polotno 3.7.0 → 3.8.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.
@@ -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 h,Image as s,Rect as l,Text as c,Transformer as u}from"react-konva";import{ROLES as g}from"../model/store.js";import m from"use-image";import f from"konva";import{Portal as p}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,isCornerAnchor as C,scaledBoxStyleAttrs as R,roundedBoxStyleAttrs as S}from"../utils/px.js";import{useFilteredSource as I}from"./use-filtered-source.js";import{useEvent as k}from"../hooks/use-event.js";import{useFadeIn as H}from"./use-fadein.js";import{isTouchDevice as W}from"../utils/screen.js";import{createPlayGate as X,playMedia as Y}from"../utils/media.js";import{useMediabunnyVideo as O}from"./use-mediabunny-video.js";import{getElementTimeRange as j,getVideoRestMs as P}from"../utils/timeline.js";function A(){return document.createElement("canvas")}const _=new window.Image;_.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 V=new window.Image;V.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,h;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),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<1&&!a,m=t instanceof HTMLVideoElement?t.videoWidth:null==t?void 0:t.width,p=t instanceof HTMLVideoElement?t.videoHeight:null==t?void 0:t.height,v=0===r.x&&0===r.y&&r.width===m&&r.height===p,w=i.useMemo(()=>{if(t&&m&&p){return v&&0===c&&!g?void 0:A()}},[t,c,g,v,m,p]),x=()=>{if(!w||!t){return}w.width=s,w.height=l;const e=w.getContext("2d");if(!e){return}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());const i=g?function(e,t){var r,i;const o=A(),n=e instanceof HTMLVideoElement?e.videoWidth:e.width,a=e instanceof HTMLVideoElement?e.videoHeight:e.height;o.width=n,o.height=a,null===(r=o.getContext("2d"))||void 0===r||r.drawImage(e,0,0,o.width,o.height);const d=function(e,t,r,i,o,n,a){for(var d=new ImageData(t,r),h=new Int32Array(e.data.buffer),s=e.width,l=new Int32Array(d.data.buffer),c=d.width,u=t/n,g=r/a,m=Math.round(1/u),f=Math.round(1/g),p=m*f,v=0;v<d.height;v++){for(var w=0;w<c;w++){for(var x=0+Math.round(w/u)+(0+Math.round(v/g))*s,M=0,y=0,E=0,b=0,L=0;L<f;L++){for(var T=0;T<m;T++){var C=h[x+T+L*s];M+=C<<24>>>24,y+=C<<16>>>24,E+=C<<8>>>24,b+=C>>>24}}M=Math.round(M/p),y=Math.round(y/p),E=Math.round(E/p),b=Math.round(b/p),l[w+v*c]=b<<24|E<<16|y<<8|M}}return d}(o.getContext("2d").getImageData(0,0,o.width,o.height),Math.floor(o.width*t),Math.floor(o.height*t),0,0,o.width,o.height);return o.width=Math.floor(o.width*t),o.height=Math.floor(o.height*t),null===(i=o.getContext("2d"))||void 0===i||i.putImageData(d,0,0),o}(t,u):t,o=g?{x:Math.floor(r.x*u),y:Math.floor(r.y*u),width:Math.floor(r.width*u),height:Math.floor(r.height*u)}:r;e.drawImage(i,o.x,o.y,o.width,o.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===(h=e.page)||void 0===h?void 0:h._exportingOrRendering,g]),i.useEffect(()=>()=>{w&&"CANVAS"===w.nodeName&&f.Util.releaseCanvas(w)},[w]),[w||t,x]};const D=A(),z=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 f.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(h,{x:r.a.x,y:r.a.y,rotation:r.a.rotation,listening:!1,opacity:r.a.opacity,hideInExport:!r.showInExport,children:[e(l,{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})]})}),B=o(({element:r})=>{const{mediaErrorStyle:i}=v(),o=Math.max(10,Math.min(30,r.width/25));return t(h,{x:r.a.x,y:r.a.y,rotation:r.a.rotation,listening:!1,opacity:r.a.opacity,hideInExport:!r.showInExport,children:[e(l,{width:r.width,height:r.height,fill:i.fill}),e(c,{text:"Can not load the video...",fontSize:o,width:r.width,height:r.height,align:"center",fill:i.textFill,verticalAlign:"middle",padding:5})]})});let U=function(e,t,r){const o=i.useRef("loading"),n=i.useRef(void 0),[a,d]=i.useState(0),h=i.useRef(void 0),s=i.useRef(void 0),l=i.useRef(void 0);return h.current===e&&s.current===t&&l.current===r||(o.current="loading",n.current=void 0,h.current=e,s.current=t,l.current=r),i.useLayoutEffect(function(){if(e){var i=document.createElement("video");return i.addEventListener("canplay",a),i.addEventListener("error",h),t&&(i.crossOrigin=t),r&&(i.referrerPolicy=r),i.src=e,i.load(),function(){i.removeEventListener("canplay",a),i.removeEventListener("error",h)}}function a(){o.current="loaded",n.current=i,n.current.currentTime=0,d(Math.random()),n.current.removeEventListener("canplay",a)}function h(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 h=e.message||(null===(t=i.error)||void 0===t?void 0:t.message)||"Unknown error",s=new Error("Video failed to load: "+h);console.error(s),o.current="failed",n.current=void 0,d(Math.random())}},[e,t,r]),[n.current,o.current]};export const setVideoLoaderHook=e=>{U=e};function F(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 c,v,x;const[M,b]=i.useState(!1),N=i.useRef(null),Z=i.useRef(null),$=o.isSelected,[q,G]=i.useState(!1),[J,K]=U(o.src,"anonymous"),[Q,ee]=i.useState(!1),te=d.activePage===o.page,re=(null===(c=o.page)||void 0===c?void 0:c._exportingOrRendering)&&"loaded"===K,ie=O(o,d,re);useLoader(K,o.src,o.id),J&&(J.playsInline=!0);const oe=((e,t,r)=>{const o=i.useMemo(()=>{var i,o;const{flipX:n,flipY:a}=e,d="svg"===e.type||e.src.indexOf("data:image/svg+xml")>=0||e.src.indexOf(".svg")>=0,h=navigator.userAgent.toLowerCase().indexOf("firefox")>-1;if(!(n||a||h&&d)){return t}if(!t){return null}const s=t instanceof HTMLVideoElement?t.videoWidth:null==t?void 0:t.width,l=t instanceof HTMLVideoElement?t.videoHeight:null==t?void 0:t.height;if(!s||!l){return null}const c=A();let u=1;"svg"===e.type&&(u=Math.max(e.width/s*r,e.height/l*r)),c.width=Math.max(s*u,1),c.height=Math.max(l*u,1);let g=n?-c.width:0,m=a?-c.height:0;return null===(i=c.getContext("2d"))||void 0===i||i.scale(n?-1:1,a?-1:1),null===(o=c.getContext("2d"))||void 0===o||o.drawImage(t,g,m,c.width,c.height),c},[e.flipX,e.flipY,t,e.width,e.height,r]);return i.useEffect(()=>()=>{o&&"CANVAS"===o.nodeName&&f.Util.releaseCanvas(o)},[o]),o})(o,J,d._elementsPixelRatio),ne=re&&ie||oe||D,[ae=D,de]=I(o,ne);i.useEffect(()=>{J&&d.history.ignore(()=>{o.set({duration:1e3*J.duration})})},[J]);const he=i.useMemo(X,[J]);i.useEffect(()=>{var e;if(!J){return}const t=d.animatedElementsIds,r=(!t.length||t.includes(o.id))&&d.isPlaying;if(!te||!r&&!q){return void J.pause()}q&&(J.muted=!1,J.currentTime=o.startTime*J.duration,Y(J).then(e=>{"refused"===e&&G(!1)}));const i=new f.Animation(()=>{Ce()},null===(e=N.current)||void 0===e?void 0:e.getLayer());i.start();const n=()=>{G(!1),J.currentTime=o.startTime*J.duration},a=()=>{J.currentTime>=o.endTime*J.duration&&(J.pause(),J.currentTime=o.startTime*J.duration,G(!1))};return J.addEventListener("ended",n),J.addEventListener("timeupdate",a),()=>{J.pause(),i.stop(),J.removeEventListener("ended",n),J.removeEventListener("timeupdate",a)}},[J,q,d.isPlaying,te]),i.useEffect(()=>{J&&(J.volume=o.volume)},[J,o.volume]),i.useEffect(()=>{J&&(J.playbackRate=o.speed,J.preservesPitch=!1)},[J,o.speed]);const se=i.useRef(null);i.useEffect(()=>{const e=a(o,()=>{var e,t;if(J){if(re&&ie){return Ce(),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*J.duration*1e3,h=J.duration*(o.endTime-o.startTime)*1e3,{start:s,end:l}=j(o.animations,o.page.duration),c=(d.currentTime||o.page.startTime)-o.page.startTime,u=n?P(d.currentTime,o.page.startTime,s,h,a,o.speed):0,g=u/1e3,m=n&&c>=s&&c<l;q||(J.muted=!m,m&&d.isPlaying&&i?J.paused?(J.currentTime=g,he.play(J)):Math.abs(1e3*J.currentTime-u)>500&&(J.currentTime=g):(he.reset(),J.paused||J.pause(),g!==J.currentTime&&(J.currentTime=g),!F(J)&&!d.isPlaying&&!se.current&&(se.current=w(`video ${o.id}`)))),Ce(),null===(t=null===(e=N.current)||void 0===e?void 0:e.getLayer())||void 0===t||t.batchDraw()}});return()=>{e(),se.current&&(se.current(),se.current=null)}},[d,J,re,ie,q]),i.useEffect(()=>{var e,t;if(!J){return}if(re){return null===(e=se.current)||void 0===e||e.call(se),void(se.current=null)}const r=()=>{var e,t,r;!F(J)&&(null===(e=o.page)||void 0===e?void 0:e._exportingOrRendering)||se.current&&(Ce(),null===(r=null===(t=N.current)||void 0===t?void 0:t.getLayer())||void 0===r||r.batchDraw(),se.current(),se.current=null)};let i;return(null===(t=o.page)||void 0===t?void 0:t._exportingOrRendering)&&(i=setInterval(r,20)),J.addEventListener("timeupdate",r),J.addEventListener("canplay",r),()=>{clearInterval(i),J.removeEventListener("timeupdate",r),J.removeEventListener("canplay",r)}},[null===(v=o.page)||void 0===v?void 0:v._exportingOrRendering,J,o.id,w,re]);let{cropX:le,cropY:ce,cropWidth:ue,cropHeight:ge}=o;"loaded"!==K&&(le=ce=0,ue=ge=1);const me=(fe=ae)instanceof HTMLVideoElement?fe.videoWidth:(null==fe?void 0:fe.width)||0;var fe;const pe=(e=>e instanceof HTMLVideoElement?e.videoHeight:(null==e?void 0:e.height)||0)(ae),ve=y({cropX:le,cropY:ce,cropWidth:ue,cropHeight:ge,width:o.width,height:o.height},{width:me,height:pe}),we=ve.width,xe=ve.height,Me="svg"===o.type,ye=null!==(x=o.cornerRadius)&&void 0!==x?x:0,[Ee,be]=useCornerRadiusAndCrop(o,ae,ve,d._elementsPixelRatio,ye,!0);let[Le,Te]=((e,t,r,o)=>{const n=(e=>{const[t,r]=i.useState(e);return i.useEffect(()=>{(async()=>{const i=await async function(e){if(!(e.indexOf("data:image/svg+xml")>=0||e.indexOf(".svg")>=0)){return e}const t=await E.urlToString(e),r=E.fixSize(t);return E.svgToURL(r)}(e);i!==t&&r(i)})()},[e]),t})(e.clipSrc||""),[a,d]=m(n,"anonymous"),h=e.clipSrc?d:"loaded";useLoader(h,e.clipSrc,e.id);const s=i.useMemo(()=>{if(t&&a){return A()}},[t,a]);function l(){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(!s){return}const d=A(),h=Math.max(e.width/a.width*r,e.height/a.height*r);d.width=a.width*h,d.height=a.height*h,null===(i=d.getContext("2d"))||void 0===i||i.drawImage(a,0,0,d.width,d.height),s.width=Math.max(o,1),s.height=Math.max(n,1);const l=s.getContext("2d");l&&(l.save(),l.drawImage(d,0,0,o,n),f.Util.releaseCanvas(d),l.globalCompositeOperation="source-in",l.drawImage(t,0,0,s.width,s.height),l.restore())}return i.useLayoutEffect(()=>{l()},[s,t,a,e.width,e.height,r,...o]),[e.clipSrc&&a?s:t,l]})(o,Ee,d._elementsPixelRatio,[ve,ye,d._elementsPixelRatio]);const Ce=k(()=>{var e,t;de(),be(),Te(),null===(t=null===(e=N.current)||void 0===e?void 0:e.getLayer())||void 0===t||t.batchDraw()});i.useEffect(()=>{Ce()});const Re=Math.max(o.width/we,o.height/xe);i.useEffect(()=>{var e;if(!o._cropModeEnabled){return}const t=null===(e=N.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 Se=i.useRef(null),Ie=i.useRef(null),ke=i.useRef(null);i.useLayoutEffect(()=>{o._cropModeEnabled&&(Ie.current.nodes([Se.current]),ke.current.nodes([Z.current]))},[o._cropModeEnabled]);const He=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,we/t),n=Math.min(1,xe/r),a=1-i,d=Math.min(a,Math.max(0,Math.round(-e.target.x())/t)),h=1-n,s=Math.min(h,Math.max(0,Math.round(-e.target.y())/r));e.target.setAttrs({x:-d*me,y:-s*pe,scaleX:1,scaleY:1}),o.set({cropX:d,cropY:s,cropWidth:i,cropHeight:n})},We=()=>{"svg"!==o.type&&o.contentEditable&&setTimeout(()=>{n(o)&&o.toggleCropMode(!0)})},Xe="loading"===K,Ye="failed"===K,Oe=!Xe&&!Ye,je=i.useRef({cropX:0,cropY:0,cropWidth:0,cropHeight:0}),Pe=i.useRef(!1),Ae=Oe?o.a.opacity:0;H(N,Ae);const _e=o.selectable||d.role===g.ADMIN,Ve=W();return e(r,{children:t(h,{onMouseEnter:()=>ee(!0),onMouseLeave:()=>ee(!1),children:[Xe&&e(z,{element:o}),Ye&&e(B,{element:o}),e(s,{ref:N,name:"element",id:o.id,image:Le,x:o.a.x,y:o.a.y,width:o.a.width||1,height:o.a.height||1,rotation:o.a.rotation,opacity:Ae,shadowEnabled:o.shadowEnabled,shadowBlur:o.shadowBlur,shadowOffsetX:o.shadowOffsetX,shadowOffsetY:o.shadowOffsetY,shadowColor:o.shadowColor,shadowOpacity:o.shadowOpacity,customCrop:ve,listening:_e,draggable:Ve?o.draggable&&$:o.draggable,preventDefault:!Ve||$,hideInExport:!o.showInExport,onDragMove:e=>{o.set({x:e.target.x(),y:e.target.y()})},onDragEnd:e=>{o.set({x:e.target.x(),y:e.target.y()})},onDblClick:We,onDblTap:We,onTransformStart:e=>{b(!0),Pe.current=C(T(e.target)),je.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-we/me,a=Math.min(n,Math.max(0,o.cropX)),d=1-xe/pe,h=Math.min(d,Math.max(0,o.cropY)),s=Pe.current,l=!s&&r<1&&je.current.cropHeight>xe/pe;let c=s?o.cropWidth:o.cropWidth*r;l&&(c=o.cropWidth);const u=!s&&i<1&&je.current.cropWidth>we/me;let g=s?o.cropHeight:o.cropHeight*i;u&&(g=o.cropHeight),Me&&(c=o.cropWidth,g=o.cropHeight);const m=s?Math.min(r,i):1;o.set(Object.assign({cropX:a,cropY:h,x:t.x(),y:t.y(),width:t.width()*r,height:t.height()*i,rotation:e.target.rotation(),cropWidth:Math.min(c,1-a),cropHeight:Math.min(g,1-h)},1!==m&&Object.assign(Object.assign({},R(o,m)),{borderSize:o.borderSize*m})))},onTransformEnd:e=>{const t=e.currentTarget;o.set(Object.assign(Object.assign({width:t.width(),height:t.height(),x:t.x(),y:t.y(),rotation:e.target.rotation(),cropWidth:we/me,cropHeight:xe/pe},S(o)),{borderSize:L(o.borderSize)})),b(!1)}}),e(l,{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:Ae,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,ye-o.borderSize),hideInExport:!o.showInExport}),!d.isPlaying&&e(s,{image:q?Q||Ve?V: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:()=>G(!q),onTap:()=>G(!q)}),o._cropModeEnabled&&t(p,{selector:".page-abs-container",enabled:!0,children:[e(l,{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(s,{listening:!1,image:Le,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(h,{x:o.a.x,y:o.a.y,rotation:o.a.rotation,scaleX:Re,scaleY:Re,children:[e(s,{image:ae,ref:Z,width:me,height:pe,opacity:.4,draggable:!0,x:-o.cropX*me,y:-o.cropY*pe,onDragMove:He,onTransform:He}),e(u,{ref:ke,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(l,{width:we,height:xe,ref:Se,listening:!1,onTransform:e=>{e.target.x()<-o.cropX*me-1e-9&&(e.target.x(-o.cropX*me),e.target.scaleX(1)),e.target.y()<-o.cropY*pe-1e-9&&(e.target.y(-o.cropY*pe),e.target.scaleY(1));const t=Math.min(1,Math.max(0,o.cropX+e.target.x()/me)),r=Math.min(1,Math.max(0,e.target.y()/pe+o.cropY)),i=e.target.width()*e.target.scaleX(),n=e.target.height()*e.target.scaleY(),a=Math.min(1-t,i/me),d=Math.min(1-r,n/pe),h=e.target.getAbsolutePosition(e.target.getParent().getParent());e.target.scale({x:1,y:1}),e.target.position({x:0,y:0}),o.set({x:h.x,y:h.y,cropX:t,cropY:r,cropWidth:a,cropHeight:d,width:Math.min(i*Re,me*(1-t)*Re),height:Math.min(n*Re,pe*(1-r)*Re)})}}),e(u,{ref:Ie,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 o from"react";import{observer as i}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 h,Image as s,Rect as l,Text as c,Transformer as u}from"react-konva";import{ROLES as g}from"../model/store.js";import m from"use-image";import f from"konva";import{Portal as p}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,isCornerAnchor as C,scaledBoxStyleAttrs as S,roundedBoxStyleAttrs as R}from"../utils/px.js";import{useFilteredSource as I}from"./use-filtered-source.js";import{useEvent as k}from"../hooks/use-event.js";import{useFadeIn as H}from"./use-fadein.js";import{isTouchDevice as W}from"../utils/screen.js";import{createPlayGate as X,playMedia as Y}from"../utils/media.js";import{useMediabunnyVideo as j}from"./use-mediabunny-video.js";import{getElementTimeRange as P,getVideoRestMs as A}from"../utils/timeline.js";function O(){return document.createElement("canvas")}const _=new window.Image;_.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 V=new window.Image;V.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,i,n=0,a=!1)=>{var d,h;const s=Math.floor(Math.max(e.width*i,1)),l=Math.floor(Math.max(e.height*i,1)),c=Math.min(n*i,s/2,l/2),u=Math.max(e.width/r.width,e.height/r.height)*i,g=(null===(d=e.page)||void 0===d?void 0:d._exportingOrRendering)&&b.imageDownScalingEnabled&&u<1&&!a,m=t instanceof HTMLVideoElement?t.videoWidth:null==t?void 0:t.width,p=t instanceof HTMLVideoElement?t.videoHeight:null==t?void 0:t.height,v=0===r.x&&0===r.y&&r.width===m&&r.height===p,w=o.useMemo(()=>{if(t&&m&&p){return v&&0===c&&!g?void 0:O()}},[t,c,g,v,m,p]),x=()=>{if(!w||!t){return}w.width=s,w.height=l;const e=w.getContext("2d");if(!e){return}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());const o=g?function(e,t){var r,o;const i=O(),n=e instanceof HTMLVideoElement?e.videoWidth:e.width,a=e instanceof HTMLVideoElement?e.videoHeight:e.height;i.width=n,i.height=a,null===(r=i.getContext("2d"))||void 0===r||r.drawImage(e,0,0,i.width,i.height);const d=function(e,t,r,o,i,n,a){for(var d=new ImageData(t,r),h=new Int32Array(e.data.buffer),s=e.width,l=new Int32Array(d.data.buffer),c=d.width,u=t/n,g=r/a,m=Math.round(1/u),f=Math.round(1/g),p=m*f,v=0;v<d.height;v++){for(var w=0;w<c;w++){for(var x=0+Math.round(w/u)+(0+Math.round(v/g))*s,M=0,y=0,E=0,b=0,L=0;L<f;L++){for(var T=0;T<m;T++){var C=h[x+T+L*s];M+=C<<24>>>24,y+=C<<16>>>24,E+=C<<8>>>24,b+=C>>>24}}M=Math.round(M/p),y=Math.round(y/p),E=Math.round(E/p),b=Math.round(b/p),l[w+v*c]=b<<24|E<<16|y<<8|M}}return d}(i.getContext("2d").getImageData(0,0,i.width,i.height),Math.floor(i.width*t),Math.floor(i.height*t),0,0,i.width,i.height);return i.width=Math.floor(i.width*t),i.height=Math.floor(i.height*t),null===(o=i.getContext("2d"))||void 0===o||o.putImageData(d,0,0),i}(t,u):t,i=g?{x:Math.floor(r.x*u),y:Math.floor(r.y*u),width:Math.floor(r.width*u),height:Math.floor(r.height*u)}:r;e.drawImage(o,i.x,i.y,i.width,i.height,0,0,w.width,w.height)};return o.useLayoutEffect(()=>{x()},[w,e.width,e.height,r.x,r.y,r.width,r.height,n,i,a,null===(h=e.page)||void 0===h?void 0:h._exportingOrRendering,g]),o.useEffect(()=>()=>{w&&"CANVAS"===w.nodeName&&f.Util.releaseCanvas(w)},[w]),[w||t,x]};const D=O(),z=i(({element:r})=>{const i=Math.min(30,r.width/4,r.height/4),n=o.useRef(null);o.useEffect(()=>{const e=n.current;if(!e){return}const t=new f.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(h,{x:r.a.x,y:r.a.y,rotation:r.a.rotation,listening:!1,opacity:r.a.opacity,hideInExport:!r.showInExport,children:[e(l,{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(i),innerRadius:Math.max(1,i-5),angle:270})]})}),U=i(({element:r})=>{const{mediaErrorStyle:o}=v(),i=Math.max(10,Math.min(30,r.width/25));return t(h,{x:r.a.x,y:r.a.y,rotation:r.a.rotation,listening:!1,opacity:r.a.opacity,hideInExport:!r.showInExport,children:[e(l,{width:r.width,height:r.height,fill:o.fill}),e(c,{text:"Can not load the video...",fontSize:i,width:r.width,height:r.height,align:"center",fill:o.textFill,verticalAlign:"middle",padding:5})]})});let B=function(e,t,r){const i=o.useRef("loading"),n=o.useRef(void 0),[a,d]=o.useState(0),h=o.useRef(void 0),s=o.useRef(void 0),l=o.useRef(void 0);return h.current===e&&s.current===t&&l.current===r||(i.current="loading",n.current=void 0,h.current=e,s.current=t,l.current=r),o.useLayoutEffect(function(){if(e){var o=document.createElement("video");return o.addEventListener("canplay",a),o.addEventListener("error",h),t&&(o.crossOrigin=t),r&&(o.referrerPolicy=r),o.src=e,o.load(),function(){o.removeEventListener("canplay",a),o.removeEventListener("error",h)}}function a(){i.current="loaded",n.current=o,n.current.currentTime=0,d(Math.random()),n.current.removeEventListener("canplay",a)}function h(e){var t;const r=4===o.readyState,a=o.buffered&&o.buffered.length>0&&o.buffered.end(o.buffered.length-1)/o.duration*100>=100;if(r&&a){return}const h=e.message||(null===(t=o.error)||void 0===t?void 0:t.message)||"Unknown error",s=new Error("Video failed to load: "+h);console.error(s),i.current="failed",n.current=void 0,d(Math.random())}},[e,t,r]),[n.current,i.current]};export const setVideoLoaderHook=e=>{B=e};function F(e){return e.readyState>=HTMLMediaElement.HAVE_CURRENT_DATA}export const useLoader=(e,t,r)=>{const i=o.useRef(void 0),n=()=>{var e;null===(e=i.current)||void 0===e||e.call(i),i.current=void 0};o.useEffect(()=>n,[]),o.useLayoutEffect(()=>{const o=t.slice(0,200),a=`video with id ${r} url: ${o}`;"loading"!==e||i.current||(i.current=w(a)),"loading"!==e&&n(),"failed"===e&&x(M("VIDEO_FAILED",a,{src:o,elementId:r,reason:"load"}))},[e])};export const VideoElement=i(({element:i,store:d})=>{var c,v,x;const[M,b]=o.useState(!1),N=o.useRef(null),Z=o.useRef(null),$=i.isSelected,[q,G]=o.useState(!1),[J,K]=B(i.src,"anonymous"),[Q,ee]=o.useState(!1),te=d.activePage===i.page,re=(null===(c=i.page)||void 0===c?void 0:c._exportingOrRendering)&&"loaded"===K,oe=j(i,d,re);useLoader(K,i.src,i.id),J&&(J.playsInline=!0);const ie=((e,t,r)=>{const i=o.useMemo(()=>{var o,i;const{flipX:n,flipY:a}=e,d="svg"===e.type||E.isSvgUrl(e.src),h=navigator.userAgent.toLowerCase().indexOf("firefox")>-1;if(!(n||a||h&&d)){return t}if(!t){return null}const s=t instanceof HTMLVideoElement?t.videoWidth:null==t?void 0:t.width,l=t instanceof HTMLVideoElement?t.videoHeight:null==t?void 0:t.height;if(!s||!l){return null}const c=O();let u=1;"svg"===e.type&&(u=Math.max(e.width/s*r,e.height/l*r)),c.width=Math.max(s*u,1),c.height=Math.max(l*u,1);let g=n?-c.width:0,m=a?-c.height:0;return null===(o=c.getContext("2d"))||void 0===o||o.scale(n?-1:1,a?-1:1),null===(i=c.getContext("2d"))||void 0===i||i.drawImage(t,g,m,c.width,c.height),c},[e.flipX,e.flipY,t,e.width,e.height,r]);return o.useEffect(()=>()=>{i&&"CANVAS"===i.nodeName&&f.Util.releaseCanvas(i)},[i]),i})(i,J,d._elementsPixelRatio),ne=re&&oe||ie||D,[ae=D,de]=I(i,ne);o.useEffect(()=>{J&&d.history.ignore(()=>{i.set({duration:1e3*J.duration})})},[J]);const he=o.useMemo(X,[J]);o.useEffect(()=>{var e;if(!J){return}const t=d.animatedElementsIds,r=(!t.length||t.includes(i.id))&&d.isPlaying;if(!te||!r&&!q){return void J.pause()}q&&(J.muted=!1,J.currentTime=i.startTime*J.duration,Y(J).then(e=>{"refused"===e&&G(!1)}));const o=new f.Animation(()=>{Ce()},null===(e=N.current)||void 0===e?void 0:e.getLayer());o.start();const n=()=>{G(!1),J.currentTime=i.startTime*J.duration},a=()=>{J.currentTime>=i.endTime*J.duration&&(J.pause(),J.currentTime=i.startTime*J.duration,G(!1))};return J.addEventListener("ended",n),J.addEventListener("timeupdate",a),()=>{J.pause(),o.stop(),J.removeEventListener("ended",n),J.removeEventListener("timeupdate",a)}},[J,q,d.isPlaying,te]),o.useEffect(()=>{J&&(J.volume=i.volume)},[J,i.volume]),o.useEffect(()=>{J&&(J.playbackRate=i.speed,J.preservesPitch=!1)},[J,i.speed]);const se=o.useRef(null);o.useEffect(()=>{const e=a(i,()=>{var e,t;if(J){if(re&&oe){return Ce(),void d.currentTime}const r=d.animatedElementsIds;if(r.length&&!r.includes(i.id)){return}const o=d.activePage===i.page,n=d.currentTime>=i.page.startTime&&d.currentTime<i.page.startTime+i.page.duration,a=i.startTime*J.duration*1e3,h=J.duration*(i.endTime-i.startTime)*1e3,{start:s,end:l}=P(i.animations,i.page.duration),c=(d.currentTime||i.page.startTime)-i.page.startTime,u=n?A(d.currentTime,i.page.startTime,s,h,a,i.speed):0,g=u/1e3,m=n&&c>=s&&c<l;q||(J.muted=!m,m&&d.isPlaying&&o?J.paused?(J.currentTime=g,he.play(J)):Math.abs(1e3*J.currentTime-u)>500&&(J.currentTime=g):(he.reset(),J.paused||J.pause(),g!==J.currentTime&&(J.currentTime=g),!F(J)&&!d.isPlaying&&!se.current&&(se.current=w(`video ${i.id}`)))),Ce(),null===(t=null===(e=N.current)||void 0===e?void 0:e.getLayer())||void 0===t||t.batchDraw()}});return()=>{e(),se.current&&(se.current(),se.current=null)}},[d,J,re,oe,q]),o.useEffect(()=>{var e,t;if(!J){return}if(re){return null===(e=se.current)||void 0===e||e.call(se),void(se.current=null)}const r=()=>{var e,t,r;!F(J)&&(null===(e=i.page)||void 0===e?void 0:e._exportingOrRendering)||se.current&&(Ce(),null===(r=null===(t=N.current)||void 0===t?void 0:t.getLayer())||void 0===r||r.batchDraw(),se.current(),se.current=null)};let o;return(null===(t=i.page)||void 0===t?void 0:t._exportingOrRendering)&&(o=setInterval(r,20)),J.addEventListener("timeupdate",r),J.addEventListener("canplay",r),()=>{clearInterval(o),J.removeEventListener("timeupdate",r),J.removeEventListener("canplay",r)}},[null===(v=i.page)||void 0===v?void 0:v._exportingOrRendering,J,i.id,w,re]);let{cropX:le,cropY:ce,cropWidth:ue,cropHeight:ge}=i;"loaded"!==K&&(le=ce=0,ue=ge=1);const me=(fe=ae)instanceof HTMLVideoElement?fe.videoWidth:(null==fe?void 0:fe.width)||0;var fe;const pe=(e=>e instanceof HTMLVideoElement?e.videoHeight:(null==e?void 0:e.height)||0)(ae),ve=y({cropX:le,cropY:ce,cropWidth:ue,cropHeight:ge,width:i.width,height:i.height},{width:me,height:pe}),we=ve.width,xe=ve.height,Me="svg"===i.type,ye=null!==(x=i.cornerRadius)&&void 0!==x?x:0,[Ee,be]=useCornerRadiusAndCrop(i,ae,ve,d._elementsPixelRatio,ye,!0);let[Le,Te]=((e,t,r,i)=>{const n=(e=>{const[t,r]=o.useState(e);return o.useEffect(()=>{(async()=>{const o=await async function(e){if(!E.isSvgUrl(e)){return e}const t=await E.urlToString(e),r=E.fixSize(t);return E.svgToURL(r)}(e);o!==t&&r(o)})()},[e]),t})(e.clipSrc||""),[a,d]=m(n,"anonymous"),h=e.clipSrc?d:"loaded";useLoader(h,e.clipSrc,e.id);const s=o.useMemo(()=>{if(t&&a){return O()}},[t,a]);function l(){var o;if(!a){return}const i=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||!i||!n){return}if(!a||!a.width||!a.height){return}if(!s){return}const d=O(),h=Math.max(e.width/a.width*r,e.height/a.height*r);d.width=a.width*h,d.height=a.height*h,null===(o=d.getContext("2d"))||void 0===o||o.drawImage(a,0,0,d.width,d.height),s.width=Math.max(i,1),s.height=Math.max(n,1);const l=s.getContext("2d");l&&(l.save(),l.drawImage(d,0,0,i,n),f.Util.releaseCanvas(d),l.globalCompositeOperation="source-in",l.drawImage(t,0,0,s.width,s.height),l.restore())}return o.useLayoutEffect(()=>{l()},[s,t,a,e.width,e.height,r,...i]),[e.clipSrc&&a?s:t,l]})(i,Ee,d._elementsPixelRatio,[ve,ye,d._elementsPixelRatio]);const Ce=k(()=>{var e,t;de(),be(),Te(),null===(t=null===(e=N.current)||void 0===e?void 0:e.getLayer())||void 0===t||t.batchDraw()});o.useEffect(()=>{Ce()});const Se=Math.max(i.width/we,i.height/xe);o.useEffect(()=>{var e;if(!i._cropModeEnabled){return}const t=null===(e=N.current)||void 0===e?void 0:e.getStage();function r(e){i._cropModeEnabled&&e.target!==Z.current&&i.toggleCropMode(!1)}function o(e){i._cropModeEnabled&&e.target.parentNode!==(null==t?void 0:t.content)&&i.toggleCropMode(!1)}return document.body.addEventListener("click",o),null==t||t.on("click",r),null==t||t.on("tap",r),()=>{document.body.removeEventListener("click",o),document.body.removeEventListener("touchstart",o),null==t||t.off("click",r),null==t||t.off("click",r)}},[i._cropModeEnabled]);const Re=o.useRef(null),Ie=o.useRef(null),ke=o.useRef(null);o.useLayoutEffect(()=>{i._cropModeEnabled&&(Ie.current.nodes([Re.current]),ke.current.nodes([Z.current]))},[i._cropModeEnabled]);const He=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(),o=Math.min(1,we/t),n=Math.min(1,xe/r),a=1-o,d=Math.min(a,Math.max(0,Math.round(-e.target.x())/t)),h=1-n,s=Math.min(h,Math.max(0,Math.round(-e.target.y())/r));e.target.setAttrs({x:-d*me,y:-s*pe,scaleX:1,scaleY:1}),i.set({cropX:d,cropY:s,cropWidth:o,cropHeight:n})},We=()=>{"svg"!==i.type&&i.contentEditable&&setTimeout(()=>{n(i)&&i.toggleCropMode(!0)})},Xe="loading"===K,Ye="failed"===K,je=!Xe&&!Ye,Pe=o.useRef({cropX:0,cropY:0,cropWidth:0,cropHeight:0}),Ae=o.useRef(!1),Oe=je?i.a.opacity:0;H(N,Oe);const _e=i.selectable||d.role===g.ADMIN,Ve=W();return e(r,{children:t(h,{onMouseEnter:()=>ee(!0),onMouseLeave:()=>ee(!1),children:[Xe&&e(z,{element:i}),Ye&&e(U,{element:i}),e(s,{ref:N,name:"element",id:i.id,image:Le,x:i.a.x,y:i.a.y,width:i.a.width||1,height:i.a.height||1,rotation:i.a.rotation,opacity:Oe,shadowEnabled:i.shadowEnabled,shadowBlur:i.shadowBlur,shadowOffsetX:i.shadowOffsetX,shadowOffsetY:i.shadowOffsetY,shadowColor:i.shadowColor,shadowOpacity:i.shadowOpacity,customCrop:ve,listening:_e,draggable:Ve?i.draggable&&$:i.draggable,preventDefault:!Ve||$,hideInExport:!i.showInExport,onDragMove:e=>{i.set({x:e.target.x(),y:e.target.y()})},onDragEnd:e=>{i.set({x:e.target.x(),y:e.target.y()})},onDblClick:We,onDblTap:We,onTransformStart:e=>{b(!0),Ae.current=C(T(e.target)),Pe.current={cropX:i.cropX,cropY:i.cropY,cropWidth:i.cropWidth,cropHeight:i.cropHeight}},onTransform:e=>{const t=e.currentTarget,r=Math.abs(t.scaleX()-1)<1e-7?1:t.scaleX(),o=Math.abs(t.scaleY()-1)<1e-7?1:t.scaleY();t.scaleX(1),t.scaleY(1);const n=1-we/me,a=Math.min(n,Math.max(0,i.cropX)),d=1-xe/pe,h=Math.min(d,Math.max(0,i.cropY)),s=Ae.current,l=!s&&r<1&&Pe.current.cropHeight>xe/pe;let c=s?i.cropWidth:i.cropWidth*r;l&&(c=i.cropWidth);const u=!s&&o<1&&Pe.current.cropWidth>we/me;let g=s?i.cropHeight:i.cropHeight*o;u&&(g=i.cropHeight),Me&&(c=i.cropWidth,g=i.cropHeight);const m=s?Math.min(r,o):1;i.set(Object.assign({cropX:a,cropY:h,x:t.x(),y:t.y(),width:t.width()*r,height:t.height()*o,rotation:e.target.rotation(),cropWidth:Math.min(c,1-a),cropHeight:Math.min(g,1-h)},1!==m&&Object.assign(Object.assign({},S(i,m)),{borderSize:i.borderSize*m})))},onTransformEnd:e=>{const t=e.currentTarget;i.set(Object.assign(Object.assign({width:t.width(),height:t.height(),x:t.x(),y:t.y(),rotation:e.target.rotation(),cropWidth:we/me,cropHeight:xe/pe},R(i)),{borderSize:L(i.borderSize)})),b(!1)}}),e(l,{x:i.a.x,y:i.a.y,width:Math.max(i.a.width-i.borderSize,0),height:Math.max(i.a.height-i.borderSize,0),opacity:Oe,offsetX:-i.borderSize/2,offsetY:-i.borderSize/2,stroke:i.borderColor,strokeWidth:i.borderSize,listening:!1,visible:!!i.borderSize,rotation:i.rotation,cornerRadius:Math.max(0,ye-i.borderSize),hideInExport:!i.showInExport}),!d.isPlaying&&e(s,{image:q?Q||Ve?V:void 0:_,x:i.a.x,y:i.a.y,offsetX:-i.a.width/2+15/d.scale,offsetY:-i.a.height/2+15/d.scale,rotation:i.a.rotation,width:30/d.scale,height:30/d.scale,hideInExport:!0,onClick:()=>G(!q),onTap:()=>G(!q)}),i._cropModeEnabled&&t(p,{selector:".page-abs-container",enabled:!0,children:[e(l,{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(s,{listening:!1,image:Le,x:i.a.x,y:i.a.y,width:i.a.width,height:i.a.height,rotation:i.a.rotation,shadowEnabled:i.shadowEnabled,shadowBlur:i.shadowBlur}),t(h,{x:i.a.x,y:i.a.y,rotation:i.a.rotation,scaleX:Se,scaleY:Se,children:[e(s,{image:ae,ref:Z,width:me,height:pe,opacity:.4,draggable:!0,x:-i.cropX*me,y:-i.cropY*pe,onDragMove:He,onTransform:He}),e(u,{ref:ke,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(l,{width:we,height:xe,ref:Re,listening:!1,onTransform:e=>{e.target.x()<-i.cropX*me-1e-9&&(e.target.x(-i.cropX*me),e.target.scaleX(1)),e.target.y()<-i.cropY*pe-1e-9&&(e.target.y(-i.cropY*pe),e.target.scaleY(1));const t=Math.min(1,Math.max(0,i.cropX+e.target.x()/me)),r=Math.min(1,Math.max(0,e.target.y()/pe+i.cropY)),o=e.target.width()*e.target.scaleX(),n=e.target.height()*e.target.scaleY(),a=Math.min(1-t,o/me),d=Math.min(1-r,n/pe),h=e.target.getAbsolutePosition(e.target.getParent().getParent());e.target.scale({x:1,y:1}),e.target.position({x:0,y:0}),i.set({x:h.x,y:h.y,cropX:t,cropY:r,cropWidth:a,cropHeight:d,width:Math.min(o*Se,me*(1-t)*Se),height:Math.min(n*Se,pe*(1-r)*Se)})}}),e(u,{ref:Ie,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:i.resizable})]})]})]})})});
@@ -1632,6 +1632,7 @@ export declare const TYPES_MAP: {
1632
1632
  height: number;
1633
1633
  } | null;
1634
1634
  } & {
1635
+ set(attrs: any): void;
1635
1636
  setCellContentHeight(cellId: string, height: number): void;
1636
1637
  _applyFitRowsToContent(): void;
1637
1638
  focusCell(cellId: string, addToSelection?: boolean): void;
@@ -1661,18 +1662,7 @@ export declare const TYPES_MAP: {
1661
1662
  clone(attrs?: any, { skipSelect }?: {
1662
1663
  skipSelect?: boolean | undefined;
1663
1664
  }): any;
1664
- }, import("mobx-state-tree").ModelCreationType<{
1665
- id: string;
1666
- type: string | undefined;
1667
- name: string | undefined;
1668
- opacity: number | undefined;
1669
- custom: any;
1670
- visible: boolean | undefined;
1671
- selectable: boolean | undefined;
1672
- removable: boolean | undefined;
1673
- alwaysOnTop: boolean | undefined;
1674
- showInExport: boolean | undefined;
1675
- }>, any>;
1665
+ }, any, any>;
1676
1666
  };
1677
1667
  export declare function registerShapeModel(defaultAttributes: any, extendFunc?: any): void;
1678
1668
  export type GroupElementType = Instance<typeof GroupElement>;
@@ -1568,6 +1568,7 @@ export declare const Page: import("mobx-state-tree").IModelType<{
1568
1568
  height: number;
1569
1569
  } | null;
1570
1570
  } & {
1571
+ set(attrs: any): void;
1571
1572
  setCellContentHeight(cellId: string, height: number): void;
1572
1573
  _applyFitRowsToContent(): void;
1573
1574
  focusCell(cellId: string, addToSelection?: boolean): void;
@@ -1597,18 +1598,7 @@ export declare const Page: import("mobx-state-tree").IModelType<{
1597
1598
  clone(attrs?: any, { skipSelect }?: {
1598
1599
  skipSelect?: boolean | undefined;
1599
1600
  }): any;
1600
- }, import("mobx-state-tree").ModelCreationType<{
1601
- id: string;
1602
- type: string | undefined;
1603
- name: string | undefined;
1604
- opacity: number | undefined;
1605
- custom: any;
1606
- visible: boolean | undefined;
1607
- selectable: boolean | undefined;
1608
- removable: boolean | undefined;
1609
- alwaysOnTop: boolean | undefined;
1610
- showInExport: boolean | undefined;
1611
- }>, any>, any, ...(import("mobx-state-tree").ModelInstanceTypeProps<{
1601
+ }, any, any>, any, ...(import("mobx-state-tree").ModelInstanceTypeProps<{
1612
1602
  id: import("mobx-state-tree").ISimpleType<string>;
1613
1603
  type: import("mobx-state-tree").IType<string | undefined, string, string>;
1614
1604
  name: import("mobx-state-tree").IType<string | undefined, string, string>;
package/model/store.d.ts CHANGED
@@ -1617,6 +1617,7 @@ export declare const Store: import("mobx-state-tree").IModelType<{
1617
1617
  height: number;
1618
1618
  } | null;
1619
1619
  } & {
1620
+ set(attrs: any): void;
1620
1621
  setCellContentHeight(cellId: string, height: number): void;
1621
1622
  _applyFitRowsToContent(): void;
1622
1623
  focusCell(cellId: string, addToSelection?: boolean): void;
@@ -1646,18 +1647,7 @@ export declare const Store: import("mobx-state-tree").IModelType<{
1646
1647
  clone(attrs?: any, { skipSelect }?: {
1647
1648
  skipSelect?: boolean | undefined;
1648
1649
  }): any;
1649
- }, import("mobx-state-tree").ModelCreationType<{
1650
- id: string;
1651
- type: string | undefined;
1652
- name: string | undefined;
1653
- opacity: number | undefined;
1654
- custom: any;
1655
- visible: boolean | undefined;
1656
- selectable: boolean | undefined;
1657
- removable: boolean | undefined;
1658
- alwaysOnTop: boolean | undefined;
1659
- showInExport: boolean | undefined;
1660
- }>, any>, any, ...(import("mobx-state-tree").ModelInstanceTypeProps<{
1650
+ }, any, any>, any, ...(import("mobx-state-tree").ModelInstanceTypeProps<{
1661
1651
  id: import("mobx-state-tree").ISimpleType<string>;
1662
1652
  type: import("mobx-state-tree").IType<string | undefined, string, string>;
1663
1653
  name: import("mobx-state-tree").IType<string | undefined, string, string>;
@@ -3672,6 +3662,7 @@ export declare const Store: import("mobx-state-tree").IModelType<{
3672
3662
  height: number;
3673
3663
  } | null;
3674
3664
  } & {
3665
+ set(attrs: any): void;
3675
3666
  setCellContentHeight(cellId: string, height: number): void;
3676
3667
  _applyFitRowsToContent(): void;
3677
3668
  focusCell(cellId: string, addToSelection?: boolean): void;
@@ -3701,18 +3692,7 @@ export declare const Store: import("mobx-state-tree").IModelType<{
3701
3692
  clone(attrs?: any, { skipSelect }?: {
3702
3693
  skipSelect?: boolean | undefined;
3703
3694
  }): any;
3704
- }, import("mobx-state-tree").ModelCreationType<{
3705
- id: string;
3706
- type: string | undefined;
3707
- name: string | undefined;
3708
- opacity: number | undefined;
3709
- custom: any;
3710
- visible: boolean | undefined;
3711
- selectable: boolean | undefined;
3712
- removable: boolean | undefined;
3713
- alwaysOnTop: boolean | undefined;
3714
- showInExport: boolean | undefined;
3715
- }>, any>, any, ...(import("mobx-state-tree").ModelInstanceTypeProps<{
3695
+ }, any, any>, any, ...(import("mobx-state-tree").ModelInstanceTypeProps<{
3716
3696
  id: import("mobx-state-tree").ISimpleType<string>;
3717
3697
  type: import("mobx-state-tree").IType<string | undefined, string, string>;
3718
3698
  name: import("mobx-state-tree").IType<string | undefined, string, string>;
@@ -5636,6 +5616,7 @@ export declare const Store: import("mobx-state-tree").IModelType<{
5636
5616
  height: number;
5637
5617
  } | null;
5638
5618
  } & {
5619
+ set(attrs: any): void;
5639
5620
  setCellContentHeight(cellId: string, height: number): void;
5640
5621
  _applyFitRowsToContent(): void;
5641
5622
  focusCell(cellId: string, addToSelection?: boolean): void;
@@ -5665,18 +5646,7 @@ export declare const Store: import("mobx-state-tree").IModelType<{
5665
5646
  clone(attrs?: any, { skipSelect }?: {
5666
5647
  skipSelect?: boolean | undefined;
5667
5648
  }): any;
5668
- }, import("mobx-state-tree").ModelCreationType<{
5669
- id: string;
5670
- type: string | undefined;
5671
- name: string | undefined;
5672
- opacity: number | undefined;
5673
- custom: any;
5674
- visible: boolean | undefined;
5675
- selectable: boolean | undefined;
5676
- removable: boolean | undefined;
5677
- alwaysOnTop: boolean | undefined;
5678
- showInExport: boolean | undefined;
5679
- }>, any>, any, ...(import("mobx-state-tree").ModelInstanceTypeProps<{
5649
+ }, any, any>, any, ...(import("mobx-state-tree").ModelInstanceTypeProps<{
5680
5650
  id: import("mobx-state-tree").ISimpleType<string>;
5681
5651
  type: import("mobx-state-tree").IType<string | undefined, string, string>;
5682
5652
  name: import("mobx-state-tree").IType<string | undefined, string, string>;
@@ -7898,6 +7868,7 @@ export declare const Store: import("mobx-state-tree").IModelType<{
7898
7868
  height: number;
7899
7869
  } | null;
7900
7870
  } & {
7871
+ set(attrs: any): void;
7901
7872
  setCellContentHeight(cellId: string, height: number): void;
7902
7873
  _applyFitRowsToContent(): void;
7903
7874
  focusCell(cellId: string, addToSelection?: boolean): void;
@@ -7927,18 +7898,7 @@ export declare const Store: import("mobx-state-tree").IModelType<{
7927
7898
  clone(attrs?: any, { skipSelect }?: {
7928
7899
  skipSelect?: boolean | undefined;
7929
7900
  }): any;
7930
- }, import("mobx-state-tree").ModelCreationType<{
7931
- id: string;
7932
- type: string | undefined;
7933
- name: string | undefined;
7934
- opacity: number | undefined;
7935
- custom: any;
7936
- visible: boolean | undefined;
7937
- selectable: boolean | undefined;
7938
- removable: boolean | undefined;
7939
- alwaysOnTop: boolean | undefined;
7940
- showInExport: boolean | undefined;
7941
- }>, any>, any, ...(import("mobx-state-tree").ModelInstanceTypeProps<{
7901
+ }, any, any>, any, ...(import("mobx-state-tree").ModelInstanceTypeProps<{
7942
7902
  id: import("mobx-state-tree").ISimpleType<string>;
7943
7903
  type: import("mobx-state-tree").IType<string | undefined, string, string>;
7944
7904
  name: import("mobx-state-tree").IType<string | undefined, string, string>;
@@ -9862,6 +9822,7 @@ export declare const Store: import("mobx-state-tree").IModelType<{
9862
9822
  height: number;
9863
9823
  } | null;
9864
9824
  } & {
9825
+ set(attrs: any): void;
9865
9826
  setCellContentHeight(cellId: string, height: number): void;
9866
9827
  _applyFitRowsToContent(): void;
9867
9828
  focusCell(cellId: string, addToSelection?: boolean): void;
@@ -9891,18 +9852,7 @@ export declare const Store: import("mobx-state-tree").IModelType<{
9891
9852
  clone(attrs?: any, { skipSelect }?: {
9892
9853
  skipSelect?: boolean | undefined;
9893
9854
  }): any;
9894
- }, import("mobx-state-tree").ModelCreationType<{
9895
- id: string;
9896
- type: string | undefined;
9897
- name: string | undefined;
9898
- opacity: number | undefined;
9899
- custom: any;
9900
- visible: boolean | undefined;
9901
- selectable: boolean | undefined;
9902
- removable: boolean | undefined;
9903
- alwaysOnTop: boolean | undefined;
9904
- showInExport: boolean | undefined;
9905
- }>, any>, any, ...(import("mobx-state-tree").ModelInstanceTypeProps<{
9855
+ }, any, any>, any, ...(import("mobx-state-tree").ModelInstanceTypeProps<{
9906
9856
  id: import("mobx-state-tree").ISimpleType<string>;
9907
9857
  type: import("mobx-state-tree").IType<string | undefined, string, string>;
9908
9858
  name: import("mobx-state-tree").IType<string | undefined, string, string>;
@@ -11827,6 +11777,7 @@ export declare const Store: import("mobx-state-tree").IModelType<{
11827
11777
  height: number;
11828
11778
  } | null;
11829
11779
  } & {
11780
+ set(attrs: any): void;
11830
11781
  setCellContentHeight(cellId: string, height: number): void;
11831
11782
  _applyFitRowsToContent(): void;
11832
11783
  focusCell(cellId: string, addToSelection?: boolean): void;
@@ -11856,18 +11807,7 @@ export declare const Store: import("mobx-state-tree").IModelType<{
11856
11807
  clone(attrs?: any, { skipSelect }?: {
11857
11808
  skipSelect?: boolean | undefined;
11858
11809
  }): any;
11859
- }, import("mobx-state-tree").ModelCreationType<{
11860
- id: string;
11861
- type: string | undefined;
11862
- name: string | undefined;
11863
- opacity: number | undefined;
11864
- custom: any;
11865
- visible: boolean | undefined;
11866
- selectable: boolean | undefined;
11867
- removable: boolean | undefined;
11868
- alwaysOnTop: boolean | undefined;
11869
- showInExport: boolean | undefined;
11870
- }>, any>, any, ...(import("mobx-state-tree").ModelInstanceTypeProps<{
11810
+ }, any, any>, any, ...(import("mobx-state-tree").ModelInstanceTypeProps<{
11871
11811
  id: import("mobx-state-tree").ISimpleType<string>;
11872
11812
  type: import("mobx-state-tree").IType<string | undefined, string, string>;
11873
11813
  name: import("mobx-state-tree").IType<string | undefined, string, string>;
@@ -13791,6 +13731,7 @@ export declare const Store: import("mobx-state-tree").IModelType<{
13791
13731
  height: number;
13792
13732
  } | null;
13793
13733
  } & {
13734
+ set(attrs: any): void;
13794
13735
  setCellContentHeight(cellId: string, height: number): void;
13795
13736
  _applyFitRowsToContent(): void;
13796
13737
  focusCell(cellId: string, addToSelection?: boolean): void;
@@ -13820,18 +13761,7 @@ export declare const Store: import("mobx-state-tree").IModelType<{
13820
13761
  clone(attrs?: any, { skipSelect }?: {
13821
13762
  skipSelect?: boolean | undefined;
13822
13763
  }): any;
13823
- }, import("mobx-state-tree").ModelCreationType<{
13824
- id: string;
13825
- type: string | undefined;
13826
- name: string | undefined;
13827
- opacity: number | undefined;
13828
- custom: any;
13829
- visible: boolean | undefined;
13830
- selectable: boolean | undefined;
13831
- removable: boolean | undefined;
13832
- alwaysOnTop: boolean | undefined;
13833
- showInExport: boolean | undefined;
13834
- }>, any>, any, ...(import("mobx-state-tree").ModelInstanceTypeProps<{
13764
+ }, any, any>, any, ...(import("mobx-state-tree").ModelInstanceTypeProps<{
13835
13765
  id: import("mobx-state-tree").ISimpleType<string>;
13836
13766
  type: import("mobx-state-tree").IType<string | undefined, string, string>;
13837
13767
  name: import("mobx-state-tree").IType<string | undefined, string, string>;
@@ -15793,6 +15723,7 @@ export declare const Store: import("mobx-state-tree").IModelType<{
15793
15723
  height: number;
15794
15724
  } | null;
15795
15725
  } & {
15726
+ set(attrs: any): void;
15796
15727
  setCellContentHeight(cellId: string, height: number): void;
15797
15728
  _applyFitRowsToContent(): void;
15798
15729
  focusCell(cellId: string, addToSelection?: boolean): void;
@@ -15822,18 +15753,7 @@ export declare const Store: import("mobx-state-tree").IModelType<{
15822
15753
  clone(attrs?: any, { skipSelect }?: {
15823
15754
  skipSelect?: boolean | undefined;
15824
15755
  }): any;
15825
- }, import("mobx-state-tree").ModelCreationType<{
15826
- id: string;
15827
- type: string | undefined;
15828
- name: string | undefined;
15829
- opacity: number | undefined;
15830
- custom: any;
15831
- visible: boolean | undefined;
15832
- selectable: boolean | undefined;
15833
- removable: boolean | undefined;
15834
- alwaysOnTop: boolean | undefined;
15835
- showInExport: boolean | undefined;
15836
- }>, any>, any, ...(import("mobx-state-tree").ModelInstanceTypeProps<{
15756
+ }, any, any>, any, ...(import("mobx-state-tree").ModelInstanceTypeProps<{
15837
15757
  id: import("mobx-state-tree").ISimpleType<string>;
15838
15758
  type: import("mobx-state-tree").IType<string | undefined, string, string>;
15839
15759
  name: import("mobx-state-tree").IType<string | undefined, string, string>;
@@ -17757,6 +17677,7 @@ export declare const Store: import("mobx-state-tree").IModelType<{
17757
17677
  height: number;
17758
17678
  } | null;
17759
17679
  } & {
17680
+ set(attrs: any): void;
17760
17681
  setCellContentHeight(cellId: string, height: number): void;
17761
17682
  _applyFitRowsToContent(): void;
17762
17683
  focusCell(cellId: string, addToSelection?: boolean): void;
@@ -17786,18 +17707,7 @@ export declare const Store: import("mobx-state-tree").IModelType<{
17786
17707
  clone(attrs?: any, { skipSelect }?: {
17787
17708
  skipSelect?: boolean | undefined;
17788
17709
  }): any;
17789
- }, import("mobx-state-tree").ModelCreationType<{
17790
- id: string;
17791
- type: string | undefined;
17792
- name: string | undefined;
17793
- opacity: number | undefined;
17794
- custom: any;
17795
- visible: boolean | undefined;
17796
- selectable: boolean | undefined;
17797
- removable: boolean | undefined;
17798
- alwaysOnTop: boolean | undefined;
17799
- showInExport: boolean | undefined;
17800
- }>, any>, any, ...(import("mobx-state-tree").ModelInstanceTypeProps<{
17710
+ }, any, any>, any, ...(import("mobx-state-tree").ModelInstanceTypeProps<{
17801
17711
  id: import("mobx-state-tree").ISimpleType<string>;
17802
17712
  type: import("mobx-state-tree").IType<string | undefined, string, string>;
17803
17713
  name: import("mobx-state-tree").IType<string | undefined, string, string>;
@@ -471,6 +471,7 @@ export declare const TableElement: import("mobx-state-tree").IModelType<{
471
471
  height: number;
472
472
  } | null;
473
473
  } & {
474
+ set(attrs: any): void;
474
475
  setCellContentHeight(cellId: string, height: number): void;
475
476
  _applyFitRowsToContent(): void;
476
477
  focusCell(cellId: string, addToSelection?: boolean): void;
@@ -500,16 +501,5 @@ export declare const TableElement: import("mobx-state-tree").IModelType<{
500
501
  clone(attrs?: any, { skipSelect }?: {
501
502
  skipSelect?: boolean | undefined;
502
503
  }): any;
503
- }, import("mobx-state-tree").ModelCreationType<{
504
- id: string;
505
- type: string | undefined;
506
- name: string | undefined;
507
- opacity: number | undefined;
508
- custom: any;
509
- visible: boolean | undefined;
510
- selectable: boolean | undefined;
511
- removable: boolean | undefined;
512
- alwaysOnTop: boolean | undefined;
513
- showInExport: boolean | undefined;
514
- }>, any>;
504
+ }, any, any>;
515
505
  export type TableElementType = Instance<typeof TableElement>;
@@ -1 +1 @@
1
- import{types as e,getParent as t,getSnapshot as o,isAlive as l,getRoot as r,cast as n}from"mobx-state-tree";import{observable as s}from"mobx";import{nanoid as i}from"nanoid";import{TABLE_CELL_OVERRIDABLE_KEYS as c}from"@polotno/schema/defaults";import{Shape as d}from"./shape-model.js";const a=.05,g=e.enumeration(["solid","dashed","dotted","none"]);function h(e){return t(e,2)}function u(e,t,o){const r=e[`_${t}`];return null!=r?r:l(e)?h(e)[t]:o}function f(e){return t(e,1)}const b=e.model("BorderSide",{color:e.maybe(e.string),width:e.maybe(e.number),style:e.maybe(g)}).postProcessSnapshot(e=>{const t={};for(const[o,l]of Object.entries(e)){null!=l&&(t[o]=l)}return t}),w=e.model("CellBorders",{top:e.maybe(b),right:e.maybe(b),bottom:e.maybe(b),left:e.maybe(b)}).postProcessSnapshot(e=>{const t={};for(const[o,l]of Object.entries(e)){null!=l&&"object"==typeof l&&Object.keys(l).length>0&&(t[o]=l)}return t}),m=c,p=new Set(m),C=["blurEnabled","blurRadius","brightnessEnabled","brightness","sepiaEnabled","grayscaleEnabled","filters","shadowEnabled","shadowBlur","shadowOffsetX","shadowOffsetY","shadowColor","shadowOpacity"],_=["id","type","text","opacity","rowSpan","colSpan","mergedInto","name","custom","borders"],y=new Set(["row","col","x","y","width","height","rotation","draggable","resizable","selectable","removable","contentEditable","visible","showInExport","alwaysOnTop","backgroundEnabled","backgroundOpacity","backgroundColor","backgroundCornerRadius","backgroundPadding","curveEnabled","curvePower","shadowEnabled","shadowBlur","shadowOffsetX","shadowOffsetY","shadowColor","shadowOpacity","blurEnabled","blurRadius","brightnessEnabled","brightness","sepiaEnabled","grayscaleEnabled","placeholder","animations","filters"]),v={opacity:1,rowSpan:1,colSpan:1,name:""},I=[];export const TableCell=e.model("TableCell",{id:e.identifier,type:e.optional(e.literal("tablecell"),"tablecell"),text:"",_fontSize:e.maybe(e.number),_fontFamily:e.maybe(e.string),_fontWeight:e.maybe(e.string),_fontStyle:e.maybe(e.string),_textDecoration:e.maybe(e.string),_textTransform:e.maybe(e.string),_fill:e.maybe(e.string),_align:e.maybe(e.string),_verticalAlign:e.maybe(e.string),_lineHeight:e.maybe(e.union(e.number,e.string)),_letterSpacing:e.maybe(e.number),_strokeWidth:e.maybe(e.number),_stroke:e.maybe(e.string),_cellBackground:e.maybe(e.string),_cellPadding:e.maybe(e.number),opacity:1,rowSpan:1,colSpan:1,mergedInto:e.maybe(e.string),borders:e.maybe(w),name:"",custom:e.frozen()}).volatile(()=>({_editModeEnabled:!1,filters:s.map()})).preProcessSnapshot(e=>{if(!e){return e}for(const o in e){null===e[o]&&(e[o]=void 0)}const t={};for(const o of _){o in e&&(t[o]=e[o])}for(const o of m){void 0!==e[o]&&(t[`_${o}`]=e[o])}return t}).postProcessSnapshot(e=>{const t={};for(const[o,l]of Object.entries(e)){if(o.startsWith("_")){null!=l&&(t[o.slice(1)]=l)}else if("borders"===o){null!=l&&"object"==typeof l&&Object.keys(l).length>0&&(t.borders=l)}else{if(o in v&&l===v[o]){continue}t[o]=l}}return t}).views(e=>{const t={get row(){if(!l(e)){return 0}const t=h(e),o=f(e).indexOf(e);return-1===o?0:Math.floor(o/t.cols)},get col(){if(!l(e)){return 0}const t=h(e),o=f(e).indexOf(e);return-1===o?0:o%t.cols},get store(){return l(e)?r(e):null},get page(){if(!l(e)){return null}try{return h(e).page}catch(t){return null}},get fontSize(){return u(e,"fontSize",30)},get fontFamily(){return u(e,"fontFamily","Roboto")},get fontWeight(){return u(e,"fontWeight","normal")},get fontStyle(){return u(e,"fontStyle","normal")},get textDecoration(){return u(e,"textDecoration","")},get textTransform(){return u(e,"textTransform","none")},get fill(){return u(e,"fill","black")},get align(){return u(e,"align","left")},get verticalAlign(){return u(e,"verticalAlign","top")},get lineHeight(){return u(e,"lineHeight",1.2)},get letterSpacing(){return u(e,"letterSpacing",0)},get strokeWidth(){return u(e,"strokeWidth",0)},get stroke(){return u(e,"stroke","black")},get cellBackground(){return u(e,"cellBackground","transparent")},get cellPadding(){return u(e,"cellPadding",4)},get width(){if(!l(e)){return 100}try{return h(e).getCellRect(t.row,t.col,e.rowSpan,e.colSpan).width}catch(o){return 100}},get height(){if(!l(e)){return 100}try{return h(e).getCellRect(t.row,t.col,e.rowSpan,e.colSpan).height}catch(o){return 100}},get borderInsets(){if(!l(e)){return{top:0,right:0,bottom:0,left:0}}const o=h(e),r=(e,o)=>{const l=t.getEffectiveBorder(e);return"none"===l.style||0===l.width?0:o?l.width:l.width/2};return{top:r("top",0===t.row),bottom:r("bottom",t.row+e.rowSpan===o.rows),left:r("left",0===t.col),right:r("right",t.col+e.colSpan===o.cols)}},get a(){var o;if(!l(e)){return{x:0,y:0,width:100,height:100,rotation:0,opacity:1,fontSize:16}}const r=h(e).getCellRect(t.row,t.col,e.rowSpan,e.colSpan),n=t.cellPadding,{top:s,right:i,bottom:c,left:d}=t.borderInsets;return{x:r.x+d+n,y:r.y+s+n,width:Math.max(0,r.width-d-i-2*n),height:Math.max(0,r.height-s-c-2*n),rotation:0,opacity:null!==(o=e.opacity)&&void 0!==o?o:1,fontSize:t.fontSize}},getEffectiveBorder(t){var o,r,n,s,i,c,d;const a=l(e)?h(e):null,g=null===(o=e.borders)||void 0===o?void 0:o[t];return{color:null!==(n=null!==(r=null==g?void 0:g.color)&&void 0!==r?r:null==a?void 0:a.borderColor)&&void 0!==n?n:"#000000",width:null!==(i=null!==(s=null==g?void 0:g.width)&&void 0!==s?s:null==a?void 0:a.borderWidth)&&void 0!==i?i:1,style:null!==(d=null!==(c=null==g?void 0:g.style)&&void 0!==c?c:null==a?void 0:a.borderStyle)&&void 0!==d?d:"solid"}},get x(){return 0},get y(){return 0},get rotation(){return 0},get draggable(){return!1},get resizable(){return!1},get selectable(){return!1},get removable(){return!1},get contentEditable(){return!0},get visible(){return!0},get showInExport(){return!0},get alwaysOnTop(){return!1},get placeholder(){return""},get backgroundEnabled(){return!1},get backgroundOpacity(){return 1},get backgroundColor(){return"transparent"},get backgroundCornerRadius(){return 0},get backgroundPadding(){return 0},get curveEnabled(){return!1},get curvePower(){return 0},get shadowEnabled(){return!1},get shadowBlur(){return 0},get shadowOffsetX(){return 0},get shadowOffsetY(){return 0},get shadowColor(){return"black"},get shadowOpacity(){return 1},get blurEnabled(){return!1},get blurRadius(){return 0},get brightnessEnabled(){return!1},get brightness(){return 0},get sepiaEnabled(){return!1},get grayscaleEnabled(){return!1},get animations(){return I}};return t}).actions(e=>({toJSON:()=>Object.assign({},o(e)),set(t){null!=t.fontSize&&t.fontSize<1&&(t=Object.assign(Object.assign({},t),{fontSize:1}));const o={};for(const[e,l]of Object.entries(t)){p.has(e)?o[`_${e}`]=l:"borders"===e?o.borders=l?JSON.parse(JSON.stringify(l)):l:y.has(e)||(o[e]=l)}Object.assign(e,o)},setBorder(t,l){const r=e.borders?Object.assign({},o(e.borders)):{},s=r[t]||{},i=Object.assign({},s);void 0!==l.color&&(i.color=l.color),void 0!==l.width&&(i.width=l.width),void 0!==l.style&&(i.style=l.style),r[t]=i,e.borders=n(r)},toggleEditMode(t){const o=null!=t?t:!e._editModeEnabled;o!==e._editModeEnabled&&(e._editModeEnabled=o,e._editModeEnabled?e.store.history.startTransaction():e.store.history.endTransaction())},beforeDestroy(){e._editModeEnabled&&e.store.history.endTransaction()}}));function H(e,t){const l=[];for(const r of e){const e={id:i(10),text:""};if(!r){l.push(e);continue}for(const t of m){const o=r[`_${t}`];null!=o&&(e[t]=o)}const n=r.borders;if(n){const l={},r=t?["left","right","top"]:["top","bottom","left"];for(const e of r){const t=n[e];t&&(l[e]=o(t))}Object.keys(l).length>0&&(e.borders=l)}l.push(e)}return l}function R(e){return Array.from({length:e},()=>1/e)}function S(e){const t=e.reduce((e,t)=>e+t,0);return 0===t?R(e.length):e.map(e=>e/t)}export const TableElement=d.named("Table").props({type:"table",width:300,height:200,rows:3,cols:3,colWidths:e.array(e.number),rowHeights:e.array(e.number),cells:e.array(TableCell),borderColor:"#000000",borderWidth:1,borderStyle:e.optional(e.enumeration(["solid","dashed","dotted","none"]),"solid"),fontSize:30,fontFamily:"Roboto",fontWeight:"normal",fontStyle:"normal",textDecoration:"",textTransform:"none",fill:"black",align:"center",verticalAlign:"middle",lineHeight:e.optional(e.union(e.number,e.string),1.2),letterSpacing:0,strokeWidth:0,stroke:"black",cellBackground:"transparent",cellPadding:4}).postProcessSnapshot(e=>{e.cells&&((e=Object.assign({},e)).cells=e.cells.map(t=>{const o={};for(const[l,r]of Object.entries(t)){p.has(l)&&r===e[l]||(o[l]=r)}return o}));for(const t of C){delete e[t]}return e}).volatile(()=>({_focusedCellIds:[],_editingCellId:void 0,_anchorCellId:void 0,_cellContentHeights:s.map(),_baseRowHeights:null,_baseHeight:null})).actions(e=>({afterCreate(){const t=e.rows*e.cols;if(0===e.cells.length){e.cells.replace(function(e,t){const o=[];for(let l=0;l<e*t;l++){o.push({id:i(10),text:""})}return o}(e.rows,e.cols))}else if(e.cells.length<t){for(;e.cells.length<t;){e.cells.push(n({id:i(10),text:""}))}}else{e.cells.length>t&&e.cells.splice(t)}0===e.colWidths.length&&e.colWidths.replace(R(e.cols)),0===e.rowHeights.length&&e.rowHeights.replace(R(e.rows))}})).views(e=>({get _cellMap(){const t=new Map,o=e.cols;return e.cells.forEach((e,l)=>{t.set(`${Math.floor(l/o)}:${l%o}`,e)}),t},getActualRowHeight:t=>e.rowHeights[t]*e.height})).views(e=>{const t={getCell:(t,o)=>e._cellMap.get(`${t}:${o}`),get minWidth(){return 20*e.cols},getRowContentOuterHeight(o){let l=0;for(let r=0;r<e.cols;r++){const n=t.getCell(o,r);if(!n){continue}const s=e._cellContentHeights.get(n.id);if(void 0===s){continue}const i=n.borderInsets,c=s+2*n.cellPadding+i.top+i.bottom;c>l&&(l=c)}return l},get minHeight(){const o=20*e.rows;if(0===e._cellContentHeights.size){return o}let l=0;for(let r=0;r<e.rows;r++){l+=t.getRowContentOuterHeight(r)}return Math.max(o,l)},get actualHeight(){let t=0;for(let o=0;o<e.rows;o++){t+=e.getActualRowHeight(o)}return t},getCellRect(t,o,l=1,r=1){let n=0;for(let d=0;d<o;d++){n+=e.colWidths[d]*e.width}let s=0;for(let d=0;d<t;d++){s+=e.getActualRowHeight(d)}let i=0;for(let d=o;d<o+r;d++){i+=(e.colWidths[d]||0)*e.width}let c=0;for(let d=t;d<t+l;d++){c+=e.getActualRowHeight(d)}return{x:n,y:s,width:i,height:c}},get visibleCells(){return e.cells.filter(e=>!e.mergedInto)},get focusedCells(){return e.cells.filter(t=>e._focusedCellIds.includes(t.id))},get editingCell(){if(e._editingCellId){return e.cells.find(t=>t.id===e._editingCellId)}},getFocusedCellRange(){if(0===e._focusedCellIds.length){return null}let t=1/0,o=-1/0,l=1/0,r=-1/0;const n=new Set(e._focusedCellIds);for(const s of e.cells){n.has(s.id)&&(s.row<t&&(t=s.row),s.row>o&&(o=s.row),s.col<l&&(l=s.col),s.col>r&&(r=s.col))}return t===1/0?null:{minRow:t,maxRow:o,minCol:l,maxCol:r}},get _fitRowsToContent(){var o,l;if(0===e._cellContentHeights.size){return null}const r=null!==(o=e._baseHeight)&&void 0!==o?o:e.height,n=null!==(l=e._baseRowHeights)&&void 0!==l?l:[...e.rowHeights];let s=!1;const i=[];for(let d=0;d<e.rows;d++){const o=e.rowHeights[d]*e.height,l=n[d]*r,c=t.getRowContentOuterHeight(d),a=Math.max(c,l);Math.abs(a-o)>1?(i.push(a),s=!0):i.push(o)}if(!s){return null}const c=i.reduce((e,t)=>e+t,0);return{rowHeights:i.map(e=>e/c),height:c}}};return t}).actions(e=>{const t={setCellContentHeight(t,o){e._cellContentHeights.set(t,o)},_applyFitRowsToContent(){if(!l(e)){return}null===e._baseRowHeights&&(e._baseRowHeights=[...e.rowHeights],e._baseHeight=e.height);const t=e._fitRowsToContent;t&&(e.height=t.height,e.rowHeights.replace(t.rowHeights))},focusCell(t,o=!1){o?e._focusedCellIds.includes(t)||(e._focusedCellIds=[...e._focusedCellIds,t]):(e._focusedCellIds=[t],e._anchorCellId=t)},selectRowRange(t,o){const l=Math.max(0,Math.min(t,o)),r=Math.min(e.rows-1,Math.max(t,o)),n=[];for(let s=l;s<=r;s++){for(let t=0;t<e.cols;t++){const o=e.getCell(s,t);o&&n.push(o.id)}}e._focusedCellIds=n,e._anchorCellId=n[0]},selectColumnRange(t,o){const l=Math.max(0,Math.min(t,o)),r=Math.min(e.cols-1,Math.max(t,o)),n=[];for(let s=0;s<e.rows;s++){for(let t=l;t<=r;t++){const o=e.getCell(s,t);o&&n.push(o.id)}}e._focusedCellIds=n,e._anchorCellId=n[0]},selectRow(e){t.selectRowRange(e,e)},selectColumn(e){t.selectColumnRange(e,e)},focusCellRange(t,o){const l=e.cells.find(t=>t.id===e._anchorCellId);if(!l){return}const r=Math.min(l.row,t),n=Math.max(l.row,t),s=Math.min(l.col,o),i=Math.max(l.col,o),c=[];for(const d of e.cells){d.row>=r&&d.row<=n&&d.col>=s&&d.col<=i&&c.push(d.id)}e._focusedCellIds=c},clearCellFocus(){if(l(e)){if(e._editingCellId){const t=e.cells.find(t=>t.id===e._editingCellId);t&&t.toggleEditMode(!1)}e._focusedCellIds=[],e._editingCellId=void 0,e._anchorCellId=void 0}},enterCellEdit(t){e._editingCellId=t,e._focusedCellIds.includes(t)||(e._focusedCellIds=[t]);const o=e.cells.find(e=>e.id===t);o&&o.toggleEditMode(!0)},exitCellEdit(){if(e._editingCellId){const t=e.cells.find(t=>t.id===e._editingCellId);t&&t.toggleEditMode(!1)}e._editingCellId=void 0},_resetBaseRowHeights(){e._baseRowHeights=null,e._baseHeight=null},setHeightRedistribute(t){const o=e.rows;if(0===o||t<=0){return void(e.height=t)}const l=e.height;if(l<=0||t>=l){return void(e.height=t)}const r=[],n=[];let s=0;for(let h=0;h<o;h++){r.push(e.rowHeights[h]*l);const t=e.getRowContentOuterHeight(h);n.push(t),s+=t}if(t<=s||s<=0){return void(e.height=t)}const i=t-s;let c=0;const d=[];for(let e=0;e<o;e++){const t=Math.max(0,r[e]-n[e]);d.push(t),c+=t}const a=[];if(c<=0){const e=t/l;for(let t=0;t<o;t++){a.push(r[t]*e)}}else{for(let e=0;e<o;e++){a.push(n[e]+d[e]/c*i)}}const g=a.map(e=>e/t);e.height=t,e.rowHeights.replace(g)},addRow(o){t._resetBaseRowHeights();const l=o>0?o-1:0,r=(e.rowHeights[l]||1/(e.rows+1))*e.height,n=e.height+r,s=[];for(let t=0;t<e.rows;t++){s.push(e.rowHeights[t]*e.height/n)}s.splice(o,0,r/n);const i=o>0?o-1:0,c=[];for(let t=0;t<e.cols;t++){c.push(e.cells[i*e.cols+t])}const d=o*e.cols,a=H(c,!0);e.cells.splice(d,0,...a),e.rows+=1,e.height=n,e.rowHeights.replace(S(s))},removeRow(o){if(e.rows<=1){return}t._resetBaseRowHeights();const l=o*e.cols,r=[];for(let t=l;t<l+e.cols;t++){r.push(e.cells[t].id)}if(e._editingCellId&&r.includes(e._editingCellId)){const t=e.cells.find(t=>t.id===e._editingCellId);t&&t.toggleEditMode(!1),e._editingCellId=void 0}e._focusedCellIds=e._focusedCellIds.filter(e=>!r.includes(e)),r.forEach(t=>e._cellContentHeights.delete(t)),e.cells.splice(l,e.cols);const n=[...e.rowHeights];n.splice(o,1),e.rows-=1,e.rowHeights.replace(S(n))},addColumn(t){const o=t>0?t-1:0,l=(e.colWidths[o]||1/(e.cols+1))*e.width,r=e.width+l,s=[];for(let n=0;n<e.cols;n++){s.push(e.colWidths[n]*e.width/r)}s.splice(t,0,l/r);const i=e.cols,c=t>0?t-1:0,d=[];for(let n=0;n<e.rows;n++){d.push(e.cells[n*i+c])}const a=H(d,!1);for(let g=e.rows-1;g>=0;g--){e.cells.splice(g*i+t,0,n(a[g]))}e.cols+=1,e.width=r,e.colWidths.replace(S(s))},removeColumn(t){if(e.cols<=1){return}const o=e.cols,l=[];for(let n=0;n<e.rows;n++){l.push(e.cells[n*o+t].id)}if(e._editingCellId&&l.includes(e._editingCellId)){const t=e.cells.find(t=>t.id===e._editingCellId);t&&t.toggleEditMode(!1),e._editingCellId=void 0}e._focusedCellIds=e._focusedCellIds.filter(e=>!l.includes(e)),l.forEach(t=>e._cellContentHeights.delete(t));for(let n=e.rows-1;n>=0;n--){e.cells.splice(n*o+t,1)}const r=[...e.colWidths];r.splice(t,1),e.cols-=1,e.colWidths.replace(S(r))},removeRowRange(o,l){for(let r=l;r>=o&&!(e.rows<=1);r--){t.removeRow(r)}},removeColumnRange(o,l){for(let r=l;r>=o&&!(e.cols<=1);r--){t.removeColumn(r)}},distributeRowsEvenly(){const o=e.rows;let l=20;for(let t=0;t<o;t++){l=Math.max(l,e.getRowContentOuterHeight(t))}t._resetBaseRowHeights(),e.height=Math.max(e.height,l*o),e.rowHeights.replace(R(o))},distributeColumnsEvenly(){e.colWidths.replace(R(e.cols))},resizeColumn(t,o){if(t>=e.cols-1){return}const l=[...e.colWidths],r=l[t]+l[t+1],n=l[t]+o,s=l[t+1]-o;n<a?(l[t]=a,l[t+1]=r-a):s<a?(l[t+1]=a,l[t]=r-a):(l[t]=n,l[t+1]=s),e.colWidths.replace(l)},resizeRow(t,o){if(t>=e.rows-1){return}const l=[...e.rowHeights],r=l[t]+l[t+1],n=e.height,s=n>0?e.getRowContentOuterHeight(t)/n:0,i=n>0?e.getRowContentOuterHeight(t+1)/n:0,c=Math.max(a,s),d=Math.max(a,i),g=l[t]+o,h=l[t+1]-o;g<c?(l[t]=c,l[t+1]=r-c):h<d?(l[t+1]=d,l[t]=r-d):(l[t]=g,l[t+1]=h),e.rowHeights.replace(l)},setCellBorders(t,o,l){const r={top:{side:"bottom",dr:-1,dc:0},bottom:{side:"top",dr:1,dc:0},left:{side:"right",dr:0,dc:-1},right:{side:"left",dr:0,dc:1}};for(const n of t){const t=e.cells.find(e=>e.id===n);if(t){for(const n of o){t.setBorder(n,l);const o=r[n],s=t.row+o.dr,i=t.col+o.dc,c=e.getCell(s,i);c&&c.setBorder(o.side,l)}}}},applyBorderMode(o,l){var r;const n=function(e,t,o){const{minRow:l,maxRow:r,minCol:n,maxCol:s}=t,i=(e,t,l,r)=>{const n=[];for(let s=e;s<=t;s++){for(let e=l;e<=r;e++){const t=o(s,e);t&&n.push(t.id)}}return n};if("all"===e){return[{cellIds:i(l,r,n,s),sides:["top","right","bottom","left"]}]}const c=[],d="outer"===e||"topOnly"===e||"topBottom"===e,a="outer"===e||"bottomOnly"===e||"topBottom"===e,g="outer"===e||"leftOnly"===e,h="outer"===e||"rightOnly"===e;if(d){const e=i(l,l,n,s);e.length&&c.push({cellIds:e,sides:["top"]})}if(a){const e=i(r,r,n,s);e.length&&c.push({cellIds:e,sides:["bottom"]})}if(g){const e=i(l,r,n,n);e.length&&c.push({cellIds:e,sides:["left"]})}if(h){const e=i(l,r,s,s);e.length&&c.push({cellIds:e,sides:["right"]})}if(d||a||g||h){return c}if(("inner"===e||"innerHorizontal"===e)&&r>l){const e=i(l,r-1,n,s);e.length&&c.push({cellIds:e,sides:["bottom"]})}if(("inner"===e||"innerVertical"===e)&&s>n){const e=i(l,r,n,s-1);e.length&&c.push({cellIds:e,sides:["right"]})}return c}(o,null!==(r=e.getFocusedCellRange())&&void 0!==r?r:{minRow:0,maxRow:e.rows-1,minCol:0,maxCol:e.cols-1},(t,o)=>e.getCell(t,o));for(const{cellIds:e,sides:s}of n){t.setCellBorders(e,s,l)}}};return t}).actions(e=>({clone(t={},{skipSelect:o=!1}={}){const l=JSON.parse(JSON.stringify(e.toJSON()));if(t.id=t.id||i(10),l.cells){const e=new Map;l.cells.forEach(t=>{const o=t.id,l=i(10);e.set(o,l),t.id=l}),l.cells.forEach(t=>{t.mergedInto&&e.has(t.mergedInto)&&(t.mergedInto=e.get(t.mergedInto))})}return Object.assign(l,t),e.page.addElement(l,{skipSelect:o})}}));
1
+ import{types as e,getParent as t,getSnapshot as o,isAlive as l,getRoot as r,cast as n}from"mobx-state-tree";import{observable as s}from"mobx";import{nanoid as i}from"nanoid";import{clampFontSize as c,TABLE_CELL_OVERRIDABLE_KEYS as d}from"@polotno/schema/defaults";import{Shape as a}from"./shape-model.js";const g=.05,u=e.enumeration(["solid","dashed","dotted","none"]);function h(e){return t(e,2)}function f(e,t,o){const r=e[`_${t}`];return null!=r?r:l(e)?h(e)[t]:o}function b(e){return t(e,1)}const w=e.model("BorderSide",{color:e.maybe(e.string),width:e.maybe(e.number),style:e.maybe(u)}).postProcessSnapshot(e=>{const t={};for(const[o,l]of Object.entries(e)){null!=l&&(t[o]=l)}return t}),p=e.model("CellBorders",{top:e.maybe(w),right:e.maybe(w),bottom:e.maybe(w),left:e.maybe(w)}).postProcessSnapshot(e=>{const t={};for(const[o,l]of Object.entries(e)){null!=l&&"object"==typeof l&&Object.keys(l).length>0&&(t[o]=l)}return t}),m=d,C=new Set(m),_=["blurEnabled","blurRadius","brightnessEnabled","brightness","sepiaEnabled","grayscaleEnabled","filters","shadowEnabled","shadowBlur","shadowOffsetX","shadowOffsetY","shadowColor","shadowOpacity"],y=["id","type","text","opacity","rowSpan","colSpan","mergedInto","name","custom","borders"],v=new Set(["row","col","x","y","width","height","rotation","draggable","resizable","selectable","removable","contentEditable","visible","showInExport","alwaysOnTop","backgroundEnabled","backgroundOpacity","backgroundColor","backgroundCornerRadius","backgroundPadding","curveEnabled","curvePower","shadowEnabled","shadowBlur","shadowOffsetX","shadowOffsetY","shadowColor","shadowOpacity","blurEnabled","blurRadius","brightnessEnabled","brightness","sepiaEnabled","grayscaleEnabled","placeholder","animations","filters"]),I={opacity:1,rowSpan:1,colSpan:1,name:""},S=[];export const TableCell=e.model("TableCell",{id:e.identifier,type:e.optional(e.literal("tablecell"),"tablecell"),text:"",_fontSize:e.maybe(e.number),_fontFamily:e.maybe(e.string),_fontWeight:e.maybe(e.string),_fontStyle:e.maybe(e.string),_textDecoration:e.maybe(e.string),_textTransform:e.maybe(e.string),_fill:e.maybe(e.string),_align:e.maybe(e.string),_verticalAlign:e.maybe(e.string),_lineHeight:e.maybe(e.union(e.number,e.string)),_letterSpacing:e.maybe(e.number),_strokeWidth:e.maybe(e.number),_stroke:e.maybe(e.string),_cellBackground:e.maybe(e.string),_cellPadding:e.maybe(e.number),opacity:1,rowSpan:1,colSpan:1,mergedInto:e.maybe(e.string),borders:e.maybe(p),name:"",custom:e.frozen()}).volatile(()=>({_editModeEnabled:!1,filters:s.map()})).preProcessSnapshot(e=>{if(!e){return e}for(const o in e){null===e[o]&&(e[o]=void 0)}const t={};for(const o of y){o in e&&(t[o]=e[o])}for(const o of m){void 0!==e[o]&&(t[`_${o}`]=e[o])}return void 0!==t._fontSize&&(t._fontSize=c(t._fontSize)),t}).postProcessSnapshot(e=>{const t={};for(const[o,l]of Object.entries(e)){if(o.startsWith("_")){null!=l&&(t[o.slice(1)]=l)}else if("borders"===o){null!=l&&"object"==typeof l&&Object.keys(l).length>0&&(t.borders=l)}else{if(o in I&&l===I[o]){continue}t[o]=l}}return t}).views(e=>{const t={get row(){if(!l(e)){return 0}const t=h(e),o=b(e).indexOf(e);return-1===o?0:Math.floor(o/t.cols)},get col(){if(!l(e)){return 0}const t=h(e),o=b(e).indexOf(e);return-1===o?0:o%t.cols},get store(){return l(e)?r(e):null},get page(){if(!l(e)){return null}try{return h(e).page}catch(t){return null}},get fontSize(){return f(e,"fontSize",30)},get fontFamily(){return f(e,"fontFamily","Roboto")},get fontWeight(){return f(e,"fontWeight","normal")},get fontStyle(){return f(e,"fontStyle","normal")},get textDecoration(){return f(e,"textDecoration","")},get textTransform(){return f(e,"textTransform","none")},get fill(){return f(e,"fill","black")},get align(){return f(e,"align","left")},get verticalAlign(){return f(e,"verticalAlign","top")},get lineHeight(){return f(e,"lineHeight",1.2)},get letterSpacing(){return f(e,"letterSpacing",0)},get strokeWidth(){return f(e,"strokeWidth",0)},get stroke(){return f(e,"stroke","black")},get cellBackground(){return f(e,"cellBackground","transparent")},get cellPadding(){return f(e,"cellPadding",4)},get width(){if(!l(e)){return 100}try{return h(e).getCellRect(t.row,t.col,e.rowSpan,e.colSpan).width}catch(o){return 100}},get height(){if(!l(e)){return 100}try{return h(e).getCellRect(t.row,t.col,e.rowSpan,e.colSpan).height}catch(o){return 100}},get borderInsets(){if(!l(e)){return{top:0,right:0,bottom:0,left:0}}const o=h(e),r=(e,o)=>{const l=t.getEffectiveBorder(e);return"none"===l.style||0===l.width?0:o?l.width:l.width/2};return{top:r("top",0===t.row),bottom:r("bottom",t.row+e.rowSpan===o.rows),left:r("left",0===t.col),right:r("right",t.col+e.colSpan===o.cols)}},get a(){var o;if(!l(e)){return{x:0,y:0,width:100,height:100,rotation:0,opacity:1,fontSize:16}}const r=h(e).getCellRect(t.row,t.col,e.rowSpan,e.colSpan),n=t.cellPadding,{top:s,right:i,bottom:c,left:d}=t.borderInsets;return{x:r.x+d+n,y:r.y+s+n,width:Math.max(0,r.width-d-i-2*n),height:Math.max(0,r.height-s-c-2*n),rotation:0,opacity:null!==(o=e.opacity)&&void 0!==o?o:1,fontSize:t.fontSize}},getEffectiveBorder(t){var o,r,n,s,i,c,d;const a=l(e)?h(e):null,g=null===(o=e.borders)||void 0===o?void 0:o[t];return{color:null!==(n=null!==(r=null==g?void 0:g.color)&&void 0!==r?r:null==a?void 0:a.borderColor)&&void 0!==n?n:"#000000",width:null!==(i=null!==(s=null==g?void 0:g.width)&&void 0!==s?s:null==a?void 0:a.borderWidth)&&void 0!==i?i:1,style:null!==(d=null!==(c=null==g?void 0:g.style)&&void 0!==c?c:null==a?void 0:a.borderStyle)&&void 0!==d?d:"solid"}},get x(){return 0},get y(){return 0},get rotation(){return 0},get draggable(){return!1},get resizable(){return!1},get selectable(){return!1},get removable(){return!1},get contentEditable(){return!0},get visible(){return!0},get showInExport(){return!0},get alwaysOnTop(){return!1},get placeholder(){return""},get backgroundEnabled(){return!1},get backgroundOpacity(){return 1},get backgroundColor(){return"transparent"},get backgroundCornerRadius(){return 0},get backgroundPadding(){return 0},get curveEnabled(){return!1},get curvePower(){return 0},get shadowEnabled(){return!1},get shadowBlur(){return 0},get shadowOffsetX(){return 0},get shadowOffsetY(){return 0},get shadowColor(){return"black"},get shadowOpacity(){return 1},get blurEnabled(){return!1},get blurRadius(){return 0},get brightnessEnabled(){return!1},get brightness(){return 0},get sepiaEnabled(){return!1},get grayscaleEnabled(){return!1},get animations(){return S}};return t}).actions(e=>({toJSON:()=>Object.assign({},o(e)),set(t){null!=t.fontSize&&(t=Object.assign(Object.assign({},t),{fontSize:c(t.fontSize)}));const o={};for(const[e,l]of Object.entries(t)){C.has(e)?o[`_${e}`]=l:"borders"===e?o.borders=l?JSON.parse(JSON.stringify(l)):l:v.has(e)||(o[e]=l)}Object.assign(e,o)},setBorder(t,l){const r=e.borders?Object.assign({},o(e.borders)):{},s=r[t]||{},i=Object.assign({},s);void 0!==l.color&&(i.color=l.color),void 0!==l.width&&(i.width=l.width),void 0!==l.style&&(i.style=l.style),r[t]=i,e.borders=n(r)},toggleEditMode(t){const o=null!=t?t:!e._editModeEnabled;o!==e._editModeEnabled&&(e._editModeEnabled=o,e._editModeEnabled?e.store.history.startTransaction():e.store.history.endTransaction())},beforeDestroy(){e._editModeEnabled&&e.store.history.endTransaction()}}));function H(e,t){const l=[];for(const r of e){const e={id:i(10),text:""};if(!r){l.push(e);continue}for(const t of m){const o=r[`_${t}`];null!=o&&(e[t]=o)}const n=r.borders;if(n){const l={},r=t?["left","right","top"]:["top","bottom","left"];for(const e of r){const t=n[e];t&&(l[e]=o(t))}Object.keys(l).length>0&&(e.borders=l)}l.push(e)}return l}function R(e){return Array.from({length:e},()=>1/e)}function O(e){const t=e.reduce((e,t)=>e+t,0);return 0===t?R(e.length):e.map(e=>e/t)}export const TableElement=a.named("Table").props({type:"table",width:300,height:200,rows:3,cols:3,colWidths:e.array(e.number),rowHeights:e.array(e.number),cells:e.array(TableCell),borderColor:"#000000",borderWidth:1,borderStyle:e.optional(e.enumeration(["solid","dashed","dotted","none"]),"solid"),fontSize:30,fontFamily:"Roboto",fontWeight:"normal",fontStyle:"normal",textDecoration:"",textTransform:"none",fill:"black",align:"center",verticalAlign:"middle",lineHeight:e.optional(e.union(e.number,e.string),1.2),letterSpacing:0,strokeWidth:0,stroke:"black",cellBackground:"transparent",cellPadding:4}).preProcessSnapshot(e=>null==(null==e?void 0:e.fontSize)?e:Object.assign(Object.assign({},e),{fontSize:c(e.fontSize)})).postProcessSnapshot(e=>{e.cells&&((e=Object.assign({},e)).cells=e.cells.map(t=>{const o={};for(const[l,r]of Object.entries(t)){C.has(l)&&r===e[l]||(o[l]=r)}return o}));for(const t of _){delete e[t]}return e}).volatile(()=>({_focusedCellIds:[],_editingCellId:void 0,_anchorCellId:void 0,_cellContentHeights:s.map(),_baseRowHeights:null,_baseHeight:null})).actions(e=>({afterCreate(){const t=e.rows*e.cols;if(0===e.cells.length){e.cells.replace(function(e,t){const o=[];for(let l=0;l<e*t;l++){o.push({id:i(10),text:""})}return o}(e.rows,e.cols))}else if(e.cells.length<t){for(;e.cells.length<t;){e.cells.push(n({id:i(10),text:""}))}}else{e.cells.length>t&&e.cells.splice(t)}0===e.colWidths.length&&e.colWidths.replace(R(e.cols)),0===e.rowHeights.length&&e.rowHeights.replace(R(e.rows))}})).views(e=>({get _cellMap(){const t=new Map,o=e.cols;return e.cells.forEach((e,l)=>{t.set(`${Math.floor(l/o)}:${l%o}`,e)}),t},getActualRowHeight:t=>e.rowHeights[t]*e.height})).views(e=>{const t={getCell:(t,o)=>e._cellMap.get(`${t}:${o}`),get minWidth(){return 20*e.cols},getRowContentOuterHeight(o){let l=0;for(let r=0;r<e.cols;r++){const n=t.getCell(o,r);if(!n){continue}const s=e._cellContentHeights.get(n.id);if(void 0===s){continue}const i=n.borderInsets,c=s+2*n.cellPadding+i.top+i.bottom;c>l&&(l=c)}return l},get minHeight(){const o=20*e.rows;if(0===e._cellContentHeights.size){return o}let l=0;for(let r=0;r<e.rows;r++){l+=t.getRowContentOuterHeight(r)}return Math.max(o,l)},get actualHeight(){let t=0;for(let o=0;o<e.rows;o++){t+=e.getActualRowHeight(o)}return t},getCellRect(t,o,l=1,r=1){let n=0;for(let d=0;d<o;d++){n+=e.colWidths[d]*e.width}let s=0;for(let d=0;d<t;d++){s+=e.getActualRowHeight(d)}let i=0;for(let d=o;d<o+r;d++){i+=(e.colWidths[d]||0)*e.width}let c=0;for(let d=t;d<t+l;d++){c+=e.getActualRowHeight(d)}return{x:n,y:s,width:i,height:c}},get visibleCells(){return e.cells.filter(e=>!e.mergedInto)},get focusedCells(){return e.cells.filter(t=>e._focusedCellIds.includes(t.id))},get editingCell(){if(e._editingCellId){return e.cells.find(t=>t.id===e._editingCellId)}},getFocusedCellRange(){if(0===e._focusedCellIds.length){return null}let t=1/0,o=-1/0,l=1/0,r=-1/0;const n=new Set(e._focusedCellIds);for(const s of e.cells){n.has(s.id)&&(s.row<t&&(t=s.row),s.row>o&&(o=s.row),s.col<l&&(l=s.col),s.col>r&&(r=s.col))}return t===1/0?null:{minRow:t,maxRow:o,minCol:l,maxCol:r}},get _fitRowsToContent(){var o,l;if(0===e._cellContentHeights.size){return null}const r=null!==(o=e._baseHeight)&&void 0!==o?o:e.height,n=null!==(l=e._baseRowHeights)&&void 0!==l?l:[...e.rowHeights];let s=!1;const i=[];for(let d=0;d<e.rows;d++){const o=e.rowHeights[d]*e.height,l=n[d]*r,c=t.getRowContentOuterHeight(d),a=Math.max(c,l);Math.abs(a-o)>1?(i.push(a),s=!0):i.push(o)}if(!s){return null}const c=i.reduce((e,t)=>e+t,0);return{rowHeights:i.map(e=>e/c),height:c}}};return t}).actions(e=>{const t=e.set,o={set(e){null!=e.fontSize&&(e=Object.assign(Object.assign({},e),{fontSize:c(e.fontSize)})),t(e)},setCellContentHeight(t,o){e._cellContentHeights.set(t,o)},_applyFitRowsToContent(){if(!l(e)){return}null===e._baseRowHeights&&(e._baseRowHeights=[...e.rowHeights],e._baseHeight=e.height);const t=e._fitRowsToContent;t&&(e.height=t.height,e.rowHeights.replace(t.rowHeights))},focusCell(t,o=!1){o?e._focusedCellIds.includes(t)||(e._focusedCellIds=[...e._focusedCellIds,t]):(e._focusedCellIds=[t],e._anchorCellId=t)},selectRowRange(t,o){const l=Math.max(0,Math.min(t,o)),r=Math.min(e.rows-1,Math.max(t,o)),n=[];for(let s=l;s<=r;s++){for(let t=0;t<e.cols;t++){const o=e.getCell(s,t);o&&n.push(o.id)}}e._focusedCellIds=n,e._anchorCellId=n[0]},selectColumnRange(t,o){const l=Math.max(0,Math.min(t,o)),r=Math.min(e.cols-1,Math.max(t,o)),n=[];for(let s=0;s<e.rows;s++){for(let t=l;t<=r;t++){const o=e.getCell(s,t);o&&n.push(o.id)}}e._focusedCellIds=n,e._anchorCellId=n[0]},selectRow(e){o.selectRowRange(e,e)},selectColumn(e){o.selectColumnRange(e,e)},focusCellRange(t,o){const l=e.cells.find(t=>t.id===e._anchorCellId);if(!l){return}const r=Math.min(l.row,t),n=Math.max(l.row,t),s=Math.min(l.col,o),i=Math.max(l.col,o),c=[];for(const d of e.cells){d.row>=r&&d.row<=n&&d.col>=s&&d.col<=i&&c.push(d.id)}e._focusedCellIds=c},clearCellFocus(){if(l(e)){if(e._editingCellId){const t=e.cells.find(t=>t.id===e._editingCellId);t&&t.toggleEditMode(!1)}e._focusedCellIds=[],e._editingCellId=void 0,e._anchorCellId=void 0}},enterCellEdit(t){e._editingCellId=t,e._focusedCellIds.includes(t)||(e._focusedCellIds=[t]);const o=e.cells.find(e=>e.id===t);o&&o.toggleEditMode(!0)},exitCellEdit(){if(e._editingCellId){const t=e.cells.find(t=>t.id===e._editingCellId);t&&t.toggleEditMode(!1)}e._editingCellId=void 0},_resetBaseRowHeights(){e._baseRowHeights=null,e._baseHeight=null},setHeightRedistribute(t){const o=e.rows;if(0===o||t<=0){return void(e.height=t)}const l=e.height;if(l<=0||t>=l){return void(e.height=t)}const r=[],n=[];let s=0;for(let u=0;u<o;u++){r.push(e.rowHeights[u]*l);const t=e.getRowContentOuterHeight(u);n.push(t),s+=t}if(t<=s||s<=0){return void(e.height=t)}const i=t-s;let c=0;const d=[];for(let e=0;e<o;e++){const t=Math.max(0,r[e]-n[e]);d.push(t),c+=t}const a=[];if(c<=0){const e=t/l;for(let t=0;t<o;t++){a.push(r[t]*e)}}else{for(let e=0;e<o;e++){a.push(n[e]+d[e]/c*i)}}const g=a.map(e=>e/t);e.height=t,e.rowHeights.replace(g)},addRow(t){o._resetBaseRowHeights();const l=t>0?t-1:0,r=(e.rowHeights[l]||1/(e.rows+1))*e.height,n=e.height+r,s=[];for(let o=0;o<e.rows;o++){s.push(e.rowHeights[o]*e.height/n)}s.splice(t,0,r/n);const i=t>0?t-1:0,c=[];for(let o=0;o<e.cols;o++){c.push(e.cells[i*e.cols+o])}const d=t*e.cols,a=H(c,!0);e.cells.splice(d,0,...a),e.rows+=1,e.height=n,e.rowHeights.replace(O(s))},removeRow(t){if(e.rows<=1){return}o._resetBaseRowHeights();const l=t*e.cols,r=[];for(let o=l;o<l+e.cols;o++){r.push(e.cells[o].id)}if(e._editingCellId&&r.includes(e._editingCellId)){const t=e.cells.find(t=>t.id===e._editingCellId);t&&t.toggleEditMode(!1),e._editingCellId=void 0}e._focusedCellIds=e._focusedCellIds.filter(e=>!r.includes(e)),r.forEach(t=>e._cellContentHeights.delete(t)),e.cells.splice(l,e.cols);const n=[...e.rowHeights];n.splice(t,1),e.rows-=1,e.rowHeights.replace(O(n))},addColumn(t){const o=t>0?t-1:0,l=(e.colWidths[o]||1/(e.cols+1))*e.width,r=e.width+l,s=[];for(let n=0;n<e.cols;n++){s.push(e.colWidths[n]*e.width/r)}s.splice(t,0,l/r);const i=e.cols,c=t>0?t-1:0,d=[];for(let n=0;n<e.rows;n++){d.push(e.cells[n*i+c])}const a=H(d,!1);for(let g=e.rows-1;g>=0;g--){e.cells.splice(g*i+t,0,n(a[g]))}e.cols+=1,e.width=r,e.colWidths.replace(O(s))},removeColumn(t){if(e.cols<=1){return}const o=e.cols,l=[];for(let n=0;n<e.rows;n++){l.push(e.cells[n*o+t].id)}if(e._editingCellId&&l.includes(e._editingCellId)){const t=e.cells.find(t=>t.id===e._editingCellId);t&&t.toggleEditMode(!1),e._editingCellId=void 0}e._focusedCellIds=e._focusedCellIds.filter(e=>!l.includes(e)),l.forEach(t=>e._cellContentHeights.delete(t));for(let n=e.rows-1;n>=0;n--){e.cells.splice(n*o+t,1)}const r=[...e.colWidths];r.splice(t,1),e.cols-=1,e.colWidths.replace(O(r))},removeRowRange(t,l){for(let r=l;r>=t&&!(e.rows<=1);r--){o.removeRow(r)}},removeColumnRange(t,l){for(let r=l;r>=t&&!(e.cols<=1);r--){o.removeColumn(r)}},distributeRowsEvenly(){const t=e.rows;let l=20;for(let o=0;o<t;o++){l=Math.max(l,e.getRowContentOuterHeight(o))}o._resetBaseRowHeights(),e.height=Math.max(e.height,l*t),e.rowHeights.replace(R(t))},distributeColumnsEvenly(){e.colWidths.replace(R(e.cols))},resizeColumn(t,o){if(t>=e.cols-1){return}const l=[...e.colWidths],r=l[t]+l[t+1],n=l[t]+o,s=l[t+1]-o;n<g?(l[t]=g,l[t+1]=r-g):s<g?(l[t+1]=g,l[t]=r-g):(l[t]=n,l[t+1]=s),e.colWidths.replace(l)},resizeRow(t,o){if(t>=e.rows-1){return}const l=[...e.rowHeights],r=l[t]+l[t+1],n=e.height,s=n>0?e.getRowContentOuterHeight(t)/n:0,i=n>0?e.getRowContentOuterHeight(t+1)/n:0,c=Math.max(g,s),d=Math.max(g,i),a=l[t]+o,u=l[t+1]-o;a<c?(l[t]=c,l[t+1]=r-c):u<d?(l[t+1]=d,l[t]=r-d):(l[t]=a,l[t+1]=u),e.rowHeights.replace(l)},setCellBorders(t,o,l){const r={top:{side:"bottom",dr:-1,dc:0},bottom:{side:"top",dr:1,dc:0},left:{side:"right",dr:0,dc:-1},right:{side:"left",dr:0,dc:1}};for(const n of t){const t=e.cells.find(e=>e.id===n);if(t){for(const n of o){t.setBorder(n,l);const o=r[n],s=t.row+o.dr,i=t.col+o.dc,c=e.getCell(s,i);c&&c.setBorder(o.side,l)}}}},applyBorderMode(t,l){var r;const n=function(e,t,o){const{minRow:l,maxRow:r,minCol:n,maxCol:s}=t,i=(e,t,l,r)=>{const n=[];for(let s=e;s<=t;s++){for(let e=l;e<=r;e++){const t=o(s,e);t&&n.push(t.id)}}return n};if("all"===e){return[{cellIds:i(l,r,n,s),sides:["top","right","bottom","left"]}]}const c=[],d="outer"===e||"topOnly"===e||"topBottom"===e,a="outer"===e||"bottomOnly"===e||"topBottom"===e,g="outer"===e||"leftOnly"===e,u="outer"===e||"rightOnly"===e;if(d){const e=i(l,l,n,s);e.length&&c.push({cellIds:e,sides:["top"]})}if(a){const e=i(r,r,n,s);e.length&&c.push({cellIds:e,sides:["bottom"]})}if(g){const e=i(l,r,n,n);e.length&&c.push({cellIds:e,sides:["left"]})}if(u){const e=i(l,r,s,s);e.length&&c.push({cellIds:e,sides:["right"]})}if(d||a||g||u){return c}if(("inner"===e||"innerHorizontal"===e)&&r>l){const e=i(l,r-1,n,s);e.length&&c.push({cellIds:e,sides:["bottom"]})}if(("inner"===e||"innerVertical"===e)&&s>n){const e=i(l,r,n,s-1);e.length&&c.push({cellIds:e,sides:["right"]})}return c}(t,null!==(r=e.getFocusedCellRange())&&void 0!==r?r:{minRow:0,maxRow:e.rows-1,minCol:0,maxCol:e.cols-1},(t,o)=>e.getCell(t,o));for(const{cellIds:e,sides:s}of n){o.setCellBorders(e,s,l)}}};return o}).actions(e=>({clone(t={},{skipSelect:o=!1}={}){const l=JSON.parse(JSON.stringify(e.toJSON()));if(t.id=t.id||i(10),l.cells){const e=new Map;l.cells.forEach(t=>{const o=t.id,l=i(10);e.set(o,l),t.id=l}),l.cells.forEach(t=>{t.mergedInto&&e.has(t.mergedInto)&&(t.mergedInto=e.get(t.mergedInto))})}return Object.assign(l,t),e.page.addElement(l,{skipSelect:o})}}));
@@ -1 +1 @@
1
- import{types as e}from"mobx-state-tree";import{hasMeasuredHeight as t,parseNumericLineHeight as o}from"@polotno/core/text-types";import{Shape as n}from"./shape-model.js";const i=e=>{var t;return"string"!=typeof e?e:null!==(t=o(e))&&void 0!==t?t:e};export const TextElement=n.named("Text").props({type:"text",text:"",placeholder:"",fontSize:14,fontFamily:"Roboto",fontStyle:"normal",fontWeight:"normal",textDecoration:"",textTransform:"none",fill:"black",align:"center",width:100,height:0,verticalAlign:"top",strokeWidth:0,stroke:"black",strokeLineJoin:"round",lineHeight:e.optional(e.union(e.number,e.string),1.2),letterSpacing:0,_editModeEnabled:!1,backgroundEnabled:!1,backgroundColor:"#7ED321",backgroundOpacity:1,backgroundCornerRadius:.5,backgroundPadding:.5,legacyBackground:e.maybe(e.boolean),curveEnabled:!1,curvePower:.5}).preProcessSnapshot(e=>{const o=Object.assign(Object.assign({},e),{fontSize:null!=e.fontSize&&e.fontSize<1?1:e.fontSize,lineHeight:i(e.lineHeight)});return t(o)||delete o.height,o}).actions(e=>{const t=e.set;return{set(e){null!=e.fontSize&&e.fontSize<1&&(e=Object.assign(Object.assign({},e),{fontSize:1})),"string"==typeof e.lineHeight&&(e=Object.assign(Object.assign({},e),{lineHeight:i(e.lineHeight)})),t(e)},toggleEditMode(t){const o=null!=t?t:!e._editModeEnabled;o!==e._editModeEnabled&&(e._editModeEnabled=o,e._editModeEnabled?e.store.history.startTransaction():e.store.history.endTransaction())},beforeDestroy(){e._editModeEnabled&&e.store.history.endTransaction()}}});
1
+ import{types as e}from"mobx-state-tree";import{clampFontSize as t}from"@polotno/schema/defaults";import{hasMeasuredHeight as o,parseNumericLineHeight as n}from"@polotno/core/text-types";import{Shape as i}from"./shape-model.js";const r=e=>{var t;return"string"!=typeof e?e:null!==(t=n(e))&&void 0!==t?t:e};export const TextElement=i.named("Text").props({type:"text",text:"",placeholder:"",fontSize:14,fontFamily:"Roboto",fontStyle:"normal",fontWeight:"normal",textDecoration:"",textTransform:"none",fill:"black",align:"center",width:100,height:0,verticalAlign:"top",strokeWidth:0,stroke:"black",strokeLineJoin:"round",lineHeight:e.optional(e.union(e.number,e.string),1.2),letterSpacing:0,_editModeEnabled:!1,backgroundEnabled:!1,backgroundColor:"#7ED321",backgroundOpacity:1,backgroundCornerRadius:.5,backgroundPadding:.5,legacyBackground:e.maybe(e.boolean),curveEnabled:!1,curvePower:.5}).preProcessSnapshot(e=>{const n=Object.assign(Object.assign({},e),{fontSize:t(e.fontSize),lineHeight:r(e.lineHeight)});return o(n)||delete n.height,n}).actions(e=>{const o=e.set;return{set(e){null!=e.fontSize&&(e=Object.assign(Object.assign({},e),{fontSize:t(e.fontSize)})),"string"==typeof e.lineHeight&&(e=Object.assign(Object.assign({},e),{lineHeight:r(e.lineHeight)})),o(e)},toggleEditMode(t){const o=null!=t?t:!e._editModeEnabled;o!==e._editModeEnabled&&(e._editModeEnabled=o,e._editModeEnabled?e.store.history.startTransaction():e.store.history.endTransaction())},beforeDestroy(){e._editModeEnabled&&e.store.history.endTransaction()}}});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "polotno",
3
- "version": "3.7.0",
3
+ "version": "3.8.0",
4
4
  "description": "Design Editor Framework",
5
5
  "author": "Anton Lavrenov",
6
6
  "keywords": [
@@ -96,10 +96,10 @@
96
96
  },
97
97
  "dependencies": {
98
98
  "@base-ui/react": "^1.7.0",
99
- "@polotno/core": "0.5.0",
100
- "@polotno/html-export": "0.3.0",
101
- "@polotno/schema": "0.5.0",
102
- "@polotno/svg-export": "0.3.0",
99
+ "@polotno/core": "0.6.0",
100
+ "@polotno/html-export": "0.3.1",
101
+ "@polotno/schema": "0.6.0",
102
+ "@polotno/svg-export": "0.3.1",
103
103
  "class-variance-authority": "^0.7.1",
104
104
  "clsx": "^2.1.1",
105
105
  "gifuct-js": "^2.1.2",
@@ -116,7 +116,7 @@
116
116
  "react-konva-utils": "^2.0.0",
117
117
  "react-sortablejs": "6.1.4",
118
118
  "react-window": "^2.3.0",
119
- "render-tag": "^0.1.27",
119
+ "render-tag": "^0.1.29",
120
120
  "sortablejs": "^1.15.7",
121
121
  "svg-round-corners": "^0.4.3",
122
122
  "swr": "^2.5.0",