polotno 4.11.0 → 4.12.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/blueprint/side-panel/select-video.d.ts +4 -0
- package/canvas/crop-overlay.d.ts +42 -0
- package/canvas/crop-overlay.js +1 -0
- package/canvas/downscale-bands.d.ts +10 -0
- package/canvas/downscale-bands.js +1 -0
- package/canvas/downscale-kernel.d.ts +7 -0
- package/canvas/downscale-kernel.js +1 -0
- package/canvas/downscale-kernel.wasm.d.ts +1 -0
- package/canvas/downscale-kernel.wasm.js +1 -0
- package/canvas/downscale-passes.d.ts +7 -0
- package/canvas/downscale-passes.js +1 -0
- package/canvas/downscale.d.ts +16 -2
- package/canvas/downscale.js +1 -1
- package/canvas/drawing-layer.js +1 -1
- package/canvas/element.js +1 -1
- package/canvas/gif-element.js +1 -1
- package/canvas/hotkeys.js +1 -1
- package/canvas/image-element.d.ts +10 -0
- package/canvas/image-element.js +1 -1
- package/canvas/page.js +1 -1
- package/canvas/tooltip.js +1 -1
- package/canvas/transform-box.d.ts +9 -0
- package/canvas/transform-box.js +1 -0
- package/canvas/use-image.d.ts +4 -0
- package/canvas/use-image.js +1 -0
- package/canvas/video-element.js +1 -1
- package/canvas/workspace-canvas.d.ts +3 -1
- package/canvas/workspace-canvas.js +1 -1
- package/canvas/workspace-style.d.ts +4 -0
- package/canvas/workspace-style.js +1 -1
- package/model/crop-mode.d.ts +34 -0
- package/model/crop-mode.js +1 -0
- package/model/gif-model.d.ts +2 -0
- package/model/group-model.d.ts +13 -0
- package/model/image-model.d.ts +2 -0
- package/model/image-model.js +1 -1
- package/model/page-model.d.ts +13 -0
- package/model/store.d.ts +144 -5
- package/model/store.js +1 -1
- package/model/svg-model.d.ts +7 -0
- package/model/svg-model.js +1 -1
- package/model/video-model.d.ts +2 -0
- package/package.json +23 -21
- package/polotno.bundle.js +179 -193
- package/side-panel/draw-panel.js +1 -1
- package/side-panel/select-image.js +1 -1
- package/side-panel/select-video.d.ts +4 -0
- package/toolbar/image-toolbar.d.ts +7 -2
- package/toolbar/image-toolbar.js +1 -1
- package/toolbar/svg-toolbar.js +1 -1
- package/toolbar/toolbar.js +1 -1
- package/utils/base64.d.ts +1 -1
- package/utils/fonts.d.ts +1 -0
- package/utils/fonts.js +1 -1
- package/utils/html2canvas.js +1 -1
- package/utils/l10n.d.ts +4 -0
- package/utils/l10n.js +1 -1
- package/utils/path-to-svg.d.ts +0 -2
- package/utils/path-to-svg.js +1 -1
- package/utils/px.d.ts +1 -0
- package/utils/px.js +1 -1
- package/utils/validate-key.js +1 -1
package/canvas/page.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var e=this&&this.__rest||function(e,t){var n={};for(var i in e){Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i])}if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(i=Object.getOwnPropertySymbols(e);o<i.length;o++){t.indexOf(i[o])<0&&Object.prototype.propertyIsEnumerable.call(e,i[o])&&(n[i[o]]=e[i[o]])}}return n};import{jsx as t,jsxs as n,Fragment as i}from"react/jsx-runtime";import o from"react";import{observer as r,useLocalObservable as l}from"mobx-react-lite";import{action as s,runInAction as a}from"mobx";import{ZERO_BLEED as d}from"@polotno/schema";import{Group as c,Image as h,Label as m,Layer as u,Line as g,Rect as f,Shape as p,Stage as x,Tag as v,Text as b,Transformer as y,KonvaRenderer as w}from"react-konva";import E from"use-image";import{useWorkspaceStyle as X}from"./workspace-style.js";import{ROLES as Y}from"../model/store.js";import S from"konva";import k from"./element.js";import{DrawingLayer as A}from"./drawing-layer.js";import{ensureDragOrder as M,useSnap as I}from"./use-transformer-snap.js";import{useImageLoader as O}from"./image-element.js";import{getCrop as P}from"../utils/crop.js";import{___ as R,____ as j,isCreditVisible as D}from"../utils/validate-key.js";import{getClientRect as C,getCorners as T,getTotalClientRect as B,polygonsIntersect as W}from"../utils/math.js";import{pxToUnitRounded as G,pxToUnitString as L}from"../utils/unit.js";import{isCornerAnchor as V,textMinResizeWidth as F,textMinWidthIsMeasured as z}from"../utils/px.js";import{flags as U}from"../utils/flags.js";import{useColor as Z}from"./use-color.js";import{isGradient as _}from"@polotno/core/gradient";import{Html as H}from"react-konva-utils";import{observerBatching as J}from"mobx-react-lite";const N=e=>w.batchedUpdates(e,null);J(e=>{w.isAlreadyRendering()?queueMicrotask(()=>N(e)):N(e)});const K=S.DD._drag;window.removeEventListener("mousemove",K),S.DD._drag=function(e){a(()=>{K.call(this,e)})},window.addEventListener("mousemove",S.DD._drag);const $={enabledAnchors:["top-left","top-center","top-right","middle-left","bottom-left","bottom-right","bottom-center","middle-right"],rotateEnabled:!0,rotationSnaps:[0,45,90,135,180,225,270,315],ignoreStroke:!0,flipEnabled:!1,keepRatio:!0},Q=e=>{const t=(e%180+180)%180;return t<.1||180-t<.1},q=e=>{if(!e.length){return null}const t=Q(e[0].rotation)?0:e[0].rotation;return e.every(e=>Q(e.rotation-t))?t:null},ee=e=>e.selectedShapes.filter(e=>!e._cropModeEnabled),te=(e,t,n)=>{const i=e.width!==t.width,o=e.height!==t.height;if(!i&&!o){return e}const r=Math.cos(t.rotation),l=Math.sin(t.rotation),s=t.x-n.x,a=t.y-n.y,d=i?0:s*r+a*l,c=o?0:-s*l+a*r;return e.x=n.x+d*r-c*l,e.y=n.y+d*l+c*r,e},ne={text:{enabledAnchors:["top-left","top-right","middle-left","bottom-left","bottom-right","middle-right"]},svg:{enabledAnchors:["top-left","top-right","bottom-left","bottom-right"]},gif:{enabledAnchors:["top-left","top-right","bottom-left","bottom-right"]},line:{enabledAnchors:[],borderEnabled:!1,rotateEnabled:!1},image:{enabledAnchors:["top-left","top-right","bottom-left","bottom-right"]},many:{enabledAnchors:["top-left","top-right","bottom-left","bottom-right"]},group:{enabledAnchors:["top-left","top-right","bottom-left","bottom-right"]},table:{keepRatio:!1,enabledAnchors:["top-left","top-center","top-right","middle-left","middle-right","bottom-left","bottom-center","bottom-right"]}};export function registerTransformerAttrs(e,t){ne[e]=ne[e]||t,Object.assign(ne[e],t)}const ie=e=>t(f,Object.assign({},e,{preventDefault:!1})),oe=n=>{var{url:i}=n,o=e(n,["url"]);const[r,l]=E(i,"anonymous"),s=r?P(r,{width:o.width,height:o.height},"center-middle"):{};return O(l,i,"page background"),t(h,Object.assign({image:r},o,s))},re=e=>{const n=Z({a:{width:e.width,height:e.height},width:e.width,height:e.height},e.fill);return t(f,Object.assign({},e,n))},le=i=>{const{background:r,scale:l,borderColor:s,transparencyBackgroundColor:a}=i,d=e(i,["background","scale","borderColor","transparencyBackgroundColor"]),c=o.useMemo(()=>!!S.Util.colorToRGBA(r)||_(r),[r]),h=o.useMemo(()=>{if(_(r)){return!0}const e=S.Util.colorToRGBA(r);return!e||e.a<1},[r]),m=o.useMemo(()=>{if(!h||a){return null}const e=document.createElement("canvas"),t=30;e.width=60,e.height=60;const n=e.getContext("2d");return n&&(n.fillStyle="black",n.fillRect(t,0,t,t),n.fillRect(0,t,t,t)),e},[h,a]);return n(o.Fragment,{children:[h&&t(f,a?Object.assign({fill:a},d,{hideInExport:!0}):Object.assign({fillPatternImage:m},d,{opacity:.1,hideInExport:!0})),c?t(re,Object.assign({fill:r},d)):t(oe,Object.assign({url:r},d))]})},se=r(({selection:e})=>{const{selectionRectStyle:n}=X();return e.visible?t(f,{name:"selection",x:Math.min(e.x1,e.x2),y:Math.min(e.y1,e.y2),width:Math.abs(e.x1-e.x2),height:Math.abs(e.y1-e.y2),fill:n.fill,stroke:n.stroke,strokeWidth:n.strokeWidth}):null});function ae(e){let t=180*e/Math.PI;return t%=360,t>180?t-=360:t<-180&&(t+=360),Math.round(t)}const de=r(({x:e,y:o,width:r,height:l,rotation:s,anchor:a,store:d})=>{const{transformLabelStyle:c}=X();if(void 0===e||void 0===o||void 0===r||void 0===l||void 0===s||void 0===a){return null}const h=C({x:e,y:o,width:r,height:l,rotation:S.Util.radToDeg(s)}),u=(l/2+70)*Math.cos(s-Math.PI/2),g=(l/2+70)*Math.sin(s-Math.PI/2),f=G({unit:d.unit,dpi:d.dpi,px:r/d.scale,precious:"px"===d.unit?0:1})+" x "+G({unit:d.unit,dpi:d.dpi,px:l/d.scale,precious:"px"===d.unit?0:1})+("px"===d.unit?"":" "+d.unit);return n(i,{children:[n(m,{x:(h.minX+h.maxX)/2+u,y:(h.minY+h.maxY)/2+g,offsetX:14,offsetY:14,visible:"rotater"===a,children:[t(v,{cornerRadius:5,fill:c.fill}),t(b,{align:"center",verticalAlign:"middle",fill:c.textFill,padding:8,text:ae(s).toString()+"°"})]}),n(m,{x:(h.minX+h.maxX)/2,y:h.maxY+20,visible:"rotater"!==a,children:[t(v,{cornerRadius:5,fill:c.fill,pointerDirection:"up",pointerHeight:0,pointerWidth:0}),t(b,{align:"center",verticalAlign:"middle",fill:c.textFill,padding:8,text:f})]})]})}),ce=r(({elements:e,store:n})=>{const i=e.filter(e=>e.alwaysOnTop),r=e.filter(e=>!e.alwaysOnTop).concat(i);return t(o.Fragment,{children:r.map(e=>t(k,{store:n,element:e,onClick:()=>{console.warn("Polotno warning: onClick callback is deprecated. Just stop using it. Polotno will do selection automatically.")}},e.id))})});export const useContextMenu=({store:e})=>{const[t,n]=o.useState(!1),[i,r]=o.useState({x:0,y:0}),l=o.useCallback(e=>{n(!0),r(e)},[]);return{open:l,close:o.useCallback(()=>{n(!1)},[]),props:{isOpen:t,offset:i,setIsOpen:n}}};let he=null;export const registerNextDomDrop=e=>{he=e};const me=atob("UG9sb3RubyBmcmVlIGxpY2Vuc2UgbGltaXRhdGlvbiBleGNlZWRlZCAtIFBsZWFzZSB1cGdyYWRlIHlvdXIgYWNjb3VudC4="),ue=atob("I2MwMzkyYg=="),ge=atob("djAuOS4y"),fe=e=>t(i,{children:n(m,{fill:ue,height:200,children:[t(v,{fill:ue}),t(b,Object.assign({},e,{fill:"white",text:me,height:void 0,padding:10,fontSize:20}))]})}),pe=atob("RlJFRSAgVFJJQUwgIExJQ0VOU0U="),xe=(atob("UG93ZXJlZCBieSBQb2xvdG5v"),atob("TElDRU5TRSAgS0VZICBJUyAgTUlTU0lORw==")),ve=atob("UGxlYXNlIGFjdGl2YXRlIHlvdXIgbGljZW5zZS4KTGljZW5zZSByZWxhdGVkIHF1ZXN0aW9uczoKcG9sb3Ruby5jb20vY29udGFjdA=="),be=e=>{const i=1===j(),o=i?xe:pe,r=i?230:195;return n(c,Object.assign({},e,{listening:!1,children:[t(f,{fill:ue,width:r,height:24,cornerRadius:2}),t(b,{text:o,fill:"white",fontSize:13,fontFamily:"monospace",width:r,align:"center",y:5,listening:!1}),i&&t(b,{text:ve,fill:"rgba(0,0,0,0.6)",fontSize:14,y:30,listening:!1})]}))};export default r(({store:e,page:i,width:r,height:a,pageControlsEnabled:h,components:w,altCloneEnabled:E,groupSelectionMode:S="drill",viewportSize:k,layout:O="vertical",tooltipSafeArea:P,transformerSafeArea:G})=>{var Z,_;const J=X(),N=J.transformerStyle,K=$,oe=i.computedBleed,re=e.bleedVisible?oe:d,ae=i.computedWidth+re.left+re.right,me=i.computedHeight+re.top+re.bottom,ue=(r-ae*e.scale)/2,pe=(a-me*e.scale)/2,xe=o.useRef(null),ve=o.useRef(null),ye=o.useRef(null),we=o.useRef(null),Ee=null==h||h,Xe=o.useRef(!1),[Ye,Se]=o.useState(null),[ke,Ae]=o.useState({}),[Me,Ie]=o.useState(0),Oe=useContextMenu({store:e}),Pe=e.selectedElements.find(e=>e._cropModeEnabled),Re=e.selectedElements.find(e=>e.curveEnabled),je=e.selectedShapes.filter(e=>!e.resizable).length>0,De=e.selectedShapes.filter(e=>!e.draggable).length>0,Ce=e.selectedElements.filter(e=>!e.visible).length>0,Te=ee(e),Be=1!==e.selectedElements.length||"group"===(null===(Z=e.selectedElements[0])||void 0===Z?void 0:Z.type),We=null!==(_=q(Te))&&void 0!==_?_:0,Ge=e=>Be&&Te.length>0&&Te.every(t=>((e,t,n)=>{if(!Q(e.rotation-n)){return!1}switch(e.type){case"text":return"x"===t&&!z(e);case"figure":case"video":case"table":return!0;case"image":case"svg":case"gif":return!e.keepRatio;default:return!1}})(t,e,We)),Le=!Be&&e.selectedElements[0].keepRatio,Ve=Ge("x"),Fe=Ge("y"),ze=()=>{var t,n,i;const o=xe.current;if(!o){return[]}const r=o.getStage();if(!r){return[]}const l=ee(e),s=l.map(e=>r.findOne("#"+e.id)).filter(e=>!!e),a=1===e.selectedElements.length,d=a&&(null===(t=e.selectedElements[0])||void 0===t?void 0:t.type)||"many",c=ne[d],h=Object.assign(Object.assign({},K),c||{});c&&("svg"!==d&&"image"!==d&&"gif"!==d||e.selectedElements[0].keepRatio||(h.enabledAnchors=K.enabledAnchors),"text"===d&&U.textVerticalResizeEnabled&&(h.enabledAnchors=null===(n=ne.text.enabledAnchors)||void 0===n?void 0:n.concat(["bottom-center","top-center"])),"text"===d&&a&&e.selectedElements[0].curveEnabled&&(h.enabledAnchors=ne.many.enabledAnchors)),(Ve||Fe)&&(h.enabledAnchors=[...h.enabledAnchors||[],...Ve?["middle-left","middle-right"]:[],...Fe?["top-center","bottom-center"]:[]]),o.setAttrs(Object.assign(Object.assign({},h),N)),je&&o.enabledAnchors([]),De&&o.rotateEnabled(!1);const m=o.nodes();if(m.length===s.length&&s.every((e,t)=>m[t]===e)||o.nodes(s),Be&&s.length){const e=q(l);null===e||Q(o.rotation()-e)||(o.rotation(e),o.forceUpdate())}return null===(i=o.getLayer())||void 0===i||i.batchDraw(),s};o.useLayoutEffect(()=>{var e;if(null===(e=xe.current)||void 0===e?void 0:e.isTransforming()){return}const t=ze();t.find(e=>null==e?void 0:e.isDragging())&&(t.forEach(e=>{e.isDragging()||null==e||e.startDrag()}),M())},[e.selectedShapes,Pe,je,Ce,De,Re,Ve,Fe,Le,We,N]);const Ue=()=>{var e,t;const n=xe.current;if(!n){return}if(!n.isTransforming()){return void Ae({})}if(!n.nodes().length||!n.isTransforming()){return}const i=n.__getNodeRect(),o=null==n?void 0:n.getActiveAnchor(),r=n.getStage();Ae({anchor:o,x:i.x-(null!==(e=null==r?void 0:r.x())&&void 0!==e?e:0),y:i.y-(null!==(t=null==r?void 0:r.y())&&void 0!==t?t:0),rotation:i.rotation,width:i.width,height:i.height})},Ze=o.useCallback(()=>{var e;if(null===(e=xe.current)||void 0===e?void 0:e.isTransforming()){return}const t=xe.current;if(!t||!t.nodes().length){return void Ie(0)}const n=t.getClientRect();if(!t.getStage()){return}const i=function(e,t,n,i=0){const o=e.x+e.width/2,r=e.y+e.height/2,l=e.width/2,s=e.height/2,a=i*Math.PI/180,d=e=>{const t=e*Math.PI/180,i=(e%360+360)%360;let d;d=0===i||180===i?s:l;const c=Math.sin(t)*(d+n),h=-Math.cos(t)*(d+n),m=c*Math.cos(a)-h*Math.sin(a),u=c*Math.sin(a)+h*Math.cos(a);return{x:o+m,y:r+u}},c=e=>e.x>=t.left&&e.x<=t.right&&e.y>=t.top&&e.y<=t.bottom;if(c(d(0))){return 0}for(const h of[180,270,90]){if(c(d(h))){return h}}return 0}(n,{top:(null==G?void 0:G.top)||0,bottom:a-((null==G?void 0:G.bottom)||0),left:(null==G?void 0:G.left)||0,right:r-((null==G?void 0:G.right)||0)},N.rotateAnchorOffset,t.rotation());Ie(i)},[G,r,a]);o.useEffect(()=>{var e;null===(e=xe.current)||void 0===e||e.update(),Ue(),Ze()},[e.scale,Ze]),o.useEffect(()=>{Ze()},[e.selectedShapes,Ze]);const _e=l(()=>({visible:!1,x1:0,y1:0,x2:0,y2:0})),He=o.useRef(!1),Je=s(t=>{var n,i,o,r,l,s,a;if(e.role===Y.VIEWER){return}He.current=!1;const d=t.target.findAncestor(".elements-container"),c=t.target.findAncestor("Transformer"),h=t.target.findAncestor(".page-abs-container");if(d||c||h){return}const m=null===(n=t.target.getStage())||void 0===n?void 0:n.getPointerPosition();m&&(m.x-=null!==(o=null===(i=t.target.getStage())||void 0===i?void 0:i.x())&&void 0!==o?o:0,m.y-=null!==(l=null===(r=t.target.getStage())||void 0===r?void 0:r.y())&&void 0!==l?l:0,_e.visible=!0,_e.x1=m.x,_e.y1=m.y,_e.x2=m.x,_e.y2=m.y,(null!==(a=null===(s=t.target.getStage())||void 0===s?void 0:s.getPointersPositions().length)&&void 0!==a?a:0)>=2&&(_e.visible=!1))});(({stageRef:e,containerRef:t,viewportSize:n})=>{o.useEffect(()=>{var n;const i=null===(n=t.current)||void 0===n?void 0:n.closest(".polotno-workspace-inner");function o(){var n;if(!e.current){return}const o=null===(n=t.current)||void 0===n?void 0:n.getBoundingClientRect(),r=null==i?void 0:i.getBoundingClientRect();if(!o||!r){return}const l=Math.max(0,r.left-o.left-100),s=Math.max(0,r.top-o.top-100);e.current.position({x:-l,y:-s}),e.current.container().style.transform=`translate(${l}px, ${s}px)`}return o(),null==i||i.addEventListener("scroll",o),()=>{null==i||i.removeEventListener("scroll",o)}},[n.width,n.height])})({stageRef:ye,containerRef:we,viewportSize:k}),o.useEffect(()=>{const t=s(e=>{var t,n,i,o,r,l;if(!_e.visible){return}null===(t=ye.current)||void 0===t||t.setPointersPositions(e);let s=null===(n=ye.current)||void 0===n?void 0:n.getPointerPosition();s?(s.x-=null!==(o=null===(i=ye.current)||void 0===i?void 0:i.x())&&void 0!==o?o:0,s.y-=null!==(l=null===(r=ye.current)||void 0===r?void 0:r.y())&&void 0!==l?l:0):s={x:_e.x2,y:_e.y2},_e.x2=s.x,_e.y2=s.y}),n=s(()=>{if(!_e.visible){return}if(!ye.current){return}const t=ye.current.findOne(".selection"),n=t?t.getClientRect({skipStroke:!0}):{width:0,height:0,x:0,y:0};if(n.width&&n.height){const t=[{x:n.x,y:n.y},{x:n.x+n.width,y:n.y},{x:n.x+n.width,y:n.y+n.height},{x:n.x,y:n.y+n.height}],i=[];ye.current.find(".element").forEach(n=>{var o;const r=e.getElementById(n.id()),l=null==r?void 0:r.draggable,s=null==r?void 0:r.selectable;if(!l||!s){return}const a=null===(o=n.getParent())||void 0===o?void 0:o.getAbsoluteTransform();if(!a){return}const d=T(r.a).map(e=>a.point(e));W(t,d)&&i.push(r.top.id)});const o=[...new Set(i)];He.current=!0,e.selectElements(o)}_e.visible=!1});return window.addEventListener("mousemove",t),window.addEventListener("touchmove",t),window.addEventListener("mouseup",n,{capture:!0}),window.addEventListener("touchend",n,{capture:!0}),()=>{window.removeEventListener("mousemove",t),window.removeEventListener("touchmove",t),window.removeEventListener("mouseup",n),window.removeEventListener("touchend",n)}},[]);const Ne=o.useCallback(t=>{if(!e.selectedElements[0]){return}if(t&&e.selectedElementsIds.includes(t)){return}const n=B(e.selectedShapes),o=t?e.getElementById(t):{x:0,y:0,width:i.computedWidth,height:i.computedHeight,rotation:0},r=C(o),l=[];n.minX>r.maxX&&l.push({distance:n.minX-r.maxX,box1:n,box2:r,points:[{x:n.minX,y:n.minY+n.height/2},{x:r.maxX,y:n.minY+n.height/2},{x:r.maxX,y:r.minY+r.height/2}]}),n.maxX<r.minX&&l.push({distance:r.minX-n.maxX,box1:n,box2:r,points:[{x:n.maxX,y:n.minY+n.height/2},{x:r.minX,y:n.minY+n.height/2},{x:r.minX,y:r.minY+r.height/2}]}),n.minY>r.maxY&&l.push({box1:n,box2:r,distance:n.minY-r.maxY,points:[{x:n.minX+n.width/2,y:n.minY},{x:n.minX+n.width/2,y:r.maxY},{x:r.minX+r.width/2,y:r.maxY}]}),n.maxY<r.minY&&l.push({box1:n,box2:r,distance:r.minY-n.maxY,points:[{x:n.minX+n.width/2,y:n.maxY},{x:n.minX+n.width/2,y:r.minY},{x:r.minX+r.width/2,y:r.minY}]});const s=n.minX>=r.minX&&n.maxX<=r.maxX&&n.minY>=r.minY&&n.maxY<=r.maxY;if(s&&(l.push({distance:n.minX-r.minX,box1:n,box2:r,points:[{x:n.minX,y:n.minY+n.height/2},{x:r.minX,y:n.minY+n.height/2},{x:r.minX,y:r.minY+r.height/2}]}),l.push({distance:r.maxX-n.maxX,box1:n,box2:r,points:[{x:n.maxX,y:n.minY+n.height/2},{x:r.maxX,y:n.minY+n.height/2},{x:r.maxX,y:r.minY+r.height/2}]}),l.push({box1:n,box2:r,distance:n.minY-r.minY,points:[{x:n.minX+n.width/2,y:n.minY},{x:n.minX+n.width/2,y:r.minY},{x:r.minX+r.width/2,y:r.minY}]}),l.push({box1:n,box2:r,distance:r.maxY-n.maxY,points:[{x:n.minX+n.width/2,y:n.maxY},{x:n.minX+n.width/2,y:r.maxY},{x:r.minX+r.width/2,y:r.maxY}]})),0===l.length&&!s){const e=n.minX<r.maxX&&n.maxX>r.minX,t=n.minY<r.maxY&&n.maxY>r.minY;if(e&&t){const e=(Math.max(n.minY,r.minY)+Math.min(n.maxY,r.maxY))/2,t=(Math.max(n.minX,r.minX)+Math.min(n.maxX,r.maxX))/2;n.minX<r.minX?l.push({distance:r.minX-n.minX,box1:n,box2:r,points:[{x:n.minX,y:e},{x:r.minX,y:e},{x:r.minX,y:e}]}):l.push({distance:n.minX-r.minX,box1:n,box2:r,points:[{x:n.minX,y:e},{x:r.minX,y:e},{x:r.minX,y:e}]}),n.maxX>r.maxX?l.push({distance:n.maxX-r.maxX,box1:n,box2:r,points:[{x:r.maxX,y:e},{x:n.maxX,y:e},{x:r.maxX,y:e}]}):l.push({distance:r.maxX-n.maxX,box1:n,box2:r,points:[{x:n.maxX,y:e},{x:r.maxX,y:e},{x:r.maxX,y:e}]}),n.minY<r.minY?l.push({box1:n,box2:r,distance:r.minY-n.minY,points:[{x:t,y:n.minY},{x:t,y:r.minY},{x:t,y:r.minY}]}):l.push({box1:n,box2:r,distance:n.minY-r.minY,points:[{x:t,y:n.minY},{x:t,y:r.minY},{x:t,y:r.minY}]}),n.maxY>r.maxY?l.push({box1:n,box2:r,distance:n.maxY-r.maxY,points:[{x:t,y:r.maxY},{x:t,y:n.maxY},{x:t,y:r.maxY}]}):l.push({box1:n,box2:r,distance:r.maxY-n.maxY,points:[{x:t,y:n.maxY},{x:t,y:r.maxY},{x:t,y:r.maxY}]})}}JSON.stringify(Ye)!==JSON.stringify(l)&&Se(l)},[e,i]);o.useEffect(()=>{e.selectedElements[0]&&e.distanceGuidesVisible?Ne():Ye&&Se(null)},[e.distanceGuidesVisible,Ne,e.selectedShapes.map(e=>`${e.x},${e.y},${e.width},${e.height},${e.rotation}`).join("|")]);const Ke=o.useRef(!1);o.useEffect(()=>{var e;let t;const n=null===(e=we.current)||void 0===e?void 0:e.closest(".polotno-workspace-inner"),i=()=>{Ke.current=!0,clearTimeout(t),t=setTimeout(()=>{Ke.current=!1},300)};return null==n||n.addEventListener("scroll",i),()=>{clearTimeout(t),null==n||n.removeEventListener("scroll",i)}},[]),o.useEffect(()=>{const t=ye.current;if(!t){return}const n=t.container(),i=new Map,o=e=>{i.set(e.target,{x:e.target.x(),y:e.target.y()})},r=e=>{i.delete(e.target)};t.on("dragstart",o),t.on("dragend",r);const l=t=>{var n,o;t.touches.length>=2&&((null===(n=xe.current)||void 0===n?void 0:n.isDragging())&&xe.current.stopDrag(),null===(o=xe.current)||void 0===o||o.nodes().forEach(t=>{var n;const o=i.get(t);t.isDragging()&&t.stopDrag(),o&&(t.setAttrs(o),null===(n=e.getElementById(t.id()))||void 0===n||n.set({x:o.x,y:o.y}))}))};return n.addEventListener("touchstart",l,{passive:!0}),n.addEventListener("touchmove",l,{passive:!0}),()=>{t.off("dragstart",o),t.off("dragend",r),n.removeEventListener("touchstart",l),n.removeEventListener("touchmove",l)}},[e]);const $e=t=>{if(e.role===Y.VIEWER){return}if(e.activePage!==i&&i.select(),Ke.current){return}if(He.current){return}const n=t.evt.shiftKey,o=t.evt.ctrlKey||t.evt.metaKey,r=n||o,l=t.target.findAncestor(".elements-container"),s=t.target.findAncestor(".page-abs-container"),a=t.target.findAncestor("Transformer"),d=t.target.findAncestor(".page-container",!0);if(!(r||l||a||s||d||_e.visible)){return e.selectElements([]),void e.selectPages([])}if(o&&!n){const t=ye.current,n=null==t?void 0:t.getPointerPosition();if(!t||!n){return}const i=t.getAllIntersections(n),o=new Set,r=[];for(const s of[...i].reverse()){const t=s.findAncestor(".element",!0);if(!t){continue}const n=e.getElementById(t.id()),i=null==n?void 0:n.top;i&&(o.has(i.id)||(o.add(i.id),r.push(i.id)))}if(0===r.length){return}let l;if(1===e.selectedElementsIds.length){const t=e.selectedElementsIds[0],n=r.indexOf(t);l=-1===n?r[0]:r[(n+1)%r.length]}else{l=r[0]}return e.selectElements([l]),void e.selectPages([])}const c=t.target.findAncestor(".element-container",!0),h=(null==c?void 0:c.findOne(".element"))||t.target.findAncestor(".element",!0),m=e.getElementById(null==h?void 0:h.id()),u=null==m?void 0:m.top;let g;if("group"===S){g=null==u?void 0:u.id}else if(u){const t=e.selectedElements.some(e=>{var t;return(null===(t=e.top)||void 0===t?void 0:t.id)===u.id});g=t?null==m?void 0:m.id:null==u?void 0:u.id}else{g=void 0}const f=null==m?void 0:m.id;if(f&&e.selectedElementsIds.indexOf(f)>=0&&!n){return}const p=!!g&&e.selectedElementsIds.indexOf(g)>=0,x=t.target.findAncestor(".page-container",!0);if(g&&n&&!p){const t=e.selectedElementsIds.concat([g]),n=new Set(t),i=t.filter(t=>{const i=e.getElementById(t);if(!i){return!1}for(let e=i.parent;e;e=null==e?void 0:e.parent){if(n.has(e.id)){return!1}}return!0});e.selectElements(i),e.selectPages([])}else{g&&n&&p?e.selectElements(e.selectedElementsIds.filter(e=>e!==g)):!g||n||p?g&&!n&&p||(x?(n||e.selectElements([]),e.selectPages([i.id])):e.selectPages([])):(e.selectElements([g]),e.selectPages([]))}};I(xe,e);const Qe=e.activePage===i,qe=e._selectedPagesIds.includes(i.id),et=null==w?void 0:w.PageControls,tt=null==w?void 0:w.Tooltip,nt=null==w?void 0:w.ContextMenu,it=1/e.scale,ot=0/e.scale;return n("div",{ref:we,onDragOver:e=>e.preventDefault(),onDrop:t=>{if(t.preventDefault(),e.role===Y.VIEWER){return}if(!ye.current){return}ye.current.setPointersPositions(t);const n=ye.current.findOne(".elements-container"),o=null==n?void 0:n.getRelativePointerPosition(),r=ye.current.getPointerPosition(),l=ye.current.getAllIntersections(r).map(e=>e.findAncestor(".element",!0)).filter(Boolean),s=[...new Set(l.reverse())].map(t=>e.getElementById(t.id())).filter(e=>!!e),a=s[0];he&&o&&(he(o,a,{elements:s,page:i}),he=null)},style:{position:"relative",width:r+"px",height:a+"px",overflow:"hidden",flexShrink:0},className:"polotno-page-container"+(Qe?" active-page":""),children:[t(x,{ref:ye,width:Math.min(r,k.width+200),height:Math.min(k.height+200,a),onClick:$e,onTap:$e,onContextMenu:t=>{if(t.evt.preventDefault(),e.role===Y.VIEWER){return}const n=t.target.findAncestor(".element",!0),i=e.getElementById(null==n?void 0:n.id()),o=null==i?void 0:i.top,r=null==o?void 0:o.id;if(!r){return e.selectElements([]),void Oe.close()}e.selectedElementsIds.indexOf(r)>=0||e.selectElements([r]),Oe.open({x:t.evt.clientX,y:t.evt.clientY})},onMouseDown:Je,onMouseMove:t=>{if(!e.distanceGuidesVisible&&!t.evt.altKey){return void(Ye&&Se(null))}const n=t.target.findAncestor(".element",!0),i=null==n?void 0:n.id();Ne(i)},onDragStart:t=>{var n;const i=t.target.getStage();if(i&&i.getPointersPositions().length>=2){return void t.target.stopDrag()}const o=t.target.findAncestor(".element",!0);if(o){const i=e.getElementById(null==o?void 0:o.id()),r=null==i?void 0:i.top,l=null==r?void 0:r.id;if(!(i&&e.selectedElementsIds.indexOf(i.id)>=0||l&&e.selectedElementsIds.indexOf(l)>=0)&&l){e.selectElements([l]);const i=ze();t.target.stopDrag(),i.forEach(e=>{e.isDragging()||e.startDrag(t)}),null===(n=xe.current)||void 0===n||n.startDrag(t),M()}}Ye&&Se(null)},pageId:i.id,style:{position:"absolute",overflow:"hidden",top:0,left:0},children:n(u,{children:[t(ie,{width:r,height:a,fill:J.workspaceBackgroundColor}),t(c,{x:ue,y:pe,scaleX:e.scale,scaleY:e.scale,name:"page-container",children:n(c,{name:"page-container-2",children:[t(c,{name:"page-background-group",x:re.left,y:re.top,children:t(le,{x:-oe.left,y:-oe.top,width:i.computedWidth+oe.left+oe.right,height:i.computedHeight+oe.top+oe.bottom,background:i.background,transparencyBackgroundColor:J.transparencyBackgroundColor,name:"page-background",preventDefault:!1,scale:e.scale})}),n(c,{x:re.left,y:re.top,name:"elements-container",listening:!e.isPlaying&&e.role!==Y.VIEWER,children:[t(f,{name:"elements-area",width:i.computedWidth,height:i.computedHeight,listening:!1}),t(ce,{elements:i.children,store:e})]}),t(p,{name:"bleed",fill:J.bleedColor,listening:!1,visible:e.bleedVisible&&(re.top>0||re.right>0||re.bottom>0||re.left>0),hideInExport:!0,sceneFunc:(e,t)=>{const{top:n,right:o,bottom:r,left:l}=oe,s=i.computedWidth,a=i.computedHeight,d=e._context;d.beginPath(),d.rect(0,0,l+s+o,n+a+r),d.rect(l,n,s,a),d.fillStyle=t.fill(),d.fill("evenodd")}}),R()===ge&&t(fe,{name:"hit-detection",x:-it/2-ot,y:-it/2-ot,width:ae+it+2*ot,height:me+it+2*ot})]})}),t(g,{name:"workspace-background",points:[0,0,r,0,r,a,0,a,0,0,ue,pe,ue,a-pe,r-ue,a-pe,r-ue,pe,ue,pe],listening:!1,closed:!0,fill:J.workspaceBackgroundColor}),t(c,{x:ue,y:pe,scaleX:e.scale,scaleY:e.scale,children:t(f,{name:"page-highlight",hideInExport:!0,x:-it/2-ot,y:-it/2-ot,width:ae+it+2*ot,height:me+it+2*ot,stroke:qe?J.activePageBorderColor:J.pageBorderColor,strokeWidth:2,listening:!1,strokeScaleEnabled:!1})}),n(c,{x:ue+re.left*e.scale,y:pe+re.top*e.scale,scaleX:e.scale,scaleY:e.scale,name:"page-abs-container",children:[t(y,{ref:xe,rotateAnchorAngle:Me,onDragStart:t=>{var n;const o=t.target.getStage();o&&o.getPointersPositions().length>=2?t.target.stopDrag():((null===(n=t.evt)||void 0===n?void 0:n.altKey)&&E&&e.selectedElements.forEach(e=>{const t=e.clone({},{skipSelect:!0}),n=i.children.indexOf(e);i.setElementZIndex(t.id,n)}),Xe.current||(Xe.current=!0,e.history.startTransaction()))},onDragEnd:()=>{Xe.current&&(e.history.endTransaction(),Xe.current=!1),Ze()},onTransformStart:()=>{e.history.startTransaction(),ve.current=new Map(Te.map(e=>[e.id,{width:e.width,height:e.height}])),Se(null)},boundBoxFunc:(t,n)=>{var i,o;const r=Math.abs(n.width)<1||Math.abs(n.height)<1,l=Math.abs(t.width)<1||Math.abs(t.height)<1;if(r&&!l){return t}const s=e.selectedElements;if(1===s.length&&"table"===(null===(i=s[0])||void 0===i?void 0:i.type)){const e=s[0],i=Math.abs(t.width),o=Math.abs(t.height);if(i>0&&o>0){const r=Math.abs(n.width)/i,l=Math.abs(n.height)/o,s=e.width*r,a=e.height*l,d=Object.assign({},n);return s<e.minWidth&&(d.width=t.width),a<e.minHeight&&(d.height=t.height),te(d,n,t)}}return Be&&Te.length>0?((e,t,n,i,o)=>{const r=Math.abs(e.width),l=Math.abs(e.height);if(0===r||0===l){return t}const s=Math.abs(t.width)/r,a=Math.abs(t.height)/l,d=!V(n),c=e=>i.some(t=>{var n;const i=null==o?void 0:o.get(t.id),r=null!==(n="x"===e?null==i?void 0:i.width:null==i?void 0:i.height)&&void 0!==n?n:"x"===e?t.width:t.height,l="x"===e?t.width:t.height,c="x"===e?s:a,h=((e,t,n,i)=>{if("table"===e.type){const n=e;return"x"===t?n.minWidth:n.minHeight}return"text"===e.type&&"x"===t&&n?F(i,e.fontSize):1})(t,e,d,r);return r>=h&&l*c<h}),h=Object.assign({},t),m=t.width*e.width<0,u=t.height*e.height<0,g=m||c("x"),f=u||c("y"),p=f||!d&&g;return(g||!d&&f)&&(h.width=e.width),p&&(h.height=e.height),te(h,t,e)})(t,n,(null===(o=xe.current)||void 0===o?void 0:o.getActiveAnchor())||"",Te,ve.current):n},onTransform:e=>{const t=xe.current.nodes(),n=t[t.length-1];e.target===n&&setTimeout(()=>{Ue()},0)},onTransformEnd:t=>{Ae({}),e.history.endTransaction(),ve.current=null,Ze(),ze()},visible:!e.isPlaying}),Ye&&Ye.map(({points:i,distance:o,box1:r,box2:l},s)=>n(c,{name:"distances-container",hideInExport:!0,listening:!1,children:[t(f,Object.assign({},r,{stroke:J.distanceGuideStyle.stroke,strokeWidth:1,strokeScaleEnabled:!1})),t(f,Object.assign({},l,{stroke:J.distanceGuideStyle.stroke,strokeWidth:1,strokeScaleEnabled:!1})),t(g,{points:[i[0].x,i[0].y,i[1].x,i[1].y],stroke:J.distanceGuideStyle.stroke,strokeWidth:1,strokeScaleEnabled:!1}),t(g,{points:[i[1].x,i[1].y,i[2].x,i[2].y],stroke:J.distanceGuideStyle.stroke,strokeWidth:1,strokeScaleEnabled:!1}),n(m,{x:(i[0].x+i[1].x)/2,y:(i[0].y+i[1].y)/2,offsetY:-10,scaleX:1/e.scale,scaleY:1/e.scale,children:[t(v,{cornerRadius:5,fill:J.distanceGuideStyle.labelFill,pointerDirection:"down"}),t(b,{align:"center",verticalAlign:"middle",fill:J.distanceGuideStyle.labelTextFill,padding:5,text:L({unit:e.unit,dpi:e.dpi,px:o})})]})]},s)),i._rendering&&n(c,{children:[t(f,{width:ae,height:me,fill:"rgba(255,255,255,0.9)"}),t(b,{text:"Rendering...",fontSize:60,width:ae,height:me,align:"center",verticalAlign:"middle"})]}),tt&&t(tt,{components:w,store:e,page:i,stageRef:ye,tooltipSafeArea:P}),nt&&t(H,{children:t(nt,Object.assign({components:w,store:e},Oe.props))})]}),t(A,{store:e,page:i,width:r,height:a,scale:e.scale,xPadding:ue,yPadding:pe,bleedLeft:re.left,bleedTop:re.top}),t(de,Object.assign({},ke,{store:e})),t(se,{selection:_e}),j()>0&&n(c,{hideInExport:!0,children:[t(be,{name:"cache-bounds",x:r-(1===j()?250:210),y:a-(1===j()?95:45)}),t(be,{name:"cache-bounds-t",x:10,y:10})]}),D()&&t(b,{text:"Powered by polotno.com",fontSize:14,fill:"rgba(0,0,0,0.6)",x:r-170,y:a-18,onMouseEnter:e=>{e.target.getStage().container().style.cursor="pointer"},onMouseLeave:e=>{e.target.getStage().container().style.cursor=""},onTouchStart:e=>{e.cancelBubble=!0},onMouseDown:e=>{e.cancelBubble=!0},onClick:()=>{window.open("https://polotno.com","_blank","noopener")},onTap:()=>{window.open("https://polotno.com","_blank","noopener")}}),t(c,{name:"line-guides"})]})}),Ee&&et&&t(et,{store:e,page:i,xPadding:ue,yPadding:pe,layout:O})]})});
|
|
1
|
+
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})]})});
|
package/canvas/tooltip.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as
|
|
1
|
+
import{jsx as t,jsxs as e}from"react/jsx-runtime";import n from"react";import{observer as o}from"mobx-react-lite";import{Html as r}from"react-konva-utils";import{getTotalClientRect as l}from"../utils/math.js";import{extendToolbar as i}from"../toolbar/element-container.js";import{TextAiWrite as s}from"../toolbar/text-ai-write.js";import{flags as u}from"../utils/flags.js";import{DuplicateButton as a}from"../toolbar/duplicate-button.js";import{RemoveButton as c}from"../toolbar/remove-button.js";import{PositionPicker as d}from"../toolbar/position-picker.js";import{GroupButton as m}from"../toolbar/group-button.js";import{Navbar as v}from"../primitives/navbar.js";import{MAIN_TRANSFORMER_NAME as p}from"../utils/px.js";function f(t,e){return t.classList.contains(e)?t:t.parentElement?f(t.parentElement,e):null}const h=()=>null,g=({stage:t})=>{var e,n;return(null===(e=null==t?void 0:t.container())||void 0===e?void 0:e.closest(".polotno-workspace-container"))||(null===(n=null==t?void 0:t.container())||void 0===n?void 0:n.parentNode)};export const Tooltip=o(({store:o,page:b,components:x,stageRef:j,tooltipSafeArea:E})=>{var w,y;const N=o.selectedShapes.every(t=>t.page===b),I=n.useRef(null),O=n.useRef(null),[S,R]=n.useState(!1),[,C]=n.useReducer(t=>t+1,0),F=n.useCallback(t=>{var e,n;t?(I.current=t,null===(e=O.current)||void 0===e||e.disconnect(),O.current=new ResizeObserver(C),O.current.observe(t),C()):I.current&&!I.current.isConnected&&(I.current=null,null===(n=O.current)||void 0===n||n.disconnect(),O.current=null)},[]),k=o._hasCroppedImages;n.useEffect(()=>{var t,e,n;const o=()=>{R(!0)},r=()=>{R(!1)};null===(t=null==j?void 0:j.current)||void 0===t||t.on("dragstart",o),null===(e=null==j?void 0:j.current)||void 0===e||e.on("dragend",r);const l=null===(n=null==j?void 0:j.current)||void 0===n?void 0:n.findOne(`.${p}`);return null==l||l.on("transformstart",o),null==l||l.on("transformend",r),()=>{var t,e;null===(t=null==j?void 0:j.current)||void 0===t||t.off("dragstart",o),null===(e=null==j?void 0:j.current)||void 0===e||e.off("dragend",r),null==l||l.off("transformstart",o),null==l||l.off("transformend",r)}},[]),n.useEffect(()=>{if(!(null==j?void 0:j.current)){return}const t=f(j.current.content,"polotno-workspace-inner");if(!t){return}const e=()=>{o.selectedShapes.length&&C()};return t.addEventListener("scroll",e),()=>{t.removeEventListener("scroll",e)}},[]);const T=o.selectedElements.map(t=>t.id).join(",");if(n.useEffect(()=>{if(!T){return}const t=requestAnimationFrame(()=>C());return()=>cancelAnimationFrame(t)},[T]),0===o.selectedShapes.length){return null}if(S){return null}if(!N){return null}if(o.activePage!==b){return null}if(k){return null}const M=l(o.selectedShapes),P=(null==x?void 0:x.Position)||d,X=(null==x?void 0:x.Duplicate)||a,Y=(null==x?void 0:x.Remove)||c,A=(null==x?void 0:x.Group)||m,L=(null==x?void 0:x.Lock)||h,B=null===(w=o.selectedElements[0])||void 0===w?void 0:w.type,_=Object.assign(Object.assign({},u.aiTextEnabled?{TextAiWrite:s}:{}),x||{}),z=i({components:_,type:B,usedItems:[]}),J=!!(null===(y=I.current)||void 0===y?void 0:y.isConnected);return t(r,{parentNodeFunc:g,transformFunc:t=>{var e,n,o;const r=M.x+M.width/2,l=null===(e=null==j?void 0:j.current)||void 0===e?void 0:e.container(),i=(null==l?void 0:l.getBoundingClientRect())||{left:0,top:0,width:0,height:0,right:0,bottom:0,x:0,y:0,toJSON:()=>({})},s=null==l?void 0:l.closest(".polotno-workspace-container"),u=(null==s?void 0:s.getBoundingClientRect())||{left:0,top:0,width:Number.POSITIVE_INFINITY,height:Number.POSITIVE_INFINITY,right:0,bottom:0,x:0,y:0,toJSON:()=>({})},a=i.left-u.left,c=i.top-u.top,d=(null===(n=I.current)||void 0===n?void 0:n.isConnected)?I.current.getBoundingClientRect():null,m=(null==d?void 0:d.width)||0,v=(null==d?void 0:d.height)||34,p=((null==E?void 0:E.top)||0)+8,f=(null!==(o=null==E?void 0:E.bottom)&&void 0!==o?o:45)+8,h=c+t.y+M.y*t.scaleY,g=c+t.y+(M.y+M.height)*t.scaleY,b=Number.isFinite(u.height),x=p+v/2,w=u.height-f-v/2;let y=h-80;b&&(y=Math.max(x,y));let N=y+v/2<=h-48?y:g+80;b&&(N=Math.min(w,Math.max(x,N)));let O=a+t.x+r*t.scaleX,S=O-M.width*t.scaleX/2,R=O+M.width*t.scaleX/2;const C=Math.min(50,M.width/2*t.scaleX),F=R>=C&&S<=u.width-C,k=(null==E?void 0:E.left)||0,T=(null==E?void 0:E.right)||0;if(Number.isFinite(u.width)&&m>0&&F){const t=8+m/2+k,e=u.width-8-m/2-T;e>=t&&(O=Math.max(t,Math.min(O,e)))}return R<C&&(O-=m+8),S>u.width-C&&(O+=m+8),Object.assign(Object.assign({},t),{x:O,y:N,scaleX:1,scaleY:1})},divProps:{style:{pointerEvents:"none",position:"absolute",visibility:J?"visible":"hidden",zIndex:9}},children:t("div",{ref:F,className:"polotno-selection-tooltip",style:{pointerEvents:"none"},children:e(v,{floating:!0,height:34,className:"pn:gap-0.5 pn:bg-popover pn:px-0.5",style:{transform:"translate(-50%, -50%)",pointerEvents:"auto"},children:[z.map(e=>{const n=_[e];return t(n,{elements:o.selectedElements,element:o.selectedElements[0],store:o},e)}),t(A,{store:o}),t(L,{store:o}),t(X,{store:o}),t(Y,{store:o}),t(P,{store:o})]})})})});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type Konva from 'konva';
|
|
2
|
+
import type { Box } from 'konva/lib/shapes/Transformer';
|
|
3
|
+
export declare const restoreHeldPoint: (clamped: Box, newBox: Box, oldBox: Box) => Box;
|
|
4
|
+
export type CropBoundMode = 'cover' | 'contain';
|
|
5
|
+
type Ref<T> = {
|
|
6
|
+
current: T | null;
|
|
7
|
+
};
|
|
8
|
+
export declare const cropBoundBoxFunc: (moving: Ref<Konva.Node>, fixed: Ref<Konva.Node>, mode: CropBoundMode, themed?: (oldBox: Box, newBox: Box) => Box) => (oldBox: Box, newBox: Box) => Box;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{clamp as t}from"../lib/utils.js";const h=(h,i)=>{const e=Math.cos(i.rotation),n=Math.sin(i.rotation),r=i.x-h.x,a=i.y-h.y,o=h.width-i.width,d=h.height-i.height;return{x:0===o?0:t((r*e+a*n)/o,0,1),y:0===d?0:t((a*e-r*n)/d,0,1)}};export const restoreHeldPoint=(t,i,e)=>{if(t.width===i.width&&t.height===i.height){return t}const n=h(e,i),r=Math.cos(i.rotation),a=Math.sin(i.rotation),o=n.x*(e.width-t.width),d=n.y*(e.height-t.height);return t.x=e.x+o*r-d*a,t.y=e.y+o*a+d*r,t};const i=(h,i,e,n)=>i>e?n:t(h,i,e);export const cropBoundBoxFunc=(t,e,n,r)=>(a,o)=>{var d;const s=r&&null!==(d=r(a,o))&&void 0!==d?d:o;if(!(a.width>0&&a.height>0)){return s}const c=h(a,s),g=t.current&&e.current?((t,h,i,e,n)=>{const r=h.width()*h.scaleX(),a=h.height()*h.scaleY();if(!(r>0&&a>0)){return null}const o=(i.x()-h.x())/r,d=o+i.width()*i.scaleX()/r,s=(i.y()-h.y())/a,c=s+i.height()*i.scaleY()/a,g=(t,h,i)=>{const n="cover"===e?0:1/0,r=t>0?(t-h)/t:n,a=t<1?(i-t)/(1-t):n;return"cover"===e?Math.max(r,a):Math.min(r,a)},m=g(n.x,o,d)*t.width,x=g(n.y,s,c)*t.height;return"cover"===e?{minWidth:Math.max(m,5),minHeight:Math.max(x,5),maxWidth:1/0,maxHeight:1/0}:{minWidth:5,minHeight:5,maxWidth:m,maxHeight:x}})(a,t.current,e.current,n,c):null;if(!g){return s}const m=s.width/a.width,x=s.height/a.height,u=Math.abs(m-x)<=1e-9*Math.max(Math.abs(m),Math.abs(x),1),w=Object.assign({},s);if(u){const t=i(m,Math.max(g.minWidth/a.width,g.minHeight/a.height),Math.min(g.maxWidth/a.width,g.maxHeight/a.height),1);t!==m&&(w.width=a.width*t,w.height=a.height*t)}else{w.width=i(s.width,g.minWidth,g.maxWidth,a.width),w.height=i(s.height,g.minHeight,g.maxHeight,a.height)}return restoreHeldPoint(w,s,a)};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export type ImageStatus = 'loading' | 'loaded' | 'failed';
|
|
2
|
+
export type CrossOrigin = 'anonymous' | 'use-credentials';
|
|
3
|
+
export declare function useImage(url: string, crossOrigin?: CrossOrigin, referrerPolicy?: string): [HTMLImageElement | undefined, ImageStatus];
|
|
4
|
+
export default useImage;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import e from"react";import{DEFAULT_RETRIES as r,isDeterministicUrl as t,retryDelayMs as n}from"@polotno/core/retry";export function useImage(o,u,c){const i=e.useRef("loading"),d=e.useRef(void 0),[,s]=e.useState(0),a=e.useRef(void 0),l=e.useRef(void 0),f=e.useRef(void 0);return a.current===o&&l.current===u&&f.current===c||(i.current="loading",d.current=void 0,a.current=o,l.current=u,f.current=c),e.useLayoutEffect(()=>{if(!o){return}const e=t(o)?1:r;let a,l,f=0,m=!1,v=!1;const g=(e,r)=>{i.current=r,d.current=e,s(Math.random())},E=()=>{f+=1;const r=document.createElement("img"),t=()=>{r.decode().catch(()=>{}).finally(()=>{m||(v=!0,g(r,"loaded"))})},i=()=>{if(!m){return!v&&f<e?(null==l||l(),void(a=setTimeout(E,n(f)))):void g(void 0,"failed")}};r.addEventListener("load",t),r.addEventListener("error",i),l=()=>{r.removeEventListener("load",t),r.removeEventListener("error",i)},u&&(r.crossOrigin=u),c&&(r.referrerPolicy=c),r.src=o};return E(),()=>{m=!0,clearTimeout(a),null==l||l()}},[o,u,c]),[d.current,i.current]}export default useImage;
|
package/canvas/video-element.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import i from"react";import{observer as o}from"mobx-react-lite";import{isAlive as n}from"mobx-state-tree";import{nodeAutorun as a}from"../utils/mobx.js";import{Arc as d,Group as s,Image as l,Rect as c,Text as h,Transformer as u}from"react-konva";import{ROLES as g}from"../model/store.js";import m from"use-image";import p from"konva";import{Portal as f}from"react-konva-utils";import{useWorkspaceStyle as v}from"./workspace-style.js";import{incrementLoader as w,triggerLoadError as x}from"../utils/loader.js";import{polotnoError as M}from"@polotno/core/errors";import{getCropRect as y}from"@polotno/core/image";import*as E from"@polotno/core/svg";import{flags as b}from"../utils/flags.js";import{roundEnabledPx as L,activeAnchorOf as T,roundedCropFraction as C,roundedGeometryPx as R,roundedPosition as S,isCornerAnchor as k,scaledBoxStyleAttrs as I,roundedBoxStyleAttrs as X}from"../utils/px.js";import{useFilteredSource as Y}from"./use-filtered-source.js";import{useEvent as H}from"../hooks/use-event.js";import{useFadeIn as W}from"./use-fadein.js";import{isTouchDevice as j}from"../utils/screen.js";import{createPlayGate as P,playMedia as O}from"../utils/media.js";import{useMediabunnyVideo as _}from"./use-mediabunny-video.js";import{getElementTimeRange as A,getVideoRestMs as V}from"../utils/timeline.js";import{resampleCanvas as D,RESAMPLE_SKIP_THRESHOLD as z}from"./downscale.js";import{useSizeFixer as U}from"./image-element.js";function B(){return document.createElement("canvas")}const F=new window.Image;F.src=E.svgToURL('\n <svg width="800px" height="800px" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">\n <path opacity="0.6" d="M4 5.49683V18.5032C4 20.05 5.68077 21.0113 7.01404 20.227L18.0694 13.7239C19.384 12.9506 19.384 11.0494 18.0694 10.2761L7.01404 3.77296C5.68077 2.98869 4 3.95 4 5.49683Z" fill="white"/>\n <path d="M4 5.49683V18.5032C4 20.05 5.68077 21.0113 7.01404 20.227L18.0694 13.7239C19.384 12.9506 19.384 11.0494 18.0694 10.2761L7.01404 3.77296C5.68077 2.98869 4 3.95 4 5.49683Z" stroke="#323232" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>\n </svg>\n');const N=new window.Image;N.src=E.svgToURL('\n <svg width="800px" height="800px" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">\n <path opacity="0.6" d="M14 19L14 5C14 3.89543 14.8954 3 16 3L17 3C18.1046 3 19 3.89543 19 5L19 19C19 20.1046 18.1046 21 17 21L16 21C14.8954 21 14 20.1046 14 19Z" fill="white"/>\n <path opacity="0.6" d="M10 19L10 5C10 3.89543 9.10457 3 8 3L7 3C5.89543 3 5 3.89543 5 5L5 19C5 20.1046 5.89543 21 7 21L8 21C9.10457 21 10 20.1046 10 19Z" fill="white"/>\n <path d="M14 19L14 5C14 3.89543 14.8954 3 16 3L17 3C18.1046 3 19 3.89543 19 5L19 19C19 20.1046 18.1046 21 17 21L16 21C14.8954 21 14 20.1046 14 19Z" stroke="#323232" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>\n <path d="M10 19L10 5C10 3.89543 9.10457 3 8 3L7 3C5.89543 3 5 3.89543 5 5L5 19C5 20.1046 5.89543 21 7 21L8 21C9.10457 21 10 20.1046 10 19Z" stroke="#323232" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>\n </svg>\n');export const useCornerRadiusAndCrop=(e,t,r,o,n=0,a=!1)=>{var d,s;const l=Math.floor(Math.max(e.width*o,1)),c=Math.floor(Math.max(e.height*o,1)),h=Math.min(n*o,l/2,c/2),u=Math.max(e.width/r.width,e.height/r.height)*o,g=(null===(d=e.page)||void 0===d?void 0:d._exportingOrRendering)&&b.imageDownScalingEnabled&&u<z&&!a,m=t instanceof HTMLVideoElement?t.videoWidth:null==t?void 0:t.width,f=t instanceof HTMLVideoElement?t.videoHeight:null==t?void 0:t.height,v=0===r.x&&0===r.y&&r.width===m&&r.height===f,w=i.useMemo(()=>{if(t&&m&&f){return v&&0===h&&!g?void 0:B()}},[t,h,g,v,m,f]),x=()=>{if(!w||!t){return}w.width=l,w.height=c;const e=w.getContext("2d");if(e){if(h&&(e.beginPath(),e.moveTo(h,0),e.lineTo(l-h,0),e.arc(l-h,h,h,3*Math.PI/2,0,!1),e.lineTo(l,c-h),e.arc(l-h,c-h,h,0,Math.PI/2,!1),e.lineTo(h,c),e.arc(h,c-h,h,Math.PI/2,Math.PI,!1),e.lineTo(0,h),e.arc(h,h,h,Math.PI,3*Math.PI/2,!1),e.clip()),g){const i=D(t,r,w.width,w.height);return e.drawImage(i,0,0),void p.Util.releaseCanvas(i)}e.drawImage(t,r.x,r.y,r.width,r.height,0,0,w.width,w.height)}};return i.useLayoutEffect(()=>{x()},[w,e.width,e.height,r.x,r.y,r.width,r.height,n,o,a,null===(s=e.page)||void 0===s?void 0:s._exportingOrRendering,g]),i.useEffect(()=>()=>{w&&"CANVAS"===w.nodeName&&p.Util.releaseCanvas(w)},[w]),[w||t,x]};const Z=B(),$=o(({element:r})=>{const o=Math.min(30,r.width/4,r.height/4),n=i.useRef(null);i.useEffect(()=>{const e=n.current;if(!e){return}const t=new p.Animation(t=>{e.rotate(((null==t?void 0:t.timeDiff)||0)/2)},e.getLayer());return t.start(),()=>{t.stop()}});const{mediaLoadingStyle:a}=v();return t(s,{x:r.a.x,y:r.a.y,rotation:r.a.rotation,listening:!1,opacity:r.a.opacity,hideInExport:!r.showInExport,children:[e(c,{width:r.width,height:r.height,fill:a.fill}),e(d,{ref:n,x:r.width/2,y:r.height/2,fill:a.textFill,outerRadius:Math.abs(o),innerRadius:Math.max(1,o-5),angle:270})]})}),q=o(({element:r})=>{const{mediaErrorStyle:i}=v(),o=Math.max(10,Math.min(30,r.width/25));return t(s,{x:r.a.x,y:r.a.y,rotation:r.a.rotation,listening:!1,opacity:r.a.opacity,hideInExport:!r.showInExport,children:[e(c,{width:r.width,height:r.height,fill:i.fill}),e(h,{text:"Can not load the video...",fontSize:o,width:r.width,height:r.height,align:"center",fill:i.textFill,verticalAlign:"middle",padding:5})]})});let G=function(e,t,r){const o=i.useRef("loading"),n=i.useRef(void 0),[a,d]=i.useState(0),s=i.useRef(void 0),l=i.useRef(void 0),c=i.useRef(void 0);return s.current===e&&l.current===t&&c.current===r||(o.current="loading",n.current=void 0,s.current=e,l.current=t,c.current=r),i.useLayoutEffect(function(){if(e){var i=document.createElement("video");return i.addEventListener("canplay",a),i.addEventListener("error",s),t&&(i.crossOrigin=t),r&&(i.referrerPolicy=r),i.src=e,i.load(),function(){i.removeEventListener("canplay",a),i.removeEventListener("error",s)}}function a(){o.current="loaded",n.current=i,n.current.currentTime=0,d(Math.random()),n.current.removeEventListener("canplay",a)}function s(e){var t;const r=4===i.readyState,a=i.buffered&&i.buffered.length>0&&i.buffered.end(i.buffered.length-1)/i.duration*100>=100;if(r&&a){return}const s=e.message||(null===(t=i.error)||void 0===t?void 0:t.message)||"Unknown error",l=new Error("Video failed to load: "+s);console.error(l),o.current="failed",n.current=void 0,d(Math.random())}},[e,t,r]),[n.current,o.current]};export const setVideoLoaderHook=e=>{G=e};function J(e){return e.readyState>=HTMLMediaElement.HAVE_CURRENT_DATA}export const useLoader=(e,t,r)=>{const o=i.useRef(void 0),n=()=>{var e;null===(e=o.current)||void 0===e||e.call(o),o.current=void 0};i.useEffect(()=>n,[]),i.useLayoutEffect(()=>{const i=t.slice(0,200),a=`video with id ${r} url: ${i}`;"loading"!==e||o.current||(o.current=w(a)),"loading"!==e&&n(),"failed"===e&&x(M("VIDEO_FAILED",a,{src:i,elementId:r,reason:"load"}))},[e])};export const VideoElement=o(({element:o,store:d})=>{var h,v,x;const[M,b]=i.useState(!1),D=i.useRef(null),z=i.useRef(null),K=o.isSelected,[Q,ee]=i.useState(!1),[te,re]=G(o.src,"anonymous"),[ie,oe]=i.useState(!1),ne=d.activePage===o.page,ae=(null===(h=o.page)||void 0===h?void 0:h._exportingOrRendering)&&"loaded"===re,de=_(o,d,ae);useLoader(re,o.src,o.id),te&&(te.playsInline=!0);const se=((e,t,r)=>{const o=i.useMemo(()=>{var i,o;const{flipX:n,flipY:a}=e,d="svg"===e.type||E.isSvgUrl(e.src),s=navigator.userAgent.toLowerCase().indexOf("firefox")>-1;if(!(n||a||s&&d)){return t}if(!t){return null}const l=t instanceof HTMLVideoElement?t.videoWidth:null==t?void 0:t.width,c=t instanceof HTMLVideoElement?t.videoHeight:null==t?void 0:t.height;if(!l||!c){return null}const h=B();let u=1;"svg"===e.type&&(u=Math.max(e.width/l*r,e.height/c*r)),h.width=Math.max(l*u,1),h.height=Math.max(c*u,1);let g=n?-h.width:0,m=a?-h.height:0;return null===(i=h.getContext("2d"))||void 0===i||i.scale(n?-1:1,a?-1:1),null===(o=h.getContext("2d"))||void 0===o||o.drawImage(t,g,m,h.width,h.height),h},[e.flipX,e.flipY,t,e.width,e.height,r]);return i.useEffect(()=>()=>{o&&"CANVAS"===o.nodeName&&p.Util.releaseCanvas(o)},[o]),o})(o,te,d._elementsPixelRatio),le=ae&&de||se||Z,[ce=Z,he]=Y(o,le);i.useEffect(()=>{te&&d.history.ignore(()=>{o.set({duration:1e3*te.duration})})},[te]);const ue=i.useMemo(P,[te]);i.useEffect(()=>{var e;if(!te){return}const t=d.animatedElementsIds,r=(!t.length||t.includes(o.id))&&d.isPlaying;if(!ne||!r&&!Q){return void te.pause()}Q&&(te.muted=!1,te.currentTime=o.startTime*te.duration,O(te).then(e=>{"refused"===e&&ee(!1)}));const i=new p.Animation(()=>{Ie()},null===(e=D.current)||void 0===e?void 0:e.getLayer());i.start();const n=()=>{ee(!1),te.currentTime=o.startTime*te.duration},a=()=>{te.currentTime>=o.endTime*te.duration&&(te.pause(),te.currentTime=o.startTime*te.duration,ee(!1))};return te.addEventListener("ended",n),te.addEventListener("timeupdate",a),()=>{te.pause(),i.stop(),te.removeEventListener("ended",n),te.removeEventListener("timeupdate",a)}},[te,Q,d.isPlaying,ne]),i.useEffect(()=>{te&&(te.volume=o.volume)},[te,o.volume]),i.useEffect(()=>{te&&(te.playbackRate=o.speed,te.preservesPitch=!1)},[te,o.speed]);const ge=i.useRef(null);i.useEffect(()=>{const e=a(o,()=>{var e,t;if(te){if(ae&&de){return Ie(),void d.currentTime}const r=d.animatedElementsIds;if(r.length&&!r.includes(o.id)){return}const i=d.activePage===o.page,n=d.currentTime>=o.page.startTime&&d.currentTime<o.page.startTime+o.page.duration,a=o.startTime*te.duration*1e3,s=te.duration*(o.endTime-o.startTime)*1e3,{start:l,end:c}=A(o.animations,o.page.duration),h=(d.currentTime||o.page.startTime)-o.page.startTime,u=n?V(d.currentTime,o.page.startTime,l,s,a,o.speed):0,g=u/1e3,m=n&&h>=l&&h<c;Q||(te.muted=!m,m&&d.isPlaying&&i?te.paused?(te.currentTime=g,ue.play(te)):Math.abs(1e3*te.currentTime-u)>500&&(te.currentTime=g):(ue.reset(),te.paused||te.pause(),g!==te.currentTime&&(te.currentTime=g),!J(te)&&!d.isPlaying&&!ge.current&&(ge.current=w(`video ${o.id}`)))),Ie(),null===(t=null===(e=D.current)||void 0===e?void 0:e.getLayer())||void 0===t||t.batchDraw()}});return()=>{e(),ge.current&&(ge.current(),ge.current=null)}},[d,te,ae,de,Q]),i.useEffect(()=>{var e,t;if(!te){return}if(ae){return null===(e=ge.current)||void 0===e||e.call(ge),void(ge.current=null)}const r=()=>{var e,t,r;!J(te)&&(null===(e=o.page)||void 0===e?void 0:e._exportingOrRendering)||ge.current&&(Ie(),null===(r=null===(t=D.current)||void 0===t?void 0:t.getLayer())||void 0===r||r.batchDraw(),ge.current(),ge.current=null)};let i;return(null===(t=o.page)||void 0===t?void 0:t._exportingOrRendering)&&(i=setInterval(r,20)),te.addEventListener("timeupdate",r),te.addEventListener("canplay",r),()=>{clearInterval(i),te.removeEventListener("timeupdate",r),te.removeEventListener("canplay",r)}},[null===(v=o.page)||void 0===v?void 0:v._exportingOrRendering,te,o.id,w,ae]);let{cropX:me,cropY:pe,cropWidth:fe,cropHeight:ve}=o;"loaded"!==re&&(me=pe=0,fe=ve=1);const we=(xe=ce)instanceof HTMLVideoElement?xe.videoWidth:(null==xe?void 0:xe.width)||0;var xe;const Me=(e=>e instanceof HTMLVideoElement?e.videoHeight:(null==e?void 0:e.height)||0)(ce),ye=y({cropX:me,cropY:pe,cropWidth:fe,cropHeight:ve,width:o.width,height:o.height},{width:we,height:Me}),Ee=ye.width,be=ye.height,Le="svg"===o.type,Te=null!==(x=o.cornerRadius)&&void 0!==x?x:0,[Ce,Re]=useCornerRadiusAndCrop(o,ce,ye,d._elementsPixelRatio,Te,!0);let[Se,ke]=((e,t,r,o)=>{const n=U(e.clipSrc||""),[a,d]=m(n,"anonymous"),s=e.clipSrc?d:"loaded";useLoader(s,e.clipSrc,e.id);const l=i.useMemo(()=>{if(t&&a){return B()}},[t,a]);function c(){var i;if(!a){return}const o=t instanceof HTMLVideoElement?t.videoWidth:null==t?void 0:t.width,n=t instanceof HTMLVideoElement?t.videoHeight:null==t?void 0:t.height;if(!t||!o||!n){return}if(!a||!a.width||!a.height){return}if(!l){return}const d=B(),s=Math.max(e.width/a.width*r,e.height/a.height*r);d.width=a.width*s,d.height=a.height*s,null===(i=d.getContext("2d"))||void 0===i||i.drawImage(a,0,0,d.width,d.height),l.width=Math.max(o,1),l.height=Math.max(n,1);const c=l.getContext("2d");c&&(c.save(),c.drawImage(d,0,0,o,n),p.Util.releaseCanvas(d),c.globalCompositeOperation="source-in",c.drawImage(t,0,0,l.width,l.height),c.restore())}return i.useLayoutEffect(()=>{c()},[l,t,a,e.width,e.height,r,...o]),[e.clipSrc&&a?l:t,c]})(o,Ce,d._elementsPixelRatio,[ye,Te,d._elementsPixelRatio]);const Ie=H(()=>{var e,t;he(),Re(),ke(),null===(t=null===(e=D.current)||void 0===e?void 0:e.getLayer())||void 0===t||t.batchDraw()});i.useEffect(()=>{Ie()});const Xe=Math.max(o.width/Ee,o.height/be);i.useEffect(()=>{var e;if(!o._cropModeEnabled){return}const t=null===(e=D.current)||void 0===e?void 0:e.getStage();function r(e){o._cropModeEnabled&&e.target!==z.current&&o.toggleCropMode(!1)}function i(e){o._cropModeEnabled&&e.target.parentNode!==(null==t?void 0:t.content)&&o.toggleCropMode(!1)}return document.body.addEventListener("click",i),null==t||t.on("click",r),null==t||t.on("tap",r),()=>{document.body.removeEventListener("click",i),document.body.removeEventListener("touchstart",i),null==t||t.off("click",r),null==t||t.off("click",r)}},[o._cropModeEnabled]);const Ye=i.useRef(null),He=i.useRef(null),We=i.useRef(null);i.useLayoutEffect(()=>{o._cropModeEnabled&&(He.current.nodes([Ye.current]),We.current.nodes([z.current]))},[o._cropModeEnabled]);const je=e=>{Math.round(e.target.x())>0&&(e.target.x(0),e.target.scaleX(1)),Math.round(e.target.y())>0&&(e.target.y(0),e.target.scaleY(1));const t=e.target.width()*e.target.scaleX(),r=e.target.height()*e.target.scaleY(),i=Math.min(1,Ee/t),n=Math.min(1,be/r),a=1-i,d=Math.min(a,Math.max(0,Math.round(-e.target.x())/t)),s=1-n,l=Math.min(s,Math.max(0,Math.round(-e.target.y())/r));e.target.setAttrs({x:-d*we,y:-l*Me,scaleX:1,scaleY:1}),o.set({cropX:d,cropY:l,cropWidth:i,cropHeight:n})},Pe=()=>{"svg"!==o.type&&o.contentEditable&&setTimeout(()=>{n(o)&&o.toggleCropMode(!0)})},Oe="loading"===re,_e="failed"===re,Ae=!Oe&&!_e,Ve=i.useRef({cropX:0,cropY:0,cropWidth:0,cropHeight:0}),De=i.useRef(!1),ze=Ae?o.a.opacity:0;W(D,ze);const Ue=o.selectable||d.role===g.ADMIN,Be=j();return e(r,{children:t(s,{onMouseEnter:()=>oe(!0),onMouseLeave:()=>oe(!1),children:[Oe&&e($,{element:o}),_e&&e(q,{element:o}),e(l,{ref:D,name:"element",id:o.id,image:Se,x:o.a.x,y:o.a.y,width:o.a.width||1,height:o.a.height||1,rotation:o.a.rotation,opacity:ze,shadowEnabled:o.shadowEnabled,shadowBlur:o.shadowBlur,shadowOffsetX:o.shadowOffsetX,shadowOffsetY:o.shadowOffsetY,shadowColor:o.shadowColor,shadowOpacity:o.shadowOpacity,customCrop:ye,listening:Ue,draggable:Be?o.draggable&&K:o.draggable,preventDefault:!Be||K,hideInExport:!o.showInExport,onDragMove:e=>{o.set({x:e.target.x(),y:e.target.y()})},onDragEnd:e=>{o.set(S(e.target))},onDblClick:Pe,onDblTap:Pe,onTransformStart:e=>{b(!0),De.current=k(T(e.target)),Ve.current={cropX:o.cropX,cropY:o.cropY,cropWidth:o.cropWidth,cropHeight:o.cropHeight}},onTransform:e=>{const t=e.currentTarget,r=Math.abs(t.scaleX()-1)<1e-7?1:t.scaleX(),i=Math.abs(t.scaleY()-1)<1e-7?1:t.scaleY();t.scaleX(1),t.scaleY(1);const n=1-Ee/we,a=Math.min(n,Math.max(0,o.cropX)),d=1-be/Me,s=Math.min(d,Math.max(0,o.cropY)),l=De.current,c=!l&&r<1&&Ve.current.cropHeight>be/Me;let h=l?o.cropWidth:o.cropWidth*r;c&&(h=o.cropWidth);const u=!l&&i<1&&Ve.current.cropWidth>Ee/we;let g=l?o.cropHeight:o.cropHeight*i;u&&(g=o.cropHeight),Le&&(h=o.cropWidth,g=o.cropHeight);const m=l?Math.min(r,i):1;o.set(Object.assign({cropX:a,cropY:s,x:t.x(),y:t.y(),width:t.width()*r,height:t.height()*i,rotation:e.target.rotation(),cropWidth:Math.min(h,1-a),cropHeight:Math.min(g,1-s)},1!==m&&Object.assign(Object.assign({},I(o,m)),{borderSize:o.borderSize*m})))},onTransformEnd:e=>{const t=e.currentTarget;o.set(Object.assign(Object.assign({width:R(t.width()),height:R(t.height()),x:R(t.x()),y:R(t.y()),rotation:R(e.target.rotation()),cropX:C(o.cropX),cropY:C(o.cropY),cropWidth:C(Ee/we),cropHeight:C(be/Me)},X(o)),{borderSize:L(o.borderSize)})),b(!1)}}),e(c,{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:ze,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,Te-o.borderSize),hideInExport:!o.showInExport}),!d.isPlaying&&e(l,{image:Q?ie||Be?N:void 0:F,x:o.a.x,y:o.a.y,offsetX:-o.a.width/2+15/d.scale,offsetY:-o.a.height/2+15/d.scale,rotation:o.a.rotation,width:30/d.scale,height:30/d.scale,hideInExport:!0,onClick:()=>ee(!Q),onTap:()=>ee(!Q)}),o._cropModeEnabled&&t(f,{selector:".page-abs-container",enabled:!0,children:[e(c,{x:-window.innerWidth/d.scale,y:-window.innerWidth/d.scale,width:window.innerWidth/d.scale*3,height:window.innerWidth/d.scale*3,fill:"rgba(0,0,0,0.3)"}),e(l,{listening:!1,image:Se,x:o.a.x,y:o.a.y,width:o.a.width,height:o.a.height,rotation:o.a.rotation,shadowEnabled:o.shadowEnabled,shadowBlur:o.shadowBlur}),t(s,{x:o.a.x,y:o.a.y,rotation:o.a.rotation,scaleX:Xe,scaleY:Xe,children:[e(l,{image:ce,ref:z,width:we,height:Me,opacity:.4,draggable:!0,x:-o.cropX*we,y:-o.cropY*Me,onDragMove:je,onTransform:je}),e(u,{ref:We,anchorSize:20,enabledAnchors:["top-left","top-right","bottom-left","bottom-right"],boundBoxFunc:(e,t)=>t.width<5||t.height<5?e:t,rotateEnabled:!1,borderEnabled:!1,anchorCornerRadius:10,anchorStrokeWidth:2,borderStrokeWidth:2}),e(c,{width:Ee,height:be,ref:Ye,listening:!1,onTransform:e=>{e.target.x()<-o.cropX*we-1e-9&&(e.target.x(-o.cropX*we),e.target.scaleX(1)),e.target.y()<-o.cropY*Me-1e-9&&(e.target.y(-o.cropY*Me),e.target.scaleY(1));const t=Math.min(1,Math.max(0,o.cropX+e.target.x()/we)),r=Math.min(1,Math.max(0,e.target.y()/Me+o.cropY)),i=e.target.width()*e.target.scaleX(),n=e.target.height()*e.target.scaleY(),a=Math.min(1-t,i/we),d=Math.min(1-r,n/Me),s=e.target.getAbsolutePosition(e.target.getParent().getParent());e.target.scale({x:1,y:1}),e.target.position({x:0,y:0}),o.set({x:s.x,y:s.y,cropX:t,cropY:r,cropWidth:a,cropHeight:d,width:Math.min(i*Xe,we*(1-t)*Xe),height:Math.min(n*Xe,Me*(1-r)*Xe)})}}),e(u,{ref:He,enabledAnchors:["top-left","top-right","bottom-left","bottom-right"],boundBoxFunc:(e,t)=>t.width<5||t.height<5?e:t,keepRatio:!1,rotateEnabled:!1,anchorFill:"rgb(240, 240, 240)",anchorStrokeWidth:2,borderStrokeWidth:2,visible:o.resizable})]})]})]})})});
|
|
1
|
+
import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import i from"react";import{observer as o}from"mobx-react-lite";import{isAlive as n}from"mobx-state-tree";import{nodeAutorun as a}from"../utils/mobx.js";import{Arc as d,Group as s,Image as l,Rect as c,Text as h}from"react-konva";import{ROLES as u}from"../model/store.js";import{useCanvasImage as m}from"./image-element.js";import{DEFAULT_RETRIES as g,isDeterministicUrl as p,retryDelayMs as f}from"@polotno/core/retry";import v from"konva";import{useWorkspaceStyle as w}from"./workspace-style.js";import{incrementLoader as x,triggerLoadError as y}from"../utils/loader.js";import{polotnoError as E}from"@polotno/core/errors";import{getCropRect as M}from"@polotno/core/image";import*as L from"@polotno/core/svg";import{roundEnabledPx as T,activeAnchorOf as b,roundedCropFraction as C,roundedGeometryPx as I,roundedPosition as R,isCornerAnchor as H,scaledBoxStyleAttrs as S,roundedBoxStyleAttrs as j}from"../utils/px.js";import{useFilteredSource as k}from"./use-filtered-source.js";import{useEvent as O}from"../hooks/use-event.js";import{useFadeIn as P}from"./use-fadein.js";import{isTouchDevice as A}from"../utils/screen.js";import{createPlayGate as W,playMedia as X}from"../utils/media.js";import{useMediabunnyVideo as Y}from"./use-mediabunny-video.js";import{getElementTimeRange as V,getVideoRestMs as _}from"../utils/timeline.js";import{drawReduced as D,exportKernelEnabled as z,shouldResample as U}from"./downscale.js";import{useSizeFixer as N}from"./image-element.js";import{CropOverlay as Z,CROP_CORNER_ANCHORS as B}from"./crop-overlay.js";function F(){return document.createElement("canvas")}const $=new window.Image;$.src=L.svgToURL('\n <svg width="800px" height="800px" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">\n <path opacity="0.6" d="M4 5.49683V18.5032C4 20.05 5.68077 21.0113 7.01404 20.227L18.0694 13.7239C19.384 12.9506 19.384 11.0494 18.0694 10.2761L7.01404 3.77296C5.68077 2.98869 4 3.95 4 5.49683Z" fill="white"/>\n <path d="M4 5.49683V18.5032C4 20.05 5.68077 21.0113 7.01404 20.227L18.0694 13.7239C19.384 12.9506 19.384 11.0494 18.0694 10.2761L7.01404 3.77296C5.68077 2.98869 4 3.95 4 5.49683Z" stroke="#323232" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>\n </svg>\n');const q=new window.Image;q.src=L.svgToURL('\n <svg width="800px" height="800px" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">\n <path opacity="0.6" d="M14 19L14 5C14 3.89543 14.8954 3 16 3L17 3C18.1046 3 19 3.89543 19 5L19 19C19 20.1046 18.1046 21 17 21L16 21C14.8954 21 14 20.1046 14 19Z" fill="white"/>\n <path opacity="0.6" d="M10 19L10 5C10 3.89543 9.10457 3 8 3L7 3C5.89543 3 5 3.89543 5 5L5 19C5 20.1046 5.89543 21 7 21L8 21C9.10457 21 10 20.1046 10 19Z" fill="white"/>\n <path d="M14 19L14 5C14 3.89543 14.8954 3 16 3L17 3C18.1046 3 19 3.89543 19 5L19 19C19 20.1046 18.1046 21 17 21L16 21C14.8954 21 14 20.1046 14 19Z" stroke="#323232" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>\n <path d="M10 19L10 5C10 3.89543 9.10457 3 8 3L7 3C5.89543 3 5 3.89543 5 5L5 19C5 20.1046 5.89543 21 7 21L8 21C9.10457 21 10 20.1046 10 19Z" stroke="#323232" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>\n </svg>\n');export const useCornerRadiusAndCrop=(e,t,r,o,n=0,a=!1)=>{var d;const s=Math.floor(Math.max(e.width*o,1)),l=Math.floor(Math.max(e.height*o,1)),c=Math.min(n*o,s/2,l/2),h=Math.max(e.width/r.width,e.height/r.height)*o,u=z(e.page)&&!a&&U(h,s,l),m=t instanceof HTMLVideoElement?t.videoWidth:null==t?void 0:t.width,g=t instanceof HTMLVideoElement?t.videoHeight:null==t?void 0:t.height,p=0===r.x&&0===r.y&&r.width===m&&r.height===g,f=i.useMemo(()=>{if(t&&m&&g){return p&&0===c&&!u?void 0:F()}},[t,c,u,p,m,g]),w=()=>{if(!f||!t){return}f.width=s,f.height=l;const e=f.getContext("2d");e&&(c&&(e.beginPath(),e.moveTo(c,0),e.lineTo(s-c,0),e.arc(s-c,c,c,3*Math.PI/2,0,!1),e.lineTo(s,l-c),e.arc(s-c,l-c,c,0,Math.PI/2,!1),e.lineTo(c,l),e.arc(c,l-c,c,Math.PI/2,Math.PI,!1),e.lineTo(0,c),e.arc(c,c,c,Math.PI,3*Math.PI/2,!1),e.clip()),u?D(e,t,r,f.width,f.height):e.drawImage(t,r.x,r.y,r.width,r.height,0,0,f.width,f.height))};return i.useLayoutEffect(()=>{w()},[f,e.width,e.height,r.x,r.y,r.width,r.height,n,o,a,null===(d=e.page)||void 0===d?void 0:d._exportingOrRendering,u]),i.useEffect(()=>()=>{f&&"CANVAS"===f.nodeName&&v.Util.releaseCanvas(f)},[f]),[f||t,w]};const G=F(),J=o(({element:r})=>{const o=Math.min(30,r.width/4,r.height/4),n=i.useRef(null);i.useEffect(()=>{const e=n.current;if(!e){return}const t=new v.Animation(t=>{e.rotate(((null==t?void 0:t.timeDiff)||0)/2)},e.getLayer());return t.start(),()=>{t.stop()}});const{mediaLoadingStyle:a}=w();return t(s,{x:r.a.x,y:r.a.y,rotation:r.a.rotation,listening:!1,opacity:r.a.opacity,hideInExport:!r.showInExport,children:[e(c,{width:r.width,height:r.height,fill:a.fill}),e(d,{ref:n,x:r.width/2,y:r.height/2,fill:a.textFill,outerRadius:Math.abs(o),innerRadius:Math.max(1,o-5),angle:270})]})}),K=o(({element:r})=>{const{mediaErrorStyle:i}=w(),o=Math.max(10,Math.min(30,r.width/25));return t(s,{x:r.a.x,y:r.a.y,rotation:r.a.rotation,listening:!1,opacity:r.a.opacity,hideInExport:!r.showInExport,children:[e(c,{width:r.width,height:r.height,fill:i.fill}),e(h,{text:"Can not load the video...",fontSize:o,width:r.width,height:r.height,align:"center",fill:i.textFill,verticalAlign:"middle",padding:5})]})});let Q=function(e,t,r){const o=i.useRef("loading"),n=i.useRef(void 0),[a,d]=i.useState(0),s=i.useRef(void 0),l=i.useRef(void 0),c=i.useRef(void 0);return s.current===e&&l.current===t&&c.current===r||(o.current="loading",n.current=void 0,s.current=e,l.current=t,c.current=r),i.useLayoutEffect(()=>{if(!e){return}const i=p(e)?1:g;let a,s,l,c=0,h=!1,u=!1;const m=e=>{e&&(e.removeAttribute("src"),e.load())},v=()=>{c+=1;const g=document.createElement("video");function p(){h||(g.removeEventListener("canplay",p),u=!0,o.current="loaded",n.current=g,g.currentTime=0,d(Math.random()))}function w(e){var t;const r=4===g.readyState,l=g.buffered&&g.buffered.length>0&&g.buffered.end(g.buffered.length-1)/g.duration*100>=100;if(r&&l){return}if(h){return}if(!u&&c<i){return null==s||s(),m(g),void(a=setTimeout(v,f(c)))}const p=e.message||(null===(t=g.error)||void 0===t?void 0:t.message)||"Unknown error";console.error(new Error("Video failed to load: "+p)),o.current="failed",n.current=void 0,d(Math.random())}l=g,g.addEventListener("canplay",p),g.addEventListener("error",w),s=()=>{g.removeEventListener("canplay",p),g.removeEventListener("error",w)},t&&(g.crossOrigin=t),r&&(g.referrerPolicy=r),g.src=e,g.load()};return v(),()=>{h=!0,clearTimeout(a),null==s||s(),u||m(l)}},[e,t,r]),[n.current,o.current]};export const setVideoLoaderHook=e=>{Q=e};function ee(e){return e.readyState>=HTMLMediaElement.HAVE_CURRENT_DATA}export const useLoader=(e,t,r)=>{const o=i.useRef(void 0),n=()=>{var e;null===(e=o.current)||void 0===e||e.call(o),o.current=void 0};i.useEffect(()=>n,[]),i.useLayoutEffect(()=>{const i=t.slice(0,200),a=`video with id ${r} url: ${i}`;"loading"!==e||o.current||(o.current=x(a)),"loading"!==e&&n(),"failed"===e&&y(E("VIDEO_FAILED",a,{src:i,elementId:r,reason:"load"}))},[e])};export const VideoElement=o(({element:o,store:d})=>{var h,g,p;const[f,w]=i.useState(!1),y=i.useRef(null),E=o.isSelected,[D,z]=i.useState(!1),[U,te]=Q(o.src,"anonymous"),[re,ie]=i.useState(!1),oe=d.activePage===o.page,ne=(null===(h=o.page)||void 0===h?void 0:h._exportingOrRendering)&&"loaded"===te,ae=Y(o,d,ne);useLoader(te,o.src,o.id),U&&(U.playsInline=!0);const de=((e,t,r)=>{const o=i.useMemo(()=>{var i,o;const{flipX:n,flipY:a}=e,d="svg"===e.type||L.isSvgUrl(e.src),s=navigator.userAgent.toLowerCase().indexOf("firefox")>-1;if(!(n||a||s&&d)){return t}if(!t){return null}const l=t instanceof HTMLVideoElement?t.videoWidth:null==t?void 0:t.width,c=t instanceof HTMLVideoElement?t.videoHeight:null==t?void 0:t.height;if(!l||!c){return null}const h=F();let u=1;"svg"===e.type&&(u=Math.max(e.width/l*r,e.height/c*r)),h.width=Math.max(l*u,1),h.height=Math.max(c*u,1);let m=n?-h.width:0,g=a?-h.height:0;return null===(i=h.getContext("2d"))||void 0===i||i.scale(n?-1:1,a?-1:1),null===(o=h.getContext("2d"))||void 0===o||o.drawImage(t,m,g,h.width,h.height),h},[e.flipX,e.flipY,t,e.width,e.height,r]);return i.useEffect(()=>()=>{o&&"CANVAS"===o.nodeName&&v.Util.releaseCanvas(o)},[o]),o})(o,U,d._elementsPixelRatio),se=ne&&ae||de||G,[le=G,ce]=k(o,se);i.useEffect(()=>{U&&d.history.ignore(()=>{o.set({duration:1e3*U.duration})})},[U]);const he=i.useMemo(W,[U]);i.useEffect(()=>{var e;if(!U){return}const t=d.animatedElementsIds,r=(!t.length||t.includes(o.id))&&d.isPlaying;if(!oe||!r&&!D){return void U.pause()}D&&(U.muted=!1,U.currentTime=o.startTime*U.duration,X(U).then(e=>{"refused"===e&&z(!1)}));const i=new v.Animation(()=>{He()},null===(e=y.current)||void 0===e?void 0:e.getLayer());i.start();const n=()=>{z(!1),U.currentTime=o.startTime*U.duration},a=()=>{U.currentTime>=o.endTime*U.duration&&(U.pause(),U.currentTime=o.startTime*U.duration,z(!1))};return U.addEventListener("ended",n),U.addEventListener("timeupdate",a),()=>{U.pause(),i.stop(),U.removeEventListener("ended",n),U.removeEventListener("timeupdate",a)}},[U,D,d.isPlaying,oe]),i.useEffect(()=>{U&&(U.volume=o.volume)},[U,o.volume]),i.useEffect(()=>{U&&(U.playbackRate=o.speed,U.preservesPitch=!1)},[U,o.speed]);const ue=i.useRef(null);i.useEffect(()=>{const e=a(o,()=>{var e,t;if(U){if(ne&&ae){return He(),void d.currentTime}const r=d.animatedElementsIds;if(r.length&&!r.includes(o.id)){return}const i=d.activePage===o.page,n=d.currentTime>=o.page.startTime&&d.currentTime<o.page.startTime+o.page.duration,a=o.startTime*U.duration*1e3,s=U.duration*(o.endTime-o.startTime)*1e3,{start:l,end:c}=V(o.animations,o.page.duration),h=(d.currentTime||o.page.startTime)-o.page.startTime,u=n?_(d.currentTime,o.page.startTime,l,s,a,o.speed):0,m=u/1e3,g=n&&h>=l&&h<c;D||(U.muted=!g,g&&d.isPlaying&&i?U.paused?(U.currentTime=m,he.play(U)):Math.abs(1e3*U.currentTime-u)>500&&(U.currentTime=m):(he.reset(),U.paused||U.pause(),m!==U.currentTime&&(U.currentTime=m),!ee(U)&&!d.isPlaying&&!ue.current&&(ue.current=x(`video ${o.id}`)))),He(),null===(t=null===(e=y.current)||void 0===e?void 0:e.getLayer())||void 0===t||t.batchDraw()}});return()=>{e(),ue.current&&(ue.current(),ue.current=null)}},[d,U,ne,ae,D]),i.useEffect(()=>{var e,t;if(!U){return}if(ne){return null===(e=ue.current)||void 0===e||e.call(ue),void(ue.current=null)}const r=()=>{var e,t,r;!ee(U)&&(null===(e=o.page)||void 0===e?void 0:e._exportingOrRendering)||ue.current&&(He(),null===(r=null===(t=y.current)||void 0===t?void 0:t.getLayer())||void 0===r||r.batchDraw(),ue.current(),ue.current=null)};let i;return(null===(t=o.page)||void 0===t?void 0:t._exportingOrRendering)&&(i=setInterval(r,20)),U.addEventListener("timeupdate",r),U.addEventListener("canplay",r),()=>{clearInterval(i),U.removeEventListener("timeupdate",r),U.removeEventListener("canplay",r)}},[null===(g=o.page)||void 0===g?void 0:g._exportingOrRendering,U,o.id,x,ne]);let{cropX:me,cropY:ge,cropWidth:pe,cropHeight:fe}=o;"loaded"!==te&&(me=ge=0,pe=fe=1);const ve=(we=le)instanceof HTMLVideoElement?we.videoWidth:(null==we?void 0:we.width)||0;var we;const xe=(e=>e instanceof HTMLVideoElement?e.videoHeight:(null==e?void 0:e.height)||0)(le),ye=M({stretchEnabled:o.stretchEnabled,cropX:me,cropY:ge,cropWidth:pe,cropHeight:fe,width:o.a.width,height:o.a.height},{width:ve,height:xe}),Ee=ye.width,Me=ye.height,Le=o.stretchEnabled,Te=null!==(p=o.cornerRadius)&&void 0!==p?p:0,[be,Ce]=useCornerRadiusAndCrop(o,le,ye,d._elementsPixelRatio,Te,!0);let[Ie,Re]=((e,t,r,o)=>{const n=N(e.clipSrc||""),[a,d]=m(n,"anonymous"),s=e.clipSrc?d:"loaded";useLoader(s,e.clipSrc,e.id);const l=i.useMemo(()=>{if(t&&a){return F()}},[t,a]);function c(){var i;if(!a){return}const o=t instanceof HTMLVideoElement?t.videoWidth:null==t?void 0:t.width,n=t instanceof HTMLVideoElement?t.videoHeight:null==t?void 0:t.height;if(!t||!o||!n){return}if(!a||!a.width||!a.height){return}if(!l){return}const d=F(),s=Math.max(e.width/a.width*r,e.height/a.height*r);d.width=a.width*s,d.height=a.height*s,null===(i=d.getContext("2d"))||void 0===i||i.drawImage(a,0,0,d.width,d.height),l.width=Math.max(o,1),l.height=Math.max(n,1);const c=l.getContext("2d");c&&(c.save(),c.drawImage(d,0,0,o,n),v.Util.releaseCanvas(d),c.globalCompositeOperation="source-in",c.drawImage(t,0,0,l.width,l.height),c.restore())}return i.useLayoutEffect(()=>{c()},[l,t,a,e.width,e.height,r,...o]),[e.clipSrc&&a?l:t,c]})(o,be,d._elementsPixelRatio,[ye,Te,d._elementsPixelRatio]);const He=O(()=>{var e,t;ce(),Ce(),Re(),null===(t=null===(e=y.current)||void 0===e?void 0:e.getLayer())||void 0===t||t.batchDraw()});i.useEffect(()=>{He()});const Se=()=>{o._cropEnabled&&setTimeout(()=>{n(o)&&o.toggleCropMode(!0)})},je="loading"===te,ke="failed"===te,Oe=!je&&!ke,Pe=i.useRef({cropX:0,cropY:0,cropWidth:0,cropHeight:0}),Ae=i.useRef(!1),We=Oe?o.a.opacity:0;P(y,We);const Xe=o.selectable||d.role===u.ADMIN,Ye=A();return e(r,{children:t(s,{onMouseEnter:()=>ie(!0),onMouseLeave:()=>ie(!1),children:[je&&e(J,{element:o}),ke&&e(K,{element:o}),e(l,{ref:y,name:"element",id:o.id,image:Ie,x:o.a.x,y:o.a.y,width:o.a.width||1,height:o.a.height||1,rotation:o.a.rotation,opacity:We,shadowEnabled:o.shadowEnabled,shadowBlur:o.shadowBlur,shadowOffsetX:o.shadowOffsetX,shadowOffsetY:o.shadowOffsetY,shadowColor:o.shadowColor,shadowOpacity:o.shadowOpacity,customCrop:ye,listening:Xe,draggable:Ye?o.draggable&&E:o.draggable,preventDefault:!Ye||E,hideInExport:!o.showInExport,onDragMove:e=>{o.set({x:e.target.x(),y:e.target.y()})},onDragEnd:e=>{o.set(R(e.target))},onDblClick:Se,onDblTap:Se,onTransformStart:e=>{w(!0),Ae.current=H(b(e.target)),Pe.current={cropX:o.cropX,cropY:o.cropY,cropWidth:o.cropWidth,cropHeight:o.cropHeight}},onTransform:e=>{const t=e.currentTarget,r=Math.abs(t.scaleX()-1)<1e-7?1:t.scaleX(),i=Math.abs(t.scaleY()-1)<1e-7?1:t.scaleY();t.scaleX(1),t.scaleY(1);const n=1-Ee/ve,a=Math.min(n,Math.max(0,o.cropX)),d=1-Me/xe,s=Math.min(d,Math.max(0,o.cropY)),l=Ae.current,c=!l&&r<1&&Pe.current.cropHeight>Me/xe;let h=l?o.cropWidth:o.cropWidth*r;c&&(h=o.cropWidth);const u=!l&&i<1&&Pe.current.cropWidth>Ee/ve;let m=l?o.cropHeight:o.cropHeight*i;u&&(m=o.cropHeight),Le&&(h=o.cropWidth,m=o.cropHeight);const g=l?Math.min(r,i):1;o.set(Object.assign({cropX:a,cropY:s,x:t.x(),y:t.y(),width:t.width()*r,height:t.height()*i,rotation:e.target.rotation(),cropWidth:Math.min(h,1-a),cropHeight:Math.min(m,1-s)},1!==g&&Object.assign(Object.assign({},S(o,g)),{borderSize:o.borderSize*g})))},onTransformEnd:e=>{const t=e.currentTarget;o.set(Object.assign(Object.assign({width:I(t.width()),height:I(t.height()),x:I(t.x()),y:I(t.y()),rotation:I(e.target.rotation()),cropX:C(o.cropX),cropY:C(o.cropY),cropWidth:C(Ee/ve),cropHeight:C(Me/xe)},j(o)),{borderSize:T(o.borderSize)})),w(!1)}}),e(c,{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:We,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,Te-o.borderSize),hideInExport:!o.showInExport}),!d.isPlaying&&e(l,{image:D?re||Ye?q:void 0:$,x:o.a.x,y:o.a.y,offsetX:-o.a.width/2+15/d.scale,offsetY:-o.a.height/2+15/d.scale,rotation:o.a.rotation,width:30/d.scale,height:30/d.scale,hideInExport:!0,onClick:()=>z(!D),onTap:()=>z(!D)}),o._cropModeEnabled&&e(Z,{element:o,store:d,previewImage:Ie,sourceImage:le,sourceWidth:ve,sourceHeight:xe,cropAbsoluteWidth:Ee,cropAbsoluteHeight:Me,innerAnchors:B})]})})});
|
|
@@ -2,6 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import { StoreType } from '../model/store.js';
|
|
3
3
|
import type { TransformerConfig } from 'konva/lib/shapes/Transformer';
|
|
4
4
|
import type { RectConfig } from 'konva/lib/shapes/Rect';
|
|
5
|
+
import type { LineConfig } from 'konva/lib/shapes/Line';
|
|
5
6
|
export type GroupSelectionMode = 'drill' | 'group';
|
|
6
7
|
export type WorkspaceProps = {
|
|
7
8
|
store: StoreType;
|
|
@@ -21,6 +22,7 @@ export type WorkspaceProps = {
|
|
|
21
22
|
transformLabelFill?: string;
|
|
22
23
|
transformLabelTextFill?: string;
|
|
23
24
|
cropOverlayFill?: string;
|
|
25
|
+
cropGridStyle?: LineConfig | null;
|
|
24
26
|
transformerStyle?: TransformerConfig;
|
|
25
27
|
innerImageCropTransformerStyle?: TransformerConfig;
|
|
26
28
|
outerImageCropTransformerStyle?: TransformerConfig;
|
|
@@ -63,7 +65,7 @@ export type WorkspaceProps = {
|
|
|
63
65
|
right?: number;
|
|
64
66
|
};
|
|
65
67
|
};
|
|
66
|
-
export declare const WorkspaceCanvas: (({ store, layout, pageControlsEnabled, backgroundColor, transparencyBackgroundColor, pageBorderColor, activePageBorderColor, bleedColor, snapGuideStroke, snapGuideStrokeWidth, snapGuideDash, selectionRectFill, selectionRectStroke, selectionRectStrokeWidth, transformLabelFill, transformLabelTextFill, cropOverlayFill, transformerStyle, innerImageCropTransformerStyle, outerImageCropTransformerStyle, highlighterStyle, mediaLoadingStyle, mediaErrorStyle, textOverflowIndicatorStyle, distanceGuideStroke, distanceLabelFill, distanceLabelTextFill, rulerBackgroundColor, rulerTextColor, rulerBorderColor, rulerBorderSize, rulerTickColor, rulerTickSize, components, onKeyDown, onPaste, paddingX, paddingY, pageGap, altCloneEnabled, groupSelectionMode, visiblePagesOffset, renderOnlyActivePage, scrollToPageThreshold, tooltipSafeArea, }: WorkspaceProps) => React.JSX.Element) & {
|
|
68
|
+
export declare const WorkspaceCanvas: (({ store, layout, pageControlsEnabled, backgroundColor, transparencyBackgroundColor, pageBorderColor, activePageBorderColor, bleedColor, snapGuideStroke, snapGuideStrokeWidth, snapGuideDash, selectionRectFill, selectionRectStroke, selectionRectStrokeWidth, transformLabelFill, transformLabelTextFill, cropOverlayFill, cropGridStyle, transformerStyle, innerImageCropTransformerStyle, outerImageCropTransformerStyle, highlighterStyle, mediaLoadingStyle, mediaErrorStyle, textOverflowIndicatorStyle, distanceGuideStroke, distanceLabelFill, distanceLabelTextFill, rulerBackgroundColor, rulerTextColor, rulerBorderColor, rulerBorderSize, rulerTickColor, rulerTickSize, components, onKeyDown, onPaste, paddingX, paddingY, pageGap, altCloneEnabled, groupSelectionMode, visiblePagesOffset, renderOnlyActivePage, scrollToPageThreshold, tooltipSafeArea, }: WorkspaceProps) => React.JSX.Element) & {
|
|
67
69
|
displayName: string;
|
|
68
70
|
};
|
|
69
71
|
export default WorkspaceCanvas;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as e,jsxs as t}from"react/jsx-runtime";import r from"react";import{observer as o}from"mobx-react-lite";import n from"./page.js";import{TopRules as l}from"./rules.js";import{AudioElement as i}from"./audio.js";import{handleHotkey as s,handleCopyEvent as a,handleCutEvent as c,handlePasteEvent as u}from"./hotkeys.js";import{t as d}from"../utils/l10n.js";import{WorkspaceStyleProvider as h,useResolvedWorkspaceStyle as g}from"./workspace-style.js";const p=(e,t,r)=>Math.max(t,Math.min(r,e)),f=(e,t)=>Math.sqrt(Math.pow(t.clientX-e.clientX,2)+Math.pow(t.clientY-e.clientY,2)),m=({store:r})=>t("div",{style:{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",textAlign:"center"},children:[e("p",{children:d("workspace.noPages")}),e("button",{onClick:()=>{r.addPage()},children:d("workspace.addPage")})]}),v=({width:t,height:r,xPadding:o,yPadding:n,backgroundColor:l})=>e("div",{style:{width:t+"px",height:r+"px",backgroundColor:l,paddingLeft:o+"px",paddingRight:o+"px",paddingTop:n+"px",paddingBottom:n+"px",flexShrink:0},children:e("div",{style:{width:" 100%",height:"100%",backgroundColor:"white"}})});export const WorkspaceCanvas=o(({store:o,layout:d="vertical",pageControlsEnabled:w,backgroundColor:x,transparencyBackgroundColor:y,pageBorderColor:L,activePageBorderColor:T,bleedColor:b,snapGuideStroke:k,snapGuideStrokeWidth:S,snapGuideDash:E,selectionRectFill:M,selectionRectStroke:C,selectionRectStrokeWidth:P,transformLabelFill:R,transformLabelTextFill:F,cropOverlayFill:W,transformerStyle:B,innerImageCropTransformerStyle:O,outerImageCropTransformerStyle:z,highlighterStyle:j,mediaLoadingStyle:N,mediaErrorStyle:H,textOverflowIndicatorStyle:G,distanceGuideStroke:I,distanceLabelFill:_,distanceLabelTextFill:Y,rulerBackgroundColor:D,rulerTextColor:X,rulerBorderColor:A,rulerBorderSize:K,rulerTickColor:q,rulerTickSize:V,components:J,onKeyDown:Q,onPaste:U,paddingX:Z,paddingY:$,pageGap:ee,altCloneEnabled:te=!0,groupSelectionMode:re="drill",visiblePagesOffset:oe,renderOnlyActivePage:ne,scrollToPageThreshold:le=.5,tooltipSafeArea:ie})=>{var se;const ae="horizontal"===d,ce=null!=Z?Z:20,ue=null!=$?$:55,[de,he]=r.useState({width:100,height:100}),ge=r.useRef(de),pe=r.useRef(null),fe=r.useRef(null),me=r.useRef(0);let ve=0,we=0,xe=0,ye=0;if(o.bleedVisible){for(const e of o.pages){const t=e.computedBleed;ve=Math.max(ve,t.left),we=Math.max(we,t.right),xe=Math.max(xe,t.top),ye=Math.max(ye,t.bottom)}}const Le=Math.max(...o.pages.map(e=>e.computedWidth)),Te=Math.max(...o.pages.map(e=>e.computedHeight)),be=(null===(se=o.activePage)||void 0===se?void 0:se.computedHeight)||0,ke=Le+ve+we,Se=(ne?be:Te)+xe+ye,Ee=async({skipTimeout:e}={skipTimeout:!1})=>{if(e||await new Promise(e=>setTimeout(e,50)),null===pe.current){return}if(!Number.isFinite(ke)||!Number.isFinite(Se)){return}const t=pe.current.getBoundingClientRect();0!==t.width&&0!==t.height||(console.warn("Polotno warning: <Workspace /> component can not automatically detect its size.\nWidth or height of parent elements is equal 0.\nPlease make sure it has non-zero size. You may need to adjust it with your styles. <Workspace /> will automatically fit into parent container.\nFor simpler debugging here is the log of the parent element:"),console.log(pe.current));const r=fe.current.clientWidth||t.width,n={width:r,height:t.height};(ge.current.width!==n.width||ge.current.height!==n.height)&&(he(n),ge.current=n);const l=(r-2*ce)/ke,i=o.pages.length>1?3.1:2,s=(t.height-ue*i)/Se,a=o.pages.length>1?3.1:2,c=(r-ce*a)/ke,u=(t.height-2*ue)/Se,d=o.pages.length?Math.max(Math.min(ae?c:l,ae?u:s),.01):1;o.scaleToFit!==d&&(o.setScale(d),o._setScaleToFit(d))};r.useLayoutEffect(()=>{Ee({skipTimeout:!0})},[]),r.useEffect(()=>{Ee()},[ke,Se,$,Z]),r.useLayoutEffect(()=>{Ee({skipTimeout:!0})},[o.openedSidePanel]),r.useEffect(()=>{o.__()},[]),r.useEffect(()=>{const e=pe.current;if(window.ResizeObserver){const t=new ResizeObserver(()=>{Ee({skipTimeout:!0})});return t.observe(e),()=>t.unobserve(e)}{const e=setInterval(()=>{Ee({skipTimeout:!0})},100);return()=>clearInterval(e)}},[ke,Se]);const Me=ne?1:o.pages.length;let Ce,Pe;if(ae){const e=ke*o.scale*Me;Ce=Math.max(ce,(de.width-e)/Me/2),Pe=Math.max(ue,(de.height-Se*o.scale)/2)}else{Ce=Math.max(ce,(de.width-ke*o.scale)/2);const e=Se*o.scale*Me;Pe=Math.max(ue,(de.height-e)/Me/2)}Number.isNaN(Ce)&&(Ce=ce),Number.isNaN(Pe)&&(Pe=ue),r.useEffect(()=>{const e=e=>{(Q||s)(e,o)};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[]),r.useEffect(()=>{const e=e=>a(e,o),t=e=>c(e,o),r=e=>(U||u)(e,o);return window.addEventListener("copy",e),window.addEventListener("cut",t),window.addEventListener("paste",r),()=>{window.removeEventListener("copy",e),window.removeEventListener("cut",t),window.removeEventListener("paste",r)}},[U]),r.useEffect(()=>{const e=e=>{if(e.ctrlKey||e.metaKey){e.preventDefault();const t=Math.max(5,o.scaleToFit);let r=Math.min(.1,o.scaleToFit);ae&&ke>0&&Number.isFinite(ke)&&(r=Math.max(r,300/ke)),r=Math.max(r,.01);const n=.03,l=p(e.deltaY<0?o.scale*(1+n):o.scale/(1+n),r,t);return void o.setScale(l)}},t=fe.current;return null==t||t.addEventListener("wheel",e),()=>null==t?void 0:t.removeEventListener("wheel",e)},[ae,ke,o]),r.useEffect(()=>{const e=fe.current;if(!e){return}const t=e=>{2===e.touches.length&&(me.current=f(e.touches[0],e.touches[1]))},r=t=>{if(2===t.touches.length&&me.current>0){t.preventDefault();const r=f(t.touches[0],t.touches[1]),n=r/me.current,l=Math.max(5,o.scaleToFit);let i=Math.min(.1,o.scaleToFit);ae&&ke>0&&Number.isFinite(ke)&&(i=Math.max(i,300/ke)),i=Math.max(i,.01);const s=o.scale,a=p(s*n,i,l),c=a/s,u=e.getBoundingClientRect(),d=(t.touches[0].clientX+t.touches[1].clientX)/2-u.left,h=(t.touches[0].clientY+t.touches[1].clientY)/2-u.top,g=e.scrollLeft+d,m=e.scrollTop+h;je.current=!0,o.setScale(a),e.scrollLeft=g*c-d,e.scrollTop=m*c-h,me.current=r}},n=()=>{me.current=0};return e.addEventListener("touchstart",t,{passive:!0}),e.addEventListener("touchmove",r,{passive:!1}),e.addEventListener("touchend",n,{passive:!0}),()=>{e.removeEventListener("touchstart",t),e.removeEventListener("touchmove",r),e.removeEventListener("touchend",n)}},[ae,ke,o]);const Re=void 0!==ee,Fe=o.pages.map(e=>{if(ae){const t=(e.computedWidth+ve+we)*o.scale;return Re?t+ee:t+2*Ce}{const t=(e.computedHeight+xe+ye)*o.scale;return Re?t+ee:t+2*Pe}}),We=[];let Be=Re?ae?Ce:Pe:0;for(let e=0;e<Fe.length;e++){We.push(Be),Be+=Fe[e]}const Oe=Fe.reduce((e,t)=>e+t,0),ze=Re?Oe+(ae?2*Ce:2*Pe):Oe,je=r.useRef(!1),[,Ne]=r.useReducer(e=>e+1,0);((e,t,o,n,l)=>{const i=r.useRef(0),s=r.useRef(0),a=r.useRef(null),c=r.useRef(null),u=r.useRef(!1),d=r.useRef(n.pages.length);u.current=d.current!==n.pages.length,d.current=n.pages.length,r.useEffect(()=>{const t=e.current,r=()=>{i.current=t.scrollLeft,s.current=t.scrollTop,a.current=t.scrollWidth,c.current=t.scrollHeight};return t.addEventListener("scroll",r),r(),()=>{t.removeEventListener("scroll",r)}},[]),r.useLayoutEffect(()=>{if(!e.current){return}if(u.current){const t=e.current;return a.current=t.scrollWidth,c.current=t.scrollHeight,i.current=t.scrollLeft,void(s.current=t.scrollTop)}const t=e.current,r=a.current,o=c.current;if(null===r||null===o){return a.current=t.scrollWidth,c.current=t.scrollHeight,i.current=t.scrollLeft,void(s.current=t.scrollTop)}l.current=!0;const n=t.offsetWidth,d=t.offsetHeight,h=(i.current+n/2)/r,g=(s.current+d/2)/o,f=Math.max(0,t.scrollWidth-n),m=Math.max(0,t.scrollHeight-d);t.scrollLeft=p(h*t.scrollWidth-n/2,0,f),t.scrollTop=p(g*t.scrollHeight-d/2,0,m),a.current=t.scrollWidth,c.current=t.scrollHeight,i.current=t.scrollLeft,s.current=t.scrollTop},[o,t])})(fe,ze,o.scale,o,je);const{handleScroll:He}=((e,t,o,n,l,i,s,a,c,u)=>{const d=r.useRef(!1),h=r.useRef(null),g=r.useRef(!1),p="horizontal"===c;r.useEffect(()=>{const t=e.current,r=()=>{s.current};return t.addEventListener("scroll",r),()=>{t.removeEventListener("scroll",r)}},[]);const f=n.pages.indexOf(n.activePage);return r.useLayoutEffect(()=>{if(a){return}if(!n.activePage){return}if(!e.current){return}if(d.current){return}const r=e.current,i=n.pages.indexOf(n.activePage),s=t[i]||0,c=p?r.scrollLeft:r.scrollTop,h=p?r.scrollWidth-r.clientWidth:r.scrollHeight-r.clientHeight,f=Math.min(s,Math.max(0,h)),m=o[i]||o[0]||0;let v=()=>{};return(Math.abs(f-c)>m*l||g.current)&&(g.current=!0,v=(({element:e,scrollTop:t,scrollLeft:r,duration:o=300,onFinish:n=()=>{}})=>{const l=void 0!==t,i=l?e.scrollTop:e.scrollLeft,s=l?t:r,a=s-i;let c=0,u=!1;if(0===o){return l?e.scrollTop=s:e.scrollLeft=s,()=>{}}const d=()=>{if(u){return}c+=20;const t=h(c,i,a,o);l?e.scrollTop=t:e.scrollLeft=t,c<o?setTimeout(d,20):n()},h=(e,t,r,o)=>(e/=o/2)<1?r/2*e*e+t:-r/2*(--e*(e-2)-1)+t;return d(),()=>{u=!0}})(Object.assign(Object.assign({element:r},p?{scrollLeft:f}:{scrollTop:f}),{onFinish:()=>{g.current=!1,null==u||u()},duration:n.isPlaying?0:300}))),v},[n.activePage,f,n.isPlaying,a,c,t,o]),{handleScroll:e=>{if(a){return}if(g.current){return}d.current=!0,clearTimeout(h.current),h.current=setTimeout(()=>{d.current=!1},300);const r=(p?e.currentTarget.scrollLeft:e.currentTarget.scrollTop)+(p?i.width:i.height)/3;let o=0;for(let n=t.length-1;n>=0;n--){if(r>=t[n]){o=n;break}}const l=n.pages[o];l&&n.activePage!==l&&l.select()}}})(fe,We,Fe,o,le,de,je,ne,d,Ne),Ge=de.width>=ke*o.scale+2*Ce,Ie=de.height>=Se*o.scale+2*Pe,_e=x||"rgba(232, 232, 232, 0.9)",Ye=(null==J?void 0:J.NoPages)||m,De=ae?de.width:de.height,Xe=fe.current?ae?fe.current.scrollLeft:fe.current.scrollTop:0,Ae=e=>{for(let t=We.length-1;t>=0;t--){if(e>=We[t]){return t}}return 0},Ke=Math.max(0,Ae(Xe)),qe=Math.min(o.pages.length-1,Ae(Xe+De)),Ve=null!=oe?oe:1,Je=Math.max(0,Ke-Ve),Qe=Math.min(o.pages.length-1,qe+Ve),Ue=g({cropOverlayFill:W,workspaceBackgroundColor:x,pageBorderColor:L,activePageBorderColor:T,bleedColor:b,transparencyBackgroundColor:y,transformerStyle:B,innerImageCropTransformerStyle:O,outerImageCropTransformerStyle:z,highlighterStyle:j,snapGuideStroke:k,snapGuideStrokeWidth:S,snapGuideDash:E,selectionRectFill:M,selectionRectStroke:C,selectionRectStrokeWidth:P,transformLabelFill:R,transformLabelTextFill:F,distanceGuideStroke:I,distanceLabelFill:_,distanceLabelTextFill:Y,mediaLoadingStyle:N,mediaErrorStyle:H,textOverflowIndicatorStyle:G,rulerBackgroundColor:D,rulerTextColor:X,rulerBorderColor:A,rulerBorderSize:K,rulerTickColor:q,rulerTickSize:V});return e(h,{value:Ue,children:e("div",{ref:pe,style:{width:"100%",height:"100%",position:"relative",outline:"none",flex:1,backgroundColor:_e,overflow:"hidden"},tabIndex:0,className:"polotno-workspace-container",children:t("div",{ref:fe,onScroll:He,style:Object.assign({position:"absolute",top:0,left:0,width:"100%",height:"100%",display:"flex",flexDirection:ae?"row":"column",overflow:"auto",overflowX:ae?"auto":Ge?"hidden":"auto",overflowY:ae&&Ie?"hidden":"auto"},Re&&{paddingTop:ae?0:Pe,paddingBottom:ae?0:Pe,paddingLeft:ae?Ce:0,paddingRight:ae?Ce:0,boxSizing:"border-box"}),className:"polotno-workspace-inner",children:[o.pages.map((t,r)=>{const l=t===o.activePage;if(ne&&!l&&!t._exportingOrRendering&&!t._forceMount){return null}const i=l||r>=Je&&r<=Qe||t._exportingOrRendering||t._forceMount,s=ae?Fe[r]:ke*o.scale+2*Ce,a=ae?Se*o.scale+2*Pe:Fe[r];if(!i){return e("div",{style:{flexShrink:0},children:e(v,{width:s,height:a,backgroundColor:_e,xPadding:Ce,yPadding:Pe})},t.id)}const c=e(n,{page:t,xPadding:Ce,yPadding:Pe,width:s,height:a,store:o,pageControlsEnabled:w,altCloneEnabled:te,groupSelectionMode:re,components:J,viewportSize:de,layout:d,tooltipSafeArea:ie},t.id);return(t._exportingOrRendering||t._forceMount)&&!l&&ne?e("div",{style:{display:"none",flexShrink:0},children:c},t.id):c}),o.rulesVisible&&e(l,{store:o,xPadding:Ce,yPadding:Pe,width:ke*o.scale+2*Ce,height:Se*o.scale+2*Pe,pageSizes:Fe,layout:d,renderOnlyActivePage:ne}),0===o.pages.length&&e(Ye,{store:o}),o.audios.map(t=>e(i,{audio:t,store:o},t.id))]})})})});export default WorkspaceCanvas;
|
|
1
|
+
import{jsx as e,jsxs as t}from"react/jsx-runtime";import r from"react";import{observer as o}from"mobx-react-lite";import n from"./page.js";import{TopRules as l}from"./rules.js";import{AudioElement as i}from"./audio.js";import{handleHotkey as s,handleCopyEvent as a,handleCutEvent as c,handlePasteEvent as u}from"./hotkeys.js";import{t as d}from"../utils/l10n.js";import{WorkspaceStyleProvider as h,useResolvedWorkspaceStyle as g}from"./workspace-style.js";const p=(e,t,r)=>Math.max(t,Math.min(r,e)),f=(e,t)=>Math.sqrt(Math.pow(t.clientX-e.clientX,2)+Math.pow(t.clientY-e.clientY,2)),m=({store:r})=>t("div",{style:{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",textAlign:"center"},children:[e("p",{children:d("workspace.noPages")}),e("button",{onClick:()=>{r.addPage()},children:d("workspace.addPage")})]}),v=({width:t,height:r,xPadding:o,yPadding:n,backgroundColor:l})=>e("div",{style:{width:t+"px",height:r+"px",backgroundColor:l,paddingLeft:o+"px",paddingRight:o+"px",paddingTop:n+"px",paddingBottom:n+"px",flexShrink:0},children:e("div",{style:{width:" 100%",height:"100%",backgroundColor:"white"}})});export const WorkspaceCanvas=o(({store:o,layout:d="vertical",pageControlsEnabled:w,backgroundColor:x,transparencyBackgroundColor:y,pageBorderColor:L,activePageBorderColor:T,bleedColor:b,snapGuideStroke:k,snapGuideStrokeWidth:S,snapGuideDash:E,selectionRectFill:M,selectionRectStroke:C,selectionRectStrokeWidth:P,transformLabelFill:R,transformLabelTextFill:F,cropOverlayFill:W,cropGridStyle:B,transformerStyle:O,innerImageCropTransformerStyle:z,outerImageCropTransformerStyle:j,highlighterStyle:N,mediaLoadingStyle:H,mediaErrorStyle:G,textOverflowIndicatorStyle:I,distanceGuideStroke:_,distanceLabelFill:Y,distanceLabelTextFill:D,rulerBackgroundColor:X,rulerTextColor:A,rulerBorderColor:K,rulerBorderSize:q,rulerTickColor:V,rulerTickSize:J,components:Q,onKeyDown:U,onPaste:Z,paddingX:$,paddingY:ee,pageGap:te,altCloneEnabled:re=!0,groupSelectionMode:oe="drill",visiblePagesOffset:ne,renderOnlyActivePage:le,scrollToPageThreshold:ie=.5,tooltipSafeArea:se})=>{var ae;const ce="horizontal"===d,ue=null!=$?$:20,de=null!=ee?ee:55,[he,ge]=r.useState({width:100,height:100}),pe=r.useRef(he),fe=r.useRef(null),me=r.useRef(null),ve=r.useRef(0);let we=0,xe=0,ye=0,Le=0;if(o.bleedVisible){for(const e of o.pages){const t=e.computedBleed;we=Math.max(we,t.left),xe=Math.max(xe,t.right),ye=Math.max(ye,t.top),Le=Math.max(Le,t.bottom)}}const Te=Math.max(...o.pages.map(e=>e.computedWidth)),be=Math.max(...o.pages.map(e=>e.computedHeight)),ke=(null===(ae=o.activePage)||void 0===ae?void 0:ae.computedHeight)||0,Se=Te+we+xe,Ee=(le?ke:be)+ye+Le,Me=async({skipTimeout:e}={skipTimeout:!1})=>{if(e||await new Promise(e=>setTimeout(e,50)),null===fe.current){return}if(!Number.isFinite(Se)||!Number.isFinite(Ee)){return}const t=fe.current.getBoundingClientRect();0!==t.width&&0!==t.height||(console.warn("Polotno warning: <Workspace /> component can not automatically detect its size.\nWidth or height of parent elements is equal 0.\nPlease make sure it has non-zero size. You may need to adjust it with your styles. <Workspace /> will automatically fit into parent container.\nFor simpler debugging here is the log of the parent element:"),console.log(fe.current));const r=me.current.clientWidth||t.width,n={width:r,height:t.height};(pe.current.width!==n.width||pe.current.height!==n.height)&&(ge(n),pe.current=n);const l=(r-2*ue)/Se,i=o.pages.length>1?3.1:2,s=(t.height-de*i)/Ee,a=o.pages.length>1?3.1:2,c=(r-ue*a)/Se,u=(t.height-2*de)/Ee,d=o.pages.length?Math.max(Math.min(ce?c:l,ce?u:s),.01):1;o.scaleToFit!==d&&(o.setScale(d),o._setScaleToFit(d))};r.useLayoutEffect(()=>{Me({skipTimeout:!0})},[]),r.useEffect(()=>{Me()},[Se,Ee,ee,$]),r.useLayoutEffect(()=>{Me({skipTimeout:!0})},[o.openedSidePanel]),r.useEffect(()=>{o.__()},[]),r.useEffect(()=>{const e=fe.current;if(window.ResizeObserver){const t=new ResizeObserver(()=>{Me({skipTimeout:!0})});return t.observe(e),()=>t.unobserve(e)}{const e=setInterval(()=>{Me({skipTimeout:!0})},100);return()=>clearInterval(e)}},[Se,Ee]);const Ce=le?1:o.pages.length;let Pe,Re;if(ce){const e=Se*o.scale*Ce;Pe=Math.max(ue,(he.width-e)/Ce/2),Re=Math.max(de,(he.height-Ee*o.scale)/2)}else{Pe=Math.max(ue,(he.width-Se*o.scale)/2);const e=Ee*o.scale*Ce;Re=Math.max(de,(he.height-e)/Ce/2)}Number.isNaN(Pe)&&(Pe=ue),Number.isNaN(Re)&&(Re=de),r.useEffect(()=>{const e=e=>{(U||s)(e,o)};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[]),r.useEffect(()=>{const e=e=>a(e,o),t=e=>c(e,o),r=e=>(Z||u)(e,o);return window.addEventListener("copy",e),window.addEventListener("cut",t),window.addEventListener("paste",r),()=>{window.removeEventListener("copy",e),window.removeEventListener("cut",t),window.removeEventListener("paste",r)}},[Z]),r.useEffect(()=>{const e=e=>{if(e.ctrlKey||e.metaKey){e.preventDefault();const t=Math.max(5,o.scaleToFit);let r=Math.min(.1,o.scaleToFit);ce&&Se>0&&Number.isFinite(Se)&&(r=Math.max(r,300/Se)),r=Math.max(r,.01);const n=.03,l=p(e.deltaY<0?o.scale*(1+n):o.scale/(1+n),r,t);return void o.setScale(l)}},t=me.current;return null==t||t.addEventListener("wheel",e),()=>null==t?void 0:t.removeEventListener("wheel",e)},[ce,Se,o]),r.useEffect(()=>{const e=me.current;if(!e){return}const t=e=>{2===e.touches.length&&(ve.current=f(e.touches[0],e.touches[1]))},r=t=>{if(2===t.touches.length&&ve.current>0){t.preventDefault();const r=f(t.touches[0],t.touches[1]),n=r/ve.current,l=Math.max(5,o.scaleToFit);let i=Math.min(.1,o.scaleToFit);ce&&Se>0&&Number.isFinite(Se)&&(i=Math.max(i,300/Se)),i=Math.max(i,.01);const s=o.scale,a=p(s*n,i,l),c=a/s,u=e.getBoundingClientRect(),d=(t.touches[0].clientX+t.touches[1].clientX)/2-u.left,h=(t.touches[0].clientY+t.touches[1].clientY)/2-u.top,g=e.scrollLeft+d,m=e.scrollTop+h;Ne.current=!0,o.setScale(a),e.scrollLeft=g*c-d,e.scrollTop=m*c-h,ve.current=r}},n=()=>{ve.current=0};return e.addEventListener("touchstart",t,{passive:!0}),e.addEventListener("touchmove",r,{passive:!1}),e.addEventListener("touchend",n,{passive:!0}),()=>{e.removeEventListener("touchstart",t),e.removeEventListener("touchmove",r),e.removeEventListener("touchend",n)}},[ce,Se,o]);const Fe=void 0!==te,We=o.pages.map(e=>{if(ce){const t=(e.computedWidth+we+xe)*o.scale;return Fe?t+te:t+2*Pe}{const t=(e.computedHeight+ye+Le)*o.scale;return Fe?t+te:t+2*Re}}),Be=[];let Oe=Fe?ce?Pe:Re:0;for(let e=0;e<We.length;e++){Be.push(Oe),Oe+=We[e]}const ze=We.reduce((e,t)=>e+t,0),je=Fe?ze+(ce?2*Pe:2*Re):ze,Ne=r.useRef(!1),[,He]=r.useReducer(e=>e+1,0);((e,t,o,n,l)=>{const i=r.useRef(0),s=r.useRef(0),a=r.useRef(null),c=r.useRef(null),u=r.useRef(!1),d=r.useRef(n.pages.length);u.current=d.current!==n.pages.length,d.current=n.pages.length,r.useEffect(()=>{const t=e.current,r=()=>{i.current=t.scrollLeft,s.current=t.scrollTop,a.current=t.scrollWidth,c.current=t.scrollHeight};return t.addEventListener("scroll",r),r(),()=>{t.removeEventListener("scroll",r)}},[]),r.useLayoutEffect(()=>{if(!e.current){return}if(u.current){const t=e.current;return a.current=t.scrollWidth,c.current=t.scrollHeight,i.current=t.scrollLeft,void(s.current=t.scrollTop)}const t=e.current,r=a.current,o=c.current;if(null===r||null===o){return a.current=t.scrollWidth,c.current=t.scrollHeight,i.current=t.scrollLeft,void(s.current=t.scrollTop)}l.current=!0;const n=t.offsetWidth,d=t.offsetHeight,h=(i.current+n/2)/r,g=(s.current+d/2)/o,f=Math.max(0,t.scrollWidth-n),m=Math.max(0,t.scrollHeight-d);t.scrollLeft=p(h*t.scrollWidth-n/2,0,f),t.scrollTop=p(g*t.scrollHeight-d/2,0,m),a.current=t.scrollWidth,c.current=t.scrollHeight,i.current=t.scrollLeft,s.current=t.scrollTop},[o,t])})(me,je,o.scale,o,Ne);const{handleScroll:Ge}=((e,t,o,n,l,i,s,a,c,u)=>{const d=r.useRef(!1),h=r.useRef(null),g=r.useRef(!1),p="horizontal"===c;r.useEffect(()=>{const t=e.current,r=()=>{s.current};return t.addEventListener("scroll",r),()=>{t.removeEventListener("scroll",r)}},[]);const f=n.pages.indexOf(n.activePage);return r.useLayoutEffect(()=>{if(a){return}if(!n.activePage){return}if(!e.current){return}if(d.current){return}const r=e.current,i=n.pages.indexOf(n.activePage),s=t[i]||0,c=p?r.scrollLeft:r.scrollTop,h=p?r.scrollWidth-r.clientWidth:r.scrollHeight-r.clientHeight,f=Math.min(s,Math.max(0,h)),m=o[i]||o[0]||0;let v=()=>{};return(Math.abs(f-c)>m*l||g.current)&&(g.current=!0,v=(({element:e,scrollTop:t,scrollLeft:r,duration:o=300,onFinish:n=()=>{}})=>{const l=void 0!==t,i=l?e.scrollTop:e.scrollLeft,s=l?t:r,a=s-i;let c=0,u=!1;if(0===o){return l?e.scrollTop=s:e.scrollLeft=s,()=>{}}const d=()=>{if(u){return}c+=20;const t=h(c,i,a,o);l?e.scrollTop=t:e.scrollLeft=t,c<o?setTimeout(d,20):n()},h=(e,t,r,o)=>(e/=o/2)<1?r/2*e*e+t:-r/2*(--e*(e-2)-1)+t;return d(),()=>{u=!0}})(Object.assign(Object.assign({element:r},p?{scrollLeft:f}:{scrollTop:f}),{onFinish:()=>{g.current=!1,null==u||u()},duration:n.isPlaying?0:300}))),v},[n.activePage,f,n.isPlaying,a,c,t,o]),{handleScroll:e=>{if(a){return}if(g.current){return}d.current=!0,clearTimeout(h.current),h.current=setTimeout(()=>{d.current=!1},300);const r=(p?e.currentTarget.scrollLeft:e.currentTarget.scrollTop)+(p?i.width:i.height)/3;let o=0;for(let n=t.length-1;n>=0;n--){if(r>=t[n]){o=n;break}}const l=n.pages[o];l&&n.activePage!==l&&l.select()}}})(me,Be,We,o,ie,he,Ne,le,d,He),Ie=he.width>=Se*o.scale+2*Pe,_e=he.height>=Ee*o.scale+2*Re,Ye=x||"rgba(232, 232, 232, 0.9)",De=(null==Q?void 0:Q.NoPages)||m,Xe=ce?he.width:he.height,Ae=me.current?ce?me.current.scrollLeft:me.current.scrollTop:0,Ke=e=>{for(let t=Be.length-1;t>=0;t--){if(e>=Be[t]){return t}}return 0},qe=Math.max(0,Ke(Ae)),Ve=Math.min(o.pages.length-1,Ke(Ae+Xe)),Je=null!=ne?ne:1,Qe=Math.max(0,qe-Je),Ue=Math.min(o.pages.length-1,Ve+Je),Ze=g({cropOverlayFill:W,cropGridStyle:B,workspaceBackgroundColor:x,pageBorderColor:L,activePageBorderColor:T,bleedColor:b,transparencyBackgroundColor:y,transformerStyle:O,innerImageCropTransformerStyle:z,outerImageCropTransformerStyle:j,highlighterStyle:N,snapGuideStroke:k,snapGuideStrokeWidth:S,snapGuideDash:E,selectionRectFill:M,selectionRectStroke:C,selectionRectStrokeWidth:P,transformLabelFill:R,transformLabelTextFill:F,distanceGuideStroke:_,distanceLabelFill:Y,distanceLabelTextFill:D,mediaLoadingStyle:H,mediaErrorStyle:G,textOverflowIndicatorStyle:I,rulerBackgroundColor:X,rulerTextColor:A,rulerBorderColor:K,rulerBorderSize:q,rulerTickColor:V,rulerTickSize:J});return e(h,{value:Ze,children:e("div",{ref:fe,style:{width:"100%",height:"100%",position:"relative",outline:"none",flex:1,backgroundColor:Ye,overflow:"hidden"},tabIndex:0,className:"polotno-workspace-container",children:t("div",{ref:me,onScroll:Ge,style:Object.assign({position:"absolute",top:0,left:0,width:"100%",height:"100%",display:"flex",flexDirection:ce?"row":"column",overflow:"auto",overflowX:ce?"auto":Ie?"hidden":"auto",overflowY:ce&&_e?"hidden":"auto"},Fe&&{paddingTop:ce?0:Re,paddingBottom:ce?0:Re,paddingLeft:ce?Pe:0,paddingRight:ce?Pe:0,boxSizing:"border-box"}),className:"polotno-workspace-inner",children:[o.pages.map((t,r)=>{const l=t===o.activePage;if(le&&!l&&!t._exportingOrRendering&&!t._forceMount){return null}const i=l||r>=Qe&&r<=Ue||t._exportingOrRendering||t._forceMount,s=ce?We[r]:Se*o.scale+2*Pe,a=ce?Ee*o.scale+2*Re:We[r];if(!i){return e("div",{style:{flexShrink:0},children:e(v,{width:s,height:a,backgroundColor:Ye,xPadding:Pe,yPadding:Re})},t.id)}const c=e(n,{page:t,xPadding:Pe,yPadding:Re,width:s,height:a,store:o,pageControlsEnabled:w,altCloneEnabled:re,groupSelectionMode:oe,components:Q,viewportSize:he,layout:d,tooltipSafeArea:se},t.id);return(t._exportingOrRendering||t._forceMount)&&!l&&le?e("div",{style:{display:"none",flexShrink:0},children:c},t.id):c}),o.rulesVisible&&e(l,{store:o,xPadding:Pe,yPadding:Re,width:Se*o.scale+2*Pe,height:Ee*o.scale+2*Re,pageSizes:We,layout:d,renderOnlyActivePage:le}),0===o.pages.length&&e(De,{store:o}),o.audios.map(t=>e(i,{audio:t,store:o},t.id))]})})})});export default WorkspaceCanvas;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { TransformerConfig } from 'konva/lib/shapes/Transformer';
|
|
3
3
|
import type { RectConfig } from 'konva/lib/shapes/Rect';
|
|
4
|
+
import type { LineConfig } from 'konva/lib/shapes/Line';
|
|
4
5
|
export declare const EDITOR_ACCENT_COLOR = "rgb(0, 161, 255)";
|
|
5
6
|
export declare const DEFAULT_TRANSFORMER_STYLE: TransformerConfig;
|
|
6
7
|
export declare const DEFAULT_INNER_IMAGE_CROP_TRANSFORMER_STYLE: TransformerConfig;
|
|
@@ -49,6 +50,7 @@ export interface RulerStyle {
|
|
|
49
50
|
}
|
|
50
51
|
export declare const DEFAULT_RULER_STYLE: RulerStyle;
|
|
51
52
|
export declare const DEFAULT_CROP_OVERLAY_FILL = "rgba(0,0,0,0.3)";
|
|
53
|
+
export declare const DEFAULT_CROP_GRID_STYLE: LineConfig;
|
|
52
54
|
export declare const DEFAULT_WORKSPACE_BACKGROUND_COLOR = "rgba(232, 232, 232, 0.9)";
|
|
53
55
|
export declare const DEFAULT_PAGE_BORDER_COLOR = "lightgrey";
|
|
54
56
|
export declare const DEFAULT_ACTIVE_PAGE_BORDER_COLOR = "rgb(0, 161, 255)";
|
|
@@ -64,6 +66,7 @@ export interface WorkspaceStyleOverrides {
|
|
|
64
66
|
innerImageCropTransformerStyle?: TransformerConfig;
|
|
65
67
|
outerImageCropTransformerStyle?: TransformerConfig;
|
|
66
68
|
highlighterStyle?: RectConfig;
|
|
69
|
+
cropGridStyle?: LineConfig | null;
|
|
67
70
|
mediaLoadingStyle?: Partial<MediaIndicatorStyle>;
|
|
68
71
|
mediaErrorStyle?: Partial<MediaIndicatorStyle>;
|
|
69
72
|
textOverflowIndicatorStyle?: Partial<TextOverflowIndicatorStyle>;
|
|
@@ -93,6 +96,7 @@ export interface ResolvedWorkspaceStyle {
|
|
|
93
96
|
activePageBorderColor: string;
|
|
94
97
|
bleedColor: string;
|
|
95
98
|
transparencyBackgroundColor: string | undefined;
|
|
99
|
+
cropGridStyle: LineConfig | null;
|
|
96
100
|
transformerStyle: TransformerConfig;
|
|
97
101
|
innerImageCropTransformerStyle: TransformerConfig;
|
|
98
102
|
outerImageCropTransformerStyle: TransformerConfig;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import r from"react";import e from"konva";const t=20,o=new e.Group;o.add(new e.Rect({width:t,height:t,fill:"white"})),o.add(new e.Path({scaleX:.8333333333333334,scaleY:.8333333333333334,data:"M4.98313549,11.0001422 C5.49589839,10.9914935 5.92501998,11.3703506 5.99116425,11.8666444 L5.99985778,11.9831355 L6.00348884,12.2068855 C6.11245031,15.4321748 8.76323537,17.9999971 11.9999971,17.9999971 C12.1869612,17.9999971 12.3726725,17.9914753 12.5567465,17.9745765 L12.2928932,17.7071068 C11.9023689,17.3165825 11.9023689,16.6834175 12.2928932,16.2928932 C12.6834175,15.9023689 13.3165825,15.9023689 13.7071068,16.2928932 L15.7071068,18.2928932 C16.0976311,18.6834175 16.0976311,19.3165825 15.7071068,19.7071068 L13.7071068,21.7071068 C13.3165825,22.0976311 12.6834175,22.0976311 12.2928932,21.7071068 C11.9023689,21.3165825 11.9023689,20.6834175 12.2928932,20.2928932 L12.6111505,19.9769552 C12.4086045,19.9922816 12.2047796,19.9999971 11.9999971,19.9999971 C7.7687005,19.9999971 4.28886152,16.7094374 4.01666425,12.5105203 L4.00420123,12.2575143 L4.00014222,12.0168645 C3.9908282,11.4646583 4.43092928,11.0094562 4.98313549,11.0001422 Z M11.7071068,2.29289322 C12.0675907,2.65337718 12.0953203,3.22060824 11.7902954,3.61289944 L11.7071068,3.70710678 L11.3891629,4.0230186 C11.5916051,4.00770767 11.7953244,4 12,4 C16.418278,4 20,7.581722 20,12 C20,12.5522847 19.5522847,13 19,13 C18.4477153,13 18,12.5522847 18,12 C18,8.6862915 15.3137085,6 12,6 C11.8129339,6 11.6271216,6.00853145 11.4429483,6.02544919 L11.7071068,6.29289322 C12.0976311,6.68341751 12.0976311,7.31658249 11.7071068,7.70710678 C11.3466228,8.06759074 10.7793918,8.09532028 10.3871006,7.79029539 L10.2928932,7.70710678 L8.29289322,5.70710678 C7.93240926,5.34662282 7.90467972,4.77939176 8.20970461,4.38710056 L8.29289322,4.29289322 L10.2928932,2.29289322 C10.6834175,1.90236893 11.3165825,1.90236893 11.7071068,2.29289322 Z",fill:"black"}));const l=o.toCanvas({pixelRatio:2,width:t,height:t});export const EDITOR_ACCENT_COLOR="rgb(0, 161, 255)";export const DEFAULT_TRANSFORMER_STYLE={borderEnabled:!0,anchorSize:10,anchorCornerRadius:0,anchorFill:"white",anchorStroke:"rgb(0, 161, 255)",anchorStrokeWidth:2,borderStrokeWidth:2,rotateAnchorOffset:30,anchorStyleFunc:r=>{if(r.hasName("rotater")){const e=20;r.setAttrs({width:e,height:e,cornerRadius:e/2,offsetX:e/2,offsetY:e/2,fillPatternImage:l,fillPatternScaleX:e/t/2,fillPatternScaleY:e/t/2,fillPriority:"pattern",fillPatternRepeat:"no-repeat"})}}};export const DEFAULT_INNER_IMAGE_CROP_TRANSFORMER_STYLE={anchorFill:"rgb(240, 240, 240)",anchorStrokeWidth:2,borderStrokeWidth:2};export const DEFAULT_OUTER_IMAGE_CROP_TRANSFORMER_STYLE={anchorSize:20,anchorCornerRadius:10,anchorStrokeWidth:2,borderStrokeWidth:2};export const DEFAULT_HIGHLIGHTER_STYLE={stroke:"rgb(0, 161, 255)",strokeWidth:2};export const DEFAULT_SNAP_GUIDE_STYLE={stroke:"rgb(0, 161, 255)",strokeWidth:1,dash:[4,6]};export const DEFAULT_SELECTION_RECT_STYLE={fill:"rgba(0, 161, 255, 0.3)",stroke:"rgb(0, 161, 255)",strokeWidth:1};export const DEFAULT_TRANSFORM_LABEL_STYLE={fill:"rgb(0, 161, 255)",textFill:"white"};export const DEFAULT_DISTANCE_GUIDE_STYLE={stroke:"rgb(0, 161, 255)",labelFill:"rgb(0, 161, 255)",labelTextFill:"white"};export const DEFAULT_MEDIA_LOADING_STYLE={fill:"rgba(124, 173, 212, 0.8)",textFill:"white"};export const DEFAULT_MEDIA_ERROR_STYLE={fill:"rgba(223, 102, 102, 0.8)",textFill:"white"};export const DEFAULT_TEXT_OVERFLOW_INDICATOR_STYLE={stroke:"red"};export const DEFAULT_RULER_STYLE={backgroundColor:"#e8e8e8",textColor:"grey",borderColor:"grey",borderSize:1,tickColor:"grey",tickSize:1};export const DEFAULT_CROP_OVERLAY_FILL="rgba(0,0,0,0.3)";export const DEFAULT_CROP_GRID_STYLE={stroke:"rgba(255, 255, 255, 0.25)",strokeWidth:1};export const DEFAULT_WORKSPACE_BACKGROUND_COLOR="rgba(232, 232, 232, 0.9)";export const DEFAULT_PAGE_BORDER_COLOR="lightgrey";export const DEFAULT_ACTIVE_PAGE_BORDER_COLOR="rgb(0, 161, 255)";export const DEFAULT_BLEED_COLOR="rgba(255, 0, 0, 0.1)";function n(r,e){if(!e){return Object.assign({},r)}const t=Object.assign({},r);for(const o in e){const r=e[o];void 0!==r&&(t[o]=r)}return t}export function buildWorkspaceStyle(r={}){var e,t,o,l,i;return{editorAccentColor:"rgb(0, 161, 255)",cropOverlayFill:null!==(e=r.cropOverlayFill)&&void 0!==e?e:"rgba(0,0,0,0.3)",cropGridStyle:null===r.cropGridStyle?null:n(DEFAULT_CROP_GRID_STYLE,r.cropGridStyle),workspaceBackgroundColor:null!==(t=r.workspaceBackgroundColor)&&void 0!==t?t:"rgba(232, 232, 232, 0.9)",pageBorderColor:null!==(o=r.pageBorderColor)&&void 0!==o?o:"lightgrey",activePageBorderColor:null!==(l=r.activePageBorderColor)&&void 0!==l?l:"rgb(0, 161, 255)",bleedColor:null!==(i=r.bleedColor)&&void 0!==i?i:DEFAULT_BLEED_COLOR,transparencyBackgroundColor:r.transparencyBackgroundColor,transformerStyle:n(DEFAULT_TRANSFORMER_STYLE,r.transformerStyle),innerImageCropTransformerStyle:n(DEFAULT_INNER_IMAGE_CROP_TRANSFORMER_STYLE,r.innerImageCropTransformerStyle),outerImageCropTransformerStyle:n(DEFAULT_OUTER_IMAGE_CROP_TRANSFORMER_STYLE,r.outerImageCropTransformerStyle),highlighterStyle:n(DEFAULT_HIGHLIGHTER_STYLE,r.highlighterStyle),snapGuideStyle:n(DEFAULT_SNAP_GUIDE_STYLE,{stroke:r.snapGuideStroke,strokeWidth:r.snapGuideStrokeWidth,dash:r.snapGuideDash}),selectionRectStyle:n(DEFAULT_SELECTION_RECT_STYLE,{fill:r.selectionRectFill,stroke:r.selectionRectStroke,strokeWidth:r.selectionRectStrokeWidth}),transformLabelStyle:n(DEFAULT_TRANSFORM_LABEL_STYLE,{fill:r.transformLabelFill,textFill:r.transformLabelTextFill}),distanceGuideStyle:n(DEFAULT_DISTANCE_GUIDE_STYLE,{stroke:r.distanceGuideStroke,labelFill:r.distanceLabelFill,labelTextFill:r.distanceLabelTextFill}),mediaLoadingStyle:n(DEFAULT_MEDIA_LOADING_STYLE,r.mediaLoadingStyle),mediaErrorStyle:n(DEFAULT_MEDIA_ERROR_STYLE,r.mediaErrorStyle),textOverflowIndicatorStyle:n(DEFAULT_TEXT_OVERFLOW_INDICATOR_STYLE,r.textOverflowIndicatorStyle),rulerStyle:n(DEFAULT_RULER_STYLE,{backgroundColor:r.rulerBackgroundColor,textColor:r.rulerTextColor,borderColor:r.rulerBorderColor,borderSize:r.rulerBorderSize,tickColor:r.rulerTickColor,tickSize:r.rulerTickSize})}}const i=r.createContext(null);export const WorkspaceStyleProvider=i.Provider;export function useWorkspaceStyle(){return r.useContext(i)||buildWorkspaceStyle()}let a=0;const s=new Set;function E(){a++,s.forEach(r=>r())}function c(r){return s.add(r),()=>{s.delete(r)}}function _(){return a}export function useResolvedWorkspaceStyle(e){const t=r.useSyncExternalStore(c,_,_),o=r.useRef(null);return o.current&&o.current.revision===t&&function(r,e){const t=Object.keys(r),o=Object.keys(e);if(t.length!==o.length){return!1}for(const l of t){if(!L(r[l],e[l])){return!1}}return!0}(o.current.overrides,e)||(o.current={overrides:e,revision:t,resolved:buildWorkspaceStyle(e)}),o.current.resolved}function L(r,e){if(r===e){return!0}if(null==r||null==e){return!1}if(Array.isArray(r)){if(!Array.isArray(e)||r.length!==e.length){return!1}for(let t=0;t<r.length;t++){if(r[t]!==e[t]){return!1}}return!0}if("object"==typeof r&&"object"==typeof e&&!Array.isArray(e)){const t=Object.keys(r),o=Object.keys(e);if(t.length!==o.length){return!1}for(const l of t){if(r[l]!==e[l]){return!1}}return!0}return!1}export const setTransformerStyle=r=>{Object.assign(DEFAULT_TRANSFORMER_STYLE,r),E()};export const setHighlighterStyle=r=>{Object.assign(DEFAULT_HIGHLIGHTER_STYLE,r),E()};export const setInnerImageCropTransformerStyle=r=>{Object.assign(DEFAULT_INNER_IMAGE_CROP_TRANSFORMER_STYLE,r),E()};export const setOuterImageCropTransformerStyle=r=>{Object.assign(DEFAULT_OUTER_IMAGE_CROP_TRANSFORMER_STYLE,r),E()};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
interface CropGeometry {
|
|
2
|
+
x: number;
|
|
3
|
+
y: number;
|
|
4
|
+
width: number;
|
|
5
|
+
height: number;
|
|
6
|
+
cropX: number;
|
|
7
|
+
cropY: number;
|
|
8
|
+
cropWidth: number;
|
|
9
|
+
cropHeight: number;
|
|
10
|
+
}
|
|
11
|
+
interface CropModeHost extends CropGeometry {
|
|
12
|
+
readonly contentEditable: boolean;
|
|
13
|
+
readonly maskSrc?: string;
|
|
14
|
+
readonly store?: {
|
|
15
|
+
readonly history: {
|
|
16
|
+
startTransaction(): void;
|
|
17
|
+
endTransaction(): void;
|
|
18
|
+
};
|
|
19
|
+
} | null;
|
|
20
|
+
set(props: Partial<CropGeometry>): void;
|
|
21
|
+
}
|
|
22
|
+
export declare const cropMode: (self: CropModeHost) => {
|
|
23
|
+
views: {
|
|
24
|
+
readonly _cropModeEnabled: boolean;
|
|
25
|
+
readonly _cropEnabled: boolean;
|
|
26
|
+
};
|
|
27
|
+
actions: {
|
|
28
|
+
toggleCropMode(flag?: boolean): void;
|
|
29
|
+
cancelCropMode(): void;
|
|
30
|
+
beforeDestroy(): void;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
export type CropModeActions = ReturnType<typeof cropMode>['actions'];
|
|
34
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{observable as o}from"mobx";export const cropMode=t=>{const e=o.box(!1);let r=!1,n=null;const c=o=>{var c;o!==e.get()&&(n=o?{x:t.x,y:t.y,width:t.width,height:t.height,cropX:t.cropX,cropY:t.cropY,cropWidth:t.cropWidth,cropHeight:t.cropHeight}:null),e.set(o);const i=null===(c=t.store)||void 0===c?void 0:c.history;i&&(o&&!r?(i.startTransaction(),r=!0):!o&&r&&(i.endTransaction(),r=!1))};return{views:{get _cropModeEnabled(){return e.get()},get _cropEnabled(){return t.contentEditable&&!t.maskSrc}},actions:{toggleCropMode(o){c(null!=o?o:!e.get())},cancelCropMode(){n&&t.set(n),c(!1)},beforeDestroy(){r&&(t.store.history.endTransaction(),r=!1)}}}};
|
package/model/gif-model.d.ts
CHANGED
|
@@ -159,9 +159,11 @@ export declare const GifElement: import("mobx-state-tree").IModelType<{
|
|
|
159
159
|
setFilter(type: any, value: any): void;
|
|
160
160
|
} & {
|
|
161
161
|
toggleCropMode(flag?: boolean): void;
|
|
162
|
+
cancelCropMode(): void;
|
|
162
163
|
beforeDestroy(): void;
|
|
163
164
|
} & {
|
|
164
165
|
readonly _cropModeEnabled: boolean;
|
|
166
|
+
readonly _cropEnabled: boolean;
|
|
165
167
|
}, import("mobx-state-tree").ModelCreationType<{
|
|
166
168
|
id: string;
|
|
167
169
|
type: string | undefined;
|
package/model/group-model.d.ts
CHANGED
|
@@ -217,6 +217,13 @@ export declare const TYPES_MAP: {
|
|
|
217
217
|
} & {
|
|
218
218
|
replaceColor(oldColor: any, newColor: any): void;
|
|
219
219
|
resetColors(): void;
|
|
220
|
+
} & {
|
|
221
|
+
toggleCropMode(flag?: boolean): void;
|
|
222
|
+
cancelCropMode(): void;
|
|
223
|
+
beforeDestroy(): void;
|
|
224
|
+
} & {
|
|
225
|
+
readonly _cropModeEnabled: boolean;
|
|
226
|
+
readonly _cropEnabled: boolean;
|
|
220
227
|
}, any, import("mobx-state-tree").ModelSnapshotType<{
|
|
221
228
|
id: import("mobx-state-tree").ISimpleType<string>;
|
|
222
229
|
type: import("mobx-state-tree").IType<string | undefined, string, string>;
|
|
@@ -567,9 +574,11 @@ export declare const TYPES_MAP: {
|
|
|
567
574
|
setFilter(type: any, value: any): void;
|
|
568
575
|
} & {
|
|
569
576
|
toggleCropMode(flag?: boolean): void;
|
|
577
|
+
cancelCropMode(): void;
|
|
570
578
|
beforeDestroy(): void;
|
|
571
579
|
} & {
|
|
572
580
|
readonly _cropModeEnabled: boolean;
|
|
581
|
+
readonly _cropEnabled: boolean;
|
|
573
582
|
}, import("mobx-state-tree").ModelCreationType<{
|
|
574
583
|
id: string;
|
|
575
584
|
type: string | undefined;
|
|
@@ -925,9 +934,11 @@ export declare const TYPES_MAP: {
|
|
|
925
934
|
setFilter(type: any, value: any): void;
|
|
926
935
|
} & {
|
|
927
936
|
toggleCropMode(flag?: boolean): void;
|
|
937
|
+
cancelCropMode(): void;
|
|
928
938
|
beforeDestroy(): void;
|
|
929
939
|
} & {
|
|
930
940
|
readonly _cropModeEnabled: boolean;
|
|
941
|
+
readonly _cropEnabled: boolean;
|
|
931
942
|
}, import("mobx-state-tree").ModelCreationType<{
|
|
932
943
|
id: string;
|
|
933
944
|
type: string | undefined;
|
|
@@ -1279,9 +1290,11 @@ export declare const TYPES_MAP: {
|
|
|
1279
1290
|
setFilter(type: any, value: any): void;
|
|
1280
1291
|
} & {
|
|
1281
1292
|
toggleCropMode(flag?: boolean): void;
|
|
1293
|
+
cancelCropMode(): void;
|
|
1282
1294
|
beforeDestroy(): void;
|
|
1283
1295
|
} & {
|
|
1284
1296
|
readonly _cropModeEnabled: boolean;
|
|
1297
|
+
readonly _cropEnabled: boolean;
|
|
1285
1298
|
}, import("mobx-state-tree").ModelCreationType<{
|
|
1286
1299
|
id: string;
|
|
1287
1300
|
type: string | undefined;
|
package/model/image-model.d.ts
CHANGED
|
@@ -155,9 +155,11 @@ export declare const ImageElement: import("mobx-state-tree").IModelType<{
|
|
|
155
155
|
setFilter(type: any, value: any): void;
|
|
156
156
|
} & {
|
|
157
157
|
toggleCropMode(flag?: boolean): void;
|
|
158
|
+
cancelCropMode(): void;
|
|
158
159
|
beforeDestroy(): void;
|
|
159
160
|
} & {
|
|
160
161
|
readonly _cropModeEnabled: boolean;
|
|
162
|
+
readonly _cropEnabled: boolean;
|
|
161
163
|
}, import("mobx-state-tree").ModelCreationType<{
|
|
162
164
|
id: string;
|
|
163
165
|
type: string | undefined;
|
package/model/image-model.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{Shape as e}from"./shape-model.js";import{cropMode as r}from"./crop-mode.js";export const ImageElement=e.named("Image").props({type:"image",width:100,height:100,src:"",cropX:0,cropY:0,cropWidth:1,cropHeight:1,cornerRadius:0,flipX:!1,flipY:!1,clipSrc:"",borderColor:"black",borderSize:0,keepRatio:!1,stretchEnabled:!1}).extend(r);
|