polotno 4.6.0 → 4.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.
Files changed (59) hide show
  1. package/LICENSE.md +22 -7
  2. package/README.md +1 -1
  3. package/blueprint/side-panel/text-panel.js +3 -3
  4. package/blueprint/toolbar/text-toolbar.js +2 -2
  5. package/blueprint.polotno.css +116 -116
  6. package/canvas/figure-element.js +1 -1
  7. package/canvas/gif-element.js +1 -1
  8. package/canvas/html-element.js +1 -1
  9. package/canvas/image-element.js +1 -1
  10. package/canvas/page.js +1 -1
  11. package/canvas/quill-font-formats.js +1 -1
  12. package/canvas/render-tag-element.js +1 -1
  13. package/canvas/rich-editor.d.ts +0 -4
  14. package/canvas/rich-editor.js +5 -2
  15. package/canvas/text-element.js +1 -1
  16. package/canvas/use-mediabunny-video.js +1 -1
  17. package/canvas/video-element.js +1 -1
  18. package/model/group-model.d.ts +2 -12
  19. package/model/image-model.js +1 -1
  20. package/model/page-model.d.ts +2 -12
  21. package/model/store.d.ts +18 -108
  22. package/model/store.js +1 -1
  23. package/model/table-model.d.ts +2 -12
  24. package/model/table-model.js +1 -1
  25. package/model/text-model.js +1 -1
  26. package/package.json +28 -28
  27. package/pages-timeline/audio-track.js +1 -1
  28. package/pages-timeline/current-time.js +1 -1
  29. package/pages-timeline/element-track.js +1 -1
  30. package/pages-timeline/page-preview.js +1 -1
  31. package/pages-timeline/pages-timeline.js +1 -1
  32. package/pages-timeline/pages.js +1 -1
  33. package/pages-timeline/play-button.js +1 -1
  34. package/pages-timeline/time-ruler.js +1 -1
  35. package/pages-timeline/track-styles.js +1 -1
  36. package/polotno.bundle.js +171 -168
  37. package/primitives/select.d.ts +1 -1
  38. package/side-panel/images-grid.d.ts +2 -1
  39. package/side-panel/images-grid.js +1 -1
  40. package/side-panel/select-svg.js +1 -1
  41. package/side-panel/text-panel.js +1 -1
  42. package/side-panel/text-template.d.ts +12 -0
  43. package/side-panel/text-template.js +1 -0
  44. package/toolbar/text-toolbar.js +1 -1
  45. package/toolbar/video-toolbar.js +1 -1
  46. package/ui.css +2 -2
  47. package/utils/font-metric.js +1 -1
  48. package/utils/fonts.js +1 -1
  49. package/utils/html-to-svg/font-inliner.js +1 -1
  50. package/utils/html2canvas.js +1 -1
  51. package/utils/measure-text.js +1 -1
  52. package/utils/pointer-drag.d.ts +13 -0
  53. package/utils/pointer-drag.js +1 -0
  54. package/utils/px.d.ts +2 -0
  55. package/utils/px.js +1 -1
  56. package/utils/rich-text-html.js +1 -1
  57. package/utils/text-format-state.js +1 -1
  58. package/utils/text-format.js +1 -1
  59. package/utils/validate-key.js +1 -1
