polotno 3.14.1 → 3.15.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 (132) hide show
  1. package/blueprint/side-panel/select-video.d.ts +22 -2
  2. package/canvas/crop-overlay.d.ts +36 -7
  3. package/canvas/crop-overlay.js +1 -1
  4. package/canvas/drawing-layer.js +1 -1
  5. package/canvas/fade-overlay.js +1 -1
  6. package/canvas/figure-element.js +1 -1
  7. package/canvas/gif-element.js +1 -1
  8. package/canvas/hotkeys.d.ts +5 -5
  9. package/canvas/hotkeys.js +1 -1
  10. package/canvas/html-element.js +1 -1
  11. package/canvas/image-element.js +1 -1
  12. package/canvas/image-processing.d.ts +5 -0
  13. package/canvas/image-processing.js +1 -0
  14. package/canvas/image-tool-controls.d.ts +15 -0
  15. package/canvas/image-tool-controls.js +1 -0
  16. package/canvas/line-element.js +1 -1
  17. package/canvas/page-controls.js +1 -1
  18. package/canvas/page.js +1 -1
  19. package/canvas/parent-frame.d.ts +5 -0
  20. package/canvas/parent-frame.js +1 -0
  21. package/canvas/quill-font-formats.js +1 -1
  22. package/canvas/rect-control.d.ts +13 -0
  23. package/canvas/rect-control.js +1 -0
  24. package/canvas/render-tag-element.js +1 -1
  25. package/canvas/rich-editor.js +3 -3
  26. package/canvas/table-element.js +1 -1
  27. package/canvas/text-element/caret-color.js +1 -1
  28. package/canvas/text-element.js +1 -1
  29. package/canvas/tooltip.js +1 -1
  30. package/canvas/use-color.d.ts +4 -0
  31. package/canvas/use-color.js +1 -1
  32. package/canvas/video-element.js +1 -1
  33. package/canvas/workspace-canvas.js +1 -1
  34. package/config.d.ts +4 -0
  35. package/config.js +1 -1
  36. package/icons/registry.d.ts +2 -0
  37. package/icons/registry.js +1 -1
  38. package/image-tools/geometry.d.ts +20 -0
  39. package/image-tools/geometry.js +1 -0
  40. package/image-tools/host.d.ts +62 -0
  41. package/image-tools/host.js +1 -0
  42. package/image-tools/messages.d.ts +5 -0
  43. package/image-tools/messages.js +1 -0
  44. package/image-tools/operations.d.ts +22 -0
  45. package/image-tools/operations.js +1 -0
  46. package/image-tools/raster.d.ts +13 -0
  47. package/image-tools/raster.js +1 -0
  48. package/image-tools/sessions.d.ts +73 -0
  49. package/image-tools/sessions.js +1 -0
  50. package/image-tools/target.d.ts +37 -0
  51. package/image-tools/target.js +1 -0
  52. package/image-tools/types.d.ts +62 -0
  53. package/image-tools/types.js +1 -0
  54. package/model/crop-mode.d.ts +18 -20
  55. package/model/crop-mode.js +1 -1
  56. package/model/gif-model.d.ts +11 -1
  57. package/model/group-model.d.ts +43 -6
  58. package/model/group-model.js +1 -1
  59. package/model/history.d.ts +8 -0
  60. package/model/history.js +1 -1
  61. package/model/image-edit-state.d.ts +14 -0
  62. package/model/image-edit-state.js +1 -0
  63. package/model/image-model.d.ts +11 -1
  64. package/model/image-model.js +1 -1
  65. package/model/image-tools.d.ts +26 -0
  66. package/model/image-tools.js +1 -0
  67. package/model/page-model.d.ts +111 -12
  68. package/model/store.d.ts +26 -3
  69. package/model/store.js +1 -1
  70. package/model/svg-model.d.ts +2 -1
  71. package/model/text-model.d.ts +2 -0
  72. package/model/text-model.js +1 -1
  73. package/model/video-model.d.ts +11 -1
  74. package/package.json +20 -20
  75. package/polotno.bundle.js +165 -165
  76. package/primitives/toggle.js +1 -1
  77. package/side-panel/ai-images-panel.js +1 -1
  78. package/side-panel/background-panel.js +1 -1
  79. package/side-panel/effect-card.js +1 -1
  80. package/side-panel/effects-panel.js +1 -1
  81. package/side-panel/image-edit-panel.d.ts +11 -0
  82. package/side-panel/image-edit-panel.js +1 -0
  83. package/side-panel/photos-panel.js +1 -1
  84. package/side-panel/select-video.d.ts +22 -2
  85. package/side-panel/side-panel.d.ts +1 -0
  86. package/side-panel/side-panel.js +1 -1
  87. package/side-panel/upload-panel.js +1 -1
  88. package/toolbar/color-picker.js +1 -1
  89. package/toolbar/element-container.js +1 -1
  90. package/toolbar/html-toolbar.js +3 -3
  91. package/toolbar/image-remove-background-button.d.ts +1 -1
  92. package/toolbar/image-remove-background-button.js +1 -1
  93. package/toolbar/image-toolbar.d.ts +1 -0
  94. package/toolbar/image-toolbar.js +1 -1
  95. package/toolbar/image-tools.d.ts +43 -0
  96. package/toolbar/image-tools.js +1 -0
  97. package/toolbar/sketch.d.ts +4 -1
  98. package/toolbar/sketch.js +1 -1
  99. package/toolbar/stop-track.d.ts +28 -0
  100. package/toolbar/stop-track.js +1 -0
  101. package/toolbar/toolbar.js +1 -1
  102. package/toolbar/use-copy-style.js +1 -1
  103. package/ui.css +1 -1
  104. package/utils/api.d.ts +14 -0
  105. package/utils/api.js +1 -1
  106. package/utils/clipboard.d.ts +4 -0
  107. package/utils/errors.d.ts +1 -0
  108. package/utils/errors.js +1 -1
  109. package/utils/fade-gradient.d.ts +5 -6
  110. package/utils/fade-gradient.js +1 -1
  111. package/utils/flags.d.ts +7 -1
  112. package/utils/flags.js +1 -1
  113. package/utils/gradient-stops.d.ts +25 -0
  114. package/utils/gradient-stops.js +1 -0
  115. package/utils/image-edit.d.ts +37 -0
  116. package/utils/image-edit.js +1 -0
  117. package/utils/l10n.d.ts +35 -0
  118. package/utils/l10n.js +1 -1
  119. package/utils/luma.js +1 -1
  120. package/utils/px.d.ts +4 -0
  121. package/utils/px.js +1 -1
  122. package/utils/rich-text-html.d.ts +5 -0
  123. package/utils/rich-text-html.js +1 -1
  124. package/utils/stops.d.ts +17 -0
  125. package/utils/stops.js +1 -0
  126. package/utils/text-format-state.d.ts +3 -2
  127. package/utils/text-format-state.js +1 -1
  128. package/utils/text-format.d.ts +4 -1
  129. package/utils/text-format.js +1 -1
  130. package/utils/to-pptx.d.ts +1 -1
  131. package/utils/to-pptx.js +1 -1
  132. package/utils/validate-key.js +1 -1
