polotno 4.12.1 → 4.13.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 (157) hide show
  1. package/blueprint/canvas/context-menu/context-menu.d.ts +2 -2
  2. package/blueprint/canvas/page-controls.d.ts +14 -2
  3. package/blueprint/canvas/tooltip.d.ts +24 -2
  4. package/blueprint/pages-timeline/audio-track.d.ts +12 -2
  5. package/blueprint/pages-timeline/audios.d.ts +10 -2
  6. package/blueprint/pages-timeline/current-time.d.ts +2 -2
  7. package/blueprint/pages-timeline/element-track.d.ts +14 -2
  8. package/blueprint/pages-timeline/elements.d.ts +2 -2
  9. package/blueprint/pages-timeline/page-preview.d.ts +8 -2
  10. package/blueprint/pages-timeline/pages-timeline.d.ts +8 -2
  11. package/blueprint/pages-timeline/pages.d.ts +8 -2
  12. package/blueprint/pages-timeline/play-button.d.ts +2 -2
  13. package/blueprint/pages-timeline/time-ruler.d.ts +10 -2
  14. package/blueprint/side-panel/ai-images-panel.d.ts +6 -2
  15. package/blueprint/side-panel/animations-panel.d.ts +6 -2
  16. package/blueprint/side-panel/background-panel.d.ts +6 -2
  17. package/blueprint/side-panel/draw-panel.d.ts +6 -2
  18. package/blueprint/side-panel/effects-panel.d.ts +6 -2
  19. package/blueprint/side-panel/image-clip-panel.d.ts +6 -2
  20. package/blueprint/side-panel/layers-panel.d.ts +6 -2
  21. package/blueprint/side-panel/pages-panel.d.ts +6 -2
  22. package/blueprint/side-panel/side-panel.d.ts +2 -2
  23. package/blueprint/side-panel/size-panel.d.ts +6 -2
  24. package/blueprint/side-panel/templates-panel.d.ts +6 -2
  25. package/blueprint/side-panel/text-panel.d.ts +6 -2
  26. package/blueprint/side-panel/videos-panel.d.ts +6 -2
  27. package/blueprint/toolbar/admin-button.d.ts +6 -2
  28. package/blueprint/toolbar/animations-picker.d.ts +18 -4
  29. package/blueprint/toolbar/copy-style.d.ts +6 -2
  30. package/blueprint/toolbar/download-button.d.ts +6 -2
  31. package/blueprint/toolbar/duplicate-button.d.ts +6 -2
  32. package/blueprint/toolbar/figure-toolbar.d.ts +8 -8
  33. package/blueprint/toolbar/filters-picker.d.ts +26 -6
  34. package/blueprint/toolbar/gif-toolbar.d.ts +2 -2
  35. package/blueprint/toolbar/group-button.d.ts +6 -2
  36. package/blueprint/toolbar/group-toolbar.d.ts +2 -2
  37. package/blueprint/toolbar/history-buttons.d.ts +6 -2
  38. package/blueprint/toolbar/html-toolbar.d.ts +10 -10
  39. package/blueprint/toolbar/image-remove-background-button.d.ts +10 -2
  40. package/blueprint/toolbar/image-toolbar.d.ts +28 -8
  41. package/blueprint/toolbar/line-toolbar.d.ts +14 -10
  42. package/blueprint/toolbar/lock-button.d.ts +6 -2
  43. package/blueprint/toolbar/many-toolbar.d.ts +2 -2
  44. package/blueprint/toolbar/opacity-picker.d.ts +6 -2
  45. package/blueprint/toolbar/page-toolbar.d.ts +2 -2
  46. package/blueprint/toolbar/position-picker.d.ts +6 -2
  47. package/blueprint/toolbar/remove-button.d.ts +6 -2
  48. package/blueprint/toolbar/svg-toolbar.d.ts +2 -2
  49. package/blueprint/toolbar/table-toolbar.d.ts +44 -14
  50. package/blueprint/toolbar/text-ai-write.d.ts +6 -2
  51. package/blueprint/toolbar/text-toolbar.d.ts +14 -14
  52. package/blueprint/toolbar/toolbar.d.ts +2 -2
  53. package/blueprint/toolbar/video-toolbar.d.ts +6 -6
  54. package/blueprint/toolbar/zoom-buttons.d.ts +4 -4
  55. package/canvas/audio.d.ts +3 -2
  56. package/canvas/context-menu/context-menu.d.ts +2 -2
  57. package/canvas/drawing-layer.d.ts +2 -2
  58. package/canvas/element.d.ts +2 -2
  59. package/canvas/fade-overlay.d.ts +14 -0
  60. package/canvas/fade-overlay.js +1 -0
  61. package/canvas/figure-element.d.ts +2 -2
  62. package/canvas/gif-element.d.ts +2 -2
  63. package/canvas/gif-element.js +1 -1
  64. package/canvas/highlighter.d.ts +6 -2
  65. package/canvas/html-element.d.ts +2 -2
  66. package/canvas/image-element.d.ts +5 -3
  67. package/canvas/image-element.js +1 -1
  68. package/canvas/line-element.d.ts +2 -2
  69. package/canvas/page-controls.d.ts +14 -2
  70. package/canvas/page.d.ts +2 -2
  71. package/canvas/page.js +1 -1
  72. package/canvas/render-tag-element.d.ts +2 -2
  73. package/canvas/render-tag-element.js +1 -1
  74. package/canvas/rich-editor.js +3 -3
  75. package/canvas/rules.d.ts +2 -2
  76. package/canvas/table-element.d.ts +2 -2
  77. package/canvas/text-element.d.ts +2 -2
  78. package/canvas/tooltip.d.ts +24 -2
  79. package/canvas/video-element.d.ts +3 -2
  80. package/canvas/video-element.js +1 -1
  81. package/canvas/workspace-canvas.d.ts +2 -2
  82. package/hooks/use-fade-stop-focus.d.ts +2 -0
  83. package/hooks/use-fade-stop-focus.js +1 -0
  84. package/icons/registry.d.ts +106 -102
  85. package/package.json +31 -34
  86. package/pages-timeline/audio-track.d.ts +14 -2
  87. package/pages-timeline/audio-track.js +1 -1
  88. package/pages-timeline/audios.d.ts +10 -2
  89. package/pages-timeline/current-time.d.ts +2 -2
  90. package/pages-timeline/current-time.js +1 -1
  91. package/pages-timeline/element-track.d.ts +14 -2
  92. package/pages-timeline/element-track.js +1 -1
  93. package/pages-timeline/elements.d.ts +2 -2
  94. package/pages-timeline/page-preview.d.ts +8 -2
  95. package/pages-timeline/page-preview.js +1 -1
  96. package/pages-timeline/pages-timeline.d.ts +8 -2
  97. package/pages-timeline/pages-timeline.js +1 -1
  98. package/pages-timeline/pages.d.ts +8 -2
  99. package/pages-timeline/play-button.d.ts +2 -2
  100. package/pages-timeline/time-ruler.d.ts +10 -2
  101. package/pages-timeline/time-ruler.js +1 -1
  102. package/polotno.bundle.js +166 -165
  103. package/side-panel/ai-images-panel.d.ts +6 -2
  104. package/side-panel/animations-panel.d.ts +6 -2
  105. package/side-panel/background-panel.d.ts +6 -2
  106. package/side-panel/draw-panel.d.ts +6 -2
  107. package/side-panel/effects-panel.d.ts +6 -2
  108. package/side-panel/effects-panel.js +1 -1
  109. package/side-panel/image-clip-panel.d.ts +6 -2
  110. package/side-panel/layers-panel.d.ts +6 -2
  111. package/side-panel/pages-panel.d.ts +6 -2
  112. package/side-panel/side-panel.d.ts +2 -2
  113. package/side-panel/size-panel.d.ts +6 -2
  114. package/side-panel/templates-panel.d.ts +6 -2
  115. package/side-panel/text-panel.d.ts +6 -2
  116. package/side-panel/videos-panel.d.ts +6 -2
  117. package/toolbar/admin-button.d.ts +6 -2
  118. package/toolbar/animations-picker.d.ts +18 -4
  119. package/toolbar/copy-style.d.ts +6 -2
  120. package/toolbar/download-button.d.ts +6 -2
  121. package/toolbar/duplicate-button.d.ts +6 -2
  122. package/toolbar/figure-toolbar.d.ts +8 -8
  123. package/toolbar/filters-picker.d.ts +26 -6
  124. package/toolbar/gif-toolbar.d.ts +2 -2
  125. package/toolbar/group-button.d.ts +6 -2
  126. package/toolbar/group-toolbar.d.ts +2 -2
  127. package/toolbar/history-buttons.d.ts +6 -2
  128. package/toolbar/html-toolbar.d.ts +10 -10
  129. package/toolbar/image-remove-background-button.d.ts +10 -2
  130. package/toolbar/image-toolbar.d.ts +32 -10
  131. package/toolbar/line-toolbar.d.ts +14 -10
  132. package/toolbar/lock-button.d.ts +6 -2
  133. package/toolbar/many-toolbar.d.ts +2 -2
  134. package/toolbar/opacity-picker.d.ts +6 -2
  135. package/toolbar/page-toolbar.d.ts +2 -2
  136. package/toolbar/position-picker.d.ts +6 -2
  137. package/toolbar/remove-button.d.ts +6 -2
  138. package/toolbar/svg-toolbar.d.ts +2 -2
  139. package/toolbar/table-toolbar.d.ts +44 -14
  140. package/toolbar/text-ai-write.d.ts +6 -2
  141. package/toolbar/text-toolbar.d.ts +30 -18
  142. package/toolbar/toolbar.d.ts +2 -2
  143. package/toolbar/video-toolbar.d.ts +12 -6
  144. package/toolbar/video-toolbar.js +1 -1
  145. package/toolbar/zoom-buttons.d.ts +4 -4
  146. package/ui.css +1 -1
  147. package/utils/clip-fade.d.ts +6 -0
  148. package/utils/clip-fade.js +1 -0
  149. package/utils/fade-gradient.d.ts +33 -0
  150. package/utils/fade-gradient.js +1 -0
  151. package/utils/fade-overlay.d.ts +9 -0
  152. package/utils/fade-overlay.js +1 -0
  153. package/utils/l10n.d.ts +19 -0
  154. package/utils/l10n.js +1 -1
  155. package/utils/pointer-drag.d.ts +6 -4
  156. package/utils/pointer-drag.js +1 -1
  157. package/utils/validate-key.js +1 -1
