polotno 3.19.0 → 3.20.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 (203) hide show
  1. package/LICENSE.md +8 -2
  2. package/THIRD_PARTY_NOTICES.md +2871 -0
  3. package/blueprint/canvas/context-menu/context-menu.js +1 -1
  4. package/blueprint/canvas/page-controls.d.ts +3 -3
  5. package/blueprint/pages-timeline/pages-timeline.js +2 -2
  6. package/blueprint/pages-timeline/play-button.js +2 -2
  7. package/blueprint/side-panel/animations-panel.d.ts +1 -1
  8. package/blueprint/side-panel/draw-panel.js +2 -2
  9. package/blueprint/side-panel/effect-card.js +3 -3
  10. package/blueprint/side-panel/effects-panel.d.ts +1 -1
  11. package/blueprint/side-panel/effects-panel.js +1 -1
  12. package/blueprint/side-panel/elements-panel.d.ts +1 -1
  13. package/blueprint/side-panel/select-video.d.ts +19 -19
  14. package/blueprint/side-panel/videos-grid.d.ts +4 -4
  15. package/blueprint/toolbar/animations-picker.d.ts +1 -1
  16. package/blueprint/toolbar/element-container.d.ts +1 -1
  17. package/blueprint/toolbar/figure-toolbar.js +1 -1
  18. package/blueprint/toolbar/filters-picker.d.ts +1 -1
  19. package/blueprint/toolbar/filters-picker.js +1 -1
  20. package/blueprint/toolbar/group-button.js +1 -1
  21. package/blueprint/toolbar/image-remove-background-button.js +1 -1
  22. package/blueprint/toolbar/image-toolbar.js +1 -1
  23. package/blueprint/toolbar/line-toolbar.js +1 -1
  24. package/blueprint/toolbar/page-toolbar.d.ts +1 -1
  25. package/blueprint/toolbar/position-picker.js +1 -1
  26. package/blueprint/toolbar/sketch.d.ts +5 -5
  27. package/blueprint/toolbar/svg-toolbar.js +1 -1
  28. package/blueprint/toolbar/table-toolbar.js +1 -1
  29. package/blueprint/toolbar/text-ai-write.js +1 -1
  30. package/blueprint/toolbar/text-toolbar.d.ts +1 -1
  31. package/blueprint.polotno.css +164 -153
  32. package/canvas/apply-filters.d.ts +2 -6
  33. package/canvas/apply-filters.js +1 -1
  34. package/canvas/context-menu/context-menu.js +1 -1
  35. package/canvas/crop-overlay.d.ts +1 -1
  36. package/canvas/crop-overlay.js +1 -1
  37. package/canvas/downscale.d.ts +1 -24
  38. package/canvas/downscale.js +1 -1
  39. package/canvas/element.d.ts +3 -1
  40. package/canvas/element.js +1 -1
  41. package/canvas/fade-overlay.js +1 -1
  42. package/canvas/figure-element.js +1 -1
  43. package/canvas/gif-element.d.ts +32 -0
  44. package/canvas/gif-element.js +1 -1
  45. package/canvas/hotkeys.d.ts +1 -1
  46. package/canvas/hotkeys.js +1 -1
  47. package/canvas/html-element.js +1 -1
  48. package/canvas/image-element.d.ts +4 -48
  49. package/canvas/image-element.js +1 -1
  50. package/canvas/image-tool-controls.js +1 -1
  51. package/canvas/line-element.js +1 -1
  52. package/canvas/lottie-element.d.ts +11 -0
  53. package/canvas/lottie-element.js +1 -0
  54. package/canvas/lottie-player.d.ts +2 -0
  55. package/canvas/lottie-player.js +1 -0
  56. package/canvas/lottie-player.wasm.d.ts +1 -0
  57. package/canvas/lottie-player.wasm.js +1 -0
  58. package/canvas/media-placeholders.d.ts +23 -0
  59. package/canvas/media-placeholders.js +1 -0
  60. package/canvas/page-controls.d.ts +3 -3
  61. package/canvas/page.js +1 -1
  62. package/canvas/quill-font-formats.d.ts +2 -2
  63. package/canvas/rect-control.js +1 -1
  64. package/canvas/render-tag-element.js +1 -1
  65. package/canvas/rich-editor.d.ts +7 -4
  66. package/canvas/rich-editor.js +5 -5
  67. package/canvas/rules.js +2 -2
  68. package/canvas/table-cell-text.d.ts +18 -0
  69. package/canvas/table-cell-text.js +1 -0
  70. package/canvas/table-element.js +1 -1
  71. package/canvas/text-element/caret-color.d.ts +3 -1
  72. package/canvas/text-element/render-tag-source.d.ts +33 -0
  73. package/canvas/text-element/render-tag-source.js +1 -0
  74. package/canvas/text-element.d.ts +1 -1
  75. package/canvas/text-element.js +1 -1
  76. package/canvas/use-color.d.ts +5 -5
  77. package/canvas/use-filtered-source.js +1 -1
  78. package/canvas/use-mediabunny-video.js +1 -1
  79. package/canvas/use-transformer-snap.d.ts +2 -2
  80. package/canvas/video-element.d.ts +4 -2
  81. package/canvas/video-element.js +1 -1
  82. package/icons/animation-icons.d.ts +1 -0
  83. package/icons/animation-icons.js +1 -1
  84. package/icons/registry.d.ts +35 -32
  85. package/icons/registry.js +1 -1
  86. package/image-tools/geometry.d.ts +2 -2
  87. package/image-tools/target.d.ts +6 -6
  88. package/image-tools/target.js +1 -1
  89. package/lib/utils.d.ts +1 -1
  90. package/model/figure-model.d.ts +10 -10
  91. package/model/gif-model.d.ts +10 -10
  92. package/model/group-model.d.ts +393 -84
  93. package/model/group-model.js +1 -1
  94. package/model/image-model.d.ts +10 -10
  95. package/model/image-tools.d.ts +1 -1
  96. package/model/line-model.d.ts +10 -10
  97. package/model/lottie-model.d.ts +242 -0
  98. package/model/lottie-model.js +5 -0
  99. package/model/node-model.d.ts +8 -8
  100. package/model/page-model.d.ts +1186 -297
  101. package/model/page-model.js +1 -1
  102. package/model/shape-model.d.ts +11 -11
  103. package/model/shape-model.js +1 -1
  104. package/model/store.d.ts +30 -26
  105. package/model/store.js +1 -1
  106. package/model/svg-model.d.ts +9 -9
  107. package/model/table-model.d.ts +127 -20
  108. package/model/table-model.js +1 -1
  109. package/model/text-model.d.ts +9 -9
  110. package/model/video-model.d.ts +10 -10
  111. package/package.json +36 -55
  112. package/pages-timeline/pages-timeline.js +1 -1
  113. package/pages-timeline/track-styles.d.ts +12 -12
  114. package/polotno-app.d.ts +1 -1
  115. package/polotno.bundle.js +183 -179
  116. package/primitives/button.d.ts +4 -4
  117. package/primitives/dialog.d.ts +4 -4
  118. package/primitives/dropdown-menu.d.ts +18 -18
  119. package/primitives/input-group.d.ts +1 -1
  120. package/primitives/popover.d.ts +4 -4
  121. package/primitives/select.d.ts +5 -5
  122. package/primitives/tooltip.d.ts +3 -3
  123. package/side-panel/animations-panel.js +1 -1
  124. package/side-panel/background-panel.js +1 -1
  125. package/side-panel/draw-panel.js +1 -1
  126. package/side-panel/effect-card.js +1 -1
  127. package/side-panel/effects-panel.js +1 -1
  128. package/side-panel/photos-panel.js +1 -1
  129. package/side-panel/select-lottie.d.ts +11 -0
  130. package/side-panel/select-lottie.js +1 -0
  131. package/side-panel/select-video.d.ts +19 -19
  132. package/side-panel/size-panel.js +1 -1
  133. package/side-panel/unsplash-credit.d.ts +4 -1
  134. package/side-panel/unsplash-credit.js +1 -1
  135. package/side-panel/upload-panel.js +1 -1
  136. package/themes/carbon.css +1 -1
  137. package/toolbar/gif-toolbar.d.ts +3 -0
  138. package/toolbar/gif-toolbar.js +1 -1
  139. package/toolbar/group-button.js +1 -1
  140. package/toolbar/html-toolbar.d.ts +1 -0
  141. package/toolbar/html-toolbar.js +3 -3
  142. package/toolbar/image-remove-background-button.js +1 -1
  143. package/toolbar/index.d.ts +1 -1
  144. package/toolbar/index.js +1 -1
  145. package/toolbar/line-toolbar.js +1 -1
  146. package/toolbar/position-picker.js +1 -1
  147. package/toolbar/table-toolbar.js +1 -1
  148. package/toolbar/text-ai-write.js +1 -1
  149. package/toolbar/text-toolbar.js +1 -1
  150. package/toolbar/toolbar-shared.d.ts +15 -4
  151. package/toolbar/toolbar-shared.js +1 -1
  152. package/toolbar/toolbar.js +1 -1
  153. package/ui.css +2 -2
  154. package/utils/animations.d.ts +47 -44
  155. package/utils/animations.js +1 -1
  156. package/utils/base64.d.ts +1 -2
  157. package/utils/base64.js +1 -1
  158. package/utils/clipboard.d.ts +19 -18
  159. package/utils/clipboard.js +1 -1
  160. package/utils/fade-gradient.d.ts +1 -1
  161. package/utils/file.d.ts +4 -3
  162. package/utils/file.js +1 -1
  163. package/utils/font-metric.d.ts +29 -28
  164. package/utils/fonts.js +1 -1
  165. package/utils/gif-lib.d.ts +1 -1
  166. package/utils/html2canvas.js +1 -1
  167. package/utils/image-dpi.d.ts +1 -1
  168. package/utils/image-dpi.js +1 -1
  169. package/utils/insert-file.js +1 -1
  170. package/utils/l10n.d.ts +1 -0
  171. package/utils/l10n.js +1 -1
  172. package/utils/lottie.d.ts +12 -0
  173. package/utils/lottie.js +1 -0
  174. package/utils/math.d.ts +4 -4
  175. package/utils/px.d.ts +3 -0
  176. package/utils/px.js +1 -1
  177. package/utils/react-color/components/common/Checkboard.d.ts +12 -12
  178. package/utils/react-color/components/common/Swatch.d.ts +6 -6
  179. package/utils/react-color/helpers/interaction.d.ts +6 -6
  180. package/utils/reactcss/components/active.d.ts +6 -6
  181. package/utils/reactcss/components/hover.d.ts +6 -6
  182. package/utils/rich-text-html.js +1 -1
  183. package/utils/selection-colors.js +1 -1
  184. package/utils/selection-transform.d.ts +4 -4
  185. package/utils/selection-transform.js +1 -1
  186. package/utils/split-element.js +1 -1
  187. package/utils/text-format-state.d.ts +1 -0
  188. package/utils/text-format-state.js +1 -1
  189. package/utils/text-format.d.ts +2 -2
  190. package/utils/text-sizing.d.ts +1 -1
  191. package/utils/timeline.d.ts +30 -2
  192. package/utils/timeline.js +1 -1
  193. package/utils/to-html.js +1 -1
  194. package/utils/to-svg.js +1 -1
  195. package/utils/validate-key.js +1 -1
  196. package/canvas/downscale-bands.d.ts +0 -10
  197. package/canvas/downscale-bands.js +0 -1
  198. package/canvas/downscale-kernel.d.ts +0 -7
  199. package/canvas/downscale-kernel.js +0 -1
  200. package/canvas/downscale-kernel.wasm.d.ts +0 -1
  201. package/canvas/downscale-kernel.wasm.js +0 -1
  202. package/canvas/downscale-passes.d.ts +0 -7
  203. package/canvas/downscale-passes.js +0 -1
