polotno 4.22.1 → 4.23.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 (72) hide show
  1. package/THIRD_PARTY_NOTICES.md +7 -7
  2. package/blueprint/toolbar/color-picker.js +2 -2
  3. package/canvas/element.js +1 -1
  4. package/canvas/fade-overlay.d.ts +5 -0
  5. package/canvas/fade-overlay.js +1 -1
  6. package/canvas/html-element.js +1 -1
  7. package/canvas/image-element.js +1 -1
  8. package/canvas/line-element.js +1 -1
  9. package/canvas/page.js +1 -1
  10. package/canvas/quill-font-formats.d.ts +1 -0
  11. package/canvas/quill-font-formats.js +1 -1
  12. package/canvas/radial-gradient-handle.d.ts +14 -0
  13. package/canvas/radial-gradient-handle.js +1 -0
  14. package/canvas/render-tag-element.js +1 -1
  15. package/canvas/rich-editor.js +12 -6
  16. package/canvas/text-element/legacy-padding-warning.d.ts +6 -0
  17. package/canvas/text-element/legacy-padding-warning.js +1 -0
  18. package/canvas/text-element/max-font-size.js +1 -1
  19. package/canvas/text-element.js +1 -1
  20. package/canvas/use-color.d.ts +24 -2
  21. package/canvas/use-color.js +1 -1
  22. package/icons/registry.d.ts +1 -0
  23. package/icons/registry.js +1 -1
  24. package/model/group-model.d.ts +26 -10
  25. package/model/group-model.js +1 -1
  26. package/model/node-model.d.ts +10 -1
  27. package/model/node-model.js +1 -1
  28. package/model/page-model.d.ts +75 -33
  29. package/model/page-model.js +1 -1
  30. package/model/table-model.d.ts +29 -9
  31. package/model/table-model.js +1 -1
  32. package/model/text-model.d.ts +5 -1
  33. package/model/text-model.js +1 -1
  34. package/package.json +16 -16
  35. package/polotno.bundle.js +194 -202
  36. package/primitives/field-group.js +1 -1
  37. package/primitives/popover.d.ts +1 -1
  38. package/primitives/popover.js +1 -1
  39. package/side-panel/effects-panel.js +1 -1
  40. package/side-panel/templates-panel.js +1 -1
  41. package/toolbar/color-picker.js +1 -1
  42. package/toolbar/gradient-center-pad.d.ts +11 -0
  43. package/toolbar/gradient-center-pad.js +1 -0
  44. package/toolbar/padding-control.d.ts +29 -0
  45. package/toolbar/padding-control.js +1 -0
  46. package/toolbar/selection-colors.js +1 -1
  47. package/toolbar/stop-track.js +1 -1
  48. package/toolbar/table-toolbar.js +1 -1
  49. package/toolbar/text-toolbar.d.ts +7 -2
  50. package/toolbar/text-toolbar.js +1 -1
  51. package/toolbar/unit-numeric-input.d.ts +5 -0
  52. package/toolbar/unit-numeric-input.js +1 -0
  53. package/toolbar/use-copy-style.js +1 -1
  54. package/ui.css +1 -1
  55. package/utils/clipboard.d.ts +10 -2
  56. package/utils/clipboard.js +1 -1
  57. package/utils/gradient-handle.d.ts +18 -0
  58. package/utils/gradient-handle.js +1 -0
  59. package/utils/gradient-stops.d.ts +7 -2
  60. package/utils/gradient-stops.js +1 -1
  61. package/utils/history-gesture.d.ts +7 -0
  62. package/utils/history-gesture.js +1 -0
  63. package/utils/l10n.d.ts +16 -1
  64. package/utils/l10n.js +1 -1
  65. package/utils/measure-text.d.ts +4 -0
  66. package/utils/measure-text.js +1 -1
  67. package/utils/px.d.ts +4 -0
  68. package/utils/px.js +1 -1
  69. package/utils/rich-text-html.d.ts +1 -0
  70. package/utils/rich-text-html.js +1 -1
  71. package/utils/selection-transform.js +1 -1
  72. package/utils/validate-key.js +1 -1