@@ -1 +1 @@
1
- import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import i from"react";import{observer as o}from"mobx-react-lite";import{isAlive as n}from"mobx-state-tree";import{nodeAutorun as a}from"../utils/mobx.js";import{Arc as d,Group as s,Image as l,Rect as c,Text as h}from"react-konva";import{ROLES as u}from"../model/store.js";import{useCanvasImage as m}from"./image-element.js";import{DEFAULT_RETRIES as g,isDeterministicUrl as p,retryDelayMs as f}from"@polotno/core/retry";import v from"konva";import{useWorkspaceStyle as w}from"./workspace-style.js";import{incrementLoader as x,triggerLoadError as y}from"../utils/loader.js";import{polotnoError as E}from"@polotno/core/errors";import{getCropRect as M}from"@polotno/core/image";import*as L from"@polotno/core/svg";import{roundEnabledPx as T,activeAnchorOf as b,roundedCropFraction as C,roundedGeometryPx as I,roundedPosition as R,isCornerAnchor as H,scaledBoxStyleAttrs as S,roundedBoxStyleAttrs as j}from"../utils/px.js";import{useFilteredSource as k}from"./use-filtered-source.js";import{useEvent as O}from"../hooks/use-event.js";import{useFadeIn as P}from"./use-fadein.js";import{isTouchDevice as A}from"../utils/screen.js";import{createPlayGate as W,playMedia as X}from"../utils/media.js";import{useMediabunnyVideo as Y}from"./use-mediabunny-video.js";import{getElementTimeRange as V,getVideoRestMs as _}from"../utils/timeline.js";import{drawReduced as D,exportKernelEnabled as z,shouldResample as U}from"./downscale.js";import{useSizeFixer as N}from"./image-element.js";import{CropOverlay as Z,CROP_CORNER_ANCHORS as B}from"./crop-overlay.js";function F(){return document.createElement("canvas")}const $=new window.Image;$.src=L.svgToURL('\n <svg width="800px" height="800px" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">\n <path opacity="0.6" d="M4 5.49683V18.5032C4 20.05 5.68077 21.0113 7.01404 20.227L18.0694 13.7239C19.384 12.9506 19.384 11.0494 18.0694 10.2761L7.01404 3.77296C5.68077 2.98869 4 3.95 4 5.49683Z" fill="white"/>\n <path d="M4 5.49683V18.5032C4 20.05 5.68077 21.0113 7.01404 20.227L18.0694 13.7239C19.384 12.9506 19.384 11.0494 18.0694 10.2761L7.01404 3.77296C5.68077 2.98869 4 3.95 4 5.49683Z" stroke="#323232" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>\n </svg>\n');const q=new window.Image;q.src=L.svgToURL('\n <svg width="800px" height="800px" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">\n <path opacity="0.6" d="M14 19L14 5C14 3.89543 14.8954 3 16 3L17 3C18.1046 3 19 3.89543 19 5L19 19C19 20.1046 18.1046 21 17 21L16 21C14.8954 21 14 20.1046 14 19Z" fill="white"/>\n <path opacity="0.6" d="M10 19L10 5C10 3.89543 9.10457 3 8 3L7 3C5.89543 3 5 3.89543 5 5L5 19C5 20.1046 5.89543 21 7 21L8 21C9.10457 21 10 20.1046 10 19Z" fill="white"/>\n <path d="M14 19L14 5C14 3.89543 14.8954 3 16 3L17 3C18.1046 3 19 3.89543 19 5L19 19C19 20.1046 18.1046 21 17 21L16 21C14.8954 21 14 20.1046 14 19Z" stroke="#323232" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>\n <path d="M10 19L10 5C10 3.89543 9.10457 3 8 3L7 3C5.89543 3 5 3.89543 5 5L5 19C5 20.1046 5.89543 21 7 21L8 21C9.10457 21 10 20.1046 10 19Z" stroke="#323232" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>\n </svg>\n');export const useCornerRadiusAndCrop=(e,t,r,o,n=0,a=!1)=>{var d;const s=Math.floor(Math.max(e.width*o,1)),l=Math.floor(Math.max(e.height*o,1)),c=Math.min(n*o,s/2,l/2),h=Math.max(e.width/r.width,e.height/r.height)*o,u=z(e.page)&&!a&&U(h,s,l),m=t instanceof HTMLVideoElement?t.videoWidth:null==t?void 0:t.width,g=t instanceof HTMLVideoElement?t.videoHeight:null==t?void 0:t.height,p=0===r.x&&0===r.y&&r.width===m&&r.height===g,f=i.useMemo(()=>{if(t&&m&&g){return p&&0===c&&!u?void 0:F()}},[t,c,u,p,m,g]),w=()=>{if(!f||!t){return}f.width=s,f.height=l;const e=f.getContext("2d");e&&(c&&(e.beginPath(),e.moveTo(c,0),e.lineTo(s-c,0),e.arc(s-c,c,c,3*Math.PI/2,0,!1),e.lineTo(s,l-c),e.arc(s-c,l-c,c,0,Math.PI/2,!1),e.lineTo(c,l),e.arc(c,l-c,c,Math.PI/2,Math.PI,!1),e.lineTo(0,c),e.arc(c,c,c,Math.PI,3*Math.PI/2,!1),e.clip()),u?D(e,t,r,f.width,f.height):e.drawImage(t,r.x,r.y,r.width,r.height,0,0,f.width,f.height))};return i.useLayoutEffect(()=>{w()},[f,e.width,e.height,r.x,r.y,r.width,r.height,n,o,a,null===(d=e.page)||void 0===d?void 0:d._exportingOrRendering,u]),i.useEffect(()=>()=>{f&&"CANVAS"===f.nodeName&&v.Util.releaseCanvas(f)},[f]),[f||t,w]};const G=F(),J=o(({element:r})=>{const o=Math.min(30,r.width/4,r.height/4),n=i.useRef(null);i.useEffect(()=>{const e=n.current;if(!e){return}const t=new v.Animation(t=>{e.rotate(((null==t?void 0:t.timeDiff)||0)/2)},e.getLayer());return t.start(),()=>{t.stop()}});const{mediaLoadingStyle:a}=w();return t(s,{x:r.a.x,y:r.a.y,rotation:r.a.rotation,listening:!1,opacity:r.a.opacity,hideInExport:!r.showInExport,children:[e(c,{width:r.width,height:r.height,fill:a.fill}),e(d,{ref:n,x:r.width/2,y:r.height/2,fill:a.textFill,outerRadius:Math.abs(o),innerRadius:Math.max(1,o-5),angle:270})]})}),K=o(({element:r})=>{const{mediaErrorStyle:i}=w(),o=Math.max(10,Math.min(30,r.width/25));return t(s,{x:r.a.x,y:r.a.y,rotation:r.a.rotation,listening:!1,opacity:r.a.opacity,hideInExport:!r.showInExport,children:[e(c,{width:r.width,height:r.height,fill:i.fill}),e(h,{text:"Can not load the video...",fontSize:o,width:r.width,height:r.height,align:"center",fill:i.textFill,verticalAlign:"middle",padding:5})]})});let Q=function(e,t,r){const o=i.useRef("loading"),n=i.useRef(void 0),[a,d]=i.useState(0),s=i.useRef(void 0),l=i.useRef(void 0),c=i.useRef(void 0);return s.current===e&&l.current===t&&c.current===r||(o.current="loading",n.current=void 0,s.current=e,l.current=t,c.current=r),i.useLayoutEffect(()=>{if(!e){return}const i=p(e)?1:g;let a,s,l,c=0,h=!1,u=!1;const m=e=>{e&&(e.removeAttribute("src"),e.load())},v=()=>{c+=1;const g=document.createElement("video");function p(){h||(g.removeEventListener("canplay",p),u=!0,o.current="loaded",n.current=g,g.currentTime=0,d(Math.random()))}function w(e){var t;const r=4===g.readyState,l=g.buffered&&g.buffered.length>0&&g.buffered.end(g.buffered.length-1)/g.duration*100>=100;if(r&&l){return}if(h){return}if(!u&&c<i){return null==s||s(),m(g),void(a=setTimeout(v,f(c)))}const p=e.message||(null===(t=g.error)||void 0===t?void 0:t.message)||"Unknown error";console.error(new Error("Video failed to load: "+p)),o.current="failed",n.current=void 0,d(Math.random())}l=g,g.addEventListener("canplay",p),g.addEventListener("error",w),s=()=>{g.removeEventListener("canplay",p),g.removeEventListener("error",w)},t&&(g.crossOrigin=t),r&&(g.referrerPolicy=r),g.src=e,g.load()};return v(),()=>{h=!0,clearTimeout(a),null==s||s(),u||m(l)}},[e,t,r]),[n.current,o.current]};export const setVideoLoaderHook=e=>{Q=e};function ee(e){return e.readyState>=HTMLMediaElement.HAVE_CURRENT_DATA}export const useLoader=(e,t,r)=>{const o=i.useRef(void 0),n=()=>{var e;null===(e=o.current)||void 0===e||e.call(o),o.current=void 0};i.useEffect(()=>n,[]),i.useLayoutEffect(()=>{const i=t.slice(0,200),a=`video with id ${r} url: ${i}`;"loading"!==e||o.current||(o.current=x(a)),"loading"!==e&&n(),"failed"===e&&y(E("VIDEO_FAILED",a,{src:i,elementId:r,reason:"load"}))},[e])};export const VideoElement=o(({element:o,store:d})=>{var h,g,p;const[f,w]=i.useState(!1),y=i.useRef(null),E=o.isSelected,[D,z]=i.useState(!1),[U,te]=Q(o.src,"anonymous"),[re,ie]=i.useState(!1),oe=d.activePage===o.page,ne=(null===(h=o.page)||void 0===h?void 0:h._exportingOrRendering)&&"loaded"===te,ae=Y(o,d,ne);useLoader(te,o.src,o.id),U&&(U.playsInline=!0);const de=((e,t,r)=>{const o=i.useMemo(()=>{var i,o;const{flipX:n,flipY:a}=e,d="svg"===e.type||L.isSvgUrl(e.src),s=navigator.userAgent.toLowerCase().indexOf("firefox")>-1;if(!(n||a||s&&d)){return t}if(!t){return null}const l=t instanceof HTMLVideoElement?t.videoWidth:null==t?void 0:t.width,c=t instanceof HTMLVideoElement?t.videoHeight:null==t?void 0:t.height;if(!l||!c){return null}const h=F();let u=1;"svg"===e.type&&(u=Math.max(e.width/l*r,e.height/c*r)),h.width=Math.max(l*u,1),h.height=Math.max(c*u,1);let m=n?-h.width:0,g=a?-h.height:0;return null===(i=h.getContext("2d"))||void 0===i||i.scale(n?-1:1,a?-1:1),null===(o=h.getContext("2d"))||void 0===o||o.drawImage(t,m,g,h.width,h.height),h},[e.flipX,e.flipY,t,e.width,e.height,r]);return i.useEffect(()=>()=>{o&&"CANVAS"===o.nodeName&&v.Util.releaseCanvas(o)},[o]),o})(o,U,d._elementsPixelRatio),se=ne&&ae||de||G,[le=G,ce]=k(o,se);i.useEffect(()=>{U&&d.history.ignore(()=>{o.set({duration:1e3*U.duration})})},[U]);const he=i.useMemo(W,[U]);i.useEffect(()=>{var e;if(!U){return}const t=d.animatedElementsIds,r=(!t.length||t.includes(o.id))&&d.isPlaying;if(!oe||!r&&!D){return void U.pause()}D&&(U.muted=!1,U.currentTime=o.startTime*U.duration,X(U).then(e=>{"refused"===e&&z(!1)}));const i=new v.Animation(()=>{He()},null===(e=y.current)||void 0===e?void 0:e.getLayer());i.start();const n=()=>{z(!1),U.currentTime=o.startTime*U.duration},a=()=>{U.currentTime>=o.endTime*U.duration&&(U.pause(),U.currentTime=o.startTime*U.duration,z(!1))};return U.addEventListener("ended",n),U.addEventListener("timeupdate",a),()=>{U.pause(),i.stop(),U.removeEventListener("ended",n),U.removeEventListener("timeupdate",a)}},[U,D,d.isPlaying,oe]),i.useEffect(()=>{U&&(U.volume=o.volume)},[U,o.volume]),i.useEffect(()=>{U&&(U.playbackRate=o.speed,U.preservesPitch=!1)},[U,o.speed]);const ue=i.useRef(null);i.useEffect(()=>{const e=a(o,()=>{var e,t;if(U){if(ne&&ae){return He(),void d.currentTime}const r=d.animatedElementsIds;if(r.length&&!r.includes(o.id)){return}const i=d.activePage===o.page,n=d.currentTime>=o.page.startTime&&d.currentTime<o.page.startTime+o.page.duration,a=o.startTime*U.duration*1e3,s=U.duration*(o.endTime-o.startTime)*1e3,{start:l,end:c}=V(o.animations,o.page.duration),h=(d.currentTime||o.page.startTime)-o.page.startTime,u=n?_(d.currentTime,o.page.startTime,l,s,a,o.speed):0,m=u/1e3,g=n&&h>=l&&h<c;D||(U.muted=!g,g&&d.isPlaying&&i?U.paused?(U.currentTime=m,he.play(U)):Math.abs(1e3*U.currentTime-u)>500&&(U.currentTime=m):(he.reset(),U.paused||U.pause(),m!==U.currentTime&&(U.currentTime=m),!ee(U)&&!d.isPlaying&&!ue.current&&(ue.current=x(`video ${o.id}`)))),He(),null===(t=null===(e=y.current)||void 0===e?void 0:e.getLayer())||void 0===t||t.batchDraw()}});return()=>{e(),ue.current&&(ue.current(),ue.current=null)}},[d,U,ne,ae,D]),i.useEffect(()=>{var e,t;if(!U){return}if(ne){return null===(e=ue.current)||void 0===e||e.call(ue),void(ue.current=null)}const r=()=>{var e,t,r;!ee(U)&&(null===(e=o.page)||void 0===e?void 0:e._exportingOrRendering)||ue.current&&(He(),null===(r=null===(t=y.current)||void 0===t?void 0:t.getLayer())||void 0===r||r.batchDraw(),ue.current(),ue.current=null)};let i;return(null===(t=o.page)||void 0===t?void 0:t._exportingOrRendering)&&(i=setInterval(r,20)),U.addEventListener("timeupdate",r),U.addEventListener("canplay",r),()=>{clearInterval(i),U.removeEventListener("timeupdate",r),U.removeEventListener("canplay",r)}},[null===(g=o.page)||void 0===g?void 0:g._exportingOrRendering,U,o.id,x,ne]);let{cropX:me,cropY:ge,cropWidth:pe,cropHeight:fe}=o;"loaded"!==te&&(me=ge=0,pe=fe=1);const ve=(we=le)instanceof HTMLVideoElement?we.videoWidth:(null==we?void 0:we.width)||0;var we;const xe=(e=>e instanceof HTMLVideoElement?e.videoHeight:(null==e?void 0:e.height)||0)(le),ye=M({stretchEnabled:o.stretchEnabled,cropX:me,cropY:ge,cropWidth:pe,cropHeight:fe,width:o.a.width,height:o.a.height},{width:ve,height:xe}),Ee=ye.width,Me=ye.height,Le=o.stretchEnabled,Te=null!==(p=o.cornerRadius)&&void 0!==p?p:0,[be,Ce]=useCornerRadiusAndCrop(o,le,ye,d._elementsPixelRatio,Te,!0);let[Ie,Re]=((e,t,r,o)=>{const n=N(e.clipSrc||""),[a,d]=m(n,"anonymous"),s=e.clipSrc?d:"loaded";useLoader(s,e.clipSrc,e.id);const l=i.useMemo(()=>{if(t&&a){return F()}},[t,a]);function c(){var i;if(!a){return}const o=t instanceof HTMLVideoElement?t.videoWidth:null==t?void 0:t.width,n=t instanceof HTMLVideoElement?t.videoHeight:null==t?void 0:t.height;if(!t||!o||!n){return}if(!a||!a.width||!a.height){return}if(!l){return}const d=F(),s=Math.max(e.width/a.width*r,e.height/a.height*r);d.width=a.width*s,d.height=a.height*s,null===(i=d.getContext("2d"))||void 0===i||i.drawImage(a,0,0,d.width,d.height),l.width=Math.max(o,1),l.height=Math.max(n,1);const c=l.getContext("2d");c&&(c.save(),c.drawImage(d,0,0,o,n),v.Util.releaseCanvas(d),c.globalCompositeOperation="source-in",c.drawImage(t,0,0,l.width,l.height),c.restore())}return i.useLayoutEffect(()=>{c()},[l,t,a,e.width,e.height,r,...o]),[e.clipSrc&&a?l:t,c]})(o,be,d._elementsPixelRatio,[ye,Te,d._elementsPixelRatio]);const He=O(()=>{var e,t;ce(),Ce(),Re(),null===(t=null===(e=y.current)||void 0===e?void 0:e.getLayer())||void 0===t||t.batchDraw()});i.useEffect(()=>{He()});const Se=()=>{o._cropEnabled&&setTimeout(()=>{n(o)&&o.toggleCropMode(!0)})},je="loading"===te,ke="failed"===te,Oe=!je&&!ke,Pe=i.useRef({cropX:0,cropY:0,cropWidth:0,cropHeight:0}),Ae=i.useRef(!1),We=Oe?o.a.opacity:0;P(y,We);const Xe=o.selectable||d.role===u.ADMIN,Ye=A();return e(r,{children:t(s,{onMouseEnter:()=>ie(!0),onMouseLeave:()=>ie(!1),children:[je&&e(J,{element:o}),ke&&e(K,{element:o}),e(l,{ref:y,name:"element",id:o.id,image:Ie,x:o.a.x,y:o.a.y,width:o.a.width||1,height:o.a.height||1,rotation:o.a.rotation,opacity:We,shadowEnabled:o.shadowEnabled,shadowBlur:o.shadowBlur,shadowOffsetX:o.shadowOffsetX,shadowOffsetY:o.shadowOffsetY,shadowColor:o.shadowColor,shadowOpacity:o.shadowOpacity,customCrop:ye,listening:Xe,draggable:Ye?o.draggable&&E:o.draggable,preventDefault:!Ye||E,hideInExport:!o.showInExport,onDragMove:e=>{o.set({x:e.target.x(),y:e.target.y()})},onDragEnd:e=>{o.set(R(e.target))},onDblClick:Se,onDblTap:Se,onTransformStart:e=>{w(!0),Ae.current=H(b(e.target)),Pe.current={cropX:o.cropX,cropY:o.cropY,cropWidth:o.cropWidth,cropHeight:o.cropHeight}},onTransform:e=>{const t=e.currentTarget,r=Math.abs(t.scaleX()-1)<1e-7?1:t.scaleX(),i=Math.abs(t.scaleY()-1)<1e-7?1:t.scaleY();t.scaleX(1),t.scaleY(1);const n=1-Ee/ve,a=Math.min(n,Math.max(0,o.cropX)),d=1-Me/xe,s=Math.min(d,Math.max(0,o.cropY)),l=Ae.current,c=!l&&r<1&&Pe.current.cropHeight>Me/xe;let h=l?o.cropWidth:o.cropWidth*r;c&&(h=o.cropWidth);const u=!l&&i<1&&Pe.current.cropWidth>Ee/ve;let m=l?o.cropHeight:o.cropHeight*i;u&&(m=o.cropHeight),Le&&(h=o.cropWidth,m=o.cropHeight);const g=l?Math.min(r,i):1;o.set(Object.assign({cropX:a,cropY:s,x:t.x(),y:t.y(),width:t.width()*r,height:t.height()*i,rotation:e.target.rotation(),cropWidth:Math.min(h,1-a),cropHeight:Math.min(m,1-s)},1!==g&&Object.assign(Object.assign({},S(o,g)),{borderSize:o.borderSize*g})))},onTransformEnd:e=>{const t=e.currentTarget;o.set(Object.assign(Object.assign({width:I(t.width()),height:I(t.height()),x:I(t.x()),y:I(t.y()),rotation:I(e.target.rotation()),cropX:C(o.cropX),cropY:C(o.cropY),cropWidth:C(Ee/ve),cropHeight:C(Me/xe)},j(o)),{borderSize:T(o.borderSize)})),w(!1)}}),e(c,{x:o.a.x,y:o.a.y,width:Math.max(o.a.width-o.borderSize,0),height:Math.max(o.a.height-o.borderSize,0),opacity:We,offsetX:-o.borderSize/2,offsetY:-o.borderSize/2,stroke:o.borderColor,strokeWidth:o.borderSize,listening:!1,visible:!!o.borderSize,rotation:o.rotation,cornerRadius:Math.max(0,Te-o.borderSize),hideInExport:!o.showInExport}),!d.isPlaying&&e(l,{image:D?re||Ye?q:void 0:$,x:o.a.x,y:o.a.y,offsetX:-o.a.width/2+15/d.scale,offsetY:-o.a.height/2+15/d.scale,rotation:o.a.rotation,width:30/d.scale,height:30/d.scale,hideInExport:!0,onClick:()=>z(!D),onTap:()=>z(!D)}),o._cropModeEnabled&&e(Z,{element:o,store:d,previewImage:Ie,sourceImage:le,sourceWidth:ve,sourceHeight:xe,cropAbsoluteWidth:Ee,cropAbsoluteHeight:Me,innerAnchors:B})]})})});
1
+ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import i from"react";import{observer as o}from"mobx-react-lite";import{isAlive as n}from"mobx-state-tree";import{nodeAutorun as a}from"../utils/mobx.js";import{Arc as s,Group as d,Image as h,Rect as l,Text as c}from"react-konva";import{ROLES as u}from"../model/store.js";import{DEFAULT_RETRIES as m,isDeterministicUrl as g,retryDelayMs as p}from"@polotno/core/retry";import f from"konva";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 E}from"@polotno/core/image";import*as y from"@polotno/core/svg";import{roundEnabledPx as L,activeAnchorOf as T,roundedCropFraction as b,roundedGeometryPx as C,roundedPosition as I,isCornerAnchor as R,scaledBoxStyleAttrs as k,roundedBoxStyleAttrs as H}from"../utils/px.js";import{useFilteredSource as S}from"./use-filtered-source.js";import{useEvent as j}from"../hooks/use-event.js";import{useFadeIn as O}from"./use-fadein.js";import{isTouchDevice as P}from"../utils/screen.js";import{createPlayGate as A,playMedia as W}from"../utils/media.js";import{useMediabunnyVideo as X}from"./use-mediabunny-video.js";import{getElementTimeRange as Y,getVideoRestMs as V}from"../utils/timeline.js";import{drawReduced as _,exportKernelEnabled as D,shouldResample as z}from"./downscale.js";import{trySetCanvasSize as U}from"../utils/canvas.js";import{useClipImage as N}from"./image-element.js";import{CropOverlay as Z,CROP_CORNER_ANCHORS as B}from"./crop-overlay.js";function F(){return document.createElement("canvas")}const $=new window.Image;$.src=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 q=new window.Image;q.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 s;const d=Math.floor(Math.max(e.width*o,1)),h=Math.floor(Math.max(e.height*o,1)),l=Math.min(n*o,d/2,h/2),c=Math.max(e.width/r.width,e.height/r.height)*o,u=D(e.page)&&!a&&z(c,d,h),m=t instanceof HTMLVideoElement?t.videoWidth:null==t?void 0:t.width,g=t instanceof HTMLVideoElement?t.videoHeight:null==t?void 0:t.height,p=0===r.x&&0===r.y&&r.width===m&&r.height===g,v=i.useMemo(()=>{if(t&&m&&g){return p&&0===l&&!u?void 0:F()}},[t,l,u,p,m,g]),w=()=>{if(!v||!t){return}v.width=d,v.height=h;const e=v.getContext("2d");e&&(l&&(e.beginPath(),e.moveTo(l,0),e.lineTo(d-l,0),e.arc(d-l,l,l,3*Math.PI/2,0,!1),e.lineTo(d,h-l),e.arc(d-l,h-l,l,0,Math.PI/2,!1),e.lineTo(l,h),e.arc(l,h-l,l,Math.PI/2,Math.PI,!1),e.lineTo(0,l),e.arc(l,l,l,Math.PI,3*Math.PI/2,!1),e.clip()),u?_(e,t,r,v.width,v.height):e.drawImage(t,r.x,r.y,r.width,r.height,0,0,v.width,v.height))};return i.useLayoutEffect(()=>{w()},[v,e.width,e.height,r.x,r.y,r.width,r.height,n,o,a,null===(s=e.page)||void 0===s?void 0:s._exportingOrRendering,u]),i.useEffect(()=>()=>{v&&"CANVAS"===v.nodeName&&f.Util.releaseCanvas(v)},[v]),[v||t,w]};export const useClip=(e,t,r,o)=>{const[n,a]=N(e.clipSrc||""),s=e.clipSrc?a:"loaded";useLoader(s,e.clipSrc,e.id);const d=!!t&&!!n,h=i.useMemo(()=>d?{canvas:F(),mask:F(),width:0,height:0}:void 0,[d]),l=null==h?void 0:h.canvas;function c(){const i=t instanceof HTMLVideoElement?t.videoWidth:null==t?void 0:t.width,o=t instanceof HTMLVideoElement?t.videoHeight:null==t?void 0:t.height;if(!(h&&l&&t&&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));h.width===n&&h.height===a||(U(l,n,a),h.width=n,h.height=a);const s=l.getContext("2d");s&&(s.clearRect(0,0,l.width,l.height),s.save(),s.drawImage(h.mask,0,0,l.width,l.height),s.globalCompositeOperation="source-in",s.drawImage(t,0,0,l.width,l.height),s.restore())}return i.useLayoutEffect(()=>{var t;if(!h||!(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);U(h.mask,Math.min(1e4,Math.max(n.width*i,1)),Math.min(1e4,Math.max(n.height*i,1))),null===(t=h.mask.getContext("2d"))||void 0===t||t.drawImage(n,0,0,h.mask.width,h.mask.height)},[h,n,e.a.width,e.a.height,r]),i.useLayoutEffect(()=>{c()},[h,t,n,e.a.width,e.a.height,r,...o]),i.useEffect(()=>()=>{h&&f.Util.releaseCanvas(h.canvas,h.mask)},[h]),[d?l:t,c]};const G=F(),J=o(({element:r})=>{const o=Math.min(30,r.width/4,r.height/4),n=i.useRef(null);i.useEffect(()=>{const e=n.current;if(!e){return}const t=new 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(d,{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(s,{ref:n,x:r.width/2,y:r.height/2,fill:a.textFill,outerRadius:Math.abs(o),innerRadius:Math.max(1,o-5),angle:270})]})}),K=o(({element:r})=>{const{mediaErrorStyle:i}=v(),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(l,{width:r.width,height:r.height,fill:i.fill}),e(c,{text:"Can not load the video...",fontSize:o,width:r.width,height:r.height,align:"center",fill:i.textFill,verticalAlign:"middle",padding:5})]})});let Q=function(e,t,r){const o=i.useRef("loading"),n=i.useRef(void 0),[a,s]=i.useState(0),d=i.useRef(void 0),h=i.useRef(void 0),l=i.useRef(void 0);return d.current===e&&h.current===t&&l.current===r||(o.current="loading",n.current=void 0,d.current=e,h.current=t,l.current=r),i.useLayoutEffect(()=>{if(!e){return}const i=g(e)?1:m;let a,d,h,l=0,c=!1,u=!1;const f=e=>{e&&(e.removeAttribute("src"),e.load())},v=()=>{l+=1;const m=document.createElement("video");function g(){c||(m.removeEventListener("canplay",g),u=!0,o.current="loaded",n.current=m,m.currentTime=0,s(Math.random()))}function w(e){var t;const r=4===m.readyState,h=m.buffered&&m.buffered.length>0&&m.buffered.end(m.buffered.length-1)/m.duration*100>=100;if(r&&h){return}if(c){return}if(!u&&l<i){return null==d||d(),f(m),void(a=setTimeout(v,p(l)))}const g=e.message||(null===(t=m.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())}h=m,m.addEventListener("canplay",g),m.addEventListener("error",w),d=()=>{m.removeEventListener("canplay",g),m.removeEventListener("error",w)},t&&(m.crossOrigin=t),r&&(m.referrerPolicy=r),m.src=e,m.load()};return v(),()=>{c=!0,clearTimeout(a),null==d||d(),u||f(h)}},[e,t,r]),[n.current,o.current]};export const setVideoLoaderHook=e=>{Q=e};function ee(e){return e.readyState>=HTMLMediaElement.HAVE_CURRENT_DATA}export const useLoader=(e,t,r)=>{const o=i.useRef(void 0),n=()=>{var e;null===(e=o.current)||void 0===e||e.call(o),o.current=void 0};i.useEffect(()=>n,[]),i.useLayoutEffect(()=>{const i=t.slice(0,200),a=`video with id ${r} url: ${i}`;"loading"!==e||o.current||(o.current=w(a)),"loading"!==e&&n(),"failed"===e&&x(M("VIDEO_FAILED",a,{src:i,elementId:r,reason:"load"}))},[e])};export const VideoElement=o(({element:o,store:s})=>{var c,m,g;const[p,v]=i.useState(!1),x=i.useRef(null),M=o.isSelected,[_,D]=i.useState(!1),[z,U]=Q(o.src,"anonymous"),[N,te]=i.useState(!1),re=s.activePage===o.page,ie=(null===(c=o.page)||void 0===c?void 0:c._exportingOrRendering)&&"loaded"===U,oe=X(o,s,ie);useLoader(U,o.src,o.id),z&&(z.playsInline=!0);const ne=((e,t,r)=>{const o=i.useMemo(()=>{var i,o;const{flipX:n,flipY:a}=e,s="svg"===e.type||y.isSvgUrl(e.src),d=navigator.userAgent.toLowerCase().indexOf("firefox")>-1;if(!(n||a||d&&s)){return t}if(!t){return null}const h=t instanceof HTMLVideoElement?t.videoWidth:null==t?void 0:t.width,l=t instanceof HTMLVideoElement?t.videoHeight:null==t?void 0:t.height;if(!h||!l){return null}const c=F();let u=1;"svg"===e.type&&(u=Math.max(e.width/h*r,e.height/l*r)),c.width=Math.max(h*u,1),c.height=Math.max(l*u,1);let m=n?-c.width:0,g=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,m,g,c.width,c.height),c},[e.flipX,e.flipY,t,e.width,e.height,r]);return i.useEffect(()=>()=>{o&&"CANVAS"===o.nodeName&&f.Util.releaseCanvas(o)},[o]),o})(o,z,s._elementsPixelRatio),ae=ie&&oe||ne||G,[se=G,de]=S(o,ae);i.useEffect(()=>{z&&s.history.ignore(()=>{o.set({duration:1e3*z.duration})})},[z]);const he=i.useMemo(A,[z]);i.useEffect(()=>{var e;if(!z){return}const t=s.animatedElementsIds,r=(!t.length||t.includes(o.id))&&s.isPlaying;if(!re||!r&&!_){return void z.pause()}_&&(z.muted=!1,z.currentTime=o.startTime*z.duration,W(z).then(e=>{"refused"===e&&D(!1)}));const i=new f.Animation(()=>{Ie()},null===(e=x.current)||void 0===e?void 0:e.getLayer());i.start();const n=()=>{D(!1),z.currentTime=o.startTime*z.duration},a=()=>{z.currentTime>=o.endTime*z.duration&&(z.pause(),z.currentTime=o.startTime*z.duration,D(!1))};return z.addEventListener("ended",n),z.addEventListener("timeupdate",a),()=>{z.pause(),i.stop(),z.removeEventListener("ended",n),z.removeEventListener("timeupdate",a)}},[z,_,s.isPlaying,re]),i.useEffect(()=>{z&&(z.volume=o.volume)},[z,o.volume]),i.useEffect(()=>{z&&(z.playbackRate=o.speed,z.preservesPitch=!1)},[z,o.speed]);const le=i.useRef(null);i.useEffect(()=>{const e=a(o,()=>{var e,t;if(z){if(ie&&oe){return Ie(),void s.currentTime}const r=s.animatedElementsIds;if(r.length&&!r.includes(o.id)){return}const i=s.activePage===o.page,n=s.currentTime>=o.page.startTime&&s.currentTime<o.page.startTime+o.page.duration,a=o.startTime*z.duration*1e3,d=z.duration*(o.endTime-o.startTime)*1e3,{start:h,end:l}=Y(o.animations,o.page.duration),c=(s.currentTime||o.page.startTime)-o.page.startTime,u=n?V(s.currentTime,o.page.startTime,h,d,a,o.speed):0,m=u/1e3,g=n&&c>=h&&c<l;_||(z.muted=!g,g&&s.isPlaying&&i?z.paused?(z.currentTime=m,he.play(z)):Math.abs(1e3*z.currentTime-u)>500&&(z.currentTime=m):(he.reset(),z.paused||z.pause(),m!==z.currentTime&&(z.currentTime=m),!ee(z)&&!s.isPlaying&&!le.current&&(le.current=w(`video ${o.id}`)))),Ie(),null===(t=null===(e=x.current)||void 0===e?void 0:e.getLayer())||void 0===t||t.batchDraw()}});return()=>{e(),le.current&&(le.current(),le.current=null)}},[s,z,ie,oe,_]),i.useEffect(()=>{var e,t;if(!z){return}if(ie){return null===(e=le.current)||void 0===e||e.call(le),void(le.current=null)}const r=()=>{var e,t,r;!ee(z)&&(null===(e=o.page)||void 0===e?void 0:e._exportingOrRendering)||le.current&&(Ie(),null===(r=null===(t=x.current)||void 0===t?void 0:t.getLayer())||void 0===r||r.batchDraw(),le.current(),le.current=null)};let i;return(null===(t=o.page)||void 0===t?void 0:t._exportingOrRendering)&&(i=setInterval(r,20)),z.addEventListener("timeupdate",r),z.addEventListener("canplay",r),()=>{clearInterval(i),z.removeEventListener("timeupdate",r),z.removeEventListener("canplay",r)}},[null===(m=o.page)||void 0===m?void 0:m._exportingOrRendering,z,o.id,w,ie]);let{cropX:ce,cropY:ue,cropWidth:me,cropHeight:ge}=o;"loaded"!==U&&(ce=ue=0,me=ge=1);const pe=(fe=se)instanceof HTMLVideoElement?fe.videoWidth:(null==fe?void 0:fe.width)||0;var fe;const ve=(e=>e instanceof HTMLVideoElement?e.videoHeight:(null==e?void 0:e.height)||0)(se),we=E({stretchEnabled:o.stretchEnabled,cropX:ce,cropY:ue,cropWidth:me,cropHeight:ge,width:o.a.width,height:o.a.height},{width:pe,height:ve}),xe=we.width,Me=we.height,Ee=o.stretchEnabled,ye=null!==(g=o.cornerRadius)&&void 0!==g?g:0,[Le,Te]=useCornerRadiusAndCrop(o,se,we,s._elementsPixelRatio,ye,!0);let[be,Ce]=useClip(o,Le,s._elementsPixelRatio,[we,ye,s._elementsPixelRatio]);const Ie=j(()=>{var e,t;de(),Te(),Ce(),null===(t=null===(e=x.current)||void 0===e?void 0:e.getLayer())||void 0===t||t.batchDraw()});i.useEffect(()=>{Ie()});const Re=()=>{o._cropEnabled&&setTimeout(()=>{n(o)&&o.toggleCropMode(!0)})},ke="loading"===U,He="failed"===U,Se=!ke&&!He,je=i.useRef({cropX:0,cropY:0,cropWidth:0,cropHeight:0}),Oe=i.useRef(!1),Pe=Se?o.a.opacity:0;O(x,Pe);const Ae=o.selectable||s.role===u.ADMIN,We=P();return e(r,{children:t(d,{onMouseEnter:()=>te(!0),onMouseLeave:()=>te(!1),children:[ke&&e(J,{element:o}),He&&e(K,{element:o}),e(h,{ref:x,name:"element",id:o.id,image:be,x:o.a.x,y:o.a.y,width:o.a.width||1,height:o.a.height||1,rotation:o.a.rotation,opacity:Pe,shadowEnabled:o.shadowEnabled,shadowBlur:o.shadowBlur,shadowOffsetX:o.shadowOffsetX,shadowOffsetY:o.shadowOffsetY,shadowColor:o.shadowColor,shadowOpacity:o.shadowOpacity,customCrop:we,listening:Ae,draggable:We?o.draggable&&M:o.draggable,preventDefault:!We||M,hideInExport:!o.showInExport,onDragMove:e=>{o.set({x:e.target.x(),y:e.target.y()})},onDragEnd:e=>{o.set(I(e.target))},onDblClick:Re,onDblTap:Re,onTransformStart:e=>{v(!0),Oe.current=R(T(e.target)),je.current={cropX:o.cropX,cropY:o.cropY,cropWidth:o.cropWidth,cropHeight:o.cropHeight}},onTransform:e=>{const t=e.currentTarget,r=Math.abs(t.scaleX()-1)<1e-7?1:t.scaleX(),i=Math.abs(t.scaleY()-1)<1e-7?1:t.scaleY();t.scaleX(1),t.scaleY(1);const n=1-xe/pe,a=Math.min(n,Math.max(0,o.cropX)),s=1-Me/ve,d=Math.min(s,Math.max(0,o.cropY)),h=Oe.current,l=!h&&r<1&&je.current.cropHeight>Me/ve;let c=h?o.cropWidth:o.cropWidth*r;l&&(c=o.cropWidth);const u=!h&&i<1&&je.current.cropWidth>xe/pe;let m=h?o.cropHeight:o.cropHeight*i;u&&(m=o.cropHeight),Ee&&(c=o.cropWidth,m=o.cropHeight);const g=h?Math.min(r,i):1;o.set(Object.assign({cropX:a,cropY:d,x:t.x(),y:t.y(),width:t.width()*r,height:t.height()*i,rotation:e.target.rotation(),cropWidth:Math.min(c,1-a),cropHeight:Math.min(m,1-d)},1!==g&&Object.assign(Object.assign({},k(o,g)),{borderSize:o.borderSize*g})))},onTransformEnd:e=>{const t=e.currentTarget;o.set(Object.assign(Object.assign({width:C(t.width()),height:C(t.height()),x:C(t.x()),y:C(t.y()),rotation:C(e.target.rotation()),cropX:b(o.cropX),cropY:b(o.cropY),cropWidth:b(xe/pe),cropHeight:b(Me/ve)},H(o)),{borderSize:L(o.borderSize)})),v(!1)}}),e(l,{x:o.a.x,y:o.a.y,width:Math.max(o.a.width-o.borderSize,0),height:Math.max(o.a.height-o.borderSize,0),opacity:Pe,offsetX:-o.borderSize/2,offsetY:-o.borderSize/2,stroke:o.borderColor,strokeWidth:o.borderSize,listening:!1,visible:!!o.borderSize,rotation:o.rotation,cornerRadius:Math.max(0,ye-o.borderSize),hideInExport:!o.showInExport}),!s.isPlaying&&e(h,{image:_?N||We?q:void 0:$,x:o.a.x,y:o.a.y,offsetX:-o.a.width/2+15/s.scale,offsetY:-o.a.height/2+15/s.scale,rotation:o.a.rotation,width:30/s.scale,height:30/s.scale,hideInExport:!0,onClick:()=>D(!_),onTap:()=>D(!_)}),o._cropModeEnabled&&e(Z,{element:o,store:s,previewImage:be,sourceImage:se,sourceWidth:pe,sourceHeight:ve,cropAbsoluteWidth:xe,cropAbsoluteHeight:Me,innerAnchors:B})]})})});
@@ -65,7 +65,7 @@ export type WorkspaceProps = {
65
65
  right?: number;
66
66
  };