@@ -1 +1 @@
1
- import{jsx as t,Fragment as e,jsxs as o}from"react/jsx-runtime";import{elementOpacity as i}from"./paint-opacity.js";import n from"react";import{observer as r}from"mobx-react-lite";import{observable as l,runInAction as s}from"mobx";import{nodeAutorun as h}from"../utils/mobx.js";import{Group as a,Rect as c,Line as d,Circle as g}from"react-konva";import{Html as u}from"react-konva-utils";import{toDisplayColor as w}from"@polotno/core/color";import{ROLES as p}from"../model/store.js";import{isTouchDevice as f}from"../utils/screen.js";import{roundedGeometryPx as x,roundedPosition as y,transformScale as v}from"../utils/px.js";import{TextElement as m}from"./text-element.js";import{PlacedNode as b}from"./placed-node.js";const C="#0d83dd",k=(t,e)=>{const o=t.target.getStage();o&&(o.container().style.cursor=e)},S=r(({axis:i,hovered:n,pillX:r,pillY:l,pillW:s,pillH:h,hitX:a,hitY:d,hitW:g,hitH:u,tint:w,hoverKind:p,idx:f,onSelect:x,onHoverChange:y})=>o(e,{children:[n&&t(c,{x:w.x,y:w.y,width:w.width,height:w.height,fill:"rgba(13, 131, 221, 0.08)",listening:!1}),t(c,{x:r,y:l,width:s,height:h,cornerRadius:Math.min(s,h)/2,fill:n?C:"#9ca3af",opacity:n?.55:.18,listening:!1}),t(c,{x:a,y:d,width:g,height:u,fill:"transparent",onMouseEnter:t=>{y({kind:p,idx:f}),k(t,"pointer")},onMouseLeave:t=>{y(null),k(t,"")},onClick:x})]})),E=r(({x:i,y:n,hovered:r,hoverKind:l,idx:s,isTouch:h,sizes:u,onInsert:w,onHoverChange:p})=>{const{hit:f,r:x,halo:y,stroke:v}=u,m=r||h;return o(a,{x:i,y:n,onMouseEnter:t=>{p({kind:l,idx:s}),k(t,"pointer")},onMouseLeave:t=>{p(null),k(t,"")},onClick:t=>{t.cancelBubble=!0,w()},children:[t(c,{x:-f/2,y:-f/2,width:f,height:f,fill:"transparent"}),m&&o(e,{children:[t(g,{radius:x+y,fill:"white",listening:!1}),t(g,{radius:x,fill:C,listening:!1}),t(d,{points:[.55*-x,0,.55*x,0],stroke:"white",strokeWidth:v,lineCap:"round",listening:!1}),t(d,{points:[0,.55*-x,0,.55*x],stroke:"white",strokeWidth:v,lineCap:"round",listening:!1})]})]})}),I=r(({element:o,store:i,inv:n,isTouch:r,hover:l,setHover:s})=>{const h=16*n,a=2*n,c=10*n,d={hit:22*n,r:7*n,halo:2*n,stroke:2*n},g=(t,e)=>null!==l&&l.kind===t&&l.idx===e,u=(t,e)=>i=>{i.cancelBubble=!0;const n=o._anchorCellId?o.cells.find(t=>t.id===o._anchorCellId):void 0;i.evt.shiftKey&&n?"col"===t?o.selectColumnRange(n.col,e):o.selectRowRange(n.row,e):"col"===t?o.selectColumn(e):o.selectRow(e)},w=[0],p=[0];for(let t=0;t<o.cols;t++){w.push(w[t]+o.colWidths[t]*o.a.width)}for(let t=0;t<o.rows;t++){p.push(p[t]+o.rowHeights[t]*o.a.height)}const f=[];for(let e=0;e<o.cols;e++){const i=Math.max(0,w[e+1]-w[e]-6);i<=0||f.push(t(S,{axis:"col",hovered:g("colSelect",e),pillX:w[e]+3,pillY:-a-c,pillW:i,pillH:a,hitX:w[e]+1,hitY:-h-c+a,hitW:i+4,hitH:h,tint:{x:w[e],y:0,width:w[e+1]-w[e],height:o.a.height},hoverKind:"colSelect",idx:e,onSelect:u("col",e),onHoverChange:s},`col-pill-${e}`))}for(let e=0;e<=o.cols;e++){f.push(t(E,{x:w[e],y:-c-a/2,hovered:g("colInsert",e),hoverKind:"colInsert",idx:e,isTouch:r,sizes:d,onInsert:()=>i.history.transaction(()=>o.addColumn(e)),onHoverChange:s},`col-insert-${e}`))}for(let e=0;e<o.rows;e++){const i=Math.max(0,p[e+1]-p[e]-6);i<=0||f.push(t(S,{axis:"row",hovered:g("rowSelect",e),pillX:-a-c,pillY:p[e]+3,pillW:a,pillH:i,hitX:-h-c+a,hitY:p[e]+1,hitW:h,hitH:i+4,tint:{x:0,y:p[e],width:o.a.width,height:p[e+1]-p[e]},hoverKind:"rowSelect",idx:e,onSelect:u("row",e),onHoverChange:s},`row-pill-${e}`))}for(let e=0;e<=o.rows;e++){f.push(t(E,{x:-c-a/2,y:p[e],hovered:g("rowInsert",e),hoverKind:"rowInsert",idx:e,isTouch:r,sizes:d,onInsert:()=>i.history.transaction(()=>o.addRow(e)),onHoverChange:s},`row-insert-${e}`))}return t(e,{children:f})});export const TableElement=r(({element:r,store:g})=>{const C=n.useRef(null),k=n.useRef(null),S=r.selectable||g.role===p.ADMIN,E=f(),R=r.isSelected,H=r._focusedCellIds.length>0,M=r.editingCell,W=R?1/Math.max(.01,g.scale):1,[T,B]=n.useState(null);n.useEffect(()=>{R||(r.clearCellFocus(),B(null))},[R]);const $=null==M?void 0:M._editModeEnabled;n.useEffect(()=>{r._editingCellId&&M&&!M._editModeEnabled&&r.exitCellEdit()},[$]),n.useEffect(()=>{H&&!r._editingCellId&&setTimeout(()=>{var t;return null===(t=k.current)||void 0===t?void 0:t.focus()},0)},[H,r._editingCellId]);const _=n.useMemo(()=>l.box(!1),[]);n.useEffect(()=>h(r,()=>{_.get()||r._fitRowsToContent&&g.history.ignore(()=>{r._applyFitRowsToContent()})}),[r,g,_]);const j=t=>{const e=t.target.getStage();if(!e){return}const o=e.getPointerPosition();if(!o){return}const i=C.current;if(!i){return}const n=i.getAbsoluteTransform().copy().invert().point(o);for(const l of r.visibleCells){const t=r.getCellRect(l.row,l.col,l.rowSpan,l.colSpan);if(n.x>=t.x&&n.x<=t.x+t.width&&n.y>=t.y&&n.y<=t.y+t.height){return l}}},D=(t,e)=>"dashed"===t?[4*e,2*e]:"dotted"===t?[e,e]:void 0,z=[];for(const e of r.visibleCells){const o=r.getCellRect(e.row,e.col,e.rowSpan,e.colSpan),i=0===e.row,n=e.row+e.rowSpan===r.rows,l=0===e.col,s=e.col+e.colSpan===r.cols;if(0===e.row){const i=e.getEffectiveBorder("top");if("none"!==i.style&&i.width>0){const n=o.y+i.width/2,r=o.x-(l?0:i.width/2),h=o.x+o.width+(s?0:i.width/2);z.push(t(d,{points:[r,n,h,n],stroke:w(i.color),strokeWidth:i.width,dash:D(i.style,i.width),listening:!1},`bt-${e.id}`))}}if(0===e.col){const r=e.getEffectiveBorder("left");if("none"!==r.style&&r.width>0){const l=o.x+r.width/2,s=o.y-(i?0:r.width/2),h=o.y+o.height+(n?0:r.width/2);z.push(t(d,{points:[l,s,l,h],stroke:w(r.color),strokeWidth:r.width,dash:D(r.style,r.width),listening:!1},`bl-${e.id}`))}}{const i=e.getEffectiveBorder("bottom");if("none"!==i.style&&i.width>0){const r=n?o.y+o.height-i.width/2:o.y+o.height,h=o.x-(l?0:i.width/2),a=o.x+o.width+(s?0:i.width/2);z.push(t(d,{points:[h,r,a,r],stroke:w(i.color),strokeWidth:i.width,dash:D(i.style,i.width),listening:!1},`bb-${e.id}`))}}{const r=e.getEffectiveBorder("right");if("none"!==r.style&&r.width>0){const l=s?o.x+o.width-r.width/2:o.x+o.width,h=o.y-(i?0:r.width/2),a=o.y+o.height+(n?0:r.width/2);z.push(t(d,{points:[l,h,l,a],stroke:w(r.color),strokeWidth:r.width,dash:D(r.style,r.width),listening:!1},`br-${e.id}`))}}}return o(e,{children:[t(b,{as:c,element:r,id:r.id,name:"element",width:r.a.width,height:r.a.height,fill:"transparent",opacity:i(r),hideInExport:!r.showInExport,listening:S,draggable:E?r.draggable&&R:r.draggable,onClick:t=>{if(!R){return}if(r.locked||!r.contentEditable){return}const e=j(t);e&&(t.evt.shiftKey&&H?(t.cancelBubble=!0,r.focusCellRange(e.row,e.col)):r.focusCell(e.id))},onDblClick:t=>{if(!R){return}if(r.locked||!r.contentEditable){return}const e=j(t);e&&r.enterCellEdit(e.id)},onDragMove:t=>{var e;const o=t.target;r.set({x:o.x(),y:o.y()}),null===(e=C.current)||void 0===e||e.position({x:o.x(),y:o.y()})},onDragEnd:t=>{r.set(y(t.target))},onTransformStart:()=>{s(()=>_.set(!0))},onTransformEnd:()=>{r.set({x:x(r.x),y:x(r.y),width:x(r.width),rotation:x(r.rotation)}),r._resetBaseRowHeights(),s(()=>_.set(!1))},onTransform:t=>{var e,o;const i=t.target,n=v(i.scaleX()),l=v(i.scaleY());i.scaleX(1),i.scaleY(1);const s=r.width*n,h=r.height*l;i.width(s),i.height(h);const a=i.x(),c=i.y(),d=i.rotation();null===(e=C.current)||void 0===e||e.position({x:a,y:c}),null===(o=C.current)||void 0===o||o.rotation(d),r.set({width:s,x:a,y:c,rotation:d}),r.setHeightRedistribute(h)}}),o(b,{as:a,nodeRef:C,element:r,opacity:i(r),hideInExport:!r.showInExport,scaleX:r.a.width/r.width,scaleY:r.a.height/r.height,children:[r.visibleCells.map(e=>{const o=r.getCellRect(e.row,e.col,e.rowSpan,e.colSpan);return"transparent"===e.cellBackground?null:t(c,{x:o.x,y:o.y,width:o.width,height:o.height,fill:w(e.cellBackground),listening:!1},`bg-${e.id}`)}),z,r.visibleCells.map(e=>t(m,{element:e,store:g},`text-${e.id}`)),R&&r._focusedCellIds.map(e=>{const o=r.cells.find(t=>t.id===e);if(!o){return null}const i=r.getCellRect(o.row,o.col,o.rowSpan,o.colSpan),n=2*W;return t(c,{x:i.x,y:i.y,width:i.width,height:i.height,fill:"rgba(13, 131, 221, 0.1)",stroke:"#0d83dd",strokeWidth:n,listening:!1},`focus-${e}`)}),H&&!M&&t(u,{children:t("div",{ref:k,tabIndex:-1,style:{position:"absolute",opacity:0,width:"1px",height:"1px",pointerEvents:"none",outline:"none"}})}),R&&!M&&!g.isPlaying&&(()=>{const e=[];let o=0;for(let i=0;i<r.cols-1;i++){o+=r.colWidths[i]*r.a.width;const n=o,l=i;e.push(t(d,{x:n,points:[0,0,0,r.a.height],stroke:"transparent",strokeWidth:1,hitStrokeWidth:16,draggable:!0,onMouseEnter:t=>{var e;const o=null===(e=t.target.getStage())||void 0===e?void 0:e.container();o&&(o.style.cursor="col-resize"),B({kind:"colInsert",idx:l+1})},onMouseLeave:t=>{var e;const o=null===(e=t.target.getStage())||void 0===e?void 0:e.container();o&&(o.style.cursor=""),B(null)},onDragStart:t=>{t.cancelBubble=!0,g.history.startTransaction()},onDragMove:t=>{t.cancelBubble=!0;const e=t.target,o=(e.x()-n)/r.width;e.x(n),r.resizeColumn(l,o)},onDragEnd:t=>{t.cancelBubble=!0,t.target.x(n),g.history.endTransaction()}},`col-resize-${i}`))}return e})(),R&&!M&&!g.isPlaying&&(()=>{const e=[];let o=0;for(let i=0;i<r.rows-1;i++){o+=r.rowHeights[i]*r.a.height;const n=o,l=i;e.push(t(d,{y:n,points:[0,0,r.a.width,0],stroke:"transparent",strokeWidth:1,hitStrokeWidth:16,draggable:!0,onMouseEnter:t=>{var e;const o=null===(e=t.target.getStage())||void 0===e?void 0:e.container();o&&(o.style.cursor="row-resize"),B({kind:"rowInsert",idx:l+1})},onMouseLeave:t=>{var e;const o=null===(e=t.target.getStage())||void 0===e?void 0:e.container();o&&(o.style.cursor=""),B(null)},onDragStart:t=>{t.cancelBubble=!0,s(()=>_.set(!0)),g.history.startTransaction()},onDragMove:t=>{t.cancelBubble=!0;const e=t.target,o=(e.y()-n)/r.height;e.y(n),r.resizeRow(l,o)},onDragEnd:t=>{t.cancelBubble=!0,t.target.y(n),r._resetBaseRowHeights(),s(()=>_.set(!1)),g.history.endTransaction()}},`row-resize-${i}`))}return e})(),R&&!M&&!g.isPlaying&&t(I,{element:r,store:g,inv:W,isTouch:E,hover:T,setHover:B})]})]})});
1
+ import{Fragment as t,jsx as e,jsxs as o}from"react/jsx-runtime";import{elementOpacity as i}from"./paint-opacity.js";import n from"react";import{observer as r}from"mobx-react-lite";import{observable as l,runInAction as s}from"mobx";import{nodeAutorun as h}from"../utils/mobx.js";import{Group as c,Rect as a,Line as d,Circle as g}from"react-konva";import{Html as u}from"react-konva-utils";import{toDisplayColor as w}from"@polotno/core/color";import{ROLES as p}from"../model/store.js";import{isTouchDevice as f}from"../utils/screen.js";import{roundedGeometryPx as x,roundedPosition as y,transformScale as v}from"../utils/px.js";import{TableCellText as m}from"./table-cell-text.js";import{PlacedNode as b}from"./placed-node.js";const C="#0d83dd",k=(t,e)=>{const o=t.target.getStage();o&&(o.container().style.cursor=e)},S=r(({axis:i,hovered:n,pillX:r,pillY:l,pillW:s,pillH:h,hitX:c,hitY:d,hitW:g,hitH:u,tint:w,hoverKind:p,idx:f,onSelect:x,onHoverChange:y})=>o(t,{children:[n&&e(a,{x:w.x,y:w.y,width:w.width,height:w.height,fill:"rgba(13, 131, 221, 0.08)",listening:!1}),e(a,{x:r,y:l,width:s,height:h,cornerRadius:Math.min(s,h)/2,fill:n?C:"#9ca3af",opacity:n?.55:.18,listening:!1}),e(a,{x:c,y:d,width:g,height:u,fill:"transparent",onMouseEnter:t=>{y({kind:p,idx:f}),k(t,"pointer")},onMouseLeave:t=>{y(null),k(t,"")},onClick:x})]})),E=r(({x:i,y:n,hovered:r,hoverKind:l,idx:s,isTouch:h,sizes:u,onInsert:w,onHoverChange:p})=>{const{hit:f,r:x,halo:y,stroke:v}=u,m=r||h;return o(c,{x:i,y:n,onMouseEnter:t=>{p({kind:l,idx:s}),k(t,"pointer")},onMouseLeave:t=>{p(null),k(t,"")},onClick:t=>{t.cancelBubble=!0,w()},children:[e(a,{x:-f/2,y:-f/2,width:f,height:f,fill:"transparent"}),m&&o(t,{children:[e(g,{radius:x+y,fill:"white",listening:!1}),e(g,{radius:x,fill:C,listening:!1}),e(d,{points:[.55*-x,0,.55*x,0],stroke:"white",strokeWidth:v,lineCap:"round",listening:!1}),e(d,{points:[0,.55*-x,0,.55*x],stroke:"white",strokeWidth:v,lineCap:"round",listening:!1})]})]})}),I=r(({element:o,store:i,inv:n,isTouch:r,hover:l,setHover:s})=>{const h=16*n,c=2*n,a=10*n,d={hit:22*n,r:7*n,halo:2*n,stroke:2*n},g=(t,e)=>null!==l&&l.kind===t&&l.idx===e,u=(t,e)=>i=>{i.cancelBubble=!0;const n=o._anchorCellId?o.cells.find(t=>t.id===o._anchorCellId):void 0;i.evt.shiftKey&&n?"col"===t?o.selectColumnRange(n.col,e):o.selectRowRange(n.row,e):"col"===t?o.selectColumn(e):o.selectRow(e)},w=[0],p=[0];for(let t=0;t<o.cols;t++){w.push(w[t]+o.colWidths[t]*o.a.width)}for(let t=0;t<o.rows;t++){p.push(p[t]+o.rowHeights[t]*o.a.height)}const f=[];for(let t=0;t<o.cols;t++){const i=Math.max(0,w[t+1]-w[t]-6);i<=0||f.push(e(S,{axis:"col",hovered:g("colSelect",t),pillX:w[t]+3,pillY:-c-a,pillW:i,pillH:c,hitX:w[t]+1,hitY:-h-a+c,hitW:i+4,hitH:h,tint:{x:w[t],y:0,width:w[t+1]-w[t],height:o.a.height},hoverKind:"colSelect",idx:t,onSelect:u("col",t),onHoverChange:s},`col-pill-${t}`))}for(let t=0;t<=o.cols;t++){f.push(e(E,{x:w[t],y:-a-c/2,hovered:g("colInsert",t),hoverKind:"colInsert",idx:t,isTouch:r,sizes:d,onInsert:()=>i.history.transaction(()=>o.addColumn(t)),onHoverChange:s},`col-insert-${t}`))}for(let t=0;t<o.rows;t++){const i=Math.max(0,p[t+1]-p[t]-6);i<=0||f.push(e(S,{axis:"row",hovered:g("rowSelect",t),pillX:-c-a,pillY:p[t]+3,pillW:c,pillH:i,hitX:-h-a+c,hitY:p[t]+1,hitW:h,hitH:i+4,tint:{x:0,y:p[t],width:o.a.width,height:p[t+1]-p[t]},hoverKind:"rowSelect",idx:t,onSelect:u("row",t),onHoverChange:s},`row-pill-${t}`))}for(let t=0;t<=o.rows;t++){f.push(e(E,{x:-a-c/2,y:p[t],hovered:g("rowInsert",t),hoverKind:"rowInsert",idx:t,isTouch:r,sizes:d,onInsert:()=>i.history.transaction(()=>o.addRow(t)),onHoverChange:s},`row-insert-${t}`))}return e(t,{children:f})});export const TableElement=r(({element:r,store:g})=>{const C=n.useRef(null),k=n.useRef(null),S=r.selectable||g.role===p.ADMIN,E=f(),R=r.isSelected,H=r._focusedCellIds.length>0,M=r.editingCell,W=R?1/Math.max(.01,g.scale):1,[B,T]=n.useState(null);n.useEffect(()=>{R||(r.clearCellFocus(),T(null))},[R]);const $=null==M?void 0:M._editModeEnabled;n.useEffect(()=>{r._editingCellId&&M&&!M._editModeEnabled&&r.exitCellEdit()},[$]),n.useEffect(()=>{H&&!r._editingCellId&&setTimeout(()=>{var t;return null===(t=k.current)||void 0===t?void 0:t.focus()},0)},[H,r._editingCellId]);const _=n.useMemo(()=>l.box(!1),[]);n.useEffect(()=>h(r,()=>{_.get()||r._fitRowsToContent&&g.history.ignore(()=>{r._applyFitRowsToContent()})}),[r,g,_]);const j=t=>{const e=t.target.getStage();if(!e){return}const o=e.getPointerPosition();if(!o){return}const i=C.current;if(!i){return}const n=i.getAbsoluteTransform().copy().invert().point(o);for(const l of r.visibleCells){const t=r.getCellRect(l.row,l.col,l.rowSpan,l.colSpan);if(n.x>=t.x&&n.x<=t.x+t.width&&n.y>=t.y&&n.y<=t.y+t.height){return l}}},D=(t,e)=>"dashed"===t?[4*e,2*e]:"dotted"===t?[e,e]:void 0,X=[];for(const t of r.visibleCells){const o=r.getCellRect(t.row,t.col,t.rowSpan,t.colSpan),i=0===t.row,n=t.row+t.rowSpan===r.rows,l=0===t.col,s=t.col+t.colSpan===r.cols;if(0===t.row){const i=t.getEffectiveBorder("top");if("none"!==i.style&&i.width>0){const n=o.y+i.width/2,r=o.x-(l?0:i.width/2),h=o.x+o.width+(s?0:i.width/2);X.push(e(d,{points:[r,n,h,n],stroke:w(i.color),strokeWidth:i.width,dash:D(i.style,i.width),listening:!1},`bt-${t.id}`))}}if(0===t.col){const r=t.getEffectiveBorder("left");if("none"!==r.style&&r.width>0){const l=o.x+r.width/2,s=o.y-(i?0:r.width/2),h=o.y+o.height+(n?0:r.width/2);X.push(e(d,{points:[l,s,l,h],stroke:w(r.color),strokeWidth:r.width,dash:D(r.style,r.width),listening:!1},`bl-${t.id}`))}}{const i=t.getEffectiveBorder("bottom");if("none"!==i.style&&i.width>0){const r=n?o.y+o.height-i.width/2:o.y+o.height,h=o.x-(l?0:i.width/2),c=o.x+o.width+(s?0:i.width/2);X.push(e(d,{points:[h,r,c,r],stroke:w(i.color),strokeWidth:i.width,dash:D(i.style,i.width),listening:!1},`bb-${t.id}`))}}{const r=t.getEffectiveBorder("right");if("none"!==r.style&&r.width>0){const l=s?o.x+o.width-r.width/2:o.x+o.width,h=o.y-(i?0:r.width/2),c=o.y+o.height+(n?0:r.width/2);X.push(e(d,{points:[l,h,l,c],stroke:w(r.color),strokeWidth:r.width,dash:D(r.style,r.width),listening:!1},`br-${t.id}`))}}}return o(t,{children:[e(b,{as:a,element:r,id:r.id,name:"element",width:r.a.width,height:r.a.height,fill:"transparent",opacity:i(r),hideInExport:!r.showInExport,listening:S,draggable:E?r.draggable&&R:r.draggable,onClick:t=>{if(!R){return}if(r.locked||!r.contentEditable){return}const e=j(t);e&&(t.evt.shiftKey&&H?(t.cancelBubble=!0,r.focusCellRange(e.row,e.col)):r.focusCell(e.id))},onDblClick:t=>{if(!R){return}if(r.locked||!r.contentEditable){return}const e=j(t);e&&r.enterCellEdit(e.id,{x:t.evt.clientX,y:t.evt.clientY})},onDragMove:t=>{var e;const o=t.target;r.set({x:o.x(),y:o.y()}),null===(e=C.current)||void 0===e||e.position({x:o.x(),y:o.y()})},onDragEnd:t=>{r.set(y(t.target))},onTransformStart:()=>{s(()=>_.set(!0))},onTransformEnd:()=>{r.set({x:x(r.x),y:x(r.y),width:x(r.width),rotation:x(r.rotation)}),r._resetBaseRowHeights(),s(()=>_.set(!1))},onTransform:t=>{var e,o;const i=t.target,n=v(i.scaleX()),l=v(i.scaleY());i.scaleX(1),i.scaleY(1);const s=r.width*n,h=r.height*l;i.width(s),i.height(h);const c=i.x(),a=i.y(),d=i.rotation();null===(e=C.current)||void 0===e||e.position({x:c,y:a}),null===(o=C.current)||void 0===o||o.rotation(d),r.set({width:s,x:c,y:a,rotation:d}),r.setHeightRedistribute(h)}}),o(b,{as:c,nodeRef:C,element:r,opacity:i(r),hideInExport:!r.showInExport,scaleX:r.a.width/r.width,scaleY:r.a.height/r.height,children:[r.visibleCells.map(t=>{const o=r.getCellRect(t.row,t.col,t.rowSpan,t.colSpan);return"transparent"===t.cellBackground?null:e(a,{x:o.x,y:o.y,width:o.width,height:o.height,fill:w(t.cellBackground),listening:!1},`bg-${t.id}`)}),X,r.visibleCells.map(t=>e(m,{cell:t,table:r,store:g},`text-${t.id}`)),R&&r._focusedCellIds.map(t=>{const o=r.cells.find(e=>e.id===t);if(!o){return null}const i=r.getCellRect(o.row,o.col,o.rowSpan,o.colSpan),n=2*W;return e(a,{x:i.x,y:i.y,width:i.width,height:i.height,fill:"rgba(13, 131, 221, 0.1)",stroke:"#0d83dd",strokeWidth:n,listening:!1},`focus-${t}`)}),H&&!M&&e(u,{children:e("div",{ref:k,tabIndex:-1,style:{position:"absolute",opacity:0,width:"1px",height:"1px",pointerEvents:"none",outline:"none"}})}),R&&!M&&!g.isPlaying&&(()=>{const t=[];let o=0;for(let i=0;i<r.cols-1;i++){o+=r.colWidths[i]*r.a.width;const n=o,l=i;t.push(e(d,{x:n,points:[0,0,0,r.a.height],stroke:"transparent",strokeWidth:1,hitStrokeWidth:16,draggable:!0,onMouseEnter:t=>{var e;const o=null===(e=t.target.getStage())||void 0===e?void 0:e.container();o&&(o.style.cursor="col-resize"),T({kind:"colInsert",idx:l+1})},onMouseLeave:t=>{var e;const o=null===(e=t.target.getStage())||void 0===e?void 0:e.container();o&&(o.style.cursor=""),T(null)},onDragStart:t=>{t.cancelBubble=!0,g.history.startTransaction()},onDragMove:t=>{t.cancelBubble=!0;const e=t.target,o=(e.x()-n)/r.width;e.x(n),r.resizeColumn(l,o)},onDragEnd:t=>{t.cancelBubble=!0,t.target.x(n),g.history.endTransaction()}},`col-resize-${i}`))}return t})(),R&&!M&&!g.isPlaying&&(()=>{const t=[];let o=0;for(let i=0;i<r.rows-1;i++){o+=r.rowHeights[i]*r.a.height;const n=o,l=i;t.push(e(d,{y:n,points:[0,0,r.a.width,0],stroke:"transparent",strokeWidth:1,hitStrokeWidth:16,draggable:!0,onMouseEnter:t=>{var e;const o=null===(e=t.target.getStage())||void 0===e?void 0:e.container();o&&(o.style.cursor="row-resize"),T({kind:"rowInsert",idx:l+1})},onMouseLeave:t=>{var e;const o=null===(e=t.target.getStage())||void 0===e?void 0:e.container();o&&(o.style.cursor=""),T(null)},onDragStart:t=>{t.cancelBubble=!0,s(()=>_.set(!0)),g.history.startTransaction()},onDragMove:t=>{t.cancelBubble=!0;const e=t.target,o=(e.y()-n)/r.height;e.y(n),r.resizeRow(l,o)},onDragEnd:t=>{t.cancelBubble=!0,t.target.y(n),r._resetBaseRowHeights(),s(()=>_.set(!1)),g.history.endTransaction()}},`row-resize-${i}`))}return t})(),R&&!M&&!g.isPlaying&&e(I,{element:r,store:g,inv:W,isTouch:E,hover:B,setHover:T})]})]})});
@@ -1,2 +1,4 @@
1
1
  import { TextElementType } from '../../model/text-model.js';
2
- export declare function getOptimalCaretColor(element: TextElementType): string;
2
+ type CaretPaint = Pick<TextElementType, 'fill' | 'stroke' | 'strokeWidth' | 'shadowEnabled' | 'shadowBlur' | 'shadowOpacity' | 'shadowColor'>;
3
+ export declare function getOptimalCaretColor(element: CaretPaint): string;
4
+ export {};
@@ -0,0 +1,33 @@
1
+ import type { GetHtmlOptions } from '@polotno/core/text-html';
2
+ import { type TextSizing, type TextSizingElement } from '@polotno/core/text-sizing';
3
+ import type { StoreType } from '../../model/store.js';
4
+ export interface RenderTagSourceElement {
5
+ text: string;
6
+ placeholder: string;
7
+ fontSize: number;
8
+ fontFamily: string;
9
+ fontWeight: string;
10
+ fontStyle: string;
11
+ fill: string;
12
+ width: number;
13
+ height: number;
14
+ a: {
15
+ width: number;
16
+ height: number;
17
+ };
18
+ }
19
+ export declare function useRenderTagSource(element: RenderTagSourceElement, store: StoreType): {
20
+ fontLoaded: boolean;
21
+ fontFamily: any;
22
+ color: string | undefined;
23
+ isPlaceholder: boolean;
24
+ normalizedSourceText: string;
25
+ getHtmlOptions: {
26
+ fontFamily: any;
27
+ color: string | undefined;
28
+ forEditor: true;
29
+ text: string;
30
+ textIsNormalized: true;
31
+ };
32
+ };
33
+ export declare function liveFitScale(element: TextSizingElement, sizing: TextSizing, getHtmlOptions: GetHtmlOptions, text: string, fallback: number): number;
@@ -0,0 +1 @@
1
+ import t from"react";import{removeTags as o}from"@polotno/core/text";import{layoutTextSizing as e,renderTagLayoutAt as i}from"@polotno/core/text-sizing";import{xmlEscape as r}from"@polotno/core/xml";import{extractFontSpecsFromHtml as l,normalizeRichTextHtml as n}from"../../utils/rich-text-html.js";import{usePrevious as m}from"../text-element.js";import{useColor as f,withDisplayTextPaints as a}from"../use-color.js";import{useFontSpecsLoader as s}from"./font-specs-loader.js";import{visiblePlaceholder as c}from"./placeholder.js";export function useRenderTagSource(e,i){const a=m(e.fontFamily),p=t.useMemo(()=>n(e.text,{fontSize:e.fontSize,fontFamily:e.fontFamily}),[e.text,e.fontSize,e.fontFamily]),x=t.useMemo(()=>l(p,{fontFamily:e.fontFamily,fontWeight:e.fontWeight,fontStyle:e.fontStyle}),[p,e.fontFamily,e.fontWeight,e.fontStyle]),[y]=s(i,x,e.text||e.placeholder),u=y?e.fontFamily:a&&a!==e.fontFamily?a:"Arial",d=f(e).fill,g=c(e.placeholder),F=!!g&&!o(e.text),h=F?r(g):p;return{fontLoaded:y,fontFamily:u,color:d,isPlaceholder:F,normalizedSourceText:h,getHtmlOptions:{fontFamily:u,color:d,forEditor:!0,text:h,textIsNormalized:!0}}}export function liveFitScale(t,o,r,l,n){try{return e({element:Object.assign(Object.assign({},t),{text:l}),sizing:o,layoutAt:i(a(t),{getHtmlOptions:Object.assign(Object.assign({},r),{text:l,textIsNormalized:!1})})}).scale}catch(m){return n}}
@@ -9,8 +9,8 @@ export { getDir } from '@polotno/core/text-html';
9
9
  export declare const useFontLoader: (store: StoreType, fontFamily: string, fontStyle?: string, fontWeight?: string, sampleText?: string) => boolean[];
10
10
  export declare const useFontFamiliesLoader: (store: StoreType, families: string[], fontStyle?: string, fontWeight?: string, sampleText?: string) => boolean[];
11
11
  export declare const getLineHeight: ({ fontLoaded, fontFamily, fontSize, lineHeight, }: {
12
- fontLoaded: any;
13
12
  fontFamily: any;
13
+ fontLoaded: any;
14
14
  fontSize: any;
15
15
  lineHeight: any;
16
16
  }) => number;
