polotno 4.12.0 → 4.12.1

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 CHANGED
@@ -1,48 +1,83 @@
1
1
  # Polotno
2
2
 
3
- Build modern image and video editing apps with a powerful, flexible SDK.
3
+ Design editor SDK. Embed a Canva-like editor in your product, generate designs from templates and data, and export them to PNG, JPEG, PDF, or video in the browser or on a server.
4
4
 
5
- **[Documentation](https://polotno.com/docs)** · **[Website](https://polotno.com/)**
5
+ Polotno ships React components and a framework-independent store. Use it from React, or from Vue, Angular, Svelte, and plain JavaScript through the [frameworkless integration](https://polotno.com/docs/frameworkless-integration). It is built on [Konva](https://konvajs.org/) and [react-konva](https://github.com/konvajs/react-konva).
6
6
 
7
- ## Installation
7
+ **[Documentation](https://polotno.com/docs)** · **[Website](https://polotno.com/)** · **[Build with AI](https://polotno.com/docs/build-with-ai)**
8
+
9
+ ## What you get
10
+
11
+ - **Editor** — canvas, toolbar, side panel, pages, and zoom controls. Every part can be replaced, hidden, or restyled.
12
+ - **Templates and automation** — designs are plain JSON. Load templates, fill variables, and generate variants from data.
13
+ - **Text, images, and media** — rich text and fonts, image crop and filters, AI background removal, SVG, GIF, and video with audio.
14
+ - **Video editing** — animations, timelines, and export to MP4 and GIF.
15
+ - **Import** — PDF and PSD files become editable designs.
16
+ - **Export** — PNG, JPEG, PDF with bleed and crop marks, SVG, HTML, PPTX, MP4, GIF.
17
+ - **Server-side rendering** — render the same JSON in Node.js with `polotno-node`, or use Polotno Cloud Render.
18
+ - **AI tools** — write assistant, background removal, and an MCP server plus skills for coding agents.
19
+
20
+ ## Install
8
21
 
9
22
  ```bash
10
23
  npm install polotno
11
24
  ```
12
25
 
13
- ## Quick Start
26
+ `polotno@4` is the React 19 line. For React 18, install `polotno@react18`.
27
+
28
+ ## Quick start
14
29
 
15
30
  ```jsx
16
- import React from 'react';
17
31
  import { PolotnoContainer, SidePanelWrap, WorkspaceWrap } from 'polotno';
18
32
  import { Toolbar } from 'polotno/toolbar/toolbar';
19
33
  import { ZoomButtons } from 'polotno/toolbar/zoom-buttons';
20
34
  import { SidePanel } from 'polotno/side-panel';
21
35
  import { Workspace } from 'polotno/canvas/workspace';
22
36
  import { createStore } from 'polotno/model/store';
37
+ import 'polotno/ui.css';
23
38
 
24
39
  const store = createStore({
25
- key: 'YOUR_API_KEY', // get your key at https://polotno.com/cabinet
26
- showCredit: true,
40
+ key: 'YOUR_API_KEY', // https://polotno.com/cabinet — the SDK warns in the console without one
27
41
  });
28
42
  store.addPage();
29
43
 
30
- export const App = () => {
31
- return (
32
- <PolotnoContainer style={{ width: '100vw', height: '100vh' }}>
33
- <SidePanelWrap>
34
- <SidePanel store={store} />
35
- </SidePanelWrap>
36
- <WorkspaceWrap>
37
- <Toolbar store={store} />
38
- <Workspace store={store} />
39
- <ZoomButtons store={store} />
40
- </WorkspaceWrap>
41
- </PolotnoContainer>
42
- );
43
- };
44
+ export const App = () => (
45
+ <PolotnoContainer style={{ width: '100vw', height: '100vh' }}>
46
+ <SidePanelWrap>
47
+ <SidePanel store={store} />
48
+ </SidePanelWrap>
49
+ <WorkspaceWrap>
50
+ <Toolbar store={store} />
51
+ <Workspace store={store} />
52
+ <ZoomButtons store={store} />
53
+ </WorkspaceWrap>
54
+ </PolotnoContainer>
55
+ );
56
+ ```
57
+
58
+ Export the current design:
59
+
60
+ ```js
61
+ await store.waitLoading();
62
+ const png = await store.toDataURL();
63
+ const pdf = await store.toPDFDataURL();
44
64
  ```
45
65
 
66
+ ## AI coding agents
67
+
68
+ Install the official skills so your agent knows the SDK before it writes code. `polotno-sdk` is for developers integrating the editor; `polotno-design` is for producing designs.
69
+
70
+ ```bash
71
+ # Claude Code: both skills plus the docs MCP server
72
+ claude plugin marketplace add polotno-project/skills
73
+ claude plugin install polotno@polotno
74
+
75
+ # Cursor, Codex, Copilot, Windsurf, Cline, and others
76
+ npx skills add polotno-project/skills
77
+ ```
78
+
79
+ Every docs page is also available as markdown by appending `.md` to its URL, and https://polotno.com/llms.txt indexes them. Full guide: https://polotno.com/docs/build-with-ai
80
+
46
81
  ## License
47
82
 
48
- See [LICENSE.md](./LICENSE.md).
83
+ Polotno is commercial software. See [LICENSE.md](./LICENSE.md) and [pricing](https://polotno.com/sdk/pricing).
@@ -160,7 +160,7 @@ export declare const selectVideo: ({ src, droppedPos, targetElement, store, attr
160
160
  } & {
161
161
  readonly locked: boolean;
162
162
  readonly a: import("../../model/shape-model.js").AnimatedAttrs;
163
- animated(attr: any): any;
163
+ animated(attr: string): any;
164
164
  readonly timeRange: {
165
165
  start: number;
166
166
  end: number;
@@ -328,7 +328,7 @@ export declare const selectVideo: ({ src, droppedPos, targetElement, store, attr
328
328
  } & {
329
329
  readonly locked: boolean;
330
330
  readonly a: import("../../model/shape-model.js").AnimatedAttrs;
331
- animated(attr: any): any;
331
+ animated(attr: string): any;
332
332
  readonly timeRange: {
333
333
  start: number;
334
334
  end: number;
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,Tag as v,Text as b,Transformer as y}from"react-konva";import{useWorkspaceStyle as w}from"./workspace-style.js";import{ROLES as E}from"../model/store.js";import X from"konva";import Y from"./element.js";import{DrawingLayer as S}from"./drawing-layer.js";import{ensureDragOrder as k,useSnap as A}from"./use-transformer-snap.js";import{useCanvasImage as M,useImageLoader as P}from"./image-element.js";import{getCrop as I}from"../utils/crop.js";import{___ as O,____ as R,isCreditVisible as j}from"../utils/validate-key.js";import{getClientRect as D,getCorners as B,getTotalClientRect as C,polygonsIntersect as T}from"../utils/math.js";import{pxToUnitRounded as W,pxToUnitString as G}from"../utils/unit.js";import{isCornerAnchor as L,MAIN_TRANSFORMER_NAME as F,textMinResizeWidth as V,textMinWidthIsMeasured as z}from"../utils/px.js";import{restoreHeldPoint as U}from"./transform-box.js";import{flags as Z}from"../utils/flags.js";import{useColor as _}from"./use-color.js";import{isGradient as H}from"@polotno/core/gradient";import{Html as J}from"react-konva-utils";const N={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},K=e=>{const t=(e%180+180)%180;return t<.1||180-t<.1},$=e=>{if(!e.length){return null}const t=K(e[0].rotation)?0:e[0].rotation;return e.every(e=>K(e.rotation-t))?t:null},Q=e=>e.selectedShapes.filter(e=>!e._cropModeEnabled),q={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){q[e]=q[e]||t,Object.assign(q[e],t)}const ee=e=>t(f,Object.assign({},e,{preventDefault:!1})),te=n=>{var{url:i}=n,o=e(n,["url"]);const[r,l]=M(i,"anonymous"),s=r?I(r,{width:o.width,height:o.height},"center-middle"):{};return P(l,i,"page background"),t(h,Object.assign({image:r},o,s))},ne=e=>{const n=_({a:{width:e.width,height:e.height},width:e.width,height:e.height},e.fill);return t(f,Object.assign({},e,n))},ie=i=>{const{background:r,scale:l,borderColor:s,transparencyBackgroundColor:a}=i,c=e(i,["background","scale","borderColor","transparencyBackgroundColor"]),d=o.useMemo(()=>!!X.Util.colorToRGBA(r)||H(r),[r]),h=o.useMemo(()=>{if(H(r)){return!0}const e=X.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(ne,Object.assign({fill:r},c)):t(te,Object.assign({url:r},c))]})},oe=r(({selection:e})=>{const{selectionRectStyle:n}=w();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 re(e){let t=180*e/Math.PI;return t%=360,t>180?t-=360:t<-180&&(t+=360),Math.round(t)}const le=r(({x:e,y:o,width:r,height:l,rotation:s,anchor:a,store:c})=>{const{transformLabelStyle:d}=w();if(void 0===e||void 0===o||void 0===r||void 0===l||void 0===s||void 0===a){return null}const h=D({x:e,y:o,width:r,height:l,rotation:X.Util.radToDeg(s)}),m=(l/2+70)*Math.cos(s-Math.PI/2),g=(l/2+70)*Math.sin(s-Math.PI/2),f=W({unit:c.unit,dpi:c.dpi,px:r/c.scale,precious:"px"===c.unit?0:1})+" x "+W({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(v,{cornerRadius:5,fill:d.fill}),t(b,{align:"center",verticalAlign:"middle",fill:d.textFill,padding:8,text:re(s).toString()+"°"})]}),n(u,{x:(h.minX+h.maxX)/2,y:h.maxY+20,visible:"rotater"!==a,children:[t(v,{cornerRadius:5,fill:d.fill,pointerDirection:"up",pointerHeight:0,pointerWidth:0}),t(b,{align:"center",verticalAlign:"middle",fill:d.textFill,padding:8,text:f})]})]})}),se=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(Y,{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 ae=null;export const registerNextDomDrop=e=>{ae=e};const ce=atob("UG9sb3RubyBmcmVlIGxpY2Vuc2UgbGltaXRhdGlvbiBleGNlZWRlZCAtIFBsZWFzZSB1cGdyYWRlIHlvdXIgYWNjb3VudC4="),de=atob("I2MwMzkyYg=="),he=atob("djAuOS4y"),ue=e=>t(i,{children:n(u,{fill:de,height:200,children:[t(v,{fill:de}),t(b,Object.assign({},e,{fill:"white",text:ce,height:void 0,padding:10,fontSize:20}))]})}),me=atob("RlJFRSAgVFJJQUwgIExJQ0VOU0U="),ge=(atob("UG93ZXJlZCBieSBQb2xvdG5v"),atob("TElDRU5TRSAgS0VZICBJUyAgTUlTU0lORw==")),fe=atob("UGxlYXNlIGFjdGl2YXRlIHlvdXIgbGljZW5zZS4KTGljZW5zZSByZWxhdGVkIHF1ZXN0aW9uczoKcG9sb3Ruby5jb20vY29udGFjdA=="),pe=e=>{const i=1===R(),o=i?ge:me,r=i?230:195;return n(d,Object.assign({},e,{listening:!1,children:[t(f,{fill:de,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:fe,fill:"rgba(0,0,0,0.6)",fontSize:14,y:30,listening:!1})]}))};export default r(({store:i,page:r,width:h,height:Y,pageControlsEnabled:M,components:P,altCloneEnabled:I,groupSelectionMode:W="drill",viewportSize:_,layout:H="vertical",tooltipSafeArea:te,transformerSafeArea:ne})=>{var re,ce;const de=w(),me=de.transformerStyle,ge=N,fe=r.computedBleed,xe=i.bleedVisible?fe:c,ve=r.computedWidth+xe.left+xe.right,be=r.computedHeight+xe.top+xe.bottom,ye=(h-ve*i.scale)/2,we=(Y-be*i.scale)/2,Ee=o.useRef(null),Xe=o.useRef(null),Ye=o.useRef(null),Se=o.useRef(null),ke=null==M||M,Ae=o.useRef(!1),[Me,Pe]=o.useState(null),[Ie,Oe]=o.useState({}),[Re,je]=o.useState(0),De=useContextMenu({store:i}),Be=i.selectedElements.find(e=>e._cropModeEnabled),Ce=i.selectedElements.find(e=>e.curveEnabled),Te=i.selectedShapes.filter(e=>!e.resizable).length>0,We=i.selectedShapes.filter(e=>!e.draggable).length>0,Ge=i.selectedElements.filter(e=>!e.visible).length>0,Le=Q(i),Fe=1!==i.selectedElements.length||"group"===(null===(re=i.selectedElements[0])||void 0===re?void 0:re.type),Ve=null!==(ce=$(Le))&&void 0!==ce?ce:0,ze=e=>Fe&&Le.length>0&&Le.every(t=>((e,t,n)=>{if(!K(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,Ve)),Ue=!Fe&&i.selectedElements[0].keepRatio,Ze=ze("x"),_e=ze("y"),He=()=>{var t,n,o;const r=Ee.current;if(!r){return[]}const l=r.getStage();if(!l){return[]}const s=Q(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=q[d],u=Object.assign(Object.assign({},ge),h||{});h&&("svg"!==d&&"image"!==d&&"gif"!==d||i.selectedElements[0].keepRatio||(u.enabledAnchors=ge.enabledAnchors),"text"===d&&Z.textVerticalResizeEnabled&&(u.enabledAnchors=null===(n=q.text.enabledAnchors)||void 0===n?void 0:n.concat(["bottom-center","top-center"])),"text"===d&&c&&i.selectedElements[0].curveEnabled&&(u.enabledAnchors=q.many.enabledAnchors)),(Ze||_e)&&(u.enabledAnchors=[...u.enabledAnchors||[],...Ze?["middle-left","middle-right"]:[],..._e?["top-center","bottom-center"]:[]]);const{boundBoxFunc:m}=me,g=e(me,["boundBoxFunc"]);r.setAttrs(Object.assign(Object.assign(Object.assign({},u),g),{name:F})),Te&&r.enabledAnchors([]),We&&r.rotateEnabled(!1);const f=r.nodes();if(f.length===a.length&&a.every((e,t)=>f[t]===e)||r.nodes(a),Fe&&a.length){const e=$(s);null===e||K(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=Ee.current)||void 0===e?void 0:e.isTransforming()){return}const t=He();t.find(e=>null==e?void 0:e.isDragging())&&(t.forEach(e=>{e.isDragging()||null==e||e.startDrag()}),k())},[i.selectedShapes,Be,Te,Ge,We,Ce,Ze,_e,Ue,Ve,me]);const Je=()=>{var e,t;const n=Ee.current;if(!n){return}if(!n.isTransforming()){return void Oe({})}if(!n.nodes().length||!n.isTransforming()){return}const i=n.__getNodeRect(),o=null==n?void 0:n.getActiveAnchor(),r=n.getStage();Oe({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})},Ne=o.useCallback(()=>{var e;if(null===(e=Ee.current)||void 0===e?void 0:e.isTransforming()){return}const t=Ee.current;if(!t||!t.nodes().length){return void je(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==ne?void 0:ne.top)||0,bottom:Y-((null==ne?void 0:ne.bottom)||0),left:(null==ne?void 0:ne.left)||0,right:h-((null==ne?void 0:ne.right)||0)},me.rotateAnchorOffset,t.rotation());je(i)},[ne,h,Y]);o.useEffect(()=>{var e;null===(e=Ee.current)||void 0===e||e.update(),Je(),Ne()},[i.scale,Ne]),o.useEffect(()=>{Ne()},[i.selectedShapes,Ne]);const Ke=l(()=>({visible:!1,x1:0,y1:0,x2:0,y2:0})),$e=o.useRef(!1),Qe=e=>{const t=Ye.current;if(!t||i.role===E.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=He();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 X.Shape?[e]:e instanceof X.Container?e.find("Shape"):[]).some(e=>e.intersects(n)));if(l){for(const[t,n]of X.DD._dragElements){"ready"!==n.dragStatus||n.node!==e.target&&!n.node.isAncestorOf(e.target)||X.DD._dragElements.delete(t)}l._createDragElement(e),"touches"in e.evt&&e.evt.cancelable&&l.preventDefault()&&e.evt.preventDefault()}},qe=s(e=>{var t,n,o,r,l,s,a;if(i.role===E.VIEWER){return}$e.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,Ke.visible=!0,Ke.x1=u.x,Ke.y1=u.y,Ke.x2=u.x,Ke.y2=u.y,(null!==(a=null===(s=e.target.getStage())||void 0===s?void 0:s.getPointersPositions().length)&&void 0!==a?a:0)>=2&&(Ke.visible=!1))});(({stageRef:e,containerRef:t,viewportSize:n})=>{o.useEffect(()=>{var n;const i=null===(n=t.current)||void 0===n?void 0:n.closest(".polotno-workspace-inner");function o(){var n;if(!e.current){return}const o=null===(n=t.current)||void 0===n?void 0:n.getBoundingClientRect(),r=null==i?void 0:i.getBoundingClientRect();if(!o||!r){return}const l=Math.max(0,r.left-o.left-100),s=Math.max(0,r.top-o.top-100);e.current.position({x:-l,y:-s}),e.current.container().style.transform=`translate(${l}px, ${s}px)`}return o(),null==i||i.addEventListener("scroll",o),()=>{null==i||i.removeEventListener("scroll",o)}},[n.width,n.height])})({stageRef:Ye,containerRef:Se,viewportSize:_}),o.useEffect(()=>{const e=s(e=>{var t,n,i,o,r,l;if(!Ke.visible){return}null===(t=Ye.current)||void 0===t||t.setPointersPositions(e);let s=null===(n=Ye.current)||void 0===n?void 0:n.getPointerPosition();s?(s.x-=null!==(o=null===(i=Ye.current)||void 0===i?void 0:i.x())&&void 0!==o?o:0,s.y-=null!==(l=null===(r=Ye.current)||void 0===r?void 0:r.y())&&void 0!==l?l:0):s={x:Ke.x2,y:Ke.y2},Ke.x2=s.x,Ke.y2=s.y}),t=s(()=>{if(!Ke.visible){return}if(!Ye.current){return}const e=Ye.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=[];Ye.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=B(r.a).map(e=>a.point(e));T(e,c)&&n.push(r.top.id)});const o=[...new Set(n)];$e.current=!0,i.selectElements(o)}Ke.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 et=o.useCallback(e=>{if(!i.selectedElements[0]){return}if(e&&i.selectedElementsIds.includes(e)){return}const t=C(i.selectedShapes),n=e?i.getElementById(e):{x:0,y:0,width:r.computedWidth,height:r.computedHeight,rotation:0},o=D(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(Me)!==JSON.stringify(l)&&Pe(l)},[i,r]);o.useEffect(()=>{i.selectedElements[0]&&i.distanceGuidesVisible?et():Me&&Pe(null)},[i.distanceGuidesVisible,et,i.selectedShapes.map(e=>`${e.x},${e.y},${e.width},${e.height},${e.rotation}`).join("|")]);const tt=o.useRef(!1);o.useEffect(()=>{var e;let t;const n=null===(e=Se.current)||void 0===e?void 0:e.closest(".polotno-workspace-inner"),i=()=>{tt.current=!0,clearTimeout(t),t=setTimeout(()=>{tt.current=!1},300)};return null==n||n.addEventListener("scroll",i),()=>{clearTimeout(t),null==n||n.removeEventListener("scroll",i)}},[]),o.useEffect(()=>{const e=Ye.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=Ee.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===Ee.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=Ee.current)||void 0===e?void 0:e.isDragging())&&Ee.current.stopDrag(),null===(t=Ee.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 nt=e=>{if(i.role===E.VIEWER){return}if(i.activePage!==r&&r.select(),tt.current){return}if($e.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||Ke.visible)){return i.selectElements([]),void i.selectPages([])}if(n&&!t){const e=Ye.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"===W){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([]))}};A(Ee,i);const it=i.activePage===r,ot=i._selectedPagesIds.includes(r.id),rt=null==P?void 0:P.PageControls,lt=null==P?void 0:P.Tooltip,st=null==P?void 0:P.ContextMenu,at=1/i.scale,ct=0/i.scale;return n("div",{ref:Se,onDragOver:e=>e.preventDefault(),onDrop:e=>{if(e.preventDefault(),i.role===E.VIEWER){return}if(!Ye.current){return}Ye.current.setPointersPositions(e);const t=Ye.current.findOne(".elements-container"),n=null==t?void 0:t.getRelativePointerPosition(),o=Ye.current.getPointerPosition(),l=Ye.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];ae&&n&&(ae(n,a,{elements:s,page:r}),ae=null)},style:{position:"relative",width:h+"px",height:Y+"px",overflow:"hidden",flexShrink:0},className:"polotno-page-container"+(it?" active-page":""),children:[t(x,{ref:Ye,eventBatchFunc:a,width:Math.min(h,_.width+200),height:Math.min(_.height+200,Y),onClick:nt,onTap:nt,onContextMenu:e=>{if(e.evt.preventDefault(),i.role===E.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 De.close()}i.selectedElementsIds.indexOf(r)>=0||i.selectElements([r]),De.open({x:e.evt.clientX,y:e.evt.clientY})},onMouseDown:e=>{Qe(e),qe(e)},onTouchStart:Qe,onMouseMove:e=>{if(!i.distanceGuidesVisible&&!e.evt.altKey){return void(Me&&Pe(null))}const t=e.target.findAncestor(".element",!0),n=null==t?void 0:t.id();et(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=He();e.target.stopDrag(),n.forEach(t=>{t.isDragging()||t.startDrag(e)}),null===(t=Ee.current)||void 0===t||t.startDrag(e),k()}}Me&&Pe(null)},onDragMove:e=>{const t=Ee.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(ee,{width:h,height:Y,fill:de.workspaceBackgroundColor}),t(d,{x:ye,y:we,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(ie,{x:-fe.left,y:-fe.top,width:r.computedWidth+fe.left+fe.right,height:r.computedHeight+fe.top+fe.bottom,background:r.background,transparencyBackgroundColor:de.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!==E.VIEWER,children:[t(f,{name:"elements-area",width:r.computedWidth,height:r.computedHeight,listening:!1}),t(se,{elements:r.children,store:i})]}),t(p,{name:"bleed",fill:de.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}=fe,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")}}),O()===he&&t(ue,{name:"hit-detection",x:-at/2-ct,y:-at/2-ct,width:ve+at+2*ct,height:be+at+2*ct})]})}),t(g,{name:"workspace-background",points:[0,0,h,0,h,Y,0,Y,0,0,ye,we,ye,Y-we,h-ye,Y-we,h-ye,we,ye,we],listening:!1,closed:!0,fill:de.workspaceBackgroundColor}),t(d,{x:ye,y:we,scaleX:i.scale,scaleY:i.scale,children:t(f,{name:"page-highlight",hideInExport:!0,x:-at/2-ct,y:-at/2-ct,width:ve+at+2*ct,height:be+at+2*ct,stroke:ot?de.activePageBorderColor:de.pageBorderColor,strokeWidth:2,listening:!1,strokeScaleEnabled:!1})}),n(d,{x:ye+xe.left*i.scale,y:we+xe.top*i.scale,scaleX:i.scale,scaleY:i.scale,name:"page-abs-container",children:[t(y,{ref:Ee,name:F,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)}),Ae.current||(Ae.current=!0,i.history.startTransaction()))},onDragEnd:()=>{Ae.current&&(i.history.endTransaction(),Ae.current=!1),Ne()},onTransformStart:()=>{i.history.startTransaction(),Xe.current=new Map(Le.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=me.boundBoxFunc)||void 0===n?void 0:n.call(me,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),U(c,s,e)}}return Fe&&Le.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=!L(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?V(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),U(h,t,e)})(e,s,(null===(l=Ee.current)||void 0===l?void 0:l.getActiveAnchor())||"",Le,Xe.current):s},onTransform:e=>{const t=Ee.current.nodes(),n=t[t.length-1];e.target===n&&setTimeout(()=>{Je()},0)},onTransformEnd:e=>{Oe({}),i.history.endTransaction(),Xe.current=null,Ne(),He()},visible:!i.isPlaying}),Me&&Me.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:de.distanceGuideStyle.stroke,strokeWidth:1,strokeScaleEnabled:!1})),t(f,Object.assign({},l,{stroke:de.distanceGuideStyle.stroke,strokeWidth:1,strokeScaleEnabled:!1})),t(g,{points:[e[0].x,e[0].y,e[1].x,e[1].y],stroke:de.distanceGuideStyle.stroke,strokeWidth:1,strokeScaleEnabled:!1}),t(g,{points:[e[1].x,e[1].y,e[2].x,e[2].y],stroke:de.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(v,{cornerRadius:5,fill:de.distanceGuideStyle.labelFill,pointerDirection:"down"}),t(b,{align:"center",verticalAlign:"middle",fill:de.distanceGuideStyle.labelTextFill,padding:5,text:G({unit:i.unit,dpi:i.dpi,px:o})})]})]},s)),r._rendering&&n(d,{children:[t(f,{width:ve,height:be,fill:"rgba(255,255,255,0.9)"}),t(b,{text:"Rendering...",fontSize:60,width:ve,height:be,align:"center",verticalAlign:"middle"})]}),lt&&t(lt,{components:P,store:i,page:r,stageRef:Ye,tooltipSafeArea:te}),st&&t(J,{children:t(st,Object.assign({components:P,store:i},De.props))})]}),t(S,{store:i,page:r,width:h,height:Y,scale:i.scale,xPadding:ye,yPadding:we,bleedLeft:xe.left,bleedTop:xe.top}),t(le,Object.assign({},Ie,{store:i})),t(oe,{selection:Ke}),R()>0&&n(d,{hideInExport:!0,children:[t(pe,{name:"cache-bounds",x:h-(1===R()?250:210),y:Y-(1===R()?95:45)}),t(pe,{name:"cache-bounds-t",x:10,y:10})]}),j()&&t(b,{text:"Powered by polotno.com",fontSize:14,fill:"rgba(0,0,0,0.6)",x:h-170,y:Y-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"})]})}),ke&&rt&&t(rt,{store:i,page:r,xPadding:ye,yPadding:we,layout:H})]})});
@@ -133,7 +133,7 @@ export declare const FigureElement: import("mobx-state-tree").IModelType<{
133
133
  } & {
134
134
  readonly locked: boolean;
135
135
  readonly a: import("./shape-model.js").AnimatedAttrs;
136
- animated(attr: any): any;
136
+ animated(attr: string): any;
137
137
  readonly timeRange: {
138
138
  start: number;
139
139
  end: number;
@@ -146,7 +146,7 @@ export declare const GifElement: import("mobx-state-tree").IModelType<{
146
146
  } & {
147
147
  readonly locked: boolean;
148
148
  readonly a: import("./shape-model.js").AnimatedAttrs;
149
- animated(attr: any): any;
149
+ animated(attr: string): any;
150
150
  readonly timeRange: {
151
151
  start: number;
152
152
  end: number;
@@ -203,7 +203,7 @@ export declare const TYPES_MAP: {
203
203
  } & {
204
204
  readonly locked: boolean;
205
205
  readonly a: import("./shape-model.js").AnimatedAttrs;
206
- animated(attr: any): any;
206
+ animated(attr: string): any;
207
207
  readonly timeRange: {
208
208
  start: number;
209
209
  end: number;
@@ -391,7 +391,7 @@ export declare const TYPES_MAP: {
391
391
  } & {
392
392
  readonly locked: boolean;
393
393
  readonly a: import("./shape-model.js").AnimatedAttrs;
394
- animated(attr: any): any;
394
+ animated(attr: string): any;
395
395
  readonly timeRange: {
396
396
  start: number;
397
397
  end: number;
@@ -561,7 +561,7 @@ export declare const TYPES_MAP: {
561
561
  } & {
562
562
  readonly locked: boolean;
563
563
  readonly a: import("./shape-model.js").AnimatedAttrs;
564
- animated(attr: any): any;
564
+ animated(attr: string): any;
565
565
  readonly timeRange: {
566
566
  start: number;
567
567
  end: number;
@@ -737,7 +737,7 @@ export declare const TYPES_MAP: {
737
737
  } & {
738
738
  readonly locked: boolean;
739
739
  readonly a: import("./shape-model.js").AnimatedAttrs;
740
- animated(attr: any): any;
740
+ animated(attr: string): any;
741
741
  readonly timeRange: {
742
742
  start: number;
743
743
  end: number;
@@ -921,7 +921,7 @@ export declare const TYPES_MAP: {
921
921
  } & {
922
922
  readonly locked: boolean;
923
923
  readonly a: import("./shape-model.js").AnimatedAttrs;
924
- animated(attr: any): any;
924
+ animated(attr: string): any;
925
925
  readonly timeRange: {
926
926
  start: number;
927
927
  end: number;
@@ -1096,7 +1096,7 @@ export declare const TYPES_MAP: {
1096
1096
  } & {
1097
1097
  readonly locked: boolean;
1098
1098
  readonly a: import("./shape-model.js").AnimatedAttrs;
1099
- animated(attr: any): any;
1099
+ animated(attr: string): any;
1100
1100
  readonly timeRange: {
1101
1101
  start: number;
1102
1102
  end: number;
@@ -1277,7 +1277,7 @@ export declare const TYPES_MAP: {
1277
1277
  } & {
1278
1278
  readonly locked: boolean;
1279
1279
  readonly a: import("./shape-model.js").AnimatedAttrs;
1280
- animated(attr: any): any;
1280
+ animated(attr: string): any;
1281
1281
  readonly timeRange: {
1282
1282
  start: number;
1283
1283
  end: number;
@@ -1601,7 +1601,7 @@ export declare const TYPES_MAP: {
1601
1601
  } & {
1602
1602
  readonly locked: boolean;
1603
1603
  readonly a: import("./shape-model.js").AnimatedAttrs;
1604
- animated(attr: any): any;
1604
+ animated(attr: string): any;
1605
1605
  readonly timeRange: {
1606
1606
  start: number;
1607
1607
  end: number;
@@ -142,7 +142,7 @@ export declare const ImageElement: import("mobx-state-tree").IModelType<{
142
142
  } & {
143
143
  readonly locked: boolean;
144
144
  readonly a: import("./shape-model.js").AnimatedAttrs;
145
- animated(attr: any): any;
145
+ animated(attr: string): any;
146
146
  readonly timeRange: {
147
147
  start: number;
148
148
  end: number;
@@ -133,7 +133,7 @@ export declare const LineElement: import("mobx-state-tree").IModelType<{
133
133
  } & {
134
134
  readonly locked: boolean;
135
135
  readonly a: import("./shape-model.js").AnimatedAttrs;
136
- animated(attr: any): any;
136
+ animated(attr: string): any;
137
137
  readonly timeRange: {
138
138
  start: number;
139
139
  end: number;
@@ -147,7 +147,7 @@ export declare const Page: import("mobx-state-tree").IModelType<{
147
147
  } & {
148
148
  readonly locked: boolean;
149
149
  readonly a: import("./shape-model.js").AnimatedAttrs;
150
- animated(attr: any): any;
150
+ animated(attr: string): any;
151
151
  readonly timeRange: {
152
152
  start: number;
153
153
  end: number;
@@ -334,7 +334,7 @@ export declare const Page: import("mobx-state-tree").IModelType<{
334
334
  } & {
335
335
  readonly locked: boolean;
336
336
  readonly a: import("./shape-model.js").AnimatedAttrs;
337
- animated(attr: any): any;
337
+ animated(attr: string): any;
338
338
  readonly timeRange: {
339
339
  start: number;
340
340
  end: number;
@@ -503,7 +503,7 @@ export declare const Page: import("mobx-state-tree").IModelType<{
503
503
  } & {
504
504
  readonly locked: boolean;
505
505
  readonly a: import("./shape-model.js").AnimatedAttrs;
506
- animated(attr: any): any;
506
+ animated(attr: string): any;
507
507
  readonly timeRange: {
508
508
  start: number;
509
509
  end: number;
@@ -677,7 +677,7 @@ export declare const Page: import("mobx-state-tree").IModelType<{
677
677
  } & {
678
678
  readonly locked: boolean;
679
679
  readonly a: import("./shape-model.js").AnimatedAttrs;
680
- animated(attr: any): any;
680
+ animated(attr: string): any;
681
681
  readonly timeRange: {
682
682
  start: number;
683
683
  end: number;
@@ -860,7 +860,7 @@ export declare const Page: import("mobx-state-tree").IModelType<{
860
860
  } & {
861
861
  readonly locked: boolean;
862
862
  readonly a: import("./shape-model.js").AnimatedAttrs;
863
- animated(attr: any): any;
863
+ animated(attr: string): any;
864
864
  readonly timeRange: {
865
865
  start: number;
866
866
  end: number;
@@ -1034,7 +1034,7 @@ export declare const Page: import("mobx-state-tree").IModelType<{
1034
1034
  } & {
1035
1035
  readonly locked: boolean;
1036
1036
  readonly a: import("./shape-model.js").AnimatedAttrs;
1037
- animated(attr: any): any;
1037
+ animated(attr: string): any;
1038
1038
  readonly timeRange: {
1039
1039
  start: number;
1040
1040
  end: number;
@@ -1214,7 +1214,7 @@ export declare const Page: import("mobx-state-tree").IModelType<{
1214
1214
  } & {
1215
1215
  readonly locked: boolean;
1216
1216
  readonly a: import("./shape-model.js").AnimatedAttrs;
1217
- animated(attr: any): any;
1217
+ animated(attr: string): any;
1218
1218
  readonly timeRange: {
1219
1219
  start: number;
1220
1220
  end: number;
@@ -1537,7 +1537,7 @@ export declare const Page: import("mobx-state-tree").IModelType<{
1537
1537
  } & {
1538
1538
  readonly locked: boolean;
1539
1539
  readonly a: import("./shape-model.js").AnimatedAttrs;
1540
- animated(attr: any): any;
1540
+ animated(attr: string): any;
1541
1541
  readonly timeRange: {
1542
1542
  start: number;
1543
1543
  end: number;
@@ -1737,7 +1737,7 @@ export declare const Page: import("mobx-state-tree").IModelType<{
1737
1737
  } & {
1738
1738
  readonly locked: boolean;
1739
1739
  readonly a: import("./shape-model.js").AnimatedAttrs;
1740
- animated(attr: any): any;
1740
+ animated(attr: string): any;
1741
1741
  readonly timeRange: {
1742
1742
  start: number;
1743
1743
  end: number;
@@ -1874,7 +1874,7 @@ export declare const Page: import("mobx-state-tree").IModelType<{
1874
1874
  } & {
1875
1875
  readonly locked: boolean;
1876
1876
  readonly a: import("./shape-model.js").AnimatedAttrs;
1877
- animated(attr: any): any;
1877
+ animated(attr: string): any;
1878
1878
  readonly timeRange: {
1879
1879
  start: number;
1880
1880
  end: number;
@@ -16,7 +16,7 @@ export declare const Animation: import("mobx-state-tree").IModelType<{
16
16
  name: import("mobx-state-tree").IType<string | undefined, string, string>;
17
17
  data: import("mobx-state-tree").IType<{} | null | undefined, {}, {}>;
18
18
  }, {}, import("mobx-state-tree")._NotCustomized, import("mobx-state-tree")._NotCustomized>;
19
- export declare const getDiff: (obj1: Record<string, any>, obj2: Record<string, any>) => Record<string, any>;
19
+ export declare const getDiff: (obj1: Record<string, unknown>, obj2: Record<string, unknown>) => Record<string, number>;
20
20
  export declare const ShapeFilter: import("mobx-state-tree").IModelType<{
21
21
  intensity: import("mobx-state-tree").IType<number | undefined, number, number>;
22
22
  }, {}, import("mobx-state-tree")._NotCustomized, import("mobx-state-tree")._NotCustomized>;
@@ -147,7 +147,7 @@ export declare const Shape: import("mobx-state-tree").IModelType<{
147
147
  } & {
148
148
  readonly locked: boolean;
149
149
  readonly a: AnimatedAttrs;
150
- animated(attr: any): any;
150
+ animated(attr: string): any;
151
151
  readonly timeRange: {
152
152
  start: number;
153
153
  end: number;
@@ -1 +1 @@
1
- import{types as e,isAlive as t}from"mobx-state-tree";import{animate as i}from"../utils/animations.js";import{observable as n,action as o}from"mobx";import{Node as a}from"./node-model.js";import{getElementTimeRange as r,getPlayheadLocalTime as s}from"../utils/timeline.js";export const Animation=e.model("Animation",{delay:0,duration:500,enabled:!0,type:e.enumeration("Type",["enter","exit","loop"]),name:"none",data:e.frozen({})});export const getDiff=(e,t)=>{const i={};for(const n in t){if("number"==typeof e[n]&&"number"==typeof t[n]){const o=t[n]-e[n];0!==o&&(i[n]=o)}}return i};export const ShapeFilter=e.model("ShapeFilter",{intensity:1});export const INDEPENDENT_FILTERS=["temperature","contrast","highlights","shadows","white","black","saturation","vibrance"];export const Shape=a.named("Shape").props({x:0,y:0,width:100,height:100,rotation:0,opacity:1,animations:e.array(Animation),blurEnabled:!1,blurRadius:10,brightnessEnabled:!1,brightness:0,sepiaEnabled:!1,grayscaleEnabled:!1,filters:e.map(ShapeFilter),shadowEnabled:!1,shadowBlur:5,shadowOffsetX:0,shadowOffsetY:0,shadowColor:"black",shadowOpacity:1,visible:!0,draggable:!0,resizable:!0,selectable:!0,contentEditable:!0,styleEditable:!0,alwaysOnTop:!1,showInExport:!0}).preProcessSnapshot(e=>{const t=Object.assign(Object.assign({},e),{x:"x"in e&&e.x||0,y:"y"in e&&e.y||0,filters:"filters"in e?Array.isArray(e.filters)?{}:e.filters:void 0});return"width"in e&&(t.width=t.width||1),"height"in e&&(t.height=t.height||1),"locked"in e&&e.locked&&(t.draggable=!1,t.contentEditable=!1,t.styleEditable=!1,t.resizable=!1,t.removable=!1),t}).views(e=>{var a,l,d,c,p,u;const f=["x","y","width","height","rotation","opacity","color","fontSize","cropX","cropY","cropWidth","cropHeight"],m=e,h={x:null!==(a=m.x)&&void 0!==a?a:0,y:null!==(l=m.y)&&void 0!==l?l:0,width:null!==(d=m.width)&&void 0!==d?d:0,height:null!==(c=m.height)&&void 0!==c?c:0,rotation:null!==(p=m.rotation)&&void 0!==p?p:0,opacity:null!==(u=m.opacity)&&void 0!==u?u:1};for(const t of f){t in e&&(h[t]=m[t])}const g=n(h),b=o(e=>{for(const t in e){g[t]=e[t]}}),y=o(e=>{Object.assign(g,e)}),E=o(e=>{for(const t in e){"number"==typeof g[t]&&(g[t]=g[t]+e[t])}});return{get locked(){return!(e.draggable||e.contentEditable||e.styleEditable||e.resizable)},get a(){if(!t(e)){return g}const n={};for(const e in g){n[e]=m[e]}b(n);const o=s(e);if(null===o){return g}const a=e.store.isEditingPaused&&this.isSelected,r=e.store.animatedElementsIds;if(r.length&&!r.includes(e.id)){return g}const l=e.animations.find(e=>"enter"===e.type),d=(null==l?void 0:l.enabled)&&o<l.delay;d&&y({opacity:0});const c=(null==l?void 0:l.enabled)&&o>=l.delay&&o<=l.delay+l.duration;if(c&&!a){const t=o-l.delay,n=i({element:e,animation:l,dTime:t}),a=getDiff(e,n);E(a)}const p=e.animations.find(e=>"exit"===e.type);if(!d&&!c&&(null==p?void 0:p.enabled)&&o>=e.page.duration-p.duration-p.delay&&o<=e.page.duration-p.delay&&!a){const t=o-(e.page.duration-p.duration-p.delay),n=i({element:e,animation:p,dTime:t}),a=getDiff(e,n);E(a)}(null==p?void 0:p.enabled)&&o>=e.page.duration-p.delay&&y({opacity:0});const u=e.animations.find(e=>"loop"===e.type);if((null==u?void 0:u.enabled)&&!a){const t=i({element:e,animation:u,dTime:o}),n=getDiff(e,t);E(n)}return g},animated(e){return this.a[e]},get timeRange(){return t(e)&&e.page?r(e.animations,e.page.duration):{start:0,end:0}},get active(){if(!t(e)){return!0}const i=s(e);if(null===i){return!0}const{start:n,end:o}=this.timeRange;return i>=n&&i<o},get isSelected(){return!!t(e)&&e.store.selectedShapes.indexOf(e)>=0&&e.selectable},get isSelectedDirectly(){return!!t(e)&&e.store.selectedElements.indexOf(e)>=0&&e.selectable}}}).actions(e=>({setAnimation(t,i){const n=e.animations.find(e=>e.type===t);n?Object.assign(n,i):e.animations.push(Object.assign({type:t},i))},setFilter(t,i){INDEPENDENT_FILTERS.includes(t)||e.filters.forEach((t,i)=>{INDEPENDENT_FILTERS.includes(i.toString())||e.filters.delete(i.toString())}),null==i?e.filters.delete(t):e.filters.set(t,{intensity:i})}}));
1
+ import{types as e,isAlive as t}from"mobx-state-tree";import{animate as n}from"../utils/animations.js";import{computed as i}from"mobx";import{Node as o}from"./node-model.js";import{getElementTimeRange as a,getPlayheadLocalTime as r}from"../utils/timeline.js";export const Animation=e.model("Animation",{delay:0,duration:500,enabled:!0,type:e.enumeration("Type",["enter","exit","loop"]),name:"none",data:e.frozen({})});export const getDiff=(e,t)=>{const n={};for(const i in t){if("number"==typeof e[i]&&"number"==typeof t[i]){const o=t[i]-e[i];0!==o&&(n[i]=o)}}return n};export const ShapeFilter=e.model("ShapeFilter",{intensity:1});export const INDEPENDENT_FILTERS=["temperature","contrast","highlights","shadows","white","black","saturation","vibrance"];export const Shape=o.named("Shape").props({x:0,y:0,width:100,height:100,rotation:0,opacity:1,animations:e.array(Animation),blurEnabled:!1,blurRadius:10,brightnessEnabled:!1,brightness:0,sepiaEnabled:!1,grayscaleEnabled:!1,filters:e.map(ShapeFilter),shadowEnabled:!1,shadowBlur:5,shadowOffsetX:0,shadowOffsetY:0,shadowColor:"black",shadowOpacity:1,visible:!0,draggable:!0,resizable:!0,selectable:!0,contentEditable:!0,styleEditable:!0,alwaysOnTop:!1,showInExport:!0}).preProcessSnapshot(e=>{const t=Object.assign(Object.assign({},e),{x:"x"in e&&e.x||0,y:"y"in e&&e.y||0,filters:"filters"in e?Array.isArray(e.filters)?{}:e.filters:void 0});return"width"in e&&(t.width=t.width||1),"height"in e&&(t.height=t.height||1),"locked"in e&&e.locked&&(t.draggable=!1,t.contentEditable=!1,t.styleEditable=!1,t.resizable=!1,t.removable=!1),t}).views(e=>{var o,s,l,d,c,u;const f=["x","y","width","height","rotation","opacity","color","fontSize","cropX","cropY","cropWidth","cropHeight"],p=e,m={x:null!==(o=p.x)&&void 0!==o?o:0,y:null!==(s=p.y)&&void 0!==s?s:0,width:null!==(l=p.width)&&void 0!==l?l:0,height:null!==(d=p.height)&&void 0!==d?d:0,rotation:null!==(c=p.rotation)&&void 0!==c?c:0,opacity:null!==(u=p.opacity)&&void 0!==u?u:1};for(const t of f){t in e&&(m[t]=p[t])}const b=i(()=>{if(!t(e)){return m}const i=Object.assign({},m);for(const e in i){i[e]=p[e]}const o=r(e);if(null===o){return i}const a=e.store.isEditingPaused&&e.isSelected,s=e.store.animatedElementsIds;if(s.length&&!s.includes(e.id)){return i}const l=e.animations.find(e=>"enter"===e.type),d=(null==l?void 0:l.enabled)&&o<l.delay;d&&(i.opacity=0);const c=(null==l?void 0:l.enabled)&&o>=l.delay&&o<=l.delay+l.duration;if(c&&!a){const t=o-l.delay,a=n({element:e,animation:l,dTime:t}),r=getDiff(p,a);for(const e in r){const t=i[e];"number"==typeof t&&(i[e]=t+r[e])}}const u=e.animations.find(e=>"exit"===e.type);if(!d&&!c&&(null==u?void 0:u.enabled)&&o>=e.page.duration-u.duration-u.delay&&o<=e.page.duration-u.delay&&!a){const t=o-(e.page.duration-u.duration-u.delay),a=n({element:e,animation:u,dTime:t}),r=getDiff(p,a);for(const e in r){const t=i[e];"number"==typeof t&&(i[e]=t+r[e])}}(null==u?void 0:u.enabled)&&o>=e.page.duration-u.delay&&(i.opacity=0);const f=e.animations.find(e=>"loop"===e.type);if((null==f?void 0:f.enabled)&&!a){const t=n({element:e,animation:f,dTime:o}),a=getDiff(p,t);for(const e in a){const t=i[e];"number"==typeof t&&(i[e]=t+a[e])}}return i}),g={};for(const t in m){const e=i(()=>b.get()[t]);Object.defineProperty(g,t,{enumerable:!0,get:()=>e.get()})}return{get locked(){return!(e.draggable||e.contentEditable||e.styleEditable||e.resizable)},get a(){return g},animated(e){return this.a[e]},get timeRange(){return t(e)&&e.page?a(e.animations,e.page.duration):{start:0,end:0}},get active(){if(!t(e)){return!0}const n=r(e);if(null===n){return!0}const{start:i,end:o}=this.timeRange;return n>=i&&n<o},get isSelected(){return!!t(e)&&e.store.selectedShapes.indexOf(e)>=0&&e.selectable},get isSelectedDirectly(){return!!t(e)&&e.store.selectedElements.indexOf(e)>=0&&e.selectable}}}).actions(e=>({setAnimation(t,n){const i=e.animations.find(e=>e.type===t);i?Object.assign(i,n):e.animations.push(Object.assign({type:t},n))},setFilter(t,n){INDEPENDENT_FILTERS.includes(t)||e.filters.forEach((t,n)=>{INDEPENDENT_FILTERS.includes(n.toString())||e.filters.delete(n.toString())}),null==n?e.filters.delete(t):e.filters.set(t,{intensity:n})}}));