67
67
  };
68
- export declare const WorkspaceCanvas: (({ store, layout, pageControlsEnabled, backgroundColor, transparencyBackgroundColor, pageBorderColor, activePageBorderColor, bleedColor, snapGuideStroke, snapGuideStrokeWidth, snapGuideDash, selectionRectFill, selectionRectStroke, selectionRectStrokeWidth, transformLabelFill, transformLabelTextFill, cropOverlayFill, cropGridStyle, transformerStyle, innerImageCropTransformerStyle, outerImageCropTransformerStyle, highlighterStyle, mediaLoadingStyle, mediaErrorStyle, textOverflowIndicatorStyle, distanceGuideStroke, distanceLabelFill, distanceLabelTextFill, rulerBackgroundColor, rulerTextColor, rulerBorderColor, rulerBorderSize, rulerTickColor, rulerTickSize, components, onKeyDown, onPaste, paddingX, paddingY, pageGap, altCloneEnabled, groupSelectionMode, visiblePagesOffset, renderOnlyActivePage, scrollToPageThreshold, tooltipSafeArea, }: WorkspaceProps) => React.JSX.Element) & {
69
- displayName: string;
68
+ export declare const WorkspaceCanvas: (({ store, layout, pageControlsEnabled, backgroundColor, transparencyBackgroundColor, pageBorderColor, activePageBorderColor, bleedColor, snapGuideStroke, snapGuideStrokeWidth, snapGuideDash, selectionRectFill, selectionRectStroke, selectionRectStrokeWidth, transformLabelFill, transformLabelTextFill, cropOverlayFill, cropGridStyle, transformerStyle, innerImageCropTransformerStyle, outerImageCropTransformerStyle, highlighterStyle, mediaLoadingStyle, mediaErrorStyle, textOverflowIndicatorStyle, distanceGuideStroke, distanceLabelFill, distanceLabelTextFill, rulerBackgroundColor, rulerTextColor, rulerBorderColor, rulerBorderSize, rulerTickColor, rulerTickSize, components, onKeyDown, onPaste, paddingX, paddingY, pageGap, altCloneEnabled, groupSelectionMode, visiblePagesOffset, renderOnlyActivePage, scrollToPageThreshold, tooltipSafeArea, }: WorkspaceProps) => React.JSX.Element) & React.NamedExoticComponent<WorkspaceProps> & {
69
+ readonly type: ({ store, layout, pageControlsEnabled, backgroundColor, transparencyBackgroundColor, pageBorderColor, activePageBorderColor, bleedColor, snapGuideStroke, snapGuideStrokeWidth, snapGuideDash, selectionRectFill, selectionRectStroke, selectionRectStrokeWidth, transformLabelFill, transformLabelTextFill, cropOverlayFill, cropGridStyle, transformerStyle, innerImageCropTransformerStyle, outerImageCropTransformerStyle, highlighterStyle, mediaLoadingStyle, mediaErrorStyle, textOverflowIndicatorStyle, distanceGuideStroke, distanceLabelFill, distanceLabelTextFill, rulerBackgroundColor, rulerTextColor, rulerBorderColor, rulerBorderSize, rulerTickColor, rulerTickSize, components, onKeyDown, onPaste, paddingX, paddingY, pageGap, altCloneEnabled, groupSelectionMode, visiblePagesOffset, renderOnlyActivePage, scrollToPageThreshold, tooltipSafeArea, }: WorkspaceProps) => React.JSX.Element;
70
70
  };
71
71
  export default WorkspaceCanvas;
@@ -0,0 +1,2 @@
1
+ import type { StoreType } from '../model/store.js';
2
+ export declare function useFadeStopFocus(store: StoreType, elementId: string, onSelectStop: (index: number) => boolean): void;
@@ -0,0 +1 @@
1
+ import e from"react";import{useEvent as t}from"./use-event.js";import{getFadeStopFocus as o,setFadeStopFocus as r}from"../utils/fade-overlay.js";export function useFadeStopFocus(n,s,u){const c=t(u);e.useEffect(()=>{const e={elementId:s,onSelectStop:c};return r(n,e),()=>{o(n)===e&&r(n,null)}},[n,s,c])}
@@ -3,111 +3,111 @@ export type IconComponent = ComponentType<{
3
3
  className?: string;
4
4
  }>;
5
5
  declare const defaults: {
6
- 'action.duplicate': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
7
- 'action.split': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
8
- 'action.rename': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
9
- 'action.remove': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
10
- 'action.lock': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
11
- 'action.unlock': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
12
- 'action.undo': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
13
- 'action.redo': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
14
- 'action.add': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
15
- 'action.more': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
16
- 'action.settings': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
17
- 'action.search': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
18
- 'action.close': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
19
- 'action.confirm': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
20
- 'action.none': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
21
- 'action.visible': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
22
- 'action.hidden': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
23
- 'action.dragHandle': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
24
- 'action.eyeDropper': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
25
- 'action.unmuted': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
26
- 'action.muted': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
27
- 'action.help': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
28
- 'ui.chevronUp': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
29
- 'ui.chevronDown': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
30
- 'ui.chevronLeft': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
31
- 'ui.chevronRight': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
32
- 'layering.menu': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
33
- 'layering.up': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
34
- 'layering.down': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
35
- 'layering.top': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
36
- 'layering.bottom': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
37
- 'text.bold': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
38
- 'text.italic': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
39
- 'text.underline': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
40
- 'text.strikethrough': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
41
- 'text.alignLeft': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
42
- 'text.alignCenter': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
43
- 'text.alignRight': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
44
- 'text.alignJustify': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
45
- 'text.valignTop': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
46
- 'text.valignMiddle': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
47
- 'text.valignBottom': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
48
- 'text.uppercase': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
49
- 'text.spacing': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
50
- 'text.bulletList': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
51
- 'text.numberedList': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
52
- 'text.paragraph': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
53
- 'text.richText': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
54
- 'text.uploadFont': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
55
- 'position.alignLeft': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
56
- 'position.alignCenter': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
57
- 'position.alignRight': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
58
- 'position.alignTop': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
59
- 'position.alignMiddle': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
60
- 'position.alignBottom': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
61
- 'position.distributeVertical': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
62
- 'position.distributeHorizontal': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
63
- 'sidePanel.templates': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
64
- 'sidePanel.text': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
65
- 'sidePanel.photos': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
66
- 'sidePanel.elements': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
67
- 'sidePanel.upload': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
68
- 'sidePanel.background': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
69
- 'sidePanel.pages': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
70
- 'sidePanel.layers': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
71
- 'sidePanel.resize': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
72
- 'sidePanel.draw': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
73
- 'sidePanel.videos': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
74
- 'toolbar.opacity': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
75
- 'toolbar.filters': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
76
- 'toolbar.aiWrite': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
77
- 'toolbar.duration': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
78
- 'toolbar.trim': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
79
- 'toolbar.flipHorizontal': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
80
- 'toolbar.flipVertical': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
81
- 'toolbar.zoomIn': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
82
- 'toolbar.zoomOut': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
83
- 'toolbar.crop': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
84
- 'download.export': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
85
- 'download.image': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
86
- 'download.pdf': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
87
- 'download.video': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
88
- 'draw.select': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
89
- 'draw.brush': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
90
- 'draw.highlighter': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
91
- 'background.colorPicker': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
92
- 'pagesTimeline.play': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
93
- 'pagesTimeline.pause': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
94
- 'pagesTimeline.rewind': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
6
+ 'action.duplicate': import("lucide-react").LucideIcon;
7
+ 'action.split': import("lucide-react").LucideIcon;
8
+ 'action.rename': import("lucide-react").LucideIcon;
9
+ 'action.remove': import("lucide-react").LucideIcon;
10
+ 'action.lock': import("lucide-react").LucideIcon;
11
+ 'action.unlock': import("lucide-react").LucideIcon;
12
+ 'action.undo': import("lucide-react").LucideIcon;
13
+ 'action.redo': import("lucide-react").LucideIcon;
14
+ 'action.add': import("lucide-react").LucideIcon;
15
+ 'action.more': import("lucide-react").LucideIcon;
16
+ 'action.settings': import("lucide-react").LucideIcon;
17
+ 'action.search': import("lucide-react").LucideIcon;
18
+ 'action.close': import("lucide-react").LucideIcon;
19
+ 'action.confirm': import("lucide-react").LucideIcon;
20
+ 'action.none': import("lucide-react").LucideIcon;
21
+ 'action.visible': import("lucide-react").LucideIcon;
22
+ 'action.hidden': import("lucide-react").LucideIcon;
23
+ 'action.dragHandle': import("lucide-react").LucideIcon;
24
+ 'action.eyeDropper': import("lucide-react").LucideIcon;
25
+ 'action.unmuted': import("lucide-react").LucideIcon;
26
+ 'action.muted': import("lucide-react").LucideIcon;
27
+ 'action.help': import("lucide-react").LucideIcon;
28
+ 'ui.chevronUp': import("lucide-react").LucideIcon;
29
+ 'ui.chevronDown': import("lucide-react").LucideIcon;
30
+ 'ui.chevronLeft': import("lucide-react").LucideIcon;
31
+ 'ui.chevronRight': import("lucide-react").LucideIcon;
32
+ 'layering.menu': import("lucide-react").LucideIcon;
33
+ 'layering.up': import("lucide-react").LucideIcon;
34
+ 'layering.down': import("lucide-react").LucideIcon;
35
+ 'layering.top': import("lucide-react").LucideIcon;
36
+ 'layering.bottom': import("lucide-react").LucideIcon;
37
+ 'text.bold': import("lucide-react").LucideIcon;
38
+ 'text.italic': import("lucide-react").LucideIcon;
39
+ 'text.underline': import("lucide-react").LucideIcon;
40
+ 'text.strikethrough': import("lucide-react").LucideIcon;
41
+ 'text.alignLeft': import("lucide-react").LucideIcon;
42
+ 'text.alignCenter': import("lucide-react").LucideIcon;
43
+ 'text.alignRight': import("lucide-react").LucideIcon;
44
+ 'text.alignJustify': import("lucide-react").LucideIcon;
45
+ 'text.valignTop': import("lucide-react").LucideIcon;
46
+ 'text.valignMiddle': import("lucide-react").LucideIcon;
47
+ 'text.valignBottom': import("lucide-react").LucideIcon;
48
+ 'text.uppercase': import("lucide-react").LucideIcon;
49
+ 'text.spacing': import("lucide-react").LucideIcon;
50
+ 'text.bulletList': import("lucide-react").LucideIcon;
51
+ 'text.numberedList': import("lucide-react").LucideIcon;
52
+ 'text.paragraph': import("lucide-react").LucideIcon;
53
+ 'text.richText': import("lucide-react").LucideIcon;
54
+ 'text.uploadFont': import("lucide-react").LucideIcon;
55
+ 'position.alignLeft': import("lucide-react").LucideIcon;
56
+ 'position.alignCenter': import("lucide-react").LucideIcon;
57
+ 'position.alignRight': import("lucide-react").LucideIcon;
58
+ 'position.alignTop': import("lucide-react").LucideIcon;
59
+ 'position.alignMiddle': import("lucide-react").LucideIcon;
60
+ 'position.alignBottom': import("lucide-react").LucideIcon;
61
+ 'position.distributeVertical': import("lucide-react").LucideIcon;
62
+ 'position.distributeHorizontal': import("lucide-react").LucideIcon;
63
+ 'sidePanel.templates': import("lucide-react").LucideIcon;
64
+ 'sidePanel.text': import("lucide-react").LucideIcon;
65
+ 'sidePanel.photos': import("lucide-react").LucideIcon;
66
+ 'sidePanel.elements': import("lucide-react").LucideIcon;
67
+ 'sidePanel.upload': import("lucide-react").LucideIcon;
68
+ 'sidePanel.background': import("lucide-react").LucideIcon;
69
+ 'sidePanel.pages': import("lucide-react").LucideIcon;
70
+ 'sidePanel.layers': import("lucide-react").LucideIcon;
71
+ 'sidePanel.resize': import("lucide-react").LucideIcon;
72
+ 'sidePanel.draw': import("lucide-react").LucideIcon;
73
+ 'sidePanel.videos': import("lucide-react").LucideIcon;
74
+ 'toolbar.opacity': import("lucide-react").LucideIcon;
75
+ 'toolbar.filters': import("lucide-react").LucideIcon;
76
+ 'toolbar.aiWrite': import("lucide-react").LucideIcon;
77
+ 'toolbar.duration': import("lucide-react").LucideIcon;
78
+ 'toolbar.trim': import("lucide-react").LucideIcon;
79
+ 'toolbar.flipHorizontal': import("lucide-react").LucideIcon;
80
+ 'toolbar.flipVertical': import("lucide-react").LucideIcon;
81
+ 'toolbar.zoomIn': import("lucide-react").LucideIcon;
82
+ 'toolbar.zoomOut': import("lucide-react").LucideIcon;
83
+ 'toolbar.crop': import("lucide-react").LucideIcon;
84
+ 'download.export': import("lucide-react").LucideIcon;
85
+ 'download.image': import("lucide-react").LucideIcon;
86
+ 'download.pdf': import("lucide-react").LucideIcon;
87
+ 'download.video': import("lucide-react").LucideIcon;
88
+ 'draw.select': import("lucide-react").LucideIcon;
89
+ 'draw.brush': import("lucide-react").LucideIcon;
90
+ 'draw.highlighter': import("lucide-react").LucideIcon;
91
+ 'background.colorPicker': import("lucide-react").LucideIcon;
92
+ 'pagesTimeline.play': import("lucide-react").LucideIcon;
93
+ 'pagesTimeline.pause': import("lucide-react").LucideIcon;
94
+ 'pagesTimeline.rewind': import("lucide-react").LucideIcon;
95
95
  'size.instagram': (props: SVGProps<SVGSVGElement>) => import("react").JSX.Element;
96
96
  'size.facebook': (props: SVGProps<SVGSVGElement>) => import("react").JSX.Element;
97
97
  'size.youtube': (props: SVGProps<SVGSVGElement>) => import("react").JSX.Element;
98
98
  'size.linkedin': (props: SVGProps<SVGSVGElement>) => import("react").JSX.Element;
99
99
  'size.twitter': (props: SVGProps<SVGSVGElement>) => import("react").JSX.Element;
100
- 'size.video': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
101
- 'size.print': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
102
- 'size.businessCard': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
103
- 'animation.directionRight': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
104
- 'animation.directionLeft': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
105
- 'animation.directionUp': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
106
- 'animation.directionDown': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
107
- 'animation.directionBottomRight': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
108
- 'animation.directionBottomLeft': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
109
- 'animation.directionTopRight': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
110
- 'animation.directionTopLeft': import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
100
+ 'size.video': import("lucide-react").LucideIcon;
101
+ 'size.print': import("lucide-react").LucideIcon;
102
+ 'size.businessCard': import("lucide-react").LucideIcon;
103
+ 'animation.directionRight': import("lucide-react").LucideIcon;
104
+ 'animation.directionLeft': import("lucide-react").LucideIcon;
105
+ 'animation.directionUp': import("lucide-react").LucideIcon;
106
+ 'animation.directionDown': import("lucide-react").LucideIcon;
107
+ 'animation.directionBottomRight': import("lucide-react").LucideIcon;
108
+ 'animation.directionBottomLeft': import("lucide-react").LucideIcon;
109
+ 'animation.directionTopRight': import("lucide-react").LucideIcon;
110
+ 'animation.directionTopLeft': import("lucide-react").LucideIcon;
111
111
  'animation.typeMove': (props: SVGProps<SVGSVGElement>) => import("react").JSX.Element;
112
112
  'animation.typeFade': (props: SVGProps<SVGSVGElement>) => import("react").JSX.Element;
113
113
  'animation.typeZoom': (props: SVGProps<SVGSVGElement>) => import("react").JSX.Element;
@@ -120,7 +120,11 @@ export declare const setIcons: (custom: Partial<Record<IconName, IconComponent>>
120
120
  export declare const resetIcons: () => void;
121
121
  export declare const PolotnoIcon: (({ name, ...rest }: {
122
122
  name: IconName;
123
- } & SVGProps<SVGSVGElement>) => import("react").JSX.Element) & {
124
- displayName: string;
123
+ } & SVGProps<SVGSVGElement>) => import("react").JSX.Element) & import("react").NamedExoticComponent<{
124
+ name: IconName;
125
+ } & SVGProps<SVGSVGElement>> & {
126
+ readonly type: ({ name, ...rest }: {
127
+ name: IconName;
128
+ } & SVGProps<SVGSVGElement>) => import("react").JSX.Element;
125
129
  };
126
130
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "polotno",
3
- "version": "4.12.1",
3
+ "version": "4.13.0",
4
4
  "description": "Design editor SDK: embed a Canva-like editor, generate designs from templates and data, export PNG, PDF, and video in the browser or on a server.",
5
5
  "author": "Anton Lavrenov",
6
6
  "repository": {
@@ -112,32 +112,32 @@
112
112
  "./polotno.blueprint.css": "./blueprint.polotno.css"
113
113
  },
114
114
  "dependencies": {
115
- "@base-ui/react": "^1.7.0",
116
- "@polotno/core": "0.11.0",
117
- "@polotno/html-export": "0.5.2",
118
- "@polotno/schema": "0.6.1",
119
- "@polotno/svg-export": "0.6.2",
115
+ "@base-ui/react": "^1.8.0",
116
+ "@polotno/core": "0.12.0",
117
+ "@polotno/html-export": "0.6.0",
118
+ "@polotno/schema": "0.6.2",
119
+ "@polotno/svg-export": "0.7.0",
120
120
  "class-variance-authority": "^0.7.1",
121
121
  "clsx": "^2.1.1",
122
122
  "gifuct-js": "^2.1.2",
123
123
  "konva": "^10.5.0",
124
124
  "lodash-es": "^4.18.1",
125
- "lucide-react": "^1.39.0",
126
- "mediabunny": "^1.55.5",
127
- "mobx": "6.16.1",
128
- "mobx-react-lite": "^4.1.1",
129
- "mobx-state-tree": "7.4.0",
125
+ "lucide-react": "^1.46.0",
126
+ "mediabunny": "^1.56.3",
127
+ "mobx": "7.0.3",
128
+ "mobx-react-lite": "^5.0.3",
129
+ "mobx-state-tree": "8.0.0",
130
130
  "nanoid": "^6.0.1",
131
131
  "quill": "^2.0.3",
132
- "react-konva": "^19.2.7",
133
- "react-konva-utils": "^2.0.0",
132
+ "react-konva": "^19.3.0",
133
+ "react-konva-utils": "^2.1.0",
134
134
  "react-sortablejs": "6.1.4",
135
- "react-window": "^2.3.0",
136
- "render-tag": "^0.1.35",
135
+ "react-window": "^2.3.1",
136
+ "render-tag": "^0.1.37",
137
137
  "sortablejs": "^1.15.7",
138
138
  "svg-round-corners": "^0.4.3",
139
139
  "swr": "^2.5.1",
140
- "tailwind-merge": "^3.6.0",
140
+ "tailwind-merge": "^3.7.0",
141
141
  "tinycolor2": "^1.6.0"
142
142
  },
143
143
  "targets": {
@@ -155,8 +155,8 @@
155
155
  "@blueprintjs/core": "^6.x",
156
156
  "@blueprintjs/icons": "^6.x",
157
157
  "@blueprintjs/select": "^6.x",
158
- "react": "^19.2.0",
159
- "react-dom": "^19.2.0"
158
+ "react": "^19.3.0",
159
+ "react-dom": "^19.3.0"
160
160
  },
161
161
  "peerDependenciesMeta": {
162
162
  "@blueprintjs/core": {
@@ -170,21 +170,19 @@
170
170
  }
171
171
  },
172
172
  "devDependencies": {
173
- "@babel/core": "^8.0.1",
174
- "@babel/parser": "^8.0.4",
175
- "@babel/traverse": "^8.0.4",
173
+ "@babel/parser": "^8.0.5",
174
+ "@babel/traverse": "^8.0.5",
176
175
  "@blueprintjs/core": "6.18.0",
177
176
  "@blueprintjs/icons": "^6.13.0",
178
177
  "@blueprintjs/select": "6.3.4",
179
- "@canvas/image": "^2.0.0",
180
178
  "@tailwindcss/cli": "^4.3.3",
181
179
  "@tailwindcss/vite": "^4.3.3",
182
- "@testing-library/dom": "^10.4.1",
180
+ "@testing-library/dom": "^10.4.2",
183
181
  "@testing-library/react": "^16.3.3",
184
- "@types/react": "^19.2.18",
182
+ "@types/react": "^19.3.0",
185
183
  "@vitejs/plugin-react": "^6.1.1",
186
- "@vitest/browser": "^4.1.11",
187
- "@vitest/browser-playwright": "^4.1.11",
184
+ "@vitest/browser": "^5.0.1",
185
+ "@vitest/browser-playwright": "^5.0.1",
188
186
  "assemblyscript": "^0.28.20",
189
187
  "assert": "^2.1.0",
190
188
  "bippy": "^0.7.3",
@@ -194,20 +192,19 @@
194
192
  "glob": "^13.0.6",
195
193
  "jest-file-snapshot": "^0.7.0",
196
194
  "jsdom": "^30.0.1",
197
- "license-checker": "^25.0.1",
198
- "playwright": "^1.62.1",
199
- "postcss": "^8.5.26",
200
- "postcss-selector-parser": "^7.1.5",
195
+ "playwright": "^1.63.0",
196
+ "postcss": "^8.5.28",
197
+ "postcss-selector-parser": "^7.1.6",
201
198
  "pptxgenjs": "^4.0.1",
202
199
  "process": "^0.11.10",
203
- "react": "^19.2.8",
204
- "react-dom": "^19.2.8",
200
+ "react": "^19.3.0",
201
+ "react-dom": "^19.3.0",
205
202
  "tailwindcss": "^4.3.3",
206
203
  "terser": "^5.51.2",
207
204
  "tw-animate-css": "^1.4.0",
208
205
  "typescript": "~6.0.3",
209
- "vite": "^8.2.2",
210
- "vitest": "^4.1.11"
206
+ "vite": "^8.3.0",
207
+ "vitest": "^5.0.1"
211
208
  },
212
209
  "homepage": "https://polotno.com/",
213
210
  "scripts": {
@@ -9,6 +9,18 @@ export declare const AudioTrack: (({ audio, scale, store, label, row, }: {
9
9
  store: StoreType;
10
10
  label: string;
11
11
  row: number;
12
- }) => React.JSX.Element) & {
13
- displayName: string;
12
+ }) => React.JSX.Element) & React.NamedExoticComponent<{
13
+ audio: AudioType;
14
+ scale: number;
15
+ store: StoreType;
16
+ label: string;
17
+ row: number;
18
+ }> & {
19
+ readonly type: ({ audio, scale, store, label, row, }: {
20
+ audio: AudioType;
21
+ scale: number;
22
+ store: StoreType;
23
+ label: string;
24
+ row: number;
25
+ }) => React.JSX.Element;
14
26
  };
