polotno 0.38.6 → 0.38.7
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 +1 -1
- package/package.json +1 -1
- package/polotno.bundle.js +1 -1
package/model/store.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,o,s){void 0===s&&(s=o),Object.defineProperty(e,s,{enumerable:!0,get:function(){return t[o]}})}:function(e,t,o,s){void 0===s&&(s=o),e[s]=t[o]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),__importStar=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var o in e)"default"!==o&&Object.prototype.hasOwnProperty.call(e,o)&&__createBinding(t,e,o);return __setModuleDefault(t,e),t},__rest=this&&this.__rest||function(e,t){var o={};for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&t.indexOf(s)<0&&(o[s]=e[s]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(s=Object.getOwnPropertySymbols(e);r<s.length;r++)t.indexOf(s[r])<0&&Object.prototype.propertyIsEnumerable.call(e,s[r])&&(o[s[r]]=e[s[r]])}return o},__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.createStore=exports.Store=exports.Font=exports.Page=exports.registerShapeModel=exports.SVGElement=exports.ImageElement=exports.TextElement=exports.Element=void 0;const mobx_state_tree_1=require("mobx-state-tree"),undo_manager_1=require("./undo-manager"),nanoid_1=require("nanoid"),konva_1=__importDefault(require("konva")),download_1=require("../utils/download"),pdf_1=require("../utils/pdf"),validate_key_1=require("../utils/validate-key"),fonts=__importStar(require("../utils/fonts")),svg_1=require("../utils/svg"),loader_1=require("../utils/loader");(0,mobx_state_tree_1.setLivelinessChecking)("ignore"),exports.Element=mobx_state_tree_1.types.model("Element",{id:mobx_state_tree_1.types.identifier,type:"none",x:0,y:0,rotation:0,opacity:1,visible:!0,locked:!1,blurEnabled:!1,blurRadius:10,brightnessEnabled:!1,brightness:0,sepiaEnabled:!1,grayscaleEnabled:!1,shadowEnabled:!1,shadowBlur:5,shadowOffsetX:0,shadowOffsetY:0,shadowColor:"black",custom:mobx_state_tree_1.types.frozen(),selectable:!0,alwaysOnTop:!1,showInExport:!0}).preProcessSnapshot((e=>{const t=Object.assign(Object.assign({},e),{x:e.x||0,y:e.y||0});return"width"in e&&(t.width=t.width||1),"height"in e&&(t.height=t.height||1),t})).postProcessSnapshot((e=>{const t=Object.assign({},e),o={};for(var s in t)"_"!==s[0]&&(o[s]=e[s]);return o})).views((e=>({get page(){return(0,mobx_state_tree_1.getParentOfType)(e,exports.Page)},get store(){return(0,mobx_state_tree_1.getParentOfType)(e,exports.Store)}}))).actions((e=>({toJSON:()=>Object.assign({},(0,mobx_state_tree_1.getSnapshot)(e))}))).actions((e=>({clone(t){const o=e.toJSON();return t.id=t.id||(0,nanoid_1.nanoid)(10),Object.assign(o,t),e.page.addElement(o)},set(t){Object.assign(e,t)},moveUp(){e.page.moveElementUp(e.id)},moveTop(){e.page.moveElementTop(e.id)},moveDown(){e.page.moveElementDown(e.id)},moveBottom(){e.page.moveElementBottom(e.id)},beforeDestroy(){e.store.history.endTransaction()}}))),exports.TextElement=exports.Element.named("Text").props({type:"text",text:"",placeholder:"",fontSize:14,fontFamily:"Roboto",fontStyle:"normal",fontWeight:"normal",textDecoration:"",fill:"black",align:"center",width:100,height:14,strokeWidth:0,stroke:"black",lineHeight:mobx_state_tree_1.types.optional(mobx_state_tree_1.types.union(mobx_state_tree_1.types.number,mobx_state_tree_1.types.string),1.2),letterSpacing:0,_editModeEnabled:!1}).preProcessSnapshot((e=>Object.assign({},e))).actions((e=>({toggleEditMode(t){e._editModeEnabled=null!=t?t:!e._editModeEnabled,e._editModeEnabled?e.store.history.startTransaction():e.store.history.endTransaction()}}))),exports.ImageElement=exports.Element.named("Image").props({type:"image",width:100,height:100,src:"",cropX:0,cropY:0,cropWidth:1,cropHeight:1,cornerRadius:0,flipX:!1,flipY:!1,clipSrc:"",borderColor:"black",borderSize:0,_cropModeEnabled:!1}).actions((e=>({toggleCropMode(t){e._cropModeEnabled=null!=t?t:!e._cropModeEnabled,e._cropModeEnabled?e.store.history.startTransaction():e.store.history.endTransaction()}}))),exports.SVGElement=exports.Element.named("SVG").props({type:"svg",src:"",maskSrc:"",__svgString:"",cropX:0,cropY:0,cropWidth:1,cropHeight:1,keepRatio:!0,flipX:!1,flipY:!1,width:100,height:100,borderColor:"black",borderSize:0,colorsReplace:mobx_state_tree_1.types.map(mobx_state_tree_1.types.string)}).preProcessSnapshot((e=>Object.assign(Object.assign({},e),{src:e.src||e.svgSource}))).views((e=>({get colors(){return e.__svgString?(0,svg_1.getColors)(e.__svgString):[]},get __finalSrc(){return e.__svgString?(0,svg_1.replaceColors)(e.__svgString,e.colorsReplace):this.src},get __isLoaded(){if(!e.__svgString)return!1;return!(Array.from(e.colorsReplace.keys()).length>0)||e.__finalSrc!==e.src}}))).actions((e=>{let t=()=>{};return{async _loadSVG(){if(!e.src)return;const t=await(0,svg_1.urlToString)(e.src);(0,mobx_state_tree_1.isAlive)(e)&&(0,mobx_state_tree_1.hasParent)(e)&&e.store.history.ignore((()=>{e.set({__svgString:(0,svg_1.fixSize)(t)})}))},async afterCreate(){e._loadSVG();let o=e.src;t=(0,mobx_state_tree_1.onSnapshot)(e,(t=>{t.src===o&&e.__svgString||(e._loadSVG(),o=e.src)}))},beforeDestroy(){t()},replaceColor(t,o){e.colorsReplace.set(t,o)}}}));const TYPES_MAP={svg:exports.SVGElement,text:exports.TextElement,image:exports.ImageElement},ADDITIONAL_TYPES=[];function registerShapeModel(e){const t=e.type;if(!t)throw new Error('You must pass "type" attribute to custom model.');const o=exports.Element.named(t).props(e);TYPES_MAP[t]=o,ADDITIONAL_TYPES.push(o)}exports.registerShapeModel=registerShapeModel;const additionalTypesUnion=[...new Array(20)].map(((e,t)=>mobx_state_tree_1.types.late((()=>ADDITIONAL_TYPES[t])))),ElementTypes=mobx_state_tree_1.types.union({dispatcher:e=>{const t=TYPES_MAP[e.type];if(!t)throw new Error(`Unknown element type: "${e.type}"`);return t}},exports.SVGElement,exports.TextElement,exports.ImageElement,...additionalTypesUnion);function createStore({key:e,showCredit:t}={key:"",showCredit:!1}){const o=exports.Store.create();return(0,validate_key_1.validateKey)(e,t),o}exports.Page=mobx_state_tree_1.types.model("Page",{id:mobx_state_tree_1.types.identifier,children:mobx_state_tree_1.types.array(ElementTypes),width:mobx_state_tree_1.types.optional(mobx_state_tree_1.types.union(mobx_state_tree_1.types.number,mobx_state_tree_1.types.literal("auto")),"auto"),height:mobx_state_tree_1.types.optional(mobx_state_tree_1.types.union(mobx_state_tree_1.types.number,mobx_state_tree_1.types.literal("auto")),"auto"),background:"white",bleed:0,custom:mobx_state_tree_1.types.frozen(),_exporting:!1}).postProcessSnapshot((e=>{const t=Object.assign({},e),o={};for(var s in t)"_"!==s[0]&&(o[s]=e[s]);return o})).views((e=>({get store(){return(0,mobx_state_tree_1.getParentOfType)(e,exports.Store)}}))).views((e=>({get computedWidth(){return"auto"===e.width?e.store.width:e.width},get computedHeight(){return"auto"===e.height?e.store.height:e.height}}))).actions((e=>({toJSON:()=>JSON.parse(JSON.stringify((0,mobx_state_tree_1.getSnapshot)(e))),clone(t){const o=e.toJSON();o.children.forEach((e=>{e.id=(0,nanoid_1.nanoid)(10)}));const s=Object.assign(Object.assign(Object.assign({},o),{id:(0,nanoid_1.nanoid)(10)}),t),r=e.store.addPage(s),n=e.store.pages.indexOf(e);r.setZIndex(n+1),r.select()},setZIndex(t){e.store.setPageZIndex(e.id,t)},set(t){Object.assign(e,t)},select(){e.store.selectPage(e.id)},addElement(t){const o=TYPES_MAP[t.type];if(!o)return void console.error("Can not find model with type "+t.type);const s=o.create(Object.assign({id:(0,nanoid_1.nanoid)(10)},t));return e.children.push(s),s.selectable&&e.store.selectElements([s.id]),s},moveElementUp(t){const o=e.children.findIndex((e=>e.id===t)),s=e.children[o];(0,mobx_state_tree_1.detach)(s),e.children.remove(s),e.children.splice(o+1,0,s)},moveElementDown(t){const o=e.children.findIndex((e=>e.id===t)),s=e.children[o];(0,mobx_state_tree_1.detach)(s),e.children.remove(s),e.children.splice(o-1,0,s)},moveElementTop(t){const o=e.children.findIndex((e=>e.id===t)),s=e.children[o];(0,mobx_state_tree_1.detach)(s),e.children.remove(s),e.children.push(s)},moveElementBottom(t){const o=e.children.findIndex((e=>e.id===t)),s=e.children[o];(0,mobx_state_tree_1.detach)(s),e.children.remove(s),e.children.splice(0,0,s)}}))),exports.Font=mobx_state_tree_1.types.model("Font",{fontFamily:mobx_state_tree_1.types.string,url:mobx_state_tree_1.types.optional(mobx_state_tree_1.types.string,""),styles:mobx_state_tree_1.types.frozen()}).preProcessSnapshot((e=>Object.assign(Object.assign({},e),{fontFamily:e.fontFamily||e.name}))),exports.Store=mobx_state_tree_1.types.model("Store",{role:"",pages:mobx_state_tree_1.types.array(exports.Page),fonts:mobx_state_tree_1.types.array(exports.Font),width:1080,height:1080,scale:1,scaleToFit:1,_bleedVisible:!1,openedSidePanel:"",selectedElementsIds:mobx_state_tree_1.types.array(mobx_state_tree_1.types.string),history:mobx_state_tree_1.types.optional(undo_manager_1.UndoManager,{targetPath:"../pages"}),_elementsPixelRatio:2,_activePageId:""}).views((e=>({get selectedElements(){return e.selectedElementsIds.map((t=>{for(const o of e.pages)for(const e of o.children)if(e.id===t)return e})).filter((e=>!!e))},get activePage(){return e.pages.slice().find((t=>t.id===e._activePageId))||(e.pages.length?e.pages[0]:null)}}))).actions((e=>({setRole(t){e.role=t},getElementById(t){for(const o of e.pages)for(const e of o.children)if(e.id===t)return e},addPage(t){const o=exports.Page.create(Object.assign({id:(0,nanoid_1.nanoid)(10)},t));return e.pages.push(o),e._activePageId=o.id,o},selectPage(t){e._activePageId=t},selectElements(t){e.selectedElementsIds=(0,mobx_state_tree_1.cast)(t)},_toggleBleed(t){e._bleedVisible=null!=t?t:!e._bleedVisible},openSidePanel(t){e.openedSidePanel=t},setScale(t){e.scale=t},_setScaleToFit(t){e.scaleToFit=t},setElementsPixelRatio(t){e._elementsPixelRatio=t},setSize(t,o,s){if(s){const s=t/e.width,r=o/e.height;for(const t of e.pages)for(const e of t.children)e.set({x:e.x*s,y:e.y*r}),"text"===e.type?e.set({fontSize:e.fontSize*s,width:Math.max(e.width*s,2)}):"image"===e.type?e.set({width:e.width*s,height:e.height*r}):"svg"===e.type&&e.set({width:Math.max(e.width*s,2),height:Math.max(e.height*s,2)})}e.width=t,e.height=o},setPageZIndex(t,o){const s=e.pages.find((e=>e.id===t));s&&((0,mobx_state_tree_1.detach)(s),e.pages.remove(s),e.pages.splice(o,0,s))},deletePages(t){const o=e.pages.indexOf(e.activePage);t.forEach((t=>{const o=e.pages.find((e=>e.id===t));(0,mobx_state_tree_1.destroy)(o)}));const s=Math.min(e.pages.length-1,o),r=e.pages[s];r&&(e._activePageId=r.id),e.selectedElementsIds=(0,mobx_state_tree_1.cast)(e.selectedElementsIds.filter((t=>e.getElementById(t))))},deleteElements(t){t.forEach((t=>{e.pages.forEach((e=>{const o=e.children.find((e=>e.id===t));o&&(0,mobx_state_tree_1.destroy)(o)}))})),e.selectedElementsIds=(0,mobx_state_tree_1.cast)([])},on(t,o){if("change"===t){let t=e.toJSON();return(0,mobx_state_tree_1.onSnapshot)(e,(s=>{const r=e.toJSON();JSON.stringify(r)!==JSON.stringify(t)&&(t=r,o(r))}))}},async toDataURL({pixelRatio:t,ignoreBackground:o,pageId:s,mimeType:r,includeBleed:n,quality:a}={}){var i;const l=t||1;s=s||(null===(i=e.pages[0])||void 0===i?void 0:i.id);const d=e.pages.find((e=>e.id===s));if(!d)throw new Error(`No page for export with id ${s}`);null==d||d.set({_exporting:!0}),await new Promise((e=>{setTimeout(e,0)})),await e.waitLoading();const c=konva_1.default.stages.find((e=>e.getAttr("pageId")===s));if(!c)throw new Error(`Export is failed. Can not find stage for page ${s}. Looks like <Workspace /> component is not mounted, but it is required in order to process the export.`);const _=c.findOne(".page-container");c.find("Transformer").forEach((e=>e.visible(!1))),_.findOne(".page-background").shadowEnabled(!1),_.findOne(".page-background").strokeEnabled(!1),_.find(".highlighter").forEach((e=>e.visible(!1)));const p=_.findOne(".page-background-group"),g=p.clip();p.clip({x:null,y:null,width:null,height:null});const m=_.find((e=>e.getAttr("hideInExport")));m.forEach((e=>{e.setAttr("oldVisible",e.visible()),e.hide()})),o&&_.findOne(".page-background").hide();const h=n?d.bleed:0;let f=h;e._bleedVisible&&n?f=0:e._bleedVisible&&!n&&(f=-d.bleed);const b=_.toDataURL({x:_.x()-f*_.scaleX(),y:_.y()-f*_.scaleY(),width:(d.computedWidth+2*h)*_.scaleX(),height:(d.computedHeight+2*h)*_.scaleY(),pixelRatio:1/_.scaleX()*l,mimeType:r,quality:a});return o&&_.findOne(".page-background").show(),m.forEach((e=>{e.visible(e.getAttr("oldVisible"))})),_.findOne(".page-background").shadowEnabled(!0),_.findOne(".page-background").strokeEnabled(!0),c.find("Transformer").forEach((e=>e.visible(!0))),_.find(".highlighter").forEach((e=>e.visible(!0))),p.clip(g),null==d||d.set({_exporting:!1}),b},async saveAsImage(t={}){var{fileName:o}=t,s=__rest(t,["fileName"]);const r=s.mimeType||"image/png",n=r.split("/")[1];(0,download_1.downloadFile)(await e.toDataURL(s),o||"polotno."+n,r)},async _toPDF(t){const o=t.dpi||300,s=t.parallel||1,r=await(0,pdf_1.getJsPDF)(),n=e=>.75*e;var a=new r({unit:"pt",orientation:e.width>e.height?"landscape":"portrait",format:[n(e.width),n(e.height)],compress:!0});a.deletePage(1);const i=e._elementsPixelRatio,l=o/72;e.setElementsPixelRatio(l),await new Promise((e=>setTimeout(e)));const d=((e,t)=>{for(var o=[],s=0;s<e.length;s+=t)o.push(e.slice(s,s+t));return o})(e.pages,s);for(const o of d){const s=o.map((async o=>{const s=t.includeBleed?o.bleed:0,r=n(o.computedWidth+s),a=n(o.computedHeight+s);let i=0,d=l;for(;i<10;){i+=1,2===i&&console.error("Polotno can not export PDF with current settings. Quality is automatically reduced."),console.log("exporting page",o.id);const s=await e.toDataURL(Object.assign(Object.assign({},t),{pageId:o.id,pixelRatio:d}));if(s.length>20)return{url:s,width:r,height:a};d*=.8}}));(await Promise.all(s)).forEach((({url:e,width:t,height:o})=>{a.addPage([t,o],t>o?"landscape":"portrait"),a.addImage(e,0,0,t,o,void 0,"FAST")}))}return e.setElementsPixelRatio(i),a},toPDFDataURL:async t=>(await e._toPDF(Object.assign({mimeType:"image/jpeg"},t))).output("datauristring"),async saveAsPDF(t={}){var{fileName:o}=t,s=__rest(t,["fileName"]);(await e._toPDF(Object.assign({mimeType:"image/jpeg"},s))).save(o||"polotno.pdf")},async waitLoading(){await(0,loader_1.whenLoaded)()},toJSON:()=>({width:e.width,height:e.height,fonts:(0,mobx_state_tree_1.getSnapshot)(e.fonts),pages:(0,mobx_state_tree_1.getSnapshot)(e.pages)}),loadJSON(t,o=!1){var s;const r=Object.assign({},t);e.pages.forEach((e=>e.children.forEach((e=>(0,mobx_state_tree_1.detach)(e))))),e.pages=(0,mobx_state_tree_1.cast)([]),r._activePageId=null===(s=r.pages[0])||void 0===s?void 0:s.id,r.scale=e.scale,r.openedSidePanel=e.openedSidePanel,r._bleedVisible=e._bleedVisible,o&&(r.history=e.history.toJSON()),(0,mobx_state_tree_1.applySnapshot)(e,r)},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,mobx_state_tree_1.destroy)(e)))},async loadFont(t){const o=e.fonts.find((e=>e.fontFamily===t))||fonts.globalFonts.find((e=>e.fontFamily===t));o?fonts.injectCustomFont(o):fonts.injectGoogleFont(t),await fonts.loadFont(t)}}))),exports.createStore=createStore,exports.default=createStore;
|
|
1
|
+
"use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,o,s){void 0===s&&(s=o),Object.defineProperty(e,s,{enumerable:!0,get:function(){return t[o]}})}:function(e,t,o,s){void 0===s&&(s=o),e[s]=t[o]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),__importStar=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var o in e)"default"!==o&&Object.prototype.hasOwnProperty.call(e,o)&&__createBinding(t,e,o);return __setModuleDefault(t,e),t},__rest=this&&this.__rest||function(e,t){var o={};for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&t.indexOf(s)<0&&(o[s]=e[s]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(s=Object.getOwnPropertySymbols(e);r<s.length;r++)t.indexOf(s[r])<0&&Object.prototype.propertyIsEnumerable.call(e,s[r])&&(o[s[r]]=e[s[r]])}return o},__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.createStore=exports.Store=exports.Font=exports.Page=exports.registerShapeModel=exports.SVGElement=exports.ImageElement=exports.TextElement=exports.Element=void 0;const mobx_state_tree_1=require("mobx-state-tree"),undo_manager_1=require("./undo-manager"),nanoid_1=require("nanoid"),konva_1=__importDefault(require("konva")),download_1=require("../utils/download"),pdf_1=require("../utils/pdf"),validate_key_1=require("../utils/validate-key"),fonts=__importStar(require("../utils/fonts")),svg_1=require("../utils/svg"),loader_1=require("../utils/loader");(0,mobx_state_tree_1.setLivelinessChecking)("ignore"),exports.Element=mobx_state_tree_1.types.model("Element",{id:mobx_state_tree_1.types.identifier,type:"none",x:0,y:0,rotation:0,opacity:1,visible:!0,locked:!1,blurEnabled:!1,blurRadius:10,brightnessEnabled:!1,brightness:0,sepiaEnabled:!1,grayscaleEnabled:!1,shadowEnabled:!1,shadowBlur:5,shadowOffsetX:0,shadowOffsetY:0,shadowColor:"black",custom:mobx_state_tree_1.types.frozen(),selectable:!0,alwaysOnTop:!1,showInExport:!0}).preProcessSnapshot((e=>{const t=Object.assign(Object.assign({},e),{x:e.x||0,y:e.y||0});return"width"in e&&(t.width=t.width||1),"height"in e&&(t.height=t.height||1),t})).postProcessSnapshot((e=>{const t=Object.assign({},e),o={};for(var s in t)"_"!==s[0]&&(o[s]=e[s]);return o})).views((e=>({get page(){return(0,mobx_state_tree_1.getParentOfType)(e,exports.Page)},get store(){return(0,mobx_state_tree_1.getParentOfType)(e,exports.Store)}}))).actions((e=>({toJSON:()=>Object.assign({},(0,mobx_state_tree_1.getSnapshot)(e))}))).actions((e=>({clone(t){const o=e.toJSON();return t.id=t.id||(0,nanoid_1.nanoid)(10),Object.assign(o,t),e.page.addElement(o)},set(t){Object.assign(e,t)},moveUp(){e.page.moveElementUp(e.id)},moveTop(){e.page.moveElementTop(e.id)},moveDown(){e.page.moveElementDown(e.id)},moveBottom(){e.page.moveElementBottom(e.id)},beforeDestroy(){e.store.history.endTransaction()}}))),exports.TextElement=exports.Element.named("Text").props({type:"text",text:"",placeholder:"",fontSize:14,fontFamily:"Roboto",fontStyle:"normal",fontWeight:"normal",textDecoration:"",fill:"black",align:"center",width:100,height:14,strokeWidth:0,stroke:"black",lineHeight:mobx_state_tree_1.types.optional(mobx_state_tree_1.types.union(mobx_state_tree_1.types.number,mobx_state_tree_1.types.string),1.2),letterSpacing:0,_editModeEnabled:!1}).preProcessSnapshot((e=>Object.assign({},e))).actions((e=>({toggleEditMode(t){e._editModeEnabled=null!=t?t:!e._editModeEnabled,e._editModeEnabled?e.store.history.startTransaction():e.store.history.endTransaction()}}))),exports.ImageElement=exports.Element.named("Image").props({type:"image",width:100,height:100,src:"",cropX:0,cropY:0,cropWidth:1,cropHeight:1,cornerRadius:0,flipX:!1,flipY:!1,clipSrc:"",borderColor:"black",borderSize:0,_cropModeEnabled:!1}).actions((e=>({toggleCropMode(t){e._cropModeEnabled=null!=t?t:!e._cropModeEnabled,e._cropModeEnabled?e.store.history.startTransaction():e.store.history.endTransaction()}}))),exports.SVGElement=exports.Element.named("SVG").props({type:"svg",src:"",maskSrc:"",__svgString:"",cropX:0,cropY:0,cropWidth:1,cropHeight:1,keepRatio:!0,flipX:!1,flipY:!1,width:100,height:100,borderColor:"black",borderSize:0,colorsReplace:mobx_state_tree_1.types.map(mobx_state_tree_1.types.string)}).preProcessSnapshot((e=>Object.assign(Object.assign({},e),{src:e.src||e.svgSource}))).views((e=>({get colors(){return e.__svgString?(0,svg_1.getColors)(e.__svgString):[]},get __finalSrc(){return e.__svgString?(0,svg_1.replaceColors)(e.__svgString,e.colorsReplace):this.src},get __isLoaded(){if(!e.__svgString)return!1;return!(Array.from(e.colorsReplace.keys()).length>0)||e.__finalSrc!==e.src}}))).actions((e=>{let t=()=>{};return{async _loadSVG(){if(!e.src)return;const t=await(0,svg_1.urlToString)(e.src);(0,mobx_state_tree_1.isAlive)(e)&&(0,mobx_state_tree_1.hasParent)(e)&&e.store.history.ignore((()=>{e.set({__svgString:(0,svg_1.fixSize)(t)})}))},async afterCreate(){e._loadSVG();let o=e.src;t=(0,mobx_state_tree_1.onSnapshot)(e,(t=>{t.src===o&&e.__svgString||(e._loadSVG(),o=e.src)}))},beforeDestroy(){t()},replaceColor(t,o){e.colorsReplace.set(t,o)}}}));const TYPES_MAP={svg:exports.SVGElement,text:exports.TextElement,image:exports.ImageElement},ADDITIONAL_TYPES=[];function registerShapeModel(e){const t=e.type;if(!t)throw new Error('You must pass "type" attribute to custom model.');const o=exports.Element.named(t).props(e);TYPES_MAP[t]=o,ADDITIONAL_TYPES.push(o)}exports.registerShapeModel=registerShapeModel;const additionalTypesUnion=[...new Array(20)].map(((e,t)=>mobx_state_tree_1.types.late((()=>ADDITIONAL_TYPES[t])))),ElementTypes=mobx_state_tree_1.types.union({dispatcher:e=>{const t=TYPES_MAP[e.type];if(!t)throw new Error(`Unknown element type: "${e.type}"`);return t}},exports.SVGElement,exports.TextElement,exports.ImageElement,...additionalTypesUnion);function createStore({key:e,showCredit:t}={key:"",showCredit:!1}){const o=exports.Store.create();return(0,validate_key_1.validateKey)(e,t),o}exports.Page=mobx_state_tree_1.types.model("Page",{id:mobx_state_tree_1.types.identifier,children:mobx_state_tree_1.types.array(ElementTypes),width:mobx_state_tree_1.types.optional(mobx_state_tree_1.types.union(mobx_state_tree_1.types.number,mobx_state_tree_1.types.literal("auto")),"auto"),height:mobx_state_tree_1.types.optional(mobx_state_tree_1.types.union(mobx_state_tree_1.types.number,mobx_state_tree_1.types.literal("auto")),"auto"),background:"white",bleed:0,custom:mobx_state_tree_1.types.frozen(),_exporting:!1}).postProcessSnapshot((e=>{const t=Object.assign({},e),o={};for(var s in t)"_"!==s[0]&&(o[s]=e[s]);return o})).views((e=>({get store(){return(0,mobx_state_tree_1.getParentOfType)(e,exports.Store)}}))).views((e=>({get computedWidth(){return"auto"===e.width?e.store.width:e.width},get computedHeight(){return"auto"===e.height?e.store.height:e.height}}))).actions((e=>({toJSON:()=>JSON.parse(JSON.stringify((0,mobx_state_tree_1.getSnapshot)(e))),clone(t){const o=e.toJSON();o.children.forEach((e=>{e.id=(0,nanoid_1.nanoid)(10)}));const s=Object.assign(Object.assign(Object.assign({},o),{id:(0,nanoid_1.nanoid)(10)}),t),r=e.store.addPage(s),n=e.store.pages.indexOf(e);r.setZIndex(n+1),r.select()},setZIndex(t){e.store.setPageZIndex(e.id,t)},set(t){Object.assign(e,t)},select(){e.store.selectPage(e.id)},addElement(t){const o=TYPES_MAP[t.type];if(!o)return void console.error("Can not find model with type "+t.type);const s=o.create(Object.assign({id:(0,nanoid_1.nanoid)(10)},t));return e.children.push(s),s.selectable&&e.store.selectElements([s.id]),s},moveElementUp(t){const o=e.children.findIndex((e=>e.id===t)),s=e.children[o];(0,mobx_state_tree_1.detach)(s),e.children.remove(s),e.children.splice(o+1,0,s)},moveElementDown(t){const o=e.children.findIndex((e=>e.id===t)),s=e.children[o];(0,mobx_state_tree_1.detach)(s),e.children.remove(s),e.children.splice(o-1,0,s)},moveElementTop(t){const o=e.children.findIndex((e=>e.id===t)),s=e.children[o];(0,mobx_state_tree_1.detach)(s),e.children.remove(s),e.children.push(s)},moveElementBottom(t){const o=e.children.findIndex((e=>e.id===t)),s=e.children[o];(0,mobx_state_tree_1.detach)(s),e.children.remove(s),e.children.splice(0,0,s)}}))),exports.Font=mobx_state_tree_1.types.model("Font",{fontFamily:mobx_state_tree_1.types.string,url:mobx_state_tree_1.types.optional(mobx_state_tree_1.types.string,""),styles:mobx_state_tree_1.types.frozen()}).preProcessSnapshot((e=>Object.assign(Object.assign({},e),{fontFamily:e.fontFamily||e.name}))),exports.Store=mobx_state_tree_1.types.model("Store",{role:"",pages:mobx_state_tree_1.types.array(exports.Page),fonts:mobx_state_tree_1.types.array(exports.Font),width:1080,height:1080,scale:1,scaleToFit:1,_bleedVisible:!1,openedSidePanel:"",selectedElementsIds:mobx_state_tree_1.types.array(mobx_state_tree_1.types.string),history:mobx_state_tree_1.types.optional(undo_manager_1.UndoManager,{targetPath:"../pages"}),_elementsPixelRatio:2,_activePageId:""}).views((e=>({get selectedElements(){return e.selectedElementsIds.map((t=>{for(const o of e.pages)for(const e of o.children)if(e.id===t)return e})).filter((e=>!!e))},get activePage(){return e.pages.slice().find((t=>t.id===e._activePageId))||(e.pages.length?e.pages[0]:null)}}))).actions((e=>({setRole(t){e.role=t},getElementById(t){for(const o of e.pages)for(const e of o.children)if(e.id===t)return e},addPage(t){const o=exports.Page.create(Object.assign({id:(0,nanoid_1.nanoid)(10)},t));return e.pages.push(o),e._activePageId=o.id,o},selectPage(t){e._activePageId=t},selectElements(t){e.selectedElementsIds=(0,mobx_state_tree_1.cast)(t)},_toggleBleed(t){e._bleedVisible=null!=t?t:!e._bleedVisible},openSidePanel(t){e.openedSidePanel=t},setScale(t){e.scale=t},_setScaleToFit(t){e.scaleToFit=t},setElementsPixelRatio(t){e._elementsPixelRatio=t},setSize(t,o,s){if(s){const s=t/e.width,r=o/e.height;for(const t of e.pages)for(const e of t.children)e.set({x:e.x*s,y:e.y*r}),"text"===e.type?e.set({fontSize:e.fontSize*s,width:Math.max(e.width*s,2)}):"image"===e.type?e.set({width:e.width*s,height:e.height*r}):"svg"===e.type&&e.set({width:Math.max(e.width*s,2),height:Math.max(e.height*s,2)})}e.width=t,e.height=o},setPageZIndex(t,o){const s=e.pages.find((e=>e.id===t));s&&((0,mobx_state_tree_1.detach)(s),e.pages.remove(s),e.pages.splice(o,0,s))},deletePages(t){const o=e.pages.indexOf(e.activePage);t.forEach((t=>{const o=e.pages.find((e=>e.id===t));(0,mobx_state_tree_1.destroy)(o)}));const s=Math.min(e.pages.length-1,o),r=e.pages[s];r&&(e._activePageId=r.id),e.selectedElementsIds=(0,mobx_state_tree_1.cast)(e.selectedElementsIds.filter((t=>e.getElementById(t))))},deleteElements(t){t.forEach((t=>{e.pages.forEach((e=>{const o=e.children.find((e=>e.id===t));o&&(0,mobx_state_tree_1.destroy)(o)}))})),e.selectedElementsIds=(0,mobx_state_tree_1.cast)([])},on(t,o){if("change"===t){let t=e.toJSON();return(0,mobx_state_tree_1.onSnapshot)(e,(s=>{const r=e.toJSON();JSON.stringify(r)!==JSON.stringify(t)&&(t=r,o(r))}))}},async toDataURL({pixelRatio:t,ignoreBackground:o,pageId:s,mimeType:r,includeBleed:n,quality:a}={}){var i;const l=t||1;s=s||(null===(i=e.pages[0])||void 0===i?void 0:i.id);const d=e.pages.find((e=>e.id===s));if(!d)throw new Error(`No page for export with id ${s}`);null==d||d.set({_exporting:!0}),await new Promise((e=>{setTimeout(e,0)})),await e.waitLoading();const c=konva_1.default.stages.find((e=>e.getAttr("pageId")===s));if(!c)throw new Error(`Export is failed. Can not find stage for page ${s}. Looks like <Workspace /> component is not mounted, but it is required in order to process the export.`);const _=c.findOne(".page-container");c.find("Transformer").forEach((e=>e.visible(!1))),_.findOne(".page-background").shadowEnabled(!1),_.findOne(".page-background").strokeEnabled(!1),_.find(".highlighter").forEach((e=>e.visible(!1)));const p=_.findOne(".page-background-group"),g=p.clip();p.clip({x:null,y:null,width:null,height:null});const m=_.find((e=>e.getAttr("hideInExport")));m.forEach((e=>{e.setAttr("oldVisible",e.visible()),e.hide()})),o&&_.findOne(".page-background").hide();const h=n?d.bleed:0;let f=h;e._bleedVisible&&n?f=0:e._bleedVisible&&!n&&(f=-d.bleed);const b=_.toDataURL({x:_.x()-f*_.scaleX(),y:_.y()-f*_.scaleY(),width:(d.computedWidth+2*h)*_.scaleX(),height:(d.computedHeight+2*h)*_.scaleY(),pixelRatio:1/_.scaleX()*l,mimeType:r,quality:a});return o&&_.findOne(".page-background").show(),m.forEach((e=>{e.visible(e.getAttr("oldVisible"))})),_.findOne(".page-background").shadowEnabled(!0),_.findOne(".page-background").strokeEnabled(!0),c.find("Transformer").forEach((e=>e.visible(!0))),_.find(".highlighter").forEach((e=>e.visible(!0))),p.clip(g),null==d||d.set({_exporting:!1}),b},async saveAsImage(t={}){var{fileName:o}=t,s=__rest(t,["fileName"]);const r=s.mimeType||"image/png",n=r.split("/")[1];(0,download_1.downloadFile)(await e.toDataURL(s),o||"polotno."+n,r)},async _toPDF(t){const o=t.dpi||300,s=t.parallel||1,r=await(0,pdf_1.getJsPDF)(),n=e=>.75*e;var a=new r({unit:"pt",orientation:e.width>e.height?"landscape":"portrait",format:[n(e.width),n(e.height)],compress:!0});a.deletePage(1);const i=e._elementsPixelRatio,l=o/72;e.setElementsPixelRatio(l),await new Promise((e=>setTimeout(e)));const d=((e,t)=>{for(var o=[],s=0;s<e.length;s+=t)o.push(e.slice(s,s+t));return o})(e.pages,s);for(const o of d){const s=o.map((async o=>{const s=t.includeBleed?o.bleed:0,r=n(o.computedWidth+s),a=n(o.computedHeight+s);let i=0,d=l;for(;i<10;){i+=1,2===i&&console.error("Polotno can not export PDF with current settings. Quality is automatically reduced.");const s=await e.toDataURL(Object.assign(Object.assign({},t),{pageId:o.id,pixelRatio:d}));if(s.length>20)return{url:s,width:r,height:a};d*=.8}}));(await Promise.all(s)).forEach((({url:e,width:t,height:o})=>{a.addPage([t,o],t>o?"landscape":"portrait"),a.addImage(e,0,0,t,o,void 0,"FAST")}))}return e.setElementsPixelRatio(i),a},toPDFDataURL:async t=>(await e._toPDF(Object.assign({mimeType:"image/jpeg"},t))).output("datauristring"),async saveAsPDF(t={}){var{fileName:o}=t,s=__rest(t,["fileName"]);(await e._toPDF(Object.assign({mimeType:"image/jpeg"},s))).save(o||"polotno.pdf")},async waitLoading(){await(0,loader_1.whenLoaded)()},toJSON:()=>({width:e.width,height:e.height,fonts:(0,mobx_state_tree_1.getSnapshot)(e.fonts),pages:(0,mobx_state_tree_1.getSnapshot)(e.pages)}),loadJSON(t,o=!1){var s;const r=Object.assign({},t);e.pages.forEach((e=>e.children.forEach((e=>(0,mobx_state_tree_1.detach)(e))))),e.pages=(0,mobx_state_tree_1.cast)([]),r._activePageId=null===(s=r.pages[0])||void 0===s?void 0:s.id,r.scale=e.scale,r.openedSidePanel=e.openedSidePanel,r._bleedVisible=e._bleedVisible,o&&(r.history=e.history.toJSON()),(0,mobx_state_tree_1.applySnapshot)(e,r)},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,mobx_state_tree_1.destroy)(e)))},async loadFont(t){const o=e.fonts.find((e=>e.fontFamily===t))||fonts.globalFonts.find((e=>e.fontFamily===t));o?fonts.injectCustomFont(o):fonts.injectGoogleFont(t),await fonts.loadFont(t)}}))),exports.createStore=createStore,exports.default=createStore;
|
package/package.json
CHANGED
package/polotno.bundle.js
CHANGED
|
@@ -325,7 +325,7 @@ PERFORMANCE OF THIS SOFTWARE.
|
|
|
325
325
|
@media screen and (max-width: 500px) {
|
|
326
326
|
display: none;
|
|
327
327
|
}
|
|
328
|
-
`,hq=[.1,.25,.5,.75,1,1.5,2,3],fq=$r.observer((({store:e})=>{const t=Math.max(2,e.scaleToFit),n=Math.min(.5,e.scaleToFit),r=e.scale<t,i=e.scale>n;return b.jsxs(m_.Group,{align:Nu,children:[b.jsx(Vx,{icon:"zoom-out",minimal:!0,onClick:()=>{e.setScale(e.scale/1.2)},disabled:!i}),b.jsx(Uz,{content:b.jsxs(f_,{style:{minWidth:"80px"},children:[hq.map((t=>b.jsx(c_,{text:Math.round(100*t)+"%",onClick:async()=>{e.setScale(t)}},t))),b.jsx(c_,{text:Xz("scale.reset"),onClick:async()=>{e.setScale(e.scaleToFit)}})]}),children:b.jsx(Vx,{minimal:!0,children:Math.round(100*e.scale)+"%"})}),b.jsx(Vx,{icon:"zoom-in",minimal:!0,onClick:()=>{e.setScale(1.2*e.scale)},disabled:!r})]})}));var dq=$r.observer((({store:e})=>b.jsx(uq,{children:b.jsx(m_,{children:b.jsx(fq,{store:e})})})));const pq=qU.model("UndoManager",{history:qU.array(qU.frozen()),undoIdx:-1,targetPath:""}).views((e=>({get canUndo(){return e.undoIdx>0},get canRedo(){return e.undoIdx<e.history.length-1}}))).actions((e=>{let t,n,r=!1,i=null,o=0,a=!1;function l(){const e=gF(t);return{pages:e.pages,width:e.width,height:e.height}}function s(e){mF(t.pages,e.pages),t.setSize(e.width,e.height)}return{startTransaction(){a=!0},endTransaction(e){a=!1,e||this.requestAddState(l())},async ignore(t){e.startTransaction();try{await t()}catch(e){setTimeout((()=>{throw e}))}e.endTransaction(!0),clearTimeout(o),o=0},async transaction(t){await e.ignore(t),this.addUndoState()},requestAddState(e){i=e,o||a||(r?r=!1:o=setTimeout((()=>{o=0,clearTimeout(o),a||this.addUndoState()}),100))},addUndoState(){if(r)return void(r=!1);const t=e.history[e.undoIdx];JSON.stringify(t)!==JSON.stringify(i)&&(e.history.splice(e.undoIdx+1),e.history.push(i),e.undoIdx=e.history.length-1)},afterCreate(){if(t=function(e,t){iB(e,1),jB();var n=sB(oB(e),t);return n?n.value:void 0}(e,".."),!t)throw new Error("Failed to find target store for UndoManager. Please provide `targetPath` property, or a `targetStore` in the environment");n=pF(t,(()=>this.requestAddState(l()))),0===e.history.length&&this.requestAddState(l())},clear(){clearTimeout(o),o=0,e.history.splice(0,e.history.length),e.undoIdx=-1,e.addUndoState(l())},beforeDestroy(){n()},undo(){o&&this.addUndoState(),e.canUndo?(e.undoIdx--,r=!0,s(e.history[e.undoIdx])):console.warn("No undo history. Please check `store.history.canUndo` before calling undo action.")},redo(){o&&this.addUndoState(),e.canRedo?(e.undoIdx++,r=!0,s(e.history[e.undoIdx])):console.warn("No redo history. Please check `store.history.canRedo` before calling redo action.")},replaceState(){e.history[e.undoIdx]=l()}}}));let vq=(e=21)=>{let t="",n=crypto.getRandomValues(new Uint8Array(e));for(;e--;){let r=63&n[e];t+=r<36?r.toString(36):r<62?(r-26).toString(36).toUpperCase():r<63?"_":"-"}return t};let mq;aF("ignore");const gq=qU.model("Element",{id:qU.identifier,type:"none",x:0,y:0,rotation:0,opacity:1,visible:!0,locked:!1,blurEnabled:!1,blurRadius:10,brightnessEnabled:!1,brightness:0,sepiaEnabled:!1,grayscaleEnabled:!1,shadowEnabled:!1,shadowBlur:5,shadowOffsetX:0,shadowOffsetY:0,shadowColor:"black",custom:qU.frozen(),selectable:!0,alwaysOnTop:!1,showInExport:!0}).preProcessSnapshot((e=>{const t={...e,x:e.x||0,y:e.y||0};return"width"in e&&(t.width=t.width||1),"height"in e&&(t.height=t.height||1),t})).postProcessSnapshot((e=>{const t={...e},n={};for(var r in t)"_"!==r[0]&&(n[r]=e[r]);return n})).views((e=>({get page(){return yF(e,Sq)},get store(){return yF(e,Oq)}}))).actions((e=>({toJSON:()=>({...gF(e)})}))).actions((e=>({clone(t){const n=e.toJSON();return t.id=t.id||vq(10),Object.assign(n,t),e.page.addElement(n)},set(t){Object.assign(e,t)},moveUp(){e.page.moveElementUp(e.id)},moveTop(){e.page.moveElementTop(e.id)},moveDown(){e.page.moveElementDown(e.id)},moveBottom(){e.page.moveElementBottom(e.id)},beforeDestroy(){e.store.history.endTransaction()}}))),yq=gq.named("Text").props({type:"text",text:"",placeholder:"",fontSize:14,fontFamily:"Roboto",fontStyle:"normal",fontWeight:"normal",textDecoration:"",fill:"black",align:"center",width:100,height:14,strokeWidth:0,stroke:"black",lineHeight:qU.optional(qU.union(qU.number,qU.string),1.2),letterSpacing:0,_editModeEnabled:!1}).preProcessSnapshot((e=>({...e}))).actions((e=>({toggleEditMode(t){e._editModeEnabled=t??!e._editModeEnabled,e._editModeEnabled?e.store.history.startTransaction():e.store.history.endTransaction()}}))),bq=gq.named("Image").props({type:"image",width:100,height:100,src:"",cropX:0,cropY:0,cropWidth:1,cropHeight:1,cornerRadius:0,flipX:!1,flipY:!1,clipSrc:"",borderColor:"black",borderSize:0,_cropModeEnabled:!1}).actions((e=>({toggleCropMode(t){e._cropModeEnabled=t??!e._cropModeEnabled,e._cropModeEnabled?e.store.history.startTransaction():e.store.history.endTransaction()}}))),wq=gq.named("SVG").props({type:"svg",src:"",maskSrc:"",__svgString:"",cropX:0,cropY:0,cropWidth:1,cropHeight:1,keepRatio:!0,flipX:!1,flipY:!1,width:100,height:100,borderColor:"black",borderSize:0,colorsReplace:qU.map(qU.string)}).preProcessSnapshot((e=>({...e,src:e.src||e.svgSource}))).views((e=>({get colors(){return e.__svgString?function(e){const t=Gs((new DOMParser).parseFromString(e,"image/svg+xml")),n=[];return t.forEach((e=>{const{fill:t,stroke:r}=Us(e);[t,r].forEach((e=>{e&&cl.Util.colorToRGBA(e)&&-1===n.indexOf(e)&&n.push(e)}))})),n}(e.__svgString):[]},get __finalSrc(){return e.__svgString?$s(e.__svgString,e.colorsReplace):this.src},get __isLoaded(){if(!e.__svgString)return!1;return!(Array.from(e.colorsReplace.keys()).length>0)||e.__finalSrc!==e.src}}))).actions((e=>{let t=()=>{};return{async _loadSVG(){if(!e.src)return;const t=await Ks(e.src);_F(e)&&function(e,t){void 0===t&&(t=1),iB(e,1),HB(0,0,0);for(var n=oB(e).parent;n;){if(0==--t)return!0;n=n.parent}return!1}(e)&&e.store.history.ignore((()=>{e.set({__svgString:Xs(t)})}))},async afterCreate(){e._loadSVG();let n=e.src;t=pF(e,(t=>{t.src===n&&e.__svgString||(e._loadSVG(),n=e.src)}))},beforeDestroy(){t()},replaceColor(t,n){e.colorsReplace.set(t,n)}}})),xq={svg:wq,text:yq,image:bq},_q=[];const Eq=[...new Array(20)].map(((e,t)=>qU.late((()=>_q[t])))),zq=qU.union({dispatcher:e=>{const t=xq[e.type];if(!t)throw new Error(`Unknown element type: "${e.type}"`);return t}},wq,yq,bq,...Eq),Sq=qU.model("Page",{id:qU.identifier,children:qU.array(zq),width:qU.optional(qU.union(qU.number,qU.literal("auto")),"auto"),height:qU.optional(qU.union(qU.number,qU.literal("auto")),"auto"),background:"white",bleed:0,custom:qU.frozen(),_exporting:!1}).postProcessSnapshot((e=>{const t={...e},n={};for(var r in t)"_"!==r[0]&&(n[r]=e[r]);return n})).views((e=>({get store(){return yF(e,Oq)}}))).views((e=>({get computedWidth(){return"auto"===e.width?e.store.width:e.width},get computedHeight(){return"auto"===e.height?e.store.height:e.height}}))).actions((e=>({toJSON:()=>JSON.parse(JSON.stringify(gF(e))),clone(t){const n=e.toJSON();n.children.forEach((e=>{e.id=vq(10)}));const r={...n,id:vq(10),...t},i=e.store.addPage(r),o=e.store.pages.indexOf(e);i.setZIndex(o+1),i.select()},setZIndex(t){e.store.setPageZIndex(e.id,t)},set(t){Object.assign(e,t)},select(){e.store.selectPage(e.id)},addElement(t){const n=xq[t.type];if(!n)return void console.error("Can not find model with type "+t.type);const r=n.create({id:vq(10),...t});return e.children.push(r),r.selectable&&e.store.selectElements([r.id]),r},moveElementUp(t){const n=e.children.findIndex((e=>e.id===t)),r=e.children[n];wF(r),e.children.remove(r),e.children.splice(n+1,0,r)},moveElementDown(t){const n=e.children.findIndex((e=>e.id===t)),r=e.children[n];wF(r),e.children.remove(r),e.children.splice(n-1,0,r)},moveElementTop(t){const n=e.children.findIndex((e=>e.id===t)),r=e.children[n];wF(r),e.children.remove(r),e.children.push(r)},moveElementBottom(t){const n=e.children.findIndex((e=>e.id===t)),r=e.children[n];wF(r),e.children.remove(r),e.children.splice(0,0,r)}}))),Cq=qU.model("Font",{fontFamily:qU.string,url:qU.optional(qU.string,""),styles:qU.frozen()}).preProcessSnapshot((e=>({...e,fontFamily:e.fontFamily||e.name}))),Oq=qU.model("Store",{role:"",pages:qU.array(Sq),fonts:qU.array(Cq),width:1080,height:1080,scale:1,scaleToFit:1,_bleedVisible:!1,openedSidePanel:"",selectedElementsIds:qU.array(qU.string),history:qU.optional(pq,{targetPath:"../pages"}),_elementsPixelRatio:2,_activePageId:""}).views((e=>({get selectedElements(){return e.selectedElementsIds.map((t=>{for(const n of e.pages)for(const e of n.children)if(e.id===t)return e})).filter((e=>!!e))},get activePage(){return e.pages.slice().find((t=>t.id===e._activePageId))||(e.pages.length?e.pages[0]:null)}}))).actions((e=>({setRole(t){e.role=t},getElementById(t){for(const n of e.pages)for(const e of n.children)if(e.id===t)return e},addPage(t){const n=Sq.create({id:vq(10),...t});return e.pages.push(n),e._activePageId=n.id,n},selectPage(t){e._activePageId=t},selectElements(t){e.selectedElementsIds=t},_toggleBleed(t){e._bleedVisible=t??!e._bleedVisible},openSidePanel(t){e.openedSidePanel=t},setScale(t){e.scale=t},_setScaleToFit(t){e.scaleToFit=t},setElementsPixelRatio(t){e._elementsPixelRatio=t},setSize(t,n,r){if(r){const r=t/e.width,i=n/e.height;for(const t of e.pages)for(const e of t.children)e.set({x:e.x*r,y:e.y*i}),"text"===e.type?e.set({fontSize:e.fontSize*r,width:Math.max(e.width*r,2)}):"image"===e.type?e.set({width:e.width*r,height:e.height*i}):"svg"===e.type&&e.set({width:Math.max(e.width*r,2),height:Math.max(e.height*r,2)})}e.width=t,e.height=n},setPageZIndex(t,n){const r=e.pages.find((e=>e.id===t));r&&(wF(r),e.pages.remove(r),e.pages.splice(n,0,r))},deletePages(t){const n=e.pages.indexOf(e.activePage);t.forEach((t=>{xF(e.pages.find((e=>e.id===t)))}));const r=Math.min(e.pages.length-1,n),i=e.pages[r];i&&(e._activePageId=i.id),e.selectedElementsIds=e.selectedElementsIds.filter((t=>e.getElementById(t)))},deleteElements(t){t.forEach((t=>{e.pages.forEach((e=>{const n=e.children.find((e=>e.id===t));n&&xF(n)}))})),e.selectedElementsIds=[]},on(t,n){if("change"===t){let t=e.toJSON();return pF(e,(r=>{const i=e.toJSON();JSON.stringify(i)!==JSON.stringify(t)&&(t=i,n(i))}))}},async toDataURL({pixelRatio:t,ignoreBackground:n,pageId:r,mimeType:i,includeBleed:o,quality:a}={}){const l=t||1;r=r||e.pages[0]?.id;const s=e.pages.find((e=>e.id===r));if(!s)throw new Error(`No page for export with id ${r}`);s?.set({_exporting:!0}),await new Promise((e=>{setTimeout(e,0)})),await e.waitLoading();const c=cl.stages.find((e=>e.getAttr("pageId")===r));if(!c)throw new 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.`);const u=c.findOne(".page-container");c.find("Transformer").forEach((e=>e.visible(!1))),u.findOne(".page-background").shadowEnabled(!1),u.findOne(".page-background").strokeEnabled(!1),u.find(".highlighter").forEach((e=>e.visible(!1)));const h=u.findOne(".page-background-group"),f=h.clip();h.clip({x:null,y:null,width:null,height:null});const d=u.find((e=>e.getAttr("hideInExport")));d.forEach((e=>{e.setAttr("oldVisible",e.visible()),e.hide()})),n&&u.findOne(".page-background").hide();const p=o?s.bleed:0;let v=p;e._bleedVisible&&o?v=0:e._bleedVisible&&!o&&(v=-s.bleed);const m=u.toDataURL({x:u.x()-v*u.scaleX(),y:u.y()-v*u.scaleY(),width:(s.computedWidth+2*p)*u.scaleX(),height:(s.computedHeight+2*p)*u.scaleY(),pixelRatio:1/u.scaleX()*l,mimeType:i,quality:a});return n&&u.findOne(".page-background").show(),d.forEach((e=>{e.visible(e.getAttr("oldVisible"))})),u.findOne(".page-background").shadowEnabled(!0),u.findOne(".page-background").strokeEnabled(!0),c.find("Transformer").forEach((e=>e.visible(!0))),u.find(".highlighter").forEach((e=>e.visible(!0))),h.clip(f),s?.set({_exporting:!1}),m},async saveAsImage({fileName:t,...n}={}){const r=n.mimeType||"image/png",i=r.split("/")[1];!async function(e,t){const n=await(await fetch(e)).blob(),r=document.createElement("a"),i=URL.createObjectURL(n);r.href=i,r.download=t,document.body.appendChild(r),r.click(),setTimeout((function(){document.body.removeChild(r),window.URL.revokeObjectURL(i)}),0)}(await e.toDataURL(n),t||"polotno."+i)},async _toPDF(t){const n=t.dpi||300,r=t.parallel||1,i=await(mq?Promise.resolve(mq):new Promise((e=>{var t=document.createElement("script");t.onload=function(){mq=window.jspdf.jsPDF,e(mq)},t.src="https://unpkg.com/jspdf@2.2.0/dist/jspdf.umd.min.js",document.head.appendChild(t)}))),o=e=>.75*e;var a=new i({unit:"pt",orientation:e.width>e.height?"landscape":"portrait",format:[o(e.width),o(e.height)],compress:!0});a.deletePage(1);const l=e._elementsPixelRatio,s=n/72;e.setElementsPixelRatio(s),await new Promise((e=>setTimeout(e)));const c=((e,t)=>{for(var n=[],r=0;r<e.length;r+=t)n.push(e.slice(r,r+t));return n})(e.pages,r);for(const n of c){const r=n.map((async n=>{const r=t.includeBleed?n.bleed:0,i=o(n.computedWidth+r),a=o(n.computedHeight+r);let l=0,c=s;for(;l<10;){l+=1,2===l&&console.error("Polotno can not export PDF with current settings. Quality is automatically reduced."),console.log("exporting page",n.id);const r=await e.toDataURL({...t,pageId:n.id,pixelRatio:c});if(r.length>20)return{url:r,width:i,height:a};c*=.8}}));(await Promise.all(r)).forEach((({url:e,width:t,height:n})=>{a.addPage([t,n],t>n?"landscape":"portrait"),a.addImage(e,0,0,t,n,void 0,"FAST")}))}return e.setElementsPixelRatio(l),a},toPDFDataURL:async t=>(await e._toPDF({mimeType:"image/jpeg",...t})).output("datauristring"),async saveAsPDF({fileName:t,...n}={}){(await e._toPDF({mimeType:"image/jpeg",...n})).save(t||"polotno.pdf")},async waitLoading(){await Cs()},toJSON:()=>({width:e.width,height:e.height,fonts:gF(e.fonts),pages:gF(e.pages)}),loadJSON(t,n=!1){const r={...t};e.pages.forEach((e=>e.children.forEach((e=>wF(e))))),e.pages=[],r._activePageId=r.pages[0]?.id,r.scale=e.scale,r.openedSidePanel=e.openedSidePanel,r._bleedVisible=e._bleedVisible,n&&(r.history=e.history.toJSON()),mF(e,r)},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=>xF(e)))},async loadFont(t){const n=e.fonts.find((e=>e.fontFamily===t))||BC.find((e=>e.fontFamily===t));n?function(e){const t=e.fontFamily;if(YC[t])return;if(!e.url&&!e.styles)return;const n=document.createElement("style");n.type="text/css";const r=e.styles||(e.url?[{src:`url("${e.url}")`}]:[]);let i="";r.forEach((e=>{i+=`\n @font-face {\n font-family: '${t}';\n src: ${e.src};\n font-style: ${e.fontStyle||"normal"};\n font-weight: ${e.fontWeight||"normal"};\n }\n `})),n.innerHTML=i,document.getElementsByTagName("head")[0].appendChild(n),YC[e.fontFamily]=!0}(n):function(e){if(KC[e])return;const t=`https://fonts.googleapis.com/css?family=${e.replace(/ /g,"+")}`,n=document.createElement("link");n.type="text/css",n.href=t,n.rel="stylesheet",document.getElementsByTagName("head")[0].appendChild(n),KC[e]=!0}(t),await WC(t)}})));function Mq({key:e,showCredit:t}={key:"",showCredit:!1}){const n=Oq.create();return pS(e,t),n}const kq=Eu("div")`
|
|
328
|
+
`,hq=[.1,.25,.5,.75,1,1.5,2,3],fq=$r.observer((({store:e})=>{const t=Math.max(2,e.scaleToFit),n=Math.min(.5,e.scaleToFit),r=e.scale<t,i=e.scale>n;return b.jsxs(m_.Group,{align:Nu,children:[b.jsx(Vx,{icon:"zoom-out",minimal:!0,onClick:()=>{e.setScale(e.scale/1.2)},disabled:!i}),b.jsx(Uz,{content:b.jsxs(f_,{style:{minWidth:"80px"},children:[hq.map((t=>b.jsx(c_,{text:Math.round(100*t)+"%",onClick:async()=>{e.setScale(t)}},t))),b.jsx(c_,{text:Xz("scale.reset"),onClick:async()=>{e.setScale(e.scaleToFit)}})]}),children:b.jsx(Vx,{minimal:!0,children:Math.round(100*e.scale)+"%"})}),b.jsx(Vx,{icon:"zoom-in",minimal:!0,onClick:()=>{e.setScale(1.2*e.scale)},disabled:!r})]})}));var dq=$r.observer((({store:e})=>b.jsx(uq,{children:b.jsx(m_,{children:b.jsx(fq,{store:e})})})));const pq=qU.model("UndoManager",{history:qU.array(qU.frozen()),undoIdx:-1,targetPath:""}).views((e=>({get canUndo(){return e.undoIdx>0},get canRedo(){return e.undoIdx<e.history.length-1}}))).actions((e=>{let t,n,r=!1,i=null,o=0,a=!1;function l(){const e=gF(t);return{pages:e.pages,width:e.width,height:e.height}}function s(e){mF(t.pages,e.pages),t.setSize(e.width,e.height)}return{startTransaction(){a=!0},endTransaction(e){a=!1,e||this.requestAddState(l())},async ignore(t){e.startTransaction();try{await t()}catch(e){setTimeout((()=>{throw e}))}e.endTransaction(!0),clearTimeout(o),o=0},async transaction(t){await e.ignore(t),this.addUndoState()},requestAddState(e){i=e,o||a||(r?r=!1:o=setTimeout((()=>{o=0,clearTimeout(o),a||this.addUndoState()}),100))},addUndoState(){if(r)return void(r=!1);const t=e.history[e.undoIdx];JSON.stringify(t)!==JSON.stringify(i)&&(e.history.splice(e.undoIdx+1),e.history.push(i),e.undoIdx=e.history.length-1)},afterCreate(){if(t=function(e,t){iB(e,1),jB();var n=sB(oB(e),t);return n?n.value:void 0}(e,".."),!t)throw new Error("Failed to find target store for UndoManager. Please provide `targetPath` property, or a `targetStore` in the environment");n=pF(t,(()=>this.requestAddState(l()))),0===e.history.length&&this.requestAddState(l())},clear(){clearTimeout(o),o=0,e.history.splice(0,e.history.length),e.undoIdx=-1,e.addUndoState(l())},beforeDestroy(){n()},undo(){o&&this.addUndoState(),e.canUndo?(e.undoIdx--,r=!0,s(e.history[e.undoIdx])):console.warn("No undo history. Please check `store.history.canUndo` before calling undo action.")},redo(){o&&this.addUndoState(),e.canRedo?(e.undoIdx++,r=!0,s(e.history[e.undoIdx])):console.warn("No redo history. Please check `store.history.canRedo` before calling redo action.")},replaceState(){e.history[e.undoIdx]=l()}}}));let vq=(e=21)=>{let t="",n=crypto.getRandomValues(new Uint8Array(e));for(;e--;){let r=63&n[e];t+=r<36?r.toString(36):r<62?(r-26).toString(36).toUpperCase():r<63?"_":"-"}return t};let mq;aF("ignore");const gq=qU.model("Element",{id:qU.identifier,type:"none",x:0,y:0,rotation:0,opacity:1,visible:!0,locked:!1,blurEnabled:!1,blurRadius:10,brightnessEnabled:!1,brightness:0,sepiaEnabled:!1,grayscaleEnabled:!1,shadowEnabled:!1,shadowBlur:5,shadowOffsetX:0,shadowOffsetY:0,shadowColor:"black",custom:qU.frozen(),selectable:!0,alwaysOnTop:!1,showInExport:!0}).preProcessSnapshot((e=>{const t={...e,x:e.x||0,y:e.y||0};return"width"in e&&(t.width=t.width||1),"height"in e&&(t.height=t.height||1),t})).postProcessSnapshot((e=>{const t={...e},n={};for(var r in t)"_"!==r[0]&&(n[r]=e[r]);return n})).views((e=>({get page(){return yF(e,Sq)},get store(){return yF(e,Oq)}}))).actions((e=>({toJSON:()=>({...gF(e)})}))).actions((e=>({clone(t){const n=e.toJSON();return t.id=t.id||vq(10),Object.assign(n,t),e.page.addElement(n)},set(t){Object.assign(e,t)},moveUp(){e.page.moveElementUp(e.id)},moveTop(){e.page.moveElementTop(e.id)},moveDown(){e.page.moveElementDown(e.id)},moveBottom(){e.page.moveElementBottom(e.id)},beforeDestroy(){e.store.history.endTransaction()}}))),yq=gq.named("Text").props({type:"text",text:"",placeholder:"",fontSize:14,fontFamily:"Roboto",fontStyle:"normal",fontWeight:"normal",textDecoration:"",fill:"black",align:"center",width:100,height:14,strokeWidth:0,stroke:"black",lineHeight:qU.optional(qU.union(qU.number,qU.string),1.2),letterSpacing:0,_editModeEnabled:!1}).preProcessSnapshot((e=>({...e}))).actions((e=>({toggleEditMode(t){e._editModeEnabled=t??!e._editModeEnabled,e._editModeEnabled?e.store.history.startTransaction():e.store.history.endTransaction()}}))),bq=gq.named("Image").props({type:"image",width:100,height:100,src:"",cropX:0,cropY:0,cropWidth:1,cropHeight:1,cornerRadius:0,flipX:!1,flipY:!1,clipSrc:"",borderColor:"black",borderSize:0,_cropModeEnabled:!1}).actions((e=>({toggleCropMode(t){e._cropModeEnabled=t??!e._cropModeEnabled,e._cropModeEnabled?e.store.history.startTransaction():e.store.history.endTransaction()}}))),wq=gq.named("SVG").props({type:"svg",src:"",maskSrc:"",__svgString:"",cropX:0,cropY:0,cropWidth:1,cropHeight:1,keepRatio:!0,flipX:!1,flipY:!1,width:100,height:100,borderColor:"black",borderSize:0,colorsReplace:qU.map(qU.string)}).preProcessSnapshot((e=>({...e,src:e.src||e.svgSource}))).views((e=>({get colors(){return e.__svgString?function(e){const t=Gs((new DOMParser).parseFromString(e,"image/svg+xml")),n=[];return t.forEach((e=>{const{fill:t,stroke:r}=Us(e);[t,r].forEach((e=>{e&&cl.Util.colorToRGBA(e)&&-1===n.indexOf(e)&&n.push(e)}))})),n}(e.__svgString):[]},get __finalSrc(){return e.__svgString?$s(e.__svgString,e.colorsReplace):this.src},get __isLoaded(){if(!e.__svgString)return!1;return!(Array.from(e.colorsReplace.keys()).length>0)||e.__finalSrc!==e.src}}))).actions((e=>{let t=()=>{};return{async _loadSVG(){if(!e.src)return;const t=await Ks(e.src);_F(e)&&function(e,t){void 0===t&&(t=1),iB(e,1),HB(0,0,0);for(var n=oB(e).parent;n;){if(0==--t)return!0;n=n.parent}return!1}(e)&&e.store.history.ignore((()=>{e.set({__svgString:Xs(t)})}))},async afterCreate(){e._loadSVG();let n=e.src;t=pF(e,(t=>{t.src===n&&e.__svgString||(e._loadSVG(),n=e.src)}))},beforeDestroy(){t()},replaceColor(t,n){e.colorsReplace.set(t,n)}}})),xq={svg:wq,text:yq,image:bq},_q=[];const Eq=[...new Array(20)].map(((e,t)=>qU.late((()=>_q[t])))),zq=qU.union({dispatcher:e=>{const t=xq[e.type];if(!t)throw new Error(`Unknown element type: "${e.type}"`);return t}},wq,yq,bq,...Eq),Sq=qU.model("Page",{id:qU.identifier,children:qU.array(zq),width:qU.optional(qU.union(qU.number,qU.literal("auto")),"auto"),height:qU.optional(qU.union(qU.number,qU.literal("auto")),"auto"),background:"white",bleed:0,custom:qU.frozen(),_exporting:!1}).postProcessSnapshot((e=>{const t={...e},n={};for(var r in t)"_"!==r[0]&&(n[r]=e[r]);return n})).views((e=>({get store(){return yF(e,Oq)}}))).views((e=>({get computedWidth(){return"auto"===e.width?e.store.width:e.width},get computedHeight(){return"auto"===e.height?e.store.height:e.height}}))).actions((e=>({toJSON:()=>JSON.parse(JSON.stringify(gF(e))),clone(t){const n=e.toJSON();n.children.forEach((e=>{e.id=vq(10)}));const r={...n,id:vq(10),...t},i=e.store.addPage(r),o=e.store.pages.indexOf(e);i.setZIndex(o+1),i.select()},setZIndex(t){e.store.setPageZIndex(e.id,t)},set(t){Object.assign(e,t)},select(){e.store.selectPage(e.id)},addElement(t){const n=xq[t.type];if(!n)return void console.error("Can not find model with type "+t.type);const r=n.create({id:vq(10),...t});return e.children.push(r),r.selectable&&e.store.selectElements([r.id]),r},moveElementUp(t){const n=e.children.findIndex((e=>e.id===t)),r=e.children[n];wF(r),e.children.remove(r),e.children.splice(n+1,0,r)},moveElementDown(t){const n=e.children.findIndex((e=>e.id===t)),r=e.children[n];wF(r),e.children.remove(r),e.children.splice(n-1,0,r)},moveElementTop(t){const n=e.children.findIndex((e=>e.id===t)),r=e.children[n];wF(r),e.children.remove(r),e.children.push(r)},moveElementBottom(t){const n=e.children.findIndex((e=>e.id===t)),r=e.children[n];wF(r),e.children.remove(r),e.children.splice(0,0,r)}}))),Cq=qU.model("Font",{fontFamily:qU.string,url:qU.optional(qU.string,""),styles:qU.frozen()}).preProcessSnapshot((e=>({...e,fontFamily:e.fontFamily||e.name}))),Oq=qU.model("Store",{role:"",pages:qU.array(Sq),fonts:qU.array(Cq),width:1080,height:1080,scale:1,scaleToFit:1,_bleedVisible:!1,openedSidePanel:"",selectedElementsIds:qU.array(qU.string),history:qU.optional(pq,{targetPath:"../pages"}),_elementsPixelRatio:2,_activePageId:""}).views((e=>({get selectedElements(){return e.selectedElementsIds.map((t=>{for(const n of e.pages)for(const e of n.children)if(e.id===t)return e})).filter((e=>!!e))},get activePage(){return e.pages.slice().find((t=>t.id===e._activePageId))||(e.pages.length?e.pages[0]:null)}}))).actions((e=>({setRole(t){e.role=t},getElementById(t){for(const n of e.pages)for(const e of n.children)if(e.id===t)return e},addPage(t){const n=Sq.create({id:vq(10),...t});return e.pages.push(n),e._activePageId=n.id,n},selectPage(t){e._activePageId=t},selectElements(t){e.selectedElementsIds=t},_toggleBleed(t){e._bleedVisible=t??!e._bleedVisible},openSidePanel(t){e.openedSidePanel=t},setScale(t){e.scale=t},_setScaleToFit(t){e.scaleToFit=t},setElementsPixelRatio(t){e._elementsPixelRatio=t},setSize(t,n,r){if(r){const r=t/e.width,i=n/e.height;for(const t of e.pages)for(const e of t.children)e.set({x:e.x*r,y:e.y*i}),"text"===e.type?e.set({fontSize:e.fontSize*r,width:Math.max(e.width*r,2)}):"image"===e.type?e.set({width:e.width*r,height:e.height*i}):"svg"===e.type&&e.set({width:Math.max(e.width*r,2),height:Math.max(e.height*r,2)})}e.width=t,e.height=n},setPageZIndex(t,n){const r=e.pages.find((e=>e.id===t));r&&(wF(r),e.pages.remove(r),e.pages.splice(n,0,r))},deletePages(t){const n=e.pages.indexOf(e.activePage);t.forEach((t=>{xF(e.pages.find((e=>e.id===t)))}));const r=Math.min(e.pages.length-1,n),i=e.pages[r];i&&(e._activePageId=i.id),e.selectedElementsIds=e.selectedElementsIds.filter((t=>e.getElementById(t)))},deleteElements(t){t.forEach((t=>{e.pages.forEach((e=>{const n=e.children.find((e=>e.id===t));n&&xF(n)}))})),e.selectedElementsIds=[]},on(t,n){if("change"===t){let t=e.toJSON();return pF(e,(r=>{const i=e.toJSON();JSON.stringify(i)!==JSON.stringify(t)&&(t=i,n(i))}))}},async toDataURL({pixelRatio:t,ignoreBackground:n,pageId:r,mimeType:i,includeBleed:o,quality:a}={}){const l=t||1;r=r||e.pages[0]?.id;const s=e.pages.find((e=>e.id===r));if(!s)throw new Error(`No page for export with id ${r}`);s?.set({_exporting:!0}),await new Promise((e=>{setTimeout(e,0)})),await e.waitLoading();const c=cl.stages.find((e=>e.getAttr("pageId")===r));if(!c)throw new 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.`);const u=c.findOne(".page-container");c.find("Transformer").forEach((e=>e.visible(!1))),u.findOne(".page-background").shadowEnabled(!1),u.findOne(".page-background").strokeEnabled(!1),u.find(".highlighter").forEach((e=>e.visible(!1)));const h=u.findOne(".page-background-group"),f=h.clip();h.clip({x:null,y:null,width:null,height:null});const d=u.find((e=>e.getAttr("hideInExport")));d.forEach((e=>{e.setAttr("oldVisible",e.visible()),e.hide()})),n&&u.findOne(".page-background").hide();const p=o?s.bleed:0;let v=p;e._bleedVisible&&o?v=0:e._bleedVisible&&!o&&(v=-s.bleed);const m=u.toDataURL({x:u.x()-v*u.scaleX(),y:u.y()-v*u.scaleY(),width:(s.computedWidth+2*p)*u.scaleX(),height:(s.computedHeight+2*p)*u.scaleY(),pixelRatio:1/u.scaleX()*l,mimeType:i,quality:a});return n&&u.findOne(".page-background").show(),d.forEach((e=>{e.visible(e.getAttr("oldVisible"))})),u.findOne(".page-background").shadowEnabled(!0),u.findOne(".page-background").strokeEnabled(!0),c.find("Transformer").forEach((e=>e.visible(!0))),u.find(".highlighter").forEach((e=>e.visible(!0))),h.clip(f),s?.set({_exporting:!1}),m},async saveAsImage({fileName:t,...n}={}){const r=n.mimeType||"image/png",i=r.split("/")[1];!async function(e,t){const n=await(await fetch(e)).blob(),r=document.createElement("a"),i=URL.createObjectURL(n);r.href=i,r.download=t,document.body.appendChild(r),r.click(),setTimeout((function(){document.body.removeChild(r),window.URL.revokeObjectURL(i)}),0)}(await e.toDataURL(n),t||"polotno."+i)},async _toPDF(t){const n=t.dpi||300,r=t.parallel||1,i=await(mq?Promise.resolve(mq):new Promise((e=>{var t=document.createElement("script");t.onload=function(){mq=window.jspdf.jsPDF,e(mq)},t.src="https://unpkg.com/jspdf@2.2.0/dist/jspdf.umd.min.js",document.head.appendChild(t)}))),o=e=>.75*e;var a=new i({unit:"pt",orientation:e.width>e.height?"landscape":"portrait",format:[o(e.width),o(e.height)],compress:!0});a.deletePage(1);const l=e._elementsPixelRatio,s=n/72;e.setElementsPixelRatio(s),await new Promise((e=>setTimeout(e)));const c=((e,t)=>{for(var n=[],r=0;r<e.length;r+=t)n.push(e.slice(r,r+t));return n})(e.pages,r);for(const n of c){const r=n.map((async n=>{const r=t.includeBleed?n.bleed:0,i=o(n.computedWidth+r),a=o(n.computedHeight+r);let l=0,c=s;for(;l<10;){l+=1,2===l&&console.error("Polotno can not export PDF with current settings. Quality is automatically reduced.");const r=await e.toDataURL({...t,pageId:n.id,pixelRatio:c});if(r.length>20)return{url:r,width:i,height:a};c*=.8}}));(await Promise.all(r)).forEach((({url:e,width:t,height:n})=>{a.addPage([t,n],t>n?"landscape":"portrait"),a.addImage(e,0,0,t,n,void 0,"FAST")}))}return e.setElementsPixelRatio(l),a},toPDFDataURL:async t=>(await e._toPDF({mimeType:"image/jpeg",...t})).output("datauristring"),async saveAsPDF({fileName:t,...n}={}){(await e._toPDF({mimeType:"image/jpeg",...n})).save(t||"polotno.pdf")},async waitLoading(){await Cs()},toJSON:()=>({width:e.width,height:e.height,fonts:gF(e.fonts),pages:gF(e.pages)}),loadJSON(t,n=!1){const r={...t};e.pages.forEach((e=>e.children.forEach((e=>wF(e))))),e.pages=[],r._activePageId=r.pages[0]?.id,r.scale=e.scale,r.openedSidePanel=e.openedSidePanel,r._bleedVisible=e._bleedVisible,n&&(r.history=e.history.toJSON()),mF(e,r)},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=>xF(e)))},async loadFont(t){const n=e.fonts.find((e=>e.fontFamily===t))||BC.find((e=>e.fontFamily===t));n?function(e){const t=e.fontFamily;if(YC[t])return;if(!e.url&&!e.styles)return;const n=document.createElement("style");n.type="text/css";const r=e.styles||(e.url?[{src:`url("${e.url}")`}]:[]);let i="";r.forEach((e=>{i+=`\n @font-face {\n font-family: '${t}';\n src: ${e.src};\n font-style: ${e.fontStyle||"normal"};\n font-weight: ${e.fontWeight||"normal"};\n }\n `})),n.innerHTML=i,document.getElementsByTagName("head")[0].appendChild(n),YC[e.fontFamily]=!0}(n):function(e){if(KC[e])return;const t=`https://fonts.googleapis.com/css?family=${e.replace(/ /g,"+")}`,n=document.createElement("link");n.type="text/css",n.href=t,n.rel="stylesheet",document.getElementsByTagName("head")[0].appendChild(n),KC[e]=!0}(t),await WC(t)}})));function Mq({key:e,showCredit:t}={key:"",showCredit:!1}){const n=Oq.create();return pS(e,t),n}const kq=Eu("div")`
|
|
329
329
|
display: flex;
|
|
330
330
|
height: 100%;
|
|
331
331
|
width: 100%;
|