@@ -1 +1 @@
1
- import{jsx as t,Fragment as e,jsxs as r}from"react/jsx-runtime";import{elementOpacity as o}from"./paint-opacity.js";import n from"react";import{toDisplayColor as i}from"@polotno/core/color";import{observer as a}from"mobx-react-lite";import{Group as l,Path as s,Text as c,TextPath as d}from"react-konva";import{Html as u}from"react-konva-utils";import{nodeAutorun as f}from"../utils/mobx.js";import h from"konva";import{parsePath as g,roundCommands as p}from"svg-round-corners/lib/index.js";import{generateBackgroundShapeFromRects as m,textLinesToRects as x}from"@polotno/core/background-shape";import{useColor as b}from"./use-color.js";import{ROLES as v}from"../model/store.js";import{incrementLoader as S}from"../utils/loader.js";import{activeAnchorOf as w,scaledFontSizeAttrs as y,roundedFontSizeAttrs as E,roundedTextDecorationAttrs as z,roundedGeometryPx as k,roundedPosition as R,textMinResizeWidth as F,transformScale as j}from"../utils/px.js";import{isFontLoaded as A}from"../utils/fonts.js";import{flags as M}from"../utils/flags.js";import{textOverflowOf as L}from"../utils/text-sizing.js";import{FIT_FONT_SIZE_STEP as O,FIT_HEIGHT_EPSILON as C,legacyTextOverflow as T}from"@polotno/core/text-sizing";import{removeTags as H}from"@polotno/core/text";import{getDir as P,getCurvePath as W,resolveLineHeight as X,normalizeStrokeLineJoin as D}from"@polotno/core/text-html";import{cssFontFamily as Y}from"@polotno/core/fonts";import{shadowCastByBackground as $}from"@polotno/core/filters";import{applyOpacityToColor as J}from"@polotno/core/svg";import{applyFilter as N}from"./apply-filters.js";import{useFadeIn as B}from"./use-fadein.js";import{isTouchDevice as I}from"../utils/screen.js";import{isAlive as _,getParent as V}from"mobx-state-tree";import{getLimitedFontSize as q}from"./text-element/max-font-size.js";import{getOptimalCaretColor as U}from"./text-element/caret-color.js";import{visiblePlaceholder as Z}from"./text-element/placeholder.js";import{hasMeasuredHeight as G,resolveTextBoxHeight as K}from"@polotno/core/text-types";let Q;function tt(){return Q||(Q=document.getElementById("polotno-text-style"),Q||(Q=document.createElement("style"),Q.id="polotno-text-style",document.head.appendChild(Q)),Q)}h._fixTextRendering=!0;const et={border:"none",padding:"0px",overflow:"hidden",background:"none",outline:"none",resize:"none",overflowWrap:"break-word",whiteSpace:"pre-wrap",userSelect:"text",wordBreak:"normal",textTransform:"none"};export{getDir}from"@polotno/core/text-html";const rt=a(({textNodeRef:e,element:r,onBlur:o,selectAll:i,cursorPosition:a})=>{const[l,s]=n.useState(et),c=e.current;n.useLayoutEffect(()=>{if(!c){return}const t={};t.width=c.width()-2*c.padding()+"px",t.height=c.height()-2*c.padding()+c.fontSize()*c.lineHeight()+"px",t.fontSize=c.fontSize()+"px",t.lineHeight=c.lineHeight()+.01,t.fontFamily=c.fontFamily(),t.textAlign=c.align(),t.color=c.fill(),t.fontWeight=r.fontWeight,t.fontStyle=r.fontStyle,t.letterSpacing=r.letterSpacing+"em",t.opacity=Math.max(r.a.opacity,.2),t.textTransform=r.textTransform,t.caretColor=U(r);const e=`\n .polotno-input::placeholder {\n color: ${l.color};\n opacity: 0.6;\n }\n `,o=tt();o.innerHTML="",o.appendChild(document.createTextNode(e)),JSON.stringify(t)!==JSON.stringify(l)&&s(t)});const d=n.useRef(null);if(n.useLayoutEffect(()=>{var t;const e=d.current;if(!e){return}null===(t=d.current)||void 0===t||t.focus({preventScroll:!0});const r=a||e.value.length;e.selectionStart=e.selectionEnd=r,i&&e.setSelectionRange(0,e.value.length)},[]),n.useEffect(()=>{window.addEventListener("blur",o);const t=t=>{var e;(null===(e=d.current)||void 0===e?void 0:e.contains(t.target))||o()};return window.addEventListener("touchstart",t),()=>{window.removeEventListener("blur",o),window.removeEventListener("touchstart",t)}},[]),!c){return null}let u=0;const f=c.textArr.length*c.lineHeight()*c.fontSize(),h=K(r.a,f);"middle"===r.verticalAlign&&(u=(h-f)/2),"bottom"===r.verticalAlign&&(u=h-f);const g=H(r.text);return t("textarea",{className:"polotno-input",ref:d,dir:P(g),style:Object.assign(Object.assign(Object.assign({},et),l),{paddingTop:u+"px"}),value:g,onChange:t=>{const e=q({oldText:r.text,newText:t.target.value,element:r});r.set(Object.assign({text:t.target.value},y(r,e)))},placeholder:Z(r.placeholder),onBlur:o})}),ot=e=>t(u,{children:t(rt,Object.assign({},e))});export const useFontLoader=(t,e,r,o,n)=>useFontFamiliesLoader(t,[e],r,o,n);export const useFontFamiliesLoader=(t,e,r,o,i)=>{const[a,l]=n.useReducer(t=>t+1,0),s=e.join("\0"),c=n.useRef(e.every(t=>A(t,r,o))),d=n.useRef(null);return n.useLayoutEffect(()=>{const n=c.current;if(c.current=e.every(t=>A(t,r,o)),c.current){return void(n||l())}let a=!0;return(async()=>{n&&l();const u=S(`fonts ${s}`);await Promise.all(e.map(e=>t.loadFont(e,r,o,i))),a?(d.current=u,c.current=!0,l()):u()})(),()=>{d.current&&(d.current(),d.current=null),a=!1}},[s,r,o]),n.useEffect(()=>{var t;c.current&&(null===(t=d.current)||void 0===t||t.call(d),d.current=null)},[c.current]),[c.current]};export const getLineHeight=({fontLoaded:t,fontFamily:e,fontSize:r,lineHeight:o})=>n.useMemo(()=>X({fontFamily:e,fontSize:r,lineHeight:o}),[t,e,r,o]);export function usePrevious(t){const e=n.useRef(t),r=n.useRef(t);return n.useMemo(()=>{r.current=e.current,e.current=t},[t]),r.current}function nt(t,e,r=!1){const o=t.fontSize(),n=t.height(),i=H(e.text);let a=e.a.fontSize;t.height(void 0);const l=Math.round(2*e.a.fontSize)-1;for(let s=1;s<l;s++){const o=G(e.a)&&t.height()>e.a.height+C;let n=i.split("\n").join(" ").split(/[\s-]+/).reduce((t,e)=>(e=e.toLowerCase(),/[\u3000-\u303F\u3040-\u309F\u30A0-\u30FF\uFF00-\uFFEF\u4E00-\u9FAF\uAC00-\uD7AF]/.test(e)?t.concat(e.split("")):t.concat(e)),[]),l=t.textArr.map(t=>t.text.toLowerCase()).join(";");const s=n.find(t=>!l.includes(t)||(l=l.replace(t,""),!1));if(!(o||s&&!r)){break}a-=O,t.fontSize(a)}return t.fontSize(o),t.height(n),a}export{getCurvePath}from"@polotno/core/text-html";export const TextElement=a(({element:a,store:u})=>{const h=n.useRef(null),A=n.useRef(null),O=n.useRef(null),C=n.useRef([]),X=n.useRef(!0),[,q]=n.useReducer(t=>t+1,0),{editorEnabled:U,selectAll:Q}=(t=>{const[e,r]=n.useState(!1),o=n.useRef(!1);return n.useEffect(()=>{var e=!0;return setTimeout(()=>{e&&(t._editModeEnabled&&(o.current=!0),r(!0),setTimeout(()=>{o.current=!1},50))},50),()=>{e=!1}},[]),{editorEnabled:e&&t._editModeEnabled,selectAll:o.current}})(a),[tt,et]=n.useState(!1),[rt,it]=n.useState(!1),at=n.useRef(a.a.height),lt=n.useRef(0),st=n.useRef(""),ct=n.useRef(0),dt=a.isSelected,ut=usePrevious(dt),{textVerticalResizeEnabled:ft}=M,ht=M.autoDeleteEmptyText,gt=usePrevious(a.fontFamily),[pt,mt]=n.useState([]),xt=a.backgroundEnabled||a.borderSize>0;n.useLayoutEffect(()=>{var t,e;if(!xt){return}const r=null!==(e=null===(t=h.current)||void 0===t?void 0:t.textArr)&&void 0!==e?e:[];JSON.stringify(r)!==JSON.stringify(pt)&&mt(r)}),n.useEffect(()=>{if(a.a.width||"tablecell"===a.type){return}const t=h.current;t.width(600),a.set({width:1.4*t.getTextWidth()})},[]),n.useEffect(()=>{ut&&!dt&&ht&&""===a.text&&a.removable&&!Z(a.placeholder)&&u.deleteElements([a.id])},[ht,a.placeholder,a.removable,a.text,dt,ut]);const bt=()=>{if(a.curveEnabled){const t=h.current;null==t||t.clearCache(),null==t||t.setAttrs({filters:[]});const e=A.current;e&&N(e,a)}else{const t=h.current;t&&N(t,a)}};n.useLayoutEffect(()=>{if(!rt){return f(a,()=>{bt()})}}),n.useEffect(()=>{const t=C.current;t.length>0&&(C.current=[],t.forEach(t=>t()))}),n.useEffect(()=>()=>{X.current=!1;const t=C.current;t.length>0&&(C.current=[],t.forEach(t=>t()))},[]);let vt=H(a.text);"uppercase"===a.textTransform&&(vt=vt.toUpperCase());const[St]=useFontLoader(u,a.fontFamily,a.fontStyle,a.fontWeight,a.text||a.placeholder),wt=()=>{if(a.curveEnabled){const t=A.current;return t.getSelfRect().height||t.fontSize()}const t=h.current.clone({height:void 0}),e=Math.ceil(t.fontSize()*t.lineHeight()*t.textArr.length+1);return t.destroy(),e};n.useLayoutEffect(()=>{if(!St){return}if("tablecell"===a.type){const t=T(L(a));if("resize"===t){const t=wt(),e=_(a)?V(a,2):null;(null==e?void 0:e.setCellContentHeight)&&e.setCellContentHeight(a.id,t)}else if("change-font-size"===t){const t=h.current;if(t){const e=nt(t,a,M.textSplitAllowed);e!==a.fontSize&&u.history.ignore(()=>{a.set({fontSize:e})})}}return}const t=T(L(a)),{textSplitAllowed:e}=M,r=(t,e,r,o)=>{const n=S(`text ${a.id}`),i=()=>{u.history.ignore(t,e,r).then(()=>{X.current?(C.current.push(n),q()):n()})};o?queueMicrotask(i):i()};if(!G(a)){const t=wt();return void r(()=>{G(a)||a.set({height:t})},void 0,void 0,!0)}if(!u.isPlaying){if("change-font-size"!==t||tt){if("resize"===t){const t=wt();ft&&a.height<t&&!tt&&r(()=>{var e;_(a)&&a.set({height:t}),null===(e=h.current)||void 0===e||e.height(t)},!1,!0),ft||a.height===t||tt||r(()=>{var e;_(a)&&a.set({height:t}),null===(e=h.current)||void 0===e||e.height(t)},!1,!0)}}else{const t=h.current,o=a.curveEnabled?a.fontSize:nt(t,a,e);if(o!==a.fontSize){return void r(()=>{a.set(y(a,o))},!1,!0)}const n=wt();a.height===n||ft||r(()=>{a.set({height:n})},!1,!0)}}}),n.useLayoutEffect(()=>{var t;if(St&&a.curveEnabled){const e=null===(t=A.current)||void 0===t?void 0:t.getSelfRect().width;if(e){const t=e-a.a.width,r=a.a.rotation*Math.PI/180,o=-t/2*Math.cos(r),n=-t/2*Math.sin(r);a.set({width:e,x:a.a.x+o,y:a.a.y+n})}}},[St,a.curveEnabled,a.curvePower,a.text,a.fontSize,a.fontFamily,a.fontWeight,a.fontStyle,a.letterSpacing]),n.useLayoutEffect(()=>{const t=h.current;t&&(t.width(t.width()+1e-8),t.width(t.width()-1e-8),t._setTextData(),bt())},[St]);const yt=n.useRef(null),Et=n.useRef(a.width),zt=n.useRef(0),kt=t=>{t.evt.preventDefault();const e=u.selectedShapes.find(t=>t===a);e&&a.contentEditable&&(zt.current=function(t){var e;const r=t.target,o=function(t){var e=t.getAbsoluteTransform().copy();e.invert();var r=t.getStage().getPointerPosition();return e.point(r)}(r),n=r.textArr,i=Math.floor(o.y/(r.fontSize()*r.lineHeight())),a=n.slice(0,i).reduce((t,e)=>t+e.text.length,i),l=null!==(e=n[i])&&void 0!==e?e:n[0];let s=0;return"right"===r.align()?s=r.width()-l.width:"center"===r.align()&&(s=r.width()/2-l.width/2),a+Math.round((o.x-s)/l.width*l.text.length)}(t),a.toggleEditMode())},Rt=Z(a.placeholder),Ft=!vt&&Rt?.6:o(a);B(h,Ft);const jt=getLineHeight({fontLoaded:St,fontFamily:a.fontFamily,fontSize:a.a.fontSize,lineHeight:a.lineHeight}),At=a.selectable||u.role===v.ADMIN,Mt=b(a),Lt=b(a,a.stroke,"stroke"),Ot=n.useMemo(()=>a.backgroundEnabled||a.borderSize?a.curveEnabled?function({width:t,height:e,padding:r=0,cornerRadius:o=0}){const n=-r,i=-r,a=t+r,l=e+r,s=g(`M ${n} ${i} L ${a} ${i} L ${a} ${l} L ${n} ${l} Z`);return p(s,o).path}({width:a.a.width,height:a.a.height,cornerRadius:a.backgroundCornerRadius*(a.a.fontSize*jt*.5),padding:a.backgroundPadding*(a.a.fontSize*jt*.5)}):function({lines:t,lineHeight:e,width:r,align:o="left",padding:n=0,cornerRadius:i=0}){const a=x({lines:t,lineHeight:e,width:r,align:o});return m({rects:a,padding:n,cornerRadius:i})}({lines:JSON.parse(JSON.stringify(pt)),cornerRadius:a.backgroundCornerRadius*(a.a.fontSize*jt*.5),lineHeight:jt*a.a.fontSize,padding:a.backgroundPadding*(a.a.fontSize*jt*.5),width:a.a.width,align:a.align}):"",[a.backgroundEnabled,a.borderSize,a.curveEnabled,a.backgroundCornerRadius,a.a.fontSize,a.a.height,jt,a.backgroundPadding,a.a.width,a.align,pt]),Ct=I();let Tt=0;if(!a.curveEnabled){const t=pt.length*jt*a.a.fontSize,e=K(a.a,t);"middle"===a.verticalAlign?Tt=(e-t)/2:"bottom"===a.verticalAlign&&(Tt=e-t)}const Ht=a.curveEnabled?W(a.a.width,a.a.height,a.curvePower,a.a.fontSize):"",Pt=St?Y(a.fontFamily):gt===a.fontFamily?"Arial":Y(gt),Wt=P(vt),Xt=a.shadowEnabled&&!$(a),Dt={shadowEnabled:a.shadowEnabled&&($(a)||a.borderSize>0),shadowBlur:a.shadowBlur,shadowOffsetX:a.shadowOffsetX,shadowOffsetY:a.shadowOffsetY,shadowColor:i(a.shadowColor),shadowOpacity:a.shadowOpacity};return r(e,{children:[xt&&t(s,Object.assign({ref:O,x:a.a.x,y:a.a.y,rotation:a.a.rotation,hideInExport:!a.showInExport,listening:!1,opacity:Ft,data:Ot,fillEnabled:a.backgroundEnabled,fill:J(a.backgroundColor,a.backgroundOpacity),strokeEnabled:a.borderSize>0,stroke:i(a.borderColor),strokeWidth:a.borderSize,lineJoin:a.backgroundCornerRadius>0?"round":"miter",offsetY:-Tt},Dt)),a.curveEnabled&&t(d,Object.assign({ref:A,data:Ht,text:vt||Rt,listening:!1,align:"center",textBaseline:"middle",direction:Wt},Mt,Lt,{strokeWidth:a.strokeWidth,lineJoin:D(a.strokeLineJoin),fillAfterStrokeEnabled:!0,fontSize:a.a.fontSize,fontFamily:`${Y(a.fontFamily)}, ${Y(gt)}`,fontStyle:a.fontStyle+" "+a.fontWeight,textDecoration:a.textDecoration.trim(),letterSpacing:a.letterSpacing*a.a.fontSize,x:a.a.x,y:a.a.y,rotation:a.a.rotation,opacity:a._editModeEnabled?.3:Ft,hideInExport:!a.showInExport},Dt,{shadowEnabled:Xt})),t(c,Object.assign({ref:h,id:a.selectable?a.id:void 0,name:a.selectable?"element":"",hideInExport:!a.showInExport,editModeEnabled:a._editModeEnabled,x:a.a.x,y:a.a.y,rotation:a.a.rotation,width:a.a.width,height:G(a.a)?a.a.height:void 0,text:vt||Rt,direction:Wt},Mt,Lt,{lineJoin:D(a.strokeLineJoin),strokeWidth:a.strokeWidth,fillAfterStrokeEnabled:!0,fontSize:a.a.fontSize,fontFamily:Pt,fontStyle:a.fontStyle+" "+a.fontWeight,textDecoration:a.textDecoration,align:a.align,verticalAlign:a.verticalAlign,draggable:Ct?a.draggable&&dt:a.draggable,preventDefault:!Ct||dt,opacity:a.curveEnabled?0:Ft,visible:!a._editModeEnabled,ellipsis:"ellipsis"===L(a)},Dt,{shadowEnabled:Xt,lineHeight:jt,letterSpacing:a.letterSpacing*a.a.fontSize,listening:!!a.selectable&&At,onDragStart:()=>{it(!0)},onDragMove:t=>{a.set({x:t.target.x(),y:t.target.y()})},onDragEnd:t=>{it(!1),a.set(R(t.target))},onClick:kt,onTap:kt,onTransformStart:()=>{et(!0);const t=h.current;at.current=t.height(),Et.current=a.a.width,yt.current=t.position(),lt.current=t.rotation(),ct.current=t.height(),st.current=w(t)},onTransform:t=>{var e,r;const o=t.target;null===(e=O.current)||void 0===e||e.setAttrs({x:o.x(),y:o.y(),rotation:o.rotation(),scale:o.scale()});const n=st.current;if("middle-left"===n||"middle-right"===n){const t=o.scaleX(),e=o.width()*t,r=F(Et.current,a.a.fontSize);let n=e;e<r&&(n=r,yt.current&&o.position(yt.current)),o.width(n),o.scaleX(1),o.scaleY(1);let i=wt();if("ellipsis"===L(a)){i=at.current}else{const t=Math.max(i,at.current);o.height(t),a.set({height:o.height()})}const l=M.textVerticalResizeEnabled?Math.max(i,at.current):wt();a.set({x:o.x(),width:o.width(),rotation:o.rotation(),height:l}),o.skewX(0),o.skewY(0),bt()}if("top-center"===n||"bottom-center"===n){const e="resize"===L(a)?wt():jt*a.a.fontSize,r=t.target.height()*t.target.scaleY();if(r<e){if(t.target.height(e),yt.current){if("top-center"===st.current){const r=lt.current*Math.PI/180,o=ct.current-e;t.target.x(yt.current.x-o*Math.sin(r)),t.target.y(yt.current.y+o*Math.cos(r))}else{t.target.position(yt.current)}}}else{t.target.height(r)}t.target.scaleY(1),t.target.scaleX(1),t.target.rotation(lt.current),t.target.skewX(0),t.target.skewY(0),ct.current=Math.max(e,r)}yt.current=t.target.position();const i=j(t.target.scaleX());null===(r=O.current)||void 0===r||r.setAttrs({scaleX:1,scaleY:1}),t.target.scaleX(1),t.target.scaleY(1),a.set({fontSize:a.a.fontSize*i,width:t.target.width()*i,x:t.target.x(),y:t.target.y(),rotation:t.target.rotation(),height:t.target.height()*i,shadowBlur:a.shadowBlur*i,shadowOffsetX:a.shadowOffsetX*i,shadowOffsetY:a.shadowOffsetY*i,strokeWidth:a.strokeWidth*i,borderSize:a.borderSize*i})},onTransformEnd:t=>{var e;const r=j(t.target.scaleX());t.target.scaleX(1),t.target.scaleY(1),a.set(Object.assign(Object.assign({},E(a,a.fontSize*r)),{width:Math.ceil(t.target.width()*r),x:k(t.target.x()),y:k(t.target.y()),rotation:k(t.target.rotation()),height:k(t.target.height()*r)})),null===(e=O.current)||void 0===e||e.setAttrs({scaleX:1,scaleY:1}),et(!1)}})),U&&a.contentEditable&&t(l,{x:a.a.x,y:a.a.y,rotation:a.a.rotation,children:t(ot,{textNodeRef:h,element:a,selectAll:Q,cursorPosition:zt.current,onBlur:()=>{a.set(z(a)),a.toggleEditMode(!1)}})})]})});
1
+ import{Fragment as t,jsx as e,jsxs as r}from"react/jsx-runtime";import{elementOpacity as o}from"./paint-opacity.js";import n from"react";import{toDisplayColor as i}from"@polotno/core/color";import{observer as a}from"mobx-react-lite";import{Group as l,Path as s,Text as c,TextPath as d}from"react-konva";import{Html as u}from"react-konva-utils";import{nodeAutorun as f}from"../utils/mobx.js";import h from"konva";import{parsePath as g,roundCommands as m}from"svg-round-corners/lib/index.js";import{generateBackgroundShapeFromRects as p,textLinesToRects as x}from"@polotno/core/background-shape";import{useColor as b}from"./use-color.js";import{ROLES as v}from"../model/store.js";import{incrementLoader as w}from"../utils/loader.js";import{activeAnchorOf as S,scaledFontSizeAttrs as y,roundedFontSizeAttrs as E,roundedTextDecorationAttrs as z,roundedGeometryPx as k,roundedPosition as R,textMinResizeWidth as F,transformScale as j}from"../utils/px.js";import{isFontLoaded as M}from"../utils/fonts.js";import{flags as A}from"../utils/flags.js";import{textOverflowOf as L}from"../utils/text-sizing.js";import{FIT_FONT_SIZE_STEP as O,FIT_HEIGHT_EPSILON as T,legacyTextOverflow as C}from"@polotno/core/text-sizing";import{removeTags as H}from"@polotno/core/text";import{getDir as P,getCurvePath as W,resolveLineHeight as X,normalizeStrokeLineJoin as D}from"@polotno/core/text-html";import{cssFontFamily as Y}from"@polotno/core/fonts";import{shadowCastByBackground as $}from"@polotno/core/filters";import{applyOpacityToColor as J}from"@polotno/core/svg";import{applyFilter as N}from"./apply-filters.js";import{useFadeIn as B}from"./use-fadein.js";import{isTouchDevice as I}from"../utils/screen.js";import{isAlive as _}from"mobx-state-tree";import{getLimitedFontSize as V}from"./text-element/max-font-size.js";import{getOptimalCaretColor as q}from"./text-element/caret-color.js";import{visiblePlaceholder as U}from"./text-element/placeholder.js";import{hasMeasuredHeight as Z,resolveTextBoxHeight as G}from"@polotno/core/text-types";let K;function Q(){return K||(K=document.getElementById("polotno-text-style"),K||(K=document.createElement("style"),K.id="polotno-text-style",document.head.appendChild(K)),K)}h._fixTextRendering=!0;const tt={border:"none",padding:"0px",overflow:"hidden",background:"none",outline:"none",resize:"none",overflowWrap:"break-word",whiteSpace:"pre-wrap",userSelect:"text",wordBreak:"normal",textTransform:"none"};export{getDir}from"@polotno/core/text-html";const et=a(({textNodeRef:t,element:r,onBlur:o,selectAll:i,cursorPosition:a})=>{const[l,s]=n.useState(tt),c=t.current;n.useLayoutEffect(()=>{if(!c){return}const t={};t.width=c.width()-2*c.padding()+"px",t.height=c.height()-2*c.padding()+c.fontSize()*c.lineHeight()+"px",t.fontSize=c.fontSize()+"px",t.lineHeight=c.lineHeight()+.01,t.fontFamily=c.fontFamily(),t.textAlign=c.align(),t.color=c.fill(),t.fontWeight=r.fontWeight,t.fontStyle=r.fontStyle,t.letterSpacing=r.letterSpacing+"em",t.opacity=Math.max(r.a.opacity,.2),t.textTransform=r.textTransform,t.caretColor=q(r);const e=`\n .polotno-input::placeholder {\n color: ${l.color};\n opacity: 0.6;\n }\n `,o=Q();o.innerHTML="",o.appendChild(document.createTextNode(e)),JSON.stringify(t)!==JSON.stringify(l)&&s(t)});const d=n.useRef(null);if(n.useLayoutEffect(()=>{var t;const e=d.current;if(!e){return}null===(t=d.current)||void 0===t||t.focus({preventScroll:!0});const r=a||e.value.length;e.selectionStart=e.selectionEnd=r,i&&e.setSelectionRange(0,e.value.length)},[]),n.useEffect(()=>{window.addEventListener("blur",o);const t=t=>{var e;(null===(e=d.current)||void 0===e?void 0:e.contains(t.target))||o()};return window.addEventListener("touchstart",t),()=>{window.removeEventListener("blur",o),window.removeEventListener("touchstart",t)}},[]),!c){return null}let u=0;const f=c.textArr.length*c.lineHeight()*c.fontSize(),h=G(r.a,f);"middle"===r.verticalAlign&&(u=(h-f)/2),"bottom"===r.verticalAlign&&(u=h-f);const g=H(r.text);return e("textarea",{className:"polotno-input",ref:d,dir:P(g),style:Object.assign(Object.assign(Object.assign({},tt),l),{paddingTop:u+"px"}),value:g,onChange:t=>{const e=V({oldText:r.text,newText:t.target.value,element:r});r.set(Object.assign({text:t.target.value},y(r,e)))},placeholder:U(r.placeholder),onBlur:o})}),rt=t=>e(u,{children:e(et,Object.assign({},t))});export const useFontLoader=(t,e,r,o,n)=>useFontFamiliesLoader(t,[e],r,o,n);export const useFontFamiliesLoader=(t,e,r,o,i)=>{const[a,l]=n.useReducer(t=>t+1,0),s=e.join("\0"),c=n.useRef(e.every(t=>M(t,r,o))),d=n.useRef(null);return n.useLayoutEffect(()=>{const n=c.current;if(c.current=e.every(t=>M(t,r,o)),c.current){return void(n||l())}let a=!0;return(async()=>{n&&l();const u=w(`fonts ${s}`);await Promise.all(e.map(e=>t.loadFont(e,r,o,i))),a?(d.current=u,c.current=!0,l()):u()})(),()=>{d.current&&(d.current(),d.current=null),a=!1}},[s,r,o]),n.useEffect(()=>{var t;c.current&&(null===(t=d.current)||void 0===t||t.call(d),d.current=null)},[c.current]),[c.current]};export const getLineHeight=({fontLoaded:t,fontFamily:e,fontSize:r,lineHeight:o})=>n.useMemo(()=>X({fontFamily:e,fontSize:r,lineHeight:o}),[t,e,r,o]);export function usePrevious(t){const e=n.useRef(t),r=n.useRef(t);return n.useMemo(()=>{r.current=e.current,e.current=t},[t]),r.current}export{getCurvePath}from"@polotno/core/text-html";export const TextElement=a(({element:a,store:u})=>{const h=n.useRef(null),M=n.useRef(null),X=n.useRef(null),V=n.useRef([]),q=n.useRef(!0),[,K]=n.useReducer(t=>t+1,0),{editorEnabled:Q,selectAll:tt}=(t=>{const[e,r]=n.useState(!1),o=n.useRef(!1);return n.useEffect(()=>{var e=!0;return setTimeout(()=>{e&&(t._editModeEnabled&&(o.current=!0),r(!0),setTimeout(()=>{o.current=!1},50))},50),()=>{e=!1}},[]),{editorEnabled:e&&t._editModeEnabled,selectAll:o.current}})(a),[et,ot]=n.useState(!1),[nt,it]=n.useState(!1),at=n.useRef(a.a.height),lt=n.useRef(0),st=n.useRef(""),ct=n.useRef(0),dt=a.isSelected,ut=usePrevious(dt),{textVerticalResizeEnabled:ft}=A,ht=A.autoDeleteEmptyText,gt=usePrevious(a.fontFamily),[mt,pt]=n.useState([]),xt=a.backgroundEnabled||a.borderSize>0;n.useLayoutEffect(()=>{var t,e;if(!xt){return}const r=null!==(e=null===(t=h.current)||void 0===t?void 0:t.textArr)&&void 0!==e?e:[];JSON.stringify(r)!==JSON.stringify(mt)&&pt(r)}),n.useEffect(()=>{if(a.a.width){return}const t=h.current;t.width(600),a.set({width:1.4*t.getTextWidth()})},[]),n.useEffect(()=>{ut&&!dt&&ht&&""===a.text&&a.removable&&!U(a.placeholder)&&u.deleteElements([a.id])},[ht,a.placeholder,a.removable,a.text,dt,ut]);const bt=()=>{if(a.curveEnabled){const t=h.current;null==t||t.clearCache(),null==t||t.setAttrs({filters:[]});const e=M.current;e&&N(e,a)}else{const t=h.current;t&&N(t,a)}};n.useLayoutEffect(()=>{if(!nt){return f(a,()=>{bt()})}}),n.useEffect(()=>{const t=V.current;t.length>0&&(V.current=[],t.forEach(t=>t()))}),n.useEffect(()=>()=>{q.current=!1;const t=V.current;t.length>0&&(V.current=[],t.forEach(t=>t()))},[]);let vt=H(a.text);"uppercase"===a.textTransform&&(vt=vt.toUpperCase());const[wt]=useFontLoader(u,a.fontFamily,a.fontStyle,a.fontWeight,a.text||a.placeholder),St=()=>{if(a.curveEnabled){const t=M.current;return t.getSelfRect().height||t.fontSize()}const t=h.current.clone({height:void 0}),e=Math.ceil(t.fontSize()*t.lineHeight()*t.textArr.length+1);return t.destroy(),e};n.useLayoutEffect(()=>{if(!wt){return}const t=C(L(a)),{textSplitAllowed:e}=A,r=(t,e,r,o)=>{const n=w(`text ${a.id}`),i=()=>{u.history.ignore(t,e,r).then(()=>{q.current?(V.current.push(n),K()):n()})};o?queueMicrotask(i):i()};if(!Z(a)){const t=St();return void r(()=>{Z(a)||a.set({height:t})},void 0,void 0,!0)}if(!u.isPlaying){if("change-font-size"!==t||et){if("resize"===t){const t=St();ft&&a.height<t&&!et&&r(()=>{var e;_(a)&&a.set({height:t}),null===(e=h.current)||void 0===e||e.height(t)},!1,!0),ft||a.height===t||et||r(()=>{var e;_(a)&&a.set({height:t}),null===(e=h.current)||void 0===e||e.height(t)},!1,!0)}}else{const t=h.current,o=a.curveEnabled?a.fontSize:function(t,e,r=!1){const o=t.fontSize(),n=t.height(),i=H(e.text);let a=e.a.fontSize;t.height(void 0);const l=Math.round(2*e.a.fontSize)-1;for(let s=1;s<l;s++){const o=Z(e.a)&&t.height()>e.a.height+T;let n=i.split("\n").join(" ").split(/[\s-]+/).reduce((t,e)=>(e=e.toLowerCase(),/[\u3000-\u303F\u3040-\u309F\u30A0-\u30FF\uFF00-\uFFEF\u4E00-\u9FAF\uAC00-\uD7AF]/.test(e)?t.concat(e.split("")):t.concat(e)),[]),l=t.textArr.map(t=>t.text.toLowerCase()).join(";");const s=n.find(t=>!l.includes(t)||(l=l.replace(t,""),!1));if(!(o||s&&!r)){break}a-=O,t.fontSize(a)}return t.fontSize(o),t.height(n),a}(t,a,e);if(o!==a.fontSize){return void r(()=>{a.set(y(a,o))},!1,!0)}const n=St();a.height===n||ft||r(()=>{a.set({height:n})},!1,!0)}}}),n.useLayoutEffect(()=>{var t;if(wt&&a.curveEnabled){const e=null===(t=M.current)||void 0===t?void 0:t.getSelfRect().width;if(e){const t=e-a.a.width,r=a.a.rotation*Math.PI/180,o=-t/2*Math.cos(r),n=-t/2*Math.sin(r);a.set({width:e,x:a.a.x+o,y:a.a.y+n})}}},[wt,a.curveEnabled,a.curvePower,a.text,a.fontSize,a.fontFamily,a.fontWeight,a.fontStyle,a.letterSpacing]),n.useLayoutEffect(()=>{const t=h.current;t&&(t.width(t.width()+1e-8),t.width(t.width()-1e-8),t._setTextData(),bt())},[wt]);const yt=n.useRef(null),Et=n.useRef(a.width),zt=n.useRef(0),kt=t=>{t.evt.preventDefault();const e=u.selectedShapes.find(t=>t===a);e&&a.contentEditable&&(zt.current=function(t){var e;const r=t.target,o=function(t){var e=t.getAbsoluteTransform().copy();e.invert();var r=t.getStage().getPointerPosition();return e.point(r)}(r),n=r.textArr,i=Math.floor(o.y/(r.fontSize()*r.lineHeight())),a=n.slice(0,i).reduce((t,e)=>t+e.text.length,i),l=null!==(e=n[i])&&void 0!==e?e:n[0];let s=0;return"right"===r.align()?s=r.width()-l.width:"center"===r.align()&&(s=r.width()/2-l.width/2),a+Math.round((o.x-s)/l.width*l.text.length)}(t),a.toggleEditMode())},Rt=U(a.placeholder),Ft=!vt&&Rt?.6:o(a);B(h,Ft);const jt=getLineHeight({fontLoaded:wt,fontFamily:a.fontFamily,fontSize:a.a.fontSize,lineHeight:a.lineHeight}),Mt=a.selectable||u.role===v.ADMIN,At=b(a),Lt=b(a,a.stroke,"stroke"),Ot=n.useMemo(()=>a.backgroundEnabled||a.borderSize?a.curveEnabled?function({width:t,height:e,padding:r=0,cornerRadius:o=0}){const n=-r,i=-r,a=t+r,l=e+r,s=g(`M ${n} ${i} L ${a} ${i} L ${a} ${l} L ${n} ${l} Z`);return m(s,o).path}({width:a.a.width,height:a.a.height,cornerRadius:a.backgroundCornerRadius*(a.a.fontSize*jt*.5),padding:a.backgroundPadding*(a.a.fontSize*jt*.5)}):function({lines:t,lineHeight:e,width:r,align:o="left",padding:n=0,cornerRadius:i=0}){const a=x({lines:t,lineHeight:e,width:r,align:o});return p({rects:a,padding:n,cornerRadius:i})}({lines:JSON.parse(JSON.stringify(mt)),cornerRadius:a.backgroundCornerRadius*(a.a.fontSize*jt*.5),lineHeight:jt*a.a.fontSize,padding:a.backgroundPadding*(a.a.fontSize*jt*.5),width:a.a.width,align:a.align}):"",[a.backgroundEnabled,a.borderSize,a.curveEnabled,a.backgroundCornerRadius,a.a.fontSize,a.a.height,jt,a.backgroundPadding,a.a.width,a.align,mt]),Tt=I();let Ct=0;if(!a.curveEnabled){const t=mt.length*jt*a.a.fontSize,e=G(a.a,t);"middle"===a.verticalAlign?Ct=(e-t)/2:"bottom"===a.verticalAlign&&(Ct=e-t)}const Ht=a.curveEnabled?W(a.a.width,a.a.height,a.curvePower,a.a.fontSize):"",Pt=wt?Y(a.fontFamily):gt===a.fontFamily?"Arial":Y(gt),Wt=P(vt),Xt=a.shadowEnabled&&!$(a),Dt={shadowEnabled:a.shadowEnabled&&($(a)||a.borderSize>0),shadowBlur:a.shadowBlur,shadowOffsetX:a.shadowOffsetX,shadowOffsetY:a.shadowOffsetY,shadowColor:i(a.shadowColor),shadowOpacity:a.shadowOpacity};return r(t,{children:[xt&&e(s,Object.assign({ref:X,x:a.a.x,y:a.a.y,rotation:a.a.rotation,hideInExport:!a.showInExport,listening:!1,opacity:Ft,data:Ot,fillEnabled:a.backgroundEnabled,fill:J(a.backgroundColor,a.backgroundOpacity),strokeEnabled:a.borderSize>0,stroke:i(a.borderColor),strokeWidth:a.borderSize,lineJoin:a.backgroundCornerRadius>0?"round":"miter",offsetY:-Ct},Dt)),a.curveEnabled&&e(d,Object.assign({ref:M,data:Ht,text:vt||Rt,listening:!1,align:"center",textBaseline:"middle",direction:Wt},At,Lt,{strokeWidth:a.strokeWidth,lineJoin:D(a.strokeLineJoin),fillAfterStrokeEnabled:!0,fontSize:a.a.fontSize,fontFamily:`${Y(a.fontFamily)}, ${Y(gt)}`,fontStyle:a.fontStyle+" "+a.fontWeight,textDecoration:a.textDecoration.trim(),letterSpacing:a.letterSpacing*a.a.fontSize,x:a.a.x,y:a.a.y,rotation:a.a.rotation,opacity:a._editModeEnabled?.3:Ft,hideInExport:!a.showInExport},Dt,{shadowEnabled:Xt})),e(c,Object.assign({ref:h,id:a.selectable?a.id:void 0,name:a.selectable?"element":"",hideInExport:!a.showInExport,editModeEnabled:a._editModeEnabled,x:a.a.x,y:a.a.y,rotation:a.a.rotation,width:a.a.width,height:Z(a.a)?a.a.height:void 0,text:vt||Rt,direction:Wt},At,Lt,{lineJoin:D(a.strokeLineJoin),strokeWidth:a.strokeWidth,fillAfterStrokeEnabled:!0,fontSize:a.a.fontSize,fontFamily:Pt,fontStyle:a.fontStyle+" "+a.fontWeight,textDecoration:a.textDecoration,align:a.align,verticalAlign:a.verticalAlign,draggable:Tt?a.draggable&&dt:a.draggable,preventDefault:!Tt||dt,opacity:a.curveEnabled?0:Ft,visible:!a._editModeEnabled,ellipsis:"ellipsis"===L(a)},Dt,{shadowEnabled:Xt,lineHeight:jt,letterSpacing:a.letterSpacing*a.a.fontSize,listening:!!a.selectable&&Mt,onDragStart:()=>{it(!0)},onDragMove:t=>{a.set({x:t.target.x(),y:t.target.y()})},onDragEnd:t=>{it(!1),a.set(R(t.target))},onClick:kt,onTap:kt,onTransformStart:()=>{ot(!0);const t=h.current;at.current=t.height(),Et.current=a.a.width,yt.current=t.position(),lt.current=t.rotation(),ct.current=t.height(),st.current=S(t)},onTransform:t=>{var e,r;const o=t.target;null===(e=X.current)||void 0===e||e.setAttrs({x:o.x(),y:o.y(),rotation:o.rotation(),scale:o.scale()});const n=st.current;if("middle-left"===n||"middle-right"===n){const t=o.scaleX(),e=o.width()*t,r=F(Et.current,a.a.fontSize);let n=e;e<r&&(n=r,yt.current&&o.position(yt.current)),o.width(n),o.scaleX(1),o.scaleY(1);let i=St();if("ellipsis"===L(a)){i=at.current}else{const t=Math.max(i,at.current);o.height(t),a.set({height:o.height()})}const l=A.textVerticalResizeEnabled?Math.max(i,at.current):St();a.set({x:o.x(),width:o.width(),rotation:o.rotation(),height:l}),o.skewX(0),o.skewY(0),bt()}if("top-center"===n||"bottom-center"===n){const e="resize"===L(a)?St():jt*a.a.fontSize,r=t.target.height()*t.target.scaleY();if(r<e){if(t.target.height(e),yt.current){if("top-center"===st.current){const r=lt.current*Math.PI/180,o=ct.current-e;t.target.x(yt.current.x-o*Math.sin(r)),t.target.y(yt.current.y+o*Math.cos(r))}else{t.target.position(yt.current)}}}else{t.target.height(r)}t.target.scaleY(1),t.target.scaleX(1),t.target.rotation(lt.current),t.target.skewX(0),t.target.skewY(0),ct.current=Math.max(e,r)}yt.current=t.target.position();const i=j(t.target.scaleX());null===(r=X.current)||void 0===r||r.setAttrs({scaleX:1,scaleY:1}),t.target.scaleX(1),t.target.scaleY(1),a.set({fontSize:a.a.fontSize*i,width:t.target.width()*i,x:t.target.x(),y:t.target.y(),rotation:t.target.rotation(),height:t.target.height()*i,shadowBlur:a.shadowBlur*i,shadowOffsetX:a.shadowOffsetX*i,shadowOffsetY:a.shadowOffsetY*i,strokeWidth:a.strokeWidth*i,borderSize:a.borderSize*i})},onTransformEnd:t=>{var e;const r=j(t.target.scaleX());t.target.scaleX(1),t.target.scaleY(1),a.set(Object.assign(Object.assign({},E(a,a.fontSize*r)),{width:Math.ceil(t.target.width()*r),x:k(t.target.x()),y:k(t.target.y()),rotation:k(t.target.rotation()),height:k(t.target.height()*r)})),null===(e=X.current)||void 0===e||e.setAttrs({scaleX:1,scaleY:1}),ot(!1)}})),Q&&a.contentEditable&&e(l,{x:a.a.x,y:a.a.y,rotation:a.a.rotation,children:e(rt,{textNodeRef:h,element:a,selectAll:tt,cursorPosition:zt.current,onBlur:()=>{a.set(z(a)),a.toggleEditMode(!1)}})})]})});
@@ -35,11 +35,6 @@ export declare const useColor: (element: ColorElement, value?: string, propName?
35
35
  strokeLinearGradientEndPointX?: undefined;
36
36
  strokeLinearGradientEndPointY?: undefined;
37
37
  } | {
38
- strokeLinearGradientStartPointX: number;
39
- strokeLinearGradientStartPointY: number;
40
- strokeLinearGradientColorStops: (string | number)[];
41
- strokeLinearGradientEndPointX: number;
42
- strokeLinearGradientEndPointY: number;
43
38
  fillLinearGradientStartPointX?: undefined;
44
39
  fillLinearGradientStartPointY?: undefined;
45
40
  fillLinearGradientColorStops?: undefined;
@@ -47,5 +42,10 @@ export declare const useColor: (element: ColorElement, value?: string, propName?
47
42
  fillLinearGradientEndPointY?: undefined;
48
43
  fill?: undefined;
49
44
  fillPriority?: undefined;
45
+ strokeLinearGradientStartPointX: number;
46
+ strokeLinearGradientStartPointY: number;
47
+ strokeLinearGradientColorStops: (string | number)[];
48
+ strokeLinearGradientEndPointX: number;
49
+ strokeLinearGradientEndPointY: number;
50
50
  };
51
51
  export {};
@@ -1 +1 @@
1
- import{isAlive as t}from"mobx-state-tree";import{applyFiltersToCanvas as r,hasActiveFilters as o,getFiltersDepsKey as e}from"./apply-filters.js";import{trySetCanvasSize as s}from"../utils/canvas.js";import{sourceSize as i}from"./downscale.js";import{useOffscreenCanvas as m}from"./use-offscreen-canvas.js";export const useFilteredSource=(n,f)=>{const a=e(n),c=t(n)&&o(n),p=o=>{if(!f||!t(n)){return}const{width:e,height:m}=i(f);if(!e||!m){return}s(o,e,m);const a=o.getContext("2d");a&&(a.drawImage(f,0,0),r(o,n))},u=m(c&&!!f,p,[f,a]);return[u||f||void 0,()=>{u&&p(u)}]};
1
+ import{isAlive as t}from"mobx-state-tree";import{applyFiltersToCanvas as r,hasActiveFilters as e,getFiltersDepsKey as o}from"./apply-filters.js";import{trySetCanvasSize as s}from"../utils/canvas.js";import{sourceSize as i}from"./downscale.js";import{useOffscreenCanvas as m}from"./use-offscreen-canvas.js";export const useFilteredSource=(n,f)=>{const a=o(n),c=t(n)&&e(n),p=e=>{if(!f||!t(n)){return}const{width:o,height:m}=i(f);if(!o||!m){return}s(e,o,m);const a=e.getContext("2d");a&&(a.drawImage(f,0,0),r(e,n))},{width:d,height:u}=f?i(f):{},h=m(c&&!!f,p,[f,a,d,u]);return[h||f||void 0,()=>{h&&p(h)}]};
@@ -1 +1 @@
1
- import e from"react";import{nodeAutorun as r}from"../utils/mobx.js";import{Input as t,UrlSource as n,BufferSource as u,VideoSampleSink as i,ALL_FORMATS as a}from"mediabunny";import{incrementLoader as c,triggerLoadError as o}from"../utils/loader.js";import{polotnoError as s}from"@polotno/core/errors";import{getElementTimeRange as l,getVideoRestMs as d}from"../utils/timeline.js";import{decodeBase64 as m}from"../utils/base64.js";function f(e,r){const t=p(e);return t>0&&r>=e.timestamp&&r<e.timestamp+t}function p(e){var r;const t=null!==(r=e.duration)&&void 0!==r?r:0;return Number.isFinite(t)&&t>0?t:0}function h(e){var r;null===(r=null==e?void 0:e.close)||void 0===r||r.call(e)}function v(e){for(const r of e.current){h(r.frame)}e.current=[]}export const useMediabunnyVideo=(g,y,w)=>{const[b,T]=e.useState({input:null,videoSink:null,duration:0,isReady:!1,error:null,hasAlpha:!1});e.useRef(b).current=b;const R=e.useRef(0),k=e.useRef(null),E=e.useRef(null),$=e.useRef(null),S=e.useRef(null),O=e.useRef(null),F=e.useRef(null),j=e.useRef(null),x=e.useRef(!1),D=e.useRef(null),I=e.useRef([]),A=e.useRef(null),L=e.useRef(!1),[,U]=e.useReducer(e=>e+1,0);return e.useEffect(()=>{if(!w){return}let e=!0;const r=++R.current;let l=null;return(async()=>{try{if(!e||r!==R.current){return}l=c(`mediabunny init ${g.id}`);const o=await async function(e){if(function(e){return e.startsWith("data:")}(e)){const r=function(e){const r=e.indexOf(",");if(-1===r){throw new Error("Invalid data URL format")}return m(e.slice(r+1)).buffer}(e);return new u(r)}if(function(e){return e.startsWith("file://")}(e)){try{const r=await fetch(e),t=await r.arrayBuffer();return new u(t)}catch(r){throw new Error(`Failed to load file URL: ${e}. File URLs may not be supported in this environment. Error: ${r}`)}}return new n(e)}(g.src);if(!e||r!==R.current){return void(l&&(l(),l=null))}const d=new t({source:o,formats:a}),f=await d.computeDuration(),p=await d.getPrimaryVideoTrack();if(!p){throw s("VIDEO_FAILED","No video track found",{reason:"no-video-track"})}if(null===p.codec){throw s("VIDEO_FAILED","Unsupported video codec",{reason:"unsupported-codec"})}if(!await p.canDecode()){throw s("VIDEO_FAILED","Unable to decode the video track",{reason:"cannot-decode"})}const h=await p.canBeTransparent(),v=new i(p);if(!e||r!==R.current){return d.dispose(),void(l&&(l(),l=null))}l&&(l(),l=null),T(e=>Object.assign(Object.assign({},e),{input:d,videoSink:v,duration:f,isReady:!0,error:null,hasAlpha:h}))}catch(d){if(console.error("Failed to initialize mediabunny:",d),l&&(l(),l=null),e&&r===R.current){const e=`Failed to initialize mediabunny for video ${g.id}: ${d}`;o(s("VIDEO_FAILED",e,Object.assign({reason:"load"},null==d?void 0:d.details),d)),T(e=>Object.assign(Object.assign({},e),{error:String(d),isReady:!1}))}}})(),()=>{e=!1,l&&(l(),l=null)}},[g.src,w]),e.useEffect(()=>()=>{E.current&&(E.current.return(),E.current=null),k.current&&(k.current(),k.current=null),$.current=null,S.current=null,O.current=null,F.current=null,x.current=!1,D.current=null,v(I),A.current=null,L.current=!1,T({input:null,videoSink:null,duration:0,isReady:!1,error:null,hasAlpha:!1})},[w]),e.useEffect(()=>{if(!w||!b.isReady||!b.videoSink){return}const e=++R.current,t="string"==typeof g.src?g.src.slice(0,120):String(g.src),n=(e,r={},n="debug")=>{var u;let i="";try{i=JSON.stringify(Object.assign(Object.assign({},r),{timeCalc:j.current}))}catch(c){i=`[unserializable extras: ${String(c)}]`}const a=`mediabunny event=${e} elementId=${g.id} targetTime=${F.current} duration=${b.duration} lastFrameTimestamp=${null===(u=O.current)||void 0===u?void 0:u.timestamp} hasIterator=${Boolean(E.current)} prefetchSize=${I.current.length} srcHint=${t} extras=${i}`;"error"===n?console.error(a):"warn"===n?console.warn(a):console.debug(a)},u=e=>{const r=b.duration||0;return r&&Number.isFinite(r)?Math.max(0,Math.min(e,r)):e},i=e=>{const r=e.displayWidth,t=e.displayHeight;let n=$.current;n&&n.width===r&&n.height===t||(n||(n=document.createElement("canvas"),$.current=n,S.current=n.getContext("2d",{alpha:b.hasAlpha})),n.width=r,n.height=t);const u=S.current,i=e.timestamp,a=p(e);try{u&&(b.hasAlpha&&u.clearRect(0,0,n.width,n.height),e.drawWithFit(u,{fit:"contain"}))}finally{h(e)}O.current={timestamp:i,duration:a}},a=e=>{const r=E.current;r&&(L.current||(L.current=!0,A.current=(async()=>{try{for(;I.current.length<4&&e===R.current;){const t=await r.next();if(e!==R.current){return void h(t.value)}if(t.done||!t.value){break}I.current.push({timestamp:t.value.timestamp,frame:t.value})}}catch(t){}finally{L.current=!1,A.current=null}})()))},o=e=>{const r=I.current;let t=-1;for(let u=0;u<r.length&&!(r[u].timestamp>e);u++){t=u}if(-1===t){return null}const n=r[t];if(!(t<r.length-1||f(n.frame,e))){return null}for(let u=0;u<t;u++){h(r[u].frame)}return I.current=r.slice(t+1),n},s=()=>v(I),m=async(e,r,t=0)=>{const c=u(e),l=(e=>{const r=O.current;return!r||e<r.timestamp||e>r.timestamp+.5})(c)?"seek":"iterate";try{const t=b.videoSink,u=O.current;if(u&&f(u,c)){return void(F.current=e)}const d=o(c);if(d){return i(d.frame),F.current=e,a(r),void U()}if(A.current){await A.current;const t=o(c);if(t){return i(t.frame),F.current=e,a(r),void U()}}s();const m=()=>n("iterator_exhausted",{mode:l,requestedTargetTime:e,clampedTargetTime:c},"warn"),p=async e=>{E.current&&(await E.current.return(),E.current=null),s();const n=t.samples(e);E.current=n;const u=await n.next();return r!==R.current?(u.value&&h(u.value),await n.return(),E.current===n&&(E.current=null),"cancelled"):u.done||!u.value?"empty":(i(u.value),a(r),"drawn")};if("seek"===l){const e=await p(c);if("cancelled"===e){return}if("empty"===e){return void m()}}else{const e=E.current;if(!e){return}for(;r===R.current;){const t=await e.next();if(r!==R.current){t.value&&h(t.value);break}if(t.done||!t.value){"empty"===await p(c)&&m();break}const n=t.value;if(f(n,c)||n.timestamp>=c){i(n),a(r);break}h(n)}}F.current=e,U()}catch(d){const u=d instanceof Error?{name:d.name,message:d.message,stack:d.stack}:{message:String(d)},i=d instanceof Error?`${d.name}: ${d.message}`:String(d),a=i.includes("Unsupported configuration")||i.includes("isConfigSupported")||i.includes("OperationError");if(n("frame_process_failed",{mode:l,requestedTargetTime:e,clampedTargetTime:c,unsupportedConfigAttempt:t,isUnsupportedConfig:a,error:u},"error"),a&&t<1){try{E.current&&(await E.current.return(),E.current=null),s(),A.current=null,L.current=!1,O.current=null,await m(e,r,t+1)}catch(p){}}}},T=r(g,()=>{const r=b.videoSink,t=b.duration;if(!r||!t){return}const n=g.startTime*t*1e3,i=t*(g.endTime-g.startTime)*1e3,{start:a}=l(g.animations,g.page.duration),o=d(y.currentTime,g.page.startTime,a,i,n,g.speed),s=o/1e3+1e-6,f=u(s);j.current={pageStartTime:g.page.startTime,storeCurrentTime:y.currentTime,offsetMs:n,durationMs:i,restMs:o,targetTime:s,clampedTargetTime:f,startTime:g.startTime,endTime:g.endTime,videoDuration:t},((e,r)=>{x.current?D.current=e:(x.current=!0,k.current||(k.current=c(`mediabunny video frame ${g.id}`)),(async()=>{let t=e;for(;null!==t&&r===R.current;){await m(t,r),t=D.current,D.current=null}k.current&&(k.current(),k.current=null),x.current=!1})())})(s,e)});return()=>{T(),R.current++,k.current&&(k.current(),k.current=null)}},[w,b.isReady,b.videoSink,b.duration,y,g]),w&&b.isReady?$.current:null};
1
+ import e from"react";import{nodeAutorun as r}from"../utils/mobx.js";import{Input as t,UrlSource as n,BufferSource as u,VideoSampleSink as i,ALL_FORMATS as a}from"mediabunny";import{incrementLoader as c,triggerLoadError as o}from"../utils/loader.js";import{polotnoError as s}from"@polotno/core/errors";import{getElementTimeRange as l,getVideoRestMs as d}from"../utils/timeline.js";import{decodeBase64 as m}from"../utils/base64.js";function f(e,r){const t=p(e);return t>0&&r>=e.timestamp&&r<e.timestamp+t}function p(e){var r;const t=null!==(r=e.duration)&&void 0!==r?r:0;return Number.isFinite(t)&&t>0?t:0}function h(e){var r;null===(r=null==e?void 0:e.close)||void 0===r||r.call(e)}function v(e){for(const r of e.current){h(r.frame)}e.current=[]}export const useMediabunnyVideo=(g,w,y)=>{const[b,T]=e.useState({input:null,videoSink:null,duration:0,isReady:!1,error:null,hasAlpha:!1});e.useRef(b).current=b;const R=e.useRef(0),E=e.useRef(null),k=e.useRef(null),$=e.useRef(null),S=e.useRef(null),O=e.useRef(null),F=e.useRef(null),j=e.useRef(null),x=e.useRef(!1),D=e.useRef(null),I=e.useRef([]),A=e.useRef(null),_=e.useRef(!1),[,M]=e.useReducer(e=>e+1,0);return e.useEffect(()=>{if(!y){return}let e=!0;const r=++R.current;let l=null;return(async()=>{try{if(!e||r!==R.current){return}l=c(`mediabunny init ${g.id}`);const o=await async function(e){if(function(e){return e.startsWith("data:")}(e)){const r=function(e){const r=e.indexOf(",");if(-1===r){throw new Error("Invalid data URL format")}return m(e.slice(r+1)).buffer}(e);return new u(r)}if(function(e){return e.startsWith("file://")}(e)){try{const r=await fetch(e),t=await r.arrayBuffer();return new u(t)}catch(r){throw new Error(`Failed to load file URL: ${e}. File URLs may not be supported in this environment. Error: ${r}`)}}return new n(e)}(g.src);if(!e||r!==R.current){return void(l&&(l(),l=null))}const d=new t({source:o,formats:a}),f=await d.computeDuration(),p=await d.getPrimaryVideoTrack();if(!p){throw s("VIDEO_FAILED","No video track found",{reason:"no-video-track"})}if(null===p.codec){throw s("VIDEO_FAILED","Unsupported video codec",{reason:"unsupported-codec"})}if(!await p.canDecode()){throw s("VIDEO_FAILED","Unable to decode the video track",{reason:"cannot-decode"})}const h=await p.canBeTransparent(),v=new i(p);if(!e||r!==R.current){return d.dispose(),void(l&&(l(),l=null))}l&&(l(),l=null),T(e=>Object.assign(Object.assign({},e),{input:d,videoSink:v,duration:f,isReady:!0,error:null,hasAlpha:h}))}catch(d){if(console.error("Failed to initialize mediabunny:",d),l&&(l(),l=null),e&&r===R.current){const e=`Failed to initialize mediabunny for video ${g.id}: ${d}`;o(s("VIDEO_FAILED",e,Object.assign({reason:"load"},null==d?void 0:d.details),d)),T(e=>Object.assign(Object.assign({},e),{error:String(d),isReady:!1}))}}})(),()=>{e=!1,l&&(l(),l=null)}},[g.src,y]),e.useEffect(()=>()=>{k.current&&(k.current.return(),k.current=null),E.current&&(E.current(),E.current=null),$.current=null,S.current=null,O.current=null,F.current=null,x.current=!1,D.current=null,v(I),A.current=null,_.current=!1,T({input:null,videoSink:null,duration:0,isReady:!1,error:null,hasAlpha:!1})},[y]),e.useEffect(()=>{if(!y||!b.isReady||!b.videoSink){return}const e=++R.current,t="string"==typeof g.src?g.src.slice(0,120):String(g.src),n=(e,r={},n="debug")=>{var u;let i="";try{i=JSON.stringify(Object.assign(Object.assign({},r),{timeCalc:j.current}))}catch(c){i=`[unserializable extras: ${String(c)}]`}const a=`mediabunny event=${e} elementId=${g.id} targetTime=${F.current} duration=${b.duration} lastFrameTimestamp=${null===(u=O.current)||void 0===u?void 0:u.timestamp} hasIterator=${Boolean(k.current)} prefetchSize=${I.current.length} srcHint=${t} extras=${i}`;"error"===n?console.error(a):"warn"===n?console.warn(a):console.debug(a)},u=e=>{const r=b.duration||0;return r&&Number.isFinite(r)?Math.max(0,Math.min(e,r)):e},i=e=>{const r=e.displayWidth,t=e.displayHeight;let n=$.current;n&&n.width===r&&n.height===t||(n||(n=document.createElement("canvas"),$.current=n,S.current=n.getContext("2d",{alpha:b.hasAlpha})),n.width=r,n.height=t);const u=S.current,i=e.timestamp,a=p(e);try{u&&(b.hasAlpha&&u.clearRect(0,0,n.width,n.height),e.drawWithFit(u,{fit:"contain"}))}finally{h(e)}O.current={timestamp:i,duration:a}},a=e=>{const r=k.current;r&&(_.current||(_.current=!0,A.current=(async()=>{try{for(;I.current.length<4&&e===R.current;){const t=await r.next();if(e!==R.current){return void h(t.value)}if(t.done||!t.value){break}I.current.push({timestamp:t.value.timestamp,frame:t.value})}}catch(t){}finally{_.current=!1,A.current=null}})()))},o=e=>{const r=I.current;let t=-1;for(let u=0;u<r.length&&!(r[u].timestamp>e);u++){t=u}if(-1===t){return null}const n=r[t];if(!(t<r.length-1||f(n.frame,e))){return null}for(let u=0;u<t;u++){h(r[u].frame)}return I.current=r.slice(t+1),n},s=()=>v(I),m=async(e,r,t=0)=>{const c=u(e),l=(e=>{const r=O.current;return!r||e<r.timestamp||e>r.timestamp+.5})(c)?"seek":"iterate";try{const t=b.videoSink,u=O.current;if(u&&f(u,c)){return void(F.current=e)}const d=o(c);if(d){return i(d.frame),F.current=e,a(r),void M()}if(A.current){await A.current;const t=o(c);if(t){return i(t.frame),F.current=e,a(r),void M()}}s();const m=()=>n("iterator_exhausted",{mode:l,requestedTargetTime:e,clampedTargetTime:c},"warn"),p=async e=>{k.current&&(await k.current.return(),k.current=null),s();const n=t.samples(e);k.current=n;const u=await n.next();return r!==R.current?(u.value&&h(u.value),await n.return(),k.current===n&&(k.current=null),"cancelled"):u.done||!u.value?"empty":(i(u.value),a(r),"drawn")};if("seek"===l){const e=await p(c);if("cancelled"===e){return}if("empty"===e){return void m()}}else{const e=k.current;if(!e){return}for(;r===R.current;){const t=await e.next();if(r!==R.current){t.value&&h(t.value);break}if(t.done||!t.value){"empty"===await p(c)&&m();break}const n=t.value;if(f(n,c)||n.timestamp>=c){i(n),a(r);break}h(n)}}F.current=e,M()}catch(d){const u=d instanceof Error?{name:d.name,message:d.message,stack:d.stack}:{message:String(d)},i=d instanceof Error?`${d.name}: ${d.message}`:String(d),a=i.includes("Unsupported configuration")||i.includes("isConfigSupported")||i.includes("OperationError");if(n("frame_process_failed",{mode:l,requestedTargetTime:e,clampedTargetTime:c,unsupportedConfigAttempt:t,isUnsupportedConfig:a,error:u},"error"),a&&t<1){try{k.current&&(await k.current.return(),k.current=null),s(),A.current=null,_.current=!1,O.current=null,await m(e,r,t+1)}catch(p){}}}},T=r(g,()=>{var r;const t=b.videoSink,n=b.duration;if(!t||!n){return}const i=g.startTime*n*1e3,a=n*(g.endTime-g.startTime)*1e3,{start:o,end:s}=l(g.animations,g.page.duration),f=d(null!==(r=g.page._mediaLocalTime)&&void 0!==r?r:0,0,o,a,i,g.speed,{windowEnd:s,frameMs:w._renderFrameMs,renderEnd:w._renderEndMs-g.page.startTime}),p=f/1e3+1e-6,h=u(p);j.current={pageStartTime:g.page.startTime,storeCurrentTime:w.currentTime,offsetMs:i,durationMs:a,restMs:f,targetTime:p,clampedTargetTime:h,startTime:g.startTime,endTime:g.endTime,videoDuration:n},((e,r)=>{x.current?D.current=e:(x.current=!0,E.current||(E.current=c(`mediabunny video frame ${g.id}`)),(async()=>{let t=e;for(;null!==t&&r===R.current;){await m(t,r),t=D.current,D.current=null}E.current&&(E.current(),E.current=null),x.current=!1})())})(p,e)});return()=>{T(),R.current++,E.current&&(E.current(),E.current=null)}},[y,b.isReady,b.videoSink,b.duration,w,g]),y&&b.isReady?$.current:null};
@@ -1,10 +1,10 @@
1
1
  import Konva from 'konva';
2
2
  import { StoreType } from '../model/store.js';
3
3
  declare let snapFilterFunc: ({ targetKonvaNodes, guideKonvaNode, distance, snapDirection, }: {
4
- targetKonvaNodes: any;
5
- guideKonvaNode: any;
6
4
  distance: any;
5
+ guideKonvaNode: any;
7
6
  snapDirection: any;
7
+ targetKonvaNodes: any;
8
8
  }) => boolean;
9
9
  export declare const setSnapFilterFunc: (func: typeof snapFilterFunc) => void;
10
10
  export declare const ensureDragOrder: () => void;
@@ -1,13 +1,15 @@
1
1
  import React from 'react';
2
2
  import { StoreType } from '../model/store.js';
3
3
  import { VideoElementType } from '../model/video-model.js';
4
- export declare const useCornerRadiusAndCrop: (element: VideoElementType, image: HTMLVideoElement | HTMLCanvasElement | undefined, crop: {
4
+ import { ImageElementType } from '../model/image-model.js';
5
+ export declare const useFlip: (element: ImageElementType, image: HTMLVideoElement | HTMLCanvasElement | undefined) => readonly [HTMLCanvasElement | HTMLVideoElement | undefined, () => void];
6
+ export declare const useCornerRadiusAndCrop: (element: ImageElementType, image: HTMLVideoElement | HTMLCanvasElement | undefined, crop: {
5
7
  x: number;
6
8
  y: number;
7
9
  width: number;
8
10
  height: number;
9
11
  }, pixelRatio: number, cornerRadius?: number, skipDownscale?: boolean) => readonly [HTMLCanvasElement | HTMLVideoElement | undefined, () => void];
10
- export declare const useClip: (element: VideoElementType, image: HTMLVideoElement | HTMLCanvasElement | undefined, pixelRatio: number, deps: readonly unknown[]) => readonly [HTMLCanvasElement | HTMLVideoElement | undefined, () => void];
12
+ export declare const useClip: (element: ImageElementType, image: HTMLVideoElement | HTMLCanvasElement | undefined, pixelRatio: number, deps: readonly unknown[]) => readonly [HTMLCanvasElement | HTMLVideoElement | undefined, () => void];
11
13
  type Props = {
12
14
  store: StoreType;
13
15
  element: VideoElementType;
@@ -1 +1 @@
1
- import{jsx as e,jsxs as t,Fragment 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 c}from"../utils/mobx.js";import{Arc as h,Group as l,Image as u,Rect as m,Text as p}from"react-konva";import{ROLES as g}from"../model/store.js";import{DEFAULT_RETRIES as f,isDeterministicUrl as v,retryDelayMs as w}from"@polotno/core/retry";import x from"konva";import{useWorkspaceStyle as E}from"./workspace-style.js";import{incrementLoader as y,triggerLoadError as M}from"../utils/loader.js";import{polotnoError as L}from"@polotno/core/errors";import{getCropRect as C}from"@polotno/core/image";import*as T from"@polotno/core/svg";import{activeAnchorOf as b,roundedCropFraction as k,roundedGeometryPx as I,roundedPosition as R,isCornerAnchor as j,scaledStyleAttrs as S,roundedStyleAttrs as P,transformScale as H}from"../utils/px.js";import{useFilteredSource as A}from"./use-filtered-source.js";import{useOffscreenCanvas as W}from"./use-offscreen-canvas.js";import{useEvent as X}from"../hooks/use-event.js";import{useFadeIn as Y}from"./use-fadein.js";import{useAnimatedBlur as _}from"./use-animated-blur.js";import{isTouchDevice as D}from"../utils/screen.js";import{createPlayGate as V,playMedia as O}from"../utils/media.js";import{useMediabunnyVideo as z}from"./use-mediabunny-video.js";import{getElementTimeRange as F,getVideoRestMs as U}from"../utils/timeline.js";import{drawReduced as Z,exportKernelEnabled as N,shouldResample as q,sourceSize as $}from"./downscale.js";import{trySetCanvasSize as B}from"../utils/canvas.js";import{useClipImage as G}from"./image-element.js";import{CropOverlay as J,CROP_CORNER_ANCHORS as K}from"./crop-overlay.js";const Q=new window.Image;Q.src=T.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 ee=new window.Image;ee.src=T.svgToURL('\n <svg width="800px" height="800px" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">\n <path opacity="0.6" d="M14 19L14 5C14 3.89543 14.8954 3 16 3L17 3C18.1046 3 19 3.89543 19 5L19 19C19 20.1046 18.1046 21 17 21L16 21C14.8954 21 14 20.1046 14 19Z" fill="white"/>\n <path opacity="0.6" d="M10 19L10 5C10 3.89543 9.10457 3 8 3L7 3C5.89543 3 5 3.89543 5 5L5 19C5 20.1046 5.89543 21 7 21L8 21C9.10457 21 10 20.1046 10 19Z" fill="white"/>\n <path d="M14 19L14 5C14 3.89543 14.8954 3 16 3L17 3C18.1046 3 19 3.89543 19 5L19 19C19 20.1046 18.1046 21 17 21L16 21C14.8954 21 14 20.1046 14 19Z" stroke="#323232" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>\n <path d="M10 19L10 5C10 3.89543 9.10457 3 8 3L7 3C5.89543 3 5 3.89543 5 5L5 19C5 20.1046 5.89543 21 7 21L8 21C9.10457 21 10 20.1046 10 19Z" stroke="#323232" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>\n </svg>\n');export const useCornerRadiusAndCrop=(e,t,r,i,n=0,a=!1)=>{var s;const d=Math.floor(Math.max(e.a.width*i,1)),c=Math.floor(Math.max(e.a.height*i,1)),h=Math.min(n*i,d/2,c/2),l=Math.max(e.a.width/r.width,e.a.height/r.height)*i,u=N(e.page)&&!a&&q(l,d,c),{width:m,height:p}=t?$(t):{},g=0===r.x&&0===r.y&&r.width===m&&r.height===p,f=o.useMemo(()=>{if(t&&m&&p){return g&&0===h&&!u?void 0:document.createElement("canvas")}},[t,h,u,g,m,p]),v=()=>{if(!f||!t){return}f.width=d,f.height=c;const e=f.getContext("2d");e&&(h&&(e.beginPath(),e.moveTo(h,0),e.lineTo(d-h,0),e.arc(d-h,h,h,3*Math.PI/2,0,!1),e.lineTo(d,c-h),e.arc(d-h,c-h,h,0,Math.PI/2,!1),e.lineTo(h,c),e.arc(h,c-h,h,Math.PI/2,Math.PI,!1),e.lineTo(0,h),e.arc(h,h,h,Math.PI,3*Math.PI/2,!1),e.clip()),u?Z(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 o.useLayoutEffect(()=>{v()},[f,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,u]),o.useEffect(()=>()=>{f&&"CANVAS"===f.nodeName&&x.Util.releaseCanvas(f)},[f]),[f||t,v]};export const useClip=(e,t,r,i)=>{const[n,a]=G(e.clipSrc||""),s=e.clipSrc?a:"loaded";useLoader(s,e.clipSrc,e.id);const d=!!t&&!!n,c=o.useMemo(()=>d?{canvas:document.createElement("canvas"),mask:document.createElement("canvas"),width:0,height:0}:void 0,[d]),h=null==c?void 0:c.canvas;function l(){if(!c||!h||!t){return}const{width:i,height:o}=$(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));h.width&&c.width===n&&c.height===a||(B(h,n,a),c.width=n,c.height=a);const s=h.getContext("2d");s&&(s.clearRect(0,0,h.width,h.height),s.save(),s.drawImage(t,0,0,h.width,h.height),s.globalCompositeOperation="destination-in",s.drawImage(c.mask,0,0,h.width,h.height),s.restore())}return o.useLayoutEffect(()=>{var t;if(!c||!(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);B(c.mask,Math.min(1e4,Math.max(n.width*i,1)),Math.min(1e4,Math.max(n.height*i,1))),null===(t=c.mask.getContext("2d"))||void 0===t||t.drawImage(n,0,0,c.mask.width,c.mask.height)},[c,n,e.a.width,e.a.height,r]),o.useLayoutEffect(()=>{l()},[c,t,n,e.a.width,e.a.height,r,...i]),o.useEffect(()=>()=>{c&&x.Util.releaseCanvas(c.canvas,c.mask)},[c]),[d?h:t,l]};const te=document.createElement("canvas"),re=s(({element:r})=>{const n=Math.min(30,r.width/4,r.height/4),a=o.useRef(null);o.useEffect(()=>{const e=a.current;if(!e){return}const t=new x.Animation(t=>{e.rotate(((null==t?void 0:t.timeDiff)||0)/2)},e.getLayer());return t.start(),()=>{t.stop()}});const{mediaLoadingStyle:s}=E();return t(l,{x:r.a.x,y:r.a.y,rotation:r.a.rotation,listening:!1,opacity:i(r),hideInExport:!r.showInExport,children:[e(m,{width:r.width,height:r.height,fill:s.fill}),e(h,{ref:a,x:r.width/2,y:r.height/2,fill:s.textFill,outerRadius:Math.abs(n),innerRadius:Math.max(1,n-5),angle:270})]})}),ie=s(({element:r})=>{const{mediaErrorStyle:o}=E(),n=Math.max(10,Math.min(30,r.width/25));return t(l,{x:r.a.x,y:r.a.y,rotation:r.a.rotation,listening:!1,opacity:i(r),hideInExport:!r.showInExport,children:[e(m,{width:r.width,height:r.height,fill:o.fill}),e(p,{text:"Can not load the video...",fontSize:n,width:r.width,height:r.height,align:"center",fill:o.textFill,verticalAlign:"middle",padding:5})]})});let oe=function(e,t,r){const i=o.useRef("loading"),n=o.useRef(void 0),[a,s]=o.useState(0),d=o.useRef(void 0),c=o.useRef(void 0),h=o.useRef(void 0);return d.current===e&&c.current===t&&h.current===r||(i.current="loading",n.current=void 0,d.current=e,c.current=t,h.current=r),o.useLayoutEffect(()=>{if(!e){return}const o=v(e)?1:f;let a,d,c,h=0,l=!1,u=!1;const m=e=>{e&&(e.removeAttribute("src"),e.load())},p=()=>{h+=1;const g=document.createElement("video");function f(){l||(g.removeEventListener("canplay",f),u=!0,i.current="loaded",n.current=g,g.currentTime=0,s(Math.random()))}function v(e){var t;const r=4===g.readyState,c=g.buffered&&g.buffered.length>0&&g.buffered.end(g.buffered.length-1)/g.duration*100>=100;if(r&&c){return}if(l){return}if(!u&&h<o){return null==d||d(),m(g),void(a=setTimeout(p,w(h)))}const f=e.message||(null===(t=g.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())}c=g,g.addEventListener("canplay",f),g.addEventListener("error",v),d=()=>{g.removeEventListener("canplay",f),g.removeEventListener("error",v)},t&&(g.crossOrigin=t),r&&(g.referrerPolicy=r),g.src=e,g.load()};return p(),()=>{l=!0,clearTimeout(a),null==d||d(),u||m(c)}},[e,t,r]),[n.current,i.current]};export const setVideoLoaderHook=e=>{oe=e};function ne(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=y(a)),"loading"!==e&&n(),"failed"===e&&M(L("VIDEO_FAILED",a,{src:o,elementId:r,reason:"load"}))},[e])};export const VideoElement=s(({element:s,store:h})=>{var p,f,v,w,E;const[M,L]=o.useState(!1),T=o.useRef(null),Z=D(),[N,q]=o.useState(!1),[B,G]=oe(s.src,"anonymous"),[ae,se]=o.useState(!1),de=h.activePage===s.page,ce=(null===(p=s.page)||void 0===p?void 0:p._exportingOrRendering)&&"loaded"===G,he=z(s,h,ce);useLoader(G,s.src,s.id),B&&(B.playsInline=!0);const le=ce&&he||B,[ue,me]=((e,t)=>{const{flipX:r,flipY:i}=e,{width:o,height:n}=t?$(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=W((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)}]})(s,le),[pe=te,ge]=A(s,ue||te);o.useEffect(()=>{B&&h.history.ignore(()=>{s.set({duration:1e3*B.duration})})},[B]);const fe=o.useMemo(V,[B]);o.useEffect(()=>{var e;if(!B){return}const t=h.animatedElementsIds,r=(!t.length||t.includes(s.id))&&h.isPlaying;if(!de||!r&&!N){return void B.pause()}N&&(B.muted=!1,B.currentTime=s.startTime*B.duration,O(B).then(e=>{"refused"===e&&q(!1)}));const i=new x.Animation(()=>{Xe()},null===(e=T.current)||void 0===e?void 0:e.getLayer());i.start();const o=()=>{q(!1),B.currentTime=s.startTime*B.duration},n=()=>{B.currentTime>=s.endTime*B.duration&&(B.pause(),B.currentTime=s.startTime*B.duration,q(!1))};return B.addEventListener("ended",o),B.addEventListener("timeupdate",n),()=>{B.pause(),i.stop(),B.removeEventListener("ended",o),B.removeEventListener("timeupdate",n)}},[B,N,h.isPlaying,de]),o.useEffect(()=>{B&&(B.volume=s.volume)},[B,s.volume]),o.useEffect(()=>{B&&(B.playbackRate=s.speed,B.preservesPitch=!1)},[B,s.speed]);const ve=o.useRef(null);o.useEffect(()=>{const e=c(s,()=>{var e,t;if(B){if(ce&&he){return Xe(),void h.currentTime}const r=h.animatedElementsIds;if(r.length&&!r.includes(s.id)){return}const i=h.activePage===s.page,o=h.currentTime>=s.page.startTime&&h.currentTime<s.page.startTime+s.page.duration,n=s.startTime*B.duration*1e3,a=B.duration*(s.endTime-s.startTime)*1e3,{start:d,end:c}=F(s.animations,s.page.duration),l=(h.currentTime||s.page.startTime)-s.page.startTime,u=o?U(h.currentTime,s.page.startTime,d,a,n,s.speed):0,m=u/1e3,p=o&&l>=d&&l<c;N||(B.muted=!p,p&&h.isPlaying&&i?B.paused?(B.currentTime=m,fe.play(B)):Math.abs(1e3*B.currentTime-u)>500&&(B.currentTime=m):(fe.reset(),B.paused||B.pause(),m!==B.currentTime&&(B.currentTime=m),!ne(B)&&!h.isPlaying&&!ve.current&&(ve.current=y(`video ${s.id}`)))),Xe(),null===(t=null===(e=T.current)||void 0===e?void 0:e.getLayer())||void 0===t||t.batchDraw()}});return()=>{e(),ve.current&&(ve.current(),ve.current=null)}},[h,B,ce,he,N]),o.useEffect(()=>{var e,t;if(!B){return}if(ce){return null===(e=ve.current)||void 0===e||e.call(ve),void(ve.current=null)}const r=()=>{var e;null===(e=ve.current)||void 0===e||e.call(ve),ve.current=null},i=()=>{ne(B)&&(Xe(),r())};let o,n;(null===(t=s.page)||void 0===t?void 0:t._exportingOrRendering)&&(o=setInterval(i,20)),B.addEventListener("timeupdate",i),B.addEventListener("canplay",i),B.addEventListener("seeked",i);const a=()=>{B.paused&&(Xe(),ne(B)&&r()),n=B.requestVideoFrameCallback(a)};return"requestVideoFrameCallback"in B&&(n=B.requestVideoFrameCallback(a)),()=>{clearInterval(o),void 0!==n&&B.cancelVideoFrameCallback(n),B.removeEventListener("timeupdate",i),B.removeEventListener("canplay",i),B.removeEventListener("seeked",i)}},[null===(f=s.page)||void 0===f?void 0:f._exportingOrRendering,B,s.id,y,ce]);let{cropX:we,cropY:xe,cropWidth:Ee,cropHeight:ye}=s.a;"loaded"!==G&&(we=xe=0,Ee=ye=1);const{width:Me,height:Le}=$(pe),Ce=null!==(v=null==B?void 0:B.videoWidth)&&void 0!==v?v:0,Te=null!==(w=null==B?void 0:B.videoHeight)&&void 0!==w?w:0;o.useLayoutEffect(()=>{"loaded"===G&&Ce>0&&Te>0&&s._setSourceSize({width:Ce,height:Te},s.src)},[s,s.src,G,Ce,Te]);const be=C({stretchEnabled:s.stretchEnabled,cropX:we,cropY:xe,cropWidth:Ee,cropHeight:ye,width:s.a.width,height:s.a.height},{width:Me,height:Le}),ke=be.width,Ie=be.height,Re=s.stretchEnabled,je=null!==(E=s.cornerRadius)&&void 0!==E?E:0,[Se,Pe]=useCornerRadiusAndCrop(s,pe,be,h._elementsPixelRatio,je,!0);let[He,Ae]=useClip(s,Se,h._elementsPixelRatio,[be,je,h._elementsPixelRatio]);const We=_(T,s,He),Xe=X(()=>{var e,t;me(),ge(),Pe(),Ae(),We(),null===(t=null===(e=T.current)||void 0===e?void 0:e.getLayer())||void 0===t||t.batchDraw()});o.useEffect(()=>{Xe()});const Ye=()=>{s._cropEnabled&&setTimeout(()=>{d(s)&&s.toggleCropMode(!0)})},_e="loading"===G,De="failed"===G,Ve=!_e&&!De,Oe=o.useRef({cropX:0,cropY:0,cropWidth:0,cropHeight:0}),ze=o.useRef(!1),Fe=Ve?i(s):0;Y(T,Fe);const Ue=s.selectable||h.role===g.ADMIN;return e(r,{children:t(l,{onMouseEnter:()=>se(!0),onMouseLeave:()=>se(!1),children:[_e&&e(re,{element:s}),De&&e(ie,{element:s}),e(u,Object.assign({ref:T,name:"element",id:s.id,image:He,x:s.a.x,y:s.a.y,width:s.a.width||1,height:s.a.height||1,rotation:s.a.rotation,opacity:Fe},a(s),{customCrop:be,listening:Ue,draggable:Z?s.draggable&&s.isSelected:s.draggable,preventDefault:!Z||s.isSelected,hideInExport:!s.showInExport,onDragMove:e=>{s.set({x:e.target.x(),y:e.target.y()})},onDragEnd:e=>{s.set(R(e.target))},onDblClick:Ye,onDblTap:Ye,onTransformStart:e=>{L(!0),ze.current=j(b(e.target)),Oe.current={cropX:s.cropX,cropY:s.cropY,cropWidth:s.cropWidth,cropHeight:s.cropHeight}},onTransform:e=>{const t=e.currentTarget,r=H(t.scaleX()),i=H(t.scaleY());t.scaleX(1),t.scaleY(1);const o=1-ke/Me,n=Math.min(o,Math.max(0,s.cropX)),a=1-Ie/Le,d=Math.min(a,Math.max(0,s.cropY)),c=ze.current,h=!c&&r<1&&Oe.current.cropHeight>Ie/Le;let l=c?s.cropWidth:s.cropWidth*r;h&&(l=s.cropWidth);const u=!c&&i<1&&Oe.current.cropWidth>ke/Me;let m=c?s.cropHeight:s.cropHeight*i;u&&(m=s.cropHeight),Re&&(l=s.cropWidth,m=s.cropHeight);const p=c?Math.min(r,i):1;s.set(Object.assign({cropX:n,cropY:d,x:t.x(),y:t.y(),width:t.width()*r,height:t.height()*i,rotation:e.target.rotation(),cropWidth:Math.min(l,1-n),cropHeight:Math.min(m,1-d)},1!==p&&S(s,p)))},onTransformEnd:e=>{const t=e.currentTarget;s.set(Object.assign({width:I(t.width()),height:I(t.height()),x:I(t.x()),y:I(t.y()),rotation:I(e.target.rotation()),cropX:k(s.cropX),cropY:k(s.cropY),cropWidth:k(ke/Me),cropHeight:k(Ie/Le)},P(s))),L(!1)}})),!!s.borderSize&&e(m,{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:Fe,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,je-s.borderSize),hideInExport:!s.showInExport}),!h.isPlaying&&e(u,{image:N?ae||Z?ee:void 0:Q,x:s.a.x,y:s.a.y,offsetX:-s.a.width/2+15/h.scale,offsetY:-s.a.height/2+15/h.scale,rotation:s.a.rotation,width:30/h.scale,height:30/h.scale,hideInExport:!0,onClick:()=>q(!N),onTap:()=>q(!N)}),s._cropModeEnabled&&"loaded"===G&&e(J,{element:s,store:h,previewImage:He,sourceImage:pe,sourceWidth:Me,sourceHeight:Le,cropAbsoluteWidth:ke,cropAbsoluteHeight:Ie,innerAnchors:K})]})})});
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 c}from"../utils/mobx.js";import{Group as h,Image as l,Rect as u}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 M}from"../utils/loader.js";import{polotnoError as L}from"@polotno/core/errors";import{getCropRect as y}from"@polotno/core/image";import*as C from"@polotno/core/svg";import{activeAnchorOf as b,roundedCropFraction as T,roundedGeometryPx as k,roundedPosition as j,isCornerAnchor as R,scaledStyleAttrs as I,roundedStyleAttrs as S,transformScale as P}from"../utils/px.js";import{useFilteredSource as H}from"./use-filtered-source.js";import{useOffscreenCanvas as W}from"./use-offscreen-canvas.js";import{useEvent as _}from"../hooks/use-event.js";import{useFadeIn as A}from"./use-fadein.js";import{useAnimatedBlur as X}from"./use-animated-blur.js";import{isTouchDevice as Y}from"../utils/screen.js";import{createPlayGate as V,playMedia as D}from"../utils/media.js";import{useMediabunnyVideo as O}from"./use-mediabunny-video.js";import{getElementTimeRange as F,getVideoRestMs as z,isHeldByPreview as U}from"../utils/timeline.js";import{drawReduced as Z,exportKernelEnabled as N,shouldResample as q,sourceSize as $}from"./downscale.js";import{trySetCanvasSize as B}from"../utils/canvas.js";import{useClipImage as G}from"./image-element.js";import{CropOverlay as J,CROP_CORNER_ANCHORS as K}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 ee=new window.Image;ee.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?$(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=W((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)),c=Math.floor(Math.max(e.a.height*o,1)),h=Math.min(n*o,d/2,c/2),l=Math.max(e.a.width/r.width,e.a.height/r.height)*o,u=N(e.page)&&!a&&q(l,d,c),{width:m,height:p}=t?$(t):{},g=0===r.x&&0===r.y&&r.width===m&&r.height===p,f=i.useMemo(()=>{if(t&&m&&p){return g&&0===h&&!u?void 0:document.createElement("canvas")}},[t,h,u,g,m,p]),w=()=>{if(!f||!t){return}f.width=d,f.height=c;const e=f.getContext("2d");e&&(h&&(e.beginPath(),e.moveTo(h,0),e.lineTo(d-h,0),e.arc(d-h,h,h,3*Math.PI/2,0,!1),e.lineTo(d,c-h),e.arc(d-h,c-h,h,0,Math.PI/2,!1),e.lineTo(h,c),e.arc(h,c-h,h,Math.PI/2,Math.PI,!1),e.lineTo(0,h),e.arc(h,h,h,Math.PI,3*Math.PI/2,!1),e.clip()),u?Z(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,u]),i.useEffect(()=>()=>{f&&"CANVAS"===f.nodeName&&v.Util.releaseCanvas(f)},[f]),[f||t,w]};export const useClip=(e,t,r,o)=>{const[n,a]=G(e.clipSrc||""),s=e.clipSrc?a:"loaded";useLoader(s,e.clipSrc,e.id);const d=!!t&&!!n,c=i.useMemo(()=>d?{canvas:document.createElement("canvas"),mask:document.createElement("canvas"),width:0,height:0}:void 0,[d]),h=null==c?void 0:c.canvas;function l(){if(!c||!h||!t){return}const{width:o,height:i}=$(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));h.width&&c.width===n&&c.height===a||(B(h,n,a),c.width=n,c.height=a);const s=h.getContext("2d");s&&(s.clearRect(0,0,h.width,h.height),s.save(),s.drawImage(t,0,0,h.width,h.height),s.globalCompositeOperation="destination-in",s.drawImage(c.mask,0,0,h.width,h.height),s.restore())}return i.useLayoutEffect(()=>{var t;if(!c||!(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);B(c.mask,Math.min(1e4,Math.max(n.width*o,1)),Math.min(1e4,Math.max(n.height*o,1))),null===(t=c.mask.getContext("2d"))||void 0===t||t.drawImage(n,0,0,c.mask.width,c.mask.height)},[c,n,e.a.width,e.a.height,r]),i.useLayoutEffect(()=>{l()},[c,t,n,e.a.width,e.a.height,r,...o]),i.useEffect(()=>()=>{c&&v.Util.releaseCanvas(c.canvas,c.mask)},[c]),[d?h:t,l]};const te=document.createElement("canvas");let re=function(e,t,r){const o=i.useRef("loading"),n=i.useRef(void 0),[a,s]=i.useState(0),d=i.useRef(void 0),c=i.useRef(void 0),h=i.useRef(void 0);return d.current===e&&c.current===t&&h.current===r||(o.current="loading",n.current=void 0,d.current=e,c.current=t,h.current=r),i.useLayoutEffect(()=>{if(!e){return}const i=g(e)?1:p;let a,d,c,h=0,l=!1,u=!1;const m=e=>{e&&(e.removeAttribute("src"),e.load())},v=()=>{h+=1;const p=document.createElement("video");function g(){l||(p.removeEventListener("canplay",g),u=!0,o.current="loaded",n.current=p,p.currentTime=0,s(Math.random()))}function w(e){var t;const r=4===p.readyState,c=p.buffered&&p.buffered.length>0&&p.buffered.end(p.buffered.length-1)/p.duration*100>=100;if(r&&c){return}if(l){return}if(!u&&h<i){return null==d||d(),m(p),void(a=setTimeout(v,f(h)))}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())}c=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(),()=>{l=!0,clearTimeout(a),null==d||d(),u||m(c)}},[e,t,r]),[n.current,o.current]};export const setVideoLoaderHook=e=>{re=e};function oe(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&&M(L("VIDEO_FAILED",a,{src:i,elementId:r,reason:"load"}))},[e])};export const VideoElement=s(({element:s,store:p})=>{var g,f,M,L,C;const[W,Z]=i.useState(!1),N=i.useRef(null),q=Y(),[B,G]=i.useState(!1),[ie,ne]=re(s.src,"anonymous"),[ae,se]=i.useState(!1),de=p.activePage===s.page,ce=(null===(g=s.page)||void 0===g?void 0:g._exportingOrRendering)&&"loaded"===ne,he=O(s,p,ce);useLoader(ne,s.src,s.id),ie&&(ie.playsInline=!0);const le=ce&&he||ie,[ue,me]=useFlip(s,le),[pe=te,ge]=H(s,ue||te);i.useEffect(()=>{ie&&p.history.ignore(()=>{s.set({duration:1e3*ie.duration})})},[ie]);const fe=i.useMemo(V,[ie]);i.useEffect(()=>{var e;if(!ie){return}const t=!U(s)&&p.isPlaying;if(!de||!t&&!B){return void ie.pause()}B&&(ie.muted=!1,ie.currentTime=s.startTime*ie.duration,D(ie).then(e=>{"refused"===e&&G(!1)}));const r=new v.Animation(()=>{Ae()},null===(e=N.current)||void 0===e?void 0:e.getLayer());r.start();const o=()=>{G(!1),ie.currentTime=s.startTime*ie.duration},i=()=>{ie.currentTime>=s.endTime*ie.duration&&(ie.pause(),ie.currentTime=s.startTime*ie.duration,G(!1))};return ie.addEventListener("ended",o),ie.addEventListener("timeupdate",i),()=>{ie.pause(),r.stop(),ie.removeEventListener("ended",o),ie.removeEventListener("timeupdate",i)}},[ie,B,p.isPlaying,de]),i.useEffect(()=>{ie&&(ie.volume=s.volume)},[ie,s.volume]),i.useEffect(()=>{ie&&(ie.playbackRate=s.speed,ie.preservesPitch=!1)},[ie,s.speed]);const ve=i.useRef(null);i.useEffect(()=>{const e=c(s,()=>{var e,t;if(ie){if(ce&&he){return Ae(),void p.currentTime}if(U(s)){return}const r=p.activePage===s.page,o=s.page._mediaLocalTime,i=s.startTime*ie.duration*1e3,n=ie.duration*(s.endTime-s.startTime)*1e3,{start:a,end:d}=F(s.animations,s.page.duration),c=z(null!=o?o:0,0,a,n,i,s.speed,{windowEnd:d,frameMs:p._renderFrameMs,renderEnd:p._renderEndMs-s.page.startTime}),h=c/1e3,l=null!==o&&o>=a&&o<d;B||(ie.muted=!l,l&&p.isPlaying&&r?ie.paused?(ie.currentTime=h,fe.play(ie)):Math.abs(1e3*ie.currentTime-c)>500&&(ie.currentTime=h):(fe.reset(),ie.paused||ie.pause(),h!==ie.currentTime&&(ie.currentTime=h),!oe(ie)&&!p.isPlaying&&!ve.current&&(ve.current=E(`video ${s.id}`)))),Ae(),null===(t=null===(e=N.current)||void 0===e?void 0:e.getLayer())||void 0===t||t.batchDraw()}});return()=>{e(),ve.current&&(ve.current(),ve.current=null)}},[p,ie,ce,he,B]),i.useEffect(()=>{var e,t;if(!ie){return}if(ce){return null===(e=ve.current)||void 0===e||e.call(ve),void(ve.current=null)}const r=()=>{var e;null===(e=ve.current)||void 0===e||e.call(ve),ve.current=null},o=()=>{oe(ie)&&(Ae(),r())};let i,n;(null===(t=s.page)||void 0===t?void 0:t._exportingOrRendering)&&(i=setInterval(o,20)),ie.addEventListener("timeupdate",o),ie.addEventListener("canplay",o),ie.addEventListener("seeked",o);const a=()=>{ie.paused&&(Ae(),oe(ie)&&r()),n=ie.requestVideoFrameCallback(a)};return"requestVideoFrameCallback"in ie&&(n=ie.requestVideoFrameCallback(a)),()=>{clearInterval(i),void 0!==n&&ie.cancelVideoFrameCallback(n),ie.removeEventListener("timeupdate",o),ie.removeEventListener("canplay",o),ie.removeEventListener("seeked",o)}},[null===(f=s.page)||void 0===f?void 0:f._exportingOrRendering,ie,s.id,E,ce]);let{cropX:we,cropY:xe,cropWidth:Ee,cropHeight:Me}=s.a;"loaded"!==ne&&(we=xe=0,Ee=Me=1);const{width:Le,height:ye}=$(pe),Ce=null!==(M=null==ie?void 0:ie.videoWidth)&&void 0!==M?M:0,be=null!==(L=null==ie?void 0:ie.videoHeight)&&void 0!==L?L:0;i.useLayoutEffect(()=>{"loaded"===ne&&Ce>0&&be>0&&s._setSourceSize({width:Ce,height:be},s.src)},[s,s.src,ne,Ce,be]);const Te=y({stretchEnabled:s.stretchEnabled,cropX:we,cropY:xe,cropWidth:Ee,cropHeight:Me,width:s.a.width,height:s.a.height},{width:Le,height:ye}),ke=Te.width,je=Te.height,Re=s.stretchEnabled,Ie=null!==(C=s.cornerRadius)&&void 0!==C?C:0,[Se,Pe]=useCornerRadiusAndCrop(s,pe,Te,p._elementsPixelRatio,Ie,!0);let[He,We]=useClip(s,Se,p._elementsPixelRatio,[Te,Ie,p._elementsPixelRatio]);const _e=X(N,s,He),Ae=_(()=>{var e,t;me(),ge(),Pe(),We(),_e(),null===(t=null===(e=N.current)||void 0===e?void 0:e.getLayer())||void 0===t||t.batchDraw()});i.useEffect(()=>{Ae()});const Xe=()=>{s._cropEnabled&&setTimeout(()=>{d(s)&&s.toggleCropMode(!0)})},Ye="loading"===ne,Ve="failed"===ne,De=!Ye&&!Ve,Oe=i.useRef({cropX:0,cropY:0,cropWidth:0,cropHeight:0}),Fe=i.useRef(!1),ze=De?o(s):0;A(N,ze);const Ue=s.selectable||p.role===m.ADMIN;return t(e,{children:r(h,{onMouseEnter:()=>se(!0),onMouseLeave:()=>se(!1),children:[Ye&&t(x,{element:s}),Ve&&t(w,{element:s,text:"Can not load the video..."}),t(l,Object.assign({ref:N,name:"element",id:s.id,image:He,x:s.a.x,y:s.a.y,width:s.a.width||1,height:s.a.height||1,rotation:s.a.rotation,opacity:ze},a(s),{customCrop:Te,listening:Ue,draggable:q?s.draggable&&s.isSelected:s.draggable,preventDefault:!q||s.isSelected,hideInExport:!s.showInExport,onDragMove:e=>{s.set({x:e.target.x(),y:e.target.y()})},onDragEnd:e=>{s.set(j(e.target))},onDblClick:Xe,onDblTap:Xe,onTransformStart:e=>{Z(!0),Fe.current=R(b(e.target)),Oe.current={cropX:s.cropX,cropY:s.cropY,cropWidth:s.cropWidth,cropHeight:s.cropHeight}},onTransform:e=>{const t=e.currentTarget,r=P(t.scaleX()),o=P(t.scaleY());t.scaleX(1),t.scaleY(1);const i=1-ke/Le,n=Math.min(i,Math.max(0,s.cropX)),a=1-je/ye,d=Math.min(a,Math.max(0,s.cropY)),c=Fe.current,h=!c&&r<1&&Oe.current.cropHeight>je/ye;let l=c?s.cropWidth:s.cropWidth*r;h&&(l=s.cropWidth);const u=!c&&o<1&&Oe.current.cropWidth>ke/Le;let m=c?s.cropHeight:s.cropHeight*o;u&&(m=s.cropHeight),Re&&(l=s.cropWidth,m=s.cropHeight);const p=c?Math.min(r,o):1;s.set(Object.assign({cropX:n,cropY:d,x:t.x(),y:t.y(),width:t.width()*r,height:t.height()*o,rotation:e.target.rotation(),cropWidth:Math.min(l,1-n),cropHeight:Math.min(m,1-d)},1!==p&&I(s,p)))},onTransformEnd:e=>{const t=e.currentTarget;s.set(Object.assign({width:k(t.width()),height:k(t.height()),x:k(t.x()),y:k(t.y()),rotation:k(e.target.rotation()),cropX:T(s.cropX),cropY:T(s.cropY),cropWidth:T(ke/Le),cropHeight:T(je/ye)},S(s))),Z(!1)}})),!!s.borderSize&&t(u,{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:ze,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,Ie-s.borderSize),hideInExport:!s.showInExport}),!p.isPlaying&&t(l,{image:B?ae||q?ee: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:()=>G(!B),onTap:()=>G(!B)}),s._cropModeEnabled&&"loaded"===ne&&t(J,{element:s,store:p,previewImage:He,sourceImage:pe,sourceWidth:Le,sourceHeight:ye,cropAbsoluteWidth:ke,cropAbsoluteHeight:je,innerAnchors:K})]})})});
@@ -18,6 +18,7 @@ export declare const WordFadeIcon: (props: IconProps) => React.JSX.Element;
18
18
  export declare const LetterPopIcon: (props: IconProps) => React.JSX.Element;