@@ -1 +1 @@
1
- var e=this&&this.__rest||function(e,t){var n={};for(var i in e){Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i])}if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(i=Object.getOwnPropertySymbols(e);o<i.length;o++){t.indexOf(i[o])<0&&Object.prototype.propertyIsEnumerable.call(e,i[o])&&(n[i[o]]=e[i[o]])}}return n};import{jsx as t,jsxs as n}from"react/jsx-runtime";import i from"react";import{observer as o}from"mobx-react-lite";import{PolotnoIcon as a}from"../icons/registry.js";import{t as s}from"../utils/l10n.js";import{firstSliderValue as r}from"../lib/utils.js";import{DRAG_SLOP_PX as l,isPrimaryDrag as m,startPointerDrag as d}from"../utils/pointer-drag.js";import{DropdownMenu as p,DropdownMenuContent as c,DropdownMenuItem as u,DropdownMenuSeparator as h}from"../primitives/dropdown-menu.js";import{Slider as f}from"../primitives/slider.js";import{SpeedControl as x}from"../primitives/speed-control.js";import{Spinner as y}from"./spinner.js";import{useWaveformData as v,useWaveformPath as g}from"./waveform.js";import{TrackWrapper as T,TrackContainer as M,TrackMenu as b,TrackMenuButton as j,TrackHandleLeft as w,TrackHandleRight as I,TrackInlineLabel as O,TrackNameInput as P,WaveformSvg as D}from"./track-styles.js";export const AUDIO_ROW_HEIGHT=28;export const AUDIO_TRACK_HEIGHT=24;const S=({position:e,store:t,scale:n})=>{const i=t.pages;for(const o of i){const t=o.startTime,i=o.startTime+o.duration;if(Math.abs(e-t)<10/n){return t}if(Math.abs(e-i)<10/n){return i}}return null};export const AudioTrack=o(({audio:o,scale:A,store:C,label:N,row:E})=>{const[_,X]=i.useState(1),z=i.useRef(null),[k,H]=i.useState(!1),R=0===o.volume,$=()=>{R?o.set({volume:_>0?_:1}):(X(o.volume),o.set({volume:0}))},B=(e=o.startTime,t=o.endTime,n=o.speed)=>Math.max(0,(t-e)*(o.duration||0)/n),V=e=>Math.max(0,C.duration-e),Y=(e,t=B())=>Math.min(Math.max(0,e),V(t)),F=B(),G=C.duration*A-o.delay*A,L=Math.min(F*A,G),U=o.delay*A,{data:J,isLoading:K}=v(o.src),W=o.visibleDuration*A,q=g(J,20).path,Q=(e,t)=>{if(!m(e)){return}e.stopPropagation();const n=e.clientX,i=U,a=L,s=o.endTime,r=o.startTime,p=o.delay,c=o.duration||1,u=o.speed;d(e,{slopX:l,onMove:e=>{const l=(e.clientX-n)/A;if("start"===t){if(l>=0){const e=l*u,t=Math.max(0,s-.1-r)*c,n=Math.min(e,t);if(n<=0){return}let i=r+n/c;const a=(o.endTime-i)*c/u,m=p+n/u,d=V(a);let h=Math.min(Math.max(0,m),d);const f=S({position:h,store:C,scale:A});h=Math.min(Math.max(0,null!=f?f:h),d);const x=h-m;i=Math.min(o.endTime-.1,Math.max(0,i+x*u/c)),o.set({delay:h,startTime:i})}else{const e=-l*u,t=r*c,n=Math.min(e,t);if(n<=0){return}const i=n/c;let a=Math.max(0,r-i);const s=(o.endTime-a)*c/u,m=p-n/u,d=V(s);let h=Math.min(Math.max(0,m),d);const f=S({position:h,store:C,scale:A});h=Math.min(Math.max(0,null!=f?f:h),d);const x=h-m;a=Math.max(0,Math.min(o.endTime-.1,a+x*u/c)),o.set({delay:h,startTime:a})}}else{const e=i/A+a/A;let t=e+l;const n=S({position:t,store:C,scale:A});t=null!=n?n:t;const r=(t-e)*u/o.duration,m=Math.min(1,Math.max(o.startTime+.1,s+r));o.set({endTime:m})}},onEnd:({moved:e})=>{e&&(()=>{if("start"===t){const e=S({position:o.delay,store:C,scale:A});if(null!=e&&e!==o.delay){const t=B(o.startTime,o.endTime),n=Y(e,t),i=n-o.delay,a=Math.max(0,Math.min(o.endTime-.1,o.startTime+i*u/c));o.set({delay:n,startTime:a})}}})()}})};return t(T,{ref:z,style:{left:`${U}px`,top:28*E+"px",width:`${L}px`,height:"24px"},className:"polotno-audio-container",children:n(M,{style:{width:"100%",height:"100%"},onPointerDown:e=>{if(!m(e)){return}const t=e.clientX,n=U;d(e,{slopX:l,onMove:e=>{const i=(e.clientX-t)/A;let a=n/A+i;const s=a+F,r=S({position:a,store:C,scale:A}),l=S({position:s,store:C,scale:A}),m=null!==r?Math.abs(a-r):Number.POSITIVE_INFINITY,d=null!==l?Math.abs(s-l):Number.POSITIVE_INFINITY;let p;p=Y(null!==r&&m<d?r:null!==l?l-F:a),o.set({delay:Y(p)})}})},children:[t("div",{style:{position:"absolute",left:"4px",top:"50%",transform:"translateY(-50%)",zIndex:10,pointerEvents:"auto"},onClick:e=>{e.stopPropagation(),$()},onPointerDown:e=>e.stopPropagation(),children:t(a,R?{name:"action.muted",className:"pn:size-3.5",style:{opacity:.7,cursor:"pointer"}}:{name:"action.unmuted",className:"pn:size-3.5",style:{opacity:.7,cursor:"pointer"}})}),t("div",{style:{position:"absolute",inset:"0 0 0 0",display:"flex",alignItems:"center",justifyContent:"center",pointerEvents:"none"},children:n("div",{style:{display:"flex",alignItems:"center",width:"100%",height:"100%",gap:"8px",paddingLeft:"22px"},children:[!k&&t(O,{children:N}),q&&t("div",{style:{flex:1,height:"14px",overflow:"hidden",opacity:R?.4:1},children:t(D,{width:W,height:"14",viewBox:`0 0 ${W} 20`,preserveAspectRatio:"none",style:{width:W+"px",height:"14px",transform:`translateX(-${o.startTime*W}px)`},children:t("path",{d:q})})}),K&&t("div",{style:{flex:1,display:"flex",justifyContent:"center",alignItems:"center"},children:t(y,{})})]})}),k&&t(P,{value:o.name,onCommit:e=>{o.set({name:e}),H(!1)},onCancel:()=>H(!1)}),t(w,{onPointerDown:e=>Q(e,"start")}),t(I,{onPointerDown:e=>Q(e,"end")}),t(b,{onClick:e=>{e.stopPropagation()},onPointerDown:e=>e.stopPropagation(),children:n(p,{children:[t(j,{}),n(c,{side:"top",align:"start",anchor:z,style:{width:"220px"},children:[n("div",{style:{padding:"8px 12px"},children:[n("div",{style:{fontSize:"12px",marginBottom:"6px",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t("span",{children:s("pagesTimeline.volume")}),n("span",{children:[Math.round(100*o.volume),"%"]})]}),t(f,{value:[o.volume],min:0,max:1,step:.01,onValueChange:e=>(e=>{const t=Math.max(0,Math.min(1,e));t>0&&X(t),o.set({volume:t})})(r(e))})]}),n("div",{style:{padding:"8px 12px"},children:[t("div",{style:{fontSize:"12px",marginBottom:"6px"},children:s("pagesTimeline.speed")}),t(x,{value:o.speed,onChange:e=>{const t=B(o.startTime,o.endTime,e);o.set({speed:e,delay:Y(o.delay,t)})}})]}),t(h,{}),n(u,{onSelect:e=>{e.preventDefault(),H(!0)},children:[t(a,{name:"action.rename"}),s("pagesTimeline.renameAudio")]}),n(u,{onSelect:e=>{e.preventDefault(),$()},children:[t(a,R?{name:"action.unmuted"}:{name:"action.muted"}),s(R?"pagesTimeline.unmuteAudio":"pagesTimeline.muteAudio")]}),n(u,{onSelect:t=>{t.preventDefault(),(()=>{const t=o.toJSON(),n=o.visibleDuration,i=o.delay+n,a=C.duration-i;let s=o.delay;a>=n?s=i:a>0&&(s=Math.max(0,C.duration-n));const{id:r}=t,l=e(t,["id"]);C.addAudio(Object.assign(Object.assign({},l),{delay:s}))})()},children:[t(a,{name:"action.duplicate"}),s("pagesTimeline.duplicateAudio")]}),t(h,{}),n(u,{onSelect:e=>{e.preventDefault(),C.removeAudio(o.id)},children:[t(a,{name:"action.remove"}),s("pagesTimeline.removeAudio")]})]})]})})]})})});
1
+ var e=this&&this.__rest||function(e,t){var n={};for(var i in e){Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i])}if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(i=Object.getOwnPropertySymbols(e);o<i.length;o++){t.indexOf(i[o])<0&&Object.prototype.propertyIsEnumerable.call(e,i[o])&&(n[i[o]]=e[i[o]])}}return n};import{jsx as t,jsxs as n}from"react/jsx-runtime";import i from"react";import{observer as o}from"mobx-react-lite";import{PolotnoIcon as a}from"../icons/registry.js";import{t as s}from"../utils/l10n.js";import{firstSliderValue as r}from"../lib/utils.js";import{DRAG_SLOP_PX as l,isPrimaryDrag as m,usePointerDrag as d}from"../utils/pointer-drag.js";import{DropdownMenu as p,DropdownMenuContent as c,DropdownMenuItem as u,DropdownMenuSeparator as h}from"../primitives/dropdown-menu.js";import{Slider as f}from"../primitives/slider.js";import{SpeedControl as x}from"../primitives/speed-control.js";import{Spinner as y}from"./spinner.js";import{useWaveformData as v,useWaveformPath as g}from"./waveform.js";import{TrackWrapper as T,TrackContainer as M,TrackMenu as b,TrackMenuButton as j,TrackHandleLeft as w,TrackHandleRight as I,TrackInlineLabel as O,TrackNameInput as P,WaveformSvg as D}from"./track-styles.js";export const AUDIO_ROW_HEIGHT=28;export const AUDIO_TRACK_HEIGHT=24;const S=({position:e,store:t,scale:n})=>{const i=t.pages;for(const o of i){const t=o.startTime,i=o.startTime+o.duration;if(Math.abs(e-t)<10/n){return t}if(Math.abs(e-i)<10/n){return i}}return null};export const AudioTrack=o(({audio:o,scale:A,store:C,label:N,row:E})=>{const[_,X]=i.useState(1),z=i.useRef(null),[k,H]=i.useState(!1),R=d(),$=0===o.volume,B=()=>{$?o.set({volume:_>0?_:1}):(X(o.volume),o.set({volume:0}))},V=(e=o.startTime,t=o.endTime,n=o.speed)=>Math.max(0,(t-e)*(o.duration||0)/n),Y=e=>Math.max(0,C.duration-e),F=(e,t=V())=>Math.min(Math.max(0,e),Y(t)),G=V(),L=C.duration*A-o.delay*A,U=Math.min(G*A,L),J=o.delay*A,{data:K,isLoading:W}=v(o.src),q=o.visibleDuration*A,Q=g(K,20).path,Z=(e,t)=>{if(!m(e)){return}e.stopPropagation();const n=e.clientX,i=J,a=U,s=o.endTime,r=o.startTime,d=o.delay,p=o.duration||1,c=o.speed;R(e,{slopX:l,node:o,onMove:e=>{const l=(e.clientX-n)/A;if("start"===t){if(l>=0){const e=l*c,t=Math.max(0,s-.1-r)*p,n=Math.min(e,t);if(n<=0){return}let i=r+n/p;const a=(o.endTime-i)*p/c,m=d+n/c,u=Y(a);let h=Math.min(Math.max(0,m),u);const f=S({position:h,store:C,scale:A});h=Math.min(Math.max(0,null!=f?f:h),u);const x=h-m;i=Math.min(o.endTime-.1,Math.max(0,i+x*c/p)),o.set({delay:h,startTime:i})}else{const e=-l*c,t=r*p,n=Math.min(e,t);if(n<=0){return}const i=n/p;let a=Math.max(0,r-i);const s=(o.endTime-a)*p/c,m=d-n/c,u=Y(s);let h=Math.min(Math.max(0,m),u);const f=S({position:h,store:C,scale:A});h=Math.min(Math.max(0,null!=f?f:h),u);const x=h-m;a=Math.max(0,Math.min(o.endTime-.1,a+x*c/p)),o.set({delay:h,startTime:a})}}else{const e=i/A+a/A;let t=e+l;const n=S({position:t,store:C,scale:A});t=null!=n?n:t;const r=(t-e)*c/o.duration,m=Math.min(1,Math.max(o.startTime+.1,s+r));o.set({endTime:m})}},onEnd:({moved:e})=>{e&&(()=>{if("start"===t){const e=S({position:o.delay,store:C,scale:A});if(null!=e&&e!==o.delay){const t=V(o.startTime,o.endTime),n=F(e,t),i=n-o.delay,a=Math.max(0,Math.min(o.endTime-.1,o.startTime+i*c/p));o.set({delay:n,startTime:a})}}})()}})};return t(T,{ref:z,style:{left:`${J}px`,top:28*E+"px",width:`${U}px`,height:"24px"},className:"polotno-audio-container",children:n(M,{style:{width:"100%",height:"100%"},onPointerDown:e=>{if(!m(e)){return}const t=e.clientX,n=J;R(e,{slopX:l,node:o,onMove:e=>{const i=(e.clientX-t)/A;let a=n/A+i;const s=a+G,r=S({position:a,store:C,scale:A}),l=S({position:s,store:C,scale:A}),m=null!==r?Math.abs(a-r):Number.POSITIVE_INFINITY,d=null!==l?Math.abs(s-l):Number.POSITIVE_INFINITY;let p;p=F(null!==r&&m<d?r:null!==l?l-G:a),o.set({delay:F(p)})}})},children:[t("div",{style:{position:"absolute",left:"4px",top:"50%",transform:"translateY(-50%)",zIndex:10,pointerEvents:"auto"},onClick:e=>{e.stopPropagation(),B()},onPointerDown:e=>e.stopPropagation(),children:t(a,$?{name:"action.muted",className:"pn:size-3.5",style:{opacity:.7,cursor:"pointer"}}:{name:"action.unmuted",className:"pn:size-3.5",style:{opacity:.7,cursor:"pointer"}})}),t("div",{style:{position:"absolute",inset:"0 0 0 0",display:"flex",alignItems:"center",justifyContent:"center",pointerEvents:"none"},children:n("div",{style:{display:"flex",alignItems:"center",width:"100%",height:"100%",gap:"8px",paddingLeft:"22px"},children:[!k&&t(O,{children:N}),Q&&t("div",{style:{flex:1,height:"14px",overflow:"hidden",opacity:$?.4:1},children:t(D,{width:q,height:"14",viewBox:`0 0 ${q} 20`,preserveAspectRatio:"none",style:{width:q+"px",height:"14px",transform:`translateX(-${o.startTime*q}px)`},children:t("path",{d:Q})})}),W&&t("div",{style:{flex:1,display:"flex",justifyContent:"center",alignItems:"center"},children:t(y,{})})]})}),k&&t(P,{value:o.name,onCommit:e=>{o.set({name:e}),H(!1)},onCancel:()=>H(!1)}),t(w,{onPointerDown:e=>Z(e,"start")}),t(I,{onPointerDown:e=>Z(e,"end")}),t(b,{onClick:e=>{e.stopPropagation()},onPointerDown:e=>e.stopPropagation(),children:n(p,{children:[t(j,{}),n(c,{side:"top",align:"start",anchor:z,style:{width:"220px"},children:[n("div",{style:{padding:"8px 12px"},children:[n("div",{style:{fontSize:"12px",marginBottom:"6px",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t("span",{children:s("pagesTimeline.volume")}),n("span",{children:[Math.round(100*o.volume),"%"]})]}),t(f,{value:[o.volume],min:0,max:1,step:.01,onValueChange:e=>(e=>{const t=Math.max(0,Math.min(1,e));t>0&&X(t),o.set({volume:t})})(r(e))})]}),n("div",{style:{padding:"8px 12px"},children:[t("div",{style:{fontSize:"12px",marginBottom:"6px"},children:s("pagesTimeline.speed")}),t(x,{value:o.speed,onChange:e=>{const t=V(o.startTime,o.endTime,e);o.set({speed:e,delay:F(o.delay,t)})}})]}),t(h,{}),n(u,{onSelect:e=>{e.preventDefault(),H(!0)},children:[t(a,{name:"action.rename"}),s("pagesTimeline.renameAudio")]}),n(u,{onSelect:e=>{e.preventDefault(),B()},children:[t(a,$?{name:"action.unmuted"}:{name:"action.muted"}),s($?"pagesTimeline.unmuteAudio":"pagesTimeline.muteAudio")]}),n(u,{onSelect:t=>{t.preventDefault(),(()=>{const t=o.toJSON(),n=o.visibleDuration,i=o.delay+n,a=C.duration-i;let s=o.delay;a>=n?s=i:a>0&&(s=Math.max(0,C.duration-n));const{id:r}=t,l=e(t,["id"]);C.addAudio(Object.assign(Object.assign({},l),{delay:s}))})()},children:[t(a,{name:"action.duplicate"}),s("pagesTimeline.duplicateAudio")]}),t(h,{}),n(u,{onSelect:e=>{e.preventDefault(),C.removeAudio(o.id)},children:[t(a,{name:"action.remove"}),s("pagesTimeline.removeAudio")]})]})]})})]})})});
@@ -3,6 +3,14 @@ export declare const Audios: (({ store, scale, width, }: {
3
3
  store: StoreType;
4
4
  scale: number;
5
5
  width: number;
6
- }) => import("react").JSX.Element | null) & {
7
- displayName: string;
6
+ }) => import("react").JSX.Element | null) & import("react").NamedExoticComponent<{
7
+ store: StoreType;
8
+ scale: number;
9
+ width: number;
10
+ }> & {
11
+ readonly type: ({ store, scale, width, }: {
12
+ store: StoreType;
13
+ scale: number;
14
+ width: number;
15
+ }) => import("react").JSX.Element | null;
8
16
  };