@@ -0,0 +1,14 @@
1
+ import React from 'react';
2
+ import { type StoreType } from '../model/store.js';
3
+ export declare const RadialGradientHandle: (({ store, pageId }: {
4
+ store: StoreType;
5
+ pageId: string;
6
+ }) => React.JSX.Element | null) & React.NamedExoticComponent<{
7
+ store: StoreType;
8
+ pageId: string;
9
+ }> & {
10
+ readonly type: ({ store, pageId }: {
11
+ store: StoreType;
12
+ pageId: string;
13
+ }) => React.JSX.Element | null;
14
+ };
@@ -0,0 +1 @@
1
+ import{jsx as t}from"react/jsx-runtime";import{observer as e}from"mobx-react-lite";import{Circle as o,Group as r}from"react-konva";import{isAlive as n}from"mobx-state-tree";import{ROLES as i}from"../model/store.js";import{beginRadialHandlePress as a,getRadialHandle as l}from"../utils/gradient-handle.js";import{readGradient as s,writeGradient as d}from"../utils/gradient-stops.js";import{isRadialGradient as c}from"@polotno/core/gradient";import{backgroundPaintBox as g}from"@polotno/core/page";import{safe01 as m}from"../utils/stops.js";import{useHistoryGesture as u}from"../utils/history-gesture.js";import{useWorkspaceStyle as p}from"./workspace-style.js";import{t as f}from"../utils/l10n.js";function h(t){var e;const o=null===(e=t.getStage())||void 0===e?void 0:e.container();o&&(o.style.cursor="",o.title="")}export const RadialGradientHandle=e(({store:e,pageId:y})=>{var b,v,x;const j=l(e),{transformerStyle:w}=p(),S=u(e);if(!j||!n(j.node)||e.role===i.VIEWER||e.isPlaying){return null}const k=e.selectedElements,B=e.activePage;let D,E;if(1===k.length&&k[0]===j.node){const t=j.node,{x:e,y:o,rotation:r,width:n,height:i}=t.a;if((null===(b=t.page)||void 0===b?void 0:b.id)!==y||"group"===(null===(v=t.parent)||void 0===v?void 0:v.type)||!t.visible||!(n>0&&i>0)){return null}const a=j.border?(t.borderSize||0)/2:0;E={x:a,y:a,width:n,height:i},D={x:e,y:o,rotation:r}}else{if(0!==k.length||!B||B!==j.node||B.id!==y){return null}E=g(B.computedBleed,B.computedWidth,B.computedHeight),D={x:0,y:0,rotation:0}}const P=j.read();if(!P||!c(P)){return null}const{center:W}=s(P),M=e.scale||1,O=t=>({x:E.x+t.x*E.width,y:E.y+t.y*E.height}),C=t=>({x:m((t.x()-E.x)/E.width),y:m((t.y()-E.y)/E.height)}),H=t=>{const o=l(e),r=null==o?void 0:o.read();o&&r&&o.onChange(d(Object.assign(Object.assign({},s(r)),{type:"radial",center:t})))};return t(r,{x:D.x,y:D.y,rotation:D.rotation,children:t(o,Object.assign({name:"radial-gradient-handle"},O(W),{radius:6/M,fill:"#ffffff",stroke:String(null!==(x=w.anchorStroke)&&void 0!==x?x:"#0d83cd"),strokeWidth:2/M,hitStrokeWidth:12/M,shadowColor:"rgba(0,0,0,0.4)",shadowBlur:2/M,draggable:!0,dragDistance:0,onPointerDown:a,onMouseEnter:t=>{const e=t.target.getStage().container();e.style.cursor="move",e.title=f("toolbar.colorPicker.center")},onMouseLeave:t=>{S.active()||h(t.target)},onDragStart:t=>{t.cancelBubble=!0,S.begin()},onDragMove:t=>{t.cancelBubble=!0;const e=C(t.target);t.target.position(O(e)),H(e)},onDragEnd:t=>{t.cancelBubble=!0,H(C(t.target)),S.end(),h(t.target)}}))})});
@@ -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 i=0;for(r=Object.getOwnPropertySymbols(t);i<r.length;i++){e.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(t,r[i])&&(o[r[i]]=t[r[i]])}}return o};import{Fragment as e,jsx as o,jsxs as r}from"react/jsx-runtime";import{elementOpacity as i}from"./paint-opacity.js";import n from"react";import{observer as s}from"mobx-react-lite";import{Group as a,Path as l,Rect as c,Shape as d}from"react-konva";import{nodeAutorun as u}from"../utils/mobx.js";import{isAlive as h}from"mobx-state-tree";import{Html as f}from"react-konva-utils";import{drawLayout as g}from"render-tag";import{drawTextOnPathLayout as m}from"render-tag/path";import{activeAnchorOf as b,isCornerAnchor as p,isRotateAnchor as x,scaledFontSizeAttrs as v,scaledFontSizeBounds as y,roundedFontSizeAttrs as w,roundedTextDecorationAttrs as j,scaledStyleAttrs as O,roundedGeometryPx as z,roundedPosition as E,textMinResizeWidth as S,transformScale as M}from"../utils/px.js";import{flags as k}from"../utils/flags.js";import{editorTextSizing as R,textOverflowOf as Y,textResizeFloorFontSize as C}from"../utils/text-sizing.js";import{curvedBoxWidth as X,layoutAsSized as P,layoutCurvedTextSizing as F,layoutTextSizing as I,renderTagLayoutAt as T}from"@polotno/core/text-sizing";import{curveLayoutAt as B}from"@polotno/core/curve-glyphs";import{applyFilter as A}from"./apply-filters.js";import{getLineHeight as H}from"./text-element.js";import{liveFitScale as $,useRenderTagSource as D}from"./text-element/render-tag-source.js";import{getHtml as L,getCurveTextHeight as _,letterSpacingOverhang as J}from"@polotno/core/text-html";import{withDisplayTextPaints as N}from"./use-color.js";import{toDisplayColor as U}from"@polotno/core/color";import{animatedShadow as V}from"./animated-shadow.js";import{detectSize as q}from"@polotno/core/measure-html";import{generateBackgroundShapeFromRects as W,trimTrailingLetterSpace as G}from"@polotno/core/background-shape";import{useFadeIn as K}from"./use-fadein.js";import{incrementLoader as Q}from"../utils/loader.js";import{removeTags as Z}from"@polotno/core/text";import{shadowCastByBackground as tt}from"@polotno/core/filters";import{applyOpacityToColor as et}from"@polotno/core/svg";import{isTouchDevice as ot}from"../utils/screen.js";import{getLimitedFontSize as rt}from"./text-element/max-font-size.js";import{scaleRichTextFontSizesInHtml as it}from"../utils/rich-text-html.js";import{RichEditor as nt}from"./rich-editor.js";import{PlacedNode as st}from"./placed-node.js";import{AutoDeleteEmptyText as at}from"./text-element/auto-delete-empty-text.js";import{wrapHtmlForRenderTag as lt}from"@polotno/core/reset-style";import{hasMeasuredHeight as ct,resolveTextBoxHeight as dt}from"@polotno/core/text-types";import{TEXT_PRESETS as ut,WIPE_DIRECTION as ht}from"@polotno/core/animation-presets";import{textUnitState as ft}from"../utils/animations.js";export{lt as wrapHtmlForRenderTag};function gt(t,e){return t!==e&&(!k.textVerticalResizeEnabled||t<e)}const mt=({opacity:t,y:e,scale:o,blur:r,from:i,to:n,shift:s})=>t>=1&&!e&&1===o&&!r&&i<=0&&n>=1&&!s;export const RenderTagElement=s(({element:s,store:lt})=>{var bt,pt,xt,vt,yt,wt,jt,Ot,zt,Et,St;const Mt=n.useRef(null),kt=n.useRef(null),[Rt,Yt]=n.useState(!1),Ct=n.useRef(s.height),Xt=n.useRef(null),Pt=ot(),{textVerticalResizeEnabled:Ft}=k,{fontLoaded:It,fontFamily:Tt,color:Bt,isPlaceholder:At,normalizedSourceText:Ht,getHtmlOptions:$t}=D(s,lt),Dt=s._editModeEnabled;K(Mt);const Lt=At?.6:i(s),_t=L(N(s),$t),Jt=s.width||1,Nt=(t,e)=>T(N(t),{getHtmlOptions:$t,textUnits:e}),Ut=Y(s),Vt=R(s),qt=s.curveEnabled,Wt=JSON.stringify(Vt),Gt="fixed"===Vt.box?s.height:0,Kt=Rt?Xt.current:null,Qt=n.useMemo(()=>{if(Kt){return Kt.sized}const t=s.filled.text,e=At?Object.assign(Object.assign({},s),{text:Ht}):void 0!==t&&t!==s.text?Object.assign(Object.assign({},s),{text:t}):s;try{return qt?Object.assign({curved:!0},F({element:e,sizing:Vt,layoutAt:B(N(s),{getHtmlOptions:{fontFamily:Tt,color:Bt,text:Ht,textIsNormalized:!0}})})):Object.assign({curved:!1},I({element:e,sizing:Vt,layoutAt:Nt(s)}))}catch(o){return console.error("render-tag layout failed:",o),null}},[_t,Jt,It,qt,Wt,Gt,s.curvePower,s.fontSize,s.width,Kt]),Zt=null!==(bt=null==Kt?void 0:Kt.width)&&void 0!==bt?bt:Jt,te=Kt?s.width/Kt.width:1,ee=!1===(null==Qt?void 0:Qt.curved)?Qt.layout:null,oe=(null==Qt?void 0:Qt.curved)?Qt.layout:null,re=s.a.text,ie=s.a.textUnits,ne=ie?ut[ie.animation.name].unit:void 0,se=n.useMemo(()=>{var t;const e="string"==typeof re&&re!==(null!==(t=s.filled.text)&&void 0!==t?t:s.text);if(!1!==(null==Qt?void 0:Qt.curved)||At||!e&&!ne){return ee}try{return P({element:e?Object.assign(Object.assign({},s),{text:re}):s,sized:Qt,sizing:Vt,layoutAt:Nt(s,ne)})}catch(o){return console.error("render-tag layout failed:",o),ee}},[ee,re,ne]),ae=ie&&(null==se?void 0:se.textUnits),le=n.useMemo(()=>{if(!ie||!ae){return null}const t=ae.map((t,e)=>ft(ie,e,ae.length)),e=e=>!t[e]||mt(t[e]);return t.map((t,o)=>({state:t,slice:mt(t)&&e(o-1)&&e(o+1)}))},[ie,ae]),ce=null!==(pt=null==Qt?void 0:Qt.fontSize)&&void 0!==pt?pt:s.fontSize,de=null!==(xt=null==Qt?void 0:Qt.scale)&&void 0!==xt?xt:1,ue=J(s.letterSpacing,ce),he=null!==(vt=null==Kt?void 0:Kt.overhang)&&void 0!==vt?vt:ue,fe=H({fontLoaded:It,fontFamily:s.fontFamily,fontSize:ce,lineHeight:s.lineHeight}),ge=qt?0:Math.max(null!==(yt=null==ee?void 0:ee.height)&&void 0!==yt?yt:0,ce*fe),me=oe?oe.bounds:null,be=me?(s.width-me.width)/2-me.x:0,pe=n.useMemo(()=>{var t;if(oe&&me){const t=oe.paintBounds;return Object.assign(Object.assign({},t),{x:t.x+be,y:t.y-me.y})}const e=null!==(t=null==se?void 0:se.paintBounds)&&void 0!==t?t:null;return e&&ae?{x:e.x-ce,y:e.y-ce,width:e.width+2*ce,height:e.height+2*ce}:e},[se,oe,me,be,ae,ce]),xe=n.useMemo(()=>se?se.lines.map(t=>G({left:t.bounds.x,right:t.bounds.x+t.bounds.width,top:t.bounds.y,bottom:t.bounds.y+t.bounds.height},he)):[],[se,he]),ve=n.useRef([]),ye=n.useRef(null),we=n.useRef(!0),[,je]=n.useReducer(t=>t+1,0);n.useEffect(()=>{const t=ve.current;t.length>0&&(ve.current=[],t.forEach(t=>t()))});const Oe=n.useCallback((t,e,o,r)=>{const i=Q(`text ${s.id}`),n=()=>{lt.history.ignore(t,e,o).then(()=>{we.current?(ve.current.push(i),je()):i()})};r?queueMicrotask(n):n()},[s.id,lt]),ze=n.useCallback(t=>{const e=null!==ye.current;ye.current=t,e||Oe(()=>{const t=ye.current;ye.current=null,h(s)&&gt(s.height,t)&&s.set({height:t})},!1,!0)},[s,Oe]),Ee=n.useRef(Qt);Ee.current=Qt,n.useEffect(()=>{if(!It){return}if(!ee){return}if(!ct(s)){return void Oe(()=>{h(s)&&(ct(s)||s.set({height:ge}))},void 0,void 0,!0)}if(lt.isPlaying){return}const t=gt(s.height,ge),e=()=>ze(ge);if(void 0===s.filled.text||"change-font-size"!==Ut){if("change-font-size"!==Ut||Rt||Dt||s.curveEnabled){"resize"===Ut&&t&&!Rt&&e()}else if(Qt&&Qt.fontSize!==s.fontSize){const{fontSize:t,text:e}=Qt;Oe(()=>{if(!h(s)){return}if(Ee.current!==Qt||"change-font-size"!==Y(s)||s._editModeEnabled){return}const o=v(s,t);At||e===s.text||(o.text=e),s.set(o)},!1,!0)}else{t&&e()}}}),n.useEffect(()=>()=>{we.current=!1;const t=ve.current;t.length>0&&(ve.current=[],t.forEach(t=>t()))},[]),n.useLayoutEffect(()=>{if(!It||!s.curveEnabled||Rt){return}if(!me||!me.width){return}const t=t=>t&&Ft?Math.max(t,me.height):me.height,e=t=>X(Vt,{width:t},me.width);Math.abs(e(s.width)-s.width)<1&&Math.abs(t(s.height)-s.height)<1||Oe(()=>{if(!h(s)){return}const o=e(s.width),r=o-s.width,i=t(s.height),n=i-s.height;if(Math.abs(r)<1&&Math.abs(n)<1){return}const a=s.a.rotation*Math.PI/180,l=-r/2*Math.cos(a),c=-r/2*Math.sin(a);s.set({width:o,height:i,x:s.a.x+l,y:s.a.y+c})},!1,!0,!0)},[It,s.curveEnabled,Ut,me,Rt,Ft,Oe]),n.useEffect(()=>u(s,()=>{const t=Mt.current;t&&A(t,s)}),[se,oe,s.a.width,s.a.height,ie,s.a.shadowColor,s.a.shadowOffsetX,s.a.shadowOffsetY,s.a.shadowOpacity]);const Se=dt(s,ge),Me=qt||!It||Rt||lt.isPlaying||"resize"!==Ut?s.a.height:Ft?Math.max(s.a.height,ge):ge;let ke=0;qt||"middle"!==s.verticalAlign?qt||"bottom"!==s.verticalAlign||(ke=Se-ge*te):ke=(Se-ge*te)/2;const Re=null!==(wt=null==Kt?void 0:Kt.backgroundPadding)&&void 0!==wt?wt:s.backgroundPadding*(ce*fe*.5),Ye=null!==(jt=null==Kt?void 0:Kt.backgroundCornerRadius)&&void 0!==jt?jt:s.backgroundCornerRadius*(ce*fe*.5),Ce=s.backgroundEnabled||s.borderSize>0,Xe=n.useMemo(()=>!Ce||s.curveEnabled||s.legacyBackground||0===xe.length?"":W({rects:xe,padding:Re,cornerRadius:Ye}),[Ce,s.curveEnabled,s.legacyBackground,xe,Re,Ye]),Pe=n.useRef(null),Fe=n.useRef(s.width),Ie=n.useRef(null),Te=n.useRef(null),Be=n.useRef(""),Ae=n.useRef(0),He=n.useRef(0),$e=n.useRef({fontSize:s.fontSize}),De=s.width>0?s.a.width/s.width:1,Le=De*te,_e=V(s),Je=null!==(Ot=null==Kt?void 0:Kt.shadow)&&void 0!==Ot?Ot:{shadowBlur:_e.shadowBlur*de,shadowOffsetX:_e.shadowOffsetX*de,shadowOffsetY:_e.shadowOffsetY*de},Ne=Object.assign(Object.assign({},Je),{shadowColor:_e.shadowColor,shadowOpacity:_e.shadowOpacity}),Ue=Object.assign(Object.assign({},Ne),{shadowEnabled:_e.shadowEnabled&&Ce});return r(e,{children:[o(at,{element:s,store:lt}),Ce?s.curveEnabled||s.legacyBackground?o(st,Object.assign({as:c,element:s,offsetX:Re/De,offsetY:Re/De,scaleX:Le,scaleY:Le,hideInExport:!s.showInExport,listening:!1,opacity:Lt,fillEnabled:s.backgroundEnabled,fill:et(s.backgroundColor,s.backgroundOpacity),strokeEnabled:s.borderSize>0,stroke:U(s.borderColor),strokeWidth:null!==(zt=null==Kt?void 0:Kt.borderSize)&&void 0!==zt?zt:s.borderSize},Ue,{width:Zt+2*Re,height:(null!==(Et=null==Kt?void 0:Kt.boxHeight)&&void 0!==Et?Et:Se)+2*Re,cornerRadius:Ye})):o(st,Object.assign({as:l,element:s,name:"rendertag-background",offsetY:-ke/Le,scaleX:Le,scaleY:Le,hideInExport:!s.showInExport,listening:!1,visible:Xe.length>0,opacity:Lt,fillEnabled:s.backgroundEnabled,fill:et(s.backgroundColor,s.backgroundOpacity),strokeEnabled:s.borderSize>0,stroke:U(s.borderColor),strokeWidth:null!==(St=null==Kt?void 0:Kt.borderSize)&&void 0!==St?St:s.borderSize,lineJoin:Ye>0?"round":"miter"},Ue,{data:Xe})):null,o(st,Object.assign({as:d,nodeRef:Mt,element:s,selfRectFunc:pe?()=>pe:void 0,name:"rendertag-text",scaleX:Le,scaleY:Le,offsetY:Le>0?-ke/Le:0,width:Zt,height:Math.max(s.height,ge),listening:!1,visible:!Dt&&!!(qt?oe:ee),editModeEnabled:Dt,opacity:Lt,shadowEnabled:_e.shadowEnabled&&!tt(s)},Ne,{hideInExport:!s.showInExport,sceneFunc:(t,e)=>{const o=t._context;if(o){try{if(qt){if(!oe||!me){return}o.save(),o.translate(be,-me.y),m({layout:oe,ctx:o}),o.restore()}else{if(!se){return}g({layout:se,width:Zt,ctx:o,pixelRatio:1,paintTextUnit:le?t=>{const{state:e,slice:o}=le[t.unit.index];(({unit:t,ctx:e,draw:o},{opacity:r,y:i,scale:n,blur:s,from:a,to:l,direction:c,shift:d},u,h)=>{if(!(r<=0||n<=0||l<=a)){if(a>0||l<1||d){const{vertical:o,low:r,high:i,forward:n}=((t,e,o)=>{var r;const i=e?ht[e]:void 0,n="y"===(null==i?void 0:i.axis);let s=n?t.y:t.x,a=s+(n?t.height:t.width);if(n||o){for(const l of t.fragments){s=Math.min(s,n?l.paintTop:l.paintLeft),a=Math.max(a,n?l.paintBottom:l.paintRight)}}return{vertical:n,low:s,high:a,forward:i?i.forward:"rtl"!==(null===(r=t.fragments[0])||void 0===r?void 0:r.direction)}})(t,c,0!==d),s=i-r,[h,f]=n?[a,l]:[1-l,1-a],g=h<=0&&!d?r-u:r+h*s,m=f>=1&&!d?i+u:r+f*s;e.beginPath(),o?e.rect(t.x-u,g,t.width+2*u,m-g):e.rect(g,t.y-u,m-g,t.height+2*u),e.clip();const b=d*s*(n?1:-1);o?e.translate(0,b):e.translate(b,0)}if(e.globalAlpha*=r,i&&e.translate(0,i*u),1!==n){const o=t.x+t.width/2,r=t.y+t.height/2;e.translate(o,r),e.scale(n,n),e.translate(-o,-r)}if(s>0){const t=e.getTransform(),o=Math.sqrt(Math.abs(t.a*t.d-t.b*t.c));e.filter=`blur(${s*u*o}px)`}o({slice:h})}})(t,e,ce,o)}:void 0})}}catch(r){console.error("render-tag draw failed:",r)}}}})),o(st,{as:c,nodeRef:kt,element:s,name:"element",listening:s.selectable,width:s.a.width,height:Me,visible:!Dt,draggable:Pt?s.draggable&&s.isSelected:s.draggable,preventDefault:!Pt||s.isSelected,opacity:0,hideInExport:!0,id:s.id,onDragMove:t=>{s.set({x:t.target.x(),y:t.target.y()})},onDragEnd:t=>{s.set(E(t.target))},onDblClick:t=>{s.contentEditable&&(Te.current={x:t.evt.clientX,y:t.evt.clientY},s.toggleEditMode(!0))},onDblTap:t=>{var e;if(s.contentEditable){const o=null===(e=t.evt.changedTouches)||void 0===e?void 0:e[0];Te.current=o?{x:o.clientX,y:o.clientY}:null,s.toggleEditMode(!0)}},onTransformStart:t=>{Ct.current=s.height,Fe.current=s.width,Ie.current=null,Pe.current=t.target.position(),Be.current=b(t.target),Ae.current=s.a.rotation,He.current=s.height,$e.current={fontSize:s.fontSize,minFontSize:s.minFontSize,maxFontSize:s.maxFontSize},Xt.current=!s.curveEnabled&&["top-left","top-right","bottom-left","bottom-right"].includes(Be.current)?{sized:Qt,width:Jt,boxHeight:Se,backgroundPadding:Re,backgroundCornerRadius:Ye,borderSize:s.borderSize,overhang:ue,shadow:Je}:null,Yt(!0)},onTransform:e=>{const o=e.target,r=Be.current,i="middle-left"===r||"middle-right"===r,n="top-center"===r||"bottom-center"===r,a=M(o.scaleX());if(i){const e=o.width()*a;let r=Math.max(e,S(Fe.current,C(s)));const i=s.toJSON();let n=0;if("fit"===Ut){n=Ct.current}else if(s.curveEnabled){n=_(Object.assign(Object.assign({},i),{width:r}))}else{const{x:e,y:o,width:s,height:a}=i,l=t(i,["x","y","width","height"]),c=`${JSON.stringify(l)}|${Tt}|${It}|${Bt}`;if(Ie.current&&Ie.current.signature===c&&r<=Ie.current.width){r=Ie.current.width,n=Ie.current.height}else{const t=t=>{const e=Object.assign(Object.assign({},i),{width:t});try{return I({element:Object.assign(Object.assign({},e),{text:Ht}),sizing:Object.assign(Object.assign({},Vt),{fit:{mode:"off"},cutAtBox:!1}),layoutAt:Nt(e)}).layout}catch(bt){const o=L(e,$t);return{height:q(o).height,lines:[]}}};let e=t(r);const o=Math.max(0,...e.lines.map(t=>t.bounds.x+t.bounds.width-ue));o>r+.5&&o<=Fe.current+.5&&(r=Math.min(Math.ceil(o),Fe.current),e=t(r),Ie.current={signature:c,width:r,height:e.height}),n=e.height}}r>e&&Pe.current&&o.position(Pe.current),o.width(r),o.scaleX(1),o.scaleY(1);let l=k.textVerticalResizeEnabled?Math.max(n,Ct.current):n;"ellipsis"!==Ut&&"fit"!==Ut||(l=Ct.current),o.height(l),s.set({width:o.width(),height:l,x:o.x(),y:o.y()})}else if(n){const t="resize"===Ut?qt?(null==me?void 0:me.height)||s.fontSize:ge:fe*("fit"===Vt.fit.mode?Vt.fit.min:s.fontSize),e=o.height()*o.scaleY();if(e<t){if(o.height(t),Pe.current){if("top-center"===Be.current){const e=Ae.current*Math.PI/180,r=He.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),He.current=Math.max(t,e),s.set({x:o.x(),y:o.y(),height:o.height(),rotation:o.rotation()})}else{o.scaleX(1),o.scaleY(1);const t=s.fontSize*a;s.set(Object.assign(Object.assign(Object.assign({},y($e.current,t/$e.current.fontSize)),{letterSpacing:s.letterSpacing,width:o.width()*a,x:o.x(),y:o.y(),rotation:o.rotation(),height:o.height()*a}),O(s,a)))}Pe.current=e.target.position()},onTransformEnd:t=>{Xt.current=null,Yt(!1);const e=t.target.scaleX();t.target.scaleX(1),t.target.scaleY(1);const o=w(s,s.fontSize*e),r=$e.current,i=Be.current;s.set(Object.assign(Object.assign(Object.assign({},o),p(i)&&!x(i)?y(r,o.fontSize/r.fontSize,!0):{}),{width:z(t.target.width()*e),x:z(t.target.x()),y:z(t.target.y()),rotation:z(t.target.rotation()),text:it(s.text,e)}))}}),Dt&&o(st,{as:a,element:s,offsetY:-ke,children:o(f,{divProps:{style:{zIndex:20}},children:o(nt,{element:s,fitScale:de,fitScaleFor:t=>qt?de:$(s,Vt,$t,t,de),onChange:t=>{if("fit"===Ut){return void s.set({text:t})}const e=rt({oldText:Z(s.text),newText:Z(t),element:s});s.set(Object.assign({text:t},v(s,e)))},onBlur:()=>{h(s)&&(s.set(j(s)),s.toggleEditMode(!1))},clickCoords:Te.current})})})]})});
1
+ var t=this&&this.__rest||function(t,e){var o={};for(var i in t){Object.prototype.hasOwnProperty.call(t,i)&&e.indexOf(i)<0&&(o[i]=t[i])}if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(t);r<i.length;r++){e.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(t,i[r])&&(o[i[r]]=t[i[r]])}}return o};import{Fragment as e,jsx as o,jsxs as i}from"react/jsx-runtime";import{elementOpacity as r}from"./paint-opacity.js";import n from"react";import{observer as s}from"mobx-react-lite";import{Group as a,Path as l,Rect as c,Shape as d}from"react-konva";import{nodeAutorun as u}from"../utils/mobx.js";import{isAlive as h}from"mobx-state-tree";import{Html as f}from"react-konva-utils";import{drawLayout as g}from"render-tag";import{drawTextOnPathLayout as m}from"render-tag/path";import{activeAnchorOf as p,isCornerAnchor as b,isRotateAnchor as x,scaledFontSizeAttrs as v,scaledFontSizeBounds as w,roundedFontSizeAttrs as y,roundedTextDecorationAttrs as j,scaledStyleAttrs as O,roundedGeometryPx as z,roundedPosition as E,paddedTextMinResizeWidth as S,roundedTextPaddingAttrs as M,transformScale as R}from"../utils/px.js";import{flags as k}from"../utils/flags.js";import{editorTextSizing as X,textOverflowOf as Y,textResizeFloorFontSize as C}from"../utils/text-sizing.js";import{curvedBoxWidth as P,layoutAsSized as T,layoutCurvedTextSizing as F,layoutTextSizing as I,renderTagLayoutAt as A}from"@polotno/core/text-sizing";import{curveLayoutAt as B}from"@polotno/core/curve-glyphs";import{applyFilter as H}from"./apply-filters.js";import{getLineHeight as L}from"./text-element.js";import{liveFitScale as $,useRenderTagSource as D}from"./text-element/render-tag-source.js";import{getHtml as _,getCurveTextHeight as J,letterSpacingOverhang as N}from"@polotno/core/text-html";import{withDisplayTextPaints as U}from"./use-color.js";import{toDisplayColor as V}from"@polotno/core/color";import{animatedShadow as q}from"./animated-shadow.js";import{detectSize as W}from"@polotno/core/measure-html";import{generateBackgroundShapeFromRects as G,trimTrailingLetterSpace as K}from"@polotno/core/background-shape";import{useFadeIn as Q}from"./use-fadein.js";import{incrementLoader as Z}from"../utils/loader.js";import{removeTags as tt}from"@polotno/core/text";import{shadowCastByBackground as et}from"@polotno/core/filters";import{applyOpacityToColor as ot}from"@polotno/core/svg";import{isTouchDevice as it}from"../utils/screen.js";import{getLimitedFontSize as rt}from"./text-element/max-font-size.js";import{scaleRichTextFontSizesInHtml as nt}from"../utils/rich-text-html.js";import{RichEditor as st}from"./rich-editor.js";import{PlacedNode as at}from"./placed-node.js";import{AutoDeleteEmptyText as lt}from"./text-element/auto-delete-empty-text.js";import{wrapHtmlForRenderTag as ct}from"@polotno/core/reset-style";import{hasMeasuredHeight as dt,resolveTextBoxHeight as ut,textBackgroundRadius as ht,textBackgroundSpread as ft,textContentElement as gt,textOuterHeight as mt,textPadding as pt}from"@polotno/core/text-types";import{TEXT_PRESETS as bt,WIPE_DIRECTION as xt}from"@polotno/core/animation-presets";import{textUnitState as vt}from"../utils/animations.js";export{ct as wrapHtmlForRenderTag};function wt(t,e){return t!==e&&(!k.textVerticalResizeEnabled||t<e)}const yt=({opacity:t,y:e,scale:o,blur:i,from:r,to:n,shift:s})=>t>=1&&!e&&1===o&&!i&&r<=0&&n>=1&&!s;export const RenderTagElement=s(({element:s,store:ct})=>{var jt,Ot,zt,Et,St,Mt,Rt,kt,Xt,Yt,Ct;const Pt=n.useRef(null),Tt=n.useRef(null),[Ft,It]=n.useState(!1),At=n.useRef(s.height),Bt=n.useRef(null),Ht=it(),{textVerticalResizeEnabled:Lt}=k,{fontLoaded:$t,fontFamily:Dt,color:_t,isPlaceholder:Jt,normalizedSourceText:Nt,getHtmlOptions:Ut}=D(s,ct),Vt=s._editModeEnabled;Q(Pt);const qt=Jt?.6:r(s),Wt=_(U(s),Ut),Gt=s.width||1,Kt=(t,e)=>A(U(t),{getHtmlOptions:Ut,textUnits:e}),Qt=Y(s),Zt=X(s),te=s.curveEnabled,ee=pt(s),oe=JSON.stringify(Zt),ie="fixed"===Zt.box?s.height:0,re=Ft?Bt.current:null,ne=n.useMemo(()=>{if(re){return re.sized}const t=s.filled.text,e=Jt?Object.assign(Object.assign({},s),{text:Nt}):void 0!==t&&t!==s.text?Object.assign(Object.assign({},s),{text:t}):s;try{return te?Object.assign({curved:!0},F({element:e,sizing:Zt,layoutAt:B(U(s),{getHtmlOptions:{fontFamily:Dt,color:_t,text:Nt,textIsNormalized:!0}})})):Object.assign({curved:!1},I({element:gt(e),sizing:Zt,layoutAt:Kt(gt(s))}))}catch(o){return console.error("render-tag layout failed:",o),null}},[Wt,Gt,$t,te,oe,ie,s.curvePower,s.fontSize,s.width,s.paddingTop,s.paddingRight,s.paddingBottom,s.paddingLeft,re]),se=null!==(jt=null==re?void 0:re.width)&&void 0!==jt?jt:Gt,ae=re?s.width/re.width:1,le=!1===(null==ne?void 0:ne.curved)?ne.layout:null,ce=(null==ne?void 0:ne.curved)?ne.layout:null,de=s.a.text,ue=s.a.textUnits,he=ue?bt[ue.animation.name].unit:void 0,fe=n.useMemo(()=>{var t;const e="string"==typeof de&&de!==(null!==(t=s.filled.text)&&void 0!==t?t:s.text);if(!1!==(null==ne?void 0:ne.curved)||Jt||!e&&!he){return le}try{const t=gt(s);return T({element:e?Object.assign(Object.assign({},t),{text:de}):t,sized:ne,sizing:Zt,layoutAt:Kt(t,he)})}catch(o){return console.error("render-tag layout failed:",o),le}},[le,de,he]),ge=ue&&(null==fe?void 0:fe.textUnits),me=n.useMemo(()=>{if(!ue||!ge){return null}const t=ge.map((t,e)=>vt(ue,e,ge.length)),e=e=>!t[e]||yt(t[e]);return t.map((t,o)=>({state:t,slice:yt(t)&&e(o-1)&&e(o+1)}))},[ue,ge]),pe=null!==(Ot=null==ne?void 0:ne.fontSize)&&void 0!==Ot?Ot:s.fontSize,be=null!==(zt=null==ne?void 0:ne.scale)&&void 0!==zt?zt:1,xe=N(s.letterSpacing,pe),ve=null!==(Et=null==re?void 0:re.overhang)&&void 0!==Et?Et:xe,we=L({fontLoaded:$t,fontFamily:s.fontFamily,fontSize:pe,lineHeight:s.lineHeight}),ye=te?0:Math.max(null!==(St=null==le?void 0:le.height)&&void 0!==St?St:0,pe*we),je=te?ye:mt(s,ye),Oe=ce?ce.bounds:null,ze=Oe?(s.width-Oe.width)/2-Oe.x:0,Ee=n.useMemo(()=>{var t;if(ce&&Oe){const t=ce.paintBounds;return Object.assign(Object.assign({},t),{x:t.x+ze,y:t.y-Oe.y})}const e=null!==(t=null==fe?void 0:fe.paintBounds)&&void 0!==t?t:null;return e&&ge?{x:e.x-pe,y:e.y-pe,width:e.width+2*pe,height:e.height+2*pe}:e},[fe,ce,Oe,ze,ge,pe]),Se=n.useMemo(()=>fe?fe.lines.map(t=>K({left:t.bounds.x,right:t.bounds.x+t.bounds.width,top:t.bounds.y,bottom:t.bounds.y+t.bounds.height},ve)):[],[fe,ve]),Me=n.useRef([]),Re=n.useRef(null),ke=n.useRef(!0),[,Xe]=n.useReducer(t=>t+1,0);n.useEffect(()=>{const t=Me.current;t.length>0&&(Me.current=[],t.forEach(t=>t()))});const Ye=n.useCallback((t,e,o,i)=>{const r=Z(`text ${s.id}`),n=()=>{ct.history.ignore(t,e,o).then(()=>{ke.current?(Me.current.push(r),Xe()):r()})};i?queueMicrotask(n):n()},[s.id,ct]),Ce=n.useCallback(t=>{const e=null!==Re.current;Re.current=t,e||Ye(()=>{const t=Re.current;Re.current=null,h(s)&&wt(s.height,t)&&s.set({height:t})},!1,!0)},[s,Ye]),Pe=n.useRef(ne);Pe.current=ne,n.useEffect(()=>{if(!$t){return}if(!le){return}if(!dt(s)){return void Ye(()=>{h(s)&&(dt(s)||s.set({height:je}))},void 0,void 0,!0)}if(ct.isPlaying){return}const t=wt(s.height,je),e=()=>Ce(je);if(void 0===s.filled.text||"change-font-size"!==Qt){if("change-font-size"!==Qt||Ft||Vt||s.curveEnabled){"resize"===Qt&&t&&!Ft&&e()}else if(ne&&ne.fontSize!==s.fontSize){const{fontSize:t,text:e}=ne;Ye(()=>{if(!h(s)){return}if(Pe.current!==ne||"change-font-size"!==Y(s)||s._editModeEnabled){return}const o=v(s,t);Jt||e===s.text||(o.text=e),s.set(o)},!1,!0)}else{t&&e()}}}),n.useEffect(()=>()=>{ke.current=!1;const t=Me.current;t.length>0&&(Me.current=[],t.forEach(t=>t()))},[]),n.useLayoutEffect(()=>{if(!$t||!s.curveEnabled||Ft){return}if(!Oe||!Oe.width){return}const t=t=>t&&Lt?Math.max(t,Oe.height):Oe.height,e=t=>P(Zt,{width:t},Oe.width);Math.abs(e(s.width)-s.width)<1&&Math.abs(t(s.height)-s.height)<1||Ye(()=>{if(!h(s)){return}const o=e(s.width),i=o-s.width,r=t(s.height),n=r-s.height;if(Math.abs(i)<1&&Math.abs(n)<1){return}const a=s.a.rotation*Math.PI/180,l=-i/2*Math.cos(a),c=-i/2*Math.sin(a);s.set({width:o,height:r,x:s.a.x+l,y:s.a.y+c})},!1,!0,!0)},[$t,s.curveEnabled,Qt,Oe,Ft,Lt,Ye]),n.useEffect(()=>u(s,()=>{const t=Pt.current;t&&H(t,s)}),[fe,ce,s.a.width,s.a.height,ue,s.a.shadowColor,s.a.shadowOffsetX,s.a.shadowOffsetY,s.a.shadowOpacity]);const Te=ut(s,je),Fe=te||!$t||Ft||ct.isPlaying||"resize"!==Qt?s.a.height:Lt?Math.max(s.a.height,je):je,Ie=ut(gt(s),ye);let Ae=0;te||"middle"!==s.verticalAlign?te||"bottom"!==s.verticalAlign||(Ae=Ie-ye*ae):Ae=(Ie-ye*ae)/2;const Be=null!==(Mt=null==re?void 0:re.backgroundPadding)&&void 0!==Mt?Mt:ft(s,we),He=null!==(Rt=null==re?void 0:re.backgroundCornerRadius)&&void 0!==Rt?Rt:ht(s,we),Le=s.backgroundEnabled||s.borderSize>0,$e="box"===s.backgroundShape,De=n.useMemo(()=>!Le||s.curveEnabled||$e||0===Se.length?"":G({rects:Se,padding:Be,cornerRadius:He}),[Le,s.curveEnabled,$e,Se,Be,He]),_e=n.useRef(null),Je=n.useRef(s.width),Ne=n.useRef(null),Ue=n.useRef(null),Ve=n.useRef(""),qe=n.useRef(0),We=n.useRef(0),Ge=n.useRef({fontSize:s.fontSize}),Ke=s.width>0?s.a.width/s.width:1,Qe=Ke*ae,Ze=ee.left&&ae>0?ee.left/ae:0,to=ee.top&&ae>0?ee.top/ae:0,eo=q(s),oo=null!==(kt=null==re?void 0:re.shadow)&&void 0!==kt?kt:{shadowBlur:eo.shadowBlur*be,shadowOffsetX:eo.shadowOffsetX*be,shadowOffsetY:eo.shadowOffsetY*be},io=Object.assign(Object.assign({},oo),{shadowColor:eo.shadowColor,shadowOpacity:eo.shadowOpacity}),ro=Object.assign(Object.assign({},io),{shadowEnabled:eo.shadowEnabled&&Le});return i(e,{children:[o(lt,{element:s,store:ct}),Le?s.curveEnabled||$e?o(at,Object.assign({as:c,element:s,offsetX:Be/Ke,offsetY:Be/Ke,scaleX:Qe,scaleY:Qe,hideInExport:!s.showInExport,listening:!1,opacity:qt,fillEnabled:s.backgroundEnabled,fill:ot(s.backgroundColor,s.backgroundOpacity),strokeEnabled:s.borderSize>0,stroke:V(s.borderColor),strokeWidth:null!==(Xt=null==re?void 0:re.borderSize)&&void 0!==Xt?Xt:s.borderSize},ro,{width:se+2*Be,height:(null!==(Yt=null==re?void 0:re.boxHeight)&&void 0!==Yt?Yt:Te)+2*Be,cornerRadius:He})):o(at,Object.assign({as:l,element:s,name:"rendertag-background",offsetX:Ze?-Ze:void 0,offsetY:-(to+Ae/Qe),scaleX:Qe,scaleY:Qe,hideInExport:!s.showInExport,listening:!1,visible:De.length>0,opacity:qt,fillEnabled:s.backgroundEnabled,fill:ot(s.backgroundColor,s.backgroundOpacity),strokeEnabled:s.borderSize>0,stroke:V(s.borderColor),strokeWidth:null!==(Ct=null==re?void 0:re.borderSize)&&void 0!==Ct?Ct:s.borderSize,lineJoin:He>0?"round":"miter"},ro,{data:De})):null,o(at,Object.assign({as:d,nodeRef:Pt,element:s,selfRectFunc:Ee?()=>Ee:void 0,name:"rendertag-text",scaleX:Qe,scaleY:Qe,offsetX:Ze&&Qe>0?-Ze:void 0,offsetY:Qe>0?-(to+Ae/Qe):0,width:se,height:Math.max(s.height,ye),listening:!1,visible:!Vt&&!!(te?ce:le),editModeEnabled:Vt,opacity:qt,shadowEnabled:eo.shadowEnabled&&!et(s)},io,{hideInExport:!s.showInExport,sceneFunc:(t,e)=>{const o=t._context;if(o){try{if(te){if(!ce||!Oe){return}o.save(),o.translate(ze,-Oe.y),m({layout:ce,ctx:o}),o.restore()}else{if(!fe){return}g({layout:fe,width:se,ctx:o,pixelRatio:1,paintTextUnit:me?t=>{const{state:e,slice:o}=me[t.unit.index];(({unit:t,ctx:e,draw:o},{opacity:i,y:r,scale:n,blur:s,from:a,to:l,direction:c,shift:d},u,h)=>{if(!(i<=0||n<=0||l<=a)){if(a>0||l<1||d){const{vertical:o,low:i,high:r,forward:n}=((t,e,o)=>{var i;const r=e?xt[e]:void 0,n="y"===(null==r?void 0:r.axis);let s=n?t.y:t.x,a=s+(n?t.height:t.width);if(n||o){for(const l of t.fragments){s=Math.min(s,n?l.paintTop:l.paintLeft),a=Math.max(a,n?l.paintBottom:l.paintRight)}}return{vertical:n,low:s,high:a,forward:r?r.forward:"rtl"!==(null===(i=t.fragments[0])||void 0===i?void 0:i.direction)}})(t,c,0!==d),s=r-i,[h,f]=n?[a,l]:[1-l,1-a],g=h<=0&&!d?i-u:i+h*s,m=f>=1&&!d?r+u:i+f*s;e.beginPath(),o?e.rect(t.x-u,g,t.width+2*u,m-g):e.rect(g,t.y-u,m-g,t.height+2*u),e.clip();const p=d*s*(n?1:-1);o?e.translate(0,p):e.translate(p,0)}if(e.globalAlpha*=i,r&&e.translate(0,r*u),1!==n){const o=t.x+t.width/2,i=t.y+t.height/2;e.translate(o,i),e.scale(n,n),e.translate(-o,-i)}if(s>0){const t=e.getTransform(),o=Math.sqrt(Math.abs(t.a*t.d-t.b*t.c));e.filter=`blur(${s*u*o}px)`}o({slice:h})}})(t,e,pe,o)}:void 0})}}catch(i){console.error("render-tag draw failed:",i)}}}})),o(at,{as:c,nodeRef:Tt,element:s,name:"element",listening:s.selectable,width:s.a.width,height:Fe,visible:!Vt,draggable:Ht?s.draggable&&s.isSelected:s.draggable,preventDefault:!Ht||s.isSelected,opacity:0,hideInExport:!0,id:s.id,onDragMove:t=>{s.set({x:t.target.x(),y:t.target.y()})},onDragEnd:t=>{s.set(E(t.target))},onDblClick:t=>{s.contentEditable&&(Ue.current={x:t.evt.clientX,y:t.evt.clientY},s.toggleEditMode(!0))},onDblTap:t=>{var e;if(s.contentEditable){const o=null===(e=t.evt.changedTouches)||void 0===e?void 0:e[0];Ue.current=o?{x:o.clientX,y:o.clientY}:null,s.toggleEditMode(!0)}},onTransformStart:t=>{At.current=s.height,Je.current=s.width,Ne.current=null,_e.current=t.target.position(),Ve.current=p(t.target),qe.current=s.a.rotation,We.current=s.height,Ge.current={fontSize:s.fontSize,minFontSize:s.minFontSize,maxFontSize:s.maxFontSize},Bt.current=!s.curveEnabled&&["top-left","top-right","bottom-left","bottom-right"].includes(Ve.current)?{sized:ne,width:Gt,boxHeight:Te,backgroundPadding:Be,backgroundCornerRadius:He,borderSize:s.borderSize,overhang:xe,shadow:oo}:null,It(!0)},onTransform:e=>{const o=e.target,i=Ve.current,r="middle-left"===i||"middle-right"===i,n="top-center"===i||"bottom-center"===i,a=R(o.scaleX());if(r){const e=o.width()*a;let i=Math.max(e,S(te?{}:s,Je.current,C(s)));const r=s.toJSON();let n=0;if("fit"===Qt){n=At.current}else if(s.curveEnabled){n=J(Object.assign(Object.assign({},r),{width:i}))}else{const{x:e,y:o,width:s,height:a}=r,l=t(r,["x","y","width","height"]),c=`${JSON.stringify(l)}|${Dt}|${$t}|${_t}`;if(Ne.current&&Ne.current.signature===c&&i<=Ne.current.width){i=Ne.current.width,n=Ne.current.height}else{const t=t=>{const e=gt(Object.assign(Object.assign({},r),{width:t}));try{return I({element:Object.assign(Object.assign({},e),{text:Nt}),sizing:Object.assign(Object.assign({},Zt),{fit:{mode:"off"},cutAtBox:!1}),layoutAt:Kt(e)}).layout}catch(jt){const o=_(e,Ut);return{height:W(o).height,lines:[]}}};let e=t(i);const o=Math.max(0,...e.lines.map(t=>t.bounds.x+t.bounds.width-xe)),s=ee.left+ee.right;o+s>i+.5&&o+s<=Je.current+.5&&(i=Math.min(Math.ceil(o)+s,Je.current),e=t(i),Ne.current={signature:c,width:i,height:e.height}),n=e.height}n+=ee.top+ee.bottom}i>e&&_e.current&&o.position(_e.current),o.width(i),o.scaleX(1),o.scaleY(1);let l=k.textVerticalResizeEnabled?Math.max(n,At.current):n;"ellipsis"!==Qt&&"fit"!==Qt||(l=At.current),o.height(l),s.set({width:o.width(),height:l,x:o.x(),y:o.y()})}else if(n){const t="resize"===Qt?te?(null==Oe?void 0:Oe.height)||s.fontSize:je:we*("fit"===Zt.fit.mode?Zt.fit.min:s.fontSize)+ee.top+ee.bottom,e=o.height()*o.scaleY();if(e<t){if(o.height(t),_e.current){if("top-center"===Ve.current){const e=qe.current*Math.PI/180,i=We.current-t;o.x(_e.current.x-i*Math.sin(e)),o.y(_e.current.y+i*Math.cos(e))}else{o.position(_e.current)}}}else{o.height(e)}o.scaleY(1),o.scaleX(1),We.current=Math.max(t,e),s.set({x:o.x(),y:o.y(),height:o.height(),rotation:o.rotation()})}else{o.scaleX(1),o.scaleY(1);const t=s.fontSize*a;s.set(Object.assign(Object.assign(Object.assign({},w(Ge.current,t/Ge.current.fontSize)),{letterSpacing:s.letterSpacing,width:o.width()*a,x:o.x(),y:o.y(),rotation:o.rotation(),height:o.height()*a}),O(s,a)))}_e.current=e.target.position()},onTransformEnd:t=>{Bt.current=null,It(!1);const e=t.target.scaleX();t.target.scaleX(1),t.target.scaleY(1);const o=y(s,s.fontSize*e),i=Ge.current,r=Ve.current;s.set(Object.assign(Object.assign(Object.assign({},o),b(r)&&!x(r)?Object.assign(Object.assign({},w(i,o.fontSize/i.fontSize,!0)),M(s)):{}),{width:z(t.target.width()*e),x:z(t.target.x()),y:z(t.target.y()),rotation:z(t.target.rotation()),text:nt(s.text,e)}))}}),Vt&&o(at,{as:a,element:s,offsetX:ee.left?-ee.left:void 0,offsetY:-(ee.top+Ae),children:o(f,{divProps:{style:{zIndex:20}},children:o(st,{element:s,fitScale:be,fitScaleFor:t=>te?be:$(gt(s),Zt,Ut,t,be),onChange:t=>{if("fit"===Qt){return void s.set({text:t})}const e=rt({oldText:tt(s.text),newText:tt(t),element:s});s.set(Object.assign({text:t},v(s,e)))},onBlur:()=>{h(s)&&(s.set(j(s)),s.toggleEditMode(!1))},clickCoords:Ue.current})})})]})});
@@ -1,4 +1,4 @@
1
- var t=this&&this.__rest||function(t,e){var o={};for(var n in t){Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(o[n]=t[n])}if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(n=Object.getOwnPropertySymbols(t);r<n.length;r++){e.indexOf(n[r])<0&&Object.prototype.propertyIsEnumerable.call(t,n[r])&&(o[n[r]]=t[n[r]])}}return o};import{jsx as e}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{geckoRtlOverhangCss as s,getDir as a,getMeasureCtx as c,getQuillEditorHtml as d,letterSpacingOverhang as u,OVERHANG_PROPERTY as f,textLayoutWidth as p}from"@polotno/core/text-html";import{quillHtmlToModelText as m,isQuillFormatMixed as h,isBoldWeight as g,detachNativeColorsInHtml as b}from"../utils/rich-text-html.js";import{toDisplayColor as v}from"@polotno/core/color";import{LIST_INDENT_EM as y}from"@polotno/core/css-values";import{resetStyleContent as x,linkStyle as w,wrapHtmlForRenderTag as S}from"@polotno/core/reset-style";import{layout as k,lineBaselineOffset as T}from"render-tag";import{removeTags as E}from"@polotno/core/text";import{cssFontFamily as q}from"@polotno/core/fonts";import{isGradient as C,firstStopColor as L}from"@polotno/core/gradient";import{getOptimalCaretColor as O}from"./text-element/caret-color.js";import{visiblePlaceholder as R}from"./text-element/placeholder.js";import{registerQuillUnrestrictedFontFormats as F,PRESERVED_INLINE_STYLES as $,PRESERVED_BLOCK_STYLES as N}from"./quill-font-formats.js";import{ALL_QUILL_MIXED_KEYS as z,setActiveTextEditor as j,updateActiveTextFormat as M,clearActiveTextEditor as D,getActiveTextEditor as P}from"../utils/text-format-state.js";import A from"../utils/styled.js";import{applyOpacityToColor as H}from"@polotno/core/svg";import{elementDropShadow as I,shadowCastByBackground as Q}from"@polotno/core/filters";export{H as applyOpacityToColor};export const quillRef=r.observable({enabled:!1,currentFormat:{},pendingToolbarInteraction:!1,editor:r.observable.object({instance:null},{},{deep:!1})});const _=z;export function syncQuillFormatState(t,e){const o=e?t.getFormat(e):{},n=function(t,e){const o={};if(!e||e.length<=0){return o}const n=t.getContents(e.index,e.length);for(const r of _){h(n,r)&&(o[r]=!0)}return o}(t,e);r.runInAction(()=>{quillRef.currentFormat=o}),M(o,n,e)}const W="polotno-saved-selection";function B(){const t=window.getSelection();if(!t||0===t.rangeCount||t.isCollapsed){return}if("undefined"==typeof Highlight||!CSS.highlights){return}const e=t.getRangeAt(0).cloneRange();CSS.highlights.set(W,new Highlight(e)),X()}function V(){"undefined"!=typeof CSS&&CSS.highlights&&CSS.highlights.delete(W)}function X(){setTimeout(()=>{"undefined"!=typeof CSS&&CSS.highlights&&CSS.highlights.has(W)&&(document.querySelector(".polotno-portal")||lt(document.activeElement)?X():V())},300)}if("undefined"!=typeof document&&"undefined"!=typeof CSS&&CSS.highlights&&!document.querySelector("[data-polotno-highlight]")){const st=document.createElement("style");st.setAttribute("data-polotno-highlight",""),st.textContent=`::highlight(${W}) { background-color: Highlight; }`,document.head.appendChild(st)}export function collectRTText(t,e){"text"===t.type?e.push(t):t.children.forEach(t=>collectRTText(t,e))}export function computeMarkerVars(t){var e,o,n;const r=t.fontSize;if(!r||r<=0){return null}const i=q(t.fontFamily),l=g(t.fontWeight)?700:400,s="italic"===t.fontStyle?"italic":"normal",a=c();a.fontKerning="normal",a.font=`${r}px ${i}`;const d=a.measureText("M"),u=(null!==(e=d.fontBoundingBoxAscent)&&void 0!==e?e:0)/r,f=(null!==(o=d.fontBoundingBoxDescent)&&void 0!==o?o:0)/r,p=`font-family:${i};font-size:${r}px;font-weight:${l};font-style:${s};line-height:${t.lineHeight};letter-spacing:${t.letterSpacing}em`,m=S(`<div style="${p}"><ul><li>x</li></ul><ol><li>x</li></ol></div>`);let h;try{h=k({html:m,width:Math.max(12*r,600)})}catch(O){return null}const b=[];collectRTText(h.layoutRoot,b);const v=b.find(t=>"•"===t.text),x=b.find(t=>/^\d/.test(t.text));if(!v){return null}const w=v.style.fontSize,E=v.x,C=v.y-T(w,w*u,w*f),L=y*r;return{bulletLeft:E,bulletTop:C,bulletFontSize:w,numberGap:x?Math.max(0,L-x.x-(null!==(n=x.width)&&void 0!==n?n:0)):0}}export const RichTextContainer=A("div",o.forwardRef)`
1
+ var t=this&&this.__rest||function(t,e){var o={};for(var n in t){Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(o[n]=t[n])}if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(n=Object.getOwnPropertySymbols(t);r<n.length;r++){e.indexOf(n[r])<0&&Object.prototype.propertyIsEnumerable.call(t,n[r])&&(o[n[r]]=t[n[r]])}}return o};import{jsx as e}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{geckoRtlOverhangCss as s,getDir as a,getMeasureCtx as c,getQuillEditorHtml as d,letterSpacingOverhang as u,OVERHANG_PROPERTY as f,textLayoutWidth as p}from"@polotno/core/text-html";import{textContentBox as m}from"@polotno/core/text-types";import{quillHtmlToModelText as h,isQuillFormatMixed as g,isBoldWeight as b,detachNativeColorsInHtml as v,VARIABLE_TOKEN_CLASS as y}from"../utils/rich-text-html.js";import{variableTokens as x}from"@polotno/schema/variables";import{toDisplayColor as w}from"@polotno/core/color";import{LIST_INDENT_EM as k}from"@polotno/core/css-values";import{resetStyleContent as S,linkStyle as T,wrapHtmlForRenderTag as E}from"@polotno/core/reset-style";import{layout as q,lineBaselineOffset as C}from"render-tag";import{removeTags as L}from"@polotno/core/text";import{cssFontFamily as R}from"@polotno/core/fonts";import{isGradient as O,firstStopColor as F}from"@polotno/core/gradient";import{getOptimalCaretColor as $}from"./text-element/caret-color.js";import{visiblePlaceholder as N}from"./text-element/placeholder.js";import{registerQuillUnrestrictedFontFormats as z,PRESERVED_INLINE_STYLES as j,PRESERVED_BLOCK_STYLES as M,VARIABLE_TOKEN_FORMAT as D}from"./quill-font-formats.js";import{ALL_QUILL_MIXED_KEYS as P,setActiveTextEditor as A,updateActiveTextFormat as H,clearActiveTextEditor as I,getActiveTextEditor as Q}from"../utils/text-format-state.js";import _ from"../utils/styled.js";import{applyOpacityToColor as W}from"@polotno/core/svg";import{elementDropShadow as B,shadowCastByBackground as V}from"@polotno/core/filters";export{W as applyOpacityToColor};export const quillRef=r.observable({enabled:!1,currentFormat:{},pendingToolbarInteraction:!1,editor:r.observable.object({instance:null},{},{deep:!1})});const X=P;export function syncQuillFormatState(t,e){const o=e?t.getFormat(e):{},n=function(t,e){const o={};if(!e||e.length<=0){return o}const n=t.getContents(e.index,e.length);for(const r of X){g(n,r)&&(o[r]=!0)}return o}(t,e);r.runInAction(()=>{quillRef.currentFormat=o}),H(o,n,e)}const G="polotno-saved-selection";function Y(){const t=window.getSelection();if(!t||0===t.rangeCount||t.isCollapsed){return}if("undefined"==typeof Highlight||!CSS.highlights){return}const e=t.getRangeAt(0).cloneRange();CSS.highlights.set(G,new Highlight(e)),K()}function U(){"undefined"!=typeof CSS&&CSS.highlights&&CSS.highlights.delete(G)}function K(){setTimeout(()=>{"undefined"!=typeof CSS&&CSS.highlights&&CSS.highlights.has(G)&&(document.querySelector(".polotno-portal")||ut(document.activeElement)?K():U())},300)}if("undefined"!=typeof document&&"undefined"!=typeof CSS&&CSS.highlights&&!document.querySelector("[data-polotno-highlight]")){const ft=document.createElement("style");ft.setAttribute("data-polotno-highlight",""),ft.textContent=`::highlight(${G}) { background-color: Highlight; }`,document.head.appendChild(ft)}export function collectRTText(t,e){"text"===t.type?e.push(t):t.children.forEach(t=>collectRTText(t,e))}export function computeMarkerVars(t){var e,o,n;const r=t.fontSize;if(!r||r<=0){return null}const i=R(t.fontFamily),l=b(t.fontWeight)?700:400,s="italic"===t.fontStyle?"italic":"normal",a=c();a.fontKerning="normal",a.font=`${r}px ${i}`;const d=a.measureText("M"),u=(null!==(e=d.fontBoundingBoxAscent)&&void 0!==e?e:0)/r,f=(null!==(o=d.fontBoundingBoxDescent)&&void 0!==o?o:0)/r,p=`font-family:${i};font-size:${r}px;font-weight:${l};font-style:${s};line-height:${t.lineHeight};letter-spacing:${t.letterSpacing}em`,m=E(`<div style="${p}"><ul><li>x</li></ul><ol><li>x</li></ol></div>`);let h;try{h=q({html:m,width:Math.max(12*r,600)})}catch(L){return null}const g=[];collectRTText(h.layoutRoot,g);const v=g.find(t=>"•"===t.text),y=g.find(t=>/^\d/.test(t.text));if(!v){return null}const x=v.style.fontSize,w=v.x,S=v.y-C(x,x*u,x*f),T=k*r;return{bulletLeft:w,bulletTop:S,bulletFontSize:x,numberGap:y?Math.max(0,T-y.x-(null!==(n=y.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 */
@@ -22,8 +22,8 @@ var t=this&&this.__rest||function(t,e){var o={};for(var n in t){Object.prototype
22
22
  pointer-events: none;
23
23
  opacity: 0;
24
24
  }
25
- ${x}
26
- ${w}
25
+ ${S}
26
+ ${T}
27
27
 
28
28
  /* ===== Editor-only list markers (Quill flat-DOM hack) ======================
29
29
  Quill emits a FLAT <ol> with per-item data-list + ql-indent classes (not
@@ -60,7 +60,7 @@ var t=this&&this.__rest||function(t,e){var o={};for(var n in t){Object.prototype
60
60
  }
61
61
  .ql-editor li {
62
62
  position: relative; /* anchor for the absolutely-positioned ::before */
63
- padding-inline-start: ${y}em; /* marker space + per-level indent (start side) */
63
+ padding-inline-start: ${k}em; /* marker space + per-level indent (start side) */
64
64
  }
65
65
  .ql-editor li[data-list='ordered'] {
66
66
  counter-increment: list-0;
@@ -87,7 +87,7 @@ var t=this&&this.__rest||function(t,e){var o={};for(var n in t){Object.prototype
87
87
  inset-inline-start: 0;
88
88
  top: 0;
89
89
  box-sizing: border-box;
90
- width: ${y}em;
90
+ width: ${k}em;
91
91
  text-align: end;
92
92
  }
93
93
  .ql-editor li[data-list='ordered']::before {
@@ -128,6 +128,12 @@ var t=this&&this.__rest||function(t,e){var o={};for(var n in t){Object.prototype
128
128
  text-align: left;
129
129
  }
130
130
 
131
+ /* A variable token shows as stored (markVariableTokens), whatever case the
132
+ element or a span asks for: its name is case-sensitive. */
133
+ .ql-editor .${y}, .ql-editor .${y} * {
134
+ text-transform: none !important;
135
+ }
136
+
131
137
  strong {
132
138
  font-weight: 700;
133
139
  }
@@ -164,4 +170,4 @@ var t=this&&this.__rest||function(t,e){var o={};for(var n in t){Object.prototype
164
170
  .ql-editor [style*='background-clip'] {
165
171
  -webkit-text-stroke-width: 0;
166
172
  }
167
- `;const G=[...$,...N,"header"];let Y=["link","background","font-weight","color","gradient","font","italic","size","script","strike","underline","text-transform","indent","list","direction",...G];export const setQuillFormats=t=>{Y=t};let U=!1;function K(){U||(U=!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 J(t){return t?"700":"400"}const Z=n.import("delta"),tt="data-polotno-rich-text",et=["text-decoration-color","text-decoration-style","text-decoration-thickness"],ot=(t,e)=>{const{style:o}=t,n=o.textDecorationLine,r={};if(n.includes("underline")&&(r.underline=!0),n.includes("line-through")&&(r.strike=!0),!r.underline&&!r.strike){return e}for(const i of et){const t=o.getPropertyValue(i);t&&!/^(initial|currentcolor|solid|auto)$/i.test(t)&&(r[i]=t)}return e.ops.reduce((t,e)=>void 0===e.insert?t:t.insert(e.insert,Object.assign(Object.assign({},r),e.attributes)),new Z)};export const createQuill=(e,o)=>{F();const r=new n(e,{toolbar:!1,keyboard:!1,placeholder:(null==o?void 0:o.placeholder)||void 0,clipboard:{matchVisual:!1},formats:Y});r.root.addEventListener("click",t=>{t.target instanceof Element&&t.target.closest("a")&&t.preventDefault()}),function(e){const o=e.format.bind(e),n=e.formatText.bind(e),r=e.getFormat.bind(e);e.format=(t,e,n)=>"bold"===t?(K(),o("font-weight",J(e),n)):o(t,e,n),e.formatText=(e,o,r,i,l)=>{if(r&&"object"==typeof r){if("bold"in r){K();const{bold:l}=r,s=t(r,["bold"]);return n(e,o,Object.assign(Object.assign({},s),{"font-weight":J(l)}),i)}return n(e,o,r,i)}return"bold"===r?(K(),n(e,o,"font-weight",J(i),l)):n(e,o,r,i,l)},e.getFormat=(...t)=>{const e=r(...t);return e&&null!=e["font-weight"]&&!("bold"in e)&&(e.bold=g(e["font-weight"])),e}}(r);const i=(t,e)=>e.compose((new Z).retain(e.length(),{"font-weight":"700"}));r.clipboard.addMatcher("STRONG",i),r.clipboard.addMatcher("B",i),r.clipboard.addMatcher(Node.ELEMENT_NODE,ot);const l=r.clipboard,s=l.onPaste.bind(l);return l.onPaste=(t,e)=>{var o;if(null===(o=e.html)||void 0===o?void 0:o.includes(tt)){return it(r,()=>s(t,e))}const n=l.convert;l.convert=(...t)=>((t,e)=>{for(const o of t.ops){if(o.attributes){for(const t of e){delete o.attributes[t]}}}return t})(n.apply(l,t),G);try{return s(t,e)}finally{l.convert=n}},r};const nt=(t,e)=>e.insert(t.data),rt=(t,e)=>{const o=e.ops[0];return parseFloat(t.style.textIndent)>0&&"string"==typeof(null==o?void 0:o.insert)&&o.insert.startsWith("\t")?e.compose((new Z).delete(1)):e};function it(t,e){const{matchers:o}=t.clipboard,n=o.findIndex(([t])=>t===Node.TEXT_NODE),r=o[n];-1!==n&&(o[n]=[Node.TEXT_NODE,nt]),o.push([Node.ELEMENT_NODE,rt]);try{return e()}finally{o.pop(),-1!==n&&(o[n]=r)}}export const setQuillContent=(t,e)=>{const o=it(t,()=>t.clipboard.convert({html:"<div class='ql-editor' style='outline: none;'>"+e+"<p><br></p></div>",text:""}));t.setContents(o),t.history.clear()};export const editorHtml=t=>d({text:b(t.text),width:t.width,fontSize:t.fontSize,fontFamily:t.fontFamily},t.fontFamily);export const RichEditor=({onBlur:t,onChange:n,element:s,clickCoords:c,initialCaret:d="start",fitScale:h=1,fitScaleFor:g})=>{const b=o.useRef(null),y=o.useRef(!1),x=o.useRef(h);x.current=h;const[w,S]=o.useState(null),k=null!=w?w:h,T=o.useRef(g);T.current=g;const F=t=>({width:p(s.a.width/t,s.letterSpacing,s.fontSize),zoom:1!==t?t:void 0}),$=o.useRef(null),N=o.useRef(void 0),z=()=>`${s.text}\0${s.fontSize}\0${s.fontFamily}`,M=t=>m(t,{fontSize:s.fontSize,fontFamily:s.fontFamily}),A=t=>{setQuillContent(t,editorHtml(s)),$.current=M(t.root.innerHTML),N.current=z()},H=o.useRef(()=>{}),_=()=>{H.current(),t()};o.useLayoutEffect(()=>{let t,e,o=!1,i=null,a=null,u=null,f=null,p=null;const m=()=>{if(!o&&b.current){try{t=createQuill(b.current,{placeholder:R(s.placeholder)}),r.runInAction(()=>{quillRef.editor.instance=t}),quillRef.pendingToolbarInteraction=!1,window.__polotnoQuill=t,j({instance:t,store:s.store,element:s});const o=e=>{e&&syncQuillFormatState(t,e)},m=()=>{let e=t.root;if(e.querySelector(".ql-cursor")){e=e.cloneNode(!0);const t=e.querySelector(".ql-cursor");t.replaceWith(t.textContent.replace(/\uFEFF/g,""))}return M(e.innerHTML)},h=()=>{const t=T.current;t&&l(s)&&(t=>{const e=b.current;if(!e){return}const o=F(t);e.style.width=`${o.width}px`,e.style.zoom=void 0===o.zoom?"":String(o.zoom)})(t(m()))},g=()=>{var o,r;if(clearTimeout(e),e=void 0,!l(s)){return}const i=m();if(i===$.current){return}$.current=i,y.current=!0,n(i);const a=t.getContents(),c=s.fill;let d=null,u=!0;for(const t of a.ops){if("string"!=typeof t.insert||"\n"===t.insert){continue}if(null===(o=t.attributes)||void 0===o?void 0:o.gradient){u=!1;break}const e=(null===(r=t.attributes)||void 0===r?void 0:r.color)||c;if(null===d){d=e}else if(e!==d){u=!1;break}}u&&d&&d!==s.fill&&s.set({fill:d})};H.current=()=>{(void 0!==e||t.composition.isComposing)&&g()},t.on("text-change",()=>{const n=P(),r=n&&n.instance===t?n.lastSelection:null;o(t.getSelection()||r),t.composition.isComposing||h(),void 0===e&&(e=setTimeout(g,10))}),t.on("selection-change",o),t.on("composition-start",()=>S(x.current)),t.on("composition-end",()=>{h(),S(null)}),A(t);const v=b.current.closest(".polotno-workspace-inner"),w=null==v?void 0:v.scrollLeft,k=null==v?void 0:v.scrollTop,E="end"===d?t.getLength()-1:0;c?setCursorFromCoords(t,c,E):t.setSelection(E,0,"api"),v&&void 0!==w&&void 0!==k&&(v.scrollLeft=w,v.scrollTop=k);const q=t.root;f=t=>{const e=t.relatedTarget;(null==e?void 0:e.classList.contains("ql-clipboard"))||(lt(e)||quillRef.pendingToolbarInteraction?B():setTimeout(()=>{quillRef.pendingToolbarInteraction||lt(document.activeElement)?B():(V(),_())},0))},p=()=>{V()},q.addEventListener("blur",f),q.addEventListener("focus",p),i=q,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 s="";if(l&&l.rangeCount>0){const t=l.getRangeAt(0);let e=t.cloneContents(),o=t.startContainer;o&&o.nodeType===Node.TEXT_NODE&&(o=o.parentNode);let n=t.endContainer;if(n&&n.nodeType===Node.TEXT_NODE&&(n=n.parentNode),o&&o===n){let t=o;for(;t&&t!==q&&t.nodeType===Node.ELEMENT_NODE;){const o=t.tagName;if("SPAN"!==o&&"EM"!==o&&"STRONG"!==o&&"U"!==o&&"S"!==o&&"A"!==o){break}const n=t.cloneNode(!1);n.appendChild(e),e=n,t=t.parentNode}}const r=document.createElement("div");r.appendChild(e),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 ${tt} 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()},u=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",u)}catch(m){console.error("RichEditor init failed:",m)}}};return b.current?m():queueMicrotask(m),()=>{o=!0,H.current(),clearTimeout(e),i&&f&&i.removeEventListener("blur",f),i&&p&&i.removeEventListener("focus",p),V(),i&&a&&u&&(i.removeEventListener("copy",a),i.removeEventListener("cut",u)),r.runInAction(()=>{quillRef.editor.instance=null,quillRef.currentFormat={}}),D(t),delete window.__polotnoQuill}},[]),o.useEffect(()=>i(s,z,t=>{const e=quillRef.editor.instance;if(!e){return}if(y.current){return y.current=!1,void(N.current=t)}if(t===N.current){return}const o=e.getSelection();A(e),o&&(e.setSelection(o.index,o.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(E(s.text))}`,()=>{const t=b.current;if(!t){return}const e="ltr"===a(E(s.text)),o=computeMarkerVars(s);o&&t.style.setProperty("--rt-number-gap",`${o.numberGap}px`),o&&e?(t.style.setProperty("--rt-bullet-left",`${o.bulletLeft}px`),t.style.setProperty("--rt-bullet-top",`${o.bulletTop}px`),t.style.setProperty("--rt-bullet-fs",`${o.bulletFontSize}px`),t.classList.add("rt-marker-geom")):t.classList.remove("rt-marker-geom")},{fireImmediately:!0}),[]),o.useEffect(()=>{window.addEventListener("blur",_);const t=t=>{var e;const o=t.target;"number"==typeof(null==o?void 0:o.nodeType)&&(null===(e=b.current)||void 0===e?void 0:e.contains(o))||lt(o)||quillRef.pendingToolbarInteraction||(V(),_())};return window.addEventListener("mousedown",t),window.addEventListener("touchstart",t),()=>{window.removeEventListener("blur",_),window.removeEventListener("mousedown",t),window.removeEventListener("touchstart",t)}},[]);const W=v(s.fill),X={color:W};W.indexOf("gradient")>=0&&(X["--polotno-gradient"]=W,X.color="transparent"),s.strokeWidth>0&&(X.WebkitTextStroke=`${s.strokeWidth}px ${L(s.stroke)}`,X.paintOrder="stroke fill");const G=C(s.fill)?L(s.fill):O(s),Y=s.shadowEnabled&&!Q(s);return e(RichTextContainer,{ref:b,style:Object.assign(Object.assign(Object.assign(Object.assign({},X),{fontSize:s.fontSize,fontFamily:q(s.fontFamily),fontWeight:s.fontWeight,fontStyle:s.fontStyle,"--polotno-text-decoration":s.textDecoration||"none",textTransform:s.textTransform}),F(k)),{[f]:u(s.letterSpacing,s.fontSize)+"px",lineHeight:s.lineHeight,letterSpacing:s.letterSpacing*s.fontSize+"px",textAlign:s.align,opacity:Math.max(s.a.opacity,.2),filter:Y?I({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(E(s.text))})};function lt(t){const e=t;return!("function"!=typeof(null==e?void 0:e.closest)||!e.closest(".sketch-picker")&&!e.closest("[data-polotno-keep-focus]")&&!e.closest(".polotno-portal")&&!e.closest(".polotno-toolbar"))}export function setCursorFromCoords(t,e,o=0){if(!t||!e){return}const{x:r,y:i}=e;try{let e=null;if(document.caretRangeFromPoint){e=document.caretRangeFromPoint(r,i)}else if(document.caretPositionFromPoint){const t=document.caretPositionFromPoint(r,i);t&&(e=document.createRange(),e.setStart(t.offsetNode,t.offset))}if(e){const o=n.find(e.startContainer,!0);if(o){const n=o.offset(t.scroll)+e.startOffset;return void t.setSelection(n,0,"api")}}}catch(l){}t.setSelection(o,0,"api")}
173
+ `;const J=[...j,...M,"header"];let Z=["link","background","font-weight","color","gradient","font","italic","size","script","strike","underline","text-transform","indent","list","direction",...J];export const setQuillFormats=t=>{Z=t};let tt=!1;function et(){tt||(tt=!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 ot(t){return t?"700":"400"}const nt=n.import("delta"),rt="data-polotno-rich-text",it=["text-decoration-color","text-decoration-style","text-decoration-thickness"],lt=(t,e)=>{const{style:o}=t,n=o.textDecorationLine,r={};if(n.includes("underline")&&(r.underline=!0),n.includes("line-through")&&(r.strike=!0),!r.underline&&!r.strike){return e}for(const i of it){const t=o.getPropertyValue(i);t&&!/^(initial|currentcolor|solid|auto)$/i.test(t)&&(r[i]=t)}return e.ops.reduce((t,e)=>void 0===e.insert?t:t.insert(e.insert,Object.assign(Object.assign({},r),e.attributes)),new nt)};export const createQuill=(e,o)=>{z();const r=new n(e,{toolbar:!1,keyboard:!1,placeholder:(null==o?void 0:o.placeholder)||void 0,clipboard:{matchVisual:!1},formats:[...Z,D]});r.root.addEventListener("click",t=>{t.target instanceof Element&&t.target.closest("a")&&t.preventDefault()}),function(e){const o=e.format.bind(e),n=e.formatText.bind(e),r=e.getFormat.bind(e);e.format=(t,e,n)=>"bold"===t?(et(),o("font-weight",ot(e),n)):o(t,e,n),e.formatText=(e,o,r,i,l)=>{if(r&&"object"==typeof r){if("bold"in r){et();const{bold:l}=r,s=t(r,["bold"]);return n(e,o,Object.assign(Object.assign({},s),{"font-weight":ot(l)}),i)}return n(e,o,r,i)}return"bold"===r?(et(),n(e,o,"font-weight",ot(i),l)):n(e,o,r,i,l)},e.getFormat=(...t)=>{const e=r(...t);return e&&null!=e["font-weight"]&&!("bold"in e)&&(e.bold=b(e["font-weight"])),e}}(r);const i=(t,e)=>e.compose((new nt).retain(e.length(),{"font-weight":"700"}));r.clipboard.addMatcher("STRONG",i),r.clipboard.addMatcher("B",i),r.clipboard.addMatcher(Node.ELEMENT_NODE,lt);const l=r.clipboard,s=l.onPaste.bind(l);return l.onPaste=(t,e)=>{var o;if(null===(o=e.html)||void 0===o?void 0:o.includes(rt)){return ct(r,()=>s(t,e))}const n=l.convert;l.convert=(...t)=>((t,e)=>{for(const o of t.ops){if(o.attributes){for(const t of e){delete o.attributes[t]}}}return t})(n.apply(l,t),J);try{return s(t,e)}finally{l.convert=n}},r};const st=(t,e)=>e.insert(t.data),at=(t,e)=>{const o=e.ops[0];return parseFloat(t.style.textIndent)>0&&"string"==typeof(null==o?void 0:o.insert)&&o.insert.startsWith("\t")?e.compose((new nt).delete(1)):e};function ct(t,e){const{matchers:o}=t.clipboard,n=o.findIndex(([t])=>t===Node.TEXT_NODE),r=o[n];-1!==n&&(o[n]=[Node.TEXT_NODE,st]),o.push([Node.ELEMENT_NODE,at]);try{return e()}finally{o.pop(),-1!==n&&(o[n]=r)}}function dt(t){var e;const{ops:o}=t.getContents(),n=o.map(t=>"string"==typeof t.insert?t.insert:"").join(""),r=new Uint8Array(n.length);for(const{start:s,end:a}of x(n)){r.fill(1,s,a)}const i=[];let l=0;for(const s of o){const t="string"==typeof s.insert?s.insert.length:1,o=!!(null===(e=s.attributes)||void 0===e?void 0:e[D]);for(let e=l;e<l+t;e++){const t=1===r[e];if(t===o){continue}const n=i[i.length-1];n&&n.index+n.length===e&&n.mark===t?n.length++:i.push({index:e,length:1,mark:t})}l+=t}for(const s of i){t.formatText(s.index,s.length,D,s.mark,"silent")}}export const setQuillContent=(t,e)=>{const o=ct(t,()=>t.clipboard.convert({html:"<div class='ql-editor' style='outline: none;'>"+e+"<p><br></p></div>",text:""}));t.setContents(o),t.history.clear()};export const editorHtml=t=>d({text:v(t.text),width:t.width,fontSize:t.fontSize,fontFamily:t.fontFamily},t.fontFamily);export const RichEditor=({onBlur:t,onChange:n,element:s,clickCoords:c,initialCaret:d="start",fitScale:g=1,fitScaleFor:b})=>{const v=o.useRef(null),y=o.useRef(!1),x=o.useRef(g);x.current=g;const[k,S]=o.useState(null),T=null!=k?k:g,E=o.useRef(b);E.current=b;const q=t=>({width:p(m({width:s.a.width,paddingLeft:s.paddingLeft,paddingRight:s.paddingRight,curveEnabled:s.curveEnabled}).width/t,s.letterSpacing,s.fontSize),zoom:1!==t?t:void 0}),C=o.useRef(null),z=o.useRef(void 0),j=()=>`${s.text}\0${s.fontSize}\0${s.fontFamily}`,M=t=>h(t,{fontSize:s.fontSize,fontFamily:s.fontFamily}),D=t=>{setQuillContent(t,editorHtml(s)),C.current=M(t.root.innerHTML),z.current=j()},P=o.useRef(()=>{}),H=()=>{P.current(),t()};o.useLayoutEffect(()=>{let t,e,o=!1,i=null,a=null,u=null,f=null,p=null;const m=()=>{if(!o&&v.current){try{t=createQuill(v.current,{placeholder:N(s.placeholder)}),r.runInAction(()=>{quillRef.editor.instance=t}),quillRef.pendingToolbarInteraction=!1,window.__polotnoQuill=t,A({instance:t,store:s.store,element:s});const o=e=>{e&&syncQuillFormatState(t,e)},m=()=>{let e=t.root;if(e.querySelector(".ql-cursor")){e=e.cloneNode(!0);const t=e.querySelector(".ql-cursor");t.replaceWith(t.textContent.replace(/\uFEFF/g,""))}return M(e.innerHTML)},h=()=>{const t=E.current;t&&l(s)&&(t=>{const e=v.current;if(!e){return}const o=q(t);e.style.width=`${o.width}px`,e.style.zoom=void 0===o.zoom?"":String(o.zoom)})(t(m()))},g=()=>{var o,r;if(clearTimeout(e),e=void 0,!l(s)){return}const i=m();if(i===C.current){return}C.current=i,y.current=!0,n(i);const a=t.getContents(),c=s.fill;let d=null,u=!0;for(const t of a.ops){if("string"!=typeof t.insert||"\n"===t.insert){continue}if(null===(o=t.attributes)||void 0===o?void 0:o.gradient){u=!1;break}const e=(null===(r=t.attributes)||void 0===r?void 0:r.color)||c;if(null===d){d=e}else if(e!==d){u=!1;break}}u&&d&&d!==s.fill&&s.set({fill:d})};P.current=()=>{(void 0!==e||t.composition.isComposing)&&g()},t.on("text-change",()=>{const n=Q(),r=n&&n.instance===t?n.lastSelection:null;o(t.getSelection()||r),t.composition.isComposing||(dt(t),h()),void 0===e&&(e=setTimeout(g,10))}),t.on("selection-change",o),t.on("composition-start",()=>S(x.current)),t.on("composition-end",()=>{dt(t),h(),S(null)}),D(t);const b=v.current.closest(".polotno-workspace-inner"),w=null==b?void 0:b.scrollLeft,k=null==b?void 0:b.scrollTop,T="end"===d?t.getLength()-1:0;c?setCursorFromCoords(t,c,T):t.setSelection(T,0,"api"),b&&void 0!==w&&void 0!==k&&(b.scrollLeft=w,b.scrollTop=k);const L=t.root;f=t=>{const e=t.relatedTarget;(null==e?void 0:e.classList.contains("ql-clipboard"))||(ut(e)||quillRef.pendingToolbarInteraction?Y():setTimeout(()=>{quillRef.pendingToolbarInteraction||ut(document.activeElement)?Y():(U(),H())},0))},p=()=>{U()},L.addEventListener("blur",f),L.addEventListener("focus",p),i=L,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 s="";if(l&&l.rangeCount>0){const t=l.getRangeAt(0);let e=t.cloneContents(),o=t.startContainer;o&&o.nodeType===Node.TEXT_NODE&&(o=o.parentNode);let n=t.endContainer;if(n&&n.nodeType===Node.TEXT_NODE&&(n=n.parentNode),o&&o===n){let t=o;for(;t&&t!==L&&t.nodeType===Node.ELEMENT_NODE;){const o=t.tagName;if("SPAN"!==o&&"EM"!==o&&"STRONG"!==o&&"U"!==o&&"S"!==o&&"A"!==o){break}const n=t.cloneNode(!1);n.appendChild(e),e=n,t=t.parentNode}}const r=document.createElement("div");r.appendChild(e),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 ${rt} 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()},u=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",u)}catch(m){console.error("RichEditor init failed:",m)}}};return v.current?m():queueMicrotask(m),()=>{o=!0,P.current(),clearTimeout(e),i&&f&&i.removeEventListener("blur",f),i&&p&&i.removeEventListener("focus",p),U(),i&&a&&u&&(i.removeEventListener("copy",a),i.removeEventListener("cut",u)),r.runInAction(()=>{quillRef.editor.instance=null,quillRef.currentFormat={}}),I(t),delete window.__polotnoQuill}},[]),o.useEffect(()=>i(s,j,t=>{const e=quillRef.editor.instance;if(!e){return}if(y.current){return y.current=!1,void(z.current=t)}if(t===z.current){return}const o=e.getSelection();D(e),o&&(e.setSelection(o.index,o.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(L(s.text))}`,()=>{const t=v.current;if(!t){return}const e="ltr"===a(L(s.text)),o=computeMarkerVars(s);o&&t.style.setProperty("--rt-number-gap",`${o.numberGap}px`),o&&e?(t.style.setProperty("--rt-bullet-left",`${o.bulletLeft}px`),t.style.setProperty("--rt-bullet-top",`${o.bulletTop}px`),t.style.setProperty("--rt-bullet-fs",`${o.bulletFontSize}px`),t.classList.add("rt-marker-geom")):t.classList.remove("rt-marker-geom")},{fireImmediately:!0}),[]),o.useEffect(()=>{window.addEventListener("blur",H);const t=t=>{var e;const o=t.target;"number"==typeof(null==o?void 0:o.nodeType)&&(null===(e=v.current)||void 0===e?void 0:e.contains(o))||ut(o)||quillRef.pendingToolbarInteraction||(U(),H())};return window.addEventListener("mousedown",t),window.addEventListener("touchstart",t),()=>{window.removeEventListener("blur",H),window.removeEventListener("mousedown",t),window.removeEventListener("touchstart",t)}},[]);const _=w(s.fill),W={color:_};_.indexOf("gradient")>=0&&(W["--polotno-gradient"]=_,W.color="transparent"),s.strokeWidth>0&&(W.WebkitTextStroke=`${s.strokeWidth}px ${F(s.stroke)}`,W.paintOrder="stroke fill");const X=O(s.fill)?F(s.fill):$(s),G=s.shadowEnabled&&!V(s);return e(RichTextContainer,{ref:v,style:Object.assign(Object.assign(Object.assign(Object.assign({},W),{fontSize:s.fontSize,fontFamily:R(s.fontFamily),fontWeight:s.fontWeight,fontStyle:s.fontStyle,"--polotno-text-decoration":s.textDecoration||"none",textTransform:s.textTransform}),q(T)),{[f]:u(s.letterSpacing,s.fontSize)+"px",lineHeight:s.lineHeight,letterSpacing:s.letterSpacing*s.fontSize+"px",textAlign:s.align,opacity:Math.max(s.a.opacity,.2),filter:G?B({shadowOffsetX:s.shadowOffsetX,shadowOffsetY:s.shadowOffsetY,shadowBlur:s.shadowBlur,shadowColor:s.shadowColor,shadowOpacity:s.shadowOpacity,rotation:s.a.rotation}):void 0,caretColor:X}),dir:a(L(s.text))})};function ut(t){const e=t;return!("function"!=typeof(null==e?void 0:e.closest)||!e.closest(".sketch-picker")&&!e.closest("[data-polotno-keep-focus]")&&!e.closest(".polotno-portal")&&!e.closest(".polotno-toolbar"))}export function setCursorFromCoords(t,e,o=0){if(!t||!e){return}const{x:r,y:i}=e;try{let e=null;if(document.caretRangeFromPoint){e=document.caretRangeFromPoint(r,i)}else if(document.caretPositionFromPoint){const t=document.caretPositionFromPoint(r,i);t&&(e=document.createRange(),e.setStart(t.offsetNode,t.offset))}if(e){const o=n.find(e.startContainer,!0);if(o){const n=o.offset(t.scroll)+e.startOffset;return void t.setSelection(n,0,"api")}}}catch(l){}t.setSelection(o,0,"api")}
@@ -0,0 +1,6 @@
1
+ export declare function useLegacyPaddingWarning(element: {
2
+ paddingTop?: number;
3
+ paddingRight?: number;
4
+ paddingBottom?: number;
5
+ paddingLeft?: number;
6
+ }): void;
@@ -0,0 +1 @@
1
+ import t from"react";import{textPadding as e}from"@polotno/core/text-types";import{warnOnceDeprecated as o}from"../../utils/deprecation.js";export function useLegacyPaddingWarning(r){const{top:d,right:n,bottom:i,left:p}=e(r),a=d+n+i+p>0;t.useEffect(()=>{a&&o("text-padding-legacy-renderer","Polotno: the deprecated text renderer does not draw text padding (paddingTop/Right/Bottom/Left); the default renderer does.")},[a])}
@@ -1 +1 @@
1
- export function getLimitedFontSize({oldText:t,newText:e,element:n}){if(!(e.length/Math.max(20,t.length)>=4)){return n.fontSize}const h=n.width*n.page.computedHeight/e.length,i=1.5*Math.sqrt(h),o=n.fontSize;return Math.min(o,Math.max(5,Math.round(i)))}
1
+ import{textContentBox as t}from"@polotno/core/text-types";export function getLimitedFontSize({oldText:e,newText:n,element:o}){if(!(n.length/Math.max(20,e.length)>=4)){return o.fontSize}const i=t(o).width*o.page.computedHeight/n.length,h=1.5*Math.sqrt(i),r=o.fontSize;return Math.min(r,Math.max(5,Math.round(h)))}
@@ -1 +1 @@
1
- import{Fragment as t,jsx as e,jsxs as r}from"react/jsx-runtime";import{elementOpacity as o}from"./paint-opacity.js";import n from"react";import{toDisplayColor as i}from"@polotno/core/color";import{observer as a}from"mobx-react-lite";import{Group as l,Path as s,Text as c,TextPath as d}from"react-konva";import{Html as u}from"react-konva-utils";import{nodeAutorun as f}from"../utils/mobx.js";import h from"konva";import{parsePath as g,roundCommands as m}from"svg-round-corners/lib/index.js";import{generateBackgroundShapeFromRects as p,textLinesToRects as x}from"@polotno/core/background-shape";import{useColor as b}from"./use-color.js";import{ROLES as v}from"../model/store.js";import{incrementLoader as w}from"../utils/loader.js";import{activeAnchorOf as S,scaledFontSizeAttrs as y,roundedFontSizeAttrs as E,roundedTextDecorationAttrs as z,roundedGeometryPx as k,roundedPosition as R,textMinResizeWidth as F,transformScale as j}from"../utils/px.js";import{isFontLoaded as M}from"../utils/fonts.js";import{flags as A}from"../utils/flags.js";import{textOverflowOf as L}from"../utils/text-sizing.js";import{FIT_FONT_SIZE_STEP as O,FIT_HEIGHT_EPSILON as T,legacyTextOverflow as C}from"@polotno/core/text-sizing";import{removeTags as H}from"@polotno/core/text";import{getDir as P,getCurvePath as W,resolveLineHeight as X,normalizeStrokeLineJoin as D}from"@polotno/core/text-html";import{cssFontFamily as Y}from"@polotno/core/fonts";import{shadowCastByBackground as $}from"@polotno/core/filters";import{applyOpacityToColor as J}from"@polotno/core/svg";import{applyFilter as N}from"./apply-filters.js";import{useFadeIn as B}from"./use-fadein.js";import{isTouchDevice as I}from"../utils/screen.js";import{isAlive as _}from"mobx-state-tree";import{getLimitedFontSize as V}from"./text-element/max-font-size.js";import{getOptimalCaretColor as q}from"./text-element/caret-color.js";import{visiblePlaceholder as U}from"./text-element/placeholder.js";import{hasMeasuredHeight as Z,resolveTextBoxHeight as G}from"@polotno/core/text-types";let K;function Q(){return K||(K=document.getElementById("polotno-text-style"),K||(K=document.createElement("style"),K.id="polotno-text-style",document.head.appendChild(K)),K)}h._fixTextRendering=!0;const tt={border:"none",padding:"0px",overflow:"hidden",background:"none",outline:"none",resize:"none",overflowWrap:"break-word",whiteSpace:"pre-wrap",userSelect:"text",wordBreak:"normal",textTransform:"none"};export{getDir}from"@polotno/core/text-html";const et=a(({textNodeRef:t,element:r,onBlur:o,selectAll:i,cursorPosition:a})=>{const[l,s]=n.useState(tt),c=t.current;n.useLayoutEffect(()=>{if(!c){return}const t={};t.width=c.width()-2*c.padding()+"px",t.height=c.height()-2*c.padding()+c.fontSize()*c.lineHeight()+"px",t.fontSize=c.fontSize()+"px",t.lineHeight=c.lineHeight()+.01,t.fontFamily=c.fontFamily(),t.textAlign=c.align(),t.color=c.fill(),t.fontWeight=r.fontWeight,t.fontStyle=r.fontStyle,t.letterSpacing=r.letterSpacing+"em",t.opacity=Math.max(r.a.opacity,.2),t.textTransform=r.textTransform,t.caretColor=q(r);const e=`\n .polotno-input::placeholder {\n color: ${l.color};\n opacity: 0.6;\n }\n `,o=Q();o.innerHTML="",o.appendChild(document.createTextNode(e)),JSON.stringify(t)!==JSON.stringify(l)&&s(t)});const d=n.useRef(null);if(n.useLayoutEffect(()=>{var t;const e=d.current;if(!e){return}null===(t=d.current)||void 0===t||t.focus({preventScroll:!0});const r=a||e.value.length;e.selectionStart=e.selectionEnd=r,i&&e.setSelectionRange(0,e.value.length)},[]),n.useEffect(()=>{window.addEventListener("blur",o);const t=t=>{var e;(null===(e=d.current)||void 0===e?void 0:e.contains(t.target))||o()};return window.addEventListener("touchstart",t),()=>{window.removeEventListener("blur",o),window.removeEventListener("touchstart",t)}},[]),!c){return null}let u=0;const f=c.textArr.length*c.lineHeight()*c.fontSize(),h=G(r.a,f);"middle"===r.verticalAlign&&(u=(h-f)/2),"bottom"===r.verticalAlign&&(u=h-f);const g=H(r.text);return e("textarea",{className:"polotno-input",ref:d,dir:P(g),style:Object.assign(Object.assign(Object.assign({},tt),l),{paddingTop:u+"px"}),value:g,onChange:t=>{const e=V({oldText:r.text,newText:t.target.value,element:r});r.set(Object.assign({text:t.target.value},y(r,e)))},placeholder:U(r.placeholder),onBlur:o})}),rt=t=>e(u,{children:e(et,Object.assign({},t))});export const useFontLoader=(t,e,r,o,n)=>useFontFamiliesLoader(t,[e],r,o,n);export const useFontFamiliesLoader=(t,e,r,o,i)=>{const[a,l]=n.useReducer(t=>t+1,0),s=e.join("\0"),c=n.useRef(e.every(t=>M(t,r,o))),d=n.useRef(null);return n.useLayoutEffect(()=>{const n=c.current;if(c.current=e.every(t=>M(t,r,o)),c.current){return void(n||l())}let a=!0;return(async()=>{n&&l();const u=w(`fonts ${s}`);await Promise.all(e.map(e=>t.loadFont(e,r,o,i))),a?(d.current=u,c.current=!0,l()):u()})(),()=>{d.current&&(d.current(),d.current=null),a=!1}},[s,r,o]),n.useEffect(()=>{var t;c.current&&(null===(t=d.current)||void 0===t||t.call(d),d.current=null)},[c.current]),[c.current]};export const getLineHeight=({fontLoaded:t,fontFamily:e,fontSize:r,lineHeight:o})=>n.useMemo(()=>X({fontFamily:e,fontSize:r,lineHeight:o}),[t,e,r,o]);export function usePrevious(t){const e=n.useRef(t),r=n.useRef(t);return n.useMemo(()=>{r.current=e.current,e.current=t},[t]),r.current}export{getCurvePath}from"@polotno/core/text-html";export const TextElement=a(({element:a,store:u})=>{const h=n.useRef(null),M=n.useRef(null),X=n.useRef(null),V=n.useRef([]),q=n.useRef(!0),[,K]=n.useReducer(t=>t+1,0),{editorEnabled:Q,selectAll:tt}=(t=>{const[e,r]=n.useState(!1),o=n.useRef(!1);return n.useEffect(()=>{var e=!0;return setTimeout(()=>{e&&(t._editModeEnabled&&(o.current=!0),r(!0),setTimeout(()=>{o.current=!1},50))},50),()=>{e=!1}},[]),{editorEnabled:e&&t._editModeEnabled,selectAll:o.current}})(a),[et,ot]=n.useState(!1),[nt,it]=n.useState(!1),at=n.useRef(a.a.height),lt=n.useRef(0),st=n.useRef(""),ct=n.useRef(0),dt=a.isSelected,ut=usePrevious(dt),{textVerticalResizeEnabled:ft}=A,ht=A.autoDeleteEmptyText,gt=usePrevious(a.fontFamily),[mt,pt]=n.useState([]),xt=a.backgroundEnabled||a.borderSize>0;n.useLayoutEffect(()=>{var t,e;if(!xt){return}const r=null!==(e=null===(t=h.current)||void 0===t?void 0:t.textArr)&&void 0!==e?e:[];JSON.stringify(r)!==JSON.stringify(mt)&&pt(r)}),n.useEffect(()=>{if(a.a.width){return}const t=h.current;t.width(600),a.set({width:1.4*t.getTextWidth()})},[]),n.useEffect(()=>{ut&&!dt&&ht&&""===a.text&&a.removable&&!U(a.placeholder)&&u.deleteElements([a.id])},[ht,a.placeholder,a.removable,a.text,dt,ut]);const bt=()=>{if(a.curveEnabled){const t=h.current;null==t||t.clearCache(),null==t||t.setAttrs({filters:[]});const e=M.current;e&&N(e,a)}else{const t=h.current;t&&N(t,a)}};n.useLayoutEffect(()=>{if(!nt){return f(a,()=>{bt()})}}),n.useEffect(()=>{const t=V.current;t.length>0&&(V.current=[],t.forEach(t=>t()))}),n.useEffect(()=>()=>{q.current=!1;const t=V.current;t.length>0&&(V.current=[],t.forEach(t=>t()))},[]);let vt=H(a.text);"uppercase"===a.textTransform&&(vt=vt.toUpperCase());const[wt]=useFontLoader(u,a.fontFamily,a.fontStyle,a.fontWeight,a.text||a.placeholder),St=()=>{if(a.curveEnabled){const t=M.current;return t.getSelfRect().height||t.fontSize()}const t=h.current.clone({height:void 0}),e=Math.ceil(t.fontSize()*t.lineHeight()*t.textArr.length+1);return t.destroy(),e};n.useLayoutEffect(()=>{if(!wt){return}const t=C(L(a)),{textSplitAllowed:e}=A,r=(t,e,r,o)=>{const n=w(`text ${a.id}`),i=()=>{u.history.ignore(t,e,r).then(()=>{q.current?(V.current.push(n),K()):n()})};o?queueMicrotask(i):i()};if(!Z(a)){const t=St();return void r(()=>{Z(a)||a.set({height:t})},void 0,void 0,!0)}if(!u.isPlaying){if("change-font-size"!==t||et){if("resize"===t){const t=St();ft&&a.height<t&&!et&&r(()=>{var e;_(a)&&a.set({height:t}),null===(e=h.current)||void 0===e||e.height(t)},!1,!0),ft||a.height===t||et||r(()=>{var e;_(a)&&a.set({height:t}),null===(e=h.current)||void 0===e||e.height(t)},!1,!0)}}else{const t=h.current,o=a.curveEnabled?a.fontSize:function(t,e,r=!1){const o=t.fontSize(),n=t.height(),i=H(e.text);let a=e.a.fontSize;t.height(void 0);const l=Math.round(2*e.a.fontSize)-1;for(let s=1;s<l;s++){const o=Z(e.a)&&t.height()>e.a.height+T;let n=i.split("\n").join(" ").split(/[\s-]+/).reduce((t,e)=>(e=e.toLowerCase(),/[\u3000-\u303F\u3040-\u309F\u30A0-\u30FF\uFF00-\uFFEF\u4E00-\u9FAF\uAC00-\uD7AF]/.test(e)?t.concat(e.split("")):t.concat(e)),[]),l=t.textArr.map(t=>t.text.toLowerCase()).join(";");const s=n.find(t=>!l.includes(t)||(l=l.replace(t,""),!1));if(!(o||s&&!r)){break}a-=O,t.fontSize(a)}return t.fontSize(o),t.height(n),a}(t,a,e);if(o!==a.fontSize){return void r(()=>{a.set(y(a,o))},!1,!0)}const n=St();a.height===n||ft||r(()=>{a.set({height:n})},!1,!0)}}}),n.useLayoutEffect(()=>{var t;if(wt&&a.curveEnabled){const e=null===(t=M.current)||void 0===t?void 0:t.getSelfRect().width;if(e){const t=e-a.a.width,r=a.a.rotation*Math.PI/180,o=-t/2*Math.cos(r),n=-t/2*Math.sin(r);a.set({width:e,x:a.a.x+o,y:a.a.y+n})}}},[wt,a.curveEnabled,a.curvePower,a.text,a.fontSize,a.fontFamily,a.fontWeight,a.fontStyle,a.letterSpacing]),n.useLayoutEffect(()=>{const t=h.current;t&&(t.width(t.width()+1e-8),t.width(t.width()-1e-8),t._setTextData(),bt())},[wt]);const yt=n.useRef(null),Et=n.useRef(a.width),zt=n.useRef(0),kt=t=>{t.evt.preventDefault();const e=u.selectedShapes.find(t=>t===a);e&&a.contentEditable&&(zt.current=function(t){var e;const r=t.target,o=function(t){var e=t.getAbsoluteTransform().copy();e.invert();var r=t.getStage().getPointerPosition();return e.point(r)}(r),n=r.textArr,i=Math.floor(o.y/(r.fontSize()*r.lineHeight())),a=n.slice(0,i).reduce((t,e)=>t+e.text.length,i),l=null!==(e=n[i])&&void 0!==e?e:n[0];let s=0;return"right"===r.align()?s=r.width()-l.width:"center"===r.align()&&(s=r.width()/2-l.width/2),a+Math.round((o.x-s)/l.width*l.text.length)}(t),a.toggleEditMode())},Rt=U(a.placeholder),Ft=!vt&&Rt?.6:o(a);B(h,Ft);const jt=getLineHeight({fontLoaded:wt,fontFamily:a.fontFamily,fontSize:a.a.fontSize,lineHeight:a.lineHeight}),Mt=a.selectable||u.role===v.ADMIN,At=b(a),Lt=b(a,a.stroke,"stroke"),Ot=n.useMemo(()=>a.backgroundEnabled||a.borderSize?a.curveEnabled?function({width:t,height:e,padding:r=0,cornerRadius:o=0}){const n=-r,i=-r,a=t+r,l=e+r,s=g(`M ${n} ${i} L ${a} ${i} L ${a} ${l} L ${n} ${l} Z`);return m(s,o).path}({width:a.a.width,height:a.a.height,cornerRadius:a.backgroundCornerRadius*(a.a.fontSize*jt*.5),padding:a.backgroundPadding*(a.a.fontSize*jt*.5)}):function({lines:t,lineHeight:e,width:r,align:o="left",padding:n=0,cornerRadius:i=0}){const a=x({lines:t,lineHeight:e,width:r,align:o});return p({rects:a,padding:n,cornerRadius:i})}({lines:JSON.parse(JSON.stringify(mt)),cornerRadius:a.backgroundCornerRadius*(a.a.fontSize*jt*.5),lineHeight:jt*a.a.fontSize,padding:a.backgroundPadding*(a.a.fontSize*jt*.5),width:a.a.width,align:a.align}):"",[a.backgroundEnabled,a.borderSize,a.curveEnabled,a.backgroundCornerRadius,a.a.fontSize,a.a.height,jt,a.backgroundPadding,a.a.width,a.align,mt]),Tt=I();let Ct=0;if(!a.curveEnabled){const t=mt.length*jt*a.a.fontSize,e=G(a.a,t);"middle"===a.verticalAlign?Ct=(e-t)/2:"bottom"===a.verticalAlign&&(Ct=e-t)}const Ht=a.curveEnabled?W(a.a.width,a.a.height,a.curvePower,a.a.fontSize):"",Pt=wt?Y(a.fontFamily):gt===a.fontFamily?"Arial":Y(gt),Wt=P(vt),Xt=a.shadowEnabled&&!$(a),Dt={shadowEnabled:a.shadowEnabled&&($(a)||a.borderSize>0),shadowBlur:a.shadowBlur,shadowOffsetX:a.shadowOffsetX,shadowOffsetY:a.shadowOffsetY,shadowColor:i(a.shadowColor),shadowOpacity:a.shadowOpacity};return r(t,{children:[xt&&e(s,Object.assign({ref:X,x:a.a.x,y:a.a.y,rotation:a.a.rotation,hideInExport:!a.showInExport,listening:!1,opacity:Ft,data:Ot,fillEnabled:a.backgroundEnabled,fill:J(a.backgroundColor,a.backgroundOpacity),strokeEnabled:a.borderSize>0,stroke:i(a.borderColor),strokeWidth:a.borderSize,lineJoin:a.backgroundCornerRadius>0?"round":"miter",offsetY:-Ct},Dt)),a.curveEnabled&&e(d,Object.assign({ref:M,data:Ht,text:vt||Rt,listening:!1,align:"center",textBaseline:"middle",direction:Wt},At,Lt,{strokeWidth:a.strokeWidth,lineJoin:D(a.strokeLineJoin),fillAfterStrokeEnabled:!0,fontSize:a.a.fontSize,fontFamily:`${Y(a.fontFamily)}, ${Y(gt)}`,fontStyle:a.fontStyle+" "+a.fontWeight,textDecoration:a.textDecoration.trim(),letterSpacing:a.letterSpacing*a.a.fontSize,x:a.a.x,y:a.a.y,rotation:a.a.rotation,opacity:a._editModeEnabled?.3:Ft,hideInExport:!a.showInExport},Dt,{shadowEnabled:Xt})),e(c,Object.assign({ref:h,id:a.selectable?a.id:void 0,name:a.selectable?"element":"",hideInExport:!a.showInExport,editModeEnabled:a._editModeEnabled,x:a.a.x,y:a.a.y,rotation:a.a.rotation,width:a.a.width,height:Z(a.a)?a.a.height:void 0,text:vt||Rt,direction:Wt},At,Lt,{lineJoin:D(a.strokeLineJoin),strokeWidth:a.strokeWidth,fillAfterStrokeEnabled:!0,fontSize:a.a.fontSize,fontFamily:Pt,fontStyle:a.fontStyle+" "+a.fontWeight,textDecoration:a.textDecoration,align:a.align,verticalAlign:a.verticalAlign,draggable:Tt?a.draggable&&dt:a.draggable,preventDefault:!Tt||dt,opacity:a.curveEnabled?0:Ft,visible:!a._editModeEnabled,ellipsis:"ellipsis"===L(a)},Dt,{shadowEnabled:Xt,lineHeight:jt,letterSpacing:a.letterSpacing*a.a.fontSize,listening:!!a.selectable&&Mt,onDragStart:()=>{it(!0)},onDragMove:t=>{a.set({x:t.target.x(),y:t.target.y()})},onDragEnd:t=>{it(!1),a.set(R(t.target))},onClick:kt,onTap:kt,onTransformStart:()=>{ot(!0);const t=h.current;at.current=t.height(),Et.current=a.a.width,yt.current=t.position(),lt.current=t.rotation(),ct.current=t.height(),st.current=S(t)},onTransform:t=>{var e,r;const o=t.target;null===(e=X.current)||void 0===e||e.setAttrs({x:o.x(),y:o.y(),rotation:o.rotation(),scale:o.scale()});const n=st.current;if("middle-left"===n||"middle-right"===n){const t=o.scaleX(),e=o.width()*t,r=F(Et.current,a.a.fontSize);let n=e;e<r&&(n=r,yt.current&&o.position(yt.current)),o.width(n),o.scaleX(1),o.scaleY(1);let i=St();if("ellipsis"===L(a)){i=at.current}else{const t=Math.max(i,at.current);o.height(t),a.set({height:o.height()})}const l=A.textVerticalResizeEnabled?Math.max(i,at.current):St();a.set({x:o.x(),width:o.width(),rotation:o.rotation(),height:l}),o.skewX(0),o.skewY(0),bt()}if("top-center"===n||"bottom-center"===n){const e="resize"===L(a)?St():jt*a.a.fontSize,r=t.target.height()*t.target.scaleY();if(r<e){if(t.target.height(e),yt.current){if("top-center"===st.current){const r=lt.current*Math.PI/180,o=ct.current-e;t.target.x(yt.current.x-o*Math.sin(r)),t.target.y(yt.current.y+o*Math.cos(r))}else{t.target.position(yt.current)}}}else{t.target.height(r)}t.target.scaleY(1),t.target.scaleX(1),t.target.rotation(lt.current),t.target.skewX(0),t.target.skewY(0),ct.current=Math.max(e,r)}yt.current=t.target.position();const i=j(t.target.scaleX());null===(r=X.current)||void 0===r||r.setAttrs({scaleX:1,scaleY:1}),t.target.scaleX(1),t.target.scaleY(1),a.set({fontSize:a.a.fontSize*i,width:t.target.width()*i,x:t.target.x(),y:t.target.y(),rotation:t.target.rotation(),height:t.target.height()*i,shadowBlur:a.shadowBlur*i,shadowOffsetX:a.shadowOffsetX*i,shadowOffsetY:a.shadowOffsetY*i,strokeWidth:a.strokeWidth*i,borderSize:a.borderSize*i})},onTransformEnd:t=>{var e;const r=j(t.target.scaleX());t.target.scaleX(1),t.target.scaleY(1),a.set(Object.assign(Object.assign({},E(a,a.fontSize*r)),{width:Math.ceil(t.target.width()*r),x:k(t.target.x()),y:k(t.target.y()),rotation:k(t.target.rotation()),height:k(t.target.height()*r)})),null===(e=X.current)||void 0===e||e.setAttrs({scaleX:1,scaleY:1}),ot(!1)}})),Q&&a.contentEditable&&e(l,{x:a.a.x,y:a.a.y,rotation:a.a.rotation,children:e(rt,{textNodeRef:h,element:a,selectAll:tt,cursorPosition:zt.current,onBlur:()=>{a.set(z(a)),a.toggleEditMode(!1)}})})]})});
1
+ import{Fragment as t,jsx as e,jsxs as r}from"react/jsx-runtime";import{elementOpacity as o}from"./paint-opacity.js";import n from"react";import{toDisplayColor as i}from"@polotno/core/color";import{observer as a}from"mobx-react-lite";import{Group as l,Path as s,Text as c,TextPath as d}from"react-konva";import{Html as u}from"react-konva-utils";import{nodeAutorun as f}from"../utils/mobx.js";import h from"konva";import{parsePath as g,roundCommands as p}from"svg-round-corners/lib/index.js";import{generateBackgroundShapeFromRects as m,textLinesToRects as x}from"@polotno/core/background-shape";import{useColor as b}from"./use-color.js";import{ROLES as S}from"../model/store.js";import{incrementLoader as v}from"../utils/loader.js";import{activeAnchorOf as w,scaledFontSizeAttrs as y,roundedFontSizeAttrs as E,roundedTextDecorationAttrs as z,roundedGeometryPx as k,roundedPosition as R,textMinResizeWidth as F,transformScale as j}from"../utils/px.js";import{isFontLoaded as M}from"../utils/fonts.js";import{flags as A}from"../utils/flags.js";import{textOverflowOf as L}from"../utils/text-sizing.js";import{FIT_FONT_SIZE_STEP as O,FIT_HEIGHT_EPSILON as T,legacyTextOverflow as C}from"@polotno/core/text-sizing";import{removeTags as H}from"@polotno/core/text";import{getDir as P,getCurvePath as W,resolveLineHeight as X,normalizeStrokeLineJoin as D}from"@polotno/core/text-html";import{cssFontFamily as Y}from"@polotno/core/fonts";import{shadowCastByBackground as $}from"@polotno/core/filters";import{applyOpacityToColor as J}from"@polotno/core/svg";import{applyFilter as N}from"./apply-filters.js";import{useFadeIn as B}from"./use-fadein.js";import{isTouchDevice as I}from"../utils/screen.js";import{isAlive as _}from"mobx-state-tree";import{getLimitedFontSize as V}from"./text-element/max-font-size.js";import{getOptimalCaretColor as q}from"./text-element/caret-color.js";import{visiblePlaceholder as U}from"./text-element/placeholder.js";import{useLegacyPaddingWarning as Z}from"./text-element/legacy-padding-warning.js";import{hasMeasuredHeight as G,resolveTextBoxHeight as K}from"@polotno/core/text-types";let Q;function tt(){return Q||(Q=document.getElementById("polotno-text-style"),Q||(Q=document.createElement("style"),Q.id="polotno-text-style",document.head.appendChild(Q)),Q)}h._fixTextRendering=!0;const et={border:"none",padding:"0px",overflow:"hidden",background:"none",outline:"none",resize:"none",overflowWrap:"break-word",whiteSpace:"pre-wrap",userSelect:"text",wordBreak:"normal",textTransform:"none"};export{getDir}from"@polotno/core/text-html";const rt=a(({textNodeRef:t,element:r,onBlur:o,selectAll:i,cursorPosition:a})=>{const[l,s]=n.useState(et),c=t.current;n.useLayoutEffect(()=>{if(!c){return}const t={};t.width=c.width()-2*c.padding()+"px",t.height=c.height()-2*c.padding()+c.fontSize()*c.lineHeight()+"px",t.fontSize=c.fontSize()+"px",t.lineHeight=c.lineHeight()+.01,t.fontFamily=c.fontFamily(),t.textAlign=c.align(),t.color=c.fill(),t.fontWeight=r.fontWeight,t.fontStyle=r.fontStyle,t.letterSpacing=r.letterSpacing+"em",t.opacity=Math.max(r.a.opacity,.2),t.textTransform=r.textTransform,t.caretColor=q(r);const e=`\n .polotno-input::placeholder {\n color: ${l.color};\n opacity: 0.6;\n }\n `,o=tt();o.innerHTML="",o.appendChild(document.createTextNode(e)),JSON.stringify(t)!==JSON.stringify(l)&&s(t)});const d=n.useRef(null);if(n.useLayoutEffect(()=>{var t;const e=d.current;if(!e){return}null===(t=d.current)||void 0===t||t.focus({preventScroll:!0});const r=a||e.value.length;e.selectionStart=e.selectionEnd=r,i&&e.setSelectionRange(0,e.value.length)},[]),n.useEffect(()=>{window.addEventListener("blur",o);const t=t=>{var e;(null===(e=d.current)||void 0===e?void 0:e.contains(t.target))||o()};return window.addEventListener("touchstart",t),()=>{window.removeEventListener("blur",o),window.removeEventListener("touchstart",t)}},[]),!c){return null}let u=0;const f=c.textArr.length*c.lineHeight()*c.fontSize(),h=K(r.a,f);"middle"===r.verticalAlign&&(u=(h-f)/2),"bottom"===r.verticalAlign&&(u=h-f);const g=H(r.text);return e("textarea",{className:"polotno-input",ref:d,dir:P(g),style:Object.assign(Object.assign(Object.assign({},et),l),{paddingTop:u+"px"}),value:g,onChange:t=>{const e=V({oldText:r.text,newText:t.target.value,element:r});r.set(Object.assign({text:t.target.value},y(r,e)))},placeholder:U(r.placeholder),onBlur:o})}),ot=t=>e(u,{children:e(rt,Object.assign({},t))});export const useFontLoader=(t,e,r,o,n)=>useFontFamiliesLoader(t,[e],r,o,n);export const useFontFamiliesLoader=(t,e,r,o,i)=>{const[a,l]=n.useReducer(t=>t+1,0),s=e.join("\0"),c=n.useRef(e.every(t=>M(t,r,o))),d=n.useRef(null);return n.useLayoutEffect(()=>{const n=c.current;if(c.current=e.every(t=>M(t,r,o)),c.current){return void(n||l())}let a=!0;return(async()=>{n&&l();const u=v(`fonts ${s}`);await Promise.all(e.map(e=>t.loadFont(e,r,o,i))),a?(d.current=u,c.current=!0,l()):u()})(),()=>{d.current&&(d.current(),d.current=null),a=!1}},[s,r,o]),n.useEffect(()=>{var t;c.current&&(null===(t=d.current)||void 0===t||t.call(d),d.current=null)},[c.current]),[c.current]};export const getLineHeight=({fontLoaded:t,fontFamily:e,fontSize:r,lineHeight:o})=>n.useMemo(()=>X({fontFamily:e,fontSize:r,lineHeight:o}),[t,e,r,o]);export function usePrevious(t){const e=n.useRef(t),r=n.useRef(t);return n.useMemo(()=>{r.current=e.current,e.current=t},[t]),r.current}export{getCurvePath}from"@polotno/core/text-html";export const TextElement=a(({element:a,store:u})=>{Z(a);const h=n.useRef(null),M=n.useRef(null),X=n.useRef(null),V=n.useRef([]),q=n.useRef(!0),[,Q]=n.useReducer(t=>t+1,0),{editorEnabled:tt,selectAll:et}=(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),[rt,nt]=n.useState(!1),[it,at]=n.useState(!1),lt=n.useRef(a.a.height),st=n.useRef(0),ct=n.useRef(""),dt=n.useRef(0),ut=a.isSelected,ft=usePrevious(ut),{textVerticalResizeEnabled:ht}=A,gt=A.autoDeleteEmptyText,pt=usePrevious(a.fontFamily),[mt,xt]=n.useState([]),bt=a.backgroundEnabled||a.borderSize>0;n.useLayoutEffect(()=>{var t,e;if(!bt){return}const r=null!==(e=null===(t=h.current)||void 0===t?void 0:t.textArr)&&void 0!==e?e:[];JSON.stringify(r)!==JSON.stringify(mt)&&xt(r)}),n.useEffect(()=>{if(a.a.width){return}const t=h.current;t.width(600),a.set({width:1.4*t.getTextWidth()})},[]),n.useEffect(()=>{ft&&!ut&&gt&&""===a.text&&a.removable&&!U(a.placeholder)&&u.deleteElements([a.id])},[gt,a.placeholder,a.removable,a.text,ut,ft]);const St=()=>{if(a.curveEnabled){const t=h.current;null==t||t.clearCache(),null==t||t.setAttrs({filters:[]});const e=M.current;e&&N(e,a)}else{const t=h.current;t&&N(t,a)}};n.useLayoutEffect(()=>{if(!it){return f(a,()=>{St()})}}),n.useEffect(()=>{const t=V.current;t.length>0&&(V.current=[],t.forEach(t=>t()))}),n.useEffect(()=>()=>{q.current=!1;const t=V.current;t.length>0&&(V.current=[],t.forEach(t=>t()))},[]);let vt=H(a.text);"uppercase"===a.textTransform&&(vt=vt.toUpperCase());const[wt]=useFontLoader(u,a.fontFamily,a.fontStyle,a.fontWeight,a.text||a.placeholder),yt=()=>{if(a.curveEnabled){const t=M.current;return t.getSelfRect().height||t.fontSize()}const t=h.current.clone({height:void 0}),e=Math.ceil(t.fontSize()*t.lineHeight()*t.textArr.length+1);return t.destroy(),e};n.useLayoutEffect(()=>{if(!wt){return}const t=C(L(a)),{textSplitAllowed:e}=A,r=(t,e,r,o)=>{const n=v(`text ${a.id}`),i=()=>{u.history.ignore(t,e,r).then(()=>{q.current?(V.current.push(n),Q()):n()})};o?queueMicrotask(i):i()};if(!G(a)){const t=yt();return void r(()=>{G(a)||a.set({height:t})},void 0,void 0,!0)}if(!u.isPlaying){if("change-font-size"!==t||rt){if("resize"===t){const t=yt();ht&&a.height<t&&!rt&&r(()=>{var e;_(a)&&a.set({height:t}),null===(e=h.current)||void 0===e||e.height(t)},!1,!0),ht||a.height===t||rt||r(()=>{var e;_(a)&&a.set({height:t}),null===(e=h.current)||void 0===e||e.height(t)},!1,!0)}}else{const t=h.current,o=a.curveEnabled?a.fontSize:function(t,e,r=!1){const o=t.fontSize(),n=t.height(),i=H(e.text);let a=e.a.fontSize;t.height(void 0);const l=Math.round(2*e.a.fontSize)-1;for(let s=1;s<l;s++){const o=G(e.a)&&t.height()>e.a.height+T;let n=i.split("\n").join(" ").split(/[\s-]+/).reduce((t,e)=>(e=e.toLowerCase(),/[\u3000-\u303F\u3040-\u309F\u30A0-\u30FF\uFF00-\uFFEF\u4E00-\u9FAF\uAC00-\uD7AF]/.test(e)?t.concat(e.split("")):t.concat(e)),[]),l=t.textArr.map(t=>t.text.toLowerCase()).join(";");const s=n.find(t=>!l.includes(t)||(l=l.replace(t,""),!1));if(!(o||s&&!r)){break}a-=O,t.fontSize(a)}return t.fontSize(o),t.height(n),a}(t,a,e);if(o!==a.fontSize){return void r(()=>{a.set(y(a,o))},!1,!0)}const n=yt();a.height===n||ht||r(()=>{a.set({height:n})},!1,!0)}}}),n.useLayoutEffect(()=>{var t;if(wt&&a.curveEnabled){const e=null===(t=M.current)||void 0===t?void 0:t.getSelfRect().width;if(e){const t=e-a.a.width,r=a.a.rotation*Math.PI/180,o=-t/2*Math.cos(r),n=-t/2*Math.sin(r);a.set({width:e,x:a.a.x+o,y:a.a.y+n})}}},[wt,a.curveEnabled,a.curvePower,a.text,a.fontSize,a.fontFamily,a.fontWeight,a.fontStyle,a.letterSpacing]),n.useLayoutEffect(()=>{const t=h.current;t&&(t.width(t.width()+1e-8),t.width(t.width()-1e-8),t._setTextData(),St())},[wt]);const Et=n.useRef(null),zt=n.useRef(a.width),kt=n.useRef(0),Rt=t=>{t.evt.preventDefault();const e=u.selectedShapes.find(t=>t===a);e&&a.contentEditable&&(kt.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())},Ft=U(a.placeholder),jt=!vt&&Ft?.6:o(a);B(h,jt);const Mt=getLineHeight({fontLoaded:wt,fontFamily:a.fontFamily,fontSize:a.a.fontSize,lineHeight:a.lineHeight}),At=a.selectable||u.role===S.ADMIN,Lt=b(a),Ot=b(a,a.stroke,"stroke"),Tt=n.useMemo(()=>a.backgroundEnabled||a.borderSize?a.curveEnabled||"box"===a.backgroundShape?function({width:t,height:e,padding:r=0,cornerRadius:o=0}){const n=-r,i=-r,a=t+r,l=e+r,s=g(`M ${n} ${i} L ${a} ${i} L ${a} ${l} L ${n} ${l} Z`);return p(s,o).path}({width:a.a.width,height:a.a.height,cornerRadius:a.backgroundCornerRadius*(a.a.fontSize*Mt*.5),padding:a.backgroundPadding*(a.a.fontSize*Mt*.5)}):function({lines:t,lineHeight:e,width:r,align:o="left",padding:n=0,cornerRadius:i=0}){const a=x({lines:t,lineHeight:e,width:r,align:o});return m({rects:a,padding:n,cornerRadius:i})}({lines:JSON.parse(JSON.stringify(mt)),cornerRadius:a.backgroundCornerRadius*(a.a.fontSize*Mt*.5),lineHeight:Mt*a.a.fontSize,padding:a.backgroundPadding*(a.a.fontSize*Mt*.5),width:a.a.width,align:a.align}):"",[a.backgroundEnabled,a.borderSize,a.curveEnabled,a.backgroundShape,a.backgroundCornerRadius,a.a.fontSize,a.a.height,Mt,a.backgroundPadding,a.a.width,a.align,mt]),Ct=I();let Ht=0;if(!a.curveEnabled&&"box"!==a.backgroundShape){const t=mt.length*Mt*a.a.fontSize,e=K(a.a,t);"middle"===a.verticalAlign?Ht=(e-t)/2:"bottom"===a.verticalAlign&&(Ht=e-t)}const Pt=a.curveEnabled?W(a.a.width,a.a.height,a.curvePower,a.a.fontSize):"",Wt=wt?Y(a.fontFamily):pt===a.fontFamily?"Arial":Y(pt),Xt=P(vt),Dt=a.shadowEnabled&&!$(a),Yt={shadowEnabled:a.shadowEnabled&&($(a)||a.borderSize>0),shadowBlur:a.shadowBlur,shadowOffsetX:a.shadowOffsetX,shadowOffsetY:a.shadowOffsetY,shadowColor:i(a.shadowColor),shadowOpacity:a.shadowOpacity};return r(t,{children:[bt&&e(s,Object.assign({ref:X,x:a.a.x,y:a.a.y,rotation:a.a.rotation,hideInExport:!a.showInExport,listening:!1,opacity:jt,data:Tt,fillEnabled:a.backgroundEnabled,fill:J(a.backgroundColor,a.backgroundOpacity),strokeEnabled:a.borderSize>0,stroke:i(a.borderColor),strokeWidth:a.borderSize,lineJoin:a.backgroundCornerRadius>0?"round":"miter",offsetY:-Ht},Yt)),a.curveEnabled&&e(d,Object.assign({ref:M,data:Pt,text:vt||Ft,listening:!1,align:"center",textBaseline:"middle",direction:Xt},Lt,Ot,{strokeWidth:a.strokeWidth,lineJoin:D(a.strokeLineJoin),fillAfterStrokeEnabled:!0,fontSize:a.a.fontSize,fontFamily:`${Y(a.fontFamily)}, ${Y(pt)}`,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:jt,hideInExport:!a.showInExport},Yt,{shadowEnabled:Dt})),e(c,Object.assign({ref:h,id:a.selectable?a.id:void 0,name:a.selectable?"element":"",hideInExport:!a.showInExport,editModeEnabled:a._editModeEnabled,x:a.a.x,y:a.a.y,rotation:a.a.rotation,width:a.a.width,height:G(a.a)?a.a.height:void 0,text:vt||Ft,direction:Xt},Lt,Ot,{lineJoin:D(a.strokeLineJoin),strokeWidth:a.strokeWidth,fillAfterStrokeEnabled:!0,fontSize:a.a.fontSize,fontFamily:Wt,fontStyle:a.fontStyle+" "+a.fontWeight,textDecoration:a.textDecoration,align:a.align,verticalAlign:a.verticalAlign,draggable:Ct?a.draggable&&ut:a.draggable,preventDefault:!Ct||ut,opacity:a.curveEnabled?0:jt,visible:!a._editModeEnabled,ellipsis:"ellipsis"===L(a)},Yt,{shadowEnabled:Dt,lineHeight:Mt,letterSpacing:a.letterSpacing*a.a.fontSize,listening:!!a.selectable&&At,onDragStart:()=>{at(!0)},onDragMove:t=>{a.set({x:t.target.x(),y:t.target.y()})},onDragEnd:t=>{at(!1),a.set(R(t.target))},onClick:Rt,onTap:Rt,onTransformStart:()=>{nt(!0);const t=h.current;lt.current=t.height(),zt.current=a.a.width,Et.current=t.position(),st.current=t.rotation(),dt.current=t.height(),ct.current=w(t)},onTransform:t=>{var e,r;const o=t.target;null===(e=X.current)||void 0===e||e.setAttrs({x:o.x(),y:o.y(),rotation:o.rotation(),scale:o.scale()});const n=ct.current;if("middle-left"===n||"middle-right"===n){const t=o.scaleX(),e=o.width()*t,r=F(zt.current,a.a.fontSize);let n=e;e<r&&(n=r,Et.current&&o.position(Et.current)),o.width(n),o.scaleX(1),o.scaleY(1);let i=yt();if("ellipsis"===L(a)){i=lt.current}else{const t=Math.max(i,lt.current);o.height(t),a.set({height:o.height()})}const l=A.textVerticalResizeEnabled?Math.max(i,lt.current):yt();a.set({x:o.x(),width:o.width(),rotation:o.rotation(),height:l}),o.skewX(0),o.skewY(0),St()}if("top-center"===n||"bottom-center"===n){const e="resize"===L(a)?yt():Mt*a.a.fontSize,r=t.target.height()*t.target.scaleY();if(r<e){if(t.target.height(e),Et.current){if("top-center"===ct.current){const r=st.current*Math.PI/180,o=dt.current-e;t.target.x(Et.current.x-o*Math.sin(r)),t.target.y(Et.current.y+o*Math.cos(r))}else{t.target.position(Et.current)}}}else{t.target.height(r)}t.target.scaleY(1),t.target.scaleX(1),t.target.rotation(st.current),t.target.skewX(0),t.target.skewY(0),dt.current=Math.max(e,r)}Et.current=t.target.position();const i=j(t.target.scaleX());null===(r=X.current)||void 0===r||r.setAttrs({scaleX:1,scaleY:1}),t.target.scaleX(1),t.target.scaleY(1),a.set({fontSize:a.a.fontSize*i,width:t.target.width()*i,x:t.target.x(),y:t.target.y(),rotation:t.target.rotation(),height:t.target.height()*i,shadowBlur:a.shadowBlur*i,shadowOffsetX:a.shadowOffsetX*i,shadowOffsetY:a.shadowOffsetY*i,strokeWidth:a.strokeWidth*i,borderSize:a.borderSize*i})},onTransformEnd:t=>{var e;const r=j(t.target.scaleX());t.target.scaleX(1),t.target.scaleY(1),a.set(Object.assign(Object.assign({},E(a,a.fontSize*r)),{width:Math.ceil(t.target.width()*r),x:k(t.target.x()),y:k(t.target.y()),rotation:k(t.target.rotation()),height:k(t.target.height()*r)})),null===(e=X.current)||void 0===e||e.setAttrs({scaleX:1,scaleY:1}),nt(!1)}})),tt&&a.contentEditable&&e(l,{x:a.a.x,y:a.a.y,rotation:a.a.rotation,children:e(ot,{textNodeRef:h,element:a,selectAll:et,cursorPosition:kt.current,onBlur:()=>{a.set(z(a)),a.toggleEditMode(!1)}})})]})});
@@ -5,10 +5,32 @@ type ColorElement = {
5
5
  width: number;
6
6
  height: number;
7
7
  fill?: string;
8
+ strokeWidth?: number;
8
9
  };
9
10
  export declare const withDisplayTextPaints: (element: TextElementLike) => TextElementLike;
10
- export declare const useColor: (element: ColorElement, value?: string, propName?: string) => {
11
- [x: string]: string;
11
+ export declare const useColor: (element: ColorElement, value?: string, propName?: string, strokeReach?: number) => {
12
+ fillRadialGradientStartPointX: number;
13
+ fillRadialGradientStartPointY: number;
14
+ fillRadialGradientStartRadius: number;
15
+ fillRadialGradientEndPointX: number;
16
+ fillRadialGradientEndPointY: number;
17
+ fillRadialGradientEndRadius: number;
18
+ fillRadialGradientColorStops: (string | number)[];
19
+ fill: string;
20
+ fillPriority: string;
21
+ fillRadialGradientScaleY?: number | undefined;
22
+ fillLinearGradientStartPointX?: undefined;
23
+ fillLinearGradientStartPointY?: undefined;
24
+ fillLinearGradientColorStops?: undefined;
25
+ fillLinearGradientEndPointX?: undefined;
26
+ fillLinearGradientEndPointY?: undefined;
27
+ strokeLinearGradientStartPointX?: undefined;
28
+ strokeLinearGradientStartPointY?: undefined;
29
+ strokeLinearGradientColorStops?: undefined;
30
+ strokeLinearGradientEndPointX?: undefined;
31
+ strokeLinearGradientEndPointY?: undefined;
32
+ } | {
33
+ [x: string]: string | CanvasGradient | CanvasPattern;
12
34
  fillLinearGradientStartPointX?: undefined;
13
35
  fillLinearGradientStartPointY?: undefined;
14
36
  fillLinearGradientColorStops?: undefined;
@@ -1 +1 @@
1
- import t from"react";import*as i from"@polotno/core/gradient";import{toDisplayColor as o}from"@polotno/core/color";const r=Object.keys({id:!0,text:!0,width:!0,height:!0,fontSize:!0,fontFamily:!0,fontWeight:!0,fontStyle:!0,lineHeight:!0,letterSpacing:!0,textTransform:!0,textDecoration:!0,align:!0,fill:!0,stroke:!0,strokeWidth:!0,strokeLineJoin:!0,curveEnabled:!0,curvePower:!0,shadowBlur:!0,shadowOffsetX:!0,shadowOffsetY:!0,textOverflow:!0,maxLines:!0,minFontSize:!0,maxFontSize:!0,a:!0});export const withDisplayTextPaints=t=>{const i={};for(const e of r){e in t&&(i[e]="fill"===e||"stroke"===e?o(t[e]):t[e])}return i};export const useColor=(r,e,n)=>{var a;return void 0===e&&(e=null!==(a=r.fill)&&void 0!==a?a:""),void 0===n&&(n="fill"),t.useMemo(()=>{if(!i.isGradient(e)){return{[n]:o(e)}}const{stops:t,rotation:a}=i.parseColor(e),{start:l,end:s}=i.canvasGradientPoints(a,r.a.width,r.a.height),d=[];return t.forEach(({offset:t,color:i})=>{d.push(t,i)}),"fill"===n?{fillLinearGradientStartPointX:l.x,fillLinearGradientStartPointY:l.y,fillLinearGradientColorStops:d,fillLinearGradientEndPointX:s.x,fillLinearGradientEndPointY:s.y,fill:t[1].color,fillPriority:"linear-gradient"}:{strokeLinearGradientStartPointX:l.x,strokeLinearGradientStartPointY:l.y,strokeLinearGradientColorStops:d,strokeLinearGradientEndPointX:s.x,strokeLinearGradientEndPointY:s.y}},[e,r.width,r.height])};
1
+ import t from"react";import*as i from"@polotno/core/gradient";import{toDisplayColor as o}from"@polotno/core/color";import r from"konva";const e=Object.keys({id:!0,text:!0,width:!0,height:!0,fontSize:!0,fontFamily:!0,fontWeight:!0,fontStyle:!0,lineHeight:!0,letterSpacing:!0,textTransform:!0,textDecoration:!0,align:!0,fill:!0,stroke:!0,strokeWidth:!0,strokeLineJoin:!0,curveEnabled:!0,curvePower:!0,shadowBlur:!0,shadowOffsetX:!0,shadowOffsetY:!0,textOverflow:!0,maxLines:!0,minFontSize:!0,maxFontSize:!0,paddingTop:!0,paddingRight:!0,paddingBottom:!0,paddingLeft:!0,a:!0});export const withDisplayTextPaints=t=>{const i={};for(const r of e){r in t&&(i[r]="fill"===r||"stroke"===r?o(t[r]):t[r])}return i};let n=null;const a=(t,o,e)=>(null!=n||(n=r.Util.createCanvasElement().getContext("2d")),i.radialStrokePaint(n,t,o,e,(t,i)=>{const o=r.Util.createCanvasElement();return o.width=t,o.height=i,o}));export const useColor=(r,e,n,l)=>{var d,s;return void 0===e&&(e=null!==(d=r.fill)&&void 0!==d?d:""),void 0===n&&(n="fill"),void 0===l&&(l=null!==(s=r.strokeWidth)&&void 0!==s?s:0),t.useMemo(()=>{var t,d,s;if(!i.isGradient(e)){return{[n]:o(e)}}const f=i.radialGradientGeometry(e,{width:r.a.width,height:r.a.height});if(f){return null!==f.solid?{[n]:f.solid}:"fill"===n?Object.assign({fillRadialGradientStartPointX:f.cx,fillRadialGradientStartPointY:f.cy,fillRadialGradientStartRadius:0,fillRadialGradientEndPointX:f.cx,fillRadialGradientEndPointY:f.cy,fillRadialGradientEndRadius:f.rx,fillRadialGradientColorStops:f.stops.flatMap(({offset:t,color:i})=>[t,i]),fill:null!==(s=null===(t=f.stops[1])||void 0===t?void 0:t.color)&&void 0!==s?s:null===(d=f.stops[0])||void 0===d?void 0:d.color,fillPriority:"radial-gradient"},f.ry!==f.rx&&{fillRadialGradientScaleY:f.ry/f.rx}):{[n]:a(f,{width:r.a.width,height:r.a.height},l)}}const{stops:h,rotation:c}=i.parseColor(e),{start:p,end:g}=i.canvasGradientPoints(c,r.a.width,r.a.height),u=[];return h.forEach(({offset:t,color:i})=>{u.push(t,i)}),"fill"===n?{fillLinearGradientStartPointX:p.x,fillLinearGradientStartPointY:p.y,fillLinearGradientColorStops:u,fillLinearGradientEndPointX:g.x,fillLinearGradientEndPointY:g.y,fill:h[1].color,fillPriority:"linear-gradient"}:{strokeLinearGradientStartPointX:p.x,strokeLinearGradientStartPointY:p.y,strokeLinearGradientColorStops:u,strokeLinearGradientEndPointX:g.x,strokeLinearGradientEndPointY:g.y}},[e,r.width,r.height,l])};
@@ -90,6 +90,7 @@ declare const defaults: {
90
90
  'toolbar.zoomIn': import("lucide-react").LucideIcon;
91
91
  'toolbar.zoomOut': import("lucide-react").LucideIcon;
92
92
  'toolbar.crop': import("lucide-react").LucideIcon;
93
+ 'toolbar.paddingSides': import("lucide-react").LucideIcon;
93
94
  'imageEdit.ai': import("lucide-react").LucideIcon;
94
95
  'colorPicker.reverseGradient': import("lucide-react").LucideIcon;
95
96
  'download.export': import("lucide-react").LucideIcon;
package/icons/registry.js CHANGED
@@ -1 +1 @@
1
- var t=this&&this.__rest||function(t,i){var e={};for(var o in t){Object.prototype.hasOwnProperty.call(t,o)&&i.indexOf(o)<0&&(e[o]=t[o])}if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(o=Object.getOwnPropertySymbols(t);n<o.length;n++){i.indexOf(o[n])<0&&Object.prototype.propertyIsEnumerable.call(t,o[n])&&(e[o[n]]=t[o[n]])}}return e};import{jsx as i}from"react/jsx-runtime";import{observable as e,action as o}from"mobx";import{observer as n}from"mobx-react-lite";import{AlignCenter as a,AlignCenterHorizontal as r,AlignCenterVertical as l,AlignEndHorizontal as s,AlignEndVertical as p,AlignHorizontalSpaceAround as c,AlignJustify as m,AlignLeft as d,AlignRight as y,AlignStartHorizontal as u,AlignStartVertical as g,AlignVerticalJustifyCenter as b,AlignVerticalJustifyEnd as f,AlignVerticalJustifyStart as x,AlignVerticalSpaceAround as v,ArrowDown as h,ArrowDownLeft as P,ArrowDownRight as w,ArrowLeft as k,ArrowLeftRight as z,ArrowRight as L,ArrowUp as O,ArrowUpDown as j,ArrowUpLeft as R,ArrowUpRight as T,Ban as B,Bold as I,Braces as W,CaseSensitive as F,Check as C,ChevronDown as D,ChevronLeft as G,ChevronRight as H,ChevronsDown as M,ChevronsUp as S,ChevronUp as V,CloudUpload as E,Contrast as U,Copy as $,CreditCard as _,Crop as J,Edit as K,Eye as N,EyeOff as Z,Files as q,FileText as A,GripVertical as Q,HelpCircle as X,Highlighter as Y,Image as tt,Italic as it,Layers as et,LayoutTemplate as ot,List as nt,ListOrdered as at,Lock as rt,MousePointer as lt,MoreHorizontal as st,PaintBucket as pt,Palette as ct,Pause as mt,Pencil as dt,Pilcrow as yt,Pipette as ut,Play as gt,Plus as bt,Redo2 as ft,Scaling as xt,Scissors as vt,Search as ht,SkipBack as Pt,Settings as wt,Shapes as kt,SlidersHorizontal as zt,Sparkles as Lt,Strikethrough as Ot,TextCursorInput as jt,Timer as Rt,ToggleRight as Tt,Trash2 as Bt,Type as It,Underline as Wt,Undo2 as Ft,Unlock as Ct,Upload as Dt,Video as Gt,Volume2 as Ht,VolumeX as Mt,WandSparkles as St,WrapText as Vt,X as Et,ZoomIn as Ut,ZoomOut as $t}from"lucide-react";import{Instagram as _t,Facebook as Jt,Youtube as Kt,Linkedin as Nt,Twitter as Zt}from"./brand-icons.js";import{NoneIcon as qt,MoveIcon as At,FadeIcon as Qt,ZoomIcon as Xt,RotateIcon as Yt,BlinkIcon as ti,BounceIcon as ii,BlurIcon as ei,CountIcon as oi,PopIcon as ni,RiseIcon as ai,FlipIcon as ri,GrowTurnIcon as li,PulseIcon as si,FloatIcon as pi,ShakeIcon as ci,TypewriterIcon as mi,LineRiseIcon as di,WordRiseIcon as yi,WordFadeIcon as ui,LetterPopIcon as gi,WordBlurIcon as bi,WipeIcon as fi,GlowIcon as xi,KenBurnsIcon as vi,LineWipeIcon as hi,LinePeekIcon as Pi,LetterWaveIcon as wi}from"./animation-icons.js";const ki={"action.duplicate":$,"action.split":vt,"action.rename":dt,"action.remove":Bt,"action.lock":rt,"action.unlock":Ct,"action.undo":Ft,"action.redo":ft,"action.add":bt,"action.more":st,"action.settings":wt,"action.search":ht,"action.close":Et,"action.confirm":C,"action.none":B,"action.visible":N,"action.hidden":Z,"action.dragHandle":Q,"action.eyeDropper":ut,"action.unmuted":Ht,"action.muted":Mt,"action.help":X,"ui.chevronUp":V,"ui.chevronDown":D,"ui.chevronLeft":G,"ui.chevronRight":H,"layering.menu":et,"layering.up":V,"layering.down":D,"layering.top":S,"layering.bottom":M,"text.bold":I,"text.italic":it,"text.underline":Wt,"text.strikethrough":Ot,"text.alignLeft":d,"text.alignCenter":a,"text.alignRight":y,"text.alignJustify":m,"text.valignTop":x,"text.valignMiddle":b,"text.valignBottom":f,"text.uppercase":F,"text.spacing":Vt,"text.bulletList":nt,"text.numberedList":at,"text.paragraph":yt,"text.richText":jt,"text.uploadFont":Dt,"position.alignLeft":g,"position.alignCenter":l,"position.alignRight":p,"position.alignTop":u,"position.alignMiddle":r,"position.alignBottom":s,"position.distributeVertical":v,"position.distributeHorizontal":c,"sidePanel.templates":ot,"sidePanel.text":It,"sidePanel.photos":tt,"sidePanel.elements":kt,"sidePanel.upload":E,"sidePanel.background":pt,"sidePanel.pages":q,"sidePanel.layers":et,"sidePanel.resize":xt,"sidePanel.draw":dt,"sidePanel.videos":Gt,"sidePanel.variables":W,"variables.text":It,"variables.image":tt,"variables.video":Gt,"variables.color":ct,"variables.boolean":Tt,"toolbar.opacity":U,"toolbar.filters":St,"toolbar.aiWrite":Lt,"toolbar.insertVariable":W,"toolbar.duration":Rt,"toolbar.trim":vt,"toolbar.flipHorizontal":z,"toolbar.flipVertical":j,"toolbar.zoomIn":Ut,"toolbar.zoomOut":$t,"toolbar.crop":J,"imageEdit.ai":Lt,"colorPicker.reverseGradient":z,"download.export":Dt,"download.image":tt,"download.pdf":A,"download.video":Gt,"draw.select":lt,"draw.brush":K,"draw.highlighter":Y,"background.colorPicker":ct,"pagesTimeline.play":gt,"pagesTimeline.pause":mt,"pagesTimeline.rewind":Pt,"size.instagram":_t,"size.facebook":Jt,"size.youtube":Kt,"size.linkedin":Nt,"size.twitter":Zt,"size.video":Gt,"size.print":A,"size.businessCard":_,"animation.directionRight":L,"animation.directionLeft":k,"animation.directionUp":O,"animation.directionDown":h,"animation.directionBottomRight":w,"animation.directionBottomLeft":P,"animation.directionTopRight":T,"animation.directionTopLeft":R,"animation.typeMove":At,"animation.typeFade":Qt,"animation.typeZoom":Xt,"animation.typeBlur":ei,"animation.typeCount":oi,"animation.typeRotate":Yt,"animation.typeBlink":ti,"animation.typeBounce":ii,"animation.typePop":ni,"animation.typeRise":ai,"animation.typeFlip":ri,"animation.typeGrowTurn":li,"animation.typePulse":si,"animation.typeFloat":pi,"animation.typeShake":ci,"animation.typeTypewriter":mi,"animation.typeLineRise":di,"animation.typeWordRise":yi,"animation.typeWordFade":ui,"animation.typeLetterPop":gi,"animation.typeWordBlur":bi,"animation.typeWipe":fi,"animation.typeGlow":xi,"animation.typeKenBurns":vi,"animation.typeLineWipe":hi,"animation.typeLinePeek":Pi,"animation.typeLetterWave":wi,"animation.typeNone":qt,"animation.settings":zt},zi=e.map();export const setIcons=o(t=>{for(const i of Object.keys(t)){const e=t[i];null!=e&&("function"==typeof e||"object"==typeof e?zi.set(i,e):console.warn(`polotno: setIcons('${i}') expects a React component, received ${typeof e}. Ignored.`))}});export const resetIcons=o(()=>zi.clear());export const PolotnoIcon=n(e=>{var o,{name:n}=e,a=t(e,["name"]);const r=null!==(o=zi.get(n))&&void 0!==o?o:ki[n];return i(r,Object.assign({"data-pn-icon":""},a))});
1
+ var t=this&&this.__rest||function(t,i){var e={};for(var o in t){Object.prototype.hasOwnProperty.call(t,o)&&i.indexOf(o)<0&&(e[o]=t[o])}if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(o=Object.getOwnPropertySymbols(t);n<o.length;n++){i.indexOf(o[n])<0&&Object.prototype.propertyIsEnumerable.call(t,o[n])&&(e[o[n]]=t[o[n]])}}return e};import{jsx as i}from"react/jsx-runtime";import{observable as e,action as o}from"mobx";import{observer as n}from"mobx-react-lite";import{AlignCenter as a,AlignCenterHorizontal as r,AlignCenterVertical as l,AlignEndHorizontal as s,AlignEndVertical as p,AlignHorizontalSpaceAround as c,AlignJustify as m,AlignLeft as d,AlignRight as y,AlignStartHorizontal as g,AlignStartVertical as u,AlignVerticalJustifyCenter as b,AlignVerticalJustifyEnd as f,AlignVerticalJustifyStart as x,AlignVerticalSpaceAround as v,ArrowDown as h,ArrowDownLeft as P,ArrowDownRight as w,ArrowLeft as k,ArrowLeftRight as z,ArrowRight as L,ArrowUp as O,ArrowUpDown as j,ArrowUpLeft as R,ArrowUpRight as T,Ban as B,Bold as I,Braces as W,CaseSensitive as F,Check as C,ChevronDown as S,ChevronLeft as D,ChevronRight as G,ChevronsDown as H,ChevronsUp as M,ChevronUp as V,CloudUpload as E,Contrast as U,Copy as $,CreditCard as _,Crop as J,Edit as K,Eye as N,EyeOff as Z,Files as q,FileText as A,GripVertical as Q,HelpCircle as X,Highlighter as Y,Image as tt,Italic as it,Layers as et,LayoutTemplate as ot,List as nt,ListOrdered as at,Lock as rt,MousePointer as lt,MoreHorizontal as st,PaintBucket as pt,Palette as ct,Pause as mt,Pencil as dt,Pilcrow as yt,Pipette as gt,Play as ut,Plus as bt,Redo2 as ft,Scaling as xt,Scan as vt,Scissors as ht,Search as Pt,SkipBack as wt,Settings as kt,Shapes as zt,SlidersHorizontal as Lt,Sparkles as Ot,Strikethrough as jt,TextCursorInput as Rt,Timer as Tt,ToggleRight as Bt,Trash2 as It,Type as Wt,Underline as Ft,Undo2 as Ct,Unlock as St,Upload as Dt,Video as Gt,Volume2 as Ht,VolumeX as Mt,WandSparkles as Vt,WrapText as Et,X as Ut,ZoomIn as $t,ZoomOut as _t}from"lucide-react";import{Instagram as Jt,Facebook as Kt,Youtube as Nt,Linkedin as Zt,Twitter as qt}from"./brand-icons.js";import{NoneIcon as At,MoveIcon as Qt,FadeIcon as Xt,ZoomIcon as Yt,RotateIcon as ti,BlinkIcon as ii,BounceIcon as ei,BlurIcon as oi,CountIcon as ni,PopIcon as ai,RiseIcon as ri,FlipIcon as li,GrowTurnIcon as si,PulseIcon as pi,FloatIcon as ci,ShakeIcon as mi,TypewriterIcon as di,LineRiseIcon as yi,WordRiseIcon as gi,WordFadeIcon as ui,LetterPopIcon as bi,WordBlurIcon as fi,WipeIcon as xi,GlowIcon as vi,KenBurnsIcon as hi,LineWipeIcon as Pi,LinePeekIcon as wi,LetterWaveIcon as ki}from"./animation-icons.js";const zi={"action.duplicate":$,"action.split":ht,"action.rename":dt,"action.remove":It,"action.lock":rt,"action.unlock":St,"action.undo":Ct,"action.redo":ft,"action.add":bt,"action.more":st,"action.settings":kt,"action.search":Pt,"action.close":Ut,"action.confirm":C,"action.none":B,"action.visible":N,"action.hidden":Z,"action.dragHandle":Q,"action.eyeDropper":gt,"action.unmuted":Ht,"action.muted":Mt,"action.help":X,"ui.chevronUp":V,"ui.chevronDown":S,"ui.chevronLeft":D,"ui.chevronRight":G,"layering.menu":et,"layering.up":V,"layering.down":S,"layering.top":M,"layering.bottom":H,"text.bold":I,"text.italic":it,"text.underline":Ft,"text.strikethrough":jt,"text.alignLeft":d,"text.alignCenter":a,"text.alignRight":y,"text.alignJustify":m,"text.valignTop":x,"text.valignMiddle":b,"text.valignBottom":f,"text.uppercase":F,"text.spacing":Et,"text.bulletList":nt,"text.numberedList":at,"text.paragraph":yt,"text.richText":Rt,"text.uploadFont":Dt,"position.alignLeft":u,"position.alignCenter":l,"position.alignRight":p,"position.alignTop":g,"position.alignMiddle":r,"position.alignBottom":s,"position.distributeVertical":v,"position.distributeHorizontal":c,"sidePanel.templates":ot,"sidePanel.text":Wt,"sidePanel.photos":tt,"sidePanel.elements":zt,"sidePanel.upload":E,"sidePanel.background":pt,"sidePanel.pages":q,"sidePanel.layers":et,"sidePanel.resize":xt,"sidePanel.draw":dt,"sidePanel.videos":Gt,"sidePanel.variables":W,"variables.text":Wt,"variables.image":tt,"variables.video":Gt,"variables.color":ct,"variables.boolean":Bt,"toolbar.opacity":U,"toolbar.filters":Vt,"toolbar.aiWrite":Ot,"toolbar.insertVariable":W,"toolbar.duration":Tt,"toolbar.trim":ht,"toolbar.flipHorizontal":z,"toolbar.flipVertical":j,"toolbar.zoomIn":$t,"toolbar.zoomOut":_t,"toolbar.crop":J,"toolbar.paddingSides":vt,"imageEdit.ai":Ot,"colorPicker.reverseGradient":z,"download.export":Dt,"download.image":tt,"download.pdf":A,"download.video":Gt,"draw.select":lt,"draw.brush":K,"draw.highlighter":Y,"background.colorPicker":ct,"pagesTimeline.play":ut,"pagesTimeline.pause":mt,"pagesTimeline.rewind":wt,"size.instagram":Jt,"size.facebook":Kt,"size.youtube":Nt,"size.linkedin":Zt,"size.twitter":qt,"size.video":Gt,"size.print":A,"size.businessCard":_,"animation.directionRight":L,"animation.directionLeft":k,"animation.directionUp":O,"animation.directionDown":h,"animation.directionBottomRight":w,"animation.directionBottomLeft":P,"animation.directionTopRight":T,"animation.directionTopLeft":R,"animation.typeMove":Qt,"animation.typeFade":Xt,"animation.typeZoom":Yt,"animation.typeBlur":oi,"animation.typeCount":ni,"animation.typeRotate":ti,"animation.typeBlink":ii,"animation.typeBounce":ei,"animation.typePop":ai,"animation.typeRise":ri,"animation.typeFlip":li,"animation.typeGrowTurn":si,"animation.typePulse":pi,"animation.typeFloat":ci,"animation.typeShake":mi,"animation.typeTypewriter":di,"animation.typeLineRise":yi,"animation.typeWordRise":gi,"animation.typeWordFade":ui,"animation.typeLetterPop":bi,"animation.typeWordBlur":fi,"animation.typeWipe":xi,"animation.typeGlow":vi,"animation.typeKenBurns":hi,"animation.typeLineWipe":Pi,"animation.typeLinePeek":wi,"animation.typeLetterWave":ki,"animation.typeNone":At,"animation.settings":Lt},Li=e.map();export const setIcons=o(t=>{for(const i of Object.keys(t)){const e=t[i];null!=e&&("function"==typeof e||"object"==typeof e?Li.set(i,e):console.warn(`polotno: setIcons('${i}') expects a React component, received ${typeof e}. Ignored.`))}});export const resetIcons=o(()=>Li.clear());export const PolotnoIcon=n(e=>{var o,{name:n}=e,a=t(e,["name"]);const r=null!==(o=Li.get(n))&&void 0!==o?o:zi[n];return i(r,Object.assign({"data-pn-icon":""},a))});
@@ -1,6 +1,7 @@
1
1
  import { Instance, SnapshotIn, IAnyModelType, IAnyType } from 'mobx-state-tree';
2
- import { NodeType } from './node-model.js';
2
+ import { NodeType, renewIds } from './node-model.js';
3
3
  import { type AnimationAttrs, type WipeBand } from '../utils/animations.js';
4
+ import { forEveryNode } from '@polotno/core/for-every-node';
4
5
  import { TextElementType } from './text-model.js';
5
6
  import { ImageElementType } from './image-model.js';
6
7
  import { VideoElementType } from './video-model.js';
@@ -11,7 +12,8 @@ import { GifElementType } from './gif-model.js';
11
12
  import { LottieElementType } from './lottie-model.js';
12
13
  import { TableElementType } from './table-model.js';
13
14
  export declare const forEveryChild: (node: any, cb: any) => void;
14
- export { forEveryNode } from '@polotno/core/for-every-node';
15
+ export { forEveryNode };
16
+ export { renewIds };
15
17
  export declare function zIndexOps<T extends {
16
18
  id: string;
17
19
  }>(self: {
@@ -403,7 +405,11 @@ export declare const TYPES_MAP: {
403
405
  backgroundPadding: import("mobx-state-tree").IType<number | undefined, number, number>;
404
406
  borderColor: import("mobx-state-tree").IType<string | undefined, string, string>;
405
407
  borderSize: import("mobx-state-tree").IType<number | undefined, number, number>;
406
- legacyBackground: import("mobx-state-tree").IMaybe<import("mobx-state-tree").ISimpleType<boolean>>;
408
+ backgroundShape: import("mobx-state-tree").IMaybe<import("mobx-state-tree").ISimpleType<string>>;
409
+ paddingTop: import("mobx-state-tree").IMaybe<import("mobx-state-tree").ISimpleType<number>>;
410
+ paddingRight: import("mobx-state-tree").IMaybe<import("mobx-state-tree").ISimpleType<number>>;
411
+ paddingBottom: import("mobx-state-tree").IMaybe<import("mobx-state-tree").ISimpleType<number>>;
412
+ paddingLeft: import("mobx-state-tree").IMaybe<import("mobx-state-tree").ISimpleType<number>>;
407
413
  curveEnabled: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
408
414
  curvePower: import("mobx-state-tree").IType<number | undefined, number, number>;
409
415
  textOverflow: import("mobx-state-tree").IMaybe<import("mobx-state-tree").ISimpleType<string>>;
@@ -2263,7 +2269,10 @@ export declare const TYPES_MAP: {
2263
2269
  _strokeWidth: import("mobx-state-tree").IMaybe<import("mobx-state-tree").ISimpleType<number>>;
2264
2270
  _stroke: import("mobx-state-tree").IMaybe<import("mobx-state-tree").ISimpleType<string>>;
2265
2271
  _cellBackground: import("mobx-state-tree").IMaybe<import("mobx-state-tree").ISimpleType<string>>;
2266
- _cellPadding: import("mobx-state-tree").IMaybe<import("mobx-state-tree").ISimpleType<number>>;
2272
+ _cellPaddingTop: import("mobx-state-tree").IMaybe<import("mobx-state-tree").ISimpleType<number>>;
2273
+ _cellPaddingRight: import("mobx-state-tree").IMaybe<import("mobx-state-tree").ISimpleType<number>>;
2274
+ _cellPaddingBottom: import("mobx-state-tree").IMaybe<import("mobx-state-tree").ISimpleType<number>>;
2275
+ _cellPaddingLeft: import("mobx-state-tree").IMaybe<import("mobx-state-tree").ISimpleType<number>>;
2267
2276
  opacity: import("mobx-state-tree").IType<number | undefined, number, number>;
2268
2277
  rowSpan: import("mobx-state-tree").IType<number | undefined, number, number>;
2269
2278
  colSpan: import("mobx-state-tree").IType<number | undefined, number, number>;
@@ -2320,6 +2329,10 @@ export declare const TYPES_MAP: {
2320
2329
  readonly strokeWidth: number;
2321
2330
  readonly stroke: string;
2322
2331
  readonly cellBackground: string;
2332
+ readonly cellPaddingTop: number;
2333
+ readonly cellPaddingRight: number;
2334
+ readonly cellPaddingBottom: number;
2335
+ readonly cellPaddingLeft: number;
2323
2336
  readonly cellPadding: number;
2324
2337
  readonly width: number;
2325
2338
  readonly height: number;
@@ -2371,7 +2384,10 @@ export declare const TYPES_MAP: {
2371
2384
  style: import("mobx-state-tree").IMaybe<import("mobx-state-tree").ISimpleType<"dashed" | "dotted" | "none" | "solid">>;
2372
2385
  }, {}, import("mobx-state-tree")._NotCustomized, any>>;
2373
2386
  }, {}, import("mobx-state-tree")._NotCustomized, any>>>) | undefined;
2374
- cellPadding: number;
2387
+ cellPaddingTop: number;
2388
+ cellPaddingRight: number;
2389
+ cellPaddingBottom: number;
2390
+ cellPaddingLeft: number;
2375
2391
  };
2376
2392
  readonly borderInsets: {
2377
2393
  top: number;
@@ -2449,7 +2465,10 @@ export declare const TYPES_MAP: {
2449
2465
  strokeWidth: import("mobx-state-tree").IType<number | undefined, number, number>;
2450
2466
  stroke: import("mobx-state-tree").IType<string | undefined, string, string>;
2451
2467
  cellBackground: import("mobx-state-tree").IType<string | undefined, string, string>;
2452
- cellPadding: import("mobx-state-tree").IType<number | undefined, number, number>;
2468
+ cellPaddingTop: import("mobx-state-tree").IType<number | undefined, number, number>;
2469
+ cellPaddingRight: import("mobx-state-tree").IType<number | undefined, number, number>;
2470
+ cellPaddingBottom: import("mobx-state-tree").IType<number | undefined, number, number>;
2471
+ cellPaddingLeft: import("mobx-state-tree").IType<number | undefined, number, number>;
2453
2472
  }, {
2454
2473
  readonly page: any;
2455
2474
  readonly store: any;
@@ -2603,6 +2622,7 @@ export declare const TYPES_MAP: {
2603
2622
  } & {
2604
2623
  readonly _cellMap: Map<string, import("./table-model.js").TableCellType>;
2605
2624
  getActualRowHeight(rowIndex: number): number;
2625
+ readonly cellPadding: number;
2606
2626
  } & {
2607
2627
  getCell(row: number, col: number): import("./table-model.js").TableCellType | undefined;
2608
2628
  visibleCellAt(row: number, col: number): import("./table-model.js").TableCellType | undefined;
@@ -2657,10 +2677,6 @@ export declare const TYPES_MAP: {
2657
2677
  resizeRow(index: number, delta: number): void;
2658
2678
  setCellBorders(cellIds: string[], sides: import("./table-model.js").BorderSideName[], attrs: import("./table-model.js").BorderAttrs): void;
2659
2679
  applyBorderMode(mode: import("./table-model.js").BorderMode, attrs: import("./table-model.js").BorderAttrs): void;
2660
- } & {
2661
- clone(attrs?: any, { skipSelect }?: {
2662
- skipSelect?: boolean | undefined;
2663
- }): any;
2664
2680
  }, any, any>;
2665
2681
  };
2666
2682
  export declare function registerShapeModel<P extends {
@@ -1 +1 @@
1
- var e=this&&this.__rest||function(e,t){var o={};for(var i in e){Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(o[i]=e[i])}if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(e);r<i.length;r++){t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(o[i[r]]=e[i[r]])}}return o};import{isAlive as t,types as o}from"mobx-state-tree";import{nanoid as i}from"nanoid";import{GROUP_BLEND_MODES as r}from"@polotno/schema/defaults";import{Node as n,explicitWrite as l}from"./node-model.js";import{Animation as s,Shape as a}from"./shape-model.js";import{animate as c,playedAnimations as d,setAnimationOf as p}from"../utils/animations.js";import{polotnoError as m}from"@polotno/core/errors";import{transitionWindows as h}from"@polotno/core/animation-presets";import{getPlayheadLocalTime as f,isHeldByPreview as y}from"../utils/timeline.js";import{getCenter as u,getTotalClientRect as g}from"../utils/math.js";import{TextElement as E}from"./text-model.js";import{ImageElement as v}from"./image-model.js";import{VideoElement as b}from"./video-model.js";import{LineElement as x}from"./line-model.js";import{SVGElement as w}from"./svg-model.js";import{FigureElement as j}from"./figure-model.js";import{GifElement as O}from"./gif-model.js";import{LottieElement as S}from"./lottie-model.js";import{TableElement as P}from"./table-model.js";export const forEveryChild=(e,t)=>{if(e.children){for(const o of e.children){if(!0===t(o)){break}forEveryChild(o,t)}}};export{forEveryNode}from"@polotno/core/for-every-node";export function zIndexOps(e){const t=(t,o,i)=>{const r=t.map(t=>e.children.findIndex(e=>e.id===t)).filter(e=>-1!==e).sort((e,t)=>(t-e)*o);for(const n of r){const r=e.children[n+o];!r||t.indexOf(r.id)>=0||i(n)}},o=(e,o)=>{let i=!1;return t(e,o,()=>{i=!0}),i},i=(o,i)=>{t(o,i,t=>{const o=e.children.slice();[o[t],o[t+i]]=[o[t+i],o[t]],e.children.replace(o)})},r=(t,o)=>{const i=[],r=[];e.children.forEach(e=>{(t.indexOf(e.id)>=0?i:r).push(e)}),e.children.replace(o?r.concat(i):i.concat(r))};return{canMoveElementsUp:e=>o(e,1),canMoveElementsTop:e=>o(e,1),canMoveElementsDown:e=>o(e,-1),canMoveElementsBottom:e=>o(e,-1),moveElementsUp(e){i(e,1)},moveElementsDown(e){i(e,-1)},moveElementsTop(e){r(e,!0)},moveElementsBottom(e){r(e,!1)},setElementZIndex(t,o){const i=e.children.find(e=>e.id===t);if(i){const t=e.children.filter(e=>e!==i);t.splice(o,0,i),e.children.replace(t)}}}}const C=[...new Array(20)].map((e,t)=>o.late(()=>z[t]));export const ElementTypes=o.union({dispatcher:e=>{const t=TYPES_MAP[e.type];if(!t){const t=`Unknown element type: "${e.type}"`;throw m("DESIGN_INVALID",t,{errors:[{path:"type",message:t}],knownTypes:Object.keys(TYPES_MAP)})}return t}},w,E,v,x,b,j,O,S,P,o.late(()=>GroupElement),...C);const M=Object.freeze({x:0,y:0,offsetX:0,offsetY:0,scaleX:1,scaleY:1,rotation:0,opacity:1});function T(e){return 1===e?M:Object.assign(Object.assign({},M),{opacity:e})}const Y=(e,t)=>"number"==typeof e&&isFinite(e)?e:t;function _(e,t,o,i,r){var n,l,s;const a={x:e.x,y:e.y,width:e.width,height:e.height,rotation:null!==(n=e.rotation)&&void 0!==n?n:0,opacity:i,fontSize:0,cropX:0,cropY:0,cropWidth:1,cropHeight:1,page:r},d=c({element:a,animation:t,dTime:o})||{},p=Y(d.width,e.width),m=Y(d.height,e.height);return{x:Y(d.x,e.x),y:Y(d.y,e.y),width:p>0?p:e.width,height:m>0?m:e.height,rotation:Y(d.rotation,a.rotation),opacity:Math.min(1,Math.max(0,Y(d.opacity,i))),wipe:null!==(l=d.wipe)&&void 0!==l?l:e.wipe,flipScale:null!==(s=d.flipScale)&&void 0!==s?s:e.flipScale}}export const GroupElement=n.named("Group").props({type:"group",blendMode:o.optional(o.enumeration([...r]),"pass-through"),children:o.array(ElementTypes),animations:o.array(s)}).views(e=>({get draggable(){let t=!0;return forEveryChild(e,e=>{e.draggable||(t=!1)}),t},get resizable(){let t=!0;return forEveryChild(e,e=>{e.resizable||(t=!1)}),t},get contentEditable(){let t=!0;return forEveryChild(e,e=>{e.contentEditable||(t=!1)}),t},get styleEditable(){let t=!0;return forEveryChild(e,e=>{e.styleEditable||(t=!1)}),t},get locked(){let t=!0;return forEveryChild(e,e=>{e.locked||(t=!1)}),t},get _restingBbox(){const t=[];if(forEveryChild(e,e=>{var o,i,r;if("group"===e.type){return}const n=e.width,l=e.height;!n||!l||n<=0||l<=0||t.push({x:null!==(o=e.x)&&void 0!==o?o:0,y:null!==(i=e.y)&&void 0!==i?i:0,width:n,height:l,rotation:null!==(r=e.rotation)&&void 0!==r?r:0})}),!t.length){return null}const o=g(t);return o.width<=0||o.height<=0?null:{x:o.x,y:o.y,width:o.width,height:o.height}},get a(){var o;if(!t(e)){return M}const i=f(e);if(null===i){return T(e.opacity)}if((e.store.isEditingPaused||y(e))&&this.isSelectedDirectly){return T(e.opacity)}const r=e.page;let n,l,s;for(const t of d(e)){t.enabled&&("enter"===t.type?n=t:"exit"===t.type?l=t:"loop"===t.type&&(s=t))}const a=h(d(e),r.duration),c=!!n&&i<n.delay,p=!!a.enter&&i>=a.enter.start&&i<=a.enter.end,m=!c&&!p&&!!a.exit&&i>=a.exit.start&&i<=a.exit.end,g=!!l&&i>=r.duration-l.delay,E=!!s&&i>=s.delay;if(!(c||p||m||g||E)){return T(e.opacity)}const v=this._restingBbox;if(!v){return T(e.opacity)}let b={x:v.x,y:v.y,width:v.width,height:v.height,rotation:0,opacity:e.opacity};c&&(b.opacity=0),p&&(b=_(v,n,(i-a.enter.start)/a.pace,e.opacity,r)),m&&(b=_(v,l,(i-a.exit.start)/a.pace,e.opacity,r)),g&&(b.opacity=0),E&&(b=_(b,s,i-s.delay,b.opacity,r));const x=u(b);return{x:x.x,y:x.y,offsetX:v.x+v.width/2,offsetY:v.y+v.height/2,scaleX:b.width/v.width*(null!==(o=b.flipScale)&&void 0!==o?o:1),scaleY:b.height/v.height,rotation:b.rotation,opacity:b.opacity,wipe:b.wipe}},get isSelectedDirectly(){return!!t(e)&&e.store.selectedElements.indexOf(e)>=0&&e.selectable},get active(){return!0}})).actions(t=>Object.assign(Object.assign({set(o){var{draggable:i,contentEditable:r,styleEditable:n,resizable:s}=o,a=e(o,["draggable","contentEditable","styleEditable","resizable"]);void 0!==i&&forEveryChild(t,e=>{e.set({draggable:i})}),void 0!==r&&forEveryChild(t,e=>{e.set({contentEditable:r})}),void 0!==n&&forEveryChild(t,e=>{e.set({styleEditable:n})}),void 0!==s&&forEveryChild(t,e=>{e.set({resizable:s})}),Object.assign(t,l(t,a))},addElement(e,{skipSelect:o=!1}={}){const r=TYPES_MAP[e.type];if(!r){return void console.error("Can not find model with type "+e.type)}e.children&&e.children.forEach(e=>{e.id=e.id||i(10)});const n=r.create(Object.assign({id:i(10)},e));return t.children.push(n),n.selectable&&!o&&t.store.selectElements([n.id]),n}},zIndexOps(t)),{setAnimation(e,o){p(t.animations,e,o)}}));const z=[];export const TYPES_MAP={svg:w,text:E,image:v,group:GroupElement,line:x,video:b,figure:j,gif:O,lottie:S,table:P};export function registerShapeModel(e,t){const o=e.type;if(!o){throw new Error('You must pass "type" attribute to custom model.')}const i=a.named(o).props(e),r=t?t(i):i;TYPES_MAP[o]=r,z.push(r)}
1
+ var e=this&&this.__rest||function(e,t){var o={};for(var i in e){Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(o[i]=e[i])}if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(e);r<i.length;r++){t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(o[i[r]]=e[i[r]])}}return o};import{isAlive as t,types as o}from"mobx-state-tree";import{nanoid as i}from"nanoid";import{GROUP_BLEND_MODES as r}from"@polotno/schema/defaults";import{Node as n,explicitWrite as l,renewIds as s}from"./node-model.js";import{Animation as a,Shape as c}from"./shape-model.js";import{animate as d,playedAnimations as p,setAnimationOf as m}from"../utils/animations.js";import{polotnoError as h}from"@polotno/core/errors";import{forEveryNode as f}from"@polotno/core/for-every-node";import{transitionWindows as y}from"@polotno/core/animation-presets";import{getPlayheadLocalTime as u,isHeldByPreview as g}from"../utils/timeline.js";import{getCenter as E,getTotalClientRect as b}from"../utils/math.js";import{TextElement as v}from"./text-model.js";import{ImageElement as x}from"./image-model.js";import{VideoElement as w}from"./video-model.js";import{LineElement as j}from"./line-model.js";import{SVGElement as O}from"./svg-model.js";import{FigureElement as S}from"./figure-model.js";import{GifElement as P}from"./gif-model.js";import{LottieElement as C}from"./lottie-model.js";import{TableElement as M}from"./table-model.js";export const forEveryChild=(e,t)=>{if(e.children){for(const o of e.children){if(!0===t(o)){break}forEveryChild(o,t)}}};export{f as forEveryNode};export{s as renewIds};export function zIndexOps(e){const t=(t,o,i)=>{const r=t.map(t=>e.children.findIndex(e=>e.id===t)).filter(e=>-1!==e).sort((e,t)=>(t-e)*o);for(const n of r){const r=e.children[n+o];!r||t.indexOf(r.id)>=0||i(n)}},o=(e,o)=>{let i=!1;return t(e,o,()=>{i=!0}),i},i=(o,i)=>{t(o,i,t=>{const o=e.children.slice();[o[t],o[t+i]]=[o[t+i],o[t]],e.children.replace(o)})},r=(t,o)=>{const i=[],r=[];e.children.forEach(e=>{(t.indexOf(e.id)>=0?i:r).push(e)}),e.children.replace(o?r.concat(i):i.concat(r))};return{canMoveElementsUp:e=>o(e,1),canMoveElementsTop:e=>o(e,1),canMoveElementsDown:e=>o(e,-1),canMoveElementsBottom:e=>o(e,-1),moveElementsUp(e){i(e,1)},moveElementsDown(e){i(e,-1)},moveElementsTop(e){r(e,!0)},moveElementsBottom(e){r(e,!1)},setElementZIndex(t,o){const i=e.children.find(e=>e.id===t);if(i){const t=e.children.filter(e=>e!==i);t.splice(o,0,i),e.children.replace(t)}}}}const T=[...new Array(20)].map((e,t)=>o.late(()=>I[t]));export const ElementTypes=o.union({dispatcher:e=>{const t=TYPES_MAP[e.type];if(!t){const t=`Unknown element type: "${e.type}"`;throw h("DESIGN_INVALID",t,{errors:[{path:"type",message:t}],knownTypes:Object.keys(TYPES_MAP)})}return t}},O,v,x,j,w,S,P,C,M,o.late(()=>GroupElement),...T);const Y=Object.freeze({x:0,y:0,offsetX:0,offsetY:0,scaleX:1,scaleY:1,rotation:0,opacity:1});function _(e){return 1===e?Y:Object.assign(Object.assign({},Y),{opacity:e})}const z=(e,t)=>"number"==typeof e&&isFinite(e)?e:t;function A(e,t,o,i,r){var n,l,s;const a={x:e.x,y:e.y,width:e.width,height:e.height,rotation:null!==(n=e.rotation)&&void 0!==n?n:0,opacity:i,fontSize:0,cropX:0,cropY:0,cropWidth:1,cropHeight:1,page:r},c=d({element:a,animation:t,dTime:o})||{},p=z(c.width,e.width),m=z(c.height,e.height);return{x:z(c.x,e.x),y:z(c.y,e.y),width:p>0?p:e.width,height:m>0?m:e.height,rotation:z(c.rotation,a.rotation),opacity:Math.min(1,Math.max(0,z(c.opacity,i))),wipe:null!==(l=c.wipe)&&void 0!==l?l:e.wipe,flipScale:null!==(s=c.flipScale)&&void 0!==s?s:e.flipScale}}export const GroupElement=n.named("Group").props({type:"group",blendMode:o.optional(o.enumeration([...r]),"pass-through"),children:o.array(ElementTypes),animations:o.array(a)}).views(e=>({get draggable(){let t=!0;return forEveryChild(e,e=>{e.draggable||(t=!1)}),t},get resizable(){let t=!0;return forEveryChild(e,e=>{e.resizable||(t=!1)}),t},get contentEditable(){let t=!0;return forEveryChild(e,e=>{e.contentEditable||(t=!1)}),t},get styleEditable(){let t=!0;return forEveryChild(e,e=>{e.styleEditable||(t=!1)}),t},get locked(){let t=!0;return forEveryChild(e,e=>{e.locked||(t=!1)}),t},get _restingBbox(){const t=[];if(forEveryChild(e,e=>{var o,i,r;if("group"===e.type){return}const n=e.width,l=e.height;!n||!l||n<=0||l<=0||t.push({x:null!==(o=e.x)&&void 0!==o?o:0,y:null!==(i=e.y)&&void 0!==i?i:0,width:n,height:l,rotation:null!==(r=e.rotation)&&void 0!==r?r:0})}),!t.length){return null}const o=b(t);return o.width<=0||o.height<=0?null:{x:o.x,y:o.y,width:o.width,height:o.height}},get a(){var o;if(!t(e)){return Y}const i=u(e);if(null===i){return _(e.opacity)}if((e.store.isEditingPaused||g(e))&&this.isSelectedDirectly){return _(e.opacity)}const r=e.page;let n,l,s;for(const t of p(e)){t.enabled&&("enter"===t.type?n=t:"exit"===t.type?l=t:"loop"===t.type&&(s=t))}const a=y(p(e),r.duration),c=!!n&&i<n.delay,d=!!a.enter&&i>=a.enter.start&&i<=a.enter.end,m=!c&&!d&&!!a.exit&&i>=a.exit.start&&i<=a.exit.end,h=!!l&&i>=r.duration-l.delay,f=!!s&&i>=s.delay;if(!(c||d||m||h||f)){return _(e.opacity)}const b=this._restingBbox;if(!b){return _(e.opacity)}let v={x:b.x,y:b.y,width:b.width,height:b.height,rotation:0,opacity:e.opacity};c&&(v.opacity=0),d&&(v=A(b,n,(i-a.enter.start)/a.pace,e.opacity,r)),m&&(v=A(b,l,(i-a.exit.start)/a.pace,e.opacity,r)),h&&(v.opacity=0),f&&(v=A(v,s,i-s.delay,v.opacity,r));const x=E(v);return{x:x.x,y:x.y,offsetX:b.x+b.width/2,offsetY:b.y+b.height/2,scaleX:v.width/b.width*(null!==(o=v.flipScale)&&void 0!==o?o:1),scaleY:v.height/b.height,rotation:v.rotation,opacity:v.opacity,wipe:v.wipe}},get isSelectedDirectly(){return!!t(e)&&e.store.selectedElements.indexOf(e)>=0&&e.selectable},get active(){return!0}})).actions(t=>Object.assign(Object.assign({set(o){var{draggable:i,contentEditable:r,styleEditable:n,resizable:s}=o,a=e(o,["draggable","contentEditable","styleEditable","resizable"]);void 0!==i&&forEveryChild(t,e=>{e.set({draggable:i})}),void 0!==r&&forEveryChild(t,e=>{e.set({contentEditable:r})}),void 0!==n&&forEveryChild(t,e=>{e.set({styleEditable:n})}),void 0!==s&&forEveryChild(t,e=>{e.set({resizable:s})}),Object.assign(t,l(t,a))},addElement(e,{skipSelect:o=!1}={}){const r=TYPES_MAP[e.type];if(!r){return void console.error("Can not find model with type "+e.type)}e.children&&e.children.forEach(e=>{e.id=e.id||i(10)});const n=r.create(Object.assign({id:i(10)},e));return t.children.push(n),n.selectable&&!o&&t.store.selectElements([n.id]),n}},zIndexOps(t)),{setAnimation(e,o){m(t.animations,e,o)}}));const I=[];export const TYPES_MAP={svg:O,text:v,image:x,group:GroupElement,line:j,video:w,figure:S,gif:P,lottie:C,table:M};export function registerShapeModel(e,t){const o=e.type;if(!o){throw new Error('You must pass "type" attribute to custom model.')}const i=c.named(o).props(e),r=t?t(i):i;TYPES_MAP[o]=r,I.push(r)}