polotno 4.22.1 → 4.24.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 (91) hide show
  1. package/THIRD_PARTY_NOTICES.md +7 -7
  2. package/blueprint/toolbar/color-picker.js +2 -2
  3. package/canvas/apply-filters.js +1 -1
  4. package/canvas/downscale.d.ts +1 -1
  5. package/canvas/downscale.js +1 -1
  6. package/canvas/element.js +1 -1
  7. package/canvas/fade-overlay.d.ts +5 -0
  8. package/canvas/fade-overlay.js +1 -1
  9. package/canvas/hotkeys.js +1 -1
  10. package/canvas/html-element.js +1 -1
  11. package/canvas/image-element.js +1 -1
  12. package/canvas/line-element.js +1 -1
  13. package/canvas/page.js +1 -1
  14. package/canvas/quill-font-formats.d.ts +1 -0
  15. package/canvas/quill-font-formats.js +1 -1
  16. package/canvas/radial-gradient-handle.d.ts +14 -0
  17. package/canvas/radial-gradient-handle.js +1 -0
  18. package/canvas/render-tag-element.js +1 -1
  19. package/canvas/rich-editor.d.ts +2 -0
  20. package/canvas/rich-editor.js +12 -6
  21. package/canvas/text-element/legacy-padding-warning.d.ts +6 -0
  22. package/canvas/text-element/legacy-padding-warning.js +1 -0
  23. package/canvas/text-element/max-font-size.js +1 -1
  24. package/canvas/text-element.js +1 -1
  25. package/canvas/use-color.d.ts +24 -2
  26. package/canvas/use-color.js +1 -1
  27. package/canvas/video-element.js +1 -1
  28. package/icons/registry.d.ts +1 -0
  29. package/icons/registry.js +1 -1
  30. package/image-tools/raster.js +1 -1
  31. package/model/group-model.d.ts +26 -10
  32. package/model/group-model.js +1 -1
  33. package/model/node-model.d.ts +10 -1
  34. package/model/node-model.js +1 -1
  35. package/model/page-model.d.ts +75 -33
  36. package/model/page-model.js +1 -1
  37. package/model/table-model.d.ts +29 -9
  38. package/model/table-model.js +1 -1
  39. package/model/text-model.d.ts +5 -1
  40. package/model/text-model.js +1 -1
  41. package/package.json +16 -16
  42. package/polotno.bundle.js +194 -202
  43. package/primitives/field-group.js +1 -1
  44. package/primitives/popover.d.ts +1 -1
  45. package/primitives/popover.js +1 -1
  46. package/primitives/slider-field.js +1 -1
  47. package/side-panel/effect-card.js +1 -1
  48. package/side-panel/effects-panel.js +1 -1
  49. package/side-panel/images-grid.js +1 -1
  50. package/side-panel/layers-panel.js +1 -1
  51. package/side-panel/tab-button.js +1 -3
  52. package/side-panel/templates-panel.js +1 -1
  53. package/toolbar/color-picker.js +1 -1
  54. package/toolbar/gradient-center-pad.d.ts +11 -0
  55. package/toolbar/gradient-center-pad.js +1 -0
  56. package/toolbar/html-toolbar.js +2 -2
  57. package/toolbar/padding-control.d.ts +29 -0
  58. package/toolbar/padding-control.js +1 -0
  59. package/toolbar/selection-colors.js +1 -1
  60. package/toolbar/stop-track.js +1 -1
  61. package/toolbar/table-toolbar.js +1 -1
  62. package/toolbar/text-toolbar.d.ts +7 -2
  63. package/toolbar/text-toolbar.js +1 -1
  64. package/toolbar/unit-numeric-input.d.ts +5 -0
  65. package/toolbar/unit-numeric-input.js +1 -0
  66. package/toolbar/use-copy-style.js +1 -1
  67. package/ui.css +1 -1
  68. package/utils/clipboard.d.ts +10 -2
  69. package/utils/clipboard.js +1 -1
  70. package/utils/engine.d.ts +2 -0
  71. package/utils/engine.js +3 -0
  72. package/utils/fonts.js +1 -1
  73. package/utils/gradient-handle.d.ts +18 -0
  74. package/utils/gradient-handle.js +1 -0
  75. package/utils/gradient-stops.d.ts +7 -2
  76. package/utils/gradient-stops.js +1 -1
  77. package/utils/history-gesture.d.ts +7 -0
  78. package/utils/history-gesture.js +1 -0
  79. package/utils/html2canvas.js +1 -1
  80. package/utils/l10n.d.ts +19 -1
  81. package/utils/l10n.js +1 -1
  82. package/utils/measure-text.d.ts +4 -0
  83. package/utils/measure-text.js +1 -1
  84. package/utils/px.d.ts +4 -0
  85. package/utils/px.js +1 -1
  86. package/utils/rich-text-html.d.ts +1 -0
  87. package/utils/rich-text-html.js +1 -1
  88. package/utils/selection-transform.js +1 -1
  89. package/utils/text-format.d.ts +5 -0
  90. package/utils/text-format.js +1 -1
  91. package/utils/validate-key.js +1 -1