@@ -1 +1 @@
1
- import{jsx as t,Fragment as e,jsxs as r}from"react/jsx-runtime";import n from"react";import{observer as o}from"mobx-react-lite";import{Group as i,Path as a,Text as l,TextPath as s}from"react-konva";import{Html as c}from"react-konva-utils";import{nodeAutorun as u}from"../utils/mobx.js";import d from"konva";import{parsePath as f,roundCommands as h}from"svg-round-corners/lib/index.js";import{generateBackgroundShapeFromRects as g,textLinesToRects as p}from"@polotno/core/background-shape";import{useColor as m}from"./use-color.js";import{useWorkspaceStyle as x}from"./workspace-style.js";import{ROLES as w}from"../model/store.js";import{incrementLoader as v}from"../utils/loader.js";import{scaledFontSizeAttrs as y,roundedFontSizeAttrs as S,roundedTextDecorationAttrs as b,textMinResizeWidth as E}from"../utils/px.js";import{isFontLoaded as z}from"../utils/fonts.js";import{flags as k}from"../utils/flags.js";import{removeTags as O}from"@polotno/core/text";import{getDir as R,getCurvePath as A,resolveLineHeight as F,normalizeStrokeLineJoin as M}from"@polotno/core/text-html";import{applyFilter as j}from"./apply-filters.js";import{useFadeIn as L}from"./use-fadein.js";import{isTouchDevice as T}from"../utils/screen.js";import{isAlive as C,getParent as H}from"mobx-state-tree";import{getLimitedFontSize as P}from"./text-element/max-font-size.js";import{getOptimalCaretColor as X}from"./text-element/caret-color.js";import{visiblePlaceholder as Y}from"./text-element/placeholder.js";import{hasMeasuredHeight as W,resolveTextBoxHeight as D}from"@polotno/core/text-types";let $;function B(){return $||($=document.getElementById("polotno-text-style"),$||($=document.createElement("style"),$.id="polotno-text-style",document.head.appendChild($)),$)}d._fixTextRendering=!0;const I={border:"none",padding:"0px",overflow:"hidden",background:"none",outline:"none",resize:"none",overflowWrap:"break-word",whiteSpace:"pre-wrap",userSelect:"text",wordBreak:"normal",textTransform:"none"};export{getDir}from"@polotno/core/text-html";const N=o(({textNodeRef:e,element:r,onBlur:o,selectAll:i,cursorPosition:a})=>{const[l,s]=n.useState(I),c=e.current;n.useLayoutEffect(()=>{if(!c){return}const t={};t.width=c.width()-2*c.padding()+"px",t.height=c.height()-2*c.padding()+c.fontSize()*c.lineHeight()+"px",t.fontSize=c.fontSize()+"px",t.lineHeight=c.lineHeight()+.01,t.fontFamily=c.fontFamily(),t.textAlign=c.align(),t.color=c.fill(),t.fontWeight=r.fontWeight,t.fontStyle=r.fontStyle,t.letterSpacing=r.letterSpacing+"em",t.opacity=Math.max(r.a.opacity,.2),t.textTransform=r.textTransform,t.caretColor=X(r);const e=`\n .polotno-input::placeholder {\n color: ${l.color};\n opacity: 0.6;\n }\n `,n=B();n.innerHTML="",n.appendChild(document.createTextNode(e)),JSON.stringify(t)!==JSON.stringify(l)&&s(t)});const u=n.useRef(null);if(n.useLayoutEffect(()=>{var t;const e=u.current;if(!e){return}null===(t=u.current)||void 0===t||t.focus({preventScroll:!0});const r=a||e.value.length;e.selectionStart=e.selectionEnd=r,i&&(null==e||e.select(),document.execCommand("selectAll",!1,void 0))},[]),n.useEffect(()=>{window.addEventListener("blur",o);const t=t=>{var e;(null===(e=u.current)||void 0===e?void 0:e.contains(t.target))||o()};return window.addEventListener("touchstart",t),()=>{window.removeEventListener("blur",o),window.removeEventListener("touchstart",t)}},[]),!c){return null}let d=0;const f=c.textArr.length*c.lineHeight()*c.fontSize(),h=D(r.a,f);"middle"===r.verticalAlign&&(d=(h-f)/2),"bottom"===r.verticalAlign&&(d=h-f);const g=O(r.text);return t("textarea",{className:"polotno-input",ref:u,dir:R(g),style:Object.assign(Object.assign(Object.assign({},I),l),{paddingTop:d+"px"}),value:g,onChange:t=>{const e=P({oldText:r.text,newText:t.target.value,element:r});r.set(Object.assign({text:t.target.value},y(r,e)))},placeholder:Y(r.placeholder),onBlur:o})}),J=e=>t(c,{children:t(N,Object.assign({},e))});export const useFontLoader=(t,e,r,o,i)=>{const[a,l]=n.useReducer(t=>t+1,0),s=n.useRef(z(e,r,o)),c=n.useRef(null);return n.useLayoutEffect(()=>{if(s.current=z(e,r,o),s.current){return}let n=!0;return(async()=>{s.current=!1,l();const a=v(`text ${e}`);await t.loadFont(e,r,o,i),n?(c.current=a,s.current=!0,l()):a()})(),()=>{c.current&&(c.current(),c.current=null),n=!1}},[e,r,o]),n.useEffect(()=>{s.current&&setTimeout(()=>{c.current&&(c.current(),c.current=null)})},[s.current]),[s.current]};export const useFontFamiliesLoader=(t,e,r,o,i)=>{const[a,l]=n.useReducer(t=>t+1,0),s=e.join("\0"),c=n.useRef(e.every(t=>z(t,r,o))),u=n.useRef(null);return n.useLayoutEffect(()=>{if(c.current=e.every(t=>z(t,r,o)),c.current){return}let n=!0;return(async()=>{c.current=!1,l();const a=v(`text fonts ${s}`);await Promise.all(e.map(e=>t.loadFont(e,r,o,i))),n?(u.current=a,c.current=!0,l()):a()})(),()=>{u.current&&(u.current(),u.current=null),n=!1}},[s,r,o]),n.useEffect(()=>{c.current&&setTimeout(()=>{u.current&&(u.current(),u.current=null)})},[c.current]),[c.current]};export const getLineHeight=({fontLoaded:t,fontFamily:e,fontSize:r,lineHeight:o})=>n.useMemo(()=>F({fontFamily:e,fontSize:r,lineHeight:o}),[t,e,r,o]);export function usePrevious(t){const e=n.useRef(t),r=n.useRef(t);return n.useMemo(()=>{r.current=e.current,e.current=t},[t]),r.current}function _(t,e,r=!1){const n=t.fontSize(),o=t.height(),i=O(e.text);let a=e.a.fontSize;t.height(void 0);const l=Math.round(2*e.a.fontSize)-1;for(let s=1;s<l;s++){const n=W(e.a)&&t.height()>e.a.height;let o=i.split("\n").join(" ").split(/[\s-]+/).reduce((t,e)=>(e=e.toLowerCase(),/[\u3000-\u303F\u3040-\u309F\u30A0-\u30FF\uFF00-\uFFEF\u4E00-\u9FAF\uAC00-\uD7AF]/.test(e)?t.concat(e.split("")):t.concat(e)),[]),l=t.textArr.map(t=>t.text.toLowerCase()).join(";");const s=o.find(t=>!l.includes(t)||(l=l.replace(t,""),!1));if(!(n||s&&!r)){break}a-=.5,t.fontSize(a)}return t.fontSize(n),t.height(o),a}export{getCurvePath}from"@polotno/core/text-html";export const TextElement=o(({element:o,store:c})=>{const{textOverflowIndicatorStyle:d}=x(),z=n.useRef(null),F=n.useRef(null),P=n.useRef(null),X=n.useRef([]),$=n.useRef(!0),[,B]=n.useReducer(t=>t+1,0),{editorEnabled:I,selectAll:N}=(t=>{const[e,r]=n.useState(!1),o=n.useRef(!1);return n.useEffect(()=>{var e=!0;return setTimeout(()=>{e&&(t._editModeEnabled&&(o.current=!0),r(!0),setTimeout(()=>{o.current=!1},50))},50),()=>{e=!1}},[]),{editorEnabled:e&&t._editModeEnabled,selectAll:o.current}})(o),[V,q]=n.useState(!1),[U,Z]=n.useState(!1),G=n.useRef(o.a.height),K=n.useRef(0),Q=n.useRef(""),tt=n.useRef(0),et=o.isSelected,rt=usePrevious(et),{textVerticalResizeEnabled:nt}=k,ot=k.autoDeleteEmptyText,it=usePrevious(o.fontFamily),[at,lt]=n.useState([]);n.useEffect(()=>{var t,e;const r=null!==(e=null===(t=z.current)||void 0===t?void 0:t.textArr)&&void 0!==e?e:[];JSON.stringify(r)!==JSON.stringify(at)&&lt(r)}),n.useEffect(()=>{if(o.a.width||"tablecell"===o.type){return}const t=z.current;t.width(600),o.set({width:1.4*t.getTextWidth()})},[]),n.useEffect(()=>{rt&&!et&&ot&&""===o.text&&o.removable&&!Y(o.placeholder)&&c.deleteElements([o.id])},[ot,o.placeholder,o.removable,o.text,et,rt]);const st=()=>{if(o.curveEnabled){const t=z.current;null==t||t.clearCache(),null==t||t.setAttrs({filters:[]});const e=F.current;e&&j(e,o)}else{const t=z.current;t&&j(t,o)}};n.useLayoutEffect(()=>{if(!U){return u(o,()=>{st()})}}),n.useEffect(()=>{const t=X.current;t.length>0&&(X.current=[],t.forEach(t=>t()))}),n.useEffect(()=>()=>{$.current=!1;const t=X.current;t.length>0&&(X.current=[],t.forEach(t=>t()))},[]);let ct=O(o.text);"uppercase"===o.textTransform&&(ct=ct.toUpperCase());const[ut]=useFontLoader(c,o.fontFamily,o.fontStyle,o.fontWeight,o.text||o.placeholder),dt=()=>{if(o.curveEnabled){const t=F.current;return t.getSelfRect().height||t.fontSize()}const t=z.current.clone({height:void 0}),e=Math.ceil(t.fontSize()*t.lineHeight()*t.textArr.length+1);return t.destroy(),e};n.useLayoutEffect(()=>{if(!ut){return}if("tablecell"===o.type){const{textOverflow:t}=k;if("resize"===t){const t=dt(),e=C(o)?H(o,2):null;(null==e?void 0:e.setCellContentHeight)&&e.setCellContentHeight(o.id,t)}else if("change-font-size"===t){const t=z.current;if(t){const e=_(t,o,k.textSplitAllowed);e!==o.fontSize&&c.history.ignore(()=>{o.set({fontSize:e})})}}return}const{textOverflow:t,textSplitAllowed:e}=k,r=(t,e,r,n)=>{const i=v(`text ${o.id}`),a=()=>{c.history.ignore(t,e,r).then(()=>{$.current?(X.current.push(i),B()):i()})};n?queueMicrotask(a):a()};if(!W(o)){const t=dt();return void r(()=>{W(o)||o.set({height:t})},void 0,void 0,!0)}if(!c.isPlaying){if("change-font-size"!==t||V){if("resize"===t){const t=dt();nt&&o.height<t&&!V&&r(()=>{var e;C(o)&&o.set({height:t}),null===(e=z.current)||void 0===e||e.height(t)},!1,!0),nt||o.height===t||V||r(()=>{var e;C(o)&&o.set({height:t}),null===(e=z.current)||void 0===e||e.height(t)},!1,!0)}}else{const t=z.current,n=o.curveEnabled?o.fontSize:_(t,o,e);if(n!==o.fontSize){return void r(()=>{o.set(y(o,n))},!1,!0)}const i=dt();o.height===i||nt||r(()=>{o.set({height:i})},!1,!0)}}}),n.useLayoutEffect(()=>{var t;if(ut&&o.curveEnabled){const e=null===(t=F.current)||void 0===t?void 0:t.getSelfRect().width;if(e){const t=e-o.a.width,r=o.a.rotation*Math.PI/180,n=-t/2*Math.cos(r),i=-t/2*Math.sin(r);o.set({width:e,x:o.a.x+n,y:o.a.y+i})}}},[ut,o.curveEnabled,o.curvePower,o.text,o.fontSize,o.fontFamily,o.fontWeight,o.fontStyle,o.letterSpacing]),n.useLayoutEffect(()=>{const t=z.current;t&&(t.width(t.width()+1e-8),t.width(t.width()-1e-8),t._setTextData(),st())},[ut]);const ft=n.useRef(null),ht=n.useRef(o.width),gt=n.useRef(0),pt=t=>{t.evt.preventDefault();const e=c.selectedShapes.find(t=>t===o);e&&o.contentEditable&&(gt.current=function(t){var e;const r=t.target,n=function(t){var e=t.getAbsoluteTransform().copy();e.invert();var r=t.getStage().getPointerPosition();return e.point(r)}(r),o=r.textArr,i=Math.floor(n.y/(r.fontSize()*r.lineHeight())),a=o.slice(0,i).reduce((t,e)=>t+e.text.length,i),l=null!==(e=o[i])&&void 0!==e?e:o[0];let s=0;return"right"===r.align()?s=r.width()-l.width:"center"===r.align()&&(s=r.width()/2-l.width/2),a+Math.round((n.x-s)/l.width*l.text.length)}(t),o.toggleEditMode())},mt=Y(o.placeholder),xt=!ct&&mt?.6:o.a.opacity;L(z,xt);const wt=getLineHeight({fontLoaded:ut,fontFamily:o.fontFamily,fontSize:o.a.fontSize,lineHeight:o.lineHeight}),vt=o.selectable||c.role===w.ADMIN,yt=m(o),St=m(o,o.stroke,"stroke"),bt=n.useMemo(()=>o.backgroundEnabled?o.curveEnabled?function({width:t,height:e,padding:r=0,cornerRadius:n=0}){const o=-r,i=-r,a=t+r,l=e+r,s=f(`M ${o} ${i} L ${a} ${i} L ${a} ${l} L ${o} ${l} Z`);return h(s,n).path}({width:o.a.width,height:o.a.height,cornerRadius:o.backgroundCornerRadius*(o.a.fontSize*wt*.5),padding:o.backgroundPadding*(o.a.fontSize*wt*.5)}):function({lines:t,lineHeight:e,width:r,align:n="left",padding:o=0,cornerRadius:i=0}){const a=p({lines:t,lineHeight:e,width:r,align:n});return g({rects:a,padding:o,cornerRadius:i})}({lines:JSON.parse(JSON.stringify(at)),cornerRadius:o.backgroundCornerRadius*(o.a.fontSize*wt*.5),lineHeight:wt*o.a.fontSize,padding:o.backgroundPadding*(o.a.fontSize*wt*.5),width:o.a.width,align:o.align}):"",[o.backgroundEnabled,o.curveEnabled,o.backgroundCornerRadius,o.a.fontSize,o.a.height,wt,o.backgroundPadding,o.a.width,o.align,at]),Et=T();let zt=0;if(!o.curveEnabled){const t=at.length*wt*o.a.fontSize,e=D(o.a,t);"middle"===o.verticalAlign?zt=(e-t)/2:"bottom"===o.verticalAlign&&(zt=e-t)}const kt=o.curveEnabled?A(o.a.width,o.a.height,o.curvePower,o.a.fontSize):"",Ot=ut?'"'+o.fontFamily+'"':it===o.fontFamily?"Arial":'"'+it+'"',Rt=R(ct);return r(e,{children:[t(a,{ref:P,x:o.a.x,y:o.a.y,rotation:o.a.rotation,hideInExport:!o.showInExport,listening:!1,visible:o.backgroundEnabled,opacity:o.backgroundOpacity*xt,data:bt,fill:o.backgroundColor,offsetY:-zt}),t(a,{data:kt,stroke:d.stroke,strokeWidth:1,x:o.a.x,y:o.a.y,rotation:o.a.rotation,visible:!1}),t(s,Object.assign({ref:F,visible:o.curveEnabled,data:kt,text:ct||mt,listening:!1,align:"center",textBaseline:"middle",direction:Rt},yt,St,{strokeWidth:o.strokeWidth,lineJoin:M(o.strokeLineJoin),fillAfterStrokeEnabled:!0,fontSize:o.a.fontSize,fontFamily:`"${o.fontFamily}", "${it}"`,fontStyle:o.fontStyle+" "+o.fontWeight,textDecoration:o.textDecoration.trim(),letterSpacing:o.letterSpacing*o.a.fontSize,x:o.a.x,y:o.a.y,rotation:o.a.rotation,opacity:o._editModeEnabled?.3:xt,hideInExport:!o.showInExport,shadowEnabled:o.shadowEnabled,shadowBlur:o.shadowBlur,shadowOffsetX:o.shadowOffsetX,shadowOffsetY:o.shadowOffsetY,shadowColor:o.shadowColor,shadowOpacity:o.shadowOpacity})),t(l,Object.assign({ref:z,id:o.selectable?o.id:void 0,name:o.selectable?"element":"",hideInExport:!o.showInExport,editModeEnabled:o._editModeEnabled,x:o.a.x,y:o.a.y,rotation:o.a.rotation,width:o.a.width,height:W(o.a)?o.a.height:void 0,text:ct||mt,direction:Rt},yt,St,{lineJoin:M(o.strokeLineJoin),strokeWidth:o.strokeWidth,fillAfterStrokeEnabled:!0,fontSize:o.a.fontSize,fontFamily:Ot,fontStyle:o.fontStyle+" "+o.fontWeight,textDecoration:o.textDecoration,align:o.align,verticalAlign:o.verticalAlign,draggable:Et?o.draggable&&et:o.draggable,preventDefault:!Et||et,opacity:o.curveEnabled?0:xt,visible:!o._editModeEnabled,ellipsis:"ellipsis"===k.textOverflow,shadowEnabled:o.shadowEnabled,shadowBlur:o.shadowBlur,shadowOffsetX:o.shadowOffsetX,shadowOffsetY:o.shadowOffsetY,shadowColor:o.shadowColor,shadowOpacity:o.shadowOpacity,lineHeight:wt,letterSpacing:o.letterSpacing*o.a.fontSize,listening:!!o.selectable&&vt,onDragStart:()=>{Z(!0)},onDragMove:t=>{o.set({x:t.target.x(),y:t.target.y()})},onDragEnd:t=>{Z(!1),o.set({x:t.target.x(),y:t.target.y()})},onClick:pt,onTap:pt,onTransformStart:()=>{var t,e;q(!0);const r=z.current;G.current=r.height(),ht.current=o.a.width,ft.current=r.position(),K.current=r.rotation(),tt.current=r.height();const n=null===(t=r.getStage())||void 0===t?void 0:t.findOne("Transformer");Q.current=null!==(e=null==n?void 0:n.getActiveAnchor())&&void 0!==e?e:""},onTransform:t=>{var e,r,n;const i=t.target;null===(e=P.current)||void 0===e||e.setAttrs({x:i.x(),y:i.y(),rotation:i.rotation(),scale:i.scale()});const a=(null===(r=i.getStage())||void 0===r?void 0:r.findOne("Transformer")).getActiveAnchor();if("middle-left"===a||"middle-right"===a){const t=i.scaleX(),e=i.width()*t,r=E(ht.current,o.a.fontSize);let n=e;e<r&&(n=r,ft.current&&i.position(ft.current)),i.width(n),i.scaleX(1),i.scaleY(1);let a=dt();if("ellipsis"===k.textOverflow){a=G.current}else{const t=Math.max(a,G.current);i.height(t),o.set({height:i.height()})}const l=k.textVerticalResizeEnabled?Math.max(a,G.current):dt();o.set({x:i.x(),width:i.width(),rotation:i.rotation(),height:l}),i.skewX(0),i.skewY(0),st()}if("top-center"===a||"bottom-center"===a){const e="resize"===k.textOverflow?dt():wt*o.a.fontSize,r=t.target.height()*t.target.scaleY();if(r<e){if(t.target.height(e),ft.current){if("top-center"===Q.current){const r=K.current*Math.PI/180,n=tt.current-e;t.target.x(ft.current.x-n*Math.sin(r)),t.target.y(ft.current.y+n*Math.cos(r))}else{t.target.position(ft.current)}}}else{t.target.height(r)}t.target.scaleY(1),t.target.scaleX(1),t.target.rotation(K.current),t.target.skewX(0),t.target.skewY(0),tt.current=Math.max(e,r)}ft.current=t.target.position();const l=t.target.scaleX();null===(n=P.current)||void 0===n||n.setAttrs({scaleX:1,scaleY:1}),t.target.scaleX(1),t.target.scaleY(1),o.set({fontSize:o.a.fontSize*l,width:t.target.width()*l,x:t.target.x(),y:t.target.y(),rotation:t.target.rotation(),height:t.target.height()*l,shadowBlur:o.shadowBlur*l,shadowOffsetX:o.shadowOffsetX*l,shadowOffsetY:o.shadowOffsetY*l,strokeWidth:o.strokeWidth*l})},onTransformEnd:t=>{var e;const r=t.target.scaleX();t.target.scaleX(1),t.target.scaleY(1),o.set(Object.assign(Object.assign({},S(o,o.fontSize*r)),{width:Math.ceil(t.target.width()*r),x:t.target.x(),y:t.target.y(),rotation:t.target.rotation(),height:t.target.height()*r})),null===(e=P.current)||void 0===e||e.setAttrs({scaleX:1,scaleY:1}),q(!1)}})),I&&o.contentEditable&&t(i,{x:o.a.x,y:o.a.y,rotation:o.a.rotation,children:t(J,{textNodeRef:z,element:o,selectAll:N,cursorPosition:gt.current,onBlur:()=>{o.set(b(o)),o.toggleEditMode(!1)}})})]})});
1
+ import{jsx as t,Fragment as e,jsxs as r}from"react/jsx-runtime";import n from"react";import{observer as o}from"mobx-react-lite";import{Group as i,Path as a,Text as s,TextPath as l}from"react-konva";import{Html as c}from"react-konva-utils";import{nodeAutorun as u}from"../utils/mobx.js";import d from"konva";import{parsePath as f,roundCommands as h}from"svg-round-corners/lib/index.js";import{generateBackgroundShapeFromRects as g,textLinesToRects as p}from"@polotno/core/background-shape";import{useColor as m}from"./use-color.js";import{useWorkspaceStyle as x}from"./workspace-style.js";import{ROLES as w}from"../model/store.js";import{incrementLoader as v}from"../utils/loader.js";import{activeAnchorOf as y,scaledFontSizeAttrs as b,roundedFontSizeAttrs as S,roundedTextDecorationAttrs as E,textMinResizeWidth as z}from"../utils/px.js";import{isFontLoaded as k}from"../utils/fonts.js";import{flags as O}from"../utils/flags.js";import{removeTags as R}from"@polotno/core/text";import{getDir as F,getCurvePath as A,resolveLineHeight as M,normalizeStrokeLineJoin as j}from"@polotno/core/text-html";import{cssFontFamily as L}from"@polotno/core/fonts";import{applyFilter as C}from"./apply-filters.js";import{useFadeIn as T}from"./use-fadein.js";import{isTouchDevice as H}from"../utils/screen.js";import{isAlive as P,getParent as X}from"mobx-state-tree";import{getLimitedFontSize as Y}from"./text-element/max-font-size.js";import{getOptimalCaretColor as W}from"./text-element/caret-color.js";import{visiblePlaceholder as D}from"./text-element/placeholder.js";import{hasMeasuredHeight as $,resolveTextBoxHeight as B}from"@polotno/core/text-types";let I;function N(){return I||(I=document.getElementById("polotno-text-style"),I||(I=document.createElement("style"),I.id="polotno-text-style",document.head.appendChild(I)),I)}d._fixTextRendering=!0;const J={border:"none",padding:"0px",overflow:"hidden",background:"none",outline:"none",resize:"none",overflowWrap:"break-word",whiteSpace:"pre-wrap",userSelect:"text",wordBreak:"normal",textTransform:"none"};export{getDir}from"@polotno/core/text-html";const _=o(({textNodeRef:e,element:r,onBlur:o,selectAll:i,cursorPosition:a})=>{const[s,l]=n.useState(J),c=e.current;n.useLayoutEffect(()=>{if(!c){return}const t={};t.width=c.width()-2*c.padding()+"px",t.height=c.height()-2*c.padding()+c.fontSize()*c.lineHeight()+"px",t.fontSize=c.fontSize()+"px",t.lineHeight=c.lineHeight()+.01,t.fontFamily=c.fontFamily(),t.textAlign=c.align(),t.color=c.fill(),t.fontWeight=r.fontWeight,t.fontStyle=r.fontStyle,t.letterSpacing=r.letterSpacing+"em",t.opacity=Math.max(r.a.opacity,.2),t.textTransform=r.textTransform,t.caretColor=W(r);const e=`\n .polotno-input::placeholder {\n color: ${s.color};\n opacity: 0.6;\n }\n `,n=N();n.innerHTML="",n.appendChild(document.createTextNode(e)),JSON.stringify(t)!==JSON.stringify(s)&&l(t)});const u=n.useRef(null);if(n.useLayoutEffect(()=>{var t;const e=u.current;if(!e){return}null===(t=u.current)||void 0===t||t.focus({preventScroll:!0});const r=a||e.value.length;e.selectionStart=e.selectionEnd=r,i&&(null==e||e.select(),document.execCommand("selectAll",!1,void 0))},[]),n.useEffect(()=>{window.addEventListener("blur",o);const t=t=>{var e;(null===(e=u.current)||void 0===e?void 0:e.contains(t.target))||o()};return window.addEventListener("touchstart",t),()=>{window.removeEventListener("blur",o),window.removeEventListener("touchstart",t)}},[]),!c){return null}let d=0;const f=c.textArr.length*c.lineHeight()*c.fontSize(),h=B(r.a,f);"middle"===r.verticalAlign&&(d=(h-f)/2),"bottom"===r.verticalAlign&&(d=h-f);const g=R(r.text);return t("textarea",{className:"polotno-input",ref:u,dir:F(g),style:Object.assign(Object.assign(Object.assign({},J),s),{paddingTop:d+"px"}),value:g,onChange:t=>{const e=Y({oldText:r.text,newText:t.target.value,element:r});r.set(Object.assign({text:t.target.value},b(r,e)))},placeholder:D(r.placeholder),onBlur:o})}),V=e=>t(c,{children:t(_,Object.assign({},e))});export const useFontLoader=(t,e,r,o,i)=>{const[a,s]=n.useReducer(t=>t+1,0),l=n.useRef(k(e,r,o)),c=n.useRef(null);return n.useLayoutEffect(()=>{if(l.current=k(e,r,o),l.current){return}let n=!0;return(async()=>{l.current=!1,s();const a=v(`text ${e}`);await t.loadFont(e,r,o,i),n?(c.current=a,l.current=!0,s()):a()})(),()=>{c.current&&(c.current(),c.current=null),n=!1}},[e,r,o]),n.useEffect(()=>{l.current&&setTimeout(()=>{c.current&&(c.current(),c.current=null)})},[l.current]),[l.current]};export const useFontFamiliesLoader=(t,e,r,o,i)=>{const[a,s]=n.useReducer(t=>t+1,0),l=e.join("\0"),c=n.useRef(e.every(t=>k(t,r,o))),u=n.useRef(null);return n.useLayoutEffect(()=>{if(c.current=e.every(t=>k(t,r,o)),c.current){return}let n=!0;return(async()=>{c.current=!1,s();const a=v(`text fonts ${l}`);await Promise.all(e.map(e=>t.loadFont(e,r,o,i))),n?(u.current=a,c.current=!0,s()):a()})(),()=>{u.current&&(u.current(),u.current=null),n=!1}},[l,r,o]),n.useEffect(()=>{c.current&&setTimeout(()=>{u.current&&(u.current(),u.current=null)})},[c.current]),[c.current]};export const getLineHeight=({fontLoaded:t,fontFamily:e,fontSize:r,lineHeight:o})=>n.useMemo(()=>M({fontFamily:e,fontSize:r,lineHeight:o}),[t,e,r,o]);export function usePrevious(t){const e=n.useRef(t),r=n.useRef(t);return n.useMemo(()=>{r.current=e.current,e.current=t},[t]),r.current}function q(t,e,r=!1){const n=t.fontSize(),o=t.height(),i=R(e.text);let a=e.a.fontSize;t.height(void 0);const s=Math.round(2*e.a.fontSize)-1;for(let l=1;l<s;l++){const n=$(e.a)&&t.height()>e.a.height;let o=i.split("\n").join(" ").split(/[\s-]+/).reduce((t,e)=>(e=e.toLowerCase(),/[\u3000-\u303F\u3040-\u309F\u30A0-\u30FF\uFF00-\uFFEF\u4E00-\u9FAF\uAC00-\uD7AF]/.test(e)?t.concat(e.split("")):t.concat(e)),[]),s=t.textArr.map(t=>t.text.toLowerCase()).join(";");const l=o.find(t=>!s.includes(t)||(s=s.replace(t,""),!1));if(!(n||l&&!r)){break}a-=.5,t.fontSize(a)}return t.fontSize(n),t.height(o),a}export{getCurvePath}from"@polotno/core/text-html";export const TextElement=o(({element:o,store:c})=>{const{textOverflowIndicatorStyle:d}=x(),k=n.useRef(null),M=n.useRef(null),Y=n.useRef(null),W=n.useRef([]),I=n.useRef(!0),[,N]=n.useReducer(t=>t+1,0),{editorEnabled:J,selectAll:_}=(t=>{const[e,r]=n.useState(!1),o=n.useRef(!1);return n.useEffect(()=>{var e=!0;return setTimeout(()=>{e&&(t._editModeEnabled&&(o.current=!0),r(!0),setTimeout(()=>{o.current=!1},50))},50),()=>{e=!1}},[]),{editorEnabled:e&&t._editModeEnabled,selectAll:o.current}})(o),[U,Z]=n.useState(!1),[G,K]=n.useState(!1),Q=n.useRef(o.a.height),tt=n.useRef(0),et=n.useRef(""),rt=n.useRef(0),nt=o.isSelected,ot=usePrevious(nt),{textVerticalResizeEnabled:it}=O,at=O.autoDeleteEmptyText,st=usePrevious(o.fontFamily),[lt,ct]=n.useState([]);n.useEffect(()=>{var t,e;const r=null!==(e=null===(t=k.current)||void 0===t?void 0:t.textArr)&&void 0!==e?e:[];JSON.stringify(r)!==JSON.stringify(lt)&&ct(r)}),n.useEffect(()=>{if(o.a.width||"tablecell"===o.type){return}const t=k.current;t.width(600),o.set({width:1.4*t.getTextWidth()})},[]),n.useEffect(()=>{ot&&!nt&&at&&""===o.text&&o.removable&&!D(o.placeholder)&&c.deleteElements([o.id])},[at,o.placeholder,o.removable,o.text,nt,ot]);const ut=()=>{if(o.curveEnabled){const t=k.current;null==t||t.clearCache(),null==t||t.setAttrs({filters:[]});const e=M.current;e&&C(e,o)}else{const t=k.current;t&&C(t,o)}};n.useLayoutEffect(()=>{if(!G){return u(o,()=>{ut()})}}),n.useEffect(()=>{const t=W.current;t.length>0&&(W.current=[],t.forEach(t=>t()))}),n.useEffect(()=>()=>{I.current=!1;const t=W.current;t.length>0&&(W.current=[],t.forEach(t=>t()))},[]);let dt=R(o.text);"uppercase"===o.textTransform&&(dt=dt.toUpperCase());const[ft]=useFontLoader(c,o.fontFamily,o.fontStyle,o.fontWeight,o.text||o.placeholder),ht=()=>{if(o.curveEnabled){const t=M.current;return t.getSelfRect().height||t.fontSize()}const t=k.current.clone({height:void 0}),e=Math.ceil(t.fontSize()*t.lineHeight()*t.textArr.length+1);return t.destroy(),e};n.useLayoutEffect(()=>{if(!ft){return}if("tablecell"===o.type){const{textOverflow:t}=O;if("resize"===t){const t=ht(),e=P(o)?X(o,2):null;(null==e?void 0:e.setCellContentHeight)&&e.setCellContentHeight(o.id,t)}else if("change-font-size"===t){const t=k.current;if(t){const e=q(t,o,O.textSplitAllowed);e!==o.fontSize&&c.history.ignore(()=>{o.set({fontSize:e})})}}return}const{textOverflow:t,textSplitAllowed:e}=O,r=(t,e,r,n)=>{const i=v(`text ${o.id}`),a=()=>{c.history.ignore(t,e,r).then(()=>{I.current?(W.current.push(i),N()):i()})};n?queueMicrotask(a):a()};if(!$(o)){const t=ht();return void r(()=>{$(o)||o.set({height:t})},void 0,void 0,!0)}if(!c.isPlaying){if("change-font-size"!==t||U){if("resize"===t){const t=ht();it&&o.height<t&&!U&&r(()=>{var e;P(o)&&o.set({height:t}),null===(e=k.current)||void 0===e||e.height(t)},!1,!0),it||o.height===t||U||r(()=>{var e;P(o)&&o.set({height:t}),null===(e=k.current)||void 0===e||e.height(t)},!1,!0)}}else{const t=k.current,n=o.curveEnabled?o.fontSize:q(t,o,e);if(n!==o.fontSize){return void r(()=>{o.set(b(o,n))},!1,!0)}const i=ht();o.height===i||it||r(()=>{o.set({height:i})},!1,!0)}}}),n.useLayoutEffect(()=>{var t;if(ft&&o.curveEnabled){const e=null===(t=M.current)||void 0===t?void 0:t.getSelfRect().width;if(e){const t=e-o.a.width,r=o.a.rotation*Math.PI/180,n=-t/2*Math.cos(r),i=-t/2*Math.sin(r);o.set({width:e,x:o.a.x+n,y:o.a.y+i})}}},[ft,o.curveEnabled,o.curvePower,o.text,o.fontSize,o.fontFamily,o.fontWeight,o.fontStyle,o.letterSpacing]),n.useLayoutEffect(()=>{const t=k.current;t&&(t.width(t.width()+1e-8),t.width(t.width()-1e-8),t._setTextData(),ut())},[ft]);const gt=n.useRef(null),pt=n.useRef(o.width),mt=n.useRef(0),xt=t=>{t.evt.preventDefault();const e=c.selectedShapes.find(t=>t===o);e&&o.contentEditable&&(mt.current=function(t){var e;const r=t.target,n=function(t){var e=t.getAbsoluteTransform().copy();e.invert();var r=t.getStage().getPointerPosition();return e.point(r)}(r),o=r.textArr,i=Math.floor(n.y/(r.fontSize()*r.lineHeight())),a=o.slice(0,i).reduce((t,e)=>t+e.text.length,i),s=null!==(e=o[i])&&void 0!==e?e:o[0];let l=0;return"right"===r.align()?l=r.width()-s.width:"center"===r.align()&&(l=r.width()/2-s.width/2),a+Math.round((n.x-l)/s.width*s.text.length)}(t),o.toggleEditMode())},wt=D(o.placeholder),vt=!dt&&wt?.6:o.a.opacity;T(k,vt);const yt=getLineHeight({fontLoaded:ft,fontFamily:o.fontFamily,fontSize:o.a.fontSize,lineHeight:o.lineHeight}),bt=o.selectable||c.role===w.ADMIN,St=m(o),Et=m(o,o.stroke,"stroke"),zt=n.useMemo(()=>o.backgroundEnabled?o.curveEnabled?function({width:t,height:e,padding:r=0,cornerRadius:n=0}){const o=-r,i=-r,a=t+r,s=e+r,l=f(`M ${o} ${i} L ${a} ${i} L ${a} ${s} L ${o} ${s} Z`);return h(l,n).path}({width:o.a.width,height:o.a.height,cornerRadius:o.backgroundCornerRadius*(o.a.fontSize*yt*.5),padding:o.backgroundPadding*(o.a.fontSize*yt*.5)}):function({lines:t,lineHeight:e,width:r,align:n="left",padding:o=0,cornerRadius:i=0}){const a=p({lines:t,lineHeight:e,width:r,align:n});return g({rects:a,padding:o,cornerRadius:i})}({lines:JSON.parse(JSON.stringify(lt)),cornerRadius:o.backgroundCornerRadius*(o.a.fontSize*yt*.5),lineHeight:yt*o.a.fontSize,padding:o.backgroundPadding*(o.a.fontSize*yt*.5),width:o.a.width,align:o.align}):"",[o.backgroundEnabled,o.curveEnabled,o.backgroundCornerRadius,o.a.fontSize,o.a.height,yt,o.backgroundPadding,o.a.width,o.align,lt]),kt=H();let Ot=0;if(!o.curveEnabled){const t=lt.length*yt*o.a.fontSize,e=B(o.a,t);"middle"===o.verticalAlign?Ot=(e-t)/2:"bottom"===o.verticalAlign&&(Ot=e-t)}const Rt=o.curveEnabled?A(o.a.width,o.a.height,o.curvePower,o.a.fontSize):"",Ft=ft?L(o.fontFamily):st===o.fontFamily?"Arial":L(st),At=F(dt);return r(e,{children:[t(a,{ref:Y,x:o.a.x,y:o.a.y,rotation:o.a.rotation,hideInExport:!o.showInExport,listening:!1,visible:o.backgroundEnabled,opacity:o.backgroundOpacity*vt,data:zt,fill:o.backgroundColor,offsetY:-Ot}),t(a,{data:Rt,stroke:d.stroke,strokeWidth:1,x:o.a.x,y:o.a.y,rotation:o.a.rotation,visible:!1}),t(l,Object.assign({ref:M,visible:o.curveEnabled,data:Rt,text:dt||wt,listening:!1,align:"center",textBaseline:"middle",direction:At},St,Et,{strokeWidth:o.strokeWidth,lineJoin:j(o.strokeLineJoin),fillAfterStrokeEnabled:!0,fontSize:o.a.fontSize,fontFamily:`${L(o.fontFamily)}, ${L(st)}`,fontStyle:o.fontStyle+" "+o.fontWeight,textDecoration:o.textDecoration.trim(),letterSpacing:o.letterSpacing*o.a.fontSize,x:o.a.x,y:o.a.y,rotation:o.a.rotation,opacity:o._editModeEnabled?.3:vt,hideInExport:!o.showInExport,shadowEnabled:o.shadowEnabled,shadowBlur:o.shadowBlur,shadowOffsetX:o.shadowOffsetX,shadowOffsetY:o.shadowOffsetY,shadowColor:o.shadowColor,shadowOpacity:o.shadowOpacity})),t(s,Object.assign({ref:k,id:o.selectable?o.id:void 0,name:o.selectable?"element":"",hideInExport:!o.showInExport,editModeEnabled:o._editModeEnabled,x:o.a.x,y:o.a.y,rotation:o.a.rotation,width:o.a.width,height:$(o.a)?o.a.height:void 0,text:dt||wt,direction:At},St,Et,{lineJoin:j(o.strokeLineJoin),strokeWidth:o.strokeWidth,fillAfterStrokeEnabled:!0,fontSize:o.a.fontSize,fontFamily:Ft,fontStyle:o.fontStyle+" "+o.fontWeight,textDecoration:o.textDecoration,align:o.align,verticalAlign:o.verticalAlign,draggable:kt?o.draggable&&nt:o.draggable,preventDefault:!kt||nt,opacity:o.curveEnabled?0:vt,visible:!o._editModeEnabled,ellipsis:"ellipsis"===O.textOverflow,shadowEnabled:o.shadowEnabled,shadowBlur:o.shadowBlur,shadowOffsetX:o.shadowOffsetX,shadowOffsetY:o.shadowOffsetY,shadowColor:o.shadowColor,shadowOpacity:o.shadowOpacity,lineHeight:yt,letterSpacing:o.letterSpacing*o.a.fontSize,listening:!!o.selectable&&bt,onDragStart:()=>{K(!0)},onDragMove:t=>{o.set({x:t.target.x(),y:t.target.y()})},onDragEnd:t=>{K(!1),o.set({x:t.target.x(),y:t.target.y()})},onClick:xt,onTap:xt,onTransformStart:()=>{Z(!0);const t=k.current;Q.current=t.height(),pt.current=o.a.width,gt.current=t.position(),tt.current=t.rotation(),rt.current=t.height(),et.current=y(t)},onTransform:t=>{var e,r;const n=t.target;null===(e=Y.current)||void 0===e||e.setAttrs({x:n.x(),y:n.y(),rotation:n.rotation(),scale:n.scale()});const i=et.current;if("middle-left"===i||"middle-right"===i){const t=n.scaleX(),e=n.width()*t,r=z(pt.current,o.a.fontSize);let i=e;e<r&&(i=r,gt.current&&n.position(gt.current)),n.width(i),n.scaleX(1),n.scaleY(1);let a=ht();if("ellipsis"===O.textOverflow){a=Q.current}else{const t=Math.max(a,Q.current);n.height(t),o.set({height:n.height()})}const s=O.textVerticalResizeEnabled?Math.max(a,Q.current):ht();o.set({x:n.x(),width:n.width(),rotation:n.rotation(),height:s}),n.skewX(0),n.skewY(0),ut()}if("top-center"===i||"bottom-center"===i){const e="resize"===O.textOverflow?ht():yt*o.a.fontSize,r=t.target.height()*t.target.scaleY();if(r<e){if(t.target.height(e),gt.current){if("top-center"===et.current){const r=tt.current*Math.PI/180,n=rt.current-e;t.target.x(gt.current.x-n*Math.sin(r)),t.target.y(gt.current.y+n*Math.cos(r))}else{t.target.position(gt.current)}}}else{t.target.height(r)}t.target.scaleY(1),t.target.scaleX(1),t.target.rotation(tt.current),t.target.skewX(0),t.target.skewY(0),rt.current=Math.max(e,r)}gt.current=t.target.position();const a=t.target.scaleX();null===(r=Y.current)||void 0===r||r.setAttrs({scaleX:1,scaleY:1}),t.target.scaleX(1),t.target.scaleY(1),o.set({fontSize:o.a.fontSize*a,width:t.target.width()*a,x:t.target.x(),y:t.target.y(),rotation:t.target.rotation(),height:t.target.height()*a,shadowBlur:o.shadowBlur*a,shadowOffsetX:o.shadowOffsetX*a,shadowOffsetY:o.shadowOffsetY*a,strokeWidth:o.strokeWidth*a})},onTransformEnd:t=>{var e;const r=t.target.scaleX();t.target.scaleX(1),t.target.scaleY(1),o.set(Object.assign(Object.assign({},S(o,o.fontSize*r)),{width:Math.ceil(t.target.width()*r),x:t.target.x(),y:t.target.y(),rotation:t.target.rotation(),height:t.target.height()*r})),null===(e=Y.current)||void 0===e||e.setAttrs({scaleX:1,scaleY:1}),Z(!1)}})),J&&o.contentEditable&&t(i,{x:o.a.x,y:o.a.y,rotation:o.a.rotation,children:t(V,{textNodeRef:k,element:o,selectAll:_,cursorPosition:mt.current,onBlur:()=>{o.set(E(o)),o.toggleEditMode(!1)}})})]})});
@@ -1 +1 @@
1
- import e from"react";import{nodeAutorun as r}from"../utils/mobx.js";import{Input as t,UrlSource as n,BufferSource as u,CanvasSink as a,ALL_FORMATS as i}from"mediabunny";import{incrementLoader as c,triggerLoadError as o}from"../utils/loader.js";import{polotnoError as s}from"@polotno/core/errors";import{getElementTimeRange as l,getVideoRestMs as d}from"../utils/timeline.js";const f=.05;export const useMediabunnyVideo=(m,p,g)=>{const[h,v]=e.useState({input:null,videoSink:null,duration:0,isReady:!1,error:null});e.useRef(h).current=h;const w=e.useRef(0),b=e.useRef(null),y=e.useRef(null),T=e.useRef(null),R=e.useRef(null),k=e.useRef(null),E=e.useRef(null),S=e.useRef(!1),$=e.useRef(null),x=e.useRef([]),O=e.useRef(null),I=e.useRef(!1),[,D]=e.useReducer(e=>e+1,0);return e.useEffect(()=>{if(!g){return}let e=!0;const r=++w.current;let l=null;return(async()=>{try{if(!e||r!==w.current){return}l=c(`mediabunny init ${m.id}`);const o=await async function(e){if(function(e){return e.startsWith("data:")}(e)){const r=function(e){const r=e.indexOf(",");if(-1===r){throw new Error("Invalid data URL format")}const t=e.slice(r+1),n=atob(t),u=new Uint8Array(n.length);for(let a=0;a<n.length;a++){u[a]=n.charCodeAt(a)}return u.buffer}(e);return new u(r)}if(function(e){return e.startsWith("file://")}(e)){try{const r=await fetch(e),t=await r.arrayBuffer();return new u(t)}catch(r){throw new Error(`Failed to load file URL: ${e}. File URLs may not be supported in this environment. Error: ${r}`)}}return new n(e)}(m.src);if(!e||r!==w.current){return void(l&&(l(),l=null))}const d=new t({source:o,formats:i}),f=await d.computeDuration(),p=await d.getPrimaryVideoTrack();if(!p){throw s("VIDEO_FAILED","No video track found",{reason:"no-video-track"})}if(null===p.codec){throw s("VIDEO_FAILED","Unsupported video codec",{reason:"unsupported-codec"})}if(!await p.canDecode()){throw s("VIDEO_FAILED","Unable to decode the video track",{reason:"cannot-decode"})}const g=await p.canBeTransparent(),h=new a(p,{poolSize:5,fit:"contain",alpha:g});if(!e||r!==w.current){return d.dispose(),void(l&&(l(),l=null))}l&&(l(),l=null),v(e=>Object.assign(Object.assign({},e),{input:d,videoSink:h,duration:f,isReady:!0,error:null}))}catch(d){if(console.error("Failed to initialize mediabunny:",d),l&&(l(),l=null),e&&r===w.current){const e=`Failed to initialize mediabunny for video ${m.id}: ${d}`;o(s("VIDEO_FAILED",e,Object.assign({reason:"load"},null==d?void 0:d.details),d)),v(e=>Object.assign(Object.assign({},e),{error:String(d),isReady:!1}))}}})(),()=>{e=!1,l&&(l(),l=null)}},[m.src,g]),e.useEffect(()=>()=>{y.current&&(y.current.return(),y.current=null),b.current&&(b.current(),b.current=null),T.current=null,R.current=null,k.current=null,S.current=!1,$.current=null,x.current=[],O.current=null,I.current=!1,v({input:null,videoSink:null,duration:0,isReady:!1,error:null})},[g]),e.useEffect(()=>{if(!g||!h.isReady||!h.videoSink){return}const e=++w.current,t="string"==typeof m.src?m.src.slice(0,120):String(m.src),n=(e,r={},n="debug")=>{let u="";try{u=JSON.stringify(Object.assign(Object.assign({},r),{timeCalc:E.current}))}catch(i){u=`[unserializable extras: ${String(i)}]`}const a=`mediabunny event=${e} elementId=${m.id} targetTime=${k.current} duration=${h.duration} lastFrameTimestamp=${R.current} hasIterator=${Boolean(y.current)} prefetchSize=${x.current.length} srcHint=${t} extras=${u}`;"error"===n?console.error(a):"warn"===n?console.warn(a):console.debug(a)},u=e=>{const r=h.duration||0;if(!r||!Number.isFinite(r)){return e}const t=r>f?r-f:r;return Math.max(0,Math.min(e,t))},a=e=>{const r=h.duration||0;return!(!r||!Number.isFinite(r))&&r-e<=.050001000000000004},i=e=>{let r=T.current;r&&r.width===e.canvas.width&&r.height===e.canvas.height||(r||(r=document.createElement("canvas"),T.current=r),r.width=e.canvas.width,r.height=e.canvas.height);const t=r.getContext("2d");t&&(t.clearRect(0,0,r.width,r.height),t.drawImage(e.canvas,0,0)),R.current=e.timestamp},o=e=>{const r=y.current;r&&(I.current||(I.current=!0,O.current=(async()=>{try{for(;x.current.length<4&&e===w.current;){const t=await r.next();if(e!==w.current){return}if(t.done||!t.value){break}x.current.push({timestamp:t.value.timestamp,frame:t.value})}}catch(t){}finally{I.current=!1,O.current=null}})()))},s=e=>{const r=x.current;for(let t=0;t<r.length;t++){if(Math.abs(r[t].timestamp-e)<f){const e=r[t];return x.current=r.slice(t+1),e}}return null},v=()=>{x.current=[]},F=async(e,r,t=0)=>{const c=u(e),l=(e=>{const r=R.current;return null===r||e<r-f||e>r+.5})(c)?"seek":"iterate";try{const t=h.videoSink,u=R.current;if(null!==u&&Math.abs(u-c)<f){return void(k.current=e)}const m=s(c);if(m){return i(m.frame),k.current=e,o(r),void D()}if(O.current){await O.current;const t=s(c);if(t){return i(t.frame),k.current=e,o(r),void D()}}if(v(),"seek"===l){y.current&&(await y.current.return(),y.current=null);const u=t.canvases(c);y.current=u;const s=await u.next();if(r!==w.current){return void(y.current&&(await y.current.return(),y.current=null))}if(s.done||!s.value){if(a(c)||n("iterator_exhausted",{mode:l,requestedTargetTime:e,clampedTargetTime:c},"warn"),r===w.current&&!a(c)){try{y.current&&(await y.current.return(),y.current=null),v();const n=t.canvases(c);y.current=n;const u=await n.next();!u.done&&u.value&&(i(u.value),o(r),k.current=e,D())}catch(d){}}return}i(s.value),o(r)}else{const u=y.current;if(!u){return}let s=!1;for(;r===w.current;){const m=await u.next();if(r!==w.current){break}if(m.done||!m.value){if(a(c)||n("iterator_exhausted",{mode:l,requestedTargetTime:e,clampedTargetTime:c},"warn"),!s&&!a(c)){s=!0;try{y.current&&(await y.current.return(),y.current=null),v();const e=t.canvases(c);y.current=e;const n=await e.next();if(r!==w.current){break}if(n.done||!n.value){break}i(n.value),o(r);break}catch(d){break}}break}const p=m.value;if(i(p),Math.abs(p.timestamp-c)<f){o(r);break}if(p.timestamp>c){o(r);break}}}k.current=e,D()}catch(m){const u=m instanceof Error?{name:m.name,message:m.message,stack:m.stack}:{message:String(m)},a=m instanceof Error?`${m.name}: ${m.message}`:String(m),i=a.includes("Unsupported configuration")||a.includes("isConfigSupported")||a.includes("OperationError");if(n("frame_process_failed",{mode:l,requestedTargetTime:e,clampedTargetTime:c,unsupportedConfigAttempt:t,isUnsupportedConfig:i,error:u},"error"),i&&t<1){try{y.current&&(await y.current.return(),y.current=null),v(),O.current=null,I.current=!1,R.current=null,await F(e,r,t+1)}catch(d){}}}},j=r(m,()=>{const r=h.videoSink,t=h.duration;if(!r||!t){return}const n=m.startTime*t*1e3,a=t*(m.endTime-m.startTime)*1e3,{start:i}=l(m.animations,m.page.duration),o=d(p.currentTime,m.page.startTime,i,a,n,m.speed),s=o/1e3,f=u(s);E.current={pageStartTime:m.page.startTime,storeCurrentTime:p.currentTime,offsetMs:n,durationMs:a,restMs:o,targetTime:s,clampedTargetTime:f,startTime:m.startTime,endTime:m.endTime,videoDuration:t},((e,r)=>{S.current?$.current=e:(S.current=!0,b.current||(b.current=c(`mediabunny video frame ${m.id}`)),(async()=>{let t=e;for(;null!==t&&r===w.current;){await F(t,r),t=$.current,$.current=null}b.current&&(b.current(),b.current=null),S.current=!1})())})(f,e)});return()=>{j(),w.current++,b.current&&(b.current(),b.current=null)}},[g,h.isReady,h.videoSink,h.duration,p,m]),g&&h.isReady?T.current:null};
1
+ import e from"react";import{nodeAutorun as r}from"../utils/mobx.js";import{Input as t,UrlSource as n,BufferSource as u,CanvasSink as i,ALL_FORMATS as a}from"mediabunny";import{incrementLoader as c,triggerLoadError as o}from"../utils/loader.js";import{polotnoError as s}from"@polotno/core/errors";import{getElementTimeRange as l,getVideoRestMs as d}from"../utils/timeline.js";import{decodeBase64 as m}from"../utils/base64.js";function f(e,r){const t=p(e);return t>0&&r>=e.timestamp&&r<e.timestamp+t}function p(e){var r;const t=null!==(r=e.duration)&&void 0!==r?r:0;return Number.isFinite(t)&&t>0?t:0}export const useMediabunnyVideo=(g,v,h)=>{const[w,y]=e.useState({input:null,videoSink:null,duration:0,isReady:!1,error:null});e.useRef(w).current=w;const b=e.useRef(0),T=e.useRef(null),R=e.useRef(null),k=e.useRef(null),E=e.useRef(null),S=e.useRef(null),$=e.useRef(null),O=e.useRef(!1),I=e.useRef(null),j=e.useRef([]),x=e.useRef(null),D=e.useRef(!1),[,F]=e.useReducer(e=>e+1,0);return e.useEffect(()=>{if(!h){return}let e=!0;const r=++b.current;let l=null;return(async()=>{try{if(!e||r!==b.current){return}l=c(`mediabunny init ${g.id}`);const o=await async function(e){if(function(e){return e.startsWith("data:")}(e)){const r=function(e){const r=e.indexOf(",");if(-1===r){throw new Error("Invalid data URL format")}return m(e.slice(r+1)).buffer}(e);return new u(r)}if(function(e){return e.startsWith("file://")}(e)){try{const r=await fetch(e),t=await r.arrayBuffer();return new u(t)}catch(r){throw new Error(`Failed to load file URL: ${e}. File URLs may not be supported in this environment. Error: ${r}`)}}return new n(e)}(g.src);if(!e||r!==b.current){return void(l&&(l(),l=null))}const d=new t({source:o,formats:a}),f=await d.computeDuration(),p=await d.getPrimaryVideoTrack();if(!p){throw s("VIDEO_FAILED","No video track found",{reason:"no-video-track"})}if(null===p.codec){throw s("VIDEO_FAILED","Unsupported video codec",{reason:"unsupported-codec"})}if(!await p.canDecode()){throw s("VIDEO_FAILED","Unable to decode the video track",{reason:"cannot-decode"})}const v=await p.canBeTransparent(),h=new i(p,{poolSize:5,fit:"contain",alpha:v});if(!e||r!==b.current){return d.dispose(),void(l&&(l(),l=null))}l&&(l(),l=null),y(e=>Object.assign(Object.assign({},e),{input:d,videoSink:h,duration:f,isReady:!0,error:null}))}catch(d){if(console.error("Failed to initialize mediabunny:",d),l&&(l(),l=null),e&&r===b.current){const e=`Failed to initialize mediabunny for video ${g.id}: ${d}`;o(s("VIDEO_FAILED",e,Object.assign({reason:"load"},null==d?void 0:d.details),d)),y(e=>Object.assign(Object.assign({},e),{error:String(d),isReady:!1}))}}})(),()=>{e=!1,l&&(l(),l=null)}},[g.src,h]),e.useEffect(()=>()=>{R.current&&(R.current.return(),R.current=null),T.current&&(T.current(),T.current=null),k.current=null,E.current=null,S.current=null,O.current=!1,I.current=null,j.current=[],x.current=null,D.current=!1,y({input:null,videoSink:null,duration:0,isReady:!1,error:null})},[h]),e.useEffect(()=>{if(!h||!w.isReady||!w.videoSink){return}const e=++b.current,t="string"==typeof g.src?g.src.slice(0,120):String(g.src),n=(e,r={},n="debug")=>{var u;let i="";try{i=JSON.stringify(Object.assign(Object.assign({},r),{timeCalc:$.current}))}catch(c){i=`[unserializable extras: ${String(c)}]`}const a=`mediabunny event=${e} elementId=${g.id} targetTime=${S.current} duration=${w.duration} lastFrameTimestamp=${null===(u=E.current)||void 0===u?void 0:u.timestamp} hasIterator=${Boolean(R.current)} prefetchSize=${j.current.length} srcHint=${t} extras=${i}`;"error"===n?console.error(a):"warn"===n?console.warn(a):console.debug(a)},u=e=>{const r=w.duration||0;return r&&Number.isFinite(r)?Math.max(0,Math.min(e,r)):e},i=e=>{let r=k.current;r&&r.width===e.canvas.width&&r.height===e.canvas.height||(r||(r=document.createElement("canvas"),k.current=r),r.width=e.canvas.width,r.height=e.canvas.height);const t=r.getContext("2d");t&&(t.clearRect(0,0,r.width,r.height),t.drawImage(e.canvas,0,0)),E.current={timestamp:e.timestamp,duration:p(e)}},a=e=>{const r=R.current;r&&(D.current||(D.current=!0,x.current=(async()=>{try{for(;j.current.length<4&&e===b.current;){const t=await r.next();if(e!==b.current){return}if(t.done||!t.value){break}j.current.push({timestamp:t.value.timestamp,frame:t.value})}}catch(t){}finally{D.current=!1,x.current=null}})()))},o=e=>{const r=j.current;let t=-1;for(let u=0;u<r.length&&!(r[u].timestamp>e);u++){t=u}if(-1===t){return null}const n=r[t];return t<r.length-1||f(n.frame,e)?(j.current=r.slice(t+1),n):null},s=()=>{j.current=[]},m=async(e,r,t=0)=>{const c=u(e),l=(e=>{const r=E.current;return!r||e<r.timestamp||e>r.timestamp+.5})(c)?"seek":"iterate";try{const t=w.videoSink,u=E.current;if(u&&f(u,c)){return void(S.current=e)}const d=o(c);if(d){return i(d.frame),S.current=e,a(r),void F()}if(x.current){await x.current;const t=o(c);if(t){return i(t.frame),S.current=e,a(r),void F()}}s();const m=()=>n("iterator_exhausted",{mode:l,requestedTargetTime:e,clampedTargetTime:c},"warn"),p=async e=>{R.current&&(await R.current.return(),R.current=null),s();const n=t.canvases(e);R.current=n;const u=await n.next();return r!==b.current?(await n.return(),R.current===n&&(R.current=null),"cancelled"):u.done||!u.value?"empty":(i(u.value),a(r),"drawn")};if("seek"===l){const e=await p(c);if("cancelled"===e){return}if("empty"===e){return void m()}}else{const e=R.current;if(!e){return}for(;r===b.current;){const t=await e.next();if(r!==b.current){break}if(t.done||!t.value){"empty"===await p(c)&&m();break}const n=t.value;if(i(n),f(n,c)||n.timestamp>=c){a(r);break}}}S.current=e,F()}catch(d){const u=d instanceof Error?{name:d.name,message:d.message,stack:d.stack}:{message:String(d)},i=d instanceof Error?`${d.name}: ${d.message}`:String(d),a=i.includes("Unsupported configuration")||i.includes("isConfigSupported")||i.includes("OperationError");if(n("frame_process_failed",{mode:l,requestedTargetTime:e,clampedTargetTime:c,unsupportedConfigAttempt:t,isUnsupportedConfig:a,error:u},"error"),a&&t<1){try{R.current&&(await R.current.return(),R.current=null),s(),x.current=null,D.current=!1,E.current=null,await m(e,r,t+1)}catch(p){}}}},y=r(g,()=>{const r=w.videoSink,t=w.duration;if(!r||!t){return}const n=g.startTime*t*1e3,i=t*(g.endTime-g.startTime)*1e3,{start:a}=l(g.animations,g.page.duration),o=d(v.currentTime,g.page.startTime,a,i,n,g.speed),s=o/1e3+1e-6,f=u(s);$.current={pageStartTime:g.page.startTime,storeCurrentTime:v.currentTime,offsetMs:n,durationMs:i,restMs:o,targetTime:s,clampedTargetTime:f,startTime:g.startTime,endTime:g.endTime,videoDuration:t},((e,r)=>{O.current?I.current=e:(O.current=!0,T.current||(T.current=c(`mediabunny video frame ${g.id}`)),(async()=>{let t=e;for(;null!==t&&r===b.current;){await m(t,r),t=I.current,I.current=null}T.current&&(T.current(),T.current=null),O.current=!1})())})(s,e)});return()=>{y(),b.current++,T.current&&(T.current(),T.current=null)}},[h,w.isReady,w.videoSink,w.duration,v,g]),h&&w.isReady?k.current:null};
@@ -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{nodeAutorun as n}from"../utils/mobx.js";import{Arc as a,Group as d,Image as h,Rect as s,Text as l,Transformer as c}from"react-konva";import{ROLES as u}from"../model/store.js";import g from"use-image";import m from"konva";import{Portal as f}from"react-konva-utils";import{useWorkspaceStyle as p}from"./workspace-style.js";import{incrementLoader as v,triggerLoadError as w}from"../utils/loader.js";import{polotnoError as x}from"@polotno/core/errors";import{getCropRect as M}from"@polotno/core/image";import*as y from"@polotno/core/svg";import{flags as E}from"../utils/flags.js";import{roundEnabledPx as b,isCornerAnchor as L,scaledBoxStyleAttrs as T,roundedBoxStyleAttrs as C}from"../utils/px.js";import{useFilteredSource as S}from"./use-filtered-source.js";import{useEvent as R}from"../hooks/use-event.js";import{useFadeIn as I}from"./use-fadein.js";import{isTouchDevice as k}from"../utils/screen.js";import{createPlayGate as H,playMedia as W}from"../utils/media.js";import{useMediabunnyVideo as X}from"./use-mediabunny-video.js";import{getElementTimeRange as Y,getVideoRestMs as O}from"../utils/timeline.js";function j(){return document.createElement("canvas")}const A=new window.Image;A.src=y.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 P=new window.Image;P.src=y.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)&&E.imageDownScalingEnabled&&u<1&&!a,f=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===f&&r.height===p,w=i.useMemo(()=>{if(t&&f&&p){return v&&0===c&&!g?void 0:j()}},[t,c,g,v,f,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=j(),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&&m.Util.releaseCanvas(w)},[w]),[w||t,x]};const _=j(),V=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 m.Animation(t=>{e.rotate(((null==t?void 0:t.timeDiff)||0)/2)},e.getLayer());return t.start(),()=>{t.stop()}});const{mediaLoadingStyle:h}=p();return t(d,{x:r.a.x,y:r.a.y,rotation:r.a.rotation,listening:!1,opacity:r.a.opacity,hideInExport:!r.showInExport,children:[e(s,{width:r.width,height:r.height,fill:h.fill}),e(a,{ref:n,x:r.width/2,y:r.height/2,fill:h.textFill,outerRadius:Math.abs(o),innerRadius:Math.max(1,o-5),angle:270})]})}),D=o(({element:r})=>{const{mediaErrorStyle:i}=p(),o=Math.max(10,Math.min(30,r.width/25));return t(d,{x:r.a.x,y:r.a.y,rotation:r.a.rotation,listening:!1,opacity:r.a.opacity,hideInExport:!r.showInExport,children:[e(s,{width:r.width,height:r.height,fill:i.fill}),e(l,{text:"Can not load the video...",fontSize:o,width:r.width,height:r.height,align:"center",fill:i.textFill,verticalAlign:"middle",padding:5})]})});let z=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=>{z=e};function B(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=v(a)),"loading"!==e&&n(),"failed"===e&&w(x("VIDEO_FAILED",a,{src:i,elementId:r,reason:"load"}))},[e])};export const VideoElement=o(({element:o,store:a})=>{var l,p,w;const[x,E]=i.useState(!1),U=i.useRef(null),F=i.useRef(null),N=o.isSelected,[Z,$]=i.useState(!1),[q,G]=z(o.src,"anonymous"),[J,K]=i.useState(!1),Q=a.activePage===o.page,ee=(null===(l=o.page)||void 0===l?void 0:l._exportingOrRendering)&&"loaded"===G,te=X(o,a,ee);useLoader(G,o.src,o.id),q&&(q.playsInline=!0);const re=((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=j();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&&m.Util.releaseCanvas(o)},[o]),o})(o,q,a._elementsPixelRatio),ie=ee&&te||re||_,[oe=_,ne]=S(o,ie);i.useEffect(()=>{q&&a.history.ignore(()=>{o.set({duration:1e3*q.duration})})},[q]);const ae=i.useMemo(H,[q]);i.useEffect(()=>{var e;if(!q){return}const t=a.animatedElementsIds,r=(!t.length||t.includes(o.id))&&a.isPlaying;if(!Q||!r&&!Z){return void q.pause()}Z&&(q.muted=!1,q.currentTime=o.startTime*q.duration,W(q).then(e=>{"refused"===e&&$(!1)}));const i=new m.Animation(()=>{Le()},null===(e=U.current)||void 0===e?void 0:e.getLayer());i.start();const n=()=>{$(!1),q.currentTime=o.startTime*q.duration},d=()=>{q.currentTime>=o.endTime*q.duration&&(q.pause(),q.currentTime=o.startTime*q.duration,$(!1))};return q.addEventListener("ended",n),q.addEventListener("timeupdate",d),()=>{q.pause(),i.stop(),q.removeEventListener("ended",n),q.removeEventListener("timeupdate",d)}},[q,Z,a.isPlaying,Q]),i.useEffect(()=>{q&&(q.volume=o.volume)},[q,o.volume]),i.useEffect(()=>{q&&(q.playbackRate=o.speed,q.preservesPitch=!1)},[q,o.speed]);const de=i.useRef(null);i.useEffect(()=>{const e=n(o,()=>{var e,t;if(q){if(ee&&te){return Le(),void a.currentTime}const r=a.animatedElementsIds;if(r.length&&!r.includes(o.id)){return}const i=a.activePage===o.page,n=a.currentTime>=o.page.startTime&&a.currentTime<o.page.startTime+o.page.duration,d=o.startTime*q.duration*1e3,h=q.duration*(o.endTime-o.startTime)*1e3,{start:s,end:l}=Y(o.animations,o.page.duration),c=(a.currentTime||o.page.startTime)-o.page.startTime,u=n?O(a.currentTime,o.page.startTime,s,h,d,o.speed):0,g=u/1e3,m=n&&c>=s&&c<l;Z||(q.muted=!m,m&&a.isPlaying&&i?q.paused?(q.currentTime=g,ae.play(q)):Math.abs(1e3*q.currentTime-u)>500&&(q.currentTime=g):(ae.reset(),q.paused||q.pause(),g!==q.currentTime&&(q.currentTime=g),!B(q)&&!a.isPlaying&&!de.current&&(de.current=v(`video ${o.id}`)))),Le(),null===(t=null===(e=U.current)||void 0===e?void 0:e.getLayer())||void 0===t||t.batchDraw()}});return()=>{e(),de.current&&(de.current(),de.current=null)}},[a,q,ee,te,Z]),i.useEffect(()=>{var e,t;if(!q){return}if(ee){return null===(e=de.current)||void 0===e||e.call(de),void(de.current=null)}const r=()=>{var e,t,r;!B(q)&&(null===(e=o.page)||void 0===e?void 0:e._exportingOrRendering)||de.current&&(Le(),null===(r=null===(t=U.current)||void 0===t?void 0:t.getLayer())||void 0===r||r.batchDraw(),de.current(),de.current=null)};let i;return(null===(t=o.page)||void 0===t?void 0:t._exportingOrRendering)&&(i=setInterval(r,20)),q.addEventListener("timeupdate",r),q.addEventListener("canplay",r),()=>{clearInterval(i),q.removeEventListener("timeupdate",r),q.removeEventListener("canplay",r)}},[null===(p=o.page)||void 0===p?void 0:p._exportingOrRendering,q,o.id,v,ee]);let{cropX:he,cropY:se,cropWidth:le,cropHeight:ce}=o;"loaded"!==G&&(he=se=0,le=ce=1);const ue=(ge=oe)instanceof HTMLVideoElement?ge.videoWidth:(null==ge?void 0:ge.width)||0;var ge;const me=(e=>e instanceof HTMLVideoElement?e.videoHeight:(null==e?void 0:e.height)||0)(oe),fe=M({cropX:he,cropY:se,cropWidth:le,cropHeight:ce,width:o.width,height:o.height},{width:ue,height:me}),pe=fe.width,ve=fe.height,we="svg"===o.type,xe=null!==(w=o.cornerRadius)&&void 0!==w?w:0,[Me,ye]=useCornerRadiusAndCrop(o,oe,fe,a._elementsPixelRatio,xe,!0);let[Ee,be]=((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 y.urlToString(e),r=y.fixSize(t);return y.svgToURL(r)}(e);i!==t&&r(i)})()},[e]),t})(e.clipSrc||""),[a,d]=g(n,"anonymous"),h=e.clipSrc?d:"loaded";useLoader(h,e.clipSrc,e.id);const s=i.useMemo(()=>{if(t&&a){return j()}},[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=j(),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),m.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,Me,a._elementsPixelRatio,[fe,xe,a._elementsPixelRatio]);const Le=R(()=>{var e,t;ne(),ye(),be(),null===(t=null===(e=U.current)||void 0===e?void 0:e.getLayer())||void 0===t||t.batchDraw()});i.useEffect(()=>{Le()});const Te=Math.max(o.width/pe,o.height/ve);i.useEffect(()=>{var e;if(!o._cropModeEnabled){return}const t=null===(e=U.current)||void 0===e?void 0:e.getStage();function r(e){o._cropModeEnabled&&e.target!==F.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 Ce=i.useRef(null),Se=i.useRef(null),Re=i.useRef(null);i.useLayoutEffect(()=>{o._cropModeEnabled&&(Se.current.nodes([Ce.current]),Re.current.nodes([F.current]))},[o._cropModeEnabled]);const Ie=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,pe/t),n=Math.min(1,ve/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*ue,y:-s*me,scaleX:1,scaleY:1}),o.set({cropX:d,cropY:s,cropWidth:i,cropHeight:n})},ke=()=>{"svg"!==o.type&&o.contentEditable&&setTimeout(()=>{o.toggleCropMode(!0)})},He="loading"===G,We="failed"===G,Xe=!He&&!We,Ye=i.useRef({cropX:0,cropY:0,cropWidth:0,cropHeight:0}),Oe=Xe?o.a.opacity:0;I(U,Oe);const je=o.selectable||a.role===u.ADMIN,Ae=k();return e(r,{children:t(d,{onMouseEnter:()=>K(!0),onMouseLeave:()=>K(!1),children:[He&&e(V,{element:o}),We&&e(D,{element:o}),e(h,{ref:U,name:"element",id:o.id,image:Ee,x:o.a.x,y:o.a.y,width:o.a.width||1,height:o.a.height||1,rotation:o.a.rotation,opacity:Oe,shadowEnabled:o.shadowEnabled,shadowBlur:o.shadowBlur,shadowOffsetX:o.shadowOffsetX,shadowOffsetY:o.shadowOffsetY,shadowColor:o.shadowColor,shadowOpacity:o.shadowOpacity,customCrop:fe,listening:je,draggable:Ae?o.draggable&&N:o.draggable,preventDefault:!Ae||N,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:ke,onDblTap:ke,onTransformStart:()=>{E(!0),Ye.current={cropX:o.cropX,cropY:o.cropY,cropWidth:o.cropWidth,cropHeight:o.cropHeight}},onTransform:e=>{var t,r;const i=e.currentTarget,n=Math.abs(i.scaleX()-1)<1e-7?1:i.scaleX(),a=Math.abs(i.scaleY()-1)<1e-7?1:i.scaleY();i.scaleX(1),i.scaleY(1);const d=null===(t=e.target.getStage())||void 0===t?void 0:t.findOne("Transformer"),h=1-pe/ue,s=Math.min(h,Math.max(0,o.cropX)),l=1-ve/me,c=Math.min(l,Math.max(0,o.cropY)),u=L(null!==(r=d.getActiveAnchor())&&void 0!==r?r:""),g=!u&&n<1&&Ye.current.cropHeight>ve/me;let m=u?o.cropWidth:o.cropWidth*n;g&&(m=o.cropWidth);const f=!u&&a<1&&Ye.current.cropWidth>pe/ue;let p=u?o.cropHeight:o.cropHeight*a;f&&(p=o.cropHeight),we&&(m=o.cropWidth,p=o.cropHeight);const v=u?Math.min(n,a):1;o.set(Object.assign({cropX:s,cropY:c,x:i.x(),y:i.y(),width:i.width()*n,height:i.height()*a,rotation:e.target.rotation(),cropWidth:Math.min(m,1-s),cropHeight:Math.min(p,1-c)},1!==v&&Object.assign(Object.assign({},T(o,v)),{borderSize:o.borderSize*v})))},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:pe/ue,cropHeight:ve/me},C(o)),{borderSize:b(o.borderSize)})),E(!1)}}),e(s,{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:Oe,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,xe-o.borderSize),hideInExport:!o.showInExport}),!a.isPlaying&&e(h,{image:Z?J||Ae?P:void 0:A,x:o.a.x,y:o.a.y,offsetX:-o.a.width/2+15/a.scale,offsetY:-o.a.height/2+15/a.scale,rotation:o.a.rotation,width:30/a.scale,height:30/a.scale,hideInExport:!0,onClick:()=>$(!Z),onTap:()=>$(!Z)}),o._cropModeEnabled&&t(f,{selector:".page-abs-container",enabled:!0,children:[e(s,{x:-window.innerWidth/a.scale,y:-window.innerWidth/a.scale,width:window.innerWidth/a.scale*3,height:window.innerWidth/a.scale*3,fill:"rgba(0,0,0,0.3)"}),e(h,{listening:!1,image:Ee,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(d,{x:o.a.x,y:o.a.y,rotation:o.a.rotation,scaleX:Te,scaleY:Te,children:[e(h,{image:oe,ref:F,width:ue,height:me,opacity:.4,draggable:!0,x:-o.cropX*ue,y:-o.cropY*me,onDragMove:Ie,onTransform:Ie}),e(c,{ref:Re,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(s,{width:pe,height:ve,ref:Ce,listening:!1,onTransform:e=>{e.target.x()<-o.cropX*ue-1e-9&&(e.target.x(-o.cropX*ue),e.target.scaleX(1)),e.target.y()<-o.cropY*me-1e-9&&(e.target.y(-o.cropY*me),e.target.scaleY(1));const t=Math.min(1,Math.max(0,o.cropX+e.target.x()/ue)),r=Math.min(1,Math.max(0,e.target.y()/me+o.cropY)),i=e.target.width()*e.target.scaleX(),n=e.target.height()*e.target.scaleY(),a=Math.min(1-t,i/ue),d=Math.min(1-r,n/me),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*Te,ue*(1-t)*Te),height:Math.min(n*Te,me*(1-r)*Te)})}}),e(c,{ref:Se,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>;
@@ -1 +1 @@
1
- import{observable as e}from"mobx";import{Shape as o}from"./shape-model.js";export const ImageElement=o.named("Image").props({type:"image",width:100,height:100,src:"",cropX:0,cropY:0,cropWidth:1,cropHeight:1,cornerRadius:0,flipX:!1,flipY:!1,clipSrc:"",borderColor:"black",borderSize:0,keepRatio:!1,stretchEnabled:!1}).extend(o=>{const r=e.box(!1);let t=!1;return{views:{get _cropModeEnabled(){return r.get()}},actions:{toggleCropMode(e){const s=null!=e?e:!r.get();r.set(s),s&&!t?(o.store.history.startTransaction(),t=!0):!s&&t&&(o.store.history.endTransaction(),t=!1)},beforeDestroy(){t&&(o.store.history.endTransaction(),t=!1)}}}});
1
+ import{observable as e}from"mobx";import{Shape as o}from"./shape-model.js";export const ImageElement=o.named("Image").props({type:"image",width:100,height:100,src:"",cropX:0,cropY:0,cropWidth:1,cropHeight:1,cornerRadius:0,flipX:!1,flipY:!1,clipSrc:"",borderColor:"black",borderSize:0,keepRatio:!1,stretchEnabled:!1}).extend(o=>{const r=e.box(!1);let t=!1;return{views:{get _cropModeEnabled(){return r.get()}},actions:{toggleCropMode(e){var n;const i=null!=e?e:!r.get();r.set(i);const s=null===(n=o.store)||void 0===n?void 0:n.history;s&&(i&&!t?(s.startTransaction(),t=!0):!i&&t&&(s.endTransaction(),t=!1))},beforeDestroy(){t&&(o.store.history.endTransaction(),t=!1)}}}});
@@ -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>;