polotno 4.12.0 → 4.13.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/README.md +57 -22
- package/blueprint/canvas/context-menu/context-menu.d.ts +2 -2
- package/blueprint/canvas/page-controls.d.ts +14 -2
- package/blueprint/canvas/tooltip.d.ts +24 -2
- package/blueprint/pages-timeline/audio-track.d.ts +12 -2
- package/blueprint/pages-timeline/audios.d.ts +10 -2
- package/blueprint/pages-timeline/current-time.d.ts +2 -2
- package/blueprint/pages-timeline/element-track.d.ts +14 -2
- package/blueprint/pages-timeline/elements.d.ts +2 -2
- package/blueprint/pages-timeline/page-preview.d.ts +8 -2
- package/blueprint/pages-timeline/pages-timeline.d.ts +8 -2
- package/blueprint/pages-timeline/pages.d.ts +8 -2
- package/blueprint/pages-timeline/play-button.d.ts +2 -2
- package/blueprint/pages-timeline/time-ruler.d.ts +10 -2
- package/blueprint/side-panel/ai-images-panel.d.ts +6 -2
- package/blueprint/side-panel/animations-panel.d.ts +6 -2
- package/blueprint/side-panel/background-panel.d.ts +6 -2
- package/blueprint/side-panel/draw-panel.d.ts +6 -2
- package/blueprint/side-panel/effects-panel.d.ts +6 -2
- package/blueprint/side-panel/image-clip-panel.d.ts +6 -2
- package/blueprint/side-panel/layers-panel.d.ts +6 -2
- package/blueprint/side-panel/pages-panel.d.ts +6 -2
- package/blueprint/side-panel/select-video.d.ts +2 -2
- package/blueprint/side-panel/side-panel.d.ts +2 -2
- package/blueprint/side-panel/size-panel.d.ts +6 -2
- package/blueprint/side-panel/templates-panel.d.ts +6 -2
- package/blueprint/side-panel/text-panel.d.ts +6 -2
- package/blueprint/side-panel/videos-panel.d.ts +6 -2
- package/blueprint/toolbar/admin-button.d.ts +6 -2
- package/blueprint/toolbar/animations-picker.d.ts +18 -4
- package/blueprint/toolbar/copy-style.d.ts +6 -2
- package/blueprint/toolbar/download-button.d.ts +6 -2
- package/blueprint/toolbar/duplicate-button.d.ts +6 -2
- package/blueprint/toolbar/figure-toolbar.d.ts +8 -8
- package/blueprint/toolbar/filters-picker.d.ts +26 -6
- package/blueprint/toolbar/gif-toolbar.d.ts +2 -2
- package/blueprint/toolbar/group-button.d.ts +6 -2
- package/blueprint/toolbar/group-toolbar.d.ts +2 -2
- package/blueprint/toolbar/history-buttons.d.ts +6 -2
- package/blueprint/toolbar/html-toolbar.d.ts +10 -10
- package/blueprint/toolbar/image-remove-background-button.d.ts +10 -2
- package/blueprint/toolbar/image-toolbar.d.ts +28 -8
- package/blueprint/toolbar/line-toolbar.d.ts +14 -10
- package/blueprint/toolbar/lock-button.d.ts +6 -2
- package/blueprint/toolbar/many-toolbar.d.ts +2 -2
- package/blueprint/toolbar/opacity-picker.d.ts +6 -2
- package/blueprint/toolbar/page-toolbar.d.ts +2 -2
- package/blueprint/toolbar/position-picker.d.ts +6 -2
- package/blueprint/toolbar/remove-button.d.ts +6 -2
- package/blueprint/toolbar/svg-toolbar.d.ts +2 -2
- package/blueprint/toolbar/table-toolbar.d.ts +44 -14
- package/blueprint/toolbar/text-ai-write.d.ts +6 -2
- package/blueprint/toolbar/text-toolbar.d.ts +14 -14
- package/blueprint/toolbar/toolbar.d.ts +2 -2
- package/blueprint/toolbar/video-toolbar.d.ts +6 -6
- package/blueprint/toolbar/zoom-buttons.d.ts +4 -4
- package/canvas/audio.d.ts +3 -2
- package/canvas/context-menu/context-menu.d.ts +2 -2
- package/canvas/drawing-layer.d.ts +2 -2
- package/canvas/element.d.ts +2 -2
- package/canvas/fade-overlay.d.ts +14 -0
- package/canvas/fade-overlay.js +1 -0
- package/canvas/figure-element.d.ts +2 -2
- package/canvas/gif-element.d.ts +2 -2
- package/canvas/gif-element.js +1 -1
- package/canvas/highlighter.d.ts +6 -2
- package/canvas/html-element.d.ts +2 -2
- package/canvas/image-element.d.ts +5 -3
- package/canvas/image-element.js +1 -1
- package/canvas/line-element.d.ts +2 -2
- package/canvas/page-controls.d.ts +14 -2
- package/canvas/page.d.ts +2 -2
- package/canvas/page.js +1 -1
- package/canvas/render-tag-element.d.ts +2 -2
- package/canvas/render-tag-element.js +1 -1
- package/canvas/rich-editor.js +3 -3
- package/canvas/rules.d.ts +2 -2
- package/canvas/table-element.d.ts +2 -2
- package/canvas/text-element.d.ts +2 -2
- package/canvas/tooltip.d.ts +24 -2
- package/canvas/video-element.d.ts +3 -2
- package/canvas/video-element.js +1 -1
- package/canvas/workspace-canvas.d.ts +2 -2
- package/hooks/use-fade-stop-focus.d.ts +2 -0
- package/hooks/use-fade-stop-focus.js +1 -0
- package/icons/registry.d.ts +106 -102
- package/model/figure-model.d.ts +1 -1
- package/model/gif-model.d.ts +1 -1
- package/model/group-model.d.ts +8 -8
- package/model/image-model.d.ts +1 -1
- package/model/line-model.d.ts +1 -1
- package/model/page-model.d.ts +10 -10
- package/model/shape-model.d.ts +2 -2
- package/model/shape-model.js +1 -1
- package/model/store.d.ts +92 -92
- package/model/svg-model.d.ts +1 -1
- package/model/table-model.d.ts +1 -1
- package/model/text-model.d.ts +1 -1
- package/model/video-model.d.ts +1 -1
- package/package.json +52 -38
- package/pages-timeline/audio-track.d.ts +14 -2
- package/pages-timeline/audio-track.js +1 -1
- package/pages-timeline/audios.d.ts +10 -2
- package/pages-timeline/current-time.d.ts +2 -2
- package/pages-timeline/current-time.js +1 -1
- package/pages-timeline/element-track.d.ts +14 -2
- package/pages-timeline/element-track.js +1 -1
- package/pages-timeline/elements.d.ts +2 -2
- package/pages-timeline/page-preview.d.ts +8 -2
- package/pages-timeline/page-preview.js +1 -1
- package/pages-timeline/pages-timeline.d.ts +8 -2
- package/pages-timeline/pages-timeline.js +1 -1
- package/pages-timeline/pages.d.ts +8 -2
- package/pages-timeline/play-button.d.ts +2 -2
- package/pages-timeline/time-ruler.d.ts +10 -2
- package/pages-timeline/time-ruler.js +1 -1
- package/polotno.bundle.js +167 -166
- package/side-panel/ai-images-panel.d.ts +6 -2
- package/side-panel/animations-panel.d.ts +6 -2
- package/side-panel/background-panel.d.ts +6 -2
- package/side-panel/draw-panel.d.ts +6 -2
- package/side-panel/effects-panel.d.ts +6 -2
- package/side-panel/effects-panel.js +1 -1
- package/side-panel/image-clip-panel.d.ts +6 -2
- package/side-panel/layers-panel.d.ts +6 -2
- package/side-panel/pages-panel.d.ts +6 -2
- package/side-panel/select-video.d.ts +2 -2
- package/side-panel/side-panel.d.ts +2 -2
- package/side-panel/size-panel.d.ts +6 -2
- package/side-panel/templates-panel.d.ts +6 -2
- package/side-panel/text-panel.d.ts +6 -2
- package/side-panel/videos-panel.d.ts +6 -2
- package/toolbar/admin-button.d.ts +6 -2
- package/toolbar/animations-picker.d.ts +18 -4
- package/toolbar/copy-style.d.ts +6 -2
- package/toolbar/download-button.d.ts +6 -2
- package/toolbar/duplicate-button.d.ts +6 -2
- package/toolbar/figure-toolbar.d.ts +8 -8
- package/toolbar/filters-picker.d.ts +26 -6
- package/toolbar/gif-toolbar.d.ts +2 -2
- package/toolbar/group-button.d.ts +6 -2
- package/toolbar/group-toolbar.d.ts +2 -2
- package/toolbar/history-buttons.d.ts +6 -2
- package/toolbar/html-toolbar.d.ts +10 -10
- package/toolbar/image-remove-background-button.d.ts +10 -2
- package/toolbar/image-toolbar.d.ts +32 -10
- package/toolbar/line-toolbar.d.ts +14 -10
- package/toolbar/lock-button.d.ts +6 -2
- package/toolbar/many-toolbar.d.ts +2 -2
- package/toolbar/opacity-picker.d.ts +6 -2
- package/toolbar/page-toolbar.d.ts +2 -2
- package/toolbar/position-picker.d.ts +6 -2
- package/toolbar/remove-button.d.ts +6 -2
- package/toolbar/svg-toolbar.d.ts +2 -2
- package/toolbar/table-toolbar.d.ts +44 -14
- package/toolbar/text-ai-write.d.ts +6 -2
- package/toolbar/text-toolbar.d.ts +30 -18
- package/toolbar/toolbar.d.ts +2 -2
- package/toolbar/video-toolbar.d.ts +12 -6
- package/toolbar/video-toolbar.js +1 -1
- package/toolbar/zoom-buttons.d.ts +4 -4
- package/ui.css +1 -1
- package/utils/clip-fade.d.ts +6 -0
- package/utils/clip-fade.js +1 -0
- package/utils/clipboard.d.ts +2 -2
- package/utils/fade-gradient.d.ts +33 -0
- package/utils/fade-gradient.js +1 -0
- package/utils/fade-overlay.d.ts +9 -0
- package/utils/fade-overlay.js +1 -0
- package/utils/l10n.d.ts +19 -0
- package/utils/l10n.js +1 -1
- package/utils/pointer-drag.d.ts +6 -4
- package/utils/pointer-drag.js +1 -1
- package/utils/rich-text-html.d.ts +0 -10
- package/utils/rich-text-html.js +1 -1
- package/utils/validate-key.js +1 -1
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
|
|
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{useClip as u,useCornerRadiusAndCrop as p}from"./video-element.js";import{useImageLoader as w}from"./image-element.js";import{fetchWithRetry as x}from"@polotno/core/retry";import{useWorkspaceStyle as y}from"./workspace-style.js";import{useFilteredSource as b}from"./use-filtered-source.js";import{useFadeIn as E}from"./use-fadein.js";import{isTouchDevice as v}from"../utils/screen.js";import{roundEnabledPx as S,activeAnchorOf as j,isCornerAnchor as I,scaledBoxStyleAttrs as R,roundedBoxStyleAttrs as M,roundedGeometryAttrs as O,roundedPosition as z}from"../utils/px.js";import{useEvent as C}from"../hooks/use-event.js";function T(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 D=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}=y();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})]})}),X=o(({element:r})=>{const{mediaErrorStyle:i}=y(),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[y,Y]=i.useState(!1),k=i.useRef(!1),F=o.isSelected,_=i.useRef(null),A=i.useRef(void 0),[P,B,G,L]=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 x(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);w(L,o.src,o.id),i.useEffect(()=>(A.current=document.createElement("canvas"),()=>{A.current&&g.Util.releaseCanvas(A.current)}),[]),i.useEffect(()=>{if("loaded"===L&&A.current&&(A.current.width=G.width,A.current.height=G.height,P.length>0)){const t=A.current.getContext("2d");if(t){t.clearRect(0,0,G.width,G.height);const e=document.createElement("canvas");T(P[0],A.current,e)}}},[G,L,P]),i.useEffect(()=>{var t;if(!P.length||!A.current){return}const e=A.current;e.width=G.width,e.height=G.height;const r=document.createElement("canvas"),i=e.getContext("2d");i&&i.clearRect(0,0,e.width,e.height);let n=-1;T(P[0],e,r),et(),n=0;const h=t=>{const i=(t=>{const e=t%B;let r=0;for(let i=0;i<P.length;i++){if(r+=P[i].delay,r>e){return i}}return 0})(t);i!==n&&(T(P[i],e,r),et(),_.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,P,B,null===(d=o.page)||void 0===d?void 0:d._exportingOrRendering]),i.useEffect(()=>{B&&s.history.ignore(()=>{o.set({duration:B})})},[B]);let{cropX:U,cropY:W,cropWidth:H,cropHeight:N}=o;"loaded"!==L&&(U=W=0,H=N=1);const q={x:G.width*U,y:G.height*W,width:G.width*H,height:G.height*N},J=null!==(l=o.cornerRadius)&&void 0!==l?l:0,[K,Q]=b(o,A.current),[V,Z]=p(o,K,q,s._elementsPixelRatio,J,y||o._cropModeEnabled),[$,tt]=u(o,V,s._elementsPixelRatio,[q,J]),et=C(()=>{Q(),Z(),tt()}),rt="loading"===L,it="failed"===L,ot=rt||it?0:o.a.opacity;E(_,ot);const at=o.selectable||s.role===c.ADMIN,nt=v();return e(r,{children:[rt&&t(D,{element:o}),it&&t(X,{element:o}),t(n,{ref:_,name:"element",id:o.id,image:$,x:o.a.x,y:o.a.y,width:o.a.width||1,height:o.a.height||1,rotation:o.a.rotation,opacity:ot,shadowEnabled:o.shadowEnabled,shadowBlur:o.shadowBlur,shadowOffsetX:o.shadowOffsetX,shadowOffsetY:o.shadowOffsetY,shadowColor:o.shadowColor,shadowOpacity:o.shadowOpacity,customCrop:q,listening:at,draggable:nt?o.draggable&&F:o.draggable,preventDefault:!nt||F,hideInExport:!o.showInExport,onDragMove:t=>{o.set({x:t.target.x(),y:t.target.y()})},onDragEnd:t=>{o.set(z(t.target))},onTransformStart:t=>{Y(!0),k.current=I(j(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=k.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({},R(o,a)),{borderSize:o.borderSize*a})))},onTransformEnd:()=>{o.set(Object.assign(Object.assign(Object.assign({},O(o)),M(o)),{borderSize:S(o.borderSize)})),Y(!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:ot,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,J-o.borderSize),hideInExport:!o.showInExport})]})});
|
package/canvas/highlighter.d.ts
CHANGED
|
@@ -10,7 +10,11 @@ type SimplifiedElement = {
|
|
|
10
10
|
};
|
|
11
11
|
export declare const Highlighter: (({ element }: {
|
|
12
12
|
element: SimplifiedElement;
|
|
13
|
-
}) => React.JSX.Element) & {
|
|
14
|
-
|
|
13
|
+
}) => React.JSX.Element) & React.NamedExoticComponent<{
|
|
14
|
+
element: SimplifiedElement;
|
|
15
|
+
}> & {
|
|
16
|
+
readonly type: ({ element }: {
|
|
17
|
+
element: SimplifiedElement;
|
|
18
|
+
}) => React.JSX.Element;
|
|
15
19
|
};
|
|
16
20
|
export {};
|
package/canvas/html-element.d.ts
CHANGED
|
@@ -8,6 +8,6 @@ type ShapeProps = {
|
|
|
8
8
|
element: TextElementType;
|
|
9
9
|
onClick: Function;
|
|
10
10
|
};
|
|
11
|
-
export declare const HTMLElement: (({ element, store }: ShapeProps) => React.JSX.Element) & {
|
|
12
|
-
|
|
11
|
+
export declare const HTMLElement: (({ element, store }: ShapeProps) => React.JSX.Element) & React.NamedExoticComponent<ShapeProps> & {
|
|
12
|
+
readonly type: ({ element, store }: ShapeProps) => React.JSX.Element;
|
|
13
13
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { StoreType } from '../model/store.js';
|
|
3
3
|
import { ImageElementType } from '../model/image-model.js';
|
|
4
|
+
import { type ImageStatus } from './use-image.js';
|
|
4
5
|
declare function alignToPixelGrid(element: ImageElementType, pixelRatio: number, ratio: number, enabled: boolean): {
|
|
5
6
|
x: number;
|
|
6
7
|
y: number;
|
|
@@ -50,9 +51,10 @@ type ImageProps = {
|
|
|
50
51
|
element: ImageOrSVGElementType;
|
|
51
52
|
};
|
|
52
53
|
export declare const setImageLoaderHook: (customImageLoaderHook: any) => void;
|
|
53
|
-
export declare const useCanvasImage: (src: string, crossOrigin?: "anonymous" | "use-credentials") => [HTMLImageElement | undefined,
|
|
54
|
+
export declare const useCanvasImage: (src: string, crossOrigin?: "anonymous" | "use-credentials") => [HTMLImageElement | undefined, ImageStatus];
|
|
55
|
+
export declare const useClipImage: (src: string) => readonly [HTMLImageElement | undefined, ImageStatus];
|
|
54
56
|
export declare const useImageLoader: (status: string, src?: string, id?: string) => void;
|
|
55
|
-
export declare const ImageElement: (({ element, store }: ImageProps) => React.JSX.Element) & {
|
|
56
|
-
|
|
57
|
+
export declare const ImageElement: (({ element, store }: ImageProps) => React.JSX.Element) & React.NamedExoticComponent<ImageProps> & {
|
|
58
|
+
readonly type: ({ element, store }: ImageProps) => React.JSX.Element;
|
|
57
59
|
};
|
|
58
60
|
export {};
|
package/canvas/image-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{isAlive as a}from"mobx-state-tree";import{Arc as h,Group as n,Image as s,Rect as d,Text as c}from"react-konva";import{ROLES as g}from"../model/store.js";import l from"./use-image.js";import u from"konva";import{useWorkspaceStyle as p}from"./workspace-style.js";import{incrementLoader as m,triggerLoadError as f}from"../utils/loader.js";import{polotnoError as w}from"@polotno/core/errors";import{getBorderInset as x,getCropRect as v}from"@polotno/core/image";import*as y from"@polotno/core/svg";import{trySetCanvasSize as M}from"../utils/canvas.js";import{roundEnabledPx as b,activeAnchorOf as S,roundedCropFraction as E,roundedGeometryPx as C,roundedPosition as R,isCornerAnchor as I,scaledBoxStyleAttrs as X,roundedBoxStyleAttrs as Y}from"../utils/px.js";import{useFilteredSource as j}from"./use-filtered-source.js";import{useFadeIn as H}from"./use-fadein.js";import{isTouchDevice as O}from"../utils/screen.js";import{useDelayer as W}from"./use-delayer.js";import{useColor as z}from"./use-color.js";import{commitCropSource as A,CropOverlay as D}from"./crop-overlay.js";import{drawReduced as k,exportKernelEnabled as L,shouldResample as T}from"./downscale.js";const _=1e4;function F(){return document.createElement("canvas")}const N=t=>"svg"===t.type||y.isSvgUrl(t.src||"");export const useSizeFixer=t=>{const[e,r]=i.useState(t);return i.useEffect(()=>{(async()=>{const i=y.isSvgUrl(t)?y.prepareSvgSource(await y.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}}export function svgSourceRatio(t,e,r){if(!(e.width>0&&e.height>0)){return 1}const i=Math.max(t.width/e.width*r,t.height/e.height*r),o=Math.min(t.cropWidth,t.cropHeight),a=o>0&&o<=1?Math.pow(2,Math.ceil(Math.log2(1/o))):1;return Math.min(i*a,_/Math.max(e.width,e.height),Math.sqrt(16777216/(e.width*e.height)))}export function maskCompositeSize(t,e){const r=v({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 U=(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,h=!1,n=!0,s=0,d)=>{var c;const g=_,l=_,p=d.aligned?U(d.deviceWidth,1,g):Math.floor(U(t.a.width*o,1,g)),m=d.aligned?U(d.deviceHeight,1,l):Math.floor(U(t.a.height*o,1,l)),f=Math.min(a*o,p/2,m/2),w=Math.min(s*o,p/2,m/2),x=q(t,r,o),v=L(t.page)&&!h&&(T(x,p,m)||d.aligned),y=0===r.x&&0===r.y&&r.width===(null==e?void 0:e.width)&&r.height===(null==e?void 0:e.height),b=i.useMemo(()=>{if(e&&e.width&&e.height){return!y||0!==f||v||w?F():void 0}},[e,f,v,y,w]);return i.useLayoutEffect(()=>{var i;if(!b||!e){return}M(b,p,m);const o=b.getContext("2d");if(o){if((null===(i=t.page)||void 0===i?void 0:i._exportingOrRendering)&&(o.imageSmoothingQuality="high"),(f||w)&&(o.beginPath(),o.roundRect(w,w,p-2*w,m-2*w,Math.max(0,f-w)),o.clip()),v){const t=b.width===p&&b.height===m&&d.aligned;return void k(o,e,r,b.width,b.height,{x:t?d.phaseX:0,y:t?d.phaseY:0,width:t?d.spanX:b.width,height:t?d.spanY:b.height})}o.drawImage(e,r.x,r.y,r.width,r.height,0,0,b.width,b.height)}},[b,t.a.width,t.a.height,r.x,r.y,r.width,r.height,a,o,h,null===(c=t.page)||void 0===c?void 0:c._exportingOrRendering,v,d.phaseX,d.phaseY,w]),i.useEffect(()=>()=>{b&&"CANVAS"===b.nodeName&&u.Util.releaseCanvas(b)},[b]),b||e};const B=F(),V=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 u.Animation(e=>{t.rotate(((null==e?void 0:e.timeDiff)||0)/2)},t.getLayer());return e.start(),()=>{e.stop()}});const{mediaLoadingStyle:s}=p();return e(n,{x:r.x,y:r.y,rotation:r.rotation,listening:!1,opacity:r.a.opacity,hideInExport:!r.showInExport,children:[t(d,{width:r.a.width,height:r.a.height,fill:s.fill}),t(h,{ref:a,x:r.a.width/2,y:r.a.height/2,fill:s.textFill,outerRadius:Math.abs(o),innerRadius:Math.max(1,o-5),angle:270})]})}),$=o(({element:r})=>{const{mediaErrorStyle:i}=p(),o=Math.max(10,Math.min(30,r.a.width/25));return e(n,{x:r.x,y:r.y,rotation:r.rotation,listening:!1,opacity:r.a.opacity,hideInExport:!r.showInExport,children:[t(d,{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 G=l;export const setImageLoaderHook=t=>{G=t};export const useCanvasImage=(t,e)=>G(t,e);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),h=`image with id ${r} url: ${i}`;"loading"!==t||o.current||(o.current=m(h)),"loading"!==t&&a(),"failed"===t&&f(w("IMAGE_FAILED",h,{src:i,elementId:r,reason:"load"}))},[t])};export const ImageElement=o(({element:o,store:h})=>{var n,c,l,p;const[m,f]=i.useState(!1),w=i.useRef(null),k=o.isSelected,[U,J]=(t=>{var e;const[r,o]=i.useReducer(t=>t+1,0),a=N(t),h=a?t.src+"\n"+JSON.stringify(null!==(e=t.colorsReplace)&&void 0!==e?e:null):"",n=i.useRef("loading"),s=i.useRef(""),d=i.useRef(h);return d.current!==h&&(d.current=h,n.current="loading"),i.useEffect(()=>{if(!a||!t.src){return}let e=!1;return(async()=>{const r=y.prepareSvgSource(await y.urlToString(t.src),t.colorsReplace);e||(s.current=r,n.current="loaded",o())})().catch(()=>{e||(n.current="failed",o())}),()=>{e=!0}},[h]),a?[s.current,n.current]:[t.src,"loaded"]})(o),[Q,K]=G(U,"anonymous"),Z="loaded"===J?K:J;useImageLoader(Z,o.src,o.id);const tt=(null===(n=o.page)||void 0===n?void 0:n._exportingOrRendering)?1:Math.max(1,h.scale),et=h._elementsPixelRatio*tt,rt=(({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:Q,status:Z}),it=((t,e,r)=>{const o=N(t)&&e?svgSourceRatio({cropWidth:t.a.cropWidth,cropHeight:t.a.cropHeight,width:t.a.width,height:t.a.height},e,r):1,a=i.useMemo(()=>{var r,i;const{flipX:a,flipY:h}=t,n=N(t),s=navigator.userAgent.toLowerCase().indexOf("firefox")>-1,d=(/^((?!chrome|android).)*safari/i.test(navigator.userAgent)||s)&&n||t.maskSrc;if(!a&&!h&&!d){return e}if(!e||!e.width||!e.height){return null}const c=F();M(c,Math.max(e.width*o,1),Math.max(e.height*o,1));let g=a?-c.width:0,l=h?-c.height:0;return null===(r=c.getContext("2d"))||void 0===r||r.scale(a?-1:1,h?-1:1),null===(i=c.getContext("2d"))||void 0===i||i.drawImage(e,g,l,c.width,c.height),c},[t.maskSrc,t.flipX,t.flipY,e,o]);return i.useEffect(()=>()=>{a&&"CANVAS"===a.nodeName&&u.Util.releaseCanvas(a)},[a]),a})(o,Q||rt,et),ot=((t,e)=>{const r=useSizeFixer(t.maskSrc||""),[o,a]=G(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 h=a.getContext("2d");if(!h){return e}h.drawImage(e,0,0,r,i,0,0,r,i),h.globalCompositeOperation="source-in";const n=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 h.drawImage(o,n.x,n.y,n.width,n.height,0,0,r,i),a},[e,o,t.a.width,t.a.height,t.stretchEnabled])})(o,it)||B,[at=B]=j(o,ot);let{cropX:ht,cropY:nt,cropWidth:st,cropHeight:dt}=o.a;"loaded"!==K&&(ht=nt=0,st=dt=1);const ct=v({stretchEnabled:o.stretchEnabled,cropX:ht,cropY:nt,cropWidth:st,cropHeight:dt,width:o.a.width,height:o.a.height},at),gt=ct.width,lt=ct.height,ut=o.stretchEnabled,pt=null!==(c=o.cornerRadius)&&void 0!==c?c:0,mt=(null===(l=o.page)||void 0===l?void 0:l._exportingOrRendering)?1:Math.min(2,h.scale),ft=h._elementsPixelRatio*mt,wt=m||o._cropModeEnabled||"svg"===o.type,xt=function(t,e,r,i){const{x:o,y:a,width:h,height:n}=t.a,s={x:o,y:a,width:h,height:n,deviceWidth:0,deviceHeight:0,phaseX:0,phaseY:0,spanX:0,spanY:0,aligned:!1};if(!i){return s}const d=o*e,c=a*e,g=Math.round(d),l=Math.round(c),u=Math.max(1,Math.round(d+h*e)-g),p=Math.max(1,Math.round(c+n*e)-l),m=t=>Math.abs(t-Math.round(t))>.001;return m(d)||m(c)||m(h*e)||m(n*e)?u>_||p>_?s:T(r,u,p)||r<=1&&u*p<=4e6?{x:g/e,y:l/e,width:u/e,height:p/e,deviceWidth:u,deviceHeight:p,phaseX:d-g,phaseY:c-l,spanX:h*e,spanY:n*e,aligned:!0}:s:s}(o,ft,q(o,ct,ft),L(o.page)&&0===o.a.rotation&&"group"!==(null===(p=o.parent)||void 0===p?void 0:p.type)&&!wt),vt=xt.aligned?xt:{x:o.x,y:o.y,width:o.a.width,height:o.a.height};let yt=((t,e,r,o)=>{const a=useSizeFixer(t.clipSrc||""),[h,n]=G(a,"anonymous"),s=t.clipSrc?n:"loaded";useImageLoader(s,t.clipSrc,t.id);const d=i.useMemo(()=>{if(e&&h){return F()}},[e,h]);return i.useLayoutEffect(()=>{var i;if(!h){return}if(!e||!e.width||!e.height){return}if(!h||!h.width||!h.height){return}if(!d){return}const o=F(),a=Math.max(t.a.width/h.width*r,t.a.height/h.height*r);o.width=Math.max(h.width*a,1),o.height=Math.max(h.height*a,1),null===(i=o.getContext("2d"))||void 0===i||i.drawImage(h,0,0,o.width,o.height),d.width=Math.max(e.width,1),d.height=Math.max(e.height,1);const n=d.getContext("2d");n&&(n.save(),n.drawImage(o,0,0,e.width,e.height),u.Util.releaseCanvas(o),n.globalCompositeOperation="source-in",n.drawImage(e,0,0,d.width,d.height),n.restore())},[d,e,h,t.a.width,t.a.height,r,...o]),t.clipSrc&&h?d:e})(o,useCornerRadiusAndCrop(o,at,ct,ft,pt,wt,!0,x({borderSize:o.borderSize,borderColor:o.borderColor,width:o.a.width,height:o.a.height}),xt),ft,[ct,pt,ft]);var Mt=i.useRef(null),bt=i.useRef(0),St=i.useRef(!1);const Et=()=>{o._cropEnabled&&setTimeout(()=>{a(o)&&o.toggleCropMode(!0)})},Ct=N(o)&&rt,Rt="loading"===Z&&!Ct,[It]=W(Rt,100,!1,!1),Xt="failed"===Z,Yt=!It&&!Xt,jt=i.useRef({cropX:0,cropY:0,cropWidth:0,cropHeight:0}),Ht=i.useRef(!1),Ot=Yt?o.a.opacity:0;H(w,Ot);const Wt=o.selectable||h.role===g.ADMIN,zt=O(),At=z(o,o.borderColor,"stroke");return e(r,{children:[It&&t(V,{element:o}),Xt&&t($,{element:o}),t(s,{ref:w,name:"element",id:o.id,image:yt,x:xt.x,y:xt.y,width:xt.width||1,height:xt.height||1,rotation:o.a.rotation,opacity:Ot,shadowEnabled:o.shadowEnabled,shadowBlur:o.shadowBlur,shadowOffsetX:o.shadowOffsetX,shadowOffsetY:o.shadowOffsetY,shadowColor:o.shadowColor,shadowOpacity:o.shadowOpacity,customCrop:ct,listening:Wt,draggable:zt?o.draggable&&k:o.draggable,preventDefault:!zt||k,hideInExport:!o.showInExport,onDragMove:t=>{o.set({x:t.target.x(),y:t.target.y()})},onDragEnd:t=>{o.set(R(t.target))},onDblClick:Et,onDblTap:Et,onTransformStart:t=>{f(!0),Ht.current=I(S(t.target)),jt.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-gt/at.width,h=Math.min(a,Math.max(0,o.cropX)),n=1-lt/at.height,s=Math.min(n,Math.max(0,o.cropY)),d=Ht.current,c=!d&&r<1&&jt.current.cropHeight>lt/at.height;let g=d?o.cropWidth:o.cropWidth*r;c&&(g=o.cropWidth);const l=!d&&i<1&&jt.current.cropWidth>gt/at.width;let u=d?o.cropHeight:o.cropHeight*i;l&&(u=o.cropHeight),ut&&(g=o.cropWidth,u=o.cropHeight);const p=d?Math.min(r,i):1;o.set(Object.assign({cropX:h,cropY:s,x:e.x(),y:e.y(),width:e.width()*r,height:e.height()*i,rotation:t.target.rotation(),cropWidth:Math.min(g,1-h),cropHeight:Math.min(u,1-s)},1!==p&&Object.assign(Object.assign({},X(o,p)),{borderSize:o.borderSize*p})))},onTransformEnd:t=>{const e=t.currentTarget;o.set(Object.assign(Object.assign({width:C(e.width()),height:C(e.height()),x:C(e.x()),y:C(e.y()),rotation:C(t.target.rotation()),cropX:E(o.cropX),cropY:E(o.cropY),cropWidth:E(gt/at.width),cropHeight:E(lt/at.height)},Y(o)),{borderSize:b(o.borderSize)})),f(!1)}}),t(d,Object.assign({x:vt.x,y:vt.y,width:Math.max(vt.width-o.borderSize,0),height:Math.max(vt.height-o.borderSize,0),opacity:Ot,offsetX:-o.borderSize/2,offsetY:-o.borderSize/2},At,{strokeWidth:o.borderSize,listening:!1,visible:!!o.borderSize,rotation:o.rotation,cornerRadius:Math.max(0,pt-o.borderSize),hideInExport:!o.showInExport})),o._cropModeEnabled&&t(D,{element:o,store:h,previewImage:yt,sourceImage:at,sourceWidth:at.width,sourceHeight:at.height,cropAbsoluteWidth:gt,cropAbsoluteHeight:lt,onSourceTouchMove:t=>{t.evt.preventDefault();const e=t.target.getStage().getPointersPositions();var r=e[0],i=e[1];const a=t.target;if(r&&!i&&!a.isDragging()&&St.current&&(a.startDrag(),St.current=!1),r&&i){u.hitOnDragEnabled=!0,a.isDragging()&&(St.current=!0,a.stopDrag());const e=t.target.getAbsoluteTransform().copy();e.invert();var h={x:r.x,y:r.y},n={x:i.x,y:i.y};if(!Mt.current){return void(Mt.current=P(h,n))}var s=P(h,n),d=function(t,e){return Math.sqrt(Math.pow(e.x-t.x,2)+Math.pow(e.y-t.y,2))}(h,n);bt.current||(bt.current=d);const f=a.position();var c={x:s.x-f.x,y:s.y-f.y},g=d/bt.current;a.scaleX(g),a.scaleY(g);const w=e.point(s),x=e.point(Mt.current);var l=w.x-x.x,p=w.y-x.y,m={x:Math.min(0,s.x-c.x*g+l),y:Math.min(0,s.y-c.y*g+p)};a.position(m),bt.current=d,Mt.current=s,(t=>{A(t,o,at.width,at.height,gt,lt)})(t)}},onSourceTouchEnd:t=>{bt.current=0,Mt.current=null,u.hitOnDragEnabled=!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{isAlive as a}from"mobx-state-tree";import{Arc as h,Group as n,Image as s,Rect as d,Text as c}from"react-konva";import{ROLES as g}from"../model/store.js";import l from"./use-image.js";import u from"konva";import{useWorkspaceStyle as p}from"./workspace-style.js";import{incrementLoader as m,triggerLoadError as f}from"../utils/loader.js";import{polotnoError as w}from"@polotno/core/errors";import{getBorderInset as x,getCropRect as v}from"@polotno/core/image";import*as M from"@polotno/core/svg";import{trySetCanvasSize as y}from"../utils/canvas.js";import{roundEnabledPx as b,activeAnchorOf as S,roundedCropFraction as E,roundedGeometryPx as C,roundedPosition as I,isCornerAnchor as R,scaledBoxStyleAttrs as X,roundedBoxStyleAttrs as Y}from"../utils/px.js";import{useFilteredSource as j}from"./use-filtered-source.js";import{useFadeIn as H}from"./use-fadein.js";import{isTouchDevice as O}from"../utils/screen.js";import{useDelayer as W}from"./use-delayer.js";import{useColor as z}from"./use-color.js";import{commitCropSource as A,CropOverlay as D}from"./crop-overlay.js";import{drawReduced as k,exportKernelEnabled as L,shouldResample as T}from"./downscale.js";const _=1e4;function N(){return document.createElement("canvas")}const U=t=>"svg"===t.type||M.isSvgUrl(t.src||""),F=t=>{const[e,r]=i.useState({src:"",value:"",status:"loaded"}),o=!!t&&M.isSvgUrl(t);return i.useEffect(()=>{if(!o){return}let e=!0;return(async()=>{try{const i=M.prepareSvgSource(await M.urlToString(t));e&&r({src:t,value:i,status:"loaded"})}catch(i){e&&r({src:t,value:"",status:"failed"})}})(),()=>{e=!1}},[t,o]),o?[e.value,e.src===t?e.status:"loading"]:[t,"loaded"]};export const useSizeFixer=t=>F(t)[0]||t;function P(t,e){return{x:(t.x+e.x)/2,y:(t.y+e.y)/2}}export function svgSourceRatio(t,e,r){if(!(e.width>0&&e.height>0)){return 1}const i=Math.max(t.width/e.width*r,t.height/e.height*r),o=Math.min(t.cropWidth,t.cropHeight),a=o>0&&o<=1?Math.pow(2,Math.ceil(Math.log2(1/o))):1;return Math.min(i*a,_/Math.max(e.width,e.height),Math.sqrt(16777216/(e.width*e.height)))}export function maskCompositeSize(t,e){const r=v({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 q=(t,e,r)=>Math.max(e,Math.min(r,t)),B=(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,h=!1,n=!0,s=0,d)=>{var c;const g=_,l=_,p=d.aligned?q(d.deviceWidth,1,g):Math.floor(q(t.a.width*o,1,g)),m=d.aligned?q(d.deviceHeight,1,l):Math.floor(q(t.a.height*o,1,l)),f=Math.min(a*o,p/2,m/2),w=Math.min(s*o,p/2,m/2),x=B(t,r,o),v=L(t.page)&&!h&&(T(x,p,m)||d.aligned),M=0===r.x&&0===r.y&&r.width===(null==e?void 0:e.width)&&r.height===(null==e?void 0:e.height),b=i.useMemo(()=>{if(e&&e.width&&e.height){return!M||0!==f||v||w?N():void 0}},[e,f,v,M,w]);return i.useLayoutEffect(()=>{var i;if(!b||!e){return}y(b,p,m);const o=b.getContext("2d");if(o){if((null===(i=t.page)||void 0===i?void 0:i._exportingOrRendering)&&(o.imageSmoothingQuality="high"),(f||w)&&(o.beginPath(),o.roundRect(w,w,p-2*w,m-2*w,Math.max(0,f-w)),o.clip()),v){const t=b.width===p&&b.height===m&&d.aligned;return void k(o,e,r,b.width,b.height,{x:t?d.phaseX:0,y:t?d.phaseY:0,width:t?d.spanX:b.width,height:t?d.spanY:b.height})}o.drawImage(e,r.x,r.y,r.width,r.height,0,0,b.width,b.height)}},[b,t.a.width,t.a.height,r.x,r.y,r.width,r.height,a,o,h,null===(c=t.page)||void 0===c?void 0:c._exportingOrRendering,v,d.phaseX,d.phaseY,w]),i.useEffect(()=>()=>{b&&"CANVAS"===b.nodeName&&u.Util.releaseCanvas(b)},[b]),b||e};const V=N(),$=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 u.Animation(e=>{t.rotate(((null==e?void 0:e.timeDiff)||0)/2)},t.getLayer());return e.start(),()=>{e.stop()}});const{mediaLoadingStyle:s}=p();return e(n,{x:r.x,y:r.y,rotation:r.rotation,listening:!1,opacity:r.a.opacity,hideInExport:!r.showInExport,children:[t(d,{width:r.a.width,height:r.a.height,fill:s.fill}),t(h,{ref:a,x:r.a.width/2,y:r.a.height/2,fill:s.textFill,outerRadius:Math.abs(o),innerRadius:Math.max(1,o-5),angle:270})]})}),G=o(({element:r})=>{const{mediaErrorStyle:i}=p(),o=Math.max(10,Math.min(30,r.a.width/25));return e(n,{x:r.x,y:r.y,rotation:r.rotation,listening:!1,opacity:r.a.opacity,hideInExport:!r.showInExport,children:[t(d,{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 J=l;export const setImageLoaderHook=t=>{J=t};export const useCanvasImage=(t,e)=>J(t,e);export const useClipImage=t=>{const[e,r]=F(t),[o,a]=useCanvasImage(e,"anonymous"),h="loaded"===r?a:r,n=i.useRef(void 0);return t&&"failed"!==h?o&&(n.current=o):n.current=void 0,[t&&"failed"!==h?o||n.current:void 0,h]};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),h=`image with id ${r} url: ${i}`;"loading"!==t||o.current||(o.current=m(h)),"loading"!==t&&a(),"failed"===t&&f(w("IMAGE_FAILED",h,{src:i,elementId:r,reason:"load"}))},[t])};export const ImageElement=o(({element:o,store:h})=>{var n,c,l,p;const[m,f]=i.useState(!1),w=i.useRef(null),k=o.isSelected,[q,Q]=(t=>{var e;const[r,o]=i.useReducer(t=>t+1,0),a=U(t),h=a?t.src+"\n"+JSON.stringify(null!==(e=t.colorsReplace)&&void 0!==e?e:null):"",n=i.useRef("loading"),s=i.useRef(""),d=i.useRef(h);return d.current!==h&&(d.current=h,n.current="loading"),i.useEffect(()=>{if(!a||!t.src){return}let e=!1;return(async()=>{const r=M.prepareSvgSource(await M.urlToString(t.src),t.colorsReplace);e||(s.current=r,n.current="loaded",o())})().catch(()=>{e||(n.current="failed",o())}),()=>{e=!0}},[h]),a?[s.current,n.current]:[t.src,"loaded"]})(o),[K,Z]=J(q,"anonymous"),tt="loaded"===Q?Z:Q;useImageLoader(tt,o.src,o.id);const et=(null===(n=o.page)||void 0===n?void 0:n._exportingOrRendering)?1:Math.max(1,h.scale),rt=h._elementsPixelRatio*et,it=(({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:K,status:tt}),ot=((t,e,r)=>{const o=U(t)&&e?svgSourceRatio({cropWidth:t.a.cropWidth,cropHeight:t.a.cropHeight,width:t.a.width,height:t.a.height},e,r):1,a=i.useMemo(()=>{var r,i;const{flipX:a,flipY:h}=t,n=U(t),s=navigator.userAgent.toLowerCase().indexOf("firefox")>-1,d=(/^((?!chrome|android).)*safari/i.test(navigator.userAgent)||s)&&n||t.maskSrc;if(!a&&!h&&!d){return e}if(!e||!e.width||!e.height){return null}const c=N();y(c,Math.max(e.width*o,1),Math.max(e.height*o,1));let g=a?-c.width:0,l=h?-c.height:0;return null===(r=c.getContext("2d"))||void 0===r||r.scale(a?-1:1,h?-1:1),null===(i=c.getContext("2d"))||void 0===i||i.drawImage(e,g,l,c.width,c.height),c},[t.maskSrc,t.flipX,t.flipY,e,o]);return i.useEffect(()=>()=>{a&&"CANVAS"===a.nodeName&&u.Util.releaseCanvas(a)},[a]),a})(o,K||it,rt),at=((t,e)=>{const[r,o]=F(t.maskSrc||""),[a,h]=J(r,"anonymous"),n=t.maskSrc?"loaded"===o?h:o:"loaded";return useImageLoader(n,t.maskSrc||"",t.id),i.useMemo(()=>{if(!a){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}),o=N();o.width=r,o.height=i;const h=o.getContext("2d");if(!h){return e}h.drawImage(e,0,0,r,i,0,0,r,i),h.globalCompositeOperation="source-in";const n=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}}(a,t);return h.drawImage(a,n.x,n.y,n.width,n.height,0,0,r,i),o},[e,a,t.a.width,t.a.height,t.stretchEnabled])})(o,ot)||V,[ht=V]=j(o,at);let{cropX:nt,cropY:st,cropWidth:dt,cropHeight:ct}=o.a;"loaded"!==Z&&(nt=st=0,dt=ct=1);const gt=v({stretchEnabled:o.stretchEnabled,cropX:nt,cropY:st,cropWidth:dt,cropHeight:ct,width:o.a.width,height:o.a.height},ht),lt=gt.width,ut=gt.height,pt=o.stretchEnabled,mt=null!==(c=o.cornerRadius)&&void 0!==c?c:0,ft=(null===(l=o.page)||void 0===l?void 0:l._exportingOrRendering)?1:Math.min(2,h.scale),wt=h._elementsPixelRatio*ft,xt=m||o._cropModeEnabled||"svg"===o.type,vt=function(t,e,r,i){const{x:o,y:a,width:h,height:n}=t.a,s={x:o,y:a,width:h,height:n,deviceWidth:0,deviceHeight:0,phaseX:0,phaseY:0,spanX:0,spanY:0,aligned:!1};if(!i){return s}const d=o*e,c=a*e,g=Math.round(d),l=Math.round(c),u=Math.max(1,Math.round(d+h*e)-g),p=Math.max(1,Math.round(c+n*e)-l),m=t=>Math.abs(t-Math.round(t))>.001;return m(d)||m(c)||m(h*e)||m(n*e)?u>_||p>_?s:T(r,u,p)||r<=1&&u*p<=4e6?{x:g/e,y:l/e,width:u/e,height:p/e,deviceWidth:u,deviceHeight:p,phaseX:d-g,phaseY:c-l,spanX:h*e,spanY:n*e,aligned:!0}:s:s}(o,wt,B(o,gt,wt),L(o.page)&&0===o.a.rotation&&"group"!==(null===(p=o.parent)||void 0===p?void 0:p.type)&&!xt),Mt=vt.aligned?vt:{x:o.x,y:o.y,width:o.a.width,height:o.a.height};let yt=((t,e,r,o)=>{const[a,h]=useClipImage(t.clipSrc||""),n=t.clipSrc?h:"loaded";useImageLoader(n,t.clipSrc,t.id);const s=i.useMemo(()=>{if(e&&a){return N()}},[e,a]);return i.useLayoutEffect(()=>{var i;if(!a){return}if(!e||!e.width||!e.height){return}if(!a||!a.width||!a.height){return}if(!s){return}const o=N(),h=Math.max(t.a.width/a.width*r,t.a.height/a.height*r);y(o,Math.min(1e4,Math.max(a.width*h,1)),Math.min(1e4,Math.max(a.height*h,1))),null===(i=o.getContext("2d"))||void 0===i||i.drawImage(a,0,0,o.width,o.height),y(s,Math.min(1e4,Math.max(e.width,Math.ceil(t.a.width*r),1)),Math.min(1e4,Math.max(e.height,Math.ceil(t.a.height*r),1)));const n=s.getContext("2d");n&&(n.save(),n.drawImage(o,0,0,s.width,s.height),u.Util.releaseCanvas(o),n.globalCompositeOperation="source-in",n.drawImage(e,0,0,s.width,s.height),n.restore())},[s,e,a,t.a.width,t.a.height,r,...o]),i.useEffect(()=>()=>{s&&u.Util.releaseCanvas(s)},[s]),t.clipSrc&&a?s:e})(o,useCornerRadiusAndCrop(o,ht,gt,wt,mt,xt,!0,x({borderSize:o.borderSize,borderColor:o.borderColor,width:o.a.width,height:o.a.height}),vt),wt,[gt,mt,wt]);var bt=i.useRef(null),St=i.useRef(0),Et=i.useRef(!1);const Ct=()=>{o._cropEnabled&&setTimeout(()=>{a(o)&&o.toggleCropMode(!0)})},It=U(o)&&it,Rt="loading"===tt&&!It,[Xt]=W(Rt,100,!1,!1),Yt="failed"===tt,jt=!Xt&&!Yt,Ht=i.useRef({cropX:0,cropY:0,cropWidth:0,cropHeight:0}),Ot=i.useRef(!1),Wt=jt?o.a.opacity:0;H(w,Wt);const zt=o.selectable||h.role===g.ADMIN,At=O(),Dt=z(o,o.borderColor,"stroke");return e(r,{children:[Xt&&t($,{element:o}),Yt&&t(G,{element:o}),t(s,{ref:w,name:"element",id:o.id,image:yt,x:vt.x,y:vt.y,width:vt.width||1,height:vt.height||1,rotation:o.a.rotation,opacity:Wt,shadowEnabled:o.shadowEnabled,shadowBlur:o.shadowBlur,shadowOffsetX:o.shadowOffsetX,shadowOffsetY:o.shadowOffsetY,shadowColor:o.shadowColor,shadowOpacity:o.shadowOpacity,customCrop:gt,listening:zt,draggable:At?o.draggable&&k:o.draggable,preventDefault:!At||k,hideInExport:!o.showInExport,onDragMove:t=>{o.set({x:t.target.x(),y:t.target.y()})},onDragEnd:t=>{o.set(I(t.target))},onDblClick:Ct,onDblTap:Ct,onTransformStart:t=>{f(!0),Ot.current=R(S(t.target)),Ht.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-lt/ht.width,h=Math.min(a,Math.max(0,o.cropX)),n=1-ut/ht.height,s=Math.min(n,Math.max(0,o.cropY)),d=Ot.current,c=!d&&r<1&&Ht.current.cropHeight>ut/ht.height;let g=d?o.cropWidth:o.cropWidth*r;c&&(g=o.cropWidth);const l=!d&&i<1&&Ht.current.cropWidth>lt/ht.width;let u=d?o.cropHeight:o.cropHeight*i;l&&(u=o.cropHeight),pt&&(g=o.cropWidth,u=o.cropHeight);const p=d?Math.min(r,i):1;o.set(Object.assign({cropX:h,cropY:s,x:e.x(),y:e.y(),width:e.width()*r,height:e.height()*i,rotation:t.target.rotation(),cropWidth:Math.min(g,1-h),cropHeight:Math.min(u,1-s)},1!==p&&Object.assign(Object.assign({},X(o,p)),{borderSize:o.borderSize*p})))},onTransformEnd:t=>{const e=t.currentTarget;o.set(Object.assign(Object.assign({width:C(e.width()),height:C(e.height()),x:C(e.x()),y:C(e.y()),rotation:C(t.target.rotation()),cropX:E(o.cropX),cropY:E(o.cropY),cropWidth:E(lt/ht.width),cropHeight:E(ut/ht.height)},Y(o)),{borderSize:b(o.borderSize)})),f(!1)}}),t(d,Object.assign({x:Mt.x,y:Mt.y,width:Math.max(Mt.width-o.borderSize,0),height:Math.max(Mt.height-o.borderSize,0),opacity:Wt,offsetX:-o.borderSize/2,offsetY:-o.borderSize/2},Dt,{strokeWidth:o.borderSize,listening:!1,visible:!!o.borderSize,rotation:o.rotation,cornerRadius:Math.max(0,mt-o.borderSize),hideInExport:!o.showInExport})),o._cropModeEnabled&&t(D,{element:o,store:h,previewImage:yt,sourceImage:ht,sourceWidth:ht.width,sourceHeight:ht.height,cropAbsoluteWidth:lt,cropAbsoluteHeight:ut,onSourceTouchMove:t=>{t.evt.preventDefault();const e=t.target.getStage().getPointersPositions();var r=e[0],i=e[1];const a=t.target;if(r&&!i&&!a.isDragging()&&Et.current&&(a.startDrag(),Et.current=!1),r&&i){u.hitOnDragEnabled=!0,a.isDragging()&&(Et.current=!0,a.stopDrag());const e=t.target.getAbsoluteTransform().copy();e.invert();var h={x:r.x,y:r.y},n={x:i.x,y:i.y};if(!bt.current){return void(bt.current=P(h,n))}var s=P(h,n),d=function(t,e){return Math.sqrt(Math.pow(e.x-t.x,2)+Math.pow(e.y-t.y,2))}(h,n);St.current||(St.current=d);const f=a.position();var c={x:s.x-f.x,y:s.y-f.y},g=d/St.current;a.scaleX(g),a.scaleY(g);const w=e.point(s),x=e.point(bt.current);var l=w.x-x.x,p=w.y-x.y,m={x:Math.min(0,s.x-c.x*g+l),y:Math.min(0,s.y-c.y*g+p)};a.position(m),St.current=d,bt.current=s,(t=>{A(t,o,ht.width,ht.height,lt,ut)})(t)}},onSourceTouchEnd:t=>{St.current=0,bt.current=null,u.hitOnDragEnabled=!1}})]})});
|
package/canvas/line-element.d.ts
CHANGED
|
@@ -22,7 +22,7 @@ export declare function getLinePositionFromMiddlePoints(middleLeft: any, middleR
|
|
|
22
22
|
height: any;
|
|
23
23
|
rotation: number;
|
|
24
24
|
};
|
|
25
|
-
export declare const LineElement: (({ element, store }: LineProps) => React.JSX.Element) & {
|
|
26
|
-
|
|
25
|
+
export declare const LineElement: (({ element, store }: LineProps) => React.JSX.Element) & React.NamedExoticComponent<LineProps> & {
|
|
26
|
+
readonly type: ({ element, store }: LineProps) => React.JSX.Element;
|
|
27
27
|
};
|
|
28
28
|
export {};
|
|
@@ -5,6 +5,18 @@ export declare const PageControls: (({ store, page, xPadding, yPadding, layout,
|
|
|
5
5
|
xPadding: number;
|
|
6
6
|
yPadding: number;
|
|
7
7
|
layout?: "vertical" | "horizontal";
|
|
8
|
-
}) => import("react").JSX.Element | null) & {
|
|
9
|
-
|
|
8
|
+
}) => import("react").JSX.Element | null) & import("react").NamedExoticComponent<{
|
|
9
|
+
store: StoreType;
|
|
10
|
+
page: PageType;
|
|
11
|
+
xPadding: number;
|
|
12
|
+
yPadding: number;
|
|
13
|
+
layout?: "vertical" | "horizontal";
|
|
14
|
+
}> & {
|
|
15
|
+
readonly type: ({ store, page, xPadding, yPadding, layout, }: {
|
|
16
|
+
store: StoreType;
|
|
17
|
+
page: PageType;
|
|
18
|
+
xPadding: number;
|
|
19
|
+
yPadding: number;
|
|
20
|
+
layout?: "vertical" | "horizontal";
|
|
21
|
+
}) => import("react").JSX.Element | null;
|
|
10
22
|
};
|
package/canvas/page.d.ts
CHANGED
|
@@ -57,7 +57,7 @@ type PageProps = {
|
|
|
57
57
|
right?: number;
|
|
58
58
|
};
|
|
59
59
|
};
|
|
60
|
-
declare const _default: (({ store, page, width, height, pageControlsEnabled, components, altCloneEnabled, groupSelectionMode, viewportSize, layout, tooltipSafeArea, transformerSafeArea, }: PageProps) => React.JSX.Element) & {
|
|
61
|
-
|
|
60
|
+
declare const _default: (({ store, page, width, height, pageControlsEnabled, components, altCloneEnabled, groupSelectionMode, viewportSize, layout, tooltipSafeArea, transformerSafeArea, }: PageProps) => React.JSX.Element) & React.NamedExoticComponent<PageProps> & {
|
|
61
|
+
readonly type: ({ store, page, width, height, pageControlsEnabled, components, altCloneEnabled, groupSelectionMode, viewportSize, layout, tooltipSafeArea, transformerSafeArea, }: PageProps) => React.JSX.Element;
|
|
62
62
|
};
|
|
63
63
|
export default _default;
|
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 m,Label as h,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{useWorkspaceStyle as E}from"./workspace-style.js";import{ROLES as X}from"../model/store.js";import Y from"konva";import S from"./element.js";import{DrawingLayer as k}from"./drawing-layer.js";import{ensureDragOrder as A,useSnap as M}from"./use-transformer-snap.js";import{useCanvasImage as I,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 B,getCorners as C,getTotalClientRect as T,polygonsIntersect as W}from"../utils/math.js";import{pxToUnitRounded as G,pxToUnitString as L}from"../utils/unit.js";import{isCornerAnchor as F,MAIN_TRANSFORMER_NAME as V,textMinResizeWidth as z,textMinWidthIsMeasured as U}from"../utils/px.js";import{restoreHeldPoint as Z}from"./transform-box.js";import{flags as _}from"../utils/flags.js";import{useColor as H}from"./use-color.js";import{isGradient as J}from"@polotno/core/gradient";import{Html as N}from"react-konva-utils";import{observerBatching as K}from"mobx-react-lite";const $=e=>w.batchedUpdates(e,null);K(e=>{w.isAlreadyRendering()?queueMicrotask(()=>$(e)):$(e)});const Q=Y.DD._drag;window.removeEventListener("mousemove",Q),Y.DD._drag=function(e){a(()=>{Q.call(this,e)})},window.addEventListener("mousemove",Y.DD._drag);const q={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},ee=e=>{const t=(e%180+180)%180;return t<.1||180-t<.1},te=e=>{if(!e.length){return null}const t=ee(e[0].rotation)?0:e[0].rotation;return e.every(e=>ee(e.rotation-t))?t:null},ne=e=>e.selectedShapes.filter(e=>!e._cropModeEnabled),ie={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){ie[e]=ie[e]||t,Object.assign(ie[e],t)}const oe=e=>t(f,Object.assign({},e,{preventDefault:!1})),re=n=>{var{url:i}=n,o=e(n,["url"]);const[r,l]=I(i,"anonymous"),s=r?P(r,{width:o.width,height:o.height},"center-middle"):{};return O(l,i,"page background"),t(m,Object.assign({image:r},o,s))},le=e=>{const n=H({a:{width:e.width,height:e.height},width:e.width,height:e.height},e.fill);return t(f,Object.assign({},e,n))},se=i=>{const{background:r,scale:l,borderColor:s,transparencyBackgroundColor:a}=i,d=e(i,["background","scale","borderColor","transparencyBackgroundColor"]),c=o.useMemo(()=>!!Y.Util.colorToRGBA(r)||J(r),[r]),m=o.useMemo(()=>{if(J(r)){return!0}const e=Y.Util.colorToRGBA(r);return!e||e.a<1},[r]),h=o.useMemo(()=>{if(!m||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},[m,a]);return n(o.Fragment,{children:[m&&t(f,a?Object.assign({fill:a},d,{hideInExport:!0}):Object.assign({fillPatternImage:h},d,{opacity:.1,hideInExport:!0})),c?t(le,Object.assign({fill:r},d)):t(re,Object.assign({url:r},d))]})},ae=r(({selection:e})=>{const{selectionRectStyle:n}=E();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 de(e){let t=180*e/Math.PI;return t%=360,t>180?t-=360:t<-180&&(t+=360),Math.round(t)}const ce=r(({x:e,y:o,width:r,height:l,rotation:s,anchor:a,store:d})=>{const{transformLabelStyle:c}=E();if(void 0===e||void 0===o||void 0===r||void 0===l||void 0===s||void 0===a){return null}const m=B({x:e,y:o,width:r,height:l,rotation:Y.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(h,{x:(m.minX+m.maxX)/2+u,y:(m.minY+m.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:de(s).toString()+"°"})]}),n(h,{x:(m.minX+m.maxX)/2,y:m.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})]})]})}),me=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(S,{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 ue=atob("UG9sb3RubyBmcmVlIGxpY2Vuc2UgbGltaXRhdGlvbiBleGNlZWRlZCAtIFBsZWFzZSB1cGdyYWRlIHlvdXIgYWNjb3VudC4="),ge=atob("I2MwMzkyYg=="),fe=atob("djAuOS4y"),pe=e=>t(i,{children:n(h,{fill:ge,height:200,children:[t(v,{fill:ge}),t(b,Object.assign({},e,{fill:"white",text:ue,height:void 0,padding:10,fontSize:20}))]})}),xe=atob("RlJFRSAgVFJJQUwgIExJQ0VOU0U="),ve=(atob("UG93ZXJlZCBieSBQb2xvdG5v"),atob("TElDRU5TRSAgS0VZICBJUyAgTUlTU0lORw==")),be=atob("UGxlYXNlIGFjdGl2YXRlIHlvdXIgbGljZW5zZS4KTGljZW5zZSByZWxhdGVkIHF1ZXN0aW9uczoKcG9sb3Ruby5jb20vY29udGFjdA=="),ye=e=>{const i=1===j(),o=i?ve:xe,r=i?230:195;return n(c,Object.assign({},e,{listening:!1,children:[t(f,{fill:ge,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:be,fill:"rgba(0,0,0,0.6)",fontSize:14,y:30,listening:!1})]}))};export default r(({store:i,page:r,width:a,height:m,pageControlsEnabled:w,components:Y,altCloneEnabled:S,groupSelectionMode:I="drill",viewportSize:O,layout:P="vertical",tooltipSafeArea:G,transformerSafeArea:H})=>{var J,K;const $=E(),Q=$.transformerStyle,re=q,le=r.computedBleed,de=i.bleedVisible?le:d,ue=r.computedWidth+de.left+de.right,ge=r.computedHeight+de.top+de.bottom,xe=(a-ue*i.scale)/2,ve=(m-ge*i.scale)/2,be=o.useRef(null),we=o.useRef(null),Ee=o.useRef(null),Xe=o.useRef(null),Ye=null==w||w,Se=o.useRef(!1),[ke,Ae]=o.useState(null),[Me,Ie]=o.useState({}),[Oe,Pe]=o.useState(0),Re=useContextMenu({store:i}),je=i.selectedElements.find(e=>e._cropModeEnabled),De=i.selectedElements.find(e=>e.curveEnabled),Be=i.selectedShapes.filter(e=>!e.resizable).length>0,Ce=i.selectedShapes.filter(e=>!e.draggable).length>0,Te=i.selectedElements.filter(e=>!e.visible).length>0,We=ne(i),Ge=1!==i.selectedElements.length||"group"===(null===(J=i.selectedElements[0])||void 0===J?void 0:J.type),Le=null!==(K=te(We))&&void 0!==K?K:0,Fe=e=>Ge&&We.length>0&&We.every(t=>((e,t,n)=>{if(!ee(e.rotation-n)){return!1}switch(e.type){case"text":return"x"===t&&!U(e);case"figure":case"video":case"table":return!0;case"image":case"svg":case"gif":return!e.keepRatio;default:return!1}})(t,e,Le)),Ve=!Ge&&i.selectedElements[0].keepRatio,ze=Fe("x"),Ue=Fe("y"),Ze=()=>{var t,n,o;const r=be.current;if(!r){return[]}const l=r.getStage();if(!l){return[]}const s=ne(i),a=s.map(e=>l.findOne("#"+e.id)).filter(e=>!!e),d=1===i.selectedElements.length,c=d&&(null===(t=i.selectedElements[0])||void 0===t?void 0:t.type)||"many",m=ie[c],h=Object.assign(Object.assign({},re),m||{});m&&("svg"!==c&&"image"!==c&&"gif"!==c||i.selectedElements[0].keepRatio||(h.enabledAnchors=re.enabledAnchors),"text"===c&&_.textVerticalResizeEnabled&&(h.enabledAnchors=null===(n=ie.text.enabledAnchors)||void 0===n?void 0:n.concat(["bottom-center","top-center"])),"text"===c&&d&&i.selectedElements[0].curveEnabled&&(h.enabledAnchors=ie.many.enabledAnchors)),(ze||Ue)&&(h.enabledAnchors=[...h.enabledAnchors||[],...ze?["middle-left","middle-right"]:[],...Ue?["top-center","bottom-center"]:[]]);const{boundBoxFunc:u}=Q,g=e(Q,["boundBoxFunc"]);r.setAttrs(Object.assign(Object.assign(Object.assign({},h),g),{name:V})),Be&&r.enabledAnchors([]),Ce&&r.rotateEnabled(!1);const f=r.nodes();if(f.length===a.length&&a.every((e,t)=>f[t]===e)||r.nodes(a),Ge&&a.length){const e=te(s);null===e||ee(r.rotation()-e)||(r.rotation(e),r.forceUpdate())}return null===(o=r.getLayer())||void 0===o||o.batchDraw(),a};o.useLayoutEffect(()=>{var e;if(null===(e=be.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()}),A())},[i.selectedShapes,je,Be,Te,Ce,De,ze,Ue,Ve,Le,Q]);const _e=()=>{var e,t;const n=be.current;if(!n){return}if(!n.isTransforming()){return void Ie({})}if(!n.nodes().length||!n.isTransforming()){return}const i=n.__getNodeRect(),o=null==n?void 0:n.getActiveAnchor(),r=n.getStage();Ie({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})},He=o.useCallback(()=>{var e;if(null===(e=be.current)||void 0===e?void 0:e.isTransforming()){return}const t=be.current;if(!t||!t.nodes().length){return void Pe(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),m=-Math.cos(t)*(d+n),h=c*Math.cos(a)-m*Math.sin(a),u=c*Math.sin(a)+m*Math.cos(a);return{x:o+h,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 m of[180,270,90]){if(c(d(m))){return m}}return 0}(n,{top:(null==H?void 0:H.top)||0,bottom:m-((null==H?void 0:H.bottom)||0),left:(null==H?void 0:H.left)||0,right:a-((null==H?void 0:H.right)||0)},Q.rotateAnchorOffset,t.rotation());Pe(i)},[H,a,m]);o.useEffect(()=>{var e;null===(e=be.current)||void 0===e||e.update(),_e(),He()},[i.scale,He]),o.useEffect(()=>{He()},[i.selectedShapes,He]);const Je=l(()=>({visible:!1,x1:0,y1:0,x2:0,y2:0})),Ne=o.useRef(!1),Ke=s(e=>{var t,n,o,r,l,s,a;if(i.role===X.VIEWER){return}Ne.current=!1;const d=e.target.findAncestor(".elements-container"),c=e.target.findAncestor("Transformer"),m=e.target.findAncestor(".page-abs-container");if(d||c||m){return}const h=null===(t=e.target.getStage())||void 0===t?void 0:t.getPointerPosition();h&&(h.x-=null!==(o=null===(n=e.target.getStage())||void 0===n?void 0:n.x())&&void 0!==o?o:0,h.y-=null!==(l=null===(r=e.target.getStage())||void 0===r?void 0:r.y())&&void 0!==l?l:0,Je.visible=!0,Je.x1=h.x,Je.y1=h.y,Je.x2=h.x,Je.y2=h.y,(null!==(a=null===(s=e.target.getStage())||void 0===s?void 0:s.getPointersPositions().length)&&void 0!==a?a:0)>=2&&(Je.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:Ee,containerRef:Xe,viewportSize:O}),o.useEffect(()=>{const e=s(e=>{var t,n,i,o,r,l;if(!Je.visible){return}null===(t=Ee.current)||void 0===t||t.setPointersPositions(e);let s=null===(n=Ee.current)||void 0===n?void 0:n.getPointerPosition();s?(s.x-=null!==(o=null===(i=Ee.current)||void 0===i?void 0:i.x())&&void 0!==o?o:0,s.y-=null!==(l=null===(r=Ee.current)||void 0===r?void 0:r.y())&&void 0!==l?l:0):s={x:Je.x2,y:Je.y2},Je.x2=s.x,Je.y2=s.y}),t=s(()=>{if(!Je.visible){return}if(!Ee.current){return}const e=Ee.current.findOne(".selection"),t=e?e.getClientRect({skipStroke:!0}):{width:0,height:0,x:0,y:0};if(t.width&&t.height){const e=[{x:t.x,y:t.y},{x:t.x+t.width,y:t.y},{x:t.x+t.width,y:t.y+t.height},{x:t.x,y:t.y+t.height}],n=[];Ee.current.find(".element").forEach(t=>{var o;const r=i.getElementById(t.id()),l=null==r?void 0:r.draggable,s=null==r?void 0:r.selectable;if(!l||!s){return}const a=null===(o=t.getParent())||void 0===o?void 0:o.getAbsoluteTransform();if(!a){return}const d=C(r.a).map(e=>a.point(e));W(e,d)&&n.push(r.top.id)});const o=[...new Set(n)];Ne.current=!0,i.selectElements(o)}Je.visible=!1});return window.addEventListener("mousemove",e),window.addEventListener("touchmove",e),window.addEventListener("mouseup",t,{capture:!0}),window.addEventListener("touchend",t,{capture:!0}),()=>{window.removeEventListener("mousemove",e),window.removeEventListener("touchmove",e),window.removeEventListener("mouseup",t),window.removeEventListener("touchend",t)}},[]);const $e=o.useCallback(e=>{if(!i.selectedElements[0]){return}if(e&&i.selectedElementsIds.includes(e)){return}const t=T(i.selectedShapes),n=e?i.getElementById(e):{x:0,y:0,width:r.computedWidth,height:r.computedHeight,rotation:0},o=B(n),l=[];t.minX>o.maxX&&l.push({distance:t.minX-o.maxX,box1:t,box2:o,points:[{x:t.minX,y:t.minY+t.height/2},{x:o.maxX,y:t.minY+t.height/2},{x:o.maxX,y:o.minY+o.height/2}]}),t.maxX<o.minX&&l.push({distance:o.minX-t.maxX,box1:t,box2:o,points:[{x:t.maxX,y:t.minY+t.height/2},{x:o.minX,y:t.minY+t.height/2},{x:o.minX,y:o.minY+o.height/2}]}),t.minY>o.maxY&&l.push({box1:t,box2:o,distance:t.minY-o.maxY,points:[{x:t.minX+t.width/2,y:t.minY},{x:t.minX+t.width/2,y:o.maxY},{x:o.minX+o.width/2,y:o.maxY}]}),t.maxY<o.minY&&l.push({box1:t,box2:o,distance:o.minY-t.maxY,points:[{x:t.minX+t.width/2,y:t.maxY},{x:t.minX+t.width/2,y:o.minY},{x:o.minX+o.width/2,y:o.minY}]});const s=t.minX>=o.minX&&t.maxX<=o.maxX&&t.minY>=o.minY&&t.maxY<=o.maxY;if(s&&(l.push({distance:t.minX-o.minX,box1:t,box2:o,points:[{x:t.minX,y:t.minY+t.height/2},{x:o.minX,y:t.minY+t.height/2},{x:o.minX,y:o.minY+o.height/2}]}),l.push({distance:o.maxX-t.maxX,box1:t,box2:o,points:[{x:t.maxX,y:t.minY+t.height/2},{x:o.maxX,y:t.minY+t.height/2},{x:o.maxX,y:o.minY+o.height/2}]}),l.push({box1:t,box2:o,distance:t.minY-o.minY,points:[{x:t.minX+t.width/2,y:t.minY},{x:t.minX+t.width/2,y:o.minY},{x:o.minX+o.width/2,y:o.minY}]}),l.push({box1:t,box2:o,distance:o.maxY-t.maxY,points:[{x:t.minX+t.width/2,y:t.maxY},{x:t.minX+t.width/2,y:o.maxY},{x:o.minX+o.width/2,y:o.maxY}]})),0===l.length&&!s){const e=t.minX<o.maxX&&t.maxX>o.minX,n=t.minY<o.maxY&&t.maxY>o.minY;if(e&&n){const e=(Math.max(t.minY,o.minY)+Math.min(t.maxY,o.maxY))/2,n=(Math.max(t.minX,o.minX)+Math.min(t.maxX,o.maxX))/2;t.minX<o.minX?l.push({distance:o.minX-t.minX,box1:t,box2:o,points:[{x:t.minX,y:e},{x:o.minX,y:e},{x:o.minX,y:e}]}):l.push({distance:t.minX-o.minX,box1:t,box2:o,points:[{x:t.minX,y:e},{x:o.minX,y:e},{x:o.minX,y:e}]}),t.maxX>o.maxX?l.push({distance:t.maxX-o.maxX,box1:t,box2:o,points:[{x:o.maxX,y:e},{x:t.maxX,y:e},{x:o.maxX,y:e}]}):l.push({distance:o.maxX-t.maxX,box1:t,box2:o,points:[{x:t.maxX,y:e},{x:o.maxX,y:e},{x:o.maxX,y:e}]}),t.minY<o.minY?l.push({box1:t,box2:o,distance:o.minY-t.minY,points:[{x:n,y:t.minY},{x:n,y:o.minY},{x:n,y:o.minY}]}):l.push({box1:t,box2:o,distance:t.minY-o.minY,points:[{x:n,y:t.minY},{x:n,y:o.minY},{x:n,y:o.minY}]}),t.maxY>o.maxY?l.push({box1:t,box2:o,distance:t.maxY-o.maxY,points:[{x:n,y:o.maxY},{x:n,y:t.maxY},{x:n,y:o.maxY}]}):l.push({box1:t,box2:o,distance:o.maxY-t.maxY,points:[{x:n,y:t.maxY},{x:n,y:o.maxY},{x:n,y:o.maxY}]})}}JSON.stringify(ke)!==JSON.stringify(l)&&Ae(l)},[i,r]);o.useEffect(()=>{i.selectedElements[0]&&i.distanceGuidesVisible?$e():ke&&Ae(null)},[i.distanceGuidesVisible,$e,i.selectedShapes.map(e=>`${e.x},${e.y},${e.width},${e.height},${e.rotation}`).join("|")]);const Qe=o.useRef(!1);o.useEffect(()=>{var e;let t;const n=null===(e=Xe.current)||void 0===e?void 0:e.closest(".polotno-workspace-inner"),i=()=>{Qe.current=!0,clearTimeout(t),t=setTimeout(()=>{Qe.current=!1},300)};return null==n||n.addEventListener("scroll",i),()=>{clearTimeout(t),null==n||n.removeEventListener("scroll",i)}},[]),o.useEffect(()=>{const e=Ee.current;if(!e){return}const t=e.container(),n=new Map,o=e=>{n.set(e.target,{x:e.target.x(),y:e.target.y()})},r=e=>{n.delete(e.target)};e.on("dragstart",o),e.on("dragend",r);const l=e=>{var t,o;e.touches.length>=2&&((null===(t=be.current)||void 0===t?void 0:t.isDragging())&&be.current.stopDrag(),null===(o=be.current)||void 0===o||o.nodes().forEach(e=>{var t;const o=n.get(e);e.isDragging()&&e.stopDrag(),o&&(e.setAttrs(o),null===(t=i.getElementById(e.id()))||void 0===t||t.set({x:o.x,y:o.y}))}))};return t.addEventListener("touchstart",l,{passive:!0}),t.addEventListener("touchmove",l,{passive:!0}),()=>{e.off("dragstart",o),e.off("dragend",r),t.removeEventListener("touchstart",l),t.removeEventListener("touchmove",l)}},[i]);const qe=e=>{if(i.role===X.VIEWER){return}if(i.activePage!==r&&r.select(),Qe.current){return}if(Ne.current){return}const t=e.evt.shiftKey,n=e.evt.ctrlKey||e.evt.metaKey,o=t||n,l=e.target.findAncestor(".elements-container"),s=e.target.findAncestor(".page-abs-container"),a=e.target.findAncestor("Transformer"),d=e.target.findAncestor(".page-container",!0);if(!(o||l||a||s||d||Je.visible)){return i.selectElements([]),void i.selectPages([])}if(n&&!t){const e=Ee.current,t=null==e?void 0:e.getPointerPosition();if(!e||!t){return}const n=e.getAllIntersections(t),o=new Set,r=[];for(const s of[...n].reverse()){const e=s.findAncestor(".element",!0);if(!e){continue}const t=i.getElementById(e.id()),n=null==t?void 0:t.top;n&&(o.has(n.id)||(o.add(n.id),r.push(n.id)))}if(0===r.length){return}let l;if(1===i.selectedElementsIds.length){const e=i.selectedElementsIds[0],t=r.indexOf(e);l=-1===t?r[0]:r[(t+1)%r.length]}else{l=r[0]}return i.selectElements([l]),void i.selectPages([])}const c=e.target.findAncestor(".element-container",!0),m=(null==c?void 0:c.findOne(".element"))||e.target.findAncestor(".element",!0),h=i.getElementById(null==m?void 0:m.id()),u=null==h?void 0:h.top;let g;if("group"===I){g=null==u?void 0:u.id}else if(u){const e=i.selectedElements.some(e=>{var t;return(null===(t=e.top)||void 0===t?void 0:t.id)===u.id});g=e?null==h?void 0:h.id:null==u?void 0:u.id}else{g=void 0}const f=null==h?void 0:h.id;if(f&&i.selectedElementsIds.indexOf(f)>=0&&!t){return}const p=!!g&&i.selectedElementsIds.indexOf(g)>=0,x=e.target.findAncestor(".page-container",!0);if(g&&t&&!p){const e=i.selectedElementsIds.concat([g]),t=new Set(e),n=e.filter(e=>{const n=i.getElementById(e);if(!n){return!1}for(let i=n.parent;i;i=null==i?void 0:i.parent){if(t.has(i.id)){return!1}}return!0});i.selectElements(n),i.selectPages([])}else{g&&t&&p?i.selectElements(i.selectedElementsIds.filter(e=>e!==g)):!g||t||p?g&&!t&&p||(x?(t||i.selectElements([]),i.selectPages([r.id])):i.selectPages([])):(i.selectElements([g]),i.selectPages([]))}};M(be,i);const et=i.activePage===r,tt=i._selectedPagesIds.includes(r.id),nt=null==Y?void 0:Y.PageControls,it=null==Y?void 0:Y.Tooltip,ot=null==Y?void 0:Y.ContextMenu,rt=1/i.scale,lt=0/i.scale;return n("div",{ref:Xe,onDragOver:e=>e.preventDefault(),onDrop:e=>{if(e.preventDefault(),i.role===X.VIEWER){return}if(!Ee.current){return}Ee.current.setPointersPositions(e);const t=Ee.current.findOne(".elements-container"),n=null==t?void 0:t.getRelativePointerPosition(),o=Ee.current.getPointerPosition(),l=Ee.current.getAllIntersections(o).map(e=>e.findAncestor(".element",!0)).filter(Boolean),s=[...new Set(l.reverse())].map(e=>i.getElementById(e.id())).filter(e=>!!e),a=s[0];he&&n&&(he(n,a,{elements:s,page:r}),he=null)},style:{position:"relative",width:a+"px",height:m+"px",overflow:"hidden",flexShrink:0},className:"polotno-page-container"+(et?" active-page":""),children:[t(x,{ref:Ee,width:Math.min(a,O.width+200),height:Math.min(O.height+200,m),onClick:qe,onTap:qe,onContextMenu:e=>{if(e.evt.preventDefault(),i.role===X.VIEWER){return}const t=e.target.findAncestor(".element",!0),n=i.getElementById(null==t?void 0:t.id()),o=null==n?void 0:n.top,r=null==o?void 0:o.id;if(!r){return i.selectElements([]),void Re.close()}i.selectedElementsIds.indexOf(r)>=0||i.selectElements([r]),Re.open({x:e.evt.clientX,y:e.evt.clientY})},onMouseDown:Ke,onMouseMove:e=>{if(!i.distanceGuidesVisible&&!e.evt.altKey){return void(ke&&Ae(null))}const t=e.target.findAncestor(".element",!0),n=null==t?void 0:t.id();$e(n)},onDragStart:e=>{var t;const n=e.target.getStage();if(n&&n.getPointersPositions().length>=2){return void e.target.stopDrag()}const o=e.target.findAncestor(".element",!0);if(o){const n=i.getElementById(null==o?void 0:o.id()),r=null==n?void 0:n.top,l=null==r?void 0:r.id;if(!(n&&i.selectedElementsIds.indexOf(n.id)>=0||l&&i.selectedElementsIds.indexOf(l)>=0)&&l){i.selectElements([l]);const n=Ze();e.target.stopDrag(),n.forEach(t=>{t.isDragging()||t.startDrag(e)}),null===(t=be.current)||void 0===t||t.startDrag(e),A()}}ke&&Ae(null)},pageId:r.id,style:{position:"absolute",overflow:"hidden",top:0,left:0},children:n(u,{children:[t(oe,{width:a,height:m,fill:$.workspaceBackgroundColor}),t(c,{x:xe,y:ve,scaleX:i.scale,scaleY:i.scale,name:"page-container",children:n(c,{name:"page-container-2",children:[t(c,{name:"page-background-group",x:de.left,y:de.top,children:t(se,{x:-le.left,y:-le.top,width:r.computedWidth+le.left+le.right,height:r.computedHeight+le.top+le.bottom,background:r.background,transparencyBackgroundColor:$.transparencyBackgroundColor,name:"page-background",preventDefault:!1,scale:i.scale})}),n(c,{x:de.left,y:de.top,name:"elements-container",listening:!i.isPlaying&&i.role!==X.VIEWER,children:[t(f,{name:"elements-area",width:r.computedWidth,height:r.computedHeight,listening:!1}),t(me,{elements:r.children,store:i})]}),t(p,{name:"bleed",fill:$.bleedColor,listening:!1,visible:i.bleedVisible&&(de.top>0||de.right>0||de.bottom>0||de.left>0),hideInExport:!0,sceneFunc:(e,t)=>{const{top:n,right:i,bottom:o,left:l}=le,s=r.computedWidth,a=r.computedHeight,d=e._context;d.beginPath(),d.rect(0,0,l+s+i,n+a+o),d.rect(l,n,s,a),d.fillStyle=t.fill(),d.fill("evenodd")}}),R()===fe&&t(pe,{name:"hit-detection",x:-rt/2-lt,y:-rt/2-lt,width:ue+rt+2*lt,height:ge+rt+2*lt})]})}),t(g,{name:"workspace-background",points:[0,0,a,0,a,m,0,m,0,0,xe,ve,xe,m-ve,a-xe,m-ve,a-xe,ve,xe,ve],listening:!1,closed:!0,fill:$.workspaceBackgroundColor}),t(c,{x:xe,y:ve,scaleX:i.scale,scaleY:i.scale,children:t(f,{name:"page-highlight",hideInExport:!0,x:-rt/2-lt,y:-rt/2-lt,width:ue+rt+2*lt,height:ge+rt+2*lt,stroke:tt?$.activePageBorderColor:$.pageBorderColor,strokeWidth:2,listening:!1,strokeScaleEnabled:!1})}),n(c,{x:xe+de.left*i.scale,y:ve+de.top*i.scale,scaleX:i.scale,scaleY:i.scale,name:"page-abs-container",children:[t(y,{ref:be,name:V,rotateAnchorAngle:Oe,onDragStart:e=>{var t;const n=e.target.getStage();n&&n.getPointersPositions().length>=2?e.target.stopDrag():((null===(t=e.evt)||void 0===t?void 0:t.altKey)&&S&&i.selectedElements.forEach(e=>{const t=e.clone({},{skipSelect:!0}),n=r.children.indexOf(e);r.setElementZIndex(t.id,n)}),Se.current||(Se.current=!0,i.history.startTransaction()))},onDragEnd:()=>{Se.current&&(i.history.endTransaction(),Se.current=!1),He()},onTransformStart:()=>{i.history.startTransaction(),we.current=new Map(We.map(e=>[e.id,{width:e.width,height:e.height}])),Ae(null)},boundBoxFunc:(e,t)=>{var n,o,r,l;const s=null!==(o=null===(n=Q.boundBoxFunc)||void 0===n?void 0:n.call(Q,e,t))&&void 0!==o?o:t,a=Math.abs(s.width)<1||Math.abs(s.height)<1,d=Math.abs(e.width)<1||Math.abs(e.height)<1;if(a&&!d){return e}const c=i.selectedElements;if(1===c.length&&"table"===(null===(r=c[0])||void 0===r?void 0:r.type)){const t=c[0],n=Math.abs(e.width),i=Math.abs(e.height);if(n>0&&i>0){const o=Math.abs(s.width)/n,r=Math.abs(s.height)/i,l=t.width*o,a=t.height*r,d=Object.assign({},s);return l<t.minWidth&&(d.width=e.width),a<t.minHeight&&(d.height=e.height),Z(d,s,e)}}return Ge&&We.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=!F(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,m=((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?z(i,e.fontSize):1})(t,e,d,r);return r>=m&&l*c<m}),m=Object.assign({},t),h=t.width*e.width<0,u=t.height*e.height<0,g=h||c("x"),f=u||c("y"),p=f||!d&&g;return(g||!d&&f)&&(m.width=e.width),p&&(m.height=e.height),Z(m,t,e)})(e,s,(null===(l=be.current)||void 0===l?void 0:l.getActiveAnchor())||"",We,we.current):s},onTransform:e=>{const t=be.current.nodes(),n=t[t.length-1];e.target===n&&setTimeout(()=>{_e()},0)},onTransformEnd:e=>{Ie({}),i.history.endTransaction(),we.current=null,He(),Ze()},visible:!i.isPlaying}),ke&&ke.map(({points:e,distance:o,box1:r,box2:l},s)=>n(c,{name:"distances-container",hideInExport:!0,listening:!1,children:[t(f,Object.assign({},r,{stroke:$.distanceGuideStyle.stroke,strokeWidth:1,strokeScaleEnabled:!1})),t(f,Object.assign({},l,{stroke:$.distanceGuideStyle.stroke,strokeWidth:1,strokeScaleEnabled:!1})),t(g,{points:[e[0].x,e[0].y,e[1].x,e[1].y],stroke:$.distanceGuideStyle.stroke,strokeWidth:1,strokeScaleEnabled:!1}),t(g,{points:[e[1].x,e[1].y,e[2].x,e[2].y],stroke:$.distanceGuideStyle.stroke,strokeWidth:1,strokeScaleEnabled:!1}),n(h,{x:(e[0].x+e[1].x)/2,y:(e[0].y+e[1].y)/2,offsetY:-10,scaleX:1/i.scale,scaleY:1/i.scale,children:[t(v,{cornerRadius:5,fill:$.distanceGuideStyle.labelFill,pointerDirection:"down"}),t(b,{align:"center",verticalAlign:"middle",fill:$.distanceGuideStyle.labelTextFill,padding:5,text:L({unit:i.unit,dpi:i.dpi,px:o})})]})]},s)),r._rendering&&n(c,{children:[t(f,{width:ue,height:ge,fill:"rgba(255,255,255,0.9)"}),t(b,{text:"Rendering...",fontSize:60,width:ue,height:ge,align:"center",verticalAlign:"middle"})]}),it&&t(it,{components:Y,store:i,page:r,stageRef:Ee,tooltipSafeArea:G}),ot&&t(N,{children:t(ot,Object.assign({components:Y,store:i},Re.props))})]}),t(k,{store:i,page:r,width:a,height:m,scale:i.scale,xPadding:xe,yPadding:ve,bleedLeft:de.left,bleedTop:de.top}),t(ce,Object.assign({},Me,{store:i})),t(ae,{selection:Je}),j()>0&&n(c,{hideInExport:!0,children:[t(ye,{name:"cache-bounds",x:a-(1===j()?250:210),y:m-(1===j()?95:45)}),t(ye,{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:a-170,y:m-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"})]})}),Ye&&nt&&t(nt,{store:i,page:r,xPadding:xe,yPadding:ve,layout:P})]})});
|
|
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 c}from"@polotno/schema";import{Group as d,Image as h,Label as u,Layer as m,Line as g,Rect as f,Shape as p,Stage as x,KonvaRenderer as v,Tag as b,Text as y,Transformer as w}from"react-konva";import{useWorkspaceStyle as E}from"./workspace-style.js";import{ROLES as X}from"../model/store.js";import Y from"konva";import S from"./element.js";import{DrawingLayer as k}from"./drawing-layer.js";import{ensureDragOrder as A,useSnap as M}from"./use-transformer-snap.js";import{useCanvasImage as I,useImageLoader as P}from"./image-element.js";import{FadeOverlay as O}from"./fade-overlay.js";import{getCrop as j}from"../utils/crop.js";import{___ as R,____ as D,isCreditVisible as B}from"../utils/validate-key.js";import{getClientRect as C,getCorners as T,getTotalClientRect as W,polygonsIntersect as G}from"../utils/math.js";import{pxToUnitRounded as L,pxToUnitString as F}from"../utils/unit.js";import{isCornerAnchor as V,MAIN_TRANSFORMER_NAME as z,textMinResizeWidth as U,textMinWidthIsMeasured as Z}from"../utils/px.js";import{restoreHeldPoint as _}from"./transform-box.js";import{flags as H}from"../utils/flags.js";import{useColor as J}from"./use-color.js";import{isGradient as N}from"@polotno/core/gradient";import{Html as K}from"react-konva-utils";const $=o.version.startsWith("18.")?o.forwardRef((e,n)=>(o.useLayoutEffect(()=>{v.flushSync()}),t(x,Object.assign({},e,{ref:n})))):x,Q={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},ee=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},te=e=>e.selectedShapes.filter(e=>!e._cropModeEnabled),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]=I(i,"anonymous"),s=r?j(r,{width:o.width,height:o.height},"center-middle"):{};return P(l,i,"page background"),t(h,Object.assign({image:r},o,s))},re=e=>{const n=J({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,c=e(i,["background","scale","borderColor","transparencyBackgroundColor"]),d=o.useMemo(()=>!!Y.Util.colorToRGBA(r)||N(r),[r]),h=o.useMemo(()=>{if(N(r)){return!0}const e=Y.Util.colorToRGBA(r);return!e||e.a<1},[r]),u=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},c,{hideInExport:!0}):Object.assign({fillPatternImage:u},c,{opacity:.1,hideInExport:!0})),d?t(re,Object.assign({fill:r},c)):t(oe,Object.assign({url:r},c))]})},se=r(({selection:e})=>{const{selectionRectStyle:n}=E();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 ce=r(({x:e,y:o,width:r,height:l,rotation:s,anchor:a,store:c})=>{const{transformLabelStyle:d}=E();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:Y.Util.radToDeg(s)}),m=(l/2+70)*Math.cos(s-Math.PI/2),g=(l/2+70)*Math.sin(s-Math.PI/2),f=L({unit:c.unit,dpi:c.dpi,px:r/c.scale,precious:"px"===c.unit?0:1})+" x "+L({unit:c.unit,dpi:c.dpi,px:l/c.scale,precious:"px"===c.unit?0:1})+("px"===c.unit?"":" "+c.unit);return n(i,{children:[n(u,{x:(h.minX+h.maxX)/2+m,y:(h.minY+h.maxY)/2+g,offsetX:14,offsetY:14,visible:"rotater"===a,children:[t(b,{cornerRadius:5,fill:d.fill}),t(y,{align:"center",verticalAlign:"middle",fill:d.textFill,padding:8,text:ae(s).toString()+"°"})]}),n(u,{x:(h.minX+h.maxX)/2,y:h.maxY+20,visible:"rotater"!==a,children:[t(b,{cornerRadius:5,fill:d.fill,pointerDirection:"up",pointerHeight:0,pointerWidth:0}),t(y,{align:"center",verticalAlign:"middle",fill:d.textFill,padding:8,text:f})]})]})}),de=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(S,{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 ue=atob("UG9sb3RubyBmcmVlIGxpY2Vuc2UgbGltaXRhdGlvbiBleGNlZWRlZCAtIFBsZWFzZSB1cGdyYWRlIHlvdXIgYWNjb3VudC4="),me=atob("I2MwMzkyYg=="),ge=atob("djAuOS4y"),fe=e=>t(i,{children:n(u,{fill:me,height:200,children:[t(b,{fill:me}),t(y,Object.assign({},e,{fill:"white",text:ue,height:void 0,padding:10,fontSize:20}))]})}),pe=atob("RlJFRSAgVFJJQUwgIExJQ0VOU0U="),xe=(atob("UG93ZXJlZCBieSBQb2xvdG5v"),atob("TElDRU5TRSAgS0VZICBJUyAgTUlTU0lORw==")),ve=atob("UGxlYXNlIGFjdGl2YXRlIHlvdXIgbGljZW5zZS4KTGljZW5zZSByZWxhdGVkIHF1ZXN0aW9uczoKcG9sb3Ruby5jb20vY29udGFjdA=="),be=e=>{const i=1===D(),o=i?xe:pe,r=i?230:195;return n(d,Object.assign({},e,{listening:!1,children:[t(f,{fill:me,width:r,height:24,cornerRadius:2}),t(y,{text:o,fill:"white",fontSize:13,fontFamily:"monospace",width:r,align:"center",y:5,listening:!1}),i&&t(y,{text:ve,fill:"rgba(0,0,0,0.6)",fontSize:14,y:30,listening:!1})]}))};export default r(({store:i,page:r,width:h,height:x,pageControlsEnabled:v,components:S,altCloneEnabled:I,groupSelectionMode:P="drill",viewportSize:j,layout:L="vertical",tooltipSafeArea:J,transformerSafeArea:N})=>{var oe,re;const ae=E(),ue=ae.transformerStyle,me=Q,pe=r.computedBleed,xe=i.bleedVisible?pe:c,ve=r.computedWidth+xe.left+xe.right,ye=r.computedHeight+xe.top+xe.bottom,we=(h-ve*i.scale)/2,Ee=(x-ye*i.scale)/2,Xe=o.useRef(null),Ye=o.useRef(null),Se=o.useRef(null),ke=o.useRef(null),Ae=null==v||v,Me=o.useRef(!1),[Ie,Pe]=o.useState(null),[Oe,je]=o.useState({}),[Re,De]=o.useState(0),Be=useContextMenu({store:i}),Ce=i.selectedElements.find(e=>e._cropModeEnabled),Te=i.selectedElements.find(e=>e.curveEnabled),We=i.selectedShapes.filter(e=>!e.resizable).length>0,Ge=i.selectedShapes.filter(e=>!e.draggable).length>0,Le=i.selectedElements.filter(e=>!e.visible).length>0,Fe=te(i),Ve=1!==i.selectedElements.length||"group"===(null===(oe=i.selectedElements[0])||void 0===oe?void 0:oe.type),ze=null!==(re=ee(Fe))&&void 0!==re?re:0,Ue=e=>Ve&&Fe.length>0&&Fe.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,ze)),Ze=!Ve&&i.selectedElements[0].keepRatio,_e=Ue("x"),He=Ue("y"),Je=()=>{var t,n,o;const r=Xe.current;if(!r){return[]}const l=r.getStage();if(!l){return[]}const s=te(i),a=s.map(e=>l.findOne("#"+e.id)).filter(e=>!!e),c=1===i.selectedElements.length,d=c&&(null===(t=i.selectedElements[0])||void 0===t?void 0:t.type)||"many",h=ne[d],u=Object.assign(Object.assign({},me),h||{});h&&("svg"!==d&&"image"!==d&&"gif"!==d||i.selectedElements[0].keepRatio||(u.enabledAnchors=me.enabledAnchors),"text"===d&&H.textVerticalResizeEnabled&&(u.enabledAnchors=null===(n=ne.text.enabledAnchors)||void 0===n?void 0:n.concat(["bottom-center","top-center"])),"text"===d&&c&&i.selectedElements[0].curveEnabled&&(u.enabledAnchors=ne.many.enabledAnchors)),(_e||He)&&(u.enabledAnchors=[...u.enabledAnchors||[],..._e?["middle-left","middle-right"]:[],...He?["top-center","bottom-center"]:[]]);const{boundBoxFunc:m}=ue,g=e(ue,["boundBoxFunc"]);r.setAttrs(Object.assign(Object.assign(Object.assign({},u),g),{name:z})),We&&r.enabledAnchors([]),Ge&&r.rotateEnabled(!1);const f=r.nodes();if(f.length===a.length&&a.every((e,t)=>f[t]===e)||r.nodes(a),Ve&&a.length){const e=ee(s);null===e||q(r.rotation()-e)||(r.rotation(e),r.forceUpdate())}return null===(o=r.getLayer())||void 0===o||o.batchDraw(),a};o.useLayoutEffect(()=>{var e;if(null===(e=Xe.current)||void 0===e?void 0:e.isTransforming()){return}const t=Je();t.find(e=>null==e?void 0:e.isDragging())&&(t.forEach(e=>{e.isDragging()||null==e||e.startDrag()}),A())},[i.selectedShapes,Ce,We,Le,Ge,Te,_e,He,Ze,ze,ue]);const Ne=()=>{var e,t;const n=Xe.current;if(!n){return}if(!n.isTransforming()){return void je({})}if(!n.nodes().length||!n.isTransforming()){return}const i=n.__getNodeRect(),o=null==n?void 0:n.getActiveAnchor(),r=n.getStage();je({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})},Ke=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 De(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,c=e=>{const t=e*Math.PI/180,i=(e%360+360)%360;let c;c=0===i||180===i?s:l;const d=Math.sin(t)*(c+n),h=-Math.cos(t)*(c+n),u=d*Math.cos(a)-h*Math.sin(a),m=d*Math.sin(a)+h*Math.cos(a);return{x:o+u,y:r+m}},d=e=>e.x>=t.left&&e.x<=t.right&&e.y>=t.top&&e.y<=t.bottom;if(d(c(0))){return 0}for(const h of[180,270,90]){if(d(c(h))){return h}}return 0}(n,{top:(null==N?void 0:N.top)||0,bottom:x-((null==N?void 0:N.bottom)||0),left:(null==N?void 0:N.left)||0,right:h-((null==N?void 0:N.right)||0)},ue.rotateAnchorOffset,t.rotation());De(i)},[N,h,x]);o.useEffect(()=>{var e;null===(e=Xe.current)||void 0===e||e.update(),Ne(),Ke()},[i.scale,Ke]),o.useEffect(()=>{Ke()},[i.selectedShapes,Ke]);const $e=l(()=>({visible:!1,x1:0,y1:0,x2:0,y2:0})),Qe=o.useRef(!1),qe=e=>{const t=Se.current;if(!t||i.role===X.VIEWER||i.activePage!==r||i.isPlaying||"button"in e.evt&&0!==e.evt.button||1!==t.getPointersPositions().length||!e.target.findAncestor(".elements-container")||!e.target.findAncestor(".element",!0)||!i.selectedShapes.length||i.selectedShapes.some(e=>!e.draggable)){return}const n=t.getPointerPosition();if(!n){return}const o=Je();if(o.some(t=>t===e.target||t.isAncestorOf(e.target))){return}const l=o.find(e=>!!(e.draggable()&&e.isVisible()&&e.isListening())&&(e instanceof Y.Shape?[e]:e instanceof Y.Container?e.find("Shape"):[]).some(e=>e.intersects(n)));if(l){for(const[t,n]of Y.DD._dragElements){"ready"!==n.dragStatus||n.node!==e.target&&!n.node.isAncestorOf(e.target)||Y.DD._dragElements.delete(t)}l._createDragElement(e),"touches"in e.evt&&e.evt.cancelable&&l.preventDefault()&&e.evt.preventDefault()}},et=s(e=>{var t,n,o,r,l,s,a;if(i.role===X.VIEWER){return}Qe.current=!1;const c=e.target.findAncestor(".elements-container"),d=e.target.findAncestor("Transformer"),h=e.target.findAncestor(".page-abs-container");if(c||d||h){return}const u=null===(t=e.target.getStage())||void 0===t?void 0:t.getPointerPosition();u&&(u.x-=null!==(o=null===(n=e.target.getStage())||void 0===n?void 0:n.x())&&void 0!==o?o:0,u.y-=null!==(l=null===(r=e.target.getStage())||void 0===r?void 0:r.y())&&void 0!==l?l:0,$e.visible=!0,$e.x1=u.x,$e.y1=u.y,$e.x2=u.x,$e.y2=u.y,(null!==(a=null===(s=e.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:Se,containerRef:ke,viewportSize:j}),o.useEffect(()=>{const e=s(e=>{var t,n,i,o,r,l;if(!$e.visible){return}null===(t=Se.current)||void 0===t||t.setPointersPositions(e);let s=null===(n=Se.current)||void 0===n?void 0:n.getPointerPosition();s?(s.x-=null!==(o=null===(i=Se.current)||void 0===i?void 0:i.x())&&void 0!==o?o:0,s.y-=null!==(l=null===(r=Se.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}),t=s(()=>{if(!$e.visible){return}if(!Se.current){return}const e=Se.current.findOne(".selection"),t=e?e.getClientRect({skipStroke:!0}):{width:0,height:0,x:0,y:0};if(t.width&&t.height){const e=[{x:t.x,y:t.y},{x:t.x+t.width,y:t.y},{x:t.x+t.width,y:t.y+t.height},{x:t.x,y:t.y+t.height}],n=[];Se.current.find(".element").forEach(t=>{var o;const r=i.getElementById(t.id()),l=null==r?void 0:r.draggable,s=null==r?void 0:r.selectable;if(!l||!s){return}const a=null===(o=t.getParent())||void 0===o?void 0:o.getAbsoluteTransform();if(!a){return}const c=T(r.a).map(e=>a.point(e));G(e,c)&&n.push(r.top.id)});const o=[...new Set(n)];Qe.current=!0,i.selectElements(o)}$e.visible=!1});return window.addEventListener("mousemove",e),window.addEventListener("touchmove",e),window.addEventListener("mouseup",t,{capture:!0}),window.addEventListener("touchend",t,{capture:!0}),()=>{window.removeEventListener("mousemove",e),window.removeEventListener("touchmove",e),window.removeEventListener("mouseup",t),window.removeEventListener("touchend",t)}},[]);const tt=o.useCallback(e=>{if(!i.selectedElements[0]){return}if(e&&i.selectedElementsIds.includes(e)){return}const t=W(i.selectedShapes),n=e?i.getElementById(e):{x:0,y:0,width:r.computedWidth,height:r.computedHeight,rotation:0},o=C(n),l=[];t.minX>o.maxX&&l.push({distance:t.minX-o.maxX,box1:t,box2:o,points:[{x:t.minX,y:t.minY+t.height/2},{x:o.maxX,y:t.minY+t.height/2},{x:o.maxX,y:o.minY+o.height/2}]}),t.maxX<o.minX&&l.push({distance:o.minX-t.maxX,box1:t,box2:o,points:[{x:t.maxX,y:t.minY+t.height/2},{x:o.minX,y:t.minY+t.height/2},{x:o.minX,y:o.minY+o.height/2}]}),t.minY>o.maxY&&l.push({box1:t,box2:o,distance:t.minY-o.maxY,points:[{x:t.minX+t.width/2,y:t.minY},{x:t.minX+t.width/2,y:o.maxY},{x:o.minX+o.width/2,y:o.maxY}]}),t.maxY<o.minY&&l.push({box1:t,box2:o,distance:o.minY-t.maxY,points:[{x:t.minX+t.width/2,y:t.maxY},{x:t.minX+t.width/2,y:o.minY},{x:o.minX+o.width/2,y:o.minY}]});const s=t.minX>=o.minX&&t.maxX<=o.maxX&&t.minY>=o.minY&&t.maxY<=o.maxY;if(s&&(l.push({distance:t.minX-o.minX,box1:t,box2:o,points:[{x:t.minX,y:t.minY+t.height/2},{x:o.minX,y:t.minY+t.height/2},{x:o.minX,y:o.minY+o.height/2}]}),l.push({distance:o.maxX-t.maxX,box1:t,box2:o,points:[{x:t.maxX,y:t.minY+t.height/2},{x:o.maxX,y:t.minY+t.height/2},{x:o.maxX,y:o.minY+o.height/2}]}),l.push({box1:t,box2:o,distance:t.minY-o.minY,points:[{x:t.minX+t.width/2,y:t.minY},{x:t.minX+t.width/2,y:o.minY},{x:o.minX+o.width/2,y:o.minY}]}),l.push({box1:t,box2:o,distance:o.maxY-t.maxY,points:[{x:t.minX+t.width/2,y:t.maxY},{x:t.minX+t.width/2,y:o.maxY},{x:o.minX+o.width/2,y:o.maxY}]})),0===l.length&&!s){const e=t.minX<o.maxX&&t.maxX>o.minX,n=t.minY<o.maxY&&t.maxY>o.minY;if(e&&n){const e=(Math.max(t.minY,o.minY)+Math.min(t.maxY,o.maxY))/2,n=(Math.max(t.minX,o.minX)+Math.min(t.maxX,o.maxX))/2;t.minX<o.minX?l.push({distance:o.minX-t.minX,box1:t,box2:o,points:[{x:t.minX,y:e},{x:o.minX,y:e},{x:o.minX,y:e}]}):l.push({distance:t.minX-o.minX,box1:t,box2:o,points:[{x:t.minX,y:e},{x:o.minX,y:e},{x:o.minX,y:e}]}),t.maxX>o.maxX?l.push({distance:t.maxX-o.maxX,box1:t,box2:o,points:[{x:o.maxX,y:e},{x:t.maxX,y:e},{x:o.maxX,y:e}]}):l.push({distance:o.maxX-t.maxX,box1:t,box2:o,points:[{x:t.maxX,y:e},{x:o.maxX,y:e},{x:o.maxX,y:e}]}),t.minY<o.minY?l.push({box1:t,box2:o,distance:o.minY-t.minY,points:[{x:n,y:t.minY},{x:n,y:o.minY},{x:n,y:o.minY}]}):l.push({box1:t,box2:o,distance:t.minY-o.minY,points:[{x:n,y:t.minY},{x:n,y:o.minY},{x:n,y:o.minY}]}),t.maxY>o.maxY?l.push({box1:t,box2:o,distance:t.maxY-o.maxY,points:[{x:n,y:o.maxY},{x:n,y:t.maxY},{x:n,y:o.maxY}]}):l.push({box1:t,box2:o,distance:o.maxY-t.maxY,points:[{x:n,y:t.maxY},{x:n,y:o.maxY},{x:n,y:o.maxY}]})}}JSON.stringify(Ie)!==JSON.stringify(l)&&Pe(l)},[i,r]);o.useEffect(()=>{i.selectedElements[0]&&i.distanceGuidesVisible?tt():Ie&&Pe(null)},[i.distanceGuidesVisible,tt,i.selectedShapes.map(e=>`${e.x},${e.y},${e.width},${e.height},${e.rotation}`).join("|")]);const nt=o.useRef(!1);o.useEffect(()=>{var e;let t;const n=null===(e=ke.current)||void 0===e?void 0:e.closest(".polotno-workspace-inner"),i=()=>{nt.current=!0,clearTimeout(t),t=setTimeout(()=>{nt.current=!1},300)};return null==n||n.addEventListener("scroll",i),()=>{clearTimeout(t),null==n||n.removeEventListener("scroll",i)}},[]),o.useEffect(()=>{const e=Se.current;if(!e){return}const t=e.container(),n=new Map,o=e=>{var t,i;n.has(e.target)||[e.target,...null!==(i=null===(t=Xe.current)||void 0===t?void 0:t.nodes())&&void 0!==i?i:[]].forEach(e=>{n.has(e)||n.set(e,{x:e.x(),y:e.y()})})},r=e=>{e.target===Xe.current?n.clear():n.delete(e.target)};e.on("dragstart",o),e.on("dragend",r);const l=e=>{e.touches.length>=2&&a(()=>{var e,t;const o=new Map(n);(null===(e=Xe.current)||void 0===e?void 0:e.isDragging())&&Xe.current.stopDrag(),null===(t=Xe.current)||void 0===t||t.nodes().forEach(e=>{var t;const n=o.get(e);e.isDragging()&&e.stopDrag(),n&&(e.setAttrs(n),null===(t=i.getElementById(e.id()))||void 0===t||t.set({x:n.x,y:n.y}))})})};return t.addEventListener("touchstart",l,{passive:!0}),t.addEventListener("touchmove",l,{passive:!0}),()=>{e.off("dragstart",o),e.off("dragend",r),t.removeEventListener("touchstart",l),t.removeEventListener("touchmove",l)}},[i]);const it=e=>{if(i.role===X.VIEWER){return}if(i.activePage!==r&&r.select(),nt.current){return}if(Qe.current){return}const t=e.evt.shiftKey,n=e.evt.ctrlKey||e.evt.metaKey,o=t||n,l=e.target.findAncestor(".elements-container"),s=e.target.findAncestor(".page-abs-container"),a=e.target.findAncestor("Transformer"),c=e.target.findAncestor(".page-container",!0);if(!(o||l||a||s||c||$e.visible)){return i.selectElements([]),void i.selectPages([])}if(n&&!t){const e=Se.current,t=null==e?void 0:e.getPointerPosition();if(!e||!t){return}const n=e.getAllIntersections(t),o=new Set,r=[];for(const s of[...n].reverse()){const e=s.findAncestor(".element",!0);if(!e){continue}const t=i.getElementById(e.id()),n=null==t?void 0:t.top;n&&(o.has(n.id)||(o.add(n.id),r.push(n.id)))}if(0===r.length){return}let l;if(1===i.selectedElementsIds.length){const e=i.selectedElementsIds[0],t=r.indexOf(e);l=-1===t?r[0]:r[(t+1)%r.length]}else{l=r[0]}return i.selectElements([l]),void i.selectPages([])}const d=e.target.findAncestor(".element-container",!0),h=(null==d?void 0:d.findOne(".element"))||e.target.findAncestor(".element",!0),u=i.getElementById(null==h?void 0:h.id()),m=null==u?void 0:u.top;let g;if("group"===P){g=null==m?void 0:m.id}else if(m){const e=i.selectedElements.some(e=>{var t;return(null===(t=e.top)||void 0===t?void 0:t.id)===m.id});g=e?null==u?void 0:u.id:null==m?void 0:m.id}else{g=void 0}const f=null==u?void 0:u.id;if(f&&i.selectedElementsIds.indexOf(f)>=0&&!t){return}const p=!!g&&i.selectedElementsIds.indexOf(g)>=0,x=e.target.findAncestor(".page-container",!0);if(g&&t&&!p){const e=i.selectedElementsIds.concat([g]),t=new Set(e),n=e.filter(e=>{const n=i.getElementById(e);if(!n){return!1}for(let i=n.parent;i;i=null==i?void 0:i.parent){if(t.has(i.id)){return!1}}return!0});i.selectElements(n),i.selectPages([])}else{g&&t&&p?i.selectElements(i.selectedElementsIds.filter(e=>e!==g)):!g||t||p?g&&!t&&p||(x?(t||i.selectElements([]),i.selectPages([r.id])):i.selectPages([])):(i.selectElements([g]),i.selectPages([]))}};M(Xe,i);const ot=i.activePage===r,rt=i._selectedPagesIds.includes(r.id),lt=null==S?void 0:S.PageControls,st=null==S?void 0:S.Tooltip,at=null==S?void 0:S.ContextMenu,ct=1/i.scale,dt=0/i.scale;return n("div",{ref:ke,onDragOver:e=>e.preventDefault(),onDrop:e=>{if(e.preventDefault(),i.role===X.VIEWER){return}if(!Se.current){return}Se.current.setPointersPositions(e);const t=Se.current.findOne(".elements-container"),n=null==t?void 0:t.getRelativePointerPosition(),o=Se.current.getPointerPosition(),l=Se.current.getAllIntersections(o).map(e=>e.findAncestor(".element",!0)).filter(Boolean),s=[...new Set(l.reverse())].map(e=>i.getElementById(e.id())).filter(e=>!!e),a=s[0];he&&n&&(he(n,a,{elements:s,page:r}),he=null)},style:{position:"relative",width:h+"px",height:x+"px",overflow:"hidden",flexShrink:0},className:"polotno-page-container"+(ot?" active-page":""),children:[t($,{ref:Se,eventBatchFunc:a,width:Math.min(h,j.width+200),height:Math.min(j.height+200,x),onClick:it,onTap:it,onContextMenu:e=>{if(e.evt.preventDefault(),i.role===X.VIEWER){return}const t=e.target.findAncestor(".element",!0),n=i.getElementById(null==t?void 0:t.id()),o=null==n?void 0:n.top,r=null==o?void 0:o.id;if(!r){return i.selectElements([]),void Be.close()}i.selectedElementsIds.indexOf(r)>=0||i.selectElements([r]),Be.open({x:e.evt.clientX,y:e.evt.clientY})},onMouseDown:e=>{qe(e),et(e)},onTouchStart:qe,onMouseMove:e=>{if(!i.distanceGuidesVisible&&!e.evt.altKey){return void(Ie&&Pe(null))}const t=e.target.findAncestor(".element",!0),n=null==t?void 0:t.id();tt(n)},onDragStart:e=>{var t;const n=e.target.getStage();if(n&&n.getPointersPositions().length>=2){return void e.target.stopDrag()}const o=e.target.findAncestor(".element",!0);if(o){const n=i.getElementById(null==o?void 0:o.id()),r=null==n?void 0:n.top,l=null==r?void 0:r.id;if(!(n&&i.selectedElementsIds.indexOf(n.id)>=0||l&&i.selectedElementsIds.indexOf(l)>=0)&&l){i.selectElements([l]);const n=Je();e.target.stopDrag(),n.forEach(t=>{t.isDragging()||t.startDrag(e)}),null===(t=Xe.current)||void 0===t||t.startDrag(e),A()}}Ie&&Pe(null)},onDragMove:e=>{const t=Xe.current;t&&e.target===t&&t.nodes().forEach(e=>{const t=i.getElementById(e.id());!t||t.x===e.x()&&t.y===e.y()||t.set({x:e.x(),y:e.y()})})},pageId:r.id,style:{position:"absolute",overflow:"hidden",top:0,left:0},children:n(m,{children:[t(ie,{width:h,height:x,fill:ae.workspaceBackgroundColor}),t(d,{x:we,y:Ee,scaleX:i.scale,scaleY:i.scale,name:"page-container",children:n(d,{name:"page-container-2",children:[t(d,{name:"page-background-group",x:xe.left,y:xe.top,children:t(le,{x:-pe.left,y:-pe.top,width:r.computedWidth+pe.left+pe.right,height:r.computedHeight+pe.top+pe.bottom,background:r.background,transparencyBackgroundColor:ae.transparencyBackgroundColor,name:"page-background",preventDefault:!1,scale:i.scale})}),n(d,{x:xe.left,y:xe.top,name:"elements-container",listening:!i.isPlaying&&i.role!==X.VIEWER,children:[t(f,{name:"elements-area",width:r.computedWidth,height:r.computedHeight,listening:!1}),t(de,{elements:r.children,store:i})]}),t(p,{name:"bleed",fill:ae.bleedColor,listening:!1,visible:i.bleedVisible&&(xe.top>0||xe.right>0||xe.bottom>0||xe.left>0),hideInExport:!0,sceneFunc:(e,t)=>{const{top:n,right:i,bottom:o,left:l}=pe,s=r.computedWidth,a=r.computedHeight,c=e._context;c.beginPath(),c.rect(0,0,l+s+i,n+a+o),c.rect(l,n,s,a),c.fillStyle=t.fill(),c.fill("evenodd")}}),R()===ge&&t(fe,{name:"hit-detection",x:-ct/2-dt,y:-ct/2-dt,width:ve+ct+2*dt,height:ye+ct+2*dt})]})}),t(g,{name:"workspace-background",points:[0,0,h,0,h,x,0,x,0,0,we,Ee,we,x-Ee,h-we,x-Ee,h-we,Ee,we,Ee],listening:!1,closed:!0,fill:ae.workspaceBackgroundColor}),t(d,{x:we,y:Ee,scaleX:i.scale,scaleY:i.scale,children:t(f,{name:"page-highlight",hideInExport:!0,x:-ct/2-dt,y:-ct/2-dt,width:ve+ct+2*dt,height:ye+ct+2*dt,stroke:rt?ae.activePageBorderColor:ae.pageBorderColor,strokeWidth:2,listening:!1,strokeScaleEnabled:!1})}),n(d,{x:we+xe.left*i.scale,y:Ee+xe.top*i.scale,scaleX:i.scale,scaleY:i.scale,name:"page-abs-container",children:[t(w,{ref:Xe,name:z,rotateAnchorAngle:Re,onDragStart:e=>{var t;const n=e.target.getStage();n&&n.getPointersPositions().length>=2?e.target.stopDrag():((null===(t=e.evt)||void 0===t?void 0:t.altKey)&&I&&i.selectedElements.forEach(e=>{const t=e.clone({},{skipSelect:!0}),n=r.children.indexOf(e);r.setElementZIndex(t.id,n)}),Me.current||(Me.current=!0,i.history.startTransaction()))},onDragEnd:()=>{Me.current&&(i.history.endTransaction(),Me.current=!1),Ke()},onTransformStart:()=>{i.history.startTransaction(),Ye.current=new Map(Fe.map(e=>[e.id,{width:e.width,height:e.height}])),Pe(null)},boundBoxFunc:(e,t)=>{var n,o,r,l;const s=null!==(o=null===(n=ue.boundBoxFunc)||void 0===n?void 0:n.call(ue,e,t))&&void 0!==o?o:t,a=Math.abs(s.width)<1||Math.abs(s.height)<1,c=Math.abs(e.width)<1||Math.abs(e.height)<1;if(a&&!c){return e}const d=i.selectedElements;if(1===d.length&&"table"===(null===(r=d[0])||void 0===r?void 0:r.type)){const t=d[0],n=Math.abs(e.width),i=Math.abs(e.height);if(n>0&&i>0){const o=Math.abs(s.width)/n,r=Math.abs(s.height)/i,l=t.width*o,a=t.height*r,c=Object.assign({},s);return l<t.minWidth&&(c.width=e.width),a<t.minHeight&&(c.height=e.height),_(c,s,e)}}return Ve&&Fe.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,c=!V(n),d=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,d="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?U(i,e.fontSize):1})(t,e,c,r);return r>=h&&l*d<h}),h=Object.assign({},t),u=t.width*e.width<0,m=t.height*e.height<0,g=u||d("x"),f=m||d("y"),p=f||!c&&g;return(g||!c&&f)&&(h.width=e.width),p&&(h.height=e.height),_(h,t,e)})(e,s,(null===(l=Xe.current)||void 0===l?void 0:l.getActiveAnchor())||"",Fe,Ye.current):s},onTransform:e=>{const t=Xe.current.nodes(),n=t[t.length-1];e.target===n&&setTimeout(()=>{Ne()},0)},onTransformEnd:e=>{je({}),i.history.endTransaction(),Ye.current=null,Ke(),Je()},visible:!i.isPlaying}),Ie&&Ie.map(({points:e,distance:o,box1:r,box2:l},s)=>n(d,{name:"distances-container",hideInExport:!0,listening:!1,children:[t(f,Object.assign({},r,{stroke:ae.distanceGuideStyle.stroke,strokeWidth:1,strokeScaleEnabled:!1})),t(f,Object.assign({},l,{stroke:ae.distanceGuideStyle.stroke,strokeWidth:1,strokeScaleEnabled:!1})),t(g,{points:[e[0].x,e[0].y,e[1].x,e[1].y],stroke:ae.distanceGuideStyle.stroke,strokeWidth:1,strokeScaleEnabled:!1}),t(g,{points:[e[1].x,e[1].y,e[2].x,e[2].y],stroke:ae.distanceGuideStyle.stroke,strokeWidth:1,strokeScaleEnabled:!1}),n(u,{x:(e[0].x+e[1].x)/2,y:(e[0].y+e[1].y)/2,offsetY:-10,scaleX:1/i.scale,scaleY:1/i.scale,children:[t(b,{cornerRadius:5,fill:ae.distanceGuideStyle.labelFill,pointerDirection:"down"}),t(y,{align:"center",verticalAlign:"middle",fill:ae.distanceGuideStyle.labelTextFill,padding:5,text:F({unit:i.unit,dpi:i.dpi,px:o})})]})]},s)),r._rendering&&n(d,{children:[t(f,{width:ve,height:ye,fill:"rgba(255,255,255,0.9)"}),t(y,{text:"Rendering...",fontSize:60,width:ve,height:ye,align:"center",verticalAlign:"middle"})]}),st&&t(st,{components:S,store:i,page:r,stageRef:Se,tooltipSafeArea:J}),at&&t(K,{children:t(at,Object.assign({components:S,store:i},Be.props))}),t(O,{store:i,pageId:r.id})]}),t(k,{store:i,page:r,width:h,height:x,scale:i.scale,xPadding:we,yPadding:Ee,bleedLeft:xe.left,bleedTop:xe.top}),t(ce,Object.assign({},Oe,{store:i})),t(se,{selection:$e}),D()>0&&n(d,{hideInExport:!0,children:[t(be,{name:"cache-bounds",x:h-(1===D()?250:210),y:x-(1===D()?95:45)}),t(be,{name:"cache-bounds-t",x:10,y:10})]}),B()&&t(y,{text:"Powered by polotno.com",fontSize:14,fill:"rgba(0,0,0,0.6)",x:h-170,y:x-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(d,{name:"line-guides"})]})}),Ae&<&&t(lt,{store:i,page:r,xPadding:we,yPadding:Ee,layout:L})]})});
|
|
@@ -8,6 +8,6 @@ type ShapeProps = {
|
|
|
8
8
|
element: TextElementType;
|
|
9
9
|
onClick: Function;
|
|
10
10
|
};
|
|
11
|
-
export declare const RenderTagElement: (({ element, store }: ShapeProps) => React.JSX.Element) & {
|
|
12
|
-
|
|
11
|
+
export declare const RenderTagElement: (({ element, store }: ShapeProps) => React.JSX.Element) & React.NamedExoticComponent<ShapeProps> & {
|
|
12
|
+
readonly type: ({ element, store }: ShapeProps) => React.JSX.Element;
|
|
13
13
|
};
|
|
@@ -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 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})})})]})});
|
|
1
|
+
var t=this&&this.__rest||function(t,e){var o={};for(var r in t){Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(o[r]=t[r])}if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(r=Object.getOwnPropertySymbols(t);n<r.length;n++){e.indexOf(r[n])<0&&Object.prototype.propertyIsEnumerable.call(t,r[n])&&(o[r[n]]=t[r[n]])}}return o};import{jsx as e,Fragment as o,jsxs as r}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 f}from"react-konva-utils";import{layout as u,drawLayout as g}from"render-tag";import{layoutTextOnPath as m,drawTextOnPathLayout as x}from"render-tag/path";import{activeAnchorOf as p,scaledFontSizeAttrs as w,roundedFontSizeAttrs as y,roundedTextDecorationAttrs as b,roundedGeometryPx as E,roundedPosition as O,textMinResizeWidth as v}from"../utils/px.js";import{flags as S}from"../utils/flags.js";import{applyFilter as M}from"./apply-filters.js";import{getLineHeight as j,usePrevious as z}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 C}from"./use-color.js";import{isGradient as I}from"@polotno/core/gradient";import{detectSize as P}from"@polotno/core/measure-html";import{generateBackgroundShapeFromRects as B,trimTrailingLetterSpace as T}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{shadowCastByBackground as $}from"@polotno/core/filters";import{isTouchDevice as J}from"../utils/screen.js";import{getLimitedFontSize as _}from"./text-element/max-font-size.js";import{normalizeRichTextHtml as A,extractFontSpecsFromHtml as L,scaleRichTextFontSizesInHtml as V}from"../utils/rich-text-html.js";import{RichEditor as H}from"./rich-editor.js";import{findFitFontSize as q}from"./text-element/fit-font-size.js";import{visiblePlaceholder as G}from"./text-element/placeholder.js";import{wrapHtmlForRenderTag as K}from"@polotno/core/reset-style";import{xmlEscape as Q}from"@polotno/core/xml";import{hasMeasuredHeight as U,resolveTextBoxHeight as Z}from"@polotno/core/text-types";export{K as wrapHtmlForRenderTag};function tt(t,e){return t!==e&&(!S.textVerticalResizeEnabled||t<e)}export const RenderTagElement=i(({element:i,store:et})=>{var ot;const rt=n.useRef(null),nt=n.useRef(null),[it,at]=n.useState(!1),st=n.useRef(i.height),lt=i.isSelected,ct=z(lt),{textVerticalResizeEnabled:ht}=S,dt=S.autoDeleteEmptyText,ft=z(i.fontFamily),ut=n.useMemo(()=>A(i.text,{fontSize:i.fontSize,fontFamily:i.fontFamily}),[i.text,i.fontSize,i.fontFamily]),gt=n.useMemo(()=>L(ut,{fontFamily:i.fontFamily,fontWeight:i.fontWeight,fontStyle:i.fontStyle}),[ut,i.fontFamily,i.fontWeight,i.fontStyle]),[mt]=k(et,gt,i.text||i.placeholder),xt=i._editModeEnabled;W(rt);const pt=mt?i.fontFamily:ft&&ft!==i.fontFamily?ft:"Arial",wt=C(i).fill,yt=I(i.fill),bt=I(i.stroke)&&!!i.strokeWidth,Et=!!i.strokeWidth&&(bt||yt),Ot="ellipsis"===S.textOverflow&&!i.curveEnabled&&U(i)&&!Et,vt=G(i.placeholder),St=!!vt&&!N(i.text),Mt=St?Q(vt):ut,jt=St?.6:i.a.opacity,zt=R(i,{fontFamily:pt,color:wt,forEditor:!Ot,textOverflow:S.textOverflow,text:Mt,textIsNormalized:!0}),kt=i.width||1,Rt=F(i.letterSpacing,i.fontSize),Yt=i.curveEnabled,Xt=function(t,e,o,r){return n.useMemo(()=>{if(r){return null}try{return u({html:K(t),width:Math.max(1,e),accuracy:"performance"})}catch(o){return console.error("render-tag layout failed:",o),null}},[t,e,o,r])}(zt,kt,mt,Yt),Ft=function(t,e,o){return n.useMemo(()=>{if(!e.curveEnabled){return null}const o=e.width||1,r=X(e),n=Y(o,r,e.curvePower,e.fontSize);try{return m({html:K(t),path:n,align:"center",textBaseline:"middle"})}catch(i){return console.error("render-tag/path layoutTextOnPath failed:",i),null}},[o,e.curveEnabled,e.curvePower,e.fontSize,e.width,e.height,t])}(zt,i,mt),Ct=j({fontLoaded:mt,fontFamily:i.fontFamily,fontSize:i.fontSize,lineHeight:i.lineHeight}),It=Yt?0:Math.max(null!==(ot=null==Xt?void 0:Xt.height)&&void 0!==ot?ot:0,i.fontSize*Ct),Pt=Ft?Ft.bounds:null,Bt=n.useMemo(()=>Xt?Xt.lines.map(t=>T({left:t.bounds.x,right:t.bounds.x+t.bounds.width,top:t.bounds.y,bottom:t.bounds.y+t.bounds.height},Rt)):[],[Xt,Rt]),Tt=n.useRef([]),Wt=n.useRef(null),Dt=n.useRef(!0),[,Nt]=n.useReducer(t=>t+1,0);n.useEffect(()=>{const t=Tt.current;t.length>0&&(Tt.current=[],t.forEach(t=>t()))});const $t=n.useCallback((t,e,o,r)=>{const n=D(`text ${i.id}`),a=()=>{et.history.ignore(t,e,o).then(()=>{Dt.current?(Tt.current.push(n),Nt()):n()})};r?queueMicrotask(a):a()},[i.id,et]),Jt=n.useCallback(t=>{const e=null!==Wt.current;Wt.current=t,e||$t(()=>{const t=Wt.current;Wt.current=null,d(i)&&tt(i.height,t)&&i.set({height:t})},!1,!0)},[i,$t]);n.useEffect(()=>{if(!mt){return}if(!Xt){return}if(!U(i)){return void $t(()=>{d(i)&&(U(i)||i.set({height:It}))},void 0,void 0,!0)}if(et.isPlaying){return}const{textOverflow:t}=S,e=tt(i.height,It),o=()=>Jt(It);if("change-font-size"!==t||it||xt||i.curveEnabled){"resize"===t&&e&&!it&&o()}else{const t=q(St?{toJSON:()=>Object.assign(Object.assign({},i.toJSON()),{text:Mt})}:i,{fontFamily:pt,color:wt,forEditor:!0},t=>{try{return u({html:K(t),width:kt,accuracy:"performance"}).height}catch(ot){return P(t).height}});t.fontSize!==i.fontSize?$t(()=>{if(!d(i)){return}const e=w(i,t.fontSize);void 0!==t.text&&t.text!==i.text&&(e.text=t.text),i.set(e)},!1,!0):e&&o()}}),n.useEffect(()=>()=>{Dt.current=!1;const t=Tt.current;t.length>0&&(Tt.current=[],t.forEach(t=>t()))},[]),n.useLayoutEffect(()=>{if(!mt||!i.curveEnabled||it){return}if(!Pt||!Pt.width){return}const t=t=>t&&ht?Math.max(t,Pt.height):Pt.height;Math.abs(Pt.width-i.width)<1&&Math.abs(t(i.height)-i.height)<1||$t(()=>{if(!d(i)){return}const e=Pt.width-i.width,o=t(i.height),r=o-i.height;if(Math.abs(e)<1&&Math.abs(r)<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:Pt.width,height:o,x:i.a.x+a,y:i.a.y+s})},!1,!0,!0)},[mt,i.curveEnabled,Pt,it,ht,$t]),n.useEffect(()=>{ct&&!lt&&dt&&""===N(i.text)&&i.removable&&!G(i.placeholder)&&et.deleteElements([i.id])},[dt,i.placeholder,i.removable,i.text,lt,ct]),n.useEffect(()=>h(i,()=>{const t=rt.current;t&&M(t,i)}),[Xt,Ft,i.a.width,i.a.height,i.shadowColor,i.shadowOffsetX,i.shadowOffsetY,i.shadowOpacity]);const _t=Z(i,It),At=Yt||!mt||it||et.isPlaying||"resize"!==S.textOverflow?i.a.height:ht?Math.max(i.a.height,It):It;let Lt=0;Yt||"middle"!==i.verticalAlign?Yt||"bottom"!==i.verticalAlign||(Lt=_t-It):Lt=(_t-It)/2;const Vt=i.backgroundPadding*(i.fontSize*Ct*.5),Ht=i.backgroundCornerRadius*(i.fontSize*Ct*.5),qt=n.useMemo(()=>!i.backgroundEnabled||i.curveEnabled||i.legacyBackground||0===Bt.length?"":B({rects:Bt,padding:Vt,cornerRadius:Ht}),[i.backgroundEnabled,i.curveEnabled,i.legacyBackground,Bt,Vt,Ht]),Gt=J(),Kt=n.useRef(null),Qt=n.useRef(i.width),Ut=n.useRef(null),Zt=n.useRef(null),te=n.useRef(""),ee=n.useRef(0),oe=n.useRef(0),re=i.width>0?i.a.width/i.width:1,ne={shadowEnabled:i.shadowEnabled&&$(i),shadowBlur:i.shadowBlur,shadowOffsetX:i.shadowOffsetX,shadowOffsetY:i.shadowOffsetY,shadowColor:i.shadowColor,shadowOpacity:i.shadowOpacity};return r(o,{children:[i.curveEnabled||i.legacyBackground?e(l,Object.assign({x:i.a.x,y:i.a.y,offsetX:Vt/re,offsetY:Vt/re,rotation:i.a.rotation,scaleX:re,scaleY:re,hideInExport:!i.showInExport,listening:!1,visible:i.backgroundEnabled,opacity:i.backgroundOpacity*jt,fill:i.backgroundColor},ne,{width:i.width+2*Vt,height:_t+2*Vt,cornerRadius:Ht})):e(s,Object.assign({name:"rendertag-background",x:i.a.x,y:i.a.y,offsetY:-Lt/re,rotation:i.a.rotation,scaleX:re,scaleY:re,hideInExport:!i.showInExport,listening:!1,visible:i.backgroundEnabled&&qt.length>0,opacity:i.backgroundOpacity*jt,fill:i.backgroundColor},ne,{data:qt})),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?-Lt/re:0,width:i.width,height:Math.max(i.height,It),listening:!1,visible:!xt&&!!(Yt?Ft:Xt),editModeEnabled:xt,opacity:jt,shadowEnabled:i.shadowEnabled&&!ne.shadowEnabled,shadowBlur:i.shadowBlur,shadowOffsetX:i.shadowOffsetX,shadowOffsetY:i.shadowOffsetY,shadowColor:i.shadowColor,shadowOpacity:i.shadowOpacity,hideInExport:!i.showInExport,sceneFunc:(t,e)=>{const o=t._context;if(o){try{if(Yt){if(!Ft||!Pt){return}const t=(i.width-Pt.width)/2-Pt.x;o.save(),o.translate(t,-Pt.y),x({layout:Ft,ctx:o}),o.restore()}else{if(!Xt){return}g({layout:Xt,width:kt,ctx:o,pixelRatio:1})}}catch(r){console.error("render-tag draw failed:",r)}}}}),e(l,{ref:nt,name:"element",x:i.a.x,y:i.a.y,listening:i.selectable,rotation:i.a.rotation,width:i.a.width,height:At,visible:!xt,draggable:Gt?i.draggable&<:i.draggable,preventDefault:!Gt||lt,opacity:0,hideInExport:!0,id:i.id,onDragMove:t=>{i.set({x:t.target.x(),y:t.target.y()})},onDragEnd:t=>{i.set(O(t.target))},onDblClick:t=>{i.contentEditable&&(Zt.current={x:t.evt.clientX,y:t.evt.clientY},i.toggleEditMode(!0))},onDblTap:t=>{var e;if(i.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,i.toggleEditMode(!0)}},onTransformStart:t=>{at(!0),st.current=i.height,Qt.current=i.width,Ut.current=null,Kt.current=t.target.position(),te.current=p(t.target),ee.current=i.a.rotation,oe.current=i.height},onTransform:e=>{const o=e.target,r=te.current,n="middle-left"===r||"middle-right"===r,a="top-center"===r||"bottom-center"===r,s=o.scaleX();if(n){const e=o.scaleX(),r=o.width()*e;let n=Math.max(r,v(Qt.current,i.fontSize));const a=i.toJSON();let s=0;if(i.curveEnabled){s=X(Object.assign(Object.assign({},a),{width:n}))}else{const{x:e,y:o,width:r,height:i}=a,l=t(a,["x","y","width","height"]),c=`${JSON.stringify(l)}|${pt}|${mt}|${wt}`;if(Ut.current&&Ut.current.signature===c&&n<=Ut.current.width){n=Ut.current.width,s=Ut.current.height}else{const t=t=>{const e=R(Object.assign(Object.assign({},a),{width:t}),{fontFamily:pt,color:wt,forEditor:!0,text:Mt,textIsNormalized:!0});try{return u({html:K(e),width:t,accuracy:"performance"})}catch(ot){return{height:P(e).height,lines:[]}}};let e=t(n);const o=Math.max(0,...e.lines.map(t=>t.bounds.x+t.bounds.width-Rt));o>n+.5&&o<=Qt.current+.5&&(n=Math.min(Math.ceil(o),Qt.current),e=t(n),Ut.current={signature:c,width:n,height:e.height}),s=e.height}}n>r&&Kt.current&&o.position(Kt.current),o.width(n),o.scaleX(1),o.scaleY(1);let l=S.textVerticalResizeEnabled?Math.max(s,st.current):s;"ellipsis"===S.textOverflow&&(l=st.current),o.height(l),i.set({width:o.width(),height:l,x:o.x(),y:o.y()})}else if(a){const t="resize"===S.textOverflow?Yt?(null==Pt?void 0:Pt.height)||i.fontSize:It:Ct*i.fontSize,e=o.height()*o.scaleY();if(e<t){if(o.height(t),Kt.current){if("top-center"===te.current){const e=ee.current*Math.PI/180,r=oe.current-t;o.x(Kt.current.x-r*Math.sin(e)),o.y(Kt.current.y+r*Math.cos(e))}else{o.position(Kt.current)}}}else{o.height(e)}o.scaleY(1),o.scaleX(1),oe.current=Math.max(t,e),i.set({x:o.x(),y:o.y(),height:o.height(),rotation:o.rotation()})}else{o.scaleX(1),o.scaleY(1),i.set({fontSize:i.fontSize*s,letterSpacing:i.letterSpacing,width:o.width()*s,x:o.x(),y:o.y(),rotation:o.rotation(),height:o.height()*s,shadowBlur:i.shadowBlur*s,shadowOffsetX:i.shadowOffsetX*s,shadowOffsetY:i.shadowOffsetY*s,strokeWidth:i.strokeWidth*s,text:V(i.text,s)})}Kt.current=e.target.position()},onTransformEnd:t=>{at(!1);const e=t.target.scaleX();t.target.scaleX(1),t.target.scaleY(1),i.set(Object.assign(Object.assign({},y(i,i.fontSize*e)),{width:E(t.target.width()*e),x:E(t.target.x()),y:E(t.target.y()),rotation:E(t.target.rotation()),text:V(i.text,e)}))}}),xt&&e(a,{x:i.a.x,y:i.a.y,rotation:i.a.rotation,offsetY:-Lt,children:e(f,{divProps:{style:{zIndex:20}},children:e(H,{element:i,onChange:t=>{const e=_({oldText:N(i.text),newText:N(t),element:i});i.set(Object.assign({text:t},w(i,e)))},onBlur:()=>{d(i)&&(i.set(b(i)),i.toggleEditMode(!1))},clickCoords:Zt.current})})})]})});
|
package/canvas/rich-editor.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var e=this&&this.__rest||function(e,t){var o={};for(var n in e){Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(o[n]=e[n])}if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(n=Object.getOwnPropertySymbols(e);r<n.length;r++){t.indexOf(n[r])<0&&Object.prototype.propertyIsEnumerable.call(e,n[r])&&(o[n[r]]=e[n[r]])}}return o};import{jsx as t}from"react/jsx-runtime";import o from"react";import n from"quill";import*as r from"mobx";import{nodeReaction as i}from"../utils/mobx.js";import{isAlive as l}from"mobx-state-tree";import{
|
|
1
|
+
var e=this&&this.__rest||function(e,t){var o={};for(var n in e){Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(o[n]=e[n])}if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(n=Object.getOwnPropertySymbols(e);r<n.length;r++){t.indexOf(n[r])<0&&Object.prototype.propertyIsEnumerable.call(e,n[r])&&(o[n[r]]=e[n[r]])}}return o};import{jsx as t}from"react/jsx-runtime";import o from"react";import n from"quill";import*as r from"mobx";import{nodeReaction as i}from"../utils/mobx.js";import{isAlive as l}from"mobx-state-tree";import{getDir as s,getMeasureCtx as a,getQuillEditorHtml as d,textLayoutWidth as c}from"@polotno/core/text-html";import{quillHtmlToModelText as u,isQuillFormatMixed as f,isBoldWeight as p}from"../utils/rich-text-html.js";import{resetStyleContent as m,wrapHtmlForRenderTag as h}from"@polotno/core/reset-style";import{layout as g,lineBaselineOffset as b}from"render-tag";import{removeTags as v}from"@polotno/core/text";import{cssFontFamily as x}from"@polotno/core/fonts";import{isGradient as y,firstStopColor as w}from"@polotno/core/gradient";import{getOptimalCaretColor as S}from"./text-element/caret-color.js";import{visiblePlaceholder as k}from"./text-element/placeholder.js";import{registerQuillUnrestrictedFontFormats as q}from"./quill-font-formats.js";import{ALL_QUILL_MIXED_KEYS as T,setActiveTextEditor as E,updateActiveTextFormat as C,clearActiveTextEditor as L,getActiveTextEditor as F}from"../utils/text-format-state.js";import R from"../utils/styled.js";import{applyOpacityToColor as $}from"@polotno/core/svg";import{localShadowOffset as O,shadowCastByBackground as j}from"@polotno/core/filters";export{$ as applyOpacityToColor};export const quillRef=r.observable({enabled:!1,currentFormat:{},pendingToolbarInteraction:!1,editor:r.observable.object({instance:null},{},{deep:!1})});const N=T;export function syncQuillFormatState(e,t){const o=t?e.getFormat(t):{},n=function(e,t){const o={};if(!t||t.length<=0){return o}const n=e.getContents(t.index,t.length);for(const r of N){f(n,r)&&(o[r]=!0)}return o}(e,t);r.runInAction(()=>{quillRef.currentFormat=o}),C(o,n,t)}const z="polotno-saved-selection";function M(){const e=window.getSelection();if(!e||0===e.rangeCount||e.isCollapsed){return}if("undefined"==typeof Highlight||!CSS.highlights){return}const t=e.getRangeAt(0).cloneRange();CSS.highlights.set(z,new Highlight(t)),Q()}function P(){"undefined"!=typeof CSS&&CSS.highlights&&CSS.highlights.delete(z)}function Q(){setTimeout(()=>{"undefined"!=typeof CSS&&CSS.highlights&&CSS.highlights.has(z)&&(document.querySelector(".polotno-portal")||W(document.activeElement)?Q():P())},300)}if("undefined"!=typeof document&&"undefined"!=typeof CSS&&CSS.highlights&&!document.querySelector("[data-polotno-highlight]")){const B=document.createElement("style");B.setAttribute("data-polotno-highlight",""),B.textContent=`::highlight(${z}) { background-color: Highlight; }`,document.head.appendChild(B)}function A(e,t){"text"===e.type&&t.push(e);for(const o of e.children||[]){A(o,t)}}export function computeMarkerVars(e){var t,o,n;const r=e.fontSize;if(!r||r<=0){return null}const i=x(e.fontFamily),l=p(e.fontWeight)?700:400,s="italic"===e.fontStyle?"italic":"normal",d=a();d.fontKerning="normal",d.font=`${r}px ${i}`;const c=d.measureText("M"),u=(null!==(t=c.fontBoundingBoxAscent)&&void 0!==t?t:0)/r,f=(null!==(o=c.fontBoundingBoxDescent)&&void 0!==o?o:0)/r,m=`font-family:${i};font-size:${r}px;font-weight:${l};font-style:${s};line-height:${e.lineHeight};letter-spacing:${e.letterSpacing}em`,v=h(`<div style="${m}"><ul><li>x</li></ul><ol><li>x</li></ol></div>`);let y;try{y=g({html:v,width:Math.max(12*r,600)})}catch(E){return null}const w=[];A(y.layoutRoot,w);const S=w.find(e=>"•"===e.text),k=w.find(e=>/^\d/.test(e.text));if(!S){return null}const q=S.style.fontSize,T=2.1*r;return{bulletLeft:S.x,bulletTop:S.y-b(q,q*u,q*f),bulletFontSize:q,numberGap:k?Math.max(0,T-k.x-(null!==(n=k.width)&&void 0!==n?n:0)):0}}export const RichTextContainer=R("div",o.forwardRef)`
|
|
2
2
|
.ql-editor {
|
|
3
3
|
outline: none;
|
|
4
4
|
/* anchor for the absolutely-positioned ::before placeholder below */
|
|
@@ -25,7 +25,7 @@ var e=this&&this.__rest||function(e,t){var o={};for(var n in e){Object.prototype
|
|
|
25
25
|
pointer-events: none;
|
|
26
26
|
opacity: 0;
|
|
27
27
|
}
|
|
28
|
-
${
|
|
28
|
+
${m}
|
|
29
29
|
|
|
30
30
|
/* ===== Editor-only list markers (Quill flat-DOM hack) ======================
|
|
31
31
|
Quill emits a FLAT <ol> with per-item data-list + ql-indent classes (not
|
|
@@ -155,4 +155,4 @@ var e=this&&this.__rest||function(e,t){var o={};for(var n in e){Object.prototype
|
|
|
155
155
|
&[style*='--polotno-gradient'] .ql-editor [style*='color:'] {
|
|
156
156
|
-webkit-text-fill-color: currentColor;
|
|
157
157
|
}
|
|
158
|
-
`;let
|
|
158
|
+
`;let D=["background","font-weight","color","gradient","font","italic","size","script","strike","underline","indent","list","direction"];export const setQuillFormats=e=>{D=e};let H=!1;function I(){H||(H=!0,console.warn("[polotno] The Quill 'bold' format is deprecated. Use the numeric 'font-weight' format instead, e.g. quill.format('font-weight', '700') or applyTextFormat({ fontWeight: 700 })."))}function _(e){return e?"700":"400"}export const createQuill=(t,o)=>{q();const r=new n(t,{toolbar:!1,keyboard:!1,placeholder:(null==o?void 0:o.placeholder)||void 0,clipboard:{matchVisual:!1},formats:D});!function(t){const o=t.format.bind(t),n=t.formatText.bind(t),r=t.getFormat.bind(t);t.format=(e,t,n)=>"bold"===e?(I(),o("font-weight",_(t),n)):o(e,t,n),t.formatText=(t,o,r,i,l)=>{if(r&&"object"==typeof r){if("bold"in r){I();const{bold:l}=r,s=e(r,["bold"]);return n(t,o,Object.assign(Object.assign({},s),{"font-weight":_(l)}),i)}return n(t,o,r,i)}return"bold"===r?(I(),n(t,o,"font-weight",_(i),l)):n(t,o,r,i,l)},t.getFormat=(...e)=>{const t=r(...e);return t&&null!=t["font-weight"]&&!("bold"in t)&&(t.bold=p(t["font-weight"])),t}}(r);const i=n.import("delta"),l=(e,t)=>t.compose((new i).retain(t.length(),{"font-weight":"700"}));return r.clipboard.addMatcher("STRONG",l),r.clipboard.addMatcher("B",l),r};export const setQuillContent=(e,t)=>{var o=e.clipboard.convert({html:"<div class='ql-editor' style='outline: none;'>"+t.replace(/\t/g,"")+"<p><br></p></div>",text:""});o.ops.forEach(e=>{"string"==typeof e.insert&&e.insert.includes("")&&(e.insert=e.insert.split("").join("\t"))}),e.setContents(o),e.history.clear()};export const RichEditor=({onBlur:e,onChange:n,element:a,clickCoords:f})=>{var p;const m=o.useRef(null),h=o.useRef(!1);o.useLayoutEffect(()=>{let t,o=!1,i=null,s=null,c=null,p=null,g=null;const b=()=>{if(!o&&m.current){try{t=createQuill(m.current,{placeholder:k(a.placeholder)}),r.runInAction(()=>{quillRef.editor.instance=t}),quillRef.pendingToolbarInteraction=!1,window.__polotnoQuill=t,E({instance:t,store:a.store,element:a});const o=e=>{e&&syncQuillFormatState(t,e)};t.on("text-change",()=>{const e=F(),r=e&&e.instance===t?e.lastSelection:null;o(t.getSelection()||r),setTimeout(()=>{var e,o;const r=t.root;if(!r||!r.isConnected){return}if(!l(a)){return}const i=r.innerHTML;h.current=!0,n(u(i,{fontSize:a.fontSize,fontFamily:a.fontFamily}));const s=t.getContents(),d=a.fill;let c=null,f=!0;for(const t of s.ops){if("string"!=typeof t.insert||"\n"===t.insert){continue}if(null===(e=t.attributes)||void 0===e?void 0:e.gradient){f=!1;break}const n=(null===(o=t.attributes)||void 0===o?void 0:o.color)||d;if(null===c){c=n}else if(n!==c){f=!1;break}}f&&c&&a.set({fill:c})},10)}),t.on("selection-change",o);const b=d(a,a.fontFamily);setQuillContent(t,b),h.current=!0;const v=m.current.closest(".polotno-workspace-inner"),x=null==v?void 0:v.scrollLeft,y=null==v?void 0:v.scrollTop;f?setCursorFromCoords(t,f):t.setSelection(0,0,"api"),v&&void 0!==x&&void 0!==y&&(v.scrollLeft=x,v.scrollTop=y);const w=t.root;p=t=>{const o=t.relatedTarget;(null==o?void 0:o.classList.contains("ql-clipboard"))||(W(o)||quillRef.pendingToolbarInteraction?M():setTimeout(()=>{quillRef.pendingToolbarInteraction||W(document.activeElement)?M():(P(),e())},0))},g=()=>{P()},w.addEventListener("blur",p),w.addEventListener("focus",g),i=w,s=e=>{var o,n;const r=t.getSelection();if(!r||0===r.length){return}const i=t.getText(r.index,r.length).replace(/\n$/,""),l=window.getSelection();let s="";if(l&&l.rangeCount>0){const e=l.getRangeAt(0);let t=e.cloneContents(),o=e.startContainer;o&&o.nodeType===Node.TEXT_NODE&&(o=o.parentNode);let n=e.endContainer;if(n&&n.nodeType===Node.TEXT_NODE&&(n=n.parentNode),o&&o===n){let e=o;for(;e&&e!==w&&e.nodeType===Node.ELEMENT_NODE;){const o=e.tagName;if("SPAN"!==o&&"EM"!==o&&"STRONG"!==o&&"U"!==o&&"S"!==o&&"A"!==o){break}const n=e.cloneNode(!1);n.appendChild(t),t=n,e=e.parentNode}}const r=document.createElement("div");r.appendChild(t),s=r.innerHTML}if(null===(o=e.clipboardData)||void 0===o||o.setData("text/plain",i),s){const t='<!DOCTYPE html><html><head><meta charset="utf-8"></head><body>\x3c!--StartFragment--\x3e<div style="white-space: pre-wrap; overflow-wrap: break-word;">'+s+"</div>\x3c!--EndFragment--\x3e</body></html>";null===(n=e.clipboardData)||void 0===n||n.setData("text/html",t)}e.preventDefault()},c=e=>{s&&s(e);const o=t.getSelection();o&&o.length>0&&t.deleteText(o.index,o.length)},i.addEventListener("copy",s),i.addEventListener("cut",c)}catch(b){console.error("RichEditor init failed:",b)}}};return m.current?b():queueMicrotask(b),()=>{o=!0,i&&p&&i.removeEventListener("blur",p),i&&g&&i.removeEventListener("focus",g),P(),i&&s&&c&&(i.removeEventListener("copy",s),i.removeEventListener("cut",c)),r.runInAction(()=>{quillRef.editor.instance=null,quillRef.currentFormat={}}),L(t),delete window.__polotnoQuill}},[]),o.useEffect(()=>i(a,()=>`${a.text}\0${a.fontSize}\0${a.fontFamily}`,()=>{const e=quillRef.editor.instance;if(!e){return}if(h.current){return void(h.current=!1)}const t=e.getSelection();setQuillContent(e,d(a,a.fontFamily)),h.current=!0,t&&(e.setSelection(t.index,t.length),syncQuillFormatState(e,e.getSelection()))},{fireImmediately:!0}),[]),o.useEffect(()=>i(a,()=>`${a.fontFamily}\0${a.fontSize}\0${a.fontWeight}\0${a.fontStyle}\0${a.lineHeight}\0${a.letterSpacing}\0${s(v(a.text))}`,()=>{const e=m.current;if(!e){return}const t="ltr"===s(v(a.text)),o=computeMarkerVars(a);o&&e.style.setProperty("--rt-number-gap",`${o.numberGap}px`),o&&t?(e.style.setProperty("--rt-bullet-left",`${o.bulletLeft}px`),e.style.setProperty("--rt-bullet-top",`${o.bulletTop}px`),e.style.setProperty("--rt-bullet-fs",`${o.bulletFontSize}px`),e.classList.add("rt-marker-geom")):e.classList.remove("rt-marker-geom")},{fireImmediately:!0}),[]),o.useEffect(()=>{window.addEventListener("blur",e);const t=t=>{var o;const n=t.target;"number"==typeof(null==n?void 0:n.nodeType)&&(null===(o=m.current)||void 0===o?void 0:o.contains(n))||W(n)||quillRef.pendingToolbarInteraction||(P(),e())};return window.addEventListener("mousedown",t),window.addEventListener("touchstart",t),()=>{window.removeEventListener("blur",e),window.removeEventListener("mousedown",t),window.removeEventListener("touchstart",t)}},[]);const g={color:a.fill};a.fill.indexOf("gradient")>=0&&(g["--polotno-gradient"]=a.fill,g.color="transparent"),a.strokeWidth>0&&(g.WebkitTextStroke=`${a.strokeWidth}px ${w(a.stroke)}`,g.paintOrder="stroke fill");const b=y(a.fill)?w(a.fill):S(a),{x:q,y:T}=O({shadowOffsetX:a.shadowOffsetX,shadowOffsetY:a.shadowOffsetY,rotation:a.a.rotation}),C=a.shadowEnabled&&!j(a);return t(RichTextContainer,{ref:m,style:Object.assign(Object.assign({},g),{fontSize:a.fontSize,fontFamily:x(a.fontFamily),fontWeight:a.fontWeight,fontStyle:a.fontStyle,"--polotno-text-decoration":a.textDecoration||"none",textTransform:a.textTransform,width:c(a.a.width,a.letterSpacing,a.fontSize),lineHeight:a.lineHeight,letterSpacing:a.letterSpacing*a.fontSize+"px",textAlign:a.align,opacity:Math.max(a.a.opacity,.2),textShadow:C?`${q}px ${T}px ${a.shadowBlur}px ${$(a.shadowColor,null!==(p=a.shadowOpacity)&&void 0!==p?p:1)}`:void 0,caretColor:b}),dir:s(v(a.text))})};function W(e){const t=e;return!("function"!=typeof(null==t?void 0:t.closest)||!t.closest(".sketch-picker")&&!t.closest("[data-polotno-keep-focus]")&&!t.closest(".polotno-portal")&&!t.closest(".polotno-toolbar"))}export function setCursorFromCoords(e,t){if(!e||!t){return}const{x:o,y:r}=t;try{let t=null;if(document.caretRangeFromPoint){t=document.caretRangeFromPoint(o,r)}else if(document.caretPositionFromPoint){const e=document.caretPositionFromPoint(o,r);e&&(t=document.createRange(),t.setStart(e.offsetNode,e.offset))}if(t){const o=n.find(t.startContainer,!0);if(o){const n=o.offset(e.scroll)+t.startOffset;return void e.setSelection(n,0,"api")}}}catch(i){}e.setSelection(0,0,"api")}
|
package/canvas/rules.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ type TopRulesProps = {
|
|
|
10
10
|
layout?: 'vertical' | 'horizontal';
|
|
11
11
|
renderOnlyActivePage?: boolean;
|
|
12
12
|
};
|
|
13
|
-
export declare const TopRules: (({ store, width, height, pageSizes, layout, renderOnlyActivePage, }: TopRulesProps) => React.JSX.Element | null) & {
|
|
14
|
-
|
|
13
|
+
export declare const TopRules: (({ store, width, height, pageSizes, layout, renderOnlyActivePage, }: TopRulesProps) => React.JSX.Element | null) & React.NamedExoticComponent<TopRulesProps> & {
|
|
14
|
+
readonly type: ({ store, width, height, pageSizes, layout, renderOnlyActivePage, }: TopRulesProps) => React.JSX.Element | null;
|
|
15
15
|
};
|
|
16
16
|
export {};
|
|
@@ -5,7 +5,7 @@ type TableProps = {
|
|
|
5
5
|
store: StoreType;
|
|
6
6
|
element: TableElementType;
|
|
7
7
|
};
|
|
8
|
-
export declare const TableElement: (({ element, store }: TableProps) => React.JSX.Element) & {
|
|
9
|
-
|
|
8
|
+
export declare const TableElement: (({ element, store }: TableProps) => React.JSX.Element) & React.NamedExoticComponent<TableProps> & {
|
|
9
|
+
readonly type: ({ element, store }: TableProps) => React.JSX.Element;
|
|
10
10
|
};
|
|
11
11
|
export {};
|
package/canvas/text-element.d.ts
CHANGED
|
@@ -16,6 +16,6 @@ export declare const getLineHeight: ({ fontLoaded, fontFamily, fontSize, lineHei
|
|
|
16
16
|
}) => number;
|
|
17
17
|
export declare function usePrevious(value: any): any;
|
|
18
18
|
export { getCurvePath } from '@polotno/core/text-html';
|
|
19
|
-
export declare const TextElement: (({ element, store }: ShapeProps) => React.JSX.Element) & {
|
|
20
|
-
|
|
19
|
+
export declare const TextElement: (({ element, store }: ShapeProps) => React.JSX.Element) & React.NamedExoticComponent<ShapeProps> & {
|
|
20
|
+
readonly type: ({ element, store }: ShapeProps) => React.JSX.Element;
|
|
21
21
|
};
|
package/canvas/tooltip.d.ts
CHANGED
|
@@ -11,6 +11,28 @@ export declare const Tooltip: (({ store, page, components, stageRef, tooltipSafe
|
|
|
11
11
|
left?: number;
|
|
12
12
|
right?: number;
|
|
13
13
|
};
|
|
14
|
-
}) => React.JSX.Element | null) & {
|
|
15
|
-
|
|
14
|
+
}) => React.JSX.Element | null) & React.NamedExoticComponent<{
|
|
15
|
+
store: StoreType;
|
|
16
|
+
page: PageType;
|
|
17
|
+
components?: any;
|
|
18
|
+
stageRef?: any;
|
|
19
|
+
tooltipSafeArea?: {
|
|
20
|
+
top?: number;
|
|
21
|
+
bottom?: number;
|
|
22
|
+
left?: number;
|
|
23
|
+
right?: number;
|
|
24
|
+
};
|
|
25
|
+
}> & {
|
|
26
|
+
readonly type: ({ store, page, components, stageRef, tooltipSafeArea, }: {
|
|
27
|
+
store: StoreType;
|
|
28
|
+
page: PageType;
|
|
29
|
+
components?: any;
|
|
30
|
+
stageRef?: any;
|
|
31
|
+
tooltipSafeArea?: {
|
|
32
|
+
top?: number;
|
|
33
|
+
bottom?: number;
|
|
34
|
+
left?: number;
|
|
35
|
+
right?: number;
|
|
36
|
+
};
|
|
37
|
+
}) => React.JSX.Element | null;
|
|
16
38
|
};
|