polotno 4.9.0 → 4.11.0
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/downscale.d.ts +8 -1
- package/canvas/downscale.js +1 -1
- package/canvas/figure-element.js +1 -1
- package/canvas/gif-element.js +1 -1
- package/canvas/html-element.js +1 -1
- package/canvas/image-element.d.ts +14 -1
- package/canvas/image-element.js +1 -1
- package/canvas/line-element.js +1 -1
- package/canvas/page-controls.js +1 -1
- package/canvas/page.js +1 -1
- package/canvas/render-tag-element.js +1 -1
- package/canvas/rich-editor.js +3 -3
- package/canvas/table-element.js +1 -1
- package/canvas/text-element.js +1 -1
- package/canvas/use-mediabunny-video.js +1 -1
- package/canvas/use-transformer-snap.js +1 -1
- package/canvas/video-element.js +1 -1
- package/model/store.js +1 -1
- package/package.json +7 -7
- package/polotno.bundle.js +143 -150
- package/primitives/tooltip.js +1 -1
- package/side-panel/size-panel.js +1 -1
- package/toolbar/duplicate-button.js +1 -1
- package/toolbar/html-toolbar.js +2 -2
- package/toolbar/lock-button.js +1 -1
- package/toolbar/opacity-picker.js +1 -1
- package/toolbar/remove-button.js +1 -1
- package/toolbar/text-toolbar.js +1 -1
- package/utils/canvas.d.ts +1 -0
- package/utils/canvas.js +1 -1
- package/utils/from-svg.js +1 -1
- package/utils/px.d.ts +20 -0
- package/utils/px.js +1 -1
- package/utils/validate-key.js +1 -1
- package/utils/list-marker-geometry.d.ts +0 -1
- package/utils/list-marker-geometry.js +0 -1
package/canvas/downscale.d.ts
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
1
|
type DownscaleSource = HTMLCanvasElement | HTMLImageElement | HTMLVideoElement;
|
|
2
|
-
export declare
|
|
2
|
+
export declare const RESAMPLE_SKIP_THRESHOLD = 0.95;
|
|
3
|
+
export interface SourceRegion {
|
|
4
|
+
x: number;
|
|
5
|
+
y: number;
|
|
6
|
+
width: number;
|
|
7
|
+
height: number;
|
|
8
|
+
}
|
|
9
|
+
export declare function resampleCanvas(image: DownscaleSource, region: SourceRegion, destWidth: number, destHeight: number, dest?: SourceRegion): HTMLCanvasElement;
|
|
3
10
|
export {};
|
package/canvas/downscale.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import t from"konva";function e(t){return t instanceof HTMLVideoElement?{width:t.videoWidth,height:t.videoHeight}:{width:t.width,height:t.height}}export const RESAMPLE_SKIP_THRESHOLD=.95;function n(t){const e=Math.abs(t);if(e<=.5){return.75-e*e}if(e<=1.5){const t=1.5-e;return.5*t*t}return 0}function h(t,e,h,i,o,a){const r=a/h,c=Math.max(1,1/r),s=1.5*c,g=[];for(let l=0;l<i;l++){const i=e+(l+.5-o)/r-.5,a=Math.max(0,Math.floor(e)),d=Math.min(t-1,Math.ceil(e+h)-1),f=Math.max(a,Math.floor(i-s)),u=Math.min(d,Math.ceil(i+s));if(u<f){g.push({start:a,weights:new Float32Array(0)});continue}const w=new Float32Array(u-f+1);let m=0;for(let t=f;t<=u;t++){const e=n((t-i)/c);w[t-f]=e,m+=e}if(m>0){for(let t=0;t<w.length;t++){w[t]/=m}}g.push({start:f,weights:w})}return g}function i(t,e,n,h,i){const o=new Float32Array(h*n*4);for(let a=0;a<n;a++){const r=a*e*4;for(let e=0;e<h;e++){const{start:h,weights:c}=i[e];let s=0,g=0,l=0,d=0;for(let e=0;e<c.length;e++){const n=r+4*(h+e),i=c[e];s+=t[n]*i,g+=t[n+1]*i,l+=t[n+2]*i,d+=t[n+3]*i}const f=4*(e*n+a);o[f]=s,o[f+1]=g,o[f+2]=l,o[f+3]=d}}return o}const o=-.25;export function resampleCanvas(n,a,r,c,s={x:0,y:0,width:r,height:c}){const g=e(n),l=function(n,h,i){let{width:o,height:a}=e(n),r=n;for(;o>2*h||a>2*i;){o=Math.max(2*h,Math.round(o/2)),a=Math.max(2*i,Math.round(a/2));const e=document.createElement("canvas");e.width=o,e.height=a;const c=e.getContext("2d");c.imageSmoothingQuality="high",c.drawImage(r,0,0,o,a),r!==n&&t.Util.releaseCanvas(r),r=e}return r}(n,g.width*r/a.width,g.height*c/a.height);let d;if(l instanceof HTMLCanvasElement){d=l}else{const t=e(l);d=document.createElement("canvas"),d.width=t.width,d.height=t.height,d.getContext("2d").drawImage(l,0,0)}const f=d.getContext("2d").getImageData(0,0,d.width,d.height),u=d.width/g.width,w=d.height/g.height,m={x:a.x*u,y:a.y*w,width:a.width*u,height:a.height*w};d!==n&&t.Util.releaseCanvas(d);const M=function(t,e,n,a,r){const c=i(function(t){const e=new Uint16Array(t.length);for(let n=0;n<t.length;n+=4){const h=t[n+3];e[n]=t[n]*h,e[n+1]=t[n+1]*h,e[n+2]=t[n+2]*h,e[n+3]=h}return e}(t.data),t.width,t.height,n,h(t.width,e.x,e.width,n,r.x,r.width)),s=function(t,e,n){const h=new ImageData(e,n),i=h.data;for(let o=0;o<i.length;o+=4){const e=t[o+3];if(e>.001){const n=1/e;i[o]=t[o]*n,i[o+1]=t[o+1]*n,i[o+2]=t[o+2]*n}i[o+3]=e}return h}(i(c,t.height,n,a,h(t.height,e.y,e.height,a,r.y,r.height)),n,a);return function(t){const{width:e,height:n,data:h}=t,i=new Float32Array(e*n*3);for(let a=0;a<n;a++){for(let t=0;t<e;t++){const n=4*(a*e+t),r=4*(a*e+Math.max(0,t-1)),c=4*(a*e+Math.min(e-1,t+1)),s=h[r+3]>0?o:0,g=h[c+3]>0?o:0,l=o-s+1.5+(o-g),d=3*(a*e+t);for(let t=0;t<3;t++){i[d+t]=l*h[n+t]+s*h[r+t]+g*h[c+t]}}}for(let a=0;a<n;a++){for(let t=0;t<e;t++){const r=4*(a*e+t);if(0===h[r+3]){continue}const c=Math.max(0,a-1)*e+t,s=Math.min(n-1,a+1)*e+t,g=h[4*c+3]>0?o:0,l=h[4*s+3]>0?o:0,d=o-g+1.5+(o-l),f=3*(a*e+t);for(let t=0;t<3;t++){h[r+t]=d*i[f+t]+g*i[3*c+t]+l*i[3*s+t]}}}}(s),s}(f,m,r,c,s),x=document.createElement("canvas");return x.width=r,x.height=c,x.getContext("2d").putImageData(M,0,0),x}
|
package/canvas/figure-element.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as t,Fragment as e,jsxs as a}from"react/jsx-runtime";import r from"react";import{observer as s}from"mobx-react-lite";import{Group as o,Rect as i,Path as h}from"react-konva";import{ROLES as n}from"../model/store.js";import{subTypeToPathDataFunc as d}from"@polotno/core/figure-to-svg";import{isTouchDevice as c}from"../utils/screen.js";import{roundEnabledPx as l,activeAnchorOf as g,isCornerAnchor as m,scaledBoxStyleAttrs as f,roundedBoxStyleAttrs as p}from"../utils/px.js";import{useColor as
|
|
1
|
+
import{jsx as t,Fragment as e,jsxs as a}from"react/jsx-runtime";import r from"react";import{observer as s}from"mobx-react-lite";import{Group as o,Rect as i,Path as h}from"react-konva";import{ROLES as n}from"../model/store.js";import{subTypeToPathDataFunc as d}from"@polotno/core/figure-to-svg";import{isTouchDevice as c}from"../utils/screen.js";import{roundEnabledPx as l,activeAnchorOf as g,isCornerAnchor as m,scaledBoxStyleAttrs as f,roundedBoxStyleAttrs as p,roundedGeometryAttrs as u,roundedPosition as b}from"../utils/px.js";import{useColor as w}from"./use-color.js";const x={};export const FigureElement=s(({element:k,store:j})=>{const O=r.useRef(null),y=r.useRef(!1),v=k.selectable||j.role===n.ADMIN,W=c(),M=k.isSelected,E=Math.min(k.strokeWidth,k.width/2,k.height/2),R=Math.max(0,Math.min(k.width/2,k.height/2,k.cornerRadius)),T=w(k,k.a.fill,"fill"),P=Object.assign(Object.assign({width:k.a.width,height:k.a.height},T),{cornerRadius:R,shadowEnabled:k.shadowEnabled,shadowBlur:k.shadowBlur,shadowOffsetX:k.shadowOffsetX,shadowOffsetY:k.shadowOffsetY,shadowColor:k.shadowColor,shadowOpacity:k.shadowOpacity,preventDefault:!W||M,hideInExport:!k.showInExport}),C=w(k,k.stroke,"stroke"),I=Object.assign(Object.assign({visible:E>0,x:E/2,y:E/2,width:k.a.width-E,height:k.a.height-E},C),{strokeWidth:E,cornerRadius:Math.max(0,R-E),dash:k.dash.map(t=>t*E),hideInExport:!k.showInExport,listening:!1}),S=Math.max(0,10-Math.min(k.a.width,k.a.height)),D=(A=k.subType,x[A]||(x[A]=(F=d(A),s(({element:s,fillProps:n,strokeProps:d,hitStrokeWidth:c})=>{const l=F({width:s.a.width,height:s.a.height,cornerRadius:s.cornerRadius}),g=r.useRef(null);return a(e,{children:[t(i,{width:s.a.width,height:s.a.height,fill:"transparent",hitStrokeWidth:c}),t(h,Object.assign({},n,{ref:g,data:l})),t(o,{clipFunc:t=>{const e=g.current;if(e){var a=e.dataArray;t.beginPath();for(var r=0;r<a.length;r++){var s=a[r].command,o=a[r].points;switch(s){case"L":t.lineTo(o[0],o[1]);break;case"M":t.moveTo(o[0],o[1]);break;case"C":t.bezierCurveTo(o[0],o[1],o[2],o[3],o[4],o[5]);break;case"Q":t.quadraticCurveTo(o[0],o[1],o[2],o[3]);break;case"A":var i=o[0],h=o[1],n=o[2],d=o[3],c=o[4],l=o[5],m=o[6],f=o[7],p=n>d?n:d,u=n>d?1:n/d,b=n>d?d/n:1;t.translate(i,h),t.rotate(m),t.scale(u,b),t.arc(0,0,p,c,c+l,!f),t.scale(1/u,1/b),t.rotate(-m),t.translate(-i,-h);break;case"z":t.closePath()}}}},children:t(h,Object.assign({},d,{x:0,y:0,data:l,strokeWidth:2*d.strokeWidth,dash:d.dash.map(t=>t)}))})]})}))),x[A]||o);var A,F;return t(e,{children:t(o,{ref:O,id:k.id,x:k.a.x,y:k.a.y,rotation:k.a.rotation,opacity:k.a.opacity,listening:v,draggable:W?k.draggable&&M:k.draggable,name:"element",onDragMove:t=>{k.set({x:t.target.x(),y:t.target.y()})},onDragEnd:t=>{k.set(b(t.target))},onTransformStart:t=>{y.current=m(g(t.target))},onTransform:t=>{const e=t.target.scale();t.target.scaleX(1),t.target.scaleY(1);const a=y.current?Math.min(e.x,e.y):1;k.set(Object.assign({width:k.width*e.x,height:k.height*e.y,x:t.target.x(),y:t.target.y(),rotation:t.target.rotation()},1!==a&&Object.assign(Object.assign({},f(k,a)),{strokeWidth:k.strokeWidth*a})))},onTransformEnd:()=>{k.set(Object.assign(Object.assign(Object.assign({},u(k)),p(k)),{strokeWidth:l(k.strokeWidth)}))},children:t(D,{element:k,fillProps:P,strokeProps:I,hitStrokeWidth:S})})})});
|
package/canvas/gif-element.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as t,jsxs as e,Fragment as r}from"react/jsx-runtime";import i from"react";import{observer as o}from"mobx-react-lite";import{nodeAutorun as a}from"../utils/mobx.js";import{Image as n,Group as s,Rect as h,Arc as d,Text as l}from"react-konva";import{ROLES as c}from"../model/store.js";import g from"konva";import{parseGIF as m,decompressFrames as f}from"gifuct-js";import{useCornerRadiusAndCrop as u}from"./video-element.js";import{useImageLoader as p}from"./image-element.js";import{useWorkspaceStyle as w}from"./workspace-style.js";import{useFilteredSource as x}from"./use-filtered-source.js";import{useFadeIn as y}from"./use-fadein.js";import{isTouchDevice as b}from"../utils/screen.js";import{roundEnabledPx as E,activeAnchorOf as v,isCornerAnchor as S,scaledBoxStyleAttrs as j,roundedBoxStyleAttrs as I}from"../utils/px.js";import{useEvent as
|
|
1
|
+
import{jsx as t,jsxs as e,Fragment as r}from"react/jsx-runtime";import i from"react";import{observer as o}from"mobx-react-lite";import{nodeAutorun as a}from"../utils/mobx.js";import{Image as n,Group as s,Rect as h,Arc as d,Text as l}from"react-konva";import{ROLES as c}from"../model/store.js";import g from"konva";import{parseGIF as m,decompressFrames as f}from"gifuct-js";import{useCornerRadiusAndCrop as u}from"./video-element.js";import{useImageLoader as p}from"./image-element.js";import{useWorkspaceStyle as w}from"./workspace-style.js";import{useFilteredSource as x}from"./use-filtered-source.js";import{useFadeIn as y}from"./use-fadein.js";import{isTouchDevice as b}from"../utils/screen.js";import{roundEnabledPx as E,activeAnchorOf as v,isCornerAnchor as S,scaledBoxStyleAttrs as j,roundedBoxStyleAttrs as I,roundedGeometryAttrs as M,roundedPosition as O}from"../utils/px.js";import{useEvent as R}from"../hooks/use-event.js";function z(t,e,r){const i=e.getContext("2d"),o=r.getContext("2d");if(!i||!o){return}2===t.disposalType&&i.clearRect(0,0,e.width,e.height),r.width=t.width,r.height=t.height;const a=o.createImageData(t.width,t.height);a.data.set(t.patch),o.putImageData(a,0,0),i.drawImage(r,t.left,t.top)}const C=o(({element:r})=>{const o=Math.min(30,r.width/4,r.height/4),a=i.useRef(null);i.useEffect(()=>{const t=a.current;if(!t){return}const e=new g.Animation(e=>{t.rotate(((null==e?void 0:e.timeDiff)||0)/2)},t.getLayer());return e.start(),()=>{e.stop()}},[]);const{mediaLoadingStyle:n}=w();return e(s,{x:r.a.x,y:r.a.y,rotation:r.a.rotation,listening:!1,opacity:r.a.opacity,hideInExport:!r.showInExport,children:[t(h,{width:r.width,height:r.height,fill:n.fill}),t(d,{ref:a,x:r.width/2,y:r.height/2,fill:n.textFill,outerRadius:Math.abs(o),innerRadius:Math.max(1,o-5),angle:270})]})}),T=o(({element:r})=>{const{mediaErrorStyle:i}=w(),o=Math.max(10,Math.min(30,r.width/22));return e(s,{x:r.a.x,y:r.a.y,rotation:r.a.rotation,listening:!1,opacity:r.a.opacity,hideInExport:!r.showInExport,children:[t(h,{width:r.width,height:r.height,fill:i.fill}),t(l,{text:"Cannot load the GIF...",fontSize:o,width:r.width,height:r.height,align:"center",fill:i.textFill,verticalAlign:"middle",padding:5})]})});export const GifElement=o(({element:o,store:s})=>{var d,l;const[w,D]=i.useState(!1),X=i.useRef(!1),Y=o.isSelected,k=i.useRef(null),F=i.useRef(void 0),[A,_,B,G]=function(t){const[e,r]=i.useState([]),[o,a]=i.useState(0),[n,s]=i.useState("loading"),[h,d]=i.useState({width:0,height:0});return i.useEffect(()=>{(async()=>{try{const e=await fetch(t),i=await e.arrayBuffer(),o=m(i),n=f(o,!0),h=o.lsd.width,l=o.lsd.height;d({width:h,height:l});const c=n.map(t=>({patch:new Uint8ClampedArray(t.patch),delay:t.delay,width:t.dims.width,height:t.dims.height,left:t.dims.left,top:t.dims.top,disposalType:t.disposalType})),g=c.reduce((t,e)=>t+e.delay,0);r(c),a(g),s("loaded")}catch(e){console.error("Failed to load GIF:",e),s("failed")}})()},[t]),[e,o,h,n]}(o.src);p(G,o.src,o.id),i.useEffect(()=>(F.current=document.createElement("canvas"),()=>{F.current&&g.Util.releaseCanvas(F.current)}),[]),i.useEffect(()=>{if("loaded"===G&&F.current&&(F.current.width=B.width,F.current.height=B.height,A.length>0)){const t=F.current.getContext("2d");if(t){t.clearRect(0,0,B.width,B.height);const e=document.createElement("canvas");z(A[0],F.current,e)}}},[B,G,A]),i.useEffect(()=>{var t;if(!A.length||!F.current){return}const e=F.current;e.width=B.width,e.height=B.height;const r=document.createElement("canvas"),i=e.getContext("2d");i&&i.clearRect(0,0,e.width,e.height);let n=-1;z(A[0],e,r),V(),n=0;const h=t=>{const i=(t=>{const e=t%_;let r=0;for(let i=0;i<A.length;i++){if(r+=A[i].delay,r>e){return i}}return 0})(t);i!==n&&(z(A[i],e,r),V(),k.current.getLayer().draw(),n=i)};if(s.isPlaying||(null===(t=o.page)||void 0===t?void 0:t._exportingOrRendering)){return a(o,()=>{h(s.currentTime-o.page.startTime)})}{const t=window.setInterval(()=>{h(s.currentTime||performance.now())},16);return()=>{clearInterval(t)}}},[s.isPlaying,A,_,null===(d=o.page)||void 0===d?void 0:d._exportingOrRendering]),i.useEffect(()=>{_&&s.history.ignore(()=>{o.set({duration:_})})},[_]);let{cropX:L,cropY:P,cropWidth:U,cropHeight:W}=o;"loaded"!==G&&(L=P=0,U=W=1);const H={x:B.width*L,y:B.height*P,width:B.width*U,height:B.height*W},N=null!==(l=o.cornerRadius)&&void 0!==l?l:0,[q,J]=x(o,F.current),[K,Q]=u(o,q,H,s._elementsPixelRatio,N,w||o._cropModeEnabled),V=R(()=>{J(),Q()}),Z="loading"===G,$="failed"===G,tt=Z||$?0:o.a.opacity;y(k,tt);const et=o.selectable||s.role===c.ADMIN,rt=b();return e(r,{children:[Z&&t(C,{element:o}),$&&t(T,{element:o}),t(n,{ref:k,name:"element",id:o.id,image:K,x:o.a.x,y:o.a.y,width:o.a.width||1,height:o.a.height||1,rotation:o.a.rotation,opacity:tt,shadowEnabled:o.shadowEnabled,shadowBlur:o.shadowBlur,shadowOffsetX:o.shadowOffsetX,shadowOffsetY:o.shadowOffsetY,shadowColor:o.shadowColor,shadowOpacity:o.shadowOpacity,customCrop:H,listening:et,draggable:rt?o.draggable&&Y:o.draggable,preventDefault:!rt||Y,hideInExport:!o.showInExport,onDragMove:t=>{o.set({x:t.target.x(),y:t.target.y()})},onDragEnd:t=>{o.set(O(t.target))},onTransformStart:t=>{D(!0),X.current=S(v(t.target))},onTransform:t=>{const e=t.currentTarget,r=Math.abs(e.scaleX()-1)<1e-7?1:e.scaleX(),i=Math.abs(e.scaleY()-1)<1e-7?1:e.scaleY();e.scaleX(1),e.scaleY(1);const a=X.current?Math.min(r,i):1;o.set(Object.assign({x:e.x(),y:e.y(),width:e.width()*r,height:e.height()*i,rotation:e.rotation()},1!==a&&Object.assign(Object.assign({},j(o,a)),{borderSize:o.borderSize*a})))},onTransformEnd:()=>{o.set(Object.assign(Object.assign(Object.assign({},M(o)),I(o)),{borderSize:E(o.borderSize)})),D(!1)}}),t(h,{x:o.a.x,y:o.a.y,width:Math.max(o.a.width-o.borderSize,0),height:Math.max(o.a.height-o.borderSize,0),opacity:tt,offsetX:-o.borderSize/2,offsetY:-o.borderSize/2,stroke:o.borderColor,strokeWidth:o.borderSize,listening:!1,visible:!!o.borderSize,rotation:o.rotation,cornerRadius:Math.max(0,N-o.borderSize),hideInExport:!o.showInExport})]})});
|
package/canvas/html-element.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as t,Fragment as e,jsxs as o}from"react/jsx-runtime";import r from"react";import{observer as n}from"mobx-react-lite";import{Group as i,Image as a,Path as s,Rect as l}from"react-konva";import{activeAnchorOf as c,scaledFontSizeAttrs as f,roundedFontSizeAttrs as d,roundedTextDecorationAttrs as h,textMinResizeWidth as u}from"../utils/px.js";import g from"konva";import{isAlive as m}from"mobx-state-tree";import{nodeAutorun as x}from"../utils/mobx.js";import{flags as p}from"../utils/flags.js";import{applyFilter as y}from"./apply-filters.js";import{getLineHeight as w,useFontFamiliesLoader as b,usePrevious as v}from"./text-element.js";import{getCurvePath as E}from"@polotno/core/text-html";import{useColor as S}from"./use-color.js";import{useWorkspaceStyle as O}from"./workspace-style.js";import{detectSize as k,detectLineRects as z,htmlToCanvas as F}from"../utils/html2canvas.js";import{generateBackgroundShapeFromRects as j}from"@polotno/core/background-shape";import{useFadeIn as M}from"./use-fadein.js";import{Html as R}from"react-konva-utils";import{incrementLoader as X,triggerLoadError as Y}from"../utils/loader.js";import{removeTags as I}from"@polotno/core/text";import{cssFontFamily as C}from"@polotno/core/fonts";import*as P from"../utils/fonts.js";import{isTouchDevice as T}from"../utils/screen.js";import{getLimitedFontSize as B}from"./text-element/max-font-size.js";import{visiblePlaceholder as A}from"./text-element/placeholder.js";import{useDelayer as W}from"./use-delayer.js";import{getHtml as $}from"@polotno/core/text-html";import{hasMeasuredHeight as D,resolveTextBoxHeight as H}from"@polotno/core/text-types";import{normalizeRichTextHtml as _,extractFontFamiliesFromHtml as L,scaleRichTextFontSizesInHtml as J}from"../utils/rich-text-html.js";import{findFitFontSize as N}from"./text-element/fit-font-size.js";import{RichEditor as q,RichTextContainer as V,applyOpacityToColor as G,quillRef as K,createQuill as Q,setQuillContent as U,setQuillFormats as Z,syncQuillFormatState as tt,setCursorFromCoords as et}from"./rich-editor.js";export{K as quillRef,Q as createQuill,U as setQuillContent,Z as setQuillFormats,tt as syncQuillFormatState,et as setCursorFromCoords};function ot(t){const e=document.createElement("canvas"),o=e.getContext("2d");return null==o||o.drawImage(t,0,0,e.width,e.height),function(t){return!function(t){const e=t.getContext("2d").getImageData(0,0,t.width,t.height).data;for(let o=0;o<e.length;o+=4){if(0!==e[o+3]){return!0}}return!1}(t)}(e)}const rt=/^((?!chrome|android).)*safari/i.test(navigator.userAgent),nt=navigator.userAgent.includes("Firefox");export const HTMLElement=n(({element:n,store:K})=>{var Q,U;const{textOverflowIndicatorStyle:Z}=O(),tt=r.useRef(null),[et,it]=r.useState(),[at,st]=r.useState(!1),[lt,ct]=r.useState(!1),ft=r.useRef(n.height),dt=n.isSelected,ht=v(dt),ut=n.fontSize/3,{textVerticalResizeEnabled:gt}=p,mt=p.autoDeleteEmptyText,xt=v(n.fontFamily),pt=r.useMemo(()=>_(n.text,{fontSize:n.fontSize,fontFamily:n.fontFamily}),[n.text,n.fontSize,n.fontFamily]),yt=r.useMemo(()=>[...new Set([n.fontFamily,...L(pt)])].filter(Boolean),[n.fontFamily,pt]),[wt]=b(K,yt,n.fontStyle,n.fontWeight,n.text||n.placeholder),bt=n._editModeEnabled;M(tt);const vt=wt?n.fontFamily:xt!==n.fontFamily?xt:"Arial",Et=S(n).fill,St=$(n,{fontFamily:vt,color:Et,textOverflow:p.textOverflow}),Ot=r.useRef([]),kt=r.useRef(!0),[,zt]=r.useReducer(t=>t+1,0);r.useEffect(()=>{const t=Ot.current;t.length>0&&(Ot.current=[],t.forEach(t=>t()))}),r.useEffect(()=>()=>{kt.current=!1;const t=Ot.current;t.length>0&&(Ot.current=[],t.forEach(t=>t()))},[]);let{width:Ft,height:jt}=function(t,e,o){return r.useMemo(()=>k(t),[t,e.width,o])}(St,n,wt);r.useEffect(()=>{if(!wt){return}const t=(t,e,o,r)=>{const i=X(`text ${n.id}`),a=()=>{K.history.ignore(t,e,o).then(()=>{kt.current?(Ot.current.push(i),zt()):i()})};r?queueMicrotask(a):a()};if(n.curveEnabled&&Math.abs(Ft-n.width)>1&&!at&&t(()=>{if(m(n)&&Math.abs(Ft-n.width)>1){const t=n.x+n.width/2;n.set({width:Ft,x:t-Ft/2})}},!1,!0),!D(n)){return void t(()=>{m(n)&&(D(n)||n.set({height:jt}))},void 0,void 0,!0)}const{textOverflow:e}=p;if("change-font-size"!==e||at||bt||n.curveEnabled){"resize"===e&&(gt&&n.height<jt&&!at&&t(()=>{m(n)&&n.set({height:jt})},!1,!0),gt||n.height===jt||at||t(()=>{m(n)&&n.set({height:jt})},!1,!0))}else{const e=N(n,{fontFamily:n.fontFamily,textOverflow:p.textOverflow});e.fontSize!==n.fontSize?t(()=>{if(!m(n)){return}const t=f(n,e.fontSize);void 0!==e.text&&e.text!==n.text&&(t.text=e.text),n.set(t)},!1,!0):n.height!==jt&&(gt&&n.height<jt?t(()=>{m(n)&&n.set({height:jt})},!1,!0):gt||t(()=>{m(n)&&n.set({height:jt})},!1,!0))}});const Mt=r.useMemo(()=>{const t={lastArgs:null,lastResult:null};return async function(e){return t.lastArgs&&t.lastResult&&(o=t.lastArgs,r=e,JSON.stringify(o)===JSON.stringify(r))||(t.lastResult=await F(e),t.lastArgs=Object.assign({},e)),t.lastResult;var o,r}},[]),Rt=r.useRef(0),Xt=r.useRef(null);r.useEffect(()=>{at||bt||(async()=>{Rt.current++;const t=Rt.current;let e=X(`text ${n.id} ${t}`);Xt.current&&Xt.current(),Xt.current=e,ct(!0);let o=null;const r=rt?5:1;for(let a=0;a<r;a++){const e=a>0?Mt:F;try{if(o=await e({skipCache:a>0,html:St,width:Ft||n.width||1,height:H(n,jt)||1,fontFamily:vt,fontFamilies:L(St),resolveFont:t=>K.fonts.find(e=>e.fontFamily===t)||P.globalFonts.find(e=>e.fontFamily===t),padding:ut,pixelRatio:K._elementsPixelRatio,font:K.fonts.find(t=>t.fontFamily===vt)||P.globalFonts.find(t=>t.fontFamily===vt)}),t!==Rt.current){return}if((rt||nt)&&o&&ot(o)){await new Promise(t=>setTimeout(t,50*(a+1)));continue}break}catch(i){console.error(i),Y(`Error rendering rich text with id ${n.id}`);break}}o?it(o):e?(e(),e=null):console.error("Finish function is called twice!"),ct(!1)})()},[St,at,jt,bt,vt,n.height,K._elementsPixelRatio,wt]);const[Yt,It]=W(lt,300),[Ct]=W(at,300,!0),Pt=Ct||Yt;r.useEffect(()=>{var t;if(!Pt){return x(n,()=>{const t=tt.current;y(t,n)})}null===(t=tt.current)||void 0===t||t.clearCache()},[et,Pt,n.shadowColor,n.shadowOffsetX,n.shadowOffsetY,n.shadowOpacity]),r.useEffect(()=>{et&&!lt&&Xt.current&&(Xt.current(),Xt.current=null)},[et,lt]),r.useLayoutEffect(()=>{if(!wt){return}if(!n.curveEnabled){return}const t=new g.TextPath({data:E(n.a.width,n.a.height,n.curvePower,n.a.fontSize),text:I(n.text),letterSpacing:n.letterSpacing*n.a.fontSize,fontSize:n.a.fontSize,fontFamily:C(n.fontFamily),fontWeight:n.fontWeight,fontStyle:n.fontStyle,align:"center",textBaseline:"middle",fill:n.fill}),e=t.getSelfRect().width;if(e){const t=e-n.a.width,o=n.a.rotation*Math.PI/180,r=-t/2*Math.cos(o),i=-t/2*Math.sin(o);queueMicrotask(()=>{m(n)&&n.set({width:e,x:n.a.x+r,y:n.a.y+i})})}t.destroy()},[wt,n.curveEnabled,n.curvePower,n.text,n.fontSize,n.fontFamily,n.fontWeight,n.fontStyle,n.letterSpacing]),r.useEffect(()=>()=>{Xt.current&&Xt.current()},[]),r.useEffect(()=>{ht&&!dt&&mt&&""===I(n.text)&&n.removable&&!A(n.placeholder)&&K.deleteElements([n.id])},[mt,n.placeholder,n.removable,n.text,dt,ht]);const Tt=H(n,jt);let Bt=0;"middle"===n.verticalAlign&&(Bt=(Tt-jt)/2),"bottom"===n.verticalAlign&&(Bt=Tt-jt);const At=w({fontLoaded:wt,fontFamily:n.fontFamily,fontSize:n.fontSize,lineHeight:n.lineHeight}),Wt=n.backgroundPadding*(n.fontSize*At*.5),$t=n.backgroundCornerRadius*(n.fontSize*At*.5),Dt=r.useMemo(()=>{if(!n.backgroundEnabled||n.curveEnabled||n.legacyBackground){return""}const t=z(St);if(0===t.length){return""}const e=t.map(t=>({left:t.left+ut,right:t.right+ut,top:t.top+ut,bottom:t.bottom+ut}));return j({rects:e,padding:Wt,cornerRadius:$t})},[n.backgroundEnabled,n.curveEnabled,n.legacyBackground,St,wt,Wt,$t,ut]),Ht=T(),_t=E(n.a.width,jt,n.curvePower,n.fontSize),Lt=r.useRef(null),Jt=r.useRef(n.width),Nt=r.useRef(""),qt=r.useRef(0),Vt=r.useRef(0),Gt=r.useRef(null),Kt=bt&&n.strokeWidth>0&&!n.curveEnabled,Qt=Ft>0?(n.a.width+2*ut)/(Ft+2*ut):1;return o(e,{children:[n.curveEnabled||n.legacyBackground?t(l,{x:n.a.x,y:n.a.y,offsetX:Wt/Qt,offsetY:Wt/Qt,rotation:n.a.rotation,scaleX:Qt,scaleY:Qt,hideInExport:!n.showInExport,listening:!1,visible:n.backgroundEnabled,opacity:n.backgroundOpacity*n.a.opacity,fill:n.backgroundColor,width:n.width+2*Wt,height:Tt+2*Wt,cornerRadius:$t}):t(s,{name:"html-background",x:n.a.x,y:n.a.y,offsetX:ut/Qt,offsetY:(ut-Bt)/Qt,rotation:n.a.rotation,scaleX:Qt,scaleY:Qt,hideInExport:!n.showInExport,listening:!1,visible:n.backgroundEnabled&&Dt.length>0,opacity:n.backgroundOpacity*n.a.opacity,fill:n.backgroundColor,data:Dt}),t(s,{x:n.a.x,y:n.a.y,rotation:n.a.rotation,data:_t,stroke:Z.stroke,strokeWidth:1,visible:!1}),t(l,{ref:tt,name:"element",x:n.a.x,y:n.a.y,listening:n.selectable,rotation:n.a.rotation,width:n.a.width,height:n.a.height,visible:!Pt,draggable:Ht?n.draggable&&dt:n.draggable,preventDefault:!Ht||dt,opacity:bt?0:n.a.opacity,hideInExport:!n.showInExport,onDragMove:t=>{n.set({x:t.target.x(),y:t.target.y()})},onDragEnd:t=>{n.set({x:t.target.x(),y:t.target.y()})},id:n.id,onDblClick:t=>{n.contentEditable&&(Gt.current={x:t.evt.clientX,y:t.evt.clientY},n.toggleEditMode(!0))},onDblTap:t=>{var e;if(n.contentEditable){const o=null===(e=t.evt.changedTouches)||void 0===e?void 0:e[0];Gt.current=o?{x:o.clientX,y:o.clientY}:null,n.toggleEditMode(!0)}},onTransformStart:t=>{st(!0),ft.current=n.height,Jt.current=n.width,Lt.current=t.target.position(),Nt.current=c(t.target),qt.current=n.a.rotation,Vt.current=n.height},onTransform:t=>{const e=t.target,o=Nt.current,r="middle-left"===o||"middle-right"===o,i="top-center"===o||"bottom-center"===o,a=e.scaleX();if(r){const t=e.scaleX(),o=e.width()*t,r=u(Jt.current,n.fontSize);let i=o;o<r&&(i=r,Lt.current&&e.position(Lt.current)),e.width(i),e.scaleX(1),e.scaleY(1);const a=$(Object.assign(Object.assign({},n.toJSON()),{width:i}),{fontFamily:vt,color:Et,textOverflow:p.textOverflow}),s=k(a).height,l=p.textVerticalResizeEnabled?Math.max(s,ft.current):s;e.height(l),n.set({width:e.width(),height:l,x:e.x(),y:e.y()})}else if(i){const t="resize"===p.textOverflow,o="number"==typeof n.lineHeight?n.lineHeight:1,r=t?jt:o*n.fontSize,i=e.height()*e.scaleY();if(i<r){if(e.height(r),Lt.current){if("top-center"===Nt.current){const t=qt.current*Math.PI/180,o=Vt.current-r;e.x(Lt.current.x-o*Math.sin(t)),e.y(Lt.current.y+o*Math.cos(t))}else{e.position(Lt.current)}}}else{e.height(i)}e.scaleY(1),e.scaleX(1),Vt.current=Math.max(r,i),n.set({x:e.x(),y:e.y(),height:e.height(),rotation:e.rotation()})}else{e.scaleX(1),e.scaleY(1),n.set({fontSize:n.fontSize*a,letterSpacing:n.letterSpacing,width:e.width()*a,x:e.x(),y:e.y(),rotation:e.rotation(),height:e.height()*a,shadowBlur:n.shadowBlur*a,shadowOffsetX:n.shadowOffsetX*a,shadowOffsetY:n.shadowOffsetY*a,strokeWidth:n.strokeWidth*a,text:J(n.text,a)})}Lt.current=t.target.position()},onTransformEnd:t=>{st(!1),ct(!0);const e=t.target.scaleX();t.target.scaleX(1),t.target.scaleY(1),n.set(Object.assign(Object.assign({},d(n,n.fontSize*e)),{width:t.target.width()*e,x:t.target.x(),y:t.target.y(),rotation:t.target.rotation(),text:J(n.text,e)}))}}),t(a,{ref:tt,image:et,x:n.a.x,y:n.a.y,offsetX:ut,offsetY:ut-Bt,listening:!1,rotation:n.a.rotation,width:n.a.width+2*ut,height:(n.a.width+2*ut)*((null!==(Q=null==et?void 0:et.height)&&void 0!==Q?Q:0)/((null==et?void 0:et.width)||1)||1),visible:!Pt&&!bt,opacity:n.a.opacity,shadowEnabled:n.shadowEnabled,shadowBlur:n.shadowBlur,shadowOffsetX:n.shadowOffsetX,shadowOffsetY:n.shadowOffsetY,shadowColor:n.shadowColor,shadowOpacity:n.shadowOpacity,hideInExport:!n.showInExport,editModeEnabled:n._editModeEnabled||at||Pt}),(Pt&&!bt||Kt)&&t(i,{x:n.a.x,y:n.a.y,rotation:n.a.rotation,offsetY:-Bt,children:t(R,{divProps:{style:{pointerEvents:"none"}},children:t(V,{dangerouslySetInnerHTML:{__html:St},style:{pointerEvents:"none",opacity:n.a.opacity,textShadow:n.shadowEnabled?`${n.shadowOffsetX}px ${n.shadowOffsetY}px ${n.shadowBlur}px ${G(n.shadowColor,null!==(U=n.shadowOpacity)&&void 0!==U?U:1)}`:void 0}})})}),bt&&t(i,{x:n.a.x,y:n.a.y,rotation:n.a.rotation,offsetY:-Bt,children:t(R,{divProps:{style:{zIndex:20}},children:t(q,{element:n,onChange:t=>{const e=B({oldText:I(n.text),newText:I(t),element:n});n.set(Object.assign({text:t},f(n,e)))},onBlur:t=>{m(n)&&(n.set(h(n)),n.toggleEditMode(!1),It(!0))},clickCoords:Gt.current})})})]})});
|
|
1
|
+
import{jsx as t,Fragment as e,jsxs as o}from"react/jsx-runtime";import r from"react";import{observer as n}from"mobx-react-lite";import{Group as i,Image as a,Path as s,Rect as l}from"react-konva";import{activeAnchorOf as c,scaledFontSizeAttrs as f,roundedFontSizeAttrs as d,roundedTextDecorationAttrs as h,roundedGeometryPx as u,roundedPosition as g,textMinResizeWidth as m}from"../utils/px.js";import x from"konva";import{isAlive as p}from"mobx-state-tree";import{nodeAutorun as y}from"../utils/mobx.js";import{flags as w}from"../utils/flags.js";import{applyFilter as b}from"./apply-filters.js";import{getLineHeight as v,useFontFamiliesLoader as E,usePrevious as S}from"./text-element.js";import{getCurvePath as O}from"@polotno/core/text-html";import{useColor as k}from"./use-color.js";import{useWorkspaceStyle as z}from"./workspace-style.js";import{detectSize as F,detectLineRects as j,htmlToCanvas as M}from"../utils/html2canvas.js";import{generateBackgroundShapeFromRects as R}from"@polotno/core/background-shape";import{useFadeIn as X}from"./use-fadein.js";import{Html as Y}from"react-konva-utils";import{incrementLoader as I,triggerLoadError as C}from"../utils/loader.js";import{removeTags as P}from"@polotno/core/text";import{cssFontFamily as T}from"@polotno/core/fonts";import*as B from"../utils/fonts.js";import{isTouchDevice as A}from"../utils/screen.js";import{getLimitedFontSize as W}from"./text-element/max-font-size.js";import{visiblePlaceholder as $}from"./text-element/placeholder.js";import{useDelayer as D}from"./use-delayer.js";import{getHtml as H,textLayoutWidth as _}from"@polotno/core/text-html";import{hasMeasuredHeight as L,resolveTextBoxHeight as J}from"@polotno/core/text-types";import{normalizeRichTextHtml as N,extractFontFamiliesFromHtml as q,scaleRichTextFontSizesInHtml as V}from"../utils/rich-text-html.js";import{findFitFontSize as G}from"./text-element/fit-font-size.js";import{RichEditor as K,RichTextContainer as Q,applyOpacityToColor as U,quillRef as Z,createQuill as tt,setQuillContent as et,setQuillFormats as ot,syncQuillFormatState as rt,setCursorFromCoords as nt}from"./rich-editor.js";export{Z as quillRef,tt as createQuill,et as setQuillContent,ot as setQuillFormats,rt as syncQuillFormatState,nt as setCursorFromCoords};function it(t){const e=document.createElement("canvas"),o=e.getContext("2d");return null==o||o.drawImage(t,0,0,e.width,e.height),function(t){return!function(t){const e=t.getContext("2d").getImageData(0,0,t.width,t.height).data;for(let o=0;o<e.length;o+=4){if(0!==e[o+3]){return!0}}return!1}(t)}(e)}const at=/^((?!chrome|android).)*safari/i.test(navigator.userAgent),st=navigator.userAgent.includes("Firefox");export const HTMLElement=n(({element:n,store:Z})=>{var tt,et;const{textOverflowIndicatorStyle:ot}=z(),rt=r.useRef(null),[nt,lt]=r.useState(),[ct,ft]=r.useState(!1),[dt,ht]=r.useState(!1),ut=r.useRef(n.height),gt=n.isSelected,mt=S(gt),xt=n.fontSize/3,pt=_(n.a.width,n.letterSpacing,n.fontSize)+2*xt,{textVerticalResizeEnabled:yt}=w,wt=w.autoDeleteEmptyText,bt=S(n.fontFamily),vt=r.useMemo(()=>N(n.text,{fontSize:n.fontSize,fontFamily:n.fontFamily}),[n.text,n.fontSize,n.fontFamily]),Et=r.useMemo(()=>[...new Set([n.fontFamily,...q(vt)])].filter(Boolean),[n.fontFamily,vt]),[St]=E(Z,Et,n.fontStyle,n.fontWeight,n.text||n.placeholder),Ot=n._editModeEnabled;X(rt);const kt=St?n.fontFamily:bt!==n.fontFamily?bt:"Arial",zt=k(n).fill,Ft=H(n,{fontFamily:kt,color:zt,textOverflow:w.textOverflow}),jt=r.useRef([]),Mt=r.useRef(!0),[,Rt]=r.useReducer(t=>t+1,0);r.useEffect(()=>{const t=jt.current;t.length>0&&(jt.current=[],t.forEach(t=>t()))}),r.useEffect(()=>()=>{Mt.current=!1;const t=jt.current;t.length>0&&(jt.current=[],t.forEach(t=>t()))},[]);let{width:Xt,height:Yt}=function(t,e,o){return r.useMemo(()=>F(t),[t,e.width,o])}(Ft,n,St);r.useEffect(()=>{if(!St){return}const t=(t,e,o,r)=>{const i=I(`text ${n.id}`),a=()=>{Z.history.ignore(t,e,o).then(()=>{Mt.current?(jt.current.push(i),Rt()):i()})};r?queueMicrotask(a):a()};if(n.curveEnabled&&Math.abs(Xt-n.width)>1&&!ct&&t(()=>{if(p(n)&&Math.abs(Xt-n.width)>1){const t=n.x+n.width/2;n.set({width:Xt,x:t-Xt/2})}},!1,!0),!L(n)){return void t(()=>{p(n)&&(L(n)||n.set({height:Yt}))},void 0,void 0,!0)}const{textOverflow:e}=w;if("change-font-size"!==e||ct||Ot||n.curveEnabled){"resize"===e&&(yt&&n.height<Yt&&!ct&&t(()=>{p(n)&&n.set({height:Yt})},!1,!0),yt||n.height===Yt||ct||t(()=>{p(n)&&n.set({height:Yt})},!1,!0))}else{const e=G(n,{fontFamily:n.fontFamily,textOverflow:w.textOverflow});e.fontSize!==n.fontSize?t(()=>{if(!p(n)){return}const t=f(n,e.fontSize);void 0!==e.text&&e.text!==n.text&&(t.text=e.text),n.set(t)},!1,!0):n.height!==Yt&&(yt&&n.height<Yt?t(()=>{p(n)&&n.set({height:Yt})},!1,!0):yt||t(()=>{p(n)&&n.set({height:Yt})},!1,!0))}});const It=r.useMemo(()=>{const t={lastArgs:null,lastResult:null};return async function(e){return t.lastArgs&&t.lastResult&&(o=t.lastArgs,r=e,JSON.stringify(o)===JSON.stringify(r))||(t.lastResult=await M(e),t.lastArgs=Object.assign({},e)),t.lastResult;var o,r}},[]),Ct=r.useRef(0),Pt=r.useRef(null);r.useEffect(()=>{ct||Ot||(async()=>{Ct.current++;const t=Ct.current;let e=I(`text ${n.id} ${t}`);Pt.current&&Pt.current(),Pt.current=e,ht(!0);let o=null;const r=at?5:1;for(let a=0;a<r;a++){const e=a>0?It:M;try{if(o=await e({skipCache:a>0,html:Ft,width:Xt||n.width||1,height:J(n,Yt)||1,fontFamily:kt,fontFamilies:q(Ft),resolveFont:t=>Z.fonts.find(e=>e.fontFamily===t)||B.globalFonts.find(e=>e.fontFamily===t),padding:xt,pixelRatio:Z._elementsPixelRatio,font:Z.fonts.find(t=>t.fontFamily===kt)||B.globalFonts.find(t=>t.fontFamily===kt)}),t!==Ct.current){return}if((at||st)&&o&&it(o)){await new Promise(t=>setTimeout(t,50*(a+1)));continue}break}catch(i){console.error(i),C(`Error rendering rich text with id ${n.id}`);break}}o?lt(o):e?(e(),e=null):console.error("Finish function is called twice!"),ht(!1)})()},[Ft,ct,Yt,Ot,kt,n.height,Z._elementsPixelRatio,St]);const[Tt,Bt]=D(dt,300),[At]=D(ct,300,!0),Wt=At||Tt;r.useEffect(()=>{var t;if(!Wt){return y(n,()=>{const t=rt.current;b(t,n)})}null===(t=rt.current)||void 0===t||t.clearCache()},[nt,Wt,n.shadowColor,n.shadowOffsetX,n.shadowOffsetY,n.shadowOpacity]),r.useEffect(()=>{nt&&!dt&&Pt.current&&(Pt.current(),Pt.current=null)},[nt,dt]),r.useLayoutEffect(()=>{if(!St){return}if(!n.curveEnabled){return}const t=new x.TextPath({data:O(n.a.width,n.a.height,n.curvePower,n.a.fontSize),text:P(n.text),letterSpacing:n.letterSpacing*n.a.fontSize,fontSize:n.a.fontSize,fontFamily:T(n.fontFamily),fontWeight:n.fontWeight,fontStyle:n.fontStyle,align:"center",textBaseline:"middle",fill:n.fill}),e=t.getSelfRect().width;if(e){const t=e-n.a.width,o=n.a.rotation*Math.PI/180,r=-t/2*Math.cos(o),i=-t/2*Math.sin(o);queueMicrotask(()=>{p(n)&&n.set({width:e,x:n.a.x+r,y:n.a.y+i})})}t.destroy()},[St,n.curveEnabled,n.curvePower,n.text,n.fontSize,n.fontFamily,n.fontWeight,n.fontStyle,n.letterSpacing]),r.useEffect(()=>()=>{Pt.current&&Pt.current()},[]),r.useEffect(()=>{mt&&!gt&&wt&&""===P(n.text)&&n.removable&&!$(n.placeholder)&&Z.deleteElements([n.id])},[wt,n.placeholder,n.removable,n.text,gt,mt]);const $t=J(n,Yt);let Dt=0;"middle"===n.verticalAlign&&(Dt=($t-Yt)/2),"bottom"===n.verticalAlign&&(Dt=$t-Yt);const Ht=v({fontLoaded:St,fontFamily:n.fontFamily,fontSize:n.fontSize,lineHeight:n.lineHeight}),_t=n.backgroundPadding*(n.fontSize*Ht*.5),Lt=n.backgroundCornerRadius*(n.fontSize*Ht*.5),Jt=r.useMemo(()=>{if(!n.backgroundEnabled||n.curveEnabled||n.legacyBackground){return""}const t=j(Ft);if(0===t.length){return""}const e=t.map(t=>({left:t.left+xt,right:t.right+xt,top:t.top+xt,bottom:t.bottom+xt}));return R({rects:e,padding:_t,cornerRadius:Lt})},[n.backgroundEnabled,n.curveEnabled,n.legacyBackground,Ft,St,_t,Lt,xt]),Nt=A(),qt=O(n.a.width,Yt,n.curvePower,n.fontSize),Vt=r.useRef(null),Gt=r.useRef(n.width),Kt=r.useRef(""),Qt=r.useRef(0),Ut=r.useRef(0),Zt=r.useRef(null),te=Ot&&n.strokeWidth>0&&!n.curveEnabled,ee=Xt>0?pt/(Xt+2*xt):1;return o(e,{children:[n.curveEnabled||n.legacyBackground?t(l,{x:n.a.x,y:n.a.y,offsetX:_t/ee,offsetY:_t/ee,rotation:n.a.rotation,scaleX:ee,scaleY:ee,hideInExport:!n.showInExport,listening:!1,visible:n.backgroundEnabled,opacity:n.backgroundOpacity*n.a.opacity,fill:n.backgroundColor,width:n.width+2*_t,height:$t+2*_t,cornerRadius:Lt}):t(s,{name:"html-background",x:n.a.x,y:n.a.y,offsetX:xt/ee,offsetY:(xt-Dt)/ee,rotation:n.a.rotation,scaleX:ee,scaleY:ee,hideInExport:!n.showInExport,listening:!1,visible:n.backgroundEnabled&&Jt.length>0,opacity:n.backgroundOpacity*n.a.opacity,fill:n.backgroundColor,data:Jt}),t(s,{x:n.a.x,y:n.a.y,rotation:n.a.rotation,data:qt,stroke:ot.stroke,strokeWidth:1,visible:!1}),t(l,{ref:rt,name:"element",x:n.a.x,y:n.a.y,listening:n.selectable,rotation:n.a.rotation,width:n.a.width,height:n.a.height,visible:!Wt,draggable:Nt?n.draggable&>:n.draggable,preventDefault:!Nt||gt,opacity:Ot?0:n.a.opacity,hideInExport:!n.showInExport,onDragMove:t=>{n.set({x:t.target.x(),y:t.target.y()})},onDragEnd:t=>{n.set(g(t.target))},id:n.id,onDblClick:t=>{n.contentEditable&&(Zt.current={x:t.evt.clientX,y:t.evt.clientY},n.toggleEditMode(!0))},onDblTap:t=>{var e;if(n.contentEditable){const o=null===(e=t.evt.changedTouches)||void 0===e?void 0:e[0];Zt.current=o?{x:o.clientX,y:o.clientY}:null,n.toggleEditMode(!0)}},onTransformStart:t=>{ft(!0),ut.current=n.height,Gt.current=n.width,Vt.current=t.target.position(),Kt.current=c(t.target),Qt.current=n.a.rotation,Ut.current=n.height},onTransform:t=>{const e=t.target,o=Kt.current,r="middle-left"===o||"middle-right"===o,i="top-center"===o||"bottom-center"===o,a=e.scaleX();if(r){const t=e.scaleX(),o=e.width()*t,r=m(Gt.current,n.fontSize);let i=o;o<r&&(i=r,Vt.current&&e.position(Vt.current)),e.width(i),e.scaleX(1),e.scaleY(1);const a=H(Object.assign(Object.assign({},n.toJSON()),{width:i}),{fontFamily:kt,color:zt,textOverflow:w.textOverflow}),s=F(a).height,l=w.textVerticalResizeEnabled?Math.max(s,ut.current):s;e.height(l),n.set({width:e.width(),height:l,x:e.x(),y:e.y()})}else if(i){const t="resize"===w.textOverflow,o="number"==typeof n.lineHeight?n.lineHeight:1,r=t?Yt:o*n.fontSize,i=e.height()*e.scaleY();if(i<r){if(e.height(r),Vt.current){if("top-center"===Kt.current){const t=Qt.current*Math.PI/180,o=Ut.current-r;e.x(Vt.current.x-o*Math.sin(t)),e.y(Vt.current.y+o*Math.cos(t))}else{e.position(Vt.current)}}}else{e.height(i)}e.scaleY(1),e.scaleX(1),Ut.current=Math.max(r,i),n.set({x:e.x(),y:e.y(),height:e.height(),rotation:e.rotation()})}else{e.scaleX(1),e.scaleY(1),n.set({fontSize:n.fontSize*a,letterSpacing:n.letterSpacing,width:e.width()*a,x:e.x(),y:e.y(),rotation:e.rotation(),height:e.height()*a,shadowBlur:n.shadowBlur*a,shadowOffsetX:n.shadowOffsetX*a,shadowOffsetY:n.shadowOffsetY*a,strokeWidth:n.strokeWidth*a,text:V(n.text,a)})}Vt.current=t.target.position()},onTransformEnd:t=>{ft(!1),ht(!0);const e=t.target.scaleX();t.target.scaleX(1),t.target.scaleY(1),n.set(Object.assign(Object.assign({},d(n,n.fontSize*e)),{width:u(t.target.width()*e),x:u(t.target.x()),y:u(t.target.y()),rotation:u(t.target.rotation()),text:V(n.text,e)}))}}),t(a,{ref:rt,image:nt,x:n.a.x,y:n.a.y,offsetX:xt,offsetY:xt-Dt,listening:!1,rotation:n.a.rotation,width:pt,height:pt*((null!==(tt=null==nt?void 0:nt.height)&&void 0!==tt?tt:0)/((null==nt?void 0:nt.width)||1)||1),visible:!Wt&&!Ot,opacity:n.a.opacity,shadowEnabled:n.shadowEnabled,shadowBlur:n.shadowBlur,shadowOffsetX:n.shadowOffsetX,shadowOffsetY:n.shadowOffsetY,shadowColor:n.shadowColor,shadowOpacity:n.shadowOpacity,hideInExport:!n.showInExport,editModeEnabled:n._editModeEnabled||ct||Wt}),(Wt&&!Ot||te)&&t(i,{x:n.a.x,y:n.a.y,rotation:n.a.rotation,offsetY:-Dt,children:t(Y,{divProps:{style:{pointerEvents:"none"}},children:t(Q,{dangerouslySetInnerHTML:{__html:Ft},style:{pointerEvents:"none",opacity:n.a.opacity,textShadow:n.shadowEnabled?`${n.shadowOffsetX}px ${n.shadowOffsetY}px ${n.shadowBlur}px ${U(n.shadowColor,null!==(et=n.shadowOpacity)&&void 0!==et?et:1)}`:void 0}})})}),Ot&&t(i,{x:n.a.x,y:n.a.y,rotation:n.a.rotation,offsetY:-Dt,children:t(Y,{divProps:{style:{zIndex:20}},children:t(K,{element:n,onChange:t=>{const e=W({oldText:P(n.text),newText:P(t),element:n});n.set(Object.assign({text:t},f(n,e)))},onBlur:t=>{p(n)&&(n.set(h(n)),n.toggleEditMode(!1),Bt(!0))},clickCoords:Zt.current})})})]})});
|
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { StoreType } from '../model/store.js';
|
|
3
3
|
import { ImageElementType } from '../model/image-model.js';
|
|
4
|
+
declare function alignToPixelGrid(element: ImageElementType, pixelRatio: number, ratio: number, enabled: boolean): {
|
|
5
|
+
x: number;
|
|
6
|
+
y: number;
|
|
7
|
+
width: number;
|
|
8
|
+
height: number;
|
|
9
|
+
deviceWidth: number;
|
|
10
|
+
deviceHeight: number;
|
|
11
|
+
phaseX: number;
|
|
12
|
+
phaseY: number;
|
|
13
|
+
spanX: number;
|
|
14
|
+
spanY: number;
|
|
15
|
+
aligned: boolean;
|
|
16
|
+
};
|
|
4
17
|
export declare const useSizeFixer: (src: string) => string;
|
|
5
18
|
export declare function maskCompositeSize(shapeRaster: {
|
|
6
19
|
width: number;
|
|
@@ -18,7 +31,7 @@ export declare const useCornerRadiusAndCrop: (element: ImageElementType, image:
|
|
|
18
31
|
y: number;
|
|
19
32
|
width: number;
|
|
20
33
|
height: number;
|
|
21
|
-
}, pixelRatio: number, cornerRadius
|
|
34
|
+
}, pixelRatio: number, cornerRadius: number | undefined, skipDownscale: boolean | undefined, isVector: boolean | undefined, borderInset: number | undefined, align: ReturnType<typeof alignToPixelGrid>) => HTMLCanvasElement | HTMLImageElement | undefined;
|
|
22
35
|
type ImageOrSVGElementType = ImageElementType & {
|
|
23
36
|
maskSrc?: string;
|
|
24
37
|
colorsReplace?: Map<string, string>;
|
package/canvas/image-element.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as t,jsxs as e,Fragment as r}from"react/jsx-runtime";import o from"react";import{observer as i}from"mobx-react-lite";import{isAlive as a}from"mobx-state-tree";import{Arc as n,Group as h,Image as s,Rect as c,Text as d,Transformer as l}from"react-konva";import{ROLES as g}from"../model/store.js";import u from"use-image";import p from"konva";import{Portal as m}from"react-konva-utils";import{useWorkspaceStyle as f}from"./workspace-style.js";import{incrementLoader as w,triggerLoadError as x}from"../utils/loader.js";import{polotnoError as y}from"@polotno/core/errors";import{getBorderInset as M,getCropRect as b}from"@polotno/core/image";import*as v from"@polotno/core/svg";import{flags as E}from"../utils/flags.js";import{trySetCanvasSize as S}from"../utils/canvas.js";import{roundEnabledPx as R,activeAnchorOf as C,isCornerAnchor as X,scaledBoxStyleAttrs as Y,roundedBoxStyleAttrs as I}from"../utils/px.js";import{useFilteredSource as O}from"./use-filtered-source.js";import{useFadeIn as j}from"./use-fadein.js";import{isTouchDevice as z}from"../utils/screen.js";import{useDelayer as W}from"./use-delayer.js";import{useColor as k}from"./use-color.js";import{downScaleCanvas as D}from"./downscale.js";function L(){return document.createElement("canvas")}export const useSizeFixer=t=>{const[e,r]=o.useState(t);return o.useEffect(()=>{(async()=>{const o=await async function(t){if(!v.isSvgUrl(t)){return t}const e=await v.urlToString(t),r=v.fixSize(e);return v.svgToURL(r)}(t);o!==e&&r(o)})()},[t]),e};function T(t,e){return{x:(t.x+e.x)/2,y:(t.y+e.y)/2}}const A=(t,e)=>e.width<5||e.height<5?t:e,H={keepRatio:!1,rotateEnabled:!1,boundBoxFunc:A},_={enabledAnchors:["top-left","top-right","bottom-left","bottom-right"],rotateEnabled:!1,borderEnabled:!1,boundBoxFunc:A};export function maskCompositeSize(t,e){const r=b({stretchEnabled:e.stretchEnabled,cropX:0,cropY:0,cropWidth:1,cropHeight:1,width:Math.max(e.width,1),height:Math.max(e.height,1)},t);return{width:Math.max(Math.round(r.width),1),height:Math.max(Math.round(r.height),1)}}const F=(t,e,r)=>Math.max(e,Math.min(r,t));export const useCornerRadiusAndCrop=(t,e,r,i,a=0,n=!1,h=!0,s=0)=>{var c,d;const l=Math.floor(F(t.a.width*i,1,1e4)),g=Math.floor(F(t.a.height*i,1,1e4)),u=Math.min(a*i,l/2,g/2),m=Math.min(s*i,l/2,g/2),f=Math.max(t.a.width/r.width,t.a.height/r.height)*i,w=(null===(c=t.page)||void 0===c?void 0:c._exportingOrRendering)&&E.imageDownScalingEnabled&&f<1&&!n,x=0===r.x&&0===r.y&&r.width===(null==e?void 0:e.width)&&r.height===(null==e?void 0:e.height),y=o.useMemo(()=>{if(e&&e.width&&e.height){return!x||0!==u||w||m?L():void 0}},[e,u,w,x,m]);return o.useLayoutEffect(()=>{if(!y||!e){return}S(y,l,g);const t=y.getContext("2d");if(!t){return}(u||m)&&(t.beginPath(),t.roundRect(m,m,l-2*m,g-2*m,Math.max(0,u-m)),t.clip());const o=w?D(e,f):e,i=w?{x:Math.floor(r.x*f),y:Math.floor(r.y*f),width:Math.floor(r.width*f),height:Math.floor(r.height*f)}:r;t.drawImage(o,i.x,i.y,i.width,i.height,0,0,y.width,y.height)},[y,t.a.width,t.a.height,r.x,r.y,r.width,r.height,a,i,n,null===(d=t.page)||void 0===d?void 0:d._exportingOrRendering,w,m]),o.useEffect(()=>()=>{y&&"CANVAS"===y.nodeName&&p.Util.releaseCanvas(y)},[y]),y||e};const P=L(),U=i(({element:r})=>{const i=Math.min(30,r.a.width/4,r.a.height/4),a=o.useRef(null);o.useEffect(()=>{const t=a.current;if(!t){return}const e=new p.Animation(e=>{t.rotate(((null==e?void 0:e.timeDiff)||0)/2)},t.getLayer());return e.start(),()=>{e.stop()}});const{mediaLoadingStyle:s}=f();return e(h,{x:r.x,y:r.y,rotation:r.rotation,listening:!1,opacity:r.a.opacity,hideInExport:!r.showInExport,children:[t(c,{width:r.a.width,height:r.a.height,fill:s.fill}),t(n,{ref:a,x:r.a.width/2,y:r.a.height/2,fill:s.textFill,outerRadius:Math.abs(i),innerRadius:Math.max(1,i-5),angle:270})]})}),N=i(({element:r})=>{const{mediaErrorStyle:o}=f(),i=Math.max(10,Math.min(30,r.a.width/25));return e(h,{x:r.x,y:r.y,rotation:r.rotation,listening:!1,opacity:r.a.opacity,hideInExport:!r.showInExport,children:[t(c,{width:r.a.width,height:r.a.height,fill:o.fill}),t(d,{text:"Can not load the image...",fontSize:i,width:r.a.width,height:r.a.height,align:"center",fill:o.textFill,verticalAlign:"middle",padding:5})]})});let B=u;export const setImageLoaderHook=t=>{B=t};export const useImageLoader=(t,e="",r="")=>{const i=o.useRef(void 0),a=()=>{var t;null===(t=i.current)||void 0===t||t.call(i),i.current=void 0};o.useEffect(()=>a,[]),o.useLayoutEffect(()=>{const o=e.slice(0,200),n=`image with id ${r} url: ${o}`;"loading"!==t||i.current||(i.current=w(n)),"loading"!==t&&a(),"failed"===t&&x(y("IMAGE_FAILED",n,{src:o,elementId:r,reason:"load"}))},[t])};export const ImageElement=i(({element:i,store:n})=>{var d,u,w;const x=f(),[y,E]=o.useState(!1),D=o.useRef(null),A=o.useRef(null),F=i.isSelected,[V,$]=(t=>{const[e,r]=o.useReducer(t=>t+1,0),i=o.useRef("loading"),a=o.useRef(t.src),n=o.useRef(t.src);n.current!==t.src&&(n.current=t.src,i.current="loading");const h=o.useMemo(()=>v.isSvgUrl(t.src)||"svg"===t.type,[t.src,t.type]);return o.useEffect(()=>{if(!h){return}if(!t.src){return}let e=!1;return(async()=>{i.current="loading",r();const o=await v.urlToString(t.src),n=v.fixSize(o);let h;h=t.colorsReplace?v.replaceColors(n,t.colorsReplace||new Map):v.svgToURL(n),e||(a.current=h,i.current="loaded",r())})(),()=>{e=!0}},[t.src,JSON.stringify(t.colorsReplace)]),h?[a.current,i.current]:[t.src,"loaded"]})(i),[q,G]=B(V,"anonymous"),J="svg"!==i.type||"loaded"===$?G:"loading";useImageLoader(J,i.src,i.id);const K=(null===(d=i.page)||void 0===d?void 0:d._exportingOrRendering)?1:Math.max(1,n.scale),Q=n._elementsPixelRatio*K,Z=(({image:t,status:e,type:r})=>{const i=o.useRef(void 0);return o.useEffect(()=>{i.current=t||i.current},[t]),"failed"!==e||"failed"!==e&&"svg"===r?i.current:void 0})({image:q,status:G,type:i.type}),tt=((t,e,r)=>{const i=o.useMemo(()=>{var o,i;const{flipX:a,flipY:n}=t,h="svg"===t.type||v.isSvgUrl(t.src),s=navigator.userAgent.toLowerCase().indexOf("firefox")>-1,c=(/^((?!chrome|android).)*safari/i.test(navigator.userAgent)||s)&&h||t.maskSrc;if(!a&&!n&&!c){return e}if(!e||!e.width||!e.height){return null}const d=L();let l=1;"svg"===t.type&&(l=Math.max(t.a.width/e.width*r,t.a.height/e.height*r)),S(d,Math.max(e.width*l,1),Math.max(e.height*l,1));let g=a?-d.width:0,u=n?-d.height:0;return null===(o=d.getContext("2d"))||void 0===o||o.scale(a?-1:1,n?-1:1),null===(i=d.getContext("2d"))||void 0===i||i.drawImage(e,g,u,d.width,d.height),d},[t.maskSrc,t.flipX,t.flipY,e,t.a.width,t.a.height,r]);return o.useEffect(()=>()=>{i&&"CANVAS"===i.nodeName&&p.Util.releaseCanvas(i)},[i]),i})(i,q||Z,Q),et=((t,e)=>{const r=useSizeFixer(t.maskSrc||""),[i,a]=B(r,"anonymous");return useImageLoader(r?a:"loaded",r||"",t.id),o.useMemo(()=>{if(!i){return e}if(!e||!e.width||!e.height){return e}const{width:r,height:o}=maskCompositeSize(e,{width:t.a.width,height:t.a.height,stretchEnabled:t.stretchEnabled}),a=L();a.width=r,a.height=o;const n=a.getContext("2d");if(!n){return e}n.drawImage(e,0,0,r,o,0,0,r,o),n.globalCompositeOperation="source-in";const h=function(t,e){const r=e.width/e.height;let o,i;return r>=t.width/t.height?(o=t.width,i=t.width/r):(o=t.height*r,i=t.height),{x:(t.width-o)/2,y:(t.height-i)/2,width:o,height:i}}(i,t);return n.drawImage(i,h.x,h.y,h.width,h.height,0,0,r,o),a},[e,i,t.a.width,t.a.height,t.stretchEnabled])})(i,tt)||P,[rt=P]=O(i,et);let{cropX:ot,cropY:it,cropWidth:at,cropHeight:nt}=i.a;"loaded"!==G&&(ot=it=0,at=nt=1);const ht=b({stretchEnabled:i.stretchEnabled,cropX:ot,cropY:it,cropWidth:at,cropHeight:nt,width:i.a.width,height:i.a.height},rt),st=ht.width,ct=ht.height,dt=i.stretchEnabled,lt=null!==(u=i.cornerRadius)&&void 0!==u?u:0,gt=(null===(w=i.page)||void 0===w?void 0:w._exportingOrRendering)?1:Math.min(2,n.scale),ut=n._elementsPixelRatio*gt;let pt=((t,e,r,i)=>{const a=useSizeFixer(t.clipSrc||""),[n,h]=B(a,"anonymous"),s=t.clipSrc?h:"loaded";useImageLoader(s,t.clipSrc,t.id);const c=o.useMemo(()=>{if(e&&n){return L()}},[e,n]);return o.useLayoutEffect(()=>{var o;if(!n){return}if(!e||!e.width||!e.height){return}if(!n||!n.width||!n.height){return}if(!c){return}const i=L(),a=Math.max(t.a.width/n.width*r,t.a.height/n.height*r);i.width=Math.max(n.width*a,1),i.height=Math.max(n.height*a,1),null===(o=i.getContext("2d"))||void 0===o||o.drawImage(n,0,0,i.width,i.height),c.width=Math.max(e.width,1),c.height=Math.max(e.height,1);const h=c.getContext("2d");h&&(h.save(),h.drawImage(i,0,0,e.width,e.height),p.Util.releaseCanvas(i),h.globalCompositeOperation="source-in",h.drawImage(e,0,0,c.width,c.height),h.restore())},[c,e,n,t.a.width,t.a.height,r,...i]),t.clipSrc&&n?c:e})(i,useCornerRadiusAndCrop(i,rt,ht,ut,lt,y||i._cropModeEnabled||"svg"===i.type,!0,M({borderSize:i.borderSize,borderColor:i.borderColor,width:i.a.width,height:i.a.height})),ut,[ht,lt,ut]);const mt=Math.max(i.a.width/st,i.a.height/ct);o.useEffect(()=>{var t;if(!i._cropModeEnabled){return}const e=null===(t=D.current)||void 0===t?void 0:t.getStage();function r(t){i._cropModeEnabled&&t.target!==A.current&&i.toggleCropMode(!1)}function o(t){i._cropModeEnabled&&t.target.parentNode!==(null==e?void 0:e.content)&&i.toggleCropMode(!1)}return document.body.addEventListener("click",o),null==e||e.on("click",r),null==e||e.on("tap",r),()=>{document.body.removeEventListener("click",o),document.body.removeEventListener("touchstart",o),null==e||e.off("click",r),null==e||e.off("click",r)}},[i._cropModeEnabled]);const ft=o.useRef(null),wt=o.useRef(null),xt=o.useRef(null);o.useLayoutEffect(()=>{i._cropModeEnabled&&(wt.current.nodes([ft.current]),xt.current.nodes([A.current]))},[i._cropModeEnabled]);var yt=o.useRef(null),Mt=o.useRef(0),bt=o.useRef(!1);const vt=t=>{var e;(null===(e=t.evt.touches)||void 0===e?void 0:e.length)>2&&t.target.stopDrag(),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(),o=t.target.height()*t.target.scaleY(),a=Math.min(1,st/r),n=Math.min(1,ct/o),h=1-a,s=Math.min(h,Math.max(0,Math.round(-t.target.x())/r)),c=1-n,d=Math.min(c,Math.max(0,Math.round(-t.target.y())/o));t.target.setAttrs({x:-s*rt.width,y:-d*rt.height,scaleX:1,scaleY:1}),i.set({cropX:s,cropY:d,cropWidth:a,cropHeight:n})},Et=()=>{"svg"!==i.type&&i.contentEditable&&(i.stretchEnabled||setTimeout(()=>{a(i)&&i.toggleCropMode(!0)}))},St="svg"===i.type&&Z,Rt="loading"===G&&!St,[Ct]=W(Rt,100,!1,!1),Xt="failed"===G,Yt=!Ct&&!Xt,It=o.useRef({cropX:0,cropY:0,cropWidth:0,cropHeight:0}),Ot=o.useRef(!1),jt=Yt?i.a.opacity:0;j(D,jt);const zt=i.selectable||n.role===g.ADMIN,Wt=z(),kt=k(i,i.borderColor,"stroke");return e(r,{children:[Ct&&t(U,{element:i}),Xt&&t(N,{element:i}),t(s,{ref:D,name:"element",id:i.id,image:pt,x:i.a.x,y:i.a.y,width:i.a.width||1,height:i.a.height||1,rotation:i.a.rotation,opacity:jt,shadowEnabled:i.shadowEnabled,shadowBlur:i.shadowBlur,shadowOffsetX:i.shadowOffsetX,shadowOffsetY:i.shadowOffsetY,shadowColor:i.shadowColor,shadowOpacity:i.shadowOpacity,customCrop:ht,listening:zt,draggable:Wt?i.draggable&&F:i.draggable,preventDefault:!Wt||F,hideInExport:!i.showInExport,onDragMove:t=>{i.set({x:t.target.x(),y:t.target.y()})},onDragEnd:t=>{i.set({x:t.target.x(),y:t.target.y()})},onDblClick:Et,onDblTap:Et,onTransformStart:t=>{E(!0),Ot.current=X(C(t.target)),It.current={cropX:i.cropX,cropY:i.cropY,cropWidth:i.cropWidth,cropHeight:i.cropHeight}},onTransform:t=>{const e=t.currentTarget,r=Math.abs(e.scaleX()-1)<1e-7?1:e.scaleX(),o=Math.abs(e.scaleY()-1)<1e-7?1:e.scaleY();e.scaleX(1),e.scaleY(1);const a=1-st/rt.width,n=Math.min(a,Math.max(0,i.cropX)),h=1-ct/rt.height,s=Math.min(h,Math.max(0,i.cropY)),c=Ot.current,d=!c&&r<1&&It.current.cropHeight>ct/rt.height;let l=c?i.cropWidth:i.cropWidth*r;d&&(l=i.cropWidth);const g=!c&&o<1&&It.current.cropWidth>st/rt.width;let u=c?i.cropHeight:i.cropHeight*o;g&&(u=i.cropHeight),dt&&(l=i.cropWidth,u=i.cropHeight);const p=c?Math.min(r,o):1;i.set(Object.assign({cropX:n,cropY:s,x:e.x(),y:e.y(),width:e.width()*r,height:e.height()*o,rotation:t.target.rotation(),cropWidth:Math.min(l,1-n),cropHeight:Math.min(u,1-s)},1!==p&&Object.assign(Object.assign({},Y(i,p)),{borderSize:i.borderSize*p})))},onTransformEnd:t=>{const e=t.currentTarget;i.set(Object.assign(Object.assign({width:e.width(),height:e.height(),x:e.x(),y:e.y(),rotation:t.target.rotation(),cropWidth:st/rt.width,cropHeight:ct/rt.height},I(i)),{borderSize:R(i.borderSize)})),E(!1)}}),t(c,Object.assign({x:i.x,y:i.y,width:Math.max(i.a.width-i.borderSize,0),height:Math.max(i.a.height-i.borderSize,0),opacity:jt,offsetX:-i.borderSize/2,offsetY:-i.borderSize/2},kt,{strokeWidth:i.borderSize,listening:!1,visible:!!i.borderSize,rotation:i.rotation,cornerRadius:Math.max(0,lt-i.borderSize),hideInExport:!i.showInExport})),i._cropModeEnabled&&e(m,{selector:".page-abs-container",enabled:!0,children:[t(c,{x:-window.innerWidth/n.scale,y:-window.innerWidth/n.scale,width:window.innerWidth/n.scale*3,height:window.innerWidth/n.scale*3,fill:x.cropOverlayFill}),t(s,{listening:!1,image:pt,x:i.x,y:i.y,width:i.a.width,height:i.a.height,rotation:i.rotation,shadowEnabled:i.shadowEnabled,shadowBlur:i.shadowBlur}),e(h,{x:i.x,y:i.y,rotation:i.rotation,scaleX:mt,scaleY:mt,children:[t(s,{image:rt,ref:A,opacity:.4,draggable:!0,x:-i.cropX*rt.width,y:-i.cropY*rt.height,onDragMove:vt,onTransform:vt,onTouchMove:t=>{t.evt.preventDefault();const e=t.target.getStage().getPointersPositions();var r=e[0],o=e[1];const i=t.target;if(r&&!o&&!i.isDragging()&&bt.current&&(i.startDrag(),bt.current=!1),r&&o){p.hitOnDragEnabled=!0,i.isDragging()&&(bt.current=!0,i.stopDrag());const e=t.target.getAbsoluteTransform().copy();e.invert();var a={x:r.x,y:r.y},n={x:o.x,y:o.y};if(!yt.current){return void(yt.current=T(a,n))}var h=T(a,n),s=function(t,e){return Math.sqrt(Math.pow(e.x-t.x,2)+Math.pow(e.y-t.y,2))}(a,n);Mt.current||(Mt.current=s);const m=i.position();var c={x:h.x-m.x,y:h.y-m.y},d=s/Mt.current;i.scaleX(d),i.scaleY(d);const f=e.point(h),w=e.point(yt.current);var l=f.x-w.x,g=f.y-w.y,u={x:Math.min(0,h.x-c.x*d+l),y:Math.min(0,h.y-c.y*d+g)};i.position(u),Mt.current=s,yt.current=h,vt(t)}},onTouchEnd:t=>{Mt.current=0,yt.current=null,p.hitOnDragEnabled=!1}}),t(l,Object.assign({ref:xt},_,x.outerImageCropTransformerStyle)),t(c,{width:st,height:ct,ref:ft,listening:!1,onTransform:t=>{if(i.cropX<Math.abs(t.target.x()/rt.width)&&t.target.x()<0&&i.cropX>0){const e=(i.cropWidth+i.cropX)*rt.width;t.target.scaleX(1),t.target.width(e)}if(i.cropY<Math.abs(t.target.y()/rt.height)&&t.target.y()<0&&i.cropY>0){const e=(i.cropHeight+i.cropY)*rt.height;t.target.scaleY(1),t.target.height(e)}t.target.x()<-i.cropX*rt.width-1e-9&&(t.target.x(-i.cropX*rt.width),t.target.scaleX(1)),t.target.y()<-i.cropY*rt.height-1e-9&&(t.target.y(-i.cropY*rt.height),t.target.scaleY(1));const e=Math.min(1,Math.max(0,i.cropX+t.target.x()/rt.width)),r=Math.min(1,Math.max(0,t.target.y()/rt.height+i.cropY)),o=t.target.width()*t.target.scaleX(),a=t.target.height()*t.target.scaleY(),n=Math.min(1-e,o/rt.width),h=Math.min(1-r,a/rt.height),s=t.target.getAbsolutePosition(t.target.getParent().getParent());t.target.scale({x:1,y:1}),t.target.position({x:0,y:0}),i.set({x:s.x,y:s.y,cropX:e,cropY:r,cropWidth:n,cropHeight:h,width:Math.min(o*mt,rt.width*(1-e)*mt),height:Math.min(a*mt,rt.height*(1-r)*mt)})}}),t(l,Object.assign({ref:wt},H,x.innerImageCropTransformerStyle,{visible:i.resizable}))]})]})]})});
|
|
1
|
+
import{jsx as t,jsxs as e,Fragment as r}from"react/jsx-runtime";import i from"react";import{observer as o}from"mobx-react-lite";import{isAlive as a}from"mobx-state-tree";import{Arc as n,Group as h,Image as d,Rect as s,Text as c,Transformer as g}from"react-konva";import{ROLES as l}from"../model/store.js";import u from"use-image";import p from"konva";import{Portal as m}from"react-konva-utils";import{useWorkspaceStyle as f}from"./workspace-style.js";import{incrementLoader as w,triggerLoadError as x}from"../utils/loader.js";import{polotnoError as y}from"@polotno/core/errors";import{getBorderInset as v,getCropRect as M}from"@polotno/core/image";import*as b from"@polotno/core/svg";import{flags as E}from"../utils/flags.js";import{trySetCanvasSize as S}from"../utils/canvas.js";import{roundEnabledPx as X,activeAnchorOf as Y,roundedCropFraction as C,roundedGeometryPx as R,roundedPosition as I,isCornerAnchor as O,scaledBoxStyleAttrs as W,roundedBoxStyleAttrs as j}from"../utils/px.js";import{useFilteredSource as z}from"./use-filtered-source.js";import{useFadeIn as H}from"./use-fadein.js";import{isTouchDevice as k}from"../utils/screen.js";import{useDelayer as D}from"./use-delayer.js";import{useColor as _}from"./use-color.js";import{resampleCanvas as A,RESAMPLE_SKIP_THRESHOLD as L}from"./downscale.js";const T=1e4;function F(){return document.createElement("canvas")}const B=t=>"svg"===t.type||b.isSvgUrl(t.src||"");export const useSizeFixer=t=>{const[e,r]=i.useState(t);return i.useEffect(()=>{(async()=>{const i=b.isSvgUrl(t)?b.prepareSvgSource(await b.urlToString(t)):t;i!==e&&r(i)})()},[t]),e};function P(t,e){return{x:(t.x+e.x)/2,y:(t.y+e.y)/2}}const N=(t,e)=>e.width<5||e.height<5?t:e,U={keepRatio:!1,rotateEnabled:!1,boundBoxFunc:N},V={enabledAnchors:["top-left","top-right","bottom-left","bottom-right"],rotateEnabled:!1,borderEnabled:!1,boundBoxFunc:N};export function maskCompositeSize(t,e){const r=M({stretchEnabled:e.stretchEnabled,cropX:0,cropY:0,cropWidth:1,cropHeight:1,width:Math.max(e.width,1),height:Math.max(e.height,1)},t);return{width:Math.max(Math.round(r.width),1),height:Math.max(Math.round(r.height),1)}}const $=(t,e,r)=>Math.max(e,Math.min(r,t)),q=(t,e,r)=>Math.max(t.a.width/e.width,t.a.height/e.height)*r;export const useCornerRadiusAndCrop=(t,e,r,o,a=0,n=!1,h=!0,d=0,s)=>{var c,g,l;const u=T,m=T,f=s.aligned?$(s.deviceWidth,1,u):Math.floor($(t.a.width*o,1,u)),w=s.aligned?$(s.deviceHeight,1,m):Math.floor($(t.a.height*o,1,m)),x=Math.min(a*o,f/2,w/2),y=Math.min(d*o,f/2,w/2),v=q(t,r,o),M=Boolean(null===(c=t.page)||void 0===c?void 0:c._exporting)&&!(null===(g=t.page)||void 0===g?void 0:g._rendering)&&E.imageDownScalingEnabled&&!n&&(v<L||s.aligned),b=0===r.x&&0===r.y&&r.width===(null==e?void 0:e.width)&&r.height===(null==e?void 0:e.height),X=i.useMemo(()=>{if(e&&e.width&&e.height){return!b||0!==x||M||y?F():void 0}},[e,x,M,b,y]);return i.useLayoutEffect(()=>{var i;if(!X||!e){return}S(X,f,w);const o=X.getContext("2d");if(o){if((null===(i=t.page)||void 0===i?void 0:i._exportingOrRendering)&&(o.imageSmoothingQuality="high"),(x||y)&&(o.beginPath(),o.roundRect(y,y,f-2*y,w-2*y,Math.max(0,x-y)),o.clip()),M){const t=X.width===f&&X.height===w&&s.aligned,i=A(e,r,X.width,X.height,{x:t?s.phaseX:0,y:t?s.phaseY:0,width:t?s.spanX:X.width,height:t?s.spanY:X.height});return o.drawImage(i,0,0),void p.Util.releaseCanvas(i)}o.drawImage(e,r.x,r.y,r.width,r.height,0,0,X.width,X.height)}},[X,t.a.width,t.a.height,r.x,r.y,r.width,r.height,a,o,n,null===(l=t.page)||void 0===l?void 0:l._exportingOrRendering,M,s.phaseX,s.phaseY,y]),i.useEffect(()=>()=>{X&&"CANVAS"===X.nodeName&&p.Util.releaseCanvas(X)},[X]),X||e};const G=F(),J=o(({element:r})=>{const o=Math.min(30,r.a.width/4,r.a.height/4),a=i.useRef(null);i.useEffect(()=>{const t=a.current;if(!t){return}const e=new p.Animation(e=>{t.rotate(((null==e?void 0:e.timeDiff)||0)/2)},t.getLayer());return e.start(),()=>{e.stop()}});const{mediaLoadingStyle:d}=f();return e(h,{x:r.x,y:r.y,rotation:r.rotation,listening:!1,opacity:r.a.opacity,hideInExport:!r.showInExport,children:[t(s,{width:r.a.width,height:r.a.height,fill:d.fill}),t(n,{ref:a,x:r.a.width/2,y:r.a.height/2,fill:d.textFill,outerRadius:Math.abs(o),innerRadius:Math.max(1,o-5),angle:270})]})}),Q=o(({element:r})=>{const{mediaErrorStyle:i}=f(),o=Math.max(10,Math.min(30,r.a.width/25));return e(h,{x:r.x,y:r.y,rotation:r.rotation,listening:!1,opacity:r.a.opacity,hideInExport:!r.showInExport,children:[t(s,{width:r.a.width,height:r.a.height,fill:i.fill}),t(c,{text:"Can not load the image...",fontSize:o,width:r.a.width,height:r.a.height,align:"center",fill:i.textFill,verticalAlign:"middle",padding:5})]})});let K=u;export const setImageLoaderHook=t=>{K=t};export const useImageLoader=(t,e="",r="")=>{const o=i.useRef(void 0),a=()=>{var t;null===(t=o.current)||void 0===t||t.call(o),o.current=void 0};i.useEffect(()=>a,[]),i.useLayoutEffect(()=>{const i=e.slice(0,200),n=`image with id ${r} url: ${i}`;"loading"!==t||o.current||(o.current=w(n)),"loading"!==t&&a(),"failed"===t&&x(y("IMAGE_FAILED",n,{src:i,elementId:r,reason:"load"}))},[t])};export const ImageElement=o(({element:o,store:n})=>{var c,u,w,x,y,A;const N=f(),[$,Z]=i.useState(!1),tt=i.useRef(null),et=i.useRef(null),rt=o.isSelected,[it,ot]=(t=>{var e;const[r,o]=i.useReducer(t=>t+1,0),a=B(t),n=a?t.src+"\n"+JSON.stringify(null!==(e=t.colorsReplace)&&void 0!==e?e:null):"",h=i.useRef("loading"),d=i.useRef(""),s=i.useRef(n);return s.current!==n&&(s.current=n,h.current="loading"),i.useEffect(()=>{if(!a||!t.src){return}let e=!1;return(async()=>{const r=b.prepareSvgSource(await b.urlToString(t.src),t.colorsReplace);e||(d.current=r,h.current="loaded",o())})().catch(()=>{e||(h.current="failed",o())}),()=>{e=!0}},[n]),a?[d.current,h.current]:[t.src,"loaded"]})(o),[at,nt]=K(it,"anonymous"),ht="loaded"===ot?nt:ot;useImageLoader(ht,o.src,o.id);const dt=(null===(c=o.page)||void 0===c?void 0:c._exportingOrRendering)?1:Math.max(1,n.scale),st=n._elementsPixelRatio*dt,ct=(({image:t,status:e})=>{const r=i.useRef(void 0);return i.useEffect(()=>{r.current=t||r.current},[t]),"failed"!==e?r.current:void 0})({image:at,status:ht}),gt=((t,e,r)=>{const o=i.useMemo(()=>{var i,o;const{flipX:a,flipY:n}=t,h=B(t),d=navigator.userAgent.toLowerCase().indexOf("firefox")>-1,s=(/^((?!chrome|android).)*safari/i.test(navigator.userAgent)||d)&&h||t.maskSrc;if(!a&&!n&&!s){return e}if(!e||!e.width||!e.height){return null}const c=F();let g=1;"svg"===t.type&&(g=Math.max(t.a.width/e.width*r,t.a.height/e.height*r)),S(c,Math.max(e.width*g,1),Math.max(e.height*g,1));let l=a?-c.width:0,u=n?-c.height:0;return null===(i=c.getContext("2d"))||void 0===i||i.scale(a?-1:1,n?-1:1),null===(o=c.getContext("2d"))||void 0===o||o.drawImage(e,l,u,c.width,c.height),c},[t.maskSrc,t.flipX,t.flipY,e,t.a.width,t.a.height,r]);return i.useEffect(()=>()=>{o&&"CANVAS"===o.nodeName&&p.Util.releaseCanvas(o)},[o]),o})(o,at||ct,st),lt=((t,e)=>{const r=useSizeFixer(t.maskSrc||""),[o,a]=K(r,"anonymous");return useImageLoader(r?a:"loaded",r||"",t.id),i.useMemo(()=>{if(!o){return e}if(!e||!e.width||!e.height){return e}const{width:r,height:i}=maskCompositeSize(e,{width:t.a.width,height:t.a.height,stretchEnabled:t.stretchEnabled}),a=F();a.width=r,a.height=i;const n=a.getContext("2d");if(!n){return e}n.drawImage(e,0,0,r,i,0,0,r,i),n.globalCompositeOperation="source-in";const h=function(t,e){const r=e.width/e.height;let i,o;return r>=t.width/t.height?(i=t.width,o=t.width/r):(i=t.height*r,o=t.height),{x:(t.width-i)/2,y:(t.height-o)/2,width:i,height:o}}(o,t);return n.drawImage(o,h.x,h.y,h.width,h.height,0,0,r,i),a},[e,o,t.a.width,t.a.height,t.stretchEnabled])})(o,gt)||G,[ut=G]=z(o,lt);let{cropX:pt,cropY:mt,cropWidth:ft,cropHeight:wt}=o.a;"loaded"!==nt&&(pt=mt=0,ft=wt=1);const xt=M({stretchEnabled:o.stretchEnabled,cropX:pt,cropY:mt,cropWidth:ft,cropHeight:wt,width:o.a.width,height:o.a.height},ut),yt=xt.width,vt=xt.height,Mt=o.stretchEnabled,bt=null!==(u=o.cornerRadius)&&void 0!==u?u:0,Et=(null===(w=o.page)||void 0===w?void 0:w._exportingOrRendering)?1:Math.min(2,n.scale),St=n._elementsPixelRatio*Et,Xt=$||o._cropModeEnabled||"svg"===o.type,Yt=function(t,e,r,i){const{x:o,y:a,width:n,height:h}=t.a,d={x:o,y:a,width:n,height:h,deviceWidth:0,deviceHeight:0,phaseX:0,phaseY:0,spanX:0,spanY:0,aligned:!1};if(!i){return d}const s=o*e,c=a*e,g=Math.round(s),l=Math.round(c),u=Math.max(1,Math.round(s+n*e)-g),p=Math.max(1,Math.round(c+h*e)-l),m=t=>Math.abs(t-Math.round(t))>.001;return m(s)||m(c)||m(n*e)||m(h*e)?u>T||p>T?d:r<L||r<=1&&u*p<=4e6?{x:g/e,y:l/e,width:u/e,height:p/e,deviceWidth:u,deviceHeight:p,phaseX:s-g,phaseY:c-l,spanX:n*e,spanY:h*e,aligned:!0}:d:d}(o,St,q(o,xt,St),Boolean(null===(x=o.page)||void 0===x?void 0:x._exporting)&&!(null===(y=o.page)||void 0===y?void 0:y._rendering)&&E.imageDownScalingEnabled&&0===o.a.rotation&&"group"!==(null===(A=o.parent)||void 0===A?void 0:A.type)&&!Xt),Ct=Yt.aligned?Yt:{x:o.x,y:o.y,width:o.a.width,height:o.a.height};let Rt=((t,e,r,o)=>{const a=useSizeFixer(t.clipSrc||""),[n,h]=K(a,"anonymous"),d=t.clipSrc?h:"loaded";useImageLoader(d,t.clipSrc,t.id);const s=i.useMemo(()=>{if(e&&n){return F()}},[e,n]);return i.useLayoutEffect(()=>{var i;if(!n){return}if(!e||!e.width||!e.height){return}if(!n||!n.width||!n.height){return}if(!s){return}const o=F(),a=Math.max(t.a.width/n.width*r,t.a.height/n.height*r);o.width=Math.max(n.width*a,1),o.height=Math.max(n.height*a,1),null===(i=o.getContext("2d"))||void 0===i||i.drawImage(n,0,0,o.width,o.height),s.width=Math.max(e.width,1),s.height=Math.max(e.height,1);const h=s.getContext("2d");h&&(h.save(),h.drawImage(o,0,0,e.width,e.height),p.Util.releaseCanvas(o),h.globalCompositeOperation="source-in",h.drawImage(e,0,0,s.width,s.height),h.restore())},[s,e,n,t.a.width,t.a.height,r,...o]),t.clipSrc&&n?s:e})(o,useCornerRadiusAndCrop(o,ut,xt,St,bt,Xt,!0,v({borderSize:o.borderSize,borderColor:o.borderColor,width:o.a.width,height:o.a.height}),Yt),St,[xt,bt,St]);const It=Math.max(o.a.width/yt,o.a.height/vt);i.useEffect(()=>{var t;if(!o._cropModeEnabled){return}const e=null===(t=tt.current)||void 0===t?void 0:t.getStage();function r(t){o._cropModeEnabled&&t.target!==et.current&&o.toggleCropMode(!1)}function i(t){o._cropModeEnabled&&t.target.parentNode!==(null==e?void 0:e.content)&&o.toggleCropMode(!1)}return document.body.addEventListener("click",i),null==e||e.on("click",r),null==e||e.on("tap",r),()=>{document.body.removeEventListener("click",i),document.body.removeEventListener("touchstart",i),null==e||e.off("click",r),null==e||e.off("click",r)}},[o._cropModeEnabled]);const Ot=i.useRef(null),Wt=i.useRef(null),jt=i.useRef(null);i.useLayoutEffect(()=>{o._cropModeEnabled&&(Wt.current.nodes([Ot.current]),jt.current.nodes([et.current]))},[o._cropModeEnabled]);var zt=i.useRef(null),Ht=i.useRef(0),kt=i.useRef(!1);const Dt=t=>{var e;(null===(e=t.evt.touches)||void 0===e?void 0:e.length)>2&&t.target.stopDrag(),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(),i=t.target.height()*t.target.scaleY(),a=Math.min(1,yt/r),n=Math.min(1,vt/i),h=1-a,d=Math.min(h,Math.max(0,Math.round(-t.target.x())/r)),s=1-n,c=Math.min(s,Math.max(0,Math.round(-t.target.y())/i));t.target.setAttrs({x:-d*ut.width,y:-c*ut.height,scaleX:1,scaleY:1}),o.set({cropX:d,cropY:c,cropWidth:a,cropHeight:n})},_t=()=>{"svg"!==o.type&&o.contentEditable&&(o.stretchEnabled||setTimeout(()=>{a(o)&&o.toggleCropMode(!0)}))},At=B(o)&&ct,Lt="loading"===ht&&!At,[Tt]=D(Lt,100,!1,!1),Ft="failed"===ht,Bt=!Tt&&!Ft,Pt=i.useRef({cropX:0,cropY:0,cropWidth:0,cropHeight:0}),Nt=i.useRef(!1),Ut=Bt?o.a.opacity:0;H(tt,Ut);const Vt=o.selectable||n.role===l.ADMIN,$t=k(),qt=_(o,o.borderColor,"stroke");return e(r,{children:[Tt&&t(J,{element:o}),Ft&&t(Q,{element:o}),t(d,{ref:tt,name:"element",id:o.id,image:Rt,x:Yt.x,y:Yt.y,width:Yt.width||1,height:Yt.height||1,rotation:o.a.rotation,opacity:Ut,shadowEnabled:o.shadowEnabled,shadowBlur:o.shadowBlur,shadowOffsetX:o.shadowOffsetX,shadowOffsetY:o.shadowOffsetY,shadowColor:o.shadowColor,shadowOpacity:o.shadowOpacity,customCrop:xt,listening:Vt,draggable:$t?o.draggable&&rt:o.draggable,preventDefault:!$t||rt,hideInExport:!o.showInExport,onDragMove:t=>{o.set({x:t.target.x(),y:t.target.y()})},onDragEnd:t=>{o.set(I(t.target))},onDblClick:_t,onDblTap:_t,onTransformStart:t=>{Z(!0),Nt.current=O(Y(t.target)),Pt.current={cropX:o.cropX,cropY:o.cropY,cropWidth:o.cropWidth,cropHeight:o.cropHeight}},onTransform:t=>{const e=t.currentTarget,r=Math.abs(e.scaleX()-1)<1e-7?1:e.scaleX(),i=Math.abs(e.scaleY()-1)<1e-7?1:e.scaleY();e.scaleX(1),e.scaleY(1);const a=1-yt/ut.width,n=Math.min(a,Math.max(0,o.cropX)),h=1-vt/ut.height,d=Math.min(h,Math.max(0,o.cropY)),s=Nt.current,c=!s&&r<1&&Pt.current.cropHeight>vt/ut.height;let g=s?o.cropWidth:o.cropWidth*r;c&&(g=o.cropWidth);const l=!s&&i<1&&Pt.current.cropWidth>yt/ut.width;let u=s?o.cropHeight:o.cropHeight*i;l&&(u=o.cropHeight),Mt&&(g=o.cropWidth,u=o.cropHeight);const p=s?Math.min(r,i):1;o.set(Object.assign({cropX:n,cropY:d,x:e.x(),y:e.y(),width:e.width()*r,height:e.height()*i,rotation:t.target.rotation(),cropWidth:Math.min(g,1-n),cropHeight:Math.min(u,1-d)},1!==p&&Object.assign(Object.assign({},W(o,p)),{borderSize:o.borderSize*p})))},onTransformEnd:t=>{const e=t.currentTarget;o.set(Object.assign(Object.assign({width:R(e.width()),height:R(e.height()),x:R(e.x()),y:R(e.y()),rotation:R(t.target.rotation()),cropX:C(o.cropX),cropY:C(o.cropY),cropWidth:C(yt/ut.width),cropHeight:C(vt/ut.height)},j(o)),{borderSize:X(o.borderSize)})),Z(!1)}}),t(s,Object.assign({x:Ct.x,y:Ct.y,width:Math.max(Ct.width-o.borderSize,0),height:Math.max(Ct.height-o.borderSize,0),opacity:Ut,offsetX:-o.borderSize/2,offsetY:-o.borderSize/2},qt,{strokeWidth:o.borderSize,listening:!1,visible:!!o.borderSize,rotation:o.rotation,cornerRadius:Math.max(0,bt-o.borderSize),hideInExport:!o.showInExport})),o._cropModeEnabled&&e(m,{selector:".page-abs-container",enabled:!0,children:[t(s,{x:-window.innerWidth/n.scale,y:-window.innerWidth/n.scale,width:window.innerWidth/n.scale*3,height:window.innerWidth/n.scale*3,fill:N.cropOverlayFill}),t(d,{listening:!1,image:Rt,x:o.x,y:o.y,width:o.a.width,height:o.a.height,rotation:o.rotation,shadowEnabled:o.shadowEnabled,shadowBlur:o.shadowBlur}),e(h,{x:o.x,y:o.y,rotation:o.rotation,scaleX:It,scaleY:It,children:[t(d,{image:ut,ref:et,opacity:.4,draggable:!0,x:-o.cropX*ut.width,y:-o.cropY*ut.height,onDragMove:Dt,onTransform:Dt,onTouchMove:t=>{t.evt.preventDefault();const e=t.target.getStage().getPointersPositions();var r=e[0],i=e[1];const o=t.target;if(r&&!i&&!o.isDragging()&&kt.current&&(o.startDrag(),kt.current=!1),r&&i){p.hitOnDragEnabled=!0,o.isDragging()&&(kt.current=!0,o.stopDrag());const e=t.target.getAbsoluteTransform().copy();e.invert();var a={x:r.x,y:r.y},n={x:i.x,y:i.y};if(!zt.current){return void(zt.current=P(a,n))}var h=P(a,n),d=function(t,e){return Math.sqrt(Math.pow(e.x-t.x,2)+Math.pow(e.y-t.y,2))}(a,n);Ht.current||(Ht.current=d);const m=o.position();var s={x:h.x-m.x,y:h.y-m.y},c=d/Ht.current;o.scaleX(c),o.scaleY(c);const f=e.point(h),w=e.point(zt.current);var g=f.x-w.x,l=f.y-w.y,u={x:Math.min(0,h.x-s.x*c+g),y:Math.min(0,h.y-s.y*c+l)};o.position(u),Ht.current=d,zt.current=h,Dt(t)}},onTouchEnd:t=>{Ht.current=0,zt.current=null,p.hitOnDragEnabled=!1}}),t(g,Object.assign({ref:jt},V,N.outerImageCropTransformerStyle)),t(s,{width:yt,height:vt,ref:Ot,listening:!1,onTransform:t=>{if(o.cropX<Math.abs(t.target.x()/ut.width)&&t.target.x()<0&&o.cropX>0){const e=(o.cropWidth+o.cropX)*ut.width;t.target.scaleX(1),t.target.width(e)}if(o.cropY<Math.abs(t.target.y()/ut.height)&&t.target.y()<0&&o.cropY>0){const e=(o.cropHeight+o.cropY)*ut.height;t.target.scaleY(1),t.target.height(e)}t.target.x()<-o.cropX*ut.width-1e-9&&(t.target.x(-o.cropX*ut.width),t.target.scaleX(1)),t.target.y()<-o.cropY*ut.height-1e-9&&(t.target.y(-o.cropY*ut.height),t.target.scaleY(1));const e=Math.min(1,Math.max(0,o.cropX+t.target.x()/ut.width)),r=Math.min(1,Math.max(0,t.target.y()/ut.height+o.cropY)),i=t.target.width()*t.target.scaleX(),a=t.target.height()*t.target.scaleY(),n=Math.min(1-e,i/ut.width),h=Math.min(1-r,a/ut.height),d=t.target.getAbsolutePosition(t.target.getParent().getParent());t.target.scale({x:1,y:1}),t.target.position({x:0,y:0}),o.set({x:d.x,y:d.y,cropX:e,cropY:r,cropWidth:n,cropHeight:h,width:Math.min(i*It,ut.width*(1-e)*It),height:Math.min(a*It,ut.height*(1-r)*It)})}}),t(g,Object.assign({ref:Wt},U,N.innerImageCropTransformerStyle,{visible:o.resizable}))]})]})]})});
|
package/canvas/line-element.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as t,jsxs as e,Fragment as o}from"react/jsx-runtime";import r from"react";import{observer as a}from"mobx-react-lite";import{Group as
|
|
1
|
+
import{jsx as t,jsxs as e,Fragment as o}from"react/jsx-runtime";import r from"react";import{observer as a}from"mobx-react-lite";import{Group as n,Line as i,Rect as s,Circle as l}from"react-konva";import{ROLES as h}from"../model/store.js";import{useColor as d}from"./use-color.js";import{getLineHeadGeometry as c}from"@polotno/core/line-head";import{Portal as g}from"react-konva-utils";import{useAnchorSnap as m}from"./use-transformer-snap.js";import{useWorkspaceStyle as f}from"./workspace-style.js";import{isTouchDevice as p}from"../utils/screen.js";import{roundedGeometryAttrs as x,roundedPosition as u}from"../utils/px.js";export function getMiddlePoints(t){const{x:e,y:o,width:r,height:a,rotation:n}=t.a,i=n*Math.PI/180,s={x:e+a/2*Math.cos(i+Math.PI/2),y:o+a/2*Math.sin(i+Math.PI/2)};return{middleLeft:s,middleRight:{x:s.x+r*Math.cos(i),y:s.y+r*Math.sin(i)}}}export function getLinePositionFromMiddlePoints(t,e,o){const r=Math.sqrt(Math.pow(e.x-t.x,2)+Math.pow(e.y-t.y,2)),a=Math.atan2(e.y-t.y,e.x-t.x),n=180*a/Math.PI;return{x:t.x+Math.cos(a-Math.PI/2)*o/2,y:t.y+Math.sin(a-Math.PI/2)*o/2,width:r,height:o,rotation:n}}const y=(t,e,o)=>{const r=o.anchorSize;return{offsetX:r/2/t,offsetY:r/2/t,width:r/t,height:r/t,cornerRadius:o.anchorCornerRadius/t,fill:o.anchorFill,stroke:o.anchorStroke,strokeWidth:o.anchorStrokeWidth,strokeScaleEnabled:!1,draggable:!0,dragDistance:0,onMouseEnter:t=>{t.target.getStage().container().style.cursor="crosshair"},onMouseLeave:t=>{t.target.getStage().container().style.cursor=""},onDragStart:t=>{e.history.startTransaction()},onDragEnd:t=>{e.history.endTransaction()}}},w=a(({element:e,type:o})=>{const r=d(e,e.a.color,"fill"),a=d(e,e.a.color,"stroke"),n=c(o,e.height);if(!n){return null}const s=Object.assign(Object.assign(Object.assign({strokeWidth:e.height,lineCap:"round",lineJoin:"round"},a),r),{opacity:e.a.opacity,hideInExport:!e.showInExport});return"circle"===n.kind?t(l,Object.assign({x:n.cx,y:n.cy,radius:n.r},s)):t(i,Object.assign({points:n.points.flat(),closed:n.filled},s))});export const LineElement=a(({element:a,store:l})=>{const{transformerStyle:c}=f(),M=r.useRef(null),b=r.useRef(null),v=r.useRef(null),k=a.selectable||l.role===h.ADMIN,j=p(),E=l.selectedElements.indexOf(a)>=0&&1===l.selectedElements.length,O=a.isSelected,{middleLeft:P,middleRight:I}=getMiddlePoints(a);m(b,[M],[E]),m(v,[M],[E]);const S=d(a,a.a.color,"stroke");return e(o,{children:[t(i,Object.assign({ref:M,name:"element",id:a.id,x:a.a.x,y:a.a.y,points:[0,0,a.a.width,0],offsetY:-a.a.height/2,strokeWidth:a.a.height,hitStrokeWidth:Math.max(a.a.height,20),dash:a.dash.map(t=>t*a.a.height)},S,{rotation:a.a.rotation,opacity:a.animated("opacity"),shadowEnabled:a.shadowEnabled,shadowBlur:a.shadowBlur,shadowOffsetX:a.shadowOffsetX,shadowOffsetY:a.shadowOffsetY,shadowColor:a.shadowColor,shadowOpacity:a.shadowOpacity,listening:k,draggable:j?a.draggable&&O:a.draggable,preventDefault:!j||O,hideInExport:!a.showInExport,onDragMove:t=>{a.set({x:t.target.x(),y:t.target.y()})},onDragEnd:t=>{a.set(u(t.target))},onTransform:t=>{const e=t.target.scaleX();t.target.scaleX(1),t.target.scaleY(1),a.set({height:a.height*e,width:a.width*e,x:t.target.x(),y:t.target.y(),rotation:t.target.rotation()})},onTransformEnd:()=>{a.set(x(a))}})),t(n,{x:P.x,y:P.y,rotation:a.rotation,hideInExport:!a.showInExport,onClick:t=>{var e;return null===(e=M.current)||void 0===e?void 0:e.fire("click",t)},onTap:t=>{var e;return null===(e=M.current)||void 0===e?void 0:e.fire("tap",t)},children:t(w,{element:a,type:a.startHead})}),t(n,{x:I.x,y:I.y,rotation:a.rotation+180,onClick:t=>{var e;return null===(e=M.current)||void 0===e?void 0:e.fire("click",t)},onTap:t=>{var e;return null===(e=M.current)||void 0===e?void 0:e.fire("tap",t)},children:t(w,{element:a,type:a.endHead})}),E&&a.resizable&&t(g,{selector:".page-abs-container",enabled:!0,children:e(n,{visible:E,children:[t(s,Object.assign({x:P.x,y:P.y,ref:b,name:"line-anchor"},y(l.scale,l,c),{onDragMove:t=>{const e=getLinePositionFromMiddlePoints(t.target.position(),I,a.height);a.set({x:e.x,y:e.y,width:e.width,rotation:e.rotation})}})),t(s,Object.assign({x:I.x,y:I.y,ref:v,name:"line-anchor"},y(l.scale,l,c),{onDragMove:t=>{const e=getLinePositionFromMiddlePoints(P,t.target.position(),a.height);a.set({x:e.x,y:e.y,width:e.width,rotation:e.rotation})}}))]})})]})});
|
package/canvas/page-controls.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as e,jsxs as o}from"react/jsx-runtime";import{observer as i}from"mobx-react-lite";import t from"konva";import{PolotnoIcon as l}from"../icons/registry.js";import{ROLES as a}from"../model/store.js";import{t as
|
|
1
|
+
import{jsx as e,jsxs as o}from"react/jsx-runtime";import{observer as i}from"mobx-react-lite";import t from"konva";import{PolotnoIcon as l}from"../icons/registry.js";import{ROLES as a}from"../model/store.js";import{t as d}from"../utils/l10n.js";import{TooltipIconButton as n}from"../primitives/tooltip-icon-button.js";import{useWorkspaceStyle as r}from"./workspace-style.js";export const PageControls=i(({store:i,page:s,xPadding:c,yPadding:p,layout:g="vertical"})=>{const v=i.pages.length>1,m=i.pages.indexOf(s),h="horizontal"===g,u=h?"ui.chevronLeft":"ui.chevronUp",b=h?"ui.chevronRight":"ui.chevronDown",k=d(h?"workspace.moveLeft":"workspace.moveUp"),f=d(h?"workspace.moveRight":"workspace.moveDown"),{workspaceBackgroundColor:P}=r(),x=(e=>{const o=t.Util.colorToRGBA(e);return(o?.299*o.r+.587*o.g+.114*o.b:232)>150?"rgba(0, 0, 0, 0.6)":"rgba(255, 255, 255, 0.85)"})(P);return"selection"!==i.tool||i.role===a.VIEWER?null:o("div",{className:"polotno-page-controls",style:{position:"absolute",top:p-40+"px",right:c+"px",color:x},children:[v&&e(n,{side:"top",label:k,disabled:0===m,onClick:()=>{s.setZIndex(m-1)},children:e(l,{name:u})}),v&&e(n,{side:"top",label:f,disabled:m===i.pages.length-1,onClick:()=>{const e=i.pages.indexOf(s);s.setZIndex(e+1)},children:e(l,{name:b})}),e(n,{side:"top",label:d("workspace.duplicatePage"),onClick:()=>{s.clone()},children:e(l,{name:"action.duplicate"})}),v&&e(n,{side:"top",label:d("workspace.removePage"),onClick:()=>{i.deletePages([s.id])},children:e(l,{name:"action.remove"})}),e(n,{side:"top",label:d("workspace.addPage"),onClick:()=>{var e,o,t,l,a,d,n;const r=i.addPage({bleed:(null===(e=i.activePage)||void 0===e?void 0:e.bleed)||0,bleedTop:null===(o=i.activePage)||void 0===o?void 0:o.bleedTop,bleedRight:null===(t=i.activePage)||void 0===t?void 0:t.bleedRight,bleedBottom:null===(l=i.activePage)||void 0===l?void 0:l.bleedBottom,bleedLeft:null===(a=i.activePage)||void 0===a?void 0:a.bleedLeft,width:(null===(d=i.activePage)||void 0===d?void 0:d.width)||"auto",height:(null===(n=i.activePage)||void 0===n?void 0:n.height)||"auto"}),c=i.pages.indexOf(s);r.setZIndex(c+1)},children:e(l,{name:"action.add"})})]})});
|
package/canvas/page.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var e=this&&this.__rest||function(e,t){var n={};for(var i in e){Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i])}if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(i=Object.getOwnPropertySymbols(e);o<i.length;o++){t.indexOf(i[o])<0&&Object.prototype.propertyIsEnumerable.call(e,i[o])&&(n[i[o]]=e[i[o]])}}return n};import{jsx as t,jsxs as n,Fragment as i}from"react/jsx-runtime";import o from"react";import{observer as r,useLocalObservable as l}from"mobx-react-lite";import{action as s,runInAction as a}from"mobx";import{ZERO_BLEED as d}from"@polotno/schema";import{Group as c,Image as h,Label as m,Layer as u,Line as g,Rect as f,Shape as p,Stage as x,Tag as v,Text as b,Transformer as y,KonvaRenderer as w}from"react-konva";import E from"use-image";import{useWorkspaceStyle as X}from"./workspace-style.js";import{ROLES as Y}from"../model/store.js";import S from"konva";import k from"./element.js";import{DrawingLayer as A}from"./drawing-layer.js";import{ensureDragOrder as M,useSnap as I}from"./use-transformer-snap.js";import{useImageLoader as O}from"./image-element.js";import{getCrop as P}from"../utils/crop.js";import{___ as R,____ as j,isCreditVisible as D}from"../utils/validate-key.js";import{getClientRect as C,getCorners as T,getTotalClientRect as B,polygonsIntersect as W}from"../utils/math.js";import{pxToUnitRounded as G,pxToUnitString as L}from"../utils/unit.js";import{isCornerAnchor as V,textMinResizeWidth as F,textMinWidthIsMeasured as z}from"../utils/px.js";import{flags as U}from"../utils/flags.js";import{useColor as Z}from"./use-color.js";import{isGradient as _}from"@polotno/core/gradient";import{Html as H}from"react-konva-utils";import{observerBatching as J}from"mobx-react-lite";const N=e=>w.batchedUpdates(e,null);J(e=>{w.isAlreadyRendering()?queueMicrotask(()=>N(e)):N(e)});const K=S.DD._drag;window.removeEventListener("mousemove",K),S.DD._drag=function(e){a(()=>{K.call(this,e)})},window.addEventListener("mousemove",S.DD._drag);const $={enabledAnchors:["top-left","top-center","top-right","middle-left","bottom-left","bottom-right","bottom-center","middle-right"],rotateEnabled:!0,rotationSnaps:[0,45,90,135,180,225,270,315],ignoreStroke:!0,flipEnabled:!1,keepRatio:!0},Q=e=>{const t=(e%180+180)%180;return t<.1||180-t<.1},q=e=>{if(!e.length){return null}const t=Q(e[0].rotation)?0:e[0].rotation;return e.every(e=>Q(e.rotation-t))?t:null},ee=e=>e.selectedShapes.filter(e=>!e._cropModeEnabled),te=(e,t,n)=>{const i=e.width!==t.width,o=e.height!==t.height;if(!i&&!o){return e}const r=Math.cos(t.rotation),l=Math.sin(t.rotation),s=t.x-n.x,a=t.y-n.y,d=i?0:s*r+a*l,c=o?0:-s*l+a*r;return e.x=n.x+d*r-c*l,e.y=n.y+d*l+c*r,e},ne={text:{enabledAnchors:["top-left","top-right","middle-left","bottom-left","bottom-right","middle-right"]},svg:{enabledAnchors:["top-left","top-right","bottom-left","bottom-right"]},gif:{enabledAnchors:["top-left","top-right","bottom-left","bottom-right"]},line:{enabledAnchors:[],borderEnabled:!1,rotateEnabled:!1},image:{enabledAnchors:["top-left","top-right","bottom-left","bottom-right"]},many:{enabledAnchors:["top-left","top-right","bottom-left","bottom-right"]},group:{enabledAnchors:["top-left","top-right","bottom-left","bottom-right"]},table:{keepRatio:!1,enabledAnchors:["top-left","top-center","top-right","middle-left","middle-right","bottom-left","bottom-center","bottom-right"]}};export function registerTransformerAttrs(e,t){ne[e]=ne[e]||t,Object.assign(ne[e],t)}const ie=e=>t(f,Object.assign({},e,{preventDefault:!1})),oe=n=>{var{url:i}=n,o=e(n,["url"]);const[r,l]=E(i,"anonymous"),s=r?P(r,{width:o.width,height:o.height},"center-middle"):{};return O(l,i,"page background"),t(h,Object.assign({image:r},o,s))},re=e=>{const n=Z({a:{width:e.width,height:e.height},width:e.width,height:e.height},e.fill);return t(f,Object.assign({},e,n))},le=i=>{const{background:r,scale:l,borderColor:s,transparencyBackgroundColor:a}=i,d=e(i,["background","scale","borderColor","transparencyBackgroundColor"]),c=o.useMemo(()=>!!S.Util.colorToRGBA(r)||_(r),[r]),h=o.useMemo(()=>{if(_(r)){return!0}const e=S.Util.colorToRGBA(r);return!e||e.a<1},[r]),m=o.useMemo(()=>{if(!h||a){return null}const e=document.createElement("canvas"),t=30;e.width=60,e.height=60;const n=e.getContext("2d");return n&&(n.fillStyle="black",n.fillRect(t,0,t,t),n.fillRect(0,t,t,t)),e},[h,a]);return n(o.Fragment,{children:[h&&t(f,a?Object.assign({fill:a},d,{hideInExport:!0}):Object.assign({fillPatternImage:m},d,{opacity:.1,hideInExport:!0})),c?t(re,Object.assign({fill:r},d)):t(oe,Object.assign({url:r},d))]})},se=r(({selection:e})=>{const{selectionRectStyle:n}=X();return e.visible?t(f,{name:"selection",x:Math.min(e.x1,e.x2),y:Math.min(e.y1,e.y2),width:Math.abs(e.x1-e.x2),height:Math.abs(e.y1-e.y2),fill:n.fill,stroke:n.stroke,strokeWidth:n.strokeWidth}):null});function ae(e){let t=180*e/Math.PI;return t%=360,t>180?t-=360:t<-180&&(t+=360),Math.round(t)}const de=r(({x:e,y:o,width:r,height:l,rotation:s,anchor:a,store:d})=>{const{transformLabelStyle:c}=X();if(void 0===e||void 0===o||void 0===r||void 0===l||void 0===s||void 0===a){return null}const h=C({x:e,y:o,width:r,height:l,rotation:S.Util.radToDeg(s)}),u=(l/2+70)*Math.cos(s-Math.PI/2),g=(l/2+70)*Math.sin(s-Math.PI/2),f=G({unit:d.unit,dpi:d.dpi,px:r/d.scale,precious:"px"===d.unit?0:1})+" x "+G({unit:d.unit,dpi:d.dpi,px:l/d.scale,precious:"px"===d.unit?0:1})+("px"===d.unit?"":" "+d.unit);return n(i,{children:[n(m,{x:(h.minX+h.maxX)/2+u,y:(h.minY+h.maxY)/2+g,offsetX:14,offsetY:14,visible:"rotater"===a,children:[t(v,{cornerRadius:5,fill:c.fill}),t(b,{align:"center",verticalAlign:"middle",fill:c.textFill,padding:8,text:ae(s).toString()+"°"})]}),n(m,{x:(h.minX+h.maxX)/2,y:h.maxY+20,visible:"rotater"!==a,children:[t(v,{cornerRadius:5,fill:c.fill,pointerDirection:"up",pointerHeight:0,pointerWidth:0}),t(b,{align:"center",verticalAlign:"middle",fill:c.textFill,padding:8,text:f})]})]})}),ce=r(({elements:e,store:n})=>{const i=e.filter(e=>e.alwaysOnTop),r=e.filter(e=>!e.alwaysOnTop).concat(i);return t(o.Fragment,{children:r.map(e=>t(k,{store:n,element:e,onClick:()=>{console.warn("Polotno warning: onClick callback is deprecated. Just stop using it. Polotno will do selection automatically.")}},e.id))})});export const useContextMenu=({store:e})=>{const[t,n]=o.useState(!1),[i,r]=o.useState({x:0,y:0}),l=o.useCallback(e=>{n(!0),r(e)},[]);return{open:l,close:o.useCallback(()=>{n(!1)},[]),props:{isOpen:t,offset:i,setIsOpen:n}}};let he=null;export const registerNextDomDrop=e=>{he=e};const me=atob("UG9sb3RubyBmcmVlIGxpY2Vuc2UgbGltaXRhdGlvbiBleGNlZWRlZCAtIFBsZWFzZSB1cGdyYWRlIHlvdXIgYWNjb3VudC4="),ue=atob("I2MwMzkyYg=="),ge=atob("djAuOS4y"),fe=e=>t(i,{children:n(m,{fill:ue,height:200,children:[t(v,{fill:ue}),t(b,Object.assign({},e,{fill:"white",text:me,height:void 0,padding:10,fontSize:20}))]})}),pe=atob("RlJFRSAgVFJJQUwgIExJQ0VOU0U="),xe=(atob("UG93ZXJlZCBieSBQb2xvdG5v"),atob("TElDRU5TRSAgS0VZICBJUyAgTUlTU0lORw==")),ve=atob("UGxlYXNlIGFjdGl2YXRlIHlvdXIgbGljZW5zZS4KTGljZW5zZSByZWxhdGVkIHF1ZXN0aW9uczoKcG9sb3Ruby5jb20vY29udGFjdA=="),be=e=>{const i=1===j(),o=i?xe:pe,r=i?230:195;return n(c,Object.assign({},e,{listening:!1,children:[t(f,{fill:ue,width:r,height:24,cornerRadius:2}),t(b,{text:o,fill:"white",fontSize:13,fontFamily:"monospace",width:r,align:"center",y:5,listening:!1}),i&&t(b,{text:ve,fill:"rgba(0,0,0,0.6)",fontSize:14,y:30,listening:!1})]}))};export default r(({store:e,page:i,width:r,height:a,pageControlsEnabled:h,components:w,altCloneEnabled:E,groupSelectionMode:S="drill",viewportSize:k,layout:O="vertical",tooltipSafeArea:P,transformerSafeArea:G})=>{var Z,_;const J=X(),N=J.transformerStyle,K=$,oe=i.computedBleed,re=e.bleedVisible?oe:d,ae=i.computedWidth+re.left+re.right,me=i.computedHeight+re.top+re.bottom,ue=(r-ae*e.scale)/2,pe=(a-me*e.scale)/2,xe=o.useRef(null),ve=o.useRef(null),ye=o.useRef(null),we=o.useRef(null),Ee=null==h||h,Xe=o.useRef(!1),[Ye,Se]=o.useState(null),[ke,Ae]=o.useState({}),[Me,Ie]=o.useState(0),Oe=useContextMenu({store:e}),Pe=e.selectedElements.find(e=>e._cropModeEnabled),Re=e.selectedElements.find(e=>e.curveEnabled),je=e.selectedShapes.filter(e=>!e.resizable).length>0,De=e.selectedShapes.filter(e=>!e.draggable).length>0,Ce=e.selectedElements.filter(e=>!e.visible).length>0,Te=ee(e),Be=1!==e.selectedElements.length||"group"===(null===(Z=e.selectedElements[0])||void 0===Z?void 0:Z.type),We=null!==(_=q(Te))&&void 0!==_?_:0,Ge=e=>Be&&Te.length>0&&Te.every(t=>((e,t,n)=>{if(!Q(e.rotation-n)){return!1}switch(e.type){case"text":return"x"===t&&!z(e);case"figure":case"video":case"table":return!0;case"image":case"svg":case"gif":return!e.keepRatio;default:return!1}})(t,e,We)),Le=Ge("x"),Ve=Ge("y"),Fe=()=>{var t,n,i;const o=xe.current;if(!o){return[]}const r=o.getStage();if(!r){return[]}const l=ee(e),s=l.map(e=>r.findOne("#"+e.id)).filter(e=>!!e),a=1===e.selectedElements.length,d=a&&(null===(t=e.selectedElements[0])||void 0===t?void 0:t.type)||"many",c=ne[d],h=Object.assign(Object.assign({},K),c||{});c&&("svg"!==d&&"image"!==d&&"gif"!==d||e.selectedElements[0].keepRatio||(h.enabledAnchors=K.enabledAnchors),"text"===d&&U.textVerticalResizeEnabled&&(h.enabledAnchors=null===(n=ne.text.enabledAnchors)||void 0===n?void 0:n.concat(["bottom-center","top-center"])),"text"===d&&a&&e.selectedElements[0].curveEnabled&&(h.enabledAnchors=ne.many.enabledAnchors)),(Le||Ve)&&(h.enabledAnchors=[...h.enabledAnchors||[],...Le?["middle-left","middle-right"]:[],...Ve?["top-center","bottom-center"]:[]]),o.setAttrs(Object.assign(Object.assign({},h),N)),je&&o.enabledAnchors([]),De&&o.rotateEnabled(!1);const m=o.nodes();if(m.length===s.length&&s.every((e,t)=>m[t]===e)||o.nodes(s),Be&&s.length){const e=q(l);null===e||Q(o.rotation()-e)||(o.rotation(e),o.forceUpdate())}return null===(i=o.getLayer())||void 0===i||i.batchDraw(),s};o.useLayoutEffect(()=>{var e;if(null===(e=xe.current)||void 0===e?void 0:e.isTransforming()){return}const t=Fe();t.find(e=>null==e?void 0:e.isDragging())&&(t.forEach(e=>{e.isDragging()||null==e||e.startDrag()}),M())},[e.selectedShapes,Pe,je,Ce,De,Re,Le,Ve,We,N]);const ze=()=>{var e,t;const n=xe.current;if(!n){return}if(!n.isTransforming()){return void Ae({})}if(!n.nodes().length||!n.isTransforming()){return}const i=n.__getNodeRect(),o=null==n?void 0:n.getActiveAnchor(),r=n.getStage();Ae({anchor:o,x:i.x-(null!==(e=null==r?void 0:r.x())&&void 0!==e?e:0),y:i.y-(null!==(t=null==r?void 0:r.y())&&void 0!==t?t:0),rotation:i.rotation,width:i.width,height:i.height})},Ue=o.useCallback(()=>{var e;if(null===(e=xe.current)||void 0===e?void 0:e.isTransforming()){return}const t=xe.current;if(!t||!t.nodes().length){return void Ie(0)}const n=t.getClientRect();if(!t.getStage()){return}const i=function(e,t,n,i=0){const o=e.x+e.width/2,r=e.y+e.height/2,l=e.width/2,s=e.height/2,a=i*Math.PI/180,d=e=>{const t=e*Math.PI/180,i=(e%360+360)%360;let d;d=0===i||180===i?s:l;const c=Math.sin(t)*(d+n),h=-Math.cos(t)*(d+n),m=c*Math.cos(a)-h*Math.sin(a),u=c*Math.sin(a)+h*Math.cos(a);return{x:o+m,y:r+u}},c=e=>e.x>=t.left&&e.x<=t.right&&e.y>=t.top&&e.y<=t.bottom;if(c(d(0))){return 0}for(const h of[180,270,90]){if(c(d(h))){return h}}return 0}(n,{top:(null==G?void 0:G.top)||0,bottom:a-((null==G?void 0:G.bottom)||0),left:(null==G?void 0:G.left)||0,right:r-((null==G?void 0:G.right)||0)},N.rotateAnchorOffset,t.rotation());Ie(i)},[G,r,a]);o.useEffect(()=>{var e;null===(e=xe.current)||void 0===e||e.update(),ze(),Ue()},[e.scale,Ue]),o.useEffect(()=>{Ue()},[e.selectedShapes,Ue]);const Ze=l(()=>({visible:!1,x1:0,y1:0,x2:0,y2:0})),_e=o.useRef(!1),He=s(t=>{var n,i,o,r,l,s,a;if(e.role===Y.VIEWER){return}_e.current=!1;const d=t.target.findAncestor(".elements-container"),c=t.target.findAncestor("Transformer"),h=t.target.findAncestor(".page-abs-container");if(d||c||h){return}const m=null===(n=t.target.getStage())||void 0===n?void 0:n.getPointerPosition();m&&(m.x-=null!==(o=null===(i=t.target.getStage())||void 0===i?void 0:i.x())&&void 0!==o?o:0,m.y-=null!==(l=null===(r=t.target.getStage())||void 0===r?void 0:r.y())&&void 0!==l?l:0,Ze.visible=!0,Ze.x1=m.x,Ze.y1=m.y,Ze.x2=m.x,Ze.y2=m.y,(null!==(a=null===(s=t.target.getStage())||void 0===s?void 0:s.getPointersPositions().length)&&void 0!==a?a:0)>=2&&(Ze.visible=!1))});(({stageRef:e,containerRef:t,viewportSize:n})=>{o.useEffect(()=>{var n;const i=null===(n=t.current)||void 0===n?void 0:n.closest(".polotno-workspace-inner");function o(){var n;if(!e.current){return}const o=null===(n=t.current)||void 0===n?void 0:n.getBoundingClientRect(),r=null==i?void 0:i.getBoundingClientRect();if(!o||!r){return}const l=Math.max(0,r.left-o.left-100),s=Math.max(0,r.top-o.top-100);e.current.position({x:-l,y:-s}),e.current.container().style.transform=`translate(${l}px, ${s}px)`}return o(),null==i||i.addEventListener("scroll",o),()=>{null==i||i.removeEventListener("scroll",o)}},[n.width,n.height])})({stageRef:ye,containerRef:we,viewportSize:k}),o.useEffect(()=>{const t=s(e=>{var t,n,i,o,r,l;if(!Ze.visible){return}null===(t=ye.current)||void 0===t||t.setPointersPositions(e);let s=null===(n=ye.current)||void 0===n?void 0:n.getPointerPosition();s?(s.x-=null!==(o=null===(i=ye.current)||void 0===i?void 0:i.x())&&void 0!==o?o:0,s.y-=null!==(l=null===(r=ye.current)||void 0===r?void 0:r.y())&&void 0!==l?l:0):s={x:Ze.x2,y:Ze.y2},Ze.x2=s.x,Ze.y2=s.y}),n=s(()=>{if(!Ze.visible){return}if(!ye.current){return}const t=ye.current.findOne(".selection"),n=t?t.getClientRect({skipStroke:!0}):{width:0,height:0,x:0,y:0};if(n.width&&n.height){const t=[{x:n.x,y:n.y},{x:n.x+n.width,y:n.y},{x:n.x+n.width,y:n.y+n.height},{x:n.x,y:n.y+n.height}],i=[];ye.current.find(".element").forEach(n=>{var o;const r=e.getElementById(n.id()),l=null==r?void 0:r.draggable,s=null==r?void 0:r.selectable;if(!l||!s){return}const a=null===(o=n.getParent())||void 0===o?void 0:o.getAbsoluteTransform();if(!a){return}const d=T(r.a).map(e=>a.point(e));W(t,d)&&i.push(r.top.id)});const o=[...new Set(i)];_e.current=!0,e.selectElements(o)}Ze.visible=!1});return window.addEventListener("mousemove",t),window.addEventListener("touchmove",t),window.addEventListener("mouseup",n,{capture:!0}),window.addEventListener("touchend",n,{capture:!0}),()=>{window.removeEventListener("mousemove",t),window.removeEventListener("touchmove",t),window.removeEventListener("mouseup",n),window.removeEventListener("touchend",n)}},[]);const Je=o.useCallback(t=>{if(!e.selectedElements[0]){return}if(t&&e.selectedElementsIds.includes(t)){return}const n=B(e.selectedShapes),o=t?e.getElementById(t):{x:0,y:0,width:i.computedWidth,height:i.computedHeight,rotation:0},r=C(o),l=[];n.minX>r.maxX&&l.push({distance:n.minX-r.maxX,box1:n,box2:r,points:[{x:n.minX,y:n.minY+n.height/2},{x:r.maxX,y:n.minY+n.height/2},{x:r.maxX,y:r.minY+r.height/2}]}),n.maxX<r.minX&&l.push({distance:r.minX-n.maxX,box1:n,box2:r,points:[{x:n.maxX,y:n.minY+n.height/2},{x:r.minX,y:n.minY+n.height/2},{x:r.minX,y:r.minY+r.height/2}]}),n.minY>r.maxY&&l.push({box1:n,box2:r,distance:n.minY-r.maxY,points:[{x:n.minX+n.width/2,y:n.minY},{x:n.minX+n.width/2,y:r.maxY},{x:r.minX+r.width/2,y:r.maxY}]}),n.maxY<r.minY&&l.push({box1:n,box2:r,distance:r.minY-n.maxY,points:[{x:n.minX+n.width/2,y:n.maxY},{x:n.minX+n.width/2,y:r.minY},{x:r.minX+r.width/2,y:r.minY}]});const s=n.minX>=r.minX&&n.maxX<=r.maxX&&n.minY>=r.minY&&n.maxY<=r.maxY;if(s&&(l.push({distance:n.minX-r.minX,box1:n,box2:r,points:[{x:n.minX,y:n.minY+n.height/2},{x:r.minX,y:n.minY+n.height/2},{x:r.minX,y:r.minY+r.height/2}]}),l.push({distance:r.maxX-n.maxX,box1:n,box2:r,points:[{x:n.maxX,y:n.minY+n.height/2},{x:r.maxX,y:n.minY+n.height/2},{x:r.maxX,y:r.minY+r.height/2}]}),l.push({box1:n,box2:r,distance:n.minY-r.minY,points:[{x:n.minX+n.width/2,y:n.minY},{x:n.minX+n.width/2,y:r.minY},{x:r.minX+r.width/2,y:r.minY}]}),l.push({box1:n,box2:r,distance:r.maxY-n.maxY,points:[{x:n.minX+n.width/2,y:n.maxY},{x:n.minX+n.width/2,y:r.maxY},{x:r.minX+r.width/2,y:r.maxY}]})),0===l.length&&!s){const e=n.minX<r.maxX&&n.maxX>r.minX,t=n.minY<r.maxY&&n.maxY>r.minY;if(e&&t){const e=(Math.max(n.minY,r.minY)+Math.min(n.maxY,r.maxY))/2,t=(Math.max(n.minX,r.minX)+Math.min(n.maxX,r.maxX))/2;n.minX<r.minX?l.push({distance:r.minX-n.minX,box1:n,box2:r,points:[{x:n.minX,y:e},{x:r.minX,y:e},{x:r.minX,y:e}]}):l.push({distance:n.minX-r.minX,box1:n,box2:r,points:[{x:n.minX,y:e},{x:r.minX,y:e},{x:r.minX,y:e}]}),n.maxX>r.maxX?l.push({distance:n.maxX-r.maxX,box1:n,box2:r,points:[{x:r.maxX,y:e},{x:n.maxX,y:e},{x:r.maxX,y:e}]}):l.push({distance:r.maxX-n.maxX,box1:n,box2:r,points:[{x:n.maxX,y:e},{x:r.maxX,y:e},{x:r.maxX,y:e}]}),n.minY<r.minY?l.push({box1:n,box2:r,distance:r.minY-n.minY,points:[{x:t,y:n.minY},{x:t,y:r.minY},{x:t,y:r.minY}]}):l.push({box1:n,box2:r,distance:n.minY-r.minY,points:[{x:t,y:n.minY},{x:t,y:r.minY},{x:t,y:r.minY}]}),n.maxY>r.maxY?l.push({box1:n,box2:r,distance:n.maxY-r.maxY,points:[{x:t,y:r.maxY},{x:t,y:n.maxY},{x:t,y:r.maxY}]}):l.push({box1:n,box2:r,distance:r.maxY-n.maxY,points:[{x:t,y:n.maxY},{x:t,y:r.maxY},{x:t,y:r.maxY}]})}}JSON.stringify(Ye)!==JSON.stringify(l)&&Se(l)},[e,i]);o.useEffect(()=>{e.selectedElements[0]&&e.distanceGuidesVisible?Je():Ye&&Se(null)},[e.distanceGuidesVisible,Je,e.selectedShapes.map(e=>`${e.x},${e.y},${e.width},${e.height},${e.rotation}`).join("|")]);const Ne=o.useRef(!1);o.useEffect(()=>{var e;let t;const n=null===(e=we.current)||void 0===e?void 0:e.closest(".polotno-workspace-inner"),i=()=>{Ne.current=!0,clearTimeout(t),t=setTimeout(()=>{Ne.current=!1},300)};return null==n||n.addEventListener("scroll",i),()=>{clearTimeout(t),null==n||n.removeEventListener("scroll",i)}},[]),o.useEffect(()=>{const t=ye.current;if(!t){return}const n=t.container(),i=new Map,o=e=>{i.set(e.target,{x:e.target.x(),y:e.target.y()})},r=e=>{i.delete(e.target)};t.on("dragstart",o),t.on("dragend",r);const l=t=>{var n,o;t.touches.length>=2&&((null===(n=xe.current)||void 0===n?void 0:n.isDragging())&&xe.current.stopDrag(),null===(o=xe.current)||void 0===o||o.nodes().forEach(t=>{var n;const o=i.get(t);t.isDragging()&&t.stopDrag(),o&&(t.setAttrs(o),null===(n=e.getElementById(t.id()))||void 0===n||n.set({x:o.x,y:o.y}))}))};return n.addEventListener("touchstart",l,{passive:!0}),n.addEventListener("touchmove",l,{passive:!0}),()=>{t.off("dragstart",o),t.off("dragend",r),n.removeEventListener("touchstart",l),n.removeEventListener("touchmove",l)}},[e]);const Ke=t=>{if(e.role===Y.VIEWER){return}if(e.activePage!==i&&i.select(),Ne.current){return}if(_e.current){return}const n=t.evt.shiftKey,o=t.evt.ctrlKey||t.evt.metaKey,r=n||o,l=t.target.findAncestor(".elements-container"),s=t.target.findAncestor(".page-abs-container"),a=t.target.findAncestor("Transformer"),d=t.target.findAncestor(".page-container",!0);if(!(r||l||a||s||d||Ze.visible)){return e.selectElements([]),void e.selectPages([])}if(o&&!n){const t=ye.current,n=null==t?void 0:t.getPointerPosition();if(!t||!n){return}const i=t.getAllIntersections(n),o=new Set,r=[];for(const s of[...i].reverse()){const t=s.findAncestor(".element",!0);if(!t){continue}const n=e.getElementById(t.id()),i=null==n?void 0:n.top;i&&(o.has(i.id)||(o.add(i.id),r.push(i.id)))}if(0===r.length){return}let l;if(1===e.selectedElementsIds.length){const t=e.selectedElementsIds[0],n=r.indexOf(t);l=-1===n?r[0]:r[(n+1)%r.length]}else{l=r[0]}return e.selectElements([l]),void e.selectPages([])}const c=t.target.findAncestor(".element-container",!0),h=(null==c?void 0:c.findOne(".element"))||t.target.findAncestor(".element",!0),m=e.getElementById(null==h?void 0:h.id()),u=null==m?void 0:m.top;let g;if("group"===S){g=null==u?void 0:u.id}else if(u){const t=e.selectedElements.some(e=>{var t;return(null===(t=e.top)||void 0===t?void 0:t.id)===u.id});g=t?null==m?void 0:m.id:null==u?void 0:u.id}else{g=void 0}const f=null==m?void 0:m.id;if(f&&e.selectedElementsIds.indexOf(f)>=0&&!n){return}const p=!!g&&e.selectedElementsIds.indexOf(g)>=0,x=t.target.findAncestor(".page-container",!0);if(g&&n&&!p){const t=e.selectedElementsIds.concat([g]),n=new Set(t),i=t.filter(t=>{const i=e.getElementById(t);if(!i){return!1}for(let e=i.parent;e;e=null==e?void 0:e.parent){if(n.has(e.id)){return!1}}return!0});e.selectElements(i),e.selectPages([])}else{g&&n&&p?e.selectElements(e.selectedElementsIds.filter(e=>e!==g)):!g||n||p?g&&!n&&p||(x?(n||e.selectElements([]),e.selectPages([i.id])):e.selectPages([])):(e.selectElements([g]),e.selectPages([]))}};I(xe,e);const $e=e.activePage===i,Qe=e._selectedPagesIds.includes(i.id),qe=null==w?void 0:w.PageControls,et=null==w?void 0:w.Tooltip,tt=null==w?void 0:w.ContextMenu,nt=1/e.scale,it=0/e.scale;return n("div",{ref:we,onDragOver:e=>e.preventDefault(),onDrop:t=>{if(t.preventDefault(),e.role===Y.VIEWER){return}if(!ye.current){return}ye.current.setPointersPositions(t);const n=ye.current.findOne(".elements-container"),o=null==n?void 0:n.getRelativePointerPosition(),r=ye.current.getPointerPosition(),l=ye.current.getAllIntersections(r).map(e=>e.findAncestor(".element",!0)).filter(Boolean),s=[...new Set(l.reverse())].map(t=>e.getElementById(t.id())).filter(e=>!!e),a=s[0];he&&o&&(he(o,a,{elements:s,page:i}),he=null)},style:{position:"relative",width:r+"px",height:a+"px",overflow:"hidden",flexShrink:0},className:"polotno-page-container"+($e?" active-page":""),children:[t(x,{ref:ye,width:Math.min(r,k.width+200),height:Math.min(k.height+200,a),onClick:Ke,onTap:Ke,onContextMenu:t=>{if(t.evt.preventDefault(),e.role===Y.VIEWER){return}const n=t.target.findAncestor(".element",!0),i=e.getElementById(null==n?void 0:n.id()),o=null==i?void 0:i.top,r=null==o?void 0:o.id;if(!r){return e.selectElements([]),void Oe.close()}e.selectedElementsIds.indexOf(r)>=0||e.selectElements([r]),Oe.open({x:t.evt.clientX,y:t.evt.clientY})},onMouseDown:He,onMouseMove:t=>{if(!e.distanceGuidesVisible&&!t.evt.altKey){return void(Ye&&Se(null))}const n=t.target.findAncestor(".element",!0),i=null==n?void 0:n.id();Je(i)},onDragStart:t=>{var n;const i=t.target.getStage();if(i&&i.getPointersPositions().length>=2){return void t.target.stopDrag()}const o=t.target.findAncestor(".element",!0);if(o){const i=e.getElementById(null==o?void 0:o.id()),r=null==i?void 0:i.top,l=null==r?void 0:r.id;if(!(i&&e.selectedElementsIds.indexOf(i.id)>=0||l&&e.selectedElementsIds.indexOf(l)>=0)&&l){e.selectElements([l]);const i=Fe();t.target.stopDrag(),i.forEach(e=>{e.isDragging()||e.startDrag(t)}),null===(n=xe.current)||void 0===n||n.startDrag(t),M()}}Ye&&Se(null)},pageId:i.id,style:{position:"absolute",overflow:"hidden",top:0,left:0},children:n(u,{children:[t(ie,{width:r,height:a,fill:J.workspaceBackgroundColor}),t(c,{x:ue,y:pe,scaleX:e.scale,scaleY:e.scale,name:"page-container",children:n(c,{name:"page-container-2",children:[t(c,{name:"page-background-group",x:re.left,y:re.top,children:t(le,{x:-oe.left,y:-oe.top,width:i.computedWidth+oe.left+oe.right,height:i.computedHeight+oe.top+oe.bottom,background:i.background,transparencyBackgroundColor:J.transparencyBackgroundColor,name:"page-background",preventDefault:!1,scale:e.scale})}),n(c,{x:re.left,y:re.top,name:"elements-container",listening:!e.isPlaying&&e.role!==Y.VIEWER,children:[t(f,{name:"elements-area",width:i.computedWidth,height:i.computedHeight,listening:!1}),t(ce,{elements:i.children,store:e})]}),t(p,{name:"bleed",fill:J.bleedColor,listening:!1,visible:e.bleedVisible&&(re.top>0||re.right>0||re.bottom>0||re.left>0),hideInExport:!0,sceneFunc:(e,t)=>{const{top:n,right:o,bottom:r,left:l}=oe,s=i.computedWidth,a=i.computedHeight,d=e._context;d.beginPath(),d.rect(0,0,l+s+o,n+a+r),d.rect(l,n,s,a),d.fillStyle=t.fill(),d.fill("evenodd")}}),R()===ge&&t(fe,{name:"hit-detection",x:-nt/2-it,y:-nt/2-it,width:ae+nt+2*it,height:me+nt+2*it})]})}),t(g,{name:"workspace-background",points:[0,0,r,0,r,a,0,a,0,0,ue,pe,ue,a-pe,r-ue,a-pe,r-ue,pe,ue,pe],listening:!1,closed:!0,fill:J.workspaceBackgroundColor}),t(c,{x:ue,y:pe,scaleX:e.scale,scaleY:e.scale,children:t(f,{name:"page-highlight",hideInExport:!0,x:-nt/2-it,y:-nt/2-it,width:ae+nt+2*it,height:me+nt+2*it,stroke:Qe?J.activePageBorderColor:J.pageBorderColor,strokeWidth:2,listening:!1,strokeScaleEnabled:!1})}),n(c,{x:ue+re.left*e.scale,y:pe+re.top*e.scale,scaleX:e.scale,scaleY:e.scale,name:"page-abs-container",children:[t(y,{ref:xe,rotateAnchorAngle:Me,onDragStart:t=>{var n;const o=t.target.getStage();o&&o.getPointersPositions().length>=2?t.target.stopDrag():((null===(n=t.evt)||void 0===n?void 0:n.altKey)&&E&&e.selectedElements.forEach(e=>{const t=e.clone({},{skipSelect:!0}),n=i.children.indexOf(e);i.setElementZIndex(t.id,n)}),Xe.current||(Xe.current=!0,e.history.startTransaction()))},onDragEnd:()=>{Xe.current&&(e.history.endTransaction(),Xe.current=!1),Ue()},onTransformStart:()=>{e.history.startTransaction(),ve.current=new Map(Te.map(e=>[e.id,{width:e.width,height:e.height}])),Se(null)},boundBoxFunc:(t,n)=>{var i,o;const r=Math.abs(n.width)<1||Math.abs(n.height)<1,l=Math.abs(t.width)<1||Math.abs(t.height)<1;if(r&&!l){return t}const s=e.selectedElements;if(1===s.length&&"table"===(null===(i=s[0])||void 0===i?void 0:i.type)){const e=s[0],i=Math.abs(t.width),o=Math.abs(t.height);if(i>0&&o>0){const r=Math.abs(n.width)/i,l=Math.abs(n.height)/o,s=e.width*r,a=e.height*l,d=Object.assign({},n);return s<e.minWidth&&(d.width=t.width),a<e.minHeight&&(d.height=t.height),te(d,n,t)}}return Be&&Te.length>0?((e,t,n,i,o)=>{const r=Math.abs(e.width),l=Math.abs(e.height);if(0===r||0===l){return t}const s=Math.abs(t.width)/r,a=Math.abs(t.height)/l,d=!V(n),c=e=>i.some(t=>{var n;const i=null==o?void 0:o.get(t.id),r=null!==(n="x"===e?null==i?void 0:i.width:null==i?void 0:i.height)&&void 0!==n?n:"x"===e?t.width:t.height,l="x"===e?t.width:t.height,c="x"===e?s:a,h=((e,t,n,i)=>{if("table"===e.type){const n=e;return"x"===t?n.minWidth:n.minHeight}return"text"===e.type&&"x"===t&&n?F(i,e.fontSize):1})(t,e,d,r);return r>=h&&l*c<h}),h=Object.assign({},t),m=t.width*e.width<0,u=t.height*e.height<0,g=m||c("x"),f=u||c("y"),p=f||!d&&g;return(g||!d&&f)&&(h.width=e.width),p&&(h.height=e.height),te(h,t,e)})(t,n,(null===(o=xe.current)||void 0===o?void 0:o.getActiveAnchor())||"",Te,ve.current):n},onTransform:e=>{const t=xe.current.nodes(),n=t[t.length-1];e.target===n&&setTimeout(()=>{ze()},0)},onTransformEnd:t=>{Ae({}),e.history.endTransaction(),ve.current=null,Ue(),Fe()},visible:!e.isPlaying}),Ye&&Ye.map(({points:i,distance:o,box1:r,box2:l},s)=>n(c,{name:"distances-container",hideInExport:!0,listening:!1,children:[t(f,Object.assign({},r,{stroke:J.distanceGuideStyle.stroke,strokeWidth:1,strokeScaleEnabled:!1})),t(f,Object.assign({},l,{stroke:J.distanceGuideStyle.stroke,strokeWidth:1,strokeScaleEnabled:!1})),t(g,{points:[i[0].x,i[0].y,i[1].x,i[1].y],stroke:J.distanceGuideStyle.stroke,strokeWidth:1,strokeScaleEnabled:!1}),t(g,{points:[i[1].x,i[1].y,i[2].x,i[2].y],stroke:J.distanceGuideStyle.stroke,strokeWidth:1,strokeScaleEnabled:!1}),n(m,{x:(i[0].x+i[1].x)/2,y:(i[0].y+i[1].y)/2,offsetY:-10,scaleX:1/e.scale,scaleY:1/e.scale,children:[t(v,{cornerRadius:5,fill:J.distanceGuideStyle.labelFill,pointerDirection:"down"}),t(b,{align:"center",verticalAlign:"middle",fill:J.distanceGuideStyle.labelTextFill,padding:5,text:L({unit:e.unit,dpi:e.dpi,px:o})})]})]},s)),i._rendering&&n(c,{children:[t(f,{width:ae,height:me,fill:"rgba(255,255,255,0.9)"}),t(b,{text:"Rendering...",fontSize:60,width:ae,height:me,align:"center",verticalAlign:"middle"})]}),et&&t(et,{components:w,store:e,page:i,stageRef:ye,tooltipSafeArea:P}),tt&&t(H,{children:t(tt,Object.assign({components:w,store:e},Oe.props))})]}),t(A,{store:e,page:i,width:r,height:a,scale:e.scale,xPadding:ue,yPadding:pe,bleedLeft:re.left,bleedTop:re.top}),t(de,Object.assign({},ke,{store:e})),t(se,{selection:Ze}),j()>0&&n(c,{hideInExport:!0,children:[t(be,{name:"cache-bounds",x:r-(1===j()?250:210),y:a-(1===j()?95:45)}),t(be,{name:"cache-bounds-t",x:10,y:10})]}),D()&&t(b,{text:"Powered by polotno.com",fontSize:14,fill:"rgba(0,0,0,0.6)",x:r-170,y:a-18,onMouseEnter:e=>{e.target.getStage().container().style.cursor="pointer"},onMouseLeave:e=>{e.target.getStage().container().style.cursor=""},onTouchStart:e=>{e.cancelBubble=!0},onMouseDown:e=>{e.cancelBubble=!0},onClick:()=>{window.open("https://polotno.com","_blank","noopener")},onTap:()=>{window.open("https://polotno.com","_blank","noopener")}}),t(c,{name:"line-guides"})]})}),Ee&&qe&&t(qe,{store:e,page:i,xPadding:ue,yPadding:pe,layout:O})]})});
|
|
1
|
+
var e=this&&this.__rest||function(e,t){var n={};for(var i in e){Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i])}if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(i=Object.getOwnPropertySymbols(e);o<i.length;o++){t.indexOf(i[o])<0&&Object.prototype.propertyIsEnumerable.call(e,i[o])&&(n[i[o]]=e[i[o]])}}return n};import{jsx as t,jsxs as n,Fragment as i}from"react/jsx-runtime";import o from"react";import{observer as r,useLocalObservable as l}from"mobx-react-lite";import{action as s,runInAction as a}from"mobx";import{ZERO_BLEED as d}from"@polotno/schema";import{Group as c,Image as h,Label as m,Layer as u,Line as g,Rect as f,Shape as p,Stage as x,Tag as v,Text as b,Transformer as y,KonvaRenderer as w}from"react-konva";import E from"use-image";import{useWorkspaceStyle as X}from"./workspace-style.js";import{ROLES as Y}from"../model/store.js";import S from"konva";import k from"./element.js";import{DrawingLayer as A}from"./drawing-layer.js";import{ensureDragOrder as M,useSnap as I}from"./use-transformer-snap.js";import{useImageLoader as O}from"./image-element.js";import{getCrop as P}from"../utils/crop.js";import{___ as R,____ as j,isCreditVisible as D}from"../utils/validate-key.js";import{getClientRect as C,getCorners as T,getTotalClientRect as B,polygonsIntersect as W}from"../utils/math.js";import{pxToUnitRounded as G,pxToUnitString as L}from"../utils/unit.js";import{isCornerAnchor as V,textMinResizeWidth as F,textMinWidthIsMeasured as z}from"../utils/px.js";import{flags as U}from"../utils/flags.js";import{useColor as Z}from"./use-color.js";import{isGradient as _}from"@polotno/core/gradient";import{Html as H}from"react-konva-utils";import{observerBatching as J}from"mobx-react-lite";const N=e=>w.batchedUpdates(e,null);J(e=>{w.isAlreadyRendering()?queueMicrotask(()=>N(e)):N(e)});const K=S.DD._drag;window.removeEventListener("mousemove",K),S.DD._drag=function(e){a(()=>{K.call(this,e)})},window.addEventListener("mousemove",S.DD._drag);const $={enabledAnchors:["top-left","top-center","top-right","middle-left","bottom-left","bottom-right","bottom-center","middle-right"],rotateEnabled:!0,rotationSnaps:[0,45,90,135,180,225,270,315],ignoreStroke:!0,flipEnabled:!1,keepRatio:!0},Q=e=>{const t=(e%180+180)%180;return t<.1||180-t<.1},q=e=>{if(!e.length){return null}const t=Q(e[0].rotation)?0:e[0].rotation;return e.every(e=>Q(e.rotation-t))?t:null},ee=e=>e.selectedShapes.filter(e=>!e._cropModeEnabled),te=(e,t,n)=>{const i=e.width!==t.width,o=e.height!==t.height;if(!i&&!o){return e}const r=Math.cos(t.rotation),l=Math.sin(t.rotation),s=t.x-n.x,a=t.y-n.y,d=i?0:s*r+a*l,c=o?0:-s*l+a*r;return e.x=n.x+d*r-c*l,e.y=n.y+d*l+c*r,e},ne={text:{enabledAnchors:["top-left","top-right","middle-left","bottom-left","bottom-right","middle-right"]},svg:{enabledAnchors:["top-left","top-right","bottom-left","bottom-right"]},gif:{enabledAnchors:["top-left","top-right","bottom-left","bottom-right"]},line:{enabledAnchors:[],borderEnabled:!1,rotateEnabled:!1},image:{enabledAnchors:["top-left","top-right","bottom-left","bottom-right"]},many:{enabledAnchors:["top-left","top-right","bottom-left","bottom-right"]},group:{enabledAnchors:["top-left","top-right","bottom-left","bottom-right"]},table:{keepRatio:!1,enabledAnchors:["top-left","top-center","top-right","middle-left","middle-right","bottom-left","bottom-center","bottom-right"]}};export function registerTransformerAttrs(e,t){ne[e]=ne[e]||t,Object.assign(ne[e],t)}const ie=e=>t(f,Object.assign({},e,{preventDefault:!1})),oe=n=>{var{url:i}=n,o=e(n,["url"]);const[r,l]=E(i,"anonymous"),s=r?P(r,{width:o.width,height:o.height},"center-middle"):{};return O(l,i,"page background"),t(h,Object.assign({image:r},o,s))},re=e=>{const n=Z({a:{width:e.width,height:e.height},width:e.width,height:e.height},e.fill);return t(f,Object.assign({},e,n))},le=i=>{const{background:r,scale:l,borderColor:s,transparencyBackgroundColor:a}=i,d=e(i,["background","scale","borderColor","transparencyBackgroundColor"]),c=o.useMemo(()=>!!S.Util.colorToRGBA(r)||_(r),[r]),h=o.useMemo(()=>{if(_(r)){return!0}const e=S.Util.colorToRGBA(r);return!e||e.a<1},[r]),m=o.useMemo(()=>{if(!h||a){return null}const e=document.createElement("canvas"),t=30;e.width=60,e.height=60;const n=e.getContext("2d");return n&&(n.fillStyle="black",n.fillRect(t,0,t,t),n.fillRect(0,t,t,t)),e},[h,a]);return n(o.Fragment,{children:[h&&t(f,a?Object.assign({fill:a},d,{hideInExport:!0}):Object.assign({fillPatternImage:m},d,{opacity:.1,hideInExport:!0})),c?t(re,Object.assign({fill:r},d)):t(oe,Object.assign({url:r},d))]})},se=r(({selection:e})=>{const{selectionRectStyle:n}=X();return e.visible?t(f,{name:"selection",x:Math.min(e.x1,e.x2),y:Math.min(e.y1,e.y2),width:Math.abs(e.x1-e.x2),height:Math.abs(e.y1-e.y2),fill:n.fill,stroke:n.stroke,strokeWidth:n.strokeWidth}):null});function ae(e){let t=180*e/Math.PI;return t%=360,t>180?t-=360:t<-180&&(t+=360),Math.round(t)}const de=r(({x:e,y:o,width:r,height:l,rotation:s,anchor:a,store:d})=>{const{transformLabelStyle:c}=X();if(void 0===e||void 0===o||void 0===r||void 0===l||void 0===s||void 0===a){return null}const h=C({x:e,y:o,width:r,height:l,rotation:S.Util.radToDeg(s)}),u=(l/2+70)*Math.cos(s-Math.PI/2),g=(l/2+70)*Math.sin(s-Math.PI/2),f=G({unit:d.unit,dpi:d.dpi,px:r/d.scale,precious:"px"===d.unit?0:1})+" x "+G({unit:d.unit,dpi:d.dpi,px:l/d.scale,precious:"px"===d.unit?0:1})+("px"===d.unit?"":" "+d.unit);return n(i,{children:[n(m,{x:(h.minX+h.maxX)/2+u,y:(h.minY+h.maxY)/2+g,offsetX:14,offsetY:14,visible:"rotater"===a,children:[t(v,{cornerRadius:5,fill:c.fill}),t(b,{align:"center",verticalAlign:"middle",fill:c.textFill,padding:8,text:ae(s).toString()+"°"})]}),n(m,{x:(h.minX+h.maxX)/2,y:h.maxY+20,visible:"rotater"!==a,children:[t(v,{cornerRadius:5,fill:c.fill,pointerDirection:"up",pointerHeight:0,pointerWidth:0}),t(b,{align:"center",verticalAlign:"middle",fill:c.textFill,padding:8,text:f})]})]})}),ce=r(({elements:e,store:n})=>{const i=e.filter(e=>e.alwaysOnTop),r=e.filter(e=>!e.alwaysOnTop).concat(i);return t(o.Fragment,{children:r.map(e=>t(k,{store:n,element:e,onClick:()=>{console.warn("Polotno warning: onClick callback is deprecated. Just stop using it. Polotno will do selection automatically.")}},e.id))})});export const useContextMenu=({store:e})=>{const[t,n]=o.useState(!1),[i,r]=o.useState({x:0,y:0}),l=o.useCallback(e=>{n(!0),r(e)},[]);return{open:l,close:o.useCallback(()=>{n(!1)},[]),props:{isOpen:t,offset:i,setIsOpen:n}}};let he=null;export const registerNextDomDrop=e=>{he=e};const me=atob("UG9sb3RubyBmcmVlIGxpY2Vuc2UgbGltaXRhdGlvbiBleGNlZWRlZCAtIFBsZWFzZSB1cGdyYWRlIHlvdXIgYWNjb3VudC4="),ue=atob("I2MwMzkyYg=="),ge=atob("djAuOS4y"),fe=e=>t(i,{children:n(m,{fill:ue,height:200,children:[t(v,{fill:ue}),t(b,Object.assign({},e,{fill:"white",text:me,height:void 0,padding:10,fontSize:20}))]})}),pe=atob("RlJFRSAgVFJJQUwgIExJQ0VOU0U="),xe=(atob("UG93ZXJlZCBieSBQb2xvdG5v"),atob("TElDRU5TRSAgS0VZICBJUyAgTUlTU0lORw==")),ve=atob("UGxlYXNlIGFjdGl2YXRlIHlvdXIgbGljZW5zZS4KTGljZW5zZSByZWxhdGVkIHF1ZXN0aW9uczoKcG9sb3Ruby5jb20vY29udGFjdA=="),be=e=>{const i=1===j(),o=i?xe:pe,r=i?230:195;return n(c,Object.assign({},e,{listening:!1,children:[t(f,{fill:ue,width:r,height:24,cornerRadius:2}),t(b,{text:o,fill:"white",fontSize:13,fontFamily:"monospace",width:r,align:"center",y:5,listening:!1}),i&&t(b,{text:ve,fill:"rgba(0,0,0,0.6)",fontSize:14,y:30,listening:!1})]}))};export default r(({store:e,page:i,width:r,height:a,pageControlsEnabled:h,components:w,altCloneEnabled:E,groupSelectionMode:S="drill",viewportSize:k,layout:O="vertical",tooltipSafeArea:P,transformerSafeArea:G})=>{var Z,_;const J=X(),N=J.transformerStyle,K=$,oe=i.computedBleed,re=e.bleedVisible?oe:d,ae=i.computedWidth+re.left+re.right,me=i.computedHeight+re.top+re.bottom,ue=(r-ae*e.scale)/2,pe=(a-me*e.scale)/2,xe=o.useRef(null),ve=o.useRef(null),ye=o.useRef(null),we=o.useRef(null),Ee=null==h||h,Xe=o.useRef(!1),[Ye,Se]=o.useState(null),[ke,Ae]=o.useState({}),[Me,Ie]=o.useState(0),Oe=useContextMenu({store:e}),Pe=e.selectedElements.find(e=>e._cropModeEnabled),Re=e.selectedElements.find(e=>e.curveEnabled),je=e.selectedShapes.filter(e=>!e.resizable).length>0,De=e.selectedShapes.filter(e=>!e.draggable).length>0,Ce=e.selectedElements.filter(e=>!e.visible).length>0,Te=ee(e),Be=1!==e.selectedElements.length||"group"===(null===(Z=e.selectedElements[0])||void 0===Z?void 0:Z.type),We=null!==(_=q(Te))&&void 0!==_?_:0,Ge=e=>Be&&Te.length>0&&Te.every(t=>((e,t,n)=>{if(!Q(e.rotation-n)){return!1}switch(e.type){case"text":return"x"===t&&!z(e);case"figure":case"video":case"table":return!0;case"image":case"svg":case"gif":return!e.keepRatio;default:return!1}})(t,e,We)),Le=!Be&&e.selectedElements[0].keepRatio,Ve=Ge("x"),Fe=Ge("y"),ze=()=>{var t,n,i;const o=xe.current;if(!o){return[]}const r=o.getStage();if(!r){return[]}const l=ee(e),s=l.map(e=>r.findOne("#"+e.id)).filter(e=>!!e),a=1===e.selectedElements.length,d=a&&(null===(t=e.selectedElements[0])||void 0===t?void 0:t.type)||"many",c=ne[d],h=Object.assign(Object.assign({},K),c||{});c&&("svg"!==d&&"image"!==d&&"gif"!==d||e.selectedElements[0].keepRatio||(h.enabledAnchors=K.enabledAnchors),"text"===d&&U.textVerticalResizeEnabled&&(h.enabledAnchors=null===(n=ne.text.enabledAnchors)||void 0===n?void 0:n.concat(["bottom-center","top-center"])),"text"===d&&a&&e.selectedElements[0].curveEnabled&&(h.enabledAnchors=ne.many.enabledAnchors)),(Ve||Fe)&&(h.enabledAnchors=[...h.enabledAnchors||[],...Ve?["middle-left","middle-right"]:[],...Fe?["top-center","bottom-center"]:[]]),o.setAttrs(Object.assign(Object.assign({},h),N)),je&&o.enabledAnchors([]),De&&o.rotateEnabled(!1);const m=o.nodes();if(m.length===s.length&&s.every((e,t)=>m[t]===e)||o.nodes(s),Be&&s.length){const e=q(l);null===e||Q(o.rotation()-e)||(o.rotation(e),o.forceUpdate())}return null===(i=o.getLayer())||void 0===i||i.batchDraw(),s};o.useLayoutEffect(()=>{var e;if(null===(e=xe.current)||void 0===e?void 0:e.isTransforming()){return}const t=ze();t.find(e=>null==e?void 0:e.isDragging())&&(t.forEach(e=>{e.isDragging()||null==e||e.startDrag()}),M())},[e.selectedShapes,Pe,je,Ce,De,Re,Ve,Fe,Le,We,N]);const Ue=()=>{var e,t;const n=xe.current;if(!n){return}if(!n.isTransforming()){return void Ae({})}if(!n.nodes().length||!n.isTransforming()){return}const i=n.__getNodeRect(),o=null==n?void 0:n.getActiveAnchor(),r=n.getStage();Ae({anchor:o,x:i.x-(null!==(e=null==r?void 0:r.x())&&void 0!==e?e:0),y:i.y-(null!==(t=null==r?void 0:r.y())&&void 0!==t?t:0),rotation:i.rotation,width:i.width,height:i.height})},Ze=o.useCallback(()=>{var e;if(null===(e=xe.current)||void 0===e?void 0:e.isTransforming()){return}const t=xe.current;if(!t||!t.nodes().length){return void Ie(0)}const n=t.getClientRect();if(!t.getStage()){return}const i=function(e,t,n,i=0){const o=e.x+e.width/2,r=e.y+e.height/2,l=e.width/2,s=e.height/2,a=i*Math.PI/180,d=e=>{const t=e*Math.PI/180,i=(e%360+360)%360;let d;d=0===i||180===i?s:l;const c=Math.sin(t)*(d+n),h=-Math.cos(t)*(d+n),m=c*Math.cos(a)-h*Math.sin(a),u=c*Math.sin(a)+h*Math.cos(a);return{x:o+m,y:r+u}},c=e=>e.x>=t.left&&e.x<=t.right&&e.y>=t.top&&e.y<=t.bottom;if(c(d(0))){return 0}for(const h of[180,270,90]){if(c(d(h))){return h}}return 0}(n,{top:(null==G?void 0:G.top)||0,bottom:a-((null==G?void 0:G.bottom)||0),left:(null==G?void 0:G.left)||0,right:r-((null==G?void 0:G.right)||0)},N.rotateAnchorOffset,t.rotation());Ie(i)},[G,r,a]);o.useEffect(()=>{var e;null===(e=xe.current)||void 0===e||e.update(),Ue(),Ze()},[e.scale,Ze]),o.useEffect(()=>{Ze()},[e.selectedShapes,Ze]);const _e=l(()=>({visible:!1,x1:0,y1:0,x2:0,y2:0})),He=o.useRef(!1),Je=s(t=>{var n,i,o,r,l,s,a;if(e.role===Y.VIEWER){return}He.current=!1;const d=t.target.findAncestor(".elements-container"),c=t.target.findAncestor("Transformer"),h=t.target.findAncestor(".page-abs-container");if(d||c||h){return}const m=null===(n=t.target.getStage())||void 0===n?void 0:n.getPointerPosition();m&&(m.x-=null!==(o=null===(i=t.target.getStage())||void 0===i?void 0:i.x())&&void 0!==o?o:0,m.y-=null!==(l=null===(r=t.target.getStage())||void 0===r?void 0:r.y())&&void 0!==l?l:0,_e.visible=!0,_e.x1=m.x,_e.y1=m.y,_e.x2=m.x,_e.y2=m.y,(null!==(a=null===(s=t.target.getStage())||void 0===s?void 0:s.getPointersPositions().length)&&void 0!==a?a:0)>=2&&(_e.visible=!1))});(({stageRef:e,containerRef:t,viewportSize:n})=>{o.useEffect(()=>{var n;const i=null===(n=t.current)||void 0===n?void 0:n.closest(".polotno-workspace-inner");function o(){var n;if(!e.current){return}const o=null===(n=t.current)||void 0===n?void 0:n.getBoundingClientRect(),r=null==i?void 0:i.getBoundingClientRect();if(!o||!r){return}const l=Math.max(0,r.left-o.left-100),s=Math.max(0,r.top-o.top-100);e.current.position({x:-l,y:-s}),e.current.container().style.transform=`translate(${l}px, ${s}px)`}return o(),null==i||i.addEventListener("scroll",o),()=>{null==i||i.removeEventListener("scroll",o)}},[n.width,n.height])})({stageRef:ye,containerRef:we,viewportSize:k}),o.useEffect(()=>{const t=s(e=>{var t,n,i,o,r,l;if(!_e.visible){return}null===(t=ye.current)||void 0===t||t.setPointersPositions(e);let s=null===(n=ye.current)||void 0===n?void 0:n.getPointerPosition();s?(s.x-=null!==(o=null===(i=ye.current)||void 0===i?void 0:i.x())&&void 0!==o?o:0,s.y-=null!==(l=null===(r=ye.current)||void 0===r?void 0:r.y())&&void 0!==l?l:0):s={x:_e.x2,y:_e.y2},_e.x2=s.x,_e.y2=s.y}),n=s(()=>{if(!_e.visible){return}if(!ye.current){return}const t=ye.current.findOne(".selection"),n=t?t.getClientRect({skipStroke:!0}):{width:0,height:0,x:0,y:0};if(n.width&&n.height){const t=[{x:n.x,y:n.y},{x:n.x+n.width,y:n.y},{x:n.x+n.width,y:n.y+n.height},{x:n.x,y:n.y+n.height}],i=[];ye.current.find(".element").forEach(n=>{var o;const r=e.getElementById(n.id()),l=null==r?void 0:r.draggable,s=null==r?void 0:r.selectable;if(!l||!s){return}const a=null===(o=n.getParent())||void 0===o?void 0:o.getAbsoluteTransform();if(!a){return}const d=T(r.a).map(e=>a.point(e));W(t,d)&&i.push(r.top.id)});const o=[...new Set(i)];He.current=!0,e.selectElements(o)}_e.visible=!1});return window.addEventListener("mousemove",t),window.addEventListener("touchmove",t),window.addEventListener("mouseup",n,{capture:!0}),window.addEventListener("touchend",n,{capture:!0}),()=>{window.removeEventListener("mousemove",t),window.removeEventListener("touchmove",t),window.removeEventListener("mouseup",n),window.removeEventListener("touchend",n)}},[]);const Ne=o.useCallback(t=>{if(!e.selectedElements[0]){return}if(t&&e.selectedElementsIds.includes(t)){return}const n=B(e.selectedShapes),o=t?e.getElementById(t):{x:0,y:0,width:i.computedWidth,height:i.computedHeight,rotation:0},r=C(o),l=[];n.minX>r.maxX&&l.push({distance:n.minX-r.maxX,box1:n,box2:r,points:[{x:n.minX,y:n.minY+n.height/2},{x:r.maxX,y:n.minY+n.height/2},{x:r.maxX,y:r.minY+r.height/2}]}),n.maxX<r.minX&&l.push({distance:r.minX-n.maxX,box1:n,box2:r,points:[{x:n.maxX,y:n.minY+n.height/2},{x:r.minX,y:n.minY+n.height/2},{x:r.minX,y:r.minY+r.height/2}]}),n.minY>r.maxY&&l.push({box1:n,box2:r,distance:n.minY-r.maxY,points:[{x:n.minX+n.width/2,y:n.minY},{x:n.minX+n.width/2,y:r.maxY},{x:r.minX+r.width/2,y:r.maxY}]}),n.maxY<r.minY&&l.push({box1:n,box2:r,distance:r.minY-n.maxY,points:[{x:n.minX+n.width/2,y:n.maxY},{x:n.minX+n.width/2,y:r.minY},{x:r.minX+r.width/2,y:r.minY}]});const s=n.minX>=r.minX&&n.maxX<=r.maxX&&n.minY>=r.minY&&n.maxY<=r.maxY;if(s&&(l.push({distance:n.minX-r.minX,box1:n,box2:r,points:[{x:n.minX,y:n.minY+n.height/2},{x:r.minX,y:n.minY+n.height/2},{x:r.minX,y:r.minY+r.height/2}]}),l.push({distance:r.maxX-n.maxX,box1:n,box2:r,points:[{x:n.maxX,y:n.minY+n.height/2},{x:r.maxX,y:n.minY+n.height/2},{x:r.maxX,y:r.minY+r.height/2}]}),l.push({box1:n,box2:r,distance:n.minY-r.minY,points:[{x:n.minX+n.width/2,y:n.minY},{x:n.minX+n.width/2,y:r.minY},{x:r.minX+r.width/2,y:r.minY}]}),l.push({box1:n,box2:r,distance:r.maxY-n.maxY,points:[{x:n.minX+n.width/2,y:n.maxY},{x:n.minX+n.width/2,y:r.maxY},{x:r.minX+r.width/2,y:r.maxY}]})),0===l.length&&!s){const e=n.minX<r.maxX&&n.maxX>r.minX,t=n.minY<r.maxY&&n.maxY>r.minY;if(e&&t){const e=(Math.max(n.minY,r.minY)+Math.min(n.maxY,r.maxY))/2,t=(Math.max(n.minX,r.minX)+Math.min(n.maxX,r.maxX))/2;n.minX<r.minX?l.push({distance:r.minX-n.minX,box1:n,box2:r,points:[{x:n.minX,y:e},{x:r.minX,y:e},{x:r.minX,y:e}]}):l.push({distance:n.minX-r.minX,box1:n,box2:r,points:[{x:n.minX,y:e},{x:r.minX,y:e},{x:r.minX,y:e}]}),n.maxX>r.maxX?l.push({distance:n.maxX-r.maxX,box1:n,box2:r,points:[{x:r.maxX,y:e},{x:n.maxX,y:e},{x:r.maxX,y:e}]}):l.push({distance:r.maxX-n.maxX,box1:n,box2:r,points:[{x:n.maxX,y:e},{x:r.maxX,y:e},{x:r.maxX,y:e}]}),n.minY<r.minY?l.push({box1:n,box2:r,distance:r.minY-n.minY,points:[{x:t,y:n.minY},{x:t,y:r.minY},{x:t,y:r.minY}]}):l.push({box1:n,box2:r,distance:n.minY-r.minY,points:[{x:t,y:n.minY},{x:t,y:r.minY},{x:t,y:r.minY}]}),n.maxY>r.maxY?l.push({box1:n,box2:r,distance:n.maxY-r.maxY,points:[{x:t,y:r.maxY},{x:t,y:n.maxY},{x:t,y:r.maxY}]}):l.push({box1:n,box2:r,distance:r.maxY-n.maxY,points:[{x:t,y:n.maxY},{x:t,y:r.maxY},{x:t,y:r.maxY}]})}}JSON.stringify(Ye)!==JSON.stringify(l)&&Se(l)},[e,i]);o.useEffect(()=>{e.selectedElements[0]&&e.distanceGuidesVisible?Ne():Ye&&Se(null)},[e.distanceGuidesVisible,Ne,e.selectedShapes.map(e=>`${e.x},${e.y},${e.width},${e.height},${e.rotation}`).join("|")]);const Ke=o.useRef(!1);o.useEffect(()=>{var e;let t;const n=null===(e=we.current)||void 0===e?void 0:e.closest(".polotno-workspace-inner"),i=()=>{Ke.current=!0,clearTimeout(t),t=setTimeout(()=>{Ke.current=!1},300)};return null==n||n.addEventListener("scroll",i),()=>{clearTimeout(t),null==n||n.removeEventListener("scroll",i)}},[]),o.useEffect(()=>{const t=ye.current;if(!t){return}const n=t.container(),i=new Map,o=e=>{i.set(e.target,{x:e.target.x(),y:e.target.y()})},r=e=>{i.delete(e.target)};t.on("dragstart",o),t.on("dragend",r);const l=t=>{var n,o;t.touches.length>=2&&((null===(n=xe.current)||void 0===n?void 0:n.isDragging())&&xe.current.stopDrag(),null===(o=xe.current)||void 0===o||o.nodes().forEach(t=>{var n;const o=i.get(t);t.isDragging()&&t.stopDrag(),o&&(t.setAttrs(o),null===(n=e.getElementById(t.id()))||void 0===n||n.set({x:o.x,y:o.y}))}))};return n.addEventListener("touchstart",l,{passive:!0}),n.addEventListener("touchmove",l,{passive:!0}),()=>{t.off("dragstart",o),t.off("dragend",r),n.removeEventListener("touchstart",l),n.removeEventListener("touchmove",l)}},[e]);const $e=t=>{if(e.role===Y.VIEWER){return}if(e.activePage!==i&&i.select(),Ke.current){return}if(He.current){return}const n=t.evt.shiftKey,o=t.evt.ctrlKey||t.evt.metaKey,r=n||o,l=t.target.findAncestor(".elements-container"),s=t.target.findAncestor(".page-abs-container"),a=t.target.findAncestor("Transformer"),d=t.target.findAncestor(".page-container",!0);if(!(r||l||a||s||d||_e.visible)){return e.selectElements([]),void e.selectPages([])}if(o&&!n){const t=ye.current,n=null==t?void 0:t.getPointerPosition();if(!t||!n){return}const i=t.getAllIntersections(n),o=new Set,r=[];for(const s of[...i].reverse()){const t=s.findAncestor(".element",!0);if(!t){continue}const n=e.getElementById(t.id()),i=null==n?void 0:n.top;i&&(o.has(i.id)||(o.add(i.id),r.push(i.id)))}if(0===r.length){return}let l;if(1===e.selectedElementsIds.length){const t=e.selectedElementsIds[0],n=r.indexOf(t);l=-1===n?r[0]:r[(n+1)%r.length]}else{l=r[0]}return e.selectElements([l]),void e.selectPages([])}const c=t.target.findAncestor(".element-container",!0),h=(null==c?void 0:c.findOne(".element"))||t.target.findAncestor(".element",!0),m=e.getElementById(null==h?void 0:h.id()),u=null==m?void 0:m.top;let g;if("group"===S){g=null==u?void 0:u.id}else if(u){const t=e.selectedElements.some(e=>{var t;return(null===(t=e.top)||void 0===t?void 0:t.id)===u.id});g=t?null==m?void 0:m.id:null==u?void 0:u.id}else{g=void 0}const f=null==m?void 0:m.id;if(f&&e.selectedElementsIds.indexOf(f)>=0&&!n){return}const p=!!g&&e.selectedElementsIds.indexOf(g)>=0,x=t.target.findAncestor(".page-container",!0);if(g&&n&&!p){const t=e.selectedElementsIds.concat([g]),n=new Set(t),i=t.filter(t=>{const i=e.getElementById(t);if(!i){return!1}for(let e=i.parent;e;e=null==e?void 0:e.parent){if(n.has(e.id)){return!1}}return!0});e.selectElements(i),e.selectPages([])}else{g&&n&&p?e.selectElements(e.selectedElementsIds.filter(e=>e!==g)):!g||n||p?g&&!n&&p||(x?(n||e.selectElements([]),e.selectPages([i.id])):e.selectPages([])):(e.selectElements([g]),e.selectPages([]))}};I(xe,e);const Qe=e.activePage===i,qe=e._selectedPagesIds.includes(i.id),et=null==w?void 0:w.PageControls,tt=null==w?void 0:w.Tooltip,nt=null==w?void 0:w.ContextMenu,it=1/e.scale,ot=0/e.scale;return n("div",{ref:we,onDragOver:e=>e.preventDefault(),onDrop:t=>{if(t.preventDefault(),e.role===Y.VIEWER){return}if(!ye.current){return}ye.current.setPointersPositions(t);const n=ye.current.findOne(".elements-container"),o=null==n?void 0:n.getRelativePointerPosition(),r=ye.current.getPointerPosition(),l=ye.current.getAllIntersections(r).map(e=>e.findAncestor(".element",!0)).filter(Boolean),s=[...new Set(l.reverse())].map(t=>e.getElementById(t.id())).filter(e=>!!e),a=s[0];he&&o&&(he(o,a,{elements:s,page:i}),he=null)},style:{position:"relative",width:r+"px",height:a+"px",overflow:"hidden",flexShrink:0},className:"polotno-page-container"+(Qe?" active-page":""),children:[t(x,{ref:ye,width:Math.min(r,k.width+200),height:Math.min(k.height+200,a),onClick:$e,onTap:$e,onContextMenu:t=>{if(t.evt.preventDefault(),e.role===Y.VIEWER){return}const n=t.target.findAncestor(".element",!0),i=e.getElementById(null==n?void 0:n.id()),o=null==i?void 0:i.top,r=null==o?void 0:o.id;if(!r){return e.selectElements([]),void Oe.close()}e.selectedElementsIds.indexOf(r)>=0||e.selectElements([r]),Oe.open({x:t.evt.clientX,y:t.evt.clientY})},onMouseDown:Je,onMouseMove:t=>{if(!e.distanceGuidesVisible&&!t.evt.altKey){return void(Ye&&Se(null))}const n=t.target.findAncestor(".element",!0),i=null==n?void 0:n.id();Ne(i)},onDragStart:t=>{var n;const i=t.target.getStage();if(i&&i.getPointersPositions().length>=2){return void t.target.stopDrag()}const o=t.target.findAncestor(".element",!0);if(o){const i=e.getElementById(null==o?void 0:o.id()),r=null==i?void 0:i.top,l=null==r?void 0:r.id;if(!(i&&e.selectedElementsIds.indexOf(i.id)>=0||l&&e.selectedElementsIds.indexOf(l)>=0)&&l){e.selectElements([l]);const i=ze();t.target.stopDrag(),i.forEach(e=>{e.isDragging()||e.startDrag(t)}),null===(n=xe.current)||void 0===n||n.startDrag(t),M()}}Ye&&Se(null)},pageId:i.id,style:{position:"absolute",overflow:"hidden",top:0,left:0},children:n(u,{children:[t(ie,{width:r,height:a,fill:J.workspaceBackgroundColor}),t(c,{x:ue,y:pe,scaleX:e.scale,scaleY:e.scale,name:"page-container",children:n(c,{name:"page-container-2",children:[t(c,{name:"page-background-group",x:re.left,y:re.top,children:t(le,{x:-oe.left,y:-oe.top,width:i.computedWidth+oe.left+oe.right,height:i.computedHeight+oe.top+oe.bottom,background:i.background,transparencyBackgroundColor:J.transparencyBackgroundColor,name:"page-background",preventDefault:!1,scale:e.scale})}),n(c,{x:re.left,y:re.top,name:"elements-container",listening:!e.isPlaying&&e.role!==Y.VIEWER,children:[t(f,{name:"elements-area",width:i.computedWidth,height:i.computedHeight,listening:!1}),t(ce,{elements:i.children,store:e})]}),t(p,{name:"bleed",fill:J.bleedColor,listening:!1,visible:e.bleedVisible&&(re.top>0||re.right>0||re.bottom>0||re.left>0),hideInExport:!0,sceneFunc:(e,t)=>{const{top:n,right:o,bottom:r,left:l}=oe,s=i.computedWidth,a=i.computedHeight,d=e._context;d.beginPath(),d.rect(0,0,l+s+o,n+a+r),d.rect(l,n,s,a),d.fillStyle=t.fill(),d.fill("evenodd")}}),R()===ge&&t(fe,{name:"hit-detection",x:-it/2-ot,y:-it/2-ot,width:ae+it+2*ot,height:me+it+2*ot})]})}),t(g,{name:"workspace-background",points:[0,0,r,0,r,a,0,a,0,0,ue,pe,ue,a-pe,r-ue,a-pe,r-ue,pe,ue,pe],listening:!1,closed:!0,fill:J.workspaceBackgroundColor}),t(c,{x:ue,y:pe,scaleX:e.scale,scaleY:e.scale,children:t(f,{name:"page-highlight",hideInExport:!0,x:-it/2-ot,y:-it/2-ot,width:ae+it+2*ot,height:me+it+2*ot,stroke:qe?J.activePageBorderColor:J.pageBorderColor,strokeWidth:2,listening:!1,strokeScaleEnabled:!1})}),n(c,{x:ue+re.left*e.scale,y:pe+re.top*e.scale,scaleX:e.scale,scaleY:e.scale,name:"page-abs-container",children:[t(y,{ref:xe,rotateAnchorAngle:Me,onDragStart:t=>{var n;const o=t.target.getStage();o&&o.getPointersPositions().length>=2?t.target.stopDrag():((null===(n=t.evt)||void 0===n?void 0:n.altKey)&&E&&e.selectedElements.forEach(e=>{const t=e.clone({},{skipSelect:!0}),n=i.children.indexOf(e);i.setElementZIndex(t.id,n)}),Xe.current||(Xe.current=!0,e.history.startTransaction()))},onDragEnd:()=>{Xe.current&&(e.history.endTransaction(),Xe.current=!1),Ze()},onTransformStart:()=>{e.history.startTransaction(),ve.current=new Map(Te.map(e=>[e.id,{width:e.width,height:e.height}])),Se(null)},boundBoxFunc:(t,n)=>{var i,o;const r=Math.abs(n.width)<1||Math.abs(n.height)<1,l=Math.abs(t.width)<1||Math.abs(t.height)<1;if(r&&!l){return t}const s=e.selectedElements;if(1===s.length&&"table"===(null===(i=s[0])||void 0===i?void 0:i.type)){const e=s[0],i=Math.abs(t.width),o=Math.abs(t.height);if(i>0&&o>0){const r=Math.abs(n.width)/i,l=Math.abs(n.height)/o,s=e.width*r,a=e.height*l,d=Object.assign({},n);return s<e.minWidth&&(d.width=t.width),a<e.minHeight&&(d.height=t.height),te(d,n,t)}}return Be&&Te.length>0?((e,t,n,i,o)=>{const r=Math.abs(e.width),l=Math.abs(e.height);if(0===r||0===l){return t}const s=Math.abs(t.width)/r,a=Math.abs(t.height)/l,d=!V(n),c=e=>i.some(t=>{var n;const i=null==o?void 0:o.get(t.id),r=null!==(n="x"===e?null==i?void 0:i.width:null==i?void 0:i.height)&&void 0!==n?n:"x"===e?t.width:t.height,l="x"===e?t.width:t.height,c="x"===e?s:a,h=((e,t,n,i)=>{if("table"===e.type){const n=e;return"x"===t?n.minWidth:n.minHeight}return"text"===e.type&&"x"===t&&n?F(i,e.fontSize):1})(t,e,d,r);return r>=h&&l*c<h}),h=Object.assign({},t),m=t.width*e.width<0,u=t.height*e.height<0,g=m||c("x"),f=u||c("y"),p=f||!d&&g;return(g||!d&&f)&&(h.width=e.width),p&&(h.height=e.height),te(h,t,e)})(t,n,(null===(o=xe.current)||void 0===o?void 0:o.getActiveAnchor())||"",Te,ve.current):n},onTransform:e=>{const t=xe.current.nodes(),n=t[t.length-1];e.target===n&&setTimeout(()=>{Ue()},0)},onTransformEnd:t=>{Ae({}),e.history.endTransaction(),ve.current=null,Ze(),ze()},visible:!e.isPlaying}),Ye&&Ye.map(({points:i,distance:o,box1:r,box2:l},s)=>n(c,{name:"distances-container",hideInExport:!0,listening:!1,children:[t(f,Object.assign({},r,{stroke:J.distanceGuideStyle.stroke,strokeWidth:1,strokeScaleEnabled:!1})),t(f,Object.assign({},l,{stroke:J.distanceGuideStyle.stroke,strokeWidth:1,strokeScaleEnabled:!1})),t(g,{points:[i[0].x,i[0].y,i[1].x,i[1].y],stroke:J.distanceGuideStyle.stroke,strokeWidth:1,strokeScaleEnabled:!1}),t(g,{points:[i[1].x,i[1].y,i[2].x,i[2].y],stroke:J.distanceGuideStyle.stroke,strokeWidth:1,strokeScaleEnabled:!1}),n(m,{x:(i[0].x+i[1].x)/2,y:(i[0].y+i[1].y)/2,offsetY:-10,scaleX:1/e.scale,scaleY:1/e.scale,children:[t(v,{cornerRadius:5,fill:J.distanceGuideStyle.labelFill,pointerDirection:"down"}),t(b,{align:"center",verticalAlign:"middle",fill:J.distanceGuideStyle.labelTextFill,padding:5,text:L({unit:e.unit,dpi:e.dpi,px:o})})]})]},s)),i._rendering&&n(c,{children:[t(f,{width:ae,height:me,fill:"rgba(255,255,255,0.9)"}),t(b,{text:"Rendering...",fontSize:60,width:ae,height:me,align:"center",verticalAlign:"middle"})]}),tt&&t(tt,{components:w,store:e,page:i,stageRef:ye,tooltipSafeArea:P}),nt&&t(H,{children:t(nt,Object.assign({components:w,store:e},Oe.props))})]}),t(A,{store:e,page:i,width:r,height:a,scale:e.scale,xPadding:ue,yPadding:pe,bleedLeft:re.left,bleedTop:re.top}),t(de,Object.assign({},ke,{store:e})),t(se,{selection:_e}),j()>0&&n(c,{hideInExport:!0,children:[t(be,{name:"cache-bounds",x:r-(1===j()?250:210),y:a-(1===j()?95:45)}),t(be,{name:"cache-bounds-t",x:10,y:10})]}),D()&&t(b,{text:"Powered by polotno.com",fontSize:14,fill:"rgba(0,0,0,0.6)",x:r-170,y:a-18,onMouseEnter:e=>{e.target.getStage().container().style.cursor="pointer"},onMouseLeave:e=>{e.target.getStage().container().style.cursor=""},onTouchStart:e=>{e.cancelBubble=!0},onMouseDown:e=>{e.cancelBubble=!0},onClick:()=>{window.open("https://polotno.com","_blank","noopener")},onTap:()=>{window.open("https://polotno.com","_blank","noopener")}}),t(c,{name:"line-guides"})]})}),Ee&&et&&t(et,{store:e,page:i,xPadding:ue,yPadding:pe,layout:O})]})});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var t=this&&this.__rest||function(t,e){var r={};for(var o in t){Object.prototype.hasOwnProperty.call(t,o)&&e.indexOf(o)<0&&(r[o]=t[o])}if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(o=Object.getOwnPropertySymbols(t);n<o.length;n++){e.indexOf(o[n])<0&&Object.prototype.propertyIsEnumerable.call(t,o[n])&&(r[o[n]]=t[o[n]])}}return r};import{jsx as e,Fragment as r,jsxs as o}from"react/jsx-runtime";import n from"react";import{observer as i}from"mobx-react-lite";import{Group as a,Path as s,Rect as l,Shape as c}from"react-konva";import{nodeAutorun as h}from"../utils/mobx.js";import{isAlive as d}from"mobx-state-tree";import{Html as u}from"react-konva-utils";import{layout as f,drawLayout as g}from"render-tag";import{layoutTextOnPath as m,drawTextOnPathLayout as x}from"render-tag/path";import{activeAnchorOf as p,scaledFontSizeAttrs as y,roundedFontSizeAttrs as b,roundedTextDecorationAttrs as w,textMinResizeWidth as v}from"../utils/px.js";import{flags as E}from"../utils/flags.js";import{applyFilter as O}from"./apply-filters.js";import{getLineHeight as M,usePrevious as S}from"./text-element.js";import{useFontSpecsLoader as j}from"./text-element/font-specs-loader.js";import{getHtml as z,getCurvePath as k,getCurveTextHeight as R}from"@polotno/core/text-html";import{useColor as Y}from"./use-color.js";import{isGradient as X}from"@polotno/core/gradient";import{detectSize as F}from"@polotno/core/measure-html";import{generateBackgroundShapeFromRects as I}from"@polotno/core/background-shape";import{useFadeIn as P}from"./use-fadein.js";import{incrementLoader as C}from"../utils/loader.js";import{removeTags as T}from"@polotno/core/text";import{isTouchDevice as B}from"../utils/screen.js";import{getLimitedFontSize as W}from"./text-element/max-font-size.js";import{normalizeRichTextHtml as D,extractFontSpecsFromHtml as N,scaleRichTextFontSizesInHtml as $}from"../utils/rich-text-html.js";import{RichEditor as J}from"./rich-editor.js";import{findFitFontSize as _}from"./text-element/fit-font-size.js";import{visiblePlaceholder as A}from"./text-element/placeholder.js";import{wrapHtmlForRenderTag as L}from"@polotno/core/reset-style";import{xmlEscape as V}from"@polotno/core/xml";import{hasMeasuredHeight as H,resolveTextBoxHeight as q}from"@polotno/core/text-types";export{L as wrapHtmlForRenderTag};function G(t,e){return t!==e&&(!E.textVerticalResizeEnabled||t<e)}export const RenderTagElement=i(({element:i,store:K})=>{var Q;const U=n.useRef(null),Z=n.useRef(null),[tt,et]=n.useState(!1),rt=n.useRef(i.height),ot=i.isSelected,nt=S(ot),{textVerticalResizeEnabled:it}=E,at=E.autoDeleteEmptyText,st=S(i.fontFamily),lt=n.useMemo(()=>D(i.text,{fontSize:i.fontSize,fontFamily:i.fontFamily}),[i.text,i.fontSize,i.fontFamily]),ct=n.useMemo(()=>N(lt,{fontFamily:i.fontFamily,fontWeight:i.fontWeight,fontStyle:i.fontStyle}),[lt,i.fontFamily,i.fontWeight,i.fontStyle]),[ht]=j(K,ct,i.text||i.placeholder),dt=i._editModeEnabled;P(U);const ut=ht?i.fontFamily:st&&st!==i.fontFamily?st:"Arial",ft=Y(i).fill,gt=X(i.fill),mt=X(i.stroke)&&!!i.strokeWidth,xt=!!i.strokeWidth&&(mt||gt),pt="ellipsis"===E.textOverflow&&!i.curveEnabled&&H(i)&&!xt,yt=A(i.placeholder),bt=!!yt&&!T(i.text),wt=bt?V(yt):lt,vt=bt?.6:i.a.opacity,Et=z(i,{fontFamily:ut,color:ft,forEditor:!pt,textOverflow:E.textOverflow,text:wt,textIsNormalized:!0}),Ot=i.width||1,Mt=i.curveEnabled,St=function(t,e,r,o){return n.useMemo(()=>{if(o){return null}try{return f({html:L(t),width:Math.max(1,e),accuracy:"performance"})}catch(r){return console.error("render-tag layout failed:",r),null}},[t,e,r,o])}(Et,Ot,ht,Mt),jt=function(t,e,r){return n.useMemo(()=>{if(!e.curveEnabled){return null}const r=e.width||1,o=R(e),n=k(r,o,e.curvePower,e.fontSize);try{return m({html:L(t),path:n,align:"center",textBaseline:"middle"})}catch(i){return console.error("render-tag/path layoutTextOnPath failed:",i),null}},[r,e.curveEnabled,e.curvePower,e.fontSize,e.width,e.height,t])}(Et,i,ht),zt=M({fontLoaded:ht,fontFamily:i.fontFamily,fontSize:i.fontSize,lineHeight:i.lineHeight}),kt=Mt?0:Math.max(null!==(Q=null==St?void 0:St.height)&&void 0!==Q?Q:0,i.fontSize*zt),Rt=jt?jt.bounds:null,Yt=n.useMemo(()=>St?St.lines.map(t=>({left:t.bounds.x,right:t.bounds.x+t.bounds.width,top:t.bounds.y,bottom:t.bounds.y+t.bounds.height})):[],[St]),Xt=n.useRef([]),Ft=n.useRef(null),It=n.useRef(!0),[,Pt]=n.useReducer(t=>t+1,0);n.useEffect(()=>{const t=Xt.current;t.length>0&&(Xt.current=[],t.forEach(t=>t()))});const Ct=n.useCallback((t,e,r,o)=>{const n=C(`text ${i.id}`),a=()=>{K.history.ignore(t,e,r).then(()=>{It.current?(Xt.current.push(n),Pt()):n()})};o?queueMicrotask(a):a()},[i.id,K]),Tt=n.useCallback(t=>{const e=null!==Ft.current;Ft.current=t,e||Ct(()=>{const t=Ft.current;Ft.current=null,d(i)&&G(i.height,t)&&i.set({height:t})},!1,!0)},[i,Ct]);n.useEffect(()=>{if(!ht){return}if(!St){return}if(!H(i)){return void Ct(()=>{d(i)&&(H(i)||i.set({height:kt}))},void 0,void 0,!0)}if(K.isPlaying){return}const{textOverflow:t}=E,e=G(i.height,kt),r=()=>Tt(kt);if("change-font-size"!==t||tt||dt||i.curveEnabled){"resize"===t&&e&&!tt&&r()}else{const t=_(bt?{toJSON:()=>Object.assign(Object.assign({},i.toJSON()),{text:wt})}:i,{fontFamily:ut,color:ft,forEditor:!0},t=>{try{return f({html:L(t),width:Ot,accuracy:"performance"}).height}catch(Q){return F(t).height}});t.fontSize!==i.fontSize?Ct(()=>{if(!d(i)){return}const e=y(i,t.fontSize);void 0!==t.text&&t.text!==i.text&&(e.text=t.text),i.set(e)},!1,!0):e&&r()}}),n.useEffect(()=>()=>{It.current=!1;const t=Xt.current;t.length>0&&(Xt.current=[],t.forEach(t=>t()))},[]),n.useLayoutEffect(()=>{if(!ht||!i.curveEnabled||tt){return}if(!Rt||!Rt.width){return}const t=t=>t&&it?Math.max(t,Rt.height):Rt.height;Math.abs(Rt.width-i.width)<1&&Math.abs(t(i.height)-i.height)<1||Ct(()=>{if(!d(i)){return}const e=Rt.width-i.width,r=t(i.height),o=r-i.height;if(Math.abs(e)<1&&Math.abs(o)<1){return}const n=i.a.rotation*Math.PI/180,a=-e/2*Math.cos(n),s=-e/2*Math.sin(n);i.set({width:Rt.width,height:r,x:i.a.x+a,y:i.a.y+s})},!1,!0,!0)},[ht,i.curveEnabled,Rt,tt,it,Ct]),n.useEffect(()=>{nt&&!ot&&at&&""===T(i.text)&&i.removable&&!A(i.placeholder)&&K.deleteElements([i.id])},[at,i.placeholder,i.removable,i.text,ot,nt]),n.useEffect(()=>h(i,()=>{const t=U.current;t&&O(t,i)}),[St,jt,i.a.width,i.a.height,i.shadowColor,i.shadowOffsetX,i.shadowOffsetY,i.shadowOpacity]);const Bt=q(i,kt),Wt=Mt||!ht||tt||K.isPlaying||"resize"!==E.textOverflow?i.a.height:it?Math.max(i.a.height,kt):kt;let Dt=0;Mt||"middle"!==i.verticalAlign?Mt||"bottom"!==i.verticalAlign||(Dt=Bt-kt):Dt=(Bt-kt)/2;const Nt=i.backgroundPadding*(i.fontSize*zt*.5),$t=i.backgroundCornerRadius*(i.fontSize*zt*.5),Jt=n.useMemo(()=>!i.backgroundEnabled||i.curveEnabled||i.legacyBackground||0===Yt.length?"":I({rects:Yt,padding:Nt,cornerRadius:$t}),[i.backgroundEnabled,i.curveEnabled,i.legacyBackground,Yt,Nt,$t]),_t=B(),At=n.useRef(null),Lt=n.useRef(i.width),Vt=n.useRef(null),Ht=n.useRef(null),qt=n.useRef(""),Gt=n.useRef(0),Kt=n.useRef(0),Qt=i.width>0?i.a.width/i.width:1;return o(r,{children:[i.curveEnabled||i.legacyBackground?e(l,{x:i.a.x,y:i.a.y,offsetX:Nt/Qt,offsetY:Nt/Qt,rotation:i.a.rotation,scaleX:Qt,scaleY:Qt,hideInExport:!i.showInExport,listening:!1,visible:i.backgroundEnabled,opacity:i.backgroundOpacity*vt,fill:i.backgroundColor,width:i.width+2*Nt,height:Bt+2*Nt,cornerRadius:$t}):e(s,{name:"rendertag-background",x:i.a.x,y:i.a.y,offsetY:-Dt/Qt,rotation:i.a.rotation,scaleX:Qt,scaleY:Qt,hideInExport:!i.showInExport,listening:!1,visible:i.backgroundEnabled&&Jt.length>0,opacity:i.backgroundOpacity*vt,fill:i.backgroundColor,data:Jt}),e(c,{ref:U,name:"rendertag-text",x:i.a.x,y:i.a.y,rotation:i.a.rotation,scaleX:Qt,scaleY:Qt,offsetY:Qt>0?-Dt/Qt:0,width:i.width,height:Math.max(i.height,kt),listening:!1,visible:!dt&&!!(Mt?jt:St),editModeEnabled:dt,opacity:vt,shadowEnabled:i.shadowEnabled,shadowBlur:i.shadowBlur,shadowOffsetX:i.shadowOffsetX,shadowOffsetY:i.shadowOffsetY,shadowColor:i.shadowColor,shadowOpacity:i.shadowOpacity,hideInExport:!i.showInExport,sceneFunc:(t,e)=>{const r=t._context;if(r){try{if(Mt){if(!jt||!Rt){return}const t=(i.width-Rt.width)/2-Rt.x;r.save(),r.translate(t,-Rt.y),x({layout:jt,ctx:r}),r.restore()}else{if(!St){return}g({layout:St,width:Ot,ctx:r,pixelRatio:1})}}catch(o){console.error("render-tag draw failed:",o)}}}}),e(l,{ref:Z,name:"element",x:i.a.x,y:i.a.y,listening:i.selectable,rotation:i.a.rotation,width:i.a.width,height:Wt,visible:!dt,draggable:_t?i.draggable&&ot:i.draggable,preventDefault:!_t||ot,opacity:0,hideInExport:!0,id:i.id,onDragMove:t=>{i.set({x:t.target.x(),y:t.target.y()})},onDragEnd:t=>{i.set({x:t.target.x(),y:t.target.y()})},onDblClick:t=>{i.contentEditable&&(Ht.current={x:t.evt.clientX,y:t.evt.clientY},i.toggleEditMode(!0))},onDblTap:t=>{var e;if(i.contentEditable){const r=null===(e=t.evt.changedTouches)||void 0===e?void 0:e[0];Ht.current=r?{x:r.clientX,y:r.clientY}:null,i.toggleEditMode(!0)}},onTransformStart:t=>{et(!0),rt.current=i.height,Lt.current=i.width,Vt.current=null,At.current=t.target.position(),qt.current=p(t.target),Gt.current=i.a.rotation,Kt.current=i.height},onTransform:e=>{const r=e.target,o=qt.current,n="middle-left"===o||"middle-right"===o,a="top-center"===o||"bottom-center"===o,s=r.scaleX();if(n){const e=r.scaleX(),o=r.width()*e;let n=Math.max(o,v(Lt.current,i.fontSize));const a=i.toJSON();let s=0;if(i.curveEnabled){s=R(Object.assign(Object.assign({},a),{width:n}))}else{const{x:e,y:r,width:o,height:i}=a,l=t(a,["x","y","width","height"]),c=`${JSON.stringify(l)}|${ut}|${ht}|${ft}`;if(Vt.current&&Vt.current.signature===c&&n<=Vt.current.width){n=Vt.current.width,s=Vt.current.height}else{const t=t=>{const e=z(Object.assign(Object.assign({},a),{width:t}),{fontFamily:ut,color:ft,forEditor:!0,text:wt,textIsNormalized:!0});try{return f({html:L(e),width:t,accuracy:"performance"})}catch(Q){return{height:F(e).height,lines:[]}}};let e=t(n);const r=Math.max(0,...e.lines.map(t=>t.bounds.x+t.bounds.width));r>n+.5&&r<=Lt.current+.5&&(n=Math.min(Math.ceil(r),Lt.current),e=t(n),Vt.current={signature:c,width:n,height:e.height}),s=e.height}}n>o&&At.current&&r.position(At.current),r.width(n),r.scaleX(1),r.scaleY(1);let l=E.textVerticalResizeEnabled?Math.max(s,rt.current):s;"ellipsis"===E.textOverflow&&(l=rt.current),r.height(l),i.set({width:r.width(),height:l,x:r.x(),y:r.y()})}else if(a){const t="resize"===E.textOverflow?Mt?(null==Rt?void 0:Rt.height)||i.fontSize:kt:zt*i.fontSize,e=r.height()*r.scaleY();if(e<t){if(r.height(t),At.current){if("top-center"===qt.current){const e=Gt.current*Math.PI/180,o=Kt.current-t;r.x(At.current.x-o*Math.sin(e)),r.y(At.current.y+o*Math.cos(e))}else{r.position(At.current)}}}else{r.height(e)}r.scaleY(1),r.scaleX(1),Kt.current=Math.max(t,e),i.set({x:r.x(),y:r.y(),height:r.height(),rotation:r.rotation()})}else{r.scaleX(1),r.scaleY(1),i.set({fontSize:i.fontSize*s,letterSpacing:i.letterSpacing,width:r.width()*s,x:r.x(),y:r.y(),rotation:r.rotation(),height:r.height()*s,shadowBlur:i.shadowBlur*s,shadowOffsetX:i.shadowOffsetX*s,shadowOffsetY:i.shadowOffsetY*s,strokeWidth:i.strokeWidth*s,text:$(i.text,s)})}At.current=e.target.position()},onTransformEnd:t=>{et(!1);const e=t.target.scaleX();t.target.scaleX(1),t.target.scaleY(1),i.set(Object.assign(Object.assign({},b(i,i.fontSize*e)),{width:t.target.width()*e,x:t.target.x(),y:t.target.y(),rotation:t.target.rotation(),text:$(i.text,e)}))}}),dt&&e(a,{x:i.a.x,y:i.a.y,rotation:i.a.rotation,offsetY:-Dt,children:e(u,{divProps:{style:{zIndex:20}},children:e(J,{element:i,onChange:t=>{const e=W({oldText:T(i.text),newText:T(t),element:i});i.set(Object.assign({text:t},y(i,e)))},onBlur:()=>{d(i)&&(i.set(w(i)),i.toggleEditMode(!1))},clickCoords:Ht.current})})})]})});
|
|
1
|
+
var t=this&&this.__rest||function(t,e){var r={};for(var o in t){Object.prototype.hasOwnProperty.call(t,o)&&e.indexOf(o)<0&&(r[o]=t[o])}if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(o=Object.getOwnPropertySymbols(t);n<o.length;n++){e.indexOf(o[n])<0&&Object.prototype.propertyIsEnumerable.call(t,o[n])&&(r[o[n]]=t[o[n]])}}return r};import{jsx as e,Fragment as r,jsxs as o}from"react/jsx-runtime";import n from"react";import{observer as i}from"mobx-react-lite";import{Group as a,Path as l,Rect as s,Shape as c}from"react-konva";import{nodeAutorun as h}from"../utils/mobx.js";import{isAlive as d}from"mobx-state-tree";import{Html as u}from"react-konva-utils";import{layout as f,drawLayout as g}from"render-tag";import{layoutTextOnPath as m,drawTextOnPathLayout as x}from"render-tag/path";import{activeAnchorOf as p,scaledFontSizeAttrs as y,roundedFontSizeAttrs as b,roundedTextDecorationAttrs as w,roundedGeometryPx as v,roundedPosition as E,textMinResizeWidth as O}from"../utils/px.js";import{flags as S}from"../utils/flags.js";import{applyFilter as M}from"./apply-filters.js";import{getLineHeight as z,usePrevious as j}from"./text-element.js";import{useFontSpecsLoader as k}from"./text-element/font-specs-loader.js";import{getHtml as R,getCurvePath as Y,getCurveTextHeight as X,letterSpacingOverhang as F}from"@polotno/core/text-html";import{useColor as I}from"./use-color.js";import{isGradient as P}from"@polotno/core/gradient";import{detectSize as C}from"@polotno/core/measure-html";import{generateBackgroundShapeFromRects as T,trimTrailingLetterSpace as B}from"@polotno/core/background-shape";import{useFadeIn as W}from"./use-fadein.js";import{incrementLoader as D}from"../utils/loader.js";import{removeTags as N}from"@polotno/core/text";import{isTouchDevice as $}from"../utils/screen.js";import{getLimitedFontSize as J}from"./text-element/max-font-size.js";import{normalizeRichTextHtml as _,extractFontSpecsFromHtml as A,scaleRichTextFontSizesInHtml as L}from"../utils/rich-text-html.js";import{RichEditor as V}from"./rich-editor.js";import{findFitFontSize as H}from"./text-element/fit-font-size.js";import{visiblePlaceholder as q}from"./text-element/placeholder.js";import{wrapHtmlForRenderTag as G}from"@polotno/core/reset-style";import{xmlEscape as K}from"@polotno/core/xml";import{hasMeasuredHeight as Q,resolveTextBoxHeight as U}from"@polotno/core/text-types";export{G as wrapHtmlForRenderTag};function Z(t,e){return t!==e&&(!S.textVerticalResizeEnabled||t<e)}export const RenderTagElement=i(({element:i,store:tt})=>{var et;const rt=n.useRef(null),ot=n.useRef(null),[nt,it]=n.useState(!1),at=n.useRef(i.height),lt=i.isSelected,st=j(lt),{textVerticalResizeEnabled:ct}=S,ht=S.autoDeleteEmptyText,dt=j(i.fontFamily),ut=n.useMemo(()=>_(i.text,{fontSize:i.fontSize,fontFamily:i.fontFamily}),[i.text,i.fontSize,i.fontFamily]),ft=n.useMemo(()=>A(ut,{fontFamily:i.fontFamily,fontWeight:i.fontWeight,fontStyle:i.fontStyle}),[ut,i.fontFamily,i.fontWeight,i.fontStyle]),[gt]=k(tt,ft,i.text||i.placeholder),mt=i._editModeEnabled;W(rt);const xt=gt?i.fontFamily:dt&&dt!==i.fontFamily?dt:"Arial",pt=I(i).fill,yt=P(i.fill),bt=P(i.stroke)&&!!i.strokeWidth,wt=!!i.strokeWidth&&(bt||yt),vt="ellipsis"===S.textOverflow&&!i.curveEnabled&&Q(i)&&!wt,Et=q(i.placeholder),Ot=!!Et&&!N(i.text),St=Ot?K(Et):ut,Mt=Ot?.6:i.a.opacity,zt=R(i,{fontFamily:xt,color:pt,forEditor:!vt,textOverflow:S.textOverflow,text:St,textIsNormalized:!0}),jt=i.width||1,kt=F(i.letterSpacing,i.fontSize),Rt=i.curveEnabled,Yt=function(t,e,r,o){return n.useMemo(()=>{if(o){return null}try{return f({html:G(t),width:Math.max(1,e),accuracy:"performance"})}catch(r){return console.error("render-tag layout failed:",r),null}},[t,e,r,o])}(zt,jt,gt,Rt),Xt=function(t,e,r){return n.useMemo(()=>{if(!e.curveEnabled){return null}const r=e.width||1,o=X(e),n=Y(r,o,e.curvePower,e.fontSize);try{return m({html:G(t),path:n,align:"center",textBaseline:"middle"})}catch(i){return console.error("render-tag/path layoutTextOnPath failed:",i),null}},[r,e.curveEnabled,e.curvePower,e.fontSize,e.width,e.height,t])}(zt,i,gt),Ft=z({fontLoaded:gt,fontFamily:i.fontFamily,fontSize:i.fontSize,lineHeight:i.lineHeight}),It=Rt?0:Math.max(null!==(et=null==Yt?void 0:Yt.height)&&void 0!==et?et:0,i.fontSize*Ft),Pt=Xt?Xt.bounds:null,Ct=n.useMemo(()=>Yt?Yt.lines.map(t=>B({left:t.bounds.x,right:t.bounds.x+t.bounds.width,top:t.bounds.y,bottom:t.bounds.y+t.bounds.height},kt)):[],[Yt,kt]),Tt=n.useRef([]),Bt=n.useRef(null),Wt=n.useRef(!0),[,Dt]=n.useReducer(t=>t+1,0);n.useEffect(()=>{const t=Tt.current;t.length>0&&(Tt.current=[],t.forEach(t=>t()))});const Nt=n.useCallback((t,e,r,o)=>{const n=D(`text ${i.id}`),a=()=>{tt.history.ignore(t,e,r).then(()=>{Wt.current?(Tt.current.push(n),Dt()):n()})};o?queueMicrotask(a):a()},[i.id,tt]),$t=n.useCallback(t=>{const e=null!==Bt.current;Bt.current=t,e||Nt(()=>{const t=Bt.current;Bt.current=null,d(i)&&Z(i.height,t)&&i.set({height:t})},!1,!0)},[i,Nt]);n.useEffect(()=>{if(!gt){return}if(!Yt){return}if(!Q(i)){return void Nt(()=>{d(i)&&(Q(i)||i.set({height:It}))},void 0,void 0,!0)}if(tt.isPlaying){return}const{textOverflow:t}=S,e=Z(i.height,It),r=()=>$t(It);if("change-font-size"!==t||nt||mt||i.curveEnabled){"resize"===t&&e&&!nt&&r()}else{const t=H(Ot?{toJSON:()=>Object.assign(Object.assign({},i.toJSON()),{text:St})}:i,{fontFamily:xt,color:pt,forEditor:!0},t=>{try{return f({html:G(t),width:jt,accuracy:"performance"}).height}catch(et){return C(t).height}});t.fontSize!==i.fontSize?Nt(()=>{if(!d(i)){return}const e=y(i,t.fontSize);void 0!==t.text&&t.text!==i.text&&(e.text=t.text),i.set(e)},!1,!0):e&&r()}}),n.useEffect(()=>()=>{Wt.current=!1;const t=Tt.current;t.length>0&&(Tt.current=[],t.forEach(t=>t()))},[]),n.useLayoutEffect(()=>{if(!gt||!i.curveEnabled||nt){return}if(!Pt||!Pt.width){return}const t=t=>t&&ct?Math.max(t,Pt.height):Pt.height;Math.abs(Pt.width-i.width)<1&&Math.abs(t(i.height)-i.height)<1||Nt(()=>{if(!d(i)){return}const e=Pt.width-i.width,r=t(i.height),o=r-i.height;if(Math.abs(e)<1&&Math.abs(o)<1){return}const n=i.a.rotation*Math.PI/180,a=-e/2*Math.cos(n),l=-e/2*Math.sin(n);i.set({width:Pt.width,height:r,x:i.a.x+a,y:i.a.y+l})},!1,!0,!0)},[gt,i.curveEnabled,Pt,nt,ct,Nt]),n.useEffect(()=>{st&&!lt&&ht&&""===N(i.text)&&i.removable&&!q(i.placeholder)&&tt.deleteElements([i.id])},[ht,i.placeholder,i.removable,i.text,lt,st]),n.useEffect(()=>h(i,()=>{const t=rt.current;t&&M(t,i)}),[Yt,Xt,i.a.width,i.a.height,i.shadowColor,i.shadowOffsetX,i.shadowOffsetY,i.shadowOpacity]);const Jt=U(i,It),_t=Rt||!gt||nt||tt.isPlaying||"resize"!==S.textOverflow?i.a.height:ct?Math.max(i.a.height,It):It;let At=0;Rt||"middle"!==i.verticalAlign?Rt||"bottom"!==i.verticalAlign||(At=Jt-It):At=(Jt-It)/2;const Lt=i.backgroundPadding*(i.fontSize*Ft*.5),Vt=i.backgroundCornerRadius*(i.fontSize*Ft*.5),Ht=n.useMemo(()=>!i.backgroundEnabled||i.curveEnabled||i.legacyBackground||0===Ct.length?"":T({rects:Ct,padding:Lt,cornerRadius:Vt}),[i.backgroundEnabled,i.curveEnabled,i.legacyBackground,Ct,Lt,Vt]),qt=$(),Gt=n.useRef(null),Kt=n.useRef(i.width),Qt=n.useRef(null),Ut=n.useRef(null),Zt=n.useRef(""),te=n.useRef(0),ee=n.useRef(0),re=i.width>0?i.a.width/i.width:1;return o(r,{children:[i.curveEnabled||i.legacyBackground?e(s,{x:i.a.x,y:i.a.y,offsetX:Lt/re,offsetY:Lt/re,rotation:i.a.rotation,scaleX:re,scaleY:re,hideInExport:!i.showInExport,listening:!1,visible:i.backgroundEnabled,opacity:i.backgroundOpacity*Mt,fill:i.backgroundColor,width:i.width+2*Lt,height:Jt+2*Lt,cornerRadius:Vt}):e(l,{name:"rendertag-background",x:i.a.x,y:i.a.y,offsetY:-At/re,rotation:i.a.rotation,scaleX:re,scaleY:re,hideInExport:!i.showInExport,listening:!1,visible:i.backgroundEnabled&&Ht.length>0,opacity:i.backgroundOpacity*Mt,fill:i.backgroundColor,data:Ht}),e(c,{ref:rt,name:"rendertag-text",x:i.a.x,y:i.a.y,rotation:i.a.rotation,scaleX:re,scaleY:re,offsetY:re>0?-At/re:0,width:i.width,height:Math.max(i.height,It),listening:!1,visible:!mt&&!!(Rt?Xt:Yt),editModeEnabled:mt,opacity:Mt,shadowEnabled:i.shadowEnabled,shadowBlur:i.shadowBlur,shadowOffsetX:i.shadowOffsetX,shadowOffsetY:i.shadowOffsetY,shadowColor:i.shadowColor,shadowOpacity:i.shadowOpacity,hideInExport:!i.showInExport,sceneFunc:(t,e)=>{const r=t._context;if(r){try{if(Rt){if(!Xt||!Pt){return}const t=(i.width-Pt.width)/2-Pt.x;r.save(),r.translate(t,-Pt.y),x({layout:Xt,ctx:r}),r.restore()}else{if(!Yt){return}g({layout:Yt,width:jt,ctx:r,pixelRatio:1})}}catch(o){console.error("render-tag draw failed:",o)}}}}),e(s,{ref:ot,name:"element",x:i.a.x,y:i.a.y,listening:i.selectable,rotation:i.a.rotation,width:i.a.width,height:_t,visible:!mt,draggable:qt?i.draggable&<:i.draggable,preventDefault:!qt||lt,opacity:0,hideInExport:!0,id:i.id,onDragMove:t=>{i.set({x:t.target.x(),y:t.target.y()})},onDragEnd:t=>{i.set(E(t.target))},onDblClick:t=>{i.contentEditable&&(Ut.current={x:t.evt.clientX,y:t.evt.clientY},i.toggleEditMode(!0))},onDblTap:t=>{var e;if(i.contentEditable){const r=null===(e=t.evt.changedTouches)||void 0===e?void 0:e[0];Ut.current=r?{x:r.clientX,y:r.clientY}:null,i.toggleEditMode(!0)}},onTransformStart:t=>{it(!0),at.current=i.height,Kt.current=i.width,Qt.current=null,Gt.current=t.target.position(),Zt.current=p(t.target),te.current=i.a.rotation,ee.current=i.height},onTransform:e=>{const r=e.target,o=Zt.current,n="middle-left"===o||"middle-right"===o,a="top-center"===o||"bottom-center"===o,l=r.scaleX();if(n){const e=r.scaleX(),o=r.width()*e;let n=Math.max(o,O(Kt.current,i.fontSize));const a=i.toJSON();let l=0;if(i.curveEnabled){l=X(Object.assign(Object.assign({},a),{width:n}))}else{const{x:e,y:r,width:o,height:i}=a,s=t(a,["x","y","width","height"]),c=`${JSON.stringify(s)}|${xt}|${gt}|${pt}`;if(Qt.current&&Qt.current.signature===c&&n<=Qt.current.width){n=Qt.current.width,l=Qt.current.height}else{const t=t=>{const e=R(Object.assign(Object.assign({},a),{width:t}),{fontFamily:xt,color:pt,forEditor:!0,text:St,textIsNormalized:!0});try{return f({html:G(e),width:t,accuracy:"performance"})}catch(et){return{height:C(e).height,lines:[]}}};let e=t(n);const r=Math.max(0,...e.lines.map(t=>t.bounds.x+t.bounds.width-kt));r>n+.5&&r<=Kt.current+.5&&(n=Math.min(Math.ceil(r),Kt.current),e=t(n),Qt.current={signature:c,width:n,height:e.height}),l=e.height}}n>o&&Gt.current&&r.position(Gt.current),r.width(n),r.scaleX(1),r.scaleY(1);let s=S.textVerticalResizeEnabled?Math.max(l,at.current):l;"ellipsis"===S.textOverflow&&(s=at.current),r.height(s),i.set({width:r.width(),height:s,x:r.x(),y:r.y()})}else if(a){const t="resize"===S.textOverflow?Rt?(null==Pt?void 0:Pt.height)||i.fontSize:It:Ft*i.fontSize,e=r.height()*r.scaleY();if(e<t){if(r.height(t),Gt.current){if("top-center"===Zt.current){const e=te.current*Math.PI/180,o=ee.current-t;r.x(Gt.current.x-o*Math.sin(e)),r.y(Gt.current.y+o*Math.cos(e))}else{r.position(Gt.current)}}}else{r.height(e)}r.scaleY(1),r.scaleX(1),ee.current=Math.max(t,e),i.set({x:r.x(),y:r.y(),height:r.height(),rotation:r.rotation()})}else{r.scaleX(1),r.scaleY(1),i.set({fontSize:i.fontSize*l,letterSpacing:i.letterSpacing,width:r.width()*l,x:r.x(),y:r.y(),rotation:r.rotation(),height:r.height()*l,shadowBlur:i.shadowBlur*l,shadowOffsetX:i.shadowOffsetX*l,shadowOffsetY:i.shadowOffsetY*l,strokeWidth:i.strokeWidth*l,text:L(i.text,l)})}Gt.current=e.target.position()},onTransformEnd:t=>{it(!1);const e=t.target.scaleX();t.target.scaleX(1),t.target.scaleY(1),i.set(Object.assign(Object.assign({},b(i,i.fontSize*e)),{width:v(t.target.width()*e),x:v(t.target.x()),y:v(t.target.y()),rotation:v(t.target.rotation()),text:L(i.text,e)}))}}),mt&&e(a,{x:i.a.x,y:i.a.y,rotation:i.a.rotation,offsetY:-At,children:e(u,{divProps:{style:{zIndex:20}},children:e(V,{element:i,onChange:t=>{const e=J({oldText:N(i.text),newText:N(t),element:i});i.set(Object.assign({text:t},y(i,e)))},onBlur:()=>{d(i)&&(i.set(w(i)),i.toggleEditMode(!1))},clickCoords:Ut.current})})})]})});
|