@@ -1 +1 @@
1
- import{jsx as t,jsxs as e,Fragment as o}from"react/jsx-runtime";import{elementOpacity as r}from"./paint-opacity.js";import a from"react";import{observer as n}from"mobx-react-lite";import{Group as i,Line as s,Rect as l,Circle as h}from"react-konva";import{ROLES as d}from"../model/store.js";import{useColor as c}from"./use-color.js";import{getLineHeadGeometry as g}from"@polotno/core/line-head";import{Portal as m}from"react-konva-utils";import{useAnchorSnap as f}from"./use-transformer-snap.js";import{useWorkspaceStyle as p}from"./workspace-style.js";import{isTouchDevice as x}from"../utils/screen.js";import{roundedGeometryAttrs as u,roundedPosition as y}from"../utils/px.js";export function getMiddlePoints(t){const{x:e,y:o,width:r,height:a,rotation:n}=t.a,i=n*Math.PI/180,s={x:e+a/2*Math.cos(i+Math.PI/2),y:o+a/2*Math.sin(i+Math.PI/2)};return{middleLeft:s,middleRight:{x:s.x+r*Math.cos(i),y:s.y+r*Math.sin(i)}}}export function getLinePositionFromMiddlePoints(t,e,o){const r=Math.sqrt(Math.pow(e.x-t.x,2)+Math.pow(e.y-t.y,2)),a=Math.atan2(e.y-t.y,e.x-t.x),n=180*a/Math.PI;return{x:t.x+Math.cos(a-Math.PI/2)*o/2,y:t.y+Math.sin(a-Math.PI/2)*o/2,width:r,height:o,rotation:n}}const w=(t,e,o)=>{const r=o.anchorSize;return{offsetX:r/2/t,offsetY:r/2/t,width:r/t,height:r/t,cornerRadius:o.anchorCornerRadius/t,fill:o.anchorFill,stroke:o.anchorStroke,strokeWidth:o.anchorStrokeWidth,strokeScaleEnabled:!1,draggable:!0,dragDistance:0,onMouseEnter:t=>{t.target.getStage().container().style.cursor="crosshair"},onMouseLeave:t=>{t.target.getStage().container().style.cursor=""},onDragStart:t=>{e.history.startTransaction()},onDragEnd:t=>{e.history.endTransaction()}}},M=n(({element:e,type:o})=>{const a=c(e,e.a.color,"fill"),n=c(e,e.a.color,"stroke"),i=g(o,e.height);if(!i){return null}const l=Object.assign(Object.assign(Object.assign({strokeWidth:e.height,lineCap:"round",lineJoin:"round"},n),a),{opacity:r(e),hideInExport:!e.showInExport});return"circle"===i.kind?t(h,Object.assign({x:i.cx,y:i.cy,radius:i.r},l)):t(s,Object.assign({points:i.points.flat(),closed:i.filled},l))});export const LineElement=n(({element:n,store:h})=>{const{transformerStyle:g}=p(),b=a.useRef(null),v=a.useRef(null),j=a.useRef(null),k=n.selectable||h.role===d.ADMIN,E=x(),O=h.selectedElements.indexOf(n)>=0&&1===h.selectedElements.length,P=n.isSelected,{middleLeft:I,middleRight:S}=getMiddlePoints(n);f(v,[b],[O]),f(j,[b],[O]);const D=c(n,n.a.color,"stroke");return e(o,{children:[t(s,Object.assign({ref:b,name:"element",id:n.id,x:n.a.x,y:n.a.y,points:[0,0,n.a.width,0],offsetY:-n.a.height/2,strokeWidth:n.a.height,hitStrokeWidth:Math.max(n.a.height,20),dash:n.dash.map(t=>t*n.a.height)},D,{rotation:n.a.rotation,opacity:r(n),shadowEnabled:n.shadowEnabled,shadowBlur:n.shadowBlur,shadowOffsetX:n.shadowOffsetX,shadowOffsetY:n.shadowOffsetY,shadowColor:n.shadowColor,shadowOpacity:n.shadowOpacity,listening:k,draggable:E?n.draggable&&P:n.draggable,preventDefault:!E||P,hideInExport:!n.showInExport,onDragMove:t=>{n.set({x:t.target.x(),y:t.target.y()})},onDragEnd:t=>{n.set(y(t.target))},onTransform:t=>{const e=t.target.scaleX();t.target.scaleX(1),t.target.scaleY(1),n.set({height:n.height*e,width:n.width*e,x:t.target.x(),y:t.target.y(),rotation:t.target.rotation()})},onTransformEnd:()=>{n.set(u(n))}})),t(i,{x:I.x,y:I.y,rotation:n.rotation,hideInExport:!n.showInExport,onClick:t=>{var e;return null===(e=b.current)||void 0===e?void 0:e.fire("click",t)},onTap:t=>{var e;return null===(e=b.current)||void 0===e?void 0:e.fire("tap",t)},children:t(M,{element:n,type:n.startHead})}),t(i,{x:S.x,y:S.y,rotation:n.rotation+180,onClick:t=>{var e;return null===(e=b.current)||void 0===e?void 0:e.fire("click",t)},onTap:t=>{var e;return null===(e=b.current)||void 0===e?void 0:e.fire("tap",t)},children:t(M,{element:n,type:n.endHead})}),O&&n.resizable&&t(m,{selector:".page-abs-container",enabled:!0,children:e(i,{visible:O,children:[t(l,Object.assign({x:I.x,y:I.y,ref:v,name:"line-anchor"},w(h.scale,h,g),{onDragMove:t=>{const e=getLinePositionFromMiddlePoints(t.target.position(),S,n.height);n.set({x:e.x,y:e.y,width:e.width,rotation:e.rotation})}})),t(l,Object.assign({x:S.x,y:S.y,ref:j,name:"line-anchor"},w(h.scale,h,g),{onDragMove:t=>{const e=getLinePositionFromMiddlePoints(I,t.target.position(),n.height);n.set({x:e.x,y:e.y,width:e.width,rotation:e.rotation})}}))]})})]})});
1
+ import{jsx as t,jsxs as e,Fragment as o}from"react/jsx-runtime";import{elementOpacity as r}from"./paint-opacity.js";import a from"react";import{toDisplayColor as n}from"@polotno/core/color";import{observer as i}from"mobx-react-lite";import{Group as s,Line as l,Rect as h,Circle as d}from"react-konva";import{ROLES as c}from"../model/store.js";import{useColor as g}from"./use-color.js";import{getLineHeadGeometry as m}from"@polotno/core/line-head";import{Portal as f}from"react-konva-utils";import{useAnchorSnap as p}from"./use-transformer-snap.js";import{useWorkspaceStyle as x}from"./workspace-style.js";import{isTouchDevice as u}from"../utils/screen.js";import{roundedGeometryAttrs as y,roundedPosition as w}from"../utils/px.js";export function getMiddlePoints(t){const{x:e,y:o,width:r,height:a,rotation:n}=t.a,i=n*Math.PI/180,s={x:e+a/2*Math.cos(i+Math.PI/2),y:o+a/2*Math.sin(i+Math.PI/2)};return{middleLeft:s,middleRight:{x:s.x+r*Math.cos(i),y:s.y+r*Math.sin(i)}}}export function getLinePositionFromMiddlePoints(t,e,o){const r=Math.sqrt(Math.pow(e.x-t.x,2)+Math.pow(e.y-t.y,2)),a=Math.atan2(e.y-t.y,e.x-t.x),n=180*a/Math.PI;return{x:t.x+Math.cos(a-Math.PI/2)*o/2,y:t.y+Math.sin(a-Math.PI/2)*o/2,width:r,height:o,rotation:n}}const M=(t,e,o)=>{const r=o.anchorSize;return{offsetX:r/2/t,offsetY:r/2/t,width:r/t,height:r/t,cornerRadius:o.anchorCornerRadius/t,fill:o.anchorFill,stroke:o.anchorStroke,strokeWidth:o.anchorStrokeWidth,strokeScaleEnabled:!1,draggable:!0,dragDistance:0,onMouseEnter:t=>{t.target.getStage().container().style.cursor="crosshair"},onMouseLeave:t=>{t.target.getStage().container().style.cursor=""},onDragStart:t=>{e.history.startTransaction()},onDragEnd:t=>{e.history.endTransaction()}}},b=i(({element:e,type:o})=>{const a=g(e,e.a.color,"fill"),n=g(e,e.a.color,"stroke"),i=m(o,e.height);if(!i){return null}const s=Object.assign(Object.assign(Object.assign({strokeWidth:e.height,lineCap:"round",lineJoin:"round"},n),a),{opacity:r(e),hideInExport:!e.showInExport});return"circle"===i.kind?t(d,Object.assign({x:i.cx,y:i.cy,radius:i.r},s)):t(l,Object.assign({points:i.points.flat(),closed:i.filled},s))});export const LineElement=i(({element:i,store:d})=>{const{transformerStyle:m}=x(),v=a.useRef(null),j=a.useRef(null),k=a.useRef(null),E=i.selectable||d.role===c.ADMIN,O=u(),P=d.selectedElements.indexOf(i)>=0&&1===d.selectedElements.length,I=i.isSelected,{middleLeft:S,middleRight:D}=getMiddlePoints(i);p(j,[v],[P]),p(k,[v],[P]);const L=g(i,i.a.color,"stroke");return e(o,{children:[t(l,Object.assign({ref:v,name:"element",id:i.id,x:i.a.x,y:i.a.y,points:[0,0,i.a.width,0],offsetY:-i.a.height/2,strokeWidth:i.a.height,hitStrokeWidth:Math.max(i.a.height,20),dash:i.dash.map(t=>t*i.a.height)},L,{rotation:i.a.rotation,opacity:r(i),shadowEnabled:i.shadowEnabled,shadowBlur:i.shadowBlur,shadowOffsetX:i.shadowOffsetX,shadowOffsetY:i.shadowOffsetY,shadowColor:n(i.shadowColor),shadowOpacity:i.shadowOpacity,listening:E,draggable:O?i.draggable&&I:i.draggable,preventDefault:!O||I,hideInExport:!i.showInExport,onDragMove:t=>{i.set({x:t.target.x(),y:t.target.y()})},onDragEnd:t=>{i.set(w(t.target))},onTransform:t=>{const e=t.target.scaleX();t.target.scaleX(1),t.target.scaleY(1),i.set({height:i.height*e,width:i.width*e,x:t.target.x(),y:t.target.y(),rotation:t.target.rotation()})},onTransformEnd:()=>{i.set(y(i))}})),t(s,{x:S.x,y:S.y,rotation:i.rotation,hideInExport:!i.showInExport,onClick:t=>{var e;return null===(e=v.current)||void 0===e?void 0:e.fire("click",t)},onTap:t=>{var e;return null===(e=v.current)||void 0===e?void 0:e.fire("tap",t)},children:t(b,{element:i,type:i.startHead})}),t(s,{x:D.x,y:D.y,rotation:i.rotation+180,onClick:t=>{var e;return null===(e=v.current)||void 0===e?void 0:e.fire("click",t)},onTap:t=>{var e;return null===(e=v.current)||void 0===e?void 0:e.fire("tap",t)},children:t(b,{element:i,type:i.endHead})}),P&&i.resizable&&t(f,{selector:".page-abs-container",enabled:!0,children:e(s,{visible:P,children:[t(h,Object.assign({x:S.x,y:S.y,ref:j,name:"line-anchor"},M(d.scale,d,m),{onDragMove:t=>{const e=getLinePositionFromMiddlePoints(t.target.position(),D,i.height);i.set({x:e.x,y:e.y,width:e.width,rotation:e.rotation})}})),t(h,Object.assign({x:D.x,y:D.y,ref:k,name:"line-anchor"},M(d.scale,d,m),{onDragMove:t=>{const e=getLinePositionFromMiddlePoints(S,t.target.position(),i.height);i.set({x:e.x,y:e.y,width:e.width,rotation:e.rotation})}}))]})})]})});
@@ -1 +1 @@
1
- import{jsx as e,jsxs as o}from"react/jsx-runtime";import{observer as i}from"mobx-react-lite";import t from"konva";import{PolotnoIcon as l}from"../icons/registry.js";import{ROLES as a}from"../model/store.js";import{t as d}from"../utils/l10n.js";import{TooltipIconButton as n}from"../primitives/tooltip-icon-button.js";import{useWorkspaceStyle as r}from"./workspace-style.js";export const PageControls=i(({store:i,page:s,xPadding:c,yPadding:p,layout:g="vertical"})=>{const v=i.pages.length>1,m=i.pages.indexOf(s),h="horizontal"===g,u=h?"ui.chevronLeft":"ui.chevronUp",b=h?"ui.chevronRight":"ui.chevronDown",k=d(h?"workspace.moveLeft":"workspace.moveUp"),f=d(h?"workspace.moveRight":"workspace.moveDown"),{workspaceBackgroundColor:P}=r(),x=(e=>{const o=t.Util.colorToRGBA(e);return(o?.299*o.r+.587*o.g+.114*o.b:232)>150?"rgba(0, 0, 0, 0.6)":"rgba(255, 255, 255, 0.85)"})(P);return"selection"!==i.tool||i.role===a.VIEWER?null:o("div",{className:"polotno-page-controls",style:{position:"absolute",top:p-40+"px",right:c+"px",color:x},children:[v&&e(n,{side:"top",label:k,disabled:0===m,onClick:()=>{s.setZIndex(m-1)},children:e(l,{name:u})}),v&&e(n,{side:"top",label:f,disabled:m===i.pages.length-1,onClick:()=>{const e=i.pages.indexOf(s);s.setZIndex(e+1)},children:e(l,{name:b})}),e(n,{side:"top",label:d("workspace.duplicatePage"),onClick:()=>{s.clone()},children:e(l,{name:"action.duplicate"})}),v&&e(n,{side:"top",label:d("workspace.removePage"),onClick:()=>{i.deletePages([s.id])},children:e(l,{name:"action.remove"})}),e(n,{side:"top",label:d("workspace.addPage"),onClick:()=>{var e,o,t,l,a,d,n;const r=i.addPage({bleed:(null===(e=i.activePage)||void 0===e?void 0:e.bleed)||0,bleedTop:null===(o=i.activePage)||void 0===o?void 0:o.bleedTop,bleedRight:null===(t=i.activePage)||void 0===t?void 0:t.bleedRight,bleedBottom:null===(l=i.activePage)||void 0===l?void 0:l.bleedBottom,bleedLeft:null===(a=i.activePage)||void 0===a?void 0:a.bleedLeft,width:(null===(d=i.activePage)||void 0===d?void 0:d.width)||"auto",height:(null===(n=i.activePage)||void 0===n?void 0:n.height)||"auto"}),c=i.pages.indexOf(s);r.setZIndex(c+1)},children:e(l,{name:"action.add"})})]})});
1
+ import{jsx as e,jsxs as o}from"react/jsx-runtime";import{observer as i}from"mobx-react-lite";import t from"konva";import{PolotnoIcon as l}from"../icons/registry.js";import{ROLES as a}from"../model/store.js";import{t as d}from"../utils/l10n.js";import{TooltipIconButton as n}from"../primitives/tooltip-icon-button.js";import{useWorkspaceStyle as r}from"./workspace-style.js";export const PageControls=i(({store:i,page:s,xPadding:c,yPadding:p,layout:v="vertical"})=>{const g=i.pages.length>1,m=i.pages.indexOf(s),h="horizontal"===v,u=h?"ui.chevronLeft":"ui.chevronUp",b=h?"ui.chevronRight":"ui.chevronDown",k=d(h?"workspace.moveLeft":"workspace.moveUp"),f=d(h?"workspace.moveRight":"workspace.moveDown"),{workspaceBackgroundColor:P}=r(),x=(e=>{const o=t.Util.colorToRGBA(e);return(o?.299*o.r+.587*o.g+.114*o.b:232)>150?"rgba(0, 0, 0, 0.6)":"rgba(255, 255, 255, 0.85)"})(P);return"selection"!==i.tool&&!i.activeTool||i.role===a.VIEWER?null:o("div",{className:"polotno-page-controls",style:{position:"absolute",top:p-40+"px",right:c+"px",color:x},children:[g&&e(n,{side:"top",label:k,disabled:0===m,onClick:()=>{s.setZIndex(m-1)},children:e(l,{name:u})}),g&&e(n,{side:"top",label:f,disabled:m===i.pages.length-1,onClick:()=>{const e=i.pages.indexOf(s);s.setZIndex(e+1)},children:e(l,{name:b})}),e(n,{side:"top",label:d("workspace.duplicatePage"),onClick:()=>{s.clone()},children:e(l,{name:"action.duplicate"})}),g&&e(n,{side:"top",label:d("workspace.removePage"),onClick:()=>{i.deletePages([s.id])},children:e(l,{name:"action.remove"})}),e(n,{side:"top",label:d("workspace.addPage"),onClick:()=>{var e,o,t,l,a,d,n;const r=i.addPage({bleed:(null===(e=i.activePage)||void 0===e?void 0:e.bleed)||0,bleedTop:null===(o=i.activePage)||void 0===o?void 0:o.bleedTop,bleedRight:null===(t=i.activePage)||void 0===t?void 0:t.bleedRight,bleedBottom:null===(l=i.activePage)||void 0===l?void 0:l.bleedBottom,bleedLeft:null===(a=i.activePage)||void 0===a?void 0:a.bleedLeft,width:(null===(d=i.activePage)||void 0===d?void 0:d.width)||"auto",height:(null===(n=i.activePage)||void 0===n?void 0:n.height)||"auto"}),c=i.pages.indexOf(s);r.setZIndex(c+1)},children:e(l,{name:"action.add"})})]})});
package/canvas/page.js CHANGED
@@ -1 +1 @@
1
- var e=this&&this.__rest||function(e,t){var n={};for(var i in e){Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i])}if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(i=Object.getOwnPropertySymbols(e);o<i.length;o++){t.indexOf(i[o])<0&&Object.prototype.propertyIsEnumerable.call(e,i[o])&&(n[i[o]]=e[i[o]])}}return n};import{jsx as t,jsxs as n,Fragment as i}from"react/jsx-runtime";import o from"react";import{observer as r,useLocalObservable as l}from"mobx-react-lite";import{action as s,runInAction as a}from"mobx";import{ZERO_BLEED as d}from"@polotno/schema";import{Group as c,Image as u,Label as h,Layer as m,Line as g,Rect as f,Shape as p,Stage as x,KonvaRenderer as v,Tag as b,Text as y,Transformer as w}from"react-konva";import{useWorkspaceStyle as E}from"./workspace-style.js";import{ROLES as X}from"../model/store.js";import Y from"konva";import S from"./element.js";import{DrawingLayer as k}from"./drawing-layer.js";import{ensureDragOrder as A,useSnap as M}from"./use-transformer-snap.js";import{useCanvasImage as I,useImageLoader as O}from"./image-element.js";import{FadeOverlay as P}from"./fade-overlay.js";import{getCrop as j}from"../utils/crop.js";import{___ as R,____ as B,isCreditVisible as D}from"../utils/validate-key.js";import{getClientRect as T,getCorners as C,getTotalClientRect as W,polygonsIntersect as G}from"../utils/math.js";import{pxToUnitRounded as L,pxToUnitString as F}from"../utils/unit.js";import{isCornerAnchor as V,MAIN_TRANSFORMER_NAME as z,textMinResizeWidth as U,textMinWidthIsMeasured as Z}from"../utils/px.js";import{restoreHeldPoint as _}from"./transform-box.js";import{flags as H}from"../utils/flags.js";import{useColor as J}from"./use-color.js";import{isGradient as N}from"@polotno/core/gradient";import{Html as K}from"react-konva-utils";const $=o.version.startsWith("18.")?o.forwardRef((e,n)=>(o.useLayoutEffect(()=>{v.flushSync()}),t(x,Object.assign({},e,{ref:n})))):x,Q={enabledAnchors:["top-left","top-center","top-right","middle-left","bottom-left","bottom-right","bottom-center","middle-right"],rotateEnabled:!0,rotationSnaps:[0,45,90,135,180,225,270,315],ignoreStroke:!0,flipEnabled:!1,keepRatio:!0},q=e=>{const t=(e%180+180)%180;return t<.1||180-t<.1},ee=e=>{if(!e.length){return null}const t=q(e[0].rotation)?0:e[0].rotation;return e.every(e=>q(e.rotation-t))?t:null},te=e=>e.selectedShapes.filter(e=>!e._cropModeEnabled),ne={text:{enabledAnchors:["top-left","top-right","middle-left","bottom-left","bottom-right","middle-right"]},svg:{enabledAnchors:["top-left","top-right","bottom-left","bottom-right"]},gif:{enabledAnchors:["top-left","top-right","bottom-left","bottom-right"]},line:{enabledAnchors:[],borderEnabled:!1,rotateEnabled:!1},image:{enabledAnchors:["top-left","top-right","bottom-left","bottom-right"]},many:{enabledAnchors:["top-left","top-right","bottom-left","bottom-right"]},group:{enabledAnchors:["top-left","top-right","bottom-left","bottom-right"]},table:{keepRatio:!1,enabledAnchors:["top-left","top-center","top-right","middle-left","middle-right","bottom-left","bottom-center","bottom-right"]}};export function registerTransformerAttrs(e,t){ne[e]=ne[e]||t,Object.assign(ne[e],t)}const ie=e=>t(f,Object.assign({},e,{preventDefault:!1})),oe=n=>{var{url:i}=n,o=e(n,["url"]);const[r,l]=I(i,"anonymous"),s=r?j(r,{width:o.width,height:o.height},"center-middle"):{};return O(l,i,"page background"),t(u,Object.assign({image:r},o,s))},re=e=>{const n=J({a:{width:e.width,height:e.height},width:e.width,height:e.height},e.fill);return t(f,Object.assign({},e,n))},le=n=>{var{background:i,transparencyBackgroundColor:r}=n,l=e(n,["background","transparencyBackgroundColor"]);const s=o.useMemo(()=>{if(N(i)){return!0}const e=Y.Util.colorToRGBA(i);return!e||e.a<1},[i]),a=o.useMemo(()=>{if(!s||r){return}const e=document.createElement("canvas"),t=30;e.width=60,e.height=60;const n=e.getContext("2d");return n&&(n.fillStyle="black",n.fillRect(t,0,t,t),n.fillRect(0,t,t,t)),e},[s,r]);return s?t(f,r?Object.assign({fill:r},l,{hideInExport:!0}):Object.assign({fillPatternImage:a},l,{opacity:.1,hideInExport:!0})):null},se=n=>{var{background:i}=n,r=e(n,["background"]);return o.useMemo(()=>!!Y.Util.colorToRGBA(i)||N(i),[i])?t(re,Object.assign({fill:i},r)):t(oe,Object.assign({url:i},r))},ae=r(({selection:e})=>{const{selectionRectStyle:n}=E();return e.visible?t(f,{name:"selection",x:Math.min(e.x1,e.x2),y:Math.min(e.y1,e.y2),width:Math.abs(e.x1-e.x2),height:Math.abs(e.y1-e.y2),fill:n.fill,stroke:n.stroke,strokeWidth:n.strokeWidth}):null});function de(e){let t=180*e/Math.PI;return t%=360,t>180?t-=360:t<-180&&(t+=360),Math.round(t)}const ce=r(({x:e,y:o,width:r,height:l,rotation:s,anchor:a,store:d})=>{const{transformLabelStyle:c}=E();if(void 0===e||void 0===o||void 0===r||void 0===l||void 0===s||void 0===a){return null}const u=T({x:e,y:o,width:r,height:l,rotation:Y.Util.radToDeg(s)}),m=(l/2+70)*Math.cos(s-Math.PI/2),g=(l/2+70)*Math.sin(s-Math.PI/2),f=L({unit:d.unit,dpi:d.dpi,px:r/d.scale,precious:"px"===d.unit?0:1})+" x "+L({unit:d.unit,dpi:d.dpi,px:l/d.scale,precious:"px"===d.unit?0:1})+("px"===d.unit?"":" "+d.unit);return n(i,{children:[n(h,{x:(u.minX+u.maxX)/2+m,y:(u.minY+u.maxY)/2+g,offsetX:14,offsetY:14,visible:"rotater"===a,children:[t(b,{cornerRadius:5,fill:c.fill}),t(y,{align:"center",verticalAlign:"middle",fill:c.textFill,padding:8,text:de(s).toString()+"°"})]}),n(h,{x:(u.minX+u.maxX)/2,y:u.maxY+20,visible:"rotater"!==a,children:[t(b,{cornerRadius:5,fill:c.fill,pointerDirection:"up",pointerHeight:0,pointerWidth:0}),t(y,{align:"center",verticalAlign:"middle",fill:c.textFill,padding:8,text:f})]})]})}),ue=r(({elements:e,store:n})=>{const i=e.filter(e=>e.alwaysOnTop),r=e.filter(e=>!e.alwaysOnTop).concat(i);return t(o.Fragment,{children:r.map(e=>t(S,{store:n,element:e,onClick:()=>{console.warn("Polotno warning: onClick callback is deprecated. Just stop using it. Polotno will do selection automatically.")}},e.id))})});export const useContextMenu=({store:e})=>{const[t,n]=o.useState(!1),[i,r]=o.useState({x:0,y:0}),l=o.useCallback(e=>{n(!0),r(e)},[]);return{open:l,close:o.useCallback(()=>{n(!1)},[]),props:{isOpen:t,offset:i,setIsOpen:n}}};let he=null;export const registerNextDomDrop=e=>{he=e};const me=atob("UG9sb3RubyBmcmVlIGxpY2Vuc2UgbGltaXRhdGlvbiBleGNlZWRlZCAtIFBsZWFzZSB1cGdyYWRlIHlvdXIgYWNjb3VudC4="),ge=atob("I2MwMzkyYg=="),fe=atob("djAuOS4y"),pe=e=>t(i,{children:n(h,{fill:ge,height:200,children:[t(b,{fill:ge}),t(y,Object.assign({},e,{fill:"white",text:me,height:void 0,padding:10,fontSize:20}))]})}),xe=atob("RlJFRSAgVFJJQUwgIExJQ0VOU0U="),ve=(atob("UG93ZXJlZCBieSBQb2xvdG5v"),atob("TElDRU5TRSAgS0VZICBJUyAgTUlTU0lORw==")),be=atob("UGxlYXNlIGFjdGl2YXRlIHlvdXIgbGljZW5zZS4KTGljZW5zZSByZWxhdGVkIHF1ZXN0aW9uczoKcG9sb3Ruby5jb20vY29udGFjdA=="),ye=e=>{const i=1===B(),o=i?ve:xe,r=i?230:195;return n(c,Object.assign({},e,{listening:!1,children:[t(f,{fill:ge,width:r,height:24,cornerRadius:2}),t(y,{text:o,fill:"white",fontSize:13,fontFamily:"monospace",width:r,align:"center",y:5,listening:!1}),i&&t(y,{text:be,fill:"rgba(0,0,0,0.6)",fontSize:14,y:30,listening:!1})]}))};export default r(({store:i,page:r,width:u,height:x,pageControlsEnabled:v,components:S,altCloneEnabled:I,groupSelectionMode:O="drill",viewportSize:j,layout:L="vertical",tooltipSafeArea:J,transformerSafeArea:N})=>{var oe,re;const de=E(),me=de.transformerStyle,ge=Q,xe=r.computedBleed,ve=i.bleedVisible?xe:d,be=r.computedWidth+ve.left+ve.right,we=r.computedHeight+ve.top+ve.bottom,Ee=(u-be*i.scale)/2,Xe=(x-we*i.scale)/2,Ye={x:-xe.left,y:-xe.top,width:r.computedWidth+xe.left+xe.right,height:r.computedHeight+xe.top+xe.bottom,background:r.background,name:"page-background",preventDefault:!1},Se=o.useRef(null),ke=o.useRef(null),Ae=o.useRef(null),Me=o.useRef(null),Ie=null==v||v,Oe=o.useRef(!1),[Pe,je]=o.useState(null),[Re,Be]=o.useState({}),[De,Te]=o.useState(0),Ce=useContextMenu({store:i}),We=i.selectedElements.find(e=>e._cropModeEnabled),Ge=i.selectedElements.find(e=>e.curveEnabled),Le=i.selectedShapes.filter(e=>!e.resizable).length>0,Fe=i.selectedShapes.filter(e=>!e.draggable).length>0,Ve=i.selectedElements.filter(e=>!e.visible).length>0,ze=te(i),Ue=1!==i.selectedElements.length||"group"===(null===(oe=i.selectedElements[0])||void 0===oe?void 0:oe.type),Ze=null!==(re=ee(ze))&&void 0!==re?re:0,_e=e=>Ue&&ze.length>0&&ze.every(t=>((e,t,n)=>{if(!q(e.rotation-n)){return!1}switch(e.type){case"text":return"x"===t&&!Z(e);case"figure":case"video":case"table":return!0;case"image":case"svg":case"gif":return!e.keepRatio;default:return!1}})(t,e,Ze)),He=!Ue&&i.selectedElements[0].keepRatio,Je=_e("x"),Ne=_e("y"),Ke=()=>{var t,n,o;const r=Se.current;if(!r){return[]}const l=r.getStage();if(!l){return[]}const s=te(i),a=s.map(e=>l.findOne("#"+e.id)).filter(e=>!!e),d=1===i.selectedElements.length,c=d&&(null===(t=i.selectedElements[0])||void 0===t?void 0:t.type)||"many",u=ne[c],h=Object.assign(Object.assign({},ge),u||{});u&&("svg"!==c&&"image"!==c&&"gif"!==c||i.selectedElements[0].keepRatio||(h.enabledAnchors=ge.enabledAnchors),"text"===c&&H.textVerticalResizeEnabled&&(h.enabledAnchors=null===(n=ne.text.enabledAnchors)||void 0===n?void 0:n.concat(["bottom-center","top-center"])),"text"===c&&d&&i.selectedElements[0].curveEnabled&&(h.enabledAnchors=ne.many.enabledAnchors)),(Je||Ne)&&(h.enabledAnchors=[...h.enabledAnchors||[],...Je?["middle-left","middle-right"]:[],...Ne?["top-center","bottom-center"]:[]]);const{boundBoxFunc:m}=me,g=e(me,["boundBoxFunc"]);r.setAttrs(Object.assign(Object.assign(Object.assign({},h),g),{name:z})),Le&&r.enabledAnchors([]),Fe&&r.rotateEnabled(!1);const f=r.nodes();if(f.length===a.length&&a.every((e,t)=>f[t]===e)||r.nodes(a),Ue&&a.length){const e=ee(s);null===e||q(r.rotation()-e)||(r.rotation(e),r.forceUpdate())}return null===(o=r.getLayer())||void 0===o||o.batchDraw(),a};o.useLayoutEffect(()=>{var e;if(null===(e=Se.current)||void 0===e?void 0:e.isTransforming()){return}const t=Ke();t.find(e=>null==e?void 0:e.isDragging())&&(t.forEach(e=>{e.isDragging()||null==e||e.startDrag()}),A())},[i.selectedShapes,We,Le,Ve,Fe,Ge,Je,Ne,He,Ze,me]);const $e=()=>{var e,t;const n=Se.current;if(!n){return}if(!n.isTransforming()){return void Be({})}if(!n.nodes().length||!n.isTransforming()){return}const i=n.__getNodeRect(),o=null==n?void 0:n.getActiveAnchor(),r=n.getStage();Be({anchor:o,x:i.x-(null!==(e=null==r?void 0:r.x())&&void 0!==e?e:0),y:i.y-(null!==(t=null==r?void 0:r.y())&&void 0!==t?t:0),rotation:i.rotation,width:i.width,height:i.height})},Qe=o.useCallback(()=>{var e;if(null===(e=Se.current)||void 0===e?void 0:e.isTransforming()){return}const t=Se.current;if(!t||!t.nodes().length){return void Te(0)}const n=t.getClientRect();if(!t.getStage()){return}const i=function(e,t,n,i=0){const o=e.x+e.width/2,r=e.y+e.height/2,l=e.width/2,s=e.height/2,a=i*Math.PI/180,d=e=>{const t=e*Math.PI/180,i=(e%360+360)%360;let d;d=0===i||180===i?s:l;const c=Math.sin(t)*(d+n),u=-Math.cos(t)*(d+n),h=c*Math.cos(a)-u*Math.sin(a),m=c*Math.sin(a)+u*Math.cos(a);return{x:o+h,y:r+m}},c=e=>e.x>=t.left&&e.x<=t.right&&e.y>=t.top&&e.y<=t.bottom;if(c(d(0))){return 0}for(const u of[180,270,90]){if(c(d(u))){return u}}return 0}(n,{top:(null==N?void 0:N.top)||0,bottom:x-((null==N?void 0:N.bottom)||0),left:(null==N?void 0:N.left)||0,right:u-((null==N?void 0:N.right)||0)},me.rotateAnchorOffset,t.rotation());Te(i)},[N,u,x]);o.useEffect(()=>{var e;null===(e=Se.current)||void 0===e||e.update(),$e(),Qe()},[i.scale,Qe]),o.useEffect(()=>{Qe()},[i.selectedShapes,Qe]);const qe=l(()=>({visible:!1,x1:0,y1:0,x2:0,y2:0})),et=o.useRef(!1),tt=e=>{const t=Ae.current;if(!t||i.role===X.VIEWER||i.activePage!==r||i.isPlaying||"button"in e.evt&&0!==e.evt.button||1!==t.getPointersPositions().length||!e.target.findAncestor(".elements-container")||!e.target.findAncestor(".element",!0)||!i.selectedShapes.length||i.selectedShapes.some(e=>!e.draggable)){return}const n=t.getPointerPosition();if(!n){return}const o=Ke();if(o.some(t=>t===e.target||t.isAncestorOf(e.target))){return}const l=o.find(e=>!!(e.draggable()&&e.isVisible()&&e.isListening())&&(e instanceof Y.Shape?[e]:e instanceof Y.Container?e.find("Shape"):[]).some(e=>e.intersects(n)));if(l){for(const[t,n]of Y.DD._dragElements){"ready"!==n.dragStatus||n.node!==e.target&&!n.node.isAncestorOf(e.target)||Y.DD._dragElements.delete(t)}l._createDragElement(e),"touches"in e.evt&&e.evt.cancelable&&l.preventDefault()&&e.evt.preventDefault()}},nt=s(e=>{var t,n,o,r,l,s,a;if(i.role===X.VIEWER){return}et.current=!1;const d=e.target.findAncestor(".elements-container"),c=e.target.findAncestor("Transformer"),u=e.target.findAncestor(".page-abs-container");if(d||c||u){return}const h=null===(t=e.target.getStage())||void 0===t?void 0:t.getPointerPosition();h&&(h.x-=null!==(o=null===(n=e.target.getStage())||void 0===n?void 0:n.x())&&void 0!==o?o:0,h.y-=null!==(l=null===(r=e.target.getStage())||void 0===r?void 0:r.y())&&void 0!==l?l:0,qe.visible=!0,qe.x1=h.x,qe.y1=h.y,qe.x2=h.x,qe.y2=h.y,(null!==(a=null===(s=e.target.getStage())||void 0===s?void 0:s.getPointersPositions().length)&&void 0!==a?a:0)>=2&&(qe.visible=!1))});(({stageRef:e,containerRef:t,viewportSize:n})=>{o.useEffect(()=>{var n;const i=null===(n=t.current)||void 0===n?void 0:n.closest(".polotno-workspace-inner");function o(){var n;if(!e.current){return}const o=null===(n=t.current)||void 0===n?void 0:n.getBoundingClientRect(),r=null==i?void 0:i.getBoundingClientRect();if(!o||!r){return}const l=Math.max(0,r.left-o.left-100),s=Math.max(0,r.top-o.top-100);e.current.position({x:-l,y:-s}),e.current.container().style.transform=`translate(${l}px, ${s}px)`}return o(),null==i||i.addEventListener("scroll",o),()=>{null==i||i.removeEventListener("scroll",o)}},[n.width,n.height])})({stageRef:Ae,containerRef:Me,viewportSize:j}),o.useEffect(()=>{const e=s(e=>{var t,n,i,o,r,l;if(!qe.visible){return}null===(t=Ae.current)||void 0===t||t.setPointersPositions(e);let s=null===(n=Ae.current)||void 0===n?void 0:n.getPointerPosition();s?(s.x-=null!==(o=null===(i=Ae.current)||void 0===i?void 0:i.x())&&void 0!==o?o:0,s.y-=null!==(l=null===(r=Ae.current)||void 0===r?void 0:r.y())&&void 0!==l?l:0):s={x:qe.x2,y:qe.y2},qe.x2=s.x,qe.y2=s.y}),t=s(()=>{if(!qe.visible){return}if(!Ae.current){return}const e=Ae.current.findOne(".selection"),t=e?e.getClientRect({skipStroke:!0}):{width:0,height:0,x:0,y:0};if(t.width&&t.height){const e=[{x:t.x,y:t.y},{x:t.x+t.width,y:t.y},{x:t.x+t.width,y:t.y+t.height},{x:t.x,y:t.y+t.height}],n=[];Ae.current.find(".element").forEach(t=>{var o;const r=i.getElementById(t.id()),l=null==r?void 0:r.draggable,s=null==r?void 0:r.selectable;if(!l||!s){return}const a=null===(o=t.getParent())||void 0===o?void 0:o.getAbsoluteTransform();if(!a){return}const d=C(r.a).map(e=>a.point(e));G(e,d)&&n.push(r.top.id)});const o=[...new Set(n)];et.current=!0,i.selectElements(o)}qe.visible=!1});return window.addEventListener("mousemove",e),window.addEventListener("touchmove",e),window.addEventListener("mouseup",t,{capture:!0}),window.addEventListener("touchend",t,{capture:!0}),()=>{window.removeEventListener("mousemove",e),window.removeEventListener("touchmove",e),window.removeEventListener("mouseup",t),window.removeEventListener("touchend",t)}},[]);const it=o.useCallback(e=>{if(!i.selectedElements[0]){return}if(e&&i.selectedElementsIds.includes(e)){return}const t=W(i.selectedShapes),n=e?i.getElementById(e):{x:0,y:0,width:r.computedWidth,height:r.computedHeight,rotation:0},o=T(n),l=[];t.minX>o.maxX&&l.push({distance:t.minX-o.maxX,box1:t,box2:o,points:[{x:t.minX,y:t.minY+t.height/2},{x:o.maxX,y:t.minY+t.height/2},{x:o.maxX,y:o.minY+o.height/2}]}),t.maxX<o.minX&&l.push({distance:o.minX-t.maxX,box1:t,box2:o,points:[{x:t.maxX,y:t.minY+t.height/2},{x:o.minX,y:t.minY+t.height/2},{x:o.minX,y:o.minY+o.height/2}]}),t.minY>o.maxY&&l.push({box1:t,box2:o,distance:t.minY-o.maxY,points:[{x:t.minX+t.width/2,y:t.minY},{x:t.minX+t.width/2,y:o.maxY},{x:o.minX+o.width/2,y:o.maxY}]}),t.maxY<o.minY&&l.push({box1:t,box2:o,distance:o.minY-t.maxY,points:[{x:t.minX+t.width/2,y:t.maxY},{x:t.minX+t.width/2,y:o.minY},{x:o.minX+o.width/2,y:o.minY}]});const s=t.minX>=o.minX&&t.maxX<=o.maxX&&t.minY>=o.minY&&t.maxY<=o.maxY;if(s&&(l.push({distance:t.minX-o.minX,box1:t,box2:o,points:[{x:t.minX,y:t.minY+t.height/2},{x:o.minX,y:t.minY+t.height/2},{x:o.minX,y:o.minY+o.height/2}]}),l.push({distance:o.maxX-t.maxX,box1:t,box2:o,points:[{x:t.maxX,y:t.minY+t.height/2},{x:o.maxX,y:t.minY+t.height/2},{x:o.maxX,y:o.minY+o.height/2}]}),l.push({box1:t,box2:o,distance:t.minY-o.minY,points:[{x:t.minX+t.width/2,y:t.minY},{x:t.minX+t.width/2,y:o.minY},{x:o.minX+o.width/2,y:o.minY}]}),l.push({box1:t,box2:o,distance:o.maxY-t.maxY,points:[{x:t.minX+t.width/2,y:t.maxY},{x:t.minX+t.width/2,y:o.maxY},{x:o.minX+o.width/2,y:o.maxY}]})),0===l.length&&!s){const e=t.minX<o.maxX&&t.maxX>o.minX,n=t.minY<o.maxY&&t.maxY>o.minY;if(e&&n){const e=(Math.max(t.minY,o.minY)+Math.min(t.maxY,o.maxY))/2,n=(Math.max(t.minX,o.minX)+Math.min(t.maxX,o.maxX))/2;t.minX<o.minX?l.push({distance:o.minX-t.minX,box1:t,box2:o,points:[{x:t.minX,y:e},{x:o.minX,y:e},{x:o.minX,y:e}]}):l.push({distance:t.minX-o.minX,box1:t,box2:o,points:[{x:t.minX,y:e},{x:o.minX,y:e},{x:o.minX,y:e}]}),t.maxX>o.maxX?l.push({distance:t.maxX-o.maxX,box1:t,box2:o,points:[{x:o.maxX,y:e},{x:t.maxX,y:e},{x:o.maxX,y:e}]}):l.push({distance:o.maxX-t.maxX,box1:t,box2:o,points:[{x:t.maxX,y:e},{x:o.maxX,y:e},{x:o.maxX,y:e}]}),t.minY<o.minY?l.push({box1:t,box2:o,distance:o.minY-t.minY,points:[{x:n,y:t.minY},{x:n,y:o.minY},{x:n,y:o.minY}]}):l.push({box1:t,box2:o,distance:t.minY-o.minY,points:[{x:n,y:t.minY},{x:n,y:o.minY},{x:n,y:o.minY}]}),t.maxY>o.maxY?l.push({box1:t,box2:o,distance:t.maxY-o.maxY,points:[{x:n,y:o.maxY},{x:n,y:t.maxY},{x:n,y:o.maxY}]}):l.push({box1:t,box2:o,distance:o.maxY-t.maxY,points:[{x:n,y:t.maxY},{x:n,y:o.maxY},{x:n,y:o.maxY}]})}}JSON.stringify(Pe)!==JSON.stringify(l)&&je(l)},[i,r]);o.useEffect(()=>{i.selectedElements[0]&&i.distanceGuidesVisible?it():Pe&&je(null)},[i.distanceGuidesVisible,it,i.selectedShapes.map(e=>`${e.x},${e.y},${e.width},${e.height},${e.rotation}`).join("|")]);const ot=o.useRef(!1);o.useEffect(()=>{var e;let t;const n=null===(e=Me.current)||void 0===e?void 0:e.closest(".polotno-workspace-inner"),i=()=>{ot.current=!0,clearTimeout(t),t=setTimeout(()=>{ot.current=!1},300)};return null==n||n.addEventListener("scroll",i),()=>{clearTimeout(t),null==n||n.removeEventListener("scroll",i)}},[]),o.useEffect(()=>{const e=Ae.current;if(!e){return}const t=e.container(),n=new Map,o=e=>{var t,i;n.has(e.target)||[e.target,...null!==(i=null===(t=Se.current)||void 0===t?void 0:t.nodes())&&void 0!==i?i:[]].forEach(e=>{n.has(e)||n.set(e,{x:e.x(),y:e.y()})})},r=e=>{e.target===Se.current?n.clear():n.delete(e.target)};e.on("dragstart",o),e.on("dragend",r);const l=e=>{e.touches.length>=2&&a(()=>{var e,t;const o=new Map(n);(null===(e=Se.current)||void 0===e?void 0:e.isDragging())&&Se.current.stopDrag(),null===(t=Se.current)||void 0===t||t.nodes().forEach(e=>{var t;const n=o.get(e);e.isDragging()&&e.stopDrag(),n&&(e.setAttrs(n),null===(t=i.getElementById(e.id()))||void 0===t||t.set({x:n.x,y:n.y}))})})};return t.addEventListener("touchstart",l,{passive:!0}),t.addEventListener("touchmove",l,{passive:!0}),()=>{e.off("dragstart",o),e.off("dragend",r),t.removeEventListener("touchstart",l),t.removeEventListener("touchmove",l)}},[i]);const rt=e=>{if(i.role===X.VIEWER){return}if(i.activePage!==r&&r.select(),ot.current){return}if(et.current){return}const t=e.evt.shiftKey,n=e.evt.ctrlKey||e.evt.metaKey,o=t||n,l=e.target.findAncestor(".elements-container"),s=e.target.findAncestor(".page-abs-container"),a=e.target.findAncestor("Transformer"),d=e.target.findAncestor(".page-container",!0);if(!(o||l||a||s||d||qe.visible)){return i.selectElements([]),void i.selectPages([])}if(n&&!t){const e=Ae.current,t=null==e?void 0:e.getPointerPosition();if(!e||!t){return}const n=e.getAllIntersections(t),o=new Set,r=[];for(const s of[...n].reverse()){const e=s.findAncestor(".element",!0);if(!e){continue}const t=i.getElementById(e.id()),n=null==t?void 0:t.top;n&&(o.has(n.id)||(o.add(n.id),r.push(n.id)))}if(0===r.length){return}let l;if(1===i.selectedElementsIds.length){const e=i.selectedElementsIds[0],t=r.indexOf(e);l=-1===t?r[0]:r[(t+1)%r.length]}else{l=r[0]}return i.selectElements([l]),void i.selectPages([])}const c=e.target.findAncestor(".element-container",!0),u=(null==c?void 0:c.findOne(".element"))||e.target.findAncestor(".element",!0),h=i.getElementById(null==u?void 0:u.id()),m=null==h?void 0:h.top;let g;if("group"===O){g=null==m?void 0:m.id}else if(m){const e=i.selectedElements.some(e=>{var t;return(null===(t=e.top)||void 0===t?void 0:t.id)===m.id});g=e?null==h?void 0:h.id:null==m?void 0:m.id}else{g=void 0}const f=null==h?void 0:h.id;if(f&&i.selectedElementsIds.indexOf(f)>=0&&!t){return}const p=!!g&&i.selectedElementsIds.indexOf(g)>=0,x=e.target.findAncestor(".page-container",!0);if(g&&t&&!p){const e=i.selectedElementsIds.concat([g]),t=new Set(e),n=e.filter(e=>{const n=i.getElementById(e);if(!n){return!1}for(let i=n.parent;i;i=null==i?void 0:i.parent){if(t.has(i.id)){return!1}}return!0});i.selectElements(n),i.selectPages([])}else{g&&t&&p?i.selectElements(i.selectedElementsIds.filter(e=>e!==g)):!g||t||p?g&&!t&&p||(x?(t||i.selectElements([]),i.selectPages([r.id])):i.selectPages([])):(i.selectElements([g]),i.selectPages([]))}};M(Se,i);const lt=i.activePage===r,st=i._selectedPagesIds.includes(r.id),at=null==S?void 0:S.PageControls,dt=null==S?void 0:S.Tooltip,ct=null==S?void 0:S.ContextMenu,ut=1/i.scale,ht=0/i.scale;return n("div",{ref:Me,onDragOver:e=>e.preventDefault(),onDrop:e=>{if(e.preventDefault(),i.role===X.VIEWER){return}if(!Ae.current){return}Ae.current.setPointersPositions(e);const t=Ae.current.findOne(".elements-container"),n=null==t?void 0:t.getRelativePointerPosition(),o=Ae.current.getPointerPosition(),l=Ae.current.getAllIntersections(o).map(e=>e.findAncestor(".element",!0)).filter(Boolean),s=[...new Set(l.reverse())].map(e=>i.getElementById(e.id())).filter(e=>!!e),a=s[0];he&&n&&(he(n,a,{elements:s,page:r}),he=null)},style:{position:"relative",width:u+"px",height:x+"px",overflow:"hidden",flexShrink:0},className:"polotno-page-container"+(lt?" active-page":""),children:[t($,{ref:Ae,eventBatchFunc:a,width:Math.min(u,j.width+200),height:Math.min(j.height+200,x),onClick:rt,onTap:rt,onContextMenu:e=>{if(e.evt.preventDefault(),i.role===X.VIEWER){return}const t=e.target.findAncestor(".element",!0),n=i.getElementById(null==t?void 0:t.id()),o=null==n?void 0:n.top,r=null==o?void 0:o.id;if(!r){return i.selectElements([]),void Ce.close()}i.selectedElementsIds.indexOf(r)>=0||i.selectElements([r]),Ce.open({x:e.evt.clientX,y:e.evt.clientY})},onMouseDown:e=>{tt(e),nt(e)},onTouchStart:tt,onMouseMove:e=>{if(!i.distanceGuidesVisible&&!e.evt.altKey){return void(Pe&&je(null))}const t=e.target.findAncestor(".element",!0),n=null==t?void 0:t.id();it(n)},onDragStart:e=>{var t;const n=e.target.getStage();if(n&&n.getPointersPositions().length>=2){return void e.target.stopDrag()}const o=e.target.findAncestor(".element",!0);if(o){const n=i.getElementById(null==o?void 0:o.id()),r=null==n?void 0:n.top,l=null==r?void 0:r.id;if(!(n&&i.selectedElementsIds.indexOf(n.id)>=0||l&&i.selectedElementsIds.indexOf(l)>=0)&&l){i.selectElements([l]);const n=Ke();e.target.stopDrag(),n.forEach(t=>{t.isDragging()||t.startDrag(e)}),null===(t=Se.current)||void 0===t||t.startDrag(e),A()}}Pe&&je(null)},onDragMove:e=>{const t=Se.current;t&&e.target===t&&t.nodes().forEach(e=>{const t=i.getElementById(e.id());!t||t.x===e.x()&&t.y===e.y()||t.set({x:e.x(),y:e.y()})})},pageId:r.id,style:{position:"absolute",overflow:"hidden",top:0,left:0},children:n(m,{children:[t(ie,{width:u,height:x,fill:de.workspaceBackgroundColor}),t(c,{x:Ee,y:Xe,scaleX:i.scale,scaleY:i.scale,name:"page-container",children:n(c,{name:"page-container-2",children:[t(c,{x:ve.left,y:ve.top,children:t(le,Object.assign({},Ye,{transparencyBackgroundColor:de.transparencyBackgroundColor}))}),n(c,{isolated:r.hasBlendMode,children:[t(c,{name:"page-background-group",x:ve.left,y:ve.top,children:t(se,Object.assign({},Ye))}),n(c,{x:ve.left,y:ve.top,name:"elements-container",listening:!i.isPlaying&&i.role!==X.VIEWER,children:[t(f,{name:"elements-area",width:r.computedWidth,height:r.computedHeight,listening:!1}),t(ue,{elements:r.children,store:i})]})]}),t(p,{name:"bleed",fill:de.bleedColor,listening:!1,visible:i.bleedVisible&&(ve.top>0||ve.right>0||ve.bottom>0||ve.left>0),hideInExport:!0,sceneFunc:(e,t)=>{const{top:n,right:i,bottom:o,left:l}=xe,s=r.computedWidth,a=r.computedHeight,d=e._context;d.beginPath(),d.rect(0,0,l+s+i,n+a+o),d.rect(l,n,s,a),d.fillStyle=t.fill(),d.fill("evenodd")}}),R()===fe&&t(pe,{name:"hit-detection",x:-ut/2-ht,y:-ut/2-ht,width:be+ut+2*ht,height:we+ut+2*ht})]})}),t(g,{name:"workspace-background",points:[0,0,u,0,u,x,0,x,0,0,Ee,Xe,Ee,x-Xe,u-Ee,x-Xe,u-Ee,Xe,Ee,Xe],listening:!1,closed:!0,fill:de.workspaceBackgroundColor}),t(c,{x:Ee,y:Xe,scaleX:i.scale,scaleY:i.scale,children:t(f,{name:"page-highlight",hideInExport:!0,x:-ut/2-ht,y:-ut/2-ht,width:be+ut+2*ht,height:we+ut+2*ht,stroke:st?de.activePageBorderColor:de.pageBorderColor,strokeWidth:2,listening:!1,strokeScaleEnabled:!1})}),n(c,{x:Ee+ve.left*i.scale,y:Xe+ve.top*i.scale,scaleX:i.scale,scaleY:i.scale,name:"page-abs-container",children:[t(w,{ref:Se,name:z,rotateAnchorAngle:De,onDragStart:e=>{var t;const n=e.target.getStage();n&&n.getPointersPositions().length>=2?e.target.stopDrag():((null===(t=e.evt)||void 0===t?void 0:t.altKey)&&I&&i.selectedElements.forEach(e=>{const t=e.clone({},{skipSelect:!0}),n=r.children.indexOf(e);r.setElementZIndex(t.id,n)}),Oe.current||(Oe.current=!0,i.history.startTransaction()))},onDragEnd:()=>{Oe.current&&(i.history.endTransaction(),Oe.current=!1),Qe()},onTransformStart:()=>{i.history.startTransaction(),ke.current=new Map(ze.map(e=>[e.id,{width:e.width,height:e.height}])),je(null)},boundBoxFunc:(e,t)=>{var n,o,r,l;const s=null!==(o=null===(n=me.boundBoxFunc)||void 0===n?void 0:n.call(me,e,t))&&void 0!==o?o:t,a=Math.abs(s.width)<1||Math.abs(s.height)<1,d=Math.abs(e.width)<1||Math.abs(e.height)<1;if(a&&!d){return e}const c=i.selectedElements;if(1===c.length&&"table"===(null===(r=c[0])||void 0===r?void 0:r.type)){const t=c[0],n=Math.abs(e.width),i=Math.abs(e.height);if(n>0&&i>0){const o=Math.abs(s.width)/n,r=Math.abs(s.height)/i,l=t.width*o,a=t.height*r,d=Object.assign({},s);return l<t.minWidth&&(d.width=e.width),a<t.minHeight&&(d.height=e.height),_(d,s,e)}}return Ue&&ze.length>0?((e,t,n,i,o)=>{const r=Math.abs(e.width),l=Math.abs(e.height);if(0===r||0===l){return t}const s=Math.abs(t.width)/r,a=Math.abs(t.height)/l,d=!V(n),c=e=>i.some(t=>{var n;const i=null==o?void 0:o.get(t.id),r=null!==(n="x"===e?null==i?void 0:i.width:null==i?void 0:i.height)&&void 0!==n?n:"x"===e?t.width:t.height,l="x"===e?t.width:t.height,c="x"===e?s:a,u=((e,t,n,i)=>{if("table"===e.type){const n=e;return"x"===t?n.minWidth:n.minHeight}return"text"===e.type&&"x"===t&&n?U(i,e.fontSize):1})(t,e,d,r);return r>=u&&l*c<u}),u=Object.assign({},t),h=t.width*e.width<0,m=t.height*e.height<0,g=h||c("x"),f=m||c("y"),p=f||!d&&g;return(g||!d&&f)&&(u.width=e.width),p&&(u.height=e.height),_(u,t,e)})(e,s,(null===(l=Se.current)||void 0===l?void 0:l.getActiveAnchor())||"",ze,ke.current):s},onTransform:e=>{const t=Se.current.nodes(),n=t[t.length-1];e.target===n&&setTimeout(()=>{$e()},0)},onTransformEnd:e=>{Be({}),i.history.endTransaction(),ke.current=null,Qe(),Ke()},visible:!i.isPlaying}),Pe&&Pe.map(({points:e,distance:o,box1:r,box2:l},s)=>n(c,{name:"distances-container",hideInExport:!0,listening:!1,children:[t(f,Object.assign({},r,{stroke:de.distanceGuideStyle.stroke,strokeWidth:1,strokeScaleEnabled:!1})),t(f,Object.assign({},l,{stroke:de.distanceGuideStyle.stroke,strokeWidth:1,strokeScaleEnabled:!1})),t(g,{points:[e[0].x,e[0].y,e[1].x,e[1].y],stroke:de.distanceGuideStyle.stroke,strokeWidth:1,strokeScaleEnabled:!1}),t(g,{points:[e[1].x,e[1].y,e[2].x,e[2].y],stroke:de.distanceGuideStyle.stroke,strokeWidth:1,strokeScaleEnabled:!1}),n(h,{x:(e[0].x+e[1].x)/2,y:(e[0].y+e[1].y)/2,offsetY:-10,scaleX:1/i.scale,scaleY:1/i.scale,children:[t(b,{cornerRadius:5,fill:de.distanceGuideStyle.labelFill,pointerDirection:"down"}),t(y,{align:"center",verticalAlign:"middle",fill:de.distanceGuideStyle.labelTextFill,padding:5,text:F({unit:i.unit,dpi:i.dpi,px:o})})]})]},s)),r._rendering&&n(c,{children:[t(f,{width:be,height:we,fill:"rgba(255,255,255,0.9)"}),t(y,{text:"Rendering...",fontSize:60,width:be,height:we,align:"center",verticalAlign:"middle"})]}),dt&&t(dt,{components:S,store:i,page:r,stageRef:Ae,tooltipSafeArea:J}),ct&&t(K,{children:t(ct,Object.assign({components:S,store:i},Ce.props))}),t(P,{store:i,pageId:r.id})]}),t(k,{store:i,page:r,width:u,height:x,scale:i.scale,xPadding:Ee,yPadding:Xe,bleedLeft:ve.left,bleedTop:ve.top}),t(ce,Object.assign({},Re,{store:i})),t(ae,{selection:qe}),B()>0&&n(c,{hideInExport:!0,children:[t(ye,{name:"cache-bounds",x:u-(1===B()?250:210),y:x-(1===B()?95:45)}),t(ye,{name:"cache-bounds-t",x:10,y:10})]}),D()&&t(y,{text:"Powered by polotno.com",fontSize:14,fill:"rgba(0,0,0,0.6)",x:u-170,y:x-18,onMouseEnter:e=>{e.target.getStage().container().style.cursor="pointer"},onMouseLeave:e=>{e.target.getStage().container().style.cursor=""},onTouchStart:e=>{e.cancelBubble=!0},onMouseDown:e=>{e.cancelBubble=!0},onClick:()=>{window.open("https://polotno.com","_blank","noopener")},onTap:()=>{window.open("https://polotno.com","_blank","noopener")}}),t(c,{name:"line-guides"})]})}),Ie&&at&&t(at,{store:i,page:r,xPadding:Ee,yPadding:Xe,layout:L})]})});
1
+ var e=this&&this.__rest||function(e,t){var n={};for(var i in e){Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i])}if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(i=Object.getOwnPropertySymbols(e);o<i.length;o++){t.indexOf(i[o])<0&&Object.prototype.propertyIsEnumerable.call(e,i[o])&&(n[i[o]]=e[i[o]])}}return n};import{jsx as t,jsxs as n,Fragment as i}from"react/jsx-runtime";import o from"react";import{observer as r,useLocalObservable as l}from"mobx-react-lite";import{action as s,runInAction as a}from"mobx";import{ZERO_BLEED as c}from"@polotno/schema";import{Group as d,Image as u,Label as h,Layer as m,Line as g,Rect as f,Shape as p,Stage as x,KonvaRenderer as v,Tag as b,Text as y,Transformer as w}from"react-konva";import{useWorkspaceStyle as E}from"./workspace-style.js";import{ROLES as X}from"../model/store.js";import Y from"konva";import S from"./element.js";import{DrawingLayer as k}from"./drawing-layer.js";import{ensureDragOrder as A,useSnap as I}from"./use-transformer-snap.js";import{useCanvasImage as M,useImageLoader as O}from"./image-element.js";import{FadeOverlay as P}from"./fade-overlay.js";import{getCrop as j}from"../utils/crop.js";import{___ as R,____ as T,isCreditVisible as B}from"../utils/validate-key.js";import{getClientRect as D,getCorners as C,getTotalClientRect as W,polygonsIntersect as G}from"../utils/math.js";import{pxToUnitRounded as L,pxToUnitString as F}from"../utils/unit.js";import{isCornerAnchor as V,MAIN_TRANSFORMER_NAME as z,textMinResizeWidth as U,textMinWidthIsMeasured as Z}from"../utils/px.js";import{restoreHeldPoint as _}from"./transform-box.js";import{flags as H}from"../utils/flags.js";import{useColor as J}from"./use-color.js";import{isGradient as N}from"@polotno/core/gradient";import{toDisplayColor as K}from"@polotno/core/color";import{Html as $}from"react-konva-utils";const Q=o.version.startsWith("18.")?o.forwardRef((e,n)=>(o.useLayoutEffect(()=>{v.flushSync()}),t(x,Object.assign({},e,{ref:n})))):x,q={enabledAnchors:["top-left","top-center","top-right","middle-left","bottom-left","bottom-right","bottom-center","middle-right"],rotateEnabled:!0,rotationSnaps:[0,45,90,135,180,225,270,315],ignoreStroke:!0,flipEnabled:!1,keepRatio:!0},ee=e=>{const t=(e%180+180)%180;return t<.1||180-t<.1},te=e=>{if(!e.length){return null}const t=ee(e[0].rotation)?0:e[0].rotation;return e.every(e=>ee(e.rotation-t))?t:null},ne=e=>e.selectedShapes.filter(t=>{var n;return(null===(n=e.activeTool)||void 0===n?void 0:n.elementId)!==t.id&&!t.pendingEdit}),ie={text:{enabledAnchors:["top-left","top-right","middle-left","bottom-left","bottom-right","middle-right"]},svg:{enabledAnchors:["top-left","top-right","bottom-left","bottom-right"]},gif:{enabledAnchors:["top-left","top-right","bottom-left","bottom-right"]},line:{enabledAnchors:[],borderEnabled:!1,rotateEnabled:!1},image:{enabledAnchors:["top-left","top-right","bottom-left","bottom-right"]},many:{enabledAnchors:["top-left","top-right","bottom-left","bottom-right"]},group:{enabledAnchors:["top-left","top-right","bottom-left","bottom-right"]},table:{keepRatio:!1,enabledAnchors:["top-left","top-center","top-right","middle-left","middle-right","bottom-left","bottom-center","bottom-right"]}};export function registerTransformerAttrs(e,t){ie[e]=ie[e]||t,Object.assign(ie[e],t)}const oe=e=>t(f,Object.assign({},e,{preventDefault:!1})),re=n=>{var{url:i}=n,o=e(n,["url"]);const[r,l]=M(i,"anonymous"),s=r?j(r,{width:o.width,height:o.height},"center-middle"):{};return O(l,i,"page background"),t(u,Object.assign({image:r},o,s))},le=e=>{const n=J({a:{width:e.width,height:e.height},width:e.width,height:e.height},e.fill);return t(f,Object.assign({},e,n))},se=n=>{var{background:i,transparencyBackgroundColor:r}=n,l=e(n,["background","transparencyBackgroundColor"]);const s=o.useMemo(()=>{if(N(i)){return!0}const e=Y.Util.colorToRGBA(i);return!e||e.a<1},[i]),a=o.useMemo(()=>{if(!s||r){return}const e=document.createElement("canvas"),t=30;e.width=60,e.height=60;const n=e.getContext("2d");return n&&(n.fillStyle="black",n.fillRect(t,0,t,t),n.fillRect(0,t,t,t)),e},[s,r]);return s?t(f,r?Object.assign({fill:r},l,{hideInExport:!0}):Object.assign({fillPatternImage:a},l,{opacity:.1,hideInExport:!0})):null},ae=n=>{var{background:i}=n,r=e(n,["background"]);return o.useMemo(()=>!!Y.Util.colorToRGBA(i)||N(i),[i])?t(le,Object.assign({fill:i},r)):t(re,Object.assign({url:i},r))},ce=r(({selection:e})=>{const{selectionRectStyle:n}=E();return e.visible?t(f,{name:"selection",x:Math.min(e.x1,e.x2),y:Math.min(e.y1,e.y2),width:Math.abs(e.x1-e.x2),height:Math.abs(e.y1-e.y2),fill:n.fill,stroke:n.stroke,strokeWidth:n.strokeWidth}):null});function de(e){let t=180*e/Math.PI;return t%=360,t>180?t-=360:t<-180&&(t+=360),Math.round(t)}const ue=r(({x:e,y:o,width:r,height:l,rotation:s,anchor:a,store:c})=>{const{transformLabelStyle:d}=E();if(void 0===e||void 0===o||void 0===r||void 0===l||void 0===s||void 0===a){return null}const u=D({x:e,y:o,width:r,height:l,rotation:Y.Util.radToDeg(s)}),m=(l/2+70)*Math.cos(s-Math.PI/2),g=(l/2+70)*Math.sin(s-Math.PI/2),f=L({unit:c.unit,dpi:c.dpi,px:r/c.scale,precious:"px"===c.unit?0:1})+" x "+L({unit:c.unit,dpi:c.dpi,px:l/c.scale,precious:"px"===c.unit?0:1})+("px"===c.unit?"":" "+c.unit);return n(i,{children:[n(h,{x:(u.minX+u.maxX)/2+m,y:(u.minY+u.maxY)/2+g,offsetX:14,offsetY:14,visible:"rotater"===a,children:[t(b,{cornerRadius:5,fill:d.fill}),t(y,{align:"center",verticalAlign:"middle",fill:d.textFill,padding:8,text:de(s).toString()+"°"})]}),n(h,{x:(u.minX+u.maxX)/2,y:u.maxY+20,visible:"rotater"!==a,children:[t(b,{cornerRadius:5,fill:d.fill,pointerDirection:"up",pointerHeight:0,pointerWidth:0}),t(y,{align:"center",verticalAlign:"middle",fill:d.textFill,padding:8,text:f})]})]})}),he=r(({elements:e,store:n})=>{const i=e.filter(e=>e.alwaysOnTop),r=e.filter(e=>!e.alwaysOnTop).concat(i);return t(o.Fragment,{children:r.map(e=>t(S,{store:n,element:e,onClick:()=>{console.warn("Polotno warning: onClick callback is deprecated. Just stop using it. Polotno will do selection automatically.")}},e.id))})});export const useContextMenu=({store:e})=>{const[t,n]=o.useState(!1),[i,r]=o.useState({x:0,y:0}),l=o.useCallback(e=>{n(!0),r(e)},[]);return{open:l,close:o.useCallback(()=>{n(!1)},[]),props:{isOpen:t,offset:i,setIsOpen:n}}};let me=null;export const registerNextDomDrop=e=>{me=e};const ge=atob("UG9sb3RubyBmcmVlIGxpY2Vuc2UgbGltaXRhdGlvbiBleGNlZWRlZCAtIFBsZWFzZSB1cGdyYWRlIHlvdXIgYWNjb3VudC4="),fe=atob("I2MwMzkyYg=="),pe=atob("djAuOS4y"),xe=e=>t(i,{children:n(h,{fill:fe,height:200,children:[t(b,{fill:fe}),t(y,Object.assign({},e,{fill:"white",text:ge,height:void 0,padding:10,fontSize:20}))]})}),ve=atob("RlJFRSAgVFJJQUwgIExJQ0VOU0U="),be=(atob("UG93ZXJlZCBieSBQb2xvdG5v"),atob("TElDRU5TRSAgS0VZICBJUyAgTUlTU0lORw==")),ye=atob("UGxlYXNlIGFjdGl2YXRlIHlvdXIgbGljZW5zZS4KTGljZW5zZSByZWxhdGVkIHF1ZXN0aW9uczoKcG9sb3Ruby5jb20vY29udGFjdA=="),we=e=>{const i=1===T(),o=i?be:ve,r=i?230:195;return n(d,Object.assign({},e,{listening:!1,children:[t(f,{fill:fe,width:r,height:24,cornerRadius:2}),t(y,{text:o,fill:"white",fontSize:13,fontFamily:"monospace",width:r,align:"center",y:5,listening:!1}),i&&t(y,{text:ye,fill:"rgba(0,0,0,0.6)",fontSize:14,y:30,listening:!1})]}))};export default r(({store:i,page:r,width:u,height:x,pageControlsEnabled:v,components:S,altCloneEnabled:M,groupSelectionMode:O="drill",viewportSize:j,layout:L="vertical",tooltipSafeArea:J,transformerSafeArea:N})=>{var re,le;const de=E(),ge=de.transformerStyle,fe=q,ve=r.computedBleed,be=i.bleedVisible?ve:c,ye=r.computedWidth+be.left+be.right,Ee=r.computedHeight+be.top+be.bottom,Xe=(u-ye*i.scale)/2,Ye=(x-Ee*i.scale)/2,Se={x:-ve.left,y:-ve.top,width:r.computedWidth+ve.left+ve.right,height:r.computedHeight+ve.top+ve.bottom,background:K(r.background),name:"page-background",preventDefault:!1},ke={x:-be.left,y:-be.top,width:ye,height:Ee},Ae=o.useRef(null),Ie=o.useRef(null),Me=o.useRef(null),Oe=o.useRef(null),Pe=null==v||v,je=o.useRef(!1),[Re,Te]=o.useState(null),[Be,De]=o.useState({}),[Ce,We]=o.useState(0),Ge=useContextMenu({store:i}),Le=i.selectedElements.find(e=>e.curveEnabled),Fe=i.selectedShapes.filter(e=>!e.resizable).length>0,Ve=i.selectedShapes.filter(e=>!e.draggable).length>0,ze=i.selectedElements.filter(e=>!e.visible).length>0,Ue=ne(i),Ze=JSON.stringify(Ue.map(e=>e.id)),_e=1!==i.selectedElements.length||"group"===(null===(re=i.selectedElements[0])||void 0===re?void 0:re.type),He=null!==(le=te(Ue))&&void 0!==le?le:0,Je=e=>_e&&Ue.length>0&&Ue.every(t=>((e,t,n)=>{if(!ee(e.rotation-n)){return!1}switch(e.type){case"text":return"x"===t&&!Z(e);case"figure":case"video":case"table":return!0;case"image":case"svg":case"gif":return!e.keepRatio;default:return!1}})(t,e,He)),Ne=!_e&&i.selectedElements[0].keepRatio,Ke=Je("x"),$e=Je("y"),Qe=()=>{var t,n,o;const r=Ae.current;if(!r){return[]}const l=r.getStage();if(!l){return[]}const s=ne(i),a=s.map(e=>l.findOne("#"+e.id)).filter(e=>!!e),c=1===i.selectedElements.length,d=c&&(null===(t=i.selectedElements[0])||void 0===t?void 0:t.type)||"many",u=ie[d],h=Object.assign(Object.assign({},fe),u||{});u&&("svg"!==d&&"image"!==d&&"gif"!==d||i.selectedElements[0].keepRatio||(h.enabledAnchors=fe.enabledAnchors),"text"===d&&H.textVerticalResizeEnabled&&(h.enabledAnchors=null===(n=ie.text.enabledAnchors)||void 0===n?void 0:n.concat(["bottom-center","top-center"])),"text"===d&&c&&i.selectedElements[0].curveEnabled&&(h.enabledAnchors=ie.many.enabledAnchors)),(Ke||$e)&&(h.enabledAnchors=[...h.enabledAnchors||[],...Ke?["middle-left","middle-right"]:[],...$e?["top-center","bottom-center"]:[]]);const{boundBoxFunc:m}=ge,g=e(ge,["boundBoxFunc"]);r.setAttrs(Object.assign(Object.assign(Object.assign({},h),g),{name:z})),Fe&&r.enabledAnchors([]),Ve&&r.rotateEnabled(!1);const f=r.nodes();if(f.length===a.length&&a.every((e,t)=>f[t]===e)||r.nodes(a),_e&&a.length){const e=te(s);null===e||ee(r.rotation()-e)||(r.rotation(e),r.forceUpdate())}return null===(o=r.getLayer())||void 0===o||o.batchDraw(),a};o.useLayoutEffect(()=>{var e;if(null===(e=Ae.current)||void 0===e?void 0:e.isTransforming()){return}const t=Qe();t.find(e=>null==e?void 0:e.isDragging())&&(t.forEach(e=>{e.isDragging()||null==e||e.startDrag()}),A())},[i.selectedShapes,Ze,Fe,ze,Ve,Le,Ke,$e,Ne,He,ge]);const qe=()=>{var e,t;const n=Ae.current;if(!n){return}if(!n.isTransforming()){return void De({})}if(!n.nodes().length||!n.isTransforming()){return}const i=n.__getNodeRect(),o=null==n?void 0:n.getActiveAnchor(),r=n.getStage();De({anchor:o,x:i.x-(null!==(e=null==r?void 0:r.x())&&void 0!==e?e:0),y:i.y-(null!==(t=null==r?void 0:r.y())&&void 0!==t?t:0),rotation:i.rotation,width:i.width,height:i.height})},et=o.useCallback(()=>{var e;if(null===(e=Ae.current)||void 0===e?void 0:e.isTransforming()){return}const t=Ae.current;if(!t||!t.nodes().length){return void We(0)}const n=t.getClientRect();if(!t.getStage()){return}const i=function(e,t,n,i=0){const o=e.x+e.width/2,r=e.y+e.height/2,l=e.width/2,s=e.height/2,a=i*Math.PI/180,c=e=>{const t=e*Math.PI/180,i=(e%360+360)%360;let c;c=0===i||180===i?s:l;const d=Math.sin(t)*(c+n),u=-Math.cos(t)*(c+n),h=d*Math.cos(a)-u*Math.sin(a),m=d*Math.sin(a)+u*Math.cos(a);return{x:o+h,y:r+m}},d=e=>e.x>=t.left&&e.x<=t.right&&e.y>=t.top&&e.y<=t.bottom;if(d(c(0))){return 0}for(const u of[180,270,90]){if(d(c(u))){return u}}return 0}(n,{top:(null==N?void 0:N.top)||0,bottom:x-((null==N?void 0:N.bottom)||0),left:(null==N?void 0:N.left)||0,right:u-((null==N?void 0:N.right)||0)},ge.rotateAnchorOffset,t.rotation());We(i)},[N,u,x]);o.useEffect(()=>{var e;null===(e=Ae.current)||void 0===e||e.update(),qe(),et()},[i.scale,et]),o.useEffect(()=>{et()},[i.selectedShapes,et]);const tt=l(()=>({visible:!1,x1:0,y1:0,x2:0,y2:0})),nt=o.useRef(!1),it=e=>{const t=Me.current;if(!t||i.role===X.VIEWER||i.activePage!==r||i.isPlaying||"button"in e.evt&&0!==e.evt.button||1!==t.getPointersPositions().length||!e.target.findAncestor(".elements-container")||!e.target.findAncestor(".element",!0)||!i.selectedShapes.length||i.selectedShapes.some(e=>!e.draggable)){return}const n=t.getPointerPosition();if(!n){return}const o=Qe();if(o.some(t=>t===e.target||t.isAncestorOf(e.target))){return}const l=o.find(e=>!!(e.draggable()&&e.isVisible()&&e.isListening())&&(e instanceof Y.Shape?[e]:e instanceof Y.Container?e.find("Shape"):[]).some(e=>e.intersects(n)));if(l){for(const[t,n]of Y.DD._dragElements){"ready"!==n.dragStatus||n.node!==e.target&&!n.node.isAncestorOf(e.target)||Y.DD._dragElements.delete(t)}l._createDragElement(e),"touches"in e.evt&&e.evt.cancelable&&l.preventDefault()&&e.evt.preventDefault()}},ot=s(e=>{var t,n,o,r,l,s,a;if(i.role===X.VIEWER){return}if(nt.current=!1,i.activeTool&&"crop"!==i.activeTool.name){return}const c=e.target.findAncestor(".elements-container"),d=e.target.findAncestor("Transformer"),u=e.target.findAncestor(".page-abs-container");if(c||d||u){return}const h=null===(t=e.target.getStage())||void 0===t?void 0:t.getPointerPosition();h&&(h.x-=null!==(o=null===(n=e.target.getStage())||void 0===n?void 0:n.x())&&void 0!==o?o:0,h.y-=null!==(l=null===(r=e.target.getStage())||void 0===r?void 0:r.y())&&void 0!==l?l:0,tt.visible=!0,tt.x1=h.x,tt.y1=h.y,tt.x2=h.x,tt.y2=h.y,(null!==(a=null===(s=e.target.getStage())||void 0===s?void 0:s.getPointersPositions().length)&&void 0!==a?a:0)>=2&&(tt.visible=!1))});(({stageRef:e,containerRef:t,viewportSize:n})=>{o.useEffect(()=>{var n;const i=null===(n=t.current)||void 0===n?void 0:n.closest(".polotno-workspace-inner");function o(){var n;if(!e.current){return}const o=null===(n=t.current)||void 0===n?void 0:n.getBoundingClientRect(),r=null==i?void 0:i.getBoundingClientRect();if(!o||!r){return}const l=Math.max(0,r.left-o.left-100),s=Math.max(0,r.top-o.top-100);e.current.position({x:-l,y:-s}),e.current.container().style.transform=`translate(${l}px, ${s}px)`}return o(),null==i||i.addEventListener("scroll",o),()=>{null==i||i.removeEventListener("scroll",o)}},[n.width,n.height])})({stageRef:Me,containerRef:Oe,viewportSize:j}),o.useEffect(()=>{const e=s(e=>{var t,n,i,o,r,l;if(!tt.visible){return}null===(t=Me.current)||void 0===t||t.setPointersPositions(e);let s=null===(n=Me.current)||void 0===n?void 0:n.getPointerPosition();s?(s.x-=null!==(o=null===(i=Me.current)||void 0===i?void 0:i.x())&&void 0!==o?o:0,s.y-=null!==(l=null===(r=Me.current)||void 0===r?void 0:r.y())&&void 0!==l?l:0):s={x:tt.x2,y:tt.y2},tt.x2=s.x,tt.y2=s.y}),t=s(()=>{if(!tt.visible){return}if(!Me.current){return}const e=Me.current.findOne(".selection"),t=e?e.getClientRect({skipStroke:!0}):{width:0,height:0,x:0,y:0};if(t.width&&t.height){const e=[{x:t.x,y:t.y},{x:t.x+t.width,y:t.y},{x:t.x+t.width,y:t.y+t.height},{x:t.x,y:t.y+t.height}],n=[];Me.current.find(".element").forEach(t=>{var o;const r=i.getElementById(t.id()),l=null==r?void 0:r.draggable,s=null==r?void 0:r.selectable;if(!l||!s){return}const a=null===(o=t.getParent())||void 0===o?void 0:o.getAbsoluteTransform();if(!a){return}const c=C(r.a).map(e=>a.point(e));G(e,c)&&n.push(r.top.id)});const o=[...new Set(n)];nt.current=!0,i.selectElements(o)}tt.visible=!1});return window.addEventListener("mousemove",e),window.addEventListener("touchmove",e),window.addEventListener("mouseup",t,{capture:!0}),window.addEventListener("touchend",t,{capture:!0}),()=>{window.removeEventListener("mousemove",e),window.removeEventListener("touchmove",e),window.removeEventListener("mouseup",t),window.removeEventListener("touchend",t)}},[]);const rt=o.useCallback(e=>{if(!i.selectedElements[0]){return}if(e&&i.selectedElementsIds.includes(e)){return}const t=W(i.selectedShapes),n=e?i.getElementById(e):{x:0,y:0,width:r.computedWidth,height:r.computedHeight,rotation:0},o=D(n),l=[];t.minX>o.maxX&&l.push({distance:t.minX-o.maxX,box1:t,box2:o,points:[{x:t.minX,y:t.minY+t.height/2},{x:o.maxX,y:t.minY+t.height/2},{x:o.maxX,y:o.minY+o.height/2}]}),t.maxX<o.minX&&l.push({distance:o.minX-t.maxX,box1:t,box2:o,points:[{x:t.maxX,y:t.minY+t.height/2},{x:o.minX,y:t.minY+t.height/2},{x:o.minX,y:o.minY+o.height/2}]}),t.minY>o.maxY&&l.push({box1:t,box2:o,distance:t.minY-o.maxY,points:[{x:t.minX+t.width/2,y:t.minY},{x:t.minX+t.width/2,y:o.maxY},{x:o.minX+o.width/2,y:o.maxY}]}),t.maxY<o.minY&&l.push({box1:t,box2:o,distance:o.minY-t.maxY,points:[{x:t.minX+t.width/2,y:t.maxY},{x:t.minX+t.width/2,y:o.minY},{x:o.minX+o.width/2,y:o.minY}]});const s=t.minX>=o.minX&&t.maxX<=o.maxX&&t.minY>=o.minY&&t.maxY<=o.maxY;if(s&&(l.push({distance:t.minX-o.minX,box1:t,box2:o,points:[{x:t.minX,y:t.minY+t.height/2},{x:o.minX,y:t.minY+t.height/2},{x:o.minX,y:o.minY+o.height/2}]}),l.push({distance:o.maxX-t.maxX,box1:t,box2:o,points:[{x:t.maxX,y:t.minY+t.height/2},{x:o.maxX,y:t.minY+t.height/2},{x:o.maxX,y:o.minY+o.height/2}]}),l.push({box1:t,box2:o,distance:t.minY-o.minY,points:[{x:t.minX+t.width/2,y:t.minY},{x:t.minX+t.width/2,y:o.minY},{x:o.minX+o.width/2,y:o.minY}]}),l.push({box1:t,box2:o,distance:o.maxY-t.maxY,points:[{x:t.minX+t.width/2,y:t.maxY},{x:t.minX+t.width/2,y:o.maxY},{x:o.minX+o.width/2,y:o.maxY}]})),0===l.length&&!s){const e=t.minX<o.maxX&&t.maxX>o.minX,n=t.minY<o.maxY&&t.maxY>o.minY;if(e&&n){const e=(Math.max(t.minY,o.minY)+Math.min(t.maxY,o.maxY))/2,n=(Math.max(t.minX,o.minX)+Math.min(t.maxX,o.maxX))/2;t.minX<o.minX?l.push({distance:o.minX-t.minX,box1:t,box2:o,points:[{x:t.minX,y:e},{x:o.minX,y:e},{x:o.minX,y:e}]}):l.push({distance:t.minX-o.minX,box1:t,box2:o,points:[{x:t.minX,y:e},{x:o.minX,y:e},{x:o.minX,y:e}]}),t.maxX>o.maxX?l.push({distance:t.maxX-o.maxX,box1:t,box2:o,points:[{x:o.maxX,y:e},{x:t.maxX,y:e},{x:o.maxX,y:e}]}):l.push({distance:o.maxX-t.maxX,box1:t,box2:o,points:[{x:t.maxX,y:e},{x:o.maxX,y:e},{x:o.maxX,y:e}]}),t.minY<o.minY?l.push({box1:t,box2:o,distance:o.minY-t.minY,points:[{x:n,y:t.minY},{x:n,y:o.minY},{x:n,y:o.minY}]}):l.push({box1:t,box2:o,distance:t.minY-o.minY,points:[{x:n,y:t.minY},{x:n,y:o.minY},{x:n,y:o.minY}]}),t.maxY>o.maxY?l.push({box1:t,box2:o,distance:t.maxY-o.maxY,points:[{x:n,y:o.maxY},{x:n,y:t.maxY},{x:n,y:o.maxY}]}):l.push({box1:t,box2:o,distance:o.maxY-t.maxY,points:[{x:n,y:t.maxY},{x:n,y:o.maxY},{x:n,y:o.maxY}]})}}JSON.stringify(Re)!==JSON.stringify(l)&&Te(l)},[i,r]);o.useEffect(()=>{i.selectedElements[0]&&i.distanceGuidesVisible?rt():Re&&Te(null)},[i.distanceGuidesVisible,rt,i.selectedShapes.map(e=>`${e.x},${e.y},${e.width},${e.height},${e.rotation}`).join("|")]);const lt=o.useRef(!1);o.useEffect(()=>{var e;let t;const n=null===(e=Oe.current)||void 0===e?void 0:e.closest(".polotno-workspace-inner"),i=()=>{lt.current=!0,clearTimeout(t),t=setTimeout(()=>{lt.current=!1},300)};return null==n||n.addEventListener("scroll",i),()=>{clearTimeout(t),null==n||n.removeEventListener("scroll",i)}},[]),o.useEffect(()=>{const e=Me.current;if(!e){return}const t=e.container(),n=new Map,o=e=>{var t,i;n.has(e.target)||[e.target,...null!==(i=null===(t=Ae.current)||void 0===t?void 0:t.nodes())&&void 0!==i?i:[]].forEach(e=>{n.has(e)||n.set(e,{x:e.x(),y:e.y()})})},r=e=>{e.target===Ae.current?n.clear():n.delete(e.target)};e.on("dragstart",o),e.on("dragend",r);const l=e=>{e.touches.length>=2&&a(()=>{var e,t;const o=new Map(n);(null===(e=Ae.current)||void 0===e?void 0:e.isDragging())&&Ae.current.stopDrag(),null===(t=Ae.current)||void 0===t||t.nodes().forEach(e=>{var t;const n=o.get(e);e.isDragging()&&e.stopDrag(),n&&(e.setAttrs(n),null===(t=i.getElementById(e.id()))||void 0===t||t.set({x:n.x,y:n.y}))})})};return t.addEventListener("touchstart",l,{passive:!0}),t.addEventListener("touchmove",l,{passive:!0}),()=>{e.off("dragstart",o),e.off("dragend",r),t.removeEventListener("touchstart",l),t.removeEventListener("touchmove",l)}},[i]);const st=e=>{if(i.role===X.VIEWER){return}if(i.activePage!==r&&r.select(),lt.current){return}if(nt.current){return}const t=e.evt.shiftKey,n=e.evt.ctrlKey||e.evt.metaKey,o=t||n,l=e.target.findAncestor(".elements-container"),s=e.target.findAncestor(".page-abs-container"),a=e.target.findAncestor("Transformer"),c=e.target.findAncestor(".page-container",!0),d=!(o||l||a||s||c||tt.visible);if(i.activeTool&&"crop"!==i.activeTool.name&&!l&&!a){return}if(d){return i.selectElements([]),void i.selectPages([])}if(n&&!t){const e=Me.current,t=null==e?void 0:e.getPointerPosition();if(!e||!t){return}const n=e.getAllIntersections(t),o=new Set,r=[];for(const s of[...n].reverse()){const e=s.findAncestor(".element",!0);if(!e){continue}const t=i.getElementById(e.id()),n=null==t?void 0:t.top;n&&(o.has(n.id)||(o.add(n.id),r.push(n.id)))}if(0===r.length){return}let l;if(1===i.selectedElementsIds.length){const e=i.selectedElementsIds[0],t=r.indexOf(e);l=-1===t?r[0]:r[(t+1)%r.length]}else{l=r[0]}return i.selectElements([l]),void i.selectPages([])}const u=e.target.findAncestor(".element-container",!0),h=(null==u?void 0:u.findOne(".element"))||e.target.findAncestor(".element",!0),m=i.getElementById(null==h?void 0:h.id());m&&"pendingEdit"in m&&m._setImageEditError(null);const g=null==m?void 0:m.top;let f;if("group"===O){f=null==g?void 0:g.id}else if(g){const e=i.selectedElements.some(e=>{var t;return(null===(t=e.top)||void 0===t?void 0:t.id)===g.id});f=e?null==m?void 0:m.id:null==g?void 0:g.id}else{f=void 0}const p=null==m?void 0:m.id;if(p&&i.selectedElementsIds.indexOf(p)>=0&&!t){return}const x=!!f&&i.selectedElementsIds.indexOf(f)>=0,v=e.target.findAncestor(".page-container",!0);if(f&&t&&!x){const e=i.selectedElementsIds.concat([f]),t=new Set(e),n=e.filter(e=>{const n=i.getElementById(e);if(!n){return!1}for(let i=n.parent;i;i=null==i?void 0:i.parent){if(t.has(i.id)){return!1}}return!0});i.selectElements(n),i.selectPages([])}else{f&&t&&x?i.selectElements(i.selectedElementsIds.filter(e=>e!==f)):!f||t||x?f&&!t&&x||(v?(t||i.selectElements([]),i.selectPages([r.id])):i.selectPages([])):(i.selectElements([f]),i.selectPages([]))}};I(Ae,i);const at=i.activePage===r,ct=i._selectedPagesIds.includes(r.id),dt=null==S?void 0:S.PageControls,ut=null==S?void 0:S.Tooltip,ht=null==S?void 0:S.ContextMenu,mt=1/i.scale,gt=0/i.scale;return n("div",{ref:Oe,onDragOver:e=>e.preventDefault(),onDrop:e=>{if(e.preventDefault(),i.role===X.VIEWER){return}if(!Me.current){return}Me.current.setPointersPositions(e);const t=Me.current.findOne(".elements-container"),n=null==t?void 0:t.getRelativePointerPosition(),o=Me.current.getPointerPosition(),l=Me.current.getAllIntersections(o).map(e=>e.findAncestor(".element",!0)).filter(Boolean),s=[...new Set(l.reverse())].map(e=>i.getElementById(e.id())).filter(e=>!!e),a=s[0];me&&n&&(me(n,a,{elements:s,page:r}),me=null)},style:{position:"relative",width:u+"px",height:x+"px",overflow:"hidden",flexShrink:0},className:"polotno-page-container"+(at?" active-page":""),children:[t(Q,{ref:Me,eventBatchFunc:a,width:Math.min(u,j.width+200),height:Math.min(j.height+200,x),onClick:st,onTap:st,onContextMenu:e=>{if(e.evt.preventDefault(),i.role===X.VIEWER){return}const t=e.target.findAncestor(".element",!0),n=i.getElementById(null==t?void 0:t.id()),o=null==n?void 0:n.top,r=null==o?void 0:o.id;if(!r){return i.selectElements([]),void Ge.close()}i.selectedElementsIds.indexOf(r)>=0||i.selectElements([r]),Ge.open({x:e.evt.clientX,y:e.evt.clientY})},onMouseDown:e=>{it(e),ot(e)},onTouchStart:it,onMouseMove:e=>{if(!i.distanceGuidesVisible&&!e.evt.altKey){return void(Re&&Te(null))}const t=e.target.findAncestor(".element",!0),n=null==t?void 0:t.id();rt(n)},onDragStart:e=>{var t;const n=e.target.getStage();if(n&&n.getPointersPositions().length>=2){return void e.target.stopDrag()}const o=e.target.findAncestor(".element",!0);if(o){const n=i.getElementById(null==o?void 0:o.id()),r=null==n?void 0:n.top,l=null==r?void 0:r.id;if(!(n&&i.selectedElementsIds.indexOf(n.id)>=0||l&&i.selectedElementsIds.indexOf(l)>=0)&&l){i.selectElements([l]);const n=Qe();e.target.stopDrag(),n.forEach(t=>{t.isDragging()||t.startDrag(e)}),null===(t=Ae.current)||void 0===t||t.startDrag(e),A()}}Re&&Te(null)},onDragMove:e=>{const t=Ae.current;t&&e.target===t&&t.nodes().forEach(e=>{const t=i.getElementById(e.id());!t||t.x===e.x()&&t.y===e.y()||t.set({x:e.x(),y:e.y()})})},pageId:r.id,style:{position:"absolute",overflow:"hidden",top:0,left:0},children:n(m,{children:[t(oe,{width:u,height:x,fill:de.workspaceBackgroundColor}),t(d,{x:Xe,y:Ye,scaleX:i.scale,scaleY:i.scale,name:"page-container",children:n(d,{name:"page-container-2",children:[t(d,{x:be.left,y:be.top,children:t(se,Object.assign({},Se,ke,{transparencyBackgroundColor:de.transparencyBackgroundColor}))}),n(d,{isolated:r.hasBlendMode,children:[t(d,{name:"page-background-group",x:be.left,y:be.top,clip:ke,children:t(ae,Object.assign({},Se))}),n(d,{x:be.left,y:be.top,name:"elements-container",listening:!i.isPlaying&&i.role!==X.VIEWER,children:[t(f,{name:"elements-area",width:r.computedWidth,height:r.computedHeight,listening:!1}),t(he,{elements:r.children,store:i})]})]}),t(p,{name:"bleed",fill:de.bleedColor,listening:!1,visible:i.bleedVisible&&(be.top>0||be.right>0||be.bottom>0||be.left>0),hideInExport:!0,sceneFunc:(e,t)=>{const{top:n,right:i,bottom:o,left:l}=ve,s=r.computedWidth,a=r.computedHeight,c=e._context;c.beginPath(),c.rect(0,0,l+s+i,n+a+o),c.rect(l,n,s,a),c.fillStyle=t.fill(),c.fill("evenodd")}}),R()===pe&&t(xe,{name:"hit-detection",x:-mt/2-gt,y:-mt/2-gt,width:ye+mt+2*gt,height:Ee+mt+2*gt})]})}),t(g,{name:"workspace-background",points:[0,0,u,0,u,x,0,x,0,0,Xe,Ye,Xe,x-Ye,u-Xe,x-Ye,u-Xe,Ye,Xe,Ye],listening:!1,closed:!0,fill:de.workspaceBackgroundColor}),t(d,{x:Xe,y:Ye,scaleX:i.scale,scaleY:i.scale,children:t(f,{name:"page-highlight",hideInExport:!0,x:-mt/2-gt,y:-mt/2-gt,width:ye+mt+2*gt,height:Ee+mt+2*gt,stroke:ct?de.activePageBorderColor:de.pageBorderColor,strokeWidth:2,listening:!1,strokeScaleEnabled:!1})}),n(d,{x:Xe+be.left*i.scale,y:Ye+be.top*i.scale,scaleX:i.scale,scaleY:i.scale,name:"page-abs-container",children:[t(w,{ref:Ae,name:z,rotateAnchorAngle:Ce,onDragStart:e=>{var t;const n=e.target.getStage();n&&n.getPointersPositions().length>=2?e.target.stopDrag():((null===(t=e.evt)||void 0===t?void 0:t.altKey)&&M&&i.selectedElements.forEach(e=>{const t=e.clone({},{skipSelect:!0}),n=r.children.indexOf(e);r.setElementZIndex(t.id,n)}),je.current||(je.current=!0,i.history.startTransaction()))},onDragEnd:()=>{je.current&&(i.history.endTransaction(),je.current=!1),et()},onTransformStart:()=>{i.history.startTransaction(),Ie.current=new Map(Ue.map(e=>[e.id,{width:e.width,height:e.height}])),Te(null)},boundBoxFunc:(e,t)=>{var n,o,r,l;const s=null!==(o=null===(n=ge.boundBoxFunc)||void 0===n?void 0:n.call(ge,e,t))&&void 0!==o?o:t,a=Math.abs(s.width)<1||Math.abs(s.height)<1,c=Math.abs(e.width)<1||Math.abs(e.height)<1;if(a&&!c){return e}const d=i.selectedElements;if(1===d.length&&"table"===(null===(r=d[0])||void 0===r?void 0:r.type)){const t=d[0],n=Math.abs(e.width),i=Math.abs(e.height);if(n>0&&i>0){const o=Math.abs(s.width)/n,r=Math.abs(s.height)/i,l=t.width*o,a=t.height*r,c=Object.assign({},s);return l<t.minWidth&&(c.width=e.width),a<t.minHeight&&(c.height=e.height),_(c,s,e)}}return _e&&Ue.length>0?((e,t,n,i,o)=>{const r=Math.abs(e.width),l=Math.abs(e.height);if(0===r||0===l){return t}const s=Math.abs(t.width)/r,a=Math.abs(t.height)/l,c=!V(n),d=e=>i.some(t=>{var n;const i=null==o?void 0:o.get(t.id),r=null!==(n="x"===e?null==i?void 0:i.width:null==i?void 0:i.height)&&void 0!==n?n:"x"===e?t.width:t.height,l="x"===e?t.width:t.height,d="x"===e?s:a,u=((e,t,n,i)=>{if("table"===e.type){const n=e;return"x"===t?n.minWidth:n.minHeight}return"text"===e.type&&"x"===t&&n?U(i,e.fontSize):1})(t,e,c,r);return r>=u&&l*d<u}),u=Object.assign({},t),h=t.width*e.width<0,m=t.height*e.height<0,g=h||d("x"),f=m||d("y"),p=f||!c&&g;return(g||!c&&f)&&(u.width=e.width),p&&(u.height=e.height),_(u,t,e)})(e,s,(null===(l=Ae.current)||void 0===l?void 0:l.getActiveAnchor())||"",Ue,Ie.current):s},onTransform:e=>{const t=Ae.current.nodes(),n=t[t.length-1];e.target===n&&setTimeout(()=>{qe()},0)},onTransformEnd:e=>{De({}),i.history.endTransaction(),Ie.current=null,et(),Qe()},visible:!i.isPlaying}),Re&&Re.map(({points:e,distance:o,box1:r,box2:l},s)=>n(d,{name:"distances-container",hideInExport:!0,listening:!1,children:[t(f,Object.assign({},r,{stroke:de.distanceGuideStyle.stroke,strokeWidth:1,strokeScaleEnabled:!1})),t(f,Object.assign({},l,{stroke:de.distanceGuideStyle.stroke,strokeWidth:1,strokeScaleEnabled:!1})),t(g,{points:[e[0].x,e[0].y,e[1].x,e[1].y],stroke:de.distanceGuideStyle.stroke,strokeWidth:1,strokeScaleEnabled:!1}),t(g,{points:[e[1].x,e[1].y,e[2].x,e[2].y],stroke:de.distanceGuideStyle.stroke,strokeWidth:1,strokeScaleEnabled:!1}),n(h,{x:(e[0].x+e[1].x)/2,y:(e[0].y+e[1].y)/2,offsetY:-10,scaleX:1/i.scale,scaleY:1/i.scale,children:[t(b,{cornerRadius:5,fill:de.distanceGuideStyle.labelFill,pointerDirection:"down"}),t(y,{align:"center",verticalAlign:"middle",fill:de.distanceGuideStyle.labelTextFill,padding:5,text:F({unit:i.unit,dpi:i.dpi,px:o})})]})]},s)),r._rendering&&n(d,{children:[t(f,{width:ye,height:Ee,fill:"rgba(255,255,255,0.9)"}),t(y,{text:"Rendering...",fontSize:60,width:ye,height:Ee,align:"center",verticalAlign:"middle"})]}),ut&&t(ut,{components:S,store:i,page:r,stageRef:Me,tooltipSafeArea:J}),ht&&t($,{children:t(ht,Object.assign({components:S,store:i},Ge.props))}),t(P,{store:i,pageId:r.id})]}),t(k,{store:i,page:r,width:u,height:x,scale:i.scale,xPadding:Xe,yPadding:Ye,bleedLeft:be.left,bleedTop:be.top}),t(ue,Object.assign({},Be,{store:i})),t(ce,{selection:tt}),T()>0&&n(d,{hideInExport:!0,children:[t(we,{name:"cache-bounds",x:u-(1===T()?250:210),y:x-(1===T()?95:45)}),t(we,{name:"cache-bounds-t",x:10,y:10})]}),B()&&t(y,{text:"Powered by polotno.com",fontSize:14,fill:"rgba(0,0,0,0.6)",x:u-170,y:x-18,onMouseEnter:e=>{e.target.getStage().container().style.cursor="pointer"},onMouseLeave:e=>{e.target.getStage().container().style.cursor=""},onTouchStart:e=>{e.cancelBubble=!0},onMouseDown:e=>{e.cancelBubble=!0},onClick:()=>{window.open("https://polotno.com","_blank","noopener")},onTap:()=>{window.open("https://polotno.com","_blank","noopener")}}),t(d,{name:"line-guides"})]})}),Pe&&dt&&t(dt,{store:i,page:r,xPadding:Xe,yPadding:Ye,layout:L})]})});
@@ -0,0 +1,5 @@
1
+ import React from 'react';
2
+ export declare function ParentFrame({ elementId, children, }: {
3
+ elementId: string;
4
+ children: React.ReactNode;
5
+ }): React.JSX.Element;
@@ -0,0 +1 @@
1
+ import{jsx as e}from"react/jsx-runtime";import r from"react";import{Group as t}from"react-konva";export function ParentFrame({elementId:o,children:n}){const a=r.useRef(null);return r.useLayoutEffect(()=>{const e=a.current,r=null==e?void 0:e.getLayer();if(!e||!r){return}const t=()=>{var r,t;const n=null===(t=null===(r=e.getStage())||void 0===r?void 0:r.findOne("#"+o))||void 0===t?void 0:t.getParent(),a=e.getParent();if(!n||!a){return}const f=a.getAbsoluteTransform().copy().invert();f.multiply(n.getAbsoluteTransform()),e.setAttrs(f.decompose())};return t(),r.on("beforeDraw",t),()=>{r.off("beforeDraw",t)}},[o]),e(t,{ref:a,children:n})}
@@ -1 +1 @@
1
- import t from"quill";import{firstStopColor as e}from"@polotno/core/gradient";import{parsePrimaryFontFamily as r}from"@polotno/core/rich-text-html";import{cssFontFamily as o}from"@polotno/core/fonts";import{isClipGradientSpan as i}from"../utils/rich-text-html.js";let l=!1;const s=["background-image","background-size","-webkit-background-clip","background-clip","-webkit-text-fill-color","color"];export function registerQuillUnrestrictedFontFormats(){if(l){return}l=!0;const n=t.import("attributors/style/size"),c=t.import("attributors/style/font");n&&(delete n.whitelist,t.register(n,!0)),c&&(delete c.whitelist,c.add=(t,e)=>(t.style.fontFamily=o(e),!0),c.value=t=>r(t.style.fontFamily)||"",t.register(c,!0));const u=t.import("parchment");if((null==u?void 0:u.StyleAttributor)&&(null==u?void 0:u.Scope)){const r=new u.StyleAttributor("font-weight","font-weight",{scope:u.Scope.INLINE});t.register(r,!0),t.register(function(t){class r extends t.StyleAttributor{constructor(t,e,r){super(t,e,r)}add(t,r){if("string"!=typeof r||!r.includes("gradient")){return!1}t.style.setProperty("background-image",r),t.style.setProperty("background-size","100% 100%"),t.style.setProperty("-webkit-background-clip","text"),t.style.setProperty("background-clip","text"),t.style.setProperty("-webkit-text-fill-color","transparent");try{t.style.setProperty("color",e(r))}catch(o){}return!0}remove(t){for(const e of s){t.style.removeProperty(e)}}value(t){return i(t)?t.style.getPropertyValue("background-image"):""}}return new r("gradient","background-image",{scope:t.Scope.INLINE})}(u),!0);const o=t.import("attributors/style/color");if(o){const e=o.value.bind(o);o.value=t=>i(t)?"":e(t),t.register(o,!0)}}}
1
+ import t from"quill";import{firstStopColor as e}from"@polotno/core/gradient";import{parsePrimaryFontFamily as r}from"@polotno/core/rich-text-html";import{cssFontFamily as o}from"@polotno/core/fonts";import{containsCmykColor as i,isCmykColor as n,toDisplayColor as s}from"@polotno/core/color";import{isClipGradientSpan as l,nativeColorAttribute as c,readNativeColor as u}from"../utils/rich-text-html.js";let a=!1;function m(t){const e=t.keyName,r=c(e),o=t.add.bind(t),i=t.remove.bind(t),l=t.value.bind(t);t.add=(t,e)=>n(e)?!!o(t,s(e))&&(t.setAttribute(r,e),!0):(t.removeAttribute(r),o(t,e)),t.remove=t=>{t.removeAttribute(r),i(t)},t.value=t=>u(t,e)||l(t)}const p=["background-image","background-size","-webkit-background-clip","background-clip","-webkit-text-fill-color","color"],b=c("background-image");export function registerQuillUnrestrictedFontFormats(){if(a){return}a=!0;const n=t.import("attributors/style/size"),c=t.import("attributors/style/font");n&&(delete n.whitelist,t.register(n,!0)),c&&(delete c.whitelist,c.add=(t,e)=>(t.style.fontFamily=o(e),!0),c.value=t=>r(t.style.fontFamily)||"",t.register(c,!0));const d=t.import("parchment");if((null==d?void 0:d.StyleAttributor)&&(null==d?void 0:d.Scope)){const r=new d.StyleAttributor("font-weight","font-weight",{scope:d.Scope.INLINE});t.register(r,!0),t.register(new d.StyleAttributor("text-transform","text-transform",{scope:d.Scope.INLINE}),!0),t.register(function(t){class r extends t.StyleAttributor{constructor(t,e,r){super(t,e,r)}add(t,r){if("string"!=typeof r||!r.includes("gradient")){return!1}t.style.setProperty("background-image",s(r)),i(r)?t.setAttribute(b,r):t.removeAttribute(b),t.style.setProperty("background-size","100% 100%"),t.style.setProperty("-webkit-background-clip","text"),t.style.setProperty("background-clip","text"),t.style.setProperty("-webkit-text-fill-color","transparent");try{t.style.setProperty("color",e(r))}catch(o){}return!0}remove(t){t.removeAttribute(b);for(const e of p){t.style.removeProperty(e)}}value(t){return l(t)?u(t,"background-image")||t.style.getPropertyValue("background-image"):""}}return new r("gradient","background-image",{scope:t.Scope.INLINE})}(d),!0);const o=t.import("attributors/style/color");if(o){m(o);const e=o.value.bind(o);o.value=t=>l(t)?"":e(t),t.register(o,!0)}const n=t.import("attributors/style/background");n&&(m(n),t.register(n,!0))}}
@@ -0,0 +1,13 @@
1
+ import React from 'react';
2
+ import type Konva from 'konva';
3
+ import type { Rect as Rectangle } from '../image-tools/types.js';
4
+ export declare function RectControl({ rect, onChange, nodeRef, fixedRef, disabled, anchors, accept, crop, }: {
5
+ rect: Rectangle;
6
+ onChange(rect: Rectangle): void;
7
+ nodeRef?: React.RefObject<Konva.Rect | null>;
8
+ fixedRef?: React.RefObject<Konva.Node | null>;
9
+ disabled?: boolean;
10
+ anchors?: string[];
11
+ accept?: (rect: Rectangle) => boolean;
12
+ crop?: boolean;
13
+ }): React.JSX.Element;
@@ -0,0 +1 @@
1
+ var e=this&&this.__rest||function(e,t){var r={};for(var n in e){Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n])}if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++){t.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(r[n[o]]=e[n[o]])}}return r};import{jsx as t,Fragment as r,jsxs as n}from"react/jsx-runtime";import o from"react";import{Rect as a,Transformer as i}from"react-konva";import{cropBoundBoxFunc as s}from"./transform-box.js";import{useWorkspaceStyle as c}from"./workspace-style.js";export function RectControl({rect:l,onChange:u,nodeRef:f,fixedRef:h,disabled:b=!1,anchors:d,accept:g,crop:p=!1}){const m=o.useRef(null),y=null!=f?f:m,x=o.useRef(null),{innerImageCropTransformerStyle:v}=c(),{boundBoxFunc:j,keepRatio:O,enabledAnchors:w}=v,R=e(v,["boundBoxFunc","keepRatio","enabledAnchors"]),A=p?v:R,k=!p;o.useLayoutEffect(()=>{var e;null===(e=x.current)||void 0===e||e.nodes(y.current?[y.current]:[])},[y]);const F=()=>{const e=y.current,t={x:e.x(),y:e.y(),width:e.width()*e.scaleX(),height:e.height()*e.scaleY()};e.scale({x:1,y:1}),t.width>0&&t.height>0&&(!g||g(t))?(e.size(t),u(t)):e.setAttrs(l)},P=h?s(y,h,"contain",A.boundBoxFunc):(e,t)=>{var r;if(t.width<5||t.height<5){return e}if(g&&(null===(r=y.current)||void 0===r?void 0:r.getParent())){const r=y.current.getParent(),n=r.getAbsoluteTransform().copy().invert().point(t),o=r.getAbsoluteScale();if(!g(Object.assign(Object.assign({},n),{width:t.width/Math.abs(o.x),height:t.height/Math.abs(o.y)}))){return e}}return t};return n(r,{children:[t(a,Object.assign({ref:y},l,{name:"image-tool-rect",fill:k?"rgba(0,0,0,0.001)":void 0,listening:k&&!b,draggable:k&&!b,onTransform:F,onDragMove:F})),t(i,Object.assign({ref:x,keepRatio:!1,rotateEnabled:!1,flipEnabled:!1},d?{enabledAnchors:d}:{},A,{boundBoxFunc:P,visible:!b}))]})}
@@ -1 +1 @@
1
- var t=this&&this.__rest||function(t,e){var o={};for(var r in t){Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(o[r]=t[r])}if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(r=Object.getOwnPropertySymbols(t);n<r.length;n++){e.indexOf(r[n])<0&&Object.prototype.propertyIsEnumerable.call(t,r[n])&&(o[r[n]]=t[r[n]])}}return o};import{jsx as e,Fragment as o,jsxs as r}from"react/jsx-runtime";import{elementOpacity as n}from"./paint-opacity.js";import i from"react";import{observer as a}from"mobx-react-lite";import{Group as s,Path as l,Rect as c,Shape as h}from"react-konva";import{nodeAutorun as d}from"../utils/mobx.js";import{isAlive as f}from"mobx-state-tree";import{Html as u}from"react-konva-utils";import{layout as g,drawLayout as m}from"render-tag";import{layoutTextOnPath as x,drawTextOnPathLayout as p}from"render-tag/path";import{activeAnchorOf as y,scaledFontSizeAttrs as w,roundedFontSizeAttrs as b,roundedTextDecorationAttrs as v,roundedGeometryPx as O,roundedPosition as E,textMinResizeWidth as j}from"../utils/px.js";import{flags as M}from"../utils/flags.js";import{applyFilter as S}from"./apply-filters.js";import{getLineHeight as z,usePrevious as k}from"./text-element.js";import{useFontSpecsLoader as R}from"./text-element/font-specs-loader.js";import{getHtml as Y,getCurvePath as X,getCurveTextHeight as F,letterSpacingOverhang as B}from"@polotno/core/text-html";import{useColor as C}from"./use-color.js";import{isGradient as I}from"@polotno/core/gradient";import{detectSize as P}from"@polotno/core/measure-html";import{generateBackgroundShapeFromRects as T,trimTrailingLetterSpace as W}from"@polotno/core/background-shape";import{useFadeIn as D}from"./use-fadein.js";import{incrementLoader as N}from"../utils/loader.js";import{removeTags as $}from"@polotno/core/text";import{shadowCastByBackground as J}from"@polotno/core/filters";import{isTouchDevice as _}from"../utils/screen.js";import{getLimitedFontSize as A}from"./text-element/max-font-size.js";import{normalizeRichTextHtml as L,extractFontSpecsFromHtml as V,scaleRichTextFontSizesInHtml as H}from"../utils/rich-text-html.js";import{RichEditor as q}from"./rich-editor.js";import{findFitFontSize as G}from"./text-element/fit-font-size.js";import{visiblePlaceholder as K}from"./text-element/placeholder.js";import{wrapHtmlForRenderTag as Q}from"@polotno/core/reset-style";import{xmlEscape as U}from"@polotno/core/xml";import{hasMeasuredHeight as Z,resolveTextBoxHeight as tt}from"@polotno/core/text-types";export{Q as wrapHtmlForRenderTag};function et(t,e){return t!==e&&(!M.textVerticalResizeEnabled||t<e)}export const RenderTagElement=a(({element:a,store:ot})=>{var rt;const nt=i.useRef(null),it=i.useRef(null),[at,st]=i.useState(!1),lt=i.useRef(a.height),ct=a.isSelected,ht=k(ct),{textVerticalResizeEnabled:dt}=M,ft=M.autoDeleteEmptyText,ut=k(a.fontFamily),gt=i.useMemo(()=>L(a.text,{fontSize:a.fontSize,fontFamily:a.fontFamily}),[a.text,a.fontSize,a.fontFamily]),mt=i.useMemo(()=>V(gt,{fontFamily:a.fontFamily,fontWeight:a.fontWeight,fontStyle:a.fontStyle}),[gt,a.fontFamily,a.fontWeight,a.fontStyle]),[xt]=R(ot,mt,a.text||a.placeholder),pt=a._editModeEnabled;D(nt);const yt=xt?a.fontFamily:ut&&ut!==a.fontFamily?ut:"Arial",wt=C(a).fill,bt=I(a.fill),vt=I(a.stroke)&&!!a.strokeWidth,Ot=!!a.strokeWidth&&(vt||bt),Et="ellipsis"===M.textOverflow&&!a.curveEnabled&&Z(a)&&!Ot,jt=K(a.placeholder),Mt=!!jt&&!$(a.text),St=Mt?U(jt):gt,zt=Mt?.6:n(a),kt=Y(a,{fontFamily:yt,color:wt,forEditor:!Et,textOverflow:M.textOverflow,text:St,textIsNormalized:!0}),Rt=a.width||1,Yt=B(a.letterSpacing,a.fontSize),Xt=a.curveEnabled,Ft=function(t,e,o,r){return i.useMemo(()=>{if(r){return null}try{return g({html:Q(t),width:Math.max(1,e),accuracy:"performance"})}catch(o){return console.error("render-tag layout failed:",o),null}},[t,e,o,r])}(kt,Rt,xt,Xt),Bt=function(t,e,o){return i.useMemo(()=>{if(!e.curveEnabled){return null}const o=e.width||1,r=F(e),n=X(o,r,e.curvePower,e.fontSize);try{return x({html:Q(t),path:n,align:"center",textBaseline:"middle"})}catch(i){return console.error("render-tag/path layoutTextOnPath failed:",i),null}},[o,e.curveEnabled,e.curvePower,e.fontSize,e.width,e.height,t])}(kt,a,xt),Ct=z({fontLoaded:xt,fontFamily:a.fontFamily,fontSize:a.fontSize,lineHeight:a.lineHeight}),It=Xt?0:Math.max(null!==(rt=null==Ft?void 0:Ft.height)&&void 0!==rt?rt:0,a.fontSize*Ct),Pt=Bt?Bt.bounds:null,Tt=Pt?(a.width-Pt.width)/2-Pt.x:0,Wt=i.useMemo(()=>{var t;if(Bt&&Pt){const t=Bt.paintBounds;return Object.assign(Object.assign({},t),{x:t.x+Tt,y:t.y-Pt.y})}return null!==(t=null==Ft?void 0:Ft.paintBounds)&&void 0!==t?t:null},[Ft,Bt,Pt,Tt]),Dt=i.useMemo(()=>Ft?Ft.lines.map(t=>W({left:t.bounds.x,right:t.bounds.x+t.bounds.width,top:t.bounds.y,bottom:t.bounds.y+t.bounds.height},Yt)):[],[Ft,Yt]),Nt=i.useRef([]),$t=i.useRef(null),Jt=i.useRef(!0),[,_t]=i.useReducer(t=>t+1,0);i.useEffect(()=>{const t=Nt.current;t.length>0&&(Nt.current=[],t.forEach(t=>t()))});const At=i.useCallback((t,e,o,r)=>{const n=N(`text ${a.id}`),i=()=>{ot.history.ignore(t,e,o).then(()=>{Jt.current?(Nt.current.push(n),_t()):n()})};r?queueMicrotask(i):i()},[a.id,ot]),Lt=i.useCallback(t=>{const e=null!==$t.current;$t.current=t,e||At(()=>{const t=$t.current;$t.current=null,f(a)&&et(a.height,t)&&a.set({height:t})},!1,!0)},[a,At]);i.useEffect(()=>{if(!xt){return}if(!Ft){return}if(!Z(a)){return void At(()=>{f(a)&&(Z(a)||a.set({height:It}))},void 0,void 0,!0)}if(ot.isPlaying){return}const{textOverflow:t}=M,e=et(a.height,It),o=()=>Lt(It);if("change-font-size"!==t||at||pt||a.curveEnabled){"resize"===t&&e&&!at&&o()}else{const t=G(Mt?{toJSON:()=>Object.assign(Object.assign({},a.toJSON()),{text:St})}:a,{fontFamily:yt,color:wt,forEditor:!0},t=>{try{return g({html:Q(t),width:Rt,accuracy:"performance"}).height}catch(rt){return P(t).height}});t.fontSize!==a.fontSize?At(()=>{if(!f(a)){return}const e=w(a,t.fontSize);void 0!==t.text&&t.text!==a.text&&(e.text=t.text),a.set(e)},!1,!0):e&&o()}}),i.useEffect(()=>()=>{Jt.current=!1;const t=Nt.current;t.length>0&&(Nt.current=[],t.forEach(t=>t()))},[]),i.useLayoutEffect(()=>{if(!xt||!a.curveEnabled||at){return}if(!Pt||!Pt.width){return}const t=t=>t&&dt?Math.max(t,Pt.height):Pt.height;Math.abs(Pt.width-a.width)<1&&Math.abs(t(a.height)-a.height)<1||At(()=>{if(!f(a)){return}const e=Pt.width-a.width,o=t(a.height),r=o-a.height;if(Math.abs(e)<1&&Math.abs(r)<1){return}const n=a.a.rotation*Math.PI/180,i=-e/2*Math.cos(n),s=-e/2*Math.sin(n);a.set({width:Pt.width,height:o,x:a.a.x+i,y:a.a.y+s})},!1,!0,!0)},[xt,a.curveEnabled,Pt,at,dt,At]),i.useEffect(()=>{ht&&!ct&&ft&&""===$(a.text)&&a.removable&&!K(a.placeholder)&&ot.deleteElements([a.id])},[ft,a.placeholder,a.removable,a.text,ct,ht]),i.useEffect(()=>d(a,()=>{const t=nt.current;t&&S(t,a)}),[Ft,Bt,a.a.width,a.a.height,a.shadowColor,a.shadowOffsetX,a.shadowOffsetY,a.shadowOpacity]);const Vt=tt(a,It),Ht=Xt||!xt||at||ot.isPlaying||"resize"!==M.textOverflow?a.a.height:dt?Math.max(a.a.height,It):It;let qt=0;Xt||"middle"!==a.verticalAlign?Xt||"bottom"!==a.verticalAlign||(qt=Vt-It):qt=(Vt-It)/2;const Gt=a.backgroundPadding*(a.fontSize*Ct*.5),Kt=a.backgroundCornerRadius*(a.fontSize*Ct*.5),Qt=i.useMemo(()=>!a.backgroundEnabled||a.curveEnabled||a.legacyBackground||0===Dt.length?"":T({rects:Dt,padding:Gt,cornerRadius:Kt}),[a.backgroundEnabled,a.curveEnabled,a.legacyBackground,Dt,Gt,Kt]),Ut=_(),Zt=i.useRef(null),te=i.useRef(a.width),ee=i.useRef(null),oe=i.useRef(null),re=i.useRef(""),ne=i.useRef(0),ie=i.useRef(0),ae=a.width>0?a.a.width/a.width:1,se={shadowEnabled:a.shadowEnabled&&J(a),shadowBlur:a.shadowBlur,shadowOffsetX:a.shadowOffsetX,shadowOffsetY:a.shadowOffsetY,shadowColor:a.shadowColor,shadowOpacity:a.shadowOpacity};return r(o,{children:[a.curveEnabled||a.legacyBackground?e(c,Object.assign({x:a.a.x,y:a.a.y,offsetX:Gt/ae,offsetY:Gt/ae,rotation:a.a.rotation,scaleX:ae,scaleY:ae,hideInExport:!a.showInExport,listening:!1,visible:a.backgroundEnabled,opacity:a.backgroundOpacity*zt,fill:a.backgroundColor},se,{width:a.width+2*Gt,height:Vt+2*Gt,cornerRadius:Kt})):e(l,Object.assign({name:"rendertag-background",x:a.a.x,y:a.a.y,offsetY:-qt/ae,rotation:a.a.rotation,scaleX:ae,scaleY:ae,hideInExport:!a.showInExport,listening:!1,visible:a.backgroundEnabled&&Qt.length>0,opacity:a.backgroundOpacity*zt,fill:a.backgroundColor},se,{data:Qt})),e(h,{ref:nt,selfRectFunc:Wt?()=>Wt:void 0,name:"rendertag-text",x:a.a.x,y:a.a.y,rotation:a.a.rotation,scaleX:ae,scaleY:ae,offsetY:ae>0?-qt/ae:0,width:a.width,height:Math.max(a.height,It),listening:!1,visible:!pt&&!!(Xt?Bt:Ft),editModeEnabled:pt,opacity:zt,shadowEnabled:a.shadowEnabled&&!se.shadowEnabled,shadowBlur:a.shadowBlur,shadowOffsetX:a.shadowOffsetX,shadowOffsetY:a.shadowOffsetY,shadowColor:a.shadowColor,shadowOpacity:a.shadowOpacity,hideInExport:!a.showInExport,sceneFunc:(t,e)=>{const o=t._context;if(o){try{if(Xt){if(!Bt||!Pt){return}o.save(),o.translate(Tt,-Pt.y),p({layout:Bt,ctx:o}),o.restore()}else{if(!Ft){return}m({layout:Ft,width:Rt,ctx:o,pixelRatio:1})}}catch(r){console.error("render-tag draw failed:",r)}}}}),e(c,{ref:it,name:"element",x:a.a.x,y:a.a.y,listening:a.selectable,rotation:a.a.rotation,width:a.a.width,height:Ht,visible:!pt,draggable:Ut?a.draggable&&ct:a.draggable,preventDefault:!Ut||ct,opacity:0,hideInExport:!0,id:a.id,onDragMove:t=>{a.set({x:t.target.x(),y:t.target.y()})},onDragEnd:t=>{a.set(E(t.target))},onDblClick:t=>{a.contentEditable&&(oe.current={x:t.evt.clientX,y:t.evt.clientY},a.toggleEditMode(!0))},onDblTap:t=>{var e;if(a.contentEditable){const o=null===(e=t.evt.changedTouches)||void 0===e?void 0:e[0];oe.current=o?{x:o.clientX,y:o.clientY}:null,a.toggleEditMode(!0)}},onTransformStart:t=>{st(!0),lt.current=a.height,te.current=a.width,ee.current=null,Zt.current=t.target.position(),re.current=y(t.target),ne.current=a.a.rotation,ie.current=a.height},onTransform:e=>{const o=e.target,r=re.current,n="middle-left"===r||"middle-right"===r,i="top-center"===r||"bottom-center"===r,s=o.scaleX();if(n){const e=o.scaleX(),r=o.width()*e;let n=Math.max(r,j(te.current,a.fontSize));const i=a.toJSON();let s=0;if(a.curveEnabled){s=F(Object.assign(Object.assign({},i),{width:n}))}else{const{x:e,y:o,width:r,height:a}=i,l=t(i,["x","y","width","height"]),c=`${JSON.stringify(l)}|${yt}|${xt}|${wt}`;if(ee.current&&ee.current.signature===c&&n<=ee.current.width){n=ee.current.width,s=ee.current.height}else{const t=t=>{const e=Y(Object.assign(Object.assign({},i),{width:t}),{fontFamily:yt,color:wt,forEditor:!0,text:St,textIsNormalized:!0});try{return g({html:Q(e),width:t,accuracy:"performance"})}catch(rt){return{height:P(e).height,lines:[]}}};let e=t(n);const o=Math.max(0,...e.lines.map(t=>t.bounds.x+t.bounds.width-Yt));o>n+.5&&o<=te.current+.5&&(n=Math.min(Math.ceil(o),te.current),e=t(n),ee.current={signature:c,width:n,height:e.height}),s=e.height}}n>r&&Zt.current&&o.position(Zt.current),o.width(n),o.scaleX(1),o.scaleY(1);let l=M.textVerticalResizeEnabled?Math.max(s,lt.current):s;"ellipsis"===M.textOverflow&&(l=lt.current),o.height(l),a.set({width:o.width(),height:l,x:o.x(),y:o.y()})}else if(i){const t="resize"===M.textOverflow?Xt?(null==Pt?void 0:Pt.height)||a.fontSize:It:Ct*a.fontSize,e=o.height()*o.scaleY();if(e<t){if(o.height(t),Zt.current){if("top-center"===re.current){const e=ne.current*Math.PI/180,r=ie.current-t;o.x(Zt.current.x-r*Math.sin(e)),o.y(Zt.current.y+r*Math.cos(e))}else{o.position(Zt.current)}}}else{o.height(e)}o.scaleY(1),o.scaleX(1),ie.current=Math.max(t,e),a.set({x:o.x(),y:o.y(),height:o.height(),rotation:o.rotation()})}else{o.scaleX(1),o.scaleY(1),a.set({fontSize:a.fontSize*s,letterSpacing:a.letterSpacing,width:o.width()*s,x:o.x(),y:o.y(),rotation:o.rotation(),height:o.height()*s,shadowBlur:a.shadowBlur*s,shadowOffsetX:a.shadowOffsetX*s,shadowOffsetY:a.shadowOffsetY*s,strokeWidth:a.strokeWidth*s,text:H(a.text,s)})}Zt.current=e.target.position()},onTransformEnd:t=>{st(!1);const e=t.target.scaleX();t.target.scaleX(1),t.target.scaleY(1),a.set(Object.assign(Object.assign({},b(a,a.fontSize*e)),{width:O(t.target.width()*e),x:O(t.target.x()),y:O(t.target.y()),rotation:O(t.target.rotation()),text:H(a.text,e)}))}}),pt&&e(s,{x:a.a.x,y:a.a.y,rotation:a.a.rotation,offsetY:-qt,children:e(u,{divProps:{style:{zIndex:20}},children:e(q,{element:a,onChange:t=>{const e=A({oldText:$(a.text),newText:$(t),element:a});a.set(Object.assign({text:t},w(a,e)))},onBlur:()=>{f(a)&&(a.set(v(a)),a.toggleEditMode(!1))},clickCoords:oe.current})})})]})});
1
+ var t=this&&this.__rest||function(t,e){var o={};for(var r in t){Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(o[r]=t[r])}if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(r=Object.getOwnPropertySymbols(t);n<r.length;n++){e.indexOf(r[n])<0&&Object.prototype.propertyIsEnumerable.call(t,r[n])&&(o[r[n]]=t[r[n]])}}return o};import{jsx as e,Fragment as o,jsxs as r}from"react/jsx-runtime";import{elementOpacity as n}from"./paint-opacity.js";import i from"react";import{observer as a}from"mobx-react-lite";import{Group as l,Path as s,Rect as d,Shape as c}from"react-konva";import{nodeAutorun as h}from"../utils/mobx.js";import{isAlive as u}from"mobx-state-tree";import{Html as f}from"react-konva-utils";import{layout as g,drawLayout as m}from"render-tag";import{layoutTextOnPath as p,drawTextOnPathLayout as x}from"render-tag/path";import{activeAnchorOf as b,scaledFontSizeAttrs as w,roundedFontSizeAttrs as y,roundedTextDecorationAttrs as v,roundedGeometryPx as O,roundedPosition as E,textMinResizeWidth as S}from"../utils/px.js";import{flags as z}from"../utils/flags.js";import{applyFilter as j}from"./apply-filters.js";import{getLineHeight as k,usePrevious as M}from"./text-element.js";import{useFontSpecsLoader as R}from"./text-element/font-specs-loader.js";import{getHtml as Y,getCurvePath as X,getCurveTextHeight as C,letterSpacingOverhang as F}from"@polotno/core/text-html";import{useColor as B,withDisplayTextPaints as P}from"./use-color.js";import{isGradient as I}from"@polotno/core/gradient";import{toDisplayColor as T}from"@polotno/core/color";import{detectSize as W}from"@polotno/core/measure-html";import{generateBackgroundShapeFromRects as D,trimTrailingLetterSpace as N}from"@polotno/core/background-shape";import{useFadeIn as J}from"./use-fadein.js";import{incrementLoader as $}from"../utils/loader.js";import{removeTags as H}from"@polotno/core/text";import{shadowCastByBackground as _}from"@polotno/core/filters";import{applyOpacityToColor as A}from"@polotno/core/svg";import{isTouchDevice as L}from"../utils/screen.js";import{getLimitedFontSize as V}from"./text-element/max-font-size.js";import{normalizeRichTextHtml as q,extractFontSpecsFromHtml as G,scaleRichTextFontSizesInHtml as K}from"../utils/rich-text-html.js";import{RichEditor as Q}from"./rich-editor.js";import{findFitFontSize as U}from"./text-element/fit-font-size.js";import{visiblePlaceholder as Z}from"./text-element/placeholder.js";import{wrapHtmlForRenderTag as tt}from"@polotno/core/reset-style";import{xmlEscape as et}from"@polotno/core/xml";import{hasMeasuredHeight as ot,resolveTextBoxHeight as rt}from"@polotno/core/text-types";export{tt as wrapHtmlForRenderTag};function nt(t,e){return t!==e&&(!z.textVerticalResizeEnabled||t<e)}export const RenderTagElement=a(({element:a,store:it})=>{var at,lt,st,dt,ct,ht,ut,ft,gt;const mt=i.useRef(null),pt=i.useRef(null),[xt,bt]=i.useState(!1),wt=i.useRef(a.height),yt=i.useRef(null),vt=a.isSelected,Ot=M(vt),{textVerticalResizeEnabled:Et}=z,St=z.autoDeleteEmptyText,zt=M(a.fontFamily),jt=i.useMemo(()=>q(a.text,{fontSize:a.fontSize,fontFamily:a.fontFamily}),[a.text,a.fontSize,a.fontFamily]),kt=i.useMemo(()=>G(jt,{fontFamily:a.fontFamily,fontWeight:a.fontWeight,fontStyle:a.fontStyle}),[jt,a.fontFamily,a.fontWeight,a.fontStyle]),[Mt]=R(it,kt,a.text||a.placeholder),Rt=a._editModeEnabled;J(mt);const Yt=Mt?a.fontFamily:zt&&zt!==a.fontFamily?zt:"Arial",Xt=B(a).fill,Ct=I(a.fill),Ft=I(a.stroke)&&!!a.strokeWidth,Bt=!!a.strokeWidth&&(Ft||Ct),Pt="ellipsis"===z.textOverflow&&!a.curveEnabled&&ot(a)&&!Bt,It=Z(a.placeholder),Tt=!!It&&!H(a.text),Wt=Tt?et(It):jt,Dt=Tt?.6:n(a),Nt=Y(P(a),{fontFamily:Yt,color:Xt,forEditor:!Pt,textOverflow:z.textOverflow,text:Wt,textIsNormalized:!0}),Jt=a.width||1,$t=F(a.letterSpacing,a.fontSize),Ht=a.curveEnabled,_t=xt?yt.current:null,At=null!==(at=null==_t?void 0:_t.width)&&void 0!==at?at:Jt,Lt=_t?a.width/_t.width:1,Vt=null!==(lt=null==_t?void 0:_t.overhang)&&void 0!==lt?lt:$t,qt=function(t,e,o,r){return i.useMemo(()=>{if(r){return null}try{return g({html:tt(t),width:Math.max(1,e),accuracy:"performance"})}catch(o){return console.error("render-tag layout failed:",o),null}},[t,e,o,r])}(null!==(st=null==_t?void 0:_t.html)&&void 0!==st?st:Nt,At,Mt,Ht),Gt=function(t,e,o){return i.useMemo(()=>{if(!e.curveEnabled){return null}const o=e.width||1,r=C(e),n=X(o,r,e.curvePower,e.fontSize);try{return p({html:tt(t),path:n,align:"center",textBaseline:"middle"})}catch(i){return console.error("render-tag/path layoutTextOnPath failed:",i),null}},[o,e.curveEnabled,e.curvePower,e.fontSize,e.width,e.height,t])}(Nt,a,Mt),Kt=k({fontLoaded:Mt,fontFamily:a.fontFamily,fontSize:a.fontSize,lineHeight:a.lineHeight}),Qt=Ht?0:Math.max(null!==(dt=null==qt?void 0:qt.height)&&void 0!==dt?dt:0,a.fontSize*Kt),Ut=Gt?Gt.bounds:null,Zt=Ut?(a.width-Ut.width)/2-Ut.x:0,te=i.useMemo(()=>{var t;if(Gt&&Ut){const t=Gt.paintBounds;return Object.assign(Object.assign({},t),{x:t.x+Zt,y:t.y-Ut.y})}return null!==(t=null==qt?void 0:qt.paintBounds)&&void 0!==t?t:null},[qt,Gt,Ut,Zt]),ee=i.useMemo(()=>qt?qt.lines.map(t=>N({left:t.bounds.x,right:t.bounds.x+t.bounds.width,top:t.bounds.y,bottom:t.bounds.y+t.bounds.height},Vt)):[],[qt,Vt]),oe=i.useRef([]),re=i.useRef(null),ne=i.useRef(!0),[,ie]=i.useReducer(t=>t+1,0);i.useEffect(()=>{const t=oe.current;t.length>0&&(oe.current=[],t.forEach(t=>t()))});const ae=i.useCallback((t,e,o,r)=>{const n=$(`text ${a.id}`),i=()=>{it.history.ignore(t,e,o).then(()=>{ne.current?(oe.current.push(n),ie()):n()})};r?queueMicrotask(i):i()},[a.id,it]),le=i.useCallback(t=>{const e=null!==re.current;re.current=t,e||ae(()=>{const t=re.current;re.current=null,u(a)&&nt(a.height,t)&&a.set({height:t})},!1,!0)},[a,ae]);i.useEffect(()=>{if(!Mt){return}if(!qt){return}if(!ot(a)){return void ae(()=>{u(a)&&(ot(a)||a.set({height:Qt}))},void 0,void 0,!0)}if(it.isPlaying){return}const{textOverflow:t}=z,e=nt(a.height,Qt),o=()=>le(Qt);if("change-font-size"!==t||xt||Rt||a.curveEnabled){"resize"===t&&e&&!xt&&o()}else{const t=U(Tt?{toJSON:()=>Object.assign(Object.assign({},a.toJSON()),{text:Wt})}:a,{fontFamily:Yt,color:Xt,forEditor:!0},t=>{try{return g({html:tt(t),width:Jt,accuracy:"performance"}).height}catch(at){return W(t).height}});t.fontSize!==a.fontSize?ae(()=>{if(!u(a)){return}const e=w(a,t.fontSize);void 0!==t.text&&t.text!==a.text&&(e.text=t.text),a.set(e)},!1,!0):e&&o()}}),i.useEffect(()=>()=>{ne.current=!1;const t=oe.current;t.length>0&&(oe.current=[],t.forEach(t=>t()))},[]),i.useLayoutEffect(()=>{if(!Mt||!a.curveEnabled||xt){return}if(!Ut||!Ut.width){return}const t=t=>t&&Et?Math.max(t,Ut.height):Ut.height;Math.abs(Ut.width-a.width)<1&&Math.abs(t(a.height)-a.height)<1||ae(()=>{if(!u(a)){return}const e=Ut.width-a.width,o=t(a.height),r=o-a.height;if(Math.abs(e)<1&&Math.abs(r)<1){return}const n=a.a.rotation*Math.PI/180,i=-e/2*Math.cos(n),l=-e/2*Math.sin(n);a.set({width:Ut.width,height:o,x:a.a.x+i,y:a.a.y+l})},!1,!0,!0)},[Mt,a.curveEnabled,Ut,xt,Et,ae]),i.useEffect(()=>{Ot&&!vt&&St&&""===H(a.text)&&a.removable&&!Z(a.placeholder)&&it.deleteElements([a.id])},[St,a.placeholder,a.removable,a.text,vt,Ot]),i.useEffect(()=>h(a,()=>{const t=mt.current;t&&j(t,a)}),[qt,Gt,a.a.width,a.a.height,a.shadowColor,a.shadowOffsetX,a.shadowOffsetY,a.shadowOpacity]);const se=rt(a,Qt),de=Ht||!Mt||xt||it.isPlaying||"resize"!==z.textOverflow?a.a.height:Et?Math.max(a.a.height,Qt):Qt;let ce=0;Ht||"middle"!==a.verticalAlign?Ht||"bottom"!==a.verticalAlign||(ce=se-Qt*Lt):ce=(se-Qt*Lt)/2;const he=null!==(ct=null==_t?void 0:_t.backgroundPadding)&&void 0!==ct?ct:a.backgroundPadding*(a.fontSize*Kt*.5),ue=null!==(ht=null==_t?void 0:_t.backgroundCornerRadius)&&void 0!==ht?ht:a.backgroundCornerRadius*(a.fontSize*Kt*.5),fe=a.backgroundEnabled||a.borderSize>0,ge=i.useMemo(()=>!fe||a.curveEnabled||a.legacyBackground||0===ee.length?"":D({rects:ee,padding:he,cornerRadius:ue}),[fe,a.curveEnabled,a.legacyBackground,ee,he,ue]),me=L(),pe=i.useRef(null),xe=i.useRef(a.width),be=i.useRef(null),we=i.useRef(null),ye=i.useRef(""),ve=i.useRef(0),Oe=i.useRef(0),Ee=a.width>0?a.a.width/a.width:1,Se=Ee*Lt,ze=null!=_t?_t:a,je={shadowEnabled:a.shadowEnabled&&fe,shadowBlur:ze.shadowBlur,shadowOffsetX:ze.shadowOffsetX,shadowOffsetY:ze.shadowOffsetY,shadowColor:T(a.shadowColor),shadowOpacity:a.shadowOpacity};return r(o,{children:[a.curveEnabled||a.legacyBackground?e(d,Object.assign({x:a.a.x,y:a.a.y,offsetX:he/Ee,offsetY:he/Ee,rotation:a.a.rotation,scaleX:Se,scaleY:Se,hideInExport:!a.showInExport,listening:!1,visible:fe,opacity:Dt,fillEnabled:a.backgroundEnabled,fill:A(a.backgroundColor,a.backgroundOpacity),strokeEnabled:a.borderSize>0,stroke:T(a.borderColor),strokeWidth:null!==(ut=null==_t?void 0:_t.borderSize)&&void 0!==ut?ut:a.borderSize},je,{width:At+2*he,height:(null!==(ft=null==_t?void 0:_t.boxHeight)&&void 0!==ft?ft:se)+2*he,cornerRadius:ue})):e(s,Object.assign({name:"rendertag-background",x:a.a.x,y:a.a.y,offsetY:-ce/Se,rotation:a.a.rotation,scaleX:Se,scaleY:Se,hideInExport:!a.showInExport,listening:!1,visible:fe&&ge.length>0,opacity:Dt,fillEnabled:a.backgroundEnabled,fill:A(a.backgroundColor,a.backgroundOpacity),strokeEnabled:a.borderSize>0,stroke:T(a.borderColor),strokeWidth:null!==(gt=null==_t?void 0:_t.borderSize)&&void 0!==gt?gt:a.borderSize,lineJoin:ue>0?"round":"miter"},je,{data:ge})),e(c,{ref:mt,selfRectFunc:te?()=>te:void 0,name:"rendertag-text",x:a.a.x,y:a.a.y,rotation:a.a.rotation,scaleX:Se,scaleY:Se,offsetY:Se>0?-ce/Se:0,width:At,height:Math.max(a.height,Qt),listening:!1,visible:!Rt&&!!(Ht?Gt:qt),editModeEnabled:Rt,opacity:Dt,shadowEnabled:a.shadowEnabled&&!_(a),shadowBlur:ze.shadowBlur,shadowOffsetX:ze.shadowOffsetX,shadowOffsetY:ze.shadowOffsetY,shadowColor:T(a.shadowColor),shadowOpacity:a.shadowOpacity,hideInExport:!a.showInExport,sceneFunc:(t,e)=>{const o=t._context;if(o){try{if(Ht){if(!Gt||!Ut){return}o.save(),o.translate(Zt,-Ut.y),x({layout:Gt,ctx:o}),o.restore()}else{if(!qt){return}m({layout:qt,width:At,ctx:o,pixelRatio:1})}}catch(r){console.error("render-tag draw failed:",r)}}}}),e(d,{ref:pt,name:"element",x:a.a.x,y:a.a.y,listening:a.selectable,rotation:a.a.rotation,width:a.a.width,height:de,visible:!Rt,draggable:me?a.draggable&&vt:a.draggable,preventDefault:!me||vt,opacity:0,hideInExport:!0,id:a.id,onDragMove:t=>{a.set({x:t.target.x(),y:t.target.y()})},onDragEnd:t=>{a.set(E(t.target))},onDblClick:t=>{a.contentEditable&&(we.current={x:t.evt.clientX,y:t.evt.clientY},a.toggleEditMode(!0))},onDblTap:t=>{var e;if(a.contentEditable){const o=null===(e=t.evt.changedTouches)||void 0===e?void 0:e[0];we.current=o?{x:o.clientX,y:o.clientY}:null,a.toggleEditMode(!0)}},onTransformStart:t=>{wt.current=a.height,xe.current=a.width,be.current=null,pe.current=t.target.position(),ye.current=b(t.target),ve.current=a.a.rotation,Oe.current=a.height,yt.current=!a.curveEnabled&&["top-left","top-right","bottom-left","bottom-right"].includes(ye.current)?{html:Nt,width:Jt,boxHeight:se,backgroundPadding:he,backgroundCornerRadius:ue,borderSize:a.borderSize,overhang:$t,shadowBlur:a.shadowBlur,shadowOffsetX:a.shadowOffsetX,shadowOffsetY:a.shadowOffsetY}:null,bt(!0)},onTransform:e=>{const o=e.target,r=ye.current,n="middle-left"===r||"middle-right"===r,i="top-center"===r||"bottom-center"===r,l=o.scaleX();if(n){const e=o.scaleX(),r=o.width()*e;let n=Math.max(r,S(xe.current,a.fontSize));const i=a.toJSON();let l=0;if(a.curveEnabled){l=C(Object.assign(Object.assign({},i),{width:n}))}else{const{x:e,y:o,width:r,height:a}=i,s=t(i,["x","y","width","height"]),d=`${JSON.stringify(s)}|${Yt}|${Mt}|${Xt}`;if(be.current&&be.current.signature===d&&n<=be.current.width){n=be.current.width,l=be.current.height}else{const t=t=>{const e=Y(Object.assign(Object.assign({},i),{width:t}),{fontFamily:Yt,color:Xt,forEditor:!0,text:Wt,textIsNormalized:!0});try{return g({html:tt(e),width:t,accuracy:"performance"})}catch(at){return{height:W(e).height,lines:[]}}};let e=t(n);const o=Math.max(0,...e.lines.map(t=>t.bounds.x+t.bounds.width-$t));o>n+.5&&o<=xe.current+.5&&(n=Math.min(Math.ceil(o),xe.current),e=t(n),be.current={signature:d,width:n,height:e.height}),l=e.height}}n>r&&pe.current&&o.position(pe.current),o.width(n),o.scaleX(1),o.scaleY(1);let s=z.textVerticalResizeEnabled?Math.max(l,wt.current):l;"ellipsis"===z.textOverflow&&(s=wt.current),o.height(s),a.set({width:o.width(),height:s,x:o.x(),y:o.y()})}else if(i){const t="resize"===z.textOverflow?Ht?(null==Ut?void 0:Ut.height)||a.fontSize:Qt:Kt*a.fontSize,e=o.height()*o.scaleY();if(e<t){if(o.height(t),pe.current){if("top-center"===ye.current){const e=ve.current*Math.PI/180,r=Oe.current-t;o.x(pe.current.x-r*Math.sin(e)),o.y(pe.current.y+r*Math.cos(e))}else{o.position(pe.current)}}}else{o.height(e)}o.scaleY(1),o.scaleX(1),Oe.current=Math.max(t,e),a.set({x:o.x(),y:o.y(),height:o.height(),rotation:o.rotation()})}else{o.scaleX(1),o.scaleY(1),a.set({fontSize:a.fontSize*l,letterSpacing:a.letterSpacing,width:o.width()*l,x:o.x(),y:o.y(),rotation:o.rotation(),height:o.height()*l,shadowBlur:a.shadowBlur*l,shadowOffsetX:a.shadowOffsetX*l,shadowOffsetY:a.shadowOffsetY*l,strokeWidth:a.strokeWidth*l,borderSize:a.borderSize*l,text:K(a.text,l)})}pe.current=e.target.position()},onTransformEnd:t=>{yt.current=null,bt(!1);const e=t.target.scaleX();t.target.scaleX(1),t.target.scaleY(1),a.set(Object.assign(Object.assign({},y(a,a.fontSize*e)),{width:O(t.target.width()*e),x:O(t.target.x()),y:O(t.target.y()),rotation:O(t.target.rotation()),text:K(a.text,e)}))}}),Rt&&e(l,{x:a.a.x,y:a.a.y,rotation:a.a.rotation,offsetY:-ce,children:e(f,{divProps:{style:{zIndex:20}},children:e(Q,{element:a,onChange:t=>{const e=V({oldText:H(a.text),newText:H(t),element:a});a.set(Object.assign({text:t},w(a,e)))},onBlur:()=>{u(a)&&(a.set(v(a)),a.toggleEditMode(!1))},clickCoords:we.current})})})]})});
@@ -1,4 +1,4 @@
1
- var e=this&&this.__rest||function(e,t){var o={};for(var n in e){Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(o[n]=e[n])}if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(n=Object.getOwnPropertySymbols(e);r<n.length;r++){t.indexOf(n[r])<0&&Object.prototype.propertyIsEnumerable.call(e,n[r])&&(o[n[r]]=e[n[r]])}}return o};import{jsx as t}from"react/jsx-runtime";import o from"react";import n from"quill";import*as r from"mobx";import{nodeReaction as i}from"../utils/mobx.js";import{isAlive as l}from"mobx-state-tree";import{getDir as a,getMeasureCtx as s,getQuillEditorHtml as d,textLayoutWidth as c}from"@polotno/core/text-html";import{quillHtmlToModelText as u,isQuillFormatMixed as f,isBoldWeight as p}from"../utils/rich-text-html.js";import{resetStyleContent as h,wrapHtmlForRenderTag as m}from"@polotno/core/reset-style";import{layout as g,lineBaselineOffset as b}from"render-tag";import{removeTags as v}from"@polotno/core/text";import{cssFontFamily as y}from"@polotno/core/fonts";import{isGradient as x,firstStopColor as w}from"@polotno/core/gradient";import{getOptimalCaretColor as k}from"./text-element/caret-color.js";import{visiblePlaceholder as S}from"./text-element/placeholder.js";import{registerQuillUnrestrictedFontFormats as q}from"./quill-font-formats.js";import{ALL_QUILL_MIXED_KEYS as T,setActiveTextEditor as E,updateActiveTextFormat as C,clearActiveTextEditor as L,getActiveTextEditor as F}from"../utils/text-format-state.js";import O from"../utils/styled.js";import{applyOpacityToColor as R}from"@polotno/core/svg";import{elementDropShadow as $,shadowCastByBackground as j}from"@polotno/core/filters";export{R as applyOpacityToColor};export const quillRef=r.observable({enabled:!1,currentFormat:{},pendingToolbarInteraction:!1,editor:r.observable.object({instance:null},{},{deep:!1})});const N=T;export function syncQuillFormatState(e,t){const o=t?e.getFormat(t):{},n=function(e,t){const o={};if(!t||t.length<=0){return o}const n=e.getContents(t.index,t.length);for(const r of N){f(n,r)&&(o[r]=!0)}return o}(e,t);r.runInAction(()=>{quillRef.currentFormat=o}),C(o,n,t)}const z="polotno-saved-selection";function M(){const e=window.getSelection();if(!e||0===e.rangeCount||e.isCollapsed){return}if("undefined"==typeof Highlight||!CSS.highlights){return}const t=e.getRangeAt(0).cloneRange();CSS.highlights.set(z,new Highlight(t)),Q()}function P(){"undefined"!=typeof CSS&&CSS.highlights&&CSS.highlights.delete(z)}function Q(){setTimeout(()=>{"undefined"!=typeof CSS&&CSS.highlights&&CSS.highlights.has(z)&&(document.querySelector(".polotno-portal")||B(document.activeElement)?Q():P())},300)}if("undefined"!=typeof document&&"undefined"!=typeof CSS&&CSS.highlights&&!document.querySelector("[data-polotno-highlight]")){const W=document.createElement("style");W.setAttribute("data-polotno-highlight",""),W.textContent=`::highlight(${z}) { background-color: Highlight; }`,document.head.appendChild(W)}function A(e,t){"text"===e.type&&t.push(e);for(const o of e.children||[]){A(o,t)}}export function computeMarkerVars(e){var t,o,n;const r=e.fontSize;if(!r||r<=0){return null}const i=y(e.fontFamily),l=p(e.fontWeight)?700:400,a="italic"===e.fontStyle?"italic":"normal",d=s();d.fontKerning="normal",d.font=`${r}px ${i}`;const c=d.measureText("M"),u=(null!==(t=c.fontBoundingBoxAscent)&&void 0!==t?t:0)/r,f=(null!==(o=c.fontBoundingBoxDescent)&&void 0!==o?o:0)/r,h=`font-family:${i};font-size:${r}px;font-weight:${l};font-style:${a};line-height:${e.lineHeight};letter-spacing:${e.letterSpacing}em`,v=m(`<div style="${h}"><ul><li>x</li></ul><ol><li>x</li></ol></div>`);let x;try{x=g({html:v,width:Math.max(12*r,600)})}catch(E){return null}const w=[];A(x.layoutRoot,w);const k=w.find(e=>"•"===e.text),S=w.find(e=>/^\d/.test(e.text));if(!k){return null}const q=k.style.fontSize,T=2.1*r;return{bulletLeft:k.x,bulletTop:k.y-b(q,q*u,q*f),bulletFontSize:q,numberGap:S?Math.max(0,T-S.x-(null!==(n=S.width)&&void 0!==n?n:0)):0}}export const RichTextContainer=O("div",o.forwardRef)`
1
+ var e=this&&this.__rest||function(e,t){var o={};for(var n in e){Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(o[n]=e[n])}if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(n=Object.getOwnPropertySymbols(e);r<n.length;r++){t.indexOf(n[r])<0&&Object.prototype.propertyIsEnumerable.call(e,n[r])&&(o[n[r]]=e[n[r]])}}return o};import{jsx as t}from"react/jsx-runtime";import o from"react";import n from"quill";import*as r from"mobx";import{nodeReaction as i}from"../utils/mobx.js";import{isAlive as l}from"mobx-state-tree";import{getDir as s,getMeasureCtx as a,getQuillEditorHtml as d,textLayoutWidth as c}from"@polotno/core/text-html";import{quillHtmlToModelText as u,isQuillFormatMixed as f,isBoldWeight as p,detachNativeColorsInHtml as h}from"../utils/rich-text-html.js";import{toDisplayColor as m}from"@polotno/core/color";import{resetStyleContent as g,wrapHtmlForRenderTag as b}from"@polotno/core/reset-style";import{layout as v,lineBaselineOffset as y}from"render-tag";import{removeTags as x}from"@polotno/core/text";import{cssFontFamily as w}from"@polotno/core/fonts";import{isGradient as k,firstStopColor as S}from"@polotno/core/gradient";import{getOptimalCaretColor as q}from"./text-element/caret-color.js";import{visiblePlaceholder as T}from"./text-element/placeholder.js";import{registerQuillUnrestrictedFontFormats as E}from"./quill-font-formats.js";import{ALL_QUILL_MIXED_KEYS as C,setActiveTextEditor as L,updateActiveTextFormat as O,clearActiveTextEditor as R,getActiveTextEditor as F}from"../utils/text-format-state.js";import $ from"../utils/styled.js";import{applyOpacityToColor as j}from"@polotno/core/svg";import{elementDropShadow as N,shadowCastByBackground as z}from"@polotno/core/filters";export{j as applyOpacityToColor};export const quillRef=r.observable({enabled:!1,currentFormat:{},pendingToolbarInteraction:!1,editor:r.observable.object({instance:null},{},{deep:!1})});const M=C;export function syncQuillFormatState(e,t){const o=t?e.getFormat(t):{},n=function(e,t){const o={};if(!t||t.length<=0){return o}const n=e.getContents(t.index,t.length);for(const r of M){f(n,r)&&(o[r]=!0)}return o}(e,t);r.runInAction(()=>{quillRef.currentFormat=o}),O(o,n,t)}const P="polotno-saved-selection";function Q(){const e=window.getSelection();if(!e||0===e.rangeCount||e.isCollapsed){return}if("undefined"==typeof Highlight||!CSS.highlights){return}const t=e.getRangeAt(0).cloneRange();CSS.highlights.set(P,new Highlight(t)),D()}function A(){"undefined"!=typeof CSS&&CSS.highlights&&CSS.highlights.delete(P)}function D(){setTimeout(()=>{"undefined"!=typeof CSS&&CSS.highlights&&CSS.highlights.has(P)&&(document.querySelector(".polotno-portal")||V(document.activeElement)?D():A())},300)}if("undefined"!=typeof document&&"undefined"!=typeof CSS&&CSS.highlights&&!document.querySelector("[data-polotno-highlight]")){const X=document.createElement("style");X.setAttribute("data-polotno-highlight",""),X.textContent=`::highlight(${P}) { background-color: Highlight; }`,document.head.appendChild(X)}function H(e,t){"text"===e.type&&t.push(e);for(const o of e.children||[]){H(o,t)}}export function computeMarkerVars(e){var t,o,n;const r=e.fontSize;if(!r||r<=0){return null}const i=w(e.fontFamily),l=p(e.fontWeight)?700:400,s="italic"===e.fontStyle?"italic":"normal",d=a();d.fontKerning="normal",d.font=`${r}px ${i}`;const c=d.measureText("M"),u=(null!==(t=c.fontBoundingBoxAscent)&&void 0!==t?t:0)/r,f=(null!==(o=c.fontBoundingBoxDescent)&&void 0!==o?o:0)/r,h=`font-family:${i};font-size:${r}px;font-weight:${l};font-style:${s};line-height:${e.lineHeight};letter-spacing:${e.letterSpacing}em`,m=b(`<div style="${h}"><ul><li>x</li></ul><ol><li>x</li></ol></div>`);let g;try{g=v({html:m,width:Math.max(12*r,600)})}catch(E){return null}const x=[];H(g.layoutRoot,x);const k=x.find(e=>"•"===e.text),S=x.find(e=>/^\d/.test(e.text));if(!k){return null}const q=k.style.fontSize,T=2.1*r;return{bulletLeft:k.x,bulletTop:k.y-y(q,q*u,q*f),bulletFontSize:q,numberGap:S?Math.max(0,T-S.x-(null!==(n=S.width)&&void 0!==n?n:0)):0}}export const RichTextContainer=$("div",o.forwardRef)`
2
2
  .ql-editor {
3
3
  outline: none;
4
4
  /* anchor for the absolutely-positioned ::before placeholder below */
@@ -25,7 +25,7 @@ var e=this&&this.__rest||function(e,t){var o={};for(var n in e){Object.prototype
25
25
  pointer-events: none;
26
26
  opacity: 0;
27
27
  }
28
- ${h}
28
+ ${g}
29
29
 
30
30
  /* ===== Editor-only list markers (Quill flat-DOM hack) ======================
31
31
  Quill emits a FLAT <ol> with per-item data-list + ql-indent classes (not
@@ -163,4 +163,4 @@ var e=this&&this.__rest||function(e,t){var o={};for(var n in e){Object.prototype
163
163
  .ql-editor [style*='background-clip'] {
164
164
  -webkit-text-stroke-width: 0;
165
165
  }
166
- `;let D=["background","font-weight","color","gradient","font","italic","size","script","strike","underline","indent","list","direction"];export const setQuillFormats=e=>{D=e};let H=!1;function I(){H||(H=!0,console.warn("[polotno] The Quill 'bold' format is deprecated. Use the numeric 'font-weight' format instead, e.g. quill.format('font-weight', '700') or applyTextFormat({ fontWeight: 700 })."))}function _(e){return e?"700":"400"}export const createQuill=(t,o)=>{q();const r=new n(t,{toolbar:!1,keyboard:!1,placeholder:(null==o?void 0:o.placeholder)||void 0,clipboard:{matchVisual:!1},formats:D});!function(t){const o=t.format.bind(t),n=t.formatText.bind(t),r=t.getFormat.bind(t);t.format=(e,t,n)=>"bold"===e?(I(),o("font-weight",_(t),n)):o(e,t,n),t.formatText=(t,o,r,i,l)=>{if(r&&"object"==typeof r){if("bold"in r){I();const{bold:l}=r,a=e(r,["bold"]);return n(t,o,Object.assign(Object.assign({},a),{"font-weight":_(l)}),i)}return n(t,o,r,i)}return"bold"===r?(I(),n(t,o,"font-weight",_(i),l)):n(t,o,r,i,l)},t.getFormat=(...e)=>{const t=r(...e);return t&&null!=t["font-weight"]&&!("bold"in t)&&(t.bold=p(t["font-weight"])),t}}(r);const i=n.import("delta"),l=(e,t)=>t.compose((new i).retain(t.length(),{"font-weight":"700"}));return r.clipboard.addMatcher("STRONG",l),r.clipboard.addMatcher("B",l),r};export const setQuillContent=(e,t)=>{var o=e.clipboard.convert({html:"<div class='ql-editor' style='outline: none;'>"+t.replace(/\t/g,"")+"<p><br></p></div>",text:""});o.ops.forEach(e=>{"string"==typeof e.insert&&e.insert.includes("")&&(e.insert=e.insert.split("").join("\t"))}),e.setContents(o),e.history.clear()};export const RichEditor=({onBlur:e,onChange:n,element:s,clickCoords:f})=>{const p=o.useRef(null),h=o.useRef(!1);o.useLayoutEffect(()=>{let t,o=!1,i=null,a=null,c=null,m=null,g=null;const b=()=>{if(!o&&p.current){try{t=createQuill(p.current,{placeholder:S(s.placeholder)}),r.runInAction(()=>{quillRef.editor.instance=t}),quillRef.pendingToolbarInteraction=!1,window.__polotnoQuill=t,E({instance:t,store:s.store,element:s});const o=e=>{e&&syncQuillFormatState(t,e)};t.on("text-change",()=>{const e=F(),r=e&&e.instance===t?e.lastSelection:null;o(t.getSelection()||r),setTimeout(()=>{var e,o;const r=t.root;if(!r||!r.isConnected){return}if(!l(s)){return}const i=r.innerHTML;h.current=!0,n(u(i,{fontSize:s.fontSize,fontFamily:s.fontFamily}));const a=t.getContents(),d=s.fill;let c=null,f=!0;for(const t of a.ops){if("string"!=typeof t.insert||"\n"===t.insert){continue}if(null===(e=t.attributes)||void 0===e?void 0:e.gradient){f=!1;break}const n=(null===(o=t.attributes)||void 0===o?void 0:o.color)||d;if(null===c){c=n}else if(n!==c){f=!1;break}}f&&c&&s.set({fill:c})},10)}),t.on("selection-change",o);const b=d(s,s.fontFamily);setQuillContent(t,b),h.current=!0;const v=p.current.closest(".polotno-workspace-inner"),y=null==v?void 0:v.scrollLeft,x=null==v?void 0:v.scrollTop;f?setCursorFromCoords(t,f):t.setSelection(0,0,"api"),v&&void 0!==y&&void 0!==x&&(v.scrollLeft=y,v.scrollTop=x);const w=t.root;m=t=>{const o=t.relatedTarget;(null==o?void 0:o.classList.contains("ql-clipboard"))||(B(o)||quillRef.pendingToolbarInteraction?M():setTimeout(()=>{quillRef.pendingToolbarInteraction||B(document.activeElement)?M():(P(),e())},0))},g=()=>{P()},w.addEventListener("blur",m),w.addEventListener("focus",g),i=w,a=e=>{var o,n;const r=t.getSelection();if(!r||0===r.length){return}const i=t.getText(r.index,r.length).replace(/\n$/,""),l=window.getSelection();let a="";if(l&&l.rangeCount>0){const e=l.getRangeAt(0);let t=e.cloneContents(),o=e.startContainer;o&&o.nodeType===Node.TEXT_NODE&&(o=o.parentNode);let n=e.endContainer;if(n&&n.nodeType===Node.TEXT_NODE&&(n=n.parentNode),o&&o===n){let e=o;for(;e&&e!==w&&e.nodeType===Node.ELEMENT_NODE;){const o=e.tagName;if("SPAN"!==o&&"EM"!==o&&"STRONG"!==o&&"U"!==o&&"S"!==o&&"A"!==o){break}const n=e.cloneNode(!1);n.appendChild(t),t=n,e=e.parentNode}}const r=document.createElement("div");r.appendChild(t),a=r.innerHTML}if(null===(o=e.clipboardData)||void 0===o||o.setData("text/plain",i),a){const t='<!DOCTYPE html><html><head><meta charset="utf-8"></head><body>\x3c!--StartFragment--\x3e<div style="white-space: pre-wrap; overflow-wrap: break-word;">'+a+"</div>\x3c!--EndFragment--\x3e</body></html>";null===(n=e.clipboardData)||void 0===n||n.setData("text/html",t)}e.preventDefault()},c=e=>{a&&a(e);const o=t.getSelection();o&&o.length>0&&t.deleteText(o.index,o.length)},i.addEventListener("copy",a),i.addEventListener("cut",c)}catch(b){console.error("RichEditor init failed:",b)}}};return p.current?b():queueMicrotask(b),()=>{o=!0,i&&m&&i.removeEventListener("blur",m),i&&g&&i.removeEventListener("focus",g),P(),i&&a&&c&&(i.removeEventListener("copy",a),i.removeEventListener("cut",c)),r.runInAction(()=>{quillRef.editor.instance=null,quillRef.currentFormat={}}),L(t),delete window.__polotnoQuill}},[]),o.useEffect(()=>i(s,()=>`${s.text}\0${s.fontSize}\0${s.fontFamily}`,()=>{const e=quillRef.editor.instance;if(!e){return}if(h.current){return void(h.current=!1)}const t=e.getSelection();setQuillContent(e,d(s,s.fontFamily)),h.current=!0,t&&(e.setSelection(t.index,t.length),syncQuillFormatState(e,e.getSelection()))},{fireImmediately:!0}),[]),o.useEffect(()=>i(s,()=>`${s.fontFamily}\0${s.fontSize}\0${s.fontWeight}\0${s.fontStyle}\0${s.lineHeight}\0${s.letterSpacing}\0${a(v(s.text))}`,()=>{const e=p.current;if(!e){return}const t="ltr"===a(v(s.text)),o=computeMarkerVars(s);o&&e.style.setProperty("--rt-number-gap",`${o.numberGap}px`),o&&t?(e.style.setProperty("--rt-bullet-left",`${o.bulletLeft}px`),e.style.setProperty("--rt-bullet-top",`${o.bulletTop}px`),e.style.setProperty("--rt-bullet-fs",`${o.bulletFontSize}px`),e.classList.add("rt-marker-geom")):e.classList.remove("rt-marker-geom")},{fireImmediately:!0}),[]),o.useEffect(()=>{window.addEventListener("blur",e);const t=t=>{var o;const n=t.target;"number"==typeof(null==n?void 0:n.nodeType)&&(null===(o=p.current)||void 0===o?void 0:o.contains(n))||B(n)||quillRef.pendingToolbarInteraction||(P(),e())};return window.addEventListener("mousedown",t),window.addEventListener("touchstart",t),()=>{window.removeEventListener("blur",e),window.removeEventListener("mousedown",t),window.removeEventListener("touchstart",t)}},[]);const m={color:s.fill};s.fill.indexOf("gradient")>=0&&(m["--polotno-gradient"]=s.fill,m.color="transparent"),s.strokeWidth>0&&(m.WebkitTextStroke=`${s.strokeWidth}px ${w(s.stroke)}`,m.paintOrder="stroke fill");const g=x(s.fill)?w(s.fill):k(s),b=s.shadowEnabled&&!j(s);return t(RichTextContainer,{ref:p,style:Object.assign(Object.assign({},m),{fontSize:s.fontSize,fontFamily:y(s.fontFamily),fontWeight:s.fontWeight,fontStyle:s.fontStyle,"--polotno-text-decoration":s.textDecoration||"none",textTransform:s.textTransform,width:c(s.a.width,s.letterSpacing,s.fontSize),lineHeight:s.lineHeight,letterSpacing:s.letterSpacing*s.fontSize+"px",textAlign:s.align,opacity:Math.max(s.a.opacity,.2),filter:b?$({shadowOffsetX:s.shadowOffsetX,shadowOffsetY:s.shadowOffsetY,shadowBlur:s.shadowBlur,shadowColor:s.shadowColor,shadowOpacity:s.shadowOpacity,rotation:s.a.rotation}):void 0,caretColor:g}),dir:a(v(s.text))})};function B(e){const t=e;return!("function"!=typeof(null==t?void 0:t.closest)||!t.closest(".sketch-picker")&&!t.closest("[data-polotno-keep-focus]")&&!t.closest(".polotno-portal")&&!t.closest(".polotno-toolbar"))}export function setCursorFromCoords(e,t){if(!e||!t){return}const{x:o,y:r}=t;try{let t=null;if(document.caretRangeFromPoint){t=document.caretRangeFromPoint(o,r)}else if(document.caretPositionFromPoint){const e=document.caretPositionFromPoint(o,r);e&&(t=document.createRange(),t.setStart(e.offsetNode,e.offset))}if(t){const o=n.find(t.startContainer,!0);if(o){const n=o.offset(e.scroll)+t.startOffset;return void e.setSelection(n,0,"api")}}}catch(i){}e.setSelection(0,0,"api")}
166
+ `;let I=["background","font-weight","color","gradient","font","italic","size","script","strike","underline","text-transform","indent","list","direction"];export const setQuillFormats=e=>{I=e};let _=!1;function B(){_||(_=!0,console.warn("[polotno] The Quill 'bold' format is deprecated. Use the numeric 'font-weight' format instead, e.g. quill.format('font-weight', '700') or applyTextFormat({ fontWeight: 700 })."))}function W(e){return e?"700":"400"}export const createQuill=(t,o)=>{E();const r=new n(t,{toolbar:!1,keyboard:!1,placeholder:(null==o?void 0:o.placeholder)||void 0,clipboard:{matchVisual:!1},formats:I});!function(t){const o=t.format.bind(t),n=t.formatText.bind(t),r=t.getFormat.bind(t);t.format=(e,t,n)=>"bold"===e?(B(),o("font-weight",W(t),n)):o(e,t,n),t.formatText=(t,o,r,i,l)=>{if(r&&"object"==typeof r){if("bold"in r){B();const{bold:l}=r,s=e(r,["bold"]);return n(t,o,Object.assign(Object.assign({},s),{"font-weight":W(l)}),i)}return n(t,o,r,i)}return"bold"===r?(B(),n(t,o,"font-weight",W(i),l)):n(t,o,r,i,l)},t.getFormat=(...e)=>{const t=r(...e);return t&&null!=t["font-weight"]&&!("bold"in t)&&(t.bold=p(t["font-weight"])),t}}(r);const i=n.import("delta"),l=(e,t)=>t.compose((new i).retain(t.length(),{"font-weight":"700"}));return r.clipboard.addMatcher("STRONG",l),r.clipboard.addMatcher("B",l),r};export const setQuillContent=(e,t)=>{var o=e.clipboard.convert({html:"<div class='ql-editor' style='outline: none;'>"+t.replace(/\t/g,"")+"<p><br></p></div>",text:""});o.ops.forEach(e=>{"string"==typeof e.insert&&e.insert.includes("")&&(e.insert=e.insert.split("").join("\t"))}),e.setContents(o),e.history.clear()};const G=e=>d(Object.assign(Object.assign({},e),{text:h(e.text)}),e.fontFamily);export const RichEditor=({onBlur:e,onChange:n,element:a,clickCoords:d})=>{const f=o.useRef(null),p=o.useRef(!1);o.useLayoutEffect(()=>{let t,o=!1,i=null,s=null,c=null,h=null,m=null;const g=()=>{if(!o&&f.current){try{t=createQuill(f.current,{placeholder:T(a.placeholder)}),r.runInAction(()=>{quillRef.editor.instance=t}),quillRef.pendingToolbarInteraction=!1,window.__polotnoQuill=t,L({instance:t,store:a.store,element:a});const o=e=>{e&&syncQuillFormatState(t,e)};t.on("text-change",()=>{const e=F(),r=e&&e.instance===t?e.lastSelection:null;o(t.getSelection()||r),setTimeout(()=>{var e,o;const r=t.root;if(!r||!r.isConnected){return}if(!l(a)){return}const i=r.innerHTML;p.current=!0,n(u(i,{fontSize:a.fontSize,fontFamily:a.fontFamily}));const s=t.getContents(),d=a.fill;let c=null,f=!0;for(const t of s.ops){if("string"!=typeof t.insert||"\n"===t.insert){continue}if(null===(e=t.attributes)||void 0===e?void 0:e.gradient){f=!1;break}const n=(null===(o=t.attributes)||void 0===o?void 0:o.color)||d;if(null===c){c=n}else if(n!==c){f=!1;break}}f&&c&&a.set({fill:c})},10)}),t.on("selection-change",o),setQuillContent(t,G(a)),p.current=!0;const g=f.current.closest(".polotno-workspace-inner"),b=null==g?void 0:g.scrollLeft,v=null==g?void 0:g.scrollTop;d?setCursorFromCoords(t,d):t.setSelection(0,0,"api"),g&&void 0!==b&&void 0!==v&&(g.scrollLeft=b,g.scrollTop=v);const y=t.root;h=t=>{const o=t.relatedTarget;(null==o?void 0:o.classList.contains("ql-clipboard"))||(V(o)||quillRef.pendingToolbarInteraction?Q():setTimeout(()=>{quillRef.pendingToolbarInteraction||V(document.activeElement)?Q():(A(),e())},0))},m=()=>{A()},y.addEventListener("blur",h),y.addEventListener("focus",m),i=y,s=e=>{var o,n;const r=t.getSelection();if(!r||0===r.length){return}const i=t.getText(r.index,r.length).replace(/\n$/,""),l=window.getSelection();let s="";if(l&&l.rangeCount>0){const e=l.getRangeAt(0);let t=e.cloneContents(),o=e.startContainer;o&&o.nodeType===Node.TEXT_NODE&&(o=o.parentNode);let n=e.endContainer;if(n&&n.nodeType===Node.TEXT_NODE&&(n=n.parentNode),o&&o===n){let e=o;for(;e&&e!==y&&e.nodeType===Node.ELEMENT_NODE;){const o=e.tagName;if("SPAN"!==o&&"EM"!==o&&"STRONG"!==o&&"U"!==o&&"S"!==o&&"A"!==o){break}const n=e.cloneNode(!1);n.appendChild(t),t=n,e=e.parentNode}}const r=document.createElement("div");r.appendChild(t),s=r.innerHTML}if(null===(o=e.clipboardData)||void 0===o||o.setData("text/plain",i),s){const t='<!DOCTYPE html><html><head><meta charset="utf-8"></head><body>\x3c!--StartFragment--\x3e<div style="white-space: pre-wrap; overflow-wrap: break-word;">'+s+"</div>\x3c!--EndFragment--\x3e</body></html>";null===(n=e.clipboardData)||void 0===n||n.setData("text/html",t)}e.preventDefault()},c=e=>{s&&s(e);const o=t.getSelection();o&&o.length>0&&t.deleteText(o.index,o.length)},i.addEventListener("copy",s),i.addEventListener("cut",c)}catch(g){console.error("RichEditor init failed:",g)}}};return f.current?g():queueMicrotask(g),()=>{o=!0,i&&h&&i.removeEventListener("blur",h),i&&m&&i.removeEventListener("focus",m),A(),i&&s&&c&&(i.removeEventListener("copy",s),i.removeEventListener("cut",c)),r.runInAction(()=>{quillRef.editor.instance=null,quillRef.currentFormat={}}),R(t),delete window.__polotnoQuill}},[]),o.useEffect(()=>i(a,()=>`${a.text}\0${a.fontSize}\0${a.fontFamily}`,()=>{const e=quillRef.editor.instance;if(!e){return}if(p.current){return void(p.current=!1)}const t=e.getSelection();setQuillContent(e,G(a)),p.current=!0,t&&(e.setSelection(t.index,t.length),syncQuillFormatState(e,e.getSelection()))},{fireImmediately:!0}),[]),o.useEffect(()=>i(a,()=>`${a.fontFamily}\0${a.fontSize}\0${a.fontWeight}\0${a.fontStyle}\0${a.lineHeight}\0${a.letterSpacing}\0${s(x(a.text))}`,()=>{const e=f.current;if(!e){return}const t="ltr"===s(x(a.text)),o=computeMarkerVars(a);o&&e.style.setProperty("--rt-number-gap",`${o.numberGap}px`),o&&t?(e.style.setProperty("--rt-bullet-left",`${o.bulletLeft}px`),e.style.setProperty("--rt-bullet-top",`${o.bulletTop}px`),e.style.setProperty("--rt-bullet-fs",`${o.bulletFontSize}px`),e.classList.add("rt-marker-geom")):e.classList.remove("rt-marker-geom")},{fireImmediately:!0}),[]),o.useEffect(()=>{window.addEventListener("blur",e);const t=t=>{var o;const n=t.target;"number"==typeof(null==n?void 0:n.nodeType)&&(null===(o=f.current)||void 0===o?void 0:o.contains(n))||V(n)||quillRef.pendingToolbarInteraction||(A(),e())};return window.addEventListener("mousedown",t),window.addEventListener("touchstart",t),()=>{window.removeEventListener("blur",e),window.removeEventListener("mousedown",t),window.removeEventListener("touchstart",t)}},[]);const h=m(a.fill),g={color:h};h.indexOf("gradient")>=0&&(g["--polotno-gradient"]=h,g.color="transparent"),a.strokeWidth>0&&(g.WebkitTextStroke=`${a.strokeWidth}px ${S(a.stroke)}`,g.paintOrder="stroke fill");const b=k(a.fill)?S(a.fill):q(a),v=a.shadowEnabled&&!z(a);return t(RichTextContainer,{ref:f,style:Object.assign(Object.assign({},g),{fontSize:a.fontSize,fontFamily:w(a.fontFamily),fontWeight:a.fontWeight,fontStyle:a.fontStyle,"--polotno-text-decoration":a.textDecoration||"none",textTransform:a.textTransform,width:c(a.a.width,a.letterSpacing,a.fontSize),lineHeight:a.lineHeight,letterSpacing:a.letterSpacing*a.fontSize+"px",textAlign:a.align,opacity:Math.max(a.a.opacity,.2),filter:v?N({shadowOffsetX:a.shadowOffsetX,shadowOffsetY:a.shadowOffsetY,shadowBlur:a.shadowBlur,shadowColor:a.shadowColor,shadowOpacity:a.shadowOpacity,rotation:a.a.rotation}):void 0,caretColor:b}),dir:s(x(a.text))})};function V(e){const t=e;return!("function"!=typeof(null==t?void 0:t.closest)||!t.closest(".sketch-picker")&&!t.closest("[data-polotno-keep-focus]")&&!t.closest(".polotno-portal")&&!t.closest(".polotno-toolbar"))}export function setCursorFromCoords(e,t){if(!e||!t){return}const{x:o,y:r}=t;try{let t=null;if(document.caretRangeFromPoint){t=document.caretRangeFromPoint(o,r)}else if(document.caretPositionFromPoint){const e=document.caretPositionFromPoint(o,r);e&&(t=document.createRange(),t.setStart(e.offsetNode,e.offset))}if(t){const o=n.find(t.startContainer,!0);if(o){const n=o.offset(e.scroll)+t.startOffset;return void e.setSelection(n,0,"api")}}}catch(i){}e.setSelection(0,0,"api")}
@@ -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{ROLES as w}from"../model/store.js";import{isTouchDevice as p}from"../utils/screen.js";import{roundedGeometryPx as f,roundedPosition as x}from"../utils/px.js";import{TextElement as y}from"./text-element.js";const v="#0d83dd",m=(t,e)=>{const o=t.target.getStage();o&&(o.container().style.cursor=e)},b=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?v:"#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}),m(t,"pointer")},onMouseLeave:t=>{y(null),m(t,"")},onClick:x})]})),C=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:b}=u,C=r||h;return o(a,{x:i,y:n,onMouseEnter:t=>{p({kind:l,idx:s}),m(t,"pointer")},onMouseLeave:t=>{p(null),m(t,"")},onClick:t=>{t.cancelBubble=!0,w()},children:[t(c,{x:-f/2,y:-f/2,width:f,height:f,fill:"transparent"}),C&&o(e,{children:[t(g,{radius:x+y,fill:"white",listening:!1}),t(g,{radius:x,fill:v,listening:!1}),t(d,{points:[.55*-x,0,.55*x,0],stroke:"white",strokeWidth:b,lineCap:"round",listening:!1}),t(d,{points:[0,.55*-x,0,.55*x],stroke:"white",strokeWidth:b,lineCap:"round",listening:!1})]})]})}),k=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(b,{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(C,{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(b,{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(C,{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 v=n.useRef(null),m=n.useRef(null),b=r.selectable||g.role===w.ADMIN,C=p(),S=r.isSelected,E=r._focusedCellIds.length>0,I=r.editingCell,H=1/Math.max(.01,g.scale),[M,R]=n.useState(null);n.useEffect(()=>{S||(r.clearCellFocus(),R(null))},[S]);const W=null==I?void 0:I._editModeEnabled;n.useEffect(()=>{r._editingCellId&&I&&!I._editModeEnabled&&r.exitCellEdit()},[W]),n.useEffect(()=>{E&&!r._editingCellId&&setTimeout(()=>{var t;return null===(t=m.current)||void 0===t?void 0:t.focus()},0)},[E,r._editingCellId]);const T=n.useMemo(()=>l.box(!1),[]);n.useEffect(()=>h(r,()=>{T.get()||r._fitRowsToContent&&g.history.ignore(()=>{r._applyFitRowsToContent()})}),[r,g,T]);const B=t=>{const e=t.target.getStage();if(!e){return}const o=e.getPointerPosition();if(!o){return}const i=v.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}}},$=(t,e)=>"dashed"===t?[4*e,2*e]:"dotted"===t?[e,e]:void 0,_=[];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);_.push(t(d,{points:[r,n,h,n],stroke:i.color,strokeWidth:i.width,dash:$(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);_.push(t(d,{points:[l,s,l,h],stroke:r.color,strokeWidth:r.width,dash:$(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);_.push(t(d,{points:[h,r,a,r],stroke:i.color,strokeWidth:i.width,dash:$(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);_.push(t(d,{points:[l,h,l,a],stroke:r.color,strokeWidth:r.width,dash:$(r.style,r.width),listening:!1},`br-${e.id}`))}}}return o(e,{children:[t(c,{id:r.id,name:"element",x:r.a.x,y:r.a.y,rotation:r.a.rotation,width:r.a.width,height:r.a.height,fill:"transparent",opacity:i(r),hideInExport:!r.showInExport,listening:b,draggable:C?r.draggable&&S:r.draggable,onClick:t=>{if(!S){return}if(r.locked||!r.contentEditable){return}const e=B(t);e&&(t.evt.shiftKey&&E?(t.cancelBubble=!0,r.focusCellRange(e.row,e.col)):r.focusCell(e.id))},onDblClick:t=>{if(!S){return}if(r.locked||!r.contentEditable){return}const e=B(t);e&&r.enterCellEdit(e.id)},onDragMove:t=>{var e;const o=t.target;r.set({x:o.x(),y:o.y()}),null===(e=v.current)||void 0===e||e.position({x:o.x(),y:o.y()})},onDragEnd:t=>{r.set(x(t.target))},onTransformStart:()=>{s(()=>T.set(!0))},onTransformEnd:()=>{r.set({x:f(r.x),y:f(r.y),width:f(r.width),rotation:f(r.rotation)}),r._resetBaseRowHeights(),s(()=>T.set(!1))},onTransform:t=>{var e,o;const i=t.target,n=i.scaleX(),l=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=v.current)||void 0===e||e.position({x:a,y:c}),null===(o=v.current)||void 0===o||o.rotation(d),r.set({width:s,x:a,y:c,rotation:d}),r.setHeightRedistribute(h)}}),o(a,{ref:v,x:r.a.x,y:r.a.y,rotation:r.a.rotation,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:e.cellBackground,listening:!1},`bg-${e.id}`)}),_,r.visibleCells.map(e=>t(y,{element:e,store:g},`text-${e.id}`)),S&&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*H;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}`)}),E&&!I&&t(u,{children:t("div",{ref:m,tabIndex:-1,style:{position:"absolute",opacity:0,width:"1px",height:"1px",pointerEvents:"none",outline:"none"}})}),S&&!I&&!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"),R({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=""),R(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})(),S&&!I&&!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"),R({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=""),R(null)},onDragStart:t=>{t.cancelBubble=!0,s(()=>T.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(()=>T.set(!1)),g.history.endTransaction()}},`row-resize-${i}`))}return e})(),S&&!I&&!g.isPlaying&&t(k,{element:r,store:g,inv:H,isTouch:C,hover:M,setHover:R})]})]})});
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}from"../utils/px.js";import{TextElement as v}from"./text-element.js";const m="#0d83dd",b=(t,e)=>{const o=t.target.getStage();o&&(o.container().style.cursor=e)},C=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?m:"#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}),b(t,"pointer")},onMouseLeave:t=>{y(null),b(t,"")},onClick:x})]})),k=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,C=r||h;return o(a,{x:i,y:n,onMouseEnter:t=>{p({kind:l,idx:s}),b(t,"pointer")},onMouseLeave:t=>{p(null),b(t,"")},onClick:t=>{t.cancelBubble=!0,w()},children:[t(c,{x:-f/2,y:-f/2,width:f,height:f,fill:"transparent"}),C&&o(e,{children:[t(g,{radius:x+y,fill:"white",listening:!1}),t(g,{radius:x,fill:m,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})]})]})}),S=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(C,{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(k,{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(C,{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(k,{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 m=n.useRef(null),b=n.useRef(null),C=r.selectable||g.role===p.ADMIN,k=f(),E=r.isSelected,I=r._focusedCellIds.length>0,H=r.editingCell,M=1/Math.max(.01,g.scale),[R,W]=n.useState(null);n.useEffect(()=>{E||(r.clearCellFocus(),W(null))},[E]);const T=null==H?void 0:H._editModeEnabled;n.useEffect(()=>{r._editingCellId&&H&&!H._editModeEnabled&&r.exitCellEdit()},[T]),n.useEffect(()=>{I&&!r._editingCellId&&setTimeout(()=>{var t;return null===(t=b.current)||void 0===t?void 0:t.focus()},0)},[I,r._editingCellId]);const B=n.useMemo(()=>l.box(!1),[]);n.useEffect(()=>h(r,()=>{B.get()||r._fitRowsToContent&&g.history.ignore(()=>{r._applyFitRowsToContent()})}),[r,g,B]);const $=t=>{const e=t.target.getStage();if(!e){return}const o=e.getPointerPosition();if(!o){return}const i=m.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}}},_=(t,e)=>"dashed"===t?[4*e,2*e]:"dotted"===t?[e,e]:void 0,D=[];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);D.push(t(d,{points:[r,n,h,n],stroke:w(i.color),strokeWidth:i.width,dash:_(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);D.push(t(d,{points:[l,s,l,h],stroke:w(r.color),strokeWidth:r.width,dash:_(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);D.push(t(d,{points:[h,r,a,r],stroke:w(i.color),strokeWidth:i.width,dash:_(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);D.push(t(d,{points:[l,h,l,a],stroke:w(r.color),strokeWidth:r.width,dash:_(r.style,r.width),listening:!1},`br-${e.id}`))}}}return o(e,{children:[t(c,{id:r.id,name:"element",x:r.a.x,y:r.a.y,rotation:r.a.rotation,width:r.a.width,height:r.a.height,fill:"transparent",opacity:i(r),hideInExport:!r.showInExport,listening:C,draggable:k?r.draggable&&E:r.draggable,onClick:t=>{if(!E){return}if(r.locked||!r.contentEditable){return}const e=$(t);e&&(t.evt.shiftKey&&I?(t.cancelBubble=!0,r.focusCellRange(e.row,e.col)):r.focusCell(e.id))},onDblClick:t=>{if(!E){return}if(r.locked||!r.contentEditable){return}const e=$(t);e&&r.enterCellEdit(e.id)},onDragMove:t=>{var e;const o=t.target;r.set({x:o.x(),y:o.y()}),null===(e=m.current)||void 0===e||e.position({x:o.x(),y:o.y()})},onDragEnd:t=>{r.set(y(t.target))},onTransformStart:()=>{s(()=>B.set(!0))},onTransformEnd:()=>{r.set({x:x(r.x),y:x(r.y),width:x(r.width),rotation:x(r.rotation)}),r._resetBaseRowHeights(),s(()=>B.set(!1))},onTransform:t=>{var e,o;const i=t.target,n=i.scaleX(),l=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=m.current)||void 0===e||e.position({x:a,y:c}),null===(o=m.current)||void 0===o||o.rotation(d),r.set({width:s,x:a,y:c,rotation:d}),r.setHeightRedistribute(h)}}),o(a,{ref:m,x:r.a.x,y:r.a.y,rotation:r.a.rotation,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}`)}),D,r.visibleCells.map(e=>t(v,{element:e,store:g},`text-${e.id}`)),E&&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*M;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}`)}),I&&!H&&t(u,{children:t("div",{ref:b,tabIndex:-1,style:{position:"absolute",opacity:0,width:"1px",height:"1px",pointerEvents:"none",outline:"none"}})}),E&&!H&&!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"),W({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=""),W(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})(),E&&!H&&!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"),W({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=""),W(null)},onDragStart:t=>{t.cancelBubble=!0,s(()=>B.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(()=>B.set(!1)),g.history.endTransaction()}},`row-resize-${i}`))}return e})(),E&&!H&&!g.isPlaying&&t(S,{element:r,store:g,inv:M,isTouch:k,hover:R,setHover:W})]})]})});
@@ -1 +1 @@
1
- import{getBrightness as o}from"../../utils/luma.js";export function getOptimalCaretColor(t){const{outlineSize:l,outlineColor:i}=function(o){const t=o.strokeWidth||0;if(t>0){return{outlineSize:t,outlineColor:o.stroke}}return{outlineSize:o.shadowEnabled&&o.shadowBlur>0&&o.shadowOpacity>.1?o.shadowBlur*o.shadowOpacity:0,outlineColor:o.shadowColor}}(t);if(l<.001){return t.fill}const r=o(t.fill),e=o(i);return Math.abs(r-e)>=50?i:t.fill}
1
+ import{toDisplayColor as o}from"@polotno/core/color";import{getBrightness as t}from"../../utils/luma.js";export function getOptimalCaretColor(r){return o(function(o){const{outlineSize:r,outlineColor:l}=function(o){const t=o.strokeWidth||0;if(t>0){return{outlineSize:t,outlineColor:o.stroke}}return{outlineSize:o.shadowEnabled&&o.shadowBlur>0&&o.shadowOpacity>.1?o.shadowBlur*o.shadowOpacity:0,outlineColor:o.shadowColor}}(o);if(r<.001){return o.fill}const i=t(o.fill),n=t(l);return Math.abs(i-n)>=50?l:o.fill}(r))}
@@ -1 +1 @@
1
- import{jsx as t,Fragment as e,jsxs as r}from"react/jsx-runtime";import{elementOpacity as n}from"./paint-opacity.js";import o from"react";import{observer as i}from"mobx-react-lite";import{Group as a,Path as s,Text as l,TextPath as c}from"react-konva";import{Html as u}from"react-konva-utils";import{nodeAutorun as d}from"../utils/mobx.js";import f from"konva";import{parsePath as h,roundCommands as g}from"svg-round-corners/lib/index.js";import{generateBackgroundShapeFromRects as p,textLinesToRects as m}from"@polotno/core/background-shape";import{useColor as x}from"./use-color.js";import{useWorkspaceStyle as w}from"./workspace-style.js";import{ROLES as v}from"../model/store.js";import{incrementLoader as y}from"../utils/loader.js";import{activeAnchorOf as b,scaledFontSizeAttrs as S,roundedFontSizeAttrs as E,roundedTextDecorationAttrs as z,roundedGeometryPx as k,roundedPosition as O,textMinResizeWidth as R}from"../utils/px.js";import{isFontLoaded as F}from"../utils/fonts.js";import{flags as A}from"../utils/flags.js";import{removeTags as j}from"@polotno/core/text";import{getDir as M,getCurvePath as L,resolveLineHeight as C,normalizeStrokeLineJoin as T}from"@polotno/core/text-html";import{cssFontFamily as H}from"@polotno/core/fonts";import{FIT_FONT_SIZE_STEP as P,FIT_HEIGHT_EPSILON as X}from"@polotno/core/fit-text";import{applyFilter as Y}from"./apply-filters.js";import{useFadeIn as W}from"./use-fadein.js";import{isTouchDevice as D}from"../utils/screen.js";import{isAlive as $,getParent as B}from"mobx-state-tree";import{getLimitedFontSize as I}from"./text-element/max-font-size.js";import{getOptimalCaretColor as N}from"./text-element/caret-color.js";import{visiblePlaceholder as J}from"./text-element/placeholder.js";import{hasMeasuredHeight as _,resolveTextBoxHeight as V}from"@polotno/core/text-types";let q;function U(){return q||(q=document.getElementById("polotno-text-style"),q||(q=document.createElement("style"),q.id="polotno-text-style",document.head.appendChild(q)),q)}f._fixTextRendering=!0;const Z={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 G=i(({textNodeRef:e,element:r,onBlur:n,selectAll:i,cursorPosition:a})=>{const[s,l]=o.useState(Z),c=e.current;o.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=N(r);const e=`\n .polotno-input::placeholder {\n color: ${s.color};\n opacity: 0.6;\n }\n `,n=U();n.innerHTML="",n.appendChild(document.createTextNode(e)),JSON.stringify(t)!==JSON.stringify(s)&&l(t)});const u=o.useRef(null);if(o.useLayoutEffect(()=>{var t;const e=u.current;if(!e){return}null===(t=u.current)||void 0===t||t.focus({preventScroll:!0});const r=a||e.value.length;e.selectionStart=e.selectionEnd=r,i&&(null==e||e.select(),document.execCommand("selectAll",!1,void 0))},[]),o.useEffect(()=>{window.addEventListener("blur",n);const t=t=>{var e;(null===(e=u.current)||void 0===e?void 0:e.contains(t.target))||n()};return window.addEventListener("touchstart",t),()=>{window.removeEventListener("blur",n),window.removeEventListener("touchstart",t)}},[]),!c){return null}let d=0;const f=c.textArr.length*c.lineHeight()*c.fontSize(),h=V(r.a,f);"middle"===r.verticalAlign&&(d=(h-f)/2),"bottom"===r.verticalAlign&&(d=h-f);const g=j(r.text);return t("textarea",{className:"polotno-input",ref:u,dir:M(g),style:Object.assign(Object.assign(Object.assign({},Z),s),{paddingTop:d+"px"}),value:g,onChange:t=>{const e=I({oldText:r.text,newText:t.target.value,element:r});r.set(Object.assign({text:t.target.value},S(r,e)))},placeholder:J(r.placeholder),onBlur:n})}),K=e=>t(u,{children:t(G,Object.assign({},e))});export const useFontLoader=(t,e,r,n,i)=>{const[a,s]=o.useReducer(t=>t+1,0),l=o.useRef(F(e,r,n)),c=o.useRef(null);return o.useLayoutEffect(()=>{if(l.current=F(e,r,n),l.current){return}let o=!0;return(async()=>{l.current=!1,s();const a=y(`text ${e}`);await t.loadFont(e,r,n,i),o?(c.current=a,l.current=!0,s()):a()})(),()=>{c.current&&(c.current(),c.current=null),o=!1}},[e,r,n]),o.useEffect(()=>{l.current&&setTimeout(()=>{c.current&&(c.current(),c.current=null)})},[l.current]),[l.current]};export const useFontFamiliesLoader=(t,e,r,n,i)=>{const[a,s]=o.useReducer(t=>t+1,0),l=e.join("\0"),c=o.useRef(e.every(t=>F(t,r,n))),u=o.useRef(null);return o.useLayoutEffect(()=>{if(c.current=e.every(t=>F(t,r,n)),c.current){return}let o=!0;return(async()=>{c.current=!1,s();const a=y(`text fonts ${l}`);await Promise.all(e.map(e=>t.loadFont(e,r,n,i))),o?(u.current=a,c.current=!0,s()):a()})(),()=>{u.current&&(u.current(),u.current=null),o=!1}},[l,r,n]),o.useEffect(()=>{c.current&&setTimeout(()=>{u.current&&(u.current(),u.current=null)})},[c.current]),[c.current]};export const getLineHeight=({fontLoaded:t,fontFamily:e,fontSize:r,lineHeight:n})=>o.useMemo(()=>C({fontFamily:e,fontSize:r,lineHeight:n}),[t,e,r,n]);export function usePrevious(t){const e=o.useRef(t),r=o.useRef(t);return o.useMemo(()=>{r.current=e.current,e.current=t},[t]),r.current}function Q(t,e,r=!1){const n=t.fontSize(),o=t.height(),i=j(e.text);let a=e.a.fontSize;t.height(void 0);const s=Math.round(2*e.a.fontSize)-1;for(let l=1;l<s;l++){const n=_(e.a)&&t.height()>e.a.height+X;let o=i.split("\n").join(" ").split(/[\s-]+/).reduce((t,e)=>(e=e.toLowerCase(),/[\u3000-\u303F\u3040-\u309F\u30A0-\u30FF\uFF00-\uFFEF\u4E00-\u9FAF\uAC00-\uD7AF]/.test(e)?t.concat(e.split("")):t.concat(e)),[]),s=t.textArr.map(t=>t.text.toLowerCase()).join(";");const l=o.find(t=>!s.includes(t)||(s=s.replace(t,""),!1));if(!(n||l&&!r)){break}a-=P,t.fontSize(a)}return t.fontSize(n),t.height(o),a}export{getCurvePath}from"@polotno/core/text-html";export const TextElement=i(({element:i,store:u})=>{const{textOverflowIndicatorStyle:f}=w(),F=o.useRef(null),C=o.useRef(null),P=o.useRef(null),X=o.useRef([]),I=o.useRef(!0),[,N]=o.useReducer(t=>t+1,0),{editorEnabled:q,selectAll:U}=(t=>{const[e,r]=o.useState(!1),n=o.useRef(!1);return o.useEffect(()=>{var e=!0;return setTimeout(()=>{e&&(t._editModeEnabled&&(n.current=!0),r(!0),setTimeout(()=>{n.current=!1},50))},50),()=>{e=!1}},[]),{editorEnabled:e&&t._editModeEnabled,selectAll:n.current}})(i),[Z,G]=o.useState(!1),[tt,et]=o.useState(!1),rt=o.useRef(i.a.height),nt=o.useRef(0),ot=o.useRef(""),it=o.useRef(0),at=i.isSelected,st=usePrevious(at),{textVerticalResizeEnabled:lt}=A,ct=A.autoDeleteEmptyText,ut=usePrevious(i.fontFamily),[dt,ft]=o.useState([]);o.useEffect(()=>{var t,e;const r=null!==(e=null===(t=F.current)||void 0===t?void 0:t.textArr)&&void 0!==e?e:[];JSON.stringify(r)!==JSON.stringify(dt)&&ft(r)}),o.useEffect(()=>{if(i.a.width||"tablecell"===i.type){return}const t=F.current;t.width(600),i.set({width:1.4*t.getTextWidth()})},[]),o.useEffect(()=>{st&&!at&&ct&&""===i.text&&i.removable&&!J(i.placeholder)&&u.deleteElements([i.id])},[ct,i.placeholder,i.removable,i.text,at,st]);const ht=()=>{if(i.curveEnabled){const t=F.current;null==t||t.clearCache(),null==t||t.setAttrs({filters:[]});const e=C.current;e&&Y(e,i)}else{const t=F.current;t&&Y(t,i)}};o.useLayoutEffect(()=>{if(!tt){return d(i,()=>{ht()})}}),o.useEffect(()=>{const t=X.current;t.length>0&&(X.current=[],t.forEach(t=>t()))}),o.useEffect(()=>()=>{I.current=!1;const t=X.current;t.length>0&&(X.current=[],t.forEach(t=>t()))},[]);let gt=j(i.text);"uppercase"===i.textTransform&&(gt=gt.toUpperCase());const[pt]=useFontLoader(u,i.fontFamily,i.fontStyle,i.fontWeight,i.text||i.placeholder),mt=()=>{if(i.curveEnabled){const t=C.current;return t.getSelfRect().height||t.fontSize()}const t=F.current.clone({height:void 0}),e=Math.ceil(t.fontSize()*t.lineHeight()*t.textArr.length+1);return t.destroy(),e};o.useLayoutEffect(()=>{if(!pt){return}if("tablecell"===i.type){const{textOverflow:t}=A;if("resize"===t){const t=mt(),e=$(i)?B(i,2):null;(null==e?void 0:e.setCellContentHeight)&&e.setCellContentHeight(i.id,t)}else if("change-font-size"===t){const t=F.current;if(t){const e=Q(t,i,A.textSplitAllowed);e!==i.fontSize&&u.history.ignore(()=>{i.set({fontSize:e})})}}return}const{textOverflow:t,textSplitAllowed:e}=A,r=(t,e,r,n)=>{const o=y(`text ${i.id}`),a=()=>{u.history.ignore(t,e,r).then(()=>{I.current?(X.current.push(o),N()):o()})};n?queueMicrotask(a):a()};if(!_(i)){const t=mt();return void r(()=>{_(i)||i.set({height:t})},void 0,void 0,!0)}if(!u.isPlaying){if("change-font-size"!==t||Z){if("resize"===t){const t=mt();lt&&i.height<t&&!Z&&r(()=>{var e;$(i)&&i.set({height:t}),null===(e=F.current)||void 0===e||e.height(t)},!1,!0),lt||i.height===t||Z||r(()=>{var e;$(i)&&i.set({height:t}),null===(e=F.current)||void 0===e||e.height(t)},!1,!0)}}else{const t=F.current,n=i.curveEnabled?i.fontSize:Q(t,i,e);if(n!==i.fontSize){return void r(()=>{i.set(S(i,n))},!1,!0)}const o=mt();i.height===o||lt||r(()=>{i.set({height:o})},!1,!0)}}}),o.useLayoutEffect(()=>{var t;if(pt&&i.curveEnabled){const e=null===(t=C.current)||void 0===t?void 0:t.getSelfRect().width;if(e){const t=e-i.a.width,r=i.a.rotation*Math.PI/180,n=-t/2*Math.cos(r),o=-t/2*Math.sin(r);i.set({width:e,x:i.a.x+n,y:i.a.y+o})}}},[pt,i.curveEnabled,i.curvePower,i.text,i.fontSize,i.fontFamily,i.fontWeight,i.fontStyle,i.letterSpacing]),o.useLayoutEffect(()=>{const t=F.current;t&&(t.width(t.width()+1e-8),t.width(t.width()-1e-8),t._setTextData(),ht())},[pt]);const xt=o.useRef(null),wt=o.useRef(i.width),vt=o.useRef(0),yt=t=>{t.evt.preventDefault();const e=u.selectedShapes.find(t=>t===i);e&&i.contentEditable&&(vt.current=function(t){var e;const r=t.target,n=function(t){var e=t.getAbsoluteTransform().copy();e.invert();var r=t.getStage().getPointerPosition();return e.point(r)}(r),o=r.textArr,i=Math.floor(n.y/(r.fontSize()*r.lineHeight())),a=o.slice(0,i).reduce((t,e)=>t+e.text.length,i),s=null!==(e=o[i])&&void 0!==e?e:o[0];let l=0;return"right"===r.align()?l=r.width()-s.width:"center"===r.align()&&(l=r.width()/2-s.width/2),a+Math.round((n.x-l)/s.width*s.text.length)}(t),i.toggleEditMode())},bt=J(i.placeholder),St=!gt&&bt?.6:n(i);W(F,St);const Et=getLineHeight({fontLoaded:pt,fontFamily:i.fontFamily,fontSize:i.a.fontSize,lineHeight:i.lineHeight}),zt=i.selectable||u.role===v.ADMIN,kt=x(i),Ot=x(i,i.stroke,"stroke"),Rt=o.useMemo(()=>i.backgroundEnabled?i.curveEnabled?function({width:t,height:e,padding:r=0,cornerRadius:n=0}){const o=-r,i=-r,a=t+r,s=e+r,l=h(`M ${o} ${i} L ${a} ${i} L ${a} ${s} L ${o} ${s} Z`);return g(l,n).path}({width:i.a.width,height:i.a.height,cornerRadius:i.backgroundCornerRadius*(i.a.fontSize*Et*.5),padding:i.backgroundPadding*(i.a.fontSize*Et*.5)}):function({lines:t,lineHeight:e,width:r,align:n="left",padding:o=0,cornerRadius:i=0}){const a=m({lines:t,lineHeight:e,width:r,align:n});return p({rects:a,padding:o,cornerRadius:i})}({lines:JSON.parse(JSON.stringify(dt)),cornerRadius:i.backgroundCornerRadius*(i.a.fontSize*Et*.5),lineHeight:Et*i.a.fontSize,padding:i.backgroundPadding*(i.a.fontSize*Et*.5),width:i.a.width,align:i.align}):"",[i.backgroundEnabled,i.curveEnabled,i.backgroundCornerRadius,i.a.fontSize,i.a.height,Et,i.backgroundPadding,i.a.width,i.align,dt]),Ft=D();let At=0;if(!i.curveEnabled){const t=dt.length*Et*i.a.fontSize,e=V(i.a,t);"middle"===i.verticalAlign?At=(e-t)/2:"bottom"===i.verticalAlign&&(At=e-t)}const jt=i.curveEnabled?L(i.a.width,i.a.height,i.curvePower,i.a.fontSize):"",Mt=pt?H(i.fontFamily):ut===i.fontFamily?"Arial":H(ut),Lt=M(gt);return r(e,{children:[t(s,{ref:P,x:i.a.x,y:i.a.y,rotation:i.a.rotation,hideInExport:!i.showInExport,listening:!1,visible:i.backgroundEnabled,opacity:i.backgroundOpacity*St,data:Rt,fill:i.backgroundColor,offsetY:-At}),t(s,{data:jt,stroke:f.stroke,strokeWidth:1,x:i.a.x,y:i.a.y,rotation:i.a.rotation,visible:!1}),t(c,Object.assign({ref:C,visible:i.curveEnabled,data:jt,text:gt||bt,listening:!1,align:"center",textBaseline:"middle",direction:Lt},kt,Ot,{strokeWidth:i.strokeWidth,lineJoin:T(i.strokeLineJoin),fillAfterStrokeEnabled:!0,fontSize:i.a.fontSize,fontFamily:`${H(i.fontFamily)}, ${H(ut)}`,fontStyle:i.fontStyle+" "+i.fontWeight,textDecoration:i.textDecoration.trim(),letterSpacing:i.letterSpacing*i.a.fontSize,x:i.a.x,y:i.a.y,rotation:i.a.rotation,opacity:i._editModeEnabled?.3:St,hideInExport:!i.showInExport,shadowEnabled:i.shadowEnabled,shadowBlur:i.shadowBlur,shadowOffsetX:i.shadowOffsetX,shadowOffsetY:i.shadowOffsetY,shadowColor:i.shadowColor,shadowOpacity:i.shadowOpacity})),t(l,Object.assign({ref:F,id:i.selectable?i.id:void 0,name:i.selectable?"element":"",hideInExport:!i.showInExport,editModeEnabled:i._editModeEnabled,x:i.a.x,y:i.a.y,rotation:i.a.rotation,width:i.a.width,height:_(i.a)?i.a.height:void 0,text:gt||bt,direction:Lt},kt,Ot,{lineJoin:T(i.strokeLineJoin),strokeWidth:i.strokeWidth,fillAfterStrokeEnabled:!0,fontSize:i.a.fontSize,fontFamily:Mt,fontStyle:i.fontStyle+" "+i.fontWeight,textDecoration:i.textDecoration,align:i.align,verticalAlign:i.verticalAlign,draggable:Ft?i.draggable&&at:i.draggable,preventDefault:!Ft||at,opacity:i.curveEnabled?0:St,visible:!i._editModeEnabled,ellipsis:"ellipsis"===A.textOverflow,shadowEnabled:i.shadowEnabled,shadowBlur:i.shadowBlur,shadowOffsetX:i.shadowOffsetX,shadowOffsetY:i.shadowOffsetY,shadowColor:i.shadowColor,shadowOpacity:i.shadowOpacity,lineHeight:Et,letterSpacing:i.letterSpacing*i.a.fontSize,listening:!!i.selectable&&zt,onDragStart:()=>{et(!0)},onDragMove:t=>{i.set({x:t.target.x(),y:t.target.y()})},onDragEnd:t=>{et(!1),i.set(O(t.target))},onClick:yt,onTap:yt,onTransformStart:()=>{G(!0);const t=F.current;rt.current=t.height(),wt.current=i.a.width,xt.current=t.position(),nt.current=t.rotation(),it.current=t.height(),ot.current=b(t)},onTransform:t=>{var e,r;const n=t.target;null===(e=P.current)||void 0===e||e.setAttrs({x:n.x(),y:n.y(),rotation:n.rotation(),scale:n.scale()});const o=ot.current;if("middle-left"===o||"middle-right"===o){const t=n.scaleX(),e=n.width()*t,r=R(wt.current,i.a.fontSize);let o=e;e<r&&(o=r,xt.current&&n.position(xt.current)),n.width(o),n.scaleX(1),n.scaleY(1);let a=mt();if("ellipsis"===A.textOverflow){a=rt.current}else{const t=Math.max(a,rt.current);n.height(t),i.set({height:n.height()})}const s=A.textVerticalResizeEnabled?Math.max(a,rt.current):mt();i.set({x:n.x(),width:n.width(),rotation:n.rotation(),height:s}),n.skewX(0),n.skewY(0),ht()}if("top-center"===o||"bottom-center"===o){const e="resize"===A.textOverflow?mt():Et*i.a.fontSize,r=t.target.height()*t.target.scaleY();if(r<e){if(t.target.height(e),xt.current){if("top-center"===ot.current){const r=nt.current*Math.PI/180,n=it.current-e;t.target.x(xt.current.x-n*Math.sin(r)),t.target.y(xt.current.y+n*Math.cos(r))}else{t.target.position(xt.current)}}}else{t.target.height(r)}t.target.scaleY(1),t.target.scaleX(1),t.target.rotation(nt.current),t.target.skewX(0),t.target.skewY(0),it.current=Math.max(e,r)}xt.current=t.target.position();const a=t.target.scaleX();null===(r=P.current)||void 0===r||r.setAttrs({scaleX:1,scaleY:1}),t.target.scaleX(1),t.target.scaleY(1),i.set({fontSize:i.a.fontSize*a,width:t.target.width()*a,x:t.target.x(),y:t.target.y(),rotation:t.target.rotation(),height:t.target.height()*a,shadowBlur:i.shadowBlur*a,shadowOffsetX:i.shadowOffsetX*a,shadowOffsetY:i.shadowOffsetY*a,strokeWidth:i.strokeWidth*a})},onTransformEnd:t=>{var e;const r=t.target.scaleX();t.target.scaleX(1),t.target.scaleY(1),i.set(Object.assign(Object.assign({},E(i,i.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=P.current)||void 0===e||e.setAttrs({scaleX:1,scaleY:1}),G(!1)}})),q&&i.contentEditable&&t(a,{x:i.a.x,y:i.a.y,rotation:i.a.rotation,children:t(K,{textNodeRef:F,element:i,selectAll:U,cursorPosition:vt.current,onBlur:()=>{i.set(z(i)),i.toggleEditMode(!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 u}from"react-konva";import{Html as d}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{useWorkspaceStyle as v}from"./workspace-style.js";import{ROLES as w}from"../model/store.js";import{incrementLoader as S}from"../utils/loader.js";import{activeAnchorOf as y,scaledFontSizeAttrs as E,roundedFontSizeAttrs as z,roundedTextDecorationAttrs as k,roundedGeometryPx as R,roundedPosition as F,textMinResizeWidth as O}from"../utils/px.js";import{isFontLoaded as j}from"../utils/fonts.js";import{flags as A}from"../utils/flags.js";import{removeTags as M}from"@polotno/core/text";import{getDir as L,getCurvePath as C,resolveLineHeight as T,normalizeStrokeLineJoin as H}from"@polotno/core/text-html";import{cssFontFamily as P}from"@polotno/core/fonts";import{shadowCastByBackground as W}from"@polotno/core/filters";import{applyOpacityToColor as X}from"@polotno/core/svg";import{FIT_FONT_SIZE_STEP as D,FIT_HEIGHT_EPSILON as Y}from"@polotno/core/fit-text";import{applyFilter as $}from"./apply-filters.js";import{useFadeIn as I}from"./use-fadein.js";import{isTouchDevice as J}from"../utils/screen.js";import{isAlive as N,getParent as B}from"mobx-state-tree";import{getLimitedFontSize as _}from"./text-element/max-font-size.js";import{getOptimalCaretColor as V}from"./text-element/caret-color.js";import{visiblePlaceholder as q}from"./text-element/placeholder.js";import{hasMeasuredHeight as U,resolveTextBoxHeight as Z}from"@polotno/core/text-types";let G;function K(){return G||(G=document.getElementById("polotno-text-style"),G||(G=document.createElement("style"),G.id="polotno-text-style",document.head.appendChild(G)),G)}h._fixTextRendering=!0;const Q={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 tt=a(({textNodeRef:e,element:r,onBlur:o,selectAll:i,cursorPosition:a})=>{const[l,s]=n.useState(Q),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=V(r);const e=`\n .polotno-input::placeholder {\n color: ${l.color};\n opacity: 0.6;\n }\n `,o=K();o.innerHTML="",o.appendChild(document.createTextNode(e)),JSON.stringify(t)!==JSON.stringify(l)&&s(t)});const u=n.useRef(null);if(n.useLayoutEffect(()=>{var t;const e=u.current;if(!e){return}null===(t=u.current)||void 0===t||t.focus({preventScroll:!0});const r=a||e.value.length;e.selectionStart=e.selectionEnd=r,i&&(null==e||e.select(),document.execCommand("selectAll",!1,void 0))},[]),n.useEffect(()=>{window.addEventListener("blur",o);const t=t=>{var e;(null===(e=u.current)||void 0===e?void 0:e.contains(t.target))||o()};return window.addEventListener("touchstart",t),()=>{window.removeEventListener("blur",o),window.removeEventListener("touchstart",t)}},[]),!c){return null}let d=0;const f=c.textArr.length*c.lineHeight()*c.fontSize(),h=Z(r.a,f);"middle"===r.verticalAlign&&(d=(h-f)/2),"bottom"===r.verticalAlign&&(d=h-f);const g=M(r.text);return t("textarea",{className:"polotno-input",ref:u,dir:L(g),style:Object.assign(Object.assign(Object.assign({},Q),l),{paddingTop:d+"px"}),value:g,onChange:t=>{const e=_({oldText:r.text,newText:t.target.value,element:r});r.set(Object.assign({text:t.target.value},E(r,e)))},placeholder:q(r.placeholder),onBlur:o})}),et=e=>t(d,{children:t(tt,Object.assign({},e))});export const useFontLoader=(t,e,r,o,i)=>{const[a,l]=n.useReducer(t=>t+1,0),s=n.useRef(j(e,r,o)),c=n.useRef(null);return n.useLayoutEffect(()=>{if(s.current=j(e,r,o),s.current){return}let n=!0;return(async()=>{s.current=!1,l();const a=S(`text ${e}`);await t.loadFont(e,r,o,i),n?(c.current=a,s.current=!0,l()):a()})(),()=>{c.current&&(c.current(),c.current=null),n=!1}},[e,r,o]),n.useEffect(()=>{s.current&&setTimeout(()=>{c.current&&(c.current(),c.current=null)})},[s.current]),[s.current]};export const useFontFamiliesLoader=(t,e,r,o,i)=>{const[a,l]=n.useReducer(t=>t+1,0),s=e.join("\0"),c=n.useRef(e.every(t=>j(t,r,o))),u=n.useRef(null);return n.useLayoutEffect(()=>{if(c.current=e.every(t=>j(t,r,o)),c.current){return}let n=!0;return(async()=>{c.current=!1,l();const a=S(`text fonts ${s}`);await Promise.all(e.map(e=>t.loadFont(e,r,o,i))),n?(u.current=a,c.current=!0,l()):a()})(),()=>{u.current&&(u.current(),u.current=null),n=!1}},[s,r,o]),n.useEffect(()=>{c.current&&setTimeout(()=>{u.current&&(u.current(),u.current=null)})},[c.current]),[c.current]};export const getLineHeight=({fontLoaded:t,fontFamily:e,fontSize:r,lineHeight:o})=>n.useMemo(()=>T({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 rt(t,e,r=!1){const o=t.fontSize(),n=t.height(),i=M(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=U(e.a)&&t.height()>e.a.height+Y;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-=D,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:d})=>{const{textOverflowIndicatorStyle:h}=v(),j=n.useRef(null),T=n.useRef(null),D=n.useRef(null),Y=n.useRef([]),_=n.useRef(!0),[,V]=n.useReducer(t=>t+1,0),{editorEnabled:G,selectAll:K}=(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),[Q,tt]=n.useState(!1),[ot,nt]=n.useState(!1),it=n.useRef(a.a.height),at=n.useRef(0),lt=n.useRef(""),st=n.useRef(0),ct=a.isSelected,ut=usePrevious(ct),{textVerticalResizeEnabled:dt}=A,ft=A.autoDeleteEmptyText,ht=usePrevious(a.fontFamily),[gt,mt]=n.useState([]);n.useEffect(()=>{var t,e;const r=null!==(e=null===(t=j.current)||void 0===t?void 0:t.textArr)&&void 0!==e?e:[];JSON.stringify(r)!==JSON.stringify(gt)&&mt(r)}),n.useEffect(()=>{if(a.a.width||"tablecell"===a.type){return}const t=j.current;t.width(600),a.set({width:1.4*t.getTextWidth()})},[]),n.useEffect(()=>{ut&&!ct&&ft&&""===a.text&&a.removable&&!q(a.placeholder)&&d.deleteElements([a.id])},[ft,a.placeholder,a.removable,a.text,ct,ut]);const pt=()=>{if(a.curveEnabled){const t=j.current;null==t||t.clearCache(),null==t||t.setAttrs({filters:[]});const e=T.current;e&&$(e,a)}else{const t=j.current;t&&$(t,a)}};n.useLayoutEffect(()=>{if(!ot){return f(a,()=>{pt()})}}),n.useEffect(()=>{const t=Y.current;t.length>0&&(Y.current=[],t.forEach(t=>t()))}),n.useEffect(()=>()=>{_.current=!1;const t=Y.current;t.length>0&&(Y.current=[],t.forEach(t=>t()))},[]);let xt=M(a.text);"uppercase"===a.textTransform&&(xt=xt.toUpperCase());const[bt]=useFontLoader(d,a.fontFamily,a.fontStyle,a.fontWeight,a.text||a.placeholder),vt=()=>{if(a.curveEnabled){const t=T.current;return t.getSelfRect().height||t.fontSize()}const t=j.current.clone({height:void 0}),e=Math.ceil(t.fontSize()*t.lineHeight()*t.textArr.length+1);return t.destroy(),e};n.useLayoutEffect(()=>{if(!bt){return}if("tablecell"===a.type){const{textOverflow:t}=A;if("resize"===t){const t=vt(),e=N(a)?B(a,2):null;(null==e?void 0:e.setCellContentHeight)&&e.setCellContentHeight(a.id,t)}else if("change-font-size"===t){const t=j.current;if(t){const e=rt(t,a,A.textSplitAllowed);e!==a.fontSize&&d.history.ignore(()=>{a.set({fontSize:e})})}}return}const{textOverflow:t,textSplitAllowed:e}=A,r=(t,e,r,o)=>{const n=S(`text ${a.id}`),i=()=>{d.history.ignore(t,e,r).then(()=>{_.current?(Y.current.push(n),V()):n()})};o?queueMicrotask(i):i()};if(!U(a)){const t=vt();return void r(()=>{U(a)||a.set({height:t})},void 0,void 0,!0)}if(!d.isPlaying){if("change-font-size"!==t||Q){if("resize"===t){const t=vt();dt&&a.height<t&&!Q&&r(()=>{var e;N(a)&&a.set({height:t}),null===(e=j.current)||void 0===e||e.height(t)},!1,!0),dt||a.height===t||Q||r(()=>{var e;N(a)&&a.set({height:t}),null===(e=j.current)||void 0===e||e.height(t)},!1,!0)}}else{const t=j.current,o=a.curveEnabled?a.fontSize:rt(t,a,e);if(o!==a.fontSize){return void r(()=>{a.set(E(a,o))},!1,!0)}const n=vt();a.height===n||dt||r(()=>{a.set({height:n})},!1,!0)}}}),n.useLayoutEffect(()=>{var t;if(bt&&a.curveEnabled){const e=null===(t=T.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})}}},[bt,a.curveEnabled,a.curvePower,a.text,a.fontSize,a.fontFamily,a.fontWeight,a.fontStyle,a.letterSpacing]),n.useLayoutEffect(()=>{const t=j.current;t&&(t.width(t.width()+1e-8),t.width(t.width()-1e-8),t._setTextData(),pt())},[bt]);const wt=n.useRef(null),St=n.useRef(a.width),yt=n.useRef(0),Et=t=>{t.evt.preventDefault();const e=d.selectedShapes.find(t=>t===a);e&&a.contentEditable&&(yt.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())},zt=q(a.placeholder),kt=!xt&&zt?.6:o(a);I(j,kt);const Rt=getLineHeight({fontLoaded:bt,fontFamily:a.fontFamily,fontSize:a.a.fontSize,lineHeight:a.lineHeight}),Ft=a.selectable||d.role===w.ADMIN,Ot=b(a),jt=b(a,a.stroke,"stroke"),At=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*Rt*.5),padding:a.backgroundPadding*(a.a.fontSize*Rt*.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(gt)),cornerRadius:a.backgroundCornerRadius*(a.a.fontSize*Rt*.5),lineHeight:Rt*a.a.fontSize,padding:a.backgroundPadding*(a.a.fontSize*Rt*.5),width:a.a.width,align:a.align}):"",[a.backgroundEnabled,a.borderSize,a.curveEnabled,a.backgroundCornerRadius,a.a.fontSize,a.a.height,Rt,a.backgroundPadding,a.a.width,a.align,gt]),Mt=J();let Lt=0;if(!a.curveEnabled){const t=gt.length*Rt*a.a.fontSize,e=Z(a.a,t);"middle"===a.verticalAlign?Lt=(e-t)/2:"bottom"===a.verticalAlign&&(Lt=e-t)}const Ct=a.curveEnabled?C(a.a.width,a.a.height,a.curvePower,a.a.fontSize):"",Tt=bt?P(a.fontFamily):ht===a.fontFamily?"Arial":P(ht),Ht=L(xt),Pt=a.shadowEnabled&&!W(a),Wt={shadowEnabled:a.shadowEnabled&&(W(a)||a.borderSize>0),shadowBlur:a.shadowBlur,shadowOffsetX:a.shadowOffsetX,shadowOffsetY:a.shadowOffsetY,shadowColor:i(a.shadowColor),shadowOpacity:a.shadowOpacity};return r(e,{children:[t(s,Object.assign({ref:D,x:a.a.x,y:a.a.y,rotation:a.a.rotation,hideInExport:!a.showInExport,listening:!1,visible:a.backgroundEnabled||a.borderSize>0,opacity:kt,data:At,fillEnabled:a.backgroundEnabled,fill:X(a.backgroundColor,a.backgroundOpacity),strokeEnabled:a.borderSize>0,stroke:i(a.borderColor),strokeWidth:a.borderSize,lineJoin:a.backgroundCornerRadius>0?"round":"miter",offsetY:-Lt},Wt)),t(s,{data:Ct,stroke:h.stroke,strokeWidth:1,x:a.a.x,y:a.a.y,rotation:a.a.rotation,visible:!1}),t(u,Object.assign({ref:T,visible:a.curveEnabled,data:Ct,text:xt||zt,listening:!1,align:"center",textBaseline:"middle",direction:Ht},Ot,jt,{strokeWidth:a.strokeWidth,lineJoin:H(a.strokeLineJoin),fillAfterStrokeEnabled:!0,fontSize:a.a.fontSize,fontFamily:`${P(a.fontFamily)}, ${P(ht)}`,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:kt,hideInExport:!a.showInExport},Wt,{shadowEnabled:Pt})),t(c,Object.assign({ref:j,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:U(a.a)?a.a.height:void 0,text:xt||zt,direction:Ht},Ot,jt,{lineJoin:H(a.strokeLineJoin),strokeWidth:a.strokeWidth,fillAfterStrokeEnabled:!0,fontSize:a.a.fontSize,fontFamily:Tt,fontStyle:a.fontStyle+" "+a.fontWeight,textDecoration:a.textDecoration,align:a.align,verticalAlign:a.verticalAlign,draggable:Mt?a.draggable&&ct:a.draggable,preventDefault:!Mt||ct,opacity:a.curveEnabled?0:kt,visible:!a._editModeEnabled,ellipsis:"ellipsis"===A.textOverflow},Wt,{shadowEnabled:Pt,lineHeight:Rt,letterSpacing:a.letterSpacing*a.a.fontSize,listening:!!a.selectable&&Ft,onDragStart:()=>{nt(!0)},onDragMove:t=>{a.set({x:t.target.x(),y:t.target.y()})},onDragEnd:t=>{nt(!1),a.set(F(t.target))},onClick:Et,onTap:Et,onTransformStart:()=>{tt(!0);const t=j.current;it.current=t.height(),St.current=a.a.width,wt.current=t.position(),at.current=t.rotation(),st.current=t.height(),lt.current=y(t)},onTransform:t=>{var e,r;const o=t.target;null===(e=D.current)||void 0===e||e.setAttrs({x:o.x(),y:o.y(),rotation:o.rotation(),scale:o.scale()});const n=lt.current;if("middle-left"===n||"middle-right"===n){const t=o.scaleX(),e=o.width()*t,r=O(St.current,a.a.fontSize);let n=e;e<r&&(n=r,wt.current&&o.position(wt.current)),o.width(n),o.scaleX(1),o.scaleY(1);let i=vt();if("ellipsis"===A.textOverflow){i=it.current}else{const t=Math.max(i,it.current);o.height(t),a.set({height:o.height()})}const l=A.textVerticalResizeEnabled?Math.max(i,it.current):vt();a.set({x:o.x(),width:o.width(),rotation:o.rotation(),height:l}),o.skewX(0),o.skewY(0),pt()}if("top-center"===n||"bottom-center"===n){const e="resize"===A.textOverflow?vt():Rt*a.a.fontSize,r=t.target.height()*t.target.scaleY();if(r<e){if(t.target.height(e),wt.current){if("top-center"===lt.current){const r=at.current*Math.PI/180,o=st.current-e;t.target.x(wt.current.x-o*Math.sin(r)),t.target.y(wt.current.y+o*Math.cos(r))}else{t.target.position(wt.current)}}}else{t.target.height(r)}t.target.scaleY(1),t.target.scaleX(1),t.target.rotation(at.current),t.target.skewX(0),t.target.skewY(0),st.current=Math.max(e,r)}wt.current=t.target.position();const i=t.target.scaleX();null===(r=D.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=t.target.scaleX();t.target.scaleX(1),t.target.scaleY(1),a.set(Object.assign(Object.assign({},z(a,a.fontSize*r)),{width:Math.ceil(t.target.width()*r),x:R(t.target.x()),y:R(t.target.y()),rotation:R(t.target.rotation()),height:R(t.target.height()*r)})),null===(e=D.current)||void 0===e||e.setAttrs({scaleX:1,scaleY:1}),tt(!1)}})),G&&a.contentEditable&&t(l,{x:a.a.x,y:a.a.y,rotation:a.a.rotation,children:t(et,{textNodeRef:j,element:a,selectAll:K,cursorPosition:yt.current,onBlur:()=>{a.set(k(a)),a.toggleEditMode(!1)}})})]})});