19
19
  export declare const WordBlurIcon: (props: IconProps) => React.JSX.Element;
20
20
  export declare const LineWipeIcon: (props: IconProps) => React.JSX.Element;
21
+ export declare const LinePeekIcon: (props: IconProps) => React.JSX.Element;
21
22
  export declare const LetterWaveIcon: (props: IconProps) => React.JSX.Element;
22
23
  export declare const RotateIcon: (props: IconProps) => React.JSX.Element;
23
24
  export declare const BlinkIcon: (props: IconProps) => React.JSX.Element;
@@ -1 +1 @@
1
- var t=this&&this.__rest||function(t,c){var e={};for(var i in t){Object.prototype.hasOwnProperty.call(t,i)&&c.indexOf(i)<0&&(e[i]=t[i])}if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(t);r<i.length;r++){c.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(t,i[r])&&(e[i[r]]=t[i[r]])}}return e};import{jsx as c,Fragment as e,jsxs as i}from"react/jsx-runtime";import r from"react";const o=t=>c("svg",Object.assign({width:"48",height:"48",viewBox:"0 0 48 48",fill:"none",xmlns:"http://www.w3.org/2000/svg",style:{margin:0,overflow:"visible"}},t)),s="currentColor",n=()=>r.useId().replace(/[^a-zA-Z0-9_-]/g,""),a=e=>{var{x:i,y:r,size:o,opacity:n=1}=e,a=t(e,["x","y","size","opacity"]);return c("rect",Object.assign({x:i,y:r,width:o,height:o,rx:.24*o,fill:s,fillOpacity:n},a))},y=e=>{var{cx:i,cy:r,r:o,opacity:n=1}=e,a=t(e,["cx","cy","r","opacity"]);return c("circle",Object.assign({cx:i,cy:r,r:o,fill:s,fillOpacity:n},a))},h=e=>{var{d:i,opacity:r=.7,width:o=2}=e,n=t(e,["d","opacity","width"]);return c("path",Object.assign({d:i,stroke:s,strokeOpacity:r,strokeWidth:o,strokeLinecap:"round",strokeLinejoin:"round"},n))},l=e=>{var{opacity:i=.35}=e,r=t(e,["opacity"]);return c("rect",Object.assign({stroke:s,strokeOpacity:i,strokeWidth:1.6,strokeDasharray:"2.5 2.5"},r))},x={A:"M0 12 L4.5 0 L9 12 M1.8 7.6 H7.2",B:"M0.6 12 V0 H4.5 C6.6 0 7.8 1.2 7.8 3 C7.8 4.7 6.6 5.8 4.5 5.8 H0.6 M4.5 5.8 C7.2 5.8 8.6 7 8.6 8.9 C8.6 10.8 7.2 12 4.9 12 H0.6",C:"M8.7 2.4 C7.9 0.9 6.5 0 4.8 0 C2.1 0 0.2 2.6 0.2 6 C0.2 9.4 2.1 12 4.8 12 C6.5 12 7.9 11.1 8.7 9.6",D:"M0.6 12 V0 H3.9 C7 0 8.9 2.4 8.9 6 C8.9 9.6 7 12 3.9 12 Z",0:"M4.5 0 C7 0 8.6 2.7 8.6 6 C8.6 9.3 7 12 4.5 12 C2 12 0.4 9.3 0.4 6 C0.4 2.7 2 0 4.5 0 Z",1:"M1.6 2.6 L5 0 V12",2:"M0.6 3 C1.1 1.1 2.6 0 4.5 0 C6.7 0 8.2 1.4 8.2 3.4 C8.2 5.6 6.3 7.1 0.6 12 H8.6"},d=({ch:t,x:e,y:i,scale:r=1,opacity:o=1})=>c("path",{d:x[t],transform:`translate(${e} ${i}) scale(${r})`,stroke:s,strokeOpacity:o,strokeWidth:2.4/r,strokeLinecap:"round",strokeLinejoin:"round"}),p=({text:t,x:i,y:r,scale:o=1,opacity:s=1})=>c(e,{children:[...t].map((t,e)=>c(d,{ch:t,x:i+12*e*o,y:r,scale:o,opacity:s},e))});export const NoneIcon=t=>i(o,Object.assign({},t,{children:[c("rect",{x:12,y:12,width:24,height:24,rx:6,stroke:s,strokeOpacity:.45,strokeWidth:2,strokeDasharray:"3 3.2"}),c(h,{d:"M15 33 L33 15",opacity:.75})]}));export const FadeIcon=t=>{const e=n();return i(o,Object.assign({},t,{children:[c("defs",{children:i("linearGradient",{id:e,x1:"0",x2:"1",y1:"0",y2:"0",children:[c("stop",{offset:"0",stopColor:s,stopOpacity:.04}),c("stop",{offset:"1",stopColor:s,stopOpacity:1})]})}),c("rect",{x:12,y:12,width:24,height:24,rx:6,fill:`url(#${e})`}),c("rect",{x:12,y:12,width:24,height:24,rx:6,stroke:s,strokeOpacity:.3,strokeWidth:1.5,strokeDasharray:"2 3"})]}))};export const MoveIcon=t=>i(o,Object.assign({},t,{children:[c(a,{x:9,y:15,size:18,opacity:.14}),c(a,{x:15,y:15,size:18,opacity:.32}),c(a,{x:23,y:15,size:18}),c(h,{d:"M2 19.5 H6.5 M2 28.5 H6.5",opacity:.55})]}));export const ZoomIcon=t=>i(o,Object.assign({},t,{children:[c(a,{x:15,y:15,size:18}),c(h,{d:"M12 12 L6.5 6.5 M6.5 11 V6.5 H11 M36 12 L41.5 6.5 M37 6.5 H41.5 V11 M36 36 L41.5 41.5 M41.5 37 V41.5 H37 M12 36 L6.5 41.5 M11 41.5 H6.5 V37"})]}));export const PopIcon=t=>i(o,Object.assign({},t,{children:[c(l,{x:10.5,y:10.5,width:27,height:27,rx:7}),c(a,{x:15,y:15,size:18}),c(h,{d:"M40 8 L43.5 4.5 M42 13 H46 M35 6 V2",opacity:.65})]}));export const RiseIcon=t=>i(o,Object.assign({},t,{children:[c(a,{x:15,y:22,size:18,opacity:.14}),c(a,{x:15,y:15.5,size:18,opacity:.32}),c(a,{x:15,y:8,size:18}),c(h,{d:"M20 42 V46 M28 42 V46",opacity:.55})]}));export const GrowTurnIcon=t=>i(o,Object.assign({},t,{children:[c("rect",{x:7,y:27,width:11,height:11,rx:2.6,fill:s,fillOpacity:.18,transform:"rotate(-40 12.5 32.5)"}),c(a,{x:21,y:9,size:19}),c(h,{d:"M8 22 C8 14.5 11.5 9.5 17 7.5 M13.6 5.7 L17 7.5 L15.3 10.9",opacity:.65})]}));export const FlipIcon=t=>i(o,Object.assign({},t,{children:[c(h,{d:"M24 4 V44",opacity:.3,width:1.5,strokeDasharray:"2 3"}),c(l,{x:13,y:14,width:22,height:22,rx:5,opacity:.3}),c("rect",{x:19,y:14,width:10,height:22,rx:3,fill:s}),c(h,{d:"M14 9 C19.5 5.5 28.5 5.5 34 9 M30.6 6.2 L34 9 L30.2 10.6",opacity:.65})]}));export const WipeIcon=t=>{const e=n();return i(o,Object.assign({},t,{children:[c("defs",{children:c("clipPath",{id:e,children:c("rect",{width:27,height:48})})}),c(a,{x:13,y:13,size:22,opacity:.16}),c("g",{clipPath:`url(#${e})`,children:c(a,{x:13,y:13,size:22})}),c(h,{d:"M27 7 V41",opacity:1,width:2.2}),c(h,{d:"M31 24 H37 M34.5 21.2 L37.3 24 L34.5 26.8",opacity:.65})]}))};export const BlurIcon=t=>{const e=n();return i(o,Object.assign({},t,{children:[c("defs",{children:c("filter",{id:e,x:"-50%",y:"-50%",width:"200%",height:"200%",children:c("feGaussianBlur",{stdDeviation:2.6})})}),c(a,{x:16,y:16,size:16,filter:`url(#${e})`}),c(h,{d:"M9 16 V9 H16 M32 9 H39 V16 M39 32 V39 H32 M16 39 H9 V32"})]}))};export const CountIcon=t=>{const e=n();return i(o,Object.assign({},t,{children:[c("defs",{children:c("clipPath",{id:e,children:c("rect",{x:9,y:13,width:30,height:22,rx:5})})}),c("rect",{x:8,y:12,width:32,height:24,rx:6,stroke:s,strokeOpacity:.35,strokeWidth:1.8}),i("g",{clipPath:`url(#${e})`,children:[c(d,{ch:"0",x:14,y:5.5,opacity:.25}),c(d,{ch:"1",x:25,y:5.5,opacity:.25}),c(d,{ch:"1",x:14,y:20.5}),c(d,{ch:"2",x:25,y:20.5})]})]}))};export const TypewriterIcon=t=>i(o,Object.assign({},t,{children:[c(d,{ch:"A",x:5,y:18}),c(d,{ch:"B",x:17,y:18}),c(h,{d:"M30.5 14.5 V33.5",opacity:1,width:2.4}),c(d,{ch:"C",x:34,y:18,opacity:.2})]}));export const LineRiseIcon=t=>i(o,Object.assign({},t,{children:[c(p,{text:"ABC",x:10.5,y:9,scale:.75}),c(p,{text:"ABC",x:10.5,y:30,scale:.75,opacity:.28}),c(h,{d:"M42 37 V30.5 M39.6 32.8 L42 30.4 L44.4 32.8",opacity:.6})]}));export const WordRiseIcon=t=>i(o,Object.assign({},t,{children:[c(p,{text:"AB",x:3.5,y:17,scale:.85}),c(p,{text:"CD",x:27,y:24,scale:.85,opacity:.3})]}));export const WordFadeIcon=t=>i(o,Object.assign({},t,{children:[c(p,{text:"AB",x:3.5,y:19,scale:.85}),c(p,{text:"CD",x:27,y:19,scale:.85,opacity:.22})]}));export const LetterPopIcon=t=>i(o,Object.assign({},t,{children:[c(d,{ch:"A",x:6,y:24,scale:.5,opacity:.25}),c(d,{ch:"B",x:15,y:21,scale:.75,opacity:.5}),c(d,{ch:"C",x:28,y:18}),c(h,{d:"M39.5 14.5 L42.5 11.5 M41.5 20 H45 M34.5 12.5 V9",opacity:.6})]}));export const WordBlurIcon=t=>{const e=n();return i(o,Object.assign({},t,{children:[c("defs",{children:c("filter",{id:e,x:"-50%",y:"-50%",width:"200%",height:"200%",children:c("feGaussianBlur",{stdDeviation:1.3})})}),c(p,{text:"AB",x:3.5,y:19,scale:.85}),c("g",{filter:`url(#${e})`,children:c(p,{text:"CD",x:27,y:19,scale:.85,opacity:.75})})]}))};export const LineWipeIcon=t=>{const e=n();return i(o,Object.assign({},t,{children:[c("defs",{children:c("clipPath",{id:e,children:c("rect",{y:20,width:32,height:28})})}),c(p,{text:"ABC",x:10.5,y:10,scale:.75}),c(p,{text:"ABC",x:10.5,y:28,scale:.75,opacity:.16}),c("g",{clipPath:`url(#${e})`,children:c(p,{text:"ABC",x:10.5,y:28,scale:.75})}),c(h,{d:"M32 25 V42",opacity:1,width:2.2})]}))};export const LetterWaveIcon=t=>i(o,Object.assign({},t,{children:[c(d,{ch:"A",x:7.5,y:20}),c(d,{ch:"B",x:19.5,y:13}),c(d,{ch:"C",x:31.5,y:20}),c(h,{d:"M6 39 C10 35.5 14 35.5 18 39 S26 42.5 30 39 S38 35.5 42 39",opacity:.35})]}));export const RotateIcon=t=>i(o,Object.assign({},t,{children:[c(y,{cx:24,cy:24,r:9}),c(h,{d:"M9.5 19.5 A15.5 15.5 0 0 1 22 8.6 M18.6 6.6 L22 8.6 L19 11.4",opacity:.65}),c(h,{d:"M38.5 28.5 A15.5 15.5 0 0 1 26 39.4 M29.4 41.4 L26 39.4 L29 36.6",opacity:.65})]}));export const BlinkIcon=t=>i(o,Object.assign({},t,{children:[c(y,{cx:15.5,cy:24,r:8.5}),c("circle",{cx:32.5,cy:24,r:8,stroke:s,strokeOpacity:.45,strokeWidth:1.8,strokeDasharray:"2.5 2.5"})]}));export const PulseIcon=t=>i(o,Object.assign({},t,{children:[c("circle",{cx:24,cy:24,r:16.5,stroke:s,strokeOpacity:.16,strokeWidth:2}),c("circle",{cx:24,cy:24,r:12,stroke:s,strokeOpacity:.38,strokeWidth:2}),c(y,{cx:24,cy:24,r:7.5})]}));export const FloatIcon=t=>i(o,Object.assign({},t,{children:[c(y,{cx:24,cy:22,r:9,opacity:.18}),c(y,{cx:24,cy:17,r:9}),c("ellipse",{cx:24,cy:39,rx:9.5,ry:2.4,fill:s,fillOpacity:.22})]}));export const ShakeIcon=t=>i(o,Object.assign({},t,{children:[c(y,{cx:17,cy:24,r:9,opacity:.16}),c(y,{cx:31,cy:24,r:9,opacity:.16}),c(y,{cx:24,cy:24,r:9}),c(h,{d:"M5 19 V29 M43 19 V29",opacity:.5})]}));export const GlowIcon=t=>{const e=n();return i(o,Object.assign({},t,{children:[c("defs",{children:c("filter",{id:e,x:"-50%",y:"-50%",width:"200%",height:"200%",children:c("feGaussianBlur",{stdDeviation:3.2})})}),c(y,{cx:24,cy:24,r:14,opacity:.4,filter:`url(#${e})`}),c(y,{cx:24,cy:24,r:8.5})]}))};export const KenBurnsIcon=t=>i(o,Object.assign({},t,{children:[c("circle",{cx:24,cy:24,r:17,stroke:s,strokeOpacity:.3,strokeWidth:2}),c(y,{cx:20.5,cy:24,r:6.5,opacity:.2}),c(y,{cx:27,cy:24,r:9.5})]}));export const BounceIcon=t=>i(o,Object.assign({},t,{children:[c("circle",{cx:24,cy:24,r:14,stroke:s,strokeOpacity:.3,strokeWidth:1.8,strokeDasharray:"2.5 2.5"}),c(y,{cx:24,cy:24,r:6})]}));
1
+ var t=this&&this.__rest||function(t,c){var e={};for(var i in t){Object.prototype.hasOwnProperty.call(t,i)&&c.indexOf(i)<0&&(e[i]=t[i])}if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(t);r<i.length;r++){c.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(t,i[r])&&(e[i[r]]=t[i[r]])}}return e};import{Fragment as c,jsx as e,jsxs as i}from"react/jsx-runtime";import r from"react";const o=t=>e("svg",Object.assign({width:"48",height:"48",viewBox:"0 0 48 48",fill:"none",xmlns:"http://www.w3.org/2000/svg",style:{margin:0,overflow:"visible"}},t)),s="currentColor",n=()=>r.useId().replace(/[^a-zA-Z0-9_-]/g,""),a=c=>{var{x:i,y:r,size:o,opacity:n=1}=c,a=t(c,["x","y","size","opacity"]);return e("rect",Object.assign({x:i,y:r,width:o,height:o,rx:.24*o,fill:s,fillOpacity:n},a))},y=c=>{var{cx:i,cy:r,r:o,opacity:n=1}=c,a=t(c,["cx","cy","r","opacity"]);return e("circle",Object.assign({cx:i,cy:r,r:o,fill:s,fillOpacity:n},a))},h=c=>{var{d:i,opacity:r=.7,width:o=2}=c,n=t(c,["d","opacity","width"]);return e("path",Object.assign({d:i,stroke:s,strokeOpacity:r,strokeWidth:o,strokeLinecap:"round",strokeLinejoin:"round"},n))},l=c=>{var{opacity:i=.35}=c,r=t(c,["opacity"]);return e("rect",Object.assign({stroke:s,strokeOpacity:i,strokeWidth:1.6,strokeDasharray:"2.5 2.5"},r))},d={A:"M0 12 L4.5 0 L9 12 M1.8 7.6 H7.2",B:"M0.6 12 V0 H4.5 C6.6 0 7.8 1.2 7.8 3 C7.8 4.7 6.6 5.8 4.5 5.8 H0.6 M4.5 5.8 C7.2 5.8 8.6 7 8.6 8.9 C8.6 10.8 7.2 12 4.9 12 H0.6",C:"M8.7 2.4 C7.9 0.9 6.5 0 4.8 0 C2.1 0 0.2 2.6 0.2 6 C0.2 9.4 2.1 12 4.8 12 C6.5 12 7.9 11.1 8.7 9.6",D:"M0.6 12 V0 H3.9 C7 0 8.9 2.4 8.9 6 C8.9 9.6 7 12 3.9 12 Z",0:"M4.5 0 C7 0 8.6 2.7 8.6 6 C8.6 9.3 7 12 4.5 12 C2 12 0.4 9.3 0.4 6 C0.4 2.7 2 0 4.5 0 Z",1:"M1.6 2.6 L5 0 V12",2:"M0.6 3 C1.1 1.1 2.6 0 4.5 0 C6.7 0 8.2 1.4 8.2 3.4 C8.2 5.6 6.3 7.1 0.6 12 H8.6"},x=({ch:t,x:c,y:i,scale:r=1,opacity:o=1})=>e("path",{d:d[t],transform:`translate(${c} ${i}) scale(${r})`,stroke:s,strokeOpacity:o,strokeWidth:2.4/r,strokeLinecap:"round",strokeLinejoin:"round"}),p=({text:t,x:i,y:r,scale:o=1,opacity:s=1})=>e(c,{children:[...t].map((t,c)=>e(x,{ch:t,x:i+12*c*o,y:r,scale:o,opacity:s},c))});export const NoneIcon=t=>i(o,Object.assign({},t,{children:[e("rect",{x:12,y:12,width:24,height:24,rx:6,stroke:s,strokeOpacity:.45,strokeWidth:2,strokeDasharray:"3 3.2"}),e(h,{d:"M15 33 L33 15",opacity:.75})]}));export const FadeIcon=t=>{const c=n();return i(o,Object.assign({},t,{children:[e("defs",{children:i("linearGradient",{id:c,x1:"0",x2:"1",y1:"0",y2:"0",children:[e("stop",{offset:"0",stopColor:s,stopOpacity:.04}),e("stop",{offset:"1",stopColor:s,stopOpacity:1})]})}),e("rect",{x:12,y:12,width:24,height:24,rx:6,fill:`url(#${c})`}),e("rect",{x:12,y:12,width:24,height:24,rx:6,stroke:s,strokeOpacity:.3,strokeWidth:1.5,strokeDasharray:"2 3"})]}))};export const MoveIcon=t=>i(o,Object.assign({},t,{children:[e(a,{x:9,y:15,size:18,opacity:.14}),e(a,{x:15,y:15,size:18,opacity:.32}),e(a,{x:23,y:15,size:18}),e(h,{d:"M2 19.5 H6.5 M2 28.5 H6.5",opacity:.55})]}));export const ZoomIcon=t=>i(o,Object.assign({},t,{children:[e(a,{x:15,y:15,size:18}),e(h,{d:"M12 12 L6.5 6.5 M6.5 11 V6.5 H11 M36 12 L41.5 6.5 M37 6.5 H41.5 V11 M36 36 L41.5 41.5 M41.5 37 V41.5 H37 M12 36 L6.5 41.5 M11 41.5 H6.5 V37"})]}));export const PopIcon=t=>i(o,Object.assign({},t,{children:[e(l,{x:10.5,y:10.5,width:27,height:27,rx:7}),e(a,{x:15,y:15,size:18}),e(h,{d:"M40 8 L43.5 4.5 M42 13 H46 M35 6 V2",opacity:.65})]}));export const RiseIcon=t=>i(o,Object.assign({},t,{children:[e(a,{x:15,y:22,size:18,opacity:.14}),e(a,{x:15,y:15.5,size:18,opacity:.32}),e(a,{x:15,y:8,size:18}),e(h,{d:"M20 42 V46 M28 42 V46",opacity:.55})]}));export const GrowTurnIcon=t=>i(o,Object.assign({},t,{children:[e("rect",{x:7,y:27,width:11,height:11,rx:2.6,fill:s,fillOpacity:.18,transform:"rotate(-40 12.5 32.5)"}),e(a,{x:21,y:9,size:19}),e(h,{d:"M8 22 C8 14.5 11.5 9.5 17 7.5 M13.6 5.7 L17 7.5 L15.3 10.9",opacity:.65})]}));export const FlipIcon=t=>i(o,Object.assign({},t,{children:[e(h,{d:"M24 4 V44",opacity:.3,width:1.5,strokeDasharray:"2 3"}),e(l,{x:13,y:14,width:22,height:22,rx:5,opacity:.3}),e("rect",{x:19,y:14,width:10,height:22,rx:3,fill:s}),e(h,{d:"M14 9 C19.5 5.5 28.5 5.5 34 9 M30.6 6.2 L34 9 L30.2 10.6",opacity:.65})]}));export const WipeIcon=t=>{const c=n();return i(o,Object.assign({},t,{children:[e("defs",{children:e("clipPath",{id:c,children:e("rect",{width:27,height:48})})}),e(a,{x:13,y:13,size:22,opacity:.16}),e("g",{clipPath:`url(#${c})`,children:e(a,{x:13,y:13,size:22})}),e(h,{d:"M27 7 V41",opacity:1,width:2.2}),e(h,{d:"M31 24 H37 M34.5 21.2 L37.3 24 L34.5 26.8",opacity:.65})]}))};export const BlurIcon=t=>{const c=n();return i(o,Object.assign({},t,{children:[e("defs",{children:e("filter",{id:c,x:"-50%",y:"-50%",width:"200%",height:"200%",children:e("feGaussianBlur",{stdDeviation:2.6})})}),e(a,{x:16,y:16,size:16,filter:`url(#${c})`}),e(h,{d:"M9 16 V9 H16 M32 9 H39 V16 M39 32 V39 H32 M16 39 H9 V32"})]}))};export const CountIcon=t=>{const c=n();return i(o,Object.assign({},t,{children:[e("defs",{children:e("clipPath",{id:c,children:e("rect",{x:9,y:13,width:30,height:22,rx:5})})}),e("rect",{x:8,y:12,width:32,height:24,rx:6,stroke:s,strokeOpacity:.35,strokeWidth:1.8}),i("g",{clipPath:`url(#${c})`,children:[e(x,{ch:"0",x:14,y:5.5,opacity:.25}),e(x,{ch:"1",x:25,y:5.5,opacity:.25}),e(x,{ch:"1",x:14,y:20.5}),e(x,{ch:"2",x:25,y:20.5})]})]}))};export const TypewriterIcon=t=>i(o,Object.assign({},t,{children:[e(x,{ch:"A",x:5,y:18}),e(x,{ch:"B",x:17,y:18}),e(h,{d:"M30.5 14.5 V33.5",opacity:1,width:2.4}),e(x,{ch:"C",x:34,y:18,opacity:.2})]}));export const LineRiseIcon=t=>i(o,Object.assign({},t,{children:[e(p,{text:"ABC",x:10.5,y:9,scale:.75}),e(p,{text:"ABC",x:10.5,y:30,scale:.75,opacity:.28}),e(h,{d:"M42 37 V30.5 M39.6 32.8 L42 30.4 L44.4 32.8",opacity:.6})]}));export const WordRiseIcon=t=>i(o,Object.assign({},t,{children:[e(p,{text:"AB",x:3.5,y:17,scale:.85}),e(p,{text:"CD",x:27,y:24,scale:.85,opacity:.3})]}));export const WordFadeIcon=t=>i(o,Object.assign({},t,{children:[e(p,{text:"AB",x:3.5,y:19,scale:.85}),e(p,{text:"CD",x:27,y:19,scale:.85,opacity:.22})]}));export const LetterPopIcon=t=>i(o,Object.assign({},t,{children:[e(x,{ch:"A",x:6,y:24,scale:.5,opacity:.25}),e(x,{ch:"B",x:15,y:21,scale:.75,opacity:.5}),e(x,{ch:"C",x:28,y:18}),e(h,{d:"M39.5 14.5 L42.5 11.5 M41.5 20 H45 M34.5 12.5 V9",opacity:.6})]}));export const WordBlurIcon=t=>{const c=n();return i(o,Object.assign({},t,{children:[e("defs",{children:e("filter",{id:c,x:"-50%",y:"-50%",width:"200%",height:"200%",children:e("feGaussianBlur",{stdDeviation:1.3})})}),e(p,{text:"AB",x:3.5,y:19,scale:.85}),e("g",{filter:`url(#${c})`,children:e(p,{text:"CD",x:27,y:19,scale:.85,opacity:.75})})]}))};export const LineWipeIcon=t=>{const c=n();return i(o,Object.assign({},t,{children:[e("defs",{children:e("clipPath",{id:c,children:e("rect",{y:20,width:32,height:28})})}),e(p,{text:"ABC",x:10.5,y:10,scale:.75}),e(p,{text:"ABC",x:10.5,y:28,scale:.75,opacity:.16}),e("g",{clipPath:`url(#${c})`,children:e(p,{text:"ABC",x:10.5,y:28,scale:.75})}),e(h,{d:"M32 25 V42",opacity:1,width:2.2})]}))};export const LinePeekIcon=t=>{const c=n();return i(o,Object.assign({},t,{children:[e("defs",{children:e("clipPath",{id:c,children:e("rect",{y:26.5,width:48,height:12})})}),e(p,{text:"ABC",x:10.5,y:10,scale:.75}),e("g",{clipPath:`url(#${c})`,children:e(p,{text:"ABC",x:10.5,y:33,scale:.75})}),e(h,{d:"M8 39.5 H37",opacity:.35}),e(h,{d:"M42 37 V30.5 M39.6 32.8 L42 30.4 L44.4 32.8",opacity:.6})]}))};export const LetterWaveIcon=t=>i(o,Object.assign({},t,{children:[e(x,{ch:"A",x:7.5,y:20}),e(x,{ch:"B",x:19.5,y:13}),e(x,{ch:"C",x:31.5,y:20}),e(h,{d:"M6 39 C10 35.5 14 35.5 18 39 S26 42.5 30 39 S38 35.5 42 39",opacity:.35})]}));export const RotateIcon=t=>i(o,Object.assign({},t,{children:[e(y,{cx:24,cy:24,r:9}),e(h,{d:"M9.5 19.5 A15.5 15.5 0 0 1 22 8.6 M18.6 6.6 L22 8.6 L19 11.4",opacity:.65}),e(h,{d:"M38.5 28.5 A15.5 15.5 0 0 1 26 39.4 M29.4 41.4 L26 39.4 L29 36.6",opacity:.65})]}));export const BlinkIcon=t=>i(o,Object.assign({},t,{children:[e(y,{cx:15.5,cy:24,r:8.5}),e("circle",{cx:32.5,cy:24,r:8,stroke:s,strokeOpacity:.45,strokeWidth:1.8,strokeDasharray:"2.5 2.5"})]}));export const PulseIcon=t=>i(o,Object.assign({},t,{children:[e("circle",{cx:24,cy:24,r:16.5,stroke:s,strokeOpacity:.16,strokeWidth:2}),e("circle",{cx:24,cy:24,r:12,stroke:s,strokeOpacity:.38,strokeWidth:2}),e(y,{cx:24,cy:24,r:7.5})]}));export const FloatIcon=t=>i(o,Object.assign({},t,{children:[e(y,{cx:24,cy:22,r:9,opacity:.18}),e(y,{cx:24,cy:17,r:9}),e("ellipse",{cx:24,cy:39,rx:9.5,ry:2.4,fill:s,fillOpacity:.22})]}));export const ShakeIcon=t=>i(o,Object.assign({},t,{children:[e(y,{cx:17,cy:24,r:9,opacity:.16}),e(y,{cx:31,cy:24,r:9,opacity:.16}),e(y,{cx:24,cy:24,r:9}),e(h,{d:"M5 19 V29 M43 19 V29",opacity:.5})]}));export const GlowIcon=t=>{const c=n();return i(o,Object.assign({},t,{children:[e("defs",{children:e("filter",{id:c,x:"-50%",y:"-50%",width:"200%",height:"200%",children:e("feGaussianBlur",{stdDeviation:3.2})})}),e(y,{cx:24,cy:24,r:14,opacity:.4,filter:`url(#${c})`}),e(y,{cx:24,cy:24,r:8.5})]}))};export const KenBurnsIcon=t=>i(o,Object.assign({},t,{children:[e("circle",{cx:24,cy:24,r:17,stroke:s,strokeOpacity:.3,strokeWidth:2}),e(y,{cx:20.5,cy:24,r:6.5,opacity:.2}),e(y,{cx:27,cy:24,r:9.5})]}));export const BounceIcon=t=>i(o,Object.assign({},t,{children:[e("circle",{cx:24,cy:24,r:14,stroke:s,strokeOpacity:.3,strokeWidth:1.8,strokeDasharray:"2.5 2.5"}),e(y,{cx:24,cy:24,r:6})]}));
@@ -1,4 +1,6 @@
1
1
  import type { ComponentType, SVGProps } from 'react';
