polotno 2.21.9 → 2.21.11
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/canvas/html-element.js +2 -2
- package/package.json +1 -1
- package/polotno.bundle.js +3 -3
- package/utils/html2canvas.d.ts +1 -1
- package/utils/html2canvas.js +1 -1
- package/utils/validate-key.js +1 -1
package/canvas/html-element.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var e,t=this&&this.__createBinding||(Object.create?function(e,t,n,i){void 0===i&&(i=n);var r=Object.getOwnPropertyDescriptor(t,n);r&&!("get"in r?!t.__esModule:r.writable||r.configurable)||(r={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,i,r)}:function(e,t,n,i){void 0===i&&(i=n),e[i]=t[n]}),n=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||(e=function(t){return e=Object.getOwnPropertyNames||function(e){var t=[];for(var n in e){Object.prototype.hasOwnProperty.call(e,n)&&(t[t.length]=n)}return t},e(t)},function(i){if(i&&i.__esModule){return i}var r={};if(null!=i){for(var o=e(i),a=0;a<o.length;a++){"default"!==o[a]&&t(r,i,o[a])}}return n(r,i),r}),r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.HTMLElement=exports.setQuillContent=exports.createQuill=exports.setQuillFormats=exports.quillRef=void 0;const o=r(require("react")),a=require("mobx-react-lite"),l=require("react-konva"),s=r(require("quill")),u=r(require("konva")),c=i(require("mobx")),d=require("../utils/flags"),f=require("./apply-filters"),g=require("./text-element"),h=require("./use-color"),m=require("../utils/html2canvas"),p=require("./use-fadein"),x=require("./highlighter"),b=require("react-konva-utils"),y=r(require("../utils/styled")),w=require("../utils/loader"),v=require("../utils/text"),S=i(require("../utils/fonts")),
|
|
1
|
+
var e,t=this&&this.__createBinding||(Object.create?function(e,t,n,i){void 0===i&&(i=n);var r=Object.getOwnPropertyDescriptor(t,n);r&&!("get"in r?!t.__esModule:r.writable||r.configurable)||(r={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,i,r)}:function(e,t,n,i){void 0===i&&(i=n),e[i]=t[n]}),n=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||(e=function(t){return e=Object.getOwnPropertyNames||function(e){var t=[];for(var n in e){Object.prototype.hasOwnProperty.call(e,n)&&(t[t.length]=n)}return t},e(t)},function(i){if(i&&i.__esModule){return i}var r={};if(null!=i){for(var o=e(i),a=0;a<o.length;a++){"default"!==o[a]&&t(r,i,o[a])}}return n(r,i),r}),r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.HTMLElement=exports.setQuillContent=exports.createQuill=exports.setQuillFormats=exports.quillRef=void 0;const o=r(require("react")),a=require("mobx-react-lite"),l=require("react-konva"),s=r(require("quill")),u=r(require("konva")),c=i(require("mobx")),d=require("../utils/flags"),f=require("./apply-filters"),g=require("./text-element"),h=require("./use-color"),m=require("../utils/html2canvas"),p=require("./use-fadein"),x=require("./highlighter"),b=require("react-konva-utils"),y=r(require("../utils/styled")),w=require("../utils/loader"),v=require("../utils/text"),S=i(require("../utils/fonts")),E=require("../utils/screen"),k=require("./text-element/max-font-size");exports.quillRef=c.observable({enabled:!1,currentFormat:{},editor:c.observable.object({instance:null},{},{deep:!1})});const z=(0,y.default)("div",o.default.forwardRef)`
|
|
2
2
|
.ql-editor {
|
|
3
3
|
outline: none;
|
|
4
4
|
}
|
|
@@ -12,4 +12,4 @@ var e,t=this&&this.__createBinding||(Object.create?function(e,t,n,i){void 0===i&
|
|
|
12
12
|
.ql-direction-rtl {
|
|
13
13
|
direction: rtl;
|
|
14
14
|
}
|
|
15
|
-
`;let O=["bold","color","font","italic","size","strike","underline","indent","list","direction"];exports.setQuillFormats=e=>{O=e},exports.createQuill=e=>new s.default(e,{toolbar:!1,keyboard:!1,clipboard:{matchVisual:!1},formats:O}),exports.setQuillContent=(e,t)=>{var n=e.clipboard.convert("<div class='ql-editor' style='outline: none;'>"+t+"<p><br></p></div>");e.setContents(n),e.history.clear()};const q=({html:e,onBlur:t,onChange:n,element:i})=>{const r=o.default.useRef(null);o.default.useEffect((()=>{if(!r.current){return}const e=(0,exports.createQuill)(r.current);return c.runInAction((()=>{exports.quillRef.editor.instance=e})),window.__polotnoQuill=e,e.on("text-change",(()=>{e.getSelection()&&c.runInAction((()=>{exports.quillRef.currentFormat=e.getFormat()})),setTimeout((()=>{var e;const t=null===(e=r.current)||void 0===e?void 0:e.childNodes[0];n(t.innerHTML)}),10)})),e.setSelection(0,0,"api"),e.on("selection-change",((t,n,i)=>{t&&c.runInAction((()=>{exports.quillRef.currentFormat=e.getFormat()}))})),r.current.childNodes[0].addEventListener("blur",(e=>{var n;if(null===(n=e.relatedTarget)||void 0===n?void 0:n.classList.contains("ql-clipboard")){return}const i=function(e){return!!e&&!!e.closest(".sketch-picker")}(e.relatedTarget);i||t()})),()=>{c.runInAction((()=>{exports.quillRef.editor.instance=null,exports.quillRef.currentFormat={}})),delete window.__polotnoQuill}}),[]),o.default.useEffect((()=>{var t;const n=exports.quillRef.editor.instance;if(!n){return}const o=n.getSelection();(null===(t=r.current)||void 0===t?void 0:t.childNodes[0].innerHTML)===i.text||((0,exports.setQuillContent)(n,e),o&&(n.setSelection(o.index,o.length),c.runInAction((()=>{exports.quillRef.currentFormat=n.getFormat()}))))}),[i.text]);const a={color:i.fill};return i.fill.indexOf("gradient")>=0&&(a.backgroundColor=i.fill,a.backgroundImage=i.fill,a.backgroundSize="100% 100%",a.backgroundRepeat="repeat",a.webkitBackgroundClip="text",a.MozBackgroundClip="text",a.WebkitTextFillColor="transparent",a.MozTextFillColor="transparent"),o.default.createElement(z,{ref:r,style:Object.assign(Object.assign({},a),{fontSize:i.fontSize,fontWeight:i.fontWeight,width:i.a.width,fontFamily:i.fontFamily,lineHeight:i.lineHeight,letterSpacing:i.letterSpacing*i.fontSize+"px",textAlign:i.align}),dir:(0,g.getDir)((0,v.removeTags)(i.text))})},F=(e,t=100,n=!1)=>{const[i,r]=o.default.useState(e),a=o.default.useRef(null);return o.default.useEffect((()=>e===n?(a.current&&(clearTimeout(a.current),a.current=null),void r(n)):(a.current&&clearTimeout(a.current),a.current=setTimeout((()=>{r(e),a.current=null}),t),()=>{a.current&&clearTimeout(a.current)})),[e,t]),[i,r]};function R(e,{fontFamily:t="",color:n="black"}={}){let i=`color: ${n||e.fill}`;return e.fill.indexOf("gradient")>=0&&(i=`\n background-color: ${n};\n background-image: ${e.fill};\n background-size: 100% 100%;\n background-repeat: repeat;\n -webkit-background-clip: text;\n -moz-background-clip: text;\n -webkit-text-fill-color: transparent;\n -moz-text-fill-color: transparent;\n `),`<div style="${["white-space: pre-wrap",`width: ${Math.round(e.width||100)}px`,i,`font-size: ${e.fontSize}px`,`font-family: '${t}'`,`text-align: ${e.align}`,e.textDecoration?`text-decoration: ${e.textDecoration}; text-decoration-color: ${n||e.fill}; text-decoration-layer: over`:"",e.lineHeight?`line-height: ${e.lineHeight}`:"",e.letterSpacing?`letter-spacing: ${e.letterSpacing*e.fontSize}px`:"",e.fontStyle?`font-style: ${e.fontStyle}`:"",e.fontWeight?`font-weight: ${e.fontWeight}`:"",e.strokeWidth?`-webkit-text-stroke: ${e.strokeWidth}px ${e.stroke}`:"",e.strokeWidth?"paint-order: stroke fill":""].filter(Boolean).join("; ")}" contentEditable dir="${(0,g.getDir)((0,v.removeTags)(e.text))}">${(0,v.sanitizeHtml)(e.text).replace(/\n/g,"</br>")}</div>`}const T=/^((?!chrome|android).)*safari/i.test(navigator.userAgent);exports.HTMLElement=(0,a.observer)((({element:e,store:t})=>{const n=o.default.useRef(null),[i,r]=o.default.useState(),[a,s]=o.default.useState(!1),[y,O]=o.default.useState(!0),[M,_]=o.default.useState(!1),C=o.default.useRef(e.height),$=t.selectedShapes.indexOf(e)>=0&&e.selectable,A=e.fontSize/3,{textVerticalResizeEnabled:H}=d.flags,I=(0,g.usePrevious)(e.fontFamily),[j]=(0,g.useFontLoader)(t,e.fontFamily),P=e._editModeEnabled;(0,p.useFadeIn)(n);const D=j?e.fontFamily:I!==e.fontFamily?I:"Arial",L=(0,h.useColor)(e).fill,X=R(e,{fontFamily:D,color:L}),{width:Y,height:W}=function(e,t,n){return o.default.useMemo((()=>(0,m.detectSize)(e)),[e,t.width,n])}(X,e,j);o.default.useEffect((()=>{if(!j){return}if(!e.height){return void e.set({height:W})}const{textOverflow:n}=d.flags;if("change-font-size"!==n||a){"resize"===n&&(H&&e.height<W&&t.history.ignore((()=>{e.set({height:W})})),H||e.height===W||t.history.ignore((()=>{e.set({height:W})})))}else{const n=(e=>{let t=e.fontSize;for(let n=1;n<50;n++){const n=R(Object.assign(Object.assign({},e.toJSON()),{fontSize:t}),{fontFamily:e.fontFamily}),{height:i}=(0,m.detectSize)(n),r=e.height&&i>e.height,o=(0,m.isContentWrapping)({html:n});if(!r&&!o){break}t-=.5}return t})(e);n!==e.fontSize?t.history.ignore((()=>{e.set({fontSize:n})})):e.height!==W&&(H&&e.height<W?t.history.ignore((()=>{e.set({height:W})})):H||t.history.ignore((()=>{e.set({height:W})})))}}));const B=o.default.useRef(0),Q=o.default.useMemo((()=>{const e={lastArgs:null,lastResult:null};return async function(t){return e.lastArgs&&e.lastResult&&(n=e.lastArgs,i=t,JSON.stringify(n)===JSON.stringify(i))||(e.lastResult=await(0,m.htmlToCanvas)(t),e.lastArgs=Object.assign({},t)),e.lastResult;var n,i}}),[]);o.default.useEffect((()=>{a||P||(async()=>{B.current++;const n=B.current,i=(0,w.incrementLoader)(`text ${e.id}`);O(!0);let o=null;const a=T?5:1;for(let r=0;r<a;r++){const a=r>0?Q:m.htmlToCanvas;try{if(o=await a({skipCache:r>0,html:X,width:e.width||1,height:e.height||W||1,fontFamily:D,padding:A,pixelRatio:t._elementsPixelRatio,font:t.fonts.find((e=>e.fontFamily===D))||S.globalFonts.find((e=>e.fontFamily===D))}),n!==B.current){return void i()}if(!function(e){const t=e.getContext("2d").getImageData(0,0,e.width,e.height).data;for(let n=0;n<t.length;n+=4){if(0!==t[n+3]){return!0}}return!1}(o)&&T){await new Promise((e=>setTimeout(e,50*(r+1))));continue}}catch(l){(0,w.triggerLoadError)(`Error rendering rich text with id ${e.id}`);break}}o?(r(o),O(!1),u.default.Util.requestAnimFrame(i)):i()})()}),[X,a,W,P,D,e.height,t._elementsPixelRatio,j]);const[N,J]=F(y),[V]=F(a,100,!0),G=V||N;o.default.useEffect((()=>c.autorun((()=>{const t=n.current;(0,f.applyFilter)(t,e)}))),[i,G,e.shadowColor,e.shadowOffsetX,e.shadowOffsetY,e.shadowOpacity]);let U=0;"middle"===e.verticalAlign&&(U=(e.height-W)/2),"bottom"===e.verticalAlign&&(U=e.height-W);const K=(0,g.getLineHeight)({fontLoaded:j,fontFamily:e.fontFamily,fontSize:e.fontSize,lineHeight:e.lineHeight}),Z=(0,k.isTouchDevice)();return o.default.createElement(o.default.Fragment,null,o.default.createElement(l.Rect,{x:e.a.x,y:e.a.y,offsetX:e.backgroundPadding*(e.fontSize*K*.5),offsetY:e.backgroundPadding*(e.fontSize*K*.5),rotation:e.a.rotation,hideInExport:!e.showInExport,listening:!1,visible:e.backgroundEnabled,opacity:e.backgroundOpacity*e.a.opacity,fill:e.backgroundColor,width:e.a.width+e.backgroundPadding*(e.fontSize*K),height:e.a.height+e.backgroundPadding*(e.fontSize*K),cornerRadius:e.backgroundCornerRadius*(e.fontSize*K*.5)}),o.default.createElement(l.Rect,{ref:n,name:"element",x:e.a.x,y:e.a.y,listening:e.selectable,rotation:e.a.rotation,width:e.a.width,height:e.a.height,visible:!G,draggable:Z?e.draggable&&$:e.draggable,preventDefault:!Z||$,opacity:P?0:e.a.opacity,hideInExport:!e.showInExport,onMouseEnter:()=>{_(!0)},onMouseLeave:()=>{_(!1)},onDragMove:t=>{e.set({x:t.target.x(),y:t.target.y()})},onDragEnd:t=>{e.set({x:t.target.x(),y:t.target.y()})},id:e.id,onDblClick:()=>{e.contentEditable&&e.toggleEditMode(!0)},onDblTap:()=>{e.contentEditable&&e.toggleEditMode(!0)},onTransformStart:t=>{s(!0),C.current=e.height},onTransform:t=>{var n;const i=t.target,r=(null===(n=i.getStage())||void 0===n?void 0:n.findOne("Transformer")).getActiveAnchor(),o="middle-left"===r||"middle-right"===r,a="top-center"===r||"bottom-center"===r,l=i.scaleX();if(o){const t=i.scaleX(),n=Math.max(i.width()*t,e.fontSize);if(i.width(n),i.scaleX(1),d.flags.textVerticalResizeEnabled){const t=Math.max(W,C.current);e.set({height:t})}e.set({width:n,x:i.x(),y:i.y()})}else if(a){let n="resize"===d.flags.textOverflow?W:e.lineHeight*e.fontSize;const r=Math.max(n,t.target.height()*t.target.scaleY());i.scaleY(1),e.set({x:i.x(),y:i.y(),height:r,rotation:i.rotation()})}else{i.scaleX(1),i.scaleY(1),e.set({fontSize:e.fontSize*l,letterSpacing:e.letterSpacing,width:i.width()*l,x:i.x(),y:i.y(),rotation:i.rotation(),height:i.height()*l})}},onTransformEnd:t=>{s(!1),O(!0);const n=t.target.scaleX();t.target.scaleX(1),t.target.scaleY(1),e.set({fontSize:e.fontSize*n,width:t.target.width()*n,x:t.target.x(),y:t.target.y(),rotation:t.target.rotation(),shadowBlur:e.shadowBlur*n,shadowOffsetX:e.shadowOffsetX*n,shadowOffsetY:e.shadowOffsetY*n,strokeWidth:e.strokeWidth*n})}}),o.default.createElement(l.Image,{ref:n,image:i,x:e.a.x,y:e.a.y,offsetX:A,offsetY:A-U,listening:!1,rotation:e.rotation,width:e.a.width+2*A,height:e.a.height+2*A,visible:!G,opacity:P?0:e.a.opacity,shadowEnabled:e.shadowEnabled,shadowBlur:e.shadowBlur,shadowOffsetX:e.shadowOffsetX,shadowOffsetY:e.shadowOffsetY,shadowColor:e.shadowColor,shadowOpacity:e.shadowOpacity,hideInExport:!e.showInExport}),G&&o.default.createElement(l.Group,{x:e.a.x,y:e.a.y,rotation:e.rotation,offsetY:-U},o.default.createElement(b.Html,{divProps:{style:{pointerEvents:"none"}}},o.default.createElement(z,{dangerouslySetInnerHTML:{__html:X},style:{pointerEvents:"none",display:"inline-block"}}))),P&&o.default.createElement(l.Group,{x:e.a.x,y:e.a.y,rotation:e.rotation,offsetY:-U},o.default.createElement(b.Html,null,o.default.createElement(q,{html:X,element:e,onChange:t=>{const n=(0,E.getLimitedFontSize)({oldText:(0,v.removeTags)(e.text),newText:(0,v.removeTags)(t),element:e});e.set({text:t,fontSize:n}),J(!0)},onBlur:t=>{e.toggleEditMode(!1)}}))),($||M)&&o.default.createElement(x.Highlighter,{element:e}))}));
|
|
15
|
+
`;let O=["bold","color","font","italic","size","strike","underline","indent","list","direction"];exports.setQuillFormats=e=>{O=e},exports.createQuill=e=>new s.default(e,{toolbar:!1,keyboard:!1,clipboard:{matchVisual:!1},formats:O}),exports.setQuillContent=(e,t)=>{var n=e.clipboard.convert("<div class='ql-editor' style='outline: none;'>"+t+"<p><br></p></div>");e.setContents(n),e.history.clear()};const q=({html:e,onBlur:t,onChange:n,element:i})=>{const r=o.default.useRef(null);o.default.useEffect((()=>{if(!r.current){return}const e=(0,exports.createQuill)(r.current);return c.runInAction((()=>{exports.quillRef.editor.instance=e})),window.__polotnoQuill=e,e.on("text-change",(()=>{e.getSelection()&&c.runInAction((()=>{exports.quillRef.currentFormat=e.getFormat()})),setTimeout((()=>{var e;const t=null===(e=r.current)||void 0===e?void 0:e.childNodes[0];n(t.innerHTML)}),10)})),e.setSelection(0,0,"api"),e.on("selection-change",((t,n,i)=>{t&&c.runInAction((()=>{exports.quillRef.currentFormat=e.getFormat()}))})),r.current.childNodes[0].addEventListener("blur",(e=>{var n;if(null===(n=e.relatedTarget)||void 0===n?void 0:n.classList.contains("ql-clipboard")){return}const i=function(e){return!!e&&!!e.closest(".sketch-picker")}(e.relatedTarget);i||t()})),()=>{c.runInAction((()=>{exports.quillRef.editor.instance=null,exports.quillRef.currentFormat={}})),delete window.__polotnoQuill}}),[]),o.default.useEffect((()=>{var t;const n=exports.quillRef.editor.instance;if(!n){return}const o=n.getSelection();(null===(t=r.current)||void 0===t?void 0:t.childNodes[0].innerHTML)===i.text||((0,exports.setQuillContent)(n,e),o&&(n.setSelection(o.index,o.length),c.runInAction((()=>{exports.quillRef.currentFormat=n.getFormat()}))))}),[i.text]);const a={color:i.fill};return i.fill.indexOf("gradient")>=0&&(a.backgroundColor=i.fill,a.backgroundImage=i.fill,a.backgroundSize="100% 100%",a.backgroundRepeat="repeat",a.webkitBackgroundClip="text",a.MozBackgroundClip="text",a.WebkitTextFillColor="transparent",a.MozTextFillColor="transparent"),o.default.createElement(z,{ref:r,style:Object.assign(Object.assign({},a),{fontSize:i.fontSize,fontWeight:i.fontWeight,width:i.a.width,fontFamily:i.fontFamily,lineHeight:i.lineHeight,letterSpacing:i.letterSpacing*i.fontSize+"px",textAlign:i.align}),dir:(0,g.getDir)((0,v.removeTags)(i.text))})},F=(e,t=100,n=!1,i="")=>{const[r,a]=o.default.useState(e),l=o.default.useRef(null);return o.default.useEffect((()=>e===n?(l.current&&(clearTimeout(l.current),l.current=null),void a(n)):(l.current&&clearTimeout(l.current),l.current=setTimeout((()=>{a(e),l.current=null}),t),()=>{l.current&&clearTimeout(l.current)})),[e,t]),[r,a]};function R(e,{fontFamily:t="",color:n="black"}={}){let i=`color: ${n||e.fill}`;return e.fill.indexOf("gradient")>=0&&(i=`\n background-color: ${n};\n background-image: ${e.fill};\n background-size: 100% 100%;\n background-repeat: repeat;\n -webkit-background-clip: text;\n -moz-background-clip: text;\n -webkit-text-fill-color: transparent;\n -moz-text-fill-color: transparent;\n `),`<div style="${["white-space: pre-wrap",`width: ${Math.round(e.width||100)}px`,i,`font-size: ${e.fontSize}px`,`font-family: '${t}'`,`text-align: ${e.align}`,e.textDecoration?`text-decoration: ${e.textDecoration}; text-decoration-color: ${n||e.fill}; text-decoration-layer: over`:"",e.lineHeight?`line-height: ${e.lineHeight}`:"",e.letterSpacing?`letter-spacing: ${e.letterSpacing*e.fontSize}px`:"",e.fontStyle?`font-style: ${e.fontStyle}`:"",e.fontWeight?`font-weight: ${e.fontWeight}`:"",e.strokeWidth?`-webkit-text-stroke: ${e.strokeWidth}px ${e.stroke}`:"",e.strokeWidth?"paint-order: stroke fill":""].filter(Boolean).join("; ")}" contentEditable dir="${(0,g.getDir)((0,v.removeTags)(e.text))}">${(0,v.sanitizeHtml)(e.text).replace(/\n/g,"</br>")}</div>`}const T=/^((?!chrome|android).)*safari/i.test(navigator.userAgent);exports.HTMLElement=(0,a.observer)((({element:e,store:t})=>{const n=o.default.useRef(null),[i,r]=o.default.useState(),[a,s]=o.default.useState(!1),[y,O]=o.default.useState(!0),[M,_]=o.default.useState(!1),C=o.default.useRef(e.height),$=t.selectedShapes.indexOf(e)>=0&&e.selectable,A=e.fontSize/3,{textVerticalResizeEnabled:H}=d.flags,I=(0,g.usePrevious)(e.fontFamily),[j]=(0,g.useFontLoader)(t,e.fontFamily),P=e._editModeEnabled;(0,p.useFadeIn)(n);const D=j?e.fontFamily:I!==e.fontFamily?I:"Arial",L=(0,h.useColor)(e).fill,X=R(e,{fontFamily:D,color:L}),{width:Y,height:W}=function(e,t,n){return o.default.useMemo((()=>(0,m.detectSize)(e)),[e,t.width,n])}(X,e,j);o.default.useEffect((()=>{if(!j){return}if(!e.height){return void e.set({height:W})}const{textOverflow:n}=d.flags;if("change-font-size"!==n||a){"resize"===n&&(H&&e.height<W&&t.history.ignore((()=>{e.set({height:W})})),H||e.height===W||t.history.ignore((()=>{e.set({height:W})})))}else{const n=(e=>{let t=e.fontSize;for(let n=1;n<50;n++){const n=R(Object.assign(Object.assign({},e.toJSON()),{fontSize:t}),{fontFamily:e.fontFamily}),{height:i}=(0,m.detectSize)(n),r=e.height&&i>e.height,o=(0,m.isContentWrapping)({html:n});if(!r&&!o){break}t-=.5}return t})(e);n!==e.fontSize?t.history.ignore((()=>{e.set({fontSize:n})})):e.height!==W&&(H&&e.height<W?t.history.ignore((()=>{e.set({height:W})})):H||t.history.ignore((()=>{e.set({height:W})})))}}));const B=o.default.useRef(0),Q=o.default.useMemo((()=>{const e={lastArgs:null,lastResult:null};return async function(t){return e.lastArgs&&e.lastResult&&(n=e.lastArgs,i=t,JSON.stringify(n)===JSON.stringify(i))||(e.lastResult=await(0,m.htmlToCanvas)(t),e.lastArgs=Object.assign({},t)),e.lastResult;var n,i}}),[]);o.default.useEffect((()=>{a||P||(async()=>{B.current++;const n=B.current,i=(0,w.incrementLoader)(`text ${e.id}`);O(!0);let o=null;const a=T?5:1;for(let r=0;r<a;r++){const a=r>0?Q:m.htmlToCanvas;try{if(o=await a({skipCache:r>0,html:X,width:e.width||1,height:e.height||W||1,fontFamily:D,padding:A,pixelRatio:t._elementsPixelRatio,font:t.fonts.find((e=>e.fontFamily===D))||S.globalFonts.find((e=>e.fontFamily===D))}),n!==B.current){return void i()}if(!function(e){const t=e.getContext("2d").getImageData(0,0,e.width,e.height).data;for(let n=0;n<t.length;n+=4){if(0!==t[n+3]){return!0}}return!1}(o)&&T){await new Promise((e=>setTimeout(e,50*(r+1))));continue}}catch(l){(0,w.triggerLoadError)(`Error rendering rich text with id ${e.id}`);break}}o?(r(o),O(!1),u.default.Util.requestAnimFrame(i)):i()})()}),[X,a,W,P,D,e.height,t._elementsPixelRatio,j]);const[N,J]=F(y),[V]=F(a,100,!0),G=V||N;o.default.useEffect((()=>c.autorun((()=>{const t=n.current;(0,f.applyFilter)(t,e)}))),[i,G,e.shadowColor,e.shadowOffsetX,e.shadowOffsetY,e.shadowOpacity]);let U=0;"middle"===e.verticalAlign&&(U=(e.height-W)/2),"bottom"===e.verticalAlign&&(U=e.height-W);const K=(0,g.getLineHeight)({fontLoaded:j,fontFamily:e.fontFamily,fontSize:e.fontSize,lineHeight:e.lineHeight}),Z=(0,E.isTouchDevice)();return o.default.createElement(o.default.Fragment,null,o.default.createElement(l.Rect,{x:e.a.x,y:e.a.y,offsetX:e.backgroundPadding*(e.fontSize*K*.5),offsetY:e.backgroundPadding*(e.fontSize*K*.5),rotation:e.a.rotation,hideInExport:!e.showInExport,listening:!1,visible:e.backgroundEnabled,opacity:e.backgroundOpacity*e.a.opacity,fill:e.backgroundColor,width:e.a.width+e.backgroundPadding*(e.fontSize*K),height:e.a.height+e.backgroundPadding*(e.fontSize*K),cornerRadius:e.backgroundCornerRadius*(e.fontSize*K*.5)}),o.default.createElement(l.Rect,{ref:n,name:"element",x:e.a.x,y:e.a.y,listening:e.selectable,rotation:e.a.rotation,width:e.a.width,height:e.a.height,visible:!G,draggable:Z?e.draggable&&$:e.draggable,preventDefault:!Z||$,opacity:P?0:e.a.opacity,hideInExport:!e.showInExport,onMouseEnter:()=>{_(!0)},onMouseLeave:()=>{_(!1)},onDragMove:t=>{e.set({x:t.target.x(),y:t.target.y()})},onDragEnd:t=>{e.set({x:t.target.x(),y:t.target.y()})},id:e.id,onDblClick:()=>{e.contentEditable&&e.toggleEditMode(!0)},onDblTap:()=>{e.contentEditable&&e.toggleEditMode(!0)},onTransformStart:t=>{s(!0),C.current=e.height},onTransform:t=>{var n;const i=t.target,r=(null===(n=i.getStage())||void 0===n?void 0:n.findOne("Transformer")).getActiveAnchor(),o="middle-left"===r||"middle-right"===r,a="top-center"===r||"bottom-center"===r,l=i.scaleX();if(o){const t=i.scaleX(),n=Math.max(i.width()*t,e.fontSize);if(i.width(n),i.scaleX(1),d.flags.textVerticalResizeEnabled){const t=Math.max(W,C.current);e.set({height:t})}e.set({width:n,x:i.x(),y:i.y()})}else if(a){let n="resize"===d.flags.textOverflow?W:e.lineHeight*e.fontSize;const r=Math.max(n,t.target.height()*t.target.scaleY());i.scaleY(1),e.set({x:i.x(),y:i.y(),height:r,rotation:i.rotation()})}else{i.scaleX(1),i.scaleY(1),e.set({fontSize:e.fontSize*l,letterSpacing:e.letterSpacing,width:i.width()*l,x:i.x(),y:i.y(),rotation:i.rotation(),height:i.height()*l})}},onTransformEnd:t=>{s(!1),O(!0);const n=t.target.scaleX();t.target.scaleX(1),t.target.scaleY(1),e.set({fontSize:e.fontSize*n,width:t.target.width()*n,x:t.target.x(),y:t.target.y(),rotation:t.target.rotation(),shadowBlur:e.shadowBlur*n,shadowOffsetX:e.shadowOffsetX*n,shadowOffsetY:e.shadowOffsetY*n,strokeWidth:e.strokeWidth*n})}}),o.default.createElement(l.Image,{ref:n,image:i,x:e.a.x,y:e.a.y,offsetX:A,offsetY:A-U,listening:!1,rotation:e.rotation,width:e.a.width+2*A,height:e.a.height+2*A,visible:!G,opacity:P?0:e.a.opacity,shadowEnabled:e.shadowEnabled,shadowBlur:e.shadowBlur,shadowOffsetX:e.shadowOffsetX,shadowOffsetY:e.shadowOffsetY,shadowColor:e.shadowColor,shadowOpacity:e.shadowOpacity,hideInExport:!e.showInExport}),G&&o.default.createElement(l.Group,{x:e.a.x,y:e.a.y,rotation:e.rotation,offsetY:-U},o.default.createElement(b.Html,{divProps:{style:{pointerEvents:"none"}}},o.default.createElement(z,{dangerouslySetInnerHTML:{__html:X},style:{pointerEvents:"none"}}))),P&&o.default.createElement(l.Group,{x:e.a.x,y:e.a.y,rotation:e.rotation,offsetY:-U},o.default.createElement(b.Html,null,o.default.createElement(q,{html:X,element:e,onChange:t=>{const n=(0,k.getLimitedFontSize)({oldText:(0,v.removeTags)(e.text),newText:(0,v.removeTags)(t),element:e});e.set({text:t,fontSize:n})},onBlur:t=>{e.toggleEditMode(!1),J(!0)}}))),($||M)&&o.default.createElement(x.Highlighter,{element:e}))}));
|
package/package.json
CHANGED
package/polotno.bundle.js
CHANGED
|
@@ -49,7 +49,7 @@ For more info see: https://github.com/konvajs/react-konva/issues/194
|
|
|
49
49
|
position: absolute;
|
|
50
50
|
/* Use logical properties for positioning */
|
|
51
51
|
inset-inline-start: 0; /* Position marker at the start edge (left in LTR, right in RTL) */
|
|
52
|
-
top:
|
|
52
|
+
top: 0; /* Adjust vertical alignment */
|
|
53
53
|
/* Prevent letter-spacing from affecting the marker */
|
|
54
54
|
letter-spacing: normal;
|
|
55
55
|
/* Define width to ensure consistent spacing and alignment */
|
|
@@ -124,7 +124,7 @@ For more info see: https://github.com/konvajs/react-konva/issues/194
|
|
|
124
124
|
.ql-direction-rtl {
|
|
125
125
|
direction: rtl;
|
|
126
126
|
}
|
|
127
|
-
`,aP=["bold","color","font","italic","size","strike","underline","indent","list","direction"],aT=e=>new(h(oO))(e,{toolbar:!1,keyboard:!1,clipboard:{matchVisual:!1},formats:aP}),aA=(e,t)=>{var n=e.clipboard.convert("<div class='ql-editor' style='outline: none;'>"+t+"<p><br></p></div>");e.setContents(n),e.history.clear()},aj=({html:e,onBlur:t,onChange:n,element:r})=>{let i=h(C).useRef(null);h(C).useEffect(()=>{if(!i.current)return;let e=aT(i.current);return _.runInAction(()=>{ak.editor.instance=e}),window.__polotnoQuill=e,e.on("text-change",()=>{e.getSelection()&&_.runInAction(()=>{ak.currentFormat=e.getFormat()}),setTimeout(()=>{n((i.current?.childNodes[0]).innerHTML)},10)}),e.setSelection(0,0,"api"),e.on("selection-change",(t,n,r)=>{t&&_.runInAction(()=>{ak.currentFormat=e.getFormat()})}),i.current.childNodes[0].addEventListener("blur",e=>{if(!e.relatedTarget?.classList.contains("ql-clipboard")){var n;(n=e.relatedTarget)&&n.closest(".sketch-picker")||t()}}),()=>{_.runInAction(()=>{ak.editor.instance=null,ak.currentFormat={}}),delete window.__polotnoQuill}},[]),h(C).useEffect(()=>{let t=ak.editor.instance;if(!t)return;let n=t.getSelection();i.current?.childNodes[0].innerHTML!==r.text&&(aA(t,e),n&&(t.setSelection(n.index,n.length),_.runInAction(()=>{ak.currentFormat=t.getFormat()})))},[r.text]);let o={color:r.fill};return r.fill.indexOf("gradient")>=0&&(o.backgroundColor=r.fill,o.backgroundImage=r.fill,o.backgroundSize="100% 100%",o.backgroundRepeat="repeat",o.webkitBackgroundClip="text",o.MozBackgroundClip="text",o.WebkitTextFillColor="transparent",o.MozTextFillColor="transparent"),(0,b.jsx)(aO,{ref:i,style:{...o,fontSize:r.fontSize,fontWeight:r.fontWeight,width:r.a.width,fontFamily:r.fontFamily,lineHeight:r.lineHeight,letterSpacing:r.letterSpacing*r.fontSize+"px",textAlign:r.align},dir:iX(iD(r.text))})},aN=(e,t=100,n=!1)=>{let[
|
|
127
|
+
`,aP=["bold","color","font","italic","size","strike","underline","indent","list","direction"],aT=e=>new(h(oO))(e,{toolbar:!1,keyboard:!1,clipboard:{matchVisual:!1},formats:aP}),aA=(e,t)=>{var n=e.clipboard.convert("<div class='ql-editor' style='outline: none;'>"+t+"<p><br></p></div>");e.setContents(n),e.history.clear()},aj=({html:e,onBlur:t,onChange:n,element:r})=>{let i=h(C).useRef(null);h(C).useEffect(()=>{if(!i.current)return;let e=aT(i.current);return _.runInAction(()=>{ak.editor.instance=e}),window.__polotnoQuill=e,e.on("text-change",()=>{e.getSelection()&&_.runInAction(()=>{ak.currentFormat=e.getFormat()}),setTimeout(()=>{n((i.current?.childNodes[0]).innerHTML)},10)}),e.setSelection(0,0,"api"),e.on("selection-change",(t,n,r)=>{t&&_.runInAction(()=>{ak.currentFormat=e.getFormat()})}),i.current.childNodes[0].addEventListener("blur",e=>{if(!e.relatedTarget?.classList.contains("ql-clipboard")){var n;(n=e.relatedTarget)&&n.closest(".sketch-picker")||t()}}),()=>{_.runInAction(()=>{ak.editor.instance=null,ak.currentFormat={}}),delete window.__polotnoQuill}},[]),h(C).useEffect(()=>{let t=ak.editor.instance;if(!t)return;let n=t.getSelection();i.current?.childNodes[0].innerHTML!==r.text&&(aA(t,e),n&&(t.setSelection(n.index,n.length),_.runInAction(()=>{ak.currentFormat=t.getFormat()})))},[r.text]);let o={color:r.fill};return r.fill.indexOf("gradient")>=0&&(o.backgroundColor=r.fill,o.backgroundImage=r.fill,o.backgroundSize="100% 100%",o.backgroundRepeat="repeat",o.webkitBackgroundClip="text",o.MozBackgroundClip="text",o.WebkitTextFillColor="transparent",o.MozTextFillColor="transparent"),(0,b.jsx)(aO,{ref:i,style:{...o,fontSize:r.fontSize,fontWeight:r.fontWeight,width:r.a.width,fontFamily:r.fontFamily,lineHeight:r.lineHeight,letterSpacing:r.letterSpacing*r.fontSize+"px",textAlign:r.align},dir:iX(iD(r.text))})},aN=(e,t=100,n=!1,r="")=>{let[i,o]=h(C).useState(e),a=h(C).useRef(null);return h(C).useEffect(()=>{if(e===n){a.current&&(clearTimeout(a.current),a.current=null),o(n);return}return a.current&&clearTimeout(a.current),a.current=setTimeout(()=>{o(e),a.current=null},t),()=>{a.current&&clearTimeout(a.current)}},[e,t]),[i,o]};function aR(e,{fontFamily:t="",color:n="black"}={}){var r;let i=`color: ${n||e.fill}`;e.fill.indexOf("gradient")>=0&&(i=`
|
|
128
128
|
background-color: ${n};
|
|
129
129
|
background-image: ${e.fill};
|
|
130
130
|
background-size: 100% 100%;
|
|
@@ -133,7 +133,7 @@ For more info see: https://github.com/konvajs/react-konva/issues/194
|
|
|
133
133
|
-moz-background-clip: text;
|
|
134
134
|
-webkit-text-fill-color: transparent;
|
|
135
135
|
-moz-text-fill-color: transparent;
|
|
136
|
-
`);let o=["white-space: pre-wrap",`width: ${Math.round(e.width||100)}px`,i,`font-size: ${e.fontSize}px`,`font-family: '${t}'`,`text-align: ${e.align}`,e.textDecoration?`text-decoration: ${e.textDecoration}; text-decoration-color: ${n||e.fill}; text-decoration-layer: over`:"",e.lineHeight?`line-height: ${e.lineHeight}`:"",e.letterSpacing?`letter-spacing: ${e.letterSpacing*e.fontSize}px`:"",e.fontStyle?`font-style: ${e.fontStyle}`:"",e.fontWeight?`font-weight: ${e.fontWeight}`:"",e.strokeWidth?`-webkit-text-stroke: ${e.strokeWidth}px ${e.stroke}`:"",e.strokeWidth?"paint-order: stroke fill":""].filter(Boolean).join("; ");return`<div style="${o}" contentEditable dir="${iX(iD(e.text))}">${((r=e.text)?/<[a-z][a-z0-9]*(\s[^>]*)?>[^<]*<\/[a-z][a-z0-9]*>/i.test(r)?r=(r=r.replace(/<(?![a-z/!])/gi,"<")).replace(/([^a-z0-9"'\s/])>/gi,"$1>"):r.replace(/</g,"<").replace(/>/g,">"):"").replace(/\n/g,"</br>")}</div>`}let aL=e=>{let t=e.fontSize;for(let n=1;n<50;n++){let n=aR({...e.toJSON(),fontSize:t},{fontFamily:e.fontFamily}),{height:r}=ac(n),i=e.height&&r>e.height,o=function({html:e}){let 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",t.style.whiteSpace="nowrap",t.style.visibility="hidden";let n=au();n.appendChild(t);let r=t.textContent,i=t.childNodes[0],o=r.split(/\s+/),a=!1;for(let e=0;e<o.length&&(i.textContent=o[e],!(a=i.scrollWidth>t.clientWidth));e++);return n.removeChild(t),a}({html:n});if(!(i||o))break;t-=.5}return t},aM=/^((?!chrome|android).)*safari/i.test(navigator.userAgent),aI=R(({element:e,store:t})=>{let n=h(C).useRef(null),[r,i]=h(C).useState(),[o,a]=h(C).useState(!1),[l,s]=h(C).useState(!0),[u,c]=h(C).useState(!1),d=h(C).useRef(e.height),f=t.selectedShapes.indexOf(e)>=0&&e.selectable,p=e.fontSize/3,{textVerticalResizeEnabled:g}=iL,m=i2(e.fontFamily),[v]=i0(t,e.fontFamily),y=e._editModeEnabled;ip(n);let x=v?e.fontFamily:m!==e.fontFamily?m:"Arial",w=id(e).fill,S=aR(e,{fontFamily:x,color:w}),{width:E,height:k}=h(C).useMemo(()=>ac(S),[S,e.width,v]);h(C).useEffect(()=>{if(!v)return;if(!e.height){e.set({height:k});return}let{textOverflow:n}=iL;if("change-font-size"!==n||o)"resize"!==n||(g&&e.height<k&&t.history.ignore(()=>{e.set({height:k})}),g||e.height===k||t.history.ignore(()=>{e.set({height:k})}));else{let n=aL(e);n!==e.fontSize?t.history.ignore(()=>{e.set({fontSize:n})}):e.height===k||(g&&e.height<k?t.history.ignore(()=>{e.set({height:k})}):g||t.history.ignore(()=>{e.set({height:k})}))}});let O=h(C).useRef(0),P=h(C).useMemo(()=>{let e={lastArgs:null,lastResult:null};return async function(t){return e.lastArgs&&e.lastResult&&JSON.stringify(e.lastArgs)===JSON.stringify(t)||(e.lastResult=await ap(t),e.lastArgs={...t}),e.lastResult}},[]),T=async()=>{O.current++;let n=O.current,r=iy(`text ${e.id}`);s(!0);let o=null,a=aM?5:1;for(let i=0;i<a;i++){let a=i>0?P:ap;try{var l;if(o=await a({skipCache:i>0,html:S,width:e.width||1,height:e.height||k||1,fontFamily:x,padding:p,pixelRatio:t._elementsPixelRatio,font:t.fonts.find(e=>e.fontFamily===x)||iE.find(e=>e.fontFamily===x)}),n!==O.current){r();return}if(l=o,!function(e){let t=e.getContext("2d").getImageData(0,0,e.width,e.height).data;for(let e=0;e<t.length;e+=4)if(0!==t[e+3])return!0;return!1}(l)&&aM){await new Promise(e=>setTimeout(e,50*(i+1)));continue}}catch(t){iw(`Error rendering rich text with id ${e.id}`);break}}if(!o){r();return}i(o),s(!1),h(M).Util.requestAnimFrame(r)};h(C).useEffect(()=>{o||y||T()},[S,o,k,y,x,e.height,t._elementsPixelRatio,v]);let[A,j]=aN(l),[N]=aN(o,100,!0),R=N||A;h(C).useEffect(()=>_.autorun(()=>{iF(n.current,e)}),[r,R,e.shadowColor,e.shadowOffsetX,e.shadowOffsetY,e.shadowOpacity]);let L=0;"middle"===e.verticalAlign&&(L=(e.height-k)/2),"bottom"===e.verticalAlign&&(L=e.height-k);let I=i1({fontLoaded:v,fontFamily:e.fontFamily,fontSize:e.fontSize,lineHeight:e.lineHeight}),D=iG();return(0,b.jsxs)(h(C).Fragment,{children:[(0,b.jsx)(rX,{x:e.a.x,y:e.a.y,offsetX:e.backgroundPadding*(e.fontSize*I*.5),offsetY:e.backgroundPadding*(e.fontSize*I*.5),rotation:e.a.rotation,hideInExport:!e.showInExport,listening:!1,visible:e.backgroundEnabled,opacity:e.backgroundOpacity*e.a.opacity,fill:e.backgroundColor,width:e.a.width+e.backgroundPadding*(e.fontSize*I),height:e.a.height+e.backgroundPadding*(e.fontSize*I),cornerRadius:e.backgroundCornerRadius*(e.fontSize*I*.5)}),(0,b.jsx)(rX,{ref:n,name:"element",x:e.a.x,y:e.a.y,listening:e.selectable,rotation:e.a.rotation,width:e.a.width,height:e.a.height,visible:!R,draggable:D?e.draggable&&f:e.draggable,preventDefault:!D||f,opacity:y?0:e.a.opacity,hideInExport:!e.showInExport,onMouseEnter:()=>{c(!0)},onMouseLeave:()=>{c(!1)},onDragMove:t=>{e.set({x:t.target.x(),y:t.target.y()})},onDragEnd:t=>{e.set({x:t.target.x(),y:t.target.y()})},id:e.id,onDblClick:()=>{e.contentEditable&&e.toggleEditMode(!0)},onDblTap:()=>{e.contentEditable&&e.toggleEditMode(!0)},onTransformStart:t=>{a(!0),d.current=e.height},onTransform:t=>{let n=t.target,r=(n.getStage()?.findOne("Transformer")).getActiveAnchor(),i=n.scaleX();if("middle-left"===r||"middle-right"===r){let t=n.scaleX(),r=Math.max(n.width()*t,e.fontSize);if(n.width(r),n.scaleX(1),iL.textVerticalResizeEnabled){let t=Math.max(k,d.current);e.set({height:t})}e.set({width:r,x:n.x(),y:n.y()})}else if("top-center"===r||"bottom-center"===r){let r=Math.max("resize"===iL.textOverflow?k:e.lineHeight*e.fontSize,t.target.height()*t.target.scaleY());n.scaleY(1),e.set({x:n.x(),y:n.y(),height:r,rotation:n.rotation()})}else n.scaleX(1),n.scaleY(1),e.set({fontSize:e.fontSize*i,letterSpacing:e.letterSpacing,width:n.width()*i,x:n.x(),y:n.y(),rotation:n.rotation(),height:n.height()*i})},onTransformEnd:t=>{a(!1),s(!0);let n=t.target.scaleX();t.target.scaleX(1),t.target.scaleY(1),e.set({fontSize:e.fontSize*n,width:t.target.width()*n,x:t.target.x(),y:t.target.y(),rotation:t.target.rotation(),shadowBlur:e.shadowBlur*n,shadowOffsetX:e.shadowOffsetX*n,shadowOffsetY:e.shadowOffsetY*n,strokeWidth:e.strokeWidth*n})}}),(0,b.jsx)(rQ,{ref:n,image:r,x:e.a.x,y:e.a.y,offsetX:p,offsetY:p-L,listening:!1,rotation:e.rotation,width:e.a.width+2*p,height:e.a.height+2*p,visible:!R,opacity:y?0:e.a.opacity,shadowEnabled:e.shadowEnabled,shadowBlur:e.shadowBlur,shadowOffsetX:e.shadowOffsetX,shadowOffsetY:e.shadowOffsetY,shadowColor:e.shadowColor,shadowOpacity:e.shadowOpacity,hideInExport:!e.showInExport}),R&&(0,b.jsx)(rK,{x:e.a.x,y:e.a.y,rotation:e.rotation,offsetY:-L,children:(0,b.jsx)(r5,{divProps:{style:{pointerEvents:"none"}},children:(0,b.jsx)(aO,{dangerouslySetInnerHTML:{__html:S},style:{pointerEvents:"none",display:"inline-block"}})})}),y&&(0,b.jsx)(rK,{x:e.a.x,y:e.a.y,rotation:e.rotation,offsetY:-L,children:(0,b.jsx)(r5,{children:(0,b.jsx)(aj,{html:S,element:e,onChange:t=>{let n=i$({oldText:iD(e.text),newText:iD(t),element:e});e.set({text:t,fontSize:n}),j(!0)},onBlur:t=>{e.toggleEditMode(!1)}})})}),(f||u)&&(0,b.jsx)(iH,{element:e})]})});var C=(v("8NFma"),v("8NFma"));function aD(e){return e/180*Math.PI}function az(e,t,n,r,i){let o=Math.sqrt(n*n+r*r);return{x:e+o*Math.cos(i+=Math.atan2(r,n)),y:t+o*Math.sin(i)}}function aF(e){let{x:t,y:n,width:r,height:i}=e,o=aD(e.rotation),a=az(t,n,0,0,o),l=az(t,n,r,0,o),s=az(t,n,r,i,o),u=az(t,n,0,i,o),c=Math.min(a.x,l.x,s.x,u.x),d=Math.min(a.y,l.y,s.y,u.y),h=Math.max(a.x,l.x,s.x,u.x),f=Math.max(a.y,l.y,s.y,u.y);return{x:c,y:d,width:h-c,height:f-d,minX:c,minY:d,maxX:h,maxY:f}}function aB(e){let t=e.map(e=>aF(e)),n=Math.min(...t.map(e=>e.minX)),r=Math.min(...t.map(e=>e.minY)),i=Math.max(...t.map(e=>e.maxX)),o=Math.max(...t.map(e=>e.maxY));return{x:n,y:r,width:i-n,height:o-r,minX:n,minY:r,maxX:i,maxY:o}}let aH=({targetKonvaNodes:e,guideKonvaNode:t,distance:n,snapDirection:r})=>n<5;function aV(e,t){var n=[],r=[];e.vertical.forEach(e=>{t.vertical.forEach(t=>{var r=Math.abs(e.offset-t.guide);aH({targetKonvaNodes:t.nodes,guideKonvaNode:e.node,distance:r,snapDirection:e.snap})&&n.push({lineGuide:e.offset,diff:r,snap:t.snap,offset:t.offset})})}),e.horizontal.forEach(e=>{t.horizontal.forEach(t=>{var n=Math.abs(e.offset-t.guide);aH({targetKonvaNodes:t.nodes,guideKonvaNode:e.node,distance:n,snapDirection:e.snap})&&r.push({lineGuide:e.offset,diff:n,snap:t.snap,offset:t.offset})})});var i=[];let o=n.sort((e,t)=>e.diff-t.diff),a=r.sort((e,t)=>e.diff-t.diff);var l=o[0],s=a[0];return l&&o.filter(e=>.1>Math.abs(e.diff-l.diff)).forEach(e=>{i.push({orientation:"V",...e})}),s&&a.filter(e=>.1>Math.abs(e.diff-s.diff)).forEach(e=>{i.push({orientation:"H",...e})}),i}function aU(e,t,n){let r=e=>e.hasName("element")||e.hasName("line-anchor")||e.hasName("page-background")||e.hasName("elements-area"),i=n=>{let i=n.target.getLayer().children.find(e=>"line-guides"===e.name());i?.destroyChildren();var o,a=aV(function(t){let n=e.current?.getStage();var i=[],o=[];return n.find(r).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}),i.push({offset:n.x,node:e,snap:"start"},{offset:n.x+n.width,node:e,snap:"end"},{offset:n.x+n.width/2,node:e,snap:"center"}),o.push({offset:n.y,node:e,snap:"start"},{offset:n.y+n.height,node:e,snap:"end"},{offset:n.y+n.height/2,node:e,snap:"center"})}}),{vertical:i,horizontal:o}}([n.target,...t.map(e=>e.current)]),{vertical:[{guide:(o=n.target).absolutePosition().x,offset:0,snap:"center",nodes:[o]}],horizontal:[{guide:o.absolutePosition().y,offset:0,snap:"center",nodes:[o]}]});if(!a.length)return;!function(t){let n=e.current?.getLayer(),r=n?.children.find(e=>"line-guides"===e.name());t.forEach(e=>{if("H"===e.orientation){var t=new(h(M)).Line({points:[-6e3,e.lineGuide,6e3,e.lineGuide],stroke:"rgb(0, 161, 255)",strokeWidth:1,name:"guid-line",dash:[4,6]});r?.add(t),n.batchDraw()}else if("V"===e.orientation){var t=new(h(M)).Line({points:[e.lineGuide,-6e3,e.lineGuide,6e3],stroke:"rgb(0, 161, 255)",strokeWidth:1,name:"guid-line",dash:[4,6]});r?.add(t)}})}(a);let l=n.target.getAbsolutePosition(),s={...l};a.forEach(e=>{switch(e.snap){case"start":case"center":case"end":switch(e.orientation){case"V":s.x=e.lineGuide+e.offset;break;case"H":s.y=e.lineGuide+e.offset}}});let u=s.x-l.x,c=s.y-l.y;if(!(n.evt.ctrlKey||n.evt.metaKey)){let e=n.target.getAbsolutePosition();n.target.absolutePosition({x:e.x+u,y:e.y+c})}},o=e=>{if(!e.target)return;let t=e.target.getLayer(),n=t.children.find(e=>"line-guides"===e.name());n?.destroyChildren(),t.batchDraw()};h(C).useEffect(()=>{e.current&&(e.current.on("dragmove",i),e.current.on("dragend",o))},n)}function aG(e,t){return e.x*t.x+e.y*t.y}let aq={"top-left":"bottom-right","top-center":"bottom-center","top-right":"bottom-left","middle-right":"middle-left","bottom-right":"top-left","bottom-center":"top-center","bottom-left":"top-right","middle-left":"middle-right"};function aW(e){let{x:t,y:n,width:r,height:i,rotation:o}=e.a,a=o*Math.PI/180,l={x:t+i/2*Math.cos(a+Math.PI/2),y:n+i/2*Math.sin(a+Math.PI/2)},s={x:l.x+r*Math.cos(a),y:l.y+r*Math.sin(a)};return{middleLeft:l,middleRight:s}}function a$(e,t,n){let r=Math.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2)),i=Math.atan2(t.y-e.y,t.x-e.x),o=180*i/Math.PI;return{x:e.x+Math.cos(i-Math.PI/2)*n/2,y:e.y+Math.sin(i-Math.PI/2)*n/2,width:r,height:n,rotation:o}}let aK=(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()}}),aY=R(({element:e,type:t})=>{let n=id(e,e.a.color,"fill"),r=id(e,e.a.color,"stroke"),i={strokeWidth:e.height,lineCap:"round",lineJoin:"round",...r,...n,opacity:e.a.opacity,hideInExport:!e.showInExport};return(0,b.jsxs)(b.Fragment,{children:["arrow"===t&&(0,b.jsx)(rZ,{points:[3*e.height,-(2*e.height),0,0,3*e.height,2*e.height],...i}),"triangle"===t&&(0,b.jsx)(rZ,{points:[3*e.height,-(2*e.height),0,0,3*e.height,2*e.height],closed:!0,...i}),"bar"===t&&(0,b.jsx)(rZ,{points:[0,-(2*e.height),0,2*e.height],closed:!0,...i}),"square"===t&&(0,b.jsx)(rZ,{points:[0,-(2*e.height),4*e.height,-(2*e.height),4*e.height,2*e.height,0,2*e.height],closed:!0,...i}),"circle"===t&&(0,b.jsx)("Circle",{x:2*e.height,y:0,radius:2*e.height,...i})]})}),aX=R(({element:e,store:t})=>{let n=h(C).useRef(null),r=h(C).useRef(null),i=h(C).useRef(null),o=e.selectable||"admin"===t.role,a=iG(),[l,s]=h(C).useState(!1),u=t.selectedElements.indexOf(e)>=0&&1===t.selectedElements.length,c=t.selectedShapes.indexOf(e)>=0&&e.selectable,{middleLeft:d,middleRight:f}=aW(e);aU(r,[n],[u]),aU(i,[n],[u]);let p=id(e,e.a.color,"stroke");return(0,b.jsxs)(h(C).Fragment,{children:[(0,b.jsx)(rZ,{ref:n,name:"element",id:e.id,x:e.a.x,y:e.a.y,points:[0,0,e.a.width,0],offsetY:-e.a.height/2,strokeWidth:e.a.height,hitStrokeWidth:Math.max(e.a.height,20),dash:e.dash.map(t=>t*e.a.height),...p,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:o,draggable:a?e.draggable&&c:e.draggable,preventDefault:!a||c,hideInExport:!e.showInExport,onMouseEnter:()=>{s(!0)},onMouseLeave:()=>{s(!1)},onDragMove:t=>{e.set({x:t.target.x(),y:t.target.y()})},onDragEnd:t=>{e.set({x:t.target.x(),y:t.target.y()})},onTransform:t=>{let n=t.target.scaleX();t.target.scaleX(1),t.target.scaleY(1),e.set({height:e.height*n,width:e.width*n,x:t.target.x(),y:t.target.y(),rotation:t.target.rotation()})}}),(0,b.jsx)(rK,{x:d.x,y:d.y,rotation:e.rotation,hideInExport:!e.showInExport,children:(0,b.jsx)(aY,{element:e,type:e.startHead})}),(0,b.jsx)(rK,{x:f.x,y:f.y,rotation:e.rotation+180,children:(0,b.jsx)(aY,{element:e,type:e.endHead})}),(l||c&&!u)&&(0,b.jsx)(iH,{element:e}),u&&e.resizable&&(0,b.jsx)(r9,{selector:".page-abs-container",enabled:!0,children:(0,b.jsxs)(rK,{visible:u,children:[(0,b.jsx)(rX,{x:d.x,y:d.y,ref:r,name:"line-anchor",...aK(t.scale,t),onDragMove:t=>{let n=a$(t.target.position(),f,e.height);e.set({x:n.x,y:n.y,width:n.width,rotation:n.rotation})}}),(0,b.jsx)(rX,{x:f.x,y:f.y,ref:i,name:"line-anchor",...aK(t.scale,t),onDragMove:t=>{let n=a$(d,t.target.position(),e.height);e.set({x:n.x,y:n.y,width:n.width,rotation:n.rotation})}})]})})]})});var C=v("8NFma"),_=v("2SBKn");function aZ(){return document.createElement("canvas")}async function aQ(e){return e.indexOf("data:image/svg+xml")>=0||e.indexOf(".svg")>=0?ot(or(await oe(e))):e}let aJ=e=>{let[t,n]=h(C).useState(e);return h(C).useEffect(()=>{(async()=>{let r=await aQ(e);r!==t&&n(r)})()},[e]),t},a0=new window.Image;a0.src=ot(`
|
|
136
|
+
`);let o=["white-space: pre-wrap",`width: ${Math.round(e.width||100)}px`,i,`font-size: ${e.fontSize}px`,`font-family: '${t}'`,`text-align: ${e.align}`,e.textDecoration?`text-decoration: ${e.textDecoration}; text-decoration-color: ${n||e.fill}; text-decoration-layer: over`:"",e.lineHeight?`line-height: ${e.lineHeight}`:"",e.letterSpacing?`letter-spacing: ${e.letterSpacing*e.fontSize}px`:"",e.fontStyle?`font-style: ${e.fontStyle}`:"",e.fontWeight?`font-weight: ${e.fontWeight}`:"",e.strokeWidth?`-webkit-text-stroke: ${e.strokeWidth}px ${e.stroke}`:"",e.strokeWidth?"paint-order: stroke fill":""].filter(Boolean).join("; ");return`<div style="${o}" contentEditable dir="${iX(iD(e.text))}">${((r=e.text)?/<[a-z][a-z0-9]*(\s[^>]*)?>[^<]*<\/[a-z][a-z0-9]*>/i.test(r)?r=(r=r.replace(/<(?![a-z/!])/gi,"<")).replace(/([^a-z0-9"'\s/])>/gi,"$1>"):r.replace(/</g,"<").replace(/>/g,">"):"").replace(/\n/g,"</br>")}</div>`}let aL=e=>{let t=e.fontSize;for(let n=1;n<50;n++){let n=aR({...e.toJSON(),fontSize:t},{fontFamily:e.fontFamily}),{height:r}=ac(n),i=e.height&&r>e.height,o=function({html:e}){let 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",t.style.whiteSpace="nowrap",t.style.visibility="hidden";let n=au();n.appendChild(t);let r=t.textContent,i=t.childNodes[0],o=r.split(/\s+/),a=!1;for(let e=0;e<o.length&&(i.textContent=o[e],!(a=i.scrollWidth>t.clientWidth));e++);return n.removeChild(t),a}({html:n});if(!(i||o))break;t-=.5}return t},aM=/^((?!chrome|android).)*safari/i.test(navigator.userAgent),aI=R(({element:e,store:t})=>{let n=h(C).useRef(null),[r,i]=h(C).useState(),[o,a]=h(C).useState(!1),[l,s]=h(C).useState(!0),[u,c]=h(C).useState(!1),d=h(C).useRef(e.height),f=t.selectedShapes.indexOf(e)>=0&&e.selectable,p=e.fontSize/3,{textVerticalResizeEnabled:g}=iL,m=i2(e.fontFamily),[v]=i0(t,e.fontFamily),y=e._editModeEnabled;ip(n);let x=v?e.fontFamily:m!==e.fontFamily?m:"Arial",w=id(e).fill,S=aR(e,{fontFamily:x,color:w}),{width:E,height:k}=h(C).useMemo(()=>ac(S),[S,e.width,v]);h(C).useEffect(()=>{if(!v)return;if(!e.height){e.set({height:k});return}let{textOverflow:n}=iL;if("change-font-size"!==n||o)"resize"!==n||(g&&e.height<k&&t.history.ignore(()=>{e.set({height:k})}),g||e.height===k||t.history.ignore(()=>{e.set({height:k})}));else{let n=aL(e);n!==e.fontSize?t.history.ignore(()=>{e.set({fontSize:n})}):e.height===k||(g&&e.height<k?t.history.ignore(()=>{e.set({height:k})}):g||t.history.ignore(()=>{e.set({height:k})}))}});let O=h(C).useRef(0),P=h(C).useMemo(()=>{let e={lastArgs:null,lastResult:null};return async function(t){return e.lastArgs&&e.lastResult&&JSON.stringify(e.lastArgs)===JSON.stringify(t)||(e.lastResult=await ap(t),e.lastArgs={...t}),e.lastResult}},[]),T=async()=>{O.current++;let n=O.current,r=iy(`text ${e.id}`);s(!0);let o=null,a=aM?5:1;for(let i=0;i<a;i++){let a=i>0?P:ap;try{var l;if(o=await a({skipCache:i>0,html:S,width:e.width||1,height:e.height||k||1,fontFamily:x,padding:p,pixelRatio:t._elementsPixelRatio,font:t.fonts.find(e=>e.fontFamily===x)||iE.find(e=>e.fontFamily===x)}),n!==O.current){r();return}if(l=o,!function(e){let t=e.getContext("2d").getImageData(0,0,e.width,e.height).data;for(let e=0;e<t.length;e+=4)if(0!==t[e+3])return!0;return!1}(l)&&aM){await new Promise(e=>setTimeout(e,50*(i+1)));continue}}catch(t){iw(`Error rendering rich text with id ${e.id}`);break}}if(!o){r();return}i(o),s(!1),h(M).Util.requestAnimFrame(r)};h(C).useEffect(()=>{o||y||T()},[S,o,k,y,x,e.height,t._elementsPixelRatio,v]);let[A,j]=aN(l),[N]=aN(o,100,!0),R=N||A;h(C).useEffect(()=>_.autorun(()=>{iF(n.current,e)}),[r,R,e.shadowColor,e.shadowOffsetX,e.shadowOffsetY,e.shadowOpacity]);let L=0;"middle"===e.verticalAlign&&(L=(e.height-k)/2),"bottom"===e.verticalAlign&&(L=e.height-k);let I=i1({fontLoaded:v,fontFamily:e.fontFamily,fontSize:e.fontSize,lineHeight:e.lineHeight}),D=iG();return(0,b.jsxs)(h(C).Fragment,{children:[(0,b.jsx)(rX,{x:e.a.x,y:e.a.y,offsetX:e.backgroundPadding*(e.fontSize*I*.5),offsetY:e.backgroundPadding*(e.fontSize*I*.5),rotation:e.a.rotation,hideInExport:!e.showInExport,listening:!1,visible:e.backgroundEnabled,opacity:e.backgroundOpacity*e.a.opacity,fill:e.backgroundColor,width:e.a.width+e.backgroundPadding*(e.fontSize*I),height:e.a.height+e.backgroundPadding*(e.fontSize*I),cornerRadius:e.backgroundCornerRadius*(e.fontSize*I*.5)}),(0,b.jsx)(rX,{ref:n,name:"element",x:e.a.x,y:e.a.y,listening:e.selectable,rotation:e.a.rotation,width:e.a.width,height:e.a.height,visible:!R,draggable:D?e.draggable&&f:e.draggable,preventDefault:!D||f,opacity:y?0:e.a.opacity,hideInExport:!e.showInExport,onMouseEnter:()=>{c(!0)},onMouseLeave:()=>{c(!1)},onDragMove:t=>{e.set({x:t.target.x(),y:t.target.y()})},onDragEnd:t=>{e.set({x:t.target.x(),y:t.target.y()})},id:e.id,onDblClick:()=>{e.contentEditable&&e.toggleEditMode(!0)},onDblTap:()=>{e.contentEditable&&e.toggleEditMode(!0)},onTransformStart:t=>{a(!0),d.current=e.height},onTransform:t=>{let n=t.target,r=(n.getStage()?.findOne("Transformer")).getActiveAnchor(),i=n.scaleX();if("middle-left"===r||"middle-right"===r){let t=n.scaleX(),r=Math.max(n.width()*t,e.fontSize);if(n.width(r),n.scaleX(1),iL.textVerticalResizeEnabled){let t=Math.max(k,d.current);e.set({height:t})}e.set({width:r,x:n.x(),y:n.y()})}else if("top-center"===r||"bottom-center"===r){let r=Math.max("resize"===iL.textOverflow?k:e.lineHeight*e.fontSize,t.target.height()*t.target.scaleY());n.scaleY(1),e.set({x:n.x(),y:n.y(),height:r,rotation:n.rotation()})}else n.scaleX(1),n.scaleY(1),e.set({fontSize:e.fontSize*i,letterSpacing:e.letterSpacing,width:n.width()*i,x:n.x(),y:n.y(),rotation:n.rotation(),height:n.height()*i})},onTransformEnd:t=>{a(!1),s(!0);let n=t.target.scaleX();t.target.scaleX(1),t.target.scaleY(1),e.set({fontSize:e.fontSize*n,width:t.target.width()*n,x:t.target.x(),y:t.target.y(),rotation:t.target.rotation(),shadowBlur:e.shadowBlur*n,shadowOffsetX:e.shadowOffsetX*n,shadowOffsetY:e.shadowOffsetY*n,strokeWidth:e.strokeWidth*n})}}),(0,b.jsx)(rQ,{ref:n,image:r,x:e.a.x,y:e.a.y,offsetX:p,offsetY:p-L,listening:!1,rotation:e.rotation,width:e.a.width+2*p,height:e.a.height+2*p,visible:!R,opacity:y?0:e.a.opacity,shadowEnabled:e.shadowEnabled,shadowBlur:e.shadowBlur,shadowOffsetX:e.shadowOffsetX,shadowOffsetY:e.shadowOffsetY,shadowColor:e.shadowColor,shadowOpacity:e.shadowOpacity,hideInExport:!e.showInExport}),R&&(0,b.jsx)(rK,{x:e.a.x,y:e.a.y,rotation:e.rotation,offsetY:-L,children:(0,b.jsx)(r5,{divProps:{style:{pointerEvents:"none"}},children:(0,b.jsx)(aO,{dangerouslySetInnerHTML:{__html:S},style:{pointerEvents:"none"}})})}),y&&(0,b.jsx)(rK,{x:e.a.x,y:e.a.y,rotation:e.rotation,offsetY:-L,children:(0,b.jsx)(r5,{children:(0,b.jsx)(aj,{html:S,element:e,onChange:t=>{let n=i$({oldText:iD(e.text),newText:iD(t),element:e});e.set({text:t,fontSize:n})},onBlur:t=>{e.toggleEditMode(!1),j(!0)}})})}),(f||u)&&(0,b.jsx)(iH,{element:e})]})});var C=(v("8NFma"),v("8NFma"));function aD(e){return e/180*Math.PI}function az(e,t,n,r,i){let o=Math.sqrt(n*n+r*r);return{x:e+o*Math.cos(i+=Math.atan2(r,n)),y:t+o*Math.sin(i)}}function aF(e){let{x:t,y:n,width:r,height:i}=e,o=aD(e.rotation),a=az(t,n,0,0,o),l=az(t,n,r,0,o),s=az(t,n,r,i,o),u=az(t,n,0,i,o),c=Math.min(a.x,l.x,s.x,u.x),d=Math.min(a.y,l.y,s.y,u.y),h=Math.max(a.x,l.x,s.x,u.x),f=Math.max(a.y,l.y,s.y,u.y);return{x:c,y:d,width:h-c,height:f-d,minX:c,minY:d,maxX:h,maxY:f}}function aB(e){let t=e.map(e=>aF(e)),n=Math.min(...t.map(e=>e.minX)),r=Math.min(...t.map(e=>e.minY)),i=Math.max(...t.map(e=>e.maxX)),o=Math.max(...t.map(e=>e.maxY));return{x:n,y:r,width:i-n,height:o-r,minX:n,minY:r,maxX:i,maxY:o}}let aH=({targetKonvaNodes:e,guideKonvaNode:t,distance:n,snapDirection:r})=>n<5;function aV(e,t){var n=[],r=[];e.vertical.forEach(e=>{t.vertical.forEach(t=>{var r=Math.abs(e.offset-t.guide);aH({targetKonvaNodes:t.nodes,guideKonvaNode:e.node,distance:r,snapDirection:e.snap})&&n.push({lineGuide:e.offset,diff:r,snap:t.snap,offset:t.offset})})}),e.horizontal.forEach(e=>{t.horizontal.forEach(t=>{var n=Math.abs(e.offset-t.guide);aH({targetKonvaNodes:t.nodes,guideKonvaNode:e.node,distance:n,snapDirection:e.snap})&&r.push({lineGuide:e.offset,diff:n,snap:t.snap,offset:t.offset})})});var i=[];let o=n.sort((e,t)=>e.diff-t.diff),a=r.sort((e,t)=>e.diff-t.diff);var l=o[0],s=a[0];return l&&o.filter(e=>.1>Math.abs(e.diff-l.diff)).forEach(e=>{i.push({orientation:"V",...e})}),s&&a.filter(e=>.1>Math.abs(e.diff-s.diff)).forEach(e=>{i.push({orientation:"H",...e})}),i}function aU(e,t,n){let r=e=>e.hasName("element")||e.hasName("line-anchor")||e.hasName("page-background")||e.hasName("elements-area"),i=n=>{let i=n.target.getLayer().children.find(e=>"line-guides"===e.name());i?.destroyChildren();var o,a=aV(function(t){let n=e.current?.getStage();var i=[],o=[];return n.find(r).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}),i.push({offset:n.x,node:e,snap:"start"},{offset:n.x+n.width,node:e,snap:"end"},{offset:n.x+n.width/2,node:e,snap:"center"}),o.push({offset:n.y,node:e,snap:"start"},{offset:n.y+n.height,node:e,snap:"end"},{offset:n.y+n.height/2,node:e,snap:"center"})}}),{vertical:i,horizontal:o}}([n.target,...t.map(e=>e.current)]),{vertical:[{guide:(o=n.target).absolutePosition().x,offset:0,snap:"center",nodes:[o]}],horizontal:[{guide:o.absolutePosition().y,offset:0,snap:"center",nodes:[o]}]});if(!a.length)return;!function(t){let n=e.current?.getLayer(),r=n?.children.find(e=>"line-guides"===e.name());t.forEach(e=>{if("H"===e.orientation){var t=new(h(M)).Line({points:[-6e3,e.lineGuide,6e3,e.lineGuide],stroke:"rgb(0, 161, 255)",strokeWidth:1,name:"guid-line",dash:[4,6]});r?.add(t),n.batchDraw()}else if("V"===e.orientation){var t=new(h(M)).Line({points:[e.lineGuide,-6e3,e.lineGuide,6e3],stroke:"rgb(0, 161, 255)",strokeWidth:1,name:"guid-line",dash:[4,6]});r?.add(t)}})}(a);let l=n.target.getAbsolutePosition(),s={...l};a.forEach(e=>{switch(e.snap){case"start":case"center":case"end":switch(e.orientation){case"V":s.x=e.lineGuide+e.offset;break;case"H":s.y=e.lineGuide+e.offset}}});let u=s.x-l.x,c=s.y-l.y;if(!(n.evt.ctrlKey||n.evt.metaKey)){let e=n.target.getAbsolutePosition();n.target.absolutePosition({x:e.x+u,y:e.y+c})}},o=e=>{if(!e.target)return;let t=e.target.getLayer(),n=t.children.find(e=>"line-guides"===e.name());n?.destroyChildren(),t.batchDraw()};h(C).useEffect(()=>{e.current&&(e.current.on("dragmove",i),e.current.on("dragend",o))},n)}function aG(e,t){return e.x*t.x+e.y*t.y}let aq={"top-left":"bottom-right","top-center":"bottom-center","top-right":"bottom-left","middle-right":"middle-left","bottom-right":"top-left","bottom-center":"top-center","bottom-left":"top-right","middle-left":"middle-right"};function aW(e){let{x:t,y:n,width:r,height:i,rotation:o}=e.a,a=o*Math.PI/180,l={x:t+i/2*Math.cos(a+Math.PI/2),y:n+i/2*Math.sin(a+Math.PI/2)},s={x:l.x+r*Math.cos(a),y:l.y+r*Math.sin(a)};return{middleLeft:l,middleRight:s}}function a$(e,t,n){let r=Math.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2)),i=Math.atan2(t.y-e.y,t.x-e.x),o=180*i/Math.PI;return{x:e.x+Math.cos(i-Math.PI/2)*n/2,y:e.y+Math.sin(i-Math.PI/2)*n/2,width:r,height:n,rotation:o}}let aK=(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()}}),aY=R(({element:e,type:t})=>{let n=id(e,e.a.color,"fill"),r=id(e,e.a.color,"stroke"),i={strokeWidth:e.height,lineCap:"round",lineJoin:"round",...r,...n,opacity:e.a.opacity,hideInExport:!e.showInExport};return(0,b.jsxs)(b.Fragment,{children:["arrow"===t&&(0,b.jsx)(rZ,{points:[3*e.height,-(2*e.height),0,0,3*e.height,2*e.height],...i}),"triangle"===t&&(0,b.jsx)(rZ,{points:[3*e.height,-(2*e.height),0,0,3*e.height,2*e.height],closed:!0,...i}),"bar"===t&&(0,b.jsx)(rZ,{points:[0,-(2*e.height),0,2*e.height],closed:!0,...i}),"square"===t&&(0,b.jsx)(rZ,{points:[0,-(2*e.height),4*e.height,-(2*e.height),4*e.height,2*e.height,0,2*e.height],closed:!0,...i}),"circle"===t&&(0,b.jsx)("Circle",{x:2*e.height,y:0,radius:2*e.height,...i})]})}),aX=R(({element:e,store:t})=>{let n=h(C).useRef(null),r=h(C).useRef(null),i=h(C).useRef(null),o=e.selectable||"admin"===t.role,a=iG(),[l,s]=h(C).useState(!1),u=t.selectedElements.indexOf(e)>=0&&1===t.selectedElements.length,c=t.selectedShapes.indexOf(e)>=0&&e.selectable,{middleLeft:d,middleRight:f}=aW(e);aU(r,[n],[u]),aU(i,[n],[u]);let p=id(e,e.a.color,"stroke");return(0,b.jsxs)(h(C).Fragment,{children:[(0,b.jsx)(rZ,{ref:n,name:"element",id:e.id,x:e.a.x,y:e.a.y,points:[0,0,e.a.width,0],offsetY:-e.a.height/2,strokeWidth:e.a.height,hitStrokeWidth:Math.max(e.a.height,20),dash:e.dash.map(t=>t*e.a.height),...p,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:o,draggable:a?e.draggable&&c:e.draggable,preventDefault:!a||c,hideInExport:!e.showInExport,onMouseEnter:()=>{s(!0)},onMouseLeave:()=>{s(!1)},onDragMove:t=>{e.set({x:t.target.x(),y:t.target.y()})},onDragEnd:t=>{e.set({x:t.target.x(),y:t.target.y()})},onTransform:t=>{let n=t.target.scaleX();t.target.scaleX(1),t.target.scaleY(1),e.set({height:e.height*n,width:e.width*n,x:t.target.x(),y:t.target.y(),rotation:t.target.rotation()})}}),(0,b.jsx)(rK,{x:d.x,y:d.y,rotation:e.rotation,hideInExport:!e.showInExport,children:(0,b.jsx)(aY,{element:e,type:e.startHead})}),(0,b.jsx)(rK,{x:f.x,y:f.y,rotation:e.rotation+180,children:(0,b.jsx)(aY,{element:e,type:e.endHead})}),(l||c&&!u)&&(0,b.jsx)(iH,{element:e}),u&&e.resizable&&(0,b.jsx)(r9,{selector:".page-abs-container",enabled:!0,children:(0,b.jsxs)(rK,{visible:u,children:[(0,b.jsx)(rX,{x:d.x,y:d.y,ref:r,name:"line-anchor",...aK(t.scale,t),onDragMove:t=>{let n=a$(t.target.position(),f,e.height);e.set({x:n.x,y:n.y,width:n.width,rotation:n.rotation})}}),(0,b.jsx)(rX,{x:f.x,y:f.y,ref:i,name:"line-anchor",...aK(t.scale,t),onDragMove:t=>{let n=a$(d,t.target.position(),e.height);e.set({x:n.x,y:n.y,width:n.width,rotation:n.rotation})}})]})})]})});var C=v("8NFma"),_=v("2SBKn");function aZ(){return document.createElement("canvas")}async function aQ(e){return e.indexOf("data:image/svg+xml")>=0||e.indexOf(".svg")>=0?ot(or(await oe(e))):e}let aJ=e=>{let[t,n]=h(C).useState(e);return h(C).useEffect(()=>{(async()=>{let r=await aQ(e);r!==t&&n(r)})()},[e]),t},a0=new window.Image;a0.src=ot(`
|
|
137
137
|
<svg width="800px" height="800px" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
138
138
|
<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"/>
|
|
139
139
|
<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"/>
|
package/utils/html2canvas.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const resetStyleContent = "\n p {\n margin: 0;\n padding: 0;\n word-wrap: break-word; /* Required for Firefox */\n /* a text may have several spaces, we need to preserve them */\n white-space: pre-wrap;\n }\n\n /* Reset default list styles and setup counters */\n ul, ol {\n list-style: none; /* Remove default markers */\n padding-inline-start: 0; /* Reset padding */\n margin: 0;\n display: inline-block; /* Or block, depending on desired layout */\n width: 100%;\n text-decoration: inherit;\n counter-reset: list-item; /* Initialize counter for ol */\n }\n\n li {\n position: relative; /* Needed for absolute positioning of ::before */\n padding-inline-start: 2.1em; /* Space for the marker (start side) */\n margin: 0; /* Reset default li margins */\n }\n\n li::before {\n content: ''; /* Base content */\n position: absolute;\n /* Use logical properties for positioning */\n inset-inline-start: 0; /* Position marker at the start edge (left in LTR, right in RTL) */\n top:
|
|
1
|
+
export declare const resetStyleContent = "\n p {\n margin: 0;\n padding: 0;\n word-wrap: break-word; /* Required for Firefox */\n /* a text may have several spaces, we need to preserve them */\n white-space: pre-wrap;\n }\n\n /* Reset default list styles and setup counters */\n ul, ol {\n list-style: none; /* Remove default markers */\n padding-inline-start: 0; /* Reset padding */\n margin: 0;\n display: inline-block; /* Or block, depending on desired layout */\n width: 100%;\n text-decoration: inherit;\n counter-reset: list-item; /* Initialize counter for ol */\n }\n\n li {\n position: relative; /* Needed for absolute positioning of ::before */\n padding-inline-start: 2.1em; /* Space for the marker (start side) */\n margin: 0; /* Reset default li margins */\n }\n\n li::before {\n content: ''; /* Base content */\n position: absolute;\n /* Use logical properties for positioning */\n inset-inline-start: 0; /* Position marker at the start edge (left in LTR, right in RTL) */\n top: 0; /* Adjust vertical alignment */\n /* Prevent letter-spacing from affecting the marker */\n letter-spacing: normal;\n /* Define width to ensure consistent spacing and alignment */\n display: inline-block;\n width: 2em; /* Width for the marker container */\n /* Align multi-digit numbers to the end (right in LTR, left in RTL) */\n text-align: end; \n /* Space between marker and text (using logical property) */\n margin-inline-end: 0.8em; /* Pushes text away from marker (2.5em total = 1.7em width + 0.8em margin)*/\n /* Prevent marker style from inheriting list item styles */\n font-weight: normal;\n font-style: normal;\n }\n\n /* Style for bullet points */\n ul > li::before {\n content: '\u2022'; /* Literal bullet character */\n /* Center the bullet within its allocated width */\n text-align: center; /* Override text-align: end for bullets */\n font-size: 1.2em;\n top: 0em; /* Re-adjust vertical alignment for bullet */\n /* Bullets don't need number alignment, width can be tighter */\n width: 2em;\n /* Adjust margin to maintain overall padding */\n margin-inline-end: 1.5em; /* 2.5em total padding = 1em width + 1.5em margin */\n }\n\n /* Style for numbers using counter */\n ol > li {\n counter-increment: list-item; /* Increment counter for each li in ol */\n }\n\n ol > li::before {\n content: counter(list-item) \".\"; /* Display counter value + dot */\n }\n\n .ql-indent-1 {\n margin-inline-start: 0.5em;\n }\n .ql-indent-2 {\n margin-inline-start: 1em;\n }\n .ql-indent-3 {\n margin-inline-start: 1.5em;\n }\n";
|
|
2
2
|
export declare const prerenderFont: (fontFamily: string) => Promise<void>;
|
|
3
3
|
export declare function isContentWrapping({ html }: {
|
|
4
4
|
html: any;
|
package/utils/html2canvas.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var e,t=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]}),n=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||(e=function(t){return e=Object.getOwnPropertyNames||function(e){var t=[];for(var n in e){Object.prototype.hasOwnProperty.call(e,n)&&(t[t.length]=n)}return t},e(t)},function(i){if(i&&i.__esModule){return i}var o={};if(null!=i){for(var r=e(i),l=0;l<r.length;l++){"default"!==r[l]&&t(o,i,r[l])}}return n(o,i),o});Object.defineProperty(exports,"__esModule",{value:!0}),exports.prerenderFont=exports.resetStyleContent=void 0,exports.isContentWrapping=function({html: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",t.style.whiteSpace="nowrap",t.style.visibility="hidden";const n=d();n.appendChild(t);const i=t.textContent,o=t.childNodes[0],r=i.split(/\s+/);let l=!1;for(let s=0;s<r.length;s++){const e=r[s];if(o.textContent=e,l=o.scrollWidth>t.clientWidth,l){break}}return n.removeChild(t),l},exports.detectSize=function(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";const n=d();n.appendChild(t);const i=t.getBoundingClientRect();return n.removeChild(t),{width:i.width,height:i.height}},exports.htmlToCanvas=async function({html:e,width:t,height:n,fontFamily:i,padding:a,font:d,pixelRatio:c}){if("Arial"!==i&&!d){const t=(0,r.getGoogleFontsVariants)();e+=`<link type="text/css" href="https://fonts.googleapis.com/css?family=${i}:${t}" rel="stylesheet">`}if(d){const t=d.styles||(d.url?[{src:`url("${d.url}")`}]:p(i));e+="<style>",t.forEach((t=>{e+=`\n @font-face {\n font-family: '${i}';\n src: ${t.src};\n font-style: ${t.fontStyle||"normal"};\n font-weight: ${t.fontWeight||"normal"};\n }\n `})),e+="</style>"}e+=s;const
|
|
1
|
+
var e,t=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]}),n=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||(e=function(t){return e=Object.getOwnPropertyNames||function(e){var t=[];for(var n in e){Object.prototype.hasOwnProperty.call(e,n)&&(t[t.length]=n)}return t},e(t)},function(i){if(i&&i.__esModule){return i}var o={};if(null!=i){for(var r=e(i),l=0;l<r.length;l++){"default"!==r[l]&&t(o,i,r[l])}}return n(o,i),o});Object.defineProperty(exports,"__esModule",{value:!0}),exports.prerenderFont=exports.resetStyleContent=void 0,exports.isContentWrapping=function({html: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",t.style.whiteSpace="nowrap",t.style.visibility="hidden";const n=d();n.appendChild(t);const i=t.textContent,o=t.childNodes[0],r=i.split(/\s+/);let l=!1;for(let s=0;s<r.length;s++){const e=r[s];if(o.textContent=e,l=o.scrollWidth>t.clientWidth,l){break}}return n.removeChild(t),l},exports.detectSize=function(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";const n=d();n.appendChild(t);const i=t.getBoundingClientRect();return n.removeChild(t),{width:i.width,height:i.height}},exports.htmlToCanvas=async function({html:e,width:t,height:n,fontFamily:i,padding:a,font:d,pixelRatio:c}){if("Arial"!==i&&!d){const t=(0,r.getGoogleFontsVariants)();e+=`<link type="text/css" href="https://fonts.googleapis.com/css?family=${i}:${t}" rel="stylesheet">`}if(d){const t=d.styles||(d.url?[{src:`url("${d.url}")`}]:p(i));e+="<style>",t.forEach((t=>{e+=`\n @font-face {\n font-family: '${i}';\n src: ${t.src};\n font-style: ${t.fontStyle||"normal"};\n font-weight: ${t.fontWeight||"normal"};\n }\n `})),e+="</style>"}e+=s;const u=document.createElement("canvas"),f=await o.drawHTML(`<div style="padding: ${a}px;" dir="auto">${e}</div>`,u,{width:t+2*a,height:n+2*a,cacheBucket:m});(0,l.trySetCanvasSize)(u,(t+2*a)*c,(n+2*a)*c);const h=u.getContext("2d");return null==h||h.drawImage(f.image,0,0,u.width,u.height),u};const o=i(require("rasterizehtml")),r=require("./fonts"),l=require("./canvas");exports.resetStyleContent="\n p {\n margin: 0;\n padding: 0;\n word-wrap: break-word; /* Required for Firefox */\n /* a text may have several spaces, we need to preserve them */\n white-space: pre-wrap;\n }\n\n /* Reset default list styles and setup counters */\n ul, ol {\n list-style: none; /* Remove default markers */\n padding-inline-start: 0; /* Reset padding */\n margin: 0;\n display: inline-block; /* Or block, depending on desired layout */\n width: 100%;\n text-decoration: inherit;\n counter-reset: list-item; /* Initialize counter for ol */\n }\n\n li {\n position: relative; /* Needed for absolute positioning of ::before */\n padding-inline-start: 2.1em; /* Space for the marker (start side) */\n margin: 0; /* Reset default li margins */\n }\n\n li::before {\n content: ''; /* Base content */\n position: absolute;\n /* Use logical properties for positioning */\n inset-inline-start: 0; /* Position marker at the start edge (left in LTR, right in RTL) */\n top: 0; /* Adjust vertical alignment */\n /* Prevent letter-spacing from affecting the marker */\n letter-spacing: normal;\n /* Define width to ensure consistent spacing and alignment */\n display: inline-block;\n width: 2em; /* Width for the marker container */\n /* Align multi-digit numbers to the end (right in LTR, left in RTL) */\n text-align: end; \n /* Space between marker and text (using logical property) */\n margin-inline-end: 0.8em; /* Pushes text away from marker (2.5em total = 1.7em width + 0.8em margin)*/\n /* Prevent marker style from inheriting list item styles */\n font-weight: normal;\n font-style: normal;\n }\n\n /* Style for bullet points */\n ul > li::before {\n content: '•'; /* Literal bullet character */\n /* Center the bullet within its allocated width */\n text-align: center; /* Override text-align: end for bullets */\n font-size: 1.2em;\n top: 0em; /* Re-adjust vertical alignment for bullet */\n /* Bullets don't need number alignment, width can be tighter */\n width: 2em;\n /* Adjust margin to maintain overall padding */\n margin-inline-end: 1.5em; /* 2.5em total padding = 1em width + 1.5em margin */\n }\n\n /* Style for numbers using counter */\n ol > li {\n counter-increment: list-item; /* Increment counter for each li in ol */\n }\n\n ol > li::before {\n content: counter(list-item) \".\"; /* Display counter value + dot */\n }\n\n .ql-indent-1 {\n margin-inline-start: 0.5em;\n }\n .ql-indent-2 {\n margin-inline-start: 1em;\n }\n .ql-indent-3 {\n margin-inline-start: 1.5em;\n }\n";const s=`\n<style>\n html, body {\n padding: 0;\n margin: 0;\n }\n ${exports.resetStyleContent}\n</style>\n`;let a;const d=()=>(a||(a=document.createElement("div"),a.id="polotno-hidden-do-not-touch",a.style.overflow="hidden",a.style.position="relative",document.body.appendChild(a),a.innerHTML=`<style>#polotno-hidden-do-not-touch {${exports.resetStyleContent}}</style>`),a),c=new Map,u=navigator.userAgent.includes("Firefox");exports.prerenderFont=async e=>{if(c.has(e)){return c.get(e)}const t=(async()=>{const t=`<div style="font-family: ${e}; font-size: 100px;">${e}<strong>${e}</strong></div>`,n=document.createElement("div");n.innerHTML=t,n.style.visibility="hidden",n.style.position="absolute";const i=d();i.appendChild(n);const o=u?180:50;await new Promise((e=>setTimeout(e,o))),i.removeChild(n)})();return c.set(e,t),t};const m={},f={},p=e=>{if(f[e]){return f[e]}const t=function(e){const t=[];for(const i of document.styleSheets){try{for(const n of i.cssRules){n instanceof CSSFontFaceRule&&n.style.fontFamily.replace(/['"]/g,"")===e&&t.push(n)}}catch(n){console.warn(`Could not access stylesheet: ${i.href}`,n)}}return t}(e),n=t.filter((t=>t.style.fontFamily.replace(/['"]/g,"")===e)).map((e=>({src:e.style.src,fontStyle:e.style.fontStyle||"normal",fontWeight:e.style.fontWeight||"normal"})));return f[e]=n,n};
|
package/utils/validate-key.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var e,t=this&&this.__createBinding||(Object.create?function(e,t,o,n){void 0===n&&(n=o);var r=Object.getOwnPropertyDescriptor(t,o);r&&!("get"in r?!t.__esModule:r.writable||r.configurable)||(r={enumerable:!0,get:function(){return t[o]}}),Object.defineProperty(e,n,r)}:function(e,t,o,n){void 0===n&&(n=o),e[n]=t[o]}),o=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),n=this&&this.__importStar||(e=function(t){return e=Object.getOwnPropertyNames||function(e){var t=[];for(var o in e){Object.prototype.hasOwnProperty.call(e,o)&&(t[t.length]=o)}return t},e(t)},function(n){if(n&&n.__esModule){return n}var r={};if(null!=n){for(var i=e(n),a=0;a<i.length;a++){"default"!==i[a]&&t(r,n,i[a])}}return o(r,n),r});Object.defineProperty(exports,"__esModule",{value:!0}),exports.__=exports.getKey=exports.isCreditVisible=exports.___=void 0,exports.isKeyPaid=w,exports.validateKey=async function(e,t){u=e,await w(e)&&!t||c()};const r=n(require("mobx")),i=require("./api"),a=require("./flags"),s=r.observable({value:!1}),l=r.observable({value:"v1"});exports.___=()=>l.value,exports.isCreditVisible=()=>s.value;const c=r.action((()=>{s.value=!0}));let u="";exports.getKey=()=>u||"";const d=5,p=3e3,g="Polotno API is initialized without API key. It may lead to unexpected behavior and stop working. Please create API key here: https://polotno.com/cabinet",v="Polotno API key is not valid. Please get new API key here: https://polotno.com/cabinet",f="Can not validate Polotno API key. Please report to anton@polotno.com immediately.",b="%cPolotno Free Version. Development or non-commercial usage only. https://polotno.com/";let _=window.location.origin;const m=navigator.userAgent.indexOf("Headless")>-1,h=navigator.userAgent.indexOf("Electron")>-1;"file://"===_&&m&&(_="headless"),"file://"===_&&h&&(_="electron");const y=`%cPolotno error! Current domain is not allowed. It may lead to unexpected behavior and stop working. Please add "${_}" here: https://polotno.com/cabinet`;let P=fetch;async function w(e){for(let o=0;o<d;o++){try{const t=await P((0,i.getAPI)()+"/validate-key",{method:"POST",body:JSON.stringify({key:e,site:location.host,skdVersion:"2.21.
|
|
1
|
+
var e,t=this&&this.__createBinding||(Object.create?function(e,t,o,n){void 0===n&&(n=o);var r=Object.getOwnPropertyDescriptor(t,o);r&&!("get"in r?!t.__esModule:r.writable||r.configurable)||(r={enumerable:!0,get:function(){return t[o]}}),Object.defineProperty(e,n,r)}:function(e,t,o,n){void 0===n&&(n=o),e[n]=t[o]}),o=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),n=this&&this.__importStar||(e=function(t){return e=Object.getOwnPropertyNames||function(e){var t=[];for(var o in e){Object.prototype.hasOwnProperty.call(e,o)&&(t[t.length]=o)}return t},e(t)},function(n){if(n&&n.__esModule){return n}var r={};if(null!=n){for(var i=e(n),a=0;a<i.length;a++){"default"!==i[a]&&t(r,n,i[a])}}return o(r,n),r});Object.defineProperty(exports,"__esModule",{value:!0}),exports.__=exports.getKey=exports.isCreditVisible=exports.___=void 0,exports.isKeyPaid=w,exports.validateKey=async function(e,t){u=e,await w(e)&&!t||c()};const r=n(require("mobx")),i=require("./api"),a=require("./flags"),s=r.observable({value:!1}),l=r.observable({value:"v1"});exports.___=()=>l.value,exports.isCreditVisible=()=>s.value;const c=r.action((()=>{s.value=!0}));let u="";exports.getKey=()=>u||"";const d=5,p=3e3,g="Polotno API is initialized without API key. It may lead to unexpected behavior and stop working. Please create API key here: https://polotno.com/cabinet",v="Polotno API key is not valid. Please get new API key here: https://polotno.com/cabinet",f="Can not validate Polotno API key. Please report to anton@polotno.com immediately.",b="%cPolotno Free Version. Development or non-commercial usage only. https://polotno.com/";let _=window.location.origin;const m=navigator.userAgent.indexOf("Headless")>-1,h=navigator.userAgent.indexOf("Electron")>-1;"file://"===_&&m&&(_="headless"),"file://"===_&&h&&(_="electron");const y=`%cPolotno error! Current domain is not allowed. It may lead to unexpected behavior and stop working. Please add "${_}" here: https://polotno.com/cabinet`;let P=fetch;async function w(e){for(let o=0;o<d;o++){try{const t=await P((0,i.getAPI)()+"/validate-key",{method:"POST",body:JSON.stringify({key:e,site:location.host,skdVersion:"2.21.11"})});if(l.value=t.headers.get("x-api-version"),!e){return console.warn(g),!1}if(200!==t.status){await new Promise((e=>setTimeout(e,p)));continue}const o=await t.json();return o.is_valid||console.warn(v),o.is_paid||console.log(b,"background: rgb(0, 161, 255); color: white; padding: 5px; margin: 5px;"),o.is_domain_valid||console.log(y,"background: rgba(247, 101, 68, 1); color: white; padding: 5px; margin: 5px;"),(0,a.useRemoveBackground)(o.remove_background_enabled),o.is_paid||!1}catch(t){await new Promise((e=>setTimeout(e,p)))}}return console.error(f),!0}exports.__=e=>{P=e};
|