polotno-node 0.3.1 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -263,13 +263,13 @@ var r,t=arguments[3];!function(n){if("object"==typeof exports&&"undefined"!=type
|
|
|
263
263
|
var define;
|
|
264
264
|
var e;!function(t,n){void 0===t&&void 0!==window&&(t=window),"function"==typeof e&&e.amd?e(["url","xmlserializer","sane-domparser-error","inlineresources"],function(e,r,o,i){return t.rasterizeHTML=n(e,r,o,i)}):"object"==typeof module&&module.exports?module.exports=n(require("url"),require("xmlserializer"),require("sane-domparser-error"),require("inlineresources")):t.rasterizeHTML=n(t.url,t.xmlserializer,t.sanedomparsererror,t.inlineresources)}(this,function(e,t,n,r){var o=function(e){"use strict";var t={},n=[];t.joinUrl=function(t,n){return t?e.resolve(t,n):n},t.getConstantUniqueIdFor=function(e){return n.indexOf(e)<0&&n.push(e),n.indexOf(e)},t.clone=function(e){var t,n={};for(t in e)e.hasOwnProperty(t)&&(n[t]=e[t]);return n};return t.parseOptionalParameters=function(e){var n,r={canvas:null,options:{}};return null==e[0]||function(e){return"object"==typeof e&&null!==e}(n=e[0])&&Object.prototype.toString.apply(n).match(/\[object (Canvas|HTMLCanvasElement)\]/i)?(r.canvas=e[0]||null,r.options=t.clone(e[1])):r.options=t.clone(e[0]),r},t}(e),i=function(e){"use strict";var t={},n=function(e,t,n){var r=e[t];return e[t]=function(){var e=Array.prototype.slice.call(arguments);return n.apply(this,[e,r])},r};return t.baseUrlRespectingXhr=function(t,r){return function(){var o=new t;return n(o,"open",function(t,n){var o=t.shift(),i=t.shift(),u=e.joinUrl(r,i);return n.apply(this,[o,u].concat(t))}),o}},t.finishNotifyingXhr=function(e){var t,r=0,o=0,i=!1,u=new Promise(function(e){t=function(){r-o<=0&&i&&e({totalCount:r})}}),c=function(){var i=new e;return n(i,"send",function(e,t){return r+=1,t.apply(this,arguments)}),i.addEventListener("load",function(){o+=1,t()}),i};return c.waitForRequestsToFinish=function(){return i=!0,t(),u},c},t}(o),u=function(e){"use strict";var t={},n=function(e){return Array.prototype.slice.call(e)},r={active:!0,hover:!0,focus:!1,target:!1};return t.fakeUserAction=function(t,n,o){var i=t.querySelector(n),u=":"+o,c="rasterizehtml"+o;i&&(r[o]?e.addClassNameRecursively(i,c):e.addClassName(i,c),e.rewriteCssSelectorWith(t,u,"."+c))},t.persistInputValues=function(e){var t=e.querySelectorAll("input"),r=e.querySelectorAll("textarea"),o=function(e){return"checkbox"===e.type||"radio"===e.type};n(t).filter(o).forEach(function(e){e.checked?e.setAttribute("checked",""):e.removeAttribute("checked")}),n(t).filter(function(e){return!o(e)}).forEach(function(e){e.setAttribute("value",e.value)}),n(r).forEach(function(e){e.textContent=e.value})},t.rewriteTagNameSelectorsToLowerCase=function(t){e.lowercaseCssTypeSelectors(t,e.findHtmlOnlyNodeNames(t))},t}(function(){"use strict";var e={},t=function(e){return Array.prototype.slice.call(e)};e.addClassName=function(e,t){e.className+=" "+t},e.addClassNameRecursively=function(t,n){e.addClassName(t,n),t.parentNode!==t.ownerDocument&&e.addClassNameRecursively(t.parentNode,n)};var n=function(e,n){var r=e.cssText.replace(/^[^\{]+/,"");!function(e,n){var r=e.parentStyleSheet,o=t(r.cssRules).indexOf(e);r.insertRule(n,o+1),r.deleteRule(o)}(e,n+" "+r)},r=function(e){var n;e.textContent=(n=e.sheet.cssRules,t(n).reduce(function(e,t){return e+t.cssText},""))},o=function(e,o,i){var u=function(e){return"((?:^|[^.#:\\w])|(?=\\W))("+e.join("|")+")(?=\\W|$)"}(o);t(e.querySelectorAll("style")).forEach(function(e){var o,c,a;void 0===e.sheet&&(o=e,c=document.implementation.createHTMLDocument(""),(a=document.createElement("style")).textContent=o.textContent,c.body.appendChild(a),o.sheet=a.sheet);var s=t(e.sheet.cssRules).filter(function(e){return e.selectorText&&new RegExp(u,"i").test(e.selectorText)});s.length&&(s.forEach(function(e){var t=e.selectorText.replace(new RegExp(u,"gi"),function(e,t,n){return t+i(n)});t!==e.selectorText&&n(e,t)}),r(e))})};return e.rewriteCssSelectorWith=function(e,t,n){o(e,[t],function(){return n})},e.lowercaseCssTypeSelectors=function(e,t){o(e,t,function(e){return e.toLowerCase()})},e.findHtmlOnlyNodeNames=function(e){var t,n=e.ownerDocument.createTreeWalker(e,NodeFilter.SHOW_ELEMENT),r={},o={};do{t=n.currentNode.tagName.toLowerCase(),"http://www.w3.org/1999/xhtml"===n.currentNode.namespaceURI?r[t]=!0:o[t]=!0}while(n.nextNode());return Object.keys(r).filter(function(e){return!o[e]})},e}()),c=function(e,t,n,r){"use strict";var o={};o.executeJavascript=function(e,n){return new Promise(function(o){var i=function(e,t,n,r){var o=e.createElement(t);return o.style.visibility="hidden",o.style.width=n+"px",o.style.height=r+"px",o.style.position="absolute",o.style.top=-1e4-r+"px",o.style.left=-1e4-n+"px",e.getElementsByTagName("body")[0].appendChild(o),o}(r.document,"iframe",n.width,n.height),u=e.outerHTML,c=[],a=n.executeJsTimeout||0,s=function(){r.document.getElementsByTagName("body")[0].removeChild(i)},l=function(){var e=i.contentDocument;o({document:e,errors:c,cleanUp:s})},f=i.contentWindow.XMLHttpRequest,m=t.finishNotifyingXhr(f),d=t.baseUrlRespectingXhr(m,n.baseUrl);i.onload=function(){var e;(e=a,e>0?new Promise(function(t){setTimeout(t,e)}):Promise.resolve()).then(m.waitForRequestsToFinish).then(l)},i.contentDocument.open(),i.contentWindow.XMLHttpRequest=d,i.contentWindow.onerror=function(e){c.push({resourceType:"scriptExecution",msg:e})},i.contentDocument.write("<!DOCTYPE html>"),i.contentDocument.write(u),i.contentDocument.close()})};var i=function(e,t,n,o,i){var u,c,a,s,l,f,m,d=Math.max(e.scrollWidth,e.clientWidth),h=Math.max(e.scrollHeight,e.clientHeight);return t?(u=(f=function(e,t){var n=e.querySelector(t);if(n)return n;if(e.ownerDocument.querySelector(t)===e)return e;throw{message:"Clipping selector not found"}}(e,t).getBoundingClientRect()).top,c=f.left,a=f.width,s=f.height):(u=0,c=0,a=d,s=h),m=function(e,t,n,r){return{width:Math.max(e.width*r,t),height:Math.max(e.height*r,n)}}({width:a,height:s},n,o,i),l=r.getComputedStyle(e.ownerDocument.documentElement).fontSize,{left:c,top:u,width:m.width,height:m.height,viewportWidth:d,viewportHeight:h,rootFontSize:l}};o.calculateDocumentContentSize=function(e,t){return new Promise(function(n,o){var u,c=t.zoom||1;u=function(e,t,n){var o=Math.floor(e/n),i=Math.floor(t/n);return function(e,t,n){var r=e.createElement("iframe");return r.style.width=t+"px",r.style.height=n+"px",r.style.visibility="hidden",r.style.position="absolute",r.style.top=-1e4-n+"px",r.style.left=-1e4-t+"px",r.style.borderWidth=0,r.sandbox="allow-same-origin",r.scrolling="no",r}(r.document,o,i)}(t.width,t.height,c),r.document.getElementsByTagName("body")[0].appendChild(u),u.onload=function(){var a,s=u.contentDocument;try{a=i(function(e,t){var n=e.tagName;return t.querySelector(n)}(e,s),t.clip,t.width,t.height,c),n(a)}catch(l){o(l)}finally{r.document.getElementsByTagName("body")[0].removeChild(u)}},u.contentDocument.open(),u.contentDocument.write("<!DOCTYPE html>"),u.contentDocument.write(function(e){var t=e.tagName.toLowerCase();return"html"===t||"body"===t?e.outerHTML:'<body style="margin: 0;">'+e.outerHTML+"</body>"}(e)),u.contentDocument.close()})},o.parseHtmlFragment=function(e){var t=r.document.implementation.createHTMLDocument("");t.documentElement.innerHTML=e;var n=t.querySelector("body").firstChild;if(!n)throw"Invalid source";return n};o.parseHTML=function(e){var t=r.document.implementation.createHTMLDocument("");return t.documentElement.innerHTML=e,function(e,t){var n,o,i,u,c=/<html((?:\s+[^>]*)?)>/im.exec(t),a=r.document.implementation.createHTMLDocument("");if(c)for(n="<div"+c[1]+"></div>",a.documentElement.innerHTML=n,i=a.querySelector("div"),o=0;o<i.attributes.length;o++)u=i.attributes[o],e.documentElement.setAttribute(u.name,u.value)}(t,e),t};var u=function(e){try{return n.failOnParseError(e)}catch(t){throw{message:"Invalid source",originalError:t}}};o.validateXHTML=function(e){var t=(new DOMParser).parseFromString(e,"application/xml");u(t)};var c=null,a=function(t,n){return new Promise(function(r,o){var i=new window.XMLHttpRequest,u=function(e,t){return"none"===t||"repeated"===t?(null!==c&&"repeated"===t||(c=Date.now()),e+"?_="+c):e}(e.joinUrl(n.baseUrl,t),n.cache),a=function(e){o({message:"Unable to load page",originalError:e})};i.addEventListener("load",function(){200===i.status||0===i.status?r(i.responseXML):a(i.statusText)},!1),i.addEventListener("error",function(e){a(e)},!1);try{i.open("GET",u,!0),i.responseType="document",i.send(null)}catch(s){a(s)}})};return o.loadDocument=function(e,t){return a(e,t).then(function(e){return u(e)})},o}(o,i,n,window),a=function(e){"use strict";var t,n={},r=function(e,t){return t?URL.createObjectURL(new Blob([e],{type:"image/svg+xml"})):"data:image/svg+xml;charset=utf-8,"+encodeURIComponent(e)},o=function(e){e instanceof Blob&&URL.revokeObjectURL(e)},i='<svg xmlns="http://www.w3.org/2000/svg" width="1" height="1"><foreignObject></foreignObject></svg>',u=function(e){return new Promise(function(t,n){var r=document.createElement("canvas"),o=new Image;o.onload=function(){var e=r.getContext("2d");try{e.drawImage(o,0,0),r.toDataURL("image/png"),t(!0)}catch(n){t(!1)}},o.onerror=n,o.src=e})},c=function(){return new Promise(function(t,n){var c;(function(){if(e.Blob)try{return new Blob(["<b></b>"],{type:"text/xml"}),!0}catch(t){}return!1})()&&e.URL?(c=r(i,!0),u(c).then(function(e){return o(c),!e&&u(r(i,!1)).then(function(e){return e})},function(){return!1})).then(function(e){t(!e)},function(){n()}):t(!1)})},a=function(e){return(void 0===t&&(t=c()),t).then(function(t){return r(e,t)})};return n.renderSvg=function(e){return new Promise(function(t,n){var r,i,u=function(){r&&o(r)};(i=new Image).onload=function(){i.onload=null,i.onerror=null,u(),t(i)},i.onerror=function(){u(),n()},a(e).then(function(e){r=e,i.src=r},n)})},n}(window),s=function(e,t,n,r){"use strict";var o={},i=function(e){var t=Object.keys(e);return t.length?" "+t.map(function(t){return t+'="'+e[t]+'"'}).join(" "):""},u=function(e,n,o){var u=r.serializeToString(e);t.validateXHTML(u);var c,a,s=function(e){var t,n;return t=Math.round(e.viewportWidth),n=Math.round(e.viewportHeight),{x:-e.left,y:-e.top,width:t,height:n}}(n);return a=(c=s).style||"",c.style=a+"float: left;",function(e){e.externalResourcesRequired=!0}(s),'<svg xmlns="http://www.w3.org/2000/svg"'+i(function(e,t){var n=t||1,r={width:e.width,height:e.height,"font-size":e.rootFontSize};return 1!==n&&(r.style="transform:scale("+n+"); transform-origin: 0 0;"),r}(n,o))+'><style scoped="">html::-webkit-scrollbar { display: none; }</style><foreignObject'+i(s)+">"+u+"</foreignObject></svg>"};return o.getSvgForDocument=function(e,t,r){return n.rewriteTagNameSelectorsToLowerCase(e),u(e,t,r)},o.drawDocumentAsSvg=function(e,r){return["hover","active","focus","target"].forEach(function(t){r[t]&&n.fakeUserAction(e,r[t],t)}),t.calculateDocumentContentSize(e,r).then(function(t){return o.getSvgForDocument(e,t,r.zoom)})},o}(0,c,u,t),l=function(e,t,n,r,o,i){"use strict";var u={},c=function(e){return{message:"Error rendering page",originalError:e}},a=function(e){return o.renderSvg(e).then(function(t){return{image:t,svg:e}},function(e){throw c(e)})},s=function(e,t,n){return r.drawDocumentAsSvg(e,n).then(a).then(function(e){return t&&function(e,t){try{t.getContext("2d").drawImage(e,0,0)}catch(n){throw c(n)}}(e.image,t),e})};return u.rasterize=function(r,o,u){var c;return(c=e.clone(u)).inlineScripts=!0===u.executeJs,i.inlineReferences(r,c).then(function(e){return u.executeJs?function(e,r){return t.executeJavascript(e,r).then(function(e){var t=e.document;return n.persistInputValues(t),{document:t,errors:e.errors,cleanUp:e.cleanUp}})}(r,u).then(function(t){return{element:t.document.documentElement,errors:e.concat(t.errors),cleanUp:t.cleanUp}}):{element:r,errors:e,cleanUp:function(){}}}).then(function(e){return s(e.element,o,u).then(function(t){return e.cleanUp(),{image:t.image,svg:t.svg,errors:e.errors}})})},u}(o,c,u,s,a,r);return function(e,t,n){"use strict";var r={};r.drawDocument=function(){var t=arguments[0],r=Array.prototype.slice.call(arguments,1),o=e.parseOptionalParameters(r),i=t.documentElement?t.documentElement:t;return n.rasterize(i,o.canvas,function(t){var n,r=function(e,t){var n=e?e.width:300,r=e?e.height:200;return{width:void 0!==t.width?t.width:n,height:void 0!==t.height?t.height:r}}(t.canvas,t.options);return(n=e.clone(t.options)).width=r.width,n.height=r.height,n}(o))};r.drawHTML=function(){var n=arguments[0],o=Array.prototype.slice.call(arguments,1),i=e.parseOptionalParameters(o);return function(e,n,o){var i=t.parseHTML(e);return r.drawDocument(i,n,o)}(n,i.canvas,i.options)};var o=function(n,o,i){return t.loadDocument(n,i).then(function(t){var u=function(t,n,r){var o=document.implementation.createHTMLDocument("");o.replaceChild(t.documentElement,o.documentElement);var i=r?e.clone(r):{};return r.baseUrl||(i.baseUrl=n),{document:o,options:i}}(t,n,i);return r.drawDocument(u.document,o,u.options)})};return r.drawURL=function(){var t=arguments[0],n=Array.prototype.slice.call(arguments,1),r=e.parseOptionalParameters(n);return o(t,r.canvas,r.options)},r}(o,c,l)});
|
|
265
265
|
},{"url":"j37I","xmlserializer":"JMLK","sane-domparser-error":"ZgwT","inlineresources":"hv1m"}],"vcNA":[function(require,module,exports) {
|
|
266
|
-
"use strict";var e=this&&this.__createBinding||(Object.create?function(e,t,n,i){void 0===i&&(i=n),Object.defineProperty(e,i,{enumerable:!0,get:function(){return t[n]}})}:function(e,t,n,i){void 0===i&&(i=n),e[i]=t[n]}),t=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||function(n){if(n&&n.__esModule)return n;var i={};if(null!=n)for(var o in n)"default"!==o&&Object.prototype.hasOwnProperty.call(n,o)&&e(i,n,o);return t(i,n),i};Object.defineProperty(exports,"__esModule",{value:!0}),exports.htmlToCanvas=exports.detectSize=void 0;const i=n(require("rasterizehtml")),o=2;function
|
|
266
|
+
"use strict";var e=this&&this.__createBinding||(Object.create?function(e,t,n,i){void 0===i&&(i=n),Object.defineProperty(e,i,{enumerable:!0,get:function(){return t[n]}})}:function(e,t,n,i){void 0===i&&(i=n),e[i]=t[n]}),t=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||function(n){if(n&&n.__esModule)return n;var i={};if(null!=n)for(var o in n)"default"!==o&&Object.prototype.hasOwnProperty.call(n,o)&&e(i,n,o);return t(i,n),i};Object.defineProperty(exports,"__esModule",{value:!0}),exports.htmlToCanvas=exports.detectSize=void 0;const i=n(require("rasterizehtml")),o=2,l="\n<style>\n html, body {\n padding: 0;\n margin: 0;\n }\n p {\n margin: 0;\n padding: 0\n }\n ul {\n list-style-position: inside;\n margin: 0;\n }\n</style>\n",d=document.createElement("div");function s(e){const t=document.createElement("div");t.innerHTML=e,t.style.display="inline-block",t.style.position="fixed",t.style.top="0px",t.style.left="0px",t.style.zIndex="1000",d.appendChild(t);const n=t.getBoundingClientRect();return d.removeChild(t),{width:n.width,height:n.height}}async function r({html:e,width:t,height:n,fontFamily:o}){const d=document.createElement("canvas");"Arial"!==o&&(e+=`<link type="text/css" href="https://fonts.googleapis.com/css?family=${o}" rel="stylesheet">`),e+=l;const s=await i.drawHTML(e,d,{width:t,height:n});d.width=2*t,d.height=2*n;const r=d.getContext("2d");return null==r||r.drawImage(s.image,0,0,2*s.image.width,2*s.image.height),d}d.id="polotno-hidden-do-not-touch",d.style.overflow="hidden",d.style.position="relative",document.body.appendChild(d),d.innerHTML="<style>\n#polotno-hidden-do-not-touch p {\n margin: 0;\n padding: 0\n}\n#polotno-hidden-do-not-touch ul {\n list-style-position: inside;\n margin: 0;\n}\n</style>",exports.detectSize=s,exports.htmlToCanvas=r;
|
|
267
267
|
},{"rasterizehtml":"x2pr"}],"MEVn":[function(require,module,exports) {
|
|
268
268
|
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.styled=exports.setup=exports.keyframes=exports.glob=exports.extractCss=exports.css=void 0;let e={data:""},t=t=>"object"==typeof window?((t?t.querySelector("#_goober"):window._goober)||Object.assign((t||document.head).appendChild(document.createElement("style")),{innerHTML:" ",id:"_goober"})).firstChild:t||e,r=e=>{let r=t(e),s=r.data;return r.data="",s},s=/(?:([\u0080-\uFFFF\w-%@]+) *:? *([^{;]+?);|([^;}{]*?) *{)|(}\s*)/g,o=/\/\*[^]*?\*\/|\s\s+|\n/g,l=(e,t)=>{let r="",s="",o="";for(let a in e){let n=e[a];"@"==a[0]?"i"==a[1]?r=a+" "+n+";":s+="f"==a[1]?l(n,a):a+"{"+l(n,"k"==a[1]?"":t)+"}":"object"==typeof n?s+=l(n,t?t.replace(/([^,])+/g,e=>a.replace(/(^:.*)|([^,])+/g,t=>/&/.test(t)?t.replace(/&/g,e):e?e+" "+t:t)):a):null!=n&&(a=a.replace(/[A-Z]/g,"-$&").toLowerCase(),o+=l.p?l.p(a,n):a+":"+n+";")}return r+(t&&o?t+"{"+o+"}":o)+s},a={},n=e=>{if("object"==typeof e){let t="";for(let r in e)t+=r+n(e[r]);return t}return e},p=(e,t,r,p,c)=>{let i=n(e),u=a[i]||(a[i]=(e=>{let t=0,r=11;for(;t<e.length;)r=101*r+e.charCodeAt(t++)>>>0;return"go"+r})(i));if(!a[u]){let t=i!==e?e:(e=>{let t,r=[{}];for(;t=s.exec(e.replace(o,""));)t[4]?r.shift():t[3]?r.unshift(r[0][t[3]]=r[0][t[3]]||{}):r[0][t[1]]=t[2];return r[0]})(e);a[u]=l(c?{["@keyframes "+u]:t}:t,r?"":"."+u)}return((e,t,r)=>{-1==t.data.indexOf(e)&&(t.data=r?e+t.data:t.data+e)})(a[u],t,p),u},c=(e,t,r)=>e.reduce((e,s,o)=>{let a=t[o];if(a&&a.call){let e=a(r),t=e&&e.props&&e.props.className||/^go/.test(e)&&e;a=t?"."+t:e&&"object"==typeof e?e.props?"":l(e,""):!1===e?"":e}return e+s+(null==a?"":a)},"");function i(e){let r=this||{},s=e.call?e(r.p):e;return p(s.unshift?s.raw?c(s,[].slice.call(arguments,1),r.p):s.reduce((e,t)=>Object.assign(e,t&&t.call?t(r.p):t),{}):s,t(r.target),r.g,r.o,r.k)}exports.extractCss=r,exports.css=i;let u,d,f,g=i.bind({g:1}),x=i.bind({k:1});function b(e,t,r,s){l.p=t,u=e,d=r,f=s}function y(e,t){let r=this||{};return function(){let s=arguments;function o(l,a){let n=Object.assign({},l),p=n.className||o.className;r.p=Object.assign({theme:d&&d()},n),r.o=/ *go\d+/.test(p),n.className=i.apply(r,s)+(p?" "+p:""),t&&(n.ref=a);let c=e;return e[0]&&(c=n.as||e,delete n.as),f&&c[0]&&f(n),u(c,n)}return t?t(o):o}}exports.glob=g,exports.keyframes=x,exports.setup=b,exports.styled=y;
|
|
269
269
|
},{}],"PsiH":[function(require,module,exports) {
|
|
270
270
|
"use strict";var e=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0});const t=e(require("react")),r=require("./goober");(0,r.setup)(t.default.createElement),exports.default=r.styled;
|
|
271
271
|
},{"react":"HdMw","./goober":"MEVn"}],"BLZX":[function(require,module,exports) {
|
|
272
|
-
"use strict";var e=this&&this.__createBinding||(Object.create?function(e,t,n
|
|
272
|
+
"use strict";var e=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r),Object.defineProperty(e,n,{enumerable:!0,get:function(){return t[r]}})}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),t=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),r=this&&this.__importStar||function(r){if(r&&r.__esModule)return r;var n={};if(null!=r)for(var i in r)"default"!==i&&Object.prototype.hasOwnProperty.call(r,i)&&e(n,r,i);return t(n,r),n},n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.HTMLElement=exports.quillRef=void 0;const i=n(require("react")),l=require("mobx-react-lite"),o=require("react-konva"),a=n(require("quill/dist/quill")),u=n(require("konva")),s=r(require("mobx")),d=require("./apply-filters"),c=require("./text-element"),f=require("../utils/html2canvas"),g=require("./use-fadein"),h=require("./highlighter"),m=require("react-konva-utils"),p=n(require("../utils/styled")),v=require("../utils/loader");exports.quillRef=s.observable({enabled:!1,currentFormat:{},editor:s.observable.object({instance:null},{},{deep:!1})});const y=(0,p.default)("div",i.default.forwardRef)`
|
|
273
273
|
.ql-editor {
|
|
274
274
|
outline: none;
|
|
275
275
|
}
|
|
@@ -277,8 +277,12 @@ var e;!function(t,n){void 0===t&&void 0!==window&&(t=window),"function"==typeof
|
|
|
277
277
|
list-style-position: inside;
|
|
278
278
|
margin: 0;
|
|
279
279
|
}
|
|
280
|
-
|
|
281
|
-
|
|
280
|
+
p {
|
|
281
|
+
line-height: auto;
|
|
282
|
+
margin: 0;
|
|
283
|
+
}
|
|
284
|
+
`,x=({html:e,onBlur:t,onChange:r,element:n})=>{const l=i.default.useRef(null);return i.default.useEffect(()=>{if(!l.current)return;const e=new a.default(l.current,{toolbar:!1,keyboard:!1,clipboard:{matchVisual:!1}});return exports.quillRef.editor.instance=e,window.__polotnoQuill=e,e.on("text-change",()=>{var t;e.getSelection()&&(exports.quillRef.currentFormat=e.getFormat()),r(null===(t=l.current)||void 0===t?void 0:t.childNodes[0].innerHTML)}),e.setSelection(0,0,"api"),e.on("selection-change",r=>{r||t(),r&&(exports.quillRef.currentFormat=e.getFormat())}),l.current.childNodes[0].addEventListener("blur",e=>{var r;(null===(r=e.relatedTarget)||void 0===r?void 0:r.classList.contains("ql-clipboard"))||t()}),()=>{exports.quillRef.editor.instance=null,exports.quillRef.currentFormat={},delete window.__polotnoQuill}},[]),i.default.useEffect(()=>{var t;const r=exports.quillRef.editor.instance,i=r.getSelection();if((null===(t=l.current)||void 0===t?void 0:t.childNodes[0].innerHTML)!==n.text){var o=r.clipboard.convert("<div class='ql-editor' style='outline: none;'>"+e+"<p><br></p></div>");r.setContents(o),r.history.clear(),i&&(r.setSelection(i.index,i.length),exports.quillRef.currentFormat=r.getFormat())}},[n.text]),i.default.createElement(y,{ref:l,style:{fontSize:n.fontSize,color:n.fill,width:n.width,fontFamily:n.fontFamily,lineHeight:n.lineHeight,letterSpacing:n.letterSpacing,textAlign:n.align}})};function b(e,t,r){return i.default.useMemo(()=>(0,f.detectSize)(e),[e,t.width,r])}exports.HTMLElement=(0,l.observer)(({element:e,store:t})=>{const r=i.default.useRef(null),[n,l]=i.default.useState(),[a,p]=i.default.useState(!1),[w,q]=i.default.useState(!0),[E,S]=i.default.useState(!1),[_,F]=i.default.useState(!1),T=t.selectedElements.indexOf(e)>=0,[M]=(0,c.useFontLoader)(t,e.fontFamily);(0,g.useFadeIn)(r);const k=M?e.fontFamily:"Arial",$=`<div style="width: ${e.width||100}px; color: ${e.fill}; font-size: ${e.fontSize}px; font-family: '${k}'; text-decoration: ${e.textDecoration}; text-align: ${e.align}; line-height: ${e.lineHeight}; letter-spacing: ${e.letterSpacing}; font-style: ${e.fontStyle}; font-weight: ${e.fontWeight}; -webkit-text-stroke: ${e.strokeWidth}px ${e.stroke}" contentEditable>${e.text}</div>`,{width:L,height:R}=b($,e,M);i.default.useEffect(()=>{e.set({height:R})},[R]),i.default.useLayoutEffect(()=>{if(a||E)return;const t=(0,v.incrementLoader)();q(!0),async function(){await new Promise(e=>setTimeout(e));const r=await(0,f.htmlToCanvas)({html:$,width:e.width||1,height:R||1,fontFamily:k});l(r),q(!1),u.default.Util.requestAnimFrame(t)}()},[$,a,R,E,k]);const H=a||w;return i.default.useLayoutEffect(()=>s.autorun(()=>{const t=r.current;(0,d.applyFilter)(t,e)}),[n,H]),i.default.createElement(i.default.Fragment,null,i.default.createElement(o.Image,{ref:r,name:"element",image:n,x:e.x,y:e.y,rotation:e.rotation,width:e.width,height:e.height,visible:!H,draggable:!e.locked,opacity:E?0:e.opacity,shadowEnabled:e.shadowEnabled,shadowBlur:e.shadowBlur,onMouseEnter:()=>{F(!0)},onMouseLeave:()=>{F(!1)},onDragStart:()=>{t.history.startTransaction()},onDragMove:t=>{setTimeout(()=>{e.set({x:t.target.x(),y:t.target.y()})})},onDragEnd:r=>{e.set({x:r.target.x(),y:r.target.y()}),t.history.endTransaction()},id:e.id,onDblClick:()=>{e.locked||S(!0)},onDblTap:()=>{e.locked||S(!0)},onTransformStart:e=>{var t;const r=(null===(t=e.target.getStage())||void 0===t?void 0:t.findOne("Transformer")).getActiveAnchor();("middle-left"===r||"middle-right"===r)&&p(!0)},onTransform:t=>{var r;const n=(null===(r=t.target.getStage())||void 0===r?void 0:r.findOne("Transformer")).getActiveAnchor();if("middle-left"===n||"middle-right"===n){const r=t.target.scaleX(),n=Math.max(t.target.width()*r,e.fontSize);t.target.width(n),t.target.scaleX(1),e.set({width:n})}e.set({x:t.target.x(),y:t.target.y(),rotation:t.target.rotation()})},onTransformEnd:t=>{p(!1),q(!0);const r=t.target.scaleX();t.target.scaleX(1),t.target.scaleY(1),e.set({fontSize:e.fontSize*r,width:t.target.width()*r,x:t.target.x(),y:t.target.y(),rotation:t.target.rotation()})}}),H&&i.default.createElement(o.Group,{x:e.x,y:e.y,rotation:e.rotation},i.default.createElement(m.Html,{divProps:{style:{pointerEvents:"none"}}},i.default.createElement(y,{dangerouslySetInnerHTML:{__html:$},style:{pointerEvents:"none",display:"inline-block"}}))),E&&i.default.createElement(o.Group,{x:e.x,y:e.y,rotation:e.rotation},i.default.createElement(m.Html,null,i.default.createElement(x,{html:$,element:e,onChange:t=>{e.set({text:t})},onBlur:e=>{S(!1)}}))),(T||_)&&i.default.createElement(h.Highlighter,{element:e}))});
|
|
285
|
+
},{"react":"HdMw","mobx-react-lite":"ZfSi","react-konva":"Sgug","quill/dist/quill":"qREC","konva":"aTGn","mobx":"BzvP","./apply-filters":"SIWI","./text-element":"Fpgh","../utils/html2canvas":"vcNA","./use-fadein":"N3c2","./highlighter":"cEy1","react-konva-utils":"jXQU","../utils/styled":"PsiH","../utils/loader":"bN4e"}],"XEPK":[function(require,module,exports) {
|
|
282
286
|
"use strict";var e=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.registerShapeComponent=void 0;const t=e(require("react")),r=require("mobx-react-lite"),n=require("./text-element"),l=require("./image-element"),o=require("./html-element"),i=require("../utils/flags"),m={text:n.TextElement,image:l.ImageElement,svg:l.ImageElement};function s(e,t){m[e]=t}exports.registerShapeComponent=s,exports.default=(0,r.observer)(e=>{let r=m[e.element.type];return"text"===e.element.type&&i.flags.htmlRenderEnabled&&(r=o.HTMLElement),e.element.visible?r?t.default.createElement(r,Object.assign({},e)):(console.error("Can not find component for "+e.element.type),null):null});
|
|
283
287
|
},{"react":"HdMw","mobx-react-lite":"ZfSi","./text-element":"Fpgh","./image-element":"VbEp","./html-element":"BLZX","../utils/flags":"IDY9"}],"RXmf":[function(require,module,exports) {
|
|
284
288
|
"use strict";var t=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.getClientRect=void 0;const e=t(require("konva"));function i(t,e,i,n,a){const o=Math.sqrt(i*i+n*n);return a+=Math.atan2(n,i),{x:t+o*Math.cos(a),y:e+o*Math.sin(a)}}function n(t){const{x:n,y:a,width:o,height:r}=t,x=e.default.Util.degToRad(t.rotation),h=i(n,a,0,0,x),s=i(n,a,o,0,x),u=i(n,a,o,r,x),y=i(n,a,0,r,x),c=Math.min(h.x,s.x,u.x,y.x),d=Math.min(h.y,s.y,u.y,y.y),M=Math.max(h.x,s.x,u.x,y.x),l=Math.max(h.y,s.y,u.y,y.y);return{x:c,y:d,width:M-c,height:l-d,minX:c,minY:d,maxX:M,maxY:l}}exports.getClientRect=n;
|
|
@@ -833,7 +837,7 @@ var e="undefined"!=typeof Element,r="function"==typeof Map,t="function"==typeof
|
|
|
833
837
|
},{"react":"HdMw","mobx-react-lite":"ZfSi","@blueprintjs/core":"Ydrz","@blueprintjs/popover2":"mZnF","../utils/l10n":"FlVj"}],"Ic0q":[function(require,module,exports) {
|
|
834
838
|
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.setAPI=exports.iconscoutDownload=exports.iconscoutList=exports.unsplashDownload=exports.unsplashList=exports.textTemplateList=exports.templateList=exports.removeBackground=exports.polotnoShapesList=exports.getGoogleFontImage=exports.getGoogleFontsListAPI=exports.URLS=exports.URL=exports.API=void 0;const e=require("./validate-key");exports.API="https://api.polotno.dev/api",exports.URL="https://api.polotno.dev";const o={},t=(e,t)=>{o[e]||(o[e]=!0,console.error(t))},s=(e,o,t)=>e.replace(new RegExp(o,"g"),t),p="API for iconscout is provided as a demonstration.\nFor production usage you have to use your own API endpoint.\nhttps://iconscout.com/developers, https://iconscout.com/legal/api-license-development-agreement\nhttps://polotno.dev/docs/server-api";exports.URLS={unsplashList:({query:o,page:t=1})=>`${exports.API}/get-unsplash?query=${o}&per_page=20&page=${t}&KEY=${(0,e.getKey)()}`,unsplashDownload:o=>`${exports.API}/download-unsplash?id=${o}&KEY=${(0,e.getKey)()}`,iconscoutList:({query:o,page:s=1})=>(t("iconscout",p),`${exports.API}/get-iconscout?query=${o}&page=${s}&KEY=${(0,e.getKey)()}`),iconscoutDownload:o=>(t("iconscout",p),`${exports.API}/download-iconscout?uuid=${o}&KEY=${(0,e.getKey)()}`),templateList:({query:o,page:t=1,sizeQuery:s})=>`${exports.API}/get-templates?${s}&query=${o}&per_page=30&page=${t}&KEY=${(0,e.getKey)()}`};const r=()=>`${exports.API}/get-google-fonts?KEY=${(0,e.getKey)()}`;exports.getGoogleFontsListAPI=r;const n=e=>{return`${exports.URL}/google-fonts-previews/black/${o=e," ","-",o.replace(new RegExp(" ","g"),"-")}.png`;var o};exports.getGoogleFontImage=n;const a=()=>`${exports.API}/get-basic-shapes?KEY=${(0,e.getKey)()}`;exports.polotnoShapesList=a;const c=()=>`${exports.API}/remove-image-background?KEY=${(0,e.getKey)()}`;exports.removeBackground=c;const i=e=>exports.URLS.templateList(e);exports.templateList=i;const l=()=>`${exports.API}/get-text-templates?KEY=${(0,e.getKey)()}`;exports.textTemplateList=l;const x=e=>exports.URLS.unsplashList(e);exports.unsplashList=x;const g=e=>exports.URLS.unsplashDownload(e);exports.unsplashDownload=g;const u=e=>exports.URLS.iconscoutList(e);exports.iconscoutList=u;const d=e=>exports.URLS.iconscoutDownload(e);exports.iconscoutDownload=d;const L=(e,o)=>{exports.URLS[e]=o};exports.setAPI=L;
|
|
835
839
|
},{"./validate-key":"zree"}],"zree":[function(require,module,exports) {
|
|
836
|
-
"use strict";var e=this&&this.__createBinding||(Object.create?function(e,o,
|
|
840
|
+
"use strict";var e=this&&this.__createBinding||(Object.create?function(e,t,o,n){void 0===n&&(n=o),Object.defineProperty(e,n,{enumerable:!0,get:function(){return t[o]}})}:function(e,t,o,n){void 0===n&&(n=o),e[n]=t[o]}),t=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),o=this&&this.__importStar||function(o){if(o&&o.__esModule)return o;var n={};if(null!=o)for(var i in o)"default"!==i&&Object.prototype.hasOwnProperty.call(o,i)&&e(n,o,i);return t(n,o),n};Object.defineProperty(exports,"__esModule",{value:!0}),exports.validateKey=exports.isKeyPaid=exports.getKey=exports.shouldShowCredit=void 0;const n=o(require("mobx")),i=require("./api"),a=require("./flags");exports.shouldShowCredit=n.observable({value:!1});const r=n.action(()=>{exports.shouldShowCredit.value=!0});let s="";const l=()=>s||"";exports.getKey=l;const d=5,c=3e3,u="Polotno API is initialized without API key. It may lead to unexpected behavior and stop working. Please create API key here: https://polotno.dev/cabinet",p="Polotno API key is not valid. Please get new API key here: https://polotno.dev/cabinet",h="Can not validate Polotno API key. Please report to anton@polotno.dev immediately.",v="%cPolotno Free Version. Development or non-commercial usage only. https://polotno.dev/";let f=location.origin;const g=navigator.userAgent.indexOf("Headless")>-1,y=navigator.userAgent.indexOf("Electron")>-1;"file://"===f&&g&&(f="headless"),"file://"===f&&y&&(f="electron");const P=`%cPolotno error! Current domain is not allowed. It may lead to unexpected behavior and stop working. Please add "${f}" here: https://polotno.dev/cabinet`;async function b(e){for(let t=0;t<5;t++)try{const t=await fetch(i.API+"/validate-key",{method:"POST",body:JSON.stringify({key:e,site:location.host+location.pathname})});if(!e)return console.warn(u),!1;if(200!==t.status){await new Promise(e=>setTimeout(e,3e3));continue}const o=await t.json();return o.is_valid||console.warn(p),o.is_paid||console.log(v,"background: rgb(0, 161, 255); color: white; padding: 5px; margin: 5px;"),o.is_domain_valid||console.log(P,"background: rgba(247, 101, 68, 1); color: white; padding: 5px; margin: 5px;"),(0,a.useRemoveBackground)(o.remove_background_enabled),o.is_paid||!1}catch(e){await new Promise(e=>setTimeout(e,3e3))}return console.error(h),!0}async function m(e,t){s=e,await b(e)&&!t||r()}exports.isKeyPaid=b,exports.validateKey=m;
|
|
837
841
|
},{"mobx":"BzvP","./api":"Ic0q","./flags":"IDY9"}],"Co9b":[function(require,module,exports) {
|
|
838
842
|
"use strict";var e=this&&this.__rest||function(e,t){var n={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(e);r<i.length;r++)t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(n[i[r]]=e[i[r]])}return n},t=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.registerNextDomDrop=exports.registerTransformerAttrs=void 0;const n=t(require("react")),i=require("mobx-react-lite"),r=require("mobx"),l=require("react-konva"),o=t(require("use-image")),a=t(require("konva")),s=t(require("./element")),d=require("./use-transformer-snap"),c=require("./image-element"),m=require("../utils/crop"),u=require("./page-controls"),h=require("../utils/validate-key"),g=require("../utils/math"),f={enabledAnchors:["top-left","top-center","top-right","middle-left","bottom-left","bottom-right","bottom-center","middle-right"],rotateEnabled:!0,rotationSnaps:[0,45,90,135,180,225,270,315],ignoreStroke:!0,anchorStrokeWidth:2,borderStrokeWidth:2},p={text:{enabledAnchors:["top-left","top-right","middle-left","bottom-left","bottom-right","middle-right"]},svg:{enabledAnchors:["top-left","top-right","bottom-left","bottom-right"]},many:{enabledAnchors:["top-left","top-right","bottom-left","bottom-right"]}};function x(e,t){p[e]=p[e]||t,Object.assign(p[e],t)}exports.registerTransformerAttrs=x;const b=e=>n.default.createElement(l.Rect,Object.assign({},e,{preventDefault:!1})),y=t=>{var{url:i}=t,r=e(t,["url"]);const[a,s]=(0,o.default)(i,"anonymous"),d=a?(0,m.getCrop)(a,{width:r.width,height:r.height},"center-middle"):{};return(0,c.useImageLoader)(s),n.default.createElement(l.Image,Object.assign({image:a},r,d))},v=e=>n.default.createElement(l.Rect,Object.assign({},e)),E=t=>{const{background:i,scale:r,borderColor:l}=t,o=e(t,["background","scale","borderColor"]),a=i.indexOf("http")>=0||i.indexOf(".png")>=0||i.indexOf(".jpg")>=0;return n.default.createElement(n.default.Fragment,null,a?n.default.createElement(y,Object.assign({url:i},o)):n.default.createElement(v,Object.assign({fill:i},o)))},w=(0,i.observer)(({selection:e})=>e.visible?n.default.createElement(l.Rect,{name:"selection",x:Math.min(e.x1,e.x2),y:Math.min(e.y1,e.y2),width:Math.abs(e.x1-e.x2),height:Math.abs(e.y1-e.y2),fill:"rgba(0, 161, 255, 0.3)"}):null),X=(0,i.observer)(({elements:e,store:t})=>{const i=e.filter(e=>e.alwaysOnTop),r=e.filter(e=>!e.alwaysOnTop).concat(i);return n.default.createElement(n.default.Fragment,null,r.map(e=>n.default.createElement(s.default,{key:e.id,store:t,element:e,onClick:()=>{console.warn("Polotno warning: onClick callback is deprecated. Just stop using it. Polotno will do selection automatically.")}})))});let Y=null;const k=e=>{Y=e};exports.registerNextDomDrop=k,exports.default=(0,i.observer)(({store:e,page:t,width:o,height:s,pageControlsEnabled:c,backColor:m,pageBorderColor:x,activePageBorderColor:y,components:v})=>{const k=e._bleedVisible?t.bleed:0,O=t.computedWidth+2*k,P=t.computedHeight+2*k,S=(o-O*e.scale)/2,A=(s-P*e.scale)/2,R=n.default.useRef(null),C=n.default.useRef(null),I=n.default.useRef(null),W=null==c||c,[j,D]=n.default.useState(null),L=e.selectedElements.find(e=>e._cropModeEnabled),M=e.selectedElements.filter(e=>e.locked).length>0,q=e.selectedElements.filter(e=>!e.visible).length>0;n.default.useEffect(()=>{var t,n;if(!R.current)return;const i=R.current.getStage(),r=e.selectedElements.map(e=>e._cropModeEnabled?null:i.findOne("#"+e.id)).filter(e=>e),l=1===e.selectedElements.length&&(null===(t=e.selectedElements[0])||void 0===t?void 0:t.type)||"many";M?(R.current.enabledAnchors([]),R.current.rotateEnabled(!1)):p[l]?(R.current.setAttrs(Object.assign(Object.assign({},f),p[l])),"svg"!==l||e.selectedElements[0].keepRatio||R.current.setAttrs({enabledAnchors:f.enabledAnchors})):R.current.setAttrs(f),R.current.nodes(r),null===(n=R.current.getLayer())||void 0===n||n.batchDraw()},[e.selectedElements,L,M,q]);const T=(0,i.useLocalObservable)(()=>({visible:!1,x1:0,y1:0,x2:0,y2:0})),_=n.default.useRef(!1),B=(0,r.action)(n=>{var i,r;_.current=!1,e.activePage!==t&&t.select();const l=n.target.findAncestor(".elements-container"),o=n.target.findAncestor("Transformer"),a=n.target.findAncestor(".page-abs-container");if(l||o||a)return;const s=null===(i=n.target.getStage())||void 0===i?void 0:i.getPointerPosition();s&&(T.visible=!0,T.x1=s.x,T.y1=s.y,T.x2=s.x,T.y2=s.y,(null===(r=n.target.getStage())||void 0===r?void 0:r.getPointersPositions().length)>=2&&(T.visible=!1))});n.default.useEffect(()=>{const t=(0,r.action)(e=>{var t,n;if(!T.visible)return;null===(t=C.current)||void 0===t||t.setPointersPositions(e);let i=(null===(n=C.current)||void 0===n?void 0:n.getPointerPosition())||{x:T.x2,y:T.y2};T.x2=i.x,T.y2=i.y}),n=(0,r.action)(()=>{if(!T.visible)return;if(!C.current)return;const t=C.current.findOne(".selection"),n=t?t.getClientRect():{width:0,height:0,x:0,y:0};if(n.width&&n.height){const t=[];C.current.find(".element").forEach(i=>{const r=i.getClientRect(),l=e.getElementById(i.id()),o=null==l?void 0:l.locked,s=null==l?void 0:l.selectable;a.default.Util.haveIntersection(n,r)&&!o&&s&&t.push(i.id())}),e.selectElements(t)}T.visible=!1,_.current=!0});return window.addEventListener("mousemove",t),window.addEventListener("touchmove",t),window.addEventListener("mouseup",n),window.addEventListener("touchend",n),()=>{window.removeEventListener("mousemove",t),window.removeEventListener("touchmove",t),window.removeEventListener("mouseup",n),window.removeEventListener("touchend",n)}},[]);const H=t=>{if(_.current)return;const n=t.evt.ctrlKey||t.evt.metaKey||t.evt.shiftKey,i=t.target.findAncestor(".elements-container"),r=t.target.findAncestor(".page-abs-container"),l=t.target.findAncestor("Transformer");if(!(n||i||l||r))return void e.selectElements([]);const o=t.target.findAncestor(".element",!0),a=e.selectedElementsIds.indexOf(null==o?void 0:o.id())>=0;o&&n&&!a&&e.selectElements(e.selectedElementsIds.concat([o.id()])),o&&n&&a&&e.selectElements(e.selectedElementsIds.filter(e=>e!==o.id())),!o||n||a||e.selectElements([o.id()])};(0,d.useSnap)(R);const G=e.activePage===t,N=(null==v?void 0:v.PageControls)||u.PageControls;return n.default.createElement("div",{ref:I,onDragOver:e=>e.preventDefault(),onDrop:t=>{if(t.preventDefault(),!C.current)return;C.current.setPointersPositions(t);const n=C.current.findOne(".elements-container").getRelativePointerPosition(),i=C.current.getPointerPosition(),r=C.current.getIntersection(i),l=r&&r.findAncestor(".element",!0),o=l?e.getElementById(l.id()):void 0;Y&&(Y(n,o),Y=null)},style:{position:"relative",width:o+"px"},className:"polotno-page-container"+(G?" active-page":"")},n.default.createElement(l.Stage,{ref:C,width:o,height:s,onClick:H,onTap:H,onMouseDown:B,onMouseMove:n=>{if(!n.evt.altKey&&j)return void D(null);if(!n.evt.altKey)return;const i=n.target.findAncestor(".element",!0),r=null==i?void 0:i.id();if(!e.selectedElements[0])return;if(e.selectedElementsIds.includes(r))return;const l=(0,g.getClientRect)(e.selectedElements[0]),o=r?e.getElementById(r):{x:0,y:0,width:t.computedWidth,height:t.computedHeight,rotation:0},a=(0,g.getClientRect)(o),s=[];l.minX>a.maxX&&s.push({distance:l.minX-a.maxX,box1:l,box2:a,points:[{x:l.minX,y:l.minY+l.height/2},{x:a.maxX,y:l.minY+l.height/2},{x:a.maxX,y:a.minY+a.height/2}]}),l.maxX<a.minX&&s.push({distance:a.minX-l.maxX,box1:l,box2:a,points:[{x:l.maxX,y:l.minY+l.height/2},{x:a.minX,y:l.minY+l.height/2},{x:a.minX,y:a.minY+a.height/2}]}),l.minY>a.maxY&&s.push({box1:l,box2:a,distance:l.minY-a.maxY,points:[{x:l.minX+l.width/2,y:l.minY},{x:l.minX+l.width/2,y:a.maxY},{x:a.minX+a.width/2,y:a.maxY}]}),l.maxY<a.minY&&s.push({box1:l,box2:a,distance:a.minY-l.maxY,points:[{x:l.minX+l.width/2,y:l.maxY},{x:l.minX+l.width/2,y:a.minY},{x:a.minX+a.width/2,y:a.minY}]}),l.minX>=a.minX&&l.maxX<=a.maxX&&l.minY>=a.minY&&l.maxY<=a.maxY&&(s.push({distance:l.minX-a.minX,box1:l,box2:a,points:[{x:l.minX,y:l.minY+l.height/2},{x:a.minX,y:l.minY+l.height/2},{x:a.minX,y:a.minY+a.height/2}]}),s.push({distance:a.maxX-l.maxX,box1:l,box2:a,points:[{x:l.maxX,y:l.minY+l.height/2},{x:a.maxX,y:l.minY+l.height/2},{x:a.maxX,y:a.minY+a.height/2}]}),s.push({box1:l,box2:a,distance:l.minY-a.minY,points:[{x:l.minX+l.width/2,y:l.minY},{x:l.minX+l.width/2,y:a.minY},{x:a.minX+a.width/2,y:a.minY}]}),s.push({box1:l,box2:a,distance:a.maxY-l.maxY,points:[{x:l.minX+l.width/2,y:l.maxY},{x:l.minX+l.width/2,y:a.maxY},{x:a.minX+a.width/2,y:a.maxY}]})),JSON.stringify(j)!==JSON.stringify(s)&&D(s)},onDragStart:t=>{var n;if(t.target.hasName("element")){const i=t.target.id();!(e.selectedElementsIds.indexOf(i)>=0)&&i&&(e.selectElements([i]),null===(n=R.current)||void 0===n||n.startDrag(t))}j&&D(null)},pageId:t.id,style:{position:"relative"}},n.default.createElement(l.Layer,null,n.default.createElement(b,{width:o,height:s,fill:m}),n.default.createElement(l.Group,{x:S,y:A,scaleX:e.scale,scaleY:e.scale,name:"page-container"},n.default.createElement(l.Rect,{name:"page-highlight",hideInExport:!0,x:-1.5/e.scale,y:-1.5/e.scale,width:O+3/e.scale,height:P+3/e.scale,stroke:G&&e.pages.length>1?y:x,strokeWidth:3,listening:!1,strokeScaleEnabled:!1}),n.default.createElement(l.Group,{name:"page-background-group",x:k,y:k,clipX:-k,clipY:-k,clipWidth:t.computedWidth+2*k,clipHeight:t.computedHeight+2*k},n.default.createElement(E,{x:-t.bleed,y:-t.bleed,width:t.computedWidth+2*t.bleed,height:t.computedHeight+2*t.bleed,background:t.background,shadowBlur:10,shadowColor:"lightgrey",name:"page-background",preventDefault:!1,scale:e.scale})),n.default.createElement(l.Group,{x:k,y:k,clipX:-k,clipY:-k,clipWidth:t.computedWidth+2*k,clipHeight:t.computedHeight+2*k,name:"elements-container"},n.default.createElement(l.Rect,{name:"elements-area",width:t.computedWidth,height:t.computedHeight,listening:!1}),n.default.createElement(X,{elements:t.children,store:e})),n.default.createElement(l.Rect,{stroke:"red",name:"bleed",strokeWidth:t.bleed,x:t.bleed/2,y:t.bleed/2,width:t.computedWidth+t.bleed,height:t.computedHeight+t.bleed,opacity:.1,listening:!1,visible:t.bleed>0&&e._bleedVisible,hideInExport:!0})),n.default.createElement(l.Group,{x:S,y:A,scaleX:e.scale,scaleY:e.scale,name:"page-abs-container"},n.default.createElement(l.Transformer,{ref:R,boundBoxFunc:(e,t)=>{const n=t.width<1||t.height<1,i=e.width<1||e.height<1;return n&&!i?e:t}}),j&&j.map(({points:t,distance:i,box1:r,box2:o},a)=>n.default.createElement(l.Group,{name:"distances-container",hideInExport:!0,key:a,listening:!1},n.default.createElement(l.Rect,Object.assign({},r,{stroke:"rgb(0, 161, 255)",strokeWidth:1,strokeScaleEnabled:!1})),n.default.createElement(l.Rect,Object.assign({},o,{stroke:"rgb(0, 161, 255)",strokeWidth:1,strokeScaleEnabled:!1})),n.default.createElement(l.Line,{points:[t[0].x,t[0].y,t[1].x,t[1].y],stroke:"rgb(0, 161, 255)",strokeWidth:1,strokeScaleEnabled:!1}),n.default.createElement(l.Line,{points:[t[1].x,t[1].y,t[2].x,t[2].y],stroke:"rgb(0, 161, 255)",strokeWidth:1,strokeScaleEnabled:!1}),n.default.createElement(l.Group,{x:(t[0].x+t[1].x)/2,y:(t[0].y+t[1].y)/2,scaleX:1/e.scale,scaleY:1/e.scale},n.default.createElement(l.Rect,{offsetX:25,offsetY:10,width:50,height:20,cornerRadius:5,fill:"rgb(0, 161, 255)"}),n.default.createElement(l.Text,{offsetX:25,offsetY:10,width:50,height:20,align:"center",verticalAlign:"middle",fill:"white",text:Math.round(i).toString()+" px"}))))),n.default.createElement(w,{selection:T}),h.shouldShowCredit.value&&n.default.createElement(l.Text,{text:"Powered by polotno.dev",fontSize:14,fill:"rgba(0,0,0,0.6)",x:o-170,y:s-18,onMouseEnter:e=>{e.target.getStage().container().style.cursor="pointer"},onMouseLeave:e=>{e.target.getStage().container().style.cursor=""},onTouchStart:e=>{e.cancelBubble=!0},onMouseDown:e=>{e.cancelBubble=!0},onClick:()=>{window.open("https://polotno.dev")},onTap:()=>{window.open("https://polotno.dev")}}),n.default.createElement(l.Group,{name:"line-guides"}))),W&&G&&n.default.createElement(N,{store:e,page:t,xPadding:S,yPadding:A}))});
|
|
839
843
|
},{"react":"HdMw","mobx-react-lite":"ZfSi","mobx":"BzvP","react-konva":"Sgug","use-image":"MJM3","konva":"aTGn","./element":"XEPK","./use-transformer-snap":"F86d","./image-element":"VbEp","../utils/crop":"hfHf","./page-controls":"smDv","../utils/validate-key":"zree","../utils/math":"RXmf"}],"NI5R":[function(require,module,exports) {
|
|
@@ -856,8 +860,8 @@ var e=require("process");Object.defineProperty(exports,"__esModule",{value:!0}),
|
|
|
856
860
|
},{}],"XXLd":[function(require,module,exports) {
|
|
857
861
|
"use strict";var t=this&&this.__createBinding||(Object.create?function(t,e,o,n){void 0===n&&(n=o),Object.defineProperty(t,n,{enumerable:!0,get:function(){return e[o]}})}:function(t,e,o,n){void 0===n&&(n=o),t[n]=e[o]}),e=this&&this.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),o=this&&this.__importStar||function(o){if(o&&o.__esModule)return o;var n={};if(null!=o)for(var r in o)"default"!==r&&Object.prototype.hasOwnProperty.call(o,r)&&t(n,o,r);return e(n,o),n};Object.defineProperty(exports,"__esModule",{value:!0}),exports.injectCustomFont=exports.injectGoogleFont=exports.loadFont=exports.addGlobalFont=exports.globalFonts=exports.getFontsList=exports.setGoogleFonts=exports.isGoogleFontChanged=void 0;const n=o(require("mobx"));let r=n.observable(["Roboto","Amatic SC","Press Start 2P","Marck Script","Rubik Mono One"]),s=!1;function i(){return s}function l(t){s=!0,r.splice(0,r.length),r.push(...t)}function a(){return r}function c(t){exports.globalFonts.push(t)}exports.isGoogleFontChanged=i,exports.setGoogleFonts=l,exports.getFontsList=a,exports.globalFonts=n.observable([]),exports.addGlobalFont=c;var u="Some test text;?#D-ПРИВЕТ!",f=document.createElement("canvas"),d=f.getContext("2d");function p(){return m("Arial")}function m(t){return d.font=`normal 40px '${t}', Arial`,d.measureText(u).width}const g=100,x={Arial:!0};async function h(t){var e;if(x[t])return;const o=!!(null===(e=document.fonts)||void 0===e?void 0:e.load),n=p();if(o)try{if(await document.fonts.load(`16px '${t}'`),n!==m(t))return void(x[t]=!0)}catch(t){}const r=m(t);for(let s=0;s<100;s++){const e=m(t);if(e!==r||e!==n)return void(x[t]=!0);await new Promise(t=>setTimeout(t,60))}console.warn(`Timeout for loading font "${t}". Looks like polotno can't load it. Is it a correct font family?`)}exports.loadFont=h;const y={};function b(t){if(y[t])return;const e=`https://fonts.googleapis.com/css?family=${t.replace(/ /g,"+")}`,o=document.createElement("link");o.type="text/css",o.href=e,o.rel="stylesheet",document.getElementsByTagName("head")[0].appendChild(o),y[t]=!0}exports.injectGoogleFont=b;const F={};function v(t){const e=t.fontFamily;if(F[e])return;if(!t.url&&!t.styles)return;const o=document.createElement("style");o.type="text/css";const n=t.styles||(t.url?[{src:`url("${t.url}")`}]:[]);let r="";n.forEach(t=>{r+=`\n @font-face {\n font-family: '${e}';\n src: ${t.src};\n font-style: ${t.fontStyle||"normal"};\n font-weight: ${t.fontWeight||"normal"};\n }\n `}),o.innerHTML=r,document.getElementsByTagName("head")[0].appendChild(o),F[t.fontFamily]=!0}exports.injectCustomFont=v;
|
|
858
862
|
},{"mobx":"BzvP"}],"GRkH":[function(require,module,exports) {
|
|
859
|
-
"use strict";var e=this&&this.__createBinding||(Object.create?function(e,t,o,n){void 0===n&&(n=o),Object.defineProperty(e,n,{enumerable:!0,get:function(){return t[o]}})}:function(e,t,o,n){void 0===n&&(n=o),e[n]=t[o]}),t=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),o=this&&this.__importStar||function(o){if(o&&o.__esModule)return o;var n={};if(null!=o)for(var s in o)"default"!==s&&Object.prototype.hasOwnProperty.call(o,s)&&e(n,o,s);return t(n,o),n},n=this&&this.__rest||function(e,t){var o={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(o[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var s=0;for(n=Object.getOwnPropertySymbols(e);s<n.length;s++)t.indexOf(n[s])<0&&Object.prototype.propertyIsEnumerable.call(e,n[s])&&(o[n[s]]=e[n[s]])}return o},s=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 i=require("mobx-state-tree"),r=require("./undo-manager"),a=require("nanoid"),l=s(require("konva")),d=require("../utils/download"),c=require("../utils/pdf"),p=require("../utils/validate-key"),g=o(require("../utils/fonts")),h=require("../utils/svg"),f=require("../utils/loader");(0,i.setLivelinessChecking)("ignore"),exports.Element=i.types.model("Element",{id:i.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:i.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 n in t)"_"!==n[0]&&(o[n]=e[n]);return o}).views(e=>({get page(){return(0,i.getParentOfType)(e,exports.Page)},get store(){return(0,i.getParentOfType)(e,exports.Store)}})).actions(e=>({toJSON:()=>Object.assign({},(0,i.getSnapshot)(e))})).actions(e=>({clone(t){const o=e.toJSON();return t.id=t.id||(0,a.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:i.types.optional(i.types.union(i.types.number,i.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:i.types.map(i.types.string)}).preProcessSnapshot(e=>Object.assign(Object.assign({},e),{src:e.src||e.svgSource})).views(e=>({get colors(){return e.__svgString?(0,h.getColors)(e.__svgString):[]},get __finalSrc(){return e.__svgString?(0,h.replaceColors)(e.__svgString,e.colorsReplace):this.src},get __isLoaded(){return!!e.__svgString&&(!(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,h.urlToString)(e.src);(0,i.isAlive)(e)&&(0,i.hasParent)(e)&&e.store.history.ignore(()=>{e.set({__svgString:(0,h.fixSize)(t)})})},async afterCreate(){e._loadSVG();let o=e.src;t=(0,i.onSnapshot)(e,t=>{t.src===o&&e.__svgString||(e._loadSVG(),o=e.src)})},beforeDestroy(){t()},replaceColor(t,o){e.colorsReplace.set(t,o)}}});const m={svg:exports.SVGElement,text:exports.TextElement,image:exports.ImageElement},u=[];function y(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);m[t]=o,u.push(o)}exports.registerShapeModel=y;const b=[...new Array(20)].map((e,t)=>i.types.late(()=>u[t])),x=i.types.union({dispatcher:e=>{const t=m[e.type];if(!t)throw new Error(`Unknown element type: "${e.type}"`);return t}},exports.SVGElement,exports.TextElement,exports.ImageElement,...b);function v({key:e,showCredit:t}={key:"",showCredit:!1}){const o=exports.Store.create();return(0,p.validateKey)(e,t),o}exports.Page=i.types.model("Page",{id:i.types.identifier,children:i.types.array(x),width:i.types.optional(i.types.union(i.types.number,i.types.literal("auto")),"auto"),height:i.types.optional(i.types.union(i.types.number,i.types.literal("auto")),"auto"),background:"white",bleed:0,custom:i.types.frozen(),_exporting:!1}).postProcessSnapshot(e=>{const t=Object.assign({},e),o={};for(var n in t)"_"!==n[0]&&(o[n]=e[n]);return o}).views(e=>({get store(){return(0,i.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,i.getSnapshot)(e))),clone(t){const o=e.toJSON();o.children.forEach(e=>{e.id=(0,a.nanoid)(10)});const n=Object.assign(Object.assign(Object.assign({},o),{id:(0,a.nanoid)(10)}),t),s=e.store.addPage(n),i=e.store.pages.indexOf(e);s.setZIndex(i+1),s.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=m[t.type];if(!o)return void console.error("Can not find model with type "+t.type);const n=o.create(Object.assign({id:(0,a.nanoid)(10)},t));return e.children.push(n),n.selectable&&e.store.selectElements([n.id]),n},moveElementUp(t){const o=e.children.findIndex(e=>e.id===t),n=e.children[o];(0,i.detach)(n),e.children.remove(n),e.children.splice(o+1,0,n)},moveElementDown(t){const o=e.children.findIndex(e=>e.id===t),n=e.children[o];(0,i.detach)(n),e.children.remove(n),e.children.splice(o-1,0,n)},moveElementTop(t){const o=e.children.findIndex(e=>e.id===t),n=e.children[o];(0,i.detach)(n),e.children.remove(n),e.children.push(n)},moveElementBottom(t){const o=e.children.findIndex(e=>e.id===t),n=e.children[o];(0,i.detach)(n),e.children.remove(n),e.children.splice(0,0,n)}})),exports.Font=i.types.model("Font",{fontFamily:i.types.string,url:i.types.optional(i.types.string,""),styles:i.types.frozen()}).preProcessSnapshot(e=>Object.assign(Object.assign({},e),{fontFamily:e.fontFamily||e.name})),exports.Store=i.types.model("Store",{role:"",pages:i.types.array(exports.Page),fonts:i.types.array(exports.Font),width:1080,height:1080,scale:1,scaleToFit:1,_bleedVisible:!1,openedSidePanel:"",selectedElementsIds:i.types.array(i.types.string),history:i.types.optional(r.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,a.nanoid)(10)},t));return e.pages.push(o),e._activePageId=o.id,o},selectPage(t){e._activePageId=t},selectElements(t){e.selectedElementsIds=(0,i.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,n){if(n){const n=t/e.width,s=o/e.height;for(const t of e.pages)for(const e of t.children)e.set({x:e.x*n,y:e.y*s}),"text"===e.type?e.set({fontSize:e.fontSize*n,width:Math.max(e.width*n,2)}):"image"===e.type?e.set({width:e.width*n,height:e.height*s}):"svg"===e.type&&e.set({width:Math.max(e.width*n,2),height:Math.max(e.height*n,2)})}e.width=t,e.height=o},setPageZIndex(t,o){const n=e.pages.find(e=>e.id===t);n&&((0,i.detach)(n),e.pages.remove(n),e.pages.splice(o,0,n))},deletePages(t){const o=e.pages.indexOf(e.activePage);t.forEach(t=>{const o=e.pages.find(e=>e.id===t);(0,i.destroy)(o)});const n=Math.min(e.pages.length-1,o),s=e.pages[n];s&&(e._activePageId=s.id),e.selectedElementsIds=(0,i.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,i.destroy)(o)})}),e.selectedElementsIds=(0,i.cast)([])},on(t,o){if("change"===t){let t=e.toJSON();return(0,i.onSnapshot)(e,n=>{const s=e.toJSON();JSON.stringify(s)!==JSON.stringify(t)&&(t=s,o(s))})}},async toDataURL({pixelRatio:t,ignoreBackground:o,pageId:n,mimeType:s,includeBleed:i,quality:r}={}){var a;const d=t||1;n=n||(null===(a=e.pages[0])||void 0===a?void 0:a.id);const c=e.pages.find(e=>e.id===n);if(!c)throw new Error(`No page for export with id ${n}`);null==c||c.set({_exporting:!0}),await new Promise(e=>{setTimeout(e,0)}),await e.waitLoading();const p=l.default.stages.find(e=>e.getAttr("pageId")===n);if(!p)throw 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.`);const g=p.findOne(".page-container");p.find("Transformer").forEach(e=>e.visible(!1)),g.findOne(".page-background").shadowEnabled(!1),g.findOne(".page-background").strokeEnabled(!1),g.find(".highlighter").forEach(e=>e.visible(!1));const h=g.findOne(".page-background-group"),f=h.clip();h.clip({x:null,y:null,width:null,height:null});const m=g.find(e=>e.getAttr("hideInExport"));m.forEach(e=>{e.setAttr("oldVisible",e.visible()),e.hide()}),o&&g.findOne(".page-background").hide();const u=i?c.bleed:0;let y=u;e._bleedVisible&&i?y=0:e._bleedVisible&&!i&&(y=-c.bleed);const b=g.toDataURL({x:g.x()-y*g.scaleX(),y:g.y()-y*g.scaleY(),width:(c.computedWidth+2*u)*g.scaleX(),height:(c.computedHeight+2*u)*g.scaleY(),pixelRatio:1/g.scaleX()*d,mimeType:s,quality:r});return o&&g.findOne(".page-background").show(),m.forEach(e=>{e.visible(e.getAttr("oldVisible"))}),g.findOne(".page-background").shadowEnabled(!0),g.findOne(".page-background").strokeEnabled(!0),p.find("Transformer").forEach(e=>e.visible(!0)),g.find(".highlighter").forEach(e=>e.visible(!0)),h.clip(f),null==c||c.set({_exporting:!1}),b},async saveAsImage(t={}){var{fileName:o}=t,s=n(t,["fileName"]);const i=s.mimeType||"image/png",r=i.split("/")[1];(0,d.downloadFile)(await e.toDataURL(s),o||"polotno."+r,i)},async _toPDF(t){const o=t.dpi||300,n=e=>.75*e;var s=new(await(0,c.getJsPDF)())({unit:"pt",orientation:e.width>e.height?"landscape":"portrait",format:[n(e.width),n(e.height)],compress:!0});s.deletePage(1);const i=e._elementsPixelRatio,r=o/72;e.setElementsPixelRatio(r),await new Promise(e=>setTimeout(e));for(const a of e.pages){const o=t.includeBleed?a.bleed:0,i=n(a.computedWidth+o),l=n(a.computedHeight+o);s.addPage([i,l],i>l?"landscape":"portrait");let d=0,c=r;for(;d<10;){2===(d+=1)&&console.error("Polotno can not export PDF with current settings. Quality is automatically reduced.");const o=await e.toDataURL(Object.assign(Object.assign({},t),{pageId:a.id,pixelRatio:c}));if(o.length>20){s.addImage(o,0,0,i,l,void 0,"FAST");break}c*=.8}}return e.setElementsPixelRatio(i),s},toPDFDataURL:async t=>(await e._toPDF(Object.assign({mimeType:"image/jpeg"},t))).output("datauristring"),async saveAsPDF(t={}){var{fileName:o}=t,s=n(t,["fileName"]);(await e._toPDF(Object.assign({mimeType:"image/jpeg"},s))).save(o||"polotno.pdf")},async waitLoading(){await(0,f.whenLoaded)()},toJSON:()=>({width:e.width,height:e.height,fonts:(0,i.getSnapshot)(e.fonts),pages:(0,i.getSnapshot)(e.pages)}),loadJSON(t,o=!1){var n;const s=Object.assign({},t);e.pages.forEach(e=>e.children.forEach(e=>(0,i.detach)(e))),e.pages=(0,i.cast)([]),s._activePageId=null===(n=s.pages[0])||void 0===n?void 0:n.id,s.scale=e.scale,s.openedSidePanel=e.openedSidePanel,s._bleedVisible=e._bleedVisible,o&&(s.history=e.history.toJSON()),(0,i.applySnapshot)(e,s)},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))},async loadFont(t){const o=e.fonts.find(e=>e.fontFamily===t)||g.globalFonts.find(e=>e.fontFamily===t);o?g.injectCustomFont(o):g.injectGoogleFont(t),await g.loadFont(t)}})),exports.createStore=v,exports.default=v;
|
|
863
|
+
"use strict";var e=this&&this.__createBinding||(Object.create?function(e,t,o,n){void 0===n&&(n=o),Object.defineProperty(e,n,{enumerable:!0,get:function(){return t[o]}})}:function(e,t,o,n){void 0===n&&(n=o),e[n]=t[o]}),t=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),o=this&&this.__importStar||function(o){if(o&&o.__esModule)return o;var n={};if(null!=o)for(var s in o)"default"!==s&&Object.prototype.hasOwnProperty.call(o,s)&&e(n,o,s);return t(n,o),n},n=this&&this.__rest||function(e,t){var o={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(o[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var s=0;for(n=Object.getOwnPropertySymbols(e);s<n.length;s++)t.indexOf(n[s])<0&&Object.prototype.propertyIsEnumerable.call(e,n[s])&&(o[n[s]]=e[n[s]])}return o},s=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 i=require("mobx-state-tree"),r=require("./undo-manager"),a=require("nanoid"),l=s(require("konva")),d=require("../utils/download"),c=require("../utils/pdf"),p=require("../utils/validate-key"),g=o(require("../utils/fonts")),h=require("../utils/svg"),f=require("../utils/loader");(0,i.setLivelinessChecking)("ignore"),exports.Element=i.types.model("Element",{id:i.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:i.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 n in t)"_"!==n[0]&&(o[n]=e[n]);return o}).views(e=>({get page(){return(0,i.getParentOfType)(e,exports.Page)},get store(){return(0,i.getParentOfType)(e,exports.Store)}})).actions(e=>({toJSON:()=>Object.assign({},(0,i.getSnapshot)(e))})).actions(e=>({clone(t){const o=e.toJSON();return t.id=t.id||(0,a.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:i.types.optional(i.types.union(i.types.number,i.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:i.types.map(i.types.string)}).preProcessSnapshot(e=>Object.assign(Object.assign({},e),{src:e.src||e.svgSource})).views(e=>({get colors(){return e.__svgString?(0,h.getColors)(e.__svgString):[]},get __finalSrc(){return e.__svgString?(0,h.replaceColors)(e.__svgString,e.colorsReplace):this.src},get __isLoaded(){return!!e.__svgString&&(!(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,h.urlToString)(e.src);(0,i.isAlive)(e)&&(0,i.hasParent)(e)&&e.store.history.ignore(()=>{e.set({__svgString:(0,h.fixSize)(t)})})},async afterCreate(){e._loadSVG();let o=e.src;t=(0,i.onSnapshot)(e,t=>{t.src===o&&e.__svgString||(e._loadSVG(),o=e.src)})},beforeDestroy(){t()},replaceColor(t,o){e.colorsReplace.set(t,o)}}});const m={svg:exports.SVGElement,text:exports.TextElement,image:exports.ImageElement},u=[];function y(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);m[t]=o,u.push(o)}exports.registerShapeModel=y;const b=[...new Array(20)].map((e,t)=>i.types.late(()=>u[t])),x=i.types.union({dispatcher:e=>{const t=m[e.type];if(!t)throw new Error(`Unknown element type: "${e.type}"`);return t}},exports.SVGElement,exports.TextElement,exports.ImageElement,...b);function v({key:e,showCredit:t}={key:"",showCredit:!1}){const o=exports.Store.create();return(0,p.validateKey)(e,t),o}exports.Page=i.types.model("Page",{id:i.types.identifier,children:i.types.array(x),width:i.types.optional(i.types.union(i.types.number,i.types.literal("auto")),"auto"),height:i.types.optional(i.types.union(i.types.number,i.types.literal("auto")),"auto"),background:"white",bleed:0,custom:i.types.frozen(),_exporting:!1}).postProcessSnapshot(e=>{const t=Object.assign({},e),o={};for(var n in t)"_"!==n[0]&&(o[n]=e[n]);return o}).views(e=>({get store(){return(0,i.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,i.getSnapshot)(e))),clone(t){const o=e.toJSON();o.children.forEach(e=>{e.id=(0,a.nanoid)(10)});const n=Object.assign(Object.assign(Object.assign({},o),{id:(0,a.nanoid)(10)}),t),s=e.store.addPage(n),i=e.store.pages.indexOf(e);s.setZIndex(i+1),s.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=m[t.type];if(!o)return void console.error("Can not find model with type "+t.type);const n=o.create(Object.assign({id:(0,a.nanoid)(10)},t));return e.children.push(n),n.selectable&&e.store.selectElements([n.id]),n},moveElementUp(t){const o=e.children.findIndex(e=>e.id===t),n=e.children[o];(0,i.detach)(n),e.children.remove(n),e.children.splice(o+1,0,n)},moveElementDown(t){const o=e.children.findIndex(e=>e.id===t),n=e.children[o];(0,i.detach)(n),e.children.remove(n),e.children.splice(o-1,0,n)},moveElementTop(t){const o=e.children.findIndex(e=>e.id===t),n=e.children[o];(0,i.detach)(n),e.children.remove(n),e.children.push(n)},moveElementBottom(t){const o=e.children.findIndex(e=>e.id===t),n=e.children[o];(0,i.detach)(n),e.children.remove(n),e.children.splice(0,0,n)}})),exports.Font=i.types.model("Font",{fontFamily:i.types.string,url:i.types.optional(i.types.string,""),styles:i.types.frozen()}).preProcessSnapshot(e=>Object.assign(Object.assign({},e),{fontFamily:e.fontFamily||e.name})),exports.Store=i.types.model("Store",{role:"",pages:i.types.array(exports.Page),fonts:i.types.array(exports.Font),width:1080,height:1080,scale:1,scaleToFit:1,_bleedVisible:!1,openedSidePanel:"",selectedElementsIds:i.types.array(i.types.string),history:i.types.optional(r.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,a.nanoid)(10)},t));return e.pages.push(o),e._activePageId=o.id,o},selectPage(t){e._activePageId=t},selectElements(t){e.selectedElementsIds=(0,i.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,n){if(n){const n=t/e.width,s=o/e.height;for(const t of e.pages)for(const e of t.children)e.set({x:e.x*n,y:e.y*s}),"text"===e.type?e.set({fontSize:e.fontSize*n,width:Math.max(e.width*n,2)}):"image"===e.type?e.set({width:e.width*n,height:e.height*s}):"svg"===e.type&&e.set({width:Math.max(e.width*n,2),height:Math.max(e.height*n,2)})}e.width=t,e.height=o},setPageZIndex(t,o){const n=e.pages.find(e=>e.id===t);n&&((0,i.detach)(n),e.pages.remove(n),e.pages.splice(o,0,n))},deletePages(t){const o=e.pages.indexOf(e.activePage);t.forEach(t=>{const o=e.pages.find(e=>e.id===t);(0,i.destroy)(o)});const n=Math.min(e.pages.length-1,o),s=e.pages[n];s&&(e._activePageId=s.id),e.selectedElementsIds=(0,i.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,i.destroy)(o)})}),e.selectedElementsIds=(0,i.cast)([])},on(t,o){if("change"===t){let t=e.toJSON();return(0,i.onSnapshot)(e,n=>{const s=e.toJSON();JSON.stringify(s)!==JSON.stringify(t)&&(t=s,o(s))})}},async toDataURL({pixelRatio:t,ignoreBackground:o,pageId:n,mimeType:s,includeBleed:i,quality:r}={}){var a;const d=t||1;n=n||(null===(a=e.pages[0])||void 0===a?void 0:a.id);const c=e.pages.find(e=>e.id===n);if(!c)throw new Error(`No page for export with id ${n}`);null==c||c.set({_exporting:!0}),await new Promise(e=>{setTimeout(e,0)}),await e.waitLoading();const p=l.default.stages.find(e=>e.getAttr("pageId")===n);if(!p)throw 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.`);const g=p.findOne(".page-container");p.find("Transformer").forEach(e=>e.visible(!1)),g.findOne(".page-background").shadowEnabled(!1),g.findOne(".page-background").strokeEnabled(!1),g.find(".highlighter").forEach(e=>e.visible(!1));const h=g.findOne(".page-background-group"),f=h.clip();h.clip({x:null,y:null,width:null,height:null});const m=g.find(e=>e.getAttr("hideInExport"));m.forEach(e=>{e.setAttr("oldVisible",e.visible()),e.hide()}),o&&g.findOne(".page-background").hide();const u=i?c.bleed:0;let y=u;e._bleedVisible&&i?y=0:e._bleedVisible&&!i&&(y=-c.bleed);const b=g.toDataURL({x:g.x()-y*g.scaleX(),y:g.y()-y*g.scaleY(),width:(c.computedWidth+2*u)*g.scaleX(),height:(c.computedHeight+2*u)*g.scaleY(),pixelRatio:1/g.scaleX()*d,mimeType:s,quality:r});return o&&g.findOne(".page-background").show(),m.forEach(e=>{e.visible(e.getAttr("oldVisible"))}),g.findOne(".page-background").shadowEnabled(!0),g.findOne(".page-background").strokeEnabled(!0),p.find("Transformer").forEach(e=>e.visible(!0)),g.find(".highlighter").forEach(e=>e.visible(!0)),h.clip(f),null==c||c.set({_exporting:!1}),b},async saveAsImage(t={}){var{fileName:o}=t,s=n(t,["fileName"]);const i=s.mimeType||"image/png",r=i.split("/")[1];(0,d.downloadFile)(await e.toDataURL(s),o||"polotno."+r,i)},async _toPDF(t){const o=t.dpi||300,n=t.parallel||1,s=await(0,c.getJsPDF)(),i=e=>.75*e;var r=new s({unit:"pt",orientation:e.width>e.height?"landscape":"portrait",format:[i(e.width),i(e.height)],compress:!0});r.deletePage(1);const a=e._elementsPixelRatio,l=o/72;e.setElementsPixelRatio(l),await new Promise(e=>setTimeout(e));const d=((e,t)=>{for(var o=[],n=0;n<e.length;n+=t)o.push(e.slice(n,n+t));return o})(e.pages,n);for(const c of d){const o=c.map(async o=>{const n=t.includeBleed?o.bleed:0,s=i(o.computedWidth+n),r=i(o.computedHeight+n);let a=0,d=l;for(;a<10;){2===(a+=1)&&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:o.id,pixelRatio:d}));if(n.length>20)return{url:n,width:s,height:r};d*=.8}});(await Promise.all(o)).forEach(({url:e,width:t,height:o})=>{r.addPage([t,o],t>o?"landscape":"portrait"),r.addImage(e,0,0,t,o,void 0,"FAST")})}return e.setElementsPixelRatio(a),r},toPDFDataURL:async t=>(await e._toPDF(Object.assign({mimeType:"image/jpeg"},t))).output("datauristring"),async saveAsPDF(t={}){var{fileName:o}=t,s=n(t,["fileName"]);(await e._toPDF(Object.assign({mimeType:"image/jpeg"},s))).save(o||"polotno.pdf")},async waitLoading(){await(0,f.whenLoaded)()},toJSON:()=>({width:e.width,height:e.height,fonts:(0,i.getSnapshot)(e.fonts),pages:(0,i.getSnapshot)(e.pages)}),loadJSON(t,o=!1){var n;const s=Object.assign({},t);e.pages.forEach(e=>e.children.forEach(e=>(0,i.detach)(e))),e.pages=(0,i.cast)([]),s._activePageId=null===(n=s.pages[0])||void 0===n?void 0:n.id,s.scale=e.scale,s.openedSidePanel=e.openedSidePanel,s._bleedVisible=e._bleedVisible,o&&(s.history=e.history.toJSON()),(0,i.applySnapshot)(e,s)},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))},async loadFont(t){const o=e.fonts.find(e=>e.fontFamily===t)||g.globalFonts.find(e=>e.fontFamily===t);o?g.injectCustomFont(o):g.injectGoogleFont(t),await g.loadFont(t)}})),exports.createStore=v,exports.default=v;
|
|
860
864
|
},{"mobx-state-tree":"pk4v","./undo-manager":"lvYv","nanoid":"iDyL","konva":"aTGn","../utils/download":"HWHW","../utils/pdf":"sptl","../utils/validate-key":"zree","../utils/fonts":"XXLd","../utils/svg":"B1DI","../utils/loader":"bN4e"}],"IVsl":[function(require,module,exports) {
|
|
861
865
|
"use strict";var e=l(require("react")),o=l(require("react-dom")),r=require("polotno/canvas/workspace"),t=require("polotno/model/store"),a=require("polotno/canvas/use-fadein"),n=require("polotno/utils/fonts");function l(e){return e&&e.__esModule?e:{default:e}}(0,a.toggleFadeInAnimation)(!1);var d=new URLSearchParams(location.search).get("key"),i=(0,t.createStore)({key:d});window.store=i,window.config={addGlobalFont:n.addGlobalFont},o.default.render(e.default.createElement(r.Workspace,{store:i}),document.getElementById("root"));
|
|
862
866
|
},{"react":"HdMw","react-dom":"X9zx","polotno/canvas/workspace":"twsc","polotno/model/store":"GRkH","polotno/canvas/use-fadein":"N3c2","polotno/utils/fonts":"XXLd"}]},{},["IVsl"], null)
|
|
863
|
-
//# sourceMappingURL=client.
|
|
867
|
+
//# sourceMappingURL=client.20ef3222.js.map
|
package/dist/client.html
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
<html><head><title>Canvas editor</title><style>body{padding:0;margin:0}</style><meta name="viewport" content="width=device-width, initial-scale=1"></head><body class="bp3-dark"> <div id="root"></div> <script src="client.
|
|
1
|
+
<html><head><title>Canvas editor</title><style>body{padding:0;margin:0}</style><meta name="viewport" content="width=device-width, initial-scale=1"></head><body class="bp3-dark"> <div id="root"></div> <script src="client.20ef3222.js"></script> </body></html>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "polotno-node",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "Polotno workflow from NodeJS",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
],
|
|
16
16
|
"devDependencies": {
|
|
17
17
|
"parcel-bundler": "^1.12.4",
|
|
18
|
-
"polotno": "^0.38.
|
|
18
|
+
"polotno": "^0.38.7",
|
|
19
19
|
"react": "^17.0.2",
|
|
20
20
|
"react-dom": "^17.0.2"
|
|
21
21
|
},
|