@@ -7,7 +7,7 @@ interface CurrentTimeProps {
7
7
  variant?: Variant;
8
8
  dragAreaRef?: React.RefObject<HTMLElement | null>;
9
9
  }
10
- export declare const CurrentTime: (({ store, scale, variant, dragAreaRef }: CurrentTimeProps) => React.JSX.Element) & {
11
- displayName: string;
10
+ export declare const CurrentTime: (({ store, scale, variant, dragAreaRef }: CurrentTimeProps) => React.JSX.Element) & React.NamedExoticComponent<CurrentTimeProps> & {
11
+ readonly type: ({ store, scale, variant, dragAreaRef }: CurrentTimeProps) => React.JSX.Element;
12
12
  };
13
13
  export {};
@@ -1 +1 @@
1
- import{jsx as e,jsxs as t}from"react/jsx-runtime";import r from"react";import{observer as i}from"mobx-react-lite";import{clamp as o}from"../lib/utils.js";import{isPrimaryDrag as n,startPointerDrag as l}from"../utils/pointer-drag.js";const s="rgb(0, 161, 255)";export const CurrentTime=i(({store:i,scale:a,variant:c="timeline",dragAreaRef:p})=>{const d=r.useRef(null),u=i.effectiveTime,m=r.useCallback(e=>{var t,r;const n=(null==p?void 0:p.current)||(null===(t=d.current)||void 0===t?void 0:t.parentElement);if(!n){return}const l=n.getBoundingClientRect(),s=n.scrollLeft||0;let c=e-l.left+s;const u=window.getComputedStyle(n);c-=parseFloat(u.paddingLeft)||0,i.setCurrentTime(o(c/a,0,i.duration)),null===(r=i.checkActivePage)||void 0===r||r.call(i)},[p,a,i]),f=r.useCallback(e=>{n(e)&&(e.stopPropagation(),m(e.clientX),l(e,{onMove:e=>m(e.clientX)}))},[m]),g=(e=>"ruler"===e?{wrapper:{top:0,width:12,height:"100%",transform:"translateX(-6px)",display:"flex",flexDirection:"column",alignItems:"center"},line:{flex:1}}:{wrapper:{top:0,width:12,height:"100%",transform:"translateX(-6px)"},line:{height:"100%",margin:"0 auto"}})(c);return t("div",{ref:d,onPointerDown:f,className:"polotno-current-time pn:touch-pan-y",style:Object.assign(Object.assign({position:"absolute",left:u*a+"px"},g.wrapper),{cursor:"col-resize"}),children:[e("svg",{width:"12",height:"8",viewBox:"0 0 12 8",style:{display:"block",filter:"drop-shadow(0 1px 2px rgba(0, 0, 0, 0.3))"},children:e("path",{d:"M0 0 H12 L6 8 Z",fill:s,stroke:s,strokeWidth:"2",strokeLinejoin:"round"})}),e("div",{style:Object.assign({width:"2px",backgroundColor:s},g.line)})]})});
1
+ import{jsx as e,jsxs as t}from"react/jsx-runtime";import r from"react";import{observer as i}from"mobx-react-lite";import{clamp as o}from"../lib/utils.js";import{isPrimaryDrag as n,usePointerDrag as l}from"../utils/pointer-drag.js";const s="rgb(0, 161, 255)";export const CurrentTime=i(({store:i,scale:a,variant:c="timeline",dragAreaRef:p})=>{const d=r.useRef(null),u=l(),m=i.effectiveTime,f=r.useCallback(e=>{var t,r;const n=(null==p?void 0:p.current)||(null===(t=d.current)||void 0===t?void 0:t.parentElement);if(!n){return}const l=n.getBoundingClientRect(),s=n.scrollLeft||0;let c=e-l.left+s;const u=window.getComputedStyle(n);c-=parseFloat(u.paddingLeft)||0,i.setCurrentTime(o(c/a,0,i.duration)),null===(r=i.checkActivePage)||void 0===r||r.call(i)},[p,a,i]),g=r.useCallback(e=>{n(e)&&(e.stopPropagation(),f(e.clientX),u(e,{onMove:e=>f(e.clientX)}))},[u,f]),h=(e=>"ruler"===e?{wrapper:{top:0,width:12,height:"100%",transform:"translateX(-6px)",display:"flex",flexDirection:"column",alignItems:"center"},line:{flex:1}}:{wrapper:{top:0,width:12,height:"100%",transform:"translateX(-6px)"},line:{height:"100%",margin:"0 auto"}})(c);return t("div",{ref:d,onPointerDown:g,className:"polotno-current-time pn:touch-pan-y",style:Object.assign(Object.assign({position:"absolute",left:m*a+"px"},h.wrapper),{cursor:"col-resize"}),children:[e("svg",{width:"12",height:"8",viewBox:"0 0 12 8",style:{display:"block",filter:"drop-shadow(0 1px 2px rgba(0, 0, 0, 0.3))"},children:e("path",{d:"M0 0 H12 L6 8 Z",fill:s,stroke:s,strokeWidth:"2",strokeLinejoin:"round"})}),e("div",{style:Object.assign({width:"2px",backgroundColor:s},h.line)})]})});