@@ -1 +1 @@
1
- import t from"react";import*as i from"@polotno/core/gradient";import{toDisplayColor as o}from"@polotno/core/color";const r=Object.keys({id:!0,text:!0,width:!0,height:!0,fontSize:!0,fontFamily:!0,fontWeight:!0,fontStyle:!0,lineHeight:!0,letterSpacing:!0,textTransform:!0,textDecoration:!0,align:!0,fill:!0,stroke:!0,strokeWidth:!0,strokeLineJoin:!0,curveEnabled:!0,curvePower:!0,shadowBlur:!0,shadowOffsetX:!0,shadowOffsetY:!0,textOverflow:!0,maxLines:!0,minFontSize:!0,maxFontSize:!0,a:!0});export const withDisplayTextPaints=t=>{const i={};for(const e of r){e in t&&(i[e]="fill"===e||"stroke"===e?o(t[e]):t[e])}return i};export const useColor=(r,e,n)=>{var a;return void 0===e&&(e=null!==(a=r.fill)&&void 0!==a?a:""),void 0===n&&(n="fill"),t.useMemo(()=>{if(!i.isGradient(e)){return{[n]:o(e)}}const{stops:t,rotation:a}=i.parseColor(e),{start:l,end:s}=i.canvasGradientPoints(a,r.a.width,r.a.height),d=[];return t.forEach(({offset:t,color:i})=>{d.push(t,i)}),"fill"===n?{fillLinearGradientStartPointX:l.x,fillLinearGradientStartPointY:l.y,fillLinearGradientColorStops:d,fillLinearGradientEndPointX:s.x,fillLinearGradientEndPointY:s.y,fill:t[1].color,fillPriority:"linear-gradient"}:{strokeLinearGradientStartPointX:l.x,strokeLinearGradientStartPointY:l.y,strokeLinearGradientColorStops:d,strokeLinearGradientEndPointX:s.x,strokeLinearGradientEndPointY:s.y}},[e,r.width,r.height])};
1
+ import t from"react";import*as i from"@polotno/core/gradient";import{toDisplayColor as o}from"@polotno/core/color";import r from"konva";const e=Object.keys({id:!0,text:!0,width:!0,height:!0,fontSize:!0,fontFamily:!0,fontWeight:!0,fontStyle:!0,lineHeight:!0,letterSpacing:!0,textTransform:!0,textDecoration:!0,align:!0,fill:!0,stroke:!0,strokeWidth:!0,strokeLineJoin:!0,curveEnabled:!0,curvePower:!0,shadowBlur:!0,shadowOffsetX:!0,shadowOffsetY:!0,textOverflow:!0,maxLines:!0,minFontSize:!0,maxFontSize:!0,paddingTop:!0,paddingRight:!0,paddingBottom:!0,paddingLeft:!0,a:!0});export const withDisplayTextPaints=t=>{const i={};for(const r of e){r in t&&(i[r]="fill"===r||"stroke"===r?o(t[r]):t[r])}return i};let n=null;const a=(t,o,e)=>(null!=n||(n=r.Util.createCanvasElement().getContext("2d")),i.radialStrokePaint(n,t,o,e,(t,i)=>{const o=r.Util.createCanvasElement();return o.width=t,o.height=i,o}));export const useColor=(r,e,n,l)=>{var d,s;return void 0===e&&(e=null!==(d=r.fill)&&void 0!==d?d:""),void 0===n&&(n="fill"),void 0===l&&(l=null!==(s=r.strokeWidth)&&void 0!==s?s:0),t.useMemo(()=>{var t,d,s;if(!i.isGradient(e)){return{[n]:o(e)}}const f=i.radialGradientGeometry(e,{width:r.a.width,height:r.a.height});if(f){return null!==f.solid?{[n]:f.solid}:"fill"===n?Object.assign({fillRadialGradientStartPointX:f.cx,fillRadialGradientStartPointY:f.cy,fillRadialGradientStartRadius:0,fillRadialGradientEndPointX:f.cx,fillRadialGradientEndPointY:f.cy,fillRadialGradientEndRadius:f.rx,fillRadialGradientColorStops:f.stops.flatMap(({offset:t,color:i})=>[t,i]),fill:null!==(s=null===(t=f.stops[1])||void 0===t?void 0:t.color)&&void 0!==s?s:null===(d=f.stops[0])||void 0===d?void 0:d.color,fillPriority:"radial-gradient"},f.ry!==f.rx&&{fillRadialGradientScaleY:f.ry/f.rx}):{[n]:a(f,{width:r.a.width,height:r.a.height},l)}}const{stops:h,rotation:c}=i.parseColor(e),{start:p,end:g}=i.canvasGradientPoints(c,r.a.width,r.a.height),u=[];return h.forEach(({offset:t,color:i})=>{u.push(t,i)}),"fill"===n?{fillLinearGradientStartPointX:p.x,fillLinearGradientStartPointY:p.y,fillLinearGradientColorStops:u,fillLinearGradientEndPointX:g.x,fillLinearGradientEndPointY:g.y,fill:h[1].color,fillPriority:"linear-gradient"}:{strokeLinearGradientStartPointX:p.x,strokeLinearGradientStartPointY:p.y,strokeLinearGradientColorStops:u,strokeLinearGradientEndPointX:g.x,strokeLinearGradientEndPointY:g.y}},[e,r.width,r.height,l])};
@@ -1 +1 @@
1
- import{Fragment as e,jsx as t,jsxs as r}from"react/jsx-runtime";import{elementOpacity as o}from"./paint-opacity.js";import i from"react";import{toDisplayColor as n}from"@polotno/core/color";import{animatedShadow as a}from"./animated-shadow.js";import{observer as s}from"mobx-react-lite";import{isAlive as d}from"mobx-state-tree";import{nodeAutorun as l}from"../utils/mobx.js";import{Group as c,Image as u,Rect as h}from"react-konva";import{ROLES as m}from"../model/store.js";import{DEFAULT_RETRIES as p,isDeterministicUrl as g,retryDelayMs as f}from"@polotno/core/retry";import v from"konva";import{ErrorPlaceholder as w,LoadingPlaceholder as x}from"./media-placeholders.js";import{incrementLoader as E,triggerLoadError as L}from"../utils/loader.js";import{polotnoError as M}from"@polotno/core/errors";import{getCropRect as y}from"@polotno/core/image";import*as C from"@polotno/core/svg";import{roundedPosition as b}from"../utils/px.js";import{useMediaResize as k}from"./media-resize.js";import{useFilteredSource as T}from"./use-filtered-source.js";import{useOffscreenCanvas as j}from"./use-offscreen-canvas.js";import{useEvent as I}from"../hooks/use-event.js";import{useFadeIn as R}from"./use-fadein.js";import{useAnimatedBlur as S}from"./use-animated-blur.js";import{isTouchDevice as P}from"../utils/screen.js";import{createPlayGate as _,playMedia as A}from"../utils/media.js";import{useMediabunnyVideo as V}from"./use-mediabunny-video.js";import{getElementTimeRange as D,getVideoRestMs as z,isHeldByPreview as F}from"../utils/timeline.js";import{drawReduced as O,exportKernelEnabled as H,shouldResample as U,sourceSize as Z}from"./downscale.js";import{trySetCanvasSize as W}from"../utils/canvas.js";import{useClipImage as X}from"./image-element.js";import{CropOverlay as Y,CROP_CORNER_ANCHORS as N}from"./crop-overlay.js";const q=new window.Image;q.src=C.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 $=new window.Image;$.src=C.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 useFlip=(e,t)=>{const{flipX:r,flipY:o}=e,{width:i,height:n}=t?Z(t):{},a=e=>{if(!t){return}const i=e.getContext("2d");i&&(i.clearRect(0,0,e.width,e.height),i.save(),i.scale(r?-1:1,o?-1:1),i.drawImage(t,r?-e.width:0,o?-e.height:0,e.width,e.height),i.restore())},s=j((r||o)&&!!i&&!!n,e=>{i&&n&&(e.width=i,e.height=n,a(e))},[r,o,t,i,n]);return[s||t,()=>{s&&a(s)}]};export const useCornerRadiusAndCrop=(e,t,r,o,n=0,a=!1)=>{var s;const d=Math.floor(Math.max(e.a.width*o,1)),l=Math.floor(Math.max(e.a.height*o,1)),c=Math.min(n*o,d/2,l/2),u=Math.max(e.a.width/r.width,e.a.height/r.height)*o,h=H(e.page)&&!a&&U(u,d,l),{width:m,height:p}=t?Z(t):{},g=0===r.x&&0===r.y&&r.width===m&&r.height===p,f=i.useMemo(()=>{if(t&&m&&p){return g&&0===c&&!h?void 0:document.createElement("canvas")}},[t,c,h,g,m,p]),w=()=>{if(!f||!t){return}f.width=d,f.height=l;const e=f.getContext("2d");e&&(c&&(e.beginPath(),e.moveTo(c,0),e.lineTo(d-c,0),e.arc(d-c,c,c,3*Math.PI/2,0,!1),e.lineTo(d,l-c),e.arc(d-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()),h?O(e,t,r,f.width,f.height):e.drawImage(t,r.x,r.y,r.width,r.height,0,0,f.width,f.height))};return i.useLayoutEffect(()=>{w()},[f,e.a.width,e.a.height,r.x,r.y,r.width,r.height,n,o,a,null===(s=e.page)||void 0===s?void 0:s._exportingOrRendering,h]),i.useEffect(()=>()=>{f&&"CANVAS"===f.nodeName&&v.Util.releaseCanvas(f)},[f]),[f||t,w]};export const useClip=(e,t,r,o)=>{const[n,a]=X(e.clipSrc||""),s=e.clipSrc?a:"loaded";useLoader(s,e.clipSrc,e.id);const d=!!t&&!!n,l=i.useMemo(()=>d?{canvas:document.createElement("canvas"),mask:document.createElement("canvas"),width:0,height:0}:void 0,[d]),c=null==l?void 0:l.canvas;function u(){if(!l||!c||!t){return}const{width:o,height:i}=Z(t);if(!o||!i){return}const n=Math.min(1e4,Math.max(o,Math.ceil(e.a.width*r),1)),a=Math.min(1e4,Math.max(i,Math.ceil(e.a.height*r),1));c.width&&l.width===n&&l.height===a||(W(c,n,a),l.width=n,l.height=a);const s=c.getContext("2d");s&&(s.clearRect(0,0,c.width,c.height),s.save(),s.drawImage(t,0,0,c.width,c.height),s.globalCompositeOperation="destination-in",s.drawImage(l.mask,0,0,c.width,c.height),s.restore())}return i.useLayoutEffect(()=>{var t;if(!l||!(null==n?void 0:n.width)||!n.height){return}const o=Math.max(e.a.width/n.width*r,e.a.height/n.height*r);W(l.mask,Math.min(1e4,Math.max(n.width*o,1)),Math.min(1e4,Math.max(n.height*o,1))),null===(t=l.mask.getContext("2d"))||void 0===t||t.drawImage(n,0,0,l.mask.width,l.mask.height)},[l,n,e.a.width,e.a.height,r]),i.useLayoutEffect(()=>{u()},[l,t,n,e.a.width,e.a.height,r,...o]),i.useEffect(()=>()=>{l&&v.Util.releaseCanvas(l.canvas,l.mask)},[l]),[d?c:t,u]};const B=document.createElement("canvas");let G=function(e,t,r){const o=i.useRef("loading"),n=i.useRef(void 0),[a,s]=i.useState(0),d=i.useRef(void 0),l=i.useRef(void 0),c=i.useRef(void 0);return d.current===e&&l.current===t&&c.current===r||(o.current="loading",n.current=void 0,d.current=e,l.current=t,c.current=r),i.useLayoutEffect(()=>{if(!e){return}const i=g(e)?1:p;let a,d,l,c=0,u=!1,h=!1;const m=e=>{e&&(e.removeAttribute("src"),e.load())},v=()=>{c+=1;const p=document.createElement("video");function g(){u||(p.removeEventListener("canplay",g),h=!0,o.current="loaded",n.current=p,p.currentTime=0,s(Math.random()))}function w(e){var t;const r=4===p.readyState,l=p.buffered&&p.buffered.length>0&&p.buffered.end(p.buffered.length-1)/p.duration*100>=100;if(r&&l){return}if(u){return}if(!h&&c<i){return null==d||d(),m(p),void(a=setTimeout(v,f(c)))}const g=e.message||(null===(t=p.error)||void 0===t?void 0:t.message)||"Unknown error";console.error(new Error("Video failed to load: "+g)),o.current="failed",n.current=void 0,s(Math.random())}l=p,p.addEventListener("canplay",g),p.addEventListener("error",w),d=()=>{p.removeEventListener("canplay",g),p.removeEventListener("error",w)},t&&(p.crossOrigin=t),r&&(p.referrerPolicy=r),p.src=e,p.load()};return v(),()=>{u=!0,clearTimeout(a),null==d||d(),h||m(l)}},[e,t,r]),[n.current,o.current]};export const setVideoLoaderHook=e=>{G=e};function J(e){return!e.seeking&&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=E(a)),"loading"!==e&&n(),"failed"===e&&L(M("VIDEO_FAILED",a,{src:i,elementId:r,reason:"load"}))},[e])};export const VideoElement=s(({element:s,store:p})=>{var g,f,L,M,C;const[j,O]=i.useState(!1),H=i.useRef(null),U=P(),[W,X]=i.useState(!1),[K,Q]=G(s.a.src,"anonymous"),[ee,te]=i.useState(!1),re=p.activePage===s.page,oe=(null===(g=s.page)||void 0===g?void 0:g._exportingOrRendering)&&"loaded"===Q,ie=V(s,p,oe);useLoader(Q,s.a.src,s.id),K&&(K.playsInline=!0);const ne=oe&&ie||K,[ae,se]=useFlip(s,ne),[de=B,le]=T(s,ae||B);i.useEffect(()=>{K&&p.history.ignore(()=>{s.set({duration:1e3*K.duration})})},[K]);const ce=i.useMemo(_,[K]);i.useEffect(()=>{var e;if(!K){return}const t=!F(s)&&p.isPlaying;if(!re||!t&&!W){return void K.pause()}W&&(K.muted=!1,K.currentTime=s.startTime*K.duration,A(K).then(e=>{"refused"===e&&X(!1)}));const r=new v.Animation(()=>{Te()},null===(e=H.current)||void 0===e?void 0:e.getLayer());r.start();const o=()=>{X(!1),K.currentTime=s.startTime*K.duration},i=()=>{K.currentTime>=s.endTime*K.duration&&(K.pause(),K.currentTime=s.startTime*K.duration,X(!1))};return K.addEventListener("ended",o),K.addEventListener("timeupdate",i),()=>{K.pause(),r.stop(),K.removeEventListener("ended",o),K.removeEventListener("timeupdate",i)}},[K,W,p.isPlaying,re]),i.useEffect(()=>{K&&(K.volume=s.volume)},[K,s.volume]),i.useEffect(()=>{K&&(K.playbackRate=s.speed,K.preservesPitch=!1)},[K,s.speed]);const ue=i.useRef(null);i.useEffect(()=>{const e=l(s,()=>{var e,t;if(K){if(oe&&ie){return Te(),void p.currentTime}if(F(s)){return}const r=p.activePage===s.page,o=s.page._mediaLocalTime,i=s.startTime*K.duration*1e3,n=K.duration*(s.endTime-s.startTime)*1e3,{start:a,end:d}=D(s.animations,s.page.duration),l=z(null!=o?o:0,0,a,n,i,s.speed,{windowEnd:d,frameMs:p._renderFrameMs,renderEnd:p._renderEndMs-s.page.startTime}),c=l/1e3,u=null!==o&&o>=a&&o<d;W||(K.muted=!u,u&&p.isPlaying&&r?K.paused?(K.currentTime=c,ce.play(K)):Math.abs(1e3*K.currentTime-l)>500&&(K.currentTime=c):(ce.reset(),K.paused||K.pause(),c!==K.currentTime&&(K.currentTime=c),!J(K)&&!p.isPlaying&&!ue.current&&(ue.current=E(`video ${s.id}`)))),Te(),null===(t=null===(e=H.current)||void 0===e?void 0:e.getLayer())||void 0===t||t.batchDraw()}});return()=>{e(),ue.current&&(ue.current(),ue.current=null)}},[p,K,oe,ie,W]),i.useEffect(()=>{var e,t;if(!K){return}if(oe){return null===(e=ue.current)||void 0===e||e.call(ue),void(ue.current=null)}const r=()=>{var e;null===(e=ue.current)||void 0===e||e.call(ue),ue.current=null},o=()=>{J(K)&&(Te(),r())};let i,n;(null===(t=s.page)||void 0===t?void 0:t._exportingOrRendering)&&(i=setInterval(o,20)),K.addEventListener("timeupdate",o),K.addEventListener("canplay",o),K.addEventListener("seeked",o);const a=()=>{K.paused&&(Te(),J(K)&&r()),n=K.requestVideoFrameCallback(a)};return"requestVideoFrameCallback"in K&&(n=K.requestVideoFrameCallback(a)),()=>{clearInterval(i),void 0!==n&&K.cancelVideoFrameCallback(n),K.removeEventListener("timeupdate",o),K.removeEventListener("canplay",o),K.removeEventListener("seeked",o)}},[null===(f=s.page)||void 0===f?void 0:f._exportingOrRendering,K,s.id,E,oe]);let{cropX:he,cropY:me,cropWidth:pe,cropHeight:ge}=s.a;"loaded"!==Q&&(he=me=0,pe=ge=1);const{width:fe,height:ve}=Z(de),we=null!==(L=null==K?void 0:K.videoWidth)&&void 0!==L?L:0,xe=null!==(M=null==K?void 0:K.videoHeight)&&void 0!==M?M:0;i.useLayoutEffect(()=>{"loaded"===Q&&we>0&&xe>0&&s._setSourceSize({width:we,height:xe},s.a.src)},[s,s.a.src,Q,we,xe]);const Ee=y({fit:s.a.fit,focus:s.focus,stretchEnabled:s.stretchEnabled,cropX:he,cropY:me,cropWidth:pe,cropHeight:ge,width:s.a.width,height:s.a.height},{width:fe,height:ve}),Le=(Ee.width,Ee.height,null!==(C=s.cornerRadius)&&void 0!==C?C:0),[Me,ye]=useCornerRadiusAndCrop(s,de,Ee,p._elementsPixelRatio,Le,!0);let[Ce,be]=useClip(s,Me,p._elementsPixelRatio,[Ee,Le,p._elementsPixelRatio]);const ke=S(H,s,Ce),Te=I(()=>{var e,t;se(),le(),ye(),be(),ke(),null===(t=null===(e=H.current)||void 0===e?void 0:e.getLayer())||void 0===t||t.batchDraw()});i.useEffect(()=>{Te()});const je=()=>{s._cropEnabled&&setTimeout(()=>{d(s)&&s.toggleCropMode(!0)})},Ie="loading"===Q,Re="failed"===Q,Se=!Ie&&!Re,Pe=k(s,Ee,"loaded"===Q?{width:fe,height:ve}:void 0,O),_e=Se?o(s):0;R(H,_e);const Ae=s.selectable||p.role===m.ADMIN;return t(e,{children:r(c,{onMouseEnter:()=>te(!0),onMouseLeave:()=>te(!1),children:[Ie&&t(x,{element:s}),Re&&t(w,{element:s,text:"Can not load the video..."}),t(u,Object.assign({ref:H,name:"element",id:s.id,image:Ce,x:s.a.x,y:s.a.y,width:s.a.width||1,height:s.a.height||1,rotation:s.a.rotation,opacity:_e},a(s),{customCrop:Ee,listening:Ae,draggable:U?s.draggable&&s.isSelected:s.draggable,preventDefault:!U||s.isSelected,hideInExport:!s.showInExport,onDragMove:e=>{s.set({x:e.target.x(),y:e.target.y()})},onDragEnd:e=>{s.set(b(e.target))},onDblClick:je,onDblTap:je},Pe)),!!s.borderSize&&t(h,{x:s.a.x,y:s.a.y,width:Math.max(s.a.width-s.borderSize,0),height:Math.max(s.a.height-s.borderSize,0),opacity:_e,offsetX:-s.borderSize/2,offsetY:-s.borderSize/2,stroke:n(s.borderColor),strokeWidth:s.borderSize,listening:!1,rotation:s.a.rotation,cornerRadius:Math.max(0,Le-s.borderSize),hideInExport:!s.showInExport}),!p.isPlaying&&t(u,{image:W?ee||U?$:void 0:q,x:s.a.x,y:s.a.y,offsetX:-s.a.width/2+15/p.scale,offsetY:-s.a.height/2+15/p.scale,rotation:s.a.rotation,width:30/p.scale,height:30/p.scale,hideInExport:!0,onClick:()=>X(!W),onTap:()=>X(!W)}),s._cropModeEnabled&&"loaded"===Q&&t(Y,{element:s,store:p,previewImage:Ce,sourceImage:de,sourceWidth:fe,sourceHeight:ve,crop:Ee,innerAnchors:N})]})})});
1
+ import{Fragment as e,jsx as t,jsxs as r}from"react/jsx-runtime";import{elementOpacity as i}from"./paint-opacity.js";import o from"react";import{toDisplayColor as n}from"@polotno/core/color";import{animatedShadow as a}from"./animated-shadow.js";import{observer as s}from"mobx-react-lite";import{isAlive as d}from"mobx-state-tree";import{nodeAutorun as l}from"../utils/mobx.js";import{Group as c,Image as u,Rect as h}from"react-konva";import{ROLES as m}from"../model/store.js";import{DEFAULT_RETRIES as p,isDeterministicUrl as f,retryDelayMs as g}from"@polotno/core/retry";import v from"konva";import{ErrorPlaceholder as w,LoadingPlaceholder as x}from"./media-placeholders.js";import{incrementLoader as E,triggerLoadError as L}from"../utils/loader.js";import{polotnoError as M}from"@polotno/core/errors";import{getCropRect as y}from"@polotno/core/image";import*as C from"@polotno/core/svg";import{roundedPosition as b}from"../utils/px.js";import{useMediaResize as k}from"./media-resize.js";import{useFilteredSource as T}from"./use-filtered-source.js";import{useOffscreenCanvas as j}from"./use-offscreen-canvas.js";import{useEvent as I}from"../hooks/use-event.js";import{useFadeIn as R}from"./use-fadein.js";import{useAnimatedBlur as S}from"./use-animated-blur.js";import{isTouchDevice as P}from"../utils/screen.js";import{createPlayGate as _,playMedia as A}from"../utils/media.js";import{useMediabunnyVideo as V}from"./use-mediabunny-video.js";import{getElementTimeRange as D,getVideoRestMs as z,isHeldByPreview as F}from"../utils/timeline.js";import{drawImageWindow as O,drawReduced as H,exportKernelEnabled as U,shouldResample as Z,sourceSize as W}from"./downscale.js";import{trySetCanvasSize as X}from"../utils/canvas.js";import{isWebKit as Y}from"../utils/engine.js";import{useClipImage as N}from"./image-element.js";import{CropOverlay as q,CROP_CORNER_ANCHORS as $}from"./crop-overlay.js";const B=new window.Image;B.src=C.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 G=new window.Image;G.src=C.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 useFlip=(e,t)=>{const{flipX:r,flipY:i}=e,{width:o,height:n}=t?W(t):{},a=e=>{if(!t){return}const o=e.getContext("2d");o&&(o.clearRect(0,0,e.width,e.height),o.save(),o.scale(r?-1:1,i?-1:1),o.drawImage(t,r?-e.width:0,i?-e.height:0,e.width,e.height),o.restore())},s=j((r||i)&&!!o&&!!n,e=>{o&&n&&(e.width=o,e.height=n,a(e))},[r,i,t,o,n]);return[s||t,()=>{s&&a(s)}]};export const useCornerRadiusAndCrop=(e,t,r,i,n=0,a=!1)=>{var s;const d=Math.floor(Math.max(e.a.width*i,1)),l=Math.floor(Math.max(e.a.height*i,1)),c=Math.min(n*i,d/2,l/2),u=Math.max(e.a.width/r.width,e.a.height/r.height)*i,h=U(e.page)&&!a&&Z(u,d,l),{width:m,height:p}=t?W(t):{},f=0===r.x&&0===r.y&&r.width===m&&r.height===p,g=o.useMemo(()=>{if(t&&m&&p){return f&&0===c&&!h?void 0:document.createElement("canvas")}},[t,c,h,f,m,p]),w=()=>{if(!g||!t){return}g.width=d,g.height=l;const e=g.getContext("2d");e&&(c&&(e.beginPath(),e.moveTo(c,0),e.lineTo(d-c,0),e.arc(d-c,c,c,3*Math.PI/2,0,!1),e.lineTo(d,l-c),e.arc(d-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()),h?H(e,t,r,g.width,g.height):O(e,t,r,{x:0,y:0,width:g.width,height:g.height}))};return o.useLayoutEffect(()=>{w()},[g,e.a.width,e.a.height,r.x,r.y,r.width,r.height,n,i,a,null===(s=e.page)||void 0===s?void 0:s._exportingOrRendering,h]),o.useEffect(()=>()=>{g&&"CANVAS"===g.nodeName&&v.Util.releaseCanvas(g)},[g]),[g||t,w]};export const useClip=(e,t,r,i)=>{const[n,a]=N(e.clipSrc||""),s=e.clipSrc?a:"loaded";useLoader(s,e.clipSrc,e.id);const d=!!t&&!!n,l=o.useMemo(()=>d?{canvas:document.createElement("canvas"),mask:document.createElement("canvas"),width:0,height:0}:void 0,[d]),c=null==l?void 0:l.canvas;function u(){if(!l||!c||!t){return}const{width:i,height:o}=W(t);if(!i||!o){return}const n=Math.min(1e4,Math.max(i,Math.ceil(e.a.width*r),1)),a=Math.min(1e4,Math.max(o,Math.ceil(e.a.height*r),1));c.width&&l.width===n&&l.height===a||(X(c,n,a),l.width=n,l.height=a);const s=c.getContext("2d");s&&(s.clearRect(0,0,c.width,c.height),s.save(),s.drawImage(t,0,0,c.width,c.height),s.globalCompositeOperation="destination-in",s.drawImage(l.mask,0,0,c.width,c.height),s.restore())}return o.useLayoutEffect(()=>{var t;if(!l||!(null==n?void 0:n.width)||!n.height){return}const i=Math.max(e.a.width/n.width*r,e.a.height/n.height*r);X(l.mask,Math.min(1e4,Math.max(n.width*i,1)),Math.min(1e4,Math.max(n.height*i,1))),null===(t=l.mask.getContext("2d"))||void 0===t||t.drawImage(n,0,0,l.mask.width,l.mask.height)},[l,n,e.a.width,e.a.height,r]),o.useLayoutEffect(()=>{u()},[l,t,n,e.a.width,e.a.height,r,...i]),o.useEffect(()=>()=>{l&&v.Util.releaseCanvas(l.canvas,l.mask)},[l]),[d?c:t,u]};const J=document.createElement("canvas");let K=function(e,t,r){const i=o.useRef("loading"),n=o.useRef(void 0),[a,s]=o.useState(0),d=o.useRef(void 0),l=o.useRef(void 0),c=o.useRef(void 0);return d.current===e&&l.current===t&&c.current===r||(i.current="loading",n.current=void 0,d.current=e,l.current=t,c.current=r),o.useLayoutEffect(()=>{if(!e){return}const o=f(e)?1:p;let a,d,l,c=0,u=!1,h=!1;const m=e=>{e&&(e.removeAttribute("src"),e.load())},v=()=>{c+=1;const p=document.createElement("video");function f(){u||(p.removeEventListener("canplay",f),h=!0,i.current="loaded",n.current=p,p.currentTime=0,s(Math.random()))}function w(e){var t;const r=4===p.readyState,l=p.buffered&&p.buffered.length>0&&p.buffered.end(p.buffered.length-1)/p.duration*100>=100;if(r&&l){return}if(u){return}if(!h&&c<o){return null==d||d(),m(p),void(a=setTimeout(v,g(c)))}const f=e.message||(null===(t=p.error)||void 0===t?void 0:t.message)||"Unknown error";console.error(new Error("Video failed to load: "+f)),i.current="failed",n.current=void 0,s(Math.random())}l=p,p.addEventListener("canplay",f),p.addEventListener("error",w),d=()=>{p.removeEventListener("canplay",f),p.removeEventListener("error",w)},t&&(p.crossOrigin=t),r&&(p.referrerPolicy=r),p.src=e,p.load()};return v(),()=>{u=!0,clearTimeout(a),null==d||d(),h||m(l)}},[e,t,r]),[n.current,i.current]};export const setVideoLoaderHook=e=>{K=e};function Q(e){return!e.seeking&&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=E(a)),"loading"!==e&&n(),"failed"===e&&L(M("VIDEO_FAILED",a,{src:o,elementId:r,reason:"load"}))},[e])};export const VideoElement=s(({element:s,store:p})=>{var f,g,L,M,C;const[j,O]=o.useState(!1),H=o.useRef(null),U=P(),[Z,X]=o.useState(!1),[N,ee]=K(s.a.src,"anonymous"),[te,re]=o.useState(!1),ie=p.activePage===s.page,oe=(null===(f=s.page)||void 0===f?void 0:f._exportingOrRendering)&&"loaded"===ee,ne=V(s,p,oe);useLoader(ee,s.a.src,s.id),N&&(N.playsInline=!0);const ae=oe&&ne||N,[se,de]=useFlip(s,ae),[le=J,ce]=T(s,se||J);o.useEffect(()=>{N&&p.history.ignore(()=>{s.set({duration:1e3*N.duration})})},[N]);const ue=o.useMemo(_,[N]);o.useEffect(()=>{var e;if(!N){return}const t=!F(s)&&p.isPlaying;if(!ie||!t&&!Z){return void N.pause()}Z&&(N.muted=!1,N.currentTime=s.startTime*N.duration,A(N).then(e=>{"refused"===e&&X(!1)}));const r=new v.Animation(()=>{je()},null===(e=H.current)||void 0===e?void 0:e.getLayer());r.start();const i=()=>{X(!1),N.currentTime=s.startTime*N.duration},o=()=>{N.currentTime>=s.endTime*N.duration&&(N.pause(),N.currentTime=s.startTime*N.duration,X(!1))};return N.addEventListener("ended",i),N.addEventListener("timeupdate",o),()=>{N.pause(),r.stop(),N.removeEventListener("ended",i),N.removeEventListener("timeupdate",o)}},[N,Z,p.isPlaying,ie]),o.useEffect(()=>{N&&(N.volume=s.volume)},[N,s.volume]),o.useEffect(()=>{N&&(N.playbackRate=s.speed,N.preservesPitch=!1)},[N,s.speed]);const he=o.useRef(null);o.useEffect(()=>{const e=l(s,()=>{var e,t;if(N){if(oe&&ne){return je(),void p.currentTime}if(F(s)){return}const r=p.activePage===s.page,i=s.page._mediaLocalTime,o=s.startTime*N.duration*1e3,n=N.duration*(s.endTime-s.startTime)*1e3,{start:a,end:d}=D(s.animations,s.page.duration),l=z(null!=i?i:0,0,a,n,o,s.speed,{windowEnd:d,frameMs:p._renderFrameMs,renderEnd:p._renderEndMs-s.page.startTime}),c=l/1e3,u=null!==i&&i>=a&&i<d;Z||(N.muted=!u,u&&p.isPlaying&&r?N.paused?(N.currentTime=c,ue.play(N)):Math.abs(1e3*N.currentTime-l)>500&&(N.currentTime=c):(ue.reset(),N.paused||N.pause(),c!==N.currentTime&&(N.currentTime=c),!Q(N)&&!p.isPlaying&&!he.current&&(he.current=E(`video ${s.id}`)))),je(),null===(t=null===(e=H.current)||void 0===e?void 0:e.getLayer())||void 0===t||t.batchDraw()}});return()=>{e(),he.current&&(he.current(),he.current=null)}},[p,N,oe,ne,Z]),o.useEffect(()=>{var e,t;if(!N){return}if(oe){return null===(e=he.current)||void 0===e||e.call(he),void(he.current=null)}const r=()=>{var e;null===(e=he.current)||void 0===e||e.call(he),he.current=null},i=()=>{Q(N)&&(je(),r())};let o,n;(null===(t=s.page)||void 0===t?void 0:t._exportingOrRendering)&&(o=setInterval(i,20)),N.addEventListener("timeupdate",i),N.addEventListener("canplay",i),N.addEventListener("seeked",i);const a=()=>{N.paused&&(je(),Q(N)&&r()),n=N.requestVideoFrameCallback(a)};return"requestVideoFrameCallback"in N&&!Y()&&(n=N.requestVideoFrameCallback(a)),()=>{clearInterval(o),void 0!==n&&N.cancelVideoFrameCallback(n),N.removeEventListener("timeupdate",i),N.removeEventListener("canplay",i),N.removeEventListener("seeked",i)}},[null===(g=s.page)||void 0===g?void 0:g._exportingOrRendering,N,s.id,E,oe]);let{cropX:me,cropY:pe,cropWidth:fe,cropHeight:ge}=s.a;"loaded"!==ee&&(me=pe=0,fe=ge=1);const{width:ve,height:we}=W(le),xe=null!==(L=null==N?void 0:N.videoWidth)&&void 0!==L?L:0,Ee=null!==(M=null==N?void 0:N.videoHeight)&&void 0!==M?M:0;o.useLayoutEffect(()=>{"loaded"===ee&&xe>0&&Ee>0&&s._setSourceSize({width:xe,height:Ee},s.a.src)},[s,s.a.src,ee,xe,Ee]);const Le=y({fit:s.a.fit,focus:s.focus,stretchEnabled:s.stretchEnabled,cropX:me,cropY:pe,cropWidth:fe,cropHeight:ge,width:s.a.width,height:s.a.height},{width:ve,height:we}),Me=(Le.width,Le.height,null!==(C=s.cornerRadius)&&void 0!==C?C:0),[ye,Ce]=useCornerRadiusAndCrop(s,le,Le,p._elementsPixelRatio,Me,!0);let[be,ke]=useClip(s,ye,p._elementsPixelRatio,[Le,Me,p._elementsPixelRatio]);const Te=S(H,s,be),je=I(()=>{var e,t;de(),ce(),Ce(),ke(),Te(),null===(t=null===(e=H.current)||void 0===e?void 0:e.getLayer())||void 0===t||t.batchDraw()});o.useEffect(()=>{je()});const Ie=()=>{s._cropEnabled&&setTimeout(()=>{d(s)&&s.toggleCropMode(!0)})},Re="loading"===ee,Se="failed"===ee,Pe=!Re&&!Se,_e=k(s,Le,"loaded"===ee?{width:ve,height:we}:void 0,O),Ae=Pe?i(s):0;R(H,Ae);const Ve=s.selectable||p.role===m.ADMIN;return t(e,{children:r(c,{onMouseEnter:()=>re(!0),onMouseLeave:()=>re(!1),children:[Re&&t(x,{element:s}),Se&&t(w,{element:s,text:"Can not load the video..."}),t(u,Object.assign({ref:H,name:"element",id:s.id,image:be,x:s.a.x,y:s.a.y,width:s.a.width||1,height:s.a.height||1,rotation:s.a.rotation,opacity:Ae},a(s),{customCrop:Le,listening:Ve,draggable:U?s.draggable&&s.isSelected:s.draggable,preventDefault:!U||s.isSelected,hideInExport:!s.showInExport,onDragMove:e=>{s.set({x:e.target.x(),y:e.target.y()})},onDragEnd:e=>{s.set(b(e.target))},onDblClick:Ie,onDblTap:Ie},_e)),!!s.borderSize&&t(h,{x:s.a.x,y:s.a.y,width:Math.max(s.a.width-s.borderSize,0),height:Math.max(s.a.height-s.borderSize,0),opacity:Ae,offsetX:-s.borderSize/2,offsetY:-s.borderSize/2,stroke:n(s.borderColor),strokeWidth:s.borderSize,listening:!1,rotation:s.a.rotation,cornerRadius:Math.max(0,Me-s.borderSize),hideInExport:!s.showInExport}),!p.isPlaying&&t(u,{image:Z?te||U?G:void 0:B,x:s.a.x,y:s.a.y,offsetX:-s.a.width/2+15/p.scale,offsetY:-s.a.height/2+15/p.scale,rotation:s.a.rotation,width:30/p.scale,height:30/p.scale,hideInExport:!0,onClick:()=>X(!Z),onTap:()=>X(!Z)}),s._cropModeEnabled&&"loaded"===ee&&t(q,{element:s,store:p,previewImage:be,sourceImage:le,sourceWidth:ve,sourceHeight:we,crop:Le,innerAnchors:$})]})})});
@@ -90,6 +90,7 @@ declare const defaults: {
90
90
  'toolbar.zoomIn': import("lucide-react").LucideIcon;
91
91
  'toolbar.zoomOut': import("lucide-react").LucideIcon;
92
92
  'toolbar.crop': import("lucide-react").LucideIcon;
93
+ 'toolbar.paddingSides': import("lucide-react").LucideIcon;
93
94
  'imageEdit.ai': import("lucide-react").LucideIcon;
94
95
  'colorPicker.reverseGradient': import("lucide-react").LucideIcon;
95
96
  'download.export': import("lucide-react").LucideIcon;
package/icons/registry.js CHANGED
@@ -1 +1 @@
1
- var t=this&&this.__rest||function(t,i){var e={};for(var o in t){Object.prototype.hasOwnProperty.call(t,o)&&i.indexOf(o)<0&&(e[o]=t[o])}if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(o=Object.getOwnPropertySymbols(t);n<o.length;n++){i.indexOf(o[n])<0&&Object.prototype.propertyIsEnumerable.call(t,o[n])&&(e[o[n]]=t[o[n]])}}return e};import{jsx as i}from"react/jsx-runtime";import{observable as e,action as o}from"mobx";import{observer as n}from"mobx-react-lite";import{AlignCenter as a,AlignCenterHorizontal as r,AlignCenterVertical as l,AlignEndHorizontal as s,AlignEndVertical as p,AlignHorizontalSpaceAround as c,AlignJustify as m,AlignLeft as d,AlignRight as y,AlignStartHorizontal as u,AlignStartVertical as g,AlignVerticalJustifyCenter as b,AlignVerticalJustifyEnd as f,AlignVerticalJustifyStart as x,AlignVerticalSpaceAround as v,ArrowDown as h,ArrowDownLeft as P,ArrowDownRight as w,ArrowLeft as k,ArrowLeftRight as z,ArrowRight as L,ArrowUp as O,ArrowUpDown as j,ArrowUpLeft as R,ArrowUpRight as T,Ban as B,Bold as I,Braces as W,CaseSensitive as F,Check as C,ChevronDown as D,ChevronLeft as G,ChevronRight as H,ChevronsDown as M,ChevronsUp as S,ChevronUp as V,CloudUpload as E,Contrast as U,Copy as $,CreditCard as _,Crop as J,Edit as K,Eye as N,EyeOff as Z,Files as q,FileText as A,GripVertical as Q,HelpCircle as X,Highlighter as Y,Image as tt,Italic as it,Layers as et,LayoutTemplate as ot,List as nt,ListOrdered as at,Lock as rt,MousePointer as lt,MoreHorizontal as st,PaintBucket as pt,Palette as ct,Pause as mt,Pencil as dt,Pilcrow as yt,Pipette as ut,Play as gt,Plus as bt,Redo2 as ft,Scaling as xt,Scissors as vt,Search as ht,SkipBack as Pt,Settings as wt,Shapes as kt,SlidersHorizontal as zt,Sparkles as Lt,Strikethrough as Ot,TextCursorInput as jt,Timer as Rt,ToggleRight as Tt,Trash2 as Bt,Type as It,Underline as Wt,Undo2 as Ft,Unlock as Ct,Upload as Dt,Video as Gt,Volume2 as Ht,VolumeX as Mt,WandSparkles as St,WrapText as Vt,X as Et,ZoomIn as Ut,ZoomOut as $t}from"lucide-react";import{Instagram as _t,Facebook as Jt,Youtube as Kt,Linkedin as Nt,Twitter as Zt}from"./brand-icons.js";import{NoneIcon as qt,MoveIcon as At,FadeIcon as Qt,ZoomIcon as Xt,RotateIcon as Yt,BlinkIcon as ti,BounceIcon as ii,BlurIcon as ei,CountIcon as oi,PopIcon as ni,RiseIcon as ai,FlipIcon as ri,GrowTurnIcon as li,PulseIcon as si,FloatIcon as pi,ShakeIcon as ci,TypewriterIcon as mi,LineRiseIcon as di,WordRiseIcon as yi,WordFadeIcon as ui,LetterPopIcon as gi,WordBlurIcon as bi,WipeIcon as fi,GlowIcon as xi,KenBurnsIcon as vi,LineWipeIcon as hi,LinePeekIcon as Pi,LetterWaveIcon as wi}from"./animation-icons.js";const ki={"action.duplicate":$,"action.split":vt,"action.rename":dt,"action.remove":Bt,"action.lock":rt,"action.unlock":Ct,"action.undo":Ft,"action.redo":ft,"action.add":bt,"action.more":st,"action.settings":wt,"action.search":ht,"action.close":Et,"action.confirm":C,"action.none":B,"action.visible":N,"action.hidden":Z,"action.dragHandle":Q,"action.eyeDropper":ut,"action.unmuted":Ht,"action.muted":Mt,"action.help":X,"ui.chevronUp":V,"ui.chevronDown":D,"ui.chevronLeft":G,"ui.chevronRight":H,"layering.menu":et,"layering.up":V,"layering.down":D,"layering.top":S,"layering.bottom":M,"text.bold":I,"text.italic":it,"text.underline":Wt,"text.strikethrough":Ot,"text.alignLeft":d,"text.alignCenter":a,"text.alignRight":y,"text.alignJustify":m,"text.valignTop":x,"text.valignMiddle":b,"text.valignBottom":f,"text.uppercase":F,"text.spacing":Vt,"text.bulletList":nt,"text.numberedList":at,"text.paragraph":yt,"text.richText":jt,"text.uploadFont":Dt,"position.alignLeft":g,"position.alignCenter":l,"position.alignRight":p,"position.alignTop":u,"position.alignMiddle":r,"position.alignBottom":s,"position.distributeVertical":v,"position.distributeHorizontal":c,"sidePanel.templates":ot,"sidePanel.text":It,"sidePanel.photos":tt,"sidePanel.elements":kt,"sidePanel.upload":E,"sidePanel.background":pt,"sidePanel.pages":q,"sidePanel.layers":et,"sidePanel.resize":xt,"sidePanel.draw":dt,"sidePanel.videos":Gt,"sidePanel.variables":W,"variables.text":It,"variables.image":tt,"variables.video":Gt,"variables.color":ct,"variables.boolean":Tt,"toolbar.opacity":U,"toolbar.filters":St,"toolbar.aiWrite":Lt,"toolbar.insertVariable":W,"toolbar.duration":Rt,"toolbar.trim":vt,"toolbar.flipHorizontal":z,"toolbar.flipVertical":j,"toolbar.zoomIn":Ut,"toolbar.zoomOut":$t,"toolbar.crop":J,"imageEdit.ai":Lt,"colorPicker.reverseGradient":z,"download.export":Dt,"download.image":tt,"download.pdf":A,"download.video":Gt,"draw.select":lt,"draw.brush":K,"draw.highlighter":Y,"background.colorPicker":ct,"pagesTimeline.play":gt,"pagesTimeline.pause":mt,"pagesTimeline.rewind":Pt,"size.instagram":_t,"size.facebook":Jt,"size.youtube":Kt,"size.linkedin":Nt,"size.twitter":Zt,"size.video":Gt,"size.print":A,"size.businessCard":_,"animation.directionRight":L,"animation.directionLeft":k,"animation.directionUp":O,"animation.directionDown":h,"animation.directionBottomRight":w,"animation.directionBottomLeft":P,"animation.directionTopRight":T,"animation.directionTopLeft":R,"animation.typeMove":At,"animation.typeFade":Qt,"animation.typeZoom":Xt,"animation.typeBlur":ei,"animation.typeCount":oi,"animation.typeRotate":Yt,"animation.typeBlink":ti,"animation.typeBounce":ii,"animation.typePop":ni,"animation.typeRise":ai,"animation.typeFlip":ri,"animation.typeGrowTurn":li,"animation.typePulse":si,"animation.typeFloat":pi,"animation.typeShake":ci,"animation.typeTypewriter":mi,"animation.typeLineRise":di,"animation.typeWordRise":yi,"animation.typeWordFade":ui,"animation.typeLetterPop":gi,"animation.typeWordBlur":bi,"animation.typeWipe":fi,"animation.typeGlow":xi,"animation.typeKenBurns":vi,"animation.typeLineWipe":hi,"animation.typeLinePeek":Pi,"animation.typeLetterWave":wi,"animation.typeNone":qt,"animation.settings":zt},zi=e.map();export const setIcons=o(t=>{for(const i of Object.keys(t)){const e=t[i];null!=e&&("function"==typeof e||"object"==typeof e?zi.set(i,e):console.warn(`polotno: setIcons('${i}') expects a React component, received ${typeof e}. Ignored.`))}});export const resetIcons=o(()=>zi.clear());export const PolotnoIcon=n(e=>{var o,{name:n}=e,a=t(e,["name"]);const r=null!==(o=zi.get(n))&&void 0!==o?o:ki[n];return i(r,Object.assign({"data-pn-icon":""},a))});
1
+ var t=this&&this.__rest||function(t,i){var e={};for(var o in t){Object.prototype.hasOwnProperty.call(t,o)&&i.indexOf(o)<0&&(e[o]=t[o])}if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(o=Object.getOwnPropertySymbols(t);n<o.length;n++){i.indexOf(o[n])<0&&Object.prototype.propertyIsEnumerable.call(t,o[n])&&(e[o[n]]=t[o[n]])}}return e};import{jsx as i}from"react/jsx-runtime";import{observable as e,action as o}from"mobx";import{observer as n}from"mobx-react-lite";import{AlignCenter as a,AlignCenterHorizontal as r,AlignCenterVertical as l,AlignEndHorizontal as s,AlignEndVertical as p,AlignHorizontalSpaceAround as c,AlignJustify as m,AlignLeft as d,AlignRight as y,AlignStartHorizontal as g,AlignStartVertical as u,AlignVerticalJustifyCenter as b,AlignVerticalJustifyEnd as f,AlignVerticalJustifyStart as x,AlignVerticalSpaceAround as v,ArrowDown as h,ArrowDownLeft as P,ArrowDownRight as w,ArrowLeft as k,ArrowLeftRight as z,ArrowRight as L,ArrowUp as O,ArrowUpDown as j,ArrowUpLeft as R,ArrowUpRight as T,Ban as B,Bold as I,Braces as W,CaseSensitive as F,Check as C,ChevronDown as S,ChevronLeft as D,ChevronRight as G,ChevronsDown as H,ChevronsUp as M,ChevronUp as V,CloudUpload as E,Contrast as U,Copy as $,CreditCard as _,Crop as J,Edit as K,Eye as N,EyeOff as Z,Files as q,FileText as A,GripVertical as Q,HelpCircle as X,Highlighter as Y,Image as tt,Italic as it,Layers as et,LayoutTemplate as ot,List as nt,ListOrdered as at,Lock as rt,MousePointer as lt,MoreHorizontal as st,PaintBucket as pt,Palette as ct,Pause as mt,Pencil as dt,Pilcrow as yt,Pipette as gt,Play as ut,Plus as bt,Redo2 as ft,Scaling as xt,Scan as vt,Scissors as ht,Search as Pt,SkipBack as wt,Settings as kt,Shapes as zt,SlidersHorizontal as Lt,Sparkles as Ot,Strikethrough as jt,TextCursorInput as Rt,Timer as Tt,ToggleRight as Bt,Trash2 as It,Type as Wt,Underline as Ft,Undo2 as Ct,Unlock as St,Upload as Dt,Video as Gt,Volume2 as Ht,VolumeX as Mt,WandSparkles as Vt,WrapText as Et,X as Ut,ZoomIn as $t,ZoomOut as _t}from"lucide-react";import{Instagram as Jt,Facebook as Kt,Youtube as Nt,Linkedin as Zt,Twitter as qt}from"./brand-icons.js";import{NoneIcon as At,MoveIcon as Qt,FadeIcon as Xt,ZoomIcon as Yt,RotateIcon as ti,BlinkIcon as ii,BounceIcon as ei,BlurIcon as oi,CountIcon as ni,PopIcon as ai,RiseIcon as ri,FlipIcon as li,GrowTurnIcon as si,PulseIcon as pi,FloatIcon as ci,ShakeIcon as mi,TypewriterIcon as di,LineRiseIcon as yi,WordRiseIcon as gi,WordFadeIcon as ui,LetterPopIcon as bi,WordBlurIcon as fi,WipeIcon as xi,GlowIcon as vi,KenBurnsIcon as hi,LineWipeIcon as Pi,LinePeekIcon as wi,LetterWaveIcon as ki}from"./animation-icons.js";const zi={"action.duplicate":$,"action.split":ht,"action.rename":dt,"action.remove":It,"action.lock":rt,"action.unlock":St,"action.undo":Ct,"action.redo":ft,"action.add":bt,"action.more":st,"action.settings":kt,"action.search":Pt,"action.close":Ut,"action.confirm":C,"action.none":B,"action.visible":N,"action.hidden":Z,"action.dragHandle":Q,"action.eyeDropper":gt,"action.unmuted":Ht,"action.muted":Mt,"action.help":X,"ui.chevronUp":V,"ui.chevronDown":S,"ui.chevronLeft":D,"ui.chevronRight":G,"layering.menu":et,"layering.up":V,"layering.down":S,"layering.top":M,"layering.bottom":H,"text.bold":I,"text.italic":it,"text.underline":Ft,"text.strikethrough":jt,"text.alignLeft":d,"text.alignCenter":a,"text.alignRight":y,"text.alignJustify":m,"text.valignTop":x,"text.valignMiddle":b,"text.valignBottom":f,"text.uppercase":F,"text.spacing":Et,"text.bulletList":nt,"text.numberedList":at,"text.paragraph":yt,"text.richText":Rt,"text.uploadFont":Dt,"position.alignLeft":u,"position.alignCenter":l,"position.alignRight":p,"position.alignTop":g,"position.alignMiddle":r,"position.alignBottom":s,"position.distributeVertical":v,"position.distributeHorizontal":c,"sidePanel.templates":ot,"sidePanel.text":Wt,"sidePanel.photos":tt,"sidePanel.elements":zt,"sidePanel.upload":E,"sidePanel.background":pt,"sidePanel.pages":q,"sidePanel.layers":et,"sidePanel.resize":xt,"sidePanel.draw":dt,"sidePanel.videos":Gt,"sidePanel.variables":W,"variables.text":Wt,"variables.image":tt,"variables.video":Gt,"variables.color":ct,"variables.boolean":Bt,"toolbar.opacity":U,"toolbar.filters":Vt,"toolbar.aiWrite":Ot,"toolbar.insertVariable":W,"toolbar.duration":Tt,"toolbar.trim":ht,"toolbar.flipHorizontal":z,"toolbar.flipVertical":j,"toolbar.zoomIn":$t,"toolbar.zoomOut":_t,"toolbar.crop":J,"toolbar.paddingSides":vt,"imageEdit.ai":Ot,"colorPicker.reverseGradient":z,"download.export":Dt,"download.image":tt,"download.pdf":A,"download.video":Gt,"draw.select":lt,"draw.brush":K,"draw.highlighter":Y,"background.colorPicker":ct,"pagesTimeline.play":ut,"pagesTimeline.pause":mt,"pagesTimeline.rewind":wt,"size.instagram":Jt,"size.facebook":Kt,"size.youtube":Nt,"size.linkedin":Zt,"size.twitter":qt,"size.video":Gt,"size.print":A,"size.businessCard":_,"animation.directionRight":L,"animation.directionLeft":k,"animation.directionUp":O,"animation.directionDown":h,"animation.directionBottomRight":w,"animation.directionBottomLeft":P,"animation.directionTopRight":T,"animation.directionTopLeft":R,"animation.typeMove":Qt,"animation.typeFade":Xt,"animation.typeZoom":Yt,"animation.typeBlur":oi,"animation.typeCount":ni,"animation.typeRotate":ti,"animation.typeBlink":ii,"animation.typeBounce":ei,"animation.typePop":ai,"animation.typeRise":ri,"animation.typeFlip":li,"animation.typeGrowTurn":si,"animation.typePulse":pi,"animation.typeFloat":ci,"animation.typeShake":mi,"animation.typeTypewriter":di,"animation.typeLineRise":yi,"animation.typeWordRise":gi,"animation.typeWordFade":ui,"animation.typeLetterPop":bi,"animation.typeWordBlur":fi,"animation.typeWipe":xi,"animation.typeGlow":vi,"animation.typeKenBurns":hi,"animation.typeLineWipe":Pi,"animation.typeLinePeek":wi,"animation.typeLetterWave":ki,"animation.typeNone":At,"animation.settings":Lt},Li=e.map();export const setIcons=o(t=>{for(const i of Object.keys(t)){const e=t[i];null!=e&&("function"==typeof e||"object"==typeof e?Li.set(i,e):console.warn(`polotno: setIcons('${i}') expects a React component, received ${typeof e}. Ignored.`))}});export const resetIcons=o(()=>Li.clear());export const PolotnoIcon=n(e=>{var o,{name:n}=e,a=t(e,["name"]);const r=null!==(o=Li.get(n))&&void 0!==o?o:zi[n];return i(r,Object.assign({"data-pn-icon":""},a))});
@@ -1 +1 @@
1
- import{getFlippedCropRect as t,loadImage as e,mayBeUnsizedSvg as i}from"@polotno/core/image";import{polotnoError as h}from"@polotno/core/errors";import{fetchSvgText as a,isSvgUrl as r,prepareSvgSource as o,urlToString as n}from"@polotno/core/svg";import{UNIT as c,matchesAspect as s}from"./geometry.js";export const WORKING_MAX_SIDE=4096;const w=(t,e,i)=>h("IMAGE_FAILED","This device could not prepare the image. Try a smaller image.",{reason:"raster-failed",stage:t,width:e.width,height:e.height},i);export function rasterCanvas(t,e){try{if(![t.width,t.height].every(t=>Number.isInteger(t)&&t>0&&t<=4096)){throw new Error("Invalid working dimensions")}const e=document.createElement("canvas");e.width=t.width,e.height=t.height;const i=e.getContext("2d");if(!i){throw new Error("Canvas 2D unavailable")}return{canvas:e,ctx:i}}catch(i){throw w(e,t,i)}}export async function encodeRaster(t,e){try{return await new Promise((e,i)=>t.toBlob(t=>t?e(t):i(new Error("PNG encoding failed")),"image/png"))}catch(i){throw w(e,t,i)}}export async function withBlobImage(t,i){const h=URL.createObjectURL(t);try{return await i(await e(h))}finally{URL.revokeObjectURL(h)}}export async function rasterizeImageInput(h,l=c){const g=r(h.src),d=g?o(await n(h.src)):h.src;let m=await e(d);if(!g&&i(m)){const t=await a(d).catch(()=>null);null!==t&&(m=await e(o(t)))}const f={width:m.naturalWidth,height:m.naturalHeight},p=t(h,f),u=Math.max(p.width,p.height)/Math.max(h.width,h.height),x=function(t){const e=Math.max(t.width,t.height);if(!Number.isFinite(e)||Math.min(t.width,t.height)<=0){throw w("compose",t)}for(let i=Math.min(4096,Math.ceil(e));i>0;i--){const h=i/e,a={width:Math.max(1,Math.round(t.width*h)),height:Math.max(1,Math.round(t.height*h))};if(s(a,t)){return a}}throw new RangeError("The image aspect cannot fit the working raster.")}({width:h.width*l.width*u,height:h.height*l.height*u}),{canvas:M,ctx:y}=rasterCanvas(x,"compose"),v=h.flipX?1-l.x-l.width:l.x,R=h.flipY?1-l.y-l.height:l.y;y.translate(h.flipX?x.width:0,h.flipY?x.height:0),y.scale(h.flipX?-1:1,h.flipY?-1:1);try{y.drawImage(m,p.x+v*p.width,p.y+R*p.height,l.width*p.width,l.height*p.height,0,0,x.width,x.height)}catch(I){throw w("compose",x,I)}return{image:await encodeRaster(M,"compose"),size:x}}export async function rectangleMask(t,e){const{canvas:i,ctx:h}=rasterCanvas(t,"mask");h.fillStyle="black",h.fillRect(0,0,t.width,t.height);const a=Math.max(0,Math.floor(e.x*t.width)),r=Math.max(0,Math.floor(e.y*t.height)),o=Math.min(t.width,Math.ceil((e.x+e.width)*t.width)),n=Math.min(t.height,Math.ceil((e.y+e.height)*t.height));return h.fillStyle="white",h.fillRect(a,r,o-a,n-r),encodeRaster(i,"mask")}
1
+ import{getFlippedCropRect as t,loadImage as e,mayBeUnsizedSvg as i}from"@polotno/core/image";import{polotnoError as h}from"@polotno/core/errors";import{drawImageWindow as a}from"@polotno/core/downscale";import{fetchSvgText as r,isSvgUrl as o,prepareSvgSource as n,urlToString as c}from"@polotno/core/svg";import{UNIT as s,matchesAspect as w}from"./geometry.js";export const WORKING_MAX_SIDE=4096;const l=(t,e,i)=>h("IMAGE_FAILED","This device could not prepare the image. Try a smaller image.",{reason:"raster-failed",stage:t,width:e.width,height:e.height},i);export function rasterCanvas(t,e){try{if(![t.width,t.height].every(t=>Number.isInteger(t)&&t>0&&t<=4096)){throw new Error("Invalid working dimensions")}const e=document.createElement("canvas");e.width=t.width,e.height=t.height;const i=e.getContext("2d");if(!i){throw new Error("Canvas 2D unavailable")}return{canvas:e,ctx:i}}catch(i){throw l(e,t,i)}}export async function encodeRaster(t,e){try{return await new Promise((e,i)=>t.toBlob(t=>t?e(t):i(new Error("PNG encoding failed")),"image/png"))}catch(i){throw l(e,t,i)}}export async function withBlobImage(t,i){const h=URL.createObjectURL(t);try{return await i(await e(h))}finally{URL.revokeObjectURL(h)}}export async function rasterizeImageInput(h,g=s){const d=o(h.src),m=d?n(await c(h.src)):h.src;let f=await e(m);if(!d&&i(f)){const t=await r(m).catch(()=>null);null!==t&&(f=await e(n(t)))}const p={width:f.naturalWidth,height:f.naturalHeight},u=t(h,p),x=Math.max(u.width,u.height)/Math.max(h.width,h.height),y=function(t){const e=Math.max(t.width,t.height);if(!Number.isFinite(e)||Math.min(t.width,t.height)<=0){throw l("compose",t)}for(let i=Math.min(4096,Math.ceil(e));i>0;i--){const h=i/e,a={width:Math.max(1,Math.round(t.width*h)),height:Math.max(1,Math.round(t.height*h))};if(w(a,t)){return a}}throw new RangeError("The image aspect cannot fit the working raster.")}({width:h.width*g.width*x,height:h.height*g.height*x}),{canvas:M,ctx:v}=rasterCanvas(y,"compose"),R=h.flipX?1-g.x-g.width:g.x,I=h.flipY?1-g.y-g.height:g.y;v.translate(h.flipX?y.width:0,h.flipY?y.height:0),v.scale(h.flipX?-1:1,h.flipY?-1:1);try{a(v,f,{x:u.x+R*u.width,y:u.y+I*u.height,width:g.width*u.width,height:g.height*u.height},{x:0,y:0,width:y.width,height:y.height})}catch(b){throw l("compose",y,b)}return{image:await encodeRaster(M,"compose"),size:y}}export async function rectangleMask(t,e){const{canvas:i,ctx:h}=rasterCanvas(t,"mask");h.fillStyle="black",h.fillRect(0,0,t.width,t.height);const a=Math.max(0,Math.floor(e.x*t.width)),r=Math.max(0,Math.floor(e.y*t.height)),o=Math.min(t.width,Math.ceil((e.x+e.width)*t.width)),n=Math.min(t.height,Math.ceil((e.y+e.height)*t.height));return h.fillStyle="white",h.fillRect(a,r,o-a,n-r),encodeRaster(i,"mask")}
@@ -1,6 +1,7 @@
1
1
  import { Instance, SnapshotIn, IAnyModelType, IAnyType } from 'mobx-state-tree';