2
+ import { Instagram, Facebook, Youtube, Linkedin, Twitter } from './brand-icons.js';
3
+ import { NoneIcon, MoveIcon, FadeIcon, ZoomIcon, RotateIcon, BlinkIcon, BounceIcon, BlurIcon, CountIcon, PopIcon, RiseIcon, FlipIcon, GrowTurnIcon, PulseIcon, FloatIcon, ShakeIcon, TypewriterIcon, LineRiseIcon, WordRiseIcon, WordFadeIcon, LetterPopIcon, WordBlurIcon, WipeIcon, GlowIcon, KenBurnsIcon, LineWipeIcon, LinePeekIcon, LetterWaveIcon } from './animation-icons.js';
2
4
  export type IconComponent = ComponentType<{
3
5
  className?: string;
4
6
  }>;
@@ -94,11 +96,11 @@ declare const defaults: {
94
96
  'pagesTimeline.play': import("lucide-react").LucideIcon;
95
97
  'pagesTimeline.pause': import("lucide-react").LucideIcon;
96
98
  'pagesTimeline.rewind': import("lucide-react").LucideIcon;
97
- 'size.instagram': (props: SVGProps<SVGSVGElement>) => import("react").JSX.Element;
98
- 'size.facebook': (props: SVGProps<SVGSVGElement>) => import("react").JSX.Element;
99
- 'size.youtube': (props: SVGProps<SVGSVGElement>) => import("react").JSX.Element;
100
- 'size.linkedin': (props: SVGProps<SVGSVGElement>) => import("react").JSX.Element;
101
- 'size.twitter': (props: SVGProps<SVGSVGElement>) => import("react").JSX.Element;
99
+ 'size.instagram': typeof Instagram;
100
+ 'size.facebook': typeof Facebook;
101
+ 'size.youtube': typeof Youtube;
102
+ 'size.linkedin': typeof Linkedin;
103
+ 'size.twitter': typeof Twitter;
102
104
  'size.video': import("lucide-react").LucideIcon;
103
105
  'size.print': import("lucide-react").LucideIcon;
104
106
  'size.businessCard': import("lucide-react").LucideIcon;
@@ -110,33 +112,34 @@ declare const defaults: {
110
112
  'animation.directionBottomLeft': import("lucide-react").LucideIcon;
111
113
  'animation.directionTopRight': import("lucide-react").LucideIcon;
112
114
  'animation.directionTopLeft': import("lucide-react").LucideIcon;
113
- 'animation.typeMove': (props: SVGProps<SVGSVGElement>) => import("react").JSX.Element;
114
- 'animation.typeFade': (props: SVGProps<SVGSVGElement>) => import("react").JSX.Element;
115
- 'animation.typeZoom': (props: SVGProps<SVGSVGElement>) => import("react").JSX.Element;
116
- 'animation.typeBlur': (props: SVGProps<SVGSVGElement>) => import("react").JSX.Element;
117
- 'animation.typeCount': (props: SVGProps<SVGSVGElement>) => import("react").JSX.Element;
118
- 'animation.typeRotate': (props: SVGProps<SVGSVGElement>) => import("react").JSX.Element;
119
- 'animation.typeBlink': (props: SVGProps<SVGSVGElement>) => import("react").JSX.Element;
120
- 'animation.typeBounce': (props: SVGProps<SVGSVGElement>) => import("react").JSX.Element;
121
- 'animation.typePop': (props: SVGProps<SVGSVGElement>) => import("react").JSX.Element;
122
- 'animation.typeRise': (props: SVGProps<SVGSVGElement>) => import("react").JSX.Element;
123
- 'animation.typeFlip': (props: SVGProps<SVGSVGElement>) => import("react").JSX.Element;
124
- 'animation.typeGrowTurn': (props: SVGProps<SVGSVGElement>) => import("react").JSX.Element;
125
- 'animation.typePulse': (props: SVGProps<SVGSVGElement>) => import("react").JSX.Element;
126
- 'animation.typeFloat': (props: SVGProps<SVGSVGElement>) => import("react").JSX.Element;
127
- 'animation.typeShake': (props: SVGProps<SVGSVGElement>) => import("react").JSX.Element;
128
- 'animation.typeTypewriter': (props: SVGProps<SVGSVGElement>) => import("react").JSX.Element;
129
- 'animation.typeLineRise': (props: SVGProps<SVGSVGElement>) => import("react").JSX.Element;
130
- 'animation.typeWordRise': (props: SVGProps<SVGSVGElement>) => import("react").JSX.Element;
131
- 'animation.typeWordFade': (props: SVGProps<SVGSVGElement>) => import("react").JSX.Element;
132
- 'animation.typeLetterPop': (props: SVGProps<SVGSVGElement>) => import("react").JSX.Element;
133
- 'animation.typeWordBlur': (props: SVGProps<SVGSVGElement>) => import("react").JSX.Element;
134
- 'animation.typeWipe': (props: SVGProps<SVGSVGElement>) => import("react").JSX.Element;
135
- 'animation.typeGlow': (props: SVGProps<SVGSVGElement>) => import("react").JSX.Element;
136
- 'animation.typeKenBurns': (props: SVGProps<SVGSVGElement>) => import("react").JSX.Element;
137
- 'animation.typeLineWipe': (props: SVGProps<SVGSVGElement>) => import("react").JSX.Element;
138
- 'animation.typeLetterWave': (props: SVGProps<SVGSVGElement>) => import("react").JSX.Element;
139
- 'animation.typeNone': (props: SVGProps<SVGSVGElement>) => import("react").JSX.Element;
115
+ 'animation.typeMove': typeof MoveIcon;
116
+ 'animation.typeFade': typeof FadeIcon;
117
+ 'animation.typeZoom': typeof ZoomIcon;
118
+ 'animation.typeBlur': typeof BlurIcon;
119
+ 'animation.typeCount': typeof CountIcon;
120
+ 'animation.typeRotate': typeof RotateIcon;
121
+ 'animation.typeBlink': typeof BlinkIcon;
122
+ 'animation.typeBounce': typeof BounceIcon;
123
+ 'animation.typePop': typeof PopIcon;
124
+ 'animation.typeRise': typeof RiseIcon;
125
+ 'animation.typeFlip': typeof FlipIcon;
126
+ 'animation.typeGrowTurn': typeof GrowTurnIcon;
127
+ 'animation.typePulse': typeof PulseIcon;
128
+ 'animation.typeFloat': typeof FloatIcon;
129
+ 'animation.typeShake': typeof ShakeIcon;
130
+ 'animation.typeTypewriter': typeof TypewriterIcon;
131
+ 'animation.typeLineRise': typeof LineRiseIcon;
132
+ 'animation.typeWordRise': typeof WordRiseIcon;
133
+ 'animation.typeWordFade': typeof WordFadeIcon;
134
+ 'animation.typeLetterPop': typeof LetterPopIcon;
135
+ 'animation.typeWordBlur': typeof WordBlurIcon;
136
+ 'animation.typeWipe': typeof WipeIcon;
137
+ 'animation.typeGlow': typeof GlowIcon;
138
+ 'animation.typeKenBurns': typeof KenBurnsIcon;
139
+ 'animation.typeLineWipe': typeof LineWipeIcon;
140
+ 'animation.typeLinePeek': typeof LinePeekIcon;
141
+ 'animation.typeLetterWave': typeof LetterWaveIcon;
142
+ 'animation.typeNone': typeof NoneIcon;
140
143
  'animation.settings': import("lucide-react").LucideIcon;
141
144
  };
142
145
  export type IconName = keyof typeof defaults;