polotno-node 2.0.4 → 2.0.6
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/README.md +3 -1
- package/dist/{client.a516c3ac.js → client.51dfa0bd.js} +18 -16
- package/dist/client.html +1 -1
- package/instance.js +24 -4
- package/package.json +11 -4
package/README.md
CHANGED
|
@@ -173,12 +173,14 @@ const url = await instance.run(async (json) => {
|
|
|
173
173
|
|
|
174
174
|
## Your own client
|
|
175
175
|
|
|
176
|
-
By default `polotno-node` ships with the default Polotno Editor with its (hopefully) last version. If you use experimental API such as `unstable_registerShapeModel` and `unstable_registerShapeComponent`, the rendering may fail if you use
|
|
176
|
+
By default `polotno-node` ships with the default Polotno Editor with its (hopefully) last version. If you use experimental API such as `unstable_registerShapeModel` and `unstable_registerShapeComponent`, the rendering may fail if you use unknown elements types.
|
|
177
177
|
|
|
178
178
|
In that case you can use your own client editor. You need to create a public html page with `store` as global variable and mount just `<Workspace />` component from `polotno/canvas` module. Take a look into `client.html` file and `client.js` file in this repo as a demo. In your own version of the Editor you can use experimental API to define custom components.
|
|
179
179
|
|
|
180
180
|
Pass `url` option to `createInstance` function with public url of your client editor.
|
|
181
181
|
|
|
182
|
+
**Note: you will have to maintain the last version of your client editor by yourself. Better to keep using the last **
|
|
183
|
+
|
|
182
184
|
```js
|
|
183
185
|
const { createInstance } = require('polotno-node');
|
|
184
186
|
|
|
@@ -201,13 +201,13 @@ var e=require("react");module.exports=function(r,n,t){const u=e.useRef("loading"
|
|
|
201
201
|
},{"./utils.js":"Qid2"}],"N3c2":[function(require,module,exports) {
|
|
202
202
|
"use strict";var e=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.useFadeIn=exports.isAnimationUsed=exports.toggleFadeInAnimation=void 0;const t=e(require("react")),r=e(require("konva"));let n=!1;const o=(e=!n)=>{n=e};exports.toggleFadeInAnimation=o;const u=()=>n;function s(e,o){const u=t.default.useRef();t.default.useLayoutEffect(()=>{u.current&&u.current.destroy()},[o]),t.default.useLayoutEffect(()=>{if(!n)return;const t=e.current.opacity();return t?(e.current.opacity(0),u.current=new r.default.Tween({node:e.current,opacity:t,onFinish:()=>{var e;null===(e=u.current)||void 0===e||e.destroy()}}),u.current.play(),()=>{var e;null===(e=u.current)||void 0===e||e.destroy()}):void 0},[])}exports.isAnimationUsed=u,exports.useFadeIn=s;
|
|
203
203
|
},{"react":"HdMw","konva":"aTGn"}],"bN4e":[function(require,module,exports) {
|
|
204
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.triggerLoadError=exports.onLoadError=exports.whenLoaded=exports.decrementLoader=exports.incrementLoader=void 0;const e=require("../canvas/use-fadein");let o=0,r=[];function
|
|
204
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.triggerLoadError=exports.onLoadError=exports.whenLoaded=exports.decrementLoader=exports.incrementLoader=exports.setAssetLoadTimeout=void 0;const e=require("../canvas/use-fadein");let o=0,r=[],t=3e4;const s=e=>{t=e};function n(e){o+=1;let r=!1;Date.now();const s=setTimeout(()=>{r||(m(`Timeout loading image ${e}`),console.error("Timeout triggered for loader. Some assets may not have loaded.",e),r=!0,i())},t);return()=>{r||(clearTimeout(s),i())}}function i(){0===(o-=1)&&(r.forEach(e=>e()),r=[])}function a(e){0===o?e():r.push(e)}function d(){return new Promise(o=>a(()=>{(0,e.isAnimationUsed)()?setTimeout(o,300):o(!0)}))}exports.setAssetLoadTimeout=s,exports.incrementLoader=n,exports.decrementLoader=i,exports.whenLoaded=d;let u=[];function c(e){u.push(e)}function m(e){u.forEach(o=>o(e))}exports.onLoadError=c,exports.triggerLoadError=m;
|
|
205
205
|
},{"../canvas/use-fadein":"N3c2"}],"XXLd":[function(require,module,exports) {
|
|
206
206
|
"use strict";var t=this&&this.__createBinding||(Object.create?function(t,e,o,n){void 0===n&&(n=o);var r=Object.getOwnPropertyDescriptor(e,o);r&&!("get"in r?!e.__esModule:r.writable||r.configurable)||(r={enumerable:!0,get:function(){return e[o]}}),Object.defineProperty(t,n,r)}: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.isFontLoaded=exports.replaceGlobalFonts=exports.removeGlobalFont=exports.addGlobalFont=exports.globalFonts=exports.getFontsList=exports.setGoogleFonts=exports.isGoogleFontChanged=void 0;const n=o(require("mobx")),r=require("./loader");let s=n.observable(["Roboto","Amatic SC","Press Start 2P","Marck Script","Rubik Mono One"]),l=n.observable({value:!1});function a(){return l.value}function i(t){"default"!==t?(l.value=!0,s.splice(0,s.length),s.push(...t)):l.value=!1}function c(){return s}function u(t){exports.globalFonts.push(t)}function f(t){const e=exports.globalFonts.findIndex(e=>e.fontFamily===t);-1!==e&&exports.globalFonts.splice(e,1)}function p(t){exports.globalFonts.replace(t)}exports.isGoogleFontChanged=a,exports.setGoogleFonts=i,exports.getFontsList=c,exports.globalFonts=n.observable([]),exports.addGlobalFont=u,exports.removeGlobalFont=f,exports.replaceGlobalFonts=p;var d="Some test text;?#D-ПРИВЕТ!1230o9u8i7y6t5r4e3w2q1",m=document.createElement("canvas");function g(){return b("Arial")}function x(){return b("Times","Times")}function b(t,e="Arial"){var o=m.getContext("2d");return o.font=`normal 40px '${t}', ${e}`,o.measureText(d).width}const F=100,v={Arial:!0},y=t=>v[t];async function h(t){var e;if(v[t])return;const o=!!(null===(e=document.fonts)||void 0===e?void 0:e.load),n=g();if(o)try{if(await document.fonts.load(`16px '${t}'`),n!==b(t))return void(v[t]=!0)}catch(t){}const s=x(),l=b(t);for(let r=0;r<100;r++){const e=b(t,"Arial"),o=b(t,"Times");if(e!==l||e!==n||o!==s)return void(v[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?`),(0,r.triggerLoadError)(`Timeout for loading font "${t}"`)}exports.isFontLoaded=y,exports.loadFont=h;const G={};function _(t){if(G[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),G[t]=!0}exports.injectGoogleFont=_;const j={};function $(t){const e=t.fontFamily;if(j[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),j[t.fontFamily]=!0}exports.injectCustomFont=$;
|
|
207
207
|
},{"mobx":"BzvP","./loader":"bN4e"}],"IDY9":[function(require,module,exports) {
|
|
208
208
|
"use strict";var e=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n);var o=Object.getOwnPropertyDescriptor(t,n);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,o)}:function(e,t,n,r){void 0===r&&(r=n),e[r]=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 r={};if(null!=n)for(var o in n)"default"!==o&&Object.prototype.hasOwnProperty.call(n,o)&&e(r,n,o);return t(r,n),r};Object.defineProperty(exports,"__esModule",{value:!0}),exports.setTextOverflow=exports.setForceTextFit=exports.useDownScaling=exports.setDownScalingEnabled=exports.useHtmlTextRender=exports.useRemoveBackground=exports.setTextVerticalResizeEnabled=exports.flags=void 0;const r=n(require("mobx"));function o(e){exports.flags.textVerticalResizeEnabled=e}function s(e){exports.flags.removeBackgroundEnabled=e}function a(e){exports.flags.htmlRenderEnabled=e}function i(e){exports.flags.imageDownScalingEnabled=e}function l(e){console.warn("useDownScaling is deprecated. Use setDownScalingEnabled instead."),i(e)}function c(e){console.warn("setForceTextFit is deprecated. Use setTextOverflow instead."),exports.flags.textOverflow="change-font-size"}function u(e){exports.flags.textOverflow=e}exports.flags=r.observable({imageDownScalingEnabled:!0,removeBackgroundEnabled:!0,htmlRenderEnabled:!1,forceTextFitEnabled:!1,textVerticalResizeEnabled:!1,textOverflow:"resize"}),exports.setTextVerticalResizeEnabled=o,exports.useRemoveBackground=s,exports.useHtmlTextRender=a,exports.setDownScalingEnabled=i,exports.useDownScaling=l,exports.setForceTextFit=c,exports.setTextOverflow=u;
|
|
209
209
|
},{"mobx":"BzvP"}],"rHBV":[function(require,module,exports) {
|
|
210
|
-
"use strict";function e(e=""){return
|
|
210
|
+
"use strict";function e(e=""){return(e=e.replace(/<\/p>/gi,"\n")).replace(/(<([^>]+)>)/gi,"")}Object.defineProperty(exports,"__esModule",{value:!0}),exports.removeTags=void 0,exports.removeTags=e;
|
|
211
211
|
},{}],"Vshz":[function(require,module,exports) {
|
|
212
212
|
var t;(t=t||{}).stringify=function(){var t={"visit_linear-gradient":function(i){return t.visit_gradient(i)},"visit_repeating-linear-gradient":function(i){return t.visit_gradient(i)},"visit_radial-gradient":function(i){return t.visit_gradient(i)},"visit_repeating-radial-gradient":function(i){return t.visit_gradient(i)},visit_gradient:function(i){var r=t.visit(i.orientation);return r&&(r+=", "),i.type+"("+r+t.visit(i.colorStops)+")"},visit_shape:function(i){var r=i.value,n=t.visit(i.at),e=t.visit(i.style);return e&&(r+=" "+e),n&&(r+=" at "+n),r},"visit_default-radial":function(i){var r="",n=t.visit(i.at);return n&&(r+=n),r},"visit_extent-keyword":function(i){var r=i.value,n=t.visit(i.at);return n&&(r+=" at "+n),r},"visit_position-keyword":function(t){return t.value},visit_position:function(i){return t.visit(i.value.x)+" "+t.visit(i.value.y)},"visit_%":function(t){return t.value+"%"},visit_em:function(t){return t.value+"em"},visit_px:function(t){return t.value+"px"},visit_literal:function(i){return t.visit_color(i.value,i)},visit_hex:function(i){return t.visit_color("#"+i.value,i)},visit_rgb:function(i){return t.visit_color("rgb("+i.value.join(", ")+")",i)},visit_rgba:function(i){return t.visit_color("rgba("+i.value.join(", ")+")",i)},visit_color:function(i,r){var n=i,e=t.visit(r.length);return e&&(n+=" "+e),n},visit_angular:function(t){return t.value+"deg"},visit_directional:function(t){return"to "+t.value},visit_array:function(i){var r="",n=i.length;return i.forEach(function(i,e){r+=t.visit(i),e<n-1&&(r+=", ")}),r},visit:function(i){if(!i)return"";if(i instanceof Array)return t.visit_array(i,"");if(i.type){var r=t["visit_"+i.type];if(r)return r(i);throw Error("Missing visitor visit_"+i.type)}throw Error("Invalid node.")}};return function(i){return t.visit(i)}}(),(t=t||{}).parse=function(){var t={linearGradient:/^(\-(webkit|o|ms|moz)\-)?(linear\-gradient)/i,repeatingLinearGradient:/^(\-(webkit|o|ms|moz)\-)?(repeating\-linear\-gradient)/i,radialGradient:/^(\-(webkit|o|ms|moz)\-)?(radial\-gradient)/i,repeatingRadialGradient:/^(\-(webkit|o|ms|moz)\-)?(repeating\-radial\-gradient)/i,sideOrCorner:/^to (left (top|bottom)|right (top|bottom)|left|right|top|bottom)/i,extentKeywords:/^(closest\-side|closest\-corner|farthest\-side|farthest\-corner|contain|cover)/,positionKeywords:/^(left|center|right|top|bottom)/i,pixelValue:/^(-?(([0-9]*\.[0-9]+)|([0-9]+\.?)))px/,percentageValue:/^(-?(([0-9]*\.[0-9]+)|([0-9]+\.?)))\%/,emValue:/^(-?(([0-9]*\.[0-9]+)|([0-9]+\.?)))em/,angleValue:/^(-?(([0-9]*\.[0-9]+)|([0-9]+\.?)))deg/,startCall:/^\(/,endCall:/^\)/,comma:/^,/,hexColor:/^\#([0-9a-fA-F]+)/,literalColor:/^([a-zA-Z]+)/,rgbColor:/^rgb/i,rgbaColor:/^rgba/i,number:/^(([0-9]*\.[0-9]+)|([0-9]+\.?))/},i="";function r(t){var r=new Error(i+": "+t);throw r.source=i,r}function n(){var t=g(e);return i.length>0&&r("Invalid input not EOF"),t}function e(){return a("linear-gradient",t.linearGradient,u)||a("repeating-linear-gradient",t.repeatingLinearGradient,u)||a("radial-gradient",t.radialGradient,s)||a("repeating-radial-gradient",t.repeatingRadialGradient,s)}function a(i,n,e){return o(n,function(n){var a=e();return a&&(h(t.comma)||r("Missing comma before color stops")),{type:i,orientation:a,colorStops:g(d)}})}function o(i,n){var e=h(i);if(e){h(t.startCall)||r("Missing (");var a=n(e);return h(t.endCall)||r("Missing )"),a}}function u(){return y("directional",t.sideOrCorner,1)||y("angular",t.angleValue,1)}function s(){var r,n,e=l();return e&&((r=[]).push(e),n=i,h(t.comma)&&((e=l())?r.push(e):i=n)),r}function l(){var t=function(){var t=y("shape",/^(circle)/i,0);t&&(t.style=_()||v());return t}()||function(){var t=y("shape",/^(ellipse)/i,0);t&&(t.style=m()||v());return t}();if(t)t.at=c();else{var i=v();if(i){t=i;var r=c();r&&(t.at=r)}else{var n=f();n&&(t={type:"default-radial",at:n})}}return t}function v(){return y("extent-keyword",t.extentKeywords,1)}function c(){if(y("position",/^at/,0)){var t=f();return t||r("Missing positioning value"),t}}function f(){var t={x:m(),y:m()};if(t.x||t.y)return{type:"position",value:t}}function g(i){var n=i(),e=[];if(n)for(e.push(n);h(t.comma);)(n=i())?e.push(n):r("One extra comma");return e}function d(){var i=y("hex",t.hexColor,1)||o(t.rgbaColor,function(){return{type:"rgba",value:g(p)}})||o(t.rgbColor,function(){return{type:"rgb",value:g(p)}})||y("literal",t.literalColor,0);return i||r("Expected color definition"),i.length=m(),i}function p(){return h(t.number)[1]}function m(){return y("%",t.percentageValue,1)||y("position-keyword",t.positionKeywords,1)||_()}function _(){return y("px",t.pixelValue,1)||y("em",t.emValue,1)}function y(t,i,r){var n=h(i);if(n)return{type:t,value:n[r]}}function h(t){var r,n;return(n=/^[\n\r\t\s]+/.exec(i))&&b(n[0].length),(r=t.exec(i))&&b(r[0].length),r}function b(t){i=i.substr(t)}return function(t){return i=t.toString(),n()}}(),exports.parse=t.parse,exports.stringify=t.stringify;
|
|
213
213
|
},{}],"V8he":[function(require,module,exports) {
|
|
@@ -219,7 +219,7 @@ var t;(t=t||{}).stringify=function(){var t={"visit_linear-gradient":function(i){
|
|
|
219
219
|
},{"react":"HdMw","mobx-react-lite":"ZfSi","react-konva":"Sgug"}],"aH85":[function(require,module,exports) {
|
|
220
220
|
"use strict";var e=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.useMobile=exports.isMobile=exports.MOBILE_BREAKPOINT=void 0;const t=e(require("react"));exports.MOBILE_BREAKPOINT=500;const s=()=>window.innerWidth<=exports.MOBILE_BREAKPOINT;exports.isMobile=s;const o=()=>{const[e,s]=t.default.useState((0,exports.isMobile)());return t.default.useEffect(()=>{const e=()=>{s((0,exports.isMobile)())};return window.addEventListener("resize",e),()=>{window.removeEventListener("resize",e)}},[]),e};exports.useMobile=o;
|
|
221
221
|
},{"react":"HdMw"}],"Fpgh":[function(require,module,exports) {
|
|
222
|
-
"use strict";var e=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n);var i=Object.getOwnPropertyDescriptor(t,n);i&&!("get"in i?!t.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,i)}:function(e,t,n,r){void 0===r&&(r=n),e[r]=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 r={};if(null!=n)for(var i in n)"default"!==i&&Object.prototype.hasOwnProperty.call(n,i)&&e(r,n,i);return t(r,n),r},r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.TextElement=exports.useTextColor=exports.getLineHeight=exports.useFontLoader=exports.getDir=exports.isRTLText=void 0;const i=r(require("react")),o=require("mobx-react-lite"),a=require("react-konva"),l=require("react-konva-utils"),s=require("mobx"),d=r(require("konva")),u=require("svg-round-corners"),c=require("../utils/loader"),f=require("../utils/fonts"),h=require("../utils/flags"),g=require("../utils/text"),p=n(require("../utils/gradient")),x=require("./apply-filters"),y=require("./use-fadein"),m=require("./highlighter"),w=require("../utils/screen"),v=document.createElement("style");v.type="text/css",document.head.appendChild(v);const b={border:"none",padding:"0px",overflow:"hidden",background:"none",outline:"none",resize:"none",overflowWrap:"break-word",whiteSpace:"pre-wrap",userSelect:"text",wordBreak:"normal"};function S(e){var t="֑-߿יִ-﷽ﹰ-ﻼ";return new RegExp("^[^"+t+"]*?["+t+"]").test(e)}function E(e){e=e.replace(/\s/g,"");let t=0;for(var n=0;n<e.length;n++)S(e[n])&&(t+=1);return t>e.length/2}function M(e){return E(e)?"rtl":"ltr"}exports.isRTLText=E,exports.getDir=M;const z=(0,o.observer)(({textNodeRef:e,element:t,onBlur:n,selectAll:r,cursorPosition:o})=>{const[a,s]=i.default.useState(b),d=e.current;i.default.useLayoutEffect(()=>{const e={};e.width=d.width()-2*d.padding()+"px",e.height=d.height()-2*d.padding()+10+"px",e.fontSize=d.fontSize()+"px",e.lineHeight=d.lineHeight()+.01,e.fontFamily=d.fontFamily(),e.textAlign=d.align(),e.color=d.fill(),e.fontWeight=t.fontWeight,e.fontStyle=t.fontStyle,e.letterSpacing=t.letterSpacing+"em";const n=`\n .polotno-input::placeholder {\n color: ${a.color};\n opacity: 0.6;\n }\n `;v.innerHTML="",v.appendChild(document.createTextNode(n)),JSON.stringify(e)!==JSON.stringify(a)&&s(e)});const u=i.default.useRef(null);i.default.useEffect(()=>{const e=setTimeout(()=>{var e;const t=u.current;if(!t)return;null===(e=u.current)||void 0===e||e.focus();const n=o||t.value.length;t.selectionStart=t.selectionEnd=n,r&&(null==t||t.select(),document.execCommand("selectAll",!1,null))});return()=>{clearTimeout(e)}},[]);let c=0;const f=d.textArr.length*d.lineHeight()*d.fontSize();return"middle"===t.verticalAlign&&(c=(t.height-f)/2),"bottom"===t.verticalAlign&&(c=t.height-f),i.default.createElement(l.Html,null,i.default.createElement("textarea",{className:"polotno-input",ref:u,dir:M(t.text),style:Object.assign(Object.assign(Object.assign({},b),a),{paddingTop:c+"px"}),value:t.text,onChange:e=>{t.set({text:e.target.value})},placeholder:t.placeholder,onBlur:n}))}),T=e=>{const[t,n]=i.default.useState(!1),r=i.default.useRef(!1);return i.default.useEffect(()=>{var t=!0;return setTimeout(()=>{t&&(e._editModeEnabled&&(r.current=!0),n(!0),setTimeout(()=>{r.current=!1},50))},50),()=>{t=!1}},[]),{editorEnabled:t&&e._editModeEnabled,selectAll:r.current}},L=(e,t)=>{const[n,r]=i.default.useState((0,f.isFontLoaded)(t));return i.default.useLayoutEffect(()=>{if((0,f.isFontLoaded)(t))return void r(!0);let i=!0;return(async()=>{n&&r(!1);const o=(0,c.incrementLoader)(`text ${t}`);await e.loadFont(t),d.default.Util.requestAnimFrame(o),i&&r(!0)})(),()=>{i=!1}},[t]),[n]};exports.useFontLoader=L;const O=({fontLoaded:e,fontFamily:t,fontSize:n,lineHeight:r})=>i.default.useMemo(()=>{if("number"==typeof r)return r;const e=document.createElement("div");e.style.fontFamily=t,e.style.fontSize=n+"px",e.style.lineHeight=r,e.innerText="Test text",document.body.appendChild(e);const i=e.offsetHeight;return document.body.removeChild(e),i/n},[e,t,n,r]);function k(e){var t=e.getAbsoluteTransform().copy();t.invert();var n=e.getStage().getPointerPosition();return t.point(n)}function A(e){var t;const n=e.target,r=k(n),i=n.textArr,o=Math.floor(r.y/(n.fontSize()*n.lineHeight())),a=i.slice(0,o).reduce((e,t)=>e+t.text.length,o),l=null!==(t=i[o])&&void 0!==t?t:i[0];let s=0;return"right"===n.align()?s=n.width()-l.width:"center"===n.align()&&(s=n.width()/2-l.width/2),a+Math.round((r.x-s)/l.width*l.text.length)}function F(e){const t=i.default.useRef(e),n=i.default.useRef(e);return i.default.useEffect(()=>{n.current=t.current,t.current=e},[e]),n.current}function $(e,t){const n=e.getAttrs(),r=(0,g.removeTags)(t.text);let i=t.fontSize;const o=Math.round(2*t.fontSize)-1;for(let a=1;a<o;a++){const n=t.height&&e.height()>t.height,o=r.split("\n").join(" ").split(" ");let a=e.textArr.map(e=>e.text).join(";");const l=o.find(e=>!a.includes(e)||(a=a.replace(e,""),!1));if(!n&&!l)break;i-=.5,e.fontSize(i)}return e.fontSize(n.fontSize),i}function _({lines:e,lineHeight:t,width:n,align:r="left",padding:i=0,cornerRadius:o=0}){var a;e.forEach((e,t)=>{e.cx=n/2,"right"===r?e.cx=n-e.width/2:"left"===r&&(e.cx=e.width/2),"justify"!==r||e.lastInParagraph||(e.width=n),"justify"===r&&(e.cx=e.width/2)});let l=`M ${null===(a=e[0])||void 0===a?void 0:a.cx} ${-i}`;e.forEach((n,r)=>{const{cx:o}=n,a=e[r-1];a&&a.width>n.width?l+=` L ${o+n.width/2+i} ${r*t+i}`:l+=` L ${o+n.width/2+i} ${r*t-i}`;const s=e[r+1];s&&s.width>n.width?l+=` L ${o+n.width/2+i} ${(r+1)*t-i}`:l+=` L ${o+n.width/2+i} ${(r+1)*t+i}`});for(var s=e.length-1;s>=0;s--){const n=e[s],{cx:r}=n,o=e[s+1];o&&o.width>n.width?l+=` L ${r-n.width/2-i} ${(s+1)*t-i}`:l+=` L ${r-n.width/2-i} ${(s+1)*t+i}`;const a=e[s-1];a&&a.width>n.width?l+=` L ${r-n.width/2-i} ${s*t+i}`:l+=` L ${r-n.width/2-i} ${s*t-i}`}l+=" Z";const d=(0,u.parsePath)(l);return(0,u.roundCommands)(d,o).path}exports.getLineHeight=O;const P=e=>i.default.useMemo(()=>{if(!p.isGradient(e.fill))return{fill:e.fill};const{stops:t,rotation:n}=p.parseColor(e.fill),r={x:e.width/2,y:e.height/2},i=Math.sqrt(Math.pow(r.x,2)+Math.pow(r.y,2)),o=d.default.Util.degToRad(n)-Math.PI/2,a=[];return t.forEach(({offset:e,color:t})=>{a.push(e,t)}),{fillLinearGradientStartPointX:r.x-i*Math.cos(o),fillLinearGradientStartPointY:r.y-i*Math.sin(o),fillLinearGradientColorStops:a,fillLinearGradientEndPointX:r.x+i*Math.cos(o),fillLinearGradientEndPointY:r.y+i*Math.sin(o),fill:t[1].color,fillPriority:"linear-gradient"}},[e.fill]);exports.useTextColor=P,exports.TextElement=(0,o.observer)(({element:e,store:t})=>{const n=i.default.useRef(null),r=i.default.useRef(null),{editorEnabled:o,selectAll:l}=T(e),[d,u]=i.default.useState(!1),[c,f]=i.default.useState(!1),p=i.default.useRef(e.height),v=t.selectedElements.indexOf(e)>=0,{textVerticalResizeEnabled:b}=h.flags,S=F(e.fontFamily),[E,M]=i.default.useState([]);i.default.useEffect(()=>{var e,t;const r=null!==(t=null===(e=n.current)||void 0===e?void 0:e.textArr)&&void 0!==t?t:[];JSON.stringify(r)!==JSON.stringify(E)&&M(r)}),i.default.useEffect(()=>{if(e.width)return;const t=n.current;t.width(600),e.set({width:1.4*t.getTextWidth()})},[]),i.default.useLayoutEffect(()=>(0,s.autorun)(()=>{const t=n.current;(0,x.applyFilter)(t,e)}));const[L]=(0,exports.useFontLoader)(t,e.fontFamily),O=(0,g.removeTags)(e.text),k=()=>{const e=n.current.clone({height:void 0}),t=Math.ceil(e.fontSize()*e.lineHeight()*e.textArr.length+1);return e.destroy(),t};i.default.useLayoutEffect(()=>{if(!L)return;const{textOverflow:r}=h.flags;if(e.height)if("change-font-size"!==r||c){if("resize"===r){const r=k();b&&e.height<r&&t.history.ignore(()=>{e.set({height:r}),n.current.height(r)}),b||e.height===r||t.history.ignore(()=>{e.set({height:r}),n.current.height(r)})}}else{const r=$(n.current,e);if(r!==e.fontSize)return void t.history.ignore(()=>{e.set({fontSize:r})});const i=k();e.height!==i&&t.history.ignore(()=>{e.set({height:i})})}else{const n=k();t.history.ignore(()=>{e.set({height:n})})}}),i.default.useLayoutEffect(()=>{const t=n.current;t&&(t.width(t.width()+1e-8),t._setTextData(),(0,x.applyFilter)(t,e))},[L]);const P=i.default.useRef(null),R=i.default.useRef(0),H=n=>{n.evt.preventDefault(),t.selectedElements.find(t=>t===e)&&e.contentEditable&&(R.current=A(n),e.toggleEditMode())},q=!O&&e.placeholder?.6:e.a.opacity;(0,y.useFadeIn)(n,q);const C=(0,exports.getLineHeight)({fontLoaded:L,fontFamily:e.fontFamily,fontSize:e.fontSize,lineHeight:e.lineHeight}),j=e.selectable||"admin"===t.role,D=(0,exports.useTextColor)(e),W=i.default.useMemo(()=>e.backgroundEnabled?_({lines:E,cornerRadius:e.backgroundCornerRadius*(e.fontSize*C*.5),lineHeight:C*e.fontSize,padding:e.backgroundPadding*(e.fontSize*C*.5),width:e.width,align:e.align}):"",[e.backgroundEnabled,e.backgroundCornerRadius,e.fontSize,C,e.backgroundPadding,e.width,e.align,E]),X=(0,w.useMobile)();let Y=0;return"middle"===e.verticalAlign?Y=(e.height-E.length*C*e.fontSize)/2:"bottom"===e.verticalAlign&&(Y=e.height-E.length*C*e.fontSize),i.default.createElement(i.default.Fragment,null,i.default.createElement(a.Path,{ref:r,x:e.a.x,y:e.a.y,rotation:e.a.rotation,hideInExport:!e.showInExport||!O,listening:!1,visible:e.backgroundEnabled,opacity:e.backgroundOpacity,data:W,fill:e.backgroundColor,offsetY:-Y}),i.default.createElement(a.Text,Object.assign({ref:n,id:e.id,name:"element",hideInExport:!e.showInExport||!O,editModeEnabled:e._editModeEnabled,x:e.a.x,y:e.a.y,rotation:e.a.rotation,width:e.width,height:e.height,text:O||e.placeholder},D,{stroke:e.stroke,strokeWidth:e.strokeWidth,fillAfterStrokeEnabled:!0,fontSize:e.fontSize,fontFamily:`"${e.fontFamily}", "${S}"`,fontStyle:e.fontStyle+" "+e.fontWeight,textDecoration:e.textDecoration,align:e.align,verticalAlign:e.verticalAlign,draggable:X?e.draggable&&v:e.draggable,preventDefault:!X||v,opacity:q,visible:!e._editModeEnabled,ellipsis:"ellipsis"===h.flags.textOverflow,shadowEnabled:e.shadowEnabled,shadowBlur:e.shadowBlur,shadowOffsetX:e.shadowOffsetX,shadowOffsetY:e.shadowOffsetY,shadowColor:e.shadowColor,shadowOpacity:e.shadowOpacity,lineHeight:C,letterSpacing:e.letterSpacing*e.fontSize,listening:j,onDragStart:()=>{t.history.startTransaction()},onDragMove:t=>{e.set({x:t.target.x(),y:t.target.y()})},onDragEnd:n=>{e.set({x:n.target.x(),y:n.target.y()}),t.history.endTransaction()},onMouseEnter:()=>{u(!0)},onMouseLeave:()=>{u(!1)},onClick:H,onTap:H,onTransformStart:()=>{f(!0),t.history.startTransaction(),p.current=n.current.height()},onTransform:t=>{var n,i;const o=t.target;null===(n=r.current)||void 0===n||n.setAttrs({x:o.x(),y:o.y(),rotation:o.rotation(),scale:o.scale()});const a=(null===(i=o.getStage())||void 0===i?void 0:i.findOne("Transformer")).getActiveAnchor();if("middle-left"===a||"middle-right"===a){const t=o.scaleX(),n=o.width()*t,r=e.fontSize;let i=n;n<r&&(i=r,P.current&&o.position(P.current)),o.width(i),o.scaleX(1),o.scaleY(1);const a=k();if("ellipsis"!==h.flags.textOverflow){const t=Math.max(a,p.current);o.height(t),e.set({height:o.height()})}e.set({x:o.x(),y:o.y(),width:o.width(),rotation:o.rotation()}),(0,x.applyFilter)(o,e)}if("top-center"===a||"bottom-center"===a){let n="resize"===h.flags.textOverflow?k():C*e.fontSize;t.target.height(Math.max(n,t.target.height()*t.target.scaleY())),t.target.scaleY(1)}t.target.strokeWidth(e.strokeWidth/t.target.scaleX()),P.current=t.target.position()},onTransformEnd:n=>{var i;f(!1);const o=n.target.scaleX();n.target.scaleX(1),n.target.scaleY(1),n.target.strokeWidth(e.strokeWidth),e.set({fontSize:Math.round(e.fontSize*o),width:Math.ceil(n.target.width()*o),x:n.target.x(),y:n.target.y(),rotation:n.target.rotation(),height:n.target.height()*o}),t.history.endTransaction(),null===(i=r.current)||void 0===i||i.setAttrs({scaleX:1,scaleY:1})}})),o&&i.default.createElement(a.Group,{x:e.a.x,y:e.a.y,rotation:e.a.rotation},i.default.createElement(z,{textNodeRef:n,element:e,selectAll:l,cursorPosition:R.current,onBlur:()=>{e.toggleEditMode(!1)}})),!c&&(d||v)&&i.default.createElement(m.Highlighter,{element:e}))});
|
|
222
|
+
"use strict";var e=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r);var i=Object.getOwnPropertyDescriptor(t,r);i&&!("get"in i?!t.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,i)}: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.TextElement=exports.useTextColor=exports.usePrevious=exports.getLineHeight=exports.useFontLoader=exports.getDir=exports.isRTLText=void 0;const i=n(require("react")),o=require("mobx-react-lite"),a=require("react-konva"),l=require("react-konva-utils"),s=require("mobx"),d=n(require("konva")),u=require("svg-round-corners"),c=require("../utils/loader"),f=require("../utils/fonts"),h=require("../utils/flags"),g=require("../utils/text"),p=r(require("../utils/gradient")),x=require("./apply-filters"),y=require("./use-fadein"),m=require("./highlighter"),w=require("../utils/screen"),v=document.createElement("style");v.type="text/css",document.head.appendChild(v);const b={border:"none",padding:"0px",overflow:"hidden",background:"none",outline:"none",resize:"none",overflowWrap:"break-word",whiteSpace:"pre-wrap",userSelect:"text",wordBreak:"normal"};function S(e){var t="֑-߿יִ-﷽ﹰ-ﻼ";return new RegExp("^[^"+t+"]*?["+t+"]").test(e)}function E(e){e=e.replace(/\s/g,"");let t=0;for(var r=0;r<e.length;r++)S(e[r])&&(t+=1);return t>e.length/2}function M(e){return E(e)?"rtl":"ltr"}exports.isRTLText=E,exports.getDir=M;const T=(0,o.observer)(({textNodeRef:e,element:t,onBlur:r,selectAll:n,cursorPosition:o})=>{const[a,s]=i.default.useState(b),d=e.current;i.default.useLayoutEffect(()=>{const e={};e.width=d.width()-2*d.padding()+"px",e.height=d.height()-2*d.padding()+10+"px",e.fontSize=d.fontSize()+"px",e.lineHeight=d.lineHeight()+.01,e.fontFamily=d.fontFamily(),e.textAlign=d.align(),e.color=d.fill(),e.fontWeight=t.fontWeight,e.fontStyle=t.fontStyle,e.letterSpacing=t.letterSpacing+"em";const r=`\n .polotno-input::placeholder {\n color: ${a.color};\n opacity: 0.6;\n }\n `;v.innerHTML="",v.appendChild(document.createTextNode(r)),JSON.stringify(e)!==JSON.stringify(a)&&s(e)});const u=i.default.useRef(null);i.default.useEffect(()=>{const e=setTimeout(()=>{var e;const t=u.current;if(!t)return;null===(e=u.current)||void 0===e||e.focus();const r=o||t.value.length;t.selectionStart=t.selectionEnd=r,n&&(null==t||t.select(),document.execCommand("selectAll",!1,null))});return()=>{clearTimeout(e)}},[]);let c=0;const f=d.textArr.length*d.lineHeight()*d.fontSize();"middle"===t.verticalAlign&&(c=(t.height-f)/2),"bottom"===t.verticalAlign&&(c=t.height-f);const h=(0,g.removeTags)(t.text);return i.default.createElement(l.Html,null,i.default.createElement("textarea",{className:"polotno-input",ref:u,dir:M(h),style:Object.assign(Object.assign(Object.assign({},b),a),{paddingTop:c+"px"}),value:h,onChange:e=>{t.set({text:e.target.value})},placeholder:t.placeholder,onBlur:r}))}),z=e=>{const[t,r]=i.default.useState(!1),n=i.default.useRef(!1);return i.default.useEffect(()=>{var t=!0;return setTimeout(()=>{t&&(e._editModeEnabled&&(n.current=!0),r(!0),setTimeout(()=>{n.current=!1},50))},50),()=>{t=!1}},[]),{editorEnabled:t&&e._editModeEnabled,selectAll:n.current}},L=(e,t)=>{const[r,n]=i.default.useReducer(e=>e+1,0),o=i.default.useRef(!1);return o.current=!!(0,f.isFontLoaded)(t),i.default.useLayoutEffect(()=>{if(o.current)return;let r=!0;return(async()=>{o.current=!1,n();const i=(0,c.incrementLoader)(`text ${t}`);await e.loadFont(t),d.default.Util.requestAnimFrame(i),r&&(o.current=!0,n())})(),()=>{r=!1}},[t]),[o.current]};exports.useFontLoader=L;const O=({fontLoaded:e,fontFamily:t,fontSize:r,lineHeight:n})=>i.default.useMemo(()=>{if("number"==typeof n)return n;const e=document.createElement("div");e.style.fontFamily=t,e.style.fontSize=r+"px",e.style.lineHeight=n,e.innerText="Test text",document.body.appendChild(e);const i=e.offsetHeight;return document.body.removeChild(e),i/r},[e,t,r,n]);function k(e){var t=e.getAbsoluteTransform().copy();t.invert();var r=e.getStage().getPointerPosition();return t.point(r)}function A(e){var t;const r=e.target,n=k(r),i=r.textArr,o=Math.floor(n.y/(r.fontSize()*r.lineHeight())),a=i.slice(0,o).reduce((e,t)=>e+t.text.length,o),l=null!==(t=i[o])&&void 0!==t?t:i[0];let s=0;return"right"===r.align()?s=r.width()-l.width:"center"===r.align()&&(s=r.width()/2-l.width/2),a+Math.round((n.x-s)/l.width*l.text.length)}function P(e){const t=i.default.useRef(e),r=i.default.useRef(e);return i.default.useMemo(()=>{r.current=t.current,t.current=e},[e]),r.current}function R(e,t){const r=e.getAttrs(),n=(0,g.removeTags)(t.text);let i=t.fontSize;const o=Math.round(2*t.fontSize)-1;for(let a=1;a<o;a++){const r=t.height&&e.height()>t.height,o=n.split("\n").join(" ").split(" ");let a=e.textArr.map(e=>e.text).join(";");const l=o.find(e=>!a.includes(e)||(a=a.replace(e,""),!1));if(!r&&!l)break;i-=.5,e.fontSize(i)}return e.fontSize(r.fontSize),i}function $({lines:e,lineHeight:t,width:r,align:n="left",padding:i=0,cornerRadius:o=0}){var a;e.forEach((e,t)=>{e.cx=r/2,"right"===n?e.cx=r-e.width/2:"left"===n&&(e.cx=e.width/2),"justify"!==n||e.lastInParagraph||(e.width=r),"justify"===n&&(e.cx=e.width/2)});let l=`M ${null===(a=e[0])||void 0===a?void 0:a.cx} ${-i}`;e.forEach((r,n)=>{const{cx:o}=r,a=e[n-1];a&&a.width>r.width?l+=` L ${o+r.width/2+i} ${n*t+i}`:l+=` L ${o+r.width/2+i} ${n*t-i}`;const s=e[n+1];s&&s.width>r.width?l+=` L ${o+r.width/2+i} ${(n+1)*t-i}`:l+=` L ${o+r.width/2+i} ${(n+1)*t+i}`});for(var s=e.length-1;s>=0;s--){const r=e[s],{cx:n}=r,o=e[s+1];o&&o.width>r.width?l+=` L ${n-r.width/2-i} ${(s+1)*t-i}`:l+=` L ${n-r.width/2-i} ${(s+1)*t+i}`;const a=e[s-1];a&&a.width>r.width?l+=` L ${n-r.width/2-i} ${s*t+i}`:l+=` L ${n-r.width/2-i} ${s*t-i}`}l+=" Z";const d=(0,u.parsePath)(l);return(0,u.roundCommands)(d,o).path}exports.getLineHeight=O,exports.usePrevious=P;const F=e=>i.default.useMemo(()=>{if(!p.isGradient(e.fill))return{fill:e.fill};const{stops:t,rotation:r}=p.parseColor(e.fill),n={x:e.width/2,y:e.height/2},i=Math.sqrt(Math.pow(n.x,2)+Math.pow(n.y,2)),o=d.default.Util.degToRad(r)-Math.PI/2,a=[];return t.forEach(({offset:e,color:t})=>{a.push(e,t)}),{fillLinearGradientStartPointX:n.x-i*Math.cos(o),fillLinearGradientStartPointY:n.y-i*Math.sin(o),fillLinearGradientColorStops:a,fillLinearGradientEndPointX:n.x+i*Math.cos(o),fillLinearGradientEndPointY:n.y+i*Math.sin(o),fill:t[1].color,fillPriority:"linear-gradient"}},[e.fill]);exports.useTextColor=F,exports.TextElement=(0,o.observer)(({element:e,store:t})=>{const r=i.default.useRef(null),n=i.default.useRef(null),{editorEnabled:o,selectAll:l}=z(e),[d,u]=i.default.useState(!1),[c,f]=i.default.useState(!1),p=i.default.useRef(e.height),v=t.selectedElements.indexOf(e)>=0,{textVerticalResizeEnabled:b}=h.flags,S=P(e.fontFamily),[E,M]=i.default.useState([]);i.default.useEffect(()=>{var e,t;const n=null!==(t=null===(e=r.current)||void 0===e?void 0:e.textArr)&&void 0!==t?t:[];JSON.stringify(n)!==JSON.stringify(E)&&M(n)}),i.default.useEffect(()=>{if(e.width)return;const t=r.current;t.width(600),e.set({width:1.4*t.getTextWidth()})},[]),i.default.useLayoutEffect(()=>(0,s.autorun)(()=>{const t=r.current;(0,x.applyFilter)(t,e)}));const[L]=(0,exports.useFontLoader)(t,e.fontFamily),O=(0,g.removeTags)(e.text),k=()=>{const e=r.current.clone({height:void 0}),t=Math.ceil(e.fontSize()*e.lineHeight()*e.textArr.length+1);return e.destroy(),t};i.default.useLayoutEffect(()=>{if(!L)return;const{textOverflow:n}=h.flags;if(e.height)if("change-font-size"!==n||c){if("resize"===n){const n=k();b&&e.height<n&&t.history.ignore(()=>{e.set({height:n}),r.current.height(n)}),b||e.height===n||t.history.ignore(()=>{e.set({height:n}),r.current.height(n)})}}else{const n=R(r.current,e);if(n!==e.fontSize)return void t.history.ignore(()=>{e.set({fontSize:n})});const i=k();e.height!==i&&t.history.ignore(()=>{e.set({height:i})})}else{const r=k();t.history.ignore(()=>{e.set({height:r})})}}),i.default.useLayoutEffect(()=>{const t=r.current;t&&(t.width(t.width()+1e-8),t._setTextData(),(0,x.applyFilter)(t,e))},[L]);const F=i.default.useRef(null),_=i.default.useRef(0),H=r=>{r.evt.preventDefault(),t.selectedShapes.find(t=>t===e)&&e.contentEditable&&(_.current=A(r),e.toggleEditMode())},q=!O&&e.placeholder?.6:e.a.opacity;(0,y.useFadeIn)(r,q);const C=(0,exports.getLineHeight)({fontLoaded:L,fontFamily:e.fontFamily,fontSize:e.fontSize,lineHeight:e.lineHeight}),j=e.selectable||"admin"===t.role,D=(0,exports.useTextColor)(e),W=i.default.useMemo(()=>e.backgroundEnabled?$({lines:E,cornerRadius:e.backgroundCornerRadius*(e.fontSize*C*.5),lineHeight:C*e.fontSize,padding:e.backgroundPadding*(e.fontSize*C*.5),width:e.width,align:e.align}):"",[e.backgroundEnabled,e.backgroundCornerRadius,e.fontSize,C,e.backgroundPadding,e.width,e.align,E]),X=(0,w.useMobile)();let Y=0;return"middle"===e.verticalAlign?Y=(e.height-E.length*C*e.fontSize)/2:"bottom"===e.verticalAlign&&(Y=e.height-E.length*C*e.fontSize),i.default.createElement(i.default.Fragment,null,i.default.createElement(a.Path,{ref:n,x:e.a.x,y:e.a.y,rotation:e.a.rotation,hideInExport:!e.showInExport||!O,listening:!1,visible:e.backgroundEnabled,opacity:e.backgroundOpacity,data:W,fill:e.backgroundColor,offsetY:-Y}),i.default.createElement(a.Text,Object.assign({ref:r,id:e.id,name:"element",hideInExport:!e.showInExport||!O,editModeEnabled:e._editModeEnabled,x:e.a.x,y:e.a.y,rotation:e.a.rotation,width:e.width,height:e.height,text:O||e.placeholder},D,{stroke:e.stroke,strokeWidth:e.strokeWidth,fillAfterStrokeEnabled:!0,fontSize:e.fontSize,fontFamily:`"${e.fontFamily}", "${S}"`,fontStyle:e.fontStyle+" "+e.fontWeight,textDecoration:e.textDecoration,align:e.align,verticalAlign:e.verticalAlign,draggable:X?e.draggable&&v:e.draggable,preventDefault:!X||v,opacity:q,visible:!e._editModeEnabled,ellipsis:"ellipsis"===h.flags.textOverflow,shadowEnabled:e.shadowEnabled,shadowBlur:e.shadowBlur,shadowOffsetX:e.shadowOffsetX,shadowOffsetY:e.shadowOffsetY,shadowColor:e.shadowColor,shadowOpacity:e.shadowOpacity,lineHeight:C,letterSpacing:e.letterSpacing*e.fontSize,listening:j,onDragStart:()=>{t.history.startTransaction()},onDragMove:t=>{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()},onMouseEnter:()=>{u(!0)},onMouseLeave:()=>{u(!1)},onClick:H,onTap:H,onTransformStart:()=>{f(!0),t.history.startTransaction(),p.current=r.current.height()},onTransform:t=>{var r,i;const o=t.target;null===(r=n.current)||void 0===r||r.setAttrs({x:o.x(),y:o.y(),rotation:o.rotation(),scale:o.scale()});const a=(null===(i=o.getStage())||void 0===i?void 0:i.findOne("Transformer")).getActiveAnchor();if("middle-left"===a||"middle-right"===a){const t=o.scaleX(),r=o.width()*t,n=e.fontSize;let i=r;r<n&&(i=n,F.current&&o.position(F.current)),o.width(i),o.scaleX(1),o.scaleY(1);const a=k();if("ellipsis"!==h.flags.textOverflow){const t=Math.max(a,p.current);o.height(t),e.set({height:o.height()})}e.set({x:o.x(),y:o.y(),width:o.width(),rotation:o.rotation()}),(0,x.applyFilter)(o,e)}if("top-center"===a||"bottom-center"===a){let r="resize"===h.flags.textOverflow?k():C*e.fontSize;t.target.height(Math.max(r,t.target.height()*t.target.scaleY())),t.target.scaleY(1)}t.target.strokeWidth(e.strokeWidth/t.target.scaleX()),F.current=t.target.position()},onTransformEnd:r=>{var i;f(!1);const o=r.target.scaleX();r.target.scaleX(1),r.target.scaleY(1),r.target.strokeWidth(e.strokeWidth),e.set({fontSize:Math.round(e.fontSize*o),width:Math.ceil(r.target.width()*o),x:r.target.x(),y:r.target.y(),rotation:r.target.rotation(),height:r.target.height()*o}),t.history.endTransaction(),null===(i=n.current)||void 0===i||i.setAttrs({scaleX:1,scaleY:1})}})),o&&i.default.createElement(a.Group,{x:e.a.x,y:e.a.y,rotation:e.a.rotation},i.default.createElement(T,{textNodeRef:r,element:e,selectAll:l,cursorPosition:_.current,onBlur:()=>{e.toggleEditMode(!1)}})),!c&&(d||v)&&i.default.createElement(m.Highlighter,{element:e}))});
|
|
223
223
|
},{"react":"HdMw","mobx-react-lite":"ZfSi","react-konva":"Sgug","react-konva-utils":"jXQU","mobx":"BzvP","konva":"aTGn","svg-round-corners":"NKfw","../utils/loader":"bN4e","../utils/fonts":"XXLd","../utils/flags":"IDY9","../utils/text":"rHBV","../utils/gradient":"V8he","./apply-filters":"SIWI","./use-fadein":"N3c2","./highlighter":"cEy1","../utils/screen":"aH85"}],"B1DI":[function(require,module,exports) {
|
|
224
224
|
"use strict";var t=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.useSvgColors=exports.replaceColors=exports.sameColors=exports.fixSize=exports.getSvgSize=exports.svgToURL=exports.getColors=exports.urlToString=exports.urlToBase64=void 0;const e=t(require("konva")),r=t(require("react")),o=require("./gradient");function s(t){for(;t.parentNode;){if("defs"===t.nodeName)return!0;t=t.parentNode}return!1}function n(t){const e={fill:"",stroke:""};return t.getAttribute("fill")&&"none"!==t.getAttribute("fill")&&(e.fill=t.getAttribute("fill")),!e.fill&&t.style.fill&&"none"!==t.style.fill&&(e.fill=t.style.fill),t.getAttribute("stroke")&&(e.stroke=t.getAttribute("stroke")),!e.stroke&&t.style.stroke&&(e.stroke=t.style.stroke),e.stroke||e.fill||(e.fill="black"),e}const i=["path","rect","circle"];function l(t){for(var e=[],r=t.getElementsByTagName("*"),o=0,n=r.length;o<n;o++){const t=r[o];s(t)||(null!==t.getAttribute("fill")&&e.push(t),(null!==t.getAttribute("stroke")||t.style&&t.style.fill||i.indexOf(t.nodeName)>=0)&&e.push(t))}return e}async function a(t){const e=await fetch(t);return f(await e.text())}async function u(t){const e=await fetch(t,{mode:"cors"});return await e.text()}function c(t){const r=l((new DOMParser).parseFromString(t,"image/svg+xml")),o=[];return r.forEach(t=>{const{fill:r,stroke:s}=n(t);[r,s].forEach(t=>{t&&e.default.Util.colorToRGBA(t)&&-1===o.indexOf(t)&&o.push(t)})}),o}function f(t){return"data:image/svg+xml;base64,"+window.btoa(unescape(encodeURIComponent(t)))}async function p(t){const e=await u(t),r=(new DOMParser).parseFromString(e,"image/svg+xml").documentElement.getAttribute("viewBox"),[o,s,n,i]=(null==r?void 0:r.split(" "))||[];return{width:parseFloat(n),height:parseFloat(i)}}function d(t){var e=(new DOMParser).parseFromString(t,"image/svg+xml");const r=e.documentElement.getAttribute("viewBox"),[o,s,n,i]=(null==r?void 0:r.split(" "))||[],l=e.documentElement.getAttribute("width");!l&&e.documentElement.setAttribute("width",n+"px");const a=e.documentElement.getAttribute("height");if((!a||a.indexOf("%")>=0)&&e.documentElement.setAttribute("height",i+"px"),l&&l.indexOf("%")>=0&&a&&-1===a.indexOf("%")){const t=parseFloat(a)/parseFloat(i);e.documentElement.setAttribute("width",t*parseFloat(n)+"px")}if(a&&a.indexOf("%")>=0&&l&&-1===l.indexOf("%")){const t=parseFloat(l)/parseFloat(n);e.documentElement.setAttribute("height",t*parseFloat(i)+"px")}return(new XMLSerializer).serializeToString(e)}exports.urlToBase64=a,exports.urlToString=u,exports.getColors=c,exports.svgToURL=f,exports.getSvgSize=p,exports.fixSize=d;const g=(t,r)=>{if(!t||!r)return!1;const o=e.default.Util.colorToRGBA(t),s=e.default.Util.colorToRGBA(r);return o&&s?o.r===s.r&&o.g===s.g&&o.b===s.b&&o.a===s.a:void 0};function m(t,r,o,s){var n=t.namespaceURI,i=document.createElementNS(n,"linearGradient");const l=e.default.Util.degToRad(o+90),a=(Math.cos(l)+1)/2,u=(Math.sin(l)+1)/2,c=(Math.cos(l+Math.PI)+1)/2,f=(Math.sin(l+Math.PI)+1)/2;i.setAttribute("x1",100*a+"%"),i.setAttribute("y1",100*u+"%"),i.setAttribute("x2",100*c+"%"),i.setAttribute("y2",100*f+"%"),i.setAttribute("gradientUnits","userSpaceOnUse"),i.setAttribute("id",r);for(var p=0;p<s.length;p++){var d=s[p],g=document.createElementNS(n,"stop");for(var m in d)d.hasOwnProperty(m)&&g.setAttribute(m,d[m]);i.appendChild(g)}return(t.querySelector("defs")||t.insertBefore(document.createElementNS(n,"defs"),t.firstChild)).appendChild(i)}function x(t,e){var r=(new DOMParser).parseFromString(t,"image/svg+xml");const s=l(r),i=Array.from(e.keys());return s.forEach(t=>{const{fill:s,stroke:l}=n(t);[{prop:"fill",color:s},{prop:"stroke",color:l}].forEach(({prop:s,color:n})=>{const l=i.find(t=>(0,exports.sameColors)(t,n));if(l){const n=e.get(l);if((0,o.isGradient)(n)){const{rotation:e,stops:i}=(0,o.parseColor)(n),l=i.map(t=>({offset:100*t.offset+"%","stop-color":t.color})),a="color"+Math.round(1e8*Math.random());m(r.children[0],a,e,l),t.style[s]=null,t.setAttribute(s,`url('#${a}')`)}else t.style[s]=e.get(l)}})}),f((new XMLSerializer).serializeToString(r))}exports.sameColors=g,exports.replaceColors=x;const h=t=>{const[e,o]=r.default.useState([]);return r.default.useEffect(()=>{let e=!1;return(async()=>{o([]);const r=c(await u(t));e||o(r)})(),()=>{e=!0}},[t]),e};exports.useSvgColors=h;
|
|
225
225
|
},{"konva":"aTGn","react":"HdMw","./gradient":"V8he"}],"VbEp":[function(require,module,exports) {
|
|
@@ -279,13 +279,13 @@ var r,t=arguments[3];!function(n){if("object"==typeof exports&&"undefined"!=type
|
|
|
279
279
|
var define;
|
|
280
280
|
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)});
|
|
281
281
|
},{"url":"j37I","xmlserializer":"JMLK","sane-domparser-error":"ZgwT","inlineresources":"hv1m"}],"vcNA":[function(require,module,exports) {
|
|
282
|
-
"use strict";var e=this&&this.__createBinding||(Object.create?function(e,t,n,i){void 0===i&&(i=n);var o=Object.getOwnPropertyDescriptor(t,n);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,i,o)}: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=
|
|
282
|
+
"use strict";var e=this&&this.__createBinding||(Object.create?function(e,t,n,i){void 0===i&&(i=n);var o=Object.getOwnPropertyDescriptor(t,n);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,i,o)}: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="\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",l=document.createElement("div");function d(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",l.appendChild(t);const n=t.getBoundingClientRect();return l.removeChild(t),{width:n.width,height:n.height}}async function r({html:e,width:t,height:n,fontFamily:l,padding:d,font:r,pixelRatio:s}){const a=document.createElement("canvas");"Arial"===l||r||(e+=`<link type="text/css" href="https://fonts.googleapis.com/css?family=${l}" rel="stylesheet">`),r&&(e+=`<style>@font-face {font-family: '${r.fontFamily}'; src: url("${r.url}")}</style>`),e+=o;const c=await i.drawHTML(`<div style="padding: ${d}px;">${e}</div>`,a,{width:t+2*d,height:n+2*d});a.width=(t+2*d)*s,a.height=(n+2*d)*s;const h=a.getContext("2d");return null==h||h.drawImage(c.image,0,0,c.image.width*s,c.image.height*s),a}l.id="polotno-hidden-do-not-touch",l.style.overflow="hidden",l.style.position="relative",document.body.appendChild(l),l.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=d,exports.htmlToCanvas=r;
|
|
283
283
|
},{"rasterizehtml":"x2pr"}],"MEVn":[function(require,module,exports) {
|
|
284
284
|
"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;
|
|
285
285
|
},{}],"PsiH":[function(require,module,exports) {
|
|
286
286
|
"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;
|
|
287
287
|
},{"react":"HdMw","./goober":"MEVn"}],"BLZX":[function(require,module,exports) {
|
|
288
|
-
"use strict";var e=this&&this.__createBinding||(Object.create?function(e,t,i,n){void 0===n&&(n=i);var o=Object.getOwnPropertyDescriptor(t,i);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[i]}}),Object.defineProperty(e,n,o)}:function(e,t,i,n){void 0===n&&(n=i),e[n]=t[i]}),t=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=this&&this.__importStar||function(i){if(i&&i.__esModule)return i;var n={};if(null!=i)for(var o in i)"default"!==o&&Object.prototype.hasOwnProperty.call(i,o)&&e(n,i,o);return t(n,i),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 o=n(require("react")),r=require("mobx-react-lite"),a=require("react-konva"),l=n(require("quill/dist/quill")),s=n(require("konva")),d=i(require("mobx")),u=require("../utils/flags"),f=require("./apply-filters"),c=require("./text-element"),h=require("../utils/html2canvas"),g=require("./use-fadein"),m=require("./highlighter"),
|
|
288
|
+
"use strict";var e=this&&this.__createBinding||(Object.create?function(e,t,i,n){void 0===n&&(n=i);var o=Object.getOwnPropertyDescriptor(t,i);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[i]}}),Object.defineProperty(e,n,o)}:function(e,t,i,n){void 0===n&&(n=i),e[n]=t[i]}),t=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=this&&this.__importStar||function(i){if(i&&i.__esModule)return i;var n={};if(null!=i)for(var o in i)"default"!==o&&Object.prototype.hasOwnProperty.call(i,o)&&e(n,i,o);return t(n,i),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 o=n(require("react")),r=require("mobx-react-lite"),a=require("react-konva"),l=n(require("quill/dist/quill")),s=n(require("konva")),d=i(require("mobx")),u=require("../utils/flags"),f=require("./apply-filters"),c=require("./text-element"),h=require("../utils/html2canvas"),g=require("./use-fadein"),m=require("./highlighter"),x=require("react-konva-utils"),y=n(require("../utils/styled")),p=require("../utils/loader"),b=require("../utils/text"),w=i(require("../utils/fonts")),v=require("../utils/screen");exports.quillRef=d.observable({enabled:!1,currentFormat:{},editor:d.observable.object({instance:null},{},{deep:!1})});const S=(0,y.default)("div",o.default.forwardRef)`
|
|
289
289
|
.ql-editor {
|
|
290
290
|
outline: none;
|
|
291
291
|
}
|
|
@@ -303,16 +303,18 @@ var e;!function(t,n){void 0===t&&void 0!==window&&(t=window),"function"==typeof
|
|
|
303
303
|
.ql-direction-rtl {
|
|
304
304
|
direction: rtl;
|
|
305
305
|
}
|
|
306
|
-
`,E=({html:e,onBlur:t,onChange:i,element:n})=>{const r=o.default.useRef(null);o.default.useEffect(()=>{if(!r.current)return;const e=new l.default(r.current,{toolbar:!1,keyboard:!1,clipboard:{matchVisual:!1},formats:["background","bold","color","font","italic","size","strike","underline","indent","align","direction"]});return exports.quillRef.editor.instance=e,window.__polotnoQuill=e,e.on("text-change",()=>{e.getSelection()&&(exports.quillRef.currentFormat=e.getFormat()),setTimeout(()=>{var e;i(null===(e=r.current)||void 0===e?void 0:e.childNodes[0].innerHTML)},10)}),e.setSelection(0,0,"api"),e.on("selection-change",i=>{i||t(),i&&(exports.quillRef.currentFormat=e.getFormat())}),r.current.childNodes[0].addEventListener("blur",e=>{var i;(null===(i=e.relatedTarget)||void 0===i?void 0:i.classList.contains("ql-clipboard"))||t()}),()=>{exports.quillRef.editor.instance=null,exports.quillRef.currentFormat={},delete window.__polotnoQuill}},[]),o.default.useEffect(()=>{var t;const i=exports.quillRef.editor.instance;if(!i)return;const o=i.getSelection();if((null===(t=r.current)||void 0===t?void 0:t.childNodes[0].innerHTML)!==n.text){var a=i.clipboard.convert("<div class='ql-editor' style='outline: none;'>"+e+"<p><br></p></div>");i.setContents(a),i.history.clear(),o&&(i.setSelection(o.index,o.length),exports.quillRef.currentFormat=i.getFormat())}},[n.text]);const a=(0,c.useTextColor)(n).fill;return o.default.createElement(S,{ref:r,style:{fontSize:n.fontSize,color:a,width:n.width,fontFamily:n.fontFamily,lineHeight:n.lineHeight,letterSpacing:n.letterSpacing+"rem",textAlign:n.align},dir:(0,c.getDir)((0,b.removeTags)(n.text))})};function q(e,t,i){return o.default.useMemo(()=>(0,h.detectSize)(e),[e,t.width,i])}function z(e,{fontFamily:t="",color:i="black"}={}){let n=`color: ${i||e.fill}`;return`<div style="white-space: unset; width: ${Math.round(e.width||100)}px; ${n}; font-size: ${e.fontSize}px; font-family: '${t}'; text-decoration: ${e.textDecoration}; text-align: ${e.align}; line-height: ${e.lineHeight}; letter-spacing: ${e.letterSpacing}rem; font-style: ${e.fontStyle}; font-weight: ${e.fontWeight}; -webkit-text-stroke: ${e.strokeWidth}px ${e.stroke};" contentEditable dir="${(0,c.getDir)((0,b.removeTags)(e.text))}">${e.text}</div>`}const
|
|
306
|
+
`,E=({html:e,onBlur:t,onChange:i,element:n})=>{const r=o.default.useRef(null);o.default.useEffect(()=>{if(!r.current)return;const e=new l.default(r.current,{toolbar:!1,keyboard:!1,clipboard:{matchVisual:!1},formats:["background","bold","color","font","italic","size","strike","underline","indent","align","direction"]});return exports.quillRef.editor.instance=e,window.__polotnoQuill=e,e.on("text-change",()=>{e.getSelection()&&(exports.quillRef.currentFormat=e.getFormat()),setTimeout(()=>{var e;i(null===(e=r.current)||void 0===e?void 0:e.childNodes[0].innerHTML)},10)}),e.setSelection(0,0,"api"),e.on("selection-change",i=>{i||t(),i&&(exports.quillRef.currentFormat=e.getFormat())}),r.current.childNodes[0].addEventListener("blur",e=>{var i;(null===(i=e.relatedTarget)||void 0===i?void 0:i.classList.contains("ql-clipboard"))||t()}),()=>{exports.quillRef.editor.instance=null,exports.quillRef.currentFormat={},delete window.__polotnoQuill}},[]),o.default.useEffect(()=>{var t;const i=exports.quillRef.editor.instance;if(!i)return;const o=i.getSelection();if((null===(t=r.current)||void 0===t?void 0:t.childNodes[0].innerHTML)!==n.text){var a=i.clipboard.convert("<div class='ql-editor' style='outline: none;'>"+e+"<p><br></p></div>");i.setContents(a),i.history.clear(),o&&(i.setSelection(o.index,o.length),exports.quillRef.currentFormat=i.getFormat())}},[n.text]);const a=(0,c.useTextColor)(n).fill;return o.default.createElement(S,{ref:r,style:{fontSize:n.fontSize,color:a,width:n.width,fontFamily:n.fontFamily,lineHeight:n.lineHeight,letterSpacing:n.letterSpacing+"rem",textAlign:n.align},dir:(0,c.getDir)((0,b.removeTags)(n.text))})};function q(e,t,i){return o.default.useMemo(()=>(0,h.detectSize)(e),[e,t.width,i])}function z(e){const t=e.getContext("2d").getImageData(0,0,e.width,e.height).data;for(let i=0;i<t.length;i+=4)if(0!==t[i+3])return!0;return!1}function F(e){return!z(e)}function O(e,{fontFamily:t="",color:i="black"}={}){let n=`color: ${i||e.fill}`;return`<div style="white-space: unset; width: ${Math.round(e.width||100)}px; ${n}; font-size: ${e.fontSize}px; font-family: '${t}'; text-decoration: ${e.textDecoration}; text-align: ${e.align}; line-height: ${e.lineHeight}; letter-spacing: ${e.letterSpacing}rem; font-style: ${e.fontStyle}; font-weight: ${e.fontWeight}; -webkit-text-stroke: ${e.strokeWidth}px ${e.stroke};" contentEditable dir="${(0,c.getDir)((0,b.removeTags)(e.text))}">${e.text}</div>`}const _=e=>{let t=e.fontSize;for(let i=1;i<50;i++){const i=O(Object.assign(Object.assign({},e.toJSON()),{fontSize:t}),{fontFamily:e.fontFamily}),{height:n}=(0,h.detectSize)(i);if(!(e.height&&n>e.height))break;t-=.5}return t},R=/^((?!chrome|android).)*safari/i.test(navigator.userAgent);exports.HTMLElement=(0,r.observer)(({element:e,store:t})=>{const i=o.default.useRef(null),[n,r]=o.default.useState(),[l,y]=o.default.useState(!1),[b,z]=o.default.useState(!0),[k,T]=o.default.useState(!1),[M,$]=o.default.useState(!1),H=o.default.useRef(e.height),P=t.selectedElements.indexOf(e)>=0,C=e.fontSize/3,{textVerticalResizeEnabled:D}=u.flags,L=(0,c.usePrevious)(e.fontFamily),[X]=(0,c.useFontLoader)(t,e.fontFamily);(0,g.useFadeIn)(i);const Y=X?e.fontFamily:L!==e.fontFamily?L:"Arial",j=(0,c.useTextColor)(e).fill,I=O(e,{fontFamily:Y,color:j}),{width:A,height:B}=q(I,e,X);o.default.useEffect(()=>{if(!X)return;if(!e.height)return void e.set({height:B});const{textOverflow:i}=u.flags;if("change-font-size"!==i||l)"resize"===i&&(D&&e.height<B&&t.history.ignore(()=>{e.set({height:B})}),D||e.height===B||t.history.ignore(()=>{e.set({height:B})}));else{const i=_(e);i!==e.fontSize?t.history.ignore(()=>{e.set({fontSize:i})}):e.height!==B&&t.history.ignore(()=>{e.set({height:B})})}});const N=o.default.useRef(0);o.default.useEffect(()=>{l||k||(async()=>{N.current++;const i=N.current,n=(0,p.incrementLoader)(`text ${e.id}`);z(!0);let o=null;const a=R?5:1;for(let r=0;r<a;r++){if(o=await(0,h.htmlToCanvas)({html:I,width:e.width||1,height:e.height||B||1,fontFamily:Y,padding:C,pixelRatio:t._elementsPixelRatio,font:t.fonts.find(e=>e.fontFamily===Y)||w.globalFonts.find(e=>e.fontFamily===Y)}),i!==N.current)return void n();F(o)&&R&&await new Promise(e=>setTimeout(e,50*(r+1)))}o?(r(o),z(!1),s.default.Util.requestAnimFrame(n)):n()})()},[I,l,B,k,Y,e.height,t._elementsPixelRatio]);const V=l||b;o.default.useEffect(()=>d.autorun(()=>{const t=i.current;(0,f.applyFilter)(t,e)}),[n,V,e.shadowColor,e.shadowOffsetX,e.shadowOffsetY,e.shadowOpacity]);let G=0;"middle"===e.verticalAlign&&(G=(e.height-B)/2),"bottom"===e.verticalAlign&&(G=e.height-B);const Q=(0,c.getLineHeight)({fontLoaded:X,fontFamily:e.fontFamily,fontSize:e.fontSize,lineHeight:e.lineHeight}),W=(0,v.useMobile)();return o.default.createElement(o.default.Fragment,null,o.default.createElement(a.Rect,{x:e.x,y:e.y,offsetX:e.backgroundPadding*(e.fontSize*Q*.5),offsetY:e.backgroundPadding*(e.fontSize*Q*.5),rotation:e.rotation,hideInExport:!e.showInExport||!e.text,listening:!1,visible:e.backgroundEnabled,opacity:e.backgroundOpacity,fill:e.backgroundColor,width:e.width+e.backgroundPadding*(e.fontSize*Q),height:e.height+e.backgroundPadding*(e.fontSize*Q),cornerRadius:e.backgroundCornerRadius*(e.fontSize*Q*.5)}),o.default.createElement(a.Rect,{ref:i,name:"element",x:e.x,y:e.y,listening:e.selectable,rotation:e.rotation,width:e.width,height:e.height,visible:!V,draggable:W?e.draggable&&P:e.draggable,preventDefault:!W||P,opacity:k?0:e.opacity,hideInExport:!e.showInExport,onMouseEnter:()=>{$(!0)},onMouseLeave:()=>{$(!1)},onDragStart:()=>{t.history.startTransaction()},onDragMove:t=>{e.set({x:t.target.x(),y:t.target.y()})},onDragEnd:i=>{e.set({x:i.target.x(),y:i.target.y()}),t.history.endTransaction()},id:e.id,onDblClick:()=>{e.contentEditable&&T(!0)},onDblTap:()=>{e.contentEditable&&T(!0)},onTransformStart:t=>{y(!0),H.current=e.height},onTransform:t=>{var i;const n=t.target,o=(null===(i=n.getStage())||void 0===i?void 0:i.findOne("Transformer")).getActiveAnchor(),r="middle-left"===o||"middle-right"===o,a="top-center"===o||"bottom-center"===o,l=n.scaleX();if(r){const t=n.scaleX(),i=Math.max(n.width()*t,e.fontSize);if(n.width(i),n.scaleX(1),u.flags.textVerticalResizeEnabled){const t=Math.max(B,H.current);e.set({height:t})}e.set({width:i,x:n.x(),y:n.y()})}else if(a){let i="resize"===u.flags.textOverflow?B:e.lineHeight*e.fontSize;const o=Math.max(i,t.target.height()*t.target.scaleY());n.scaleY(1),e.set({x:n.x(),y:n.y(),height:o,rotation:n.rotation()})}else n.scaleX(1),n.scaleY(1),e.set({fontSize:e.fontSize*l,width:n.width()*l,x:n.x(),y:n.y(),rotation:n.rotation(),height:n.height()*l})},onTransformEnd:t=>{y(!1),z(!0);const i=t.target.scaleX();t.target.scaleX(1),t.target.scaleY(1),e.set({fontSize:e.fontSize*i,width:t.target.width()*i,x:t.target.x(),y:t.target.y(),rotation:t.target.rotation()})}}),o.default.createElement(a.Image,{ref:i,image:n,x:e.x,y:e.y,offsetX:C,offsetY:C-G,listening:!1,rotation:e.rotation,width:e.width+2*C,height:e.height+2*C,visible:!V,opacity:k?0:e.opacity,shadowEnabled:e.shadowEnabled,shadowBlur:e.shadowBlur,shadowOffsetX:e.shadowOffsetX,shadowOffsetY:e.shadowOffsetY,shadowColor:e.shadowColor,shadowOpacity:e.shadowOpacity,hideInExport:!e.showInExport}),V&&o.default.createElement(a.Group,{x:e.x,y:e.y,rotation:e.rotation,offsetY:-G},o.default.createElement(x.Html,{divProps:{style:{pointerEvents:"none"}}},o.default.createElement(S,{dangerouslySetInnerHTML:{__html:I},style:{pointerEvents:"none",display:"inline-block"}}))),k&&o.default.createElement(a.Group,{x:e.x,y:e.y,rotation:e.rotation,offsetY:-G},o.default.createElement(x.Html,null,o.default.createElement(E,{html:I,element:e,onChange:t=>{e.set({text:t})},onBlur:e=>{T(!1)}}))),(P||M)&&o.default.createElement(m.Highlighter,{element:e}))});
|
|
307
307
|
},{"react":"HdMw","mobx-react-lite":"ZfSi","react-konva":"Sgug","quill/dist/quill":"qREC","konva":"aTGn","mobx":"BzvP","../utils/flags":"IDY9","./apply-filters":"SIWI","./text-element":"Fpgh","../utils/html2canvas":"vcNA","./use-fadein":"N3c2","./highlighter":"cEy1","react-konva-utils":"jXQU","../utils/styled":"PsiH","../utils/loader":"bN4e","../utils/text":"rHBV","../utils/fonts":"XXLd","../utils/screen":"aH85"}],"RXmf":[function(require,module,exports) {
|
|
308
308
|
"use strict";var t=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.getTotalClientRect=exports.getClientRect=void 0;const e=t(require("konva"));function a(t,e,a,n,i){const x=Math.sqrt(a*a+n*n);return i+=Math.atan2(n,a),{x:t+x*Math.cos(i),y:e+x*Math.sin(i)}}function n(t){const{x:n,y:i,width:x,height:m}=t,o=e.default.Util.degToRad(t.rotation),h=a(n,i,0,0,o),r=a(n,i,x,0,o),s=a(n,i,x,m,o),u=a(n,i,0,m,o),c=Math.min(h.x,r.x,s.x,u.x),M=Math.min(h.y,r.y,s.y,u.y),l=Math.max(h.x,r.x,s.x,u.x),y=Math.max(h.y,r.y,s.y,u.y);return{x:c,y:M,width:l-c,height:y-M,minX:c,minY:M,maxX:l,maxY:y}}function i(t){const e=t.map(t=>n(t)),a=Math.min(...e.map(t=>t.minX)),i=Math.min(...e.map(t=>t.minY)),x=Math.max(...e.map(t=>t.maxX)),m=Math.max(...e.map(t=>t.maxY));return{x:a,y:i,width:x-a,height:m-i,minX:a,minY:i,maxX:x,maxY:m}}exports.getClientRect=n,exports.getTotalClientRect=i;
|
|
309
309
|
},{"konva":"aTGn"}],"F86d":[function(require,module,exports) {
|
|
310
310
|
"use strict";var e=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.useAnchorSnap=exports.useSnap=void 0;const t=e(require("react")),n=e(require("konva")),i=require("../utils/math");var r=5;function a(e){const t=e.__getNodeRect(),r=(0,i.getClientRect)(Object.assign(Object.assign({},t),{rotation:n.default.Util.radToDeg(t.rotation)})),a=e.getAbsolutePosition();return{vertical:[{guide:r.x,offset:a.x-r.x,snap:"start"},{guide:r.x+r.width/2,offset:a.x-r.x-r.width/2,snap:"center"},{guide:r.x+r.width,offset:a.x-r.x-r.width,snap:"end"}],horizontal:[{guide:r.y,offset:a.y-r.y,snap:"start"},{guide:r.y+r.height/2,offset:a.y-r.y-r.height/2,snap:"center"},{guide:r.y+r.height,offset:a.y-r.y-r.height,snap:"end"}]}}function o(e,t){var n=[],i=[];e.vertical.forEach(e=>{t.vertical.forEach(t=>{var i=Math.abs(e-t.guide);i<r&&n.push({lineGuide:e,diff:i,snap:t.snap,offset:t.offset})})}),e.horizontal.forEach(e=>{t.horizontal.forEach(t=>{var n=Math.abs(e-t.guide);n<r&&i.push({lineGuide:e,diff:n,snap:t.snap,offset:t.offset})})});var a=[];const o=n.sort((e,t)=>e.diff-t.diff),s=i.sort((e,t)=>e.diff-t.diff);var d=o[0],u=s[0];return d&&o.filter(e=>Math.abs(e.diff-d.diff)<.1).forEach(e=>{a.push(Object.assign({orientation:"V"},e))}),u&&s.filter(e=>Math.abs(e.diff-u.diff)<.1).forEach(e=>{a.push(Object.assign({orientation:"H"},e))}),a}function s(e){const i=e=>e.hasName("element")||e.hasName("page-background")||e.hasName("elements-area");function r(t){var n;const r=null===(n=e.current)||void 0===n?void 0:n.getStage();var a=[],o=[];return r.find(i).forEach(e=>{if(!(t.indexOf(e)>=0)){var n=e.getClientRect({skipShadow:!0,skipStroke:!0});a.push(n.x,n.x+n.width,n.x+n.width/2),o.push(n.y,n.y+n.height,n.y+n.height/2)}}),{vertical:a,horizontal:o}}function s(t){var i;const r=null===(i=e.current)||void 0===i?void 0:i.getLayer(),a=null==r?void 0:r.children.find(e=>"line-guides"===e.name());t.forEach(e=>{if("H"===e.orientation){var t=new n.default.Line({points:[-6e3,e.lineGuide,6e3,e.lineGuide],stroke:"rgb(0, 161, 255)",strokeWidth:1,name:"guid-line",dash:[4,6]});null==a||a.add(t),r.batchDraw()}else"V"===e.orientation&&(t=new n.default.Line({points:[e.lineGuide,-6e3,e.lineGuide,6e3],stroke:"rgb(0, 161, 255)",strokeWidth:1,name:"guid-line",dash:[4,6]}),null==a||a.add(t))})}const d=e=>{e.target.getLayer().children.find(e=>"line-guides"===e.name()).destroyChildren();var t=o(r(e.target.nodes()),a(e.target));if(!t.length)return;s(t);const n=e.target.getAbsolutePosition(),i=Object.assign({},n);t.forEach(e=>{switch(e.snap){case"start":case"center":case"end":switch(e.orientation){case"V":i.x=e.lineGuide+e.offset;break;case"H":i.y=e.lineGuide+e.offset}}});const d=i.x-n.x,u=i.y-n.y;e.evt.ctrlKey||e.evt.metaKey||e.target.nodes().forEach(e=>{const t=e.getAbsolutePosition();e.setAbsolutePosition({x:t.x+d,y:t.y+u})})},u=(t,n,i)=>{const a=e.current,d=a.getLayer();if(d.children.find(e=>"line-guides"===e.name()).destroyChildren(),"rotater"===a.getActiveAnchor())return n;if(Math.sqrt(Math.pow(n.x-t.x,2)+Math.pow(n.y-t.y,2))>50)return n;if(!d)return n;var u=o(r(a.nodes()),{vertical:[{guide:n.x,offset:0,snap:"start"}],horizontal:[{guide:n.y,offset:0,snap:"start"}]});if(!u.length)return n;if(s(u),i.ctrlKey||i.metaKey)return n;let c=n.x,f=n.x;u.forEach(e=>{switch(e.orientation){case"V":c=e.lineGuide;break;case"H":f=e.lineGuide}});const l=Math.abs(n.x-c)<10,h=Math.abs(n.y-f)<10;return l&&!h?{x:c,y:t.y}:h&&!l?{x:t.x,y:f}:l&&h?{x:c,y:f}:n},c=e=>{if(!e.target)return;const t=e.target.getLayer();t.children.find(e=>"line-guides"===e.name()).destroyChildren(),t.batchDraw()};t.default.useEffect(()=>{e.current&&(e.current.anchorDragBoundFunc(u),e.current.on("dragstart",()=>{setTimeout(()=>{const e=[...n.default.DD._dragElements.entries()];e.reverse(),n.default.DD._dragElements.clear(),e.forEach(([e,t])=>{n.default.DD._dragElements.set(e,t)})})}),e.current.on("dragmove",d),e.current.on("dragend",c),e.current.on("transformend",c))},[])}function d(e){return{vertical:[{guide:e.absolutePosition().x,offset:0,snap:"center"}],horizontal:[{guide:e.absolutePosition().y,offset:0,snap:"center"}]}}function u(e,i,r){const a=e=>e.hasName("element")||e.hasName("line-anchor")||e.hasName("page-background")||e.hasName("elements-area"),s=t=>{t.target.getLayer().children.find(e=>"line-guides"===e.name()).destroyChildren();var r=o(function(t){var n;const i=null===(n=e.current)||void 0===n?void 0:n.getStage();var r=[],o=[];return i.find(a).forEach(e=>{if(!(t.indexOf(e)>=0)){var n=e.getClientRect({skipShadow:!0,skipStroke:!0});e.hasName("line-anchor")&&(n={x:e.absolutePosition().x,y:e.absolutePosition().y,width:0,height:0}),r.push(n.x,n.x+n.width,n.x+n.width/2),o.push(n.y,n.y+n.height,n.y+n.height/2)}}),{vertical:r,horizontal:o}}([t.target,...i.map(e=>e.current)]),d(t.target));if(!r.length)return;!function(t){var i;const r=null===(i=e.current)||void 0===i?void 0:i.getLayer(),a=null==r?void 0:r.children.find(e=>"line-guides"===e.name());t.forEach(e=>{if("H"===e.orientation){var t=new n.default.Line({points:[-6e3,e.lineGuide,6e3,e.lineGuide],stroke:"rgb(0, 161, 255)",strokeWidth:1,name:"guid-line",dash:[4,6]});null==a||a.add(t),r.batchDraw()}else"V"===e.orientation&&(t=new n.default.Line({points:[e.lineGuide,-6e3,e.lineGuide,6e3],stroke:"rgb(0, 161, 255)",strokeWidth:1,name:"guid-line",dash:[4,6]}),null==a||a.add(t))})}(r);const s=t.target.getAbsolutePosition(),u=Object.assign({},s);r.forEach(e=>{switch(e.snap){case"start":case"center":case"end":switch(e.orientation){case"V":u.x=e.lineGuide+e.offset;break;case"H":u.y=e.lineGuide+e.offset}}});const c=u.x-s.x,f=u.y-s.y;if(!t.evt.ctrlKey&&!t.evt.metaKey){const e=t.target.getAbsolutePosition();t.target.absolutePosition({x:e.x+c,y:e.y+f})}},u=e=>{if(!e.target)return;const t=e.target.getLayer();t.children.find(e=>"line-guides"===e.name()).destroyChildren(),t.batchDraw()};t.default.useEffect(()=>{e.current&&(e.current.on("dragmove",s),e.current.on("dragend",u))},r)}exports.useSnap=s,exports.useAnchorSnap=u;
|
|
311
311
|
},{"react":"HdMw","konva":"aTGn","../utils/math":"RXmf"}],"JKBY":[function(require,module,exports) {
|
|
312
312
|
"use strict";var e=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.LineElement=exports.getLinePositionFromMiddlePoints=exports.getMiddlePoints=void 0;const t=e(require("react")),a=require("mobx-react-lite"),r=require("react-konva"),o=require("react-konva-utils"),n=require("./highlighter"),i=require("./use-transformer-snap"),s=require("../utils/screen");function h({x:e,y:t,width:a,height:r,rotation:o}){const n=o*Math.PI/180,i={x:e+r/2*Math.cos(n+Math.PI/2),y:t+r/2*Math.sin(n+Math.PI/2)};return{middleLeft:i,middleRight:{x:i.x+a*Math.cos(n),y:i.y+a*Math.sin(n)}}}function l(e,t,a){const r=Math.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2)),o=Math.atan2(t.y-e.y,t.x-e.x),n=180*o/Math.PI;return{x:e.x+Math.cos(o-Math.PI/2)*a/2,y:e.y+Math.sin(o-Math.PI/2)*a/2,width:r,height:a,rotation:n}}exports.getMiddlePoints=h,exports.getLinePositionFromMiddlePoints=l;const d=(e,t)=>({offsetX:5/e,offsetY:5/e,width:10/e,height:10/e,fill:"white",stroke:"rgb(0, 161, 255)",strokeWidth:2,strokeScaleEnabled:!1,draggable:!0,dragDistance:0,onMouseEnter:e=>{e.target.getStage().container().style.cursor="crosshair"},onMouseLeave:e=>{e.target.getStage().container().style.cursor=""},onDragStart:e=>{t.history.startTransaction()},onDragEnd:e=>{t.history.endTransaction()}}),c=(0,a.observer)(({element:e,type:a})=>{const o={strokeWidth:e.height,stroke:e.a.color,lineCap:"round",lineJoin:"round",fill:e.a.color,opacity:e.a.opacity};return t.default.createElement(t.default.Fragment,null,"arrow"===a&&t.default.createElement(r.Line,Object.assign({points:[3*e.height,2*-e.height,0,0,3*e.height,2*e.height]},o)),"triangle"===a&&t.default.createElement(r.Line,Object.assign({points:[3*e.height,2*-e.height,0,0,3*e.height,2*e.height],closed:!0},o)),"bar"===a&&t.default.createElement(r.Line,Object.assign({points:[0,2*-e.height,0,2*e.height],closed:!0},o)),"square"===a&&t.default.createElement(r.Line,Object.assign({points:[0,2*-e.height,4*e.height,2*-e.height,4*e.height,2*e.height,0,2*e.height],closed:!0},o)),"circle"===a&&t.default.createElement(r.Circle,Object.assign({x:2*e.height,y:0,radius:2*e.height},o)))});exports.LineElement=(0,a.observer)(({element:e,store:a})=>{const g=t.default.useRef(null),u=t.default.useRef(null),f=t.default.useRef(null),y=e.selectable||"admin"===a.role,m=(0,s.useMobile)(),[x,p]=t.default.useState(!1),E=a.selectedElements.indexOf(e)>=0&&1===a.selectedElements.length,{middleLeft:M,middleRight:w}=h(e);return(0,i.useAnchorSnap)(u,[g],[E]),(0,i.useAnchorSnap)(f,[g],[E]),t.default.createElement(t.default.Fragment,null,t.default.createElement(r.Line,{ref:g,name:"element",id:e.id,x:e.a.x,y:e.a.y,points:[0,0,e.width,0],offsetY:-e.height/2,strokeWidth:e.height,hitStrokeWidth:Math.max(e.height,20),dash:e.dash.map(t=>t*e.height),stroke:e.a.color,rotation:e.a.rotation,opacity:e.animated("opacity"),shadowEnabled:e.shadowEnabled,shadowBlur:e.shadowBlur,shadowOffsetX:e.shadowOffsetX,shadowOffsetY:e.shadowOffsetY,shadowColor:e.shadowColor,shadowOpacity:e.shadowOpacity,listening:y,draggable:m?e.draggable&&E:e.draggable,preventDefault:!m||E,hideInExport:!e.showInExport,onMouseEnter:()=>{p(!0)},onMouseLeave:()=>{p(!1)},onDragStart:()=>{a.history.startTransaction()},onDragMove:t=>{e.set({x:t.target.x(),y:t.target.y()})},onDragEnd:t=>{e.set({x:t.target.x(),y:t.target.y()}),a.history.endTransaction()},onTransformStart:()=>{a.history.startTransaction()},onTransform:t=>{const a=t.target.scaleX();t.target.scaleX(1),t.target.scaleY(1),e.set({height:e.height*a,width:e.width*a,x:t.target.x(),y:t.target.y(),rotation:t.target.rotation()})},onTransformEnd:e=>{a.history.endTransaction()}}),t.default.createElement(r.Group,{x:M.x,y:M.y,rotation:e.rotation},t.default.createElement(c,{element:e,type:e.startHead})),t.default.createElement(r.Group,{x:w.x,y:w.y,rotation:e.rotation+180},t.default.createElement(c,{element:e,type:e.endHead})),x&&!E&&t.default.createElement(n.Highlighter,{element:e}),E&&e.resizable&&t.default.createElement(o.Portal,{selector:".page-abs-container",enabled:!0},t.default.createElement(r.Group,{visible:E},t.default.createElement(r.Rect,Object.assign({x:M.x,y:M.y,ref:u,name:"line-anchor"},d(a.scale,a),{onDragMove:t=>{const a=l(t.target.position(),w,e.height);e.set({x:a.x,y:a.y,width:a.width,rotation:a.rotation})}})),t.default.createElement(r.Rect,Object.assign({x:w.x,y:w.y,ref:f,name:"line-anchor"},d(a.scale,a),{onDragMove:t=>{const a=l(M,t.target.position(),e.height);e.set({x:a.x,y:a.y,width:a.width,rotation:a.rotation})}})))))});
|
|
313
|
-
},{"react":"HdMw","mobx-react-lite":"ZfSi","react-konva":"Sgug","react-konva-utils":"jXQU","./highlighter":"cEy1","./use-transformer-snap":"F86d","../utils/screen":"aH85"}],"
|
|
314
|
-
"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"),i=require("./html-element"),o=require("./line-element"),a=require("react-konva"),m=require("../utils/flags"),s=(0,r.observer)(e=>{const{element:r,store:n}=e,{children:l}=r,i=r.selectable||"admin"===n.role;return t.default.createElement(a.Group,{opacity:r.opacity,listening:i},l.map(r=>t.default.createElement(p,Object.assign({},e,{key:r.id,store:n,element:r}))))}),u={text:n.TextElement,image:l.ImageElement,svg:l.ImageElement,line:o.LineElement,group:s};function c(e,t){u[e]=t}exports.registerShapeComponent=c;const p=(0,r.observer)(e=>{let r=u[e.element.type];return"text"===e.element.type&&m.flags.htmlRenderEnabled&&(r=i.HTMLElement),e.element.visible?r?t.default.createElement(r,Object.assign({},e)):(console.error("Can not find component for "+e.element.type),null):null});exports.default=p;
|
|
315
|
-
},{"react":"HdMw","mobx-react-lite":"ZfSi","
|
|
313
|
+
},{"react":"HdMw","mobx-react-lite":"ZfSi","react-konva":"Sgug","react-konva-utils":"jXQU","./highlighter":"cEy1","./use-transformer-snap":"F86d","../utils/screen":"aH85"}],"pMve":[function(require,module,exports) {
|
|
314
|
+
"use strict";var e=this&&this.__createBinding||(Object.create?function(e,t,r,a){void 0===a&&(a=r);var i=Object.getOwnPropertyDescriptor(t,r);i&&!("get"in i?!t.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,a,i)}:function(e,t,r,a){void 0===a&&(a=r),e[a]=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 a={};if(null!=r)for(var i in r)"default"!==i&&Object.prototype.hasOwnProperty.call(r,i)&&e(a,r,i);return t(a,r),a},a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.VideoElement=exports.useImageLoader=exports.setImageLoaderHook=void 0;const i=a(require("react")),o=require("mobx-react-lite"),n=require("mobx"),h=require("react-konva"),d=a(require("use-image")),l=a(require("konva")),c=r(require("../utils/svg")),u=require("react-konva-utils"),s=require("./highlighter"),g=require("../utils/loader"),f=require("../utils/flags"),p=require("./apply-filters"),w=require("./use-fadein"),m=require("../utils/screen");function x(){return document.createElement("canvas")}async function y(e){if(!(e.indexOf("data:image/svg+xml")>=0||e.indexOf(".svg")>=0))return e;const t=await c.urlToString(e),r=c.fixSize(t);return c.svgToURL(r)}const v=e=>{const[t,r]=i.default.useState(e);return i.default.useEffect(()=>{(async()=>{const a=await y(e);a!==t&&r(a)})()},[e]),t},M=new window.Image;M.src=c.svgToURL('\n <svg width="800px" height="800px" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">\n <path opacity="0.6" d="M4 5.49683V18.5032C4 20.05 5.68077 21.0113 7.01404 20.227L18.0694 13.7239C19.384 12.9506 19.384 11.0494 18.0694 10.2761L7.01404 3.77296C5.68077 2.98869 4 3.95 4 5.49683Z" fill="white"/>\n <path d="M4 5.49683V18.5032C4 20.05 5.68077 21.0113 7.01404 20.227L18.0694 13.7239C19.384 12.9506 19.384 11.0494 18.0694 10.2761L7.01404 3.77296C5.68077 2.98869 4 3.95 4 5.49683Z" stroke="#323232" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>\n </svg>\n');const E=new window.Image;E.src=c.svgToURL('\n <svg width="800px" height="800px" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">\n <path opacity="0.6" d="M14 19L14 5C14 3.89543 14.8954 3 16 3L17 3C18.1046 3 19 3.89543 19 5L19 19C19 20.1046 18.1046 21 17 21L16 21C14.8954 21 14 20.1046 14 19Z" fill="white"/>\n <path opacity="0.6" d="M10 19L10 5C10 3.89543 9.10457 3 8 3L7 3C5.89543 3 5 3.89543 5 5L5 19C5 20.1046 5.89543 21 7 21L8 21C9.10457 21 10 20.1046 10 19Z" fill="white"/>\n <path d="M14 19L14 5C14 3.89543 14.8954 3 16 3L17 3C18.1046 3 19 3.89543 19 5L19 19C19 20.1046 18.1046 21 17 21L16 21C14.8954 21 14 20.1046 14 19Z" stroke="#323232" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>\n <path d="M10 19L10 5C10 3.89543 9.10457 3 8 3L7 3C5.89543 3 5 3.89543 5 5L5 19C5 20.1046 5.89543 21 7 21L8 21C9.10457 21 10 20.1046 10 19Z" stroke="#323232" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>\n </svg>\n');const b=(e,t,r)=>{const a=i.default.useMemo(()=>{var a,i;const{flipX:o,flipY:n}=e,h="svg"===e.type||e.src.indexOf("data:image/svg+xml")>=0||e.src.indexOf(".svg")>=0,d=navigator.userAgent.toLowerCase().indexOf("firefox")>-1&&h||e.maskSrc;if(!o&&!n&&!d)return t;if(!t||!t.width||!t.height)return null;const l=x();let c=1;"svg"===e.type&&(c=Math.max(e.width/t.width*r,e.height/t.height*r)),l.width=Math.max(t.width*c,1),l.height=Math.max(t.height*c,1);let u=o?-l.width:0,s=n?-l.height:0;return null===(a=l.getContext("2d"))||void 0===a||a.scale(o?-1:1,n?-1:1),null===(i=l.getContext("2d"))||void 0===i||i.drawImage(t,u,s,l.width,l.height),l},[e.maskSrc,e.flipX,e.flipY,t,e.width,e.height,r]);return i.default.useEffect(()=>()=>{a&&"CANVAS"===a.nodeName&&l.default.Util.releaseCanvas(a)},[a]),a};function C(e,t){const r=t.width/t.height;let a,i;return r>=e.width/e.height?(a=e.width,i=e.width/r):(a=e.height*r,i=e.height),{x:(e.width-a)/2,y:(e.height-i)/2,width:a,height:i}}function L(e,t,r,a,i,o,n){for(var h=new ImageData(t,r),d=new Int32Array(e.data.buffer),l=e.width,c=new Int32Array(h.data.buffer),u=h.width,s=t/o,g=r/n,f=Math.round(1/s),p=Math.round(1/g),w=f*p,m=0;m<h.height;m++)for(var x=0;x<u;x++){for(var y=a+Math.round(x/s)+(i+Math.round(m/g))*l,v=0,M=0,E=0,b=0,C=0;C<p;C++)for(var L=0;L<f;L++){var I=d[y+L+C*l];v+=I<<24>>>24,M+=I<<16>>>24,E+=I<<8>>>24,b+=I>>>24}v=Math.round(v/w),M=Math.round(M/w),E=Math.round(E/w),b=Math.round(b/w),c[x+m*u]=b<<24|E<<16|M<<8|v}return h}function I(e,t){var r,a;const i=x();i.width=e.width,i.height=e.height,null===(r=i.getContext("2d"))||void 0===r||r.drawImage(e,0,0,i.width,i.height);const o=L(i.getContext("2d").getImageData(0,0,i.width,i.height),Math.floor(i.width*t),Math.floor(i.height*t),0,0,i.width,i.height);return i.width=Math.floor(i.width*t),i.height=Math.floor(i.height*t),null===(a=i.getContext("2d"))||void 0===a||a.putImageData(o,0,0),i}const R=(e,t,r,a,o=0,n=!1)=>{const h=Math.floor(Math.max(e.width*a,1)),d=Math.floor(Math.max(e.height*a,1)),c=Math.min(o*a,h/2,d/2),u=Math.max(e.width/r.width,e.height/r.height)*a,s=e.page._exporting&&f.flags.imageDownScalingEnabled&&u<1&&!n,g=0===r.x&&0===r.y&&r.width===(null==t?void 0:t.width)&&r.height===(null==t?void 0:t.height),p=i.default.useMemo(()=>{if(t&&t.width&&t.height)return g&&0===c&&!s?void 0:x()},[t,c,s,g]);return i.default.useLayoutEffect(()=>{if(!p||!t)return;p.width=h,p.height=d;const e=p.getContext("2d");if(!e)return;c&&(e.beginPath(),e.moveTo(c,0),e.lineTo(h-c,0),e.arc(h-c,c,c,3*Math.PI/2,0,!1),e.lineTo(h,d-c),e.arc(h-c,d-c,c,0,Math.PI/2,!1),e.lineTo(c,d),e.arc(c,d-c,c,Math.PI/2,Math.PI,!1),e.lineTo(0,c),e.arc(c,c,c,Math.PI,3*Math.PI/2,!1),e.clip());const a=s?I(t,u):t,i=s?{x:Math.floor(r.x*u),y:Math.floor(r.y*u),width:Math.floor(r.width*u),height:Math.floor(r.height*u)}:r;e.drawImage(a,i.x,i.y,i.width,i.height,0,0,p.width,p.height)},[p,e.width,e.height,r.x,r.y,r.width,r.height,o,a,n,e.page._exporting,s]),i.default.useEffect(()=>()=>{p&&"CANVAS"===p.nodeName&&l.default.Util.releaseCanvas(p)},[p]),p||t},S=(e,t,r,a)=>{const o=v(e.clipSrc||""),[n,h]=T(o,"anonymous"),d=e.clipSrc?h:"loaded";(0,exports.useImageLoader)(d,e.id+"-clip");const c=i.default.useMemo(()=>{if(t&&n)return x()},[t,n]);return i.default.useLayoutEffect(()=>{var a;if(!n)return;if(!t||!t.width||!t.height)return;if(!n||!n.width||!n.height)return;if(!c)return;const i=x(),o=Math.max(e.width/n.width*r,e.height/n.height*r);i.width=n.width*o,i.height=n.height*o,null===(a=i.getContext("2d"))||void 0===a||a.drawImage(n,0,0,i.width,i.height),c.width=Math.max(t.width,1),c.height=Math.max(t.height,1);const h=c.getContext("2d");h&&(h.save(),h.drawImage(i,0,0,t.width,t.height),l.default.Util.releaseCanvas(i),h.globalCompositeOperation="source-in",h.drawImage(t,0,0,c.width,c.height),h.restore())},[c,t,n,e.width,e.height,r,...a]),e.clipSrc&&n?c:t},k=x(),_=(0,o.observer)(({element:e})=>{const t=Math.min(30,e.width/4,e.height/4),r=i.default.useRef(null);return i.default.useEffect(()=>{const e=r.current;if(!e)return;const t=new l.default.Animation(t=>{e.rotate(((null==t?void 0:t.timeDiff)||0)/2)},e.getLayer());return t.start(),()=>{t.stop()}}),i.default.createElement(h.Group,{x:e.x,y:e.y,rotation:e.rotation,listening:!1,opacity:e.a.opacity,hideInExport:!e.showInExport},i.default.createElement(h.Rect,{width:e.width,height:e.height,fill:"rgba(124, 173, 212, 0.8)"}),i.default.createElement(h.Arc,{ref:r,x:e.width/2,y:e.height/2,fill:"white",outerRadius:Math.abs(t),innerRadius:Math.max(1,t-5),angle:270}))}),O=(0,o.observer)(({element:e})=>{const t="Can not load the image...",r=Math.max(10,Math.min(30,e.width/t.length));return i.default.createElement(h.Group,{x:e.x,y:e.y,rotation:e.rotation,listening:!1,opacity:e.a.opacity,hideInExport:!e.showInExport},i.default.createElement(h.Rect,{width:e.width,height:e.height,fill:"rgba(223, 102, 102, 0.8)"}),i.default.createElement(h.Text,{text:t,fontSize:r,width:e.width,height:e.height,align:"center",fill:"white",verticalAlign:"middle",padding:5}))});let T=d.default;const X=e=>{T=e};exports.setImageLoaderHook=X;const Y=(e,t)=>{const r=i.default.useRef(),a=()=>{var e;null===(e=r.current)||void 0===e||e.call(r),r.current=void 0};i.default.useEffect(()=>a,[]),i.default.useLayoutEffect(()=>{"loading"!==e||r.current||(r.current=(0,g.incrementLoader)(`image ${t}`)),"loading"!==e&&a(),"failed"===e&&(0,g.triggerLoadError)(`image ${t}`)},[e])};exports.useImageLoader=Y;const W=({image:e,status:t,type:r})=>{const a=i.default.useRef();return i.default.useEffect(()=>{a.current=e||a.current},[e]),"failed"!==t||"failed"!==t&&"svg"===r?a.current:void 0},P=e=>{const[t,r]=i.default.useReducer(e=>e+1,0),a=i.default.useRef("loading"),o=i.default.useRef(e.src),n=i.default.useRef(e.src);return n.current!==e.src&&(n.current=e.src,a.current="loading"),i.default.useEffect(()=>{if("image"===e.type)return;if(!e.src)return;let t=!1;return(async()=>{a.current="loading",r();const i=await c.urlToString(e.src),n=c.fixSize(i),h=c.replaceColors(n,e.colorsReplace);t||(o.current=h,a.current="loaded",r())})(),()=>{t=!0}},[e.src,JSON.stringify(e.colorsReplace)]),"image"===e.type?[e.src,"loaded"]:[o.current,a.current]};function A(e,t,r){const a=i.default.useRef("loading"),o=i.default.useRef(),[n,h]=i.default.useState(0),d=i.default.useRef(),l=i.default.useRef(),c=i.default.useRef();return d.current===e&&l.current===t&&c.current===r||(a.current="loading",o.current=void 0,d.current=e,l.current=t,c.current=r),i.default.useLayoutEffect(function(){if(e){var i=document.createElement("video");return i.addEventListener("canplay",n),i.addEventListener("error",d),t&&(i.crossOrigin=t),r&&(i.referrerpolicy=r),i.src=e,function(){i.removeEventListener("canplay",n),i.removeEventListener("error",d)}}function n(){a.current="loaded",o.current=i,h(Math.random())}function d(){a.current="failed",o.current=void 0,h(Math.random())}},[e,t,r]),[o.current,a.current]}exports.VideoElement=(0,o.observer)(({element:e,store:t})=>{var r;const[a,o]=i.default.useState(!1),d=i.default.useRef(null),c=i.default.useRef(null),[g,f]=i.default.useState(!1),x=t.selectedElements.indexOf(e)>=0,[y,v]=i.default.useState(!1),[b,C]=A(e.src,"anonymous");b&&(b.muted=!0,b.width=b.videoWidth,b.height=b.videoHeight);const L=b||k;i.default.useEffect(()=>{b&&t.history.ignore(()=>{e.set({duration:1e3*b.duration})})},[b]),i.default.useEffect(()=>{var e;if(!b)return;const r=t.isPlaying||y;if(!r)return void b.pause();r&&b.play();const a=new l.default.Animation(()=>{},null===(e=d.current)||void 0===e?void 0:e.getLayer());a.start();const i=()=>{v(!1),b.currentTime=0};return b.addEventListener("ended",i),()=>{a.stop(),b.removeEventListener("ended",i)}},[b,y,t.isPlaying]),i.default.useEffect(()=>(0,n.autorun)(()=>{var r,a;if(b){const i=t.currentTime%e.duration;console.log("rest",i),b.currentTime=i/1e3,null===(a=null===(r=d.current)||void 0===r?void 0:r.getLayer())||void 0===a||a.batchDraw()}}),[t,b]);let{cropX:I,cropY:T,cropWidth:X,cropHeight:Y}=e;"loaded"!==C&&(I=T=0,X=Y=1);const W=L.width*X,P=L.height*Y,H=e.width/e.height;let D,q;const z=W/P,j="svg"===e.type;j?(D=W,q=P):H>=z?(D=W,q=W/H):(D=P*H,q=P);const B={x:L.width*I,y:L.height*T,width:D,height:q},F=null!==(r=e.cornerRadius)&&void 0!==r?r:0;let N=S(e,R(e,L,B,t._elementsPixelRatio,F,a||e._cropModeEnabled||"svg"===e.type),t._elementsPixelRatio,[B,F,t._elementsPixelRatio]);const V=Math.max(e.width/D,e.height/q);i.default.useEffect(()=>{var t;if(!e._cropModeEnabled)return;const r=null===(t=d.current)||void 0===t?void 0:t.getStage();function a(t){e._cropModeEnabled&&t.target!==c.current&&e.toggleCropMode(!1)}function i(t){e._cropModeEnabled&&"CANVAS"!==t.target.nodeName&&e.toggleCropMode(!1)}return document.body.addEventListener("click",i),null==r||r.on("click",a),null==r||r.on("tap",a),()=>{document.body.removeEventListener("click",i),document.body.removeEventListener("touchstart",i),null==r||r.off("click",a),null==r||r.off("click",a)}},[e._cropModeEnabled]),i.default.useLayoutEffect(()=>{if(!a&&!e._cropModeEnabled)return(0,p.applyFilter)(d.current,e),(0,n.autorun)(()=>{(0,p.applyFilter)(d.current,e)},{delay:100})},[L,a,X,Y,e._cropModeEnabled]),i.default.useLayoutEffect(()=>{var t;a||e._cropModeEnabled?null===(t=d.current)||void 0===t||t.clearCache():(0,p.applyFilter)(d.current,e)},[a,e.width,e.height,e._cropModeEnabled]),i.default.useEffect(()=>{(0,p.applyFilter)(d.current,e)},[e.shadowEnabled,e.shadowBlur,e.cornerRadius,e.shadowColor,e.shadowOffsetX,e.shadowOffsetY,e.shadowOpacity]);const U=i.default.useRef(null),Z=i.default.useRef(null),G=i.default.useRef(null);i.default.useLayoutEffect(()=>{e._cropModeEnabled&&(Z.current.nodes([U.current]),G.current.nodes([c.current]))},[e._cropModeEnabled]);const $=t=>{Math.round(t.target.x())>0&&(t.target.x(0),t.target.scaleX(1)),Math.round(t.target.y())>0&&(t.target.y(0),t.target.scaleY(1));const r=t.target.width()*t.target.scaleX(),a=t.target.height()*t.target.scaleY(),i=Math.min(1,D/r),o=Math.min(1,q/a),n=1-i,h=Math.min(n,Math.max(0,Math.round(-t.target.x())/r)),d=1-o,l=Math.min(d,Math.max(0,Math.round(-t.target.y())/a));t.target.setAttrs({x:-h*L.width,y:-l*L.height,scaleX:1,scaleY:1}),e.set({cropX:h,cropY:l,cropWidth:i,cropHeight:o})},J=()=>{"svg"!==e.type&&e.contentEditable&&setTimeout(()=>{e.toggleCropMode(!0)})},K="svg"===e.type&&oldImage,Q="loading"===C&&!K,ee="failed"===C,te=!Q&&!ee,re=i.default.useRef({cropX:0,cropY:0,cropWidth:0,cropHeight:0}),ae=te?e.a.opacity:0;(0,w.useFadeIn)(d,ae);const ie=e.selectable||"admin"===t.role,oe=(0,m.useMobile)();return i.default.createElement(i.default.Fragment,null,Q&&i.default.createElement(_,{element:e}),ee&&i.default.createElement(O,{element:e}),i.default.createElement(h.Image,{ref:d,name:"element",id:e.id,image:L,x:e.x,y:e.y,width:e.width||1,height:e.height||1,rotation:e.rotation,opacity:ae,shadowEnabled:e.shadowEnabled,shadowBlur:e.shadowBlur,shadowOffsetX:e.shadowOffsetX,shadowOffsetY:e.shadowOffsetY,shadowColor:e.shadowColor,shadowOpacity:e.shadowOpacity,customCrop:B,listening:ie,cropX:B.x,cropY:B.y,cropWidth:B.width,cropHeight:B.height,draggable:oe?e.draggable&&x:e.draggable,preventDefault:!oe||x,hideInExport:!e.showInExport,onMouseEnter:()=>{f(!0)},onMouseLeave:()=>{f(!1)},onDragStart:()=>{t.history.startTransaction()},onDragMove:t=>{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()},onDblClick:J,onDblTap:J,onTransformStart:()=>{o(!0),t.history.startTransaction(),re.current={cropX:e.cropX,cropY:e.cropY,cropWidth:e.cropWidth,cropHeight:e.cropHeight}},onTransform:t=>{var r;const a=t.currentTarget,i=Math.abs(a.scaleX()-1)<1e-7?1:a.scaleX(),o=Math.abs(a.scaleY()-1)<1e-7?1:a.scaleY();a.scaleX(1),a.scaleY(1);const n=null===(r=t.target.getStage())||void 0===r?void 0:r.findOne("Transformer"),h=1-D/L.width,d=Math.min(h,Math.max(0,e.cropX)),l=1-q/L.height,c=Math.min(l,Math.max(0,e.cropY)),u=n.getActiveAnchor(),s=!(u.indexOf("middle")>=0||u.indexOf("center")>=0),g=!s&&i<1&&re.current.cropHeight>q/L.height;let f=s?e.cropWidth:e.cropWidth*i;g&&(f=e.cropWidth);const p=!s&&o<1&&re.current.cropWidth>D/L.width;let w=s?e.cropHeight:e.cropHeight*o;p&&(w=e.cropHeight),j&&(f=e.cropWidth,w=e.cropHeight),e.set({cropX:d,cropY:c,x:a.x(),y:a.y(),width:a.width()*i,height:a.height()*o,rotation:t.target.rotation(),cropWidth:Math.min(f,1-d),cropHeight:Math.min(w,1-c)})},onTransformEnd:r=>{const a=r.currentTarget;e.set({width:a.width(),height:a.height(),x:a.x(),y:a.y(),rotation:r.target.rotation(),cropWidth:D/L.width,cropHeight:q/L.height}),o(!1),t.history.endTransaction()}}),i.default.createElement(h.Rect,{x:e.x,y:e.y,width:Math.max(e.width-e.borderSize,0),height:Math.max(e.height-e.borderSize,0),opacity:ae,offsetX:-e.borderSize/2,offsetY:-e.borderSize/2,stroke:e.borderColor,strokeWidth:e.borderSize,listening:!1,visible:!!e.borderSize,rotation:e.rotation,cornerRadius:Math.max(0,F-e.borderSize),hideInExport:!e.showInExport}),!y&&i.default.createElement(h.Image,{image:M,x:e.x+e.width/2-20,y:e.y+e.height/2-20,width:40,height:40,hideInExport:!0,onClick:()=>{v(!0)}}),y&&i.default.createElement(h.Image,{image:E,x:e.x+e.width/2-20,y:e.y+e.height/2-20,width:40,height:40,hideInExport:!0,onClick:()=>{v(!1)}}),e._cropModeEnabled&&i.default.createElement(u.Portal,{selector:".page-abs-container",enabled:!0},i.default.createElement(h.Rect,{x:-window.innerWidth/t.scale,y:-window.innerWidth/t.scale,width:window.innerWidth/t.scale*3,height:window.innerWidth/t.scale*3,fill:"rgba(0,0,0,0.3)"}),i.default.createElement(h.Image,{listening:!1,image:N,x:e.x,y:e.y,width:e.width,height:e.height,rotation:e.rotation,shadowEnabled:e.shadowEnabled,shadowBlur:e.shadowBlur}),i.default.createElement(h.Group,{x:e.x,y:e.y,rotation:e.rotation,scaleX:V,scaleY:V},i.default.createElement(h.Image,{image:L,ref:c,opacity:.4,draggable:!0,x:-e.cropX*L.width,y:-e.cropY*L.height,onDragMove:$,onTransform:$}),i.default.createElement(h.Transformer,{ref:G,anchorSize:20,enabledAnchors:["top-left","top-right","bottom-left","bottom-right"],boundBoxFunc:(e,t)=>t.width<5||t.height<5?e:t,rotateEnabled:!1,borderEnabled:!1,anchorCornerRadius:10,anchorStrokeWidth:2,borderStrokeWidth:2}),i.default.createElement(h.Rect,{width:D,height:q,ref:U,listening:!1,onTransform:t=>{t.target.x()<-e.cropX*L.width-1e-9&&(t.target.x(-e.cropX*L.width),t.target.scaleX(1)),t.target.y()<-e.cropY*L.height-1e-9&&(t.target.y(-e.cropY*L.height),t.target.scaleY(1));const r=Math.min(1,Math.max(0,e.cropX+t.target.x()/L.width)),a=Math.min(1,Math.max(0,t.target.y()/L.height+e.cropY)),i=t.target.width()*t.target.scaleX(),o=t.target.height()*t.target.scaleY(),n=Math.min(1-r,i/L.width),h=Math.min(1-a,o/L.height),d=t.target.getAbsolutePosition(t.target.getParent().getParent());t.target.scale({x:1,y:1}),t.target.position({x:0,y:0}),e.set({x:d.x,y:d.y,cropX:r,cropY:a,cropWidth:n,cropHeight:h,width:Math.min(i*V,L.width*(1-r)*V),height:Math.min(o*V,L.height*(1-a)*V)})}}),i.default.createElement(h.Transformer,{ref:Z,enabledAnchors:["top-left","top-right","bottom-left","bottom-right"],boundBoxFunc:(e,t)=>t.width<5||t.height<5?e:t,keepRatio:!1,rotateEnabled:!1,anchorFill:"rgb(240, 240, 240)",anchorStrokeWidth:2,borderStrokeWidth:2}))),(g||x)&&i.default.createElement(s.Highlighter,{element:e}))});
|
|
315
|
+
},{"react":"HdMw","mobx-react-lite":"ZfSi","mobx":"BzvP","react-konva":"Sgug","use-image":"MJM3","konva":"aTGn","../utils/svg":"B1DI","react-konva-utils":"jXQU","./highlighter":"cEy1","../utils/loader":"bN4e","../utils/flags":"IDY9","./apply-filters":"SIWI","./use-fadein":"N3c2","../utils/screen":"aH85"}],"XEPK":[function(require,module,exports) {
|
|
316
|
+
"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"),i=require("./html-element"),o=require("./line-element"),m=require("./video-element"),a=require("react-konva"),s=require("../utils/flags"),u=(0,r.observer)(e=>{const{element:r,store:n}=e,{children:l}=r,i=r.selectable||"admin"===n.role;return t.default.createElement(a.Group,{opacity:r.opacity,listening:i},l.map(r=>t.default.createElement(d,Object.assign({},e,{key:r.id,store:n,element:r}))))}),c={text:n.TextElement,image:l.ImageElement,svg:l.ImageElement,line:o.LineElement,video:m.VideoElement,group:u};function p(e,t){c[e]=t}exports.registerShapeComponent=p;const d=(0,r.observer)(e=>{let r=c[e.element.type];return"text"===e.element.type&&s.flags.htmlRenderEnabled&&(r=i.HTMLElement),e.element.visible?r?t.default.createElement(r,Object.assign({},e)):(console.error("Can not find component for "+e.element.type),null):null});exports.default=d;
|
|
317
|
+
},{"react":"HdMw","mobx-react-lite":"ZfSi","./text-element":"Fpgh","./image-element":"VbEp","./html-element":"BLZX","./line-element":"JKBY","./video-element":"pMve","react-konva":"Sgug","../utils/flags":"IDY9"}],"hfHf":[function(require,module,exports) {
|
|
316
318
|
"use strict";function t(t,e,h="scale"){const i=e.width/e.height;let o,r;i>=t.width/t.height?(o=t.width,r=t.width/i):(o=t.height*i,r=t.height);let d=0,g=0;return"left-top"===h?(d=0,g=0):"left-middle"===h?(d=0,g=(t.height-r)/2):"left-bottom"===h?(d=0,g=t.height-r):"center-top"===h?(d=(t.width-o)/2,g=0):"center-middle"===h?(d=(t.width-o)/2,g=(t.height-r)/2):"center-bottom"===h?(d=(t.width-o)/2,g=t.height-r):"right-top"===h?(d=t.width-o,g=0):"right-middle"===h?(d=t.width-o,g=(t.height-r)/2):"right-bottom"===h?(d=t.width-o,g=t.height-r):"scale"===h?(d=0,g=0,o=t.width,r=t.height):console.error(new Error("Unknown clip position property - "+h)),{cropX:d,cropY:g,cropWidth:o,cropHeight:r}}Object.defineProperty(exports,"__esModule",{value:!0}),exports.getCrop=void 0,exports.getCrop=t;
|
|
317
319
|
},{}],"Qw3W":[function(require,module,exports) {
|
|
318
320
|
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Alignment=void 0;var e={CENTER:"center",LEFT:"left",RIGHT:"right"};exports.Alignment=e;
|
|
@@ -3257,7 +3259,7 @@ var e="undefined"!=typeof Element,r="function"==typeof Map,t="function"==typeof
|
|
|
3257
3259
|
},{"react":"HdMw","../utils/math":"RXmf","../utils/unit":"BUt3","mobx-react-lite":"ZfSi"}],"NI5R":[function(require,module,exports) {
|
|
3258
3260
|
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.handleHotkey=void 0;let e=[],t="";const o="polotno_clipboard",l=t=>{e=t;try{localStorage.setItem(o,JSON.stringify(t))}catch(t){}},d=()=>{try{const e=localStorage.getItem(o);if(e)return JSON.parse(e)}catch(t){}return e};function n(e,o){var n,a,c,i,r,s,v,u;if("INPUT"===(null===(n=document.activeElement)||void 0===n?void 0:n.tagName)||"TEXTAREA"===(null===(a=document.activeElement)||void 0===a?void 0:a.tagName)||"true"===(null===(c=document.activeElement)||void 0===c?void 0:c.contentEditable))return;const m=o.selectedElements.filter(e=>e.removable),f=m.map(e=>e.id);46!==e.keyCode&&8!==e.keyCode||o.deleteElements(f);const y=e.ctrlKey||e.metaKey,p=e.shiftKey;if(y&&!p&&"KeyZ"===e.code&&(e.preventDefault(),o.history.undo()),y&&p&&"KeyZ"===e.code&&(e.preventDefault(),o.history.redo()),y&&"KeyA"===e.code){e.preventDefault();const t=null===(i=o.activePage)||void 0===i?void 0:i.children.filter(e=>e.selectable),l=(null==t?void 0:t.map(e=>e.id))||[];o.selectElements(l)}if(y&&"KeyC"===e.code&&(e.preventDefault(),t=null===(r=o.activePage)||void 0===r?void 0:r.id,l(o.selectedElements.map(e=>e.toJSON()))),y&&"KeyX"===e.code&&(e.preventDefault(),t=null===(s=o.activePage)||void 0===s?void 0:s.id,l(o.selectedElements.map(e=>e.toJSON())),o.deleteElements(m)),y&&"KeyV"===e.code){e.preventDefault();let n=0;t===(null===(v=o.activePage)||void 0===v?void 0:v.id)&&(n=o.width/20),t=null===(u=o.activePage)||void 0===u?void 0:u.id,o.history.transaction(()=>{const e=[],t=d();t.forEach(t=>{var l;delete t.id,t.x+=n,t.y+=n;const d=null===(l=o.activePage)||void 0===l?void 0:l.addElement(t);d&&e.push(d.id)}),l(t),o.selectElements(e)})}"ArrowDown"===e.code&&(e.preventDefault(),o.selectedElements.forEach(e=>{e.set({y:e.y+1})})),"ArrowUp"===e.code&&(e.preventDefault(),o.selectedElements.forEach(e=>{e.set({y:e.y-1})})),"ArrowLeft"===e.code&&(e.preventDefault(),o.selectedElements.forEach(e=>{e.set({x:e.x-1})})),"ArrowRight"===e.code&&(e.preventDefault(),o.selectedElements.forEach(e=>{e.set({x:e.x+1})}))}exports.handleHotkey=n;
|
|
3259
3261
|
},{}],"twsc":[function(require,module,exports) {
|
|
3260
|
-
"use strict";var e=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.Workspace=void 0;const t=e(require("react")),r=require("mobx-react-lite"),a=e(require("./page")),n=require("./rules"),o=require("./hotkeys"),l=require("../utils/l10n"),s=(e,t,r)=>Math.max(t,Math.min(r,e)),i="Polotno warning: <Workspace /> component can not automatically detect its size.\nWidth or height of parent elements is equal 0.\nPlease make sure it has non-zero size. You may need to adjust it with your styles. <Workspace /> will automatically fit into parent container.\nFor simpler debugging here is the log of the parent element:",c=(e,r,a,n,o,l)=>{const s=t.default.useRef({width:r,height:a}),i=t.default.useRef({top:0,left:0}),c=t.default.useRef(!1),u=t.default.useRef(o.pages.length);c.current=u.current!==o.pages.length,u.current=o.pages.length,t.default.useEffect(()=>{const t=e.current,r=e=>{i.current={top:t.scrollTop,left:t.scrollLeft}};return t.addEventListener("scroll",r),()=>{t.removeEventListener("scroll",r)}},[]),t.default.useLayoutEffect(()=>{if(!e.current)return;if(c.current)return;const t=e.current,n=(i.current.left+t.offsetWidth/2)/s.current.width,o=(i.current.top+t.offsetHeight/2)/s.current.height;l.current=!0,t.scrollLeft=n*r-t.offsetWidth/2,t.scrollTop=o*a-t.offsetHeight/2,s.current={width:r,height:a}},[n,r,a])},u=(e,r,a,n,o)=>{const l=t.default.useRef(!1),s=t.default.useRef(null);t.default.useEffect(()=>{const t=e.current,r=()=>{o.current};return t.addEventListener("scroll",r),()=>{t.removeEventListener("scroll",r)}},[]);const i=a.pages.indexOf(a.activePage);return t.default.useLayoutEffect(()=>{if(!a.activePage)return;if(!e.current)return;if(l.current)return;const t=e.current,n=a.pages.indexOf(a.activePage)*r;Math.abs(n-t.scrollTop)>.
|
|
3262
|
+
"use strict";var e=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.Workspace=void 0;const t=e(require("react")),r=require("mobx-react-lite"),a=e(require("./page")),n=require("./rules"),o=require("./hotkeys"),l=require("../utils/l10n"),s=(e,t,r)=>Math.max(t,Math.min(r,e)),i="Polotno warning: <Workspace /> component can not automatically detect its size.\nWidth or height of parent elements is equal 0.\nPlease make sure it has non-zero size. You may need to adjust it with your styles. <Workspace /> will automatically fit into parent container.\nFor simpler debugging here is the log of the parent element:",c=(e,r,a,n,o,l)=>{const s=t.default.useRef({width:r,height:a}),i=t.default.useRef({top:0,left:0}),c=t.default.useRef(!1),u=t.default.useRef(o.pages.length);c.current=u.current!==o.pages.length,u.current=o.pages.length,t.default.useEffect(()=>{const t=e.current,r=e=>{i.current={top:t.scrollTop,left:t.scrollLeft}};return t.addEventListener("scroll",r),()=>{t.removeEventListener("scroll",r)}},[]),t.default.useLayoutEffect(()=>{if(!e.current)return;if(c.current)return;const t=e.current,n=(i.current.left+t.offsetWidth/2)/s.current.width,o=(i.current.top+t.offsetHeight/2)/s.current.height;l.current=!0,t.scrollLeft=n*r-t.offsetWidth/2,t.scrollTop=o*a-t.offsetHeight/2,s.current={width:r,height:a}},[n,r,a])},u=(e,r,a,n,o)=>{const l=t.default.useRef(!1),s=t.default.useRef(null);t.default.useEffect(()=>{const t=e.current,r=()=>{o.current};return t.addEventListener("scroll",r),()=>{t.removeEventListener("scroll",r)}},[]);const i=a.pages.indexOf(a.activePage);return t.default.useLayoutEffect(()=>{if(!a.activePage)return;if(!e.current)return;if(l.current)return;const t=e.current,n=a.pages.indexOf(a.activePage)*r;Math.abs(n-t.scrollTop)>.5*r&&(o.current=!0,t.scrollTop=n)},[a.activePage,i]),{handleScroll:e=>{if(o.current)return void(o.current=!1);l.current=!0,clearTimeout(s.current),s.current=setTimeout(()=>{l.current=!1},300);const t=e.currentTarget.childNodes[0].offsetHeight,r=e.currentTarget.scrollTop,i=Math.floor((r+n.height/3)/t),c=a.pages[i];c&&c.select()}}},d=({store:e})=>t.default.createElement("div",{style:{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",textAlign:"center"}},t.default.createElement("p",null,(0,l.t)("workspace.noPages")),t.default.createElement("button",{onClick:()=>{e.addPage()}},(0,l.t)("workspace.addPage")));exports.Workspace=(0,r.observer)(({store:e,pageControlsEnabled:r,backgroundColor:l,pageBorderColor:s,activePageBorderColor:h,bleedColor:f,components:g,onKeyDown:p})=>{const[m,v]=t.default.useState({width:100,height:100}),w=t.default.useRef(m),b=t.default.useRef(null),x=t.default.useRef(null),E=e.bleedVisible?Math.max(0,...e.pages.map(e=>e.bleed)):0,y=Math.max(...e.pages.map(e=>e.computedWidth)),k=Math.max(...e.pages.map(e=>e.computedHeight)),M=y+2*E,P=k+2*E,C=()=>{if(null===b.current)return;const t=b.current.getBoundingClientRect();0!==t.width&&0!==t.height||(console.warn(i),console.log(b.current));const r=x.current.clientWidth||t.width,a={width:r,height:t.height};(w.current.width!==a.width||w.current.height!==a.height)&&(v(a),w.current=a);const n=(r-40)/M,o=(t.height-110)/P,l=Math.max(Math.min(n,o),.01);e.scaleToFit!==l&&(e.setScale(l),e._setScaleToFit(l))};t.default.useEffect(C,[M,P]),t.default.useEffect(()=>{const e=b.current;if(window.ResizeObserver){const t=new ResizeObserver(C);return t.observe(e),()=>t.unobserve(e)}{const e=setInterval(C,100);return()=>clearInterval(e)}},[M,P]);const R=Math.max(20,(m.width-M*e.scale)/2),T=P*e.scale*e.pages.length,L=Math.max(55,(m.height-T)/e.pages.length/2);t.default.useEffect(()=>{const t=t=>{(p||o.handleHotkey)(t,e)};return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[]),t.default.useEffect(()=>{var t;const r=t=>{if(t.ctrlKey||t.metaKey){t.preventDefault();const o=Math.max(2,e.scaleToFit),l=Math.min(.5,e.scaleToFit),s=(r=t.deltaY<0?1.05*e.scale:e.scale/1.05,a=l,n=o,Math.max(a,Math.min(n,r)));e.setScale(s)}else var r,a,n};return null===(t=x.current)||void 0===t||t.addEventListener("wheel",r),()=>{var e;return null===(e=x.current)||void 0===e?void 0:e.removeEventListener("wheel",r)}},[]);const W=t.default.useRef(!1);c(x,M*e.scale+2*R,P*e.scale+2*L,e.scale,e,W);const{handleScroll:_}=u(x,P*e.scale+2*L,e,m,W),q=m.width>=M*e.scale+2*R,S=l||"rgba(232, 232, 232, 0.9)",B=e.pages.indexOf(e.activePage),O=(null==g?void 0:g.NoPages)||d;return t.default.createElement("div",{ref:b,style:{width:"100%",height:"100%",position:"relative",outline:"none",flex:1,backgroundColor:S},tabIndex:0,className:"polotno-workspace-container"},t.default.createElement("div",{ref:x,onScroll:_,style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",overflow:"auto",overflowX:q?"hidden":"auto"},className:"polotno-workspace-inner"},e.pages.map((n,o)=>Math.abs(o-B)<=1||n._exporting?t.default.createElement(a.default,{key:n.id,page:n,xPadding:R,yPadding:L,width:M*e.scale+2*R,height:P*e.scale+2*L,store:e,pageControlsEnabled:r,backColor:S,pageBorderColor:s||"lightgrey",activePageBorderColor:h||"rgb(0, 161, 255)",bleedColor:f||"rgba(255, 0, 0, 0.1)",components:g}):t.default.createElement("div",{key:n.id,style:{width:M*e.scale+2*R+"px",height:P*e.scale+2*L+"px",backgroundColor:S,paddingLeft:R+"px",paddingRight:R+"px",paddingTop:L+"px",paddingBottom:L+"px"}},t.default.createElement("div",{style:{width:" 100%",height:"100%",backgroundColor:"white"}}))),e.rulesVisible&&t.default.createElement(n.TopRules,{store:e,xPadding:R,yPadding:L,width:M*e.scale+2*R,height:P*e.scale+2*L}),0===e.pages.length&&t.default.createElement(O,{store:e})))}),exports.default=exports.Workspace;
|
|
3261
3263
|
},{"react":"HdMw","mobx-react-lite":"ZfSi","./page":"Co9b","./rules":"s1Tm","./hotkeys":"NI5R","../utils/l10n":"FlVj"}],"pk4v":[function(require,module,exports) {
|
|
3262
3264
|
var process = require("process");
|
|
3263
3265
|
var e=require("process");Object.defineProperty(exports,"__esModule",{value:!0}),exports.addDisposer=G,exports.addMiddleware=Ve,exports.applyAction=Pe,exports.applyPatch=m,exports.applySnapshot=_,exports.cast=q,exports.castFlowReturn=Zt,exports.castToReferenceSnapshot=Q,exports.castToSnapshot=K,exports.clone=L,exports.createActionTrackingMiddleware=de,exports.createActionTrackingMiddleware2=ve,exports.decorate=Ne,exports.destroy=$,exports.detach=U,exports.escapeJsonPath=rr,exports.flow=Jt,exports.getChildType=y,exports.getEnv=Y,exports.getIdentifier=R,exports.getLivelinessChecking=o,exports.getMembers=B,exports.getNodeId=X,exports.getParent=I,exports.getParentOfType=T,exports.getPath=E,exports.getPathParts=V,exports.getPropertyMembers=Z,exports.getRelativePath=H,exports.getRoot=C,exports.getRunningActionContext=Re,exports.getSnapshot=S,exports.getType=d,exports.hasParent=A,exports.hasParentOfType=x,exports.isActionContextChildOf=Fe,exports.isActionContextThisOrChildOf=Me,exports.isAlive=W,exports.isArrayType=Or,exports.isFrozenType=dn,exports.isIdentifierType=Cn,exports.isLateType=pn,exports.isLiteralType=Gr,exports.isMapType=yr,exports.isModelType=Er,exports.isOptionalType=nn,exports.isPrimitiveType=Ur,exports.isProtected=j,exports.isReferenceType=jn,exports.isRefinementType=Zr,exports.isRoot=N,exports.isStateTreeNode=nt,exports.isType=fe,exports.isUnionType=Qr,exports.isValidReference=F,exports.joinJsonPath=ir,exports.onAction=_e,exports.onPatch=v,exports.onSnapshot=g,exports.process=ht,exports.protect=P,exports.recordActions=je,exports.recordPatches=w,exports.resolveIdentifier=k,exports.resolvePath=D,exports.setLivelinessChecking=i,exports.setLivelynessChecking=a,exports.splitJsonPath=or,exports.toGenerator=qt,exports.toGeneratorFunction=Bt,exports.tryReference=z,exports.tryResolve=M,exports.typecheck=Be,exports.unescapeJsonPath=nr,exports.unprotect=O,exports.walk=J,exports.types=void 0;var t,r=require("mobx"),n="warn";function i(e){n=e}function o(){return n}function a(e){i(e)}!function(e){e.afterCreate="afterCreate",e.afterAttach="afterAttach",e.afterCreationFinalization="afterCreationFinalization",e.beforeDetach="beforeDetach",e.beforeDestroy="beforeDestroy"}(t||(t={}));var u=function(e,t){return(u=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])})(e,t)};function l(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function r(){this.constructor=e}u(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}var s=function(){return(s=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var i in t=arguments[r])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e}).apply(this,arguments)};function c(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(n=Object.getOwnPropertySymbols(e);i<n.length;i++)t.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(e,n[i])&&(r[n[i]]=e[n[i]])}return r}function p(e,t){var r,n,i,o,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function u(o){return function(u){return function(o){if(r)throw new TypeError("Generator is already executing.");for(;a;)try{if(r=1,n&&(i=2&o[0]?n.return:o[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,o[1])).done)return i;switch(n=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return a.label++,{value:o[1],done:!1};case 5:a.label++,n=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!(i=(i=a.trys).length>0&&i[i.length-1])&&(6===o[0]||2===o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){a.label=o[1];break}if(6===o[0]&&a.label<i[1]){a.label=i[1],i=o;break}if(i&&a.label<i[2]){a.label=i[2],a.ops.push(o);break}i[2]&&a.ops.pop(),a.trys.pop();continue}o=t.call(e,a)}catch(u){o=[6,u],n=0}finally{r=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,u])}}}function f(e){var t="function"==typeof Symbol&&Symbol.iterator,r=t&&e[t],n=0;if(r)return r.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function b(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var n,i,o=r.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(n=o.next()).done;)a.push(n.value)}catch(u){i={error:u}}finally{try{n&&!n.done&&(r=o.return)&&r.call(o)}finally{if(i)throw i.error}}return a}function h(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(b(arguments[t]));return e}function d(e){return it(e,1),ot(e).type}function y(e,t){return it(e,1),ot(e).getChildType(t)}function v(e,t){return it(e,1),$t(t,2),ot(e).onPatch(t)}function g(e,t){return it(e,1),$t(t,2),ot(e).onSnapshot(t)}function m(e,t){it(e,1),Ut(t,function(e){return"object"==typeof e},"object or array",2),ot(e).applyPatches(jt(t))}function w(e,t){it(e,1);var r,n={patches:[],reversedInversePatches:[]},i={},o={get recording(){return!!r},get patches(){return i.patches||(i.patches=n.patches.slice()),i.patches},get reversedInversePatches(){return i.reversedInversePatches||(i.reversedInversePatches=n.reversedInversePatches.slice()),i.reversedInversePatches},get inversePatches(){return i.inversePatches||(i.inversePatches=n.reversedInversePatches.slice().reverse()),i.inversePatches},stop:function(){r&&(r(),r=void 0)},resume:function(){r||(r=v(e,function(e,r){t&&!t(e,r,Re())||(n.patches.push(e),n.reversedInversePatches.unshift(r),i.patches=void 0,i.inversePatches=void 0,i.reversedInversePatches=void 0)}))},replay:function(t){m(t||e,n.patches)},undo:function(t){m(t||e,n.reversedInversePatches)}};return o.resume(),o}function P(e){it(e,1);var t=ot(e);if(!t.isRoot)throw mt("`protect` can only be invoked on root nodes");t.isProtectionEnabled=!0}function O(e){it(e,1);var t=ot(e);if(!t.isRoot)throw mt("`unprotect` can only be invoked on root nodes");t.isProtectionEnabled=!1}function j(e){return ot(e).isProtected}function _(e,t){return it(e,1),ot(e).applySnapshot(t)}function S(e,t){void 0===t&&(t=!0),it(e,1);var r=ot(e);return t?r.snapshot:xt(r.type.getSnapshot(r,!1))}function A(e,t){void 0===t&&(t=1),it(e,1),Wt(t,2,0);for(var r=ot(e).parent;r;){if(0==--t)return!0;r=r.parent}return!1}function I(e,t){void 0===t&&(t=1),it(e,1),Wt(t,2,0);for(var r=t,n=ot(e).parent;n;){if(0==--r)return n.storedValue;n=n.parent}throw mt("Failed to find the parent of "+ot(e)+" at depth "+t)}function x(e,t){it(e,1),be(t,2);for(var r=ot(e).parent;r;){if(t.is(r.storedValue))return!0;r=r.parent}return!1}function T(e,t){it(e,1),be(t,2);for(var r=ot(e).parent;r;){if(t.is(r.storedValue))return r.storedValue;r=r.parent}throw mt("Failed to find the parent of "+ot(e)+" of a given type")}function C(e){return it(e,1),ot(e).root.storedValue}function E(e){return it(e,1),ot(e).path}function V(e){return it(e,1),or(ot(e).path)}function N(e){return it(e,1),ot(e).isRoot}function D(e,t){it(e,1),Gt(t,2);var r=ct(ot(e),t);return r?r.value:void 0}function k(e,t,r){be(e,1),it(t,2),Nn(r,3);var n=ot(t).root.identifierCache.resolve(e,En(r));return null==n?void 0:n.value}function R(e){return it(e,1),ot(e).identifier}function z(e,t){void 0===t&&(t=!0);try{var r=e();if(null==r)return;if(nt(r))return t?W(r)?r:void 0:r;throw mt("The reference to be checked is not one of node, null or undefined")}catch(n){if(n instanceof gn)return;throw n}}function F(e,t){void 0===t&&(t=!0);try{var r=e();if(null==r)return!1;if(nt(r))return!t||W(r);throw mt("The reference to be checked is not one of node, null or undefined")}catch(n){if(n instanceof gn)return!1;throw n}}function M(e,t){it(e,1),Gt(t,2);var r=ct(ot(e),t,!1);if(void 0!==r)try{return r.value}catch(n){return}}function H(e,t){return it(e,1),it(t,2),st(ot(e),ot(t))}function L(e,t){void 0===t&&(t=!0),it(e,1);var r=ot(e);return r.type.create(r.snapshot,!0===t?r.root.environment:!1===t?void 0:t)}function U(e){return it(e,1),ot(e).detach(),e}function $(e){it(e,1);var t=ot(e);t.isRoot?t.die():t.parent.removeChild(t.subpath)}function W(e){return it(e,1),ot(e).observableIsAlive}function G(e,t){return it(e,1),$t(t,2),ot(e).addDisposer(t),t}function Y(e){it(e,1);var t=ot(e).root.environment;return t||vt}function J(e,t){it(e,1),$t(t,2);var r=ot(e);r.getChildren().forEach(function(e){nt(e.storedValue)&&J(e.storedValue,t)}),t(r.storedValue)}function Z(e){var t;return Ut(t=nt(e)?d(e):e,function(e){return Er(e)},"model type or model instance",1),{name:t.name,properties:s({},t.properties)}}function B(e){var t=ot(e).type,n=s(s({},Z(t)),{actions:[],volatile:[],views:[]});return Object.getOwnPropertyNames(e).forEach(function(t){if(!(t in n.properties)){var i=Object.getOwnPropertyDescriptor(e,t);i.get?(0,r.isComputedProp)(e,t)?n.views.push(t):n.volatile.push(t):!0===i.value._isMSTAction?n.actions.push(t):(0,r.isObservableProp)(e,t)?n.volatile.push(t):n.views.push(t)}}),n}function q(e){return e}function K(e){return e}function Q(e){return e}function X(e){return it(e,1),ot(e).nodeId}var ee=function(){function e(e,t,r,n){Object.defineProperty(this,"type",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"environment",{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(this,"_escapedSubpath",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_subpath",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_subpathUponDeath",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_pathUponDeath",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"storedValue",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"aliveAtom",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_state",{enumerable:!0,configurable:!0,writable:!0,value:Ke.INITIALIZING}),Object.defineProperty(this,"_hookSubscribers",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_parent",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"pathAtom",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.environment=n,this.baseSetParent(t,r)}return Object.defineProperty(e.prototype,"subpath",{get:function(){return this._subpath},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"subpathUponDeath",{get:function(){return this._subpathUponDeath},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"pathUponDeath",{get:function(){return this._pathUponDeath},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"value",{get:function(){return this.type.getValue(this)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"state",{get:function(){return this._state},set:function(e){var t=this.isAlive;this._state=e;var r=this.isAlive;this.aliveAtom&&t!==r&&this.aliveAtom.reportChanged()},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"fireInternalHook",{enumerable:!1,configurable:!0,writable:!0,value:function(e){this._hookSubscribers&&this._hookSubscribers.emit(e,this,e)}}),Object.defineProperty(e.prototype,"registerHook",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){return this._hookSubscribers||(this._hookSubscribers=new kt),this._hookSubscribers.register(e,t)}}),Object.defineProperty(e.prototype,"parent",{get:function(){return this._parent},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"getReconciliationType",{enumerable:!1,configurable:!0,writable:!0,value:function(){return this.type}}),Object.defineProperty(e.prototype,"baseSetParent",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){this._parent=e,this._subpath=t,this._escapedSubpath=void 0,this.pathAtom&&this.pathAtom.reportChanged()}}),Object.defineProperty(e.prototype,"path",{get:function(){return this.getEscapedPath(!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"getEscapedPath",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return e&&(this.pathAtom||(this.pathAtom=(0,r.createAtom)("path")),this.pathAtom.reportObserved()),this.parent?(void 0===this._escapedSubpath&&(this._escapedSubpath=this._subpath?rr(this._subpath):""),this.parent.getEscapedPath(e)+"/"+this._escapedSubpath):""}}),Object.defineProperty(e.prototype,"isRoot",{get:function(){return null===this.parent},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"isAlive",{get:function(){return this.state!==Ke.DEAD},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"isDetaching",{get:function(){return this.state===Ke.DETACHING},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"observableIsAlive",{get:function(){return this.aliveAtom||(this.aliveAtom=(0,r.createAtom)("alive")),this.aliveAtom.reportObserved(),this.isAlive},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"baseFinalizeCreation",{enumerable:!1,configurable:!0,writable:!0,value:function(e){if(Lt()&&!this.isAlive)throw fail("assertion failed: cannot finalize the creation of a node that is already dead");if(this.state===Ke.CREATED){if(this.parent){if(this.parent.state!==Ke.FINALIZED)return;this.fireHook(t.afterAttach)}this.state=Ke.FINALIZED,e&&e()}}}),Object.defineProperty(e.prototype,"baseFinalizeDeath",{enumerable:!1,configurable:!0,writable:!0,value:function(){this._hookSubscribers&&this._hookSubscribers.clearAll(),this._subpathUponDeath=this._subpath,this._pathUponDeath=this.getEscapedPath(!1),this.baseSetParent(null,""),this.state=Ke.DEAD}}),Object.defineProperty(e.prototype,"baseAboutToDie",{enumerable:!1,configurable:!0,writable:!0,value:function(){this.fireHook(t.beforeDestroy)}}),e}(),te=function(e){function t(t,r,n,i,o){var a=e.call(this,t,r,n,i)||this;try{a.storedValue=t.createNewInstance(o)}catch(u){throw a.state=Ke.DEAD,u}return a.state=Ke.CREATED,a.finalizeCreation(),a}return l(t,e),Object.defineProperty(t.prototype,"root",{get:function(){if(!this.parent)throw mt("This scalar node is not part of a tree");return this.parent.root},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"setParent",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var r=this.parent!==e,n=this.subpath!==t;if(r||n){if(Lt()){if(!t)throw mt("assertion failed: subpath expected");if(!e)throw mt("assertion failed: parent expected");if(r)throw mt("assertion failed: scalar nodes cannot change their parent")}this.environment=void 0,this.baseSetParent(this.parent,t)}}}),Object.defineProperty(t.prototype,"snapshot",{get:function(){return xt(this.getSnapshot())},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"getSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(){return this.type.getSnapshot(this)}}),Object.defineProperty(t.prototype,"toString",{enumerable:!1,configurable:!0,writable:!0,value:function(){var e=(this.isAlive?this.path:this.pathUponDeath)||"<root>";return this.type.name+"@"+e+(this.isAlive?"":" [dead]")}}),Object.defineProperty(t.prototype,"die",{enumerable:!1,configurable:!0,writable:!0,value:function(){this.isAlive&&this.state!==Ke.DETACHING&&(this.aboutToDie(),this.finalizeDeath())}}),Object.defineProperty(t.prototype,"finalizeCreation",{enumerable:!1,configurable:!0,writable:!0,value:function(){this.baseFinalizeCreation()}}),Object.defineProperty(t.prototype,"aboutToDie",{enumerable:!1,configurable:!0,writable:!0,value:function(){this.baseAboutToDie()}}),Object.defineProperty(t.prototype,"finalizeDeath",{enumerable:!1,configurable:!0,writable:!0,value:function(){this.baseFinalizeDeath()}}),Object.defineProperty(t.prototype,"fireHook",{enumerable:!1,configurable:!0,writable:!0,value:function(e){this.fireInternalHook(e)}}),t}(ee);te.prototype.die=(0,r.action)(te.prototype.die);var re,ne,ie=1,oe={onError:function(e){throw e}},ae=function(e){function n(t,n,i,o,a){var u=e.call(this,t,n,i,o)||this;if(Object.defineProperty(u,"nodeId",{enumerable:!0,configurable:!0,writable:!0,value:++ie}),Object.defineProperty(u,"identifierAttribute",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(u,"identifier",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(u,"unnormalizedIdentifier",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(u,"identifierCache",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(u,"isProtectionEnabled",{enumerable:!0,configurable:!0,writable:!0,value:!0}),Object.defineProperty(u,"middlewares",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(u,"_applyPatches",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(u,"_applySnapshot",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(u,"_autoUnbox",{enumerable:!0,configurable:!0,writable:!0,value:!0}),Object.defineProperty(u,"_isRunningAction",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(u,"_hasSnapshotReaction",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(u,"_observableInstanceState",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(u,"_childNodes",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(u,"_initialSnapshot",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(u,"_cachedInitialSnapshot",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(u,"_cachedInitialSnapshotCreated",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(u,"_snapshotComputed",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(u,"_snapshotUponDeath",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(u,"_internalEvents",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),u._snapshotComputed=(0,r.computed)(function(){return xt(u.getSnapshot())}),u.unbox=u.unbox.bind(u),u._initialSnapshot=xt(a),u.identifierAttribute=t.identifierAttribute,n||(u.identifierCache=new Xe),u._childNodes=t.initializeChildNodes(u,u._initialSnapshot),u.identifier=null,u.unnormalizedIdentifier=null,u.identifierAttribute&&u._initialSnapshot){var l=u._initialSnapshot[u.identifierAttribute];if(void 0===l){var s=u._childNodes[u.identifierAttribute];s&&(l=s.value)}if("string"!=typeof l&&"number"!=typeof l)throw mt("Instance identifier '"+u.identifierAttribute+"' for type '"+u.type.name+"' must be a string or a number");u.identifier=En(l),u.unnormalizedIdentifier=l}return n?n.root.identifierCache.addNodeToCache(u):u.identifierCache.addNodeToCache(u),u}return l(n,e),Object.defineProperty(n.prototype,"applyPatches",{enumerable:!1,configurable:!0,writable:!0,value:function(e){this.createObservableInstanceIfNeeded(),this._applyPatches(e)}}),Object.defineProperty(n.prototype,"applySnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(e){this.createObservableInstanceIfNeeded(),this._applySnapshot(e)}}),Object.defineProperty(n.prototype,"createObservableInstanceIfNeeded",{enumerable:!1,configurable:!0,writable:!0,value:function(){0===this._observableInstanceState&&this.createObservableInstance()}}),Object.defineProperty(n.prototype,"createObservableInstance",{enumerable:!1,configurable:!0,writable:!0,value:function(){var e,r;if(Lt()&&this.state!==Ke.INITIALIZING)throw mt("assertion failed: the creation of the observable instance must be done on the initializing phase");this._observableInstanceState=1;for(var n=[],i=this.parent;i&&0===i._observableInstanceState;)n.unshift(i),i=i.parent;try{for(var o=f(n),a=o.next();!a.done;a=o.next()){a.value.createObservableInstanceIfNeeded()}}catch(l){e={error:l}}finally{try{a&&!a.done&&(r=o.return)&&r.call(o)}finally{if(e)throw e.error}}var u=this.type;try{this.storedValue=u.createNewInstance(this._childNodes),this.preboot(),this._isRunningAction=!0,u.finalizeNewInstance(this,this.storedValue)}catch(s){throw this.state=Ke.DEAD,s}finally{this._isRunningAction=!1}this._observableInstanceState=2,this._snapshotComputed.trackAndCompute(),this.isRoot&&this._addSnapshotReaction(),this._childNodes=vt,this.state=Ke.CREATED,this.fireHook(t.afterCreate),this.finalizeCreation()}}),Object.defineProperty(n.prototype,"root",{get:function(){var e=this.parent;return e?e.root:this},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"clearParent",{enumerable:!1,configurable:!0,writable:!0,value:function(){if(this.parent){this.fireHook(t.beforeDetach);var e=this.state;this.state=Ke.DETACHING;var r=this.root,n=r.environment,i=r.identifierCache.splitCache(this);try{this.parent.removeChild(this.subpath),this.baseSetParent(null,""),this.environment=n,this.identifierCache=i}finally{this.state=e}}}}),Object.defineProperty(n.prototype,"setParent",{enumerable:!1,configurable:!0,writable:!0,value:function(e,r){var n=e!==this.parent,i=r!==this.subpath;if(n||i){if(Lt()){if(!r)throw mt("assertion failed: subpath expected");if(!e)throw mt("assertion failed: new parent expected");if(this.parent&&n)throw mt("A node cannot exists twice in the state tree. Failed to add "+this+" to path '"+e.path+"/"+r+"'.");if(!this.parent&&e.root===this)throw mt("A state tree is not allowed to contain itself. Cannot assign "+this+" to path '"+e.path+"/"+r+"'");if(!this.parent&&this.environment&&this.environment!==e.root.environment)throw mt("A state tree cannot be made part of another state tree as long as their environments are different.")}n?(this.environment=void 0,e.root.identifierCache.mergeCache(this),this.baseSetParent(e,r),this.fireHook(t.afterAttach)):i&&this.baseSetParent(this.parent,r)}}}),Object.defineProperty(n.prototype,"fireHook",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this;this.fireInternalHook(e);var n=this.storedValue&&"object"==typeof this.storedValue&&this.storedValue[e];"function"==typeof n&&(r._allowStateChangesInsideComputed?(0,r._allowStateChangesInsideComputed)(function(){n.apply(t.storedValue)}):n.apply(this.storedValue))}}),Object.defineProperty(n.prototype,"snapshot",{get:function(){return this._snapshotComputed.get()},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"getSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(){return this.isAlive?2===this._observableInstanceState?this._getActualSnapshot():this._getCachedInitialSnapshot():this._snapshotUponDeath}}),Object.defineProperty(n.prototype,"_getActualSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(){return this.type.getSnapshot(this)}}),Object.defineProperty(n.prototype,"_getCachedInitialSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(){if(!this._cachedInitialSnapshotCreated){var e=this.type,t=this._childNodes,r=this._initialSnapshot;this._cachedInitialSnapshot=e.processInitialSnapshot(t,r),this._cachedInitialSnapshotCreated=!0}return this._cachedInitialSnapshot}}),Object.defineProperty(n.prototype,"isRunningAction",{enumerable:!1,configurable:!0,writable:!0,value:function(){return!!this._isRunningAction||!this.isRoot&&this.parent.isRunningAction()}}),Object.defineProperty(n.prototype,"assertAlive",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=o();if(!this.isAlive&&"ignore"!==t){var r=this._getAssertAliveError(e);switch(t){case"error":throw mt(r);case"warn":Mt(r)}}}}),Object.defineProperty(n.prototype,"_getAssertAliveError",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this.getEscapedPath(!1)||this.pathUponDeath||"",r=e.subpath&&rr(e.subpath)||"",n=e.actionContext||Ie();n&&"action"!==n.type&&n.parentActionEvent&&(n=n.parentActionEvent);var i="";n&&null!=n.name&&(i=(n&&n.context&&E(n.context)||t)+"."+n.name+"()");return"You are trying to read or write to an object that is no longer part of a state tree. (Object type: '"+this.type.name+"', Path upon death: '"+t+"', Subpath: '"+r+"', Action: '"+i+"'). Either detach nodes first, or don't use objects after removing / replacing them in the tree."}}),Object.defineProperty(n.prototype,"getChildNode",{enumerable:!1,configurable:!0,writable:!0,value:function(e){this.assertAlive({subpath:e}),this._autoUnbox=!1;try{return 2===this._observableInstanceState?this.type.getChildNode(this,e):this._childNodes[e]}finally{this._autoUnbox=!0}}}),Object.defineProperty(n.prototype,"getChildren",{enumerable:!1,configurable:!0,writable:!0,value:function(){this.assertAlive(vt),this._autoUnbox=!1;try{return 2===this._observableInstanceState?this.type.getChildren(this):ft(this._childNodes)}finally{this._autoUnbox=!0}}}),Object.defineProperty(n.prototype,"getChildType",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return this.type.getChildType(e)}}),Object.defineProperty(n.prototype,"isProtected",{get:function(){return this.root.isProtectionEnabled},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"assertWritable",{enumerable:!1,configurable:!0,writable:!0,value:function(e){if(this.assertAlive(e),!this.isRunningAction()&&this.isProtected)throw mt("Cannot modify '"+this+"', the object is protected and can only be modified by using an action.")}}),Object.defineProperty(n.prototype,"removeChild",{enumerable:!1,configurable:!0,writable:!0,value:function(e){this.type.removeChild(this,e)}}),Object.defineProperty(n.prototype,"unbox",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return e?(this.assertAlive({subpath:e.subpath||e.subpathUponDeath}),this._autoUnbox?e.value:e):e}}),Object.defineProperty(n.prototype,"toString",{enumerable:!1,configurable:!0,writable:!0,value:function(){var e=(this.isAlive?this.path:this.pathUponDeath)||"<root>",t=this.identifier?"(id: "+this.identifier+")":"";return this.type.name+"@"+e+t+(this.isAlive?"":" [dead]")}}),Object.defineProperty(n.prototype,"finalizeCreation",{enumerable:!1,configurable:!0,writable:!0,value:function(){var e=this;this.baseFinalizeCreation(function(){var r,n;try{for(var i=f(e.getChildren()),o=i.next();!o.done;o=i.next()){o.value.finalizeCreation()}}catch(a){r={error:a}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(r)throw r.error}}e.fireInternalHook(t.afterCreationFinalization)})}}),Object.defineProperty(n.prototype,"detach",{enumerable:!1,configurable:!0,writable:!0,value:function(){if(!this.isAlive)throw mt("Error while detaching, node is not alive.");this.clearParent()}}),Object.defineProperty(n.prototype,"preboot",{enumerable:!1,configurable:!0,writable:!0,value:function(){var e=this;this._applyPatches=Ee(this.storedValue,"@APPLY_PATCHES",function(t){t.forEach(function(t){if(t.path){var r=or(t.path);pt(e,r.slice(0,-1)).applyPatchLocally(r[r.length-1],t)}else e.type.applySnapshot(e,t.value)})}),this._applySnapshot=Ee(this.storedValue,"@APPLY_SNAPSHOT",function(t){if(t!==e.snapshot)return e.type.applySnapshot(e,t)}),Vt(this.storedValue,"$treenode",this),Vt(this.storedValue,"toJSON",ut)}}),Object.defineProperty(n.prototype,"die",{enumerable:!1,configurable:!0,writable:!0,value:function(){this.isAlive&&this.state!==Ke.DETACHING&&(this.aboutToDie(),this.finalizeDeath())}}),Object.defineProperty(n.prototype,"aboutToDie",{enumerable:!1,configurable:!0,writable:!0,value:function(){0!==this._observableInstanceState&&(this.getChildren().forEach(function(e){e.aboutToDie()}),this.baseAboutToDie(),this._internalEventsEmit("dispose"),this._internalEventsClear("dispose"))}}),Object.defineProperty(n.prototype,"finalizeDeath",{enumerable:!1,configurable:!0,writable:!0,value:function(){this.getChildren().forEach(function(e){e.finalizeDeath()}),this.root.identifierCache.notifyDied(this);var e=this.snapshot;this._snapshotUponDeath=e,this._internalEventsClearAll(),this.baseFinalizeDeath()}}),Object.defineProperty(n.prototype,"onSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return this._addSnapshotReaction(),this._internalEventsRegister("snapshot",e)}}),Object.defineProperty(n.prototype,"emitSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(e){this._internalEventsEmit("snapshot",e)}}),Object.defineProperty(n.prototype,"onPatch",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return this._internalEventsRegister("patch",e)}}),Object.defineProperty(n.prototype,"emitPatch",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){if(this._internalEventsHasSubscribers("patch")){var r=b(Qt(_t({},e,{path:t.path.substr(this.path.length)+"/"+e.path})),2),n=r[0],i=r[1];this._internalEventsEmit("patch",n,i)}this.parent&&this.parent.emitPatch(e,t)}}),Object.defineProperty(n.prototype,"hasDisposer",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return this._internalEventsHas("dispose",e)}}),Object.defineProperty(n.prototype,"addDisposer",{enumerable:!1,configurable:!0,writable:!0,value:function(e){if(this.hasDisposer(e))throw mt("cannot add a disposer when it is already registered for execution");this._internalEventsRegister("dispose",e,!0)}}),Object.defineProperty(n.prototype,"removeDisposer",{enumerable:!1,configurable:!0,writable:!0,value:function(e){if(!this._internalEventsHas("dispose",e))throw mt("cannot remove a disposer which was never registered for execution");this._internalEventsUnregister("dispose",e)}}),Object.defineProperty(n.prototype,"removeMiddleware",{enumerable:!1,configurable:!0,writable:!0,value:function(e){if(this.middlewares){var t=this.middlewares.indexOf(e);t>=0&&this.middlewares.splice(t,1)}}}),Object.defineProperty(n.prototype,"addMiddleWare",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var r=this;void 0===t&&(t=!0);var n={handler:e,includeHooks:t};return this.middlewares?this.middlewares.push(n):this.middlewares=[n],function(){r.removeMiddleware(n)}}}),Object.defineProperty(n.prototype,"applyPatchLocally",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){this.assertWritable({subpath:e}),this.createObservableInstanceIfNeeded(),this.type.applyPatchLocally(this,e,t)}}),Object.defineProperty(n.prototype,"_addSnapshotReaction",{enumerable:!1,configurable:!0,writable:!0,value:function(){var e=this;if(!this._hasSnapshotReaction){var t=(0,r.reaction)(function(){return e.snapshot},function(t){return e.emitSnapshot(t)},oe);this.addDisposer(t),this._hasSnapshotReaction=!0}}}),Object.defineProperty(n.prototype,"_internalEventsHasSubscribers",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return!!this._internalEvents&&this._internalEvents.hasSubscribers(e)}}),Object.defineProperty(n.prototype,"_internalEventsRegister",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,r){return void 0===r&&(r=!1),this._internalEvents||(this._internalEvents=new kt),this._internalEvents.register(e,t,r)}}),Object.defineProperty(n.prototype,"_internalEventsHas",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){return!!this._internalEvents&&this._internalEvents.has(e,t)}}),Object.defineProperty(n.prototype,"_internalEventsUnregister",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){this._internalEvents&&this._internalEvents.unregister(e,t)}}),Object.defineProperty(n.prototype,"_internalEventsEmit",{enumerable:!1,configurable:!0,writable:!0,value:function(e){for(var t,r=[],n=1;n<arguments.length;n++)r[n-1]=arguments[n];this._internalEvents&&(t=this._internalEvents).emit.apply(t,h([e],r))}}),Object.defineProperty(n.prototype,"_internalEventsClear",{enumerable:!1,configurable:!0,writable:!0,value:function(e){this._internalEvents&&this._internalEvents.clear(e)}}),Object.defineProperty(n.prototype,"_internalEventsClearAll",{enumerable:!1,configurable:!0,writable:!0,value:function(){this._internalEvents&&this._internalEvents.clearAll()}}),n}(ee);ae.prototype.createObservableInstance=(0,r.action)(ae.prototype.createObservableInstance),ae.prototype.detach=(0,r.action)(ae.prototype.detach),ae.prototype.die=(0,r.action)(ae.prototype.die),function(e){e[e.String=1]="String",e[e.Number=2]="Number",e[e.Boolean=4]="Boolean",e[e.Date=8]="Date",e[e.Literal=16]="Literal",e[e.Array=32]="Array",e[e.Map=64]="Map",e[e.Object=128]="Object",e[e.Frozen=256]="Frozen",e[e.Optional=512]="Optional",e[e.Reference=1024]="Reference",e[e.Identifier=2048]="Identifier",e[e.Late=4096]="Late",e[e.Refinement=8192]="Refinement",e[e.Union=16384]="Union",e[e.Null=32768]="Null",e[e.Undefined=65536]="Undefined",e[e.Integer=131072]="Integer",e[e.Custom=262144]="Custom",e[e.SnapshotProcessor=524288]="SnapshotProcessor"}(ne||(ne={}));var ue="cannotDetermine",le=Symbol("$type"),se=function(){function e(e){Object.defineProperty(this,re,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"C",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"S",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"T",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"N",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"isType",{enumerable:!0,configurable:!0,writable:!0,value:!0}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.name=e}return Object.defineProperty(e.prototype,"create",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){return Ze(this,e),this.instantiate(null,"",t,e).value}}),Object.defineProperty(e.prototype,"getSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){throw mt("unimplemented method")}}),Object.defineProperty(e.prototype,"isAssignableFrom",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return e===this}}),Object.defineProperty(e.prototype,"validate",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){if(at(e)){var r=d(e);return this.isAssignableFrom(r)?Ge():Ye(t,e)}return this.isValidSnapshot(e,t)}}),Object.defineProperty(e.prototype,"is",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return 0===this.validate(e,[{path:"",type:this}]).length}}),Object.defineProperty(e.prototype,"Type",{get:function(){throw mt("Factory.Type should not be actually called. It is just a Type signature that can be used at compile time with Typescript, by using `typeof type.Type`")},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"TypeWithoutSTN",{get:function(){throw mt("Factory.TypeWithoutSTN should not be actually called. It is just a Type signature that can be used at compile time with Typescript, by using `typeof type.TypeWithoutSTN`")},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"SnapshotType",{get:function(){throw mt("Factory.SnapshotType should not be actually called. It is just a Type signature that can be used at compile time with Typescript, by using `typeof type.SnapshotType`")},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"CreationType",{get:function(){throw mt("Factory.CreationType should not be actually called. It is just a Type signature that can be used at compile time with Typescript, by using `typeof type.CreationType`")},enumerable:!1,configurable:!0}),e}();re=le,se.prototype.create=(0,r.action)(se.prototype.create);var ce=function(e){function t(t){var r=e.call(this,t)||this;return Object.defineProperty(r,"identifierAttribute",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),r}return l(t,e),Object.defineProperty(t.prototype,"create",{enumerable:!1,configurable:!0,writable:!0,value:function(t,r){return void 0===t&&(t=this.getDefaultSnapshot()),e.prototype.create.call(this,t,r)}}),Object.defineProperty(t.prototype,"getValue",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return e.createObservableInstanceIfNeeded(),e.storedValue}}),Object.defineProperty(t.prototype,"isMatchingSnapshotId",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){return!e.identifierAttribute||e.identifier===En(t[e.identifierAttribute])}}),Object.defineProperty(t.prototype,"tryToReconcileNode",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){return!e.isDetaching&&(e.snapshot===t||(!(!nt(t)||ot(t)!==e)||!(e.type!==this||!At(t)||nt(t)||!this.isMatchingSnapshotId(e,t))&&(e.applySnapshot(t),!0)))}}),Object.defineProperty(t.prototype,"reconcile",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,r,n){if(this.tryToReconcileNode(e,t))return e.setParent(r,n),e;if(e.die(),nt(t)&&this.isAssignableFrom(d(t))){var i=ot(t);return i.setParent(r,n),i}return this.instantiate(r,n,void 0,t)}}),Object.defineProperty(t.prototype,"getSubTypes",{enumerable:!1,configurable:!0,writable:!0,value:function(){return null}}),t}(se);ce.prototype.create=(0,r.action)(ce.prototype.create);var pe=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return l(t,e),Object.defineProperty(t.prototype,"createNewInstance",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return e}}),Object.defineProperty(t.prototype,"getValue",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return e.storedValue}}),Object.defineProperty(t.prototype,"getSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return e.storedValue}}),Object.defineProperty(t.prototype,"reconcile",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,r,n){if(!e.isDetaching&&e.type===this&&e.storedValue===t)return e;var i=this.instantiate(r,n,void 0,t);return e.die(),i}}),Object.defineProperty(t.prototype,"getSubTypes",{enumerable:!1,configurable:!0,writable:!0,value:function(){return null}}),t}(se);function fe(e){return"object"==typeof e&&e&&!0===e.isType}function be(e,t){Ut(e,fe,"mobx-state-tree type",t)}var he=new Map;function de(e){return function(t,r,n){switch(t.type){case"action":if(e.filter&&!0!==e.filter(t))return r(t);var i=e.onStart(t);e.onResume(t,i),he.set(t.id,{call:t,context:i,async:!1});try{var o=r(t);return e.onSuspend(t,i),!1===he.get(t.id).async&&(he.delete(t.id),e.onSuccess(t,i,o)),o}catch(u){throw he.delete(t.id),e.onFail(t,i,u),u}case"flow_spawn":return(a=he.get(t.rootId)).async=!0,r(t);case"flow_resume":case"flow_resume_error":var a=he.get(t.rootId);e.onResume(t,a.context);try{return r(t)}finally{e.onSuspend(t,a.context)}case"flow_throw":a=he.get(t.rootId);return he.delete(t.rootId),e.onFail(t,a.context,t.args[0]),r(t);case"flow_return":a=he.get(t.rootId);return he.delete(t.rootId),e.onSuccess(t,a.context,t.args[0]),r(t)}}}var ye=function(){function e(e,t){Object.defineProperty(this,"hooks",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"call",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"flowsPending",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"running",{enumerable:!0,configurable:!0,writable:!0,value:!0}),e&&e.onStart(t)}return Object.defineProperty(e.prototype,"finish",{enumerable:!1,configurable:!0,writable:!0,value:function(e){this.running&&(this.running=!1,this.hooks&&this.hooks.onFinish(this.call,e))}}),Object.defineProperty(e.prototype,"incFlowsPending",{enumerable:!1,configurable:!0,writable:!0,value:function(){this.flowsPending++}}),Object.defineProperty(e.prototype,"decFlowsPending",{enumerable:!1,configurable:!0,writable:!0,value:function(){this.flowsPending--}}),Object.defineProperty(e.prototype,"hasFlowsPending",{get:function(){return this.flowsPending>0},enumerable:!1,configurable:!0}),e}();function ve(e){var t=new WeakMap;return function(r,n){var i=r.parentActionEvent?t.get(r.parentActionEvent):void 0;if("action"===r.type){var o=s(s({},r),{env:i&&i.call.env,parentCall:i&&i.call}),a=!e.filter||e.filter(o),u=new ye(a?e:void 0,o);t.set(r,u);var l=void 0;try{l=n(r)}catch(p){throw u.finish(p),p}return u.hasFlowsPending||u.finish(),l}if(!i)return n(r);switch(r.type){case"flow_spawn":return i.incFlowsPending(),n(r);case"flow_resume":case"flow_resume_error":return n(r);case"flow_throw":var c=r.args[0];try{return n(r)}finally{i.decFlowsPending(),i.hasFlowsPending||i.finish(c)}case"flow_return":try{return n(r)}finally{i.decFlowsPending(),i.hasFlowsPending||i.finish()}}}}function ge(e,t,r,n){if(n instanceof Date)return{$MST_DATE:n.getTime()};if(It(n))return n;if(nt(n))return we("[MSTNode: "+d(n).name+"]");if("function"==typeof n)return we("[function]");if("object"==typeof n&&!St(n)&&!Ot(n))return we("[object "+(n&&n.constructor&&n.constructor.name||"Complex Object")+"]");try{return JSON.stringify(n),n}catch(i){return we(""+i)}}function me(e,t){return t&&"object"==typeof t&&"$MST_DATE"in t?new Date(t.$MST_DATE):t}function we(e){return{$MST_UNSERIALIZABLE:!0,type:e}}function Pe(e,t){it(e,1),Ut(t,function(e){return"object"==typeof e},"object or array",2),(0,r.runInAction)(function(){jt(t).forEach(function(t){return Oe(e,t)})})}function Oe(e,t){var r=M(e,t.path||"");if(!r)throw mt("Invalid action path: "+(t.path||""));var n=ot(r);if("@APPLY_PATCHES"===t.name)return m.call(null,r,t.args[0]);if("@APPLY_SNAPSHOT"===t.name)return _.call(null,r,t.args[0]);if("function"!=typeof r[t.name])throw mt("Action '"+t.name+"' does not exist in '"+n.path+"'");return r[t.name].apply(r,t.args?t.args.map(function(e){return me(n,e)}):[])}function je(e,t){it(e,1);var r,n=[],i=function(e){(!t||t(e,Re()))&&n.push(e)},o={actions:n,get recording(){return!!r},stop:function(){r&&(r(),r=void 0)},resume:function(){r||(r=_e(e,i))},replay:function(e){Pe(e,n)}};return o.resume(),o}function _e(e,t,r){return void 0===r&&(r=!1),it(e,1),Lt()&&(N(e)||Mt("Warning: Attaching onAction listeners to non root nodes is dangerous: No events will be emitted for actions initiated higher up in the tree."),j(e)||Mt("Warning: Attaching onAction listeners to non protected nodes is dangerous: No events will be emitted for direct modifications without action.")),Ve(e,function(n,i){if("action"===n.type&&n.id===n.rootId){var o=ot(n.context),a={name:n.name,path:st(ot(e),o),args:n.args.map(function(e,t){return ge(o,n.name,t,e)})};if(r){var u=i(n);return t(a),u}return t(a),i(n)}return i(n)})}var Se,Ae=1;function Ie(){return Se}function xe(){return Ae++}function Te(e,t){var r=ot(e.context);"action"===e.type&&r.assertAlive({actionContext:e});var n=r._isRunningAction;r._isRunningAction=!0;var i=Se;Se=e;try{return ke(r,e,t)}finally{Se=i,r._isRunningAction=n}}function Ce(e){if(e)return"action"===e.type?e:e.parentActionEvent}function Ee(e,t,r){var n=function(){var n=xe(),i=Se,o=Ce(i);return Te({type:"action",name:t,id:n,args:Rt(arguments),context:e,tree:C(e),rootId:i?i.rootId:n,parentId:i?i.id:0,allParentIds:i?h(i.allParentIds,[i.id]):[],parentEvent:i,parentActionEvent:o},r)};return n._isMSTAction=!0,n}function Ve(e,t,r){void 0===r&&(r=!0);var n=ot(e);return Lt()&&(n.isProtectionEnabled||Mt("It is recommended to protect the state tree before attaching action middleware, as otherwise it cannot be guaranteed that all changes are passed through middleware. See `protect`")),n.addMiddleWare(t,r)}function Ne(e,t,r){void 0===r&&(r=!0);var n={handler:e,includeHooks:r};return t.$mst_middleware=t.$mst_middleware||[],t.$mst_middleware.push(n),t}var De=function(){function e(e,t){Object.defineProperty(this,"arrayIndex",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"inArrayIndex",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"middlewares",{enumerable:!0,configurable:!0,writable:!0,value:[]}),t.$mst_middleware&&this.middlewares.push(t.$mst_middleware);for(var r=e;r;)r.middlewares&&this.middlewares.push(r.middlewares),r=r.parent}return Object.defineProperty(e.prototype,"isEmpty",{get:function(){return this.middlewares.length<=0},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"getNextMiddleware",{enumerable:!1,configurable:!0,writable:!0,value:function(){var e=this.middlewares[this.arrayIndex];if(e){var t=e[this.inArrayIndex++];return t||(this.arrayIndex++,this.inArrayIndex=0,this.getNextMiddleware())}}}),e}();function ke(e,n,i){var o=new De(e,i);if(o.isEmpty)return(0,r.action)(i).apply(null,n.args);var a=null;return function e(n){var u=o.getNextMiddleware(),l=u&&u.handler;if(!l)return(0,r.action)(i).apply(null,n.args);if(!u.includeHooks&&t[n.name])return e(n);var s=!1;var c=!1;if(l(n,function(t,r){s=!0,a=e(t),r&&(a=r(a))},function(e){c=!0,a=e}),Lt()){if(!s&&!c){var p=ot(n.tree);throw mt("Neither the next() nor the abort() callback within the middleware "+l.name+' for the action: "'+n.name+'" on the node: '+p.type.name+" was invoked.")}if(s&&c)throw p=ot(n.tree),mt("The next() and abort() callback within the middleware "+l.name+' for the action: "'+n.name+'" on the node: '+p.type.name+" were invoked.")}return a}(n)}function Re(){for(var e=Ie();e&&"action"!==e.type;)e=e.parentActionEvent;return e}function ze(e,t,r){for(var n="number"==typeof t?t:t.id,i=r?e:e.parentActionEvent;i;){if(i.id===n)return!0;i=i.parentActionEvent}return!1}function Fe(e,t){return ze(e,t,!1)}function Me(e,t){return ze(e,t,!0)}function He(e){try{return JSON.stringify(e)}catch(t){return"<Unserializable: "+t+">"}}function Le(e){return"function"==typeof e?"<function"+(e.name?" "+e.name:"")+">":nt(e)?"<"+e+">":"`"+He(e)+"`"}function Ue(e){return e.length<280?e:e.substring(0,272)+"......"+e.substring(e.length-8)}function $e(e){var t=e.value,r=e.context[e.context.length-1].type,n=e.context.map(function(e){return e.path}).filter(function(e){return e.length>0}).join("/"),i=n.length>0?'at path "/'+n+'" ':"",o=nt(t)?"value of type "+ot(t).type.name+":":It(t)?"value":"snapshot",a=r&&nt(t)&&r.is(ot(t).snapshot);return""+i+o+" "+Le(t)+" is not assignable "+(r?"to type: `"+r.name+"`":"")+(e.message?" ("+e.message+")":"")+(r?Ur(r)||It(t)?".":", expected an instance of `"+r.name+"` or a snapshot like `"+r.describe()+"` instead."+(a?" (Note that a snapshot of the provided value is compatible with the targeted type)":""):".")}function We(e,t,r){return e.concat([{path:t,type:r}])}function Ge(){return yt}function Ye(e,t,r){return[{context:e,value:t,message:r}]}function Je(e){return e.reduce(function(e,t){return e.concat(t)},[])}function Ze(e,t){Ht()&&Be(e,t)}function Be(e,t){var r=e.validate(t,[{path:"",type:e}]);if(r.length>0)throw mt(qe(e,t,r))}function qe(e,t,r){if(0!==r.length)return"Error while converting "+Ue(Le(t))+" to `"+e.name+"`:\n\n "+r.map($e).join("\n ")}var Ke,Qe=0,Xe=function(){function e(){Object.defineProperty(this,"cacheId",{enumerable:!0,configurable:!0,writable:!0,value:Qe++}),Object.defineProperty(this,"cache",{enumerable:!0,configurable:!0,writable:!0,value:r.observable.map()}),Object.defineProperty(this,"lastCacheModificationPerId",{enumerable:!0,configurable:!0,writable:!0,value:r.observable.map()})}return Object.defineProperty(e.prototype,"updateLastCacheModificationPerId",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this.lastCacheModificationPerId.get(e);this.lastCacheModificationPerId.set(e,void 0===t?1:t+1)}}),Object.defineProperty(e.prototype,"getLastCacheModificationPerId",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this.lastCacheModificationPerId.get(e)||0;return this.cacheId+"-"+t}}),Object.defineProperty(e.prototype,"addNodeToCache",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){if(void 0===t&&(t=!0),e.identifierAttribute){var n=e.identifier;this.cache.has(n)||this.cache.set(n,r.observable.array([],gt));var i=this.cache.get(n);if(-1!==i.indexOf(e))throw mt("Already registered");i.push(e),t&&this.updateLastCacheModificationPerId(n)}}}),Object.defineProperty(e.prototype,"mergeCache",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this;(0,r.values)(e.identifierCache.cache).forEach(function(e){return e.forEach(function(e){t.addNodeToCache(e)})})}}),Object.defineProperty(e.prototype,"notifyDied",{enumerable:!1,configurable:!0,writable:!0,value:function(e){if(e.identifierAttribute){var t=e.identifier,r=this.cache.get(t);r&&(r.remove(e),r.length||this.cache.delete(t),this.updateLastCacheModificationPerId(e.identifier))}}}),Object.defineProperty(e.prototype,"splitCache",{enumerable:!1,configurable:!0,writable:!0,value:function(t){var n=this,i=new e,o=t.path;return(0,r.entries)(this.cache).forEach(function(e){for(var t=b(e,2),r=t[0],a=t[1],u=!1,l=a.length-1;l>=0;l--)0===a[l].path.indexOf(o)&&(i.addNodeToCache(a[l],!1),a.splice(l,1),u=!0);u&&n.updateLastCacheModificationPerId(r)}),i}}),Object.defineProperty(e.prototype,"has",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var r=this.cache.get(t);return!!r&&r.some(function(t){return e.isAssignableFrom(t.type)})}}),Object.defineProperty(e.prototype,"resolve",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var r=this.cache.get(t);if(!r)return null;var n=r.filter(function(t){return e.isAssignableFrom(t.type)});switch(n.length){case 0:return null;case 1:return n[0];default:throw mt("Cannot resolve a reference to type '"+e.name+"' with id: '"+t+"' unambigously, there are multiple candidates: "+n.map(function(e){return e.path}).join(", "))}}}),e}();function et(e,t,r,n,i){var o=at(i);if(o){if(o.parent)throw mt("Cannot add an object to a state tree if it is already part of the same or another state tree. Tried to assign an object to '"+(t?t.path:"")+"/"+r+"', but it lives already at '"+o.path+"'");return t&&o.setParent(t,r),o}return new ae(e,t,r,n,i)}function tt(e,t,r,n,i){return new te(e,t,r,n,i)}function rt(e){return e instanceof te||e instanceof ae}function nt(e){return!(!e||!e.$treenode)}function it(e,t){Ut(e,nt,"mobx-state-tree node",t)}function ot(e){if(!nt(e))throw mt("Value "+e+" is no MST Node");return e.$treenode}function at(e){return e&&e.$treenode||null}function ut(){return ot(this).snapshot}!function(e){e[e.INITIALIZING=0]="INITIALIZING",e[e.CREATED=1]="CREATED",e[e.FINALIZED=2]="FINALIZED",e[e.DETACHING=3]="DETACHING",e[e.DEAD=4]="DEAD"}(Ke||(Ke={}));var lt=function(e){return".."};function st(e,t){if(e.root!==t.root)throw mt("Cannot calculate relative path: objects '"+e+"' and '"+t+"' are not part of the same object tree");for(var r=or(e.path),n=or(t.path),i=0;i<r.length&&r[i]===n[i];i++);return r.slice(i).map(lt).join("/")+ir(n.slice(i))}function ct(e,t,r){return void 0===r&&(r=!0),pt(e,or(t),r)}function pt(e,t,r){void 0===r&&(r=!0);for(var n=e,i=0;i<t.length;i++){var o=t[i];if(".."===o){if(n=n.parent)continue}else{if("."===o)continue;if(n){if(n instanceof te)try{var a=n.value;nt(a)&&(n=ot(a))}catch(u){if(!r)return;throw u}if(n instanceof ae)if(n.getChildType(o)&&(n=n.getChildNode(o)))continue}}if(r)throw mt("Could not resolve '"+o+"' in path '"+(ir(t.slice(0,i))||"/")+"' while resolving '"+ir(t)+"'");return}return n}function ft(e){if(!e)return yt;var t=Object.keys(e);if(!t.length)return yt;var r=new Array(t.length);return t.forEach(function(t,n){r[n]=e[t]}),r}var bt="See https://github.com/mobxjs/mobx-state-tree/issues/399 for more information. Note that the middleware event types starting with `process` now start with `flow`.";function ht(e){return Ft("process","`process()` has been renamed to `flow()`. "+bt),Jt(e)}var dt=Object.toString(),yt=Object.freeze([]),vt=Object.freeze({}),gt=(0,r._getGlobalState)().useProxies?{deep:!1}:{deep:!1,proxy:!1};function mt(e){return void 0===e&&(e="Illegal state"),new Error("[mobx-state-tree] "+e)}function wt(e){return e}Object.freeze(gt);var Pt=Number.isInteger||function(e){return"number"==typeof e&&isFinite(e)&&Math.floor(e)===e};function Ot(e){return Array.isArray(e)||(0,r.isObservableArray)(e)}function jt(e){return e?Ot(e)?e:[e]:yt}function _t(e){for(var t=[],r=1;r<arguments.length;r++)t[r-1]=arguments[r];for(var n=0;n<t.length;n++){var i=t[n];for(var o in i)e[o]=i[o]}return e}function St(e){var t;if(null===e||"object"!=typeof e)return!1;var r=Object.getPrototypeOf(e);return null==r||(null===(t=r.constructor)||void 0===t?void 0:t.toString())===dt}function At(e){return!(null===e||"object"!=typeof e||e instanceof Date||e instanceof RegExp)}function It(e,t){return void 0===t&&(t=!0),null==e||"string"==typeof e||"number"==typeof e||"boolean"==typeof e||t&&e instanceof Date}function xt(e){return Lt()?It(e)||(0,r.isObservableArray)(e)?e:Object.freeze(e):e}function Tt(e){return Lt()?(xt(e),St(e)&&Object.keys(e).forEach(function(t){It(e[t])||Object.isFrozen(e[t])||Tt(e[t])}),e):e}function Ct(e){return"function"!=typeof e}function Et(e,t,n){(0,r.isObservableObject)(e)?(0,r.defineProperty)(e,t,n):Object.defineProperty(e,t,n)}function Vt(e,t,r){Et(e,t,{enumerable:!1,writable:!1,configurable:!0,value:r})}function Nt(e,t,r){Et(e,t,{enumerable:!1,writable:!0,configurable:!0,value:r})}var Dt=function(){function e(){Object.defineProperty(this,"handlers",{enumerable:!0,configurable:!0,writable:!0,value:[]})}return Object.defineProperty(e.prototype,"hasSubscribers",{get:function(){return this.handlers.length>0},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"register",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var r=this;return void 0===t&&(t=!1),t?this.handlers.unshift(e):this.handlers.push(e),function(){r.unregister(e)}}}),Object.defineProperty(e.prototype,"has",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return this.handlers.indexOf(e)>=0}}),Object.defineProperty(e.prototype,"unregister",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this.handlers.indexOf(e);t>=0&&this.handlers.splice(t,1)}}),Object.defineProperty(e.prototype,"clear",{enumerable:!1,configurable:!0,writable:!0,value:function(){this.handlers.length=0}}),Object.defineProperty(e.prototype,"emit",{enumerable:!1,configurable:!0,writable:!0,value:function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this.handlers.slice().forEach(function(t){return t.apply(void 0,h(e))})}}),e}(),kt=function(){function e(){Object.defineProperty(this,"eventHandlers",{enumerable:!0,configurable:!0,writable:!0,value:void 0})}return Object.defineProperty(e.prototype,"hasSubscribers",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this.eventHandlers&&this.eventHandlers[e];return!!t&&t.hasSubscribers}}),Object.defineProperty(e.prototype,"register",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,r){void 0===r&&(r=!1),this.eventHandlers||(this.eventHandlers={});var n=this.eventHandlers[e];return n||(n=this.eventHandlers[e]=new Dt),n.register(t,r)}}),Object.defineProperty(e.prototype,"has",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var r=this.eventHandlers&&this.eventHandlers[e];return!!r&&r.has(t)}}),Object.defineProperty(e.prototype,"unregister",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var r=this.eventHandlers&&this.eventHandlers[e];r&&r.unregister(t)}}),Object.defineProperty(e.prototype,"clear",{enumerable:!1,configurable:!0,writable:!0,value:function(e){this.eventHandlers&&delete this.eventHandlers[e]}}),Object.defineProperty(e.prototype,"clearAll",{enumerable:!1,configurable:!0,writable:!0,value:function(){this.eventHandlers=void 0}}),Object.defineProperty(e.prototype,"emit",{enumerable:!1,configurable:!0,writable:!0,value:function(e){for(var t,r=[],n=1;n<arguments.length;n++)r[n-1]=arguments[n];var i=this.eventHandlers&&this.eventHandlers[e];i&&(t=i).emit.apply(t,h(r))}}),e}();function Rt(e){for(var t=new Array(e.length),r=0;r<e.length;r++)t[r]=e[r];return t}function zt(e,t){return 0===e.indexOf(t)}var Ft=function(e,t){Lt()&&(Ft.ids&&!Ft.ids.hasOwnProperty(e)&&Mt("Deprecation warning: "+t),Ft.ids&&(Ft.ids[e]=!0))};function Mt(e){console.warn(new Error("[mobx-state-tree] "+e))}function Ht(){return Lt()||void 0!==e&&e.env&&!0}function Lt(){return!1}function Ut(e,t,r,n){if(Lt()&&!t(e))throw mt("expected "+r+" as argument "+jt(n).join(" or ")+", got "+e+" instead")}function $t(e,t){Ut(e,function(e){return"function"==typeof e},"function",t)}function Wt(e,t,r,n){Ut(e,function(e){return"number"==typeof e},"number",t),void 0!==r&&Ut(e,function(e){return e>=r},"number greater than "+r,t),void 0!==n&&Ut(e,function(e){return e<=n},"number lesser than "+n,t)}function Gt(e,t,r){void 0===r&&(r=!0),Ut(e,function(e){return"string"==typeof e},"string",t),r||Ut(e,function(e){return""!==e},"not empty string",t)}function Yt(e){"function"==typeof queueMicrotask?queueMicrotask(e):"function"==typeof setImmediate?setImmediate(e):setTimeout(e,1)}function Jt(e){return Kt(e.name,e)}function Zt(e){return e}function Bt(e){return function(){var t,r=[];for(t=0;t<arguments.length;t++)r[t]=arguments[t];return p(this,function(t){switch(t.label){case 0:return[4,e.apply(void 0,h(r))];case 1:return[2,t.sent()]}})}}function qt(e){return p(this,function(t){switch(t.label){case 0:return[4,e];case 1:return[2,t.sent()]}})}function Kt(e,t){var r=function(){var n=xe(),i=Ie();if(!i)throw mt("a mst flow must always have a parent context");var o=Ce(i);if(!o)throw mt("a mst flow must always have a parent action context");var a={name:e,id:n,tree:i.tree,context:i.context,parentId:i.id,allParentIds:h(i.allParentIds,[i.id]),rootId:i.rootId,parentEvent:i,parentActionEvent:o},u=arguments;function l(e,t,n){e.$mst_middleware=r.$mst_middleware,Te(s(s({},a),{type:t,args:[n]}),e)}return new Promise(function(e,n){var i,o=function(){i=t.apply(null,arguments),c(void 0)};function c(e){var t;try{l(function(e){t=i.next(e)},"flow_resume",e)}catch(r){return void Yt(function(){l(function(e){n(r)},"flow_throw",r)})}f(t)}function p(e){var t;try{l(function(e){t=i.throw(e)},"flow_resume_error",e)}catch(r){return void Yt(function(){l(function(e){n(r)},"flow_throw",r)})}f(t)}function f(t){if(!t.done){if(!t.value||"function"!=typeof t.value.then)throw mt("Only promises can be yielded to `async`, got: "+t);return t.value.then(c,p)}Yt(function(){l(function(t){e(t)},"flow_return",t.value)})}o.$mst_middleware=r.$mst_middleware,Te(s(s({},a),{type:"flow_spawn",args:Rt(u)}),o)})};return r}function Qt(e){if(!("oldValue"in e))throw mt("Patches without `oldValue` field cannot be inversed");return[Xt(e),er(e)]}function Xt(e){switch(e.op){case"add":return{op:"add",path:e.path,value:e.value};case"remove":return{op:"remove",path:e.path};case"replace":return{op:"replace",path:e.path,value:e.value}}}function er(e){switch(e.op){case"add":return{op:"remove",path:e.path};case"remove":return{op:"add",path:e.path,value:e.oldValue};case"replace":return{op:"replace",path:e.path,value:e.oldValue}}}function tr(e){return"number"==typeof e}function rr(e){return!0===tr(e)?""+e:-1===e.indexOf("/")&&-1===e.indexOf("~")?e:e.replace(/~/g,"~0").replace(/\//g,"~1")}function nr(e){return e.replace(/~1/g,"/").replace(/~0/g,"~")}function ir(e){if(0===e.length)return"";var t=function(e){return e.map(rr).join("/")};return"."===e[0]||".."===e[0]?t(e):"/"+t(e)}function or(e){var t=e.split("/").map(nr);if(!(""===e||"."===e||".."===e||zt(e,"/")||zt(e,"./")||zt(e,"../")))throw mt("a json path must be either rooted, empty or relative, but got '"+e+"'");return""===t[0]&&t.shift(),t}Ft.ids={};var ar=Symbol("$preProcessorFailed"),ur=function(e){function t(t,r,n){var i=e.call(this,n||t.name)||this;return Object.defineProperty(i,"_subtype",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(i,"_processors",{enumerable:!0,configurable:!0,writable:!0,value:r}),i}return l(t,e),Object.defineProperty(t.prototype,"flags",{get:function(){return this._subtype.flags|ne.SnapshotProcessor},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"describe",{enumerable:!1,configurable:!0,writable:!0,value:function(){return"snapshotProcessor("+this._subtype.describe()+")"}}),Object.defineProperty(t.prototype,"preProcessSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return this._processors.preProcessor?this._processors.preProcessor.call(null,e):e}}),Object.defineProperty(t.prototype,"preProcessSnapshotSafe",{enumerable:!1,configurable:!0,writable:!0,value:function(e){try{return this.preProcessSnapshot(e)}catch(t){return ar}}}),Object.defineProperty(t.prototype,"postProcessSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return this._processors.postProcessor?this._processors.postProcessor.call(null,e):e}}),Object.defineProperty(t.prototype,"_fixNode",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this;lr(e.type,this,"create");var r=e.getSnapshot;e.getSnapshot=function(){return t.postProcessSnapshot(r.call(e))},Qr(this._subtype)||(e.getReconciliationType=function(){return t})}}),Object.defineProperty(t.prototype,"instantiate",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,r,n){var i=nt(n)?n:this.preProcessSnapshot(n),o=this._subtype.instantiate(e,t,r,i);return this._fixNode(o),o}}),Object.defineProperty(t.prototype,"reconcile",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,r,n){var i=this._subtype.reconcile(e,nt(t)?t:this.preProcessSnapshot(t),r,n);return i!==e&&this._fixNode(i),i}}),Object.defineProperty(t.prototype,"getSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){void 0===t&&(t=!0);var r=this._subtype.getSnapshot(e);return t?this.postProcessSnapshot(r):r}}),Object.defineProperty(t.prototype,"isValidSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var r=this.preProcessSnapshotSafe(e);return r===ar?Ye(t,e,"Failed to preprocess value"):this._subtype.validate(r,t)}}),Object.defineProperty(t.prototype,"getSubTypes",{enumerable:!1,configurable:!0,writable:!0,value:function(){return this._subtype}}),Object.defineProperty(t.prototype,"is",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=fe(e)?this._subtype:nt(e)?S(e,!1):this.preProcessSnapshotSafe(e);return t!==ar&&0===this._subtype.validate(t,[{path:"",type:this._subtype}]).length}}),Object.defineProperty(t.prototype,"isAssignableFrom",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return this._subtype.isAssignableFrom(e)}}),Object.defineProperty(t.prototype,"isMatchingSnapshotId",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){if(!(this._subtype instanceof ce))return!1;var r=this.preProcessSnapshot(t);return this._subtype.isMatchingSnapshotId(e,r)}}),t}(se);function lr(e,t){for(var r,n,i=[],o=2;o<arguments.length;o++)i[o-2]=arguments[o];try{for(var a=f(i),u=a.next();!u.done;u=a.next()){var l=u.value;e[l]=t[l].bind(t)}}catch(s){r={error:s}}finally{try{u&&!u.done&&(n=a.return)&&n.call(a)}finally{if(r)throw r.error}}}function sr(e,t,r){if(be(e,1),Lt()){if(t.postProcessor&&"function"!=typeof t.postProcessor)throw fail("postSnapshotProcessor must be a function");if(t.preProcessor&&"function"!=typeof t.preProcessor)throw fail("preSnapshotProcessor must be a function")}return new ur(e,t,r)}var cr,pr="Map.put can only be used to store complex values that have an identifier type attribute";function fr(e,t){var r,n,i=e.getSubTypes();if(i===ue)return!1;if(i){var o=jt(i);try{for(var a=f(o),u=a.next();!u.done;u=a.next()){if(!fr(u.value,t))return!1}}catch(l){r={error:l}}finally{try{u&&!u.done&&(n=a.return)&&n.call(a)}finally{if(r)throw r.error}}}return e instanceof xr&&t.push(e),!0}!function(e){e[e.UNKNOWN=0]="UNKNOWN",e[e.YES=1]="YES",e[e.NO=2]="NO"}(cr||(cr={}));var br=function(e){function t(t){return e.call(this,t,r.observable.ref.enhancer)||this}return l(t,e),Object.defineProperty(t.prototype,"get",{enumerable:!1,configurable:!0,writable:!0,value:function(t){return e.prototype.get.call(this,""+t)}}),Object.defineProperty(t.prototype,"has",{enumerable:!1,configurable:!0,writable:!0,value:function(t){return e.prototype.has.call(this,""+t)}}),Object.defineProperty(t.prototype,"delete",{enumerable:!1,configurable:!0,writable:!0,value:function(t){return e.prototype.delete.call(this,""+t)}}),Object.defineProperty(t.prototype,"set",{enumerable:!1,configurable:!0,writable:!0,value:function(t,r){return e.prototype.set.call(this,""+t,r)}}),Object.defineProperty(t.prototype,"put",{enumerable:!1,configurable:!0,writable:!0,value:function(e){if(!e)throw mt("Map.put cannot be used to set empty values");if(nt(e)){var t=ot(e);if(Lt()&&!t.identifierAttribute)throw mt(pr);if(null===t.identifier)throw mt(pr);return this.set(t.identifier,e),e}if(At(e)){var r=ot(this),n=r.type;if(n.identifierMode!==cr.YES)throw mt(pr);var i=e[n.mapIdentifierAttribute];if(!Vn(i)){var o=this.put(n.getChildType().create(e,r.environment));return this.put(S(o))}var a=En(i);return this.set(a,e),this.get(a)}throw mt("Map.put can only be used to store complex values")}}),t}(r.ObservableMap),hr=function(e){function t(t,r,n){void 0===n&&(n=[]);var i=e.call(this,t)||this;return Object.defineProperty(i,"_subType",{enumerable:!0,configurable:!0,writable:!0,value:r}),Object.defineProperty(i,"identifierMode",{enumerable:!0,configurable:!0,writable:!0,value:cr.UNKNOWN}),Object.defineProperty(i,"mapIdentifierAttribute",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(i,"flags",{enumerable:!0,configurable:!0,writable:!0,value:ne.Map}),Object.defineProperty(i,"hookInitializers",{enumerable:!0,configurable:!0,writable:!0,value:[]}),i._determineIdentifierMode(),i.hookInitializers=n,i}return l(t,e),Object.defineProperty(t.prototype,"hooks",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var r=this.hookInitializers.length>0?this.hookInitializers.concat(e):[e];return new t(this.name,this._subType,r)}}),Object.defineProperty(t.prototype,"instantiate",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,r,n){return this._determineIdentifierMode(),et(this,e,t,r,n)}}),Object.defineProperty(t.prototype,"_determineIdentifierMode",{enumerable:!1,configurable:!0,writable:!0,value:function(){if(this.identifierMode===cr.UNKNOWN){var e=[];if(fr(this._subType,e)){var t=e.reduce(function(e,t){if(!t.identifierAttribute)return e;if(e&&e!==t.identifierAttribute)throw mt("The objects in a map should all have the same identifier attribute, expected '"+e+"', but child of type '"+t.name+"' declared attribute '"+t.identifierAttribute+"' as identifier");return t.identifierAttribute},void 0);t?(this.identifierMode=cr.YES,this.mapIdentifierAttribute=t):this.identifierMode=cr.NO}}}}),Object.defineProperty(t.prototype,"initializeChildNodes",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){void 0===t&&(t={});var r=e.type._subType,n={};return Object.keys(t).forEach(function(i){n[i]=r.instantiate(e,i,void 0,t[i])}),n}}),Object.defineProperty(t.prototype,"createNewInstance",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return new br(e)}}),Object.defineProperty(t.prototype,"finalizeNewInstance",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){(0,r._interceptReads)(t,e.unbox),e.type.hookInitializers.forEach(function(e){var r=e(t);Object.keys(r).forEach(function(e){var n=r[e],i=Ee(t,e,n);(Lt()?Nt:Vt)(t,e,i)})}),(0,r.intercept)(t,this.willChange),(0,r.observe)(t,this.didChange)}}),Object.defineProperty(t.prototype,"describe",{enumerable:!1,configurable:!0,writable:!0,value:function(){return"Map<string, "+this._subType.describe()+">"}}),Object.defineProperty(t.prototype,"getChildren",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return(0,r.values)(e.storedValue)}}),Object.defineProperty(t.prototype,"getChildNode",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var r=e.storedValue.get(""+t);if(!r)throw mt("Not a child "+t);return r}}),Object.defineProperty(t.prototype,"willChange",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=ot(e.object),r=e.name;t.assertWritable({subpath:r});var n=t.type,i=n._subType;switch(e.type){case"update":var o=e.newValue;if(o===e.object.get(r))return null;Ze(i,o),e.newValue=i.reconcile(t.getChildNode(r),e.newValue,t,r),n.processIdentifier(r,e.newValue);break;case"add":Ze(i,e.newValue),e.newValue=i.instantiate(t,r,void 0,e.newValue),n.processIdentifier(r,e.newValue)}return e}}),Object.defineProperty(t.prototype,"processIdentifier",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){if(this.identifierMode===cr.YES&&t instanceof ae){var r=t.identifier;if(r!==e)throw mt("A map of objects containing an identifier should always store the object under their own identifier. Trying to store key '"+r+"', but expected: '"+e+"'")}}}),Object.defineProperty(t.prototype,"getSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t={};return e.getChildren().forEach(function(e){t[e.subpath]=e.snapshot}),t}}),Object.defineProperty(t.prototype,"processInitialSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t={};return Object.keys(e).forEach(function(r){t[r]=e[r].getSnapshot()}),t}}),Object.defineProperty(t.prototype,"didChange",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=ot(e.object);switch(e.type){case"update":return void t.emitPatch({op:"replace",path:rr(e.name),value:e.newValue.snapshot,oldValue:e.oldValue?e.oldValue.snapshot:void 0},t);case"add":return void t.emitPatch({op:"add",path:rr(e.name),value:e.newValue.snapshot,oldValue:void 0},t);case"delete":var r=e.oldValue.snapshot;return e.oldValue.die(),void t.emitPatch({op:"remove",path:rr(e.name),oldValue:r},t)}}}),Object.defineProperty(t.prototype,"applyPatchLocally",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,r){var n=e.storedValue;switch(r.op){case"add":case"replace":n.set(t,r.value);break;case"remove":n.delete(t)}}}),Object.defineProperty(t.prototype,"applySnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){Ze(this,t);var r=e.storedValue,n={};if(Array.from(r.keys()).forEach(function(e){n[e]=!1}),t)for(var i in t)r.set(i,t[i]),n[""+i]=!0;Object.keys(n).forEach(function(e){!1===n[e]&&r.delete(e)})}}),Object.defineProperty(t.prototype,"getChildType",{enumerable:!1,configurable:!0,writable:!0,value:function(){return this._subType}}),Object.defineProperty(t.prototype,"isValidSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var r=this;return St(e)?Je(Object.keys(e).map(function(n){return r._subType.validate(e[n],We(t,n,r._subType))})):Ye(t,e,"Value is not a plain object")}}),Object.defineProperty(t.prototype,"getDefaultSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(){return vt}}),Object.defineProperty(t.prototype,"removeChild",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){e.storedValue.delete(t)}}),t}(ce);function dr(e){return new hr("map<string, "+e.name+">",e)}function yr(e){return fe(e)&&(e.flags&ne.Map)>0}hr.prototype.applySnapshot=(0,r.action)(hr.prototype.applySnapshot);var vr=function(e){function t(t,r,n){void 0===n&&(n=[]);var i=e.call(this,t)||this;return Object.defineProperty(i,"_subType",{enumerable:!0,configurable:!0,writable:!0,value:r}),Object.defineProperty(i,"flags",{enumerable:!0,configurable:!0,writable:!0,value:ne.Array}),Object.defineProperty(i,"hookInitializers",{enumerable:!0,configurable:!0,writable:!0,value:[]}),i.hookInitializers=n,i}return l(t,e),Object.defineProperty(t.prototype,"hooks",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var r=this.hookInitializers.length>0?this.hookInitializers.concat(e):[e];return new t(this.name,this._subType,r)}}),Object.defineProperty(t.prototype,"instantiate",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,r,n){return et(this,e,t,r,n)}}),Object.defineProperty(t.prototype,"initializeChildNodes",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){void 0===t&&(t=[]);var r=e.type._subType,n={};return t.forEach(function(t,i){var o=""+i;n[o]=r.instantiate(e,o,void 0,t)}),n}}),Object.defineProperty(t.prototype,"createNewInstance",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return r.observable.array(ft(e),gt)}}),Object.defineProperty(t.prototype,"finalizeNewInstance",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){(0,r._getAdministration)(t).dehancer=e.unbox,e.type.hookInitializers.forEach(function(e){var r=e(t);Object.keys(r).forEach(function(e){var n=r[e],i=Ee(t,e,n);(Lt()?Nt:Vt)(t,e,i)})}),(0,r.intercept)(t,this.willChange),(0,r.observe)(t,this.didChange)}}),Object.defineProperty(t.prototype,"describe",{enumerable:!1,configurable:!0,writable:!0,value:function(){return this._subType.describe()+"[]"}}),Object.defineProperty(t.prototype,"getChildren",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return e.storedValue.slice()}}),Object.defineProperty(t.prototype,"getChildNode",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var r=Number(t);if(r<e.storedValue.length)return e.storedValue[r];throw mt("Not a child: "+t)}}),Object.defineProperty(t.prototype,"willChange",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=ot(e.object);t.assertWritable({subpath:""+e.index});var r=t.type._subType,n=t.getChildren();switch(e.type){case"update":if(e.newValue===e.object[e.index])return null;var i=mr(t,r,[n[e.index]],[e.newValue],[e.index]);if(!i)return null;e.newValue=i[0];break;case"splice":var o=e.index,a=e.removedCount,u=e.added,l=mr(t,r,n.slice(o,o+a),u,u.map(function(e,t){return o+t}));if(!l)return null;e.added=l;for(var s=o+a;s<n.length;s++)n[s].setParent(t,""+(s+u.length-a))}return e}}),Object.defineProperty(t.prototype,"getSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return e.getChildren().map(function(e){return e.snapshot})}}),Object.defineProperty(t.prototype,"processInitialSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=[];return Object.keys(e).forEach(function(r){t.push(e[r].getSnapshot())}),t}}),Object.defineProperty(t.prototype,"didChange",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=ot(e.object);switch(e.type){case"update":return void t.emitPatch({op:"replace",path:""+e.index,value:e.newValue.snapshot,oldValue:e.oldValue?e.oldValue.snapshot:void 0},t);case"splice":for(var r=e.removedCount-1;r>=0;r--)t.emitPatch({op:"remove",path:""+(e.index+r),oldValue:e.removed[r].snapshot},t);for(r=0;r<e.addedCount;r++)t.emitPatch({op:"add",path:""+(e.index+r),value:t.getChildNode(""+(e.index+r)).snapshot,oldValue:void 0},t);return}}}),Object.defineProperty(t.prototype,"applyPatchLocally",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,r){var n=e.storedValue,i="-"===t?n.length:Number(t);switch(r.op){case"replace":n[i]=r.value;break;case"add":n.splice(i,0,r.value);break;case"remove":n.splice(i,1)}}}),Object.defineProperty(t.prototype,"applySnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){Ze(this,t),e.storedValue.replace(t)}}),Object.defineProperty(t.prototype,"getChildType",{enumerable:!1,configurable:!0,writable:!0,value:function(){return this._subType}}),Object.defineProperty(t.prototype,"isValidSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var r=this;return Ot(e)?Je(e.map(function(e,n){return r._subType.validate(e,We(t,""+n,r._subType))})):Ye(t,e,"Value is not an array")}}),Object.defineProperty(t.prototype,"getDefaultSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(){return yt}}),Object.defineProperty(t.prototype,"removeChild",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){e.storedValue.splice(Number(t),1)}}),t}(ce);function gr(e){return be(e,1),new vr(e.name+"[]",e)}function mr(e,t,r,n,i){for(var o=!0,a=0;;a++){var u=a<=n.length-1,l=r[a],s=u?n[a]:void 0,c=""+i[a];if(rt(s)&&(s=s.storedValue),!l&&!u)break;if(u)if(l)if(Pr(l,s))r[a]=wr(t,e,c,s,l);else{for(var p=void 0,f=a;f<r.length;f++)if(Pr(r[f],s)){p=r.splice(f,1)[0];break}o=!1;b=wr(t,e,c,s,p);r.splice(a,0,b)}else{if(nt(s)&&ot(s).parent===e)throw mt("Cannot add an object to a state tree if it is already part of the same or another state tree. Tried to assign an object to '"+e.path+"/"+c+"', but it lives already at '"+ot(s).path+"'");o=!1;var b=wr(t,e,c,s);r.splice(a,0,b)}else o=!1,r.splice(a,1),l instanceof ae&&l.createObservableInstanceIfNeeded(),l.die(),a--}return o?null:r}function wr(e,t,r,n,i){Ze(e,n);var o=function(){if(nt(n)){var o=ot(n);if(o.assertAlive(vt),null!==o.parent&&o.parent===t)return o.setParent(t,r),o}return i?e.reconcile(i,n,t,r):e.instantiate(t,r,void 0,n)}();return i&&i!==o&&(i instanceof ae&&i.createObservableInstanceIfNeeded(),i.die()),o}function Pr(e,t){if(!e.isAlive)return!1;if(nt(t)){var r=ot(t);return r.isAlive&&r===e}if(e.snapshot===t)return!0;if(!(e instanceof ae))return!1;var n=e.getReconciliationType();return null!==e.identifier&&e.identifierAttribute&&St(t)&&n.is(t)&&n.isMatchingSnapshotId(e,t)}function Or(e){return fe(e)&&(e.flags&ne.Array)>0}vr.prototype.applySnapshot=(0,r.action)(vr.prototype.applySnapshot);var jr="preProcessSnapshot",_r="postProcessSnapshot";function Sr(){return ot(this).toString()}var Ar={name:"AnonymousModel",properties:{},initializers:yt};function Ir(e){return Object.keys(e).reduce(function(e,r){var n,i,o;if(r in t)throw mt("Hook '"+r+"' was defined as property. Hooks should be defined as part of the actions");var a=Object.getOwnPropertyDescriptor(e,r);if("get"in a)throw mt("Getters are not supported as properties. Please use views instead");var u=a.value;if(null==u)throw mt("The default value of an attribute cannot be null or undefined as the type cannot be inferred. Did you mean `types.maybe(someType)`?");if(It(u))return Object.assign({},e,((n={})[r]=tn(Lr(u),u),n));if(u instanceof hr)return Object.assign({},e,((i={})[r]=tn(u,{}),i));if(u instanceof vr)return Object.assign({},e,((o={})[r]=tn(u,[]),o));if(fe(u))return e;throw Lt()&&"function"==typeof u?mt("Invalid type definition for property '"+r+"', it looks like you passed a function. Did you forget to invoke it, or did you intend to declare a view / action?"):Lt()&&"object"==typeof u?mt("Invalid type definition for property '"+r+"', it looks like you passed an object. Try passing another model type or a types.frozen."):mt("Invalid type definition for property '"+r+"', cannot infer a type from a value like '"+u+"' ("+typeof u+")")},e)}var xr=function(e){function n(t){var r=e.call(this,t.name||Ar.name)||this;return Object.defineProperty(r,"flags",{enumerable:!0,configurable:!0,writable:!0,value:ne.Object}),Object.defineProperty(r,"initializers",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(r,"properties",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(r,"preProcessor",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(r,"postProcessor",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(r,"propertyNames",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(r,"named",{enumerable:!0,configurable:!0,writable:!0,value:function(e){return r.cloneAndEnhance({name:e})}}),Object.defineProperty(r,"props",{enumerable:!0,configurable:!0,writable:!0,value:function(e){return r.cloneAndEnhance({properties:e})}}),Object.defineProperty(r,"preProcessSnapshot",{enumerable:!0,configurable:!0,writable:!0,value:function(e){var t=r.preProcessor;return t?r.cloneAndEnhance({preProcessor:function(r){return t(e(r))}}):r.cloneAndEnhance({preProcessor:e})}}),Object.defineProperty(r,"postProcessSnapshot",{enumerable:!0,configurable:!0,writable:!0,value:function(e){var t=r.postProcessor;return t?r.cloneAndEnhance({postProcessor:function(r){return e(t(r))}}):r.cloneAndEnhance({postProcessor:e})}}),Object.assign(r,Ar,t),r.properties=Ir(r.properties),xt(r.properties),r.propertyNames=Object.keys(r.properties),r.identifierAttribute=r._getIdentifierAttribute(),r}return l(n,e),Object.defineProperty(n.prototype,"_getIdentifierAttribute",{enumerable:!1,configurable:!0,writable:!0,value:function(){var e=void 0;return this.forAllProps(function(t,r){if(r.flags&ne.Identifier){if(e)throw mt("Cannot define property '"+t+"' as object identifier, property '"+e+"' is already defined as identifier property");e=t}}),e}}),Object.defineProperty(n.prototype,"cloneAndEnhance",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return new n({name:e.name||this.name,properties:Object.assign({},this.properties,e.properties),initializers:this.initializers.concat(e.initializers||[]),preProcessor:e.preProcessor||this.preProcessor,postProcessor:e.postProcessor||this.postProcessor})}}),Object.defineProperty(n.prototype,"actions",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this;return this.cloneAndEnhance({initializers:[function(r){return t.instantiateActions(r,e(r)),r}]})}}),Object.defineProperty(n.prototype,"instantiateActions",{enumerable:!1,configurable:!0,writable:!0,value:function(e,r){if(!St(r))throw mt("actions initializer should return a plain object containing actions");Object.keys(r).forEach(function(n){if(n===jr)throw mt("Cannot define action '"+jr+"', it should be defined using 'type.preProcessSnapshot(fn)' instead");if(n===_r)throw mt("Cannot define action '"+_r+"', it should be defined using 'type.postProcessSnapshot(fn)' instead");var i=r[n],o=e[n];if(n in t&&o){var a=i;i=function(){o.apply(null,arguments),a.apply(null,arguments)}}var u=i.$mst_middleware,l=i.bind(r);l.$mst_middleware=u;var s=Ee(e,n,l);r[n]=s,(Lt()?Nt:Vt)(e,n,s)})}}),Object.defineProperty(n.prototype,"volatile",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this;if("function"!=typeof e)throw mt("You passed an "+typeof e+" to volatile state as an argument, when function is expected");return this.cloneAndEnhance({initializers:[function(r){return t.instantiateVolatileState(r,e(r)),r}]})}}),Object.defineProperty(n.prototype,"instantiateVolatileState",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){if(!St(t))throw mt("volatile state initializer should return a plain object containing state");(0,r.set)(e,t)}}),Object.defineProperty(n.prototype,"extend",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this;return this.cloneAndEnhance({initializers:[function(r){var n=e(r),i=n.actions,o=n.views,a=n.state,u=c(n,["actions","views","state"]);for(var l in u)throw mt("The `extend` function should return an object with a subset of the fields 'actions', 'views' and 'state'. Found invalid key '"+l+"'");return a&&t.instantiateVolatileState(r,a),o&&t.instantiateViews(r,o),i&&t.instantiateActions(r,i),r}]})}}),Object.defineProperty(n.prototype,"views",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this;return this.cloneAndEnhance({initializers:[function(r){return t.instantiateViews(r,e(r)),r}]})}}),Object.defineProperty(n.prototype,"instantiateViews",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){if(!St(t))throw mt("views initializer should return a plain object containing views");Object.getOwnPropertyNames(t).forEach(function(n){var i,o=Object.getOwnPropertyDescriptor(t,n);if("get"in o)(0,r.defineProperty)(e,n,o),(0,r.makeObservable)(e,((i={})[n]=r.computed,i));else{if("function"!=typeof o.value)throw mt("A view member should either be a function or getter based property");(Lt()?Nt:Vt)(e,n,o.value)}})}}),Object.defineProperty(n.prototype,"instantiate",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,r,n){return et(this,e,t,r,nt(n)?n:this.applySnapshotPreProcessor(n))}}),Object.defineProperty(n.prototype,"initializeChildNodes",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){void 0===t&&(t={});var r=e.type,n={};return r.forAllProps(function(r,i){n[r]=i.instantiate(e,r,void 0,t[r])}),n}}),Object.defineProperty(n.prototype,"createNewInstance",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return r.observable.object(e,vt,gt)}}),Object.defineProperty(n.prototype,"finalizeNewInstance",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){Vt(t,"toString",Sr),this.forAllProps(function(n){(0,r._interceptReads)(t,n,e.unbox)}),this.initializers.reduce(function(e,t){return t(e)},t),(0,r.intercept)(t,this.willChange),(0,r.observe)(t,this.didChange)}}),Object.defineProperty(n.prototype,"willChange",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=e,r=ot(t.object),n=t.name;r.assertWritable({subpath:n});var i=r.type.properties[n];return i&&(Ze(i,t.newValue),t.newValue=i.reconcile(r.getChildNode(n),t.newValue,r,n)),t}}),Object.defineProperty(n.prototype,"didChange",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=e,r=ot(t.object);if(r.type.properties[t.name]){var n=t.oldValue?t.oldValue.snapshot:void 0;r.emitPatch({op:"replace",path:rr(t.name),value:t.newValue.snapshot,oldValue:n},r)}}}),Object.defineProperty(n.prototype,"getChildren",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this,r=[];return this.forAllProps(function(n){r.push(t.getChildNode(e,n))}),r}}),Object.defineProperty(n.prototype,"getChildNode",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){if(!(t in this.properties))throw mt("Not a value property: "+t);var n=(0,r._getAdministration)(e.storedValue,t).raw();if(!n)throw mt("Node not available for property "+t);return n}}),Object.defineProperty(n.prototype,"getSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var n=this;void 0===t&&(t=!0);var i={};return this.forAllProps(function(t,o){(0,r.getAtom)(e.storedValue,t).reportObserved(),i[t]=n.getChildNode(e,t).snapshot}),t?this.applySnapshotPostProcessor(i):i}}),Object.defineProperty(n.prototype,"processInitialSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t={};return Object.keys(e).forEach(function(r){t[r]=e[r].getSnapshot()}),this.applySnapshotPostProcessor(t)}}),Object.defineProperty(n.prototype,"applyPatchLocally",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,r){if("replace"!==r.op&&"add"!==r.op)throw mt("object does not support operation "+r.op);e.storedValue[t]=r.value}}),Object.defineProperty(n.prototype,"applySnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var r=this.applySnapshotPreProcessor(t);Ze(this,r),this.forAllProps(function(t){e.storedValue[t]=r[t]})}}),Object.defineProperty(n.prototype,"applySnapshotPreProcessor",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this.preProcessor;return t?t.call(null,e):e}}),Object.defineProperty(n.prototype,"applySnapshotPostProcessor",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this.postProcessor;return t?t.call(null,e):e}}),Object.defineProperty(n.prototype,"getChildType",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return Gt(e,1),this.properties[e]}}),Object.defineProperty(n.prototype,"isValidSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var r=this,n=this.applySnapshotPreProcessor(e);return St(n)?Je(this.propertyNames.map(function(e){return r.properties[e].validate(n[e],We(t,e,r.properties[e]))})):Ye(t,n,"Value is not a plain object")}}),Object.defineProperty(n.prototype,"forAllProps",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this;this.propertyNames.forEach(function(r){return e(r,t.properties[r])})}}),Object.defineProperty(n.prototype,"describe",{enumerable:!1,configurable:!0,writable:!0,value:function(){var e=this;return"{ "+this.propertyNames.map(function(t){return t+": "+e.properties[t].describe()}).join("; ")+" }"}}),Object.defineProperty(n.prototype,"getDefaultSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(){return vt}}),Object.defineProperty(n.prototype,"removeChild",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){e.storedValue[t]=void 0}}),n}(ce);function Tr(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var r="string"==typeof e[0]?e.shift():"AnonymousModel",n=e.shift()||{};return new xr({name:r,properties:n})}function Cr(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var r="string"==typeof e[0],n=r?e[0]:"AnonymousModel";return r&&e.shift(),Lt()&&e.forEach(function(e,t){Ut(e,Er,"mobx-state-tree model type",r?t+2:t+1)}),e.reduce(function(e,t){return e.cloneAndEnhance({name:e.name+"_"+t.name,properties:t.properties,initializers:t.initializers,preProcessor:function(r){return t.applySnapshotPreProcessor(e.applySnapshotPreProcessor(r))},postProcessor:function(r){return t.applySnapshotPostProcessor(e.applySnapshotPostProcessor(r))}})}).named(n)}function Er(e){return fe(e)&&(e.flags&ne.Object)>0}xr.prototype.applySnapshot=(0,r.action)(xr.prototype.applySnapshot);var Vr=function(e){function t(t,r,n,i){void 0===i&&(i=wt);var o=e.call(this,t)||this;return Object.defineProperty(o,"flags",{enumerable:!0,configurable:!0,writable:!0,value:r}),Object.defineProperty(o,"checker",{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(o,"initializer",{enumerable:!0,configurable:!0,writable:!0,value:i}),o.flags=r,o}return l(t,e),Object.defineProperty(t.prototype,"describe",{enumerable:!1,configurable:!0,writable:!0,value:function(){return this.name}}),Object.defineProperty(t.prototype,"instantiate",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,r,n){return tt(this,e,t,r,n)}}),Object.defineProperty(t.prototype,"createNewInstance",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return this.initializer(e)}}),Object.defineProperty(t.prototype,"isValidSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){return It(e)&&this.checker(e)?Ge():Ye(t,e,"Value is not a "+("Date"===this.name?"Date or a unix milliseconds timestamp":this.name))}}),t}(pe),Nr=new Vr("string",ne.String,function(e){return"string"==typeof e}),Dr=new Vr("number",ne.Number,function(e){return"number"==typeof e}),kr=new Vr("integer",ne.Integer,function(e){return Pt(e)}),Rr=new Vr("boolean",ne.Boolean,function(e){return"boolean"==typeof e}),zr=new Vr("null",ne.Null,function(e){return null===e}),Fr=new Vr("undefined",ne.Undefined,function(e){return void 0===e}),Mr=new Vr("Date",ne.Date,function(e){return"number"==typeof e||e instanceof Date},function(e){return e instanceof Date?e:new Date(e)});Mr.getSnapshot=function(e){return e.storedValue.getTime()};var Hr=Mr;function Lr(e){switch(typeof e){case"string":return Nr;case"number":return Dr;case"boolean":return Rr;case"object":if(e instanceof Date)return Hr}throw mt("Cannot determine primitive type from value "+e)}function Ur(e){return fe(e)&&(e.flags&(ne.String|ne.Number|ne.Integer|ne.Boolean|ne.Date))>0}var $r=function(e){function t(t){var r=e.call(this,JSON.stringify(t))||this;return Object.defineProperty(r,"value",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(r,"flags",{enumerable:!0,configurable:!0,writable:!0,value:ne.Literal}),r.value=t,r}return l(t,e),Object.defineProperty(t.prototype,"instantiate",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,r,n){return tt(this,e,t,r,n)}}),Object.defineProperty(t.prototype,"describe",{enumerable:!1,configurable:!0,writable:!0,value:function(){return JSON.stringify(this.value)}}),Object.defineProperty(t.prototype,"isValidSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){return It(e)&&e===this.value?Ge():Ye(t,e,"Value is not a literal "+JSON.stringify(this.value))}}),t}(pe);function Wr(e){return Ut(e,It,"primitive",1),new $r(e)}function Gr(e){return fe(e)&&(e.flags&ne.Literal)>0}var Yr=function(e){function t(t,r,n,i){var o=e.call(this,t)||this;return Object.defineProperty(o,"_subtype",{enumerable:!0,configurable:!0,writable:!0,value:r}),Object.defineProperty(o,"_predicate",{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(o,"_message",{enumerable:!0,configurable:!0,writable:!0,value:i}),o}return l(t,e),Object.defineProperty(t.prototype,"flags",{get:function(){return this._subtype.flags|ne.Refinement},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"describe",{enumerable:!1,configurable:!0,writable:!0,value:function(){return this.name}}),Object.defineProperty(t.prototype,"instantiate",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,r,n){return this._subtype.instantiate(e,t,r,n)}}),Object.defineProperty(t.prototype,"isAssignableFrom",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return this._subtype.isAssignableFrom(e)}}),Object.defineProperty(t.prototype,"isValidSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var r=this._subtype.validate(e,t);if(r.length>0)return r;var n=nt(e)?ot(e).snapshot:e;return this._predicate(n)?Ge():Ye(t,e,this._message(e))}}),Object.defineProperty(t.prototype,"reconcile",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,r,n){return this._subtype.reconcile(e,t,r,n)}}),Object.defineProperty(t.prototype,"getSubTypes",{enumerable:!1,configurable:!0,writable:!0,value:function(){return this._subtype}}),t}(se);function Jr(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var r="string"==typeof e[0]?e.shift():fe(e[0])?e[0].name:null,n=e[0],i=e[1],o=e[2]?e[2]:function(e){return"Value does not respect the refinement predicate"};return be(n,[1,2]),Gt(r,1),$t(i,[2,3]),$t(o,[3,4]),new Yr(r,n,i,o)}function Zr(e){return(e.flags&ne.Refinement)>0}function Br(e,t){var r="string"==typeof e?t:e;Lt()&&r.forEach(function(e,t){Gt(e,t+1)});var n=Kr.apply(void 0,h(r.map(function(e){return Wr(""+e)})));return"string"==typeof e&&(n.name=e),n}var qr=function(e){function t(t,r,n){var i=e.call(this,t)||this;return Object.defineProperty(i,"_types",{enumerable:!0,configurable:!0,writable:!0,value:r}),Object.defineProperty(i,"_dispatcher",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(i,"_eager",{enumerable:!0,configurable:!0,writable:!0,value:!0}),n=s({eager:!0,dispatcher:void 0},n),i._dispatcher=n.dispatcher,n.eager||(i._eager=!1),i}return l(t,e),Object.defineProperty(t.prototype,"flags",{get:function(){var e=ne.Union;return this._types.forEach(function(t){e|=t.flags}),e},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"isAssignableFrom",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return this._types.some(function(t){return t.isAssignableFrom(e)})}}),Object.defineProperty(t.prototype,"describe",{enumerable:!1,configurable:!0,writable:!0,value:function(){return"("+this._types.map(function(e){return e.describe()}).join(" | ")+")"}}),Object.defineProperty(t.prototype,"instantiate",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,r,n){var i=this.determineType(n,void 0);if(!i)throw mt("No matching type for union "+this.describe());return i.instantiate(e,t,r,n)}}),Object.defineProperty(t.prototype,"reconcile",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,r,n){var i=this.determineType(t,e.getReconciliationType());if(!i)throw mt("No matching type for union "+this.describe());return i.reconcile(e,t,r,n)}}),Object.defineProperty(t.prototype,"determineType",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){return this._dispatcher?this._dispatcher(e):t?t.is(e)?t:this._types.filter(function(e){return e!==t}).find(function(t){return t.is(e)}):this._types.find(function(t){return t.is(e)})}}),Object.defineProperty(t.prototype,"isValidSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){if(this._dispatcher)return this._dispatcher(e).validate(e,t);for(var r=[],n=0,i=0;i<this._types.length;i++){var o=this._types[i].validate(e,t);if(0===o.length){if(this._eager)return Ge();n++}else r.push(o)}return 1===n?Ge():Ye(t,e,"No type is applicable for the union").concat(Je(r))}}),Object.defineProperty(t.prototype,"getSubTypes",{enumerable:!1,configurable:!0,writable:!0,value:function(){return this._types}}),t}(se);function Kr(e){for(var t=[],r=1;r<arguments.length;r++)t[r-1]=arguments[r];var n=fe(e)?void 0:e,i=fe(e)?h([e],t):t,o="("+i.map(function(e){return e.name}).join(" | ")+")";return Lt()&&(n&&Ut(n,function(e){return St(e)},"object { eager?: boolean, dispatcher?: Function }",1),i.forEach(function(e,t){be(e,n?t+2:t+1)})),new qr(o,i,n)}function Qr(e){return(e.flags&ne.Union)>0}var Xr=function(e){function t(t,r,n){var i=e.call(this,t.name)||this;return Object.defineProperty(i,"_subtype",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(i,"_defaultValue",{enumerable:!0,configurable:!0,writable:!0,value:r}),Object.defineProperty(i,"optionalValues",{enumerable:!0,configurable:!0,writable:!0,value:n}),i}return l(t,e),Object.defineProperty(t.prototype,"flags",{get:function(){return this._subtype.flags|ne.Optional},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"describe",{enumerable:!1,configurable:!0,writable:!0,value:function(){return this._subtype.describe()+"?"}}),Object.defineProperty(t.prototype,"instantiate",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,r,n){if(this.optionalValues.indexOf(n)>=0){var i=this.getDefaultInstanceOrSnapshot();return this._subtype.instantiate(e,t,r,i)}return this._subtype.instantiate(e,t,r,n)}}),Object.defineProperty(t.prototype,"reconcile",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,r,n){return this._subtype.reconcile(e,this.optionalValues.indexOf(t)<0&&this._subtype.is(t)?t:this.getDefaultInstanceOrSnapshot(),r,n)}}),Object.defineProperty(t.prototype,"getDefaultInstanceOrSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(){var e="function"==typeof this._defaultValue?this._defaultValue():this._defaultValue;return"function"==typeof this._defaultValue&&Ze(this,e),e}}),Object.defineProperty(t.prototype,"isValidSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){return this.optionalValues.indexOf(e)>=0?Ge():this._subtype.validate(e,t)}}),Object.defineProperty(t.prototype,"isAssignableFrom",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return this._subtype.isAssignableFrom(e)}}),Object.defineProperty(t.prototype,"getSubTypes",{enumerable:!1,configurable:!0,writable:!0,value:function(){return this._subtype}}),t}(se);function en(e,t){if("function"!=typeof t&&nt(t))throw mt("default value cannot be an instance, pass a snapshot or a function that creates an instance/snapshot instead");be(e,1),Lt()&&"function"!=typeof t&&Ze(e,t)}function tn(e,t,r){return en(e,t),new Xr(e,t,r||rn)}var rn=[void 0];function nn(e){return fe(e)&&(e.flags&ne.Optional)>0}var on=tn(Fr,void 0),an=tn(zr,null);function un(e){return be(e,1),Kr(e,on)}function ln(e){return be(e,1),Kr(e,an)}var sn=function(e){function t(t,r){var n=e.call(this,t)||this;return Object.defineProperty(n,"_definition",{enumerable:!0,configurable:!0,writable:!0,value:r}),Object.defineProperty(n,"_subType",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),n}return l(t,e),Object.defineProperty(t.prototype,"flags",{get:function(){return(this._subType?this._subType.flags:0)|ne.Late},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"getSubType",{enumerable:!1,configurable:!0,writable:!0,value:function(e){if(!this._subType){var t=void 0;try{t=this._definition()}catch(r){if(!(r instanceof ReferenceError))throw r;t=void 0}if(e&&void 0===t)throw mt("Late type seems to be used too early, the definition (still) returns undefined");if(t){if(Lt()&&!fe(t))throw mt("Failed to determine subtype, make sure types.late returns a type definition.");this._subType=t}}return this._subType}}),Object.defineProperty(t.prototype,"instantiate",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,r,n){return this.getSubType(!0).instantiate(e,t,r,n)}}),Object.defineProperty(t.prototype,"reconcile",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,r,n){return this.getSubType(!0).reconcile(e,t,r,n)}}),Object.defineProperty(t.prototype,"describe",{enumerable:!1,configurable:!0,writable:!0,value:function(){var e=this.getSubType(!1);return e?e.name:"<uknown late type>"}}),Object.defineProperty(t.prototype,"isValidSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var r=this.getSubType(!1);return r?r.validate(e,t):Ge()}}),Object.defineProperty(t.prototype,"isAssignableFrom",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this.getSubType(!1);return!!t&&t.isAssignableFrom(e)}}),Object.defineProperty(t.prototype,"getSubTypes",{enumerable:!1,configurable:!0,writable:!0,value:function(){var e=this.getSubType(!1);return e||ue}}),t}(se);function cn(e,t){var r="string"==typeof e?e:"late("+e.toString()+")",n="string"==typeof e?t:e;if(Lt()&&("function"!=typeof n||0!==n.length))throw mt("Invalid late type, expected a function with zero arguments that returns a type, got: "+n);return new sn(r,n)}function pn(e){return fe(e)&&(e.flags&ne.Late)>0}var fn=function(e){function t(t){var r=e.call(this,t?"frozen("+t.name+")":"frozen")||this;return Object.defineProperty(r,"subType",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(r,"flags",{enumerable:!0,configurable:!0,writable:!0,value:ne.Frozen}),r}return l(t,e),Object.defineProperty(t.prototype,"describe",{enumerable:!1,configurable:!0,writable:!0,value:function(){return"<any immutable value>"}}),Object.defineProperty(t.prototype,"instantiate",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,r,n){return tt(this,e,t,r,Tt(n))}}),Object.defineProperty(t.prototype,"isValidSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){return Ct(e)?this.subType?this.subType.validate(e,t):Ge():Ye(t,e,"Value is not serializable and cannot be frozen")}}),t}(pe),bn=new fn;function hn(e){return 0===arguments.length?bn:fe(e)?new fn(e):tn(bn,e)}function dn(e){return fe(e)&&(e.flags&ne.Frozen)>0}function yn(e){switch(e){case t.beforeDestroy:return"destroy";case t.beforeDetach:return"detach";default:return}}var vn=function(){function e(e,t){if(Object.defineProperty(this,"targetType",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"identifier",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"node",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"resolvedReference",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Vn(e))this.identifier=e;else{if(!nt(e))throw mt("Can only store references to tree nodes or identifiers, got: '"+e+"'");var r=ot(e);if(!r.identifierAttribute)throw mt("Can only store references with a defined identifier attribute.");var n=r.unnormalizedIdentifier;if(null==n)throw mt("Can only store references to tree nodes with a defined identifier.");this.identifier=n}}return Object.defineProperty(e.prototype,"updateResolvedReference",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=En(this.identifier),r=e.root,n=r.identifierCache.getLastCacheModificationPerId(t);if(!this.resolvedReference||this.resolvedReference.lastCacheModification!==n){var i=this.targetType,o=r.identifierCache.resolve(i,t);if(!o)throw new gn("[mobx-state-tree] Failed to resolve reference '"+this.identifier+"' to type '"+this.targetType.name+"' (from node: "+e.path+")");this.resolvedReference={node:o,lastCacheModification:n}}}}),Object.defineProperty(e.prototype,"resolvedValue",{get:function(){return this.updateResolvedReference(this.node),this.resolvedReference.node.value},enumerable:!1,configurable:!0}),e}(),gn=function(e){function t(r){var n=e.call(this,r)||this;return Object.setPrototypeOf(n,t.prototype),n}return l(t,e),t}(Error),mn=function(e){function r(t,r){var n=e.call(this,"reference("+t.name+")")||this;return Object.defineProperty(n,"targetType",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(n,"onInvalidated",{enumerable:!0,configurable:!0,writable:!0,value:r}),Object.defineProperty(n,"flags",{enumerable:!0,configurable:!0,writable:!0,value:ne.Reference}),n}return l(r,e),Object.defineProperty(r.prototype,"describe",{enumerable:!1,configurable:!0,writable:!0,value:function(){return this.name}}),Object.defineProperty(r.prototype,"isAssignableFrom",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return this.targetType.isAssignableFrom(e)}}),Object.defineProperty(r.prototype,"isValidSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){return Vn(e)?Ge():Ye(t,e,"Value is not a valid identifier, which is a string or a number")}}),Object.defineProperty(r.prototype,"fireInvalidated",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,r,n){var i=t.parent;if(i&&i.isAlive){var o=i.storedValue;o&&this.onInvalidated({cause:e,parent:o,invalidTarget:n?n.storedValue:void 0,invalidId:r,replaceRef:function(e){m(t.root.storedValue,{op:"replace",value:e,path:t.path})},removeRef:function(){Er(i.type)?this.replaceRef(void 0):m(t.root.storedValue,{op:"remove",path:t.path})}})}}}),Object.defineProperty(r.prototype,"addTargetNodeWatcher",{enumerable:!1,configurable:!0,writable:!0,value:function(e,r){var n=this,i=this.getValue(e);if(i){var o=ot(i),a=function(t,i){var a=yn(i);a&&n.fireInvalidated(a,e,r,o)},u=o.registerHook(t.beforeDetach,a),l=o.registerHook(t.beforeDestroy,a);return function(){u(),l()}}}}),Object.defineProperty(r.prototype,"watchTargetNodeForInvalidations",{enumerable:!1,configurable:!0,writable:!0,value:function(e,r,n){var i=this;if(this.onInvalidated){var o;e.registerHook(t.beforeDestroy,function(){o&&o()});var a=function(t){o&&o();var a=e.parent,u=a&&a.storedValue;if(a&&a.isAlive&&u){(n?!!n.get(r,u):e.root.identifierCache.has(i.targetType,En(r)))?o=i.addTargetNodeWatcher(e,r):t||i.fireInvalidated("invalidSnapshotReference",e,r,null)}};e.state===Ke.FINALIZED?a(!0):(e.isRoot||e.root.registerHook(t.afterCreationFinalization,function(){e.parent&&e.parent.createObservableInstanceIfNeeded()}),e.registerHook(t.afterAttach,function(){a(!1)}))}}}),r}(pe),wn=function(e){function t(t,r){return e.call(this,t,r)||this}return l(t,e),Object.defineProperty(t.prototype,"getValue",{enumerable:!1,configurable:!0,writable:!0,value:function(e){if(e.isAlive)return e.storedValue.resolvedValue}}),Object.defineProperty(t.prototype,"getSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return e.storedValue.identifier}}),Object.defineProperty(t.prototype,"instantiate",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,r,n){var i=nt(n)?R(n):n,o=new vn(n,this.targetType),a=tt(this,e,t,r,o);return o.node=a,this.watchTargetNodeForInvalidations(a,i,void 0),a}}),Object.defineProperty(t.prototype,"reconcile",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,r,n){if(!e.isDetaching&&e.type===this){var i=nt(t),o=e.storedValue;if(!i&&o.identifier===t||i&&o.resolvedValue===t)return e.setParent(r,n),e}var a=this.instantiate(r,n,void 0,t);return e.die(),a}}),t}(mn),Pn=function(e){function t(t,r,n){var i=e.call(this,t,n)||this;return Object.defineProperty(i,"options",{enumerable:!0,configurable:!0,writable:!0,value:r}),i}return l(t,e),Object.defineProperty(t.prototype,"getValue",{enumerable:!1,configurable:!0,writable:!0,value:function(e){if(e.isAlive)return this.options.get(e.storedValue,e.parent?e.parent.storedValue:null)}}),Object.defineProperty(t.prototype,"getSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return e.storedValue}}),Object.defineProperty(t.prototype,"instantiate",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,r,n){var i=nt(n)?this.options.set(n,e?e.storedValue:null):n,o=tt(this,e,t,r,i);return this.watchTargetNodeForInvalidations(o,i,this.options),o}}),Object.defineProperty(t.prototype,"reconcile",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,r,n){var i=nt(t)?this.options.set(t,e?e.storedValue:null):t;if(!e.isDetaching&&e.type===this&&e.storedValue===i)return e.setParent(r,n),e;var o=this.instantiate(r,n,void 0,i);return e.die(),o}}),t}(mn);function On(e,t){if(be(e,1),Lt()&&2===arguments.length&&"string"==typeof arguments[1])throw mt("References with base path are no longer supported. Please remove the base path.");var r=t||void 0,n=t?t.onInvalidated:void 0;if(r&&(r.get||r.set)){if(Lt()&&(!r.get||!r.set))throw mt("reference options must either contain both a 'get' and a 'set' method or none of them");return new Pn(e,{get:r.get,set:r.set},n)}return new wn(e,n)}function jn(e){return(e.flags&ne.Reference)>0}function _n(e,t){var r=On(e,s(s({},t),{onInvalidated:function(e){t&&t.onInvalidated&&t.onInvalidated(e),e.removeRef()}}));return t&&!1===t.acceptsUndefined?r:un(r)}var Sn=function(e){function t(t,r){var n=e.call(this,t)||this;return Object.defineProperty(n,"validType",{enumerable:!0,configurable:!0,writable:!0,value:r}),Object.defineProperty(n,"flags",{enumerable:!0,configurable:!0,writable:!0,value:ne.Identifier}),n}return l(t,e),Object.defineProperty(t.prototype,"instantiate",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,r,n){if(!(e&&e.type instanceof xr))throw mt("Identifier types can only be instantiated as direct child of a model type");return tt(this,e,t,r,n)}}),Object.defineProperty(t.prototype,"reconcile",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,r,n){if(e.storedValue!==t)throw mt("Tried to change identifier from '"+e.storedValue+"' to '"+t+"'. Changing identifiers is not allowed.");return e.setParent(r,n),e}}),Object.defineProperty(t.prototype,"isValidSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){return typeof e!==this.validType?Ye(t,e,"Value is not a valid "+this.describe()+", expected a "+this.validType):Ge()}}),t}(pe),An=function(e){function t(){var t=e.call(this,"identifier","string")||this;return Object.defineProperty(t,"flags",{enumerable:!0,configurable:!0,writable:!0,value:ne.Identifier}),t}return l(t,e),Object.defineProperty(t.prototype,"describe",{enumerable:!1,configurable:!0,writable:!0,value:function(){return"identifier"}}),t}(Sn),In=function(e){function t(){return e.call(this,"identifierNumber","number")||this}return l(t,e),Object.defineProperty(t.prototype,"getSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return e.storedValue}}),Object.defineProperty(t.prototype,"describe",{enumerable:!1,configurable:!0,writable:!0,value:function(){return"identifierNumber"}}),t}(Sn),xn=new An,Tn=new In;function Cn(e){return fe(e)&&(e.flags&ne.Identifier)>0}function En(e){return""+e}function Vn(e){return"string"==typeof e||"number"==typeof e}function Nn(e,t){Ut(e,Vn,"string or number (identifier)",t)}function Dn(e){return new kn(e)}var kn=function(e){function t(t){var r=e.call(this,t.name)||this;return Object.defineProperty(r,"options",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(r,"flags",{enumerable:!0,configurable:!0,writable:!0,value:ne.Custom}),r}return l(t,e),Object.defineProperty(t.prototype,"describe",{enumerable:!1,configurable:!0,writable:!0,value:function(){return this.name}}),Object.defineProperty(t.prototype,"isValidSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){if(this.options.isTargetType(e))return Ge();var r=this.options.getValidationMessage(e);return r?Ye(t,e,"Invalid value for type '"+this.name+"': "+r):Ge()}}),Object.defineProperty(t.prototype,"getSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return this.options.toSnapshot(e.storedValue)}}),Object.defineProperty(t.prototype,"instantiate",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,r,n){return tt(this,e,t,r,this.options.isTargetType(n)?n:this.options.fromSnapshot(n,e&&e.root.environment))}}),Object.defineProperty(t.prototype,"reconcile",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,r,n){var i=!this.options.isTargetType(t);if(!e.isDetaching&&(e.type===this&&(i?t===e.snapshot:t===e.storedValue)))return e.setParent(r,n),e;var o=i?this.options.fromSnapshot(t,r.root.environment):t,a=this.instantiate(r,n,void 0,o);return e.die(),a}}),t}(pe),Rn={enumeration:Br,model:Tr,compose:Cr,custom:Dn,reference:On,safeReference:_n,union:Kr,optional:tn,literal:Wr,maybe:un,maybeNull:ln,refinement:Jr,string:Nr,boolean:Rr,number:Dr,integer:kr,Date:Hr,map:dr,array:gr,frozen:hn,identifier:xn,identifierNumber:Tn,late:cn,undefined:Fr,null:zr,snapshotProcessor:sr};exports.types=Rn;
|
|
@@ -3278,9 +3280,9 @@ var e=require("process");Object.defineProperty(exports,"__esModule",{value:!0}),
|
|
|
3278
3280
|
},{}],"GGhN":[function(require,module,exports) {
|
|
3279
3281
|
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.getCrop=exports.getImageSize=void 0;const t=require("./svg");function e(e){return new Promise(i=>{const h=document.createElement("img");h.onload=(async()=>{0===h.width||0===h.height?i(await(0,t.getSvgSize)(e)):i({width:h.width,height:h.height})}),h.src=e})}function i(t,e){const{width:i,height:h}=t,o=i/h;let r,g;o>=e.width/e.height?(r=e.width,g=e.width/o):(r=e.height*o,g=e.height);const c=(e.width-r)/2,d=(e.height-g)/2;return{cropX:c/e.width,cropY:d/e.height,cropWidth:r/e.width,cropHeight:g/e.height}}exports.getImageSize=e,exports.getCrop=i;
|
|
3280
3282
|
},{"./svg":"B1DI"}],"YsBD":[function(require,module,exports) {
|
|
3281
|
-
"use strict";var e=this&&this.__createBinding||(Object.create?function(e,t,o
|
|
3283
|
+
"use strict";var e=this&&this.__createBinding||(Object.create?function(e,t,i,o){void 0===o&&(o=i);var n=Object.getOwnPropertyDescriptor(t,i);n&&!("get"in n?!t.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return t[i]}}),Object.defineProperty(e,o,n)}:function(e,t,i,o){void 0===o&&(o=i),e[o]=t[i]}),t=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=this&&this.__importStar||function(i){if(i&&i.__esModule)return i;var o={};if(null!=i)for(var n in i)"default"!==n&&Object.prototype.hasOwnProperty.call(i,n)&&e(o,i,n);return t(o,i),o};Object.defineProperty(exports,"__esModule",{value:!0}),exports.jsonToHTML=exports.jsonToDOM=exports.fixRatio=void 0;const o=require("./image"),n=i(require("./svg"));async function r(e,t){const i=await l(e),o=document.createElement("canvas");o.width=2*i.width,o.height=2*i.height,o.getContext("2d").drawImage(i,0,0,o.width,o.height);const n=document.createElement("canvas");n.width=t.width,n.height=t.height;const r=n.getContext("2d");let{cropX:s,cropY:a}=t;const h=o.width*t.cropWidth,c=o.height*t.cropHeight,g=t.width/t.height;let p,d;const u=h/c;return"svg"===t.type?(p=h,d=c):g>=u?(p=h,d=h/g):(p=c*g,d=c),r.drawImage(o,s*o.width,a*o.height,p,d,0,0,n.width,n.height),n.toDataURL("image/png")}const s=(e,t,...i)=>({type:e,props:t,children:i||[]});function a(e){var t=(new DOMParser).parseFromString(e,"image/svg+xml");return t.documentElement.setAttribute("preserveAspectRatio","none"),(new XMLSerializer).serializeToString(t)}exports.fixRatio=a;const l=e=>new Promise(t=>{const i=new window.Image;i.onload=(()=>{t(i)}),i.src=e,i.crossOrigin="anonymous"}),h=async({element:e,page:t,store:i})=>{let{src:o}=e;if("svg"===e.type){const t=await n.urlToString(o);o=n.replaceColors(t,new Map(Object.entries(e.colorsReplace)))}o=await r(o,e);let a="";return e.flipX&&(a+="scaleX(-1)"),e.flipY&&(a+="scaleY(-1)"),s("img",{src:o,width:"100%",height:"100%",style:Object.assign(Object.assign({},{}),{"border-radius":e.cornerRadius+"px",border:e.borderSize?`${e.borderSize}px solid ${e.borderColor}`:"none",transform:a})})},c=async({element:e,page:t,store:i})=>{let o={};e.fill.indexOf("gradient")>=0&&(o=Object.assign(Object.assign({},o),{"background-color":e.fill,"background-image":e.fill,"background-clip":"text","text-fill-color":"transparent","-webkit-background-clip":"text","-webkit-text-fill-color":"transparent"}));const n=e.backgroundPadding*(e.fontSize*e.lineHeight),r=s("div",{style:{position:"absolute",top:-n/2+"px",left:-n/2+"px",display:e.backgroundEnabled?"block":"none",width:e.width+n+"px",height:e.height+n+"px","background-color":e.backgroundColor,"border-radius":e.backgroundCornerRadius*(e.fontSize*e.lineHeight*.5)+"px"}}),a=s("div",{style:Object.assign(Object.assign({},o),{position:"absolute",top:0,left:0,width:e.width+"px",color:e.fill,"white-space":"pre-wrap","font-size":e.fontSize+"px","text-align":e.align,"font-family":e.fontFamily,"text-decoration":e.textDecoration||"none","line-height":e.lineHeight,"letter-spacing":e.letterSpacing+"em","font-style":e.fontStyle,"font-weight":e.fontWeight,"-webkit-text-stroke":`${e.strokeWidth}px ${e.stroke}`,"text-stroke":`${e.strokeWidth}px ${e.stroke}`})},e.text.split("\n").join("<br />"));return s("div",{style:{position:"relative"}},r,a)},g=({element:e,type:t})=>{const i={"stroke-width":e.height,stroke:e.color,"line-cap":"round","stroke-linejoin":"round",opacity:e.opacity};return"arrow"===t||"triangle"===t?s("polyline",Object.assign({points:`${3*e.height},${2*-e.height} 0,0 ${3*e.height},${2*e.height}`},i)):"bar"===t?s("polyline",Object.assign({points:`0,${2*-e.height} 0,${2*e.height}`},i)):"circle"===t?s("circle",Object.assign({r:e.height},i)):"square"===t?s("polyline",Object.assign({points:`${-e.height},${-e.height} ${-e.height},${e.height} ${e.height},${e.height} ${e.height},${-e.height}`},i)):null},p=async({element:e,page:t,store:i})=>s("svg",{style:{width:"100%",height:"100%",contain:"layout style size",overflow:"visible"}},s("rect",{x:0,y:0,width:e.width,height:e.height,fill:e.color}),s("g",{transform:`translate(0 ${e.height/2})`},g({element:e,type:e.startHead})),s("g",{transform:`translate(${e.width} ${e.height/2}) rotate(180)`},g({element:e,type:e.endHead}))),d=async({element:e,page:t,store:i,elementHook:o})=>{const n=await Promise.all(e.children.map(e=>f({element:e,page:t,store:i,elementHook:o}))),r=s("div",{style:{"transform-origin":"top left",opacity:e.opacity}},...n);return o&&o({dom:r,element:e})||r},u={image:h,svg:h,text:c,line:p,group:d};async function f({element:e,page:t,store:i,elementHook:o}){let n=await u[e.type];n||(n=(()=>s("div",{})),console.error(`HTML export does not support ${e.type} type...`));const r=await n({element:e,page:t,store:i}),a=[];e.blurEnabled&&a.push(`blur(${e.blurRadius/2}px)`),e.brightnessEnabled&&a.push(`brightness(${100*e.brightness+100}%)`),e.sepiaEnabled&&a.push("sepia()"),e.grayscaleEnabled&&a.push("grayscale()"),e.shadowEnabled&&a.push(`drop-shadow(${e.shadowOffsetX}px ${e.shadowOffsetY}px ${e.shadowBlur}px ${e.shadowColor})`);const l=s("div",{style:{position:"absolute",left:e.x+"px",top:e.y+"px",width:e.width+"px",height:e.height+"px",transform:`rotate(${e.rotation}deg)`,"transform-origin":"top left",opacity:e.opacity,filter:a.join(" ")}},r);return o&&o({dom:l,element:e})||l}async function b({page:e,store:t,elementHook:i}){const n=await Promise.all(e.children.map(o=>f({element:o,page:e,store:t,elementHook:i})));let a={};if(e.background.indexOf("url")>=0||e.background.indexOf("http")>=0||e.background.indexOf(".jpg")>=0||e.background.indexOf(".png")>=0||e.background.indexOf(".jpeg")>=0){const i=await l(e.background),n=await r(e.background,Object.assign({width:t.width,height:t.height,x:0,y:0},(0,o.getCrop)({width:t.width,height:t.height},{width:i.width,height:i.height})));a=Object.assign(Object.assign({},a),{"background-image":`url(${n})`})}return s("div",{className:"page",style:Object.assign(Object.assign({},a),{width:t.width+"px",height:t.height+"px",background:e.background,border:"1px solid grey",overflow:"hidden",position:"relative"})},...n)}async function m({json:e,elementHook:t}){const i=await Promise.all(e.pages.map(i=>b({page:i,store:e,elementHook:t}))),o=[];e.pages.forEach(e=>{e.children.forEach(e=>{"text"===e.type&&-1===o.indexOf(e.fontFamily)&&o.push(e.fontFamily)})});const n=o.map(t=>e.fonts.find(e=>e.fontFamily===t)?s("style",{},""):s("link",{href:`https://fonts.googleapis.com/css?family=${t}`,rel:"stylesheet"}));return s("div",{className:"design"},...n,...i)}exports.jsonToDOM=m;const y=(e,t)=>"object"==typeof t?`${e}="${Object.keys(t).map(e=>`${e}:${t[e]};`).join(" ")}"`:`${e}="${t}"`,w=({dom:e})=>"string"==typeof e?e:e?`<${e.type} ${Object.keys(e.props).map(t=>y(t,e.props[t])).join(" ")}>${e.children.map(e=>w({dom:e})).join("")}</${e.type}>`:"";async function x({json:e,elementHook:t}){const i=await m({json:e,elementHook:t});return w({dom:i})}exports.jsonToHTML=x;
|
|
3282
3284
|
},{"./image":"GGhN","./svg":"B1DI"}],"GRkH":[function(require,module,exports) {
|
|
3283
|
-
"use strict";var e=this&&this.__createBinding||(Object.create?function(e,t,o,n){void 0===n&&(n=o);var i=Object.getOwnPropertyDescriptor(t,o);i&&!("get"in i?!t.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return t[o]}}),Object.defineProperty(e,n,i)}: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},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 i=0;for(n=Object.getOwnPropertySymbols(e);i<n.length;i++)t.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(e,n[i])&&(o[n[i]]=e[n[i]])}return o},i=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.GroupElement=exports.registerShapeModel=exports.SVGElement=exports.LineElement=exports.ImageElement=exports.TextElement=exports.Element=exports.Node=void 0;const s=require("mobx-state-tree"),a=require("./history"),r=require("nanoid"),l=i(require("konva")),d=require("../utils/download"),c=require("../utils/pdf"),p=require("../utils/validate-key"),g=o(require("../utils/fonts")),h=require("../utils/loader"),u=require("../utils/unit"),m=require("../utils/deep-equal"),f=require("../utils/wait"),b=require("../utils/html");(0,s.setLivelinessChecking)("ignore");const y=(e,t)=>{e.children&&e.children.forEach(e=>{t(e),y(e,t)})};exports.Node=s.types.model("Node",{id:s.types.identifier,type:"none",name:"",opacity:1,animations:s.types.array(s.types.frozen()),custom:s.types.frozen(),visible:!0,selectable:!0,removable:!0,alwaysOnTop:!1,showInExport:!0}).postProcessSnapshot(e=>{const t=Object.assign({},e),o={};for(var n in t)"_"!==n[0]&&(o[n]=e[n]);return o}).views(e=>({get locked(){return!(e.draggable||e.contentEditable||e.styleEditable||e.resizable)},get page(){return(0,s.getParentOfType)(e,exports.Page)},get store(){return(0,s.getParentOfType)(e,exports.Store)},get top(){let t=e;for(;;){if(!(0,s.hasParentOfType)(t,exports.GroupElement))return t;t=(0,s.getParentOfType)(t,exports.GroupElement)}},get parent(){return(0,s.hasParentOfType)(e,exports.GroupElement)?(0,s.getParentOfType)(e,exports.GroupElement):(0,s.hasParentOfType)(e,exports.Page)?(0,s.getParentOfType)(e,exports.Page):(0,s.hasParentOfType)(e,exports.Store)?(0,s.getParentOfType)(e,exports.Store):null}})).actions(e=>({toJSON:()=>Object.assign({},(0,s.getSnapshot)(e))})).actions(e=>({clone(t={}){const o=e.toJSON();return t.id=t.id||(0,r.nanoid)(10),y(o,e=>{e.id=(0,r.nanoid)(10)}),Object.assign(o,t),e.page.addElement(o)},set(t){Object.assign(e,t)},moveUp(){e.page.moveElementsUp([e.id])},moveTop(){e.page.moveElementsTop([e.id])},moveDown(){e.page.moveElementsDown([e.id])},moveBottom(){e.page.moveElementsBottom([e.id])},beforeDestroy(){e.store.history.endTransaction()}})),exports.Element=exports.Node.named("Element").props({x:0,y:0,width:100,height:100,rotation:0,opacity:1,blurEnabled:!1,blurRadius:10,brightnessEnabled:!1,brightness:0,sepiaEnabled:!1,grayscaleEnabled:!1,shadowEnabled:!1,shadowBlur:5,shadowOffsetX:0,shadowOffsetY:0,shadowColor:"black",shadowOpacity:1,visible:!0,draggable:!0,resizable:!0,selectable:!0,contentEditable:!0,styleEditable:!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),e.locked&&(t.draggable=!1,t.contentEditable=!1,t.styleEditable=!1,t.resizable=!1),t}).views(e=>({get a(){return e},animated:t=>e[t]})),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:0,verticalAlign:"top",strokeWidth:0,stroke:"black",lineHeight:s.types.optional(s.types.union(s.types.number,s.types.string),1.2),letterSpacing:0,_editModeEnabled:!1,backgroundEnabled:!1,backgroundColor:"#7ED321",backgroundOpacity:1,backgroundCornerRadius:.5,backgroundPadding:.5}).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,keepRatio:!1,_cropModeEnabled:!1}).actions(e=>({toggleCropMode(t){e._cropModeEnabled=null!=t?t:!e._cropModeEnabled,e._cropModeEnabled?e.store.history.startTransaction():e.store.history.endTransaction()}})),exports.LineElement=exports.Element.named("Line").props({type:"line",width:400,height:10,color:"black",dash:s.types.array(s.types.number),startHead:"",endHead:""}).actions(e=>({})),exports.SVGElement=exports.Element.named("SVG").props({type:"svg",src:"",maskSrc:"",cropX:0,cropY:0,cropWidth:1,cropHeight:1,keepRatio:!0,flipX:!1,flipY:!1,width:100,height:100,borderColor:"black",borderSize:0,cornerRadius:0,colorsReplace:s.types.map(s.types.string)}).preProcessSnapshot(e=>Object.assign(Object.assign({},e),{src:e.src||e.svgSource})).actions(e=>({replaceColor(t,o){e.colorsReplace.set(t,o)}}));const E=[];function x(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);O[t]=o,E.push(o)}exports.registerShapeModel=x;const w=[...new Array(20)].map((e,t)=>s.types.late(()=>E[t])),v=s.types.union({dispatcher:e=>{const t=O[e.type];if(!t)throw new Error(`Unknown element type: "${e.type}"`);return t}},exports.SVGElement,exports.TextElement,exports.ImageElement,exports.LineElement,s.types.late(()=>exports.GroupElement),...w);exports.GroupElement=exports.Node.named("Group").props({type:"group",children:s.types.array(v)}).views(e=>({get draggable(){let t=!0;return y(e,e=>{e.draggable||(t=!1)}),t},get resizable(){let t=!0;return y(e,e=>{e.resizable||(t=!1)}),t},get contentEditable(){let t=!0;return y(e,e=>{e.contentEditable||(t=!1)}),t},get styleEditable(){let t=!0;return y(e,e=>{e.styleEditable||(t=!1)}),t},get locked(){let t=!0;return y(e,e=>{e.locked||(t=!1)}),t}})).actions(e=>({set(t){var{draggable:o,contentEditable:i,styleEditable:s,resizable:a}=t,r=n(t,["draggable","contentEditable","styleEditable","resizable"]);void 0!==o&&y(e,e=>{e.set({draggable:o})}),void 0!==i&&y(e,e=>{e.set({contentEditable:i})}),void 0!==s&&y(e,e=>{e.set({styleEditable:s})}),void 0!==a&&y(e,e=>{e.set({resizable:a})}),Object.assign(e,r)}}));const O={svg:exports.SVGElement,text:exports.TextElement,image:exports.ImageElement,group:exports.GroupElement,line:exports.LineElement};function P({key:e,showCredit:t}={key:"",showCredit:!1}){const o=exports.Store.create();return(0,p.validateKey)(e,t),o}exports.Page=s.types.model("Page",{id:s.types.identifier,children:s.types.array(v),width:s.types.optional(s.types.union(s.types.number,s.types.literal("auto")),"auto"),height:s.types.optional(s.types.union(s.types.number,s.types.literal("auto")),"auto"),background:"white",bleed:0,custom:s.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,s.getParentOfType)(e,exports.Store)},get animatedChildren(){}})).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,s.getSnapshot)(e))),_forEachElementUp(t,o){const n=t.map(t=>({id:t,index:e.children.findIndex(e=>e.id===t)}));n.sort((e,t)=>t.index-e.index);for(const{index:i}of n){if(-1==i)continue;const n=i<e.children.length-1&&e.children[i+1],s=t.indexOf(null==n?void 0:n.id)>=0;i===e.children.length-1||s||o(i)}},_forEachElementDown(t,o){const n=t.map(t=>({id:t,index:e.children.findIndex(e=>e.id===t)}));n.sort((e,t)=>e.index-t.index);for(const{index:i}of n){if(-1==i)continue;const n=i>0&&e.children[i-1],s=t.indexOf(null==n?void 0:n.id)>=0;0===i||s||o(i)}return!1}})).actions(e=>({clone(t={}){const o=e.toJSON();o.children.forEach(e=>{e.id=(0,r.nanoid)(10),y(e,e=>{e.id=(0,r.nanoid)(10)})});const n=Object.assign(Object.assign(Object.assign({},o),{id:(0,r.nanoid)(10)}),t),i=e.store.addPage(n),s=e.store.pages.indexOf(e);i.setZIndex(s+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 o=O[t.type];if(!o)return void console.error("Can not find model with type "+t.type);t.children&&t.children.forEach(e=>{e.id=(0,r.nanoid)(10)});const n=o.create(Object.assign({id:(0,r.nanoid)(10)},t));return e.children.push(n),n.selectable&&e.store.selectElements([n.id]),n},canMoveElementsUp(t){let o=!1;return e._forEachElementUp(t,()=>{o=o||!0}),o},moveElementsUp(t){e._forEachElementUp(t,t=>{const o=e.children[t];(0,s.detach)(o),e.children.splice(t+1,0,o)})},canMoveElementsTop(e){return this.canMoveElementsUp(e)},moveElementsTop(t){const o=[],n=[];e.children.forEach(e=>{t.indexOf(e.id)>=0?o.push(e):n.push(e)}),e.children.replace(n.concat(o))},canMoveElementsDown(t){let o=!1;return e._forEachElementDown(t,()=>{o=o||!0}),o},moveElementsDown(t){e._forEachElementDown(t,t=>{const o=e.children[t];(0,s.detach)(o),e.children.splice(t-1,0,o)})},canMoveElementsBottom(e){return this.canMoveElementsDown(e)},moveElementsBottom(t){const o=[],n=[];e.children.forEach(e=>{t.indexOf(e.id)>=0?o.push(e):n.push(e)}),e.children.replace(o.concat(n))},setElementZIndex(t,o){const n=e.children.find(e=>e.id===t);n&&((0,s.detach)(n),e.children.remove(n),e.children.splice(o,0,n))},setSize({width:t,height:o,useMagic:n,softChange:i}){if(n){const n=t/e.computedWidth,i=o/e.computedHeight;for(const t of e.children)t.set({x:t.x*n,y:t.y*i}),"text"===t.type?t.set({fontSize:t.fontSize*n,width:Math.max(t.width*n,2)}):"image"===t.type?t.set({width:t.width*n,height:t.height*i}):"svg"===t.type&&t.set({width:Math.max(t.width*n,2),height:Math.max(t.height*n,2)})}"auto"!==e.width||i||(e.width=t),"auto"!==e.height||i||(e.height=o)}})).actions(e=>({moveElementUp(t){console.warn("page.moveElementUp(id) is deprecated. Please use page.moveElementsUp([id1, id2]) instead."),e.moveElementsUp([t])},moveElementDown(t){console.warn("page.moveElementDown(id) is deprecated. Please use page.moveElementsDown([id1, id2]) instead."),e.moveElementsDown([t])},moveElementTop(t){console.warn("page.moveElementTop(id) is deprecated. Please use page.moveElementsTop([id1, id2]) instead."),e.moveElementsTop([t])},moveElementBottom(t){console.warn("page.moveElementBottom(id) is deprecated. Please use page.moveElementsBottom([id1, id2]) instead."),e.moveElementsBottom([t])}})),exports.Font=s.types.model("Font",{fontFamily:s.types.string,url:s.types.optional(s.types.string,""),styles:s.types.frozen()}).preProcessSnapshot(e=>Object.assign(Object.assign({},e),{fontFamily:e.fontFamily||e.name})),exports.Store=s.types.model("Store",{role:"",pages:s.types.array(exports.Page),fonts:s.types.array(exports.Font),width:1080,height:1080,currentTime:0,scale:1,scaleToFit:1,unit:"px",dpi:72,bleedVisible:!1,rulesVisible:!1,openedSidePanel:"",selectedElementsIds:s.types.array(s.types.string),history:s.types.optional(a.UndoManager,{targetPath:"../pages"}),_elementsPixelRatio:2,_activePageId:""}).views(e=>({get _bleedVisible(){return console.warn("store._bleedVisible is deprecated. Please use store.bleedVisible instead."),e.bleedVisible},get selectedElements(){return e.selectedElementsIds.map(t=>{for(const o of e.pages)for(const e of o.children)if(e.id===t)return e}).filter(e=>!!e)},get selectedShapes(){const t=[];return e.selectedElementsIds.forEach(o=>{for(const n of e.pages)for(const e of n.children)e.id===o&&"group"!==e.type&&t.push(e),"group"===e.type&&e.id===o&&t.push(...e.children)}),t},get activePage(){return e.pages.slice().find(t=>t.id===e._activePageId)||(e.pages.length?e.pages[0]:null)}})).actions(e=>({afterCreate(){e.history.canUndo},setCurrentTime(t){e.currentTime=t},setUnit({unit:t,dpi:o}){e.unit=t||e.unit,e.dpi=o||e.dpi},setRole(t){e.role=t},find(t){let o;return y({children:e.pages},e=>{!o&&t(e)&&(o=e)}),o},getElementById:t=>e.find(e=>e.id===t),addPage(t){const o=exports.Page.create(Object.assign({id:(0,r.nanoid)(10)},t));return e.pages.push(o),e._activePageId=o.id,o},selectPage(t){e._activePageId=t},selectElements(t){const o=t.map(t=>e.getElementById(t)).sort((e,t)=>e.page.children.indexOf(e)-e.page.children.indexOf(t)).filter(e=>!!e).map(e=>e.id);e.selectedElementsIds=(0,s.cast)(o)},toggleBleed(t){e.bleedVisible=null!=t?t:!e.bleedVisible},toggleRulers(t){e.rulesVisible=null!=t?t:!e.rulesVisible},openSidePanel(t){e.openedSidePanel=t},setScale(t){e.scale=t},_setScaleToFit(t){e.scaleToFit=t},setElementsPixelRatio(t){e._elementsPixelRatio=t},setSize(t,o,n){e.pages.forEach(e=>{e.setSize({width:t,height:o,useMagic:n,softChange:!0})}),e.width=t,e.height=o},setPageZIndex(t,o){const n=e.pages.find(e=>e.id===t);n&&((0,s.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,s.destroy)(o)});const n=Math.min(e.pages.length-1,o),i=e.pages[n];i&&(e._activePageId=i.id),e.selectedElementsIds=(0,s.cast)(e.selectedElementsIds.filter(t=>e.getElementById(t)))},groupElements(t){const o=t.map(t=>e.getElementById(t));o.forEach(e=>{e&&(0,s.detach)(e)});const n=e.activePage,i=exports.GroupElement.create({id:(0,r.nanoid)(10),children:(0,s.cast)(o)});return n.children.push(i),e.selectedElementsIds=(0,s.cast)([i.id]),i},ungroupElements(t){const o=t.map(t=>e.getElementById(t)),n=[];o.forEach(e=>{if(e&&"group"===e.type){const t=e.page,o=t.children.indexOf(e);e.children.forEach(e=>{n.push(e.id)}),e.children.forEach(e=>{(0,s.detach)(e),t.children.push(e)}),t.children.splice(o,1)}}),e.selectedElementsIds=(0,s.cast)(n)},deleteElements(t){t.forEach(t=>{e.pages.forEach(e=>{const o=e.children.find(e=>e.id===t);o&&(0,s.destroy)(o)})}),e.selectedElementsIds=(0,s.cast)(e.selectedElementsIds.filter(t=>e.getElementById(t)))},on(t,o){if("change"===t){let t=e.toJSON();return(0,s.onSnapshot)(e,n=>{const i=e.toJSON();!(0,m.deepEqual)(t,i)&&(t=i,o(i))})}},async _toCanvas({pixelRatio:t,ignoreBackground:o,pageId:n,mimeType:i,includeBleed:s}={}){var a;const r=t||1;n=n||(null===(a=e.pages[0])||void 0===a?void 0:a.id);const d=e.pages.find(e=>e.id===n);if(!d)throw new Error(`No page for export with id ${n}`);null==d||d.set({_exporting:!0});const c=await(0,f.waitTillAvailable)(()=>l.default.stages.find(e=>e.getAttr("pageId")===n));if(!c)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.`);await e.waitLoading();const p=c.findOne(".page-container");c.find("Transformer").forEach(e=>e.visible(!1)),p.find(".page-background").forEach(e=>e.shadowEnabled(!1)),p.find(".page-background").forEach(e=>e.strokeEnabled(!1)),p.find(".highlighter").forEach(e=>e.visible(!1));const g=p.findOne(".page-background-group"),h=g.clip();g.clip({x:null,y:null,width:null,height:null});const u=p.findOne(".elements-container"),m=u.clip();u.clip({x:null,y:null,width:null,height:null});const b=p.find(e=>e.getAttr("hideInExport"));b.forEach(e=>{e.setAttr("oldVisible",e.visible()),e.hide()});const y=p.find(e=>!e.visible()&&e.getAttr("editModeEnabled"));y.forEach(e=>{e.setAttr("oldVisible",e.visible()),e.show()}),o&&p.find(".page-background").forEach(e=>e.hide());const E=s?d.bleed:0;let x=E;e.bleedVisible&&s?x=0:e.bleedVisible&&!s&&(x=-d.bleed);const w=document.createElement("canvas");w.width=(d.computedWidth+2*E)*r,w.height=(d.computedHeight+2*E)*r;const v=w.getContext("2d");"image/jpeg"===i&&(v.fillStyle="white",v.fillRect(0,0,w.width,w.height));const O=p.toCanvas({x:p.x()-x*p.scaleX(),y:p.y()-x*p.scaleY(),width:(d.computedWidth+2*E)*p.scaleX(),height:(d.computedHeight+2*E)*p.scaleY(),pixelRatio:1/p.scaleX()*r});return v.drawImage(O,0,0),l.default.Util.releaseCanvas(O),o&&p.find(".page-background").forEach(e=>e.show()),b.forEach(e=>{e.visible(e.getAttr("oldVisible"))}),y.forEach(e=>{e.visible(e.getAttr("oldVisible"))}),p.find(".page-background").forEach(e=>e.shadowEnabled(!0)),p.find(".page-background").forEach(e=>e.strokeEnabled(!0)),c.find("Transformer").forEach(e=>e.visible(!0)),p.find(".highlighter").forEach(e=>e.visible(!0)),g.clip(h),u.clip(m),null==d||d.set({_exporting:!1}),w},async toDataURL({pixelRatio:t,ignoreBackground:o,pageId:n,mimeType:i,includeBleed:s,quality:a}={}){const r=await e._toCanvas({pixelRatio:t,ignoreBackground:o,pageId:n,mimeType:i,includeBleed:s}),d=r.toDataURL(i,a);return l.default.Util.releaseCanvas(r),d},async toBlob({pixelRatio:t,ignoreBackground:o,pageId:n,mimeType:i,includeBleed:s,quality:a}={}){const r=await e._toCanvas({pixelRatio:t,ignoreBackground:o,pageId:n,mimeType:i,includeBleed:s}),d=new Promise(e=>{r.toBlob(e,i,a)});return l.default.Util.releaseCanvas(r),d},async saveAsImage(t={}){var{fileName:o}=t,i=n(t,["fileName"]);const s=i.mimeType||"image/png",a=s.split("/")[1];(0,d.downloadFile)(await e.toDataURL(i),o||"polotno."+a,s)},async _toPDF(t){const o=t.dpi||e.dpi,n=t.parallel||1,i=t.unit||("px"===e.unit?"mm":e.unit),s=t.pixelRatio||1,a=t.pageIds||e.pages.map(e=>e.id),r=e.pages.filter(e=>a.includes(e.id)),l=await(0,c.getJsPDF)(),d=e=>(0,u.pxToUnit)({px:e,unit:i,dpi:o}),p=r[0]||{},g=t.includeBleed?p.bleed:0,h=d(p.computedWidth+2*g),m=d(p.computedHeight+2*g);var f=new l({unit:i,orientation:h>m?"landscape":"portrait",format:[h,m],compress:!0,putOnlyUsedFonts:!0});f.deletePage(1);const b=e._elementsPixelRatio;e.setElementsPixelRatio(s),await new Promise(e=>setTimeout(e));const y=((e,t)=>{for(var o=[],n=0;n<e.length;n+=t)o.push(e.slice(n,n+t));return o})(r,n);for(const c of y){const o=c.map(async o=>{const n=t.includeBleed?o.bleed:0,i=d(o.computedWidth+2*n),a=d(o.computedHeight+2*n);let r=0,l=s;for(;r<10;){2===(r+=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:l}));if(n.length>20)return{url:n,width:i,height:a};l*=.8}});(await Promise.all(o)).forEach(({url:e,width:t,height:o})=>{f.addPage([t,o],t>o?"landscape":"portrait"),f.addImage(e,0,0,t,o,void 0,"FAST")})}return e.setElementsPixelRatio(b),f},toPDFDataURL:async t=>(await e._toPDF(Object.assign({mimeType:"image/jpeg"},t))).output("datauristring"),async toHTML(){const t=e.toJSON();return(0,b.jsonToHTML)({json:t})},async saveAsHTML({filename:t}={}){const o=await e.toHTML(),n="data:text/html;base64,"+window.btoa(unescape(encodeURIComponent(o)));(0,d.downloadFile)(n,t||"polotno.html")},async saveAsPDF(t={}){var{fileName:o}=t,i=n(t,["fileName"]);(await e._toPDF(Object.assign({mimeType:"image/jpeg"},i))).save(o||"polotno.pdf")},async waitLoading(){await new Promise(e=>setTimeout(e,50)),await(0,h.whenLoaded)()},toJSON:()=>({width:e.width,height:e.height,fonts:(0,s.getSnapshot)(e.fonts),pages:(0,s.getSnapshot)(e.pages),unit:e.unit,dpi:e.dpi}),loadJSON(t,o=!1){var n;const i=Object.assign({},t),a=e.pages.indexOf(e.activePage);let r=null===(n=i.pages[a]||i.pages[0])||void 0===n?void 0:n.id;i._activePageId=r;const l=Object.assign({},(0,s.getSnapshot)(e));Object.assign(l,i),l.history=o?e.history.toJSON():{history:[],undoIdx:-1},(0,s.applySnapshot)(e,l)},addFont(t){e.removeFont(t.fontFamily),e.fonts.push(t),e.loadFont(t.fontFamily)},removeFont(t){e.fonts.filter(e=>e.fontFamily===t).forEach(e=>(0,s.destroy)(e))},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=P,exports.default=P;
|
|
3285
|
+
"use strict";var e=this&&this.__createBinding||(Object.create?function(e,t,n,o){void 0===o&&(o=n);var i=Object.getOwnPropertyDescriptor(t,n);i&&!("get"in i?!t.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,o,i)}:function(e,t,n,o){void 0===o&&(o=n),e[o]=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 o={};if(null!=n)for(var i in n)"default"!==i&&Object.prototype.hasOwnProperty.call(n,i)&&e(o,n,i);return t(o,n),o},o=this&&this.__rest||function(e,t){var n={};for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&t.indexOf(o)<0&&(n[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(o=Object.getOwnPropertySymbols(e);i<o.length;i++)t.indexOf(o[i])<0&&Object.prototype.propertyIsEnumerable.call(e,o[i])&&(n[o[i]]=e[o[i]])}return n},i=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.GroupElement=exports.registerShapeModel=exports.SVGElement=exports.LineElement=exports.VideoElement=exports.ImageElement=exports.TextElement=exports.Element=exports.Node=void 0;const s=require("mobx-state-tree"),a=require("./history"),r=require("nanoid"),l=i(require("konva")),d=require("../utils/download"),c=require("../utils/pdf"),p=require("../utils/validate-key"),g=n(require("../utils/fonts")),h=require("../utils/loader"),m=require("../utils/unit"),u=require("../utils/deep-equal"),f=require("../utils/wait"),y=require("../utils/html");(0,s.setLivelinessChecking)("ignore");const E=(e,t)=>{e.children&&e.children.forEach(e=>{t(e),E(e,t)})};exports.Node=s.types.model("Node",{id:s.types.identifier,type:"none",name:"",opacity:1,animations:s.types.array(s.types.frozen()),custom:s.types.frozen(),visible:!0,selectable:!0,removable:!0,alwaysOnTop:!1,showInExport:!0}).postProcessSnapshot(e=>{const t=Object.assign({},e),n={};for(var o in t)"_"!==o[0]&&(n[o]=e[o]);return n}).views(e=>({get locked(){return!(e.draggable||e.contentEditable||e.styleEditable||e.resizable)},get page(){return(0,s.getParentOfType)(e,exports.Page)},get store(){return(0,s.getParentOfType)(e,exports.Store)},get top(){let t=e;for(;;){if(!(0,s.hasParentOfType)(t,exports.GroupElement))return t;t=(0,s.getParentOfType)(t,exports.GroupElement)}},get parent(){return(0,s.hasParentOfType)(e,exports.GroupElement)?(0,s.getParentOfType)(e,exports.GroupElement):(0,s.hasParentOfType)(e,exports.Page)?(0,s.getParentOfType)(e,exports.Page):(0,s.hasParentOfType)(e,exports.Store)?(0,s.getParentOfType)(e,exports.Store):null}})).actions(e=>({toJSON:()=>Object.assign({},(0,s.getSnapshot)(e))})).actions(e=>({clone(t={}){const n=e.toJSON();return t.id=t.id||(0,r.nanoid)(10),E(n,e=>{e.id=(0,r.nanoid)(10)}),Object.assign(n,t),e.page.addElement(n)},set(t){Object.assign(e,t)},moveUp(){e.page.moveElementsUp([e.id])},moveTop(){e.page.moveElementsTop([e.id])},moveDown(){e.page.moveElementsDown([e.id])},moveBottom(){e.page.moveElementsBottom([e.id])},beforeDestroy(){e.store.history.endTransaction()}})),exports.Element=exports.Node.named("Element").props({x:0,y:0,width:100,height:100,rotation:0,opacity:1,blurEnabled:!1,blurRadius:10,brightnessEnabled:!1,brightness:0,sepiaEnabled:!1,grayscaleEnabled:!1,shadowEnabled:!1,shadowBlur:5,shadowOffsetX:0,shadowOffsetY:0,shadowColor:"black",shadowOpacity:1,visible:!0,draggable:!0,resizable:!0,selectable:!0,contentEditable:!0,styleEditable:!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),e.locked&&(t.draggable=!1,t.contentEditable=!1,t.styleEditable=!1,t.resizable=!1),t}).views(e=>({get a(){return e},animated:t=>e[t]})),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:0,verticalAlign:"top",strokeWidth:0,stroke:"black",lineHeight:s.types.optional(s.types.union(s.types.number,s.types.string),1.2),letterSpacing:0,_editModeEnabled:!1,backgroundEnabled:!1,backgroundColor:"#7ED321",backgroundOpacity:1,backgroundCornerRadius:.5,backgroundPadding:.5}).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,keepRatio:!1,_cropModeEnabled:!1}).actions(e=>({toggleCropMode(t){e._cropModeEnabled=null!=t?t:!e._cropModeEnabled,e._cropModeEnabled?e.store.history.startTransaction():e.store.history.endTransaction()}})),exports.VideoElement=exports.ImageElement.named("Video").props({type:"video",duration:0}),exports.LineElement=exports.Element.named("Line").props({type:"line",width:400,height:10,color:"black",dash:s.types.array(s.types.number),startHead:"",endHead:""}).actions(e=>({})),exports.SVGElement=exports.Element.named("SVG").props({type:"svg",src:"",maskSrc:"",cropX:0,cropY:0,cropWidth:1,cropHeight:1,keepRatio:!0,flipX:!1,flipY:!1,width:100,height:100,borderColor:"black",borderSize:0,cornerRadius:0,colorsReplace:s.types.map(s.types.string)}).preProcessSnapshot(e=>Object.assign(Object.assign({},e),{src:e.src||e.svgSource})).actions(e=>({replaceColor(t,n){e.colorsReplace.set(t,n)}}));const b=[];function x(e){const t=e.type;if(!t)throw new Error('You must pass "type" attribute to custom model.');const n=exports.Element.named(t).props(e);O[t]=n,b.push(n)}exports.registerShapeModel=x;const w=[...new Array(20)].map((e,t)=>s.types.late(()=>b[t])),v=s.types.union({dispatcher:e=>{const t=O[e.type];if(!t)throw new Error(`Unknown element type: "${e.type}"`);return t}},exports.SVGElement,exports.TextElement,exports.ImageElement,exports.LineElement,exports.VideoElement,s.types.late(()=>exports.GroupElement),...w);exports.GroupElement=exports.Node.named("Group").props({type:"group",children:s.types.array(v)}).views(e=>({get draggable(){let t=!0;return E(e,e=>{e.draggable||(t=!1)}),t},get resizable(){let t=!0;return E(e,e=>{e.resizable||(t=!1)}),t},get contentEditable(){let t=!0;return E(e,e=>{e.contentEditable||(t=!1)}),t},get styleEditable(){let t=!0;return E(e,e=>{e.styleEditable||(t=!1)}),t},get locked(){let t=!0;return E(e,e=>{e.locked||(t=!1)}),t}})).actions(e=>({set(t){var{draggable:n,contentEditable:i,styleEditable:s,resizable:a}=t,r=o(t,["draggable","contentEditable","styleEditable","resizable"]);void 0!==n&&E(e,e=>{e.set({draggable:n})}),void 0!==i&&E(e,e=>{e.set({contentEditable:i})}),void 0!==s&&E(e,e=>{e.set({styleEditable:s})}),void 0!==a&&E(e,e=>{e.set({resizable:a})}),Object.assign(e,r)}}));const O={svg:exports.SVGElement,text:exports.TextElement,image:exports.ImageElement,group:exports.GroupElement,line:exports.LineElement,video:exports.VideoElement};function P({key:e,showCredit:t}={key:"",showCredit:!1}){const n=exports.Store.create();return(0,p.validateKey)(e,t),n}exports.Page=s.types.model("Page",{id:s.types.identifier,children:s.types.array(v),width:s.types.optional(s.types.union(s.types.number,s.types.literal("auto")),"auto"),height:s.types.optional(s.types.union(s.types.number,s.types.literal("auto")),"auto"),background:"white",bleed:0,custom:s.types.frozen(),_exporting:!1}).postProcessSnapshot(e=>{const t=Object.assign({},e),n={};for(var o in t)"_"!==o[0]&&(n[o]=e[o]);return n}).views(e=>({get store(){return(0,s.getParentOfType)(e,exports.Store)},get animatedChildren(){}})).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,s.getSnapshot)(e))),_forEachElementUp(t,n){const o=t.map(t=>({id:t,index:e.children.findIndex(e=>e.id===t)}));o.sort((e,t)=>t.index-e.index);for(const{index:i}of o){if(-1==i)continue;const o=i<e.children.length-1&&e.children[i+1],s=t.indexOf(null==o?void 0:o.id)>=0;i===e.children.length-1||s||n(i)}},_forEachElementDown(t,n){const o=t.map(t=>({id:t,index:e.children.findIndex(e=>e.id===t)}));o.sort((e,t)=>e.index-t.index);for(const{index:i}of o){if(-1==i)continue;const o=i>0&&e.children[i-1],s=t.indexOf(null==o?void 0:o.id)>=0;0===i||s||n(i)}return!1}})).actions(e=>({clone(t={}){const n=e.toJSON();n.children.forEach(e=>{e.id=(0,r.nanoid)(10),E(e,e=>{e.id=(0,r.nanoid)(10)})});const o=Object.assign(Object.assign(Object.assign({},n),{id:(0,r.nanoid)(10)}),t),i=e.store.addPage(o),s=e.store.pages.indexOf(e);i.setZIndex(s+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=O[t.type];if(!n)return void console.error("Can not find model with type "+t.type);t.children&&t.children.forEach(e=>{e.id=(0,r.nanoid)(10)});const o=n.create(Object.assign({id:(0,r.nanoid)(10)},t));return e.children.push(o),o.selectable&&e.store.selectElements([o.id]),o},canMoveElementsUp(t){let n=!1;return e._forEachElementUp(t,()=>{n=n||!0}),n},moveElementsUp(t){e._forEachElementUp(t,t=>{const n=e.children[t];(0,s.detach)(n),e.children.splice(t+1,0,n)})},canMoveElementsTop(e){return this.canMoveElementsUp(e)},moveElementsTop(t){const n=[],o=[];e.children.forEach(e=>{t.indexOf(e.id)>=0?n.push(e):o.push(e)}),e.children.replace(o.concat(n))},canMoveElementsDown(t){let n=!1;return e._forEachElementDown(t,()=>{n=n||!0}),n},moveElementsDown(t){e._forEachElementDown(t,t=>{const n=e.children[t];(0,s.detach)(n),e.children.splice(t-1,0,n)})},canMoveElementsBottom(e){return this.canMoveElementsDown(e)},moveElementsBottom(t){const n=[],o=[];e.children.forEach(e=>{t.indexOf(e.id)>=0?n.push(e):o.push(e)}),e.children.replace(n.concat(o))},setElementZIndex(t,n){const o=e.children.find(e=>e.id===t);o&&((0,s.detach)(o),e.children.remove(o),e.children.splice(n,0,o))},setSize({width:t,height:n,useMagic:o,softChange:i}){if(o){const o=t/e.computedWidth,i=n/e.computedHeight;for(const t of e.children)t.set({x:t.x*o,y:t.y*i}),"text"===t.type?t.set({fontSize:t.fontSize*o,width:Math.max(t.width*o,2)}):"image"===t.type?t.set({width:t.width*o,height:t.height*i}):"svg"===t.type&&t.set({width:Math.max(t.width*o,2),height:Math.max(t.height*o,2)})}"auto"!==e.width||i||(e.width=t),"auto"!==e.height||i||(e.height=n)}})).actions(e=>({moveElementUp(t){console.warn("page.moveElementUp(id) is deprecated. Please use page.moveElementsUp([id1, id2]) instead."),e.moveElementsUp([t])},moveElementDown(t){console.warn("page.moveElementDown(id) is deprecated. Please use page.moveElementsDown([id1, id2]) instead."),e.moveElementsDown([t])},moveElementTop(t){console.warn("page.moveElementTop(id) is deprecated. Please use page.moveElementsTop([id1, id2]) instead."),e.moveElementsTop([t])},moveElementBottom(t){console.warn("page.moveElementBottom(id) is deprecated. Please use page.moveElementsBottom([id1, id2]) instead."),e.moveElementsBottom([t])}})),exports.Font=s.types.model("Font",{fontFamily:s.types.string,url:s.types.optional(s.types.string,""),styles:s.types.frozen()}).preProcessSnapshot(e=>Object.assign(Object.assign({},e),{fontFamily:e.fontFamily||e.name})),exports.Store=s.types.model("Store",{role:"",pages:s.types.array(exports.Page),fonts:s.types.array(exports.Font),width:1080,height:1080,currentTime:0,isPlaying:!1,scale:1,scaleToFit:1,unit:"px",dpi:72,bleedVisible:!1,rulesVisible:!1,openedSidePanel:"",selectedElementsIds:s.types.array(s.types.string),history:s.types.optional(a.UndoManager,{targetPath:"../pages"}),_elementsPixelRatio:2,_activePageId:""}).views(e=>({get _bleedVisible(){return console.warn("store._bleedVisible is deprecated. Please use store.bleedVisible instead."),e.bleedVisible},get selectedElements(){return e.selectedElementsIds.map(t=>{for(const n of e.pages)for(const e of n.children)if(e.id===t)return e}).filter(e=>!!e)},get children(){return e.pages},get selectedShapes(){const t=[];return e.selectedElementsIds.forEach(n=>{for(const o of e.pages)for(const e of o.children)e.id===n&&"group"!==e.type&&t.push(e),"group"===e.type&&e.id===n&&t.push(...e.children)}),t},get activePage(){return e.pages.slice().find(t=>t.id===e._activePageId)||(e.pages.length?e.pages[0]:null)},get duration(){let t=0;return E(e,e=>{"video"===e.type&&(t=Math.max(t,e.duration))}),t}})).actions(e=>({afterCreate(){e.history.canUndo},setCurrentTime(t){e.currentTime=t},play(){e.currentTime=0,e.isPlaying=!0,requestAnimationFrame(e.seek)},seek(){e.currentTime+=1e3/60,e.isPlaying&&e.currentTime<e.duration?requestAnimationFrame(e.seek):e.stop()},stop(){e.isPlaying=!1,e.currentTime=0},setUnit({unit:t,dpi:n}){e.unit=t||e.unit,e.dpi=n||e.dpi},setRole(t){e.role=t},find(t){let n;return E({children:e.pages},e=>{!n&&t(e)&&(n=e)}),n},getElementById:t=>e.find(e=>e.id===t),addPage(t){const n=exports.Page.create(Object.assign({id:(0,r.nanoid)(10)},t));return e.pages.push(n),e._activePageId=n.id,n},selectPage(t){e._activePageId=t},selectElements(t){const n=t.map(t=>e.getElementById(t)).sort((e,t)=>e.page.children.indexOf(e)-e.page.children.indexOf(t)).filter(e=>!!e).map(e=>e.id);e.selectedElementsIds=(0,s.cast)(n)},toggleBleed(t){e.bleedVisible=null!=t?t:!e.bleedVisible},toggleRulers(t){e.rulesVisible=null!=t?t:!e.rulesVisible},openSidePanel(t){e.openedSidePanel=t},setScale(t){e.scale=t},_setScaleToFit(t){e.scaleToFit=t},setElementsPixelRatio(t){e._elementsPixelRatio=t},setSize(t,n,o){e.pages.forEach(e=>{e.setSize({width:t,height:n,useMagic:o,softChange:!0})}),e.width=t,e.height=n},setPageZIndex(t,n){const o=e.pages.find(e=>e.id===t);o&&((0,s.detach)(o),e.pages.remove(o),e.pages.splice(n,0,o))},deletePages(t){const n=e.pages.indexOf(e.activePage);t.forEach(t=>{const n=e.pages.find(e=>e.id===t);(0,s.destroy)(n)});const o=Math.min(e.pages.length-1,n),i=e.pages[o];i&&(e._activePageId=i.id),e.selectedElementsIds=(0,s.cast)(e.selectedElementsIds.filter(t=>e.getElementById(t)))},groupElements(t){const n=t.map(t=>e.getElementById(t));n.forEach(e=>{e&&(0,s.detach)(e)});const o=e.activePage,i=exports.GroupElement.create({id:(0,r.nanoid)(10),children:(0,s.cast)(n)});return o.children.push(i),e.selectedElementsIds=(0,s.cast)([i.id]),i},ungroupElements(t){const n=t.map(t=>e.getElementById(t)),o=[];n.forEach(e=>{if(e&&"group"===e.type){const t=e.page,n=t.children.indexOf(e);e.children.forEach(e=>{o.push(e.id)}),e.children.forEach(e=>{(0,s.detach)(e),t.children.push(e)}),t.children.splice(n,1)}}),e.selectedElementsIds=(0,s.cast)(o)},deleteElements(t){t.forEach(t=>{e.pages.forEach(e=>{const n=e.children.find(e=>e.id===t);n&&(0,s.destroy)(n)})}),e.selectedElementsIds=(0,s.cast)(e.selectedElementsIds.filter(t=>e.getElementById(t)))},on(t,n){if("change"===t){let t=e.toJSON();return(0,s.onSnapshot)(e,o=>{const i=e.toJSON();!(0,u.deepEqual)(t,i)&&(t=i,n(i))})}},async _toCanvas({pixelRatio:t,ignoreBackground:n,pageId:o,mimeType:i,includeBleed:s}={}){var a;const r=t||1;o=o||(null===(a=e.pages[0])||void 0===a?void 0:a.id);const d=e.pages.find(e=>e.id===o);if(!d)throw new Error(`No page for export with id ${o}`);null==d||d.set({_exporting:!0});const c=await(0,f.waitTillAvailable)(()=>l.default.stages.find(e=>e.getAttr("pageId")===o));if(!c)throw new Error(`Export is failed. Can not find stage for page ${o}. Looks like <Workspace /> component is not mounted, but it is required in order to process the export.`);const p=!!c.findOne(".page-container");await e.waitLoading();const g=c.findOne(".page-container");if(!g)throw new Error(`Export is failed. Can't find page container. ${p}`);c.find("Transformer").forEach(e=>e.visible(!1)),g.find(".page-background").forEach(e=>e.shadowEnabled(!1)),g.find(".page-background").forEach(e=>e.strokeEnabled(!1)),g.find(".highlighter").forEach(e=>e.visible(!1));const h=g.findOne(".page-background-group"),m=h.clip();h.clip({x:null,y:null,width:null,height:null});const u=g.findOne(".elements-container"),y=u.clip();u.clip({x:null,y:null,width:null,height:null});const E=g.find(e=>e.getAttr("hideInExport"));E.forEach(e=>{e.setAttr("oldVisible",e.visible()),e.hide()});const b=g.find(e=>!e.visible()&&e.getAttr("editModeEnabled"));b.forEach(e=>{e.setAttr("oldVisible",e.visible()),e.show()}),n&&g.find(".page-background").forEach(e=>e.hide());const x=s?d.bleed:0;let w=x;e.bleedVisible&&s?w=0:e.bleedVisible&&!s&&(w=-d.bleed);const v=document.createElement("canvas");v.width=(d.computedWidth+2*x)*r,v.height=(d.computedHeight+2*x)*r;const O=v.getContext("2d");"image/jpeg"===i&&(O.fillStyle="white",O.fillRect(0,0,v.width,v.height));const P=g.toCanvas({x:g.x()-w*g.scaleX(),y:g.y()-w*g.scaleY(),width:(d.computedWidth+2*x)*g.scaleX(),height:(d.computedHeight+2*x)*g.scaleY(),pixelRatio:1/g.scaleX()*r});return O.drawImage(P,0,0),l.default.Util.releaseCanvas(P),n&&g.find(".page-background").forEach(e=>e.show()),E.forEach(e=>{e.visible(e.getAttr("oldVisible"))}),b.forEach(e=>{e.visible(e.getAttr("oldVisible"))}),g.find(".page-background").forEach(e=>e.shadowEnabled(!0)),g.find(".page-background").forEach(e=>e.strokeEnabled(!0)),c.find("Transformer").forEach(e=>e.visible(!0)),g.find(".highlighter").forEach(e=>e.visible(!0)),h.clip(m),u.clip(y),null==d||d.set({_exporting:!1}),v},async toDataURL({pixelRatio:t,ignoreBackground:n,pageId:o,mimeType:i,includeBleed:s,quality:a}={}){const r=await e._toCanvas({pixelRatio:t,ignoreBackground:n,pageId:o,mimeType:i,includeBleed:s}),d=r.toDataURL(i,a);return l.default.Util.releaseCanvas(r),d},async toBlob({pixelRatio:t,ignoreBackground:n,pageId:o,mimeType:i,includeBleed:s,quality:a}={}){const r=await e._toCanvas({pixelRatio:t,ignoreBackground:n,pageId:o,mimeType:i,includeBleed:s}),d=new Promise(e=>{r.toBlob(e,i,a)});return l.default.Util.releaseCanvas(r),d},async saveAsImage(t={}){var{fileName:n}=t,i=o(t,["fileName"]);const s=i.mimeType||"image/png",a=s.split("/")[1];(0,d.downloadFile)(await e.toDataURL(i),n||"polotno."+a,s)},async _toPDF(t){const n=t.dpi||e.dpi,o=t.parallel||1,i=t.unit||("px"===e.unit?"mm":e.unit),s=t.pixelRatio||1,a=t.pageIds||e.pages.map(e=>e.id),r=e.pages.filter(e=>a.includes(e.id)),l=await(0,c.getJsPDF)(),d=e=>(0,m.pxToUnit)({px:e,unit:i,dpi:n}),p=r[0]||{},g=t.includeBleed?p.bleed:0,h=d(p.computedWidth+2*g),u=d(p.computedHeight+2*g);var f=new l({unit:i,orientation:h>u?"landscape":"portrait",format:[h,u],compress:!0,putOnlyUsedFonts:!0});f.deletePage(1);const y=e._elementsPixelRatio;e.setElementsPixelRatio(s),await new Promise(e=>setTimeout(e));const E=((e,t)=>{for(var n=[],o=0;o<e.length;o+=t)n.push(e.slice(o,o+t));return n})(r,o);for(const c of E){const n=c.map(async n=>{const o=t.includeBleed?n.bleed:0,i=d(n.computedWidth+2*o),a=d(n.computedHeight+2*o);let r=0,l=s;for(;r<10;){2===(r+=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:n.id,pixelRatio:l}));if(o.length>20)return{url:o,width:i,height:a};l*=.8}});(await Promise.all(n)).forEach(({url:e,width:t,height:n})=>{f.addPage([t,n],t>n?"landscape":"portrait"),f.addImage(e,0,0,t,n,void 0,"FAST")})}return e.setElementsPixelRatio(y),f},toPDFDataURL:async t=>(await e._toPDF(Object.assign({mimeType:"image/jpeg"},t))).output("datauristring"),async toHTML(){const t=e.toJSON();return(0,y.jsonToHTML)({json:t})},async saveAsHTML({filename:t}={}){const n=await e.toHTML(),o="data:text/html;base64,"+window.btoa(unescape(encodeURIComponent(n)));(0,d.downloadFile)(o,t||"polotno.html")},async saveAsPDF(t={}){var{fileName:n}=t,i=o(t,["fileName"]);(await e._toPDF(Object.assign({mimeType:"image/jpeg"},i))).save(n||"polotno.pdf")},async waitLoading(){await new Promise(e=>setTimeout(e,50)),await(0,h.whenLoaded)()},toJSON:()=>({width:e.width,height:e.height,fonts:(0,s.getSnapshot)(e.fonts),pages:(0,s.getSnapshot)(e.pages),unit:e.unit,dpi:e.dpi}),loadJSON(t,n=!1){var o;const i=Object.assign({},t),a=e.pages.indexOf(e.activePage);let r=null===(o=i.pages[a]||i.pages[0])||void 0===o?void 0:o.id;i._activePageId=r;const l=Object.assign({},(0,s.getSnapshot)(e));Object.assign(l,i),l.history=n?e.history.toJSON():{history:[],undoIdx:-1},(0,s.applySnapshot)(e,l)},addFont(t){e.removeFont(t.fontFamily),e.fonts.push(t),e.loadFont(t.fontFamily)},removeFont(t){e.fonts.filter(e=>e.fontFamily===t).forEach(e=>(0,s.destroy)(e))},async loadFont(t){const n=e.fonts.find(e=>e.fontFamily===t)||g.globalFonts.find(e=>e.fontFamily===t);n?g.injectCustomFont(n):g.injectGoogleFont(t),await g.loadFont(t)}})),exports.createStore=P,exports.default=P;
|
|
3284
3286
|
},{"mobx-state-tree":"pk4v","./history":"X9z9","nanoid":"iDyL","konva":"aTGn","../utils/download":"HWHW","../utils/pdf":"sptl","../utils/validate-key":"zree","../utils/fonts":"XXLd","../utils/loader":"bN4e","../utils/unit":"BUt3","../utils/deep-equal":"lHx4","../utils/wait":"uddG","../utils/html":"YsBD"}],"oiQN":[function(require,module,exports) {
|
|
3285
3287
|
"use strict";async function e(e){return new Promise((o,r)=>{const t=new FileReader;t.readAsDataURL(e),t.onload=(()=>o(t.result)),t.onerror=(e=>r(e))})}Object.defineProperty(exports,"__esModule",{value:!0}),exports.localFileToURL=void 0,exports.localFileToURL=e;
|
|
3286
3288
|
},{}],"Tz78":[function(require,module,exports) {
|
|
@@ -4189,7 +4191,7 @@ var r=require("../lib").GenIcon;module.exports=function(t){return r({tag:"svg",a
|
|
|
4189
4191
|
.bp4-dark & {
|
|
4190
4192
|
filter: invert(1);
|
|
4191
4193
|
}
|
|
4192
|
-
`,
|
|
4194
|
+
`,b=(0,a.getFontsList)(),T=({fontFamily:e,handleClick:n,modifiers:o,store:i,isCustom:r})=>{t.default.useEffect(()=>{r&&i.loadFont(e)},[e,r]);const a=r?e:t.default.createElement(y,{src:(0,u.getGoogleFontImage)(e)});return t.default.createElement(l.MenuItem,{text:a,active:o.active,disabled:o.disabled,onClick:n,style:{fontFamily:'"'+e+'"'}})},q=({onChange:e,defaultValue:n})=>{const o=t.default.useRef(null);return t.default.useEffect(()=>{o.current&&o.current.focus()},[]),t.default.createElement(l.InputGroup,{leftIcon:"search",inputRef:o,defaultValue:n,onChange:t=>e(t.target.value)})},w=({store:e,fonts:n,activeFont:r,activeFontLabel:u,onFontSelect:c})=>{const[s,d]=t.default.useState(""),m=n.filter(e=>e.toLowerCase().indexOf(s.toLowerCase())>=0);return t.default.createElement(o.Popover2,{content:t.default.createElement("div",null,t.default.createElement(q,{onChange:e=>d(e),defaultValue:s}),t.default.createElement("div",{style:{paddingTop:"5px"}},t.default.createElement(i.FixedSizeList,{innerElementType:t.default.forwardRef((e,n)=>t.default.createElement(l.Menu,Object.assign({ref:n},e))),height:Math.min(400,30*m.length)+10,width:210,itemCount:m.length,itemSize:30,children:({index:n,style:l})=>{const o=m[n];return t.default.createElement("div",{style:l},t.default.createElement(T,{key:o,fontFamily:o,modifiers:{active:r===o},handleClick:()=>c(o),store:e,isCustom:e.fonts.find(e=>e.fontFamily===o)||a.globalFonts.find(e=>e.fontFamily===o)}))}})))},t.default.createElement(l.Button,{text:u,rightIcon:"caret-down",minimal:!0,style:{marginRight:"5px",fontFamily:'"'+r+'"',overflow:"hidden",whiteSpace:"nowrap",maxHeight:"30px"}}))};exports.FontFamilyInput=(0,n.observer)(({element:e,store:n})=>{const{data:l,mutate:o}=(0,r.default)((0,u.getGoogleFontsListAPI)(),c.fetcher,{isPaused:()=>(0,a.isGoogleFontChanged)(),fallbackData:[]});t.default.useEffect(()=>{o()},[(0,a.isGoogleFontChanged)()]);const i=n.fonts.concat(a.globalFonts).map(e=>e.fontFamily).concat((null==l?void 0:l.length)?l:b);let s=e.fontFamily;return s.length>15&&(s=e.fontFamily.slice(0,15)+"..."),t.default.createElement(w,{fonts:i,activeFont:e.fontFamily,activeFontLabel:s,store:n,onFontSelect:t=>{e.set({fontFamily:t})}})}),exports.FontSizeInput=(0,n.observer)(({element:e})=>t.default.createElement(l.NumericInput,{onValueChange:t=>{e.set({fontSize:t})},value:Math.round(e.fontSize),style:{width:"50px"},min:5}));const C=["left","center","right","justify"],I=["top","middle","bottom"],k={top:t.default.createElement("span",{className:"bp4-icon"},t.default.createElement(h.default,null)),middle:t.default.createElement("span",{className:"bp4-icon"},t.default.createElement(F.default,null)),bottom:t.default.createElement("span",{className:"bp4-icon"},t.default.createElement(v.default,null))};exports.FontStyleGroup=(0,n.observer)(({element:e,store:n})=>t.default.createElement(l.ButtonGroup,null,t.default.createElement(l.Button,{minimal:!0,icon:"align-"+e.align,onClick:()=>{const t=(C.indexOf(e.align)+1+C.length)%C.length,n=C[t];e.set({align:n})}}),E.flags.textVerticalResizeEnabled&&t.default.createElement(l.Button,{minimal:!0,icon:k[e.verticalAlign],onClick:()=>{const t=(I.indexOf(e.verticalAlign)+1+I.length)%I.length,l=I[t];n.history.transaction(()=>{e.set({verticalAlign:l})})}}),t.default.createElement(l.Button,{minimal:!0,icon:"bold",active:S.quillRef.currentFormat.bold||"bold"===e.fontWeight||"700"===e.fontWeight,onMouseDown:e=>{e.preventDefault()},onClick:t=>{const n=window.__polotnoQuill;if(n){const e=n.getSelection();n.formatText(e.index,e.length,"bold",!S.quillRef.currentFormat.bold,"user")}else"bold"===e.fontWeight||"700"===e.fontWeight?e.set({fontWeight:"normal"}):e.set({fontWeight:"bold"})}}),t.default.createElement(l.Button,{minimal:!0,icon:"italic",onMouseDown:e=>{e.preventDefault()},active:S.quillRef.currentFormat.italic||"italic"===e.fontStyle,onClick:()=>{const t=window.__polotnoQuill;if(t){const e=t.getSelection();t.formatText(e.index,e.length,"italic",!S.quillRef.currentFormat.italic,"user")}else"italic"===e.fontStyle?e.set({fontStyle:"normal"}):e.set({fontStyle:"italic"})}}),t.default.createElement(l.Button,{minimal:!0,icon:"underline",active:S.quillRef.currentFormat.underline||e.textDecoration.indexOf("underline")>=0,onMouseDown:e=>{e.preventDefault()},onClick:()=>{const t=window.__polotnoQuill;if(t){const e=t.getSelection();return void t.formatText(e.index,e.length,"underline",!S.quillRef.currentFormat.underline,"user")}let n=e.textDecoration.split(" ");n.indexOf("underline")>=0?n=n.filter(e=>"underline"!==e):n.push("underline"),e.set({textDecoration:n.join(" ")})}}),t.default.createElement(l.Button,{minimal:!0,icon:"strikethrough",active:S.quillRef.currentFormat.strike||e.textDecoration.indexOf("line-through")>=0,onMouseDown:e=>{e.preventDefault()},onClick:()=>{const t=window.__polotnoQuill;if(t){const e=t.getSelection();return void t.formatText(e.index,e.length,"strike",!S.quillRef.currentFormat.strike,"user")}let n=e.textDecoration.split(" ");n.indexOf("line-through")>=0?n=n.filter(e=>"line-through"!==e):n.push("line-through"),e.set({textDecoration:n.join(" ")})}}))),exports.FontColorInput=(0,n.observer)(({element:e,store:n})=>t.default.createElement(d.default,{value:S.quillRef.currentFormat.color||e.fill,onChange:t=>{const n=window.__polotnoQuill,l=null==n?void 0:n.getSelection(),o=(null==l?void 0:l.length)>=(null==n?void 0:n.getLength())-1;if(n&&!o&&(null==l?void 0:l.length))n.formatText(l.index,l.length,"color",t,"user");else{var i=e.text.replace(/style=".*?"/g,"");e.set({fill:t,text:i})}},store:n})),exports.SpacingInput=(0,n.observer)(({element:e})=>t.default.createElement(o.Popover2,{content:t.default.createElement("div",{style:{padding:"15px 25px",width:"200px"}},t.default.createElement("p",null,"Line height"),t.default.createElement(l.Slider,{value:"number"==typeof e.lineHeight?100*e.lineHeight:120,labelStepSize:50,onChange:t=>{e.set({lineHeight:t/100})},min:50,max:250,stepSize:10,showTrackFill:!0}),t.default.createElement("p",null,"Letter spacing"),t.default.createElement(l.Slider,{value:100*e.letterSpacing,labelStepSize:50,onChange:t=>{e.set({letterSpacing:t/100})},min:-50,max:250,stepSize:10,showTrackFill:!1})),position:l.Position.BOTTOM},t.default.createElement(l.Button,{icon:t.default.createElement(f.default,{className:"bp4-icon",style:{fontSize:"20px"}}),minimal:!0}))),exports.DirectionInput=(0,n.observer)(({element:e})=>{const n="rtl"===e.dir?p.default:x.default;return t.default.createElement(l.Button,{icon:t.default.createElement(n,{className:"bp4-icon",style:{fontSize:"20px"}}),minimal:!0,onClick:()=>{e.set({dir:"rtl"===e.dir?"ltr":"rtl"})}})});const D={TextFontFamily:exports.FontFamilyInput,TextFontSize:exports.FontSizeInput,TextFontVariant:exports.FontStyleGroup,TextFilters:m.default,TextFill:exports.FontColorInput,TextSpacing:exports.SpacingInput,TextDirection:exports.DirectionInput};exports.HtmlToolbar=(0,n.observer)(({store:e,hideTextFontFamily:n,hideTextEffects:l,hideTextSpacing:o,hideTextBold:i,hideTextItalic:r,hideTextUnderline:a,components:u})=>{const c=e.selectedElements[0],d=["TextFill",!n&&"TextFontFamily","TextFontSize","TextFontVariant",!o&&"TextSpacing",!l&&"TextFilters"].filter(e=>!!e),m=(0,s.extendToolbar)({type:"text",usedItems:d,components:u});return t.default.createElement(s.ElementContainer,{items:m,itemRender:n=>{const l=u[n]||D[n];return t.default.createElement(l,{element:c,store:e,key:n,hideTextBold:i,hideTextItalic:r,hideTextUnderline:a})}})});
|
|
4193
4195
|
},{"react":"HdMw","mobx-react-lite":"ZfSi","@blueprintjs/core":"Ydrz","@blueprintjs/popover2":"mZnF","react-window":"lmXC","swr":"kNI9","../utils/fonts":"XXLd","../utils/api":"Ic0q","../utils/use-api":"ZPqN","./element-container":"IPaf","./color-picker":"zFB1","./filters-picker":"dy0S","@meronex/icons/mdc/MdcFormatLineSpacing":"cXdM","@meronex/icons/md/MdFormatTextdirectionRToL":"oJPe","@meronex/icons/md/MdFormatTextdirectionLToR":"t9HB","../utils/styled":"PsiH","@meronex/icons/mdc/MdcFormatVerticalAlignTop":"hLKz","@meronex/icons/mdc/MdcFormatVerticalAlignCenter":"GYHp","@meronex/icons/mdc/MdcFormatVerticalAlignBottom":"HZV1","../utils/flags":"IDY9","../canvas/html-element":"BLZX"}],"ml2Z":[function(require,module,exports) {
|
|
4194
4196
|
"use strict";var e=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.FlipButton=void 0;const t=e(require("react")),o=require("@blueprintjs/core"),l=require("@blueprintjs/popover2"),r=require("../utils/l10n"),i=({element:e})=>t.default.createElement(l.Popover2,{content:t.default.createElement(o.Menu,null,t.default.createElement(o.MenuItem,{shouldDismissPopover:!1,icon:"arrows-horizontal",text:(0,r.t)("toolbar.flipHorizontally"),onClick:()=>{e.set({flipX:!e.flipX})}}),t.default.createElement(o.MenuItem,{shouldDismissPopover:!1,text:(0,r.t)("toolbar.flipVertically"),icon:"arrows-vertical",onClick:()=>{e.set({flipY:!e.flipY})}})),position:o.Position.BOTTOM},t.default.createElement(o.Button,{text:(0,r.t)("toolbar.flip"),minimal:!0}));exports.FlipButton=i,exports.default=exports.FlipButton;
|
|
4195
4197
|
},{"react":"HdMw","@blueprintjs/core":"Ydrz","@blueprintjs/popover2":"mZnF","../utils/l10n":"FlVj"}],"wwJC":[function(require,module,exports) {
|
|
@@ -4239,8 +4241,8 @@ var r=require("../lib").GenIcon;module.exports=function(t){return r({tag:"svg",a
|
|
|
4239
4241
|
}
|
|
4240
4242
|
`;exports.Toolbar=(0,o.observer)(({store:e,downloadButtonEnabled:o,hideTextFontFamily:r,hideTextSpacing:a,hideTextEffects:d,hideImageFlip:u,hideImageEffects:s,hideImageCrop:c,hideImageFit:T,hideImageRemoveBackground:F,hideSvgEffects:k,hidePosition:w,hideOpacity:B,hideDuplicate:P,hideLock:R,hideRemove:S,components:D={}})=>{const _=1===new Set(e.selectedElements.map(e=>e.type)).size,C=1===e.selectedElements.length,L=e.selectedElements[0],O=e.selectedElements.every(e=>e.styleEditable);let A=O&&C&&y[L.type];_&&"text"===(null==L?void 0:L.type)?A=y[L.type]:e.selectedElements.length>1&&(A=y.many),C&&"text"===L.type&&x.flags.htmlRenderEnabled&&(A=n.HtmlToolbar);const G=C&&L._cropModeEnabled,H=(null==D?void 0:D.ActionControls)||(o?m.DownloadButton:null),M=(null==D?void 0:D.Position)||g.PositionPicker,j=(null==D?void 0:D.Opacity)||b.OpacityPicker,N=(null==D?void 0:D.Lock)||f.LockButton,z=(null==D?void 0:D.Duplicate)||p.DuplicateButton,$=(null==D?void 0:D.Remove)||h.RemoveButton,J=(null==D?void 0:D.Group)||E.GroupButton,K=(null==D?void 0:D.History)||l.HistoryButtons,Q=[r,a,d,u,s,c,T,F,k,w,B,P,R,S],U=["hideTextFontFamily","hideTextSpacing","hideTextEffects","hideImageFlip","hideImageEffects","hideImageCrop","hideImageFit","hideImageRemoveBackground","hideSvgEffects","hidePosition","hideOpacity","hideDuplicate","hideLock","hideRemove"];return t.default.useEffect(()=>{const e=[];Q.forEach((t,o)=>{void 0!==t&&e.push(o)}),e.length>0&&console.warn(`Toolbar props ${e.map(e=>U[e]).join(", ")} are deprecated. Please use components API instead instead. See https://polotno.com/docs/toolbar`)},Q),t.default.createElement(q,{className:"bp4-navbar"},t.default.createElement(I,null,!G&&t.default.createElement(K,{store:e}),A&&O&&t.default.createElement(A,{store:e,hideTextFontFamily:r,hideTextSpacing:a,hideTextEffects:d,hideImageFlip:u,hideImageEffects:s,hideImageCrop:c,hideImageFit:T,hideSvgEffects:k,hideImageRemoveBackground:F,components:D}),!G&&t.default.createElement(i.Navbar.Group,{align:i.Alignment.RIGHT},"admin"===e.role&&t.default.createElement(v.AdminButton,{store:e}),t.default.createElement(J,{store:e}),!w&&t.default.createElement(M,{store:e}),!B&&O&&t.default.createElement(j,{store:e}),!R&&t.default.createElement(N,{store:e}),!P&&t.default.createElement(z,{store:e}),!S&&t.default.createElement($,{store:e}),H&&t.default.createElement(t.default.Fragment,null,t.default.createElement(i.Divider,{style:{height:"100%",margin:"0 15px"}}),t.default.createElement(H,{store:e})))))}),exports.default=exports.Toolbar;
|
|
4241
4243
|
},{"react":"HdMw","mobx-react-lite":"ZfSi","@blueprintjs/core":"Ydrz","../utils/styled":"PsiH","./history-buttons":"APqM","./text-toolbar":"LDge","./html-toolbar":"JODo","./image-toolbar":"LcnJ","./svg-toolbar":"nsjL","./line-toolbar":"BSzA","./many-toolbar":"espJ","./download-button":"hzA0","./duplicate-button":"I7IM","./remove-button":"F6AQ","./lock-button":"xZD7","./position-picker":"Taqf","./opacity-picker":"tmro","./admin-button":"ccY3","./group-button":"wGhb","../utils/flags":"IDY9"}],"Otsg":[function(require,module,exports) {
|
|
4242
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.unstable_setTextVerticalResizeEnabled=exports.unstable_setTextOverflow=exports.unstable_setForceTextFit=exports.unstable_useHtmlTextRender=exports.unstable_setRemoveBackgroundEnabled=exports.useDownScaling=exports.setColorsPresetFunc=exports.setAPI=exports.getGoogleFontImage=exports.getGoogleFontsListAPI=exports.unstable_registerNextDomDrop=exports.getTranslations=exports.setTranslations=exports.onLoadError=exports.unstable_registerToolbarComponent=exports.unstable_registerTransformerAttrs=exports.unstable_registerShapeComponent=exports.unstable_registerShapeModel=exports.unstable_setImageLoaderHook=exports.toggleFadeInAnimation=exports.setUploadFunc=exports.replaceGlobalFonts=exports.removeGlobalFont=exports.addGlobalFont=exports.setGoogleFonts=void 0;var e=require("./utils/fonts");Object.defineProperty(exports,"setGoogleFonts",{enumerable:!0,get:function(){return e.setGoogleFonts}}),Object.defineProperty(exports,"addGlobalFont",{enumerable:!0,get:function(){return e.addGlobalFont}}),Object.defineProperty(exports,"removeGlobalFont",{enumerable:!0,get:function(){return e.removeGlobalFont}}),Object.defineProperty(exports,"replaceGlobalFonts",{enumerable:!0,get:function(){return e.replaceGlobalFonts}});var t=require("./side-panel/upload-panel");Object.defineProperty(exports,"setUploadFunc",{enumerable:!0,get:function(){return t.setUploadFunc}});var r=require("./canvas/use-fadein");Object.defineProperty(exports,"toggleFadeInAnimation",{enumerable:!0,get:function(){return r.toggleFadeInAnimation}});var o=require("./canvas/image-element");Object.defineProperty(exports,"unstable_setImageLoaderHook",{enumerable:!0,get:function(){return o.setImageLoaderHook}});var n=require("./model/store");Object.defineProperty(exports,"unstable_registerShapeModel",{enumerable:!0,get:function(){return n.registerShapeModel}});var s=require("./canvas/element");Object.defineProperty(exports,"unstable_registerShapeComponent",{enumerable:!0,get:function(){return s.registerShapeComponent}});var a=require("./canvas/page");Object.defineProperty(exports,"unstable_registerTransformerAttrs",{enumerable:!0,get:function(){return a.registerTransformerAttrs}});var u=require("./toolbar/toolbar");Object.defineProperty(exports,"unstable_registerToolbarComponent",{enumerable:!0,get:function(){return u.registerToolbarComponent}});var l=require("./utils/loader");Object.defineProperty(exports,"onLoadError",{enumerable:!0,get:function(){return l.onLoadError}});var i=require("./utils/l10n");Object.defineProperty(exports,"setTranslations",{enumerable:!0,get:function(){return i.setTranslations}}),Object.defineProperty(exports,"getTranslations",{enumerable:!0,get:function(){return i.getTranslations}});var p=require("./canvas/page");Object.defineProperty(exports,"unstable_registerNextDomDrop",{enumerable:!0,get:function(){return p.registerNextDomDrop}});var b=require("./utils/api");Object.defineProperty(exports,"getGoogleFontsListAPI",{enumerable:!0,get:function(){return b.getGoogleFontsListAPI}}),Object.defineProperty(exports,"getGoogleFontImage",{enumerable:!0,get:function(){return b.getGoogleFontImage}}),Object.defineProperty(exports,"setAPI",{enumerable:!0,get:function(){return b.setAPI}});var g=require("./toolbar/color-picker");Object.defineProperty(exports,"setColorsPresetFunc",{enumerable:!0,get:function(){return g.setColorsPresetFunc}});var c=require("./utils/flags");Object.defineProperty(exports,"useDownScaling",{enumerable:!0,get:function(){return c.useDownScaling}});var
|
|
4244
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.unstable_setTextVerticalResizeEnabled=exports.unstable_setTextOverflow=exports.unstable_setForceTextFit=exports.unstable_useHtmlTextRender=exports.unstable_setRemoveBackgroundEnabled=exports.useDownScaling=exports.setColorsPresetFunc=exports.setAPI=exports.getGoogleFontImage=exports.getGoogleFontsListAPI=exports.unstable_registerNextDomDrop=exports.getTranslations=exports.setTranslations=exports.setAssetLoadTimeout=exports.onLoadError=exports.unstable_registerToolbarComponent=exports.unstable_registerTransformerAttrs=exports.unstable_registerShapeComponent=exports.unstable_registerShapeModel=exports.unstable_setImageLoaderHook=exports.toggleFadeInAnimation=exports.setUploadFunc=exports.replaceGlobalFonts=exports.removeGlobalFont=exports.addGlobalFont=exports.setGoogleFonts=void 0;var e=require("./utils/fonts");Object.defineProperty(exports,"setGoogleFonts",{enumerable:!0,get:function(){return e.setGoogleFonts}}),Object.defineProperty(exports,"addGlobalFont",{enumerable:!0,get:function(){return e.addGlobalFont}}),Object.defineProperty(exports,"removeGlobalFont",{enumerable:!0,get:function(){return e.removeGlobalFont}}),Object.defineProperty(exports,"replaceGlobalFonts",{enumerable:!0,get:function(){return e.replaceGlobalFonts}});var t=require("./side-panel/upload-panel");Object.defineProperty(exports,"setUploadFunc",{enumerable:!0,get:function(){return t.setUploadFunc}});var r=require("./canvas/use-fadein");Object.defineProperty(exports,"toggleFadeInAnimation",{enumerable:!0,get:function(){return r.toggleFadeInAnimation}});var o=require("./canvas/image-element");Object.defineProperty(exports,"unstable_setImageLoaderHook",{enumerable:!0,get:function(){return o.setImageLoaderHook}});var n=require("./model/store");Object.defineProperty(exports,"unstable_registerShapeModel",{enumerable:!0,get:function(){return n.registerShapeModel}});var s=require("./canvas/element");Object.defineProperty(exports,"unstable_registerShapeComponent",{enumerable:!0,get:function(){return s.registerShapeComponent}});var a=require("./canvas/page");Object.defineProperty(exports,"unstable_registerTransformerAttrs",{enumerable:!0,get:function(){return a.registerTransformerAttrs}});var u=require("./toolbar/toolbar");Object.defineProperty(exports,"unstable_registerToolbarComponent",{enumerable:!0,get:function(){return u.registerToolbarComponent}});var l=require("./utils/loader");Object.defineProperty(exports,"onLoadError",{enumerable:!0,get:function(){return l.onLoadError}}),Object.defineProperty(exports,"setAssetLoadTimeout",{enumerable:!0,get:function(){return l.setAssetLoadTimeout}});var i=require("./utils/l10n");Object.defineProperty(exports,"setTranslations",{enumerable:!0,get:function(){return i.setTranslations}}),Object.defineProperty(exports,"getTranslations",{enumerable:!0,get:function(){return i.getTranslations}});var p=require("./canvas/page");Object.defineProperty(exports,"unstable_registerNextDomDrop",{enumerable:!0,get:function(){return p.registerNextDomDrop}});var b=require("./utils/api");Object.defineProperty(exports,"getGoogleFontsListAPI",{enumerable:!0,get:function(){return b.getGoogleFontsListAPI}}),Object.defineProperty(exports,"getGoogleFontImage",{enumerable:!0,get:function(){return b.getGoogleFontImage}}),Object.defineProperty(exports,"setAPI",{enumerable:!0,get:function(){return b.setAPI}});var g=require("./toolbar/color-picker");Object.defineProperty(exports,"setColorsPresetFunc",{enumerable:!0,get:function(){return g.setColorsPresetFunc}});var c=require("./utils/flags");Object.defineProperty(exports,"useDownScaling",{enumerable:!0,get:function(){return c.useDownScaling}});var d=require("./utils/flags");Object.defineProperty(exports,"unstable_setRemoveBackgroundEnabled",{enumerable:!0,get:function(){return d.useRemoveBackground}});var x=require("./utils/flags");Object.defineProperty(exports,"unstable_useHtmlTextRender",{enumerable:!0,get:function(){return x.useHtmlTextRender}});var f=require("./utils/flags");Object.defineProperty(exports,"unstable_setForceTextFit",{enumerable:!0,get:function(){return f.setForceTextFit}});var m=require("./utils/flags");Object.defineProperty(exports,"unstable_setTextOverflow",{enumerable:!0,get:function(){return m.setTextOverflow}});var P=require("./utils/flags");Object.defineProperty(exports,"unstable_setTextVerticalResizeEnabled",{enumerable:!0,get:function(){return P.setTextVerticalResizeEnabled}});
|
|
4243
4245
|
},{"./utils/fonts":"XXLd","./side-panel/upload-panel":"ioqf","./canvas/use-fadein":"N3c2","./canvas/image-element":"VbEp","./model/store":"GRkH","./canvas/element":"XEPK","./canvas/page":"Co9b","./toolbar/toolbar":"CetC","./utils/loader":"bN4e","./utils/l10n":"FlVj","./utils/api":"Ic0q","./toolbar/color-picker":"zFB1","./utils/flags":"IDY9"}],"IVsl":[function(require,module,exports) {
|
|
4244
|
-
"use strict";var e=
|
|
4246
|
+
"use strict";var e=l(require("react")),t=l(require("react-dom/client")),o=require("polotno/canvas/workspace"),r=require("polotno/model/store"),a=require("polotno/canvas/use-fadein"),n=require("polotno/config"),s=require("polotno/utils/fonts");function l(e){return e&&e.__esModule?e:{default:e}}(0,a.toggleFadeInAnimation)(!1),(0,n.unstable_setTextOverflow)("change-font-size");var u=new URLSearchParams(location.search).get("key"),i=(0,r.createStore)({key:u});window.store=i,window.config={addGlobalFont:s.addGlobalFont,unstable_useHtmlTextRender:n.unstable_useHtmlTextRender,unstable_setTextVerticalResizeEnabled:n.unstable_setTextVerticalResizeEnabled,unstable_setTextOverflow:n.unstable_setTextOverflow,onLoadError:n.onLoadError,setAssetLoadTimeout:n.setAssetLoadTimeout};var d=t.default.createRoot(document.getElementById("root"));d.render(e.default.createElement(o.Workspace,{store:i}));
|
|
4245
4247
|
},{"react":"HdMw","react-dom/client":"U1bq","polotno/canvas/workspace":"twsc","polotno/model/store":"GRkH","polotno/canvas/use-fadein":"N3c2","polotno/config":"Otsg","polotno/utils/fonts":"XXLd"}]},{},["IVsl"], null)
|
|
4246
|
-
//# sourceMappingURL=client.
|
|
4248
|
+
//# sourceMappingURL=client.51dfa0bd.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.51dfa0bd.js"></script> </body></html>
|
package/instance.js
CHANGED
|
@@ -19,7 +19,6 @@ module.exports.createPage = async (browser, url) => {
|
|
|
19
19
|
});
|
|
20
20
|
|
|
21
21
|
await page.goto(url);
|
|
22
|
-
|
|
23
22
|
return page;
|
|
24
23
|
};
|
|
25
24
|
|
|
@@ -82,14 +81,32 @@ module.exports.createInstance = async ({
|
|
|
82
81
|
: firstPage;
|
|
83
82
|
|
|
84
83
|
try {
|
|
84
|
+
if (args[1]?.assetLoadTimeout) {
|
|
85
|
+
await page.evaluate((timeout) => {
|
|
86
|
+
if (window.config && window.config.setAssetLoadTimeout) {
|
|
87
|
+
window.config.setAssetLoadTimeout(timeout);
|
|
88
|
+
}
|
|
89
|
+
}, args[1].assetLoadTimeout);
|
|
90
|
+
}
|
|
91
|
+
await page.evaluate(() => {
|
|
92
|
+
if (window.config?.onLoadError) {
|
|
93
|
+
window.config.onLoadError((error) => {
|
|
94
|
+
window._polotnoError = error;
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
});
|
|
85
98
|
const result = await page.evaluate(func, ...args);
|
|
99
|
+
const error = await page.evaluate(() => window._polotnoError);
|
|
100
|
+
if (error) {
|
|
101
|
+
throw new Error(error);
|
|
102
|
+
}
|
|
86
103
|
if (useParallelPages) {
|
|
87
|
-
page.close();
|
|
104
|
+
await page.close();
|
|
88
105
|
}
|
|
89
106
|
return result;
|
|
90
107
|
} catch (e) {
|
|
91
108
|
if (useParallelPages) {
|
|
92
|
-
page.close();
|
|
109
|
+
await page.close();
|
|
93
110
|
}
|
|
94
111
|
throw e;
|
|
95
112
|
}
|
|
@@ -144,7 +161,9 @@ module.exports.createInstance = async ({
|
|
|
144
161
|
};
|
|
145
162
|
|
|
146
163
|
return {
|
|
147
|
-
close: async () =>
|
|
164
|
+
close: async () => {
|
|
165
|
+
await browser.close();
|
|
166
|
+
},
|
|
148
167
|
firstPage,
|
|
149
168
|
browser,
|
|
150
169
|
run,
|
|
@@ -153,5 +172,6 @@ module.exports.createInstance = async ({
|
|
|
153
172
|
jsonToPDFDataURL,
|
|
154
173
|
jsonToPDFBase64,
|
|
155
174
|
jsonToBlob,
|
|
175
|
+
createPage: async () => await module.exports.createPage(browser, visitPage),
|
|
156
176
|
};
|
|
157
177
|
};
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "polotno-node",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.6",
|
|
4
4
|
"description": "Polotno workflow from NodeJS",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"test": "
|
|
7
|
+
"test": "ava",
|
|
8
8
|
"build": "rm -rf ./dist && parcel build ./client.html --public-url ./ && rm ./dist/*js.map",
|
|
9
9
|
"dev": "parcel ./client.html"
|
|
10
10
|
},
|
|
@@ -15,16 +15,23 @@
|
|
|
15
15
|
"README.md"
|
|
16
16
|
],
|
|
17
17
|
"devDependencies": {
|
|
18
|
+
"ava": "^5.2.0",
|
|
18
19
|
"parcel-bundler": "^1.12.4",
|
|
19
|
-
"
|
|
20
|
+
"pixelmatch": "^5.3.0",
|
|
21
|
+
"pngjs": "^7.0.0",
|
|
22
|
+
"polotno": "^1.8.5",
|
|
20
23
|
"react": "^18.2.0",
|
|
21
24
|
"react-dom": "^18.2.0"
|
|
22
25
|
},
|
|
23
26
|
"author": "Anton Lavrenov",
|
|
24
27
|
"license": "MIT",
|
|
25
28
|
"dependencies": {
|
|
29
|
+
"axios": "^1.3.4",
|
|
30
|
+
"canvas": "^2.11.0",
|
|
26
31
|
"chrome-aws-lambda": "^10.1.0",
|
|
27
|
-
"
|
|
32
|
+
"fluent-ffmpeg": "^2.1.2",
|
|
33
|
+
"gifencoder": "^2.0.1",
|
|
34
|
+
"puppeteer": "^19.7.5"
|
|
28
35
|
},
|
|
29
36
|
"bugs": {
|
|
30
37
|
"url": "https://github.com/polotno-project/polotno-node/issues"
|