2
- import { NodeType } from './node-model.js';
2
+ import { NodeType, renewIds } from './node-model.js';
3
3
  import { type AnimationAttrs, type WipeBand } from '../utils/animations.js';
4
+ import { forEveryNode } from '@polotno/core/for-every-node';
4
5
  import { TextElementType } from './text-model.js';
5
6
  import { ImageElementType } from './image-model.js';
6
7
  import { VideoElementType } from './video-model.js';
@@ -11,7 +12,8 @@ import { GifElementType } from './gif-model.js';
11
12
  import { LottieElementType } from './lottie-model.js';
12
13
  import { TableElementType } from './table-model.js';
13
14
  export declare const forEveryChild: (node: any, cb: any) => void;
14
- export { forEveryNode } from '@polotno/core/for-every-node';
15
+ export { forEveryNode };
16
+ export { renewIds };
15
17
  export declare function zIndexOps<T extends {
16
18
  id: string;
17
19
  }>(self: {
@@ -403,7 +405,11 @@ export declare const TYPES_MAP: {
403
405
  backgroundPadding: import("mobx-state-tree").IType<number | undefined, number, number>;
404
406
  borderColor: import("mobx-state-tree").IType<string | undefined, string, string>;
405
407
  borderSize: import("mobx-state-tree").IType<number | undefined, number, number>;
406
- legacyBackground: import("mobx-state-tree").IMaybe<import("mobx-state-tree").ISimpleType<boolean>>;
408
+ backgroundShape: import("mobx-state-tree").IMaybe<import("mobx-state-tree").ISimpleType<string>>;
409
+ paddingTop: import("mobx-state-tree").IMaybe<import("mobx-state-tree").ISimpleType<number>>;
410
+ paddingRight: import("mobx-state-tree").IMaybe<import("mobx-state-tree").ISimpleType<number>>;
411
+ paddingBottom: import("mobx-state-tree").IMaybe<import("mobx-state-tree").ISimpleType<number>>;
412
+ paddingLeft: import("mobx-state-tree").IMaybe<import("mobx-state-tree").ISimpleType<number>>;
407
413
  curveEnabled: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
408
414
  curvePower: import("mobx-state-tree").IType<number | undefined, number, number>;
409
415
  textOverflow: import("mobx-state-tree").IMaybe<import("mobx-state-tree").ISimpleType<string>>;
@@ -2263,7 +2269,10 @@ export declare const TYPES_MAP: {
2263
2269
  _strokeWidth: import("mobx-state-tree").IMaybe<import("mobx-state-tree").ISimpleType<number>>;
2264
2270
  _stroke: import("mobx-state-tree").IMaybe<import("mobx-state-tree").ISimpleType<string>>;
2265
2271
  _cellBackground: import("mobx-state-tree").IMaybe<import("mobx-state-tree").ISimpleType<string>>;
2266
- _cellPadding: import("mobx-state-tree").IMaybe<import("mobx-state-tree").ISimpleType<number>>;
2272
+ _cellPaddingTop: import("mobx-state-tree").IMaybe<import("mobx-state-tree").ISimpleType<number>>;
2273
+ _cellPaddingRight: import("mobx-state-tree").IMaybe<import("mobx-state-tree").ISimpleType<number>>;
2274
+ _cellPaddingBottom: import("mobx-state-tree").IMaybe<import("mobx-state-tree").ISimpleType<number>>;
2275
+ _cellPaddingLeft: import("mobx-state-tree").IMaybe<import("mobx-state-tree").ISimpleType<number>>;
2267
2276
  opacity: import("mobx-state-tree").IType<number | undefined, number, number>;
2268
2277
  rowSpan: import("mobx-state-tree").IType<number | undefined, number, number>;
2269
2278
  colSpan: import("mobx-state-tree").IType<number | undefined, number, number>;
@@ -2320,6 +2329,10 @@ export declare const TYPES_MAP: {
2320
2329
  readonly strokeWidth: number;
2321
2330
  readonly stroke: string;
2322
2331
  readonly cellBackground: string;
2332
+ readonly cellPaddingTop: number;
2333
+ readonly cellPaddingRight: number;
2334
+ readonly cellPaddingBottom: number;
2335
+ readonly cellPaddingLeft: number;
2323
2336
  readonly cellPadding: number;
2324
2337
  readonly width: number;
2325
2338
  readonly height: number;
@@ -2371,7 +2384,10 @@ export declare const TYPES_MAP: {
2371
2384
  style: import("mobx-state-tree").IMaybe<import("mobx-state-tree").ISimpleType<"dashed" | "dotted" | "none" | "solid">>;
2372
2385
  }, {}, import("mobx-state-tree")._NotCustomized, any>>;
2373
2386
  }, {}, import("mobx-state-tree")._NotCustomized, any>>>) | undefined;
2374
- cellPadding: number;
2387
+ cellPaddingTop: number;
2388
+ cellPaddingRight: number;
2389
+ cellPaddingBottom: number;
2390
+ cellPaddingLeft: number;
2375
2391
  };
2376
2392
  readonly borderInsets: {
2377
2393
  top: number;
@@ -2449,7 +2465,10 @@ export declare const TYPES_MAP: {
2449
2465
  strokeWidth: import("mobx-state-tree").IType<number | undefined, number, number>;
2450
2466
  stroke: import("mobx-state-tree").IType<string | undefined, string, string>;
2451
2467
  cellBackground: import("mobx-state-tree").IType<string | undefined, string, string>;
2452
- cellPadding: import("mobx-state-tree").IType<number | undefined, number, number>;
2468
+ cellPaddingTop: import("mobx-state-tree").IType<number | undefined, number, number>;
2469
+ cellPaddingRight: import("mobx-state-tree").IType<number | undefined, number, number>;
2470
+ cellPaddingBottom: import("mobx-state-tree").IType<number | undefined, number, number>;
2471
+ cellPaddingLeft: import("mobx-state-tree").IType<number | undefined, number, number>;
2453
2472
  }, {
2454
2473
  readonly page: any;
2455
2474
  readonly store: any;
@@ -2603,6 +2622,7 @@ export declare const TYPES_MAP: {
2603
2622
  } & {
2604
2623
  readonly _cellMap: Map<string, import("./table-model.js").TableCellType>;
2605
2624
  getActualRowHeight(rowIndex: number): number;
2625
+ readonly cellPadding: number;
2606
2626
  } & {
2607
2627
  getCell(row: number, col: number): import("./table-model.js").TableCellType | undefined;
2608
2628
  visibleCellAt(row: number, col: number): import("./table-model.js").TableCellType | undefined;
@@ -2657,10 +2677,6 @@ export declare const TYPES_MAP: {
2657
2677
  resizeRow(index: number, delta: number): void;
2658
2678
  setCellBorders(cellIds: string[], sides: import("./table-model.js").BorderSideName[], attrs: import("./table-model.js").BorderAttrs): void;
2659
2679
  applyBorderMode(mode: import("./table-model.js").BorderMode, attrs: import("./table-model.js").BorderAttrs): void;
2660
- } & {
2661
- clone(attrs?: any, { skipSelect }?: {
2662
- skipSelect?: boolean | undefined;
2663
- }): any;
2664
2680
  }, any, any>;
2665
2681
  };
2666
2682
  export declare function registerShapeModel<P extends {
@@ -1 +1 @@
1
- var e=this&&this.__rest||function(e,t){var o={};for(var i in e){Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(o[i]=e[i])}if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(e);r<i.length;r++){t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(o[i[r]]=e[i[r]])}}return o};import{isAlive as t,types as o}from"mobx-state-tree";import{nanoid as i}from"nanoid";import{GROUP_BLEND_MODES as r}from"@polotno/schema/defaults";import{Node as n,explicitWrite as l}from"./node-model.js";import{Animation as s,Shape as a}from"./shape-model.js";import{animate as c,playedAnimations as d,setAnimationOf as p}from"../utils/animations.js";import{polotnoError as m}from"@polotno/core/errors";import{transitionWindows as h}from"@polotno/core/animation-presets";import{getPlayheadLocalTime as f,isHeldByPreview as y}from"../utils/timeline.js";import{getCenter as u,getTotalClientRect as g}from"../utils/math.js";import{TextElement as E}from"./text-model.js";import{ImageElement as v}from"./image-model.js";import{VideoElement as b}from"./video-model.js";import{LineElement as x}from"./line-model.js";import{SVGElement as w}from"./svg-model.js";import{FigureElement as j}from"./figure-model.js";import{GifElement as O}from"./gif-model.js";import{LottieElement as S}from"./lottie-model.js";import{TableElement as P}from"./table-model.js";export const forEveryChild=(e,t)=>{if(e.children){for(const o of e.children){if(!0===t(o)){break}forEveryChild(o,t)}}};export{forEveryNode}from"@polotno/core/for-every-node";export function zIndexOps(e){const t=(t,o,i)=>{const r=t.map(t=>e.children.findIndex(e=>e.id===t)).filter(e=>-1!==e).sort((e,t)=>(t-e)*o);for(const n of r){const r=e.children[n+o];!r||t.indexOf(r.id)>=0||i(n)}},o=(e,o)=>{let i=!1;return t(e,o,()=>{i=!0}),i},i=(o,i)=>{t(o,i,t=>{const o=e.children.slice();[o[t],o[t+i]]=[o[t+i],o[t]],e.children.replace(o)})},r=(t,o)=>{const i=[],r=[];e.children.forEach(e=>{(t.indexOf(e.id)>=0?i:r).push(e)}),e.children.replace(o?r.concat(i):i.concat(r))};return{canMoveElementsUp:e=>o(e,1),canMoveElementsTop:e=>o(e,1),canMoveElementsDown:e=>o(e,-1),canMoveElementsBottom:e=>o(e,-1),moveElementsUp(e){i(e,1)},moveElementsDown(e){i(e,-1)},moveElementsTop(e){r(e,!0)},moveElementsBottom(e){r(e,!1)},setElementZIndex(t,o){const i=e.children.find(e=>e.id===t);if(i){const t=e.children.filter(e=>e!==i);t.splice(o,0,i),e.children.replace(t)}}}}const C=[...new Array(20)].map((e,t)=>o.late(()=>z[t]));export const ElementTypes=o.union({dispatcher:e=>{const t=TYPES_MAP[e.type];if(!t){const t=`Unknown element type: "${e.type}"`;throw m("DESIGN_INVALID",t,{errors:[{path:"type",message:t}],knownTypes:Object.keys(TYPES_MAP)})}return t}},w,E,v,x,b,j,O,S,P,o.late(()=>GroupElement),...C);const M=Object.freeze({x:0,y:0,offsetX:0,offsetY:0,scaleX:1,scaleY:1,rotation:0,opacity:1});function T(e){return 1===e?M:Object.assign(Object.assign({},M),{opacity:e})}const Y=(e,t)=>"number"==typeof e&&isFinite(e)?e:t;function _(e,t,o,i,r){var n,l,s;const a={x:e.x,y:e.y,width:e.width,height:e.height,rotation:null!==(n=e.rotation)&&void 0!==n?n:0,opacity:i,fontSize:0,cropX:0,cropY:0,cropWidth:1,cropHeight:1,page:r},d=c({element:a,animation:t,dTime:o})||{},p=Y(d.width,e.width),m=Y(d.height,e.height);return{x:Y(d.x,e.x),y:Y(d.y,e.y),width:p>0?p:e.width,height:m>0?m:e.height,rotation:Y(d.rotation,a.rotation),opacity:Math.min(1,Math.max(0,Y(d.opacity,i))),wipe:null!==(l=d.wipe)&&void 0!==l?l:e.wipe,flipScale:null!==(s=d.flipScale)&&void 0!==s?s:e.flipScale}}export const GroupElement=n.named("Group").props({type:"group",blendMode:o.optional(o.enumeration([...r]),"pass-through"),children:o.array(ElementTypes),animations:o.array(s)}).views(e=>({get draggable(){let t=!0;return forEveryChild(e,e=>{e.draggable||(t=!1)}),t},get resizable(){let t=!0;return forEveryChild(e,e=>{e.resizable||(t=!1)}),t},get contentEditable(){let t=!0;return forEveryChild(e,e=>{e.contentEditable||(t=!1)}),t},get styleEditable(){let t=!0;return forEveryChild(e,e=>{e.styleEditable||(t=!1)}),t},get locked(){let t=!0;return forEveryChild(e,e=>{e.locked||(t=!1)}),t},get _restingBbox(){const t=[];if(forEveryChild(e,e=>{var o,i,r;if("group"===e.type){return}const n=e.width,l=e.height;!n||!l||n<=0||l<=0||t.push({x:null!==(o=e.x)&&void 0!==o?o:0,y:null!==(i=e.y)&&void 0!==i?i:0,width:n,height:l,rotation:null!==(r=e.rotation)&&void 0!==r?r:0})}),!t.length){return null}const o=g(t);return o.width<=0||o.height<=0?null:{x:o.x,y:o.y,width:o.width,height:o.height}},get a(){var o;if(!t(e)){return M}const i=f(e);if(null===i){return T(e.opacity)}if((e.store.isEditingPaused||y(e))&&this.isSelectedDirectly){return T(e.opacity)}const r=e.page;let n,l,s;for(const t of d(e)){t.enabled&&("enter"===t.type?n=t:"exit"===t.type?l=t:"loop"===t.type&&(s=t))}const a=h(d(e),r.duration),c=!!n&&i<n.delay,p=!!a.enter&&i>=a.enter.start&&i<=a.enter.end,m=!c&&!p&&!!a.exit&&i>=a.exit.start&&i<=a.exit.end,g=!!l&&i>=r.duration-l.delay,E=!!s&&i>=s.delay;if(!(c||p||m||g||E)){return T(e.opacity)}const v=this._restingBbox;if(!v){return T(e.opacity)}let b={x:v.x,y:v.y,width:v.width,height:v.height,rotation:0,opacity:e.opacity};c&&(b.opacity=0),p&&(b=_(v,n,(i-a.enter.start)/a.pace,e.opacity,r)),m&&(b=_(v,l,(i-a.exit.start)/a.pace,e.opacity,r)),g&&(b.opacity=0),E&&(b=_(b,s,i-s.delay,b.opacity,r));const x=u(b);return{x:x.x,y:x.y,offsetX:v.x+v.width/2,offsetY:v.y+v.height/2,scaleX:b.width/v.width*(null!==(o=b.flipScale)&&void 0!==o?o:1),scaleY:b.height/v.height,rotation:b.rotation,opacity:b.opacity,wipe:b.wipe}},get isSelectedDirectly(){return!!t(e)&&e.store.selectedElements.indexOf(e)>=0&&e.selectable},get active(){return!0}})).actions(t=>Object.assign(Object.assign({set(o){var{draggable:i,contentEditable:r,styleEditable:n,resizable:s}=o,a=e(o,["draggable","contentEditable","styleEditable","resizable"]);void 0!==i&&forEveryChild(t,e=>{e.set({draggable:i})}),void 0!==r&&forEveryChild(t,e=>{e.set({contentEditable:r})}),void 0!==n&&forEveryChild(t,e=>{e.set({styleEditable:n})}),void 0!==s&&forEveryChild(t,e=>{e.set({resizable:s})}),Object.assign(t,l(t,a))},addElement(e,{skipSelect:o=!1}={}){const r=TYPES_MAP[e.type];if(!r){return void console.error("Can not find model with type "+e.type)}e.children&&e.children.forEach(e=>{e.id=e.id||i(10)});const n=r.create(Object.assign({id:i(10)},e));return t.children.push(n),n.selectable&&!o&&t.store.selectElements([n.id]),n}},zIndexOps(t)),{setAnimation(e,o){p(t.animations,e,o)}}));const z=[];export const TYPES_MAP={svg:w,text:E,image:v,group:GroupElement,line:x,video:b,figure:j,gif:O,lottie:S,table:P};export function registerShapeModel(e,t){const o=e.type;if(!o){throw new Error('You must pass "type" attribute to custom model.')}const i=a.named(o).props(e),r=t?t(i):i;TYPES_MAP[o]=r,z.push(r)}
1
+ var e=this&&this.__rest||function(e,t){var o={};for(var i in e){Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(o[i]=e[i])}if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(e);r<i.length;r++){t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(o[i[r]]=e[i[r]])}}return o};import{isAlive as t,types as o}from"mobx-state-tree";import{nanoid as i}from"nanoid";import{GROUP_BLEND_MODES as r}from"@polotno/schema/defaults";import{Node as n,explicitWrite as l,renewIds as s}from"./node-model.js";import{Animation as a,Shape as c}from"./shape-model.js";import{animate as d,playedAnimations as p,setAnimationOf as m}from"../utils/animations.js";import{polotnoError as h}from"@polotno/core/errors";import{forEveryNode as f}from"@polotno/core/for-every-node";import{transitionWindows as y}from"@polotno/core/animation-presets";import{getPlayheadLocalTime as u,isHeldByPreview as g}from"../utils/timeline.js";import{getCenter as E,getTotalClientRect as b}from"../utils/math.js";import{TextElement as v}from"./text-model.js";import{ImageElement as x}from"./image-model.js";import{VideoElement as w}from"./video-model.js";import{LineElement as j}from"./line-model.js";import{SVGElement as O}from"./svg-model.js";import{FigureElement as S}from"./figure-model.js";import{GifElement as P}from"./gif-model.js";import{LottieElement as C}from"./lottie-model.js";import{TableElement as M}from"./table-model.js";export const forEveryChild=(e,t)=>{if(e.children){for(const o of e.children){if(!0===t(o)){break}forEveryChild(o,t)}}};export{f as forEveryNode};export{s as renewIds};export function zIndexOps(e){const t=(t,o,i)=>{const r=t.map(t=>e.children.findIndex(e=>e.id===t)).filter(e=>-1!==e).sort((e,t)=>(t-e)*o);for(const n of r){const r=e.children[n+o];!r||t.indexOf(r.id)>=0||i(n)}},o=(e,o)=>{let i=!1;return t(e,o,()=>{i=!0}),i},i=(o,i)=>{t(o,i,t=>{const o=e.children.slice();[o[t],o[t+i]]=[o[t+i],o[t]],e.children.replace(o)})},r=(t,o)=>{const i=[],r=[];e.children.forEach(e=>{(t.indexOf(e.id)>=0?i:r).push(e)}),e.children.replace(o?r.concat(i):i.concat(r))};return{canMoveElementsUp:e=>o(e,1),canMoveElementsTop:e=>o(e,1),canMoveElementsDown:e=>o(e,-1),canMoveElementsBottom:e=>o(e,-1),moveElementsUp(e){i(e,1)},moveElementsDown(e){i(e,-1)},moveElementsTop(e){r(e,!0)},moveElementsBottom(e){r(e,!1)},setElementZIndex(t,o){const i=e.children.find(e=>e.id===t);if(i){const t=e.children.filter(e=>e!==i);t.splice(o,0,i),e.children.replace(t)}}}}const T=[...new Array(20)].map((e,t)=>o.late(()=>I[t]));export const ElementTypes=o.union({dispatcher:e=>{const t=TYPES_MAP[e.type];if(!t){const t=`Unknown element type: "${e.type}"`;throw h("DESIGN_INVALID",t,{errors:[{path:"type",message:t}],knownTypes:Object.keys(TYPES_MAP)})}return t}},O,v,x,j,w,S,P,C,M,o.late(()=>GroupElement),...T);const Y=Object.freeze({x:0,y:0,offsetX:0,offsetY:0,scaleX:1,scaleY:1,rotation:0,opacity:1});function _(e){return 1===e?Y:Object.assign(Object.assign({},Y),{opacity:e})}const z=(e,t)=>"number"==typeof e&&isFinite(e)?e:t;function A(e,t,o,i,r){var n,l,s;const a={x:e.x,y:e.y,width:e.width,height:e.height,rotation:null!==(n=e.rotation)&&void 0!==n?n:0,opacity:i,fontSize:0,cropX:0,cropY:0,cropWidth:1,cropHeight:1,page:r},c=d({element:a,animation:t,dTime:o})||{},p=z(c.width,e.width),m=z(c.height,e.height);return{x:z(c.x,e.x),y:z(c.y,e.y),width:p>0?p:e.width,height:m>0?m:e.height,rotation:z(c.rotation,a.rotation),opacity:Math.min(1,Math.max(0,z(c.opacity,i))),wipe:null!==(l=c.wipe)&&void 0!==l?l:e.wipe,flipScale:null!==(s=c.flipScale)&&void 0!==s?s:e.flipScale}}export const GroupElement=n.named("Group").props({type:"group",blendMode:o.optional(o.enumeration([...r]),"pass-through"),children:o.array(ElementTypes),animations:o.array(a)}).views(e=>({get draggable(){let t=!0;return forEveryChild(e,e=>{e.draggable||(t=!1)}),t},get resizable(){let t=!0;return forEveryChild(e,e=>{e.resizable||(t=!1)}),t},get contentEditable(){let t=!0;return forEveryChild(e,e=>{e.contentEditable||(t=!1)}),t},get styleEditable(){let t=!0;return forEveryChild(e,e=>{e.styleEditable||(t=!1)}),t},get locked(){let t=!0;return forEveryChild(e,e=>{e.locked||(t=!1)}),t},get _restingBbox(){const t=[];if(forEveryChild(e,e=>{var o,i,r;if("group"===e.type){return}const n=e.width,l=e.height;!n||!l||n<=0||l<=0||t.push({x:null!==(o=e.x)&&void 0!==o?o:0,y:null!==(i=e.y)&&void 0!==i?i:0,width:n,height:l,rotation:null!==(r=e.rotation)&&void 0!==r?r:0})}),!t.length){return null}const o=b(t);return o.width<=0||o.height<=0?null:{x:o.x,y:o.y,width:o.width,height:o.height}},get a(){var o;if(!t(e)){return Y}const i=u(e);if(null===i){return _(e.opacity)}if((e.store.isEditingPaused||g(e))&&this.isSelectedDirectly){return _(e.opacity)}const r=e.page;let n,l,s;for(const t of p(e)){t.enabled&&("enter"===t.type?n=t:"exit"===t.type?l=t:"loop"===t.type&&(s=t))}const a=y(p(e),r.duration),c=!!n&&i<n.delay,d=!!a.enter&&i>=a.enter.start&&i<=a.enter.end,m=!c&&!d&&!!a.exit&&i>=a.exit.start&&i<=a.exit.end,h=!!l&&i>=r.duration-l.delay,f=!!s&&i>=s.delay;if(!(c||d||m||h||f)){return _(e.opacity)}const b=this._restingBbox;if(!b){return _(e.opacity)}let v={x:b.x,y:b.y,width:b.width,height:b.height,rotation:0,opacity:e.opacity};c&&(v.opacity=0),d&&(v=A(b,n,(i-a.enter.start)/a.pace,e.opacity,r)),m&&(v=A(b,l,(i-a.exit.start)/a.pace,e.opacity,r)),h&&(v.opacity=0),f&&(v=A(v,s,i-s.delay,v.opacity,r));const x=E(v);return{x:x.x,y:x.y,offsetX:b.x+b.width/2,offsetY:b.y+b.height/2,scaleX:v.width/b.width*(null!==(o=v.flipScale)&&void 0!==o?o:1),scaleY:v.height/b.height,rotation:v.rotation,opacity:v.opacity,wipe:v.wipe}},get isSelectedDirectly(){return!!t(e)&&e.store.selectedElements.indexOf(e)>=0&&e.selectable},get active(){return!0}})).actions(t=>Object.assign(Object.assign({set(o){var{draggable:i,contentEditable:r,styleEditable:n,resizable:s}=o,a=e(o,["draggable","contentEditable","styleEditable","resizable"]);void 0!==i&&forEveryChild(t,e=>{e.set({draggable:i})}),void 0!==r&&forEveryChild(t,e=>{e.set({contentEditable:r})}),void 0!==n&&forEveryChild(t,e=>{e.set({styleEditable:n})}),void 0!==s&&forEveryChild(t,e=>{e.set({resizable:s})}),Object.assign(t,l(t,a))},addElement(e,{skipSelect:o=!1}={}){const r=TYPES_MAP[e.type];if(!r){return void console.error("Can not find model with type "+e.type)}e.children&&e.children.forEach(e=>{e.id=e.id||i(10)});const n=r.create(Object.assign({id:i(10)},e));return t.children.push(n),n.selectable&&!o&&t.store.selectElements([n.id]),n}},zIndexOps(t)),{setAnimation(e,o){m(t.animations,e,o)}}));const I=[];export const TYPES_MAP={svg:O,text:v,image:x,group:GroupElement,line:j,video:w,figure:S,gif:P,lottie:C,table:M};export function registerShapeModel(e,t){const o=e.type;if(!o){throw new Error('You must pass "type" attribute to custom model.')}const i=c.named(o).props(e),r=t?t(i):i;TYPES_MAP[o]=r,I.push(r)}
@@ -1,5 +1,13 @@
1
- import { Instance } from 'mobx-state-tree';
1
+ import { Instance, type IAnyStateTreeNode } from 'mobx-state-tree';
2
2
  import type { Bindings } from '@polotno/schema';
3
+ export declare function ancestorNamed(node: IAnyStateTreeNode, name: 'Store' | 'Page' | 'Group'): any;
4
+ interface IdNode {
5
+ id?: string;
6
+ mergedInto?: string;
7
+ children?: IdNode[];
8
+ cells?: IdNode[];
9
+ }
10
+ export declare function renewIds(root: IdNode): void;
3
11
  export declare function explicitWrite(node: Record<string, any>, attrs: Record<string, any>): Record<string, any>;
4
12
  export declare const unboundWrite: (node: Record<string, any>, attrs: Record<string, any>) => Record<string, any>;
5
13
  export declare const Node: import("mobx-state-tree").IModelType<{
@@ -182,3 +190,4 @@ export declare const Node: import("mobx-state-tree").IModelType<{
182
190
  blendMode: "color" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "normal" | "overlay" | "saturation" | "screen" | "soft-light";
183
191
  }>;
184
192
  export type NodeType = Instance<typeof Node>;
193
+ export {};
@@ -1 +1 @@
1
- var e=this&&this.__rest||function(e,t){var n={};for(var o in e){Object.prototype.hasOwnProperty.call(e,o)&&t.indexOf(o)<0&&(n[o]=e[o])}if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(o=Object.getOwnPropertySymbols(e);r<o.length;r++){t.indexOf(o[r])<0&&Object.prototype.propertyIsEnumerable.call(e,o[r])&&(n[o[r]]=e[o[r]])}}return n};import{types as t,getParentOfType as n,getSnapshot as o,hasParentOfType as r,isAlive as i}from"mobx-state-tree";import{nanoid as s}from"nanoid";import{BLEND_MODES as l}from"@polotno/schema/defaults";import{fillElement as d}from"@polotno/schema/variables";import{Store as a}from"./store.js";import{Page as c}from"./page-model.js";import{GroupElement as p,forEveryNode as m}from"./group-model.js";const g=["cropX","cropY","cropWidth","cropHeight"];function f(e,t,n){const o=e.bindings;if(!o||"bindings"in t){return t}const r=Object.fromEntries(Object.entries(o).filter(([e])=>!n(e))),i=Object.keys(r).length;return i===Object.keys(o).length?t:Object.assign(Object.assign({},t),{bindings:i?r:void 0})}export function explicitWrite(e,t){let n=f(e,t,n=>n in t&&t[n]!==e[n]);return e.fit&&!("fit"in t)&&g.some(e=>e in t)&&(n=Object.assign(Object.assign({},n),{fit:void 0})),n}export const unboundWrite=(e,t)=>f(e,t,e=>e in t);export const Node=t.model("Node",{id:t.identifier,type:"none",name:"",opacity:1,blendMode:t.optional(t.enumeration([...l]),"normal"),custom:t.frozen(),bindings:t.maybe(t.frozen()),href:t.maybe(t.string),visible:!0,selectable:!0,removable:!0,alwaysOnTop:!1,showInExport:!0}).preProcessSnapshot(e=>{for(var t in e){null===e[t]&&(e[t]=void 0)}return e}).postProcessSnapshot(t=>{const{blendMode:n}=t,o=e(t,["blendMode"]);for(const e in o){"_"===e[0]&&delete o[e]}for(const e of["href","bindings","fit","focus"]){void 0===o[e]&&delete o[e]}return n===("group"===o.type?"pass-through":"normal")?o:Object.assign(Object.assign({},o),{blendMode:n})}).views(e=>({get page(){return i(e)?n(e,c):null},get store(){return i(e)?n(e,a):null},get filled(){var t;const n=e,o=i(e)&&(null===(t=n.store)||void 0===t?void 0:t._variablesByName);return o?d({type:e.type,text:n._editModeEnabled?void 0:n.text,placeholder:n.placeholder,src:n.src,fill:n.fill,visible:e.visible,bindings:e.bindings},o):{}},get top(){if(!i(e)){return e}let t=e;for(;;){if(!r(t,p)){return t}t=n(t,p)}},get parent(){if(!i(e)){return null}if(r(e,p)){const t=n(e,p);return t&&t.children&&t.children.length,t}if(r(e,c)){const t=n(e,c);return t&&t.children&&t.children.length,t}if(r(e,a)){const t=n(e,a);return t&&t.pages&&t.pages.length,t}return null},get isHighlighted(){var t;return!!i(e)&&(null===(t=e.store)||void 0===t?void 0:t.highlightedElementId)===e.id},get zIndex(){return i(e)?e.parent.children.indexOf(e):-1}})).actions(e=>({toJSON:()=>Object.assign({},o(e))})).actions(e=>({clone(t={},{skipSelect:n=!1}={}){const o=JSON.parse(JSON.stringify(e.toJSON()));t.id=t.id||s(10);const r=new Map;return m(o,e=>{const t=e.id,n=s(10);r.set(t,n),e.id=n}),m(o,e=>{e.mergedInto&&r.has(e.mergedInto)&&(e.mergedInto=r.get(e.mergedInto))}),Object.assign(o,t),e.page.addElement(o,{skipSelect:n})},set(t){Object.assign(e,explicitWrite(e,t))},moveUp(){var t;null===(t=e.parent)||void 0===t||t.moveElementsUp([e.id])},moveTop(){var t;null===(t=e.parent)||void 0===t||t.moveElementsTop([e.id])},moveDown(){var t;null===(t=e.parent)||void 0===t||t.moveElementsDown([e.id])},moveBottom(){var t;null===(t=e.parent)||void 0===t||t.moveElementsBottom([e.id])},setZIndex(t){e.parent.setElementZIndex(e.id,t)},beforeDestroy(){}}));
1
+ var e=this&&this.__rest||function(e,t){var n={};for(var o in e){Object.prototype.hasOwnProperty.call(e,o)&&t.indexOf(o)<0&&(n[o]=e[o])}if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(o=Object.getOwnPropertySymbols(e);r<o.length;r++){t.indexOf(o[r])<0&&Object.prototype.propertyIsEnumerable.call(e,o[r])&&(n[o[r]]=e[o[r]])}}return n};import{types as t,getParent as n,getSnapshot as o,getType as r,hasParent as i,isAlive as s}from"mobx-state-tree";import{nanoid as l}from"nanoid";import{BLEND_MODES as a}from"@polotno/schema/defaults";import{forEveryNode as d}from"@polotno/core/for-every-node";import{fillElement as c}from"@polotno/schema/variables";export function ancestorNamed(e,t){for(let o=1;i(e,o);o++){const i=n(e,o);if(i&&r(i).name===t){return i}}return null}export function renewIds(e){const t=new Map;d(e,e=>{const n=l(10);e.id&&t.set(e.id,n),e.id=n}),d(e,e=>{const n=e.mergedInto&&t.get(e.mergedInto);n&&(e.mergedInto=n)})}const p=["cropX","cropY","cropWidth","cropHeight"];function m(e,t,n){const o=e.bindings;if(!o||"bindings"in t){return t}const r=Object.fromEntries(Object.entries(o).filter(([e])=>!n(e))),i=Object.keys(r).length;return i===Object.keys(o).length?t:Object.assign(Object.assign({},t),{bindings:i?r:void 0})}export function explicitWrite(e,t){let n=m(e,t,n=>n in t&&t[n]!==e[n]);return e.fit&&!("fit"in t)&&p.some(e=>e in t)&&(n=Object.assign(Object.assign({},n),{fit:void 0})),n}export const unboundWrite=(e,t)=>m(e,t,e=>e in t);export const Node=t.model("Node",{id:t.identifier,type:"none",name:"",opacity:1,blendMode:t.optional(t.enumeration([...a]),"normal"),custom:t.frozen(),bindings:t.maybe(t.frozen()),href:t.maybe(t.string),visible:!0,selectable:!0,removable:!0,alwaysOnTop:!1,showInExport:!0}).preProcessSnapshot(e=>{for(var t in e){null===e[t]&&(e[t]=void 0)}return e}).postProcessSnapshot(t=>{const{blendMode:n}=t,o=e(t,["blendMode"]);for(const e in o){"_"===e[0]&&delete o[e]}for(const e of["href","bindings","fit","focus"]){void 0===o[e]&&delete o[e]}return n===("group"===o.type?"pass-through":"normal")?o:Object.assign(Object.assign({},o),{blendMode:n})}).views(e=>({get page(){return s(e)?ancestorNamed(e,"Page"):null},get store(){return s(e)?ancestorNamed(e,"Store"):null},get filled(){var t;const n=e,o=s(e)&&(null===(t=n.store)||void 0===t?void 0:t._variablesByName);return o?c({type:e.type,text:n._editModeEnabled?void 0:n.text,placeholder:n.placeholder,src:n.src,fill:n.fill,visible:e.visible,bindings:e.bindings},o):{}},get top(){if(!s(e)){return e}let t=e;for(let e=ancestorNamed(t,"Group");e;){t=e,e=ancestorNamed(t,"Group")}return t},get parent(){if(!s(e)){return null}const t=ancestorNamed(e,"Group");if(t){return t.children&&t.children.length,t}const n=ancestorNamed(e,"Page");if(n){return n.children&&n.children.length,n}const o=ancestorNamed(e,"Store");return o?(o.pages&&o.pages.length,o):null},get isHighlighted(){var t;return!!s(e)&&(null===(t=e.store)||void 0===t?void 0:t.highlightedElementId)===e.id},get zIndex(){return s(e)?e.parent.children.indexOf(e):-1}})).actions(e=>({toJSON:()=>Object.assign({},o(e))})).actions(e=>({clone(t={},{skipSelect:n=!1}={}){const o=JSON.parse(JSON.stringify(e.toJSON()));return t.id=t.id||l(10),renewIds(o),Object.assign(o,t),e.page.addElement(o,{skipSelect:n})},set(t){Object.assign(e,explicitWrite(e,t))},moveUp(){var t;null===(t=e.parent)||void 0===t||t.moveElementsUp([e.id])},moveTop(){var t;null===(t=e.parent)||void 0===t||t.moveElementsTop([e.id])},moveDown(){var t;null===(t=e.parent)||void 0===t||t.moveElementsDown([e.id])},moveBottom(){var t;null===(t=e.parent)||void 0===t||t.moveElementsBottom([e.id])},setZIndex(t){e.parent.setElementZIndex(e.id,t)},beforeDestroy(){}}));