polotno 3.5.1 → 3.5.2

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.
@@ -1 +1 @@
1
- import{jsx as t,Fragment as e,jsxs as o}from"react/jsx-runtime";import r from"react";import{observer as n}from"mobx-react-lite";import{Group as i,Image as a,Path as s,Rect as l}from"react-konva";import{scaledFontSizeAttrs as c,roundedFontSizeAttrs as f,roundedTextDecorationAttrs as h,textMinResizeWidth as d}from"../utils/px.js";import u from"konva";import{isAlive as g}from"mobx-state-tree";import{nodeAutorun as m}from"../utils/mobx.js";import{flags as x}from"../utils/flags.js";import{applyFilter as p}from"./apply-filters.js";import{getLineHeight as y,useFontFamiliesLoader as w,usePrevious as v}from"./text-element.js";import{getCurvePath as b}from"@polotno/core/text-html";import{useColor as E}from"./use-color.js";import{useWorkspaceStyle as S}from"./workspace-style.js";import{detectSize as O,detectLineRects as k,htmlToCanvas as z}from"../utils/html2canvas.js";import{generateBackgroundShapeFromRects as F}from"@polotno/core/background-shape";import{useFadeIn as j}from"./use-fadein.js";import{Html as M}from"react-konva-utils";import{incrementLoader as R,triggerLoadError as X}from"../utils/loader.js";import{removeTags as Y}from"@polotno/core/text";import*as I from"../utils/fonts.js";import{isTouchDevice as C}from"../utils/screen.js";import{getLimitedFontSize as T}from"./text-element/max-font-size.js";import{visiblePlaceholder as A}from"./text-element/placeholder.js";import{useDelayer as P}from"./use-delayer.js";import{getHtml as B}from"@polotno/core/text-html";import{normalizeRichTextHtml as W,extractFontFamiliesFromHtml as $,scaleRichTextFontSizesInHtml as D}from"../utils/rich-text-html.js";import{findFitFontSize as H}from"./text-element/fit-font-size.js";import{RichEditor as _,RichTextContainer as L,applyOpacityToColor as J,quillRef as N,createQuill as q,setQuillContent as V,setQuillFormats as G,syncQuillFormatState as K,setCursorFromCoords as Q}from"./rich-editor.js";export{N as quillRef,q as createQuill,V as setQuillContent,G as setQuillFormats,K as syncQuillFormatState,Q as setCursorFromCoords};function U(t){const e=document.createElement("canvas"),o=e.getContext("2d");return null==o||o.drawImage(t,0,0,e.width,e.height),function(t){return!function(t){const e=t.getContext("2d").getImageData(0,0,t.width,t.height).data;for(let o=0;o<e.length;o+=4){if(0!==e[o+3]){return!0}}return!1}(t)}(e)}const Z=/^((?!chrome|android).)*safari/i.test(navigator.userAgent),tt=navigator.userAgent.includes("Firefox");export const HTMLElement=n(({element:n,store:N})=>{var q,V;const{textOverflowIndicatorStyle:G}=S(),K=r.useRef(null),[Q,et]=r.useState(),[ot,rt]=r.useState(!1),[nt,it]=r.useState(!1),at=r.useRef(n.height),st=n.isSelected,lt=v(st),ct=n.fontSize/3,{textVerticalResizeEnabled:ft}=x,ht=x.autoDeleteEmptyText,dt=v(n.fontFamily),ut=r.useMemo(()=>W(n.text,{fontSize:n.fontSize,fontFamily:n.fontFamily}),[n.text,n.fontSize,n.fontFamily]),gt=r.useMemo(()=>[...new Set([n.fontFamily,...$(ut)])].filter(Boolean),[n.fontFamily,ut]),[mt]=w(N,gt,n.fontStyle,n.fontWeight,n.text||n.placeholder),xt=n._editModeEnabled;j(K);const pt=mt?n.fontFamily:dt!==n.fontFamily?dt:"Arial",yt=E(n).fill,wt=B(n,{fontFamily:pt,color:yt,textOverflow:x.textOverflow}),vt=r.useRef([]),bt=r.useRef(!0),[,Et]=r.useReducer(t=>t+1,0);r.useEffect(()=>{const t=vt.current;t.length>0&&(vt.current=[],t.forEach(t=>t()))}),r.useEffect(()=>()=>{bt.current=!1;const t=vt.current;t.length>0&&(vt.current=[],t.forEach(t=>t()))},[]);let{width:St,height:Ot}=function(t,e,o){return r.useMemo(()=>O(t),[t,e.width,o])}(wt,n,mt);r.useEffect(()=>{if(!mt){return}const t=(t,e,o,r)=>{const i=R(`text ${n.id}`),a=()=>{N.history.ignore(t,e,o).then(()=>{bt.current?(vt.current.push(i),Et()):i()})};r?queueMicrotask(a):a()};if(n.curveEnabled&&Math.abs(St-n.width)>1&&!ot&&t(()=>{if(g(n)&&Math.abs(St-n.width)>1){const t=n.x+n.width/2;n.set({width:St,x:t-St/2})}},!1,!0),!n.height){return void t(()=>{g(n)&&(n.height||n.set({height:Ot}))},void 0,void 0,!0)}const{textOverflow:e}=x;if("change-font-size"!==e||ot||xt||n.curveEnabled){"resize"===e&&(ft&&n.height<Ot&&!ot&&t(()=>{g(n)&&n.set({height:Ot})},!1,!0),ft||n.height===Ot||ot||t(()=>{g(n)&&n.set({height:Ot})},!1,!0))}else{const e=H(n,{fontFamily:n.fontFamily,textOverflow:x.textOverflow});e.fontSize!==n.fontSize?t(()=>{if(!g(n)){return}const t=c(n,e.fontSize);void 0!==e.text&&e.text!==n.text&&(t.text=e.text),n.set(t)},!1,!0):n.height!==Ot&&(ft&&n.height<Ot?t(()=>{g(n)&&n.set({height:Ot})},!1,!0):ft||t(()=>{g(n)&&n.set({height:Ot})},!1,!0))}});const kt=r.useMemo(()=>{const t={lastArgs:null,lastResult:null};return async function(e){return t.lastArgs&&t.lastResult&&(o=t.lastArgs,r=e,JSON.stringify(o)===JSON.stringify(r))||(t.lastResult=await z(e),t.lastArgs=Object.assign({},e)),t.lastResult;var o,r}},[]),zt=r.useRef(0),Ft=r.useRef(null);r.useEffect(()=>{ot||xt||(async()=>{zt.current++;const t=zt.current;let e=R(`text ${n.id} ${t}`);Ft.current&&Ft.current(),Ft.current=e,it(!0);let o=null;const r=Z?5:1;for(let a=0;a<r;a++){const e=a>0?kt:z;try{if(o=await e({skipCache:a>0,html:wt,width:St||n.width||1,height:n.height||Ot||1,fontFamily:pt,fontFamilies:$(wt),resolveFont:t=>N.fonts.find(e=>e.fontFamily===t)||I.globalFonts.find(e=>e.fontFamily===t),padding:ct,pixelRatio:N._elementsPixelRatio,font:N.fonts.find(t=>t.fontFamily===pt)||I.globalFonts.find(t=>t.fontFamily===pt)}),t!==zt.current){return}if((Z||tt)&&o&&U(o)){await new Promise(t=>setTimeout(t,50*(a+1)));continue}break}catch(i){console.error(i),X(`Error rendering rich text with id ${n.id}`);break}}o?et(o):e?(e(),e=null):console.error("Finish function is called twice!"),it(!1)})()},[wt,ot,Ot,xt,pt,n.height,N._elementsPixelRatio,mt]);const[jt,Mt]=P(nt,300),[Rt]=P(ot,300,!0),Xt=Rt||jt;r.useEffect(()=>{var t;if(!Xt){return m(n,()=>{const t=K.current;p(t,n)})}null===(t=K.current)||void 0===t||t.clearCache()},[Q,Xt,n.shadowColor,n.shadowOffsetX,n.shadowOffsetY,n.shadowOpacity]),r.useEffect(()=>{Q&&!nt&&Ft.current&&(Ft.current(),Ft.current=null)},[Q,nt]),r.useLayoutEffect(()=>{if(!mt){return}if(!n.curveEnabled){return}const t=new u.TextPath({data:b(n.a.width,n.a.height,n.curvePower,n.a.fontSize),text:Y(n.text),letterSpacing:n.letterSpacing*n.a.fontSize,fontSize:n.a.fontSize,fontFamily:n.fontFamily,fontWeight:n.fontWeight,fontStyle:n.fontStyle,align:"center",textBaseline:"middle",fill:n.fill}),e=t.getSelfRect().width;if(e){const t=e-n.a.width,o=n.a.rotation*Math.PI/180,r=-t/2*Math.cos(o),i=-t/2*Math.sin(o);queueMicrotask(()=>{g(n)&&n.set({width:e,x:n.a.x+r,y:n.a.y+i})})}t.destroy()},[mt,n.curveEnabled,n.curvePower,n.text,n.fontSize,n.fontFamily,n.fontWeight,n.fontStyle,n.letterSpacing]),r.useEffect(()=>()=>{Ft.current&&Ft.current()},[]),r.useEffect(()=>{lt&&!st&&ht&&""===Y(n.text)&&n.removable&&!A(n.placeholder)&&N.deleteElements([n.id])},[ht,n.placeholder,n.removable,n.text,st,lt]);let Yt=0;"middle"===n.verticalAlign&&(Yt=(n.height-Ot)/2),"bottom"===n.verticalAlign&&(Yt=n.height-Ot);const It=y({fontLoaded:mt,fontFamily:n.fontFamily,fontSize:n.fontSize,lineHeight:n.lineHeight}),Ct=n.backgroundPadding*(n.fontSize*It*.5),Tt=n.backgroundCornerRadius*(n.fontSize*It*.5),At=r.useMemo(()=>{if(!n.backgroundEnabled||n.curveEnabled||n.legacyBackground){return""}const t=k(wt);if(0===t.length){return""}const e=t.map(t=>({left:t.left+ct,right:t.right+ct,top:t.top+ct,bottom:t.bottom+ct}));return F({rects:e,padding:Ct,cornerRadius:Tt})},[n.backgroundEnabled,n.curveEnabled,n.legacyBackground,wt,mt,Ct,Tt,ct]),Pt=C(),Bt=b(n.a.width,Ot,n.curvePower,n.fontSize),Wt=r.useRef(null),$t=r.useRef(n.width),Dt=r.useRef(null),Ht=r.useRef(0),_t=r.useRef(0),Lt=r.useRef(null),Jt=xt&&n.strokeWidth>0&&!n.curveEnabled,Nt=St>0?(n.a.width+2*ct)/(St+2*ct):1;return o(e,{children:[n.curveEnabled||n.legacyBackground?t(l,{x:n.a.x,y:n.a.y,offsetX:Ct/Nt,offsetY:Ct/Nt,rotation:n.a.rotation,scaleX:Nt,scaleY:Nt,hideInExport:!n.showInExport,listening:!1,visible:n.backgroundEnabled,opacity:n.backgroundOpacity*n.a.opacity,fill:n.backgroundColor,width:n.width+2*Ct,height:n.height+2*Ct,cornerRadius:Tt}):t(s,{name:"html-background",x:n.a.x,y:n.a.y,offsetX:ct/Nt,offsetY:(ct-Yt)/Nt,rotation:n.a.rotation,scaleX:Nt,scaleY:Nt,hideInExport:!n.showInExport,listening:!1,visible:n.backgroundEnabled&&At.length>0,opacity:n.backgroundOpacity*n.a.opacity,fill:n.backgroundColor,data:At}),t(s,{x:n.a.x,y:n.a.y,rotation:n.a.rotation,data:Bt,stroke:G.stroke,strokeWidth:1,visible:!1}),t(l,{ref:K,name:"element",x:n.a.x,y:n.a.y,listening:n.selectable,rotation:n.a.rotation,width:n.a.width,height:n.a.height,visible:!Xt,draggable:Pt?n.draggable&&st:n.draggable,preventDefault:!Pt||st,opacity:xt?0:n.a.opacity,hideInExport:!n.showInExport,onDragMove:t=>{n.set({x:t.target.x(),y:t.target.y()})},onDragEnd:t=>{n.set({x:t.target.x(),y:t.target.y()})},id:n.id,onDblClick:t=>{n.contentEditable&&(Lt.current={x:t.evt.clientX,y:t.evt.clientY},n.toggleEditMode(!0))},onDblTap:t=>{var e;if(n.contentEditable){const o=null===(e=t.evt.changedTouches)||void 0===e?void 0:e[0];Lt.current=o?{x:o.clientX,y:o.clientY}:null,n.toggleEditMode(!0)}},onTransformStart:t=>{var e,o;rt(!0),at.current=n.height,$t.current=n.width,Wt.current=t.target.position();const r=null===(e=t.target.getStage())||void 0===e?void 0:e.findOne("Transformer");Dt.current=null!==(o=null==r?void 0:r.getActiveAnchor())&&void 0!==o?o:null,Ht.current=n.a.rotation,_t.current=n.height},onTransform:t=>{var e;const o=t.target,r=(null===(e=o.getStage())||void 0===e?void 0:e.findOne("Transformer")).getActiveAnchor(),i="middle-left"===r||"middle-right"===r,a="top-center"===r||"bottom-center"===r,s=o.scaleX();if(i){const t=o.scaleX(),e=o.width()*t,r=d($t.current,n.fontSize);let i=e;e<r&&(i=r,Wt.current&&o.position(Wt.current)),o.width(i),o.scaleX(1),o.scaleY(1);const a=B(Object.assign(Object.assign({},n.toJSON()),{width:i}),{fontFamily:pt,color:yt,textOverflow:x.textOverflow}),s=O(a).height,l=x.textVerticalResizeEnabled?Math.max(s,at.current):s;o.height(l),n.set({width:o.width(),height:l,x:o.x(),y:o.y()})}else if(a){const t="resize"===x.textOverflow,e="number"==typeof n.lineHeight?n.lineHeight:1,r=t?Ot:e*n.fontSize,i=o.height()*o.scaleY();if(i<r){if(o.height(r),Wt.current){if("top-center"===Dt.current){const t=Ht.current*Math.PI/180,e=_t.current-r;o.x(Wt.current.x-e*Math.sin(t)),o.y(Wt.current.y+e*Math.cos(t))}else{o.position(Wt.current)}}}else{o.height(i)}o.scaleY(1),o.scaleX(1),_t.current=Math.max(r,i),n.set({x:o.x(),y:o.y(),height:o.height(),rotation:o.rotation()})}else{o.scaleX(1),o.scaleY(1),n.set({fontSize:n.fontSize*s,letterSpacing:n.letterSpacing,width:o.width()*s,x:o.x(),y:o.y(),rotation:o.rotation(),height:o.height()*s,shadowBlur:n.shadowBlur*s,shadowOffsetX:n.shadowOffsetX*s,shadowOffsetY:n.shadowOffsetY*s,strokeWidth:n.strokeWidth*s,text:D(n.text,s)})}Wt.current=t.target.position()},onTransformEnd:t=>{rt(!1),it(!0);const e=t.target.scaleX();t.target.scaleX(1),t.target.scaleY(1),n.set(Object.assign(Object.assign({},f(n,n.fontSize*e)),{width:t.target.width()*e,x:t.target.x(),y:t.target.y(),rotation:t.target.rotation(),text:D(n.text,e)}))}}),t(a,{ref:K,image:Q,x:n.a.x,y:n.a.y,offsetX:ct,offsetY:ct-Yt,listening:!1,rotation:n.a.rotation,width:n.a.width+2*ct,height:(n.a.width+2*ct)*((null!==(q=null==Q?void 0:Q.height)&&void 0!==q?q:0)/((null==Q?void 0:Q.width)||1)||1),visible:!Xt&&!xt,opacity:n.a.opacity,shadowEnabled:n.shadowEnabled,shadowBlur:n.shadowBlur,shadowOffsetX:n.shadowOffsetX,shadowOffsetY:n.shadowOffsetY,shadowColor:n.shadowColor,shadowOpacity:n.shadowOpacity,hideInExport:!n.showInExport,editModeEnabled:n._editModeEnabled||ot||Xt}),(Xt&&!xt||Jt)&&t(i,{x:n.a.x,y:n.a.y,rotation:n.a.rotation,offsetY:-Yt,children:t(M,{divProps:{style:{pointerEvents:"none"}},children:t(L,{dangerouslySetInnerHTML:{__html:wt},style:{pointerEvents:"none",opacity:n.a.opacity,textShadow:n.shadowEnabled?`${n.shadowOffsetX}px ${n.shadowOffsetY}px ${n.shadowBlur}px ${J(n.shadowColor,null!==(V=n.shadowOpacity)&&void 0!==V?V:1)}`:void 0}})})}),xt&&t(i,{x:n.a.x,y:n.a.y,rotation:n.a.rotation,offsetY:-Yt,children:t(M,{divProps:{style:{zIndex:20}},children:t(_,{element:n,onChange:t=>{const e=T({oldText:Y(n.text),newText:Y(t),element:n});n.set(Object.assign({text:t},c(n,e)))},onBlur:t=>{g(n)&&(n.set(h(n)),n.toggleEditMode(!1),Mt(!0))},clickCoords:Lt.current})})})]})});
1
+ import{jsx as t,Fragment as e,jsxs as o}from"react/jsx-runtime";import r from"react";import{observer as n}from"mobx-react-lite";import{Group as i,Image as a,Path as s,Rect as l}from"react-konva";import{scaledFontSizeAttrs as c,roundedFontSizeAttrs as f,roundedTextDecorationAttrs as d,textMinResizeWidth as h}from"../utils/px.js";import u from"konva";import{isAlive as g}from"mobx-state-tree";import{nodeAutorun as m}from"../utils/mobx.js";import{flags as x}from"../utils/flags.js";import{applyFilter as p}from"./apply-filters.js";import{getLineHeight as y,useFontFamiliesLoader as w,usePrevious as v}from"./text-element.js";import{getCurvePath as b}from"@polotno/core/text-html";import{useColor as E}from"./use-color.js";import{useWorkspaceStyle as S}from"./workspace-style.js";import{detectSize as O,detectLineRects as k,htmlToCanvas as z}from"../utils/html2canvas.js";import{generateBackgroundShapeFromRects as F}from"@polotno/core/background-shape";import{useFadeIn as j}from"./use-fadein.js";import{Html as M}from"react-konva-utils";import{incrementLoader as R,triggerLoadError as X}from"../utils/loader.js";import{removeTags as Y}from"@polotno/core/text";import*as I from"../utils/fonts.js";import{isTouchDevice as C}from"../utils/screen.js";import{getLimitedFontSize as T}from"./text-element/max-font-size.js";import{visiblePlaceholder as A}from"./text-element/placeholder.js";import{useDelayer as P}from"./use-delayer.js";import{getHtml as B}from"@polotno/core/text-html";import{hasMeasuredHeight as W,resolveTextBoxHeight as $}from"@polotno/core/text-types";import{normalizeRichTextHtml as D,extractFontFamiliesFromHtml as H,scaleRichTextFontSizesInHtml as _}from"../utils/rich-text-html.js";import{findFitFontSize as L}from"./text-element/fit-font-size.js";import{RichEditor as J,RichTextContainer as N,applyOpacityToColor as q,quillRef as V,createQuill as G,setQuillContent as K,setQuillFormats as Q,syncQuillFormatState as U,setCursorFromCoords as Z}from"./rich-editor.js";export{V as quillRef,G as createQuill,K as setQuillContent,Q as setQuillFormats,U as syncQuillFormatState,Z as setCursorFromCoords};function tt(t){const e=document.createElement("canvas"),o=e.getContext("2d");return null==o||o.drawImage(t,0,0,e.width,e.height),function(t){return!function(t){const e=t.getContext("2d").getImageData(0,0,t.width,t.height).data;for(let o=0;o<e.length;o+=4){if(0!==e[o+3]){return!0}}return!1}(t)}(e)}const et=/^((?!chrome|android).)*safari/i.test(navigator.userAgent),ot=navigator.userAgent.includes("Firefox");export const HTMLElement=n(({element:n,store:V})=>{var G,K;const{textOverflowIndicatorStyle:Q}=S(),U=r.useRef(null),[Z,rt]=r.useState(),[nt,it]=r.useState(!1),[at,st]=r.useState(!1),lt=r.useRef(n.height),ct=n.isSelected,ft=v(ct),dt=n.fontSize/3,{textVerticalResizeEnabled:ht}=x,ut=x.autoDeleteEmptyText,gt=v(n.fontFamily),mt=r.useMemo(()=>D(n.text,{fontSize:n.fontSize,fontFamily:n.fontFamily}),[n.text,n.fontSize,n.fontFamily]),xt=r.useMemo(()=>[...new Set([n.fontFamily,...H(mt)])].filter(Boolean),[n.fontFamily,mt]),[pt]=w(V,xt,n.fontStyle,n.fontWeight,n.text||n.placeholder),yt=n._editModeEnabled;j(U);const wt=pt?n.fontFamily:gt!==n.fontFamily?gt:"Arial",vt=E(n).fill,bt=B(n,{fontFamily:wt,color:vt,textOverflow:x.textOverflow}),Et=r.useRef([]),St=r.useRef(!0),[,Ot]=r.useReducer(t=>t+1,0);r.useEffect(()=>{const t=Et.current;t.length>0&&(Et.current=[],t.forEach(t=>t()))}),r.useEffect(()=>()=>{St.current=!1;const t=Et.current;t.length>0&&(Et.current=[],t.forEach(t=>t()))},[]);let{width:kt,height:zt}=function(t,e,o){return r.useMemo(()=>O(t),[t,e.width,o])}(bt,n,pt);r.useEffect(()=>{if(!pt){return}const t=(t,e,o,r)=>{const i=R(`text ${n.id}`),a=()=>{V.history.ignore(t,e,o).then(()=>{St.current?(Et.current.push(i),Ot()):i()})};r?queueMicrotask(a):a()};if(n.curveEnabled&&Math.abs(kt-n.width)>1&&!nt&&t(()=>{if(g(n)&&Math.abs(kt-n.width)>1){const t=n.x+n.width/2;n.set({width:kt,x:t-kt/2})}},!1,!0),!W(n)){return void t(()=>{g(n)&&(W(n)||n.set({height:zt}))},void 0,void 0,!0)}const{textOverflow:e}=x;if("change-font-size"!==e||nt||yt||n.curveEnabled){"resize"===e&&(ht&&n.height<zt&&!nt&&t(()=>{g(n)&&n.set({height:zt})},!1,!0),ht||n.height===zt||nt||t(()=>{g(n)&&n.set({height:zt})},!1,!0))}else{const e=L(n,{fontFamily:n.fontFamily,textOverflow:x.textOverflow});e.fontSize!==n.fontSize?t(()=>{if(!g(n)){return}const t=c(n,e.fontSize);void 0!==e.text&&e.text!==n.text&&(t.text=e.text),n.set(t)},!1,!0):n.height!==zt&&(ht&&n.height<zt?t(()=>{g(n)&&n.set({height:zt})},!1,!0):ht||t(()=>{g(n)&&n.set({height:zt})},!1,!0))}});const Ft=r.useMemo(()=>{const t={lastArgs:null,lastResult:null};return async function(e){return t.lastArgs&&t.lastResult&&(o=t.lastArgs,r=e,JSON.stringify(o)===JSON.stringify(r))||(t.lastResult=await z(e),t.lastArgs=Object.assign({},e)),t.lastResult;var o,r}},[]),jt=r.useRef(0),Mt=r.useRef(null);r.useEffect(()=>{nt||yt||(async()=>{jt.current++;const t=jt.current;let e=R(`text ${n.id} ${t}`);Mt.current&&Mt.current(),Mt.current=e,st(!0);let o=null;const r=et?5:1;for(let a=0;a<r;a++){const e=a>0?Ft:z;try{if(o=await e({skipCache:a>0,html:bt,width:kt||n.width||1,height:$(n,zt)||1,fontFamily:wt,fontFamilies:H(bt),resolveFont:t=>V.fonts.find(e=>e.fontFamily===t)||I.globalFonts.find(e=>e.fontFamily===t),padding:dt,pixelRatio:V._elementsPixelRatio,font:V.fonts.find(t=>t.fontFamily===wt)||I.globalFonts.find(t=>t.fontFamily===wt)}),t!==jt.current){return}if((et||ot)&&o&&tt(o)){await new Promise(t=>setTimeout(t,50*(a+1)));continue}break}catch(i){console.error(i),X(`Error rendering rich text with id ${n.id}`);break}}o?rt(o):e?(e(),e=null):console.error("Finish function is called twice!"),st(!1)})()},[bt,nt,zt,yt,wt,n.height,V._elementsPixelRatio,pt]);const[Rt,Xt]=P(at,300),[Yt]=P(nt,300,!0),It=Yt||Rt;r.useEffect(()=>{var t;if(!It){return m(n,()=>{const t=U.current;p(t,n)})}null===(t=U.current)||void 0===t||t.clearCache()},[Z,It,n.shadowColor,n.shadowOffsetX,n.shadowOffsetY,n.shadowOpacity]),r.useEffect(()=>{Z&&!at&&Mt.current&&(Mt.current(),Mt.current=null)},[Z,at]),r.useLayoutEffect(()=>{if(!pt){return}if(!n.curveEnabled){return}const t=new u.TextPath({data:b(n.a.width,n.a.height,n.curvePower,n.a.fontSize),text:Y(n.text),letterSpacing:n.letterSpacing*n.a.fontSize,fontSize:n.a.fontSize,fontFamily:n.fontFamily,fontWeight:n.fontWeight,fontStyle:n.fontStyle,align:"center",textBaseline:"middle",fill:n.fill}),e=t.getSelfRect().width;if(e){const t=e-n.a.width,o=n.a.rotation*Math.PI/180,r=-t/2*Math.cos(o),i=-t/2*Math.sin(o);queueMicrotask(()=>{g(n)&&n.set({width:e,x:n.a.x+r,y:n.a.y+i})})}t.destroy()},[pt,n.curveEnabled,n.curvePower,n.text,n.fontSize,n.fontFamily,n.fontWeight,n.fontStyle,n.letterSpacing]),r.useEffect(()=>()=>{Mt.current&&Mt.current()},[]),r.useEffect(()=>{ft&&!ct&&ut&&""===Y(n.text)&&n.removable&&!A(n.placeholder)&&V.deleteElements([n.id])},[ut,n.placeholder,n.removable,n.text,ct,ft]);const Ct=$(n,zt);let Tt=0;"middle"===n.verticalAlign&&(Tt=(Ct-zt)/2),"bottom"===n.verticalAlign&&(Tt=Ct-zt);const At=y({fontLoaded:pt,fontFamily:n.fontFamily,fontSize:n.fontSize,lineHeight:n.lineHeight}),Pt=n.backgroundPadding*(n.fontSize*At*.5),Bt=n.backgroundCornerRadius*(n.fontSize*At*.5),Wt=r.useMemo(()=>{if(!n.backgroundEnabled||n.curveEnabled||n.legacyBackground){return""}const t=k(bt);if(0===t.length){return""}const e=t.map(t=>({left:t.left+dt,right:t.right+dt,top:t.top+dt,bottom:t.bottom+dt}));return F({rects:e,padding:Pt,cornerRadius:Bt})},[n.backgroundEnabled,n.curveEnabled,n.legacyBackground,bt,pt,Pt,Bt,dt]),$t=C(),Dt=b(n.a.width,zt,n.curvePower,n.fontSize),Ht=r.useRef(null),_t=r.useRef(n.width),Lt=r.useRef(null),Jt=r.useRef(0),Nt=r.useRef(0),qt=r.useRef(null),Vt=yt&&n.strokeWidth>0&&!n.curveEnabled,Gt=kt>0?(n.a.width+2*dt)/(kt+2*dt):1;return o(e,{children:[n.curveEnabled||n.legacyBackground?t(l,{x:n.a.x,y:n.a.y,offsetX:Pt/Gt,offsetY:Pt/Gt,rotation:n.a.rotation,scaleX:Gt,scaleY:Gt,hideInExport:!n.showInExport,listening:!1,visible:n.backgroundEnabled,opacity:n.backgroundOpacity*n.a.opacity,fill:n.backgroundColor,width:n.width+2*Pt,height:Ct+2*Pt,cornerRadius:Bt}):t(s,{name:"html-background",x:n.a.x,y:n.a.y,offsetX:dt/Gt,offsetY:(dt-Tt)/Gt,rotation:n.a.rotation,scaleX:Gt,scaleY:Gt,hideInExport:!n.showInExport,listening:!1,visible:n.backgroundEnabled&&Wt.length>0,opacity:n.backgroundOpacity*n.a.opacity,fill:n.backgroundColor,data:Wt}),t(s,{x:n.a.x,y:n.a.y,rotation:n.a.rotation,data:Dt,stroke:Q.stroke,strokeWidth:1,visible:!1}),t(l,{ref:U,name:"element",x:n.a.x,y:n.a.y,listening:n.selectable,rotation:n.a.rotation,width:n.a.width,height:n.a.height,visible:!It,draggable:$t?n.draggable&&ct:n.draggable,preventDefault:!$t||ct,opacity:yt?0:n.a.opacity,hideInExport:!n.showInExport,onDragMove:t=>{n.set({x:t.target.x(),y:t.target.y()})},onDragEnd:t=>{n.set({x:t.target.x(),y:t.target.y()})},id:n.id,onDblClick:t=>{n.contentEditable&&(qt.current={x:t.evt.clientX,y:t.evt.clientY},n.toggleEditMode(!0))},onDblTap:t=>{var e;if(n.contentEditable){const o=null===(e=t.evt.changedTouches)||void 0===e?void 0:e[0];qt.current=o?{x:o.clientX,y:o.clientY}:null,n.toggleEditMode(!0)}},onTransformStart:t=>{var e,o;it(!0),lt.current=n.height,_t.current=n.width,Ht.current=t.target.position();const r=null===(e=t.target.getStage())||void 0===e?void 0:e.findOne("Transformer");Lt.current=null!==(o=null==r?void 0:r.getActiveAnchor())&&void 0!==o?o:null,Jt.current=n.a.rotation,Nt.current=n.height},onTransform:t=>{var e;const o=t.target,r=(null===(e=o.getStage())||void 0===e?void 0:e.findOne("Transformer")).getActiveAnchor(),i="middle-left"===r||"middle-right"===r,a="top-center"===r||"bottom-center"===r,s=o.scaleX();if(i){const t=o.scaleX(),e=o.width()*t,r=h(_t.current,n.fontSize);let i=e;e<r&&(i=r,Ht.current&&o.position(Ht.current)),o.width(i),o.scaleX(1),o.scaleY(1);const a=B(Object.assign(Object.assign({},n.toJSON()),{width:i}),{fontFamily:wt,color:vt,textOverflow:x.textOverflow}),s=O(a).height,l=x.textVerticalResizeEnabled?Math.max(s,lt.current):s;o.height(l),n.set({width:o.width(),height:l,x:o.x(),y:o.y()})}else if(a){const t="resize"===x.textOverflow,e="number"==typeof n.lineHeight?n.lineHeight:1,r=t?zt:e*n.fontSize,i=o.height()*o.scaleY();if(i<r){if(o.height(r),Ht.current){if("top-center"===Lt.current){const t=Jt.current*Math.PI/180,e=Nt.current-r;o.x(Ht.current.x-e*Math.sin(t)),o.y(Ht.current.y+e*Math.cos(t))}else{o.position(Ht.current)}}}else{o.height(i)}o.scaleY(1),o.scaleX(1),Nt.current=Math.max(r,i),n.set({x:o.x(),y:o.y(),height:o.height(),rotation:o.rotation()})}else{o.scaleX(1),o.scaleY(1),n.set({fontSize:n.fontSize*s,letterSpacing:n.letterSpacing,width:o.width()*s,x:o.x(),y:o.y(),rotation:o.rotation(),height:o.height()*s,shadowBlur:n.shadowBlur*s,shadowOffsetX:n.shadowOffsetX*s,shadowOffsetY:n.shadowOffsetY*s,strokeWidth:n.strokeWidth*s,text:_(n.text,s)})}Ht.current=t.target.position()},onTransformEnd:t=>{it(!1),st(!0);const e=t.target.scaleX();t.target.scaleX(1),t.target.scaleY(1),n.set(Object.assign(Object.assign({},f(n,n.fontSize*e)),{width:t.target.width()*e,x:t.target.x(),y:t.target.y(),rotation:t.target.rotation(),text:_(n.text,e)}))}}),t(a,{ref:U,image:Z,x:n.a.x,y:n.a.y,offsetX:dt,offsetY:dt-Tt,listening:!1,rotation:n.a.rotation,width:n.a.width+2*dt,height:(n.a.width+2*dt)*((null!==(G=null==Z?void 0:Z.height)&&void 0!==G?G:0)/((null==Z?void 0:Z.width)||1)||1),visible:!It&&!yt,opacity:n.a.opacity,shadowEnabled:n.shadowEnabled,shadowBlur:n.shadowBlur,shadowOffsetX:n.shadowOffsetX,shadowOffsetY:n.shadowOffsetY,shadowColor:n.shadowColor,shadowOpacity:n.shadowOpacity,hideInExport:!n.showInExport,editModeEnabled:n._editModeEnabled||nt||It}),(It&&!yt||Vt)&&t(i,{x:n.a.x,y:n.a.y,rotation:n.a.rotation,offsetY:-Tt,children:t(M,{divProps:{style:{pointerEvents:"none"}},children:t(N,{dangerouslySetInnerHTML:{__html:bt},style:{pointerEvents:"none",opacity:n.a.opacity,textShadow:n.shadowEnabled?`${n.shadowOffsetX}px ${n.shadowOffsetY}px ${n.shadowBlur}px ${q(n.shadowColor,null!==(K=n.shadowOpacity)&&void 0!==K?K:1)}`:void 0}})})}),yt&&t(i,{x:n.a.x,y:n.a.y,rotation:n.a.rotation,offsetY:-Tt,children:t(M,{divProps:{style:{zIndex:20}},children:t(J,{element:n,onChange:t=>{const e=T({oldText:Y(n.text),newText:Y(t),element:n});n.set(Object.assign({text:t},c(n,e)))},onBlur:t=>{g(n)&&(n.set(d(n)),n.toggleEditMode(!1),Xt(!0))},clickCoords:qt.current})})})]})});
@@ -1 +1 @@
1
- var t=this&&this.__rest||function(t,e){var r={};for(var o in t){Object.prototype.hasOwnProperty.call(t,o)&&e.indexOf(o)<0&&(r[o]=t[o])}if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(o=Object.getOwnPropertySymbols(t);n<o.length;n++){e.indexOf(o[n])<0&&Object.prototype.propertyIsEnumerable.call(t,o[n])&&(r[o[n]]=t[o[n]])}}return r};import{jsx as e,Fragment as r,jsxs as o}from"react/jsx-runtime";import n from"react";import{observer as i}from"mobx-react-lite";import{Group as a,Path as s,Rect as l,Shape as c}from"react-konva";import{nodeAutorun as h}from"../utils/mobx.js";import{isAlive as d}from"mobx-state-tree";import{Html as f}from"react-konva-utils";import{layout as u,drawLayout as g}from"render-tag";import{layoutTextOnPath as m,drawTextOnPathLayout as x}from"render-tag/path";import{scaledFontSizeAttrs as p,roundedFontSizeAttrs as y,roundedTextDecorationAttrs as b,textMinResizeWidth as w}from"../utils/px.js";import{flags as v}from"../utils/flags.js";import{applyFilter as O}from"./apply-filters.js";import{getLineHeight as E,usePrevious as S}from"./text-element.js";import{useFontSpecsLoader as j}from"./text-element/font-specs-loader.js";import{getHtml as M,getCurvePath as z,getCurveTextHeight as k}from"@polotno/core/text-html";import{useColor as R}from"./use-color.js";import{isGradient as Y}from"@polotno/core/gradient";import{detectSize as X}from"@polotno/core/measure-html";import{generateBackgroundShapeFromRects as F}from"@polotno/core/background-shape";import{useFadeIn as T}from"./use-fadein.js";import{incrementLoader as I}from"../utils/loader.js";import{removeTags as P}from"@polotno/core/text";import{isTouchDevice as C}from"../utils/screen.js";import{getLimitedFontSize as B}from"./text-element/max-font-size.js";import{normalizeRichTextHtml as A,extractFontSpecsFromHtml as W,scaleRichTextFontSizesInHtml as D}from"../utils/rich-text-html.js";import{RichEditor as J}from"./rich-editor.js";import{findFitFontSize as N}from"./text-element/fit-font-size.js";import{visiblePlaceholder as $}from"./text-element/placeholder.js";import{wrapHtmlForRenderTag as _}from"@polotno/core/reset-style";import{xmlEscape as L}from"@polotno/core/xml";export{_ as wrapHtmlForRenderTag};export const RenderTagElement=i(({element:i,store:H})=>{var V;const q=n.useRef(null),G=n.useRef(null),[K,Q]=n.useState(!1),U=n.useRef(i.height),Z=i.isSelected,tt=S(Z),{textVerticalResizeEnabled:et}=v,rt=v.autoDeleteEmptyText,ot=S(i.fontFamily),nt=n.useMemo(()=>A(i.text,{fontSize:i.fontSize,fontFamily:i.fontFamily}),[i.text,i.fontSize,i.fontFamily]),it=n.useMemo(()=>W(nt,{fontFamily:i.fontFamily,fontWeight:i.fontWeight,fontStyle:i.fontStyle}),[nt,i.fontFamily,i.fontWeight,i.fontStyle]),[at]=j(H,it,i.text||i.placeholder),st=i._editModeEnabled;T(q);const lt=at?i.fontFamily:ot&&ot!==i.fontFamily?ot:"Arial",ct=R(i).fill,ht=Y(i.fill),dt=Y(i.stroke)&&!!i.strokeWidth,ft=!!i.strokeWidth&&(dt||ht),ut="ellipsis"===v.textOverflow&&!i.curveEnabled&&!!i.height&&!ft,gt=$(i.placeholder),mt=!P(i.text)&&!!gt,xt=mt?L(gt):i.text,pt=mt?.6:i.a.opacity,yt=M(mt?Object.assign(Object.assign({},i.toJSON()),{text:xt}):i,{fontFamily:lt,color:ct,forEditor:!ut,textOverflow:v.textOverflow}),bt=i.width||1,wt=i.curveEnabled,vt=function(t,e,r,o){return n.useMemo(()=>{if(o){return null}try{return u({html:_(t),width:Math.max(1,e),accuracy:"performance"})}catch(r){return console.error("render-tag layout failed:",r),null}},[t,e,r,o])}(yt,bt,at,wt),Ot=function(t,e,r){return n.useMemo(()=>{if(!e.curveEnabled){return null}const r=e.width||1,o=k(e),n=z(r,o,e.curvePower,e.fontSize);try{return m({html:_(t),path:n,align:"center",textBaseline:"middle"})}catch(i){return console.error("render-tag/path layoutTextOnPath failed:",i),null}},[r,e.curveEnabled,e.curvePower,e.fontSize,e.width,e.height,t])}(yt,i,at),Et=E({fontLoaded:at,fontFamily:i.fontFamily,fontSize:i.fontSize,lineHeight:i.lineHeight}),St=wt?0:Math.max(null!==(V=null==vt?void 0:vt.height)&&void 0!==V?V:0,i.fontSize*Et),jt=Ot?Ot.bounds:null,Mt=n.useMemo(()=>vt?vt.lines.map(t=>({left:t.bounds.x,right:t.bounds.x+t.bounds.width,top:t.bounds.y,bottom:t.bounds.y+t.bounds.height})):[],[vt]),zt=n.useRef([]),kt=n.useRef(!0),[,Rt]=n.useReducer(t=>t+1,0);n.useEffect(()=>{const t=zt.current;t.length>0&&(zt.current=[],t.forEach(t=>t()))});const Yt=n.useCallback((t,e,r,o)=>{const n=I(`text ${i.id}`),a=()=>{H.history.ignore(t,e,r).then(()=>{kt.current?(zt.current.push(n),Rt()):n()})};o?queueMicrotask(a):a()},[i.id,H]);n.useEffect(()=>{if(!at){return}if(!vt){return}if(!i.height){return void Yt(()=>{d(i)&&(i.height||i.set({height:St}))},void 0,void 0,!0)}if(H.isPlaying){return}const{textOverflow:t}=v,e=i.height!==St&&(!et||i.height<St),r=()=>Yt(()=>{d(i)&&i.set({height:St})},!1,!0);if("change-font-size"!==t||K||st||i.curveEnabled){"resize"===t&&e&&!K&&r()}else{const t=N(mt?Object.assign(Object.assign({},i.toJSON()),{text:xt,toJSON:()=>Object.assign(Object.assign({},i.toJSON()),{text:xt})}):i,{fontFamily:lt,color:ct,forEditor:!0},t=>{try{return u({html:_(t),width:bt,accuracy:"performance"}).height}catch(V){return X(t).height}});t.fontSize!==i.fontSize?Yt(()=>{if(!d(i)){return}const e=p(i,t.fontSize);void 0!==t.text&&t.text!==i.text&&(e.text=t.text),i.set(e)},!1,!0):e&&r()}}),n.useEffect(()=>()=>{kt.current=!1;const t=zt.current;t.length>0&&(zt.current=[],t.forEach(t=>t()))},[]),n.useLayoutEffect(()=>{if(!at||!i.curveEnabled||K){return}if(!jt||!jt.width){return}const t=t=>t&&et?Math.max(t,jt.height):jt.height;Math.abs(jt.width-i.width)<1&&Math.abs(t(i.height)-i.height)<1||Yt(()=>{if(!d(i)){return}const e=jt.width-i.width,r=t(i.height),o=r-i.height;if(Math.abs(e)<1&&Math.abs(o)<1){return}const n=i.a.rotation*Math.PI/180,a=-e/2*Math.cos(n),s=-e/2*Math.sin(n);i.set({width:jt.width,height:r,x:i.a.x+a,y:i.a.y+s})},!1,!0,!0)},[at,i.curveEnabled,jt,K,et,Yt]),n.useEffect(()=>{tt&&!Z&&rt&&""===P(i.text)&&i.removable&&!$(i.placeholder)&&H.deleteElements([i.id])},[rt,i.placeholder,i.removable,i.text,Z,tt]),n.useEffect(()=>h(i,()=>{const t=q.current;t&&O(t,i)}),[vt,Ot,i.a.width,i.a.height,i.shadowColor,i.shadowOffsetX,i.shadowOffsetY,i.shadowOpacity]);let Xt=0;wt||"middle"!==i.verticalAlign?wt||"bottom"!==i.verticalAlign||(Xt=i.height-St):Xt=(i.height-St)/2;const Ft=i.backgroundPadding*(i.fontSize*Et*.5),Tt=i.backgroundCornerRadius*(i.fontSize*Et*.5),It=n.useMemo(()=>!i.backgroundEnabled||i.curveEnabled||i.legacyBackground||0===Mt.length?"":F({rects:Mt,padding:Ft,cornerRadius:Tt}),[i.backgroundEnabled,i.curveEnabled,i.legacyBackground,Mt,Ft,Tt]),Pt=C(),Ct=n.useRef(null),Bt=n.useRef(i.width),At=n.useRef(null),Wt=n.useRef(null),Dt=n.useRef(null),Jt=n.useRef(0),Nt=n.useRef(0),$t=i.width>0?i.a.width/i.width:1;return o(r,{children:[i.curveEnabled||i.legacyBackground?e(l,{x:i.a.x,y:i.a.y,offsetX:Ft/$t,offsetY:Ft/$t,rotation:i.a.rotation,scaleX:$t,scaleY:$t,hideInExport:!i.showInExport,listening:!1,visible:i.backgroundEnabled,opacity:i.backgroundOpacity*pt,fill:i.backgroundColor,width:i.width+2*Ft,height:i.height+2*Ft,cornerRadius:Tt}):e(s,{name:"rendertag-background",x:i.a.x,y:i.a.y,offsetY:-Xt/$t,rotation:i.a.rotation,scaleX:$t,scaleY:$t,hideInExport:!i.showInExport,listening:!1,visible:i.backgroundEnabled&&It.length>0,opacity:i.backgroundOpacity*pt,fill:i.backgroundColor,data:It}),e(c,{ref:q,name:"rendertag-text",x:i.a.x,y:i.a.y,rotation:i.a.rotation,scaleX:$t,scaleY:$t,offsetY:$t>0?-Xt/$t:0,width:i.width,height:Math.max(i.height,St),listening:!1,visible:!st&&!!(wt?Ot:vt),opacity:pt,shadowEnabled:i.shadowEnabled,shadowBlur:i.shadowBlur,shadowOffsetX:i.shadowOffsetX,shadowOffsetY:i.shadowOffsetY,shadowColor:i.shadowColor,shadowOpacity:i.shadowOpacity,hideInExport:!i.showInExport,sceneFunc:(t,e)=>{const r=t._context;if(r){try{if(wt){if(!Ot||!jt){return}const t=(i.width-jt.width)/2-jt.x;r.save(),r.translate(t,-jt.y),x({layout:Ot,ctx:r}),r.restore()}else{if(!vt){return}g({layout:vt,width:bt,ctx:r,pixelRatio:1})}}catch(o){console.error("render-tag draw failed:",o)}}}}),e(l,{ref:G,name:"element",x:i.a.x,y:i.a.y,listening:i.selectable,rotation:i.a.rotation,width:i.a.width,height:i.a.height,visible:!st,draggable:Pt?i.draggable&&Z:i.draggable,preventDefault:!Pt||Z,opacity:0,hideInExport:!0,id:i.id,onDragMove:t=>{i.set({x:t.target.x(),y:t.target.y()})},onDragEnd:t=>{i.set({x:t.target.x(),y:t.target.y()})},onDblClick:t=>{i.contentEditable&&(Wt.current={x:t.evt.clientX,y:t.evt.clientY},i.toggleEditMode(!0))},onDblTap:t=>{var e;if(i.contentEditable){const r=null===(e=t.evt.changedTouches)||void 0===e?void 0:e[0];Wt.current=r?{x:r.clientX,y:r.clientY}:null,i.toggleEditMode(!0)}},onTransformStart:t=>{var e,r;Q(!0),U.current=i.height,Bt.current=i.width,At.current=null,Ct.current=t.target.position();const o=null===(e=t.target.getStage())||void 0===e?void 0:e.findOne("Transformer");Dt.current=null!==(r=null==o?void 0:o.getActiveAnchor())&&void 0!==r?r:null,Jt.current=i.a.rotation,Nt.current=i.height},onTransform:e=>{var r;const o=e.target,n=(null===(r=o.getStage())||void 0===r?void 0:r.findOne("Transformer")).getActiveAnchor(),a="middle-left"===n||"middle-right"===n,s="top-center"===n||"bottom-center"===n,l=o.scaleX();if(a){const e=o.scaleX(),n=o.width()*e;let a=Math.max(n,w(Bt.current,i.fontSize));const s=i.toJSON();let l=0;if(i.curveEnabled){l=k(Object.assign(Object.assign({},s),{width:a}))}else{const{x:e,y:o,width:n,height:i}=s,c=t(s,["x","y","width","height"]),h=`${JSON.stringify(c)}|${lt}|${at}|${ct}`;if(At.current&&At.current.signature===h&&a<=At.current.width){a=At.current.width,l=At.current.height}else{const t=t=>{const e=M(Object.assign(Object.assign({},s),{text:xt,width:t}),{fontFamily:lt,color:ct,forEditor:!0});try{return u({html:_(e),width:t,accuracy:"performance"})}catch(r){return{height:X(e).height,lines:[]}}};let e=t(a);const o=Math.max(0,...e.lines.map(t=>t.bounds.x+t.bounds.width));o>a+.5&&o<=Bt.current+.5&&(a=Math.min(Math.ceil(o),Bt.current),e=t(a),At.current={signature:h,width:a,height:e.height}),l=e.height}}a>n&&Ct.current&&o.position(Ct.current),o.width(a),o.scaleX(1),o.scaleY(1);let c=v.textVerticalResizeEnabled?Math.max(l,U.current):l;"ellipsis"===v.textOverflow&&(c=U.current),o.height(c),i.set({width:o.width(),height:c,x:o.x(),y:o.y()})}else if(s){const t="resize"===v.textOverflow?wt?(null==jt?void 0:jt.height)||i.fontSize:St:Et*i.fontSize,e=o.height()*o.scaleY();if(e<t){if(o.height(t),Ct.current){if("top-center"===Dt.current){const e=Jt.current*Math.PI/180,r=Nt.current-t;o.x(Ct.current.x-r*Math.sin(e)),o.y(Ct.current.y+r*Math.cos(e))}else{o.position(Ct.current)}}}else{o.height(e)}o.scaleY(1),o.scaleX(1),Nt.current=Math.max(t,e),i.set({x:o.x(),y:o.y(),height:o.height(),rotation:o.rotation()})}else{o.scaleX(1),o.scaleY(1),i.set({fontSize:i.fontSize*l,letterSpacing:i.letterSpacing,width:o.width()*l,x:o.x(),y:o.y(),rotation:o.rotation(),height:o.height()*l,shadowBlur:i.shadowBlur*l,shadowOffsetX:i.shadowOffsetX*l,shadowOffsetY:i.shadowOffsetY*l,strokeWidth:i.strokeWidth*l,text:D(i.text,l)})}Ct.current=e.target.position()},onTransformEnd:t=>{Q(!1);const e=t.target.scaleX();t.target.scaleX(1),t.target.scaleY(1),i.set(Object.assign(Object.assign({},y(i,i.fontSize*e)),{width:t.target.width()*e,x:t.target.x(),y:t.target.y(),rotation:t.target.rotation(),text:D(i.text,e)}))}}),st&&e(a,{x:i.a.x,y:i.a.y,rotation:i.a.rotation,offsetY:-Xt,children:e(f,{divProps:{style:{zIndex:20}},children:e(J,{element:i,onChange:t=>{const e=B({oldText:P(i.text),newText:P(t),element:i});i.set(Object.assign({text:t},p(i,e)))},onBlur:()=>{d(i)&&(i.set(b(i)),i.toggleEditMode(!1))},clickCoords:Wt.current})})})]})});
1
+ var t=this&&this.__rest||function(t,e){var r={};for(var o in t){Object.prototype.hasOwnProperty.call(t,o)&&e.indexOf(o)<0&&(r[o]=t[o])}if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(o=Object.getOwnPropertySymbols(t);n<o.length;n++){e.indexOf(o[n])<0&&Object.prototype.propertyIsEnumerable.call(t,o[n])&&(r[o[n]]=t[o[n]])}}return r};import{jsx as e,Fragment as r,jsxs as o}from"react/jsx-runtime";import n from"react";import{observer as i}from"mobx-react-lite";import{Group as a,Path as s,Rect as l,Shape as c}from"react-konva";import{nodeAutorun as h}from"../utils/mobx.js";import{isAlive as d}from"mobx-state-tree";import{Html as f}from"react-konva-utils";import{layout as u,drawLayout as g}from"render-tag";import{layoutTextOnPath as m,drawTextOnPathLayout as x}from"render-tag/path";import{scaledFontSizeAttrs as p,roundedFontSizeAttrs as y,roundedTextDecorationAttrs as b,textMinResizeWidth as w}from"../utils/px.js";import{flags as v}from"../utils/flags.js";import{applyFilter as O}from"./apply-filters.js";import{getLineHeight as E,usePrevious as S}from"./text-element.js";import{useFontSpecsLoader as j}from"./text-element/font-specs-loader.js";import{getHtml as M,getCurvePath as z,getCurveTextHeight as k}from"@polotno/core/text-html";import{useColor as R}from"./use-color.js";import{isGradient as Y}from"@polotno/core/gradient";import{detectSize as X}from"@polotno/core/measure-html";import{generateBackgroundShapeFromRects as F}from"@polotno/core/background-shape";import{useFadeIn as T}from"./use-fadein.js";import{incrementLoader as I}from"../utils/loader.js";import{removeTags as P}from"@polotno/core/text";import{isTouchDevice as C}from"../utils/screen.js";import{getLimitedFontSize as B}from"./text-element/max-font-size.js";import{normalizeRichTextHtml as A,extractFontSpecsFromHtml as W,scaleRichTextFontSizesInHtml as D}from"../utils/rich-text-html.js";import{RichEditor as J}from"./rich-editor.js";import{findFitFontSize as N}from"./text-element/fit-font-size.js";import{visiblePlaceholder as $}from"./text-element/placeholder.js";import{wrapHtmlForRenderTag as _}from"@polotno/core/reset-style";import{xmlEscape as L}from"@polotno/core/xml";import{hasMeasuredHeight as H,resolveTextBoxHeight as V}from"@polotno/core/text-types";export{_ as wrapHtmlForRenderTag};export const RenderTagElement=i(({element:i,store:q})=>{var G;const K=n.useRef(null),Q=n.useRef(null),[U,Z]=n.useState(!1),tt=n.useRef(i.height),et=i.isSelected,rt=S(et),{textVerticalResizeEnabled:ot}=v,nt=v.autoDeleteEmptyText,it=S(i.fontFamily),at=n.useMemo(()=>A(i.text,{fontSize:i.fontSize,fontFamily:i.fontFamily}),[i.text,i.fontSize,i.fontFamily]),st=n.useMemo(()=>W(at,{fontFamily:i.fontFamily,fontWeight:i.fontWeight,fontStyle:i.fontStyle}),[at,i.fontFamily,i.fontWeight,i.fontStyle]),[lt]=j(q,st,i.text||i.placeholder),ct=i._editModeEnabled;T(K);const ht=lt?i.fontFamily:it&&it!==i.fontFamily?it:"Arial",dt=R(i).fill,ft=Y(i.fill),ut=Y(i.stroke)&&!!i.strokeWidth,gt=!!i.strokeWidth&&(ut||ft),mt="ellipsis"===v.textOverflow&&!i.curveEnabled&&H(i)&&!gt,xt=$(i.placeholder),pt=!P(i.text)&&!!xt,yt=pt?L(xt):i.text,bt=pt?.6:i.a.opacity,wt=M(pt?Object.assign(Object.assign({},i.toJSON()),{text:yt}):i,{fontFamily:ht,color:dt,forEditor:!mt,textOverflow:v.textOverflow}),vt=i.width||1,Ot=i.curveEnabled,Et=function(t,e,r,o){return n.useMemo(()=>{if(o){return null}try{return u({html:_(t),width:Math.max(1,e),accuracy:"performance"})}catch(r){return console.error("render-tag layout failed:",r),null}},[t,e,r,o])}(wt,vt,lt,Ot),St=function(t,e,r){return n.useMemo(()=>{if(!e.curveEnabled){return null}const r=e.width||1,o=k(e),n=z(r,o,e.curvePower,e.fontSize);try{return m({html:_(t),path:n,align:"center",textBaseline:"middle"})}catch(i){return console.error("render-tag/path layoutTextOnPath failed:",i),null}},[r,e.curveEnabled,e.curvePower,e.fontSize,e.width,e.height,t])}(wt,i,lt),jt=E({fontLoaded:lt,fontFamily:i.fontFamily,fontSize:i.fontSize,lineHeight:i.lineHeight}),Mt=Ot?0:Math.max(null!==(G=null==Et?void 0:Et.height)&&void 0!==G?G:0,i.fontSize*jt),zt=St?St.bounds:null,kt=n.useMemo(()=>Et?Et.lines.map(t=>({left:t.bounds.x,right:t.bounds.x+t.bounds.width,top:t.bounds.y,bottom:t.bounds.y+t.bounds.height})):[],[Et]),Rt=n.useRef([]),Yt=n.useRef(!0),[,Xt]=n.useReducer(t=>t+1,0);n.useEffect(()=>{const t=Rt.current;t.length>0&&(Rt.current=[],t.forEach(t=>t()))});const Ft=n.useCallback((t,e,r,o)=>{const n=I(`text ${i.id}`),a=()=>{q.history.ignore(t,e,r).then(()=>{Yt.current?(Rt.current.push(n),Xt()):n()})};o?queueMicrotask(a):a()},[i.id,q]);n.useEffect(()=>{if(!lt){return}if(!Et){return}if(!H(i)){return void Ft(()=>{d(i)&&(H(i)||i.set({height:Mt}))},void 0,void 0,!0)}if(q.isPlaying){return}const{textOverflow:t}=v,e=i.height!==Mt&&(!ot||i.height<Mt),r=()=>Ft(()=>{d(i)&&i.set({height:Mt})},!1,!0);if("change-font-size"!==t||U||ct||i.curveEnabled){"resize"===t&&e&&!U&&r()}else{const t=N(pt?Object.assign(Object.assign({},i.toJSON()),{text:yt,toJSON:()=>Object.assign(Object.assign({},i.toJSON()),{text:yt})}):i,{fontFamily:ht,color:dt,forEditor:!0},t=>{try{return u({html:_(t),width:vt,accuracy:"performance"}).height}catch(G){return X(t).height}});t.fontSize!==i.fontSize?Ft(()=>{if(!d(i)){return}const e=p(i,t.fontSize);void 0!==t.text&&t.text!==i.text&&(e.text=t.text),i.set(e)},!1,!0):e&&r()}}),n.useEffect(()=>()=>{Yt.current=!1;const t=Rt.current;t.length>0&&(Rt.current=[],t.forEach(t=>t()))},[]),n.useLayoutEffect(()=>{if(!lt||!i.curveEnabled||U){return}if(!zt||!zt.width){return}const t=t=>t&&ot?Math.max(t,zt.height):zt.height;Math.abs(zt.width-i.width)<1&&Math.abs(t(i.height)-i.height)<1||Ft(()=>{if(!d(i)){return}const e=zt.width-i.width,r=t(i.height),o=r-i.height;if(Math.abs(e)<1&&Math.abs(o)<1){return}const n=i.a.rotation*Math.PI/180,a=-e/2*Math.cos(n),s=-e/2*Math.sin(n);i.set({width:zt.width,height:r,x:i.a.x+a,y:i.a.y+s})},!1,!0,!0)},[lt,i.curveEnabled,zt,U,ot,Ft]),n.useEffect(()=>{rt&&!et&&nt&&""===P(i.text)&&i.removable&&!$(i.placeholder)&&q.deleteElements([i.id])},[nt,i.placeholder,i.removable,i.text,et,rt]),n.useEffect(()=>h(i,()=>{const t=K.current;t&&O(t,i)}),[Et,St,i.a.width,i.a.height,i.shadowColor,i.shadowOffsetX,i.shadowOffsetY,i.shadowOpacity]);const Tt=V(i,Mt);let It=0;Ot||"middle"!==i.verticalAlign?Ot||"bottom"!==i.verticalAlign||(It=Tt-Mt):It=(Tt-Mt)/2;const Pt=i.backgroundPadding*(i.fontSize*jt*.5),Ct=i.backgroundCornerRadius*(i.fontSize*jt*.5),Bt=n.useMemo(()=>!i.backgroundEnabled||i.curveEnabled||i.legacyBackground||0===kt.length?"":F({rects:kt,padding:Pt,cornerRadius:Ct}),[i.backgroundEnabled,i.curveEnabled,i.legacyBackground,kt,Pt,Ct]),At=C(),Wt=n.useRef(null),Dt=n.useRef(i.width),Jt=n.useRef(null),Nt=n.useRef(null),$t=n.useRef(null),_t=n.useRef(0),Lt=n.useRef(0),Ht=i.width>0?i.a.width/i.width:1;return o(r,{children:[i.curveEnabled||i.legacyBackground?e(l,{x:i.a.x,y:i.a.y,offsetX:Pt/Ht,offsetY:Pt/Ht,rotation:i.a.rotation,scaleX:Ht,scaleY:Ht,hideInExport:!i.showInExport,listening:!1,visible:i.backgroundEnabled,opacity:i.backgroundOpacity*bt,fill:i.backgroundColor,width:i.width+2*Pt,height:Tt+2*Pt,cornerRadius:Ct}):e(s,{name:"rendertag-background",x:i.a.x,y:i.a.y,offsetY:-It/Ht,rotation:i.a.rotation,scaleX:Ht,scaleY:Ht,hideInExport:!i.showInExport,listening:!1,visible:i.backgroundEnabled&&Bt.length>0,opacity:i.backgroundOpacity*bt,fill:i.backgroundColor,data:Bt}),e(c,{ref:K,name:"rendertag-text",x:i.a.x,y:i.a.y,rotation:i.a.rotation,scaleX:Ht,scaleY:Ht,offsetY:Ht>0?-It/Ht:0,width:i.width,height:Math.max(i.height,Mt),listening:!1,visible:!ct&&!!(Ot?St:Et),opacity:bt,shadowEnabled:i.shadowEnabled,shadowBlur:i.shadowBlur,shadowOffsetX:i.shadowOffsetX,shadowOffsetY:i.shadowOffsetY,shadowColor:i.shadowColor,shadowOpacity:i.shadowOpacity,hideInExport:!i.showInExport,sceneFunc:(t,e)=>{const r=t._context;if(r){try{if(Ot){if(!St||!zt){return}const t=(i.width-zt.width)/2-zt.x;r.save(),r.translate(t,-zt.y),x({layout:St,ctx:r}),r.restore()}else{if(!Et){return}g({layout:Et,width:vt,ctx:r,pixelRatio:1})}}catch(o){console.error("render-tag draw failed:",o)}}}}),e(l,{ref:Q,name:"element",x:i.a.x,y:i.a.y,listening:i.selectable,rotation:i.a.rotation,width:i.a.width,height:i.a.height,visible:!ct,draggable:At?i.draggable&&et:i.draggable,preventDefault:!At||et,opacity:0,hideInExport:!0,id:i.id,onDragMove:t=>{i.set({x:t.target.x(),y:t.target.y()})},onDragEnd:t=>{i.set({x:t.target.x(),y:t.target.y()})},onDblClick:t=>{i.contentEditable&&(Nt.current={x:t.evt.clientX,y:t.evt.clientY},i.toggleEditMode(!0))},onDblTap:t=>{var e;if(i.contentEditable){const r=null===(e=t.evt.changedTouches)||void 0===e?void 0:e[0];Nt.current=r?{x:r.clientX,y:r.clientY}:null,i.toggleEditMode(!0)}},onTransformStart:t=>{var e,r;Z(!0),tt.current=i.height,Dt.current=i.width,Jt.current=null,Wt.current=t.target.position();const o=null===(e=t.target.getStage())||void 0===e?void 0:e.findOne("Transformer");$t.current=null!==(r=null==o?void 0:o.getActiveAnchor())&&void 0!==r?r:null,_t.current=i.a.rotation,Lt.current=i.height},onTransform:e=>{var r;const o=e.target,n=(null===(r=o.getStage())||void 0===r?void 0:r.findOne("Transformer")).getActiveAnchor(),a="middle-left"===n||"middle-right"===n,s="top-center"===n||"bottom-center"===n,l=o.scaleX();if(a){const e=o.scaleX(),n=o.width()*e;let a=Math.max(n,w(Dt.current,i.fontSize));const s=i.toJSON();let l=0;if(i.curveEnabled){l=k(Object.assign(Object.assign({},s),{width:a}))}else{const{x:e,y:o,width:n,height:i}=s,c=t(s,["x","y","width","height"]),h=`${JSON.stringify(c)}|${ht}|${lt}|${dt}`;if(Jt.current&&Jt.current.signature===h&&a<=Jt.current.width){a=Jt.current.width,l=Jt.current.height}else{const t=t=>{const e=M(Object.assign(Object.assign({},s),{text:yt,width:t}),{fontFamily:ht,color:dt,forEditor:!0});try{return u({html:_(e),width:t,accuracy:"performance"})}catch(r){return{height:X(e).height,lines:[]}}};let e=t(a);const o=Math.max(0,...e.lines.map(t=>t.bounds.x+t.bounds.width));o>a+.5&&o<=Dt.current+.5&&(a=Math.min(Math.ceil(o),Dt.current),e=t(a),Jt.current={signature:h,width:a,height:e.height}),l=e.height}}a>n&&Wt.current&&o.position(Wt.current),o.width(a),o.scaleX(1),o.scaleY(1);let c=v.textVerticalResizeEnabled?Math.max(l,tt.current):l;"ellipsis"===v.textOverflow&&(c=tt.current),o.height(c),i.set({width:o.width(),height:c,x:o.x(),y:o.y()})}else if(s){const t="resize"===v.textOverflow?Ot?(null==zt?void 0:zt.height)||i.fontSize:Mt:jt*i.fontSize,e=o.height()*o.scaleY();if(e<t){if(o.height(t),Wt.current){if("top-center"===$t.current){const e=_t.current*Math.PI/180,r=Lt.current-t;o.x(Wt.current.x-r*Math.sin(e)),o.y(Wt.current.y+r*Math.cos(e))}else{o.position(Wt.current)}}}else{o.height(e)}o.scaleY(1),o.scaleX(1),Lt.current=Math.max(t,e),i.set({x:o.x(),y:o.y(),height:o.height(),rotation:o.rotation()})}else{o.scaleX(1),o.scaleY(1),i.set({fontSize:i.fontSize*l,letterSpacing:i.letterSpacing,width:o.width()*l,x:o.x(),y:o.y(),rotation:o.rotation(),height:o.height()*l,shadowBlur:i.shadowBlur*l,shadowOffsetX:i.shadowOffsetX*l,shadowOffsetY:i.shadowOffsetY*l,strokeWidth:i.strokeWidth*l,text:D(i.text,l)})}Wt.current=e.target.position()},onTransformEnd:t=>{Z(!1);const e=t.target.scaleX();t.target.scaleX(1),t.target.scaleY(1),i.set(Object.assign(Object.assign({},y(i,i.fontSize*e)),{width:t.target.width()*e,x:t.target.x(),y:t.target.y(),rotation:t.target.rotation(),text:D(i.text,e)}))}}),ct&&e(a,{x:i.a.x,y:i.a.y,rotation:i.a.rotation,offsetY:-It,children:e(f,{divProps:{style:{zIndex:20}},children:e(J,{element:i,onChange:t=>{const e=B({oldText:P(i.text),newText:P(t),element:i});i.set(Object.assign({text:t},p(i,e)))},onBlur:()=>{d(i)&&(i.set(b(i)),i.toggleEditMode(!1))},clickCoords:Nt.current})})})]})});
@@ -1 +1 @@
1
- import{jsx as t,Fragment as e,jsxs as r}from"react/jsx-runtime";import n from"react";import{observer as o}from"mobx-react-lite";import{Group as i,Path as a,Text as l,TextPath as s}from"react-konva";import{Html as c}from"react-konva-utils";import{nodeAutorun as u}from"../utils/mobx.js";import d from"konva";import{parsePath as f,roundCommands as h}from"svg-round-corners/lib/index.js";import{generateBackgroundShapeFromRects as g,textLinesToRects as m}from"@polotno/core/background-shape";import{useColor as p}from"./use-color.js";import{useWorkspaceStyle as x}from"./workspace-style.js";import{ROLES as w}from"../model/store.js";import{incrementLoader as v}from"../utils/loader.js";import{scaledFontSizeAttrs as y,roundedFontSizeAttrs as S,roundedTextDecorationAttrs as b,textMinResizeWidth as E}from"../utils/px.js";import{isFontLoaded as z}from"../utils/fonts.js";import{flags as k}from"../utils/flags.js";import{removeTags as O}from"@polotno/core/text";import{getDir as R,getCurvePath as A,resolveLineHeight as F,normalizeStrokeLineJoin as M}from"@polotno/core/text-html";import{applyFilter as j}from"./apply-filters.js";import{useFadeIn as L}from"./use-fadein.js";import{isTouchDevice as T}from"../utils/screen.js";import{isAlive as C,getParent as H}from"mobx-state-tree";import{getLimitedFontSize as P}from"./text-element/max-font-size.js";import{getOptimalCaretColor as X}from"./text-element/caret-color.js";import{visiblePlaceholder as Y}from"./text-element/placeholder.js";let W;function D(){return W||(W=document.getElementById("polotno-text-style"),W||(W=document.createElement("style"),W.id="polotno-text-style",document.head.appendChild(W)),W)}d._fixTextRendering=!0;const $={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 B=o(({textNodeRef:e,element:r,onBlur:o,selectAll:i,cursorPosition:a})=>{const[l,s]=n.useState($),c=e.current;n.useLayoutEffect(()=>{if(!c){return}const t={};t.width=c.width()-2*c.padding()+"px",t.height=c.height()-2*c.padding()+c.fontSize()*c.lineHeight()+"px",t.fontSize=c.fontSize()+"px",t.lineHeight=c.lineHeight()+.01,t.fontFamily=c.fontFamily(),t.textAlign=c.align(),t.color=c.fill(),t.fontWeight=r.fontWeight,t.fontStyle=r.fontStyle,t.letterSpacing=r.letterSpacing+"em",t.opacity=Math.max(r.a.opacity,.2),t.textTransform=r.textTransform,t.caretColor=X(r);const e=`\n .polotno-input::placeholder {\n color: ${l.color};\n opacity: 0.6;\n }\n `,n=D();n.innerHTML="",n.appendChild(document.createTextNode(e)),JSON.stringify(t)!==JSON.stringify(l)&&s(t)});const u=n.useRef(null);if(n.useLayoutEffect(()=>{var t;const e=u.current;if(!e){return}null===(t=u.current)||void 0===t||t.focus({preventScroll:!0});const r=a||e.value.length;e.selectionStart=e.selectionEnd=r,i&&(null==e||e.select(),document.execCommand("selectAll",!1,void 0))},[]),n.useEffect(()=>{window.addEventListener("blur",o);const t=t=>{var e;(null===(e=u.current)||void 0===e?void 0:e.contains(t.target))||o()};return window.addEventListener("touchstart",t),()=>{window.removeEventListener("blur",o),window.removeEventListener("touchstart",t)}},[]),!c){return null}let d=0;const f=c.textArr.length*c.lineHeight()*c.fontSize();"middle"===r.verticalAlign&&(d=(r.a.height-f)/2),"bottom"===r.verticalAlign&&(d=r.a.height-f);const h=O(r.text);return t("textarea",{className:"polotno-input",ref:u,dir:R(h),style:Object.assign(Object.assign(Object.assign({},$),l),{paddingTop:d+"px"}),value:h,onChange:t=>{const e=P({oldText:r.text,newText:t.target.value,element:r});r.set(Object.assign({text:t.target.value},y(r,e)))},placeholder:Y(r.placeholder),onBlur:o})}),I=e=>t(c,{children:t(B,Object.assign({},e))});export const useFontLoader=(t,e,r,o,i)=>{const[a,l]=n.useReducer(t=>t+1,0),s=n.useRef(z(e,r,o)),c=n.useRef(null);return n.useLayoutEffect(()=>{if(s.current=z(e,r,o),s.current){return}let n=!0;return(async()=>{s.current=!1,l();const a=v(`text ${e}`);await t.loadFont(e,r,o,i),n?(c.current=a,s.current=!0,l()):a()})(),()=>{c.current&&(c.current(),c.current=null),n=!1}},[e,r,o]),n.useEffect(()=>{s.current&&setTimeout(()=>{c.current&&(c.current(),c.current=null)})},[s.current]),[s.current]};export const useFontFamiliesLoader=(t,e,r,o,i)=>{const[a,l]=n.useReducer(t=>t+1,0),s=e.join("\0"),c=n.useRef(e.every(t=>z(t,r,o))),u=n.useRef(null);return n.useLayoutEffect(()=>{if(c.current=e.every(t=>z(t,r,o)),c.current){return}let n=!0;return(async()=>{c.current=!1,l();const a=v(`text fonts ${s}`);await Promise.all(e.map(e=>t.loadFont(e,r,o,i))),n?(u.current=a,c.current=!0,l()):a()})(),()=>{u.current&&(u.current(),u.current=null),n=!1}},[s,r,o]),n.useEffect(()=>{c.current&&setTimeout(()=>{u.current&&(u.current(),u.current=null)})},[c.current]),[c.current]};export const getLineHeight=({fontLoaded:t,fontFamily:e,fontSize:r,lineHeight:o})=>n.useMemo(()=>F({fontFamily:e,fontSize:r,lineHeight:o}),[t,e,r,o]);export function usePrevious(t){const e=n.useRef(t),r=n.useRef(t);return n.useMemo(()=>{r.current=e.current,e.current=t},[t]),r.current}function N(t,e,r=!1){const n=t.fontSize(),o=t.height(),i=O(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 n=e.a.height&&t.height()>e.a.height;let o=i.split("\n").join(" ").split(/[\s-]+/).reduce((t,e)=>(e=e.toLowerCase(),/[\u3000-\u303F\u3040-\u309F\u30A0-\u30FF\uFF00-\uFFEF\u4E00-\u9FAF\uAC00-\uD7AF]/.test(e)?t.concat(e.split("")):t.concat(e)),[]),l=t.textArr.map(t=>t.text.toLowerCase()).join(";");const s=o.find(t=>!l.includes(t)||(l=l.replace(t,""),!1));if(!(n||s&&!r)){break}a-=.5,t.fontSize(a)}return t.fontSize(n),t.height(o),a}export{getCurvePath}from"@polotno/core/text-html";export const TextElement=o(({element:o,store:c})=>{const{textOverflowIndicatorStyle:d}=x(),z=n.useRef(null),F=n.useRef(null),P=n.useRef(null),X=n.useRef([]),W=n.useRef(!0),[,D]=n.useReducer(t=>t+1,0),{editorEnabled:$,selectAll:B}=(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}})(o),[J,_]=n.useState(!1),[V,q]=n.useState(!1),U=n.useRef(o.a.height),Z=n.useRef(0),G=n.useRef(""),K=n.useRef(0),Q=o.isSelected,tt=usePrevious(Q),{textVerticalResizeEnabled:et}=k,rt=k.autoDeleteEmptyText,nt=usePrevious(o.fontFamily),[ot,it]=n.useState([]);n.useEffect(()=>{var t,e;const r=null!==(e=null===(t=z.current)||void 0===t?void 0:t.textArr)&&void 0!==e?e:[];JSON.stringify(r)!==JSON.stringify(ot)&&it(r)}),n.useEffect(()=>{if(o.a.width||"tablecell"===o.type){return}const t=z.current;t.width(600),o.set({width:1.4*t.getTextWidth()})},[]),n.useEffect(()=>{tt&&!Q&&rt&&""===o.text&&o.removable&&!Y(o.placeholder)&&c.deleteElements([o.id])},[rt,o.placeholder,o.removable,o.text,Q,tt]);const at=()=>{if(o.curveEnabled){const t=z.current;null==t||t.clearCache(),null==t||t.setAttrs({filters:[]});const e=F.current;e&&j(e,o)}else{const t=z.current;t&&j(t,o)}};n.useLayoutEffect(()=>{if(!V){return u(o,()=>{at()})}}),n.useEffect(()=>{const t=X.current;t.length>0&&(X.current=[],t.forEach(t=>t()))}),n.useEffect(()=>()=>{W.current=!1;const t=X.current;t.length>0&&(X.current=[],t.forEach(t=>t()))},[]);let lt=O(o.text);"uppercase"===o.textTransform&&(lt=lt.toUpperCase());const[st]=useFontLoader(c,o.fontFamily,o.fontStyle,o.fontWeight,o.text||o.placeholder),ct=()=>{if(o.curveEnabled){const t=F.current;return t.getSelfRect().height||t.fontSize()}const t=z.current.clone({height:void 0}),e=Math.ceil(t.fontSize()*t.lineHeight()*t.textArr.length+1);return t.destroy(),e};n.useLayoutEffect(()=>{if(!st){return}if("tablecell"===o.type){const{textOverflow:t}=k;if("resize"===t){const t=ct(),e=C(o)?H(o,2):null;(null==e?void 0:e.setCellContentHeight)&&e.setCellContentHeight(o.id,t)}else if("change-font-size"===t){const t=z.current;if(t){const e=N(t,o,k.textSplitAllowed);e!==o.fontSize&&c.history.ignore(()=>{o.set({fontSize:e})})}}return}const{textOverflow:t,textSplitAllowed:e}=k,r=(t,e,r,n)=>{const i=v(`text ${o.id}`),a=()=>{c.history.ignore(t,e,r).then(()=>{W.current?(X.current.push(i),D()):i()})};n?queueMicrotask(a):a()};if(!o.height){const t=ct();return void r(()=>{o.height||o.set({height:t})},void 0,void 0,!0)}if(!c.isPlaying){if("change-font-size"!==t||J){if("resize"===t){const t=ct();et&&o.height<t&&!J&&r(()=>{var e;C(o)&&o.set({height:t}),null===(e=z.current)||void 0===e||e.height(t)},!1,!0),et||o.height===t||J||r(()=>{var e;C(o)&&o.set({height:t}),null===(e=z.current)||void 0===e||e.height(t)},!1,!0)}}else{const t=z.current,n=o.curveEnabled?o.fontSize:N(t,o,e);if(n!==o.fontSize){return void r(()=>{o.set(y(o,n))},!1,!0)}const i=ct();o.height===i||et||r(()=>{o.set({height:i})},!1,!0)}}}),n.useLayoutEffect(()=>{var t;if(st&&o.curveEnabled){const e=null===(t=F.current)||void 0===t?void 0:t.getSelfRect().width;if(e){const t=e-o.a.width,r=o.a.rotation*Math.PI/180,n=-t/2*Math.cos(r),i=-t/2*Math.sin(r);o.set({width:e,x:o.a.x+n,y:o.a.y+i})}}},[st,o.curveEnabled,o.curvePower,o.text,o.fontSize,o.fontFamily,o.fontWeight,o.fontStyle,o.letterSpacing]),n.useLayoutEffect(()=>{const t=z.current;t&&(t.width(t.width()+1e-8),t.width(t.width()-1e-8),t._setTextData(),at())},[st]);const ut=n.useRef(null),dt=n.useRef(o.width),ft=n.useRef(0),ht=t=>{t.evt.preventDefault();const e=c.selectedShapes.find(t=>t===o);e&&o.contentEditable&&(ft.current=function(t){var e;const r=t.target,n=function(t){var e=t.getAbsoluteTransform().copy();e.invert();var r=t.getStage().getPointerPosition();return e.point(r)}(r),o=r.textArr,i=Math.floor(n.y/(r.fontSize()*r.lineHeight())),a=o.slice(0,i).reduce((t,e)=>t+e.text.length,i),l=null!==(e=o[i])&&void 0!==e?e:o[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((n.x-s)/l.width*l.text.length)}(t),o.toggleEditMode())},gt=Y(o.placeholder),mt=!lt&&gt?.6:o.a.opacity;L(z,mt);const pt=getLineHeight({fontLoaded:st,fontFamily:o.fontFamily,fontSize:o.a.fontSize,lineHeight:o.lineHeight}),xt=o.selectable||c.role===w.ADMIN,wt=p(o),vt=p(o,o.stroke,"stroke"),yt=n.useMemo(()=>o.backgroundEnabled?o.curveEnabled?function({width:t,height:e,padding:r=0,cornerRadius:n=0}){const o=-r,i=-r,a=t+r,l=e+r,s=f(`M ${o} ${i} L ${a} ${i} L ${a} ${l} L ${o} ${l} Z`);return h(s,n).path}({width:o.a.width,height:o.a.height,cornerRadius:o.backgroundCornerRadius*(o.a.fontSize*pt*.5),padding:o.backgroundPadding*(o.a.fontSize*pt*.5)}):function({lines:t,lineHeight:e,width:r,align:n="left",padding:o=0,cornerRadius:i=0}){const a=m({lines:t,lineHeight:e,width:r,align:n});return g({rects:a,padding:o,cornerRadius:i})}({lines:JSON.parse(JSON.stringify(ot)),cornerRadius:o.backgroundCornerRadius*(o.a.fontSize*pt*.5),lineHeight:pt*o.a.fontSize,padding:o.backgroundPadding*(o.a.fontSize*pt*.5),width:o.a.width,align:o.align}):"",[o.backgroundEnabled,o.curveEnabled,o.backgroundCornerRadius,o.a.fontSize,o.a.height,pt,o.backgroundPadding,o.a.width,o.align,ot]),St=T();let bt=0;o.curveEnabled||("middle"===o.verticalAlign?bt=(o.a.height-ot.length*pt*o.a.fontSize)/2:"bottom"===o.verticalAlign&&(bt=o.a.height-ot.length*pt*o.a.fontSize));const Et=o.curveEnabled?A(o.a.width,o.a.height,o.curvePower,o.a.fontSize):"",zt=st?'"'+o.fontFamily+'"':nt===o.fontFamily?"Arial":'"'+nt+'"',kt=R(lt);return r(e,{children:[t(a,{ref:P,x:o.a.x,y:o.a.y,rotation:o.a.rotation,hideInExport:!o.showInExport,listening:!1,visible:o.backgroundEnabled,opacity:o.backgroundOpacity*mt,data:yt,fill:o.backgroundColor,offsetY:-bt}),t(a,{data:Et,stroke:d.stroke,strokeWidth:1,x:o.a.x,y:o.a.y,rotation:o.a.rotation,visible:!1}),t(s,Object.assign({ref:F,visible:o.curveEnabled,data:Et,text:lt||gt,listening:!1,align:"center",textBaseline:"middle",direction:kt},wt,vt,{strokeWidth:o.strokeWidth,lineJoin:M(o.strokeLineJoin),fillAfterStrokeEnabled:!0,fontSize:o.a.fontSize,fontFamily:`"${o.fontFamily}", "${nt}"`,fontStyle:o.fontStyle+" "+o.fontWeight,textDecoration:o.textDecoration.trim(),letterSpacing:o.letterSpacing*o.a.fontSize,x:o.a.x,y:o.a.y,rotation:o.a.rotation,opacity:o._editModeEnabled?.3:mt,hideInExport:!o.showInExport,shadowEnabled:o.shadowEnabled,shadowBlur:o.shadowBlur,shadowOffsetX:o.shadowOffsetX,shadowOffsetY:o.shadowOffsetY,shadowColor:o.shadowColor,shadowOpacity:o.shadowOpacity})),t(l,Object.assign({ref:z,id:o.selectable?o.id:void 0,name:o.selectable?"element":"",hideInExport:!o.showInExport,editModeEnabled:o._editModeEnabled,x:o.a.x,y:o.a.y,rotation:o.a.rotation,width:o.a.width,height:o.a.height,text:lt||gt,direction:kt},wt,vt,{lineJoin:M(o.strokeLineJoin),strokeWidth:o.strokeWidth,fillAfterStrokeEnabled:!0,fontSize:o.a.fontSize,fontFamily:zt,fontStyle:o.fontStyle+" "+o.fontWeight,textDecoration:o.textDecoration,align:o.align,verticalAlign:o.verticalAlign,draggable:St?o.draggable&&Q:o.draggable,preventDefault:!St||Q,opacity:o.curveEnabled?0:mt,visible:!o._editModeEnabled,ellipsis:"ellipsis"===k.textOverflow,shadowEnabled:o.shadowEnabled,shadowBlur:o.shadowBlur,shadowOffsetX:o.shadowOffsetX,shadowOffsetY:o.shadowOffsetY,shadowColor:o.shadowColor,shadowOpacity:o.shadowOpacity,lineHeight:pt,letterSpacing:o.letterSpacing*o.a.fontSize,listening:!!o.selectable&&xt,onDragStart:()=>{q(!0)},onDragMove:t=>{o.set({x:t.target.x(),y:t.target.y()})},onDragEnd:t=>{q(!1),o.set({x:t.target.x(),y:t.target.y()})},onClick:ht,onTap:ht,onTransformStart:()=>{var t,e;_(!0);const r=z.current;U.current=r.height(),dt.current=o.a.width,ut.current=r.position(),Z.current=r.rotation(),K.current=r.height();const n=null===(t=r.getStage())||void 0===t?void 0:t.findOne("Transformer");G.current=null!==(e=null==n?void 0:n.getActiveAnchor())&&void 0!==e?e:""},onTransform:t=>{var e,r,n;const i=t.target;null===(e=P.current)||void 0===e||e.setAttrs({x:i.x(),y:i.y(),rotation:i.rotation(),scale:i.scale()});const a=(null===(r=i.getStage())||void 0===r?void 0:r.findOne("Transformer")).getActiveAnchor();if("middle-left"===a||"middle-right"===a){const t=i.scaleX(),e=i.width()*t,r=E(dt.current,o.a.fontSize);let n=e;e<r&&(n=r,ut.current&&i.position(ut.current)),i.width(n),i.scaleX(1),i.scaleY(1);let a=ct();if("ellipsis"===k.textOverflow){a=U.current}else{const t=Math.max(a,U.current);i.height(t),o.set({height:i.height()})}const l=k.textVerticalResizeEnabled?Math.max(a,U.current):ct();o.set({x:i.x(),width:i.width(),rotation:i.rotation(),height:l}),i.skewX(0),i.skewY(0),at()}if("top-center"===a||"bottom-center"===a){const e="resize"===k.textOverflow?ct():pt*o.a.fontSize,r=t.target.height()*t.target.scaleY();if(r<e){if(t.target.height(e),ut.current){if("top-center"===G.current){const r=Z.current*Math.PI/180,n=K.current-e;t.target.x(ut.current.x-n*Math.sin(r)),t.target.y(ut.current.y+n*Math.cos(r))}else{t.target.position(ut.current)}}}else{t.target.height(r)}t.target.scaleY(1),t.target.scaleX(1),t.target.rotation(Z.current),t.target.skewX(0),t.target.skewY(0),K.current=Math.max(e,r)}ut.current=t.target.position();const l=t.target.scaleX();null===(n=P.current)||void 0===n||n.setAttrs({scaleX:1,scaleY:1}),t.target.scaleX(1),t.target.scaleY(1),o.set({fontSize:o.a.fontSize*l,width:t.target.width()*l,x:t.target.x(),y:t.target.y(),rotation:t.target.rotation(),height:t.target.height()*l,shadowBlur:o.shadowBlur*l,shadowOffsetX:o.shadowOffsetX*l,shadowOffsetY:o.shadowOffsetY*l,strokeWidth:o.strokeWidth*l})},onTransformEnd:t=>{var e;const r=t.target.scaleX();t.target.scaleX(1),t.target.scaleY(1),o.set(Object.assign(Object.assign({},S(o,o.fontSize*r)),{width:Math.ceil(t.target.width()*r),x:t.target.x(),y:t.target.y(),rotation:t.target.rotation(),height:t.target.height()*r})),null===(e=P.current)||void 0===e||e.setAttrs({scaleX:1,scaleY:1}),_(!1)}})),$&&o.contentEditable&&t(i,{x:o.a.x,y:o.a.y,rotation:o.a.rotation,children:t(I,{textNodeRef:z,element:o,selectAll:B,cursorPosition:ft.current,onBlur:()=>{o.set(b(o)),o.toggleEditMode(!1)}})})]})});
1
+ import{jsx as t,Fragment as e,jsxs as r}from"react/jsx-runtime";import n from"react";import{observer as o}from"mobx-react-lite";import{Group as i,Path as a,Text as l,TextPath as s}from"react-konva";import{Html as c}from"react-konva-utils";import{nodeAutorun as u}from"../utils/mobx.js";import d from"konva";import{parsePath as f,roundCommands as h}from"svg-round-corners/lib/index.js";import{generateBackgroundShapeFromRects as g,textLinesToRects as p}from"@polotno/core/background-shape";import{useColor as m}from"./use-color.js";import{useWorkspaceStyle as x}from"./workspace-style.js";import{ROLES as w}from"../model/store.js";import{incrementLoader as v}from"../utils/loader.js";import{scaledFontSizeAttrs as y,roundedFontSizeAttrs as S,roundedTextDecorationAttrs as b,textMinResizeWidth as E}from"../utils/px.js";import{isFontLoaded as z}from"../utils/fonts.js";import{flags as k}from"../utils/flags.js";import{removeTags as O}from"@polotno/core/text";import{getDir as R,getCurvePath as A,resolveLineHeight as F,normalizeStrokeLineJoin as M}from"@polotno/core/text-html";import{applyFilter as j}from"./apply-filters.js";import{useFadeIn as L}from"./use-fadein.js";import{isTouchDevice as T}from"../utils/screen.js";import{isAlive as C,getParent as H}from"mobx-state-tree";import{getLimitedFontSize as P}from"./text-element/max-font-size.js";import{getOptimalCaretColor as X}from"./text-element/caret-color.js";import{visiblePlaceholder as Y}from"./text-element/placeholder.js";import{hasMeasuredHeight as W,resolveTextBoxHeight as D}from"@polotno/core/text-types";let $;function B(){return $||($=document.getElementById("polotno-text-style"),$||($=document.createElement("style"),$.id="polotno-text-style",document.head.appendChild($)),$)}d._fixTextRendering=!0;const I={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 N=o(({textNodeRef:e,element:r,onBlur:o,selectAll:i,cursorPosition:a})=>{const[l,s]=n.useState(I),c=e.current;n.useLayoutEffect(()=>{if(!c){return}const t={};t.width=c.width()-2*c.padding()+"px",t.height=c.height()-2*c.padding()+c.fontSize()*c.lineHeight()+"px",t.fontSize=c.fontSize()+"px",t.lineHeight=c.lineHeight()+.01,t.fontFamily=c.fontFamily(),t.textAlign=c.align(),t.color=c.fill(),t.fontWeight=r.fontWeight,t.fontStyle=r.fontStyle,t.letterSpacing=r.letterSpacing+"em",t.opacity=Math.max(r.a.opacity,.2),t.textTransform=r.textTransform,t.caretColor=X(r);const e=`\n .polotno-input::placeholder {\n color: ${l.color};\n opacity: 0.6;\n }\n `,n=B();n.innerHTML="",n.appendChild(document.createTextNode(e)),JSON.stringify(t)!==JSON.stringify(l)&&s(t)});const u=n.useRef(null);if(n.useLayoutEffect(()=>{var t;const e=u.current;if(!e){return}null===(t=u.current)||void 0===t||t.focus({preventScroll:!0});const r=a||e.value.length;e.selectionStart=e.selectionEnd=r,i&&(null==e||e.select(),document.execCommand("selectAll",!1,void 0))},[]),n.useEffect(()=>{window.addEventListener("blur",o);const t=t=>{var e;(null===(e=u.current)||void 0===e?void 0:e.contains(t.target))||o()};return window.addEventListener("touchstart",t),()=>{window.removeEventListener("blur",o),window.removeEventListener("touchstart",t)}},[]),!c){return null}let d=0;const f=c.textArr.length*c.lineHeight()*c.fontSize(),h=D(r.a,f);"middle"===r.verticalAlign&&(d=(h-f)/2),"bottom"===r.verticalAlign&&(d=h-f);const g=O(r.text);return t("textarea",{className:"polotno-input",ref:u,dir:R(g),style:Object.assign(Object.assign(Object.assign({},I),l),{paddingTop:d+"px"}),value:g,onChange:t=>{const e=P({oldText:r.text,newText:t.target.value,element:r});r.set(Object.assign({text:t.target.value},y(r,e)))},placeholder:Y(r.placeholder),onBlur:o})}),J=e=>t(c,{children:t(N,Object.assign({},e))});export const useFontLoader=(t,e,r,o,i)=>{const[a,l]=n.useReducer(t=>t+1,0),s=n.useRef(z(e,r,o)),c=n.useRef(null);return n.useLayoutEffect(()=>{if(s.current=z(e,r,o),s.current){return}let n=!0;return(async()=>{s.current=!1,l();const a=v(`text ${e}`);await t.loadFont(e,r,o,i),n?(c.current=a,s.current=!0,l()):a()})(),()=>{c.current&&(c.current(),c.current=null),n=!1}},[e,r,o]),n.useEffect(()=>{s.current&&setTimeout(()=>{c.current&&(c.current(),c.current=null)})},[s.current]),[s.current]};export const useFontFamiliesLoader=(t,e,r,o,i)=>{const[a,l]=n.useReducer(t=>t+1,0),s=e.join("\0"),c=n.useRef(e.every(t=>z(t,r,o))),u=n.useRef(null);return n.useLayoutEffect(()=>{if(c.current=e.every(t=>z(t,r,o)),c.current){return}let n=!0;return(async()=>{c.current=!1,l();const a=v(`text fonts ${s}`);await Promise.all(e.map(e=>t.loadFont(e,r,o,i))),n?(u.current=a,c.current=!0,l()):a()})(),()=>{u.current&&(u.current(),u.current=null),n=!1}},[s,r,o]),n.useEffect(()=>{c.current&&setTimeout(()=>{u.current&&(u.current(),u.current=null)})},[c.current]),[c.current]};export const getLineHeight=({fontLoaded:t,fontFamily:e,fontSize:r,lineHeight:o})=>n.useMemo(()=>F({fontFamily:e,fontSize:r,lineHeight:o}),[t,e,r,o]);export function usePrevious(t){const e=n.useRef(t),r=n.useRef(t);return n.useMemo(()=>{r.current=e.current,e.current=t},[t]),r.current}function _(t,e,r=!1){const n=t.fontSize(),o=t.height(),i=O(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 n=W(e.a)&&t.height()>e.a.height;let o=i.split("\n").join(" ").split(/[\s-]+/).reduce((t,e)=>(e=e.toLowerCase(),/[\u3000-\u303F\u3040-\u309F\u30A0-\u30FF\uFF00-\uFFEF\u4E00-\u9FAF\uAC00-\uD7AF]/.test(e)?t.concat(e.split("")):t.concat(e)),[]),l=t.textArr.map(t=>t.text.toLowerCase()).join(";");const s=o.find(t=>!l.includes(t)||(l=l.replace(t,""),!1));if(!(n||s&&!r)){break}a-=.5,t.fontSize(a)}return t.fontSize(n),t.height(o),a}export{getCurvePath}from"@polotno/core/text-html";export const TextElement=o(({element:o,store:c})=>{const{textOverflowIndicatorStyle:d}=x(),z=n.useRef(null),F=n.useRef(null),P=n.useRef(null),X=n.useRef([]),$=n.useRef(!0),[,B]=n.useReducer(t=>t+1,0),{editorEnabled:I,selectAll:N}=(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}})(o),[V,q]=n.useState(!1),[U,Z]=n.useState(!1),G=n.useRef(o.a.height),K=n.useRef(0),Q=n.useRef(""),tt=n.useRef(0),et=o.isSelected,rt=usePrevious(et),{textVerticalResizeEnabled:nt}=k,ot=k.autoDeleteEmptyText,it=usePrevious(o.fontFamily),[at,lt]=n.useState([]);n.useEffect(()=>{var t,e;const r=null!==(e=null===(t=z.current)||void 0===t?void 0:t.textArr)&&void 0!==e?e:[];JSON.stringify(r)!==JSON.stringify(at)&&lt(r)}),n.useEffect(()=>{if(o.a.width||"tablecell"===o.type){return}const t=z.current;t.width(600),o.set({width:1.4*t.getTextWidth()})},[]),n.useEffect(()=>{rt&&!et&&ot&&""===o.text&&o.removable&&!Y(o.placeholder)&&c.deleteElements([o.id])},[ot,o.placeholder,o.removable,o.text,et,rt]);const st=()=>{if(o.curveEnabled){const t=z.current;null==t||t.clearCache(),null==t||t.setAttrs({filters:[]});const e=F.current;e&&j(e,o)}else{const t=z.current;t&&j(t,o)}};n.useLayoutEffect(()=>{if(!U){return u(o,()=>{st()})}}),n.useEffect(()=>{const t=X.current;t.length>0&&(X.current=[],t.forEach(t=>t()))}),n.useEffect(()=>()=>{$.current=!1;const t=X.current;t.length>0&&(X.current=[],t.forEach(t=>t()))},[]);let ct=O(o.text);"uppercase"===o.textTransform&&(ct=ct.toUpperCase());const[ut]=useFontLoader(c,o.fontFamily,o.fontStyle,o.fontWeight,o.text||o.placeholder),dt=()=>{if(o.curveEnabled){const t=F.current;return t.getSelfRect().height||t.fontSize()}const t=z.current.clone({height:void 0}),e=Math.ceil(t.fontSize()*t.lineHeight()*t.textArr.length+1);return t.destroy(),e};n.useLayoutEffect(()=>{if(!ut){return}if("tablecell"===o.type){const{textOverflow:t}=k;if("resize"===t){const t=dt(),e=C(o)?H(o,2):null;(null==e?void 0:e.setCellContentHeight)&&e.setCellContentHeight(o.id,t)}else if("change-font-size"===t){const t=z.current;if(t){const e=_(t,o,k.textSplitAllowed);e!==o.fontSize&&c.history.ignore(()=>{o.set({fontSize:e})})}}return}const{textOverflow:t,textSplitAllowed:e}=k,r=(t,e,r,n)=>{const i=v(`text ${o.id}`),a=()=>{c.history.ignore(t,e,r).then(()=>{$.current?(X.current.push(i),B()):i()})};n?queueMicrotask(a):a()};if(!W(o)){const t=dt();return void r(()=>{W(o)||o.set({height:t})},void 0,void 0,!0)}if(!c.isPlaying){if("change-font-size"!==t||V){if("resize"===t){const t=dt();nt&&o.height<t&&!V&&r(()=>{var e;C(o)&&o.set({height:t}),null===(e=z.current)||void 0===e||e.height(t)},!1,!0),nt||o.height===t||V||r(()=>{var e;C(o)&&o.set({height:t}),null===(e=z.current)||void 0===e||e.height(t)},!1,!0)}}else{const t=z.current,n=o.curveEnabled?o.fontSize:_(t,o,e);if(n!==o.fontSize){return void r(()=>{o.set(y(o,n))},!1,!0)}const i=dt();o.height===i||nt||r(()=>{o.set({height:i})},!1,!0)}}}),n.useLayoutEffect(()=>{var t;if(ut&&o.curveEnabled){const e=null===(t=F.current)||void 0===t?void 0:t.getSelfRect().width;if(e){const t=e-o.a.width,r=o.a.rotation*Math.PI/180,n=-t/2*Math.cos(r),i=-t/2*Math.sin(r);o.set({width:e,x:o.a.x+n,y:o.a.y+i})}}},[ut,o.curveEnabled,o.curvePower,o.text,o.fontSize,o.fontFamily,o.fontWeight,o.fontStyle,o.letterSpacing]),n.useLayoutEffect(()=>{const t=z.current;t&&(t.width(t.width()+1e-8),t.width(t.width()-1e-8),t._setTextData(),st())},[ut]);const ft=n.useRef(null),ht=n.useRef(o.width),gt=n.useRef(0),pt=t=>{t.evt.preventDefault();const e=c.selectedShapes.find(t=>t===o);e&&o.contentEditable&&(gt.current=function(t){var e;const r=t.target,n=function(t){var e=t.getAbsoluteTransform().copy();e.invert();var r=t.getStage().getPointerPosition();return e.point(r)}(r),o=r.textArr,i=Math.floor(n.y/(r.fontSize()*r.lineHeight())),a=o.slice(0,i).reduce((t,e)=>t+e.text.length,i),l=null!==(e=o[i])&&void 0!==e?e:o[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((n.x-s)/l.width*l.text.length)}(t),o.toggleEditMode())},mt=Y(o.placeholder),xt=!ct&&mt?.6:o.a.opacity;L(z,xt);const wt=getLineHeight({fontLoaded:ut,fontFamily:o.fontFamily,fontSize:o.a.fontSize,lineHeight:o.lineHeight}),vt=o.selectable||c.role===w.ADMIN,yt=m(o),St=m(o,o.stroke,"stroke"),bt=n.useMemo(()=>o.backgroundEnabled?o.curveEnabled?function({width:t,height:e,padding:r=0,cornerRadius:n=0}){const o=-r,i=-r,a=t+r,l=e+r,s=f(`M ${o} ${i} L ${a} ${i} L ${a} ${l} L ${o} ${l} Z`);return h(s,n).path}({width:o.a.width,height:o.a.height,cornerRadius:o.backgroundCornerRadius*(o.a.fontSize*wt*.5),padding:o.backgroundPadding*(o.a.fontSize*wt*.5)}):function({lines:t,lineHeight:e,width:r,align:n="left",padding:o=0,cornerRadius:i=0}){const a=p({lines:t,lineHeight:e,width:r,align:n});return g({rects:a,padding:o,cornerRadius:i})}({lines:JSON.parse(JSON.stringify(at)),cornerRadius:o.backgroundCornerRadius*(o.a.fontSize*wt*.5),lineHeight:wt*o.a.fontSize,padding:o.backgroundPadding*(o.a.fontSize*wt*.5),width:o.a.width,align:o.align}):"",[o.backgroundEnabled,o.curveEnabled,o.backgroundCornerRadius,o.a.fontSize,o.a.height,wt,o.backgroundPadding,o.a.width,o.align,at]),Et=T();let zt=0;if(!o.curveEnabled){const t=at.length*wt*o.a.fontSize,e=D(o.a,t);"middle"===o.verticalAlign?zt=(e-t)/2:"bottom"===o.verticalAlign&&(zt=e-t)}const kt=o.curveEnabled?A(o.a.width,o.a.height,o.curvePower,o.a.fontSize):"",Ot=ut?'"'+o.fontFamily+'"':it===o.fontFamily?"Arial":'"'+it+'"',Rt=R(ct);return r(e,{children:[t(a,{ref:P,x:o.a.x,y:o.a.y,rotation:o.a.rotation,hideInExport:!o.showInExport,listening:!1,visible:o.backgroundEnabled,opacity:o.backgroundOpacity*xt,data:bt,fill:o.backgroundColor,offsetY:-zt}),t(a,{data:kt,stroke:d.stroke,strokeWidth:1,x:o.a.x,y:o.a.y,rotation:o.a.rotation,visible:!1}),t(s,Object.assign({ref:F,visible:o.curveEnabled,data:kt,text:ct||mt,listening:!1,align:"center",textBaseline:"middle",direction:Rt},yt,St,{strokeWidth:o.strokeWidth,lineJoin:M(o.strokeLineJoin),fillAfterStrokeEnabled:!0,fontSize:o.a.fontSize,fontFamily:`"${o.fontFamily}", "${it}"`,fontStyle:o.fontStyle+" "+o.fontWeight,textDecoration:o.textDecoration.trim(),letterSpacing:o.letterSpacing*o.a.fontSize,x:o.a.x,y:o.a.y,rotation:o.a.rotation,opacity:o._editModeEnabled?.3:xt,hideInExport:!o.showInExport,shadowEnabled:o.shadowEnabled,shadowBlur:o.shadowBlur,shadowOffsetX:o.shadowOffsetX,shadowOffsetY:o.shadowOffsetY,shadowColor:o.shadowColor,shadowOpacity:o.shadowOpacity})),t(l,Object.assign({ref:z,id:o.selectable?o.id:void 0,name:o.selectable?"element":"",hideInExport:!o.showInExport,editModeEnabled:o._editModeEnabled,x:o.a.x,y:o.a.y,rotation:o.a.rotation,width:o.a.width,height:W(o.a)?o.a.height:void 0,text:ct||mt,direction:Rt},yt,St,{lineJoin:M(o.strokeLineJoin),strokeWidth:o.strokeWidth,fillAfterStrokeEnabled:!0,fontSize:o.a.fontSize,fontFamily:Ot,fontStyle:o.fontStyle+" "+o.fontWeight,textDecoration:o.textDecoration,align:o.align,verticalAlign:o.verticalAlign,draggable:Et?o.draggable&&et:o.draggable,preventDefault:!Et||et,opacity:o.curveEnabled?0:xt,visible:!o._editModeEnabled,ellipsis:"ellipsis"===k.textOverflow,shadowEnabled:o.shadowEnabled,shadowBlur:o.shadowBlur,shadowOffsetX:o.shadowOffsetX,shadowOffsetY:o.shadowOffsetY,shadowColor:o.shadowColor,shadowOpacity:o.shadowOpacity,lineHeight:wt,letterSpacing:o.letterSpacing*o.a.fontSize,listening:!!o.selectable&&vt,onDragStart:()=>{Z(!0)},onDragMove:t=>{o.set({x:t.target.x(),y:t.target.y()})},onDragEnd:t=>{Z(!1),o.set({x:t.target.x(),y:t.target.y()})},onClick:pt,onTap:pt,onTransformStart:()=>{var t,e;q(!0);const r=z.current;G.current=r.height(),ht.current=o.a.width,ft.current=r.position(),K.current=r.rotation(),tt.current=r.height();const n=null===(t=r.getStage())||void 0===t?void 0:t.findOne("Transformer");Q.current=null!==(e=null==n?void 0:n.getActiveAnchor())&&void 0!==e?e:""},onTransform:t=>{var e,r,n;const i=t.target;null===(e=P.current)||void 0===e||e.setAttrs({x:i.x(),y:i.y(),rotation:i.rotation(),scale:i.scale()});const a=(null===(r=i.getStage())||void 0===r?void 0:r.findOne("Transformer")).getActiveAnchor();if("middle-left"===a||"middle-right"===a){const t=i.scaleX(),e=i.width()*t,r=E(ht.current,o.a.fontSize);let n=e;e<r&&(n=r,ft.current&&i.position(ft.current)),i.width(n),i.scaleX(1),i.scaleY(1);let a=dt();if("ellipsis"===k.textOverflow){a=G.current}else{const t=Math.max(a,G.current);i.height(t),o.set({height:i.height()})}const l=k.textVerticalResizeEnabled?Math.max(a,G.current):dt();o.set({x:i.x(),width:i.width(),rotation:i.rotation(),height:l}),i.skewX(0),i.skewY(0),st()}if("top-center"===a||"bottom-center"===a){const e="resize"===k.textOverflow?dt():wt*o.a.fontSize,r=t.target.height()*t.target.scaleY();if(r<e){if(t.target.height(e),ft.current){if("top-center"===Q.current){const r=K.current*Math.PI/180,n=tt.current-e;t.target.x(ft.current.x-n*Math.sin(r)),t.target.y(ft.current.y+n*Math.cos(r))}else{t.target.position(ft.current)}}}else{t.target.height(r)}t.target.scaleY(1),t.target.scaleX(1),t.target.rotation(K.current),t.target.skewX(0),t.target.skewY(0),tt.current=Math.max(e,r)}ft.current=t.target.position();const l=t.target.scaleX();null===(n=P.current)||void 0===n||n.setAttrs({scaleX:1,scaleY:1}),t.target.scaleX(1),t.target.scaleY(1),o.set({fontSize:o.a.fontSize*l,width:t.target.width()*l,x:t.target.x(),y:t.target.y(),rotation:t.target.rotation(),height:t.target.height()*l,shadowBlur:o.shadowBlur*l,shadowOffsetX:o.shadowOffsetX*l,shadowOffsetY:o.shadowOffsetY*l,strokeWidth:o.strokeWidth*l})},onTransformEnd:t=>{var e;const r=t.target.scaleX();t.target.scaleX(1),t.target.scaleY(1),o.set(Object.assign(Object.assign({},S(o,o.fontSize*r)),{width:Math.ceil(t.target.width()*r),x:t.target.x(),y:t.target.y(),rotation:t.target.rotation(),height:t.target.height()*r})),null===(e=P.current)||void 0===e||e.setAttrs({scaleX:1,scaleY:1}),q(!1)}})),I&&o.contentEditable&&t(i,{x:o.a.x,y:o.a.y,rotation:o.a.rotation,children:t(J,{textNodeRef:z,element:o,selectAll:N,cursorPosition:gt.current,onBlur:()=>{o.set(b(o)),o.toggleEditMode(!1)}})})]})});
@@ -1 +1 @@
1
- import e from"react";import t from"konva";import{getClientRect as n}from"../utils/math.js";import{useWorkspaceStyle as o}from"./workspace-style.js";let r=({targetKonvaNodes:e,guideKonvaNode:t,distance:n,snapDirection:o})=>n<5;export const setSnapFilterFunc=e=>{r=e};function s(e,t){var n=[],o=[];e.vertical.forEach(e=>{t.vertical.forEach(t=>{var o=Math.abs(e.offset-t.guide);r({targetKonvaNodes:t.nodes,guideKonvaNode:e.node,distance:o,snapDirection:e.snap})&&n.push({lineGuide:e.offset,diff:o,snap:t.snap,offset:t.offset})})}),e.horizontal.forEach(e=>{t.horizontal.forEach(t=>{var n=Math.abs(e.offset-t.guide);r({targetKonvaNodes:t.nodes,guideKonvaNode:e.node,distance:n,snapDirection:e.snap})&&o.push({lineGuide:e.offset,diff:n,snap:t.snap,offset:t.offset})})});var s=[];const i=n.sort((e,t)=>e.diff-t.diff),a=o.sort((e,t)=>e.diff-t.diff);var d=i[0],c=a[0];return d&&i.filter(e=>Math.abs(e.diff-d.diff)<.1).forEach(e=>{s.push(Object.assign({orientation:"V"},e))}),c&&a.filter(e=>Math.abs(e.diff-c.diff)<.1).forEach(e=>{s.push(Object.assign({orientation:"H"},e))}),s}export const ensureDragOrder=()=>{if(0===t.DD._dragElements.size){return}const e=[...t.DD._dragElements.entries()],n=e.find(([e,n])=>n.node instanceof t.Transformer);n&&(e.splice(e.indexOf(n),1),e.unshift(n),t.DD._dragElements.clear(),e.forEach(([e,n])=>{t.DD._dragElements.set(e,n)}))};function i(e,n,o){return new t.Line({x:-e.x(),y:-e.y(),points:o,stroke:n.stroke,strokeWidth:n.strokeWidth,name:"guid-line",dash:n.dash})}function a(e,t,n){const o=null==e?void 0:e.children.find(e=>"line-guides"===e.name()),r=e.getStage();n.forEach(e=>{"H"===e.orientation?null==o||o.add(i(r,t,[-6e3,e.lineGuide,6e3,e.lineGuide])):"V"===e.orientation&&(null==o||o.add(i(r,t,[e.lineGuide,-6e3,e.lineGuide,6e3])))})}export function useSnap(r,f){const u=e.useRef(null),l=e.useRef(null),h=e.useRef(new Map),g=e.useRef(null),{snapGuideStyle:y}=o(),p=e.useRef(y);p.current=y;const x=e=>e.hasName("element")||e.hasName("page-background")||!u.current&&e.hasName("elements-area");function v(e){var t;const n=null===(t=r.current)||void 0===t?void 0:t.getStage(),o=[],s=[];return n.find(x).forEach(t=>{if(!(e.indexOf(t)>=0)){var n=t.getClientRect({skipShadow:!0,skipStroke:!0});o.push({offset:n.x,node:t,snap:"start"},{offset:n.x+n.width,node:t,snap:"end"},{offset:n.x+n.width/2,node:t,snap:"center"}),s.push({offset:n.y,node:t,snap:"start"},{offset:n.y+n.height,node:t,snap:"end"},{offset:n.y+n.height/2,node:t,snap:"center"})}}),{vertical:o,horizontal:s}}function m(e){var t;a(null===(t=r.current)||void 0===t?void 0:t.getLayer(),p.current,e)}const b=e=>{var o;const r=e.target.getLayer(),a=r.children.find(e=>"line-guides"===e.name());null==a||a.destroyChildren();const d=l.current;if((null===(o=e.evt)||void 0===o?void 0:o.shiftKey)&&d){const t=e.target.getAbsolutePosition();let n=t.x-d.x,o=t.y-d.y;const s=Math.abs(n),c=Math.abs(o);if(s>2.414*c){o=0}else if(c>2.414*s){n=0}else{const e=(s+c)/2;n=Math.sign(n)*e,o=Math.sign(o)*e}e.target.nodes().forEach(e=>{const t=h.current.get(e);t&&e.setAbsolutePosition({x:t.x+n,y:t.y+o})});const f=g.current;if(f&&(s>0||c>0)){const e=Math.sign(n),t=Math.sign(o);null==a||a.add(i(r.getStage(),p.current,[f.x-6e3*e,f.y-6e3*t,f.x+6e3*e,f.y+6e3*t]))}return}var c=v(e.target.nodes()),f=function(e){const o=e.__getNodeRect(),r=n(Object.assign(Object.assign({},o),{rotation:t.Util.radToDeg(o.rotation)})),s=e.getAbsolutePosition();return{vertical:[{guide:r.x,offset:s.x-r.x,snap:"start",nodes:e.nodes()},{guide:r.x+r.width/2,offset:s.x-r.x-r.width/2,snap:"center",nodes:e.nodes()},{guide:r.x+r.width,offset:s.x-r.x-r.width,snap:"end",nodes:e.nodes()}],horizontal:[{guide:r.y,offset:s.y-r.y,snap:"start",nodes:e.nodes()},{guide:r.y+r.height/2,offset:s.y-r.y-r.height/2,snap:"center",nodes:e.nodes()},{guide:r.y+r.height,offset:s.y-r.y-r.height,snap:"end",nodes:e.nodes()}]}}(e.target),u=s(c,f);if(!u.length){return}m(u);const y=e.target.getAbsolutePosition(),x=(e.target.nodes().map(e=>e.getAbsolutePosition()),Object.assign({},y));u.forEach(e=>{switch(e.snap){case"start":case"center":case"end":switch(e.orientation){case"V":x.x=e.lineGuide+e.offset;break;case"H":x.y=e.lineGuide+e.offset}}});const b=x.x-y.x,w=x.y-y.y;e.evt.ctrlKey||e.evt.metaKey||e.target.nodes().forEach(e=>{const t=e.getAbsolutePosition();e.setAbsolutePosition({x:t.x+b,y:t.y+w})})},w=(e,t,n)=>{var o;const i=r.current,a=i.getLayer().children.find(e=>"line-guides"===e.name());if(null==a||a.destroyChildren(),"rotater"===i.getActiveAnchor()){return t}const f=i.getActiveAnchor(),u=c[f],l=null===(o=i.findOne(`.${u}`))||void 0===o?void 0:o.getAbsolutePosition();if(!l){return t}const h={x:e.x-l.x,y:e.y-l.y},g=function(e,t){const n=d(e,t)/d(t,t);return{x:n*t.x,y:n*t.y}}({x:t.x-e.x,y:t.y-e.y},h);if(Math.sqrt(Math.pow(g.x,2)+Math.pow(g.y,2))>5){return t}const y={x:e.x+g.x,y:e.y+g.y};var p=s(v(i.nodes()),{vertical:[{guide:y.x,offset:0,snap:"start",nodes:i.nodes()}],horizontal:[{guide:y.y,offset:0,snap:"start",nodes:i.nodes()}]});if(!p.length){return t}if(m(p),n.ctrlKey||n.metaKey){return t}const x=[];if(p.forEach(e=>{const t=function(e,t,n){if("V"===n.orientation){const o=n.lineGuide;if(Math.abs(t.x-e.x)<1e-4){return null}const r=(t.y-e.y)/(t.x-e.x);return{x:o,y:r*o+(e.y-r*e.x)}}{const o=n.lineGuide;if(Math.abs(t.y-e.y)<1e-4){return null}const r=(t.y-e.y)/(t.x-e.x);return{x:(o-e.y)/r+e.x,y:o}}}(y,l,{orientation:e.orientation,lineGuide:e.lineGuide});t&&x.push(t)}),x.length>0){let e=x[0],t=Math.sqrt(Math.pow(y.x-e.x,2)+Math.pow(y.y-e.y,2));if(x.forEach(n=>{const o=Math.sqrt(Math.pow(y.x-n.x,2)+Math.pow(y.y-n.y,2));o<t&&(t=o,e=n)}),t<10){return e}}return y},M=e=>{if(l.current=null,h.current=new Map,g.current=null,!e.target){return}const t=e.target.getLayer(),n=t.children.find(e=>"line-guides"===e.name());null==n||n.destroyChildren(),t.batchDraw()};e.useEffect(()=>{r.current&&(r.current.anchorDragBoundFunc(w),r.current.on("dragstart",e=>{const t=r.current;if(t){l.current=t.getAbsolutePosition(),h.current=new Map(t.nodes().map(e=>[e,e.getAbsolutePosition()]));const e=t.getClientRect();g.current={x:e.x+e.width/2,y:e.y+e.height/2}}setTimeout(()=>{ensureDragOrder()})}),r.current.on("dragmove",b),r.current.on("dragend",M),r.current.on("transformend",M),r.current.on("transform",e=>{var t,n;e.evt.ctrlKey||e.evt.metaKey?null===(t=r.current)||void 0===t||t.rotationSnapTolerance(0):null===(n=r.current)||void 0===n||n.rotationSnapTolerance(5)}))},[])}export function useAnchorSnap(t,n,r){const{snapGuideStyle:i}=o(),d=e.useRef(i);d.current=i;const c=e=>e.hasName("element")||e.hasName("line-anchor")||e.hasName("page-background")||e.hasName("elements-area"),f=e=>{const o=e.target.getLayer().children.find(e=>"line-guides"===e.name());null==o||o.destroyChildren();var r,i=s(function(e){var n;const o=null===(n=t.current)||void 0===n?void 0:n.getStage();var r=[],s=[];return o.find(c).forEach(t=>{if(!(e.indexOf(t)>=0)){var n=t.getClientRect({skipShadow:!0,skipStroke:!0});t.hasName("line-anchor")&&(n={x:t.absolutePosition().x,y:t.absolutePosition().y,width:0,height:0}),r.push({offset:n.x,node:t,snap:"start"},{offset:n.x+n.width,node:t,snap:"end"},{offset:n.x+n.width/2,node:t,snap:"center"}),s.push({offset:n.y,node:t,snap:"start"},{offset:n.y+n.height,node:t,snap:"end"},{offset:n.y+n.height/2,node:t,snap:"center"})}}),{vertical:r,horizontal:s}}([e.target,...n.map(e=>e.current)]),{vertical:[{guide:(r=e.target).absolutePosition().x,offset:0,snap:"center",nodes:[r]}],horizontal:[{guide:r.absolutePosition().y,offset:0,snap:"center",nodes:[r]}]});if(!i.length){return}!function(e){var n;a(null===(n=t.current)||void 0===n?void 0:n.getLayer(),d.current,e)}(i);const f=e.target.getAbsolutePosition(),u=Object.assign({},f);i.forEach(e=>{switch(e.snap){case"start":case"center":case"end":switch(e.orientation){case"V":u.x=e.lineGuide+e.offset;break;case"H":u.y=e.lineGuide+e.offset}}});const l=u.x-f.x,h=u.y-f.y;if(!e.evt.ctrlKey&&!e.evt.metaKey){const t=e.target.getAbsolutePosition();e.target.absolutePosition({x:t.x+l,y:t.y+h})}},u=e=>{if(!e.target){return}const t=e.target.getLayer(),n=t.children.find(e=>"line-guides"===e.name());null==n||n.destroyChildren(),t.batchDraw()};e.useEffect(()=>{t.current&&(t.current.on("dragmove",f),t.current.on("dragend",u))},r)}function d(e,t){return e.x*t.x+e.y*t.y}const c={"top-left":"bottom-right","top-center":"bottom-center","top-right":"bottom-left","middle-right":"middle-left","bottom-right":"top-left","bottom-center":"top-center","bottom-left":"top-right","middle-left":"middle-right"};
1
+ import e from"react";import t from"konva";import{getClientRect as n}from"../utils/math.js";import{useWorkspaceStyle as o}from"./workspace-style.js";let r=({targetKonvaNodes:e,guideKonvaNode:t,distance:n,snapDirection:o})=>n<5;export const setSnapFilterFunc=e=>{r=e};function s(e,t){var n=[],o=[];e.vertical.forEach(e=>{t.vertical.forEach(t=>{var o=Math.abs(e.offset-t.guide);r({targetKonvaNodes:t.nodes,guideKonvaNode:e.node,distance:o,snapDirection:e.snap})&&n.push({lineGuide:e.offset,diff:o,snap:t.snap,offset:t.offset})})}),e.horizontal.forEach(e=>{t.horizontal.forEach(t=>{var n=Math.abs(e.offset-t.guide);r({targetKonvaNodes:t.nodes,guideKonvaNode:e.node,distance:n,snapDirection:e.snap})&&o.push({lineGuide:e.offset,diff:n,snap:t.snap,offset:t.offset})})});var s=[];const i=n.sort((e,t)=>e.diff-t.diff),a=o.sort((e,t)=>e.diff-t.diff);var d=i[0],c=a[0];return d&&i.filter(e=>Math.abs(e.diff-d.diff)<.1).forEach(e=>{s.push(Object.assign({orientation:"V"},e))}),c&&a.filter(e=>Math.abs(e.diff-c.diff)<.1).forEach(e=>{s.push(Object.assign({orientation:"H"},e))}),s}export const ensureDragOrder=()=>{if(0===t.DD._dragElements.size){return}const e=[...t.DD._dragElements.entries()],n=e.find(([e,n])=>n.node instanceof t.Transformer);n&&(e.splice(e.indexOf(n),1),e.unshift(n),t.DD._dragElements.clear(),e.forEach(([e,n])=>{t.DD._dragElements.set(e,n)}))};function i(e,n,o){return new t.Line({x:-e.x(),y:-e.y(),points:o,stroke:n.stroke,strokeWidth:n.strokeWidth,name:"guid-line",dash:n.dash})}function a(e,t,n){const o=null==e?void 0:e.children.find(e=>"line-guides"===e.name()),r=e.getStage();n.forEach(e=>{"H"===e.orientation?null==o||o.add(i(r,t,[-6e3,e.lineGuide,6e3,e.lineGuide])):"V"===e.orientation&&(null==o||o.add(i(r,t,[e.lineGuide,-6e3,e.lineGuide,6e3])))})}export function useSnap(r,f){const u=e.useRef(null),l=e.useRef(null),h=e.useRef(new Map),g=e.useRef(null),{snapGuideStyle:y}=o(),p=e.useRef(y);p.current=y;const x=e=>e.hasName("element")||e.hasName("page-background")||!u.current&&e.hasName("elements-area");function v(e){var t;const n=null===(t=r.current)||void 0===t?void 0:t.getStage(),o=[],s=[];return n.find(x).forEach(t=>{if(!(e.indexOf(t)>=0)){var n=t.getClientRect({skipShadow:!0,skipStroke:!0});o.push({offset:n.x,node:t,snap:"start"},{offset:n.x+n.width,node:t,snap:"end"},{offset:n.x+n.width/2,node:t,snap:"center"}),s.push({offset:n.y,node:t,snap:"start"},{offset:n.y+n.height,node:t,snap:"end"},{offset:n.y+n.height/2,node:t,snap:"center"})}}),{vertical:o,horizontal:s}}function m(e){var t;a(null===(t=r.current)||void 0===t?void 0:t.getLayer(),p.current,e)}const b=e=>{var o,r;const a=null===(o=e.target)||void 0===o?void 0:o.getLayer();if(!a){return}const d=a.children.find(e=>"line-guides"===e.name());null==d||d.destroyChildren();const c=l.current;if((null===(r=e.evt)||void 0===r?void 0:r.shiftKey)&&c){const t=e.target.getAbsolutePosition();let n=t.x-c.x,o=t.y-c.y;const r=Math.abs(n),s=Math.abs(o);if(r>2.414*s){o=0}else if(s>2.414*r){n=0}else{const e=(r+s)/2;n=Math.sign(n)*e,o=Math.sign(o)*e}e.target.nodes().forEach(e=>{const t=h.current.get(e);t&&e.setAbsolutePosition({x:t.x+n,y:t.y+o})});const f=g.current;if(f&&(r>0||s>0)){const e=Math.sign(n),t=Math.sign(o);null==d||d.add(i(a.getStage(),p.current,[f.x-6e3*e,f.y-6e3*t,f.x+6e3*e,f.y+6e3*t]))}return}var f=v(e.target.nodes()),u=function(e){const o=e.__getNodeRect(),r=n(Object.assign(Object.assign({},o),{rotation:t.Util.radToDeg(o.rotation)})),s=e.getAbsolutePosition();return{vertical:[{guide:r.x,offset:s.x-r.x,snap:"start",nodes:e.nodes()},{guide:r.x+r.width/2,offset:s.x-r.x-r.width/2,snap:"center",nodes:e.nodes()},{guide:r.x+r.width,offset:s.x-r.x-r.width,snap:"end",nodes:e.nodes()}],horizontal:[{guide:r.y,offset:s.y-r.y,snap:"start",nodes:e.nodes()},{guide:r.y+r.height/2,offset:s.y-r.y-r.height/2,snap:"center",nodes:e.nodes()},{guide:r.y+r.height,offset:s.y-r.y-r.height,snap:"end",nodes:e.nodes()}]}}(e.target),y=s(f,u);if(!y.length){return}m(y);const x=e.target.getAbsolutePosition(),b=(e.target.nodes().map(e=>e.getAbsolutePosition()),Object.assign({},x));y.forEach(e=>{switch(e.snap){case"start":case"center":case"end":switch(e.orientation){case"V":b.x=e.lineGuide+e.offset;break;case"H":b.y=e.lineGuide+e.offset}}});const w=b.x-x.x,M=b.y-x.y;e.evt.ctrlKey||e.evt.metaKey||e.target.nodes().forEach(e=>{const t=e.getAbsolutePosition();e.setAbsolutePosition({x:t.x+w,y:t.y+M})})},w=(e,t,n)=>{var o;const i=r.current;if(!i){return t}const a=i.getLayer();if(!a){return t}const f=a.children.find(e=>"line-guides"===e.name());if(null==f||f.destroyChildren(),"rotater"===i.getActiveAnchor()){return t}const u=i.getActiveAnchor(),l=c[u],h=null===(o=i.findOne(`.${l}`))||void 0===o?void 0:o.getAbsolutePosition();if(!h){return t}const g={x:e.x-h.x,y:e.y-h.y},y=function(e,t){const n=d(e,t)/d(t,t);return{x:n*t.x,y:n*t.y}}({x:t.x-e.x,y:t.y-e.y},g);if(Math.sqrt(Math.pow(y.x,2)+Math.pow(y.y,2))>5){return t}const p={x:e.x+y.x,y:e.y+y.y};var x=s(v(i.nodes()),{vertical:[{guide:p.x,offset:0,snap:"start",nodes:i.nodes()}],horizontal:[{guide:p.y,offset:0,snap:"start",nodes:i.nodes()}]});if(!x.length){return t}if(m(x),n.ctrlKey||n.metaKey){return t}const b=[];if(x.forEach(e=>{const t=function(e,t,n){if("V"===n.orientation){const o=n.lineGuide;if(Math.abs(t.x-e.x)<1e-4){return null}const r=(t.y-e.y)/(t.x-e.x);return{x:o,y:r*o+(e.y-r*e.x)}}{const o=n.lineGuide;if(Math.abs(t.y-e.y)<1e-4){return null}const r=(t.y-e.y)/(t.x-e.x);return{x:(o-e.y)/r+e.x,y:o}}}(p,h,{orientation:e.orientation,lineGuide:e.lineGuide});t&&b.push(t)}),b.length>0){let e=b[0],t=Math.sqrt(Math.pow(p.x-e.x,2)+Math.pow(p.y-e.y,2));if(b.forEach(n=>{const o=Math.sqrt(Math.pow(p.x-n.x,2)+Math.pow(p.y-n.y,2));o<t&&(t=o,e=n)}),t<10){return e}}return p},M=e=>{if(l.current=null,h.current=new Map,g.current=null,!e.target){return}const t=e.target.getLayer();if(!t){return}const n=t.children.find(e=>"line-guides"===e.name());null==n||n.destroyChildren(),t.batchDraw()};e.useEffect(()=>{r.current&&(r.current.anchorDragBoundFunc(w),r.current.on("dragstart",e=>{const t=r.current;if(t){l.current=t.getAbsolutePosition(),h.current=new Map(t.nodes().map(e=>[e,e.getAbsolutePosition()]));const e=t.getClientRect();g.current={x:e.x+e.width/2,y:e.y+e.height/2}}setTimeout(()=>{ensureDragOrder()})}),r.current.on("dragmove",b),r.current.on("dragend",M),r.current.on("transformend",M),r.current.on("transform",e=>{var t,n;e.evt.ctrlKey||e.evt.metaKey?null===(t=r.current)||void 0===t||t.rotationSnapTolerance(0):null===(n=r.current)||void 0===n||n.rotationSnapTolerance(5)}))},[])}export function useAnchorSnap(t,n,r){const{snapGuideStyle:i}=o(),d=e.useRef(i);d.current=i;const c=e=>e.hasName("element")||e.hasName("line-anchor")||e.hasName("page-background")||e.hasName("elements-area"),f=e=>{var o;const r=null===(o=e.target)||void 0===o?void 0:o.getLayer();if(!r){return}const i=r.children.find(e=>"line-guides"===e.name());null==i||i.destroyChildren();var f,u=function(e){var n;const o=null===(n=t.current)||void 0===n?void 0:n.getStage();var r=[],s=[];return o.find(c).forEach(t=>{if(!(e.indexOf(t)>=0)){var n=t.getClientRect({skipShadow:!0,skipStroke:!0});t.hasName("line-anchor")&&(n={x:t.absolutePosition().x,y:t.absolutePosition().y,width:0,height:0}),r.push({offset:n.x,node:t,snap:"start"},{offset:n.x+n.width,node:t,snap:"end"},{offset:n.x+n.width/2,node:t,snap:"center"}),s.push({offset:n.y,node:t,snap:"start"},{offset:n.y+n.height,node:t,snap:"end"},{offset:n.y+n.height/2,node:t,snap:"center"})}}),{vertical:r,horizontal:s}}([e.target,...n.map(e=>e.current)]),l=s(u,{vertical:[{guide:(f=e.target).absolutePosition().x,offset:0,snap:"center",nodes:[f]}],horizontal:[{guide:f.absolutePosition().y,offset:0,snap:"center",nodes:[f]}]});if(!l.length){return}!function(e){var n;a(null===(n=t.current)||void 0===n?void 0:n.getLayer(),d.current,e)}(l);const h=e.target.getAbsolutePosition(),g=Object.assign({},h);l.forEach(e=>{switch(e.snap){case"start":case"center":case"end":switch(e.orientation){case"V":g.x=e.lineGuide+e.offset;break;case"H":g.y=e.lineGuide+e.offset}}});const y=g.x-h.x,p=g.y-h.y;if(!e.evt.ctrlKey&&!e.evt.metaKey){const t=e.target.getAbsolutePosition();e.target.absolutePosition({x:t.x+y,y:t.y+p})}},u=e=>{if(!e.target){return}const t=e.target.getLayer();if(!t){return}const n=t.children.find(e=>"line-guides"===e.name());null==n||n.destroyChildren(),t.batchDraw()};e.useEffect(()=>{t.current&&(t.current.on("dragmove",f),t.current.on("dragend",u))},r)}function d(e,t){return e.x*t.x+e.y*t.y}const c={"top-left":"bottom-right","top-center":"bottom-center","top-right":"bottom-left","middle-right":"middle-left","bottom-right":"top-left","bottom-center":"top-center","bottom-left":"top-right","middle-left":"middle-right"};
package/icons/meronex.js CHANGED
@@ -1 +1 @@
1
- import{jsx as c,jsxs as t}from"react/jsx-runtime";export const MdOpacity=t=>c("svg",Object.assign({width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor"},t,{children:c("path",{d:"M17.66 8L12 2.35 6.34 8C4.78 9.56 4 11.64 4 13.64s.78 4.11 2.34 5.67 3.61 2.35 5.66 2.35 4.1-.79 5.66-2.35S20 15.64 20 13.64 19.22 9.56 17.66 8zM6 14c.01-2 .62-3.27 1.76-4.4L12 5.27l4.24 4.38C17.38 10.77 17.99 12 18 14H6z"})}));export const MdFormatTextdirectionRToL=t=>c("svg",Object.assign({width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor"},t,{children:c("path",{d:"M10 10v5h2V4h2v11h2V4h2V2h-8C7.79 2 6 3.79 6 6s1.79 4 4 4zm-2 7v-3l-4 4 4 4v-3h12v-2H8z"})}));export const MdFormatTextdirectionLToR=t=>c("svg",Object.assign({width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor"},t,{children:c("path",{d:"M9 10v5h2V4h2v11h2V4h2V2H9C6.79 2 5 3.79 5 6s1.79 4 4 4zm12 8l-4-4v3H5v2h12v3l4-4z"})}));export const MdcFormatVerticalAlignTop=t=>c("svg",Object.assign({width:"16",height:"16",version:"1.1",id:"mdi-format-vertical-align-top",viewBox:"0 0 24 24",fill:"currentColor"},t,{children:c("path",{d:"M8,11H11V21H13V11H16L12,7L8,11M4,3V5H20V3H4Z"})}));export const MdcFormatVerticalAlignCenter=t=>c("svg",Object.assign({width:"16",height:"16",version:"1.1",id:"mdi-format-vertical-align-center",viewBox:"0 0 24 24",fill:"currentColor"},t,{children:c("path",{d:"M8,19H11V23H13V19H16L12,15L8,19M16,5H13V1H11V5H8L12,9L16,5M4,11V13H20V11H4Z"})}));export const MdcFormatVerticalAlignBottom=t=>c("svg",Object.assign({width:"16",height:"16",version:"1.1",id:"mdi-format-vertical-align-bottom",viewBox:"0 0 24 24",fill:"currentColor"},t,{children:c("path",{d:"M16,13H13V3H11V13H8L12,17L16,13M4,19V21H20V19H4Z"})}));export const MdcFormatListBulleted=t=>c("svg",Object.assign({width:"16",height:"16",version:"1.1",id:"mdi-format-list-bulleted",viewBox:"0 0 24 24",fill:"currentColor"},t,{children:c("path",{d:"M7,5H21V7H7V5M7,13V11H21V13H7M4,4.5A1.5,1.5 0 0,1 5.5,6A1.5,1.5 0 0,1 4,7.5A1.5,1.5 0 0,1 2.5,6A1.5,1.5 0 0,1 4,4.5M4,10.5A1.5,1.5 0 0,1 5.5,12A1.5,1.5 0 0,1 4,13.5A1.5,1.5 0 0,1 2.5,12A1.5,1.5 0 0,1 4,10.5M7,19V17H21V19H7M4,16.5A1.5,1.5 0 0,1 5.5,18A1.5,1.5 0 0,1 4,19.5A1.5,1.5 0 0,1 2.5,18A1.5,1.5 0 0,1 4,16.5Z"})}));export const MdcFormatListNumbered=t=>c("svg",Object.assign({width:"16",height:"16",version:"1.1",id:"mdi-format-list-numbered",viewBox:"0 0 24 24",fill:"currentColor"},t,{children:c("path",{d:"M7,13V11H21V13H7M7,19V17H21V19H7M7,7V5H21V7H7M3,8V5H2V4H4V8H3M2,17V16H5V20H2V19H4V18.5H3V17.5H4V17H2M4.25,10A0.75,0.75 0 0,1 5,10.75C5,10.95 4.92,11.14 4.79,11.27L3.12,13H5V14H2V13.08L4,11H2V10H4.25Z"})}));export const MdcFormatLineSpacing=t=>c("svg",Object.assign({width:"16",height:"16",version:"1.1",id:"mdi-format-line-spacing",viewBox:"0 0 24 24",fill:"currentColor"},t,{children:c("path",{d:"M10,13H22V11H10M10,19H22V17H10M10,7H22V5H10M6,7H8.5L5,3.5L1.5,7H4V17H1.5L5,20.5L8.5,17H6V7Z"})}));export const MdcFormatLetterCase=t=>c("svg",Object.assign({width:"16",height:"16",version:"1.1",id:"mdi-format-letter-case",viewBox:"0 0 24 24",fill:"currentColor"},t,{children:c("path",{d:"M20.06,18C20,17.83 19.91,17.54 19.86,17.11C19.19,17.81 18.38,18.16 17.45,18.16C16.62,18.16 15.93,17.92 15.4,17.45C14.87,17 14.6,16.39 14.6,15.66C14.6,14.78 14.93,14.1 15.6,13.61C16.27,13.12 17.21,12.88 18.43,12.88H19.83V12.24C19.83,11.75 19.68,11.36 19.38,11.07C19.08,10.78 18.63,10.64 18.05,10.64C17.53,10.64 17.1,10.76 16.75,11C16.4,11.25 16.23,11.54 16.23,11.89H14.77C14.77,11.46 14.92,11.05 15.22,10.65C15.5,10.25 15.93,9.94 16.44,9.71C16.95,9.5 17.5,9.36 18.13,9.36C19.11,9.36 19.87,9.6 20.42,10.09C20.97,10.58 21.26,11.25 21.28,12.11V16C21.28,16.8 21.38,17.42 21.58,17.88V18H20.06M17.66,16.88C18.11,16.88 18.54,16.77 18.95,16.56C19.35,16.35 19.65,16.07 19.83,15.73V14.16H18.7C16.93,14.16 16.04,14.63 16.04,15.57C16.04,16 16.19,16.3 16.5,16.53C16.8,16.76 17.18,16.88 17.66,16.88M5.46,13.71H9.53L7.5,8.29L5.46,13.71M6.64,6H8.36L13.07,18H11.14L10.17,15.43H4.82L3.86,18H1.93L6.64,6Z"})}));export const FaShapes=t=>c("svg",Object.assign({width:"16",height:"16",viewBox:"0 0 512 512",fill:"currentColor"},t,{children:c("path",{d:"M128,256A128,128,0,1,0,256,384,128,128,0,0,0,128,256Zm379-54.86L400.07,18.29a37.26,37.26,0,0,0-64.14,0L229,201.14C214.76,225.52,232.58,256,261.09,256H474.91C503.42,256,521.24,225.52,507,201.14ZM480,288H320a32,32,0,0,0-32,32V480a32,32,0,0,0,32,32H480a32,32,0,0,0,32-32V320A32,32,0,0,0,480,288Z"})}));export const FaBrain=t=>c("svg",Object.assign({width:"16",height:"16",viewBox:"0 0 576 512",fill:"currentColor"},t,{children:c("path",{d:"M208 0c-29.9 0-54.7 20.5-61.8 48.2-.8 0-1.4-.2-2.2-.2-35.3 0-64 28.7-64 64 0 4.8.6 9.5 1.7 14C52.5 138 32 166.6 32 200c0 12.6 3.2 24.3 8.3 34.9C16.3 248.7 0 274.3 0 304c0 33.3 20.4 61.9 49.4 73.9-.9 4.6-1.4 9.3-1.4 14.1 0 39.8 32.2 72 72 72 4.1 0 8.1-.5 12-1.2 9.6 28.5 36.2 49.2 68 49.2 39.8 0 72-32.2 72-72V64c0-35.3-28.7-64-64-64zm368 304c0-29.7-16.3-55.3-40.3-69.1 5.2-10.6 8.3-22.3 8.3-34.9 0-33.4-20.5-62-49.7-74 1-4.5 1.7-9.2 1.7-14 0-35.3-28.7-64-64-64-.8 0-1.5.2-2.2.2C422.7 20.5 397.9 0 368 0c-35.3 0-64 28.6-64 64v376c0 39.8 32.2 72 72 72 31.8 0 58.4-20.7 68-49.2 3.9.7 7.9 1.2 12 1.2 39.8 0 72-32.2 72-72 0-4.8-.5-9.5-1.4-14.1 29-12 49.4-40.6 49.4-73.9z"})}));export const FdPageMultiple=i=>c("svg",Object.assign({width:"16",height:"16",version:"1.1",id:"Layer_1",x:"0px",y:"0px",viewBox:"0 0 100 100",enableBackground:"new 0 0 100 100",fill:"currentColor"},i,{children:t("g",{children:[c("path",{d:"M86.45,23.27h-3.475V90.18c0,0.835-0.677,1.513-1.513,1.513H31.987v3.475c0,0.836,0.677,1.513,1.513,1.513l0.001,0v0h52.95c0.836,0,1.513-0.677,1.513-1.513V24.782C87.963,23.946,87.286,23.27,86.45,23.27z"}),c("path",{d:"M77.988,85.193V14.807c0-0.836-0.677-1.513-1.513-1.513h-3.475v66.911c0,0.836-0.677,1.513-1.513,1.513H22.011v3.475c0,0.836,0.677,1.513,1.513,1.513c0,0,0,0,0,0h52.951C77.311,86.706,77.988,86.029,77.988,85.193z"}),c("path",{d:"M68.013,75.218V4.832c0-0.836-0.677-1.513-1.513-1.513H13.55c-0.836,0-1.513,0.677-1.513,1.513v70.386c0,0.836,0.677,1.513,1.513,1.513H66.5C67.336,76.731,68.013,76.054,68.013,75.218z"})]})}));export const ZoStrokeWidth=t=>c("svg",Object.assign({width:"16",height:"16",viewBox:"0 0 20 20",fill:"currentColor"},t,{children:c("path",{d:"M0 0h20v5H0V0zm0 7h20v4H0V7zm0 6h20v3H0v-3zm0 5h20v2H0v-2z"})}));export const ZoDocument=t=>c("svg",Object.assign({width:"16",height:"16",viewBox:"0 0 20 20",fill:"currentColor"},t,{children:c("path",{d:"M4 18h12V6h-4V2H4v16zm-2 1V0h12l4 4v16H2v-1z"})}));export const CgColorPicker=i=>t("svg",Object.assign({width:"16",height:"16",viewBox:"0 0 24 24",fill:"none"},i,{children:[c("path",{d:"M20.3847 2.87868C19.2132 1.70711 17.3137 1.70711 16.1421 2.87868L14.0202 5.00052L13.313 4.29332C12.9225 3.9028 12.2894 3.9028 11.8988 4.29332C11.5083 4.68385 11.5083 5.31701 11.8988 5.70754L17.5557 11.3644C17.9462 11.7549 18.5794 11.7549 18.9699 11.3644C19.3604 10.9739 19.3604 10.3407 18.9699 9.95018L18.2629 9.24316L20.3847 7.12132C21.5563 5.94975 21.5563 4.05025 20.3847 2.87868Z",fill:"currentColor"}),c("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M11.9297 7.09116L4.1515 14.8693C3.22786 15.793 3.03239 17.169 3.5651 18.2842L1.99994 19.8493L3.41415 21.2635L4.97931 19.6984C6.09444 20.2311 7.4705 20.0356 8.39414 19.112L16.1723 11.3338L11.9297 7.09116ZM13.3439 11.3338L11.9297 9.91959L5.56571 16.2835C5.17518 16.6741 5.17518 17.3072 5.56571 17.6978C5.95623 18.0883 6.5894 18.0883 6.97992 17.6978L13.3439 11.3338Z",fill:"currentColor"})]}));export const AiOutlineFacebook=t=>c("svg",Object.assign({width:"16",height:"16",className:"icon",viewBox:"0 0 1024 1024",fill:"currentColor"},t,{children:c("path",{d:"M880 112H144c-17.7 0-32 14.3-32 32v736c0 17.7 14.3 32 32 32h736c17.7 0 32-14.3 32-32V144c0-17.7-14.3-32-32-32zm-32 736H663.9V602.2h104l15.6-120.7H663.9v-77.1c0-35 9.7-58.8 59.8-58.8h63.9v-108c-11.1-1.5-49-4.8-93.2-4.8-92.2 0-155.3 56.3-155.3 159.6v89H434.9v120.7h104.3V848H176V176h672v672z"})}));export const AiOutlineInstagram=t=>c("svg",Object.assign({width:"16",height:"16",className:"icon",viewBox:"0 0 1024 1024",fill:"currentColor"},t,{children:c("path",{d:"M512 306.9c-113.5 0-205.1 91.6-205.1 205.1S398.5 717.1 512 717.1 717.1 625.5 717.1 512 625.5 306.9 512 306.9zm0 338.4c-73.4 0-133.3-59.9-133.3-133.3S438.6 378.7 512 378.7 645.3 438.6 645.3 512 585.4 645.3 512 645.3zm213.5-394.6c-26.5 0-47.9 21.4-47.9 47.9s21.4 47.9 47.9 47.9 47.9-21.3 47.9-47.9a47.84 47.84 0 0 0-47.9-47.9zM911.8 512c0-55.2.5-109.9-2.6-165-3.1-64-17.7-120.8-64.5-167.6-46.9-46.9-103.6-61.4-167.6-64.5-55.2-3.1-109.9-2.6-165-2.6-55.2 0-109.9-.5-165 2.6-64 3.1-120.8 17.7-167.6 64.5C132.6 226.3 118.1 283 115 347c-3.1 55.2-2.6 109.9-2.6 165s-.5 109.9 2.6 165c3.1 64 17.7 120.8 64.5 167.6 46.9 46.9 103.6 61.4 167.6 64.5 55.2 3.1 109.9 2.6 165 2.6 55.2 0 109.9.5 165-2.6 64-3.1 120.8-17.7 167.6-64.5 46.9-46.9 61.4-103.6 64.5-167.6 3.2-55.1 2.6-109.8 2.6-165zm-88 235.8c-7.3 18.2-16.1 31.8-30.2 45.8-14.1 14.1-27.6 22.9-45.8 30.2C695.2 844.7 570.3 840 512 840c-58.3 0-183.3 4.7-235.9-16.1-18.2-7.3-31.8-16.1-45.8-30.2-14.1-14.1-22.9-27.6-30.2-45.8C179.3 695.2 184 570.3 184 512c0-58.3-4.7-183.3 16.1-235.9 7.3-18.2 16.1-31.8 30.2-45.8s27.6-22.9 45.8-30.2C328.7 179.3 453.7 184 512 184s183.3-4.7 235.9 16.1c18.2 7.3 31.8 16.1 45.8 30.2 14.1 14.1 22.9 27.6 30.2 45.8C844.7 328.7 840 453.7 840 512c0 58.3 4.7 183.2-16.2 235.8z"})}));export const AiOutlineYoutube=t=>c("svg",Object.assign({width:"16",height:"16",className:"icon",viewBox:"0 0 1024 1024",fill:"currentColor"},t,{children:c("path",{d:"M960 509.2c0-2.2 0-4.7-.1-7.6-.1-8.1-.3-17.2-.5-26.9-.8-27.9-2.2-55.7-4.4-81.9-3-36.1-7.4-66.2-13.4-88.8a139.52 139.52 0 0 0-98.3-98.5c-28.3-7.6-83.7-12.3-161.7-15.2-37.1-1.4-76.8-2.3-116.5-2.8-13.9-.2-26.8-.3-38.4-.4h-29.4c-11.6.1-24.5.2-38.4.4-39.7.5-79.4 1.4-116.5 2.8-78 3-133.5 7.7-161.7 15.2A139.35 139.35 0 0 0 82.4 304C76.3 326.6 72 356.7 69 392.8c-2.2 26.2-3.6 54-4.4 81.9-.3 9.7-.4 18.8-.5 26.9 0 2.9-.1 5.4-.1 7.6v5.6c0 2.2 0 4.7.1 7.6.1 8.1.3 17.2.5 26.9.8 27.9 2.2 55.7 4.4 81.9 3 36.1 7.4 66.2 13.4 88.8 12.8 47.9 50.4 85.7 98.3 98.5 28.2 7.6 83.7 12.3 161.7 15.2 37.1 1.4 76.8 2.3 116.5 2.8 13.9.2 26.8.3 38.4.4h29.4c11.6-.1 24.5-.2 38.4-.4 39.7-.5 79.4-1.4 116.5-2.8 78-3 133.5-7.7 161.7-15.2 47.9-12.8 85.5-50.5 98.3-98.5 6.1-22.6 10.4-52.7 13.4-88.8 2.2-26.2 3.6-54 4.4-81.9.3-9.7.4-18.8.5-26.9 0-2.9.1-5.4.1-7.6v-5.6zm-72 5.2c0 2.1 0 4.4-.1 7.1-.1 7.8-.3 16.4-.5 25.7-.7 26.6-2.1 53.2-4.2 77.9-2.7 32.2-6.5 58.6-11.2 76.3-6.2 23.1-24.4 41.4-47.4 47.5-21 5.6-73.9 10.1-145.8 12.8-36.4 1.4-75.6 2.3-114.7 2.8-13.7.2-26.4.3-37.8.3h-28.6l-37.8-.3c-39.1-.5-78.2-1.4-114.7-2.8-71.9-2.8-124.9-7.2-145.8-12.8-23-6.2-41.2-24.4-47.4-47.5-4.7-17.7-8.5-44.1-11.2-76.3-2.1-24.7-3.4-51.3-4.2-77.9-.3-9.3-.4-18-.5-25.7 0-2.7-.1-5.1-.1-7.1v-4.8c0-2.1 0-4.4.1-7.1.1-7.8.3-16.4.5-25.7.7-26.6 2.1-53.2 4.2-77.9 2.7-32.2 6.5-58.6 11.2-76.3 6.2-23.1 24.4-41.4 47.4-47.5 21-5.6 73.9-10.1 145.8-12.8 36.4-1.4 75.6-2.3 114.7-2.8 13.7-.2 26.4-.3 37.8-.3h28.6l37.8.3c39.1.5 78.2 1.4 114.7 2.8 71.9 2.8 124.9 7.2 145.8 12.8 23 6.2 41.2 24.4 47.4 47.5 4.7 17.7 8.5 44.1 11.2 76.3 2.1 24.7 3.4 51.3 4.2 77.9.3 9.3.4 18 .5 25.7 0 2.7.1 5.1.1 7.1v4.8zM423 646l232-135-232-133z"})}));export const AiOutlineVideoCamera=t=>c("svg",Object.assign({width:"16",height:"16",className:"icon",viewBox:"0 0 1024 1024",fill:"currentColor"},t,{children:c("path",{d:"M912 302.3L784 376V224c0-35.3-28.7-64-64-64H128c-35.3 0-64 28.7-64 64v576c0 35.3 28.7 64 64 64h592c35.3 0 64-28.7 64-64V648l128 73.7c21.3 12.3 48-3.1 48-27.6V330c0-24.6-26.7-40-48-27.7zM712 792H136V232h576v560zm176-167l-104-59.8V458.9L888 399v226zM208 360h112c4.4 0 8-3.6 8-8v-48c0-4.4-3.6-8-8-8H208c-4.4 0-8 3.6-8 8v48c0 4.4 3.6 8 8 8z"})}));export const AiOutlineIdcard=t=>c("svg",Object.assign({width:"16",height:"16",className:"icon",viewBox:"0 0 1024 1024",fill:"currentColor"},t,{children:c("path",{d:"M928 160H96c-17.7 0-32 14.3-32 32v640c0 17.7 14.3 32 32 32h832c17.7 0 32-14.3 32-32V192c0-17.7-14.3-32-32-32zm-40 632H136V232h752v560zM610.3 476h123.4c1.3 0 2.3-3.6 2.3-8v-48c0-4.4-1-8-2.3-8H610.3c-1.3 0-2.3 3.6-2.3 8v48c0 4.4 1 8 2.3 8zm4.8 144h185.7c3.9 0 7.1-3.6 7.1-8v-48c0-4.4-3.2-8-7.1-8H615.1c-3.9 0-7.1 3.6-7.1 8v48c0 4.4 3.2 8 7.1 8zM224 673h43.9c4.2 0 7.6-3.3 7.9-7.5 3.8-50.5 46-90.5 97.2-90.5s93.4 40 97.2 90.5c.3 4.2 3.7 7.5 7.9 7.5H522a8 8 0 0 0 8-8.4c-2.8-53.3-32-99.7-74.6-126.1a111.8 111.8 0 0 0 29.1-75.5c0-61.9-49.9-112-111.4-112s-111.4 50.1-111.4 112c0 29.1 11 55.5 29.1 75.5a158.09 158.09 0 0 0-74.6 126.1c-.4 4.6 3.2 8.4 7.8 8.4zm149-262c28.5 0 51.7 23.3 51.7 52s-23.2 52-51.7 52-51.7-23.3-51.7-52 23.2-52 51.7-52z"})}));export const AiOutlineLinkedin=t=>c("svg",Object.assign({width:"16",height:"16",className:"icon",viewBox:"0 0 1024 1024",fill:"currentColor"},t,{children:c("path",{d:"M847.7 112H176.3c-35.5 0-64.3 28.8-64.3 64.3v671.4c0 35.5 28.8 64.3 64.3 64.3h671.4c35.5 0 64.3-28.8 64.3-64.3V176.3c0-35.5-28.8-64.3-64.3-64.3zm0 736c-447.8-.1-671.7-.2-671.7-.3.1-447.8.2-671.7.3-671.7 447.8.1 671.7.2 671.7.3-.1 447.8-.2 671.7-.3 671.7zM230.6 411.9h118.7v381.8H230.6zm59.4-52.2c37.9 0 68.8-30.8 68.8-68.8a68.8 68.8 0 1 0-137.6 0c-.1 38 30.7 68.8 68.8 68.8zm252.3 245.1c0-49.8 9.5-98 71.2-98 60.8 0 61.7 56.9 61.7 101.2v185.7h118.6V584.3c0-102.8-22.2-181.9-142.3-181.9-57.7 0-96.4 31.7-112.3 61.7h-1.6v-52.2H423.7v381.8h118.6V604.8z"})}));export const AiOutlineTwitter=t=>c("svg",Object.assign({width:"16",height:"16",className:"icon",viewBox:"0 0 1024 1024",fill:"currentColor"},t,{children:c("path",{d:"M928 254.3c-30.6 13.2-63.9 22.7-98.2 26.4a170.1 170.1 0 0 0 75-94 336.64 336.64 0 0 1-108.2 41.2A170.1 170.1 0 0 0 672 174c-94.5 0-170.5 76.6-170.5 170.6 0 13.2 1.6 26.4 4.2 39.1-141.5-7.4-267.7-75-351.6-178.5a169.32 169.32 0 0 0-23.2 86.1c0 59.2 30.1 111.4 76 142.1a172 172 0 0 1-77.1-21.7v2.1c0 82.9 58.6 151.6 136.7 167.4a180.6 180.6 0 0 1-44.9 5.8c-11.1 0-21.6-1.1-32.2-2.6C211 652 273.9 701.1 348.8 702.7c-58.6 45.9-132 72.9-211.7 72.9-14.3 0-27.5-.5-41.2-2.1C171.5 822 261.2 850 357.8 850 671.4 850 843 590.2 843 364.7c0-7.4 0-14.8-.5-22.2 33.2-24.3 62.3-54.4 85.5-88.2z"})}));export const IoMdColorPalette=t=>c("svg",Object.assign({width:"16",height:"16",viewBox:"0 0 512 512",fill:"currentColor"},t,{children:c("path",{d:"M430.1 347.9c-6.6-6.1-16.3-7.6-24.6-9-11.5-1.9-15.9-4-22.6-10-14.3-12.7-14.3-31.1 0-43.8l30.3-26.9c46.4-41 46.4-108.2 0-149.2-34.2-30.1-80.1-45-127.8-45-55.7 0-113.9 20.3-158.8 60.1-83.5 73.8-83.5 194.7 0 268.5 41.5 36.7 97.5 55 152.9 55.4h1.7c55.4 0 110-17.9 148.8-52.4 14.4-12.7 12-36.6.1-47.7zM120 216c0-17.7 14.3-32 32-32s32 14.3 32 32-14.3 32-32 32-32-14.3-32-32zm40 126c-17.7 0-32-14.3-32-32s14.3-32 32-32 32 14.3 32 32-14.3 32-32 32zm64-161c-17.7 0-32-14.3-32-32s14.3-32 32-32 32 14.3 32 32-14.3 32-32 32zm72 219c-26.5 0-48-21.5-48-48s21.5-48 48-48 48 21.5 48 48-21.5 48-48 48zm24-208c-17.7 0-32-14.3-32-32s14.3-32 32-32 32 14.3 32 32-14.3 32-32 32z"})}));
1
+ import{jsx as c,jsxs as t}from"react/jsx-runtime";export const MdOpacity=t=>c("svg",Object.assign({width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor"},t,{children:c("path",{d:"M17.66 8L12 2.35 6.34 8C4.78 9.56 4 11.64 4 13.64s.78 4.11 2.34 5.67 3.61 2.35 5.66 2.35 4.1-.79 5.66-2.35S20 15.64 20 13.64 19.22 9.56 17.66 8zM6 14c.01-2 .62-3.27 1.76-4.4L12 5.27l4.24 4.38C17.38 10.77 17.99 12 18 14H6z"})}));export const MdFormatTextdirectionRToL=t=>c("svg",Object.assign({width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor"},t,{children:c("path",{d:"M10 10v5h2V4h2v11h2V4h2V2h-8C7.79 2 6 3.79 6 6s1.79 4 4 4zm-2 7v-3l-4 4 4 4v-3h12v-2H8z"})}));export const MdFormatTextdirectionLToR=t=>c("svg",Object.assign({width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor"},t,{children:c("path",{d:"M9 10v5h2V4h2v11h2V4h2V2H9C6.79 2 5 3.79 5 6s1.79 4 4 4zm12 8l-4-4v3H5v2h12v3l4-4z"})}));export const MdcFormatVerticalAlignTop=t=>c("svg",Object.assign({width:"16",height:"16",version:"1.1",id:"mdi-format-vertical-align-top",viewBox:"0 0 24 24",fill:"currentColor"},t,{children:c("path",{d:"M8,11H11V21H13V11H16L12,7L8,11M4,3V5H20V3H4Z"})}));export const MdcFormatVerticalAlignCenter=t=>c("svg",Object.assign({width:"16",height:"16",version:"1.1",id:"mdi-format-vertical-align-center",viewBox:"0 0 24 24",fill:"currentColor"},t,{children:c("path",{d:"M8,19H11V23H13V19H16L12,15L8,19M16,5H13V1H11V5H8L12,9L16,5M4,11V13H20V11H4Z"})}));export const MdcFormatVerticalAlignBottom=t=>c("svg",Object.assign({width:"16",height:"16",version:"1.1",id:"mdi-format-vertical-align-bottom",viewBox:"0 0 24 24",fill:"currentColor"},t,{children:c("path",{d:"M16,13H13V3H11V13H8L12,17L16,13M4,19V21H20V19H4Z"})}));export const MdcFormatListBulleted=t=>c("svg",Object.assign({width:"16",height:"16",version:"1.1",id:"mdi-format-list-bulleted",viewBox:"0 0 24 24",fill:"currentColor"},t,{children:c("path",{d:"M7,5H21V7H7V5M7,13V11H21V13H7M4,4.5A1.5,1.5 0 0,1 5.5,6A1.5,1.5 0 0,1 4,7.5A1.5,1.5 0 0,1 2.5,6A1.5,1.5 0 0,1 4,4.5M4,10.5A1.5,1.5 0 0,1 5.5,12A1.5,1.5 0 0,1 4,13.5A1.5,1.5 0 0,1 2.5,12A1.5,1.5 0 0,1 4,10.5M7,19V17H21V19H7M4,16.5A1.5,1.5 0 0,1 5.5,18A1.5,1.5 0 0,1 4,19.5A1.5,1.5 0 0,1 2.5,18A1.5,1.5 0 0,1 4,16.5Z"})}));export const MdcFormatListNumbered=t=>c("svg",Object.assign({width:"16",height:"16",version:"1.1",id:"mdi-format-list-numbered",viewBox:"0 0 24 24",fill:"currentColor"},t,{children:c("path",{d:"M7,13V11H21V13H7M7,19V17H21V19H7M7,7V5H21V7H7M3,8V5H2V4H4V8H3M2,17V16H5V20H2V19H4V18.5H3V17.5H4V17H2M4.25,10A0.75,0.75 0 0,1 5,10.75C5,10.95 4.92,11.14 4.79,11.27L3.12,13H5V14H2V13.08L4,11H2V10H4.25Z"})}));export const MdcFormatLineSpacing=t=>c("svg",Object.assign({width:"16",height:"16",version:"1.1",id:"mdi-format-line-spacing",viewBox:"0 0 24 24",fill:"currentColor"},t,{children:c("path",{d:"M10,13H22V11H10M10,19H22V17H10M10,7H22V5H10M6,7H8.5L5,3.5L1.5,7H4V17H1.5L5,20.5L8.5,17H6V7Z"})}));export const MdcFormatLetterCase=t=>c("svg",Object.assign({width:"16",height:"16",version:"1.1",id:"mdi-format-letter-case",viewBox:"0 0 24 24",fill:"currentColor"},t,{children:c("path",{d:"M20.06,18C20,17.83 19.91,17.54 19.86,17.11C19.19,17.81 18.38,18.16 17.45,18.16C16.62,18.16 15.93,17.92 15.4,17.45C14.87,17 14.6,16.39 14.6,15.66C14.6,14.78 14.93,14.1 15.6,13.61C16.27,13.12 17.21,12.88 18.43,12.88H19.83V12.24C19.83,11.75 19.68,11.36 19.38,11.07C19.08,10.78 18.63,10.64 18.05,10.64C17.53,10.64 17.1,10.76 16.75,11C16.4,11.25 16.23,11.54 16.23,11.89H14.77C14.77,11.46 14.92,11.05 15.22,10.65C15.5,10.25 15.93,9.94 16.44,9.71C16.95,9.5 17.5,9.36 18.13,9.36C19.11,9.36 19.87,9.6 20.42,10.09C20.97,10.58 21.26,11.25 21.28,12.11V16C21.28,16.8 21.38,17.42 21.58,17.88V18H20.06M17.66,16.88C18.11,16.88 18.54,16.77 18.95,16.56C19.35,16.35 19.65,16.07 19.83,15.73V14.16H18.7C16.93,14.16 16.04,14.63 16.04,15.57C16.04,16 16.19,16.3 16.5,16.53C16.8,16.76 17.18,16.88 17.66,16.88M5.46,13.71H9.53L7.5,8.29L5.46,13.71M6.64,6H8.36L13.07,18H11.14L10.17,15.43H4.82L3.86,18H1.93L6.64,6Z"})}));export const FaShapes=t=>c("svg",Object.assign({width:"16",height:"16",viewBox:"0 0 512 512",fill:"currentColor"},t,{children:c("path",{d:"M128,256A128,128,0,1,0,256,384,128,128,0,0,0,128,256Zm379-54.86L400.07,18.29a37.26,37.26,0,0,0-64.14,0L229,201.14C214.76,225.52,232.58,256,261.09,256H474.91C503.42,256,521.24,225.52,507,201.14ZM480,288H320a32,32,0,0,0-32,32V480a32,32,0,0,0,32,32H480a32,32,0,0,0,32-32V320A32,32,0,0,0,480,288Z"})}));export const FaBrain=t=>c("svg",Object.assign({width:"16",height:"16",viewBox:"0 0 576 512",fill:"currentColor"},t,{children:c("path",{d:"M208 0c-29.9 0-54.7 20.5-61.8 48.2-.8 0-1.4-.2-2.2-.2-35.3 0-64 28.7-64 64 0 4.8.6 9.5 1.7 14C52.5 138 32 166.6 32 200c0 12.6 3.2 24.3 8.3 34.9C16.3 248.7 0 274.3 0 304c0 33.3 20.4 61.9 49.4 73.9-.9 4.6-1.4 9.3-1.4 14.1 0 39.8 32.2 72 72 72 4.1 0 8.1-.5 12-1.2 9.6 28.5 36.2 49.2 68 49.2 39.8 0 72-32.2 72-72V64c0-35.3-28.7-64-64-64zm368 304c0-29.7-16.3-55.3-40.3-69.1 5.2-10.6 8.3-22.3 8.3-34.9 0-33.4-20.5-62-49.7-74 1-4.5 1.7-9.2 1.7-14 0-35.3-28.7-64-64-64-.8 0-1.5.2-2.2.2C422.7 20.5 397.9 0 368 0c-35.3 0-64 28.6-64 64v376c0 39.8 32.2 72 72 72 31.8 0 58.4-20.7 68-49.2 3.9.7 7.9 1.2 12 1.2 39.8 0 72-32.2 72-72 0-4.8-.5-9.5-1.4-14.1 29-12 49.4-40.6 49.4-73.9z"})}));export const FdPageMultiple=i=>c("svg",Object.assign({width:"16",height:"16",version:"1.1",id:"Layer_1",x:"0px",y:"0px",viewBox:"0 0 100 100",enableBackground:"new 0 0 100 100",fill:"currentColor"},i,{children:t("g",{children:[c("path",{d:"M86.45,23.27h-3.475V90.18c0,0.835-0.677,1.513-1.513,1.513H31.987v3.475c0,0.836,0.677,1.513,1.513,1.513l0.001,0v0h52.95c0.836,0,1.513-0.677,1.513-1.513V24.782C87.963,23.946,87.286,23.27,86.45,23.27z"}),c("path",{d:"M77.988,85.193V14.807c0-0.836-0.677-1.513-1.513-1.513h-3.475v66.911c0,0.836-0.677,1.513-1.513,1.513H22.011v3.475c0,0.836,0.677,1.513,1.513,1.513c0,0,0,0,0,0h52.951C77.311,86.706,77.988,86.029,77.988,85.193z"}),c("path",{d:"M68.013,75.218V4.832c0-0.836-0.677-1.513-1.513-1.513H13.55c-0.836,0-1.513,0.677-1.513,1.513v70.386c0,0.836,0.677,1.513,1.513,1.513H66.5C67.336,76.731,68.013,76.054,68.013,75.218z"})]})}));export const ZoStrokeWidth=t=>c("svg",Object.assign({width:"16",height:"16",viewBox:"0 0 20 20",fill:"currentColor"},t,{children:c("path",{d:"M0 0h20v5H0V0zm0 7h20v4H0V7zm0 6h20v3H0v-3zm0 5h20v2H0v-2z"})}));export const ZoDocument=t=>c("svg",Object.assign({width:"16",height:"16",viewBox:"0 0 20 20",fill:"currentColor"},t,{children:c("path",{d:"M4 18h12V6h-4V2H4v16zm-2 1V0h12l4 4v16H2v-1z"})}));export const CgColorPicker=i=>t("svg",Object.assign({width:"16",height:"16",viewBox:"0 0 24 24",fill:"none"},i,{children:[c("path",{d:"M20.3847 2.87868C19.2132 1.70711 17.3137 1.70711 16.1421 2.87868L14.0202 5.00052L13.313 4.29332C12.9225 3.9028 12.2894 3.9028 11.8988 4.29332C11.5083 4.68385 11.5083 5.31701 11.8988 5.70754L17.5557 11.3644C17.9462 11.7549 18.5794 11.7549 18.9699 11.3644C19.3604 10.9739 19.3604 10.3407 18.9699 9.95018L18.2629 9.24316L20.3847 7.12132C21.5563 5.94975 21.5563 4.05025 20.3847 2.87868Z",fill:"currentColor"}),c("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M11.9297 7.09116L4.1515 14.8693C3.22786 15.793 3.03239 17.169 3.5651 18.2842L1.99994 19.8493L3.41415 21.2635L4.97931 19.6984C6.09444 20.2311 7.4705 20.0356 8.39414 19.112L16.1723 11.3338L11.9297 7.09116ZM13.3439 11.3338L11.9297 9.91959L5.56571 16.2835C5.17518 16.6741 5.17518 17.3072 5.56571 17.6978C5.95623 18.0883 6.5894 18.0883 6.97992 17.6978L13.3439 11.3338Z",fill:"currentColor"})]}));export const AiOutlineFacebook=t=>c("svg",Object.assign({width:"16",height:"16",className:"icon",viewBox:"0 0 1024 1024",fill:"currentColor"},t,{children:c("path",{d:"M880 112H144c-17.7 0-32 14.3-32 32v736c0 17.7 14.3 32 32 32h736c17.7 0 32-14.3 32-32V144c0-17.7-14.3-32-32-32zm-32 736H663.9V602.2h104l15.6-120.7H663.9v-77.1c0-35 9.7-58.8 59.8-58.8h63.9v-108c-11.1-1.5-49-4.8-93.2-4.8-92.2 0-155.3 56.3-155.3 159.6v89H434.9v120.7h104.3V848H176V176h672v672z"})}));export const AiOutlineInstagram=t=>c("svg",Object.assign({width:"16",height:"16",className:"icon",viewBox:"0 0 1024 1024",fill:"currentColor"},t,{children:c("path",{d:"M512 306.9c-113.5 0-205.1 91.6-205.1 205.1S398.5 717.1 512 717.1 717.1 625.5 717.1 512 625.5 306.9 512 306.9zm0 338.4c-73.4 0-133.3-59.9-133.3-133.3S438.6 378.7 512 378.7 645.3 438.6 645.3 512 585.4 645.3 512 645.3zm213.5-394.6c-26.5 0-47.9 21.4-47.9 47.9s21.4 47.9 47.9 47.9 47.9-21.3 47.9-47.9a47.84 47.84 0 0 0-47.9-47.9zM911.8 512c0-55.2.5-109.9-2.6-165-3.1-64-17.7-120.8-64.5-167.6-46.9-46.9-103.6-61.4-167.6-64.5-55.2-3.1-109.9-2.6-165-2.6-55.2 0-109.9-.5-165 2.6-64 3.1-120.8 17.7-167.6 64.5C132.6 226.3 118.1 283 115 347c-3.1 55.2-2.6 109.9-2.6 165s-.5 109.9 2.6 165c3.1 64 17.7 120.8 64.5 167.6 46.9 46.9 103.6 61.4 167.6 64.5 55.2 3.1 109.9 2.6 165 2.6 55.2 0 109.9.5 165-2.6 64-3.1 120.8-17.7 167.6-64.5 46.9-46.9 61.4-103.6 64.5-167.6 3.2-55.1 2.6-109.8 2.6-165zm-88 235.8c-7.3 18.2-16.1 31.8-30.2 45.8-14.1 14.1-27.6 22.9-45.8 30.2C695.2 844.7 570.3 840 512 840c-58.3 0-183.3 4.7-235.9-16.1-18.2-7.3-31.8-16.1-45.8-30.2-14.1-14.1-22.9-27.6-30.2-45.8C179.3 695.2 184 570.3 184 512c0-58.3-4.7-183.3 16.1-235.9 7.3-18.2 16.1-31.8 30.2-45.8s27.6-22.9 45.8-30.2C328.7 179.3 453.7 184 512 184s183.3-4.7 235.9 16.1c18.2 7.3 31.8 16.1 45.8 30.2 14.1 14.1 22.9 27.6 30.2 45.8C844.7 328.7 840 453.7 840 512c0 58.3 4.7 183.2-16.2 235.8z"})}));export const AiOutlineYoutube=t=>c("svg",Object.assign({width:"16",height:"16",className:"icon",viewBox:"0 0 1024 1024",fill:"currentColor"},t,{children:c("path",{d:"M960 509.2c0-2.2 0-4.7-.1-7.6-.1-8.1-.3-17.2-.5-26.9-.8-27.9-2.2-55.7-4.4-81.9-3-36.1-7.4-66.2-13.4-88.8a139.52 139.52 0 0 0-98.3-98.5c-28.3-7.6-83.7-12.3-161.7-15.2-37.1-1.4-76.8-2.3-116.5-2.8-13.9-.2-26.8-.3-38.4-.4h-29.4c-11.6.1-23.5.2-38.4.4-39.7.5-79.4 1.4-116.5 2.8-78 3-133.5 7.7-161.7 15.2A139.35 139.35 0 0 0 82.4 304C76.3 326.6 72 356.7 69 392.8c-2.2 26.2-3.6 54-4.4 81.9-.3 9.7-.4 18.8-.5 26.9 0 2.9-.1 5.4-.1 7.6v5.6c0 2.2 0 4.7.1 7.6.1 8.1.3 17.2.5 26.9.8 27.9 2.2 55.7 4.4 81.9 3 36.1 7.4 66.2 13.4 88.8 12.8 47.9 50.4 85.7 98.3 98.5 28.2 7.6 83.7 12.3 161.7 15.2 37.1 1.4 76.8 2.3 116.5 2.8 13.9.2 26.8.3 38.4.4h29.4c11.6-.1 24.5-.2 38.4-.4 39.7-.5 79.4-1.4 116.5-2.8 78-3 133.5-7.7 161.7-15.2 47.9-12.8 85.5-50.5 98.3-98.5 6.1-22.6 10.4-52.7 13.4-88.8 2.2-26.2 3.6-54 4.4-81.9.3-9.7.4-18.8.5-26.9 0-2.9.1-5.4.1-7.6v-5.6zm-72 5.2c0 2.1 0 4.4-.1 7.1-.1 7.8-.3 16.4-.5 25.7-.7 26.6-2.1 53.2-4.2 77.9-2.7 32.2-6.5 58.6-11.2 76.3-6.2 23.1-24.4 41.4-47.4 47.5-21 5.6-73.9 10.1-145.8 12.8-36.4 1.4-75.6 2.3-114.7 2.8-13.7.2-26.4.3-37.8.3h-28.6l-37.8-.3c-39.1-.5-78.2-1.4-114.7-2.8-71.9-2.8-124.9-7.2-145.8-12.8-23-6.2-41.2-24.4-47.4-47.5-4.7-17.7-8.5-44.1-11.2-76.3-2.1-24.7-3.4-51.3-4.2-77.9-.3-9.3-.4-18-.5-25.7 0-2.7-.1-5.1-.1-7.1v-4.8c0-2.1 0-4.4.1-7.1.1-7.8.3-16.4.5-25.7.7-26.6 2.1-53.2 4.2-77.9 2.7-32.2 6.5-58.6 11.2-76.3 6.2-23.1 24.4-41.4 47.4-47.5 21-5.6 73.9-10.1 145.8-12.8 36.4-1.4 75.6-2.3 114.7-2.8 13.7-.2 26.4-.3 37.8-.3h28.6l37.8.3c39.1.5 78.2 1.4 114.7 2.8 71.9 2.8 124.9 7.2 145.8 12.8 23 6.2 41.2 24.4 47.4 47.5 4.7 17.7 8.5 44.1 11.2 76.3 2.1 24.7 3.4 51.3 4.2 77.9.3 9.3.4 18 .5 25.7 0 2.7.1 5.1.1 7.1v4.8zM423 646l232-135-232-133z"})}));export const AiOutlineVideoCamera=t=>c("svg",Object.assign({width:"16",height:"16",className:"icon",viewBox:"0 0 1024 1024",fill:"currentColor"},t,{children:c("path",{d:"M912 302.3L784 376V224c0-35.3-28.7-64-64-64H128c-35.3 0-64 28.7-64 64v576c0 35.3 28.7 64 64 64h592c35.3 0 64-28.7 64-64V648l128 73.7c21.3 12.3 48-3.1 48-27.6V330c0-24.6-26.7-40-48-27.7zM712 792H136V232h576v560zm176-167l-104-59.8V458.9L888 399v226zM208 360h112c4.4 0 8-3.6 8-8v-48c0-4.4-3.6-8-8-8H208c-4.4 0-8 3.6-8 8v48c0 4.4 3.6 8 8 8z"})}));export const AiOutlineIdcard=t=>c("svg",Object.assign({width:"16",height:"16",className:"icon",viewBox:"0 0 1024 1024",fill:"currentColor"},t,{children:c("path",{d:"M928 160H96c-17.7 0-32 14.3-32 32v640c0 17.7 14.3 32 32 32h832c17.7 0 32-14.3 32-32V192c0-17.7-14.3-32-32-32zm-40 632H136V232h752v560zM610.3 476h123.4c1.3 0 2.3-3.6 2.3-8v-48c0-4.4-1-8-2.3-8H610.3c-1.3 0-2.3 3.6-2.3 8v48c0 4.4 1 8 2.3 8zm4.8 144h185.7c3.9 0 7.1-3.6 7.1-8v-48c0-4.4-3.2-8-7.1-8H615.1c-3.9 0-7.1 3.6-7.1 8v48c0 4.4 3.2 8 7.1 8zM224 673h43.9c4.2 0 7.6-3.3 7.9-7.5 3.8-50.5 46-90.5 97.2-90.5s93.4 40 97.2 90.5c.3 4.2 3.7 7.5 7.9 7.5H522a8 8 0 0 0 8-8.4c-2.8-53.3-32-99.7-74.6-126.1a111.8 111.8 0 0 0 29.1-75.5c0-61.9-49.9-112-111.4-112s-111.4 50.1-111.4 112c0 29.1 11 55.5 29.1 75.5a158.09 158.09 0 0 0-74.6 126.1c-.4 4.6 3.2 8.4 7.8 8.4zm149-262c28.5 0 51.7 23.3 51.7 52s-23.2 52-51.7 52-51.7-23.3-51.7-52 23.2-52 51.7-52z"})}));export const AiOutlineLinkedin=t=>c("svg",Object.assign({width:"16",height:"16",className:"icon",viewBox:"0 0 1024 1024",fill:"currentColor"},t,{children:c("path",{d:"M847.7 112H176.3c-35.5 0-64.3 28.8-64.3 64.3v671.4c0 35.5 28.8 64.3 64.3 64.3h671.4c35.5 0 64.3-28.8 64.3-64.3V176.3c0-35.5-28.8-64.3-64.3-64.3zm0 736c-447.8-.1-671.7-.2-671.7-.3.1-447.8.2-671.7.3-671.7 447.8.1 671.7.2 671.7.3-.1 447.8-.2 671.7-.3 671.7zM230.6 411.9h118.7v381.8H230.6zm59.4-52.2c37.9 0 68.8-30.8 68.8-68.8a68.8 68.8 0 1 0-137.6 0c-.1 38 30.7 68.8 68.8 68.8zm252.3 245.1c0-49.8 9.5-98 71.2-98 60.8 0 61.7 56.9 61.7 101.2v185.7h118.6V584.3c0-102.8-22.2-181.9-142.3-181.9-57.7 0-96.4 31.7-112.3 61.7h-1.6v-52.2H423.7v381.8h118.6V604.8z"})}));export const AiOutlineTwitter=t=>c("svg",Object.assign({width:"16",height:"16",className:"icon",viewBox:"0 0 1024 1024",fill:"currentColor"},t,{children:c("path",{d:"M928 254.3c-30.6 13.2-63.9 22.7-98.2 26.4a170.1 170.1 0 0 0 75-94 336.64 336.64 0 0 1-108.2 41.2A170.1 170.1 0 0 0 672 174c-94.5 0-170.5 76.6-170.5 170.6 0 13.2 1.6 26.4 4.2 39.1-141.5-7.4-267.7-75-351.6-178.5a169.32 169.32 0 0 0-23.2 86.1c0 59.2 30.1 111.4 76 142.1a172 172 0 0 1-77.1-21.7v2.1c0 82.9 58.6 151.6 136.7 167.4a180.6 180.6 0 0 1-44.9 5.8c-11.1 0-21.6-1.1-32.2-2.6C211 652 273.9 701.1 348.8 702.7c-58.6 45.9-132 72.9-211.7 72.9-14.3 0-27.5-.5-41.2-2.1C171.5 822 261.2 850 357.8 850 671.4 850 843 590.2 843 364.7c0-7.4 0-14.8-.5-22.2 33.2-24.3 62.3-54.4 85.5-88.2z"})}));export const IoMdColorPalette=t=>c("svg",Object.assign({width:"16",height:"16",viewBox:"0 0 512 512",fill:"currentColor"},t,{children:c("path",{d:"M430.1 347.9c-6.6-6.1-16.3-7.6-24.6-9-11.5-1.9-15.9-4-22.6-10-14.3-12.7-14.3-31.1 0-43.8l30.3-26.9c46.4-41 46.4-108.2 0-149.2-34.2-30.1-80.1-45-127.8-45-55.7 0-113.9 20.3-158.8 60.1-83.5 73.8-83.5 194.7 0 268.5 41.5 36.7 97.5 55 152.9 55.4h1.7c55.4 0 110-17.9 148.8-52.4 14.4-12.7 12-36.6.1-47.7zM120 216c0-17.7 14.3-32 32-32s32 14.3 32 32-14.3 32-32 32-32-14.3-32-32zm40 126c-17.7 0-32-14.3-32-32s14.3-32 32-32 32 14.3 32 32-14.3 32-32 32zm64-161c-17.7 0-32-14.3-32-32s14.3-32 32-32 32 14.3 32 32-14.3 32-32 32zm72 219c-26.5 0-48-21.5-48-48s21.5-48 48-48 48 21.5 48 48-21.5 48-48 48zm24-208c-17.7 0-32-14.3-32-32s14.3-32 32-32 32 14.3 32 32-14.3 32-32 32z"})}));
@@ -397,7 +397,6 @@ export declare const TYPES_MAP: {
397
397
  setFilter(type: any, value: any): void;
398
398
  } & {
399
399
  set(attrs: any): void;
400
- afterCreate(): void;
401
400
  toggleEditMode(editing?: boolean): void;
402
401
  beforeDestroy(): void;
403
402
  }, any, import("mobx-state-tree").ModelSnapshotType<{
@@ -340,7 +340,6 @@ export declare const Page: import("mobx-state-tree").IModelType<{
340
340
  setFilter(type: any, value: any): void;
341
341
  } & {
342
342
  set(attrs: any): void;
343
- afterCreate(): void;
344
343
  toggleEditMode(editing?: boolean): void;
345
344
  beforeDestroy(): void;
346
345
  }, any, import("mobx-state-tree").ModelSnapshotType<{
package/model/store.d.ts CHANGED
@@ -389,7 +389,6 @@ export declare const Store: import("mobx-state-tree").IModelType<{
389
389
  setFilter(type: any, value: any): void;
390
390
  } & {
391
391
  set(attrs: any): void;
392
- afterCreate(): void;
393
392
  toggleEditMode(editing?: boolean): void;
394
393
  beforeDestroy(): void;
395
394
  }, any, import("mobx-state-tree").ModelSnapshotType<{
@@ -2443,7 +2442,6 @@ export declare const Store: import("mobx-state-tree").IModelType<{
2443
2442
  setFilter(type: any, value: any): void;
2444
2443
  } & {
2445
2444
  set(attrs: any): void;
2446
- afterCreate(): void;
2447
2445
  toggleEditMode(editing?: boolean): void;
2448
2446
  beforeDestroy(): void;
2449
2447
  }, any, import("mobx-state-tree").ModelSnapshotType<{
@@ -4408,7 +4406,6 @@ export declare const Store: import("mobx-state-tree").IModelType<{
4408
4406
  setFilter(type: any, value: any): void;
4409
4407
  } & {
4410
4408
  set(attrs: any): void;
4411
- afterCreate(): void;
4412
4409
  toggleEditMode(editing?: boolean): void;
4413
4410
  beforeDestroy(): void;
4414
4411
  }, any, import("mobx-state-tree").ModelSnapshotType<{
@@ -6671,7 +6668,6 @@ export declare const Store: import("mobx-state-tree").IModelType<{
6671
6668
  setFilter(type: any, value: any): void;
6672
6669
  } & {
6673
6670
  set(attrs: any): void;
6674
- afterCreate(): void;
6675
6671
  toggleEditMode(editing?: boolean): void;
6676
6672
  beforeDestroy(): void;
6677
6673
  }, any, import("mobx-state-tree").ModelSnapshotType<{
@@ -8636,7 +8632,6 @@ export declare const Store: import("mobx-state-tree").IModelType<{
8636
8632
  setFilter(type: any, value: any): void;
8637
8633
  } & {
8638
8634
  set(attrs: any): void;
8639
- afterCreate(): void;
8640
8635
  toggleEditMode(editing?: boolean): void;
8641
8636
  beforeDestroy(): void;
8642
8637
  }, any, import("mobx-state-tree").ModelSnapshotType<{
@@ -10602,7 +10597,6 @@ export declare const Store: import("mobx-state-tree").IModelType<{
10602
10597
  setFilter(type: any, value: any): void;
10603
10598
  } & {
10604
10599
  set(attrs: any): void;
10605
- afterCreate(): void;
10606
10600
  toggleEditMode(editing?: boolean): void;
10607
10601
  beforeDestroy(): void;
10608
10602
  }, any, import("mobx-state-tree").ModelSnapshotType<{
@@ -12567,7 +12561,6 @@ export declare const Store: import("mobx-state-tree").IModelType<{
12567
12561
  setFilter(type: any, value: any): void;
12568
12562
  } & {
12569
12563
  set(attrs: any): void;
12570
- afterCreate(): void;
12571
12564
  toggleEditMode(editing?: boolean): void;
12572
12565
  beforeDestroy(): void;
12573
12566
  }, any, import("mobx-state-tree").ModelSnapshotType<{
@@ -14570,7 +14563,6 @@ export declare const Store: import("mobx-state-tree").IModelType<{
14570
14563
  setFilter(type: any, value: any): void;
14571
14564
  } & {
14572
14565
  set(attrs: any): void;
14573
- afterCreate(): void;
14574
14566
  toggleEditMode(editing?: boolean): void;
14575
14567
  beforeDestroy(): void;
14576
14568
  }, any, import("mobx-state-tree").ModelSnapshotType<{
@@ -16535,7 +16527,6 @@ export declare const Store: import("mobx-state-tree").IModelType<{
16535
16527
  setFilter(type: any, value: any): void;
16536
16528
  } & {
16537
16529
  set(attrs: any): void;
16538
- afterCreate(): void;
16539
16530
  toggleEditMode(editing?: boolean): void;
16540
16531
  beforeDestroy(): void;
16541
16532
  }, any, import("mobx-state-tree").ModelSnapshotType<{
@@ -167,7 +167,6 @@ export declare const TextElement: import("mobx-state-tree").IModelType<{
167
167
  setFilter(type: any, value: any): void;
168
168
  } & {
169
169
  set(attrs: any): void;
170
- afterCreate(): void;
171
170
  toggleEditMode(editing?: boolean): void;
172
171
  beforeDestroy(): void;
173
172
  }, any, import("mobx-state-tree").ModelSnapshotType<{
@@ -1 +1 @@
1
- import{types as e}from"mobx-state-tree";import{Shape as t}from"./shape-model.js";const n=e=>{if("string"!=typeof e){return e}const t=e.trim().match(/^(-?\d*\.?\d+)(%?)$/);if(!t){return e}const n=parseFloat(t[1]);return t[2]?n/100:n};export const TextElement=t.named("Text").props({type:"text",text:"",placeholder:"",fontSize:14,fontFamily:"Roboto",fontStyle:"normal",fontWeight:"normal",textDecoration:"",textTransform:"none",fill:"black",align:"center",width:100,height:0,verticalAlign:"top",strokeWidth:0,stroke:"black",strokeLineJoin:"round",lineHeight:e.optional(e.union(e.number,e.string),1.2),letterSpacing:0,_editModeEnabled:!1,backgroundEnabled:!1,backgroundColor:"#7ED321",backgroundOpacity:1,backgroundCornerRadius:.5,backgroundPadding:.5,legacyBackground:e.maybe(e.boolean),curveEnabled:!1,curvePower:.5}).preProcessSnapshot(e=>Object.assign(Object.assign({},e),{fontSize:null!=e.fontSize&&e.fontSize<1?1:e.fontSize,lineHeight:n(e.lineHeight)})).actions(e=>{const t=e.set;return{set(e){null!=e.fontSize&&e.fontSize<1&&(e=Object.assign(Object.assign({},e),{fontSize:1})),"string"==typeof e.lineHeight&&(e=Object.assign(Object.assign({},e),{lineHeight:n(e.lineHeight)})),t(e)},afterCreate(){if(!e.height){const t=e.lineHeight,n="number"==typeof t?t:parseFloat(t)||1.2;e.height=Math.round(e.fontSize*n)}},toggleEditMode(t){const n=null!=t?t:!e._editModeEnabled;n!==e._editModeEnabled&&(e._editModeEnabled=n,e._editModeEnabled?e.store.history.startTransaction():e.store.history.endTransaction())},beforeDestroy(){e._editModeEnabled&&e.store.history.endTransaction()}}});
1
+ import{types as e}from"mobx-state-tree";import{hasMeasuredHeight as t,parseNumericLineHeight as o}from"@polotno/core/text-types";import{Shape as n}from"./shape-model.js";const i=e=>{var t;return"string"!=typeof e?e:null!==(t=o(e))&&void 0!==t?t:e};export const TextElement=n.named("Text").props({type:"text",text:"",placeholder:"",fontSize:14,fontFamily:"Roboto",fontStyle:"normal",fontWeight:"normal",textDecoration:"",textTransform:"none",fill:"black",align:"center",width:100,height:0,verticalAlign:"top",strokeWidth:0,stroke:"black",strokeLineJoin:"round",lineHeight:e.optional(e.union(e.number,e.string),1.2),letterSpacing:0,_editModeEnabled:!1,backgroundEnabled:!1,backgroundColor:"#7ED321",backgroundOpacity:1,backgroundCornerRadius:.5,backgroundPadding:.5,legacyBackground:e.maybe(e.boolean),curveEnabled:!1,curvePower:.5}).preProcessSnapshot(e=>{const o=Object.assign(Object.assign({},e),{fontSize:null!=e.fontSize&&e.fontSize<1?1:e.fontSize,lineHeight:i(e.lineHeight)});return t(o)||delete o.height,o}).actions(e=>{const t=e.set;return{set(e){null!=e.fontSize&&e.fontSize<1&&(e=Object.assign(Object.assign({},e),{fontSize:1})),"string"==typeof e.lineHeight&&(e=Object.assign(Object.assign({},e),{lineHeight:i(e.lineHeight)})),t(e)},toggleEditMode(t){const o=null!=t?t:!e._editModeEnabled;o!==e._editModeEnabled&&(e._editModeEnabled=o,e._editModeEnabled?e.store.history.startTransaction():e.store.history.endTransaction())},beforeDestroy(){e._editModeEnabled&&e.store.history.endTransaction()}}});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "polotno",
3
- "version": "3.5.1",
3
+ "version": "3.5.2",
4
4
  "description": "Design Editor Framework",
5
5
  "author": "Anton Lavrenov",
6
6
  "keywords": [
@@ -96,10 +96,10 @@
96
96
  },
97
97
  "dependencies": {
98
98
  "@base-ui/react": "^1.6.0",
99
- "@polotno/core": "0.2.0",
100
- "@polotno/html-export": "0.1.0",
99
+ "@polotno/core": "0.3.0",
100
+ "@polotno/html-export": "0.1.1",
101
101
  "@polotno/schema": "0.3.0",
102
- "@polotno/svg-export": "0.1.1",
102
+ "@polotno/svg-export": "0.1.2",
103
103
  "class-variance-authority": "^0.7.1",
104
104
  "clsx": "^2.1.1",
105
105
  "gifuct-js": "^2.1.2",