@orangecatai/adgen-canvas 0.0.16 → 0.0.18
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.
- package/dist/dev/{chunk-4VEZT6GV.js → chunk-MCENPNB7.js} +2 -2
- package/dist/dev/{chunk-UJP3DIYP.js → chunk-V5POPSPR.js} +3 -3
- package/dist/dev/data/{image-PZBTJSVV.js → image-5TNF6BOW.js} +3 -3
- package/dist/dev/index.js +38 -5
- package/dist/dev/index.js.map +2 -2
- package/dist/dev/subset-shared.chunk.js +1 -1
- package/dist/dev/subset-worker.chunk.js +1 -1
- package/dist/prod/{chunk-62H5HX6J.js → chunk-OH4MQBSI.js} +1 -1
- package/dist/prod/{chunk-VXQSQDGS.js → chunk-TDDASSRC.js} +2 -2
- package/dist/prod/data/image-3TR7TIWR.js +1 -0
- package/dist/prod/index.js +22 -22
- package/dist/prod/subset-shared.chunk.js +1 -1
- package/dist/prod/subset-worker.chunk.js +1 -1
- package/dist/types/excalidraw/types.d.ts +1 -1
- package/package.json +1 -1
- package/dist/prod/data/image-REZEAPVS.js +0 -1
- /package/dist/dev/{chunk-4VEZT6GV.js.map → chunk-MCENPNB7.js.map} +0 -0
- /package/dist/dev/{chunk-UJP3DIYP.js.map → chunk-V5POPSPR.js.map} +0 -0
- /package/dist/dev/data/{image-PZBTJSVV.js.map → image-5TNF6BOW.js.map} +0 -0
package/dist/prod/index.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import{$ as mh,A as ch,B as eL,C as iE,D as sE,E as rm,F as ql,G as am,H as im,I as Jl,J as lE,K as cE,L as dE,M as zr,N as Yi,O as mE,P as tL,Q as Ga,R as $i,S as Ql,U as pE,W as uE,X as gE,Y as sm,Z as hE,_ as dh,a as oE,aa as lm,b as Ha,ba as fE,c as Ln,ca as ph,d as nE,da as Ua,e as Ge,ea as bE,f as rE,fa as Vi,g as de,ga as xE,h as Hi,ha as So,i as _n,ia as uh,j as Kl,ja as yE,k as Xl,ka as cm,l as Gi,la as gh,m as Zl,ma as EE,n as Ui,na as wE,o as aE,oa as vE,p as sh,pa as ec,q as Dn,r as Ho,s as Or,t as ho,u as pr,v as Wi,w as om,x as lh,y as jl,z as nm}from"./chunk-VXQSQDGS.js";import{a as T}from"./chunk-62H5HX6J.js";import{M as ih}from"./chunk-MSBJ7C4T.js";import{c as tE}from"./chunk-3PELD44J.js";import{b as Qy,c as eE,d as A}from"./chunk-SRAX5OIU.js";import uee,{useEffect as gee,useMemo as hee}from"react";import{DEFAULT_UI_OPTIONS as zA,isShallowEqual as fee}from"@orangecatai/common";import RP from"clsx";import Rj from"lodash.throttle";import cr,{useContext as Ba}from"react";import{flushSync as Io}from"react-dom";import Nj from"roughjs/bin/rough";import{nanoid as R1}from"nanoid";import{clamp as NP,pointFrom as pe,pointDistance as Pa,vector as BP,pointRotateRads as N1,vectorFromPoint as B1,vectorSubtract as FP,vectorDot as OP,vectorNormalize as zP}from"@orangecatai/math";import{COLOR_PALETTE as Bj,CODES as HP,shouldResizeFromCenter as GP,shouldMaintainAspectRatio as Dd,shouldRotateWithDiscreteAngle as UP,isArrowKey as Lg,KEYS as ne,APP_NAME as Fj,CURSOR_TYPE as lt,DEFAULT_MAX_IMAGE_WIDTH_OR_HEIGHT as Oj,DEFAULT_VERTICAL_ALIGN as WP,DRAGGING_THRESHOLD as YP,ELEMENT_SHIFT_TRANSLATE_AMOUNT as zj,ELEMENT_TRANSLATE_AMOUNT as $P,EVENT as he,FRAME_STYLE as ln,IMAGE_MIME_TYPES as Hj,IMAGE_RENDER_TIMEOUT as Gj,LINE_CONFIRM_THRESHOLD as F1,MAX_ALLOWED_FILE_BYTES as VP,MIME_TYPES as rr,MQ_RIGHT_SIDEBAR_MIN_WIDTH as Uj,POINTER_BUTTON as Aa,ROUNDNESS as _g,SCROLL_TIMEOUT as Wj,TAP_TWICE_TIMEOUT as Yj,TEXT_TO_CENTER_SNAP_THRESHOLD as $j,THEME as Dg,TOUCH_CTX_MENU_TIMEOUT as Vj,VERTICAL_ALIGN as Kj,YOUTUBE_STATES as Rg,ZOOM_STEP as Xj,POINTER_EVENTS as Nl,TOOL_TYPE as ar,supportsResizeObserver as Zj,DEFAULT_COLLISION_THRESHOLD as KP,DEFAULT_TEXT_ALIGN as jj,ARROW_TYPE as La,DEFAULT_REDUCED_GLOBAL_ALPHA as qj,isLocalLink as Jj,normalizeLink as O1,toValidURL as Qj,getGridPoint as Jt,getLineHeight as XP,debounce as ZP,distance as Bl,getFontString as z1,getNearestScrollableContainer as eq,isInputLike as jP,isToolIcon as tq,isWritableElement as Rd,sceneCoordsToViewportCoords as Ng,tupleToCoors as H1,viewportCoordsToSceneCoords as rt,wrapEvent as oq,updateObject as G1,updateActiveTool as ir,isTransparent as nq,easeToValuesRAF as rq,muteFSAbortError as aq,isTestEnv as N6,isDevEnv as B6,easeOut as iq,updateStable as Nd,addEventListener as ht,normalizeEOL as sq,getDateTime as qP,isShallowEqual as JP,arrayToMap as Bg,applyDarkModeFilter as lq,randomInteger as cq,CLASSES as U1,Emitter as Ai,MINIMUM_ARROW_SIZE as dq,DOUBLE_TAP_POSITION_THRESHOLD as mq,BIND_MODE_TIMEOUT as pq,invariant as sr,getFeatureFlag as Rr,createUserAgentDescriptor as F6,getFormFactor as uq,deriveStylesPanelMode as Wg,isIOS as gq,isBrave as hq,isSafari as fq,loadDesktopUIModePreference as bq,setDesktopUIMode as xq,isSelectionLikeTool as Fg,oneOf as QP}from"@orangecatai/common";import{getObservedAppState as yq,getCommonBounds as Fl,getElementAbsoluteCoords as Og,bindOrUnbindBindingElements as e6,fixBindingsAfterDeletion as Eq,getHoveredElementForBinding as Cn,isBindingEnabled as Bd,shouldEnableBindingForPointerEvent as wq,updateBoundElements as zg,LinearElementEditor as _e,newElementWith as _a,newFrameElement as t6,newFreeDrawElement as vq,newEmbeddableElement as o6,newMagicFrameElement as n6,newIframeElement as Iq,newArrowElement as Tq,newElement as Cq,newImageElement as W1,newLinearElement as kq,newTextElement as r6,refreshTextDimensions as Sq,deepCopyElement as a6,duplicateElements as Y1,hasBoundTextElement as i6,isArrowElement as Ol,isBindingElement as lr,isBindingElementType as Mq,isBoundToContainer as $1,isFrameLikeElement as Qt,isImageElement as Da,isEmbeddableElement as Nr,isInitializedImageElement as Fd,isLinearElement as mo,isLinearElementType as Pq,isUsingAdaptiveRadius as Aq,isIframeElement as zl,isIframeLikeElement as V1,isMagicFrameElement as K1,isTextBindableContainer as s6,isElbowArrow as To,isFlowchartNodeElement as Lq,isBindableElement as X1,isTextElement as kn,getNormalizedDimensions as _q,isElementCompletelyInViewport as Z1,isElementInViewport as l6,isInvisiblySmallElement as c6,getCornerRadius as Dq,isPathALoop as d6,createSrcDoc as m6,embeddableURLValidator as j1,maybeParseEmbedSrc as Rq,getEmbedLink as Hg,getInitializedImageElements as Nq,normalizeSVG as p6,updateImageCache as Bq,getBoundTextElement as q1,getContainerCenter as J1,getContainerElement as u6,isValidTextContainer as Fq,redrawTextBoundingBox as Oq,hasBoundingBox as zq,getFrameChildren as Q1,isCursorInFrame as g6,addElementsToFrame as ey,replaceAllElementsInFrame as Hq,removeElementsFromFrame as Gq,getElementsInResizingFrame as ty,getElementsInNewFrame as Uq,getContainingFrame as oy,elementOverlapsWithFrame as Wq,updateFrameMembershipOfSelectedElements as h6,isElementInFrame as f6,getFrameLikeTitle as Yq,getElementsOverlappingFrame as $q,filterElementsEligibleAsFrameChildren as Vq,hitElementBoundText as Kq,hitElementBoundingBoxOnly as Xq,hitElementItself as Od,getVisibleSceneBounds as Zq,FlowChartCreator as jq,FlowChartNavigator as qq,getLinkDirectionFromKey as b6,cropElement as Jq,wrapText as Qq,isElementLink as ny,parseElementLinkFromURL as eJ,isMeasureTextSupported as tJ,normalizeText as oJ,measureText as x6,getLineHeightInPx as nJ,getApproxMinLineWidth as rJ,getApproxMinLineHeight as aJ,getMinTextElementWidth as iJ,ShapeCache as zd,getRenderOpacity as sJ,editGroupForSelectedElement as lJ,getElementsInGroup as Li,getSelectedGroupIdForElement as cJ,getSelectedGroupIds as dJ,isElementInGroup as y6,isSelectedViaGroup as mJ,selectGroupsForSelectedElements as cn,syncInvalidIndices as O6,syncMovedIndices as E6,excludeElementsInFramesFromSelection as pJ,getSelectionStateForElements as uJ,makeNextSelectedElementIds as ze,getResizeOffsetXY as gJ,getResizeArrowDirection as hJ,transformElements as fJ,getCursorForResizingElement as w6,getElementWithTransformHandleType as v6,getTransformHandleTypeFromCoords as I6,dragNewElement as T6,dragSelectedElements as bJ,getDragOffsetXY as xJ,isNonDeletedElement as C6,Scene as k6,Store as yJ,CaptureUpdateAction as po,hitElementBoundingBox as EJ,isLineElement as ry,isSimpleArrow as ay,StoreDelta as S6,positionElementsOnGrid as M6,calculateFixedPointForNonElbowArrowBinding as P6,bindOrUnbindBindingElement as wJ,mutateElement as Gg,getElementBounds as A6,doBoundsIntersect as vJ,isPointInElement as IJ,maxBindingDistance_simple as iy,convertToExcalidrawElements as L6,getSnapOutlineMidPoint as sy,handleFocusPointDrag as TJ,handleFocusPointHover as CJ,handleFocusPointPointerDown as kJ,handleFocusPointPointerUp as SJ,maybeHandleArrowPointlikeDrag as Ug,getUncroppedWidthAndHeight as MJ}from"@orangecatai/element";import{KEYS as Hh,MOBILE_ACTION_BUTTON_BG as gL,updateActiveTool as hL}from"@orangecatai/common";import{getNonDeletedElements as Gh}from"@orangecatai/element";import{fixBindingsAfterDeletion as fL}from"@orangecatai/element";import{LinearElementEditor as vv}from"@orangecatai/element";import{newElementWith as Pm}from"@orangecatai/element";import{getContainerElement as Iv}from"@orangecatai/element";import{isBoundToContainer as Sm,isElbowArrow as bL,isFrameLikeElement as xL}from"@orangecatai/element";import{getFrameChildren as yL}from"@orangecatai/element";import{getElementsInGroup as Uh,selectGroupsForSelectedElements as EL}from"@orangecatai/element";import{CaptureUpdateAction as Mm}from"@orangecatai/element";import{isDevEnv as aL}from"@orangecatai/common";import{atom as Pe,createStore as oL}from"jotai";import{createIsolation as nL}from"jotai-scope";var IE=nL();var{useAtom:le,useSetAtom:Rn,useAtomValue:Ki,useStore:vee}=IE,TE=IE.Provider,Et=oL();var rL=Qy({"./locales/ar-SA.json":()=>import("./locales/ar-SA-NXDWD63E.js"),"./locales/az-AZ.json":()=>import("./locales/az-AZ-MXSORGZV.js"),"./locales/bg-BG.json":()=>import("./locales/bg-BG-O6MV2KSF.js"),"./locales/bn-BD.json":()=>import("./locales/bn-BD-T2VJNT7N.js"),"./locales/bn-IN.json":()=>import("./locales/bn-IN-MMW2ORAC.js"),"./locales/ca-ES.json":()=>import("./locales/ca-ES-MKBCGNOG.js"),"./locales/cs-CZ.json":()=>import("./locales/cs-CZ-V77HGUP7.js"),"./locales/da-DK.json":()=>import("./locales/da-DK-I5RFNTM4.js"),"./locales/de-CH.json":()=>import("./locales/de-CH-WLRDEVBV.js"),"./locales/de-DE.json":()=>import("./locales/de-DE-DTI4WUSC.js"),"./locales/el-GR.json":()=>import("./locales/el-GR-ZXDJ2OS4.js"),"./locales/en.json":()=>import("./locales/en-RQF5X6GM.js"),"./locales/es-ES.json":()=>import("./locales/es-ES-DYQHAD43.js"),"./locales/eu-ES.json":()=>import("./locales/eu-ES-QDSYU5Y3.js"),"./locales/fa-IR.json":()=>import("./locales/fa-IR-26LZG4PM.js"),"./locales/fi-FI.json":()=>import("./locales/fi-FI-6YS4KDE4.js"),"./locales/fr-FR.json":()=>import("./locales/fr-FR-BRLLPTZC.js"),"./locales/gl-ES.json":()=>import("./locales/gl-ES-OKUZTLYG.js"),"./locales/he-IL.json":()=>import("./locales/he-IL-26MGYIU7.js"),"./locales/hi-IN.json":()=>import("./locales/hi-IN-Q4ZOGTP2.js"),"./locales/hu-HU.json":()=>import("./locales/hu-HU-P2OXPSN5.js"),"./locales/id-ID.json":()=>import("./locales/id-ID-2EIKXYN6.js"),"./locales/it-IT.json":()=>import("./locales/it-IT-4CFKVXI2.js"),"./locales/ja-JP.json":()=>import("./locales/ja-JP-MAND2Z4V.js"),"./locales/kaa.json":()=>import("./locales/kaa-HQRTCXTJ.js"),"./locales/kab-KAB.json":()=>import("./locales/kab-KAB-JKIKKTGH.js"),"./locales/kk-KZ.json":()=>import("./locales/kk-KZ-HXQ63ZFC.js"),"./locales/km-KH.json":()=>import("./locales/km-KH-PKL3LSGX.js"),"./locales/ko-KR.json":()=>import("./locales/ko-KR-KXLREZX3.js"),"./locales/ku-TR.json":()=>import("./locales/ku-TR-MJ4IER3X.js"),"./locales/lt-LT.json":()=>import("./locales/lt-LT-H6WFQ6FJ.js"),"./locales/lv-LV.json":()=>import("./locales/lv-LV-GOCK6SJW.js"),"./locales/mr-IN.json":()=>import("./locales/mr-IN-IXVLDMEQ.js"),"./locales/my-MM.json":()=>import("./locales/my-MM-YG6MYTTD.js"),"./locales/nb-NO.json":()=>import("./locales/nb-NO-XGWJISD2.js"),"./locales/nl-NL.json":()=>import("./locales/nl-NL-XVDVCPNC.js"),"./locales/nn-NO.json":()=>import("./locales/nn-NO-EMX5MJX5.js"),"./locales/oc-FR.json":()=>import("./locales/oc-FR-ROEINTVO.js"),"./locales/pa-IN.json":()=>import("./locales/pa-IN-ZYN6SUDY.js"),"./locales/percentages.json":()=>import("./locales/percentages-5DKR754L.js"),"./locales/pl-PL.json":()=>import("./locales/pl-PL-6VTG7PHC.js"),"./locales/pt-BR.json":()=>import("./locales/pt-BR-5YFKRR5G.js"),"./locales/pt-PT.json":()=>import("./locales/pt-PT-GEIXXZ67.js"),"./locales/ro-RO.json":()=>import("./locales/ro-RO-E2P6TFZI.js"),"./locales/ru-RU.json":()=>import("./locales/ru-RU-YBIIY43T.js"),"./locales/si-LK.json":()=>import("./locales/si-LK-673C2CI2.js"),"./locales/sk-SK.json":()=>import("./locales/sk-SK-CKZHQ4AP.js"),"./locales/sl-SI.json":()=>import("./locales/sl-SI-557H2GWM.js"),"./locales/sv-SE.json":()=>import("./locales/sv-SE-XOPKKDWS.js"),"./locales/ta-IN.json":()=>import("./locales/ta-IN-XBH7DQI3.js"),"./locales/th-TH.json":()=>import("./locales/th-TH-TOCWH3R4.js"),"./locales/tr-TR.json":()=>import("./locales/tr-TR-GXW6CYY5.js"),"./locales/uk-UA.json":()=>import("./locales/uk-UA-IJKTNUDG.js"),"./locales/uz-UZ.json":()=>import("./locales/uz-UZ-TBZZEA4V.js"),"./locales/vi-VN.json":()=>import("./locales/vi-VN-MULSGNVB.js"),"./locales/zh-CN.json":()=>import("./locales/zh-CN-MVX3E32U.js"),"./locales/zh-HK.json":()=>import("./locales/zh-HK-JNU5RLIE.js"),"./locales/zh-TW.json":()=>import("./locales/zh-TW-LENVCA6T.js")});var iL=85,Nn={code:"en",label:"English"},Zi=[Nn,...[{code:"ar-SA",label:"\u0627\u0644\u0639\u0631\u0628\u064A\u0629",rtl:!0},{code:"bg-BG",label:"\u0411\u044A\u043B\u0433\u0430\u0440\u0441\u043A\u0438"},{code:"ca-ES",label:"Catal\xE0"},{code:"cs-CZ",label:"\u010Cesky"},{code:"de-DE",label:"Deutsch"},{code:"el-GR",label:"\u0395\u03BB\u03BB\u03B7\u03BD\u03B9\u03BA\u03AC"},{code:"es-ES",label:"Espa\xF1ol"},{code:"eu-ES",label:"Euskara"},{code:"fa-IR",label:"\u0641\u0627\u0631\u0633\u06CC",rtl:!0},{code:"fi-FI",label:"Suomi"},{code:"fr-FR",label:"Fran\xE7ais"},{code:"gl-ES",label:"Galego"},{code:"he-IL",label:"\u05E2\u05D1\u05E8\u05D9\u05EA",rtl:!0},{code:"hi-IN",label:"\u0939\u093F\u0928\u094D\u0926\u0940"},{code:"hu-HU",label:"Magyar"},{code:"id-ID",label:"Bahasa Indonesia"},{code:"it-IT",label:"Italiano"},{code:"ja-JP",label:"\u65E5\u672C\u8A9E"},{code:"kab-KAB",label:"Taqbaylit"},{code:"kk-KZ",label:"\u049A\u0430\u0437\u0430\u049B \u0442\u0456\u043B\u0456"},{code:"ko-KR",label:"\uD55C\uAD6D\uC5B4"},{code:"ku-TR",label:"Kurd\xEE"},{code:"lt-LT",label:"Lietuvi\u0173"},{code:"lv-LV",label:"Latvie\u0161u"},{code:"my-MM",label:"Burmese"},{code:"nb-NO",label:"Norsk bokm\xE5l"},{code:"nl-NL",label:"Nederlands"},{code:"nn-NO",label:"Norsk nynorsk"},{code:"oc-FR",label:"Occitan"},{code:"pa-IN",label:"\u0A2A\u0A70\u0A1C\u0A3E\u0A2C\u0A40"},{code:"pl-PL",label:"Polski"},{code:"pt-BR",label:"Portugu\xEAs Brasileiro"},{code:"pt-PT",label:"Portugu\xEAs"},{code:"ro-RO",label:"Rom\xE2n\u0103"},{code:"ru-RU",label:"\u0420\u0443\u0441\u0441\u043A\u0438\u0439"},{code:"sk-SK",label:"Sloven\u010Dina"},{code:"sv-SE",label:"Svenska"},{code:"sl-SI",label:"Sloven\u0161\u010Dina"},{code:"tr-TR",label:"T\xFCrk\xE7e"},{code:"uk-UA",label:"\u0423\u043A\u0440\u0430\u0457\u043D\u0441\u044C\u043A\u0430"},{code:"zh-CN",label:"\u7B80\u4F53\u4E2D\u6587"},{code:"zh-TW",label:"\u7E41\u9AD4\u4E2D\u6587"},{code:"vi-VN",label:"Ti\u1EBFng Vi\u1EC7t"},{code:"mr-IN",label:"\u092E\u0930\u093E\u0920\u0940"}].filter(e=>tE[e.code]>=iL).sort((e,t)=>e.label>t.label?1:-1)],mm="__test__";aL()&&Zi.unshift({code:mm,label:"test language"},{code:`${mm}.rtl`,label:"\u202Atest language (rtl)\u202C",rtl:!0});var Xi=Nn,dm={},pm=async e=>{if(Xi=e,document.documentElement.dir=Xi.rtl?"rtl":"ltr",document.documentElement.lang=Xi.code,e.code.startsWith(mm))dm={};else try{dm=await rL(`./locales/${Xi.code}.json`)}catch(t){console.error(`Failed to load language ${e.code}:`,t.message),dm=ih}Et.set(kE,e.code)},ur=()=>Xi,CE=(e,t)=>{for(let o=0;o<t.length;++o){let n=t[o];if(e[n]===void 0)return;e=e[n]}if(typeof e=="string")return e},f=(e,t,o)=>{if(Xi.code.startsWith(mm))return`\u202A[[${t?`${e}(${JSON.stringify(t).slice(1,-1)})`:e}]]\u202C`;let n=e.split("."),r=CE(dm,n)||CE(ih,n)||o;if(r===void 0){let a=`Can't find translation for ${e}`;if(T.PROD)return console.warn(a),"";throw new Error(a)}if(t)for(let a in t)r=r.replace(`{{${a}}}`,String(t[a]));return r},kE=Pe(Nn.code),Ue=()=>{let e=Ki(kE);return{t:f,langCode:e}};import sL from"clsx";import _t from"react";import{THEME as lL}from"@orangecatai/common";import{Fragment as We,jsx as b,jsxs as H}from"react/jsx-runtime";var pn=e=>"var(--icon-fill-color)",SE=e=>e===lL.LIGHT?"#fff":"#1e1e1e",R=(e,t=512)=>{let{width:o=512,height:n=o,mirror:r,style:a,...i}=typeof t=="number"?{width:t}:t;return b("svg",{"aria-hidden":"true",focusable:"false",role:"img",viewBox:`0 0 ${o} ${n}`,className:sL({"rtl-mirror":r}),style:a,...i,children:typeof e=="string"?b("path",{fill:"currentColor",d:e}):e})},K={width:24,height:24,fill:"none",strokeWidth:2,stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round"},Ee={width:20,height:20,fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round"},Fee=R(H("g",{strokeWidth:"1.5",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("rect",{x:3,y:8,width:18,height:4,rx:1}),b("line",{x1:12,y1:8,x2:12,y2:21}),b("path",{d:"M19 12v7a2 2 0 0 1 -2 2h-10a2 2 0 0 1 -2 -2v-7"}),b("path",{d:"M7.5 8a2.5 2.5 0 0 1 0 -5a4.8 8 0 0 1 4.5 5a4.8 8 0 0 1 4.5 -5a2.5 2.5 0 0 1 0 5"})]}),K),um=R(H("g",{strokeWidth:"1.25",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M3 19a9 9 0 0 1 9 0a9 9 0 0 1 9 0"}),b("path",{d:"M3 6a9 9 0 0 1 9 0a9 9 0 0 1 9 0"}),b("line",{x1:"3",y1:"6",x2:"3",y2:"19"}),b("line",{x1:"12",y1:"6",x2:"12",y2:"19"}),b("line",{x1:"21",y1:"6",x2:"21",y2:"19"})]}),K),ME=R(H("svg",{strokeWidth:"1.5",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),b("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]}),K),PE=R(H("g",{strokeWidth:"1.5",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("circle",{cx:"12",cy:"12",r:"1"}),b("circle",{cx:"12",cy:"19",r:"1"}),b("circle",{cx:"12",cy:"5",r:"1"})]}),K),AE=R(H("g",{strokeWidth:"1.5",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M5 12m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0"}),b("path",{d:"M12 12m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0"}),b("path",{d:"M19 12m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0"})]}),K),LE=R(H("svg",{strokeWidth:"1.5",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M9 4v6l-2 4v2h10v-2l-2 -4v-6"}),b("line",{x1:"12",y1:"16",x2:"12",y2:"21"}),b("line",{x1:"8",y1:"4",x2:"16",y2:"4"})]}),K),hh=R(H("g",{strokeWidth:1.25,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M12 5m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"}),b("path",{d:"M19 8m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"}),b("path",{d:"M5 11m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"}),b("path",{d:"M15 19m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"}),b("path",{d:"M6.5 9.5l3.5 -3"}),b("path",{d:"M14 5.5l3 1.5"}),b("path",{d:"M18.5 10l-2.5 7"}),b("path",{d:"M13.5 17.5l-7 -5"})]}),K),Wa=R(H("g",{children:[b("path",{d:"M13.542 8.542H6.458a2.5 2.5 0 0 0-2.5 2.5v3.75a2.5 2.5 0 0 0 2.5 2.5h7.084a2.5 2.5 0 0 0 2.5-2.5v-3.75a2.5 2.5 0 0 0-2.5-2.5Z",stroke:"currentColor",strokeWidth:"1.25"}),b("path",{d:"M10 13.958a1.042 1.042 0 1 0 0-2.083 1.042 1.042 0 0 0 0 2.083Z",stroke:"currentColor",strokeWidth:"1.25"}),b("mask",{id:"UnlockedIcon",style:{maskType:"alpha"},maskUnits:"userSpaceOnUse",x:6,y:1,width:9,height:9,children:b("path",{stroke:"none",d:"M6.399 9.561V5.175c0-.93.401-1.823 1.116-2.48a3.981 3.981 0 0 1 2.693-1.028c1.01 0 1.98.37 2.694 1.027.715.658 1.116 1.55 1.116 2.481",fill:"#fff"})}),b("g",{mask:"url(#UnlockedIcon)",children:b("path",{stroke:"none",d:"M5.149 9.561v1.25h2.5v-1.25h-2.5Zm5.06-7.894V.417v1.25Zm2.559 3.508v1.25h2.5v-1.25h-2.5ZM7.648 8.51V5.175h-2.5V8.51h2.5Zm0-3.334c0-.564.243-1.128.713-1.561L6.668 1.775c-.959.883-1.52 2.104-1.52 3.4h2.5Zm.713-1.561a2.732 2.732 0 0 1 1.847-.697v-2.5c-1.31 0-2.585.478-3.54 1.358L8.36 3.614Zm1.847-.697c.71 0 1.374.26 1.847.697l1.694-1.839a5.231 5.231 0 0 0-3.54-1.358v2.5Zm1.847.697c.47.433.713.997.713 1.561h2.5c0-1.296-.56-2.517-1.52-3.4l-1.693 1.839Z",fill:"currentColor"})})]}),Ee),ji=R(H("g",{strokeWidth:"1.25",children:[b("path",{d:"M13.542 8.542H6.458a2.5 2.5 0 0 0-2.5 2.5v3.75a2.5 2.5 0 0 0 2.5 2.5h7.084a2.5 2.5 0 0 0 2.5-2.5v-3.75a2.5 2.5 0 0 0-2.5-2.5Z"}),b("path",{d:"M10 13.958a1.042 1.042 0 1 0 0-2.083 1.042 1.042 0 0 0 0 2.083Z"}),b("path",{d:"M6.667 8.333V5.417C6.667 3.806 8.159 2.5 10 2.5c1.841 0 3.333 1.306 3.333 2.917v2.916"})]}),Ee),_E=R(b("g",{fill:"currentColor",children:b("path",{d:"M12 2a5 5 0 0 1 5 5v3a3 3 0 0 1 3 3v6a3 3 0 0 1 -3 3h-10a3 3 0 0 1 -3 -3v-6a3 3 0 0 1 3 -3v-3a5 5 0 0 1 5 -5m0 12a2 2 0 0 0 -1.995 1.85l-.005 .15a2 2 0 1 0 2 -2m0 -10a3 3 0 0 0 -3 3v3h6v-3a3 3 0 0 0 -3 -3"})}),{width:24,height:24}),DE=R(H(We,{children:[b("path",{d:"M38.5 83.5c-14-2-17.833-10.473-21-22.5C14.333 48.984 12 22 12 12.5",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round"}),b("path",{fillRule:"evenodd",clipRule:"evenodd",d:"m12.005 10.478 7.905 14.423L6 25.75l6.005-15.273Z",fill:"currentColor"}),b("path",{d:"M12.005 10.478c1.92 3.495 3.838 7 7.905 14.423m-7.905-14.423c3.11 5.683 6.23 11.368 7.905 14.423m0 0c-3.68.226-7.35.455-13.91.85m13.91-.85c-5.279.33-10.566.647-13.91.85m0 0c1.936-4.931 3.882-9.86 6.005-15.273M6 25.75c2.069-5.257 4.135-10.505 6.005-15.272",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round"})]}),{width:41,height:94,fill:"none"}),RE=R(H(We,{children:[b("path",{d:"M18.026 1.232c-5.268 13.125-5.548 33.555 3.285 42.311 8.823 8.75 33.31 12.304 42.422 13.523",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round"}),b("path",{fillRule:"evenodd",clipRule:"evenodd",d:"m72.181 59.247-13.058-10-2.948 13.62 16.006-3.62Z",fill:"currentColor"}),b("path",{d:"M72.181 59.247c-3.163-2.429-6.337-4.856-13.058-10m13.058 10c-5.145-3.936-10.292-7.882-13.058-10m0 0c-.78 3.603-1.563 7.196-2.948 13.62m2.948-13.62c-1.126 5.168-2.24 10.346-2.948 13.62m0 0c5.168-1.166 10.334-2.343 16.006-3.62m-16.006 3.62c5.51-1.248 11.01-2.495 16.006-3.62",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round"})]}),{width:85,height:71,fill:"none"}),NE=R(H(We,{children:[b("path",{d:"M1 77c14-2 31.833-11.973 35-24 3.167-12.016-6-35-9.5-43.5",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round"}),b("path",{fillRule:"evenodd",clipRule:"evenodd",d:"m24.165 1.093-2.132 16.309 13.27-4.258-11.138-12.05Z",fill:"currentColor"}),b("path",{d:"M24.165 1.093c-.522 3.953-1.037 7.916-2.132 16.309m2.131-16.309c-.835 6.424-1.68 12.854-2.13 16.308m0 0c3.51-1.125 7.013-2.243 13.27-4.257m-13.27 4.257c5.038-1.608 10.08-3.232 13.27-4.257m0 0c-3.595-3.892-7.197-7.777-11.14-12.05m11.14 12.05c-3.837-4.148-7.667-8.287-11.14-12.05",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round"})]}),{width:38,height:78,fill:"none"}),Oee=R(b("g",{fill:"currentColor",children:b("path",{d:"M39.9 32.889a.326.326 0 0 0-.279-.056c-2.094-3.083-4.774-6-7.343-8.833l-.419-.472a.212.212 0 0 0-.056-.139.586.586 0 0 0-.167-.111l-.084-.083-.056-.056c-.084-.167-.28-.278-.475-.167-.782.39-1.507.973-2.206 1.528-.92.722-1.842 1.445-2.708 2.25a8.405 8.405 0 0 0-.977 1.028c-.14.194-.028.361.14.444-.615.611-1.23 1.223-1.843 1.861a.315.315 0 0 0-.084.223c0 .083.056.166.111.194l1.09.833v.028c1.535 1.528 4.244 3.611 7.12 5.861.418.334.865.667 1.284 1 .195.223.39.473.558.695.084.11.28.139.391.055.056.056.14.111.196.167a.398.398 0 0 0 .167.056.255.255 0 0 0 .224-.111.394.394 0 0 0 .055-.167c.029 0 .028.028.056.028a.318.318 0 0 0 .224-.084l5.082-5.528a.309.309 0 0 0 0-.444Zm-14.63-1.917a.485.485 0 0 0 .111.14c.586.5 1.2 1 1.843 1.555l-2.569-1.945-.251-.166c-.056-.028-.112-.084-.168-.111l-.195-.167.056-.056.055-.055.112-.111c.866-.861 2.346-2.306 3.1-3.028-.81.805-2.43 3.167-2.095 3.944Zm8.767 6.89-2.122-1.612a44.713 44.713 0 0 0-2.625-2.5c1.145.861 2.122 1.611 2.262 1.75 1.117.972 1.06.806 1.815 1.445l.921.666a1.06 1.06 0 0 1-.251.25Zm.558.416-.056-.028c.084-.055.168-.111.252-.194l-.196.222ZM1.089 5.75c.055.361.14.722.195 1.056.335 1.833.67 3.5 1.284 4.75l.252.944c.084.361.223.806.363.917 1.424 1.25 3.602 3.11 5.947 4.889a.295.295 0 0 0 .363 0s0 .027.028.027a.254.254 0 0 0 .196.084.318.318 0 0 0 .223-.084c2.988-3.305 5.221-6.027 6.813-8.305.112-.111.14-.278.14-.417.111-.111.195-.25.307-.333.111-.111.111-.306 0-.39l-.028-.027c0-.055-.028-.139-.084-.167-.698-.666-1.2-1.138-1.731-1.638-.922-.862-1.871-1.75-3.881-3.75l-.028-.028c-.028-.028-.056-.056-.112-.056-.558-.194-1.703-.389-3.127-.639C6.087 2.223 3.21 1.723.614.944c0 0-.168 0-.196.028l-.083.084c-.028.027-.056.055-.224.11h.056-.056c.028.167.028.278.084.473 0 .055.112.5.112.555l.782 3.556Zm15.496 3.278-.335-.334c.084.112.196.195.335.334Zm-3.546 4.666-.056.056c0-.028.028-.056.056-.056Zm-2.038-10c.168.167.866.834 1.033.973-.726-.334-2.54-1.167-3.379-1.445.838.167 1.983.334 2.346.472ZM1.424 2.306c.419.722.754 3.222 1.089 5.666-.196-.778-.335-1.555-.503-2.278-.251-1.277-.503-2.416-.838-3.416.056 0 .14 0 .252.028Zm-.168-.584c-.112 0-.223-.028-.307-.028 0-.027 0-.055-.028-.055.14 0 .223.028.335.083Zm-1.089.222c0-.027 0-.027 0 0ZM39.453 1.333c.028-.11-.558-.61-.363-.639.42-.027.42-.666 0-.666-.558.028-1.144.166-1.675.25-.977.194-1.982.389-2.96.61-2.205.473-4.383.973-6.561 1.557-.67.194-1.424.333-2.066.666-.224.111-.196.333-.084.472-.056.028-.084.028-.14.056-.195.028-.363.056-.558.083-.168.028-.252.167-.224.334 0 .027.028.083.028.11-1.173 1.556-2.485 3.195-3.909 4.945-1.396 1.611-2.876 3.306-4.356 5.056-4.719 5.5-10.052 11.75-15.943 17.25a.268.268 0 0 0 0 .389c.028.027.056.055.084.055-.084.084-.168.14-.252.222-.056.056-.084.111-.084.167a.605.605 0 0 0-.111.139c-.112.111-.112.305.028.389.111.11.307.11.39-.028.029-.028.029-.056.056-.056a.44.44 0 0 1 .615 0c.335.362.67.723.977 1.028l-.698-.583c-.112-.111-.307-.083-.39.028-.113.11-.085.305.027.389l7.427 6.194c.056.056.112.056.196.056s.14-.028.195-.084l.168-.166c.028.027.083.027.111.027.084 0 .14-.027.196-.083 10.052-10.055 18.15-17.639 27.42-24.417.083-.055.111-.166.111-.25.112 0 .196-.083.251-.194 1.704-5.194 2.039-9.806 2.15-12.083v-.028c0-.028.028-.056.028-.083.028-.056.028-.084.028-.084a1.626 1.626 0 0 0-.111-1.028ZM21.472 9.5c.446-.5.893-1.028 1.34-1.5-2.876 3.778-7.65 9.583-14.408 16.5 4.607-5.083 9.242-10.333 13.068-15ZM5.193 35.778h.084-.084Zm3.462 3.194c-.027-.028-.027-.028 0-.028v.028Zm4.16-3.583c.224-.25.448-.472.699-.722 0 0 0 .027.028.027-.252.223-.475.445-.726.695Zm1.146-1.111c.14-.14.279-.334.446-.5l.028-.028c1.648-1.694 3.351-3.389 5.082-5.111l.028-.028c.419-.333.921-.694 1.368-1.028a379.003 379.003 0 0 0-6.952 6.695ZM24.794 6.472c-.921 1.195-1.954 2.778-2.82 4.028-2.736 3.944-11.532 13.583-11.727 13.75a1976.983 1976.983 0 0 1-8.042 7.639l-.167.167c-.14-.167-.14-.417.028-.556C14.49 19.861 22.03 10.167 25.074 5.917c-.084.194-.14.36-.28.555Zm4.83 5.695c-1.116-.64-1.646-1.64-1.34-2.611l.084-.334c.028-.083.084-.194.14-.277.307-.5.754-.917 1.257-1.167.027 0 .055 0 .083-.028-.028-.056-.028-.139-.028-.222.028-.167.14-.278.335-.278.335 0 1.369.306 1.76.639.111.083.223.194.335.305.14.167.363.445.474.667.056.028.112.306.196.445.056.222.111.472.084.694-.028.028 0 .194-.028.194a2.668 2.668 0 0 1-.363 1.028c-.028.028-.028.056-.056.084l-.028.027c-.14.223-.335.417-.53.556-.643.444-1.369.583-2.095.389 0 0-.195-.084-.28-.111Zm8.154-.834a39.098 39.098 0 0 1-.893 3.167c0 .028-.028.083 0 .111-.056 0-.084.028-.14.056-2.206 1.61-4.356 3.305-6.506 5.028 1.843-1.64 3.686-3.306 5.613-4.945.558-.5.949-1.139 1.06-1.861l.28-1.667v-.055c.14-.334.67-.195.586.166Z",fill:"currentColor"})}),{width:40,height:40,fill:"none"}),Ya=R(H("g",{stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M6 6l4.153 11.793a0.365 .365 0 0 0 .331 .207a0.366 .366 0 0 0 .332 -.207l2.184 -4.793l4.787 -1.994a0.355 .355 0 0 0 .213 -.323a0.355 .355 0 0 0 -.213 -.323l-11.787 -4.36z"}),b("path",{d:"M13.5 13.5l4.5 4.5"})]}),{fill:"none",width:22,height:22,strokeWidth:1.25}),Hr=R(H("g",{stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,children:[b("path",{d:"M4.028 13.252c-.657 -.972 -1.028 -2.078 -1.028 -3.252c0 -3.866 4.03 -7 9 -7s9 3.134 9 7s-4.03 7 -9 7c-1.913 0 -3.686 -.464 -5.144 -1.255"}),b("path",{d:"M5 15m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"}),b("path",{d:"M5 17c0 1.42 .316 2.805 1 4"})]}),{fill:"none",width:22,height:22,strokeWidth:1.25}),qi=R(H("g",{strokeWidth:"1.5",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"})]}),K),Ji=R(H("g",{strokeWidth:"1.5",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M10.5 20.4l-6.9 -6.9c-.781 -.781 -.781 -2.219 0 -3l6.9 -6.9c.781 -.781 2.219 -.781 3 0l6.9 6.9c.781 .781 .781 2.219 0 3l-6.9 6.9c-.781 .781 -2.219 .781 -3 0z"})]}),K),Qi=R(H("g",{strokeWidth:"1.5",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("circle",{cx:"12",cy:"12",r:"9"})]}),K),gm=R(H("g",{strokeWidth:"1.5",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("line",{x1:"5",y1:"12",x2:"19",y2:"12"}),b("line",{x1:"15",y1:"16",x2:"19",y2:"12"}),b("line",{x1:"15",y1:"8",x2:"19",y2:"12"})]}),K),es=R(b("path",{d:"M4.167 10h11.666",strokeWidth:"1.5"}),Ee),BE=R(H("g",{strokeWidth:"1.25",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M20 17v-12c0 -1.121 -.879 -2 -2 -2s-2 .879 -2 2v12l2 2l2 -2z"}),b("path",{d:"M16 7h4"}),b("path",{d:"M18 19h-13a2 2 0 1 1 0 -4h4a2 2 0 1 0 0 -4h-3"})]}),K),Bn=R(H("g",{strokeWidth:"1.25",children:[b("path",{clipRule:"evenodd",d:"m7.643 15.69 7.774-7.773a2.357 2.357 0 1 0-3.334-3.334L4.31 12.357a3.333 3.333 0 0 0-.977 2.357v1.953h1.953c.884 0 1.732-.352 2.357-.977Z"}),b("path",{d:"m11.25 5.417 3.333 3.333"})]}),Ee),Fn=R(H("g",{strokeWidth:"1.5",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("line",{x1:"4",y1:"20",x2:"7",y2:"20"}),b("line",{x1:"14",y1:"20",x2:"21",y2:"20"}),b("line",{x1:"6.9",y1:"15",x2:"13.8",y2:"15"}),b("line",{x1:"10.2",y1:"6.3",x2:"16",y2:"20"}),b("polyline",{points:"5 20 11 4 13 4 20 20"})]}),K),FE=R(H("g",{stroke:"currentColor",strokeWidth:"1.5",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M3 7v-2h13v2"}),b("path",{d:"M10 5v14"}),b("path",{d:"M12 19h-4"}),b("path",{d:"M15 13v-1h6v1"}),b("path",{d:"M18 12v7"}),b("path",{d:"M17 19h2"})]}),K),ts=R(H("g",{strokeWidth:"1.25",children:[b("path",{d:"M12.5 6.667h.01"}),b("path",{d:"M4.91 2.625h10.18a2.284 2.284 0 0 1 2.285 2.284v10.182a2.284 2.284 0 0 1-2.284 2.284H4.909a2.284 2.284 0 0 1-2.284-2.284V4.909a2.284 2.284 0 0 1 2.284-2.284Z"}),b("path",{d:"m3.333 12.5 3.334-3.333c.773-.745 1.726-.745 2.5 0l4.166 4.166"}),b("path",{d:"m11.667 11.667.833-.834c.774-.744 1.726-.744 2.5 0l1.667 1.667"})]}),Ee),hm=R(H("g",{strokeWidth:"1.5",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M19 20h-10.5l-4.21 -4.3a1 1 0 0 1 0 -1.41l10 -10a1 1 0 0 1 1.41 0l5 5a1 1 0 0 1 0 1.41l-9.2 9.3"}),b("path",{d:"M18 13.3l-6.3 -6.3"})]}),K),fh=R(b("path",{strokeWidth:"1.25",d:"M10 4.167v11.666M4.167 10h11.666"}),Ee),bh=R(b("path",{d:"M5 10h10",strokeWidth:"1.25"}),Ee),OE=R(H("g",{strokeWidth:1.25,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M21 21l-6 -6"}),b("path",{d:"M3.268 12.043a7.017 7.017 0 0 0 6.634 4.957a7.012 7.012 0 0 0 7.043 -6.131a7 7 0 0 0 -5.314 -7.672a7.021 7.021 0 0 0 -8.241 4.403"}),b("path",{d:"M3 4v4h4"})]}),K),Ut=R(b("path",{strokeWidth:"1.25",d:"M3.333 5.833h13.334M8.333 9.167v5M11.667 9.167v5M4.167 5.833l.833 10c0 .92.746 1.667 1.667 1.667h6.666c.92 0 1.667-.746 1.667-1.667l.833-10M7.5 5.833v-2.5c0-.46.373-.833.833-.833h3.334c.46 0 .833.373.833.833v2.5"}),Ee),os=R(H("g",{strokeWidth:"1.5",children:[b("polyline",{points:"12 16 18 10 12 4"}),b("polyline",{points:"8 4 2 10 8 16"})]}),Ee),tc=R(H("g",{strokeWidth:"1.25",children:[b("path",{d:"M14.375 6.458H8.958a2.5 2.5 0 0 0-2.5 2.5v5.417a2.5 2.5 0 0 0 2.5 2.5h5.417a2.5 2.5 0 0 0 2.5-2.5V8.958a2.5 2.5 0 0 0-2.5-2.5Z"}),b("path",{clipRule:"evenodd",d:"M11.667 3.125c.517 0 .986.21 1.325.55.34.338.55.807.55 1.325v1.458H8.333c-.485 0-.927.185-1.26.487-.343.312-.57.75-.609 1.24l-.005 5.357H5a1.87 1.87 0 0 1-1.326-.55 1.87 1.87 0 0 1-.549-1.325V5c0-.518.21-.987.55-1.326.338-.34.807-.549 1.325-.549h6.667Z"})]}),Ee),oc=R(b("path",{clipRule:"evenodd",d:"M10 2.5h.328a6.25 6.25 0 0 0 6.6 10.372A7.5 7.5 0 1 1 10 2.493V2.5Z",stroke:"currentColor"}),Ee),nc=R(b("g",{stroke:"currentColor",strokeLinejoin:"round",children:b("path",{d:"M10 12.5a2.5 2.5 0 1 0 0-5 2.5 2.5 0 0 0 0 5ZM10 4.167V2.5M14.167 5.833l1.166-1.166M15.833 10H17.5M14.167 14.167l1.166 1.166M10 15.833V17.5M5.833 14.167l-1.166 1.166M5 10H3.333M5.833 5.833 4.667 4.667"})}),{...Ee,strokeWidth:1.5}),zE=R(H("g",{strokeWidth:"1.5",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("line",{x1:"4",y1:"6",x2:"20",y2:"6"}),b("line",{x1:"4",y1:"12",x2:"20",y2:"12"}),b("line",{x1:"4",y1:"18",x2:"20",y2:"18"})]}),K),$a=R(b("path",{strokeWidth:"1.25",d:"M3.333 14.167v1.666c0 .92.747 1.667 1.667 1.667h10c.92 0 1.667-.746 1.667-1.667v-1.666M5.833 9.167 10 13.333l4.167-4.166M10 3.333v10"}),Ee),ns=R(H("g",{strokeWidth:"1.5",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("circle",{cx:"12",cy:"12",r:"9"}),b("line",{x1:"12",y1:"17",x2:"12",y2:"17.01"}),b("path",{d:"M12 13.5a1.5 1.5 0 0 1 1 -1.5a2.6 2.6 0 1 0 -3 -4"})]}),K),HE=R(H("g",{strokeWidth:"1.25",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("circle",{cx:"12",cy:"12",r:"9"}),b("line",{x1:"12",y1:"17",x2:"12",y2:"17.01"}),b("path",{d:"M12 13.5a1.5 1.5 0 0 1 1 -1.5a2.6 2.6 0 1 0 -3 -4"})]}),K),xh=R(b("path",{strokeWidth:"1.25",d:"M9.167 5.833H5.833c-1.254 0-2.5 1.282-2.5 2.5v5.834c0 1.283 1.252 2.5 2.5 2.5h5.834c1.251 0 2.5-1.25 2.5-2.5v-3.334M8.333 11.667l8.334-8.334M12.5 3.333h4.167V7.5"}),Ee),fm=R(b("path",{d:"M7.5 15.833c-3.583 1.167-3.583-2.083-5-2.5m10 4.167v-2.917c0-.833.083-1.166-.417-1.666 2.334-.25 4.584-1.167 4.584-5a3.833 3.833 0 0 0-1.084-2.667 3.5 3.5 0 0 0-.083-2.667s-.917-.25-2.917 1.084a10.25 10.25 0 0 0-5.166 0C5.417 2.333 4.5 2.583 4.5 2.583a3.5 3.5 0 0 0-.083 2.667 3.833 3.833 0 0 0-1.084 2.667c0 3.833 2.25 4.75 4.584 5-.5.5-.5 1-.417 1.666V17.5",strokeWidth:"1.25"}),Ee),GE=R(H("g",{strokeWidth:"1.25",children:[b("path",{d:"M7.5 10.833a.833.833 0 1 0 0-1.666.833.833 0 0 0 0 1.666ZM12.5 10.833a.833.833 0 1 0 0-1.666.833.833 0 0 0 0 1.666ZM6.25 6.25c2.917-.833 4.583-.833 7.5 0M5.833 13.75c2.917.833 5.417.833 8.334 0"}),b("path",{d:"M12.917 14.167c0 .833 1.25 2.5 1.666 2.5 1.25 0 2.361-1.39 2.917-2.5.556-1.39.417-4.861-1.25-9.584-1.214-.846-2.5-1.116-3.75-1.25l-.833 2.084M7.083 14.167c0 .833-1.13 2.5-1.526 2.5-1.191 0-2.249-1.39-2.778-2.5-.529-1.39-.397-4.861 1.19-9.584 1.157-.846 2.318-1.116 3.531-1.25l.833 2.084"})]}),Ee),UE=R(H("g",{strokeWidth:"1.25",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M4 4l11.733 16h4.267l-11.733 -16z"}),b("path",{d:"M4 20l6.768 -6.768m2.46 -2.46l6.772 -6.772"})]}),K),bm=R(b("polyline",{fill:"none",stroke:"currentColor",points:"20 6 9 17 4 12"}),{width:24,height:24}),rc=R(H("g",{strokeWidth:"1.25",children:[b("path",{d:"M8.333 11.667a2.917 2.917 0 0 0 4.167 0l3.333-3.334a2.946 2.946 0 1 0-4.166-4.166l-.417.416"}),b("path",{d:"M11.667 8.333a2.917 2.917 0 0 0-4.167 0l-3.333 3.334a2.946 2.946 0 0 0 4.166 4.166l.417-.416"})]}),Ee),WE=R("M433.941 129.941l-83.882-83.882A48 48 0 0 0 316.118 32H48C21.49 32 0 53.49 0 80v352c0 26.51 21.49 48 48 48h352c26.51 0 48-21.49 48-48V163.882a48 48 0 0 0-14.059-33.941zM224 416c-35.346 0-64-28.654-64-64 0-35.346 28.654-64 64-64s64 28.654 64 64c0 35.346-28.654 64-64 64zm96-304.52V212c0 6.627-5.373 12-12 12H76c-6.627 0-12-5.373-12-12V108c0-6.627 5.373-12 12-12h228.52c3.183 0 6.235 1.264 8.485 3.515l3.48 3.48A11.996 11.996 0 0 1 320 111.48z",{width:448,height:512}),YE=R("M252 54L203 8a28 27 0 00-20-8H28C12 0 0 12 0 27v195c0 15 12 26 28 26h204c15 0 28-11 28-26V73a28 27 0 00-8-19zM130 213c-21 0-37-16-37-36 0-19 16-35 37-35 20 0 37 16 37 35 0 20-17 36-37 36zm56-169v56c0 4-4 6-7 6H44c-4 0-7-2-7-6V42c0-4 3-7 7-7h133l4 2 3 2a7 7 0 012 5z M296 201l87 95-188 205-78 9c-10 1-19-8-18-20l9-84zm141-14l-41-44a31 31 0 00-46 0l-38 41 87 95 38-42c13-14 13-36 0-50z",{width:448,height:512}),rs=R(b("path",{d:"m9.257 6.351.183.183H15.819c.34 0 .727.182 1.051.506.323.323.505.708.505 1.05v5.819c0 .316-.183.7-.52 1.035-.337.338-.723.522-1.037.522H4.182c-.352 0-.74-.181-1.058-.5-.318-.318-.499-.705-.499-1.057V5.182c0-.351.181-.736.5-1.054.32-.321.71-.503 1.057-.503H6.53l2.726 2.726Z",strokeWidth:"1.25"}),Ee),zee=R("M384 112v352c0 26.51-21.49 48-48 48H48c-26.51 0-48-21.49-48-48V112c0-26.51 21.49-48 48-48h80c0-35.29 28.71-64 64-64s64 28.71 64 64h80c26.51 0 48 21.49 48 48zM192 40c-13.255 0-24 10.745-24 24s10.745 24 24 24 24-10.745 24-24-10.745-24-24-24m96 114v-20a6 6 0 0 0-6-6H102a6 6 0 0 0-6 6v20a6 6 0 0 0 6 6h180a6 6 0 0 0 6-6z",{width:384,height:512}),Hee=R("M204.3 5C104.9 24.4 24.8 104.3 5.2 203.4c-37 187 131.7 326.4 258.8 306.7 41.2-6.4 61.4-54.6 42.5-91.7-23.1-45.4 9.9-98.4 60.9-98.4h79.7c35.8 0 64.8-29.6 64.9-65.3C511.5 97.1 368.1-26.9 204.3 5zM96 320c-17.7 0-32-14.3-32-32s14.3-32 32-32 32 14.3 32 32-14.3 32-32 32zm32-128c-17.7 0-32-14.3-32-32s14.3-32 32-32 32 14.3 32 32-14.3 32-32 32zm128-64c-17.7 0-32-14.3-32-32s14.3-32 32-32 32 14.3 32 32-14.3 32-32 32zm128 64c-17.7 0-32-14.3-32-32s14.3-32 32-32 32 14.3 32 32-14.3 32-32 32z"),xm=R(H("g",{strokeWidth:1.25,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M5 16l1.465 1.638a2 2 0 1 1 -3.015 .099l1.55 -1.737z"}),b("path",{d:"M13.737 9.737c2.299 -2.3 3.23 -5.095 2.081 -6.245c-1.15 -1.15 -3.945 -.217 -6.244 2.082c-2.3 2.299 -3.231 5.095 -2.082 6.244c1.15 1.15 3.946 .218 6.245 -2.081z"}),b("path",{d:"M7.492 11.818c.362 .362 .768 .676 1.208 .934l6.895 4.047c1.078 .557 2.255 -.075 3.692 -1.512c1.437 -1.437 2.07 -2.614 1.512 -3.692c-.372 -.718 -1.72 -3.017 -4.047 -6.895a6.015 6.015 0 0 0 -.934 -1.208"})]}),K),$E=R(b("g",{strokeWidth:1.5,children:b("path",{d:"M6 18l12 -12"})}),K),ym=R(H("g",{strokeWidth:"1.25",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M15 8h.01"}),b("path",{d:"M12 20h-5a3 3 0 0 1 -3 -3v-10a3 3 0 0 1 3 -3h10a3 3 0 0 1 3 3v5"}),b("path",{d:"M4 15l4 -4c.928 -.893 2.072 -.893 3 0l4 4"}),b("path",{d:"M14 14l1 -1c.617 -.593 1.328 -.793 2.009 -.598"}),b("path",{d:"M19 16v6"}),b("path",{d:"M22 19l-3 3l-3 -3"})]}),K),VE=R("M216 0h80c13.3 0 24 10.7 24 24v168h87.7c17.8 0 26.7 21.5 14.1 34.1L269.7 378.3c-7.5 7.5-19.8 7.5-27.3 0L90.1 226.1c-12.6-12.6-3.7-34.1 14.1-34.1H192V24c0-13.3 10.7-24 24-24zm296 376v112c0 13.3-10.7 24-24 24H24c-13.3 0-24-10.7-24-24V376c0-13.3 10.7-24 24-24h146.7l49 49c20.1 20.1 52.5 20.1 72.6 0l49-49H488c13.3 0 24 10.7 24 24zm-124 88c0-11-9-20-20-20s-20 9-20 20 9 20 20 20 20-9 20-20zm64 0c0-11-9-20-20-20s-20 9-20 20 9 20 20 20 20-9 20-20z",{width:512,height:512}),Gee=R("M416 208H272V64c0-17.67-14.33-32-32-32h-32c-17.67 0-32 14.33-32 32v144H32c-17.67 0-32 14.33-32 32v32c0 17.67 14.33 32 32 32h144v144c0 17.67 14.33 32 32 32h32c17.67 0 32-14.33 32-32V304h144c17.67 0 32-14.33 32-32v-32c0-17.67-14.33-32-32-32z",{width:448,height:512}),Uee=R("M416 208H32c-17.67 0-32 14.33-32 32v32c0 17.67 14.33 32 32 32h384c17.67 0 32-14.33 32-32v-32c0-17.67-14.33-32-32-32z",{width:448,height:512}),KE=R("M173.898 439.404l-166.4-166.4c-9.997-9.997-9.997-26.206 0-36.204l36.203-36.204c9.997-9.998 26.207-9.998 36.204 0L192 312.69 432.095 72.596c9.997-9.997 26.207-9.997 36.204 0l36.203 36.204c9.997 9.997 9.997 26.206 0 36.204l-294.4 294.401c-9.998 9.997-26.207 9.997-36.204-.001z"),Wee=R("M16 132h416c8.837 0 16-7.163 16-16V76c0-8.837-7.163-16-16-16H16C7.163 60 0 67.163 0 76v40c0 8.837 7.163 16 16 16zm0 160h416c8.837 0 16-7.163 16-16v-40c0-8.837-7.163-16-16-16H16c-8.837 0-16 7.163-16 16v40c0 8.837 7.163 16 16 16zm0 160h416c8.837 0 16-7.163 16-16v-40c0-8.837-7.163-16-16-16H16c-8.837 0-16 7.163-16 16v40c0 8.837 7.163 16 16 16z"),yh=R(b("path",{d:"M7.5 10.833 4.167 7.5 7.5 4.167M4.167 7.5h9.166a3.333 3.333 0 0 1 0 6.667H12.5",strokeWidth:"1.25"}),Ee),Eh=R(b("path",{d:"M12.5 10.833 15.833 7.5 12.5 4.167M15.833 7.5H6.667a3.333 3.333 0 1 0 0 6.667H7.5",strokeWidth:"1.25"}),Ee),XE=R("M504 256c0 136.997-111.043 248-248 248S8 392.997 8 256C8 119.083 119.043 8 256 8s248 111.083 248 248zM262.655 90c-54.497 0-89.255 22.957-116.549 63.758-3.536 5.286-2.353 12.415 2.715 16.258l34.699 26.31c5.205 3.947 12.621 3.008 16.665-2.122 17.864-22.658 30.113-35.797 57.303-35.797 20.429 0 45.698 13.148 45.698 32.958 0 14.976-12.363 22.667-32.534 33.976C247.128 238.528 216 254.941 216 296v4c0 6.627 5.373 12 12 12h56c6.627 0 12-5.373 12-12v-1.333c0-28.462 83.186-29.647 83.186-106.667 0-58.002-60.165-102-116.531-102zM256 338c-25.365 0-46 20.635-46 46 0 25.364 20.635 46 46 46s46-20.636 46-46c0-25.365-20.635-46-46-46z",{mirror:!0}),ZE=R(b("path",{d:"M5 12.5a2.5 2.5 0 1 0 0-5 2.5 2.5 0 0 0 0 5ZM15 7.5a2.5 2.5 0 1 0 0-5 2.5 2.5 0 0 0 0 5ZM15 17.5a2.5 2.5 0 1 0 0-5 2.5 2.5 0 0 0 0 5ZM7.25 8.917l5.5-2.834M7.25 11.083l5.5 2.834",strokeWidth:"1.5"}),Ee),Yee=R("M256 32c14.2 0 27.3 7.5 34.5 19.8l216 368c7.3 12.4 7.3 27.7 .2 40.1S486.3 480 472 480H40c-14.3 0-27.6-7.7-34.7-20.1s-7-27.8 .2-40.1l216-368C228.7 39.5 241.8 32 256 32zm0 128c-13.3 0-24 10.7-24 24V296c0 13.3 10.7 24 24 24s24-10.7 24-24V184c0-13.3-10.7-24-24-24zm32 224a32 32 0 1 0 -64 0 32 32 0 1 0 64 0z"),$ee=R("M16 5l-1.42 1.42-1.59-1.59V16h-1.98V4.83L9.42 6.42 8 5l4-4 4 4zm4 5v11c0 1.1-.9 2-2 2H6c-1.11 0-2-.9-2-2V10c0-1.11.89-2 2-2h3v2H6v11h12V10h-3V8h3c1.1 0 2 .89 2 2z",{width:24,height:24}),Vee=R(H("g",{strokeWidth:1.25,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M8 9h-1a2 2 0 0 0 -2 2v8a2 2 0 0 0 2 2h10a2 2 0 0 0 2 -2v-8a2 2 0 0 0 -2 -2h-1"}),b("path",{d:"M12 14v-11"}),b("path",{d:"M9 6l3 -3l3 3"})]}),K),Kee=R(H(We,{children:[b("path",{fill:"currentColor",d:"M40 5.6v6.1l-4.1.7c-8.9 1.4-16.5 6.9-20.6 15C13 32 10.9 43 12.4 43c.4 0 2.4-1.3 4.4-3 5-3.9 12.1-7 18.2-7.7l5-.6v12.8l11.2-11.3L62.5 22 51.2 10.8 40-.5v6.1zm10.2 22.6L44 34.5v-6.8l-6.9.6c-3.9.3-9.8 1.7-13.2 3.1-3.5 1.4-6.5 2.4-6.7 2.2-.9-1 3-7.5 6.4-10.8C28 18.6 34.4 16 40.1 16c3.7 0 3.9-.1 3.9-3.2V9.5l6.2 6.3 6.3 6.2-6.3 6.2z"}),b("path",{stroke:"currentColor",fill:"currentColor",d:"M0 36v20h48v-6.2c0-6 0-6.1-2-4.3-1.1 1-2 2.9-2 4.2V52H4V34c0-17.3-.1-18-2-18s-2 .7-2 20z"})]}),{width:64,height:64}),Xee=R(b("path",{stroke:"currentColor",strokeWidth:"40",fill:"currentColor",d:"M148 560a318 318 0 0 0 522 110 316 316 0 0 0 0-450 316 316 0 0 0-450 0c-11 11-21 22-30 34v4h47c25 0 46 21 46 46s-21 45-46 45H90c-13 0-25-6-33-14-9-9-14-20-14-33V156c0-25 20-45 45-45s45 20 45 45v32l1 1a401 401 0 0 1 623 509l212 212a42 42 0 0 1-59 59L698 757A401 401 0 0 1 65 570a42 42 0 0 1 83-10z"}),{width:1024}),jE=H("g",{strokeWidth:1.5,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M12 10l0 10"}),b("path",{d:"M12 10l4 4"}),b("path",{d:"M12 10l-4 4"}),b("path",{d:"M4 4l16 0"})]}),qE=H("g",{strokeWidth:1.5,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M12 5l0 14"}),b("path",{d:"M16 9l-4 -4"}),b("path",{d:"M8 9l4 -4"})]}),wh=R(qE,K),vh=R(qE,{...K,style:{transform:"rotate(180deg)"}}),Ih=R(jE,K),Th=R(jE,{...K,style:{transform:"rotate(180deg)"}}),Ch=R(H(We,{children:[H("g",{clipPath:"url(#a)",stroke:"currentColor",strokeWidth:"1.25",children:[b("path",{d:"M3.333 3.333h13.334",strokeLinecap:"round",strokeLinejoin:"round"}),b("path",{d:"M13.542 6.458h-.417c-.92 0-1.667.747-1.667 1.667v7.083c0 .92.746 1.667 1.667 1.667h.417c.92 0 1.666-.746 1.666-1.667V8.125c0-.92-.746-1.667-1.666-1.667ZM6.875 6.458h-.417c-.92 0-1.666.747-1.666 1.667v3.75c0 .92.746 1.667 1.666 1.667h.417c.92 0 1.667-.746 1.667-1.667v-3.75c0-.92-.747-1.667-1.667-1.667Z"})]}),b("defs",{children:b("clipPath",{id:"a",children:b("path",{fill:"#fff",d:"M0 0h20v20H0z"})})})]}),Ee),kh=R(H(We,{children:[H("g",{clipPath:"url(#a)",stroke:"currentColor",strokeWidth:"1.25",children:[b("path",{d:"M3.333 16.667h13.334",strokeLinecap:"round",strokeLinejoin:"round"}),b("path",{d:"M6.875 3.125h-.417c-.92 0-1.666.746-1.666 1.667v7.083c0 .92.746 1.667 1.666 1.667h.417c.92 0 1.667-.746 1.667-1.667V4.792c0-.92-.747-1.667-1.667-1.667ZM13.542 5.817h-.417c-.92 0-1.667.747-1.667 1.667v4.391c0 .92.746 1.667 1.667 1.667h.417c.92 0 1.666-.746 1.666-1.667V7.484c0-.92-.746-1.667-1.666-1.667Z"})]}),b("defs",{children:b("clipPath",{id:"a",children:b("path",{fill:"#fff",d:"M0 0h20v20H0z"})})})]}),Ee),Sh=R(H(We,{children:[H("g",{clipPath:"url(#a)",stroke:"currentColor",strokeWidth:"1.25",children:[b("path",{d:"M3.333 3.333v13.334",strokeLinecap:"round",strokeLinejoin:"round"}),b("path",{d:"M15.208 4.792H8.125c-.92 0-1.667.746-1.667 1.666v.417c0 .92.747 1.667 1.667 1.667h7.083c.92 0 1.667-.747 1.667-1.667v-.417c0-.92-.746-1.666-1.667-1.666ZM12.516 11.458H8.125c-.92 0-1.667.746-1.667 1.667v.417c0 .92.747 1.666 1.667 1.666h4.391c.92 0 1.667-.746 1.667-1.666v-.417c0-.92-.746-1.667-1.667-1.667Z"})]}),b("defs",{children:b("clipPath",{id:"a",children:b("path",{fill:"#fff",d:"M0 0h20v20H0z"})})})]}),Ee),Mh=R(H(We,{children:[H("g",{clipPath:"url(#a)",stroke:"currentColor",strokeWidth:"1.25",children:[b("path",{d:"M16.667 3.333v13.334",strokeLinecap:"round",strokeLinejoin:"round"}),b("path",{d:"M11.875 4.792H4.792c-.92 0-1.667.746-1.667 1.666v.417c0 .92.746 1.667 1.667 1.667h7.083c.92 0 1.667-.747 1.667-1.667v-.417c0-.92-.746-1.666-1.667-1.666ZM11.683 11.458H7.292c-.92 0-1.667.746-1.667 1.667v.417c0 .92.746 1.666 1.667 1.666h4.39c.921 0 1.667-.746 1.667-1.666v-.417c0-.92-.746-1.667-1.666-1.667Z"})]}),b("defs",{children:b("clipPath",{id:"a",children:b("path",{fill:"#fff",d:"M0 0h20v20H0z"})})})]}),Ee),JE=R(H(We,{children:[H("g",{clipPath:"url(#a)",stroke:"currentColor",strokeWidth:"1.25",children:[b("path",{d:"M16.667 3.333v13.334M3.333 3.333v13.334",strokeLinecap:"round",strokeLinejoin:"round"}),b("path",{d:"M14.375 10.208v-.416c0-.92-.746-1.667-1.667-1.667H7.292c-.92 0-1.667.746-1.667 1.667v.416c0 .92.746 1.667 1.667 1.667h5.416c.92 0 1.667-.746 1.667-1.667Z"})]}),b("defs",{children:b("clipPath",{id:"a",children:b("path",{fill:"#fff",d:"M0 0h20v20H0z"})})})]}),Ee),QE=R(H(We,{children:[H("g",{clipPath:"url(#a)",stroke:"currentColor",strokeWidth:"1.25",children:[b("path",{d:"M3.333 3.333h13.334M3.333 16.667h13.334",strokeLinecap:"round",strokeLinejoin:"round"}),b("path",{d:"M10.208 5.625h-.416c-.92 0-1.667.746-1.667 1.667v5.416c0 .92.746 1.667 1.667 1.667h.416c.92 0 1.667-.746 1.667-1.667V7.292c0-.92-.746-1.667-1.667-1.667Z"})]}),b("defs",{children:b("clipPath",{id:"a",children:b("path",{fill:"#fff",d:"M0 0h20v20H0z"})})})]}),Ee),Ph=R(H("g",{stroke:"currentColor",strokeWidth:"1.25",children:[b("path",{d:"M1.667 10h2.916",strokeLinecap:"round",strokeLinejoin:"round"}),b("path",{d:"M8.333 10h3.334",strokeLinejoin:"round"}),b("path",{d:"M15.417 10h2.916",strokeLinecap:"round",strokeLinejoin:"round"}),b("path",{d:"M6.875 4.792h-.417c-.92 0-1.666.746-1.666 1.666v7.084c0 .92.746 1.666 1.666 1.666h.417c.92 0 1.667-.746 1.667-1.666V6.458c0-.92-.747-1.666-1.667-1.666ZM13.542 6.458h-.417c-.92 0-1.667.747-1.667 1.667v3.75c0 .92.746 1.667 1.667 1.667h.417c.92 0 1.666-.746 1.666-1.667v-3.75c0-.92-.746-1.667-1.666-1.667Z"})]}),Ee),Ah=R(H("g",{stroke:"currentColor",strokeWidth:"1.25",children:[b("path",{d:"M10 18.333v-2.916",strokeLinecap:"round",strokeLinejoin:"round"}),b("path",{d:"M10 11.667V8.333",strokeLinejoin:"round"}),b("path",{d:"M10 4.583V1.667",strokeLinecap:"round",strokeLinejoin:"round"}),b("path",{d:"M4.792 13.125v.417c0 .92.746 1.666 1.666 1.666h7.084c.92 0 1.666-.746 1.666-1.666v-.417c0-.92-.746-1.667-1.666-1.667H6.458c-.92 0-1.666.746-1.666 1.667ZM6.458 6.458v.417c0 .92.747 1.667 1.667 1.667h3.75c.92 0 1.667-.747 1.667-1.667v-.417c0-.92-.746-1.666-1.667-1.666h-3.75c-.92 0-1.667.746-1.667 1.666Z"})]}),Ee),Em=R(H("g",{strokeWidth:"1.5",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("circle",{cx:"9",cy:"7",r:"4"}),b("path",{d:"M3 21v-2a4 4 0 0 1 4 -4h4a4 4 0 0 1 4 4v2"}),b("path",{d:"M16 3.13a4 4 0 0 1 0 7.75"}),b("path",{d:"M21 21v-2a4 4 0 0 0 -3 -3.85"})]}),K),Zee=R("M256 8C119 8 8 119 8 256s111 248 248 248 248-111 248-248S393 8 256 8zm115.7 272l-176 101c-15.8 8.8-35.7-2.5-35.7-21V152c0-18.4 19.8-29.8 35.7-21l176 107c16.4 9.2 16.4 32.9 0 42z"),ew=R("M256 8C119 8 8 119 8 256s111 248 248 248 248-111 248-248S393 8 256 8zm96 328c0 8.8-7.2 16-16 16H176c-8.8 0-16-7.2-16-16V176c0-8.8 7.2-16 16-16h160c8.8 0 16 7.2 16 16v160z"),Go=R(H(We,{children:[b("g",{clipPath:"url(#a)",stroke:"currentColor",strokeWidth:"1.25",strokeLinecap:"round",strokeLinejoin:"round",children:b("path",{d:"M15 5 5 15M5 5l10 10"})}),b("defs",{children:b("clipPath",{id:"a",children:b("path",{fill:"#fff",d:"M0 0h20v20H0z"})})})]}),Ee),jee=R("M464 0c26.51 0 48 21.49 48 48v288c0 26.51-21.49 48-48 48H176c-26.51 0-48-21.49-48-48V48c0-26.51 21.49-48 48-48h288M176 416c-44.112 0-80-35.888-80-80V128H48c-26.51 0-48 21.49-48 48v288c0 26.51 21.49 48 48 48h288c26.51 0 48-21.49 48-48v-48H176z",{mirror:!0}),qee=R("M11.553 22.894a.998.998 0 00.894 0s3.037-1.516 5.465-4.097C19.616 16.987 21 14.663 21 12V5a1 1 0 00-.649-.936l-8-3a.998.998 0 00-.702 0l-8 3A1 1 0 003 5v7c0 2.663 1.384 4.987 3.088 6.797 2.428 2.581 5.465 4.097 5.465 4.097zm-1.303-8.481l6.644-6.644a.856.856 0 111.212 1.212l-7.25 7.25a.856.856 0 01-1.212 0l-3.75-3.75a.856.856 0 111.212-1.212l3.144 3.144z",{width:24}),Jee=R("M369.9 97.9L286 14C277 5 264.8-.1 252.1-.1H48C21.5 0 0 21.5 0 48v416c0 26.5 21.5 48 48 48h288c26.5 0 48-21.5 48-48V131.9c0-12.7-5.1-25-14.1-34zM332.1 128H256V51.9l76.1 76.1zM48 464V48h160v104c0 13.3 10.7 24 24 24h104v288H48zm32-48h224V288l-23.5-23.5c-4.7-4.7-12.3-4.7-17 0L176 352l-39.5-39.5c-4.7-4.7-12.3-4.7-17 0L80 352v64zm48-240c-26.5 0-48 21.5-48 48s21.5 48 48 48 48-21.5 48-48-21.5-48-48-48z",{width:384,height:512}),Lh=_t.memo(({theme:e})=>R(H(We,{children:[b("path",{d:"M25 26H111V111H25",fill:pn(e)}),b("path",{d:"M25 111C25 80.2068 25 49.4135 25 26M25 26C48.6174 26 72.2348 26 111 26H25ZM25 26C53.3671 26 81.7343 26 111 26H25ZM111 26C111 52.303 111 78.606 111 111V26ZM111 26C111 51.2947 111 76.5893 111 111V26ZM111 111C87.0792 111 63.1585 111 25 111H111ZM111 111C87.4646 111 63.9293 111 25 111H111ZM25 111C25 81.1514 25 51.3028 25 26V111Z",stroke:pn(e),strokeWidth:"2"}),b("path",{d:"M100 100H160V160H100",fill:pn(e)}),b("path",{d:"M100 160C100 144.106 100 128.211 100 100M100 100C117.706 100 135.412 100 160 100H100ZM100 100C114.214 100 128.428 100 160 100H100ZM160 100C160 120.184 160 140.369 160 160V100ZM160 100C160 113.219 160 126.437 160 160V100ZM160 160C145.534 160 131.068 160 100 160H160ZM160 160C143.467 160 126.934 160 100 160H160ZM100 160C100 143.661 100 127.321 100 100V160Z",stroke:pn(e),strokeWidth:"2"}),H("g",{fill:SE(e),stroke:pn(e),strokeWidth:"6",children:[b("rect",{x:"2.5",y:"2.5",width:"30",height:"30"}),b("rect",{x:"2.5",y:"149.5",width:"30",height:"30"}),b("rect",{x:"147.5",y:"149.5",width:"30",height:"30"}),b("rect",{x:"147.5",y:"2.5",width:"30",height:"30"})]})]}),{width:182,height:182,mirror:!0})),_h=_t.memo(({theme:e})=>R(H(We,{children:[b("path",{d:"M25 26H111V111H25",fill:pn(e)}),b("path",{d:"M25 111C25 80.2068 25 49.4135 25 26M25 26C48.6174 26 72.2348 26 111 26H25ZM25 26C53.3671 26 81.7343 26 111 26H25ZM111 26C111 52.303 111 78.606 111 111V26ZM111 26C111 51.2947 111 76.5893 111 111V26ZM111 111C87.0792 111 63.1585 111 25 111H111ZM111 111C87.4646 111 63.9293 111 25 111H111ZM25 111C25 81.1514 25 51.3028 25 26V111Z",stroke:pn(e),strokeWidth:"2"}),b("path",{d:"M100 100H160V160H100",fill:pn(e)}),b("path",{d:"M100 160C100 144.106 100 128.211 100 100M100 100C117.706 100 135.412 100 160 100H100ZM100 100C114.214 100 128.428 100 160 100H100ZM160 100C160 120.184 160 140.369 160 160V100ZM160 100C160 113.219 160 126.437 160 160V100ZM160 160C145.534 160 131.068 160 100 160H160ZM160 160C143.467 160 126.934 160 100 160H160ZM100 160C100 143.661 100 127.321 100 100V160Z",stroke:pn(e),strokeWidth:"2"}),H("g",{fill:SE(e),stroke:pn(e),strokeWidth:"6",children:[b("rect",{x:"2.5",y:"2.5",width:"30",height:"30"}),b("rect",{x:"78.5",y:"149.5",width:"30",height:"30"}),b("rect",{x:"147.5",y:"149.5",width:"30",height:"30"}),b("rect",{x:"147.5",y:"78.5",width:"30",height:"30"}),b("rect",{x:"105.5",y:"2.5",width:"30",height:"30"}),b("rect",{x:"2.5",y:"102.5",width:"30",height:"30"})]})]}),{width:182,height:182,mirror:!0})),tw=R(b("g",{strokeWidth:1.25,children:b("path",{d:"M5.879 2.625h8.242a3.27 3.27 0 0 1 3.254 3.254v8.242a3.27 3.27 0 0 1-3.254 3.254H5.88a3.27 3.27 0 0 1-3.254-3.254V5.88A3.27 3.27 0 0 1 5.88 2.626l-.001-.001ZM4.518 16.118l7.608-12.83m.198 13.934 5.051-9.897M2.778 9.675l9.348-6.387m-7.608 12.83 12.857-8.793"})}),Ee),ow=R(H(We,{children:[b("path",{d:"M5.879 2.625h8.242a3.254 3.254 0 0 1 3.254 3.254v8.242a3.254 3.254 0 0 1-3.254 3.254H5.88a3.254 3.254 0 0 1-3.254-3.254V5.88a3.254 3.254 0 0 1 3.254-3.254Z",stroke:"currentColor",strokeWidth:"1.25"}),b("mask",{id:"FillHachureIcon",style:{maskType:"alpha"},maskUnits:"userSpaceOnUse",x:2,y:2,width:16,height:16,children:b("path",{d:"M5.879 2.625h8.242a3.254 3.254 0 0 1 3.254 3.254v8.242a3.254 3.254 0 0 1-3.254 3.254H5.88a3.254 3.254 0 0 1-3.254-3.254V5.88a3.254 3.254 0 0 1 3.254-3.254Z",fill:"currentColor",stroke:"currentColor",strokeWidth:"1.25"})}),b("g",{mask:"url(#FillHachureIcon)",children:b("path",{d:"M2.258 15.156 15.156 2.258M7.324 20.222 20.222 7.325m-20.444 5.35L12.675-.222m-8.157 18.34L17.416 5.22",stroke:"currentColor",strokeWidth:"1.25",strokeLinecap:"round",strokeLinejoin:"round"})})]}),Ee),nw=R(H(We,{children:[H("g",{clipPath:"url(#a)",children:[b("path",{d:"M5.879 2.625h8.242a3.254 3.254 0 0 1 3.254 3.254v8.242a3.254 3.254 0 0 1-3.254 3.254H5.88a3.254 3.254 0 0 1-3.254-3.254V5.88a3.254 3.254 0 0 1 3.254-3.254Z",stroke:"currentColor",strokeWidth:"1.25"}),b("mask",{id:"FillCrossHatchIcon",style:{maskType:"alpha"},maskUnits:"userSpaceOnUse",x:-1,y:-1,width:22,height:22,children:b("path",{d:"M2.426 15.044 15.044 2.426M7.383 20 20 7.383M0 12.617 12.617 0m-7.98 17.941L17.256 5.324m-2.211 12.25L2.426 4.956M20 12.617 7.383 0m5.234 20L0 7.383m17.941 7.98L5.324 2.745",stroke:"currentColor",strokeWidth:"1.25",strokeLinecap:"round",strokeLinejoin:"round"})}),b("g",{mask:"url(#FillCrossHatchIcon)",children:b("path",{d:"M14.121 2H5.88A3.879 3.879 0 0 0 2 5.879v8.242A3.879 3.879 0 0 0 5.879 18h8.242A3.879 3.879 0 0 0 18 14.121V5.88A3.879 3.879 0 0 0 14.121 2Z",fill:"currentColor"})})]}),b("defs",{children:b("clipPath",{id:"a",children:b("path",{fill:"#fff",d:"M0 0h20v20H0z"})})})]}),Ee),rw=R(H(We,{children:[b("g",{clipPath:"url(#a)",children:b("path",{d:"M4.91 2.625h10.18a2.284 2.284 0 0 1 2.285 2.284v10.182a2.284 2.284 0 0 1-2.284 2.284H4.909a2.284 2.284 0 0 1-2.284-2.284V4.909a2.284 2.284 0 0 1 2.284-2.284Z",stroke:"currentColor",strokeWidth:"1.25"})}),b("defs",{children:b("clipPath",{id:"a",children:b("path",{fill:"#fff",d:"M0 0h20v20H0z"})})})]}),{...Ee,fill:"currentColor"}),Dh=R(b(We,{children:b("path",{d:"M4.167 10h11.666",stroke:"currentColor",strokeWidth:"1.25",strokeLinecap:"round",strokeLinejoin:"round"})}),Ee),aw=R(b("path",{d:"M5 10h10",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round"}),Ee),iw=R(b("path",{d:"M5 10h10",stroke:"currentColor",strokeWidth:"3.75",strokeLinecap:"round",strokeLinejoin:"round"}),Ee),Qee=_t.memo(({theme:e})=>R(b("path",{d:"M6 10H34",stroke:pn(e),strokeWidth:2,fill:"none",strokeLinecap:"round"}),{width:40,height:20})),sw=R(H("g",{strokeWidth:"2",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M5 12h2"}),b("path",{d:"M17 12h2"}),b("path",{d:"M11 12h2"})]}),K),lw=R(H("g",{strokeWidth:"2",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M4 12v.01"}),b("path",{d:"M8 12v.01"}),b("path",{d:"M12 12v.01"}),b("path",{d:"M16 12v.01"}),b("path",{d:"M20 12v.01"})]}),K),cw=R(b("path",{d:"M2.5 12.038c1.655-.885 5.9-3.292 8.568-4.354 2.668-1.063.101 2.821 1.32 3.104 1.218.283 5.112-1.814 5.112-1.814",strokeWidth:"1.25"}),Ee),dw=R(b("path",{d:"M2.5 12.563c1.655-.886 5.9-3.293 8.568-4.355 2.668-1.062.101 2.822 1.32 3.105 1.218.283 5.112-1.814 5.112-1.814m-13.469 2.23c2.963-1.586 6.13-5.62 7.468-4.998 1.338.623-1.153 4.11-.132 5.595 1.02 1.487 6.133-1.43 6.133-1.43",strokeWidth:"1.25"}),Ee),mw=R(b("path",{d:"M2.5 11.936c1.737-.879 8.627-5.346 10.42-5.268 1.795.078-.418 5.138.345 5.736.763.598 3.53-1.789 4.235-2.147M2.929 9.788c1.164-.519 5.47-3.28 6.987-3.114 1.519.165 1 3.827 2.121 4.109 1.122.281 3.839-2.016 4.606-2.42",strokeWidth:"1.25"}),Ee),pw=R(H("svg",{strokeWidth:"1.5",children:[b("path",{d:"M3.33334 9.99998V6.66665C3.33334 6.04326 3.33403 4.9332 3.33539 3.33646C4.95233 3.33436 6.06276 3.33331 6.66668 3.33331H10"}),b("path",{d:"M13.3333 3.33331V3.34331"}),b("path",{d:"M16.6667 3.33331V3.34331"}),b("path",{d:"M16.6667 6.66669V6.67669"}),b("path",{d:"M16.6667 10V10.01"}),b("path",{d:"M3.33334 13.3333V13.3433"}),b("path",{d:"M16.6667 13.3333V13.3433"}),b("path",{d:"M3.33334 16.6667V16.6767"}),b("path",{d:"M6.66666 16.6667V16.6767"}),b("path",{d:"M10 16.6667V16.6767"}),b("path",{d:"M13.3333 16.6667V16.6767"}),b("path",{d:"M16.6667 16.6667V16.6767"})]}),Ee),uw=R(H("g",{strokeWidth:"1.5",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M4 12v-4a4 4 0 0 1 4 -4h4"}),b("line",{x1:"16",y1:"4",x2:"16",y2:"4.01"}),b("line",{x1:"20",y1:"4",x2:"20",y2:"4.01"}),b("line",{x1:"20",y1:"8",x2:"20",y2:"8.01"}),b("line",{x1:"20",y1:"12",x2:"20",y2:"12.01"}),b("line",{x1:"4",y1:"16",x2:"4",y2:"16.01"}),b("line",{x1:"20",y1:"16",x2:"20",y2:"16.01"}),b("line",{x1:"4",y1:"20",x2:"4",y2:"20.01"}),b("line",{x1:"8",y1:"20",x2:"8",y2:"20.01"}),b("line",{x1:"12",y1:"20",x2:"12",y2:"20.01"}),b("line",{x1:"16",y1:"20",x2:"16",y2:"20.01"}),b("line",{x1:"20",y1:"20",x2:"20",y2:"20.01"})]}),K),gw=_t.memo(({flip:e=!1})=>R(H("g",{transform:e?"translate(24, 0) scale(-1, 1)":"",stroke:"currentColor",opacity:.3,strokeWidth:2,children:[b("path",{d:"M12 12l-9 0"}),b("path",{d:"M21 9l-6 6"}),b("path",{d:"M21 15l-6 -6"})]}),K)),hw=_t.memo(({flip:e=!1})=>R(H("g",{transform:e?"translate(40, 0) scale(-1, 1)":"",stroke:"currentColor",strokeWidth:2,fill:"none",children:[b("path",{d:"M34 10H6M34 10L27 5M34 10L27 15"}),b("path",{d:"M27.5 5L34.5 10L27.5 15"})]}),{width:40,height:20})),fw=_t.memo(({flip:e=!1})=>R(H("g",{stroke:"currentColor",fill:"currentColor",transform:e?"translate(40, 0) scale(-1, 1)":"",children:[b("path",{d:"M32 10L6 10",strokeWidth:2}),b("circle",{r:"4",transform:"matrix(-1 0 0 1 30 10)"})]}),{width:40,height:20})),bw=_t.memo(({flip:e=!1})=>R(H("g",{stroke:"currentColor",fill:"none",transform:e?"translate(40, 0) scale(-1, 1)":"",strokeWidth:2,children:[b("path",{d:"M26 10L6 10"}),b("circle",{r:"4",transform:"matrix(-1 0 0 1 30 10)"})]}),{width:40,height:20})),xw=_t.memo(({flip:e=!1})=>R(b("g",{transform:e?"translate(40, 0) scale(-1, 1)":"",children:b("path",{d:"M34 10H5.99996M34 10L34 5M34 10L34 15",stroke:"currentColor",strokeWidth:2,fill:"none"})}),{width:40,height:20})),yw=_t.memo(({flip:e=!1})=>R(H("g",{stroke:"currentColor",fill:"currentColor",transform:e?"translate(40, 0) scale(-1, 1)":"",children:[b("path",{d:"M32 10L6 10",strokeWidth:2}),b("path",{d:"M27.5 5.5L34.5 10L27.5 14.5L27.5 5.5"})]}),{width:40,height:20})),Ew=_t.memo(({flip:e=!1})=>R(H("g",{stroke:"currentColor",fill:"none",transform:e?"translate(40, 0) scale(-1, 1)":"",strokeWidth:2,strokeLinejoin:"round",children:[b("path",{d:"M6,9.5H27"}),b("path",{d:"M27,5L34,10L27,14Z",fill:"none"})]}),{width:40,height:20})),ww=_t.memo(({flip:e=!1})=>R(H("g",{stroke:"currentColor",fill:"currentColor",transform:e?"translate(40, 0) scale(-1, 1)":"",strokeLinejoin:"round",strokeWidth:2,children:[b("path",{d:"M6,9.5H20"}),b("path",{d:"M27,5L34,10L27,14L20,9.5Z"})]}),{width:40,height:20})),vw=_t.memo(({flip:e=!1})=>R(H("g",{stroke:"currentColor",fill:"none",transform:e?"translate(40, 0) scale(-1, 1)":"",strokeLinejoin:"round",strokeWidth:2,children:[b("path",{d:"M6,9.5H20"}),b("path",{d:"M27,5L34,10L27,14L20,9.5Z"})]}),{width:40,height:20})),Iw=_t.memo(({flip:e=!1})=>R(b("g",{stroke:"currentColor",fill:"none",transform:e?"":"translate(40, 0) scale(-1, 1)",strokeLinejoin:"round",strokeWidth:2,children:b("path",{d:"M34,10 H6 M15,10 L7,5 M15,10 L7,15"})}),{width:40,height:20})),Tw=_t.memo(({flip:e=!1})=>R(b("g",{stroke:"currentColor",fill:"none",transform:e?"":"translate(40, 0) scale(-1, 1)",strokeLinejoin:"round",strokeWidth:2,children:b("path",{d:"M34,10 H6 M15,10 L15,15 L15,5"})}),{width:40,height:20})),Cw=_t.memo(({flip:e=!1})=>R(b("g",{stroke:"currentColor",fill:"none",transform:e?"":"translate(40, 0) scale(-1, 1)",strokeLinejoin:"round",strokeWidth:2,children:b("path",{d:"M34,10 H6 M15,10 L15,16 L15,4 M15,10 L7,5 M15,10 L7,15"})}),{width:40,height:20})),kw=R(H(We,{children:[b("g",{clipPath:"url(#a)",children:b("path",{d:"M14.167 6.667a3.333 3.333 0 0 0-3.334-3.334H9.167a3.333 3.333 0 0 0 0 6.667h1.666a3.333 3.333 0 0 1 0 6.667H9.167a3.333 3.333 0 0 1-3.334-3.334",stroke:"currentColor",strokeWidth:"1.25",strokeLinecap:"round",strokeLinejoin:"round"})}),b("defs",{children:b("clipPath",{id:"a",children:b("path",{fill:"#fff",d:"M0 0h20v20H0z"})})})]}),Ee),Sw=R(H(We,{children:[b("g",{clipPath:"url(#a)",children:b("path",{d:"M5 16.667V3.333L10 15l5-11.667v13.334",stroke:"currentColor",strokeWidth:"1.25",strokeLinecap:"round",strokeLinejoin:"round"})}),b("defs",{children:b("clipPath",{id:"a",children:b("path",{fill:"#fff",d:"M0 0h20v20H0z"})})})]}),Ee),Mw=R(H(We,{children:[b("g",{clipPath:"url(#a)",children:b("path",{d:"M5.833 3.333v13.334h8.334",stroke:"currentColor",strokeWidth:"1.25",strokeLinecap:"round",strokeLinejoin:"round"})}),b("defs",{children:b("clipPath",{id:"a",children:b("path",{fill:"#fff",d:"M0 0h20v20H0z"})})})]}),Ee),Pw=R(b(We,{children:b("path",{d:"m1.667 3.333 6.666 13.334M8.333 3.333 1.667 16.667M11.667 3.333v13.334h6.666",stroke:"currentColor",strokeWidth:"1.25",strokeLinecap:"round",strokeLinejoin:"round"})}),Ee),Va=R(H("g",{strokeWidth:1.25,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M3 7v-2h13v2"}),b("path",{d:"M10 5v14"}),b("path",{d:"M12 19h-4"}),b("path",{d:"M15 13v-1h6v1"}),b("path",{d:"M18 12v7"}),b("path",{d:"M17 19h2"})]}),K),Aw=R(b(We,{children:H("g",{stroke:"currentColor",strokeWidth:"1.25",strokeLinecap:"round",strokeLinejoin:"round",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M7 12h10"}),b("path",{d:"M7 5v14"}),b("path",{d:"M17 5v14"}),b("path",{d:"M15 19h4"}),b("path",{d:"M15 5h4"}),b("path",{d:"M5 19h4"}),b("path",{d:"M5 5h4"})]})}),K),ac=R(b(We,{children:b("g",{stroke:"currentColor",strokeWidth:"1.25",strokeLinecap:"round",strokeLinejoin:"round",children:b("path",{d:"M5.833 16.667v-10a3.333 3.333 0 0 1 3.334-3.334h1.666a3.333 3.333 0 0 1 3.334 3.334v10M5.833 10.833h8.334"})})}),Ee),Rh=R(H("g",{strokeWidth:"1.5",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M7 8l-4 4l4 4"}),b("path",{d:"M17 8l4 4l-4 4"}),b("path",{d:"M14 4l-4 16"})]}),K),wm=Rh,Lw=R(H("g",{stroke:"currentColor",fill:"none",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("line",{x1:"4",y1:"8",x2:"20",y2:"8"}),b("line",{x1:"4",y1:"12",x2:"12",y2:"12"}),b("line",{x1:"4",y1:"16",x2:"16",y2:"16"})]}),K),_w=R(H("g",{stroke:"currentColor",fill:"none",strokeLinecap:"round",strokeLinejoin:"round",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("line",{x1:"4",y1:"8",x2:"20",y2:"8"}),b("line",{x1:"8",y1:"12",x2:"16",y2:"12"}),b("line",{x1:"6",y1:"16",x2:"18",y2:"16"})]}),K),Dw=R(H("g",{stroke:"currentColor",fill:"none",strokeLinecap:"round",strokeLinejoin:"round",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("line",{x1:"4",y1:"8",x2:"20",y2:"8"}),b("line",{x1:"10",y1:"12",x2:"20",y2:"12"}),b("line",{x1:"8",y1:"16",x2:"20",y2:"16"})]}),K),Rw=_t.memo(({theme:e})=>R(H("g",{strokeWidth:"1.5",stroke:"currentColor",fill:"none",strokeLinecap:"round",strokeLinejoin:"round",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("line",{x1:"4",y1:"4",x2:"20",y2:"4"}),b("rect",{x:"9",y:"8",width:"6",height:"12",rx:"2"})]}),K)),Nw=_t.memo(({theme:e})=>R(H("g",{strokeWidth:"2",stroke:"currentColor",fill:"none",strokeLinecap:"round",strokeLinejoin:"round",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("line",{x1:"4",y1:"20",x2:"20",y2:"20"}),b("rect",{x:"9",y:"4",width:"6",height:"12",rx:"2"})]}),K)),Bw=_t.memo(({theme:e})=>R(H("g",{strokeWidth:"1.5",stroke:"currentColor",fill:"none",strokeLinecap:"round",strokeLinejoin:"round",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("line",{x1:"4",y1:"12",x2:"9",y2:"12"}),b("line",{x1:"15",y1:"12",x2:"20",y2:"12"}),b("rect",{x:"9",y:"6",width:"6",height:"12",rx:"2"})]}),K)),vm=R(H("g",{children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M21 19h-18l9 -15"}),b("path",{d:"M20.615 15.171h.015"}),b("path",{d:"M19.515 11.771h.015"}),b("path",{d:"M17.715 8.671h.015"}),b("path",{d:"M15.415 5.971h.015"})]}),K),Fw=R(b("path",{d:"M537.6 226.6c4.1-10.7 6.4-22.4 6.4-34.6 0-53-43-96-96-96-19.7 0-38.1 6-53.3 16.2C367 64.2 315.3 32 256 32c-88.4 0-160 71.6-160 160 0 2.7.1 5.4.2 8.1C40.2 219.8 0 273.2 0 336c0 79.5 64.5 144 144 144h368c70.7 0 128-57.3 128-128 0-61.9-44-113.6-102.4-125.4zM393.4 288H328v112c0 8.8-7.2 16-16 16h-48c-8.8 0-16-7.2-16-16V288h-65.4c-14.3 0-21.4-17.2-11.3-27.3l105.4-105.4c6.2-6.2 16.4-6.2 22.6 0l105.4 105.4c10.1 10.1 2.9 27.3-11.3 27.3z",fill:"currentColor"}),{width:640,height:512}),ete=R(b("path",{d:"M480 416C497.7 416 512 430.3 512 448C512 465.7 497.7 480 480 480H150.6C133.7 480 117.4 473.3 105.4 461.3L25.37 381.3C.3786 356.3 .3786 315.7 25.37 290.7L258.7 57.37C283.7 32.38 324.3 32.38 349.3 57.37L486.6 194.7C511.6 219.7 511.6 260.3 486.6 285.3L355.9 416H480zM265.4 416L332.7 348.7L195.3 211.3L70.63 336L150.6 416L265.4 416z"})),as=R(H("g",{strokeWidth:1.25,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M8 13v-7.5a1.5 1.5 0 0 1 3 0v6.5"}),b("path",{d:"M11 5.5v-2a1.5 1.5 0 1 1 3 0v8.5"}),b("path",{d:"M14 5.5a1.5 1.5 0 0 1 3 0v6.5"}),b("path",{d:"M17 7.5a1.5 1.5 0 0 1 3 0v8.5a6 6 0 0 1 -6 6h-2h.208a6 6 0 0 1 -5.012 -2.7a69.74 69.74 0 0 1 -.196 -.3c-.312 -.479 -1.407 -2.388 -3.286 -5.728a1.5 1.5 0 0 1 .536 -2.022a1.867 1.867 0 0 1 2.28 .28l1.47 1.47"})]}),K),Nh=R(H(We,{children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M4 17v2a2 2 0 0 0 2 2h12a2 2 0 0 0 2 -2v-2"}),b("path",{d:"M7 11l5 5l5 -5"}),b("path",{d:"M12 4l0 12"})]}),K),is=R(H(We,{children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M8 8m0 2a2 2 0 0 1 2 -2h8a2 2 0 0 1 2 2v8a2 2 0 0 1 -2 2h-8a2 2 0 0 1 -2 -2z"}),b("path",{d:"M16 8v-2a2 2 0 0 0 -2 -2h-8a2 2 0 0 0 -2 2v8a2 2 0 0 0 2 2h2"})]}),K),Ow=R(H("g",{strokeWidth:1.25,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M7 17m-3 0a3 3 0 1 0 6 0a3 3 0 1 0 -6 0"}),b("path",{d:"M17 17m-3 0a3 3 0 1 0 6 0a3 3 0 1 0 -6 0"}),b("path",{d:"M9.15 14.85l8.85 -10.85"}),b("path",{d:"M6 4l8.85 10.85"})]}),K),zw=R(H(We,{children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M12 12m-9 0a9 9 0 1 0 18 0a9 9 0 1 0 -18 0"}),b("path",{d:"M12 17l0 .01"}),b("path",{d:"M12 13.5a1.5 1.5 0 0 1 1 -1.5a2.6 2.6 0 1 0 -3 -4"})]}),K),tte=R(H(We,{children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M7 4v16l13 -8z"})]}),K),ote=R(H(We,{children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M17 4h-10a3 3 0 0 0 -3 3v10a3 3 0 0 0 3 3h10a3 3 0 0 0 3 -3v-10a3 3 0 0 0 -3 -3z",strokeWidth:"0",fill:"currentColor"})]}),K),Hw=R(H(We,{children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M5 12l5 5l10 -10"})]}),K),Im=R(H(We,{children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M10.24 3.957l-8.422 14.06a1.989 1.989 0 0 0 1.7 2.983h16.845a1.989 1.989 0 0 0 1.7 -2.983l-8.423 -14.06a1.989 1.989 0 0 0 -3.4 0z"}),b("path",{d:"M12 9v4"}),b("path",{d:"M12 17h.01"})]}),K),Gw=R(H("g",{strokeWidth:1.25,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M11 7l6 6"}),b("path",{d:"M4 16l11.7 -11.7a1 1 0 0 1 1.4 0l2.6 2.6a1 1 0 0 1 0 1.4l-11.7 11.7h-4v-4z"})]}),K),ic=R(H("g",{strokeWidth:1.5,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M12 3l-4 7h8z"}),b("path",{d:"M17 17m-3 0a3 3 0 1 0 6 0a3 3 0 1 0 -6 0"}),b("path",{d:"M4 14m0 1a1 1 0 0 1 1 -1h4a1 1 0 0 1 1 1v4a1 1 0 0 1 -1 1h-4a1 1 0 0 1 -1 -1z"})]}),K),On=R(H("g",{strokeWidth:1.5,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M4 7l16 0"}),b("path",{d:"M4 17l16 0"}),b("path",{d:"M7 4l0 16"}),b("path",{d:"M17 4l0 16"})]}),K),Uw=R(H("g",{strokeWidth:1.5,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),b("circle",{cx:"8.5",cy:"8.5",r:"1.5",fill:"currentColor",stroke:"none"}),b("path",{d:"M3 16l5-5c.928-.893 2.072-.893 3 0l5 5"}),b("path",{d:"M14 14l1-1c.928-.893 2.072-.893 3 0l3 3"}),b("path",{d:"M17.5 4.5l0 3m-1.5-1.5l3 0",strokeWidth:"1.5",strokeLinecap:"round"})]}),K),ss=R(b("path",{fill:"currentColor",d:"M407.48,111.18C335.587,108.103 269.573,152.338 245.08,220C220.587,152.338 154.573,108.103 82.68,111.18C80.285,168.229 107.577,222.632 154.74,254.82C178.908,271.419 193.35,298.951 193.27,328.27L193.27,379.13L296.9,379.13L296.9,328.27C296.816,298.953 311.255,271.42 335.42,254.82C382.596,222.644 409.892,168.233 407.48,111.18Z"})),Ww=R(H("g",{strokeWidth:"1.5",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M20 11a8.1 8.1 0 0 0 -15.5 -2m-.5 -4v4h4"}),b("path",{d:"M4 13a8.1 8.1 0 0 0 15.5 2m.5 4v-4h-4"})]}),K),Yw=R(H("g",{children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M6 10l-2 1l8 4l8 -4l-2 -1"}),b("path",{d:"M4 15l8 4l8 -4"}),b("path",{d:"M12 4v7"}),b("path",{d:"M15 8l-3 3l-3 -3"})]}),K),Gr=R(H("g",{strokeWidth:"1.25",children:[b("path",{d:"M4.16602 10H15.8327"}),b("path",{d:"M12.5 13.3333L15.8333 10"}),b("path",{d:"M12.5 6.66666L15.8333 9.99999"})]}),Ee),zn=R(H("g",{fill:"none",stroke:"currentColor",strokeWidth:"1.25",strokeLinecap:"round",strokeLinejoin:"round",transform:"rotate(90 10 10)",children:[b("path",{clipRule:"evenodd",d:"m9.644 13.69 7.774-7.773a2.357 2.357 0 0 0-3.334-3.334l-7.773 7.774L8 12l1.643 1.69Z"}),b("path",{d:"m13.25 3.417 3.333 3.333M10 10l2-2M5 15l3-3M2.156 17.894l1-1M5.453 19.029l-.144-1.407M2.377 11.887l.866 1.118M8.354 17.273l-1.194-.758M.953 14.652l1.408.13"})]}),20),Ka=R(H("g",{stroke:"currentColor",fill:"none",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z"}),b("path",{d:"M6 21l15 -15l-3 -3l-15 15l3 3"}),b("path",{d:"M15 6l3 3"}),b("path",{d:"M9 3a2 2 0 0 0 2 2a2 2 0 0 0 -2 2a2 2 0 0 0 -2 -2a2 2 0 0 0 2 -2"}),b("path",{d:"M19 13a2 2 0 0 0 2 2a2 2 0 0 0 -2 2a2 2 0 0 0 -2 -2a2 2 0 0 0 2 -2"})]}),K),nte=R(H("g",{strokeWidth:1.25,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z"}),b("path",{d:"M6 21l15 -15l-3 -3l-15 15l3 3"}),b("path",{d:"M15 6l3 3"}),b("path",{d:"M9 3a2 2 0 0 0 2 2a2 2 0 0 0 -2 2a2 2 0 0 0 -2 -2a2 2 0 0 0 2 -2"}),b("path",{d:"M19 13a2 2 0 0 0 2 2a2 2 0 0 0 -2 2a2 2 0 0 0 -2 -2a2 2 0 0 0 2 -2"})]}),K),rte=R(H("g",{stroke:"currentColor",fill:"none",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M11.217 19.384a3.501 3.501 0 0 0 6.783 -1.217v-5.167l-6 -3.35"}),b("path",{d:"M5.214 15.014a3.501 3.501 0 0 0 4.446 5.266l4.34 -2.534v-6.946"}),b("path",{d:"M6 7.63c-1.391 -.236 -2.787 .395 -3.534 1.689a3.474 3.474 0 0 0 1.271 4.745l4.263 2.514l6 -3.348"}),b("path",{d:"M12.783 4.616a3.501 3.501 0 0 0 -6.783 1.217v5.067l6 3.45"}),b("path",{d:"M18.786 8.986a3.501 3.501 0 0 0 -4.446 -5.266l-4.34 2.534v6.946"}),b("path",{d:"M18 16.302c1.391 .236 2.787 -.395 3.534 -1.689a3.474 3.474 0 0 0 -1.271 -4.745l-4.308 -2.514l-5.955 3.42"})]}),K),$w=R(H("g",{stroke:"currentColor",fill:"none",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M4 8v-2a2 2 0 0 1 2 -2h2"}),b("path",{d:"M4 16v2a2 2 0 0 0 2 2h2"}),b("path",{d:"M16 4h2a2 2 0 0 1 2 2v2"}),b("path",{d:"M16 20h2a2 2 0 0 0 2 -2v-2"})]}),K),ls=R(H("g",{stroke:"currentColor",fill:"none",strokeWidth:1.5,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M10 12a2 2 0 1 0 4 0a2 2 0 0 0 -4 0"}),b("path",{d:"M21 12c-2.4 4 -5.4 6 -9 6c-3.6 0 -6.6 -2 -9 -6c2.4 -4 5.4 -6 9 -6c3.6 0 6.6 2 9 6"})]}),K),Vw=R(H("g",{stroke:"currentColor",fill:"none",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M10.585 10.587a2 2 0 0 0 2.829 2.828"}),b("path",{d:"M16.681 16.673a8.717 8.717 0 0 1 -4.681 1.327c-3.6 0 -6.6 -2 -9 -6c1.272 -2.12 2.712 -3.678 4.32 -4.674m2.86 -1.146a9.055 9.055 0 0 1 1.82 -.18c3.6 0 6.6 2 9 6c-.666 1.11 -1.379 2.067 -2.138 2.87"}),b("path",{d:"M3 3l18 18"})]}),K),Kw=R(H("g",{stroke:"currentColor",fill:"none",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M15.5 13a3.5 3.5 0 0 0 -3.5 3.5v1a3.5 3.5 0 0 0 7 0v-1.8"}),b("path",{d:"M8.5 13a3.5 3.5 0 0 1 3.5 3.5v1a3.5 3.5 0 0 1 -7 0v-1.8"}),b("path",{d:"M17.5 16a3.5 3.5 0 0 0 0 -7h-.5"}),b("path",{d:"M19 9.3v-2.8a3.5 3.5 0 0 0 -7 0"}),b("path",{d:"M6.5 16a3.5 3.5 0 0 1 0 -7h.5"}),b("path",{d:"M5 9.3v-2.8a3.5 3.5 0 0 1 7 0v10"})]}),K),Xw=R(H("g",{strokeWidth:1.25,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M15.5 13a3.5 3.5 0 0 0 -3.5 3.5v1a3.5 3.5 0 0 0 7 0v-1.8"}),b("path",{d:"M8.5 13a3.5 3.5 0 0 1 3.5 3.5v1a3.5 3.5 0 0 1 -7 0v-1.8"}),b("path",{d:"M17.5 16a3.5 3.5 0 0 0 0 -7h-.5"}),b("path",{d:"M19 9.3v-2.8a3.5 3.5 0 0 0 -7 0"}),b("path",{d:"M6.5 16a3.5 3.5 0 0 1 0 -7h.5"}),b("path",{d:"M5 9.3v-2.8a3.5 3.5 0 0 1 7 0v10"})]}),K),Mo=R(H("g",{strokeWidth:1.5,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M10 10m-7 0a7 7 0 1 0 14 0a7 7 0 1 0 -14 0"}),b("path",{d:"M21 21l-6 -6"})]}),K),Zw=R(H("g",{strokeWidth:1.5,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M20.984 12.53a9 9 0 1 0 -7.552 8.355"}),b("path",{d:"M12 7v5l3 3"}),b("path",{d:"M19 16l-2 3h4l-2 3"})]}),K),jw=R(H("g",{strokeWidth:1.5,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M12 8l0 4l2 2"}),b("path",{d:"M3.05 11a9 9 0 1 1 .5 4m-.5 5v-5h5"})]}),K),qw=R(H("g",{strokeWidth:1.5,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M9 2m0 3a3 3 0 0 1 3 -3h0a3 3 0 0 1 3 3v5a3 3 0 0 1 -3 3h0a3 3 0 0 1 -3 -3z"}),b("path",{d:"M5 10a7 7 0 0 0 14 0"}),b("path",{d:"M8 21l8 0"}),b("path",{d:"M12 17l0 4"})]}),K),Jw=R(H("g",{strokeWidth:1.5,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M3 3l18 18"}),b("path",{d:"M9 5a3 3 0 0 1 6 0v5a3 3 0 0 1 -.13 .874m-2 2a3 3 0 0 1 -3.87 -2.872v-1"}),b("path",{d:"M5 10a7 7 0 0 0 10.846 5.85m2 -2a6.967 6.967 0 0 0 1.152 -3.85"}),b("path",{d:"M8 21l8 0"}),b("path",{d:"M12 17l0 4"})]}),K),sc=R(H("g",{strokeWidth:1.25,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M13 3l0 7l6 0l-8 11l0 -7l-6 0l8 -11"})]}),K),Qw=R(H("g",{children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M8 8m0 1a1 1 0 0 1 1 -1h6a1 1 0 0 1 1 1v6a1 1 0 0 1 -1 1h-6a1 1 0 0 1 -1 -1z"}),b("path",{d:"M12 20v.01"}),b("path",{d:"M16 20v.01"}),b("path",{d:"M8 20v.01"}),b("path",{d:"M4 20v.01"}),b("path",{d:"M4 16v.01"}),b("path",{d:"M4 12v.01"}),b("path",{d:"M4 8v.01"}),b("path",{d:"M4 4v.01"}),b("path",{d:"M8 4v.01"}),b("path",{d:"M12 4v.01"}),b("path",{d:"M16 4v.01"}),b("path",{d:"M20 4v.01"}),b("path",{d:"M20 8v.01"}),b("path",{d:"M20 12v.01"}),b("path",{d:"M20 16v.01"}),b("path",{d:"M20 20v.01"})]}),K),ev=R(H("g",{strokeWidth:1.25,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M5 3v18"}),b("path",{d:"M19 21v-18"}),b("path",{d:"M5 7h14"}),b("path",{d:"M5 15h14"}),b("path",{d:"M8 13v4"}),b("path",{d:"M11 13v4"}),b("path",{d:"M16 13v4"}),b("path",{d:"M14 5v4"}),b("path",{d:"M11 5v4"}),b("path",{d:"M8 5v4"}),b("path",{d:"M3 21h18"})]}),K),tv=R(H("g",{strokeWidth:1.25,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M3 12l18 0"}),b("path",{d:"M7 16l10 0l-10 5l0 -5"}),b("path",{d:"M7 8l10 0l-10 -5l0 5"})]}),K),ov=R(H("g",{strokeWidth:1.25,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M12 3l0 18"}),b("path",{d:"M16 7l0 10l5 0l-5 -10"}),b("path",{d:"M8 7l0 10l-5 0l5 -10"})]}),K),Bh=R(H("g",{strokeWidth:1.25,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M5 3m0 2a2 2 0 0 1 2 -2h10a2 2 0 0 1 2 2v2a2 2 0 0 1 -2 2h-10a2 2 0 0 1 -2 -2z"}),b("path",{d:"M19 6h1a2 2 0 0 1 2 2a5 5 0 0 1 -5 5l-5 0v2"}),b("path",{d:"M10 15m0 1a1 1 0 0 1 1 -1h2a1 1 0 0 1 1 1v4a1 1 0 0 1 -1 1h-2a1 1 0 0 1 -1 -1z"})]}),K),cs=R(H("g",{strokeWidth:1.25,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M15 15m-5 0a5 5 0 1 0 10 0a5 5 0 1 0 -10 0"}),b("path",{d:"M22 22l-3 -3"}),b("path",{d:"M6 18h-1a2 2 0 0 1 -2 -2v-1"}),b("path",{d:"M3 11v-1"}),b("path",{d:"M3 6v-1a2 2 0 0 1 2 -2h1"}),b("path",{d:"M10 3h1"}),b("path",{d:"M15 3h1a2 2 0 0 1 2 2v1"})]}),K),nv=R(H("g",{strokeWidth:1.25,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M14 3v4a1 1 0 0 0 1 1h4"}),b("path",{d:"M5 12v-7a2 2 0 0 1 2 -2h7l5 5v4"}),b("path",{d:"M4 20.25c0 .414 .336 .75 .75 .75h1.25a1 1 0 0 0 1 -1v-1a1 1 0 0 0 -1 -1h-1a1 1 0 0 1 -1 -1v-1a1 1 0 0 1 1 -1h1.25a.75 .75 0 0 1 .75 .75"}),b("path",{d:"M10 15l2 6l2 -6"}),b("path",{d:"M20 15h-1a2 2 0 0 0 -2 2v2a2 2 0 0 0 2 2h1v-3"})]}),K),rv=R(H("g",{strokeWidth:1.25,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M14 3v4a1 1 0 0 0 1 1h4"}),b("path",{d:"M5 12v-7a2 2 0 0 1 2 -2h7l5 5v4"}),b("path",{d:"M20 15h-1a2 2 0 0 0 -2 2v2a2 2 0 0 0 2 2h1v-3"}),b("path",{d:"M5 18h1.5a1.5 1.5 0 0 0 0 -3h-1.5v6"}),b("path",{d:"M11 21v-6l3 6v-6"})]}),K),av=R(H("g",{strokeWidth:1.25,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M4 13v-8a2 2 0 0 1 2 -2h1a2 2 0 0 1 2 2v8a2 2 0 0 0 6 0v-8a2 2 0 0 1 2 -2h1a2 2 0 0 1 2 2v8a8 8 0 0 1 -16 0"}),b("path",{d:"M4 8l5 0"}),b("path",{d:"M15 8l4 0"})]}),K),iv=R(H("g",{strokeWidth:1.25,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M3 14c.83 .642 2.077 1.017 3.5 1c1.423 .017 2.67 -.358 3.5 -1c.83 -.642 2.077 -1.017 3.5 -1c1.423 -.017 2.67 .358 3.5 1"}),b("path",{d:"M8 3a2.4 2.4 0 0 0 -1 2a2.4 2.4 0 0 0 1 2"}),b("path",{d:"M12 3a2.4 2.4 0 0 0 -1 2a2.4 2.4 0 0 0 1 2"}),b("path",{d:"M3 10h14v5a6 6 0 0 1 -6 6h-2a6 6 0 0 1 -6 -6v-5z"}),b("path",{d:"M16.746 16.726a3 3 0 1 0 .252 -5.555"})]}),K),sv=R(H("g",{stroke:"currentColor",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M3 5a1 1 0 0 1 1-1h16a1 1 0 0 1 1 1v10a1 1 0 0 1-1 1h-16a1 1 0 0 1-1-1v-10zM7 20h10M9 16v4M15 16v4"})]}),{...K,strokeWidth:1.5}),ate=R(H("g",{strokeWidth:1.5,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M15 8v-2a2 2 0 0 0 -2 -2h-7a2 2 0 0 0 -2 2v12a2 2 0 0 0 2 2h7a2 2 0 0 0 2 -2v-2"}),b("path",{d:"M21 12h-13l3 -3"}),b("path",{d:"M11 15l-3 -3"})]}),K),lv=R(H("g",{children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M2 8a4 4 0 0 1 4 -4h12a4 4 0 0 1 4 4v8a4 4 0 0 1 -4 4h-12a4 4 0 0 1 -4 -4v-8z"}),b("path",{d:"M10 9l5 3l-5 3z"})]}),K),cv=R(H("g",{strokeWidth:1.5,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M3 6h18"}),b("path",{d:"M3 12h18"}),b("path",{d:"M3 18h18"}),b("path",{d:"M6 3v18"}),b("path",{d:"M12 3v18"}),b("path",{d:"M18 3v18"})]}),K),dv=R(H("g",{strokeWidth:1.5,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M17 3m0 1a1 1 0 0 1 1 -1h2a1 1 0 0 1 1 1v2a1 1 0 0 1 -1 1h-2a1 1 0 0 1 -1 -1z"}),b("path",{d:"M3 17m0 1a1 1 0 0 1 1 -1h2a1 1 0 0 1 1 1v2a1 1 0 0 1 -1 1h-2a1 1 0 0 1 -1 -1z"}),b("path",{d:"M17 5c-6.627 0 -12 5.373 -12 12"})]}),K),ds=R(H("g",{children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M6 18l12 -12"}),b("path",{d:"M18 10v-4h-4"})]}),K),ms=R(H("g",{children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M4,19L10,19C11.097,19 12,18.097 12,17L12,9C12,7.903 12.903,7 14,7L21,7"}),b("path",{d:"M18 4l3 3l-3 3"})]}),K),ps=R(H("g",{children:[b("path",{d:"M16,12L20,9L16,6"}),b("path",{d:"M6 20c0 -6.075 4.925 -11 11 -11h3"})]}),K),Tm=R(H("g",{children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M6 9l6 6l6 -6"})]}),K),mv=R(H("g",{children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M6 15l6 -6l6 6"})]}),K),pv=R(H("g",{children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M6 15l6 -6l6 6"})]}),K),Fh=R(H("g",{strokeWidth:"1.25",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M8 5v10a1 1 0 0 0 1 1h10"}),b("path",{d:"M5 8h10a1 1 0 0 1 1 1v10"})]}),K),Cm=R(H("g",{children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M5 5m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"}),b("path",{d:"M19 5m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"}),b("path",{d:"M5 19m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"}),b("path",{d:"M19 19m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"}),b("path",{d:"M5 7l0 10"}),b("path",{d:"M7 5l10 0"}),b("path",{d:"M7 19l10 0"}),b("path",{d:"M19 7l0 10"})]}),K),ite=R(H("g",{strokeWidth:1.5,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M4 11v8a1 1 0 0 0 1 1h8m-9 -14v-1a1 1 0 0 1 1 -1h1m5 0h2m5 0h1a1 1 0 0 1 1 1v1m0 5v2m0 5v1a1 1 0 0 1 -1 1h-1"}),b("path",{d:"M4 12h7a1 1 0 0 1 1 1v7"})]}),K),uv=R(H("g",{strokeWidth:1.5,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M14 6m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"}),b("path",{d:"M4 6l8 0"}),b("path",{d:"M16 6l4 0"}),b("path",{d:"M8 12m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"}),b("path",{d:"M4 12l2 0"}),b("path",{d:"M10 12l10 0"}),b("path",{d:"M17 18m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"}),b("path",{d:"M4 18l11 0"}),b("path",{d:"M19 18l1 0"})]}),K),gv=R(H("g",{strokeWidth:1,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M6 10l4 -4 L6 14l8 -8 L6 18l12 -12 L10 18l8 -8 L14 18l4 -4"})]}),K),hv=R(H("g",{strokeWidth:1.25,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M4 20h4l10.5 -10.5a2.828 2.828 0 1 0 -4 -4l-10.5 10.5v4"}),b("path",{d:"M13.5 6.5l4 4"})]}),K),ste=R(H("g",{strokeWidth:1,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M11 7l-5 5l5 5"}),b("path",{d:"M17 7l-5 5l5 5"})]}),K),fv=R(H("g",{strokeWidth:"1.75",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M4 4m0 2a2 2 0 0 1 2 -2h12a2 2 0 0 1 2 2v12a2 2 0 0 1 -2 2h-12a2 2 0 0 1 -2 -2z"}),b("path",{d:"M15 4l0 16"})]}),K),lte=R(H("g",{strokeWidth:"1.25",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M3 20l1.3 -3.9c-2.324 -3.437 -1.426 -7.872 2.1 -10.374c3.526 -2.501 8.59 -2.296 11.845 .48c3.255 2.777 3.695 7.266 1.029 10.501c-2.666 3.235 -7.615 4.215 -11.574 2.293l-4.7 1"})]}),K),cte=R(H("g",{strokeWidth:"1.25",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M3 4l18 0"}),b("path",{d:"M4 4v10a2 2 0 0 0 2 2h12a2 2 0 0 0 2 -2v-10"}),b("path",{d:"M12 16l0 4"}),b("path",{d:"M9 20l6 0"}),b("path",{d:"M8 12l3 -3l2 2l3 -3"})]}),K),bv=b("div",{style:{width:"1rem",height:"1rem"}}),xv=R(H("g",{strokeWidth:"1.5",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("polyline",{points:"9 6 15 12 9 18"})]}),K),yv=R(H("g",{strokeWidth:1.25,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M14 6m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"}),b("path",{d:"M4 6l8 0"}),b("path",{d:"M16 6l4 0"}),b("path",{d:"M8 12m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"}),b("path",{d:"M4 12l2 0"}),b("path",{d:"M10 12l10 0"}),b("path",{d:"M17 18m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"}),b("path",{d:"M4 18l11 0"}),b("path",{d:"M19 18l1 0"})]}),K);import Ev from"clsx";import zh,{useEffect as mL,useRef as wv,useState as pL}from"react";import{isPromiseLike as uL}from"@orangecatai/common";import cL from"react";import{jsx as Oh}from"react/jsx-runtime";var dL=({size:e="1em",circleWidth:t=8,synchronized:o=!1,className:n=""})=>{let a=-(cL.useRef(Date.now()).current%1600);return Oh("div",{className:`Spinner ${n}`,children:Oh("svg",{viewBox:"0 0 100 100",style:{width:e,height:e,"--spinner-delay":o?`${a}ms`:0},children:Oh("circle",{cx:"50",cy:"50",r:50-t/2,strokeWidth:t,fill:"none",strokeMiterlimit:"10"})})})},Wt=dL;import{jsx as lc,jsxs as cc}from"react/jsx-runtime";var ae=zh.forwardRef(({size:e="medium",visible:t=!0,className:o="",...n},r)=>{let{id:a}=Qe(),i=zh.useRef(null);zh.useImperativeHandle(r,()=>i.current);let s=`ToolIcon_size_${e}`,[l,c]=pL(!1),m=wv(!0),p=async u=>{let h="onClick"in n&&n.onClick?.(u);if(uL(h))try{c(!0),await h}catch(g){if(g instanceof Ui)console.warn(g);else throw g}finally{m.current&&c(!1)}};mL(()=>(m.current=!0,()=>{m.current=!1}),[]);let d=wv(null);if(n.type==="button"||n.type==="icon"||n.type==="submit"){let u=n.type==="icon"?"button":n.type;return cc("button",{className:Ev("ToolIcon_type_button",s,o,t&&!n.hidden?"ToolIcon_type_button--show":"ToolIcon_type_button--hide",{ToolIcon:!n.hidden,"ToolIcon--selected":n.selected,"ToolIcon--plain":n.type==="icon"}),style:n.style,"data-testid":n["data-testid"],hidden:n.hidden,title:n.title,"aria-label":n["aria-label"],type:u,onClick:p,ref:i,disabled:l||n.isLoading||!!n.disabled,children:[(n.icon||n.label)&&cc("div",{className:"ToolIcon__icon","aria-hidden":"true","aria-disabled":!!n.disabled,children:[n.icon||n.label,n.keyBindingLabel&&lc("span",{className:"ToolIcon__keybinding",children:n.keyBindingLabel}),n.isLoading&&lc(Wt,{})]}),n.showAriaLabel&&cc("div",{className:"ToolIcon__label",children:[n["aria-label"]," ",l&&lc(Wt,{})]}),n.children]})}return cc("label",{className:Ev("ToolIcon",o),title:n.title,onPointerDown:u=>{d.current=u.pointerType||null,n.onPointerDown?.({pointerType:u.pointerType||null})},onPointerUp:()=>{requestAnimationFrame(()=>{d.current=null})},children:[lc("input",{className:`ToolIcon_type_radio ${s}`,type:"radio",name:n.name,"aria-label":n["aria-label"],"aria-keyshortcuts":n["aria-keyshortcuts"],"data-testid":n["data-testid"],id:`${a}-${n.id}`,onChange:()=>{n.onChange?.({pointerType:d.current})},checked:n.checked,ref:i}),cc("div",{className:"ToolIcon__icon",children:[n.icon,n.keyBindingLabel&&lc("span",{className:"ToolIcon__keybinding",children:n.keyBindingLabel})]})]})});ae.displayName="ToolButton";var km=[],W=e=>(km=km.concat(e),e);import{jsx as vL}from"react/jsx-runtime";var wL=(e,t,o)=>{let n=new Set(de(e.filter(m=>xL(m)),t).map(m=>m.id)),r={},a=o.scene.getNonDeletedElementsMap(),i=new Set;for(let m of n){let p=yL(e,m);for(let d of p)if(!i.has(d.id)){if(Sm(d)){let u=Iv(d,a);u&&(r[u.id]=!0)}else r[d.id]=!0;i.add(d.id)}}let s=!0,l=e.map(m=>{if(t.selectedElementIds[m.id]){let p=Sm(m)?Iv(m,a):null;return m.frameId&&n.has(m.frameId)?(s=!1,r[m.id]=!0,m):p?.frameId&&n.has(p?.frameId)?m:(m.boundElements&&m.boundElements.forEach(d=>{let u=o.scene.getNonDeletedElementsMap().get(d.id);u&&bL(u)&&o.scene.mutateElement(u,{startBinding:m.id===u.startBinding?.elementId?null:u.startBinding,endBinding:m.id===u.endBinding?.elementId?null:u.endBinding})}),Pm(m,{isDeleted:!0}))}return m.frameId&&n.has(m.frameId)?(s=!1,Sm(m)||(r[m.id]=!0),Pm(m,{frameId:null})):Sm(m)&&t.selectedElementIds[m.containerId]?Pm(m,{isDeleted:!0}):m}),c=t.editingGroupId;if(s&&t.editingGroupId){let m=Uh(l,t.editingGroupId).filter(p=>!p.isDeleted);if(m.length>1)m[0]&&(r[m[0].id]=!0);else{c=null,m[0]&&(r[m[0].id]=!0);let p=m[0];if(p){let d=p.groupIds.findIndex(h=>h===t.editingGroupId),u=p.groupIds[d+1];if(u){let h=Uh(l,u).filter(g=>!g.isDeleted);h.length>1&&(c=u,h.forEach(g=>{r[g.id]=!0}))}}}}return{elements:l,appState:{...t,...EL({selectedElementIds:r,editingGroupId:c},l,t,null)}}},Tv=(e,t)=>{if(e.editingGroupId){let o=Uh(Gh(t),e.editingGroupId);if(o.length)return{...e,selectedElementIds:{[o[0].id]:!0}}}return e},dc=W({name:"deleteSelectedElements",label:"labels.delete",icon:Ut,trackEvent:{category:"element",action:"delete"},perform:(e,t,o,n)=>{if(t.selectedLinearElement?.isEditing){let{elementId:i,selectedPointsIndices:s}=t.selectedLinearElement,l=n.scene.getNonDeletedElementsMap(),c=vv.getElement(i,l);if(!c||s==null)return!1;if(s.length>=c.points.length){let m=e.map(d=>d.id===c.id?Pm(d,{isDeleted:!0}):d),p=Tv(t,m);return{elements:m,appState:{...p,selectedLinearElement:null},captureUpdate:Mm.IMMEDIATELY}}return vv.deletePoints(c,n,s),{elements:e,appState:{...t,selectedLinearElement:{...t.selectedLinearElement,selectedPointsIndices:s?.[0]>0?[s[0]-1]:[0]}},captureUpdate:Mm.IMMEDIATELY}}let{elements:r,appState:a}=wL(e,t,n);return fL(r,r.filter(i=>i.isDeleted)),a=Tv(a,r),{elements:r,appState:{...a,activeTool:hL(t,{type:n.state.preferredSelectionTool.type}),multiElement:null,newElement:null,activeEmbeddable:null,selectedLinearElement:null},captureUpdate:Ge(Gh(e),t)?Mm.IMMEDIATELY:Mm.EVENTUALLY}},keyTest:(e,t,o)=>(e.key===Hh.BACKSPACE||e.key===Hh.DELETE)&&!e[Hh.CTRL_OR_CMD],PanelComponent:({elements:e,appState:t,updateData:o,app:n})=>{let r=Dt()==="mobile";return vL(ae,{type:"button",icon:Ut,title:f("labels.delete"),"aria-label":f("labels.delete"),onClick:()=>o(null),disabled:!Ge(Gh(e),t),style:{...r&&t.openPopup!=="compactOtherProperties"?gL:{}}})}});import{KEYS as us,CODES as gs,isDarwin as Am}from"@orangecatai/common";import{moveOneLeft as IL,moveOneRight as TL,moveAllLeft as CL,moveAllRight as kL}from"@orangecatai/element";import{CaptureUpdateAction as Lm}from"@orangecatai/element";import{isDarwin as Cv}from"@orangecatai/common";var G=e=>e.replace(/\b(Opt(?:ion)?|Alt)\b/i,Cv?f("keys.option"):f("keys.alt")).replace(/\bShift\b/i,f("keys.shift")).replace(/\b(Enter|Return)\b/i,f("keys.enter")).replace(/\b(Ctrl|Cmd|Command|CtrlOrCmd)\b/gi,Cv?f("keys.cmd"):f("keys.ctrl")).replace(/\b(Esc(?:ape)?)\b/i,f("keys.escape")).replace(/\b(Space(?:bar)?)\b/i,f("keys.spacebar")).replace(/\b(Del(?:ete)?)\b/i,f("keys.delete"));import{jsx as _m}from"react/jsx-runtime";var Wh=W({name:"sendBackward",label:"labels.sendBackward",keywords:["move down","zindex","layer"],icon:vh,trackEvent:{category:"element"},perform:(e,t,o,n)=>({elements:IL(e,t,n.scene),appState:t,captureUpdate:Lm.IMMEDIATELY}),keyPriority:40,keyTest:e=>e[us.CTRL_OR_CMD]&&!e.shiftKey&&e.code===gs.BRACKET_LEFT,PanelComponent:({updateData:e,appState:t})=>_m("button",{type:"button",className:"zIndexButton",onClick:()=>e(null),title:`${f("labels.sendBackward")} \u2014 ${G("CtrlOrCmd+[")}`,children:vh})}),Yh=W({name:"bringForward",label:"labels.bringForward",keywords:["move up","zindex","layer"],icon:wh,trackEvent:{category:"element"},perform:(e,t,o,n)=>({elements:TL(e,t,n.scene),appState:t,captureUpdate:Lm.IMMEDIATELY}),keyPriority:40,keyTest:e=>e[us.CTRL_OR_CMD]&&!e.shiftKey&&e.code===gs.BRACKET_RIGHT,PanelComponent:({updateData:e,appState:t})=>_m("button",{type:"button",className:"zIndexButton",onClick:()=>e(null),title:`${f("labels.bringForward")} \u2014 ${G("CtrlOrCmd+]")}`,children:wh})}),$h=W({name:"sendToBack",label:"labels.sendToBack",keywords:["move down","zindex","layer"],icon:Th,trackEvent:{category:"element"},perform:(e,t)=>({elements:CL(e,t),appState:t,captureUpdate:Lm.IMMEDIATELY}),keyTest:e=>Am?e[us.CTRL_OR_CMD]&&e.altKey&&e.code===gs.BRACKET_LEFT:e[us.CTRL_OR_CMD]&&e.shiftKey&&e.code===gs.BRACKET_LEFT,PanelComponent:({updateData:e,appState:t})=>_m("button",{type:"button",className:"zIndexButton",onClick:()=>e(null),title:`${f("labels.sendToBack")} \u2014 ${Am?G("CtrlOrCmd+Alt+["):G("CtrlOrCmd+Shift+[")}`,children:Th})}),Vh=W({name:"bringToFront",label:"labels.bringToFront",keywords:["move up","zindex","layer"],icon:Ih,trackEvent:{category:"element"},perform:(e,t)=>({elements:kL(e,t),appState:t,captureUpdate:Lm.IMMEDIATELY}),keyTest:e=>Am?e[us.CTRL_OR_CMD]&&e.altKey&&e.code===gs.BRACKET_RIGHT:e[us.CTRL_OR_CMD]&&e.shiftKey&&e.code===gs.BRACKET_RIGHT,PanelComponent:({updateData:e,appState:t})=>_m("button",{type:"button",className:"zIndexButton",onClick:o=>e(null),title:`${f("labels.bringToFront")} \u2014 ${Am?G("CtrlOrCmd+Alt+]"):G("CtrlOrCmd+Shift+]")}`,children:Ih})});import{getNonDeletedElements as SL}from"@orangecatai/element";import{LinearElementEditor as ML}from"@orangecatai/element";import{isLinearElement as PL,isTextElement as AL}from"@orangecatai/element";import{arrayToMap as LL,KEYS as kv}from"@orangecatai/common";import{selectGroupsForSelectedElements as _L}from"@orangecatai/element";import{CaptureUpdateAction as DL}from"@orangecatai/element";var Kh=W({name:"selectAll",label:"labels.selectAll",icon:Qw,trackEvent:{category:"canvas"},viewMode:!1,perform:(e,t,o,n)=>{if(t.selectedLinearElement?.isEditing)return!1;let r=e.filter(a=>!a.isDeleted&&!(AL(a)&&a.containerId)&&!a.locked).reduce((a,i)=>(a[i.id]=!0,a),{});return{appState:{...t,..._L({editingGroupId:null,selectedElementIds:r},SL(e),t,n),selectedLinearElement:Object.keys(r).length===1&&PL(e[0])?new ML(e[0],LL(e)):null},captureUpdate:DL.IMMEDIATELY}},keyTest:e=>e[kv.CTRL_OR_CMD]&&e.key===kv.A});import{DEFAULT_GRID_SIZE as Sv,KEYS as Mv,MOBILE_ACTION_BUTTON_BG as RL,arrayToMap as Pv}from"@orangecatai/common";import{getNonDeletedElements as Av}from"@orangecatai/element";import{LinearElementEditor as NL}from"@orangecatai/element";import{getSelectedElements as BL,getSelectionStateForElements as FL}from"@orangecatai/element";import{syncMovedIndices as OL}from"@orangecatai/element";import{duplicateElements as zL}from"@orangecatai/element";import{CaptureUpdateAction as Lv}from"@orangecatai/element";import{jsx as HL}from"react/jsx-runtime";var Xh=W({name:"duplicateSelection",label:"labels.duplicateSelection",icon:tc,trackEvent:{category:"element"},perform:(e,t,o,n)=>{if(t.selectedElementsAreBeingDragged)return!1;if(t.selectedLinearElement?.isEditing)try{let i=NL.duplicateSelectedPoints(t,n.scene);return{elements:e,appState:i,captureUpdate:Lv.IMMEDIATELY}}catch{return!1}let{duplicatedElements:r,elementsWithDuplicates:a}=zL({type:"in-place",elements:e,idsOfElementsToDuplicate:Pv(BL(e,t,{includeBoundTextElement:!0,includeElementsInFrames:!0})),appState:t,randomizeSeed:!0,overrides:({origElement:i,origIdToDuplicateId:s})=>{let l=i.frameId&&s.get(i.frameId);return{x:i.x+Sv/2,y:i.y+Sv/2,frameId:l??i.frameId}}});if(n.props.onDuplicate&&a){let i=n.props.onDuplicate(a,e);i&&(a=i)}return{elements:OL(a,Pv(r)),appState:{...t,...FL(r,Av(a),t)},captureUpdate:Lv.IMMEDIATELY}},keyTest:e=>e[Mv.CTRL_OR_CMD]&&e.key===Mv.D,PanelComponent:({elements:e,appState:t,updateData:o,app:n})=>{let r=Dt()==="mobile";return HL(ae,{type:"button",icon:tc,title:`${f("labels.duplicateSelection")} \u2014 ${G("CtrlOrCmd+D")}`,"aria-label":f("labels.duplicateSelection"),onClick:()=>o(null),disabled:!Ge(Av(e),t),style:{...r&&t.openPopup!=="compactOtherProperties"?RL:{}}})}});import{pointFrom as GD}from"@orangecatai/math";import{useEffect as xf,useMemo as UD,useRef as yf,useState as WD}from"react";import{DEFAULT_ELEMENT_BACKGROUND_COLOR_PALETTE as YD,DEFAULT_ELEMENT_BACKGROUND_PICKS as $D,DEFAULT_ELEMENT_STROKE_COLOR_PALETTE as VD,DEFAULT_ELEMENT_STROKE_PICKS as KD,ARROW_TYPE as Vo,DEFAULT_FONT_FAMILY as XD,DEFAULT_FONT_SIZE as ZD,FONT_FAMILY as jD,ROUNDNESS as Zm,STROKE_WIDTH as Ef,VERTICAL_ALIGN as Km,KEYS as vs,randomInteger as qD,arrayToMap as vf,getFontFamilyString as JD,getLineHeight as QD,isTransparent as e8,reduceToCommonValue as t8,invariant as If,FONT_SIZES as Xm}from"@orangecatai/common";import{canBecomePolygon as o8,getNonDeletedElements as w2}from"@orangecatai/element";import{bindBindingElement as b2,calculateFixedPointForElbowArrowBinding as x2,updateBoundElements as n8}from"@orangecatai/element";import{LinearElementEditor as ja}from"@orangecatai/element";import{newElementWith as kt}from"@orangecatai/element";import{getBoundTextElement as qr,redrawTextBoundingBox as vc}from"@orangecatai/element";import{isArrowElement as jm,isBoundToContainer as r8,isElbowArrow as v2,isLinearElement as wf,isLineElement as y2,isTextElement as fo,isUsingAdaptiveRadius as a8}from"@orangecatai/element";import{hasStrokeColor as i8}from"@orangecatai/element";import{updateElbowArrowPoints as s8,CaptureUpdateAction as St,toggleLinePolygonState as l8}from"@orangecatai/element";import{deriveStylesPanelMode as c8}from"@orangecatai/common";import{isDevEnv as GL}from"@orangecatai/common";var UL=new Set(["command_palette","export"]),be=(e,t,o,n)=>{try{if(typeof window>"u"||T.VITE_WORKER_ID||T.VITE_APP_ENABLE_TRACKING!=="true"||!UL.has(e)||GL())return;T.PROD||console.info("trackEvent",{category:e,action:t,label:o,value:n}),window.sa_event&&window.sa_event(t,{category:e,label:o,value:n})}catch(r){console.error("error during analytics",r)}};import VL from"clsx";import WL from"clsx";import{forwardRef as YL}from"react";import{jsx as $L}from"react/jsx-runtime";var hs=YL((e,t)=>{let{title:o,className:n,testId:r,active:a,standalone:i,icon:s,onClick:l}=e;return $L("button",{type:"button",ref:t,title:o,"data-testid":r,className:WL(n,{standalone:i,active:a}),onClick:l,style:e.style,children:s},o)});import{Fragment as XL,jsx as Zh,jsxs as KL}from"react/jsx-runtime";var Uo=e=>Zh(XL,{children:e.options.map(t=>e.type==="button"?Zh(hs,{icon:t.icon,title:t.text,testId:t.testId,active:t.active??e.value===t.value,onClick:o=>e.onClick(t.value,o)},t.text):KL("label",{className:VL({active:e.value===t.value}),title:t.text,children:[Zh("input",{type:"radio",name:e.group,onChange:()=>e.onChange(t.value),checked:e.value===t.value,"data-testid":t.testId}),t.icon]},t.text))});import{Popover as qv}from"radix-ui";import Jv from"clsx";import{useRef as Qv,useEffect as j_}from"react";import{COLOR_OUTLINE_CONTRAST_THRESHOLD as Zv,COLOR_PALETTE as e2,isColorDark as jv,isWritableElement as q_}from"@orangecatai/common";import{jsx as ZL}from"react/jsx-runtime";var Dm=()=>ZL("div",{style:{width:1,height:"1rem",backgroundColor:"var(--default-border-color)",margin:"0 auto"}});import{useEffect as e_,useRef as t_}from"react";import{createPortal as o_}from"react-dom";import{EVENT as Wr,KEYS as n_,rgbToHex as r_}from"@orangecatai/common";import _v from"react";var jh=_v.createContext(null),Ie=()=>_v.useContext(jh);import{useState as jL,useLayoutEffect as Dv}from"react";import{THEME as qL}from"@orangecatai/common";var Rm=e=>{let[t,o]=jL(null),n=Te(),{theme:r}=Ie(),{container:a}=Qe();return Dv(()=>{t&&(t.className="",t.classList.add("excalidraw",...e?.className?.split(/\s+/)||[]),t.classList.toggle("excalidraw--mobile",n.formFactor==="phone"),t.classList.toggle("theme--dark",r===qL.DARK))},[t,r,n.formFactor,e?.className]),Dv(()=>{let i=e?.parentSelector?a?.querySelector(e.parentSelector):document.body;if(!i)return;let s=document.createElement("div");return i.appendChild(s),o(s),()=>{i.removeChild(s)}},[a,e?.parentSelector]),t};import{useEffect as JL}from"react";import{EVENT as Nm}from"@orangecatai/common";function fs(e,t,o){JL(()=>{function n(r){let a=r;if(!e.current)return;let i=o?.(a,e.current);if(i===!0)return;if(i===!1)return t(a);e.current.contains(a.target)||!document.documentElement.contains(a.target)||a.target.closest("[data-radix-portal]")||a.target===document.documentElement&&document.body.style.pointerEvents==="none"||a.target.closest("[data-prevent-outside-click]")||t(a)}return document.addEventListener(Nm.POINTER_DOWN,n),document.addEventListener(Nm.TOUCH_START,n),()=>{document.removeEventListener(Nm.POINTER_DOWN,n),document.removeEventListener(Nm.TOUCH_START,n)}},[e,t,o])}import{useRef as QL}from"react";var Ur=e=>{let t=QL(e);return Object.assign(t.current,e),t.current};import{jsx as a_}from"react/jsx-runtime";var Yr=Pe(null),Rv=({onCancel:e,onChange:t,onSelect:o,colorPickerType:n})=>{let r=Rm({className:"excalidraw-eye-dropper-backdrop",parentSelector:".excalidraw-eye-dropper-container"}),a=Ie(),i=$r(),s=tt(),l=de(i,a),c=Ur({app:s,onCancel:e,onChange:t,onSelect:o,selectedElements:l}),{container:m}=Qe();e_(()=>{let d=p.current;if(!d||!s.canvas||!r)return;let u=!1,h=s.canvas.getContext("2d"),g=({clientX:C,clientY:P})=>{let S=h.getImageData((C-a.offsetLeft)*window.devicePixelRatio,(P-a.offsetTop)*window.devicePixelRatio,1,1).data;return r_(S[0],S[1],S[2])},x=({clientX:C,clientY:P,altKey:S})=>{d.style.top=`${P+20}px`,d.style.left=`${C+20}px`;let D=g({clientX:C,clientY:P});u&&c.onChange(n,D,c.selectedElements,{altKey:S}),d.style.background=D},E=()=>{c.onCancel()},y=(C,P)=>{c.onSelect(C,P)},w=C=>{u=!0,C.stopImmediatePropagation()},v=C=>{u=!1,m?.focus(),C.stopImmediatePropagation(),C.preventDefault(),y(g(C),C)},I=C=>{C.key===n_.ESCAPE&&(C.preventDefault(),C.stopImmediatePropagation(),E())};return r.tabIndex=-1,r.focus(),x({clientX:c.app.lastViewportPosition.x,clientY:c.app.lastViewportPosition.y,altKey:!1}),r.addEventListener(Wr.KEYDOWN,I),r.addEventListener(Wr.POINTER_DOWN,w),r.addEventListener(Wr.POINTER_UP,v),window.addEventListener("pointermove",x,{passive:!0}),window.addEventListener(Wr.BLUR,E),()=>{u=!1,r.removeEventListener(Wr.KEYDOWN,I),r.removeEventListener(Wr.POINTER_DOWN,w),r.removeEventListener(Wr.POINTER_UP,v),window.removeEventListener("pointermove",x),window.removeEventListener(Wr.BLUR,E)}},[c,s.canvas,r,n,m,a.offsetLeft,a.offsetTop]);let p=t_(null);return fs(p,()=>{e()},d=>!!d.target.closest(".excalidraw-eye-dropper-trigger, .excalidraw-eye-dropper-backdrop")),r?o_(a_("div",{ref:p,className:"excalidraw-eye-dropper-preview"}),r):null};import{Popover as qh}from"radix-ui";import c_ from"clsx";import d_ from"react";import{isInteractive as m_}from"@orangecatai/common";import i_ from"react";import s_ from"clsx";import{jsx as l_}from"react/jsx-runtime";var gt=i_.forwardRef(({children:e,padding:t,className:o,style:n},r)=>l_("div",{className:s_("Island",o),style:{"--padding":t,...n},ref:r,children:e}));import{jsx as Jh,jsxs as p_}from"react/jsx-runtime";var gr=d_.forwardRef(({className:e,container:t,children:o,style:n,onClose:r,onKeyDown:a,onFocusOutside:i,onPointerLeave:s,onPointerDownOutside:l,preventAutoFocusOnTouch:c=!1},m)=>{let p=Te(),d=p.formFactor==="phone"&&!p.isLandscape;return Jh(qh.Portal,{container:t,children:p_(qh.Content,{ref:m,className:c_("focus-visible-none",e),"data-prevent-outside-click":!0,side:d?"bottom":"right",align:d?"center":"start",alignOffset:-16,sideOffset:20,collisionBoundary:t??void 0,style:{zIndex:"var(--zIndex-ui-styles-popup)",marginLeft:p.formFactor==="phone"?"0.5rem":void 0},onPointerLeave:s,onKeyDown:a,onFocusOutside:i,onPointerDownOutside:l,onOpenAutoFocus:u=>{c&&p.isTouchScreen&&u.preventDefault()},onCloseAutoFocus:u=>{u.stopPropagation(),u.preventDefault(),t&&!m_(document.activeElement)&&t.focus(),r()},children:[Jh(gt,{padding:3,style:n,children:o}),Jh(qh.Arrow,{width:20,height:10,style:{fill:"var(--popup-bg-color)",filter:"drop-shadow(rgba(0, 0, 0, 0.05) 0px 3px 2px)"}})]})})});import{useState as u_,useCallback as Qh}from"react";var Bm=()=>document.querySelector(".excalidraw-wysiwyg"),Fm=()=>{let e=Bm();return e?{start:e.selectionStart,end:e.selectionEnd}:null},mc=e=>{setTimeout(()=>{let t=Bm();t&&(t.focus(),e&&(t.selectionStart=e.start,t.selectionEnd=e.end))},0)},pc=(e,t,o,n)=>{t&&n&&n();let r=t&&o?Fm():null;e(),t&&o&&mc(r)},Nv=()=>{let[e,t]=u_(null),o=Qh(()=>{let a=Fm();t(a)},[]),n=Qh(()=>{setTimeout(()=>{let a=Bm();a&&(a.focus(),e&&(a.selectionStart=e.start,a.selectionEnd=e.end,t(null)))},0)},[e]),r=Qh(()=>{t(null)},[]);return{saveCaretPosition:o,restoreCaretPosition:n,clearSavedPosition:r,hasSavedPosition:!!e}},Bv=(e=100)=>{let t=Bm();if(t){let o=t.onblur;t.onblur=null,setTimeout(()=>{t.onblur=o},e)}};import h_ from"clsx";import{useCallback as f_,useEffect as tf,useRef as Ov,useState as b_}from"react";import{KEYS as of,normalizeInputColor as x_}from"@orangecatai/common";import{MAX_CUSTOM_COLORS_USED_IN_CANVAS as g_}from"@orangecatai/common";var Vr=({palette:e,color:t})=>{if(!t)return null;for(let[o,n]of Object.entries(e))if(Array.isArray(n)){let r=n.indexOf(t);if(r>-1)return{colorName:o,shade:r}}else if(n===t)return{colorName:o,shade:null};return null},uc=[["q","w","e","r","t"],["a","s","d","f","g"],["z","x","c","v","b"]].flat(),ef=({color:e,palette:t})=>!Object.values(t).flat().includes(e),Fv=(e,t,o)=>{let n={elementBackground:"backgroundColor",elementStroke:"strokeColor"},r=e.filter(i=>{if(i.isDeleted)return!1;let s=i[n[t]];return ef({color:s,palette:o})}),a=new Map;return r.forEach(i=>{let s=i[n[t]];a.has(s)?a.set(s,a.get(s)+1):a.set(s,1)}),[...a.entries()].sort((i,s)=>s[1]-i[1]).map(i=>i[0]).slice(0,g_)},Wo=Pe(null);import{Fragment as y_,jsx as Om,jsxs as zv}from"react/jsx-runtime";var Hv=({color:e,onChange:t,label:o,colorPickerType:n,placeholder:r})=>{let a=Te(),[i,s]=b_(e),[l,c]=le(Wo);tf(()=>{s(e)},[e]);let m=f_(g=>{let x=g.toLowerCase(),E=x_(x);E&&t(E),s(x)},[t]),p=Ov(null),d=Ov(null);tf(()=>{p.current&&p.current.focus()},[l]);let[u,h]=le(Yr);return tf(()=>()=>{h(null)},[h]),zv("div",{className:"color-picker__input-label",children:[Om("div",{className:"color-picker__input-hash",children:"#"}),Om("input",{ref:l==="hex"?p:void 0,style:{border:0,padding:0},spellCheck:!1,className:"color-picker-input","aria-label":o,onChange:g=>{m(g.target.value)},value:(i||"").replace(/^#/,""),onBlur:()=>{s(e)},tabIndex:-1,onFocus:()=>c("hex"),onKeyDown:g=>{g.key!==of.TAB&&(g.key===of.ESCAPE&&d.current?.focus(),g.stopPropagation())},placeholder:r}),a.formFactor!=="phone"&&zv(y_,{children:[Om("div",{style:{width:"1px",height:"1.25rem",backgroundColor:"var(--default-border-color)"}}),Om("div",{ref:d,className:h_("excalidraw-eye-dropper-trigger",{selected:u}),onClick:()=>h(g=>g?null:{keepOpenOnAlt:!1,onSelect:x=>t(x),colorPickerType:n}),title:`${f("labels.eyeDropper")} \u2014 ${of.I.toLocaleUpperCase()} or ${G("Alt")} `,children:Gw})]})]})};import sf,{useEffect as lf,useImperativeHandle as z_,useState as H_}from"react";import{EVENT as Vv}from"@orangecatai/common";import{DEFAULT_ELEMENT_BACKGROUND_COLOR_INDEX as G_,DEFAULT_ELEMENT_STROKE_COLOR_INDEX as U_,KEYS as W_}from"@orangecatai/common";import I_ from"clsx";import{useEffect as T_,useRef as C_}from"react";import{isColorDark as E_}from"@orangecatai/common";import{jsxs as v_}from"react/jsx-runtime";var w_=({color:e,keyLabel:t,isShade:o=!1})=>v_("div",{className:"color-picker__button__hotkey-label",style:{color:E_(e)?"#fff":"#000"},children:[o&&"\u21E7",t]}),bs=w_;import{jsx as nf,jsxs as k_}from"react/jsx-runtime";var Gv=({colors:e,color:t,onChange:o,label:n})=>{let[r,a]=le(Wo),i=C_(null);return T_(()=>{i.current&&i.current.focus()},[t,r]),nf("div",{className:"color-picker-content--default",children:e.map((s,l)=>k_("button",{ref:t===s?i:void 0,tabIndex:-1,type:"button",className:I_("color-picker__button color-picker__button--large has-outline",{active:t===s,"is-transparent":s==="transparent"||!s}),onClick:()=>{o(s),a("custom")},title:s,"aria-label":n,style:{"--swatch-color":s},children:[nf("div",{className:"color-picker__button-outline"}),nf(bs,{color:s,keyLabel:l+1})]},l))})};import S_ from"clsx";import{useEffect as M_,useRef as P_}from"react";import{jsx as rf,jsxs as L_}from"react/jsx-runtime";var A_=({palette:e,color:t,onChange:o,activeShade:n,showHotKey:r=!0})=>{let a=Vr({color:t,palette:e}),[i,s]=le(Wo),l=P_(null);return M_(()=>{l.current&&i==="baseColors"&&l.current.focus()},[a?.colorName,i]),rf("div",{className:"color-picker-content--default",children:Object.entries(e).map(([c,m],p)=>{let d=(Array.isArray(m)?m[n]:m)||"transparent",u=uc[p],h=f(`colors.${c.replace(/\d+/,"")}`,null,"");return L_("button",{ref:a?.colorName===c?l:void 0,tabIndex:-1,type:"button",className:S_("color-picker__button color-picker__button--large has-outline",{active:a?.colorName===c,"is-transparent":d==="transparent"||!d}),onClick:()=>{o(d),s("baseColors")},title:`${h}${d.startsWith("#")?` ${d}`:""} \u2014 ${u}`,"aria-label":`${h} \u2014 ${u}`,style:d?{"--swatch-color":d}:void 0,"data-testid":`color-${c}`,children:[rf("div",{className:"color-picker__button-outline"}),r&&rf(bs,{color:d,keyLabel:u})]},c)})})},Uv=A_;import{jsx as D_}from"react/jsx-runtime";var __=({children:e})=>D_("div",{className:"color-picker__heading",children:e}),xs=__;import R_ from"clsx";import{useEffect as N_,useRef as B_}from"react";import{jsx as gc,jsxs as Wv}from"react/jsx-runtime";var Yv=({color:e,onChange:t,palette:o,showHotKey:n})=>{let r=Vr({color:e||"transparent",palette:o}),[a,i]=le(Wo),s=B_(null);if(N_(()=>{s.current&&a==="shades"&&s.current.focus()},[r,a]),r){let{colorName:l,shade:c}=r,m=o[l];if(Array.isArray(m))return gc("div",{className:"color-picker-content--default shades",children:m.map((p,d)=>Wv("button",{ref:d===c&&a==="shades"?s:void 0,tabIndex:-1,type:"button",className:R_("color-picker__button color-picker__button--large has-outline",{active:d===c}),"aria-label":"Shade",title:`${l} - ${d+1}`,style:p?{"--swatch-color":p}:void 0,onClick:()=>{t(p),i("shades")},children:[gc("div",{className:"color-picker__button-outline"}),n&&gc(bs,{color:p,keyLabel:d+1,isShade:!0})]},d))})}return Wv("div",{className:"color-picker-content--default",style:{position:"relative"},tabIndex:-1,children:[gc("button",{type:"button",tabIndex:-1,className:"color-picker__button color-picker__button--large color-picker__button--no-focus-visible"}),gc("div",{tabIndex:-1,style:{position:"absolute",top:0,left:0,right:0,bottom:0,display:"flex",alignItems:"center",justifyContent:"center",textAlign:"center",fontSize:"0.75rem"},children:f("colorPicker.noShades")})]})};import{COLORS_PER_ROW as ys,COLOR_PALETTE as F_,KEYS as hc}from"@orangecatai/common";var af=(e,t,o)=>{let n=Math.ceil(o/ys);switch(t=t??-1,e){case"ArrowLeft":{let r=t-1;return r<0?o-1:r}case"ArrowRight":return(t+1)%o;case"ArrowDown":{let r=t+ys;return r>=o?t%ys:r}case"ArrowUp":{let r=t-ys,a=r<0?ys*n+r:r;return a>=o?void 0:a}}},O_=({e,colorObj:t,onChange:o,palette:n,customColors:r,setActiveColorPickerSection:a,activeShade:i})=>{if(t?.shade!=null&&["Digit1","Digit2","Digit3","Digit4","Digit5"].includes(e.code)&&e.shiftKey){let s=Number(e.code.slice(-1))-1;return o(n[t.colorName][s]),a("shades"),!0}if(["1","2","3","4","5"].includes(e.key)&&r[Number(e.key)-1])return o(r[Number(e.key)-1]),a("custom"),!0;if(uc.includes(e.key)){let s=uc.indexOf(e.key),l=Object.keys(n)[s],c=n[l],m=Array.isArray(c)?c[i]:c;return o(m),a("baseColors"),!0}return!1},$v=({event:e,activeColorPickerSection:t,palette:o,color:n,onChange:r,customColors:a,setActiveColorPickerSection:i,updateData:s,activeShade:l,onEyeDropperToggle:c,onEscape:m})=>{if(e[hc.CTRL_OR_CMD])return!1;if(e.key===hc.ESCAPE)return m(e),!0;if(e.key===hc.ALT)return c(!0),!0;if(e.key===hc.I)return c(),!0;let p=Vr({color:n,palette:o});if(e.key===hc.TAB){let d={custom:!!a.length,baseColors:!0,shades:p?.shade!=null,hex:!0},u=Object.entries(d).reduce((y,[w,v])=>(v&&y.push(w),y),[]),h=u.indexOf(t),g=e.shiftKey?-1:1,x=h+g>u.length-1?0:h+g<0?u.length-1:h+g,E=u[x];return E&&i(E),E==="custom"?r(a[0]):E==="baseColors"&&(Object.entries(o).find(([w,v])=>Array.isArray(v)?v.includes(n):v===n?w:null)||r(F_.black)),e.preventDefault(),e.stopPropagation(),!0}if(O_({e,colorObj:p,onChange:r,palette:o,customColors:a,setActiveColorPickerSection:i,activeShade:l}))return!0;if(t==="shades"&&p){let{shade:d}=p,u=af(e.key,d,ys);if(u!==void 0)return r(o[p.colorName][u]),!0}if(t==="baseColors"&&p){let{colorName:d}=p,u=Object.keys(o),h=u.indexOf(d),g=af(e.key,h,u.length);if(g!==void 0){let x=u[g],E=o[x];return r(Array.isArray(E)?E[l]:E),!0}}if(t==="custom"){let d=n!=null?a.indexOf(n):0,u=af(e.key,d,a.length);if(u!==void 0){let h=a[u];return r(h),!0}}return!1};import{jsx as Kr,jsxs as zm}from"react/jsx-runtime";var Kv=sf.forwardRef(({color:e,onChange:t,type:o,elements:n,palette:r,updateData:a,children:i,showTitle:s,onEyeDropperToggle:l,onEscape:c,showHotKey:m=!0},p)=>{let d=s?o==="elementStroke"?f("labels.stroke"):o==="elementBackground"?f("labels.background"):null:null,[u]=sf.useState(()=>o==="canvasBackground"?[]:Fv(n,o,r)),[h,g]=le(Wo),x=Vr({color:e,palette:r});lf(()=>{if(!h){let v=!!e&&ef({color:e,palette:r}),I=v&&!u.includes(e);g(I?null:v?"custom":x?.shade!=null?"shades":"baseColors")}},[h,e,r,g,x,u]);let[E,y]=H_(x?.shade??(o==="elementBackground"?G_:U_));lf(()=>{x?.shade!=null&&y(x.shade);let v=I=>{I.key===W_.ALT&&l(!1)};return document.addEventListener(Vv.KEYUP,v,{capture:!0}),()=>{document.removeEventListener(Vv.KEYUP,v,{capture:!0})}},[x,l]);let w=sf.useRef(null);return z_(p,()=>w.current),lf(()=>{w?.current?.focus()},[]),Kr("div",{role:"dialog","aria-modal":"true","aria-label":f("labels.colorPicker"),children:zm("div",{ref:w,onKeyDown:v=>{$v({event:v,activeColorPickerSection:h,palette:r,color:e,onChange:t,onEyeDropperToggle:l,customColors:u,setActiveColorPickerSection:g,updateData:a,activeShade:E,onEscape:c})&&(v.preventDefault(),v.stopPropagation())},className:"color-picker-content properties-content",tabIndex:-1,children:[d&&Kr("div",{className:"color-picker__title",children:d}),!!u.length&&zm("div",{children:[Kr(xs,{children:f("colorPicker.mostUsedCustomColors")}),Kr(Gv,{colors:u,color:e,label:f("colorPicker.mostUsedCustomColors"),onChange:t})]}),zm("div",{children:[Kr(xs,{children:f("colorPicker.colors")}),Kr(Uv,{color:e,palette:r,onChange:t,activeShade:E,showHotKey:m})]}),zm("div",{children:[Kr(xs,{children:f("colorPicker.shades")}),Kr(Yv,{color:e,onChange:t,palette:r,showHotKey:m})]}),i]})})});import Y_ from"clsx";import{COLOR_OUTLINE_CONTRAST_THRESHOLD as $_,DEFAULT_CANVAS_BACKGROUND_PICKS as V_,DEFAULT_ELEMENT_BACKGROUND_PICKS as K_,DEFAULT_ELEMENT_STROKE_PICKS as X_,isColorDark as Z_}from"@orangecatai/common";import{jsx as cf}from"react/jsx-runtime";var Xv=({onChange:e,type:t,activeColor:o,topPicks:n})=>{let r;return t==="elementStroke"&&(r=X_),t==="elementBackground"&&(r=K_),t==="canvasBackground"&&(r=V_),n&&(r=n),r?cf("div",{className:"color-picker__top-picks",children:r.map(a=>cf("button",{className:Y_("color-picker__button",{active:a===o,"is-transparent":a==="transparent"||!a,"has-outline":!Z_(a,$_)}),style:{"--swatch-color":a},type:"button",title:a,onClick:()=>e(a),"data-testid":`color-top-pick-${a}`,children:cf("div",{className:"color-picker__button-outline"})},a))}):(console.error("Invalid type for TopPicks"),null)};import{jsx as Yo,jsxs as Hm}from"react/jsx-runtime";var J_=({type:e,color:t,onChange:o,label:n,elements:r,palette:a=e2,updateData:i,getOpenPopup:s,appState:l})=>{let{container:c}=Qe(),m=Dt(),p=m!=="full",d=m==="mobile",[,u]=le(Wo),[h,g]=le(Yr),x=Hm("div",{children:[Yo(xs,{children:f("colorPicker.hexCode")}),Yo(Hv,{color:t||"",label:n,onChange:w=>{o(w)},colorPickerType:e,placeholder:f("colorPicker.color")})]}),E=Qv(null),y=()=>{E.current?.focus()};return Yo(gr,{container:c,style:{maxWidth:"13rem"},preventAutoFocusOnTouch:!!l.editingTextElement,onFocusOutside:w=>{q_(w.target)||y(),w.preventDefault()},onPointerDownOutside:w=>{h&&w.preventDefault()},onClose:()=>{s()===e&&i({openPopup:null}),u(null),l.editingTextElement&&setTimeout(()=>{let w=document.querySelector(".excalidraw-wysiwyg");w&&w.focus()},0)},children:a?Yo(Kv,{ref:E,palette:a,color:t,onChange:w=>{let v=l.editingTextElement?Fm():null;o(w),l.editingTextElement&&v&&mc(v)},onEyeDropperToggle:w=>{g(v=>w?(v=v||{keepOpenOnAlt:!0,onSelect:o,colorPickerType:e},v.keepOpenOnAlt=!0,v):w===!1||v?null:{keepOpenOnAlt:!1,onSelect:o,colorPickerType:e})},onEscape:w=>{h?g(null):i({openPopup:null})},type:e,elements:r,updateData:i,showTitle:p,showHotKey:!d,children:x}):x})},Q_=({label:e,color:t,type:o,mode:n="background",onToggle:r,editingTextElement:a})=>{let i=Dt(),s=i!=="full",l=i==="mobile",c=m=>{m.preventDefault(),m.stopPropagation(),a&&Bv(),r()};return Hm(qv.Trigger,{type:"button",className:Jv("color-picker__button active-color properties-trigger",{"is-transparent":!t||t==="transparent","has-outline":!t||!jv(t,Zv),"compact-sizing":s,"mobile-border":l}),"aria-label":e,style:t?{"--swatch-color":t}:void 0,title:o==="elementStroke"?f("labels.showStroke"):f("labels.showBackground"),"data-openpopup":o,onClick:c,children:[Yo("div",{className:"color-picker__button-outline",children:!t&&$E}),s&&t&&n==="stroke"&&Yo("div",{className:"color-picker__button-background",children:Yo("span",{style:{color:t&&jv(t,Zv)?"#fff":"#111"},children:gv})})]})},fc=({type:e,color:t,onChange:o,label:n,elements:r,palette:a=e2,topPicks:i,updateData:s,appState:l})=>{let c=Qv(l.openPopup);j_(()=>{c.current=l.openPopup},[l.openPopup]);let p=Dt()!=="full";return Yo("div",{children:Hm("div",{role:"dialog","aria-modal":"true",className:Jv("color-picker-container",{"color-picker-container--no-top-picks":p}),children:[!p&&Yo(Xv,{activeColor:t,onChange:o,type:e,topPicks:i}),!p&&Yo(Dm,{}),Hm(qv.Root,{open:l.openPopup===e,onOpenChange:d=>{d&&s({openPopup:e})},children:[Yo(Q_,{color:t,label:n,type:e,mode:e==="elementStroke"?"stroke":"background",editingTextElement:!!l.editingTextElement,onToggle:()=>{l.openPopup===e?s({openPopup:null}):l.openPopup?s({openPopup:e}):s({openPopup:e})}}),l.openPopup===e&&Yo(J_,{type:e,color:t,onChange:o,label:n,elements:r,palette:a,updateData:s,getOpenPopup:()=>c.current,appState:l})]})]})})};import{Popover as SD}from"radix-ui";import MD from"clsx";import PD,{useCallback as AD,useMemo as LD}from"react";import{FONT_FAMILY as uf}from"@orangecatai/common";import bD,{useMemo as jr,useState as xD,useRef as r2,useEffect as a2,useCallback as i2,useSyncExternalStore as yD}from"react";import{arrayToList as ED,debounce as wD,FONT_FAMILY as Xa,getFontFamilyString as vD}from"@orangecatai/common";import eD from"clsx";import tD from"react";import{jsx as oD,jsxs as nD}from"react/jsx-runtime";var Gm=tD.forwardRef(({className:e,placeholder:t,onChange:o},n)=>nD("div",{className:eD("QuickSearch__wrapper",e),children:[Mo,oD("input",{ref:n,className:"QuickSearch__input",type:"text",placeholder:t,onChange:r=>o(r.target.value.trim().toLowerCase())})]}));import rD from"clsx";import{Children as aD}from"react";import{jsx as t2}from"react/jsx-runtime";var Um=({className:e,placeholder:t,children:o})=>{let n=!aD.count(o);return t2("div",{className:rD("ScrollableList__wrapper",e),role:"menu",children:n?t2("div",{className:"empty",children:t}):o})};import{jsx as iD,jsxs as sD}from"react/jsx-runtime";var o2=({children:e,className:t="",style:o,title:n})=>sD("div",{className:`dropdown-menu-group ${t}`,style:o,children:[n&&iD("p",{className:"dropdown-menu-group-title",children:n}),e]}),bc=o2;o2.displayName="DropdownMenuGroup";import{THEME as hD}from"@orangecatai/common";import{DropdownMenu as fD}from"radix-ui";import lD,{useContext as cD}from"react";import{composeEventHandlers as dD}from"@orangecatai/common";var df=lD.createContext({}),Xr=(e="",t=!1,o=!1)=>`dropdown-menu-item dropdown-menu-item-base ${e} ${t?"dropdown-menu-item--selected":""} ${o?"dropdown-menu-item--hovered":""}`.trim(),Wm=e=>{let t=cD(df);return dD(e,o=>{t.onSelect?.(o)})};import{jsx as mD}from"react/jsx-runtime";var xc=({children:e,...t})=>mD("span",{...t,style:{textOverflow:"ellipsis",overflow:"hidden",whiteSpace:"nowrap",...t.style},children:e});import{Fragment as uD,jsx as yc,jsxs as gD}from"react/jsx-runtime";var pD=({textStyle:e,icon:t,shortcut:o,children:n,badge:r})=>{let a=Te();return gD(uD,{children:[t&&yc("div",{className:"dropdown-menu-item__icon",children:t}),yc("div",{style:e,className:"dropdown-menu-item__text",children:yc(xc,{children:n})}),r&&yc("div",{className:"dropdown-menu-item__badge",children:r}),o&&a.formFactor!=="phone"&&yc("div",{className:"dropdown-menu-item__shortcut",children:o})]})},Zr=pD;import{jsx as Ym}from"react/jsx-runtime";var mf=({icon:e,badge:t,value:o,children:n,shortcut:r,className:a,selected:i,onSelect:s,...l})=>{let c=Wm(s);return Ym(fD.Item,{className:"radix-menu-item",onSelect:c,asChild:!0,children:Ym("button",{...l,value:o,className:Xr(a,i),title:l.title??l["aria-label"],children:Ym(Zr,{icon:e,shortcut:r,badge:t,children:n})})})};mf.displayName="DropdownMenuItem";var Es={GREEN:"green",RED:"red",BLUE:"blue"},$m=({type:e=Es.BLUE,children:t})=>{let{theme:o}=$o(),n={display:"inline-flex",marginLeft:"auto",padding:"2px 4px",borderRadius:6,fontSize:9,fontFamily:"Cascadia, monospace",border:o===hD.LIGHT?"1.5px solid white":"none"};switch(e){case Es.GREEN:Object.assign(n,{backgroundColor:"var(--background-color-badge)",color:"var(--color-badge)"});break;case Es.RED:Object.assign(n,{backgroundColor:"pink",color:"darkred"});break;case Es.BLUE:default:Object.assign(n,{background:"var(--color-promo)",color:"var(--color-surface-lowest)"})}return Ym("div",{className:"DropDownMenuItemBadge",style:n,children:t})};$m.displayName="DropdownMenuItemBadge";mf.Badge=$m;var to=mf;import{KEYS as ws}from"@orangecatai/common";var n2=({event:e,inputRef:t,hoveredFont:o,filteredFonts:n,onClose:r,onSelect:a,onHover:i})=>{if(!e[ws.CTRL_OR_CMD]&&e.shiftKey&&e.key.toLowerCase()===ws.F)return t.current?.focus(),!0;if(e.key===ws.ESCAPE)return r(),!0;if(e.key===ws.ENTER)return o?.value&&a(o.value),!0;if(e.key===ws.ARROW_DOWN)return o?.next?i(o.next.value):n[0]?.value&&i(n[0].value),!0;if(e.key===ws.ARROW_UP)return o?.prev?i(o.prev.value):n[n.length-1]?.value&&i(n[n.length-1].value),!0};import{jsx as hr,jsxs as TD}from"react/jsx-runtime";var ID=e=>{switch(e){case Xa.Excalifont:case Xa.Virgil:return Bn;case Xa.Nunito:case Xa.Helvetica:return ac;case Xa["Lilita One"]:return Aw;case Xa["Comic Shanns"]:case Xa.Cascadia:return wm;default:return ac}},s2=bD.memo(({selectedFontFamily:e,hoveredFontFamily:t,onSelect:o,onHover:n,onLeave:r,onOpen:a,onClose:i})=>{let{container:s}=Qe(),l=tt(),{fonts:c}=l,{showDeprecatedFonts:m}=Hn(),p=Dt(),[d,u]=xD(""),h=r2(null),g=yD(Ho.subscribeToCustomFonts,Ho.getCustomFontVersion),x=jr(()=>Array.from(Ho.registered.entries()).filter(([M,{metadata:B}])=>!B.private&&!B.fallback).map(([M,{metadata:B,fontFaces:O}])=>{let N={value:M,icon:ID(M),text:O[0]?.fontFace?.family??"Unknown"};return B.deprecated&&Object.assign(N,{deprecated:B.deprecated,badge:{type:Es.RED,placeholder:f("fontList.badge.old")}}),N}).sort((M,B)=>M.text.toLowerCase()>B.text.toLowerCase()?1:-1),[g]),E=jr(()=>new Set(c.getSceneFamilies()),[e]),y=jr(()=>x.filter(M=>E.has(M.value)),[x,E]),w=jr(()=>x.filter(M=>!E.has(M.value)&&(m||!M.deprecated)),[x,E,m]),v=jr(()=>ED([...y,...w].filter(M=>M.text?.toLowerCase().includes(d))),[y,w,d]),I=jr(()=>{let M;return t?M=v.find(B=>B.value===t):e&&(M=v.find(B=>B.value===e)),!M&&d&&(v[0]?.value?n(v[0].value):r()),M},[t,e,d,v,n,r]),C=i2(M=>{let B=null;if(l.state.editingTextElement){let O=document.querySelector(".excalidraw-wysiwyg");O&&(B={start:O.selectionStart,end:O.selectionEnd})}o(M),l.state.editingTextElement&&B&&setTimeout(()=>{let O=document.querySelector(".excalidraw-wysiwyg");O&&B&&(O.focus(),O.selectionStart=B.start,O.selectionEnd=B.end)},0)},[o,l.state.editingTextElement]),P=i2(M=>{n2({event:M,inputRef:h,hoveredFont:I,filteredFonts:v,onSelect:C,onHover:n,onClose:i})&&(M.preventDefault(),M.stopPropagation())},[I,v,C,n,i]);a2(()=>(a(),()=>{i()}),[]);let S=jr(()=>v.filter(M=>E.has(M.value)),[v,E]),D=jr(()=>v.filter(M=>!E.has(M.value)),[v,E]),_=({font:M,order:B})=>{let O=r2(null),N=M.value===I?.value,z=M.value===e;return a2(()=>{N&&(B===0?O.current?.scrollIntoView?.({block:"end"}):O.current?.scrollIntoView?.({block:"nearest"}))},[N,B]),hr("button",{ref:O,type:"button",value:M.value,className:Xr("",z,N),title:M.text,tabIndex:z?0:-1,onClick:L=>{C(Number(L.currentTarget.value))},onMouseMove:()=>{I?.value!==M.value&&n(M.value)},children:hr(Zr,{icon:M.icon,badge:M.badge&&hr($m,{type:M.badge.type,children:M.badge.placeholder}),textStyle:{fontFamily:vD({fontFamily:M.value})},children:M.text})})},k=[];return S.length&&k.push(hr(bc,{title:f("fontList.sceneFonts"),children:S.map((M,B)=>hr(_,{font:M,order:B},M.value))},"group_1")),D.length&&k.push(hr(bc,{title:f("fontList.availableFonts"),children:D.map((M,B)=>hr(_,{font:M,order:B+S.length},M.value))},"group_2")),TD(gr,{className:"properties-content",container:s,style:{width:"15rem"},onClose:()=>{i(),l.state.editingTextElement&&setTimeout(()=>{let M=document.querySelector(".excalidraw-wysiwyg");M&&M.focus()},0)},onPointerLeave:r,onKeyDown:P,preventAutoFocusOnTouch:!!l.state.editingTextElement,children:[p==="full"&&hr(Gm,{ref:h,placeholder:f("quickSearch.placeholder"),onChange:wD(u,20)}),hr(Um,{className:"dropdown-menu fonts manual-hover",placeholder:f("fontList.empty"),children:k.length?k:null})]})},(e,t)=>e.selectedFontFamily===t.selectedFontFamily&&e.hoveredFontFamily===t.hoveredFontFamily);import{Popover as CD}from"radix-ui";import{MOBILE_ACTION_BUTTON_BG as kD}from"@orangecatai/common";import{jsx as pf}from"react/jsx-runtime";var l2=({selectedFontFamily:e,isOpened:t=!1,compactMode:o=!1})=>{let n=Ce(),r=o?{...kD,width:"2rem",height:"2rem"}:{};return pf(CD.Trigger,{asChild:!0,children:pf("div",{"data-openpopup":"fontFamily",className:"properties-trigger",children:pf(hs,{standalone:!0,icon:Fn,title:f("labels.showFonts"),className:"properties-trigger",testId:"font-family-show-fonts",active:t,onClick:()=>{n(a=>({openPopup:a.openPopup==="fontFamily"?null:a.openPopup}))},style:{border:"none",...r}})})})};import{jsx as Ec,jsxs as c2}from"react/jsx-runtime";var d2=[{value:uf.Excalifont,icon:Bn,text:f("labels.handDrawn"),testId:"font-family-hand-drawn"},{value:uf.Nunito,icon:ac,text:f("labels.normal"),testId:"font-family-normal"},{value:uf["Comic Shanns"],icon:wm,text:f("labels.code"),testId:"font-family-code"}],yse=new Set(d2.map(e=>e.value));var m2=PD.memo(({isOpened:e,selectedFontFamily:t,hoveredFontFamily:o,onSelect:n,onHover:r,onLeave:a,onPopupChange:i,compactMode:s=!1})=>{let l=LD(()=>d2,[]),c=AD(m=>{m&&n(m)},[n]);return c2("div",{role:"dialog","aria-modal":"true",className:MD("FontPicker__container",{"FontPicker__container--compact":s}),children:[!s&&Ec("div",{className:"buttonList",children:Ec(Uo,{type:"button",options:l,value:t,onClick:c})}),!s&&Ec(Dm,{}),c2(SD.Root,{open:e,onOpenChange:i,children:[Ec(l2,{selectedFontFamily:t,isOpened:e,compactMode:s}),e&&Ec(s2,{selectedFontFamily:t,hoveredFontFamily:o,onSelect:c,onHover:r,onLeave:a,onOpen:()=>i(!0),onClose:()=>i(!1)})]})]})},(e,t)=>e.isOpened===t.isOpened&&e.selectedFontFamily===t.selectedFontFamily&&e.hoveredFontFamily===t.hoveredFontFamily);import{Popover as gf}from"radix-ui";import ND from"clsx";import Vm,{useEffect as BD}from"react";import{isArrowKey as FD,KEYS as fr}from"@orangecatai/common";import{jsx as _D}from"react/jsx-runtime";var Gn=({className:e,icon:t,size:o="1em"})=>_D("span",{className:e,style:{width:o,height:"100%",margin:"0 0.5ex 0 0.5ex",display:"inline-flex",lineHeight:0,verticalAlign:"middle",flex:"0 0 auto"},children:t});import{Fragment as RD,jsx as p2,jsxs as u2}from"react/jsx-runtime";var DD=({label:e,open:t,openTrigger:o,children:n,className:r,showCollapsedIcon:a=!0})=>u2(RD,{children:[u2("div",{style:{cursor:"pointer",display:"flex",justifyContent:"space-between",alignItems:"center"},className:r,onClick:o,children:[e,a&&p2(Gn,{icon:t?mv:Tm})]}),t&&p2("div",{style:{display:"flex",flexDirection:"column"},children:n})]}),wc=DD;import{jsx as Za,jsxs as hf}from"react/jsx-runtime";var OD=Pe(!1);function zD({options:e,value:t,label:o,onChange:n,onClose:r,numberOfOptionsToAlwaysShow:a=e.length}){let i=Te(),{container:s}=Qe(),l=g=>{let x=e.find(E=>E.keyBinding===g.key.toLowerCase());if(!(g.metaKey||g.altKey||g.ctrlKey)&&x)n(x.value),g.preventDefault();else if(g.key===fr.TAB){let E=e.findIndex(w=>w.value===t),y=g.shiftKey?(e.length+E-1)%e.length:(E+1)%e.length;n(e[y].value)}else if(FD(g.key)){let E=ur().rtl,y=e.findIndex(w=>w.value===t);if(y!==-1){let w=e.length,v=y;switch(g.key){case(E?fr.ARROW_LEFT:fr.ARROW_RIGHT):v=(y+1)%w;break;case(E?fr.ARROW_RIGHT:fr.ARROW_LEFT):v=(w+y-1)%w;break;case fr.ARROW_DOWN:{v=(y+(a??1))%w;break}case fr.ARROW_UP:{v=(w+y-(a??1))%w;break}}n(e[v].value)}g.preventDefault()}else(g.key===fr.ESCAPE||g.key===fr.ENTER)&&(g.preventDefault(),r());g.nativeEvent.stopImmediatePropagation(),g.stopPropagation()},[c,m]=le(OD),p=Vm.useMemo(()=>e.slice(0,a),[e,a]),d=Vm.useMemo(()=>e.slice(a),[e,a]);BD(()=>{p.some(g=>g.value===t)||m(!0)},[t,p,m]);let u=g=>Za("div",{className:"picker-content",children:g.map((x,E)=>hf("button",{type:"button",className:ND("picker-option",{active:t===x.value}),onClick:y=>{n(x.value)},title:`${x.text} ${x.keyBinding&&`\u2014 ${x.keyBinding.toUpperCase()}`}`,"aria-label":x.text||"none","aria-keyshortcuts":x.keyBinding||void 0,ref:y=>{t===x.value&&setTimeout(()=>{y?.focus()},0)},children:[x.icon,x.keyBinding&&Za("span",{className:"picker-keybinding",children:x.keyBinding})]},x.text))}),h=i.formFactor==="phone";return Za(gf.Content,{side:h?"right":"bottom",align:"start",sideOffset:h?8:12,style:{zIndex:"var(--zIndex-ui-styles-popup)"},onKeyDown:l,collisionBoundary:s??void 0,children:hf("div",{className:"picker",role:"dialog","aria-modal":"true","aria-label":o,children:[u(p),d.length>0&&Za(wc,{label:f("labels.more_options"),open:c,openTrigger:()=>{m(g=>!g)},className:"picker-collapsible",children:u(d)})]})})}function ff({value:e,label:t,options:o,onChange:n,group:r="",numberOfOptionsToAlwaysShow:a}){let[i,s]=Vm.useState(!1),l=Vm.useRef(null);return Za("div",{children:hf(gf.Root,{open:i,onOpenChange:c=>s(c),children:[Za(gf.Trigger,{name:r,type:"button","aria-label":t,onClick:()=>s(!i),ref:l,className:i?"active":"",children:o.find(c=>c.value===e)?.icon}),i&&Za(zD,{options:o,value:e,label:t,onChange:n,onClose:()=>{s(!1)},numberOfOptionsToAlwaysShow:a})]})})}import g2,{useEffect as HD}from"react";import{jsx as bf,jsxs as h2}from"react/jsx-runtime";var f2=({updateData:e,app:t,testId:o})=>{let n=g2.useRef(null),r=g2.useRef(null),a=t.scene.getSelectedElements(t.state),i=!0,s=a.at(0),c=a.reduce((m,p)=>(m!=null&&m!==p.opacity&&(i=!1),m==null||m>p.opacity?p.opacity:m),s?.opacity??null)??t.state.currentItemOpacity;return HD(()=>{if(n.current&&r.current){let m=n.current,p=r.current,d=m.offsetWidth,u=15,h=c/100*(d-u)+u/2;p.style.left=`${h}px`,m.style.background=`linear-gradient(to right, var(--color-slider-track) 0%, var(--color-slider-track) ${c}%, var(--button-bg) ${c}%, var(--button-bg) 100%)`}},[c]),h2("label",{className:"control-label",children:[f("labels.opacity"),h2("div",{className:"range-wrapper",children:[bf("input",{style:{"--color-slider-track":i?void 0:"var(--button-bg)"},ref:n,type:"range",min:"0",max:"100",step:"10",onChange:m=>{e(+m.target.value)},value:c,className:"range-input","data-testid":o}),bf("div",{className:"value-bubble",ref:r,children:c!==0?c:null}),bf("div",{className:"zero-label",children:"0"})]})]})};import{Fragment as Sf,jsx as ge,jsxs as no}from"react/jsx-runtime";var I2=.1,Is=e=>{let t=c8(e.editorInterface);return{stylesPanelMode:t,isCompact:t!=="full",isMobile:t==="mobile"}},oo=(e,t,o,n=!1)=>{let r=vf(de(e,t,{includeBoundTextElement:n}));return e.map(a=>r.get(a.id)||a.id===t.editingTextElement?.id?o(a):a)},Kt=function(e,t,o,n,r){let a=t.state.editingTextElement,i=w2(e),s=null;if(a&&(s=o(a)),!s)if(Ge(i,t.state)){let c=t.scene.getSelectedElements(t.state),m=n===!0?c:c.filter(p=>n(p));s=t8(m,o)??(typeof r=="function"?r(!0):r)}else s=typeof r=="function"?r(!1):r;return s},d8=(e,t,o)=>r8(t)||!t.autoResize?t:o.mutateElement(t,{x:e.textAlign==="left"?e.x:e.x+(e.width-t.width)/(e.textAlign==="center"?2:1),y:e.y+(e.height-t.height)/2}),Tf=(e,t,o,n,r)=>{let a=new Set,i=oo(e,t,s=>{if(fo(s)){let l=n(s);a.add(l);let c=kt(s,{fontSize:l});return vc(c,o.scene.getContainerElement(s),o.scene),c=d8(s,c,o.scene),c}return s},!0);return de(e,t,{includeBoundTextElement:!0}).forEach(s=>{fo(s)&&n8(s,o.scene)}),{elements:i,appState:{...t,currentItemFontSize:a.size===1?[...a][0]:r??t.currentItemFontSize},captureUpdate:St.IMMEDIATELY}},m8=W({name:"changeStrokeColor",label:"labels.stroke",trackEvent:!1,perform:(e,t,o)=>({...o?.currentItemStrokeColor&&{elements:oo(e,t,n=>i8(n.type)?kt(n,{strokeColor:o.currentItemStrokeColor}):n,!0)},appState:{...t,...o},captureUpdate:o?.currentItemStrokeColor?St.IMMEDIATELY:St.EVENTUALLY}),PanelComponent:({elements:e,appState:t,updateData:o,app:n,data:r})=>{let{stylesPanelMode:a}=Is(n);return no(Sf,{children:[a==="full"&&ge("h3",{"aria-hidden":"true",children:f("labels.stroke")}),ge(fc,{topPicks:KD,palette:VD,type:"elementStroke",label:f("labels.stroke"),color:Kt(e,n,i=>i.strokeColor,!0,i=>i?null:t.currentItemStrokeColor),onChange:i=>o({currentItemStrokeColor:i}),elements:e,appState:t,updateData:o})]})}}),p8=W({name:"changeBackgroundColor",label:"labels.changeBackground",trackEvent:!1,perform:(e,t,o,n)=>{if(!o?.currentItemBackgroundColor)return{appState:{...t,...o},captureUpdate:St.EVENTUALLY};let r,a=n.scene.getSelectedElements(t);if(!e8(o.currentItemBackgroundColor)&&a.every(s=>y2(s)&&o8(s.points))){let s=vf(a);r=e.map(l=>s.has(l.id)&&y2(l)?kt(l,{backgroundColor:o.currentItemBackgroundColor,...l8(l,!0)}):l)}else r=oo(e,t,s=>kt(s,{backgroundColor:o.currentItemBackgroundColor}));return{elements:r,appState:{...t,...o},captureUpdate:St.IMMEDIATELY}},PanelComponent:({elements:e,appState:t,updateData:o,app:n,data:r})=>{let{stylesPanelMode:a}=Is(n);return no(Sf,{children:[a==="full"&&ge("h3",{"aria-hidden":"true",children:f("labels.background")}),ge(fc,{topPicks:$D,palette:YD,type:"elementBackground",label:f("labels.background"),color:Kt(e,n,i=>i.backgroundColor,!0,i=>i?null:t.currentItemBackgroundColor),onChange:i=>o({currentItemBackgroundColor:i}),elements:e,appState:t,updateData:o})]})}}),u8=W({name:"changeFillStyle",label:"labels.fill",trackEvent:!1,perform:(e,t,o,n)=>(be("element","changeFillStyle",`${o} (${n.editorInterface.formFactor==="phone"?"mobile":"desktop"})`),{elements:oo(e,t,r=>kt(r,{fillStyle:o})),appState:{...t,currentItemFillStyle:o},captureUpdate:St.IMMEDIATELY}),PanelComponent:({elements:e,appState:t,updateData:o,app:n})=>{let r=de(e,t),a=r.length>0&&r.every(i=>i.fillStyle==="zigzag");return no("fieldset",{children:[ge("legend",{children:f("labels.fill")}),ge("div",{className:"buttonList",children:ge(Uo,{type:"button",options:[{value:"hachure",text:`${a?f("labels.zigzag"):f("labels.hachure")} (${G("Alt-Click")})`,icon:a?tw:ow,active:a?!0:void 0,testId:"fill-hachure"},{value:"cross-hatch",text:f("labels.crossHatch"),icon:nw,testId:"fill-cross-hatch"},{value:"solid",text:f("labels.solid"),icon:rw,testId:"fill-solid"}],value:Kt(e,n,i=>i.fillStyle,i=>i.hasOwnProperty("fillStyle"),i=>i?null:t.currentItemFillStyle),onClick:(i,s)=>{let l=s.altKey&&i==="hachure"&&r.every(c=>c.fillStyle==="hachure")?"zigzag":i;o(l)}})})]})}}),g8=W({name:"changeStrokeWidth",label:"labels.strokeWidth",trackEvent:!1,perform:(e,t,o)=>({elements:oo(e,t,n=>kt(n,{strokeWidth:o})),appState:{...t,currentItemStrokeWidth:o},captureUpdate:St.IMMEDIATELY}),PanelComponent:({elements:e,appState:t,updateData:o,app:n,data:r})=>no("fieldset",{children:[ge("legend",{children:f("labels.strokeWidth")}),ge("div",{className:"buttonList",children:ge(Uo,{group:"stroke-width",options:[{value:Ef.thin,text:f("labels.thin"),icon:Dh,testId:"strokeWidth-thin"},{value:Ef.bold,text:f("labels.bold"),icon:aw,testId:"strokeWidth-bold"},{value:Ef.extraBold,text:f("labels.extraBold"),icon:iw,testId:"strokeWidth-extraBold"}],value:Kt(e,n,a=>a.strokeWidth,a=>a.hasOwnProperty("strokeWidth"),a=>a?null:t.currentItemStrokeWidth),onChange:a=>o(a)})})]})}),h8=W({name:"changeSloppiness",label:"labels.sloppiness",trackEvent:!1,perform:(e,t,o)=>({elements:oo(e,t,n=>kt(n,{seed:qD(),roughness:o})),appState:{...t,currentItemRoughness:o},captureUpdate:St.IMMEDIATELY}),PanelComponent:({elements:e,appState:t,updateData:o,app:n,data:r})=>no("fieldset",{children:[ge("legend",{children:f("labels.sloppiness")}),ge("div",{className:"buttonList",children:ge(Uo,{group:"sloppiness",options:[{value:0,text:f("labels.architect"),icon:cw},{value:1,text:f("labels.artist"),icon:dw},{value:2,text:f("labels.cartoonist"),icon:mw}],value:Kt(e,n,a=>a.roughness,a=>a.hasOwnProperty("roughness"),a=>a?null:t.currentItemRoughness),onChange:a=>o(a)})})]})}),Tle=W({name:"changeStrokeStyle",label:"labels.strokeStyle",trackEvent:!1,perform:(e,t,o)=>({elements:oo(e,t,n=>kt(n,{strokeStyle:o})),appState:{...t,currentItemStrokeStyle:o},captureUpdate:St.IMMEDIATELY}),PanelComponent:({elements:e,appState:t,updateData:o,app:n,data:r})=>no("fieldset",{children:[ge("legend",{children:f("labels.strokeStyle")}),ge("div",{className:"buttonList",children:ge(Uo,{group:"strokeStyle",options:[{value:"solid",text:f("labels.strokeStyle_solid"),icon:Dh},{value:"dashed",text:f("labels.strokeStyle_dashed"),icon:sw},{value:"dotted",text:f("labels.strokeStyle_dotted"),icon:lw}],value:Kt(e,n,a=>a.strokeStyle,a=>a.hasOwnProperty("strokeStyle"),a=>a?null:t.currentItemStrokeStyle),onChange:a=>o(a)})})]})}),f8=W({name:"changeOpacity",label:"labels.opacity",trackEvent:!1,perform:(e,t,o)=>({elements:oo(e,t,n=>kt(n,{opacity:o}),!0),appState:{...t,currentItemOpacity:o},captureUpdate:St.IMMEDIATELY}),PanelComponent:({app:e,updateData:t})=>ge(f2,{updateData:t,app:e,testId:"opacity"})}),b8=W({name:"changeFontSize",label:"labels.fontSize",trackEvent:!1,perform:(e,t,o,n)=>Tf(e,t,n,()=>(If(o,"actionChangeFontSize: Expected a font size value"),o),o),PanelComponent:({elements:e,appState:t,updateData:o,app:n,data:r})=>{let{isCompact:a}=Is(n);return no("fieldset",{children:[ge("legend",{children:f("labels.fontSize")}),ge("div",{className:"buttonList",children:ge(Uo,{group:"font-size",options:[{value:Xm.sm,text:f("labels.small"),icon:kw,testId:"fontSize-small"},{value:Xm.md,text:f("labels.medium"),icon:Sw,testId:"fontSize-medium"},{value:Xm.lg,text:f("labels.large"),icon:Mw,testId:"fontSize-large"},{value:Xm.xl,text:f("labels.veryLarge"),icon:Pw,testId:"fontSize-veryLarge"}],value:Kt(e,n,i=>{if(fo(i))return i.fontSize;let s=qr(i,n.scene.getNonDeletedElementsMap());return s?s.fontSize:null},i=>fo(i)||qr(i,n.scene.getNonDeletedElementsMap())!==null,i=>i?null:t.currentItemFontSize||ZD),onChange:i=>{pc(()=>o(i),a,!!t.editingTextElement,r?.onPreventClose)}})})]})}}),Cf=W({name:"decreaseFontSize",label:"labels.decreaseFontSize",icon:Va,trackEvent:!1,perform:(e,t,o,n)=>Tf(e,t,n,r=>Math.round(1/(1+I2)*r.fontSize)),keyTest:e=>e[vs.CTRL_OR_CMD]&&e.shiftKey&&(e.key===vs.CHEVRON_LEFT||e.key===vs.COMMA)}),kf=W({name:"increaseFontSize",label:"labels.increaseFontSize",icon:Va,trackEvent:!1,perform:(e,t,o,n)=>Tf(e,t,n,r=>Math.round(r.fontSize*(1+I2))),keyTest:e=>e[vs.CTRL_OR_CMD]&&e.shiftKey&&(e.key===vs.CHEVRON_RIGHT||e.key===vs.PERIOD)}),x8=W({name:"changeFontFamily",label:"labels.fontFamily",trackEvent:!1,perform:(e,t,o,n)=>{let{cachedElements:r,resetAll:a,resetContainers:i,...s}=o;if(a)return{elements:oo(e,t,g=>{let x=r?.get(g.id);return x?kt(g,{...x}):g},!0),appState:{...t,...s},captureUpdate:St.NEVER};If(o,"actionChangeFontFamily: value must be defined");let{currentItemFontFamily:l,currentHoveredFontFamily:c}=o,m=St.EVENTUALLY,p,d=!1;if(l)p=l,m=St.IMMEDIATELY;else if(c){p=c,m=St.EVENTUALLY;let h=de(e,t,{includeBoundTextElement:!0}).filter(g=>fo(g));if(h.length>200)d=!0;else{let g=0,x=0;for(;g<h.length&&x<5e3;){let E=h[g];x+=E?.originalText.length||0,g++}x>5e3&&(d=!0)}}let u={appState:{...t,...s},captureUpdate:m};if(p&&!d){let h=new Map,g=new Set,x=!1,E=Array.from(Ho.loadedFontsCache.values()),y=Object.entries(jD).find(([I,C])=>C===p)?.[0];c&&y&&E.some(I=>I.startsWith(y))&&(x=!0),Object.assign(u,{elements:oo(e,t,I=>{if(fo(I)&&(I.fontFamily!==p||l)){let C=kt(I,{fontFamily:p,lineHeight:QD(p)}),P=r?.get(I.containerId||"")||{},S=n.scene.getContainerElement(I);return i&&S&&P&&n.scene.mutateElement(S,{...P}),x||(g=new Set([...g,...Array.from(C.originalText)])),h.set(C,S),C}return I},!0)});let w=`10px ${JD({fontFamily:p})}`,v=Array.from(g.values()).join();if(x||window.document.fonts.check(w,v))for(let[I,C]of h)vc(I,C,n.scene);else window.document.fonts.load(w,v).then(I=>{for(let[C,P]of h){let S=n.scene.getElement(C.id),D=P?n.scene.getElement(P.id):null;S&&vc(S,D,n.scene)}n.fonts.onLoaded(I)})}return u},PanelComponent:({elements:e,appState:t,app:o,updateData:n})=>{let r=yf(new Map),a=yf(null),[i,s]=WD({}),l=yf(!0),{stylesPanelMode:c,isCompact:m}=Is(o),p=UD(()=>{let d=(u,h)=>Kt(u,o,g=>{if(fo(g))return g.fontFamily;let x=qr(g,h);return x?x.fontFamily:null},g=>fo(g)||qr(g,h)!==null,g=>g?null:t.currentItemFontFamily||XD);return i.openPopup==="fontFamily"&&t.openPopup==="fontFamily"?d(Array.from(r.current?.values()??[]),r.current):!i.openPopup&&t.openPopup!=="fontFamily"?d(e,o.scene.getNonDeletedElementsMap()):a.current},[i.openPopup,t,e,o]);return xf(()=>{a.current=p},[p]),xf(()=>{Object.keys(i).length&&(n(i),s({}))},[i]),xf(()=>(l.current=!1,()=>{l.current=!0}),[]),no(Sf,{children:[c==="full"&&ge("legend",{children:f("labels.fontFamily")}),ge(m2,{isOpened:t.openPopup==="fontFamily",selectedFontFamily:p,hoveredFontFamily:t.currentHoveredFontFamily,compactMode:c!=="full",onSelect:d=>{pc(()=>{s({openPopup:null,currentHoveredFontFamily:null,currentItemFontFamily:d}),r.current.clear()},m,!!t.editingTextElement)},onHover:d=>{s({currentHoveredFontFamily:d,cachedElements:new Map(r.current),resetContainers:!0})},onLeave:()=>{s({currentHoveredFontFamily:null,cachedElements:new Map(r.current),resetAll:!0})},onPopupChange:d=>{if(d){r.current.clear();let{editingTextElement:u}=t;if(u?.type==="text"){let h=o.scene.getElement(u.id);r.current.set(u.id,kt(h||u,{},!0))}else{let h=de(e,t,{includeBoundTextElement:!0});for(let g of h)r.current.set(g.id,kt(g,{},!0))}s({...i,openPopup:"fontFamily"})}else{let u={currentHoveredFontFamily:null,cachedElements:new Map(r.current),resetAll:!0};s({...u}),r.current.clear(),m&&t.editingTextElement&&mc(null)}}})]})}}),y8=W({name:"changeTextAlign",label:"Change text alignment",trackEvent:!1,perform:(e,t,o,n)=>({elements:oo(e,t,r=>{if(fo(r)){let a=kt(r,{textAlign:o});return vc(a,n.scene.getContainerElement(r),n.scene),a}return r},!0),appState:{...t,currentItemTextAlign:o},captureUpdate:St.IMMEDIATELY}),PanelComponent:({elements:e,appState:t,updateData:o,app:n,data:r})=>{let a=n.scene.getNonDeletedElementsMap(),{isCompact:i}=Is(n);return no("fieldset",{children:[ge("legend",{children:f("labels.textAlign")}),ge("div",{className:"buttonList",children:ge(Uo,{group:"text-align",options:[{value:"left",text:f("labels.left"),icon:Lw,testId:"align-left"},{value:"center",text:f("labels.center"),icon:_w,testId:"align-horizontal-center"},{value:"right",text:f("labels.right"),icon:Dw,testId:"align-right"}],value:Kt(e,n,s=>{if(fo(s))return s.textAlign;let l=qr(s,a);return l?l.textAlign:null},s=>fo(s)||qr(s,a)!==null,s=>s?null:t.currentItemTextAlign),onChange:s=>{pc(()=>o(s),i,!!t.editingTextElement,r?.onPreventClose)}})})]})}}),E8=W({name:"changeVerticalAlign",label:"Change vertical alignment",trackEvent:{category:"element"},perform:(e,t,o,n)=>({elements:oo(e,t,r=>{if(fo(r)){let a=kt(r,{verticalAlign:o});return vc(a,n.scene.getContainerElement(r),n.scene),a}return r},!0),appState:{...t},captureUpdate:St.IMMEDIATELY}),PanelComponent:({elements:e,appState:t,updateData:o,app:n,data:r})=>{let{isCompact:a}=Is(n);return ge("fieldset",{children:ge("div",{className:"buttonList",children:ge(Uo,{group:"text-align",options:[{value:Km.TOP,text:f("labels.alignTop"),icon:ge(Rw,{theme:t.theme}),testId:"align-top"},{value:Km.MIDDLE,text:f("labels.centerVertically"),icon:ge(Bw,{theme:t.theme}),testId:"align-middle"},{value:Km.BOTTOM,text:f("labels.alignBottom"),icon:ge(Nw,{theme:t.theme}),testId:"align-bottom"}],value:Kt(e,n,i=>{if(fo(i)&&i.containerId)return i.verticalAlign;let s=qr(i,n.scene.getNonDeletedElementsMap());return s?s.verticalAlign:null},i=>fo(i)||qr(i,n.scene.getNonDeletedElementsMap())!==null,i=>i?null:Km.MIDDLE),onChange:i=>{pc(()=>o(i),a,!!t.editingTextElement,r?.onPreventClose)}})})})}}),Cle=W({name:"changeRoundness",label:"Change edge roundness",trackEvent:!1,perform:(e,t,o)=>({elements:oo(e,t,n=>v2(n)?n:kt(n,{roundness:o==="round"?{type:a8(n.type)?Zm.ADAPTIVE_RADIUS:Zm.PROPORTIONAL_RADIUS}:null})),appState:{...t,currentItemRoundness:o},captureUpdate:St.IMMEDIATELY}),PanelComponent:({elements:e,appState:t,updateData:o,app:n,renderAction:r})=>{let i=Hi(w2(e),t).some(s=>s.roundness?.type===Zm.LEGACY);return no("fieldset",{children:[ge("legend",{children:f("labels.edges")}),no("div",{className:"buttonList",children:[ge(Uo,{group:"edges",options:[{value:"sharp",text:f("labels.sharp"),icon:pw},{value:"round",text:f("labels.round"),icon:uw}],value:Kt(e,n,s=>i?null:s.roundness?"round":"sharp",s=>!jm(s)&&s.hasOwnProperty("roundness"),s=>s?null:t.currentItemRoundness),onChange:s=>o(s)}),r("togglePolygon")]})]})}}),E2=e=>[{value:null,text:f("labels.arrowhead_none"),keyBinding:"q",icon:ge(gw,{flip:e})},{value:"arrow",text:f("labels.arrowhead_arrow"),keyBinding:"w",icon:ge(hw,{flip:e})},{value:"triangle",text:f("labels.arrowhead_triangle"),icon:ge(yw,{flip:e}),keyBinding:"e"},{value:"triangle_outline",text:f("labels.arrowhead_triangle_outline"),icon:ge(Ew,{flip:e}),keyBinding:"r"},{value:"circle",text:f("labels.arrowhead_circle"),keyBinding:"a",icon:ge(fw,{flip:e})},{value:"circle_outline",text:f("labels.arrowhead_circle_outline"),keyBinding:"s",icon:ge(bw,{flip:e})},{value:"diamond",text:f("labels.arrowhead_diamond"),icon:ge(ww,{flip:e}),keyBinding:"d"},{value:"diamond_outline",text:f("labels.arrowhead_diamond_outline"),icon:ge(vw,{flip:e}),keyBinding:"f"},{value:"bar",text:f("labels.arrowhead_bar"),keyBinding:"z",icon:ge(xw,{flip:e})},{value:"crowfoot_one",text:f("labels.arrowhead_crowfoot_one"),icon:ge(Tw,{flip:e}),keyBinding:"x"},{value:"crowfoot_many",text:f("labels.arrowhead_crowfoot_many"),icon:ge(Iw,{flip:e}),keyBinding:"c"},{value:"crowfoot_one_or_many",text:f("labels.arrowhead_crowfoot_one_or_many"),icon:ge(Cw,{flip:e}),keyBinding:"v"}],kle=W({name:"changeArrowhead",label:"Change arrowheads",trackEvent:!1,perform:(e,t,o)=>(If(o,"actionChangeArrowhead: value must be defined"),{elements:oo(e,t,n=>{if(wf(n)){let{position:r,type:a}=o;if(r==="start")return kt(n,{startArrowhead:a});if(r==="end")return kt(n,{endArrowhead:a})}return n}),appState:{...t,[o.position==="start"?"currentItemStartArrowhead":"currentItemEndArrowhead"]:o.type},captureUpdate:St.IMMEDIATELY}),PanelComponent:({elements:e,appState:t,updateData:o,app:n})=>{let r=ur().rtl;return no("fieldset",{children:[ge("legend",{children:f("labels.arrowheads")}),no("div",{className:"iconSelectList buttonList",children:[ge(ff,{label:"arrowhead_start",options:E2(!r),value:Kt(e,n,a=>wf(a)&&Gi(a.type)?a.startArrowhead:t.currentItemStartArrowhead,!0,a=>a?null:t.currentItemStartArrowhead),onChange:a=>o({position:"start",type:a}),numberOfOptionsToAlwaysShow:4}),ge(ff,{label:"arrowhead_end",group:"arrowheads",options:E2(!!r),value:Kt(e,n,a=>wf(a)&&Gi(a.type)?a.endArrowhead:t.currentItemEndArrowhead,!0,a=>a?null:t.currentItemEndArrowhead),onChange:a=>o({position:"end",type:a}),numberOfOptionsToAlwaysShow:4})]})]})}}),w8=W({name:"changeArrowProperties",label:"Change arrow properties",trackEvent:!1,perform:(e,t,o,n)=>!1,PanelComponent:({elements:e,appState:t,updateData:o,app:n,renderAction:r})=>no("div",{className:"selected-shape-actions",children:[r("changeArrowhead"),r("changeArrowType")]})}),Sle=W({name:"changeArrowType",label:"Change arrow types",trackEvent:!1,perform:(e,t,o,n)=>{let r=oo(e,t,s=>{if(!jm(s))return s;let l=n.scene.getNonDeletedElementsMap(),c=ja.getPointAtIndexGlobalCoordinates(s,0,l),m=ja.getPointAtIndexGlobalCoordinates(s,-1,l),p=kt(s,{x:o===Vo.elbow?c[0]:s.x,y:o===Vo.elbow?c[1]:s.y,roundness:o===Vo.round?{type:Zm.PROPORTIONAL_RADIUS}:null,elbowed:o===Vo.elbow,angle:o===Vo.elbow?0:s.angle,points:o===Vo.elbow||s.elbowed?[ja.pointFromAbsoluteCoords({...s,x:c[0],y:c[1],angle:0},c,l),ja.pointFromAbsoluteCoords({...s,x:c[0],y:c[1],angle:0},m,l)]:s.points});if(v2(p)){p.fixedSegments=null;let d=n.scene.getNonDeletedElementsMap();n.dismissLinearEditor();let u=ja.getPointAtIndexGlobalCoordinates(p,0,d),h=ja.getPointAtIndexGlobalCoordinates(p,-1,d),g=p.startBinding&&d.get(p.startBinding.elementId),x=p.endBinding&&d.get(p.endBinding.elementId),E=g&&p.startBinding?{...p.startBinding,...x2(p,g,"start",d)}:null,y=x&&p.endBinding?{...p.endBinding,...x2(p,x,"end",d)}:null;p={...p,startBinding:E,endBinding:y,...s8(p,d,{points:[u,h].map(w=>GD(w[0]-p.x,w[1]-p.y)),startBinding:E,endBinding:y,fixedSegments:null})}}else{let d=n.scene.getNonDeletedElementsMap();if(p.startBinding){let u=d.get(p.startBinding.elementId);u&&b2(p,u,t.bindMode==="inside"?"inside":"orbit","start",n.scene)}if(p.endBinding){let u=d.get(p.endBinding.elementId);u&&b2(p,u,t.bindMode==="inside"?"inside":"orbit","end",n.scene)}}return p}),a={...t,currentItemArrowType:o},i=t.selectedLinearElement?.elementId;if(i){let s=r.find(l=>l.id===i);s&&(a.selectedLinearElement=new ja(s,vf(e)))}return{elements:r,appState:a,captureUpdate:St.IMMEDIATELY}},PanelComponent:({elements:e,appState:t,updateData:o,app:n})=>no("fieldset",{children:[ge("legend",{children:f("labels.arrowtypes")}),ge("div",{className:"buttonList",children:ge(Uo,{group:"arrowtypes",options:[{value:Vo.sharp,text:f("labels.arrowtype_sharp"),icon:ds,testId:"sharp-arrow"},{value:Vo.round,text:f("labels.arrowtype_round"),icon:ps,testId:"round-arrow"},{value:Vo.elbow,text:f("labels.arrowtype_elbowed"),icon:ms,testId:"elbow-arrow"}],value:Kt(e,n,r=>jm(r)?r.elbowed?Vo.elbow:r.roundness?Vo.round:Vo.sharp:null,r=>jm(r),r=>r?null:t.currentItemArrowType),onChange:r=>o(r)})})]})});import{clamp as _f,roundToStep as M8}from"@orangecatai/math";import{DEFAULT_CANVAS_BACKGROUND_PICKS as P8,CURSOR_TYPE as L2,MAX_ZOOM as _2,MIN_ZOOM as D2,THEME as Ic,ZOOM_STEP as Df,updateActiveTool as Cs,CODES as Wn,KEYS as xr,viewportCoordsToSceneCoords as A8}from"@orangecatai/common";import{getElementAbsoluteCoords as M2,getNonDeletedElements as R2,getVisibleElements as L8}from"@orangecatai/element";import{newElementWith as _8}from"@orangecatai/element";import{getCommonBounds as N2}from"@orangecatai/element";import{CaptureUpdateAction as un}from"@orangecatai/element";import{useEffect as v8}from"react";import{jsx as T8}from"react/jsx-runtime";var Ts=()=>{let e=document.querySelector(".excalidraw-tooltip");if(e)return e;let t=document.createElement("div");return document.body.appendChild(t),t.classList.add("excalidraw-tooltip"),t},Mf=(e,t,o="bottom")=>{let n=e.getBoundingClientRect(),r=window.innerWidth,a=window.innerHeight,i=5,s=t.left+t.width/2-n.width/2;s<0?s=i:s+n.width>=r&&(s=r-n.width-i);let l;o==="bottom"?(l=t.top+t.height+i,l+n.height>=a&&(l=t.top-n.height-i)):(l=t.top-n.height-i,l<0&&(l=t.top+t.height+i)),Object.assign(e.style,{top:`${l}px`,left:`${s}px`})},I8=(e,t,o,n)=>{t.classList.add("excalidraw-tooltip--visible"),t.style.minWidth=n?"50ch":"10ch",t.style.maxWidth=n?"50ch":"15ch",t.textContent=o;let r=e.getBoundingClientRect();Mf(t,r)},Xt=({children:e,label:t,long:o=!1,style:n,disabled:r})=>(v8(()=>()=>Ts().classList.remove("excalidraw-tooltip--visible"),[]),r?null:T8("div",{className:"excalidraw-tooltip-wrapper",onPointerEnter:a=>I8(a.currentTarget,Ts(),t,o),onPointerLeave:()=>Ts().classList.remove("excalidraw-tooltip--visible"),style:n,children:e}));import{CURSOR_TYPE as Pf,MIME_TYPES as Af,THEME as C2}from"@orangecatai/common";var k2='<svg viewBox="0 0 24 24" stroke-width="1" width="28" height="28" xmlns="http://www.w3.org/2000/svg">',C8='<path d="M6.164 11.755a5.314 5.314 0 0 1-4.932-5.298 5.314 5.314 0 0 1 5.311-5.311 5.314 5.314 0 0 1 5.307 5.113l8.773 8.773a3.322 3.322 0 0 1 0 4.696l-.895.895a3.322 3.322 0 0 1-4.696 0l-8.868-8.868Z" style="fill:#fff"/>',S2='<path stroke="#1b1b1f" fill="#fff" d="m7.868 11.113 7.773 7.774a2.359 2.359 0 0 0 1.667.691 2.368 2.368 0 0 0 2.357-2.358c0-.625-.248-1.225-.69-1.667L11.201 7.78 9.558 9.469l-1.69 1.643v.001Zm10.273 3.606-3.333 3.333m-3.25-6.583 2 2m-7-7 3 3M3.664 3.625l1 1M2.529 6.922l1.407-.144m5.735-2.932-1.118.866M4.285 9.823l.758-1.194m1.863-6.207-.13 1.408"/>',k8=`data:${Af.svg},${encodeURIComponent(`${k2}${S2}</svg>`)}`,S8=`data:${Af.svg},${encodeURIComponent(`${k2}${C8}${S2}</svg>`)}`,Po=e=>{e&&(e.style.cursor="")},Be=(e,t)=>{e&&(e.style.cursor=t)},Un,T2,Lf=(e,t)=>{let n=()=>{let r=t===C2.DARK;Un=document.createElement("canvas"),Un.theme=t,Un.height=20,Un.width=20;let a=Un.getContext("2d");a.lineWidth=1,a.beginPath(),a.arc(Un.width/2,Un.height/2,5,0,2*Math.PI),a.fillStyle=r?"#000":"#fff",a.fill(),a.strokeStyle=r?"#fff":"#000",a.stroke(),T2=Un.toDataURL(Af.svg)};(!Un||Un.theme!==t)&&n(),Be(e,`url(${T2}) ${20/2} ${20/2}, auto`)},Ao=(e,t)=>{if(e)if(t.activeTool.type==="selection")Po(e);else if(pr(t))e.style.cursor=Pf.GRAB;else if(ho(t))Lf(e,t.theme);else if(t.activeTool.type==="laser"){let o=t.theme===C2.LIGHT?k8:S8;e.style.cursor=`url(${o}), auto`}else["image","custom"].includes(t.activeTool.type)?t.activeTool.type!=="image"&&(e.style.cursor=Pf.AUTO):e.style.cursor=Pf.CROSSHAIR};var br=({viewportX:e,viewportY:t,nextZoom:o},n)=>{let r=e-n.offsetLeft,a=t-n.offsetTop,i=n.zoom.value,s=n.scrollX+(r-r/i),l=n.scrollY+(a-a/i),c=-(r-r/o),m=-(a-a/o);return{scrollX:s+c,scrollY:l+m,zoom:{value:o}}};import{jsx as ks,jsxs as G8}from"react/jsx-runtime";var D8=W({name:"changeViewBackgroundColor",label:"labels.canvasBackground",trackEvent:!1,predicate:(e,t,o,n)=>!!n.props.UIOptions.canvasActions.changeViewBackgroundColor&&!t.viewModeEnabled,perform:(e,t,o)=>({appState:{...t,...o},captureUpdate:o?.viewBackgroundColor?un.IMMEDIATELY:un.EVENTUALLY}),PanelComponent:({elements:e,appState:t,updateData:o,appProps:n,data:r})=>ks(fc,{palette:null,topPicks:P8,label:f("labels.canvasBackground"),type:"canvasBackground",color:t.viewBackgroundColor,onChange:a=>o({viewBackgroundColor:a}),"data-testid":"canvas-background-picker",elements:e,appState:t,updateData:o})}),yr=W({name:"clearCanvas",label:"labels.clearCanvas",icon:Ut,trackEvent:{category:"canvas"},predicate:(e,t,o,n)=>!!n.props.UIOptions.canvasActions.clearCanvas&&!t.viewModeEnabled&&t.openDialog?.name!=="elementLinkSelector",perform:(e,t,o,n)=>(n.imageCache.clear(),{elements:e.map(r=>_8(r,{isDeleted:!0})),appState:{...Or(),files:{},theme:t.theme,penMode:t.penMode,penDetected:t.penDetected,exportBackground:t.exportBackground,exportEmbedScene:t.exportEmbedScene,gridSize:t.gridSize,gridStep:t.gridStep,gridModeEnabled:t.gridModeEnabled,stats:t.stats,pasteDialog:t.pasteDialog,activeTool:t.activeTool.type==="image"?{...t.activeTool,type:n.state.preferredSelectionTool.type}:t.activeTool},captureUpdate:un.IMMEDIATELY})}),qm=W({name:"zoomIn",label:"buttons.zoomIn",viewMode:!0,icon:fh,trackEvent:{category:"canvas"},perform:(e,t,o,n)=>({appState:{...t,...br({viewportX:t.width/2+t.offsetLeft,viewportY:t.height/2+t.offsetTop,nextZoom:Ln(t.zoom.value+Df)},t),userToFollow:null},captureUpdate:un.EVENTUALLY}),PanelComponent:({updateData:e,appState:t})=>ks(ae,{type:"button",className:"zoom-in-button zoom-button",icon:fh,title:`${f("buttons.zoomIn")} \u2014 ${G("CtrlOrCmd++")}`,"aria-label":f("buttons.zoomIn"),disabled:t.zoom.value>=_2,onClick:()=>{e(null)}}),keyTest:e=>(e.code===Wn.EQUAL||e.code===Wn.NUM_ADD)&&(e[xr.CTRL_OR_CMD]||e.shiftKey)}),Jm=W({name:"zoomOut",label:"buttons.zoomOut",icon:bh,viewMode:!0,trackEvent:{category:"canvas"},perform:(e,t,o,n)=>({appState:{...t,...br({viewportX:t.width/2+t.offsetLeft,viewportY:t.height/2+t.offsetTop,nextZoom:Ln(t.zoom.value-Df)},t),userToFollow:null},captureUpdate:un.EVENTUALLY}),PanelComponent:({updateData:e,appState:t})=>ks(ae,{type:"button",className:"zoom-out-button zoom-button",icon:bh,title:`${f("buttons.zoomOut")} \u2014 ${G("CtrlOrCmd+-")}`,"aria-label":f("buttons.zoomOut"),disabled:t.zoom.value<=D2,onClick:()=>{e(null)}}),keyTest:e=>(e.code===Wn.MINUS||e.code===Wn.NUM_SUBTRACT)&&(e[xr.CTRL_OR_CMD]||e.shiftKey)}),Qm=W({name:"resetZoom",label:"buttons.resetZoom",icon:OE,viewMode:!0,trackEvent:{category:"canvas"},perform:(e,t,o,n)=>({appState:{...t,...br({viewportX:t.width/2+t.offsetLeft,viewportY:t.height/2+t.offsetTop,nextZoom:Ln(1)},t),userToFollow:null},captureUpdate:un.EVENTUALLY}),PanelComponent:({updateData:e,appState:t})=>ks(Xt,{label:f("buttons.resetZoom"),style:{height:"100%"},children:G8(ae,{type:"button",className:"reset-zoom-button zoom-button",title:f("buttons.resetZoom"),"aria-label":f("buttons.resetZoom"),onClick:()=>{e(null)},children:[(t.zoom.value*100).toFixed(0),"%"]})}),keyTest:e=>(e.code===Wn.ZERO||e.code===Wn.NUM_ZERO)&&(e[xr.CTRL_OR_CMD]||e.shiftKey)}),R8=(e,t,o=1)=>{let[n,r,a,i]=e,s=a-n,l=t.width/s,c=i-r,m=t.height/c,d=Math.min(l,m)*_f(o,.1,1);return Math.min(d,1)},N8=.8,B8=(e,t)=>e[0]<=t[2]&&e[2]>=t[0]&&e[1]<=t[3]&&e[3]>=t[1],F8=(e,t)=>[e[0]-t,e[1]-t,e[2]+t,e[3]+t],P2=(e,t)=>{let o=(e[0]+e[2])/2,n=(e[1]+e[3])/2;return Math.hypot(o-t.x,n-t.y)},A2=e=>[e[0],e[1],e[2],e[3]],O8=(e,t)=>{let o=R2(e);if(!o.length)return[];let n=L8(o),r=n.length?n:o,a=new Map(o.map(d=>[d.id,d])),i=A8({clientX:t.offsetLeft+t.width/2,clientY:t.offsetTop+t.height/2},t),s=r.reduce((d,u)=>{let h=A2(M2(u,a));return d?P2(h,i)<P2(d.bounds,i)?{element:u,bounds:h}:d:{element:u,bounds:h}},null);if(!s)return[];let l=Math.max(160/t.zoom.value,.12*Math.min(t.width,t.height)/t.zoom.value),c=new Map([[s.element.id,s.element]]),m=s.bounds,p=!0;for(;p;){p=!1;let d=F8(m,l);for(let u of r){if(c.has(u.id))continue;let h=A2(M2(u,a));B8(h,d)&&(c.set(u.id,u),m=N2([...c.values()]),p=!0)}}return[...c.values()]},B2=({bounds:e,appState:t,canvasOffsets:o,fitToViewport:n=!1,viewportZoomFactor:r=1,minZoom:a=-1/0,maxZoom:i=1/0})=>{r=_f(r,D2,_2);let[s,l,c,m]=e,p=(s+c)/2,d=(l+m)/2,u=o?.left??0,h=o?.top??0,g=o?.right??0,x=o?.bottom??0,E=t.width-u-g,y=t.height-h-x,w;if(n){let C=c-s,P=m-l;w=Math.min(E/C,y/P)*r}else w=R8(e,{width:E,height:y},r);let v=Ln(_f(M8(w,Df,"floor"),a,i)),I=oE({scenePoint:{x:p,y:d},viewportDimensions:{width:t.width,height:t.height},offsets:o,zoom:{value:v}});return{appState:{...t,scrollX:I.scrollX,scrollY:I.scrollY,zoom:{value:v}},captureUpdate:un.EVENTUALLY}},Ss=({canvasOffsets:e,targetElements:t,appState:o,fitToViewport:n,viewportZoomFactor:r,minZoom:a,maxZoom:i})=>{let s=N2(R2(t));return B2({canvasOffsets:e,bounds:s,appState:o,fitToViewport:n,viewportZoomFactor:r,minZoom:a,maxZoom:i})},cce=W({name:"zoomToFitSelectionInViewport",label:"labels.zoomToFitViewport",icon:cs,trackEvent:{category:"canvas"},perform:(e,t,o,n)=>{let r=n.scene.getSelectedElements(t);return Ss({targetElements:r.length?r:e,appState:{...t,userToFollow:null},fitToViewport:!1,canvasOffsets:n.getEditorUIOffsets()})},keyTest:e=>e.code===Wn.TWO&&e.shiftKey&&!e.altKey&&!e[xr.CTRL_OR_CMD]}),dce=W({name:"zoomToFitSelection",label:"helpDialog.zoomToSelection",icon:cs,trackEvent:{category:"canvas"},perform:(e,t,o,n)=>{let r=n.scene.getSelectedElements(t);return Ss({targetElements:r.length?r:e,appState:{...t,userToFollow:null},fitToViewport:!0,canvasOffsets:n.getEditorUIOffsets()})},keyTest:e=>e.code===Wn.THREE&&e.shiftKey&&!e.altKey&&!e[xr.CTRL_OR_CMD]}),z8=W({name:"zoomToFit",label:"helpDialog.zoomToFit",icon:cs,viewMode:!0,trackEvent:{category:"canvas"},perform:(e,t,o,n)=>Ss({targetElements:e,appState:{...t,userToFollow:null},fitToViewport:!1,canvasOffsets:n.getEditorUIOffsets()}),keyTest:e=>e.code===Wn.ONE&&e.shiftKey&&!e.altKey&&!e[xr.CTRL_OR_CMD]}),H8=W({name:"scrollBackToContent",label:"buttons.scrollBackToContent",icon:cs,viewMode:!0,trackEvent:{category:"canvas"},perform:(e,t,o,n)=>{let r=n.scene.getSelectedElements(t),a=r.length?r:O8(e,t);return a.length?Ss({targetElements:a,appState:{...t,userToFollow:null},fitToViewport:!0,viewportZoomFactor:N8,canvasOffsets:n.getEditorUIOffsets()}):!1},PanelComponent:({updateData:e})=>ks(Xt,{label:f("buttons.scrollBackToContent"),style:{height:"100%"},children:ks(ae,{type:"button",className:"scroll-back-to-content-button zoom-button",icon:cs,title:f("buttons.scrollBackToContent"),"aria-label":f("buttons.scrollBackToContent"),onClick:()=>{e(null)}})})}),qa=W({name:"toggleTheme",label:(e,t)=>t.theme===Ic.DARK?"buttons.lightMode":"buttons.darkMode",keywords:["toggle","dark","light","mode","theme"],icon:(e,t)=>e.theme===Ic.LIGHT?oc:nc,viewMode:!0,trackEvent:{category:"canvas"},perform:(e,t,o)=>({appState:{...t,theme:o||(t.theme===Ic.LIGHT?Ic.DARK:Ic.LIGHT)},captureUpdate:un.EVENTUALLY}),keyTest:e=>e.altKey&&e.shiftKey&&e.code===Wn.D,predicate:(e,t,o,n)=>!!n.props.UIOptions.canvasActions.toggleTheme}),mce=W({name:"toggleEraserTool",label:"toolBar.eraser",trackEvent:{category:"toolbar"},perform:(e,t,o,n)=>{let r;return ho(t)?r=Cs(t,{...t.activeTool.lastActiveTool||{type:n.state.preferredSelectionTool.type},lastActiveToolBeforeEraser:null}):r=Cs(t,{type:"eraser",lastActiveToolBeforeEraser:t.activeTool}),{appState:{...t,selectedElementIds:{},selectedGroupIds:{},activeEmbeddable:null,activeTool:r},captureUpdate:un.IMMEDIATELY}},keyTest:e=>e.key===xr.E}),pce=W({name:"toggleLassoTool",label:"toolBar.lasso",icon:Hr,trackEvent:{category:"toolbar"},predicate:(e,t,o,n)=>n.state.preferredSelectionTool.type!=="lasso",perform:(e,t,o,n)=>{let r;return t.activeTool.type!=="lasso"?(r=Cs(t,{type:"lasso",fromSelection:!1}),Be(n.interactiveCanvas,L2.CROSSHAIR)):r=Cs(t,{type:"selection"}),{appState:{...t,selectedElementIds:{},selectedGroupIds:{},activeEmbeddable:null,activeTool:r},captureUpdate:un.NEVER}}}),F2=W({name:"toggleHandTool",label:"toolBar.hand",trackEvent:{category:"toolbar"},icon:as,viewMode:!1,perform:(e,t,o,n)=>{let r;return pr(t)?r=Cs(t,{...t.activeTool.lastActiveTool||{type:"selection"},lastActiveToolBeforeEraser:null}):(r=Cs(t,{type:"hand",lastActiveToolBeforeEraser:t.activeTool}),Be(n.interactiveCanvas,L2.GRAB)),{appState:{...t,selectedElementIds:{},selectedGroupIds:{},activeEmbeddable:null,activeTool:r},captureUpdate:un.IMMEDIATELY}},keyTest:e=>!e.altKey&&!e[xr.CTRL_OR_CMD]&&e.key===xr.H});import{updateActiveTool as O2}from"@orangecatai/common";import{CaptureUpdateAction as U8}from"@orangecatai/element";var W8=W({name:"setEmbeddableAsActiveTool",trackEvent:{category:"toolbar"},target:"Tool",label:"toolBar.embeddable",perform:(e,t,o,n)=>{let r=O2(t,{type:"embeddable"});return Ao(n.canvas,{...t,activeTool:r}),{elements:e,appState:{...t,activeTool:O2(t,{type:"embeddable"})},captureUpdate:U8.EVENTUALLY}}});import{pointFrom as z2}from"@orangecatai/math";import{bindOrUnbindBindingElement as Y8}from"@orangecatai/element/binding";import{isValidPolygon as H2,LinearElementEditor as ep,newElementWith as Rf}from"@orangecatai/element";import{isBindingElement as G2,isFreeDrawElement as U2,isLinearElement as W2,isLineElement as tp}from"@orangecatai/element";import{KEYS as Nf,arrayToMap as $8,invariant as Y2,shouldRotateWithDiscreteAngle as V8,updateActiveTool as $2}from"@orangecatai/common";import{isPathALoop as K8}from"@orangecatai/element";import{isInvisiblySmallElement as Bf}from"@orangecatai/element";import{CaptureUpdateAction as V2}from"@orangecatai/element";import{jsx as X8}from"react/jsx-runtime";var ro=W({name:"finalize",label:"",trackEvent:!1,perform:(e,t,o,n)=>{let r=e,{interactiveCanvas:a,focusContainer:i,scene:s}=n,l=s.getNonDeletedElementsMap();if(o&&t.selectedLinearElement){let{event:d,sceneCoords:u}=o,h=ep.getElement(t.selectedLinearElement.elementId,l);Y2(h,"Arrow element should exist if selectedLinearElement is set"),Y2(u,"sceneCoords should be defined if actionFinalize is called with event");let g=ep.handlePointerUp(d,t.selectedLinearElement,t,n.scene);if(G2(h)&&!t.selectedLinearElement.segmentMidPointHoveredCoords){let x=!!t.newElement,y=(x||!t.selectedLinearElement.selectedPointsIndices?[h.points.length-1]:t.selectedLinearElement.selectedPointsIndices).reduce((w,v)=>(w.set(v,{point:ep.pointFromAbsoluteCoords(h,z2(u.x-g.pointerOffset.x,u.y-g.pointerOffset.y),l)}),w),new Map)??new Map;Y8(h,y,u.x-g.pointerOffset.x,u.y-g.pointerOffset.y,s,t,{newArrow:x,altKey:d.altKey,angleLocked:V8(d)})}else tp(h)&&t.selectedLinearElement?.isEditing&&!t.newElement&&!H2(h.points)&&s.mutateElement(h,{polygon:!1});if(g!==t.selectedLinearElement){h&&Bf(h)&&(r=r.map(E=>E.id===h.id?Rf(E,{isDeleted:!0}):E));let x=t.activeTool?.locked;return{elements:h.points.length<2||Bf(h)?e.map(E=>E.id===h.id?Rf(E,{isDeleted:!0}):E):r,appState:{...t,cursorButton:"up",selectedLinearElement:x?null:{...g,selectedPointsIndices:null,isEditing:!1,initialState:{...g.initialState,lastClickedPoint:-1},pointerOffset:{x:0,y:0}},selectionElement:null,suggestedBinding:null,newElement:null,multiElement:null},captureUpdate:V2.IMMEDIATELY}}}window.document.activeElement instanceof HTMLElement&&i();let c=null;if(t.multiElement)c=t.multiElement;else if(t.newElement?.type==="freedraw"||G2(t.newElement))c=t.newElement;else if(Object.keys(t.selectedElementIds).length===1){let d=l.get(Object.keys(t.selectedElementIds)[0]);d&&(c=d)}if(c){if(t.selectedLinearElement&&t.multiElement&&c.type!=="freedraw"&&t.lastPointerDownWith!=="touch"){let{points:d}=c,{lastCommittedPoint:u}=t.selectedLinearElement;(!u||d[d.length-1]!==u)&&s.mutateElement(c,{points:c.points.slice(0,-1)})}if(c&&Bf(c)&&(r=r.map(d=>d.id===c?.id?Rf(d,{isDeleted:!0}):d)),W2(c)||U2(c)){if(K8(c.points,t.zoom.value)&&(tp(c)||U2(c))){let u=c.points,h=u[0],g=u.map((x,E)=>E===u.length-1?z2(h[0],h[1]):x);tp(c)?s.mutateElement(c,{points:g,polygon:!0}):s.mutateElement(c,{points:g})}tp(c)&&!H2(c.points)&&s.mutateElement(c,{polygon:!1})}}(!t.activeTool.locked&&t.activeTool.type!=="freedraw"||!c)&&Po(a);let m;t.activeTool.type==="eraser"?m=$2(t,{...t.activeTool.lastActiveTool||{type:n.state.preferredSelectionTool.type},lastActiveToolBeforeEraser:null}):m=$2(t,{type:n.state.preferredSelectionTool.type});let p=c&&W2(c)?new ep(c,$8(r)):t.selectedLinearElement;return p=p&&{...p,isEditing:t.newElement?!1:p.isEditing,initialState:{...p.initialState,lastClickedPoint:-1,origin:null}},{elements:r,appState:{...t,cursorButton:"up",activeTool:(t.activeTool.locked||t.activeTool.type==="freedraw")&&c?t.activeTool:m,activeEmbeddable:null,newElement:null,selectionElement:null,multiElement:null,editingTextElement:null,startBoundElement:null,suggestedBinding:null,selectedElementIds:c&&!t.activeTool.locked&&t.activeTool.type!=="freedraw"?{...t.selectedElementIds,[c.id]:!0}:t.selectedElementIds,selectedLinearElement:p},captureUpdate:V2.IMMEDIATELY}},keyTest:(e,t)=>e.key===Nf.ESCAPE&&(t.selectedLinearElement?.isEditing||!t.newElement&&t.multiElement===null)||(e.key===Nf.ESCAPE||e.key===Nf.ENTER)&&t.multiElement!==null,PanelComponent:({appState:e,updateData:t,data:o})=>X8(ae,{type:"button",icon:KE,title:f("buttons.done"),"aria-label":f("buttons.done"),onClick:t,visible:e.multiElement!=null,size:o?.size||"medium",style:{pointerEvents:"all"}})});import{KEYS as Ls,DEFAULT_EXPORT_PADDING as OR,EXPORT_SCALES as zR,THEME as zf}from"@orangecatai/common";import{getNonDeletedElements as HR}from"@orangecatai/element";import{CaptureUpdateAction as fn}from"@orangecatai/element";import Z8 from"clsx";import{jsx as K2,jsxs as j8}from"react/jsx-runtime";var Tc=({children:e,checked:t,onChange:o,className:n})=>j8("div",{className:Z8("Checkbox",n,{"is-checked":t}),onClick:r=>{o(!t,r),r.currentTarget.querySelector(".Checkbox-box").focus()},children:[K2("button",{type:"button",className:"Checkbox-box",role:"checkbox","aria-checked":t,children:bm}),K2("div",{className:"Checkbox-label",children:e})]});import{THEME as Cc}from"@orangecatai/common";import{jsx as kc}from"react/jsx-runtime";var Z2=e=>{let t=e.title||(e.value===Cc.DARK?f("buttons.lightMode"):f("buttons.darkMode"));return kc(ae,{type:"icon",icon:e.value===Cc.LIGHT?X2.MOON:X2.SUN,title:t,"aria-label":t,onClick:()=>e.onChange(e.value===Cc.DARK?Cc.LIGHT:Cc.DARK),"data-testid":"toggle-dark-mode"})},X2={SUN:kc("svg",{width:"512",height:"512",className:"rtl-mirror",viewBox:"0 0 512 512",children:kc("path",{fill:"currentColor",d:"M256 160c-52.9 0-96 43.1-96 96s43.1 96 96 96 96-43.1 96-96-43.1-96-96-96zm246.4 80.5l-94.7-47.3 33.5-100.4c4.5-13.6-8.4-26.5-21.9-21.9l-100.4 33.5-47.4-94.8c-6.4-12.8-24.6-12.8-31 0l-47.3 94.7L92.7 70.8c-13.6-4.5-26.5 8.4-21.9 21.9l33.5 100.4-94.7 47.4c-12.8 6.4-12.8 24.6 0 31l94.7 47.3-33.5 100.5c-4.5 13.6 8.4 26.5 21.9 21.9l100.4-33.5 47.3 94.7c6.4 12.8 24.6 12.8 31 0l47.3-94.7 100.4 33.5c13.6 4.5 26.5-8.4 21.9-21.9l-33.5-100.4 94.7-47.3c13-6.5 13-24.7.2-31.1zm-155.9 106c-49.9 49.9-131.1 49.9-181 0-49.9-49.9-49.9-131.1 0-181 49.9-49.9 131.1-49.9 181 0 49.9 49.9 49.9 131.1 0 181z"})}),MOON:kc("svg",{width:"512",height:"512",className:"rtl-mirror",viewBox:"0 0 512 512",children:kc("path",{fill:"currentColor",d:"M283.211 512c78.962 0 151.079-35.925 198.857-94.792 7.068-8.708-.639-21.43-11.562-19.35-124.203 23.654-238.262-71.576-238.262-196.954 0-72.222 38.662-138.635 101.498-174.394 9.686-5.512 7.25-20.197-3.756-22.23A258.156 258.156 0 0 0 283.211 0c-141.309 0-256 114.511-256 256 0 141.309 114.511 256 256 256z"})})};import{useState as q8}from"react";import{focusNearestParent as J8,KEYS as Q8}from"@orangecatai/common";import{jsx as j2,jsxs as eR}from"react/jsx-runtime";var q2=e=>{let{id:t}=Qe(),[o,n]=q8(e.value),r=i=>{e.ignoreFocus||J8(i.target);let s=i.target.value;s!==e.value&&e.onChange(s)},a=i=>{if(i.key===Q8.ENTER){if(i.preventDefault(),i.nativeEvent.isComposing||i.keyCode===229)return;i.currentTarget.blur()}};return eR("div",{className:"ProjectName",children:[j2("label",{className:"ProjectName-label",htmlFor:"filename",children:`${e.label}:`}),j2("input",{type:"text",className:"TextInput",onBlur:r,onKeyDown:a,id:`${t}-filename`,value:o,onChange:i=>n(i.target.value)})]})};import{DEFAULT_EXPORT_PADDING as PR,DEFAULT_FILENAME as AR,IMAGE_MIME_TYPES as gI,isFirefox as LR,MIME_TYPES as _R,cloneJSON as DR,SVG_DOCUMENT_PREAMBLE as RR}from"@orangecatai/common";import{getNonDeletedElements as NR}from"@orangecatai/element";import{isFrameLikeElement as BR}from"@orangecatai/element";import{getElementsOverlappingFrame as FR}from"@orangecatai/element";import{ALLOWED_PASTE_MIME_TYPES as pR,EXPORT_DATA_TYPES as Pc,MIME_TYPES as Lo,arrayToMap as uR,isMemberOf as gR,isPromiseLike as hR,EVENT as rp}from"@orangecatai/common";import{mutateElement as fR}from"@orangecatai/element";import{deepCopyElement as bR}from"@orangecatai/element";import{isFrameLikeElement as xR,isInitializedImageElement as yR}from"@orangecatai/element";import{getContainingFrame as lI}from"@orangecatai/element";import{pointFrom as Jr}from"@orangecatai/math";import{COLOR_PALETTE as Q2,DEFAULT_CHART_COLOR_INDEX as tR,getAllColorsSpecificShade as oR,DEFAULT_FONT_FAMILY as nR,DEFAULT_FONT_SIZE as eI,VERTICAL_ALIGN as rR,randomId as tI,isDevEnv as oI,FONT_SIZES as aR}from"@orangecatai/common";import{newTextElement as op,newLinearElement as Mc,newElement as Of}from"@orangecatai/element";var gn=32,Ke=12,Qr=256,nI=50,Ja="NOT_SPREADSHEET",Ms="VALID_SPREADSHEET",Sc=e=>{let t=/^([-+]?)[$€£¥₩]?([-+]?)([\d.,]+)[%]?$/.exec(e);return t?parseFloat(`${(t[1]||t[2])+t[3]}`.replace(/,/g,"")):null},Ff=(e,t)=>e.slice(1).every(o=>Sc(o[t])!==null),J2=e=>{let t=e[0].length;if(t>2)return{type:Ja,reason:"More than 2 columns"};if(t===1){if(!Ff(e,0))return{type:Ja,reason:"Value is not numeric"};let l=Sc(e[0][0])===null,c=(l?e.slice(1):e).map(m=>Sc(m[0]));return c.length<2?{type:Ja,reason:"Less than two rows"}:{type:Ms,spreadsheet:{title:l?e[0][0]:null,labels:null,values:c}}}let o=Ff(e,0),n=Ff(e,1);if(!o&&!n)return{type:Ja,reason:"Value is not numeric"};let[r,a]=n?[0,1]:[1,0],i=Sc(e[0][a])===null,s=i?e.slice(1):e;return s.length<2?{type:Ja,reason:"Less than 2 rows"}:{type:Ms,spreadsheet:{title:i?e[0][a]:null,labels:s.map(l=>l[r]),values:s.map(l=>Sc(l[a]))}}},iR=e=>{let t=[];for(let o=0;o<e[0].length;o++){let n=[];for(let r=0;r<e.length;r++)n.push(e[r][o]);t.push(n)}return t},rI=e=>{let t=e.trim().split(`
|
|
1
|
+
import{$ as mh,A as ch,B as eL,C as iE,D as sE,E as rm,F as ql,G as am,H as im,I as Jl,J as lE,K as cE,L as dE,M as zr,N as Yi,O as mE,P as tL,Q as Ga,R as $i,S as Ql,U as pE,W as uE,X as gE,Y as sm,Z as hE,_ as dh,a as oE,aa as lm,b as Ha,ba as fE,c as Ln,ca as ph,d as nE,da as Ua,e as Ge,ea as bE,f as rE,fa as Vi,g as de,ga as xE,h as Hi,ha as So,i as _n,ia as uh,j as Kl,ja as yE,k as Xl,ka as cm,l as Gi,la as gh,m as Zl,ma as EE,n as Ui,na as wE,o as aE,oa as vE,p as sh,pa as ec,q as Dn,r as Ho,s as Or,t as ho,u as pr,v as Wi,w as om,x as lh,y as jl,z as nm}from"./chunk-TDDASSRC.js";import{a as T}from"./chunk-OH4MQBSI.js";import{M as ih}from"./chunk-MSBJ7C4T.js";import{c as tE}from"./chunk-3PELD44J.js";import{b as Qy,c as eE,d as A}from"./chunk-SRAX5OIU.js";import uee,{useEffect as gee,useMemo as hee}from"react";import{DEFAULT_UI_OPTIONS as zA,isShallowEqual as fee}from"@orangecatai/common";import RP from"clsx";import Rj from"lodash.throttle";import cr,{useContext as Ba}from"react";import{flushSync as Io}from"react-dom";import Nj from"roughjs/bin/rough";import{nanoid as R1}from"nanoid";import{clamp as NP,pointFrom as pe,pointDistance as Pa,vector as BP,pointRotateRads as N1,vectorFromPoint as B1,vectorSubtract as FP,vectorDot as OP,vectorNormalize as zP}from"@orangecatai/math";import{COLOR_PALETTE as Bj,CODES as HP,shouldResizeFromCenter as GP,shouldMaintainAspectRatio as Dd,shouldRotateWithDiscreteAngle as UP,isArrowKey as Lg,KEYS as re,APP_NAME as Fj,CURSOR_TYPE as lt,DEFAULT_MAX_IMAGE_WIDTH_OR_HEIGHT as Oj,DEFAULT_VERTICAL_ALIGN as WP,DRAGGING_THRESHOLD as YP,ELEMENT_SHIFT_TRANSLATE_AMOUNT as zj,ELEMENT_TRANSLATE_AMOUNT as $P,EVENT as fe,FRAME_STYLE as ln,IMAGE_MIME_TYPES as Hj,IMAGE_RENDER_TIMEOUT as Gj,LINE_CONFIRM_THRESHOLD as F1,MAX_ALLOWED_FILE_BYTES as VP,MIME_TYPES as rr,MQ_RIGHT_SIDEBAR_MIN_WIDTH as Uj,POINTER_BUTTON as Aa,ROUNDNESS as _g,SCROLL_TIMEOUT as Wj,TAP_TWICE_TIMEOUT as Yj,TEXT_TO_CENTER_SNAP_THRESHOLD as $j,THEME as Dg,TOUCH_CTX_MENU_TIMEOUT as Vj,VERTICAL_ALIGN as Kj,YOUTUBE_STATES as Rg,ZOOM_STEP as Xj,POINTER_EVENTS as Nl,TOOL_TYPE as ar,supportsResizeObserver as Zj,DEFAULT_COLLISION_THRESHOLD as KP,DEFAULT_TEXT_ALIGN as jj,ARROW_TYPE as La,DEFAULT_REDUCED_GLOBAL_ALPHA as qj,isLocalLink as Jj,normalizeLink as O1,toValidURL as Qj,getGridPoint as Jt,getLineHeight as XP,debounce as ZP,distance as Bl,getFontString as z1,getNearestScrollableContainer as eq,isInputLike as jP,isToolIcon as tq,isWritableElement as Rd,sceneCoordsToViewportCoords as Ng,tupleToCoors as H1,viewportCoordsToSceneCoords as rt,wrapEvent as oq,updateObject as G1,updateActiveTool as ir,isTransparent as nq,easeToValuesRAF as rq,muteFSAbortError as aq,isTestEnv as N6,isDevEnv as B6,easeOut as iq,updateStable as Nd,addEventListener as ht,normalizeEOL as sq,getDateTime as qP,isShallowEqual as JP,arrayToMap as Bg,applyDarkModeFilter as lq,randomInteger as cq,CLASSES as U1,Emitter as Ai,MINIMUM_ARROW_SIZE as dq,DOUBLE_TAP_POSITION_THRESHOLD as mq,BIND_MODE_TIMEOUT as pq,invariant as sr,getFeatureFlag as Rr,createUserAgentDescriptor as F6,getFormFactor as uq,deriveStylesPanelMode as Wg,isIOS as gq,isBrave as hq,isSafari as fq,loadDesktopUIModePreference as bq,setDesktopUIMode as xq,isSelectionLikeTool as Fg,oneOf as QP}from"@orangecatai/common";import{getObservedAppState as yq,getCommonBounds as Fl,getElementAbsoluteCoords as Og,bindOrUnbindBindingElements as e6,fixBindingsAfterDeletion as Eq,getHoveredElementForBinding as Cn,isBindingEnabled as Bd,shouldEnableBindingForPointerEvent as wq,updateBoundElements as zg,LinearElementEditor as _e,newElementWith as _a,newFrameElement as t6,newFreeDrawElement as vq,newEmbeddableElement as o6,newMagicFrameElement as n6,newIframeElement as Iq,newArrowElement as Tq,newElement as Cq,newImageElement as W1,newLinearElement as kq,newTextElement as r6,refreshTextDimensions as Sq,deepCopyElement as a6,duplicateElements as Y1,hasBoundTextElement as i6,isArrowElement as Ol,isBindingElement as lr,isBindingElementType as Mq,isBoundToContainer as $1,isFrameLikeElement as Qt,isImageElement as Da,isEmbeddableElement as Nr,isInitializedImageElement as Fd,isLinearElement as mo,isLinearElementType as Pq,isUsingAdaptiveRadius as Aq,isIframeElement as zl,isIframeLikeElement as V1,isMagicFrameElement as K1,isTextBindableContainer as s6,isElbowArrow as To,isFlowchartNodeElement as Lq,isBindableElement as X1,isTextElement as kn,getNormalizedDimensions as _q,isElementCompletelyInViewport as Z1,isElementInViewport as l6,isInvisiblySmallElement as c6,getCornerRadius as Dq,isPathALoop as d6,createSrcDoc as m6,embeddableURLValidator as j1,maybeParseEmbedSrc as Rq,getEmbedLink as Hg,getInitializedImageElements as Nq,normalizeSVG as p6,updateImageCache as Bq,getBoundTextElement as q1,getContainerCenter as J1,getContainerElement as u6,isValidTextContainer as Fq,redrawTextBoundingBox as Oq,hasBoundingBox as zq,getFrameChildren as Q1,isCursorInFrame as g6,addElementsToFrame as ey,replaceAllElementsInFrame as Hq,removeElementsFromFrame as Gq,getElementsInResizingFrame as ty,getElementsInNewFrame as Uq,getContainingFrame as oy,elementOverlapsWithFrame as Wq,updateFrameMembershipOfSelectedElements as h6,isElementInFrame as f6,getFrameLikeTitle as Yq,getElementsOverlappingFrame as $q,filterElementsEligibleAsFrameChildren as Vq,hitElementBoundText as Kq,hitElementBoundingBoxOnly as Xq,hitElementItself as Od,getVisibleSceneBounds as Zq,FlowChartCreator as jq,FlowChartNavigator as qq,getLinkDirectionFromKey as b6,cropElement as Jq,wrapText as Qq,isElementLink as ny,parseElementLinkFromURL as eJ,isMeasureTextSupported as tJ,normalizeText as oJ,measureText as x6,getLineHeightInPx as nJ,getApproxMinLineWidth as rJ,getApproxMinLineHeight as aJ,getMinTextElementWidth as iJ,ShapeCache as zd,getRenderOpacity as sJ,editGroupForSelectedElement as lJ,getElementsInGroup as Li,getSelectedGroupIdForElement as cJ,getSelectedGroupIds as dJ,isElementInGroup as y6,isSelectedViaGroup as mJ,selectGroupsForSelectedElements as cn,syncInvalidIndices as O6,syncMovedIndices as E6,excludeElementsInFramesFromSelection as pJ,getSelectionStateForElements as uJ,makeNextSelectedElementIds as ze,getResizeOffsetXY as gJ,getResizeArrowDirection as hJ,transformElements as fJ,getCursorForResizingElement as w6,getElementWithTransformHandleType as v6,getTransformHandleTypeFromCoords as I6,dragNewElement as T6,dragSelectedElements as bJ,getDragOffsetXY as xJ,isNonDeletedElement as C6,Scene as k6,Store as yJ,CaptureUpdateAction as po,hitElementBoundingBox as EJ,isLineElement as ry,isSimpleArrow as ay,StoreDelta as S6,positionElementsOnGrid as M6,calculateFixedPointForNonElbowArrowBinding as P6,bindOrUnbindBindingElement as wJ,mutateElement as Gg,getElementBounds as A6,doBoundsIntersect as vJ,isPointInElement as IJ,maxBindingDistance_simple as iy,convertToExcalidrawElements as L6,getSnapOutlineMidPoint as sy,handleFocusPointDrag as TJ,handleFocusPointHover as CJ,handleFocusPointPointerDown as kJ,handleFocusPointPointerUp as SJ,maybeHandleArrowPointlikeDrag as Ug,getUncroppedWidthAndHeight as MJ}from"@orangecatai/element";import{KEYS as Hh,MOBILE_ACTION_BUTTON_BG as gL,updateActiveTool as hL}from"@orangecatai/common";import{getNonDeletedElements as Gh}from"@orangecatai/element";import{fixBindingsAfterDeletion as fL}from"@orangecatai/element";import{LinearElementEditor as vv}from"@orangecatai/element";import{newElementWith as Pm}from"@orangecatai/element";import{getContainerElement as Iv}from"@orangecatai/element";import{isBoundToContainer as Sm,isElbowArrow as bL,isFrameLikeElement as xL}from"@orangecatai/element";import{getFrameChildren as yL}from"@orangecatai/element";import{getElementsInGroup as Uh,selectGroupsForSelectedElements as EL}from"@orangecatai/element";import{CaptureUpdateAction as Mm}from"@orangecatai/element";import{isDevEnv as aL}from"@orangecatai/common";import{atom as Pe,createStore as oL}from"jotai";import{createIsolation as nL}from"jotai-scope";var IE=nL();var{useAtom:le,useSetAtom:Rn,useAtomValue:Ki,useStore:vee}=IE,TE=IE.Provider,Et=oL();var rL=Qy({"./locales/ar-SA.json":()=>import("./locales/ar-SA-NXDWD63E.js"),"./locales/az-AZ.json":()=>import("./locales/az-AZ-MXSORGZV.js"),"./locales/bg-BG.json":()=>import("./locales/bg-BG-O6MV2KSF.js"),"./locales/bn-BD.json":()=>import("./locales/bn-BD-T2VJNT7N.js"),"./locales/bn-IN.json":()=>import("./locales/bn-IN-MMW2ORAC.js"),"./locales/ca-ES.json":()=>import("./locales/ca-ES-MKBCGNOG.js"),"./locales/cs-CZ.json":()=>import("./locales/cs-CZ-V77HGUP7.js"),"./locales/da-DK.json":()=>import("./locales/da-DK-I5RFNTM4.js"),"./locales/de-CH.json":()=>import("./locales/de-CH-WLRDEVBV.js"),"./locales/de-DE.json":()=>import("./locales/de-DE-DTI4WUSC.js"),"./locales/el-GR.json":()=>import("./locales/el-GR-ZXDJ2OS4.js"),"./locales/en.json":()=>import("./locales/en-RQF5X6GM.js"),"./locales/es-ES.json":()=>import("./locales/es-ES-DYQHAD43.js"),"./locales/eu-ES.json":()=>import("./locales/eu-ES-QDSYU5Y3.js"),"./locales/fa-IR.json":()=>import("./locales/fa-IR-26LZG4PM.js"),"./locales/fi-FI.json":()=>import("./locales/fi-FI-6YS4KDE4.js"),"./locales/fr-FR.json":()=>import("./locales/fr-FR-BRLLPTZC.js"),"./locales/gl-ES.json":()=>import("./locales/gl-ES-OKUZTLYG.js"),"./locales/he-IL.json":()=>import("./locales/he-IL-26MGYIU7.js"),"./locales/hi-IN.json":()=>import("./locales/hi-IN-Q4ZOGTP2.js"),"./locales/hu-HU.json":()=>import("./locales/hu-HU-P2OXPSN5.js"),"./locales/id-ID.json":()=>import("./locales/id-ID-2EIKXYN6.js"),"./locales/it-IT.json":()=>import("./locales/it-IT-4CFKVXI2.js"),"./locales/ja-JP.json":()=>import("./locales/ja-JP-MAND2Z4V.js"),"./locales/kaa.json":()=>import("./locales/kaa-HQRTCXTJ.js"),"./locales/kab-KAB.json":()=>import("./locales/kab-KAB-JKIKKTGH.js"),"./locales/kk-KZ.json":()=>import("./locales/kk-KZ-HXQ63ZFC.js"),"./locales/km-KH.json":()=>import("./locales/km-KH-PKL3LSGX.js"),"./locales/ko-KR.json":()=>import("./locales/ko-KR-KXLREZX3.js"),"./locales/ku-TR.json":()=>import("./locales/ku-TR-MJ4IER3X.js"),"./locales/lt-LT.json":()=>import("./locales/lt-LT-H6WFQ6FJ.js"),"./locales/lv-LV.json":()=>import("./locales/lv-LV-GOCK6SJW.js"),"./locales/mr-IN.json":()=>import("./locales/mr-IN-IXVLDMEQ.js"),"./locales/my-MM.json":()=>import("./locales/my-MM-YG6MYTTD.js"),"./locales/nb-NO.json":()=>import("./locales/nb-NO-XGWJISD2.js"),"./locales/nl-NL.json":()=>import("./locales/nl-NL-XVDVCPNC.js"),"./locales/nn-NO.json":()=>import("./locales/nn-NO-EMX5MJX5.js"),"./locales/oc-FR.json":()=>import("./locales/oc-FR-ROEINTVO.js"),"./locales/pa-IN.json":()=>import("./locales/pa-IN-ZYN6SUDY.js"),"./locales/percentages.json":()=>import("./locales/percentages-5DKR754L.js"),"./locales/pl-PL.json":()=>import("./locales/pl-PL-6VTG7PHC.js"),"./locales/pt-BR.json":()=>import("./locales/pt-BR-5YFKRR5G.js"),"./locales/pt-PT.json":()=>import("./locales/pt-PT-GEIXXZ67.js"),"./locales/ro-RO.json":()=>import("./locales/ro-RO-E2P6TFZI.js"),"./locales/ru-RU.json":()=>import("./locales/ru-RU-YBIIY43T.js"),"./locales/si-LK.json":()=>import("./locales/si-LK-673C2CI2.js"),"./locales/sk-SK.json":()=>import("./locales/sk-SK-CKZHQ4AP.js"),"./locales/sl-SI.json":()=>import("./locales/sl-SI-557H2GWM.js"),"./locales/sv-SE.json":()=>import("./locales/sv-SE-XOPKKDWS.js"),"./locales/ta-IN.json":()=>import("./locales/ta-IN-XBH7DQI3.js"),"./locales/th-TH.json":()=>import("./locales/th-TH-TOCWH3R4.js"),"./locales/tr-TR.json":()=>import("./locales/tr-TR-GXW6CYY5.js"),"./locales/uk-UA.json":()=>import("./locales/uk-UA-IJKTNUDG.js"),"./locales/uz-UZ.json":()=>import("./locales/uz-UZ-TBZZEA4V.js"),"./locales/vi-VN.json":()=>import("./locales/vi-VN-MULSGNVB.js"),"./locales/zh-CN.json":()=>import("./locales/zh-CN-MVX3E32U.js"),"./locales/zh-HK.json":()=>import("./locales/zh-HK-JNU5RLIE.js"),"./locales/zh-TW.json":()=>import("./locales/zh-TW-LENVCA6T.js")});var iL=85,Nn={code:"en",label:"English"},Zi=[Nn,...[{code:"ar-SA",label:"\u0627\u0644\u0639\u0631\u0628\u064A\u0629",rtl:!0},{code:"bg-BG",label:"\u0411\u044A\u043B\u0433\u0430\u0440\u0441\u043A\u0438"},{code:"ca-ES",label:"Catal\xE0"},{code:"cs-CZ",label:"\u010Cesky"},{code:"de-DE",label:"Deutsch"},{code:"el-GR",label:"\u0395\u03BB\u03BB\u03B7\u03BD\u03B9\u03BA\u03AC"},{code:"es-ES",label:"Espa\xF1ol"},{code:"eu-ES",label:"Euskara"},{code:"fa-IR",label:"\u0641\u0627\u0631\u0633\u06CC",rtl:!0},{code:"fi-FI",label:"Suomi"},{code:"fr-FR",label:"Fran\xE7ais"},{code:"gl-ES",label:"Galego"},{code:"he-IL",label:"\u05E2\u05D1\u05E8\u05D9\u05EA",rtl:!0},{code:"hi-IN",label:"\u0939\u093F\u0928\u094D\u0926\u0940"},{code:"hu-HU",label:"Magyar"},{code:"id-ID",label:"Bahasa Indonesia"},{code:"it-IT",label:"Italiano"},{code:"ja-JP",label:"\u65E5\u672C\u8A9E"},{code:"kab-KAB",label:"Taqbaylit"},{code:"kk-KZ",label:"\u049A\u0430\u0437\u0430\u049B \u0442\u0456\u043B\u0456"},{code:"ko-KR",label:"\uD55C\uAD6D\uC5B4"},{code:"ku-TR",label:"Kurd\xEE"},{code:"lt-LT",label:"Lietuvi\u0173"},{code:"lv-LV",label:"Latvie\u0161u"},{code:"my-MM",label:"Burmese"},{code:"nb-NO",label:"Norsk bokm\xE5l"},{code:"nl-NL",label:"Nederlands"},{code:"nn-NO",label:"Norsk nynorsk"},{code:"oc-FR",label:"Occitan"},{code:"pa-IN",label:"\u0A2A\u0A70\u0A1C\u0A3E\u0A2C\u0A40"},{code:"pl-PL",label:"Polski"},{code:"pt-BR",label:"Portugu\xEAs Brasileiro"},{code:"pt-PT",label:"Portugu\xEAs"},{code:"ro-RO",label:"Rom\xE2n\u0103"},{code:"ru-RU",label:"\u0420\u0443\u0441\u0441\u043A\u0438\u0439"},{code:"sk-SK",label:"Sloven\u010Dina"},{code:"sv-SE",label:"Svenska"},{code:"sl-SI",label:"Sloven\u0161\u010Dina"},{code:"tr-TR",label:"T\xFCrk\xE7e"},{code:"uk-UA",label:"\u0423\u043A\u0440\u0430\u0457\u043D\u0441\u044C\u043A\u0430"},{code:"zh-CN",label:"\u7B80\u4F53\u4E2D\u6587"},{code:"zh-TW",label:"\u7E41\u9AD4\u4E2D\u6587"},{code:"vi-VN",label:"Ti\u1EBFng Vi\u1EC7t"},{code:"mr-IN",label:"\u092E\u0930\u093E\u0920\u0940"}].filter(e=>tE[e.code]>=iL).sort((e,t)=>e.label>t.label?1:-1)],mm="__test__";aL()&&Zi.unshift({code:mm,label:"test language"},{code:`${mm}.rtl`,label:"\u202Atest language (rtl)\u202C",rtl:!0});var Xi=Nn,dm={},pm=async e=>{if(Xi=e,document.documentElement.dir=Xi.rtl?"rtl":"ltr",document.documentElement.lang=Xi.code,e.code.startsWith(mm))dm={};else try{dm=await rL(`./locales/${Xi.code}.json`)}catch(t){console.error(`Failed to load language ${e.code}:`,t.message),dm=ih}Et.set(kE,e.code)},ur=()=>Xi,CE=(e,t)=>{for(let o=0;o<t.length;++o){let n=t[o];if(e[n]===void 0)return;e=e[n]}if(typeof e=="string")return e},f=(e,t,o)=>{if(Xi.code.startsWith(mm))return`\u202A[[${t?`${e}(${JSON.stringify(t).slice(1,-1)})`:e}]]\u202C`;let n=e.split("."),r=CE(dm,n)||CE(ih,n)||o;if(r===void 0){let a=`Can't find translation for ${e}`;if(T.PROD)return console.warn(a),"";throw new Error(a)}if(t)for(let a in t)r=r.replace(`{{${a}}}`,String(t[a]));return r},kE=Pe(Nn.code),Ue=()=>{let e=Ki(kE);return{t:f,langCode:e}};import sL from"clsx";import _t from"react";import{THEME as lL}from"@orangecatai/common";import{Fragment as We,jsx as b,jsxs as H}from"react/jsx-runtime";var pn=e=>"var(--icon-fill-color)",SE=e=>e===lL.LIGHT?"#fff":"#1e1e1e",R=(e,t=512)=>{let{width:o=512,height:n=o,mirror:r,style:a,...i}=typeof t=="number"?{width:t}:t;return b("svg",{"aria-hidden":"true",focusable:"false",role:"img",viewBox:`0 0 ${o} ${n}`,className:sL({"rtl-mirror":r}),style:a,...i,children:typeof e=="string"?b("path",{fill:"currentColor",d:e}):e})},K={width:24,height:24,fill:"none",strokeWidth:2,stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round"},Ee={width:20,height:20,fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round"},Fee=R(H("g",{strokeWidth:"1.5",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("rect",{x:3,y:8,width:18,height:4,rx:1}),b("line",{x1:12,y1:8,x2:12,y2:21}),b("path",{d:"M19 12v7a2 2 0 0 1 -2 2h-10a2 2 0 0 1 -2 -2v-7"}),b("path",{d:"M7.5 8a2.5 2.5 0 0 1 0 -5a4.8 8 0 0 1 4.5 5a4.8 8 0 0 1 4.5 -5a2.5 2.5 0 0 1 0 5"})]}),K),um=R(H("g",{strokeWidth:"1.25",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M3 19a9 9 0 0 1 9 0a9 9 0 0 1 9 0"}),b("path",{d:"M3 6a9 9 0 0 1 9 0a9 9 0 0 1 9 0"}),b("line",{x1:"3",y1:"6",x2:"3",y2:"19"}),b("line",{x1:"12",y1:"6",x2:"12",y2:"19"}),b("line",{x1:"21",y1:"6",x2:"21",y2:"19"})]}),K),ME=R(H("svg",{strokeWidth:"1.5",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),b("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]}),K),PE=R(H("g",{strokeWidth:"1.5",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("circle",{cx:"12",cy:"12",r:"1"}),b("circle",{cx:"12",cy:"19",r:"1"}),b("circle",{cx:"12",cy:"5",r:"1"})]}),K),AE=R(H("g",{strokeWidth:"1.5",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M5 12m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0"}),b("path",{d:"M12 12m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0"}),b("path",{d:"M19 12m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0"})]}),K),LE=R(H("svg",{strokeWidth:"1.5",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M9 4v6l-2 4v2h10v-2l-2 -4v-6"}),b("line",{x1:"12",y1:"16",x2:"12",y2:"21"}),b("line",{x1:"8",y1:"4",x2:"16",y2:"4"})]}),K),hh=R(H("g",{strokeWidth:1.25,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M12 5m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"}),b("path",{d:"M19 8m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"}),b("path",{d:"M5 11m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"}),b("path",{d:"M15 19m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"}),b("path",{d:"M6.5 9.5l3.5 -3"}),b("path",{d:"M14 5.5l3 1.5"}),b("path",{d:"M18.5 10l-2.5 7"}),b("path",{d:"M13.5 17.5l-7 -5"})]}),K),Wa=R(H("g",{children:[b("path",{d:"M13.542 8.542H6.458a2.5 2.5 0 0 0-2.5 2.5v3.75a2.5 2.5 0 0 0 2.5 2.5h7.084a2.5 2.5 0 0 0 2.5-2.5v-3.75a2.5 2.5 0 0 0-2.5-2.5Z",stroke:"currentColor",strokeWidth:"1.25"}),b("path",{d:"M10 13.958a1.042 1.042 0 1 0 0-2.083 1.042 1.042 0 0 0 0 2.083Z",stroke:"currentColor",strokeWidth:"1.25"}),b("mask",{id:"UnlockedIcon",style:{maskType:"alpha"},maskUnits:"userSpaceOnUse",x:6,y:1,width:9,height:9,children:b("path",{stroke:"none",d:"M6.399 9.561V5.175c0-.93.401-1.823 1.116-2.48a3.981 3.981 0 0 1 2.693-1.028c1.01 0 1.98.37 2.694 1.027.715.658 1.116 1.55 1.116 2.481",fill:"#fff"})}),b("g",{mask:"url(#UnlockedIcon)",children:b("path",{stroke:"none",d:"M5.149 9.561v1.25h2.5v-1.25h-2.5Zm5.06-7.894V.417v1.25Zm2.559 3.508v1.25h2.5v-1.25h-2.5ZM7.648 8.51V5.175h-2.5V8.51h2.5Zm0-3.334c0-.564.243-1.128.713-1.561L6.668 1.775c-.959.883-1.52 2.104-1.52 3.4h2.5Zm.713-1.561a2.732 2.732 0 0 1 1.847-.697v-2.5c-1.31 0-2.585.478-3.54 1.358L8.36 3.614Zm1.847-.697c.71 0 1.374.26 1.847.697l1.694-1.839a5.231 5.231 0 0 0-3.54-1.358v2.5Zm1.847.697c.47.433.713.997.713 1.561h2.5c0-1.296-.56-2.517-1.52-3.4l-1.693 1.839Z",fill:"currentColor"})})]}),Ee),ji=R(H("g",{strokeWidth:"1.25",children:[b("path",{d:"M13.542 8.542H6.458a2.5 2.5 0 0 0-2.5 2.5v3.75a2.5 2.5 0 0 0 2.5 2.5h7.084a2.5 2.5 0 0 0 2.5-2.5v-3.75a2.5 2.5 0 0 0-2.5-2.5Z"}),b("path",{d:"M10 13.958a1.042 1.042 0 1 0 0-2.083 1.042 1.042 0 0 0 0 2.083Z"}),b("path",{d:"M6.667 8.333V5.417C6.667 3.806 8.159 2.5 10 2.5c1.841 0 3.333 1.306 3.333 2.917v2.916"})]}),Ee),_E=R(b("g",{fill:"currentColor",children:b("path",{d:"M12 2a5 5 0 0 1 5 5v3a3 3 0 0 1 3 3v6a3 3 0 0 1 -3 3h-10a3 3 0 0 1 -3 -3v-6a3 3 0 0 1 3 -3v-3a5 5 0 0 1 5 -5m0 12a2 2 0 0 0 -1.995 1.85l-.005 .15a2 2 0 1 0 2 -2m0 -10a3 3 0 0 0 -3 3v3h6v-3a3 3 0 0 0 -3 -3"})}),{width:24,height:24}),DE=R(H(We,{children:[b("path",{d:"M38.5 83.5c-14-2-17.833-10.473-21-22.5C14.333 48.984 12 22 12 12.5",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round"}),b("path",{fillRule:"evenodd",clipRule:"evenodd",d:"m12.005 10.478 7.905 14.423L6 25.75l6.005-15.273Z",fill:"currentColor"}),b("path",{d:"M12.005 10.478c1.92 3.495 3.838 7 7.905 14.423m-7.905-14.423c3.11 5.683 6.23 11.368 7.905 14.423m0 0c-3.68.226-7.35.455-13.91.85m13.91-.85c-5.279.33-10.566.647-13.91.85m0 0c1.936-4.931 3.882-9.86 6.005-15.273M6 25.75c2.069-5.257 4.135-10.505 6.005-15.272",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round"})]}),{width:41,height:94,fill:"none"}),RE=R(H(We,{children:[b("path",{d:"M18.026 1.232c-5.268 13.125-5.548 33.555 3.285 42.311 8.823 8.75 33.31 12.304 42.422 13.523",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round"}),b("path",{fillRule:"evenodd",clipRule:"evenodd",d:"m72.181 59.247-13.058-10-2.948 13.62 16.006-3.62Z",fill:"currentColor"}),b("path",{d:"M72.181 59.247c-3.163-2.429-6.337-4.856-13.058-10m13.058 10c-5.145-3.936-10.292-7.882-13.058-10m0 0c-.78 3.603-1.563 7.196-2.948 13.62m2.948-13.62c-1.126 5.168-2.24 10.346-2.948 13.62m0 0c5.168-1.166 10.334-2.343 16.006-3.62m-16.006 3.62c5.51-1.248 11.01-2.495 16.006-3.62",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round"})]}),{width:85,height:71,fill:"none"}),NE=R(H(We,{children:[b("path",{d:"M1 77c14-2 31.833-11.973 35-24 3.167-12.016-6-35-9.5-43.5",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round"}),b("path",{fillRule:"evenodd",clipRule:"evenodd",d:"m24.165 1.093-2.132 16.309 13.27-4.258-11.138-12.05Z",fill:"currentColor"}),b("path",{d:"M24.165 1.093c-.522 3.953-1.037 7.916-2.132 16.309m2.131-16.309c-.835 6.424-1.68 12.854-2.13 16.308m0 0c3.51-1.125 7.013-2.243 13.27-4.257m-13.27 4.257c5.038-1.608 10.08-3.232 13.27-4.257m0 0c-3.595-3.892-7.197-7.777-11.14-12.05m11.14 12.05c-3.837-4.148-7.667-8.287-11.14-12.05",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round"})]}),{width:38,height:78,fill:"none"}),Oee=R(b("g",{fill:"currentColor",children:b("path",{d:"M39.9 32.889a.326.326 0 0 0-.279-.056c-2.094-3.083-4.774-6-7.343-8.833l-.419-.472a.212.212 0 0 0-.056-.139.586.586 0 0 0-.167-.111l-.084-.083-.056-.056c-.084-.167-.28-.278-.475-.167-.782.39-1.507.973-2.206 1.528-.92.722-1.842 1.445-2.708 2.25a8.405 8.405 0 0 0-.977 1.028c-.14.194-.028.361.14.444-.615.611-1.23 1.223-1.843 1.861a.315.315 0 0 0-.084.223c0 .083.056.166.111.194l1.09.833v.028c1.535 1.528 4.244 3.611 7.12 5.861.418.334.865.667 1.284 1 .195.223.39.473.558.695.084.11.28.139.391.055.056.056.14.111.196.167a.398.398 0 0 0 .167.056.255.255 0 0 0 .224-.111.394.394 0 0 0 .055-.167c.029 0 .028.028.056.028a.318.318 0 0 0 .224-.084l5.082-5.528a.309.309 0 0 0 0-.444Zm-14.63-1.917a.485.485 0 0 0 .111.14c.586.5 1.2 1 1.843 1.555l-2.569-1.945-.251-.166c-.056-.028-.112-.084-.168-.111l-.195-.167.056-.056.055-.055.112-.111c.866-.861 2.346-2.306 3.1-3.028-.81.805-2.43 3.167-2.095 3.944Zm8.767 6.89-2.122-1.612a44.713 44.713 0 0 0-2.625-2.5c1.145.861 2.122 1.611 2.262 1.75 1.117.972 1.06.806 1.815 1.445l.921.666a1.06 1.06 0 0 1-.251.25Zm.558.416-.056-.028c.084-.055.168-.111.252-.194l-.196.222ZM1.089 5.75c.055.361.14.722.195 1.056.335 1.833.67 3.5 1.284 4.75l.252.944c.084.361.223.806.363.917 1.424 1.25 3.602 3.11 5.947 4.889a.295.295 0 0 0 .363 0s0 .027.028.027a.254.254 0 0 0 .196.084.318.318 0 0 0 .223-.084c2.988-3.305 5.221-6.027 6.813-8.305.112-.111.14-.278.14-.417.111-.111.195-.25.307-.333.111-.111.111-.306 0-.39l-.028-.027c0-.055-.028-.139-.084-.167-.698-.666-1.2-1.138-1.731-1.638-.922-.862-1.871-1.75-3.881-3.75l-.028-.028c-.028-.028-.056-.056-.112-.056-.558-.194-1.703-.389-3.127-.639C6.087 2.223 3.21 1.723.614.944c0 0-.168 0-.196.028l-.083.084c-.028.027-.056.055-.224.11h.056-.056c.028.167.028.278.084.473 0 .055.112.5.112.555l.782 3.556Zm15.496 3.278-.335-.334c.084.112.196.195.335.334Zm-3.546 4.666-.056.056c0-.028.028-.056.056-.056Zm-2.038-10c.168.167.866.834 1.033.973-.726-.334-2.54-1.167-3.379-1.445.838.167 1.983.334 2.346.472ZM1.424 2.306c.419.722.754 3.222 1.089 5.666-.196-.778-.335-1.555-.503-2.278-.251-1.277-.503-2.416-.838-3.416.056 0 .14 0 .252.028Zm-.168-.584c-.112 0-.223-.028-.307-.028 0-.027 0-.055-.028-.055.14 0 .223.028.335.083Zm-1.089.222c0-.027 0-.027 0 0ZM39.453 1.333c.028-.11-.558-.61-.363-.639.42-.027.42-.666 0-.666-.558.028-1.144.166-1.675.25-.977.194-1.982.389-2.96.61-2.205.473-4.383.973-6.561 1.557-.67.194-1.424.333-2.066.666-.224.111-.196.333-.084.472-.056.028-.084.028-.14.056-.195.028-.363.056-.558.083-.168.028-.252.167-.224.334 0 .027.028.083.028.11-1.173 1.556-2.485 3.195-3.909 4.945-1.396 1.611-2.876 3.306-4.356 5.056-4.719 5.5-10.052 11.75-15.943 17.25a.268.268 0 0 0 0 .389c.028.027.056.055.084.055-.084.084-.168.14-.252.222-.056.056-.084.111-.084.167a.605.605 0 0 0-.111.139c-.112.111-.112.305.028.389.111.11.307.11.39-.028.029-.028.029-.056.056-.056a.44.44 0 0 1 .615 0c.335.362.67.723.977 1.028l-.698-.583c-.112-.111-.307-.083-.39.028-.113.11-.085.305.027.389l7.427 6.194c.056.056.112.056.196.056s.14-.028.195-.084l.168-.166c.028.027.083.027.111.027.084 0 .14-.027.196-.083 10.052-10.055 18.15-17.639 27.42-24.417.083-.055.111-.166.111-.25.112 0 .196-.083.251-.194 1.704-5.194 2.039-9.806 2.15-12.083v-.028c0-.028.028-.056.028-.083.028-.056.028-.084.028-.084a1.626 1.626 0 0 0-.111-1.028ZM21.472 9.5c.446-.5.893-1.028 1.34-1.5-2.876 3.778-7.65 9.583-14.408 16.5 4.607-5.083 9.242-10.333 13.068-15ZM5.193 35.778h.084-.084Zm3.462 3.194c-.027-.028-.027-.028 0-.028v.028Zm4.16-3.583c.224-.25.448-.472.699-.722 0 0 0 .027.028.027-.252.223-.475.445-.726.695Zm1.146-1.111c.14-.14.279-.334.446-.5l.028-.028c1.648-1.694 3.351-3.389 5.082-5.111l.028-.028c.419-.333.921-.694 1.368-1.028a379.003 379.003 0 0 0-6.952 6.695ZM24.794 6.472c-.921 1.195-1.954 2.778-2.82 4.028-2.736 3.944-11.532 13.583-11.727 13.75a1976.983 1976.983 0 0 1-8.042 7.639l-.167.167c-.14-.167-.14-.417.028-.556C14.49 19.861 22.03 10.167 25.074 5.917c-.084.194-.14.36-.28.555Zm4.83 5.695c-1.116-.64-1.646-1.64-1.34-2.611l.084-.334c.028-.083.084-.194.14-.277.307-.5.754-.917 1.257-1.167.027 0 .055 0 .083-.028-.028-.056-.028-.139-.028-.222.028-.167.14-.278.335-.278.335 0 1.369.306 1.76.639.111.083.223.194.335.305.14.167.363.445.474.667.056.028.112.306.196.445.056.222.111.472.084.694-.028.028 0 .194-.028.194a2.668 2.668 0 0 1-.363 1.028c-.028.028-.028.056-.056.084l-.028.027c-.14.223-.335.417-.53.556-.643.444-1.369.583-2.095.389 0 0-.195-.084-.28-.111Zm8.154-.834a39.098 39.098 0 0 1-.893 3.167c0 .028-.028.083 0 .111-.056 0-.084.028-.14.056-2.206 1.61-4.356 3.305-6.506 5.028 1.843-1.64 3.686-3.306 5.613-4.945.558-.5.949-1.139 1.06-1.861l.28-1.667v-.055c.14-.334.67-.195.586.166Z",fill:"currentColor"})}),{width:40,height:40,fill:"none"}),Ya=R(H("g",{stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M6 6l4.153 11.793a0.365 .365 0 0 0 .331 .207a0.366 .366 0 0 0 .332 -.207l2.184 -4.793l4.787 -1.994a0.355 .355 0 0 0 .213 -.323a0.355 .355 0 0 0 -.213 -.323l-11.787 -4.36z"}),b("path",{d:"M13.5 13.5l4.5 4.5"})]}),{fill:"none",width:22,height:22,strokeWidth:1.25}),Hr=R(H("g",{stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,children:[b("path",{d:"M4.028 13.252c-.657 -.972 -1.028 -2.078 -1.028 -3.252c0 -3.866 4.03 -7 9 -7s9 3.134 9 7s-4.03 7 -9 7c-1.913 0 -3.686 -.464 -5.144 -1.255"}),b("path",{d:"M5 15m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"}),b("path",{d:"M5 17c0 1.42 .316 2.805 1 4"})]}),{fill:"none",width:22,height:22,strokeWidth:1.25}),qi=R(H("g",{strokeWidth:"1.5",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"})]}),K),Ji=R(H("g",{strokeWidth:"1.5",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M10.5 20.4l-6.9 -6.9c-.781 -.781 -.781 -2.219 0 -3l6.9 -6.9c.781 -.781 2.219 -.781 3 0l6.9 6.9c.781 .781 .781 2.219 0 3l-6.9 6.9c-.781 .781 -2.219 .781 -3 0z"})]}),K),Qi=R(H("g",{strokeWidth:"1.5",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("circle",{cx:"12",cy:"12",r:"9"})]}),K),gm=R(H("g",{strokeWidth:"1.5",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("line",{x1:"5",y1:"12",x2:"19",y2:"12"}),b("line",{x1:"15",y1:"16",x2:"19",y2:"12"}),b("line",{x1:"15",y1:"8",x2:"19",y2:"12"})]}),K),es=R(b("path",{d:"M4.167 10h11.666",strokeWidth:"1.5"}),Ee),BE=R(H("g",{strokeWidth:"1.25",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M20 17v-12c0 -1.121 -.879 -2 -2 -2s-2 .879 -2 2v12l2 2l2 -2z"}),b("path",{d:"M16 7h4"}),b("path",{d:"M18 19h-13a2 2 0 1 1 0 -4h4a2 2 0 1 0 0 -4h-3"})]}),K),Bn=R(H("g",{strokeWidth:"1.25",children:[b("path",{clipRule:"evenodd",d:"m7.643 15.69 7.774-7.773a2.357 2.357 0 1 0-3.334-3.334L4.31 12.357a3.333 3.333 0 0 0-.977 2.357v1.953h1.953c.884 0 1.732-.352 2.357-.977Z"}),b("path",{d:"m11.25 5.417 3.333 3.333"})]}),Ee),Fn=R(H("g",{strokeWidth:"1.5",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("line",{x1:"4",y1:"20",x2:"7",y2:"20"}),b("line",{x1:"14",y1:"20",x2:"21",y2:"20"}),b("line",{x1:"6.9",y1:"15",x2:"13.8",y2:"15"}),b("line",{x1:"10.2",y1:"6.3",x2:"16",y2:"20"}),b("polyline",{points:"5 20 11 4 13 4 20 20"})]}),K),FE=R(H("g",{stroke:"currentColor",strokeWidth:"1.5",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M3 7v-2h13v2"}),b("path",{d:"M10 5v14"}),b("path",{d:"M12 19h-4"}),b("path",{d:"M15 13v-1h6v1"}),b("path",{d:"M18 12v7"}),b("path",{d:"M17 19h2"})]}),K),ts=R(H("g",{strokeWidth:"1.25",children:[b("path",{d:"M12.5 6.667h.01"}),b("path",{d:"M4.91 2.625h10.18a2.284 2.284 0 0 1 2.285 2.284v10.182a2.284 2.284 0 0 1-2.284 2.284H4.909a2.284 2.284 0 0 1-2.284-2.284V4.909a2.284 2.284 0 0 1 2.284-2.284Z"}),b("path",{d:"m3.333 12.5 3.334-3.333c.773-.745 1.726-.745 2.5 0l4.166 4.166"}),b("path",{d:"m11.667 11.667.833-.834c.774-.744 1.726-.744 2.5 0l1.667 1.667"})]}),Ee),hm=R(H("g",{strokeWidth:"1.5",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M19 20h-10.5l-4.21 -4.3a1 1 0 0 1 0 -1.41l10 -10a1 1 0 0 1 1.41 0l5 5a1 1 0 0 1 0 1.41l-9.2 9.3"}),b("path",{d:"M18 13.3l-6.3 -6.3"})]}),K),fh=R(b("path",{strokeWidth:"1.25",d:"M10 4.167v11.666M4.167 10h11.666"}),Ee),bh=R(b("path",{d:"M5 10h10",strokeWidth:"1.25"}),Ee),OE=R(H("g",{strokeWidth:1.25,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M21 21l-6 -6"}),b("path",{d:"M3.268 12.043a7.017 7.017 0 0 0 6.634 4.957a7.012 7.012 0 0 0 7.043 -6.131a7 7 0 0 0 -5.314 -7.672a7.021 7.021 0 0 0 -8.241 4.403"}),b("path",{d:"M3 4v4h4"})]}),K),Ut=R(b("path",{strokeWidth:"1.25",d:"M3.333 5.833h13.334M8.333 9.167v5M11.667 9.167v5M4.167 5.833l.833 10c0 .92.746 1.667 1.667 1.667h6.666c.92 0 1.667-.746 1.667-1.667l.833-10M7.5 5.833v-2.5c0-.46.373-.833.833-.833h3.334c.46 0 .833.373.833.833v2.5"}),Ee),os=R(H("g",{strokeWidth:"1.5",children:[b("polyline",{points:"12 16 18 10 12 4"}),b("polyline",{points:"8 4 2 10 8 16"})]}),Ee),tc=R(H("g",{strokeWidth:"1.25",children:[b("path",{d:"M14.375 6.458H8.958a2.5 2.5 0 0 0-2.5 2.5v5.417a2.5 2.5 0 0 0 2.5 2.5h5.417a2.5 2.5 0 0 0 2.5-2.5V8.958a2.5 2.5 0 0 0-2.5-2.5Z"}),b("path",{clipRule:"evenodd",d:"M11.667 3.125c.517 0 .986.21 1.325.55.34.338.55.807.55 1.325v1.458H8.333c-.485 0-.927.185-1.26.487-.343.312-.57.75-.609 1.24l-.005 5.357H5a1.87 1.87 0 0 1-1.326-.55 1.87 1.87 0 0 1-.549-1.325V5c0-.518.21-.987.55-1.326.338-.34.807-.549 1.325-.549h6.667Z"})]}),Ee),oc=R(b("path",{clipRule:"evenodd",d:"M10 2.5h.328a6.25 6.25 0 0 0 6.6 10.372A7.5 7.5 0 1 1 10 2.493V2.5Z",stroke:"currentColor"}),Ee),nc=R(b("g",{stroke:"currentColor",strokeLinejoin:"round",children:b("path",{d:"M10 12.5a2.5 2.5 0 1 0 0-5 2.5 2.5 0 0 0 0 5ZM10 4.167V2.5M14.167 5.833l1.166-1.166M15.833 10H17.5M14.167 14.167l1.166 1.166M10 15.833V17.5M5.833 14.167l-1.166 1.166M5 10H3.333M5.833 5.833 4.667 4.667"})}),{...Ee,strokeWidth:1.5}),zE=R(H("g",{strokeWidth:"1.5",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("line",{x1:"4",y1:"6",x2:"20",y2:"6"}),b("line",{x1:"4",y1:"12",x2:"20",y2:"12"}),b("line",{x1:"4",y1:"18",x2:"20",y2:"18"})]}),K),$a=R(b("path",{strokeWidth:"1.25",d:"M3.333 14.167v1.666c0 .92.747 1.667 1.667 1.667h10c.92 0 1.667-.746 1.667-1.667v-1.666M5.833 9.167 10 13.333l4.167-4.166M10 3.333v10"}),Ee),ns=R(H("g",{strokeWidth:"1.5",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("circle",{cx:"12",cy:"12",r:"9"}),b("line",{x1:"12",y1:"17",x2:"12",y2:"17.01"}),b("path",{d:"M12 13.5a1.5 1.5 0 0 1 1 -1.5a2.6 2.6 0 1 0 -3 -4"})]}),K),HE=R(H("g",{strokeWidth:"1.25",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("circle",{cx:"12",cy:"12",r:"9"}),b("line",{x1:"12",y1:"17",x2:"12",y2:"17.01"}),b("path",{d:"M12 13.5a1.5 1.5 0 0 1 1 -1.5a2.6 2.6 0 1 0 -3 -4"})]}),K),xh=R(b("path",{strokeWidth:"1.25",d:"M9.167 5.833H5.833c-1.254 0-2.5 1.282-2.5 2.5v5.834c0 1.283 1.252 2.5 2.5 2.5h5.834c1.251 0 2.5-1.25 2.5-2.5v-3.334M8.333 11.667l8.334-8.334M12.5 3.333h4.167V7.5"}),Ee),fm=R(b("path",{d:"M7.5 15.833c-3.583 1.167-3.583-2.083-5-2.5m10 4.167v-2.917c0-.833.083-1.166-.417-1.666 2.334-.25 4.584-1.167 4.584-5a3.833 3.833 0 0 0-1.084-2.667 3.5 3.5 0 0 0-.083-2.667s-.917-.25-2.917 1.084a10.25 10.25 0 0 0-5.166 0C5.417 2.333 4.5 2.583 4.5 2.583a3.5 3.5 0 0 0-.083 2.667 3.833 3.833 0 0 0-1.084 2.667c0 3.833 2.25 4.75 4.584 5-.5.5-.5 1-.417 1.666V17.5",strokeWidth:"1.25"}),Ee),GE=R(H("g",{strokeWidth:"1.25",children:[b("path",{d:"M7.5 10.833a.833.833 0 1 0 0-1.666.833.833 0 0 0 0 1.666ZM12.5 10.833a.833.833 0 1 0 0-1.666.833.833 0 0 0 0 1.666ZM6.25 6.25c2.917-.833 4.583-.833 7.5 0M5.833 13.75c2.917.833 5.417.833 8.334 0"}),b("path",{d:"M12.917 14.167c0 .833 1.25 2.5 1.666 2.5 1.25 0 2.361-1.39 2.917-2.5.556-1.39.417-4.861-1.25-9.584-1.214-.846-2.5-1.116-3.75-1.25l-.833 2.084M7.083 14.167c0 .833-1.13 2.5-1.526 2.5-1.191 0-2.249-1.39-2.778-2.5-.529-1.39-.397-4.861 1.19-9.584 1.157-.846 2.318-1.116 3.531-1.25l.833 2.084"})]}),Ee),UE=R(H("g",{strokeWidth:"1.25",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M4 4l11.733 16h4.267l-11.733 -16z"}),b("path",{d:"M4 20l6.768 -6.768m2.46 -2.46l6.772 -6.772"})]}),K),bm=R(b("polyline",{fill:"none",stroke:"currentColor",points:"20 6 9 17 4 12"}),{width:24,height:24}),rc=R(H("g",{strokeWidth:"1.25",children:[b("path",{d:"M8.333 11.667a2.917 2.917 0 0 0 4.167 0l3.333-3.334a2.946 2.946 0 1 0-4.166-4.166l-.417.416"}),b("path",{d:"M11.667 8.333a2.917 2.917 0 0 0-4.167 0l-3.333 3.334a2.946 2.946 0 0 0 4.166 4.166l.417-.416"})]}),Ee),WE=R("M433.941 129.941l-83.882-83.882A48 48 0 0 0 316.118 32H48C21.49 32 0 53.49 0 80v352c0 26.51 21.49 48 48 48h352c26.51 0 48-21.49 48-48V163.882a48 48 0 0 0-14.059-33.941zM224 416c-35.346 0-64-28.654-64-64 0-35.346 28.654-64 64-64s64 28.654 64 64c0 35.346-28.654 64-64 64zm96-304.52V212c0 6.627-5.373 12-12 12H76c-6.627 0-12-5.373-12-12V108c0-6.627 5.373-12 12-12h228.52c3.183 0 6.235 1.264 8.485 3.515l3.48 3.48A11.996 11.996 0 0 1 320 111.48z",{width:448,height:512}),YE=R("M252 54L203 8a28 27 0 00-20-8H28C12 0 0 12 0 27v195c0 15 12 26 28 26h204c15 0 28-11 28-26V73a28 27 0 00-8-19zM130 213c-21 0-37-16-37-36 0-19 16-35 37-35 20 0 37 16 37 35 0 20-17 36-37 36zm56-169v56c0 4-4 6-7 6H44c-4 0-7-2-7-6V42c0-4 3-7 7-7h133l4 2 3 2a7 7 0 012 5z M296 201l87 95-188 205-78 9c-10 1-19-8-18-20l9-84zm141-14l-41-44a31 31 0 00-46 0l-38 41 87 95 38-42c13-14 13-36 0-50z",{width:448,height:512}),rs=R(b("path",{d:"m9.257 6.351.183.183H15.819c.34 0 .727.182 1.051.506.323.323.505.708.505 1.05v5.819c0 .316-.183.7-.52 1.035-.337.338-.723.522-1.037.522H4.182c-.352 0-.74-.181-1.058-.5-.318-.318-.499-.705-.499-1.057V5.182c0-.351.181-.736.5-1.054.32-.321.71-.503 1.057-.503H6.53l2.726 2.726Z",strokeWidth:"1.25"}),Ee),zee=R("M384 112v352c0 26.51-21.49 48-48 48H48c-26.51 0-48-21.49-48-48V112c0-26.51 21.49-48 48-48h80c0-35.29 28.71-64 64-64s64 28.71 64 64h80c26.51 0 48 21.49 48 48zM192 40c-13.255 0-24 10.745-24 24s10.745 24 24 24 24-10.745 24-24-10.745-24-24-24m96 114v-20a6 6 0 0 0-6-6H102a6 6 0 0 0-6 6v20a6 6 0 0 0 6 6h180a6 6 0 0 0 6-6z",{width:384,height:512}),Hee=R("M204.3 5C104.9 24.4 24.8 104.3 5.2 203.4c-37 187 131.7 326.4 258.8 306.7 41.2-6.4 61.4-54.6 42.5-91.7-23.1-45.4 9.9-98.4 60.9-98.4h79.7c35.8 0 64.8-29.6 64.9-65.3C511.5 97.1 368.1-26.9 204.3 5zM96 320c-17.7 0-32-14.3-32-32s14.3-32 32-32 32 14.3 32 32-14.3 32-32 32zm32-128c-17.7 0-32-14.3-32-32s14.3-32 32-32 32 14.3 32 32-14.3 32-32 32zm128-64c-17.7 0-32-14.3-32-32s14.3-32 32-32 32 14.3 32 32-14.3 32-32 32zm128 64c-17.7 0-32-14.3-32-32s14.3-32 32-32 32 14.3 32 32-14.3 32-32 32z"),xm=R(H("g",{strokeWidth:1.25,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M5 16l1.465 1.638a2 2 0 1 1 -3.015 .099l1.55 -1.737z"}),b("path",{d:"M13.737 9.737c2.299 -2.3 3.23 -5.095 2.081 -6.245c-1.15 -1.15 -3.945 -.217 -6.244 2.082c-2.3 2.299 -3.231 5.095 -2.082 6.244c1.15 1.15 3.946 .218 6.245 -2.081z"}),b("path",{d:"M7.492 11.818c.362 .362 .768 .676 1.208 .934l6.895 4.047c1.078 .557 2.255 -.075 3.692 -1.512c1.437 -1.437 2.07 -2.614 1.512 -3.692c-.372 -.718 -1.72 -3.017 -4.047 -6.895a6.015 6.015 0 0 0 -.934 -1.208"})]}),K),$E=R(b("g",{strokeWidth:1.5,children:b("path",{d:"M6 18l12 -12"})}),K),ym=R(H("g",{strokeWidth:"1.25",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M15 8h.01"}),b("path",{d:"M12 20h-5a3 3 0 0 1 -3 -3v-10a3 3 0 0 1 3 -3h10a3 3 0 0 1 3 3v5"}),b("path",{d:"M4 15l4 -4c.928 -.893 2.072 -.893 3 0l4 4"}),b("path",{d:"M14 14l1 -1c.617 -.593 1.328 -.793 2.009 -.598"}),b("path",{d:"M19 16v6"}),b("path",{d:"M22 19l-3 3l-3 -3"})]}),K),VE=R("M216 0h80c13.3 0 24 10.7 24 24v168h87.7c17.8 0 26.7 21.5 14.1 34.1L269.7 378.3c-7.5 7.5-19.8 7.5-27.3 0L90.1 226.1c-12.6-12.6-3.7-34.1 14.1-34.1H192V24c0-13.3 10.7-24 24-24zm296 376v112c0 13.3-10.7 24-24 24H24c-13.3 0-24-10.7-24-24V376c0-13.3 10.7-24 24-24h146.7l49 49c20.1 20.1 52.5 20.1 72.6 0l49-49H488c13.3 0 24 10.7 24 24zm-124 88c0-11-9-20-20-20s-20 9-20 20 9 20 20 20 20-9 20-20zm64 0c0-11-9-20-20-20s-20 9-20 20 9 20 20 20 20-9 20-20z",{width:512,height:512}),Gee=R("M416 208H272V64c0-17.67-14.33-32-32-32h-32c-17.67 0-32 14.33-32 32v144H32c-17.67 0-32 14.33-32 32v32c0 17.67 14.33 32 32 32h144v144c0 17.67 14.33 32 32 32h32c17.67 0 32-14.33 32-32V304h144c17.67 0 32-14.33 32-32v-32c0-17.67-14.33-32-32-32z",{width:448,height:512}),Uee=R("M416 208H32c-17.67 0-32 14.33-32 32v32c0 17.67 14.33 32 32 32h384c17.67 0 32-14.33 32-32v-32c0-17.67-14.33-32-32-32z",{width:448,height:512}),KE=R("M173.898 439.404l-166.4-166.4c-9.997-9.997-9.997-26.206 0-36.204l36.203-36.204c9.997-9.998 26.207-9.998 36.204 0L192 312.69 432.095 72.596c9.997-9.997 26.207-9.997 36.204 0l36.203 36.204c9.997 9.997 9.997 26.206 0 36.204l-294.4 294.401c-9.998 9.997-26.207 9.997-36.204-.001z"),Wee=R("M16 132h416c8.837 0 16-7.163 16-16V76c0-8.837-7.163-16-16-16H16C7.163 60 0 67.163 0 76v40c0 8.837 7.163 16 16 16zm0 160h416c8.837 0 16-7.163 16-16v-40c0-8.837-7.163-16-16-16H16c-8.837 0-16 7.163-16 16v40c0 8.837 7.163 16 16 16zm0 160h416c8.837 0 16-7.163 16-16v-40c0-8.837-7.163-16-16-16H16c-8.837 0-16 7.163-16 16v40c0 8.837 7.163 16 16 16z"),yh=R(b("path",{d:"M7.5 10.833 4.167 7.5 7.5 4.167M4.167 7.5h9.166a3.333 3.333 0 0 1 0 6.667H12.5",strokeWidth:"1.25"}),Ee),Eh=R(b("path",{d:"M12.5 10.833 15.833 7.5 12.5 4.167M15.833 7.5H6.667a3.333 3.333 0 1 0 0 6.667H7.5",strokeWidth:"1.25"}),Ee),XE=R("M504 256c0 136.997-111.043 248-248 248S8 392.997 8 256C8 119.083 119.043 8 256 8s248 111.083 248 248zM262.655 90c-54.497 0-89.255 22.957-116.549 63.758-3.536 5.286-2.353 12.415 2.715 16.258l34.699 26.31c5.205 3.947 12.621 3.008 16.665-2.122 17.864-22.658 30.113-35.797 57.303-35.797 20.429 0 45.698 13.148 45.698 32.958 0 14.976-12.363 22.667-32.534 33.976C247.128 238.528 216 254.941 216 296v4c0 6.627 5.373 12 12 12h56c6.627 0 12-5.373 12-12v-1.333c0-28.462 83.186-29.647 83.186-106.667 0-58.002-60.165-102-116.531-102zM256 338c-25.365 0-46 20.635-46 46 0 25.364 20.635 46 46 46s46-20.636 46-46c0-25.365-20.635-46-46-46z",{mirror:!0}),ZE=R(b("path",{d:"M5 12.5a2.5 2.5 0 1 0 0-5 2.5 2.5 0 0 0 0 5ZM15 7.5a2.5 2.5 0 1 0 0-5 2.5 2.5 0 0 0 0 5ZM15 17.5a2.5 2.5 0 1 0 0-5 2.5 2.5 0 0 0 0 5ZM7.25 8.917l5.5-2.834M7.25 11.083l5.5 2.834",strokeWidth:"1.5"}),Ee),Yee=R("M256 32c14.2 0 27.3 7.5 34.5 19.8l216 368c7.3 12.4 7.3 27.7 .2 40.1S486.3 480 472 480H40c-14.3 0-27.6-7.7-34.7-20.1s-7-27.8 .2-40.1l216-368C228.7 39.5 241.8 32 256 32zm0 128c-13.3 0-24 10.7-24 24V296c0 13.3 10.7 24 24 24s24-10.7 24-24V184c0-13.3-10.7-24-24-24zm32 224a32 32 0 1 0 -64 0 32 32 0 1 0 64 0z"),$ee=R("M16 5l-1.42 1.42-1.59-1.59V16h-1.98V4.83L9.42 6.42 8 5l4-4 4 4zm4 5v11c0 1.1-.9 2-2 2H6c-1.11 0-2-.9-2-2V10c0-1.11.89-2 2-2h3v2H6v11h12V10h-3V8h3c1.1 0 2 .89 2 2z",{width:24,height:24}),Vee=R(H("g",{strokeWidth:1.25,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M8 9h-1a2 2 0 0 0 -2 2v8a2 2 0 0 0 2 2h10a2 2 0 0 0 2 -2v-8a2 2 0 0 0 -2 -2h-1"}),b("path",{d:"M12 14v-11"}),b("path",{d:"M9 6l3 -3l3 3"})]}),K),Kee=R(H(We,{children:[b("path",{fill:"currentColor",d:"M40 5.6v6.1l-4.1.7c-8.9 1.4-16.5 6.9-20.6 15C13 32 10.9 43 12.4 43c.4 0 2.4-1.3 4.4-3 5-3.9 12.1-7 18.2-7.7l5-.6v12.8l11.2-11.3L62.5 22 51.2 10.8 40-.5v6.1zm10.2 22.6L44 34.5v-6.8l-6.9.6c-3.9.3-9.8 1.7-13.2 3.1-3.5 1.4-6.5 2.4-6.7 2.2-.9-1 3-7.5 6.4-10.8C28 18.6 34.4 16 40.1 16c3.7 0 3.9-.1 3.9-3.2V9.5l6.2 6.3 6.3 6.2-6.3 6.2z"}),b("path",{stroke:"currentColor",fill:"currentColor",d:"M0 36v20h48v-6.2c0-6 0-6.1-2-4.3-1.1 1-2 2.9-2 4.2V52H4V34c0-17.3-.1-18-2-18s-2 .7-2 20z"})]}),{width:64,height:64}),Xee=R(b("path",{stroke:"currentColor",strokeWidth:"40",fill:"currentColor",d:"M148 560a318 318 0 0 0 522 110 316 316 0 0 0 0-450 316 316 0 0 0-450 0c-11 11-21 22-30 34v4h47c25 0 46 21 46 46s-21 45-46 45H90c-13 0-25-6-33-14-9-9-14-20-14-33V156c0-25 20-45 45-45s45 20 45 45v32l1 1a401 401 0 0 1 623 509l212 212a42 42 0 0 1-59 59L698 757A401 401 0 0 1 65 570a42 42 0 0 1 83-10z"}),{width:1024}),jE=H("g",{strokeWidth:1.5,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M12 10l0 10"}),b("path",{d:"M12 10l4 4"}),b("path",{d:"M12 10l-4 4"}),b("path",{d:"M4 4l16 0"})]}),qE=H("g",{strokeWidth:1.5,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M12 5l0 14"}),b("path",{d:"M16 9l-4 -4"}),b("path",{d:"M8 9l4 -4"})]}),wh=R(qE,K),vh=R(qE,{...K,style:{transform:"rotate(180deg)"}}),Ih=R(jE,K),Th=R(jE,{...K,style:{transform:"rotate(180deg)"}}),Ch=R(H(We,{children:[H("g",{clipPath:"url(#a)",stroke:"currentColor",strokeWidth:"1.25",children:[b("path",{d:"M3.333 3.333h13.334",strokeLinecap:"round",strokeLinejoin:"round"}),b("path",{d:"M13.542 6.458h-.417c-.92 0-1.667.747-1.667 1.667v7.083c0 .92.746 1.667 1.667 1.667h.417c.92 0 1.666-.746 1.666-1.667V8.125c0-.92-.746-1.667-1.666-1.667ZM6.875 6.458h-.417c-.92 0-1.666.747-1.666 1.667v3.75c0 .92.746 1.667 1.666 1.667h.417c.92 0 1.667-.746 1.667-1.667v-3.75c0-.92-.747-1.667-1.667-1.667Z"})]}),b("defs",{children:b("clipPath",{id:"a",children:b("path",{fill:"#fff",d:"M0 0h20v20H0z"})})})]}),Ee),kh=R(H(We,{children:[H("g",{clipPath:"url(#a)",stroke:"currentColor",strokeWidth:"1.25",children:[b("path",{d:"M3.333 16.667h13.334",strokeLinecap:"round",strokeLinejoin:"round"}),b("path",{d:"M6.875 3.125h-.417c-.92 0-1.666.746-1.666 1.667v7.083c0 .92.746 1.667 1.666 1.667h.417c.92 0 1.667-.746 1.667-1.667V4.792c0-.92-.747-1.667-1.667-1.667ZM13.542 5.817h-.417c-.92 0-1.667.747-1.667 1.667v4.391c0 .92.746 1.667 1.667 1.667h.417c.92 0 1.666-.746 1.666-1.667V7.484c0-.92-.746-1.667-1.666-1.667Z"})]}),b("defs",{children:b("clipPath",{id:"a",children:b("path",{fill:"#fff",d:"M0 0h20v20H0z"})})})]}),Ee),Sh=R(H(We,{children:[H("g",{clipPath:"url(#a)",stroke:"currentColor",strokeWidth:"1.25",children:[b("path",{d:"M3.333 3.333v13.334",strokeLinecap:"round",strokeLinejoin:"round"}),b("path",{d:"M15.208 4.792H8.125c-.92 0-1.667.746-1.667 1.666v.417c0 .92.747 1.667 1.667 1.667h7.083c.92 0 1.667-.747 1.667-1.667v-.417c0-.92-.746-1.666-1.667-1.666ZM12.516 11.458H8.125c-.92 0-1.667.746-1.667 1.667v.417c0 .92.747 1.666 1.667 1.666h4.391c.92 0 1.667-.746 1.667-1.666v-.417c0-.92-.746-1.667-1.667-1.667Z"})]}),b("defs",{children:b("clipPath",{id:"a",children:b("path",{fill:"#fff",d:"M0 0h20v20H0z"})})})]}),Ee),Mh=R(H(We,{children:[H("g",{clipPath:"url(#a)",stroke:"currentColor",strokeWidth:"1.25",children:[b("path",{d:"M16.667 3.333v13.334",strokeLinecap:"round",strokeLinejoin:"round"}),b("path",{d:"M11.875 4.792H4.792c-.92 0-1.667.746-1.667 1.666v.417c0 .92.746 1.667 1.667 1.667h7.083c.92 0 1.667-.747 1.667-1.667v-.417c0-.92-.746-1.666-1.667-1.666ZM11.683 11.458H7.292c-.92 0-1.667.746-1.667 1.667v.417c0 .92.746 1.666 1.667 1.666h4.39c.921 0 1.667-.746 1.667-1.666v-.417c0-.92-.746-1.667-1.666-1.667Z"})]}),b("defs",{children:b("clipPath",{id:"a",children:b("path",{fill:"#fff",d:"M0 0h20v20H0z"})})})]}),Ee),JE=R(H(We,{children:[H("g",{clipPath:"url(#a)",stroke:"currentColor",strokeWidth:"1.25",children:[b("path",{d:"M16.667 3.333v13.334M3.333 3.333v13.334",strokeLinecap:"round",strokeLinejoin:"round"}),b("path",{d:"M14.375 10.208v-.416c0-.92-.746-1.667-1.667-1.667H7.292c-.92 0-1.667.746-1.667 1.667v.416c0 .92.746 1.667 1.667 1.667h5.416c.92 0 1.667-.746 1.667-1.667Z"})]}),b("defs",{children:b("clipPath",{id:"a",children:b("path",{fill:"#fff",d:"M0 0h20v20H0z"})})})]}),Ee),QE=R(H(We,{children:[H("g",{clipPath:"url(#a)",stroke:"currentColor",strokeWidth:"1.25",children:[b("path",{d:"M3.333 3.333h13.334M3.333 16.667h13.334",strokeLinecap:"round",strokeLinejoin:"round"}),b("path",{d:"M10.208 5.625h-.416c-.92 0-1.667.746-1.667 1.667v5.416c0 .92.746 1.667 1.667 1.667h.416c.92 0 1.667-.746 1.667-1.667V7.292c0-.92-.746-1.667-1.667-1.667Z"})]}),b("defs",{children:b("clipPath",{id:"a",children:b("path",{fill:"#fff",d:"M0 0h20v20H0z"})})})]}),Ee),Ph=R(H("g",{stroke:"currentColor",strokeWidth:"1.25",children:[b("path",{d:"M1.667 10h2.916",strokeLinecap:"round",strokeLinejoin:"round"}),b("path",{d:"M8.333 10h3.334",strokeLinejoin:"round"}),b("path",{d:"M15.417 10h2.916",strokeLinecap:"round",strokeLinejoin:"round"}),b("path",{d:"M6.875 4.792h-.417c-.92 0-1.666.746-1.666 1.666v7.084c0 .92.746 1.666 1.666 1.666h.417c.92 0 1.667-.746 1.667-1.666V6.458c0-.92-.747-1.666-1.667-1.666ZM13.542 6.458h-.417c-.92 0-1.667.747-1.667 1.667v3.75c0 .92.746 1.667 1.667 1.667h.417c.92 0 1.666-.746 1.666-1.667v-3.75c0-.92-.746-1.667-1.666-1.667Z"})]}),Ee),Ah=R(H("g",{stroke:"currentColor",strokeWidth:"1.25",children:[b("path",{d:"M10 18.333v-2.916",strokeLinecap:"round",strokeLinejoin:"round"}),b("path",{d:"M10 11.667V8.333",strokeLinejoin:"round"}),b("path",{d:"M10 4.583V1.667",strokeLinecap:"round",strokeLinejoin:"round"}),b("path",{d:"M4.792 13.125v.417c0 .92.746 1.666 1.666 1.666h7.084c.92 0 1.666-.746 1.666-1.666v-.417c0-.92-.746-1.667-1.666-1.667H6.458c-.92 0-1.666.746-1.666 1.667ZM6.458 6.458v.417c0 .92.747 1.667 1.667 1.667h3.75c.92 0 1.667-.747 1.667-1.667v-.417c0-.92-.746-1.666-1.667-1.666h-3.75c-.92 0-1.667.746-1.667 1.666Z"})]}),Ee),Em=R(H("g",{strokeWidth:"1.5",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("circle",{cx:"9",cy:"7",r:"4"}),b("path",{d:"M3 21v-2a4 4 0 0 1 4 -4h4a4 4 0 0 1 4 4v2"}),b("path",{d:"M16 3.13a4 4 0 0 1 0 7.75"}),b("path",{d:"M21 21v-2a4 4 0 0 0 -3 -3.85"})]}),K),Zee=R("M256 8C119 8 8 119 8 256s111 248 248 248 248-111 248-248S393 8 256 8zm115.7 272l-176 101c-15.8 8.8-35.7-2.5-35.7-21V152c0-18.4 19.8-29.8 35.7-21l176 107c16.4 9.2 16.4 32.9 0 42z"),ew=R("M256 8C119 8 8 119 8 256s111 248 248 248 248-111 248-248S393 8 256 8zm96 328c0 8.8-7.2 16-16 16H176c-8.8 0-16-7.2-16-16V176c0-8.8 7.2-16 16-16h160c8.8 0 16 7.2 16 16v160z"),Go=R(H(We,{children:[b("g",{clipPath:"url(#a)",stroke:"currentColor",strokeWidth:"1.25",strokeLinecap:"round",strokeLinejoin:"round",children:b("path",{d:"M15 5 5 15M5 5l10 10"})}),b("defs",{children:b("clipPath",{id:"a",children:b("path",{fill:"#fff",d:"M0 0h20v20H0z"})})})]}),Ee),jee=R("M464 0c26.51 0 48 21.49 48 48v288c0 26.51-21.49 48-48 48H176c-26.51 0-48-21.49-48-48V48c0-26.51 21.49-48 48-48h288M176 416c-44.112 0-80-35.888-80-80V128H48c-26.51 0-48 21.49-48 48v288c0 26.51 21.49 48 48 48h288c26.51 0 48-21.49 48-48v-48H176z",{mirror:!0}),qee=R("M11.553 22.894a.998.998 0 00.894 0s3.037-1.516 5.465-4.097C19.616 16.987 21 14.663 21 12V5a1 1 0 00-.649-.936l-8-3a.998.998 0 00-.702 0l-8 3A1 1 0 003 5v7c0 2.663 1.384 4.987 3.088 6.797 2.428 2.581 5.465 4.097 5.465 4.097zm-1.303-8.481l6.644-6.644a.856.856 0 111.212 1.212l-7.25 7.25a.856.856 0 01-1.212 0l-3.75-3.75a.856.856 0 111.212-1.212l3.144 3.144z",{width:24}),Jee=R("M369.9 97.9L286 14C277 5 264.8-.1 252.1-.1H48C21.5 0 0 21.5 0 48v416c0 26.5 21.5 48 48 48h288c26.5 0 48-21.5 48-48V131.9c0-12.7-5.1-25-14.1-34zM332.1 128H256V51.9l76.1 76.1zM48 464V48h160v104c0 13.3 10.7 24 24 24h104v288H48zm32-48h224V288l-23.5-23.5c-4.7-4.7-12.3-4.7-17 0L176 352l-39.5-39.5c-4.7-4.7-12.3-4.7-17 0L80 352v64zm48-240c-26.5 0-48 21.5-48 48s21.5 48 48 48 48-21.5 48-48-21.5-48-48-48z",{width:384,height:512}),Lh=_t.memo(({theme:e})=>R(H(We,{children:[b("path",{d:"M25 26H111V111H25",fill:pn(e)}),b("path",{d:"M25 111C25 80.2068 25 49.4135 25 26M25 26C48.6174 26 72.2348 26 111 26H25ZM25 26C53.3671 26 81.7343 26 111 26H25ZM111 26C111 52.303 111 78.606 111 111V26ZM111 26C111 51.2947 111 76.5893 111 111V26ZM111 111C87.0792 111 63.1585 111 25 111H111ZM111 111C87.4646 111 63.9293 111 25 111H111ZM25 111C25 81.1514 25 51.3028 25 26V111Z",stroke:pn(e),strokeWidth:"2"}),b("path",{d:"M100 100H160V160H100",fill:pn(e)}),b("path",{d:"M100 160C100 144.106 100 128.211 100 100M100 100C117.706 100 135.412 100 160 100H100ZM100 100C114.214 100 128.428 100 160 100H100ZM160 100C160 120.184 160 140.369 160 160V100ZM160 100C160 113.219 160 126.437 160 160V100ZM160 160C145.534 160 131.068 160 100 160H160ZM160 160C143.467 160 126.934 160 100 160H160ZM100 160C100 143.661 100 127.321 100 100V160Z",stroke:pn(e),strokeWidth:"2"}),H("g",{fill:SE(e),stroke:pn(e),strokeWidth:"6",children:[b("rect",{x:"2.5",y:"2.5",width:"30",height:"30"}),b("rect",{x:"2.5",y:"149.5",width:"30",height:"30"}),b("rect",{x:"147.5",y:"149.5",width:"30",height:"30"}),b("rect",{x:"147.5",y:"2.5",width:"30",height:"30"})]})]}),{width:182,height:182,mirror:!0})),_h=_t.memo(({theme:e})=>R(H(We,{children:[b("path",{d:"M25 26H111V111H25",fill:pn(e)}),b("path",{d:"M25 111C25 80.2068 25 49.4135 25 26M25 26C48.6174 26 72.2348 26 111 26H25ZM25 26C53.3671 26 81.7343 26 111 26H25ZM111 26C111 52.303 111 78.606 111 111V26ZM111 26C111 51.2947 111 76.5893 111 111V26ZM111 111C87.0792 111 63.1585 111 25 111H111ZM111 111C87.4646 111 63.9293 111 25 111H111ZM25 111C25 81.1514 25 51.3028 25 26V111Z",stroke:pn(e),strokeWidth:"2"}),b("path",{d:"M100 100H160V160H100",fill:pn(e)}),b("path",{d:"M100 160C100 144.106 100 128.211 100 100M100 100C117.706 100 135.412 100 160 100H100ZM100 100C114.214 100 128.428 100 160 100H100ZM160 100C160 120.184 160 140.369 160 160V100ZM160 100C160 113.219 160 126.437 160 160V100ZM160 160C145.534 160 131.068 160 100 160H160ZM160 160C143.467 160 126.934 160 100 160H160ZM100 160C100 143.661 100 127.321 100 100V160Z",stroke:pn(e),strokeWidth:"2"}),H("g",{fill:SE(e),stroke:pn(e),strokeWidth:"6",children:[b("rect",{x:"2.5",y:"2.5",width:"30",height:"30"}),b("rect",{x:"78.5",y:"149.5",width:"30",height:"30"}),b("rect",{x:"147.5",y:"149.5",width:"30",height:"30"}),b("rect",{x:"147.5",y:"78.5",width:"30",height:"30"}),b("rect",{x:"105.5",y:"2.5",width:"30",height:"30"}),b("rect",{x:"2.5",y:"102.5",width:"30",height:"30"})]})]}),{width:182,height:182,mirror:!0})),tw=R(b("g",{strokeWidth:1.25,children:b("path",{d:"M5.879 2.625h8.242a3.27 3.27 0 0 1 3.254 3.254v8.242a3.27 3.27 0 0 1-3.254 3.254H5.88a3.27 3.27 0 0 1-3.254-3.254V5.88A3.27 3.27 0 0 1 5.88 2.626l-.001-.001ZM4.518 16.118l7.608-12.83m.198 13.934 5.051-9.897M2.778 9.675l9.348-6.387m-7.608 12.83 12.857-8.793"})}),Ee),ow=R(H(We,{children:[b("path",{d:"M5.879 2.625h8.242a3.254 3.254 0 0 1 3.254 3.254v8.242a3.254 3.254 0 0 1-3.254 3.254H5.88a3.254 3.254 0 0 1-3.254-3.254V5.88a3.254 3.254 0 0 1 3.254-3.254Z",stroke:"currentColor",strokeWidth:"1.25"}),b("mask",{id:"FillHachureIcon",style:{maskType:"alpha"},maskUnits:"userSpaceOnUse",x:2,y:2,width:16,height:16,children:b("path",{d:"M5.879 2.625h8.242a3.254 3.254 0 0 1 3.254 3.254v8.242a3.254 3.254 0 0 1-3.254 3.254H5.88a3.254 3.254 0 0 1-3.254-3.254V5.88a3.254 3.254 0 0 1 3.254-3.254Z",fill:"currentColor",stroke:"currentColor",strokeWidth:"1.25"})}),b("g",{mask:"url(#FillHachureIcon)",children:b("path",{d:"M2.258 15.156 15.156 2.258M7.324 20.222 20.222 7.325m-20.444 5.35L12.675-.222m-8.157 18.34L17.416 5.22",stroke:"currentColor",strokeWidth:"1.25",strokeLinecap:"round",strokeLinejoin:"round"})})]}),Ee),nw=R(H(We,{children:[H("g",{clipPath:"url(#a)",children:[b("path",{d:"M5.879 2.625h8.242a3.254 3.254 0 0 1 3.254 3.254v8.242a3.254 3.254 0 0 1-3.254 3.254H5.88a3.254 3.254 0 0 1-3.254-3.254V5.88a3.254 3.254 0 0 1 3.254-3.254Z",stroke:"currentColor",strokeWidth:"1.25"}),b("mask",{id:"FillCrossHatchIcon",style:{maskType:"alpha"},maskUnits:"userSpaceOnUse",x:-1,y:-1,width:22,height:22,children:b("path",{d:"M2.426 15.044 15.044 2.426M7.383 20 20 7.383M0 12.617 12.617 0m-7.98 17.941L17.256 5.324m-2.211 12.25L2.426 4.956M20 12.617 7.383 0m5.234 20L0 7.383m17.941 7.98L5.324 2.745",stroke:"currentColor",strokeWidth:"1.25",strokeLinecap:"round",strokeLinejoin:"round"})}),b("g",{mask:"url(#FillCrossHatchIcon)",children:b("path",{d:"M14.121 2H5.88A3.879 3.879 0 0 0 2 5.879v8.242A3.879 3.879 0 0 0 5.879 18h8.242A3.879 3.879 0 0 0 18 14.121V5.88A3.879 3.879 0 0 0 14.121 2Z",fill:"currentColor"})})]}),b("defs",{children:b("clipPath",{id:"a",children:b("path",{fill:"#fff",d:"M0 0h20v20H0z"})})})]}),Ee),rw=R(H(We,{children:[b("g",{clipPath:"url(#a)",children:b("path",{d:"M4.91 2.625h10.18a2.284 2.284 0 0 1 2.285 2.284v10.182a2.284 2.284 0 0 1-2.284 2.284H4.909a2.284 2.284 0 0 1-2.284-2.284V4.909a2.284 2.284 0 0 1 2.284-2.284Z",stroke:"currentColor",strokeWidth:"1.25"})}),b("defs",{children:b("clipPath",{id:"a",children:b("path",{fill:"#fff",d:"M0 0h20v20H0z"})})})]}),{...Ee,fill:"currentColor"}),Dh=R(b(We,{children:b("path",{d:"M4.167 10h11.666",stroke:"currentColor",strokeWidth:"1.25",strokeLinecap:"round",strokeLinejoin:"round"})}),Ee),aw=R(b("path",{d:"M5 10h10",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round"}),Ee),iw=R(b("path",{d:"M5 10h10",stroke:"currentColor",strokeWidth:"3.75",strokeLinecap:"round",strokeLinejoin:"round"}),Ee),Qee=_t.memo(({theme:e})=>R(b("path",{d:"M6 10H34",stroke:pn(e),strokeWidth:2,fill:"none",strokeLinecap:"round"}),{width:40,height:20})),sw=R(H("g",{strokeWidth:"2",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M5 12h2"}),b("path",{d:"M17 12h2"}),b("path",{d:"M11 12h2"})]}),K),lw=R(H("g",{strokeWidth:"2",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M4 12v.01"}),b("path",{d:"M8 12v.01"}),b("path",{d:"M12 12v.01"}),b("path",{d:"M16 12v.01"}),b("path",{d:"M20 12v.01"})]}),K),cw=R(b("path",{d:"M2.5 12.038c1.655-.885 5.9-3.292 8.568-4.354 2.668-1.063.101 2.821 1.32 3.104 1.218.283 5.112-1.814 5.112-1.814",strokeWidth:"1.25"}),Ee),dw=R(b("path",{d:"M2.5 12.563c1.655-.886 5.9-3.293 8.568-4.355 2.668-1.062.101 2.822 1.32 3.105 1.218.283 5.112-1.814 5.112-1.814m-13.469 2.23c2.963-1.586 6.13-5.62 7.468-4.998 1.338.623-1.153 4.11-.132 5.595 1.02 1.487 6.133-1.43 6.133-1.43",strokeWidth:"1.25"}),Ee),mw=R(b("path",{d:"M2.5 11.936c1.737-.879 8.627-5.346 10.42-5.268 1.795.078-.418 5.138.345 5.736.763.598 3.53-1.789 4.235-2.147M2.929 9.788c1.164-.519 5.47-3.28 6.987-3.114 1.519.165 1 3.827 2.121 4.109 1.122.281 3.839-2.016 4.606-2.42",strokeWidth:"1.25"}),Ee),pw=R(H("svg",{strokeWidth:"1.5",children:[b("path",{d:"M3.33334 9.99998V6.66665C3.33334 6.04326 3.33403 4.9332 3.33539 3.33646C4.95233 3.33436 6.06276 3.33331 6.66668 3.33331H10"}),b("path",{d:"M13.3333 3.33331V3.34331"}),b("path",{d:"M16.6667 3.33331V3.34331"}),b("path",{d:"M16.6667 6.66669V6.67669"}),b("path",{d:"M16.6667 10V10.01"}),b("path",{d:"M3.33334 13.3333V13.3433"}),b("path",{d:"M16.6667 13.3333V13.3433"}),b("path",{d:"M3.33334 16.6667V16.6767"}),b("path",{d:"M6.66666 16.6667V16.6767"}),b("path",{d:"M10 16.6667V16.6767"}),b("path",{d:"M13.3333 16.6667V16.6767"}),b("path",{d:"M16.6667 16.6667V16.6767"})]}),Ee),uw=R(H("g",{strokeWidth:"1.5",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M4 12v-4a4 4 0 0 1 4 -4h4"}),b("line",{x1:"16",y1:"4",x2:"16",y2:"4.01"}),b("line",{x1:"20",y1:"4",x2:"20",y2:"4.01"}),b("line",{x1:"20",y1:"8",x2:"20",y2:"8.01"}),b("line",{x1:"20",y1:"12",x2:"20",y2:"12.01"}),b("line",{x1:"4",y1:"16",x2:"4",y2:"16.01"}),b("line",{x1:"20",y1:"16",x2:"20",y2:"16.01"}),b("line",{x1:"4",y1:"20",x2:"4",y2:"20.01"}),b("line",{x1:"8",y1:"20",x2:"8",y2:"20.01"}),b("line",{x1:"12",y1:"20",x2:"12",y2:"20.01"}),b("line",{x1:"16",y1:"20",x2:"16",y2:"20.01"}),b("line",{x1:"20",y1:"20",x2:"20",y2:"20.01"})]}),K),gw=_t.memo(({flip:e=!1})=>R(H("g",{transform:e?"translate(24, 0) scale(-1, 1)":"",stroke:"currentColor",opacity:.3,strokeWidth:2,children:[b("path",{d:"M12 12l-9 0"}),b("path",{d:"M21 9l-6 6"}),b("path",{d:"M21 15l-6 -6"})]}),K)),hw=_t.memo(({flip:e=!1})=>R(H("g",{transform:e?"translate(40, 0) scale(-1, 1)":"",stroke:"currentColor",strokeWidth:2,fill:"none",children:[b("path",{d:"M34 10H6M34 10L27 5M34 10L27 15"}),b("path",{d:"M27.5 5L34.5 10L27.5 15"})]}),{width:40,height:20})),fw=_t.memo(({flip:e=!1})=>R(H("g",{stroke:"currentColor",fill:"currentColor",transform:e?"translate(40, 0) scale(-1, 1)":"",children:[b("path",{d:"M32 10L6 10",strokeWidth:2}),b("circle",{r:"4",transform:"matrix(-1 0 0 1 30 10)"})]}),{width:40,height:20})),bw=_t.memo(({flip:e=!1})=>R(H("g",{stroke:"currentColor",fill:"none",transform:e?"translate(40, 0) scale(-1, 1)":"",strokeWidth:2,children:[b("path",{d:"M26 10L6 10"}),b("circle",{r:"4",transform:"matrix(-1 0 0 1 30 10)"})]}),{width:40,height:20})),xw=_t.memo(({flip:e=!1})=>R(b("g",{transform:e?"translate(40, 0) scale(-1, 1)":"",children:b("path",{d:"M34 10H5.99996M34 10L34 5M34 10L34 15",stroke:"currentColor",strokeWidth:2,fill:"none"})}),{width:40,height:20})),yw=_t.memo(({flip:e=!1})=>R(H("g",{stroke:"currentColor",fill:"currentColor",transform:e?"translate(40, 0) scale(-1, 1)":"",children:[b("path",{d:"M32 10L6 10",strokeWidth:2}),b("path",{d:"M27.5 5.5L34.5 10L27.5 14.5L27.5 5.5"})]}),{width:40,height:20})),Ew=_t.memo(({flip:e=!1})=>R(H("g",{stroke:"currentColor",fill:"none",transform:e?"translate(40, 0) scale(-1, 1)":"",strokeWidth:2,strokeLinejoin:"round",children:[b("path",{d:"M6,9.5H27"}),b("path",{d:"M27,5L34,10L27,14Z",fill:"none"})]}),{width:40,height:20})),ww=_t.memo(({flip:e=!1})=>R(H("g",{stroke:"currentColor",fill:"currentColor",transform:e?"translate(40, 0) scale(-1, 1)":"",strokeLinejoin:"round",strokeWidth:2,children:[b("path",{d:"M6,9.5H20"}),b("path",{d:"M27,5L34,10L27,14L20,9.5Z"})]}),{width:40,height:20})),vw=_t.memo(({flip:e=!1})=>R(H("g",{stroke:"currentColor",fill:"none",transform:e?"translate(40, 0) scale(-1, 1)":"",strokeLinejoin:"round",strokeWidth:2,children:[b("path",{d:"M6,9.5H20"}),b("path",{d:"M27,5L34,10L27,14L20,9.5Z"})]}),{width:40,height:20})),Iw=_t.memo(({flip:e=!1})=>R(b("g",{stroke:"currentColor",fill:"none",transform:e?"":"translate(40, 0) scale(-1, 1)",strokeLinejoin:"round",strokeWidth:2,children:b("path",{d:"M34,10 H6 M15,10 L7,5 M15,10 L7,15"})}),{width:40,height:20})),Tw=_t.memo(({flip:e=!1})=>R(b("g",{stroke:"currentColor",fill:"none",transform:e?"":"translate(40, 0) scale(-1, 1)",strokeLinejoin:"round",strokeWidth:2,children:b("path",{d:"M34,10 H6 M15,10 L15,15 L15,5"})}),{width:40,height:20})),Cw=_t.memo(({flip:e=!1})=>R(b("g",{stroke:"currentColor",fill:"none",transform:e?"":"translate(40, 0) scale(-1, 1)",strokeLinejoin:"round",strokeWidth:2,children:b("path",{d:"M34,10 H6 M15,10 L15,16 L15,4 M15,10 L7,5 M15,10 L7,15"})}),{width:40,height:20})),kw=R(H(We,{children:[b("g",{clipPath:"url(#a)",children:b("path",{d:"M14.167 6.667a3.333 3.333 0 0 0-3.334-3.334H9.167a3.333 3.333 0 0 0 0 6.667h1.666a3.333 3.333 0 0 1 0 6.667H9.167a3.333 3.333 0 0 1-3.334-3.334",stroke:"currentColor",strokeWidth:"1.25",strokeLinecap:"round",strokeLinejoin:"round"})}),b("defs",{children:b("clipPath",{id:"a",children:b("path",{fill:"#fff",d:"M0 0h20v20H0z"})})})]}),Ee),Sw=R(H(We,{children:[b("g",{clipPath:"url(#a)",children:b("path",{d:"M5 16.667V3.333L10 15l5-11.667v13.334",stroke:"currentColor",strokeWidth:"1.25",strokeLinecap:"round",strokeLinejoin:"round"})}),b("defs",{children:b("clipPath",{id:"a",children:b("path",{fill:"#fff",d:"M0 0h20v20H0z"})})})]}),Ee),Mw=R(H(We,{children:[b("g",{clipPath:"url(#a)",children:b("path",{d:"M5.833 3.333v13.334h8.334",stroke:"currentColor",strokeWidth:"1.25",strokeLinecap:"round",strokeLinejoin:"round"})}),b("defs",{children:b("clipPath",{id:"a",children:b("path",{fill:"#fff",d:"M0 0h20v20H0z"})})})]}),Ee),Pw=R(b(We,{children:b("path",{d:"m1.667 3.333 6.666 13.334M8.333 3.333 1.667 16.667M11.667 3.333v13.334h6.666",stroke:"currentColor",strokeWidth:"1.25",strokeLinecap:"round",strokeLinejoin:"round"})}),Ee),Va=R(H("g",{strokeWidth:1.25,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M3 7v-2h13v2"}),b("path",{d:"M10 5v14"}),b("path",{d:"M12 19h-4"}),b("path",{d:"M15 13v-1h6v1"}),b("path",{d:"M18 12v7"}),b("path",{d:"M17 19h2"})]}),K),Aw=R(b(We,{children:H("g",{stroke:"currentColor",strokeWidth:"1.25",strokeLinecap:"round",strokeLinejoin:"round",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M7 12h10"}),b("path",{d:"M7 5v14"}),b("path",{d:"M17 5v14"}),b("path",{d:"M15 19h4"}),b("path",{d:"M15 5h4"}),b("path",{d:"M5 19h4"}),b("path",{d:"M5 5h4"})]})}),K),ac=R(b(We,{children:b("g",{stroke:"currentColor",strokeWidth:"1.25",strokeLinecap:"round",strokeLinejoin:"round",children:b("path",{d:"M5.833 16.667v-10a3.333 3.333 0 0 1 3.334-3.334h1.666a3.333 3.333 0 0 1 3.334 3.334v10M5.833 10.833h8.334"})})}),Ee),Rh=R(H("g",{strokeWidth:"1.5",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M7 8l-4 4l4 4"}),b("path",{d:"M17 8l4 4l-4 4"}),b("path",{d:"M14 4l-4 16"})]}),K),wm=Rh,Lw=R(H("g",{stroke:"currentColor",fill:"none",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("line",{x1:"4",y1:"8",x2:"20",y2:"8"}),b("line",{x1:"4",y1:"12",x2:"12",y2:"12"}),b("line",{x1:"4",y1:"16",x2:"16",y2:"16"})]}),K),_w=R(H("g",{stroke:"currentColor",fill:"none",strokeLinecap:"round",strokeLinejoin:"round",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("line",{x1:"4",y1:"8",x2:"20",y2:"8"}),b("line",{x1:"8",y1:"12",x2:"16",y2:"12"}),b("line",{x1:"6",y1:"16",x2:"18",y2:"16"})]}),K),Dw=R(H("g",{stroke:"currentColor",fill:"none",strokeLinecap:"round",strokeLinejoin:"round",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("line",{x1:"4",y1:"8",x2:"20",y2:"8"}),b("line",{x1:"10",y1:"12",x2:"20",y2:"12"}),b("line",{x1:"8",y1:"16",x2:"20",y2:"16"})]}),K),Rw=_t.memo(({theme:e})=>R(H("g",{strokeWidth:"1.5",stroke:"currentColor",fill:"none",strokeLinecap:"round",strokeLinejoin:"round",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("line",{x1:"4",y1:"4",x2:"20",y2:"4"}),b("rect",{x:"9",y:"8",width:"6",height:"12",rx:"2"})]}),K)),Nw=_t.memo(({theme:e})=>R(H("g",{strokeWidth:"2",stroke:"currentColor",fill:"none",strokeLinecap:"round",strokeLinejoin:"round",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("line",{x1:"4",y1:"20",x2:"20",y2:"20"}),b("rect",{x:"9",y:"4",width:"6",height:"12",rx:"2"})]}),K)),Bw=_t.memo(({theme:e})=>R(H("g",{strokeWidth:"1.5",stroke:"currentColor",fill:"none",strokeLinecap:"round",strokeLinejoin:"round",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("line",{x1:"4",y1:"12",x2:"9",y2:"12"}),b("line",{x1:"15",y1:"12",x2:"20",y2:"12"}),b("rect",{x:"9",y:"6",width:"6",height:"12",rx:"2"})]}),K)),vm=R(H("g",{children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M21 19h-18l9 -15"}),b("path",{d:"M20.615 15.171h.015"}),b("path",{d:"M19.515 11.771h.015"}),b("path",{d:"M17.715 8.671h.015"}),b("path",{d:"M15.415 5.971h.015"})]}),K),Fw=R(b("path",{d:"M537.6 226.6c4.1-10.7 6.4-22.4 6.4-34.6 0-53-43-96-96-96-19.7 0-38.1 6-53.3 16.2C367 64.2 315.3 32 256 32c-88.4 0-160 71.6-160 160 0 2.7.1 5.4.2 8.1C40.2 219.8 0 273.2 0 336c0 79.5 64.5 144 144 144h368c70.7 0 128-57.3 128-128 0-61.9-44-113.6-102.4-125.4zM393.4 288H328v112c0 8.8-7.2 16-16 16h-48c-8.8 0-16-7.2-16-16V288h-65.4c-14.3 0-21.4-17.2-11.3-27.3l105.4-105.4c6.2-6.2 16.4-6.2 22.6 0l105.4 105.4c10.1 10.1 2.9 27.3-11.3 27.3z",fill:"currentColor"}),{width:640,height:512}),ete=R(b("path",{d:"M480 416C497.7 416 512 430.3 512 448C512 465.7 497.7 480 480 480H150.6C133.7 480 117.4 473.3 105.4 461.3L25.37 381.3C.3786 356.3 .3786 315.7 25.37 290.7L258.7 57.37C283.7 32.38 324.3 32.38 349.3 57.37L486.6 194.7C511.6 219.7 511.6 260.3 486.6 285.3L355.9 416H480zM265.4 416L332.7 348.7L195.3 211.3L70.63 336L150.6 416L265.4 416z"})),as=R(H("g",{strokeWidth:1.25,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M8 13v-7.5a1.5 1.5 0 0 1 3 0v6.5"}),b("path",{d:"M11 5.5v-2a1.5 1.5 0 1 1 3 0v8.5"}),b("path",{d:"M14 5.5a1.5 1.5 0 0 1 3 0v6.5"}),b("path",{d:"M17 7.5a1.5 1.5 0 0 1 3 0v8.5a6 6 0 0 1 -6 6h-2h.208a6 6 0 0 1 -5.012 -2.7a69.74 69.74 0 0 1 -.196 -.3c-.312 -.479 -1.407 -2.388 -3.286 -5.728a1.5 1.5 0 0 1 .536 -2.022a1.867 1.867 0 0 1 2.28 .28l1.47 1.47"})]}),K),Nh=R(H(We,{children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M4 17v2a2 2 0 0 0 2 2h12a2 2 0 0 0 2 -2v-2"}),b("path",{d:"M7 11l5 5l5 -5"}),b("path",{d:"M12 4l0 12"})]}),K),is=R(H(We,{children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M8 8m0 2a2 2 0 0 1 2 -2h8a2 2 0 0 1 2 2v8a2 2 0 0 1 -2 2h-8a2 2 0 0 1 -2 -2z"}),b("path",{d:"M16 8v-2a2 2 0 0 0 -2 -2h-8a2 2 0 0 0 -2 2v8a2 2 0 0 0 2 2h2"})]}),K),Ow=R(H("g",{strokeWidth:1.25,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M7 17m-3 0a3 3 0 1 0 6 0a3 3 0 1 0 -6 0"}),b("path",{d:"M17 17m-3 0a3 3 0 1 0 6 0a3 3 0 1 0 -6 0"}),b("path",{d:"M9.15 14.85l8.85 -10.85"}),b("path",{d:"M6 4l8.85 10.85"})]}),K),zw=R(H(We,{children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M12 12m-9 0a9 9 0 1 0 18 0a9 9 0 1 0 -18 0"}),b("path",{d:"M12 17l0 .01"}),b("path",{d:"M12 13.5a1.5 1.5 0 0 1 1 -1.5a2.6 2.6 0 1 0 -3 -4"})]}),K),tte=R(H(We,{children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M7 4v16l13 -8z"})]}),K),ote=R(H(We,{children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M17 4h-10a3 3 0 0 0 -3 3v10a3 3 0 0 0 3 3h10a3 3 0 0 0 3 -3v-10a3 3 0 0 0 -3 -3z",strokeWidth:"0",fill:"currentColor"})]}),K),Hw=R(H(We,{children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M5 12l5 5l10 -10"})]}),K),Im=R(H(We,{children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M10.24 3.957l-8.422 14.06a1.989 1.989 0 0 0 1.7 2.983h16.845a1.989 1.989 0 0 0 1.7 -2.983l-8.423 -14.06a1.989 1.989 0 0 0 -3.4 0z"}),b("path",{d:"M12 9v4"}),b("path",{d:"M12 17h.01"})]}),K),Gw=R(H("g",{strokeWidth:1.25,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M11 7l6 6"}),b("path",{d:"M4 16l11.7 -11.7a1 1 0 0 1 1.4 0l2.6 2.6a1 1 0 0 1 0 1.4l-11.7 11.7h-4v-4z"})]}),K),ic=R(H("g",{strokeWidth:1.5,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M12 3l-4 7h8z"}),b("path",{d:"M17 17m-3 0a3 3 0 1 0 6 0a3 3 0 1 0 -6 0"}),b("path",{d:"M4 14m0 1a1 1 0 0 1 1 -1h4a1 1 0 0 1 1 1v4a1 1 0 0 1 -1 1h-4a1 1 0 0 1 -1 -1z"})]}),K),On=R(H("g",{strokeWidth:1.5,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M4 7l16 0"}),b("path",{d:"M4 17l16 0"}),b("path",{d:"M7 4l0 16"}),b("path",{d:"M17 4l0 16"})]}),K),Uw=R(H("g",{strokeWidth:1.5,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),b("circle",{cx:"8.5",cy:"8.5",r:"1.5",fill:"currentColor",stroke:"none"}),b("path",{d:"M3 16l5-5c.928-.893 2.072-.893 3 0l5 5"}),b("path",{d:"M14 14l1-1c.928-.893 2.072-.893 3 0l3 3"}),b("path",{d:"M17.5 4.5l0 3m-1.5-1.5l3 0",strokeWidth:"1.5",strokeLinecap:"round"})]}),K),ss=R(b("path",{fill:"currentColor",d:"M407.48,111.18C335.587,108.103 269.573,152.338 245.08,220C220.587,152.338 154.573,108.103 82.68,111.18C80.285,168.229 107.577,222.632 154.74,254.82C178.908,271.419 193.35,298.951 193.27,328.27L193.27,379.13L296.9,379.13L296.9,328.27C296.816,298.953 311.255,271.42 335.42,254.82C382.596,222.644 409.892,168.233 407.48,111.18Z"})),Ww=R(H("g",{strokeWidth:"1.5",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M20 11a8.1 8.1 0 0 0 -15.5 -2m-.5 -4v4h4"}),b("path",{d:"M4 13a8.1 8.1 0 0 0 15.5 2m.5 4v-4h-4"})]}),K),Yw=R(H("g",{children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M6 10l-2 1l8 4l8 -4l-2 -1"}),b("path",{d:"M4 15l8 4l8 -4"}),b("path",{d:"M12 4v7"}),b("path",{d:"M15 8l-3 3l-3 -3"})]}),K),Gr=R(H("g",{strokeWidth:"1.25",children:[b("path",{d:"M4.16602 10H15.8327"}),b("path",{d:"M12.5 13.3333L15.8333 10"}),b("path",{d:"M12.5 6.66666L15.8333 9.99999"})]}),Ee),zn=R(H("g",{fill:"none",stroke:"currentColor",strokeWidth:"1.25",strokeLinecap:"round",strokeLinejoin:"round",transform:"rotate(90 10 10)",children:[b("path",{clipRule:"evenodd",d:"m9.644 13.69 7.774-7.773a2.357 2.357 0 0 0-3.334-3.334l-7.773 7.774L8 12l1.643 1.69Z"}),b("path",{d:"m13.25 3.417 3.333 3.333M10 10l2-2M5 15l3-3M2.156 17.894l1-1M5.453 19.029l-.144-1.407M2.377 11.887l.866 1.118M8.354 17.273l-1.194-.758M.953 14.652l1.408.13"})]}),20),Ka=R(H("g",{stroke:"currentColor",fill:"none",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z"}),b("path",{d:"M6 21l15 -15l-3 -3l-15 15l3 3"}),b("path",{d:"M15 6l3 3"}),b("path",{d:"M9 3a2 2 0 0 0 2 2a2 2 0 0 0 -2 2a2 2 0 0 0 -2 -2a2 2 0 0 0 2 -2"}),b("path",{d:"M19 13a2 2 0 0 0 2 2a2 2 0 0 0 -2 2a2 2 0 0 0 -2 -2a2 2 0 0 0 2 -2"})]}),K),nte=R(H("g",{strokeWidth:1.25,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z"}),b("path",{d:"M6 21l15 -15l-3 -3l-15 15l3 3"}),b("path",{d:"M15 6l3 3"}),b("path",{d:"M9 3a2 2 0 0 0 2 2a2 2 0 0 0 -2 2a2 2 0 0 0 -2 -2a2 2 0 0 0 2 -2"}),b("path",{d:"M19 13a2 2 0 0 0 2 2a2 2 0 0 0 -2 2a2 2 0 0 0 -2 -2a2 2 0 0 0 2 -2"})]}),K),rte=R(H("g",{stroke:"currentColor",fill:"none",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M11.217 19.384a3.501 3.501 0 0 0 6.783 -1.217v-5.167l-6 -3.35"}),b("path",{d:"M5.214 15.014a3.501 3.501 0 0 0 4.446 5.266l4.34 -2.534v-6.946"}),b("path",{d:"M6 7.63c-1.391 -.236 -2.787 .395 -3.534 1.689a3.474 3.474 0 0 0 1.271 4.745l4.263 2.514l6 -3.348"}),b("path",{d:"M12.783 4.616a3.501 3.501 0 0 0 -6.783 1.217v5.067l6 3.45"}),b("path",{d:"M18.786 8.986a3.501 3.501 0 0 0 -4.446 -5.266l-4.34 2.534v6.946"}),b("path",{d:"M18 16.302c1.391 .236 2.787 -.395 3.534 -1.689a3.474 3.474 0 0 0 -1.271 -4.745l-4.308 -2.514l-5.955 3.42"})]}),K),$w=R(H("g",{stroke:"currentColor",fill:"none",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M4 8v-2a2 2 0 0 1 2 -2h2"}),b("path",{d:"M4 16v2a2 2 0 0 0 2 2h2"}),b("path",{d:"M16 4h2a2 2 0 0 1 2 2v2"}),b("path",{d:"M16 20h2a2 2 0 0 0 2 -2v-2"})]}),K),ls=R(H("g",{stroke:"currentColor",fill:"none",strokeWidth:1.5,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M10 12a2 2 0 1 0 4 0a2 2 0 0 0 -4 0"}),b("path",{d:"M21 12c-2.4 4 -5.4 6 -9 6c-3.6 0 -6.6 -2 -9 -6c2.4 -4 5.4 -6 9 -6c3.6 0 6.6 2 9 6"})]}),K),Vw=R(H("g",{stroke:"currentColor",fill:"none",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M10.585 10.587a2 2 0 0 0 2.829 2.828"}),b("path",{d:"M16.681 16.673a8.717 8.717 0 0 1 -4.681 1.327c-3.6 0 -6.6 -2 -9 -6c1.272 -2.12 2.712 -3.678 4.32 -4.674m2.86 -1.146a9.055 9.055 0 0 1 1.82 -.18c3.6 0 6.6 2 9 6c-.666 1.11 -1.379 2.067 -2.138 2.87"}),b("path",{d:"M3 3l18 18"})]}),K),Kw=R(H("g",{stroke:"currentColor",fill:"none",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M15.5 13a3.5 3.5 0 0 0 -3.5 3.5v1a3.5 3.5 0 0 0 7 0v-1.8"}),b("path",{d:"M8.5 13a3.5 3.5 0 0 1 3.5 3.5v1a3.5 3.5 0 0 1 -7 0v-1.8"}),b("path",{d:"M17.5 16a3.5 3.5 0 0 0 0 -7h-.5"}),b("path",{d:"M19 9.3v-2.8a3.5 3.5 0 0 0 -7 0"}),b("path",{d:"M6.5 16a3.5 3.5 0 0 1 0 -7h.5"}),b("path",{d:"M5 9.3v-2.8a3.5 3.5 0 0 1 7 0v10"})]}),K),Xw=R(H("g",{strokeWidth:1.25,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M15.5 13a3.5 3.5 0 0 0 -3.5 3.5v1a3.5 3.5 0 0 0 7 0v-1.8"}),b("path",{d:"M8.5 13a3.5 3.5 0 0 1 3.5 3.5v1a3.5 3.5 0 0 1 -7 0v-1.8"}),b("path",{d:"M17.5 16a3.5 3.5 0 0 0 0 -7h-.5"}),b("path",{d:"M19 9.3v-2.8a3.5 3.5 0 0 0 -7 0"}),b("path",{d:"M6.5 16a3.5 3.5 0 0 1 0 -7h.5"}),b("path",{d:"M5 9.3v-2.8a3.5 3.5 0 0 1 7 0v10"})]}),K),Mo=R(H("g",{strokeWidth:1.5,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M10 10m-7 0a7 7 0 1 0 14 0a7 7 0 1 0 -14 0"}),b("path",{d:"M21 21l-6 -6"})]}),K),Zw=R(H("g",{strokeWidth:1.5,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M20.984 12.53a9 9 0 1 0 -7.552 8.355"}),b("path",{d:"M12 7v5l3 3"}),b("path",{d:"M19 16l-2 3h4l-2 3"})]}),K),jw=R(H("g",{strokeWidth:1.5,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M12 8l0 4l2 2"}),b("path",{d:"M3.05 11a9 9 0 1 1 .5 4m-.5 5v-5h5"})]}),K),qw=R(H("g",{strokeWidth:1.5,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M9 2m0 3a3 3 0 0 1 3 -3h0a3 3 0 0 1 3 3v5a3 3 0 0 1 -3 3h0a3 3 0 0 1 -3 -3z"}),b("path",{d:"M5 10a7 7 0 0 0 14 0"}),b("path",{d:"M8 21l8 0"}),b("path",{d:"M12 17l0 4"})]}),K),Jw=R(H("g",{strokeWidth:1.5,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M3 3l18 18"}),b("path",{d:"M9 5a3 3 0 0 1 6 0v5a3 3 0 0 1 -.13 .874m-2 2a3 3 0 0 1 -3.87 -2.872v-1"}),b("path",{d:"M5 10a7 7 0 0 0 10.846 5.85m2 -2a6.967 6.967 0 0 0 1.152 -3.85"}),b("path",{d:"M8 21l8 0"}),b("path",{d:"M12 17l0 4"})]}),K),sc=R(H("g",{strokeWidth:1.25,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M13 3l0 7l6 0l-8 11l0 -7l-6 0l8 -11"})]}),K),Qw=R(H("g",{children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M8 8m0 1a1 1 0 0 1 1 -1h6a1 1 0 0 1 1 1v6a1 1 0 0 1 -1 1h-6a1 1 0 0 1 -1 -1z"}),b("path",{d:"M12 20v.01"}),b("path",{d:"M16 20v.01"}),b("path",{d:"M8 20v.01"}),b("path",{d:"M4 20v.01"}),b("path",{d:"M4 16v.01"}),b("path",{d:"M4 12v.01"}),b("path",{d:"M4 8v.01"}),b("path",{d:"M4 4v.01"}),b("path",{d:"M8 4v.01"}),b("path",{d:"M12 4v.01"}),b("path",{d:"M16 4v.01"}),b("path",{d:"M20 4v.01"}),b("path",{d:"M20 8v.01"}),b("path",{d:"M20 12v.01"}),b("path",{d:"M20 16v.01"}),b("path",{d:"M20 20v.01"})]}),K),ev=R(H("g",{strokeWidth:1.25,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M5 3v18"}),b("path",{d:"M19 21v-18"}),b("path",{d:"M5 7h14"}),b("path",{d:"M5 15h14"}),b("path",{d:"M8 13v4"}),b("path",{d:"M11 13v4"}),b("path",{d:"M16 13v4"}),b("path",{d:"M14 5v4"}),b("path",{d:"M11 5v4"}),b("path",{d:"M8 5v4"}),b("path",{d:"M3 21h18"})]}),K),tv=R(H("g",{strokeWidth:1.25,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M3 12l18 0"}),b("path",{d:"M7 16l10 0l-10 5l0 -5"}),b("path",{d:"M7 8l10 0l-10 -5l0 5"})]}),K),ov=R(H("g",{strokeWidth:1.25,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M12 3l0 18"}),b("path",{d:"M16 7l0 10l5 0l-5 -10"}),b("path",{d:"M8 7l0 10l-5 0l5 -10"})]}),K),Bh=R(H("g",{strokeWidth:1.25,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M5 3m0 2a2 2 0 0 1 2 -2h10a2 2 0 0 1 2 2v2a2 2 0 0 1 -2 2h-10a2 2 0 0 1 -2 -2z"}),b("path",{d:"M19 6h1a2 2 0 0 1 2 2a5 5 0 0 1 -5 5l-5 0v2"}),b("path",{d:"M10 15m0 1a1 1 0 0 1 1 -1h2a1 1 0 0 1 1 1v4a1 1 0 0 1 -1 1h-2a1 1 0 0 1 -1 -1z"})]}),K),cs=R(H("g",{strokeWidth:1.25,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M15 15m-5 0a5 5 0 1 0 10 0a5 5 0 1 0 -10 0"}),b("path",{d:"M22 22l-3 -3"}),b("path",{d:"M6 18h-1a2 2 0 0 1 -2 -2v-1"}),b("path",{d:"M3 11v-1"}),b("path",{d:"M3 6v-1a2 2 0 0 1 2 -2h1"}),b("path",{d:"M10 3h1"}),b("path",{d:"M15 3h1a2 2 0 0 1 2 2v1"})]}),K),nv=R(H("g",{strokeWidth:1.25,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M14 3v4a1 1 0 0 0 1 1h4"}),b("path",{d:"M5 12v-7a2 2 0 0 1 2 -2h7l5 5v4"}),b("path",{d:"M4 20.25c0 .414 .336 .75 .75 .75h1.25a1 1 0 0 0 1 -1v-1a1 1 0 0 0 -1 -1h-1a1 1 0 0 1 -1 -1v-1a1 1 0 0 1 1 -1h1.25a.75 .75 0 0 1 .75 .75"}),b("path",{d:"M10 15l2 6l2 -6"}),b("path",{d:"M20 15h-1a2 2 0 0 0 -2 2v2a2 2 0 0 0 2 2h1v-3"})]}),K),rv=R(H("g",{strokeWidth:1.25,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M14 3v4a1 1 0 0 0 1 1h4"}),b("path",{d:"M5 12v-7a2 2 0 0 1 2 -2h7l5 5v4"}),b("path",{d:"M20 15h-1a2 2 0 0 0 -2 2v2a2 2 0 0 0 2 2h1v-3"}),b("path",{d:"M5 18h1.5a1.5 1.5 0 0 0 0 -3h-1.5v6"}),b("path",{d:"M11 21v-6l3 6v-6"})]}),K),av=R(H("g",{strokeWidth:1.25,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M4 13v-8a2 2 0 0 1 2 -2h1a2 2 0 0 1 2 2v8a2 2 0 0 0 6 0v-8a2 2 0 0 1 2 -2h1a2 2 0 0 1 2 2v8a8 8 0 0 1 -16 0"}),b("path",{d:"M4 8l5 0"}),b("path",{d:"M15 8l4 0"})]}),K),iv=R(H("g",{strokeWidth:1.25,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M3 14c.83 .642 2.077 1.017 3.5 1c1.423 .017 2.67 -.358 3.5 -1c.83 -.642 2.077 -1.017 3.5 -1c1.423 -.017 2.67 .358 3.5 1"}),b("path",{d:"M8 3a2.4 2.4 0 0 0 -1 2a2.4 2.4 0 0 0 1 2"}),b("path",{d:"M12 3a2.4 2.4 0 0 0 -1 2a2.4 2.4 0 0 0 1 2"}),b("path",{d:"M3 10h14v5a6 6 0 0 1 -6 6h-2a6 6 0 0 1 -6 -6v-5z"}),b("path",{d:"M16.746 16.726a3 3 0 1 0 .252 -5.555"})]}),K),sv=R(H("g",{stroke:"currentColor",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M3 5a1 1 0 0 1 1-1h16a1 1 0 0 1 1 1v10a1 1 0 0 1-1 1h-16a1 1 0 0 1-1-1v-10zM7 20h10M9 16v4M15 16v4"})]}),{...K,strokeWidth:1.5}),ate=R(H("g",{strokeWidth:1.5,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M15 8v-2a2 2 0 0 0 -2 -2h-7a2 2 0 0 0 -2 2v12a2 2 0 0 0 2 2h7a2 2 0 0 0 2 -2v-2"}),b("path",{d:"M21 12h-13l3 -3"}),b("path",{d:"M11 15l-3 -3"})]}),K),lv=R(H("g",{children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M2 8a4 4 0 0 1 4 -4h12a4 4 0 0 1 4 4v8a4 4 0 0 1 -4 4h-12a4 4 0 0 1 -4 -4v-8z"}),b("path",{d:"M10 9l5 3l-5 3z"})]}),K),cv=R(H("g",{strokeWidth:1.5,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M3 6h18"}),b("path",{d:"M3 12h18"}),b("path",{d:"M3 18h18"}),b("path",{d:"M6 3v18"}),b("path",{d:"M12 3v18"}),b("path",{d:"M18 3v18"})]}),K),dv=R(H("g",{strokeWidth:1.5,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M17 3m0 1a1 1 0 0 1 1 -1h2a1 1 0 0 1 1 1v2a1 1 0 0 1 -1 1h-2a1 1 0 0 1 -1 -1z"}),b("path",{d:"M3 17m0 1a1 1 0 0 1 1 -1h2a1 1 0 0 1 1 1v2a1 1 0 0 1 -1 1h-2a1 1 0 0 1 -1 -1z"}),b("path",{d:"M17 5c-6.627 0 -12 5.373 -12 12"})]}),K),ds=R(H("g",{children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M6 18l12 -12"}),b("path",{d:"M18 10v-4h-4"})]}),K),ms=R(H("g",{children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M4,19L10,19C11.097,19 12,18.097 12,17L12,9C12,7.903 12.903,7 14,7L21,7"}),b("path",{d:"M18 4l3 3l-3 3"})]}),K),ps=R(H("g",{children:[b("path",{d:"M16,12L20,9L16,6"}),b("path",{d:"M6 20c0 -6.075 4.925 -11 11 -11h3"})]}),K),Tm=R(H("g",{children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M6 9l6 6l6 -6"})]}),K),mv=R(H("g",{children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M6 15l6 -6l6 6"})]}),K),pv=R(H("g",{children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M6 15l6 -6l6 6"})]}),K),Fh=R(H("g",{strokeWidth:"1.25",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M8 5v10a1 1 0 0 0 1 1h10"}),b("path",{d:"M5 8h10a1 1 0 0 1 1 1v10"})]}),K),Cm=R(H("g",{children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M5 5m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"}),b("path",{d:"M19 5m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"}),b("path",{d:"M5 19m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"}),b("path",{d:"M19 19m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"}),b("path",{d:"M5 7l0 10"}),b("path",{d:"M7 5l10 0"}),b("path",{d:"M7 19l10 0"}),b("path",{d:"M19 7l0 10"})]}),K),ite=R(H("g",{strokeWidth:1.5,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M4 11v8a1 1 0 0 0 1 1h8m-9 -14v-1a1 1 0 0 1 1 -1h1m5 0h2m5 0h1a1 1 0 0 1 1 1v1m0 5v2m0 5v1a1 1 0 0 1 -1 1h-1"}),b("path",{d:"M4 12h7a1 1 0 0 1 1 1v7"})]}),K),uv=R(H("g",{strokeWidth:1.5,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M14 6m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"}),b("path",{d:"M4 6l8 0"}),b("path",{d:"M16 6l4 0"}),b("path",{d:"M8 12m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"}),b("path",{d:"M4 12l2 0"}),b("path",{d:"M10 12l10 0"}),b("path",{d:"M17 18m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"}),b("path",{d:"M4 18l11 0"}),b("path",{d:"M19 18l1 0"})]}),K),gv=R(H("g",{strokeWidth:1,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M6 10l4 -4 L6 14l8 -8 L6 18l12 -12 L10 18l8 -8 L14 18l4 -4"})]}),K),hv=R(H("g",{strokeWidth:1.25,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M4 20h4l10.5 -10.5a2.828 2.828 0 1 0 -4 -4l-10.5 10.5v4"}),b("path",{d:"M13.5 6.5l4 4"})]}),K),ste=R(H("g",{strokeWidth:1,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M11 7l-5 5l5 5"}),b("path",{d:"M17 7l-5 5l5 5"})]}),K),fv=R(H("g",{strokeWidth:"1.75",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M4 4m0 2a2 2 0 0 1 2 -2h12a2 2 0 0 1 2 2v12a2 2 0 0 1 -2 2h-12a2 2 0 0 1 -2 -2z"}),b("path",{d:"M15 4l0 16"})]}),K),lte=R(H("g",{strokeWidth:"1.25",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M3 20l1.3 -3.9c-2.324 -3.437 -1.426 -7.872 2.1 -10.374c3.526 -2.501 8.59 -2.296 11.845 .48c3.255 2.777 3.695 7.266 1.029 10.501c-2.666 3.235 -7.615 4.215 -11.574 2.293l-4.7 1"})]}),K),cte=R(H("g",{strokeWidth:"1.25",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M3 4l18 0"}),b("path",{d:"M4 4v10a2 2 0 0 0 2 2h12a2 2 0 0 0 2 -2v-10"}),b("path",{d:"M12 16l0 4"}),b("path",{d:"M9 20l6 0"}),b("path",{d:"M8 12l3 -3l2 2l3 -3"})]}),K),bv=b("div",{style:{width:"1rem",height:"1rem"}}),xv=R(H("g",{strokeWidth:"1.5",children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("polyline",{points:"9 6 15 12 9 18"})]}),K),yv=R(H("g",{strokeWidth:1.25,children:[b("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),b("path",{d:"M14 6m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"}),b("path",{d:"M4 6l8 0"}),b("path",{d:"M16 6l4 0"}),b("path",{d:"M8 12m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"}),b("path",{d:"M4 12l2 0"}),b("path",{d:"M10 12l10 0"}),b("path",{d:"M17 18m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"}),b("path",{d:"M4 18l11 0"}),b("path",{d:"M19 18l1 0"})]}),K);import Ev from"clsx";import zh,{useEffect as mL,useRef as wv,useState as pL}from"react";import{isPromiseLike as uL}from"@orangecatai/common";import cL from"react";import{jsx as Oh}from"react/jsx-runtime";var dL=({size:e="1em",circleWidth:t=8,synchronized:o=!1,className:n=""})=>{let a=-(cL.useRef(Date.now()).current%1600);return Oh("div",{className:`Spinner ${n}`,children:Oh("svg",{viewBox:"0 0 100 100",style:{width:e,height:e,"--spinner-delay":o?`${a}ms`:0},children:Oh("circle",{cx:"50",cy:"50",r:50-t/2,strokeWidth:t,fill:"none",strokeMiterlimit:"10"})})})},Wt=dL;import{jsx as lc,jsxs as cc}from"react/jsx-runtime";var ie=zh.forwardRef(({size:e="medium",visible:t=!0,className:o="",...n},r)=>{let{id:a}=Qe(),i=zh.useRef(null);zh.useImperativeHandle(r,()=>i.current);let s=`ToolIcon_size_${e}`,[l,c]=pL(!1),m=wv(!0),p=async u=>{let h="onClick"in n&&n.onClick?.(u);if(uL(h))try{c(!0),await h}catch(g){if(g instanceof Ui)console.warn(g);else throw g}finally{m.current&&c(!1)}};mL(()=>(m.current=!0,()=>{m.current=!1}),[]);let d=wv(null);if(n.type==="button"||n.type==="icon"||n.type==="submit"){let u=n.type==="icon"?"button":n.type;return cc("button",{className:Ev("ToolIcon_type_button",s,o,t&&!n.hidden?"ToolIcon_type_button--show":"ToolIcon_type_button--hide",{ToolIcon:!n.hidden,"ToolIcon--selected":n.selected,"ToolIcon--plain":n.type==="icon"}),style:n.style,"data-testid":n["data-testid"],hidden:n.hidden,title:n.title,"aria-label":n["aria-label"],type:u,onClick:p,ref:i,disabled:l||n.isLoading||!!n.disabled,children:[(n.icon||n.label)&&cc("div",{className:"ToolIcon__icon","aria-hidden":"true","aria-disabled":!!n.disabled,children:[n.icon||n.label,n.keyBindingLabel&&lc("span",{className:"ToolIcon__keybinding",children:n.keyBindingLabel}),n.isLoading&&lc(Wt,{})]}),n.showAriaLabel&&cc("div",{className:"ToolIcon__label",children:[n["aria-label"]," ",l&&lc(Wt,{})]}),n.children]})}return cc("label",{className:Ev("ToolIcon",o),title:n.title,onPointerDown:u=>{d.current=u.pointerType||null,n.onPointerDown?.({pointerType:u.pointerType||null})},onPointerUp:()=>{requestAnimationFrame(()=>{d.current=null})},children:[lc("input",{className:`ToolIcon_type_radio ${s}`,type:"radio",name:n.name,"aria-label":n["aria-label"],"aria-keyshortcuts":n["aria-keyshortcuts"],"data-testid":n["data-testid"],id:`${a}-${n.id}`,onChange:()=>{n.onChange?.({pointerType:d.current})},checked:n.checked,ref:i}),cc("div",{className:"ToolIcon__icon",children:[n.icon,n.keyBindingLabel&&lc("span",{className:"ToolIcon__keybinding",children:n.keyBindingLabel})]})]})});ie.displayName="ToolButton";var km=[],W=e=>(km=km.concat(e),e);import{jsx as vL}from"react/jsx-runtime";var wL=(e,t,o)=>{let n=new Set(de(e.filter(m=>xL(m)),t).map(m=>m.id)),r={},a=o.scene.getNonDeletedElementsMap(),i=new Set;for(let m of n){let p=yL(e,m);for(let d of p)if(!i.has(d.id)){if(Sm(d)){let u=Iv(d,a);u&&(r[u.id]=!0)}else r[d.id]=!0;i.add(d.id)}}let s=!0,l=e.map(m=>{if(t.selectedElementIds[m.id]){let p=Sm(m)?Iv(m,a):null;return m.frameId&&n.has(m.frameId)?(s=!1,r[m.id]=!0,m):p?.frameId&&n.has(p?.frameId)?m:(m.boundElements&&m.boundElements.forEach(d=>{let u=o.scene.getNonDeletedElementsMap().get(d.id);u&&bL(u)&&o.scene.mutateElement(u,{startBinding:m.id===u.startBinding?.elementId?null:u.startBinding,endBinding:m.id===u.endBinding?.elementId?null:u.endBinding})}),Pm(m,{isDeleted:!0}))}return m.frameId&&n.has(m.frameId)?(s=!1,Sm(m)||(r[m.id]=!0),Pm(m,{frameId:null})):Sm(m)&&t.selectedElementIds[m.containerId]?Pm(m,{isDeleted:!0}):m}),c=t.editingGroupId;if(s&&t.editingGroupId){let m=Uh(l,t.editingGroupId).filter(p=>!p.isDeleted);if(m.length>1)m[0]&&(r[m[0].id]=!0);else{c=null,m[0]&&(r[m[0].id]=!0);let p=m[0];if(p){let d=p.groupIds.findIndex(h=>h===t.editingGroupId),u=p.groupIds[d+1];if(u){let h=Uh(l,u).filter(g=>!g.isDeleted);h.length>1&&(c=u,h.forEach(g=>{r[g.id]=!0}))}}}}return{elements:l,appState:{...t,...EL({selectedElementIds:r,editingGroupId:c},l,t,null)}}},Tv=(e,t)=>{if(e.editingGroupId){let o=Uh(Gh(t),e.editingGroupId);if(o.length)return{...e,selectedElementIds:{[o[0].id]:!0}}}return e},dc=W({name:"deleteSelectedElements",label:"labels.delete",icon:Ut,trackEvent:{category:"element",action:"delete"},perform:(e,t,o,n)=>{if(t.selectedLinearElement?.isEditing){let{elementId:i,selectedPointsIndices:s}=t.selectedLinearElement,l=n.scene.getNonDeletedElementsMap(),c=vv.getElement(i,l);if(!c||s==null)return!1;if(s.length>=c.points.length){let m=e.map(d=>d.id===c.id?Pm(d,{isDeleted:!0}):d),p=Tv(t,m);return{elements:m,appState:{...p,selectedLinearElement:null},captureUpdate:Mm.IMMEDIATELY}}return vv.deletePoints(c,n,s),{elements:e,appState:{...t,selectedLinearElement:{...t.selectedLinearElement,selectedPointsIndices:s?.[0]>0?[s[0]-1]:[0]}},captureUpdate:Mm.IMMEDIATELY}}let{elements:r,appState:a}=wL(e,t,n);return fL(r,r.filter(i=>i.isDeleted)),a=Tv(a,r),{elements:r,appState:{...a,activeTool:hL(t,{type:n.state.preferredSelectionTool.type}),multiElement:null,newElement:null,activeEmbeddable:null,selectedLinearElement:null},captureUpdate:Ge(Gh(e),t)?Mm.IMMEDIATELY:Mm.EVENTUALLY}},keyTest:(e,t,o)=>(e.key===Hh.BACKSPACE||e.key===Hh.DELETE)&&!e[Hh.CTRL_OR_CMD],PanelComponent:({elements:e,appState:t,updateData:o,app:n})=>{let r=Dt()==="mobile";return vL(ie,{type:"button",icon:Ut,title:f("labels.delete"),"aria-label":f("labels.delete"),onClick:()=>o(null),disabled:!Ge(Gh(e),t),style:{...r&&t.openPopup!=="compactOtherProperties"?gL:{}}})}});import{KEYS as us,CODES as gs,isDarwin as Am}from"@orangecatai/common";import{moveOneLeft as IL,moveOneRight as TL,moveAllLeft as CL,moveAllRight as kL}from"@orangecatai/element";import{CaptureUpdateAction as Lm}from"@orangecatai/element";import{isDarwin as Cv}from"@orangecatai/common";var G=e=>e.replace(/\b(Opt(?:ion)?|Alt)\b/i,Cv?f("keys.option"):f("keys.alt")).replace(/\bShift\b/i,f("keys.shift")).replace(/\b(Enter|Return)\b/i,f("keys.enter")).replace(/\b(Ctrl|Cmd|Command|CtrlOrCmd)\b/gi,Cv?f("keys.cmd"):f("keys.ctrl")).replace(/\b(Esc(?:ape)?)\b/i,f("keys.escape")).replace(/\b(Space(?:bar)?)\b/i,f("keys.spacebar")).replace(/\b(Del(?:ete)?)\b/i,f("keys.delete"));import{jsx as _m}from"react/jsx-runtime";var Wh=W({name:"sendBackward",label:"labels.sendBackward",keywords:["move down","zindex","layer"],icon:vh,trackEvent:{category:"element"},perform:(e,t,o,n)=>({elements:IL(e,t,n.scene),appState:t,captureUpdate:Lm.IMMEDIATELY}),keyPriority:40,keyTest:e=>e[us.CTRL_OR_CMD]&&!e.shiftKey&&e.code===gs.BRACKET_LEFT,PanelComponent:({updateData:e,appState:t})=>_m("button",{type:"button",className:"zIndexButton",onClick:()=>e(null),title:`${f("labels.sendBackward")} \u2014 ${G("CtrlOrCmd+[")}`,children:vh})}),Yh=W({name:"bringForward",label:"labels.bringForward",keywords:["move up","zindex","layer"],icon:wh,trackEvent:{category:"element"},perform:(e,t,o,n)=>({elements:TL(e,t,n.scene),appState:t,captureUpdate:Lm.IMMEDIATELY}),keyPriority:40,keyTest:e=>e[us.CTRL_OR_CMD]&&!e.shiftKey&&e.code===gs.BRACKET_RIGHT,PanelComponent:({updateData:e,appState:t})=>_m("button",{type:"button",className:"zIndexButton",onClick:()=>e(null),title:`${f("labels.bringForward")} \u2014 ${G("CtrlOrCmd+]")}`,children:wh})}),$h=W({name:"sendToBack",label:"labels.sendToBack",keywords:["move down","zindex","layer"],icon:Th,trackEvent:{category:"element"},perform:(e,t)=>({elements:CL(e,t),appState:t,captureUpdate:Lm.IMMEDIATELY}),keyTest:e=>Am?e[us.CTRL_OR_CMD]&&e.altKey&&e.code===gs.BRACKET_LEFT:e[us.CTRL_OR_CMD]&&e.shiftKey&&e.code===gs.BRACKET_LEFT,PanelComponent:({updateData:e,appState:t})=>_m("button",{type:"button",className:"zIndexButton",onClick:()=>e(null),title:`${f("labels.sendToBack")} \u2014 ${Am?G("CtrlOrCmd+Alt+["):G("CtrlOrCmd+Shift+[")}`,children:Th})}),Vh=W({name:"bringToFront",label:"labels.bringToFront",keywords:["move up","zindex","layer"],icon:Ih,trackEvent:{category:"element"},perform:(e,t)=>({elements:kL(e,t),appState:t,captureUpdate:Lm.IMMEDIATELY}),keyTest:e=>Am?e[us.CTRL_OR_CMD]&&e.altKey&&e.code===gs.BRACKET_RIGHT:e[us.CTRL_OR_CMD]&&e.shiftKey&&e.code===gs.BRACKET_RIGHT,PanelComponent:({updateData:e,appState:t})=>_m("button",{type:"button",className:"zIndexButton",onClick:o=>e(null),title:`${f("labels.bringToFront")} \u2014 ${Am?G("CtrlOrCmd+Alt+]"):G("CtrlOrCmd+Shift+]")}`,children:Ih})});import{getNonDeletedElements as SL}from"@orangecatai/element";import{LinearElementEditor as ML}from"@orangecatai/element";import{isLinearElement as PL,isTextElement as AL}from"@orangecatai/element";import{arrayToMap as LL,KEYS as kv}from"@orangecatai/common";import{selectGroupsForSelectedElements as _L}from"@orangecatai/element";import{CaptureUpdateAction as DL}from"@orangecatai/element";var Kh=W({name:"selectAll",label:"labels.selectAll",icon:Qw,trackEvent:{category:"canvas"},viewMode:!1,perform:(e,t,o,n)=>{if(t.selectedLinearElement?.isEditing)return!1;let r=e.filter(a=>!a.isDeleted&&!(AL(a)&&a.containerId)&&!a.locked).reduce((a,i)=>(a[i.id]=!0,a),{});return{appState:{...t,..._L({editingGroupId:null,selectedElementIds:r},SL(e),t,n),selectedLinearElement:Object.keys(r).length===1&&PL(e[0])?new ML(e[0],LL(e)):null},captureUpdate:DL.IMMEDIATELY}},keyTest:e=>e[kv.CTRL_OR_CMD]&&e.key===kv.A});import{DEFAULT_GRID_SIZE as Sv,KEYS as Mv,MOBILE_ACTION_BUTTON_BG as RL,arrayToMap as Pv}from"@orangecatai/common";import{getNonDeletedElements as Av}from"@orangecatai/element";import{LinearElementEditor as NL}from"@orangecatai/element";import{getSelectedElements as BL,getSelectionStateForElements as FL}from"@orangecatai/element";import{syncMovedIndices as OL}from"@orangecatai/element";import{duplicateElements as zL}from"@orangecatai/element";import{CaptureUpdateAction as Lv}from"@orangecatai/element";import{jsx as HL}from"react/jsx-runtime";var Xh=W({name:"duplicateSelection",label:"labels.duplicateSelection",icon:tc,trackEvent:{category:"element"},perform:(e,t,o,n)=>{if(t.selectedElementsAreBeingDragged)return!1;if(t.selectedLinearElement?.isEditing)try{let i=NL.duplicateSelectedPoints(t,n.scene);return{elements:e,appState:i,captureUpdate:Lv.IMMEDIATELY}}catch{return!1}let{duplicatedElements:r,elementsWithDuplicates:a}=zL({type:"in-place",elements:e,idsOfElementsToDuplicate:Pv(BL(e,t,{includeBoundTextElement:!0,includeElementsInFrames:!0})),appState:t,randomizeSeed:!0,overrides:({origElement:i,origIdToDuplicateId:s})=>{let l=i.frameId&&s.get(i.frameId);return{x:i.x+Sv/2,y:i.y+Sv/2,frameId:l??i.frameId}}});if(n.props.onDuplicate&&a){let i=n.props.onDuplicate(a,e);i&&(a=i)}return{elements:OL(a,Pv(r)),appState:{...t,...FL(r,Av(a),t)},captureUpdate:Lv.IMMEDIATELY}},keyTest:e=>e[Mv.CTRL_OR_CMD]&&e.key===Mv.D,PanelComponent:({elements:e,appState:t,updateData:o,app:n})=>{let r=Dt()==="mobile";return HL(ie,{type:"button",icon:tc,title:`${f("labels.duplicateSelection")} \u2014 ${G("CtrlOrCmd+D")}`,"aria-label":f("labels.duplicateSelection"),onClick:()=>o(null),disabled:!Ge(Av(e),t),style:{...r&&t.openPopup!=="compactOtherProperties"?RL:{}}})}});import{pointFrom as GD}from"@orangecatai/math";import{useEffect as xf,useMemo as UD,useRef as yf,useState as WD}from"react";import{DEFAULT_ELEMENT_BACKGROUND_COLOR_PALETTE as YD,DEFAULT_ELEMENT_BACKGROUND_PICKS as $D,DEFAULT_ELEMENT_STROKE_COLOR_PALETTE as VD,DEFAULT_ELEMENT_STROKE_PICKS as KD,ARROW_TYPE as Vo,DEFAULT_FONT_FAMILY as XD,DEFAULT_FONT_SIZE as ZD,FONT_FAMILY as jD,ROUNDNESS as Zm,STROKE_WIDTH as Ef,VERTICAL_ALIGN as Km,KEYS as vs,randomInteger as qD,arrayToMap as vf,getFontFamilyString as JD,getLineHeight as QD,isTransparent as e8,reduceToCommonValue as t8,invariant as If,FONT_SIZES as Xm}from"@orangecatai/common";import{canBecomePolygon as o8,getNonDeletedElements as w2}from"@orangecatai/element";import{bindBindingElement as b2,calculateFixedPointForElbowArrowBinding as x2,updateBoundElements as n8}from"@orangecatai/element";import{LinearElementEditor as ja}from"@orangecatai/element";import{newElementWith as kt}from"@orangecatai/element";import{getBoundTextElement as qr,redrawTextBoundingBox as vc}from"@orangecatai/element";import{isArrowElement as jm,isBoundToContainer as r8,isElbowArrow as v2,isLinearElement as wf,isLineElement as y2,isTextElement as fo,isUsingAdaptiveRadius as a8}from"@orangecatai/element";import{hasStrokeColor as i8}from"@orangecatai/element";import{updateElbowArrowPoints as s8,CaptureUpdateAction as St,toggleLinePolygonState as l8}from"@orangecatai/element";import{deriveStylesPanelMode as c8}from"@orangecatai/common";import{isDevEnv as GL}from"@orangecatai/common";var UL=new Set(["command_palette","export"]),be=(e,t,o,n)=>{try{if(typeof window>"u"||T.VITE_WORKER_ID||T.VITE_APP_ENABLE_TRACKING!=="true"||!UL.has(e)||GL())return;T.PROD||console.info("trackEvent",{category:e,action:t,label:o,value:n}),window.sa_event&&window.sa_event(t,{category:e,label:o,value:n})}catch(r){console.error("error during analytics",r)}};import VL from"clsx";import WL from"clsx";import{forwardRef as YL}from"react";import{jsx as $L}from"react/jsx-runtime";var hs=YL((e,t)=>{let{title:o,className:n,testId:r,active:a,standalone:i,icon:s,onClick:l}=e;return $L("button",{type:"button",ref:t,title:o,"data-testid":r,className:WL(n,{standalone:i,active:a}),onClick:l,style:e.style,children:s},o)});import{Fragment as XL,jsx as Zh,jsxs as KL}from"react/jsx-runtime";var Uo=e=>Zh(XL,{children:e.options.map(t=>e.type==="button"?Zh(hs,{icon:t.icon,title:t.text,testId:t.testId,active:t.active??e.value===t.value,onClick:o=>e.onClick(t.value,o)},t.text):KL("label",{className:VL({active:e.value===t.value}),title:t.text,children:[Zh("input",{type:"radio",name:e.group,onChange:()=>e.onChange(t.value),checked:e.value===t.value,"data-testid":t.testId}),t.icon]},t.text))});import{Popover as qv}from"radix-ui";import Jv from"clsx";import{useRef as Qv,useEffect as j_}from"react";import{COLOR_OUTLINE_CONTRAST_THRESHOLD as Zv,COLOR_PALETTE as e2,isColorDark as jv,isWritableElement as q_}from"@orangecatai/common";import{jsx as ZL}from"react/jsx-runtime";var Dm=()=>ZL("div",{style:{width:1,height:"1rem",backgroundColor:"var(--default-border-color)",margin:"0 auto"}});import{useEffect as e_,useRef as t_}from"react";import{createPortal as o_}from"react-dom";import{EVENT as Wr,KEYS as n_,rgbToHex as r_}from"@orangecatai/common";import _v from"react";var jh=_v.createContext(null),Ie=()=>_v.useContext(jh);import{useState as jL,useLayoutEffect as Dv}from"react";import{THEME as qL}from"@orangecatai/common";var Rm=e=>{let[t,o]=jL(null),n=Te(),{theme:r}=Ie(),{container:a}=Qe();return Dv(()=>{t&&(t.className="",t.classList.add("excalidraw",...e?.className?.split(/\s+/)||[]),t.classList.toggle("excalidraw--mobile",n.formFactor==="phone"),t.classList.toggle("theme--dark",r===qL.DARK))},[t,r,n.formFactor,e?.className]),Dv(()=>{let i=e?.parentSelector?a?.querySelector(e.parentSelector):document.body;if(!i)return;let s=document.createElement("div");return i.appendChild(s),o(s),()=>{i.removeChild(s)}},[a,e?.parentSelector]),t};import{useEffect as JL}from"react";import{EVENT as Nm}from"@orangecatai/common";function fs(e,t,o){JL(()=>{function n(r){let a=r;if(!e.current)return;let i=o?.(a,e.current);if(i===!0)return;if(i===!1)return t(a);e.current.contains(a.target)||!document.documentElement.contains(a.target)||a.target.closest("[data-radix-portal]")||a.target===document.documentElement&&document.body.style.pointerEvents==="none"||a.target.closest("[data-prevent-outside-click]")||t(a)}return document.addEventListener(Nm.POINTER_DOWN,n),document.addEventListener(Nm.TOUCH_START,n),()=>{document.removeEventListener(Nm.POINTER_DOWN,n),document.removeEventListener(Nm.TOUCH_START,n)}},[e,t,o])}import{useRef as QL}from"react";var Ur=e=>{let t=QL(e);return Object.assign(t.current,e),t.current};import{jsx as a_}from"react/jsx-runtime";var Yr=Pe(null),Rv=({onCancel:e,onChange:t,onSelect:o,colorPickerType:n})=>{let r=Rm({className:"excalidraw-eye-dropper-backdrop",parentSelector:".excalidraw-eye-dropper-container"}),a=Ie(),i=$r(),s=tt(),l=de(i,a),c=Ur({app:s,onCancel:e,onChange:t,onSelect:o,selectedElements:l}),{container:m}=Qe();e_(()=>{let d=p.current;if(!d||!s.canvas||!r)return;let u=!1,h=s.canvas.getContext("2d"),g=({clientX:C,clientY:P})=>{let S=h.getImageData((C-a.offsetLeft)*window.devicePixelRatio,(P-a.offsetTop)*window.devicePixelRatio,1,1).data;return r_(S[0],S[1],S[2])},x=({clientX:C,clientY:P,altKey:S})=>{d.style.top=`${P+20}px`,d.style.left=`${C+20}px`;let D=g({clientX:C,clientY:P});u&&c.onChange(n,D,c.selectedElements,{altKey:S}),d.style.background=D},E=()=>{c.onCancel()},y=(C,P)=>{c.onSelect(C,P)},w=C=>{u=!0,C.stopImmediatePropagation()},v=C=>{u=!1,m?.focus(),C.stopImmediatePropagation(),C.preventDefault(),y(g(C),C)},I=C=>{C.key===n_.ESCAPE&&(C.preventDefault(),C.stopImmediatePropagation(),E())};return r.tabIndex=-1,r.focus(),x({clientX:c.app.lastViewportPosition.x,clientY:c.app.lastViewportPosition.y,altKey:!1}),r.addEventListener(Wr.KEYDOWN,I),r.addEventListener(Wr.POINTER_DOWN,w),r.addEventListener(Wr.POINTER_UP,v),window.addEventListener("pointermove",x,{passive:!0}),window.addEventListener(Wr.BLUR,E),()=>{u=!1,r.removeEventListener(Wr.KEYDOWN,I),r.removeEventListener(Wr.POINTER_DOWN,w),r.removeEventListener(Wr.POINTER_UP,v),window.removeEventListener("pointermove",x),window.removeEventListener(Wr.BLUR,E)}},[c,s.canvas,r,n,m,a.offsetLeft,a.offsetTop]);let p=t_(null);return fs(p,()=>{e()},d=>!!d.target.closest(".excalidraw-eye-dropper-trigger, .excalidraw-eye-dropper-backdrop")),r?o_(a_("div",{ref:p,className:"excalidraw-eye-dropper-preview"}),r):null};import{Popover as qh}from"radix-ui";import c_ from"clsx";import d_ from"react";import{isInteractive as m_}from"@orangecatai/common";import i_ from"react";import s_ from"clsx";import{jsx as l_}from"react/jsx-runtime";var gt=i_.forwardRef(({children:e,padding:t,className:o,style:n},r)=>l_("div",{className:s_("Island",o),style:{"--padding":t,...n},ref:r,children:e}));import{jsx as Jh,jsxs as p_}from"react/jsx-runtime";var gr=d_.forwardRef(({className:e,container:t,children:o,style:n,onClose:r,onKeyDown:a,onFocusOutside:i,onPointerLeave:s,onPointerDownOutside:l,preventAutoFocusOnTouch:c=!1},m)=>{let p=Te(),d=p.formFactor==="phone"&&!p.isLandscape;return Jh(qh.Portal,{container:t,children:p_(qh.Content,{ref:m,className:c_("focus-visible-none",e),"data-prevent-outside-click":!0,side:d?"bottom":"right",align:d?"center":"start",alignOffset:-16,sideOffset:20,collisionBoundary:t??void 0,style:{zIndex:"var(--zIndex-ui-styles-popup)",marginLeft:p.formFactor==="phone"?"0.5rem":void 0},onPointerLeave:s,onKeyDown:a,onFocusOutside:i,onPointerDownOutside:l,onOpenAutoFocus:u=>{c&&p.isTouchScreen&&u.preventDefault()},onCloseAutoFocus:u=>{u.stopPropagation(),u.preventDefault(),t&&!m_(document.activeElement)&&t.focus(),r()},children:[Jh(gt,{padding:3,style:n,children:o}),Jh(qh.Arrow,{width:20,height:10,style:{fill:"var(--popup-bg-color)",filter:"drop-shadow(rgba(0, 0, 0, 0.05) 0px 3px 2px)"}})]})})});import{useState as u_,useCallback as Qh}from"react";var Bm=()=>document.querySelector(".excalidraw-wysiwyg"),Fm=()=>{let e=Bm();return e?{start:e.selectionStart,end:e.selectionEnd}:null},mc=e=>{setTimeout(()=>{let t=Bm();t&&(t.focus(),e&&(t.selectionStart=e.start,t.selectionEnd=e.end))},0)},pc=(e,t,o,n)=>{t&&n&&n();let r=t&&o?Fm():null;e(),t&&o&&mc(r)},Nv=()=>{let[e,t]=u_(null),o=Qh(()=>{let a=Fm();t(a)},[]),n=Qh(()=>{setTimeout(()=>{let a=Bm();a&&(a.focus(),e&&(a.selectionStart=e.start,a.selectionEnd=e.end,t(null)))},0)},[e]),r=Qh(()=>{t(null)},[]);return{saveCaretPosition:o,restoreCaretPosition:n,clearSavedPosition:r,hasSavedPosition:!!e}},Bv=(e=100)=>{let t=Bm();if(t){let o=t.onblur;t.onblur=null,setTimeout(()=>{t.onblur=o},e)}};import h_ from"clsx";import{useCallback as f_,useEffect as tf,useRef as Ov,useState as b_}from"react";import{KEYS as of,normalizeInputColor as x_}from"@orangecatai/common";import{MAX_CUSTOM_COLORS_USED_IN_CANVAS as g_}from"@orangecatai/common";var Vr=({palette:e,color:t})=>{if(!t)return null;for(let[o,n]of Object.entries(e))if(Array.isArray(n)){let r=n.indexOf(t);if(r>-1)return{colorName:o,shade:r}}else if(n===t)return{colorName:o,shade:null};return null},uc=[["q","w","e","r","t"],["a","s","d","f","g"],["z","x","c","v","b"]].flat(),ef=({color:e,palette:t})=>!Object.values(t).flat().includes(e),Fv=(e,t,o)=>{let n={elementBackground:"backgroundColor",elementStroke:"strokeColor"},r=e.filter(i=>{if(i.isDeleted)return!1;let s=i[n[t]];return ef({color:s,palette:o})}),a=new Map;return r.forEach(i=>{let s=i[n[t]];a.has(s)?a.set(s,a.get(s)+1):a.set(s,1)}),[...a.entries()].sort((i,s)=>s[1]-i[1]).map(i=>i[0]).slice(0,g_)},Wo=Pe(null);import{Fragment as y_,jsx as Om,jsxs as zv}from"react/jsx-runtime";var Hv=({color:e,onChange:t,label:o,colorPickerType:n,placeholder:r})=>{let a=Te(),[i,s]=b_(e),[l,c]=le(Wo);tf(()=>{s(e)},[e]);let m=f_(g=>{let x=g.toLowerCase(),E=x_(x);E&&t(E),s(x)},[t]),p=Ov(null),d=Ov(null);tf(()=>{p.current&&p.current.focus()},[l]);let[u,h]=le(Yr);return tf(()=>()=>{h(null)},[h]),zv("div",{className:"color-picker__input-label",children:[Om("div",{className:"color-picker__input-hash",children:"#"}),Om("input",{ref:l==="hex"?p:void 0,style:{border:0,padding:0},spellCheck:!1,className:"color-picker-input","aria-label":o,onChange:g=>{m(g.target.value)},value:(i||"").replace(/^#/,""),onBlur:()=>{s(e)},tabIndex:-1,onFocus:()=>c("hex"),onKeyDown:g=>{g.key!==of.TAB&&(g.key===of.ESCAPE&&d.current?.focus(),g.stopPropagation())},placeholder:r}),a.formFactor!=="phone"&&zv(y_,{children:[Om("div",{style:{width:"1px",height:"1.25rem",backgroundColor:"var(--default-border-color)"}}),Om("div",{ref:d,className:h_("excalidraw-eye-dropper-trigger",{selected:u}),onClick:()=>h(g=>g?null:{keepOpenOnAlt:!1,onSelect:x=>t(x),colorPickerType:n}),title:`${f("labels.eyeDropper")} \u2014 ${of.I.toLocaleUpperCase()} or ${G("Alt")} `,children:Gw})]})]})};import sf,{useEffect as lf,useImperativeHandle as z_,useState as H_}from"react";import{EVENT as Vv}from"@orangecatai/common";import{DEFAULT_ELEMENT_BACKGROUND_COLOR_INDEX as G_,DEFAULT_ELEMENT_STROKE_COLOR_INDEX as U_,KEYS as W_}from"@orangecatai/common";import I_ from"clsx";import{useEffect as T_,useRef as C_}from"react";import{isColorDark as E_}from"@orangecatai/common";import{jsxs as v_}from"react/jsx-runtime";var w_=({color:e,keyLabel:t,isShade:o=!1})=>v_("div",{className:"color-picker__button__hotkey-label",style:{color:E_(e)?"#fff":"#000"},children:[o&&"\u21E7",t]}),bs=w_;import{jsx as nf,jsxs as k_}from"react/jsx-runtime";var Gv=({colors:e,color:t,onChange:o,label:n})=>{let[r,a]=le(Wo),i=C_(null);return T_(()=>{i.current&&i.current.focus()},[t,r]),nf("div",{className:"color-picker-content--default",children:e.map((s,l)=>k_("button",{ref:t===s?i:void 0,tabIndex:-1,type:"button",className:I_("color-picker__button color-picker__button--large has-outline",{active:t===s,"is-transparent":s==="transparent"||!s}),onClick:()=>{o(s),a("custom")},title:s,"aria-label":n,style:{"--swatch-color":s},children:[nf("div",{className:"color-picker__button-outline"}),nf(bs,{color:s,keyLabel:l+1})]},l))})};import S_ from"clsx";import{useEffect as M_,useRef as P_}from"react";import{jsx as rf,jsxs as L_}from"react/jsx-runtime";var A_=({palette:e,color:t,onChange:o,activeShade:n,showHotKey:r=!0})=>{let a=Vr({color:t,palette:e}),[i,s]=le(Wo),l=P_(null);return M_(()=>{l.current&&i==="baseColors"&&l.current.focus()},[a?.colorName,i]),rf("div",{className:"color-picker-content--default",children:Object.entries(e).map(([c,m],p)=>{let d=(Array.isArray(m)?m[n]:m)||"transparent",u=uc[p],h=f(`colors.${c.replace(/\d+/,"")}`,null,"");return L_("button",{ref:a?.colorName===c?l:void 0,tabIndex:-1,type:"button",className:S_("color-picker__button color-picker__button--large has-outline",{active:a?.colorName===c,"is-transparent":d==="transparent"||!d}),onClick:()=>{o(d),s("baseColors")},title:`${h}${d.startsWith("#")?` ${d}`:""} \u2014 ${u}`,"aria-label":`${h} \u2014 ${u}`,style:d?{"--swatch-color":d}:void 0,"data-testid":`color-${c}`,children:[rf("div",{className:"color-picker__button-outline"}),r&&rf(bs,{color:d,keyLabel:u})]},c)})})},Uv=A_;import{jsx as D_}from"react/jsx-runtime";var __=({children:e})=>D_("div",{className:"color-picker__heading",children:e}),xs=__;import R_ from"clsx";import{useEffect as N_,useRef as B_}from"react";import{jsx as gc,jsxs as Wv}from"react/jsx-runtime";var Yv=({color:e,onChange:t,palette:o,showHotKey:n})=>{let r=Vr({color:e||"transparent",palette:o}),[a,i]=le(Wo),s=B_(null);if(N_(()=>{s.current&&a==="shades"&&s.current.focus()},[r,a]),r){let{colorName:l,shade:c}=r,m=o[l];if(Array.isArray(m))return gc("div",{className:"color-picker-content--default shades",children:m.map((p,d)=>Wv("button",{ref:d===c&&a==="shades"?s:void 0,tabIndex:-1,type:"button",className:R_("color-picker__button color-picker__button--large has-outline",{active:d===c}),"aria-label":"Shade",title:`${l} - ${d+1}`,style:p?{"--swatch-color":p}:void 0,onClick:()=>{t(p),i("shades")},children:[gc("div",{className:"color-picker__button-outline"}),n&&gc(bs,{color:p,keyLabel:d+1,isShade:!0})]},d))})}return Wv("div",{className:"color-picker-content--default",style:{position:"relative"},tabIndex:-1,children:[gc("button",{type:"button",tabIndex:-1,className:"color-picker__button color-picker__button--large color-picker__button--no-focus-visible"}),gc("div",{tabIndex:-1,style:{position:"absolute",top:0,left:0,right:0,bottom:0,display:"flex",alignItems:"center",justifyContent:"center",textAlign:"center",fontSize:"0.75rem"},children:f("colorPicker.noShades")})]})};import{COLORS_PER_ROW as ys,COLOR_PALETTE as F_,KEYS as hc}from"@orangecatai/common";var af=(e,t,o)=>{let n=Math.ceil(o/ys);switch(t=t??-1,e){case"ArrowLeft":{let r=t-1;return r<0?o-1:r}case"ArrowRight":return(t+1)%o;case"ArrowDown":{let r=t+ys;return r>=o?t%ys:r}case"ArrowUp":{let r=t-ys,a=r<0?ys*n+r:r;return a>=o?void 0:a}}},O_=({e,colorObj:t,onChange:o,palette:n,customColors:r,setActiveColorPickerSection:a,activeShade:i})=>{if(t?.shade!=null&&["Digit1","Digit2","Digit3","Digit4","Digit5"].includes(e.code)&&e.shiftKey){let s=Number(e.code.slice(-1))-1;return o(n[t.colorName][s]),a("shades"),!0}if(["1","2","3","4","5"].includes(e.key)&&r[Number(e.key)-1])return o(r[Number(e.key)-1]),a("custom"),!0;if(uc.includes(e.key)){let s=uc.indexOf(e.key),l=Object.keys(n)[s],c=n[l],m=Array.isArray(c)?c[i]:c;return o(m),a("baseColors"),!0}return!1},$v=({event:e,activeColorPickerSection:t,palette:o,color:n,onChange:r,customColors:a,setActiveColorPickerSection:i,updateData:s,activeShade:l,onEyeDropperToggle:c,onEscape:m})=>{if(e[hc.CTRL_OR_CMD])return!1;if(e.key===hc.ESCAPE)return m(e),!0;if(e.key===hc.ALT)return c(!0),!0;if(e.key===hc.I)return c(),!0;let p=Vr({color:n,palette:o});if(e.key===hc.TAB){let d={custom:!!a.length,baseColors:!0,shades:p?.shade!=null,hex:!0},u=Object.entries(d).reduce((y,[w,v])=>(v&&y.push(w),y),[]),h=u.indexOf(t),g=e.shiftKey?-1:1,x=h+g>u.length-1?0:h+g<0?u.length-1:h+g,E=u[x];return E&&i(E),E==="custom"?r(a[0]):E==="baseColors"&&(Object.entries(o).find(([w,v])=>Array.isArray(v)?v.includes(n):v===n?w:null)||r(F_.black)),e.preventDefault(),e.stopPropagation(),!0}if(O_({e,colorObj:p,onChange:r,palette:o,customColors:a,setActiveColorPickerSection:i,activeShade:l}))return!0;if(t==="shades"&&p){let{shade:d}=p,u=af(e.key,d,ys);if(u!==void 0)return r(o[p.colorName][u]),!0}if(t==="baseColors"&&p){let{colorName:d}=p,u=Object.keys(o),h=u.indexOf(d),g=af(e.key,h,u.length);if(g!==void 0){let x=u[g],E=o[x];return r(Array.isArray(E)?E[l]:E),!0}}if(t==="custom"){let d=n!=null?a.indexOf(n):0,u=af(e.key,d,a.length);if(u!==void 0){let h=a[u];return r(h),!0}}return!1};import{jsx as Kr,jsxs as zm}from"react/jsx-runtime";var Kv=sf.forwardRef(({color:e,onChange:t,type:o,elements:n,palette:r,updateData:a,children:i,showTitle:s,onEyeDropperToggle:l,onEscape:c,showHotKey:m=!0},p)=>{let d=s?o==="elementStroke"?f("labels.stroke"):o==="elementBackground"?f("labels.background"):null:null,[u]=sf.useState(()=>o==="canvasBackground"?[]:Fv(n,o,r)),[h,g]=le(Wo),x=Vr({color:e,palette:r});lf(()=>{if(!h){let v=!!e&&ef({color:e,palette:r}),I=v&&!u.includes(e);g(I?null:v?"custom":x?.shade!=null?"shades":"baseColors")}},[h,e,r,g,x,u]);let[E,y]=H_(x?.shade??(o==="elementBackground"?G_:U_));lf(()=>{x?.shade!=null&&y(x.shade);let v=I=>{I.key===W_.ALT&&l(!1)};return document.addEventListener(Vv.KEYUP,v,{capture:!0}),()=>{document.removeEventListener(Vv.KEYUP,v,{capture:!0})}},[x,l]);let w=sf.useRef(null);return z_(p,()=>w.current),lf(()=>{w?.current?.focus()},[]),Kr("div",{role:"dialog","aria-modal":"true","aria-label":f("labels.colorPicker"),children:zm("div",{ref:w,onKeyDown:v=>{$v({event:v,activeColorPickerSection:h,palette:r,color:e,onChange:t,onEyeDropperToggle:l,customColors:u,setActiveColorPickerSection:g,updateData:a,activeShade:E,onEscape:c})&&(v.preventDefault(),v.stopPropagation())},className:"color-picker-content properties-content",tabIndex:-1,children:[d&&Kr("div",{className:"color-picker__title",children:d}),!!u.length&&zm("div",{children:[Kr(xs,{children:f("colorPicker.mostUsedCustomColors")}),Kr(Gv,{colors:u,color:e,label:f("colorPicker.mostUsedCustomColors"),onChange:t})]}),zm("div",{children:[Kr(xs,{children:f("colorPicker.colors")}),Kr(Uv,{color:e,palette:r,onChange:t,activeShade:E,showHotKey:m})]}),zm("div",{children:[Kr(xs,{children:f("colorPicker.shades")}),Kr(Yv,{color:e,onChange:t,palette:r,showHotKey:m})]}),i]})})});import Y_ from"clsx";import{COLOR_OUTLINE_CONTRAST_THRESHOLD as $_,DEFAULT_CANVAS_BACKGROUND_PICKS as V_,DEFAULT_ELEMENT_BACKGROUND_PICKS as K_,DEFAULT_ELEMENT_STROKE_PICKS as X_,isColorDark as Z_}from"@orangecatai/common";import{jsx as cf}from"react/jsx-runtime";var Xv=({onChange:e,type:t,activeColor:o,topPicks:n})=>{let r;return t==="elementStroke"&&(r=X_),t==="elementBackground"&&(r=K_),t==="canvasBackground"&&(r=V_),n&&(r=n),r?cf("div",{className:"color-picker__top-picks",children:r.map(a=>cf("button",{className:Y_("color-picker__button",{active:a===o,"is-transparent":a==="transparent"||!a,"has-outline":!Z_(a,$_)}),style:{"--swatch-color":a},type:"button",title:a,onClick:()=>e(a),"data-testid":`color-top-pick-${a}`,children:cf("div",{className:"color-picker__button-outline"})},a))}):(console.error("Invalid type for TopPicks"),null)};import{jsx as Yo,jsxs as Hm}from"react/jsx-runtime";var J_=({type:e,color:t,onChange:o,label:n,elements:r,palette:a=e2,updateData:i,getOpenPopup:s,appState:l})=>{let{container:c}=Qe(),m=Dt(),p=m!=="full",d=m==="mobile",[,u]=le(Wo),[h,g]=le(Yr),x=Hm("div",{children:[Yo(xs,{children:f("colorPicker.hexCode")}),Yo(Hv,{color:t||"",label:n,onChange:w=>{o(w)},colorPickerType:e,placeholder:f("colorPicker.color")})]}),E=Qv(null),y=()=>{E.current?.focus()};return Yo(gr,{container:c,style:{maxWidth:"13rem"},preventAutoFocusOnTouch:!!l.editingTextElement,onFocusOutside:w=>{q_(w.target)||y(),w.preventDefault()},onPointerDownOutside:w=>{h&&w.preventDefault()},onClose:()=>{s()===e&&i({openPopup:null}),u(null),l.editingTextElement&&setTimeout(()=>{let w=document.querySelector(".excalidraw-wysiwyg");w&&w.focus()},0)},children:a?Yo(Kv,{ref:E,palette:a,color:t,onChange:w=>{let v=l.editingTextElement?Fm():null;o(w),l.editingTextElement&&v&&mc(v)},onEyeDropperToggle:w=>{g(v=>w?(v=v||{keepOpenOnAlt:!0,onSelect:o,colorPickerType:e},v.keepOpenOnAlt=!0,v):w===!1||v?null:{keepOpenOnAlt:!1,onSelect:o,colorPickerType:e})},onEscape:w=>{h?g(null):i({openPopup:null})},type:e,elements:r,updateData:i,showTitle:p,showHotKey:!d,children:x}):x})},Q_=({label:e,color:t,type:o,mode:n="background",onToggle:r,editingTextElement:a})=>{let i=Dt(),s=i!=="full",l=i==="mobile",c=m=>{m.preventDefault(),m.stopPropagation(),a&&Bv(),r()};return Hm(qv.Trigger,{type:"button",className:Jv("color-picker__button active-color properties-trigger",{"is-transparent":!t||t==="transparent","has-outline":!t||!jv(t,Zv),"compact-sizing":s,"mobile-border":l}),"aria-label":e,style:t?{"--swatch-color":t}:void 0,title:o==="elementStroke"?f("labels.showStroke"):f("labels.showBackground"),"data-openpopup":o,onClick:c,children:[Yo("div",{className:"color-picker__button-outline",children:!t&&$E}),s&&t&&n==="stroke"&&Yo("div",{className:"color-picker__button-background",children:Yo("span",{style:{color:t&&jv(t,Zv)?"#fff":"#111"},children:gv})})]})},fc=({type:e,color:t,onChange:o,label:n,elements:r,palette:a=e2,topPicks:i,updateData:s,appState:l})=>{let c=Qv(l.openPopup);j_(()=>{c.current=l.openPopup},[l.openPopup]);let p=Dt()!=="full";return Yo("div",{children:Hm("div",{role:"dialog","aria-modal":"true",className:Jv("color-picker-container",{"color-picker-container--no-top-picks":p}),children:[!p&&Yo(Xv,{activeColor:t,onChange:o,type:e,topPicks:i}),!p&&Yo(Dm,{}),Hm(qv.Root,{open:l.openPopup===e,onOpenChange:d=>{d&&s({openPopup:e})},children:[Yo(Q_,{color:t,label:n,type:e,mode:e==="elementStroke"?"stroke":"background",editingTextElement:!!l.editingTextElement,onToggle:()=>{l.openPopup===e?s({openPopup:null}):l.openPopup?s({openPopup:e}):s({openPopup:e})}}),l.openPopup===e&&Yo(J_,{type:e,color:t,onChange:o,label:n,elements:r,palette:a,updateData:s,getOpenPopup:()=>c.current,appState:l})]})]})})};import{Popover as SD}from"radix-ui";import MD from"clsx";import PD,{useCallback as AD,useMemo as LD}from"react";import{FONT_FAMILY as uf}from"@orangecatai/common";import bD,{useMemo as jr,useState as xD,useRef as r2,useEffect as a2,useCallback as i2,useSyncExternalStore as yD}from"react";import{arrayToList as ED,debounce as wD,FONT_FAMILY as Xa,getFontFamilyString as vD}from"@orangecatai/common";import eD from"clsx";import tD from"react";import{jsx as oD,jsxs as nD}from"react/jsx-runtime";var Gm=tD.forwardRef(({className:e,placeholder:t,onChange:o},n)=>nD("div",{className:eD("QuickSearch__wrapper",e),children:[Mo,oD("input",{ref:n,className:"QuickSearch__input",type:"text",placeholder:t,onChange:r=>o(r.target.value.trim().toLowerCase())})]}));import rD from"clsx";import{Children as aD}from"react";import{jsx as t2}from"react/jsx-runtime";var Um=({className:e,placeholder:t,children:o})=>{let n=!aD.count(o);return t2("div",{className:rD("ScrollableList__wrapper",e),role:"menu",children:n?t2("div",{className:"empty",children:t}):o})};import{jsx as iD,jsxs as sD}from"react/jsx-runtime";var o2=({children:e,className:t="",style:o,title:n})=>sD("div",{className:`dropdown-menu-group ${t}`,style:o,children:[n&&iD("p",{className:"dropdown-menu-group-title",children:n}),e]}),bc=o2;o2.displayName="DropdownMenuGroup";import{THEME as hD}from"@orangecatai/common";import{DropdownMenu as fD}from"radix-ui";import lD,{useContext as cD}from"react";import{composeEventHandlers as dD}from"@orangecatai/common";var df=lD.createContext({}),Xr=(e="",t=!1,o=!1)=>`dropdown-menu-item dropdown-menu-item-base ${e} ${t?"dropdown-menu-item--selected":""} ${o?"dropdown-menu-item--hovered":""}`.trim(),Wm=e=>{let t=cD(df);return dD(e,o=>{t.onSelect?.(o)})};import{jsx as mD}from"react/jsx-runtime";var xc=({children:e,...t})=>mD("span",{...t,style:{textOverflow:"ellipsis",overflow:"hidden",whiteSpace:"nowrap",...t.style},children:e});import{Fragment as uD,jsx as yc,jsxs as gD}from"react/jsx-runtime";var pD=({textStyle:e,icon:t,shortcut:o,children:n,badge:r})=>{let a=Te();return gD(uD,{children:[t&&yc("div",{className:"dropdown-menu-item__icon",children:t}),yc("div",{style:e,className:"dropdown-menu-item__text",children:yc(xc,{children:n})}),r&&yc("div",{className:"dropdown-menu-item__badge",children:r}),o&&a.formFactor!=="phone"&&yc("div",{className:"dropdown-menu-item__shortcut",children:o})]})},Zr=pD;import{jsx as Ym}from"react/jsx-runtime";var mf=({icon:e,badge:t,value:o,children:n,shortcut:r,className:a,selected:i,onSelect:s,...l})=>{let c=Wm(s);return Ym(fD.Item,{className:"radix-menu-item",onSelect:c,asChild:!0,children:Ym("button",{...l,value:o,className:Xr(a,i),title:l.title??l["aria-label"],children:Ym(Zr,{icon:e,shortcut:r,badge:t,children:n})})})};mf.displayName="DropdownMenuItem";var Es={GREEN:"green",RED:"red",BLUE:"blue"},$m=({type:e=Es.BLUE,children:t})=>{let{theme:o}=$o(),n={display:"inline-flex",marginLeft:"auto",padding:"2px 4px",borderRadius:6,fontSize:9,fontFamily:"Cascadia, monospace",border:o===hD.LIGHT?"1.5px solid white":"none"};switch(e){case Es.GREEN:Object.assign(n,{backgroundColor:"var(--background-color-badge)",color:"var(--color-badge)"});break;case Es.RED:Object.assign(n,{backgroundColor:"pink",color:"darkred"});break;case Es.BLUE:default:Object.assign(n,{background:"var(--color-promo)",color:"var(--color-surface-lowest)"})}return Ym("div",{className:"DropDownMenuItemBadge",style:n,children:t})};$m.displayName="DropdownMenuItemBadge";mf.Badge=$m;var to=mf;import{KEYS as ws}from"@orangecatai/common";var n2=({event:e,inputRef:t,hoveredFont:o,filteredFonts:n,onClose:r,onSelect:a,onHover:i})=>{if(!e[ws.CTRL_OR_CMD]&&e.shiftKey&&e.key.toLowerCase()===ws.F)return t.current?.focus(),!0;if(e.key===ws.ESCAPE)return r(),!0;if(e.key===ws.ENTER)return o?.value&&a(o.value),!0;if(e.key===ws.ARROW_DOWN)return o?.next?i(o.next.value):n[0]?.value&&i(n[0].value),!0;if(e.key===ws.ARROW_UP)return o?.prev?i(o.prev.value):n[n.length-1]?.value&&i(n[n.length-1].value),!0};import{jsx as hr,jsxs as TD}from"react/jsx-runtime";var ID=e=>{switch(e){case Xa.Excalifont:case Xa.Virgil:return Bn;case Xa.Nunito:case Xa.Helvetica:return ac;case Xa["Lilita One"]:return Aw;case Xa["Comic Shanns"]:case Xa.Cascadia:return wm;default:return ac}},s2=bD.memo(({selectedFontFamily:e,hoveredFontFamily:t,onSelect:o,onHover:n,onLeave:r,onOpen:a,onClose:i})=>{let{container:s}=Qe(),l=tt(),{fonts:c}=l,{showDeprecatedFonts:m}=Hn(),p=Dt(),[d,u]=xD(""),h=r2(null),g=yD(Ho.subscribeToCustomFonts,Ho.getCustomFontVersion),x=jr(()=>Array.from(Ho.registered.entries()).filter(([M,{metadata:B}])=>!B.private&&!B.fallback).map(([M,{metadata:B,fontFaces:O}])=>{let N={value:M,icon:ID(M),text:O[0]?.fontFace?.family??"Unknown"};return B.deprecated&&Object.assign(N,{deprecated:B.deprecated,badge:{type:Es.RED,placeholder:f("fontList.badge.old")}}),N}).sort((M,B)=>M.text.toLowerCase()>B.text.toLowerCase()?1:-1),[g]),E=jr(()=>new Set(c.getSceneFamilies()),[e]),y=jr(()=>x.filter(M=>E.has(M.value)),[x,E]),w=jr(()=>x.filter(M=>!E.has(M.value)&&(m||!M.deprecated)),[x,E,m]),v=jr(()=>ED([...y,...w].filter(M=>M.text?.toLowerCase().includes(d))),[y,w,d]),I=jr(()=>{let M;return t?M=v.find(B=>B.value===t):e&&(M=v.find(B=>B.value===e)),!M&&d&&(v[0]?.value?n(v[0].value):r()),M},[t,e,d,v,n,r]),C=i2(M=>{let B=null;if(l.state.editingTextElement){let O=document.querySelector(".excalidraw-wysiwyg");O&&(B={start:O.selectionStart,end:O.selectionEnd})}o(M),l.state.editingTextElement&&B&&setTimeout(()=>{let O=document.querySelector(".excalidraw-wysiwyg");O&&B&&(O.focus(),O.selectionStart=B.start,O.selectionEnd=B.end)},0)},[o,l.state.editingTextElement]),P=i2(M=>{n2({event:M,inputRef:h,hoveredFont:I,filteredFonts:v,onSelect:C,onHover:n,onClose:i})&&(M.preventDefault(),M.stopPropagation())},[I,v,C,n,i]);a2(()=>(a(),()=>{i()}),[]);let S=jr(()=>v.filter(M=>E.has(M.value)),[v,E]),D=jr(()=>v.filter(M=>!E.has(M.value)),[v,E]),_=({font:M,order:B})=>{let O=r2(null),N=M.value===I?.value,z=M.value===e;return a2(()=>{N&&(B===0?O.current?.scrollIntoView?.({block:"end"}):O.current?.scrollIntoView?.({block:"nearest"}))},[N,B]),hr("button",{ref:O,type:"button",value:M.value,className:Xr("",z,N),title:M.text,tabIndex:z?0:-1,onClick:L=>{C(Number(L.currentTarget.value))},onMouseMove:()=>{I?.value!==M.value&&n(M.value)},children:hr(Zr,{icon:M.icon,badge:M.badge&&hr($m,{type:M.badge.type,children:M.badge.placeholder}),textStyle:{fontFamily:vD({fontFamily:M.value})},children:M.text})})},k=[];return S.length&&k.push(hr(bc,{title:f("fontList.sceneFonts"),children:S.map((M,B)=>hr(_,{font:M,order:B},M.value))},"group_1")),D.length&&k.push(hr(bc,{title:f("fontList.availableFonts"),children:D.map((M,B)=>hr(_,{font:M,order:B+S.length},M.value))},"group_2")),TD(gr,{className:"properties-content",container:s,style:{width:"15rem"},onClose:()=>{i(),l.state.editingTextElement&&setTimeout(()=>{let M=document.querySelector(".excalidraw-wysiwyg");M&&M.focus()},0)},onPointerLeave:r,onKeyDown:P,preventAutoFocusOnTouch:!!l.state.editingTextElement,children:[p==="full"&&hr(Gm,{ref:h,placeholder:f("quickSearch.placeholder"),onChange:wD(u,20)}),hr(Um,{className:"dropdown-menu fonts manual-hover",placeholder:f("fontList.empty"),children:k.length?k:null})]})},(e,t)=>e.selectedFontFamily===t.selectedFontFamily&&e.hoveredFontFamily===t.hoveredFontFamily);import{Popover as CD}from"radix-ui";import{MOBILE_ACTION_BUTTON_BG as kD}from"@orangecatai/common";import{jsx as pf}from"react/jsx-runtime";var l2=({selectedFontFamily:e,isOpened:t=!1,compactMode:o=!1})=>{let n=Ce(),r=o?{...kD,width:"2rem",height:"2rem"}:{};return pf(CD.Trigger,{asChild:!0,children:pf("div",{"data-openpopup":"fontFamily",className:"properties-trigger",children:pf(hs,{standalone:!0,icon:Fn,title:f("labels.showFonts"),className:"properties-trigger",testId:"font-family-show-fonts",active:t,onClick:()=>{n(a=>({openPopup:a.openPopup==="fontFamily"?null:a.openPopup}))},style:{border:"none",...r}})})})};import{jsx as Ec,jsxs as c2}from"react/jsx-runtime";var d2=[{value:uf.Excalifont,icon:Bn,text:f("labels.handDrawn"),testId:"font-family-hand-drawn"},{value:uf.Nunito,icon:ac,text:f("labels.normal"),testId:"font-family-normal"},{value:uf["Comic Shanns"],icon:wm,text:f("labels.code"),testId:"font-family-code"}],yse=new Set(d2.map(e=>e.value));var m2=PD.memo(({isOpened:e,selectedFontFamily:t,hoveredFontFamily:o,onSelect:n,onHover:r,onLeave:a,onPopupChange:i,compactMode:s=!1})=>{let l=LD(()=>d2,[]),c=AD(m=>{m&&n(m)},[n]);return c2("div",{role:"dialog","aria-modal":"true",className:MD("FontPicker__container",{"FontPicker__container--compact":s}),children:[!s&&Ec("div",{className:"buttonList",children:Ec(Uo,{type:"button",options:l,value:t,onClick:c})}),!s&&Ec(Dm,{}),c2(SD.Root,{open:e,onOpenChange:i,children:[Ec(l2,{selectedFontFamily:t,isOpened:e,compactMode:s}),e&&Ec(s2,{selectedFontFamily:t,hoveredFontFamily:o,onSelect:c,onHover:r,onLeave:a,onOpen:()=>i(!0),onClose:()=>i(!1)})]})]})},(e,t)=>e.isOpened===t.isOpened&&e.selectedFontFamily===t.selectedFontFamily&&e.hoveredFontFamily===t.hoveredFontFamily);import{Popover as gf}from"radix-ui";import ND from"clsx";import Vm,{useEffect as BD}from"react";import{isArrowKey as FD,KEYS as fr}from"@orangecatai/common";import{jsx as _D}from"react/jsx-runtime";var Gn=({className:e,icon:t,size:o="1em"})=>_D("span",{className:e,style:{width:o,height:"100%",margin:"0 0.5ex 0 0.5ex",display:"inline-flex",lineHeight:0,verticalAlign:"middle",flex:"0 0 auto"},children:t});import{Fragment as RD,jsx as p2,jsxs as u2}from"react/jsx-runtime";var DD=({label:e,open:t,openTrigger:o,children:n,className:r,showCollapsedIcon:a=!0})=>u2(RD,{children:[u2("div",{style:{cursor:"pointer",display:"flex",justifyContent:"space-between",alignItems:"center"},className:r,onClick:o,children:[e,a&&p2(Gn,{icon:t?mv:Tm})]}),t&&p2("div",{style:{display:"flex",flexDirection:"column"},children:n})]}),wc=DD;import{jsx as Za,jsxs as hf}from"react/jsx-runtime";var OD=Pe(!1);function zD({options:e,value:t,label:o,onChange:n,onClose:r,numberOfOptionsToAlwaysShow:a=e.length}){let i=Te(),{container:s}=Qe(),l=g=>{let x=e.find(E=>E.keyBinding===g.key.toLowerCase());if(!(g.metaKey||g.altKey||g.ctrlKey)&&x)n(x.value),g.preventDefault();else if(g.key===fr.TAB){let E=e.findIndex(w=>w.value===t),y=g.shiftKey?(e.length+E-1)%e.length:(E+1)%e.length;n(e[y].value)}else if(FD(g.key)){let E=ur().rtl,y=e.findIndex(w=>w.value===t);if(y!==-1){let w=e.length,v=y;switch(g.key){case(E?fr.ARROW_LEFT:fr.ARROW_RIGHT):v=(y+1)%w;break;case(E?fr.ARROW_RIGHT:fr.ARROW_LEFT):v=(w+y-1)%w;break;case fr.ARROW_DOWN:{v=(y+(a??1))%w;break}case fr.ARROW_UP:{v=(w+y-(a??1))%w;break}}n(e[v].value)}g.preventDefault()}else(g.key===fr.ESCAPE||g.key===fr.ENTER)&&(g.preventDefault(),r());g.nativeEvent.stopImmediatePropagation(),g.stopPropagation()},[c,m]=le(OD),p=Vm.useMemo(()=>e.slice(0,a),[e,a]),d=Vm.useMemo(()=>e.slice(a),[e,a]);BD(()=>{p.some(g=>g.value===t)||m(!0)},[t,p,m]);let u=g=>Za("div",{className:"picker-content",children:g.map((x,E)=>hf("button",{type:"button",className:ND("picker-option",{active:t===x.value}),onClick:y=>{n(x.value)},title:`${x.text} ${x.keyBinding&&`\u2014 ${x.keyBinding.toUpperCase()}`}`,"aria-label":x.text||"none","aria-keyshortcuts":x.keyBinding||void 0,ref:y=>{t===x.value&&setTimeout(()=>{y?.focus()},0)},children:[x.icon,x.keyBinding&&Za("span",{className:"picker-keybinding",children:x.keyBinding})]},x.text))}),h=i.formFactor==="phone";return Za(gf.Content,{side:h?"right":"bottom",align:"start",sideOffset:h?8:12,style:{zIndex:"var(--zIndex-ui-styles-popup)"},onKeyDown:l,collisionBoundary:s??void 0,children:hf("div",{className:"picker",role:"dialog","aria-modal":"true","aria-label":o,children:[u(p),d.length>0&&Za(wc,{label:f("labels.more_options"),open:c,openTrigger:()=>{m(g=>!g)},className:"picker-collapsible",children:u(d)})]})})}function ff({value:e,label:t,options:o,onChange:n,group:r="",numberOfOptionsToAlwaysShow:a}){let[i,s]=Vm.useState(!1),l=Vm.useRef(null);return Za("div",{children:hf(gf.Root,{open:i,onOpenChange:c=>s(c),children:[Za(gf.Trigger,{name:r,type:"button","aria-label":t,onClick:()=>s(!i),ref:l,className:i?"active":"",children:o.find(c=>c.value===e)?.icon}),i&&Za(zD,{options:o,value:e,label:t,onChange:n,onClose:()=>{s(!1)},numberOfOptionsToAlwaysShow:a})]})})}import g2,{useEffect as HD}from"react";import{jsx as bf,jsxs as h2}from"react/jsx-runtime";var f2=({updateData:e,app:t,testId:o})=>{let n=g2.useRef(null),r=g2.useRef(null),a=t.scene.getSelectedElements(t.state),i=!0,s=a.at(0),c=a.reduce((m,p)=>(m!=null&&m!==p.opacity&&(i=!1),m==null||m>p.opacity?p.opacity:m),s?.opacity??null)??t.state.currentItemOpacity;return HD(()=>{if(n.current&&r.current){let m=n.current,p=r.current,d=m.offsetWidth,u=15,h=c/100*(d-u)+u/2;p.style.left=`${h}px`,m.style.background=`linear-gradient(to right, var(--color-slider-track) 0%, var(--color-slider-track) ${c}%, var(--button-bg) ${c}%, var(--button-bg) 100%)`}},[c]),h2("label",{className:"control-label",children:[f("labels.opacity"),h2("div",{className:"range-wrapper",children:[bf("input",{style:{"--color-slider-track":i?void 0:"var(--button-bg)"},ref:n,type:"range",min:"0",max:"100",step:"10",onChange:m=>{e(+m.target.value)},value:c,className:"range-input","data-testid":o}),bf("div",{className:"value-bubble",ref:r,children:c!==0?c:null}),bf("div",{className:"zero-label",children:"0"})]})]})};import{Fragment as Sf,jsx as he,jsxs as no}from"react/jsx-runtime";var I2=.1,Is=e=>{let t=c8(e.editorInterface);return{stylesPanelMode:t,isCompact:t!=="full",isMobile:t==="mobile"}},oo=(e,t,o,n=!1)=>{let r=vf(de(e,t,{includeBoundTextElement:n}));return e.map(a=>r.get(a.id)||a.id===t.editingTextElement?.id?o(a):a)},Kt=function(e,t,o,n,r){let a=t.state.editingTextElement,i=w2(e),s=null;if(a&&(s=o(a)),!s)if(Ge(i,t.state)){let c=t.scene.getSelectedElements(t.state),m=n===!0?c:c.filter(p=>n(p));s=t8(m,o)??(typeof r=="function"?r(!0):r)}else s=typeof r=="function"?r(!1):r;return s},d8=(e,t,o)=>r8(t)||!t.autoResize?t:o.mutateElement(t,{x:e.textAlign==="left"?e.x:e.x+(e.width-t.width)/(e.textAlign==="center"?2:1),y:e.y+(e.height-t.height)/2}),Tf=(e,t,o,n,r)=>{let a=new Set,i=oo(e,t,s=>{if(fo(s)){let l=n(s);a.add(l);let c=kt(s,{fontSize:l});return vc(c,o.scene.getContainerElement(s),o.scene),c=d8(s,c,o.scene),c}return s},!0);return de(e,t,{includeBoundTextElement:!0}).forEach(s=>{fo(s)&&n8(s,o.scene)}),{elements:i,appState:{...t,currentItemFontSize:a.size===1?[...a][0]:r??t.currentItemFontSize},captureUpdate:St.IMMEDIATELY}},m8=W({name:"changeStrokeColor",label:"labels.stroke",trackEvent:!1,perform:(e,t,o)=>({...o?.currentItemStrokeColor&&{elements:oo(e,t,n=>i8(n.type)?kt(n,{strokeColor:o.currentItemStrokeColor}):n,!0)},appState:{...t,...o},captureUpdate:o?.currentItemStrokeColor?St.IMMEDIATELY:St.EVENTUALLY}),PanelComponent:({elements:e,appState:t,updateData:o,app:n,data:r})=>{let{stylesPanelMode:a}=Is(n);return no(Sf,{children:[a==="full"&&he("h3",{"aria-hidden":"true",children:f("labels.stroke")}),he(fc,{topPicks:KD,palette:VD,type:"elementStroke",label:f("labels.stroke"),color:Kt(e,n,i=>i.strokeColor,!0,i=>i?null:t.currentItemStrokeColor),onChange:i=>o({currentItemStrokeColor:i}),elements:e,appState:t,updateData:o})]})}}),p8=W({name:"changeBackgroundColor",label:"labels.changeBackground",trackEvent:!1,perform:(e,t,o,n)=>{if(!o?.currentItemBackgroundColor)return{appState:{...t,...o},captureUpdate:St.EVENTUALLY};let r,a=n.scene.getSelectedElements(t);if(!e8(o.currentItemBackgroundColor)&&a.every(s=>y2(s)&&o8(s.points))){let s=vf(a);r=e.map(l=>s.has(l.id)&&y2(l)?kt(l,{backgroundColor:o.currentItemBackgroundColor,...l8(l,!0)}):l)}else r=oo(e,t,s=>kt(s,{backgroundColor:o.currentItemBackgroundColor}));return{elements:r,appState:{...t,...o},captureUpdate:St.IMMEDIATELY}},PanelComponent:({elements:e,appState:t,updateData:o,app:n,data:r})=>{let{stylesPanelMode:a}=Is(n);return no(Sf,{children:[a==="full"&&he("h3",{"aria-hidden":"true",children:f("labels.background")}),he(fc,{topPicks:$D,palette:YD,type:"elementBackground",label:f("labels.background"),color:Kt(e,n,i=>i.backgroundColor,!0,i=>i?null:t.currentItemBackgroundColor),onChange:i=>o({currentItemBackgroundColor:i}),elements:e,appState:t,updateData:o})]})}}),u8=W({name:"changeFillStyle",label:"labels.fill",trackEvent:!1,perform:(e,t,o,n)=>(be("element","changeFillStyle",`${o} (${n.editorInterface.formFactor==="phone"?"mobile":"desktop"})`),{elements:oo(e,t,r=>kt(r,{fillStyle:o})),appState:{...t,currentItemFillStyle:o},captureUpdate:St.IMMEDIATELY}),PanelComponent:({elements:e,appState:t,updateData:o,app:n})=>{let r=de(e,t),a=r.length>0&&r.every(i=>i.fillStyle==="zigzag");return no("fieldset",{children:[he("legend",{children:f("labels.fill")}),he("div",{className:"buttonList",children:he(Uo,{type:"button",options:[{value:"hachure",text:`${a?f("labels.zigzag"):f("labels.hachure")} (${G("Alt-Click")})`,icon:a?tw:ow,active:a?!0:void 0,testId:"fill-hachure"},{value:"cross-hatch",text:f("labels.crossHatch"),icon:nw,testId:"fill-cross-hatch"},{value:"solid",text:f("labels.solid"),icon:rw,testId:"fill-solid"}],value:Kt(e,n,i=>i.fillStyle,i=>i.hasOwnProperty("fillStyle"),i=>i?null:t.currentItemFillStyle),onClick:(i,s)=>{let l=s.altKey&&i==="hachure"&&r.every(c=>c.fillStyle==="hachure")?"zigzag":i;o(l)}})})]})}}),g8=W({name:"changeStrokeWidth",label:"labels.strokeWidth",trackEvent:!1,perform:(e,t,o)=>({elements:oo(e,t,n=>kt(n,{strokeWidth:o})),appState:{...t,currentItemStrokeWidth:o},captureUpdate:St.IMMEDIATELY}),PanelComponent:({elements:e,appState:t,updateData:o,app:n,data:r})=>no("fieldset",{children:[he("legend",{children:f("labels.strokeWidth")}),he("div",{className:"buttonList",children:he(Uo,{group:"stroke-width",options:[{value:Ef.thin,text:f("labels.thin"),icon:Dh,testId:"strokeWidth-thin"},{value:Ef.bold,text:f("labels.bold"),icon:aw,testId:"strokeWidth-bold"},{value:Ef.extraBold,text:f("labels.extraBold"),icon:iw,testId:"strokeWidth-extraBold"}],value:Kt(e,n,a=>a.strokeWidth,a=>a.hasOwnProperty("strokeWidth"),a=>a?null:t.currentItemStrokeWidth),onChange:a=>o(a)})})]})}),h8=W({name:"changeSloppiness",label:"labels.sloppiness",trackEvent:!1,perform:(e,t,o)=>({elements:oo(e,t,n=>kt(n,{seed:qD(),roughness:o})),appState:{...t,currentItemRoughness:o},captureUpdate:St.IMMEDIATELY}),PanelComponent:({elements:e,appState:t,updateData:o,app:n,data:r})=>no("fieldset",{children:[he("legend",{children:f("labels.sloppiness")}),he("div",{className:"buttonList",children:he(Uo,{group:"sloppiness",options:[{value:0,text:f("labels.architect"),icon:cw},{value:1,text:f("labels.artist"),icon:dw},{value:2,text:f("labels.cartoonist"),icon:mw}],value:Kt(e,n,a=>a.roughness,a=>a.hasOwnProperty("roughness"),a=>a?null:t.currentItemRoughness),onChange:a=>o(a)})})]})}),Tle=W({name:"changeStrokeStyle",label:"labels.strokeStyle",trackEvent:!1,perform:(e,t,o)=>({elements:oo(e,t,n=>kt(n,{strokeStyle:o})),appState:{...t,currentItemStrokeStyle:o},captureUpdate:St.IMMEDIATELY}),PanelComponent:({elements:e,appState:t,updateData:o,app:n,data:r})=>no("fieldset",{children:[he("legend",{children:f("labels.strokeStyle")}),he("div",{className:"buttonList",children:he(Uo,{group:"strokeStyle",options:[{value:"solid",text:f("labels.strokeStyle_solid"),icon:Dh},{value:"dashed",text:f("labels.strokeStyle_dashed"),icon:sw},{value:"dotted",text:f("labels.strokeStyle_dotted"),icon:lw}],value:Kt(e,n,a=>a.strokeStyle,a=>a.hasOwnProperty("strokeStyle"),a=>a?null:t.currentItemStrokeStyle),onChange:a=>o(a)})})]})}),f8=W({name:"changeOpacity",label:"labels.opacity",trackEvent:!1,perform:(e,t,o)=>({elements:oo(e,t,n=>kt(n,{opacity:o}),!0),appState:{...t,currentItemOpacity:o},captureUpdate:St.IMMEDIATELY}),PanelComponent:({app:e,updateData:t})=>he(f2,{updateData:t,app:e,testId:"opacity"})}),b8=W({name:"changeFontSize",label:"labels.fontSize",trackEvent:!1,perform:(e,t,o,n)=>Tf(e,t,n,()=>(If(o,"actionChangeFontSize: Expected a font size value"),o),o),PanelComponent:({elements:e,appState:t,updateData:o,app:n,data:r})=>{let{isCompact:a}=Is(n);return no("fieldset",{children:[he("legend",{children:f("labels.fontSize")}),he("div",{className:"buttonList",children:he(Uo,{group:"font-size",options:[{value:Xm.sm,text:f("labels.small"),icon:kw,testId:"fontSize-small"},{value:Xm.md,text:f("labels.medium"),icon:Sw,testId:"fontSize-medium"},{value:Xm.lg,text:f("labels.large"),icon:Mw,testId:"fontSize-large"},{value:Xm.xl,text:f("labels.veryLarge"),icon:Pw,testId:"fontSize-veryLarge"}],value:Kt(e,n,i=>{if(fo(i))return i.fontSize;let s=qr(i,n.scene.getNonDeletedElementsMap());return s?s.fontSize:null},i=>fo(i)||qr(i,n.scene.getNonDeletedElementsMap())!==null,i=>i?null:t.currentItemFontSize||ZD),onChange:i=>{pc(()=>o(i),a,!!t.editingTextElement,r?.onPreventClose)}})})]})}}),Cf=W({name:"decreaseFontSize",label:"labels.decreaseFontSize",icon:Va,trackEvent:!1,perform:(e,t,o,n)=>Tf(e,t,n,r=>Math.round(1/(1+I2)*r.fontSize)),keyTest:e=>e[vs.CTRL_OR_CMD]&&e.shiftKey&&(e.key===vs.CHEVRON_LEFT||e.key===vs.COMMA)}),kf=W({name:"increaseFontSize",label:"labels.increaseFontSize",icon:Va,trackEvent:!1,perform:(e,t,o,n)=>Tf(e,t,n,r=>Math.round(r.fontSize*(1+I2))),keyTest:e=>e[vs.CTRL_OR_CMD]&&e.shiftKey&&(e.key===vs.CHEVRON_RIGHT||e.key===vs.PERIOD)}),x8=W({name:"changeFontFamily",label:"labels.fontFamily",trackEvent:!1,perform:(e,t,o,n)=>{let{cachedElements:r,resetAll:a,resetContainers:i,...s}=o;if(a)return{elements:oo(e,t,g=>{let x=r?.get(g.id);return x?kt(g,{...x}):g},!0),appState:{...t,...s},captureUpdate:St.NEVER};If(o,"actionChangeFontFamily: value must be defined");let{currentItemFontFamily:l,currentHoveredFontFamily:c}=o,m=St.EVENTUALLY,p,d=!1;if(l)p=l,m=St.IMMEDIATELY;else if(c){p=c,m=St.EVENTUALLY;let h=de(e,t,{includeBoundTextElement:!0}).filter(g=>fo(g));if(h.length>200)d=!0;else{let g=0,x=0;for(;g<h.length&&x<5e3;){let E=h[g];x+=E?.originalText.length||0,g++}x>5e3&&(d=!0)}}let u={appState:{...t,...s},captureUpdate:m};if(p&&!d){let h=new Map,g=new Set,x=!1,E=Array.from(Ho.loadedFontsCache.values()),y=Object.entries(jD).find(([I,C])=>C===p)?.[0];c&&y&&E.some(I=>I.startsWith(y))&&(x=!0),Object.assign(u,{elements:oo(e,t,I=>{if(fo(I)&&(I.fontFamily!==p||l)){let C=kt(I,{fontFamily:p,lineHeight:QD(p)}),P=r?.get(I.containerId||"")||{},S=n.scene.getContainerElement(I);return i&&S&&P&&n.scene.mutateElement(S,{...P}),x||(g=new Set([...g,...Array.from(C.originalText)])),h.set(C,S),C}return I},!0)});let w=`10px ${JD({fontFamily:p})}`,v=Array.from(g.values()).join();if(x||window.document.fonts.check(w,v))for(let[I,C]of h)vc(I,C,n.scene);else window.document.fonts.load(w,v).then(I=>{for(let[C,P]of h){let S=n.scene.getElement(C.id),D=P?n.scene.getElement(P.id):null;S&&vc(S,D,n.scene)}n.fonts.onLoaded(I)})}return u},PanelComponent:({elements:e,appState:t,app:o,updateData:n})=>{let r=yf(new Map),a=yf(null),[i,s]=WD({}),l=yf(!0),{stylesPanelMode:c,isCompact:m}=Is(o),p=UD(()=>{let d=(u,h)=>Kt(u,o,g=>{if(fo(g))return g.fontFamily;let x=qr(g,h);return x?x.fontFamily:null},g=>fo(g)||qr(g,h)!==null,g=>g?null:t.currentItemFontFamily||XD);return i.openPopup==="fontFamily"&&t.openPopup==="fontFamily"?d(Array.from(r.current?.values()??[]),r.current):!i.openPopup&&t.openPopup!=="fontFamily"?d(e,o.scene.getNonDeletedElementsMap()):a.current},[i.openPopup,t,e,o]);return xf(()=>{a.current=p},[p]),xf(()=>{Object.keys(i).length&&(n(i),s({}))},[i]),xf(()=>(l.current=!1,()=>{l.current=!0}),[]),no(Sf,{children:[c==="full"&&he("legend",{children:f("labels.fontFamily")}),he(m2,{isOpened:t.openPopup==="fontFamily",selectedFontFamily:p,hoveredFontFamily:t.currentHoveredFontFamily,compactMode:c!=="full",onSelect:d=>{pc(()=>{s({openPopup:null,currentHoveredFontFamily:null,currentItemFontFamily:d}),r.current.clear()},m,!!t.editingTextElement)},onHover:d=>{s({currentHoveredFontFamily:d,cachedElements:new Map(r.current),resetContainers:!0})},onLeave:()=>{s({currentHoveredFontFamily:null,cachedElements:new Map(r.current),resetAll:!0})},onPopupChange:d=>{if(d){r.current.clear();let{editingTextElement:u}=t;if(u?.type==="text"){let h=o.scene.getElement(u.id);r.current.set(u.id,kt(h||u,{},!0))}else{let h=de(e,t,{includeBoundTextElement:!0});for(let g of h)r.current.set(g.id,kt(g,{},!0))}s({...i,openPopup:"fontFamily"})}else{let u={currentHoveredFontFamily:null,cachedElements:new Map(r.current),resetAll:!0};s({...u}),r.current.clear(),m&&t.editingTextElement&&mc(null)}}})]})}}),y8=W({name:"changeTextAlign",label:"Change text alignment",trackEvent:!1,perform:(e,t,o,n)=>({elements:oo(e,t,r=>{if(fo(r)){let a=kt(r,{textAlign:o});return vc(a,n.scene.getContainerElement(r),n.scene),a}return r},!0),appState:{...t,currentItemTextAlign:o},captureUpdate:St.IMMEDIATELY}),PanelComponent:({elements:e,appState:t,updateData:o,app:n,data:r})=>{let a=n.scene.getNonDeletedElementsMap(),{isCompact:i}=Is(n);return no("fieldset",{children:[he("legend",{children:f("labels.textAlign")}),he("div",{className:"buttonList",children:he(Uo,{group:"text-align",options:[{value:"left",text:f("labels.left"),icon:Lw,testId:"align-left"},{value:"center",text:f("labels.center"),icon:_w,testId:"align-horizontal-center"},{value:"right",text:f("labels.right"),icon:Dw,testId:"align-right"}],value:Kt(e,n,s=>{if(fo(s))return s.textAlign;let l=qr(s,a);return l?l.textAlign:null},s=>fo(s)||qr(s,a)!==null,s=>s?null:t.currentItemTextAlign),onChange:s=>{pc(()=>o(s),i,!!t.editingTextElement,r?.onPreventClose)}})})]})}}),E8=W({name:"changeVerticalAlign",label:"Change vertical alignment",trackEvent:{category:"element"},perform:(e,t,o,n)=>({elements:oo(e,t,r=>{if(fo(r)){let a=kt(r,{verticalAlign:o});return vc(a,n.scene.getContainerElement(r),n.scene),a}return r},!0),appState:{...t},captureUpdate:St.IMMEDIATELY}),PanelComponent:({elements:e,appState:t,updateData:o,app:n,data:r})=>{let{isCompact:a}=Is(n);return he("fieldset",{children:he("div",{className:"buttonList",children:he(Uo,{group:"text-align",options:[{value:Km.TOP,text:f("labels.alignTop"),icon:he(Rw,{theme:t.theme}),testId:"align-top"},{value:Km.MIDDLE,text:f("labels.centerVertically"),icon:he(Bw,{theme:t.theme}),testId:"align-middle"},{value:Km.BOTTOM,text:f("labels.alignBottom"),icon:he(Nw,{theme:t.theme}),testId:"align-bottom"}],value:Kt(e,n,i=>{if(fo(i)&&i.containerId)return i.verticalAlign;let s=qr(i,n.scene.getNonDeletedElementsMap());return s?s.verticalAlign:null},i=>fo(i)||qr(i,n.scene.getNonDeletedElementsMap())!==null,i=>i?null:Km.MIDDLE),onChange:i=>{pc(()=>o(i),a,!!t.editingTextElement,r?.onPreventClose)}})})})}}),Cle=W({name:"changeRoundness",label:"Change edge roundness",trackEvent:!1,perform:(e,t,o)=>({elements:oo(e,t,n=>v2(n)?n:kt(n,{roundness:o==="round"?{type:a8(n.type)?Zm.ADAPTIVE_RADIUS:Zm.PROPORTIONAL_RADIUS}:null})),appState:{...t,currentItemRoundness:o},captureUpdate:St.IMMEDIATELY}),PanelComponent:({elements:e,appState:t,updateData:o,app:n,renderAction:r})=>{let i=Hi(w2(e),t).some(s=>s.roundness?.type===Zm.LEGACY);return no("fieldset",{children:[he("legend",{children:f("labels.edges")}),no("div",{className:"buttonList",children:[he(Uo,{group:"edges",options:[{value:"sharp",text:f("labels.sharp"),icon:pw},{value:"round",text:f("labels.round"),icon:uw}],value:Kt(e,n,s=>i?null:s.roundness?"round":"sharp",s=>!jm(s)&&s.hasOwnProperty("roundness"),s=>s?null:t.currentItemRoundness),onChange:s=>o(s)}),r("togglePolygon")]})]})}}),E2=e=>[{value:null,text:f("labels.arrowhead_none"),keyBinding:"q",icon:he(gw,{flip:e})},{value:"arrow",text:f("labels.arrowhead_arrow"),keyBinding:"w",icon:he(hw,{flip:e})},{value:"triangle",text:f("labels.arrowhead_triangle"),icon:he(yw,{flip:e}),keyBinding:"e"},{value:"triangle_outline",text:f("labels.arrowhead_triangle_outline"),icon:he(Ew,{flip:e}),keyBinding:"r"},{value:"circle",text:f("labels.arrowhead_circle"),keyBinding:"a",icon:he(fw,{flip:e})},{value:"circle_outline",text:f("labels.arrowhead_circle_outline"),keyBinding:"s",icon:he(bw,{flip:e})},{value:"diamond",text:f("labels.arrowhead_diamond"),icon:he(ww,{flip:e}),keyBinding:"d"},{value:"diamond_outline",text:f("labels.arrowhead_diamond_outline"),icon:he(vw,{flip:e}),keyBinding:"f"},{value:"bar",text:f("labels.arrowhead_bar"),keyBinding:"z",icon:he(xw,{flip:e})},{value:"crowfoot_one",text:f("labels.arrowhead_crowfoot_one"),icon:he(Tw,{flip:e}),keyBinding:"x"},{value:"crowfoot_many",text:f("labels.arrowhead_crowfoot_many"),icon:he(Iw,{flip:e}),keyBinding:"c"},{value:"crowfoot_one_or_many",text:f("labels.arrowhead_crowfoot_one_or_many"),icon:he(Cw,{flip:e}),keyBinding:"v"}],kle=W({name:"changeArrowhead",label:"Change arrowheads",trackEvent:!1,perform:(e,t,o)=>(If(o,"actionChangeArrowhead: value must be defined"),{elements:oo(e,t,n=>{if(wf(n)){let{position:r,type:a}=o;if(r==="start")return kt(n,{startArrowhead:a});if(r==="end")return kt(n,{endArrowhead:a})}return n}),appState:{...t,[o.position==="start"?"currentItemStartArrowhead":"currentItemEndArrowhead"]:o.type},captureUpdate:St.IMMEDIATELY}),PanelComponent:({elements:e,appState:t,updateData:o,app:n})=>{let r=ur().rtl;return no("fieldset",{children:[he("legend",{children:f("labels.arrowheads")}),no("div",{className:"iconSelectList buttonList",children:[he(ff,{label:"arrowhead_start",options:E2(!r),value:Kt(e,n,a=>wf(a)&&Gi(a.type)?a.startArrowhead:t.currentItemStartArrowhead,!0,a=>a?null:t.currentItemStartArrowhead),onChange:a=>o({position:"start",type:a}),numberOfOptionsToAlwaysShow:4}),he(ff,{label:"arrowhead_end",group:"arrowheads",options:E2(!!r),value:Kt(e,n,a=>wf(a)&&Gi(a.type)?a.endArrowhead:t.currentItemEndArrowhead,!0,a=>a?null:t.currentItemEndArrowhead),onChange:a=>o({position:"end",type:a}),numberOfOptionsToAlwaysShow:4})]})]})}}),w8=W({name:"changeArrowProperties",label:"Change arrow properties",trackEvent:!1,perform:(e,t,o,n)=>!1,PanelComponent:({elements:e,appState:t,updateData:o,app:n,renderAction:r})=>no("div",{className:"selected-shape-actions",children:[r("changeArrowhead"),r("changeArrowType")]})}),Sle=W({name:"changeArrowType",label:"Change arrow types",trackEvent:!1,perform:(e,t,o,n)=>{let r=oo(e,t,s=>{if(!jm(s))return s;let l=n.scene.getNonDeletedElementsMap(),c=ja.getPointAtIndexGlobalCoordinates(s,0,l),m=ja.getPointAtIndexGlobalCoordinates(s,-1,l),p=kt(s,{x:o===Vo.elbow?c[0]:s.x,y:o===Vo.elbow?c[1]:s.y,roundness:o===Vo.round?{type:Zm.PROPORTIONAL_RADIUS}:null,elbowed:o===Vo.elbow,angle:o===Vo.elbow?0:s.angle,points:o===Vo.elbow||s.elbowed?[ja.pointFromAbsoluteCoords({...s,x:c[0],y:c[1],angle:0},c,l),ja.pointFromAbsoluteCoords({...s,x:c[0],y:c[1],angle:0},m,l)]:s.points});if(v2(p)){p.fixedSegments=null;let d=n.scene.getNonDeletedElementsMap();n.dismissLinearEditor();let u=ja.getPointAtIndexGlobalCoordinates(p,0,d),h=ja.getPointAtIndexGlobalCoordinates(p,-1,d),g=p.startBinding&&d.get(p.startBinding.elementId),x=p.endBinding&&d.get(p.endBinding.elementId),E=g&&p.startBinding?{...p.startBinding,...x2(p,g,"start",d)}:null,y=x&&p.endBinding?{...p.endBinding,...x2(p,x,"end",d)}:null;p={...p,startBinding:E,endBinding:y,...s8(p,d,{points:[u,h].map(w=>GD(w[0]-p.x,w[1]-p.y)),startBinding:E,endBinding:y,fixedSegments:null})}}else{let d=n.scene.getNonDeletedElementsMap();if(p.startBinding){let u=d.get(p.startBinding.elementId);u&&b2(p,u,t.bindMode==="inside"?"inside":"orbit","start",n.scene)}if(p.endBinding){let u=d.get(p.endBinding.elementId);u&&b2(p,u,t.bindMode==="inside"?"inside":"orbit","end",n.scene)}}return p}),a={...t,currentItemArrowType:o},i=t.selectedLinearElement?.elementId;if(i){let s=r.find(l=>l.id===i);s&&(a.selectedLinearElement=new ja(s,vf(e)))}return{elements:r,appState:a,captureUpdate:St.IMMEDIATELY}},PanelComponent:({elements:e,appState:t,updateData:o,app:n})=>no("fieldset",{children:[he("legend",{children:f("labels.arrowtypes")}),he("div",{className:"buttonList",children:he(Uo,{group:"arrowtypes",options:[{value:Vo.sharp,text:f("labels.arrowtype_sharp"),icon:ds,testId:"sharp-arrow"},{value:Vo.round,text:f("labels.arrowtype_round"),icon:ps,testId:"round-arrow"},{value:Vo.elbow,text:f("labels.arrowtype_elbowed"),icon:ms,testId:"elbow-arrow"}],value:Kt(e,n,r=>jm(r)?r.elbowed?Vo.elbow:r.roundness?Vo.round:Vo.sharp:null,r=>jm(r),r=>r?null:t.currentItemArrowType),onChange:r=>o(r)})})]})});import{clamp as _f,roundToStep as M8}from"@orangecatai/math";import{DEFAULT_CANVAS_BACKGROUND_PICKS as P8,CURSOR_TYPE as L2,MAX_ZOOM as _2,MIN_ZOOM as D2,THEME as Ic,ZOOM_STEP as Df,updateActiveTool as Cs,CODES as Wn,KEYS as xr,viewportCoordsToSceneCoords as A8}from"@orangecatai/common";import{getElementAbsoluteCoords as M2,getNonDeletedElements as R2,getVisibleElements as L8}from"@orangecatai/element";import{newElementWith as _8}from"@orangecatai/element";import{getCommonBounds as N2}from"@orangecatai/element";import{CaptureUpdateAction as un}from"@orangecatai/element";import{useEffect as v8}from"react";import{jsx as T8}from"react/jsx-runtime";var Ts=()=>{let e=document.querySelector(".excalidraw-tooltip");if(e)return e;let t=document.createElement("div");return document.body.appendChild(t),t.classList.add("excalidraw-tooltip"),t},Mf=(e,t,o="bottom")=>{let n=e.getBoundingClientRect(),r=window.innerWidth,a=window.innerHeight,i=5,s=t.left+t.width/2-n.width/2;s<0?s=i:s+n.width>=r&&(s=r-n.width-i);let l;o==="bottom"?(l=t.top+t.height+i,l+n.height>=a&&(l=t.top-n.height-i)):(l=t.top-n.height-i,l<0&&(l=t.top+t.height+i)),Object.assign(e.style,{top:`${l}px`,left:`${s}px`})},I8=(e,t,o,n)=>{t.classList.add("excalidraw-tooltip--visible"),t.style.minWidth=n?"50ch":"10ch",t.style.maxWidth=n?"50ch":"15ch",t.textContent=o;let r=e.getBoundingClientRect();Mf(t,r)},Xt=({children:e,label:t,long:o=!1,style:n,disabled:r})=>(v8(()=>()=>Ts().classList.remove("excalidraw-tooltip--visible"),[]),r?null:T8("div",{className:"excalidraw-tooltip-wrapper",onPointerEnter:a=>I8(a.currentTarget,Ts(),t,o),onPointerLeave:()=>Ts().classList.remove("excalidraw-tooltip--visible"),style:n,children:e}));import{CURSOR_TYPE as Pf,MIME_TYPES as Af,THEME as C2}from"@orangecatai/common";var k2='<svg viewBox="0 0 24 24" stroke-width="1" width="28" height="28" xmlns="http://www.w3.org/2000/svg">',C8='<path d="M6.164 11.755a5.314 5.314 0 0 1-4.932-5.298 5.314 5.314 0 0 1 5.311-5.311 5.314 5.314 0 0 1 5.307 5.113l8.773 8.773a3.322 3.322 0 0 1 0 4.696l-.895.895a3.322 3.322 0 0 1-4.696 0l-8.868-8.868Z" style="fill:#fff"/>',S2='<path stroke="#1b1b1f" fill="#fff" d="m7.868 11.113 7.773 7.774a2.359 2.359 0 0 0 1.667.691 2.368 2.368 0 0 0 2.357-2.358c0-.625-.248-1.225-.69-1.667L11.201 7.78 9.558 9.469l-1.69 1.643v.001Zm10.273 3.606-3.333 3.333m-3.25-6.583 2 2m-7-7 3 3M3.664 3.625l1 1M2.529 6.922l1.407-.144m5.735-2.932-1.118.866M4.285 9.823l.758-1.194m1.863-6.207-.13 1.408"/>',k8=`data:${Af.svg},${encodeURIComponent(`${k2}${S2}</svg>`)}`,S8=`data:${Af.svg},${encodeURIComponent(`${k2}${C8}${S2}</svg>`)}`,Po=e=>{e&&(e.style.cursor="")},Be=(e,t)=>{e&&(e.style.cursor=t)},Un,T2,Lf=(e,t)=>{let n=()=>{let r=t===C2.DARK;Un=document.createElement("canvas"),Un.theme=t,Un.height=20,Un.width=20;let a=Un.getContext("2d");a.lineWidth=1,a.beginPath(),a.arc(Un.width/2,Un.height/2,5,0,2*Math.PI),a.fillStyle=r?"#000":"#fff",a.fill(),a.strokeStyle=r?"#fff":"#000",a.stroke(),T2=Un.toDataURL(Af.svg)};(!Un||Un.theme!==t)&&n(),Be(e,`url(${T2}) ${20/2} ${20/2}, auto`)},Ao=(e,t)=>{if(e)if(t.activeTool.type==="selection")Po(e);else if(pr(t))e.style.cursor=Pf.GRAB;else if(ho(t))Lf(e,t.theme);else if(t.activeTool.type==="laser"){let o=t.theme===C2.LIGHT?k8:S8;e.style.cursor=`url(${o}), auto`}else["image","custom"].includes(t.activeTool.type)?t.activeTool.type!=="image"&&(e.style.cursor=Pf.AUTO):e.style.cursor=Pf.CROSSHAIR};var br=({viewportX:e,viewportY:t,nextZoom:o},n)=>{let r=e-n.offsetLeft,a=t-n.offsetTop,i=n.zoom.value,s=n.scrollX+(r-r/i),l=n.scrollY+(a-a/i),c=-(r-r/o),m=-(a-a/o);return{scrollX:s+c,scrollY:l+m,zoom:{value:o}}};import{jsx as ks,jsxs as G8}from"react/jsx-runtime";var D8=W({name:"changeViewBackgroundColor",label:"labels.canvasBackground",trackEvent:!1,predicate:(e,t,o,n)=>!!n.props.UIOptions.canvasActions.changeViewBackgroundColor&&!t.viewModeEnabled,perform:(e,t,o)=>({appState:{...t,...o},captureUpdate:o?.viewBackgroundColor?un.IMMEDIATELY:un.EVENTUALLY}),PanelComponent:({elements:e,appState:t,updateData:o,appProps:n,data:r})=>ks(fc,{palette:null,topPicks:P8,label:f("labels.canvasBackground"),type:"canvasBackground",color:t.viewBackgroundColor,onChange:a=>o({viewBackgroundColor:a}),"data-testid":"canvas-background-picker",elements:e,appState:t,updateData:o})}),yr=W({name:"clearCanvas",label:"labels.clearCanvas",icon:Ut,trackEvent:{category:"canvas"},predicate:(e,t,o,n)=>!!n.props.UIOptions.canvasActions.clearCanvas&&!t.viewModeEnabled&&t.openDialog?.name!=="elementLinkSelector",perform:(e,t,o,n)=>(n.imageCache.clear(),{elements:e.map(r=>_8(r,{isDeleted:!0})),appState:{...Or(),files:{},theme:t.theme,penMode:t.penMode,penDetected:t.penDetected,exportBackground:t.exportBackground,exportEmbedScene:t.exportEmbedScene,gridSize:t.gridSize,gridStep:t.gridStep,gridModeEnabled:t.gridModeEnabled,stats:t.stats,pasteDialog:t.pasteDialog,activeTool:t.activeTool.type==="image"?{...t.activeTool,type:n.state.preferredSelectionTool.type}:t.activeTool},captureUpdate:un.IMMEDIATELY})}),qm=W({name:"zoomIn",label:"buttons.zoomIn",viewMode:!0,icon:fh,trackEvent:{category:"canvas"},perform:(e,t,o,n)=>({appState:{...t,...br({viewportX:t.width/2+t.offsetLeft,viewportY:t.height/2+t.offsetTop,nextZoom:Ln(t.zoom.value+Df)},t),userToFollow:null},captureUpdate:un.EVENTUALLY}),PanelComponent:({updateData:e,appState:t})=>ks(ie,{type:"button",className:"zoom-in-button zoom-button",icon:fh,title:`${f("buttons.zoomIn")} \u2014 ${G("CtrlOrCmd++")}`,"aria-label":f("buttons.zoomIn"),disabled:t.zoom.value>=_2,onClick:()=>{e(null)}}),keyTest:e=>(e.code===Wn.EQUAL||e.code===Wn.NUM_ADD)&&(e[xr.CTRL_OR_CMD]||e.shiftKey)}),Jm=W({name:"zoomOut",label:"buttons.zoomOut",icon:bh,viewMode:!0,trackEvent:{category:"canvas"},perform:(e,t,o,n)=>({appState:{...t,...br({viewportX:t.width/2+t.offsetLeft,viewportY:t.height/2+t.offsetTop,nextZoom:Ln(t.zoom.value-Df)},t),userToFollow:null},captureUpdate:un.EVENTUALLY}),PanelComponent:({updateData:e,appState:t})=>ks(ie,{type:"button",className:"zoom-out-button zoom-button",icon:bh,title:`${f("buttons.zoomOut")} \u2014 ${G("CtrlOrCmd+-")}`,"aria-label":f("buttons.zoomOut"),disabled:t.zoom.value<=D2,onClick:()=>{e(null)}}),keyTest:e=>(e.code===Wn.MINUS||e.code===Wn.NUM_SUBTRACT)&&(e[xr.CTRL_OR_CMD]||e.shiftKey)}),Qm=W({name:"resetZoom",label:"buttons.resetZoom",icon:OE,viewMode:!0,trackEvent:{category:"canvas"},perform:(e,t,o,n)=>({appState:{...t,...br({viewportX:t.width/2+t.offsetLeft,viewportY:t.height/2+t.offsetTop,nextZoom:Ln(1)},t),userToFollow:null},captureUpdate:un.EVENTUALLY}),PanelComponent:({updateData:e,appState:t})=>ks(Xt,{label:f("buttons.resetZoom"),style:{height:"100%"},children:G8(ie,{type:"button",className:"reset-zoom-button zoom-button",title:f("buttons.resetZoom"),"aria-label":f("buttons.resetZoom"),onClick:()=>{e(null)},children:[(t.zoom.value*100).toFixed(0),"%"]})}),keyTest:e=>(e.code===Wn.ZERO||e.code===Wn.NUM_ZERO)&&(e[xr.CTRL_OR_CMD]||e.shiftKey)}),R8=(e,t,o=1)=>{let[n,r,a,i]=e,s=a-n,l=t.width/s,c=i-r,m=t.height/c,d=Math.min(l,m)*_f(o,.1,1);return Math.min(d,1)},N8=.8,B8=(e,t)=>e[0]<=t[2]&&e[2]>=t[0]&&e[1]<=t[3]&&e[3]>=t[1],F8=(e,t)=>[e[0]-t,e[1]-t,e[2]+t,e[3]+t],P2=(e,t)=>{let o=(e[0]+e[2])/2,n=(e[1]+e[3])/2;return Math.hypot(o-t.x,n-t.y)},A2=e=>[e[0],e[1],e[2],e[3]],O8=(e,t)=>{let o=R2(e);if(!o.length)return[];let n=L8(o),r=n.length?n:o,a=new Map(o.map(d=>[d.id,d])),i=A8({clientX:t.offsetLeft+t.width/2,clientY:t.offsetTop+t.height/2},t),s=r.reduce((d,u)=>{let h=A2(M2(u,a));return d?P2(h,i)<P2(d.bounds,i)?{element:u,bounds:h}:d:{element:u,bounds:h}},null);if(!s)return[];let l=Math.max(160/t.zoom.value,.12*Math.min(t.width,t.height)/t.zoom.value),c=new Map([[s.element.id,s.element]]),m=s.bounds,p=!0;for(;p;){p=!1;let d=F8(m,l);for(let u of r){if(c.has(u.id))continue;let h=A2(M2(u,a));B8(h,d)&&(c.set(u.id,u),m=N2([...c.values()]),p=!0)}}return[...c.values()]},B2=({bounds:e,appState:t,canvasOffsets:o,fitToViewport:n=!1,viewportZoomFactor:r=1,minZoom:a=-1/0,maxZoom:i=1/0})=>{r=_f(r,D2,_2);let[s,l,c,m]=e,p=(s+c)/2,d=(l+m)/2,u=o?.left??0,h=o?.top??0,g=o?.right??0,x=o?.bottom??0,E=t.width-u-g,y=t.height-h-x,w;if(n){let C=c-s,P=m-l;w=Math.min(E/C,y/P)*r}else w=R8(e,{width:E,height:y},r);let v=Ln(_f(M8(w,Df,"floor"),a,i)),I=oE({scenePoint:{x:p,y:d},viewportDimensions:{width:t.width,height:t.height},offsets:o,zoom:{value:v}});return{appState:{...t,scrollX:I.scrollX,scrollY:I.scrollY,zoom:{value:v}},captureUpdate:un.EVENTUALLY}},Ss=({canvasOffsets:e,targetElements:t,appState:o,fitToViewport:n,viewportZoomFactor:r,minZoom:a,maxZoom:i})=>{let s=N2(R2(t));return B2({canvasOffsets:e,bounds:s,appState:o,fitToViewport:n,viewportZoomFactor:r,minZoom:a,maxZoom:i})},cce=W({name:"zoomToFitSelectionInViewport",label:"labels.zoomToFitViewport",icon:cs,trackEvent:{category:"canvas"},perform:(e,t,o,n)=>{let r=n.scene.getSelectedElements(t);return Ss({targetElements:r.length?r:e,appState:{...t,userToFollow:null},fitToViewport:!1,canvasOffsets:n.getEditorUIOffsets()})},keyTest:e=>e.code===Wn.TWO&&e.shiftKey&&!e.altKey&&!e[xr.CTRL_OR_CMD]}),dce=W({name:"zoomToFitSelection",label:"helpDialog.zoomToSelection",icon:cs,trackEvent:{category:"canvas"},perform:(e,t,o,n)=>{let r=n.scene.getSelectedElements(t);return Ss({targetElements:r.length?r:e,appState:{...t,userToFollow:null},fitToViewport:!0,canvasOffsets:n.getEditorUIOffsets()})},keyTest:e=>e.code===Wn.THREE&&e.shiftKey&&!e.altKey&&!e[xr.CTRL_OR_CMD]}),z8=W({name:"zoomToFit",label:"helpDialog.zoomToFit",icon:cs,viewMode:!0,trackEvent:{category:"canvas"},perform:(e,t,o,n)=>Ss({targetElements:e,appState:{...t,userToFollow:null},fitToViewport:!1,canvasOffsets:n.getEditorUIOffsets()}),keyTest:e=>e.code===Wn.ONE&&e.shiftKey&&!e.altKey&&!e[xr.CTRL_OR_CMD]}),H8=W({name:"scrollBackToContent",label:"buttons.scrollBackToContent",icon:cs,viewMode:!0,trackEvent:{category:"canvas"},perform:(e,t,o,n)=>{let r=n.scene.getSelectedElements(t),a=r.length?r:O8(e,t);return a.length?Ss({targetElements:a,appState:{...t,userToFollow:null},fitToViewport:!0,viewportZoomFactor:N8,canvasOffsets:n.getEditorUIOffsets()}):!1},PanelComponent:({updateData:e})=>ks(Xt,{label:f("buttons.scrollBackToContent"),style:{height:"100%"},children:ks(ie,{type:"button",className:"scroll-back-to-content-button zoom-button",icon:cs,title:f("buttons.scrollBackToContent"),"aria-label":f("buttons.scrollBackToContent"),onClick:()=>{e(null)}})})}),qa=W({name:"toggleTheme",label:(e,t)=>t.theme===Ic.DARK?"buttons.lightMode":"buttons.darkMode",keywords:["toggle","dark","light","mode","theme"],icon:(e,t)=>e.theme===Ic.LIGHT?oc:nc,viewMode:!0,trackEvent:{category:"canvas"},perform:(e,t,o)=>({appState:{...t,theme:o||(t.theme===Ic.LIGHT?Ic.DARK:Ic.LIGHT)},captureUpdate:un.EVENTUALLY}),keyTest:e=>e.altKey&&e.shiftKey&&e.code===Wn.D,predicate:(e,t,o,n)=>!!n.props.UIOptions.canvasActions.toggleTheme}),mce=W({name:"toggleEraserTool",label:"toolBar.eraser",trackEvent:{category:"toolbar"},perform:(e,t,o,n)=>{let r;return ho(t)?r=Cs(t,{...t.activeTool.lastActiveTool||{type:n.state.preferredSelectionTool.type},lastActiveToolBeforeEraser:null}):r=Cs(t,{type:"eraser",lastActiveToolBeforeEraser:t.activeTool}),{appState:{...t,selectedElementIds:{},selectedGroupIds:{},activeEmbeddable:null,activeTool:r},captureUpdate:un.IMMEDIATELY}},keyTest:e=>e.key===xr.E}),pce=W({name:"toggleLassoTool",label:"toolBar.lasso",icon:Hr,trackEvent:{category:"toolbar"},predicate:(e,t,o,n)=>n.state.preferredSelectionTool.type!=="lasso",perform:(e,t,o,n)=>{let r;return t.activeTool.type!=="lasso"?(r=Cs(t,{type:"lasso",fromSelection:!1}),Be(n.interactiveCanvas,L2.CROSSHAIR)):r=Cs(t,{type:"selection"}),{appState:{...t,selectedElementIds:{},selectedGroupIds:{},activeEmbeddable:null,activeTool:r},captureUpdate:un.NEVER}}}),F2=W({name:"toggleHandTool",label:"toolBar.hand",trackEvent:{category:"toolbar"},icon:as,viewMode:!1,perform:(e,t,o,n)=>{let r;return pr(t)?r=Cs(t,{...t.activeTool.lastActiveTool||{type:"selection"},lastActiveToolBeforeEraser:null}):(r=Cs(t,{type:"hand",lastActiveToolBeforeEraser:t.activeTool}),Be(n.interactiveCanvas,L2.GRAB)),{appState:{...t,selectedElementIds:{},selectedGroupIds:{},activeEmbeddable:null,activeTool:r},captureUpdate:un.IMMEDIATELY}},keyTest:e=>!e.altKey&&!e[xr.CTRL_OR_CMD]&&e.key===xr.H});import{updateActiveTool as O2}from"@orangecatai/common";import{CaptureUpdateAction as U8}from"@orangecatai/element";var W8=W({name:"setEmbeddableAsActiveTool",trackEvent:{category:"toolbar"},target:"Tool",label:"toolBar.embeddable",perform:(e,t,o,n)=>{let r=O2(t,{type:"embeddable"});return Ao(n.canvas,{...t,activeTool:r}),{elements:e,appState:{...t,activeTool:O2(t,{type:"embeddable"})},captureUpdate:U8.EVENTUALLY}}});import{pointFrom as z2}from"@orangecatai/math";import{bindOrUnbindBindingElement as Y8}from"@orangecatai/element/binding";import{isValidPolygon as H2,LinearElementEditor as ep,newElementWith as Rf}from"@orangecatai/element";import{isBindingElement as G2,isFreeDrawElement as U2,isLinearElement as W2,isLineElement as tp}from"@orangecatai/element";import{KEYS as Nf,arrayToMap as $8,invariant as Y2,shouldRotateWithDiscreteAngle as V8,updateActiveTool as $2}from"@orangecatai/common";import{isPathALoop as K8}from"@orangecatai/element";import{isInvisiblySmallElement as Bf}from"@orangecatai/element";import{CaptureUpdateAction as V2}from"@orangecatai/element";import{jsx as X8}from"react/jsx-runtime";var ro=W({name:"finalize",label:"",trackEvent:!1,perform:(e,t,o,n)=>{let r=e,{interactiveCanvas:a,focusContainer:i,scene:s}=n,l=s.getNonDeletedElementsMap();if(o&&t.selectedLinearElement){let{event:d,sceneCoords:u}=o,h=ep.getElement(t.selectedLinearElement.elementId,l);Y2(h,"Arrow element should exist if selectedLinearElement is set"),Y2(u,"sceneCoords should be defined if actionFinalize is called with event");let g=ep.handlePointerUp(d,t.selectedLinearElement,t,n.scene);if(G2(h)&&!t.selectedLinearElement.segmentMidPointHoveredCoords){let x=!!t.newElement,y=(x||!t.selectedLinearElement.selectedPointsIndices?[h.points.length-1]:t.selectedLinearElement.selectedPointsIndices).reduce((w,v)=>(w.set(v,{point:ep.pointFromAbsoluteCoords(h,z2(u.x-g.pointerOffset.x,u.y-g.pointerOffset.y),l)}),w),new Map)??new Map;Y8(h,y,u.x-g.pointerOffset.x,u.y-g.pointerOffset.y,s,t,{newArrow:x,altKey:d.altKey,angleLocked:V8(d)})}else tp(h)&&t.selectedLinearElement?.isEditing&&!t.newElement&&!H2(h.points)&&s.mutateElement(h,{polygon:!1});if(g!==t.selectedLinearElement){h&&Bf(h)&&(r=r.map(E=>E.id===h.id?Rf(E,{isDeleted:!0}):E));let x=t.activeTool?.locked;return{elements:h.points.length<2||Bf(h)?e.map(E=>E.id===h.id?Rf(E,{isDeleted:!0}):E):r,appState:{...t,cursorButton:"up",selectedLinearElement:x?null:{...g,selectedPointsIndices:null,isEditing:!1,initialState:{...g.initialState,lastClickedPoint:-1},pointerOffset:{x:0,y:0}},selectionElement:null,suggestedBinding:null,newElement:null,multiElement:null},captureUpdate:V2.IMMEDIATELY}}}window.document.activeElement instanceof HTMLElement&&i();let c=null;if(t.multiElement)c=t.multiElement;else if(t.newElement?.type==="freedraw"||G2(t.newElement))c=t.newElement;else if(Object.keys(t.selectedElementIds).length===1){let d=l.get(Object.keys(t.selectedElementIds)[0]);d&&(c=d)}if(c){if(t.selectedLinearElement&&t.multiElement&&c.type!=="freedraw"&&t.lastPointerDownWith!=="touch"){let{points:d}=c,{lastCommittedPoint:u}=t.selectedLinearElement;(!u||d[d.length-1]!==u)&&s.mutateElement(c,{points:c.points.slice(0,-1)})}if(c&&Bf(c)&&(r=r.map(d=>d.id===c?.id?Rf(d,{isDeleted:!0}):d)),W2(c)||U2(c)){if(K8(c.points,t.zoom.value)&&(tp(c)||U2(c))){let u=c.points,h=u[0],g=u.map((x,E)=>E===u.length-1?z2(h[0],h[1]):x);tp(c)?s.mutateElement(c,{points:g,polygon:!0}):s.mutateElement(c,{points:g})}tp(c)&&!H2(c.points)&&s.mutateElement(c,{polygon:!1})}}(!t.activeTool.locked&&t.activeTool.type!=="freedraw"||!c)&&Po(a);let m;t.activeTool.type==="eraser"?m=$2(t,{...t.activeTool.lastActiveTool||{type:n.state.preferredSelectionTool.type},lastActiveToolBeforeEraser:null}):m=$2(t,{type:n.state.preferredSelectionTool.type});let p=c&&W2(c)?new ep(c,$8(r)):t.selectedLinearElement;return p=p&&{...p,isEditing:t.newElement?!1:p.isEditing,initialState:{...p.initialState,lastClickedPoint:-1,origin:null}},{elements:r,appState:{...t,cursorButton:"up",activeTool:(t.activeTool.locked||t.activeTool.type==="freedraw")&&c?t.activeTool:m,activeEmbeddable:null,newElement:null,selectionElement:null,multiElement:null,editingTextElement:null,startBoundElement:null,suggestedBinding:null,selectedElementIds:c&&!t.activeTool.locked&&t.activeTool.type!=="freedraw"?{...t.selectedElementIds,[c.id]:!0}:t.selectedElementIds,selectedLinearElement:p},captureUpdate:V2.IMMEDIATELY}},keyTest:(e,t)=>e.key===Nf.ESCAPE&&(t.selectedLinearElement?.isEditing||!t.newElement&&t.multiElement===null)||(e.key===Nf.ESCAPE||e.key===Nf.ENTER)&&t.multiElement!==null,PanelComponent:({appState:e,updateData:t,data:o})=>X8(ie,{type:"button",icon:KE,title:f("buttons.done"),"aria-label":f("buttons.done"),onClick:t,visible:e.multiElement!=null,size:o?.size||"medium",style:{pointerEvents:"all"}})});import{KEYS as Ls,DEFAULT_EXPORT_PADDING as OR,EXPORT_SCALES as zR,THEME as zf}from"@orangecatai/common";import{getNonDeletedElements as HR}from"@orangecatai/element";import{CaptureUpdateAction as fn}from"@orangecatai/element";import Z8 from"clsx";import{jsx as K2,jsxs as j8}from"react/jsx-runtime";var Tc=({children:e,checked:t,onChange:o,className:n})=>j8("div",{className:Z8("Checkbox",n,{"is-checked":t}),onClick:r=>{o(!t,r),r.currentTarget.querySelector(".Checkbox-box").focus()},children:[K2("button",{type:"button",className:"Checkbox-box",role:"checkbox","aria-checked":t,children:bm}),K2("div",{className:"Checkbox-label",children:e})]});import{THEME as Cc}from"@orangecatai/common";import{jsx as kc}from"react/jsx-runtime";var Z2=e=>{let t=e.title||(e.value===Cc.DARK?f("buttons.lightMode"):f("buttons.darkMode"));return kc(ie,{type:"icon",icon:e.value===Cc.LIGHT?X2.MOON:X2.SUN,title:t,"aria-label":t,onClick:()=>e.onChange(e.value===Cc.DARK?Cc.LIGHT:Cc.DARK),"data-testid":"toggle-dark-mode"})},X2={SUN:kc("svg",{width:"512",height:"512",className:"rtl-mirror",viewBox:"0 0 512 512",children:kc("path",{fill:"currentColor",d:"M256 160c-52.9 0-96 43.1-96 96s43.1 96 96 96 96-43.1 96-96-43.1-96-96-96zm246.4 80.5l-94.7-47.3 33.5-100.4c4.5-13.6-8.4-26.5-21.9-21.9l-100.4 33.5-47.4-94.8c-6.4-12.8-24.6-12.8-31 0l-47.3 94.7L92.7 70.8c-13.6-4.5-26.5 8.4-21.9 21.9l33.5 100.4-94.7 47.4c-12.8 6.4-12.8 24.6 0 31l94.7 47.3-33.5 100.5c-4.5 13.6 8.4 26.5 21.9 21.9l100.4-33.5 47.3 94.7c6.4 12.8 24.6 12.8 31 0l47.3-94.7 100.4 33.5c13.6 4.5 26.5-8.4 21.9-21.9l-33.5-100.4 94.7-47.3c13-6.5 13-24.7.2-31.1zm-155.9 106c-49.9 49.9-131.1 49.9-181 0-49.9-49.9-49.9-131.1 0-181 49.9-49.9 131.1-49.9 181 0 49.9 49.9 49.9 131.1 0 181z"})}),MOON:kc("svg",{width:"512",height:"512",className:"rtl-mirror",viewBox:"0 0 512 512",children:kc("path",{fill:"currentColor",d:"M283.211 512c78.962 0 151.079-35.925 198.857-94.792 7.068-8.708-.639-21.43-11.562-19.35-124.203 23.654-238.262-71.576-238.262-196.954 0-72.222 38.662-138.635 101.498-174.394 9.686-5.512 7.25-20.197-3.756-22.23A258.156 258.156 0 0 0 283.211 0c-141.309 0-256 114.511-256 256 0 141.309 114.511 256 256 256z"})})};import{useState as q8}from"react";import{focusNearestParent as J8,KEYS as Q8}from"@orangecatai/common";import{jsx as j2,jsxs as eR}from"react/jsx-runtime";var q2=e=>{let{id:t}=Qe(),[o,n]=q8(e.value),r=i=>{e.ignoreFocus||J8(i.target);let s=i.target.value;s!==e.value&&e.onChange(s)},a=i=>{if(i.key===Q8.ENTER){if(i.preventDefault(),i.nativeEvent.isComposing||i.keyCode===229)return;i.currentTarget.blur()}};return eR("div",{className:"ProjectName",children:[j2("label",{className:"ProjectName-label",htmlFor:"filename",children:`${e.label}:`}),j2("input",{type:"text",className:"TextInput",onBlur:r,onKeyDown:a,id:`${t}-filename`,value:o,onChange:i=>n(i.target.value)})]})};import{DEFAULT_EXPORT_PADDING as PR,DEFAULT_FILENAME as AR,IMAGE_MIME_TYPES as gI,isFirefox as LR,MIME_TYPES as _R,cloneJSON as DR,SVG_DOCUMENT_PREAMBLE as RR}from"@orangecatai/common";import{getNonDeletedElements as NR}from"@orangecatai/element";import{isFrameLikeElement as BR}from"@orangecatai/element";import{getElementsOverlappingFrame as FR}from"@orangecatai/element";import{ALLOWED_PASTE_MIME_TYPES as pR,EXPORT_DATA_TYPES as Pc,MIME_TYPES as Lo,arrayToMap as uR,isMemberOf as gR,isPromiseLike as hR,EVENT as rp}from"@orangecatai/common";import{mutateElement as fR}from"@orangecatai/element";import{deepCopyElement as bR}from"@orangecatai/element";import{isFrameLikeElement as xR,isInitializedImageElement as yR}from"@orangecatai/element";import{getContainingFrame as lI}from"@orangecatai/element";import{pointFrom as Jr}from"@orangecatai/math";import{COLOR_PALETTE as Q2,DEFAULT_CHART_COLOR_INDEX as tR,getAllColorsSpecificShade as oR,DEFAULT_FONT_FAMILY as nR,DEFAULT_FONT_SIZE as eI,VERTICAL_ALIGN as rR,randomId as tI,isDevEnv as oI,FONT_SIZES as aR}from"@orangecatai/common";import{newTextElement as op,newLinearElement as Mc,newElement as Of}from"@orangecatai/element";var gn=32,Ke=12,Qr=256,nI=50,Ja="NOT_SPREADSHEET",Ms="VALID_SPREADSHEET",Sc=e=>{let t=/^([-+]?)[$€£¥₩]?([-+]?)([\d.,]+)[%]?$/.exec(e);return t?parseFloat(`${(t[1]||t[2])+t[3]}`.replace(/,/g,"")):null},Ff=(e,t)=>e.slice(1).every(o=>Sc(o[t])!==null),J2=e=>{let t=e[0].length;if(t>2)return{type:Ja,reason:"More than 2 columns"};if(t===1){if(!Ff(e,0))return{type:Ja,reason:"Value is not numeric"};let l=Sc(e[0][0])===null,c=(l?e.slice(1):e).map(m=>Sc(m[0]));return c.length<2?{type:Ja,reason:"Less than two rows"}:{type:Ms,spreadsheet:{title:l?e[0][0]:null,labels:null,values:c}}}let o=Ff(e,0),n=Ff(e,1);if(!o&&!n)return{type:Ja,reason:"Value is not numeric"};let[r,a]=n?[0,1]:[1,0],i=Sc(e[0][a])===null,s=i?e.slice(1):e;return s.length<2?{type:Ja,reason:"Less than 2 rows"}:{type:Ms,spreadsheet:{title:i?e[0][a]:null,labels:s.map(l=>l[r]),values:s.map(l=>Sc(l[a]))}}},iR=e=>{let t=[];for(let o=0;o<e[0].length;o++){let n=[];for(let r=0;r<e.length;r++)n.push(e[r][o]);t.push(n)}return t},rI=e=>{let t=e.trim().split(`
|
|
2
2
|
`).map(a=>a.trim().split(" "));if(t.length&&t[0].length!==2&&(t=e.trim().split(`
|
|
3
3
|
`).map(a=>a.trim().split(","))),t.length===0)return{type:Ja,reason:"No values"};let o=t[0].length;if(!t.every(a=>a.length===o))return{type:Ja,reason:"All rows don't have same number of columns"};let r=J2(t);if(r.type!==Ms){let a=J2(iR(t));if(a.type===Ms)return a}return r},np=oR(tR),Ko={fillStyle:"hachure",fontFamily:nR,fontSize:eI,opacity:100,roughness:1,strokeColor:Q2.black,roundness:null,strokeStyle:"solid",strokeWidth:1,verticalAlign:rR.MIDDLE,locked:!1},aI=e=>{let t=(gn+Ke)*e.values.length+Ke,o=Qr+Ke*2;return{chartWidth:t,chartHeight:o}},sR=(e,t,o,n,r)=>e.labels?.map((a,i)=>op({groupIds:[n],backgroundColor:r,...Ko,text:a.length>8?`${a.slice(0,5)}...`:a,x:t+i*(gn+Ke)+Ke*2,y:o+Ke/2,width:gn,angle:5.87,fontSize:aR.sm,textAlign:"center",verticalAlign:"top"}))||[],lR=(e,t,o,n,r)=>{let a=op({groupIds:[n],backgroundColor:r,...Ko,x:t-Ke,y:o-Ke,text:"0",textAlign:"right"}),i=op({groupIds:[n],backgroundColor:r,...Ko,x:t-Ke,y:o-Qr-a.height/2,text:Math.max(...e.values).toLocaleString(),textAlign:"right"});return[a,i]},cR=(e,t,o,n,r)=>{let{chartWidth:a,chartHeight:i}=aI(e),s=Mc({backgroundColor:r,groupIds:[n],...Ko,type:"line",x:t,y:o,width:a,points:[Jr(0,0),Jr(a,0)]}),l=Mc({backgroundColor:r,groupIds:[n],...Ko,type:"line",x:t,y:o,height:i,points:[Jr(0,0),Jr(0,-i)]}),c=Mc({backgroundColor:r,groupIds:[n],...Ko,type:"line",x:t,y:o-Qr-Ke,strokeStyle:"dotted",width:a,opacity:nI,points:[Jr(0,0),Jr(a,0)]});return[s,l,c]},iI=(e,t,o,n,r,a)=>{let{chartWidth:i,chartHeight:s}=aI(e),l=e.title?op({backgroundColor:r,groupIds:[n],...Ko,text:e.title,x:t+i/2,y:o-Qr-Ke*2-eI,roundness:null,textAlign:"center"}):null,c=a?Of({backgroundColor:r,groupIds:[n],...Ko,type:"rectangle",x:t,y:o-s,width:i,height:s,strokeColor:Q2.black,fillStyle:"solid",opacity:6}):null;return[...c?[c]:[],...l?[l]:[],...sR(e,t,o,n,r),...lR(e,t,o,n,r),...cR(e,t,o,n,r)]},dR=(e,t,o)=>{let n=Math.max(...e.values),r=tI(),a=np[Math.floor(Math.random()*np.length)];return[...e.values.map((s,l)=>{let c=s/n*Qr;return Of({backgroundColor:a,groupIds:[r],...Ko,type:"rectangle",x:t+l*(gn+Ke)+Ke,y:o-c-Ke,width:gn,height:c})}),...iI(e,t,o,r,a,oI())]},mR=(e,t,o)=>{let n=Math.max(...e.values),r=tI(),a=np[Math.floor(Math.random()*np.length)],i=0,s=[];for(let g of e.values){let x=i*(gn+Ke),E=-(g/n)*Qr;s.push([x,E]),i++}let l=Math.max(...s.map(g=>g[0])),c=Math.max(...s.map(g=>g[1])),m=Math.min(...s.map(g=>g[0])),p=Math.min(...s.map(g=>g[1])),d=Mc({backgroundColor:a,groupIds:[r],...Ko,type:"line",x:t+Ke+gn/2,y:o-Ke,height:c-p,width:l-m,strokeWidth:2,points:s}),u=e.values.map((g,x)=>{let E=x*(gn+Ke)+Ke/2,y=-(g/n)*Qr+Ke/2;return Of({backgroundColor:a,groupIds:[r],...Ko,fillStyle:"solid",strokeWidth:2,type:"ellipse",x:t+E+gn/2,y:o+y-Ke*2,width:Ke,height:Ke})}),h=e.values.map((g,x)=>{let E=x*(gn+Ke)+Ke/2,y=g/n*Qr+Ke/2+Ke;return Mc({backgroundColor:a,groupIds:[r],...Ko,type:"line",x:t+E+gn/2+Ke/2,y:o-y,height:y,strokeStyle:"dotted",opacity:nI,points:[Jr(0,0),Jr(0,y)]})});return[...iI(e,t,o,r,a,oI()),d,...h,...u]},sI=(e,t,o,n)=>e==="line"?mR(t,o,n):dR(t,o,n);var Cde="clipboard"in navigator&&"readText"in navigator.clipboard,ap="clipboard"in navigator&&"writeText"in navigator.clipboard,Ps="clipboard"in navigator&&"write"in navigator.clipboard&&"ClipboardItem"in window&&"toBlob"in HTMLCanvasElement.prototype,ER=e=>!!([Pc.excalidraw,Pc.excalidrawClipboard,Pc.excalidrawClipboardWithAPI].includes(e?.type)&&Array.isArray(e.elements)),cI=({types:e,files:t})=>{!e&&!t&&console.warn("createPasteEvent: no types or files provided");let o=new ClipboardEvent(rp.PASTE,{clipboardData:new DataTransfer});if(e)for(let[n,r]of Object.entries(e)){if(typeof r!="string"){t=t||[],t.push(r);continue}try{if(o.clipboardData?.items.add(r,n),o.clipboardData?.getData(n)!==r)throw new Error(`Failed to set "${n}" as clipboardData item`)}catch(a){throw new Error(a.message)}}if(t){let n=-1;for(let r of t){n++;try{if(o.clipboardData?.items.add(r),o.clipboardData?.files[n]!==r)throw new Error(`Failed to set file "${r.name}" as clipboardData item`)}catch(a){throw new Error(a.message)}}}return o},wR=({elements:e,files:t})=>{let o=uR(e),n=new Set(e.filter(s=>xR(s))),r=!1,a=e.reduce((s,l)=>(yR(l)&&(r=!0,t&&t[l.fileId]&&(s[l.fileId]=t[l.fileId])),s),{});r&&!t&&console.warn("copyToClipboard: attempting to file element(s) without providing associated `files` object.");let i={type:Pc.excalidrawClipboard,elements:e.map(s=>{if(lI(s,o)&&!n.has(lI(s,o))){let l=bR(s);return fR(l,o,{frameId:null}),l}return s}),files:t?a:void 0};return JSON.stringify(i)},ip=async(e,t,o)=>{let n=wR({elements:e,files:t});await hn({[Lo.excalidrawClipboard]:n,[Lo.text]:n},o)},vR=e=>{let t=rI(e);return t.type===Ms?{spreadsheet:t.spreadsheet}:null};function dI(e){let t=[];for(let o of e.childNodes)if(o.nodeType===3){let n=o.textContent?.trim();n&&t.push({type:"text",value:n})}else if(o instanceof HTMLImageElement){let n=o.getAttribute("src");n&&n.startsWith("http")&&t.push({type:"imageUrl",value:n})}else t=t.concat(dI(o));return t}var IR=e=>{let t=e.value;try{let o=new DOMParser().parseFromString(t,Lo.html),n=dI(o.body);if(n.length)return{type:"mixedContent",value:n}}catch(o){console.error(`error in parseHTMLFromPaste: ${o.message}`)}return null},mI=async()=>{let e={},t;try{t=await navigator.clipboard?.read()}catch(o){try{if(navigator.clipboard?.readText){console.warn(`navigator.clipboard.readText() failed (${o.message}). Failling back to navigator.clipboard.read()`);let n=await navigator.clipboard?.readText();if(n)return{[Lo.text]:n}}}catch(n){if(navigator.clipboard?.read)console.warn(`navigator.clipboard.readText() failed (${n.message}). Failling back to navigator.clipboard.read()`);else{if(n.name==="DataError")return console.warn(`navigator.clipboard.read() error, clipboard is probably empty: ${n.message}`),e;throw n}}throw o}for(let o of t)for(let n of o.types)if(gR(pR,n))try{if(n===Lo.text||n===Lo.html)e[n]=await(await o.getType(n)).text();else if(hE(n)){let r=await o.getType(n),a=vE(r,n,void 0);e[n]=a}else throw new sh(`Unsupported clipboard type: ${n}`)}catch(r){console.warn(r instanceof sh?r.message:`Cannot retrieve ${n} from clipboardItem: ${r.message}`)}return Object.keys(e).length===0&&console.warn("No clipboard data found from clipboard.read()."),e},TR=async(e,t=!1)=>{try{let o=e.findByType(Lo.html),n=!t&&o&&IR(o);return n?n.value.every(r=>r.type==="text")?{type:"text",value:e.getData(Lo.text)??n.value.map(r=>r.value).join(`
|
|
4
|
-
`).trim()}:n:{type:"text",value:(e.getData(Lo.text)||"").trim()}}catch{return{type:"text",value:""}}},CR=function(e){return this.find(t=>t.type===e)||null},kR=function(e){return this.find(o=>o.type===e)?.value??null},SR=function(){return this.filter(e=>e.kind==="file")},pI=e=>{let t;uI(e)?t=e.clipboardData?.items:t=e.dataTransfer?.items;let o=new Set;for(let n of Array.from(t||[]))o.has(n.type)||o.add(n.type);return o},As=async e=>{let t;uI(e)?t=e.clipboardData?.items:t=e.dataTransfer?.items;let o=(await Promise.all(Array.from(t||[]).map(async n=>{if(n.kind==="file"){let r=n.getAsFile();if(r){let a=await wE(n);return r=await ec(r),{type:r.type,kind:"file",file:r,fileHandle:a}}}else if(n.kind==="string"){let{type:r}=n,a;return"clipboardData"in e&&e.clipboardData?a=e.clipboardData?.getData(r):a=await new Promise(i=>{n.getAsString(s=>i(s))}),{type:r,kind:"string",value:a}}return null}))).filter(n=>n!=null);return Object.assign(o,{findByType:CR,getData:kR,getFiles:SR})},sp=async(e,t=!1)=>{let o=await TR(e,t);if(o.type==="mixedContent")return{mixedContent:o.value};try{let n=!t&&vR(o.value);if(n)return n}catch(n){console.error(n)}try{let n=JSON.parse(o.value),r=n.type===Pc.excalidrawClipboardWithAPI;if(ER(n))return{elements:n.elements,files:n.files,text:t?JSON.stringify(n.elements,null,2):void 0,programmaticAPI:r}}catch{}return{text:o.value}},lp=async e=>{try{await navigator.clipboard.write([new ClipboardItem({[Lo.png]:e})])}catch(t){if(hR(e))await navigator.clipboard.write([new ClipboardItem({[Lo.png]:await e})]);else throw t}},hn=async(e,t)=>{e=e||"";let o=Object.entries(typeof e=="string"?{[Lo.text]:e}:e);try{if(t){for(let[r,a]of o)if(t.clipboardData?.setData(r,a),t.clipboardData?.getData(r)!==a)throw new Error("Failed to setData on clipboardEvent");return}}catch(r){console.error(r)}let n=o.find(([r])=>r===Lo.text);if(ap&&n)try{await navigator.clipboard.writeText(n[1]);return}catch(r){console.error(r)}if(n&&!MR(n[1]))throw new Error("Error copying to clipboard.")},MR=e=>{e||(e=" ");let t=document.documentElement.getAttribute("dir")==="rtl",o=document.createElement("textarea");o.style.border="0",o.style.padding="0",o.style.margin="0",o.style.position="absolute",o.style[t?"right":"left"]="-9999px";let n=window.pageYOffset||document.documentElement.scrollTop;o.style.top=`${n}px`,o.style.fontSize="12pt",o.setAttribute("readonly",""),o.value=e,document.body.appendChild(o);let r=!1;try{o.select(),o.setSelectionRange(0,o.value.length),r=document.execCommand("copy")}catch(a){console.error(a)}return o.remove(),r},uI=e=>e.type===rp.PASTE||e.type===rp.COPY||e.type===rp.CUT;var Qa=(e,{selectedElementIds:t},o)=>{e=NR(e);let n=o&&Ge(e,{selectedElementIds:t}),r=null,a=n?de(e,{selectedElementIds:t},{includeBoundTextElement:!0}):e;return n&&(a.length===1&&BR(a[0])?(r=a[0],a=FR(e,r)):a.length>1&&(a=de(e,{selectedElementIds:t},{includeBoundTextElement:!0,includeElementsInFrames:!0}))),{exportingFrame:r,exportedElements:DR(a)}},ei=async(e,t,o,n,{exportBackground:r,exportPadding:a=PR,viewBackgroundColor:i,name:s=o.name||AR,fileHandle:l=null,exportingFrame:c=null})=>{if(t.length===0)throw new Error(f("alerts.cannotExportEmptyCanvas"));if(e==="svg"||e==="clipboard-svg"){let p=Yi(t,{exportBackground:r,exportWithDarkMode:o.exportWithDarkMode,viewBackgroundColor:i,exportPadding:a,exportScale:o.exportScale,exportEmbedScene:o.exportEmbedScene&&e==="svg"},n,{exportingFrame:c});if(e==="svg")return lh(p.then(d=>new Blob([RR+d.outerHTML],{type:_R.svg})),{description:"Export to SVG",name:s,extension:o.exportEmbedScene?"excalidraw.svg":"svg",mimeTypes:[gI.svg],fileHandle:l});if(e==="clipboard-svg"){let d=await p.then(u=>u.outerHTML);try{await hn(d)}catch{throw new Error(f("errors.copyToSystemClipboardFailed"))}return}}let m=zr(t,o,n,{exportBackground:r,viewBackgroundColor:i,exportPadding:a,exportingFrame:c});if(e==="png"){let p=Ua(m);return o.exportEmbedScene&&(p=p.then(d=>import("./data/image-
|
|
4
|
+
`).trim()}:n:{type:"text",value:(e.getData(Lo.text)||"").trim()}}catch{return{type:"text",value:""}}},CR=function(e){return this.find(t=>t.type===e)||null},kR=function(e){return this.find(o=>o.type===e)?.value??null},SR=function(){return this.filter(e=>e.kind==="file")},pI=e=>{let t;uI(e)?t=e.clipboardData?.items:t=e.dataTransfer?.items;let o=new Set;for(let n of Array.from(t||[]))o.has(n.type)||o.add(n.type);return o},As=async e=>{let t;uI(e)?t=e.clipboardData?.items:t=e.dataTransfer?.items;let o=(await Promise.all(Array.from(t||[]).map(async n=>{if(n.kind==="file"){let r=n.getAsFile();if(r){let a=await wE(n);return r=await ec(r),{type:r.type,kind:"file",file:r,fileHandle:a}}}else if(n.kind==="string"){let{type:r}=n,a;return"clipboardData"in e&&e.clipboardData?a=e.clipboardData?.getData(r):a=await new Promise(i=>{n.getAsString(s=>i(s))}),{type:r,kind:"string",value:a}}return null}))).filter(n=>n!=null);return Object.assign(o,{findByType:CR,getData:kR,getFiles:SR})},sp=async(e,t=!1)=>{let o=await TR(e,t);if(o.type==="mixedContent")return{mixedContent:o.value};try{let n=!t&&vR(o.value);if(n)return n}catch(n){console.error(n)}try{let n=JSON.parse(o.value),r=n.type===Pc.excalidrawClipboardWithAPI;if(ER(n))return{elements:n.elements,files:n.files,text:t?JSON.stringify(n.elements,null,2):void 0,programmaticAPI:r}}catch{}return{text:o.value}},lp=async e=>{try{await navigator.clipboard.write([new ClipboardItem({[Lo.png]:e})])}catch(t){if(hR(e))await navigator.clipboard.write([new ClipboardItem({[Lo.png]:await e})]);else throw t}},hn=async(e,t)=>{e=e||"";let o=Object.entries(typeof e=="string"?{[Lo.text]:e}:e);try{if(t){for(let[r,a]of o)if(t.clipboardData?.setData(r,a),t.clipboardData?.getData(r)!==a)throw new Error("Failed to setData on clipboardEvent");return}}catch(r){console.error(r)}let n=o.find(([r])=>r===Lo.text);if(ap&&n)try{await navigator.clipboard.writeText(n[1]);return}catch(r){console.error(r)}if(n&&!MR(n[1]))throw new Error("Error copying to clipboard.")},MR=e=>{e||(e=" ");let t=document.documentElement.getAttribute("dir")==="rtl",o=document.createElement("textarea");o.style.border="0",o.style.padding="0",o.style.margin="0",o.style.position="absolute",o.style[t?"right":"left"]="-9999px";let n=window.pageYOffset||document.documentElement.scrollTop;o.style.top=`${n}px`,o.style.fontSize="12pt",o.setAttribute("readonly",""),o.value=e,document.body.appendChild(o);let r=!1;try{o.select(),o.setSelectionRange(0,o.value.length),r=document.execCommand("copy")}catch(a){console.error(a)}return o.remove(),r},uI=e=>e.type===rp.PASTE||e.type===rp.COPY||e.type===rp.CUT;var Qa=(e,{selectedElementIds:t},o)=>{e=NR(e);let n=o&&Ge(e,{selectedElementIds:t}),r=null,a=n?de(e,{selectedElementIds:t},{includeBoundTextElement:!0}):e;return n&&(a.length===1&&BR(a[0])?(r=a[0],a=FR(e,r)):a.length>1&&(a=de(e,{selectedElementIds:t},{includeBoundTextElement:!0,includeElementsInFrames:!0}))),{exportingFrame:r,exportedElements:DR(a)}},ei=async(e,t,o,n,{exportBackground:r,exportPadding:a=PR,viewBackgroundColor:i,name:s=o.name||AR,fileHandle:l=null,exportingFrame:c=null})=>{if(t.length===0)throw new Error(f("alerts.cannotExportEmptyCanvas"));if(e==="svg"||e==="clipboard-svg"){let p=Yi(t,{exportBackground:r,exportWithDarkMode:o.exportWithDarkMode,viewBackgroundColor:i,exportPadding:a,exportScale:o.exportScale,exportEmbedScene:o.exportEmbedScene&&e==="svg"},n,{exportingFrame:c});if(e==="svg")return lh(p.then(d=>new Blob([RR+d.outerHTML],{type:_R.svg})),{description:"Export to SVG",name:s,extension:o.exportEmbedScene?"excalidraw.svg":"svg",mimeTypes:[gI.svg],fileHandle:l});if(e==="clipboard-svg"){let d=await p.then(u=>u.outerHTML);try{await hn(d)}catch{throw new Error(f("errors.copyToSystemClipboardFailed"))}return}}let m=zr(t,o,n,{exportBackground:r,viewBackgroundColor:i,exportPadding:a,exportingFrame:c});if(e==="png"){let p=Ua(m);return o.exportEmbedScene&&(p=p.then(d=>import("./data/image-3TR7TIWR.js").then(({encodePngMetadata:u})=>u({blob:d,metadata:jl(t,o,n,"local")})))),lh(p,{description:"Export to PNG",name:s,extension:o.exportEmbedScene?"excalidraw.png":"png",mimeTypes:[gI.png],fileHandle:l})}else if(e==="clipboard")try{let p=Ua(m);await lp(p)}catch(p){throw console.warn(p),p.name==="CANVAS_POSSIBLY_TOO_BIG"?new Error(f("canvasError.canvasTooBig")):LR&&p.name==="TypeError"?new Error(`${f("alerts.couldNotCopyToClipboard")}
|
|
5
5
|
|
|
6
|
-
${f("hints.firefox_clipboard_write")}`):new Error(f("alerts.couldNotCopyToClipboard"))}else throw new Error("Unsupported export type")};var hI=async(e,t,o,n)=>{let{exportBackground:r,viewBackgroundColor:a,fileHandle:i}=t,s=uE(i);if(!i||!gE(s))throw new Error("fileHandle should exist and should be of type svg or png when resaving");t={...t,exportEmbedScene:!0};let{exportedElements:l,exportingFrame:c}=Qa(e,t,!1);return await ei(s,l,t,o,{exportBackground:r,viewBackgroundColor:a,name:n,fileHandle:i,exportingFrame:c}),{fileHandle:i}};import{Fragment as GR,jsx as Er,jsxs as UR}from"react/jsx-runtime";var Hf=W({name:"changeProjectName",label:"labels.fileTitle",trackEvent:!1,perform:(e,t,o)=>({appState:{...t,name:o},captureUpdate:fn.EVENTUALLY}),PanelComponent:({appState:e,updateData:t,appProps:o,data:n,app:r})=>Er(q2,{label:f("labels.fileTitle"),value:r.getName(),onChange:a=>t(a),ignoreFocus:n?.ignoreFocus??!1})}),fI=W({name:"changeExportScale",label:"imageExportDialog.scale",trackEvent:{category:"export",action:"scale"},perform:(e,t,o)=>({appState:{...t,exportScale:o},captureUpdate:fn.EVENTUALLY}),PanelComponent:({elements:e,appState:t,updateData:o})=>{let n=HR(e),a=Ge(n,t)?de(n,t):n;return Er(GR,{children:zR.map(i=>{let[s,l]=mE(a,OR,i),c=`${f("imageExportDialog.label.scale")} ${i}x (${s}x${l})`;return Er(ae,{size:"small",type:"radio",icon:`${i}x`,name:"export-canvas-scale",title:c,"aria-label":c,id:"export-canvas-scale",checked:i===t.exportScale,onChange:()=>o(i)},i)})})}}),Gf=W({name:"changeExportBackground",label:"imageExportDialog.label.withBackground",trackEvent:{category:"export",action:"toggleBackground"},perform:(e,t,o)=>({appState:{...t,exportBackground:o},captureUpdate:fn.EVENTUALLY}),PanelComponent:({appState:e,updateData:t})=>Er(Tc,{checked:e.exportBackground,onChange:o=>t(o),children:f("imageExportDialog.label.withBackground")})}),cp=W({name:"changeExportEmbedScene",label:"imageExportDialog.tooltip.embedScene",trackEvent:{category:"export",action:"embedScene"},perform:(e,t,o)=>({appState:{...t,exportEmbedScene:o},captureUpdate:fn.EVENTUALLY}),PanelComponent:({appState:e,updateData:t})=>UR(Tc,{checked:e.exportEmbedScene,onChange:o=>t(o),children:[f("imageExportDialog.label.embedScene"),Er(Xt,{label:f("imageExportDialog.tooltip.embedScene"),long:!0,children:Er("div",{className:"excalidraw-tooltip-icon",children:XE})})]})}),ti=W({name:"saveToActiveFile",label:"buttons.save",icon:$a,trackEvent:{category:"export"},predicate:(e,t,o,n)=>!!n.props.UIOptions.canvasActions.saveToActiveFile&&!!t.fileHandle&&!t.viewModeEnabled,perform:async(e,t,o,n)=>{let r=!!t.fileHandle;try{let{fileHandle:a}=sm(t.fileHandle)?await hI(e,t,n.files,n.getName()):await nm(e,t,n.files,n.getName());return{captureUpdate:fn.EVENTUALLY,appState:{...t,fileHandle:a,toast:r?{message:a?.name?f("toast.fileSavedToFilename").replace("{filename}",`"${a.name}"`):f("toast.fileSaved")}:null}}}catch(a){return a?.name!=="AbortError"?console.error(a):console.warn(a),{captureUpdate:fn.EVENTUALLY}}},keyTest:e=>e.key===Ls.S&&e[Ls.CTRL_OR_CMD]&&!e.shiftKey}),Ac=W({name:"saveFileToDisk",label:"exportDialog.disk_title",icon:$a,viewMode:!0,trackEvent:{category:"export"},perform:async(e,t,o,n)=>{try{let{fileHandle:r}=await nm(e,{...t,fileHandle:null},n.files,n.getName());return{captureUpdate:fn.EVENTUALLY,appState:{...t,openDialog:null,fileHandle:r,toast:{message:f("toast.fileSaved")}}}}catch(r){return r?.name!=="AbortError"?console.error(r):console.warn(r),{captureUpdate:fn.EVENTUALLY}}},keyTest:e=>e.key===Ls.S&&e.shiftKey&&e[Ls.CTRL_OR_CMD],PanelComponent:({updateData:e})=>Er(ae,{type:"button",icon:YE,title:f("buttons.saveAs"),"aria-label":f("buttons.saveAs"),showAriaLabel:Te().formFactor==="phone",hidden:!Wi,onClick:()=>e(null),"data-testid":"save-as-button"})}),_s=W({name:"loadScene",label:"buttons.load",trackEvent:{category:"export"},predicate:(e,t,o,n)=>!!n.props.UIOptions.canvasActions.loadScene&&!t.viewModeEnabled,perform:async(e,t,o,n)=>{try{let{elements:r,appState:a,files:i}=await ch(t,e);return{elements:r,appState:a,files:i,captureUpdate:fn.IMMEDIATELY}}catch(r){return r?.name==="AbortError"?(console.warn(r),!1):{elements:e,appState:{...t,errorMessage:r.message},files:n.files,captureUpdate:fn.EVENTUALLY}}},keyTest:e=>e[Ls.CTRL_OR_CMD]&&e.key===Ls.O}),bI=W({name:"exportWithDarkMode",label:"imageExportDialog.label.darkMode",trackEvent:{category:"export",action:"toggleTheme"},perform:(e,t,o)=>({appState:{...t,exportWithDarkMode:o},captureUpdate:fn.EVENTUALLY}),PanelComponent:({appState:e,updateData:t})=>Er("div",{style:{display:"flex",justifyContent:"flex-end",marginTop:"-45px",marginBottom:"10px"},children:Er(Z2,{value:e.exportWithDarkMode?zf.DARK:zf.LIGHT,onChange:o=>{t(o===zf.DARK)},title:f("imageExportDialog.label.darkMode")})})});import{DEFAULT_FONT_SIZE as WR,DEFAULT_FONT_FAMILY as YR,DEFAULT_TEXT_ALIGN as $R,CODES as xI,KEYS as yI,getLineHeight as VR}from"@orangecatai/common";import{newElementWith as dp}from"@orangecatai/element";import{hasBoundTextElement as KR,canApplyRoundnessTypeToElement as XR,getDefaultRoundnessTypeForElement as ZR,isFrameLikeElement as jR,isArrowElement as qR,isExcalidrawElement as JR,isTextElement as Uf}from"@orangecatai/element";import{getBoundTextElement as QR,redrawTextBoundingBox as e7}from"@orangecatai/element";import{CaptureUpdateAction as Wf}from"@orangecatai/element";var EI="{}",Yf=W({name:"copyStyles",label:"labels.copyStyles",icon:Bh,trackEvent:{category:"element"},perform:(e,t,o,n)=>{let r=[],a=e.find(i=>t.selectedElementIds[i.id]);if(r.push(a),a&&KR(a)){let i=QR(a,n.scene.getNonDeletedElementsMap());r.push(i)}return a&&(EI=JSON.stringify(r)),{appState:{...t,toast:{message:f("toast.copyStyles")}},captureUpdate:Wf.EVENTUALLY}},keyTest:e=>e[yI.CTRL_OR_CMD]&&e.altKey&&e.code===xI.C}),$f=W({name:"pasteStyles",label:"labels.pasteStyles",icon:Bh,trackEvent:{category:"element"},perform:(e,t,o,n)=>{let r=JSON.parse(EI),a=r[0],i=r[1];if(!JR(a))return{elements:e,captureUpdate:Wf.EVENTUALLY};let s=de(e,t,{includeBoundTextElement:!0}),l=s.map(c=>c.id);return{elements:e.map(c=>{if(l.includes(c.id)){let m=a;if(Uf(c)&&c.containerId&&(m=i),!m)return c;let p=dp(c,{backgroundColor:m?.backgroundColor,strokeWidth:m?.strokeWidth,strokeColor:m?.strokeColor,strokeStyle:m?.strokeStyle,fillStyle:m?.fillStyle,opacity:m?.opacity,roughness:m?.roughness,roundness:m.roundness?XR(m.roundness.type,c)?m.roundness:ZR(c):null});if(Uf(p)){let d=m.fontSize||WR,u=m.fontFamily||YR;p=dp(p,{fontSize:d,fontFamily:u,textAlign:m.textAlign||$R,lineHeight:m.lineHeight||VR(u)});let h=null;p.containerId&&(h=s.find(g=>Uf(p)&&g.id===p.containerId)||null),e7(p,h,n.scene)}return p.type==="arrow"&&qR(m)&&(p=dp(p,{startArrowhead:m.startArrowhead,endArrowhead:m.endArrowhead})),jR(c)&&(p=dp(p,{roundness:null,backgroundColor:"transparent"})),p}return c}),captureUpdate:Wf.IMMEDIATELY}},keyTest:e=>e[yI.CTRL_OR_CMD]&&e.altKey&&e.code===xI.V});import{KEYS as t7}from"@orangecatai/common";import{CaptureUpdateAction as o7}from"@orangecatai/element";var oi=W({name:"toggleShortcuts",label:"welcomeScreen.defaults.helpHint",icon:HE,viewMode:!0,trackEvent:{category:"menu",action:"toggleHelpDialog"},perform:(e,t,o,{focusContainer:n})=>(t.openDialog?.name==="help"&&n(),{appState:{...t,openDialog:t.openDialog?.name==="help"?null:{name:"help"},openMenu:null,openPopup:null},captureUpdate:o7.EVENTUALLY}),keyTest:e=>e.key===t7.QUESTION_MARK});import{getNonDeletedElements as pp}from"@orangecatai/element";import{newElementWith as II}from"@orangecatai/element";import{isBoundToContainer as n7}from"@orangecatai/element";import{frameAndChildrenSelectedTogether as r7,getElementsInResizingFrame as a7,getFrameLikeElements as i7,getRootElements as s7,groupByFrameLikes as l7,removeElementsFromFrame as c7,replaceAllElementsInFrame as d7}from"@orangecatai/element";import{KEYS as up,randomId as m7,arrayToMap as Vf}from"@orangecatai/common";import{getSelectedGroupIds as mp,selectGroup as p7,selectGroupsForSelectedElements as u7,getElementsInGroup as wI,addToGroup as g7,removeFromSelectedGroups as h7,isElementInGroup as TI}from"@orangecatai/element";import{syncMovedIndices as f7}from"@orangecatai/element";import{CaptureUpdateAction as Lc}from"@orangecatai/element";import{jsx as Ds}from"react/jsx-runtime";var b7=e=>{if(e.length>=2){let t=e[0].groupIds;for(let o of t)if(e.reduce((n,r)=>n&&TI(r,o),!0))return!0}return!1},vI=(e,t,o)=>{let n=o.scene.getSelectedElements({selectedElementIds:t.selectedElementIds,includeBoundTextElement:!0});return n.length>=2&&!b7(n)&&!r7(n)},Kf=W({name:"group",label:"labels.group",icon:e=>Ds(Lh,{theme:e.theme}),trackEvent:{category:"element"},perform:(e,t,o,n)=>{let r=s7(n.scene.getSelectedElements({selectedElementIds:t.selectedElementIds,includeBoundTextElement:!0}));if(r.length<2)return{appState:t,elements:e,captureUpdate:Lc.EVENTUALLY};let a=mp(t);if(a.length===1){let x=a[0],E=new Set(wI(e,x).map(v=>v.id)),y=new Set(r.map(v=>v.id));if(new Set([...Array.from(E),...Array.from(y)]).size===E.size)return{appState:t,elements:e,captureUpdate:Lc.EVENTUALLY}}let i=[...e];new Set(r.map(x=>x.frameId)).size>1&&l7(r).forEach((E,y)=>{c7(E,n.scene.getNonDeletedElementsMap())});let l=m7(),c=Vf(r);i=i.map(x=>c.get(x.id)?II(x,{groupIds:g7(x.groupIds,l,t.editingGroupId)}):x);let m=wI(i,l),p=m[m.length-1],d=i.lastIndexOf(p),u=i.slice(d+1),h=i.slice(0,d).filter(x=>!TI(x,l)),g=f7([...h,...m,...u],Vf(m));return{appState:{...t,...p7(l,{...t,selectedGroupIds:{}},pp(i))},elements:g,captureUpdate:Lc.IMMEDIATELY}},predicate:(e,t,o,n)=>vI(e,t,n),keyTest:e=>!e.shiftKey&&e[up.CTRL_OR_CMD]&&e.key===up.G,PanelComponent:({elements:e,appState:t,updateData:o,app:n})=>Ds(ae,{hidden:!vI(e,t,n),type:"button",icon:Ds(Lh,{theme:t.theme}),onClick:()=>o(null),title:`${f("labels.group")} \u2014 ${G("CtrlOrCmd+G")}`,"aria-label":f("labels.group"),visible:Ge(pp(e),t)})}),Xf=W({name:"ungroup",label:"labels.ungroup",icon:e=>Ds(_h,{theme:e.theme}),trackEvent:{category:"element"},perform:(e,t,o,n)=>{let r=mp(t),a=Vf(e);if(r.length===0)return{appState:t,elements:e,captureUpdate:Lc.EVENTUALLY};let i=[...e],s=[];i=i.map(d=>{n7(d)&&s.push(d.id);let u=h7(d.groupIds,t.selectedGroupIds);return u.length===d.groupIds.length?d:II(d,{groupIds:u})});let l=u7(t,pp(i),t,null),c=n.scene.getSelectedElements(t),m=new Set(c.filter(d=>d.frameId).map(d=>d.frameId));return i7(e).filter(d=>m.has(d.id)).forEach(d=>{d&&(i=d7(i,a7(i,d,t,a),d,n))}),l.selectedElementIds=Object.entries(l.selectedElementIds).reduce((d,[u,h])=>(h&&!s.includes(u)&&(d[u]=!0),d),{}),{appState:{...t,...l},elements:i,captureUpdate:Lc.IMMEDIATELY}},keyTest:e=>e.shiftKey&&e[up.CTRL_OR_CMD]&&e.key===up.G.toUpperCase(),predicate:(e,t)=>mp(t).length>0,PanelComponent:({elements:e,appState:t,updateData:o})=>Ds(ae,{type:"button",hidden:mp(t).length===0,icon:Ds(_h,{theme:t.theme}),onClick:()=>o(null),title:`${f("labels.ungroup")} \u2014 ${G("CtrlOrCmd+Shift+G")}`,"aria-label":f("labels.ungroup"),visible:Ge(pp(e),t)})});import T7 from"clsx";import{CaptureUpdateAction as PI}from"@orangecatai/element";import{invariant as C7}from"@orangecatai/common";import{COLOR_CHARCOAL_BLACK as x7,COLOR_VOICE_CALL as y7,COLOR_WHITE as hp,THEME as E7,UserIdleState as CI}from"@orangecatai/common";var gp=(e,t,o,n,r,a,i)=>{e.beginPath(),e.moveTo(t+a,o),e.lineTo(t+n-a,o),e.quadraticCurveTo(t+n,o,t+n,o+a),e.lineTo(t+n,o+r-a),e.quadraticCurveTo(t+n,o+r,t+n-a,o+r),e.lineTo(t+a,o+r),e.quadraticCurveTo(t,o+r,t,o+r-a),e.lineTo(t,o+a),e.quadraticCurveTo(t,o,t+a,o),e.closePath(),e.fill(),i&&(e.strokeStyle=i),e.stroke()};function w7(e){let t=0;if(e.length===0)return t;for(let o=0;o<e.length;o++){let n=e.charCodeAt(o);t=(t<<5)-t+n}return t}var ni=(e,t)=>`hsl(${Math.abs(w7(t?.id||e))%37*10}, 100%, 83%)`,kI=e=>{let t=e?.trim()?.codePointAt(0);return(t?String.fromCodePoint(t):"?").toUpperCase()},SI=({context:e,renderConfig:t,appState:o,normalizedWidth:n,normalizedHeight:r})=>{for(let[a,i]of t.remotePointerViewportCoords){let{x:s,y:l}=i,c=o.collaborators.get(a);s-=o.offsetLeft,l-=o.offsetTop;let m=11,p=14,d=s<0||s>n-m||l<0||l>r-p;s=Math.max(s,0),s=Math.min(s,n-m),l=Math.max(l,0),l=Math.min(l,r-p);let u=ni(a,c);e.save(),e.strokeStyle=u,e.fillStyle=u;let h=t.remotePointerUserStates.get(a),g=d||h===CI.IDLE||h===CI.AWAY;g&&(e.globalAlpha=.3),t.remotePointerButton.get(a)==="down"&&(e.beginPath(),e.arc(s,l,15,0,2*Math.PI,!1),e.lineWidth=3,e.strokeStyle="#ffffff88",e.stroke(),e.closePath(),e.beginPath(),e.arc(s,l,15,0,2*Math.PI,!1),e.lineWidth=1,e.strokeStyle=u,e.stroke(),e.closePath());let x=o.theme===E7.DARK?"#2f6330":y7,E=c?.isSpeaking;E&&(e.fillStyle=x,e.strokeStyle=x,e.lineWidth=10,e.lineJoin="round",e.beginPath(),e.moveTo(s,l),e.lineTo(s+0,l+14),e.lineTo(s+4,l+9),e.lineTo(s+11,l+8),e.closePath(),e.stroke(),e.fill()),e.fillStyle=hp,e.strokeStyle=hp,e.lineWidth=6,e.lineJoin="round",e.beginPath(),e.moveTo(s,l),e.lineTo(s+0,l+14),e.lineTo(s+4,l+9),e.lineTo(s+11,l+8),e.closePath(),e.stroke(),e.fill(),e.fillStyle=u,e.strokeStyle=u,e.lineWidth=2,e.lineJoin="round",e.beginPath(),g?(e.moveTo(s-1,l-1),e.lineTo(s-1,l+15),e.lineTo(s+5,l+10),e.lineTo(s+12,l+9),e.closePath(),e.fill()):(e.moveTo(s,l),e.lineTo(s+0,l+14),e.lineTo(s+4,l+9),e.lineTo(s+11,l+8),e.closePath(),e.fill(),e.stroke());let y=t.remotePointerUsernames.get(a)||"";if(!d&&y){e.font="600 12px sans-serif";let w=(E?s+0:s)+m/2,v=(E?l+0:l)+p+2,I=5,C=3,P=e.measureText(y),S=P.actualBoundingBoxDescent+P.actualBoundingBoxAscent,D=Math.max(S,12),_=w-1,k=v-1,M=P.width+2+I*2+2,B=D+2+C*2+2;if(e.roundRect?(e.beginPath(),e.roundRect(_,k,M,B,8),e.fillStyle=u,e.fill(),e.strokeStyle=hp,e.stroke(),E&&(e.beginPath(),e.roundRect(_-2,k-2,M+4,B+4,8),e.strokeStyle=x,e.stroke())):gp(e,_,k,M,B,8,hp),e.fillStyle=x7,e.fillText(y,w+I+1,v+C+P.actualBoundingBoxAscent+Math.floor((D-S)/2)+2),E){e.fillStyle=x;let O=8,N=8,z=5;e.fillRect(_+M+N,k+(B/2-O/2),2,O),e.fillRect(_+M+N+z,k+(B/2-O*2/2),2,O*2),e.fillRect(_+M+N+z*2,k+(B/2-O/2),2,O)}}e.restore(),e.closePath()}};import v7 from"clsx";import{useState as I7}from"react";import{jsx as MI}from"react/jsx-runtime";var Zf=({color:e,onClick:t,name:o,src:n,className:r})=>{let a=kI(o),[i,s]=I7(!1),l=!i&&n,c=l?void 0:{background:e};return MI("div",{className:v7("Avatar",r),style:c,onClick:t,children:l?MI("img",{className:"Avatar-img",src:n,alt:a,referrerPolicy:"no-referrer",onError:()=>s(!0)}):a})};import{jsx as Yn,jsxs as fp}from"react/jsx-runtime";var k7=W({name:"goToCollaborator",label:"Go to a collaborator",viewMode:!0,trackEvent:{category:"collab"},perform:(e,t,o)=>(C7(o,"actionGoToCollaborator: collaborator should be defined when actionGoToCollaborator is called"),!o.socketId||t.userToFollow?.socketId===o.socketId||o.isCurrentUser?{appState:{...t,userToFollow:null},captureUpdate:PI.EVENTUALLY}:{appState:{...t,userToFollow:{socketId:o.socketId,username:o.username||""},openMenu:t.openMenu==="canvas"?null:t.openMenu},captureUpdate:PI.EVENTUALLY}),PanelComponent:({updateData:e,data:t,appState:o})=>{let{socketId:n,collaborator:r,withName:a,isBeingFollowed:i}=t,s=ni(n,r),l=T7({"is-followed":i,"is-current-user":r.isCurrentUser===!0,"is-speaking":r.isSpeaking,"is-in-call":r.isInCall,"is-muted":r.isMuted}),c=r.isInCall?r.isSpeaking?fp("div",{className:"UserList__collaborator-status-icon-speaking-indicator",title:f("userList.hint.isSpeaking"),children:[Yn("div",{}),Yn("div",{}),Yn("div",{})]}):r.isMuted?Yn("div",{className:"UserList__collaborator-status-icon-microphone-muted",title:f("userList.hint.micMuted"),children:Jw}):Yn("div",{title:f("userList.hint.inCall"),children:qw}):null;return a?fp("div",{className:`dropdown-menu-item dropdown-menu-item-base UserList__collaborator ${l}`,style:{"--avatar-size":"1.5rem"},onClick:()=>e(r),children:[Yn(Zf,{color:s,onClick:()=>{},name:r.username||"",src:r.avatarUrl,className:l}),Yn("div",{className:"UserList__collaborator-name",children:r.username}),fp("div",{className:"UserList__collaborator-status-icons","aria-hidden":!0,children:[i&&Yn("div",{className:"UserList__collaborator-status-icon-is-followed",title:f("userList.hint.followStatus"),children:ls}),c]})]}):fp("div",{className:`UserList__collaborator UserList__collaborator--avatar-only ${l}`,children:[Yn(Zf,{color:s,onClick:()=>{e(r)},name:r.username||"",src:r.avatarUrl,className:l}),c&&Yn("div",{className:"UserList__collaborator-status-icon",children:c})]})}});import{LIBRARY_DISABLED_TYPES as S7,randomId as M7}from"@orangecatai/common";import{deepCopyElement as P7}from"@orangecatai/element";import{CaptureUpdateAction as jf}from"@orangecatai/element";var qf=W({name:"addToLibrary",trackEvent:{category:"element"},perform:(e,t,o,n)=>{let r=n.scene.getSelectedElements({selectedElementIds:t.selectedElementIds,includeBoundTextElement:!0,includeElementsInFrames:!0});for(let a of S7)if(r.some(i=>i.type===a))return{captureUpdate:jf.EVENTUALLY,appState:{...t,errorMessage:f(`errors.libraryElementTypeError.${a}`)}};return n.library.getLatestLibrary().then(a=>n.library.setLibrary([{id:M7(),status:"unpublished",elements:r.map(P7),created:Date.now()},...a])).then(()=>({captureUpdate:jf.EVENTUALLY,appState:{...t,toast:{message:f("toast.addedToLibrary")}}})).catch(a=>({captureUpdate:jf.EVENTUALLY,appState:{...t,errorMessage:a.message}}))},label:"labels.addToLibrary"});import{getNonDeletedElements as Rs}from"@orangecatai/element";import{isFrameLikeElement as A7}from"@orangecatai/element";import{updateFrameMembershipOfSelectedElements as L7}from"@orangecatai/element";import{KEYS as ea,arrayToMap as _7}from"@orangecatai/common";import{alignElements as D7}from"@orangecatai/element";import{CaptureUpdateAction as Ns}from"@orangecatai/element";import{getSelectedElementsByGroup as R7}from"@orangecatai/element";import{jsx as Fs}from"react/jsx-runtime";var ao=(e,t)=>{let o=t.scene.getSelectedElements(e);return R7(o,t.scene.getNonDeletedElementsMap(),e).length>1&&!o.some(n=>A7(n))},Bs=(e,t,o,n)=>{let r=o.scene.getSelectedElements(t),a=D7(r,n,o.scene,t),i=_7(a);return L7(e.map(s=>i.get(s.id)||s),t,o)},N7=W({name:"alignTop",label:"labels.alignTop",icon:Ch,trackEvent:{category:"element"},predicate:(e,t,o,n)=>ao(t,n),perform:(e,t,o,n)=>({appState:t,elements:Bs(e,t,n,{position:"start",axis:"y"}),captureUpdate:Ns.IMMEDIATELY}),keyTest:e=>e[ea.CTRL_OR_CMD]&&e.shiftKey&&e.key===ea.ARROW_UP,PanelComponent:({elements:e,appState:t,updateData:o,app:n})=>Fs(ae,{hidden:!ao(t,n),type:"button",icon:Ch,onClick:()=>o(null),title:`${f("labels.alignTop")} \u2014 ${G("CtrlOrCmd+Shift+Up")}`,"aria-label":f("labels.alignTop"),visible:Ge(Rs(e),t)})}),B7=W({name:"alignBottom",label:"labels.alignBottom",icon:kh,trackEvent:{category:"element"},predicate:(e,t,o,n)=>ao(t,n),perform:(e,t,o,n)=>({appState:t,elements:Bs(e,t,n,{position:"end",axis:"y"}),captureUpdate:Ns.IMMEDIATELY}),keyTest:e=>e[ea.CTRL_OR_CMD]&&e.shiftKey&&e.key===ea.ARROW_DOWN,PanelComponent:({elements:e,appState:t,updateData:o,app:n})=>Fs(ae,{hidden:!ao(t,n),type:"button",icon:kh,onClick:()=>o(null),title:`${f("labels.alignBottom")} \u2014 ${G("CtrlOrCmd+Shift+Down")}`,"aria-label":f("labels.alignBottom"),visible:Ge(Rs(e),t)})}),F7=W({name:"alignLeft",label:"labels.alignLeft",icon:Sh,trackEvent:{category:"element"},predicate:(e,t,o,n)=>ao(t,n),perform:(e,t,o,n)=>({appState:t,elements:Bs(e,t,n,{position:"start",axis:"x"}),captureUpdate:Ns.IMMEDIATELY}),keyTest:e=>e[ea.CTRL_OR_CMD]&&e.shiftKey&&e.key===ea.ARROW_LEFT,PanelComponent:({elements:e,appState:t,updateData:o,app:n})=>Fs(ae,{hidden:!ao(t,n),type:"button",icon:Sh,onClick:()=>o(null),title:`${f("labels.alignLeft")} \u2014 ${G("CtrlOrCmd+Shift+Left")}`,"aria-label":f("labels.alignLeft"),visible:Ge(Rs(e),t)})}),O7=W({name:"alignRight",label:"labels.alignRight",icon:Mh,trackEvent:{category:"element"},predicate:(e,t,o,n)=>ao(t,n),perform:(e,t,o,n)=>({appState:t,elements:Bs(e,t,n,{position:"end",axis:"x"}),captureUpdate:Ns.IMMEDIATELY}),keyTest:e=>e[ea.CTRL_OR_CMD]&&e.shiftKey&&e.key===ea.ARROW_RIGHT,PanelComponent:({elements:e,appState:t,updateData:o,app:n})=>Fs(ae,{hidden:!ao(t,n),type:"button",icon:Mh,onClick:()=>o(null),title:`${f("labels.alignRight")} \u2014 ${G("CtrlOrCmd+Shift+Right")}`,"aria-label":f("labels.alignRight"),visible:Ge(Rs(e),t)})}),z7=W({name:"alignVerticallyCentered",label:"labels.centerVertically",icon:Ph,trackEvent:{category:"element"},predicate:(e,t,o,n)=>ao(t,n),perform:(e,t,o,n)=>({appState:t,elements:Bs(e,t,n,{position:"center",axis:"y"}),captureUpdate:Ns.IMMEDIATELY}),PanelComponent:({elements:e,appState:t,updateData:o,app:n})=>Fs(ae,{hidden:!ao(t,n),type:"button",icon:Ph,onClick:()=>o(null),title:f("labels.centerVertically"),"aria-label":f("labels.centerVertically"),visible:Ge(Rs(e),t)})}),H7=W({name:"alignHorizontallyCentered",label:"labels.centerHorizontally",icon:Ah,trackEvent:{category:"element"},predicate:(e,t,o,n)=>ao(t,n),perform:(e,t,o,n)=>({appState:t,elements:Bs(e,t,n,{position:"center",axis:"x"}),captureUpdate:Ns.IMMEDIATELY}),PanelComponent:({elements:e,appState:t,updateData:o,app:n})=>Fs(ae,{hidden:!ao(t,n),type:"button",icon:Ah,onClick:()=>o(null),title:f("labels.centerHorizontally"),"aria-label":f("labels.centerHorizontally"),visible:Ge(Rs(e),t)})});import{getNonDeletedElements as AI}from"@orangecatai/element";import{isFrameLikeElement as G7}from"@orangecatai/element";import{CODES as LI,KEYS as _I,arrayToMap as U7}from"@orangecatai/common";import{updateFrameMembershipOfSelectedElements as W7}from"@orangecatai/element";import{distributeElements as Y7}from"@orangecatai/element";import{CaptureUpdateAction as DI}from"@orangecatai/element";import{getSelectedElementsByGroup as $7}from"@orangecatai/element";import{jsx as BI}from"react/jsx-runtime";var RI=(e,t)=>{let o=t.scene.getSelectedElements(e);return $7(o,t.scene.getNonDeletedElementsMap(),e).length>2&&!o.some(n=>G7(n))},NI=(e,t,o,n)=>{let r=o.scene.getSelectedElements(t),a=Y7(r,o.scene.getNonDeletedElementsMap(),n,t,o.scene),i=U7(a);return W7(e.map(s=>i.get(s.id)||s),t,o)},V7=W({name:"distributeHorizontally",label:"labels.distributeHorizontally",trackEvent:{category:"element"},perform:(e,t,o,n)=>({appState:t,elements:NI(e,t,n,{space:"between",axis:"x"}),captureUpdate:DI.IMMEDIATELY}),keyTest:e=>!e[_I.CTRL_OR_CMD]&&e.altKey&&e.code===LI.H,PanelComponent:({elements:e,appState:t,updateData:o,app:n})=>BI(ae,{hidden:!RI(t,n),type:"button",icon:JE,onClick:()=>o(null),title:`${f("labels.distributeHorizontally")} \u2014 ${G("Alt+H")}`,"aria-label":f("labels.distributeHorizontally"),visible:Ge(AI(e),t)})}),K7=W({name:"distributeVertically",label:"labels.distributeVertically",trackEvent:{category:"element"},perform:(e,t,o,n)=>({appState:t,elements:NI(e,t,n,{space:"between",axis:"y"}),captureUpdate:DI.IMMEDIATELY}),keyTest:e=>!e[_I.CTRL_OR_CMD]&&e.altKey&&e.code===LI.V,PanelComponent:({elements:e,appState:t,updateData:o,app:n})=>BI(ae,{hidden:!RI(t,n),type:"button",icon:QE,onClick:()=>o(null),title:`${f("labels.distributeVertically")} \u2014 ${G("Alt+V")}`,"aria-label":f("labels.distributeVertically"),visible:Ge(AI(e),t)})});import{getNonDeletedElements as X7}from"@orangecatai/element";import{bindOrUnbindBindingElements as Z7}from"@orangecatai/element";import{getCommonBoundingBox as FI}from"@orangecatai/element";import{newElementWith as j7}from"@orangecatai/element";import{deepCopyElement as q7}from"@orangecatai/element";import{resizeMultipleElements as J7}from"@orangecatai/element";import{isArrowElement as OI,isElbowArrow as Q7}from"@orangecatai/element";import{updateFrameMembershipOfSelectedElements as zI}from"@orangecatai/element";import{CODES as HI,KEYS as eN,arrayToMap as tN}from"@orangecatai/common";import{CaptureUpdateAction as GI}from"@orangecatai/element";var Jf=W({name:"flipHorizontal",label:"labels.flipHorizontal",icon:ov,trackEvent:{category:"element"},perform:(e,t,o,n)=>({elements:zI(UI(e,n.scene.getNonDeletedElementsMap(),t,"horizontal",n),t,n),appState:t,captureUpdate:GI.IMMEDIATELY}),keyTest:e=>e.shiftKey&&e.code===HI.H}),Qf=W({name:"flipVertical",label:"labels.flipVertical",icon:tv,trackEvent:{category:"element"},perform:(e,t,o,n)=>({elements:zI(UI(e,n.scene.getNonDeletedElementsMap(),t,"vertical",n),t,n),appState:t,captureUpdate:GI.IMMEDIATELY}),keyTest:e=>e.shiftKey&&e.code===HI.V&&!e[eN.CTRL_OR_CMD]}),UI=(e,t,o,n,r)=>{let a=de(X7(e),o,{includeBoundTextElement:!0,includeElementsInFrames:!0}),i=oN(a,t,n,r),s=tN(i);return e.map(l=>s.get(l.id)||l)},oN=(e,t,o,n)=>{if(e.every(d=>OI(d)&&(d.startBinding||d.endBinding)))return e.map(d=>{let u=d;return j7(u,{startArrowhead:u.endArrowhead,endArrowhead:u.startArrowhead})});let{midX:r,midY:a}=FI(e);J7(e,t,"nw",n.scene,new Map(Array.from(t.values()).map(d=>[d.id,q7(d)])),{flipByX:o==="horizontal",flipByY:o==="vertical",shouldResizeFromCenter:!0,shouldMaintainAspectRatio:!0}),Z7(e.filter(OI),n.scene,n.state);let{elbowArrows:i,otherElements:s}=e.reduce((d,u)=>Q7(u)?{...d,elbowArrows:d.elbowArrows.concat(u)}:{...d,otherElements:d.otherElements.concat(u)},{elbowArrows:[],otherElements:[]}),{midX:l,midY:c}=FI(e),[m,p]=[r-l,a-c];return s.forEach(d=>n.scene.mutateElement(d,{x:d.x+m,y:d.y+p})),i.forEach(d=>n.scene.mutateElement(d,{x:d.x+m,y:d.y+p})),e};import{isTextElement as nN}from"@orangecatai/element";import{getTextFromElements as rN}from"@orangecatai/element";import{CODES as aN,KEYS as WI,isFirefox as iN}from"@orangecatai/common";import{CaptureUpdateAction as _o}from"@orangecatai/element";var Os=W({name:"copy",label:"labels.copy",icon:tc,trackEvent:{category:"element"},perform:async(e,t,o,n)=>{let r=n.scene.getSelectedElements({selectedElementIds:t.selectedElementIds,includeBoundTextElement:!0,includeElementsInFrames:!0});try{await ip(r,n.files,o)}catch(a){return{captureUpdate:_o.EVENTUALLY,appState:{...t,errorMessage:a.message}}}return{captureUpdate:_o.EVENTUALLY}},keyTest:void 0}),eb=W({name:"paste",label:"labels.paste",trackEvent:{category:"element"},perform:async(e,t,o,n)=>{let r;try{r=await mI()}catch(a){return a.name==="AbortError"||a.name==="NotAllowedError"?!1:(console.error(`actionPaste ${a.name}: ${a.message}`),iN?{captureUpdate:_o.EVENTUALLY,appState:{...t,errorMessage:f("hints.firefox_clipboard_write")}}:{captureUpdate:_o.EVENTUALLY,appState:{...t,errorMessage:f("errors.asyncPasteFailedOnRead")}})}try{n.pasteFromClipboard(cI({types:r}))}catch(a){return console.error(a),{captureUpdate:_o.EVENTUALLY,appState:{...t,errorMessage:f("errors.asyncPasteFailedOnParse")}}}return{captureUpdate:_o.EVENTUALLY}},keyTest:void 0}),bp=W({name:"cut",label:"labels.cut",icon:Ow,trackEvent:{category:"element"},perform:(e,t,o,n)=>(Os.perform(e,t,o,n),dc.perform(e,t,null,n)),keyTest:e=>e[WI.CTRL_OR_CMD]&&e.key===WI.X}),xp=W({name:"copyAsSvg",label:"labels.copyAsSvg",icon:nv,trackEvent:{category:"element"},perform:async(e,t,o,n)=>{if(!n.canvas)return{captureUpdate:_o.EVENTUALLY};let{exportedElements:r,exportingFrame:a}=Qa(e,t,!0);try{await ei("clipboard-svg",r,t,n.files,{...t,exportingFrame:a,name:n.getName()});let i=n.scene.getSelectedElements({selectedElementIds:t.selectedElementIds,includeBoundTextElement:!0,includeElementsInFrames:!0});return{appState:{toast:{message:f("toast.copyToClipboardAsSvg",{exportSelection:i.length?f("toast.selection"):f("toast.canvas"),exportColorScheme:t.exportWithDarkMode?f("buttons.darkMode"):f("buttons.lightMode")})}},captureUpdate:_o.EVENTUALLY}}catch(i){return console.error(i),{appState:{errorMessage:i.message},captureUpdate:_o.EVENTUALLY}}},predicate:e=>ap&&e.length>0,keywords:["svg","clipboard","copy"]}),yp=W({name:"copyAsPng",label:"labels.copyAsPng",icon:rv,trackEvent:{category:"element"},perform:async(e,t,o,n)=>{if(!n.canvas)return{captureUpdate:_o.EVENTUALLY};let r=n.scene.getSelectedElements({selectedElementIds:t.selectedElementIds,includeBoundTextElement:!0,includeElementsInFrames:!0}),{exportedElements:a,exportingFrame:i}=Qa(e,t,!0);try{return await ei("clipboard",a,t,n.files,{...t,exportingFrame:i,name:n.getName()}),{appState:{...t,toast:{message:f("toast.copyToClipboardAsPng",{exportSelection:r.length?f("toast.selection"):f("toast.canvas"),exportColorScheme:t.exportWithDarkMode?f("buttons.darkMode"):f("buttons.lightMode")})}},captureUpdate:_o.EVENTUALLY}}catch(s){return console.error(s),{appState:{...t,errorMessage:s.message},captureUpdate:_o.EVENTUALLY}}},predicate:e=>Ps&&e.length>0,keyTest:e=>e.code===aN.C&&e.altKey&&e.shiftKey,keywords:["png","clipboard","copy"]}),Ep=W({name:"copyText",label:"labels.copyText",trackEvent:{category:"element"},perform:(e,t,o,n)=>{let r=n.scene.getSelectedElements({selectedElementIds:t.selectedElementIds,includeBoundTextElement:!0});try{hn(rN(r))}catch{throw new Error(f("errors.copyToSystemClipboardFailed"))}return{captureUpdate:_o.EVENTUALLY}},predicate:(e,t,o,n)=>ap&&n.scene.getSelectedElements({selectedElementIds:t.selectedElementIds,includeBoundTextElement:!0}).some(nN),keywords:["text","clipboard","copy"]});import{CODES as sN,KEYS as lN}from"@orangecatai/common";import{CaptureUpdateAction as cN}from"@orangecatai/element";var zs=W({name:"gridMode",icon:cv,keywords:["snap"],label:"labels.toggleGrid",viewMode:!0,trackEvent:{category:"canvas",predicate:e=>e.gridModeEnabled},perform(e,t){return{appState:{...t,gridModeEnabled:!this.checked(t),objectsSnapModeEnabled:!1},captureUpdate:cN.EVENTUALLY}},checked:e=>e.gridModeEnabled,predicate:(e,t,o)=>o.gridModeEnabled===void 0,keyTest:e=>e[lN.CTRL_OR_CMD]&&e.code===sN.QUOTE});import{CODES as dN,KEYS as mN}from"@orangecatai/common";import{CaptureUpdateAction as pN}from"@orangecatai/element";var ta=W({name:"zenMode",label:"buttons.zenMode",icon:iv,viewMode:!0,trackEvent:{category:"canvas",predicate:e=>!e.zenModeEnabled},perform(e,t){return{appState:{...t,zenModeEnabled:!this.checked(t)},captureUpdate:pN.EVENTUALLY}},checked:e=>e.zenModeEnabled,predicate:(e,t,o,n)=>n.editorInterface.formFactor!=="phone"&&typeof o.zenModeEnabled>"u",keyTest:e=>!e[mN.CTRL_OR_CMD]&&e.altKey&&e.code===dN.Z});import{CODES as uN,KEYS as gN}from"@orangecatai/common";import{CaptureUpdateAction as hN}from"@orangecatai/element";var _c=W({name:"objectsSnapMode",label:"buttons.objectsSnapMode",icon:av,viewMode:!1,trackEvent:{category:"canvas",predicate:e=>!e.objectsSnapModeEnabled},perform(e,t){return{appState:{...t,objectsSnapModeEnabled:!this.checked(t),gridModeEnabled:!1},captureUpdate:hN.EVENTUALLY}},checked:e=>e.objectsSnapModeEnabled,predicate:(e,t,o)=>typeof o.objectsSnapModeEnabled>"u",keyTest:e=>!e[gN.CTRL_OR_CMD]&&e.altKey&&e.code===uN.S});import{CODES as fN,KEYS as bN}from"@orangecatai/common";import{CaptureUpdateAction as xN}from"@orangecatai/element";var oa=W({name:"stats",label:"stats.fullTitle",icon:ev,viewMode:!0,trackEvent:{category:"menu"},keywords:["edit","attributes","customize"],perform(e,t){return{appState:{...t,stats:{...t.stats,open:!this.checked(t)}},captureUpdate:xN.EVENTUALLY}},checked:e=>e.stats.open,keyTest:e=>!e[bN.CTRL_OR_CMD]&&e.altKey&&e.code===fN.SLASH});import{BOUND_TEXT_PADDING as YI,ROUNDNESS as $I,TEXT_ALIGN as XI,VERTICAL_ALIGN as ZI,arrayToMap as jI,getFontString as yN}from"@orangecatai/common";import{getOriginalContainerHeightFromCache as EN,isBoundToContainer as VI,resetOriginalContainerCache as wN,updateOriginalContainerCache as vN}from"@orangecatai/element";import{computeBoundTextPosition as IN,computeContainerDimensionForBoundText as KI,getBoundTextElement as qI,redrawTextBoundingBox as JI}from"@orangecatai/element";import{hasBoundTextElement as TN,isArrowElement as CN,isTextBindableContainer as tb,isTextElement as Dc,isUsingAdaptiveRadius as kN}from"@orangecatai/element";import{measureText as SN}from"@orangecatai/element";import{syncMovedIndices as QI}from"@orangecatai/element";import{newElement as MN}from"@orangecatai/element";import{CaptureUpdateAction as ob}from"@orangecatai/element";var nb=W({name:"unbindText",label:"labels.unbindText",trackEvent:{category:"element"},predicate:(e,t,o,n)=>n.scene.getSelectedElements(t).some(a=>TN(a)),perform:(e,t,o,n)=>{let r=n.scene.getSelectedElements(t),a=n.scene.getNonDeletedElementsMap();return r.forEach(i=>{let s=qI(i,a);if(s){let{width:l,height:c}=SN(s.originalText,yN(s),s.lineHeight),m=EN(i.id);wN(i.id);let{x:p,y:d}=IN(i,s,a);n.scene.mutateElement(s,{containerId:null,width:l,height:c,text:s.originalText,x:p,y:d}),n.scene.mutateElement(i,{boundElements:i.boundElements?.filter(u=>u.id!==s.id),height:m||i.height})}}),{elements:e,appState:t,captureUpdate:ob.IMMEDIATELY}}}),rb=W({name:"bindText",label:"labels.bindText",trackEvent:{category:"element"},predicate:(e,t,o,n)=>{let r=n.scene.getSelectedElements(t);if(r.length===2){let a=Dc(r[0])||Dc(r[1]),i;if(tb(r[0])?i=r[0]:tb(r[1])&&(i=r[1]),a&&i&&qI(i,n.scene.getNonDeletedElementsMap())===null)return!0}return!1},perform:(e,t,o,n)=>{let r=n.scene.getSelectedElements(t),a,i;Dc(r[0])&&tb(r[1])?(a=r[0],i=r[1]):(a=r[1],i=r[0]),n.scene.mutateElement(a,{containerId:i.id,verticalAlign:ZI.MIDDLE,textAlign:XI.CENTER,autoResize:!0,angle:CN(i)?0:i?.angle??0}),n.scene.mutateElement(i,{boundElements:(i.boundElements||[]).concat({type:"text",id:a.id})});let s=i.height;return JI(a,i,n.scene),vN(i.id,s),{elements:PN(e,i,a),appState:{...t,selectedElementIds:{[i.id]:!0}},captureUpdate:ob.IMMEDIATELY}}}),PN=(e,t,o)=>{let n=e.slice(),r=n.findIndex(i=>i.id===o.id);n.splice(r,1);let a=n.findIndex(i=>i.id===t.id);return n.splice(a+1,0,o),QI(n,jI([t,o])),n},AN=(e,t,o)=>{let n=e.slice(),r=n.findIndex(i=>i.id===t.id);n.splice(r,1);let a=n.findIndex(i=>i.id===o.id);return n.splice(a,0,t),QI(n,jI([t,o])),n},eT=W({name:"wrapTextInContainer",label:"labels.createContainerFromText",trackEvent:{category:"element"},predicate:(e,t,o,n)=>{let r=n.scene.getSelectedElements(t),a=r.some(i=>Dc(i)&&!VI(i));return r.length>0&&a},perform:(e,t,o,n)=>{let r=n.scene.getSelectedElements(t),a=e.slice(),i={};for(let s of r)if(Dc(s)&&!VI(s)){let l=MN({type:"rectangle",backgroundColor:t.currentItemBackgroundColor,boundElements:[...s.boundElements||[],{id:s.id,type:"text"}],angle:s.angle,fillStyle:t.currentItemFillStyle,strokeColor:t.currentItemStrokeColor,roughness:t.currentItemRoughness,strokeWidth:t.currentItemStrokeWidth,strokeStyle:t.currentItemStrokeStyle,roundness:t.currentItemRoundness==="round"?{type:kN("rectangle")?$I.ADAPTIVE_RADIUS:$I.PROPORTIONAL_RADIUS}:null,opacity:100,locked:!1,x:s.x-YI,y:s.y-YI,width:KI(s.width,"rectangle"),height:KI(s.height,"rectangle"),groupIds:s.groupIds,frameId:s.frameId});if(s.boundElements?.length){let c=s.boundElements.filter(p=>p.type==="arrow").map(p=>p.id);a.filter(p=>c.includes(p.id)).forEach(p=>{let d=p.startBinding,u=p.endBinding;d?.elementId===s.id&&(d={...d,elementId:l.id}),u?.elementId===s.id&&(u={...u,elementId:l.id}),(d||u)&&n.scene.mutateElement(p,{startBinding:d,endBinding:u})})}n.scene.mutateElement(s,{containerId:l.id,verticalAlign:ZI.MIDDLE,boundElements:null,textAlign:XI.CENTER,autoResize:!0}),JI(s,l,n.scene),a=AN([...a,l],l,s),i[l.id]=!0}return{elements:a,appState:{...t,selectedElementIds:i},captureUpdate:ob.IMMEDIATELY}}});import{isEmbeddableElement as KN}from"@orangecatai/element";import{KEYS as dT}from"@orangecatai/common";import{CaptureUpdateAction as XN}from"@orangecatai/element";import{pointFrom as rT}from"@orangecatai/math";import LN from"clsx";import{useCallback as tT,useEffect as oT,useLayoutEffect as _N,useRef as DN,useState as RN}from"react";import{EVENT as ab,HYPERLINK_TOOLTIP_DELAY as NN,KEYS as wp}from"@orangecatai/common";import{getElementAbsoluteCoords as db}from"@orangecatai/element";import{hitElementBoundingBox as BN}from"@orangecatai/element";import{isElementLink as FN}from"@orangecatai/element";import{getEmbedLink as ON,embeddableURLValidator as zN}from"@orangecatai/element";import{sceneCoordsToViewportCoords as aT,viewportCoordsToSceneCoords as HN,wrapEvent as GN,isLocalLink as UN,normalizeLink as ib}from"@orangecatai/common";import{isEmbeddableElement as sb}from"@orangecatai/element";import{jsx as Hs,jsxs as nT}from"react/jsx-runtime";var mb=380,WN=42,lb=5,iT=85,YN=500,cb=!1,vp=new Map,sT=({element:e,scene:t,setAppState:o,onLinkOpen:n,setToast:r,updateEmbedValidationStatus:a})=>{let i=t.getNonDeletedElementsMap(),s=$o(),l=Hn(),c=Te(),m=e.link||"",[p,d]=RN(m),u=DN(null),h=s.showHyperlinkPopup==="editor",g=tT(()=>{if(!u.current)return;let v=ib(u.current.value)||null;if(!e.link&&v&&be("hyperlink","create"),sb(e)){if(s.activeEmbeddable?.element===e&&o({activeEmbeddable:null}),!v){t.mutateElement(e,{link:null}),a(e,!1);return}if(!zN(v,l.validateEmbeddable))v&&r({message:f("toast.unableToEmbed"),closable:!0}),e.link&&vp.set(e.id,e.link),t.mutateElement(e,{link:v}),a(e,!1);else{let{width:I,height:C}=e,P=ON(v);P?.error instanceof URIError&&r({message:f("toast.unrecognizedLinkFormat"),closable:!0});let S=P?P.intrinsicSize.w/P.intrinsicSize.h:1,D=vp.get(e.id)!==e.link;t.mutateElement(e,{...D?{width:P?.type==="video"?I>C?I:C*S:I,height:P?.type==="video"&&I>C?I/S:C}:{},link:v}),a(e,!0),vp.has(e.id)&&vp.delete(e.id)}}else t.mutateElement(e,{link:v})},[e,t,r,l.validateEmbeddable,s.activeEmbeddable,o,a]);_N(()=>()=>{g()},[g]),oT(()=>{h&&u?.current&&!(c.formFactor==="phone"||c.isTouchScreen)&&u.current.select()},[h,c.formFactor,c.isTouchScreen]),oT(()=>{let v=null,I=C=>{if(h)return;v&&clearTimeout(v),VN(e,i,s,rT(C.clientX,C.clientY))&&(v=window.setTimeout(()=>{o({showHyperlinkPopup:!1})},YN))};return window.addEventListener(ab.POINTER_MOVE,I,!1),()=>{window.removeEventListener(ab.POINTER_MOVE,I,!1),v&&clearTimeout(v)}},[s,e,h,o,i]);let x=tT(()=>{be("hyperlink","delete"),t.mutateElement(e,{link:null}),o({showHyperlinkPopup:!1})},[o,e,t]),E=()=>{be("hyperlink","edit","popup-ui"),o({showHyperlinkPopup:"editor"})},{x:y,y:w}=lT(e,s,i);return s.contextMenu||s.selectedElementsAreBeingDragged||s.resizingElement||s.isRotating||s.openMenu||s.viewModeEnabled?null:nT("div",{className:"excalidraw-hyperlinkContainer",style:{top:`${w}px`,left:`${y}px`,width:mb,padding:lb},children:[h?Hs("input",{className:LN("excalidraw-hyperlinkContainer-input"),placeholder:f("labels.link.hint"),ref:u,value:p,onChange:v=>d(v.target.value),autoFocus:!0,onKeyDown:v=>{v.stopPropagation(),v[wp.CTRL_OR_CMD]&&v.key===wp.K&&v.preventDefault(),(v.key===wp.ENTER||v.key===wp.ESCAPE)&&(g(),o({showHyperlinkPopup:"info"}))}}):e.link?Hs("a",{href:ib(e.link||""),className:"excalidraw-hyperlinkContainer-link",target:UN(e.link)?"_self":"_blank",onClick:v=>{if(e.link&&n){let I=GN(ab.EXCALIDRAW_LINK,v.nativeEvent);n({...e,link:ib(e.link)},I),I.defaultPrevented&&v.preventDefault()}},rel:"noopener noreferrer",children:e.link}):Hs("div",{className:"excalidraw-hyperlinkContainer-link",children:f("labels.link.empty")}),nT("div",{className:"excalidraw-hyperlinkContainer__buttons",children:[!h&&Hs(ae,{type:"button",title:f("buttons.edit"),"aria-label":f("buttons.edit"),label:f("buttons.edit"),onClick:E,className:"excalidraw-hyperlinkContainer--edit",icon:Bn}),Hs(ae,{type:"button",title:f("labels.linkToElement"),"aria-label":f("labels.linkToElement"),label:f("labels.linkToElement"),onClick:()=>{o({openDialog:{name:"elementLinkSelector",sourceElementId:e.id}})},icon:Cm}),m&&!sb(e)&&Hs(ae,{type:"button",title:f("buttons.remove"),"aria-label":f("buttons.remove"),label:f("buttons.remove"),onClick:x,className:"excalidraw-hyperlinkContainer--remove",icon:Ut})]})]})},lT=(e,t,o)=>{let[n,r]=db(e,o),{x:a,y:i}=aT({sceneX:n+e.width/2,sceneY:r},t),s=a-t.offsetLeft-mb/2,l=i-t.offsetTop-iT;return{x:s,y:l}},pb=(e,t)=>{let o=de(e,t);return sb(o[0])?"labels.link.editEmbed":o[0]?.link?"labels.link.edit":"labels.link.create"},Rc=null,cT=(e,t,o)=>{Rc&&clearTimeout(Rc),Rc=window.setTimeout(()=>$N(e,t,o),NN)},$N=(e,t,o)=>{if(!e.link)return;let n=Ts();n.classList.add("excalidraw-tooltip--visible"),n.style.maxWidth="20rem",n.textContent=FN(e.link)?f("labels.link.goToElement"):e.link;let[r,a,i,s]=db(e,o),[l,c,m,p]=sE([r,a,i,s],e.angle,t),d=aT({sceneX:l,sceneY:c},t);Mf(n,{left:d.x,top:d.y,width:m,height:p},"top"),be("hyperlink","tooltip","link-icon"),cb=!0},ub=()=>{Rc&&clearTimeout(Rc),cb&&(cb=!1,Ts().classList.remove("excalidraw-tooltip--visible"))},VN=(e,t,o,[n,r])=>{let{x:a,y:i}=HN({clientX:n,clientY:r},o),s=15/o.zoom.value;if(BN(rT(a,i),e,t))return!1;let[l,c,m]=db(e,t);if(a>=l&&a<=m&&i>=c-iT&&i<=c)return!1;let{x:p,y:d}=lT(e,o,t);return!(n>=p-s&&n<=p+mb+lb*2+s&&r>=d-s&&r<=d+s+lb*2+WN)};import{jsx as ZN}from"react/jsx-runtime";var Nc=W({name:"hyperlink",label:(e,t)=>pb(e,t),icon:rc,perform:(e,t)=>t.showHyperlinkPopup==="editor"?!1:{elements:e,appState:{...t,showHyperlinkPopup:"editor",openMenu:null},captureUpdate:XN.IMMEDIATELY},trackEvent:{category:"hyperlink",action:"click"},keyTest:e=>e[dT.CTRL_OR_CMD]&&e.key===dT.K,predicate:(e,t)=>de(e,t).length===1,PanelComponent:({elements:e,appState:t,updateData:o})=>{let n=de(e,t);return ZN(ae,{type:"button",icon:rc,"aria-label":f(pb(e,t)),title:`${KN(e[0])?f("labels.link.labelEmbed"):f("labels.link.label")} - ${G("CtrlOrCmd+K")}`,onClick:()=>o(null),selected:n.length===1&&!!n[0].link})}});import{KEYS as mT,arrayToMap as hb,randomId as jN}from"@orangecatai/common";import{elementsAreInSameGroup as qN,newElementWith as pT,selectGroupsFromGivenElements as uT}from"@orangecatai/element";import{CaptureUpdateAction as gT}from"@orangecatai/element";var gb=e=>e.every(t=>!t.locked),Bc=W({name:"toggleElementLock",label:(e,t,o)=>{let n=o.scene.getSelectedElements({selectedElementIds:t.selectedElementIds,includeBoundTextElement:!1});return gb(n)?"labels.elementLock.lock":"labels.elementLock.unlock"},icon:(e,t)=>{let o=de(t,e);return gb(o)?ji:Wa},trackEvent:{category:"element"},predicate:(e,t,o,n)=>{let r=n.scene.getSelectedElements(t);return r.length>0&&!r.some(a=>a.locked&&a.frameId)},perform:(e,t,o,n)=>{let r=n.scene.getSelectedElements({selectedElementIds:t.selectedElementIds,includeBoundTextElement:!0,includeElementsInFrames:!0});if(!r.length)return!1;let a=gb(r),i=hb(r),s=r.length>1&&qN(r),c=r.length===1||s?null:jN(),m={...t.lockedMultiSelections};if(a)m={...t.lockedMultiSelections,...c?{[c]:!0}:{}};else if(s){let E=r[0].groupIds.at(-1);delete m[E]}let p=e.map(E=>{if(!i.has(E.id))return E;let y=E.groupIds;return a?c&&(y=[...y,c]):y=y.filter(w=>!t.lockedMultiSelections[w]),pT(E,{locked:a,groupIds:y.length!==E.groupIds.length?y:E.groupIds})}),d=hb(p),u=a?{}:Object.fromEntries(r.map(E=>[E.id,!0])),h=r.map(E=>d.get(E.id)||E),g=a?{}:uT(h,t),x=a?c||(s?r[0].groupIds.at(-1):r[0].id):null;return{elements:p,appState:{...t,selectedElementIds:u,selectedGroupIds:g,selectedLinearElement:a?null:t.selectedLinearElement,lockedMultiSelections:m,activeLockedId:x},captureUpdate:gT.IMMEDIATELY}},keyTest:(e,t,o,n)=>e.key.toLocaleLowerCase()===mT.L&&e[mT.CTRL_OR_CMD]&&e.shiftKey&&n.scene.getSelectedElements({selectedElementIds:t.selectedElementIds,includeBoundTextElement:!1}).length>0}),hT=W({name:"unlockAllElements",trackEvent:{category:"canvas"},viewMode:!1,icon:Wa,predicate:(e,t)=>de(e,t).length===0&&e.some(n=>n.locked),perform:(e,t)=>{let o=e.filter(i=>i.locked),n=e.map(i=>{if(i.locked){let s=i.groupIds.filter(l=>!t.lockedMultiSelections[l]);return pT(i,{locked:!1,groupIds:i.groupIds.length!==s.length?s:i.groupIds})}return i}),r=hb(n),a=o.map(i=>r.get(i.id)||i);return{elements:n,appState:{...t,selectedElementIds:Object.fromEntries(o.map(i=>[i.id,!0])),selectedGroupIds:uT(a,t),lockedMultiSelections:{},activeLockedId:null},captureUpdate:gT.IMMEDIATELY}},label:"labels.elementLock.unlockAll"});import{isElbowArrow as Fz,isLinearElement as Oz,isLineElement as al}from"@orangecatai/element";import{arrayToMap as zz,invariant as I0}from"@orangecatai/common";import{toggleLinePolygonState as Hz,CaptureUpdateAction as O5}from"@orangecatai/element";import p5 from"clsx";import SO from"fuzzy";import{useEffect as qp,useRef as u5,useMemo as MO,useState as jp}from"react";import{DEFAULT_SIDEBAR as c5,EVENT as Qp,KEYS as yn,capitalizeString as PO,isWritableElement as AO}from"@orangecatai/common";import{CaptureUpdateAction as D9}from"@orangecatai/element";import{useEffect as zc,useMemo as fT,useRef as yb,useState as JN}from"react";import{getLinearElementSubType as Ws,updateElbowArrowPoints as QN}from"@orangecatai/element";import{pointFrom as Tp,pointRotateRads as e9}from"@orangecatai/math";import{hasBoundTextElement as t9,isArrowBoundToElement as o9,isArrowElement as n9,isElbowArrow as r9,isLinearElement as Ib,isUsingAdaptiveRadius as a9}from"@orangecatai/element";import{getCommonBoundingBox as i9,getElementAbsoluteCoords as s9}from"@orangecatai/element";import{getBoundTextElement as wT,getBoundTextMaxHeight as l9,getBoundTextMaxWidth as c9,redrawTextBoundingBox as d9}from"@orangecatai/element";import{wrapText as m9}from"@orangecatai/element";import{assertNever as p9,CLASSES as u9,getFontString as fb,isProdEnv as g9,mapFind as h9,reduceToCommonValue as f9,updateActiveTool as bT}from"@orangecatai/common";import{measureText as xT}from"@orangecatai/element";import{LinearElementEditor as b9}from"@orangecatai/element";import{newArrowElement as bb,newElement as x9,newLinearElement as y9}from"@orangecatai/element";import{ShapeCache as E9}from"@orangecatai/element";import{updateBindings as w9}from"@orangecatai/element";import{jsx as vb}from"react/jsx-runtime";var v9=8,I9=10,Fc=["rectangle","diamond","ellipse"],Oc=["line","sharpArrow","curvedArrow","elbowArrow"],T9=new Set(Fc),C9=new Set(Oc),Ys=e=>T9.has(e),kp=e=>e==="arrow"||C9.has(e),bn=Pe(null),Hc=new Map,Gc=new Map,k9=({app:e})=>{let t=e.scene.getSelectedElements(e.state),o=yb(null);return zc(()=>{if(t.length===0){e.updateEditorAtom(bn,null);return}let n=$s(t);n&&!o.current?o.current=n:(o.current&&!n||o.current&&n!==o.current)&&(e.updateEditorAtom(bn,null),o.current=null)},[t,e]),zc(()=>()=>{Hc.clear(),Gc.clear()},[]),vb(S9,{app:e,elements:t})},S9=({app:e,elements:t})=>{let o=$s(t),n=fT(()=>o==="generic"?IT(t):[],[o,t]),r=fT(()=>o==="linear"?wb(t):[],[o,t]),a=o==="generic"?n.every(p=>p.type===n[0].type):o==="linear"?r.every(p=>Ws(p)===Ws(r[0])):!1,[i,s]=JN({x:0,y:0}),l=yb(""),c=yb(null);zc(()=>{let p=[...n,...r].sort((x,E)=>x.id.localeCompare(E.id)),d=`
|
|
7
|
-
${e.state.scrollX}${e.state.scrollY}${e.state.offsetTop}${e.state.offsetLeft}${e.state.zoom.value}${p.map(x=>x.id).join(",")}`;if(d===l.current)return;l.current=d;let u;if(p.length===1){let[x,,,E,y,w]=s9(p[0],e.scene.getNonDeletedElementsMap());u=e9(Tp(x,E),Tp(y,w),p[0].angle)}else{let{minX:x,maxY:E}=i9(p);u=Tp(x,E)}let{x:h,y:g}=CT({sceneX:u[0],sceneY:u[1]},e.state);s({x:h,y:g})},[n,r,e.scene,e.state]),zc(()=>{for(let p of r){let d=Eb(p.id,_9(p));Gc.has(d)||Gc.set(d,p)}},[r]),zc(()=>{for(let p of n)if(!Hc.has(p.id)){let d=wT(p,e.scene.getNonDeletedElementsMap());d&&Hc.set(p.id,{fontSize:d.fontSize})}},[n,e.scene]);let m=o==="linear"?[["line",es],["sharpArrow",ds],["curvedArrow",ps],["elbowArrow",ms]]:o==="generic"?[["rectangle",qi],["diamond",Ji],["ellipse",Qi]]:[];return vb("div",{ref:c,tabIndex:-1,style:{position:"absolute",top:`${i.y+(I9+8)*e.state.zoom.value-e.state.offsetTop}px`,left:`${i.x-e.state.offsetLeft-v9}px`,zIndex:2},className:u9.CONVERT_ELEMENT_TYPE_POPUP,children:m.map(([p,d])=>{let u=a&&(o==="generic"&&n[0].type===p||o==="linear"&&Ws(r[0])===p);return vb(ae,{className:"Shape",type:"radio",icon:d,checked:u,name:"convertElementType-option",title:p,keyBindingLabel:"","aria-label":p,"data-testid":`toolbar-${p}`,onChange:()=>{e.state.activeTool.type!==p&&be("convertElementType",p,"ui"),Tb(e,{conversionType:o,nextType:p}),c.current?.focus()}},`${t[0].id}${t[0].version}_${p}`)})})},M9=(e,t,o)=>{let n=c9(e,t),r=l9(e,t),a=m9(t.text,fb(t),n),i=xT(a,fb(t),t.lineHeight),s=t.fontSize;for(;(i.width>n||i.height>r)&&s>0;){s-=1;let l={...t,fontSize:s};i=xT(t.text,fb(l),t.lineHeight)}Sp(t,o.getNonDeletedElementsMap(),{fontSize:s,width:i.width,height:i.height}),d9(t,e,o)},Tb=(e,{conversionType:t,nextType:o,direction:n="right"})=>{if(!t)return!1;let r=e.scene.getSelectedElements(e.state),a=r.reduce((s,l)=>({...s,[l.id]:!0}),{}),i=n==="right"?1:-1;if(t==="generic"){let s=IT(r),c=s.every(m=>m.type===s[0].type)?Fc.indexOf(s[0].type):-1;if(o=o??Fc[(c+Fc.length+i)%Fc.length],o&&Ys(o)){let m={};for(let d of s){let u=ET(d,o,e);m[u.id]=u}let p=[];for(let d of e.scene.getElementsIncludingDeleted())m[d.id]?p.push(m[d.id]):p.push(d);e.scene.replaceAllElements(p);for(let d of Object.values(m)){let u=wT(d,e.scene.getNonDeletedElementsMap());u&&(Hc.get(d.id)&&Sp(u,e.scene.getNonDeletedElementsMap(),{fontSize:Hc.get(d.id)?.fontSize??u.fontSize}),M9(d,u,e.scene))}e.setState(d=>({selectedElementIds:a,activeTool:bT(d,{type:"selection"})}))}}if(t==="linear"){let s=wb(r);if(!o){let c=f9(s,Ws),m=c?Oc.indexOf(c):-1;o=Oc[(m+Oc.length+i)%Oc.length]}if(kp(o)){let c=[],m=e.scene.getElementsMapIncludingDeleted();for(let p of s){let d=Gc.get(Eb(p.id,o));if(d&&Ws(d)===o)m.set(d.id,d),c.push(d);else{let u=ET(p,o,e);m.set(u.id,u),c.push(u)}}e.scene.replaceAllElements(m);for(let p of c)if(Ib(p))if(r9(p)){let d=P9(p);if(d.length<2)continue;let u=[];for(let g=1;g<d.length-2;g++)u.push({start:d[g],end:d[g+1],index:g+1});let h=QN(p,e.scene.getNonDeletedElementsMap(),{points:d,fixedSegments:u});Sp(p,e.scene.getNonDeletedElementsMap(),{...h,endArrowhead:"arrow"})}else{let d=h9(["line","sharpArrow","curvedArrow"],u=>Gc.get(Eb(p.id,u)));if(d){let u=d.points;e.scene.mutateElement(p,{points:u})}}}let l=wb(e.scene.getSelectedElements(e.state));e.setState(c=>({selectedElementIds:a,selectedLinearElement:l.length===1?new b9(l[0],e.scene.getNonDeletedElementsMap()):null,activeTool:bT(c,{type:"selection"})}))}return!0},$s=e=>{if(e.length===0)return null;let t=!1;for(let o of e){if(Ys(o.type))return"generic";vT(o)&&(t=!0)}return t?"linear":null},vT=e=>Ib(e)&&(!n9(e)||!o9(e)&&!t9(e)),Eb=(e,t)=>`${e}:${t}`,IT=e=>e.filter(t=>Ys(t.type)),wb=e=>e.filter(t=>vT(t)),Ip=20,Gs=(e,t)=>e[0]===t[0],xb=(e,t)=>e[1]===t[1],yT=(e,t)=>Gs(e,t)?Math.abs(e[1]-t[1]):Math.abs(e[0]-t[0]),P9=e=>{let t=[e.points[0]],o=A9(e.points);for(let a=1;a<o.length;++a){let i=t[t.length-1],s=[...o[a]];Math.abs(s[0]-i[0])<Ip?s[0]=i[0]:Math.abs(s[1]-i[1])<Ip&&(s[1]=i[1]),Gs(i,s)||xb(i,s)||t.push(Tp(i[0],s[1])),t.push(s)}let n=[t[0]];for(let a=1;a<t.length-1;++a)Gs(t[a-1],t[a])&&Gs(t[a],t[a+1])||xb(t[a-1],t[a])&&xb(t[a],t[a+1])||n.push(t[a]);n.push(t[t.length-1]);let r=[n[0]];for(let a=1;a<n.length-1;++a){let i=r[r.length-1],s=n[a],l=n[a+1],c=Gs(i,s),m=Gs(s,l);if(c!==m){let p=yT(i,s),d=yT(s,l);if(p<Ip||d<Ip){if(d<p)c?l[0]=i[0]:l[1]=i[1];else if(m)for(let u=r.length-1;u>=0&&r[u][0]===i[0];--u)r[u][0]=s[0];else for(let u=r.length-1;u>=0&&r[u][1]===i[1];--u)r[u][1]=s[1];continue}}r.push(s)}return r.push(n[n.length-1]),r},A9=e=>{if(e.length===0)return[];let t=[e[0]];for(let o=1;o<e.length;o++){let[n,r]=t[t.length-1],[a,i]=e[o];(n!==a||r!==i)&&t.push(e[o])}return t},ET=(e,t,o)=>{if(!L9(e.type,t)){if(!g9())throw Error(`Invalid conversion from ${e.type} to ${t}.`);return e}if(e.type===t)return e;if(E9.delete(e),Ys(t)){let n=Us(x9({...e,type:t,roundness:t==="diamond"&&e.roundness?{type:a9(t)?Cp.ADAPTIVE_RADIUS:Cp.PROPORTIONAL_RADIUS}:e.roundness}));return w9(n,o.scene,o.state),n}if(kp(t))switch(t){case"line":return Us(y9({...e,type:"line"}));case"sharpArrow":return Us(bb({...e,type:"arrow",elbowed:!1,roundness:null,startArrowhead:o.state.currentItemStartArrowhead,endArrowhead:o.state.currentItemEndArrowhead}));case"curvedArrow":return Us(bb({...e,type:"arrow",elbowed:!1,roundness:{type:Cp.PROPORTIONAL_RADIUS},startArrowhead:o.state.currentItemStartArrowhead,endArrowhead:o.state.currentItemEndArrowhead}));case"elbowArrow":return Us(bb({...e,type:"arrow",elbowed:!0,fixedSegments:null,roundness:null}))}return p9(t,`unhandled conversion type: ${t}`),e},L9=(e,t)=>!!(Ys(e)&&Ys(t)||kp(e)&&kp(t)),_9=e=>Ib(e)?Ws(e):e.type,TT=k9;var kT=W({name:"toggleShapeSwitch",label:"labels.shapeSwitch",icon:()=>null,viewMode:!0,trackEvent:{category:"shape_switch",action:"toggle"},keywords:["change","switch","swap"],perform(e,t,o,n){return Et.set(bn,{type:"panel"}),{captureUpdate:D9.NEVER}},checked:e=>e.gridModeEnabled,predicate:(e,t,o)=>$s(e)!==null});import{canCreateLinkFromElements as Cb,defaultGetElementLinkFromSelection as R9,getLinkIdAndTypeFromSelection as N9}from"@orangecatai/element";import{CaptureUpdateAction as Uc}from"@orangecatai/element";var Mp=W({name:"copyElementLink",label:"labels.copyElementLink",icon:is,trackEvent:{category:"element"},perform:async(e,t,o,n)=>{let r=de(e,t);try{if(window.location){let a=N9(r,t);return a?(await hn(n.props.generateLinkForSelection?n.props.generateLinkForSelection(a.id,a.type):R9(a.id,a.type)),{appState:{toast:{message:f("toast.elementLinkCopied"),closable:!0}},captureUpdate:Uc.EVENTUALLY}):{appState:t,elements:e,app:n,captureUpdate:Uc.EVENTUALLY}}}catch(a){console.error(a)}return{appState:t,elements:e,app:n,captureUpdate:Uc.EVENTUALLY}},predicate:(e,t)=>Cb(de(e,t))}),ST=W({name:"linkToElement",label:"labels.linkToElement",icon:Cm,perform:(e,t,o,n)=>{let r=de(e,t);return r.length!==1||!Cb(r)?{elements:e,appState:t,app:n,captureUpdate:Uc.EVENTUALLY}:{appState:{...t,openDialog:{name:"elementLinkSelector",sourceElementId:de(e,t)[0].id}},captureUpdate:Uc.IMMEDIATELY}},predicate:(e,t,o,n)=>{let r=de(e,t);return t.openDialog?.name!=="elementLinkSelector"&&r.length===1&&Cb(r)},trackEvent:!1});import{isDarwin as MT}from"@orangecatai/common";var B9={toggleTheme:[G("Shift+Alt+D")],saveScene:[G("CtrlOrCmd+S")],loadScene:[G("CtrlOrCmd+O")],clearCanvas:[G("CtrlOrCmd+Delete")],imageExport:[G("CtrlOrCmd+Shift+E")],commandPalette:[G("CtrlOrCmd+/"),G("CtrlOrCmd+Shift+P")],cut:[G("CtrlOrCmd+X")],copy:[G("CtrlOrCmd+C")],paste:[G("CtrlOrCmd+V")],copyStyles:[G("CtrlOrCmd+Alt+C")],pasteStyles:[G("CtrlOrCmd+Alt+V")],selectAll:[G("CtrlOrCmd+A")],deleteSelectedElements:[G("Delete")],duplicateSelection:[G("CtrlOrCmd+D"),G(`Alt+${f("helpDialog.drag")}`)],sendBackward:[G("CtrlOrCmd+[")],bringForward:[G("CtrlOrCmd+]")],sendToBack:[MT?G("CtrlOrCmd+Alt+["):G("CtrlOrCmd+Shift+[")],bringToFront:[MT?G("CtrlOrCmd+Alt+]"):G("CtrlOrCmd+Shift+]")],copyAsPng:[G("Shift+Alt+C")],group:[G("CtrlOrCmd+G")],ungroup:[G("CtrlOrCmd+Shift+G")],gridMode:[G("CtrlOrCmd+'")],zenMode:[G("Alt+Z")],objectsSnapMode:[G("Alt+S")],stats:[G("Alt+/")],addToLibrary:[],flipHorizontal:[G("Shift+H")],flipVertical:[G("Shift+V")],viewMode:[G("Alt+R")],hyperlink:[G("CtrlOrCmd+K")],toggleElementLock:[G("CtrlOrCmd+Shift+L")],resetZoom:[G("CtrlOrCmd+0")],zoomOut:[G("CtrlOrCmd+-")],zoomIn:[G("CtrlOrCmd++")],zoomToFitSelection:[G("Shift+3")],zoomToFit:[G("Shift+1")],zoomToFitSelectionInViewport:[G("Shift+2")],toggleEraserTool:[G("E")],toggleHandTool:[G("H")],setFrameAsActiveTool:[G("F")],saveFileToDisk:[G("CtrlOrCmd+S")],saveToActiveFile:[G("CtrlOrCmd+S")],toggleShortcuts:[G("?")],searchMenu:[G("CtrlOrCmd+F")],wrapSelectionInFrame:[],toolLock:[G("Q")]},Xe=(e,t=0)=>{let o=B9[e];return o&&o.length>0?o[t]||o[0]:""};var F9="\\u0300-\\u036f",O9="\\ufe20-\\ufe2f",z9="\\u20d0-\\u20ff",H9=F9+O9+z9,G9=`[${H9}]`,U9=RegExp(G9,"g"),W9=/[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g,Y9={\u00C0:"A",\u00C1:"A",\u00C2:"A",\u00C3:"A",\u00C4:"A",\u00C5:"A",\u00E0:"a",\u00E1:"a",\u00E2:"a",\u00E3:"a",\u00E4:"a",\u00E5:"a",\u00C7:"C",\u00E7:"c",\u00D0:"D",\u00F0:"d",\u00C8:"E",\u00C9:"E",\u00CA:"E",\u00CB:"E",\u00E8:"e",\u00E9:"e",\u00EA:"e",\u00EB:"e",\u00CC:"I",\u00CD:"I",\u00CE:"I",\u00CF:"I",\u00EC:"i",\u00ED:"i",\u00EE:"i",\u00EF:"i",\u00D1:"N",\u00F1:"n",\u00D2:"O",\u00D3:"O",\u00D4:"O",\u00D5:"O",\u00D6:"O",\u00D8:"O",\u00F2:"o",\u00F3:"o",\u00F4:"o",\u00F5:"o",\u00F6:"o",\u00F8:"o",\u00D9:"U",\u00DA:"U",\u00DB:"U",\u00DC:"U",\u00F9:"u",\u00FA:"u",\u00FB:"u",\u00FC:"u",\u00DD:"Y",\u00FD:"y",\u00FF:"y",\u00C6:"E",\u00E6:"e",\u00DE:"T",\u00FE:"t",\u00DF:"s",\u0100:"A",\u0102:"A",\u0104:"A",\u0101:"a",\u0103:"a",\u0105:"a",\u0106:"C",\u0108:"C",\u010A:"C",\u010C:"C",\u0107:"c",\u0109:"c",\u010B:"c",\u010D:"c",\u010E:"D",\u0110:"D",\u010F:"d",\u0111:"d",\u0112:"E",\u0114:"E",\u0116:"E",\u0118:"E",\u011A:"E",\u0113:"e",\u0115:"e",\u0117:"e",\u0119:"e",\u011B:"e",\u011C:"G",\u011E:"G",\u0120:"G",\u0122:"G",\u011D:"g",\u011F:"g",\u0121:"g",\u0123:"g",\u0124:"H",\u0126:"H",\u0125:"h",\u0127:"h",\u0128:"I",\u012A:"I",\u012C:"I",\u012E:"I",\u0130:"I",\u0129:"i",\u012B:"i",\u012D:"i",\u012F:"i",\u0131:"i",\u0134:"J",\u0135:"j",\u0136:"K",\u0137:"k",\u0138:"k",\u0139:"L",\u013B:"L",\u013D:"L",\u013F:"L",\u0141:"L",\u013A:"l",\u013C:"l",\u013E:"l",\u0140:"l",\u0142:"l",\u0143:"N",\u0145:"N",\u0147:"N",\u014A:"N",\u0144:"n",\u0146:"n",\u0148:"n",\u014B:"n",\u014C:"O",\u014E:"O",\u0150:"O",\u014D:"o",\u014F:"o",\u0151:"o",\u0154:"R",\u0156:"R",\u0158:"R",\u0155:"r",\u0157:"r",\u0159:"r",\u015A:"S",\u015C:"S",\u015E:"S",\u0160:"S",\u015B:"s",\u015D:"s",\u015F:"s",\u0161:"s",\u0162:"T",\u0164:"T",\u0166:"T",\u0163:"t",\u0165:"t",\u0167:"t",\u0168:"U",\u016A:"U",\u016C:"U",\u016E:"U",\u0170:"U",\u0172:"U",\u0169:"u",\u016B:"u",\u016D:"u",\u016F:"u",\u0171:"u",\u0173:"u",\u0174:"W",\u0175:"w",\u0176:"Y",\u0177:"y",\u0178:"Y",\u0179:"Z",\u017B:"Z",\u017D:"Z",\u017A:"z",\u017C:"z",\u017E:"z",\u0132:"I",\u0133:"i",\u0152:"E",\u0153:"e",\u0149:"n",\u017F:"s"},ri=e=>e.replace(W9,t=>Y9[t]||t).replace(U9,"");import aO from"clsx";import{useEffect as iO,useState as sO}from"react";import{KEYS as lO,queryFocusableElements as OC}from"@orangecatai/common";import{useCallback as $9,useState as V9}from"react";var PT=()=>{let[e,t]=V9(null),o=$9(n=>t(n),[]);return[e,o]};import{useState as _C,useCallback as Kb,useMemo as DC,useEffect as Xb,memo as RC,useRef as YF}from"react";import{LIBRARY_DISABLED_TYPES as $F,randomId as VF,isShallowEqual as KF,KEYS as XF,isWritableElement as ZF,addEventListener as jF,EVENT as qF,CLASSES as PC}from"@orangecatai/common";import{useEffect as DT,useRef as RT}from"react";import{URL_HASH_KEYS as Mb,URL_QUERY_KEYS as Pb,APP_NAME as NT,EVENT as Ap,DEFAULT_SIDEBAR as j9,LIBRARY_SIDEBAR_TAB as q9,arrayToMap as Ab,cloneJSON as J9,preventUnload as Q9,promiseTry as BT,resolvablePromise as eB,toValidURL as tB,Queue as oB,Emitter as nB}from"@orangecatai/common";import{hashElementsVersion as rB,hashString as aB}from"@orangecatai/element";import{getCommonBoundingBox as Sb}from"@orangecatai/element";import{MIME_TYPES as ai}from"@orangecatai/common";var na=({elements:e,appState:t,files:o,maxWidthOrHeight:n,getDimensions:r,exportPadding:a,exportingFrame:i})=>{let s=Ga(e,null,{deleteInvisibleElements:!0}),l=$i(t,null),{exportBackground:c,viewBackgroundColor:m}=l;return zr(s,{...l,offsetTop:0,offsetLeft:0,width:0,height:0},o||{},{exportBackground:c,exportPadding:a,viewBackgroundColor:m,exportingFrame:i},(p,d)=>{let u=document.createElement("canvas");if(n){typeof r=="function"&&console.warn("`getDimensions()` is ignored when `maxWidthOrHeight` is supplied.");let g=Math.max(p,d),x=n<g?n/g:t?.exportScale??1;return u.width=p*x,u.height=d*x,{canvas:u,scale:x}}let h=r?.(p,d)||{width:p,height:d};return u.width=h.width,u.height=h.height,{canvas:u,scale:h.scale??1}})},AT=async e=>{let{mimeType:t=ai.png,quality:o}=e;t===ai.png&&typeof o=="number"&&console.warn(`"quality" will be ignored for "${ai.png}" mimeType`),t==="image/jpg"&&(t=ai.jpg),t===ai.jpg&&!e.appState?.exportBackground&&(console.warn(`Defaulting "exportBackground" to "true" for "${ai.jpg}" mimeType`),e={...e,appState:{...e.appState,exportBackground:!0}});let n=await na(e);return o=o||(/image\/jpe?g/.test(t)?.92:.8),new Promise((r,a)=>{n.toBlob(async i=>{if(!i)return a(new Error("couldn't export to blob"));i&&t===ai.png&&e.appState?.exportEmbedScene&&(i=await pE({blob:i,metadata:jl(e.elements,e.appState,e.files||{},"local")})),r(i)},t,o)})},Vs=async({elements:e,appState:t=Or(),files:o={},exportPadding:n,renderEmbeddables:r,exportingFrame:a,skipInliningFonts:i,reuseImages:s})=>{let l=Ga(e,null,{deleteInvisibleElements:!0}),m={...$i(t,null),exportPadding:n};return Yi(l,m,o,{exportingFrame:a,renderEmbeddables:r,skipInliningFonts:i,reuseImages:s})},K9=async e=>{if(e.type==="svg"){let t=await Vs(e);await hn(t.outerHTML)}else if(e.type==="png")await lp(AT(e));else if(e.type==="json")await ip(e.elements,e.files);else throw new Error("Invalid export type")};import{useEffect as LT,useState as X9}from"react";import{COLOR_PALETTE as Z9}from"@orangecatai/common";var kb=Pe(new Map),_T=async e=>await Vs({elements:e,appState:{exportBackground:!1,viewBackgroundColor:Z9.white},files:null,renderEmbeddables:!1,skipInliningFonts:!0}),Pp=(e,t,o,n)=>{let[r,a]=X9();return LT(()=>{if(t)if(e){let i=o.get(e);i?a(i):(async()=>{let s=await _T(t);s.querySelector(".style-fonts")?.remove(),s&&(o.set(e,s),a(s))})()}else(async()=>{let i=await _T(t);a(i)})()},[e,t,o,a]),LT(()=>{let i=n.current;if(i)return r&&(i.innerHTML=r.outerHTML),()=>{i.innerHTML=""}},[r,n]),r},Ks=()=>{let[e]=le(kb);return{clearLibraryCache:()=>e.clear(),deleteItemsFromLibraryCache:n=>{n.forEach(r=>e.delete(r))},svgCache:e}};var iB=["excalidraw.com","raw.githubusercontent.com/excalidraw/excalidraw-libraries"],OT=new nB,wr=Pe({status:"loaded",isInitialized:!1,libraryItems:[]}),Wc=e=>J9(e),sB=(e,t)=>!e.find(o=>o.elements.length!==t.elements.length?!1:o.elements.every((n,r)=>n.id===t.elements[r].id&&n.versionNonce===t.elements[r].versionNonce)),zT=(e,t)=>{let o=[];for(let n of t)sB(e,n)&&o.push(n);return[...o,...e]},HT=(e,t)=>{let o=Ab(t),n={deletedItems:new Map,addedItems:new Map,updatedItems:new Map};for(let a of e)o.has(a.id)||n.deletedItems.set(a.id,a);let r=Ab(e);for(let a of t){let i=r.get(a.id);i?Db(i)!==Db(a)&&n.updatedItems.set(a.id,a):n.addedItems.set(a.id,a)}return n},Lb=class{constructor(t){A(this,"currLibraryItems",[]);A(this,"prevLibraryItems",Wc(this.currLibraryItems));A(this,"app");A(this,"updateQueue",[]);A(this,"getLastUpdateTask",()=>this.updateQueue[this.updateQueue.length-1]);A(this,"notifyListeners",()=>{if(this.updateQueue.length>0)Et.set(wr,t=>({status:"loading",libraryItems:this.currLibraryItems,isInitialized:t.isInitialized}));else{Et.set(wr,{status:"loaded",libraryItems:this.currLibraryItems,isInitialized:!0});try{let t=this.prevLibraryItems;this.prevLibraryItems=Wc(this.currLibraryItems);let o=Wc(this.currLibraryItems);this.app.props.onLibraryChange?.(o),OT.trigger(HT(t,o),o)}catch(t){console.error(t)}}});A(this,"destroy",()=>{this.updateQueue=[],this.currLibraryItems=[],Et.set(kb,new Map)});A(this,"resetLibrary",()=>this.setLibrary([]));A(this,"getLatestLibrary",()=>new Promise(async t=>{try{let o=await(this.getLastUpdateTask()||this.currLibraryItems);this.updateQueue.length>0?t(this.getLatestLibrary()):t(Wc(o))}catch{return t(this.currLibraryItems)}}));A(this,"updateLibrary",async({libraryItems:t,prompt:o=!1,merge:n=!1,openLibraryMenu:r=!1,defaultStatus:a="unpublished"})=>(r&&this.app.setState({openSidebar:{name:j9.name,tab:q9}}),this.setLibrary(()=>new Promise(async(i,s)=>{try{let l=await(typeof t=="function"&&!(t instanceof Blob)?t(this.currLibraryItems):t),c;l instanceof Blob?c=await ph(l,a):c=Ql(l,a),!o||window.confirm(f("alerts.confirmAddLibrary",{numShapes:c.length}))?(o&&this.app.focusContainer(),i(n?zT(this.currLibraryItems,c):c)):s(new Ui)}catch(l){s(l)}}))));A(this,"setLibrary",t=>{let o=new Promise(async(n,r)=>{try{await this.getLastUpdateTask(),typeof t=="function"&&(t=t(this.currLibraryItems)),this.currLibraryItems=Wc(await t),n(this.currLibraryItems)}catch(a){r(a)}}).catch(n=>{if(n.name==="AbortError")return console.warn("Library update aborted by user"),this.currLibraryItems;throw n}).finally(()=>{this.updateQueue=this.updateQueue.filter(n=>n!==o),this.notifyListeners()});return this.updateQueue.push(o),this.notifyListeners(),o});this.app=t}},GT=Lb,Zs=e=>{let o=Math.ceil(Math.sqrt(e.length)),n=[],r=u=>e.slice(u*o,u*o+o).reduce((g,x)=>{let{height:E}=Sb(x.elements);return Math.max(g,E)},0),a=u=>{let h=0,g=0,x=0;for(let E of e){if(h%o===0&&(g=0),g===u){let{width:y}=Sb(E.elements);x=Math.max(x,y)}h++,g++}return x},i=0,s=0,l=0,c=0,m=0,p=0,d=0;for(let u of e){m&&m%o===0&&(s+=l+50,i=0,p=0,d++),p===0&&(l=r(d)),c=a(p);let{minX:h,minY:g,width:x,height:E}=Sb(u.elements),y=(c-x)/2,w=(l-E)/2;n.push(...u.elements.map(v=>({...v,x:v.x+i+y-h,y:v.y+s+w-g}))),i+=c+50,m++,p++}return n},lB=(e,t=iB)=>{if(typeof t=="function"?t(e):t.some(o=>{let n=new URL(`https://${o.replace(/^https?:\/\//,"")}`),{hostname:r,pathname:a}=new URL(e);return new RegExp(`(^|\\.)${n.hostname}$`).test(r)&&new RegExp(`^${n.pathname.replace(/\/+$/,"")}(/+|$)`).test(a)}))return!0;throw new Error(`Invalid or disallowed library URL: "${e}"`)},_b=()=>{let e=new URLSearchParams(window.location.hash.slice(1)).get(Mb.addLibrary)||new URLSearchParams(window.location.search).get(Pb.addLibrary),t=e?new URLSearchParams(window.location.hash.slice(1)).get("token"):null;return e?{libraryUrl:e,idToken:t}:null},ra=class ra{constructor(t){A(this,"adapter");this.adapter=t}static async getLibraryItems(t,o,n=!0){let r=()=>new Promise(async(a,i)=>{try{let s=await t.load({source:o});a(Ql(s?.libraryItems||[],"published"))}catch(s){i(s)}});return n?ra.queue.push(r):r()}getLibraryItems(t){return ra.getLibraryItems(this.adapter,t,!1)}};A(ra,"queue",new oB),A(ra,"run",async(t,o)=>{let n=new ra(t);return ra.queue.push(()=>o(n))});var Xs=ra,Yc=0,Lp=0,Db=e=>`${e.id}:${e.name||""}:${rB(e.elements)}`,_p=e=>aB(e.map(t=>Db(t)).sort().join()),FT=async(e,t)=>{try{return Lp++,await Xs.run(e,async o=>{let n=Ab(await o.getLibraryItems("save"));for(let[s]of t.deletedItems)n.delete(s);let r=[];for(let[s,l]of t.addedItems)n.has(s)?n.set(s,l):r.push(l);if(t.updatedItems)for(let[s,l]of t.updatedItems)n.set(s,l);let a=r.concat(Array.from(n.values())),i=_p(a);return i!==Yc&&await e.save({libraryItems:a}),Yc=i,a})}finally{Lp--}},cB=e=>{let{excalidrawAPI:t}=e,o=RT(e);o.current=e;let n=RT(!1);DT(()=>{if(!t)return;n.current=!1;let r=async({libraryUrl:s,idToken:l})=>{let c=new Promise(async(p,d)=>{try{s=decodeURIComponent(s),s=tB(s),lB(s,o.current.validateLibraryUrl);let h=await(await fetch(s)).blob();p(h)}catch(u){d(u)}}),m=l!==t.id;await(m&&document.hidden?new Promise(p=>{window.addEventListener("focus",()=>p(),{once:!0})}):null);try{await t.updateLibrary({libraryItems:c,prompt:m,merge:!0,defaultStatus:"published",openLibraryMenu:!0})}catch(p){throw t.updateScene({appState:{errorMessage:p.message}}),p}finally{if(window.location.hash.includes(Mb.addLibrary)){let p=new URLSearchParams(window.location.hash.slice(1));p.delete(Mb.addLibrary),window.history.replaceState({},NT,`#${p.toString()}`)}else if(window.location.search.includes(Pb.addLibrary)){let p=new URLSearchParams(window.location.search);p.delete(Pb.addLibrary),window.history.replaceState({},NT,`?${p.toString()}`)}}},a=s=>{s.preventDefault();let l=_b();l&&(s.stopImmediatePropagation(),window.history.replaceState({},"",s.oldURL),r(l))},i=_b();if(i&&r(i),"getInitialLibraryItems"in o.current&&o.current.getInitialLibraryItems&&(console.warn("useHandleLibrar `opts.getInitialLibraryItems` is deprecated. Use `opts.adapter` instead."),Promise.resolve(o.current.getInitialLibraryItems()).then(s=>{t.updateLibrary({libraryItems:s,merge:!0})}).catch(s=>{console.error(`UseHandeLibrary getInitialLibraryItems failed: ${s?.message}`)})),"adapter"in o.current&&o.current.adapter){let s=o.current.adapter,l=o.current.migrationAdapter,c=eB();l?c.resolve(BT(l.load).then(async m=>{let p=null;try{if(!m)return Xs.getLibraryItems(s,"load");p=Ql(m.libraryItems||[],"published");let d=await FT(s,HT([],p));try{await l.clear()}catch(u){console.error(`couldn't delete legacy library data: ${u.message}`)}return d}catch(d){return console.error(`couldn't migrate legacy library data: ${d.message}`),p}}).catch(m=>(console.error(`error during library migration: ${m.message}`),Xs.getLibraryItems(s,"load")))):c.resolve(BT(Xs.getLibraryItems,s,"load")),t.updateLibrary({libraryItems:c.then(m=>{let p=m||[];return Yc=_p(p),p}),merge:!0}).finally(()=>{n.current=!0})}return window.addEventListener(Ap.HASHCHANGE,a),()=>{window.removeEventListener(Ap.HASHCHANGE,a)}},[t]),DT(()=>{let r=OT.on(async(i,s)=>{let l=n.current,c="adapter"in o.current&&o.current.adapter||null;try{c&&Yc!==_p(s)&&await FT(c,i)}catch(m){console.error(`couldn't persist library update: ${m.message}`,i),l&&o.current.excalidrawAPI&&o.current.excalidrawAPI.updateScene({appState:{errorMessage:f("errors.saveLibraryError")}})}}),a=i=>{Lp&&Q9(i)};return window.addEventListener(Ap.BEFORE_UNLOAD,a),()=>{window.removeEventListener(Ap.BEFORE_UNLOAD,a),r(),Yc=0,Lp=0}},[])};import uB from"clsx";import{VERSIONS as dB}from"@orangecatai/common";import{jsx as pB}from"react/jsx-runtime";var mB=({theme:e,id:t,libraryReturnUrl:o})=>{let n=o||window.location.origin+window.location.pathname;return pB("a",{className:"library-menu-browse-button",href:`${T.VITE_APP_LIBRARY_URL}?target=${window.name||"_blank"}&referrer=${n}&useHash=true&token=${t}&theme=${e}&version=${dB.excalidrawLibrary}`,target:"_excalidraw_libraries",children:f("labels.libraries")})},UT=mB;import{jsx as gB,jsxs as hB}from"react/jsx-runtime";var Dp=({libraryReturnUrl:e,theme:t,id:o,style:n,children:r,className:a})=>hB("div",{className:uB("library-menu-control-buttons",a),style:n,children:[gB(UT,{id:o,libraryReturnUrl:e,theme:t}),r]});import{useCallback as Js,useEffect as Wb,useMemo as Yb,useRef as kC,useState as SC}from"react";import{MIME_TYPES as FF,arrayToMap as OF,nextAnimationFrame as zF}from"@orangecatai/common";import{duplicateElements as HF}from"@orangecatai/element";import GF from"clsx";import fB from"lodash.throttle";import{useEffect as bB}from"react";var xB=Pe(0),WT=e=>{let[t,o]=le(xB);return bB(()=>{let{current:n}=e;if(!n)return;let r=fB(()=>{let{scrollTop:a}=n;o(a)},200);return n.addEventListener("scroll",r),()=>{r.cancel(),n.removeEventListener("scroll",r)}},[e,o]),t};import uF from"clsx";import{useCallback as gF,useState as Hb}from"react";import{muteFSAbortError as hF}from"@orangecatai/common";import{flushSync as YT}from"react-dom";import yB from"clsx";import{jsx as Rp,jsxs as wB}from"react/jsx-runtime";var EB=({label:e,onClick:t,className:o,children:n,actionType:r,type:a="button",isLoading:i,...s})=>{let l=r?`Dialog__action-button--${r}`:"";return wB("button",{className:yB("Dialog__action-button",l,o),type:a,"aria-label":e,onClick:t,...s,children:[n&&Rp("div",{style:i?{visibility:"hidden"}:{},children:n}),Rp("div",{style:i?{visibility:"hidden"}:{},children:e}),i&&Rp("div",{style:{position:"absolute",inset:0},children:Rp(Wt,{})})]})},vr=EB;import{jsx as $T,jsxs as VT}from"react/jsx-runtime";var vB=e=>{let{onConfirm:t,onCancel:o,children:n,confirmText:r=f("buttons.confirm"),cancelText:a=f("buttons.cancel"),className:i="",...s}=e,l=Ce(),c=Rn(js),{container:m}=Qe();return VT(bt,{onCloseRequest:o,size:"small",...s,className:`confirm-dialog ${i}`,children:[n,VT("div",{className:"confirm-dialog-buttons",children:[$T(vr,{label:a,onClick:()=>{l({openMenu:null}),c(!1),YT(()=>{o()}),m?.focus()}}),$T(vr,{label:r,onClick:()=>{l({openMenu:null}),c(!1),YT(()=>{t()}),m?.focus()},actionType:"danger"})]})]})},Np=vB;import{useCallback as PB,useEffect as Bb,useRef as KT,useState as Rb}from"react";import{EDITOR_LS_KEYS as Nb,EXPORT_DATA_TYPES as AB,MIME_TYPES as XT,VERSIONS as LB,chunk as _B,getExportSource as DB}from"@orangecatai/common";var Xo=class{static has(t){try{return!!window.localStorage.getItem(t)}catch(o){return console.warn(`localStorage.getItem error: ${o.message}`),!1}}static get(t){try{let o=window.localStorage.getItem(t);return o?JSON.parse(o):null}catch(o){return console.warn(`localStorage.getItem error: ${o.message}`),null}}};A(Xo,"set",(t,o)=>{try{return window.localStorage.setItem(t,JSON.stringify(o)),!0}catch(n){return console.warn(`localStorage.setItem error: ${n.message}`),!1}}),A(Xo,"delete",t=>{try{window.localStorage.removeItem(t)}catch(o){console.warn(`localStorage.removeItem error: ${o.message}`)}});import Bp from"react";var IB=/({{[\w-]+}})|(<[\w-]+>)|(<\/[\w-]+>)/g,TB=/{{([\w-]+)}}/,CB=/<([\w-]+)>/,kB=/<\/([\w-]+)>/,SB=(e,t)=>{let o=[{name:"",children:[]}];return e.split(IB).filter(Boolean).forEach(n=>{let r=n.match(CB),a=n.match(kB),i=n.match(TB);if(r!==null){let s=r[1];t.hasOwnProperty(s)?o.push({name:s,children:[]}):console.warn(`Trans: missed to pass in prop ${s} for interpolating ${e}`)}else if(a!==null)if(a[1]===o[o.length-1].name){let l=o.pop(),c=Bp.createElement(Bp.Fragment,{},...l.children),m=t[l.name];typeof m=="function"&&o[o.length-1].children.push(m(c))}else console.warn(`Trans: unexpected end tag ${n} for interpolating ${e}`);else if(i!==null){let s=i[1];t.hasOwnProperty(s)?o[o.length-1].children.push(t[s]):console.warn(`Trans: key ${s} not in props for interpolating ${e}`)}else o[o.length-1].children.push(n)}),o.length!==1&&console.warn(`Trans: stack not empty for interpolating ${e}`),o[0].children},MB=({i18nKey:e,children:t,...o})=>{let{t:n}=Ue();return Bp.createElement(Bp.Fragment,{},...SB(n(e),o))},io=MB;import{jsx as Ae,jsxs as Zt}from"react/jsx-runtime";var RB=async e=>{let n=Math.round(8),r=Math.max(Math.round(128/64),2),a=_B(e,6),i=document.createElement("canvas");i.width=a[0].length*128+(a[0].length+1)*(n*2)-n*2,i.height=a.length*128+(a.length+1)*(n*2)-n*2;let s=i.getContext("2d");s.fillStyle="#fff",s.fillRect(0,0,i.width,i.height);for(let[l,c]of e.entries()){let m=await na({elements:c.elements,files:null,maxWidthOrHeight:128}),{width:p,height:d}=m,u=Math.floor(l/6)*(128+n*2),h=l%6*(128+n*2);s.drawImage(m,h+(128-p)/2+n,u+(128-d)/2+n),s.lineWidth=r,s.strokeStyle="#ced4da",s.strokeRect(h+n/2,u+n/2,128+n,128+n)}return await cm(new File([await Ua(i)],"preview",{type:XT.png}),{outputType:XT.jpg,maxWidthOrHeight:5e3})},NB=({libItem:e,appState:t,index:o,onChange:n,onRemove:r})=>{let a=KT(null),i=KT(null);return Bb(()=>{let s=a.current;s&&(async()=>{let l=await Vs({elements:e.elements,appState:{...t,viewBackgroundColor:"#fff",exportBackground:!0},files:null,skipInliningFonts:!0});s.innerHTML=l.outerHTML})()},[e.elements,t]),Zt("div",{className:"single-library-item",children:[e.status==="published"&&Ae("span",{className:"single-library-item-status",children:f("labels.statusPublished")}),Ae("div",{ref:a,className:"single-library-item__svg"}),Ae(ae,{"aria-label":f("buttons.remove"),type:"button",icon:Go,className:"single-library-item--remove",onClick:r.bind(null,e.id),title:f("buttons.remove")}),Zt("div",{style:{display:"flex",margin:"0.8rem 0",width:"100%",fontSize:"14px",fontWeight:500,flexDirection:"column"},children:[Zt("label",{style:{display:"flex",justifyContent:"space-between",flexDirection:"column"},children:[Zt("div",{style:{padding:"0.5em 0"},children:[Ae("span",{style:{fontWeight:500,color:"#868e96"},children:f("publishDialog.itemName")}),Ae("span",{"aria-hidden":"true",className:"required",children:"*"})]}),Ae("input",{type:"text",ref:i,style:{width:"80%",padding:"0.2rem"},defaultValue:e.name,placeholder:"Item name",onChange:s=>{n(s.target.value,o)}})]}),Ae("span",{className:"error",children:e.error})]})]})},BB=({onClose:e,libraryItems:t,appState:o,onSuccess:n,onError:r,updateItemsInStorage:a,onRemove:i})=>{let[s,l]=Rb({authorName:"",githubHandle:"",name:"",description:"",twitterHandle:"",website:""}),[c,m]=Rb(!1);Bb(()=>{let w=Xo.get(Nb.PUBLISH_LIBRARY);w&&l(w)},[]);let[p,d]=Rb(t.slice());Bb(()=>{d(t.slice())},[t]);let u=w=>{l({...s,[w.target.name]:w.target.value})},h=async w=>{w.preventDefault(),m(!0);let v=[],I=!1;if(p.forEach(k=>{let M="";k.name||(M=f("publishDialog.errors.required"),I=!0),v.push({...k,error:M})}),I){d(v),m(!1);return}let C=await RB(p),P={type:AB.excalidrawLibrary,version:LB.excalidrawLibrary,source:DB(),libraryItems:p},S=JSON.stringify(P,null,2),D=new Blob([S],{type:"application/json"}),_=new FormData;_.append("excalidrawLib",D),_.append("previewImage",C),_.append("previewImageType",C.type),_.append("title",s.name),_.append("authorName",s.authorName),_.append("githubHandle",s.githubHandle),_.append("name",s.name),_.append("description",s.description),_.append("twitterHandle",s.twitterHandle),_.append("website",s.website),fetch(`${T.VITE_APP_LIBRARY_BACKEND}/submit`,{method:"post",body:_}).then(k=>k.ok?k.json().then(({url:M})=>{Xo.delete(Nb.PUBLISH_LIBRARY),n({url:M,authorName:s.authorName,items:p})}):k.json().catch(()=>{throw new Error(k.statusText||"something went wrong")}).then(M=>{throw new Error(M.message||k.statusText||"something went wrong")}),k=>{console.error(k),r(k),m(!1)}).catch(k=>{console.error(k),r(k),m(!1)})},g=()=>{let w=[];return p.forEach((v,I)=>{w.push(Ae("div",{className:"single-library-item-wrapper",children:Ae(NB,{libItem:v,appState:o,index:I,onChange:(C,P)=>{let S=p.slice();S[P].name=C,d(S)},onRemove:i})},I))}),Ae("div",{className:"selected-library-items",children:w})},x=PB(()=>{a(p),Xo.set(Nb.PUBLISH_LIBRARY,s),e()},[p,e,a,s]),E=!!t.length,y=t.some(w=>w.status==="published");return Ae(bt,{onCloseRequest:x,title:f("publishDialog.title"),className:"publish-library",children:E?Zt("form",{onSubmit:h,children:[Ae("div",{className:"publish-library-note",children:Ae(io,{i18nKey:"publishDialog.noteDescription",link:w=>Ae("a",{href:"https://libraries.excalidraw.com",target:"_blank",rel:"noopener",children:w})})}),Ae("span",{className:"publish-library-note",children:Ae(io,{i18nKey:"publishDialog.noteGuidelines",link:w=>Ae("a",{href:"https://github.com/excalidraw/excalidraw-libraries#guidelines",target:"_blank",rel:"noopener noreferrer",children:w})})}),Ae("div",{className:"publish-library-note",children:f("publishDialog.noteItems")}),y&&Ae("span",{className:"publish-library-note publish-library-warning",children:f("publishDialog.republishWarning")}),g(),Zt("div",{className:"publish-library__fields",children:[Zt("label",{children:[Zt("div",{children:[Ae("span",{children:f("publishDialog.libraryName")}),Ae("span",{"aria-hidden":"true",className:"required",children:"*"})]}),Ae("input",{type:"text",name:"name",required:!0,value:s.name,onChange:u,placeholder:f("publishDialog.placeholder.libraryName")})]}),Zt("label",{style:{alignItems:"flex-start"},children:[Zt("div",{children:[Ae("span",{children:f("publishDialog.libraryDesc")}),Ae("span",{"aria-hidden":"true",className:"required",children:"*"})]}),Ae("textarea",{name:"description",rows:4,required:!0,value:s.description,onChange:u,placeholder:f("publishDialog.placeholder.libraryDesc")})]}),Zt("label",{children:[Zt("div",{children:[Ae("span",{children:f("publishDialog.authorName")}),Ae("span",{"aria-hidden":"true",className:"required",children:"*"})]}),Ae("input",{type:"text",name:"authorName",required:!0,value:s.authorName,onChange:u,placeholder:f("publishDialog.placeholder.authorName")})]}),Zt("label",{children:[Ae("span",{children:f("publishDialog.githubUsername")}),Ae("input",{type:"text",name:"githubHandle",value:s.githubHandle,onChange:u,placeholder:f("publishDialog.placeholder.githubHandle")})]}),Zt("label",{children:[Ae("span",{children:f("publishDialog.twitterUsername")}),Ae("input",{type:"text",name:"twitterHandle",value:s.twitterHandle,onChange:u,placeholder:f("publishDialog.placeholder.twitterHandle")})]}),Zt("label",{children:[Ae("span",{children:f("publishDialog.website")}),Ae("input",{type:"text",name:"website",pattern:"https?://.+",title:f("publishDialog.errors.website"),value:s.website,onChange:u,placeholder:f("publishDialog.placeholder.website")})]}),Ae("span",{className:"publish-library-note",children:Ae(io,{i18nKey:"publishDialog.noteLicense",link:w=>Ae("a",{href:"https://github.com/excalidraw/excalidraw-libraries/blob/main/LICENSE",target:"_blank",rel:"noopener noreferrer",children:w})})})]}),Zt("div",{className:"publish-library__buttons",children:[Ae(vr,{label:f("buttons.saveLibNames"),onClick:x,"data-testid":"cancel-clear-canvas-button"}),Ae(vr,{type:"submit",label:f("buttons.submit"),actionType:"primary",isLoading:c})]})]}):Ae("p",{style:{padding:"1em",textAlign:"center",fontWeight:500},children:f("publishDialog.atleastOneLibItem")})})},ZT=BB;import yC from"react";import{DropdownMenu as cF}from"radix-ui";import{CLASSES as dF}from"@orangecatai/common";import zB from"clsx";import{useCallback as HB,useEffect as GB,useRef as UB}from"react";import{CLASSES as WB,EVENT as QT,KEYS as YB}from"@orangecatai/common";import{DropdownMenu as $B}from"radix-ui";import{forwardRef as jT}from"react";import qT from"clsx";import{jsx as JT}from"react/jsx-runtime";var FB=jT(({children:e,gap:t,align:o,justifyContent:n,className:r,style:a},i)=>JT("div",{className:qT("Stack Stack_horizontal",r),style:{"--gap":t,alignItems:o,justifyContent:n,...a},ref:i,children:e})),OB=jT(({children:e,gap:t,align:o,justifyContent:n,className:r,style:a},i)=>JT("div",{className:qT("Stack Stack_vertical",r),style:{"--gap":t,justifyItems:o,justifyContent:n,...a},ref:i,children:e})),Rt={Row:FB,Col:OB};import{jsx as Fp}from"react/jsx-runtime";var eC=({children:e,onClickOutside:t,className:o="",onSelect:n,open:r=!0,align:a="end",style:i})=>{let s=Te(),l=UB(null),c=Ur({onClickOutside:t});fs(l,HB(p=>{l.current?.closest(`.${WB.DROPDOWN_MENU_EVENT_WRAPPER}`)?.contains(p.target)||c.onClickOutside?.()},[c])),GB(()=>{if(!r)return;let p=u=>{u.key===YB.ESCAPE&&(u.stopImmediatePropagation(),c.onClickOutside?.())},d={capture:!0};return document.addEventListener(QT.KEYDOWN,p,d),()=>{document.removeEventListener(QT.KEYDOWN,p,d)}},[c,r]);let m=zB(`dropdown-menu ${o}`,{"dropdown-menu--mobile":s.formFactor==="phone"}).trim();return Fp(df.Provider,{value:{onSelect:n},children:Fp($B.Content,{ref:l,className:m,style:i,"data-testid":"dropdown-menu",align:a,sideOffset:8,onCloseAutoFocus:p=>p.preventDefault(),children:s.formFactor==="phone"?Fp(Rt.Col,{className:"dropdown-menu-container",children:e}):Fp(gt,{className:"dropdown-menu-container",padding:2,children:e})})})};eC.displayName="DropdownMenuContent";var tC=eC;import{jsx as KB}from"react/jsx-runtime";var VB=({children:e,className:t="",selected:o,...n})=>KB("div",{...n,className:`dropdown-menu-item-base dropdown-menu-item-custom ${t} ${o?"dropdown-menu-item--selected":""}`.trim(),children:e}),oC=VB;import{DropdownMenu as XB}from"radix-ui";import{jsx as Fb}from"react/jsx-runtime";var nC=({icon:e,shortcut:t,href:o,children:n,onSelect:r,className:a="",selected:i,rel:s="noopener",...l})=>{let c=Wm(r);return Fb(XB.Item,{className:"radix-menu-item",onSelect:c,asChild:!0,children:Fb("a",{...l,href:o,target:"_blank",rel:`noopener ${s}`,className:Xr(a,i),title:l.title??l["aria-label"],children:Fb(Zr,{icon:e,shortcut:t,children:n})})})},qs=nC;nC.displayName="DropdownMenuItemLink";import{jsx as ZB}from"react/jsx-runtime";var rC=()=>ZB("div",{style:{height:"1px",backgroundColor:"var(--default-border-color)",margin:"6px 0",flex:"0 0 auto"}}),aC=rC;rC.displayName="DropdownMenuSeparator";import{DropdownMenu as oF}from"radix-ui";import jB from"clsx";import{DropdownMenu as qB}from"radix-ui";import{useCallback as JB,useState as iC}from"react";import{jsx as zb}from"react/jsx-runtime";var Ob=-4,QB=4,sC=({children:e,className:t})=>{let o=Te(),n=jB(`dropdown-menu dropdown-submenu ${t}`,{"dropdown-menu--mobile":o.formFactor==="phone"}).trim(),r=JB(c=>{if(c){let p=c.closest(".dropdown-menu-container")?.getBoundingClientRect();if(p){let d=c.getBoundingClientRect().width,h=window.innerWidth-p.right;h<d+20&&(i(h-d+Ob),l(Ob+8))}}},[]),[a,i]=iC(QB),[s,l]=iC(Ob);return zb(qB.SubContent,{className:n,sideOffset:a,alignOffset:s,collisionPadding:8,ref:r,children:o.formFactor==="phone"?zb(Rt.Col,{className:"dropdown-menu-container",children:e}):zb(gt,{className:"dropdown-menu-container",padding:2,style:{zIndex:1},children:e})})},lC=sC;sC.displayName="DropdownMenuSubContent";import{DropdownMenu as eF}from"radix-ui";import{jsx as cC,jsxs as tF}from"react/jsx-runtime";var dC=({children:e,icon:t,shortcut:o,className:n})=>tF(eF.SubTrigger,{className:`${Xr(n)} dropdown-menu__submenu-trigger`,children:[cC(Zr,{icon:t,shortcut:o,children:e}),cC("div",{className:"dropdown-menu__submenu-trigger-icon",children:xv})]}),mC=dC;dC.displayName="DropdownMenuSubTrigger";import pC from"react";var Op=e=>t=>{let o=pC.Children.toArray(t).find(n=>pC.isValidElement(n)&&typeof n.type!="string"&&n?.type.displayName&&n.type.displayName===e);return o||null},uC=Op("DropdownMenuTrigger"),gC=Op("DropdownMenuContent"),hC=Op("DropdownMenuSubTrigger"),fC=Op("DropdownMenuSubContent");import{jsxs as nF}from"react/jsx-runtime";var zp=({children:e})=>{let t=hC(e),o=fC(e);return nF(oF.Sub,{children:[t,o]})};zp.Trigger=mC;zp.Content=lC;zp.displayName="DropdownMenuSub";var aa=zp;import rF from"clsx";import{DropdownMenu as aF}from"radix-ui";import{jsx as iF}from"react/jsx-runtime";var bC=({className:e="",children:t,onToggle:o,title:n,...r})=>{let a=Te(),i=rF(`dropdown-menu-button ${e}`,"zen-mode-transition",{"dropdown-menu-button--mobile":a.formFactor==="phone"}).trim();return iF(aF.Trigger,{className:i,onClick:o,type:"button","data-testid":"dropdown-menu-button",title:n,...r,children:t})},xC=bC;bC.displayName="DropdownMenuTrigger";import{jsx as lF}from"react/jsx-runtime";var sF=e=>lF(to,{...e,icon:e.checked?bm:bv}),Ir=sF;import{jsx as pF,jsxs as mF}from"react/jsx-runtime";var xn=({children:e,open:t})=>{let o=uC(e),n=gC(e),r=n&&yC.isValidElement(n)?yC.cloneElement(n,{open:t}):n;return pF(cF.Root,{open:t,modal:!1,children:mF("div",{className:dF.DROPDOWN_MENU_EVENT_WRAPPER,style:{display:"contents"},children:[o,r]})})};xn.Trigger=xC;xn.Content=tC;xn.Item=to;xn.ItemCheckbox=Ir;xn.ItemLink=qs;xn.ItemCustom=oC;xn.Group=bc;xn.Separator=aC;xn.Sub=aa;var ye=xn;xn.displayName="DropdownMenu";import{jsx as bo,jsxs as Hp}from"react/jsx-runtime";var fF=(e,t)=>e.filter(o=>t.includes(o.id)),bF=({setAppState:e,selectedItems:t,library:o,onRemoveFromLibrary:n,resetLibrary:r,onSelectItems:a,appState:i,className:s})=>{let[l]=le(wr),[c,m]=le(js),p=()=>{let _=t.length?f("alerts.removeItemsFromsLibrary",{count:t.length}):f("alerts.resetLibrary"),k=t.length?f("confirmDialog.removeItemsFromLib"):f("confirmDialog.resetLibrary");return bo(Np,{onConfirm:()=>{t.length?n():r(),u(!1)},onCancel:()=>{u(!1)},title:k,children:bo("p",{children:_})})},[d,u]=Hb(!1),h=!!t.length,g=h?l.libraryItems.filter(_=>t.includes(_.id)):l.libraryItems,x=h?f("buttons.remove"):f("buttons.resetLibrary"),[E,y]=Hb(!1),[w,v]=Hb(null),I=gF(()=>Hp(bt,{onCloseRequest:()=>v(null),title:f("publishSuccessDialog.title"),className:"publish-library-success",size:"small",children:[bo("p",{children:bo(io,{i18nKey:"publishSuccessDialog.content",authorName:w.authorName,link:_=>bo("a",{href:w?.url,target:"_blank",rel:"noopener noreferrer",children:_})})}),bo(ae,{type:"button",title:f("buttons.close"),"aria-label":f("buttons.close"),label:f("buttons.close"),onClick:()=>v(null),"data-testid":"publish-library-success-close",className:"publish-library-success-close"})]}),[v,w]),C=(_,k)=>{y(!1),v({url:_.url,authorName:_.authorName});let M=k.slice();M.forEach(B=>{t.includes(B.id)&&(B.status="published")}),o.setLibrary(M)},P=async()=>{try{await o.updateLibrary({libraryItems:om({description:"Excalidraw library files"}),merge:!0,openLibraryMenu:!0})}catch(_){if(_?.name==="AbortError"){console.warn(_);return}e({errorMessage:f("errors.importLibraryError")})}},S=async()=>{let _=h?g:await o.getLatestLibrary();iE(_).catch(hF).catch(k=>{e({errorMessage:k.message})})},D=()=>Hp(ye,{open:c,children:[bo(ye.Trigger,{onToggle:()=>m(!c),children:PE}),Hp(ye.Content,{onClickOutside:()=>m(!1),onSelect:()=>m(!1),className:"library-menu",children:[!h&&bo(ye.Item,{onSelect:P,icon:rs,"data-testid":"lib-dropdown--load",children:f("buttons.load")}),!!g.length&&bo(ye.Item,{onSelect:S,icon:$a,"data-testid":"lib-dropdown--export",children:f("buttons.export")}),h&&bo(ye.Item,{icon:Fw,onSelect:()=>y(!0),"data-testid":"lib-dropdown--remove",children:f("buttons.publishLibrary")}),!!g.length&&bo(ye.Item,{onSelect:()=>u(!0),icon:Ut,children:x})]})]});return Hp("div",{className:uF("library-menu-dropdown-container",s),children:[D(),t.length>0&&bo("div",{className:"library-actions-counter",children:t.length}),d&&p(),E&&bo(ZT,{onClose:()=>y(!1),libraryItems:fF(l.libraryItems,t),appState:i,onSuccess:_=>C(_,l.libraryItems),onError:_=>window.alert(_),updateItemsInStorage:()=>o.setLibrary(l.libraryItems),onRemove:_=>a(t.filter(k=>k!==_))}),w&&I()]})},EC=({selectedItems:e,onSelectItems:t,className:o})=>{let{library:n}=tt(),{clearLibraryCache:r,deleteItemsFromLibraryCache:a}=Ks(),i=Ie(),s=Ce(),[l]=le(wr),c=async p=>{let d=p.filter(u=>!e.includes(u.id));n.setLibrary(d).catch(()=>{s({errorMessage:f("alerts.errorRemovingFromLibrary")})}),a(e),t([])};return bo(bF,{appState:i,setAppState:s,selectedItems:e,onSelectItems:t,library:n,onRemoveFromLibrary:()=>c(l.libraryItems),resetLibrary:()=>{n.resetLibrary(),r()},className:o})};import{memo as CF,useEffect as kF,useState as SF}from"react";import xF,{useCallback as yF}from"react";function EF(){return[!1,yF(t=>t(),[])]}var wC=xF.useTransition||EF;import vC from"clsx";import{memo as wF,useRef as vF,useState as IF}from"react";import{jsx as Gp,jsxs as TF}from"react/jsx-runtime";var IC=wF(({id:e,elements:t,isPending:o,onClick:n,selected:r,onToggle:a,onDrag:i,svgCache:s})=>{let l=vF(null),c=Pp(e,t,s,l),[m,p]=IF(!1),d=Te().formFactor==="phone",u=o&&Gp("div",{className:"library-unit__adder",children:ME});return TF("div",{className:vC("library-unit",{"library-unit__active":t,"library-unit--hover":t&&m,"library-unit--selected":r,"library-unit--skeleton":!c}),onMouseEnter:()=>p(!0),onMouseLeave:()=>p(!1),children:[Gp("div",{className:vC("library-unit__dragger",{"library-unit__pulse":!!o}),ref:l,draggable:!!t,onClick:t||o?h=>{e&&h.shiftKey?a(e,h):n(e)}:void 0,onDragStart:h=>{if(!e){h.preventDefault();return}p(!1),i(e,h)}}),u,e&&t&&(m||d||r)&&Gp(Tc,{checked:r,onChange:(h,g)=>a(e,g),className:"library-unit__checkbox"})]})}),TC=()=>Gp("div",{className:"library-unit library-unit--skeleton"});import{Fragment as MF,jsx as Up}from"react/jsx-runtime";var Wp=({children:e})=>Up("div",{className:"library-menu-items-container__grid",children:e}),$c=CF(({items:e,onItemSelectToggle:t,onItemDrag:o,isItemSelected:n,onClick:r,svgCache:a,itemsRenderedPerBatch:i})=>{let[,s]=wC(),[l,c]=SF(0);return kF(()=>{l<e.length&&s(()=>{c(l+i)})},[l,e.length,s,i]),Up(MF,{children:e.map((m,p)=>p<l?Up(IC,{elements:m?.elements,isPending:!m?.id&&!!m?.elements,onClick:r,svgCache:a,id:m?.id,selected:n(m.id),onToggle:t,onDrag:o},m?.id??p):Up(TC,{},p))})});import Gb from"clsx";import{forwardRef as _F,useRef as DF,useImperativeHandle as RF,useLayoutEffect as NF,useState as BF}from"react";import PF from"clsx";import{composeEventHandlers as AF}from"@orangecatai/common";import{jsx as LF}from"react/jsx-runtime";var so=({type:e="button",onSelect:t,selected:o,children:n,className:r="",...a})=>LF("button",{onClick:AF(a.onClick,i=>{t()}),type:e,className:PF("excalidraw-button",r,{selected:o}),...a,children:n});import{jsx as Ub,jsxs as CC}from"react/jsx-runtime";var ia=_F(({onChange:e,label:t,fullWidth:o,placeholder:n,readonly:r,selectOnRender:a,onKeyDown:i,isRedacted:s=!1,icon:l,className:c,type:m,...p},d)=>{let u=DF(null);RF(d,()=>u.current),NF(()=>{a&&(u.current?.focus(),u.current?.select())},[a]);let[h,g]=BF(!1);return CC("div",{className:Gb("ExcTextField",c,{"ExcTextField--fullWidth":o,"ExcTextField--hasIcon":!!l}),onClick:()=>{u.current?.focus()},children:[l,t&&Ub("div",{className:"ExcTextField__label",children:t}),CC("div",{className:Gb("ExcTextField__input",{"ExcTextField__input--readonly":r}),children:[Ub("input",{className:Gb({"is-redacted":"value"in p&&p.value&&s&&!h}),readOnly:r,value:"value"in p?p.value:void 0,defaultValue:"defaultValue"in p?p.defaultValue:void 0,placeholder:n,ref:u,onChange:x=>e?.(x.target.value),onKeyDown:i,type:m}),s&&Ub(so,{onSelect:()=>g(!h),style:{border:0,userSelect:"none"},children:h?Vw:ls})]})]})});import{Fragment as MC,jsx as Nt,jsxs as $n}from"react/jsx-runtime";var UF=17,WF=64;function $b({isLoading:e,libraryItems:t,onAddToLibrary:o,onInsertLibraryItems:n,pendingElements:r,theme:a,id:i,libraryReturnUrl:s,onSelectItems:l,selectedItems:c}){let m=Te(),p=kC(null),d=WT(p);Wb(()=>{d>0&&p.current?.scrollTo(0,d)},[]);let{svgCache:u}=Ks(),[h,g]=SC(null),[x,E]=SC(""),y=!t.length&&!r.length,w=!y&&!!x.trim(),v=Yb(()=>{let L=ri(x.trim().toLowerCase());return L?t.filter(F=>{let $=F.name||"";return $.trim()&&ri($.toLowerCase()).includes(L)}):[]},[t,x]),I=Yb(()=>t.filter(L=>L.status!=="published"),[t]),C=Yb(()=>t.filter(L=>L.status==="published"),[t]),P=Js((L,F)=>{let $=!c.includes(L),Q=[...I,...C];if($){if(F.shiftKey&&h){let Z=Q.findIndex(fe=>fe.id===h),U=Q.findIndex(fe=>fe.id===L);if(Z===-1||U===-1){l([...c,L]);return}let q=OF(c),re=Math.min(Z,U),J=Math.max(Z,U),se=Q.reduce((fe,Me,ct)=>((ct>=re&&ct<=J||q.has(Me.id))&&fe.push(Me.id),fe),[]);l(se)}else l([...c,L]);g(L)}else g(null),l(c.filter(Z=>Z!==L))},[h,l,C,c,I]);Wb(()=>{c.length||g(null)},[c]);let S=Js(L=>{let F;return c.includes(L)?F=t.filter($=>c.includes($.id)):F=t.filter($=>$.id===L),F.map($=>({...$,elements:HF({type:"everything",elements:$.elements,randomizeSeed:!0}).duplicatedElements}))},[t,c]),D=Js((L,F)=>{let $={itemIds:c.includes(L)?c:[L]};F.dataTransfer.setData(FF.excalidrawlibIds,JSON.stringify($))},[c]),_=Js(L=>L?c.includes(L):!1,[c]),k=Js(()=>{o(r)},[r,o]),M=Js(L=>{L&&n(S(L))},[S,n]),B=u.size>=(v.length?v:t).length?WF:UF,O=kC(null);Wb(()=>{zF(()=>{O.current?.focus()})},[]);let N=!w&&$n(MC,{children:[!y&&Nt("div",{className:"library-menu-items-container__header",children:f("labels.personalLib")}),!r.length&&!I.length?$n("div",{className:"library-menu-items__no-items",children:[!C.length&&Nt("div",{className:"library-menu-items__no-items__label",children:f("library.noItems")}),Nt("div",{className:"library-menu-items__no-items__hint",children:C.length>0?f("library.hint_emptyPrivateLibrary"):f("library.hint_emptyLibrary")})]}):$n(Wp,{children:[r.length>0&&Nt($c,{itemsRenderedPerBatch:B,items:[{id:null,elements:r}],onItemSelectToggle:P,onItemDrag:D,onClick:k,isItemSelected:_,svgCache:u}),Nt($c,{itemsRenderedPerBatch:B,items:I,onItemSelectToggle:P,onItemDrag:D,onClick:M,isItemSelected:_,svgCache:u})]}),C.length>0&&Nt("div",{className:"library-menu-items-container__header",style:{marginTop:"0.75rem"},children:f("labels.excalidrawLib")}),C.length>0&&Nt(Wp,{children:Nt($c,{itemsRenderedPerBatch:B,items:C,onItemSelectToggle:P,onItemDrag:D,onClick:M,isItemSelected:_,svgCache:u})})]}),z=w&&$n(MC,{children:[$n("div",{className:"library-menu-items-container__header",children:[f("library.search.heading"),!e&&$n("div",{className:"library-menu-items-container__header__hint",style:{cursor:"pointer"},onPointerDown:L=>L.preventDefault(),onClick:L=>{E("")},children:[Nt("kbd",{children:"esc"})," to clear"]})]}),v.length>0?Nt(Wp,{children:Nt($c,{itemsRenderedPerBatch:B,items:v,onItemSelectToggle:P,onItemDrag:D,onClick:M,isItemSelected:_,svgCache:u})}):$n("div",{className:"library-menu-items__no-items",children:[Nt("div",{className:"library-menu-items__no-items__hint",children:f("library.search.noResults")}),Nt(so,{onPointerDown:L=>L.preventDefault(),onSelect:()=>{E("")},style:{width:"auto",marginTop:"1rem"},children:f("library.search.clearSearch")})]})]});return $n("div",{className:"library-menu-items-container",style:r.length||I.length||C.length?{justifyContent:"flex-start"}:{borderBottom:0},children:[$n("div",{className:"library-menu-items-header",children:[!y&&Nt(ia,{ref:O,type:"search",className:GF("library-menu-items-container__search",{hideCancelButton:m.formFactor!=="phone"}),placeholder:f("library.search.inputPlaceholder"),value:x,onChange:L=>E(L)}),Nt(EC,{selectedItems:c,onSelectItems:l,className:"library-menu-dropdown-container--in-heading"})]}),$n(Rt.Col,{className:"library-menu-items-container__items",align:"start",gap:1,style:{flex:C.length>0?1:"0 1 auto",margin:y?"auto":0},ref:p,children:[e&&Nt("div",{style:{position:"absolute",top:"var(--container-padding-y)",right:"var(--container-padding-x)",transform:"translateY(50%)"},children:Nt(Wt,{})}),N,z,y&&Nt(Dp,{style:{padding:"16px 0",width:"100%"},id:i,libraryReturnUrl:s,theme:a})]})]})}import{jsx as sa,jsxs as LC}from"react/jsx-runtime";var js=Pe(!1),AC=({children:e})=>sa("div",{className:"layer-ui__library",children:e}),JF=RC(({onInsertLibraryItems:e,pendingElements:t,onAddToLibrary:o,setAppState:n,libraryReturnUrl:r,library:a,id:i,theme:s,selectedItems:l,onSelectItems:c})=>{let[m]=le(wr),p=Kb(h=>{(async(x,E)=>{be("element","addToLibrary","ui");for(let w of $F)if(x.some(v=>v.type===w))return n({errorMessage:f(`errors.libraryElementTypeError.${w}`)});let y=[{status:"unpublished",elements:x,id:VF(),created:Date.now()},...E];o(),a.setLibrary(y).catch(()=>{n({errorMessage:f("alerts.errorAddingToLibrary")})})})(h,m.libraryItems)},[o,a,n,m.libraryItems]),d=DC(()=>m.libraryItems,[m]);if(m.status==="loading"&&!m.isInitialized)return sa(AC,{children:sa("div",{className:"layer-ui__library-message",children:LC("div",{children:[sa(Wt,{size:"2em"}),sa("span",{children:f("labels.libraryLoadingMessage")})]})})});let u=m.libraryItems.length>0||t.length>0;return LC(AC,{children:[sa($b,{isLoading:m.status==="loading",libraryItems:d,onAddToLibrary:p,onInsertLibraryItems:e,pendingElements:t,id:i,libraryReturnUrl:r,theme:s,onSelectItems:c,selectedItems:l}),u&&sa(Dp,{className:"library-menu-control-buttons--at-bottom",style:{padding:"16px 12px 0 12px"},id:i,libraryReturnUrl:r,theme:s})]})}),Vb=(e,t)=>({elements:e,pending:de(e,{selectedElementIds:t},{includeBoundTextElement:!0,includeElementsInFrames:!0}),selectedElementIds:t}),QF=(e,t)=>{let o=$r(),[n,r]=_C(()=>Vb(o,e.selectedElementIds)),a=YF(new Map);return Xb(()=>{for(let i of n.pending)a.current.set(i.id,i.version)},[n.pending]),Xb(()=>{t.state.cursorButton==="up"&&t.state.activeTool.type==="selection"&&r(i=>{if(!KF(i.selectedElementIds,e.selectedElementIds))return a.current.clear(),Vb(o,e.selectedElementIds);let s=t.scene.getNonDeletedElementsMap();for(let l of Object.keys(e.selectedElementIds)){let c=s.get(l)?.version;if(c&&c!==a.current.get(l))return Vb(o,e.selectedElementIds)}return i})},[t,t.state.cursorButton,t.state.activeTool.type,e.selectedElementIds,o]),n.pending},NC=RC(()=>{let e=tt(),{onInsertElements:t}=e,o=Hn(),n=Ie(),r=Ce(),[a,i]=_C([]),s=DC(()=>e.library,[e.library]),l=QF(n,e);Xb(()=>jF(document,qF.KEYDOWN,p=>{if(p.key===XF.ESCAPE&&p.target instanceof HTMLElement){let d=p.target;if(d.closest(`.${PC.SIDEBAR}`))a.length>0?(p.stopPropagation(),i([])):ZF(d)&&d instanceof HTMLInputElement&&!d.value&&(p.stopPropagation(),r({openSidebar:null}),e.focusContainer());else if(a.length>0){let{x:u,y:h}=e.lastViewportPosition;document.elementFromPoint(u,h)?.closest(`.${PC.SIDEBAR}`)&&(p.stopPropagation(),i([]))}}},{capture:!0}),[a,r,e]);let c=Kb(p=>{t(Zs(p)),e.focusContainer()},[t,e]),m=Kb(()=>{r({selectedElementIds:{},selectedGroupIds:{},activeEmbeddable:null})},[r]);return sa(JF,{pendingElements:l,onInsertLibraryItems:c,onAddToLibrary:m,setAppState:r,libraryReturnUrl:o.libraryReturnUrl,library:s,id:e.id,theme:n.theme,selectedItems:a,onSelectItems:i})});import eO from"clsx";import{useRef as tO}from"react";import{createPortal as oO}from"react-dom";import{KEYS as nO}from"@orangecatai/common";import{jsx as BC,jsxs as rO}from"react/jsx-runtime";var FC=e=>{let{closeOnClickOutside:t=!0}=e,o=Rm({className:"excalidraw-modal-container"}),n=tO(document.body.classList.contains("excalidraw-animations-disabled"));if(!o)return null;let r=a=>{a.key===nO.ESCAPE&&(a.nativeEvent.stopImmediatePropagation(),a.stopPropagation(),e.onCloseRequest())};return oO(rO("div",{className:eO("Modal",e.className,{"animations-disabled":n.current}),role:"dialog","aria-modal":"true",onKeyDown:r,"aria-labelledby":e.labelledBy,children:[BC("div",{className:"Modal__background",onClick:t?e.onCloseRequest:void 0}),BC("div",{className:"Modal__content",style:{"--max-width":`${e.maxWidth}px`},tabIndex:0,children:e.children})]}),o)};import{jsx as Vc,jsxs as dO}from"react/jsx-runtime";function cO(e){if(e&&typeof e=="number")return e;switch(e){case"small":return 550;case"wide":return 1024;case"regular":default:return 800}}var bt=e=>{let[t,o]=PT(),[n]=sO(document.activeElement),{id:r}=Qe(),a=Te().formFactor==="phone";iO(()=>{if(!t)return;let c=OC(t);setTimeout(()=>{c.length>0&&e.autofocus!==!1&&(c[1]||c[0]).focus()});let m=p=>{if(p.key===lO.TAB){let d=OC(t),{activeElement:u}=document,h=d.findIndex(g=>g===u);h===0&&p.shiftKey?(d[d.length-1].focus(),p.preventDefault()):h===d.length-1&&!p.shiftKey&&(d[0].focus(),p.preventDefault())}};return t.addEventListener("keydown",m),()=>t.removeEventListener("keydown",m)},[t,e.autofocus]);let i=Ce(),s=Rn(js),l=()=>{i({openMenu:null}),s(!1),n.focus(),e.onCloseRequest()};return Vc(FC,{className:aO("Dialog",e.className,{"Dialog--fullscreen":a}),labelledBy:"dialog-title",maxWidth:cO(e.size),onCloseRequest:l,closeOnClickOutside:e.closeOnClickOutside,children:dO(gt,{ref:o,children:[e.title&&Vc("h2",{id:`${r}-dialog-title`,className:"Dialog__title",children:Vc("span",{className:"Dialog__titleContent",children:e.title})}),a&&Vc("button",{className:"Dialog__close",onClick:l,title:f("buttons.close"),"aria-label":f("buttons.close"),type:"button",children:Go}),Vc("div",{className:"Dialog__content",children:e.children})]})})};import{KEYS as dt}from"@orangecatai/common";var Yp=[{icon:as,value:"hand",key:dt.H,numericKey:null,fillable:!1,toolbar:!0},{icon:Ya,value:"selection",key:dt.V,numericKey:dt[1],fillable:!0,toolbar:!0},{icon:qi,value:"rectangle",key:dt.R,numericKey:dt[2],fillable:!0,toolbar:!0},{icon:Ji,value:"diamond",key:dt.D,numericKey:dt[3],fillable:!0,toolbar:!0},{icon:Qi,value:"ellipse",key:dt.O,numericKey:dt[4],fillable:!0,toolbar:!0},{icon:gm,value:"arrow",key:dt.A,numericKey:dt[5],fillable:!0,toolbar:!0},{icon:es,value:"line",key:dt.L,numericKey:dt[6],fillable:!0,toolbar:!0},{icon:Bn,value:"freedraw",key:[dt.P,dt.X],numericKey:dt[7],fillable:!1,toolbar:!0},{icon:Fn,value:"text",key:dt.T,numericKey:dt[8],fillable:!1,toolbar:!0},{icon:ts,value:"image",key:null,numericKey:dt[9],fillable:!1,toolbar:!0},{icon:hm,value:"eraser",key:dt.E,numericKey:dt[0],fillable:!1,toolbar:!0},{icon:zn,value:"laser",key:dt.K,numericKey:null,fillable:!1,toolbar:!1}],Zb=e=>e.state.preferredSelectionTool.type==="lasso"?[{value:"lasso",icon:Ya,key:dt.V,numericKey:dt[1],fillable:!0,toolbar:!0},...Yp.slice(1)]:Yp,zC=(e,t)=>Zb(t).find((n,r)=>n.numericKey!=null&&e===n.numericKey.toString()||n.key&&(typeof n.key=="string"?n.key===e:n.key.includes(e)))?.value||null;import Kn from"clsx";import{useRef as yO,useState as EO}from"react";import{Popover as ca}from"radix-ui";import{CLASSES as $C,KEYS as wO,capitalizeString as la,isTransparent as Vp}from"@orangecatai/common";import{shouldAllowVerticalAlign as VC,suppportsHorizontalAlign as KC,hasBoundTextElement as Kp,isElbowArrow as Qb,isImageElement as XC,isLinearElement as e0,isTextElement as Zp,isArrowElement as WC,hasStrokeColor as YC,toolIsArrow as Xp}from"@orangecatai/element";import{createIsolation as mO}from"jotai-scope";import jb from"react";import Vn from"tunnel-rat";var qb=jb.createContext(null),Ze=()=>jb.useContext(qb),pO=mO(),HC=()=>jb.useMemo(()=>({MainMenuTunnel:Vn(),WelcomeScreenMenuHintTunnel:Vn(),WelcomeScreenToolbarHintTunnel:Vn(),WelcomeScreenHelpHintTunnel:Vn(),WelcomeScreenCenterTunnel:Vn(),FooterCenterTunnel:Vn(),DefaultSidebarTriggerTunnel:Vn(),DefaultSidebarTabTriggersTunnel:Vn(),OverwriteConfirmDialogTunnel:Vn(),TTDDialogTriggerTunnel:Vn(),tunnelsJotai:pO}),[]);import{CODES as uO,KEYS as gO}from"@orangecatai/common";import{CaptureUpdateAction as hO}from"@orangecatai/element";var ii=W({name:"viewMode",label:"labels.viewMode",icon:ls,viewMode:!0,trackEvent:{category:"canvas",predicate:e=>!e.viewModeEnabled},perform(e,t){return{appState:{...t,viewModeEnabled:!this.checked(t)},captureUpdate:hO.EVENTUALLY}},checked:e=>e.viewModeEnabled,predicate:(e,t,o)=>typeof o.viewModeEnabled>"u",keyTest:e=>!e[gO.CTRL_OR_CMD]&&e.altKey&&e.code===uO.R});import{useEffect as fO,useState as bO}from"react";import GC from"clsx";import{capitalizeString as UC}from"@orangecatai/common";import{Popover as Jb}from"radix-ui";import{jsx as $p,jsxs as xO}from"react/jsx-runtime";var Qs=({app:e,options:t,activeTool:o,defaultOption:n,className:r="Shape",namePrefix:a,title:i,"data-testid":s,onToolChange:l,displayedOption:c,fillable:m=!1})=>{let[p,d]=bO(!1),u=o.type,h=c.type===u,g=32/2+10,{container:x}=Qe();return!t.some(E=>E.type===u)&&p&&d(!1),fO(()=>{let E=e.onPointerDownEmitter.on(()=>{d(!1)});return()=>E?.()},[e]),xO(Jb.Root,{open:p,children:[$p(Jb.Trigger,{asChild:!0,children:$p(ae,{className:GC(r,{fillable:m,active:t.some(E=>E.type===o.type)}),type:"radio",icon:c.icon,checked:h,name:"editor-current-shape",title:i,"aria-label":i,"data-testid":s,onPointerDown:()=>{d(E=>!E),l(n)}})}),$p(Jb.Content,{className:"tool-popover-content",sideOffset:g,collisionBoundary:x??void 0,children:t.map(({type:E,icon:y,title:w})=>$p(ae,{className:GC(r,{active:u===E}),type:"radio",icon:y,checked:u===E,name:`${a}-option`,title:w||UC(E),keyBindingLabel:"","aria-label":w||UC(E),"data-testid":`toolbar-${E}`,onChange:()=>{e.state.activeTool.type!==E&&be("toolbar",E,"ui"),e.setActiveTool({type:E}),l?.(E)}},E))})]})};import{Fragment as Do,jsx as ie,jsxs as ke}from"react/jsx-runtime";var t0=Kn([$C.SHAPE_ACTIONS_THEME_SCOPE,"properties-content"]),Kc=(e,t)=>{let o=t[0]?.type||null;for(let n of t)if(n.type!==o){o=null;break}return YC(e.activeTool.type)&&o!=="image"&&o!=="frame"&&o!=="magicframe"||t.some(n=>YC(n.type))},Xc=(e,t)=>_n(e.activeTool.type)||t.some(o=>_n(o.type)),ZC=({appState:e,elementsMap:t,renderAction:o,app:n})=>{let r=Hi(t,e),a=!1;r.length===2&&(Kp(r[0])||Kp(r[1]))&&(a=!0);let i=!!(e.editingTextElement||e.newElement),s=Te(),l=document.documentElement.getAttribute("dir")==="rtl",c=_n(e.activeTool.type)&&!Vp(e.currentItemBackgroundColor)||r.some(h=>_n(h.type)&&!Vp(h.backgroundColor)),m=r.length===1||a,p=!e.selectedLinearElement?.isEditing&&r.length===1&&e0(r[0])&&!Qb(r[0]),d=!e.croppingElementId&&r.length===1&&XC(r[0]),u=!a&&ao(e,n);return ke("div",{className:"selected-shape-actions",children:[ie("div",{children:Kc(e,r)&&o("changeStrokeColor")}),Xc(e,r)&&ie("div",{children:o("changeBackgroundColor")}),c&&o("changeFillStyle"),(Kl(e.activeTool.type)||r.some(h=>Kl(h.type)))&&o("changeStrokeWidth"),(e.activeTool.type==="freedraw"||r.some(h=>h.type==="freedraw"))&&o("changeStrokeShape"),(Xl(e.activeTool.type)||r.some(h=>Xl(h.type)))&&ke(Do,{children:[o("changeStrokeStyle"),o("changeSloppiness")]}),(Zl(e.activeTool.type)||r.some(h=>Zl(h.type)))&&ie(Do,{children:o("changeRoundness")}),(Xp(e.activeTool.type)||r.some(h=>Xp(h.type)))&&ie(Do,{children:o("changeArrowType")}),(e.activeTool.type==="text"||r.some(Zp))&&ke(Do,{children:[o("changeFontFamily"),o("changeFontSize"),(e.activeTool.type==="text"||KC(r,t))&&o("changeTextAlign")]}),VC(r,t)&&o("changeVerticalAlign"),(Gi(e.activeTool.type)||r.some(h=>Gi(h.type)))&&ie(Do,{children:o("changeArrowhead")}),o("changeOpacity"),ke("fieldset",{children:[ie("legend",{children:f("labels.layers")}),ke("div",{className:"buttonList",children:[o("sendToBack"),o("sendBackward"),o("bringForward"),o("bringToFront")]})]}),u&&!a&&ke("fieldset",{children:[ie("legend",{children:f("labels.align")}),ke("div",{className:"buttonList",children:[l?ke(Do,{children:[o("alignRight"),o("alignHorizontallyCentered"),o("alignLeft")]}):ke(Do,{children:[o("alignLeft"),o("alignHorizontallyCentered"),o("alignRight")]}),r.length>2&&o("distributeHorizontally"),ie("div",{style:{flexBasis:"100%",height:0}}),ke("div",{style:{display:"flex",flexWrap:"wrap",gap:".5rem",marginTop:"-0.5rem"},children:[o("alignTop"),o("alignVerticallyCentered"),o("alignBottom"),r.length>2&&o("distributeVertically")]})]})]}),!i&&r.length>0&&ke("fieldset",{children:[ie("legend",{children:f("labels.actions")}),ke("div",{className:"buttonList",children:[s.formFactor!=="phone"&&o("duplicateSelection"),s.formFactor!=="phone"&&o("deleteSelectedElements"),o("group"),o("ungroup"),m&&o("hyperlink"),d&&o("cropEditor"),p&&o("toggleLinearEditor")]})]})]})},jC=({appState:e,renderAction:t,setAppState:o,targetElements:n,container:r})=>{let a=_n(e.activeTool.type)&&!Vp(e.currentItemBackgroundColor)||n.some(l=>_n(l.type)&&!Vp(l.backgroundColor)),i=n.length>0||e.activeTool.type!=="selection"&&e.activeTool.type!=="eraser"&&e.activeTool.type!=="hand"&&e.activeTool.type!=="laser"&&e.activeTool.type!=="lasso",s=e.openPopup==="compactStrokeStyles";return i?ie("div",{className:"compact-action-item",children:ke(ca.Root,{open:s,onOpenChange:l=>{o(l?{openPopup:"compactStrokeStyles"}:{openPopup:null})},children:[ie(ca.Trigger,{asChild:!0,children:ie("button",{type:"button",className:Kn("compact-action-button properties-trigger",{active:s}),title:f("labels.stroke"),onClick:l=>{l.preventDefault(),l.stopPropagation(),o({openPopup:s?null:"compactStrokeStyles"})},children:uv})}),s&&ie(gr,{className:t0,container:r,style:{maxWidth:"13rem"},onClose:()=>{},children:ke("div",{className:"selected-shape-actions",children:[a&&t("changeFillStyle"),(Kl(e.activeTool.type)||n.some(l=>Kl(l.type)))&&t("changeStrokeWidth"),(Xl(e.activeTool.type)||n.some(l=>Xl(l.type)))&&ke(Do,{children:[t("changeStrokeStyle"),t("changeSloppiness")]}),(Zl(e.activeTool.type)||n.some(l=>Zl(l.type)))&&t("changeRoundness"),t("changeOpacity")]})})]})}):null},qC=({appState:e,renderAction:t,setAppState:o,targetElements:n,container:r,app:a})=>{let i=Xp(e.activeTool.type)||n.some(l=>Xp(l.type)),s=e.openPopup==="compactArrowProperties";return i?ie("div",{className:"compact-action-item",children:ke(ca.Root,{open:s,onOpenChange:l=>{o(l?{openPopup:"compactArrowProperties"}:{openPopup:null})},children:[ie(ca.Trigger,{asChild:!0,children:ie("button",{type:"button",className:Kn("compact-action-button properties-trigger",{active:s}),title:f("labels.arrowtypes"),onClick:l=>{l.preventDefault(),l.stopPropagation(),o({openPopup:s?null:"compactArrowProperties"})},children:(()=>{let l=Kt(n,a,c=>WC(c)?c.elbowed?"elbow":c.roundness?"round":"sharp":null,c=>WC(c),c=>c?null:e.currentItemArrowType);return l==="elbow"?ms:l==="round"?ps:ds})()})}),s&&ie(gr,{container:r,className:"properties-content",style:{maxWidth:"13rem"},onClose:()=>{},children:t("changeArrowProperties")})]})}):null},JC=({appState:e,renderAction:t,setAppState:o,targetElements:n,container:r,elementsMap:a})=>{let{saveCaretPosition:i,restoreCaretPosition:s}=Nv(),l=e.openPopup==="compactTextProperties";return ie("div",{className:"compact-action-item",children:ke(ca.Root,{open:l,onOpenChange:c=>{c?(e.editingTextElement&&i(),o({openPopup:"compactTextProperties"})):(o({openPopup:null}),e.editingTextElement&&s())},children:[ie(ca.Trigger,{asChild:!0,children:ie("button",{type:"button",className:Kn("compact-action-button properties-trigger",{active:l}),title:f("labels.textAlign"),onClick:c=>{c.preventDefault(),c.stopPropagation(),l?o({openPopup:null}):(e.editingTextElement&&i(),o({openPopup:"compactTextProperties"}))},children:FE})}),e.openPopup==="compactTextProperties"&&ie(gr,{className:t0,container:r,style:{maxWidth:"13rem"},preventAutoFocusOnTouch:!!e.editingTextElement,onClose:()=>{e.editingTextElement&&s()},children:ke("div",{className:"selected-shape-actions",children:[(e.activeTool.type==="text"||n.some(Zp))&&t("changeFontSize"),(e.activeTool.type==="text"||KC(n,a))&&t("changeTextAlign"),VC(n,a)&&t("changeVerticalAlign")]})})]})})},QC=({appState:e,renderAction:t,targetElements:o,setAppState:n,container:r,app:a,showDuplicate:i,showDelete:s})=>{let l=!!(e.editingTextElement||e.newElement),c=!e.croppingElementId&&o.length===1&&XC(o[0]),m=o.length===1,p=ao(e,a),d=!1;o.length===2&&(Kp(o[0])||Kp(o[1]))&&(d=!0);let u=document.documentElement.getAttribute("dir")==="rtl",h=e.openPopup==="compactOtherProperties";return l||o.length===0?null:ie("div",{className:"compact-action-item",children:ke(ca.Root,{open:h,onOpenChange:g=>{n(g?{openPopup:"compactOtherProperties"}:{openPopup:null})},children:[ie(ca.Trigger,{asChild:!0,children:ie("button",{type:"button",className:Kn("compact-action-button properties-trigger",{active:h}),title:f("labels.actions"),onClick:g=>{g.preventDefault(),g.stopPropagation(),n({openPopup:h?null:"compactOtherProperties"})},children:AE})}),h&&ie(gr,{className:t0,container:r,style:{maxWidth:"12rem",justifyContent:"center",alignItems:"center"},onClose:()=>{},children:ke("div",{className:"selected-shape-actions",children:[ke("fieldset",{children:[ie("legend",{children:f("labels.layers")}),ke("div",{className:"buttonList",children:[t("sendToBack"),t("sendBackward"),t("bringForward"),t("bringToFront")]})]}),p&&!d&&ke("fieldset",{children:[ie("legend",{children:f("labels.align")}),ke("div",{className:"buttonList",children:[u?ke(Do,{children:[t("alignRight"),t("alignHorizontallyCentered"),t("alignLeft")]}):ke(Do,{children:[t("alignLeft"),t("alignHorizontallyCentered"),t("alignRight")]}),o.length>2&&t("distributeHorizontally"),ie("div",{style:{flexBasis:"100%",height:0}}),ke("div",{style:{display:"flex",flexWrap:"wrap",gap:".5rem",marginTop:"-0.5rem"},children:[t("alignTop"),t("alignVerticallyCentered"),t("alignBottom"),o.length>2&&t("distributeVertically")]})]})]}),ke("fieldset",{children:[ie("legend",{children:f("labels.actions")}),ke("div",{className:"buttonList",children:[t("group"),t("ungroup"),m&&t("hyperlink"),c&&t("cropEditor"),i&&t("duplicateSelection"),s&&t("deleteSelectedElements")]})]})]})})]})})},vO=({appState:e,renderAction:t,targetElements:o})=>!e.selectedLinearElement?.isEditing&&o.length===1&&e0(o[0])&&!Qb(o[0])?ie("div",{className:"compact-action-item",children:t("toggleLinearEditor")}):null,e5=({appState:e,elementsMap:t,renderAction:o,app:n,setAppState:r})=>{let a=Hi(t,e),{container:i}=Qe(),s=!!(e.editingTextElement||e.newElement),l=!e.selectedLinearElement?.isEditing&&a.length===1&&e0(a[0])&&!Qb(a[0]);return ke("div",{className:"compact-shape-actions",children:[Kc(e,a)&&ie("div",{className:Kn("compact-action-item"),children:o("changeStrokeColor")}),Xc(e,a)&&ie("div",{className:"compact-action-item",children:o("changeBackgroundColor")}),ie(jC,{appState:e,renderAction:o,setAppState:r,targetElements:a,container:i}),ie(qC,{appState:e,renderAction:o,setAppState:r,targetElements:a,container:i,app:n}),l&&ie("div",{className:"compact-action-item",children:o("toggleLinearEditor")}),(e.activeTool.type==="text"||a.some(Zp))&&ke(Do,{children:[ie("div",{className:"compact-action-item",children:o("changeFontFamily")}),ie(JC,{appState:e,renderAction:o,setAppState:r,targetElements:a,container:i,elementsMap:t})]}),!s&&a.length>0&&ie("div",{className:"compact-action-item",children:o("duplicateSelection")}),!s&&a.length>0&&ie("div",{className:"compact-action-item",children:o("deleteSelectedElements")}),ie(QC,{appState:e,renderAction:o,targetElements:a,setAppState:r,container:i,app:n})]})},t5=({appState:e,elementsMap:t,renderAction:o,app:n,setAppState:r})=>{let a=Hi(t,e),{container:i}=Qe(),s=yO(null),l=s.current?.getBoundingClientRect()?.width??0,c=9,m=6,p=32,d=c*p+(c-1)*m,u=p+m,h=l>=d+u,g=l>=d+2*u;return ke(gt,{className:"compact-shape-actions mobile-shape-actions",style:{flexDirection:"row",boxShadow:"none",padding:0,zIndex:2,backgroundColor:"transparent",height:p*1.35,marginBottom:4,alignItems:"center",gap:m,pointerEvents:"none"},ref:s,children:[ke("div",{style:{display:"flex",flexDirection:"row",gap:m,flex:1},children:[Kc(e,a)&&ie("div",{className:Kn("compact-action-item"),children:o("changeStrokeColor")}),Xc(e,a)&&ie("div",{className:"compact-action-item",children:o("changeBackgroundColor")}),ie(jC,{appState:e,renderAction:o,setAppState:r,targetElements:a,container:i}),ie(qC,{appState:e,renderAction:o,setAppState:r,targetElements:a,container:i,app:n}),ie(vO,{appState:e,renderAction:o,targetElements:a}),(e.activeTool.type==="text"||a.some(Zp))&&ke(Do,{children:[ie("div",{className:"compact-action-item",children:o("changeFontFamily")}),ie(JC,{appState:e,renderAction:o,setAppState:r,targetElements:a,container:i,elementsMap:t})]}),ie(QC,{appState:e,renderAction:o,targetElements:a,setAppState:r,container:i,app:n,showDuplicate:!g,showDelete:!h})]}),ke("div",{style:{display:"flex",flexDirection:"row",gap:m},children:[ie("div",{className:"compact-action-item",children:o("undo")}),ie("div",{className:"compact-action-item",children:o("redo")}),g&&ie("div",{className:"compact-action-item",children:o("duplicateSelection")}),h&&ie("div",{className:"compact-action-item",children:o("deleteSelectedElements")})]})]})},o5=({activeTool:e,setAppState:t,app:o,UIOptions:n})=>{let[r,a]=EO(!1),i=Dt(),s=i==="full",l=i==="compact",c=[{type:"selection",icon:Ya,title:la(f("toolBar.selection"))},{type:"lasso",icon:Hr,title:la(f("toolBar.lasso"))}],m=e.type==="frame",p=e.type==="laser",d=s&&e.type==="lasso"&&o.state.preferredSelectionTool.type!=="lasso",u=e.type==="embeddable",{TTDDialogTriggerTunnel:h}=Ze();return ke(Do,{children:[Zb(o).map(({value:g,icon:x,key:E,numericKey:y,fillable:w,toolbar:v})=>{if(v===!1||n.tools?.[g]===!1)return null;let I=f(`toolBar.${g}`),C=E&&la(typeof E=="string"?E:E[0]),P=C?`${C} ${f("helpDialog.or")} ${y}`:`${y}`,S=g==="hand"?void 0:y||C;return(g==="selection"||g==="lasso")&&l?ie(Qs,{app:o,options:c,activeTool:e,defaultOption:o.state.preferredSelectionTool.type,namePrefix:"selectionType",title:la(f("toolBar.selection")),"data-testid":"toolbar-selection",onToolChange:D=>{(D==="selection"||D==="lasso")&&(o.setActiveTool({type:D}),t({preferredSelectionTool:{type:D,initialized:!0}}))},displayedOption:c.find(D=>D.type===o.state.preferredSelectionTool.type)||c[0],fillable:e.type==="selection"},"selection-popover"):ie(ae,{className:Kn("Shape",{fillable:w}),type:"radio",icon:x,checked:e.type===g,name:"editor-current-shape",title:`${la(I)} \u2014 ${P}`,keyBindingLabel:S,"aria-label":la(I),"aria-keyshortcuts":P,"data-testid":`toolbar-${g}`,onPointerDown:({pointerType:D})=>{!o.state.penDetected&&D==="pen"&&o.togglePenMode(!0),g==="selection"&&(o.state.activeTool.type==="selection"?o.setActiveTool({type:"lasso"}):o.setActiveTool({type:"selection"}))},onChange:({pointerType:D})=>{o.state.activeTool.type!==g&&be("toolbar",g,"ui"),g==="image"?o.setActiveTool({type:g}):o.setActiveTool({type:g})}},g)}),ie("div",{className:"App-toolbar__divider"}),ie(ae,{className:"Shape",type:"radio",icon:Uw,checked:!1,name:"editor-current-shape",title:"Image Generator \u2014 A",keyBindingLabel:"A","aria-label":"Image Generator","data-testid":"toolbar-image-generator",onChange:()=>{be("toolbar","imageGenerator","ui"),o.onImageGeneratorSelect()}}),ie(ae,{className:"Shape",type:"radio",icon:On,checked:m,name:"editor-current-shape",title:`${la(f("toolBar.frame"))} \u2014 F`,keyBindingLabel:"F","aria-label":la(f("toolBar.frame")),"data-testid":"toolbar-frame",onChange:()=>{be("toolbar","frame","ui"),o.setActiveTool({type:"frame"})}}),ke(ye,{open:r,children:[ie(ye.Trigger,{className:Kn("App-toolbar__extra-tools-trigger",{"App-toolbar__extra-tools-trigger--selected":u||d||p&&!o.props.isCollaborating}),onToggle:()=>{a(!r),t({openMenu:null,openPopup:null})},title:f("toolBar.extraTools"),children:u?os:p&&!o.props.isCollaborating?zn:d?Hr:ic}),ke(ye.Content,{onClickOutside:()=>a(!1),onSelect:()=>a(!1),className:"App-toolbar__extra-tools-dropdown",children:[ie(ye.Item,{onSelect:()=>o.setActiveTool({type:"embeddable"}),icon:os,"data-testid":"toolbar-embeddable",selected:u,children:f("toolBar.embeddable")}),ie(ye.Item,{onSelect:()=>o.setActiveTool({type:"laser"}),icon:zn,"data-testid":"toolbar-laser",selected:p,shortcut:wO.K.toLocaleUpperCase(),children:f("toolBar.laser")}),s&&ie(ye.Item,{onSelect:()=>o.setActiveTool({type:"lasso"}),icon:Hr,"data-testid":"toolbar-lasso",selected:d,children:f("toolBar.lasso")}),ie("div",{style:{margin:"6px 0",fontSize:14,fontWeight:600},children:"Generate"}),o.props.aiEnabled!==!1&&ie(h.Out,{}),ie(ye.Item,{onSelect:()=>o.setOpenDialog({name:"ttd",tab:"mermaid"}),icon:ss,"data-testid":"toolbar-mermaid",children:f("toolBar.mermaidToExcalidraw")}),o.props.aiEnabled!==!1&&o.plugins.diagramToCode&&ie(ye.Item,{onSelect:()=>o.onMagicframeToolSelect(),icon:Ka,"data-testid":"toolbar-magicframe",badge:ie(ye.Item.Badge,{children:"AI"}),children:f("toolBar.magicframe")})]})]})]})},n5=({renderAction:e})=>e("scrollBackToContent"),r5=({renderAction:e,zoom:t})=>ke(Rt.Row,{align:"center",className:$C.ZOOM_ACTIONS,children:[e("zoomOut"),e("resetZoom"),e("zoomIn")]}),a5=({renderAction:e,className:t})=>ke("div",{className:`undo-redo-buttons ${t}`,children:[ie("div",{className:"undo-button-container",children:ie(Xt,{label:f("buttons.undo"),children:e("undo")})}),ie("div",{className:"redo-button-container",children:ke(Xt,{label:f("buttons.redo"),children:[" ",e("redo")]})})]}),i5=({actionManager:e,showExitZenModeBtn:t})=>ie("button",{type:"button",className:Kn("disable-zen-mode",{"disable-zen-mode--visible":t}),onClick:()=>e.executeAction(ta),children:f("buttons.exitZenMode")}),s5=({actionManager:e})=>ie("button",{type:"button",className:"disable-view-mode",onClick:()=>e.executeAction(ii),children:hv});import{useRef as IO}from"react";var o0=e=>{let t=IO({userFn:e});return t.current.userFn=e,t.current.stableFn||(t.current.stableFn=(...o)=>t.current.userFn(...o)),t.current.stableFn};import{jsx as CO,jsxs as TO}from"react/jsx-runtime";var si=Pe(null),l5=()=>{let[e,t]=le(si),o=at();return e&&e==="clearCanvas"?CO(Np,{onConfirm:()=>{o.executeAction(yr),t(null)},onCancel:()=>t(null),title:f("clearCanvasDialog.title"),children:TO("p",{className:"clear-canvas__content",children:[" ",f("alerts.clearReset")]})}):null};var n0={};eE(n0,{toggleTheme:()=>kO});var kO={...qa,category:"App",label:"Toggle theme",perform:({actionManager:e})=>{e.executeAction(qa,"commandPalette")}};import{jsx as Bt,jsxs as Xn}from"react/jsx-runtime";var LO=Pe(null),it={app:"App",export:"Export",tools:"Tools",editor:"Editor",elements:"Elements",links:"Links",library:"Library"},d5=e=>{switch(e){case it.app:return 1;case it.export:return 2;case it.editor:return 3;case it.tools:return 4;case it.elements:return 5;case it.links:return 6;default:return 10}},Jp=({shortcut:e,className:t,children:o})=>{let n=e.replace("++","+$").split("+");return Xn("div",{className:p5("shortcut",t),children:[n.map((r,a)=>Bt("div",{className:"shortcut-wrapper",children:Bt("div",{className:"shortcut-key",children:r==="$"?"+":r})},r)),Bt("div",{className:"shortcut-desc",children:o})]})},g5=e=>!e.altKey&&e[yn.CTRL_OR_CMD]&&(e.shiftKey&&e.key.toLowerCase()===yn.P||e.key===yn.SLASH),_O=Object.assign(e=>{let t=Ie(),o=Ce();return qp(()=>{let n=r=>{g5(r)&&(r.preventDefault(),r.stopPropagation(),o(a=>{let i=a.openDialog?.name==="commandPalette"?null:{name:"commandPalette"};return i&&be("command_palette","open","shortcut"),{openDialog:i}}))};return window.addEventListener(Qp.KEYDOWN,n,{capture:!0}),()=>window.removeEventListener(Qp.KEYDOWN,n,{capture:!0})},[o]),t.openDialog?.name!=="commandPalette"?null:Bt(DO,{...e})},{defaultItems:n0});function DO({customCommandPaletteItems:e}){let t=tt(),o=Ie(),n=Ce(),r=Hn(),a=at(),[i,s]=le(LO),[l,c]=jp(null),m=u5(null),p=Ur({uiAppState:o,customCommandPaletteItems:e,appProps:r}),[d]=le(wr),u=MO(()=>d.libraryItems?.filter(S=>!!S.name).map(S=>({label:S.name,icon:Bt(RO,{id:S.id,elements:S.elements}),category:"Library",order:d5("Library"),haystack:ri(S.name),perform:()=>{t.onInsertElements(Zs([S]))}}))||[],[t,d.libraryItems]);qp(()=>{let{uiAppState:S,customCommandPaletteItems:D,appProps:_}=p,k=N=>{let z="";return N.label&&(typeof N.label=="function"?z=f(N.label(t.scene.getNonDeletedElements(),S,t)):z=f(N.label)),z},M=N=>typeof N.icon=="function"?N.icon(S,t.scene.getNonDeletedElements()):N.icon,B=[],O=(N,z,L)=>{let F={label:k(N),icon:M(N),category:z,shortcut:Xe(N.name),keywords:N.keywords,predicate:N.predicate,viewMode:N.viewMode,perform:()=>{a.executeAction(N,"commandPalette")}};return L?L(F,N):F};if(S&&t.scene&&a){let N=[a.actions.group,a.actions.ungroup,a.actions.cut,a.actions.copy,a.actions.deleteSelectedElements,a.actions.wrapSelectionInFrame,a.actions.copyStyles,a.actions.pasteStyles,a.actions.bringToFront,a.actions.bringForward,a.actions.sendBackward,a.actions.sendToBack,a.actions.alignTop,a.actions.alignBottom,a.actions.alignLeft,a.actions.alignRight,a.actions.alignVerticallyCentered,a.actions.alignHorizontallyCentered,a.actions.duplicateSelection,a.actions.flipHorizontal,a.actions.flipVertical,a.actions.zoomToFitSelection,a.actions.zoomToFitSelectionInViewport,a.actions.increaseFontSize,a.actions.decreaseFontSize,a.actions.toggleLinearEditor,a.actions.cropEditor,a.actions.togglePolygon,Nc,Mp,ST].map(Z=>O(Z,it.elements,(U,q)=>({...U,predicate:q.predicate?q.predicate:(re,J,se,fe)=>de(re,J).length>0}))),z=[a.actions.toggleHandTool,a.actions.setFrameAsActiveTool,a.actions.toggleLassoTool].map(Z=>O(Z,it.tools)),L=[a.actions.undo,a.actions.redo,a.actions.zoomIn,a.actions.zoomOut,a.actions.resetZoom,a.actions.zoomToFit,a.actions.zenMode,a.actions.viewMode,a.actions.gridMode,a.actions.objectsSnapMode,a.actions.toggleShortcuts,a.actions.selectAll,a.actions.toggleElementLock,a.actions.unlockAllElements,a.actions.stats].map(Z=>O(Z,it.editor)),F=[a.actions.saveToActiveFile,a.actions.saveFileToDisk,a.actions.copyAsPng,a.actions.copyAsSvg].map(Z=>O(Z,it.export));B=[...N,...L,{label:k(yr),icon:M(yr),shortcut:Xe(yr.name),category:it.editor,keywords:["delete","destroy"],viewMode:!1,perform:()=>{Et.set(si,"clearCanvas")}},{label:f("buttons.exportImage"),category:it.export,icon:ym,shortcut:Xe("imageExport"),keywords:["export","image","png","jpeg","svg","clipboard","picture"],perform:()=>{n({openDialog:{name:"imageExport"}})}},...F];let $=[{label:f("toolBar.library"),category:it.app,icon:um,viewMode:!1,perform:()=>{S.openSidebar?n({openSidebar:null}):n({openSidebar:{name:c5.name,tab:c5.defaultTab}})}},{label:f("search.title"),category:it.app,icon:Mo,viewMode:!0,perform:()=>{a.executeAction(Zc)}},{label:f("labels.shapeSwitch"),category:it.elements,icon:sc,perform:()=>{a.executeAction(kT)}},{label:f("labels.changeStroke"),keywords:["color","outline"],category:it.elements,icon:xm,viewMode:!1,predicate:(Z,U)=>{let q=de(Z,U);return q.length>0&&Kc(U,q)},perform:()=>{n(Z=>({openPopup:"elementStroke"}))}},{label:f("labels.changeBackground"),keywords:["color","fill"],icon:xm,category:it.elements,viewMode:!1,predicate:(Z,U)=>{let q=de(Z,U);return q.length>0&&Xc(U,q)},perform:()=>{n(Z=>({openPopup:"elementBackground"}))}},{label:f("labels.canvasBackground"),keywords:["color"],icon:xm,category:it.editor,viewMode:!1,perform:()=>{n(Z=>({openMenu:Z.openMenu==="canvas"?null:"canvas",openPopup:"canvasBackground"}))}},...Yp.reduce((Z,U)=>{let{value:q,icon:re,key:J,numericKey:se}=U;if(_.UIOptions.tools?.[q]===!1)return Z;let Me=J&&PO(typeof J=="string"?J:J[0])||se,ct={label:f(`toolBar.${q}`),category:it.tools,shortcut:Me,icon:re,keywords:["toolbar"],viewMode:!1,perform:({event:Lt})=>{q==="image"?t.setActiveTool({type:q}):t.setActiveTool({type:q})}};return Z.push(ct),Z},[]),...z,{label:f("toolBar.lock"),category:it.tools,icon:S.activeTool.locked?ji:Wa,shortcut:yn.Q.toLocaleUpperCase(),viewMode:!1,perform:()=>{t.toggleLock()}},{label:`${f("labels.textToDiagram")}...`,category:it.tools,icon:Xw,viewMode:!1,predicate:_.aiEnabled,perform:()=>{n(Z=>({...Z,openDialog:{name:"ttd",tab:"text-to-diagram"}}))}},{label:`${f("toolBar.mermaidToExcalidraw")}...`,category:it.tools,icon:ss,viewMode:!1,predicate:_.aiEnabled,perform:()=>{n(Z=>({...Z,openDialog:{name:"ttd",tab:"mermaid"}}))}}],Q=[...B,...$,...D||[]].map(Z=>({...Z,icon:Z.icon||sc,order:Z.order??d5(Z.category),haystack:`${ri(Z.label.toLocaleLowerCase())} ${Z.keywords?.join(" ")||""}`}));c(Q),s([...Q,...u].find(Z=>Z.label===i?.label)??null)}},[p,t,a,c,i?.label,s,n,u]);let[h,g]=jp(""),[x,E]=jp(null),[y,w]=jp({}),v=S=>{n({openDialog:null},S),g("")},I=(S,D)=>{o.openDialog?.name==="commandPalette"&&(D.stopPropagation(),D.preventDefault(),document.body.classList.add("excalidraw-animations-disabled"),v(()=>{S.perform({actionManager:a,event:D}),s(S),requestAnimationFrame(()=>{document.body.classList.remove("excalidraw-animations-disabled")})}))},C=o0(S=>S.viewMode===!1&&o.viewModeEnabled?!1:typeof S.predicate=="function"?S.predicate(t.scene.getNonDeletedElements(),o,r,t):S.predicate===void 0||S.predicate),P=o0(S=>{let D=AO(S.target)||g5(S)||S.key===yn.ESCAPE;if(D&&S.key!==yn.ARROW_UP&&S.key!==yn.ARROW_DOWN&&S.key!==yn.ENTER)return;let _=Object.values(y).flat(),k=i&&!h&&C(i);if(S.key===yn.ARROW_UP){S.preventDefault();let M=_.findIndex(N=>N.label===x?.label);if(k){if(M===0){E(i);return}if(x===i){let N=_[_.length-1];N&&E(N);return}}let B;M===-1?B=_.length-1:B=M===0?_.length-1:(M-1)%_.length;let O=_[B];O&&E(O);return}if(S.key===yn.ARROW_DOWN){S.preventDefault();let M=_.findIndex(N=>N.label===x?.label);if(k){if(!x||M===_.length-1){E(i);return}if(x===i){let N=_[0];N&&E(N);return}}let B=(M+1)%_.length,O=_[B];O&&E(O);return}if(S.key===yn.ENTER&&x&&setTimeout(()=>{I(x,S)}),!D){if(S.stopPropagation(),/^[a-zA-Z0-9]$/.test(S.key)){m?.current?.focus();return}S.preventDefault()}});return qp(()=>(window.addEventListener(Qp.KEYDOWN,P,{capture:!0}),()=>window.removeEventListener(Qp.KEYDOWN,P,{capture:!0})),[P]),qp(()=>{if(!l)return;let S=M=>{let B={};for(let O of M)B[O.category]?B[O.category].push(O):B[O.category]=[O];return B},D=h?.length>1?[...l.filter(C).sort((M,B)=>M.order-B.order),...u]:l.filter(C).sort((M,B)=>M.order-B.order),_=!h&&i&&C(i);if(!h){w(S(_?D.filter(M=>M.label!==i?.label):D)),E(_?i:D[0]||null);return}let k=ri(h.toLocaleLowerCase().replace(/[<>_| -]/g,""));D=SO.filter(k,D,{extract:M=>M.haystack??""}).sort((M,B)=>B.score-M.score).map(M=>M.original),w(S(D)),E(D[0]??null)},[h,l,C,i,u]),Xn(bt,{onCloseRequest:()=>v(),closeOnClickOutside:!0,title:!1,size:720,autofocus:!0,className:"command-palette-dialog",children:[Bt(ia,{value:h,placeholder:f("commandPalette.search.placeholder"),onChange:S=>{g(S)},selectOnRender:!0,ref:m}),t.editorInterface.formFactor!=="phone"&&Xn("div",{className:"shortcuts-wrapper",children:[Bt(Jp,{shortcut:"\u2191\u2193",children:f("commandPalette.shortcuts.select")}),Bt(Jp,{shortcut:"\u21B5",children:f("commandPalette.shortcuts.confirm")}),Bt(Jp,{shortcut:G("Esc"),children:f("commandPalette.shortcuts.close")})]}),Xn("div",{className:"commands",children:[i&&!h&&Xn("div",{className:"command-category",children:[Xn("div",{className:"command-category-title",children:[f("commandPalette.recents"),Bt("div",{className:"icon",style:{marginLeft:"6px"},children:Zw})]}),Bt(m5,{command:i,isSelected:i.label===x?.label,onClick:S=>I(i,S),disabled:!C(i),onMouseMove:()=>E(i),showShortcut:t.editorInterface.formFactor!=="phone",appState:o})]}),Object.keys(y).length>0?Object.keys(y).map((S,D)=>Xn("div",{className:"command-category",children:[Bt("div",{className:"command-category-title",children:S}),y[S].map(_=>Bt(m5,{command:_,isSelected:_.label===x?.label,onClick:k=>I(_,k),onMouseMove:()=>E(_),showShortcut:t.editorInterface.formFactor!=="phone",appState:o,size:S==="Library"?"large":"small"},_.label))]},S)):l?Xn("div",{className:"no-match",children:[Bt("div",{className:"icon",children:Mo})," ",f("commandPalette.search.noMatch")]}):null]})]})}var RO=({id:e,elements:t})=>{let o=u5(null),{svgCache:n}=Ks();return Pp(e,t,n,o),Bt("div",{className:"library-item-icon",ref:o})},m5=({command:e,isSelected:t,disabled:o,onMouseMove:n,onClick:r,showShortcut:a,appState:i,size:s="small"})=>{let l=()=>{};return Xn("div",{className:p5("command-item",{"item-selected":t,"item-disabled":o,"command-item-large":s==="large"}),ref:c=>{t&&!o&&c?.scrollIntoView?.({block:"nearest"})},onClick:o?l:r,onMouseMove:o?l:n,title:o?f("commandPalette.itemNotAvailable"):"",children:[Xn("div",{className:"name",children:[e.icon&&Bt(Gn,{className:"icon",size:"var(--icon-size, 1rem)",icon:typeof e.icon=="function"?e.icon(i,[]):e.icon}),Bt(xc,{children:e.label})]}),a&&e.shortcut&&Bt(Jp,{shortcut:e.shortcut})]})};import{getSizeFromPoints as oSe,randomInteger as Nz,getUpdatedTimestamp as Bz}from"@orangecatai/common";import{simplify as Ez}from"points-on-curve";import{getStroke as wz}from"perfect-freehand";import{pointsOnBezierCurves as Uwe}from"points-on-curve";import{invariant as Ywe}from"@orangecatai/common";import{curve as Vwe,lineSegment as Kwe,pointFrom as Xwe,pointDistance as Zwe,pointFromArray as jwe,pointFromVector as qwe,pointRotateRads as Jwe,polygon as Qwe,polygonFromPoints as eve,PRECISION as tve,segmentsIntersectAt as ove,vector as nve,vectorAdd as rve,vectorFromPoint as ave,vectorScale as ive}from"@orangecatai/math";import{getElementAbsoluteCoords as lve}from"@orangecatai/element";var r0=e=>{if(!e)return[];for(let t of e.sets)if(t.type==="path")return t.ops;return e.sets[0].ops};import{pointFrom as vz,pointDistance as _5,pointRotateRads as G3e}from"@orangecatai/math";import{ROUGHNESS as Iz,THEME as v0,isTransparent as Qc,assertNever as Tz,COLOR_PALETTE as Cz,LINE_POLYGON_POINT_MERGE_DISTANCE as W3e,applyDarkModeFilter as cu}from"@orangecatai/common";import{RoughGenerator as kz}from"roughjs/bin/generator";import qke from"roughjs/bin/rough";import{isRightAngleRads as Qke,lineSegment as e3e,pointFrom as t3e,pointRotateRads as o3e}from"@orangecatai/math";import{BOUND_TEXT_PADDING as r3e,DEFAULT_REDUCED_GLOBAL_ALPHA as a3e,ELEMENT_READY_TO_ERASE_OPACITY as i3e,FRAME_STYLE as s3e,DARK_THEME_FILTER as l3e,MIME_TYPES as A5,THEME as c3e,distance as d3e,getFontString as m3e,isRTL as p3e,getVerticalOffset as u3e,invariant as g3e,applyDarkModeFilter as h3e,isSafari as f3e}from"@orangecatai/common";import c5e from"roughjs/bin/rough";import{arrayToMap as m5e,invariant as I5,rescalePoints as p5e,sizeOf as u5e}from"@orangecatai/common";import{degreesToRadians as f0,lineSegment as h5e,pointDistance as f5e,pointFrom as Yt,pointFromArray as oz,pointRotateRads as rl}from"@orangecatai/math";import{pointsOnBezierCurves as y5e}from"points-on-curve";import{pointCenter as TCe,pointFrom as CCe,pointRotateRads as kCe,pointsEqual as SCe,pointDistance as MCe,vectorFromPoint as PCe,curveLength as ACe,curvePointAtLength as LCe}from"@orangecatai/math";import{DRAGGING_THRESHOLD as RCe,KEYS as NCe,shouldRotateWithDiscreteAngle as BCe,getGridPoint as FCe,invariant as OCe,isShallowEqual as zCe,getFeatureFlag as HCe}from"@orangecatai/common";import{deconstructLinearOrFreeDrawElement as UCe,getSnapOutlineMidPoint as WCe,isPathALoop as YCe,moveArrowAboveBindable as $Ce,projectFixedPointOntoDiagonal as VCe}from"@orangecatai/element";import{KEYS as TTe,arrayToMap as CTe,getFeatureFlag as kTe,invariant as STe,isTransparent as MTe}from"@orangecatai/common";import{PRECISION as ATe,clamp as LTe,lineSegment as _Te,pointDistance as DTe,pointDistanceSq as RTe,pointFrom as NTe,pointFromVector as BTe,pointRotateRads as FTe,pointsEqual as OTe,vectorFromPoint as zTe,vectorNormalize as HTe,vectorScale as GTe}from"@orangecatai/math";import{invariant as j2e,isTransparent as q2e}from"@orangecatai/common";import{curveIntersectLineSegment as Q2e,isPointWithinBounds as eIe,lineSegment as tIe,lineSegmentIntersectionPoints as oIe,pointFrom as nIe,pointFromVector as rIe,pointRotateRads as aIe,pointsEqual as iIe,vectorFromPoint as sIe,vectorNormalize as lIe,vectorScale as cIe}from"@orangecatai/math";import{ellipse as mIe,ellipseSegmentInterceptPoints as pIe}from"@orangecatai/math/ellipse";import{DEFAULT_ADAPTIVE_RADIUS as FO,DEFAULT_PROPORTIONAL_RADIUS as i0,invariant as yve,LINE_CONFIRM_THRESHOLD as OO,ROUNDNESS as s0}from"@orangecatai/common";import{bezierEquation as wve,curve as vve,curveCatmullRomCubicApproxPoints as Ive,curveOffsetPoints as Tve,lineSegment as Cve,lineSegmentIntersectionPoints as kve,pointDistance as zO,pointFrom as Sve,pointFromArray as Mve,pointFromVector as Pve,pointRotateRads as Ave,pointTranslate as Lve,rectangle as _ve,vectorFromPoint as Dve,vectorNormalize as Rve,vectorScale as Nve}from"@orangecatai/math";import{ROUNDNESS as pve,assertNever as uve}from"@orangecatai/common";import{pointsEqual as hve}from"@orangecatai/math";var h5=e=>!!e&&e.type==="embeddable",f5=e=>!!e&&e.type==="iframe",a0=e=>!!e&&(e.type==="iframe"||e.type==="embeddable"),li=e=>e!=null&&e.type==="text";var eu=e=>e!=null&&(e.type==="frame"||e.type==="magicframe");var ci=e=>e!=null&&NO(e.type);var di=e=>e!=null&&e.type==="arrow",jc=e=>di(e)&&e.elbowed;var NO=e=>e==="arrow"||e==="line";var el=e=>e!==null&&"containerId"in e&&e.containerId!==null&&li(e);var tu=(e,t=1)=>{if(e.length>=3){let[o,n]=[e[0],e[e.length-1]];return zO(o,n)<=OO/t}return!1},qc=(e,t)=>{if(t.roundness?.type===s0.PROPORTIONAL_RADIUS||t.roundness?.type===s0.LEGACY)return e*i0;if(t.roundness?.type===s0.ADAPTIVE_RADIUS){let o=t.roundness?.value??FO,n=o/i0;return e<=n?e*i0:o}return 0};import{ARROW_LABEL_FONT_SIZE_TO_MIN_WIDTH_RATIO as y2e,ARROW_LABEL_WIDTH_FRACTION as E2e,BOUND_TEXT_PADDING as w2e,DEFAULT_FONT_SIZE as v2e,TEXT_ALIGN as I2e,VERTICAL_ALIGN as T2e,getFontString as C2e,isProdEnv as k2e,invariant as S2e}from"@orangecatai/common";import{pointFrom as P2e,pointRotateRads as A2e}from"@orangecatai/math";import{BOUND_TEXT_PADDING as jve,DEFAULT_FONT_SIZE as qve,DEFAULT_FONT_FAMILY as Jve,getFontString as Qve,isTestEnv as e2e,normalizeEOL as t2e}from"@orangecatai/common";var o2e="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".toLocaleUpperCase();import{isDevEnv as c2e,isTestEnv as d2e}from"@orangecatai/common";import{curvePointDistance as z2e,distanceToLineSegment as H2e,pointRotateRads as G2e}from"@orangecatai/math";import{ellipse as W2e,ellipseDistanceFromPoint as Y2e}from"@orangecatai/math/ellipse";import{invariant as kIe,isDevEnv as SIe,isTestEnv as MIe}from"@orangecatai/common";import{pointFrom as AIe,pointFromVector as LIe,pointRotateRads as _Ie,pointScaleFromOrigin as DIe,pointsEqual as RIe,triangleIncludesPoint as NIe,vectorCross as BIe,vectorFromPoint as ZO,vectorScale as FIe}from"@orangecatai/math";var g0=[1,0],y5=[0,1],h0=[-1,0],E5=[0,-1],ru=e=>{let[t,o]=e,n=Math.abs(t),r=Math.abs(o);return t>r?g0:t<=-r?h0:o>n?y5:E5},w5=(e,t)=>ru(ZO(e,t)),au=(e,t)=>iu(w5(e,t)),u0=(e,t)=>e[0]===t[0]&&e[1]===t[1],iu=e=>u0(e,g0)||u0(e,h0);import{clamp as WIe,pointDistance as YIe,pointFrom as $Ie,pointScaleFromOrigin as VIe,pointsEqual as KIe,pointTranslate as XIe,vector as ZIe,vectorCross as jIe,vectorFromPoint as qIe,vectorScale as JIe}from"@orangecatai/math";import{BinaryHeap as eTe,invariant as tTe,isAnyTrue as oTe,getSizeFromPoints as nTe,isDevEnv as rTe,arrayToMap as aTe}from"@orangecatai/common";var QTe=10/1.5;import{SHIFT_LOCKING_ANGLE as rCe,viewportCoordsToSceneCoords as aCe}from"@orangecatai/common";import{normalizeRadians as sCe,radiansBetweenAngles as lCe,radiansDifference as cCe}from"@orangecatai/math";import{pointsEqual as mCe}from"@orangecatai/math";var ou=e=>{let t=Math.floor(e.width/2)+1,o=0,n=e.width,r=Math.floor(e.height/2)+1,a=t,i=e.height;return[t,o,n,r,a,i,0,r]};var nz=e=>{switch(e){case"arrow":return 25;case"diamond":case"diamond_outline":return 12;case"crowfoot_many":case"crowfoot_one":case"crowfoot_one_or_many":return 20;default:return 15}},rz=e=>{switch(e){case"bar":return 90;case"arrow":return 20;default:return 25}},b0=(e,t,o,n)=>{if(t.length<1)return null;let r=r0(t[0]);if(r.length<1)return null;let a=o==="start"?1:r.length-1,i=r[a].data;I5(i.length===6,"Op data length is not 6");let s=Yt(i[4],i[5]),l=Yt(i[2],i[3]),c=Yt(i[0],i[1]),m=r[a-1],p=Yt(0,0);if(m.op==="move"){let N=oz(m.data);I5(N!=null,"Op data is not a point"),p=N}else m.op==="bcurveTo"&&(p=Yt(m.data[4],m.data[5]));let d=(N,z)=>Math.pow(1-N,3)*s[z]+3*N*Math.pow(1-N,2)*l[z]+3*Math.pow(N,2)*(1-N)*c[z]+p[z]*Math.pow(N,3),[u,h]=o==="start"?p:s,[g,x]=[d(.3,0),d(.3,1)],E=Math.hypot(u-g,h-x),y=(u-g)/E,w=(h-x)/E,v=nz(n),I=0;{let[N,z]=o==="end"?e.points[e.points.length-1]:e.points[0],[L,F]=e.points.length>1?o==="end"?e.points[e.points.length-2]:e.points[1]:[0,0];I=Math.hypot(N-L,z-F)}let P=Math.min(v,I*(n==="diamond"||n==="diamond_outline"?.25:.5)),S=u-y*P,D=h-w*P;if(n==="dot"||n==="circle"||n==="circle_outline"){let N=Math.hypot(D-h,S-u)+e.strokeWidth-2;return[u,h,N]}let _=rz(n);if(n==="crowfoot_many"||n==="crowfoot_one_or_many"){let[N,z]=rl(Yt(u,h),Yt(S,D),f0(-_)),[L,F]=rl(Yt(u,h),Yt(S,D),f0(_));return[S,D,N,z,L,F]}let[k,M]=rl(Yt(S,D),Yt(u,h),-_*Math.PI/180),[B,O]=rl(Yt(S,D),Yt(u,h),f0(_));if(n==="diamond"||n==="diamond_outline"){let N,z;if(o==="start"){let[L,F]=e.points.length>1?e.points[1]:[0,0];[N,z]=rl(Yt(u+P*2,h),Yt(u,h),Math.atan2(F-h,L-u))}else{let[L,F]=e.points.length>1?e.points[e.points.length-2]:[0,0];[N,z]=rl(Yt(u-P*2,h),Yt(u,h),Math.atan2(h-F,u-L))}return[u,h,k,M,N,z,B,O]}return[u,h,k,M,B,O]};import{pointFrom as D5e,pointCenter as R5e,pointRotateRads as N5e,vectorFromPoint as B5e,vectorNormalize as F5e,vectorSubtract as O5e,vectorAdd as z5e,vectorScale as H5e,pointFromVector as G5e,clamp as U5e,isCloseTo as W5e}from"@orangecatai/math";import{arrayToMap as Pke}from"@orangecatai/common";import{isPointWithinBounds as Lke,pointFrom as _ke}from"@orangecatai/math";import{vectorCross as X5e,vectorFromPoint as Z5e}from"@orangecatai/math";import{arrayToMap as az}from"@orangecatai/common";import{getElementBounds as iz}from"@orangecatai/element";import{isArrowElement as sz,isExcalidrawElement as lz,isFreeDrawElement as cz,isLinearElement as dz,isTextElement as mz}from"@orangecatai/element";import{rangeIncludesValue as su,pointFrom as Cr,pointRotateRads as pz,rangeInclusive as lu}from"@orangecatai/math";var uz=e=>e.type==="diamond"?[Cr(e.width/2,0),Cr(e.width,e.height/2),Cr(e.width/2,e.height),Cr(0,e.height/2)]:[Cr(0,0),Cr(0+e.width,0),Cr(0+e.width,e.height),Cr(0,e.height)],gz=e=>dz(e)||cz(e)?e.points:uz(e),C5=e=>{let t=e.reduce((o,[n,r])=>(o.minY=Math.min(o.minY,r),o.minX=Math.min(o.minX,n),o.maxX=Math.max(o.maxX,n),o.maxY=Math.max(o.maxY,r),o),{minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0,cx:0,cy:0});return t.cx=(t.maxX+t.minX)/2,t.cy=(t.maxY+t.minY)/2,t},k5=e=>{let t=gz(e),{cx:o,cy:n}=C5(t),r=Cr(o,n),a=t.map(m=>pz(m,r,e.angle)),{minX:i,minY:s,maxX:l,maxY:c}=C5(a);return[i+e.x,s+e.y,l+e.x,c+e.y]},x0=(e,t,o=!1)=>{let n=k5(e),r=t[0]<=n[0]&&t[2]>=n[2]&&t[1]<=n[1]&&t[3]>=n[3];return o?r?!0:n[0]<=t[0]&&n[2]>=t[2]&&n[1]<=t[1]&&n[3]>=t[3]:r},S5=(e,t)=>{let o=k5(e);return(su(o[0],lu(t[0],t[2]))||su(t[0],lu(o[0],o[2])))&&(su(o[1],lu(t[1],t[3]))||su(t[1],lu(o[1],o[3])))},M5=({elements:e,bounds:t,type:o,errorMargin:n=0})=>{lz(t)&&(t=iz(t,az(e)));let r=[t[0]-n,t[1]-n,t[2]+n,t[3]+n],a=new Set;for(let i of e){if(a.has(i.id))continue;if(o==="overlap"?S5(i,r):o==="inside"?x0(i,r):x0(i,r,!0)){if(a.add(i.id),i.boundElements)for(let l of i.boundElements)a.add(l.id);mz(i)&&i.containerId&&a.add(i.containerId),sz(i)&&(i.startBinding&&a.add(i.startBinding.elementId),i.endBinding&&a.add(i.endBinding?.elementId))}}return e.filter(i=>a.has(i.id))};import{arrayToMap as mke,isShallowEqual as fz}from"@orangecatai/common";var hz=function(){let e=null,t=null,o=null,n=(a,i,s,l)=>{if(o!==void 0&&i===t&&a===e&&s.editingGroupId===o?.editingGroupId)return o;let c={};for(let d of a){let u=d.groupIds;if(s.editingGroupId){let h=u.indexOf(s.editingGroupId);h>-1&&(u=u.slice(0,h))}if(u.length>0){let h=u[u.length-1];c[h]=!0}}let m={},p=i.reduce((d,u)=>{if(u.isDeleted)return d;let h=u.groupIds.find(g=>c[g]);return h&&(d[u.id]=!0,Array.isArray(m[h])?m[h].push(u.id):m[h]=[u.id]),d},{});for(let d of Object.keys(m))m[d].length<2&&c[d]&&(c[d]=!1);return t=i,e=a,o={editingGroupId:s.editingGroupId,selectedGroupIds:c,selectedElementIds:y0({...s.selectedElementIds,...p},l)},o},r=(a,i,s,l)=>{let c=l?l.scene.getSelectedElements({selectedElementIds:a.selectedElementIds,elements:i}):E0(i,a);return c.length?n(c,i,a,s):{selectedGroupIds:{},editingGroupId:null,selectedElementIds:y0(a.selectedElementIds,s)}};return r.clearCache=()=>{t=null,e=null,o=null},r}();var xke=function(){let e=null,t=null,o=null,n=(r,a)=>(o!=null&&r===e&&a.selectedElementIds===t||(o=r.some(i=>a.selectedElementIds[i.id]),e=r,t=a.selectedElementIds),o);return n.clearCache=()=>{e=null,t=null,o=null},n}(),E0=(e,t,o)=>{let n=new Set,r=[];for(let a of e.values()){if(t.selectedElementIds[a.id]){r.push(a),n.add(a.id);continue}if(o?.includeBoundTextElement&&el(a)&&t.selectedElementIds[a?.containerId]){r.push(a),n.add(a.id);continue}}if(o?.includeElementsInFrames){let a=[];return r.forEach(i=>{eu(i)&&P5(e,i.id).forEach(s=>!n.has(s.id)&&a.push(s)),a.push(i)}),a}return r};var y0=(e,t)=>fz(t.selectedElementIds,e)?t.selectedElementIds:e;var P5=(e,t)=>{let o=[];for(let n of e.values())n.frameId===t&&o.push(n);return o};var xz=typeof document<"u"?document.createElement("img"):{src:""};xz.src=`data:${A5.svg},${encodeURIComponent('<svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="image" class="svg-inline--fa fa-image fa-w-16" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="#888" d="M464 448H48c-26.51 0-48-21.49-48-48V112c0-26.51 21.49-48 48-48h416c26.51 0 48 21.49 48 48v288c0 26.51-21.49 48-48 48zM112 120c-30.928 0-56 25.072-56 56s25.072 56 56 56 56-25.072 56-56-25.072-56-56-56zM64 384h384V272l-87.515-87.515c-4.686-4.686-12.284-4.686-16.971 0L208 320l-55.515-55.515c-4.686-4.686-12.284-4.686-16.971 0L64 336v48z"></path></svg>')}`;var yz=typeof document<"u"?document.createElement("img"):{src:""};yz.src=`data:${A5.svg},${encodeURIComponent('<svg viewBox="0 0 668 668" xmlns="http://www.w3.org/2000/svg" xml:space="preserve" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2"><path d="M464 448H48c-26.51 0-48-21.49-48-48V112c0-26.51 21.49-48 48-48h416c26.51 0 48 21.49 48 48v288c0 26.51-21.49 48-48 48ZM112 120c-30.928 0-56 25.072-56 56s25.072 56 56 56 56-25.072 56-56-25.072-56-56-56ZM64 384h384V272l-87.515-87.515c-4.686-4.686-12.284-4.686-16.971 0L208 320l-55.515-55.515c-4.686-4.686-12.284-4.686-16.971 0L64 336v48Z" style="fill:#888;fill-rule:nonzero" transform="matrix(.81709 0 0 .81709 124.825 145.825)"/><path d="M256 8C119.034 8 8 119.033 8 256c0 136.967 111.034 248 248 248s248-111.034 248-248S392.967 8 256 8Zm130.108 117.892c65.448 65.448 70 165.481 20.677 235.637L150.47 105.216c70.204-49.356 170.226-44.735 235.638 20.676ZM125.892 386.108c-65.448-65.448-70-165.481-20.677-235.637L361.53 406.784c-70.203 49.356-170.226 44.736-235.638-20.676Z" style="fill:#888;fill-rule:nonzero" transform="matrix(.30366 0 0 .30366 506.822 60.065)"/></svg>')}`;var w0=new WeakMap;var L5=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="line"||e==="diamond"||e==="image";var xo=class xo{};A(xo,"rg",new kz),A(xo,"cache",new WeakMap),A(xo,"get",(t,o)=>{let n=xo.cache.get(t);if(n&&(o===null||n.theme===o))return n.shape}),A(xo,"delete",t=>{xo.cache.delete(t),w0.delete(t)}),A(xo,"destroy",()=>{xo.cache=new WeakMap}),A(xo,"generateElementShape",(t,o)=>{let n=o?.isExporting?void 0:xo.get(t,o?o.theme:null);if(n!==void 0)return n;w0.delete(t);let r=Pz(t,xo.rg,o||{isExporting:!1,canvasBackgroundColor:Cz.white,embedsValidationStatus:null,theme:v0.LIGHT});return o?.isExporting||xo.cache.set(t,{shape:r,theme:o?.theme||v0.LIGHT}),r});var nl=xo,Sz=e=>[8,8+e],B5=e=>[1.5,6+e];function Mz(e){let t=e.roughness,o=Math.max(e.width,e.height),n=Math.min(e.width,e.height);return n>=20&&o>=50||n>=15&&e.roundness&&L5(e.type)||ci(e)&&o>=50?t:Math.min(t/(o<10?3:2),2.5)}var Tr=(e,t=!1,o=!1)=>{let n={seed:e.seed,strokeLineDash:e.strokeStyle==="dashed"?Sz(e.strokeWidth):e.strokeStyle==="dotted"?B5(e.strokeWidth):void 0,disableMultiStroke:e.strokeStyle!=="solid",strokeWidth:e.strokeStyle!=="solid"?e.strokeWidth+.5:e.strokeWidth,fillWeight:e.strokeWidth/2,hachureGap:e.strokeWidth*4,roughness:Mz(e),stroke:o?cu(e.strokeColor):e.strokeColor,preserveVertices:t||e.roughness<Iz.cartoonist};switch(e.type){case"rectangle":case"iframe":case"embeddable":case"diamond":case"ellipse":return n.fillStyle=e.fillStyle,n.fill=Qc(e.backgroundColor)?void 0:o?cu(e.backgroundColor):e.backgroundColor,e.type==="ellipse"&&(n.curveFitting=1),n;case"line":case"freedraw":return tu(e.points)&&(n.fillStyle=e.fillStyle,n.fill=e.backgroundColor==="transparent"?void 0:o?cu(e.backgroundColor):e.backgroundColor),n;case"arrow":return n;default:throw new Error(`Unimplemented type ${e.type}`)}},D5=(e,t,o)=>a0(e)&&(t||h5(e)&&o?.get(e.id)!==!0)&&Qc(e.backgroundColor)&&Qc(e.strokeColor)?{...e,roughness:0,backgroundColor:"#d3d3d3",fillStyle:"solid"}:f5(e)?{...e,strokeColor:Qc(e.strokeColor)?"#000000":e.strokeColor,backgroundColor:Qc(e.backgroundColor)?"#f4f4f6":e.backgroundColor}:e,R5=(e,t,o,n,r,a,i,s)=>{let l=b0(e,t,o,n);if(l===null)return[];let c=(p,d)=>{if(p===null)return[];let[,,u,h,g,x]=p;return[r.line(u,h,g,x,d)]},m=s?cu(e.strokeColor):e.strokeColor;switch(n){case"dot":case"circle":case"circle_outline":{let[p,d,u]=l;return delete a.strokeLineDash,[r.circle(p,d,u,{...a,fill:n==="circle_outline"?i:m,fillStyle:"solid",stroke:m,roughness:Math.min(.5,a.roughness||0)})]}case"triangle":case"triangle_outline":{let[p,d,u,h,g,x]=l;return delete a.strokeLineDash,[r.polygon([[p,d],[u,h],[g,x],[p,d]],{...a,fill:n==="triangle_outline"?i:m,fillStyle:"solid",roughness:Math.min(1,a.roughness||0)})]}case"diamond":case"diamond_outline":{let[p,d,u,h,g,x,E,y]=l;return delete a.strokeLineDash,[r.polygon([[p,d],[u,h],[g,x],[E,y],[p,d]],{...a,fill:n==="diamond_outline"?i:m,fillStyle:"solid",roughness:Math.min(1,a.roughness||0)})]}case"crowfoot_one":return c(l,a);case"bar":case"arrow":case"crowfoot_many":case"crowfoot_one_or_many":default:{let[p,d,u,h,g,x]=l;if(e.strokeStyle==="dotted"){let E=B5(e.strokeWidth-1);a.strokeLineDash=[E[0],E[1]-1]}else delete a.strokeLineDash;return a.roughness=Math.min(1,a.roughness||0),[r.line(u,h,p,d,a),r.line(g,x,p,d,a),...n==="crowfoot_one_or_many"?c(b0(e,t,o,"crowfoot_one"),a):[]]}}};var Pz=(e,t,{isExporting:o,canvasBackgroundColor:n,embedsValidationStatus:r,theme:a})=>{let i=a===v0.DARK;switch(e.type){case"rectangle":case"iframe":case"embeddable":{let s;if(e.roundness){let l=e.width,c=e.height,m=qc(Math.min(l,c),e);s=t.path(`M ${m} 0 L ${l-m} 0 Q ${l} 0, ${l} ${m} L ${l} ${c-m} Q ${l} ${c}, ${l-m} ${c} L ${m} ${c} Q 0 ${c}, 0 ${c-m} L 0 ${m} Q 0 0, ${m} 0`,Tr(D5(e,o,r),!0,i))}else s=t.rectangle(0,0,e.width,e.height,Tr(D5(e,o,r),!1,i));return s}case"diamond":{let s,[l,c,m,p,d,u,h,g]=ou(e);if(e.roundness){let x=qc(Math.abs(l-h),e),E=qc(Math.abs(p-c),e);s=t.path(`M ${l+x} ${c+E} L ${m-x} ${p-E}
|
|
6
|
+
${f("hints.firefox_clipboard_write")}`):new Error(f("alerts.couldNotCopyToClipboard"))}else throw new Error("Unsupported export type")};var hI=async(e,t,o,n)=>{let{exportBackground:r,viewBackgroundColor:a,fileHandle:i}=t,s=uE(i);if(!i||!gE(s))throw new Error("fileHandle should exist and should be of type svg or png when resaving");t={...t,exportEmbedScene:!0};let{exportedElements:l,exportingFrame:c}=Qa(e,t,!1);return await ei(s,l,t,o,{exportBackground:r,viewBackgroundColor:a,name:n,fileHandle:i,exportingFrame:c}),{fileHandle:i}};import{Fragment as GR,jsx as Er,jsxs as UR}from"react/jsx-runtime";var Hf=W({name:"changeProjectName",label:"labels.fileTitle",trackEvent:!1,perform:(e,t,o)=>({appState:{...t,name:o},captureUpdate:fn.EVENTUALLY}),PanelComponent:({appState:e,updateData:t,appProps:o,data:n,app:r})=>Er(q2,{label:f("labels.fileTitle"),value:r.getName(),onChange:a=>t(a),ignoreFocus:n?.ignoreFocus??!1})}),fI=W({name:"changeExportScale",label:"imageExportDialog.scale",trackEvent:{category:"export",action:"scale"},perform:(e,t,o)=>({appState:{...t,exportScale:o},captureUpdate:fn.EVENTUALLY}),PanelComponent:({elements:e,appState:t,updateData:o})=>{let n=HR(e),a=Ge(n,t)?de(n,t):n;return Er(GR,{children:zR.map(i=>{let[s,l]=mE(a,OR,i),c=`${f("imageExportDialog.label.scale")} ${i}x (${s}x${l})`;return Er(ie,{size:"small",type:"radio",icon:`${i}x`,name:"export-canvas-scale",title:c,"aria-label":c,id:"export-canvas-scale",checked:i===t.exportScale,onChange:()=>o(i)},i)})})}}),Gf=W({name:"changeExportBackground",label:"imageExportDialog.label.withBackground",trackEvent:{category:"export",action:"toggleBackground"},perform:(e,t,o)=>({appState:{...t,exportBackground:o},captureUpdate:fn.EVENTUALLY}),PanelComponent:({appState:e,updateData:t})=>Er(Tc,{checked:e.exportBackground,onChange:o=>t(o),children:f("imageExportDialog.label.withBackground")})}),cp=W({name:"changeExportEmbedScene",label:"imageExportDialog.tooltip.embedScene",trackEvent:{category:"export",action:"embedScene"},perform:(e,t,o)=>({appState:{...t,exportEmbedScene:o},captureUpdate:fn.EVENTUALLY}),PanelComponent:({appState:e,updateData:t})=>UR(Tc,{checked:e.exportEmbedScene,onChange:o=>t(o),children:[f("imageExportDialog.label.embedScene"),Er(Xt,{label:f("imageExportDialog.tooltip.embedScene"),long:!0,children:Er("div",{className:"excalidraw-tooltip-icon",children:XE})})]})}),ti=W({name:"saveToActiveFile",label:"buttons.save",icon:$a,trackEvent:{category:"export"},predicate:(e,t,o,n)=>!!n.props.UIOptions.canvasActions.saveToActiveFile&&!!t.fileHandle&&!t.viewModeEnabled,perform:async(e,t,o,n)=>{let r=!!t.fileHandle;try{let{fileHandle:a}=sm(t.fileHandle)?await hI(e,t,n.files,n.getName()):await nm(e,t,n.files,n.getName());return{captureUpdate:fn.EVENTUALLY,appState:{...t,fileHandle:a,toast:r?{message:a?.name?f("toast.fileSavedToFilename").replace("{filename}",`"${a.name}"`):f("toast.fileSaved")}:null}}}catch(a){return a?.name!=="AbortError"?console.error(a):console.warn(a),{captureUpdate:fn.EVENTUALLY}}},keyTest:e=>e.key===Ls.S&&e[Ls.CTRL_OR_CMD]&&!e.shiftKey}),Ac=W({name:"saveFileToDisk",label:"exportDialog.disk_title",icon:$a,viewMode:!0,trackEvent:{category:"export"},perform:async(e,t,o,n)=>{try{let{fileHandle:r}=await nm(e,{...t,fileHandle:null},n.files,n.getName());return{captureUpdate:fn.EVENTUALLY,appState:{...t,openDialog:null,fileHandle:r,toast:{message:f("toast.fileSaved")}}}}catch(r){return r?.name!=="AbortError"?console.error(r):console.warn(r),{captureUpdate:fn.EVENTUALLY}}},keyTest:e=>e.key===Ls.S&&e.shiftKey&&e[Ls.CTRL_OR_CMD],PanelComponent:({updateData:e})=>Er(ie,{type:"button",icon:YE,title:f("buttons.saveAs"),"aria-label":f("buttons.saveAs"),showAriaLabel:Te().formFactor==="phone",hidden:!Wi,onClick:()=>e(null),"data-testid":"save-as-button"})}),_s=W({name:"loadScene",label:"buttons.load",trackEvent:{category:"export"},predicate:(e,t,o,n)=>!!n.props.UIOptions.canvasActions.loadScene&&!t.viewModeEnabled,perform:async(e,t,o,n)=>{try{let{elements:r,appState:a,files:i}=await ch(t,e);return{elements:r,appState:a,files:i,captureUpdate:fn.IMMEDIATELY}}catch(r){return r?.name==="AbortError"?(console.warn(r),!1):{elements:e,appState:{...t,errorMessage:r.message},files:n.files,captureUpdate:fn.EVENTUALLY}}},keyTest:e=>e[Ls.CTRL_OR_CMD]&&e.key===Ls.O}),bI=W({name:"exportWithDarkMode",label:"imageExportDialog.label.darkMode",trackEvent:{category:"export",action:"toggleTheme"},perform:(e,t,o)=>({appState:{...t,exportWithDarkMode:o},captureUpdate:fn.EVENTUALLY}),PanelComponent:({appState:e,updateData:t})=>Er("div",{style:{display:"flex",justifyContent:"flex-end",marginTop:"-45px",marginBottom:"10px"},children:Er(Z2,{value:e.exportWithDarkMode?zf.DARK:zf.LIGHT,onChange:o=>{t(o===zf.DARK)},title:f("imageExportDialog.label.darkMode")})})});import{DEFAULT_FONT_SIZE as WR,DEFAULT_FONT_FAMILY as YR,DEFAULT_TEXT_ALIGN as $R,CODES as xI,KEYS as yI,getLineHeight as VR}from"@orangecatai/common";import{newElementWith as dp}from"@orangecatai/element";import{hasBoundTextElement as KR,canApplyRoundnessTypeToElement as XR,getDefaultRoundnessTypeForElement as ZR,isFrameLikeElement as jR,isArrowElement as qR,isExcalidrawElement as JR,isTextElement as Uf}from"@orangecatai/element";import{getBoundTextElement as QR,redrawTextBoundingBox as e7}from"@orangecatai/element";import{CaptureUpdateAction as Wf}from"@orangecatai/element";var EI="{}",Yf=W({name:"copyStyles",label:"labels.copyStyles",icon:Bh,trackEvent:{category:"element"},perform:(e,t,o,n)=>{let r=[],a=e.find(i=>t.selectedElementIds[i.id]);if(r.push(a),a&&KR(a)){let i=QR(a,n.scene.getNonDeletedElementsMap());r.push(i)}return a&&(EI=JSON.stringify(r)),{appState:{...t,toast:{message:f("toast.copyStyles")}},captureUpdate:Wf.EVENTUALLY}},keyTest:e=>e[yI.CTRL_OR_CMD]&&e.altKey&&e.code===xI.C}),$f=W({name:"pasteStyles",label:"labels.pasteStyles",icon:Bh,trackEvent:{category:"element"},perform:(e,t,o,n)=>{let r=JSON.parse(EI),a=r[0],i=r[1];if(!JR(a))return{elements:e,captureUpdate:Wf.EVENTUALLY};let s=de(e,t,{includeBoundTextElement:!0}),l=s.map(c=>c.id);return{elements:e.map(c=>{if(l.includes(c.id)){let m=a;if(Uf(c)&&c.containerId&&(m=i),!m)return c;let p=dp(c,{backgroundColor:m?.backgroundColor,strokeWidth:m?.strokeWidth,strokeColor:m?.strokeColor,strokeStyle:m?.strokeStyle,fillStyle:m?.fillStyle,opacity:m?.opacity,roughness:m?.roughness,roundness:m.roundness?XR(m.roundness.type,c)?m.roundness:ZR(c):null});if(Uf(p)){let d=m.fontSize||WR,u=m.fontFamily||YR;p=dp(p,{fontSize:d,fontFamily:u,textAlign:m.textAlign||$R,lineHeight:m.lineHeight||VR(u)});let h=null;p.containerId&&(h=s.find(g=>Uf(p)&&g.id===p.containerId)||null),e7(p,h,n.scene)}return p.type==="arrow"&&qR(m)&&(p=dp(p,{startArrowhead:m.startArrowhead,endArrowhead:m.endArrowhead})),jR(c)&&(p=dp(p,{roundness:null,backgroundColor:"transparent"})),p}return c}),captureUpdate:Wf.IMMEDIATELY}},keyTest:e=>e[yI.CTRL_OR_CMD]&&e.altKey&&e.code===xI.V});import{KEYS as t7}from"@orangecatai/common";import{CaptureUpdateAction as o7}from"@orangecatai/element";var oi=W({name:"toggleShortcuts",label:"welcomeScreen.defaults.helpHint",icon:HE,viewMode:!0,trackEvent:{category:"menu",action:"toggleHelpDialog"},perform:(e,t,o,{focusContainer:n})=>(t.openDialog?.name==="help"&&n(),{appState:{...t,openDialog:t.openDialog?.name==="help"?null:{name:"help"},openMenu:null,openPopup:null},captureUpdate:o7.EVENTUALLY}),keyTest:e=>e.key===t7.QUESTION_MARK});import{getNonDeletedElements as pp}from"@orangecatai/element";import{newElementWith as II}from"@orangecatai/element";import{isBoundToContainer as n7}from"@orangecatai/element";import{frameAndChildrenSelectedTogether as r7,getElementsInResizingFrame as a7,getFrameLikeElements as i7,getRootElements as s7,groupByFrameLikes as l7,removeElementsFromFrame as c7,replaceAllElementsInFrame as d7}from"@orangecatai/element";import{KEYS as up,randomId as m7,arrayToMap as Vf}from"@orangecatai/common";import{getSelectedGroupIds as mp,selectGroup as p7,selectGroupsForSelectedElements as u7,getElementsInGroup as wI,addToGroup as g7,removeFromSelectedGroups as h7,isElementInGroup as TI}from"@orangecatai/element";import{syncMovedIndices as f7}from"@orangecatai/element";import{CaptureUpdateAction as Lc}from"@orangecatai/element";import{jsx as Ds}from"react/jsx-runtime";var b7=e=>{if(e.length>=2){let t=e[0].groupIds;for(let o of t)if(e.reduce((n,r)=>n&&TI(r,o),!0))return!0}return!1},vI=(e,t,o)=>{let n=o.scene.getSelectedElements({selectedElementIds:t.selectedElementIds,includeBoundTextElement:!0});return n.length>=2&&!b7(n)&&!r7(n)},Kf=W({name:"group",label:"labels.group",icon:e=>Ds(Lh,{theme:e.theme}),trackEvent:{category:"element"},perform:(e,t,o,n)=>{let r=s7(n.scene.getSelectedElements({selectedElementIds:t.selectedElementIds,includeBoundTextElement:!0}));if(r.length<2)return{appState:t,elements:e,captureUpdate:Lc.EVENTUALLY};let a=mp(t);if(a.length===1){let x=a[0],E=new Set(wI(e,x).map(v=>v.id)),y=new Set(r.map(v=>v.id));if(new Set([...Array.from(E),...Array.from(y)]).size===E.size)return{appState:t,elements:e,captureUpdate:Lc.EVENTUALLY}}let i=[...e];new Set(r.map(x=>x.frameId)).size>1&&l7(r).forEach((E,y)=>{c7(E,n.scene.getNonDeletedElementsMap())});let l=m7(),c=Vf(r);i=i.map(x=>c.get(x.id)?II(x,{groupIds:g7(x.groupIds,l,t.editingGroupId)}):x);let m=wI(i,l),p=m[m.length-1],d=i.lastIndexOf(p),u=i.slice(d+1),h=i.slice(0,d).filter(x=>!TI(x,l)),g=f7([...h,...m,...u],Vf(m));return{appState:{...t,...p7(l,{...t,selectedGroupIds:{}},pp(i))},elements:g,captureUpdate:Lc.IMMEDIATELY}},predicate:(e,t,o,n)=>vI(e,t,n),keyTest:e=>!e.shiftKey&&e[up.CTRL_OR_CMD]&&e.key===up.G,PanelComponent:({elements:e,appState:t,updateData:o,app:n})=>Ds(ie,{hidden:!vI(e,t,n),type:"button",icon:Ds(Lh,{theme:t.theme}),onClick:()=>o(null),title:`${f("labels.group")} \u2014 ${G("CtrlOrCmd+G")}`,"aria-label":f("labels.group"),visible:Ge(pp(e),t)})}),Xf=W({name:"ungroup",label:"labels.ungroup",icon:e=>Ds(_h,{theme:e.theme}),trackEvent:{category:"element"},perform:(e,t,o,n)=>{let r=mp(t),a=Vf(e);if(r.length===0)return{appState:t,elements:e,captureUpdate:Lc.EVENTUALLY};let i=[...e],s=[];i=i.map(d=>{n7(d)&&s.push(d.id);let u=h7(d.groupIds,t.selectedGroupIds);return u.length===d.groupIds.length?d:II(d,{groupIds:u})});let l=u7(t,pp(i),t,null),c=n.scene.getSelectedElements(t),m=new Set(c.filter(d=>d.frameId).map(d=>d.frameId));return i7(e).filter(d=>m.has(d.id)).forEach(d=>{d&&(i=d7(i,a7(i,d,t,a),d,n))}),l.selectedElementIds=Object.entries(l.selectedElementIds).reduce((d,[u,h])=>(h&&!s.includes(u)&&(d[u]=!0),d),{}),{appState:{...t,...l},elements:i,captureUpdate:Lc.IMMEDIATELY}},keyTest:e=>e.shiftKey&&e[up.CTRL_OR_CMD]&&e.key===up.G.toUpperCase(),predicate:(e,t)=>mp(t).length>0,PanelComponent:({elements:e,appState:t,updateData:o})=>Ds(ie,{type:"button",hidden:mp(t).length===0,icon:Ds(_h,{theme:t.theme}),onClick:()=>o(null),title:`${f("labels.ungroup")} \u2014 ${G("CtrlOrCmd+Shift+G")}`,"aria-label":f("labels.ungroup"),visible:Ge(pp(e),t)})});import T7 from"clsx";import{CaptureUpdateAction as PI}from"@orangecatai/element";import{invariant as C7}from"@orangecatai/common";import{COLOR_CHARCOAL_BLACK as x7,COLOR_VOICE_CALL as y7,COLOR_WHITE as hp,THEME as E7,UserIdleState as CI}from"@orangecatai/common";var gp=(e,t,o,n,r,a,i)=>{e.beginPath(),e.moveTo(t+a,o),e.lineTo(t+n-a,o),e.quadraticCurveTo(t+n,o,t+n,o+a),e.lineTo(t+n,o+r-a),e.quadraticCurveTo(t+n,o+r,t+n-a,o+r),e.lineTo(t+a,o+r),e.quadraticCurveTo(t,o+r,t,o+r-a),e.lineTo(t,o+a),e.quadraticCurveTo(t,o,t+a,o),e.closePath(),e.fill(),i&&(e.strokeStyle=i),e.stroke()};function w7(e){let t=0;if(e.length===0)return t;for(let o=0;o<e.length;o++){let n=e.charCodeAt(o);t=(t<<5)-t+n}return t}var ni=(e,t)=>`hsl(${Math.abs(w7(t?.id||e))%37*10}, 100%, 83%)`,kI=e=>{let t=e?.trim()?.codePointAt(0);return(t?String.fromCodePoint(t):"?").toUpperCase()},SI=({context:e,renderConfig:t,appState:o,normalizedWidth:n,normalizedHeight:r})=>{for(let[a,i]of t.remotePointerViewportCoords){let{x:s,y:l}=i,c=o.collaborators.get(a);s-=o.offsetLeft,l-=o.offsetTop;let m=11,p=14,d=s<0||s>n-m||l<0||l>r-p;s=Math.max(s,0),s=Math.min(s,n-m),l=Math.max(l,0),l=Math.min(l,r-p);let u=ni(a,c);e.save(),e.strokeStyle=u,e.fillStyle=u;let h=t.remotePointerUserStates.get(a),g=d||h===CI.IDLE||h===CI.AWAY;g&&(e.globalAlpha=.3),t.remotePointerButton.get(a)==="down"&&(e.beginPath(),e.arc(s,l,15,0,2*Math.PI,!1),e.lineWidth=3,e.strokeStyle="#ffffff88",e.stroke(),e.closePath(),e.beginPath(),e.arc(s,l,15,0,2*Math.PI,!1),e.lineWidth=1,e.strokeStyle=u,e.stroke(),e.closePath());let x=o.theme===E7.DARK?"#2f6330":y7,E=c?.isSpeaking;E&&(e.fillStyle=x,e.strokeStyle=x,e.lineWidth=10,e.lineJoin="round",e.beginPath(),e.moveTo(s,l),e.lineTo(s+0,l+14),e.lineTo(s+4,l+9),e.lineTo(s+11,l+8),e.closePath(),e.stroke(),e.fill()),e.fillStyle=hp,e.strokeStyle=hp,e.lineWidth=6,e.lineJoin="round",e.beginPath(),e.moveTo(s,l),e.lineTo(s+0,l+14),e.lineTo(s+4,l+9),e.lineTo(s+11,l+8),e.closePath(),e.stroke(),e.fill(),e.fillStyle=u,e.strokeStyle=u,e.lineWidth=2,e.lineJoin="round",e.beginPath(),g?(e.moveTo(s-1,l-1),e.lineTo(s-1,l+15),e.lineTo(s+5,l+10),e.lineTo(s+12,l+9),e.closePath(),e.fill()):(e.moveTo(s,l),e.lineTo(s+0,l+14),e.lineTo(s+4,l+9),e.lineTo(s+11,l+8),e.closePath(),e.fill(),e.stroke());let y=t.remotePointerUsernames.get(a)||"";if(!d&&y){e.font="600 12px sans-serif";let w=(E?s+0:s)+m/2,v=(E?l+0:l)+p+2,I=5,C=3,P=e.measureText(y),S=P.actualBoundingBoxDescent+P.actualBoundingBoxAscent,D=Math.max(S,12),_=w-1,k=v-1,M=P.width+2+I*2+2,B=D+2+C*2+2;if(e.roundRect?(e.beginPath(),e.roundRect(_,k,M,B,8),e.fillStyle=u,e.fill(),e.strokeStyle=hp,e.stroke(),E&&(e.beginPath(),e.roundRect(_-2,k-2,M+4,B+4,8),e.strokeStyle=x,e.stroke())):gp(e,_,k,M,B,8,hp),e.fillStyle=x7,e.fillText(y,w+I+1,v+C+P.actualBoundingBoxAscent+Math.floor((D-S)/2)+2),E){e.fillStyle=x;let O=8,N=8,z=5;e.fillRect(_+M+N,k+(B/2-O/2),2,O),e.fillRect(_+M+N+z,k+(B/2-O*2/2),2,O*2),e.fillRect(_+M+N+z*2,k+(B/2-O/2),2,O)}}e.restore(),e.closePath()}};import v7 from"clsx";import{useState as I7}from"react";import{jsx as MI}from"react/jsx-runtime";var Zf=({color:e,onClick:t,name:o,src:n,className:r})=>{let a=kI(o),[i,s]=I7(!1),l=!i&&n,c=l?void 0:{background:e};return MI("div",{className:v7("Avatar",r),style:c,onClick:t,children:l?MI("img",{className:"Avatar-img",src:n,alt:a,referrerPolicy:"no-referrer",onError:()=>s(!0)}):a})};import{jsx as Yn,jsxs as fp}from"react/jsx-runtime";var k7=W({name:"goToCollaborator",label:"Go to a collaborator",viewMode:!0,trackEvent:{category:"collab"},perform:(e,t,o)=>(C7(o,"actionGoToCollaborator: collaborator should be defined when actionGoToCollaborator is called"),!o.socketId||t.userToFollow?.socketId===o.socketId||o.isCurrentUser?{appState:{...t,userToFollow:null},captureUpdate:PI.EVENTUALLY}:{appState:{...t,userToFollow:{socketId:o.socketId,username:o.username||""},openMenu:t.openMenu==="canvas"?null:t.openMenu},captureUpdate:PI.EVENTUALLY}),PanelComponent:({updateData:e,data:t,appState:o})=>{let{socketId:n,collaborator:r,withName:a,isBeingFollowed:i}=t,s=ni(n,r),l=T7({"is-followed":i,"is-current-user":r.isCurrentUser===!0,"is-speaking":r.isSpeaking,"is-in-call":r.isInCall,"is-muted":r.isMuted}),c=r.isInCall?r.isSpeaking?fp("div",{className:"UserList__collaborator-status-icon-speaking-indicator",title:f("userList.hint.isSpeaking"),children:[Yn("div",{}),Yn("div",{}),Yn("div",{})]}):r.isMuted?Yn("div",{className:"UserList__collaborator-status-icon-microphone-muted",title:f("userList.hint.micMuted"),children:Jw}):Yn("div",{title:f("userList.hint.inCall"),children:qw}):null;return a?fp("div",{className:`dropdown-menu-item dropdown-menu-item-base UserList__collaborator ${l}`,style:{"--avatar-size":"1.5rem"},onClick:()=>e(r),children:[Yn(Zf,{color:s,onClick:()=>{},name:r.username||"",src:r.avatarUrl,className:l}),Yn("div",{className:"UserList__collaborator-name",children:r.username}),fp("div",{className:"UserList__collaborator-status-icons","aria-hidden":!0,children:[i&&Yn("div",{className:"UserList__collaborator-status-icon-is-followed",title:f("userList.hint.followStatus"),children:ls}),c]})]}):fp("div",{className:`UserList__collaborator UserList__collaborator--avatar-only ${l}`,children:[Yn(Zf,{color:s,onClick:()=>{e(r)},name:r.username||"",src:r.avatarUrl,className:l}),c&&Yn("div",{className:"UserList__collaborator-status-icon",children:c})]})}});import{LIBRARY_DISABLED_TYPES as S7,randomId as M7}from"@orangecatai/common";import{deepCopyElement as P7}from"@orangecatai/element";import{CaptureUpdateAction as jf}from"@orangecatai/element";var qf=W({name:"addToLibrary",trackEvent:{category:"element"},perform:(e,t,o,n)=>{let r=n.scene.getSelectedElements({selectedElementIds:t.selectedElementIds,includeBoundTextElement:!0,includeElementsInFrames:!0});for(let a of S7)if(r.some(i=>i.type===a))return{captureUpdate:jf.EVENTUALLY,appState:{...t,errorMessage:f(`errors.libraryElementTypeError.${a}`)}};return n.library.getLatestLibrary().then(a=>n.library.setLibrary([{id:M7(),status:"unpublished",elements:r.map(P7),created:Date.now()},...a])).then(()=>({captureUpdate:jf.EVENTUALLY,appState:{...t,toast:{message:f("toast.addedToLibrary")}}})).catch(a=>({captureUpdate:jf.EVENTUALLY,appState:{...t,errorMessage:a.message}}))},label:"labels.addToLibrary"});import{getNonDeletedElements as Rs}from"@orangecatai/element";import{isFrameLikeElement as A7}from"@orangecatai/element";import{updateFrameMembershipOfSelectedElements as L7}from"@orangecatai/element";import{KEYS as ea,arrayToMap as _7}from"@orangecatai/common";import{alignElements as D7}from"@orangecatai/element";import{CaptureUpdateAction as Ns}from"@orangecatai/element";import{getSelectedElementsByGroup as R7}from"@orangecatai/element";import{jsx as Fs}from"react/jsx-runtime";var ao=(e,t)=>{let o=t.scene.getSelectedElements(e);return R7(o,t.scene.getNonDeletedElementsMap(),e).length>1&&!o.some(n=>A7(n))},Bs=(e,t,o,n)=>{let r=o.scene.getSelectedElements(t),a=D7(r,n,o.scene,t),i=_7(a);return L7(e.map(s=>i.get(s.id)||s),t,o)},N7=W({name:"alignTop",label:"labels.alignTop",icon:Ch,trackEvent:{category:"element"},predicate:(e,t,o,n)=>ao(t,n),perform:(e,t,o,n)=>({appState:t,elements:Bs(e,t,n,{position:"start",axis:"y"}),captureUpdate:Ns.IMMEDIATELY}),keyTest:e=>e[ea.CTRL_OR_CMD]&&e.shiftKey&&e.key===ea.ARROW_UP,PanelComponent:({elements:e,appState:t,updateData:o,app:n})=>Fs(ie,{hidden:!ao(t,n),type:"button",icon:Ch,onClick:()=>o(null),title:`${f("labels.alignTop")} \u2014 ${G("CtrlOrCmd+Shift+Up")}`,"aria-label":f("labels.alignTop"),visible:Ge(Rs(e),t)})}),B7=W({name:"alignBottom",label:"labels.alignBottom",icon:kh,trackEvent:{category:"element"},predicate:(e,t,o,n)=>ao(t,n),perform:(e,t,o,n)=>({appState:t,elements:Bs(e,t,n,{position:"end",axis:"y"}),captureUpdate:Ns.IMMEDIATELY}),keyTest:e=>e[ea.CTRL_OR_CMD]&&e.shiftKey&&e.key===ea.ARROW_DOWN,PanelComponent:({elements:e,appState:t,updateData:o,app:n})=>Fs(ie,{hidden:!ao(t,n),type:"button",icon:kh,onClick:()=>o(null),title:`${f("labels.alignBottom")} \u2014 ${G("CtrlOrCmd+Shift+Down")}`,"aria-label":f("labels.alignBottom"),visible:Ge(Rs(e),t)})}),F7=W({name:"alignLeft",label:"labels.alignLeft",icon:Sh,trackEvent:{category:"element"},predicate:(e,t,o,n)=>ao(t,n),perform:(e,t,o,n)=>({appState:t,elements:Bs(e,t,n,{position:"start",axis:"x"}),captureUpdate:Ns.IMMEDIATELY}),keyTest:e=>e[ea.CTRL_OR_CMD]&&e.shiftKey&&e.key===ea.ARROW_LEFT,PanelComponent:({elements:e,appState:t,updateData:o,app:n})=>Fs(ie,{hidden:!ao(t,n),type:"button",icon:Sh,onClick:()=>o(null),title:`${f("labels.alignLeft")} \u2014 ${G("CtrlOrCmd+Shift+Left")}`,"aria-label":f("labels.alignLeft"),visible:Ge(Rs(e),t)})}),O7=W({name:"alignRight",label:"labels.alignRight",icon:Mh,trackEvent:{category:"element"},predicate:(e,t,o,n)=>ao(t,n),perform:(e,t,o,n)=>({appState:t,elements:Bs(e,t,n,{position:"end",axis:"x"}),captureUpdate:Ns.IMMEDIATELY}),keyTest:e=>e[ea.CTRL_OR_CMD]&&e.shiftKey&&e.key===ea.ARROW_RIGHT,PanelComponent:({elements:e,appState:t,updateData:o,app:n})=>Fs(ie,{hidden:!ao(t,n),type:"button",icon:Mh,onClick:()=>o(null),title:`${f("labels.alignRight")} \u2014 ${G("CtrlOrCmd+Shift+Right")}`,"aria-label":f("labels.alignRight"),visible:Ge(Rs(e),t)})}),z7=W({name:"alignVerticallyCentered",label:"labels.centerVertically",icon:Ph,trackEvent:{category:"element"},predicate:(e,t,o,n)=>ao(t,n),perform:(e,t,o,n)=>({appState:t,elements:Bs(e,t,n,{position:"center",axis:"y"}),captureUpdate:Ns.IMMEDIATELY}),PanelComponent:({elements:e,appState:t,updateData:o,app:n})=>Fs(ie,{hidden:!ao(t,n),type:"button",icon:Ph,onClick:()=>o(null),title:f("labels.centerVertically"),"aria-label":f("labels.centerVertically"),visible:Ge(Rs(e),t)})}),H7=W({name:"alignHorizontallyCentered",label:"labels.centerHorizontally",icon:Ah,trackEvent:{category:"element"},predicate:(e,t,o,n)=>ao(t,n),perform:(e,t,o,n)=>({appState:t,elements:Bs(e,t,n,{position:"center",axis:"x"}),captureUpdate:Ns.IMMEDIATELY}),PanelComponent:({elements:e,appState:t,updateData:o,app:n})=>Fs(ie,{hidden:!ao(t,n),type:"button",icon:Ah,onClick:()=>o(null),title:f("labels.centerHorizontally"),"aria-label":f("labels.centerHorizontally"),visible:Ge(Rs(e),t)})});import{getNonDeletedElements as AI}from"@orangecatai/element";import{isFrameLikeElement as G7}from"@orangecatai/element";import{CODES as LI,KEYS as _I,arrayToMap as U7}from"@orangecatai/common";import{updateFrameMembershipOfSelectedElements as W7}from"@orangecatai/element";import{distributeElements as Y7}from"@orangecatai/element";import{CaptureUpdateAction as DI}from"@orangecatai/element";import{getSelectedElementsByGroup as $7}from"@orangecatai/element";import{jsx as BI}from"react/jsx-runtime";var RI=(e,t)=>{let o=t.scene.getSelectedElements(e);return $7(o,t.scene.getNonDeletedElementsMap(),e).length>2&&!o.some(n=>G7(n))},NI=(e,t,o,n)=>{let r=o.scene.getSelectedElements(t),a=Y7(r,o.scene.getNonDeletedElementsMap(),n,t,o.scene),i=U7(a);return W7(e.map(s=>i.get(s.id)||s),t,o)},V7=W({name:"distributeHorizontally",label:"labels.distributeHorizontally",trackEvent:{category:"element"},perform:(e,t,o,n)=>({appState:t,elements:NI(e,t,n,{space:"between",axis:"x"}),captureUpdate:DI.IMMEDIATELY}),keyTest:e=>!e[_I.CTRL_OR_CMD]&&e.altKey&&e.code===LI.H,PanelComponent:({elements:e,appState:t,updateData:o,app:n})=>BI(ie,{hidden:!RI(t,n),type:"button",icon:JE,onClick:()=>o(null),title:`${f("labels.distributeHorizontally")} \u2014 ${G("Alt+H")}`,"aria-label":f("labels.distributeHorizontally"),visible:Ge(AI(e),t)})}),K7=W({name:"distributeVertically",label:"labels.distributeVertically",trackEvent:{category:"element"},perform:(e,t,o,n)=>({appState:t,elements:NI(e,t,n,{space:"between",axis:"y"}),captureUpdate:DI.IMMEDIATELY}),keyTest:e=>!e[_I.CTRL_OR_CMD]&&e.altKey&&e.code===LI.V,PanelComponent:({elements:e,appState:t,updateData:o,app:n})=>BI(ie,{hidden:!RI(t,n),type:"button",icon:QE,onClick:()=>o(null),title:`${f("labels.distributeVertically")} \u2014 ${G("Alt+V")}`,"aria-label":f("labels.distributeVertically"),visible:Ge(AI(e),t)})});import{getNonDeletedElements as X7}from"@orangecatai/element";import{bindOrUnbindBindingElements as Z7}from"@orangecatai/element";import{getCommonBoundingBox as FI}from"@orangecatai/element";import{newElementWith as j7}from"@orangecatai/element";import{deepCopyElement as q7}from"@orangecatai/element";import{resizeMultipleElements as J7}from"@orangecatai/element";import{isArrowElement as OI,isElbowArrow as Q7}from"@orangecatai/element";import{updateFrameMembershipOfSelectedElements as zI}from"@orangecatai/element";import{CODES as HI,KEYS as eN,arrayToMap as tN}from"@orangecatai/common";import{CaptureUpdateAction as GI}from"@orangecatai/element";var Jf=W({name:"flipHorizontal",label:"labels.flipHorizontal",icon:ov,trackEvent:{category:"element"},perform:(e,t,o,n)=>({elements:zI(UI(e,n.scene.getNonDeletedElementsMap(),t,"horizontal",n),t,n),appState:t,captureUpdate:GI.IMMEDIATELY}),keyTest:e=>e.shiftKey&&e.code===HI.H}),Qf=W({name:"flipVertical",label:"labels.flipVertical",icon:tv,trackEvent:{category:"element"},perform:(e,t,o,n)=>({elements:zI(UI(e,n.scene.getNonDeletedElementsMap(),t,"vertical",n),t,n),appState:t,captureUpdate:GI.IMMEDIATELY}),keyTest:e=>e.shiftKey&&e.code===HI.V&&!e[eN.CTRL_OR_CMD]}),UI=(e,t,o,n,r)=>{let a=de(X7(e),o,{includeBoundTextElement:!0,includeElementsInFrames:!0}),i=oN(a,t,n,r),s=tN(i);return e.map(l=>s.get(l.id)||l)},oN=(e,t,o,n)=>{if(e.every(d=>OI(d)&&(d.startBinding||d.endBinding)))return e.map(d=>{let u=d;return j7(u,{startArrowhead:u.endArrowhead,endArrowhead:u.startArrowhead})});let{midX:r,midY:a}=FI(e);J7(e,t,"nw",n.scene,new Map(Array.from(t.values()).map(d=>[d.id,q7(d)])),{flipByX:o==="horizontal",flipByY:o==="vertical",shouldResizeFromCenter:!0,shouldMaintainAspectRatio:!0}),Z7(e.filter(OI),n.scene,n.state);let{elbowArrows:i,otherElements:s}=e.reduce((d,u)=>Q7(u)?{...d,elbowArrows:d.elbowArrows.concat(u)}:{...d,otherElements:d.otherElements.concat(u)},{elbowArrows:[],otherElements:[]}),{midX:l,midY:c}=FI(e),[m,p]=[r-l,a-c];return s.forEach(d=>n.scene.mutateElement(d,{x:d.x+m,y:d.y+p})),i.forEach(d=>n.scene.mutateElement(d,{x:d.x+m,y:d.y+p})),e};import{isTextElement as nN}from"@orangecatai/element";import{getTextFromElements as rN}from"@orangecatai/element";import{CODES as aN,KEYS as WI,isFirefox as iN}from"@orangecatai/common";import{CaptureUpdateAction as _o}from"@orangecatai/element";var Os=W({name:"copy",label:"labels.copy",icon:tc,trackEvent:{category:"element"},perform:async(e,t,o,n)=>{let r=n.scene.getSelectedElements({selectedElementIds:t.selectedElementIds,includeBoundTextElement:!0,includeElementsInFrames:!0});try{await ip(r,n.files,o)}catch(a){return{captureUpdate:_o.EVENTUALLY,appState:{...t,errorMessage:a.message}}}return{captureUpdate:_o.EVENTUALLY}},keyTest:void 0}),eb=W({name:"paste",label:"labels.paste",trackEvent:{category:"element"},perform:async(e,t,o,n)=>{let r;try{r=await mI()}catch(a){return a.name==="AbortError"||a.name==="NotAllowedError"?!1:(console.error(`actionPaste ${a.name}: ${a.message}`),iN?{captureUpdate:_o.EVENTUALLY,appState:{...t,errorMessage:f("hints.firefox_clipboard_write")}}:{captureUpdate:_o.EVENTUALLY,appState:{...t,errorMessage:f("errors.asyncPasteFailedOnRead")}})}try{n.pasteFromClipboard(cI({types:r}))}catch(a){return console.error(a),{captureUpdate:_o.EVENTUALLY,appState:{...t,errorMessage:f("errors.asyncPasteFailedOnParse")}}}return{captureUpdate:_o.EVENTUALLY}},keyTest:void 0}),bp=W({name:"cut",label:"labels.cut",icon:Ow,trackEvent:{category:"element"},perform:(e,t,o,n)=>(Os.perform(e,t,o,n),dc.perform(e,t,null,n)),keyTest:e=>e[WI.CTRL_OR_CMD]&&e.key===WI.X}),xp=W({name:"copyAsSvg",label:"labels.copyAsSvg",icon:nv,trackEvent:{category:"element"},perform:async(e,t,o,n)=>{if(!n.canvas)return{captureUpdate:_o.EVENTUALLY};let{exportedElements:r,exportingFrame:a}=Qa(e,t,!0);try{await ei("clipboard-svg",r,t,n.files,{...t,exportingFrame:a,name:n.getName()});let i=n.scene.getSelectedElements({selectedElementIds:t.selectedElementIds,includeBoundTextElement:!0,includeElementsInFrames:!0});return{appState:{toast:{message:f("toast.copyToClipboardAsSvg",{exportSelection:i.length?f("toast.selection"):f("toast.canvas"),exportColorScheme:t.exportWithDarkMode?f("buttons.darkMode"):f("buttons.lightMode")})}},captureUpdate:_o.EVENTUALLY}}catch(i){return console.error(i),{appState:{errorMessage:i.message},captureUpdate:_o.EVENTUALLY}}},predicate:e=>ap&&e.length>0,keywords:["svg","clipboard","copy"]}),yp=W({name:"copyAsPng",label:"labels.copyAsPng",icon:rv,trackEvent:{category:"element"},perform:async(e,t,o,n)=>{if(!n.canvas)return{captureUpdate:_o.EVENTUALLY};let r=n.scene.getSelectedElements({selectedElementIds:t.selectedElementIds,includeBoundTextElement:!0,includeElementsInFrames:!0}),{exportedElements:a,exportingFrame:i}=Qa(e,t,!0);try{return await ei("clipboard",a,t,n.files,{...t,exportingFrame:i,name:n.getName()}),{appState:{...t,toast:{message:f("toast.copyToClipboardAsPng",{exportSelection:r.length?f("toast.selection"):f("toast.canvas"),exportColorScheme:t.exportWithDarkMode?f("buttons.darkMode"):f("buttons.lightMode")})}},captureUpdate:_o.EVENTUALLY}}catch(s){return console.error(s),{appState:{...t,errorMessage:s.message},captureUpdate:_o.EVENTUALLY}}},predicate:e=>Ps&&e.length>0,keyTest:e=>e.code===aN.C&&e.altKey&&e.shiftKey,keywords:["png","clipboard","copy"]}),Ep=W({name:"copyText",label:"labels.copyText",trackEvent:{category:"element"},perform:(e,t,o,n)=>{let r=n.scene.getSelectedElements({selectedElementIds:t.selectedElementIds,includeBoundTextElement:!0});try{hn(rN(r))}catch{throw new Error(f("errors.copyToSystemClipboardFailed"))}return{captureUpdate:_o.EVENTUALLY}},predicate:(e,t,o,n)=>ap&&n.scene.getSelectedElements({selectedElementIds:t.selectedElementIds,includeBoundTextElement:!0}).some(nN),keywords:["text","clipboard","copy"]});import{CODES as sN,KEYS as lN}from"@orangecatai/common";import{CaptureUpdateAction as cN}from"@orangecatai/element";var zs=W({name:"gridMode",icon:cv,keywords:["snap"],label:"labels.toggleGrid",viewMode:!0,trackEvent:{category:"canvas",predicate:e=>e.gridModeEnabled},perform(e,t){return{appState:{...t,gridModeEnabled:!this.checked(t),objectsSnapModeEnabled:!1},captureUpdate:cN.EVENTUALLY}},checked:e=>e.gridModeEnabled,predicate:(e,t,o)=>o.gridModeEnabled===void 0,keyTest:e=>e[lN.CTRL_OR_CMD]&&e.code===sN.QUOTE});import{CODES as dN,KEYS as mN}from"@orangecatai/common";import{CaptureUpdateAction as pN}from"@orangecatai/element";var ta=W({name:"zenMode",label:"buttons.zenMode",icon:iv,viewMode:!0,trackEvent:{category:"canvas",predicate:e=>!e.zenModeEnabled},perform(e,t){return{appState:{...t,zenModeEnabled:!this.checked(t)},captureUpdate:pN.EVENTUALLY}},checked:e=>e.zenModeEnabled,predicate:(e,t,o,n)=>n.editorInterface.formFactor!=="phone"&&typeof o.zenModeEnabled>"u",keyTest:e=>!e[mN.CTRL_OR_CMD]&&e.altKey&&e.code===dN.Z});import{CODES as uN,KEYS as gN}from"@orangecatai/common";import{CaptureUpdateAction as hN}from"@orangecatai/element";var _c=W({name:"objectsSnapMode",label:"buttons.objectsSnapMode",icon:av,viewMode:!1,trackEvent:{category:"canvas",predicate:e=>!e.objectsSnapModeEnabled},perform(e,t){return{appState:{...t,objectsSnapModeEnabled:!this.checked(t),gridModeEnabled:!1},captureUpdate:hN.EVENTUALLY}},checked:e=>e.objectsSnapModeEnabled,predicate:(e,t,o)=>typeof o.objectsSnapModeEnabled>"u",keyTest:e=>!e[gN.CTRL_OR_CMD]&&e.altKey&&e.code===uN.S});import{CODES as fN,KEYS as bN}from"@orangecatai/common";import{CaptureUpdateAction as xN}from"@orangecatai/element";var oa=W({name:"stats",label:"stats.fullTitle",icon:ev,viewMode:!0,trackEvent:{category:"menu"},keywords:["edit","attributes","customize"],perform(e,t){return{appState:{...t,stats:{...t.stats,open:!this.checked(t)}},captureUpdate:xN.EVENTUALLY}},checked:e=>e.stats.open,keyTest:e=>!e[bN.CTRL_OR_CMD]&&e.altKey&&e.code===fN.SLASH});import{BOUND_TEXT_PADDING as YI,ROUNDNESS as $I,TEXT_ALIGN as XI,VERTICAL_ALIGN as ZI,arrayToMap as jI,getFontString as yN}from"@orangecatai/common";import{getOriginalContainerHeightFromCache as EN,isBoundToContainer as VI,resetOriginalContainerCache as wN,updateOriginalContainerCache as vN}from"@orangecatai/element";import{computeBoundTextPosition as IN,computeContainerDimensionForBoundText as KI,getBoundTextElement as qI,redrawTextBoundingBox as JI}from"@orangecatai/element";import{hasBoundTextElement as TN,isArrowElement as CN,isTextBindableContainer as tb,isTextElement as Dc,isUsingAdaptiveRadius as kN}from"@orangecatai/element";import{measureText as SN}from"@orangecatai/element";import{syncMovedIndices as QI}from"@orangecatai/element";import{newElement as MN}from"@orangecatai/element";import{CaptureUpdateAction as ob}from"@orangecatai/element";var nb=W({name:"unbindText",label:"labels.unbindText",trackEvent:{category:"element"},predicate:(e,t,o,n)=>n.scene.getSelectedElements(t).some(a=>TN(a)),perform:(e,t,o,n)=>{let r=n.scene.getSelectedElements(t),a=n.scene.getNonDeletedElementsMap();return r.forEach(i=>{let s=qI(i,a);if(s){let{width:l,height:c}=SN(s.originalText,yN(s),s.lineHeight),m=EN(i.id);wN(i.id);let{x:p,y:d}=IN(i,s,a);n.scene.mutateElement(s,{containerId:null,width:l,height:c,text:s.originalText,x:p,y:d}),n.scene.mutateElement(i,{boundElements:i.boundElements?.filter(u=>u.id!==s.id),height:m||i.height})}}),{elements:e,appState:t,captureUpdate:ob.IMMEDIATELY}}}),rb=W({name:"bindText",label:"labels.bindText",trackEvent:{category:"element"},predicate:(e,t,o,n)=>{let r=n.scene.getSelectedElements(t);if(r.length===2){let a=Dc(r[0])||Dc(r[1]),i;if(tb(r[0])?i=r[0]:tb(r[1])&&(i=r[1]),a&&i&&qI(i,n.scene.getNonDeletedElementsMap())===null)return!0}return!1},perform:(e,t,o,n)=>{let r=n.scene.getSelectedElements(t),a,i;Dc(r[0])&&tb(r[1])?(a=r[0],i=r[1]):(a=r[1],i=r[0]),n.scene.mutateElement(a,{containerId:i.id,verticalAlign:ZI.MIDDLE,textAlign:XI.CENTER,autoResize:!0,angle:CN(i)?0:i?.angle??0}),n.scene.mutateElement(i,{boundElements:(i.boundElements||[]).concat({type:"text",id:a.id})});let s=i.height;return JI(a,i,n.scene),vN(i.id,s),{elements:PN(e,i,a),appState:{...t,selectedElementIds:{[i.id]:!0}},captureUpdate:ob.IMMEDIATELY}}}),PN=(e,t,o)=>{let n=e.slice(),r=n.findIndex(i=>i.id===o.id);n.splice(r,1);let a=n.findIndex(i=>i.id===t.id);return n.splice(a+1,0,o),QI(n,jI([t,o])),n},AN=(e,t,o)=>{let n=e.slice(),r=n.findIndex(i=>i.id===t.id);n.splice(r,1);let a=n.findIndex(i=>i.id===o.id);return n.splice(a,0,t),QI(n,jI([t,o])),n},eT=W({name:"wrapTextInContainer",label:"labels.createContainerFromText",trackEvent:{category:"element"},predicate:(e,t,o,n)=>{let r=n.scene.getSelectedElements(t),a=r.some(i=>Dc(i)&&!VI(i));return r.length>0&&a},perform:(e,t,o,n)=>{let r=n.scene.getSelectedElements(t),a=e.slice(),i={};for(let s of r)if(Dc(s)&&!VI(s)){let l=MN({type:"rectangle",backgroundColor:t.currentItemBackgroundColor,boundElements:[...s.boundElements||[],{id:s.id,type:"text"}],angle:s.angle,fillStyle:t.currentItemFillStyle,strokeColor:t.currentItemStrokeColor,roughness:t.currentItemRoughness,strokeWidth:t.currentItemStrokeWidth,strokeStyle:t.currentItemStrokeStyle,roundness:t.currentItemRoundness==="round"?{type:kN("rectangle")?$I.ADAPTIVE_RADIUS:$I.PROPORTIONAL_RADIUS}:null,opacity:100,locked:!1,x:s.x-YI,y:s.y-YI,width:KI(s.width,"rectangle"),height:KI(s.height,"rectangle"),groupIds:s.groupIds,frameId:s.frameId});if(s.boundElements?.length){let c=s.boundElements.filter(p=>p.type==="arrow").map(p=>p.id);a.filter(p=>c.includes(p.id)).forEach(p=>{let d=p.startBinding,u=p.endBinding;d?.elementId===s.id&&(d={...d,elementId:l.id}),u?.elementId===s.id&&(u={...u,elementId:l.id}),(d||u)&&n.scene.mutateElement(p,{startBinding:d,endBinding:u})})}n.scene.mutateElement(s,{containerId:l.id,verticalAlign:ZI.MIDDLE,boundElements:null,textAlign:XI.CENTER,autoResize:!0}),JI(s,l,n.scene),a=AN([...a,l],l,s),i[l.id]=!0}return{elements:a,appState:{...t,selectedElementIds:i},captureUpdate:ob.IMMEDIATELY}}});import{isEmbeddableElement as KN}from"@orangecatai/element";import{KEYS as dT}from"@orangecatai/common";import{CaptureUpdateAction as XN}from"@orangecatai/element";import{pointFrom as rT}from"@orangecatai/math";import LN from"clsx";import{useCallback as tT,useEffect as oT,useLayoutEffect as _N,useRef as DN,useState as RN}from"react";import{EVENT as ab,HYPERLINK_TOOLTIP_DELAY as NN,KEYS as wp}from"@orangecatai/common";import{getElementAbsoluteCoords as db}from"@orangecatai/element";import{hitElementBoundingBox as BN}from"@orangecatai/element";import{isElementLink as FN}from"@orangecatai/element";import{getEmbedLink as ON,embeddableURLValidator as zN}from"@orangecatai/element";import{sceneCoordsToViewportCoords as aT,viewportCoordsToSceneCoords as HN,wrapEvent as GN,isLocalLink as UN,normalizeLink as ib}from"@orangecatai/common";import{isEmbeddableElement as sb}from"@orangecatai/element";import{jsx as Hs,jsxs as nT}from"react/jsx-runtime";var mb=380,WN=42,lb=5,iT=85,YN=500,cb=!1,vp=new Map,sT=({element:e,scene:t,setAppState:o,onLinkOpen:n,setToast:r,updateEmbedValidationStatus:a})=>{let i=t.getNonDeletedElementsMap(),s=$o(),l=Hn(),c=Te(),m=e.link||"",[p,d]=RN(m),u=DN(null),h=s.showHyperlinkPopup==="editor",g=tT(()=>{if(!u.current)return;let v=ib(u.current.value)||null;if(!e.link&&v&&be("hyperlink","create"),sb(e)){if(s.activeEmbeddable?.element===e&&o({activeEmbeddable:null}),!v){t.mutateElement(e,{link:null}),a(e,!1);return}if(!zN(v,l.validateEmbeddable))v&&r({message:f("toast.unableToEmbed"),closable:!0}),e.link&&vp.set(e.id,e.link),t.mutateElement(e,{link:v}),a(e,!1);else{let{width:I,height:C}=e,P=ON(v);P?.error instanceof URIError&&r({message:f("toast.unrecognizedLinkFormat"),closable:!0});let S=P?P.intrinsicSize.w/P.intrinsicSize.h:1,D=vp.get(e.id)!==e.link;t.mutateElement(e,{...D?{width:P?.type==="video"?I>C?I:C*S:I,height:P?.type==="video"&&I>C?I/S:C}:{},link:v}),a(e,!0),vp.has(e.id)&&vp.delete(e.id)}}else t.mutateElement(e,{link:v})},[e,t,r,l.validateEmbeddable,s.activeEmbeddable,o,a]);_N(()=>()=>{g()},[g]),oT(()=>{h&&u?.current&&!(c.formFactor==="phone"||c.isTouchScreen)&&u.current.select()},[h,c.formFactor,c.isTouchScreen]),oT(()=>{let v=null,I=C=>{if(h)return;v&&clearTimeout(v),VN(e,i,s,rT(C.clientX,C.clientY))&&(v=window.setTimeout(()=>{o({showHyperlinkPopup:!1})},YN))};return window.addEventListener(ab.POINTER_MOVE,I,!1),()=>{window.removeEventListener(ab.POINTER_MOVE,I,!1),v&&clearTimeout(v)}},[s,e,h,o,i]);let x=tT(()=>{be("hyperlink","delete"),t.mutateElement(e,{link:null}),o({showHyperlinkPopup:!1})},[o,e,t]),E=()=>{be("hyperlink","edit","popup-ui"),o({showHyperlinkPopup:"editor"})},{x:y,y:w}=lT(e,s,i);return s.contextMenu||s.selectedElementsAreBeingDragged||s.resizingElement||s.isRotating||s.openMenu||s.viewModeEnabled?null:nT("div",{className:"excalidraw-hyperlinkContainer",style:{top:`${w}px`,left:`${y}px`,width:mb,padding:lb},children:[h?Hs("input",{className:LN("excalidraw-hyperlinkContainer-input"),placeholder:f("labels.link.hint"),ref:u,value:p,onChange:v=>d(v.target.value),autoFocus:!0,onKeyDown:v=>{v.stopPropagation(),v[wp.CTRL_OR_CMD]&&v.key===wp.K&&v.preventDefault(),(v.key===wp.ENTER||v.key===wp.ESCAPE)&&(g(),o({showHyperlinkPopup:"info"}))}}):e.link?Hs("a",{href:ib(e.link||""),className:"excalidraw-hyperlinkContainer-link",target:UN(e.link)?"_self":"_blank",onClick:v=>{if(e.link&&n){let I=GN(ab.EXCALIDRAW_LINK,v.nativeEvent);n({...e,link:ib(e.link)},I),I.defaultPrevented&&v.preventDefault()}},rel:"noopener noreferrer",children:e.link}):Hs("div",{className:"excalidraw-hyperlinkContainer-link",children:f("labels.link.empty")}),nT("div",{className:"excalidraw-hyperlinkContainer__buttons",children:[!h&&Hs(ie,{type:"button",title:f("buttons.edit"),"aria-label":f("buttons.edit"),label:f("buttons.edit"),onClick:E,className:"excalidraw-hyperlinkContainer--edit",icon:Bn}),Hs(ie,{type:"button",title:f("labels.linkToElement"),"aria-label":f("labels.linkToElement"),label:f("labels.linkToElement"),onClick:()=>{o({openDialog:{name:"elementLinkSelector",sourceElementId:e.id}})},icon:Cm}),m&&!sb(e)&&Hs(ie,{type:"button",title:f("buttons.remove"),"aria-label":f("buttons.remove"),label:f("buttons.remove"),onClick:x,className:"excalidraw-hyperlinkContainer--remove",icon:Ut})]})]})},lT=(e,t,o)=>{let[n,r]=db(e,o),{x:a,y:i}=aT({sceneX:n+e.width/2,sceneY:r},t),s=a-t.offsetLeft-mb/2,l=i-t.offsetTop-iT;return{x:s,y:l}},pb=(e,t)=>{let o=de(e,t);return sb(o[0])?"labels.link.editEmbed":o[0]?.link?"labels.link.edit":"labels.link.create"},Rc=null,cT=(e,t,o)=>{Rc&&clearTimeout(Rc),Rc=window.setTimeout(()=>$N(e,t,o),NN)},$N=(e,t,o)=>{if(!e.link)return;let n=Ts();n.classList.add("excalidraw-tooltip--visible"),n.style.maxWidth="20rem",n.textContent=FN(e.link)?f("labels.link.goToElement"):e.link;let[r,a,i,s]=db(e,o),[l,c,m,p]=sE([r,a,i,s],e.angle,t),d=aT({sceneX:l,sceneY:c},t);Mf(n,{left:d.x,top:d.y,width:m,height:p},"top"),be("hyperlink","tooltip","link-icon"),cb=!0},ub=()=>{Rc&&clearTimeout(Rc),cb&&(cb=!1,Ts().classList.remove("excalidraw-tooltip--visible"))},VN=(e,t,o,[n,r])=>{let{x:a,y:i}=HN({clientX:n,clientY:r},o),s=15/o.zoom.value;if(BN(rT(a,i),e,t))return!1;let[l,c,m]=db(e,t);if(a>=l&&a<=m&&i>=c-iT&&i<=c)return!1;let{x:p,y:d}=lT(e,o,t);return!(n>=p-s&&n<=p+mb+lb*2+s&&r>=d-s&&r<=d+s+lb*2+WN)};import{jsx as ZN}from"react/jsx-runtime";var Nc=W({name:"hyperlink",label:(e,t)=>pb(e,t),icon:rc,perform:(e,t)=>t.showHyperlinkPopup==="editor"?!1:{elements:e,appState:{...t,showHyperlinkPopup:"editor",openMenu:null},captureUpdate:XN.IMMEDIATELY},trackEvent:{category:"hyperlink",action:"click"},keyTest:e=>e[dT.CTRL_OR_CMD]&&e.key===dT.K,predicate:(e,t)=>de(e,t).length===1,PanelComponent:({elements:e,appState:t,updateData:o})=>{let n=de(e,t);return ZN(ie,{type:"button",icon:rc,"aria-label":f(pb(e,t)),title:`${KN(e[0])?f("labels.link.labelEmbed"):f("labels.link.label")} - ${G("CtrlOrCmd+K")}`,onClick:()=>o(null),selected:n.length===1&&!!n[0].link})}});import{KEYS as mT,arrayToMap as hb,randomId as jN}from"@orangecatai/common";import{elementsAreInSameGroup as qN,newElementWith as pT,selectGroupsFromGivenElements as uT}from"@orangecatai/element";import{CaptureUpdateAction as gT}from"@orangecatai/element";var gb=e=>e.every(t=>!t.locked),Bc=W({name:"toggleElementLock",label:(e,t,o)=>{let n=o.scene.getSelectedElements({selectedElementIds:t.selectedElementIds,includeBoundTextElement:!1});return gb(n)?"labels.elementLock.lock":"labels.elementLock.unlock"},icon:(e,t)=>{let o=de(t,e);return gb(o)?ji:Wa},trackEvent:{category:"element"},predicate:(e,t,o,n)=>{let r=n.scene.getSelectedElements(t);return r.length>0&&!r.some(a=>a.locked&&a.frameId)},perform:(e,t,o,n)=>{let r=n.scene.getSelectedElements({selectedElementIds:t.selectedElementIds,includeBoundTextElement:!0,includeElementsInFrames:!0});if(!r.length)return!1;let a=gb(r),i=hb(r),s=r.length>1&&qN(r),c=r.length===1||s?null:jN(),m={...t.lockedMultiSelections};if(a)m={...t.lockedMultiSelections,...c?{[c]:!0}:{}};else if(s){let E=r[0].groupIds.at(-1);delete m[E]}let p=e.map(E=>{if(!i.has(E.id))return E;let y=E.groupIds;return a?c&&(y=[...y,c]):y=y.filter(w=>!t.lockedMultiSelections[w]),pT(E,{locked:a,groupIds:y.length!==E.groupIds.length?y:E.groupIds})}),d=hb(p),u=a?{}:Object.fromEntries(r.map(E=>[E.id,!0])),h=r.map(E=>d.get(E.id)||E),g=a?{}:uT(h,t),x=a?c||(s?r[0].groupIds.at(-1):r[0].id):null;return{elements:p,appState:{...t,selectedElementIds:u,selectedGroupIds:g,selectedLinearElement:a?null:t.selectedLinearElement,lockedMultiSelections:m,activeLockedId:x},captureUpdate:gT.IMMEDIATELY}},keyTest:(e,t,o,n)=>e.key.toLocaleLowerCase()===mT.L&&e[mT.CTRL_OR_CMD]&&e.shiftKey&&n.scene.getSelectedElements({selectedElementIds:t.selectedElementIds,includeBoundTextElement:!1}).length>0}),hT=W({name:"unlockAllElements",trackEvent:{category:"canvas"},viewMode:!1,icon:Wa,predicate:(e,t)=>de(e,t).length===0&&e.some(n=>n.locked),perform:(e,t)=>{let o=e.filter(i=>i.locked),n=e.map(i=>{if(i.locked){let s=i.groupIds.filter(l=>!t.lockedMultiSelections[l]);return pT(i,{locked:!1,groupIds:i.groupIds.length!==s.length?s:i.groupIds})}return i}),r=hb(n),a=o.map(i=>r.get(i.id)||i);return{elements:n,appState:{...t,selectedElementIds:Object.fromEntries(o.map(i=>[i.id,!0])),selectedGroupIds:uT(a,t),lockedMultiSelections:{},activeLockedId:null},captureUpdate:gT.IMMEDIATELY}},label:"labels.elementLock.unlockAll"});import{isElbowArrow as Fz,isLinearElement as Oz,isLineElement as al}from"@orangecatai/element";import{arrayToMap as zz,invariant as I0}from"@orangecatai/common";import{toggleLinePolygonState as Hz,CaptureUpdateAction as O5}from"@orangecatai/element";import p5 from"clsx";import SO from"fuzzy";import{useEffect as qp,useRef as u5,useMemo as MO,useState as jp}from"react";import{DEFAULT_SIDEBAR as c5,EVENT as Qp,KEYS as yn,capitalizeString as PO,isWritableElement as AO}from"@orangecatai/common";import{CaptureUpdateAction as D9}from"@orangecatai/element";import{useEffect as zc,useMemo as fT,useRef as yb,useState as JN}from"react";import{getLinearElementSubType as Ws,updateElbowArrowPoints as QN}from"@orangecatai/element";import{pointFrom as Tp,pointRotateRads as e9}from"@orangecatai/math";import{hasBoundTextElement as t9,isArrowBoundToElement as o9,isArrowElement as n9,isElbowArrow as r9,isLinearElement as Ib,isUsingAdaptiveRadius as a9}from"@orangecatai/element";import{getCommonBoundingBox as i9,getElementAbsoluteCoords as s9}from"@orangecatai/element";import{getBoundTextElement as wT,getBoundTextMaxHeight as l9,getBoundTextMaxWidth as c9,redrawTextBoundingBox as d9}from"@orangecatai/element";import{wrapText as m9}from"@orangecatai/element";import{assertNever as p9,CLASSES as u9,getFontString as fb,isProdEnv as g9,mapFind as h9,reduceToCommonValue as f9,updateActiveTool as bT}from"@orangecatai/common";import{measureText as xT}from"@orangecatai/element";import{LinearElementEditor as b9}from"@orangecatai/element";import{newArrowElement as bb,newElement as x9,newLinearElement as y9}from"@orangecatai/element";import{ShapeCache as E9}from"@orangecatai/element";import{updateBindings as w9}from"@orangecatai/element";import{jsx as vb}from"react/jsx-runtime";var v9=8,I9=10,Fc=["rectangle","diamond","ellipse"],Oc=["line","sharpArrow","curvedArrow","elbowArrow"],T9=new Set(Fc),C9=new Set(Oc),Ys=e=>T9.has(e),kp=e=>e==="arrow"||C9.has(e),bn=Pe(null),Hc=new Map,Gc=new Map,k9=({app:e})=>{let t=e.scene.getSelectedElements(e.state),o=yb(null);return zc(()=>{if(t.length===0){e.updateEditorAtom(bn,null);return}let n=$s(t);n&&!o.current?o.current=n:(o.current&&!n||o.current&&n!==o.current)&&(e.updateEditorAtom(bn,null),o.current=null)},[t,e]),zc(()=>()=>{Hc.clear(),Gc.clear()},[]),vb(S9,{app:e,elements:t})},S9=({app:e,elements:t})=>{let o=$s(t),n=fT(()=>o==="generic"?IT(t):[],[o,t]),r=fT(()=>o==="linear"?wb(t):[],[o,t]),a=o==="generic"?n.every(p=>p.type===n[0].type):o==="linear"?r.every(p=>Ws(p)===Ws(r[0])):!1,[i,s]=JN({x:0,y:0}),l=yb(""),c=yb(null);zc(()=>{let p=[...n,...r].sort((x,E)=>x.id.localeCompare(E.id)),d=`
|
|
7
|
+
${e.state.scrollX}${e.state.scrollY}${e.state.offsetTop}${e.state.offsetLeft}${e.state.zoom.value}${p.map(x=>x.id).join(",")}`;if(d===l.current)return;l.current=d;let u;if(p.length===1){let[x,,,E,y,w]=s9(p[0],e.scene.getNonDeletedElementsMap());u=e9(Tp(x,E),Tp(y,w),p[0].angle)}else{let{minX:x,maxY:E}=i9(p);u=Tp(x,E)}let{x:h,y:g}=CT({sceneX:u[0],sceneY:u[1]},e.state);s({x:h,y:g})},[n,r,e.scene,e.state]),zc(()=>{for(let p of r){let d=Eb(p.id,_9(p));Gc.has(d)||Gc.set(d,p)}},[r]),zc(()=>{for(let p of n)if(!Hc.has(p.id)){let d=wT(p,e.scene.getNonDeletedElementsMap());d&&Hc.set(p.id,{fontSize:d.fontSize})}},[n,e.scene]);let m=o==="linear"?[["line",es],["sharpArrow",ds],["curvedArrow",ps],["elbowArrow",ms]]:o==="generic"?[["rectangle",qi],["diamond",Ji],["ellipse",Qi]]:[];return vb("div",{ref:c,tabIndex:-1,style:{position:"absolute",top:`${i.y+(I9+8)*e.state.zoom.value-e.state.offsetTop}px`,left:`${i.x-e.state.offsetLeft-v9}px`,zIndex:2},className:u9.CONVERT_ELEMENT_TYPE_POPUP,children:m.map(([p,d])=>{let u=a&&(o==="generic"&&n[0].type===p||o==="linear"&&Ws(r[0])===p);return vb(ie,{className:"Shape",type:"radio",icon:d,checked:u,name:"convertElementType-option",title:p,keyBindingLabel:"","aria-label":p,"data-testid":`toolbar-${p}`,onChange:()=>{e.state.activeTool.type!==p&&be("convertElementType",p,"ui"),Tb(e,{conversionType:o,nextType:p}),c.current?.focus()}},`${t[0].id}${t[0].version}_${p}`)})})},M9=(e,t,o)=>{let n=c9(e,t),r=l9(e,t),a=m9(t.text,fb(t),n),i=xT(a,fb(t),t.lineHeight),s=t.fontSize;for(;(i.width>n||i.height>r)&&s>0;){s-=1;let l={...t,fontSize:s};i=xT(t.text,fb(l),t.lineHeight)}Sp(t,o.getNonDeletedElementsMap(),{fontSize:s,width:i.width,height:i.height}),d9(t,e,o)},Tb=(e,{conversionType:t,nextType:o,direction:n="right"})=>{if(!t)return!1;let r=e.scene.getSelectedElements(e.state),a=r.reduce((s,l)=>({...s,[l.id]:!0}),{}),i=n==="right"?1:-1;if(t==="generic"){let s=IT(r),c=s.every(m=>m.type===s[0].type)?Fc.indexOf(s[0].type):-1;if(o=o??Fc[(c+Fc.length+i)%Fc.length],o&&Ys(o)){let m={};for(let d of s){let u=ET(d,o,e);m[u.id]=u}let p=[];for(let d of e.scene.getElementsIncludingDeleted())m[d.id]?p.push(m[d.id]):p.push(d);e.scene.replaceAllElements(p);for(let d of Object.values(m)){let u=wT(d,e.scene.getNonDeletedElementsMap());u&&(Hc.get(d.id)&&Sp(u,e.scene.getNonDeletedElementsMap(),{fontSize:Hc.get(d.id)?.fontSize??u.fontSize}),M9(d,u,e.scene))}e.setState(d=>({selectedElementIds:a,activeTool:bT(d,{type:"selection"})}))}}if(t==="linear"){let s=wb(r);if(!o){let c=f9(s,Ws),m=c?Oc.indexOf(c):-1;o=Oc[(m+Oc.length+i)%Oc.length]}if(kp(o)){let c=[],m=e.scene.getElementsMapIncludingDeleted();for(let p of s){let d=Gc.get(Eb(p.id,o));if(d&&Ws(d)===o)m.set(d.id,d),c.push(d);else{let u=ET(p,o,e);m.set(u.id,u),c.push(u)}}e.scene.replaceAllElements(m);for(let p of c)if(Ib(p))if(r9(p)){let d=P9(p);if(d.length<2)continue;let u=[];for(let g=1;g<d.length-2;g++)u.push({start:d[g],end:d[g+1],index:g+1});let h=QN(p,e.scene.getNonDeletedElementsMap(),{points:d,fixedSegments:u});Sp(p,e.scene.getNonDeletedElementsMap(),{...h,endArrowhead:"arrow"})}else{let d=h9(["line","sharpArrow","curvedArrow"],u=>Gc.get(Eb(p.id,u)));if(d){let u=d.points;e.scene.mutateElement(p,{points:u})}}}let l=wb(e.scene.getSelectedElements(e.state));e.setState(c=>({selectedElementIds:a,selectedLinearElement:l.length===1?new b9(l[0],e.scene.getNonDeletedElementsMap()):null,activeTool:bT(c,{type:"selection"})}))}return!0},$s=e=>{if(e.length===0)return null;let t=!1;for(let o of e){if(Ys(o.type))return"generic";vT(o)&&(t=!0)}return t?"linear":null},vT=e=>Ib(e)&&(!n9(e)||!o9(e)&&!t9(e)),Eb=(e,t)=>`${e}:${t}`,IT=e=>e.filter(t=>Ys(t.type)),wb=e=>e.filter(t=>vT(t)),Ip=20,Gs=(e,t)=>e[0]===t[0],xb=(e,t)=>e[1]===t[1],yT=(e,t)=>Gs(e,t)?Math.abs(e[1]-t[1]):Math.abs(e[0]-t[0]),P9=e=>{let t=[e.points[0]],o=A9(e.points);for(let a=1;a<o.length;++a){let i=t[t.length-1],s=[...o[a]];Math.abs(s[0]-i[0])<Ip?s[0]=i[0]:Math.abs(s[1]-i[1])<Ip&&(s[1]=i[1]),Gs(i,s)||xb(i,s)||t.push(Tp(i[0],s[1])),t.push(s)}let n=[t[0]];for(let a=1;a<t.length-1;++a)Gs(t[a-1],t[a])&&Gs(t[a],t[a+1])||xb(t[a-1],t[a])&&xb(t[a],t[a+1])||n.push(t[a]);n.push(t[t.length-1]);let r=[n[0]];for(let a=1;a<n.length-1;++a){let i=r[r.length-1],s=n[a],l=n[a+1],c=Gs(i,s),m=Gs(s,l);if(c!==m){let p=yT(i,s),d=yT(s,l);if(p<Ip||d<Ip){if(d<p)c?l[0]=i[0]:l[1]=i[1];else if(m)for(let u=r.length-1;u>=0&&r[u][0]===i[0];--u)r[u][0]=s[0];else for(let u=r.length-1;u>=0&&r[u][1]===i[1];--u)r[u][1]=s[1];continue}}r.push(s)}return r.push(n[n.length-1]),r},A9=e=>{if(e.length===0)return[];let t=[e[0]];for(let o=1;o<e.length;o++){let[n,r]=t[t.length-1],[a,i]=e[o];(n!==a||r!==i)&&t.push(e[o])}return t},ET=(e,t,o)=>{if(!L9(e.type,t)){if(!g9())throw Error(`Invalid conversion from ${e.type} to ${t}.`);return e}if(e.type===t)return e;if(E9.delete(e),Ys(t)){let n=Us(x9({...e,type:t,roundness:t==="diamond"&&e.roundness?{type:a9(t)?Cp.ADAPTIVE_RADIUS:Cp.PROPORTIONAL_RADIUS}:e.roundness}));return w9(n,o.scene,o.state),n}if(kp(t))switch(t){case"line":return Us(y9({...e,type:"line"}));case"sharpArrow":return Us(bb({...e,type:"arrow",elbowed:!1,roundness:null,startArrowhead:o.state.currentItemStartArrowhead,endArrowhead:o.state.currentItemEndArrowhead}));case"curvedArrow":return Us(bb({...e,type:"arrow",elbowed:!1,roundness:{type:Cp.PROPORTIONAL_RADIUS},startArrowhead:o.state.currentItemStartArrowhead,endArrowhead:o.state.currentItemEndArrowhead}));case"elbowArrow":return Us(bb({...e,type:"arrow",elbowed:!0,fixedSegments:null,roundness:null}))}return p9(t,`unhandled conversion type: ${t}`),e},L9=(e,t)=>!!(Ys(e)&&Ys(t)||kp(e)&&kp(t)),_9=e=>Ib(e)?Ws(e):e.type,TT=k9;var kT=W({name:"toggleShapeSwitch",label:"labels.shapeSwitch",icon:()=>null,viewMode:!0,trackEvent:{category:"shape_switch",action:"toggle"},keywords:["change","switch","swap"],perform(e,t,o,n){return Et.set(bn,{type:"panel"}),{captureUpdate:D9.NEVER}},checked:e=>e.gridModeEnabled,predicate:(e,t,o)=>$s(e)!==null});import{canCreateLinkFromElements as Cb,defaultGetElementLinkFromSelection as R9,getLinkIdAndTypeFromSelection as N9}from"@orangecatai/element";import{CaptureUpdateAction as Uc}from"@orangecatai/element";var Mp=W({name:"copyElementLink",label:"labels.copyElementLink",icon:is,trackEvent:{category:"element"},perform:async(e,t,o,n)=>{let r=de(e,t);try{if(window.location){let a=N9(r,t);return a?(await hn(n.props.generateLinkForSelection?n.props.generateLinkForSelection(a.id,a.type):R9(a.id,a.type)),{appState:{toast:{message:f("toast.elementLinkCopied"),closable:!0}},captureUpdate:Uc.EVENTUALLY}):{appState:t,elements:e,app:n,captureUpdate:Uc.EVENTUALLY}}}catch(a){console.error(a)}return{appState:t,elements:e,app:n,captureUpdate:Uc.EVENTUALLY}},predicate:(e,t)=>Cb(de(e,t))}),ST=W({name:"linkToElement",label:"labels.linkToElement",icon:Cm,perform:(e,t,o,n)=>{let r=de(e,t);return r.length!==1||!Cb(r)?{elements:e,appState:t,app:n,captureUpdate:Uc.EVENTUALLY}:{appState:{...t,openDialog:{name:"elementLinkSelector",sourceElementId:de(e,t)[0].id}},captureUpdate:Uc.IMMEDIATELY}},predicate:(e,t,o,n)=>{let r=de(e,t);return t.openDialog?.name!=="elementLinkSelector"&&r.length===1&&Cb(r)},trackEvent:!1});import{isDarwin as MT}from"@orangecatai/common";var B9={toggleTheme:[G("Shift+Alt+D")],saveScene:[G("CtrlOrCmd+S")],loadScene:[G("CtrlOrCmd+O")],clearCanvas:[G("CtrlOrCmd+Delete")],imageExport:[G("CtrlOrCmd+Shift+E")],commandPalette:[G("CtrlOrCmd+/"),G("CtrlOrCmd+Shift+P")],cut:[G("CtrlOrCmd+X")],copy:[G("CtrlOrCmd+C")],paste:[G("CtrlOrCmd+V")],copyStyles:[G("CtrlOrCmd+Alt+C")],pasteStyles:[G("CtrlOrCmd+Alt+V")],selectAll:[G("CtrlOrCmd+A")],deleteSelectedElements:[G("Delete")],duplicateSelection:[G("CtrlOrCmd+D"),G(`Alt+${f("helpDialog.drag")}`)],sendBackward:[G("CtrlOrCmd+[")],bringForward:[G("CtrlOrCmd+]")],sendToBack:[MT?G("CtrlOrCmd+Alt+["):G("CtrlOrCmd+Shift+[")],bringToFront:[MT?G("CtrlOrCmd+Alt+]"):G("CtrlOrCmd+Shift+]")],copyAsPng:[G("Shift+Alt+C")],group:[G("CtrlOrCmd+G")],ungroup:[G("CtrlOrCmd+Shift+G")],gridMode:[G("CtrlOrCmd+'")],zenMode:[G("Alt+Z")],objectsSnapMode:[G("Alt+S")],stats:[G("Alt+/")],addToLibrary:[],flipHorizontal:[G("Shift+H")],flipVertical:[G("Shift+V")],viewMode:[G("Alt+R")],hyperlink:[G("CtrlOrCmd+K")],toggleElementLock:[G("CtrlOrCmd+Shift+L")],resetZoom:[G("CtrlOrCmd+0")],zoomOut:[G("CtrlOrCmd+-")],zoomIn:[G("CtrlOrCmd++")],zoomToFitSelection:[G("Shift+3")],zoomToFit:[G("Shift+1")],zoomToFitSelectionInViewport:[G("Shift+2")],toggleEraserTool:[G("E")],toggleHandTool:[G("H")],setFrameAsActiveTool:[G("F")],saveFileToDisk:[G("CtrlOrCmd+S")],saveToActiveFile:[G("CtrlOrCmd+S")],toggleShortcuts:[G("?")],searchMenu:[G("CtrlOrCmd+F")],wrapSelectionInFrame:[],toolLock:[G("Q")]},Xe=(e,t=0)=>{let o=B9[e];return o&&o.length>0?o[t]||o[0]:""};var F9="\\u0300-\\u036f",O9="\\ufe20-\\ufe2f",z9="\\u20d0-\\u20ff",H9=F9+O9+z9,G9=`[${H9}]`,U9=RegExp(G9,"g"),W9=/[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g,Y9={\u00C0:"A",\u00C1:"A",\u00C2:"A",\u00C3:"A",\u00C4:"A",\u00C5:"A",\u00E0:"a",\u00E1:"a",\u00E2:"a",\u00E3:"a",\u00E4:"a",\u00E5:"a",\u00C7:"C",\u00E7:"c",\u00D0:"D",\u00F0:"d",\u00C8:"E",\u00C9:"E",\u00CA:"E",\u00CB:"E",\u00E8:"e",\u00E9:"e",\u00EA:"e",\u00EB:"e",\u00CC:"I",\u00CD:"I",\u00CE:"I",\u00CF:"I",\u00EC:"i",\u00ED:"i",\u00EE:"i",\u00EF:"i",\u00D1:"N",\u00F1:"n",\u00D2:"O",\u00D3:"O",\u00D4:"O",\u00D5:"O",\u00D6:"O",\u00D8:"O",\u00F2:"o",\u00F3:"o",\u00F4:"o",\u00F5:"o",\u00F6:"o",\u00F8:"o",\u00D9:"U",\u00DA:"U",\u00DB:"U",\u00DC:"U",\u00F9:"u",\u00FA:"u",\u00FB:"u",\u00FC:"u",\u00DD:"Y",\u00FD:"y",\u00FF:"y",\u00C6:"E",\u00E6:"e",\u00DE:"T",\u00FE:"t",\u00DF:"s",\u0100:"A",\u0102:"A",\u0104:"A",\u0101:"a",\u0103:"a",\u0105:"a",\u0106:"C",\u0108:"C",\u010A:"C",\u010C:"C",\u0107:"c",\u0109:"c",\u010B:"c",\u010D:"c",\u010E:"D",\u0110:"D",\u010F:"d",\u0111:"d",\u0112:"E",\u0114:"E",\u0116:"E",\u0118:"E",\u011A:"E",\u0113:"e",\u0115:"e",\u0117:"e",\u0119:"e",\u011B:"e",\u011C:"G",\u011E:"G",\u0120:"G",\u0122:"G",\u011D:"g",\u011F:"g",\u0121:"g",\u0123:"g",\u0124:"H",\u0126:"H",\u0125:"h",\u0127:"h",\u0128:"I",\u012A:"I",\u012C:"I",\u012E:"I",\u0130:"I",\u0129:"i",\u012B:"i",\u012D:"i",\u012F:"i",\u0131:"i",\u0134:"J",\u0135:"j",\u0136:"K",\u0137:"k",\u0138:"k",\u0139:"L",\u013B:"L",\u013D:"L",\u013F:"L",\u0141:"L",\u013A:"l",\u013C:"l",\u013E:"l",\u0140:"l",\u0142:"l",\u0143:"N",\u0145:"N",\u0147:"N",\u014A:"N",\u0144:"n",\u0146:"n",\u0148:"n",\u014B:"n",\u014C:"O",\u014E:"O",\u0150:"O",\u014D:"o",\u014F:"o",\u0151:"o",\u0154:"R",\u0156:"R",\u0158:"R",\u0155:"r",\u0157:"r",\u0159:"r",\u015A:"S",\u015C:"S",\u015E:"S",\u0160:"S",\u015B:"s",\u015D:"s",\u015F:"s",\u0161:"s",\u0162:"T",\u0164:"T",\u0166:"T",\u0163:"t",\u0165:"t",\u0167:"t",\u0168:"U",\u016A:"U",\u016C:"U",\u016E:"U",\u0170:"U",\u0172:"U",\u0169:"u",\u016B:"u",\u016D:"u",\u016F:"u",\u0171:"u",\u0173:"u",\u0174:"W",\u0175:"w",\u0176:"Y",\u0177:"y",\u0178:"Y",\u0179:"Z",\u017B:"Z",\u017D:"Z",\u017A:"z",\u017C:"z",\u017E:"z",\u0132:"I",\u0133:"i",\u0152:"E",\u0153:"e",\u0149:"n",\u017F:"s"},ri=e=>e.replace(W9,t=>Y9[t]||t).replace(U9,"");import aO from"clsx";import{useEffect as iO,useState as sO}from"react";import{KEYS as lO,queryFocusableElements as OC}from"@orangecatai/common";import{useCallback as $9,useState as V9}from"react";var PT=()=>{let[e,t]=V9(null),o=$9(n=>t(n),[]);return[e,o]};import{useState as _C,useCallback as Kb,useMemo as DC,useEffect as Xb,memo as RC,useRef as YF}from"react";import{LIBRARY_DISABLED_TYPES as $F,randomId as VF,isShallowEqual as KF,KEYS as XF,isWritableElement as ZF,addEventListener as jF,EVENT as qF,CLASSES as PC}from"@orangecatai/common";import{useEffect as DT,useRef as RT}from"react";import{URL_HASH_KEYS as Mb,URL_QUERY_KEYS as Pb,APP_NAME as NT,EVENT as Ap,DEFAULT_SIDEBAR as j9,LIBRARY_SIDEBAR_TAB as q9,arrayToMap as Ab,cloneJSON as J9,preventUnload as Q9,promiseTry as BT,resolvablePromise as eB,toValidURL as tB,Queue as oB,Emitter as nB}from"@orangecatai/common";import{hashElementsVersion as rB,hashString as aB}from"@orangecatai/element";import{getCommonBoundingBox as Sb}from"@orangecatai/element";import{MIME_TYPES as ai}from"@orangecatai/common";var na=({elements:e,appState:t,files:o,maxWidthOrHeight:n,getDimensions:r,exportPadding:a,exportingFrame:i})=>{let s=Ga(e,null,{deleteInvisibleElements:!0}),l=$i(t,null),{exportBackground:c,viewBackgroundColor:m}=l;return zr(s,{...l,offsetTop:0,offsetLeft:0,width:0,height:0},o||{},{exportBackground:c,exportPadding:a,viewBackgroundColor:m,exportingFrame:i},(p,d)=>{let u=document.createElement("canvas");if(n){typeof r=="function"&&console.warn("`getDimensions()` is ignored when `maxWidthOrHeight` is supplied.");let g=Math.max(p,d),x=n<g?n/g:t?.exportScale??1;return u.width=p*x,u.height=d*x,{canvas:u,scale:x}}let h=r?.(p,d)||{width:p,height:d};return u.width=h.width,u.height=h.height,{canvas:u,scale:h.scale??1}})},AT=async e=>{let{mimeType:t=ai.png,quality:o}=e;t===ai.png&&typeof o=="number"&&console.warn(`"quality" will be ignored for "${ai.png}" mimeType`),t==="image/jpg"&&(t=ai.jpg),t===ai.jpg&&!e.appState?.exportBackground&&(console.warn(`Defaulting "exportBackground" to "true" for "${ai.jpg}" mimeType`),e={...e,appState:{...e.appState,exportBackground:!0}});let n=await na(e);return o=o||(/image\/jpe?g/.test(t)?.92:.8),new Promise((r,a)=>{n.toBlob(async i=>{if(!i)return a(new Error("couldn't export to blob"));i&&t===ai.png&&e.appState?.exportEmbedScene&&(i=await pE({blob:i,metadata:jl(e.elements,e.appState,e.files||{},"local")})),r(i)},t,o)})},Vs=async({elements:e,appState:t=Or(),files:o={},exportPadding:n,renderEmbeddables:r,exportingFrame:a,skipInliningFonts:i,reuseImages:s})=>{let l=Ga(e,null,{deleteInvisibleElements:!0}),m={...$i(t,null),exportPadding:n};return Yi(l,m,o,{exportingFrame:a,renderEmbeddables:r,skipInliningFonts:i,reuseImages:s})},K9=async e=>{if(e.type==="svg"){let t=await Vs(e);await hn(t.outerHTML)}else if(e.type==="png")await lp(AT(e));else if(e.type==="json")await ip(e.elements,e.files);else throw new Error("Invalid export type")};import{useEffect as LT,useState as X9}from"react";import{COLOR_PALETTE as Z9}from"@orangecatai/common";var kb=Pe(new Map),_T=async e=>await Vs({elements:e,appState:{exportBackground:!1,viewBackgroundColor:Z9.white},files:null,renderEmbeddables:!1,skipInliningFonts:!0}),Pp=(e,t,o,n)=>{let[r,a]=X9();return LT(()=>{if(t)if(e){let i=o.get(e);i?a(i):(async()=>{let s=await _T(t);s.querySelector(".style-fonts")?.remove(),s&&(o.set(e,s),a(s))})()}else(async()=>{let i=await _T(t);a(i)})()},[e,t,o,a]),LT(()=>{let i=n.current;if(i)return r&&(i.innerHTML=r.outerHTML),()=>{i.innerHTML=""}},[r,n]),r},Ks=()=>{let[e]=le(kb);return{clearLibraryCache:()=>e.clear(),deleteItemsFromLibraryCache:n=>{n.forEach(r=>e.delete(r))},svgCache:e}};var iB=["excalidraw.com","raw.githubusercontent.com/excalidraw/excalidraw-libraries"],OT=new nB,wr=Pe({status:"loaded",isInitialized:!1,libraryItems:[]}),Wc=e=>J9(e),sB=(e,t)=>!e.find(o=>o.elements.length!==t.elements.length?!1:o.elements.every((n,r)=>n.id===t.elements[r].id&&n.versionNonce===t.elements[r].versionNonce)),zT=(e,t)=>{let o=[];for(let n of t)sB(e,n)&&o.push(n);return[...o,...e]},HT=(e,t)=>{let o=Ab(t),n={deletedItems:new Map,addedItems:new Map,updatedItems:new Map};for(let a of e)o.has(a.id)||n.deletedItems.set(a.id,a);let r=Ab(e);for(let a of t){let i=r.get(a.id);i?Db(i)!==Db(a)&&n.updatedItems.set(a.id,a):n.addedItems.set(a.id,a)}return n},Lb=class{constructor(t){A(this,"currLibraryItems",[]);A(this,"prevLibraryItems",Wc(this.currLibraryItems));A(this,"app");A(this,"updateQueue",[]);A(this,"getLastUpdateTask",()=>this.updateQueue[this.updateQueue.length-1]);A(this,"notifyListeners",()=>{if(this.updateQueue.length>0)Et.set(wr,t=>({status:"loading",libraryItems:this.currLibraryItems,isInitialized:t.isInitialized}));else{Et.set(wr,{status:"loaded",libraryItems:this.currLibraryItems,isInitialized:!0});try{let t=this.prevLibraryItems;this.prevLibraryItems=Wc(this.currLibraryItems);let o=Wc(this.currLibraryItems);this.app.props.onLibraryChange?.(o),OT.trigger(HT(t,o),o)}catch(t){console.error(t)}}});A(this,"destroy",()=>{this.updateQueue=[],this.currLibraryItems=[],Et.set(kb,new Map)});A(this,"resetLibrary",()=>this.setLibrary([]));A(this,"getLatestLibrary",()=>new Promise(async t=>{try{let o=await(this.getLastUpdateTask()||this.currLibraryItems);this.updateQueue.length>0?t(this.getLatestLibrary()):t(Wc(o))}catch{return t(this.currLibraryItems)}}));A(this,"updateLibrary",async({libraryItems:t,prompt:o=!1,merge:n=!1,openLibraryMenu:r=!1,defaultStatus:a="unpublished"})=>(r&&this.app.setState({openSidebar:{name:j9.name,tab:q9}}),this.setLibrary(()=>new Promise(async(i,s)=>{try{let l=await(typeof t=="function"&&!(t instanceof Blob)?t(this.currLibraryItems):t),c;l instanceof Blob?c=await ph(l,a):c=Ql(l,a),!o||window.confirm(f("alerts.confirmAddLibrary",{numShapes:c.length}))?(o&&this.app.focusContainer(),i(n?zT(this.currLibraryItems,c):c)):s(new Ui)}catch(l){s(l)}}))));A(this,"setLibrary",t=>{let o=new Promise(async(n,r)=>{try{await this.getLastUpdateTask(),typeof t=="function"&&(t=t(this.currLibraryItems)),this.currLibraryItems=Wc(await t),n(this.currLibraryItems)}catch(a){r(a)}}).catch(n=>{if(n.name==="AbortError")return console.warn("Library update aborted by user"),this.currLibraryItems;throw n}).finally(()=>{this.updateQueue=this.updateQueue.filter(n=>n!==o),this.notifyListeners()});return this.updateQueue.push(o),this.notifyListeners(),o});this.app=t}},GT=Lb,Zs=e=>{let o=Math.ceil(Math.sqrt(e.length)),n=[],r=u=>e.slice(u*o,u*o+o).reduce((g,x)=>{let{height:E}=Sb(x.elements);return Math.max(g,E)},0),a=u=>{let h=0,g=0,x=0;for(let E of e){if(h%o===0&&(g=0),g===u){let{width:y}=Sb(E.elements);x=Math.max(x,y)}h++,g++}return x},i=0,s=0,l=0,c=0,m=0,p=0,d=0;for(let u of e){m&&m%o===0&&(s+=l+50,i=0,p=0,d++),p===0&&(l=r(d)),c=a(p);let{minX:h,minY:g,width:x,height:E}=Sb(u.elements),y=(c-x)/2,w=(l-E)/2;n.push(...u.elements.map(v=>({...v,x:v.x+i+y-h,y:v.y+s+w-g}))),i+=c+50,m++,p++}return n},lB=(e,t=iB)=>{if(typeof t=="function"?t(e):t.some(o=>{let n=new URL(`https://${o.replace(/^https?:\/\//,"")}`),{hostname:r,pathname:a}=new URL(e);return new RegExp(`(^|\\.)${n.hostname}$`).test(r)&&new RegExp(`^${n.pathname.replace(/\/+$/,"")}(/+|$)`).test(a)}))return!0;throw new Error(`Invalid or disallowed library URL: "${e}"`)},_b=()=>{let e=new URLSearchParams(window.location.hash.slice(1)).get(Mb.addLibrary)||new URLSearchParams(window.location.search).get(Pb.addLibrary),t=e?new URLSearchParams(window.location.hash.slice(1)).get("token"):null;return e?{libraryUrl:e,idToken:t}:null},ra=class ra{constructor(t){A(this,"adapter");this.adapter=t}static async getLibraryItems(t,o,n=!0){let r=()=>new Promise(async(a,i)=>{try{let s=await t.load({source:o});a(Ql(s?.libraryItems||[],"published"))}catch(s){i(s)}});return n?ra.queue.push(r):r()}getLibraryItems(t){return ra.getLibraryItems(this.adapter,t,!1)}};A(ra,"queue",new oB),A(ra,"run",async(t,o)=>{let n=new ra(t);return ra.queue.push(()=>o(n))});var Xs=ra,Yc=0,Lp=0,Db=e=>`${e.id}:${e.name||""}:${rB(e.elements)}`,_p=e=>aB(e.map(t=>Db(t)).sort().join()),FT=async(e,t)=>{try{return Lp++,await Xs.run(e,async o=>{let n=Ab(await o.getLibraryItems("save"));for(let[s]of t.deletedItems)n.delete(s);let r=[];for(let[s,l]of t.addedItems)n.has(s)?n.set(s,l):r.push(l);if(t.updatedItems)for(let[s,l]of t.updatedItems)n.set(s,l);let a=r.concat(Array.from(n.values())),i=_p(a);return i!==Yc&&await e.save({libraryItems:a}),Yc=i,a})}finally{Lp--}},cB=e=>{let{excalidrawAPI:t}=e,o=RT(e);o.current=e;let n=RT(!1);DT(()=>{if(!t)return;n.current=!1;let r=async({libraryUrl:s,idToken:l})=>{let c=new Promise(async(p,d)=>{try{s=decodeURIComponent(s),s=tB(s),lB(s,o.current.validateLibraryUrl);let h=await(await fetch(s)).blob();p(h)}catch(u){d(u)}}),m=l!==t.id;await(m&&document.hidden?new Promise(p=>{window.addEventListener("focus",()=>p(),{once:!0})}):null);try{await t.updateLibrary({libraryItems:c,prompt:m,merge:!0,defaultStatus:"published",openLibraryMenu:!0})}catch(p){throw t.updateScene({appState:{errorMessage:p.message}}),p}finally{if(window.location.hash.includes(Mb.addLibrary)){let p=new URLSearchParams(window.location.hash.slice(1));p.delete(Mb.addLibrary),window.history.replaceState({},NT,`#${p.toString()}`)}else if(window.location.search.includes(Pb.addLibrary)){let p=new URLSearchParams(window.location.search);p.delete(Pb.addLibrary),window.history.replaceState({},NT,`?${p.toString()}`)}}},a=s=>{s.preventDefault();let l=_b();l&&(s.stopImmediatePropagation(),window.history.replaceState({},"",s.oldURL),r(l))},i=_b();if(i&&r(i),"getInitialLibraryItems"in o.current&&o.current.getInitialLibraryItems&&(console.warn("useHandleLibrar `opts.getInitialLibraryItems` is deprecated. Use `opts.adapter` instead."),Promise.resolve(o.current.getInitialLibraryItems()).then(s=>{t.updateLibrary({libraryItems:s,merge:!0})}).catch(s=>{console.error(`UseHandeLibrary getInitialLibraryItems failed: ${s?.message}`)})),"adapter"in o.current&&o.current.adapter){let s=o.current.adapter,l=o.current.migrationAdapter,c=eB();l?c.resolve(BT(l.load).then(async m=>{let p=null;try{if(!m)return Xs.getLibraryItems(s,"load");p=Ql(m.libraryItems||[],"published");let d=await FT(s,HT([],p));try{await l.clear()}catch(u){console.error(`couldn't delete legacy library data: ${u.message}`)}return d}catch(d){return console.error(`couldn't migrate legacy library data: ${d.message}`),p}}).catch(m=>(console.error(`error during library migration: ${m.message}`),Xs.getLibraryItems(s,"load")))):c.resolve(BT(Xs.getLibraryItems,s,"load")),t.updateLibrary({libraryItems:c.then(m=>{let p=m||[];return Yc=_p(p),p}),merge:!0}).finally(()=>{n.current=!0})}return window.addEventListener(Ap.HASHCHANGE,a),()=>{window.removeEventListener(Ap.HASHCHANGE,a)}},[t]),DT(()=>{let r=OT.on(async(i,s)=>{let l=n.current,c="adapter"in o.current&&o.current.adapter||null;try{c&&Yc!==_p(s)&&await FT(c,i)}catch(m){console.error(`couldn't persist library update: ${m.message}`,i),l&&o.current.excalidrawAPI&&o.current.excalidrawAPI.updateScene({appState:{errorMessage:f("errors.saveLibraryError")}})}}),a=i=>{Lp&&Q9(i)};return window.addEventListener(Ap.BEFORE_UNLOAD,a),()=>{window.removeEventListener(Ap.BEFORE_UNLOAD,a),r(),Yc=0,Lp=0}},[])};import uB from"clsx";import{VERSIONS as dB}from"@orangecatai/common";import{jsx as pB}from"react/jsx-runtime";var mB=({theme:e,id:t,libraryReturnUrl:o})=>{let n=o||window.location.origin+window.location.pathname;return pB("a",{className:"library-menu-browse-button",href:`${T.VITE_APP_LIBRARY_URL}?target=${window.name||"_blank"}&referrer=${n}&useHash=true&token=${t}&theme=${e}&version=${dB.excalidrawLibrary}`,target:"_excalidraw_libraries",children:f("labels.libraries")})},UT=mB;import{jsx as gB,jsxs as hB}from"react/jsx-runtime";var Dp=({libraryReturnUrl:e,theme:t,id:o,style:n,children:r,className:a})=>hB("div",{className:uB("library-menu-control-buttons",a),style:n,children:[gB(UT,{id:o,libraryReturnUrl:e,theme:t}),r]});import{useCallback as Js,useEffect as Wb,useMemo as Yb,useRef as kC,useState as SC}from"react";import{MIME_TYPES as FF,arrayToMap as OF,nextAnimationFrame as zF}from"@orangecatai/common";import{duplicateElements as HF}from"@orangecatai/element";import GF from"clsx";import fB from"lodash.throttle";import{useEffect as bB}from"react";var xB=Pe(0),WT=e=>{let[t,o]=le(xB);return bB(()=>{let{current:n}=e;if(!n)return;let r=fB(()=>{let{scrollTop:a}=n;o(a)},200);return n.addEventListener("scroll",r),()=>{r.cancel(),n.removeEventListener("scroll",r)}},[e,o]),t};import uF from"clsx";import{useCallback as gF,useState as Hb}from"react";import{muteFSAbortError as hF}from"@orangecatai/common";import{flushSync as YT}from"react-dom";import yB from"clsx";import{jsx as Rp,jsxs as wB}from"react/jsx-runtime";var EB=({label:e,onClick:t,className:o,children:n,actionType:r,type:a="button",isLoading:i,...s})=>{let l=r?`Dialog__action-button--${r}`:"";return wB("button",{className:yB("Dialog__action-button",l,o),type:a,"aria-label":e,onClick:t,...s,children:[n&&Rp("div",{style:i?{visibility:"hidden"}:{},children:n}),Rp("div",{style:i?{visibility:"hidden"}:{},children:e}),i&&Rp("div",{style:{position:"absolute",inset:0},children:Rp(Wt,{})})]})},vr=EB;import{jsx as $T,jsxs as VT}from"react/jsx-runtime";var vB=e=>{let{onConfirm:t,onCancel:o,children:n,confirmText:r=f("buttons.confirm"),cancelText:a=f("buttons.cancel"),className:i="",...s}=e,l=Ce(),c=Rn(js),{container:m}=Qe();return VT(bt,{onCloseRequest:o,size:"small",...s,className:`confirm-dialog ${i}`,children:[n,VT("div",{className:"confirm-dialog-buttons",children:[$T(vr,{label:a,onClick:()=>{l({openMenu:null}),c(!1),YT(()=>{o()}),m?.focus()}}),$T(vr,{label:r,onClick:()=>{l({openMenu:null}),c(!1),YT(()=>{t()}),m?.focus()},actionType:"danger"})]})]})},Np=vB;import{useCallback as PB,useEffect as Bb,useRef as KT,useState as Rb}from"react";import{EDITOR_LS_KEYS as Nb,EXPORT_DATA_TYPES as AB,MIME_TYPES as XT,VERSIONS as LB,chunk as _B,getExportSource as DB}from"@orangecatai/common";var Xo=class{static has(t){try{return!!window.localStorage.getItem(t)}catch(o){return console.warn(`localStorage.getItem error: ${o.message}`),!1}}static get(t){try{let o=window.localStorage.getItem(t);return o?JSON.parse(o):null}catch(o){return console.warn(`localStorage.getItem error: ${o.message}`),null}}};A(Xo,"set",(t,o)=>{try{return window.localStorage.setItem(t,JSON.stringify(o)),!0}catch(n){return console.warn(`localStorage.setItem error: ${n.message}`),!1}}),A(Xo,"delete",t=>{try{window.localStorage.removeItem(t)}catch(o){console.warn(`localStorage.removeItem error: ${o.message}`)}});import Bp from"react";var IB=/({{[\w-]+}})|(<[\w-]+>)|(<\/[\w-]+>)/g,TB=/{{([\w-]+)}}/,CB=/<([\w-]+)>/,kB=/<\/([\w-]+)>/,SB=(e,t)=>{let o=[{name:"",children:[]}];return e.split(IB).filter(Boolean).forEach(n=>{let r=n.match(CB),a=n.match(kB),i=n.match(TB);if(r!==null){let s=r[1];t.hasOwnProperty(s)?o.push({name:s,children:[]}):console.warn(`Trans: missed to pass in prop ${s} for interpolating ${e}`)}else if(a!==null)if(a[1]===o[o.length-1].name){let l=o.pop(),c=Bp.createElement(Bp.Fragment,{},...l.children),m=t[l.name];typeof m=="function"&&o[o.length-1].children.push(m(c))}else console.warn(`Trans: unexpected end tag ${n} for interpolating ${e}`);else if(i!==null){let s=i[1];t.hasOwnProperty(s)?o[o.length-1].children.push(t[s]):console.warn(`Trans: key ${s} not in props for interpolating ${e}`)}else o[o.length-1].children.push(n)}),o.length!==1&&console.warn(`Trans: stack not empty for interpolating ${e}`),o[0].children},MB=({i18nKey:e,children:t,...o})=>{let{t:n}=Ue();return Bp.createElement(Bp.Fragment,{},...SB(n(e),o))},io=MB;import{jsx as Ae,jsxs as Zt}from"react/jsx-runtime";var RB=async e=>{let n=Math.round(8),r=Math.max(Math.round(128/64),2),a=_B(e,6),i=document.createElement("canvas");i.width=a[0].length*128+(a[0].length+1)*(n*2)-n*2,i.height=a.length*128+(a.length+1)*(n*2)-n*2;let s=i.getContext("2d");s.fillStyle="#fff",s.fillRect(0,0,i.width,i.height);for(let[l,c]of e.entries()){let m=await na({elements:c.elements,files:null,maxWidthOrHeight:128}),{width:p,height:d}=m,u=Math.floor(l/6)*(128+n*2),h=l%6*(128+n*2);s.drawImage(m,h+(128-p)/2+n,u+(128-d)/2+n),s.lineWidth=r,s.strokeStyle="#ced4da",s.strokeRect(h+n/2,u+n/2,128+n,128+n)}return await cm(new File([await Ua(i)],"preview",{type:XT.png}),{outputType:XT.jpg,maxWidthOrHeight:5e3})},NB=({libItem:e,appState:t,index:o,onChange:n,onRemove:r})=>{let a=KT(null),i=KT(null);return Bb(()=>{let s=a.current;s&&(async()=>{let l=await Vs({elements:e.elements,appState:{...t,viewBackgroundColor:"#fff",exportBackground:!0},files:null,skipInliningFonts:!0});s.innerHTML=l.outerHTML})()},[e.elements,t]),Zt("div",{className:"single-library-item",children:[e.status==="published"&&Ae("span",{className:"single-library-item-status",children:f("labels.statusPublished")}),Ae("div",{ref:a,className:"single-library-item__svg"}),Ae(ie,{"aria-label":f("buttons.remove"),type:"button",icon:Go,className:"single-library-item--remove",onClick:r.bind(null,e.id),title:f("buttons.remove")}),Zt("div",{style:{display:"flex",margin:"0.8rem 0",width:"100%",fontSize:"14px",fontWeight:500,flexDirection:"column"},children:[Zt("label",{style:{display:"flex",justifyContent:"space-between",flexDirection:"column"},children:[Zt("div",{style:{padding:"0.5em 0"},children:[Ae("span",{style:{fontWeight:500,color:"#868e96"},children:f("publishDialog.itemName")}),Ae("span",{"aria-hidden":"true",className:"required",children:"*"})]}),Ae("input",{type:"text",ref:i,style:{width:"80%",padding:"0.2rem"},defaultValue:e.name,placeholder:"Item name",onChange:s=>{n(s.target.value,o)}})]}),Ae("span",{className:"error",children:e.error})]})]})},BB=({onClose:e,libraryItems:t,appState:o,onSuccess:n,onError:r,updateItemsInStorage:a,onRemove:i})=>{let[s,l]=Rb({authorName:"",githubHandle:"",name:"",description:"",twitterHandle:"",website:""}),[c,m]=Rb(!1);Bb(()=>{let w=Xo.get(Nb.PUBLISH_LIBRARY);w&&l(w)},[]);let[p,d]=Rb(t.slice());Bb(()=>{d(t.slice())},[t]);let u=w=>{l({...s,[w.target.name]:w.target.value})},h=async w=>{w.preventDefault(),m(!0);let v=[],I=!1;if(p.forEach(k=>{let M="";k.name||(M=f("publishDialog.errors.required"),I=!0),v.push({...k,error:M})}),I){d(v),m(!1);return}let C=await RB(p),P={type:AB.excalidrawLibrary,version:LB.excalidrawLibrary,source:DB(),libraryItems:p},S=JSON.stringify(P,null,2),D=new Blob([S],{type:"application/json"}),_=new FormData;_.append("excalidrawLib",D),_.append("previewImage",C),_.append("previewImageType",C.type),_.append("title",s.name),_.append("authorName",s.authorName),_.append("githubHandle",s.githubHandle),_.append("name",s.name),_.append("description",s.description),_.append("twitterHandle",s.twitterHandle),_.append("website",s.website),fetch(`${T.VITE_APP_LIBRARY_BACKEND}/submit`,{method:"post",body:_}).then(k=>k.ok?k.json().then(({url:M})=>{Xo.delete(Nb.PUBLISH_LIBRARY),n({url:M,authorName:s.authorName,items:p})}):k.json().catch(()=>{throw new Error(k.statusText||"something went wrong")}).then(M=>{throw new Error(M.message||k.statusText||"something went wrong")}),k=>{console.error(k),r(k),m(!1)}).catch(k=>{console.error(k),r(k),m(!1)})},g=()=>{let w=[];return p.forEach((v,I)=>{w.push(Ae("div",{className:"single-library-item-wrapper",children:Ae(NB,{libItem:v,appState:o,index:I,onChange:(C,P)=>{let S=p.slice();S[P].name=C,d(S)},onRemove:i})},I))}),Ae("div",{className:"selected-library-items",children:w})},x=PB(()=>{a(p),Xo.set(Nb.PUBLISH_LIBRARY,s),e()},[p,e,a,s]),E=!!t.length,y=t.some(w=>w.status==="published");return Ae(bt,{onCloseRequest:x,title:f("publishDialog.title"),className:"publish-library",children:E?Zt("form",{onSubmit:h,children:[Ae("div",{className:"publish-library-note",children:Ae(io,{i18nKey:"publishDialog.noteDescription",link:w=>Ae("a",{href:"https://libraries.excalidraw.com",target:"_blank",rel:"noopener",children:w})})}),Ae("span",{className:"publish-library-note",children:Ae(io,{i18nKey:"publishDialog.noteGuidelines",link:w=>Ae("a",{href:"https://github.com/excalidraw/excalidraw-libraries#guidelines",target:"_blank",rel:"noopener noreferrer",children:w})})}),Ae("div",{className:"publish-library-note",children:f("publishDialog.noteItems")}),y&&Ae("span",{className:"publish-library-note publish-library-warning",children:f("publishDialog.republishWarning")}),g(),Zt("div",{className:"publish-library__fields",children:[Zt("label",{children:[Zt("div",{children:[Ae("span",{children:f("publishDialog.libraryName")}),Ae("span",{"aria-hidden":"true",className:"required",children:"*"})]}),Ae("input",{type:"text",name:"name",required:!0,value:s.name,onChange:u,placeholder:f("publishDialog.placeholder.libraryName")})]}),Zt("label",{style:{alignItems:"flex-start"},children:[Zt("div",{children:[Ae("span",{children:f("publishDialog.libraryDesc")}),Ae("span",{"aria-hidden":"true",className:"required",children:"*"})]}),Ae("textarea",{name:"description",rows:4,required:!0,value:s.description,onChange:u,placeholder:f("publishDialog.placeholder.libraryDesc")})]}),Zt("label",{children:[Zt("div",{children:[Ae("span",{children:f("publishDialog.authorName")}),Ae("span",{"aria-hidden":"true",className:"required",children:"*"})]}),Ae("input",{type:"text",name:"authorName",required:!0,value:s.authorName,onChange:u,placeholder:f("publishDialog.placeholder.authorName")})]}),Zt("label",{children:[Ae("span",{children:f("publishDialog.githubUsername")}),Ae("input",{type:"text",name:"githubHandle",value:s.githubHandle,onChange:u,placeholder:f("publishDialog.placeholder.githubHandle")})]}),Zt("label",{children:[Ae("span",{children:f("publishDialog.twitterUsername")}),Ae("input",{type:"text",name:"twitterHandle",value:s.twitterHandle,onChange:u,placeholder:f("publishDialog.placeholder.twitterHandle")})]}),Zt("label",{children:[Ae("span",{children:f("publishDialog.website")}),Ae("input",{type:"text",name:"website",pattern:"https?://.+",title:f("publishDialog.errors.website"),value:s.website,onChange:u,placeholder:f("publishDialog.placeholder.website")})]}),Ae("span",{className:"publish-library-note",children:Ae(io,{i18nKey:"publishDialog.noteLicense",link:w=>Ae("a",{href:"https://github.com/excalidraw/excalidraw-libraries/blob/main/LICENSE",target:"_blank",rel:"noopener noreferrer",children:w})})})]}),Zt("div",{className:"publish-library__buttons",children:[Ae(vr,{label:f("buttons.saveLibNames"),onClick:x,"data-testid":"cancel-clear-canvas-button"}),Ae(vr,{type:"submit",label:f("buttons.submit"),actionType:"primary",isLoading:c})]})]}):Ae("p",{style:{padding:"1em",textAlign:"center",fontWeight:500},children:f("publishDialog.atleastOneLibItem")})})},ZT=BB;import yC from"react";import{DropdownMenu as cF}from"radix-ui";import{CLASSES as dF}from"@orangecatai/common";import zB from"clsx";import{useCallback as HB,useEffect as GB,useRef as UB}from"react";import{CLASSES as WB,EVENT as QT,KEYS as YB}from"@orangecatai/common";import{DropdownMenu as $B}from"radix-ui";import{forwardRef as jT}from"react";import qT from"clsx";import{jsx as JT}from"react/jsx-runtime";var FB=jT(({children:e,gap:t,align:o,justifyContent:n,className:r,style:a},i)=>JT("div",{className:qT("Stack Stack_horizontal",r),style:{"--gap":t,alignItems:o,justifyContent:n,...a},ref:i,children:e})),OB=jT(({children:e,gap:t,align:o,justifyContent:n,className:r,style:a},i)=>JT("div",{className:qT("Stack Stack_vertical",r),style:{"--gap":t,justifyItems:o,justifyContent:n,...a},ref:i,children:e})),Rt={Row:FB,Col:OB};import{jsx as Fp}from"react/jsx-runtime";var eC=({children:e,onClickOutside:t,className:o="",onSelect:n,open:r=!0,align:a="end",style:i})=>{let s=Te(),l=UB(null),c=Ur({onClickOutside:t});fs(l,HB(p=>{l.current?.closest(`.${WB.DROPDOWN_MENU_EVENT_WRAPPER}`)?.contains(p.target)||c.onClickOutside?.()},[c])),GB(()=>{if(!r)return;let p=u=>{u.key===YB.ESCAPE&&(u.stopImmediatePropagation(),c.onClickOutside?.())},d={capture:!0};return document.addEventListener(QT.KEYDOWN,p,d),()=>{document.removeEventListener(QT.KEYDOWN,p,d)}},[c,r]);let m=zB(`dropdown-menu ${o}`,{"dropdown-menu--mobile":s.formFactor==="phone"}).trim();return Fp(df.Provider,{value:{onSelect:n},children:Fp($B.Content,{ref:l,className:m,style:i,"data-testid":"dropdown-menu",align:a,sideOffset:8,onCloseAutoFocus:p=>p.preventDefault(),children:s.formFactor==="phone"?Fp(Rt.Col,{className:"dropdown-menu-container",children:e}):Fp(gt,{className:"dropdown-menu-container",padding:2,children:e})})})};eC.displayName="DropdownMenuContent";var tC=eC;import{jsx as KB}from"react/jsx-runtime";var VB=({children:e,className:t="",selected:o,...n})=>KB("div",{...n,className:`dropdown-menu-item-base dropdown-menu-item-custom ${t} ${o?"dropdown-menu-item--selected":""}`.trim(),children:e}),oC=VB;import{DropdownMenu as XB}from"radix-ui";import{jsx as Fb}from"react/jsx-runtime";var nC=({icon:e,shortcut:t,href:o,children:n,onSelect:r,className:a="",selected:i,rel:s="noopener",...l})=>{let c=Wm(r);return Fb(XB.Item,{className:"radix-menu-item",onSelect:c,asChild:!0,children:Fb("a",{...l,href:o,target:"_blank",rel:`noopener ${s}`,className:Xr(a,i),title:l.title??l["aria-label"],children:Fb(Zr,{icon:e,shortcut:t,children:n})})})},qs=nC;nC.displayName="DropdownMenuItemLink";import{jsx as ZB}from"react/jsx-runtime";var rC=()=>ZB("div",{style:{height:"1px",backgroundColor:"var(--default-border-color)",margin:"6px 0",flex:"0 0 auto"}}),aC=rC;rC.displayName="DropdownMenuSeparator";import{DropdownMenu as oF}from"radix-ui";import jB from"clsx";import{DropdownMenu as qB}from"radix-ui";import{useCallback as JB,useState as iC}from"react";import{jsx as zb}from"react/jsx-runtime";var Ob=-4,QB=4,sC=({children:e,className:t})=>{let o=Te(),n=jB(`dropdown-menu dropdown-submenu ${t}`,{"dropdown-menu--mobile":o.formFactor==="phone"}).trim(),r=JB(c=>{if(c){let p=c.closest(".dropdown-menu-container")?.getBoundingClientRect();if(p){let d=c.getBoundingClientRect().width,h=window.innerWidth-p.right;h<d+20&&(i(h-d+Ob),l(Ob+8))}}},[]),[a,i]=iC(QB),[s,l]=iC(Ob);return zb(qB.SubContent,{className:n,sideOffset:a,alignOffset:s,collisionPadding:8,ref:r,children:o.formFactor==="phone"?zb(Rt.Col,{className:"dropdown-menu-container",children:e}):zb(gt,{className:"dropdown-menu-container",padding:2,style:{zIndex:1},children:e})})},lC=sC;sC.displayName="DropdownMenuSubContent";import{DropdownMenu as eF}from"radix-ui";import{jsx as cC,jsxs as tF}from"react/jsx-runtime";var dC=({children:e,icon:t,shortcut:o,className:n})=>tF(eF.SubTrigger,{className:`${Xr(n)} dropdown-menu__submenu-trigger`,children:[cC(Zr,{icon:t,shortcut:o,children:e}),cC("div",{className:"dropdown-menu__submenu-trigger-icon",children:xv})]}),mC=dC;dC.displayName="DropdownMenuSubTrigger";import pC from"react";var Op=e=>t=>{let o=pC.Children.toArray(t).find(n=>pC.isValidElement(n)&&typeof n.type!="string"&&n?.type.displayName&&n.type.displayName===e);return o||null},uC=Op("DropdownMenuTrigger"),gC=Op("DropdownMenuContent"),hC=Op("DropdownMenuSubTrigger"),fC=Op("DropdownMenuSubContent");import{jsxs as nF}from"react/jsx-runtime";var zp=({children:e})=>{let t=hC(e),o=fC(e);return nF(oF.Sub,{children:[t,o]})};zp.Trigger=mC;zp.Content=lC;zp.displayName="DropdownMenuSub";var aa=zp;import rF from"clsx";import{DropdownMenu as aF}from"radix-ui";import{jsx as iF}from"react/jsx-runtime";var bC=({className:e="",children:t,onToggle:o,title:n,...r})=>{let a=Te(),i=rF(`dropdown-menu-button ${e}`,"zen-mode-transition",{"dropdown-menu-button--mobile":a.formFactor==="phone"}).trim();return iF(aF.Trigger,{className:i,onClick:o,type:"button","data-testid":"dropdown-menu-button",title:n,...r,children:t})},xC=bC;bC.displayName="DropdownMenuTrigger";import{jsx as lF}from"react/jsx-runtime";var sF=e=>lF(to,{...e,icon:e.checked?bm:bv}),Ir=sF;import{jsx as pF,jsxs as mF}from"react/jsx-runtime";var xn=({children:e,open:t})=>{let o=uC(e),n=gC(e),r=n&&yC.isValidElement(n)?yC.cloneElement(n,{open:t}):n;return pF(cF.Root,{open:t,modal:!1,children:mF("div",{className:dF.DROPDOWN_MENU_EVENT_WRAPPER,style:{display:"contents"},children:[o,r]})})};xn.Trigger=xC;xn.Content=tC;xn.Item=to;xn.ItemCheckbox=Ir;xn.ItemLink=qs;xn.ItemCustom=oC;xn.Group=bc;xn.Separator=aC;xn.Sub=aa;var ye=xn;xn.displayName="DropdownMenu";import{jsx as bo,jsxs as Hp}from"react/jsx-runtime";var fF=(e,t)=>e.filter(o=>t.includes(o.id)),bF=({setAppState:e,selectedItems:t,library:o,onRemoveFromLibrary:n,resetLibrary:r,onSelectItems:a,appState:i,className:s})=>{let[l]=le(wr),[c,m]=le(js),p=()=>{let _=t.length?f("alerts.removeItemsFromsLibrary",{count:t.length}):f("alerts.resetLibrary"),k=t.length?f("confirmDialog.removeItemsFromLib"):f("confirmDialog.resetLibrary");return bo(Np,{onConfirm:()=>{t.length?n():r(),u(!1)},onCancel:()=>{u(!1)},title:k,children:bo("p",{children:_})})},[d,u]=Hb(!1),h=!!t.length,g=h?l.libraryItems.filter(_=>t.includes(_.id)):l.libraryItems,x=h?f("buttons.remove"):f("buttons.resetLibrary"),[E,y]=Hb(!1),[w,v]=Hb(null),I=gF(()=>Hp(bt,{onCloseRequest:()=>v(null),title:f("publishSuccessDialog.title"),className:"publish-library-success",size:"small",children:[bo("p",{children:bo(io,{i18nKey:"publishSuccessDialog.content",authorName:w.authorName,link:_=>bo("a",{href:w?.url,target:"_blank",rel:"noopener noreferrer",children:_})})}),bo(ie,{type:"button",title:f("buttons.close"),"aria-label":f("buttons.close"),label:f("buttons.close"),onClick:()=>v(null),"data-testid":"publish-library-success-close",className:"publish-library-success-close"})]}),[v,w]),C=(_,k)=>{y(!1),v({url:_.url,authorName:_.authorName});let M=k.slice();M.forEach(B=>{t.includes(B.id)&&(B.status="published")}),o.setLibrary(M)},P=async()=>{try{await o.updateLibrary({libraryItems:om({description:"Excalidraw library files"}),merge:!0,openLibraryMenu:!0})}catch(_){if(_?.name==="AbortError"){console.warn(_);return}e({errorMessage:f("errors.importLibraryError")})}},S=async()=>{let _=h?g:await o.getLatestLibrary();iE(_).catch(hF).catch(k=>{e({errorMessage:k.message})})},D=()=>Hp(ye,{open:c,children:[bo(ye.Trigger,{onToggle:()=>m(!c),children:PE}),Hp(ye.Content,{onClickOutside:()=>m(!1),onSelect:()=>m(!1),className:"library-menu",children:[!h&&bo(ye.Item,{onSelect:P,icon:rs,"data-testid":"lib-dropdown--load",children:f("buttons.load")}),!!g.length&&bo(ye.Item,{onSelect:S,icon:$a,"data-testid":"lib-dropdown--export",children:f("buttons.export")}),h&&bo(ye.Item,{icon:Fw,onSelect:()=>y(!0),"data-testid":"lib-dropdown--remove",children:f("buttons.publishLibrary")}),!!g.length&&bo(ye.Item,{onSelect:()=>u(!0),icon:Ut,children:x})]})]});return Hp("div",{className:uF("library-menu-dropdown-container",s),children:[D(),t.length>0&&bo("div",{className:"library-actions-counter",children:t.length}),d&&p(),E&&bo(ZT,{onClose:()=>y(!1),libraryItems:fF(l.libraryItems,t),appState:i,onSuccess:_=>C(_,l.libraryItems),onError:_=>window.alert(_),updateItemsInStorage:()=>o.setLibrary(l.libraryItems),onRemove:_=>a(t.filter(k=>k!==_))}),w&&I()]})},EC=({selectedItems:e,onSelectItems:t,className:o})=>{let{library:n}=tt(),{clearLibraryCache:r,deleteItemsFromLibraryCache:a}=Ks(),i=Ie(),s=Ce(),[l]=le(wr),c=async p=>{let d=p.filter(u=>!e.includes(u.id));n.setLibrary(d).catch(()=>{s({errorMessage:f("alerts.errorRemovingFromLibrary")})}),a(e),t([])};return bo(bF,{appState:i,setAppState:s,selectedItems:e,onSelectItems:t,library:n,onRemoveFromLibrary:()=>c(l.libraryItems),resetLibrary:()=>{n.resetLibrary(),r()},className:o})};import{memo as CF,useEffect as kF,useState as SF}from"react";import xF,{useCallback as yF}from"react";function EF(){return[!1,yF(t=>t(),[])]}var wC=xF.useTransition||EF;import vC from"clsx";import{memo as wF,useRef as vF,useState as IF}from"react";import{jsx as Gp,jsxs as TF}from"react/jsx-runtime";var IC=wF(({id:e,elements:t,isPending:o,onClick:n,selected:r,onToggle:a,onDrag:i,svgCache:s})=>{let l=vF(null),c=Pp(e,t,s,l),[m,p]=IF(!1),d=Te().formFactor==="phone",u=o&&Gp("div",{className:"library-unit__adder",children:ME});return TF("div",{className:vC("library-unit",{"library-unit__active":t,"library-unit--hover":t&&m,"library-unit--selected":r,"library-unit--skeleton":!c}),onMouseEnter:()=>p(!0),onMouseLeave:()=>p(!1),children:[Gp("div",{className:vC("library-unit__dragger",{"library-unit__pulse":!!o}),ref:l,draggable:!!t,onClick:t||o?h=>{e&&h.shiftKey?a(e,h):n(e)}:void 0,onDragStart:h=>{if(!e){h.preventDefault();return}p(!1),i(e,h)}}),u,e&&t&&(m||d||r)&&Gp(Tc,{checked:r,onChange:(h,g)=>a(e,g),className:"library-unit__checkbox"})]})}),TC=()=>Gp("div",{className:"library-unit library-unit--skeleton"});import{Fragment as MF,jsx as Up}from"react/jsx-runtime";var Wp=({children:e})=>Up("div",{className:"library-menu-items-container__grid",children:e}),$c=CF(({items:e,onItemSelectToggle:t,onItemDrag:o,isItemSelected:n,onClick:r,svgCache:a,itemsRenderedPerBatch:i})=>{let[,s]=wC(),[l,c]=SF(0);return kF(()=>{l<e.length&&s(()=>{c(l+i)})},[l,e.length,s,i]),Up(MF,{children:e.map((m,p)=>p<l?Up(IC,{elements:m?.elements,isPending:!m?.id&&!!m?.elements,onClick:r,svgCache:a,id:m?.id,selected:n(m.id),onToggle:t,onDrag:o},m?.id??p):Up(TC,{},p))})});import Gb from"clsx";import{forwardRef as _F,useRef as DF,useImperativeHandle as RF,useLayoutEffect as NF,useState as BF}from"react";import PF from"clsx";import{composeEventHandlers as AF}from"@orangecatai/common";import{jsx as LF}from"react/jsx-runtime";var so=({type:e="button",onSelect:t,selected:o,children:n,className:r="",...a})=>LF("button",{onClick:AF(a.onClick,i=>{t()}),type:e,className:PF("excalidraw-button",r,{selected:o}),...a,children:n});import{jsx as Ub,jsxs as CC}from"react/jsx-runtime";var ia=_F(({onChange:e,label:t,fullWidth:o,placeholder:n,readonly:r,selectOnRender:a,onKeyDown:i,isRedacted:s=!1,icon:l,className:c,type:m,...p},d)=>{let u=DF(null);RF(d,()=>u.current),NF(()=>{a&&(u.current?.focus(),u.current?.select())},[a]);let[h,g]=BF(!1);return CC("div",{className:Gb("ExcTextField",c,{"ExcTextField--fullWidth":o,"ExcTextField--hasIcon":!!l}),onClick:()=>{u.current?.focus()},children:[l,t&&Ub("div",{className:"ExcTextField__label",children:t}),CC("div",{className:Gb("ExcTextField__input",{"ExcTextField__input--readonly":r}),children:[Ub("input",{className:Gb({"is-redacted":"value"in p&&p.value&&s&&!h}),readOnly:r,value:"value"in p?p.value:void 0,defaultValue:"defaultValue"in p?p.defaultValue:void 0,placeholder:n,ref:u,onChange:x=>e?.(x.target.value),onKeyDown:i,type:m}),s&&Ub(so,{onSelect:()=>g(!h),style:{border:0,userSelect:"none"},children:h?Vw:ls})]})]})});import{Fragment as MC,jsx as Nt,jsxs as $n}from"react/jsx-runtime";var UF=17,WF=64;function $b({isLoading:e,libraryItems:t,onAddToLibrary:o,onInsertLibraryItems:n,pendingElements:r,theme:a,id:i,libraryReturnUrl:s,onSelectItems:l,selectedItems:c}){let m=Te(),p=kC(null),d=WT(p);Wb(()=>{d>0&&p.current?.scrollTo(0,d)},[]);let{svgCache:u}=Ks(),[h,g]=SC(null),[x,E]=SC(""),y=!t.length&&!r.length,w=!y&&!!x.trim(),v=Yb(()=>{let L=ri(x.trim().toLowerCase());return L?t.filter(F=>{let $=F.name||"";return $.trim()&&ri($.toLowerCase()).includes(L)}):[]},[t,x]),I=Yb(()=>t.filter(L=>L.status!=="published"),[t]),C=Yb(()=>t.filter(L=>L.status==="published"),[t]),P=Js((L,F)=>{let $=!c.includes(L),Q=[...I,...C];if($){if(F.shiftKey&&h){let Z=Q.findIndex(ue=>ue.id===h),U=Q.findIndex(ue=>ue.id===L);if(Z===-1||U===-1){l([...c,L]);return}let q=OF(c),ae=Math.min(Z,U),J=Math.max(Z,U),te=Q.reduce((ue,Me,ct)=>((ct>=ae&&ct<=J||q.has(Me.id))&&ue.push(Me.id),ue),[]);l(te)}else l([...c,L]);g(L)}else g(null),l(c.filter(Z=>Z!==L))},[h,l,C,c,I]);Wb(()=>{c.length||g(null)},[c]);let S=Js(L=>{let F;return c.includes(L)?F=t.filter($=>c.includes($.id)):F=t.filter($=>$.id===L),F.map($=>({...$,elements:HF({type:"everything",elements:$.elements,randomizeSeed:!0}).duplicatedElements}))},[t,c]),D=Js((L,F)=>{let $={itemIds:c.includes(L)?c:[L]};F.dataTransfer.setData(FF.excalidrawlibIds,JSON.stringify($))},[c]),_=Js(L=>L?c.includes(L):!1,[c]),k=Js(()=>{o(r)},[r,o]),M=Js(L=>{L&&n(S(L))},[S,n]),B=u.size>=(v.length?v:t).length?WF:UF,O=kC(null);Wb(()=>{zF(()=>{O.current?.focus()})},[]);let N=!w&&$n(MC,{children:[!y&&Nt("div",{className:"library-menu-items-container__header",children:f("labels.personalLib")}),!r.length&&!I.length?$n("div",{className:"library-menu-items__no-items",children:[!C.length&&Nt("div",{className:"library-menu-items__no-items__label",children:f("library.noItems")}),Nt("div",{className:"library-menu-items__no-items__hint",children:C.length>0?f("library.hint_emptyPrivateLibrary"):f("library.hint_emptyLibrary")})]}):$n(Wp,{children:[r.length>0&&Nt($c,{itemsRenderedPerBatch:B,items:[{id:null,elements:r}],onItemSelectToggle:P,onItemDrag:D,onClick:k,isItemSelected:_,svgCache:u}),Nt($c,{itemsRenderedPerBatch:B,items:I,onItemSelectToggle:P,onItemDrag:D,onClick:M,isItemSelected:_,svgCache:u})]}),C.length>0&&Nt("div",{className:"library-menu-items-container__header",style:{marginTop:"0.75rem"},children:f("labels.excalidrawLib")}),C.length>0&&Nt(Wp,{children:Nt($c,{itemsRenderedPerBatch:B,items:C,onItemSelectToggle:P,onItemDrag:D,onClick:M,isItemSelected:_,svgCache:u})})]}),z=w&&$n(MC,{children:[$n("div",{className:"library-menu-items-container__header",children:[f("library.search.heading"),!e&&$n("div",{className:"library-menu-items-container__header__hint",style:{cursor:"pointer"},onPointerDown:L=>L.preventDefault(),onClick:L=>{E("")},children:[Nt("kbd",{children:"esc"})," to clear"]})]}),v.length>0?Nt(Wp,{children:Nt($c,{itemsRenderedPerBatch:B,items:v,onItemSelectToggle:P,onItemDrag:D,onClick:M,isItemSelected:_,svgCache:u})}):$n("div",{className:"library-menu-items__no-items",children:[Nt("div",{className:"library-menu-items__no-items__hint",children:f("library.search.noResults")}),Nt(so,{onPointerDown:L=>L.preventDefault(),onSelect:()=>{E("")},style:{width:"auto",marginTop:"1rem"},children:f("library.search.clearSearch")})]})]});return $n("div",{className:"library-menu-items-container",style:r.length||I.length||C.length?{justifyContent:"flex-start"}:{borderBottom:0},children:[$n("div",{className:"library-menu-items-header",children:[!y&&Nt(ia,{ref:O,type:"search",className:GF("library-menu-items-container__search",{hideCancelButton:m.formFactor!=="phone"}),placeholder:f("library.search.inputPlaceholder"),value:x,onChange:L=>E(L)}),Nt(EC,{selectedItems:c,onSelectItems:l,className:"library-menu-dropdown-container--in-heading"})]}),$n(Rt.Col,{className:"library-menu-items-container__items",align:"start",gap:1,style:{flex:C.length>0?1:"0 1 auto",margin:y?"auto":0},ref:p,children:[e&&Nt("div",{style:{position:"absolute",top:"var(--container-padding-y)",right:"var(--container-padding-x)",transform:"translateY(50%)"},children:Nt(Wt,{})}),N,z,y&&Nt(Dp,{style:{padding:"16px 0",width:"100%"},id:i,libraryReturnUrl:s,theme:a})]})]})}import{jsx as sa,jsxs as LC}from"react/jsx-runtime";var js=Pe(!1),AC=({children:e})=>sa("div",{className:"layer-ui__library",children:e}),JF=RC(({onInsertLibraryItems:e,pendingElements:t,onAddToLibrary:o,setAppState:n,libraryReturnUrl:r,library:a,id:i,theme:s,selectedItems:l,onSelectItems:c})=>{let[m]=le(wr),p=Kb(h=>{(async(x,E)=>{be("element","addToLibrary","ui");for(let w of $F)if(x.some(v=>v.type===w))return n({errorMessage:f(`errors.libraryElementTypeError.${w}`)});let y=[{status:"unpublished",elements:x,id:VF(),created:Date.now()},...E];o(),a.setLibrary(y).catch(()=>{n({errorMessage:f("alerts.errorAddingToLibrary")})})})(h,m.libraryItems)},[o,a,n,m.libraryItems]),d=DC(()=>m.libraryItems,[m]);if(m.status==="loading"&&!m.isInitialized)return sa(AC,{children:sa("div",{className:"layer-ui__library-message",children:LC("div",{children:[sa(Wt,{size:"2em"}),sa("span",{children:f("labels.libraryLoadingMessage")})]})})});let u=m.libraryItems.length>0||t.length>0;return LC(AC,{children:[sa($b,{isLoading:m.status==="loading",libraryItems:d,onAddToLibrary:p,onInsertLibraryItems:e,pendingElements:t,id:i,libraryReturnUrl:r,theme:s,onSelectItems:c,selectedItems:l}),u&&sa(Dp,{className:"library-menu-control-buttons--at-bottom",style:{padding:"16px 12px 0 12px"},id:i,libraryReturnUrl:r,theme:s})]})}),Vb=(e,t)=>({elements:e,pending:de(e,{selectedElementIds:t},{includeBoundTextElement:!0,includeElementsInFrames:!0}),selectedElementIds:t}),QF=(e,t)=>{let o=$r(),[n,r]=_C(()=>Vb(o,e.selectedElementIds)),a=YF(new Map);return Xb(()=>{for(let i of n.pending)a.current.set(i.id,i.version)},[n.pending]),Xb(()=>{t.state.cursorButton==="up"&&t.state.activeTool.type==="selection"&&r(i=>{if(!KF(i.selectedElementIds,e.selectedElementIds))return a.current.clear(),Vb(o,e.selectedElementIds);let s=t.scene.getNonDeletedElementsMap();for(let l of Object.keys(e.selectedElementIds)){let c=s.get(l)?.version;if(c&&c!==a.current.get(l))return Vb(o,e.selectedElementIds)}return i})},[t,t.state.cursorButton,t.state.activeTool.type,e.selectedElementIds,o]),n.pending},NC=RC(()=>{let e=tt(),{onInsertElements:t}=e,o=Hn(),n=Ie(),r=Ce(),[a,i]=_C([]),s=DC(()=>e.library,[e.library]),l=QF(n,e);Xb(()=>jF(document,qF.KEYDOWN,p=>{if(p.key===XF.ESCAPE&&p.target instanceof HTMLElement){let d=p.target;if(d.closest(`.${PC.SIDEBAR}`))a.length>0?(p.stopPropagation(),i([])):ZF(d)&&d instanceof HTMLInputElement&&!d.value&&(p.stopPropagation(),r({openSidebar:null}),e.focusContainer());else if(a.length>0){let{x:u,y:h}=e.lastViewportPosition;document.elementFromPoint(u,h)?.closest(`.${PC.SIDEBAR}`)&&(p.stopPropagation(),i([]))}}},{capture:!0}),[a,r,e]);let c=Kb(p=>{t(Zs(p)),e.focusContainer()},[t,e]),m=Kb(()=>{r({selectedElementIds:{},selectedGroupIds:{},activeEmbeddable:null})},[r]);return sa(JF,{pendingElements:l,onInsertLibraryItems:c,onAddToLibrary:m,setAppState:r,libraryReturnUrl:o.libraryReturnUrl,library:s,id:e.id,theme:n.theme,selectedItems:a,onSelectItems:i})});import eO from"clsx";import{useRef as tO}from"react";import{createPortal as oO}from"react-dom";import{KEYS as nO}from"@orangecatai/common";import{jsx as BC,jsxs as rO}from"react/jsx-runtime";var FC=e=>{let{closeOnClickOutside:t=!0}=e,o=Rm({className:"excalidraw-modal-container"}),n=tO(document.body.classList.contains("excalidraw-animations-disabled"));if(!o)return null;let r=a=>{a.key===nO.ESCAPE&&(a.nativeEvent.stopImmediatePropagation(),a.stopPropagation(),e.onCloseRequest())};return oO(rO("div",{className:eO("Modal",e.className,{"animations-disabled":n.current}),role:"dialog","aria-modal":"true",onKeyDown:r,"aria-labelledby":e.labelledBy,children:[BC("div",{className:"Modal__background",onClick:t?e.onCloseRequest:void 0}),BC("div",{className:"Modal__content",style:{"--max-width":`${e.maxWidth}px`},tabIndex:0,children:e.children})]}),o)};import{jsx as Vc,jsxs as dO}from"react/jsx-runtime";function cO(e){if(e&&typeof e=="number")return e;switch(e){case"small":return 550;case"wide":return 1024;case"regular":default:return 800}}var bt=e=>{let[t,o]=PT(),[n]=sO(document.activeElement),{id:r}=Qe(),a=Te().formFactor==="phone";iO(()=>{if(!t)return;let c=OC(t);setTimeout(()=>{c.length>0&&e.autofocus!==!1&&(c[1]||c[0]).focus()});let m=p=>{if(p.key===lO.TAB){let d=OC(t),{activeElement:u}=document,h=d.findIndex(g=>g===u);h===0&&p.shiftKey?(d[d.length-1].focus(),p.preventDefault()):h===d.length-1&&!p.shiftKey&&(d[0].focus(),p.preventDefault())}};return t.addEventListener("keydown",m),()=>t.removeEventListener("keydown",m)},[t,e.autofocus]);let i=Ce(),s=Rn(js),l=()=>{i({openMenu:null}),s(!1),n.focus(),e.onCloseRequest()};return Vc(FC,{className:aO("Dialog",e.className,{"Dialog--fullscreen":a}),labelledBy:"dialog-title",maxWidth:cO(e.size),onCloseRequest:l,closeOnClickOutside:e.closeOnClickOutside,children:dO(gt,{ref:o,children:[e.title&&Vc("h2",{id:`${r}-dialog-title`,className:"Dialog__title",children:Vc("span",{className:"Dialog__titleContent",children:e.title})}),a&&Vc("button",{className:"Dialog__close",onClick:l,title:f("buttons.close"),"aria-label":f("buttons.close"),type:"button",children:Go}),Vc("div",{className:"Dialog__content",children:e.children})]})})};import{KEYS as dt}from"@orangecatai/common";var Yp=[{icon:as,value:"hand",key:dt.H,numericKey:null,fillable:!1,toolbar:!0},{icon:Ya,value:"selection",key:dt.V,numericKey:dt[1],fillable:!0,toolbar:!0},{icon:qi,value:"rectangle",key:dt.R,numericKey:dt[2],fillable:!0,toolbar:!0},{icon:Ji,value:"diamond",key:dt.D,numericKey:dt[3],fillable:!0,toolbar:!0},{icon:Qi,value:"ellipse",key:dt.O,numericKey:dt[4],fillable:!0,toolbar:!0},{icon:gm,value:"arrow",key:dt.A,numericKey:dt[5],fillable:!0,toolbar:!0},{icon:es,value:"line",key:dt.L,numericKey:dt[6],fillable:!0,toolbar:!0},{icon:Bn,value:"freedraw",key:[dt.P,dt.X],numericKey:dt[7],fillable:!1,toolbar:!0},{icon:Fn,value:"text",key:dt.T,numericKey:dt[8],fillable:!1,toolbar:!0},{icon:ts,value:"image",key:null,numericKey:dt[9],fillable:!1,toolbar:!0},{icon:hm,value:"eraser",key:dt.E,numericKey:dt[0],fillable:!1,toolbar:!0},{icon:zn,value:"laser",key:dt.K,numericKey:null,fillable:!1,toolbar:!1}],Zb=e=>e.state.preferredSelectionTool.type==="lasso"?[{value:"lasso",icon:Ya,key:dt.V,numericKey:dt[1],fillable:!0,toolbar:!0},...Yp.slice(1)]:Yp,zC=(e,t)=>Zb(t).find((n,r)=>n.numericKey!=null&&e===n.numericKey.toString()||n.key&&(typeof n.key=="string"?n.key===e:n.key.includes(e)))?.value||null;import Kn from"clsx";import{useRef as yO,useState as EO}from"react";import{Popover as ca}from"radix-ui";import{CLASSES as $C,KEYS as wO,capitalizeString as la,isTransparent as Vp}from"@orangecatai/common";import{shouldAllowVerticalAlign as VC,suppportsHorizontalAlign as KC,hasBoundTextElement as Kp,isElbowArrow as Qb,isImageElement as XC,isLinearElement as e0,isTextElement as Zp,isArrowElement as WC,hasStrokeColor as YC,toolIsArrow as Xp}from"@orangecatai/element";import{createIsolation as mO}from"jotai-scope";import jb from"react";import Vn from"tunnel-rat";var qb=jb.createContext(null),Ze=()=>jb.useContext(qb),pO=mO(),HC=()=>jb.useMemo(()=>({MainMenuTunnel:Vn(),WelcomeScreenMenuHintTunnel:Vn(),WelcomeScreenToolbarHintTunnel:Vn(),WelcomeScreenHelpHintTunnel:Vn(),WelcomeScreenCenterTunnel:Vn(),FooterCenterTunnel:Vn(),DefaultSidebarTriggerTunnel:Vn(),DefaultSidebarTabTriggersTunnel:Vn(),OverwriteConfirmDialogTunnel:Vn(),TTDDialogTriggerTunnel:Vn(),tunnelsJotai:pO}),[]);import{CODES as uO,KEYS as gO}from"@orangecatai/common";import{CaptureUpdateAction as hO}from"@orangecatai/element";var ii=W({name:"viewMode",label:"labels.viewMode",icon:ls,viewMode:!0,trackEvent:{category:"canvas",predicate:e=>!e.viewModeEnabled},perform(e,t){return{appState:{...t,viewModeEnabled:!this.checked(t)},captureUpdate:hO.EVENTUALLY}},checked:e=>e.viewModeEnabled,predicate:(e,t,o)=>typeof o.viewModeEnabled>"u",keyTest:e=>!e[gO.CTRL_OR_CMD]&&e.altKey&&e.code===uO.R});import{useEffect as fO,useState as bO}from"react";import GC from"clsx";import{capitalizeString as UC}from"@orangecatai/common";import{Popover as Jb}from"radix-ui";import{jsx as $p,jsxs as xO}from"react/jsx-runtime";var Qs=({app:e,options:t,activeTool:o,defaultOption:n,className:r="Shape",namePrefix:a,title:i,"data-testid":s,onToolChange:l,displayedOption:c,fillable:m=!1})=>{let[p,d]=bO(!1),u=o.type,h=c.type===u,g=32/2+10,{container:x}=Qe();return!t.some(E=>E.type===u)&&p&&d(!1),fO(()=>{let E=e.onPointerDownEmitter.on(()=>{d(!1)});return()=>E?.()},[e]),xO(Jb.Root,{open:p,children:[$p(Jb.Trigger,{asChild:!0,children:$p(ie,{className:GC(r,{fillable:m,active:t.some(E=>E.type===o.type)}),type:"radio",icon:c.icon,checked:h,name:"editor-current-shape",title:i,"aria-label":i,"data-testid":s,onPointerDown:()=>{d(E=>!E),l(n)}})}),$p(Jb.Content,{className:"tool-popover-content",sideOffset:g,collisionBoundary:x??void 0,children:t.map(({type:E,icon:y,title:w})=>$p(ie,{className:GC(r,{active:u===E}),type:"radio",icon:y,checked:u===E,name:`${a}-option`,title:w||UC(E),keyBindingLabel:"","aria-label":w||UC(E),"data-testid":`toolbar-${E}`,onChange:()=>{e.state.activeTool.type!==E&&be("toolbar",E,"ui"),e.setActiveTool({type:E}),l?.(E)}},E))})]})};import{Fragment as Do,jsx as se,jsxs as ke}from"react/jsx-runtime";var t0=Kn([$C.SHAPE_ACTIONS_THEME_SCOPE,"properties-content"]),Kc=(e,t)=>{let o=t[0]?.type||null;for(let n of t)if(n.type!==o){o=null;break}return YC(e.activeTool.type)&&o!=="image"&&o!=="frame"&&o!=="magicframe"||t.some(n=>YC(n.type))},Xc=(e,t)=>_n(e.activeTool.type)||t.some(o=>_n(o.type)),ZC=({appState:e,elementsMap:t,renderAction:o,app:n})=>{let r=Hi(t,e),a=!1;r.length===2&&(Kp(r[0])||Kp(r[1]))&&(a=!0);let i=!!(e.editingTextElement||e.newElement),s=Te(),l=document.documentElement.getAttribute("dir")==="rtl",c=_n(e.activeTool.type)&&!Vp(e.currentItemBackgroundColor)||r.some(h=>_n(h.type)&&!Vp(h.backgroundColor)),m=r.length===1||a,p=!e.selectedLinearElement?.isEditing&&r.length===1&&e0(r[0])&&!Qb(r[0]),d=!e.croppingElementId&&r.length===1&&XC(r[0]),u=!a&&ao(e,n);return ke("div",{className:"selected-shape-actions",children:[se("div",{children:Kc(e,r)&&o("changeStrokeColor")}),Xc(e,r)&&se("div",{children:o("changeBackgroundColor")}),c&&o("changeFillStyle"),(Kl(e.activeTool.type)||r.some(h=>Kl(h.type)))&&o("changeStrokeWidth"),(e.activeTool.type==="freedraw"||r.some(h=>h.type==="freedraw"))&&o("changeStrokeShape"),(Xl(e.activeTool.type)||r.some(h=>Xl(h.type)))&&ke(Do,{children:[o("changeStrokeStyle"),o("changeSloppiness")]}),(Zl(e.activeTool.type)||r.some(h=>Zl(h.type)))&&se(Do,{children:o("changeRoundness")}),(Xp(e.activeTool.type)||r.some(h=>Xp(h.type)))&&se(Do,{children:o("changeArrowType")}),(e.activeTool.type==="text"||r.some(Zp))&&ke(Do,{children:[o("changeFontFamily"),o("changeFontSize"),(e.activeTool.type==="text"||KC(r,t))&&o("changeTextAlign")]}),VC(r,t)&&o("changeVerticalAlign"),(Gi(e.activeTool.type)||r.some(h=>Gi(h.type)))&&se(Do,{children:o("changeArrowhead")}),o("changeOpacity"),ke("fieldset",{children:[se("legend",{children:f("labels.layers")}),ke("div",{className:"buttonList",children:[o("sendToBack"),o("sendBackward"),o("bringForward"),o("bringToFront")]})]}),u&&!a&&ke("fieldset",{children:[se("legend",{children:f("labels.align")}),ke("div",{className:"buttonList",children:[l?ke(Do,{children:[o("alignRight"),o("alignHorizontallyCentered"),o("alignLeft")]}):ke(Do,{children:[o("alignLeft"),o("alignHorizontallyCentered"),o("alignRight")]}),r.length>2&&o("distributeHorizontally"),se("div",{style:{flexBasis:"100%",height:0}}),ke("div",{style:{display:"flex",flexWrap:"wrap",gap:".5rem",marginTop:"-0.5rem"},children:[o("alignTop"),o("alignVerticallyCentered"),o("alignBottom"),r.length>2&&o("distributeVertically")]})]})]}),!i&&r.length>0&&ke("fieldset",{children:[se("legend",{children:f("labels.actions")}),ke("div",{className:"buttonList",children:[s.formFactor!=="phone"&&o("duplicateSelection"),s.formFactor!=="phone"&&o("deleteSelectedElements"),o("group"),o("ungroup"),m&&o("hyperlink"),d&&o("cropEditor"),p&&o("toggleLinearEditor")]})]})]})},jC=({appState:e,renderAction:t,setAppState:o,targetElements:n,container:r})=>{let a=_n(e.activeTool.type)&&!Vp(e.currentItemBackgroundColor)||n.some(l=>_n(l.type)&&!Vp(l.backgroundColor)),i=n.length>0||e.activeTool.type!=="selection"&&e.activeTool.type!=="eraser"&&e.activeTool.type!=="hand"&&e.activeTool.type!=="laser"&&e.activeTool.type!=="lasso",s=e.openPopup==="compactStrokeStyles";return i?se("div",{className:"compact-action-item",children:ke(ca.Root,{open:s,onOpenChange:l=>{o(l?{openPopup:"compactStrokeStyles"}:{openPopup:null})},children:[se(ca.Trigger,{asChild:!0,children:se("button",{type:"button",className:Kn("compact-action-button properties-trigger",{active:s}),title:f("labels.stroke"),onClick:l=>{l.preventDefault(),l.stopPropagation(),o({openPopup:s?null:"compactStrokeStyles"})},children:uv})}),s&&se(gr,{className:t0,container:r,style:{maxWidth:"13rem"},onClose:()=>{},children:ke("div",{className:"selected-shape-actions",children:[a&&t("changeFillStyle"),(Kl(e.activeTool.type)||n.some(l=>Kl(l.type)))&&t("changeStrokeWidth"),(Xl(e.activeTool.type)||n.some(l=>Xl(l.type)))&&ke(Do,{children:[t("changeStrokeStyle"),t("changeSloppiness")]}),(Zl(e.activeTool.type)||n.some(l=>Zl(l.type)))&&t("changeRoundness"),t("changeOpacity")]})})]})}):null},qC=({appState:e,renderAction:t,setAppState:o,targetElements:n,container:r,app:a})=>{let i=Xp(e.activeTool.type)||n.some(l=>Xp(l.type)),s=e.openPopup==="compactArrowProperties";return i?se("div",{className:"compact-action-item",children:ke(ca.Root,{open:s,onOpenChange:l=>{o(l?{openPopup:"compactArrowProperties"}:{openPopup:null})},children:[se(ca.Trigger,{asChild:!0,children:se("button",{type:"button",className:Kn("compact-action-button properties-trigger",{active:s}),title:f("labels.arrowtypes"),onClick:l=>{l.preventDefault(),l.stopPropagation(),o({openPopup:s?null:"compactArrowProperties"})},children:(()=>{let l=Kt(n,a,c=>WC(c)?c.elbowed?"elbow":c.roundness?"round":"sharp":null,c=>WC(c),c=>c?null:e.currentItemArrowType);return l==="elbow"?ms:l==="round"?ps:ds})()})}),s&&se(gr,{container:r,className:"properties-content",style:{maxWidth:"13rem"},onClose:()=>{},children:t("changeArrowProperties")})]})}):null},JC=({appState:e,renderAction:t,setAppState:o,targetElements:n,container:r,elementsMap:a})=>{let{saveCaretPosition:i,restoreCaretPosition:s}=Nv(),l=e.openPopup==="compactTextProperties";return se("div",{className:"compact-action-item",children:ke(ca.Root,{open:l,onOpenChange:c=>{c?(e.editingTextElement&&i(),o({openPopup:"compactTextProperties"})):(o({openPopup:null}),e.editingTextElement&&s())},children:[se(ca.Trigger,{asChild:!0,children:se("button",{type:"button",className:Kn("compact-action-button properties-trigger",{active:l}),title:f("labels.textAlign"),onClick:c=>{c.preventDefault(),c.stopPropagation(),l?o({openPopup:null}):(e.editingTextElement&&i(),o({openPopup:"compactTextProperties"}))},children:FE})}),e.openPopup==="compactTextProperties"&&se(gr,{className:t0,container:r,style:{maxWidth:"13rem"},preventAutoFocusOnTouch:!!e.editingTextElement,onClose:()=>{e.editingTextElement&&s()},children:ke("div",{className:"selected-shape-actions",children:[(e.activeTool.type==="text"||n.some(Zp))&&t("changeFontSize"),(e.activeTool.type==="text"||KC(n,a))&&t("changeTextAlign"),VC(n,a)&&t("changeVerticalAlign")]})})]})})},QC=({appState:e,renderAction:t,targetElements:o,setAppState:n,container:r,app:a,showDuplicate:i,showDelete:s})=>{let l=!!(e.editingTextElement||e.newElement),c=!e.croppingElementId&&o.length===1&&XC(o[0]),m=o.length===1,p=ao(e,a),d=!1;o.length===2&&(Kp(o[0])||Kp(o[1]))&&(d=!0);let u=document.documentElement.getAttribute("dir")==="rtl",h=e.openPopup==="compactOtherProperties";return l||o.length===0?null:se("div",{className:"compact-action-item",children:ke(ca.Root,{open:h,onOpenChange:g=>{n(g?{openPopup:"compactOtherProperties"}:{openPopup:null})},children:[se(ca.Trigger,{asChild:!0,children:se("button",{type:"button",className:Kn("compact-action-button properties-trigger",{active:h}),title:f("labels.actions"),onClick:g=>{g.preventDefault(),g.stopPropagation(),n({openPopup:h?null:"compactOtherProperties"})},children:AE})}),h&&se(gr,{className:t0,container:r,style:{maxWidth:"12rem",justifyContent:"center",alignItems:"center"},onClose:()=>{},children:ke("div",{className:"selected-shape-actions",children:[ke("fieldset",{children:[se("legend",{children:f("labels.layers")}),ke("div",{className:"buttonList",children:[t("sendToBack"),t("sendBackward"),t("bringForward"),t("bringToFront")]})]}),p&&!d&&ke("fieldset",{children:[se("legend",{children:f("labels.align")}),ke("div",{className:"buttonList",children:[u?ke(Do,{children:[t("alignRight"),t("alignHorizontallyCentered"),t("alignLeft")]}):ke(Do,{children:[t("alignLeft"),t("alignHorizontallyCentered"),t("alignRight")]}),o.length>2&&t("distributeHorizontally"),se("div",{style:{flexBasis:"100%",height:0}}),ke("div",{style:{display:"flex",flexWrap:"wrap",gap:".5rem",marginTop:"-0.5rem"},children:[t("alignTop"),t("alignVerticallyCentered"),t("alignBottom"),o.length>2&&t("distributeVertically")]})]})]}),ke("fieldset",{children:[se("legend",{children:f("labels.actions")}),ke("div",{className:"buttonList",children:[t("group"),t("ungroup"),m&&t("hyperlink"),c&&t("cropEditor"),i&&t("duplicateSelection"),s&&t("deleteSelectedElements")]})]})]})})]})})},vO=({appState:e,renderAction:t,targetElements:o})=>!e.selectedLinearElement?.isEditing&&o.length===1&&e0(o[0])&&!Qb(o[0])?se("div",{className:"compact-action-item",children:t("toggleLinearEditor")}):null,e5=({appState:e,elementsMap:t,renderAction:o,app:n,setAppState:r})=>{let a=Hi(t,e),{container:i}=Qe(),s=!!(e.editingTextElement||e.newElement),l=!e.selectedLinearElement?.isEditing&&a.length===1&&e0(a[0])&&!Qb(a[0]);return ke("div",{className:"compact-shape-actions",children:[Kc(e,a)&&se("div",{className:Kn("compact-action-item"),children:o("changeStrokeColor")}),Xc(e,a)&&se("div",{className:"compact-action-item",children:o("changeBackgroundColor")}),se(jC,{appState:e,renderAction:o,setAppState:r,targetElements:a,container:i}),se(qC,{appState:e,renderAction:o,setAppState:r,targetElements:a,container:i,app:n}),l&&se("div",{className:"compact-action-item",children:o("toggleLinearEditor")}),(e.activeTool.type==="text"||a.some(Zp))&&ke(Do,{children:[se("div",{className:"compact-action-item",children:o("changeFontFamily")}),se(JC,{appState:e,renderAction:o,setAppState:r,targetElements:a,container:i,elementsMap:t})]}),!s&&a.length>0&&se("div",{className:"compact-action-item",children:o("duplicateSelection")}),!s&&a.length>0&&se("div",{className:"compact-action-item",children:o("deleteSelectedElements")}),se(QC,{appState:e,renderAction:o,targetElements:a,setAppState:r,container:i,app:n})]})},t5=({appState:e,elementsMap:t,renderAction:o,app:n,setAppState:r})=>{let a=Hi(t,e),{container:i}=Qe(),s=yO(null),l=s.current?.getBoundingClientRect()?.width??0,c=9,m=6,p=32,d=c*p+(c-1)*m,u=p+m,h=l>=d+u,g=l>=d+2*u;return ke(gt,{className:"compact-shape-actions mobile-shape-actions",style:{flexDirection:"row",boxShadow:"none",padding:0,zIndex:2,backgroundColor:"transparent",height:p*1.35,marginBottom:4,alignItems:"center",gap:m,pointerEvents:"none"},ref:s,children:[ke("div",{style:{display:"flex",flexDirection:"row",gap:m,flex:1},children:[Kc(e,a)&&se("div",{className:Kn("compact-action-item"),children:o("changeStrokeColor")}),Xc(e,a)&&se("div",{className:"compact-action-item",children:o("changeBackgroundColor")}),se(jC,{appState:e,renderAction:o,setAppState:r,targetElements:a,container:i}),se(qC,{appState:e,renderAction:o,setAppState:r,targetElements:a,container:i,app:n}),se(vO,{appState:e,renderAction:o,targetElements:a}),(e.activeTool.type==="text"||a.some(Zp))&&ke(Do,{children:[se("div",{className:"compact-action-item",children:o("changeFontFamily")}),se(JC,{appState:e,renderAction:o,setAppState:r,targetElements:a,container:i,elementsMap:t})]}),se(QC,{appState:e,renderAction:o,targetElements:a,setAppState:r,container:i,app:n,showDuplicate:!g,showDelete:!h})]}),ke("div",{style:{display:"flex",flexDirection:"row",gap:m},children:[se("div",{className:"compact-action-item",children:o("undo")}),se("div",{className:"compact-action-item",children:o("redo")}),g&&se("div",{className:"compact-action-item",children:o("duplicateSelection")}),h&&se("div",{className:"compact-action-item",children:o("deleteSelectedElements")})]})]})},o5=({activeTool:e,setAppState:t,app:o,UIOptions:n})=>{let[r,a]=EO(!1),i=Dt(),s=i==="full",l=i==="compact",c=[{type:"selection",icon:Ya,title:la(f("toolBar.selection"))},{type:"lasso",icon:Hr,title:la(f("toolBar.lasso"))}],m=e.type==="frame",p=e.type==="laser",d=s&&e.type==="lasso"&&o.state.preferredSelectionTool.type!=="lasso",u=e.type==="embeddable",{TTDDialogTriggerTunnel:h}=Ze();return ke(Do,{children:[Zb(o).map(({value:g,icon:x,key:E,numericKey:y,fillable:w,toolbar:v})=>{if(v===!1||n.tools?.[g]===!1)return null;let I=f(`toolBar.${g}`),C=E&&la(typeof E=="string"?E:E[0]),P=C?`${C} ${f("helpDialog.or")} ${y}`:`${y}`,S=g==="hand"?void 0:y||C;return(g==="selection"||g==="lasso")&&l?se(Qs,{app:o,options:c,activeTool:e,defaultOption:o.state.preferredSelectionTool.type,namePrefix:"selectionType",title:la(f("toolBar.selection")),"data-testid":"toolbar-selection",onToolChange:D=>{(D==="selection"||D==="lasso")&&(o.setActiveTool({type:D}),t({preferredSelectionTool:{type:D,initialized:!0}}))},displayedOption:c.find(D=>D.type===o.state.preferredSelectionTool.type)||c[0],fillable:e.type==="selection"},"selection-popover"):se(ie,{className:Kn("Shape",{fillable:w}),type:"radio",icon:x,checked:e.type===g,name:"editor-current-shape",title:`${la(I)} \u2014 ${P}`,keyBindingLabel:S,"aria-label":la(I),"aria-keyshortcuts":P,"data-testid":`toolbar-${g}`,onPointerDown:({pointerType:D})=>{!o.state.penDetected&&D==="pen"&&o.togglePenMode(!0),g==="selection"&&(o.state.activeTool.type==="selection"?o.setActiveTool({type:"lasso"}):o.setActiveTool({type:"selection"}))},onChange:({pointerType:D})=>{o.state.activeTool.type!==g&&be("toolbar",g,"ui"),g==="image"?o.setActiveTool({type:g}):o.setActiveTool({type:g})}},g)}),se("div",{className:"App-toolbar__divider"}),se(ie,{className:"Shape",type:"radio",icon:Uw,checked:!1,name:"editor-current-shape",title:"Image Generator \u2014 A",keyBindingLabel:"A","aria-label":"Image Generator","data-testid":"toolbar-image-generator",onChange:()=>{be("toolbar","imageGenerator","ui"),o.onImageGeneratorSelect()}}),se(ie,{className:"Shape",type:"radio",icon:On,checked:m,name:"editor-current-shape",title:`${la(f("toolBar.frame"))} \u2014 F`,keyBindingLabel:"F","aria-label":la(f("toolBar.frame")),"data-testid":"toolbar-frame",onChange:()=>{be("toolbar","frame","ui"),o.setActiveTool({type:"frame"})}}),ke(ye,{open:r,children:[se(ye.Trigger,{className:Kn("App-toolbar__extra-tools-trigger",{"App-toolbar__extra-tools-trigger--selected":u||d||p&&!o.props.isCollaborating}),onToggle:()=>{a(!r),t({openMenu:null,openPopup:null})},title:f("toolBar.extraTools"),children:u?os:p&&!o.props.isCollaborating?zn:d?Hr:ic}),ke(ye.Content,{onClickOutside:()=>a(!1),onSelect:()=>a(!1),className:"App-toolbar__extra-tools-dropdown",children:[se(ye.Item,{onSelect:()=>o.setActiveTool({type:"embeddable"}),icon:os,"data-testid":"toolbar-embeddable",selected:u,children:f("toolBar.embeddable")}),se(ye.Item,{onSelect:()=>o.setActiveTool({type:"laser"}),icon:zn,"data-testid":"toolbar-laser",selected:p,shortcut:wO.K.toLocaleUpperCase(),children:f("toolBar.laser")}),s&&se(ye.Item,{onSelect:()=>o.setActiveTool({type:"lasso"}),icon:Hr,"data-testid":"toolbar-lasso",selected:d,children:f("toolBar.lasso")}),se("div",{style:{margin:"6px 0",fontSize:14,fontWeight:600},children:"Generate"}),o.props.aiEnabled!==!1&&se(h.Out,{}),se(ye.Item,{onSelect:()=>o.setOpenDialog({name:"ttd",tab:"mermaid"}),icon:ss,"data-testid":"toolbar-mermaid",children:f("toolBar.mermaidToExcalidraw")}),o.props.aiEnabled!==!1&&o.plugins.diagramToCode&&se(ye.Item,{onSelect:()=>o.onMagicframeToolSelect(),icon:Ka,"data-testid":"toolbar-magicframe",badge:se(ye.Item.Badge,{children:"AI"}),children:f("toolBar.magicframe")})]})]})]})},n5=({renderAction:e})=>e("scrollBackToContent"),r5=({renderAction:e,zoom:t})=>ke(Rt.Row,{align:"center",className:$C.ZOOM_ACTIONS,children:[e("zoomOut"),e("resetZoom"),e("zoomIn")]}),a5=({renderAction:e,className:t})=>ke("div",{className:`undo-redo-buttons ${t}`,children:[se("div",{className:"undo-button-container",children:se(Xt,{label:f("buttons.undo"),children:e("undo")})}),se("div",{className:"redo-button-container",children:ke(Xt,{label:f("buttons.redo"),children:[" ",e("redo")]})})]}),i5=({actionManager:e,showExitZenModeBtn:t})=>se("button",{type:"button",className:Kn("disable-zen-mode",{"disable-zen-mode--visible":t}),onClick:()=>e.executeAction(ta),children:f("buttons.exitZenMode")}),s5=({actionManager:e})=>se("button",{type:"button",className:"disable-view-mode",onClick:()=>e.executeAction(ii),children:hv});import{useRef as IO}from"react";var o0=e=>{let t=IO({userFn:e});return t.current.userFn=e,t.current.stableFn||(t.current.stableFn=(...o)=>t.current.userFn(...o)),t.current.stableFn};import{jsx as CO,jsxs as TO}from"react/jsx-runtime";var si=Pe(null),l5=()=>{let[e,t]=le(si),o=at();return e&&e==="clearCanvas"?CO(Np,{onConfirm:()=>{o.executeAction(yr),t(null)},onCancel:()=>t(null),title:f("clearCanvasDialog.title"),children:TO("p",{className:"clear-canvas__content",children:[" ",f("alerts.clearReset")]})}):null};var n0={};eE(n0,{toggleTheme:()=>kO});var kO={...qa,category:"App",label:"Toggle theme",perform:({actionManager:e})=>{e.executeAction(qa,"commandPalette")}};import{jsx as Bt,jsxs as Xn}from"react/jsx-runtime";var LO=Pe(null),it={app:"App",export:"Export",tools:"Tools",editor:"Editor",elements:"Elements",links:"Links",library:"Library"},d5=e=>{switch(e){case it.app:return 1;case it.export:return 2;case it.editor:return 3;case it.tools:return 4;case it.elements:return 5;case it.links:return 6;default:return 10}},Jp=({shortcut:e,className:t,children:o})=>{let n=e.replace("++","+$").split("+");return Xn("div",{className:p5("shortcut",t),children:[n.map((r,a)=>Bt("div",{className:"shortcut-wrapper",children:Bt("div",{className:"shortcut-key",children:r==="$"?"+":r})},r)),Bt("div",{className:"shortcut-desc",children:o})]})},g5=e=>!e.altKey&&e[yn.CTRL_OR_CMD]&&(e.shiftKey&&e.key.toLowerCase()===yn.P||e.key===yn.SLASH),_O=Object.assign(e=>{let t=Ie(),o=Ce();return qp(()=>{let n=r=>{g5(r)&&(r.preventDefault(),r.stopPropagation(),o(a=>{let i=a.openDialog?.name==="commandPalette"?null:{name:"commandPalette"};return i&&be("command_palette","open","shortcut"),{openDialog:i}}))};return window.addEventListener(Qp.KEYDOWN,n,{capture:!0}),()=>window.removeEventListener(Qp.KEYDOWN,n,{capture:!0})},[o]),t.openDialog?.name!=="commandPalette"?null:Bt(DO,{...e})},{defaultItems:n0});function DO({customCommandPaletteItems:e}){let t=tt(),o=Ie(),n=Ce(),r=Hn(),a=at(),[i,s]=le(LO),[l,c]=jp(null),m=u5(null),p=Ur({uiAppState:o,customCommandPaletteItems:e,appProps:r}),[d]=le(wr),u=MO(()=>d.libraryItems?.filter(S=>!!S.name).map(S=>({label:S.name,icon:Bt(RO,{id:S.id,elements:S.elements}),category:"Library",order:d5("Library"),haystack:ri(S.name),perform:()=>{t.onInsertElements(Zs([S]))}}))||[],[t,d.libraryItems]);qp(()=>{let{uiAppState:S,customCommandPaletteItems:D,appProps:_}=p,k=N=>{let z="";return N.label&&(typeof N.label=="function"?z=f(N.label(t.scene.getNonDeletedElements(),S,t)):z=f(N.label)),z},M=N=>typeof N.icon=="function"?N.icon(S,t.scene.getNonDeletedElements()):N.icon,B=[],O=(N,z,L)=>{let F={label:k(N),icon:M(N),category:z,shortcut:Xe(N.name),keywords:N.keywords,predicate:N.predicate,viewMode:N.viewMode,perform:()=>{a.executeAction(N,"commandPalette")}};return L?L(F,N):F};if(S&&t.scene&&a){let N=[a.actions.group,a.actions.ungroup,a.actions.cut,a.actions.copy,a.actions.deleteSelectedElements,a.actions.wrapSelectionInFrame,a.actions.copyStyles,a.actions.pasteStyles,a.actions.bringToFront,a.actions.bringForward,a.actions.sendBackward,a.actions.sendToBack,a.actions.alignTop,a.actions.alignBottom,a.actions.alignLeft,a.actions.alignRight,a.actions.alignVerticallyCentered,a.actions.alignHorizontallyCentered,a.actions.duplicateSelection,a.actions.flipHorizontal,a.actions.flipVertical,a.actions.zoomToFitSelection,a.actions.zoomToFitSelectionInViewport,a.actions.increaseFontSize,a.actions.decreaseFontSize,a.actions.toggleLinearEditor,a.actions.cropEditor,a.actions.togglePolygon,Nc,Mp,ST].map(Z=>O(Z,it.elements,(U,q)=>({...U,predicate:q.predicate?q.predicate:(ae,J,te,ue)=>de(ae,J).length>0}))),z=[a.actions.toggleHandTool,a.actions.setFrameAsActiveTool,a.actions.toggleLassoTool].map(Z=>O(Z,it.tools)),L=[a.actions.undo,a.actions.redo,a.actions.zoomIn,a.actions.zoomOut,a.actions.resetZoom,a.actions.zoomToFit,a.actions.zenMode,a.actions.viewMode,a.actions.gridMode,a.actions.objectsSnapMode,a.actions.toggleShortcuts,a.actions.selectAll,a.actions.toggleElementLock,a.actions.unlockAllElements,a.actions.stats].map(Z=>O(Z,it.editor)),F=[a.actions.saveToActiveFile,a.actions.saveFileToDisk,a.actions.copyAsPng,a.actions.copyAsSvg].map(Z=>O(Z,it.export));B=[...N,...L,{label:k(yr),icon:M(yr),shortcut:Xe(yr.name),category:it.editor,keywords:["delete","destroy"],viewMode:!1,perform:()=>{Et.set(si,"clearCanvas")}},{label:f("buttons.exportImage"),category:it.export,icon:ym,shortcut:Xe("imageExport"),keywords:["export","image","png","jpeg","svg","clipboard","picture"],perform:()=>{n({openDialog:{name:"imageExport"}})}},...F];let $=[{label:f("toolBar.library"),category:it.app,icon:um,viewMode:!1,perform:()=>{S.openSidebar?n({openSidebar:null}):n({openSidebar:{name:c5.name,tab:c5.defaultTab}})}},{label:f("search.title"),category:it.app,icon:Mo,viewMode:!0,perform:()=>{a.executeAction(Zc)}},{label:f("labels.shapeSwitch"),category:it.elements,icon:sc,perform:()=>{a.executeAction(kT)}},{label:f("labels.changeStroke"),keywords:["color","outline"],category:it.elements,icon:xm,viewMode:!1,predicate:(Z,U)=>{let q=de(Z,U);return q.length>0&&Kc(U,q)},perform:()=>{n(Z=>({openPopup:"elementStroke"}))}},{label:f("labels.changeBackground"),keywords:["color","fill"],icon:xm,category:it.elements,viewMode:!1,predicate:(Z,U)=>{let q=de(Z,U);return q.length>0&&Xc(U,q)},perform:()=>{n(Z=>({openPopup:"elementBackground"}))}},{label:f("labels.canvasBackground"),keywords:["color"],icon:xm,category:it.editor,viewMode:!1,perform:()=>{n(Z=>({openMenu:Z.openMenu==="canvas"?null:"canvas",openPopup:"canvasBackground"}))}},...Yp.reduce((Z,U)=>{let{value:q,icon:ae,key:J,numericKey:te}=U;if(_.UIOptions.tools?.[q]===!1)return Z;let Me=J&&PO(typeof J=="string"?J:J[0])||te,ct={label:f(`toolBar.${q}`),category:it.tools,shortcut:Me,icon:ae,keywords:["toolbar"],viewMode:!1,perform:({event:Lt})=>{q==="image"?t.setActiveTool({type:q}):t.setActiveTool({type:q})}};return Z.push(ct),Z},[]),...z,{label:f("toolBar.lock"),category:it.tools,icon:S.activeTool.locked?ji:Wa,shortcut:yn.Q.toLocaleUpperCase(),viewMode:!1,perform:()=>{t.toggleLock()}},{label:`${f("labels.textToDiagram")}...`,category:it.tools,icon:Xw,viewMode:!1,predicate:_.aiEnabled,perform:()=>{n(Z=>({...Z,openDialog:{name:"ttd",tab:"text-to-diagram"}}))}},{label:`${f("toolBar.mermaidToExcalidraw")}...`,category:it.tools,icon:ss,viewMode:!1,predicate:_.aiEnabled,perform:()=>{n(Z=>({...Z,openDialog:{name:"ttd",tab:"mermaid"}}))}}],Q=[...B,...$,...D||[]].map(Z=>({...Z,icon:Z.icon||sc,order:Z.order??d5(Z.category),haystack:`${ri(Z.label.toLocaleLowerCase())} ${Z.keywords?.join(" ")||""}`}));c(Q),s([...Q,...u].find(Z=>Z.label===i?.label)??null)}},[p,t,a,c,i?.label,s,n,u]);let[h,g]=jp(""),[x,E]=jp(null),[y,w]=jp({}),v=S=>{n({openDialog:null},S),g("")},I=(S,D)=>{o.openDialog?.name==="commandPalette"&&(D.stopPropagation(),D.preventDefault(),document.body.classList.add("excalidraw-animations-disabled"),v(()=>{S.perform({actionManager:a,event:D}),s(S),requestAnimationFrame(()=>{document.body.classList.remove("excalidraw-animations-disabled")})}))},C=o0(S=>S.viewMode===!1&&o.viewModeEnabled?!1:typeof S.predicate=="function"?S.predicate(t.scene.getNonDeletedElements(),o,r,t):S.predicate===void 0||S.predicate),P=o0(S=>{let D=AO(S.target)||g5(S)||S.key===yn.ESCAPE;if(D&&S.key!==yn.ARROW_UP&&S.key!==yn.ARROW_DOWN&&S.key!==yn.ENTER)return;let _=Object.values(y).flat(),k=i&&!h&&C(i);if(S.key===yn.ARROW_UP){S.preventDefault();let M=_.findIndex(N=>N.label===x?.label);if(k){if(M===0){E(i);return}if(x===i){let N=_[_.length-1];N&&E(N);return}}let B;M===-1?B=_.length-1:B=M===0?_.length-1:(M-1)%_.length;let O=_[B];O&&E(O);return}if(S.key===yn.ARROW_DOWN){S.preventDefault();let M=_.findIndex(N=>N.label===x?.label);if(k){if(!x||M===_.length-1){E(i);return}if(x===i){let N=_[0];N&&E(N);return}}let B=(M+1)%_.length,O=_[B];O&&E(O);return}if(S.key===yn.ENTER&&x&&setTimeout(()=>{I(x,S)}),!D){if(S.stopPropagation(),/^[a-zA-Z0-9]$/.test(S.key)){m?.current?.focus();return}S.preventDefault()}});return qp(()=>(window.addEventListener(Qp.KEYDOWN,P,{capture:!0}),()=>window.removeEventListener(Qp.KEYDOWN,P,{capture:!0})),[P]),qp(()=>{if(!l)return;let S=M=>{let B={};for(let O of M)B[O.category]?B[O.category].push(O):B[O.category]=[O];return B},D=h?.length>1?[...l.filter(C).sort((M,B)=>M.order-B.order),...u]:l.filter(C).sort((M,B)=>M.order-B.order),_=!h&&i&&C(i);if(!h){w(S(_?D.filter(M=>M.label!==i?.label):D)),E(_?i:D[0]||null);return}let k=ri(h.toLocaleLowerCase().replace(/[<>_| -]/g,""));D=SO.filter(k,D,{extract:M=>M.haystack??""}).sort((M,B)=>B.score-M.score).map(M=>M.original),w(S(D)),E(D[0]??null)},[h,l,C,i,u]),Xn(bt,{onCloseRequest:()=>v(),closeOnClickOutside:!0,title:!1,size:720,autofocus:!0,className:"command-palette-dialog",children:[Bt(ia,{value:h,placeholder:f("commandPalette.search.placeholder"),onChange:S=>{g(S)},selectOnRender:!0,ref:m}),t.editorInterface.formFactor!=="phone"&&Xn("div",{className:"shortcuts-wrapper",children:[Bt(Jp,{shortcut:"\u2191\u2193",children:f("commandPalette.shortcuts.select")}),Bt(Jp,{shortcut:"\u21B5",children:f("commandPalette.shortcuts.confirm")}),Bt(Jp,{shortcut:G("Esc"),children:f("commandPalette.shortcuts.close")})]}),Xn("div",{className:"commands",children:[i&&!h&&Xn("div",{className:"command-category",children:[Xn("div",{className:"command-category-title",children:[f("commandPalette.recents"),Bt("div",{className:"icon",style:{marginLeft:"6px"},children:Zw})]}),Bt(m5,{command:i,isSelected:i.label===x?.label,onClick:S=>I(i,S),disabled:!C(i),onMouseMove:()=>E(i),showShortcut:t.editorInterface.formFactor!=="phone",appState:o})]}),Object.keys(y).length>0?Object.keys(y).map((S,D)=>Xn("div",{className:"command-category",children:[Bt("div",{className:"command-category-title",children:S}),y[S].map(_=>Bt(m5,{command:_,isSelected:_.label===x?.label,onClick:k=>I(_,k),onMouseMove:()=>E(_),showShortcut:t.editorInterface.formFactor!=="phone",appState:o,size:S==="Library"?"large":"small"},_.label))]},S)):l?Xn("div",{className:"no-match",children:[Bt("div",{className:"icon",children:Mo})," ",f("commandPalette.search.noMatch")]}):null]})]})}var RO=({id:e,elements:t})=>{let o=u5(null),{svgCache:n}=Ks();return Pp(e,t,n,o),Bt("div",{className:"library-item-icon",ref:o})},m5=({command:e,isSelected:t,disabled:o,onMouseMove:n,onClick:r,showShortcut:a,appState:i,size:s="small"})=>{let l=()=>{};return Xn("div",{className:p5("command-item",{"item-selected":t,"item-disabled":o,"command-item-large":s==="large"}),ref:c=>{t&&!o&&c?.scrollIntoView?.({block:"nearest"})},onClick:o?l:r,onMouseMove:o?l:n,title:o?f("commandPalette.itemNotAvailable"):"",children:[Xn("div",{className:"name",children:[e.icon&&Bt(Gn,{className:"icon",size:"var(--icon-size, 1rem)",icon:typeof e.icon=="function"?e.icon(i,[]):e.icon}),Bt(xc,{children:e.label})]}),a&&e.shortcut&&Bt(Jp,{shortcut:e.shortcut})]})};import{getSizeFromPoints as oSe,randomInteger as Nz,getUpdatedTimestamp as Bz}from"@orangecatai/common";import{simplify as Ez}from"points-on-curve";import{getStroke as wz}from"perfect-freehand";import{pointsOnBezierCurves as Uwe}from"points-on-curve";import{invariant as Ywe}from"@orangecatai/common";import{curve as Vwe,lineSegment as Kwe,pointFrom as Xwe,pointDistance as Zwe,pointFromArray as jwe,pointFromVector as qwe,pointRotateRads as Jwe,polygon as Qwe,polygonFromPoints as eve,PRECISION as tve,segmentsIntersectAt as ove,vector as nve,vectorAdd as rve,vectorFromPoint as ave,vectorScale as ive}from"@orangecatai/math";import{getElementAbsoluteCoords as lve}from"@orangecatai/element";var r0=e=>{if(!e)return[];for(let t of e.sets)if(t.type==="path")return t.ops;return e.sets[0].ops};import{pointFrom as vz,pointDistance as _5,pointRotateRads as G3e}from"@orangecatai/math";import{ROUGHNESS as Iz,THEME as v0,isTransparent as Qc,assertNever as Tz,COLOR_PALETTE as Cz,LINE_POLYGON_POINT_MERGE_DISTANCE as W3e,applyDarkModeFilter as cu}from"@orangecatai/common";import{RoughGenerator as kz}from"roughjs/bin/generator";import qke from"roughjs/bin/rough";import{isRightAngleRads as Qke,lineSegment as e3e,pointFrom as t3e,pointRotateRads as o3e}from"@orangecatai/math";import{BOUND_TEXT_PADDING as r3e,DEFAULT_REDUCED_GLOBAL_ALPHA as a3e,ELEMENT_READY_TO_ERASE_OPACITY as i3e,FRAME_STYLE as s3e,DARK_THEME_FILTER as l3e,MIME_TYPES as A5,THEME as c3e,distance as d3e,getFontString as m3e,isRTL as p3e,getVerticalOffset as u3e,invariant as g3e,applyDarkModeFilter as h3e,isSafari as f3e}from"@orangecatai/common";import c5e from"roughjs/bin/rough";import{arrayToMap as m5e,invariant as I5,rescalePoints as p5e,sizeOf as u5e}from"@orangecatai/common";import{degreesToRadians as f0,lineSegment as h5e,pointDistance as f5e,pointFrom as Yt,pointFromArray as oz,pointRotateRads as rl}from"@orangecatai/math";import{pointsOnBezierCurves as y5e}from"points-on-curve";import{pointCenter as TCe,pointFrom as CCe,pointRotateRads as kCe,pointsEqual as SCe,pointDistance as MCe,vectorFromPoint as PCe,curveLength as ACe,curvePointAtLength as LCe}from"@orangecatai/math";import{DRAGGING_THRESHOLD as RCe,KEYS as NCe,shouldRotateWithDiscreteAngle as BCe,getGridPoint as FCe,invariant as OCe,isShallowEqual as zCe,getFeatureFlag as HCe}from"@orangecatai/common";import{deconstructLinearOrFreeDrawElement as UCe,getSnapOutlineMidPoint as WCe,isPathALoop as YCe,moveArrowAboveBindable as $Ce,projectFixedPointOntoDiagonal as VCe}from"@orangecatai/element";import{KEYS as TTe,arrayToMap as CTe,getFeatureFlag as kTe,invariant as STe,isTransparent as MTe}from"@orangecatai/common";import{PRECISION as ATe,clamp as LTe,lineSegment as _Te,pointDistance as DTe,pointDistanceSq as RTe,pointFrom as NTe,pointFromVector as BTe,pointRotateRads as FTe,pointsEqual as OTe,vectorFromPoint as zTe,vectorNormalize as HTe,vectorScale as GTe}from"@orangecatai/math";import{invariant as j2e,isTransparent as q2e}from"@orangecatai/common";import{curveIntersectLineSegment as Q2e,isPointWithinBounds as eIe,lineSegment as tIe,lineSegmentIntersectionPoints as oIe,pointFrom as nIe,pointFromVector as rIe,pointRotateRads as aIe,pointsEqual as iIe,vectorFromPoint as sIe,vectorNormalize as lIe,vectorScale as cIe}from"@orangecatai/math";import{ellipse as mIe,ellipseSegmentInterceptPoints as pIe}from"@orangecatai/math/ellipse";import{DEFAULT_ADAPTIVE_RADIUS as FO,DEFAULT_PROPORTIONAL_RADIUS as i0,invariant as yve,LINE_CONFIRM_THRESHOLD as OO,ROUNDNESS as s0}from"@orangecatai/common";import{bezierEquation as wve,curve as vve,curveCatmullRomCubicApproxPoints as Ive,curveOffsetPoints as Tve,lineSegment as Cve,lineSegmentIntersectionPoints as kve,pointDistance as zO,pointFrom as Sve,pointFromArray as Mve,pointFromVector as Pve,pointRotateRads as Ave,pointTranslate as Lve,rectangle as _ve,vectorFromPoint as Dve,vectorNormalize as Rve,vectorScale as Nve}from"@orangecatai/math";import{ROUNDNESS as pve,assertNever as uve}from"@orangecatai/common";import{pointsEqual as hve}from"@orangecatai/math";var h5=e=>!!e&&e.type==="embeddable",f5=e=>!!e&&e.type==="iframe",a0=e=>!!e&&(e.type==="iframe"||e.type==="embeddable"),li=e=>e!=null&&e.type==="text";var eu=e=>e!=null&&(e.type==="frame"||e.type==="magicframe");var ci=e=>e!=null&&NO(e.type);var di=e=>e!=null&&e.type==="arrow",jc=e=>di(e)&&e.elbowed;var NO=e=>e==="arrow"||e==="line";var el=e=>e!==null&&"containerId"in e&&e.containerId!==null&&li(e);var tu=(e,t=1)=>{if(e.length>=3){let[o,n]=[e[0],e[e.length-1]];return zO(o,n)<=OO/t}return!1},qc=(e,t)=>{if(t.roundness?.type===s0.PROPORTIONAL_RADIUS||t.roundness?.type===s0.LEGACY)return e*i0;if(t.roundness?.type===s0.ADAPTIVE_RADIUS){let o=t.roundness?.value??FO,n=o/i0;return e<=n?e*i0:o}return 0};import{ARROW_LABEL_FONT_SIZE_TO_MIN_WIDTH_RATIO as y2e,ARROW_LABEL_WIDTH_FRACTION as E2e,BOUND_TEXT_PADDING as w2e,DEFAULT_FONT_SIZE as v2e,TEXT_ALIGN as I2e,VERTICAL_ALIGN as T2e,getFontString as C2e,isProdEnv as k2e,invariant as S2e}from"@orangecatai/common";import{pointFrom as P2e,pointRotateRads as A2e}from"@orangecatai/math";import{BOUND_TEXT_PADDING as jve,DEFAULT_FONT_SIZE as qve,DEFAULT_FONT_FAMILY as Jve,getFontString as Qve,isTestEnv as e2e,normalizeEOL as t2e}from"@orangecatai/common";var o2e="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".toLocaleUpperCase();import{isDevEnv as c2e,isTestEnv as d2e}from"@orangecatai/common";import{curvePointDistance as z2e,distanceToLineSegment as H2e,pointRotateRads as G2e}from"@orangecatai/math";import{ellipse as W2e,ellipseDistanceFromPoint as Y2e}from"@orangecatai/math/ellipse";import{invariant as kIe,isDevEnv as SIe,isTestEnv as MIe}from"@orangecatai/common";import{pointFrom as AIe,pointFromVector as LIe,pointRotateRads as _Ie,pointScaleFromOrigin as DIe,pointsEqual as RIe,triangleIncludesPoint as NIe,vectorCross as BIe,vectorFromPoint as ZO,vectorScale as FIe}from"@orangecatai/math";var g0=[1,0],y5=[0,1],h0=[-1,0],E5=[0,-1],ru=e=>{let[t,o]=e,n=Math.abs(t),r=Math.abs(o);return t>r?g0:t<=-r?h0:o>n?y5:E5},w5=(e,t)=>ru(ZO(e,t)),au=(e,t)=>iu(w5(e,t)),u0=(e,t)=>e[0]===t[0]&&e[1]===t[1],iu=e=>u0(e,g0)||u0(e,h0);import{clamp as WIe,pointDistance as YIe,pointFrom as $Ie,pointScaleFromOrigin as VIe,pointsEqual as KIe,pointTranslate as XIe,vector as ZIe,vectorCross as jIe,vectorFromPoint as qIe,vectorScale as JIe}from"@orangecatai/math";import{BinaryHeap as eTe,invariant as tTe,isAnyTrue as oTe,getSizeFromPoints as nTe,isDevEnv as rTe,arrayToMap as aTe}from"@orangecatai/common";var QTe=10/1.5;import{SHIFT_LOCKING_ANGLE as rCe,viewportCoordsToSceneCoords as aCe}from"@orangecatai/common";import{normalizeRadians as sCe,radiansBetweenAngles as lCe,radiansDifference as cCe}from"@orangecatai/math";import{pointsEqual as mCe}from"@orangecatai/math";var ou=e=>{let t=Math.floor(e.width/2)+1,o=0,n=e.width,r=Math.floor(e.height/2)+1,a=t,i=e.height;return[t,o,n,r,a,i,0,r]};var nz=e=>{switch(e){case"arrow":return 25;case"diamond":case"diamond_outline":return 12;case"crowfoot_many":case"crowfoot_one":case"crowfoot_one_or_many":return 20;default:return 15}},rz=e=>{switch(e){case"bar":return 90;case"arrow":return 20;default:return 25}},b0=(e,t,o,n)=>{if(t.length<1)return null;let r=r0(t[0]);if(r.length<1)return null;let a=o==="start"?1:r.length-1,i=r[a].data;I5(i.length===6,"Op data length is not 6");let s=Yt(i[4],i[5]),l=Yt(i[2],i[3]),c=Yt(i[0],i[1]),m=r[a-1],p=Yt(0,0);if(m.op==="move"){let N=oz(m.data);I5(N!=null,"Op data is not a point"),p=N}else m.op==="bcurveTo"&&(p=Yt(m.data[4],m.data[5]));let d=(N,z)=>Math.pow(1-N,3)*s[z]+3*N*Math.pow(1-N,2)*l[z]+3*Math.pow(N,2)*(1-N)*c[z]+p[z]*Math.pow(N,3),[u,h]=o==="start"?p:s,[g,x]=[d(.3,0),d(.3,1)],E=Math.hypot(u-g,h-x),y=(u-g)/E,w=(h-x)/E,v=nz(n),I=0;{let[N,z]=o==="end"?e.points[e.points.length-1]:e.points[0],[L,F]=e.points.length>1?o==="end"?e.points[e.points.length-2]:e.points[1]:[0,0];I=Math.hypot(N-L,z-F)}let P=Math.min(v,I*(n==="diamond"||n==="diamond_outline"?.25:.5)),S=u-y*P,D=h-w*P;if(n==="dot"||n==="circle"||n==="circle_outline"){let N=Math.hypot(D-h,S-u)+e.strokeWidth-2;return[u,h,N]}let _=rz(n);if(n==="crowfoot_many"||n==="crowfoot_one_or_many"){let[N,z]=rl(Yt(u,h),Yt(S,D),f0(-_)),[L,F]=rl(Yt(u,h),Yt(S,D),f0(_));return[S,D,N,z,L,F]}let[k,M]=rl(Yt(S,D),Yt(u,h),-_*Math.PI/180),[B,O]=rl(Yt(S,D),Yt(u,h),f0(_));if(n==="diamond"||n==="diamond_outline"){let N,z;if(o==="start"){let[L,F]=e.points.length>1?e.points[1]:[0,0];[N,z]=rl(Yt(u+P*2,h),Yt(u,h),Math.atan2(F-h,L-u))}else{let[L,F]=e.points.length>1?e.points[e.points.length-2]:[0,0];[N,z]=rl(Yt(u-P*2,h),Yt(u,h),Math.atan2(h-F,u-L))}return[u,h,k,M,N,z,B,O]}return[u,h,k,M,B,O]};import{pointFrom as D5e,pointCenter as R5e,pointRotateRads as N5e,vectorFromPoint as B5e,vectorNormalize as F5e,vectorSubtract as O5e,vectorAdd as z5e,vectorScale as H5e,pointFromVector as G5e,clamp as U5e,isCloseTo as W5e}from"@orangecatai/math";import{arrayToMap as Pke}from"@orangecatai/common";import{isPointWithinBounds as Lke,pointFrom as _ke}from"@orangecatai/math";import{vectorCross as X5e,vectorFromPoint as Z5e}from"@orangecatai/math";import{arrayToMap as az}from"@orangecatai/common";import{getElementBounds as iz}from"@orangecatai/element";import{isArrowElement as sz,isExcalidrawElement as lz,isFreeDrawElement as cz,isLinearElement as dz,isTextElement as mz}from"@orangecatai/element";import{rangeIncludesValue as su,pointFrom as Cr,pointRotateRads as pz,rangeInclusive as lu}from"@orangecatai/math";var uz=e=>e.type==="diamond"?[Cr(e.width/2,0),Cr(e.width,e.height/2),Cr(e.width/2,e.height),Cr(0,e.height/2)]:[Cr(0,0),Cr(0+e.width,0),Cr(0+e.width,e.height),Cr(0,e.height)],gz=e=>dz(e)||cz(e)?e.points:uz(e),C5=e=>{let t=e.reduce((o,[n,r])=>(o.minY=Math.min(o.minY,r),o.minX=Math.min(o.minX,n),o.maxX=Math.max(o.maxX,n),o.maxY=Math.max(o.maxY,r),o),{minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0,cx:0,cy:0});return t.cx=(t.maxX+t.minX)/2,t.cy=(t.maxY+t.minY)/2,t},k5=e=>{let t=gz(e),{cx:o,cy:n}=C5(t),r=Cr(o,n),a=t.map(m=>pz(m,r,e.angle)),{minX:i,minY:s,maxX:l,maxY:c}=C5(a);return[i+e.x,s+e.y,l+e.x,c+e.y]},x0=(e,t,o=!1)=>{let n=k5(e),r=t[0]<=n[0]&&t[2]>=n[2]&&t[1]<=n[1]&&t[3]>=n[3];return o?r?!0:n[0]<=t[0]&&n[2]>=t[2]&&n[1]<=t[1]&&n[3]>=t[3]:r},S5=(e,t)=>{let o=k5(e);return(su(o[0],lu(t[0],t[2]))||su(t[0],lu(o[0],o[2])))&&(su(o[1],lu(t[1],t[3]))||su(t[1],lu(o[1],o[3])))},M5=({elements:e,bounds:t,type:o,errorMargin:n=0})=>{lz(t)&&(t=iz(t,az(e)));let r=[t[0]-n,t[1]-n,t[2]+n,t[3]+n],a=new Set;for(let i of e){if(a.has(i.id))continue;if(o==="overlap"?S5(i,r):o==="inside"?x0(i,r):x0(i,r,!0)){if(a.add(i.id),i.boundElements)for(let l of i.boundElements)a.add(l.id);mz(i)&&i.containerId&&a.add(i.containerId),sz(i)&&(i.startBinding&&a.add(i.startBinding.elementId),i.endBinding&&a.add(i.endBinding?.elementId))}}return e.filter(i=>a.has(i.id))};import{arrayToMap as mke,isShallowEqual as fz}from"@orangecatai/common";var hz=function(){let e=null,t=null,o=null,n=(a,i,s,l)=>{if(o!==void 0&&i===t&&a===e&&s.editingGroupId===o?.editingGroupId)return o;let c={};for(let d of a){let u=d.groupIds;if(s.editingGroupId){let h=u.indexOf(s.editingGroupId);h>-1&&(u=u.slice(0,h))}if(u.length>0){let h=u[u.length-1];c[h]=!0}}let m={},p=i.reduce((d,u)=>{if(u.isDeleted)return d;let h=u.groupIds.find(g=>c[g]);return h&&(d[u.id]=!0,Array.isArray(m[h])?m[h].push(u.id):m[h]=[u.id]),d},{});for(let d of Object.keys(m))m[d].length<2&&c[d]&&(c[d]=!1);return t=i,e=a,o={editingGroupId:s.editingGroupId,selectedGroupIds:c,selectedElementIds:y0({...s.selectedElementIds,...p},l)},o},r=(a,i,s,l)=>{let c=l?l.scene.getSelectedElements({selectedElementIds:a.selectedElementIds,elements:i}):E0(i,a);return c.length?n(c,i,a,s):{selectedGroupIds:{},editingGroupId:null,selectedElementIds:y0(a.selectedElementIds,s)}};return r.clearCache=()=>{t=null,e=null,o=null},r}();var xke=function(){let e=null,t=null,o=null,n=(r,a)=>(o!=null&&r===e&&a.selectedElementIds===t||(o=r.some(i=>a.selectedElementIds[i.id]),e=r,t=a.selectedElementIds),o);return n.clearCache=()=>{e=null,t=null,o=null},n}(),E0=(e,t,o)=>{let n=new Set,r=[];for(let a of e.values()){if(t.selectedElementIds[a.id]){r.push(a),n.add(a.id);continue}if(o?.includeBoundTextElement&&el(a)&&t.selectedElementIds[a?.containerId]){r.push(a),n.add(a.id);continue}}if(o?.includeElementsInFrames){let a=[];return r.forEach(i=>{eu(i)&&P5(e,i.id).forEach(s=>!n.has(s.id)&&a.push(s)),a.push(i)}),a}return r};var y0=(e,t)=>fz(t.selectedElementIds,e)?t.selectedElementIds:e;var P5=(e,t)=>{let o=[];for(let n of e.values())n.frameId===t&&o.push(n);return o};var xz=typeof document<"u"?document.createElement("img"):{src:""};xz.src=`data:${A5.svg},${encodeURIComponent('<svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="image" class="svg-inline--fa fa-image fa-w-16" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="#888" d="M464 448H48c-26.51 0-48-21.49-48-48V112c0-26.51 21.49-48 48-48h416c26.51 0 48 21.49 48 48v288c0 26.51-21.49 48-48 48zM112 120c-30.928 0-56 25.072-56 56s25.072 56 56 56 56-25.072 56-56-25.072-56-56-56zM64 384h384V272l-87.515-87.515c-4.686-4.686-12.284-4.686-16.971 0L208 320l-55.515-55.515c-4.686-4.686-12.284-4.686-16.971 0L64 336v48z"></path></svg>')}`;var yz=typeof document<"u"?document.createElement("img"):{src:""};yz.src=`data:${A5.svg},${encodeURIComponent('<svg viewBox="0 0 668 668" xmlns="http://www.w3.org/2000/svg" xml:space="preserve" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2"><path d="M464 448H48c-26.51 0-48-21.49-48-48V112c0-26.51 21.49-48 48-48h416c26.51 0 48 21.49 48 48v288c0 26.51-21.49 48-48 48ZM112 120c-30.928 0-56 25.072-56 56s25.072 56 56 56 56-25.072 56-56-25.072-56-56-56ZM64 384h384V272l-87.515-87.515c-4.686-4.686-12.284-4.686-16.971 0L208 320l-55.515-55.515c-4.686-4.686-12.284-4.686-16.971 0L64 336v48Z" style="fill:#888;fill-rule:nonzero" transform="matrix(.81709 0 0 .81709 124.825 145.825)"/><path d="M256 8C119.034 8 8 119.033 8 256c0 136.967 111.034 248 248 248s248-111.034 248-248S392.967 8 256 8Zm130.108 117.892c65.448 65.448 70 165.481 20.677 235.637L150.47 105.216c70.204-49.356 170.226-44.735 235.638 20.676ZM125.892 386.108c-65.448-65.448-70-165.481-20.677-235.637L361.53 406.784c-70.203 49.356-170.226 44.736-235.638-20.676Z" style="fill:#888;fill-rule:nonzero" transform="matrix(.30366 0 0 .30366 506.822 60.065)"/></svg>')}`;var w0=new WeakMap;var L5=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="line"||e==="diamond"||e==="image";var xo=class xo{};A(xo,"rg",new kz),A(xo,"cache",new WeakMap),A(xo,"get",(t,o)=>{let n=xo.cache.get(t);if(n&&(o===null||n.theme===o))return n.shape}),A(xo,"delete",t=>{xo.cache.delete(t),w0.delete(t)}),A(xo,"destroy",()=>{xo.cache=new WeakMap}),A(xo,"generateElementShape",(t,o)=>{let n=o?.isExporting?void 0:xo.get(t,o?o.theme:null);if(n!==void 0)return n;w0.delete(t);let r=Pz(t,xo.rg,o||{isExporting:!1,canvasBackgroundColor:Cz.white,embedsValidationStatus:null,theme:v0.LIGHT});return o?.isExporting||xo.cache.set(t,{shape:r,theme:o?.theme||v0.LIGHT}),r});var nl=xo,Sz=e=>[8,8+e],B5=e=>[1.5,6+e];function Mz(e){let t=e.roughness,o=Math.max(e.width,e.height),n=Math.min(e.width,e.height);return n>=20&&o>=50||n>=15&&e.roundness&&L5(e.type)||ci(e)&&o>=50?t:Math.min(t/(o<10?3:2),2.5)}var Tr=(e,t=!1,o=!1)=>{let n={seed:e.seed,strokeLineDash:e.strokeStyle==="dashed"?Sz(e.strokeWidth):e.strokeStyle==="dotted"?B5(e.strokeWidth):void 0,disableMultiStroke:e.strokeStyle!=="solid",strokeWidth:e.strokeStyle!=="solid"?e.strokeWidth+.5:e.strokeWidth,fillWeight:e.strokeWidth/2,hachureGap:e.strokeWidth*4,roughness:Mz(e),stroke:o?cu(e.strokeColor):e.strokeColor,preserveVertices:t||e.roughness<Iz.cartoonist};switch(e.type){case"rectangle":case"iframe":case"embeddable":case"diamond":case"ellipse":return n.fillStyle=e.fillStyle,n.fill=Qc(e.backgroundColor)?void 0:o?cu(e.backgroundColor):e.backgroundColor,e.type==="ellipse"&&(n.curveFitting=1),n;case"line":case"freedraw":return tu(e.points)&&(n.fillStyle=e.fillStyle,n.fill=e.backgroundColor==="transparent"?void 0:o?cu(e.backgroundColor):e.backgroundColor),n;case"arrow":return n;default:throw new Error(`Unimplemented type ${e.type}`)}},D5=(e,t,o)=>a0(e)&&(t||h5(e)&&o?.get(e.id)!==!0)&&Qc(e.backgroundColor)&&Qc(e.strokeColor)?{...e,roughness:0,backgroundColor:"#d3d3d3",fillStyle:"solid"}:f5(e)?{...e,strokeColor:Qc(e.strokeColor)?"#000000":e.strokeColor,backgroundColor:Qc(e.backgroundColor)?"#f4f4f6":e.backgroundColor}:e,R5=(e,t,o,n,r,a,i,s)=>{let l=b0(e,t,o,n);if(l===null)return[];let c=(p,d)=>{if(p===null)return[];let[,,u,h,g,x]=p;return[r.line(u,h,g,x,d)]},m=s?cu(e.strokeColor):e.strokeColor;switch(n){case"dot":case"circle":case"circle_outline":{let[p,d,u]=l;return delete a.strokeLineDash,[r.circle(p,d,u,{...a,fill:n==="circle_outline"?i:m,fillStyle:"solid",stroke:m,roughness:Math.min(.5,a.roughness||0)})]}case"triangle":case"triangle_outline":{let[p,d,u,h,g,x]=l;return delete a.strokeLineDash,[r.polygon([[p,d],[u,h],[g,x],[p,d]],{...a,fill:n==="triangle_outline"?i:m,fillStyle:"solid",roughness:Math.min(1,a.roughness||0)})]}case"diamond":case"diamond_outline":{let[p,d,u,h,g,x,E,y]=l;return delete a.strokeLineDash,[r.polygon([[p,d],[u,h],[g,x],[E,y],[p,d]],{...a,fill:n==="diamond_outline"?i:m,fillStyle:"solid",roughness:Math.min(1,a.roughness||0)})]}case"crowfoot_one":return c(l,a);case"bar":case"arrow":case"crowfoot_many":case"crowfoot_one_or_many":default:{let[p,d,u,h,g,x]=l;if(e.strokeStyle==="dotted"){let E=B5(e.strokeWidth-1);a.strokeLineDash=[E[0],E[1]-1]}else delete a.strokeLineDash;return a.roughness=Math.min(1,a.roughness||0),[r.line(u,h,p,d,a),r.line(g,x,p,d,a),...n==="crowfoot_one_or_many"?c(b0(e,t,o,"crowfoot_one"),a):[]]}}};var Pz=(e,t,{isExporting:o,canvasBackgroundColor:n,embedsValidationStatus:r,theme:a})=>{let i=a===v0.DARK;switch(e.type){case"rectangle":case"iframe":case"embeddable":{let s;if(e.roundness){let l=e.width,c=e.height,m=qc(Math.min(l,c),e);s=t.path(`M ${m} 0 L ${l-m} 0 Q ${l} 0, ${l} ${m} L ${l} ${c-m} Q ${l} ${c}, ${l-m} ${c} L ${m} ${c} Q 0 ${c}, 0 ${c-m} L 0 ${m} Q 0 0, ${m} 0`,Tr(D5(e,o,r),!0,i))}else s=t.rectangle(0,0,e.width,e.height,Tr(D5(e,o,r),!1,i));return s}case"diamond":{let s,[l,c,m,p,d,u,h,g]=ou(e);if(e.roundness){let x=qc(Math.abs(l-h),e),E=qc(Math.abs(p-c),e);s=t.path(`M ${l+x} ${c+E} L ${m-x} ${p-E}
|
|
8
8
|
C ${m} ${p}, ${m} ${p}, ${m-x} ${p+E}
|
|
9
9
|
L ${d+x} ${u-E}
|
|
10
10
|
C ${d} ${u}, ${d} ${u}, ${d-x} ${u-E}
|
|
11
11
|
L ${h+x} ${g+E}
|
|
12
12
|
C ${h} ${g}, ${h} ${g}, ${h+x} ${g-E}
|
|
13
13
|
L ${l-x} ${c+E}
|
|
14
|
-
C ${l} ${c}, ${l} ${c}, ${l+x} ${c+E}`,Tr(e,!0,i))}else s=t.polygon([[l,c],[m,p],[d,u],[h,g]],Tr(e,!1,i));return s}case"ellipse":return t.ellipse(e.width/2,e.height/2,e.width,e.height,Tr(e,!1,i));case"line":case"arrow":{let s,l=Tr(e,!1,i),c=e.points.length?e.points:[vz(0,0)];if(jc(e)?c.every(m=>Math.abs(m[0])<=1e6&&Math.abs(m[1])<=1e6)?s=[t.path(Az(c,16),Tr(e,!0,i))]:(console.error("Elbow arrow with extreme point positions detected. Arrow not rendered.",e.id,JSON.stringify(c)),s=[]):e.roundness?s=[t.curve(c,l)]:l.fill?s=[t.polygon(c,l)]:s=[t.linearPath(c,l)],e.type==="arrow"){let{startArrowhead:m=null,endArrowhead:p="arrow"}=e;if(m!==null){let d=R5(e,s,"start",m,t,l,n,i);s.push(...d)}if(p!==null){let d=R5(e,s,"end",p,t,l,n,i);s.push(...d)}}return s}case"freedraw":{let s=[];if(tu(e.points)){let l=Ez(e.points,.75);s.push(t.curve(l,{...Tr(e,!1,i),stroke:"none"}))}return s.push(Lz(e)),s}case"frame":case"magicframe":case"text":case"image":return null;default:return Tz(e,`generateElementShape(): Unimplemented type ${e?.type}`),null}},Az=(e,t)=>{let o=[];for(let r=1;r<e.length-1;r+=1){let a=e[r-1],i=e[r+1],s=e[r],l=au(s,a),c=au(i,s),m=Math.min(t,_5(e[r],i)/2,_5(e[r],a)/2);l?a[0]<s[0]?o.push([e[r][0]-m,e[r][1]]):o.push([e[r][0]+m,e[r][1]]):a[1]<s[1]?o.push([e[r][0],e[r][1]-m]):o.push([e[r][0],e[r][1]+m]),o.push(e[r]),c?i[0]<s[0]?o.push([e[r][0]-m,e[r][1]]):o.push([e[r][0]+m,e[r][1]]):i[1]<s[1]?o.push([e[r][0],e[r][1]-m]):o.push([e[r][0],e[r][1]+m])}let n=[`M ${e[0][0]} ${e[0][1]}`];for(let r=0;r<o.length;r+=3)n.push(`L ${o[r][0]} ${o[r][1]}`),n.push(`Q ${o[r+1][0]} ${o[r+1][1]}, ${o[r+2][0]} ${o[r+2][1]}`);return n.push(`L ${e[e.length-1][0]} ${e[e.length-1][1]}`),n.join(" ")};var Lz=e=>Rz(_z(e)),_z=e=>{let t=e.simulatePressure?e.points:e.points.length?e.points.map(([o,n],r)=>[o,n,e.pressures[r]]):[[0,0,.5]];return wz(t,{simulatePressure:e.simulatePressure,size:e.strokeWidth*4.25,thinning:.6,smoothing:.5,streamline:.5,easing:o=>Math.sin(o*Math.PI/2),last:!0})},N5=(e,t)=>[(e[0]+t[0])/2,(e[1]+t[1])/2],Dz=/(\s?[A-Z]?,?-?[0-9]*\.[0-9]{0,2})(([0-9]|e|-)*)/g,Rz=e=>{if(!e.length)return"";let t=e.length-1;return e.reduce((o,n,r,a)=>(r===t?o.push(n,N5(n,a[0]),"L",a[0],"Z"):o.push(n,N5(n,a[r+1])),o),["M",e[0],"Q"]).join(" ").replace(Dz,"$1")};var F5=(e,t,o=!1)=>{let n=!1;for(let r in t){let a=t[r];if(typeof a<"u"){if(e[r]===a&&(typeof a!="object"||a===null))continue;n=!0}}return!n&&!o?e:{...e,...t,version:t.version??e.version+1,versionNonce:t.versionNonce??Nz(),updated:Bz()}};import{jsx as z5}from"react/jsx-runtime";var il=W({name:"toggleLinearEditor",category:it.elements,label:(e,t,o)=>o.scene.getSelectedElements({selectedElementIds:t.selectedElementIds})[0]?.type==="arrow"?"labels.lineEditor.editArrow":"labels.lineEditor.edit",keywords:["line"],trackEvent:{category:"element"},predicate:(e,t,o,n)=>{let r=n.scene.getSelectedElements(t);return!!(!t.selectedLinearElement?.isEditing&&r.length===1&&Oz(r[0])&&!Fz(r[0]))},perform(e,t,o,n){let r=n.scene.getSelectedElements({selectedElementIds:t.selectedElementIds,includeBoundTextElement:!0})[0];I0(r,"No selected element found"),I0(t.selectedLinearElement,"No selected linear element found"),I0(r.id===t.selectedLinearElement.elementId,"Selected element ID and linear editor elementId does not match");let a={...t.selectedLinearElement,isEditing:!t.selectedLinearElement.isEditing};return{appState:{...t,selectedLinearElement:a},captureUpdate:O5.IMMEDIATELY}},PanelComponent:({appState:e,updateData:t,app:o})=>{let n=o.scene.getSelectedElements({selectedElementIds:e.selectedElementIds})[0];if(!n)return null;let r=f(n.type==="arrow"?"labels.lineEditor.editArrow":"labels.lineEditor.edit");return z5(ae,{type:"button",icon:dv,title:r,"aria-label":r,onClick:()=>t(null)})}}),xSe=W({name:"togglePolygon",category:it.elements,icon:hh,keywords:["loop"],label:(e,t,o)=>!o.scene.getSelectedElements({selectedElementIds:t.selectedElementIds}).some(a=>!al(a)||!a.polygon)?"labels.polygon.breakPolygon":"labels.polygon.convertToPolygon",trackEvent:{category:"element"},predicate:(e,t,o,n)=>{let r=n.scene.getSelectedElements({selectedElementIds:t.selectedElementIds});return r.length>0&&r.every(a=>al(a)&&a.points.length>=4)},perform(e,t,o,n){let r=n.scene.getSelectedElements(t);if(r.some(l=>!al(l)))return!1;let a=r,i=a.some(l=>!l.polygon),s=zz(a);return{elements:e.map(l=>!s.has(l.id)||!al(l)?l:F5(l,{backgroundColor:i?l.backgroundColor:"transparent",...Hz(l,i)})),appState:t,captureUpdate:O5.IMMEDIATELY}},PanelComponent:({appState:e,updateData:t,app:o})=>{let n=o.scene.getSelectedElements({selectedElementIds:e.selectedElementIds});if(n.length===0||n.some(i=>!al(i)||!i.polygon||i.points.length<3))return null;let r=n.every(i=>al(i)&&i.polygon),a=f(r?"labels.polygon.breakPolygon":"labels.polygon.convertToPolygon");return z5(hs,{icon:hh,title:a,"aria-label":a,active:r,onClick:()=>t(null),style:{marginLeft:"auto"}})}});import{KEYS as H5,CANVAS_SEARCH_TAB as G5,CLASSES as Gz,DEFAULT_SIDEBAR as U5}from"@orangecatai/common";import{CaptureUpdateAction as Uz}from"@orangecatai/element";var Zc=W({name:"searchMenu",icon:Mo,keywords:["search","find"],label:"search.title",viewMode:!0,trackEvent:{category:"search_menu",action:"toggle",predicate:e=>e.gridModeEnabled},perform(e,t,o,n){if(t.openDialog)return!1;if(t.openSidebar?.name===U5.name&&t.openSidebar.tab===G5){let r=n.excalidrawContainerValue.container?.querySelector(`.${Gz.SEARCH_MENU_INPUT_WRAPPER} input`);return r?.focus(),r?.select(),!1}return{appState:{...t,openSidebar:{name:U5.name,tab:G5},openDialog:null},captureUpdate:Uz.EVENTUALLY}},checked:e=>e.gridModeEnabled,predicate:(e,t,o)=>o.gridModeEnabled===void 0,keyTest:e=>e[H5.CTRL_OR_CMD]&&e.key===H5.F});import{isImageElement as Wz}from"@orangecatai/element";import{CaptureUpdateAction as Yz}from"@orangecatai/element";import{jsx as $z}from"react/jsx-runtime";var ed=W({name:"cropEditor",label:"helpDialog.cropStart",icon:Fh,viewMode:!0,trackEvent:{category:"menu"},keywords:["image","crop"],perform(e,t,o,n){let r=n.scene.getSelectedElements({selectedElementIds:t.selectedElementIds,includeBoundTextElement:!0})[0];return{appState:{...t,isCropping:!1,croppingElementId:r.id},captureUpdate:Yz.IMMEDIATELY}},predicate:(e,t,o,n)=>{let r=n.scene.getSelectedElements(t);return!!(!t.croppingElementId&&r.length===1&&Wz(r[0]))},PanelComponent:({appState:e,updateData:t,app:o})=>{let n=f("helpDialog.cropStart");return $z(ae,{type:"button",icon:Fh,title:n,"aria-label":n,onClick:()=>t(null)})}});import{getNonDeletedElements as Vz}from"@orangecatai/element";import{mutateElement as Kz}from"@orangecatai/element";import{newFrameElement as Xz}from"@orangecatai/element";import{isFrameLikeElement as du}from"@orangecatai/element";import{addElementsToFrame as Zz,removeAllElementsFromFrame as jz}from"@orangecatai/element";import{getFrameChildren as qz}from"@orangecatai/element";import{KEYS as W5,updateActiveTool as Y5}from"@orangecatai/common";import{getElementsInGroup as Jz}from"@orangecatai/element";import{getCommonBounds as Qz}from"@orangecatai/element";import{CaptureUpdateAction as mi}from"@orangecatai/element";var $5=(e,t)=>{let o=t.scene.getSelectedElements(e);return o.length===1&&du(o[0])},V5=W({name:"selectAllElementsInFrame",label:"labels.selectAllElementsInFrame",trackEvent:{category:"canvas"},perform:(e,t,o,n)=>{let r=n.scene.getSelectedElements(t).at(0)||null;if(du(r)){let a=qz(Vz(e),r.id).filter(i=>!(i.type==="text"&&i.containerId));return{elements:e,appState:{...t,selectedElementIds:a.reduce((i,s)=>(i[s.id]=!0,i),{})},captureUpdate:mi.IMMEDIATELY}}return{elements:e,appState:t,captureUpdate:mi.EVENTUALLY}},predicate:(e,t,o,n)=>$5(t,n)}),K5=W({name:"removeAllElementsFromFrame",label:"labels.removeAllElementsFromFrame",trackEvent:{category:"history"},perform:(e,t,o,n)=>{let r=n.scene.getSelectedElements(t).at(0)||null;return du(r)?{elements:jz(e,r),appState:{...t,selectedElementIds:{[r.id]:!0}},captureUpdate:mi.IMMEDIATELY}:{elements:e,appState:t,captureUpdate:mi.EVENTUALLY}},predicate:(e,t,o,n)=>$5(t,n)}),SMe=W({name:"updateFrameRendering",label:"labels.updateFrameRendering",viewMode:!0,trackEvent:{category:"canvas"},perform:(e,t)=>({elements:e,appState:{...t,frameRendering:{...t.frameRendering,enabled:!t.frameRendering.enabled}},captureUpdate:mi.EVENTUALLY}),checked:e=>e.frameRendering.enabled}),MMe=W({name:"setFrameAsActiveTool",label:"toolBar.frame",trackEvent:{category:"toolbar"},icon:On,viewMode:!1,perform:(e,t,o,n)=>{let r=Y5(t,{type:"frame"});return Ao(n.interactiveCanvas,{...t,activeTool:r}),{elements:e,appState:{...t,activeTool:Y5(t,{type:"frame"})},captureUpdate:mi.EVENTUALLY}},keyTest:e=>!e[W5.CTRL_OR_CMD]&&!e.shiftKey&&!e.altKey&&e.key.toLocaleLowerCase()===W5.F}),X5=W({name:"wrapSelectionInFrame",label:"labels.wrapSelectionInFrame",trackEvent:{category:"element"},predicate:(e,t,o,n)=>{let r=de(e,t);return r.length>0&&!r.some(a=>du(a))},perform:(e,t,o,n)=>{let r=de(e,t),a=n.scene.getNonDeletedElementsMap(),[i,s,l,c]=Qz(r,a),m=16,p=Xz({x:i-m,y:s-m,width:l-i+m*2,height:c-s+m*2});if(t.editingGroupId){let u=Jz(r,t.editingGroupId);for(let h of u){let g=h.groupIds.indexOf(t.editingGroupId);Kz(h,a,{groupIds:h.groupIds.slice(0,g)})}}return{elements:Zz([...n.scene.getElementsIncludingDeleted(),p],r,p,t),appState:{selectedElementIds:{[p.id]:!0}},captureUpdate:mi.IMMEDIATELY}}});import{isWindows as iH,KEYS as od,matchKey as k0,arrayToMap as Z5,MOBILE_ACTION_BUTTON_BG as j5}from"@orangecatai/common";import{CaptureUpdateAction as C0}from"@orangecatai/element";import{orderByFractionalIndex as sH}from"@orangecatai/element";import{Emitter as eH}from"@orangecatai/common";import{CaptureUpdateAction as tH,StoreChange as oH,StoreDelta as nH}from"@orangecatai/element";var sl=class extends nH{applyTo(t,o,n){let[r,a]=this.elements.applyTo(t,n.elements,{excludedProperties:new Set(["version","versionNonce"])}),[i,s]=this.appState.applyTo(o,r);return[r,i,a||s]}static calculate(t,o){return super.calculate(t,o)}static inverse(t){return super.inverse(t)}static applyLatestChanges(t,o,n,r){return super.applyLatestChanges(t,o,n,r)}},pi=class{constructor(t=!0,o=!0){this.isUndoStackEmpty=t;this.isRedoStackEmpty=o}},td=class e{constructor(t){this.store=t;A(this,"onHistoryChangedEmitter",new eH);A(this,"undoStack",[]);A(this,"redoStack",[])}get isUndoStackEmpty(){return this.undoStack.length===0}get isRedoStackEmpty(){return this.redoStack.length===0}clear(){this.undoStack.length=0,this.redoStack.length=0}record(t){if(t.isEmpty()||t instanceof sl)return;let o=sl.inverse(t);this.undoStack.push(o),o.elements.isEmpty()||(this.redoStack.length=0),this.onHistoryChangedEmitter.trigger(new pi(this.isUndoStackEmpty,this.isRedoStackEmpty))}undo(t,o){return this.perform(t,o,()=>e.pop(this.undoStack),n=>e.push(this.redoStack,n))}redo(t,o){return this.perform(t,o,()=>e.pop(this.redoStack),n=>e.push(this.undoStack,n))}perform(t,o,n,r){try{let a=n();if(a===null)return;let i=tH.IMMEDIATELY,s=this.store.snapshot,l=t,c=o,m=!1;for(;a;){try{[l,c,m]=a.applyTo(l,c,s);let p=s.elements,d=s.maybeClone(i,l,c),u=oH.create(s,d),h=sl.applyLatestChanges(a,p,l);h.isEmpty()||(this.store.scheduleMicroAction({action:i,change:u,delta:h}),a=h),s=d}finally{r(a)}if(m)break;a=n()}return[l,c]}finally{this.onHistoryChangedEmitter.trigger(new pi(this.isUndoStackEmpty,this.isRedoStackEmpty))}}static pop(t){if(!t.length)return null;let o=t.pop();return o!==void 0?o:null}static push(t,o){let n=sl.inverse(o);return t.push(n)}};import{useEffect as rH,useState as aH}from"react";var T0=(e,t)=>{let[o,n]=aH(t);return rH(()=>{let r=e.on(a=>{n(a)});return()=>{r()}},[e]),o};import{jsx as ek}from"react/jsx-runtime";var q5=(e,t,o)=>{if(!t.multiElement&&!t.resizingElement&&!t.editingTextElement&&!t.newElement&&!t.selectedElementsAreBeingDragged&&!t.selectionElement&&!e.flowChartCreator.isCreatingChart){let n=o();if(!n)return{captureUpdate:C0.EVENTUALLY};let[r,a]=n,i=sH(Array.from(r.values()));return{appState:a,elements:i,captureUpdate:C0.NEVER}}return{captureUpdate:C0.EVENTUALLY}},J5=e=>({name:"undo",label:"buttons.undo",icon:yh,trackEvent:{category:"history"},viewMode:!1,perform:(t,o,n,r)=>q5(r,o,()=>e.undo(Z5(t),o)),keyTest:t=>t[od.CTRL_OR_CMD]&&k0(t,od.Z)&&!t.shiftKey,PanelComponent:({appState:t,updateData:o,data:n,app:r})=>{let{isUndoStackEmpty:a}=T0(e.onHistoryChangedEmitter,new pi(e.isUndoStackEmpty,e.isRedoStackEmpty)),i=Dt()==="mobile";return ek(ae,{type:"button",icon:yh,"aria-label":f("buttons.undo"),onClick:o,size:n?.size||"medium",disabled:a,"data-testid":"button-undo",style:{...i?j5:{}}})}}),Q5=e=>({name:"redo",label:"buttons.redo",icon:Eh,trackEvent:{category:"history"},viewMode:!1,perform:(t,o,n,r)=>q5(r,o,()=>e.redo(Z5(t),o)),keyTest:t=>t[od.CTRL_OR_CMD]&&t.shiftKey&&k0(t,od.Z)||iH&&t.ctrlKey&&!t.shiftKey&&k0(t,od.Y),PanelComponent:({appState:t,updateData:o,data:n,app:r})=>{let{isRedoStackEmpty:a}=T0(e.onHistoryChangedEmitter,new pi(e.isUndoStackEmpty,e.isRedoStackEmpty)),i=Dt()==="mobile";return ek(ae,{type:"button",icon:Eh,"aria-label":f("buttons.redo"),onClick:o,size:n?.size||"medium",disabled:a,"data-testid":"button-redo",style:{...i?j5:{}}})}});import{getFontString as lH}from"@orangecatai/common";import{newElementWith as cH}from"@orangecatai/element";import{measureText as dH}from"@orangecatai/element";import{isTextElement as tk}from"@orangecatai/element";import{CaptureUpdateAction as mH}from"@orangecatai/element";var ok=W({name:"autoResize",label:"labels.autoResize",icon:null,trackEvent:{category:"element"},predicate:(e,t,o,n)=>{let r=de(e,t);return r.length===1&&tk(r[0])&&!r[0].autoResize},perform:(e,t,o,n)=>{let r=de(e,t);return{appState:t,elements:e.map(a=>{if(a.id===r[0].id&&tk(a)){let i=dH(a.originalText,lH(a),a.lineHeight);return cH(a,{autoResize:!0,width:i.width,height:i.height,text:a.originalText})}return a}),captureUpdate:mH.IMMEDIATELY}}});import{isPromiseLike as pH}from"@orangecatai/common";import{jsx as uH}from"react/jsx-runtime";var S0=(e,t,o,n,r,a)=>{if(e.trackEvent)try{typeof e.trackEvent=="object"&&(!e.trackEvent.predicate||e.trackEvent.predicate(o,n,a))&&be(e.trackEvent.category,e.trackEvent.action||e.name,`${t} (${r.editorInterface.formFactor==="phone"?"mobile":"desktop"})`)}catch(i){console.error("error while logging action:",i)}},mu=class{constructor(t,o,n,r){A(this,"actions",{});A(this,"updater");A(this,"getAppState");A(this,"getElementsIncludingDeleted");A(this,"app");A(this,"renderAction",(t,o)=>{let n=this.app.props.UIOptions.canvasActions;if(this.actions[t]&&"PanelComponent"in this.actions[t]&&(!(t in n)||n[t])){let r=this.actions[t],a=r.PanelComponent;a.displayName="PanelComponent";let i=this.getElementsIncludingDeleted(),s=this.getAppState(),l=c=>{S0(r,"ui",s,i,this.app,c),this.updater(r.perform(this.getElementsIncludingDeleted(),this.getAppState(),c,this.app))};return uH(a,{elements:this.getElementsIncludingDeleted(),appState:this.getAppState(),updateData:l,appProps:this.app.props,app:this.app,data:o,renderAction:this.renderAction})}return null});A(this,"isActionEnabled",t=>{let o=this.getElementsIncludingDeleted(),n=this.getAppState();return!t.predicate||t.predicate(o,n,this.app.props,this.app)});this.updater=a=>{if(pH(a))a.then(i=>t(i));else return t(a)},this.getAppState=o,this.getElementsIncludingDeleted=n,this.app=r}registerAction(t){this.actions[t.name]=t}registerAll(t){t.forEach(o=>this.registerAction(o))}handleKeyDown(t){let o=this.app.props.UIOptions.canvasActions,n=Object.values(this.actions).sort((l,c)=>(c.keyPriority||0)-(l.keyPriority||0)).filter(l=>(l.name in o?o[l.name]:!0)&&l.keyTest&&l.keyTest(t,this.getAppState(),this.getElementsIncludingDeleted(),this.app));if(n.length!==1)return n.length>1&&console.warn("Canceling as multiple actions match this shortcut",n),!1;let r=n[0];if(this.getAppState().viewModeEnabled&&r.viewMode!==!0)return!1;let a=this.getElementsIncludingDeleted(),i=this.getAppState(),s=null;return S0(r,"keyboard",i,a,this.app,null),t.preventDefault(),t.stopPropagation(),this.updater(n[0].perform(a,i,s,this.app)),!0}executeAction(t,o="api",n=null){let r=this.getElementsIncludingDeleted(),a=this.getAppState();S0(t,o,a,r,this.app,n),this.updater(t.perform(r,a,n,this.app))}};var pu=class{constructor(){A(this,"targets",new WeakMap);A(this,"rafIds",new WeakMap)}register(t,o){this.targets.set(t,{callback:o,stopped:!0})}start(t){let o=this.targets.get(t);o&&(this.rafIds.has(t)||(this.targets.set(t,{...o,stopped:!1}),this.scheduleFrame(t)))}stop(t){let o=this.targets.get(t);o&&!o.stopped&&this.targets.set(t,{...o,stopped:!0}),this.cancelFrame(t)}constructFrame(t){return o=>{let n=this.targets.get(t);if(!n)return;let r=this.onFrame(n,o);!n.stopped&&!r?this.scheduleFrame(t):this.cancelFrame(t)}}scheduleFrame(t){let o=requestAnimationFrame(this.constructFrame(t));this.rafIds.set(t,o)}cancelFrame(t){if(this.rafIds.has(t)){let o=this.rafIds.get(t);cancelAnimationFrame(o)}this.rafIds.delete(t)}onFrame(t,o){return t.callback(o)??!1}};var M0=e=>{let t=Array.from(e.values());return{x:nk(t,o=>o.x)/t.length,y:nk(t,o=>o.y)/t.length}},P0=([e,t])=>Math.hypot(e.x-t.x,e.y-t.y),nk=(e,t)=>e.reduce((o,n)=>o+t(n),0);import{pointFrom as ee,pointRotateRads as da,rangeInclusive as Zo,rangeIntersection as uu,rangesOverlap as gu}from"@orangecatai/math";import{TOOL_TYPE as ui,KEYS as rk}from"@orangecatai/common";import{getCommonBounds as A0,getDraggedElementsBounds as L0,getElementAbsoluteCoords as gH}from"@orangecatai/element";import{isBoundToContainer as lk}from"@orangecatai/element";import{getMaximumGroups as ck}from"@orangecatai/element";import{getSelectedElements as hH,getVisibleAndNonSelectedElements as dk}from"@orangecatai/element";var fH=8,ak=99999,hu=e=>fH/e,lo=class lo{};A(lo,"referenceSnapPoints",null),A(lo,"visibleGaps",null),A(lo,"setReferenceSnapPoints",t=>{lo.referenceSnapPoints=t}),A(lo,"getReferenceSnapPoints",()=>lo.referenceSnapPoints),A(lo,"setVisibleGaps",t=>{lo.visibleGaps=t}),A(lo,"getVisibleGaps",()=>lo.visibleGaps),A(lo,"destroy",()=>{lo.referenceSnapPoints=null,lo.visibleGaps=null});var jo=lo,ma=e=>e.props.gridModeEnabled??e.state.gridModeEnabled,kr=({event:e,app:t,selectedElements:o})=>{if(e){let n=t.state.activeTool.type==="lasso"&&t.state.selectedElementsAreBeingDragged;return(t.state.activeTool.type!=="lasso"||n)&&(t.state.objectsSnapModeEnabled&&!e[rk.CTRL_OR_CMD]||!t.state.objectsSnapModeEnabled&&e[rk.CTRL_OR_CMD]&&!ma(t))}return o.length===1&&o[0].type==="arrow"?!1:t.state.objectsSnapModeEnabled},bH=(e,t,o=.01)=>Math.abs(e-t)<=o,nd=(e,t,{omitCenter:o,boundingBoxCorners:n,dragOffset:r}={omitCenter:!1,boundingBoxCorners:!1})=>{let a=[];if(e.length===1){let i=e[0],[s,l,c,m,p,d]=gH(i,t);r&&(s+=r.x,c+=r.x,p+=r.x,l+=r.y,m+=r.y,d+=r.y);let u=(c-s)/2,h=(m-l)/2;if((i.type==="diamond"||i.type==="ellipse")&&!n){let g=da(ee(s,l+h),ee(p,d),i.angle),x=da(ee(s+u,l),ee(p,d),i.angle),E=da(ee(c,l+h),ee(p,d),i.angle),y=da(ee(s+u,m),ee(p,d),i.angle),w=ee(p,d);a=o?[g,x,E,y]:[g,x,E,y,w]}else{let g=da(ee(s,l),ee(p,d),i.angle),x=da(ee(c,l),ee(p,d),i.angle),E=da(ee(s,m),ee(p,d),i.angle),y=da(ee(c,m),ee(p,d),i.angle),w=ee(p,d);a=o?[g,x,E,y]:[g,x,E,y,w]}}else if(e.length>1){let[i,s,l,c]=L0(e,r??{x:0,y:0}),m=l-i,p=c-s,d=ee(i,s),u=ee(l,s),h=ee(i,c),g=ee(l,c),x=ee(i+m/2,s+p/2);a=o?[d,u,h,g]:[d,u,h,g,x]}return a.map(i=>ee(mt(i[0]),mt(i[1])))},mk=(e,t,o,n)=>dk(e,t,o,n),pk=(e,t,o,n)=>{let r=mk(e,t,o,n),a=ck(r,n).filter(p=>!(p.length===1&&lk(p[0]))).map(p=>A0(p).map(d=>mt(d))),i=a.sort((p,d)=>p[0]-d[0]),s=[],l=0;e:for(let p=0;p<i.length;p++){let d=i[p];for(let u=p+1;u<i.length;u++){if(++l>ak)break e;let h=i[u],[,g,x,E]=d,[y,w,,v]=h;x<y&&gu(Zo(g,E),Zo(w,v))&&s.push({startBounds:d,endBounds:h,startSide:[ee(x,g),ee(x,E)],endSide:[ee(y,w),ee(y,v)],length:y-x,overlap:uu(Zo(g,E),Zo(w,v))})}}let c=a.sort((p,d)=>p[1]-d[1]),m=[];l=0;e:for(let p=0;p<c.length;p++){let d=c[p];for(let u=p+1;u<c.length;u++){if(++l>ak)break e;let h=c[u],[g,,x,E]=d,[y,w,v]=h;E<w&&gu(Zo(g,x),Zo(y,v))&&m.push({startBounds:d,endBounds:h,startSide:[ee(g,E),ee(x,E)],endSide:[ee(y,w),ee(v,w)],length:w-E,overlap:uu(Zo(g,x),Zo(y,v))})}}return{horizontalGaps:s,verticalGaps:m}},ik=(e,t,o,n,r,a,i)=>{if(!kr({app:o,event:n,selectedElements:e}))return[];if(e.length===0)return[];let s=jo.getVisibleGaps();if(s){let{horizontalGaps:l,verticalGaps:c}=s,[m,p,d,u]=L0(e,t).map(x=>mt(x)),h=(m+d)/2,g=(p+u)/2;for(let x of l){if(!gu(Zo(p,u),x.overlap))continue;let E=x.startSide[0][0]+x.length/2,y=mt(E-h);if(x.length>d-m&&Math.abs(y)<=i.x){Math.abs(y)<i.x&&(r.length=0),i.x=Math.abs(y);let _={type:"gap",direction:"center_horizontal",gap:x,offset:y};r.push(_);continue}let[,,v]=x.endBounds,I=m-v,C=mt(x.length-I);if(Math.abs(C)<=i.x){Math.abs(C)<i.x&&(r.length=0),i.x=Math.abs(C);let _={type:"gap",direction:"side_right",gap:x,offset:C};r.push(_);continue}let[P,,,]=x.startBounds,S=P-d,D=mt(S-x.length);if(Math.abs(D)<=i.x){Math.abs(D)<i.x&&(r.length=0),i.x=Math.abs(D);let _={type:"gap",direction:"side_left",gap:x,offset:D};r.push(_);continue}}for(let x of c){if(!gu(Zo(m,d),x.overlap))continue;let E=x.startSide[0][1]+x.length/2,y=mt(E-g);if(x.length>u-p&&Math.abs(y)<=i.y){Math.abs(y)<i.y&&(a.length=0),i.y=Math.abs(y);let _={type:"gap",direction:"center_vertical",gap:x,offset:y};a.push(_);continue}let[,v,,]=x.startBounds,I=v-u,C=mt(I-x.length);if(Math.abs(C)<=i.y){Math.abs(C)<i.y&&(a.length=0),i.y=Math.abs(C);let _={type:"gap",direction:"side_top",gap:x,offset:C};a.push(_);continue}let[,,,P]=x.endBounds,S=mt(p-P),D=x.length-S;if(Math.abs(D)<=i.y){Math.abs(D)<i.y&&(a.length=0),i.y=Math.abs(D);let _={type:"gap",direction:"side_bottom",gap:x,offset:D};a.push(_);continue}}}},uk=(e,t,o,n)=>{let r=mk(e,t,o,n);return ck(r,n).filter(a=>!(a.length===1&&lk(a[0]))).flatMap(a=>nd(a,n))},ll=(e,t,o,n,r,a,i)=>{if(!kr({app:o,event:n,selectedElements:e})||e.length===0&&t.length===0)return[];let s=jo.getReferenceSnapPoints();if(s)for(let l of t)for(let c of s){let m=c[0]-l[0],p=c[1]-l[1];Math.abs(m)<=i.x&&(Math.abs(m)<i.x&&(r.length=0),r.push({type:"point",points:[l,c],offset:m}),i.x=Math.abs(m)),Math.abs(p)<=i.y&&(Math.abs(p)<i.y&&(a.length=0),a.push({type:"point",points:[l,c],offset:p}),i.y=Math.abs(p))}},gk=(e,t,o,n,r)=>{let a=o.state,i=hH(e,a);if(!kr({app:o,event:n,selectedElements:i})||i.length===0)return{snapOffset:{x:0,y:0},snapLines:[]};t.x=mt(t.x),t.y=mt(t.y);let s=[],l=[],c=hu(a.zoom.value),m={x:c,y:c},p=nd(i,r,{dragOffset:t});ll(i,p,o,n,s,l,m),ik(i,t,o,n,s,l,m);let d={x:s[0]?.offset??0,y:l[0]?.offset??0};m.x=0,m.y=0,s.length=0,l.length=0;let u={x:mt(t.x+d.x),y:mt(t.y+d.y)};ll(i,nd(i,r,{dragOffset:u}),o,n,s,l,m),ik(i,u,o,n,s,l,m);let h=_0(s,l),g=yH(i,u,[...s,...l].filter(x=>x.type==="gap"));return{snapOffset:d,snapLines:[...h,...g]}},mt=e=>Math.round(e*10**6)/10**6,sk=e=>{let t=new Map;for(let o of e){let n=o.join(",");t.has(n)||t.set(n,o)}return Array.from(t.values())},_0=(e,t)=>{let o={},n={};if(e.length>0){for(let r of e)if(r.type==="point"){let a=mt(r.points[0][0]);o[a]||(o[a]=[]),o[a].push(...r.points.map(i=>ee(mt(i[0]),mt(i[1]))))}}if(t.length>0){for(let r of t)if(r.type==="point"){let a=mt(r.points[0][1]);n[a]||(n[a]=[]),n[a].push(...r.points.map(i=>ee(mt(i[0]),mt(i[1]))))}}return Object.entries(o).map(([r,a])=>({type:"points",points:sk(a.map(i=>ee(Number(r),i[1])).sort((i,s)=>i[1]-s[1]))})).concat(Object.entries(n).map(([r,a])=>({type:"points",points:sk(a.map(i=>ee(i[0],Number(r))).sort((i,s)=>i[0]-s[0]))})))},xH=e=>{let t=new Map;for(let o of e){let n=o.points.flat().map(r=>[mt(r)]).join(",");t.has(n)||t.set(n,o)}return Array.from(t.values())},yH=(e,t,o)=>{let[n,r,a,i]=L0(e,t),s=[];for(let l of o){let[c,m,p,d]=l.gap.startBounds,[u,h,g,x]=l.gap.endBounds,E=uu(Zo(r,i),l.gap.overlap),y=uu(Zo(n,a),l.gap.overlap);switch(l.direction){case"center_horizontal":{if(E){let w=(E[0]+E[1])/2;s.push({type:"gap",direction:"horizontal",points:[ee(l.gap.startSide[0][0],w),ee(n,w)]},{type:"gap",direction:"horizontal",points:[ee(a,w),ee(l.gap.endSide[0][0],w)]})}break}case"center_vertical":{if(y){let w=(y[0]+y[1])/2;s.push({type:"gap",direction:"vertical",points:[ee(w,l.gap.startSide[0][1]),ee(w,r)]},{type:"gap",direction:"vertical",points:[ee(w,i),ee(w,l.gap.endSide[0][1])]})}break}case"side_right":{if(E){let w=(E[0]+E[1])/2;s.push({type:"gap",direction:"horizontal",points:[ee(p,w),ee(u,w)]},{type:"gap",direction:"horizontal",points:[ee(g,w),ee(n,w)]})}break}case"side_left":{if(E){let w=(E[0]+E[1])/2;s.push({type:"gap",direction:"horizontal",points:[ee(a,w),ee(c,w)]},{type:"gap",direction:"horizontal",points:[ee(p,w),ee(u,w)]})}break}case"side_top":{if(y){let w=(y[0]+y[1])/2;s.push({type:"gap",direction:"vertical",points:[ee(w,i),ee(w,m)]},{type:"gap",direction:"vertical",points:[ee(w,d),ee(w,h)]})}break}case"side_bottom":{if(y){let w=(y[0]+y[1])/2;s.push({type:"gap",direction:"vertical",points:[ee(w,d),ee(w,h)]},{type:"gap",direction:"vertical",points:[ee(w,x),ee(w,r)]})}break}}}return xH(s.map(l=>({...l,points:l.points.map(c=>ee(mt(c[0]),mt(c[1])))})))},D0=(e,t,o,n,r,a)=>{if(!kr({event:n,selectedElements:e,app:o})||e.length===0||e.length===1&&!bH(e[0].angle,0))return{snapOffset:{x:0,y:0},snapLines:[]};let[i,s,l,c]=A0(t);a&&(a.includes("e")?l+=r.x:a.includes("w")&&(i+=r.x),a.includes("n")?s+=r.y:a.includes("s")&&(c+=r.y));let m=[];if(a)switch(a){case"e":{m.push(ee(l,s),ee(l,c));break}case"w":{m.push(ee(i,s),ee(i,c));break}case"n":{m.push(ee(i,s),ee(l,s));break}case"s":{m.push(ee(i,c),ee(l,c));break}case"ne":{m.push(ee(l,s));break}case"nw":{m.push(ee(i,s));break}case"se":{m.push(ee(l,c));break}case"sw":{m.push(ee(i,c));break}}let p=hu(o.state.zoom.value),d={x:p,y:p},u=[],h=[];ll(t,m,o,n,u,h,d);let g={x:u[0]?.offset??0,y:h[0]?.offset??0};d.x=0,d.y=0,u.length=0,h.length=0;let[x,E,y,w]=A0(e).map(C=>mt(C)),v=[ee(x,E),ee(x,w),ee(y,E),ee(y,w)];ll(e,v,o,n,u,h,d);let I=_0(u,h);return{snapOffset:g,snapLines:I}},hk=(e,t,o,n,r,a)=>{if(!kr({event:o,selectedElements:[e],app:t}))return{snapOffset:{x:0,y:0},snapLines:[]};let i=[ee(n.x+r.x,n.y+r.y)],s=hu(t.state.zoom.value),l={x:s,y:s},c=[],m=[];ll([e],i,t,o,c,m,l);let p={x:c[0]?.offset??0,y:m[0]?.offset??0};l.x=0,l.y=0,c.length=0,m.length=0;let d=nd([e],a,{boundingBoxCorners:!0,omitCenter:!0});ll([e],d,t,o,c,m,l);let u=_0(c,m);return{snapOffset:p,snapLines:u}},fk=(e,t,o,n,r)=>{if(!kr({event:n,selectedElements:[],app:t}))return{originOffset:{x:0,y:0},snapLines:[]};let a=dk(e,[],t.state,r),i=hu(t.state.zoom.value),s={x:i,y:i},l=[],c=[];for(let m of a){let p=nd([m],r);for(let d of p){let u=d[0]-o.x;Math.abs(u)<=Math.abs(s.x)&&(Math.abs(u)<Math.abs(s.x)&&(c.length=0),c.push({type:"pointer",points:[d,ee(d[0],o.y)],direction:"vertical"}),s.x=u);let h=d[1]-o.y;Math.abs(h)<=Math.abs(s.y)&&(Math.abs(h)<Math.abs(s.y)&&(l.length=0),l.push({type:"pointer",points:[d,ee(o.x,d[1])],direction:"horizontal"}),s.y=h)}}return{originOffset:{x:c.length>0?c[0].points[0][0]-o.x:0,y:l.length>0?l[0].points[0][1]-o.y:0},snapLines:[...c,...l]}},bk=e=>e===ui.rectangle||e===ui.ellipse||e===ui.diamond||e===ui.frame||e===ui.magicframe||e===ui.image||e===ui.text;import{isElementInViewport as EH}from"@orangecatai/element";import{memoize as wH,toBrandedType as vH}from"@orangecatai/common";var rd=class{constructor(t){A(this,"scene");A(this,"getRenderableElements",(()=>{let t=({elementsMap:n,zoom:r,offsetLeft:a,offsetTop:i,scrollX:s,scrollY:l,height:c,width:m})=>{let p=[];for(let d of n.values())EH(d,m,c,{zoom:r,offsetLeft:a,offsetTop:i,scrollX:s,scrollY:l},n)&&p.push(d);return p},o=({elements:n,editingTextElement:r,newElementId:a})=>{let i=vH(new Map);for(let s of n)a!==s.id&&(!r||r.type!=="text"||s.id!==r.id)&&i.set(s.id,s);return i};return wH(({zoom:n,offsetLeft:r,offsetTop:a,scrollX:i,scrollY:s,height:l,width:c,editingTextElement:m,newElementId:p,sceneNonce:d})=>{let u=this.scene.getNonDeletedElements(),h=o({elements:u,editingTextElement:m,newElementId:p}),g=t({elementsMap:h,zoom:n,offsetLeft:r,offsetTop:a,scrollX:i,scrollY:s,height:l,width:c});return{elementsMap:h,visibleElements:g}})})());this.scene=t}destroy(){cE.cancel(),this.getRenderableElements.clear()}};import{sceneCoordsToViewportCoords as IH}from"@orangecatai/common";import{getElementAbsoluteCoords as TH}from"@orangecatai/element";import{jsx as SH}from"react/jsx-runtime";var CH=5,kH=(e,t,o)=>{let[n,r]=TH(e,o),{x:a,y:i}=IH({sceneX:n+e.width,sceneY:r},t),s=a-t.offsetLeft+10,l=i-t.offsetTop;return{x:s,y:l}},R0=({children:e,element:t,elementsMap:o})=>{let n=$o();if(n.contextMenu||n.newElement||n.resizingElement||n.isRotating||n.openMenu||n.viewModeEnabled)return null;let{x:r,y:a}=kH(t,n,o);return SH("div",{className:"excalidraw-canvas-buttons",style:{top:`${a}px`,left:`${r}px`,padding:CH},children:e})};import{useCallback as id,useEffect as fu,useRef as MH,useState as cl}from"react";import{sceneCoordsToViewportCoords as PH}from"@orangecatai/common";import{getElementAbsoluteCoords as AH}from"@orangecatai/element";import{isFrameLikeElement as LH}from"@orangecatai/element";var gi={element:null,isOpen:!1,isRunning:!1},B0=new Set;function N0(){B0.forEach(e=>e(gi))}var En={open(e){gi={...gi,element:e,isOpen:!0},N0()},close(){gi={element:null,isOpen:!1,isRunning:!1},N0()},setRunning(e){gi={...gi,isRunning:e},N0()},getState(){return gi},subscribe(e){return B0.add(e),()=>B0.delete(e)}};var qo={isOpen:!1,isBuilding:!1,templateName:"",campaignTag:"",sourceFrameId:null},F0=new Set;function ad(){F0.forEach(e=>e(qo))}var Ro={open(e){qo={...qo,isOpen:!0,templateName:"",campaignTag:"",sourceFrameId:e??null},ad()},close(){qo={...qo,isOpen:!1,isBuilding:!1,sourceFrameId:null},ad()},setBuilding(e){qo={...qo,isBuilding:e},ad()},setName(e){qo={...qo,templateName:e},ad()},setCampaignTag(e){qo={...qo,campaignTag:e},ad()},getState(){return qo},subscribe(e){return F0.add(e),()=>F0.delete(e)}};import{Fragment as xk,jsx as xe,jsxs as co}from"react/jsx-runtime";var yk=[{label:"1:1",width:1024,height:1024,icon:"square"},{label:"2:3",width:1024,height:1536,icon:"portrait"},{label:"9:16",width:1080,height:1920,icon:"portrait-tall"},{label:"3:2",width:1536,height:1024,icon:"landscape"},{label:"16:9",width:1920,height:1080,icon:"landscape-wide"},{label:"A4",width:1024,height:1754,icon:"portrait"},{label:"Website",width:1366,height:768,icon:"landscape-wide"}],O0=e=>{let t={border:"1.5px solid currentColor",borderRadius:2,boxSizing:"border-box"};switch(e){case"square":return xe("div",{style:{...t,width:14,height:14}});case"portrait":return xe("div",{style:{...t,width:10,height:14}});case"portrait-tall":return xe("div",{style:{...t,width:8,height:14}});case"landscape":return xe("div",{style:{...t,width:14,height:10}});case"landscape-wide":return xe("div",{style:{...t,width:14,height:8}});default:return xe("div",{style:{...t,width:14,height:14}})}},_H=({active:e})=>xe("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:e?co(xk,{children:[xe("path",{d:"M5 3H4C3.44772 3 3 3.44772 3 4V10C3 10.5523 3.44772 11 4 11H5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"}),xe("path",{d:"M9 3H10C10.5523 3 11 3.44772 11 4V10C11 10.5523 10.5523 11 10 11H9",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"}),xe("line",{x1:"5",y1:"7",x2:"9",y2:"7",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]}):co(xk,{children:[xe("path",{d:"M5 3H4C3.44772 3 3 3.44772 3 4V10C3 10.5523 3.44772 11 4 11H5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"}),xe("path",{d:"M9 3H10C10.5523 3 11 3.44772 11 4V10C11 10.5523 10.5523 11 10 11H9",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]})}),DH=()=>co("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[xe("path",{d:"M8 2V10M8 10L5 7M8 10L11 7",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"}),xe("path",{d:"M3 12H13",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]}),RH=()=>xe("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:xe("path",{d:"M2.5 3.75L5 6.25L7.5 3.75",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),NH=()=>xe("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:xe("path",{d:"M3.5 8.5L6.5 11.5L12.5 4.5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),BH=()=>co("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",children:[xe("rect",{x:"1",y:"1",width:"5",height:"5",rx:"1",stroke:"currentColor",strokeWidth:"1.4"}),xe("rect",{x:"8",y:"1",width:"5",height:"5",rx:"1",stroke:"currentColor",strokeWidth:"1.4"}),xe("rect",{x:"1",y:"8",width:"5",height:"5",rx:"1",stroke:"currentColor",strokeWidth:"1.4"}),xe("rect",{x:"8",y:"8",width:"5",height:"5",rx:"1",stroke:"currentColor",strokeWidth:"1.4"})]}),FH=()=>co("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",children:[xe("rect",{x:"1.5",y:"1.5",width:"6.5",height:"6.5",rx:"1",stroke:"currentColor",strokeWidth:"1.4"}),xe("rect",{x:"8",y:"8",width:"6.5",height:"6.5",rx:"1",stroke:"currentColor",strokeWidth:"1.4",strokeDasharray:"2 1.2",opacity:"0.65"}),xe("path",{d:"M10.5 5.5H13.5V2.5",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round"})]}),OH=(e,t)=>yk.find(o=>o.width===e&&o.height===t)||null,Ek=({element:e,app:t})=>{let o=t.state,[n,r]=cl(!1),[a,i]=cl(!0),[s,l]=cl(Math.round(e.width)),[c,m]=cl(Math.round(e.height)),[p,d]=cl(En.getState()),[u,h]=cl(Ro.getState()),g=MH(null);fu(()=>En.subscribe(d),[]),fu(()=>Ro.subscribe(h),[]),fu(()=>{l(Math.round(e.width)),m(Math.round(e.height))},[e.width,e.height]),fu(()=>{let M=B=>{g.current&&!g.current.contains(B.target)&&r(!1)};if(n)return document.addEventListener("mousedown",M),()=>document.removeEventListener("mousedown",M)},[n]);let x=OH(Math.round(e.width),Math.round(e.height)),[E,y]=AH(e,t.scene.getNonDeletedElementsMap()),{x:w,y:v}=PH({sceneX:E+e.width/2,sceneY:y},o),I=w-o.offsetLeft,C=Math.max(v-o.offsetTop-82,8),P=id((M,B)=>{M>0&&B>0&&t.scene.mutateElement(e,{width:M,height:B})},[t.scene,e]),S=id(M=>{let B=parseInt(M,10);if(!isNaN(B)&&B>0)if(l(B),a){let O=e.height/e.width,N=Math.round(B*O);m(N),P(B,N)}else P(B,e.height)},[a,e.width,e.height,P]),D=id(M=>{let B=parseInt(M,10);if(!isNaN(B)&&B>0)if(m(B),a){let O=e.width/e.height,N=Math.round(B*O);l(N),P(N,B)}else P(e.width,B)},[a,e.width,e.height,P]),_=id(M=>{l(M.width),m(M.height),P(M.width,M.height),r(!1)},[P]),k=id(()=>{LH(e)&&t.onExportImage("png",t.getSceneElements(),{exportingFrame:e})},[t,e]);return o.contextMenu||o.newElement||o.resizingElement||o.isRotating||o.openMenu||o.viewModeEnabled||o.selectedElementsAreBeingDragged?null:co("div",{className:"frame-toolbar",style:{left:`${I}px`,top:`${C}px`},onPointerDown:M=>M.stopPropagation(),onClick:M=>M.stopPropagation(),children:[co("div",{className:"frame-toolbar__section",ref:g,children:[co("button",{className:"frame-toolbar__ratio-btn",onClick:()=>r(!n),title:"Frame format",children:[O0(x?x.icon:"square"),xe("span",{children:x?.label||"Custom"}),xe(RH,{})]}),n&&co("div",{className:"frame-toolbar__dropdown",children:[xe("div",{style:{padding:"6px 12px",fontSize:11,fontWeight:600,color:"var(--text-secondary-color, #888)",textTransform:"uppercase",letterSpacing:"0.5px"},children:"Format"}),yk.map(M=>{let B=x?.label===M.label;return co("button",{className:"frame-toolbar__dropdown-item",onClick:()=>_(M),children:[O0(M.icon),xe("span",{className:"frame-toolbar__dropdown-item-label",children:M.label}),co("span",{className:"frame-toolbar__dropdown-item-dims",children:[M.width,"*",M.height]}),B&&xe("span",{className:"frame-toolbar__dropdown-item-check",children:xe(NH,{})})]},M.label)})]})]}),xe("div",{className:"frame-toolbar__divider"}),co("div",{className:"frame-toolbar__input-group",children:[xe("label",{children:"W"}),xe("input",{type:"number",value:s,onChange:M=>S(M.target.value),onPointerDown:M=>M.stopPropagation(),min:1})]}),xe("button",{className:`frame-toolbar__constrain-btn ${a?"frame-toolbar__constrain-btn--active":""}`,onClick:()=>i(!a),title:a?"Unlock proportions":"Constrain proportions",children:xe(_H,{active:a})}),co("div",{className:"frame-toolbar__input-group",children:[xe("label",{children:"H"}),xe("input",{type:"number",value:c,onChange:M=>D(M.target.value),onPointerDown:M=>M.stopPropagation(),min:1})]}),xe("div",{className:"frame-toolbar__divider"}),xe("button",{className:"frame-toolbar__export-btn",onClick:k,title:"Export frame as PNG",children:xe(DH,{})}),xe("div",{className:"frame-toolbar__divider"}),xe("div",{className:"frame-toolbar__section",children:co("button",{className:`frame-toolbar__btn ${p.isOpen&&p.element?.id===e.id?"frame-toolbar__btn--active":""}`,onClick:()=>{p.isOpen&&p.element?.id===e.id?p.isRunning||En.close():En.open(e)},title:"Auto resize to multiple dimensions",children:[xe(FH,{}),xe("span",{children:"Resize"})]})}),xe("div",{className:"frame-toolbar__divider"}),xe("div",{className:"frame-toolbar__section",children:co("button",{className:`frame-toolbar__btn ${u.isOpen?"frame-toolbar__btn--active":""}`,onClick:()=>{u.isOpen?Ro.close():Ro.open(e.id)},title:"Template Builder \u2014 add slot blocks to this frame",children:[xe(BH,{}),xe("span",{children:"Template"})]})})]})};import{useEffect as zH,useReducer as HH}from"react";import{sceneCoordsToViewportCoords as GH}from"@orangecatai/common";var sd=[],H0=new Set;function z0(){H0.forEach(e=>e())}var Sr={setLoadingFrames(e){sd=[...e],z0()},markComplete(e){sd=sd.filter(t=>t.frameId!==e),z0()},clear(){sd=[],z0()},getLoadingFrames(){return sd},subscribe(e){return H0.add(e),()=>H0.delete(e)}};import{Fragment as UH,jsx as wk}from"react/jsx-runtime";var vk=()=>{let e=$o(),[,t]=HH(r=>r+1,0);zH(()=>Sr.subscribe(t),[]);let o=Sr.getLoadingFrames();if(o.length===0)return null;let n=e.zoom.value;return wk(UH,{children:o.map(r=>{let{x:a,y:i}=GH({sceneX:r.x,sceneY:r.y},e),s=a-e.offsetLeft,l=i-e.offsetTop,c=r.width*n,m=r.height*n;return wk("div",{className:"ars-shimmer",style:{position:"absolute",left:s,top:l,width:c,height:m,pointerEvents:"none",zIndex:5,overflow:"hidden",boxSizing:"border-box"}},r.frameId)})})};import{useEffect as $k,useRef as XG,useState as ZG}from"react";import{sceneCoordsToViewportCoords as jG}from"@orangecatai/common";import{getElementAbsoluteCoords as qG}from"@orangecatai/element";function ld(e){let t=e?.trim();return(t||void 0)??(typeof import.meta<"u"&&T?.VITE_APP_OPENROUTER_API_KEY?T.VITE_APP_OPENROUTER_API_KEY:"")??""}import{useCallback as K0,useEffect as WG,useRef as YG,useState as Ei}from"react";function dl(e){let t=e?.trim();return(t||void 0)??(typeof import.meta<"u"&&T?.VITE_APP_GEMINI_API_KEY?T.VITE_APP_GEMINI_API_KEY:"")??""}import{nanoid as Lk}from"nanoid";import{newFrameElement as Bk,newElement as _k,newTextElement as vG,newImageElement as Dk,getFrameChildren as V0,syncMovedIndices as Au}from"@orangecatai/element";import{FRAME_STYLE as Fk,arrayToMap as Lu}from"@orangecatai/common";import{useCallback as bi,useEffect as dd,useRef as ua,useState as Zn}from"react";import{sceneCoordsToViewportCoords as QH}from"@orangecatai/common";import{CaptureUpdateAction as U0,getElementAbsoluteCoords as eG}from"@orangecatai/element";import{ArrowUp as tG,ImagePlus as oG,X as nG}from"lucide-react";var Mr=new Map;function bu(e,t,o,n){Mr.set(e,{subscribers:new Set,prompt:t,settings:o,controller:n})}function xu(e,t){let o=Mr.get(e);o&&(o.finishedError=t,o.subscribers.forEach(n=>n(t)))}function yu(e,t){let o=Mr.get(e);return o?(o.subscribers.add(t),o.finishedError!==void 0&&t(o.finishedError),!0):!1}function Eu(e,t){Mr.get(e)?.subscribers.delete(t)}function wu(e){Mr.delete(e)}function vu(e){Mr.get(e)?.controller.abort()}function Iu(e){return Mr.get(e)?.prompt??""}function pa(e){return Mr.get(e)?.settings??null}function hi(e){return Mr.has(e)}import VH,{createContext as KH,useContext as XH,useLayoutEffect as ZH,useRef as jH,useState as qH}from"react";import{clsx as WH}from"clsx";import{twMerge as YH}from"tailwind-merge";function je(...e){return YH(WH(e))}import*as Ik from"react";import{jsx as $H}from"react/jsx-runtime";var G0=Ik.forwardRef(({className:e,...t},o)=>$H("textarea",{className:je("flex min-h-[60px] w-full rounded-md border border-zinc-200 bg-transparent px-3 py-2 text-base shadow-sm placeholder:text-zinc-500 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-zinc-950 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm dark:border-zinc-800 dark:placeholder:text-zinc-400 dark:focus-visible:ring-zinc-300",e),ref:o,...t}));G0.displayName="Textarea";import*as Ck from"react";import*as wn from"@radix-ui/react-tooltip";import{jsx as Tk}from"react/jsx-runtime";var Tu=wn.Provider,Cu=wn.Root,ku=wn.Trigger,cd=Ck.forwardRef(({className:e,sideOffset:t=4,...o},n)=>Tk(wn.Portal,{children:Tk(wn.Content,{ref:n,sideOffset:t,className:je("z-50 overflow-hidden rounded-md bg-zinc-900 px-3 py-1.5 text-xs text-zinc-50 animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-[--radix-tooltip-content-transform-origin] dark:bg-zinc-50 dark:text-zinc-900",e),...o})}));cd.displayName=wn.Content.displayName;import{jsx as fi,jsxs as JH}from"react/jsx-runtime";var kk=KH({isLoading:!1,value:"",setValue:()=>{},maxHeight:320,onSubmit:void 0,disabled:!1,textareaRef:VH.createRef()});function Sk(){return XH(kk)}function ml({className:e,isLoading:t=!1,maxHeight:o=320,value:n,onValueChange:r,onSubmit:a,children:i,disabled:s=!1,onClick:l,...c}){let[m,p]=qH(n||""),d=jH(null),u=g=>{p(g),r?.(g)},h=g=>{s||d.current?.focus(),l?.(g)};return fi(Tu,{children:fi(kk.Provider,{value:{isLoading:t,value:n??m,setValue:r??u,maxHeight:o,onSubmit:a,disabled:s,textareaRef:d},children:fi("div",{onClick:h,className:je("border-zinc-200 bg-white cursor-text rounded-3xl border p-2 shadow-xs dark:border-zinc-800 dark:bg-zinc-950",s&&"cursor-not-allowed opacity-60",e),...c,children:i})})})}function pl({className:e,onKeyDown:t,disableAutosize:o=!1,...n}){let{value:r,setValue:a,maxHeight:i,onSubmit:s,disabled:l,textareaRef:c}=Sk(),m=h=>{if(!h||o)return;h.style.height="auto";let g;typeof i=="number"?(h.style.height=`${Math.min(h.scrollHeight,i)}px`,g=i):(h.style.height=`min(${h.scrollHeight}px, ${i})`,g=1/0),h.style.overflowY=h.scrollHeight>g?"auto":"hidden"},p=h=>{c.current=h,m(h)};return ZH(()=>{m(c.current)},[r,i,o]),fi(G0,{ref:p,value:r,onChange:h=>{m(h.target),a(h.target.value)},onKeyDown:h=>{h.key==="Enter"&&!h.shiftKey&&(h.preventDefault(),s?.()),t?.(h)},onWheel:h=>{h.stopPropagation()},className:je("text-zinc-900 min-h-[44px] w-full resize-none border-none bg-transparent shadow-none outline-none focus-visible:ring-0 focus-visible:ring-offset-0 dark:text-zinc-50",e),rows:1,disabled:l,...n})}function ul({children:e,className:t,...o}){return fi("div",{className:je("flex items-center gap-2",t),...o,children:e})}function Pr({tooltip:e,children:t,className:o,side:n="top",...r}){let{disabled:a}=Sk();return JH(Cu,{...r,children:[fi(ku,{asChild:!0,disabled:a,onClick:i=>i.stopPropagation(),children:t}),fi(cd,{side:n,className:o,children:e})]})}import{jsx as we,jsxs as Mt}from"react/jsx-runtime";var ga={"Gemini 2.5 Flash":{geminiModelId:"gemini-3.1-flash-image-preview",supportsImageSize:!1,supportsThinking:!1,supportedResolutions:["1K"],supportedRatios:["21:9","16:9","4:3","3:2","1:1","9:16","3:4","2:3","5:4","4:5"]},"Gemini 3.1 Flash":{geminiModelId:"gemini-3.1-flash-image-preview",supportsImageSize:!0,supportsThinking:!0,supportedResolutions:["0.5K","1K","2K","4K"],supportedRatios:["21:9","16:9","4:3","3:2","1:1","9:16","3:4","2:3","5:4","4:5","4:1","1:4","8:1","1:8"]},"Gemini 3 Pro":{geminiModelId:"gemini-3-pro-image-preview",supportsImageSize:!0,supportsThinking:!1,supportedResolutions:["1K","2K","4K"],supportedRatios:["21:9","16:9","4:3","3:2","1:1","9:16","3:4","2:3","5:4","4:5"]}},$0=Object.keys(ga),rG={"Gemini 2.5 Flash":{"1:1":{"1K":{w:1024,h:1024}},"2:3":{"1K":{w:832,h:1248}},"3:2":{"1K":{w:1248,h:832}},"3:4":{"1K":{w:864,h:1184}},"4:3":{"1K":{w:1184,h:864}},"4:5":{"1K":{w:896,h:1152}},"5:4":{"1K":{w:1152,h:896}},"9:16":{"1K":{w:768,h:1344}},"16:9":{"1K":{w:1344,h:768}},"21:9":{"1K":{w:1536,h:672}}},"Gemini 3.1 Flash":{"1:1":{"0.5K":{w:512,h:512},"1K":{w:1024,h:1024},"2K":{w:2048,h:2048},"4K":{w:4096,h:4096}},"1:4":{"0.5K":{w:256,h:1024},"1K":{w:512,h:2048},"2K":{w:1024,h:4096},"4K":{w:2048,h:8192}},"1:8":{"0.5K":{w:192,h:1536},"1K":{w:384,h:3072},"2K":{w:768,h:6144},"4K":{w:1536,h:12288}},"2:3":{"0.5K":{w:424,h:632},"1K":{w:848,h:1264},"2K":{w:1696,h:2528},"4K":{w:3392,h:5056}},"3:2":{"0.5K":{w:632,h:424},"1K":{w:1264,h:848},"2K":{w:2528,h:1696},"4K":{w:5056,h:3392}},"3:4":{"0.5K":{w:448,h:600},"1K":{w:896,h:1200},"2K":{w:1792,h:2400},"4K":{w:3584,h:4800}},"4:1":{"0.5K":{w:1024,h:256},"1K":{w:2048,h:512},"2K":{w:4096,h:1024},"4K":{w:8192,h:2048}},"4:3":{"0.5K":{w:600,h:448},"1K":{w:1200,h:896},"2K":{w:2400,h:1792},"4K":{w:4800,h:3584}},"4:5":{"0.5K":{w:464,h:576},"1K":{w:928,h:1152},"2K":{w:1856,h:2304},"4K":{w:3712,h:4608}},"5:4":{"0.5K":{w:576,h:464},"1K":{w:1152,h:928},"2K":{w:2304,h:1856},"4K":{w:4608,h:3712}},"8:1":{"0.5K":{w:1536,h:192},"1K":{w:3072,h:384},"2K":{w:6144,h:768},"4K":{w:12288,h:1536}},"9:16":{"0.5K":{w:384,h:688},"1K":{w:768,h:1376},"2K":{w:1536,h:2752},"4K":{w:3072,h:5504}},"16:9":{"0.5K":{w:688,h:384},"1K":{w:1376,h:768},"2K":{w:2752,h:1536},"4K":{w:5504,h:3072}},"21:9":{"0.5K":{w:792,h:168},"1K":{w:1584,h:672},"2K":{w:3168,h:1344},"4K":{w:6336,h:2688}}},"Gemini 3 Pro":{"1:1":{"1K":{w:1024,h:1024},"2K":{w:2048,h:2048},"4K":{w:4096,h:4096}},"2:3":{"1K":{w:848,h:1264},"2K":{w:1696,h:2528},"4K":{w:3392,h:5056}},"3:2":{"1K":{w:1264,h:848},"2K":{w:2528,h:1696},"4K":{w:5056,h:3392}},"3:4":{"1K":{w:896,h:1200},"2K":{w:1792,h:2400},"4K":{w:3584,h:4800}},"4:3":{"1K":{w:1200,h:896},"2K":{w:2400,h:1792},"4K":{w:4800,h:3584}},"4:5":{"1K":{w:928,h:1152},"2K":{w:1856,h:2304},"4K":{w:3712,h:4608}},"5:4":{"1K":{w:1152,h:928},"2K":{w:2304,h:1856},"4K":{w:4608,h:3712}},"9:16":{"1K":{w:768,h:1376},"2K":{w:1536,h:2752},"4K":{w:3072,h:5504}},"16:9":{"1K":{w:1376,h:768},"2K":{w:2752,h:1536},"4K":{w:5504,h:3072}},"21:9":{"1K":{w:1584,h:672},"2K":{w:3168,h:1344},"4K":{w:6336,h:2688}}}};function xi(e,t,o){let r=rG[e][t];if(!r)return{width:1024,height:1024};let a=r[o];if(!a){let i=Object.values(r)[0];return{width:i.w,height:i.h}}return{width:a.w,height:a.h}}function aG(e){return e==="0.5K"?"512px":e}async function yi(e,t,o,n,r,a,i,s,l){let c=[{text:e}];if(s){let y=s.match(/^data:([^;]+);base64,(.+)$/);y&&c.unshift({inlineData:{mimeType:y[1],data:y[2]}})}let m={aspectRatio:o};r&&(m.imageSize=aG(n));let p={responseModalities:["IMAGE","TEXT"],imageConfig:m,temperature:.1};a&&(p.thinkingConfig={thinkingLevel:"High",includeThoughts:!0});let d={contents:[{parts:c}],generationConfig:p},u=await fetch(`https://generativelanguage.googleapis.com/v1beta/models/${t}:generateContent`,{method:"POST",signal:l,headers:{"x-goog-api-key":i,"Content-Type":"application/json"},body:JSON.stringify(d)});if(!u.ok){let y=`Gemini API error ${u.status}`;try{let w=await u.json();w?.error?.message&&(y=w.error.message)}catch{}throw new Error(y)}let x=((await u.json())?.candidates?.[0]?.content?.parts??[]).find(y=>y.inlineData?.data);if(!x?.inlineData?.data)throw new Error("No image was returned by the API.");return`data:${x.inlineData.mimeType??"image/png"};base64,${x.inlineData.data}`}var W0=()=>we("svg",{width:"9",height:"9",viewBox:"0 0 10 10",fill:"none",children:we("path",{d:"M2.5 3.75L5 6.25L7.5 3.75",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round"})}),Y0=()=>we("svg",{width:"12",height:"12",viewBox:"0 0 14 14",fill:"none",children:we("path",{d:"M2.5 7.5L5.5 10.5L11.5 3.5",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round"})}),iG=()=>we("svg",{width:"13",height:"13",viewBox:"0 0 16 16",fill:"none",children:we("path",{d:"M8 2L10.5 5.5H13.5L11.5 8L13 11.5L8 9.5L3 11.5L4.5 8L2.5 5.5H5.5L8 2Z",stroke:"currentColor",strokeWidth:"1.3",strokeLinejoin:"round"})}),sG=()=>Mt("svg",{width:"12",height:"12",viewBox:"0 0 14 14",fill:"none",children:[we("circle",{cx:"7",cy:"7",r:"5.5",stroke:"currentColor",strokeWidth:"1.2"}),we("path",{d:"M7 6.5V10",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round"}),we("circle",{cx:"7",cy:"4.5",r:"0.75",fill:"currentColor"})]}),lG=()=>we("svg",{width:"15",height:"15",viewBox:"0 0 14 14",fill:"none",className:"igp-spinner",children:we("circle",{cx:"7",cy:"7",r:"5.5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeDasharray:"20 14"})}),cG=({label:e})=>{let o={"21:9":{width:21,height:9},"16:9":{width:18,height:10},"4:3":{width:16,height:12},"3:2":{width:15,height:10},"1:1":{width:13,height:13},"9:16":{width:10,height:18},"3:4":{width:12,height:16},"2:3":{width:10,height:15},"5:4":{width:15,height:12},"4:5":{width:12,height:15},"4:1":{width:24,height:6},"1:4":{width:6,height:24},"8:1":{width:24,height:3},"1:8":{width:3,height:24}}[e]??{width:13,height:13};return we("div",{style:{border:"1.5px solid currentColor",borderRadius:2,boxSizing:"border-box",display:"inline-block",flexShrink:0,color:"#999",...o}})},Mk=({element:e,app:t,onBeforeImageGen:o,onAfterImageGen:n})=>{let r=Y=>{let oe=Y.customData?.imageGenerator;return oe?{model:oe.model,ratio:oe.ratio,resolution:oe.resolution}:null},a=t.state,i=dl(t.props.geminiApiKey),[s,l]=Zn(()=>Iu(e.id)),[c,m]=Zn(()=>{let Y=r(e),oe=pa(e.id);return Y?.model??oe?.model??"Gemini 3.1 Flash"}),p=ga[c],d=p.supportedRatios,u=p.supportedResolutions,h=d.includes("2:3")?"2:3":d[0],g=u.includes("2K")?"2K":u[u.length-1],[x,E]=Zn(()=>{let Y=r(e),oe=pa(e.id);return Y?.ratio??oe?.ratio??h}),[y,w]=Zn(()=>{let Y=r(e),oe=pa(e.id);return Y?.resolution??oe?.resolution??g}),v=bi(Y=>{t.scene.mutateElement(e,{customData:{...e.customData??{},imageGenerator:Y}})},[t.scene,e]),I=bi((Y,oe=!1)=>{t.scrollToContent(Y,{fitToViewport:!0,viewportZoomFactor:.8,animate:oe,canvasOffsets:t.getEditorUIOffsets()})},[t]),C=ua(!0);dd(()=>{if(C.current){C.current=!1;return}let Y=ga[c],oe=Y.supportedRatios,De=oe.includes(x),ft=x;De||(ft=oe.includes("2:3")?"2:3":oe[0],E(ft));let $t=Y.supportedResolutions,Oo=$t.includes(y),Pn=y;Oo||(Pn=$t.includes("2K")?"2K":$t[$t.length-1],w(Pn));let Fr=xi(c,ft,Pn);t.scene.mutateElement(e,{width:Fr.width,height:Fr.height}),v({model:c,ratio:ft,resolution:Pn}),t.syncActionResult({captureUpdate:U0.IMMEDIATELY})},[c,t,e,v]);let[P,S]=Zn(()=>hi(e.id)),[D,_]=Zn(null),[k,M]=Zn(null),[B,O]=Zn(!1),[N,z]=Zn(!1),[L,F]=Zn(!1),$=ua(null),Q=ua(null),Z=ua(null),U=ua(null),q=ua(null),re=ua(e),J=ua(t);dd(()=>{re.current=e,J.current=t}),dd(()=>{if(!e.customData?.imageGeneratorAutoFitPending)return;let Y=0,oe=!1,De=()=>{oe||(I(e),t.scene.mutateElement(e,{customData:{...e.customData??{},imageGeneratorAutoFitPending:!1}}))};return Y=window.requestAnimationFrame(()=>{Y=window.requestAnimationFrame(De)}),()=>{oe=!0,window.cancelAnimationFrame(Y)}},[t.scene,e,I]);let se=bi(Y=>{E(Y),O(!1);let oe=xi(c,Y,y);J.current.scene.mutateElement(re.current,{width:oe.width,height:oe.height,customData:{...re.current.customData??{},imageGenerator:{model:c,ratio:Y,resolution:y}}}),J.current.syncActionResult({captureUpdate:U0.IMMEDIATELY})},[c,y]),fe=bi(Y=>{w(Y),z(!1);let oe=xi(c,x,Y);J.current.scene.mutateElement(re.current,{width:oe.width,height:oe.height,customData:{...re.current.customData??{},imageGenerator:{model:c,ratio:x,resolution:Y}}}),J.current.syncActionResult({captureUpdate:U0.IMMEDIATELY})},[c,x]);dd(()=>{let Y=oe=>{$.current&&!$.current.contains(oe.target)&&O(!1),Q.current&&!Q.current.contains(oe.target)&&z(!1),Z.current&&!Z.current.contains(oe.target)&&F(!1)};return document.addEventListener("mousedown",Y),()=>document.removeEventListener("mousedown",Y)},[]),dd(()=>{let Y=oe=>{S(!1),oe?oe!=="aborted"&&_(oe):_(null)};return yu(e.id,Y),()=>Eu(e.id,Y)},[e.id]);let Me=bi(Y=>{let oe=Y.target.files?.[0];if(!oe)return;let De=new FileReader;De.onload=()=>M(De.result),De.readAsDataURL(oe),Y.target.value=""},[]),ct=bi(()=>{vu(e.id)},[e.id]),Lt=bi(async()=>{if(!s.trim()){_("Please enter a prompt.");return}if(!i){_("No Gemini API key found. Set VITE_APP_GEMINI_API_KEY in .env.");return}if(o)try{let{allowed:De,error:ft}=await o();if(!De){_(ft||"Insufficient credits for image generation");return}}catch{_("Credit check failed");return}let Y=new AbortController;q.current=Y,bu(e.id,s,{model:c,ratio:x,resolution:y},Y),S(!0),_(null);let oe=null;try{let De=ga[c],ft=await yi(s,De.geminiModelId,x,y,De.supportsImageSize,De.supportsThinking,i,k??void 0,Y.signal);await t.insertGeneratedImageIntoFrame(ft,e),n?.()}catch(De){De instanceof Error&&(De.name==="AbortError"?oe="aborted":oe=De.message)}finally{q.current=null,xu(e.id,oe),S(!1),oe===null?(wu(e.id),l(""),M(null),_(null)):oe!=="aborted"&&_(oe)}},[s,i,c,x,y,k,t,e,o,n]);if(a.contextMenu||a.newElement||a.resizingElement||a.isRotating||a.openMenu||a.viewModeEnabled||a.selectedElementsAreBeingDragged)return null;let[Sn,,,Mn]=eG(e,t.scene.getNonDeletedElementsMap()),{x:eo,y:Gt}=QH({sceneX:Sn+e.width/2,sceneY:Mn},a),yt=eo-a.offsetLeft,dr=Gt-a.offsetTop+16;return Mt("div",{className:"igp",style:{left:`${yt}px`,top:`${dr}px`},onPointerDown:Y=>Y.stopPropagation(),onClick:Y=>Y.stopPropagation(),children:[we("input",{ref:U,type:"file",accept:"image/*",style:{display:"none"},onChange:Me}),Mt(ml,{isLoading:P,value:s,onValueChange:l,onSubmit:Lt,className:"igp-container",children:[k&&Mt("div",{className:"igp-ref-chip",children:[we("img",{src:k,alt:"Reference"}),we("span",{children:"Reference image"}),we("button",{onClick:()=>M(null),title:"Remove",children:we(nG,{size:10})})]}),we(pl,{placeholder:"What are we creating today\u2026",className:"igp-textarea",disableAutosize:!1}),D&&we("div",{className:"igp-error",children:D}),Mt(ul,{className:"igp-actions",children:[Mt("div",{className:"igp-actions-left",children:[Mt("div",{className:"igp-dropdown-root",ref:Z,children:[we(Pr,{tooltip:"Select model",side:"top",children:Mt("button",{className:"igp-btn",onClick:()=>{F(Y=>!Y),O(!1),z(!1)},disabled:P,children:[we(iG,{}),we("span",{children:c}),we(W0,{})]})}),L&&we("div",{className:"igp-dropdown igp-dropdown--up igp-dropdown--left",children:$0.map(Y=>Mt("button",{className:"igp-dropdown-item",onClick:()=>{v({model:Y,ratio:x,resolution:y}),m(Y),F(!1)},children:[we("span",{style:{flex:1},children:Y}),Y===c&&we("span",{className:"igp-check",children:we(Y0,{})})]},Y))})]}),we(Pr,{tooltip:"Add reference image",side:"top",children:we("button",{className:`igp-btn igp-btn--icon${k?" igp-btn--active":""}`,onClick:()=>U.current?.click(),disabled:P,children:we(oG,{size:15})})})]}),Mt("div",{className:"igp-actions-right",children:[Mt("div",{className:"igp-dropdown-root",ref:Q,children:[Mt("button",{className:"igp-btn igp-btn--compact",onClick:()=>{u.length<=1||(z(Y=>!Y),O(!1),F(!1))},disabled:P||u.length<=1,title:u.length<=1?"Fixed resolution for this model":void 0,children:[we("span",{children:y}),u.length>1&&we(W0,{})]}),N&&u.length>1&&we("div",{className:"igp-dropdown igp-dropdown--up igp-dropdown--right",children:u.map(Y=>Mt("button",{className:"igp-dropdown-item",onClick:()=>fe(Y),children:[we("span",{style:{flex:1},children:Y}),Y===y&&we("span",{className:"igp-check",children:we(Y0,{})})]},Y))})]}),Mt("div",{className:"igp-dropdown-root",ref:$,children:[Mt("button",{className:"igp-btn igp-btn--compact",onClick:()=>{O(Y=>!Y),z(!1),F(!1)},disabled:P,children:[we("span",{children:x}),we(W0,{})]}),B&&Mt("div",{className:"igp-dropdown igp-dropdown--up igp-dropdown--right igp-dropdown--ratio",children:[Mt("div",{className:"igp-dropdown-header",children:[we("span",{children:"Format"}),we(sG,{})]}),d.map(Y=>{let oe=xi(c,Y,y);return Mt("button",{className:"igp-dropdown-item",onClick:()=>se(Y),children:[we(cG,{label:Y}),we("span",{style:{flex:1},children:Y}),Mt("span",{className:"igp-dims",children:[oe.width,"\xD7",oe.height]}),Y===x&&we("span",{className:"igp-check",children:we(Y0,{})})]},Y)})]})]}),we("button",{className:"igp-generate",onClick:P?ct:Lt,disabled:!P&&!s.trim(),title:P?"Stop generation":"Generate image",children:P?we(lG,{}):we(tG,{size:16})})]})]})]})]})};function ha(e){if(!e||e==="transparent"||e==="rgba(0, 0, 0, 0)")return"transparent";if(e.startsWith("#"))return e;let t=e.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([0-9.]+))?\)/);if(!t)return e;let o=parseInt(t[1],10),n=parseInt(t[2],10),r=parseInt(t[3],10);return`#${o.toString(16).padStart(2,"0")}${n.toString(16).padStart(2,"0")}${r.toString(16).padStart(2,"0")}`}function dG(e){let t=e.match(/rgba\(\d+,\s*\d+,\s*\d+,\s*([0-9.]+)\)/);return t?Math.round(parseFloat(t[1])*100):100}function mG(e,t){let o=e.toLowerCase();if(t){for(let[n,r]of Object.entries(t))if(o.includes(n))return r}return o.includes("sans-serif")||o.includes("arial")||o.includes("helvetica")||o.includes("verdana")||o.includes("impact")||o.includes("nunito")||o.includes("roboto")||o.includes("inter")||o.includes("liberation sans")||o.includes("tahoma")||o.includes("trebuchet")?2:o.includes("georgia")||o.includes("serif")||o.includes("cursive")||o.includes("script")||o.includes("times")||o.includes("playfair")?1:o.includes("courier")||o.includes("mono")||o.includes("cascadia")?3:2}function pG(e,t){switch(t){case"uppercase":return e.toUpperCase();case"lowercase":return e.toLowerCase();case"capitalize":return e.replace(/\b\w/g,o=>o.toUpperCase());default:return e}}function uG(e){let t=parseFloat(e);return isNaN(t)?16:Math.round(t)}function gG(e){let t=e.borderTopLeftRadius||"0",o=parseFloat(t);return isNaN(o)?0:Math.round(o)}function hG(e,t,o){let n=e.borderTopLeftRadius||"0";if(n.includes("%")){let r=parseFloat(n);if(!isNaN(r)&&r>=50)return!0}else{let r=parseFloat(n);if(!isNaN(r)&&r>0&&r>=t/2&&r>=o/2)return!0}return!1}function fG(e){return e!=="none"&&(e.includes("linear-gradient")||e.includes("radial-gradient"))}function bG(e){let t=[...e.matchAll(/(#[\da-fA-F]{3,8}|rgba?\([^)]+\))/g)];if(t.length===0)return"#1a1a2e";if(t.length===1||e.includes("repeating"))return ha(t[0][1]);let o=ha(t[0][1]).replace("#","").padEnd(6,"0"),n=ha(t[t.length-1][1]).replace("#","").padEnd(6,"0"),r=parseInt(o.slice(0,2),16),a=parseInt(o.slice(2,4),16),i=parseInt(o.slice(4,6),16),s=parseInt(n.slice(0,2),16),l=parseInt(n.slice(2,4),16),c=parseInt(n.slice(4,6),16),m=(p,d)=>Math.round((p+d)/2).toString(16).padStart(2,"0");return`#${m(r,s)}${m(a,l)}${m(i,c)}`}function xG(e){let t=e.match(/url\("?(data:[^")]+)"?\)/);return t?t[1]:null}function yG(e){return e==="center"?"center":e==="right"||e==="end"?"right":"left"}var Ak=new Set(["SPAN","EM","STRONG","B","I","A","LABEL"]);function Pk(e){let t="",o=!1;for(let r of e.childNodes)if(r.nodeType===Node.TEXT_NODE){let a=r.textContent||"";a.trim()&&(o=!0),t+=a}else if(r.nodeType===Node.ELEMENT_NODE){let a=r;if(a.tagName==="BR")t+=`
|
|
14
|
+
C ${l} ${c}, ${l} ${c}, ${l+x} ${c+E}`,Tr(e,!0,i))}else s=t.polygon([[l,c],[m,p],[d,u],[h,g]],Tr(e,!1,i));return s}case"ellipse":return t.ellipse(e.width/2,e.height/2,e.width,e.height,Tr(e,!1,i));case"line":case"arrow":{let s,l=Tr(e,!1,i),c=e.points.length?e.points:[vz(0,0)];if(jc(e)?c.every(m=>Math.abs(m[0])<=1e6&&Math.abs(m[1])<=1e6)?s=[t.path(Az(c,16),Tr(e,!0,i))]:(console.error("Elbow arrow with extreme point positions detected. Arrow not rendered.",e.id,JSON.stringify(c)),s=[]):e.roundness?s=[t.curve(c,l)]:l.fill?s=[t.polygon(c,l)]:s=[t.linearPath(c,l)],e.type==="arrow"){let{startArrowhead:m=null,endArrowhead:p="arrow"}=e;if(m!==null){let d=R5(e,s,"start",m,t,l,n,i);s.push(...d)}if(p!==null){let d=R5(e,s,"end",p,t,l,n,i);s.push(...d)}}return s}case"freedraw":{let s=[];if(tu(e.points)){let l=Ez(e.points,.75);s.push(t.curve(l,{...Tr(e,!1,i),stroke:"none"}))}return s.push(Lz(e)),s}case"frame":case"magicframe":case"text":case"image":return null;default:return Tz(e,`generateElementShape(): Unimplemented type ${e?.type}`),null}},Az=(e,t)=>{let o=[];for(let r=1;r<e.length-1;r+=1){let a=e[r-1],i=e[r+1],s=e[r],l=au(s,a),c=au(i,s),m=Math.min(t,_5(e[r],i)/2,_5(e[r],a)/2);l?a[0]<s[0]?o.push([e[r][0]-m,e[r][1]]):o.push([e[r][0]+m,e[r][1]]):a[1]<s[1]?o.push([e[r][0],e[r][1]-m]):o.push([e[r][0],e[r][1]+m]),o.push(e[r]),c?i[0]<s[0]?o.push([e[r][0]-m,e[r][1]]):o.push([e[r][0]+m,e[r][1]]):i[1]<s[1]?o.push([e[r][0],e[r][1]-m]):o.push([e[r][0],e[r][1]+m])}let n=[`M ${e[0][0]} ${e[0][1]}`];for(let r=0;r<o.length;r+=3)n.push(`L ${o[r][0]} ${o[r][1]}`),n.push(`Q ${o[r+1][0]} ${o[r+1][1]}, ${o[r+2][0]} ${o[r+2][1]}`);return n.push(`L ${e[e.length-1][0]} ${e[e.length-1][1]}`),n.join(" ")};var Lz=e=>Rz(_z(e)),_z=e=>{let t=e.simulatePressure?e.points:e.points.length?e.points.map(([o,n],r)=>[o,n,e.pressures[r]]):[[0,0,.5]];return wz(t,{simulatePressure:e.simulatePressure,size:e.strokeWidth*4.25,thinning:.6,smoothing:.5,streamline:.5,easing:o=>Math.sin(o*Math.PI/2),last:!0})},N5=(e,t)=>[(e[0]+t[0])/2,(e[1]+t[1])/2],Dz=/(\s?[A-Z]?,?-?[0-9]*\.[0-9]{0,2})(([0-9]|e|-)*)/g,Rz=e=>{if(!e.length)return"";let t=e.length-1;return e.reduce((o,n,r,a)=>(r===t?o.push(n,N5(n,a[0]),"L",a[0],"Z"):o.push(n,N5(n,a[r+1])),o),["M",e[0],"Q"]).join(" ").replace(Dz,"$1")};var F5=(e,t,o=!1)=>{let n=!1;for(let r in t){let a=t[r];if(typeof a<"u"){if(e[r]===a&&(typeof a!="object"||a===null))continue;n=!0}}return!n&&!o?e:{...e,...t,version:t.version??e.version+1,versionNonce:t.versionNonce??Nz(),updated:Bz()}};import{jsx as z5}from"react/jsx-runtime";var il=W({name:"toggleLinearEditor",category:it.elements,label:(e,t,o)=>o.scene.getSelectedElements({selectedElementIds:t.selectedElementIds})[0]?.type==="arrow"?"labels.lineEditor.editArrow":"labels.lineEditor.edit",keywords:["line"],trackEvent:{category:"element"},predicate:(e,t,o,n)=>{let r=n.scene.getSelectedElements(t);return!!(!t.selectedLinearElement?.isEditing&&r.length===1&&Oz(r[0])&&!Fz(r[0]))},perform(e,t,o,n){let r=n.scene.getSelectedElements({selectedElementIds:t.selectedElementIds,includeBoundTextElement:!0})[0];I0(r,"No selected element found"),I0(t.selectedLinearElement,"No selected linear element found"),I0(r.id===t.selectedLinearElement.elementId,"Selected element ID and linear editor elementId does not match");let a={...t.selectedLinearElement,isEditing:!t.selectedLinearElement.isEditing};return{appState:{...t,selectedLinearElement:a},captureUpdate:O5.IMMEDIATELY}},PanelComponent:({appState:e,updateData:t,app:o})=>{let n=o.scene.getSelectedElements({selectedElementIds:e.selectedElementIds})[0];if(!n)return null;let r=f(n.type==="arrow"?"labels.lineEditor.editArrow":"labels.lineEditor.edit");return z5(ie,{type:"button",icon:dv,title:r,"aria-label":r,onClick:()=>t(null)})}}),xSe=W({name:"togglePolygon",category:it.elements,icon:hh,keywords:["loop"],label:(e,t,o)=>!o.scene.getSelectedElements({selectedElementIds:t.selectedElementIds}).some(a=>!al(a)||!a.polygon)?"labels.polygon.breakPolygon":"labels.polygon.convertToPolygon",trackEvent:{category:"element"},predicate:(e,t,o,n)=>{let r=n.scene.getSelectedElements({selectedElementIds:t.selectedElementIds});return r.length>0&&r.every(a=>al(a)&&a.points.length>=4)},perform(e,t,o,n){let r=n.scene.getSelectedElements(t);if(r.some(l=>!al(l)))return!1;let a=r,i=a.some(l=>!l.polygon),s=zz(a);return{elements:e.map(l=>!s.has(l.id)||!al(l)?l:F5(l,{backgroundColor:i?l.backgroundColor:"transparent",...Hz(l,i)})),appState:t,captureUpdate:O5.IMMEDIATELY}},PanelComponent:({appState:e,updateData:t,app:o})=>{let n=o.scene.getSelectedElements({selectedElementIds:e.selectedElementIds});if(n.length===0||n.some(i=>!al(i)||!i.polygon||i.points.length<3))return null;let r=n.every(i=>al(i)&&i.polygon),a=f(r?"labels.polygon.breakPolygon":"labels.polygon.convertToPolygon");return z5(hs,{icon:hh,title:a,"aria-label":a,active:r,onClick:()=>t(null),style:{marginLeft:"auto"}})}});import{KEYS as H5,CANVAS_SEARCH_TAB as G5,CLASSES as Gz,DEFAULT_SIDEBAR as U5}from"@orangecatai/common";import{CaptureUpdateAction as Uz}from"@orangecatai/element";var Zc=W({name:"searchMenu",icon:Mo,keywords:["search","find"],label:"search.title",viewMode:!0,trackEvent:{category:"search_menu",action:"toggle",predicate:e=>e.gridModeEnabled},perform(e,t,o,n){if(t.openDialog)return!1;if(t.openSidebar?.name===U5.name&&t.openSidebar.tab===G5){let r=n.excalidrawContainerValue.container?.querySelector(`.${Gz.SEARCH_MENU_INPUT_WRAPPER} input`);return r?.focus(),r?.select(),!1}return{appState:{...t,openSidebar:{name:U5.name,tab:G5},openDialog:null},captureUpdate:Uz.EVENTUALLY}},checked:e=>e.gridModeEnabled,predicate:(e,t,o)=>o.gridModeEnabled===void 0,keyTest:e=>e[H5.CTRL_OR_CMD]&&e.key===H5.F});import{isImageElement as Wz}from"@orangecatai/element";import{CaptureUpdateAction as Yz}from"@orangecatai/element";import{jsx as $z}from"react/jsx-runtime";var ed=W({name:"cropEditor",label:"helpDialog.cropStart",icon:Fh,viewMode:!0,trackEvent:{category:"menu"},keywords:["image","crop"],perform(e,t,o,n){let r=n.scene.getSelectedElements({selectedElementIds:t.selectedElementIds,includeBoundTextElement:!0})[0];return{appState:{...t,isCropping:!1,croppingElementId:r.id},captureUpdate:Yz.IMMEDIATELY}},predicate:(e,t,o,n)=>{let r=n.scene.getSelectedElements(t);return!!(!t.croppingElementId&&r.length===1&&Wz(r[0]))},PanelComponent:({appState:e,updateData:t,app:o})=>{let n=f("helpDialog.cropStart");return $z(ie,{type:"button",icon:Fh,title:n,"aria-label":n,onClick:()=>t(null)})}});import{getNonDeletedElements as Vz}from"@orangecatai/element";import{mutateElement as Kz}from"@orangecatai/element";import{newFrameElement as Xz}from"@orangecatai/element";import{isFrameLikeElement as du}from"@orangecatai/element";import{addElementsToFrame as Zz,removeAllElementsFromFrame as jz}from"@orangecatai/element";import{getFrameChildren as qz}from"@orangecatai/element";import{KEYS as W5,updateActiveTool as Y5}from"@orangecatai/common";import{getElementsInGroup as Jz}from"@orangecatai/element";import{getCommonBounds as Qz}from"@orangecatai/element";import{CaptureUpdateAction as mi}from"@orangecatai/element";var $5=(e,t)=>{let o=t.scene.getSelectedElements(e);return o.length===1&&du(o[0])},V5=W({name:"selectAllElementsInFrame",label:"labels.selectAllElementsInFrame",trackEvent:{category:"canvas"},perform:(e,t,o,n)=>{let r=n.scene.getSelectedElements(t).at(0)||null;if(du(r)){let a=qz(Vz(e),r.id).filter(i=>!(i.type==="text"&&i.containerId));return{elements:e,appState:{...t,selectedElementIds:a.reduce((i,s)=>(i[s.id]=!0,i),{})},captureUpdate:mi.IMMEDIATELY}}return{elements:e,appState:t,captureUpdate:mi.EVENTUALLY}},predicate:(e,t,o,n)=>$5(t,n)}),K5=W({name:"removeAllElementsFromFrame",label:"labels.removeAllElementsFromFrame",trackEvent:{category:"history"},perform:(e,t,o,n)=>{let r=n.scene.getSelectedElements(t).at(0)||null;return du(r)?{elements:jz(e,r),appState:{...t,selectedElementIds:{[r.id]:!0}},captureUpdate:mi.IMMEDIATELY}:{elements:e,appState:t,captureUpdate:mi.EVENTUALLY}},predicate:(e,t,o,n)=>$5(t,n)}),SMe=W({name:"updateFrameRendering",label:"labels.updateFrameRendering",viewMode:!0,trackEvent:{category:"canvas"},perform:(e,t)=>({elements:e,appState:{...t,frameRendering:{...t.frameRendering,enabled:!t.frameRendering.enabled}},captureUpdate:mi.EVENTUALLY}),checked:e=>e.frameRendering.enabled}),MMe=W({name:"setFrameAsActiveTool",label:"toolBar.frame",trackEvent:{category:"toolbar"},icon:On,viewMode:!1,perform:(e,t,o,n)=>{let r=Y5(t,{type:"frame"});return Ao(n.interactiveCanvas,{...t,activeTool:r}),{elements:e,appState:{...t,activeTool:Y5(t,{type:"frame"})},captureUpdate:mi.EVENTUALLY}},keyTest:e=>!e[W5.CTRL_OR_CMD]&&!e.shiftKey&&!e.altKey&&e.key.toLocaleLowerCase()===W5.F}),X5=W({name:"wrapSelectionInFrame",label:"labels.wrapSelectionInFrame",trackEvent:{category:"element"},predicate:(e,t,o,n)=>{let r=de(e,t);return r.length>0&&!r.some(a=>du(a))},perform:(e,t,o,n)=>{let r=de(e,t),a=n.scene.getNonDeletedElementsMap(),[i,s,l,c]=Qz(r,a),m=16,p=Xz({x:i-m,y:s-m,width:l-i+m*2,height:c-s+m*2});if(t.editingGroupId){let u=Jz(r,t.editingGroupId);for(let h of u){let g=h.groupIds.indexOf(t.editingGroupId);Kz(h,a,{groupIds:h.groupIds.slice(0,g)})}}return{elements:Zz([...n.scene.getElementsIncludingDeleted(),p],r,p,t),appState:{selectedElementIds:{[p.id]:!0}},captureUpdate:mi.IMMEDIATELY}}});import{isWindows as iH,KEYS as od,matchKey as k0,arrayToMap as Z5,MOBILE_ACTION_BUTTON_BG as j5}from"@orangecatai/common";import{CaptureUpdateAction as C0}from"@orangecatai/element";import{orderByFractionalIndex as sH}from"@orangecatai/element";import{Emitter as eH}from"@orangecatai/common";import{CaptureUpdateAction as tH,StoreChange as oH,StoreDelta as nH}from"@orangecatai/element";var sl=class extends nH{applyTo(t,o,n){let[r,a]=this.elements.applyTo(t,n.elements,{excludedProperties:new Set(["version","versionNonce"])}),[i,s]=this.appState.applyTo(o,r);return[r,i,a||s]}static calculate(t,o){return super.calculate(t,o)}static inverse(t){return super.inverse(t)}static applyLatestChanges(t,o,n,r){return super.applyLatestChanges(t,o,n,r)}},pi=class{constructor(t=!0,o=!0){this.isUndoStackEmpty=t;this.isRedoStackEmpty=o}},td=class e{constructor(t){this.store=t;A(this,"onHistoryChangedEmitter",new eH);A(this,"undoStack",[]);A(this,"redoStack",[])}get isUndoStackEmpty(){return this.undoStack.length===0}get isRedoStackEmpty(){return this.redoStack.length===0}clear(){this.undoStack.length=0,this.redoStack.length=0}record(t){if(t.isEmpty()||t instanceof sl)return;let o=sl.inverse(t);this.undoStack.push(o),o.elements.isEmpty()||(this.redoStack.length=0),this.onHistoryChangedEmitter.trigger(new pi(this.isUndoStackEmpty,this.isRedoStackEmpty))}undo(t,o){return this.perform(t,o,()=>e.pop(this.undoStack),n=>e.push(this.redoStack,n))}redo(t,o){return this.perform(t,o,()=>e.pop(this.redoStack),n=>e.push(this.undoStack,n))}perform(t,o,n,r){try{let a=n();if(a===null)return;let i=tH.IMMEDIATELY,s=this.store.snapshot,l=t,c=o,m=!1;for(;a;){try{[l,c,m]=a.applyTo(l,c,s);let p=s.elements,d=s.maybeClone(i,l,c),u=oH.create(s,d),h=sl.applyLatestChanges(a,p,l);h.isEmpty()||(this.store.scheduleMicroAction({action:i,change:u,delta:h}),a=h),s=d}finally{r(a)}if(m)break;a=n()}return[l,c]}finally{this.onHistoryChangedEmitter.trigger(new pi(this.isUndoStackEmpty,this.isRedoStackEmpty))}}static pop(t){if(!t.length)return null;let o=t.pop();return o!==void 0?o:null}static push(t,o){let n=sl.inverse(o);return t.push(n)}};import{useEffect as rH,useState as aH}from"react";var T0=(e,t)=>{let[o,n]=aH(t);return rH(()=>{let r=e.on(a=>{n(a)});return()=>{r()}},[e]),o};import{jsx as ek}from"react/jsx-runtime";var q5=(e,t,o)=>{if(!t.multiElement&&!t.resizingElement&&!t.editingTextElement&&!t.newElement&&!t.selectedElementsAreBeingDragged&&!t.selectionElement&&!e.flowChartCreator.isCreatingChart){let n=o();if(!n)return{captureUpdate:C0.EVENTUALLY};let[r,a]=n,i=sH(Array.from(r.values()));return{appState:a,elements:i,captureUpdate:C0.NEVER}}return{captureUpdate:C0.EVENTUALLY}},J5=e=>({name:"undo",label:"buttons.undo",icon:yh,trackEvent:{category:"history"},viewMode:!1,perform:(t,o,n,r)=>q5(r,o,()=>e.undo(Z5(t),o)),keyTest:t=>t[od.CTRL_OR_CMD]&&k0(t,od.Z)&&!t.shiftKey,PanelComponent:({appState:t,updateData:o,data:n,app:r})=>{let{isUndoStackEmpty:a}=T0(e.onHistoryChangedEmitter,new pi(e.isUndoStackEmpty,e.isRedoStackEmpty)),i=Dt()==="mobile";return ek(ie,{type:"button",icon:yh,"aria-label":f("buttons.undo"),onClick:o,size:n?.size||"medium",disabled:a,"data-testid":"button-undo",style:{...i?j5:{}}})}}),Q5=e=>({name:"redo",label:"buttons.redo",icon:Eh,trackEvent:{category:"history"},viewMode:!1,perform:(t,o,n,r)=>q5(r,o,()=>e.redo(Z5(t),o)),keyTest:t=>t[od.CTRL_OR_CMD]&&t.shiftKey&&k0(t,od.Z)||iH&&t.ctrlKey&&!t.shiftKey&&k0(t,od.Y),PanelComponent:({appState:t,updateData:o,data:n,app:r})=>{let{isRedoStackEmpty:a}=T0(e.onHistoryChangedEmitter,new pi(e.isUndoStackEmpty,e.isRedoStackEmpty)),i=Dt()==="mobile";return ek(ie,{type:"button",icon:Eh,"aria-label":f("buttons.redo"),onClick:o,size:n?.size||"medium",disabled:a,"data-testid":"button-redo",style:{...i?j5:{}}})}});import{getFontString as lH}from"@orangecatai/common";import{newElementWith as cH}from"@orangecatai/element";import{measureText as dH}from"@orangecatai/element";import{isTextElement as tk}from"@orangecatai/element";import{CaptureUpdateAction as mH}from"@orangecatai/element";var ok=W({name:"autoResize",label:"labels.autoResize",icon:null,trackEvent:{category:"element"},predicate:(e,t,o,n)=>{let r=de(e,t);return r.length===1&&tk(r[0])&&!r[0].autoResize},perform:(e,t,o,n)=>{let r=de(e,t);return{appState:t,elements:e.map(a=>{if(a.id===r[0].id&&tk(a)){let i=dH(a.originalText,lH(a),a.lineHeight);return cH(a,{autoResize:!0,width:i.width,height:i.height,text:a.originalText})}return a}),captureUpdate:mH.IMMEDIATELY}}});import{isPromiseLike as pH}from"@orangecatai/common";import{jsx as uH}from"react/jsx-runtime";var S0=(e,t,o,n,r,a)=>{if(e.trackEvent)try{typeof e.trackEvent=="object"&&(!e.trackEvent.predicate||e.trackEvent.predicate(o,n,a))&&be(e.trackEvent.category,e.trackEvent.action||e.name,`${t} (${r.editorInterface.formFactor==="phone"?"mobile":"desktop"})`)}catch(i){console.error("error while logging action:",i)}},mu=class{constructor(t,o,n,r){A(this,"actions",{});A(this,"updater");A(this,"getAppState");A(this,"getElementsIncludingDeleted");A(this,"app");A(this,"renderAction",(t,o)=>{let n=this.app.props.UIOptions.canvasActions;if(this.actions[t]&&"PanelComponent"in this.actions[t]&&(!(t in n)||n[t])){let r=this.actions[t],a=r.PanelComponent;a.displayName="PanelComponent";let i=this.getElementsIncludingDeleted(),s=this.getAppState(),l=c=>{S0(r,"ui",s,i,this.app,c),this.updater(r.perform(this.getElementsIncludingDeleted(),this.getAppState(),c,this.app))};return uH(a,{elements:this.getElementsIncludingDeleted(),appState:this.getAppState(),updateData:l,appProps:this.app.props,app:this.app,data:o,renderAction:this.renderAction})}return null});A(this,"isActionEnabled",t=>{let o=this.getElementsIncludingDeleted(),n=this.getAppState();return!t.predicate||t.predicate(o,n,this.app.props,this.app)});this.updater=a=>{if(pH(a))a.then(i=>t(i));else return t(a)},this.getAppState=o,this.getElementsIncludingDeleted=n,this.app=r}registerAction(t){this.actions[t.name]=t}registerAll(t){t.forEach(o=>this.registerAction(o))}handleKeyDown(t){let o=this.app.props.UIOptions.canvasActions,n=Object.values(this.actions).sort((l,c)=>(c.keyPriority||0)-(l.keyPriority||0)).filter(l=>(l.name in o?o[l.name]:!0)&&l.keyTest&&l.keyTest(t,this.getAppState(),this.getElementsIncludingDeleted(),this.app));if(n.length!==1)return n.length>1&&console.warn("Canceling as multiple actions match this shortcut",n),!1;let r=n[0];if(this.getAppState().viewModeEnabled&&r.viewMode!==!0)return!1;let a=this.getElementsIncludingDeleted(),i=this.getAppState(),s=null;return S0(r,"keyboard",i,a,this.app,null),t.preventDefault(),t.stopPropagation(),this.updater(n[0].perform(a,i,s,this.app)),!0}executeAction(t,o="api",n=null){let r=this.getElementsIncludingDeleted(),a=this.getAppState();S0(t,o,a,r,this.app,n),this.updater(t.perform(r,a,n,this.app))}};var pu=class{constructor(){A(this,"targets",new WeakMap);A(this,"rafIds",new WeakMap)}register(t,o){this.targets.set(t,{callback:o,stopped:!0})}start(t){let o=this.targets.get(t);o&&(this.rafIds.has(t)||(this.targets.set(t,{...o,stopped:!1}),this.scheduleFrame(t)))}stop(t){let o=this.targets.get(t);o&&!o.stopped&&this.targets.set(t,{...o,stopped:!0}),this.cancelFrame(t)}constructFrame(t){return o=>{let n=this.targets.get(t);if(!n)return;let r=this.onFrame(n,o);!n.stopped&&!r?this.scheduleFrame(t):this.cancelFrame(t)}}scheduleFrame(t){let o=requestAnimationFrame(this.constructFrame(t));this.rafIds.set(t,o)}cancelFrame(t){if(this.rafIds.has(t)){let o=this.rafIds.get(t);cancelAnimationFrame(o)}this.rafIds.delete(t)}onFrame(t,o){return t.callback(o)??!1}};var M0=e=>{let t=Array.from(e.values());return{x:nk(t,o=>o.x)/t.length,y:nk(t,o=>o.y)/t.length}},P0=([e,t])=>Math.hypot(e.x-t.x,e.y-t.y),nk=(e,t)=>e.reduce((o,n)=>o+t(n),0);import{pointFrom as ee,pointRotateRads as da,rangeInclusive as Zo,rangeIntersection as uu,rangesOverlap as gu}from"@orangecatai/math";import{TOOL_TYPE as ui,KEYS as rk}from"@orangecatai/common";import{getCommonBounds as A0,getDraggedElementsBounds as L0,getElementAbsoluteCoords as gH}from"@orangecatai/element";import{isBoundToContainer as lk}from"@orangecatai/element";import{getMaximumGroups as ck}from"@orangecatai/element";import{getSelectedElements as hH,getVisibleAndNonSelectedElements as dk}from"@orangecatai/element";var fH=8,ak=99999,hu=e=>fH/e,lo=class lo{};A(lo,"referenceSnapPoints",null),A(lo,"visibleGaps",null),A(lo,"setReferenceSnapPoints",t=>{lo.referenceSnapPoints=t}),A(lo,"getReferenceSnapPoints",()=>lo.referenceSnapPoints),A(lo,"setVisibleGaps",t=>{lo.visibleGaps=t}),A(lo,"getVisibleGaps",()=>lo.visibleGaps),A(lo,"destroy",()=>{lo.referenceSnapPoints=null,lo.visibleGaps=null});var jo=lo,ma=e=>e.props.gridModeEnabled??e.state.gridModeEnabled,kr=({event:e,app:t,selectedElements:o})=>{if(e){let n=t.state.activeTool.type==="lasso"&&t.state.selectedElementsAreBeingDragged;return(t.state.activeTool.type!=="lasso"||n)&&(t.state.objectsSnapModeEnabled&&!e[rk.CTRL_OR_CMD]||!t.state.objectsSnapModeEnabled&&e[rk.CTRL_OR_CMD]&&!ma(t))}return o.length===1&&o[0].type==="arrow"?!1:t.state.objectsSnapModeEnabled},bH=(e,t,o=.01)=>Math.abs(e-t)<=o,nd=(e,t,{omitCenter:o,boundingBoxCorners:n,dragOffset:r}={omitCenter:!1,boundingBoxCorners:!1})=>{let a=[];if(e.length===1){let i=e[0],[s,l,c,m,p,d]=gH(i,t);r&&(s+=r.x,c+=r.x,p+=r.x,l+=r.y,m+=r.y,d+=r.y);let u=(c-s)/2,h=(m-l)/2;if((i.type==="diamond"||i.type==="ellipse")&&!n){let g=da(ee(s,l+h),ee(p,d),i.angle),x=da(ee(s+u,l),ee(p,d),i.angle),E=da(ee(c,l+h),ee(p,d),i.angle),y=da(ee(s+u,m),ee(p,d),i.angle),w=ee(p,d);a=o?[g,x,E,y]:[g,x,E,y,w]}else{let g=da(ee(s,l),ee(p,d),i.angle),x=da(ee(c,l),ee(p,d),i.angle),E=da(ee(s,m),ee(p,d),i.angle),y=da(ee(c,m),ee(p,d),i.angle),w=ee(p,d);a=o?[g,x,E,y]:[g,x,E,y,w]}}else if(e.length>1){let[i,s,l,c]=L0(e,r??{x:0,y:0}),m=l-i,p=c-s,d=ee(i,s),u=ee(l,s),h=ee(i,c),g=ee(l,c),x=ee(i+m/2,s+p/2);a=o?[d,u,h,g]:[d,u,h,g,x]}return a.map(i=>ee(mt(i[0]),mt(i[1])))},mk=(e,t,o,n)=>dk(e,t,o,n),pk=(e,t,o,n)=>{let r=mk(e,t,o,n),a=ck(r,n).filter(p=>!(p.length===1&&lk(p[0]))).map(p=>A0(p).map(d=>mt(d))),i=a.sort((p,d)=>p[0]-d[0]),s=[],l=0;e:for(let p=0;p<i.length;p++){let d=i[p];for(let u=p+1;u<i.length;u++){if(++l>ak)break e;let h=i[u],[,g,x,E]=d,[y,w,,v]=h;x<y&&gu(Zo(g,E),Zo(w,v))&&s.push({startBounds:d,endBounds:h,startSide:[ee(x,g),ee(x,E)],endSide:[ee(y,w),ee(y,v)],length:y-x,overlap:uu(Zo(g,E),Zo(w,v))})}}let c=a.sort((p,d)=>p[1]-d[1]),m=[];l=0;e:for(let p=0;p<c.length;p++){let d=c[p];for(let u=p+1;u<c.length;u++){if(++l>ak)break e;let h=c[u],[g,,x,E]=d,[y,w,v]=h;E<w&&gu(Zo(g,x),Zo(y,v))&&m.push({startBounds:d,endBounds:h,startSide:[ee(g,E),ee(x,E)],endSide:[ee(y,w),ee(v,w)],length:w-E,overlap:uu(Zo(g,x),Zo(y,v))})}}return{horizontalGaps:s,verticalGaps:m}},ik=(e,t,o,n,r,a,i)=>{if(!kr({app:o,event:n,selectedElements:e}))return[];if(e.length===0)return[];let s=jo.getVisibleGaps();if(s){let{horizontalGaps:l,verticalGaps:c}=s,[m,p,d,u]=L0(e,t).map(x=>mt(x)),h=(m+d)/2,g=(p+u)/2;for(let x of l){if(!gu(Zo(p,u),x.overlap))continue;let E=x.startSide[0][0]+x.length/2,y=mt(E-h);if(x.length>d-m&&Math.abs(y)<=i.x){Math.abs(y)<i.x&&(r.length=0),i.x=Math.abs(y);let _={type:"gap",direction:"center_horizontal",gap:x,offset:y};r.push(_);continue}let[,,v]=x.endBounds,I=m-v,C=mt(x.length-I);if(Math.abs(C)<=i.x){Math.abs(C)<i.x&&(r.length=0),i.x=Math.abs(C);let _={type:"gap",direction:"side_right",gap:x,offset:C};r.push(_);continue}let[P,,,]=x.startBounds,S=P-d,D=mt(S-x.length);if(Math.abs(D)<=i.x){Math.abs(D)<i.x&&(r.length=0),i.x=Math.abs(D);let _={type:"gap",direction:"side_left",gap:x,offset:D};r.push(_);continue}}for(let x of c){if(!gu(Zo(m,d),x.overlap))continue;let E=x.startSide[0][1]+x.length/2,y=mt(E-g);if(x.length>u-p&&Math.abs(y)<=i.y){Math.abs(y)<i.y&&(a.length=0),i.y=Math.abs(y);let _={type:"gap",direction:"center_vertical",gap:x,offset:y};a.push(_);continue}let[,v,,]=x.startBounds,I=v-u,C=mt(I-x.length);if(Math.abs(C)<=i.y){Math.abs(C)<i.y&&(a.length=0),i.y=Math.abs(C);let _={type:"gap",direction:"side_top",gap:x,offset:C};a.push(_);continue}let[,,,P]=x.endBounds,S=mt(p-P),D=x.length-S;if(Math.abs(D)<=i.y){Math.abs(D)<i.y&&(a.length=0),i.y=Math.abs(D);let _={type:"gap",direction:"side_bottom",gap:x,offset:D};a.push(_);continue}}}},uk=(e,t,o,n)=>{let r=mk(e,t,o,n);return ck(r,n).filter(a=>!(a.length===1&&lk(a[0]))).flatMap(a=>nd(a,n))},ll=(e,t,o,n,r,a,i)=>{if(!kr({app:o,event:n,selectedElements:e})||e.length===0&&t.length===0)return[];let s=jo.getReferenceSnapPoints();if(s)for(let l of t)for(let c of s){let m=c[0]-l[0],p=c[1]-l[1];Math.abs(m)<=i.x&&(Math.abs(m)<i.x&&(r.length=0),r.push({type:"point",points:[l,c],offset:m}),i.x=Math.abs(m)),Math.abs(p)<=i.y&&(Math.abs(p)<i.y&&(a.length=0),a.push({type:"point",points:[l,c],offset:p}),i.y=Math.abs(p))}},gk=(e,t,o,n,r)=>{let a=o.state,i=hH(e,a);if(!kr({app:o,event:n,selectedElements:i})||i.length===0)return{snapOffset:{x:0,y:0},snapLines:[]};t.x=mt(t.x),t.y=mt(t.y);let s=[],l=[],c=hu(a.zoom.value),m={x:c,y:c},p=nd(i,r,{dragOffset:t});ll(i,p,o,n,s,l,m),ik(i,t,o,n,s,l,m);let d={x:s[0]?.offset??0,y:l[0]?.offset??0};m.x=0,m.y=0,s.length=0,l.length=0;let u={x:mt(t.x+d.x),y:mt(t.y+d.y)};ll(i,nd(i,r,{dragOffset:u}),o,n,s,l,m),ik(i,u,o,n,s,l,m);let h=_0(s,l),g=yH(i,u,[...s,...l].filter(x=>x.type==="gap"));return{snapOffset:d,snapLines:[...h,...g]}},mt=e=>Math.round(e*10**6)/10**6,sk=e=>{let t=new Map;for(let o of e){let n=o.join(",");t.has(n)||t.set(n,o)}return Array.from(t.values())},_0=(e,t)=>{let o={},n={};if(e.length>0){for(let r of e)if(r.type==="point"){let a=mt(r.points[0][0]);o[a]||(o[a]=[]),o[a].push(...r.points.map(i=>ee(mt(i[0]),mt(i[1]))))}}if(t.length>0){for(let r of t)if(r.type==="point"){let a=mt(r.points[0][1]);n[a]||(n[a]=[]),n[a].push(...r.points.map(i=>ee(mt(i[0]),mt(i[1]))))}}return Object.entries(o).map(([r,a])=>({type:"points",points:sk(a.map(i=>ee(Number(r),i[1])).sort((i,s)=>i[1]-s[1]))})).concat(Object.entries(n).map(([r,a])=>({type:"points",points:sk(a.map(i=>ee(i[0],Number(r))).sort((i,s)=>i[0]-s[0]))})))},xH=e=>{let t=new Map;for(let o of e){let n=o.points.flat().map(r=>[mt(r)]).join(",");t.has(n)||t.set(n,o)}return Array.from(t.values())},yH=(e,t,o)=>{let[n,r,a,i]=L0(e,t),s=[];for(let l of o){let[c,m,p,d]=l.gap.startBounds,[u,h,g,x]=l.gap.endBounds,E=uu(Zo(r,i),l.gap.overlap),y=uu(Zo(n,a),l.gap.overlap);switch(l.direction){case"center_horizontal":{if(E){let w=(E[0]+E[1])/2;s.push({type:"gap",direction:"horizontal",points:[ee(l.gap.startSide[0][0],w),ee(n,w)]},{type:"gap",direction:"horizontal",points:[ee(a,w),ee(l.gap.endSide[0][0],w)]})}break}case"center_vertical":{if(y){let w=(y[0]+y[1])/2;s.push({type:"gap",direction:"vertical",points:[ee(w,l.gap.startSide[0][1]),ee(w,r)]},{type:"gap",direction:"vertical",points:[ee(w,i),ee(w,l.gap.endSide[0][1])]})}break}case"side_right":{if(E){let w=(E[0]+E[1])/2;s.push({type:"gap",direction:"horizontal",points:[ee(p,w),ee(u,w)]},{type:"gap",direction:"horizontal",points:[ee(g,w),ee(n,w)]})}break}case"side_left":{if(E){let w=(E[0]+E[1])/2;s.push({type:"gap",direction:"horizontal",points:[ee(a,w),ee(c,w)]},{type:"gap",direction:"horizontal",points:[ee(p,w),ee(u,w)]})}break}case"side_top":{if(y){let w=(y[0]+y[1])/2;s.push({type:"gap",direction:"vertical",points:[ee(w,i),ee(w,m)]},{type:"gap",direction:"vertical",points:[ee(w,d),ee(w,h)]})}break}case"side_bottom":{if(y){let w=(y[0]+y[1])/2;s.push({type:"gap",direction:"vertical",points:[ee(w,d),ee(w,h)]},{type:"gap",direction:"vertical",points:[ee(w,x),ee(w,r)]})}break}}}return xH(s.map(l=>({...l,points:l.points.map(c=>ee(mt(c[0]),mt(c[1])))})))},D0=(e,t,o,n,r,a)=>{if(!kr({event:n,selectedElements:e,app:o})||e.length===0||e.length===1&&!bH(e[0].angle,0))return{snapOffset:{x:0,y:0},snapLines:[]};let[i,s,l,c]=A0(t);a&&(a.includes("e")?l+=r.x:a.includes("w")&&(i+=r.x),a.includes("n")?s+=r.y:a.includes("s")&&(c+=r.y));let m=[];if(a)switch(a){case"e":{m.push(ee(l,s),ee(l,c));break}case"w":{m.push(ee(i,s),ee(i,c));break}case"n":{m.push(ee(i,s),ee(l,s));break}case"s":{m.push(ee(i,c),ee(l,c));break}case"ne":{m.push(ee(l,s));break}case"nw":{m.push(ee(i,s));break}case"se":{m.push(ee(l,c));break}case"sw":{m.push(ee(i,c));break}}let p=hu(o.state.zoom.value),d={x:p,y:p},u=[],h=[];ll(t,m,o,n,u,h,d);let g={x:u[0]?.offset??0,y:h[0]?.offset??0};d.x=0,d.y=0,u.length=0,h.length=0;let[x,E,y,w]=A0(e).map(C=>mt(C)),v=[ee(x,E),ee(x,w),ee(y,E),ee(y,w)];ll(e,v,o,n,u,h,d);let I=_0(u,h);return{snapOffset:g,snapLines:I}},hk=(e,t,o,n,r,a)=>{if(!kr({event:o,selectedElements:[e],app:t}))return{snapOffset:{x:0,y:0},snapLines:[]};let i=[ee(n.x+r.x,n.y+r.y)],s=hu(t.state.zoom.value),l={x:s,y:s},c=[],m=[];ll([e],i,t,o,c,m,l);let p={x:c[0]?.offset??0,y:m[0]?.offset??0};l.x=0,l.y=0,c.length=0,m.length=0;let d=nd([e],a,{boundingBoxCorners:!0,omitCenter:!0});ll([e],d,t,o,c,m,l);let u=_0(c,m);return{snapOffset:p,snapLines:u}},fk=(e,t,o,n,r)=>{if(!kr({event:n,selectedElements:[],app:t}))return{originOffset:{x:0,y:0},snapLines:[]};let a=dk(e,[],t.state,r),i=hu(t.state.zoom.value),s={x:i,y:i},l=[],c=[];for(let m of a){let p=nd([m],r);for(let d of p){let u=d[0]-o.x;Math.abs(u)<=Math.abs(s.x)&&(Math.abs(u)<Math.abs(s.x)&&(c.length=0),c.push({type:"pointer",points:[d,ee(d[0],o.y)],direction:"vertical"}),s.x=u);let h=d[1]-o.y;Math.abs(h)<=Math.abs(s.y)&&(Math.abs(h)<Math.abs(s.y)&&(l.length=0),l.push({type:"pointer",points:[d,ee(o.x,d[1])],direction:"horizontal"}),s.y=h)}}return{originOffset:{x:c.length>0?c[0].points[0][0]-o.x:0,y:l.length>0?l[0].points[0][1]-o.y:0},snapLines:[...c,...l]}},bk=e=>e===ui.rectangle||e===ui.ellipse||e===ui.diamond||e===ui.frame||e===ui.magicframe||e===ui.image||e===ui.text;import{isElementInViewport as EH}from"@orangecatai/element";import{memoize as wH,toBrandedType as vH}from"@orangecatai/common";var rd=class{constructor(t){A(this,"scene");A(this,"getRenderableElements",(()=>{let t=({elementsMap:n,zoom:r,offsetLeft:a,offsetTop:i,scrollX:s,scrollY:l,height:c,width:m})=>{let p=[];for(let d of n.values())EH(d,m,c,{zoom:r,offsetLeft:a,offsetTop:i,scrollX:s,scrollY:l},n)&&p.push(d);return p},o=({elements:n,editingTextElement:r,newElementId:a})=>{let i=vH(new Map);for(let s of n)a!==s.id&&(!r||r.type!=="text"||s.id!==r.id)&&i.set(s.id,s);return i};return wH(({zoom:n,offsetLeft:r,offsetTop:a,scrollX:i,scrollY:s,height:l,width:c,editingTextElement:m,newElementId:p,sceneNonce:d})=>{let u=this.scene.getNonDeletedElements(),h=o({elements:u,editingTextElement:m,newElementId:p}),g=t({elementsMap:h,zoom:n,offsetLeft:r,offsetTop:a,scrollX:i,scrollY:s,height:l,width:c});return{elementsMap:h,visibleElements:g}})})());this.scene=t}destroy(){cE.cancel(),this.getRenderableElements.clear()}};import{sceneCoordsToViewportCoords as IH}from"@orangecatai/common";import{getElementAbsoluteCoords as TH}from"@orangecatai/element";import{jsx as SH}from"react/jsx-runtime";var CH=5,kH=(e,t,o)=>{let[n,r]=TH(e,o),{x:a,y:i}=IH({sceneX:n+e.width,sceneY:r},t),s=a-t.offsetLeft+10,l=i-t.offsetTop;return{x:s,y:l}},R0=({children:e,element:t,elementsMap:o})=>{let n=$o();if(n.contextMenu||n.newElement||n.resizingElement||n.isRotating||n.openMenu||n.viewModeEnabled)return null;let{x:r,y:a}=kH(t,n,o);return SH("div",{className:"excalidraw-canvas-buttons",style:{top:`${a}px`,left:`${r}px`,padding:CH},children:e})};import{useCallback as id,useEffect as fu,useRef as MH,useState as cl}from"react";import{sceneCoordsToViewportCoords as PH}from"@orangecatai/common";import{getElementAbsoluteCoords as AH}from"@orangecatai/element";import{isFrameLikeElement as LH}from"@orangecatai/element";var gi={element:null,isOpen:!1,isRunning:!1},B0=new Set;function N0(){B0.forEach(e=>e(gi))}var En={open(e){gi={...gi,element:e,isOpen:!0},N0()},close(){gi={element:null,isOpen:!1,isRunning:!1},N0()},setRunning(e){gi={...gi,isRunning:e},N0()},getState(){return gi},subscribe(e){return B0.add(e),()=>B0.delete(e)}};var qo={isOpen:!1,isBuilding:!1,templateName:"",campaignTag:"",sourceFrameId:null},F0=new Set;function ad(){F0.forEach(e=>e(qo))}var Ro={open(e){qo={...qo,isOpen:!0,templateName:"",campaignTag:"",sourceFrameId:e??null},ad()},close(){qo={...qo,isOpen:!1,isBuilding:!1,sourceFrameId:null},ad()},setBuilding(e){qo={...qo,isBuilding:e},ad()},setName(e){qo={...qo,templateName:e},ad()},setCampaignTag(e){qo={...qo,campaignTag:e},ad()},getState(){return qo},subscribe(e){return F0.add(e),()=>F0.delete(e)}};import{Fragment as xk,jsx as xe,jsxs as co}from"react/jsx-runtime";var yk=[{label:"1:1",width:1024,height:1024,icon:"square"},{label:"2:3",width:1024,height:1536,icon:"portrait"},{label:"9:16",width:1080,height:1920,icon:"portrait-tall"},{label:"3:2",width:1536,height:1024,icon:"landscape"},{label:"16:9",width:1920,height:1080,icon:"landscape-wide"},{label:"A4",width:1024,height:1754,icon:"portrait"},{label:"Website",width:1366,height:768,icon:"landscape-wide"}],O0=e=>{let t={border:"1.5px solid currentColor",borderRadius:2,boxSizing:"border-box"};switch(e){case"square":return xe("div",{style:{...t,width:14,height:14}});case"portrait":return xe("div",{style:{...t,width:10,height:14}});case"portrait-tall":return xe("div",{style:{...t,width:8,height:14}});case"landscape":return xe("div",{style:{...t,width:14,height:10}});case"landscape-wide":return xe("div",{style:{...t,width:14,height:8}});default:return xe("div",{style:{...t,width:14,height:14}})}},_H=({active:e})=>xe("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:e?co(xk,{children:[xe("path",{d:"M5 3H4C3.44772 3 3 3.44772 3 4V10C3 10.5523 3.44772 11 4 11H5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"}),xe("path",{d:"M9 3H10C10.5523 3 11 3.44772 11 4V10C11 10.5523 10.5523 11 10 11H9",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"}),xe("line",{x1:"5",y1:"7",x2:"9",y2:"7",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]}):co(xk,{children:[xe("path",{d:"M5 3H4C3.44772 3 3 3.44772 3 4V10C3 10.5523 3.44772 11 4 11H5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"}),xe("path",{d:"M9 3H10C10.5523 3 11 3.44772 11 4V10C11 10.5523 10.5523 11 10 11H9",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]})}),DH=()=>co("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[xe("path",{d:"M8 2V10M8 10L5 7M8 10L11 7",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"}),xe("path",{d:"M3 12H13",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]}),RH=()=>xe("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:xe("path",{d:"M2.5 3.75L5 6.25L7.5 3.75",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),NH=()=>xe("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:xe("path",{d:"M3.5 8.5L6.5 11.5L12.5 4.5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),BH=()=>co("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",children:[xe("rect",{x:"1",y:"1",width:"5",height:"5",rx:"1",stroke:"currentColor",strokeWidth:"1.4"}),xe("rect",{x:"8",y:"1",width:"5",height:"5",rx:"1",stroke:"currentColor",strokeWidth:"1.4"}),xe("rect",{x:"1",y:"8",width:"5",height:"5",rx:"1",stroke:"currentColor",strokeWidth:"1.4"}),xe("rect",{x:"8",y:"8",width:"5",height:"5",rx:"1",stroke:"currentColor",strokeWidth:"1.4"})]}),FH=()=>co("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",children:[xe("rect",{x:"1.5",y:"1.5",width:"6.5",height:"6.5",rx:"1",stroke:"currentColor",strokeWidth:"1.4"}),xe("rect",{x:"8",y:"8",width:"6.5",height:"6.5",rx:"1",stroke:"currentColor",strokeWidth:"1.4",strokeDasharray:"2 1.2",opacity:"0.65"}),xe("path",{d:"M10.5 5.5H13.5V2.5",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round"})]}),OH=(e,t)=>yk.find(o=>o.width===e&&o.height===t)||null,Ek=({element:e,app:t})=>{let o=t.state,[n,r]=cl(!1),[a,i]=cl(!0),[s,l]=cl(Math.round(e.width)),[c,m]=cl(Math.round(e.height)),[p,d]=cl(En.getState()),[u,h]=cl(Ro.getState()),g=MH(null);fu(()=>En.subscribe(d),[]),fu(()=>Ro.subscribe(h),[]),fu(()=>{l(Math.round(e.width)),m(Math.round(e.height))},[e.width,e.height]),fu(()=>{let M=B=>{g.current&&!g.current.contains(B.target)&&r(!1)};if(n)return document.addEventListener("mousedown",M),()=>document.removeEventListener("mousedown",M)},[n]);let x=OH(Math.round(e.width),Math.round(e.height)),[E,y]=AH(e,t.scene.getNonDeletedElementsMap()),{x:w,y:v}=PH({sceneX:E+e.width/2,sceneY:y},o),I=w-o.offsetLeft,C=Math.max(v-o.offsetTop-82,8),P=id((M,B)=>{M>0&&B>0&&t.scene.mutateElement(e,{width:M,height:B})},[t.scene,e]),S=id(M=>{let B=parseInt(M,10);if(!isNaN(B)&&B>0)if(l(B),a){let O=e.height/e.width,N=Math.round(B*O);m(N),P(B,N)}else P(B,e.height)},[a,e.width,e.height,P]),D=id(M=>{let B=parseInt(M,10);if(!isNaN(B)&&B>0)if(m(B),a){let O=e.width/e.height,N=Math.round(B*O);l(N),P(N,B)}else P(e.width,B)},[a,e.width,e.height,P]),_=id(M=>{l(M.width),m(M.height),P(M.width,M.height),r(!1)},[P]),k=id(()=>{LH(e)&&t.onExportImage("png",t.getSceneElements(),{exportingFrame:e})},[t,e]);return o.contextMenu||o.newElement||o.resizingElement||o.isRotating||o.openMenu||o.viewModeEnabled||o.selectedElementsAreBeingDragged?null:co("div",{className:"frame-toolbar",style:{left:`${I}px`,top:`${C}px`},onPointerDown:M=>M.stopPropagation(),onClick:M=>M.stopPropagation(),children:[co("div",{className:"frame-toolbar__section",ref:g,children:[co("button",{className:"frame-toolbar__ratio-btn",onClick:()=>r(!n),title:"Frame format",children:[O0(x?x.icon:"square"),xe("span",{children:x?.label||"Custom"}),xe(RH,{})]}),n&&co("div",{className:"frame-toolbar__dropdown",children:[xe("div",{style:{padding:"6px 12px",fontSize:11,fontWeight:600,color:"var(--text-secondary-color, #888)",textTransform:"uppercase",letterSpacing:"0.5px"},children:"Format"}),yk.map(M=>{let B=x?.label===M.label;return co("button",{className:"frame-toolbar__dropdown-item",onClick:()=>_(M),children:[O0(M.icon),xe("span",{className:"frame-toolbar__dropdown-item-label",children:M.label}),co("span",{className:"frame-toolbar__dropdown-item-dims",children:[M.width,"*",M.height]}),B&&xe("span",{className:"frame-toolbar__dropdown-item-check",children:xe(NH,{})})]},M.label)})]})]}),xe("div",{className:"frame-toolbar__divider"}),co("div",{className:"frame-toolbar__input-group",children:[xe("label",{children:"W"}),xe("input",{type:"number",value:s,onChange:M=>S(M.target.value),onPointerDown:M=>M.stopPropagation(),min:1})]}),xe("button",{className:`frame-toolbar__constrain-btn ${a?"frame-toolbar__constrain-btn--active":""}`,onClick:()=>i(!a),title:a?"Unlock proportions":"Constrain proportions",children:xe(_H,{active:a})}),co("div",{className:"frame-toolbar__input-group",children:[xe("label",{children:"H"}),xe("input",{type:"number",value:c,onChange:M=>D(M.target.value),onPointerDown:M=>M.stopPropagation(),min:1})]}),xe("div",{className:"frame-toolbar__divider"}),xe("button",{className:"frame-toolbar__export-btn",onClick:k,title:"Export frame as PNG",children:xe(DH,{})}),xe("div",{className:"frame-toolbar__divider"}),xe("div",{className:"frame-toolbar__section",children:co("button",{className:`frame-toolbar__btn ${p.isOpen&&p.element?.id===e.id?"frame-toolbar__btn--active":""}`,onClick:()=>{p.isOpen&&p.element?.id===e.id?p.isRunning||En.close():En.open(e)},title:"Auto resize to multiple dimensions",children:[xe(FH,{}),xe("span",{children:"Resize"})]})}),xe("div",{className:"frame-toolbar__divider"}),xe("div",{className:"frame-toolbar__section",children:co("button",{className:`frame-toolbar__btn ${u.isOpen?"frame-toolbar__btn--active":""}`,onClick:()=>{u.isOpen?Ro.close():Ro.open(e.id)},title:"Template Builder \u2014 add slot blocks to this frame",children:[xe(BH,{}),xe("span",{children:"Template"})]})})]})};import{useEffect as zH,useReducer as HH}from"react";import{sceneCoordsToViewportCoords as GH}from"@orangecatai/common";var sd=[],H0=new Set;function z0(){H0.forEach(e=>e())}var Sr={setLoadingFrames(e){sd=[...e],z0()},markComplete(e){sd=sd.filter(t=>t.frameId!==e),z0()},clear(){sd=[],z0()},getLoadingFrames(){return sd},subscribe(e){return H0.add(e),()=>H0.delete(e)}};import{Fragment as UH,jsx as wk}from"react/jsx-runtime";var vk=()=>{let e=$o(),[,t]=HH(r=>r+1,0);zH(()=>Sr.subscribe(t),[]);let o=Sr.getLoadingFrames();if(o.length===0)return null;let n=e.zoom.value;return wk(UH,{children:o.map(r=>{let{x:a,y:i}=GH({sceneX:r.x,sceneY:r.y},e),s=a-e.offsetLeft,l=i-e.offsetTop,c=r.width*n,m=r.height*n;return wk("div",{className:"ars-shimmer",style:{position:"absolute",left:s,top:l,width:c,height:m,pointerEvents:"none",zIndex:5,overflow:"hidden",boxSizing:"border-box"}},r.frameId)})})};import{useEffect as $k,useRef as XG,useState as ZG}from"react";import{sceneCoordsToViewportCoords as jG}from"@orangecatai/common";import{getElementAbsoluteCoords as qG}from"@orangecatai/element";function ld(e){let t=e?.trim();return(t||void 0)??(typeof import.meta<"u"&&T?.VITE_APP_OPENROUTER_API_KEY?T.VITE_APP_OPENROUTER_API_KEY:"")??""}import{useCallback as K0,useEffect as WG,useRef as YG,useState as Ei}from"react";function dl(e){let t=e?.trim();return(t||void 0)??(typeof import.meta<"u"&&T?.VITE_APP_GEMINI_API_KEY?T.VITE_APP_GEMINI_API_KEY:"")??""}import{nanoid as Lk}from"nanoid";import{newFrameElement as Bk,newElement as _k,newTextElement as vG,newImageElement as Dk,getFrameChildren as V0,syncMovedIndices as Au}from"@orangecatai/element";import{FRAME_STYLE as Fk,arrayToMap as Lu}from"@orangecatai/common";import{useCallback as bi,useEffect as dd,useRef as ua,useState as Zn}from"react";import{sceneCoordsToViewportCoords as QH}from"@orangecatai/common";import{CaptureUpdateAction as U0,getElementAbsoluteCoords as eG}from"@orangecatai/element";import{ArrowUp as tG,ImagePlus as oG,X as nG}from"lucide-react";var Mr=new Map;function bu(e,t,o,n){Mr.set(e,{subscribers:new Set,prompt:t,settings:o,controller:n})}function xu(e,t){let o=Mr.get(e);o&&(o.finishedError=t,o.subscribers.forEach(n=>n(t)))}function yu(e,t){let o=Mr.get(e);return o?(o.subscribers.add(t),o.finishedError!==void 0&&t(o.finishedError),!0):!1}function Eu(e,t){Mr.get(e)?.subscribers.delete(t)}function wu(e){Mr.delete(e)}function vu(e){Mr.get(e)?.controller.abort()}function Iu(e){return Mr.get(e)?.prompt??""}function pa(e){return Mr.get(e)?.settings??null}function hi(e){return Mr.has(e)}import VH,{createContext as KH,useContext as XH,useLayoutEffect as ZH,useRef as jH,useState as qH}from"react";import{clsx as WH}from"clsx";import{twMerge as YH}from"tailwind-merge";function je(...e){return YH(WH(e))}import*as Ik from"react";import{jsx as $H}from"react/jsx-runtime";var G0=Ik.forwardRef(({className:e,...t},o)=>$H("textarea",{className:je("flex min-h-[60px] w-full rounded-md border border-zinc-200 bg-transparent px-3 py-2 text-base shadow-sm placeholder:text-zinc-500 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-zinc-950 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm dark:border-zinc-800 dark:placeholder:text-zinc-400 dark:focus-visible:ring-zinc-300",e),ref:o,...t}));G0.displayName="Textarea";import*as Ck from"react";import*as wn from"@radix-ui/react-tooltip";import{jsx as Tk}from"react/jsx-runtime";var Tu=wn.Provider,Cu=wn.Root,ku=wn.Trigger,cd=Ck.forwardRef(({className:e,sideOffset:t=4,...o},n)=>Tk(wn.Portal,{children:Tk(wn.Content,{ref:n,sideOffset:t,className:je("z-50 overflow-hidden rounded-md bg-zinc-900 px-3 py-1.5 text-xs text-zinc-50 animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-[--radix-tooltip-content-transform-origin] dark:bg-zinc-50 dark:text-zinc-900",e),...o})}));cd.displayName=wn.Content.displayName;import{jsx as fi,jsxs as JH}from"react/jsx-runtime";var kk=KH({isLoading:!1,value:"",setValue:()=>{},maxHeight:320,onSubmit:void 0,disabled:!1,textareaRef:VH.createRef()});function Sk(){return XH(kk)}function ml({className:e,isLoading:t=!1,maxHeight:o=320,value:n,onValueChange:r,onSubmit:a,children:i,disabled:s=!1,onClick:l,...c}){let[m,p]=qH(n||""),d=jH(null),u=g=>{p(g),r?.(g)},h=g=>{s||d.current?.focus(),l?.(g)};return fi(Tu,{children:fi(kk.Provider,{value:{isLoading:t,value:n??m,setValue:r??u,maxHeight:o,onSubmit:a,disabled:s,textareaRef:d},children:fi("div",{onClick:h,className:je("border-zinc-200 bg-white cursor-text rounded-3xl border p-2 shadow-xs dark:border-zinc-800 dark:bg-zinc-950",s&&"cursor-not-allowed opacity-60",e),...c,children:i})})})}function pl({className:e,onKeyDown:t,disableAutosize:o=!1,...n}){let{value:r,setValue:a,maxHeight:i,onSubmit:s,disabled:l,textareaRef:c}=Sk(),m=h=>{if(!h||o)return;h.style.height="auto";let g;typeof i=="number"?(h.style.height=`${Math.min(h.scrollHeight,i)}px`,g=i):(h.style.height=`min(${h.scrollHeight}px, ${i})`,g=1/0),h.style.overflowY=h.scrollHeight>g?"auto":"hidden"},p=h=>{c.current=h,m(h)};return ZH(()=>{m(c.current)},[r,i,o]),fi(G0,{ref:p,value:r,onChange:h=>{m(h.target),a(h.target.value)},onKeyDown:h=>{h.key==="Enter"&&!h.shiftKey&&(h.preventDefault(),s?.()),t?.(h)},onWheel:h=>{h.stopPropagation()},className:je("text-zinc-900 min-h-[44px] w-full resize-none border-none bg-transparent shadow-none outline-none focus-visible:ring-0 focus-visible:ring-offset-0 dark:text-zinc-50",e),rows:1,disabled:l,...n})}function ul({children:e,className:t,...o}){return fi("div",{className:je("flex items-center gap-2",t),...o,children:e})}function Pr({tooltip:e,children:t,className:o,side:n="top",...r}){let{disabled:a}=Sk();return JH(Cu,{...r,children:[fi(ku,{asChild:!0,disabled:a,onClick:i=>i.stopPropagation(),children:t}),fi(cd,{side:n,className:o,children:e})]})}import{jsx as we,jsxs as Mt}from"react/jsx-runtime";var ga={"Gemini 2.5 Flash":{geminiModelId:"gemini-3.1-flash-image-preview",supportsImageSize:!1,supportsThinking:!1,supportedResolutions:["1K"],supportedRatios:["21:9","16:9","4:3","3:2","1:1","9:16","3:4","2:3","5:4","4:5"]},"Gemini 3.1 Flash":{geminiModelId:"gemini-3.1-flash-image-preview",supportsImageSize:!0,supportsThinking:!0,supportedResolutions:["0.5K","1K","2K","4K"],supportedRatios:["21:9","16:9","4:3","3:2","1:1","9:16","3:4","2:3","5:4","4:5","4:1","1:4","8:1","1:8"]},"Gemini 3 Pro":{geminiModelId:"gemini-3-pro-image-preview",supportsImageSize:!0,supportsThinking:!1,supportedResolutions:["1K","2K","4K"],supportedRatios:["21:9","16:9","4:3","3:2","1:1","9:16","3:4","2:3","5:4","4:5"]}},$0=Object.keys(ga),rG={"Gemini 2.5 Flash":{"1:1":{"1K":{w:1024,h:1024}},"2:3":{"1K":{w:832,h:1248}},"3:2":{"1K":{w:1248,h:832}},"3:4":{"1K":{w:864,h:1184}},"4:3":{"1K":{w:1184,h:864}},"4:5":{"1K":{w:896,h:1152}},"5:4":{"1K":{w:1152,h:896}},"9:16":{"1K":{w:768,h:1344}},"16:9":{"1K":{w:1344,h:768}},"21:9":{"1K":{w:1536,h:672}}},"Gemini 3.1 Flash":{"1:1":{"0.5K":{w:512,h:512},"1K":{w:1024,h:1024},"2K":{w:2048,h:2048},"4K":{w:4096,h:4096}},"1:4":{"0.5K":{w:256,h:1024},"1K":{w:512,h:2048},"2K":{w:1024,h:4096},"4K":{w:2048,h:8192}},"1:8":{"0.5K":{w:192,h:1536},"1K":{w:384,h:3072},"2K":{w:768,h:6144},"4K":{w:1536,h:12288}},"2:3":{"0.5K":{w:424,h:632},"1K":{w:848,h:1264},"2K":{w:1696,h:2528},"4K":{w:3392,h:5056}},"3:2":{"0.5K":{w:632,h:424},"1K":{w:1264,h:848},"2K":{w:2528,h:1696},"4K":{w:5056,h:3392}},"3:4":{"0.5K":{w:448,h:600},"1K":{w:896,h:1200},"2K":{w:1792,h:2400},"4K":{w:3584,h:4800}},"4:1":{"0.5K":{w:1024,h:256},"1K":{w:2048,h:512},"2K":{w:4096,h:1024},"4K":{w:8192,h:2048}},"4:3":{"0.5K":{w:600,h:448},"1K":{w:1200,h:896},"2K":{w:2400,h:1792},"4K":{w:4800,h:3584}},"4:5":{"0.5K":{w:464,h:576},"1K":{w:928,h:1152},"2K":{w:1856,h:2304},"4K":{w:3712,h:4608}},"5:4":{"0.5K":{w:576,h:464},"1K":{w:1152,h:928},"2K":{w:2304,h:1856},"4K":{w:4608,h:3712}},"8:1":{"0.5K":{w:1536,h:192},"1K":{w:3072,h:384},"2K":{w:6144,h:768},"4K":{w:12288,h:1536}},"9:16":{"0.5K":{w:384,h:688},"1K":{w:768,h:1376},"2K":{w:1536,h:2752},"4K":{w:3072,h:5504}},"16:9":{"0.5K":{w:688,h:384},"1K":{w:1376,h:768},"2K":{w:2752,h:1536},"4K":{w:5504,h:3072}},"21:9":{"0.5K":{w:792,h:168},"1K":{w:1584,h:672},"2K":{w:3168,h:1344},"4K":{w:6336,h:2688}}},"Gemini 3 Pro":{"1:1":{"1K":{w:1024,h:1024},"2K":{w:2048,h:2048},"4K":{w:4096,h:4096}},"2:3":{"1K":{w:848,h:1264},"2K":{w:1696,h:2528},"4K":{w:3392,h:5056}},"3:2":{"1K":{w:1264,h:848},"2K":{w:2528,h:1696},"4K":{w:5056,h:3392}},"3:4":{"1K":{w:896,h:1200},"2K":{w:1792,h:2400},"4K":{w:3584,h:4800}},"4:3":{"1K":{w:1200,h:896},"2K":{w:2400,h:1792},"4K":{w:4800,h:3584}},"4:5":{"1K":{w:928,h:1152},"2K":{w:1856,h:2304},"4K":{w:3712,h:4608}},"5:4":{"1K":{w:1152,h:928},"2K":{w:2304,h:1856},"4K":{w:4608,h:3712}},"9:16":{"1K":{w:768,h:1376},"2K":{w:1536,h:2752},"4K":{w:3072,h:5504}},"16:9":{"1K":{w:1376,h:768},"2K":{w:2752,h:1536},"4K":{w:5504,h:3072}},"21:9":{"1K":{w:1584,h:672},"2K":{w:3168,h:1344},"4K":{w:6336,h:2688}}}};function xi(e,t,o){let r=rG[e][t];if(!r)return{width:1024,height:1024};let a=r[o];if(!a){let i=Object.values(r)[0];return{width:i.w,height:i.h}}return{width:a.w,height:a.h}}function aG(e){return e==="0.5K"?"512px":e}async function yi(e,t,o,n,r,a,i,s,l){let c=[{text:e}];if(s){let y=s.match(/^data:([^;]+);base64,(.+)$/);y&&c.unshift({inlineData:{mimeType:y[1],data:y[2]}})}let m={aspectRatio:o};r&&(m.imageSize=aG(n));let p={responseModalities:["IMAGE","TEXT"],imageConfig:m,temperature:.1};a&&(p.thinkingConfig={thinkingLevel:"High",includeThoughts:!0});let d={contents:[{parts:c}],generationConfig:p},u=await fetch(`https://generativelanguage.googleapis.com/v1beta/models/${t}:generateContent`,{method:"POST",signal:l,headers:{"x-goog-api-key":i,"Content-Type":"application/json"},body:JSON.stringify(d)});if(!u.ok){let y=`Gemini API error ${u.status}`;try{let w=await u.json();w?.error?.message&&(y=w.error.message)}catch{}throw new Error(y)}let x=((await u.json())?.candidates?.[0]?.content?.parts??[]).find(y=>y.inlineData?.data);if(!x?.inlineData?.data)throw new Error("No image was returned by the API.");return`data:${x.inlineData.mimeType??"image/png"};base64,${x.inlineData.data}`}var W0=()=>we("svg",{width:"9",height:"9",viewBox:"0 0 10 10",fill:"none",children:we("path",{d:"M2.5 3.75L5 6.25L7.5 3.75",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round"})}),Y0=()=>we("svg",{width:"12",height:"12",viewBox:"0 0 14 14",fill:"none",children:we("path",{d:"M2.5 7.5L5.5 10.5L11.5 3.5",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round"})}),iG=()=>we("svg",{width:"13",height:"13",viewBox:"0 0 16 16",fill:"none",children:we("path",{d:"M8 2L10.5 5.5H13.5L11.5 8L13 11.5L8 9.5L3 11.5L4.5 8L2.5 5.5H5.5L8 2Z",stroke:"currentColor",strokeWidth:"1.3",strokeLinejoin:"round"})}),sG=()=>Mt("svg",{width:"12",height:"12",viewBox:"0 0 14 14",fill:"none",children:[we("circle",{cx:"7",cy:"7",r:"5.5",stroke:"currentColor",strokeWidth:"1.2"}),we("path",{d:"M7 6.5V10",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round"}),we("circle",{cx:"7",cy:"4.5",r:"0.75",fill:"currentColor"})]}),lG=()=>we("svg",{width:"15",height:"15",viewBox:"0 0 14 14",fill:"none",className:"igp-spinner",children:we("circle",{cx:"7",cy:"7",r:"5.5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeDasharray:"20 14"})}),cG=({label:e})=>{let o={"21:9":{width:21,height:9},"16:9":{width:18,height:10},"4:3":{width:16,height:12},"3:2":{width:15,height:10},"1:1":{width:13,height:13},"9:16":{width:10,height:18},"3:4":{width:12,height:16},"2:3":{width:10,height:15},"5:4":{width:15,height:12},"4:5":{width:12,height:15},"4:1":{width:24,height:6},"1:4":{width:6,height:24},"8:1":{width:24,height:3},"1:8":{width:3,height:24}}[e]??{width:13,height:13};return we("div",{style:{border:"1.5px solid currentColor",borderRadius:2,boxSizing:"border-box",display:"inline-block",flexShrink:0,color:"#999",...o}})},Mk=({element:e,app:t,onBeforeImageGen:o,onAfterImageGen:n})=>{let r=Y=>{let ne=Y.customData?.imageGenerator;return ne?{model:ne.model,ratio:ne.ratio,resolution:ne.resolution}:null},a=t.state,i=dl(t.props.geminiApiKey),[s,l]=Zn(()=>Iu(e.id)),[c,m]=Zn(()=>{let Y=r(e),ne=pa(e.id);return Y?.model??ne?.model??"Gemini 3.1 Flash"}),p=ga[c],d=p.supportedRatios,u=p.supportedResolutions,h=d.includes("2:3")?"2:3":d[0],g=u.includes("2K")?"2K":u[u.length-1],[x,E]=Zn(()=>{let Y=r(e),ne=pa(e.id);return Y?.ratio??ne?.ratio??h}),[y,w]=Zn(()=>{let Y=r(e),ne=pa(e.id);return Y?.resolution??ne?.resolution??g}),v=bi(Y=>{t.scene.mutateElement(e,{customData:{...e.customData??{},imageGenerator:Y}})},[t.scene,e]),I=bi((Y,ne=!1)=>{t.scrollToContent(Y,{fitToViewport:!0,viewportZoomFactor:.8,animate:ne,canvasOffsets:t.getEditorUIOffsets()})},[t]),C=ua(!0);dd(()=>{if(C.current){C.current=!1;return}let Y=ga[c],ne=Y.supportedRatios,De=ne.includes(x),ft=x;De||(ft=ne.includes("2:3")?"2:3":ne[0],E(ft));let $t=Y.supportedResolutions,Oo=$t.includes(y),Pn=y;Oo||(Pn=$t.includes("2K")?"2K":$t[$t.length-1],w(Pn));let Fr=xi(c,ft,Pn);t.scene.mutateElement(e,{width:Fr.width,height:Fr.height}),v({model:c,ratio:ft,resolution:Pn}),t.syncActionResult({captureUpdate:U0.IMMEDIATELY})},[c,t,e,v]);let[P,S]=Zn(()=>hi(e.id)),[D,_]=Zn(null),[k,M]=Zn(null),[B,O]=Zn(!1),[N,z]=Zn(!1),[L,F]=Zn(!1),$=ua(null),Q=ua(null),Z=ua(null),U=ua(null),q=ua(null),ae=ua(e),J=ua(t);dd(()=>{ae.current=e,J.current=t}),dd(()=>{if(!e.customData?.imageGeneratorAutoFitPending)return;let Y=0,ne=!1,De=()=>{ne||(I(e),t.scene.mutateElement(e,{customData:{...e.customData??{},imageGeneratorAutoFitPending:!1}}))};return Y=window.requestAnimationFrame(()=>{Y=window.requestAnimationFrame(De)}),()=>{ne=!0,window.cancelAnimationFrame(Y)}},[t.scene,e,I]);let te=bi(Y=>{E(Y),O(!1);let ne=xi(c,Y,y);J.current.scene.mutateElement(ae.current,{width:ne.width,height:ne.height,customData:{...ae.current.customData??{},imageGenerator:{model:c,ratio:Y,resolution:y}}}),J.current.syncActionResult({captureUpdate:U0.IMMEDIATELY})},[c,y]),ue=bi(Y=>{w(Y),z(!1);let ne=xi(c,x,Y);J.current.scene.mutateElement(ae.current,{width:ne.width,height:ne.height,customData:{...ae.current.customData??{},imageGenerator:{model:c,ratio:x,resolution:Y}}}),J.current.syncActionResult({captureUpdate:U0.IMMEDIATELY})},[c,x]);dd(()=>{let Y=ne=>{$.current&&!$.current.contains(ne.target)&&O(!1),Q.current&&!Q.current.contains(ne.target)&&z(!1),Z.current&&!Z.current.contains(ne.target)&&F(!1)};return document.addEventListener("mousedown",Y),()=>document.removeEventListener("mousedown",Y)},[]),dd(()=>{let Y=ne=>{S(!1),ne?ne!=="aborted"&&_(ne):_(null)};return yu(e.id,Y),()=>Eu(e.id,Y)},[e.id]);let Me=bi(Y=>{let ne=Y.target.files?.[0];if(!ne)return;let De=new FileReader;De.onload=()=>M(De.result),De.readAsDataURL(ne),Y.target.value=""},[]),ct=bi(()=>{vu(e.id)},[e.id]),Lt=bi(async()=>{if(!s.trim()){_("Please enter a prompt.");return}if(!i){_("No Gemini API key found. Set VITE_APP_GEMINI_API_KEY in .env.");return}if(o)try{let{allowed:De,error:ft}=await o();if(!De){_(ft||"Insufficient credits for image generation");return}}catch{_("Credit check failed");return}let Y=new AbortController;q.current=Y,bu(e.id,s,{model:c,ratio:x,resolution:y},Y),S(!0),_(null);let ne=null;try{let De=ga[c],ft=await yi(s,De.geminiModelId,x,y,De.supportsImageSize,De.supportsThinking,i,k??void 0,Y.signal);await t.insertGeneratedImageIntoFrame(ft,e),n?.()}catch(De){De instanceof Error&&(De.name==="AbortError"?ne="aborted":ne=De.message)}finally{q.current=null,xu(e.id,ne),S(!1),ne===null?(wu(e.id),l(""),M(null),_(null)):ne!=="aborted"&&_(ne)}},[s,i,c,x,y,k,t,e,o,n]);if(a.contextMenu||a.newElement||a.resizingElement||a.isRotating||a.openMenu||a.viewModeEnabled||a.selectedElementsAreBeingDragged)return null;let[Sn,,,Mn]=eG(e,t.scene.getNonDeletedElementsMap()),{x:eo,y:Gt}=QH({sceneX:Sn+e.width/2,sceneY:Mn},a),yt=eo-a.offsetLeft,dr=Gt-a.offsetTop+16;return Mt("div",{className:"igp",style:{left:`${yt}px`,top:`${dr}px`},onPointerDown:Y=>Y.stopPropagation(),onClick:Y=>Y.stopPropagation(),children:[we("input",{ref:U,type:"file",accept:"image/*",style:{display:"none"},onChange:Me}),Mt(ml,{isLoading:P,value:s,onValueChange:l,onSubmit:Lt,className:"igp-container",children:[k&&Mt("div",{className:"igp-ref-chip",children:[we("img",{src:k,alt:"Reference"}),we("span",{children:"Reference image"}),we("button",{onClick:()=>M(null),title:"Remove",children:we(nG,{size:10})})]}),we(pl,{placeholder:"What are we creating today\u2026",className:"igp-textarea",disableAutosize:!1}),D&&we("div",{className:"igp-error",children:D}),Mt(ul,{className:"igp-actions",children:[Mt("div",{className:"igp-actions-left",children:[Mt("div",{className:"igp-dropdown-root",ref:Z,children:[we(Pr,{tooltip:"Select model",side:"top",children:Mt("button",{className:"igp-btn",onClick:()=>{F(Y=>!Y),O(!1),z(!1)},disabled:P,children:[we(iG,{}),we("span",{children:c}),we(W0,{})]})}),L&&we("div",{className:"igp-dropdown igp-dropdown--up igp-dropdown--left",children:$0.map(Y=>Mt("button",{className:"igp-dropdown-item",onClick:()=>{v({model:Y,ratio:x,resolution:y}),m(Y),F(!1)},children:[we("span",{style:{flex:1},children:Y}),Y===c&&we("span",{className:"igp-check",children:we(Y0,{})})]},Y))})]}),we(Pr,{tooltip:"Add reference image",side:"top",children:we("button",{className:`igp-btn igp-btn--icon${k?" igp-btn--active":""}`,onClick:()=>U.current?.click(),disabled:P,children:we(oG,{size:15})})})]}),Mt("div",{className:"igp-actions-right",children:[Mt("div",{className:"igp-dropdown-root",ref:Q,children:[Mt("button",{className:"igp-btn igp-btn--compact",onClick:()=>{u.length<=1||(z(Y=>!Y),O(!1),F(!1))},disabled:P||u.length<=1,title:u.length<=1?"Fixed resolution for this model":void 0,children:[we("span",{children:y}),u.length>1&&we(W0,{})]}),N&&u.length>1&&we("div",{className:"igp-dropdown igp-dropdown--up igp-dropdown--right",children:u.map(Y=>Mt("button",{className:"igp-dropdown-item",onClick:()=>ue(Y),children:[we("span",{style:{flex:1},children:Y}),Y===y&&we("span",{className:"igp-check",children:we(Y0,{})})]},Y))})]}),Mt("div",{className:"igp-dropdown-root",ref:$,children:[Mt("button",{className:"igp-btn igp-btn--compact",onClick:()=>{O(Y=>!Y),z(!1),F(!1)},disabled:P,children:[we("span",{children:x}),we(W0,{})]}),B&&Mt("div",{className:"igp-dropdown igp-dropdown--up igp-dropdown--right igp-dropdown--ratio",children:[Mt("div",{className:"igp-dropdown-header",children:[we("span",{children:"Format"}),we(sG,{})]}),d.map(Y=>{let ne=xi(c,Y,y);return Mt("button",{className:"igp-dropdown-item",onClick:()=>te(Y),children:[we(cG,{label:Y}),we("span",{style:{flex:1},children:Y}),Mt("span",{className:"igp-dims",children:[ne.width,"\xD7",ne.height]}),Y===x&&we("span",{className:"igp-check",children:we(Y0,{})})]},Y)})]})]}),we("button",{className:"igp-generate",onClick:P?ct:Lt,disabled:!P&&!s.trim(),title:P?"Stop generation":"Generate image",children:P?we(lG,{}):we(tG,{size:16})})]})]})]})]})};function ha(e){if(!e||e==="transparent"||e==="rgba(0, 0, 0, 0)")return"transparent";if(e.startsWith("#"))return e;let t=e.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([0-9.]+))?\)/);if(!t)return e;let o=parseInt(t[1],10),n=parseInt(t[2],10),r=parseInt(t[3],10);return`#${o.toString(16).padStart(2,"0")}${n.toString(16).padStart(2,"0")}${r.toString(16).padStart(2,"0")}`}function dG(e){let t=e.match(/rgba\(\d+,\s*\d+,\s*\d+,\s*([0-9.]+)\)/);return t?Math.round(parseFloat(t[1])*100):100}function mG(e,t){let o=e.toLowerCase();if(t){for(let[n,r]of Object.entries(t))if(o.includes(n))return r}return o.includes("sans-serif")||o.includes("arial")||o.includes("helvetica")||o.includes("verdana")||o.includes("impact")||o.includes("nunito")||o.includes("roboto")||o.includes("inter")||o.includes("liberation sans")||o.includes("tahoma")||o.includes("trebuchet")?2:o.includes("georgia")||o.includes("serif")||o.includes("cursive")||o.includes("script")||o.includes("times")||o.includes("playfair")?1:o.includes("courier")||o.includes("mono")||o.includes("cascadia")?3:2}function pG(e,t){switch(t){case"uppercase":return e.toUpperCase();case"lowercase":return e.toLowerCase();case"capitalize":return e.replace(/\b\w/g,o=>o.toUpperCase());default:return e}}function uG(e){let t=parseFloat(e);return isNaN(t)?16:Math.round(t)}function gG(e){let t=e.borderTopLeftRadius||"0",o=parseFloat(t);return isNaN(o)?0:Math.round(o)}function hG(e,t,o){let n=e.borderTopLeftRadius||"0";if(n.includes("%")){let r=parseFloat(n);if(!isNaN(r)&&r>=50)return!0}else{let r=parseFloat(n);if(!isNaN(r)&&r>0&&r>=t/2&&r>=o/2)return!0}return!1}function fG(e){return e!=="none"&&(e.includes("linear-gradient")||e.includes("radial-gradient"))}function bG(e){let t=[...e.matchAll(/(#[\da-fA-F]{3,8}|rgba?\([^)]+\))/g)];if(t.length===0)return"#1a1a2e";if(t.length===1||e.includes("repeating"))return ha(t[0][1]);let o=ha(t[0][1]).replace("#","").padEnd(6,"0"),n=ha(t[t.length-1][1]).replace("#","").padEnd(6,"0"),r=parseInt(o.slice(0,2),16),a=parseInt(o.slice(2,4),16),i=parseInt(o.slice(4,6),16),s=parseInt(n.slice(0,2),16),l=parseInt(n.slice(2,4),16),c=parseInt(n.slice(4,6),16),m=(p,d)=>Math.round((p+d)/2).toString(16).padStart(2,"0");return`#${m(r,s)}${m(a,l)}${m(i,c)}`}function xG(e){let t=e.match(/url\("?(data:[^")]+)"?\)/);return t?t[1]:null}function yG(e){return e==="center"?"center":e==="right"||e==="end"?"right":"left"}var Ak=new Set(["SPAN","EM","STRONG","B","I","A","LABEL"]);function Pk(e){let t="",o=!1;for(let r of e.childNodes)if(r.nodeType===Node.TEXT_NODE){let a=r.textContent||"";a.trim()&&(o=!0),t+=a}else if(r.nodeType===Node.ELEMENT_NODE){let a=r;if(a.tagName==="BR")t+=`
|
|
15
15
|
`,o=!0;else if(Ak.has(a.tagName)){let i=a.textContent||"";i.trim()&&(o=!0),t+=i}}let n=t.replace(/^\s+|\s+$/g,"");return o&&n?n:null}async function Su(e,t,o,n,r,a){let i=document.createElement("iframe");i.style.cssText=`
|
|
16
16
|
position: fixed;
|
|
17
17
|
left: -${n+200}px;
|
|
@@ -197,8 +197,8 @@ Only change positions and sizes.
|
|
|
197
197
|
11. border-radius in px if needed.
|
|
198
198
|
12. One purpose per div: background fill OR image OR text (never mixed).
|
|
199
199
|
|
|
200
|
-
Return ONLY the raw HTML. No markdown, no code fences, no explanation.`,imagePlaceholders:c}}async function HG(e,t,o,n){let r=await fetch("https://openrouter.ai/api/v1/chat/completions",{method:"POST",signal:n,headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json"},body:JSON.stringify({model:o,messages:[{role:"user",content:e}],stream:!1,temperature:.3})});if(!r.ok){let l=`OpenRouter API error ${r.status}`;try{let c=await r.json();c?.error?.message&&(l=c.error.message)}catch{}throw new Error(l)}return((await r.json())?.choices?.[0]?.message?.content??"").replace(/^```(?:html)?\s*/i,"").replace(/\s*```\s*$/i,"").trim()}function GG(e,t){let o=e.findIndex(r=>r.id===t);if(o<0)return e.length;let n=o+1;for(let r=o+1;r<e.length;r++)e[r].frameId===t&&(n=r+1);return n}async function UG(e){let{info:t,targetWidth:o,targetHeight:n,placementX:r,placementY:a,app:i,geminiApiKey:s,openRouterApiKey:l,chatModel:c,agentImageModel:m,customFontMap:p={},onProgress:d,signal:u,debugLabel:h=`${o}\xD7${n}`,existingFrameId:g}=e,x=t.frame,E;if(g)E=g;else{let I=Bk({...Fk,x:r,y:a,width:o,height:n,opacity:100,locked:!1,name:`${o}\xD7${n}`}),P=[...i.getSceneElements(),I];Au(P,Lu([I])),i.updateScene({elements:P}),E=I.id}let y=null;if(t.background.type==="image"){let I=t.background.dataUrl,C=_G(x.width,x.height,o,n);if(wt(`[AutoResize] ${h} \u2014 background: needsRegen=${C}`),C){d?.("Regenerating background image\u2026");let P=DG(o,n);wt(`[AutoResize] ${h} \u2014 calling Gemini for background regen (ar=${P})`),y=await yi(`You are given an input background image. Preserve the original scene identity, composition, color palette, and style. Outpaint only beyond the existing edges so the final image fits aspect ratio ${P}. Keep the center subject and key content unchanged. Ensure all surfaces extend with natural, seamless continuity \u2014 no visible seams, repeated patterns, or tiling artifacts. For areas far from the center, gradually soften into ambient bokeh rather than extending sharp textures. Do not add text, logos, watermarks, UI, symbols, or new unrelated objects. Avoid altering brand-relevant details.`,m||TG,P,"1K",!1,!1,s,I,u)}else y=I}if(y){d?.("Placing background\u2026");let{width:I,height:C}=await Rk(y),{relX:P,relY:S,width:D,height:_}=RG(I,C,o,n),k=Lk(),M=Dk({type:"image",x:r+P,y:a+S,width:D,height:_,fileId:k,status:"pending",scale:[1,1],customData:{autoResizeBg:!0}}),B=i.getSceneElements(),O=GG(B,E),N=[...B.slice(0,O),{...M,frameId:E},...B.slice(O)];Au(N,Lu([M])),i.updateScene({elements:N}),i.addFiles([{id:k,dataURL:y,mimeType:So(y),created:Date.now(),lastRetrieved:Date.now()}])}d?.("Generating layout\u2026");let w=0,v;for(;;){wt(`[AutoResize] ${h} \u2014 calling OpenRouter for HTML layout (model=${c}, round=${w+1})`);let{prompt:I,imagePlaceholders:C}=zG(t,o,n,v),P=await HG(I,l,c,u);if(!P||P.length<20)throw new Error("LLM returned empty HTML");wt(`[AutoResize] ${h} \u2014 HTML received (${P.length} chars), substituting ${C.size} image placeholder(s)\u2026`);for(let[U,q]of C)P=P.split(`url(${U})`).join(`url(${q})`);d?.("Parsing layout\u2026");let S;try{S=await Su(P,r,a,o,n,p)}catch(U){throw new Error(`HTML parse failed: ${U instanceof Error?U.message:String(U)}`)}if(!S||S.length===0)throw new Error("HTML parser produced no elements");d?.("Inserting elements\u2026");let D=[],_=[];for(let U of S)if(U.kind==="rectangle"){let q=_k({type:"rectangle",x:U.x,y:U.y,width:U.width,height:U.height,backgroundColor:U.backgroundColor,fillStyle:"solid",strokeColor:U.strokeColor,strokeWidth:U.strokeWidth,opacity:U.opacity,roughness:0,...U.borderRadius>0?{roundness:{type:3,value:U.borderRadius}}:{},customData:{generatedByHtml:!0}});D.push({...q,frameId:E})}else if(U.kind==="ellipse"){let q=_k({type:"ellipse",x:U.x,y:U.y,width:U.width,height:U.height,backgroundColor:U.backgroundColor,fillStyle:"solid",strokeColor:U.strokeColor,strokeWidth:U.strokeWidth,opacity:U.opacity,roughness:0,customData:{generatedByHtml:!0}});D.push({...q,frameId:E})}else if(U.kind==="text"){let q=vG({x:U.x,y:U.y,text:U.text,fontSize:U.fontSize,fontFamily:U.fontFamily,strokeColor:U.color,textAlign:U.textAlign,width:U.width,opacity:U.opacity,roughness:0,customData:{generatedByHtml:!0}});D.push({...q,frameId:E})}else if(U.kind==="image"){let q=Lk(),{width:re,height:J}=await Rk(U.dataUrl),{relX:se,relY:fe,width:Me,height:ct}=NG(re,J,U.width,U.height),Lt=Dk({type:"image",x:U.x+se,y:U.y+fe,width:Me,height:ct,fileId:q,status:"pending",scale:[1,1],customData:{generatedByHtml:!0}});D.push({...Lt,frameId:E}),_.push({id:q,dataURL:U.dataUrl,mimeType:So(U.dataUrl),created:Date.now(),lastRetrieved:Date.now()})}if(w>0){let q=i.getSceneElements().filter(re=>{let J=re;return!(J.frameId===E&&J.customData?.generatedByHtml)});i.updateScene({elements:q})}let k=o*n,M=[],B=[];for(let U of D)U.type==="rectangle"&&U.width*U.height>=k*.25?M.push(U):B.push(U);let O=i.getSceneElements(),N=O.findIndex(U=>U.id===E),z=V0(O,E),L=z.length>0?O.findIndex(U=>U.id===z[0].id):N+1,F=z.length>0?O.findIndex(U=>U.id===z[z.length-1].id)+1:N+1,$=[...O.slice(0,L),...M,...O.slice(L,F),...B,...O.slice(F)],Q=[...M,...B];if(Au($,Lu(Q)),i.updateScene({elements:$}),_.length>0&&i.addFiles(_),wt(`[AutoResize] ${h} \u2014 inserted ${D.length} elements (${M.length} bg, ${B.length} fg)`),w>=CG){wt(`[AutoResize] ${h} \u2014 reviewer cap reached, finalising`);break}let Z=await Ok(i,E);if(!Z){wt(`[AutoResize] ${h} \u2014 screenshot unavailable, skipping reviewer`);break}d?.("Reviewing layout\u2026");try{let U=await Mu({screenshotDataUrl:Z,htmlSource:P,frame:{id:E,width:o,height:n},userBrief:`Auto-resize ad from ${Math.round(x.width)}\xD7${Math.round(x.height)} to ${o}\xD7${n}`,apiKey:l,reviewerModel:c,signal:u,iteration:w+1});if(w++,U.approved){wt(`[AutoResize] ${h} \u2014 reviewer approved (round ${w})`);break}wt(`[AutoResize] ${h} \u2014 reviewer found ${U.issues.length} issue(s), regenerating\u2026`),v=U,d?.("Refining layout\u2026")}catch{wt(`[AutoResize] ${h} \u2014 reviewer error, accepting output`);break}}return{frameId:E}}function zk(e,t,o){let n=t.x+t.width+80,r=e.map((l,c)=>{let m=e.slice(0,c).reduce((d,u)=>d+u.height+40,t.y);return{frame:Bk({...Fk,x:n,y:m,width:l.width,height:l.height,opacity:100,locked:!1,name:l.label??`${l.width}\xD7${l.height}`}),x:n,y:m,width:l.width,height:l.height}}),a=o.getSceneElements(),i=r.map(l=>l.frame),s=[...a,...i];return Au(s,Lu(i)),o.updateScene({elements:s}),r.map(l=>({frameId:l.frame.id,x:l.x,y:l.y,width:l.width,height:l.height}))}async function Hk(e){let{sourceFrameId:t,targetDimensions:o,app:n,geminiApiKey:r,openRouterApiKey:a,chatModel:i="google/gemini-3.1-flash-lite-preview",agentImageModel:s,customFontMap:l={},onBeforeAutoResize:c,onAfterAutoResize:m,onProgress:p,signal:d,preCreatedFrameInfos:u}=e,h=new Array(o.length),g=n.getSceneElements(),x=g.find(P=>P.id===t);if(!x)return o.map(()=>({status:"error",error:"Source frame not found"}));let E=AG(g,x,n.files),y=await Ok(n,t);y&&await OG(E,y,a,i,d);let w=x.x+x.width+80,v=u??o.map((P,S)=>({x:w,y:o.slice(0,S).reduce((D,_)=>D+_.height+40,x.y)})),I=3,C=o.length;wt(`[AutoResize] Starting ${C} dimension(s), batch size ${I}`);for(let P=0;P<C;P+=I){let S=Math.min(P+I,C),D=Math.floor(P/I)+1;wt(`[AutoResize] Batch ${D}: dimensions ${P+1}\u2013${S} of ${C}`),await Promise.allSettled(o.slice(P,S).map(async(_,k)=>{let M=P+k,B=_.label??`${_.width}\xD7${_.height}`,O=`[${M+1}/${C}] ${B}`;if(c){wt(`[AutoResize] ${O} \u2014 checking credits`);let{allowed:N,error:z}=await c();if(!N){h[M]={status:"error",error:z??"Not allowed"},p?.(M,C,"error",B),wt(`[AutoResize] ${O} \u2014 credits denied: ${z}`);return}wt(`[AutoResize] ${O} \u2014 credits OK`)}p?.(M,C,"bg-regen",B),wt(`[AutoResize] ${O} \u2014 starting AI at (${v[M].x}, ${v[M].y})`);try{let{frameId:N}=await UG({info:E,targetWidth:_.width,targetHeight:_.height,placementX:v[M].x,placementY:v[M].y,existingFrameId:u?.[M]?.frameId,app:n,geminiApiKey:r,openRouterApiKey:a,chatModel:i,agentImageModel:s,customFontMap:l,debugLabel:O,onProgress:z=>{p?.(M,C,"layout",`${B}: ${z}`)},signal:d});h[M]={status:"ok",frameId:N},p?.(M,C,"done",B),m?.(),wt(`[AutoResize] ${O} \u2014 DONE`)}catch(N){let z=N instanceof Error?N.message:String(N);h[M]={status:"error",error:z},p?.(M,C,"error",`${B}: ${z}`),wt(`[AutoResize] ${O} \u2014 ERROR: ${z}`)}})),wt(`[AutoResize] Batch ${D} complete`)}return h}import{Fragment as Z0,jsx as ue,jsxs as yo}from"react/jsx-runtime";var Gk=[{label:"1200\xD7628",width:1200,height:628,desc:"Facebook / OG"},{label:"1080\xD71080",width:1080,height:1080,desc:"Square"},{label:"1080\xD71920",width:1080,height:1920,desc:"Story 9:16"},{label:"728\xD790",width:728,height:90,desc:"Leaderboard"},{label:"320\xD750",width:320,height:50,desc:"Mobile Banner"},{label:"300\xD7600",width:300,height:600,desc:"Half Page"},{label:"300\xD7250",width:300,height:250,desc:"Medium Rect"},{label:"160\xD7600",width:160,height:600,desc:"Wide Skyscraper"}],$G=()=>yo("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",children:[ue("rect",{x:"1.5",y:"1.5",width:"7",height:"7",rx:"1",stroke:"currentColor",strokeWidth:"1.4"}),ue("rect",{x:"7.5",y:"7.5",width:"7",height:"7",rx:"1",stroke:"currentColor",strokeWidth:"1.4",strokeDasharray:"2 1",opacity:"0.6"}),ue("path",{d:"M9.5 6.5L13.5 6.5M13.5 6.5L13.5 2.5M13.5 2.5L9.5 2.5",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round"})]}),VG=()=>ue("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",children:ue("path",{d:"M1.5 1.5L10.5 10.5M10.5 1.5L1.5 10.5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})}),X0=()=>ue("svg",{width:"11",height:"11",viewBox:"0 0 12 12",fill:"none",children:ue("path",{d:"M2 6.5L4.5 9L10 3",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round"})}),Uk=()=>ue("svg",{className:"arp-spinner",width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",children:ue("circle",{cx:"7",cy:"7",r:"5.5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeDasharray:"20 14"})}),Wk=()=>yo("svg",{width:"11",height:"11",viewBox:"0 0 12 12",fill:"none",children:[ue("circle",{cx:"6",cy:"6",r:"4.5",stroke:"currentColor",strokeWidth:"1.3"}),ue("path",{d:"M6 3.5V6.5",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"}),ue("circle",{cx:"6",cy:"8.5",r:"0.65",fill:"currentColor"})]}),KG=({onAdd:e})=>{let[t,o]=Ei(""),[n,r]=Ei("");return yo("div",{className:"arp-custom-row",children:[ue("input",{className:"arp-custom-input",type:"number",placeholder:"W",value:t,min:1,onChange:i=>o(i.target.value),onPointerDown:i=>i.stopPropagation()}),ue("span",{className:"arp-custom-x",children:"\xD7"}),ue("input",{className:"arp-custom-input",type:"number",placeholder:"H",value:n,min:1,onChange:i=>r(i.target.value),onPointerDown:i=>i.stopPropagation()}),ue("button",{className:"arp-custom-add",onClick:()=>{let i=parseInt(t,10),s=parseInt(n,10);i>0&&s>0&&(e({width:i,height:s,label:`${i}\xD7${s}`}),o(""),r(""))},disabled:!t||!n,title:"Add custom dimension",children:"+ Add"})]})},Yk=({element:e,app:t,onClose:o,onBeforeAutoResize:n,onAfterAutoResize:r,onRunningChange:a,openRouterApiKey:i,chatModel:s,agentImageModel:l})=>{let[c,m]=Ei(new Set),[p,d]=Ei([]),[u,h]=Ei(!1),[g,x]=Ei({}),[E,y]=Ei(null),w=YG(null),v=[...Gk.filter(N=>c.has(N.label)).map(N=>({width:N.width,height:N.height,label:N.label})),...p],I=N=>{m(z=>{let L=new Set(z);return L.has(N)?L.delete(N):L.add(N),L})},C=N=>{let z=N.label;c.has(z)||(d(L=>[...L,N]),m(L=>new Set([...L,z])))},P=N=>{d(z=>z.filter(L=>L.label!==N)),m(z=>{let L=new Set(z);return L.delete(N),L})},S=K0((N,z)=>{x(L=>({...L,[N]:{...L[N],...z}}))},[]),D=K0(()=>{Sr.clear()},[]);WG(()=>()=>{w.current?.abort(),Sr.clear()},[]);let _=K0(async()=>{if(v.length===0)return;h(!0),a?.(!0),y(null);let N={};v.forEach(q=>{N[q.label]={status:"waiting"}}),x(N);let z=new AbortController;w.current=z;let L=dl(t.props.geminiApiKey),F={},$=t.state.brandContext;if($?.typography){let{headline:q,body:re}=$.typography;q?.family&&q?.fontFamilyId&&(F[q.family.toLowerCase().trim()]=q.fontFamilyId),re?.family&&re?.fontFamilyId&&(F[re.family.toLowerCase().trim()]=re.fontFamilyId)}let Z=t.getSceneElements().find(q=>q.id===e.id),U=[];Z&&(U=zk(v,Z,t)),U.length>0&&Sr.setLoadingFrames(U);try{await Hk({sourceFrameId:e.id,targetDimensions:v,preCreatedFrameInfos:U.length>0?U:void 0,app:t,geminiApiKey:L,openRouterApiKey:i,chatModel:s,agentImageModel:l,customFontMap:F,onBeforeAutoResize:n,onAfterAutoResize:r,onProgress:(q,re,J,se)=>{let fe=v[q]?.label??se;J==="done"?(S(fe,{status:"done"}),U[q]&&Sr.markComplete(U[q].frameId)):J==="error"?(S(fe,{status:"error",error:se}),U[q]&&Sr.markComplete(U[q].frameId)):J==="bg-regen"?S(fe,{status:"bg-regen"}):S(fe,{status:"layout"})},signal:z.signal})}catch(q){q instanceof DOMException&&q.name==="AbortError"||z.signal.aborted||y(q instanceof Error?q.message:"An unexpected error occurred")}finally{h(!1),a?.(!1),w.current=null,D()}},[v,t,e.id,S,D,n,r,i,s,l]),k=()=>{w.current?.abort(),h(!1),a?.(!1),D()},M=Object.values(g).filter(N=>N.status==="done").length,B=v.length,O=M>0;return ue(Z0,{children:yo("div",{className:"arp",onPointerDown:N=>N.stopPropagation(),onClick:N=>N.stopPropagation(),children:[yo("div",{className:"arp-header",children:[yo("span",{className:"arp-header__title",children:[ue($G,{}),"Auto Resize"]}),ue("button",{className:"arp-header__close",onClick:()=>{u?window.confirm("This will cancel the generation. Are you sure?")&&(k(),o()):o()},title:"Close",children:ue(VG,{})})]}),yo("div",{className:"arp-source",children:["Source: ",Math.round(e.width),"\xD7",Math.round(e.height)]}),ue("div",{className:"arp-section-label",children:"Target dimensions"}),ue("div",{className:"arp-presets",children:Gk.map(N=>{let z=c.has(N.label),L=g[N.label];return yo("button",{className:`arp-preset ${z?"arp-preset--selected":""} ${u?"arp-preset--disabled":""}`,onClick:()=>!u&&I(N.label),title:N.desc,children:[ue("span",{className:"arp-preset__check",children:z&&ue(X0,{})}),ue("span",{className:"arp-preset__label",children:N.label}),ue("span",{className:"arp-preset__desc",children:N.desc}),L&&yo("span",{className:"arp-preset__status",children:[L.status==="waiting"&&ue("span",{className:"arp-status arp-status--waiting",children:"\u2026"}),(L.status==="bg-regen"||L.status==="layout"||L.status==="inserting")&&ue("span",{className:"arp-status arp-status--running",children:ue(Uk,{})}),L.status==="done"&&ue("span",{className:"arp-status arp-status--done",children:ue(X0,{})}),L.status==="error"&&ue("span",{className:"arp-status arp-status--error",title:L.error,children:ue(Wk,{})})]})]},N.label)})}),p.length>0&&ue("div",{className:"arp-extras",children:p.map(N=>{let z=g[N.label];return yo("div",{className:"arp-extra-tag",children:[ue("span",{children:N.label}),z?.status==="done"&&ue("span",{className:"arp-status arp-status--done",children:ue(X0,{})}),z?.status==="error"&&ue("span",{className:"arp-status arp-status--error",title:z.error,children:ue(Wk,{})}),(z?.status==="bg-regen"||z?.status==="layout")&&ue("span",{className:"arp-status arp-status--running",children:ue(Uk,{})}),!u&&ue("button",{className:"arp-extra-tag__remove",onClick:()=>P(N.label),children:"\xD7"})]},N.label)})}),!u&&yo(Z0,{children:[ue("div",{className:"arp-section-label",children:"Custom size"}),ue(KG,{onAdd:C})]}),E&&ue("div",{className:"arp-error",children:E}),u&&B>0&&yo("div",{className:"arp-progress",children:[ue("div",{className:"arp-progress__bar-bg",children:ue("div",{className:"arp-progress__bar-fill",style:{width:`${M/B*100}%`}})}),yo("span",{className:"arp-progress__text",children:[M,"/",B," done"]})]}),ue("div",{className:"arp-actions",children:u?ue("button",{className:"arp-btn arp-btn--cancel",onClick:k,children:"Cancel"}):O?yo(Z0,{children:[ue("button",{className:"arp-btn arp-btn--primary",onClick:_,disabled:v.length===0,children:"Generate more"}),ue("button",{className:"arp-btn arp-btn--ghost",onClick:o,children:"Done"})]}):ue("button",{className:"arp-btn arp-btn--primary",onClick:_,disabled:v.length===0,children:v.length===0?"Select sizes above":`Generate ${v.length} size${v.length!==1?"s":""}`})})]})})};import{jsx as Vk}from"react/jsx-runtime";var Kk=({app:e})=>{let[t,o]=ZG(En.getState()),n=XG(null);if($k(()=>En.subscribe(o),[]),$k(()=>{if(!t.isOpen)return;let d=u=>{t.isRunning||n.current&&!n.current.contains(u.target)&&En.close()};return document.addEventListener("mousedown",d),()=>document.removeEventListener("mousedown",d)},[t.isOpen,t.isRunning]),!t.isOpen||!t.element)return null;let r=t.element,a=e.state,[i,s]=qG(r,e.scene.getNonDeletedElementsMap()),{x:l,y:c}=jG({sceneX:i+r.width/2,sceneY:s},a),m=l-a.offsetLeft,p=Math.max(c-a.offsetTop-82,8);return Vk("div",{ref:n,style:{position:"absolute",left:`${m}px`,top:`${p}px`,transform:"translateX(-50%)",zIndex:"var(--zIndex-canvasButtons)",pointerEvents:"all"},children:Vk(Yk,{element:r,app:e,onClose:()=>En.close(),onRunningChange:d=>En.setRunning(d),onBeforeAutoResize:e.props.onBeforeAutoResize,onAfterAutoResize:e.props.onAfterAutoResize,openRouterApiKey:ld(e.props.openRouterApiKey),chatModel:e.props.chatModel??"google/gemini-3.1-flash-lite-preview",agentImageModel:e.props.agentImageModel})})};import{useEffect as oU,useState as nU}from"react";import{isFrameLikeElement as Jk,getFrameChildren as Qk}from"@orangecatai/element";import{newElement as Zk,newTextElement as JG,isFrameLikeElement as QG,syncMovedIndices as eU}from"@orangecatai/element";import{arrayToMap as tU}from"@orangecatai/common";var Xk=[{id:"background",label:"Background",color:"#94a3b8",kind:"rect"},{id:"logo",label:"Logo",color:"#f97316",kind:"image"},{id:"product_image",label:"Product Image",color:"#22c55e",kind:"image"},{id:"headline",label:"Headline",color:"#3b82f6",kind:"text"},{id:"subhead",label:"Subhead",color:"#8b5cf6",kind:"text"},{id:"cta",label:"CTA",color:"#ef4444",kind:"text"},{id:"signoff",label:"Signoff",color:"#64748b",kind:"text"},{id:"auxiliary_image",label:"Aux Image",color:"#14b8a6",kind:"image"}];import{jsx as j0,jsxs as jk}from"react/jsx-runtime";var qk=({app:e})=>{let t=o=>{let n=e.state.selectedElementIds,a=e.getSceneElements().find(c=>n[c.id]&&QG(c)&&!c.isDeleted);if(!a){alert("Please select a frame first.");return}let i;o.kind==="rect"?i={...Zk({type:"rectangle",x:a.x+a.width*.1,y:a.y+a.height*.1,width:a.width*.8,height:a.height*.8,backgroundColor:o.color,fillStyle:"solid",strokeColor:"transparent",opacity:60}),frameId:a.id,customData:{slotType:o.id,isSlot:!0}}:o.kind==="text"?i={...JG({text:o.label,x:a.x+a.width*.1,y:a.y+a.height*.3,fontSize:32,strokeColor:o.color}),frameId:a.id,customData:{slotType:o.id,isSlot:!0}}:i={...Zk({type:"rectangle",x:a.x+a.width*.1,y:a.y+a.height*.1,width:a.width*.8,height:a.height*.8,backgroundColor:o.color,fillStyle:"solid",strokeColor:o.color,opacity:40}),frameId:a.id,customData:{slotType:o.id,isSlot:!0}};let l=[...e.getSceneElements(),i];eU(l,tU([i])),e.updateScene({elements:l})};return jk("div",{style:{background:"var(--popup-bg-color, #1e1e2e)",border:"1px solid var(--default-border-color, #333)",borderRadius:8,padding:12,width:240},children:[j0("div",{style:{fontSize:11,fontWeight:600,color:"var(--text-secondary-color, #888)",textTransform:"uppercase",letterSpacing:"0.5px",marginBottom:8},children:"Slot Blocks"}),j0("div",{children:Xk.map(o=>jk("button",{onClick:()=>t(o),style:{display:"flex",alignItems:"center",gap:8,padding:"6px 10px",borderRadius:6,cursor:"pointer",background:"rgba(255,255,255,0.05)",border:"1px solid rgba(255,255,255,0.1)",color:"var(--text-primary-color, #fff)",fontSize:12,margin:"3px 0",width:"100%",textAlign:"left"},children:[j0("span",{style:{width:8,height:8,borderRadius:2,background:o.color,flexShrink:0,display:"inline-block"}}),o.label]},o.id))})]})};import{jsx as jn,jsxs as md}from"react/jsx-runtime";var e3=({app:e})=>{let[t,o]=nU(Ro.getState());if(oU(()=>Ro.subscribe(o),[]),!t.isOpen)return null;let n=()=>{let r=e.props.onSaveTemplate;if(!r)return;let a=e.getSceneElements(),i=[];if(t.sourceFrameId){let p=a.find(d=>!d.isDeleted&&d.id===t.sourceFrameId&&Jk(d));p&&(i=[p])}if(i.length===0&&(i=a.filter(p=>p.isDeleted||!Jk(p)?!1:Qk(a,p.id).some(u=>u.customData?.isSlot===!0))),i.length===0){alert("No frame found to save. Please select a frame on the canvas first.");return}let s=i[0],l=Qk(a,s.id),c=e.files,m={};for(let p of l){let d=p;if(p.type==="image"&&d.fileId){let u=c[d.fileId];u?.dataURL&&(m[d.fileId]={dataURL:u.dataURL,mimeType:u.mimeType})}}r({name:t.templateName,campaignTag:t.campaignTag||void 0,label:`${Math.round(s.width)}x${Math.round(s.height)}`,width:Math.round(s.width),height:Math.round(s.height),canvasJson:JSON.stringify({frame:{...s},elements:l,...Object.keys(m).length>0?{files:m}:{}})}),Ro.close()};return jn("div",{style:{position:"fixed",right:20,bottom:20,zIndex:9999,pointerEvents:"all",display:"flex",flexDirection:"column",gap:8},onPointerDown:r=>r.stopPropagation(),onClick:r=>r.stopPropagation(),children:md("div",{style:{background:"var(--popup-bg-color, #1e1e2e)",border:"1px solid var(--default-border-color, #333)",borderRadius:8,padding:12,width:264,display:"flex",flexDirection:"column",gap:10},children:[md("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[jn("span",{style:{fontSize:13,fontWeight:600,color:"var(--text-primary-color, #fff)"},children:"Template Builder"}),jn("button",{onClick:()=>Ro.close(),style:{background:"none",border:"none",cursor:"pointer",color:"var(--text-secondary-color, #888)",fontSize:16,padding:"0 2px",lineHeight:1},title:"Close Template Builder",children:"\xD7"})]}),md("div",{style:{display:"flex",flexDirection:"column",gap:4},children:[jn("label",{style:{fontSize:11,color:"var(--text-secondary-color, #888)",fontWeight:500},children:"Template Name"}),jn("input",{type:"text",value:t.templateName,onChange:r=>Ro.setName(r.target.value),placeholder:"e.g. Summer Campaign",style:{background:"rgba(255,255,255,0.06)",border:"1px solid var(--default-border-color, #444)",borderRadius:5,color:"var(--text-primary-color, #fff)",fontSize:12,padding:"5px 8px",outline:"none",width:"100%",boxSizing:"border-box"}})]}),md("div",{style:{display:"flex",flexDirection:"column",gap:4},children:[jn("label",{style:{fontSize:11,color:"var(--text-secondary-color, #888)",fontWeight:500},children:"Campaign Tag (optional)"}),jn("input",{type:"text",value:t.campaignTag,onChange:r=>Ro.setCampaignTag(r.target.value),placeholder:"e.g. summer_2026",style:{background:"rgba(255,255,255,0.06)",border:"1px solid var(--default-border-color, #444)",borderRadius:5,color:"var(--text-primary-color, #fff)",fontSize:12,padding:"5px 8px",outline:"none",width:"100%",boxSizing:"border-box"}})]}),jn(qk,{app:e}),md("div",{style:{display:"flex",gap:6,marginTop:4},children:[jn("button",{onClick:n,disabled:!t.templateName.trim(),style:{flex:1,background:"#3b82f6",border:"none",borderRadius:6,color:"#fff",cursor:t.templateName.trim()?"pointer":"not-allowed",fontSize:12,fontWeight:600,padding:"7px 12px",opacity:t.templateName.trim()?1:.5},children:"Save Template"}),jn("button",{onClick:()=>Ro.close(),style:{background:"rgba(255,255,255,0.08)",border:"1px solid var(--default-border-color, #444)",borderRadius:6,color:"var(--text-primary-color, #fff)",cursor:"pointer",fontSize:12,padding:"7px 12px"},children:"Close"})]})]})})};import{useCallback as Ru,useState as ex}from"react";import{sceneCoordsToViewportCoords as pU}from"@orangecatai/common";import{getElementAbsoluteCoords as uU}from"@orangecatai/element";function t3(e){let t=e?.trim();return(t||void 0)??(typeof import.meta<"u"&&T?.VITE_APP_LEONARDO_API_KEY?T.VITE_APP_LEONARDO_API_KEY:"")??""}function o3(e){let t=e?.trim();return(t||void 0)??(typeof import.meta<"u"&&T?.VITE_APP_REMOVE_BG_API_KEY?T.VITE_APP_REMOVE_BG_API_KEY:"")??""}import{useCallback as _u,useEffect as q0,useRef as Du,useState as qn}from"react";import{sceneCoordsToViewportCoords as n3}from"@orangecatai/common";import{getElementAbsoluteCoords as rU}from"@orangecatai/element";import{ArrowUp as aU}from"lucide-react";import{Fragment as mU,jsx as ve,jsxs as Ft}from"react/jsx-runtime";var J0=()=>ve("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",children:ve("path",{d:"M2.5 3.75L5 6.25L7.5 3.75",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),Q0=()=>ve("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",children:ve("path",{d:"M2.5 7.5L5.5 10.5L11.5 3.5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),iU=()=>ve("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:ve("path",{d:"M8 2L10.5 5.5H13.5L11.5 8L13 11.5L8 9.5L3 11.5L4.5 8L2.5 5.5H5.5L8 2Z",stroke:"currentColor",strokeWidth:"1.3",strokeLinejoin:"round"})}),sU=()=>Ft("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",children:[ve("circle",{cx:"7",cy:"7",r:"5.5",stroke:"currentColor",strokeWidth:"1.2"}),ve("path",{d:"M7 6.5V10",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round"}),ve("circle",{cx:"7",cy:"4.5",r:"0.75",fill:"currentColor"})]}),lU=()=>ve("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",className:"igp-spinner",children:ve("circle",{cx:"7",cy:"7",r:"5.5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeDasharray:"20 14"})}),cU=()=>ve("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",children:ve("path",{d:"M7 1.5L8.5 5.5H12.5L9.5 8L10.5 12L7 9.5L3.5 12L4.5 8L1.5 5.5H5.5L7 1.5Z",fill:"currentColor"})}),dU=({label:e})=>{let t={border:"1.5px solid currentColor",borderRadius:2,boxSizing:"border-box",display:"inline-block",flexShrink:0},n={"21:9":{width:21,height:9},"16:9":{width:18,height:10},"4:3":{width:16,height:12},"3:2":{width:15,height:10},"1:1":{width:13,height:13},"9:16":{width:10,height:18},"3:4":{width:12,height:16},"2:3":{width:10,height:15},"5:4":{width:15,height:12},"4:5":{width:12,height:15},"4:1":{width:24,height:6},"1:4":{width:6,height:24},"8:1":{width:24,height:3},"1:8":{width:3,height:24}}[e]??{width:13,height:13};return ve("div",{style:{...t,...n}})},r3=({element:e,app:t,onBeforeImageGen:o,onAfterImageGen:n,forceOpen:r,onClose:a})=>{let i=t.state,s=dl(t.props.geminiApiKey),[l,c]=qn(()=>r||hi(e.id)),m=_u(()=>{c(!1),a?.()},[a]),[p,d]=qn(()=>Iu(e.id)),[u,h]=qn(()=>pa(e.id)?.model??"Gemini 3.1 Flash"),g=ga[u],x=g.supportedRatios,E=g.supportedResolutions,y=x.includes("1:1")?"1:1":x[0],w=E.includes("2K")?"2K":E[E.length-1],[v,I]=qn(()=>pa(e.id)?.ratio??y),[C,P]=qn(()=>pa(e.id)?.resolution??w);q0(()=>{let Y=ga[u],oe=Y.supportedRatios;oe.includes(v)||I(oe.includes("1:1")?"1:1":oe[0]);let ft=Y.supportedResolutions;ft.includes(C)||P(ft.includes("2K")?"2K":ft[ft.length-1])},[u]);let[S,D]=qn(()=>hi(e.id)),[_,k]=qn(null),[M,B]=qn(!1),[O,N]=qn(!1),[z,L]=qn(!1),F=Du(null),$=Du(null),Q=Du(null),Z=Du(null),U=_u(Y=>{I(Y),B(!1)},[]);q0(()=>{let Y=oe=>{D(!1),oe?oe!=="aborted"&&k(oe):(m(),d(""))};return yu(e.id,Y),()=>Eu(e.id,Y)},[e.id]),q0(()=>{let Y=oe=>{F.current&&!F.current.contains(oe.target)&&B(!1),$.current&&!$.current.contains(oe.target)&&N(!1),Q.current&&!Q.current.contains(oe.target)&&L(!1)};return document.addEventListener("mousedown",Y),()=>document.removeEventListener("mousedown",Y)},[]);let q=_u(()=>{vu(e.id)},[e.id]),re=_u(async()=>{if(!p.trim()){k("Please enter a prompt.");return}if(!s){k("No Gemini API key found. Set VITE_APP_GEMINI_API_KEY in .env or pass geminiApiKey as a prop.");return}if(o)try{let{allowed:De,error:ft}=await o();if(!De){k(ft||"Insufficient credits for image generation");return}}catch{k("Credit check failed");return}let Y=new AbortController;Z.current=Y,bu(e.id,p,{model:u,ratio:v,resolution:C},Y),D(!0),k(null);let oe=null;try{let De=ga[u],ft=e.fileId?t.files[e.fileId]?.dataURL:void 0,$t=await yi(p,De.geminiModelId,v,C,De.supportsImageSize,De.supportsThinking,s,ft,Y.signal),Oo=xi(u,v,C);await t.insertGeneratedImageNearElement($t,e,Oo.width,Oo.height),n?.()}catch(De){De instanceof Error&&(De.name==="AbortError"?oe="aborted":oe=De.message)}finally{Z.current=null,xu(e.id,oe),D(!1),oe===null?(wu(e.id),m(),d(""),k(null)):oe!=="aborted"&&k(oe)}},[p,s,u,v,C,t,e,o,n]);if(i.contextMenu||i.newElement||i.resizingElement||i.isRotating||i.openMenu||i.viewModeEnabled||i.selectedElementsAreBeingDragged)return null;let J=t.scene.getNonDeletedElementsMap(),[se,fe,,Me]=rU(e,J),{x:ct,y:Lt}=n3({sceneX:se+e.width/2,sceneY:fe},i),Sn=ct-i.offsetLeft,Mn=Math.max(Lt-i.offsetTop-44,8),{x:eo,y:Gt}=n3({sceneX:se+e.width/2,sceneY:Me},i),yt=eo-i.offsetLeft,dr=Gt-i.offsetTop+16;return Ft(mU,{children:[!r&&ve("div",{className:"iqep__trigger-bar",style:{left:`${Sn}px`,top:`${Mn}px`},onPointerDown:Y=>Y.stopPropagation(),onClick:Y=>Y.stopPropagation(),children:Ft("button",{className:"iqep__trigger-btn",onClick:()=>c(Y=>!Y),title:"Quick AI edit",children:[ve(cU,{}),ve("span",{children:"AI Edit"})]})}),l&&ve("div",{className:"igp iqep__panel",style:{left:`${yt}px`,top:`${dr}px`},onPointerDown:Y=>Y.stopPropagation(),onClick:Y=>Y.stopPropagation(),children:Ft(ml,{isLoading:S,value:p,onValueChange:d,onSubmit:re,className:"igp-container",children:[ve(pl,{placeholder:"Describe your edit\u2026",className:"igp-textarea",disableAutosize:!1}),_&&ve("div",{className:"igp-error",children:_}),Ft(ul,{className:"igp-actions",children:[ve("div",{className:"igp-actions-left",children:Ft("div",{className:"igp-dropdown-root",ref:Q,children:[ve(Pr,{tooltip:"Select model",side:"top",children:Ft("button",{className:"igp-btn",onClick:()=>{L(Y=>!Y),B(!1),N(!1)},disabled:S,children:[ve(iU,{}),ve("span",{children:u}),ve(J0,{})]})}),z&&ve("div",{className:"igp-dropdown igp-dropdown--up igp-dropdown--left",children:$0.map(Y=>Ft("button",{className:"igp-dropdown-item",onClick:()=>{h(Y),L(!1)},children:[ve("span",{style:{flex:1},children:Y}),Y===u&&ve("span",{className:"igp-check",children:ve(Q0,{})})]},Y))})]})}),Ft("div",{className:"igp-actions-right",children:[Ft("div",{className:"igp-dropdown-root",ref:$,children:[Ft("button",{className:"igp-btn igp-btn--compact",onClick:()=>{E.length<=1||(N(Y=>!Y),B(!1),L(!1))},disabled:S||E.length<=1,title:E.length<=1?"Fixed resolution for this model":void 0,children:[ve("span",{children:C}),E.length>1&&ve(J0,{})]}),O&&E.length>1&&ve("div",{className:"igp-dropdown igp-dropdown--up igp-dropdown--right",children:E.map(Y=>Ft("button",{className:"igp-dropdown-item",onClick:()=>{P(Y),N(!1)},children:[ve("span",{style:{flex:1},children:Y}),Y===C&&ve("span",{className:"igp-check",children:ve(Q0,{})})]},Y))})]}),Ft("div",{className:"igp-dropdown-root",ref:F,children:[Ft("button",{className:"igp-btn igp-btn--compact",onClick:()=>{B(Y=>!Y),N(!1),L(!1)},disabled:S,children:[ve("span",{children:v}),ve(J0,{})]}),M&&Ft("div",{className:"igp-dropdown igp-dropdown--up igp-dropdown--right igp-dropdown--ratio",children:[Ft("div",{className:"igp-dropdown-header",children:[ve("span",{children:"Output format"}),ve(sU,{})]}),x.map(Y=>{let oe=xi(u,Y,C);return Ft("button",{className:"igp-dropdown-item",onClick:()=>U(Y),children:[ve(dU,{label:Y}),ve("span",{style:{flex:1},children:Y}),Ft("span",{className:"igp-dims",children:[oe.width,"\xD7",oe.height]}),Y===v&&ve("span",{className:"igp-check",children:ve(Q0,{})})]},Y)})]})]}),ve("button",{className:"igp-generate",onClick:S?q:re,disabled:!S&&!p.trim(),title:S?"Stop generation":"Generate edit",children:S?ve(lU,{}):ve(aU,{size:16})})]})]})]})})]})};import{Fragment as AU,jsx as Ye,jsxs as vn}from"react/jsx-runtime";var tx="https://cloud.leonardo.ai/api/rest/v1",gU=1500,a3=40,s3=e=>({Authorization:`Bearer ${e}`,"Content-Type":"application/json"}),l3=e=>{switch(e){case"image/jpeg":return"jpeg";case"image/jpg":return"jpg";case"image/webp":return"webp";default:return"png"}},hU=e=>e==="upscale"?"Upscale":"Remove background",fU=e=>e==="upscale"?"Upscaling image...":"Removing background...",bU=e=>new Promise(t=>{window.setTimeout(t,e)}),Nu=async(e,t)=>{try{let o=await e.json(),n=o?.error?.message??o?.message??o?.detail??o?.errors?.[0]?.message;if(typeof n=="string"&&n.trim())return n}catch{}try{let o=await e.text();if(o.trim())return o.trim()}catch{}return`${t} (${e.status})`},i3=async(e,t)=>{let o=e.crop;return o?new Promise((n,r)=>{let a=new Image;a.onload=()=>{let i=document.createElement("canvas");i.width=o.width,i.height=o.height;let s=i.getContext("2d");if(!s){r(new Error("Could not prepare the cropped image for editing."));return}s.drawImage(a,o.x,o.y,o.width,o.height,0,0,o.width,o.height),n(i.toDataURL("image/png"))},a.onerror=()=>r(new Error("Could not read the selected image for editing.")),a.src=t}):t},xU=async(e,t)=>{let o=l3(So(e)),n=await fetch(`${tx}/init-image`,{method:"POST",headers:s3(t),body:JSON.stringify({extension:o})});if(!n.ok)throw new Error(await Nu(n,"Leonardo init image request failed"));let a=(await n.json()).uploadInitImage;if(!a?.id||!a.url)throw new Error("Leonardo init image response was incomplete.");let i=a.fields??{},s=typeof i=="string"?JSON.parse(i):i,l=new FormData;return Object.entries(s).forEach(([c,m])=>{l.append(c,m)}),l.append("file",uh(e,`image.${o}`)),await fetch(a.url,{method:"POST",body:l,mode:"no-cors"}),a.id},yU=async(e,t)=>{let o=So(e),n=l3(o),r=uh(e,`image.${n}`),a=new FormData;a.append("size","auto"),a.append("image_file",r);let i=await fetch("https://api.remove.bg/v1.0/removebg",{method:"POST",headers:{"X-Api-Key":t},body:a});if(!i.ok){let l=`Remove background failed (${i.status})`;try{let m=(await i.json())?.errors?.[0]?.title;m&&(l=m)}catch{}throw new Error(l)}let s=await i.arrayBuffer();return await Vi(new Blob([s],{type:"image/png"}))},EU=async(e,t)=>{let o=await fetch(`${tx}/variations/universal-upscaler`,{method:"POST",headers:s3(t),body:JSON.stringify({ultraUpscaleStyle:"ARTISTIC",creativityStrength:1,detailContrast:5,similarity:10,upscaleMultiplier:1.5,initImageId:e})});if(!o.ok)throw new Error(await Nu(o,"Leonardo upscale request failed"));let r=(await o.json()).universalUpscaler?.id;if(!r)throw new Error("Leonardo variation job id was missing from the response.");return r},wU=async(e,t)=>{for(let o=0;o<a3;o++){let n=await fetch(`${tx}/variations/${e}`,{method:"GET",headers:{Authorization:`Bearer ${t}`}});if(!n.ok)throw new Error(await Nu(n,"Leonardo variation status check failed"));let r=await n.json(),a=Array.isArray(r.generated_image_variation_generic)?r.generated_image_variation_generic[0]:r.generated_image_variation_generic;if(!a)throw new Error("Leonardo variation details were missing from the response.");if(a.status==="COMPLETE"){if(!a.url)throw new Error("Leonardo variation completed without an image URL.");return a.url}if(a.status==="FAILED")throw new Error("Leonardo variation failed.");o<a3-1&&await bU(gU)}throw new Error("Leonardo variation timed out.")},vU=async e=>{let t=await fetch(e);if(!t.ok)throw new Error(await Nu(t,"Leonardo result image download failed"));return Vi(await t.blob())},IU=()=>vn("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[Ye("path",{d:"M12 20h9"}),Ye("path",{d:"M16.5 3.5a2.121 2.121 0 0 1 3 3L7 19l-4 1 1-4L16.5 3.5z"})]}),TU=()=>vn("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[Ye("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),Ye("path",{d:"M9 3v18"}),Ye("path",{d:"M14 9l3-3 3 3"}),Ye("path",{d:"M17 6v6"})]}),CU=()=>vn("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[Ye("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),Ye("path",{d:"M9 3v18M3 9h18M3 15h18M15 3v18",strokeDasharray:"2 2",opacity:"0.5"}),Ye("circle",{cx:"12",cy:"12",r:"4"})]}),kU=()=>vn("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[Ye("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),Ye("polyline",{points:"7 10 12 15 17 10"}),Ye("line",{x1:"12",y1:"15",x2:"12",y2:"3"})]}),SU=()=>vn("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[Ye("path",{d:"M6.13 1L6 16a2 2 0 0 0 2 2h15"}),Ye("path",{d:"M1 6.13L16 6a2 2 0 0 1 2 2v15"})]}),MU=()=>vn("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[Ye("path",{d:"M7 16V4m0 0L3 8m4-4l4 4"}),Ye("path",{d:"M17 8v12m0 0l4-4m-4 4l-4-4"})]}),PU=[{id:"quick-edit",label:"Quick Edit",icon:Ye(IU,{})},{id:"upscale",label:"Upscale",icon:Ye(TU,{})},{id:"remove-bg",label:"Remove BG",icon:Ye(CU,{})},{id:"crop",label:"Crop",icon:Ye(SU,{})}],c3=({element:e,app:t,callbacks:o})=>{let n=t.state,r=t3(t.props.leonardoApiKey),a=o3(t.props.removeBgApiKey),[i,s]=ex(()=>hi(e.id)),[l,c]=ex(null),[m,p]=ex(null),d=l!==null,u=Ru(async S=>{if(!r){p("No Leonardo API key found. Set VITE_APP_LEONARDO_API_KEY in .env or pass leonardoApiKey as a prop.");return}let D=e.fileId;if(!D){p("The selected image is missing its file reference.");return}let _=t.files[D]?.dataURL;if(!_){p("The selected image file could not be found.");return}let k=t.props.onBeforeUpscale,M=t.props.onAfterUpscale;if(k)try{let{allowed:B,error:O}=await k();if(!B){p(O||"Insufficient credits for upscale");return}}catch{p("Credit check failed");return}c(S),p(null);try{let B=await i3(e,_),O=await xU(B,r),N=await EU(O,r),z=await wU(N,r),L=await vU(z);await t.insertGeneratedImageNearElement(L,e,e.width,e.height),M?.()}catch(B){p(B instanceof Error?B.message:`${hU(S)} failed.`)}finally{c(null)}},[t,e,r]),h=Ru(async()=>{if(!a){p("No remove.bg API key found. Set VITE_APP_REMOVE_BG_API_KEY in .env or pass removeBgApiKey as a prop.");return}let S=e.fileId;if(!S){p("The selected image is missing its file reference.");return}let D=t.files[S]?.dataURL;if(!D){p("The selected image file could not be found.");return}let _=t.props.onBeforeRemoveBg,k=t.props.onAfterRemoveBg;if(_)try{let{allowed:M,error:B}=await _();if(!M){p(B||"Insufficient credits for remove background");return}}catch{p("Credit check failed");return}c("remove-bg"),p(null);try{let M=await i3(e,D),B=await yU(M,a);await t.insertGeneratedImageNearElement(B,e,e.width,e.height),k?.()}catch(M){p(M instanceof Error?M.message:"Remove background failed.")}finally{c(null)}},[t,e,a]),g=Ru(S=>{if(p(null),S==="quick-edit"){o?.onQuickEdit?o.onQuickEdit():s(_=>!_);return}if(S==="crop"){o?.onCrop?o.onCrop():t.actionManager.executeAction(ed);return}let D={upscale:o?.onUpscale,"remove-bg":o?.onRemoveBG};if(D[S]){D[S]?.();return}S==="upscale"?u(S):S==="remove-bg"&&h()},[o,t.actionManager,u,h]),x=Ru(()=>{if(o?.onDownload){o.onDownload();return}let S=e.fileId;if(!S)return;let D=t.files[S];if(!D?.dataURL)return;let _=B=>{let O=document.createElement("a");O.href=B,O.download=`image-${S}.png`,document.body.appendChild(O),O.click(),document.body.removeChild(O)},k=e.crop;if(!k){_(D.dataURL);return}let M=new Image;M.onload=()=>{let B=document.createElement("canvas");B.width=k.width,B.height=k.height;let O=B.getContext("2d");if(!O){_(D.dataURL);return}O.drawImage(M,k.x,k.y,k.width,k.height,0,0,k.width,k.height),_(B.toDataURL("image/png"))},M.onerror=()=>_(D.dataURL),M.src=D.dataURL},[e.fileId,e.crop,t.files,o]);if(n.contextMenu||n.newElement||n.resizingElement||n.isRotating||n.openMenu||n.viewModeEnabled||n.selectedElementsAreBeingDragged)return null;let E=t.scene.getNonDeletedElementsMap(),[y,w]=uU(e,E),{x:v,y:I}=pU({sceneX:y+e.width/2,sceneY:w},n),C=v-n.offsetLeft,P=Math.max(I-n.offsetTop-52,8);return vn(AU,{children:[i&&!o?.onQuickEdit&&Ye(r3,{element:e,app:t,onBeforeImageGen:t.props.onBeforeImageGen,onAfterImageGen:t.props.onAfterImageGen,forceOpen:!0,onClose:()=>s(!1)}),vn("div",{className:"iet",style:{left:`${C}px`,top:`${P}px`},onPointerDown:S=>S.stopPropagation(),onClick:S=>S.stopPropagation(),children:[vn("div",{className:"iet__bar",children:[PU.map(S=>vn("button",{type:"button",className:"iet__tool-btn",onClick:()=>g(S.id),title:S.label,disabled:d,"aria-busy":l===S.id,children:[S.icon,Ye("span",{className:"iet__tool-label",children:S.label}),S.badge&&Ye("span",{className:"iet__tool-badge",children:S.badge})]},S.id)),!!o?.onSwapAsset&&vn("button",{type:"button",className:"iet__tool-btn",onClick:()=>{o.onSwapAsset(e.id)},title:"Swap image from asset bank",disabled:d,children:[Ye(MU,{}),Ye("span",{className:"iet__tool-label",children:"Swap"})]}),Ye("div",{className:"iet__divider"}),Ye("button",{type:"button",className:"iet__tool-btn iet__download-btn",onClick:x,title:"Download",disabled:d,children:Ye(kU,{})})]}),(l||m)&&Ye("div",{className:`iet__status${m?" iet__status--error":""}`,children:m??(l?fU(l):null)})]})]})};import{DEFAULT_LASER_COLOR as RU,easeOut as m3}from"@orangecatai/common";import{LaserPointer as LU}from"@excalidraw/laser-pointer";import{SVG_NS as d3,getSvgPathFromStroke as _U,sceneCoordsToViewportCoords as DU}from"@orangecatai/common";var Ar=class{constructor(t,o,n){this.animationFrameHandler=t;this.app=o;this.options=n;A(this,"currentTrail");A(this,"pastTrails",[]);A(this,"container");A(this,"trailElement");A(this,"trailAnimation");this.animationFrameHandler.register(this,this.onFrame.bind(this)),this.trailElement=document.createElementNS(d3,"path"),this.options.animateTrail&&(this.trailAnimation=document.createElementNS(d3,"animate"),this.trailAnimation.setAttribute("attributeName","stroke-dashoffset"),this.trailElement.setAttribute("stroke-dasharray","7 7"),this.trailElement.setAttribute("stroke-dashoffset","10"),this.trailAnimation.setAttribute("from","0"),this.trailAnimation.setAttribute("to","-14"),this.trailAnimation.setAttribute("dur","0.3s"),this.trailElement.appendChild(this.trailAnimation))}get hasCurrentTrail(){return!!this.currentTrail}hasLastPoint(t,o){if(this.currentTrail){let n=this.currentTrail.originalPoints.length;return this.currentTrail.originalPoints[n-1][0]===t&&this.currentTrail.originalPoints[n-1][1]===o}return!1}start(t){t&&(this.container=t),this.trailElement.parentNode!==this.container&&this.container&&this.container.appendChild(this.trailElement),this.animationFrameHandler.start(this)}stop(){this.animationFrameHandler.stop(this),this.trailElement.parentNode===this.container&&this.container?.removeChild(this.trailElement)}startPath(t,o){this.currentTrail=new LU(this.options),this.currentTrail.addPoint([t,o,performance.now()]),this.update()}addPointToPath(t,o){this.currentTrail&&(this.currentTrail.addPoint([t,o,performance.now()]),this.update())}endPath(){this.currentTrail&&(this.currentTrail.close(),this.currentTrail.options.keepHead=!1,this.pastTrails.push(this.currentTrail),this.currentTrail=void 0,this.update())}getCurrentTrail(){return this.currentTrail}clearTrails(){this.pastTrails=[],this.currentTrail=void 0,this.update()}update(){this.start(),this.trailAnimation&&(this.trailAnimation.setAttribute("begin","indefinite"),this.trailAnimation.setAttribute("repeatCount","indefinite"))}onFrame(){let t=[];for(let n of this.pastTrails)t.push(this.drawTrail(n,this.app.state));if(this.currentTrail){let n=this.drawTrail(this.currentTrail,this.app.state);t.push(n)}this.pastTrails=this.pastTrails.filter(n=>n.getStrokeOutline().length!==0),t.length===0&&this.stop();let o=t.join(" ").trim();this.trailElement.setAttribute("d",o),this.trailAnimation?(this.trailElement.setAttribute("fill",(this.options.fill??(()=>"black"))(this)),this.trailElement.setAttribute("stroke",(this.options.stroke??(()=>"black"))(this))):this.trailElement.setAttribute("fill",(this.options.fill??(()=>"black"))(this))}drawTrail(t,o){let n=t.getStrokeOutline(t.options.size/o.zoom.value).map(([a,i])=>{let s=DU({sceneX:a,sceneY:i},o);return[s.x,s.y]}),r=this.trailAnimation?n.slice(0,n.length/2):n;return _U(r,!0)}};var Bu=class{constructor(t,o){this.animationFrameHandler=t;this.app=o;A(this,"localTrail");A(this,"collabTrails",new Map);A(this,"container");this.animationFrameHandler.register(this,this.onFrame.bind(this)),this.localTrail=new Ar(t,o,{...this.getTrailOptions(),fill:()=>RU})}getTrailOptions(){return{simplify:0,streamline:.4,sizeMapping:t=>{let r=Math.max(0,1-(performance.now()-t.pressure)/1e3),a=(50-Math.min(50,t.totalLength-t.currentIndex))/50;return Math.min(m3(a),m3(r))}}}startPath(t,o){this.localTrail.startPath(t,o)}addPointToPath(t,o){this.localTrail.addPointToPath(t,o)}endPath(){this.localTrail.endPath()}start(t){this.container=t,this.animationFrameHandler.start(this),this.localTrail.start(t)}stop(){this.animationFrameHandler.stop(this),this.localTrail.stop()}onFrame(){this.updateCollabTrails()}updateCollabTrails(){if(!(!this.container||this.app.state.collaborators.size===0)){for(let[t,o]of this.app.state.collaborators.entries()){let n;this.collabTrails.has(t)?n=this.collabTrails.get(t):(n=new Ar(this.animationFrameHandler,this.app,{...this.getTrailOptions(),fill:()=>o.pointer?.laserColor||ni(t,o)}),n.start(this.container),this.collabTrails.set(t,n)),o.pointer&&o.pointer.tool==="laser"&&(o.button==="down"&&!n.hasCurrentTrail&&n.startPath(o.pointer.x,o.pointer.y),o.button==="down"&&n.hasCurrentTrail&&!n.hasLastPoint(o.pointer.x,o.pointer.y)&&n.addPointToPath(o.pointer.x,o.pointer.y),o.button==="up"&&n.hasCurrentTrail&&(n.addPointToPath(o.pointer.x,o.pointer.y),n.endPath()))}for(let t of this.collabTrails.keys())this.app.state.collaborators.has(t)||(this.collabTrails.get(t).stop(),this.collabTrails.delete(t))}}};import{version as NU}from"react";import{unstable_batchedUpdates as p3}from"react-dom";import{throttleRAF as BU}from"@orangecatai/common";var pt=e=>t=>{p3(e,t)},Fu=e=>BU(t=>{p3(e,t)}),wi=(()=>{let e;try{let o=NU.split(".");e=Number(o[0])>17}catch{e=!1}let t=!1;return()=>window.EXCALIDRAW_THROTTLE_RENDER===!0?e?!0:(t||(t=!0,console.warn("Excalidraw: render throttling is disabled on React versions < 18.")),!1):!1})();import{CODES as ox,KEYS as pd,CLASSES as nx,POINTER_BUTTON as FU,THEME as OU,isWritableElement as zU,getFontString as u3,getFontFamilyString as g3,isTestEnv as h3,MIME_TYPES as rx,applyDarkModeFilter as HU}from"@orangecatai/common";import{getTextFromElements as GU,originalContainerCache as UU,updateBoundElements as f3,updateOriginalContainerCache as b3}from"@orangecatai/element";import{LinearElementEditor as WU}from"@orangecatai/element";import{bumpVersion as YU}from"@orangecatai/element";import{getBoundTextElementId as $U,getContainerElement as ax,getTextElementAngle as VU,redrawTextBoundingBox as KU,getBoundTextMaxHeight as XU,getBoundTextMaxWidth as x3,computeContainerDimensionForBoundText as y3,computeBoundTextPosition as ZU,getBoundTextElement as jU}from"@orangecatai/element";import{getTextWidth as qU}from"@orangecatai/element";import{normalizeText as E3}from"@orangecatai/element";import{wrapText as JU}from"@orangecatai/element";import{isArrowElement as Ou,isBoundToContainer as QU,isTextElement as w3}from"@orangecatai/element";var eW=(e,t,o,n,r,a)=>{let{zoom:i}=n,s=180*o/Math.PI,l=e*(i.value-1)/2,c=t*(i.value-1)/2;return e>r&&i.value!==1&&(l=r*(i.value-1)/2),t>a&&i.value!==1&&(c=a*(i.value-1)/2),`translate(${l}px, ${c}px) scale(${i.value}) rotate(${s}deg)`},v3=({id:e,onChange:t,onSubmit:o,getViewportCoords:n,element:r,canvas:a,excalidrawContainer:i,app:s,autoSelect:l=!0})=>{let c=(L,F)=>{if(!F.style.fontFamily||!F.style.fontSize)return!1;let $=F.style.fontFamily.replace(/"/g,"");return g3({fontFamily:L.fontFamily})!==$||`${L.fontSize}px`!==F.style.fontSize},m=s.state.theme,p=()=>{m=s.state.theme;let L=s.state,F=s.scene.getElement(e);if(!F)return;let{textAlign:$,verticalAlign:Q}=F,Z=s.scene.getNonDeletedElementsMap();if(F&&w3(F)){let U=F.x,q=F.y,re=ax(F,s.scene.getNonDeletedElementsMap()),J=F.width,se=F.height,fe=F.width,Me=F.height;if(re&&F.containerId){if(Ou(re)){let yt=WU.getBoundTextElementPosition(re,F,Z);U=yt.x,q=yt.y}let eo=c(F,d),Gt;if(eo?Gt=b3(re.id,re.height):(Gt=UU[re.id],Gt||(Gt=b3(re.id,re.height))),fe=x3(re,F),Me=XU(re,F),!Ou(re)&&se>Me){let yt=y3(se,re.type);s.scene.mutateElement(re,{height:yt}),f3(re,s.scene);return}else if(!Ou(re)&&re.height>Gt.height&&se<Me){let yt=y3(se,re.type);s.scene.mutateElement(re,{height:yt}),f3(re,s.scene)}else{let{x:yt,y:dr}=ZU(re,F,Z);U=yt,q=dr}}let[ct,Lt]=n(U,q);re?J+=.5:(fe=(L.width-8-ct)/L.zoom.value,J=Math.min(J,fe)),se*=1.05;let Sn=u3(F),Mn=(L.height-Lt)/L.zoom.value;Object.assign(d.style,{font:Sn,lineHeight:F.lineHeight,width:`${J}px`,height:`${se}px`,left:`${ct}px`,top:`${Lt}px`,transform:eW(J,se,VU(F,re),L,fe,Mn),textAlign:$,verticalAlign:Q,color:L.theme===OU.DARK?HU(F.strokeColor):F.strokeColor,opacity:F.opacity/100,maxHeight:`${Mn}px`}),d.scrollTop=0,h3()&&(d.style.fontFamily=g3(F)),s.scene.mutateElement(F,{x:U,y:q})}},d=document.createElement("textarea");d.dir="auto",d.tabIndex=0,d.dataset.type="wysiwyg",d.wrap="off",d.classList.add("excalidraw-wysiwyg");let u="pre",h="normal";(QU(r)||!r.autoResize)&&(u="pre-wrap",h="break-word"),Object.assign(d.style,{position:"absolute",display:"inline-block",minHeight:"1em",backfaceVisibility:"hidden",margin:0,padding:0,border:0,outline:0,resize:"none",background:"transparent",overflow:"hidden",zIndex:"var(--zIndex-wysiwyg)",wordBreak:h,whiteSpace:u,overflowWrap:"break-word",boxSizing:"content-box"}),d.value=r.originalText,p(),t&&(d.onpaste=async L=>{let F=pI(L),$=null;if(F.has(rx.excalidrawClipboard)||F.has(rx.excalidraw)){L.preventDefault(),$=await As(L);try{let re=await sp($);if(re.elements){let J=GU(re.elements);if(J){let{selectionStart:se,selectionEnd:fe,value:Me}=d;d.value=Me.slice(0,se)+J+Me.slice(fe);let ct=se+J.length;d.selectionStart=d.selectionEnd=ct,d.dispatchEvent(new Event("input"))}}return}catch{console.warn("failed to parse excalidraw clipboard data")}}$=$||await As(L);let Q=$.findByType(rx.text);if(!Q)return;let Z=E3(Q.value);if(!Z)return;let U=ax(r,s.scene.getNonDeletedElementsMap()),q=u3({fontSize:s.state.currentItemFontSize,fontFamily:s.state.currentItemFontFamily});if(U){let re=jU(U,s.scene.getNonDeletedElementsMap()),J=JU(`${d.value}${Z}`,q,x3(U,re)),se=qU(J,q);d.style.width=`${se}px`}},d.oninput=()=>{let L=E3(d.value);if(d.value!==L){let F=d.selectionStart;d.value=L,d.selectionStart=F,d.selectionEnd=F}t(d.value)}),d.onkeydown=L=>{if(!L.shiftKey&&qm.keyTest(L))L.preventDefault(),s.actionManager.executeAction(qm),p();else if(!L.shiftKey&&Jm.keyTest(L))L.preventDefault(),s.actionManager.executeAction(Jm),p();else if(!L.shiftKey&&Qm.keyTest(L))L.preventDefault(),s.actionManager.executeAction(Qm),p();else if(Cf.keyTest(L))s.actionManager.executeAction(Cf);else if(kf.keyTest(L))s.actionManager.executeAction(kf);else if(L.key===pd.ESCAPE)L.preventDefault(),C=!0,P();else if(ti.keyTest(L))L.preventDefault(),P(),s.actionManager.executeAction(ti);else if(L.key===pd.ENTER&&L[pd.CTRL_OR_CMD]){if(L.preventDefault(),L.isComposing||L.keyCode===229)return;C=!0,P()}else if(L.key===pd.TAB||L[pd.CTRL_OR_CMD]&&(L.code===ox.BRACKET_LEFT||L.code===ox.BRACKET_RIGHT)){if(L.preventDefault(),L.isComposing)return;L.shiftKey||L.code===ox.BRACKET_LEFT?w():y(),d.dispatchEvent(new Event("input"))}};let g=4,x=" ".repeat(g),E=new RegExp(`^ {1,${g}}`),y=()=>{let{selectionStart:L,selectionEnd:F}=d,$=v(),Q=d.value;$.forEach(Z=>{let U=Q.slice(0,Z),q=Q.slice(Z);Q=`${U}${x}${q}`}),d.value=Q,d.selectionStart=L+g,d.selectionEnd=F+g*$.length},w=()=>{let{selectionStart:L,selectionEnd:F}=d,$=v(),Q=[],Z=d.value;$.forEach(U=>{let q=Z.slice(U,U+g).match(E);if(q){let re=Z.slice(0,U),J=Z.slice(U+q[0].length);Z=`${re}${J}`,Q.push(U)}}),d.value=Z,Q.length&&(L>Q[Q.length-1]?d.selectionStart=Math.max(L-g,Q[Q.length-1]):d.selectionStart=L,d.selectionEnd=Math.max(d.selectionStart,F-g*Q.length))},v=()=>{let{selectionStart:L,selectionEnd:F,value:$}=d,Q=$.slice(0,L).match(/[^\n]*$/)[0].length;return L=L-Q,$.slice(L,F).split(`
|
|
201
|
-
`).reduce((U,q,re,J)=>U.concat(re?U[re-1]+J[re-1].length+1:L),[]).reverse()},I=L=>{L.target instanceof HTMLCanvasElement&&(L.preventDefault(),L.stopPropagation())},C=!1,P=()=>{if(N)return;N=!0,S();let L=s.scene.getElement(r.id);if(!L)return;let F=ax(L,s.scene.getNonDeletedElementsMap());if(F){if(d.value.trim()){let $=$U(F);!$||$!==r.id?s.scene.mutateElement(F,{boundElements:(F.boundElements||[]).concat({type:"text",id:r.id})}):Ou(F)&&YU(F)}else s.scene.mutateElement(F,{boundElements:F.boundElements?.filter($=>!w3($))});KU(L,F,s.scene)}o({viaKeyboard:C,nextOriginalText:d.value})},S=()=>{d.onblur=null,d.oninput=null,d.onkeydown=null,z&&z.disconnect(),window.removeEventListener("resize",p),window.removeEventListener("wheel",I,!0),window.removeEventListener("pointerdown",k),window.removeEventListener("pointerup",D),window.removeEventListener("blur",P),window.removeEventListener("beforeunload",P),B(),M(),O(),d.remove()},D=L=>{window.removeEventListener("pointerup",D);let F=L?.target,$=F instanceof HTMLElement&&F.classList.contains("properties-trigger"),Q=(F instanceof HTMLElement||F instanceof SVGElement)&&!!F.closest(".properties-content"),Z=(F instanceof HTMLElement||F instanceof SVGElement)&&(!!F.closest(`.${nx.SHAPE_ACTIONS_MENU}`)||!!F.closest(".compact-shape-actions-island"));setTimeout(()=>{Z||$||Q||(d.onblur=P,d.focus())})},_=()=>{d.onblur=null,window.addEventListener("pointerup",D),window.addEventListener("blur",P)},k=L=>{let F=L?.target;if(L.button===FU.WHEEL){F instanceof HTMLTextAreaElement&&(L.preventDefault(),s.handleCanvasPanUsingWheelOrSpaceDrag(L)),_();return}let $=F instanceof HTMLElement&&F.classList.contains("properties-trigger"),Q=(F instanceof HTMLElement||F instanceof SVGElement)&&!!F.closest(".properties-content");(L.target instanceof HTMLElement||L.target instanceof SVGElement)&&(L.target.closest(`.${nx.SHAPE_ACTIONS_MENU}, .${nx.ZOOM_ACTIONS}`)||L.target.closest(".compact-shape-actions-island"))&&!zU(L.target)||$||Q?_():L.target instanceof HTMLCanvasElement&&!h3()&&requestAnimationFrame(()=>{P()})},M=s.onChangeEmitter.on(L=>{s.state.theme!==m&&p()}),B=s.scene.onUpdate(()=>{p(),!!document.activeElement?.closest(".properties-content")||d.focus()}),O=s.onScrollChangeEmitter.on(()=>{p()}),N=!1;l&&d.select(),D();let z=null;return a&&"ResizeObserver"in window?(z=new window.ResizeObserver(()=>{p()}),z.observe(a)):window.addEventListener("resize",p),d.onpointerdown=L=>L.stopPropagation(),requestAnimationFrame(()=>{window.addEventListener("pointerdown",k,{capture:!0})}),window.addEventListener("beforeunload",P),i?.querySelector(".excalidraw-textEditorContainer").appendChild(d),P};import{getGlobalCSSVariable as zu}from"@orangecatai/common";import{getCommonBounds as tW}from"@orangecatai/element";var Lr=4,Jo=6,I3="rgba(0,0,0,0.3)",T3=(e,t,o,n)=>{if(!e.size)return{horizontal:null,vertical:null};let[r,a,i,s]=tW(e),l=t/n.zoom.value,c=o/n.zoom.value,m={top:parseInt(zu("sat"))||0,bottom:parseInt(zu("sab"))||0,left:parseInt(zu("sal"))||0,right:parseInt(zu("sar"))||0},p=ur().rtl,d=-n.scrollX+m.left,u=-n.scrollY+m.top,h=d+l-m.right,g=u+c-m.bottom,x=Math.min(r,d),E=Math.min(a,u),y=Math.max(i,h),w=Math.max(s,g),v=i-r,I=s-a,C=y-x,P=w-E,S=Math.max(Lr*2,m.left+m.right)+Jo*2,D=t*(l/C)-S,_=Math.max(Lr*2,m.top+m.bottom)+Jo*2,k=o*(c/P)-_,M=C>v?C*n.zoom.value/(D+S):t/(D+S),B=P>I?P*n.zoom.value/(k+_):o/(k+_);return{horizontal:d===x&&h===y?null:{x:Math.max(m.left,Lr)+Jo+(d-x)/C*t,y:o-Jo-Math.max(Lr,m.bottom),width:D,height:Jo,deltaMultiplier:M},vertical:u===E&&g===w?null:{x:p?Math.max(m.left,Lr):t-Jo-Math.max(m.right,Lr),y:Math.max(m.top,Lr)+Jo+(u-E)/P*o,width:Jo,height:k,deltaMultiplier:B}}},ix=(e,t,o)=>{let[n,r]=[e.horizontal,e.vertical].map(i=>i!=null&&i.x<=t&&t<=i.x+i.width&&i.y<=o&&o<=i.y+i.height);return{isOverEither:n||r,isOverHorizontal:n,isOverVertical:r}};var C3=e=>{let t=["flowchart","graph","sequenceDiagram","classDiagram","stateDiagram","stateDiagram-v2","erDiagram","journey","gantt","pie","quadrantChart","requirementDiagram","gitGraph","C4Context","mindmap","timeline","zenuml","sankey","xychart","block"];return new RegExp(`^(?:%%{.*?}%%[\\s\\n]*)?\\b(?:${t.map(n=>`\\s*${n}(-beta)?`).join("|")})\\b`).test(e.trim())};import{pointFrom as mW}from"@orangecatai/math";import{getElementLineSegments as pW}from"@orangecatai/element";import{LinearElementEditor as uW}from"@orangecatai/element";import{isFrameLikeElement as gW,isLinearElement as hW,isTextElement as fW}from"@orangecatai/element";import{getFrameChildren as bW}from"@orangecatai/element";import{selectGroupsForSelectedElements as xW}from"@orangecatai/element";import{getContainerElement as yW}from"@orangecatai/element";import{arrayToMap as EW,easeOut as P3,isShallowEqual as wW}from"@orangecatai/common";import{simplify as oW}from"points-on-curve";import{polygonFromPoints as nW,lineSegment as k3,polygonIncludesPointNonZero as rW}from"@orangecatai/math";import{computeBoundTextPosition as aW,doBoundsIntersect as iW,getBoundTextElement as sW,getElementBounds as lW,intersectElementWithLineSegment as S3}from"@orangecatai/element";var M3=e=>{let{lassoPath:t,elements:o,elementsMap:n,elementsSegments:r,intersectedElements:a,enclosedElements:i,simplifyDistance:s}=e,l=t;s&&(l=oW(t,s));let c=o.filter(d=>!d.locked);i.clear(),a.clear();let m=t.reduce((d,u)=>[Math.min(d[0],u[0]),Math.min(d[1],u[1]),Math.max(d[2],u[0]),Math.max(d[3],u[1])],[1/0,1/0,-1/0,-1/0]);for(let d of c){let u=lW(d,n);iW(m,u)&&!a.has(d.id)&&!i.has(d.id)&&(cW(l,d,r)?i.add(d.id):dW(l,d,n)&&a.add(d.id))}return{selectedElementIds:[...a,...i]}},cW=(e,t,o)=>{let n=nW(e),r=o.get(t.id);return r?r.some(a=>a.some(i=>rW(i,n))):!1},dW=(e,t,o)=>{let n=e.slice(1).map((a,i)=>k3(e[i],a)).concat([k3(e[e.length-1],e[0])]),r=sW(t,o);return n.some(a=>S3(t,o,a,0,!0).length>0||!!r&&S3({...r,...aW(t,r,o)},o,a,0,!0).length>0)};var Hu=class extends Ar{constructor(o,n){super(o,n,{animateTrail:!0,streamline:.4,sizeMapping:r=>{let s=Math.max(0,1-(performance.now()-r.pressure)/(1/0)),l=(5e3-Math.min(5e3,r.totalLength-r.currentIndex))/5e3;return Math.min(P3(l),P3(s))},fill:()=>"rgba(105,101,219,0.05)",stroke:()=>"rgba(105,101,219)"});A(this,"intersectedElements",new Set);A(this,"enclosedElements",new Set);A(this,"elementsSegments",null);A(this,"canvasTranslate",null);A(this,"keepPreviousSelection",!1);A(this,"selectElementsFromIds",o=>{this.app.setState(n=>{let r=o.reduce((l,c)=>(l[c]=!0,l),{});if(this.keepPreviousSelection)for(let l of Object.keys(n.selectedElementIds))r[l]=!0;for(let[l]of Object.entries(r)){let c=this.app.scene.getNonDeletedElement(l);if(c&&fW(c)){let m=yW(c,this.app.scene.getNonDeletedElementsMap());m&&(r[m.id]=!0,delete r[c.id])}}for(let[l]of Object.entries(r)){let c=this.app.scene.getNonDeletedElement(l);if(c&&gW(c)){let m=bW(this.app.scene.getNonDeletedElementsMap(),c.id);for(let p of m)delete r[p.id]}}let a=xW({editingGroupId:n.editingGroupId,selectedElementIds:r},this.app.scene.getNonDeletedElements(),n,this.app),i=[...Object.keys(a.selectedElementIds)],s=[...Object.keys(a.selectedGroupIds)];return{selectedElementIds:a.selectedElementIds,selectedGroupIds:a.selectedGroupIds,selectedLinearElement:i.length===1&&!s.length&&hW(this.app.scene.getNonDeletedElement(i[0]))?new uW(this.app.scene.getNonDeletedElement(i[0]),this.app.scene.getNonDeletedElementsMap()):null}})});A(this,"addPointToPath",(o,n,r=!1)=>{super.addPointToPath(o,n),this.keepPreviousSelection=r,this.updateSelection()});A(this,"updateSelection",()=>{let o=super.getCurrentTrail()?.originalPoints?.map(r=>mW(r[0],r[1])),n={scrollX:this.app.state.scrollX,scrollY:this.app.state.scrollY,zoom:this.app.state.zoom.value};if(!this.elementsSegments||!wW(n,this.canvasTranslate??{})){this.canvasTranslate=n,this.elementsSegments=new Map;let r=EW(this.app.visibleElements);for(let a of this.app.visibleElements){let i=pW(a,r);this.elementsSegments.set(a.id,i)}}if(o){let{selectedElementIds:r}=M3({lassoPath:o,elements:this.app.visibleElements,elementsMap:this.app.scene.getNonDeletedElementsMap(),elementsSegments:this.elementsSegments,intersectedElements:this.intersectedElements,enclosedElements:this.enclosedElements,simplifyDistance:5/this.app.state.zoom.value});this.selectElementsFromIds(r)}})}startPath(o,n,r=!1){this.endPath(),super.startPath(o,n),this.intersectedElements.clear(),this.enclosedElements.clear(),this.keepPreviousSelection=r,this.keepPreviousSelection||this.app.setState({selectedElementIds:{},selectedGroupIds:{},selectedLinearElement:null})}endPath(){super.endPath(),super.clearTrails(),this.intersectedElements.clear(),this.enclosedElements.clear(),this.elementsSegments=null}};import{arrayToMap as vW,easeOut as A3,THEME as IW}from"@orangecatai/common";import{computeBoundTextPosition as TW,doBoundsIntersect as CW,getBoundTextElement as kW,getElementBounds as SW,getElementLineSegments as MW,getFreedrawOutlineAsSegments as PW,getFreedrawOutlinePoints as AW,intersectElementWithLineSegment as L3,isArrowElement as LW,isFreeDrawElement as _3,isLineElement as _W,isPointInElement as DW}from"@orangecatai/element";import{lineSegment as RW,lineSegmentsDistance as D3,pointFrom as z3,polygon as NW,polygonIncludesPointNonZero as BW}from"@orangecatai/math";import{getElementsInGroup as R3}from"@orangecatai/element";import{shouldTestInside as FW}from"@orangecatai/element";import{hasBoundTextElement as N3,isBoundToContainer as B3}from"@orangecatai/element";import{getBoundTextElementId as F3}from"@orangecatai/element";var Gu=class extends Ar{constructor(o,n){super(o,n,{streamline:.2,size:5,keepHead:!0,sizeMapping:r=>{let s=Math.max(0,1-(performance.now()-r.pressure)/200),l=(10-Math.min(10,r.totalLength-r.currentIndex))/10;return Math.min(A3(l),A3(s))},fill:()=>n.state.theme===IW.LIGHT?"rgba(0, 0, 0, 0.2)":"rgba(255, 255, 255, 0.2)"});A(this,"elementsToErase",new Set);A(this,"groupsToErase",new Set)}startPath(o,n){this.endPath(),super.startPath(o,n),this.elementsToErase.clear()}addPointToPath(o,n,r=!1){return super.addPointToPath(o,n),this.updateElementsToBeErased(r)}updateElementsToBeErased(o){let n=super.getCurrentTrail()?.originalPoints?.map(s=>z3(s[0],s[1]))||[];if(n.length<2)return[];let r=RW(n[n.length-1],n[n.length-2]),a=this.app.visibleElements.filter(s=>!s.locked),i=vW(a);for(let s of a)if(o&&this.elementsToErase.has(s.id)){if(O3(r,s,i,this.app.state.zoom.value)){let c=s.groupIds.at(-1);if(this.groupsToErase.has(c)){let m=R3(this.app.scene.getNonDeletedElementsMap(),c);for(let p of m)this.elementsToErase.delete(p.id);this.groupsToErase.delete(c)}if(B3(s)&&this.elementsToErase.delete(s.containerId),N3(s)){let m=F3(s);m&&this.elementsToErase.delete(m)}this.elementsToErase.delete(s.id)}}else if(!o&&!this.elementsToErase.has(s.id)&&O3(r,s,i,this.app.state.zoom.value)){let c=s.groupIds.at(-1);if(!this.groupsToErase.has(c)){let m=R3(this.app.scene.getNonDeletedElementsMap(),c);for(let p of m)this.elementsToErase.add(p.id);this.groupsToErase.add(c)}if(N3(s)){let m=F3(s);m&&this.elementsToErase.add(m)}B3(s)&&this.elementsToErase.add(s.containerId),this.elementsToErase.add(s.id)}return Array.from(this.elementsToErase)}endPath(){super.endPath(),super.clearTrails(),this.elementsToErase.clear(),this.groupsToErase.clear()}},O3=(e,t,o,n)=>{let r=e[1],a=_3(t)?15:t.strokeWidth/2,i=[Math.min(e[0][0],e[1][0])-a,Math.min(e[0][1],e[1][1])-a,Math.max(e[0][0],e[1][0])+a,Math.max(e[0][1],e[1][1])+a],s=SW(t,o),l=[s[0]-a,s[1]-a,s[2]+a,s[3]+a];if(!CW(i,l))return!1;if(FW(t)&&DW(r,t,o))return!0;if(_3(t)){let m=AW(t),p=PW(t,m,o),d=Math.max(2.25,5/n);for(let h of p)if(D3(h,e)<=d)return!0;let u=NW(...m.map(([h,g])=>z3(t.x+h,t.y+g)));return!!BW(e[0],u)}let c=kW(t,o);if(LW(t)||_W(t)&&!t.polygon){let m=Math.max(t.strokeWidth,t.strokeWidth*2/n),p=MW(t,o);for(let d of p)if(D3(d,e)<=m)return!0;return!1}return L3(t,o,e,0,!0).length>0||!!c&&L3({...c,...TW(t,c,o)},o,e,0,!0).length>0};import{jsx as Qo,jsxs as H3}from"react/jsx-runtime";var OW=()=>H3("div",{"data-testid":"brave-measure-text-error",children:[Qo("p",{children:Qo(io,{i18nKey:"errors.brave_measure_text_error.line1",bold:e=>Qo("span",{style:{fontWeight:600},children:e})})}),Qo("p",{children:Qo(io,{i18nKey:"errors.brave_measure_text_error.line2",bold:e=>Qo("span",{style:{fontWeight:600},children:e})})}),Qo("p",{children:Qo(io,{i18nKey:"errors.brave_measure_text_error.line3",link:e=>Qo("a",{href:"http://docs.excalidraw.com/docs/@orangecatai/adgen-canvas/faq#turning-off-aggresive-block-fingerprinting-in-brave-browser",children:e})})}),Qo("p",{children:Qo(io,{i18nKey:"errors.brave_measure_text_error.line4",issueLink:e=>Qo("a",{href:"https://github.com/excalidraw/excalidraw/issues/new",children:e}),discordLink:e=>H3("a",{href:"https://discord.gg/UexuTaE",children:[e,"."]})})})]}),G3=OW;import $W from"clsx";import VW from"react";import{useLayoutEffect as zW,useRef as U3,useEffect as W3}from"react";import{unstable_batchedUpdates as HW}from"react-dom";import{KEYS as GW,queryFocusableElements as UW}from"@orangecatai/common";import WW from"clsx";import{jsx as YW}from"react/jsx-runtime";var Y3=({children:e,left:t,top:o,onCloseRequest:n,fitInViewport:r=!1,offsetLeft:a=0,offsetTop:i=0,viewportWidth:s=window.innerWidth,viewportHeight:l=window.innerHeight,className:c})=>{let m=U3(null);W3(()=>{let d=m.current;if(!d)return;d.contains(document.activeElement)||d.focus();let u=h=>{if(h.key===GW.TAB){let g=UW(d),{activeElement:x}=document,E=g.findIndex(y=>y===x);x===d?(h.shiftKey?g[g.length-1]?.focus():g[0].focus(),h.preventDefault(),h.stopImmediatePropagation()):E===0&&h.shiftKey?(g[g.length-1]?.focus(),h.preventDefault(),h.stopImmediatePropagation()):E===g.length-1&&!h.shiftKey&&(g[0]?.focus(),h.preventDefault(),h.stopImmediatePropagation())}};return d.addEventListener("keydown",u),()=>d.removeEventListener("keydown",u)},[]);let p=U3(null);return zW(()=>{if(r&&m.current&&o!=null&&t!=null){let d=m.current,{width:u,height:h}=d.getBoundingClientRect();if(p.current?.top===o&&p.current?.left===t)return;p.current={top:o,left:t},u>=s?(d.style.width=`${s}px`,d.style.left="0px",d.style.overflowX="scroll"):t+u-a>s?d.style.left=`${s-u-10}px`:d.style.left=`${t}px`,h>=l?(d.style.height=`${l-20}px`,d.style.top="10px",d.style.overflowY="scroll"):o+h-i>l?d.style.top=`${l-h}px`:d.style.top=`${o}px`}},[o,t,r,s,l,a,i]),W3(()=>{if(n){let d=u=>{m.current?.contains(u.target)||HW(()=>n(u))};return document.addEventListener("pointerdown",d,!1),()=>document.removeEventListener("pointerdown",d,!1)}},[n]),YW("div",{className:WW("popover",c),ref:m,tabIndex:-1,children:e})};import{jsx as gl,jsxs as KW}from"react/jsx-runtime";var vt="separator",$3=VW.memo(({actionManager:e,items:t,top:o,left:n,onClose:r})=>{let a=$o(),i=$r(),s=t.reduce((l,c)=>(c&&(c===vt||!c.predicate||c.predicate(i,a,e.app.props,e.app))&&l.push(c),l),[]);return gl(Y3,{onCloseRequest:()=>{r()},top:o,left:n,fitInViewport:!0,offsetLeft:a.offsetLeft,offsetTop:a.offsetTop,viewportWidth:a.width,viewportHeight:a.height,className:"context-menu-popover",children:gl("ul",{className:"context-menu",onContextMenu:l=>l.preventDefault(),children:s.map((l,c)=>{if(l===vt)return!s[c-1]||s[c-1]===vt?null:gl("hr",{className:"context-menu-item-separator"},c);let m=l.name,p="";return l.label&&(typeof l.label=="function"?p=f(l.label(i,a,e.app)):p=f(l.label)),gl("li",{"data-testid":m,onClick:()=>{r(()=>{e.executeAction(l,"contextMenu")})},children:KW("button",{type:"button",className:$W("context-menu-item",{dangerous:m==="deleteSelectedElements",checkmark:l.checked?.(a)}),children:[gl("div",{className:"context-menu-item__label",children:p}),gl("kbd",{className:"context-menu-item__shortcut",children:m?Xe(m):""})]})},c)})})})});import{jsx as sx,jsxs as V3}from"react/jsx-runtime";var XW=({height:e,width:t,userToFollow:o,onDisconnect:n})=>sx("div",{className:"follow-mode",style:{width:t,height:e},children:V3("div",{className:"follow-mode__badge",children:[V3("div",{className:"follow-mode__badge__label",children:["Following"," ",sx("span",{className:"follow-mode__badge__username",title:o.username,children:o.username})]}),sx("button",{type:"button",onClick:n,className:"follow-mode__disconnect-btn",children:Go})]})}),K3=XW;import Pi from"clsx";import oZ from"react";import{CLASSES as nZ,DEFAULT_SIDEBAR as v1,TOOL_TYPE as q4,arrayToMap as rZ,capitalizeString as aZ,isShallowEqual as Sg}from"@orangecatai/common";import{mutateElement as iZ}from"@orangecatai/element";import{showSelectedShapeActions as sZ}from"@orangecatai/element";import{ShapeCache as lZ}from"@orangecatai/element";import ZW from"clsx";import{useState as jW,useEffect as qW}from"react";import{THEME as JW}from"@orangecatai/common";import{jsx as lx,jsxs as QW}from"react/jsx-runtime";var Uu=({delay:e,theme:t})=>{let[o,n]=jW(!!e);return qW(()=>{if(!e)return;let r=setTimeout(()=>{n(!1)},e);return()=>clearTimeout(r)},[e]),o?null:QW("div",{className:ZW("LoadingMessage",{"LoadingMessage--dark":t===JW.DARK}),children:[lx("div",{children:lx(Wt,{})}),lx("div",{className:"LoadingMessage-text",children:f("labels.loadingScene")})]})};import eY from"clsx";import{jsx as Z3,jsxs as oY}from"react/jsx-runtime";var tY="medium",X3={CHECKED:ji,UNCHECKED:Wa},j3=e=>oY("label",{className:eY("ToolIcon ToolIcon__lock",`ToolIcon_size_${tY}`,{"is-mobile":e.isMobile}),title:`${e.title} \u2014 Q`,children:[Z3("input",{className:"ToolIcon_type_checkbox",type:"checkbox",name:e.name,onChange:e.onChange,checked:e.checked,"aria-label":e.title,"data-testid":"toolbar-lock"}),Z3("div",{className:"ToolIcon__icon",children:e.checked?X3.CHECKED:X3.UNCHECKED})]});import{useState as Wu,useEffect as Q3}from"react";import hl from"clsx";import{KEYS as cx,capitalizeString as Tt}from"@orangecatai/common";import nY from"clsx";import{KEYS as q3}from"@orangecatai/common";import{jsx as rY}from"react/jsx-runtime";var J3=e=>rY(ae,{className:nY("Shape",{fillable:!1,active:e.checked}),type:"radio",icon:as,name:"editor-current-shape",checked:e.checked,title:`${e.title} \u2014 H`,keyBindingLabel:e.isMobile?void 0:q3.H.toLocaleUpperCase(),"aria-label":`${e.title} \u2014 H`,"aria-keyshortcuts":q3.H,"data-testid":"toolbar-hand",onChange:()=>e.onChange?.()});import{Fragment as aY,jsx as It,jsxs as Yu}from"react/jsx-runtime";var dx=[{type:"rectangle",icon:qi,title:Tt(f("toolBar.rectangle"))},{type:"diamond",icon:Ji,title:Tt(f("toolBar.diamond"))},{type:"ellipse",icon:Qi,title:Tt(f("toolBar.ellipse"))}],mx=[{type:"selection",icon:Ya,title:Tt(f("toolBar.selection"))},{type:"lasso",icon:Hr,title:Tt(f("toolBar.lasso"))}],px=[{type:"arrow",icon:gm,title:Tt(f("toolBar.arrow"))},{type:"line",icon:es,title:Tt(f("toolBar.line"))}],eS=({app:e,onHandToolToggle:t,setAppState:o})=>{let n=e.state.activeTool,[r,a]=Wu(!1),[i,s]=Wu("rectangle"),[l,c]=Wu("arrow");Q3(()=>{(n.type==="rectangle"||n.type==="diamond"||n.type==="ellipse")&&s(n.type)},[n.type]),Q3(()=>{(n.type==="arrow"||n.type==="line")&&c(n.type)},[n.type]);let m=n.type==="frame",p=n.type==="laser",d=n.type==="embeddable",{TTDDialogTriggerTunnel:u}=Ze(),h=(M,B)=>{e.state.activeTool.type!==M&&be("toolbar",M,"ui"),M==="selection"?e.state.activeTool.type==="selection"||e.setActiveTool({type:"selection"}):e.setActiveTool({type:M})},[g,x]=Wu(0),E=36,y=4,w=7,v=w*E+(w-1)*y,I=E+y,C=g>=v+1*I,P=g>=v+2*I,S=g>=v+3*I,_=["text","frame","embeddable","laser","magicframe"].filter(M=>!(C&&M==="text"||P&&M==="image"||S&&M==="frame")).includes(n.type),k=_?n.type==="text"?Fn:n.type==="image"?ts:n.type==="frame"?On:n.type==="embeddable"?os:n.type==="laser"?zn:n.type==="magicframe"?Ka:ic:ic;return Yu("div",{className:"mobile-toolbar",ref:M=>{M&&x(M.getBoundingClientRect().width)},children:[It(J3,{checked:pr(e.state),onChange:t,title:f("toolBar.hand"),isMobile:!0}),It(Qs,{app:e,options:mx,activeTool:n,defaultOption:e.state.preferredSelectionTool.type,namePrefix:"selectionType",title:Tt(f("toolBar.selection")),"data-testid":"toolbar-selection",onToolChange:M=>{(M==="selection"||M==="lasso")&&(e.setActiveTool({type:M}),o({preferredSelectionTool:{type:M,initialized:!0}}))},displayedOption:mx.find(M=>M.type===e.state.preferredSelectionTool.type)||mx[0]}),It(ae,{className:hl({active:n.type==="freedraw"}),type:"radio",icon:Bn,checked:n.type==="freedraw",name:"editor-current-shape",title:`${Tt(f("toolBar.freedraw"))}`,"aria-label":Tt(f("toolBar.freedraw")),"data-testid":"toolbar-freedraw",onChange:()=>h("freedraw")}),It(ae,{className:hl({active:n.type==="eraser"}),type:"radio",icon:hm,checked:n.type==="eraser",name:"editor-current-shape",title:`${Tt(f("toolBar.eraser"))}`,"aria-label":Tt(f("toolBar.eraser")),"data-testid":"toolbar-eraser",onChange:()=>h("eraser")}),It(Qs,{app:e,options:dx,activeTool:n,defaultOption:i,namePrefix:"shapeType",title:Tt(f(i==="rectangle"?"toolBar.rectangle":i==="diamond"?"toolBar.diamond":i==="ellipse"?"toolBar.ellipse":"toolBar.rectangle")),"data-testid":"toolbar-rectangle",onToolChange:M=>{(M==="rectangle"||M==="diamond"||M==="ellipse")&&(s(M),e.setActiveTool({type:M}))},displayedOption:dx.find(M=>M.type===i)||dx[0]}),It(Qs,{app:e,options:px,activeTool:n,defaultOption:l,namePrefix:"linearElementType",title:Tt(f(l==="arrow"?"toolBar.arrow":"toolBar.line")),"data-testid":"toolbar-arrow",fillable:!0,onToolChange:M=>{(M==="arrow"||M==="line")&&(c(M),e.setActiveTool({type:M}))},displayedOption:px.find(M=>M.type===l)||px[0]}),C&&It(ae,{className:hl({active:n.type==="text"}),type:"radio",icon:Fn,checked:n.type==="text",name:"editor-current-shape",title:`${Tt(f("toolBar.text"))}`,"aria-label":Tt(f("toolBar.text")),"data-testid":"toolbar-text",onChange:()=>h("text")}),P&&It(ae,{className:hl({active:n.type==="image"}),type:"radio",icon:ts,checked:n.type==="image",name:"editor-current-shape",title:`${Tt(f("toolBar.image"))}`,"aria-label":Tt(f("toolBar.image")),"data-testid":"toolbar-image",onChange:()=>h("image")}),S&&It(ae,{className:hl({active:m}),type:"radio",icon:On,checked:m,name:"editor-current-shape",title:`${Tt(f("toolBar.frame"))}`,"aria-label":Tt(f("toolBar.frame")),"data-testid":"toolbar-frame",onChange:()=>h("frame")}),Yu(ye,{open:r,children:[It(ye.Trigger,{className:hl("App-toolbar__extra-tools-trigger App-toolbar__extra-tools-trigger--mobile",{"App-toolbar__extra-tools-trigger--selected":_||r}),onToggle:()=>{a(!r),o({openMenu:null,openPopup:null})},title:f("toolBar.extraTools"),style:{width:E,height:E,display:"flex",alignItems:"center",justifyContent:"center"},children:k}),Yu(ye.Content,{onClickOutside:()=>a(!1),onSelect:()=>a(!1),className:"App-toolbar__extra-tools-dropdown",align:"start",children:[!C&&It(ye.Item,{onSelect:()=>e.setActiveTool({type:"text"}),icon:Fn,shortcut:cx.T.toLocaleUpperCase(),"data-testid":"toolbar-text",selected:n.type==="text",children:f("toolBar.text")}),!P&&It(ye.Item,{onSelect:()=>e.setActiveTool({type:"image"}),icon:ts,"data-testid":"toolbar-image",selected:n.type==="image",children:f("toolBar.image")}),!S&&It(ye.Item,{onSelect:()=>e.setActiveTool({type:"frame"}),icon:On,shortcut:cx.F.toLocaleUpperCase(),"data-testid":"toolbar-frame",selected:m,children:f("toolBar.frame")}),It(ye.Item,{onSelect:()=>e.setActiveTool({type:"embeddable"}),icon:os,"data-testid":"toolbar-embeddable",selected:d,children:f("toolBar.embeddable")}),It(ye.Item,{onSelect:()=>e.setActiveTool({type:"laser"}),icon:zn,"data-testid":"toolbar-laser",selected:p,shortcut:cx.K.toLocaleUpperCase(),children:f("toolBar.laser")}),It("div",{style:{margin:"6px 0",fontSize:14,fontWeight:600},children:"Generate"}),e.props.aiEnabled!==!1&&It(u.Out,{}),It(ye.Item,{onSelect:()=>e.setOpenDialog({name:"ttd",tab:"mermaid"}),icon:ss,"data-testid":"toolbar-embeddable",children:f("toolBar.mermaidToExcalidraw")}),e.props.aiEnabled!==!1&&e.plugins.diagramToCode&&It(aY,{children:Yu(ye.Item,{onSelect:()=>e.onMagicframeToolSelect(),icon:Ka,"data-testid":"toolbar-magicframe",children:[f("toolBar.magicframe"),It(ye.Item.Badge,{children:"AI"})]})})]})]})]})};import iY from"clsx";import{jsx as sY}from"react/jsx-runtime";var $u=({children:e,side:t,className:o})=>sY("div",{className:iY("FixedSideContainer",`FixedSideContainer_side_${t}`,o),children:e});import lY from"clsx";import{jsx as tS,jsxs as dY}from"react/jsx-runtime";var cY="medium",Vu=e=>e.penDetected?dY("label",{className:lY("ToolIcon ToolIcon__penMode",`ToolIcon_size_${cY}`,{"is-mobile":e.isMobile}),title:`${e.title}`,children:[tS("input",{className:"ToolIcon_type_checkbox",type:"checkbox",name:e.name,onChange:e.onChange,checked:e.checked,"aria-label":e.title}),tS("div",{className:"ToolIcon__icon",children:BE})]}):null;import{Fragment as oS,jsx as Jn,jsxs as vi}from"react/jsx-runtime";var nS=({appState:e,elements:t,actionManager:o,setAppState:n,onHandToolToggle:r,renderTopLeftUI:a,renderTopRightUI:i,renderSidebars:s,renderWelcomeScreen:l,UIOptions:c,app:m,onPenModeToggle:p})=>{let{WelcomeScreenCenterTunnel:d,MainMenuTunnel:u,DefaultSidebarTriggerTunnel:h}=Ze(),g=()=>{if(e.openDialog?.name==="elementLinkSelector")return null;let E=vi("div",{className:"excalidraw-ui-top-right",children:[i?.(!0,e)??(!e.viewModeEnabled&&vi(oS,{children:[Jn(Vu,{checked:e.penMode,onChange:()=>p(null),title:f("toolBar.penMode"),isMobile:!0,penDetected:e.penDetected}),Jn(h.Out,{})]})),e.viewModeEnabled&&Jn(s5,{actionManager:o})]}),y=vi("div",{className:"excalidraw-ui-top-left",children:[a?.(!0,e),Jn(u.Out,{})]});return vi("div",{className:"App-toolbar-content",style:{display:"flex",flexDirection:"row",justifyContent:"space-between"},children:[y,E]})},x=()=>Jn(eS,{app:m,onHandToolToggle:r,setAppState:n});return vi(oS,{children:[s(),Jn("div",{className:"App-welcome-screen",children:l&&Jn(d.Out,{})}),!e.viewModeEnabled&&vi("div",{className:"App-bottom-bar",style:{marginBottom:Jo+Lr},children:[Jn(t5,{appState:e,elementsMap:m.scene.getNonDeletedElementsMap(),renderAction:o.renderAction,app:m,setAppState:n}),vi(gt,{className:"App-toolbar",children:[!e.viewModeEnabled&&e.openDialog?.name!=="elementLinkSelector"&&x(),e.scrolledOutside&&!e.openMenu&&!e.openSidebar&&Jn("button",{type:"button",className:"scroll-back-to-content",onClick:()=>{n(E=>({...Ha(t,E)}))},children:f("buttons.scrollBackToContent")})]})]}),Jn($u,{side:"top",className:"App-top-bar",children:g()})]})};import mY,{useLayoutEffect as pY,useRef as uY,useState as gY}from"react";import{jsx as ud,jsxs as hY}from"react/jsx-runtime";var rS=e=>{let t=uY(null),[o,n]=gY(null);return pY(()=>{if(!e.spreadsheet)return;let r=sI(e.chartType,e.spreadsheet,0,0);n(r);let a,i=t.current;return(async()=>(a=await Yi(r,{exportBackground:!1,viewBackgroundColor:"#fff"},null,{skipInliningFonts:!0}),a.querySelector(".style-fonts")?.remove(),i.replaceChildren(),i.appendChild(a),e.selected&&i.parentNode.focus()))(),()=>{i.replaceChildren()}},[e.spreadsheet,e.chartType,e.selected]),ud("button",{type:"button",className:"ChartPreview",onClick:()=>{o&&e.onClick(e.chartType,o)},children:ud("div",{ref:t})})},aS=({setAppState:e,appState:t,onClose:o})=>{let{onInsertElements:n}=tt(),r=mY.useCallback(()=>{o&&o()},[o]),a=(i,s)=>{n(s),be("paste","chart",i),e({currentChartType:i,pasteDialog:{shown:!1,data:null}})};return ud(bt,{size:"small",onCloseRequest:r,title:f("labels.pasteCharts"),className:"PasteChartDialog",autofocus:!1,children:hY("div",{className:"container",children:[ud(rS,{chartType:"bar",spreadsheet:t.pasteDialog.data,selected:t.currentChartType==="bar",onClick:a}),ud(rS,{chartType:"line",spreadsheet:t.pasteDialog.data,selected:t.currentChartType==="line",onClick:a})]})})};import{Fragment as fY,jsx as iS,jsxs as bY}from"react/jsx-runtime";var gd=({heading:e,children:t,...o})=>{let{id:n}=Qe(),r=iS("h2",{className:"visually-hidden",id:`${n}-${e}-title`,children:f(`headings.${e}`)});return iS("section",{...o,"aria-labelledby":`${n}-${e}-title`,children:typeof t=="function"?t(r):bY(fY,{children:[r,t]})})};import{Popover as Ku}from"radix-ui";import sS from"clsx";import Xu,{useLayoutEffect as xY}from"react";import{supportsResizeObserver as yY,isShallowEqual as EY}from"@orangecatai/common";import{Fragment as CY,jsx as Qn,jsxs as Zu}from"react/jsx-runtime";var wY=4,vY=8,IY=({shouldWrap:e,children:t,username:o})=>e?Qn(Xt,{label:o||"Unknown user",children:t}):Qn(CY,{children:t}),ux=({actionManager:e,collaborator:t,socketId:o,withName:n=!1,shouldWrapWithTooltip:r=!1,isBeingFollowed:a})=>{let i={socketId:o,collaborator:t,withName:n,isBeingFollowed:a},s=e.renderAction("goToCollaborator",i);return Qn(IY,{username:t.username,shouldWrap:r,children:s},o)},TY=["avatarUrl","id","socketId","username","isInCall","isSpeaking","isMuted"],ju=Xu.memo(({className:e,mobile:t,collaborators:o,userToFollow:n})=>{let r=at(),a=new Map;o.forEach((g,x)=>{let E=g.id||x;a.set(E,{...g,socketId:x})});let i=Array.from(a.values()).filter(g=>g.username?.trim()),[s,l]=Xu.useState(""),c=i.filter(g=>g.username?.toLowerCase().includes(s)),m=Xu.useRef(null);xY(()=>{if(m.current){let g=E=>{let y=Math.max(1,Math.min(8,Math.floor(E/38)));d(y)};if(g(m.current.clientWidth),!yY)return;let x=new ResizeObserver(E=>{for(let y of E){let{width:w}=y.contentRect;g(w)}});return x.observe(m.current),()=>{x.disconnect()}}},[]);let[p,d]=Xu.useState(wY),h=i.slice(0,p-1).map(g=>ux({actionManager:r,collaborator:g,socketId:g.socketId,shouldWrapWithTooltip:!0,isBeingFollowed:g.socketId===n}));return t?Qn("div",{className:sS("UserList UserList_mobile",e),children:i.map(g=>ux({actionManager:r,collaborator:g,socketId:g.socketId,shouldWrapWithTooltip:!0,isBeingFollowed:g.socketId===n}))}):Qn("div",{className:"UserList__wrapper",ref:m,children:Zu("div",{className:sS("UserList",e),style:{"--max-avatars":p},children:[h,i.length>p-1&&Zu(Ku.Root,{children:[Zu(Ku.Trigger,{className:"UserList__more",children:["+",i.length-p+1]}),Qn(Ku.Content,{style:{zIndex:2,width:"15rem",textAlign:"left"},align:"end",sideOffset:10,children:Zu(gt,{padding:2,children:[i.length>=vY&&Qn(Gm,{placeholder:f("quickSearch.placeholder"),onChange:l}),Qn(Um,{className:"dropdown-menu UserList__collaborators",placeholder:f("userList.empty"),children:c.length>0?[Qn("div",{className:"hint",children:f("userList.hint.text")}),c.map(g=>ux({actionManager:r,collaborator:g,socketId:g.socketId,withName:!0,isBeingFollowed:g.socketId===n}))]:[]}),Qn(Ku.Arrow,{width:20,height:10,style:{fill:"var(--popup-bg-color)",filter:"drop-shadow(rgba(0, 0, 0, 0.05) 0px 3px 2px)"}})]})})]})]})})},(e,t)=>{if(e.collaborators.size!==t.collaborators.size||e.mobile!==t.mobile||e.className!==t.className||e.userToFollow!==t.userToFollow)return!1;let o=t.collaborators.keys();for(let[n,r]of e.collaborators){let a=t.collaborators.get(n);if(!a||n!==o.next().value||!EY(r,a,TY))return!1}return!0});import xx from"clsx";import{useState as NY,useRef as cS,useEffect as BY,useCallback as FY}from"react";import{useCallback as Eo,useEffect as PY,useRef as fd,useState as hx}from"react";var gx=({h:e,s:t,v:o,a:n})=>{e=e/360,t=t/100,o=o/100;let r=0,a=0,i=0,s=Math.floor(e*6),l=e*6-s,c=o*(1-t),m=o*(1-l*t),p=o*(1-(1-l)*t);switch(s%6){case 0:r=o,a=p,i=c;break;case 1:r=m,a=o,i=c;break;case 2:r=c,a=o,i=p;break;case 3:r=c,a=m,i=o;break;case 4:r=p,a=c,i=o;break;case 5:r=o,a=c,i=m;break}return{r:Math.round(r*255),g:Math.round(a*255),b:Math.round(i*255),a:n}},kY=({r:e,g:t,b:o,a:n})=>{e/=255,t/=255,o/=255;let r=Math.max(e,t,o),a=Math.min(e,t,o),i=r-a,s=0,l=r===0?0:i/r*100,c=r*100;if(i!==0)switch(r){case e:s=((t-o)/i+(t<o?6:0))*60;break;case t:s=((o-e)/i+2)*60;break;case o:s=((e-t)/i+4)*60;break}return{h:s,s:l,v:c,a:n}},SY=({r:e,g:t,b:o,a:n})=>{let r=i=>i.toString(16).padStart(2,"0"),a=`#${r(e)}${r(t)}${r(o)}`;return n<1?`${a}${r(Math.round(n*255))}`:a},MY=e=>{let t=e.replace(/^#/,"");t.length===3?t=t[0]+t[0]+t[1]+t[1]+t[2]+t[2]:t.length===4&&(t=t[0]+t[0]+t[1]+t[1]+t[2]+t[2]+t[3]+t[3]);let o=parseInt(t.slice(0,2),16),n=parseInt(t.slice(2,4),16),r=parseInt(t.slice(4,6),16),a=t.length===8?parseInt(t.slice(6,8),16)/255:1;return{r:isNaN(o)?0:o,g:isNaN(n)?0:n,b:isNaN(r)?0:r,a:isNaN(a)?1:a}},qu=e=>SY(gx(e)),hd=e=>kY(MY(e));var fl=(e,t,o)=>Math.max(t,Math.min(o,e));import{jsx as Pt,jsxs as bl}from"react/jsx-runtime";var AY=["transparent","#000000","#ffffff","#00e639","#a855f4","#d4b0ff"],fx=(e,t)=>{let o=fd(null),n=fd(!1),r=fd(null),a=fd(null),i=Eo((p,d)=>{if(!o.current||!n.current)return;let u=o.current.getBoundingClientRect();e(p,d,u)},[e]),s=Eo(()=>{n.current=!1,t?.(),r.current&&(window.removeEventListener("mousemove",r.current),r.current=null),a.current&&(window.removeEventListener("touchmove",a.current),a.current=null),window.removeEventListener("mouseup",s),window.removeEventListener("touchend",s)},[t]),l=Eo(p=>i(p.clientX,p.clientY),[i]),c=Eo(p=>{p.preventDefault(),i(p.touches[0].clientX,p.touches[0].clientY)},[i]),m=Eo(p=>{p.preventDefault(),p.stopPropagation(),n.current=!0;let d="touches"in p?p.touches[0].clientX:p.clientX,u="touches"in p?p.touches[0].clientY:p.clientY;if(o.current){let h=o.current.getBoundingClientRect();e(d,u,h)}r.current=l,a.current=c,window.addEventListener("mousemove",l),window.addEventListener("mouseup",s),window.addEventListener("touchmove",c,{passive:!1}),window.addEventListener("touchend",s)},[e,l,c,s]);return{ref:o,handleDown:m}},LY=({hsva:e,onChange:t})=>{let{ref:o,handleDown:n}=fx((s,l,c)=>{let m=fl(s-c.left,0,c.width),p=fl(l-c.top,0,c.height),d=m/c.width*100,u=100-p/c.height*100;t(d,u)}),r=`hsl(${e.h}, 100%, 50%)`,a=`${e.s}%`,i=`${100-e.v}%`;return bl("div",{ref:o,className:"adv-cp__saturation",style:{backgroundColor:r},onMouseDown:n,onTouchStart:n,children:[Pt("div",{className:"adv-cp__saturation-white"}),Pt("div",{className:"adv-cp__saturation-black"}),Pt("div",{className:"adv-cp__handle",style:{left:a,top:i}})]})},_Y=({hue:e,onChange:t})=>{let{ref:o,handleDown:n}=fx((r,a,i)=>{let s=fl(r-i.left,0,i.width);t(s/i.width*360)});return Pt("div",{ref:o,className:"adv-cp__slider adv-cp__hue-slider",onMouseDown:n,onTouchStart:n,children:Pt("div",{className:"adv-cp__slider-handle",style:{left:`${e/360*100}%`}})})},DY=({hsva:e,onChange:t})=>{let{r:o,g:n,b:r}=gx({...e,a:1}),a=`rgba(${o}, ${n}, ${r}, 1)`,{ref:i,handleDown:s}=fx((l,c,m)=>{let p=fl(l-m.left,0,m.width);t(p/m.width)});return bl("div",{ref:i,className:"adv-cp__slider adv-cp__alpha-slider",onMouseDown:s,onTouchStart:s,children:[Pt("div",{className:"adv-cp__alpha-checker"}),Pt("div",{className:"adv-cp__alpha-gradient",style:{background:`linear-gradient(to right, transparent 0%, ${a} 100%)`}}),Pt("div",{className:"adv-cp__slider-handle",style:{left:`${e.a*100}%`}})]})},RY=({activeColor:e,onChange:t})=>Pt("div",{className:"adv-cp__presets",children:AY.map(o=>Pt("button",{type:"button",className:`adv-cp__preset-btn${o===e?" active":""}${o==="transparent"?" is-transparent":""}`,style:o!=="transparent"?{backgroundColor:o}:void 0,title:o,onClick:()=>t(o),children:o==="transparent"&&Pt("div",{className:"adv-cp__preset-slash"})},o))}),lS=({color:e,onChange:t,showAlpha:o=!0})=>{let[n,r]=hx(()=>!e||e==="transparent"?{h:0,s:0,v:100,a:e==="transparent"?0:1}:hd(e)),[a,i]=hx(()=>e==="transparent"?"000000":(e||"#ffffff").replace(/^#/,"").toUpperCase()),[s,l]=hx(()=>Math.round(n.a*100).toString()),c=fd(e);PY(()=>{if(e!==c.current)if(c.current=e,!e||e==="transparent")r({h:0,s:0,v:100,a:0}),i("000000"),l("0");else{let w=hd(e);r(w),i(e.replace(/^#/,"").substring(0,6).toUpperCase()),l(Math.round(w.a*100).toString())}},[e]);let m=Eo(w=>{r(w);let v=qu(w);c.current=v,i(v.replace(/^#/,"").substring(0,6).toUpperCase()),l(Math.round(w.a*100).toString()),w.a===0?t("transparent"):t(v)},[t]),p=Eo((w,v)=>{m({...n,s:w,v})},[n,m]),d=Eo(w=>{m({...n,h:w})},[n,m]),u=Eo(w=>{m({...n,a:w})},[n,m]),h=Eo(w=>{if(w==="transparent")m({h:0,s:0,v:100,a:0});else{let v=hd(w);v.a=1,m(v)}},[m]),g=Eo(()=>{let w=a.trim().replace(/^#/,"");if(/^[0-9a-fA-F]{3}$|^[0-9a-fA-F]{6}$|^[0-9a-fA-F]{8}$/.test(w)){let v=hd(`#${w}`);m(v)}else{let v=qu(n);i(v.replace(/^#/,"").substring(0,6).toUpperCase())}},[a,n,m]),x=Eo(w=>{w.key==="Enter"&&g(),w.stopPropagation()},[g]),E=Eo(()=>{let w=parseInt(s,10);if(isNaN(w))l(Math.round(n.a*100).toString());else{let v=fl(w,0,100)/100;m({...n,a:v})}},[s,n,m]),y=Eo(w=>{w.key==="Enter"&&E(),w.stopPropagation()},[E]);return bl("div",{className:"adv-cp",children:[Pt(LY,{hsva:n,onChange:p}),Pt(_Y,{hue:n.h,onChange:d}),o&&Pt(DY,{hsva:n,onChange:u}),Pt(RY,{activeColor:n.a===0?"transparent":qu({...n,a:1}).toLowerCase(),onChange:h}),bl("div",{className:"adv-cp__inputs",children:[bl("div",{className:"adv-cp__hex-input",children:[Pt("span",{className:"adv-cp__hash",children:"#"}),Pt("input",{type:"text",style:{border:0,padding:0,margin:0,outline:"none"},spellCheck:!1,value:a,onChange:w=>i(w.target.value.toUpperCase()),onBlur:g,onKeyDown:x,maxLength:8,"aria-label":"Hex color"})]}),o&&bl("div",{className:"adv-cp__alpha-input",children:[Pt("input",{type:"text",style:{border:0,padding:0,margin:0,outline:"none"},value:s,onChange:w=>l(w.target.value),onBlur:E,onKeyDown:y,maxLength:3,"aria-label":"Opacity percentage"}),Pt("span",{className:"adv-cp__percent",children:"%"})]})]})]})};import{jsx as fa,jsxs as bx}from"react/jsx-runtime";var dS=({actionManager:e,appState:t})=>{let[o,n]=NY(!1),r=cS(null),a=cS(null);BY(()=>{if(!o)return;let c=m=>{r.current&&!r.current.contains(m.target)&&a.current&&!a.current.contains(m.target)&&n(!1)};return document.addEventListener("mousedown",c),()=>document.removeEventListener("mousedown",c)},[o]);let i=t.viewBackgroundColor||"#ffffff",s=i==="transparent",l=FY(c=>{e.executeAction(e.actions.changeViewBackgroundColor,"ui",{viewBackgroundColor:c})},[e]);return bx("div",{className:"canvas-bg-swatch-wrapper",children:[fa(Xt,{label:f("labels.canvasBackground"),children:fa("button",{ref:a,type:"button",className:"canvas-bg-swatch",onClick:()=>n(c=>!c),title:f("labels.canvasBackground"),children:fa("div",{className:"canvas-bg-swatch__color",style:{backgroundColor:s?void 0:i},children:s&&fa("div",{className:"canvas-bg-swatch__transparent"})})})}),o&&bx("div",{ref:r,className:"canvas-bg-swatch__popover",children:[bx("div",{className:"canvas-bg-swatch__popover-header",children:[fa("span",{children:f("labels.canvasBackground")}),fa("button",{type:"button",className:"canvas-bg-swatch__close",onClick:()=>n(!1),children:"\u2715"})]}),fa("div",{className:"canvas-bg-swatch__picker-content",children:fa(lS,{color:i,onChange:l,showAlpha:!0})})]})]})};import{jsx as OY}from"react/jsx-runtime";var mS=e=>OY("button",{className:"help-icon",onClick:e.onClick,type:"button",title:`${f("helpDialog.title")} \u2014 ?`,"aria-label":f("helpDialog.title"),children:ns});import{jsx as en,jsxs as bd}from"react/jsx-runtime";var pS=({appState:e,actionManager:t,showExitZenModeBtn:o,renderWelcomeScreen:n})=>{let{FooterCenterTunnel:r,WelcomeScreenHelpHintTunnel:a}=Ze();return bd("footer",{role:"contentinfo",className:"layer-ui__wrapper__footer App-menu App-menu_bottom",children:[en("div",{className:xx("layer-ui__wrapper__footer-left zen-mode-transition",{"layer-ui__wrapper__footer-left--transition-left":e.zenModeEnabled}),children:en(Rt.Col,{gap:2,children:en(gd,{heading:"canvasActions",children:bd(Rt.Col,{gap:1,className:"footer-canvas-actions",children:[bd(Rt.Row,{align:"center",gap:1,children:[en(n5,{renderAction:t.renderAction}),!e.viewModeEnabled&&en(dS,{actionManager:t,appState:e})]}),bd(Rt.Row,{align:"center",gap:1,className:"footer-canvas-actions-row",children:[en(r5,{renderAction:t.renderAction,zoom:e.zoom}),!e.viewModeEnabled&&en(a5,{renderAction:t.renderAction,className:xx("zen-mode-transition",{"layer-ui__wrapper__footer-left--transition-bottom":e.zenModeEnabled})})]})]})})})}),en(r.Out,{}),en("div",{className:xx("layer-ui__wrapper__footer-right zen-mode-transition",{"transition-right":e.zenModeEnabled}),children:bd("div",{style:{position:"relative"},children:[n&&en(a.Out,{}),en(mS,{onClick:()=>t.executeAction(oi)})]})}),en(i5,{actionManager:t,showExitZenModeBtn:o})]})},uS=pS;pS.displayName="Footer";import jY from"clsx";import{useEffect as ES,useLayoutEffect as wS,useRef as Sx,useState as qY,forwardRef as vS,useImperativeHandle as JY,useCallback as bS}from"react";import{CLASSES as QY,EVENT as xS,isDevEnv as e$,KEYS as t$,updateObject as o$}from"@orangecatai/common";import HY from"clsx";import{useContext as GY}from"react";import zY from"react";var Ju=zY.createContext({});import{jsx as yx,jsxs as gS}from"react/jsx-runtime";var Ex=({children:e,className:t})=>{let o=Te(),n=GY(Ju),r=!!(o.canFitSidebar&&n.shouldRenderDockButton);return gS("div",{className:HY("sidebar__header",t),"data-testid":"sidebar-header",children:[e,gS("div",{className:"sidebar__header__buttons",children:[r&&yx(Xt,{label:f("labels.sidebarLock"),children:yx(so,{onSelect:()=>n.onDock?.(!n.docked),selected:!!n.docked,className:"sidebar__dock","data-testid":"sidebar-dock","aria-label":f("labels.sidebarLock"),children:LE})}),yx(so,{"data-testid":"sidebar-close",className:"sidebar__close",onSelect:n.onCloseRequest,"aria-label":f("buttons.close"),children:Go})]})]})};Ex.displayName="SidebarHeader";import{Tabs as UY}from"radix-ui";import{jsx as hS}from"react/jsx-runtime";var wx=({children:e,tab:t,onSelect:o,...n})=>hS(UY.Trigger,{value:t,asChild:!0,onSelect:o,children:hS("button",{type:"button",className:"excalidraw-button sidebar-tab-trigger",...n,children:e})});wx.displayName="SidebarTabTrigger";import{Tabs as WY}from"radix-ui";import{jsx as YY}from"react/jsx-runtime";var vx=({children:e,...t})=>YY(WY.List,{className:"sidebar-triggers",...t,children:e});vx.displayName="SidebarTabTriggers";import $Y from"clsx";import{jsx as Ix,jsxs as fS}from"react/jsx-runtime";var Tx=({name:e,tab:t,icon:o,title:n,children:r,onToggle:a,className:i,style:s})=>{let l=Ce(),c=Ie();return fS("label",{title:n,className:"sidebar-trigger__label-element",children:[Ix("input",{className:"ToolIcon_type_checkbox",type:"checkbox",onChange:m=>{document.querySelector(".layer-ui__wrapper")?.classList.remove("animate");let p=m.target.checked;l({openSidebar:p?{name:e,tab:t}:null,openMenu:null,openPopup:null}),a?.(p)},checked:c.openSidebar?.name===e,"aria-label":n,"aria-keyshortcuts":"0"}),fS("div",{className:$Y("sidebar-trigger",i),style:s,children:[o&&Ix("div",{children:o}),r&&Ix("div",{className:"sidebar-trigger__label",children:r})]})]})};Tx.displayName="SidebarTrigger";import{Tabs as VY}from"radix-ui";import{jsx as KY}from"react/jsx-runtime";var Cx=({children:e,...t})=>{let o=Ie(),n=Ce();if(!o.openSidebar)return null;let{name:r}=o.openSidebar;return KY(VY.Root,{className:"sidebar-tabs-root",value:o.openSidebar.tab,onValueChange:a=>n(i=>({...i,openSidebar:{...i.openSidebar,name:r,tab:a}})),...t,children:e})};Cx.displayName="SidebarTabs";import{Tabs as XY}from"radix-ui";import{jsx as ZY}from"react/jsx-runtime";var kx=({tab:e,children:t,...o})=>ZY(XY.Content,{...o,value:e,"data-testid":e,children:t});kx.displayName="SidebarTab";import{jsx as yS}from"react/jsx-runtime";import{createElement as n$}from"react";var xd=Pe(!1),IS=vS(({name:e,children:t,onDock:o,docked:n,className:r,...a},i)=>{e$()&&o&&n==null&&console.warn("Sidebar: `docked` must be set when `onDock` is supplied for the sidebar to be user-dockable. To hide this message, either pass `docked` or remove `onDock`");let s=Ce(),l=Rn(xd);wS(()=>(l(!!n),()=>{l(!1)}),[l,n]);let c=Sx({});c.current.onCloseRequest=()=>{s({openSidebar:null})},c.current.onDock=u=>o?.(u),c.current=o$(c.current,{docked:n,shouldRenderDockButton:!!o&&n!=null});let m=Sx(null);JY(i,()=>m.current);let p=Te(),d=bS(()=>{document.querySelector(".Dialog")||s({openSidebar:null})},[s]);return fs(m,bS(u=>{u.target.closest(".sidebar-trigger")||(!n||!p.canFitSidebar)&&d()},[d,n,p.canFitSidebar])),ES(()=>{let u=h=>{h.key===t$.ESCAPE&&(!n||!p.canFitSidebar)&&d()};return document.addEventListener(xS.KEYDOWN,u),()=>{document.removeEventListener(xS.KEYDOWN,u)}},[d,n,p.canFitSidebar]),yS(gt,{...a,className:jY(QY.SIDEBAR,{"sidebar--docked":n},r),ref:m,children:yS(Ju.Provider,{value:c.current,children:t})})});IS.displayName="SidebarInner";var tn=Object.assign(vS((e,t)=>{let o=Ie()??{openSidebar:null},{onStateChange:n}=e,r=Sx(o.openSidebar);ES(()=>{(!o.openSidebar&&r?.current?.name===e.name||o.openSidebar?.name===e.name&&r?.current?.name!==e.name||r.current?.name===e.name)&&o.openSidebar!==r.current&&n?.(o.openSidebar?.name!==e.name?null:o.openSidebar),r.current=o.openSidebar},[o.openSidebar,n,e.name]);let[a,i]=qY(!1);return wS(()=>(i(!0),()=>i(!1)),[]),a&&o.openSidebar?.name===e.name?n$(IS,{...e,ref:t,key:e.name}):null}),{Header:Ex,TabTriggers:vx,TabTrigger:wx,Tabs:Cx,Tab:kx,Trigger:Tx});tn.displayName="Sidebar";import{composeEventHandlers as m$}from"@orangecatai/common";import{useLayoutEffect as r$,useRef as a$}from"react";import{jsx as i$}from"react/jsx-runtime";var _r=(e,t)=>{let o=Pe(0),n=r=>{let{tunnelsJotai:{useAtom:a}}=Ze(),[,i]=a(o),s=a$({preferHost:!1,counter:0});return r$(()=>{let l=s.current;return i(c=>{let m=c+1;return l.counter=m,m}),()=>{i(c=>{let m=c-1;return l.counter=m,m||(l.preferHost=!1),m})}},[i]),r.__fallback||(s.current.preferHost=!0),!s.current.counter&&r.__fallback&&s.current.preferHost||s.current.counter>1&&r.__fallback?null:i$(t,{...r})};return n.displayName=e,n};var _x={};eE(_x,{ChangeCanvasBackground:()=>FS,ClearCanvas:()=>NS,CommandPalette:()=>_S,Export:()=>OS,Help:()=>RS,LiveCollaborationTrigger:()=>HS,LoadScene:()=>PS,Preferences:()=>xa,PreferencesToggleGridModeItem:()=>Ax,PreferencesToggleZenModeItem:()=>Lx,SaveAsImage:()=>LS,SaveToActiveFile:()=>AS,SearchMenu:()=>DS,Socials:()=>zS,ToggleTheme:()=>BS});import d$ from"clsx";import{THEME as ba}from"@orangecatai/common";var Mx=Pe({active:!1});async function TS({title:e,description:t,actionLabel:o,color:n}){return new Promise(r=>{Et.set(Mx,{active:!0,onConfirm:()=>r(!0),onClose:()=>r(!1),onReject:()=>r(!1),title:e,description:t,actionLabel:o,color:n})})}import s$ from"clsx";import{jsx as CS,jsxs as l$}from"react/jsx-runtime";var Qu=function({onChange:e,value:t,choices:o,name:n}){return CS("div",{className:"RadioGroup",children:o.map(r=>l$("div",{className:s$("RadioGroup__choice",{active:r.value===t}),title:r.ariaLabel,children:[CS("input",{name:n,type:"radio",checked:r.value===t,onChange:()=>e(r.value),"aria-label":r.ariaLabel}),r.label]},String(r.value)))})};import{Fragment as c$,jsx as Px,jsxs as kS}from"react/jsx-runtime";var SS=({value:e,shortcut:t,onChange:o,choices:n,children:r,name:a})=>{let i=Te();return kS(c$,{children:[kS("div",{className:"dropdown-menu-item-base dropdown-menu-item-bare",children:[Px("label",{className:"dropdown-menu-item__text",children:r}),Px(Qu,{name:a,value:e,onChange:o,choices:n})]}),t&&i.formFactor!=="phone"&&Px("div",{className:"dropdown-menu-item__shortcut dropdown-menu-item__shortcut--orphaned",children:t})]})};SS.displayName="DropdownMenuItemContentRadio";var MS=SS;import{Fragment as $S,jsx as Fe,jsxs as yd}from"react/jsx-runtime";var PS=()=>{let{t:e}=Ue(),t=at(),o=$r();return t.isActionEnabled(_s)?Fe(to,{icon:rs,onSelect:async()=>{(!o.length||await TS({title:e("overwriteConfirm.modal.loadFromFile.title"),actionLabel:e("overwriteConfirm.modal.loadFromFile.button"),color:"warning",description:Fe(io,{i18nKey:"overwriteConfirm.modal.loadFromFile.description",bold:r=>Fe("strong",{children:r}),br:()=>Fe("br",{})})}))&&t.executeAction(_s)},"data-testid":"load-button",shortcut:Xe("loadScene"),"aria-label":e("buttons.load"),children:e("buttons.load")}):null};PS.displayName="LoadScene";var AS=()=>{let{t:e}=Ue(),t=at();return t.isActionEnabled(ti)?Fe(to,{shortcut:Xe("saveScene"),"data-testid":"save-button",onSelect:()=>t.executeAction(ti),icon:WE,"aria-label":`${e("buttons.save")}`,children:`${e("buttons.save")}`}):null};AS.displayName="SaveToActiveFile";var LS=()=>{let e=Ce(),{t}=Ue();return Fe(to,{icon:ym,"data-testid":"image-export-button",onSelect:()=>e({openDialog:{name:"imageExport"}}),shortcut:Xe("imageExport"),"aria-label":t("buttons.exportImage"),children:t("buttons.exportImage")})};LS.displayName="SaveAsImage";var _S=e=>{let t=Ce(),{t:o}=Ue();return Fe(to,{icon:sc,"data-testid":"command-palette-button",onSelect:()=>{be("command_palette","open","menu"),t({openDialog:{name:"commandPalette"}})},shortcut:Xe("commandPalette"),"aria-label":o("commandPalette.title"),className:e?.className,children:o("commandPalette.title")})};_S.displayName="CommandPalette";var DS=e=>{let{t}=Ue(),o=at();return Fe(to,{icon:Mo,"data-testid":"search-menu-button",onSelect:()=>{o.executeAction(Zc)},shortcut:Xe("searchMenu"),"aria-label":t("search.title"),className:e?.className,children:t("search.title")})};DS.displayName="SearchMenu";var RS=()=>{let{t:e}=Ue(),t=at();return Fe(to,{"data-testid":"help-menu-item",icon:ns,onSelect:()=>t.executeAction(oi),shortcut:"?","aria-label":e("helpDialog.title"),children:e("helpDialog.title")})};RS.displayName="Help";var NS=()=>{let{t:e}=Ue(),t=Rn(si);return at().isActionEnabled(yr)?Fe(to,{icon:Ut,onSelect:()=>t("clearCanvas"),"data-testid":"clear-canvas-button","aria-label":e("buttons.clearReset"),children:e("buttons.clearReset")}):null};NS.displayName="ClearCanvas";var BS=e=>{let{t}=Ue(),o=Ie(),n=at(),r=Xe("toggleTheme");return n.isActionEnabled(qa)?e?.allowSystemTheme?Fe(MS,{name:"theme",value:e.theme,onChange:a=>e.onSelect(a),choices:[{value:ba.LIGHT,label:nc,ariaLabel:`${t("buttons.lightMode")} - ${r}`},{value:ba.DARK,label:oc,ariaLabel:`${t("buttons.darkMode")} - ${r}`},{value:"system",label:sv,ariaLabel:t("buttons.systemMode")}],children:t("labels.theme")}):Fe(to,{onSelect:a=>{if(a.preventDefault(),e?.onSelect)e.onSelect(o.theme===ba.DARK?ba.LIGHT:ba.DARK);else return n.executeAction(qa)},icon:o.theme===ba.DARK?nc:oc,"data-testid":"toggle-dark-mode",shortcut:r,"aria-label":o.theme===ba.DARK?t("buttons.lightMode"):t("buttons.darkMode"),children:o.theme===ba.DARK?t("buttons.lightMode"):t("buttons.darkMode")}):null};BS.displayName="ToggleTheme";var FS=()=>{let{t:e}=Ue(),t=Ie(),o=at(),n=Hn();return t.viewModeEnabled||!n.UIOptions.canvasActions.changeViewBackgroundColor?null:yd("div",{style:{marginTop:"0.75rem"},children:[Fe("div",{"data-testid":"canvas-background-label",style:{fontSize:"0.875rem",marginBottom:"0.25rem",marginLeft:"0.5rem"},children:e("labels.canvasBackground")}),Fe("div",{style:{padding:"0 0.625rem"},children:o.renderAction("changeViewBackgroundColor")})]})};FS.displayName="ChangeCanvasBackground";var OS=()=>{let{t:e}=Ue(),t=Ce();return Fe(to,{icon:$a,onSelect:()=>{t({openDialog:{name:"jsonExport"}})},"data-testid":"json-export-button","aria-label":e("buttons.export"),children:e("buttons.export")})};OS.displayName="Export";var zS=()=>{let{t:e}=Ue();return yd($S,{children:[Fe(qs,{icon:fm,href:"https://github.com/excalidraw/excalidraw","aria-label":"GitHub",children:"GitHub"}),Fe(qs,{icon:UE,href:"https://x.com/excalidraw","aria-label":"X",children:e("labels.followUs")}),Fe(qs,{icon:GE,href:"https://discord.gg/UexuTaE","aria-label":"Discord",children:e("labels.discordChat")})]})};zS.displayName="Socials";var HS=({onSelect:e,isCollaborating:t})=>{let{t:o}=Ue();return Fe(to,{"data-testid":"collab-button",icon:Em,className:d$({"active-collab":t}),onSelect:e,children:o("labels.liveCollaboration")})};HS.displayName="LiveCollaborationTrigger";var GS=()=>{let{t:e}=Ue(),t=tt(),o=Ie();return Fe(Ir,{checked:o.activeTool.locked,shortcut:Xe("toolLock"),onSelect:n=>{t.toggleLock(),n.preventDefault()},children:e("labels.preferences_toolLock")})},US=()=>{let{t:e}=Ue(),t=at(),o=Ie();return Fe(Ir,{checked:o.objectsSnapModeEnabled,shortcut:Xe("objectsSnapMode"),onSelect:n=>{t.executeAction(_c),n.preventDefault()},children:e("buttons.objectsSnapMode")})},Ax=()=>{let{t:e}=Ue(),t=at(),o=Ie();return Fe(Ir,{checked:o.gridModeEnabled,shortcut:Xe("gridMode"),onSelect:n=>{t.executeAction(zs),n.preventDefault()},children:e("labels.toggleGrid")})},Lx=()=>{let{t:e}=Ue(),t=at(),o=Ie();return Fe(Ir,{checked:o.zenModeEnabled,shortcut:Xe("zenMode"),onSelect:n=>{t.executeAction(ta),n.preventDefault()},children:e("buttons.zenMode")})},WS=()=>{let{t:e}=Ue(),t=at(),o=Ie();return Fe(Ir,{checked:o.viewModeEnabled,shortcut:Xe("viewMode"),onSelect:n=>{t.executeAction(ii),n.preventDefault()},children:e("labels.viewMode")})},YS=()=>{let{t:e}=Ue(),t=at(),o=Ie();return Fe(Ir,{checked:o.stats.open,shortcut:Xe("stats"),onSelect:n=>{t.executeAction(oa),n.preventDefault()},children:e("stats.fullTitle")})},xa=({children:e,additionalItems:t})=>{let{t:o}=Ue();return yd(aa,{children:[Fe(aa.Trigger,{icon:yv,children:o("labels.preferences")}),yd(aa.Content,{className:"excalidraw-main-menu-preferences-submenu",children:[e||yd($S,{children:[Fe(GS,{}),Fe(US,{}),Fe(Ax,{}),Fe(Lx,{}),Fe(WS,{}),Fe(YS,{})]}),t]})]})};xa.ToggleToolLock=GS;xa.ToggleSnapMode=US;xa.ToggleGridMode=Ax;xa.ToggleZenMode=Lx;xa.ToggleViewMode=WS;xa.ToggleElementProperties=YS;xa.displayName="Preferences";import{jsx as eg,jsxs as Dx}from"react/jsx-runtime";var p$=Object.assign(_r("MainMenu",({children:e,onSelect:t})=>{let{MainMenuTunnel:o}=Ze(),n=Te(),r=Ie(),a=Ce();return eg(o.In,{children:Dx(ye,{open:r.openMenu==="canvas",children:[eg(ye.Trigger,{onToggle:()=>{a({openMenu:r.openMenu==="canvas"?null:"canvas",openPopup:null,openDialog:null})},"data-testid":"main-menu-trigger",className:"main-menu-trigger",children:zE}),Dx(ye.Content,{onClickOutside:()=>a({openMenu:null}),onSelect:m$(t,()=>{a({openMenu:null})}),className:"main-menu",align:"start",children:[e,n.formFactor==="phone"&&r.collaborators.size>0&&Dx("fieldset",{className:"UserList-Wrapper",children:[eg("legend",{children:f("labels.collaborators")}),eg(ju,{mobile:!0,collaborators:r.collaborators,userToFollow:r.userToFollow?.socketId||null})]})]})]})})}),{Trigger:ye.Trigger,Item:ye.Item,ItemLink:ye.ItemLink,ItemCustom:ye.ItemCustom,Group:ye.Group,Separator:ye.Separator,Sub:aa,DefaultItems:_x}),jt=p$;import u$ from"clsx";import{forwardRef as g$,useState as h$}from"react";import{isPromiseLike as f$}from"@orangecatai/common";import{jsx as tg,jsxs as b$}from"react/jsx-runtime";var on=g$(({children:e,icon:t,onClick:o,label:n,variant:r="filled",color:a="primary",size:i="medium",fullWidth:s,className:l,status:c,disabled:m},p)=>{let[d,u]=h$(!1),h=async x=>{let E=o?.(x);if(f$(E)){let y=window.setTimeout(()=>{u(!0)},50);try{await E}catch(w){if(w instanceof Ui)console.warn(w);else throw w}finally{clearTimeout(y),u(!1)}}},g=d?"loading":c;return a=g==="success"?"success":a,tg("button",{className:u$("ExcButton",`ExcButton--color-${a}`,`ExcButton--variant-${r}`,`ExcButton--size-${i}`,`ExcButton--status-${g}`,{"ExcButton--fullWidth":s},l),onClick:h,type:"button","aria-label":n,ref:p,disabled:m||g==="loading"||g==="success",children:b$("div",{className:"ExcButton__contents",children:[g==="loading"?tg(Wt,{className:"ExcButton__statusIcon"}):g==="success"&&tg("div",{className:"ExcButton__statusIcon",children:Hw}),t&&tg("div",{className:"ExcButton__icon","aria-hidden":!0,children:t}),r!=="icon"&&(e??n)]})})});import{jsx as xl,jsxs as E$}from"react/jsx-runtime";var og=({title:e,children:t,actionLabel:o,onClick:n})=>E$("div",{className:"OverwriteConfirm__Actions__Action",children:[xl("h4",{children:e}),xl("div",{className:"OverwriteConfirm__Actions__Action__content",children:t}),xl(on,{variant:"outlined",color:"muted",label:o,size:"large",fullWidth:!0,onClick:n})]}),x$=()=>{let{t:e}=Ue(),t=at(),o=Ce();return xl(og,{title:e("overwriteConfirm.action.exportToImage.title"),actionLabel:e("overwriteConfirm.action.exportToImage.button"),onClick:()=>{t.executeAction(cp,"ui",!0),o({openDialog:{name:"imageExport"}})},children:e("overwriteConfirm.action.exportToImage.description")})},y$=()=>{let{t:e}=Ue(),t=at();return xl(og,{title:e("overwriteConfirm.action.saveToDisk.title"),actionLabel:e("overwriteConfirm.action.saveToDisk.button"),onClick:()=>{t.executeAction(Ac,"ui")},children:e("overwriteConfirm.action.saveToDisk.description")})},Rx=Object.assign(({children:e})=>xl("div",{className:"OverwriteConfirm__Actions",children:e}),{ExportToImage:x$,SaveToDisk:y$});import{jsx as ya,jsxs as VS}from"react/jsx-runtime";var ng=Object.assign(_r("OverwriteConfirmDialog",({children:e})=>{let{OverwriteConfirmDialogTunnel:t}=Ze(),[o,n]=le(Mx);if(!o.active)return null;let r=()=>{o.onClose(),n(i=>({...i,active:!1}))},a=()=>{o.onConfirm(),n(i=>({...i,active:!1}))};return ya(t.In,{children:ya(bt,{onCloseRequest:r,title:!1,size:916,children:VS("div",{className:"OverwriteConfirm",children:[ya("h3",{children:o.title}),VS("div",{className:`OverwriteConfirm__Description OverwriteConfirm__Description--color-${o.color}`,children:[ya("div",{className:"OverwriteConfirm__Description__icon",children:Im}),ya("div",{children:o.description}),ya("div",{className:"OverwriteConfirm__Description__spacer"}),ya(on,{color:o.color,size:"large",label:o.actionLabel,onClick:a})]}),ya(Rx,{children:e})]})})})}),{Actions:Rx,Action:og});import U$ from"clsx";import{CANVAS_SEARCH_TAB as zx,DEFAULT_SIDEBAR as W$,LIBRARY_SIDEBAR_TAB as oM,composeEventHandlers as Y$}from"@orangecatai/common";import{round as w$}from"@orangecatai/math";import v$ from"clsx";import I$ from"lodash.debounce";import{Fragment as T$,memo as C$,useEffect as Ed,useMemo as KS,useRef as Nx,useState as XS}from"react";import{CLASSES as k$,EVENT as S$,FONT_FAMILY as Bx,FRAME_STYLE as Fx,getLineHeight as M$}from"@orangecatai/common";import{isElementCompletelyInViewport as P$}from"@orangecatai/element";import{measureText as wd}from"@orangecatai/element";import{KEYS as yl,randomInteger as ZS,addEventListener as A$,getFontString as rg}from"@orangecatai/common";import{newTextElement as L$}from"@orangecatai/element";import{isTextElement as QS,isFrameLikeElement as ag}from"@orangecatai/element";import{getDefaultFrameName as eM}from"@orangecatai/element/frame";import{Fragment as G$,jsx as Ot,jsxs as er}from"react/jsx-runtime";var _$=Pe(""),Ox=Pe(null),D$=350,tM=()=>{let e=tt(),t=Ce(),o=Nx(null),[n,r]=le(_$),a=n.trim(),[i,s]=XS(!1),[l,c]=XS({nonce:null,items:[]}),m=Nx(null),p=Nx(void 0),[d,u]=le(Ox),h=e.scene.getNonDeletedElementsMap();Ed(()=>{i||(a!==m.current||e.scene.getSceneNonce()!==p.current)&&(m.current=null,JS(a,e,(w,v)=>{c({nonce:ZS(),items:w}),m.current=a,p.current=e.scene.getSceneNonce(),t({searchMatches:w.length?{focusedId:null,matches:w.map(I=>({id:I.element.id,focus:!1,matchedLines:I.matchedLines}))}:null})}))},[i,a,h,e,t,u,p]);let g=()=>{l.items.length>0&&u(w=>w===null?0:(w+1)%l.items.length)},x=()=>{l.items.length>0&&u(w=>w===null?0:w-1<0?l.items.length-1:w-1)};Ed(()=>{t(w=>w.searchMatches?{searchMatches:{focusedId:d!==null&&w.searchMatches?.matches[d]?.id||null,matches:w.searchMatches.matches.map((I,C)=>C===d?{...I,focus:!0}:{...I,focus:!1})}}:null)},[d,t]),Ed(()=>{if(l.items.length>0&&d!==null){let w=l.items[d];if(w){let v=e.state.zoom.value,I=L$({text:w.searchQuery,x:w.element.x+(w.matchedLines[0]?.offsetX??0),y:w.element.y+(w.matchedLines[0]?.offsetY??0),width:w.matchedLines[0]?.width,height:w.matchedLines[0]?.height,fontSize:ag(w.element)?Fx.nameFontSize:w.element.fontSize,fontFamily:ag(w.element)?Bx.Assistant:w.element.fontFamily}),C=14,P=I.fontSize,S=P*v<C;if(!P$([I],e.canvas.width/window.devicePixelRatio,e.canvas.height/window.devicePixelRatio,{offsetLeft:e.state.offsetLeft,offsetTop:e.state.offsetTop,scrollX:e.state.scrollX,scrollY:e.state.scrollY,zoom:e.state.zoom},e.scene.getNonDeletedElementsMap(),e.getEditorUIOffsets())||S){let D;S?P>=C?D={fitToContent:!0}:D={fitToViewport:!0,maxZoom:w$(C/P,1)}:D={fitToContent:!0},e.scrollToContent(I,{animate:!0,duration:300,...D,canvasOffsets:e.getEditorUIOffsets()})}}}},[d,l,e]),Ed(()=>()=>{u(null),m.current=null,p.current=void 0,t({searchMatches:null}),s(!1)},[t,u]);let E=Ur({goToNextItem:g,goToPreviousItem:x,searchMatches:l});Ed(()=>{let w=v=>{if(v.key===yl.ESCAPE&&!e.state.openDialog&&!e.state.openPopup){v.preventDefault(),v.stopPropagation(),t({openSidebar:null});return}if(v[yl.CTRL_OR_CMD]&&v.key===yl.F){if(v.preventDefault(),v.stopPropagation(),e.state.openDialog)return;o.current?.matches(":focus")||(e.state.openDialog&&t({openDialog:null}),o.current?.focus(),o.current?.select())}v.target instanceof HTMLElement&&v.target.closest(".layer-ui__search")&&E.searchMatches.items.length&&(v.key===yl.ENTER&&(v.stopPropagation(),E.goToNextItem()),v.key===yl.ARROW_UP?(v.stopPropagation(),E.goToPreviousItem()):v.key===yl.ARROW_DOWN&&(v.stopPropagation(),E.goToNextItem()))};return A$(window,S$.KEYDOWN,w,{capture:!0,passive:!1})},[t,E,e]);let y=`${l.items.length} ${l.items.length===1?f("search.singleResult"):f("search.multipleResults")}`;return er("div",{className:"layer-ui__search",children:[Ot("div",{className:"layer-ui__search-header",children:Ot(ia,{className:k$.SEARCH_MENU_INPUT_WRAPPER,value:n,ref:o,placeholder:f("search.placeholder"),icon:Mo,onChange:w=>{r(w),s(!0);let v=w.trim();JS(v,e,(I,C)=>{c({nonce:ZS(),items:I}),u(C),m.current=v,p.current=e.scene.getSceneNonce(),t({searchMatches:I.length?{focusedId:null,matches:I.map(P=>({id:P.element.id,focus:!1,matchedLines:P.matchedLines}))}:null}),s(!1)})},selectOnRender:!0})}),er("div",{className:"layer-ui__search-count",children:[l.items.length>0&&er(G$,{children:[d!==null&&d>-1?er("div",{children:[d+1," / ",y]}):Ot("div",{children:y}),er("div",{className:"result-nav",children:[Ot(so,{onSelect:()=>{g()},className:"result-nav-btn",children:Tm}),Ot(so,{onSelect:()=>{x()},className:"result-nav-btn",children:pv})]})]}),l.items.length===0&&a&&m.current&&Ot("div",{style:{margin:"1rem auto"},children:f("search.noMatch")})]}),Ot(B$,{matches:l,onItemClick:u,focusIndex:d,searchQuery:a})]})},jS=e=>{let t=[e.preview.moreBefore?"...":"",e.preview.previewText.slice(0,e.preview.indexInSearchQuery),e.preview.previewText.slice(e.preview.indexInSearchQuery,e.preview.indexInSearchQuery+e.searchQuery.length),e.preview.previewText.slice(e.preview.indexInSearchQuery+e.searchQuery.length),e.preview.moreAfter?"...":""];return Ot("div",{tabIndex:-1,className:v$("layer-ui__result-item",{active:e.highlighted}),onClick:e.onClick,ref:o=>{e.highlighted&&o?.scrollIntoView({behavior:"auto",block:"nearest"})},children:Ot("div",{className:"preview-text",children:t.flatMap((o,n)=>Ot(T$,{children:n===2?Ot("b",{children:o}):o},n))})})},R$=e=>{let t=KS(()=>e.matches.items.filter(n=>ag(n.element)),[e.matches]),o=KS(()=>e.matches.items.filter(n=>QS(n.element)),[e.matches]);return er("div",{children:[t.length>0&&er("div",{className:"layer-ui__search-result-container",children:[er("div",{className:"layer-ui__search-result-title",children:[Ot("div",{className:"title-icon",children:On}),Ot("div",{children:f("search.frames")})]}),t.map((n,r)=>Ot(jS,{searchQuery:e.searchQuery,preview:n.preview,highlighted:r===e.focusIndex,onClick:()=>e.onItemClick(r)},n.element.id+n.index)),o.length>0&&Ot("div",{className:"layer-ui__divider"})]}),o.length>0&&er("div",{className:"layer-ui__search-result-container",children:[er("div",{className:"layer-ui__search-result-title",children:[Ot("div",{className:"title-icon",children:Fn}),Ot("div",{children:f("search.texts")})]}),o.map((n,r)=>Ot(jS,{searchQuery:e.searchQuery,preview:n.preview,highlighted:r+t.length===e.focusIndex,onClick:()=>e.onItemClick(r+t.length)},n.element.id+n.index))]})]})},N$=(e,t)=>e.matches.nonce===t.matches.nonce&&e.focusIndex===t.focusIndex,B$=C$(R$,N$),qS=(e,t,o)=>{let a=e.slice(0,t),i=a.split(/\s+/),s=a.endsWith(" "),l=i.length-2-1-(s?0:1),c=i.slice(l<=0?0:l).join(" ")+(s?" ":""),m=20;c=c.length>m?c.slice(-m):c;let p=e.slice(t+o.length),d=p.split(/\s+/),u=!p.startsWith(" "),h=u?6:5,g=(u?"":" ")+d.slice(0,h).join(" ");return{indexInSearchQuery:c.length,previewText:c+o+g,moreBefore:l>0,moreAfter:d.length>h}},F$=(e,t)=>{let o=e.split(`
|
|
200
|
+
Return ONLY the raw HTML. No markdown, no code fences, no explanation.`,imagePlaceholders:c}}async function HG(e,t,o,n){let r=await fetch("https://openrouter.ai/api/v1/chat/completions",{method:"POST",signal:n,headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json"},body:JSON.stringify({model:o,messages:[{role:"user",content:e}],stream:!1,temperature:.3})});if(!r.ok){let l=`OpenRouter API error ${r.status}`;try{let c=await r.json();c?.error?.message&&(l=c.error.message)}catch{}throw new Error(l)}return((await r.json())?.choices?.[0]?.message?.content??"").replace(/^```(?:html)?\s*/i,"").replace(/\s*```\s*$/i,"").trim()}function GG(e,t){let o=e.findIndex(r=>r.id===t);if(o<0)return e.length;let n=o+1;for(let r=o+1;r<e.length;r++)e[r].frameId===t&&(n=r+1);return n}async function UG(e){let{info:t,targetWidth:o,targetHeight:n,placementX:r,placementY:a,app:i,geminiApiKey:s,openRouterApiKey:l,chatModel:c,agentImageModel:m,customFontMap:p={},onProgress:d,signal:u,debugLabel:h=`${o}\xD7${n}`,existingFrameId:g}=e,x=t.frame,E;if(g)E=g;else{let I=Bk({...Fk,x:r,y:a,width:o,height:n,opacity:100,locked:!1,name:`${o}\xD7${n}`}),P=[...i.getSceneElements(),I];Au(P,Lu([I])),i.updateScene({elements:P}),E=I.id}let y=null;if(t.background.type==="image"){let I=t.background.dataUrl,C=_G(x.width,x.height,o,n);if(wt(`[AutoResize] ${h} \u2014 background: needsRegen=${C}`),C){d?.("Regenerating background image\u2026");let P=DG(o,n);wt(`[AutoResize] ${h} \u2014 calling Gemini for background regen (ar=${P})`),y=await yi(`You are given an input background image. Preserve the original scene identity, composition, color palette, and style. Outpaint only beyond the existing edges so the final image fits aspect ratio ${P}. Keep the center subject and key content unchanged. Ensure all surfaces extend with natural, seamless continuity \u2014 no visible seams, repeated patterns, or tiling artifacts. For areas far from the center, gradually soften into ambient bokeh rather than extending sharp textures. Do not add text, logos, watermarks, UI, symbols, or new unrelated objects. Avoid altering brand-relevant details.`,m||TG,P,"1K",!1,!1,s,I,u)}else y=I}if(y){d?.("Placing background\u2026");let{width:I,height:C}=await Rk(y),{relX:P,relY:S,width:D,height:_}=RG(I,C,o,n),k=Lk(),M=Dk({type:"image",x:r+P,y:a+S,width:D,height:_,fileId:k,status:"pending",scale:[1,1],customData:{autoResizeBg:!0}}),B=i.getSceneElements(),O=GG(B,E),N=[...B.slice(0,O),{...M,frameId:E},...B.slice(O)];Au(N,Lu([M])),i.updateScene({elements:N}),i.addFiles([{id:k,dataURL:y,mimeType:So(y),created:Date.now(),lastRetrieved:Date.now()}])}d?.("Generating layout\u2026");let w=0,v;for(;;){wt(`[AutoResize] ${h} \u2014 calling OpenRouter for HTML layout (model=${c}, round=${w+1})`);let{prompt:I,imagePlaceholders:C}=zG(t,o,n,v),P=await HG(I,l,c,u);if(!P||P.length<20)throw new Error("LLM returned empty HTML");wt(`[AutoResize] ${h} \u2014 HTML received (${P.length} chars), substituting ${C.size} image placeholder(s)\u2026`);for(let[U,q]of C)P=P.split(`url(${U})`).join(`url(${q})`);d?.("Parsing layout\u2026");let S;try{S=await Su(P,r,a,o,n,p)}catch(U){throw new Error(`HTML parse failed: ${U instanceof Error?U.message:String(U)}`)}if(!S||S.length===0)throw new Error("HTML parser produced no elements");d?.("Inserting elements\u2026");let D=[],_=[];for(let U of S)if(U.kind==="rectangle"){let q=_k({type:"rectangle",x:U.x,y:U.y,width:U.width,height:U.height,backgroundColor:U.backgroundColor,fillStyle:"solid",strokeColor:U.strokeColor,strokeWidth:U.strokeWidth,opacity:U.opacity,roughness:0,...U.borderRadius>0?{roundness:{type:3,value:U.borderRadius}}:{},customData:{generatedByHtml:!0}});D.push({...q,frameId:E})}else if(U.kind==="ellipse"){let q=_k({type:"ellipse",x:U.x,y:U.y,width:U.width,height:U.height,backgroundColor:U.backgroundColor,fillStyle:"solid",strokeColor:U.strokeColor,strokeWidth:U.strokeWidth,opacity:U.opacity,roughness:0,customData:{generatedByHtml:!0}});D.push({...q,frameId:E})}else if(U.kind==="text"){let q=vG({x:U.x,y:U.y,text:U.text,fontSize:U.fontSize,fontFamily:U.fontFamily,strokeColor:U.color,textAlign:U.textAlign,width:U.width,opacity:U.opacity,roughness:0,customData:{generatedByHtml:!0}});D.push({...q,frameId:E})}else if(U.kind==="image"){let q=Lk(),{width:ae,height:J}=await Rk(U.dataUrl),{relX:te,relY:ue,width:Me,height:ct}=NG(ae,J,U.width,U.height),Lt=Dk({type:"image",x:U.x+te,y:U.y+ue,width:Me,height:ct,fileId:q,status:"pending",scale:[1,1],customData:{generatedByHtml:!0}});D.push({...Lt,frameId:E}),_.push({id:q,dataURL:U.dataUrl,mimeType:So(U.dataUrl),created:Date.now(),lastRetrieved:Date.now()})}if(w>0){let q=i.getSceneElements().filter(ae=>{let J=ae;return!(J.frameId===E&&J.customData?.generatedByHtml)});i.updateScene({elements:q})}let k=o*n,M=[],B=[];for(let U of D)U.type==="rectangle"&&U.width*U.height>=k*.25?M.push(U):B.push(U);let O=i.getSceneElements(),N=O.findIndex(U=>U.id===E),z=V0(O,E),L=z.length>0?O.findIndex(U=>U.id===z[0].id):N+1,F=z.length>0?O.findIndex(U=>U.id===z[z.length-1].id)+1:N+1,$=[...O.slice(0,L),...M,...O.slice(L,F),...B,...O.slice(F)],Q=[...M,...B];if(Au($,Lu(Q)),i.updateScene({elements:$}),_.length>0&&i.addFiles(_),wt(`[AutoResize] ${h} \u2014 inserted ${D.length} elements (${M.length} bg, ${B.length} fg)`),w>=CG){wt(`[AutoResize] ${h} \u2014 reviewer cap reached, finalising`);break}let Z=await Ok(i,E);if(!Z){wt(`[AutoResize] ${h} \u2014 screenshot unavailable, skipping reviewer`);break}d?.("Reviewing layout\u2026");try{let U=await Mu({screenshotDataUrl:Z,htmlSource:P,frame:{id:E,width:o,height:n},userBrief:`Auto-resize ad from ${Math.round(x.width)}\xD7${Math.round(x.height)} to ${o}\xD7${n}`,apiKey:l,reviewerModel:c,signal:u,iteration:w+1});if(w++,U.approved){wt(`[AutoResize] ${h} \u2014 reviewer approved (round ${w})`);break}wt(`[AutoResize] ${h} \u2014 reviewer found ${U.issues.length} issue(s), regenerating\u2026`),v=U,d?.("Refining layout\u2026")}catch{wt(`[AutoResize] ${h} \u2014 reviewer error, accepting output`);break}}return{frameId:E}}function zk(e,t,o){let n=t.x+t.width+80,r=e.map((l,c)=>{let m=e.slice(0,c).reduce((d,u)=>d+u.height+40,t.y);return{frame:Bk({...Fk,x:n,y:m,width:l.width,height:l.height,opacity:100,locked:!1,name:l.label??`${l.width}\xD7${l.height}`}),x:n,y:m,width:l.width,height:l.height}}),a=o.getSceneElements(),i=r.map(l=>l.frame),s=[...a,...i];return Au(s,Lu(i)),o.updateScene({elements:s}),r.map(l=>({frameId:l.frame.id,x:l.x,y:l.y,width:l.width,height:l.height}))}async function Hk(e){let{sourceFrameId:t,targetDimensions:o,app:n,geminiApiKey:r,openRouterApiKey:a,chatModel:i="google/gemini-3.1-flash-lite-preview",agentImageModel:s,customFontMap:l={},onBeforeAutoResize:c,onAfterAutoResize:m,onProgress:p,signal:d,preCreatedFrameInfos:u}=e,h=new Array(o.length),g=n.getSceneElements(),x=g.find(P=>P.id===t);if(!x)return o.map(()=>({status:"error",error:"Source frame not found"}));let E=AG(g,x,n.files),y=await Ok(n,t);y&&await OG(E,y,a,i,d);let w=x.x+x.width+80,v=u??o.map((P,S)=>({x:w,y:o.slice(0,S).reduce((D,_)=>D+_.height+40,x.y)})),I=3,C=o.length;wt(`[AutoResize] Starting ${C} dimension(s), batch size ${I}`);for(let P=0;P<C;P+=I){let S=Math.min(P+I,C),D=Math.floor(P/I)+1;wt(`[AutoResize] Batch ${D}: dimensions ${P+1}\u2013${S} of ${C}`),await Promise.allSettled(o.slice(P,S).map(async(_,k)=>{let M=P+k,B=_.label??`${_.width}\xD7${_.height}`,O=`[${M+1}/${C}] ${B}`;if(c){wt(`[AutoResize] ${O} \u2014 checking credits`);let{allowed:N,error:z}=await c();if(!N){h[M]={status:"error",error:z??"Not allowed"},p?.(M,C,"error",B),wt(`[AutoResize] ${O} \u2014 credits denied: ${z}`);return}wt(`[AutoResize] ${O} \u2014 credits OK`)}p?.(M,C,"bg-regen",B),wt(`[AutoResize] ${O} \u2014 starting AI at (${v[M].x}, ${v[M].y})`);try{let{frameId:N}=await UG({info:E,targetWidth:_.width,targetHeight:_.height,placementX:v[M].x,placementY:v[M].y,existingFrameId:u?.[M]?.frameId,app:n,geminiApiKey:r,openRouterApiKey:a,chatModel:i,agentImageModel:s,customFontMap:l,debugLabel:O,onProgress:z=>{p?.(M,C,"layout",`${B}: ${z}`)},signal:d});h[M]={status:"ok",frameId:N},p?.(M,C,"done",B),m?.(),wt(`[AutoResize] ${O} \u2014 DONE`)}catch(N){let z=N instanceof Error?N.message:String(N);h[M]={status:"error",error:z},p?.(M,C,"error",`${B}: ${z}`),wt(`[AutoResize] ${O} \u2014 ERROR: ${z}`)}})),wt(`[AutoResize] Batch ${D} complete`)}return h}import{Fragment as Z0,jsx as ge,jsxs as yo}from"react/jsx-runtime";var Gk=[{label:"1200\xD7628",width:1200,height:628,desc:"Facebook / OG"},{label:"1080\xD71080",width:1080,height:1080,desc:"Square"},{label:"1080\xD71920",width:1080,height:1920,desc:"Story 9:16"},{label:"728\xD790",width:728,height:90,desc:"Leaderboard"},{label:"320\xD750",width:320,height:50,desc:"Mobile Banner"},{label:"300\xD7600",width:300,height:600,desc:"Half Page"},{label:"300\xD7250",width:300,height:250,desc:"Medium Rect"},{label:"160\xD7600",width:160,height:600,desc:"Wide Skyscraper"}],$G=()=>yo("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",children:[ge("rect",{x:"1.5",y:"1.5",width:"7",height:"7",rx:"1",stroke:"currentColor",strokeWidth:"1.4"}),ge("rect",{x:"7.5",y:"7.5",width:"7",height:"7",rx:"1",stroke:"currentColor",strokeWidth:"1.4",strokeDasharray:"2 1",opacity:"0.6"}),ge("path",{d:"M9.5 6.5L13.5 6.5M13.5 6.5L13.5 2.5M13.5 2.5L9.5 2.5",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round"})]}),VG=()=>ge("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",children:ge("path",{d:"M1.5 1.5L10.5 10.5M10.5 1.5L1.5 10.5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})}),X0=()=>ge("svg",{width:"11",height:"11",viewBox:"0 0 12 12",fill:"none",children:ge("path",{d:"M2 6.5L4.5 9L10 3",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round"})}),Uk=()=>ge("svg",{className:"arp-spinner",width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",children:ge("circle",{cx:"7",cy:"7",r:"5.5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeDasharray:"20 14"})}),Wk=()=>yo("svg",{width:"11",height:"11",viewBox:"0 0 12 12",fill:"none",children:[ge("circle",{cx:"6",cy:"6",r:"4.5",stroke:"currentColor",strokeWidth:"1.3"}),ge("path",{d:"M6 3.5V6.5",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"}),ge("circle",{cx:"6",cy:"8.5",r:"0.65",fill:"currentColor"})]}),KG=({onAdd:e})=>{let[t,o]=Ei(""),[n,r]=Ei("");return yo("div",{className:"arp-custom-row",children:[ge("input",{className:"arp-custom-input",type:"number",placeholder:"W",value:t,min:1,onChange:i=>o(i.target.value),onPointerDown:i=>i.stopPropagation()}),ge("span",{className:"arp-custom-x",children:"\xD7"}),ge("input",{className:"arp-custom-input",type:"number",placeholder:"H",value:n,min:1,onChange:i=>r(i.target.value),onPointerDown:i=>i.stopPropagation()}),ge("button",{className:"arp-custom-add",onClick:()=>{let i=parseInt(t,10),s=parseInt(n,10);i>0&&s>0&&(e({width:i,height:s,label:`${i}\xD7${s}`}),o(""),r(""))},disabled:!t||!n,title:"Add custom dimension",children:"+ Add"})]})},Yk=({element:e,app:t,onClose:o,onBeforeAutoResize:n,onAfterAutoResize:r,onRunningChange:a,openRouterApiKey:i,chatModel:s,agentImageModel:l})=>{let[c,m]=Ei(new Set),[p,d]=Ei([]),[u,h]=Ei(!1),[g,x]=Ei({}),[E,y]=Ei(null),w=YG(null),v=[...Gk.filter(N=>c.has(N.label)).map(N=>({width:N.width,height:N.height,label:N.label})),...p],I=N=>{m(z=>{let L=new Set(z);return L.has(N)?L.delete(N):L.add(N),L})},C=N=>{let z=N.label;c.has(z)||(d(L=>[...L,N]),m(L=>new Set([...L,z])))},P=N=>{d(z=>z.filter(L=>L.label!==N)),m(z=>{let L=new Set(z);return L.delete(N),L})},S=K0((N,z)=>{x(L=>({...L,[N]:{...L[N],...z}}))},[]),D=K0(()=>{Sr.clear()},[]);WG(()=>()=>{w.current?.abort(),Sr.clear()},[]);let _=K0(async()=>{if(v.length===0)return;h(!0),a?.(!0),y(null);let N={};v.forEach(q=>{N[q.label]={status:"waiting"}}),x(N);let z=new AbortController;w.current=z;let L=dl(t.props.geminiApiKey),F={},$=t.state.brandContext;if($?.typography){let{headline:q,body:ae}=$.typography;q?.family&&q?.fontFamilyId&&(F[q.family.toLowerCase().trim()]=q.fontFamilyId),ae?.family&&ae?.fontFamilyId&&(F[ae.family.toLowerCase().trim()]=ae.fontFamilyId)}let Z=t.getSceneElements().find(q=>q.id===e.id),U=[];Z&&(U=zk(v,Z,t)),U.length>0&&Sr.setLoadingFrames(U);try{await Hk({sourceFrameId:e.id,targetDimensions:v,preCreatedFrameInfos:U.length>0?U:void 0,app:t,geminiApiKey:L,openRouterApiKey:i,chatModel:s,agentImageModel:l,customFontMap:F,onBeforeAutoResize:n,onAfterAutoResize:r,onProgress:(q,ae,J,te)=>{let ue=v[q]?.label??te;J==="done"?(S(ue,{status:"done"}),U[q]&&Sr.markComplete(U[q].frameId)):J==="error"?(S(ue,{status:"error",error:te}),U[q]&&Sr.markComplete(U[q].frameId)):J==="bg-regen"?S(ue,{status:"bg-regen"}):S(ue,{status:"layout"})},signal:z.signal})}catch(q){q instanceof DOMException&&q.name==="AbortError"||z.signal.aborted||y(q instanceof Error?q.message:"An unexpected error occurred")}finally{h(!1),a?.(!1),w.current=null,D()}},[v,t,e.id,S,D,n,r,i,s,l]),k=()=>{w.current?.abort(),h(!1),a?.(!1),D()},M=Object.values(g).filter(N=>N.status==="done").length,B=v.length,O=M>0;return ge(Z0,{children:yo("div",{className:"arp",onPointerDown:N=>N.stopPropagation(),onClick:N=>N.stopPropagation(),children:[yo("div",{className:"arp-header",children:[yo("span",{className:"arp-header__title",children:[ge($G,{}),"Auto Resize"]}),ge("button",{className:"arp-header__close",onClick:()=>{u?window.confirm("This will cancel the generation. Are you sure?")&&(k(),o()):o()},title:"Close",children:ge(VG,{})})]}),yo("div",{className:"arp-source",children:["Source: ",Math.round(e.width),"\xD7",Math.round(e.height)]}),ge("div",{className:"arp-section-label",children:"Target dimensions"}),ge("div",{className:"arp-presets",children:Gk.map(N=>{let z=c.has(N.label),L=g[N.label];return yo("button",{className:`arp-preset ${z?"arp-preset--selected":""} ${u?"arp-preset--disabled":""}`,onClick:()=>!u&&I(N.label),title:N.desc,children:[ge("span",{className:"arp-preset__check",children:z&&ge(X0,{})}),ge("span",{className:"arp-preset__label",children:N.label}),ge("span",{className:"arp-preset__desc",children:N.desc}),L&&yo("span",{className:"arp-preset__status",children:[L.status==="waiting"&&ge("span",{className:"arp-status arp-status--waiting",children:"\u2026"}),(L.status==="bg-regen"||L.status==="layout"||L.status==="inserting")&&ge("span",{className:"arp-status arp-status--running",children:ge(Uk,{})}),L.status==="done"&&ge("span",{className:"arp-status arp-status--done",children:ge(X0,{})}),L.status==="error"&&ge("span",{className:"arp-status arp-status--error",title:L.error,children:ge(Wk,{})})]})]},N.label)})}),p.length>0&&ge("div",{className:"arp-extras",children:p.map(N=>{let z=g[N.label];return yo("div",{className:"arp-extra-tag",children:[ge("span",{children:N.label}),z?.status==="done"&&ge("span",{className:"arp-status arp-status--done",children:ge(X0,{})}),z?.status==="error"&&ge("span",{className:"arp-status arp-status--error",title:z.error,children:ge(Wk,{})}),(z?.status==="bg-regen"||z?.status==="layout")&&ge("span",{className:"arp-status arp-status--running",children:ge(Uk,{})}),!u&&ge("button",{className:"arp-extra-tag__remove",onClick:()=>P(N.label),children:"\xD7"})]},N.label)})}),!u&&yo(Z0,{children:[ge("div",{className:"arp-section-label",children:"Custom size"}),ge(KG,{onAdd:C})]}),E&&ge("div",{className:"arp-error",children:E}),u&&B>0&&yo("div",{className:"arp-progress",children:[ge("div",{className:"arp-progress__bar-bg",children:ge("div",{className:"arp-progress__bar-fill",style:{width:`${M/B*100}%`}})}),yo("span",{className:"arp-progress__text",children:[M,"/",B," done"]})]}),ge("div",{className:"arp-actions",children:u?ge("button",{className:"arp-btn arp-btn--cancel",onClick:k,children:"Cancel"}):O?yo(Z0,{children:[ge("button",{className:"arp-btn arp-btn--primary",onClick:_,disabled:v.length===0,children:"Generate more"}),ge("button",{className:"arp-btn arp-btn--ghost",onClick:o,children:"Done"})]}):ge("button",{className:"arp-btn arp-btn--primary",onClick:_,disabled:v.length===0,children:v.length===0?"Select sizes above":`Generate ${v.length} size${v.length!==1?"s":""}`})})]})})};import{jsx as Vk}from"react/jsx-runtime";var Kk=({app:e})=>{let[t,o]=ZG(En.getState()),n=XG(null);if($k(()=>En.subscribe(o),[]),$k(()=>{if(!t.isOpen)return;let d=u=>{t.isRunning||n.current&&!n.current.contains(u.target)&&En.close()};return document.addEventListener("mousedown",d),()=>document.removeEventListener("mousedown",d)},[t.isOpen,t.isRunning]),!t.isOpen||!t.element)return null;let r=t.element,a=e.state,[i,s]=qG(r,e.scene.getNonDeletedElementsMap()),{x:l,y:c}=jG({sceneX:i+r.width/2,sceneY:s},a),m=l-a.offsetLeft,p=Math.max(c-a.offsetTop-82,8);return Vk("div",{ref:n,style:{position:"absolute",left:`${m}px`,top:`${p}px`,transform:"translateX(-50%)",zIndex:"var(--zIndex-canvasButtons)",pointerEvents:"all"},children:Vk(Yk,{element:r,app:e,onClose:()=>En.close(),onRunningChange:d=>En.setRunning(d),onBeforeAutoResize:e.props.onBeforeAutoResize,onAfterAutoResize:e.props.onAfterAutoResize,openRouterApiKey:ld(e.props.openRouterApiKey),chatModel:e.props.chatModel??"google/gemini-3.1-flash-lite-preview",agentImageModel:e.props.agentImageModel})})};import{useEffect as oU,useState as nU}from"react";import{isFrameLikeElement as Jk,getFrameChildren as Qk}from"@orangecatai/element";import{newElement as Zk,newTextElement as JG,isFrameLikeElement as QG,syncMovedIndices as eU}from"@orangecatai/element";import{arrayToMap as tU}from"@orangecatai/common";var Xk=[{id:"background",label:"Background",color:"#94a3b8",kind:"rect"},{id:"logo",label:"Logo",color:"#f97316",kind:"image"},{id:"product_image",label:"Product Image",color:"#22c55e",kind:"image"},{id:"headline",label:"Headline",color:"#3b82f6",kind:"text"},{id:"subhead",label:"Subhead",color:"#8b5cf6",kind:"text"},{id:"cta",label:"CTA",color:"#ef4444",kind:"text"},{id:"signoff",label:"Signoff",color:"#64748b",kind:"text"},{id:"auxiliary_image",label:"Aux Image",color:"#14b8a6",kind:"image"}];import{jsx as j0,jsxs as jk}from"react/jsx-runtime";var qk=({app:e})=>{let t=o=>{let n=e.state.selectedElementIds,a=e.getSceneElements().find(c=>n[c.id]&&QG(c)&&!c.isDeleted);if(!a){alert("Please select a frame first.");return}let i;o.kind==="rect"?i={...Zk({type:"rectangle",x:a.x+a.width*.1,y:a.y+a.height*.1,width:a.width*.8,height:a.height*.8,backgroundColor:o.color,fillStyle:"solid",strokeColor:"transparent",opacity:60}),frameId:a.id,customData:{slotType:o.id,isSlot:!0}}:o.kind==="text"?i={...JG({text:o.label,x:a.x+a.width*.1,y:a.y+a.height*.3,fontSize:32,strokeColor:o.color}),frameId:a.id,customData:{slotType:o.id,isSlot:!0}}:i={...Zk({type:"rectangle",x:a.x+a.width*.1,y:a.y+a.height*.1,width:a.width*.8,height:a.height*.8,backgroundColor:o.color,fillStyle:"solid",strokeColor:o.color,opacity:40}),frameId:a.id,customData:{slotType:o.id,isSlot:!0}};let l=[...e.getSceneElements(),i];eU(l,tU([i])),e.updateScene({elements:l})};return jk("div",{style:{background:"var(--popup-bg-color, #1e1e2e)",border:"1px solid var(--default-border-color, #333)",borderRadius:8,padding:12,width:240},children:[j0("div",{style:{fontSize:11,fontWeight:600,color:"var(--text-secondary-color, #888)",textTransform:"uppercase",letterSpacing:"0.5px",marginBottom:8},children:"Slot Blocks"}),j0("div",{children:Xk.map(o=>jk("button",{onClick:()=>t(o),style:{display:"flex",alignItems:"center",gap:8,padding:"6px 10px",borderRadius:6,cursor:"pointer",background:"rgba(255,255,255,0.05)",border:"1px solid rgba(255,255,255,0.1)",color:"var(--text-primary-color, #fff)",fontSize:12,margin:"3px 0",width:"100%",textAlign:"left"},children:[j0("span",{style:{width:8,height:8,borderRadius:2,background:o.color,flexShrink:0,display:"inline-block"}}),o.label]},o.id))})]})};import{jsx as jn,jsxs as md}from"react/jsx-runtime";var e3=({app:e})=>{let[t,o]=nU(Ro.getState());if(oU(()=>Ro.subscribe(o),[]),!t.isOpen)return null;let n=()=>{let r=e.props.onSaveTemplate;if(!r)return;let a=e.getSceneElements(),i=[];if(t.sourceFrameId){let p=a.find(d=>!d.isDeleted&&d.id===t.sourceFrameId&&Jk(d));p&&(i=[p])}if(i.length===0&&(i=a.filter(p=>p.isDeleted||!Jk(p)?!1:Qk(a,p.id).some(u=>u.customData?.isSlot===!0))),i.length===0){alert("No frame found to save. Please select a frame on the canvas first.");return}let s=i[0],l=Qk(a,s.id),c=e.files,m={};for(let p of l){let d=p;if(p.type==="image"&&d.fileId){let u=c[d.fileId];u?.dataURL&&(m[d.fileId]={dataURL:u.dataURL,mimeType:u.mimeType})}}r({name:t.templateName,campaignTag:t.campaignTag||void 0,label:`${Math.round(s.width)}x${Math.round(s.height)}`,width:Math.round(s.width),height:Math.round(s.height),canvasJson:JSON.stringify({frame:{...s},elements:l,...Object.keys(m).length>0?{files:m}:{}})}),Ro.close()};return jn("div",{style:{position:"fixed",right:20,bottom:20,zIndex:9999,pointerEvents:"all",display:"flex",flexDirection:"column",gap:8},onPointerDown:r=>r.stopPropagation(),onClick:r=>r.stopPropagation(),children:md("div",{style:{background:"var(--popup-bg-color, #1e1e2e)",border:"1px solid var(--default-border-color, #333)",borderRadius:8,padding:12,width:264,display:"flex",flexDirection:"column",gap:10},children:[md("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[jn("span",{style:{fontSize:13,fontWeight:600,color:"var(--text-primary-color, #fff)"},children:"Template Builder"}),jn("button",{onClick:()=>Ro.close(),style:{background:"none",border:"none",cursor:"pointer",color:"var(--text-secondary-color, #888)",fontSize:16,padding:"0 2px",lineHeight:1},title:"Close Template Builder",children:"\xD7"})]}),md("div",{style:{display:"flex",flexDirection:"column",gap:4},children:[jn("label",{style:{fontSize:11,color:"var(--text-secondary-color, #888)",fontWeight:500},children:"Template Name"}),jn("input",{type:"text",value:t.templateName,onChange:r=>Ro.setName(r.target.value),placeholder:"e.g. Summer Campaign",style:{background:"rgba(255,255,255,0.06)",border:"1px solid var(--default-border-color, #444)",borderRadius:5,color:"var(--text-primary-color, #fff)",fontSize:12,padding:"5px 8px",outline:"none",width:"100%",boxSizing:"border-box"}})]}),md("div",{style:{display:"flex",flexDirection:"column",gap:4},children:[jn("label",{style:{fontSize:11,color:"var(--text-secondary-color, #888)",fontWeight:500},children:"Campaign Tag (optional)"}),jn("input",{type:"text",value:t.campaignTag,onChange:r=>Ro.setCampaignTag(r.target.value),placeholder:"e.g. summer_2026",style:{background:"rgba(255,255,255,0.06)",border:"1px solid var(--default-border-color, #444)",borderRadius:5,color:"var(--text-primary-color, #fff)",fontSize:12,padding:"5px 8px",outline:"none",width:"100%",boxSizing:"border-box"}})]}),jn(qk,{app:e}),md("div",{style:{display:"flex",gap:6,marginTop:4},children:[jn("button",{onClick:n,disabled:!t.templateName.trim(),style:{flex:1,background:"#3b82f6",border:"none",borderRadius:6,color:"#fff",cursor:t.templateName.trim()?"pointer":"not-allowed",fontSize:12,fontWeight:600,padding:"7px 12px",opacity:t.templateName.trim()?1:.5},children:"Save Template"}),jn("button",{onClick:()=>Ro.close(),style:{background:"rgba(255,255,255,0.08)",border:"1px solid var(--default-border-color, #444)",borderRadius:6,color:"var(--text-primary-color, #fff)",cursor:"pointer",fontSize:12,padding:"7px 12px"},children:"Close"})]})]})})};import{useCallback as Ru,useState as ex}from"react";import{sceneCoordsToViewportCoords as pU}from"@orangecatai/common";import{getElementAbsoluteCoords as uU}from"@orangecatai/element";function t3(e){let t=e?.trim();return(t||void 0)??(typeof import.meta<"u"&&T?.VITE_APP_LEONARDO_API_KEY?T.VITE_APP_LEONARDO_API_KEY:"")??""}function o3(e){let t=e?.trim();return(t||void 0)??(typeof import.meta<"u"&&T?.VITE_APP_REMOVE_BG_API_KEY?T.VITE_APP_REMOVE_BG_API_KEY:"")??""}import{useCallback as _u,useEffect as q0,useRef as Du,useState as qn}from"react";import{sceneCoordsToViewportCoords as n3}from"@orangecatai/common";import{getElementAbsoluteCoords as rU}from"@orangecatai/element";import{ArrowUp as aU}from"lucide-react";import{Fragment as mU,jsx as ve,jsxs as Ft}from"react/jsx-runtime";var J0=()=>ve("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",children:ve("path",{d:"M2.5 3.75L5 6.25L7.5 3.75",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),Q0=()=>ve("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",children:ve("path",{d:"M2.5 7.5L5.5 10.5L11.5 3.5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),iU=()=>ve("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:ve("path",{d:"M8 2L10.5 5.5H13.5L11.5 8L13 11.5L8 9.5L3 11.5L4.5 8L2.5 5.5H5.5L8 2Z",stroke:"currentColor",strokeWidth:"1.3",strokeLinejoin:"round"})}),sU=()=>Ft("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",children:[ve("circle",{cx:"7",cy:"7",r:"5.5",stroke:"currentColor",strokeWidth:"1.2"}),ve("path",{d:"M7 6.5V10",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round"}),ve("circle",{cx:"7",cy:"4.5",r:"0.75",fill:"currentColor"})]}),lU=()=>ve("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",className:"igp-spinner",children:ve("circle",{cx:"7",cy:"7",r:"5.5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeDasharray:"20 14"})}),cU=()=>ve("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",children:ve("path",{d:"M7 1.5L8.5 5.5H12.5L9.5 8L10.5 12L7 9.5L3.5 12L4.5 8L1.5 5.5H5.5L7 1.5Z",fill:"currentColor"})}),dU=({label:e})=>{let t={border:"1.5px solid currentColor",borderRadius:2,boxSizing:"border-box",display:"inline-block",flexShrink:0},n={"21:9":{width:21,height:9},"16:9":{width:18,height:10},"4:3":{width:16,height:12},"3:2":{width:15,height:10},"1:1":{width:13,height:13},"9:16":{width:10,height:18},"3:4":{width:12,height:16},"2:3":{width:10,height:15},"5:4":{width:15,height:12},"4:5":{width:12,height:15},"4:1":{width:24,height:6},"1:4":{width:6,height:24},"8:1":{width:24,height:3},"1:8":{width:3,height:24}}[e]??{width:13,height:13};return ve("div",{style:{...t,...n}})},r3=({element:e,app:t,onBeforeImageGen:o,onAfterImageGen:n,forceOpen:r,onClose:a})=>{let i=t.state,s=dl(t.props.geminiApiKey),[l,c]=qn(()=>r||hi(e.id)),m=_u(()=>{c(!1),a?.()},[a]),[p,d]=qn(()=>Iu(e.id)),[u,h]=qn(()=>pa(e.id)?.model??"Gemini 3.1 Flash"),g=ga[u],x=g.supportedRatios,E=g.supportedResolutions,y=x.includes("1:1")?"1:1":x[0],w=E.includes("2K")?"2K":E[E.length-1],[v,I]=qn(()=>pa(e.id)?.ratio??y),[C,P]=qn(()=>pa(e.id)?.resolution??w);q0(()=>{let Y=ga[u],ne=Y.supportedRatios;ne.includes(v)||I(ne.includes("1:1")?"1:1":ne[0]);let ft=Y.supportedResolutions;ft.includes(C)||P(ft.includes("2K")?"2K":ft[ft.length-1])},[u]);let[S,D]=qn(()=>hi(e.id)),[_,k]=qn(null),[M,B]=qn(!1),[O,N]=qn(!1),[z,L]=qn(!1),F=Du(null),$=Du(null),Q=Du(null),Z=Du(null),U=_u(Y=>{I(Y),B(!1)},[]);q0(()=>{let Y=ne=>{D(!1),ne?ne!=="aborted"&&k(ne):(m(),d(""))};return yu(e.id,Y),()=>Eu(e.id,Y)},[e.id]),q0(()=>{let Y=ne=>{F.current&&!F.current.contains(ne.target)&&B(!1),$.current&&!$.current.contains(ne.target)&&N(!1),Q.current&&!Q.current.contains(ne.target)&&L(!1)};return document.addEventListener("mousedown",Y),()=>document.removeEventListener("mousedown",Y)},[]);let q=_u(()=>{vu(e.id)},[e.id]),ae=_u(async()=>{if(!p.trim()){k("Please enter a prompt.");return}if(!s){k("No Gemini API key found. Set VITE_APP_GEMINI_API_KEY in .env or pass geminiApiKey as a prop.");return}if(o)try{let{allowed:De,error:ft}=await o();if(!De){k(ft||"Insufficient credits for image generation");return}}catch{k("Credit check failed");return}let Y=new AbortController;Z.current=Y,bu(e.id,p,{model:u,ratio:v,resolution:C},Y),D(!0),k(null);let ne=null;try{let De=ga[u],ft=e.fileId?t.files[e.fileId]?.dataURL:void 0,$t=await yi(p,De.geminiModelId,v,C,De.supportsImageSize,De.supportsThinking,s,ft,Y.signal),Oo=xi(u,v,C);await t.insertGeneratedImageNearElement($t,e,Oo.width,Oo.height),n?.()}catch(De){De instanceof Error&&(De.name==="AbortError"?ne="aborted":ne=De.message)}finally{Z.current=null,xu(e.id,ne),D(!1),ne===null?(wu(e.id),m(),d(""),k(null)):ne!=="aborted"&&k(ne)}},[p,s,u,v,C,t,e,o,n]);if(i.contextMenu||i.newElement||i.resizingElement||i.isRotating||i.openMenu||i.viewModeEnabled||i.selectedElementsAreBeingDragged)return null;let J=t.scene.getNonDeletedElementsMap(),[te,ue,,Me]=rU(e,J),{x:ct,y:Lt}=n3({sceneX:te+e.width/2,sceneY:ue},i),Sn=ct-i.offsetLeft,Mn=Math.max(Lt-i.offsetTop-44,8),{x:eo,y:Gt}=n3({sceneX:te+e.width/2,sceneY:Me},i),yt=eo-i.offsetLeft,dr=Gt-i.offsetTop+16;return Ft(mU,{children:[!r&&ve("div",{className:"iqep__trigger-bar",style:{left:`${Sn}px`,top:`${Mn}px`},onPointerDown:Y=>Y.stopPropagation(),onClick:Y=>Y.stopPropagation(),children:Ft("button",{className:"iqep__trigger-btn",onClick:()=>c(Y=>!Y),title:"Quick AI edit",children:[ve(cU,{}),ve("span",{children:"AI Edit"})]})}),l&&ve("div",{className:"igp iqep__panel",style:{left:`${yt}px`,top:`${dr}px`},onPointerDown:Y=>Y.stopPropagation(),onClick:Y=>Y.stopPropagation(),children:Ft(ml,{isLoading:S,value:p,onValueChange:d,onSubmit:ae,className:"igp-container",children:[ve(pl,{placeholder:"Describe your edit\u2026",className:"igp-textarea",disableAutosize:!1}),_&&ve("div",{className:"igp-error",children:_}),Ft(ul,{className:"igp-actions",children:[ve("div",{className:"igp-actions-left",children:Ft("div",{className:"igp-dropdown-root",ref:Q,children:[ve(Pr,{tooltip:"Select model",side:"top",children:Ft("button",{className:"igp-btn",onClick:()=>{L(Y=>!Y),B(!1),N(!1)},disabled:S,children:[ve(iU,{}),ve("span",{children:u}),ve(J0,{})]})}),z&&ve("div",{className:"igp-dropdown igp-dropdown--up igp-dropdown--left",children:$0.map(Y=>Ft("button",{className:"igp-dropdown-item",onClick:()=>{h(Y),L(!1)},children:[ve("span",{style:{flex:1},children:Y}),Y===u&&ve("span",{className:"igp-check",children:ve(Q0,{})})]},Y))})]})}),Ft("div",{className:"igp-actions-right",children:[Ft("div",{className:"igp-dropdown-root",ref:$,children:[Ft("button",{className:"igp-btn igp-btn--compact",onClick:()=>{E.length<=1||(N(Y=>!Y),B(!1),L(!1))},disabled:S||E.length<=1,title:E.length<=1?"Fixed resolution for this model":void 0,children:[ve("span",{children:C}),E.length>1&&ve(J0,{})]}),O&&E.length>1&&ve("div",{className:"igp-dropdown igp-dropdown--up igp-dropdown--right",children:E.map(Y=>Ft("button",{className:"igp-dropdown-item",onClick:()=>{P(Y),N(!1)},children:[ve("span",{style:{flex:1},children:Y}),Y===C&&ve("span",{className:"igp-check",children:ve(Q0,{})})]},Y))})]}),Ft("div",{className:"igp-dropdown-root",ref:F,children:[Ft("button",{className:"igp-btn igp-btn--compact",onClick:()=>{B(Y=>!Y),N(!1),L(!1)},disabled:S,children:[ve("span",{children:v}),ve(J0,{})]}),M&&Ft("div",{className:"igp-dropdown igp-dropdown--up igp-dropdown--right igp-dropdown--ratio",children:[Ft("div",{className:"igp-dropdown-header",children:[ve("span",{children:"Output format"}),ve(sU,{})]}),x.map(Y=>{let ne=xi(u,Y,C);return Ft("button",{className:"igp-dropdown-item",onClick:()=>U(Y),children:[ve(dU,{label:Y}),ve("span",{style:{flex:1},children:Y}),Ft("span",{className:"igp-dims",children:[ne.width,"\xD7",ne.height]}),Y===v&&ve("span",{className:"igp-check",children:ve(Q0,{})})]},Y)})]})]}),ve("button",{className:"igp-generate",onClick:S?q:ae,disabled:!S&&!p.trim(),title:S?"Stop generation":"Generate edit",children:S?ve(lU,{}):ve(aU,{size:16})})]})]})]})})]})};import{Fragment as AU,jsx as Ye,jsxs as vn}from"react/jsx-runtime";var tx="https://cloud.leonardo.ai/api/rest/v1",gU=1500,a3=40,s3=e=>({Authorization:`Bearer ${e}`,"Content-Type":"application/json"}),l3=e=>{switch(e){case"image/jpeg":return"jpeg";case"image/jpg":return"jpg";case"image/webp":return"webp";default:return"png"}},hU=e=>e==="upscale"?"Upscale":"Remove background",fU=e=>e==="upscale"?"Upscaling image...":"Removing background...",bU=e=>new Promise(t=>{window.setTimeout(t,e)}),Nu=async(e,t)=>{try{let o=await e.json(),n=o?.error?.message??o?.message??o?.detail??o?.errors?.[0]?.message;if(typeof n=="string"&&n.trim())return n}catch{}try{let o=await e.text();if(o.trim())return o.trim()}catch{}return`${t} (${e.status})`},i3=async(e,t)=>{let o=e.crop;return o?new Promise((n,r)=>{let a=new Image;a.onload=()=>{let i=document.createElement("canvas");i.width=o.width,i.height=o.height;let s=i.getContext("2d");if(!s){r(new Error("Could not prepare the cropped image for editing."));return}s.drawImage(a,o.x,o.y,o.width,o.height,0,0,o.width,o.height),n(i.toDataURL("image/png"))},a.onerror=()=>r(new Error("Could not read the selected image for editing.")),a.src=t}):t},xU=async(e,t)=>{let o=l3(So(e)),n=await fetch(`${tx}/init-image`,{method:"POST",headers:s3(t),body:JSON.stringify({extension:o})});if(!n.ok)throw new Error(await Nu(n,"Leonardo init image request failed"));let a=(await n.json()).uploadInitImage;if(!a?.id||!a.url)throw new Error("Leonardo init image response was incomplete.");let i=a.fields??{},s=typeof i=="string"?JSON.parse(i):i,l=new FormData;return Object.entries(s).forEach(([c,m])=>{l.append(c,m)}),l.append("file",uh(e,`image.${o}`)),await fetch(a.url,{method:"POST",body:l,mode:"no-cors"}),a.id},yU=async(e,t)=>{let o=So(e),n=l3(o),r=uh(e,`image.${n}`),a=new FormData;a.append("size","auto"),a.append("image_file",r);let i=await fetch("https://api.remove.bg/v1.0/removebg",{method:"POST",headers:{"X-Api-Key":t},body:a});if(!i.ok){let l=`Remove background failed (${i.status})`;try{let m=(await i.json())?.errors?.[0]?.title;m&&(l=m)}catch{}throw new Error(l)}let s=await i.arrayBuffer();return await Vi(new Blob([s],{type:"image/png"}))},EU=async(e,t)=>{let o=await fetch(`${tx}/variations/universal-upscaler`,{method:"POST",headers:s3(t),body:JSON.stringify({ultraUpscaleStyle:"ARTISTIC",creativityStrength:1,detailContrast:5,similarity:10,upscaleMultiplier:1.5,initImageId:e})});if(!o.ok)throw new Error(await Nu(o,"Leonardo upscale request failed"));let r=(await o.json()).universalUpscaler?.id;if(!r)throw new Error("Leonardo variation job id was missing from the response.");return r},wU=async(e,t)=>{for(let o=0;o<a3;o++){let n=await fetch(`${tx}/variations/${e}`,{method:"GET",headers:{Authorization:`Bearer ${t}`}});if(!n.ok)throw new Error(await Nu(n,"Leonardo variation status check failed"));let r=await n.json(),a=Array.isArray(r.generated_image_variation_generic)?r.generated_image_variation_generic[0]:r.generated_image_variation_generic;if(!a)throw new Error("Leonardo variation details were missing from the response.");if(a.status==="COMPLETE"){if(!a.url)throw new Error("Leonardo variation completed without an image URL.");return a.url}if(a.status==="FAILED")throw new Error("Leonardo variation failed.");o<a3-1&&await bU(gU)}throw new Error("Leonardo variation timed out.")},vU=async e=>{let t=await fetch(e);if(!t.ok)throw new Error(await Nu(t,"Leonardo result image download failed"));return Vi(await t.blob())},IU=()=>vn("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[Ye("path",{d:"M12 20h9"}),Ye("path",{d:"M16.5 3.5a2.121 2.121 0 0 1 3 3L7 19l-4 1 1-4L16.5 3.5z"})]}),TU=()=>vn("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[Ye("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),Ye("path",{d:"M9 3v18"}),Ye("path",{d:"M14 9l3-3 3 3"}),Ye("path",{d:"M17 6v6"})]}),CU=()=>vn("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[Ye("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),Ye("path",{d:"M9 3v18M3 9h18M3 15h18M15 3v18",strokeDasharray:"2 2",opacity:"0.5"}),Ye("circle",{cx:"12",cy:"12",r:"4"})]}),kU=()=>vn("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[Ye("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),Ye("polyline",{points:"7 10 12 15 17 10"}),Ye("line",{x1:"12",y1:"15",x2:"12",y2:"3"})]}),SU=()=>vn("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[Ye("path",{d:"M6.13 1L6 16a2 2 0 0 0 2 2h15"}),Ye("path",{d:"M1 6.13L16 6a2 2 0 0 1 2 2v15"})]}),MU=()=>vn("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[Ye("path",{d:"M7 16V4m0 0L3 8m4-4l4 4"}),Ye("path",{d:"M17 8v12m0 0l4-4m-4 4l-4-4"})]}),PU=[{id:"quick-edit",label:"Quick Edit",icon:Ye(IU,{})},{id:"upscale",label:"Upscale",icon:Ye(TU,{})},{id:"remove-bg",label:"Remove BG",icon:Ye(CU,{})},{id:"crop",label:"Crop",icon:Ye(SU,{})}],c3=({element:e,app:t,callbacks:o})=>{let n=t.state,r=t3(t.props.leonardoApiKey),a=o3(t.props.removeBgApiKey),[i,s]=ex(()=>hi(e.id)),[l,c]=ex(null),[m,p]=ex(null),d=l!==null,u=Ru(async S=>{if(!r){p("No Leonardo API key found. Set VITE_APP_LEONARDO_API_KEY in .env or pass leonardoApiKey as a prop.");return}let D=e.fileId;if(!D){p("The selected image is missing its file reference.");return}let _=t.files[D]?.dataURL;if(!_){p("The selected image file could not be found.");return}let k=t.props.onBeforeUpscale,M=t.props.onAfterUpscale;if(k)try{let{allowed:B,error:O}=await k();if(!B){p(O||"Insufficient credits for upscale");return}}catch{p("Credit check failed");return}c(S),p(null);try{let B=await i3(e,_),O=await xU(B,r),N=await EU(O,r),z=await wU(N,r),L=await vU(z);await t.insertGeneratedImageNearElement(L,e,e.width,e.height),M?.()}catch(B){p(B instanceof Error?B.message:`${hU(S)} failed.`)}finally{c(null)}},[t,e,r]),h=Ru(async()=>{if(!a){p("No remove.bg API key found. Set VITE_APP_REMOVE_BG_API_KEY in .env or pass removeBgApiKey as a prop.");return}let S=e.fileId;if(!S){p("The selected image is missing its file reference.");return}let D=t.files[S]?.dataURL;if(!D){p("The selected image file could not be found.");return}let _=t.props.onBeforeRemoveBg,k=t.props.onAfterRemoveBg;if(_)try{let{allowed:M,error:B}=await _();if(!M){p(B||"Insufficient credits for remove background");return}}catch{p("Credit check failed");return}c("remove-bg"),p(null);try{let M=await i3(e,D),B=await yU(M,a);await t.insertGeneratedImageNearElement(B,e,e.width,e.height),k?.()}catch(M){p(M instanceof Error?M.message:"Remove background failed.")}finally{c(null)}},[t,e,a]),g=Ru(S=>{if(p(null),S==="quick-edit"){o?.onQuickEdit?o.onQuickEdit():s(_=>!_);return}if(S==="crop"){o?.onCrop?o.onCrop():t.actionManager.executeAction(ed);return}let D={upscale:o?.onUpscale,"remove-bg":o?.onRemoveBG};if(D[S]){D[S]?.();return}S==="upscale"?u(S):S==="remove-bg"&&h()},[o,t.actionManager,u,h]),x=Ru(()=>{if(o?.onDownload){o.onDownload();return}let S=e.fileId;if(!S)return;let D=t.files[S];if(!D?.dataURL)return;let _=B=>{let O=document.createElement("a");O.href=B,O.download=`image-${S}.png`,document.body.appendChild(O),O.click(),document.body.removeChild(O)},k=e.crop;if(!k){_(D.dataURL);return}let M=new Image;M.onload=()=>{let B=document.createElement("canvas");B.width=k.width,B.height=k.height;let O=B.getContext("2d");if(!O){_(D.dataURL);return}O.drawImage(M,k.x,k.y,k.width,k.height,0,0,k.width,k.height),_(B.toDataURL("image/png"))},M.onerror=()=>_(D.dataURL),M.src=D.dataURL},[e.fileId,e.crop,t.files,o]);if(n.contextMenu||n.newElement||n.resizingElement||n.isRotating||n.openMenu||n.viewModeEnabled||n.selectedElementsAreBeingDragged)return null;let E=t.scene.getNonDeletedElementsMap(),[y,w]=uU(e,E),{x:v,y:I}=pU({sceneX:y+e.width/2,sceneY:w},n),C=v-n.offsetLeft,P=Math.max(I-n.offsetTop-52,8);return vn(AU,{children:[i&&!o?.onQuickEdit&&Ye(r3,{element:e,app:t,onBeforeImageGen:t.props.onBeforeImageGen,onAfterImageGen:t.props.onAfterImageGen,forceOpen:!0,onClose:()=>s(!1)}),vn("div",{className:"iet",style:{left:`${C}px`,top:`${P}px`},onPointerDown:S=>S.stopPropagation(),onClick:S=>S.stopPropagation(),children:[vn("div",{className:"iet__bar",children:[PU.map(S=>vn("button",{type:"button",className:"iet__tool-btn",onClick:()=>g(S.id),title:S.label,disabled:d,"aria-busy":l===S.id,children:[S.icon,Ye("span",{className:"iet__tool-label",children:S.label}),S.badge&&Ye("span",{className:"iet__tool-badge",children:S.badge})]},S.id)),!!o?.onSwapAsset&&vn("button",{type:"button",className:"iet__tool-btn",onClick:()=>{o.onSwapAsset(e.id)},title:"Swap image from asset bank",disabled:d,children:[Ye(MU,{}),Ye("span",{className:"iet__tool-label",children:"Swap"})]}),Ye("div",{className:"iet__divider"}),Ye("button",{type:"button",className:"iet__tool-btn iet__download-btn",onClick:x,title:"Download",disabled:d,children:Ye(kU,{})})]}),(l||m)&&Ye("div",{className:`iet__status${m?" iet__status--error":""}`,children:m??(l?fU(l):null)})]})]})};import{DEFAULT_LASER_COLOR as RU,easeOut as m3}from"@orangecatai/common";import{LaserPointer as LU}from"@excalidraw/laser-pointer";import{SVG_NS as d3,getSvgPathFromStroke as _U,sceneCoordsToViewportCoords as DU}from"@orangecatai/common";var Ar=class{constructor(t,o,n){this.animationFrameHandler=t;this.app=o;this.options=n;A(this,"currentTrail");A(this,"pastTrails",[]);A(this,"container");A(this,"trailElement");A(this,"trailAnimation");this.animationFrameHandler.register(this,this.onFrame.bind(this)),this.trailElement=document.createElementNS(d3,"path"),this.options.animateTrail&&(this.trailAnimation=document.createElementNS(d3,"animate"),this.trailAnimation.setAttribute("attributeName","stroke-dashoffset"),this.trailElement.setAttribute("stroke-dasharray","7 7"),this.trailElement.setAttribute("stroke-dashoffset","10"),this.trailAnimation.setAttribute("from","0"),this.trailAnimation.setAttribute("to","-14"),this.trailAnimation.setAttribute("dur","0.3s"),this.trailElement.appendChild(this.trailAnimation))}get hasCurrentTrail(){return!!this.currentTrail}hasLastPoint(t,o){if(this.currentTrail){let n=this.currentTrail.originalPoints.length;return this.currentTrail.originalPoints[n-1][0]===t&&this.currentTrail.originalPoints[n-1][1]===o}return!1}start(t){t&&(this.container=t),this.trailElement.parentNode!==this.container&&this.container&&this.container.appendChild(this.trailElement),this.animationFrameHandler.start(this)}stop(){this.animationFrameHandler.stop(this),this.trailElement.parentNode===this.container&&this.container?.removeChild(this.trailElement)}startPath(t,o){this.currentTrail=new LU(this.options),this.currentTrail.addPoint([t,o,performance.now()]),this.update()}addPointToPath(t,o){this.currentTrail&&(this.currentTrail.addPoint([t,o,performance.now()]),this.update())}endPath(){this.currentTrail&&(this.currentTrail.close(),this.currentTrail.options.keepHead=!1,this.pastTrails.push(this.currentTrail),this.currentTrail=void 0,this.update())}getCurrentTrail(){return this.currentTrail}clearTrails(){this.pastTrails=[],this.currentTrail=void 0,this.update()}update(){this.start(),this.trailAnimation&&(this.trailAnimation.setAttribute("begin","indefinite"),this.trailAnimation.setAttribute("repeatCount","indefinite"))}onFrame(){let t=[];for(let n of this.pastTrails)t.push(this.drawTrail(n,this.app.state));if(this.currentTrail){let n=this.drawTrail(this.currentTrail,this.app.state);t.push(n)}this.pastTrails=this.pastTrails.filter(n=>n.getStrokeOutline().length!==0),t.length===0&&this.stop();let o=t.join(" ").trim();this.trailElement.setAttribute("d",o),this.trailAnimation?(this.trailElement.setAttribute("fill",(this.options.fill??(()=>"black"))(this)),this.trailElement.setAttribute("stroke",(this.options.stroke??(()=>"black"))(this))):this.trailElement.setAttribute("fill",(this.options.fill??(()=>"black"))(this))}drawTrail(t,o){let n=t.getStrokeOutline(t.options.size/o.zoom.value).map(([a,i])=>{let s=DU({sceneX:a,sceneY:i},o);return[s.x,s.y]}),r=this.trailAnimation?n.slice(0,n.length/2):n;return _U(r,!0)}};var Bu=class{constructor(t,o){this.animationFrameHandler=t;this.app=o;A(this,"localTrail");A(this,"collabTrails",new Map);A(this,"container");this.animationFrameHandler.register(this,this.onFrame.bind(this)),this.localTrail=new Ar(t,o,{...this.getTrailOptions(),fill:()=>RU})}getTrailOptions(){return{simplify:0,streamline:.4,sizeMapping:t=>{let r=Math.max(0,1-(performance.now()-t.pressure)/1e3),a=(50-Math.min(50,t.totalLength-t.currentIndex))/50;return Math.min(m3(a),m3(r))}}}startPath(t,o){this.localTrail.startPath(t,o)}addPointToPath(t,o){this.localTrail.addPointToPath(t,o)}endPath(){this.localTrail.endPath()}start(t){this.container=t,this.animationFrameHandler.start(this),this.localTrail.start(t)}stop(){this.animationFrameHandler.stop(this),this.localTrail.stop()}onFrame(){this.updateCollabTrails()}updateCollabTrails(){if(!(!this.container||this.app.state.collaborators.size===0)){for(let[t,o]of this.app.state.collaborators.entries()){let n;this.collabTrails.has(t)?n=this.collabTrails.get(t):(n=new Ar(this.animationFrameHandler,this.app,{...this.getTrailOptions(),fill:()=>o.pointer?.laserColor||ni(t,o)}),n.start(this.container),this.collabTrails.set(t,n)),o.pointer&&o.pointer.tool==="laser"&&(o.button==="down"&&!n.hasCurrentTrail&&n.startPath(o.pointer.x,o.pointer.y),o.button==="down"&&n.hasCurrentTrail&&!n.hasLastPoint(o.pointer.x,o.pointer.y)&&n.addPointToPath(o.pointer.x,o.pointer.y),o.button==="up"&&n.hasCurrentTrail&&(n.addPointToPath(o.pointer.x,o.pointer.y),n.endPath()))}for(let t of this.collabTrails.keys())this.app.state.collaborators.has(t)||(this.collabTrails.get(t).stop(),this.collabTrails.delete(t))}}};import{version as NU}from"react";import{unstable_batchedUpdates as p3}from"react-dom";import{throttleRAF as BU}from"@orangecatai/common";var pt=e=>t=>{p3(e,t)},Fu=e=>BU(t=>{p3(e,t)}),wi=(()=>{let e;try{let o=NU.split(".");e=Number(o[0])>17}catch{e=!1}let t=!1;return()=>window.EXCALIDRAW_THROTTLE_RENDER===!0?e?!0:(t||(t=!0,console.warn("Excalidraw: render throttling is disabled on React versions < 18.")),!1):!1})();import{CODES as ox,KEYS as pd,CLASSES as nx,POINTER_BUTTON as FU,THEME as OU,isWritableElement as zU,getFontString as u3,getFontFamilyString as g3,isTestEnv as h3,MIME_TYPES as rx,applyDarkModeFilter as HU}from"@orangecatai/common";import{getTextFromElements as GU,originalContainerCache as UU,updateBoundElements as f3,updateOriginalContainerCache as b3}from"@orangecatai/element";import{LinearElementEditor as WU}from"@orangecatai/element";import{bumpVersion as YU}from"@orangecatai/element";import{getBoundTextElementId as $U,getContainerElement as ax,getTextElementAngle as VU,redrawTextBoundingBox as KU,getBoundTextMaxHeight as XU,getBoundTextMaxWidth as x3,computeContainerDimensionForBoundText as y3,computeBoundTextPosition as ZU,getBoundTextElement as jU}from"@orangecatai/element";import{getTextWidth as qU}from"@orangecatai/element";import{normalizeText as E3}from"@orangecatai/element";import{wrapText as JU}from"@orangecatai/element";import{isArrowElement as Ou,isBoundToContainer as QU,isTextElement as w3}from"@orangecatai/element";var eW=(e,t,o,n,r,a)=>{let{zoom:i}=n,s=180*o/Math.PI,l=e*(i.value-1)/2,c=t*(i.value-1)/2;return e>r&&i.value!==1&&(l=r*(i.value-1)/2),t>a&&i.value!==1&&(c=a*(i.value-1)/2),`translate(${l}px, ${c}px) scale(${i.value}) rotate(${s}deg)`},v3=({id:e,onChange:t,onSubmit:o,getViewportCoords:n,element:r,canvas:a,excalidrawContainer:i,app:s,autoSelect:l=!0})=>{let c=(L,F)=>{if(!F.style.fontFamily||!F.style.fontSize)return!1;let $=F.style.fontFamily.replace(/"/g,"");return g3({fontFamily:L.fontFamily})!==$||`${L.fontSize}px`!==F.style.fontSize},m=s.state.theme,p=()=>{m=s.state.theme;let L=s.state,F=s.scene.getElement(e);if(!F)return;let{textAlign:$,verticalAlign:Q}=F,Z=s.scene.getNonDeletedElementsMap();if(F&&w3(F)){let U=F.x,q=F.y,ae=ax(F,s.scene.getNonDeletedElementsMap()),J=F.width,te=F.height,ue=F.width,Me=F.height;if(ae&&F.containerId){if(Ou(ae)){let yt=WU.getBoundTextElementPosition(ae,F,Z);U=yt.x,q=yt.y}let eo=c(F,d),Gt;if(eo?Gt=b3(ae.id,ae.height):(Gt=UU[ae.id],Gt||(Gt=b3(ae.id,ae.height))),ue=x3(ae,F),Me=XU(ae,F),!Ou(ae)&&te>Me){let yt=y3(te,ae.type);s.scene.mutateElement(ae,{height:yt}),f3(ae,s.scene);return}else if(!Ou(ae)&&ae.height>Gt.height&&te<Me){let yt=y3(te,ae.type);s.scene.mutateElement(ae,{height:yt}),f3(ae,s.scene)}else{let{x:yt,y:dr}=ZU(ae,F,Z);U=yt,q=dr}}let[ct,Lt]=n(U,q);ae?J+=.5:(ue=(L.width-8-ct)/L.zoom.value,J=Math.min(J,ue)),te*=1.05;let Sn=u3(F),Mn=(L.height-Lt)/L.zoom.value;Object.assign(d.style,{font:Sn,lineHeight:F.lineHeight,width:`${J}px`,height:`${te}px`,left:`${ct}px`,top:`${Lt}px`,transform:eW(J,te,VU(F,ae),L,ue,Mn),textAlign:$,verticalAlign:Q,color:L.theme===OU.DARK?HU(F.strokeColor):F.strokeColor,opacity:F.opacity/100,maxHeight:`${Mn}px`}),d.scrollTop=0,h3()&&(d.style.fontFamily=g3(F)),s.scene.mutateElement(F,{x:U,y:q})}},d=document.createElement("textarea");d.dir="auto",d.tabIndex=0,d.dataset.type="wysiwyg",d.wrap="off",d.classList.add("excalidraw-wysiwyg");let u="pre",h="normal";(QU(r)||!r.autoResize)&&(u="pre-wrap",h="break-word"),Object.assign(d.style,{position:"absolute",display:"inline-block",minHeight:"1em",backfaceVisibility:"hidden",margin:0,padding:0,border:0,outline:0,resize:"none",background:"transparent",overflow:"hidden",zIndex:"var(--zIndex-wysiwyg)",wordBreak:h,whiteSpace:u,overflowWrap:"break-word",boxSizing:"content-box"}),d.value=r.originalText,p(),t&&(d.onpaste=async L=>{let F=pI(L),$=null;if(F.has(rx.excalidrawClipboard)||F.has(rx.excalidraw)){L.preventDefault(),$=await As(L);try{let ae=await sp($);if(ae.elements){let J=GU(ae.elements);if(J){let{selectionStart:te,selectionEnd:ue,value:Me}=d;d.value=Me.slice(0,te)+J+Me.slice(ue);let ct=te+J.length;d.selectionStart=d.selectionEnd=ct,d.dispatchEvent(new Event("input"))}}return}catch{console.warn("failed to parse excalidraw clipboard data")}}$=$||await As(L);let Q=$.findByType(rx.text);if(!Q)return;let Z=E3(Q.value);if(!Z)return;let U=ax(r,s.scene.getNonDeletedElementsMap()),q=u3({fontSize:s.state.currentItemFontSize,fontFamily:s.state.currentItemFontFamily});if(U){let ae=jU(U,s.scene.getNonDeletedElementsMap()),J=JU(`${d.value}${Z}`,q,x3(U,ae)),te=qU(J,q);d.style.width=`${te}px`}},d.oninput=()=>{let L=E3(d.value);if(d.value!==L){let F=d.selectionStart;d.value=L,d.selectionStart=F,d.selectionEnd=F}t(d.value)}),d.onkeydown=L=>{if(!L.shiftKey&&qm.keyTest(L))L.preventDefault(),s.actionManager.executeAction(qm),p();else if(!L.shiftKey&&Jm.keyTest(L))L.preventDefault(),s.actionManager.executeAction(Jm),p();else if(!L.shiftKey&&Qm.keyTest(L))L.preventDefault(),s.actionManager.executeAction(Qm),p();else if(Cf.keyTest(L))s.actionManager.executeAction(Cf);else if(kf.keyTest(L))s.actionManager.executeAction(kf);else if(L.key===pd.ESCAPE)L.preventDefault(),C=!0,P();else if(ti.keyTest(L))L.preventDefault(),P(),s.actionManager.executeAction(ti);else if(L.key===pd.ENTER&&L[pd.CTRL_OR_CMD]){if(L.preventDefault(),L.isComposing||L.keyCode===229)return;C=!0,P()}else if(L.key===pd.TAB||L[pd.CTRL_OR_CMD]&&(L.code===ox.BRACKET_LEFT||L.code===ox.BRACKET_RIGHT)){if(L.preventDefault(),L.isComposing)return;L.shiftKey||L.code===ox.BRACKET_LEFT?w():y(),d.dispatchEvent(new Event("input"))}};let g=4,x=" ".repeat(g),E=new RegExp(`^ {1,${g}}`),y=()=>{let{selectionStart:L,selectionEnd:F}=d,$=v(),Q=d.value;$.forEach(Z=>{let U=Q.slice(0,Z),q=Q.slice(Z);Q=`${U}${x}${q}`}),d.value=Q,d.selectionStart=L+g,d.selectionEnd=F+g*$.length},w=()=>{let{selectionStart:L,selectionEnd:F}=d,$=v(),Q=[],Z=d.value;$.forEach(U=>{let q=Z.slice(U,U+g).match(E);if(q){let ae=Z.slice(0,U),J=Z.slice(U+q[0].length);Z=`${ae}${J}`,Q.push(U)}}),d.value=Z,Q.length&&(L>Q[Q.length-1]?d.selectionStart=Math.max(L-g,Q[Q.length-1]):d.selectionStart=L,d.selectionEnd=Math.max(d.selectionStart,F-g*Q.length))},v=()=>{let{selectionStart:L,selectionEnd:F,value:$}=d,Q=$.slice(0,L).match(/[^\n]*$/)[0].length;return L=L-Q,$.slice(L,F).split(`
|
|
201
|
+
`).reduce((U,q,ae,J)=>U.concat(ae?U[ae-1]+J[ae-1].length+1:L),[]).reverse()},I=L=>{L.target instanceof HTMLCanvasElement&&(L.preventDefault(),L.stopPropagation())},C=!1,P=()=>{if(N)return;N=!0,S();let L=s.scene.getElement(r.id);if(!L)return;let F=ax(L,s.scene.getNonDeletedElementsMap());if(F){if(d.value.trim()){let $=$U(F);!$||$!==r.id?s.scene.mutateElement(F,{boundElements:(F.boundElements||[]).concat({type:"text",id:r.id})}):Ou(F)&&YU(F)}else s.scene.mutateElement(F,{boundElements:F.boundElements?.filter($=>!w3($))});KU(L,F,s.scene)}o({viaKeyboard:C,nextOriginalText:d.value})},S=()=>{d.onblur=null,d.oninput=null,d.onkeydown=null,z&&z.disconnect(),window.removeEventListener("resize",p),window.removeEventListener("wheel",I,!0),window.removeEventListener("pointerdown",k),window.removeEventListener("pointerup",D),window.removeEventListener("blur",P),window.removeEventListener("beforeunload",P),B(),M(),O(),d.remove()},D=L=>{window.removeEventListener("pointerup",D);let F=L?.target,$=F instanceof HTMLElement&&F.classList.contains("properties-trigger"),Q=(F instanceof HTMLElement||F instanceof SVGElement)&&!!F.closest(".properties-content"),Z=(F instanceof HTMLElement||F instanceof SVGElement)&&(!!F.closest(`.${nx.SHAPE_ACTIONS_MENU}`)||!!F.closest(".compact-shape-actions-island"));setTimeout(()=>{Z||$||Q||(d.onblur=P,d.focus())})},_=()=>{d.onblur=null,window.addEventListener("pointerup",D),window.addEventListener("blur",P)},k=L=>{let F=L?.target;if(L.button===FU.WHEEL){F instanceof HTMLTextAreaElement&&(L.preventDefault(),s.handleCanvasPanUsingWheelOrSpaceDrag(L)),_();return}let $=F instanceof HTMLElement&&F.classList.contains("properties-trigger"),Q=(F instanceof HTMLElement||F instanceof SVGElement)&&!!F.closest(".properties-content");(L.target instanceof HTMLElement||L.target instanceof SVGElement)&&(L.target.closest(`.${nx.SHAPE_ACTIONS_MENU}, .${nx.ZOOM_ACTIONS}`)||L.target.closest(".compact-shape-actions-island"))&&!zU(L.target)||$||Q?_():L.target instanceof HTMLCanvasElement&&!h3()&&requestAnimationFrame(()=>{P()})},M=s.onChangeEmitter.on(L=>{s.state.theme!==m&&p()}),B=s.scene.onUpdate(()=>{p(),!!document.activeElement?.closest(".properties-content")||d.focus()}),O=s.onScrollChangeEmitter.on(()=>{p()}),N=!1;l&&d.select(),D();let z=null;return a&&"ResizeObserver"in window?(z=new window.ResizeObserver(()=>{p()}),z.observe(a)):window.addEventListener("resize",p),d.onpointerdown=L=>L.stopPropagation(),requestAnimationFrame(()=>{window.addEventListener("pointerdown",k,{capture:!0})}),window.addEventListener("beforeunload",P),i?.querySelector(".excalidraw-textEditorContainer").appendChild(d),P};import{getGlobalCSSVariable as zu}from"@orangecatai/common";import{getCommonBounds as tW}from"@orangecatai/element";var Lr=4,Jo=6,I3="rgba(0,0,0,0.3)",T3=(e,t,o,n)=>{if(!e.size)return{horizontal:null,vertical:null};let[r,a,i,s]=tW(e),l=t/n.zoom.value,c=o/n.zoom.value,m={top:parseInt(zu("sat"))||0,bottom:parseInt(zu("sab"))||0,left:parseInt(zu("sal"))||0,right:parseInt(zu("sar"))||0},p=ur().rtl,d=-n.scrollX+m.left,u=-n.scrollY+m.top,h=d+l-m.right,g=u+c-m.bottom,x=Math.min(r,d),E=Math.min(a,u),y=Math.max(i,h),w=Math.max(s,g),v=i-r,I=s-a,C=y-x,P=w-E,S=Math.max(Lr*2,m.left+m.right)+Jo*2,D=t*(l/C)-S,_=Math.max(Lr*2,m.top+m.bottom)+Jo*2,k=o*(c/P)-_,M=C>v?C*n.zoom.value/(D+S):t/(D+S),B=P>I?P*n.zoom.value/(k+_):o/(k+_);return{horizontal:d===x&&h===y?null:{x:Math.max(m.left,Lr)+Jo+(d-x)/C*t,y:o-Jo-Math.max(Lr,m.bottom),width:D,height:Jo,deltaMultiplier:M},vertical:u===E&&g===w?null:{x:p?Math.max(m.left,Lr):t-Jo-Math.max(m.right,Lr),y:Math.max(m.top,Lr)+Jo+(u-E)/P*o,width:Jo,height:k,deltaMultiplier:B}}},ix=(e,t,o)=>{let[n,r]=[e.horizontal,e.vertical].map(i=>i!=null&&i.x<=t&&t<=i.x+i.width&&i.y<=o&&o<=i.y+i.height);return{isOverEither:n||r,isOverHorizontal:n,isOverVertical:r}};var C3=e=>{let t=["flowchart","graph","sequenceDiagram","classDiagram","stateDiagram","stateDiagram-v2","erDiagram","journey","gantt","pie","quadrantChart","requirementDiagram","gitGraph","C4Context","mindmap","timeline","zenuml","sankey","xychart","block"];return new RegExp(`^(?:%%{.*?}%%[\\s\\n]*)?\\b(?:${t.map(n=>`\\s*${n}(-beta)?`).join("|")})\\b`).test(e.trim())};import{pointFrom as mW}from"@orangecatai/math";import{getElementLineSegments as pW}from"@orangecatai/element";import{LinearElementEditor as uW}from"@orangecatai/element";import{isFrameLikeElement as gW,isLinearElement as hW,isTextElement as fW}from"@orangecatai/element";import{getFrameChildren as bW}from"@orangecatai/element";import{selectGroupsForSelectedElements as xW}from"@orangecatai/element";import{getContainerElement as yW}from"@orangecatai/element";import{arrayToMap as EW,easeOut as P3,isShallowEqual as wW}from"@orangecatai/common";import{simplify as oW}from"points-on-curve";import{polygonFromPoints as nW,lineSegment as k3,polygonIncludesPointNonZero as rW}from"@orangecatai/math";import{computeBoundTextPosition as aW,doBoundsIntersect as iW,getBoundTextElement as sW,getElementBounds as lW,intersectElementWithLineSegment as S3}from"@orangecatai/element";var M3=e=>{let{lassoPath:t,elements:o,elementsMap:n,elementsSegments:r,intersectedElements:a,enclosedElements:i,simplifyDistance:s}=e,l=t;s&&(l=oW(t,s));let c=o.filter(d=>!d.locked);i.clear(),a.clear();let m=t.reduce((d,u)=>[Math.min(d[0],u[0]),Math.min(d[1],u[1]),Math.max(d[2],u[0]),Math.max(d[3],u[1])],[1/0,1/0,-1/0,-1/0]);for(let d of c){let u=lW(d,n);iW(m,u)&&!a.has(d.id)&&!i.has(d.id)&&(cW(l,d,r)?i.add(d.id):dW(l,d,n)&&a.add(d.id))}return{selectedElementIds:[...a,...i]}},cW=(e,t,o)=>{let n=nW(e),r=o.get(t.id);return r?r.some(a=>a.some(i=>rW(i,n))):!1},dW=(e,t,o)=>{let n=e.slice(1).map((a,i)=>k3(e[i],a)).concat([k3(e[e.length-1],e[0])]),r=sW(t,o);return n.some(a=>S3(t,o,a,0,!0).length>0||!!r&&S3({...r,...aW(t,r,o)},o,a,0,!0).length>0)};var Hu=class extends Ar{constructor(o,n){super(o,n,{animateTrail:!0,streamline:.4,sizeMapping:r=>{let s=Math.max(0,1-(performance.now()-r.pressure)/(1/0)),l=(5e3-Math.min(5e3,r.totalLength-r.currentIndex))/5e3;return Math.min(P3(l),P3(s))},fill:()=>"rgba(105,101,219,0.05)",stroke:()=>"rgba(105,101,219)"});A(this,"intersectedElements",new Set);A(this,"enclosedElements",new Set);A(this,"elementsSegments",null);A(this,"canvasTranslate",null);A(this,"keepPreviousSelection",!1);A(this,"selectElementsFromIds",o=>{this.app.setState(n=>{let r=o.reduce((l,c)=>(l[c]=!0,l),{});if(this.keepPreviousSelection)for(let l of Object.keys(n.selectedElementIds))r[l]=!0;for(let[l]of Object.entries(r)){let c=this.app.scene.getNonDeletedElement(l);if(c&&fW(c)){let m=yW(c,this.app.scene.getNonDeletedElementsMap());m&&(r[m.id]=!0,delete r[c.id])}}for(let[l]of Object.entries(r)){let c=this.app.scene.getNonDeletedElement(l);if(c&&gW(c)){let m=bW(this.app.scene.getNonDeletedElementsMap(),c.id);for(let p of m)delete r[p.id]}}let a=xW({editingGroupId:n.editingGroupId,selectedElementIds:r},this.app.scene.getNonDeletedElements(),n,this.app),i=[...Object.keys(a.selectedElementIds)],s=[...Object.keys(a.selectedGroupIds)];return{selectedElementIds:a.selectedElementIds,selectedGroupIds:a.selectedGroupIds,selectedLinearElement:i.length===1&&!s.length&&hW(this.app.scene.getNonDeletedElement(i[0]))?new uW(this.app.scene.getNonDeletedElement(i[0]),this.app.scene.getNonDeletedElementsMap()):null}})});A(this,"addPointToPath",(o,n,r=!1)=>{super.addPointToPath(o,n),this.keepPreviousSelection=r,this.updateSelection()});A(this,"updateSelection",()=>{let o=super.getCurrentTrail()?.originalPoints?.map(r=>mW(r[0],r[1])),n={scrollX:this.app.state.scrollX,scrollY:this.app.state.scrollY,zoom:this.app.state.zoom.value};if(!this.elementsSegments||!wW(n,this.canvasTranslate??{})){this.canvasTranslate=n,this.elementsSegments=new Map;let r=EW(this.app.visibleElements);for(let a of this.app.visibleElements){let i=pW(a,r);this.elementsSegments.set(a.id,i)}}if(o){let{selectedElementIds:r}=M3({lassoPath:o,elements:this.app.visibleElements,elementsMap:this.app.scene.getNonDeletedElementsMap(),elementsSegments:this.elementsSegments,intersectedElements:this.intersectedElements,enclosedElements:this.enclosedElements,simplifyDistance:5/this.app.state.zoom.value});this.selectElementsFromIds(r)}})}startPath(o,n,r=!1){this.endPath(),super.startPath(o,n),this.intersectedElements.clear(),this.enclosedElements.clear(),this.keepPreviousSelection=r,this.keepPreviousSelection||this.app.setState({selectedElementIds:{},selectedGroupIds:{},selectedLinearElement:null})}endPath(){super.endPath(),super.clearTrails(),this.intersectedElements.clear(),this.enclosedElements.clear(),this.elementsSegments=null}};import{arrayToMap as vW,easeOut as A3,THEME as IW}from"@orangecatai/common";import{computeBoundTextPosition as TW,doBoundsIntersect as CW,getBoundTextElement as kW,getElementBounds as SW,getElementLineSegments as MW,getFreedrawOutlineAsSegments as PW,getFreedrawOutlinePoints as AW,intersectElementWithLineSegment as L3,isArrowElement as LW,isFreeDrawElement as _3,isLineElement as _W,isPointInElement as DW}from"@orangecatai/element";import{lineSegment as RW,lineSegmentsDistance as D3,pointFrom as z3,polygon as NW,polygonIncludesPointNonZero as BW}from"@orangecatai/math";import{getElementsInGroup as R3}from"@orangecatai/element";import{shouldTestInside as FW}from"@orangecatai/element";import{hasBoundTextElement as N3,isBoundToContainer as B3}from"@orangecatai/element";import{getBoundTextElementId as F3}from"@orangecatai/element";var Gu=class extends Ar{constructor(o,n){super(o,n,{streamline:.2,size:5,keepHead:!0,sizeMapping:r=>{let s=Math.max(0,1-(performance.now()-r.pressure)/200),l=(10-Math.min(10,r.totalLength-r.currentIndex))/10;return Math.min(A3(l),A3(s))},fill:()=>n.state.theme===IW.LIGHT?"rgba(0, 0, 0, 0.2)":"rgba(255, 255, 255, 0.2)"});A(this,"elementsToErase",new Set);A(this,"groupsToErase",new Set)}startPath(o,n){this.endPath(),super.startPath(o,n),this.elementsToErase.clear()}addPointToPath(o,n,r=!1){return super.addPointToPath(o,n),this.updateElementsToBeErased(r)}updateElementsToBeErased(o){let n=super.getCurrentTrail()?.originalPoints?.map(s=>z3(s[0],s[1]))||[];if(n.length<2)return[];let r=RW(n[n.length-1],n[n.length-2]),a=this.app.visibleElements.filter(s=>!s.locked),i=vW(a);for(let s of a)if(o&&this.elementsToErase.has(s.id)){if(O3(r,s,i,this.app.state.zoom.value)){let c=s.groupIds.at(-1);if(this.groupsToErase.has(c)){let m=R3(this.app.scene.getNonDeletedElementsMap(),c);for(let p of m)this.elementsToErase.delete(p.id);this.groupsToErase.delete(c)}if(B3(s)&&this.elementsToErase.delete(s.containerId),N3(s)){let m=F3(s);m&&this.elementsToErase.delete(m)}this.elementsToErase.delete(s.id)}}else if(!o&&!this.elementsToErase.has(s.id)&&O3(r,s,i,this.app.state.zoom.value)){let c=s.groupIds.at(-1);if(!this.groupsToErase.has(c)){let m=R3(this.app.scene.getNonDeletedElementsMap(),c);for(let p of m)this.elementsToErase.add(p.id);this.groupsToErase.add(c)}if(N3(s)){let m=F3(s);m&&this.elementsToErase.add(m)}B3(s)&&this.elementsToErase.add(s.containerId),this.elementsToErase.add(s.id)}return Array.from(this.elementsToErase)}endPath(){super.endPath(),super.clearTrails(),this.elementsToErase.clear(),this.groupsToErase.clear()}},O3=(e,t,o,n)=>{let r=e[1],a=_3(t)?15:t.strokeWidth/2,i=[Math.min(e[0][0],e[1][0])-a,Math.min(e[0][1],e[1][1])-a,Math.max(e[0][0],e[1][0])+a,Math.max(e[0][1],e[1][1])+a],s=SW(t,o),l=[s[0]-a,s[1]-a,s[2]+a,s[3]+a];if(!CW(i,l))return!1;if(FW(t)&&DW(r,t,o))return!0;if(_3(t)){let m=AW(t),p=PW(t,m,o),d=Math.max(2.25,5/n);for(let h of p)if(D3(h,e)<=d)return!0;let u=NW(...m.map(([h,g])=>z3(t.x+h,t.y+g)));return!!BW(e[0],u)}let c=kW(t,o);if(LW(t)||_W(t)&&!t.polygon){let m=Math.max(t.strokeWidth,t.strokeWidth*2/n),p=MW(t,o);for(let d of p)if(D3(d,e)<=m)return!0;return!1}return L3(t,o,e,0,!0).length>0||!!c&&L3({...c,...TW(t,c,o)},o,e,0,!0).length>0};import{jsx as Qo,jsxs as H3}from"react/jsx-runtime";var OW=()=>H3("div",{"data-testid":"brave-measure-text-error",children:[Qo("p",{children:Qo(io,{i18nKey:"errors.brave_measure_text_error.line1",bold:e=>Qo("span",{style:{fontWeight:600},children:e})})}),Qo("p",{children:Qo(io,{i18nKey:"errors.brave_measure_text_error.line2",bold:e=>Qo("span",{style:{fontWeight:600},children:e})})}),Qo("p",{children:Qo(io,{i18nKey:"errors.brave_measure_text_error.line3",link:e=>Qo("a",{href:"http://docs.excalidraw.com/docs/@orangecatai/adgen-canvas/faq#turning-off-aggresive-block-fingerprinting-in-brave-browser",children:e})})}),Qo("p",{children:Qo(io,{i18nKey:"errors.brave_measure_text_error.line4",issueLink:e=>Qo("a",{href:"https://github.com/excalidraw/excalidraw/issues/new",children:e}),discordLink:e=>H3("a",{href:"https://discord.gg/UexuTaE",children:[e,"."]})})})]}),G3=OW;import $W from"clsx";import VW from"react";import{useLayoutEffect as zW,useRef as U3,useEffect as W3}from"react";import{unstable_batchedUpdates as HW}from"react-dom";import{KEYS as GW,queryFocusableElements as UW}from"@orangecatai/common";import WW from"clsx";import{jsx as YW}from"react/jsx-runtime";var Y3=({children:e,left:t,top:o,onCloseRequest:n,fitInViewport:r=!1,offsetLeft:a=0,offsetTop:i=0,viewportWidth:s=window.innerWidth,viewportHeight:l=window.innerHeight,className:c})=>{let m=U3(null);W3(()=>{let d=m.current;if(!d)return;d.contains(document.activeElement)||d.focus();let u=h=>{if(h.key===GW.TAB){let g=UW(d),{activeElement:x}=document,E=g.findIndex(y=>y===x);x===d?(h.shiftKey?g[g.length-1]?.focus():g[0].focus(),h.preventDefault(),h.stopImmediatePropagation()):E===0&&h.shiftKey?(g[g.length-1]?.focus(),h.preventDefault(),h.stopImmediatePropagation()):E===g.length-1&&!h.shiftKey&&(g[0]?.focus(),h.preventDefault(),h.stopImmediatePropagation())}};return d.addEventListener("keydown",u),()=>d.removeEventListener("keydown",u)},[]);let p=U3(null);return zW(()=>{if(r&&m.current&&o!=null&&t!=null){let d=m.current,{width:u,height:h}=d.getBoundingClientRect();if(p.current?.top===o&&p.current?.left===t)return;p.current={top:o,left:t},u>=s?(d.style.width=`${s}px`,d.style.left="0px",d.style.overflowX="scroll"):t+u-a>s?d.style.left=`${s-u-10}px`:d.style.left=`${t}px`,h>=l?(d.style.height=`${l-20}px`,d.style.top="10px",d.style.overflowY="scroll"):o+h-i>l?d.style.top=`${l-h}px`:d.style.top=`${o}px`}},[o,t,r,s,l,a,i]),W3(()=>{if(n){let d=u=>{m.current?.contains(u.target)||HW(()=>n(u))};return document.addEventListener("pointerdown",d,!1),()=>document.removeEventListener("pointerdown",d,!1)}},[n]),YW("div",{className:WW("popover",c),ref:m,tabIndex:-1,children:e})};import{jsx as gl,jsxs as KW}from"react/jsx-runtime";var vt="separator",$3=VW.memo(({actionManager:e,items:t,top:o,left:n,onClose:r})=>{let a=$o(),i=$r(),s=t.reduce((l,c)=>(c&&(c===vt||!c.predicate||c.predicate(i,a,e.app.props,e.app))&&l.push(c),l),[]);return gl(Y3,{onCloseRequest:()=>{r()},top:o,left:n,fitInViewport:!0,offsetLeft:a.offsetLeft,offsetTop:a.offsetTop,viewportWidth:a.width,viewportHeight:a.height,className:"context-menu-popover",children:gl("ul",{className:"context-menu",onContextMenu:l=>l.preventDefault(),children:s.map((l,c)=>{if(l===vt)return!s[c-1]||s[c-1]===vt?null:gl("hr",{className:"context-menu-item-separator"},c);let m=l.name,p="";return l.label&&(typeof l.label=="function"?p=f(l.label(i,a,e.app)):p=f(l.label)),gl("li",{"data-testid":m,onClick:()=>{r(()=>{e.executeAction(l,"contextMenu")})},children:KW("button",{type:"button",className:$W("context-menu-item",{dangerous:m==="deleteSelectedElements",checkmark:l.checked?.(a)}),children:[gl("div",{className:"context-menu-item__label",children:p}),gl("kbd",{className:"context-menu-item__shortcut",children:m?Xe(m):""})]})},c)})})})});import{jsx as sx,jsxs as V3}from"react/jsx-runtime";var XW=({height:e,width:t,userToFollow:o,onDisconnect:n})=>sx("div",{className:"follow-mode",style:{width:t,height:e},children:V3("div",{className:"follow-mode__badge",children:[V3("div",{className:"follow-mode__badge__label",children:["Following"," ",sx("span",{className:"follow-mode__badge__username",title:o.username,children:o.username})]}),sx("button",{type:"button",onClick:n,className:"follow-mode__disconnect-btn",children:Go})]})}),K3=XW;import Pi from"clsx";import oZ from"react";import{CLASSES as nZ,DEFAULT_SIDEBAR as v1,TOOL_TYPE as q4,arrayToMap as rZ,capitalizeString as aZ,isShallowEqual as Sg}from"@orangecatai/common";import{mutateElement as iZ}from"@orangecatai/element";import{showSelectedShapeActions as sZ}from"@orangecatai/element";import{ShapeCache as lZ}from"@orangecatai/element";import ZW from"clsx";import{useState as jW,useEffect as qW}from"react";import{THEME as JW}from"@orangecatai/common";import{jsx as lx,jsxs as QW}from"react/jsx-runtime";var Uu=({delay:e,theme:t})=>{let[o,n]=jW(!!e);return qW(()=>{if(!e)return;let r=setTimeout(()=>{n(!1)},e);return()=>clearTimeout(r)},[e]),o?null:QW("div",{className:ZW("LoadingMessage",{"LoadingMessage--dark":t===JW.DARK}),children:[lx("div",{children:lx(Wt,{})}),lx("div",{className:"LoadingMessage-text",children:f("labels.loadingScene")})]})};import eY from"clsx";import{jsx as Z3,jsxs as oY}from"react/jsx-runtime";var tY="medium",X3={CHECKED:ji,UNCHECKED:Wa},j3=e=>oY("label",{className:eY("ToolIcon ToolIcon__lock",`ToolIcon_size_${tY}`,{"is-mobile":e.isMobile}),title:`${e.title} \u2014 Q`,children:[Z3("input",{className:"ToolIcon_type_checkbox",type:"checkbox",name:e.name,onChange:e.onChange,checked:e.checked,"aria-label":e.title,"data-testid":"toolbar-lock"}),Z3("div",{className:"ToolIcon__icon",children:e.checked?X3.CHECKED:X3.UNCHECKED})]});import{useState as Wu,useEffect as Q3}from"react";import hl from"clsx";import{KEYS as cx,capitalizeString as Tt}from"@orangecatai/common";import nY from"clsx";import{KEYS as q3}from"@orangecatai/common";import{jsx as rY}from"react/jsx-runtime";var J3=e=>rY(ie,{className:nY("Shape",{fillable:!1,active:e.checked}),type:"radio",icon:as,name:"editor-current-shape",checked:e.checked,title:`${e.title} \u2014 H`,keyBindingLabel:e.isMobile?void 0:q3.H.toLocaleUpperCase(),"aria-label":`${e.title} \u2014 H`,"aria-keyshortcuts":q3.H,"data-testid":"toolbar-hand",onChange:()=>e.onChange?.()});import{Fragment as aY,jsx as It,jsxs as Yu}from"react/jsx-runtime";var dx=[{type:"rectangle",icon:qi,title:Tt(f("toolBar.rectangle"))},{type:"diamond",icon:Ji,title:Tt(f("toolBar.diamond"))},{type:"ellipse",icon:Qi,title:Tt(f("toolBar.ellipse"))}],mx=[{type:"selection",icon:Ya,title:Tt(f("toolBar.selection"))},{type:"lasso",icon:Hr,title:Tt(f("toolBar.lasso"))}],px=[{type:"arrow",icon:gm,title:Tt(f("toolBar.arrow"))},{type:"line",icon:es,title:Tt(f("toolBar.line"))}],eS=({app:e,onHandToolToggle:t,setAppState:o})=>{let n=e.state.activeTool,[r,a]=Wu(!1),[i,s]=Wu("rectangle"),[l,c]=Wu("arrow");Q3(()=>{(n.type==="rectangle"||n.type==="diamond"||n.type==="ellipse")&&s(n.type)},[n.type]),Q3(()=>{(n.type==="arrow"||n.type==="line")&&c(n.type)},[n.type]);let m=n.type==="frame",p=n.type==="laser",d=n.type==="embeddable",{TTDDialogTriggerTunnel:u}=Ze(),h=(M,B)=>{e.state.activeTool.type!==M&&be("toolbar",M,"ui"),M==="selection"?e.state.activeTool.type==="selection"||e.setActiveTool({type:"selection"}):e.setActiveTool({type:M})},[g,x]=Wu(0),E=36,y=4,w=7,v=w*E+(w-1)*y,I=E+y,C=g>=v+1*I,P=g>=v+2*I,S=g>=v+3*I,_=["text","frame","embeddable","laser","magicframe"].filter(M=>!(C&&M==="text"||P&&M==="image"||S&&M==="frame")).includes(n.type),k=_?n.type==="text"?Fn:n.type==="image"?ts:n.type==="frame"?On:n.type==="embeddable"?os:n.type==="laser"?zn:n.type==="magicframe"?Ka:ic:ic;return Yu("div",{className:"mobile-toolbar",ref:M=>{M&&x(M.getBoundingClientRect().width)},children:[It(J3,{checked:pr(e.state),onChange:t,title:f("toolBar.hand"),isMobile:!0}),It(Qs,{app:e,options:mx,activeTool:n,defaultOption:e.state.preferredSelectionTool.type,namePrefix:"selectionType",title:Tt(f("toolBar.selection")),"data-testid":"toolbar-selection",onToolChange:M=>{(M==="selection"||M==="lasso")&&(e.setActiveTool({type:M}),o({preferredSelectionTool:{type:M,initialized:!0}}))},displayedOption:mx.find(M=>M.type===e.state.preferredSelectionTool.type)||mx[0]}),It(ie,{className:hl({active:n.type==="freedraw"}),type:"radio",icon:Bn,checked:n.type==="freedraw",name:"editor-current-shape",title:`${Tt(f("toolBar.freedraw"))}`,"aria-label":Tt(f("toolBar.freedraw")),"data-testid":"toolbar-freedraw",onChange:()=>h("freedraw")}),It(ie,{className:hl({active:n.type==="eraser"}),type:"radio",icon:hm,checked:n.type==="eraser",name:"editor-current-shape",title:`${Tt(f("toolBar.eraser"))}`,"aria-label":Tt(f("toolBar.eraser")),"data-testid":"toolbar-eraser",onChange:()=>h("eraser")}),It(Qs,{app:e,options:dx,activeTool:n,defaultOption:i,namePrefix:"shapeType",title:Tt(f(i==="rectangle"?"toolBar.rectangle":i==="diamond"?"toolBar.diamond":i==="ellipse"?"toolBar.ellipse":"toolBar.rectangle")),"data-testid":"toolbar-rectangle",onToolChange:M=>{(M==="rectangle"||M==="diamond"||M==="ellipse")&&(s(M),e.setActiveTool({type:M}))},displayedOption:dx.find(M=>M.type===i)||dx[0]}),It(Qs,{app:e,options:px,activeTool:n,defaultOption:l,namePrefix:"linearElementType",title:Tt(f(l==="arrow"?"toolBar.arrow":"toolBar.line")),"data-testid":"toolbar-arrow",fillable:!0,onToolChange:M=>{(M==="arrow"||M==="line")&&(c(M),e.setActiveTool({type:M}))},displayedOption:px.find(M=>M.type===l)||px[0]}),C&&It(ie,{className:hl({active:n.type==="text"}),type:"radio",icon:Fn,checked:n.type==="text",name:"editor-current-shape",title:`${Tt(f("toolBar.text"))}`,"aria-label":Tt(f("toolBar.text")),"data-testid":"toolbar-text",onChange:()=>h("text")}),P&&It(ie,{className:hl({active:n.type==="image"}),type:"radio",icon:ts,checked:n.type==="image",name:"editor-current-shape",title:`${Tt(f("toolBar.image"))}`,"aria-label":Tt(f("toolBar.image")),"data-testid":"toolbar-image",onChange:()=>h("image")}),S&&It(ie,{className:hl({active:m}),type:"radio",icon:On,checked:m,name:"editor-current-shape",title:`${Tt(f("toolBar.frame"))}`,"aria-label":Tt(f("toolBar.frame")),"data-testid":"toolbar-frame",onChange:()=>h("frame")}),Yu(ye,{open:r,children:[It(ye.Trigger,{className:hl("App-toolbar__extra-tools-trigger App-toolbar__extra-tools-trigger--mobile",{"App-toolbar__extra-tools-trigger--selected":_||r}),onToggle:()=>{a(!r),o({openMenu:null,openPopup:null})},title:f("toolBar.extraTools"),style:{width:E,height:E,display:"flex",alignItems:"center",justifyContent:"center"},children:k}),Yu(ye.Content,{onClickOutside:()=>a(!1),onSelect:()=>a(!1),className:"App-toolbar__extra-tools-dropdown",align:"start",children:[!C&&It(ye.Item,{onSelect:()=>e.setActiveTool({type:"text"}),icon:Fn,shortcut:cx.T.toLocaleUpperCase(),"data-testid":"toolbar-text",selected:n.type==="text",children:f("toolBar.text")}),!P&&It(ye.Item,{onSelect:()=>e.setActiveTool({type:"image"}),icon:ts,"data-testid":"toolbar-image",selected:n.type==="image",children:f("toolBar.image")}),!S&&It(ye.Item,{onSelect:()=>e.setActiveTool({type:"frame"}),icon:On,shortcut:cx.F.toLocaleUpperCase(),"data-testid":"toolbar-frame",selected:m,children:f("toolBar.frame")}),It(ye.Item,{onSelect:()=>e.setActiveTool({type:"embeddable"}),icon:os,"data-testid":"toolbar-embeddable",selected:d,children:f("toolBar.embeddable")}),It(ye.Item,{onSelect:()=>e.setActiveTool({type:"laser"}),icon:zn,"data-testid":"toolbar-laser",selected:p,shortcut:cx.K.toLocaleUpperCase(),children:f("toolBar.laser")}),It("div",{style:{margin:"6px 0",fontSize:14,fontWeight:600},children:"Generate"}),e.props.aiEnabled!==!1&&It(u.Out,{}),It(ye.Item,{onSelect:()=>e.setOpenDialog({name:"ttd",tab:"mermaid"}),icon:ss,"data-testid":"toolbar-embeddable",children:f("toolBar.mermaidToExcalidraw")}),e.props.aiEnabled!==!1&&e.plugins.diagramToCode&&It(aY,{children:Yu(ye.Item,{onSelect:()=>e.onMagicframeToolSelect(),icon:Ka,"data-testid":"toolbar-magicframe",children:[f("toolBar.magicframe"),It(ye.Item.Badge,{children:"AI"})]})})]})]})]})};import iY from"clsx";import{jsx as sY}from"react/jsx-runtime";var $u=({children:e,side:t,className:o})=>sY("div",{className:iY("FixedSideContainer",`FixedSideContainer_side_${t}`,o),children:e});import lY from"clsx";import{jsx as tS,jsxs as dY}from"react/jsx-runtime";var cY="medium",Vu=e=>e.penDetected?dY("label",{className:lY("ToolIcon ToolIcon__penMode",`ToolIcon_size_${cY}`,{"is-mobile":e.isMobile}),title:`${e.title}`,children:[tS("input",{className:"ToolIcon_type_checkbox",type:"checkbox",name:e.name,onChange:e.onChange,checked:e.checked,"aria-label":e.title}),tS("div",{className:"ToolIcon__icon",children:BE})]}):null;import{Fragment as oS,jsx as Jn,jsxs as vi}from"react/jsx-runtime";var nS=({appState:e,elements:t,actionManager:o,setAppState:n,onHandToolToggle:r,renderTopLeftUI:a,renderTopRightUI:i,renderSidebars:s,renderWelcomeScreen:l,UIOptions:c,app:m,onPenModeToggle:p})=>{let{WelcomeScreenCenterTunnel:d,MainMenuTunnel:u,DefaultSidebarTriggerTunnel:h}=Ze(),g=()=>{if(e.openDialog?.name==="elementLinkSelector")return null;let E=vi("div",{className:"excalidraw-ui-top-right",children:[i?.(!0,e)??(!e.viewModeEnabled&&vi(oS,{children:[Jn(Vu,{checked:e.penMode,onChange:()=>p(null),title:f("toolBar.penMode"),isMobile:!0,penDetected:e.penDetected}),Jn(h.Out,{})]})),e.viewModeEnabled&&Jn(s5,{actionManager:o})]}),y=vi("div",{className:"excalidraw-ui-top-left",children:[a?.(!0,e),Jn(u.Out,{})]});return vi("div",{className:"App-toolbar-content",style:{display:"flex",flexDirection:"row",justifyContent:"space-between"},children:[y,E]})},x=()=>Jn(eS,{app:m,onHandToolToggle:r,setAppState:n});return vi(oS,{children:[s(),Jn("div",{className:"App-welcome-screen",children:l&&Jn(d.Out,{})}),!e.viewModeEnabled&&vi("div",{className:"App-bottom-bar",style:{marginBottom:Jo+Lr},children:[Jn(t5,{appState:e,elementsMap:m.scene.getNonDeletedElementsMap(),renderAction:o.renderAction,app:m,setAppState:n}),vi(gt,{className:"App-toolbar",children:[!e.viewModeEnabled&&e.openDialog?.name!=="elementLinkSelector"&&x(),e.scrolledOutside&&!e.openMenu&&!e.openSidebar&&Jn("button",{type:"button",className:"scroll-back-to-content",onClick:()=>{n(E=>({...Ha(t,E)}))},children:f("buttons.scrollBackToContent")})]})]}),Jn($u,{side:"top",className:"App-top-bar",children:g()})]})};import mY,{useLayoutEffect as pY,useRef as uY,useState as gY}from"react";import{jsx as ud,jsxs as hY}from"react/jsx-runtime";var rS=e=>{let t=uY(null),[o,n]=gY(null);return pY(()=>{if(!e.spreadsheet)return;let r=sI(e.chartType,e.spreadsheet,0,0);n(r);let a,i=t.current;return(async()=>(a=await Yi(r,{exportBackground:!1,viewBackgroundColor:"#fff"},null,{skipInliningFonts:!0}),a.querySelector(".style-fonts")?.remove(),i.replaceChildren(),i.appendChild(a),e.selected&&i.parentNode.focus()))(),()=>{i.replaceChildren()}},[e.spreadsheet,e.chartType,e.selected]),ud("button",{type:"button",className:"ChartPreview",onClick:()=>{o&&e.onClick(e.chartType,o)},children:ud("div",{ref:t})})},aS=({setAppState:e,appState:t,onClose:o})=>{let{onInsertElements:n}=tt(),r=mY.useCallback(()=>{o&&o()},[o]),a=(i,s)=>{n(s),be("paste","chart",i),e({currentChartType:i,pasteDialog:{shown:!1,data:null}})};return ud(bt,{size:"small",onCloseRequest:r,title:f("labels.pasteCharts"),className:"PasteChartDialog",autofocus:!1,children:hY("div",{className:"container",children:[ud(rS,{chartType:"bar",spreadsheet:t.pasteDialog.data,selected:t.currentChartType==="bar",onClick:a}),ud(rS,{chartType:"line",spreadsheet:t.pasteDialog.data,selected:t.currentChartType==="line",onClick:a})]})})};import{Fragment as fY,jsx as iS,jsxs as bY}from"react/jsx-runtime";var gd=({heading:e,children:t,...o})=>{let{id:n}=Qe(),r=iS("h2",{className:"visually-hidden",id:`${n}-${e}-title`,children:f(`headings.${e}`)});return iS("section",{...o,"aria-labelledby":`${n}-${e}-title`,children:typeof t=="function"?t(r):bY(fY,{children:[r,t]})})};import{Popover as Ku}from"radix-ui";import sS from"clsx";import Xu,{useLayoutEffect as xY}from"react";import{supportsResizeObserver as yY,isShallowEqual as EY}from"@orangecatai/common";import{Fragment as CY,jsx as Qn,jsxs as Zu}from"react/jsx-runtime";var wY=4,vY=8,IY=({shouldWrap:e,children:t,username:o})=>e?Qn(Xt,{label:o||"Unknown user",children:t}):Qn(CY,{children:t}),ux=({actionManager:e,collaborator:t,socketId:o,withName:n=!1,shouldWrapWithTooltip:r=!1,isBeingFollowed:a})=>{let i={socketId:o,collaborator:t,withName:n,isBeingFollowed:a},s=e.renderAction("goToCollaborator",i);return Qn(IY,{username:t.username,shouldWrap:r,children:s},o)},TY=["avatarUrl","id","socketId","username","isInCall","isSpeaking","isMuted"],ju=Xu.memo(({className:e,mobile:t,collaborators:o,userToFollow:n})=>{let r=at(),a=new Map;o.forEach((g,x)=>{let E=g.id||x;a.set(E,{...g,socketId:x})});let i=Array.from(a.values()).filter(g=>g.username?.trim()),[s,l]=Xu.useState(""),c=i.filter(g=>g.username?.toLowerCase().includes(s)),m=Xu.useRef(null);xY(()=>{if(m.current){let g=E=>{let y=Math.max(1,Math.min(8,Math.floor(E/38)));d(y)};if(g(m.current.clientWidth),!yY)return;let x=new ResizeObserver(E=>{for(let y of E){let{width:w}=y.contentRect;g(w)}});return x.observe(m.current),()=>{x.disconnect()}}},[]);let[p,d]=Xu.useState(wY),h=i.slice(0,p-1).map(g=>ux({actionManager:r,collaborator:g,socketId:g.socketId,shouldWrapWithTooltip:!0,isBeingFollowed:g.socketId===n}));return t?Qn("div",{className:sS("UserList UserList_mobile",e),children:i.map(g=>ux({actionManager:r,collaborator:g,socketId:g.socketId,shouldWrapWithTooltip:!0,isBeingFollowed:g.socketId===n}))}):Qn("div",{className:"UserList__wrapper",ref:m,children:Zu("div",{className:sS("UserList",e),style:{"--max-avatars":p},children:[h,i.length>p-1&&Zu(Ku.Root,{children:[Zu(Ku.Trigger,{className:"UserList__more",children:["+",i.length-p+1]}),Qn(Ku.Content,{style:{zIndex:2,width:"15rem",textAlign:"left"},align:"end",sideOffset:10,children:Zu(gt,{padding:2,children:[i.length>=vY&&Qn(Gm,{placeholder:f("quickSearch.placeholder"),onChange:l}),Qn(Um,{className:"dropdown-menu UserList__collaborators",placeholder:f("userList.empty"),children:c.length>0?[Qn("div",{className:"hint",children:f("userList.hint.text")}),c.map(g=>ux({actionManager:r,collaborator:g,socketId:g.socketId,withName:!0,isBeingFollowed:g.socketId===n}))]:[]}),Qn(Ku.Arrow,{width:20,height:10,style:{fill:"var(--popup-bg-color)",filter:"drop-shadow(rgba(0, 0, 0, 0.05) 0px 3px 2px)"}})]})})]})]})})},(e,t)=>{if(e.collaborators.size!==t.collaborators.size||e.mobile!==t.mobile||e.className!==t.className||e.userToFollow!==t.userToFollow)return!1;let o=t.collaborators.keys();for(let[n,r]of e.collaborators){let a=t.collaborators.get(n);if(!a||n!==o.next().value||!EY(r,a,TY))return!1}return!0});import xx from"clsx";import{useState as NY,useRef as cS,useEffect as BY,useCallback as FY}from"react";import{useCallback as Eo,useEffect as PY,useRef as fd,useState as hx}from"react";var gx=({h:e,s:t,v:o,a:n})=>{e=e/360,t=t/100,o=o/100;let r=0,a=0,i=0,s=Math.floor(e*6),l=e*6-s,c=o*(1-t),m=o*(1-l*t),p=o*(1-(1-l)*t);switch(s%6){case 0:r=o,a=p,i=c;break;case 1:r=m,a=o,i=c;break;case 2:r=c,a=o,i=p;break;case 3:r=c,a=m,i=o;break;case 4:r=p,a=c,i=o;break;case 5:r=o,a=c,i=m;break}return{r:Math.round(r*255),g:Math.round(a*255),b:Math.round(i*255),a:n}},kY=({r:e,g:t,b:o,a:n})=>{e/=255,t/=255,o/=255;let r=Math.max(e,t,o),a=Math.min(e,t,o),i=r-a,s=0,l=r===0?0:i/r*100,c=r*100;if(i!==0)switch(r){case e:s=((t-o)/i+(t<o?6:0))*60;break;case t:s=((o-e)/i+2)*60;break;case o:s=((e-t)/i+4)*60;break}return{h:s,s:l,v:c,a:n}},SY=({r:e,g:t,b:o,a:n})=>{let r=i=>i.toString(16).padStart(2,"0"),a=`#${r(e)}${r(t)}${r(o)}`;return n<1?`${a}${r(Math.round(n*255))}`:a},MY=e=>{let t=e.replace(/^#/,"");t.length===3?t=t[0]+t[0]+t[1]+t[1]+t[2]+t[2]:t.length===4&&(t=t[0]+t[0]+t[1]+t[1]+t[2]+t[2]+t[3]+t[3]);let o=parseInt(t.slice(0,2),16),n=parseInt(t.slice(2,4),16),r=parseInt(t.slice(4,6),16),a=t.length===8?parseInt(t.slice(6,8),16)/255:1;return{r:isNaN(o)?0:o,g:isNaN(n)?0:n,b:isNaN(r)?0:r,a:isNaN(a)?1:a}},qu=e=>SY(gx(e)),hd=e=>kY(MY(e));var fl=(e,t,o)=>Math.max(t,Math.min(o,e));import{jsx as Pt,jsxs as bl}from"react/jsx-runtime";var AY=["transparent","#000000","#ffffff","#00e639","#a855f4","#d4b0ff"],fx=(e,t)=>{let o=fd(null),n=fd(!1),r=fd(null),a=fd(null),i=Eo((p,d)=>{if(!o.current||!n.current)return;let u=o.current.getBoundingClientRect();e(p,d,u)},[e]),s=Eo(()=>{n.current=!1,t?.(),r.current&&(window.removeEventListener("mousemove",r.current),r.current=null),a.current&&(window.removeEventListener("touchmove",a.current),a.current=null),window.removeEventListener("mouseup",s),window.removeEventListener("touchend",s)},[t]),l=Eo(p=>i(p.clientX,p.clientY),[i]),c=Eo(p=>{p.preventDefault(),i(p.touches[0].clientX,p.touches[0].clientY)},[i]),m=Eo(p=>{p.preventDefault(),p.stopPropagation(),n.current=!0;let d="touches"in p?p.touches[0].clientX:p.clientX,u="touches"in p?p.touches[0].clientY:p.clientY;if(o.current){let h=o.current.getBoundingClientRect();e(d,u,h)}r.current=l,a.current=c,window.addEventListener("mousemove",l),window.addEventListener("mouseup",s),window.addEventListener("touchmove",c,{passive:!1}),window.addEventListener("touchend",s)},[e,l,c,s]);return{ref:o,handleDown:m}},LY=({hsva:e,onChange:t})=>{let{ref:o,handleDown:n}=fx((s,l,c)=>{let m=fl(s-c.left,0,c.width),p=fl(l-c.top,0,c.height),d=m/c.width*100,u=100-p/c.height*100;t(d,u)}),r=`hsl(${e.h}, 100%, 50%)`,a=`${e.s}%`,i=`${100-e.v}%`;return bl("div",{ref:o,className:"adv-cp__saturation",style:{backgroundColor:r},onMouseDown:n,onTouchStart:n,children:[Pt("div",{className:"adv-cp__saturation-white"}),Pt("div",{className:"adv-cp__saturation-black"}),Pt("div",{className:"adv-cp__handle",style:{left:a,top:i}})]})},_Y=({hue:e,onChange:t})=>{let{ref:o,handleDown:n}=fx((r,a,i)=>{let s=fl(r-i.left,0,i.width);t(s/i.width*360)});return Pt("div",{ref:o,className:"adv-cp__slider adv-cp__hue-slider",onMouseDown:n,onTouchStart:n,children:Pt("div",{className:"adv-cp__slider-handle",style:{left:`${e/360*100}%`}})})},DY=({hsva:e,onChange:t})=>{let{r:o,g:n,b:r}=gx({...e,a:1}),a=`rgba(${o}, ${n}, ${r}, 1)`,{ref:i,handleDown:s}=fx((l,c,m)=>{let p=fl(l-m.left,0,m.width);t(p/m.width)});return bl("div",{ref:i,className:"adv-cp__slider adv-cp__alpha-slider",onMouseDown:s,onTouchStart:s,children:[Pt("div",{className:"adv-cp__alpha-checker"}),Pt("div",{className:"adv-cp__alpha-gradient",style:{background:`linear-gradient(to right, transparent 0%, ${a} 100%)`}}),Pt("div",{className:"adv-cp__slider-handle",style:{left:`${e.a*100}%`}})]})},RY=({activeColor:e,onChange:t})=>Pt("div",{className:"adv-cp__presets",children:AY.map(o=>Pt("button",{type:"button",className:`adv-cp__preset-btn${o===e?" active":""}${o==="transparent"?" is-transparent":""}`,style:o!=="transparent"?{backgroundColor:o}:void 0,title:o,onClick:()=>t(o),children:o==="transparent"&&Pt("div",{className:"adv-cp__preset-slash"})},o))}),lS=({color:e,onChange:t,showAlpha:o=!0})=>{let[n,r]=hx(()=>!e||e==="transparent"?{h:0,s:0,v:100,a:e==="transparent"?0:1}:hd(e)),[a,i]=hx(()=>e==="transparent"?"000000":(e||"#ffffff").replace(/^#/,"").toUpperCase()),[s,l]=hx(()=>Math.round(n.a*100).toString()),c=fd(e);PY(()=>{if(e!==c.current)if(c.current=e,!e||e==="transparent")r({h:0,s:0,v:100,a:0}),i("000000"),l("0");else{let w=hd(e);r(w),i(e.replace(/^#/,"").substring(0,6).toUpperCase()),l(Math.round(w.a*100).toString())}},[e]);let m=Eo(w=>{r(w);let v=qu(w);c.current=v,i(v.replace(/^#/,"").substring(0,6).toUpperCase()),l(Math.round(w.a*100).toString()),w.a===0?t("transparent"):t(v)},[t]),p=Eo((w,v)=>{m({...n,s:w,v})},[n,m]),d=Eo(w=>{m({...n,h:w})},[n,m]),u=Eo(w=>{m({...n,a:w})},[n,m]),h=Eo(w=>{if(w==="transparent")m({h:0,s:0,v:100,a:0});else{let v=hd(w);v.a=1,m(v)}},[m]),g=Eo(()=>{let w=a.trim().replace(/^#/,"");if(/^[0-9a-fA-F]{3}$|^[0-9a-fA-F]{6}$|^[0-9a-fA-F]{8}$/.test(w)){let v=hd(`#${w}`);m(v)}else{let v=qu(n);i(v.replace(/^#/,"").substring(0,6).toUpperCase())}},[a,n,m]),x=Eo(w=>{w.key==="Enter"&&g(),w.stopPropagation()},[g]),E=Eo(()=>{let w=parseInt(s,10);if(isNaN(w))l(Math.round(n.a*100).toString());else{let v=fl(w,0,100)/100;m({...n,a:v})}},[s,n,m]),y=Eo(w=>{w.key==="Enter"&&E(),w.stopPropagation()},[E]);return bl("div",{className:"adv-cp",children:[Pt(LY,{hsva:n,onChange:p}),Pt(_Y,{hue:n.h,onChange:d}),o&&Pt(DY,{hsva:n,onChange:u}),Pt(RY,{activeColor:n.a===0?"transparent":qu({...n,a:1}).toLowerCase(),onChange:h}),bl("div",{className:"adv-cp__inputs",children:[bl("div",{className:"adv-cp__hex-input",children:[Pt("span",{className:"adv-cp__hash",children:"#"}),Pt("input",{type:"text",style:{border:0,padding:0,margin:0,outline:"none"},spellCheck:!1,value:a,onChange:w=>i(w.target.value.toUpperCase()),onBlur:g,onKeyDown:x,maxLength:8,"aria-label":"Hex color"})]}),o&&bl("div",{className:"adv-cp__alpha-input",children:[Pt("input",{type:"text",style:{border:0,padding:0,margin:0,outline:"none"},value:s,onChange:w=>l(w.target.value),onBlur:E,onKeyDown:y,maxLength:3,"aria-label":"Opacity percentage"}),Pt("span",{className:"adv-cp__percent",children:"%"})]})]})]})};import{jsx as fa,jsxs as bx}from"react/jsx-runtime";var dS=({actionManager:e,appState:t})=>{let[o,n]=NY(!1),r=cS(null),a=cS(null);BY(()=>{if(!o)return;let c=m=>{r.current&&!r.current.contains(m.target)&&a.current&&!a.current.contains(m.target)&&n(!1)};return document.addEventListener("mousedown",c),()=>document.removeEventListener("mousedown",c)},[o]);let i=t.viewBackgroundColor||"#ffffff",s=i==="transparent",l=FY(c=>{e.executeAction(e.actions.changeViewBackgroundColor,"ui",{viewBackgroundColor:c})},[e]);return bx("div",{className:"canvas-bg-swatch-wrapper",children:[fa(Xt,{label:f("labels.canvasBackground"),children:fa("button",{ref:a,type:"button",className:"canvas-bg-swatch",onClick:()=>n(c=>!c),title:f("labels.canvasBackground"),children:fa("div",{className:"canvas-bg-swatch__color",style:{backgroundColor:s?void 0:i},children:s&&fa("div",{className:"canvas-bg-swatch__transparent"})})})}),o&&bx("div",{ref:r,className:"canvas-bg-swatch__popover",children:[bx("div",{className:"canvas-bg-swatch__popover-header",children:[fa("span",{children:f("labels.canvasBackground")}),fa("button",{type:"button",className:"canvas-bg-swatch__close",onClick:()=>n(!1),children:"\u2715"})]}),fa("div",{className:"canvas-bg-swatch__picker-content",children:fa(lS,{color:i,onChange:l,showAlpha:!0})})]})]})};import{jsx as OY}from"react/jsx-runtime";var mS=e=>OY("button",{className:"help-icon",onClick:e.onClick,type:"button",title:`${f("helpDialog.title")} \u2014 ?`,"aria-label":f("helpDialog.title"),children:ns});import{jsx as en,jsxs as bd}from"react/jsx-runtime";var pS=({appState:e,actionManager:t,showExitZenModeBtn:o,renderWelcomeScreen:n})=>{let{FooterCenterTunnel:r,WelcomeScreenHelpHintTunnel:a}=Ze();return bd("footer",{role:"contentinfo",className:"layer-ui__wrapper__footer App-menu App-menu_bottom",children:[en("div",{className:xx("layer-ui__wrapper__footer-left zen-mode-transition",{"layer-ui__wrapper__footer-left--transition-left":e.zenModeEnabled}),children:en(Rt.Col,{gap:2,children:en(gd,{heading:"canvasActions",children:bd(Rt.Col,{gap:1,className:"footer-canvas-actions",children:[bd(Rt.Row,{align:"center",gap:1,children:[en(n5,{renderAction:t.renderAction}),!e.viewModeEnabled&&en(dS,{actionManager:t,appState:e})]}),bd(Rt.Row,{align:"center",gap:1,className:"footer-canvas-actions-row",children:[en(r5,{renderAction:t.renderAction,zoom:e.zoom}),!e.viewModeEnabled&&en(a5,{renderAction:t.renderAction,className:xx("zen-mode-transition",{"layer-ui__wrapper__footer-left--transition-bottom":e.zenModeEnabled})})]})]})})})}),en(r.Out,{}),en("div",{className:xx("layer-ui__wrapper__footer-right zen-mode-transition",{"transition-right":e.zenModeEnabled}),children:bd("div",{style:{position:"relative"},children:[n&&en(a.Out,{}),en(mS,{onClick:()=>t.executeAction(oi)})]})}),en(i5,{actionManager:t,showExitZenModeBtn:o})]})},uS=pS;pS.displayName="Footer";import jY from"clsx";import{useEffect as ES,useLayoutEffect as wS,useRef as Sx,useState as qY,forwardRef as vS,useImperativeHandle as JY,useCallback as bS}from"react";import{CLASSES as QY,EVENT as xS,isDevEnv as e$,KEYS as t$,updateObject as o$}from"@orangecatai/common";import HY from"clsx";import{useContext as GY}from"react";import zY from"react";var Ju=zY.createContext({});import{jsx as yx,jsxs as gS}from"react/jsx-runtime";var Ex=({children:e,className:t})=>{let o=Te(),n=GY(Ju),r=!!(o.canFitSidebar&&n.shouldRenderDockButton);return gS("div",{className:HY("sidebar__header",t),"data-testid":"sidebar-header",children:[e,gS("div",{className:"sidebar__header__buttons",children:[r&&yx(Xt,{label:f("labels.sidebarLock"),children:yx(so,{onSelect:()=>n.onDock?.(!n.docked),selected:!!n.docked,className:"sidebar__dock","data-testid":"sidebar-dock","aria-label":f("labels.sidebarLock"),children:LE})}),yx(so,{"data-testid":"sidebar-close",className:"sidebar__close",onSelect:n.onCloseRequest,"aria-label":f("buttons.close"),children:Go})]})]})};Ex.displayName="SidebarHeader";import{Tabs as UY}from"radix-ui";import{jsx as hS}from"react/jsx-runtime";var wx=({children:e,tab:t,onSelect:o,...n})=>hS(UY.Trigger,{value:t,asChild:!0,onSelect:o,children:hS("button",{type:"button",className:"excalidraw-button sidebar-tab-trigger",...n,children:e})});wx.displayName="SidebarTabTrigger";import{Tabs as WY}from"radix-ui";import{jsx as YY}from"react/jsx-runtime";var vx=({children:e,...t})=>YY(WY.List,{className:"sidebar-triggers",...t,children:e});vx.displayName="SidebarTabTriggers";import $Y from"clsx";import{jsx as Ix,jsxs as fS}from"react/jsx-runtime";var Tx=({name:e,tab:t,icon:o,title:n,children:r,onToggle:a,className:i,style:s})=>{let l=Ce(),c=Ie();return fS("label",{title:n,className:"sidebar-trigger__label-element",children:[Ix("input",{className:"ToolIcon_type_checkbox",type:"checkbox",onChange:m=>{document.querySelector(".layer-ui__wrapper")?.classList.remove("animate");let p=m.target.checked;l({openSidebar:p?{name:e,tab:t}:null,openMenu:null,openPopup:null}),a?.(p)},checked:c.openSidebar?.name===e,"aria-label":n,"aria-keyshortcuts":"0"}),fS("div",{className:$Y("sidebar-trigger",i),style:s,children:[o&&Ix("div",{children:o}),r&&Ix("div",{className:"sidebar-trigger__label",children:r})]})]})};Tx.displayName="SidebarTrigger";import{Tabs as VY}from"radix-ui";import{jsx as KY}from"react/jsx-runtime";var Cx=({children:e,...t})=>{let o=Ie(),n=Ce();if(!o.openSidebar)return null;let{name:r}=o.openSidebar;return KY(VY.Root,{className:"sidebar-tabs-root",value:o.openSidebar.tab,onValueChange:a=>n(i=>({...i,openSidebar:{...i.openSidebar,name:r,tab:a}})),...t,children:e})};Cx.displayName="SidebarTabs";import{Tabs as XY}from"radix-ui";import{jsx as ZY}from"react/jsx-runtime";var kx=({tab:e,children:t,...o})=>ZY(XY.Content,{...o,value:e,"data-testid":e,children:t});kx.displayName="SidebarTab";import{jsx as yS}from"react/jsx-runtime";import{createElement as n$}from"react";var xd=Pe(!1),IS=vS(({name:e,children:t,onDock:o,docked:n,className:r,...a},i)=>{e$()&&o&&n==null&&console.warn("Sidebar: `docked` must be set when `onDock` is supplied for the sidebar to be user-dockable. To hide this message, either pass `docked` or remove `onDock`");let s=Ce(),l=Rn(xd);wS(()=>(l(!!n),()=>{l(!1)}),[l,n]);let c=Sx({});c.current.onCloseRequest=()=>{s({openSidebar:null})},c.current.onDock=u=>o?.(u),c.current=o$(c.current,{docked:n,shouldRenderDockButton:!!o&&n!=null});let m=Sx(null);JY(i,()=>m.current);let p=Te(),d=bS(()=>{document.querySelector(".Dialog")||s({openSidebar:null})},[s]);return fs(m,bS(u=>{u.target.closest(".sidebar-trigger")||(!n||!p.canFitSidebar)&&d()},[d,n,p.canFitSidebar])),ES(()=>{let u=h=>{h.key===t$.ESCAPE&&(!n||!p.canFitSidebar)&&d()};return document.addEventListener(xS.KEYDOWN,u),()=>{document.removeEventListener(xS.KEYDOWN,u)}},[d,n,p.canFitSidebar]),yS(gt,{...a,className:jY(QY.SIDEBAR,{"sidebar--docked":n},r),ref:m,children:yS(Ju.Provider,{value:c.current,children:t})})});IS.displayName="SidebarInner";var tn=Object.assign(vS((e,t)=>{let o=Ie()??{openSidebar:null},{onStateChange:n}=e,r=Sx(o.openSidebar);ES(()=>{(!o.openSidebar&&r?.current?.name===e.name||o.openSidebar?.name===e.name&&r?.current?.name!==e.name||r.current?.name===e.name)&&o.openSidebar!==r.current&&n?.(o.openSidebar?.name!==e.name?null:o.openSidebar),r.current=o.openSidebar},[o.openSidebar,n,e.name]);let[a,i]=qY(!1);return wS(()=>(i(!0),()=>i(!1)),[]),a&&o.openSidebar?.name===e.name?n$(IS,{...e,ref:t,key:e.name}):null}),{Header:Ex,TabTriggers:vx,TabTrigger:wx,Tabs:Cx,Tab:kx,Trigger:Tx});tn.displayName="Sidebar";import{composeEventHandlers as m$}from"@orangecatai/common";import{useLayoutEffect as r$,useRef as a$}from"react";import{jsx as i$}from"react/jsx-runtime";var _r=(e,t)=>{let o=Pe(0),n=r=>{let{tunnelsJotai:{useAtom:a}}=Ze(),[,i]=a(o),s=a$({preferHost:!1,counter:0});return r$(()=>{let l=s.current;return i(c=>{let m=c+1;return l.counter=m,m}),()=>{i(c=>{let m=c-1;return l.counter=m,m||(l.preferHost=!1),m})}},[i]),r.__fallback||(s.current.preferHost=!0),!s.current.counter&&r.__fallback&&s.current.preferHost||s.current.counter>1&&r.__fallback?null:i$(t,{...r})};return n.displayName=e,n};var _x={};eE(_x,{ChangeCanvasBackground:()=>FS,ClearCanvas:()=>NS,CommandPalette:()=>_S,Export:()=>OS,Help:()=>RS,LiveCollaborationTrigger:()=>HS,LoadScene:()=>PS,Preferences:()=>xa,PreferencesToggleGridModeItem:()=>Ax,PreferencesToggleZenModeItem:()=>Lx,SaveAsImage:()=>LS,SaveToActiveFile:()=>AS,SearchMenu:()=>DS,Socials:()=>zS,ToggleTheme:()=>BS});import d$ from"clsx";import{THEME as ba}from"@orangecatai/common";var Mx=Pe({active:!1});async function TS({title:e,description:t,actionLabel:o,color:n}){return new Promise(r=>{Et.set(Mx,{active:!0,onConfirm:()=>r(!0),onClose:()=>r(!1),onReject:()=>r(!1),title:e,description:t,actionLabel:o,color:n})})}import s$ from"clsx";import{jsx as CS,jsxs as l$}from"react/jsx-runtime";var Qu=function({onChange:e,value:t,choices:o,name:n}){return CS("div",{className:"RadioGroup",children:o.map(r=>l$("div",{className:s$("RadioGroup__choice",{active:r.value===t}),title:r.ariaLabel,children:[CS("input",{name:n,type:"radio",checked:r.value===t,onChange:()=>e(r.value),"aria-label":r.ariaLabel}),r.label]},String(r.value)))})};import{Fragment as c$,jsx as Px,jsxs as kS}from"react/jsx-runtime";var SS=({value:e,shortcut:t,onChange:o,choices:n,children:r,name:a})=>{let i=Te();return kS(c$,{children:[kS("div",{className:"dropdown-menu-item-base dropdown-menu-item-bare",children:[Px("label",{className:"dropdown-menu-item__text",children:r}),Px(Qu,{name:a,value:e,onChange:o,choices:n})]}),t&&i.formFactor!=="phone"&&Px("div",{className:"dropdown-menu-item__shortcut dropdown-menu-item__shortcut--orphaned",children:t})]})};SS.displayName="DropdownMenuItemContentRadio";var MS=SS;import{Fragment as $S,jsx as Fe,jsxs as yd}from"react/jsx-runtime";var PS=()=>{let{t:e}=Ue(),t=at(),o=$r();return t.isActionEnabled(_s)?Fe(to,{icon:rs,onSelect:async()=>{(!o.length||await TS({title:e("overwriteConfirm.modal.loadFromFile.title"),actionLabel:e("overwriteConfirm.modal.loadFromFile.button"),color:"warning",description:Fe(io,{i18nKey:"overwriteConfirm.modal.loadFromFile.description",bold:r=>Fe("strong",{children:r}),br:()=>Fe("br",{})})}))&&t.executeAction(_s)},"data-testid":"load-button",shortcut:Xe("loadScene"),"aria-label":e("buttons.load"),children:e("buttons.load")}):null};PS.displayName="LoadScene";var AS=()=>{let{t:e}=Ue(),t=at();return t.isActionEnabled(ti)?Fe(to,{shortcut:Xe("saveScene"),"data-testid":"save-button",onSelect:()=>t.executeAction(ti),icon:WE,"aria-label":`${e("buttons.save")}`,children:`${e("buttons.save")}`}):null};AS.displayName="SaveToActiveFile";var LS=()=>{let e=Ce(),{t}=Ue();return Fe(to,{icon:ym,"data-testid":"image-export-button",onSelect:()=>e({openDialog:{name:"imageExport"}}),shortcut:Xe("imageExport"),"aria-label":t("buttons.exportImage"),children:t("buttons.exportImage")})};LS.displayName="SaveAsImage";var _S=e=>{let t=Ce(),{t:o}=Ue();return Fe(to,{icon:sc,"data-testid":"command-palette-button",onSelect:()=>{be("command_palette","open","menu"),t({openDialog:{name:"commandPalette"}})},shortcut:Xe("commandPalette"),"aria-label":o("commandPalette.title"),className:e?.className,children:o("commandPalette.title")})};_S.displayName="CommandPalette";var DS=e=>{let{t}=Ue(),o=at();return Fe(to,{icon:Mo,"data-testid":"search-menu-button",onSelect:()=>{o.executeAction(Zc)},shortcut:Xe("searchMenu"),"aria-label":t("search.title"),className:e?.className,children:t("search.title")})};DS.displayName="SearchMenu";var RS=()=>{let{t:e}=Ue(),t=at();return Fe(to,{"data-testid":"help-menu-item",icon:ns,onSelect:()=>t.executeAction(oi),shortcut:"?","aria-label":e("helpDialog.title"),children:e("helpDialog.title")})};RS.displayName="Help";var NS=()=>{let{t:e}=Ue(),t=Rn(si);return at().isActionEnabled(yr)?Fe(to,{icon:Ut,onSelect:()=>t("clearCanvas"),"data-testid":"clear-canvas-button","aria-label":e("buttons.clearReset"),children:e("buttons.clearReset")}):null};NS.displayName="ClearCanvas";var BS=e=>{let{t}=Ue(),o=Ie(),n=at(),r=Xe("toggleTheme");return n.isActionEnabled(qa)?e?.allowSystemTheme?Fe(MS,{name:"theme",value:e.theme,onChange:a=>e.onSelect(a),choices:[{value:ba.LIGHT,label:nc,ariaLabel:`${t("buttons.lightMode")} - ${r}`},{value:ba.DARK,label:oc,ariaLabel:`${t("buttons.darkMode")} - ${r}`},{value:"system",label:sv,ariaLabel:t("buttons.systemMode")}],children:t("labels.theme")}):Fe(to,{onSelect:a=>{if(a.preventDefault(),e?.onSelect)e.onSelect(o.theme===ba.DARK?ba.LIGHT:ba.DARK);else return n.executeAction(qa)},icon:o.theme===ba.DARK?nc:oc,"data-testid":"toggle-dark-mode",shortcut:r,"aria-label":o.theme===ba.DARK?t("buttons.lightMode"):t("buttons.darkMode"),children:o.theme===ba.DARK?t("buttons.lightMode"):t("buttons.darkMode")}):null};BS.displayName="ToggleTheme";var FS=()=>{let{t:e}=Ue(),t=Ie(),o=at(),n=Hn();return t.viewModeEnabled||!n.UIOptions.canvasActions.changeViewBackgroundColor?null:yd("div",{style:{marginTop:"0.75rem"},children:[Fe("div",{"data-testid":"canvas-background-label",style:{fontSize:"0.875rem",marginBottom:"0.25rem",marginLeft:"0.5rem"},children:e("labels.canvasBackground")}),Fe("div",{style:{padding:"0 0.625rem"},children:o.renderAction("changeViewBackgroundColor")})]})};FS.displayName="ChangeCanvasBackground";var OS=()=>{let{t:e}=Ue(),t=Ce();return Fe(to,{icon:$a,onSelect:()=>{t({openDialog:{name:"jsonExport"}})},"data-testid":"json-export-button","aria-label":e("buttons.export"),children:e("buttons.export")})};OS.displayName="Export";var zS=()=>{let{t:e}=Ue();return yd($S,{children:[Fe(qs,{icon:fm,href:"https://github.com/excalidraw/excalidraw","aria-label":"GitHub",children:"GitHub"}),Fe(qs,{icon:UE,href:"https://x.com/excalidraw","aria-label":"X",children:e("labels.followUs")}),Fe(qs,{icon:GE,href:"https://discord.gg/UexuTaE","aria-label":"Discord",children:e("labels.discordChat")})]})};zS.displayName="Socials";var HS=({onSelect:e,isCollaborating:t})=>{let{t:o}=Ue();return Fe(to,{"data-testid":"collab-button",icon:Em,className:d$({"active-collab":t}),onSelect:e,children:o("labels.liveCollaboration")})};HS.displayName="LiveCollaborationTrigger";var GS=()=>{let{t:e}=Ue(),t=tt(),o=Ie();return Fe(Ir,{checked:o.activeTool.locked,shortcut:Xe("toolLock"),onSelect:n=>{t.toggleLock(),n.preventDefault()},children:e("labels.preferences_toolLock")})},US=()=>{let{t:e}=Ue(),t=at(),o=Ie();return Fe(Ir,{checked:o.objectsSnapModeEnabled,shortcut:Xe("objectsSnapMode"),onSelect:n=>{t.executeAction(_c),n.preventDefault()},children:e("buttons.objectsSnapMode")})},Ax=()=>{let{t:e}=Ue(),t=at(),o=Ie();return Fe(Ir,{checked:o.gridModeEnabled,shortcut:Xe("gridMode"),onSelect:n=>{t.executeAction(zs),n.preventDefault()},children:e("labels.toggleGrid")})},Lx=()=>{let{t:e}=Ue(),t=at(),o=Ie();return Fe(Ir,{checked:o.zenModeEnabled,shortcut:Xe("zenMode"),onSelect:n=>{t.executeAction(ta),n.preventDefault()},children:e("buttons.zenMode")})},WS=()=>{let{t:e}=Ue(),t=at(),o=Ie();return Fe(Ir,{checked:o.viewModeEnabled,shortcut:Xe("viewMode"),onSelect:n=>{t.executeAction(ii),n.preventDefault()},children:e("labels.viewMode")})},YS=()=>{let{t:e}=Ue(),t=at(),o=Ie();return Fe(Ir,{checked:o.stats.open,shortcut:Xe("stats"),onSelect:n=>{t.executeAction(oa),n.preventDefault()},children:e("stats.fullTitle")})},xa=({children:e,additionalItems:t})=>{let{t:o}=Ue();return yd(aa,{children:[Fe(aa.Trigger,{icon:yv,children:o("labels.preferences")}),yd(aa.Content,{className:"excalidraw-main-menu-preferences-submenu",children:[e||yd($S,{children:[Fe(GS,{}),Fe(US,{}),Fe(Ax,{}),Fe(Lx,{}),Fe(WS,{}),Fe(YS,{})]}),t]})]})};xa.ToggleToolLock=GS;xa.ToggleSnapMode=US;xa.ToggleGridMode=Ax;xa.ToggleZenMode=Lx;xa.ToggleViewMode=WS;xa.ToggleElementProperties=YS;xa.displayName="Preferences";import{jsx as eg,jsxs as Dx}from"react/jsx-runtime";var p$=Object.assign(_r("MainMenu",({children:e,onSelect:t})=>{let{MainMenuTunnel:o}=Ze(),n=Te(),r=Ie(),a=Ce();return eg(o.In,{children:Dx(ye,{open:r.openMenu==="canvas",children:[eg(ye.Trigger,{onToggle:()=>{a({openMenu:r.openMenu==="canvas"?null:"canvas",openPopup:null,openDialog:null})},"data-testid":"main-menu-trigger",className:"main-menu-trigger",children:zE}),Dx(ye.Content,{onClickOutside:()=>a({openMenu:null}),onSelect:m$(t,()=>{a({openMenu:null})}),className:"main-menu",align:"start",children:[e,n.formFactor==="phone"&&r.collaborators.size>0&&Dx("fieldset",{className:"UserList-Wrapper",children:[eg("legend",{children:f("labels.collaborators")}),eg(ju,{mobile:!0,collaborators:r.collaborators,userToFollow:r.userToFollow?.socketId||null})]})]})]})})}),{Trigger:ye.Trigger,Item:ye.Item,ItemLink:ye.ItemLink,ItemCustom:ye.ItemCustom,Group:ye.Group,Separator:ye.Separator,Sub:aa,DefaultItems:_x}),jt=p$;import u$ from"clsx";import{forwardRef as g$,useState as h$}from"react";import{isPromiseLike as f$}from"@orangecatai/common";import{jsx as tg,jsxs as b$}from"react/jsx-runtime";var on=g$(({children:e,icon:t,onClick:o,label:n,variant:r="filled",color:a="primary",size:i="medium",fullWidth:s,className:l,status:c,disabled:m},p)=>{let[d,u]=h$(!1),h=async x=>{let E=o?.(x);if(f$(E)){let y=window.setTimeout(()=>{u(!0)},50);try{await E}catch(w){if(w instanceof Ui)console.warn(w);else throw w}finally{clearTimeout(y),u(!1)}}},g=d?"loading":c;return a=g==="success"?"success":a,tg("button",{className:u$("ExcButton",`ExcButton--color-${a}`,`ExcButton--variant-${r}`,`ExcButton--size-${i}`,`ExcButton--status-${g}`,{"ExcButton--fullWidth":s},l),onClick:h,type:"button","aria-label":n,ref:p,disabled:m||g==="loading"||g==="success",children:b$("div",{className:"ExcButton__contents",children:[g==="loading"?tg(Wt,{className:"ExcButton__statusIcon"}):g==="success"&&tg("div",{className:"ExcButton__statusIcon",children:Hw}),t&&tg("div",{className:"ExcButton__icon","aria-hidden":!0,children:t}),r!=="icon"&&(e??n)]})})});import{jsx as xl,jsxs as E$}from"react/jsx-runtime";var og=({title:e,children:t,actionLabel:o,onClick:n})=>E$("div",{className:"OverwriteConfirm__Actions__Action",children:[xl("h4",{children:e}),xl("div",{className:"OverwriteConfirm__Actions__Action__content",children:t}),xl(on,{variant:"outlined",color:"muted",label:o,size:"large",fullWidth:!0,onClick:n})]}),x$=()=>{let{t:e}=Ue(),t=at(),o=Ce();return xl(og,{title:e("overwriteConfirm.action.exportToImage.title"),actionLabel:e("overwriteConfirm.action.exportToImage.button"),onClick:()=>{t.executeAction(cp,"ui",!0),o({openDialog:{name:"imageExport"}})},children:e("overwriteConfirm.action.exportToImage.description")})},y$=()=>{let{t:e}=Ue(),t=at();return xl(og,{title:e("overwriteConfirm.action.saveToDisk.title"),actionLabel:e("overwriteConfirm.action.saveToDisk.button"),onClick:()=>{t.executeAction(Ac,"ui")},children:e("overwriteConfirm.action.saveToDisk.description")})},Rx=Object.assign(({children:e})=>xl("div",{className:"OverwriteConfirm__Actions",children:e}),{ExportToImage:x$,SaveToDisk:y$});import{jsx as ya,jsxs as VS}from"react/jsx-runtime";var ng=Object.assign(_r("OverwriteConfirmDialog",({children:e})=>{let{OverwriteConfirmDialogTunnel:t}=Ze(),[o,n]=le(Mx);if(!o.active)return null;let r=()=>{o.onClose(),n(i=>({...i,active:!1}))},a=()=>{o.onConfirm(),n(i=>({...i,active:!1}))};return ya(t.In,{children:ya(bt,{onCloseRequest:r,title:!1,size:916,children:VS("div",{className:"OverwriteConfirm",children:[ya("h3",{children:o.title}),VS("div",{className:`OverwriteConfirm__Description OverwriteConfirm__Description--color-${o.color}`,children:[ya("div",{className:"OverwriteConfirm__Description__icon",children:Im}),ya("div",{children:o.description}),ya("div",{className:"OverwriteConfirm__Description__spacer"}),ya(on,{color:o.color,size:"large",label:o.actionLabel,onClick:a})]}),ya(Rx,{children:e})]})})})}),{Actions:Rx,Action:og});import U$ from"clsx";import{CANVAS_SEARCH_TAB as zx,DEFAULT_SIDEBAR as W$,LIBRARY_SIDEBAR_TAB as oM,composeEventHandlers as Y$}from"@orangecatai/common";import{round as w$}from"@orangecatai/math";import v$ from"clsx";import I$ from"lodash.debounce";import{Fragment as T$,memo as C$,useEffect as Ed,useMemo as KS,useRef as Nx,useState as XS}from"react";import{CLASSES as k$,EVENT as S$,FONT_FAMILY as Bx,FRAME_STYLE as Fx,getLineHeight as M$}from"@orangecatai/common";import{isElementCompletelyInViewport as P$}from"@orangecatai/element";import{measureText as wd}from"@orangecatai/element";import{KEYS as yl,randomInteger as ZS,addEventListener as A$,getFontString as rg}from"@orangecatai/common";import{newTextElement as L$}from"@orangecatai/element";import{isTextElement as QS,isFrameLikeElement as ag}from"@orangecatai/element";import{getDefaultFrameName as eM}from"@orangecatai/element/frame";import{Fragment as G$,jsx as Ot,jsxs as er}from"react/jsx-runtime";var _$=Pe(""),Ox=Pe(null),D$=350,tM=()=>{let e=tt(),t=Ce(),o=Nx(null),[n,r]=le(_$),a=n.trim(),[i,s]=XS(!1),[l,c]=XS({nonce:null,items:[]}),m=Nx(null),p=Nx(void 0),[d,u]=le(Ox),h=e.scene.getNonDeletedElementsMap();Ed(()=>{i||(a!==m.current||e.scene.getSceneNonce()!==p.current)&&(m.current=null,JS(a,e,(w,v)=>{c({nonce:ZS(),items:w}),m.current=a,p.current=e.scene.getSceneNonce(),t({searchMatches:w.length?{focusedId:null,matches:w.map(I=>({id:I.element.id,focus:!1,matchedLines:I.matchedLines}))}:null})}))},[i,a,h,e,t,u,p]);let g=()=>{l.items.length>0&&u(w=>w===null?0:(w+1)%l.items.length)},x=()=>{l.items.length>0&&u(w=>w===null?0:w-1<0?l.items.length-1:w-1)};Ed(()=>{t(w=>w.searchMatches?{searchMatches:{focusedId:d!==null&&w.searchMatches?.matches[d]?.id||null,matches:w.searchMatches.matches.map((I,C)=>C===d?{...I,focus:!0}:{...I,focus:!1})}}:null)},[d,t]),Ed(()=>{if(l.items.length>0&&d!==null){let w=l.items[d];if(w){let v=e.state.zoom.value,I=L$({text:w.searchQuery,x:w.element.x+(w.matchedLines[0]?.offsetX??0),y:w.element.y+(w.matchedLines[0]?.offsetY??0),width:w.matchedLines[0]?.width,height:w.matchedLines[0]?.height,fontSize:ag(w.element)?Fx.nameFontSize:w.element.fontSize,fontFamily:ag(w.element)?Bx.Assistant:w.element.fontFamily}),C=14,P=I.fontSize,S=P*v<C;if(!P$([I],e.canvas.width/window.devicePixelRatio,e.canvas.height/window.devicePixelRatio,{offsetLeft:e.state.offsetLeft,offsetTop:e.state.offsetTop,scrollX:e.state.scrollX,scrollY:e.state.scrollY,zoom:e.state.zoom},e.scene.getNonDeletedElementsMap(),e.getEditorUIOffsets())||S){let D;S?P>=C?D={fitToContent:!0}:D={fitToViewport:!0,maxZoom:w$(C/P,1)}:D={fitToContent:!0},e.scrollToContent(I,{animate:!0,duration:300,...D,canvasOffsets:e.getEditorUIOffsets()})}}}},[d,l,e]),Ed(()=>()=>{u(null),m.current=null,p.current=void 0,t({searchMatches:null}),s(!1)},[t,u]);let E=Ur({goToNextItem:g,goToPreviousItem:x,searchMatches:l});Ed(()=>{let w=v=>{if(v.key===yl.ESCAPE&&!e.state.openDialog&&!e.state.openPopup){v.preventDefault(),v.stopPropagation(),t({openSidebar:null});return}if(v[yl.CTRL_OR_CMD]&&v.key===yl.F){if(v.preventDefault(),v.stopPropagation(),e.state.openDialog)return;o.current?.matches(":focus")||(e.state.openDialog&&t({openDialog:null}),o.current?.focus(),o.current?.select())}v.target instanceof HTMLElement&&v.target.closest(".layer-ui__search")&&E.searchMatches.items.length&&(v.key===yl.ENTER&&(v.stopPropagation(),E.goToNextItem()),v.key===yl.ARROW_UP?(v.stopPropagation(),E.goToPreviousItem()):v.key===yl.ARROW_DOWN&&(v.stopPropagation(),E.goToNextItem()))};return A$(window,S$.KEYDOWN,w,{capture:!0,passive:!1})},[t,E,e]);let y=`${l.items.length} ${l.items.length===1?f("search.singleResult"):f("search.multipleResults")}`;return er("div",{className:"layer-ui__search",children:[Ot("div",{className:"layer-ui__search-header",children:Ot(ia,{className:k$.SEARCH_MENU_INPUT_WRAPPER,value:n,ref:o,placeholder:f("search.placeholder"),icon:Mo,onChange:w=>{r(w),s(!0);let v=w.trim();JS(v,e,(I,C)=>{c({nonce:ZS(),items:I}),u(C),m.current=v,p.current=e.scene.getSceneNonce(),t({searchMatches:I.length?{focusedId:null,matches:I.map(P=>({id:P.element.id,focus:!1,matchedLines:P.matchedLines}))}:null}),s(!1)})},selectOnRender:!0})}),er("div",{className:"layer-ui__search-count",children:[l.items.length>0&&er(G$,{children:[d!==null&&d>-1?er("div",{children:[d+1," / ",y]}):Ot("div",{children:y}),er("div",{className:"result-nav",children:[Ot(so,{onSelect:()=>{g()},className:"result-nav-btn",children:Tm}),Ot(so,{onSelect:()=>{x()},className:"result-nav-btn",children:pv})]})]}),l.items.length===0&&a&&m.current&&Ot("div",{style:{margin:"1rem auto"},children:f("search.noMatch")})]}),Ot(B$,{matches:l,onItemClick:u,focusIndex:d,searchQuery:a})]})},jS=e=>{let t=[e.preview.moreBefore?"...":"",e.preview.previewText.slice(0,e.preview.indexInSearchQuery),e.preview.previewText.slice(e.preview.indexInSearchQuery,e.preview.indexInSearchQuery+e.searchQuery.length),e.preview.previewText.slice(e.preview.indexInSearchQuery+e.searchQuery.length),e.preview.moreAfter?"...":""];return Ot("div",{tabIndex:-1,className:v$("layer-ui__result-item",{active:e.highlighted}),onClick:e.onClick,ref:o=>{e.highlighted&&o?.scrollIntoView({behavior:"auto",block:"nearest"})},children:Ot("div",{className:"preview-text",children:t.flatMap((o,n)=>Ot(T$,{children:n===2?Ot("b",{children:o}):o},n))})})},R$=e=>{let t=KS(()=>e.matches.items.filter(n=>ag(n.element)),[e.matches]),o=KS(()=>e.matches.items.filter(n=>QS(n.element)),[e.matches]);return er("div",{children:[t.length>0&&er("div",{className:"layer-ui__search-result-container",children:[er("div",{className:"layer-ui__search-result-title",children:[Ot("div",{className:"title-icon",children:On}),Ot("div",{children:f("search.frames")})]}),t.map((n,r)=>Ot(jS,{searchQuery:e.searchQuery,preview:n.preview,highlighted:r===e.focusIndex,onClick:()=>e.onItemClick(r)},n.element.id+n.index)),o.length>0&&Ot("div",{className:"layer-ui__divider"})]}),o.length>0&&er("div",{className:"layer-ui__search-result-container",children:[er("div",{className:"layer-ui__search-result-title",children:[Ot("div",{className:"title-icon",children:Fn}),Ot("div",{children:f("search.texts")})]}),o.map((n,r)=>Ot(jS,{searchQuery:e.searchQuery,preview:n.preview,highlighted:r+t.length===e.focusIndex,onClick:()=>e.onItemClick(r+t.length)},n.element.id+n.index))]})]})},N$=(e,t)=>e.matches.nonce===t.matches.nonce&&e.focusIndex===t.focusIndex,B$=C$(R$,N$),qS=(e,t,o)=>{let a=e.slice(0,t),i=a.split(/\s+/),s=a.endsWith(" "),l=i.length-2-1-(s?0:1),c=i.slice(l<=0?0:l).join(" ")+(s?" ":""),m=20;c=c.length>m?c.slice(-m):c;let p=e.slice(t+o.length),d=p.split(/\s+/),u=!p.startsWith(" "),h=u?6:5,g=(u?"":" ")+d.slice(0,h).join(" ");return{indexInSearchQuery:c.length,previewText:c+o+g,moreBefore:l>0,moreAfter:d.length>h}},F$=(e,t)=>{let o=e.split(`
|
|
202
202
|
`),n=[],r=0;for(let a=0;a<o.length;a++){let i=o[a],s=o[a+1];if(s){let l=t.indexOf(s,r);if(l>i.length+r){let c=l-(i.length+r);for(;c>0;)i+=" ",c--}}n.push(i),r=r+i.length}return n.join(`
|
|
203
203
|
`)},O$=(e,t,o)=>{let r=F$(e.text,e.originalText).split(`
|
|
204
204
|
`),a=[],i=0,s=0;for(let p of r){let d=i,u=d+p.length-1;a.push({line:p,startIndex:d,endIndex:u,lineNumber:s}),i=u+1,s++}let l=o,c=e.originalText.slice(o,o+t.length),m=[];for(let p of a){if(c==="")break;if(l>=p.startIndex&&l<=p.endIndex){let d=p.endIndex+1-l,u=p.line.slice(0,l-p.startIndex),h=c.slice(0,d);c=c.slice(d);let g=wd(u,rg(e),e.lineHeight);if(u===""&&(g.width=0),e.textAlign!=="left"&&p.line.length>0){let v=wd(p.line,rg(e),e.lineHeight),I=e.textAlign==="center"?(e.width-v.width)/2:e.width-v.width;g.width+=I}let{width:x,height:E}=wd(h,rg(e),e.lineHeight),y=g.width,w=p.lineNumber*g.height;m.push({offsetX:y,offsetY:w,width:x,height:E,showOnCanvas:!0}),l+=d}}return m},z$=(e,t,o,n)=>{let r=e.name??eM(e),a=r.slice(o,o+t.length),i=r.slice(0,o),s=rg({fontSize:Fx.nameFontSize,fontFamily:Bx.Assistant}),l=M$(Bx.Assistant),c=wd(i,s,l);i===""&&(c.width=0);let m=wd(a,s,l),p=c.width,d=-c.height-Fx.strokeWidth,u=m.width;return[{offsetX:p,offsetY:d,width:u,height:m.height,showOnCanvas:p+u<=e.width*n}]},H$=e=>e.replace(/[.*+?^${}()|[\]\\-]/g,"\\$&"),JS=I$((e,t,o)=>{if(!e||e===""){o([],null);return}let n=t.scene.getNonDeletedElements(),r=n.filter(d=>QS(d)),a=n.filter(d=>ag(d));r.sort((d,u)=>d.y-u.y),a.sort((d,u)=>d.y-u.y);let i=[],s=new RegExp(H$(e),"gi");for(let d of r){let u=null,h=d.originalText;for(;(u=s.exec(h))!==null;){let g=qS(h,u.index,e),x=O$(d,e,u.index);x.length>0&&i.push({element:d,searchQuery:e,preview:g,index:u.index,matchedLines:x})}}let l=[];for(let d of a){let u=null,h=d.name??eM(d);for(;(u=s.exec(h))!==null;){let g=qS(h,u.index,e),x=z$(d,e,u.index,t.state.zoom.value);x.length>0&&l.push({element:d,searchQuery:e,preview:g,index:u.index,matchedLines:x})}}let c=new Set(t.visibleElements.map(d=>d.id)),m=[...l,...i],p=m.findIndex(d=>c.has(d.element.id))??null;o(m,p)},D$);import{jsx as In,jsxs as nM}from"react/jsx-runtime";import{createElement as $$}from"react";var rM=_r("DefaultSidebarTrigger",e=>{let{DefaultSidebarTriggerTunnel:t}=Ze();return In(t.In,{children:In(tn.Trigger,{...e,className:"default-sidebar-trigger",name:W$.name})})});rM.displayName="DefaultSidebarTrigger";var aM=({children:e})=>{let{DefaultSidebarTabTriggersTunnel:t}=Ze();return In(t.In,{children:e})};aM.displayName="DefaultTabTriggers";var ig=Object.assign(_r("DefaultSidebar",({children:e,className:t,onDock:o,docked:n,...r})=>{let a=Ie(),i=Ce(),{DefaultSidebarTabTriggersTunnel:s}=Ze(),l=a.openSidebar?.tab===zx;return $$(tn,{...r,name:"default",key:"default",className:U$("default-sidebar",t),docked:l||(n??a.defaultSidebarDockedPreference),onDock:l||o===!1||!o&&n!=null?void 0:Y$(o,c=>{i({defaultSidebarDockedPreference:c})})},nM(tn.Tabs,{children:[In(tn.Header,{children:nM(tn.TabTriggers,{children:[In(tn.TabTrigger,{tab:zx,children:Mo}),In(tn.TabTrigger,{tab:oM,children:um}),In(s.Out,{})]})}),In(tn.Tab,{tab:oM,children:In(NC,{})}),In(tn.Tab,{tab:zx,children:In(tM,{})}),e]}))}),{Trigger:rM,TabTriggers:aM});import{useEffect as UV,useState as WV}from"react";import{useState as fM,useRef as bM,useEffect as xM,useDeferredValue as eV}from"react";import{EDITOR_LS_KEYS as tV,debounce as oV,isDevEnv as nV}from"@orangecatai/common";import{useEffect as V$,useRef as iM}from"react";import{EVENT as sM,KEYS as lM}from"@orangecatai/common";import{jsx as K$}from"react/jsx-runtime";var cM=({input:e,placeholder:t,onChange:o,onKeyboardSubmit:n})=>{let r=iM(null),a=iM(n);return a.current=n,V$(()=>{if(!a.current)return;let i=r.current;if(i){let s=l=>{l[lM.CTRL_OR_CMD]&&l.key===lM.ENTER&&(l.preventDefault(),a.current?.())};return i.focus(),i.addEventListener(sM.KEYDOWN,s),()=>{i.removeEventListener(sM.KEYDOWN,s)}}},[]),K$("textarea",{className:"ttd-dialog-input",onChange:o,value:e,placeholder:t,ref:r})};import X$ from"clsx";import{jsx as Ii,jsxs as dM}from"react/jsx-runtime";var sg=({error:e,canvasRef:t,loaded:o,hideErrorDetails:n})=>dM("div",{className:`ttd-dialog-output-wrapper ${e?"ttd-dialog-output-wrapper--error":""}`,children:[e&&Ii("div",{"data-testid":"ttd-dialog-output-error",className:"ttd-dialog-output-error",children:dM("div",{className:"ttd-dialog-output-error-content",children:[Ii("div",{className:"ttd-dialog-output-error-icon",children:Im}),Ii("div",{className:"ttd-dialog-output-error-title",children:f("ttd.error")}),Ii("div",{className:"ttd-dialog-output-error-message",children:n?f("chat.errors.mermaidParseError"):e.message})]})},"error"),o?Ii("div",{className:X$("ttd-dialog-output-canvas-container",{invisible:!!e}),children:Ii("div",{ref:t,className:"ttd-dialog-output-canvas-content"})},"canvas"):Ii(Wt,{size:"2rem"})]});import El from"clsx";import{Fragment as Z$}from"react";import{jsx as wl,jsxs as vl}from"react/jsx-runtime";var Ti=({label:e,children:t,panelActions:o=[],onTextSubmitInProgess:n,renderTopRight:r,renderSubmitShortcut:a,className:i,panelActionJustifyContent:s="flex-start"})=>{let l=c=>{if(c?.variant==="link")return vl("button",{className:El("ttd-dialog-panel-action-link",c.className),onClick:c.action,disabled:c?.disabled||n,type:"button",children:[c.label,c.icon&&wl("span",{className:"ttd-dialog-panel-action-link__icon",children:c.icon})]});if(c?.variant==="button")return vl(so,{className:El("ttd-dialog-panel-button",c.className),onSelect:c.action?c.action:()=>{},disabled:c?.disabled||n,children:[vl("div",{className:El({invisible:n}),children:[c?.label,c?.icon&&wl("span",{children:c.icon})]}),n&&wl(Wt,{})]});if(c?.variant==="rateLimit")return wl("div",{className:El("ttd-dialog-panel__rate-limit",c.className),children:c.label})};return vl("div",{className:El("ttd-dialog-panel",i),children:[(e||r)&&vl("div",{className:"ttd-dialog-panel__header",children:[typeof e=="string"?wl("label",{children:e}):e,r?.()]}),t,vl("div",{className:El("ttd-dialog-panel-button-container",{invisible:!o.length}),style:{justifyContent:s},children:[o.filter(Boolean).map(c=>wl(Z$,{children:l(c)},c.label)),!n&&a?.()]})]})};import{jsx as j$}from"react/jsx-runtime";var mM=({children:e})=>j$("div",{className:"ttd-dialog-panels",children:e});import{jsx as pM,jsxs as q$}from"react/jsx-runtime";var uM=()=>q$("div",{className:"ttd-dialog-submit-shortcut",children:[pM("div",{className:"ttd-dialog-submit-shortcut__key",children:G("CtrlOrCmd")}),pM("div",{className:"ttd-dialog-submit-shortcut__key",children:G("Enter")})]});import{DEFAULT_EXPORT_PADDING as J$,EDITOR_LS_KEYS as Q$}from"@orangecatai/common";var Hx=({canvasRef:e,setError:t})=>{let o=e.current;if(!o)return;let n=o.parentElement;n&&(n.style.background="",t(null),o.replaceChildren())},Il=async({canvasRef:e,mermaidToExcalidrawLib:t,mermaidDefinition:o,setError:n,data:r,theme:a})=>{let i=e.current,s=i?.parentElement;if(!i||!s)return{success:!1};if(!o)return Hx({canvasRef:e,setError:n}),{success:!1};let l;try{let c=await t.api;try{try{l=await c.parseMermaidToExcalidraw(o)}catch{l=await c.parseMermaidToExcalidraw(o.replace(/"/g,"'"))}}catch(u){return{success:!1,error:u}}let{elements:m,files:p}=l;n(null),r.current={elements:hM(m,{regenerateIds:!0}),files:p};let d=await na({elements:r.current.elements,files:r.current.files,exportPadding:J$,maxWidthOrHeight:Math.max(s.offsetWidth,s.offsetHeight)*window.devicePixelRatio,appState:{exportWithDarkMode:a===gM.DARK}});return s.style.background="var(--default-bg-color)",i.replaceChildren(d),{success:!0}}catch(c){return s.style.background="var(--default-bg-color)",o&&n(c),{success:!1,error:c}}},Tl=e=>{Xo.set(Q$.MERMAID_TO_EXCALIDRAW,e)},vd=({app:e,data:t,text:o,shouldSaveMermaidDataToStorage:n})=>{let{elements:r,files:a}=t.current;r.length&&(e.addElementsFromPasteOrLibrary({elements:r,files:a,position:"center",fitToContent:!0}),e.setOpenDialog(null),n&&o&&Tl(o))};import{Fragment as iV,jsx as tr,jsxs as EM}from"react/jsx-runtime";var rV=`flowchart TD
|
|
@@ -215,7 +215,7 @@ ${F}
|
|
|
215
215
|
|
|
216
216
|
The exception/error is: ${$}
|
|
217
217
|
|
|
218
|
-
Please fix the Mermaid syntax and regenerate a valid diagram.`;await E({prompt:Q,isRepairFlow:!0})},B=async L=>{let F=m.messages.findIndex($=>$.id===L.id);if(F>0){let $=m.messages[F-1];$.type==="user"&&typeof $.content=="string"&&(g(),await E({prompt:$.content,isRepairFlow:!0}))}},O=()=>{vd({app:a,data:x})},N=L=>{let F=m.messages.findIndex(Q=>Q.id===L&&Q.type==="assistant"),$=m.messages.slice(0,F-1);p({...m,messages:$})},z=L=>{p(F=>({...F,currentPrompt:L}))};return DV("div",{className:`ttd-dialog-layout ${d?"ttd-dialog-layout--split":"ttd-dialog-layout--chat-only"}`,children:[jx(BM,{chatId:m.id,messages:m.messages,currentPrompt:m.currentPrompt,onPromptChange:z,onGenerate:E,isGenerating:h?.isGenerating??!1,generatedResponse:h?.content,isMenuOpen:w,onMenuToggle:P,onMenuClose:S,onNewChat:C,onRestoreChat:v,onDeleteChat:I,savedChats:u,activeSessionId:m.id,onAbort:y,onMermaidTabClick:_,onAiRepairClick:M,onDeleteMessage:N,onInsertMessage:k,onRetry:B,onViewAsMermaid:D,renderWarning:n,renderWelcomeScreen:o}),d&&jx(OM,{canvasRef:s,hideErrorDetails:h?.errorType==="parse",error:l,loaded:e.loaded,onInsert:O})]})},_V=({mermaidToExcalidrawLib:e,onTextSubmit:t,renderWelcomeScreen:o,renderWarning:n,persistenceAdapter:r})=>jx(LV,{mermaidToExcalidrawLib:e,onTextSubmit:t,renderWelcomeScreen:o,renderWarning:n,persistenceAdapter:r}),zM=_V;import{Tabs as RV}from"radix-ui";import{useRef as HM}from"react";import{isMemberOf as NV}from"@orangecatai/common";import{jsx as BV}from"react/jsx-runtime";var GM=e=>{let t=Ce(),o=HM(null),n=HM(0);return BV(RV.Root,{ref:o,className:"ttd-dialog-tabs-root",value:e.tab,onValueChange:r=>{if(!r)return;let a=o.current?.closest(".Modal__content");if(a){let i=a.offsetHeight||0;i>n.current&&(n.current=i,a.style.minHeight=`min(${n.current}px, 100%)`)}e.dialog==="ttd"&&NV(["text-to-diagram","mermaid"],r)&&t({openDialog:{name:e.dialog,tab:r}})},children:e.children})};GM.displayName="TTDDialogTabs";var UM=GM;import{Tabs as FV}from"radix-ui";import{jsx as OV}from"react/jsx-runtime";var qx=({children:e,...t})=>OV(FV.List,{className:"ttd-dialog-triggers",...t,children:e});qx.displayName="TTDDialogTabTriggers";import{Tabs as zV}from"radix-ui";import{jsx as WM}from"react/jsx-runtime";var ug=({children:e,tab:t,onSelect:o,...n})=>WM(zV.Trigger,{value:t,asChild:!0,onSelect:o,children:WM("button",{type:"button",className:"ttd-dialog-tab-trigger",...n,children:e})});ug.displayName="TTDDialogTabTrigger";import{Tabs as HV}from"radix-ui";import{jsx as GV}from"react/jsx-runtime";var gg=({tab:e,children:t,...o})=>GV(HV.Content,{...o,value:e,children:t});gg.displayName="TTDDialogTab";import{jsx as or,jsxs as Jx}from"react/jsx-runtime";var hg=e=>{let t=Ie();return t.openDialog?.name!=="ttd"?null:or(YV,{...e,tab:t.openDialog.tab})};hg.WelcomeMessage=lg;var YV=_r("TTDDialogBase",({tab:e,...t})=>{let o=tt(),[n,r]=WV({loaded:!1,api:import("@excalidraw/mermaid-to-excalidraw")});return UV(()=>{(async()=>{await n.api,r(i=>({...i,loaded:!0}))})()},[n.api]),or(bt,{className:"ttd-dialog",onCloseRequest:()=>{o.setOpenDialog(null)},size:1520,title:!1,...t,autofocus:!1,children:Jx(UM,{dialog:"ttd",tab:e,children:["__fallback"in t&&t.__fallback?or("p",{className:"dialog-mermaid-title",children:f("mermaid.title")}):Jx(qx,{children:[or(ug,{tab:"text-to-diagram",children:Jx("div",{className:"ttd-dialog-tab-trigger__content",children:[f("labels.textToDiagram"),or("div",{className:"ttd-dialog-tab-trigger__badge",children:f("chat.aiBeta")})]})}),or(ug,{tab:"mermaid",children:f("mermaid.label")})]}),!("__fallback"in t)&&or(gg,{className:"ttd-dialog-content",tab:"text-to-diagram",children:or(zM,{mermaidToExcalidrawLib:n,onTextSubmit:t.onTextSubmit,renderWelcomeScreen:t.renderWelcomeScreen,renderWarning:t.renderWarning,persistenceAdapter:t.persistenceAdapter})}),or(gg,{className:"ttd-dialog-content",tab:"mermaid",children:or(wM,{mermaidToExcalidrawLib:n,isActive:e==="mermaid"})})]})})});import{round as A4}from"@orangecatai/math";import rX from"clsx";import aX from"lodash.throttle";import{useEffect as L4,useMemo as p1,useState as iX,memo as sX}from"react";import{STATS_PANELS as Ig}from"@orangecatai/common";import{getCommonBounds as lX}from"@orangecatai/element";import{getUncroppedWidthAndHeight as cX}from"@orangecatai/element";import{isImageElement as u1}from"@orangecatai/element";import{frameAndChildrenSelectedTogether as dX}from"@orangecatai/element";import{elementsAreInSameGroup as mX}from"@orangecatai/element";import{degreesToRadians as qM,radiansToDegrees as t4}from"@orangecatai/math";import{getBoundTextElement as JM}from"@orangecatai/element";import{isArrowElement as QM,isElbowArrow as nK}from"@orangecatai/element";import{updateBindings as e4}from"@orangecatai/element";import qV from"clsx";import{useEffect as ZM,useRef as bg,useState as JV}from"react";import{EVENT as Ml,KEYS as QV,cloneJSON as Qx}from"@orangecatai/common";import{deepCopyElement as eK}from"@orangecatai/element";import{CaptureUpdateAction as jM}from"@orangecatai/element";import{pointFrom as Ia,pointRotateRads as fg}from"@orangecatai/math";import{getBoundTextElement as $V,isBindingElement as VV,unbindBindingElement as YM}from"@orangecatai/element";import{isFrameLikeElement as KM}from"@orangecatai/element";import{getSelectedGroupIds as KV,getElementsInGroup as XV,isInGroup as ZV}from"@orangecatai/element";import{getFrameChildren as jV}from"@orangecatai/element";import{updateBindings as $M}from"@orangecatai/element";import{DRAGGING_THRESHOLD as VM}from"@orangecatai/common";var XM=.01,kd=10,wo=(e,t)=>!(t==="angle"&&KM(e)),st=(e,t)=>{let o=e+t/2;return o-o%t},kl=(e,t,o)=>Object.keys(e).map(n=>({original:(o??t).get(n),latest:t.get(n)})).filter(n=>n.original!==void 0&&n.latest!==void 0);var Mi=(e,t,o,n,r,a,i=!0)=>{if(VV(o)&&(o.startBinding||o.endBinding)){if(Math.abs(e-o.x)<VM&&Math.abs(t-o.y)<VM)return;YM(o,"start",n),YM(o,"end",n)}let s=n.getNonDeletedElementsMap(),l=s.get(o.id);if(!l)return;let[c,m]=[o.x+o.width/2,o.y+o.height/2],[p,d]=fg(Ia(o.x,o.y),Ia(c,m),o.angle),u=e-p,h=t-d,[g,x]=fg(Ia(e,t),Ia(c+u,m+h),-o.angle);n.mutateElement(l,{x:g,y:x},{informMutation:i,isDragging:!1}),$M(l,n,r);let E=$V(o,a);if(E){let y=s.get(E.id);y&&n.mutateElement(y,{x:E.x+u,y:E.y+h},{informMutation:i,isDragging:!1})}if(KM(o)){let y=jV(a,o.id);y.forEach(w=>{let v=s.get(w.id);if(!v)return;let[I,C]=[w.x+w.width/2,w.y+w.height/2],[P,S]=fg(Ia(w.x,w.y),Ia(I,C),w.angle),D=Math.round(P+u),_=Math.round(S+h),[k,M]=fg(Ia(D,_),Ia(I+u,C+h),-w.angle);n.mutateElement(v,{x:k,y:M},{informMutation:i,isDragging:!1}),$M(v,n,r,{simultaneouslyUpdated:y})})}},Sl=(e,t)=>{let n=KV(t).map(r=>XV(e,r).reduce((a,i)=>(a[i.id]=!0,a),{}));return e.filter(r=>!ZV(r)).forEach(r=>{n.push({[r.id]:!0})}),n};import{jsx as e1,jsxs as oK}from"react/jsx-runtime";var tK=({label:e,icon:t,dragInputCallback:o,value:n,elements:r,editable:a=!0,shouldKeepAspectRatio:i,property:s,scene:l,appState:c,sensitivity:m=1,dragFinishedCallback:p})=>{let d=tt(),u=Ce(),h=bg(null),g=bg(null),[x,E]=JV(n.toString()),y=bg(null);y.current||(y.current={originalAppState:Qx(c),originalElements:r,lastUpdatedValue:x,updatePending:!1}),ZM(()=>{let I=n.toString();E(I),y.current.lastUpdatedValue=I},[n]);let w=(I,C,P)=>{if(!y.current.updatePending)return!1;y.current.updatePending=!1;let S=Number(I);if(isNaN(S)){E(n.toString());return}let D=Number(S.toFixed(2)),_=Number(n);(isNaN(_)||Math.abs(D-_)>=XM)&&(y.current.lastUpdatedValue=I,o({accumulatedChange:0,instantChange:0,originalElements:C,originalElementsMap:d.scene.getNonDeletedElementsMap(),shouldKeepAspectRatio:i,shouldChangeByStepSize:!1,scene:l,nextValue:D,property:s,originalAppState:P,setInputValue:k=>E(String(k)),app:d,setAppState:u}),d.syncActionResult({captureUpdate:jM.IMMEDIATELY}))},v=bg({});return v.current.handleInputValue=w,ZM(()=>{let I=h.current,C=v.current;return()=>{let P=I?.value;P&&C.handleInputValue?.(P,y.current.originalElements,y.current.originalAppState),window.removeEventListener(Ml.POINTER_MOVE,C.onPointerMove,!1),window.removeEventListener(Ml.POINTER_UP,C.onPointerUp,!1)}},[a]),a?oK("div",{className:qV("drag-input-container",!a&&"disabled"),"data-testid":e,children:[e1("div",{className:"drag-input-label",ref:g,onPointerDown:I=>{if(h.current&&a){document.body.classList.add("excalidraw-cursor-resize");let C=Number(h.current.value);isNaN(C)&&(C=0);let P=null,S=d.scene.getNonDeletedElements().reduce((N,z)=>(N.set(z.id,eK(z)),N),new Map),D=r.map(N=>S.get(N.id)),_=Qx(c),k=0,M=0,B=N=>{if(P&&S!==null&&D!==null){let z=N.clientX-P.x;z!==0&&(M+=z,Math.abs(M)>=m&&(M=Math.sign(M)*Math.floor(Math.abs(M)/m),k+=M,o({accumulatedChange:k,instantChange:M,originalElements:D,originalElementsMap:S,shouldKeepAspectRatio:i,shouldChangeByStepSize:N.shiftKey,property:s,scene:l,originalAppState:_,setInputValue:L=>E(String(L)),app:d,setAppState:u}),M=0))}P={x:N.clientX,y:N.clientY}},O=()=>{window.removeEventListener(Ml.POINTER_MOVE,B,!1),d.syncActionResult({captureUpdate:jM.IMMEDIATELY}),p?.({app:d,setAppState:u,originalElements:D,originalAppState:_}),P=null,k=0,M=0,D=null,S=null,document.body.classList.remove("excalidraw-cursor-resize"),window.removeEventListener(Ml.POINTER_UP,O,!1)};v.current.onPointerMove=B,v.current.onPointerUp=O,window.addEventListener(Ml.POINTER_MOVE,B,!1),window.addEventListener(Ml.POINTER_UP,O,!1)}},onPointerEnter:()=>{g.current&&(g.current.style.cursor="ew-resize")},children:t?e1(Gn,{icon:t}):e}),e1("input",{className:"drag-input",autoComplete:"off",spellCheck:"false",onKeyDown:I=>{if(a){let C=I.target;C instanceof HTMLInputElement&&I.key===QV.ENTER&&(w(C.value,r,c),d.focusContainer())}},ref:h,value:x,onChange:I=>{y.current.updatePending=!0,E(I.target.value)},onFocus:I=>{I.target.select(),y.current.originalElements=r,y.current.originalAppState=Qx(c)},onBlur:I=>{x?a&&w(I.target.value,y.current.originalElements,y.current.originalAppState):E(n.toString())},disabled:!a})]}):null},zt=tK;import{jsx as sK}from"react/jsx-runtime";var rK=15,aK=({accumulatedChange:e,originalElements:t,shouldChangeByStepSize:o,nextValue:n,scene:r,app:a})=>{let i=r.getNonDeletedElementsMap(),s=t[0];if(s&&!nK(s)){let l=i.get(s.id);if(!l)return;if(n!==void 0){let h=qM(n);r.mutateElement(l,{angle:h}),e4(l,r,a.state);let g=JM(l,i);g&&!QM(l)&&r.mutateElement(g,{angle:h});return}let c=Math.round(t4(s.angle)*100)/100,m=Math.round(e),p=(c+m)%360;o&&(p=st(p,rK)),p=p<0?p+360:p;let d=qM(p);r.mutateElement(l,{angle:d}),e4(l,r,a.state);let u=JM(l,i);u&&!QM(l)&&r.mutateElement(u,{angle:d})}},iK=({element:e,scene:t,appState:o,property:n})=>sK(zt,{label:"A",icon:vm,value:Math.round(t4(e.angle)%360*100)/100,elements:[e],dragInputCallback:aK,editable:wo(e,"angle"),scene:t,appState:o,property:n}),o4=iK;import{jsx as cK}from"react/jsx-runtime";var n4=5,lK=({property:e,scene:t,appState:o,setAppState:n})=>cK(zt,{label:"Grid step",sensitivity:8,elements:[],dragInputCallback:({nextValue:r,instantChange:a,shouldChangeByStepSize:i,setInputValue:s})=>{n(l=>{let c;return r?c=r:a&&(c=i?st(l.gridStep+n4*Math.sign(a),n4):l.gridStep+a),c?(c=nE(c),s(c),{gridStep:c}):(s(l.gridStep),null)})},scene:t,value:o.gridStep,property:e,appState:o}),r4=lK;import{clamp as xg,round as t1}from"@orangecatai/math";import{MIN_WIDTH_OR_HEIGHT as yg}from"@orangecatai/common";import{MINIMAL_CROP_SIZE as a4,getUncroppedWidthAndHeight as l4}from"@orangecatai/element";import{resizeSingleElement as i4}from"@orangecatai/element";import{isImageElement as c4}from"@orangecatai/element";import{isFrameLikeElement as o1}from"@orangecatai/element";import{getElementsInResizingFrame as n1}from"@orangecatai/element";import{replaceAllElementsInFrame as d4}from"@orangecatai/element";import{jsx as gK}from"react/jsx-runtime";var s4=10,dK=e=>e.type==="image",mK=({accumulatedChange:e,originalElements:t,originalElementsMap:o,shouldKeepAspectRatio:n,shouldChangeByStepSize:r,nextValue:a,property:i,originalAppState:s,instantChange:l,scene:c,app:m,setAppState:p})=>{let d=c.getNonDeletedElementsMap(),u=t[0],h=d.get(u.id);if(u&&h){let g=n||dK(u),x=u.width/u.height;if(s.croppingElementId===u.id){let E=d.get(u.id);if(!E||!c4(E)||!E.crop)return;let y=E.crop,w={...y},v=E.scale[0]===-1,I=E.scale[1]===-1,{width:C,height:P}=l4(E),S=y.naturalWidth/C,D=y.naturalHeight/P,_=v?y.width+y.x:y.naturalWidth-y.x,k=I?y.height+y.y:y.naturalHeight-y.y,M=a4*S,B=a4*D;if(a!==void 0){if(i==="width"){let F=a*S,$=xg(F,M,_);w={...w,width:$,x:v?y.x+y.width-$:y.x}}else if(i==="height"){let F=a*D,$=xg(F,B,k);w={...w,height:$,y:I?y.y+y.height-$:y.y}}c.mutateElement(E,{crop:w,width:w.width/(y.naturalWidth/C),height:w.height/(y.naturalHeight/P)});return}let O=i==="width"?l:0,N=i==="height"?l:0,z=xg(y.width+O,M,_),L=xg(y.height+N,M,k);w={...y,x:v?y.x+y.width-z:y.x,y:I?y.y+y.height-L:y.y,width:z,height:L},c.mutateElement(E,{crop:w,width:w.width/(y.naturalWidth/C),height:w.height/(y.naturalHeight/P)});return}if(a!==void 0){let E=Math.max(i==="width"?a:g?a*x:u.width,yg),y=Math.max(i==="height"?a:g?a/x:u.height,yg);if(i4(E,y,h,u,o,c,i==="width"?"e":"s",{shouldMaintainAspectRatio:g}),o1(h)){let w=n1(c.getElementsIncludingDeleted(),h,s,c.getNonDeletedElementsMap()),v=d4(c.getElementsIncludingDeleted(),w,h,m);c.replaceAllElements(v)}return}{let E=i==="width"?e:0,y=i==="height"?e:0,w=Math.max(0,u.width+E);i==="width"&&(r?w=st(w,s4):w=Math.round(w));let v=Math.max(0,u.height+y);if(i==="height"&&(r?v=st(v,s4):v=Math.round(v)),g&&(i==="width"?v=Math.round(w/x*100)/100:w=Math.round(v*x*100)/100),v=Math.max(yg,v),w=Math.max(yg,w),i4(w,v,h,u,o,c,i==="width"?"e":"s",{shouldMaintainAspectRatio:g}),o1(h)){let I=n1(c.getElementsIncludingDeleted(),h,s,c.getNonDeletedElementsMap());p({elementsToHighlight:I})}}}},pK=({setAppState:e,app:t,originalElements:o,originalAppState:n})=>{let r=t.scene.getNonDeletedElementsMap(),a=o?.[0],i=a&&r.get(a.id);if(i&&o1(i)){let s=n1(t.scene.getElementsIncludingDeleted(),i,n,t.scene.getNonDeletedElementsMap()),l=d4(t.scene.getElementsIncludingDeleted(),s,i,t);t.scene.replaceAllElements(l),e({elementsToHighlight:null})}},uK=({property:e,element:t,scene:o,appState:n})=>{let r=t1(e==="width"?t.width:t.height,2);if(n.croppingElementId&&n.croppingElementId===t.id&&c4(t)&&t.crop){let{width:a,height:i}=l4(t);if(e==="width"){let s=a/t.crop.naturalWidth;r=t1(t.crop.width*s,2)}if(e==="height"){let s=i/t.crop.naturalHeight;r=t1(t.crop.height*s,2)}}return gK(zt,{label:e==="width"?"W":"H",elements:[t],dragInputCallback:mK,value:r,editable:wo(t,e),scene:o,appState:n,property:e,dragFinishedCallback:pK})},r1=uK;import{getBoundTextElement as hK,redrawTextBoundingBox as fK}from"@orangecatai/element";import{hasBoundTextElement as bK,isTextElement as p4}from"@orangecatai/element";import{jsx as wK}from"react/jsx-runtime";var m4=4,xK=4,yK=({accumulatedChange:e,originalElements:t,shouldChangeByStepSize:o,nextValue:n,scene:r})=>{let a=r.getNonDeletedElementsMap(),i=t[0];if(i){let s=a.get(i.id);if(!s||!p4(s))return;let l;if(n!==void 0)l=Math.max(Math.round(n),m4);else if(i.type==="text"){let c=Math.round(i.fontSize),m=Math.round(e);l=Math.max(c+m,m4),o&&(l=st(l,xK))}l&&(r.mutateElement(s,{fontSize:l}),fK(s,r.getContainerElement(s),r))}},EK=({element:e,scene:t,appState:o,property:n})=>{let r=p4(e)?e:bK(e)?hK(e,t.getNonDeletedElementsMap()):null;return r?wK(zt,{label:"F",value:Math.round(r.fontSize*10)/10,elements:[r],dragInputCallback:yK,icon:Va,appState:o,scene:t,property:n}):null},u4=EK;import{degreesToRadians as g4,radiansToDegrees as b4}from"@orangecatai/math";import{getBoundTextElement as h4}from"@orangecatai/element";import{isArrowElement as f4}from"@orangecatai/element";import{isInGroup as a1}from"@orangecatai/element";import{jsx as CK}from"react/jsx-runtime";var vK=15,IK=({accumulatedChange:e,originalElements:t,shouldChangeByStepSize:o,nextValue:n,property:r,scene:a})=>{let i=a.getNonDeletedElementsMap(),s=t.map(c=>i.get(c.id)).filter(c=>c&&!a1(c)&&wo(c,r)),l=t.filter(c=>!a1(c)&&wo(c,r));if(n!==void 0){let c=g4(n);for(let m of s){if(!m)continue;a.mutateElement(m,{angle:c});let p=h4(m,i);p&&!f4(m)&&a.mutateElement(p,{angle:c})}a.triggerUpdate();return}for(let c=0;c<s.length;c++){let m=s[c];if(!m)continue;let p=l[c],d=Math.round(b4(p.angle)*100)/100,u=Math.round(e),h=(d+u)%360;o&&(h=st(h,vK)),h=h<0?h+360:h;let g=g4(h);a.mutateElement(m,{angle:g});let x=h4(m,i);x&&!f4(m)&&a.mutateElement(x,{angle:g})}a.triggerUpdate()},TK=({elements:e,scene:t,appState:o,property:n})=>{let r=e.filter(l=>!a1(l)&&wo(l,"angle")),a=r.map(l=>Math.round(b4(l.angle)%360*100)/100),i=new Set(a).size===1?a[0]:"Mixed",s=r.some(l=>wo(l,"angle"));return CK(zt,{label:"A",icon:vm,value:i,elements:e,dragInputCallback:IK,editable:s,appState:o,scene:t,property:n})},x4=TK;import{pointFrom as y4}from"@orangecatai/math";import{useMemo as kK}from"react";import{MIN_WIDTH_OR_HEIGHT as Ta}from"@orangecatai/common";import{getElementsInResizingFrame as i1,isFrameLikeElement as s1,replaceAllElementsInFrame as v4,updateBoundElements as SK}from"@orangecatai/element";import{rescalePointsInElement as MK,resizeSingleElement as E4}from"@orangecatai/element";import{getBoundTextElement as PK,handleBindTextResize as AK}from"@orangecatai/element";import{isTextElement as I4}from"@orangecatai/element";import{getCommonBounds as Eg}from"@orangecatai/element";import{jsx as BK}from"react/jsx-runtime";var Pl=10,LK=(e,t,o,n)=>{let r=n.x-e,a=n.y-t,i=n.width*o,s=n.height*o,l=e+r*o,c=t+a*o;return{width:i,height:s,x:l,y:c,...MK(n,i,s,!1),...I4(n)?{fontSize:n.fontSize*o}:{}}},_K=(e,t,o,n,r,a,i,s)=>{let l=s.getNonDeletedElementsMap(),c=LK(e,t,n,a);s.mutateElement(r,c);let m=PK(a,i);if(m){let p=m.fontSize*n;SK(r,s);let d=l.get(m.id);d&&I4(d)&&(s.mutateElement(d,{fontSize:p}),AK(r,s,o==="width"?"e":"s",!0))}},w4=(e,t,o,n,r,a,i,s,l,c)=>{a==="width"?t=Math.round(e/n*100)/100:e=Math.round(t*n*100)/100;let m=t/o;for(let p=0;p<s.length;p++){let d=s[p],u=i[p];_K(r[0],r[1],a,m,u,d,l,c)}},DK=({accumulatedChange:e,originalElements:t,originalElementsMap:o,originalAppState:n,shouldChangeByStepSize:r,nextValue:a,scene:i,property:s,setAppState:l,app:c})=>{let m=i.getNonDeletedElementsMap(),p=Sl(t,n);if(a!==void 0){for(let g of p){let x=kl(g,m,o);if(x.length>1){let E=x.map(M=>M.latest),y=x.map(M=>M.original),[w,v,I,C]=Eg(y),P=I-w,S=C-v,D=P/S,_=Math.max(Ta,s==="width"?Math.max(0,a):P),k=Math.max(Ta,s==="height"?Math.max(0,a):S);w4(_,k,S,D,y4(w,v),s,E,y,o,i)}else{let[E]=x,y=E?.latest,w=E?.original;if(y&&w&&wo(y,s)){let v=s==="width"?Math.max(0,a):y.width;s==="width"&&(r?v=st(v,Pl):v=Math.round(v));let I=s==="height"?Math.max(0,a):y.height;if(s==="height"&&(r?I=st(I,Pl):I=Math.round(I)),v=Math.max(Ta,v),I=Math.max(Ta,I),E4(v,I,y,w,o,i,s==="width"?"e":"s",{shouldInformMutation:!1}),s1(y)){let C=i1(i.getElementsIncludingDeleted(),y,n,i.getNonDeletedElementsMap()),P=v4(i.getElementsIncludingDeleted(),C,y,c);i.replaceAllElements(P)}}}}i.triggerUpdate();return}let d=s==="width"?e:0,u=s==="height"?e:0,h=[];for(let g of p){let x=kl(g,m,o);if(x.length>1){let E=x.map(M=>M.latest),y=x.map(M=>M.original),[w,v,I,C]=Eg(y),P=I-w,S=C-v,D=P/S,_=Math.max(0,P+d);s==="width"&&(r?_=st(_,Pl):_=Math.round(_));let k=Math.max(0,S+u);s==="height"&&(r?k=st(k,Pl):k=Math.round(k)),_=Math.max(Ta,_),k=Math.max(Ta,k),w4(_,k,S,D,y4(w,v),s,E,y,o,i)}else{let[E]=x,y=E?.latest,w=E?.original;if(y&&w&&wo(y,s)){let v=Math.max(0,w.width+d);s==="width"&&(r?v=st(v,Pl):v=Math.round(v));let I=Math.max(0,w.height+u);if(s==="height"&&(r?I=st(I,Pl):I=Math.round(I)),v=Math.max(Ta,v),I=Math.max(Ta,I),E4(v,I,y,w,o,i,s==="width"?"e":"s",{shouldInformMutation:!1}),s1(y)){let C=i1(i.getElementsIncludingDeleted(),y,n,i.getNonDeletedElementsMap());h.push(...C)}}}}l({elementsToHighlight:h}),i.triggerUpdate()},RK=({setAppState:e,app:t,originalElements:o,originalAppState:n})=>{let r=t.scene.getNonDeletedElementsMap(),a=o?.[0],i=a&&r.get(a.id);if(i&&s1(i)){let s=i1(t.scene.getElementsIncludingDeleted(),i,n,t.scene.getNonDeletedElementsMap()),l=v4(t.scene.getElementsIncludingDeleted(),s,i,t);t.scene.replaceAllElements(l),e({elementsToHighlight:null})}},NK=({property:e,elements:t,elementsMap:o,atomicUnits:n,scene:r,appState:a})=>{let i=kK(()=>n.map(c=>{let m=kl(c,o);if(m.length>1){let[d,u,h,g]=Eg(m.map(x=>x.latest));return Math.round((e==="width"?h-d:g-u)*100)/100}let[p]=m;return Math.round((e==="width"?p.latest.width:p.latest.height)*100)/100}),[o,n,e]),s=new Set(i).size===1?Math.round(i[0]*100)/100:"Mixed",l=i.length>0;return BK(zt,{label:e==="width"?"W":"H",elements:t,dragInputCallback:DK,value:s,editable:l,appState:a,property:e,scene:r,dragFinishedCallback:RK})},l1=NK;import{getBoundTextElement as FK,redrawTextBoundingBox as T4}from"@orangecatai/element";import{hasBoundTextElement as OK,isTextElement as zK}from"@orangecatai/element";import{isInGroup as HK}from"@orangecatai/element";import{jsx as $K}from"react/jsx-runtime";var C4=4,GK=4,UK=(e,t)=>e.reduce((o,n)=>{if(!n||HK(n))return o;if(zK(n))return o.push(n),o;if(OK(n)){let r=FK(n,t);if(r)return o.push(r),o}return o},[]),WK=({accumulatedChange:e,originalElements:t,shouldChangeByStepSize:o,nextValue:n,scene:r})=>{let a=r.getNonDeletedElementsMap(),i=t.map(l=>a.get(l.id)),s;if(n){s=Math.max(Math.round(n),C4);for(let l of i)r.mutateElement(l,{fontSize:s}),T4(l,r.getContainerElement(l),r);r.triggerUpdate()}else{let l=t;for(let c=0;c<i.length;c++){let m=i[c],p=l[c],d=Math.round(p.fontSize),u=Math.round(e),h=Math.max(d+u,C4);o&&(h=st(h,GK)),r.mutateElement(m,{fontSize:h}),T4(m,r.getContainerElement(m),r)}r.triggerUpdate()}},YK=({elements:e,scene:t,appState:o,property:n,elementsMap:r})=>{let a=UK(e,r);if(!a.length)return null;let i=a.map(c=>Math.round(c.fontSize*10)/10),s=new Set(i).size===1?i[0]:"Mixed",l=i.length>0;return $K(zt,{label:"F",icon:Va,elements:a,dragInputCallback:WK,value:s,editable:l,scene:t,property:n,appState:o})},k4=YK;import{pointFrom as Ca,pointRotateRads as wg}from"@orangecatai/math";import{useMemo as VK}from"react";import{isTextElement as KK}from"@orangecatai/element";import{getCommonBounds as c1}from"@orangecatai/element";import{jsx as JK}from"react/jsx-runtime";var XK=(e,t,o,n,r,a,i)=>{for(let s=0;s<n.length;s++){let l=n[s],[c,m]=[l.x+l.width/2,l.y+l.height/2],[p,d]=wg(Ca(l.x,l.y),Ca(c,m),l.angle),u=e==="x"?Math.round(p+t):p,h=e==="y"?Math.round(d+o):d;Mi(u,h,l,a,i,r,!1)}},ZK=(e,t,o,n,r,a)=>{let i=r.getNonDeletedElementsMap(),[s,l,,]=c1(o),c=e-s,m=t-l;for(let p=0;p<o.length;p++){let d=o[p],u=i.get(d.id);if(u&&(!KK(u)||!u.containerId)){let[h,g]=[u.x+u.width/2,u.y+u.height/2],[x,E]=wg(Ca(u.x,u.y),Ca(h,g),u.angle);Mi(x+c,E+m,d,r,a,n,!1)}}},jK=({accumulatedChange:e,originalElements:t,originalElementsMap:o,shouldChangeByStepSize:n,nextValue:r,property:a,scene:i,originalAppState:s,app:l})=>{let c=i.getNonDeletedElementsMap();if(r!==void 0){for(let u of Sl(t,s)){let h=kl(u,c,o);if(h.length>1){let[g,x,,]=c1(h.map(w=>w.latest));ZK(a==="x"?r:g,a==="y"?r:x,h.map(w=>w.original),o,i,l.state)}else{let g=h[0]?.original,x=h[0]?.latest;if(g&&x&&wo(x,a)){let[E,y]=[g.x+g.width/2,g.y+g.height/2],[w,v]=wg(Ca(g.x,g.y),Ca(E,y),g.angle);Mi(a==="x"?r:w,a==="y"?r:v,g,i,l.state,o,!1)}}}i.triggerUpdate();return}let m=n?st(e,kd):e;XK(a,a==="x"?m:0,a==="y"?m:0,t,o,i,l.state),i.triggerUpdate()},qK=({property:e,elements:t,elementsMap:o,atomicUnits:n,scene:r,appState:a})=>{let i=VK(()=>n.map(l=>{let c=Object.keys(l).map(g=>o.get(g)).filter(g=>g!==void 0);if(c.length>1){let[g,x]=c1(c);return Math.round((e==="x"?g:x)*100)/100}let[m]=c,[p,d]=[m.x+m.width/2,m.y+m.height/2],[u,h]=wg(Ca(m.x,m.y),Ca(p,d),m.angle);return Math.round((e==="x"?u:h)*100)/100}),[n,o,e]),s=new Set(i).size===1?i[0]:"Mixed";return JK(zt,{label:e==="x"?"X":"Y",elements:t,dragInputCallback:jK,value:s,property:e,scene:r,appState:a})},d1=qK;import{clamp as Sd,pointFrom as vg,pointRotateRads as M4,round as S4}from"@orangecatai/math";import{getFlipAdjustedCropPosition as QK,getUncroppedWidthAndHeight as eX}from"@orangecatai/element";import{isImageElement as P4}from"@orangecatai/element";import{jsx as nX}from"react/jsx-runtime";var tX=({accumulatedChange:e,instantChange:t,originalElements:o,originalElementsMap:n,shouldChangeByStepSize:r,nextValue:a,property:i,scene:s,originalAppState:l,app:c})=>{let m=s.getNonDeletedElementsMap(),p=o[0],[d,u]=[p.x+p.width/2,p.y+p.height/2],[h,g]=M4(vg(p.x,p.y),vg(d,u),p.angle);if(l.croppingElementId===p.id){let v=m.get(p.id);if(!v||!P4(v)||!v.crop)return;let I=v.crop,C=I,P=v.scale[0]===-1,S=v.scale[1]===-1,{width:D,height:_}=eX(v);if(a!==void 0){if(i==="x"){let B=a*(I.naturalWidth/D);P?C={...I,x:Sd(I.naturalWidth-B-I.width,0,I.naturalWidth-I.width)}:C={...I,x:Sd(a*(I.naturalWidth/D),0,I.naturalWidth-I.width)}}i==="y"&&(C={...I,y:Sd(a*(I.naturalHeight/_),0,I.naturalHeight-I.height)}),s.mutateElement(v,{crop:C});return}let k=(i==="x"?t:0)*(P?-1:1),M=(i==="y"?t:0)*(S?-1:1);C={...I,x:Sd(I.x+k,0,I.naturalWidth-I.width),y:Sd(I.y+M,0,I.naturalHeight-I.height)},s.mutateElement(v,{crop:C});return}if(a!==void 0){Mi(i==="x"?a:h,i==="y"?a:g,p,s,c.state,n);return}let x=i==="x"?e:0,E=i==="y"?e:0,y=i==="x"?Math.round(r?st(p.x+x,kd):h+x):h,w=i==="y"?Math.round(r?st(p.y+E,kd):g+E):g;Mi(y,w,p,s,c.state,n)},oX=({property:e,element:t,elementsMap:o,scene:n,appState:r})=>{let[a,i]=M4(vg(t.x,t.y),vg(t.x+t.width/2,t.y+t.height/2),t.angle),s=S4(e==="x"?a:i,2);if(r.croppingElementId===t.id&&P4(t)&&t.crop){let l=QK(t);l&&(s=S4(e==="x"?l.x:l.y,2))}return nX(zt,{label:e==="x"?"X":"Y",elements:[t],dragInputCallback:tX,scene:n,value:s,property:e,appState:r})},m1=oX;import{Fragment as g1,jsx as me,jsxs as vo}from"react/jsx-runtime";var pX=50,Md=e=>{let t=$o(),o=e.app.scene.getSceneNonce()||1,n=e.app.scene.getSelectedElements({selectedElementIds:t.selectedElementIds,includeBoundTextElement:!1}),r=ma(e.app);return me(uX,{...e,appState:t,sceneNonce:o,selectedElements:n,gridModeEnabled:r})},ot=({children:e,columns:t=1,heading:o,style:n,...r})=>me("div",{className:rX("exc-stats__row",{"exc-stats__row--heading":o}),style:{gridTemplateColumns:`repeat(${t}, 1fr)`,...n},...r,children:e});ot.displayName="StatsRow";var Tg=({children:e,order:t,style:o,...n})=>me("div",{className:"exc-stats__rows",style:{order:t,...o},...n,children:e});Tg.displayName="StatsRows";Md.StatsRow=ot;Md.StatsRows=Tg;var uX=sX(({app:e,onClose:t,renderCustomStats:o,selectedElements:n,appState:r,sceneNonce:a,gridModeEnabled:i})=>{let s=e.scene,l=s.getNonDeletedElements(),c=s.getNonDeletedElementsMap(),m=Ce(),p=n.length===1?n[0]:null,d=n.length>1?n:null,u=r.croppingElementId&&u1(p),h=u?cX(p):null,[g,x]=iX({width:0,height:0}),E=p1(()=>aX(v=>{let I=lX(v);x({width:Math.round(I[2])-Math.round(I[0]),height:Math.round(I[3])-Math.round(I[1])})},pX),[]);L4(()=>{E(l)},[a,l,E]),L4(()=>()=>E.cancel(),[E]);let y=p1(()=>Sl(n,r),[n,r]),w=p1(()=>dX(n),[n]);return me("div",{className:"exc-stats",children:vo(gt,{padding:3,children:[vo("div",{className:"title",children:[me("h2",{children:f("stats.title")}),me("div",{className:"close",onClick:t,children:Go})]}),vo(wc,{label:me("h3",{children:f("stats.generalStats")}),open:!!(r.stats.panels&Ig.generalStats),openTrigger:()=>m(v=>({stats:{open:!0,panels:v.stats.panels^Ig.generalStats}})),children:[vo(Tg,{children:[me(ot,{heading:!0,children:f("stats.scene")}),vo(ot,{columns:2,children:[me("div",{children:f("stats.shapes")}),me("div",{children:l.length})]}),vo(ot,{columns:2,children:[me("div",{children:f("stats.width")}),me("div",{children:g.width})]}),vo(ot,{columns:2,children:[me("div",{children:f("stats.height")}),me("div",{children:g.height})]}),i&&vo(g1,{children:[me(ot,{heading:!0,children:"Canvas"}),me(ot,{children:me(r4,{property:"gridStep",scene:s,appState:r,setAppState:m})})]})]}),o?.(l,r)]}),!w&&n.length>0&&me("div",{id:"elementStats",style:{marginTop:12},children:me(wc,{label:me("h3",{children:f("stats.elementProperties")}),open:!!(r.stats.panels&Ig.elementProperties),openTrigger:()=>m(v=>({stats:{open:!0,panels:v.stats.panels^Ig.elementProperties}})),children:vo(Tg,{children:[p&&vo(g1,{children:[u&&me(ot,{heading:!0,children:f("labels.unCroppedDimension")}),r.croppingElementId&&u1(p)&&h&&vo(ot,{columns:2,children:[me("div",{children:f("stats.width")}),me("div",{children:A4(h.width,2)})]}),r.croppingElementId&&u1(p)&&h&&vo(ot,{columns:2,children:[me("div",{children:f("stats.height")}),me("div",{children:A4(h.height,2)})]}),me(ot,{heading:!0,"data-testid":"stats-element-type",style:{margin:"0.3125rem 0"},children:r.croppingElementId?f("labels.imageCropping"):f(`element.${p.type}`)}),me(ot,{children:me(m1,{element:p,property:"x",elementsMap:c,scene:s,appState:r})}),me(ot,{children:me(m1,{element:p,property:"y",elementsMap:c,scene:s,appState:r})}),me(ot,{children:me(r1,{property:"width",element:p,scene:s,appState:r})}),me(ot,{children:me(r1,{property:"height",element:p,scene:s,appState:r})}),me(ot,{children:me(o4,{property:"angle",element:p,scene:s,appState:r})}),me(ot,{children:me(u4,{property:"fontSize",element:p,scene:s,appState:r})})]}),d&&vo(g1,{children:[mX(d)&&me(ot,{heading:!0,children:f("element.group")}),vo(ot,{columns:2,style:{margin:"0.3125rem 0"},children:[me("div",{children:f("stats.shapes")}),me("div",{children:n.length})]}),me(ot,{children:me(d1,{property:"x",elements:d,elementsMap:c,atomicUnits:y,scene:s,appState:r})}),me(ot,{children:me(d1,{property:"y",elements:d,elementsMap:c,atomicUnits:y,scene:s,appState:r})}),me(ot,{children:me(l1,{property:"width",elements:d,elementsMap:c,atomicUnits:y,scene:s,appState:r})}),me(ot,{children:me(l1,{property:"height",elements:d,elementsMap:c,atomicUnits:y,scene:s,appState:r})}),me(ot,{children:me(x4,{property:"angle",elements:d,scene:s,appState:r})}),me(ot,{children:me(k4,{property:"fontSize",elements:d,scene:s,appState:r,elementsMap:c})})]})]})})})]})})},(e,t)=>e.sceneNonce===t.sceneNonce&&e.selectedElements===t.selectedElements&&e.appState.stats.panels===t.appState.stats.panels&&e.gridModeEnabled===t.gridModeEnabled&&e.appState.gridStep===t.appState.gridStep&&e.appState.croppingElementId===t.appState.croppingElementId);import{useCallback as gX,useEffect as _4,useState as D4}from"react";import{normalizeLink as hX,KEYS as h1}from"@orangecatai/common";import{defaultGetElementLinkFromSelection as fX,getLinkIdAndTypeFromSelection as bX}from"@orangecatai/element";import{jsx as Al,jsxs as Cg}from"react/jsx-runtime";var xX=({sourceElementId:e,onClose:t,appState:o,scene:n,generateLinkForSelection:r=fX})=>{let a=n.getNonDeletedElementsMap(),i=a.get(e)?.link??null,[s,l]=D4(i),[c,m]=D4(!1);_4(()=>{let d=de(a,o),u=i;if(d.length>0&&r){let h=bX(d,o);h&&(u=hX(r(h.id,h.type)))}l(u)},[a,o,o.selectedElementIds,i,r]);let p=gX(()=>{if(s&&s!==a.get(e)?.link){let d=a.get(e);d&&n.mutateElement(d,{link:s})}if(!s&&c&&e){let d=a.get(e);d&&n.mutateElement(d,{link:null})}t?.()},[e,s,a,c,n,t]);return _4(()=>{let d=u=>{o.openDialog?.name==="elementLinkSelector"&&u.key===h1.ENTER&&p(),o.openDialog?.name==="elementLinkSelector"&&u.key===h1.ESCAPE&&t?.()};return window.addEventListener("keydown",d),()=>{window.removeEventListener("keydown",d)}},[o,t,p]),Cg("div",{className:"ElementLinkDialog",children:[Cg("div",{className:"ElementLinkDialog__header",children:[Al("h2",{children:f("elementLink.title")}),Al("p",{children:f("elementLink.desc")})]}),Cg("div",{className:"ElementLinkDialog__input",children:[Al(ia,{value:s??"",onChange:d=>{c||m(!0),l(d)},onKeyDown:d=>{d.key===h1.ENTER&&p()},className:"ElementLinkDialog__input-field",selectOnRender:!0}),i&&s&&Al(ae,{type:"button",title:f("buttons.remove"),"aria-label":f("buttons.remove"),label:f("buttons.remove"),onClick:()=>{l(null),m(!0)},className:"ElementLinkDialog__remove",icon:Ut})]}),Cg("div",{className:"ElementLinkDialog__actions",children:[Al(vr,{label:f("buttons.cancel"),onClick:()=>{t?.()},style:{marginRight:10}}),Al(vr,{label:f("buttons.confirm"),onClick:p,actionType:"primary"})]})]})},R4=xX;import yX,{useState as EX}from"react";import{Fragment as wX,jsx as f1}from"react/jsx-runtime";var N4=({children:e,onClose:t})=>{let[o,n]=EX(!!e),{container:r}=Qe(),a=yX.useCallback(()=>{n(!1),t&&t(),r?.focus()},[t,r]);return f1(wX,{children:o&&f1(bt,{size:"small",onCloseRequest:a,title:f("errorDialog.title"),children:f1("div",{style:{whiteSpace:"pre-wrap"},children:e})})})};import vX from"react";import{isDarwin as B4,isFirefox as F4,isWindows as IX}from"@orangecatai/common";import{KEYS as ut}from"@orangecatai/common";import{Fragment as z4,jsx as j,jsxs as No}from"react/jsx-runtime";var TX=()=>No("div",{className:"HelpDialog__header",children:[No("a",{className:"HelpDialog__btn",href:"https://docs.excalidraw.com",target:"_blank",rel:"noopener",children:[j("div",{className:"HelpDialog__link-icon",children:xh}),f("helpDialog.documentation")]}),No("a",{className:"HelpDialog__btn",href:"https://plus.excalidraw.com/blog",target:"_blank",rel:"noopener",children:[j("div",{className:"HelpDialog__link-icon",children:xh}),f("helpDialog.blog")]}),No("a",{className:"HelpDialog__btn",href:"https://github.com/excalidraw/excalidraw/issues",target:"_blank",rel:"noopener noreferrer",children:[j("div",{className:"HelpDialog__link-icon",children:fm}),f("helpDialog.github")]}),No("a",{className:"HelpDialog__btn",href:"https://youtube.com/@excalidraw",target:"_blank",rel:"noopener noreferrer",children:[j("div",{className:"HelpDialog__link-icon",children:lv}),"YouTube"]})]}),CX=e=>No(z4,{children:[j("h3",{children:e.title}),j("div",{className:"HelpDialog__islands-container",children:e.children})]}),b1=e=>No("div",{className:`HelpDialog__island ${e.className}`,children:[j("h4",{className:"HelpDialog__island-title",children:e.caption}),j("div",{className:"HelpDialog__island-content",children:e.children})]});function*kX(e,t){let o=!0;for(let n of e)o||(yield t),o=!1,yield n}var SX=e=>e.replace(/\b[a-z]\b/,t=>t.toUpperCase()),te=({label:e,shortcuts:t,isOr:o=!0})=>{let n=t.map(r=>(r.endsWith("++")?[...r.slice(0,-2).split("+"),"+"]:r.split("+")).map(i=>j(MX,{children:SX(i)},i)));return No("div",{className:"HelpDialog__shortcut",children:[j("div",{children:e}),j("div",{className:"HelpDialog__key-container",children:[...kX(n,o?f("helpDialog.or"):null)]})]})},MX=e=>j("kbd",{className:"HelpDialog__key",...e}),O4=({onClose:e})=>{let t=vX.useCallback(()=>{e&&e()},[e]);return j(z4,{children:No(bt,{onCloseRequest:t,title:f("helpDialog.title"),className:"HelpDialog",children:[j(TX,{}),No(CX,{title:f("helpDialog.shortcuts"),children:[No(b1,{className:"HelpDialog__island--tools",caption:f("helpDialog.tools"),children:[j(te,{label:f("toolBar.hand"),shortcuts:[ut.H]}),j(te,{label:f("toolBar.selection"),shortcuts:[ut.V,ut[1]]}),j(te,{label:f("toolBar.rectangle"),shortcuts:[ut.R,ut[2]]}),j(te,{label:f("toolBar.diamond"),shortcuts:[ut.D,ut[3]]}),j(te,{label:f("toolBar.ellipse"),shortcuts:[ut.O,ut[4]]}),j(te,{label:f("toolBar.arrow"),shortcuts:[ut.A,ut[5]]}),j(te,{label:f("toolBar.line"),shortcuts:[ut.L,ut[6]]}),j(te,{label:f("toolBar.freedraw"),shortcuts:[ut.P,ut[7]]}),j(te,{label:f("toolBar.text"),shortcuts:[ut.T,ut[8]]}),j(te,{label:f("toolBar.image"),shortcuts:[ut[9]]}),j(te,{label:f("toolBar.eraser"),shortcuts:[ut.E,ut[0]]}),j(te,{label:f("toolBar.frame"),shortcuts:[ut.F]}),j(te,{label:f("toolBar.laser"),shortcuts:[ut.K]}),j(te,{label:f("labels.eyeDropper"),shortcuts:[ut.I,"Shift+S","Shift+G"]}),j(te,{label:f("helpDialog.editLineArrowPoints"),shortcuts:[G("CtrlOrCmd+Enter")]}),j(te,{label:f("helpDialog.editText"),shortcuts:[G("Enter")]}),j(te,{label:f("helpDialog.textNewLine"),shortcuts:[G("Enter"),G("Shift+Enter")]}),j(te,{label:f("helpDialog.textFinish"),shortcuts:[G("Esc"),G("CtrlOrCmd+Enter")]}),j(te,{label:f("helpDialog.curvedArrow"),shortcuts:["A",f("helpDialog.click"),f("helpDialog.click"),f("helpDialog.click")],isOr:!1}),j(te,{label:f("helpDialog.curvedLine"),shortcuts:["L",f("helpDialog.click"),f("helpDialog.click"),f("helpDialog.click")],isOr:!1}),j(te,{label:f("helpDialog.cropStart"),shortcuts:[f("helpDialog.doubleClick"),G("Enter")],isOr:!0}),j(te,{label:f("helpDialog.cropFinish"),shortcuts:[G("Enter"),G("Escape")],isOr:!0}),j(te,{label:f("toolBar.lock"),shortcuts:[ut.Q]}),j(te,{label:f("helpDialog.preventBinding"),shortcuts:[G("CtrlOrCmd")]}),j(te,{label:f("toolBar.link"),shortcuts:[G("CtrlOrCmd+K")]}),j(te,{label:f("toolBar.convertElementType"),shortcuts:["Tab","Shift+Tab"],isOr:!0})]}),No(b1,{className:"HelpDialog__island--view",caption:f("helpDialog.view"),children:[j(te,{label:f("buttons.zoomIn"),shortcuts:[G("CtrlOrCmd++")]}),j(te,{label:f("buttons.zoomOut"),shortcuts:[G("CtrlOrCmd+-")]}),j(te,{label:f("buttons.resetZoom"),shortcuts:[G("CtrlOrCmd+0")]}),j(te,{label:f("helpDialog.zoomToFit"),shortcuts:["Shift+1"]}),j(te,{label:f("helpDialog.zoomToSelection"),shortcuts:["Shift+2"]}),j(te,{label:f("helpDialog.movePageUpDown"),shortcuts:["PgUp/PgDn"]}),j(te,{label:f("helpDialog.movePageLeftRight"),shortcuts:["Shift+PgUp/PgDn"]}),j(te,{label:f("buttons.zenMode"),shortcuts:[G("Alt+Z")]}),j(te,{label:f("buttons.objectsSnapMode"),shortcuts:[G("Alt+S")]}),j(te,{label:f("labels.toggleGrid"),shortcuts:[G("CtrlOrCmd+'")]}),j(te,{label:f("labels.viewMode"),shortcuts:[G("Alt+R")]}),j(te,{label:f("labels.toggleTheme"),shortcuts:[G("Alt+Shift+D")]}),j(te,{label:f("stats.fullTitle"),shortcuts:[G("Alt+/")]}),j(te,{label:f("search.title"),shortcuts:[Xe("searchMenu")]}),j(te,{label:f("commandPalette.title"),shortcuts:F4?[Xe("commandPalette")]:[Xe("commandPalette"),Xe("commandPalette",1)]})]}),No(b1,{className:"HelpDialog__island--editor",caption:f("helpDialog.editor"),children:[j(te,{label:f("helpDialog.createFlowchart"),shortcuts:[G("CtrlOrCmd+Arrow Key")],isOr:!0}),j(te,{label:f("helpDialog.navigateFlowchart"),shortcuts:[G("Alt+Arrow Key")],isOr:!0}),j(te,{label:f("labels.moveCanvas"),shortcuts:[G(`Space+${f("helpDialog.drag")}`),G(`Wheel+${f("helpDialog.drag")}`)],isOr:!0}),j(te,{label:f("buttons.clearReset"),shortcuts:[G("CtrlOrCmd+Delete")]}),j(te,{label:f("labels.delete"),shortcuts:[G("Delete")]}),j(te,{label:f("labels.cut"),shortcuts:[G("CtrlOrCmd+X")]}),j(te,{label:f("labels.copy"),shortcuts:[G("CtrlOrCmd+C")]}),j(te,{label:f("labels.paste"),shortcuts:[G("CtrlOrCmd+V")]}),j(te,{label:f("labels.pasteAsPlaintext"),shortcuts:[G("CtrlOrCmd+Shift+V")]}),j(te,{label:f("labels.selectAll"),shortcuts:[G("CtrlOrCmd+A")]}),j(te,{label:f("labels.multiSelect"),shortcuts:[G(`Shift+${f("helpDialog.click")}`)]}),j(te,{label:f("helpDialog.deepSelect"),shortcuts:[G(`CtrlOrCmd+${f("helpDialog.click")}`)]}),j(te,{label:f("helpDialog.deepBoxSelect"),shortcuts:[G(`CtrlOrCmd+${f("helpDialog.drag")}`)]}),(Ps||F4)&&j(te,{label:f("labels.copyAsPng"),shortcuts:[G("Shift+Alt+C")]}),j(te,{label:f("labels.copyStyles"),shortcuts:[G("CtrlOrCmd+Alt+C")]}),j(te,{label:f("labels.pasteStyles"),shortcuts:[G("CtrlOrCmd+Alt+V")]}),j(te,{label:f("labels.sendToBack"),shortcuts:[B4?G("CtrlOrCmd+Alt+["):G("CtrlOrCmd+Shift+[")]}),j(te,{label:f("labels.bringToFront"),shortcuts:[B4?G("CtrlOrCmd+Alt+]"):G("CtrlOrCmd+Shift+]")]}),j(te,{label:f("labels.sendBackward"),shortcuts:[G("CtrlOrCmd+[")]}),j(te,{label:f("labels.bringForward"),shortcuts:[G("CtrlOrCmd+]")]}),j(te,{label:f("labels.alignTop"),shortcuts:[G("CtrlOrCmd+Shift+Up")]}),j(te,{label:f("labels.alignBottom"),shortcuts:[G("CtrlOrCmd+Shift+Down")]}),j(te,{label:f("labels.alignLeft"),shortcuts:[G("CtrlOrCmd+Shift+Left")]}),j(te,{label:f("labels.alignRight"),shortcuts:[G("CtrlOrCmd+Shift+Right")]}),j(te,{label:f("labels.duplicateSelection"),shortcuts:[G("CtrlOrCmd+D"),G(`Alt+${f("helpDialog.drag")}`)]}),j(te,{label:f("helpDialog.toggleElementLock"),shortcuts:[G("CtrlOrCmd+Shift+L")]}),j(te,{label:f("buttons.undo"),shortcuts:[G("CtrlOrCmd+Z")]}),j(te,{label:f("buttons.redo"),shortcuts:IX?[G("CtrlOrCmd+Y"),G("CtrlOrCmd+Shift+Z")]:[G("CtrlOrCmd+Shift+Z")]}),j(te,{label:f("labels.group"),shortcuts:[G("CtrlOrCmd+G")]}),j(te,{label:f("labels.ungroup"),shortcuts:[G("CtrlOrCmd+Shift+G")]}),j(te,{label:f("labels.flipHorizontal"),shortcuts:[G("Shift+H")]}),j(te,{label:f("labels.flipVertical"),shortcuts:[G("Shift+V")]}),j(te,{label:f("labels.showStroke"),shortcuts:[G("S")]}),j(te,{label:f("labels.showBackground"),shortcuts:[G("G")]}),j(te,{label:f("labels.showFonts"),shortcuts:[G("Shift+F")]}),j(te,{label:f("labels.decreaseFontSize"),shortcuts:[G("CtrlOrCmd+Shift+<")]}),j(te,{label:f("labels.increaseFontSize"),shortcuts:[G("CtrlOrCmd+Shift+>")]})]})]})]})})};import{CANVAS_SEARCH_TAB as PX,DEFAULT_SIDEBAR as AX}from"@orangecatai/common";import{isFlowchartNodeElement as LX,isImageElement as H4,isLinearElement as G4,isLineElement as _X,isTextBindableContainer as DX,isTextElement as RX}from"@orangecatai/element";import{isNodeInFlowchart as NX}from"@orangecatai/element";import{jsx as x1}from"react/jsx-runtime";var Oe=e=>Array.isArray(e)?`<kbd>${e.map(G).join(" + ")}</kbd>`:`<kbd>${G(e)}</kbd>`,BX=({appState:e,isMobile:t,editorInterface:o,app:n})=>{let{activeTool:r,isResizing:a,isRotating:i,lastPointerDownWith:s}=e,l=e.multiElement!==null;if(e.openSidebar?.name===AX.name&&e.openSidebar.tab===PX&&e.searchMatches?.matches.length)return f("hints.dismissSearch",{shortcut:Oe("Escape")});if(e.openSidebar&&!o.canFitSidebar)return null;if(ho(e))return f("hints.eraserRevert",{shortcut:Oe("Alt")});let c=n.scene.getSelectedElements(e);if(e.selectedLinearElement?.isDragging&&c[0]?.type==="arrow")return f("hints.arrowBindModifiers",{shortcut_1:Oe("Ctrl"),shortcut_2:Oe("Alt")});if(r.type==="arrow"||r.type==="line")return l?f("hints.linearElementMulti",{shortcut_1:Oe("Escape"),shortcut_2:Oe("Enter")}):r.type==="arrow"?f("hints.arrowTool",{shortcut:Oe("A")}):f("hints.linearElement");if(r.type==="freedraw")return f("hints.freeDraw");if(r.type==="text")return f("hints.text");if(r.type==="embeddable")return f("hints.embeddable");if(a&&s==="mouse"&&c.length===1){let m=c[0];return G4(m)&&m.points.length===2?f("hints.lockAngle",{shortcut:Oe("Shift")}):H4(m)?f("hints.resizeImage",{shortcut_1:Oe("Shift"),shortcut_2:Oe("Alt")}):f("hints.resize",{shortcut_1:Oe("Shift"),shortcut_2:Oe("Alt")})}if(i&&s==="mouse")return f("hints.rotate",{shortcut:Oe("Shift")});if(c.length===1&&RX(c[0]))return f("hints.text_selected",{shortcut:Oe("Enter")});if(e.editingTextElement)return f("hints.text_editing",{shortcut_1:Oe("Escape"),shortcut_2:Oe(["CtrlOrCmd","Enter"])});if(e.croppingElementId)return f("hints.leaveCropEditor",{shortcut_1:Oe("Enter"),shortcut_2:Oe("Escape")});if(c.length===1&&H4(c[0]))return f("hints.enterCropEditor",{shortcut:Oe("Enter")});if(r.type==="selection"){if(e.selectionElement&&!c.length&&!e.editingTextElement&&!e.selectedLinearElement?.isEditing)return f("hints.deepBoxSelect",{shortcut:Oe("CtrlOrCmd")});if(ma(n)&&e.selectedElementsAreBeingDragged)return f("hints.disableSnapping",{shortcut:Oe("CtrlOrCmd")});if(!c.length&&!t)return f("hints.canvasPanning",{shortcut_1:Oe(f("keys.mmb")),shortcut_2:Oe("Space")});if(c.length===1){if(G4(c[0]))return e.selectedLinearElement?.isEditing?e.selectedLinearElement.selectedPointsIndices?f("hints.lineEditor_pointSelected",{shortcut_1:Oe("Delete"),shortcut_2:Oe(["CtrlOrCmd","D"])}):f("hints.lineEditor_nothingSelected",{shortcut_1:Oe("Shift"),shortcut_2:Oe("Alt")}):_X(c[0])?f("hints.lineEditor_line_info",{shortcut:Oe("Enter")}):f("hints.lineEditor_info",{shortcut_1:Oe("CtrlOrCmd"),shortcut_2:Oe(["CtrlOrCmd","Enter"])});if(!e.newElement&&!e.selectedElementsAreBeingDragged&&DX(c[0])){let m=f("hints.bindTextToElement",{shortcut:Oe("Enter")}),p=f("hints.createFlowchart",{shortcut:Oe(["CtrlOrCmd","\u2191\u2193"])});return LX(c[0])?NX(c[0],n.scene.getNonDeletedElementsMap())?[m,p]:[m,p]:m}}}return null},U4=({appState:e,isMobile:t,editorInterface:o,app:n})=>{let r=BX({appState:e,isMobile:t,editorInterface:o,app:n});if(!r)return null;let i=(Array.isArray(r)?r.map(s=>s.replace(/\. ?$/,"")).join(", "):r).split(/(<kbd>[^<]+<\/kbd>)/g).map((s,l)=>{if(l%2===1){let c=s[0]==="<"&&s.match(/^<kbd>([^<]+)<\/kbd>$/);return x1("kbd",{children:c?c[1]:s},l)}return s});return x1("div",{className:"HintViewer",children:x1("span",{children:i})})};import{useEffect as $4,useRef as UX,useState as ka}from"react";import{DEFAULT_EXPORT_PADDING as WX,EXPORT_IMAGE_TYPES as y1,isFirefox as YX,EXPORT_SCALES as $X,cloneJSON as V4}from"@orangecatai/common";import{useCallback as FX,useRef as OX,useState as zX}from"react";var HX=2e3,W4=()=>{let[e,t]=zX(null),o=OX(0),n=()=>{clearTimeout(o.current),t("success"),o.current=window.setTimeout(()=>{t(null)},HX)},r=FX(()=>{t(null)},[]);return{copyStatus:e,resetCopyStatus:r,onCopy:n}};import GX from"clsx";import{jsx as Y4}from"react/jsx-runtime";var Pd=({title:e,name:t,checked:o,onChange:n,disabled:r=!1})=>Y4("div",{className:GX("Switch",{toggled:o,disabled:r}),children:Y4("input",{name:t,id:t,title:e,type:"checkbox",checked:o,disabled:r,onChange:()=>n(!o),onKeyDown:a=>{a.key===" "&&n(!o)}})});import{jsx as nt,jsxs as Sa}from"react/jsx-runtime";var VX=()=>Sa("div",{children:[nt("h3",{children:f("canvasError.cannotShowPreview")}),nt("p",{children:nt("span",{children:f("canvasError.canvasTooBig")})}),Sa("em",{children:["(",f("canvasError.canvasTooBigTip"),")"]})]}),KX=({appStateSnapshot:e,elementsSnapshot:t,files:o,actionManager:n,onExportImage:r,name:a})=>{let i=Ge(t,e),[s,l]=ka(a),[c,m]=ka(i),[p,d]=ka(e.exportBackground),[u,h]=ka(e.exportWithDarkMode),[g,x]=ka(e.exportEmbedScene),[E,y]=ka(e.exportScale),w=UX(null),[v,I]=ka(null),{onCopy:C,copyStatus:P,resetCopyStatus:S}=W4();$4(()=>{S()},[s,p,u,E,g,S]);let{exportedElements:D,exportingFrame:_}=Qa(t,e,c);return $4(()=>{let k=w.current;if(!k)return;let M=k.offsetWidth,B=k.offsetHeight;M&&na({elements:D,appState:{...e,name:s,exportBackground:p,exportWithDarkMode:u,exportScale:E,exportEmbedScene:g},files:o,exportPadding:WX,maxWidthOrHeight:Math.max(M,B),exportingFrame:_}).then(O=>(I(null),Ua(O).then(()=>{k.replaceChildren(O)}).catch(N=>{throw N.name==="CANVAS_POSSIBLY_TOO_BIG"?new Error(f("canvasError.canvasTooBig")):N}))).catch(O=>{console.error(O),I(O)})},[e,o,D,_,s,p,u,E,g]),Sa("div",{className:"ImageExportModal",children:[nt("h3",{children:f("imageExportDialog.header")}),Sa("div",{className:"ImageExportModal__preview",children:[nt("div",{className:"ImageExportModal__preview__canvas",ref:w,children:v&&nt(VX,{})}),nt("div",{className:"ImageExportModal__preview__filename",children:!Wi&&nt("input",{type:"text",className:"TextInput",value:s,style:{width:"30ch"},onChange:k=>{l(k.target.value),n.executeAction(Hf,"ui",k.target.value)}})})]}),Sa("div",{className:"ImageExportModal__settings",children:[nt("h3",{children:f("imageExportDialog.header")}),i&&nt(Ad,{label:f("imageExportDialog.label.onlySelected"),name:"exportOnlySelected",children:nt(Pd,{name:"exportOnlySelected",checked:c,onChange:k=>{m(k)}})}),nt(Ad,{label:f("imageExportDialog.label.withBackground"),name:"exportBackgroundSwitch",children:nt(Pd,{name:"exportBackgroundSwitch",checked:p,onChange:k=>{d(k),n.executeAction(Gf,"ui",k)}})}),nt(Ad,{label:f("imageExportDialog.label.darkMode"),name:"exportDarkModeSwitch",children:nt(Pd,{name:"exportDarkModeSwitch",checked:u,onChange:k=>{h(k),n.executeAction(bI,"ui",k)}})}),nt(Ad,{label:f("imageExportDialog.label.embedScene"),tooltip:f("imageExportDialog.tooltip.embedScene"),name:"exportEmbedSwitch",children:nt(Pd,{name:"exportEmbedSwitch",checked:g,onChange:k=>{x(k),n.executeAction(cp,"ui",k)}})}),nt(Ad,{label:f("imageExportDialog.label.scale"),name:"exportScale",children:nt(Qu,{name:"exportScale",value:E,onChange:k=>{y(k),n.executeAction(fI,"ui",k)},choices:$X.map(k=>({value:k,label:`${k}\xD7`}))})}),Sa("div",{className:"ImageExportModal__settings__buttons",children:[nt(on,{className:"ImageExportModal__settings__buttons__button",label:f("imageExportDialog.title.exportToPng"),onClick:()=>r(y1.png,D,{exportingFrame:_}),icon:Nh,children:f("imageExportDialog.button.exportToPng")}),nt(on,{className:"ImageExportModal__settings__buttons__button",label:f("imageExportDialog.title.exportToSvg"),onClick:()=>r(y1.svg,D,{exportingFrame:_}),icon:Nh,children:f("imageExportDialog.button.exportToSvg")}),(Ps||YX)&&nt(on,{className:"ImageExportModal__settings__buttons__button",label:f("imageExportDialog.title.copyPngToClipboard"),status:P,onClick:async()=>{await r(y1.clipboard,D,{exportingFrame:_}),C()},icon:is,children:f("imageExportDialog.button.copyPngToClipboard")})]})]})]})},Ad=({label:e,children:t,tooltip:o,name:n})=>Sa("div",{className:"ImageExportModal__settings__setting",title:e,children:[Sa("label",{htmlFor:n,className:"ImageExportModal__settings__setting__label",children:[e,o&&nt(Xt,{label:o,long:!0,children:zw})]}),nt("div",{className:"ImageExportModal__settings__setting__content",children:t})]}),K4=({elements:e,appState:t,files:o,actionManager:n,onExportImage:r,onCloseRequest:a,name:i})=>{let[{appStateSnapshot:s,elementsSnapshot:l}]=ka(()=>({appStateSnapshot:V4(t),elementsSnapshot:V4(e)}));return nt(bt,{onCloseRequest:a,size:"wide",title:!1,children:nt(KX,{elementsSnapshot:l,appStateSnapshot:s,files:o,actionManager:n,onExportImage:r,name:i})})};import ZX from"react";import{getFrame as jX}from"@orangecatai/common";import{jsx as XX}from"react/jsx-runtime";var E1={primary:{base:"var(--color-primary)",darker:"var(--color-primary-darker)",darkest:"var(--color-primary-darkest)"},lime:{base:"#74b816",darker:"#66a80f",darkest:"#5c940d"},pink:{base:"#d6336c",darker:"#c2255c",darkest:"#a61e4d"}},w1=({children:e,color:t})=>XX("div",{className:"Card",style:{"--card-color":E1[t].base,"--card-color-darker":E1[t].darker,"--card-color-darkest":E1[t].darkest},children:e});import{Fragment as JX,jsx as Tn,jsxs as kg}from"react/jsx-runtime";var qX=({elements:e,appState:t,setAppState:o,files:n,actionManager:r,exportOpts:a,canvas:i,onCloseRequest:s})=>{let{onExportToBackend:l}=a;return Tn("div",{className:"ExportDialog ExportDialog--json",children:kg("div",{className:"ExportDialog-cards",children:[a.saveFileToDisk&&kg(w1,{color:"lime",children:[Tn("div",{className:"Card-icon",children:VE}),Tn("h2",{children:f("exportDialog.disk_title")}),kg("div",{className:"Card-details",children:[f("exportDialog.disk_details"),!Wi&&r.renderAction("changeProjectName")]}),Tn(ae,{className:"Card-button",type:"button",title:f("exportDialog.disk_button"),"aria-label":f("exportDialog.disk_button"),showAriaLabel:!0,onClick:()=>{r.executeAction(Ac,"ui")}})]}),l&&kg(w1,{color:"pink",children:[Tn("div",{className:"Card-icon",children:rc}),Tn("h2",{children:f("exportDialog.link_title")}),Tn("div",{className:"Card-details",children:f("exportDialog.link_details")}),Tn(ae,{className:"Card-button",type:"button",title:f("exportDialog.link_button"),"aria-label":f("exportDialog.link_button"),showAriaLabel:!0,onClick:async()=>{try{be("export","link",`ui (${jX()})`),await l(e,t,n),s()}catch(c){o({errorMessage:c.message})}}})]}),a.renderCustomUI&&a.renderCustomUI(e,t,n,i)]})})},X4=({elements:e,appState:t,files:o,actionManager:n,exportOpts:r,canvas:a,setAppState:i})=>{let s=ZX.useCallback(()=>{i({openDialog:null})},[i]);return Tn(JX,{children:t.openDialog?.name==="jsonExport"&&Tn(bt,{onCloseRequest:s,title:f("buttons.export"),children:Tn(qX,{elements:e,appState:t,setAppState:i,files:o,actionManager:n,onCloseRequest:s,exportOpts:r,canvas:a})})})};import QX from"clsx";import{jsx as Z4,jsxs as tZ}from"react/jsx-runtime";var eZ="small",j4=e=>tZ("label",{className:QX("ToolIcon ToolIcon__LaserPointer",`ToolIcon_size_${eZ}`,{"is-mobile":e.isMobile}),title:`${e.title}`,children:[Z4("input",{className:"ToolIcon_type_checkbox",type:"checkbox",name:e.name,onChange:e.onChange,checked:e.checked,"aria-label":e.title,"data-testid":"toolbar-LaserPointer"}),Z4("div",{className:"ToolIcon__icon",children:zn})]});import{Fragment as Q4,jsx as ce,jsxs as Bo}from"react/jsx-runtime";var cZ=({UIOptions:e})=>Bo(jt,{__fallback:!0,children:[ce(jt.DefaultItems.LoadScene,{}),ce(jt.DefaultItems.SaveToActiveFile,{}),e.canvasActions.export&&ce(jt.DefaultItems.Export,{}),e.canvasActions.saveAsImage&&ce(jt.DefaultItems.SaveAsImage,{}),ce(jt.DefaultItems.SearchMenu,{}),ce(jt.DefaultItems.Help,{}),ce(jt.DefaultItems.ClearCanvas,{}),ce(jt.Separator,{}),ce(jt.Group,{title:"Excalidraw links",children:ce(jt.DefaultItems.Socials,{})}),ce(jt.Separator,{}),ce(jt.DefaultItems.ToggleTheme,{}),ce(jt.DefaultItems.ChangeCanvasBackground,{})]}),dZ=()=>Bo(ng,{__fallback:!0,children:[ce(ng.Actions.SaveToDisk,{}),ce(ng.Actions.ExportToImage,{})]}),mZ=({actionManager:e,appState:t,files:o,setAppState:n,elements:r,canvas:a,onLockToggle:i,onHandToolToggle:s,onPenModeToggle:l,showExitZenModeBtn:c,renderTopLeftUI:m,renderTopRightUI:p,renderCustomStats:d,UIOptions:u,onExportImage:h,renderWelcomeScreen:g,children:x,app:E,isCollaborating:y,generateLinkForSelection:w})=>{let v=Te(),C=Dt()==="compact",P=HC(),S=C?{menuTopGap:4,toolbarColGap:4,toolbarRowGap:1,toolbarInnerRowGap:.5,islandPadding:1,collabMarginLeft:8}:{menuTopGap:6,toolbarColGap:4,toolbarRowGap:1,toolbarInnerRowGap:1,islandPadding:1,collabMarginLeft:8},D=P.tunnelsJotai.Provider,[_,k]=le(Yr),M=()=>u.canvasActions.export?ce(X4,{elements:r,appState:t,files:o,actionManager:e,exportOpts:u.canvasActions.export,canvas:a,setAppState:n}):null,B=()=>!u.canvasActions.saveAsImage||t.openDialog?.name!=="imageExport"?null:ce(K4,{elements:r,appState:t,files:o,actionManager:e,onExportImage:h,onCloseRequest:()=>n({openDialog:null}),name:E.getName()}),O=()=>Bo("div",{style:{position:"relative"},children:[ce(P.MainMenuTunnel.Out,{}),g&&ce(P.WelcomeScreenMenuHintTunnel.Out,{})]}),N=()=>{let Q=C;return ce(gd,{heading:"selectedShapeActions",className:Pi("selected-shape-actions zen-mode-transition",{"transition-left":t.zenModeEnabled}),children:Q?ce(gt,{className:Pi("compact-shape-actions-island"),padding:0,style:{maxHeight:`${t.height-166}px`},children:ce(e5,{appState:t,elementsMap:E.scene.getNonDeletedElementsMap(),renderAction:e.renderAction,app:E,setAppState:n})}):ce(gt,{className:nZ.SHAPE_ACTIONS_MENU,padding:2,style:{maxHeight:`${t.height-166}px`},children:ce(ZC,{appState:t,elementsMap:E.scene.getNonDeletedElementsMap(),renderAction:e.renderAction,app:E})})})},z=()=>{let Q=sZ(t,r),Z=t.stats.open&&!t.zenModeEnabled&&!t.viewModeEnabled&&t.openDialog?.name!=="elementLinkSelector";return ce($u,{side:"top",children:Bo("div",{className:"App-menu App-menu_top",children:[Bo(Rt.Col,{gap:S.menuTopGap,className:Pi("App-menu_top__left"),children:[O(),ce("div",{className:Pi("selected-shape-actions-container",{"selected-shape-actions-container--compact":C}),children:Q&&N()})]}),!t.viewModeEnabled&&t.openDialog?.name!=="elementLinkSelector"&&ce(gd,{heading:"shapes",className:"shapes-section",children:U=>Bo("div",{style:{position:"relative"},children:[g&&ce(P.WelcomeScreenToolbarHintTunnel.Out,{}),ce(Rt.Col,{gap:S.toolbarColGap,align:"start",children:Bo(Rt.Row,{gap:S.toolbarRowGap,className:Pi("App-toolbar-container",{"zen-mode":t.zenModeEnabled}),children:[Bo(gt,{padding:S.islandPadding,className:Pi("App-toolbar",{"zen-mode":t.zenModeEnabled,"App-toolbar--compact":C}),children:[ce(U4,{appState:t,isMobile:v.formFactor==="phone",editorInterface:v,app:E}),U,Bo(Rt.Row,{gap:S.toolbarInnerRowGap,children:[ce(Vu,{zenModeEnabled:t.zenModeEnabled,checked:t.penMode,onChange:()=>l(null),title:f("toolBar.penMode"),penDetected:t.penDetected}),ce(j3,{checked:t.activeTool.locked,onChange:i,title:f("toolBar.lock")}),ce("div",{className:"App-toolbar__divider"}),ce(o5,{setAppState:n,activeTool:t.activeTool,UIOptions:u,app:E})]})]}),y&&ce(gt,{style:{marginLeft:S.collabMarginLeft,alignSelf:"center",height:"fit-content"},children:ce(j4,{title:f("toolBar.laser"),checked:t.activeTool.type===q4.laser,onChange:()=>E.setActiveTool({type:q4.laser}),isMobile:!0})})]})})]})}),Bo("div",{className:Pi("layer-ui__wrapper__top-right zen-mode-transition",{"transition-right":t.zenModeEnabled,"layer-ui__wrapper__top-right--compact":C}),children:[t.collaborators.size>0&&ce(ju,{collaborators:t.collaborators,userToFollow:t.userToFollow?.socketId||null}),p?.(v.formFactor==="phone",t),E.props.showLibraryButton===!0&&!t.viewModeEnabled&&t.openDialog?.name!=="elementLinkSelector"&&(!F||t.openSidebar?.name!==v1.name)&&ce(P.DefaultSidebarTriggerTunnel.Out,{}),Z&&ce(Md,{app:E,onClose:()=>{e.executeAction(oa)},renderCustomStats:d})]})]})})},L=()=>ce(ig,{__fallback:!0,onDock:Q=>{be("sidebar",`toggleDock (${Q?"dock":"undock"})`,`(${v.formFactor==="phone"?"mobile":"desktop"})`)}}),F=Ki(xd),$=Bo(Q4,{children:[x,ce(cZ,{UIOptions:u}),ce(ig.Trigger,{__fallback:!0,icon:fv,title:aZ(f("toolBar.library")),onToggle:Q=>{Q&&be("sidebar",`${v1.name} (open)`,`button (${v.formFactor==="phone"?"mobile":"desktop"})`)},tab:v1.defaultTab}),ce(dZ,{}),t.openDialog?.name==="ttd"&&ce(hg,{__fallback:!0}),t.isLoading&&ce(Uu,{delay:250}),t.errorMessage&&ce(N4,{onClose:()=>n({errorMessage:null}),children:t.errorMessage}),_&&v.formFactor!=="phone"&&ce(Rv,{colorPickerType:_.colorPickerType,onCancel:()=>{k(null)},onChange:(Q,Z,U,{altKey:q})=>{if(!(Q!=="elementBackground"&&Q!=="elementStroke"))if(U.length){for(let re of U)iZ(re,rZ(r),{[q&&_.swapPreviewOnAlt?Q==="elementBackground"?"strokeColor":"backgroundColor":Q==="elementBackground"?"backgroundColor":"strokeColor"]:Z}),lZ.delete(re);E.scene.triggerUpdate()}else n(Q==="elementBackground"?{currentItemBackgroundColor:Z}:{currentItemStrokeColor:Z})},onSelect:(Q,Z)=>{k(U=>U?.keepOpenOnAlt&&Z.altKey?U:null),_?.onSelect?.(Q,Z)}}),t.openDialog?.name==="help"&&ce(O4,{onClose:()=>{n({openDialog:null})}}),ce(l5,{}),t.openDialog?.name==="elementLinkSelector"&&ce(R4,{sourceElementId:t.openDialog.sourceElementId,onClose:()=>{n({openDialog:null})},scene:E.scene,appState:t,generateLinkForSelection:w}),ce(P.OverwriteConfirmDialogTunnel.Out,{}),B(),M(),t.pasteDialog.shown&&ce(aS,{setAppState:n,appState:t,onClose:()=>n({pasteDialog:{shown:!1,data:null}})}),v.formFactor==="phone"&&ce(nS,{app:E,appState:t,elements:r,actionManager:e,renderJSONExportDialog:M,renderImageExportDialog:B,setAppState:n,onHandToolToggle:s,onPenModeToggle:l,renderTopLeftUI:m,renderTopRightUI:p,renderSidebars:L,renderWelcomeScreen:g,UIOptions:u}),v.formFactor!=="phone"&&Bo(Q4,{children:[Bo("div",{className:"layer-ui__wrapper",style:t.openSidebar&&F&&v.canFitSidebar?{width:"calc(100% - var(--right-sidebar-width))"}:{},children:[g&&ce(P.WelcomeScreenCenterTunnel.Out,{}),z(),ce(uS,{appState:t,actionManager:e,showExitZenModeBtn:c,renderWelcomeScreen:g}),t.scrolledOutside&&ce("button",{type:"button",className:"scroll-back-to-content",onClick:()=>{n(Q=>({...Ha(r,Q)}))},children:f("buttons.scrollBackToContent")})]}),L()]})]});return ce(jh.Provider,{value:t,children:ce(D,{children:ce(qb.Provider,{value:P,children:$})})})},J4=e=>{let{startBoundElement:t,cursorButton:o,scrollX:n,scrollY:r,...a}=e;return a},pZ=(e,t)=>{if(e.children!==t.children)return!1;let{canvas:o,appState:n,...r}=e,{canvas:a,appState:i,...s}=t;return Sg(J4(n),J4(i),{selectedElementIds:Sg,selectedGroupIds:Sg})&&Sg(r,s)},eP=oZ.memo(mZ,pZ);import uZ from"clsx";import{jsx as tP,jsxs as hZ}from"react/jsx-runtime";var gZ="small",Mg=e=>hZ("label",{className:uZ("ToolIcon ToolIcon__MagicButton",`ToolIcon_size_${gZ}`,{"is-mobile":e.isMobile}),title:`${e.title}`,children:[tP("input",{className:"ToolIcon_type_checkbox",type:"checkbox",name:e.name,onChange:e.onChange,checked:e.checked,"aria-label":e.title}),tP("div",{className:"ToolIcon__icon",children:e.icon})]});import{useEffect as fZ,useRef as bZ}from"react";import{jsx as oP}from"react/jsx-runtime";var nP=({trails:e})=>{let t=bZ(null);return fZ(()=>{if(t.current)for(let o of e)o.start(t.current);return()=>{for(let o of e)o.stop()}},e),oP("div",{className:"SVGLayer",children:oP("svg",{ref:t})})};import tj,{useEffect as oj,useRef as EP}from"react";import{CURSOR_TYPE as wP,isShallowEqual as nj,sceneCoordsToViewportCoords as rj}from"@orangecatai/common";var Ht=class Ht{static start(t,o){let n=o({deltaTime:0,state:void 0});n&&(Ht.animations.set(t,{animation:o,lastTime:0,state:n}),Ht.isRunning||(Ht.isRunning=!0,wi()?requestAnimationFrame(Ht.tick):setTimeout(Ht.tick,0)))}static tick(){if(Ht.animations.size>0){for(let[t,o]of Ht.animations){let n=performance.now(),r=o.lastTime===0?0:n-o.lastTime,a=o.animation({deltaTime:r,state:o.state});if(a)o.lastTime=n,o.state=a;else if(Ht.animations.delete(t),Ht.animations.size===0){Ht.isRunning=!1;return}}wi()?requestAnimationFrame(Ht.tick):setTimeout(Ht.tick,0)}}static running(t){return Ht.animations.has(t)}static cancel(t){Ht.animations.delete(t)}};A(Ht,"isRunning",!1),A(Ht,"animations",new Map);var Ld=Ht;import{clamp as k1,pointFrom as Ll,pointsEqual as TZ,bezierEquation as hP,pointRotateRads as Pg,pointDistance as CZ}from"@orangecatai/math";import{arrayToMap as kZ,BIND_MODE_TIMEOUT as _d,DEFAULT_TRANSFORM_HANDLE_SPACING as A1,FRAME_STYLE as sn,getFeatureFlag as SZ,invariant as lP,THEME as Ma}from"@orangecatai/common";import{deconstructDiamondElement as S1,deconstructRectanguloidElement as fP,elementCenterPoint as _l,getDiamondBaseCorners as MZ,FOCUS_POINT_SIZE as PZ,getOmitSidesForEditorInterface as I1,getTransformHandles as AZ,getTransformHandlesFromCoords as LZ,hasBoundingBox as _Z,hitElementItself as DZ,isArrowElement as RZ,isBindableElement as bP,isElbowArrow as Dl,isFrameLikeElement as Rl,isImageElement as cP,isLinearElement as NZ,isLineElement as BZ,maxBindingDistance_simple as FZ,isTextElement as dP,LinearElementEditor as nr}from"@orangecatai/element";import{renderSelectionElement as OZ}from"@orangecatai/element";import{getElementsInGroup as M1,getSelectedGroupIds as zZ,isSelectedViaGroup as HZ,selectGroupsFromGivenElements as GZ}from"@orangecatai/element";import{getCommonBounds as P1,getElementAbsoluteCoords as Ag}from"@orangecatai/element";import{getGlobalFixedPointForBindableElement as mP,isFocusPointVisible as UZ}from"@orangecatai/element";import{pointFrom as qt}from"@orangecatai/math";import{THEME as xZ}from"@orangecatai/common";var yZ="#ff6b6b",EZ="#ff0000",rP=1,aP=2,iP=(e,t)=>{if(!t.snapLines.length)return;let o=t.theme===xZ.LIGHT||t.zenModeEnabled?yZ:EZ,n=(t.zenModeEnabled?rP*1.5:rP)/t.zoom.value;e.save(),e.translate(t.scrollX,t.scrollY);for(let r of t.snapLines)r.type==="pointer"?(e.lineWidth=n,e.strokeStyle=o,vZ(r,e,t)):r.type==="gap"?(e.lineWidth=n,e.strokeStyle=o,IZ(r.points[0],r.points[1],r.direction,t,e)):r.type==="points"&&(e.lineWidth=n,e.strokeStyle=o,wZ(r,e,t));e.restore()},wZ=(e,t,o)=>{if(!o.zenModeEnabled){let n=e.points[0],r=e.points[e.points.length-1];an(n,r,t)}for(let n of e.points)sP(n,o,t)},vZ=(e,t,o)=>{sP(e.points[0],o,t),o.zenModeEnabled||an(e.points[0],e.points[1],t)},sP=([e,t],o,n)=>{n.save();let r=(o.zenModeEnabled?aP*1.5:aP)/o.zoom.value;n.beginPath(),n.moveTo(e-r,t-r),n.lineTo(e+r,t+r),n.moveTo(e+r,t-r),n.lineTo(e-r,t+r),n.stroke(),n.restore()},an=(e,t,o)=>{o.beginPath(),o.lineTo(e[0],e[1]),o.lineTo(t[0],t[1]),o.stroke()},IZ=(e,t,o,n,r)=>{let a=8/n.zoom.value,i=a/2,s=a/4;if(o==="horizontal"){let l=[(e[0]+t[0])/2,e[1]];n.zenModeEnabled||an(qt(e[0],e[1]-a),qt(e[0],e[1]+a),r),an(qt(l[0]-s,l[1]-i),qt(l[0]-s,l[1]+i),r),an(qt(l[0]+s,l[1]-i),qt(l[0]+s,l[1]+i),r),n.zenModeEnabled||(an(qt(t[0],t[1]-a),qt(t[0],t[1]+a),r),an(e,t,r))}else{let l=[e[0],(e[1]+t[1])/2];n.zenModeEnabled||an(qt(e[0]-a,e[1]),qt(e[0]+a,e[1]),r),an(qt(l[0]-i,l[1]-s),qt(l[0]+i,l[1]-s),r),an(qt(l[0]-i,l[1]+s),qt(l[0]+i,l[1]+s),r),n.zenModeEnabled||(an(qt(t[0]-a,t[1]),qt(t[0]+a,t[1]),r),an(e,t,r))}};var WZ=(e,t)=>{lP(t.selectedLinearElement,"selectedLinearElement is null");let{segmentMidPointHoveredCoords:o}=t.selectedLinearElement;lP(o,"midPointCoords is null"),e.save(),e.translate(t.scrollX,t.scrollY),L1(o,e,t),e.restore()},YZ=(e,t,o)=>{let{elementId:n,hoverPointIndex:r}=t.selectedLinearElement;if(t.selectedLinearElement?.isEditing&&t.selectedLinearElement?.selectedPointsIndices?.includes(r)||t.selectedLinearElement?.isDragging)return;let a=nr.getElement(n,o);if(!a)return;let i=nr.getPointAtIndexGlobalCoordinates(a,r,o);e.save(),e.translate(t.scrollX,t.scrollY),L1(i,e,t),e.restore()},L1=(e,t,o)=>{t.fillStyle="rgba(105, 101, 219, 0.4)",ql(t,e[0],e[1],nr.POINT_HANDLE_SIZE/o.zoom.value,!1)},$Z=(e,t,o)=>{e.save(),e.translate(t.scrollX,t.scrollY),L1(o,e,t),e.restore()},T1=(e,t,o,n,r,a,i)=>{e.strokeStyle="#5e5ad8",e.setLineDash([]),e.fillStyle="rgba(255, 255, 255, 0.9)",r?e.fillStyle="rgba(134, 131, 226, 0.9)":a&&(e.fillStyle="rgba(177, 151, 252, 0.7)"),ql(e,o[0],o[1],(i?n*(t.selectedLinearElement?.isEditing?1.5:2):n)/t.zoom.value,!a,!i||r)},VZ=(e,t,o,n,r)=>{let a=t.element.frameId&&o.get(t.element.frameId);switch(a&&Rl(a)&&(e.translate(a.x,a.y),e.beginPath(),sn.radius&&e.roundRect?e.roundRect(-1,-1,a.width+1,a.height+1,sn.radius/n.zoom.value):e.rect(-1,-1,a.width+1,a.height+1),e.clip(),e.translate(-a.x,-a.y)),t.element.type){case"magicframe":case"frame":e.save(),e.translate(t.element.x,t.element.y),e.lineWidth=sn.strokeWidth/n.zoom.value,e.strokeStyle=n.theme===Ma.DARK?"rgba(3, 93, 161, 1)":"rgba(106, 189, 252, 1)",sn.radius&&e.roundRect?(e.beginPath(),e.roundRect(0,0,t.element.width,t.element.height,sn.radius/n.zoom.value),e.stroke(),e.closePath()):e.strokeRect(0,0,t.element.width,t.element.height),e.restore();break;default:e.save();let i=_l(t.element,o);switch(e.translate(i[0],i[1]),e.rotate(t.element.angle),e.translate(-i[0],-i[1]),e.translate(t.element.x,t.element.y),e.lineWidth=k1(1.75,t.element.strokeWidth,4)/Math.max(.25,n.zoom.value),e.strokeStyle=n.theme===Ma.DARK?"rgba(3, 93, 161, 1)":"rgba(106, 189, 252, 1)",t.element.type){case"ellipse":e.beginPath(),e.ellipse(t.element.width/2,t.element.height/2,t.element.width/2,t.element.height/2,0,0,2*Math.PI),e.closePath(),e.stroke();break;case"diamond":{let[s,l]=S1(t.element);s.forEach(c=>{e.beginPath(),e.moveTo(c[0][0]-t.element.x,c[0][1]-t.element.y),e.lineTo(c[1][0]-t.element.x,c[1][1]-t.element.y),e.stroke()}),l.forEach(c=>{let[m,p,d,u]=c;e.beginPath(),e.moveTo(m[0]-t.element.x,m[1]-t.element.y),e.bezierCurveTo(p[0]-t.element.x,p[1]-t.element.y,d[0]-t.element.x,d[1]-t.element.y,u[0]-t.element.x,u[1]-t.element.y),e.stroke()})}break;default:{let[s,l]=fP(t.element);s.forEach(c=>{e.beginPath(),e.moveTo(c[0][0]-t.element.x,c[0][1]-t.element.y),e.lineTo(c[1][0]-t.element.x,c[1][1]-t.element.y),e.stroke()}),l.forEach(c=>{let[m,p,d,u]=c;e.beginPath(),e.moveTo(m[0]-t.element.x,m[1]-t.element.y),e.bezierCurveTo(p[0]-t.element.x,p[1]-t.element.y,d[0]-t.element.x,d[1]-t.element.y,u[0]-t.element.x,u[1]-t.element.y),e.stroke()})}break}e.restore();break}if(Rl(t.element)||bP(t.element)){let i=n.selectedLinearElement,s=i?.elementId&&nr.getElement(i?.elementId,o),l=r&&DZ({point:r,element:t.element,elementsMap:o,threshold:0,overrideShouldTestInside:!0}),c=s&&Dl(s)||n.activeTool.type==="arrow"&&n.currentItemArrowType==="elbow";if(!l||c){e.save();let m=_l(t.element,o),p;if(t.element.type==="diamond"){let g=_l(t.element,o);p=MZ(t.element).map(x=>{let E=hP(x,.5),y=Pg(E,g,t.element.angle);return Ll(y[0],y[1])})}else p=[{x:t.element.width,y:t.element.height/2},{x:t.element.width/2,y:t.element.height},{x:0,y:t.element.height/2},{x:t.element.width/2,y:0}].map(x=>{let E=Ll(x.x+t.element.x,x.y+t.element.y),y=Pg(E,m,t.element.angle);return Ll(y[0],y[1])});let d=r&&p.reduce((g,x,E)=>{let y=CZ(x,r);return E===-1||y<g.distance?{idx:E,distance:y}:g},{idx:-1,distance:1/0}),u=4/n.zoom.value,h=FZ(n.zoom)+t.element.strokeWidth/2;p.forEach((g,x)=>{let E=(!l||c)&&d?.idx===x&&d.distance<=h,y=!E&&(c||x===d?.idx&&d.distance<=h*2);E?(e.fillStyle=n.theme===Ma.DARK?"rgba(3, 93, 161, 1)":"rgba(106, 189, 252, 1)",e.beginPath(),e.arc(g[0],g[1],u,0,2*Math.PI),e.fill()):y&&(e.fillStyle=n.theme===Ma.DARK?"rgba(0, 0, 0, 0.8)":"rgba(65, 65, 65, 0.5)",e.beginPath(),e.arc(g[0],g[1],u,0,2*Math.PI),e.fill())}),e.restore()}}},KZ=(e,t,o,n,r,a,i)=>{let s=e.state.bindMode==="orbit"&&e.bindModeHandler!==null,l=_d-(i?.runtime??(s?0:_d)),c=k1(1/_d*l,1e-4,1),m=o.strokeWidth/2,p=o.frameId&&n.get(o.frameId);switch(p&&Rl(p)&&(t.translate(p.x,p.y),t.beginPath(),sn.radius&&t.roundRect?t.roundRect(-1,-1,p.width+1,p.height+1,sn.radius/r.zoom.value):t.rect(-1,-1,p.width+1,p.height+1),t.clip(),t.translate(-p.x,-p.y)),o.type){case"magicframe":case"frame":t.save(),t.translate(o.x,o.y),t.lineWidth=sn.strokeWidth/r.zoom.value,t.strokeStyle=r.theme===Ma.DARK?`rgba(3, 93, 161, ${c})`:`rgba(106, 189, 252, ${c})`,sn.radius&&t.roundRect?(t.beginPath(),t.roundRect(0,0,o.width,o.height,sn.radius/r.zoom.value),t.stroke(),t.closePath()):t.strokeRect(0,0,o.width,o.height),t.restore();break;default:t.save();let u=_l(o,n),h=u[0]+r.scrollX,g=u[1]+r.scrollY;switch(t.translate(h,g),t.rotate(o.angle),t.translate(-h,-g),t.translate(o.x+r.scrollX-m,o.y+r.scrollY-m),t.lineWidth=k1(2.5,o.strokeWidth*1.75,4)/Math.max(.25,r.zoom.value),t.strokeStyle=r.theme===Ma.DARK?`rgba(3, 93, 161, ${c/2})`:`rgba(106, 189, 252, ${c/2})`,o.type){case"ellipse":t.beginPath(),t.ellipse((o.width+m*2)/2,(o.height+m*2)/2,(o.width+m*2)/2,(o.height+m*2)/2,0,0,2*Math.PI),t.closePath(),t.stroke();break;case"diamond":{let[x,E]=S1(o,m);x.forEach(y=>{t.beginPath(),t.moveTo(y[0][0]-o.x+m,y[0][1]-o.y+m),t.lineTo(y[1][0]-o.x+m,y[1][1]-o.y+m),t.stroke()}),E.forEach(y=>{let[w,v,I,C]=y;t.beginPath(),t.moveTo(w[0]-o.x+m,w[1]-o.y+m),t.bezierCurveTo(v[0]-o.x+m,v[1]-o.y+m,I[0]-o.x+m,I[1]-o.y+m,C[0]-o.x+m,C[1]-o.y+m),t.stroke()})}break;default:{let[x,E]=fP(o,m);x.forEach(y=>{t.beginPath(),t.moveTo(y[0][0]-o.x+m,y[0][1]-o.y+m),t.lineTo(y[1][0]-o.x+m,y[1][1]-o.y+m),t.stroke()}),E.forEach(y=>{let[w,v,I,C]=y;t.beginPath(),t.moveTo(w[0]-o.x+m,w[1]-o.y+m),t.bezierCurveTo(v[0]-o.x+m,v[1]-o.y+m,I[0]-o.x+m,I[1]-o.y+m,C[0]-o.x+m,C[1]-o.y+m),t.stroke()})}break}t.restore();break}if(!s||(i?.runtime??0)>_d)return;let d=.5*(Math.min(o.width,o.height)/2);if(!Rl(o)){t.save(),t.translate(o.x+r.scrollX,o.y+r.scrollY);let u=1/_d*l;t.strokeStyle="rgba(0, 0, 0, 0.2)",t.lineWidth=1/r.zoom.value,t.setLineDash([4/r.zoom.value,4/r.zoom.value]),t.lineDashOffset=-u*10/r.zoom.value,t.beginPath(),t.ellipse(o.width/2,o.height/2,d,d,0,0,2*Math.PI),t.stroke(),t.fillStyle="rgba(0, 0, 0, 0.04)",t.beginPath(),t.ellipse(o.width/2,o.height/2,d*(1-c),d*(1-c),0,0,2*Math.PI),t.fill(),t.restore(),t.save(),t.translate(o.x+r.scrollX,o.y+r.scrollY);let h=5/r.zoom.value,g=5/r.zoom.value,x=h+g,E;if(o.type==="diamond"){let[,y]=S1(o),w=_l(o,n);E=y.map(v=>{let I=hP(v,.5),C=Pg(I,w,o.angle);return{x:C[0]-o.x,y:C[1]-o.y}})}else{let y=_l(o,n);E=[{x:o.width/2,y:0},{x:o.width,y:o.height/2},{x:o.width/2,y:o.height},{x:0,y:o.height/2}].map(v=>{let I=Ll(v.x+o.x,v.y+o.y),C=Pg(I,y,o.angle);return{x:C[0]-o.x,y:C[1]-o.y}})}E.forEach(y=>{t.clearRect(y.x-x,y.y-x,x*2,x*2)}),t.fillStyle=r.theme===Ma.DARK?`rgba(3, 93, 161, ${c})`:`rgba(106, 189, 252, ${c})`,E.forEach(y=>{t.beginPath(),t.arc(y.x,y.y,h,0,2*Math.PI),t.fill()}),t.restore()}return{runtime:(i?.runtime??0)+a}},XZ=(e,t,o,n,r,a,i)=>{if(o===null)return;if(SZ("COMPLEX_BINDINGS"))return KZ(e,t,o.element,n,r,a,i);t.save(),t.translate(r.scrollX,r.scrollY);let s=e.lastPointerMoveCoords?Ll(e.lastPointerMoveCoords.x,e.lastPointerMoveCoords.y):null;VZ(t,o,n,r,s),t.restore()},xP=(e,t,o)=>{let{angle:n,x1:r,y1:a,x2:i,y2:s,selectionColors:l,cx:c,cy:m,dashed:p,activeEmbeddable:d}=o,u=i-r,h=s-a,x=(o.padding??A1*2)/t.zoom.value,E=8/t.zoom.value,y=4/t.zoom.value;e.save(),e.translate(t.scrollX,t.scrollY),e.lineWidth=(d?4:1)/t.zoom.value;let w=l.length;for(let v=0;v<w;++v)e.strokeStyle=l[v],p&&e.setLineDash([E,y+(E+y)*(w-1)]),e.lineDashOffset=(E+y)*v,Jl(e,r-x,a-x,u+x*2,h+x*2,c,m,n);e.restore()},ZZ=(e,t,o,n)=>{let[r,a,i,s]=Ag(o,n),l=i-r,c=s-a;e.strokeStyle="rgb(0,118,255)",e.lineWidth=sn.strokeWidth/t.zoom.value,e.save(),e.translate(t.scrollX,t.scrollY),Jl(e,r,a,l,c,r+l/2,a+c/2,o.angle,!1,sn.radius/t.zoom.value),e.restore()},pP=(e,t,o,n)=>{let{colors:r=["rgb(0,118,255)"],dashed:a=!1}=n||{},i=o.filter(m=>m.groupIds.length===0),s=o.filter(m=>m.groupIds.length>0),l=m=>{let[p,d,u,h]=P1(m);return{angle:0,x1:p,x2:u,y1:d,y2:h,selectionColors:r,dashed:a,cx:p+(u-p)/2,cy:d+(h-d)/2,activeEmbeddable:!1}},c=m=>{let p=M1(o,m);return l(p)};Object.entries(GZ(s,t)).filter(([m,p])=>p).map(([m,p])=>m).map(m=>c(m)).concat(i.map(m=>l([m]))).forEach(m=>xP(e,t,m))},C1=(e,t,o,n)=>{if(!t.selectedLinearElement)return;e.save(),e.translate(t.scrollX,t.scrollY),e.lineWidth=1/t.zoom.value;let r=nr.getPointsGlobalCoordinates(o,n),{POINT_HANDLE_SIZE:a}=nr,i=t.selectedLinearElement?.isEditing?a:a/2,s=Dl(o),l=BZ(o);if(r.forEach((c,m)=>{if(s&&m!==0&&m!==r.length-1)return;let p=m>0&&(m!==r.length-1||!l||!o.polygon)&&TZ(c,m===r.length-1?r[0]:r[m-1],2/t.zoom.value),d=!!t.selectedLinearElement?.isEditing&&!!t.selectedLinearElement?.selectedPointsIndices?.includes(m);l&&o.polygon&&!d&&m===o.points.length-1&&t.selectedLinearElement?.isEditing&&t.selectedLinearElement?.selectedPointsIndices?.includes(0)&&(d=!0),T1(e,t,c,i,d,!1,p)}),Dl(o)){let c=o.fixedSegments?.map(m=>m.index)||[];r.slice(0,-1).forEach((m,p)=>{nr.isSegmentTooShort(o,r[p+1],r[p],p,t.zoom)||T1(e,t,Ll((m[0]+r[p+1][0])/2,(m[1]+r[p+1][1])/2),a/2,!1,!c.includes(p+1),!1)})}else nr.getEditorMidPoints(o,n,t).filter((m,p,d)=>m!==null&&!(Dl(o)&&(p===0||p===d.length-1))).forEach(m=>{(t.selectedLinearElement?.isEditing||r.length===2)&&T1(e,t,m,a/2,!1,!0,!1)});e.restore()},jZ=(e,t,o,n)=>{e.save(),e.translate(t.scrollX,t.scrollY),e.strokeStyle="rgba(134, 131, 226, 0.6)",e.lineWidth=1/t.zoom.value,e.setLineDash([4/t.zoom.value,4/t.zoom.value]),e.beginPath(),e.moveTo(o[0],o[1]),e.lineTo(n[0],n[1]),e.stroke(),e.restore()},qZ=(e,t,o,n,r)=>{e.save(),e.translate(t.scrollX,t.scrollY),e.strokeStyle="rgba(134, 131, 226, 0.6)",e.lineWidth=1/t.zoom.value,e.setLineDash([]),e.fillStyle=r?"rgba(134, 131, 226, 0.9)":"rgba(255, 255, 255, 0.9)",ql(e,o[0],o[1],n/t.zoom.value,!0,!0),e.restore()},uP=({arrow:e,appState:t,type:o,context:n,elementsMap:r})=>{let a=o==="start"?e.startBinding:e.endBinding,i=a?.elementId&&r.get(a.elementId);if(!i||!bP(i)||i.isDeleted)return;let s=mP(a.fixedPoint,i,r);if(!UZ(s,e,i,r,t,o))return;let l=t.selectedLinearElement,c=!!l?.isDragging,m=o==="start"?0:e.points.length-1,p=!!l?.selectedPointsIndices?.includes(m);if(l?.hoveredFocusPointBinding===o&&!l.draggedFocusPointBinding&&$Z(n,t,s),!(p&&c)){let d=mP(a.fixedPoint,i,r),u=l?.hoveredFocusPointBinding===o,h=nr.getPointAtIndexGlobalCoordinates(e,m,r);jZ(n,t,h,d),qZ(n,t,d,PZ/1.5,u)}},gP=(e,t,o,n,r)=>{Object.keys(n).forEach(a=>{let i=n[a];if(i!==void 0){let[s,l,c,m]=i;e.save(),e.lineWidth=1/o.zoom.value,t.selectionColor&&(e.strokeStyle=t.selectionColor),a==="rotation"?ql(e,s+c/2,l+m/2,c/2,!0):e.roundRect?(e.beginPath(),e.roundRect(s,l,c,m,2/o.zoom.value),e.fill(),e.stroke()):Jl(e,s,l,c,m,s+c/2,l+m/2,r,!0),e.restore()}})},JZ=(e,t,o,n,r)=>{let[a,i,,,s,l]=Ag(n,r),c=3,m=20,p=c/o.zoom.value,d=p/2,u=s-a+p,h=l-i+p,g=Math.min(m/o.zoom.value,u),x=Math.min(m/o.zoom.value,h);e.save(),e.fillStyle=t.selectionColor,e.strokeStyle=t.selectionColor,e.lineWidth=p,[[[-u,-h],[0,d],[g,d],[d,0],[d,x]],[[u-d,-h],[d,d],[-g+d,d],[0,0],[0,x]],[[-u,h],[0,-d],[g,-d],[d,0],[d,-x]],[[u-d,h],[d,-d],[-g+d,-d],[0,0],[0,-x]]].forEach(y=>{let[[w,v],[I,C],[P,S],[D,_],[k,M]]=y;e.save(),e.translate(s,l),e.rotate(n.angle),e.beginPath(),e.moveTo(w+I,v+C),e.lineTo(w+P,v+S),e.stroke(),e.beginPath(),e.moveTo(w+D,v+_),e.lineTo(w+k,v+M),e.stroke(),e.restore()}),e.restore()},QZ=(e,t,o,n)=>{t.save();let r=A1*2/o.zoom.value,a=e.width+r*2,i=e.height+r*2,s=e.x+a/2,l=e.y+i/2,c=-(a/2+r),m=-(i/2+r);t.translate(s+o.scrollX,l+o.scrollY),t.rotate(e.angle),t.lineWidth=1/o.zoom.value,t.strokeStyle=n,t.strokeRect(c,m,a,i),t.restore()},ej=({app:e,canvas:t,elementsMap:o,visibleElements:n,selectedElements:r,allElementsMap:a,scale:i,appState:s,renderConfig:l,editorInterface:c,animationState:m,deltaTime:p})=>{if(t===null)return{atLeastOneVisibleElement:!1,elementsMap:o};let[d,u]=am(t,i),h=m,g=im({canvas:t,scale:i,normalizedWidth:d,normalizedHeight:u});g.save(),g.scale(s.zoom.value,s.zoom.value);let x;if(n.forEach(I=>{s.selectedLinearElement?.isEditing&&s.selectedLinearElement.elementId===I.id&&I&&(x=I)}),x&&C1(g,s,x,o),s.selectionElement&&!s.isCropping)try{OZ(s.selectionElement,g,s,l.selectionColor)}catch(I){console.error(I)}if(s.editingTextElement&&dP(s.editingTextElement)){let I=a.get(s.editingTextElement.id);I&&!I.autoResize&&QZ(I,g,s,l.selectionColor)}if(s.isBindingEnabled&&s.suggestedBinding?h={...m,bindingHighlight:XZ(e,g,s.suggestedBinding,a,s,p,m?.bindingHighlight)}:h={...m,bindingHighlight:void 0},s.frameToHighlight&&ZZ(g,s,s.frameToHighlight,o),s.elementsToHighlight&&pP(g,s,s.elementsToHighlight),s.activeLockedId){let I=a.get(s.activeLockedId),C=I?[I]:M1(a,s.activeLockedId);pP(g,s,C,{colors:["#ced4da"],dashed:!0})}let E=r.some(I=>Rl(I));r.length===1&&s.selectedLinearElement?.isEditing&&s.selectedLinearElement.elementId===r[0].id&&C1(g,s,r[0],o);let y=s.selectedLinearElement,w=y&&nr.getElement(y.elementId,a);if(w&&(s.selectedLinearElement.isDragging||(y.segmentMidPointHoveredCoords?WZ(g,s):(Dl(w)?y.hoverPointIndex===0||y.hoverPointIndex===w.points.length-1:y.hoverPointIndex>=0)&&YZ(g,s,o)),RZ(w)&&(uP({arrow:w,elementsMap:a,appState:s,context:g,type:"start"}),uP({arrow:w,elementsMap:a,appState:s,context:g,type:"end"}))),!s.multiElement&&!s.newElement&&!s.selectedLinearElement?.isEditing){let I=_Z(r,s,c),C=r.length===1&&NZ(r[0]);C&&s.selectedLinearElement?.elementId===r[0].id&&!r[0].locked&&C1(g,s,r[0],o);let P=l.selectionColor||"#000";if(I){let S=kZ(r),D=[];for(let k of o.values()){let M=[],B=l.remoteSelectedElementIds.get(k.id);if(C&&Dl(k)&&(k.startBinding||k.endBinding)||(S.has(k.id)&&!HZ(s,k)&&M.push(P),B&&M.push(...B.map(O=>ni(O,s.collaborators.get(O))))),M.length){let[O,N,z,L,F,$]=Ag(k,o,!0);D.push({angle:k.angle,x1:O,y1:N,x2:z,y2:L,selectionColors:k.locked?["#ced4da"]:M,dashed:!!B||k.locked,cx:F,cy:$,activeEmbeddable:s.activeEmbeddable?.element===k&&s.activeEmbeddable.state==="active",padding:k.id===s.croppingElementId||cP(k)?0:void 0})}}let _=k=>{let M=M1(o,k),[B,O,N,z]=P1(M);D.push({angle:0,x1:B,x2:N,y1:O,y2:z,selectionColors:M.some(L=>L.locked)?["#ced4da"]:["#000"],dashed:!0,cx:B+(N-B)/2,cy:O+(z-O)/2,activeEmbeddable:!1})};for(let k of zZ(s))_(k);s.editingGroupId&&_(s.editingGroupId),D.forEach(k=>xP(g,s,k))}if(g.save(),g.translate(s.scrollX,s.scrollY),r.length===1){g.fillStyle="#fff";let S=AZ(r[0],s.zoom,o,"mouse",I1(c));if(!s.viewModeEnabled&&I&&!dP(s.editingTextElement)&&!s.croppingElementId&&gP(g,l,s,S,r[0].angle),s.croppingElementId&&!s.isCropping){let D=o.get(s.croppingElementId);D&&cP(D)&&JZ(g,l,s,D,o)}}else if(r.length>1&&!s.isRotating&&!r.some(S=>S.locked)){let S=A1*2/s.zoom.value;g.fillStyle="#fff";let[D,_,k,M]=P1(r,o),B=g.getLineDash();g.setLineDash([2/s.zoom.value]);let O=g.lineWidth;g.lineWidth=1/s.zoom.value,g.strokeStyle=P,Jl(g,D-S,_-S,k-D+S*2,M-_+S*2,(D+k)/2,(_+M)/2,0),g.lineWidth=O,g.setLineDash(B);let N=LZ([D,_,k,M,(D+k)/2,(_+M)/2],0,s.zoom,"mouse",E?{...I1(c),rotation:!0}:I1(c));r.some(z=>!z.locked)&&gP(g,l,s,N,0)}g.restore()}s.searchMatches?.matches.forEach(({id:I,focus:C,matchedLines:P})=>{let S=o.get(I);if(S){let[D,_,,,k,M]=Ag(S,o,!0);g.save(),s.theme===Ma.LIGHT?C?g.fillStyle="rgba(255, 124, 0, 0.4)":g.fillStyle="rgba(255, 226, 0, 0.4)":C?g.fillStyle="rgba(229, 82, 0, 0.4)":g.fillStyle="rgba(99, 52, 0, 0.4)";let B=Rl(S)?s.zoom.value:1;g.translate(s.scrollX,s.scrollY),g.translate(k,M),g.rotate(S.angle),P.forEach(O=>{(O.showOnCanvas||C)&&g.fillRect(D+O.offsetX/B-k,_+O.offsetY/B-M,O.width/B,O.height/B)}),g.restore()}}),iP(g,s),g.restore(),SI({context:g,renderConfig:l,appState:s,normalizedWidth:d,normalizedHeight:u});let v;return l.renderScrollbars&&(v=T3(o,d,u,s),g.save(),g.fillStyle=I3,g.strokeStyle="rgba(255,255,255,0.8)",[v.horizontal,v.vertical].forEach(I=>{I&&gp(g,I.x,I.y,I.width,I.height,Jo/2)}),g.restore()),{scrollBars:v,atLeastOneVisibleElement:n.length>0,elementsMap:o,animationState:h}},yP=e=>{let t=ej(e);return e.callback(t),t};import{jsx as sj}from"react/jsx-runtime";var vP="animateInteractiveScene",aj=e=>{let t=EP(!1),o=EP(null);return oj(()=>{if(!t.current){t.current=!0;return}let n=new Map,r=new Map,a=new Map,i=new Map,s=new Map;e.appState.collaborators.forEach((c,m)=>{if(c.selectedElementIds)for(let p of Object.keys(c.selectedElementIds))a.has(p)||a.set(p,[]),a.get(p).push(m);!c.pointer||c.pointer.renderCursor===!1||(c.username&&i.set(m,c.username),c.userState&&s.set(m,c.userState),r.set(m,rj({sceneX:c.pointer.x,sceneY:c.pointer.y},e.appState)),n.set(m,c.button))});let l=e.containerRef?.current&&getComputedStyle(e.containerRef.current).getPropertyValue("--color-selection")||"#6965db";o.current={app:e.app,canvas:e.canvas,elementsMap:e.elementsMap,visibleElements:e.visibleElements,selectedElements:e.selectedElements,allElementsMap:e.allElementsMap,scale:window.devicePixelRatio,appState:e.appState,renderConfig:{remotePointerViewportCoords:r,remotePointerButton:n,remoteSelectedElementIds:a,remotePointerUsernames:i,remotePointerUserStates:s,selectionColor:l,renderScrollbars:e.renderScrollbars,lastViewportPosition:e.app.lastViewportPosition},editorInterface:e.editorInterface,callback:e.renderInteractiveSceneCallback,animationState:{bindingHighlight:void 0},deltaTime:0},Ld.running(vP)||Ld.start(vP,({deltaTime:c,state:m})=>{let p=yP({...o.current,deltaTime:c,animationState:m}).animationState;if(p){for(let d in p)if(p[d]!==void 0)return p}})}),sj("canvas",{className:"excalidraw__canvas interactive",style:{width:e.appState.width,height:e.appState.height,cursor:e.appState.viewModeEnabled&&e.appState.activeTool.type!=="laser"?wP.GRAB:wP.AUTO},width:e.appState.width*e.scale,height:e.appState.height*e.scale,ref:e.handleCanvasRef,onContextMenu:e.onContextMenu,onPointerMove:e.onPointerMove,onPointerUp:e.onPointerUp,onPointerCancel:e.onPointerCancel,onTouchMove:e.onTouchMove,onPointerDown:e.onPointerDown,onDoubleClick:e.appState.viewModeEnabled?void 0:e.onDoubleClick,children:f("labels.drawingCanvas")})},IP=e=>({zoom:e.zoom,scrollX:e.scrollX,scrollY:e.scrollY,width:e.width,height:e.height,viewModeEnabled:e.viewModeEnabled,activeTool:e.activeTool,openDialog:e.openDialog,editingGroupId:e.editingGroupId,selectedElementIds:e.selectedElementIds,frameToHighlight:e.frameToHighlight,offsetLeft:e.offsetLeft,offsetTop:e.offsetTop,theme:e.theme,selectionElement:e.selectionElement,selectedGroupIds:e.selectedGroupIds,selectedLinearElement:e.selectedLinearElement,multiElement:e.multiElement,newElement:e.newElement,isBindingEnabled:e.isBindingEnabled,suggestedBinding:e.suggestedBinding,isRotating:e.isRotating,elementsToHighlight:e.elementsToHighlight,collaborators:e.collaborators,activeEmbeddable:e.activeEmbeddable,snapLines:e.snapLines,zenModeEnabled:e.zenModeEnabled,editingTextElement:e.editingTextElement,isCropping:e.isCropping,croppingElementId:e.croppingElementId,searchMatches:e.searchMatches,activeLockedId:e.activeLockedId,hoveredElementIds:e.hoveredElementIds,frameRendering:e.frameRendering,shouldCacheIgnoreZoom:e.shouldCacheIgnoreZoom,exportScale:e.exportScale,currentItemArrowType:e.currentItemArrowType}),ij=(e,t)=>e.selectionNonce!==t.selectionNonce||e.sceneNonce!==t.sceneNonce||e.scale!==t.scale||e.elementsMap!==t.elementsMap||e.visibleElements!==t.visibleElements||e.selectedElements!==t.selectedElements||e.renderScrollbars!==t.renderScrollbars?!1:nj(IP(e.appState),IP(t.appState)),_1=tj.memo(aj,ij);import lj,{useEffect as TP,useRef as CP}from"react";import{isShallowEqual as kP}from"@orangecatai/common";import{jsx as mj}from"react/jsx-runtime";var cj=e=>{let t=CP(null),o=CP(!1);return TP(()=>{e.canvas.style.width=`${e.appState.width}px`,e.canvas.style.height=`${e.appState.height}px`,e.canvas.width=e.appState.width*e.scale,e.canvas.height=e.appState.height*e.scale},[e.appState.height,e.appState.width,e.canvas,e.scale]),TP(()=>{let n=t.current;if(!n)return;let r=e.canvas;o.current||(o.current=!0,n.replaceChildren(r),r.classList.add("excalidraw__canvas","static")),dE({canvas:r,rc:e.rc,scale:e.scale,elementsMap:e.elementsMap,allElementsMap:e.allElementsMap,visibleElements:e.visibleElements,appState:e.appState,renderConfig:e.renderConfig},wi())}),mj("div",{className:"excalidraw__canvas-wrapper",ref:t})},SP=e=>({zoom:e.zoom,scrollX:e.scrollX,scrollY:e.scrollY,width:e.width,height:e.height,viewModeEnabled:e.viewModeEnabled,openDialog:e.openDialog,hoveredElementIds:e.hoveredElementIds,offsetLeft:e.offsetLeft,offsetTop:e.offsetTop,theme:e.theme,shouldCacheIgnoreZoom:e.shouldCacheIgnoreZoom,viewBackgroundColor:e.viewBackgroundColor,exportScale:e.exportScale,selectedElementsAreBeingDragged:e.selectedElementsAreBeingDragged,gridSize:e.gridSize,gridStep:e.gridStep,frameRendering:e.frameRendering,selectedElementIds:e.selectedElementIds,frameToHighlight:e.frameToHighlight,editingGroupId:e.editingGroupId,currentHoveredFontFamily:e.currentHoveredFontFamily,croppingElementId:e.croppingElementId,suggestedBinding:e.suggestedBinding}),dj=(e,t)=>e.sceneNonce!==t.sceneNonce||e.scale!==t.scale||e.elementsMap!==t.elementsMap||e.visibleElements!==t.visibleElements?!1:kP(SP(e.appState),SP(t.appState))&&kP(e.renderConfig,t.renderConfig),D1=lj.memo(cj,dj);import{useEffect as xj,useRef as yj}from"react";import{throttleRAF as pj}from"@orangecatai/common";import{getTargetFrame as uj,isInvisiblySmallElement as gj,renderElement as hj,shouldApplyFrameClip as fj}from"@orangecatai/element";var MP=({canvas:e,rc:t,newElement:o,elementsMap:n,allElementsMap:r,scale:a,appState:i,renderConfig:s})=>{if(e){let[l,c]=am(e,a),m=im({canvas:e,scale:a,normalizedWidth:l,normalizedHeight:c});if(m.save(),m.scale(i.zoom.value,i.zoom.value),o&&o.type!=="selection"){if(gj(o))return;if((o.frameId||i.frameToHighlight?.id)&&i.frameRendering.enabled&&i.frameRendering.clip){let d=uj(o,n,i);d&&fj(o,d,i,n)&&lE(d,m,s,i)}hj(o,n,r,t,m,s,i)}else m.clearRect(0,0,l,c);m.restore()}},bj=pj(e=>{MP(e)},{trailing:!0}),PP=(e,t)=>{if(t){bj(e);return}MP(e)};import{jsx as wj}from"react/jsx-runtime";var Ej=e=>{let t=yj(null);return xj(()=>{t.current&&PP({canvas:t.current,scale:e.scale,newElement:e.appState.newElement,elementsMap:e.elementsMap,allElementsMap:e.allElementsMap,rc:e.rc,renderConfig:e.renderConfig,appState:e.appState},wi())}),wj("canvas",{className:"excalidraw__canvas",style:{width:e.appState.width,height:e.appState.height},width:e.appState.width*e.scale,height:e.appState.height*e.scale,ref:t})},AP=Ej;import{useCallback as vj,useEffect as Ij,useRef as Tj}from"react";import{jsx as LP,jsxs as kj}from"react/jsx-runtime";var Cj=5e3,_P=({message:e,onClose:t,closable:o=!1,duration:n=Cj,style:r})=>{let a=Tj(0),i=n!==1/0,s=vj(()=>{i&&(a.current=window.setTimeout(()=>t(),n))},[t,n,i]);return Ij(()=>{if(i)return s(),()=>clearTimeout(a.current)},[s,e,n,i]),kj("div",{className:"Toast",onMouseEnter:i?()=>clearTimeout(a?.current):void 0,onMouseLeave:i?s:void 0,style:r,children:[LP("p",{className:"Toast__message",children:e}),o&&LP(ae,{icon:Go,"aria-label":"close",type:"icon",onClick:t,className:"close"})]})};import{getCommonBounds as Sj,getElementsInGroup as Mj,selectGroupsFromGivenElements as Pj}from"@orangecatai/element";import{sceneCoordsToViewportCoords as Aj}from"@orangecatai/common";import{flushSync as Lj}from"react-dom";import{jsx as Dj}from"react/jsx-runtime";var _j=({app:e,activeLockedId:t})=>{let o=e.scene.getElement(t),n=o?[o]:Mj(e.scene.getNonDeletedElementsMap(),t);if(n.length===0)return null;let[r,a]=Sj(n),{x:i,y:s}=Aj({sceneX:r,sceneY:a},e.state);return Dj("div",{className:"UnlockPopup",style:{bottom:`${e.state.height+12-s+e.state.offsetTop}px`,left:`${i-e.state.offsetLeft}px`},onClick:()=>{Lj(()=>{let l=Pj(n,e.state);e.setState({selectedElementIds:n.reduce((c,m)=>({...c,[m.id]:!0}),{}),selectedGroupIds:l,activeLockedId:null})}),e.actionManager.executeAction(Bc)},title:f("labels.elementLock.unlock"),children:_E})},DP=_j;import{Fragment as R6,jsx as Se,jsxs as Vd}from"react/jsx-runtime";var z6=cr.createContext(null),H6=cr.createContext(null),py={formFactor:"desktop",desktopUIMode:"full",userAgent:F6(typeof navigator<"u"?navigator.userAgent:""),isTouchScreen:!1,canFitSidebar:!1,isLandscape:!0},gy=cr.createContext(py);gy.displayName="EditorInterfaceContext";var hy=cr.createContext({container:null,id:null});hy.displayName="ExcalidrawContainerContext";var fy=cr.createContext([]);fy.displayName="ExcalidrawElementsContext";var by=cr.createContext({...Or(),width:0,height:0,offsetLeft:0,offsetTop:0});by.displayName="ExcalidrawAppStateContext";var xy=cr.createContext(()=>{console.warn("Uninitialized ExcalidrawSetAppStateContext context!")});xy.displayName="ExcalidrawSetAppStateContext";var yy=cr.createContext(null);yy.displayName="ExcalidrawActionManagerContext";var tt=()=>Ba(z6),Hn=()=>Ba(H6),Te=()=>Ba(gy),Dt=()=>Wg(Te()),Qe=()=>Ba(hy),$r=()=>Ba(fy),$o=()=>Ba(by),Ce=()=>Ba(xy),at=()=>Ba(yy),Hd=!1,ly=0,Gd=null,Ra=!1,Ud=!1,cy=!1,Wd={horizontal:null,vertical:null},Na=0,Yd=!1,dy=new Map,my=!1,_6=0,D6=!1,$d=null,Ne={pointers:new Map,lastCenter:null,initialDistance:null,initialScale:null},uy=class e extends cr.Component{constructor(o){super(o);A(this,"canvas");A(this,"interactiveCanvas",null);A(this,"rc");A(this,"unmounted",!1);A(this,"actionManager");A(this,"editorInterface",py);A(this,"stylesPanelMode",Wg(py));A(this,"excalidrawContainerRef",cr.createRef());A(this,"scene");A(this,"fonts");A(this,"renderer");A(this,"visibleElements");A(this,"resizeObserver");A(this,"library");A(this,"libraryItemsFromStorage");A(this,"id");A(this,"store");A(this,"history");A(this,"excalidrawContainerValue");A(this,"files",{});A(this,"imageCache",new Map);A(this,"iFrameRefs",new Map);A(this,"embedsValidationStatus",new Map);A(this,"initializedEmbeds",new Set);A(this,"handleToastClose",()=>{this.setToast(null)});A(this,"elementsPendingErasure",new Set);A(this,"flowChartCreator",new jq);A(this,"flowChartNavigator",new qq);A(this,"bindModeHandler",null);A(this,"hitLinkElement");A(this,"lastPointerDownEvent",null);A(this,"lastPointerUpEvent",null);A(this,"lastPointerMoveEvent",null);A(this,"lastPointerMoveCoords",null);A(this,"previousPointerMoveCoords",null);A(this,"lastViewportPosition",{x:0,y:0});A(this,"animationFrameHandler",new pu);A(this,"laserTrails",new Bu(this.animationFrameHandler,this));A(this,"eraserTrail",new Gu(this.animationFrameHandler,this));A(this,"lassoTrail",new Hu(this.animationFrameHandler,this));A(this,"onChangeEmitter",new Ai);A(this,"onPointerDownEmitter",new Ai);A(this,"onPointerUpEmitter",new Ai);A(this,"onUserFollowEmitter",new Ai);A(this,"onScrollChangeEmitter",new Ai);A(this,"missingPointerEventCleanupEmitter",new Ai);A(this,"onRemoveEventListenersEmitter",new Ai);A(this,"updateEditorAtom",(o,...n)=>{let r=Et.set(o,...n);return this.triggerRender(),r});A(this,"previousHoveredBindableElement",null);A(this,"getEffectiveGridSize",()=>ma(this)?this.state.gridSize:null);A(this,"handleIframeLikeElementHover",({hitElement:o,scenePointer:n,moveEvent:r})=>o&&V1(o)&&(this.state.viewModeEnabled||this.state.activeTool.type==="laser"||this.isIframeLikeElementCenter(o,r,n.x,n.y))?(Be(this.interactiveCanvas,lt.POINTER),this.setState({activeEmbeddable:{element:o,state:"hover"}}),!0):(this.state.activeEmbeddable?.state==="hover"&&this.setState({activeEmbeddable:null}),!1));A(this,"updateEmbedValidationStatus",(o,n)=>{this.embedsValidationStatus.set(o.id,n),zd.delete(o)});A(this,"updateEmbeddables",()=>{let o=new Set,n=!1;this.scene.getNonDeletedElements().filter(r=>{if(Nr(r)){if(o.add(r.id),!this.embedsValidationStatus.has(r.id)){n=!0;let a=j1(r.link,this.props.validateEmbeddable);this.updateEmbedValidationStatus(r,a)}}else zl(r)&&o.add(r.id);return!1}),n&&this.scene.triggerUpdate(),this.iFrameRefs.forEach((r,a)=>{o.has(a)||this.iFrameRefs.delete(a)})});A(this,"getFrameNameDOMId",o=>`${this.id}-frame-name-${o.id}`);A(this,"frameNameBoundsCache",{get:o=>{let n=this.frameNameBoundsCache._cache.get(o.id);if(!n||n.zoom!==this.state.zoom.value||n.versionNonce!==o.versionNonce){let r=document.getElementById(this.getFrameNameDOMId(o));if(r){let a=r.getBoundingClientRect(),i=rt({clientX:a.x,clientY:a.y},this.state),s=rt({clientX:a.right,clientY:a.bottom},this.state);return n={x:i.x,y:i.y,width:s.x-i.x,height:s.y-i.y,angle:0,zoom:this.state.zoom.value,versionNonce:o.versionNonce},this.frameNameBoundsCache._cache.set(o.id,n),n}return null}return n},_cache:new Map});A(this,"resetEditingFrame",o=>{o&&this.scene.mutateElement(o,{name:o.name?.trim()||null}),this.setState({editingFrame:null})});A(this,"renderFrameNames",()=>{if(!this.state.frameRendering.enabled||!this.state.frameRendering.name)return this.state.editingFrame&&this.resetEditingFrame(null),null;let o=this.state.theme===Dg.DARK,n=this.scene.getNonDeletedFramesLikes(),r=n.length>0&&this.state.searchMatches?.focusedId&&Qt(this.scene.getElement(this.state.searchMatches.focusedId))?this.state.searchMatches.matches.find(a=>a.focus):null;return n.map(a=>{if(!l6(a,this.canvas.width/window.devicePixelRatio,this.canvas.height/window.devicePixelRatio,{offsetLeft:this.state.offsetLeft,offsetTop:this.state.offsetTop,scrollX:this.state.scrollX,scrollY:this.state.scrollY,zoom:this.state.zoom},this.scene.getNonDeletedElementsMap()))return this.state.editingFrame===a.id&&this.resetEditingFrame(a),null;let{x:i,y:s}=Ng({sceneX:a.x,sceneY:a.y},this.state),l=6,c,m=Yq(a),p=`${Math.round(a.width)} x ${Math.round(a.height)}`;if(a.id===this.state.editingFrame){let d=m;c=Se("input",{autoFocus:!0,value:d,onChange:u=>{this.scene.mutateElement(a,{name:u.target.value})},onFocus:u=>u.target.select(),onBlur:()=>this.resetEditingFrame(a),onKeyDown:u=>{(u.key===ne.ESCAPE||u.key===ne.ENTER)&&this.resetEditingFrame(a)},style:{background:o?lq(this.state.viewBackgroundColor):this.state.viewBackgroundColor,zIndex:2,border:"none",display:"block",padding:`${l}px`,borderRadius:4,boxShadow:"inset 0 0 0 1px var(--color-primary)",fontFamily:"Assistant",fontSize:`${ln.nameFontSize}px`,transform:`translate(-${l}px, ${l}px)`,color:o?ln.nameColorDarkTheme:ln.nameColorLightTheme,overflow:"hidden",maxWidth:`${document.body.clientWidth-i-l}px`},size:d.length+1||1,dir:"auto",autoComplete:"off",autoCapitalize:"off",autoCorrect:"off"})}else c=Vd(R6,{children:[Se("span",{children:m}),Se("span",{style:{marginLeft:8,opacity:.7,fontSize:ln.nameFontSize-1},children:p})]});return Se("div",{id:this.getFrameNameDOMId(a),className:U1.FRAME_NAME,style:{position:"absolute",bottom:`${this.state.height+ln.nameOffsetY-s+this.state.offsetTop}px`,left:`${i-this.state.offsetLeft}px`,zIndex:2,fontSize:ln.nameFontSize,color:o?ln.nameColorDarkTheme:ln.nameColorLightTheme,lineHeight:ln.nameLineHeight,width:"max-content",maxWidth:r?.id===a.id&&r?.focus?"none":`${a.width*this.state.zoom.value}px`,overflow:a.id===this.state.editingFrame?"visible":"hidden",whiteSpace:"nowrap",textOverflow:"ellipsis",cursor:lt.MOVE,pointerEvents:this.state.viewModeEnabled?Nl.disabled:Nl.enabled},onPointerDown:d=>this.handleCanvasPointerDown(d),onWheel:d=>this.handleWheel(d),onContextMenu:this.handleCanvasContextMenu,onDoubleClick:()=>{this.setState({editingFrame:a.id})},children:c},a.id)})});A(this,"focusContainer",()=>{this.excalidrawContainerRef.current?.focus()});A(this,"getSceneElementsIncludingDeleted",()=>this.scene.getElementsIncludingDeleted());A(this,"getSceneElementsMapIncludingDeleted",()=>this.scene.getElementsMapIncludingDeleted());A(this,"getSceneElements",()=>this.scene.getNonDeletedElements());A(this,"onInsertElements",o=>{this.addElementsFromPasteOrLibrary({elements:o,position:"center",files:null})});A(this,"onExportImage",async(o,n,r)=>{be("export",o,"ui");let a=await ei(o,n,this.state,this.files,{exportBackground:this.state.exportBackground,name:this.getName(),viewBackgroundColor:this.state.viewBackgroundColor,exportingFrame:r.exportingFrame}).catch(aq).catch(i=>{console.error(i),this.setState({errorMessage:i.message})});this.state.exportEmbedScene&&a&&sm(a)&&this.setState({fileHandle:a})});A(this,"magicGenerations",new Map);A(this,"updateMagicGeneration",({frameElement:o,data:n})=>{n.status==="pending"?this.scene.mutateElement(o,{customData:{generationData:void 0}},{informMutation:!1,isDragging:!1}):this.scene.mutateElement(o,{customData:{generationData:n}},{informMutation:!1,isDragging:!1}),this.magicGenerations.set(o.id,n),this.triggerRender()});A(this,"plugins",{});A(this,"onMagicframeToolSelect",()=>{let o=this.scene.getSelectedElements({selectedElementIds:this.state.selectedElementIds});if(o.length===0)this.setActiveTool({type:ar.magicframe}),be("ai","tool-select (empty-selection)","d2c");else{let n=o.length===1&&K1(o[0])&&o[0];if(!n&&o.some(a=>Qt(a)||a.frameId)){this.setActiveTool({type:ar.magicframe});return}be("ai","tool-select (existing selection)","d2c");let r;if(n)r=n;else{let[a,i,s,l]=Fl(o),c=50;r=n6({...ln,x:a-c,y:i-c,width:s-a+c*2,height:l-i+c*2,opacity:100,locked:!1}),this.scene.insertElement(r);for(let m of o)this.scene.mutateElement(m,{frameId:r.id});this.setState({selectedElementIds:{[r.id]:!0}})}this.onMagicFrameGenerate(r,"upstream")}});A(this,"onImageGeneratorSelect",()=>{let r=(this.canvas.width/window.devicePixelRatio/2-this.state.offsetLeft)/this.state.zoom.value-this.state.scrollX,a=(this.canvas.height/window.devicePixelRatio/2-this.state.offsetTop)/this.state.zoom.value-this.state.scrollY,i=t6({...ln,x:r-896/2,y:a-1344/2,width:896,height:1344,opacity:100,locked:!1,backgroundColor:"#cce8f5",fillStyle:"solid",customData:{type:"image-generator",imageGeneratorAutoFitPending:!0}});this.scene.insertElement(i),this.setActiveTool({type:"selection"}),this.setState({selectedElementIds:{[i.id]:!0}})});A(this,"insertGeneratedImageIntoFrame",async(o,n)=>{let r=R1(),a=W1({type:"image",x:n.x,y:n.y,width:n.width,height:n.height,fileId:r,status:"pending",scale:[1,1],frameId:null});this.scene.insertElement(a),this.scene.mutateElement(a,{frameId:n.id}),this.addFiles([{id:r,dataURL:o,mimeType:So(o),created:Date.now(),lastRetrieved:Date.now()}])});A(this,"insertGeneratedImageNearElement",async(o,n,r,a)=>{let s=this.scene.getNonDeletedElementsMap(),l=this.scene.getNonDeletedElements().filter(y=>y.id!==n.id),[c,m,p,d]=Og(n,s),u=[{x:p+25,y:m},{x:c,y:d+25},{x:c-r-25,y:m},{x:c,y:m-a-25}],h=(y,w)=>{let v=y+r,I=w+a,C=y-25,P=w-25,S=v+25,D=I+25;return l.some(_=>{let[k,M,B,O]=Og(_,s);return k<S&&B>C&&M<D&&O>P})},g=u.find(y=>!h(y.x,y.y))??u[0],x=R1(),E=W1({type:"image",x:g.x,y:g.y,width:r,height:a,fileId:x,status:"pending",scale:[1,1],frameId:null});this.scene.insertElement(E),this.addFiles([{id:x,dataURL:o,mimeType:So(o),created:Date.now(),lastRetrieved:Date.now()}]),this.setState({selectedElementIds:{[E.id]:!0}})});A(this,"openEyeDropper",({type:o})=>{this.updateEditorAtom(Yr,{swapPreviewOnAlt:!0,colorPickerType:o==="stroke"?"elementStroke":"elementBackground",onSelect:(n,r)=>{let a=o==="background"&&r.altKey||o==="stroke"&&!r.altKey;!this.scene.getSelectedElements(this.state).length||this.state.activeTool.type!=="selection"?a?this.syncActionResult({appState:{...this.state,currentItemStrokeColor:n},captureUpdate:po.IMMEDIATELY}):this.syncActionResult({appState:{...this.state,currentItemBackgroundColor:n},captureUpdate:po.IMMEDIATELY}):this.updateScene({elements:this.scene.getElementsIncludingDeleted().map(s=>this.state.selectedElementIds[s.id]?_a(s,{[a?"strokeColor":"backgroundColor"]:n}):s),captureUpdate:po.IMMEDIATELY})},keepOpenOnAlt:!1})});A(this,"dismissLinearEditor",()=>{setTimeout(()=>{this.state.selectedLinearElement?.isEditing&&this.setState({selectedLinearElement:{...this.state.selectedLinearElement,isEditing:!1}})})});A(this,"syncActionResult",pt(o=>{if(this.unmounted||o===!1)return;this.store.scheduleAction(o.captureUpdate);let n=!1,r=null;if(o.elements&&(this.scene.replaceAllElements(o.elements),n=!0),o.files&&(this.addMissingFiles(o.files,o.replaceFiles),this.addNewImagesToImageCache()),o.appState||r||this.state.contextMenu){let a=o?.appState?.viewModeEnabled||!1,i=o?.appState?.zenModeEnabled||!1,s=o?.appState?.theme||this.props.theme||Dg.LIGHT,l=o?.appState?.name??this.state.name,c=o?.appState?.errorMessage??this.state.errorMessage;typeof this.props.viewModeEnabled<"u"&&(a=this.props.viewModeEnabled),typeof this.props.zenModeEnabled<"u"&&(i=this.props.zenModeEnabled),r=o.appState?.editingTextElement||null,o.elements&&r&&o.elements.forEach(m=>{r?.id===m.id&&r!==m&&C6(m)&&kn(m)&&(r=m)}),r?.isDeleted&&(r=null),this.setState(m=>{let p=o.appState||{};return{...m,...p,contextMenu:null,editingTextElement:r,viewModeEnabled:a,zenModeEnabled:i,theme:s,name:l,errorMessage:c}}),n=!0}n||this.scene.triggerUpdate()}));A(this,"onBlur",pt(()=>{Ra=!1,this.setState({isBindingEnabled:!0})}));A(this,"onUnload",()=>{this.onBlur()});A(this,"disableEvent",o=>{o.preventDefault()});A(this,"resetHistory",()=>{this.history.clear()});A(this,"resetStore",()=>{this.store.clear()});A(this,"resetScene",pt(o=>{this.scene.replaceAllElements([]),this.setState(n=>({...Or(),isLoading:o?.resetLoadingState?!1:n.isLoading,theme:this.state.theme})),this.resetStore(),this.resetHistory()}));A(this,"initializeScene",async()=>{"launchQueue"in window&&"LaunchParams"in window&&window.launchQueue.setConsumer(async i=>{if(!i.files.length)return;let s=i.files[0],l=await s.getFile();this.loadFileToCanvas(new File([l],l.name||"",{type:l.type}),s)}),this.props.theme&&this.setState({theme:this.props.theme}),this.state.isLoading||this.setState({isLoading:!0});let o=null;try{typeof this.props.initialData=="function"?o=await this.props.initialData()||null:o=await this.props.initialData||null,o?.libraryItems&&this.library.updateLibrary({libraryItems:o.libraryItems,merge:!0}).catch(i=>{console.error(i)})}catch(i){console.error(i),o={appState:{errorMessage:i.message||"Encountered an error during importing or restoring scene data"}}}let n=Ga(o?.elements,null,{repairBindings:!0,deleteInvisibleElements:!0}),r=$i(o?.appState,null),a=r.activeTool;r.preferredSelectionTool.initialized||(r.preferredSelectionTool={type:this.editorInterface.formFactor==="phone"?"lasso":"selection",initialized:!0}),r={...r,theme:this.props.theme||r.theme,openSidebar:r?.openSidebar||this.state.openSidebar,activeTool:a.type==="image"||a.type==="lasso"||a.type==="selection"?{...a,type:r.preferredSelectionTool.type}:r.activeTool,isLoading:!1,toast:this.state.toast},o?.scrollToContent&&(r={...r,...Ha(n,{...r,width:this.state.width,height:this.state.height,offsetTop:this.state.offsetTop,offsetLeft:this.state.offsetLeft})}),this.resetStore(),this.resetHistory(),this.syncActionResult({elements:n,appState:r,files:o?.files,captureUpdate:po.NEVER}),this.clearImageShapeCache(),this.fonts.loadSceneFonts().then(i=>{this.fonts.onLoaded(i)}),ny(window.location.href)&&this.scrollToContent(window.location.href,{animate:!1})});A(this,"getFormFactor",(o,n)=>this.props.UIOptions.getFormFactor?.(o,n)??uq(o,n));A(this,"refreshEditorInterface",()=>{let o=this.excalidrawContainerRef.current;if(!o)return;let{width:n,height:r}=o.getBoundingClientRect(),a=bq(),i=F6(typeof navigator<"u"?navigator.userAgent:""),s=this.props.UIOptions.dockedSidebarBreakpoint!=null?this.props.UIOptions.dockedSidebarBreakpoint:Uj,l=G1(this.editorInterface,{desktopUIMode:a??this.editorInterface.desktopUIMode,formFactor:this.getFormFactor(n,r),userAgent:i,canFitSidebar:n>s,isLandscape:n>r});this.editorInterface=l,this.reconcileStylesPanelMode(l)});A(this,"reconcileStylesPanelMode",o=>{let n=Wg(o);if(n===this.stylesPanelMode)return;let r=this.stylesPanelMode;this.stylesPanelMode=n,r!=="full"&&n==="full"&&this.setState(a=>({preferredSelectionTool:{type:"selection",initialized:!0}}))});A(this,"setDesktopUIMode",o=>{let n=xq(o);this.editorInterface=G1(this.editorInterface,{desktopUIMode:n}),this.reconcileStylesPanelMode(this.editorInterface)});A(this,"onResize",pt(()=>{this.scene.getElementsIncludingDeleted().forEach(o=>zd.delete(o)),this.refreshEditorInterface(),this.updateDOMRect(),this.setState({})}));A(this,"onFullscreenChange",()=>{!document.fullscreenElement&&this.state.activeEmbeddable?.state==="active"&&this.setState({activeEmbeddable:null})});A(this,"renderInteractiveSceneCallback",({atLeastOneVisibleElement:o,scrollBars:n,elementsMap:r})=>{n&&(Wd=n);let a=this.state.editingTextElement?!1:!o&&r.size>0;this.state.scrolledOutside!==a&&this.setState({scrolledOutside:a}),this.scheduleImageRefresh()});A(this,"onScroll",ZP(()=>{let{offsetTop:o,offsetLeft:n}=this.getCanvasOffsets();this.setState(r=>r.offsetLeft===n&&r.offsetTop===o?null:{offsetTop:o,offsetLeft:n})},Wj));A(this,"onCut",pt(o=>{!this.excalidrawContainerRef.current?.contains(document.activeElement)||Rd(o.target)||(this.actionManager.executeAction(bp,"keyboard",o),o.preventDefault(),o.stopPropagation())}));A(this,"onCopy",pt(o=>{!this.excalidrawContainerRef.current?.contains(document.activeElement)||Rd(o.target)||(this.actionManager.executeAction(Os,"keyboard",o),o.preventDefault(),o.stopPropagation())}));A(this,"onTouchStart",o=>{if(gq&&o.preventDefault(),!Hd){Hd=!0,o.touches.length===1&&(Gd={x:o.touches[0].clientX,y:o.touches[0].clientY}),clearTimeout(ly),ly=window.setTimeout(e.resetTapTwice,Yj);return}if(Hd&&o.touches.length===1&&Gd){let n=o.touches[0];Pa(pe(n.clientX,n.clientY),pe(Gd.x,Gd.y))<=mq&&(this.lassoTrail.endPath(),this.deselectElements(),this.handleCanvasDoubleClick({clientX:n.clientX,clientY:n.clientY})),Hd=!1,clearTimeout(ly)}o.touches.length===2&&this.setState({selectedElementIds:ze({},this.state),activeEmbeddable:null})});A(this,"onTouchEnd",o=>{this.resetContextMenuTimer(),o.touches.length>0?this.setState({previousSelectedElementIds:{},selectedElementIds:ze(this.state.previousSelectedElementIds,this.state)}):Ne.pointers.clear()});A(this,"pasteFromClipboard",pt(async o=>{let n=!!my,r=document.activeElement,a=this.excalidrawContainerRef.current?.contains(r);if(o&&!a)return;let i=document.elementFromPoint(this.lastViewportPosition.x,this.lastViewportPosition.y);if(o&&(!(i instanceof HTMLCanvasElement)||Rd(r)))return;let s=await As(o),l=s.getFiles(),c=await sp(s,n);if(this.props.onPaste)try{if(await this.props.onPaste(c,o)===!1)return}catch(m){console.error(m)}await this.insertClipboardContent(c,l,n),this.setActiveTool({type:this.state.preferredSelectionTool.type},!0),o?.preventDefault()}));A(this,"addElementsFromPasteOrLibrary",o=>{let n=Ga(o.elements,null,{deleteInvisibleElements:!0}),[r,a,i,s]=Fl(n),l=Bl(r,i)/2,c=Bl(a,s)/2,m=typeof o.position=="object"?o.position.clientX:o.position==="cursor"?this.lastViewportPosition.x:this.state.width/2+this.state.offsetLeft,p=typeof o.position=="object"?o.position.clientY:o.position==="cursor"?this.lastViewportPosition.y:this.state.height/2+this.state.offsetTop,{x:d,y:u}=rt({clientX:m,clientY:p},this.state),h=d-l,g=u-c,[x,E]=Jt(h,g,this.getEffectiveGridSize()),{duplicatedElements:y}=Y1({type:"everything",elements:n.map(S=>_a(S,{x:S.x+x-r,y:S.y+E-a})),randomizeSeed:!o.retainSeed}),w=this.scene.getElementsIncludingDeleted(),v=[...w,...y];v=this.props.onDuplicate?.(v,w)||v,E6(v,Bg(y));let C=this.getTopLayerFrameAtSceneCoords({x:d,y:u});if(C){let S=Vq(y,C);ey(v,S,C,this.state)}this.scene.replaceAllElements(v),y.forEach(S=>{if(kn(S)&&$1(S)){let D=u6(S,this.scene.getElementsMapIncludingDeleted());Oq(S,D,this.scene)}}),fq&&Ho.loadElementsFonts(y).then(S=>{this.fonts.onLoaded(S)}),o.files&&this.addMissingFiles(o.files);let P=pJ(y);this.store.scheduleCapture(),this.setState({...this.state,openSidebar:this.state.openSidebar&&this.editorInterface.canFitSidebar&&Et.get(xd)?this.state.openSidebar:null,...cn({editingGroupId:null,selectedElementIds:P.reduce((S,D)=>($1(D)||(S[D.id]=!0),S),{})},this.scene.getNonDeletedElements(),this.state,this)},()=>{o.files&&this.addNewImagesToImageCache()}),this.setActiveTool({type:this.state.preferredSelectionTool.type},!0),o.fitToContent&&this.scrollToContent(y,{fitToContent:!0,canvasOffsets:this.getEditorUIOffsets()})});A(this,"setAppState",(o,n)=>{this.setState(o,n)});A(this,"removePointer",o=>{Na&&this.resetContextMenuTimer(),Ne.pointers.delete(o.pointerId)});A(this,"toggleLock",(o="ui")=>{this.state.activeTool.locked||be("toolbar","toggleLock",`${o} (${this.editorInterface.formFactor==="phone"?"mobile":"desktop"})`),this.setState(n=>({activeTool:{...n.activeTool,...ir(this.state,n.activeTool.locked?{type:this.state.preferredSelectionTool.type}:n.activeTool),locked:!n.activeTool.locked}}))});A(this,"updateFrameRendering",o=>{this.setState(n=>{let r=typeof o=="function"?o(n.frameRendering):o;return{frameRendering:{enabled:r?.enabled??n.frameRendering.enabled,clip:r?.clip??n.frameRendering.clip,name:r?.name??n.frameRendering.name,outline:r?.outline??n.frameRendering.outline}}})});A(this,"togglePenMode",o=>{this.setState(n=>({penMode:o??!n.penMode,penDetected:!0}))});A(this,"onHandToolToggle",()=>{this.actionManager.executeAction(F2)});A(this,"zoomCanvas",o=>{this.setState({...br({viewportX:this.state.width/2+this.state.offsetLeft,viewportY:this.state.height/2+this.state.offsetTop,nextZoom:Ln(o)},this.state)})});A(this,"cancelInProgressAnimation",null);A(this,"scrollToContent",(o=this.scene.getNonDeletedElements(),n)=>{if(typeof o=="string"){let l;if(ny(o)?l=eJ(o):l=o,l){let c=this.scene.getElementsFromId(l);c?.length?this.scrollToContent(c,{fitToContent:n?.fitToContent??!0,animate:n?.animate??!0}):ny(o)&&this.setState({toast:{message:f("elementLink.notFound"),duration:3e3,closable:!0}})}return}this.cancelInProgressAnimation?.();let r=Array.isArray(o)?o:[o],a=this.state.zoom,i=this.state.scrollX,s=this.state.scrollY;if(n?.fitToContent||n?.fitToViewport){let{appState:l}=Ss({canvasOffsets:n.canvasOffsets,targetElements:r,appState:this.state,fitToViewport:!!n?.fitToViewport,viewportZoomFactor:n?.viewportZoomFactor,minZoom:n?.minZoom,maxZoom:n?.maxZoom});a=l.zoom,i=l.scrollX,s=l.scrollY}else{let l=Ha(r,this.state);i=l.scrollX,s=l.scrollY}if(n?.animate){let l=this.state.scrollX,c=this.state.scrollY,m=this.state.zoom.value,p=rq({fromValues:{scrollX:l,scrollY:c,zoom:m},toValues:{scrollX:i,scrollY:s,zoom:a.value},interpolateValue:(d,u,h,g)=>{if(g==="zoom")return d*Math.pow(u/d,iq(h))},onStep:({scrollX:d,scrollY:u,zoom:h})=>{this.setState({scrollX:d,scrollY:u,zoom:{value:h}})},onStart:()=>{this.setState({shouldCacheIgnoreZoom:!0})},onEnd:()=>{this.setState({shouldCacheIgnoreZoom:!1})},onCancel:()=>{this.setState({shouldCacheIgnoreZoom:!1})},duration:n?.duration??500});this.cancelInProgressAnimation=()=>{p(),this.cancelInProgressAnimation=null}}else this.setState({scrollX:i,scrollY:s,zoom:a})});A(this,"maybeUnfollowRemoteUser",()=>{this.state.userToFollow&&this.setState({userToFollow:null})});A(this,"translateCanvas",o=>{this.cancelInProgressAnimation?.(),this.maybeUnfollowRemoteUser(),this.setState(o)});A(this,"setToast",o=>{this.setState({toast:o})});A(this,"restoreFileFromShare",async()=>{try{let o=await caches.open("web-share-target"),n=await o.match("shared-file");if(n){let r=await n.blob(),a=new File([r],r.name||"",{type:r.type});this.loadFileToCanvas(a,null),await o.delete("shared-file"),window.history.replaceState(null,Fj,window.location.pathname)}}catch(o){this.setState({errorMessage:o.message})}});A(this,"addFiles",pt(o=>{let{addedFiles:n}=this.addMissingFiles(o);this.clearImageShapeCache(n),this.scene.triggerUpdate(),this.addNewImagesToImageCache()}));A(this,"addMissingFiles",(o,n=!1)=>{let r=n?{}:{...this.files},a={},i=Array.isArray(o)?o:Object.values(o);for(let s of i)if(!r[s.id]&&(a[s.id]=s,r[s.id]=s,s.mimeType===rr.svg))try{let l=xE(p6(yE(s.dataURL)),rr.svg);s.dataURL!==l&&(s.version=(s.version??1)+1,s.dataURL=l)}catch(l){console.error(l)}return this.files=r,{addedFiles:a}});A(this,"updateScene",pt(o=>{let{elements:n,appState:r,collaborators:a,captureUpdate:i}=o;if(i){let s=n||void 0,l=r?yq({...this.store.snapshot.appState,...r}):void 0;this.store.scheduleMicroAction({action:i,elements:s,appState:l})}r&&this.setState(r),n&&this.scene.replaceAllElements(n),a&&this.setState({collaborators:a})}));A(this,"applyDeltas",(o,n)=>{let r=S6.squash(...o),a={...this.state},i=new Map(this.scene.getElementsMapIncludingDeleted());return S6.applyTo(r,i,a,n)});A(this,"mutateElement",(o,n,r=!0)=>this.scene.mutateElement(o,n,{informMutation:r,isDragging:!1}));A(this,"triggerRender",o=>{o===!0?this.scene.triggerUpdate():this.setState({})});A(this,"toggleSidebar",({name:o,tab:n,force:r})=>{let a;r===void 0?a=this.state.openSidebar?.name===o&&this.state.openSidebar?.tab===n?null:o:a=r?o:null;let i=a?{name:a}:null;return i&&n&&(i.tab=n),this.setState({openSidebar:i}),!!a});A(this,"updateCurrentCursorPosition",pt(o=>{this.lastViewportPosition.x=o.clientX,this.lastViewportPosition.y=o.clientY}));A(this,"getEditorUIOffsets",()=>{let o=this.excalidrawContainerRef?.current?.querySelector(".App-toolbar")?.getBoundingClientRect()?.bottom??0,n=this.excalidrawContainerRef?.current?.querySelector(".sidebar")?.getBoundingClientRect(),r=this.excalidrawContainerRef?.current?.querySelector(".App-menu__left")?.getBoundingClientRect(),a=16;return ur().rtl?{top:o+a,right:Math.max(this.state.width-(r?.left??this.state.width),0)+a,bottom:a,left:Math.max(n?.right??0,0)+a}:{top:o+a,right:Math.max(this.state.width-(n?.left??this.state.width)+a,0),bottom:a,left:Math.max(r?.right??0,0)+a}});A(this,"onKeyDown",pt(o=>{if("Proxy"in window&&(!o.shiftKey&&/^[A-Z]$/.test(o.key)||o.shiftKey&&/^[a-z]$/.test(o.key))&&(o=new Proxy(o,{get(s,l){let c=s[l];return typeof c=="function"?c.bind(s):l==="key"?o.shiftKey?s.key.toUpperCase():s.key.toLowerCase():c}})),!jP(o.target)){if((o.key===ne.ESCAPE||o.key===ne.ENTER)&&this.state.croppingElementId){this.finishImageCropping();return}let s=de(this.scene.getNonDeletedElementsMap(),this.state);if(s.length===1&&Da(s[0])&&o.key===ne.ENTER){this.startImageCropping(s[0]);return}if(o.key===ne.ESCAPE)this.updateEditorAtom(bn,null);else if(o.key===ne.TAB&&(document.activeElement===this.excalidrawContainerRef?.current||document.activeElement?.classList.contains(U1.CONVERT_ELEMENT_TYPE_POPUP))){o.preventDefault();let c=$s(s);Et.get(bn)?.type==="panel"&&Tb(this,{conversionType:c,direction:o.shiftKey?"left":"right"})&&this.store.scheduleCapture(),c&&this.updateEditorAtom(bn,{type:"panel"})}if(o.key===ne.ESCAPE&&this.flowChartCreator.isCreatingChart){this.flowChartCreator.clear(),this.triggerRender(!0);return}let l=Lg(o.key);if(o[ne.CTRL_OR_CMD]&&l&&!o.shiftKey){o.preventDefault();let c=de(this.scene.getNonDeletedElementsMap(),this.state);c.length===1&&Lq(c[0])&&this.flowChartCreator.createNodes(c[0],this.state,b6(o.key),this.scene),this.flowChartCreator.pendingNodes?.length&&!Z1(this.flowChartCreator.pendingNodes,this.canvas.width/window.devicePixelRatio,this.canvas.height/window.devicePixelRatio,{offsetLeft:this.state.offsetLeft,offsetTop:this.state.offsetTop,scrollX:this.state.scrollX,scrollY:this.state.scrollY,zoom:this.state.zoom},this.scene.getNonDeletedElementsMap(),this.getEditorUIOffsets())&&this.scrollToContent(this.flowChartCreator.pendingNodes,{animate:!0,duration:300,fitToContent:!0,canvasOffsets:this.getEditorUIOffsets()});return}if(o.altKey){let c=de(this.scene.getNonDeletedElementsMap(),this.state);if(c.length===1&&l){o.preventDefault();let m=this.flowChartNavigator.exploreByDirection(c[0],this.scene.getNonDeletedElementsMap(),b6(o.key));if(m){this.setState(d=>({selectedElementIds:ze({[m]:!0},d)}));let p=this.scene.getNonDeletedElementsMap().get(m);p&&!Z1([p],this.canvas.width/window.devicePixelRatio,this.canvas.height/window.devicePixelRatio,{offsetLeft:this.state.offsetLeft,offsetTop:this.state.offsetTop,scrollX:this.state.scrollX,scrollY:this.state.scrollY,zoom:this.state.zoom},this.scene.getNonDeletedElementsMap(),this.getEditorUIOffsets())&&this.scrollToContent(p,{animate:!0,duration:300,canvasOffsets:this.getEditorUIOffsets()})}return}}}if(o[ne.CTRL_OR_CMD]&&o.key===ne.P&&!o.shiftKey&&!o.altKey){this.setToast({message:f("commandPalette.shortcutHint",{shortcut:Xe("commandPalette")})}),o.preventDefault();return}if(o[ne.CTRL_OR_CMD]&&o.key.toLowerCase()===ne.V&&(my=o.shiftKey,clearTimeout(_6),_6=window.setTimeout(()=>{my=!1},100)),o[ne.CTRL_OR_CMD]&&Rd(o.target)&&(o.code===HP.MINUS||o.code===HP.EQUAL)){o.preventDefault();return}if(Rd(o.target)&&o.key!==ne.ESCAPE||Lg(o.key)&&jP(o.target))return;if(o.key===ne.QUESTION_MARK){this.setState({openDialog:{name:"help"}});return}else if(o.key.toLowerCase()===ne.E&&o.shiftKey&&o[ne.CTRL_OR_CMD]){o.preventDefault(),this.setState({openDialog:{name:"imageExport"}});return}if(o.key===ne.PAGE_UP||o.key===ne.PAGE_DOWN){let s=(o.shiftKey?this.state.width:this.state.height)/this.state.zoom.value;o.key===ne.PAGE_DOWN&&(s=-s),o.shiftKey?this.translateCanvas(l=>({scrollX:l.scrollX+s})):this.translateCanvas(l=>({scrollY:l.scrollY+s}))}if(this.state.openDialog?.name==="elementLinkSelector"||(o.key===ne.ALT&&(Rr("COMPLEX_BINDINGS")?this.handleSkipBindMode():Ug({app:this,event:o})),this.actionManager.handleKeyDown(o)))return;let n=this.props.viewModeEnabled===!0;if(!n&&this.state.viewModeEnabled&&o.key===ne.ESCAPE){this.setActiveTool({type:"hand"});return}if(!n&&!o.ctrlKey&&!o.altKey&&!o.metaKey&&!this.state.newElement&&!this.state.selectionElement&&!this.state.selectedElementsAreBeingDragged){let s=zC(o.key,this);if(this.state.viewModeEnabled&&!QP(s,["laser","hand"]))return;if(s){this.state.activeTool.type!==s&&be("toolbar",s,`keyboard (${this.editorInterface.formFactor==="phone"?"mobile":"desktop"})`),s==="arrow"&&this.state.activeTool.type==="arrow"&&this.setState(l=>({currentItemArrowType:l.currentItemArrowType===La.sharp?La.round:l.currentItemArrowType===La.round?La.elbow:La.sharp})),s==="lasso"&&this.state.activeTool.type==="laser"?this.setActiveTool({type:this.state.preferredSelectionTool.type}):this.setActiveTool({type:s}),o.stopPropagation();return}else if(o.key===ne.Q){this.toggleLock("keyboard"),o.stopPropagation();return}}if(this.state.viewModeEnabled)return;if(o[ne.CTRL_OR_CMD]&&this.state.isBindingEnabled&&(Rr("COMPLEX_BINDINGS")&&this.resetDelayedBindMode(),Io(()=>{this.setState({isBindingEnabled:!1})}),Ug({app:this,event:o})),Lg(o.key)){let s=this.scene.getSelectedElements({selectedElementIds:this.state.selectedElementIds,includeBoundTextElement:!0,includeElementsInFrames:!0}),l=new Set;s.filter(d=>lr(d)).filter(d=>{let u=d.startBinding&&!s.some(g=>g.id===d.startBinding?.elementId),h=d.endBinding&&!s.some(g=>g.id===d.endBinding?.elementId);return u||h}).forEach(d=>l.add(d.id)),s=s.filter(d=>!l.has(d.id));let c=this.getEffectiveGridSize()&&(o.shiftKey?$P:this.getEffectiveGridSize())||(o.shiftKey?zj:$P),m=0,p=0;o.key===ne.ARROW_LEFT?m=-c:o.key===ne.ARROW_RIGHT?m=c:o.key===ne.ARROW_UP?p=-c:o.key===ne.ARROW_DOWN&&(p=c),s.forEach(d=>{this.scene.mutateElement(d,{x:d.x+m,y:d.y+p},{informMutation:!1,isDragging:!1}),zg(d,this.scene,{simultaneouslyUpdated:s})}),this.scene.triggerUpdate(),o.preventDefault()}else if(o.key===ne.ENTER){let s=this.scene.getSelectedElements(this.state);if(s.length===1){let l=s[0];if(o[ne.CTRL_OR_CMD]||ry(l))mo(l)&&(!this.state.selectedLinearElement?.isEditing||this.state.selectedLinearElement.elementId!==l.id)&&(this.store.scheduleCapture(),To(l)||this.actionManager.executeAction(il));else if(kn(l)||Fq(l)){let c;kn(l)||(c=l);let m=J1(l,this.state,this.scene.getNonDeletedElementsMap()),p=m.x,d=m.y;this.startTextEditing({sceneX:p,sceneY:d,container:c}),o.preventDefault();return}else Qt(l)&&this.setState({editingFrame:l.id})}}if(o.key===ne.SPACE&&Ne.pointers.size===0&&(Ra=!0,Be(this.interactiveCanvas,lt.GRAB),o.preventDefault()),(o.key===ne.G||o.key===ne.S)&&!o.altKey&&!o[ne.CTRL_OR_CMD]){let s=this.scene.getSelectedElements(this.state);if(this.state.activeTool.type==="selection"&&!s.length)return;o.key===ne.G&&(_n(this.state.activeTool.type)||s.some(l=>_n(l.type)))&&(this.setState({openPopup:"elementBackground"}),o.stopPropagation()),o.key===ne.S&&(this.setState({openPopup:"elementStroke"}),o.stopPropagation())}if(!o[ne.CTRL_OR_CMD]&&o.shiftKey&&o.key.toLowerCase()===ne.F){let s=this.scene.getSelectedElements(this.state);if(this.state.activeTool.type==="selection"&&!s.length)return;(this.state.activeTool.type==="text"||s.find(l=>kn(l)||q1(l,this.scene.getNonDeletedElementsMap())))&&(o.preventDefault(),this.setState({openPopup:"fontFamily"}))}o[ne.CTRL_OR_CMD]&&(o.key===ne.BACKSPACE||o.key===ne.DELETE)&&this.updateEditorAtom(si,"clearCanvas");let r=o.key.toLocaleLowerCase(),a=r===ne.S&&o.shiftKey,i=o.key===ne.I||r===ne.G&&o.shiftKey;(a||i)&&this.openEyeDropper({type:a?"stroke":"background"})}));A(this,"onKeyUp",pt(o=>{if(o.key===ne.SPACE&&(this.state.viewModeEnabled&&this.state.activeTool.type!=="laser"||this.state.openDialog?.name==="elementLinkSelector"?Be(this.interactiveCanvas,lt.GRAB):Fg(this.state.activeTool.type)?Po(this.interactiveCanvas):(Ao(this.interactiveCanvas,this.state),this.setState({selectedElementIds:ze({},this.state),selectedGroupIds:{},editingGroupId:null,activeEmbeddable:null})),Ra=!1),o.key===ne.ALT&&Ug({app:this,event:o}),(o.key===ne.ALT&&this.state.bindMode==="skip"||!o[ne.CTRL_OR_CMD]&&!Bd(this.state))&&(this.setState({bindMode:"orbit"}),this.lastPointerMoveEvent&&Rr("COMPLEX_BINDINGS"))){let n=rt({clientX:this.lastPointerMoveEvent.clientX,clientY:this.lastPointerMoveEvent.clientY},this.state),r=Cn(pe(n.x,n.y),this.scene.getNonDeletedElements(),this.scene.getNonDeletedElementsMap());if(this.state.selectedLinearElement){let a=_e.getElement(this.state.selectedLinearElement.elementId,this.scene.getNonDeletedElementsMap());lr(a)&&this.handleDelayedBindModeChange(a,r)}}if(!o[ne.CTRL_OR_CMD]&&!this.state.isBindingEnabled&&(Io(()=>{this.setState({isBindingEnabled:!0})}),Ug({app:this,event:o})),Lg(o.key)){e6(this.scene.getSelectedElements(this.state).filter(Ol),this.scene,this.state);let n=this.scene.getNonDeletedElementsMap();this.scene.getSelectedElements(this.state).filter(ay).forEach(r=>{r.startBinding&&this.scene.mutateElement(r,{startBinding:{...r.startBinding,...P6(r,n.get(r.startBinding.elementId),"start",n)}}),r.endBinding&&this.scene.mutateElement(r,{endBinding:{...r.endBinding,...P6(r,n.get(r.endBinding.elementId),"end",n)}})}),this.setState({suggestedBinding:null})}if(o.altKey||this.flowChartNavigator.isExploring&&(this.flowChartNavigator.clear(),this.syncActionResult({captureUpdate:po.IMMEDIATELY})),!o[ne.CTRL_OR_CMD]&&this.flowChartCreator.isCreatingChart){this.flowChartCreator.pendingNodes?.length&&this.scene.insertElements(this.flowChartCreator.pendingNodes);let n=this.flowChartCreator.pendingNodes?.[0];n&&(this.setState(r=>({selectedElementIds:ze({[n.id]:!0},r)})),Z1([n],this.canvas.width/window.devicePixelRatio,this.canvas.height/window.devicePixelRatio,{offsetLeft:this.state.offsetLeft,offsetTop:this.state.offsetTop,scrollX:this.state.scrollX,scrollY:this.state.scrollY,zoom:this.state.zoom},this.scene.getNonDeletedElementsMap(),this.getEditorUIOffsets())||this.scrollToContent(n,{animate:!0,duration:300,canvasOffsets:this.getEditorUIOffsets()})),this.flowChartCreator.clear(),this.syncActionResult({captureUpdate:po.IMMEDIATELY})}}));A(this,"isToolSupported",o=>this.props.UIOptions.tools?.[o]!==!1);A(this,"setActiveTool",(o,n=!1)=>{if(!this.isToolSupported(o.type)){console.warn(`"${o.type}" tool is disabled via "UIOptions.canvasActions.tools.${o.type}"`);return}let r=ir(this.state,o);r.type==="hand"?Be(this.interactiveCanvas,lt.GRAB):Ra||Ao(this.interactiveCanvas,{...this.state,activeTool:r}),tq(document.activeElement)&&this.focusContainer(),Pq(r.type)||this.setState({suggestedBinding:null}),r.type==="image"&&this.onImageToolbarButtonClick(),this.setState(a=>{let i={snapLines:a.snapLines.length?[]:a.snapLines,originSnapOffset:null,activeEmbeddable:null,selectedLinearElement:Fg(r.type)?a.selectedLinearElement:null};return r.type==="freedraw"&&this.store.scheduleCapture(),r.type==="lasso"?{...a,...i,activeTool:r,...n?{}:{selectedElementIds:ze({},a),selectedGroupIds:ze({},a),editingGroupId:null,multiElement:null}}:r.type!=="selection"?{...a,...i,activeTool:r,selectedElementIds:ze({},a),selectedGroupIds:ze({},a),editingGroupId:null,multiElement:null}:{...a,...i,activeTool:r}})});A(this,"setOpenDialog",o=>{this.setState({openDialog:o})});A(this,"setCursor",o=>{Be(this.interactiveCanvas,o)});A(this,"resetCursor",()=>{Po(this.interactiveCanvas)});A(this,"isTouchScreenMultiTouchGesture",()=>Ne.pointers.size>=2);A(this,"getName",()=>this.state.name||this.props.name||`${f("labels.untitled")}-${qP()}`);A(this,"onGestureStart",pt(o=>{o.preventDefault(),this.isTouchScreenMultiTouchGesture()&&this.setState({selectedElementIds:ze({},this.state),activeEmbeddable:null}),Ne.initialScale=this.state.zoom.value}));A(this,"onGestureChange",pt(o=>{if(o.preventDefault(),this.isTouchScreenMultiTouchGesture())return;let n=Ne.initialScale;n&&this.setState(r=>({...br({viewportX:this.lastViewportPosition.x,viewportY:this.lastViewportPosition.y,nextZoom:Ln(n*o.scale)},r)}))}));A(this,"onGestureEnd",pt(o=>{o.preventDefault(),this.isTouchScreenMultiTouchGesture()&&this.setState({previousSelectedElementIds:{},selectedElementIds:ze(this.state.previousSelectedElementIds,this.state)}),Ne.initialScale=null}));A(this,"startTextEditing",({sceneX:o,sceneY:n,insertAtParentCenter:r=!0,container:a,autoEdit:i=!0})=>{let s=!1,l=r&&this.getTextWysiwygSnappedToCenterPosition(o,n,this.state,a);a&&l&&(q1(a,this.scene.getNonDeletedElementsMap())||(s=!0));let c=null,m=this.scene.getSelectedElements(this.state);m.length===1?kn(m[0])?c=m[0]:a?c=q1(m[0],this.scene.getNonDeletedElementsMap()):c=this.getTextElementAtPosition(o,n):c=this.getTextElementAtPosition(o,n);let p=c?.fontFamily||this.state.currentItemFontFamily,d=c?.lineHeight||XP(p),u=this.state.currentItemFontSize;if(!c&&s&&a&&!Ol(a)){let E=rJ(z1({fontSize:u,fontFamily:p}),d),y=aJ(u,d),w=Math.max(a.height,y),v=Math.max(a.width,E);this.scene.mutateElement(a,{height:w,width:v}),o=a.x+v/2,n=a.y+w/2,l&&(l=this.getTextWysiwygSnappedToCenterPosition(o,n,this.state,a))}let h=this.getTopLayerFrameAtSceneCoords({x:o,y:n}),g=c||r6({x:l?l.elementCenterX:o,y:l?l.elementCenterY:n,strokeColor:this.state.currentItemStrokeColor,backgroundColor:this.state.currentItemBackgroundColor,fillStyle:this.state.currentItemFillStyle,strokeWidth:this.state.currentItemStrokeWidth,strokeStyle:this.state.currentItemStrokeStyle,roughness:this.state.currentItemRoughness,opacity:this.state.currentItemOpacity,text:"",fontSize:u,fontFamily:p,textAlign:l?"center":this.state.currentItemTextAlign,verticalAlign:l?Kj.MIDDLE:WP,containerId:s?a?.id:void 0,groupIds:a?.groupIds??[],lineHeight:d,angle:a?Ol(a)?0:a.angle:0,frameId:h?h.id:null});if(!c&&s&&a&&this.scene.mutateElement(a,{boundElements:(a.boundElements||[]).concat({type:"text",id:g.id})}),this.setState({editingTextElement:g}),!c)if(a&&s){let x=this.scene.getElementIndex(a.id);this.scene.insertElementAtIndex(g,x+1)}else this.scene.insertElement(g);i||c||a?this.handleTextWysiwyg(g,{isExistingElement:!!c}):this.setState({newElement:g,multiElement:null})});A(this,"startImageCropping",o=>{this.store.scheduleCapture(),this.setState({croppingElementId:o.id})});A(this,"finishImageCropping",()=>{this.state.croppingElementId&&(this.store.scheduleCapture(),this.setState({croppingElementId:null}))});A(this,"handleCanvasDoubleClick",o=>{if(this.state.multiElement||this.state.activeTool.type!==this.state.preferredSelectionTool.type)return;let n=this.scene.getSelectedElements(this.state),{x:r,y:a}=rt(o,this.state);if(n.length===1&&mo(n[0])){let s=n[0];if((o[ne.CTRL_OR_CMD]&&ay(s)||ry(s))&&(!this.state.selectedLinearElement?.isEditing||this.state.selectedLinearElement.elementId!==s.id)){this.actionManager.executeAction(il);return}else if(this.state.selectedLinearElement&&To(n[0])){let l=_e.getSegmentMidpointHitCoords(this.state.selectedLinearElement,{x:r,y:a},this.state,this.scene.getNonDeletedElementsMap()),c=l?_e.getSegmentMidPointIndex(this.state.selectedLinearElement,this.state,l,this.scene.getNonDeletedElementsMap()):-1;if(c&&c>-1){this.store.scheduleCapture(),_e.deleteFixedSegment(n[0],this.scene,c);let m=_e.getSegmentMidpointHitCoords({...this.state.selectedLinearElement,segmentMidPointHoveredCoords:null},{x:r,y:a},this.state,this.scene.getNonDeletedElementsMap()),p=m?_e.getSegmentMidPointIndex(this.state.selectedLinearElement,this.state,m,this.scene.getNonDeletedElementsMap()):null;this.setState({selectedLinearElement:{...this.state.selectedLinearElement,initialState:{...this.state.selectedLinearElement.initialState,segmentMidpoint:{index:p,value:l,added:!1}},segmentMidPointHoveredCoords:m}});return}}else if(this.state.selectedLinearElement?.isEditing&&this.state.selectedLinearElement.elementId===s.id&&ry(s))return}if(n.length===1&&Da(n[0])){this.startImageCropping(n[0]);return}if(Po(this.interactiveCanvas),dJ(this.state).length>0){let s=this.getElementAtPosition(r,a),l=s&&cJ(s,this.state.selectedGroupIds);if(l){this.store.scheduleCapture(),this.setState(c=>({...c,...cn({editingGroupId:l,selectedElementIds:{[s.id]:!0}},this.scene.getNonDeletedElements(),c,this)}));return}}if(Po(this.interactiveCanvas),!o[ne.CTRL_OR_CMD]&&!this.state.viewModeEnabled){let s=this.getElementAtPosition(r,a);if(V1(s)){this.setState({activeEmbeddable:{element:s,state:"active"}});return}if(!this.state.selectedLinearElement?.isEditing){let l=this.getTextBindableContainerAtPosition(r,a);if(l&&(i6(l)||!nq(l.backgroundColor)||Od({point:pe(r,a),element:l,elementsMap:this.scene.getNonDeletedElementsMap(),threshold:this.getElementHitThreshold(l)}))){let c=J1(l,this.state,this.scene.getNonDeletedElementsMap());r=c.x,a=c.y}this.startTextEditing({sceneX:r,sceneY:a,insertAtParentCenter:!o.altKey,container:l})}}});A(this,"getElementLinkAtPosition",(o,n)=>{if(n&&n.locked)return;let r=this.scene.getNonDeletedElements(),a=-1;for(let i=r.length-1;i>=0;i--){let s=r[i];if(n&&s.id===n.id&&(a=i),s.link&&i>=a&&rm(s,this.scene.getNonDeletedElementsMap(),this.state,pe(o.x,o.y),this.editorInterface.formFactor==="phone"))return s}});A(this,"handleElementLinkClick",o=>{let n=Pa(pe(this.lastPointerDownEvent.clientX,this.lastPointerDownEvent.clientY),pe(this.lastPointerUpEvent.clientX,this.lastPointerUpEvent.clientY));if(!this.hitLinkElement||n>YP)return;let r=rt(this.lastPointerDownEvent,this.state),a=this.scene.getNonDeletedElementsMap(),i=rm(this.hitLinkElement,a,this.state,pe(r.x,r.y),this.editorInterface.formFactor==="phone"),s=rt(this.lastPointerUpEvent,this.state),l=rm(this.hitLinkElement,a,this.state,pe(s.x,s.y),this.editorInterface.formFactor==="phone");if(i&&l){ub();let c=this.hitLinkElement.link;if(c){c=O1(c);let m;if(this.props.onLinkOpen&&(m=oq(he.EXCALIDRAW_LINK,o.nativeEvent),this.props.onLinkOpen({...this.hitLinkElement,link:c},m)),!m?.defaultPrevented){let p=Jj(c)?"_self":"_blank",d=window.open(void 0,p);d&&(d.opener=null,d.location=c)}}}});A(this,"getTopLayerFrameAtSceneCoords",o=>{let n=this.scene.getNonDeletedElementsMap(),r=this.scene.getNonDeletedFramesLikes().filter(a=>!a.locked&&g6(o,a,n));return r.length?r[r.length-1]:null});A(this,"handleCanvasPointerMove",o=>{this.savePointer(o.clientX,o.clientY,this.state.cursorButton),this.lastPointerMoveEvent=o.nativeEvent;let n=rt(o,this.state),{x:r,y:a}=n;this.lastPointerMoveCoords={x:r,y:a},Ne.pointers.has(o.pointerId)&&Ne.pointers.set(o.pointerId,{x:o.clientX,y:o.clientY});let i=Ne.initialScale;if(Ne.pointers.size===2&&Ne.lastCenter&&i&&Ne.initialDistance){let g=M0(Ne.pointers),x=g.x-Ne.lastCenter.x,E=g.y-Ne.lastCenter.y;Ne.lastCenter=g;let y=P0(Array.from(Ne.pointers.values())),w=this.state.activeTool.type==="freedraw"&&this.state.penMode?1:y/Ne.initialDistance,v=w?Ln(i*w):this.state.zoom.value;this.setState(I=>{let C=br({viewportX:g.x,viewportY:g.y,nextZoom:v},I);return this.translateCanvas({zoom:C.zoom,scrollX:C.scrollX+2*(x/v),scrollY:C.scrollY+2*(E/v),shouldCacheIgnoreZoom:!0}),null}),this.resetShouldCacheIgnoreZoomDebounced()}else Ne.lastCenter=Ne.initialDistance=Ne.initialScale=null;if(Ra||Ud||cy||pr(this.state))return;let l=ix(Wd,o.clientX-this.state.offsetLeft,o.clientY-this.state.offsetTop).isOverEither;if(!this.state.newElement&&!this.state.selectionElement&&!this.state.selectedElementsAreBeingDragged&&!this.state.multiElement&&(l?Po(this.interactiveCanvas):Ao(this.interactiveCanvas,this.state)),!this.state.newElement&&bk(this.state.activeTool.type)){let{originOffset:g,snapLines:x}=fk(this.scene.getNonDeletedElements(),this,{x:r,y:a},o,this.scene.getNonDeletedElementsMap());this.setState(E=>{let y=Nd(E.snapLines,x),w=E.originSnapOffset?Nd(E.originSnapOffset,g):g;return E.snapLines===y&&E.originSnapOffset===w?null:{snapLines:y,originSnapOffset:w}})}else!this.state.newElement&&!this.state.selectedElementsAreBeingDragged&&!this.state.selectionElement&&this.setState(g=>g.snapLines.length?{snapLines:[]}:null);if(this.state.selectedLinearElement?.isEditing&&!this.state.selectedLinearElement.isDragging){let g=this.state.newElement?null:_e.handlePointerMoveInEditMode(o,r,a,this);g&&g!==this.state.selectedLinearElement&&Io(()=>{this.setState({selectedLinearElement:g})})}if(Mq(this.state.activeTool.type)){let{newElement:g}=this.state;if(!g&&Bd(this.state)){let x=pe(r,a),E=this.scene.getNonDeletedElementsMap(),y=Cn(x,this.scene.getNonDeletedElements(),E,iy(this.state.zoom));y?this.setState({suggestedBinding:{element:y,midPoint:sy(x,y,E,this.state.zoom)}}):this.state.suggestedBinding&&this.setState({suggestedBinding:null})}}if(this.state.multiElement&&this.state.selectedLinearElement){let{multiElement:g,selectedLinearElement:x}=this.state,{x:E,y,points:w}=g,v=w[w.length-1],{lastCommittedPoint:I}=x;if(Ao(this.interactiveCanvas,this.state),v===I)Ol(this.state.newElement)&&Bd(this.state)&&Cn(pe(r,a),this.scene.getNonDeletedElements(),this.scene.getNonDeletedElementsMap(),iy(this.state.zoom))?(this.actionManager.executeAction(ro,"ui",{event:o.nativeEvent,sceneCoords:{x:r,y:a}}),this.setState({suggestedBinding:null,startBoundElement:null}),this.state.activeTool.locked||(Po(this.interactiveCanvas),this.setState(P=>({newElement:null,activeTool:ir(this.state,{type:this.state.preferredSelectionTool.type}),selectedElementIds:ze({...P.selectedElementIds,[g.id]:!0},P),selectedLinearElement:new _e(g,this.scene.getNonDeletedElementsMap())})))):Pa(pe(r-E,a-y),v)>=F1?(this.scene.mutateElement(g,{points:[...w,pe(r-E,a-y)]},{informMutation:!1,isDragging:!1}),sr(this.state.selectedLinearElement?.initialState,"initialState must be set"),this.setState({selectedLinearElement:{...this.state.selectedLinearElement,lastCommittedPoint:w[w.length-1],selectedPointsIndices:[g.points.length-1],initialState:{...this.state.selectedLinearElement.initialState,lastClickedPoint:g.points.length-1}}})):Be(this.interactiveCanvas,lt.POINTER);else if(w.length>2&&I&&Pa(pe(r-E,a-y),I)<F1)Be(this.interactiveCanvas,lt.POINTER),this.scene.mutateElement(g,{points:w.slice(0,-1)},{informMutation:!1,isDragging:!1}),this.setState({selectedLinearElement:{...x,selectedPointsIndices:x.selectedPointsIndices?.includes(g.points.length)?[...x.selectedPointsIndices.filter(C=>C!==g.points.length&&C!==g.points.length-1),g.points.length-1]:x.selectedPointsIndices,lastCommittedPoint:g.points[g.points.length-1],initialState:{...x.initialState,lastClickedPoint:g.points.length-1}}});else{d6(w,this.state.zoom.value)&&Be(this.interactiveCanvas,lt.POINTER);let C=this.scene.getNonDeletedElementsMap();if(ay(g)){let S=Cn(pe(r,a),this.scene.getNonDeletedElements(),C);Rr("COMPLEX_BINDINGS")&&this.handleDelayedBindModeChange(g,S)}sr(this.state.selectedLinearElement,"Expected selectedLinearElement to be set to operate on a linear element");let P=_e.handlePointerMove(o.nativeEvent,this,r,a,this.state.selectedLinearElement);P&&this.setState(P)}return}if(this.state.activeTool.type==="arrow"){let g=Cn(pe(r,a),this.scene.getNonDeletedElements(),this.scene.getNonDeletedElementsMap(),iy(this.state.zoom)),x=pe(r,a),E=this.scene.getNonDeletedElementsMap();g&&!IJ(x,g,E)&&this.setState({suggestedBinding:{element:g,midPoint:sy(x,g,E,this.state.zoom)}})}let c=!!o.buttons,m=this.state.activeTool.type==="laser";if(c||!m&&this.state.activeTool.type!=="selection"&&this.state.activeTool.type!=="lasso"&&this.state.activeTool.type!=="text"&&this.state.activeTool.type!=="eraser")return;let p=this.scene.getNonDeletedElements(),d=this.scene.getSelectedElements(this.state);if(d.length===1&&!l&&!this.state.selectedLinearElement?.isEditing){if(this.state.selectedLinearElement&&this.handleHoverSelectedLinearElement(this.state.selectedLinearElement,r,a),(!this.state.selectedLinearElement||this.state.selectedLinearElement.hoverPointIndex===-1)&&this.state.openDialog?.name!=="elementLinkSelector"&&!(d.length===1&&To(d[0]))&&!(mo(d[0])&&(this.editorInterface.userAgent.isMobileDevice||d[0].points.length===2))){let g=v6(p,this.state,r,a,this.state.zoom,o.pointerType,this.scene.getNonDeletedElementsMap(),this.editorInterface);if(g&&g.transformHandleType){Be(this.interactiveCanvas,w6(g));return}}}else if(d.length>1&&!l&&this.state.openDialog?.name!=="elementLinkSelector"){let g=I6(Fl(d),r,a,this.state.zoom,o.pointerType,this.editorInterface);if(g){Be(this.interactiveCanvas,w6({transformHandleType:g}));return}}if(ho(this.state))return;let u=this.getElementAtPosition(r,a,{preferSelected:!0,includeLockedElements:!0}),h=null;if(u&&u.locked?h=null:h=u,this.handleIframeLikeElementHover({hitElement:h,scenePointer:n,moveEvent:o})||(this.hitLinkElement=this.getElementLinkAtPosition(n,u)),this.hitLinkElement&&!this.state.selectedElementIds[this.hitLinkElement.id])Be(this.interactiveCanvas,lt.POINTER),cT(this.hitLinkElement,this.state,this.scene.getNonDeletedElementsMap());else{if(ub(),m)return;h&&(h.link||Nr(h))&&this.state.selectedElementIds[h.id]&&!this.state.contextMenu&&!this.state.showHyperlinkPopup?this.setState({showHyperlinkPopup:"info"}):this.state.activeTool.type==="text"?Be(this.interactiveCanvas,kn(h)?lt.TEXT:lt.CROSSHAIR):this.state.viewModeEnabled?Be(this.interactiveCanvas,lt.GRAB):this.state.openDialog?.name==="elementLinkSelector"?Be(this.interactiveCanvas,lt.AUTO):l?Be(this.interactiveCanvas,lt.AUTO):o[ne.CTRL_OR_CMD]?Be(this.interactiveCanvas,lt.AUTO):(h||this.isHittingCommonBoundingBoxOfSelectedElements(n,d))&&!h?.locked&&(!h||!To(h)||!(h.startBinding||h.endBinding))&&(this.state.activeTool.type!=="lasso"||d.length>0)&&Be(this.interactiveCanvas,lt.MOVE),this.state.selectedLinearElement&&this.handleHoverSelectedLinearElement(this.state.selectedLinearElement,r,a)}this.state.openDialog?.name==="elementLinkSelector"&&h?this.setState(g=>({hoveredElementIds:Nd(g.hoveredElementIds,cn({editingGroupId:g.editingGroupId,selectedElementIds:{[h.id]:!0}},this.scene.getNonDeletedElements(),g,this).selectedElementIds)})):this.state.openDialog?.name==="elementLinkSelector"&&!h&&this.setState(g=>({hoveredElementIds:Nd(g.hoveredElementIds,{})}))});A(this,"handleEraser",(o,n)=>{let r=this.eraserTrail.addPointToPath(n.x,n.y,o.altKey);this.elementsPendingErasure=new Set(r),this.triggerRender()});A(this,"handleTouchMove",o=>{Yd=!0});A(this,"handleCanvasPointerDown",o=>{let n=rt(o,this.state),{x:r,y:a}=n;this.lastPointerMoveCoords={x:r,y:a};let i=o.target;if(i.setPointerCapture&&i.setPointerCapture(o.pointerId),this.maybeCleanupAfterMissingPointerUp(o.nativeEvent),this.maybeUnfollowRemoteUser(),this.state.searchMatches&&(this.setState(h=>({searchMatches:h.searchMatches&&{focusedId:null,matches:h.searchMatches.matches.map(g=>({...g,focus:!1}))}})),this.updateEditorAtom(Ox,null)),Et.get(bn)&&this.updateEditorAtom(bn,null),this.state.contextMenu&&this.setState({contextMenu:null}),this.state.snapLines&&this.setAppState({snapLines:[]}),this.state.openPopup&&this.setState({openPopup:null}),this.updateGestureOnPointerDown(o),o.pointerType==="touch"&&this.state.newElement&&this.state.newElement.type==="freedraw"){let h=this.state.newElement;this.updateScene({...h.points.length<10?{elements:this.scene.getElementsIncludingDeleted().filter(g=>g.id!==h.id)}:{},appState:{newElement:null,editingTextElement:null,startBoundElement:null,suggestedBinding:null,selectedElementIds:ze(Object.keys(this.state.selectedElementIds).filter(g=>g!==h.id).reduce((g,x)=>(g[x]=this.state.selectedElementIds[x],g),{}),this.state)},captureUpdate:this.state.openDialog?.name==="elementLinkSelector"?po.EVENTUALLY:po.NEVER});return}let s=document.getSelection();if(s?.anchorNode&&s.removeAllRanges(),this.maybeOpenContextMenuAfterPointerDownOnTouchDevices(o),!this.state.penDetected&&o.pointerType==="pen"&&this.setState(h=>({penMode:!0,penDetected:!0})),!this.editorInterface.isTouchScreen&&["pen","touch"].includes(o.pointerType)&&(this.editorInterface=G1(this.editorInterface,{isTouchScreen:!0})),Ud||(this.lastPointerDownEvent=o,this.handleCanvasPanUsingWheelOrSpaceDrag(o)))return;if(this.setState({lastPointerDownWith:o.pointerType,cursorButton:"down"}),this.savePointer(o.clientX,o.clientY,"down"),o.button===Aa.ERASER&&this.state.activeTool.type!==ar.eraser){this.setState({activeTool:ir(this.state,{type:ar.eraser,lastActiveToolBeforeEraser:this.state.activeTool})},()=>{this.handleCanvasPointerDown(o);let h=()=>{g(),x?.(),ho(this.state)&&this.setState({activeTool:ir(this.state,{...this.state.activeTool.lastActiveTool||{type:ar.selection},lastActiveToolBeforeEraser:null})})},g=ht(window,he.POINTER_UP,h,{once:!0}),x;requestAnimationFrame(()=>{x=this.missingPointerEventCleanupEmitter.once(h)})});return}if(o.button!==Aa.MAIN&&o.button!==Aa.TOUCH&&o.button!==Aa.ERASER||Ne.pointers.size>1)return;let l=this.initialPointerDownState(o);if(this.setState({selectedElementsAreBeingDragged:!1}),this.handleDraggingScrollBar(o,l)||(this.clearSelectionIfNotUsingSelection(),this.updateBindingEnabledOnPointerMove(o),this.handleSelectionOnPointerDown(o,l))||!(!this.state.penMode||o.pointerType!=="touch"||this.state.activeTool.type==="selection"||this.state.activeTool.type==="lasso"||this.state.activeTool.type==="text"||this.state.activeTool.type==="image"))return;if(this.state.activeTool.type==="lasso"){let h=l.hit.element&&this.isASelectedElement(l.hit.element);!l.hit.hasHitCommonBoundingBoxOfSelectedElements&&!l.resize.handleType&&!h&&(this.lassoTrail.startPath(l.origin.x,l.origin.y,o.shiftKey),l.drag.blockDragging=this.editorInterface.formFactor==="desktop"),this.editorInterface.formFactor!=="desktop"&&l.hit.element&&!h&&(this.setState(g=>{let x={...g.selectedElementIds,[l.hit.element.id]:!0},E=[];Object.keys(g.selectedElementIds).forEach(w=>{let v=this.scene.getElement(w);v&&E.push(v)});let y=l.hit.element;if(Qt(y))Q1(E,y.id).forEach(w=>{delete x[w.id]});else if(y.frameId)x[y.frameId]&&delete x[y.id];else{let w=y.groupIds,v=new Set(w.flatMap(I=>Li(this.scene.getNonDeletedElements(),I)).filter(I=>Qt(I)).map(I=>I.id));v.size>0&&E.forEach(I=>{I.frameId&&v.has(I.frameId)&&(delete x[I.id],I.groupIds.flatMap(C=>Li(this.scene.getNonDeletedElements(),C)).forEach(C=>{delete x[C.id]}))})}return{...cn({editingGroupId:g.editingGroupId,selectedElementIds:x},this.scene.getNonDeletedElements(),g,this),showHyperlinkPopup:y.link||Nr(y)?"info":!1}}),l.hit.wasAddedToSelection=!0)}else this.state.activeTool.type==="text"?this.handleTextOnPointerDown(o,l):this.state.activeTool.type==="arrow"||this.state.activeTool.type==="line"?this.handleLinearElementOnPointerDown(o,this.state.activeTool.type,l):this.state.activeTool.type==="freedraw"?this.handleFreeDrawElementOnPointerDown(o,this.state.activeTool.type,l):this.state.activeTool.type==="custom"?Ao(this.interactiveCanvas,this.state):this.state.activeTool.type===ar.frame||this.state.activeTool.type===ar.magicframe?this.createFrameElementOnPointerDown(l,this.state.activeTool.type):this.state.activeTool.type==="laser"?this.laserTrails.startPath(l.lastCoords.x,l.lastCoords.y):this.state.activeTool.type!=="eraser"&&this.state.activeTool.type!=="hand"&&this.state.activeTool.type!=="image"&&this.createGenericElementOnPointerDown(this.state.activeTool.type,l);this.props?.onPointerDown?.(this.state.activeTool,l),this.onPointerDownEmitter.trigger(this.state.activeTool,l,o),this.state.activeTool.type==="eraser"&&this.eraserTrail.startPath(l.lastCoords.x,l.lastCoords.y);let m=this.onPointerMoveFromPointerDownHandler(l),p=this.onPointerUpFromPointerDownHandler(l),d=this.onKeyDownFromPointerDownHandler(l),u=this.onKeyUpFromPointerDownHandler(l);this.missingPointerEventCleanupEmitter.once(h=>p(h||o.nativeEvent)),(!this.state.viewModeEnabled||this.state.activeTool.type==="laser")&&(window.addEventListener(he.POINTER_MOVE,m),window.addEventListener(he.POINTER_UP,p),window.addEventListener(he.KEYDOWN,d),window.addEventListener(he.KEYUP,u),l.eventListeners.onMove=m,l.eventListeners.onUp=p,l.eventListeners.onKeyUp=u,l.eventListeners.onKeyDown=d)});A(this,"handleCanvasPointerUp",o=>{Rr("COMPLEX_BINDINGS")&&this.resetDelayedBindMode(),this.removePointer(o),this.lastPointerUpEvent=o;let n=rt({clientX:o.clientX,clientY:o.clientY},this.state),{x:r,y:a}=n;if(this.lastPointerMoveCoords={x:r,y:a},!this.handleIframeLikeCenterClick()){if(this.editorInterface.isTouchScreen){let i=this.getElementAtPosition(n.x,n.y,{includeLockedElements:!0});this.hitLinkElement=this.getElementLinkAtPosition(n,i)}this.hitLinkElement&&!this.state.selectedElementIds[this.hitLinkElement.id]?this.handleElementLinkClick(o):this.state.viewModeEnabled&&this.setState({activeEmbeddable:null,selectedElementIds:{}})}});A(this,"maybeOpenContextMenuAfterPointerDownOnTouchDevices",o=>{o.pointerType==="touch"&&(Yd=!1,Na?Yd=!0:Na=window.setTimeout(()=>{Na=0,Yd||this.handleCanvasContextMenu(o)},Vj))});A(this,"resetContextMenuTimer",()=>{clearTimeout(Na),Na=0,Yd=!1});A(this,"maybeCleanupAfterMissingPointerUp",o=>{$d?.(),this.missingPointerEventCleanupEmitter.trigger(o).clear()});A(this,"handleCanvasPanUsingWheelOrSpaceDrag",o=>{if(!(Ne.pointers.size<=1&&(o.button===Aa.WHEEL||o.button===Aa.MAIN&&Ra||pr(this.state)||this.state.viewModeEnabled&&this.state.activeTool.type!=="laser")))return!1;Ud=!0,this.focusContainer(),this.state.editingTextElement||o.preventDefault();let n=!1,r=typeof window===void 0?!1:/Linux/.test(window.navigator.platform);Be(this.interactiveCanvas,lt.GRABBING);let{clientX:a,clientY:i}=o,s=Fu(c=>{let m=a-c.clientX,p=i-c.clientY;if(a=c.clientX,i=c.clientY,r&&!n&&(Math.abs(m)>1||Math.abs(p)>1)){n=!0;let d=h=>{document.body.removeEventListener(he.PASTE,d),h.stopPropagation()},u=()=>{setTimeout(()=>{document.body.removeEventListener(he.PASTE,d),window.removeEventListener(he.POINTER_UP,u)},100)};document.body.addEventListener(he.PASTE,d),window.addEventListener(he.POINTER_UP,u)}this.translateCanvas({scrollX:this.state.scrollX-m/this.state.zoom.value,scrollY:this.state.scrollY-p/this.state.zoom.value})}),l=pt($d=()=>{$d=null,Ud=!1,Ra||(this.state.viewModeEnabled&&this.state.activeTool.type!=="laser"?Be(this.interactiveCanvas,lt.GRAB):Ao(this.interactiveCanvas,this.state)),this.setState({cursorButton:"up"}),this.savePointer(o.clientX,o.clientY,"up"),window.removeEventListener(he.POINTER_MOVE,s),window.removeEventListener(he.POINTER_UP,l),window.removeEventListener(he.BLUR,l),s.flush()});return window.addEventListener(he.BLUR,l),window.addEventListener(he.POINTER_MOVE,s,{passive:!0}),window.addEventListener(he.POINTER_UP,l),!0});A(this,"clearSelectionIfNotUsingSelection",()=>{Fg(this.state.activeTool.type)||this.setState({selectedElementIds:ze({},this.state),selectedGroupIds:{},editingGroupId:null,activeEmbeddable:null})});A(this,"handleSelectionOnPointerDown",(o,n)=>{if(Fg(this.state.activeTool.type)){let r=this.scene.getNonDeletedElements(),a=this.scene.getNonDeletedElementsMap(),i=this.scene.getSelectedElements(this.state);if(i.length===1&&!this.state.selectedLinearElement?.isEditing&&!To(i[0])&&!(mo(i[0])&&(this.editorInterface.userAgent.isMobileDevice||i[0].points.length===2))&&!(this.state.selectedLinearElement&&this.state.selectedLinearElement.hoverPointIndex!==-1)){let s=v6(r,this.state,n.origin.x,n.origin.y,this.state.zoom,o.pointerType,this.scene.getNonDeletedElementsMap(),this.editorInterface);s!=null&&(s.transformHandleType==="rotation"?(this.setState({resizingElement:s.element}),n.resize.handleType=s.transformHandleType):(this.state.croppingElementId||this.setState({resizingElement:s.element}),n.resize.handleType=s.transformHandleType))}else i.length>1&&(n.resize.handleType=I6(Fl(i),n.origin.x,n.origin.y,this.state.zoom,o.pointerType,this.editorInterface));if(n.resize.handleType)n.resize.isResizing=!0,n.resize.offset=H1(gJ(n.resize.handleType,i,a,n.origin.x,n.origin.y)),i.length===1&&mo(i[0])&&i[0].points.length===2&&(n.resize.arrowDirection=hJ(n.resize.handleType,i[0]));else{if(this.state.selectedLinearElement){let d=this.state.selectedLinearElement,u=_e.handlePointerDown(o,this,this.store,n.origin,d,this.scene);if(u.hitElement&&(n.hit.element=u.hitElement),u.linearElementEditor&&this.setState({selectedLinearElement:u.linearElementEditor}),u.didAddPoint)return!0;let h=this.scene.getNonDeletedElementsMap(),g=_e.getElement(d.elementId,h);if(g&&lr(g)){let{hitFocusPoint:x,pointerOffset:E}=kJ(g,n,h,this.state);if(x)return this.setState({selectedLinearElement:{...d,hoveredFocusPointBinding:x,draggedFocusPointBinding:x,pointerOffset:E}}),!1}}let s=this.getElementsAtPosition(n.origin.x,n.origin.y,{includeLockedElements:!0}),l=s.filter(d=>!d.locked),c=this.getElementAtPosition(n.origin.x,n.origin.y,{allHitElements:s});if((!c||c.id!==this.state.activeLockedId)&&this.setState({activeLockedId:null}),c&&c.locked&&!l.some(d=>this.state.selectedElementIds[d.id])?n.hit.element=null:n.hit.element=n.hit.element??this.getElementAtPosition(n.origin.x,n.origin.y),this.hitLinkElement=this.getElementLinkAtPosition(n.origin,c),this.hitLinkElement)return!0;if(this.state.croppingElementId&&n.hit.element?.id!==this.state.croppingElementId&&this.finishImageCropping(),n.hit.element&&this.getElementLinkAtPosition({x:n.origin.x,y:n.origin.y},n.hit.element))return!1;n.hit.allHitElements=l;let m=n.hit.element,p=n.hit.allHitElements.some(d=>this.isASelectedElement(d));if((m===null||!p)&&!o.shiftKey&&!n.hit.hasHitCommonBoundingBoxOfSelectedElements&&(!this.state.selectedLinearElement?.isEditing||m&&m?.id!==this.state.selectedLinearElement?.elementId)&&this.clearSelection(m),this.state.selectedLinearElement?.isEditing)this.setState(d=>({selectedLinearElement:d.selectedLinearElement?{...d.selectedLinearElement,isEditing:!!m&&m.id===this.state.selectedLinearElement?.elementId}:null,selectedElementIds:d.selectedLinearElement?ze({[d.selectedLinearElement.elementId]:!0},this.state):ze({},d)}));else if(m!=null){if(o[ne.CTRL_OR_CMD])return o.altKey?(this.state.openDialog?.name==="elementLinkSelector"&&this.setOpenDialog(null),this.lassoTrail.startPath(n.origin.x,n.origin.y,o.shiftKey),this.setActiveTool({type:"lasso",fromSelection:!0}),!1):(this.state.selectedElementIds[m.id]||(n.hit.wasAddedToSelection=!0),this.setState(d=>({...lJ(d,m),previousSelectedElementIds:this.state.selectedElementIds})),!1);this.state.selectedElementIds[m.id]||(this.state.editingGroupId&&!y6(m,this.state.editingGroupId)&&this.setState({selectedElementIds:ze({},this.state),selectedGroupIds:{},editingGroupId:null,activeEmbeddable:null}),!p&&!n.hit.hasHitCommonBoundingBoxOfSelectedElements&&(this.setState(d=>{let u={...d.selectedElementIds,[m.id]:!0},h=[];if(Object.keys(d.selectedElementIds).forEach(g=>{let x=this.scene.getElement(g);x&&h.push(x)}),Qt(m))Q1(h,m.id).forEach(g=>{delete u[g.id]});else if(m.frameId)u[m.frameId]&&delete u[m.id];else{let g=m.groupIds,x=new Set(g.flatMap(E=>Li(this.scene.getNonDeletedElements(),E)).filter(E=>Qt(E)).map(E=>E.id));x.size>0&&h.forEach(E=>{E.frameId&&x.has(E.frameId)&&(delete u[E.id],E.groupIds.flatMap(y=>Li(this.scene.getNonDeletedElements(),y)).forEach(y=>{delete u[y.id]}))})}return d.openDialog?.name==="elementLinkSelector"&&(m.groupIds.some(g=>d.selectedGroupIds[g])||(u={[m.id]:!0})),{...cn({editingGroupId:d.editingGroupId,selectedElementIds:u},this.scene.getNonDeletedElements(),d,this),showHyperlinkPopup:m.link||Nr(m)?"info":!1}}),n.hit.wasAddedToSelection=!0))}this.setState({previousSelectedElementIds:this.state.selectedElementIds})}}return!1});A(this,"handleTextOnPointerDown",(o,n)=>{if(this.state.editingTextElement)return;let r=n.origin.x,a=n.origin.y,i=this.getElementAtPosition(r,a,{includeBoundTextElement:!0}),s=this.getTextBindableContainerAtPosition(r,a);i6(i)&&(s=i,r=i.x+i.width/2,a=i.y+i.height/2),this.startTextEditing({sceneX:r,sceneY:a,insertAtParentCenter:!o.altKey,container:s,autoEdit:!1}),Po(this.interactiveCanvas),this.state.activeTool.locked||this.setState({activeTool:ir(this.state,{type:this.state.preferredSelectionTool.type})})});A(this,"handleFreeDrawElementOnPointerDown",(o,n,r)=>{let[a,i]=Jt(r.origin.x,r.origin.y,null),s=this.getTopLayerFrameAtSceneCoords({x:a,y:i}),l=o.pressure===.5,c=vq({type:n,x:a,y:i,strokeColor:this.state.currentItemStrokeColor,backgroundColor:this.state.currentItemBackgroundColor,fillStyle:this.state.currentItemFillStyle,strokeWidth:this.state.currentItemStrokeWidth,strokeStyle:this.state.currentItemStrokeStyle,roughness:this.state.currentItemRoughness,opacity:this.state.currentItemOpacity,roundness:null,simulatePressure:l,locked:!1,frameId:s?s.id:null,points:[pe(0,0)],pressures:l?[]:[o.pressure]});this.scene.insertElement(c),this.setState(p=>{let d={...p.selectedElementIds};return delete d[c.id],{selectedElementIds:ze(d,p)}});let m=Cn(pe(r.origin.x,r.origin.y),this.scene.getNonDeletedElements(),this.scene.getNonDeletedElementsMap());this.setState({newElement:c,startBoundElement:m,suggestedBinding:null})});A(this,"insertIframeElement",({sceneX:o,sceneY:n,width:r,height:a})=>{let[i,s]=Jt(o,n,this.lastPointerDownEvent?.[ne.CTRL_OR_CMD]?null:this.getEffectiveGridSize()),l=Iq({type:"iframe",x:i,y:s,strokeColor:"transparent",backgroundColor:"transparent",fillStyle:this.state.currentItemFillStyle,strokeWidth:this.state.currentItemStrokeWidth,strokeStyle:this.state.currentItemStrokeStyle,roughness:this.state.currentItemRoughness,roundness:this.getCurrentItemRoundness("iframe"),opacity:this.state.currentItemOpacity,locked:!1,width:r,height:a});return this.scene.insertElement(l),l});A(this,"insertEmbeddableElement",({sceneX:o,sceneY:n,link:r})=>{let[a,i]=Jt(o,n,this.lastPointerDownEvent?.[ne.CTRL_OR_CMD]?null:this.getEffectiveGridSize()),s=Hg(r);if(!s)return;s.error instanceof URIError&&this.setToast({message:f("toast.unrecognizedLinkFormat"),closable:!0});let l=o6({type:"embeddable",x:a,y:i,strokeColor:"transparent",backgroundColor:"transparent",fillStyle:this.state.currentItemFillStyle,strokeWidth:this.state.currentItemStrokeWidth,strokeStyle:this.state.currentItemStrokeStyle,roughness:this.state.currentItemRoughness,roundness:this.getCurrentItemRoundness("embeddable"),opacity:this.state.currentItemOpacity,locked:!1,width:s.intrinsicSize.w,height:s.intrinsicSize.h,link:r});return this.scene.insertElement(l),l});A(this,"newImagePlaceholder",({sceneX:o,sceneY:n,addToFrameUnderCursor:r=!0})=>{let[a,i]=Jt(o,n,this.lastPointerDownEvent?.[ne.CTRL_OR_CMD]?null:this.getEffectiveGridSize()),s=r?this.getTopLayerFrameAtSceneCoords({x:a,y:i}):null,l=100/this.state.zoom.value;return W1({type:"image",strokeColor:this.state.currentItemStrokeColor,backgroundColor:this.state.currentItemBackgroundColor,fillStyle:this.state.currentItemFillStyle,strokeWidth:this.state.currentItemStrokeWidth,strokeStyle:this.state.currentItemStrokeStyle,roughness:this.state.currentItemRoughness,roundness:null,opacity:this.state.currentItemOpacity,locked:!1,frameId:s?s.id:null,x:a-l/2,y:i-l/2,width:l,height:l})});A(this,"handleLinearElementOnPointerDown",(o,n,r)=>{if(o.ctrlKey&&Io(()=>{this.setState({isBindingEnabled:!1})}),this.state.multiElement){let{multiElement:a,selectedLinearElement:i}=this.state;if(sr(i,"selectedLinearElement is expected to be set"),a.type==="line"&&d6(a.points,this.state.zoom.value)){Io(()=>{this.setState({selectedLinearElement:{...i,lastCommittedPoint:a.points[a.points.length-1],initialState:{...i.initialState,lastClickedPoint:-1}}})}),this.actionManager.executeAction(ro);return}if(To(a)&&a.points.length>1){this.actionManager.executeAction(ro,"ui",{event:o.nativeEvent,sceneCoords:{x:r.origin.x,y:r.origin.y}});return}let{x:s,y:l}=a,{lastCommittedPoint:c}=i,m=Bd(this.state)&&Cn(pe(this.lastPointerMoveCoords?.x??s+a.points[a.points.length-1][0],this.lastPointerMoveCoords?.y??l+a.points[a.points.length-1][1]),this.scene.getNonDeletedElements(),this.scene.getNonDeletedElementsMap());if(lr(a)&&m||a.points.length>1&&c&&Pa(pe(r.origin.x-s,r.origin.y-l),c)<F1){this.actionManager.executeAction(ro,"ui",{event:o.nativeEvent,sceneCoords:{x:r.origin.x,y:r.origin.y}});return}this.setState(p=>({selectedElementIds:ze({...p.selectedElementIds,[a.id]:!0},p)})),Be(this.interactiveCanvas,lt.POINTER)}else{let[a,i]=Jt(r.origin.x,r.origin.y,o[ne.CTRL_OR_CMD]?null:this.getEffectiveGridSize()),s=this.getTopLayerFrameAtSceneCoords({x:a,y:i}),{currentItemStartArrowhead:l,currentItemEndArrowhead:c}=this.state,[m,p]=n==="arrow"?[l,c]:[null,null],d=n==="arrow"?Tq({type:n,x:a,y:i,strokeColor:this.state.currentItemStrokeColor,backgroundColor:this.state.currentItemBackgroundColor,fillStyle:this.state.currentItemFillStyle,strokeWidth:this.state.currentItemStrokeWidth,strokeStyle:this.state.currentItemStrokeStyle,roughness:this.state.currentItemRoughness,opacity:this.state.currentItemOpacity,roundness:this.state.currentItemArrowType===La.round?{type:_g.PROPORTIONAL_RADIUS}:null,startArrowhead:m,endArrowhead:p,locked:!1,frameId:s?s.id:null,elbowed:this.state.currentItemArrowType===La.elbow,fixedSegments:this.state.currentItemArrowType===La.elbow?[]:null}):kq({type:n,x:a,y:i,strokeColor:this.state.currentItemStrokeColor,backgroundColor:this.state.currentItemBackgroundColor,fillStyle:this.state.currentItemFillStyle,strokeWidth:this.state.currentItemStrokeWidth,strokeStyle:this.state.currentItemStrokeStyle,roughness:this.state.currentItemRoughness,opacity:this.state.currentItemOpacity,roundness:this.state.currentItemRoundness==="round"?{type:_g.PROPORTIONAL_RADIUS}:null,locked:!1,frameId:s?s.id:null}),u=pe(r.origin.x,r.origin.y),h=this.scene.getNonDeletedElementsMap(),g=Bd(this.state)?Cn(u,this.scene.getNonDeletedElements(),h):null;this.scene.mutateElement(d,{points:[pe(0,0),pe(0,0)]}),this.scene.insertElement(d),lr(d)&&wJ(d,new Map([[0,{point:pe(0,0),isDragging:!1}]]),u[0],u[1],this.scene,this.state,{newArrow:!0,altKey:o.altKey,initialBinding:!0,angleLocked:UP(o.nativeEvent)}),Io(()=>{this.setState(x=>{let E=null,y=x.selectedElementIds;if(mo(d)){E=new _e(d,this.scene.getNonDeletedElementsMap());let w=d.points.length-1;E={...E,selectedPointsIndices:[w],initialState:{...E.initialState,arrowStartIsInside:o.altKey,lastClickedPoint:w,origin:pe(r.origin.x,r.origin.y)}}}return y=this.state.activeTool.locked?x.selectedElementIds:ze({[d.id]:!0},x),{...x,bindMode:"orbit",newElement:d,startBoundElement:g,suggestedBinding:g&&lr(d)?{element:g,midPoint:sy(u,g,h,this.state.zoom)}:null,selectedElementIds:y,selectedLinearElement:E}})}),lr(d)&&Rr("COMPLEX_BINDINGS")&&this.handleDelayedBindModeChange(d,g)}});A(this,"createGenericElementOnPointerDown",(o,n)=>{let[r,a]=Jt(n.origin.x,n.origin.y,this.lastPointerDownEvent?.[ne.CTRL_OR_CMD]?null:this.getEffectiveGridSize()),i=this.getTopLayerFrameAtSceneCoords({x:r,y:a}),s={x:r,y:a,strokeColor:this.state.currentItemStrokeColor,backgroundColor:this.state.currentItemBackgroundColor,fillStyle:this.state.currentItemFillStyle,strokeWidth:this.state.currentItemStrokeWidth,strokeStyle:this.state.currentItemStrokeStyle,roughness:this.state.currentItemRoughness,opacity:this.state.currentItemOpacity,roundness:this.getCurrentItemRoundness(o),locked:!1,frameId:i?i.id:null},l;o==="embeddable"?l=o6({type:"embeddable",...s}):l=Cq({type:o,...s}),l.type==="selection"?this.setState({selectionElement:l}):(this.scene.insertElement(l),this.setState({multiElement:null,newElement:l}))});A(this,"createFrameElementOnPointerDown",(o,n)=>{let[r,a]=Jt(o.origin.x,o.origin.y,this.lastPointerDownEvent?.[ne.CTRL_OR_CMD]?null:this.getEffectiveGridSize()),i={x:r,y:a,opacity:this.state.currentItemOpacity,locked:!1,...ln},s=n===ar.magicframe?n6(i):t6(i);this.scene.insertElement(s),this.setState({multiElement:null,newElement:s})});A(this,"restoreReadyToEraseElements",()=>{this.elementsPendingErasure=new Set,this.triggerRender()});A(this,"eraseElements",()=>{let o=!1;this.elementsPendingErasure.forEach(r=>{let a=this.scene.getElement(r);if(lr(a)){if(a.startBinding){let i=this.scene.getElement(a.startBinding.elementId);Gg(i,this.scene.getElementsMapIncludingDeleted(),{boundElements:i.boundElements.filter(s=>s.id!==a.id)})}if(a.endBinding){let i=this.scene.getElement(a.endBinding.elementId);Gg(i,this.scene.getElementsMapIncludingDeleted(),{boundElements:i.boundElements.filter(s=>s.id!==a.id)})}}else X1(a)&&a.boundElements?.forEach(i=>{if(i.type==="arrow"){let s=this.scene.getElement(i.id);s?.startBinding?.elementId===a.id&&Gg(s,this.scene.getElementsMapIncludingDeleted(),{startBinding:null}),s?.endBinding?.elementId===a.id&&Gg(s,this.scene.getElementsMapIncludingDeleted(),{endBinding:null})}})});let n=this.scene.getElementsIncludingDeleted().map(r=>this.elementsPendingErasure.has(r.id)||r.frameId&&this.elementsPendingErasure.has(r.frameId)||$1(r)&&this.elementsPendingErasure.has(r.containerId)?(o=!0,_a(r,{isDeleted:!0})):r);this.elementsPendingErasure=new Set,o&&(this.store.scheduleCapture(),this.scene.replaceAllElements(n))});A(this,"initializeImage",async(o,n)=>{if(!dh(n))throw new Error(f("errors.unsupportedFileType"));let r=n.type;if(Be(this.interactiveCanvas,"wait"),r===rr.svg)try{n=gh(p6(await n.text()),n.name)}catch(l){throw console.warn(l),new Error(f("errors.svgImageInsertError"))}let a=await(this.props.generateIdForFile?.(n)||bE(n));if(!a)throw console.warn("Couldn't generate file id or the supplied `generateIdForFile` didn't resolve to one."),new Error(f("errors.imageInsertError"));if(!this.files[a]?.dataURL){try{n=await cm(n,{maxWidthOrHeight:Oj})}catch(l){console.error("Error trying to resizing image file on insertion",l)}if(n.size>VP)throw new Error(f("errors.fileTooBig",{maxSize:`${Math.trunc(VP/1024/1024)}MB`}))}let s=this.files[a]?.dataURL||await Vi(n);return new Promise(async(l,c)=>{try{let m=this.getLatestInitializedImageElement(o,a);if(this.addMissingFiles([{mimeType:r,id:a,dataURL:s,created:Date.now(),lastRetrieved:Date.now()}]),!this.imageCache.get(a)){this.addNewImagesToImageCache();let{erroredFiles:d}=await this.updateImageCache([m]);if(d.size)throw new Error("Image cache update resulted with an error.")}let p=await this.imageCache.get(a)?.image;if(p&&this.state.newElement?.id!==m.id){m=this.getLatestInitializedImageElement(o,a);let d=this.getImageNaturalDimensions(m,p);Object.assign(m,d)}l(m)}catch(m){console.error(m),c(new Error(f("errors.imageInsertError")))}})});A(this,"getLatestInitializedImageElement",(o,n)=>{let r=this.scene.getElement(o.id)??o;return _a(r,{fileId:n})});A(this,"onImageToolbarButtonClick",async()=>{try{let o=this.state.width/2+this.state.offsetLeft,n=this.state.height/2+this.state.offsetTop,{x:r,y:a}=rt({clientX:o,clientY:n},this.state),i=await om({description:"Image",extensions:Object.keys(Hj),multiple:!0});this.insertImages(i,r,a)}catch(o){o.name!=="AbortError"?console.error(o):console.warn(o),this.setState({newElement:null,activeTool:ir(this.state,{type:this.state.preferredSelectionTool.type})},()=>{this.actionManager.executeAction(ro)})}});A(this,"getImageNaturalDimensions",(o,n)=>{let r=Math.max(this.state.height-120,160),a=Math.min(r,Math.floor(this.state.height*.5)/this.state.zoom.value),i=Math.min(n.naturalHeight,a),s=i*(n.naturalWidth/n.naturalHeight),l=o.x+o.width/2-s/2,c=o.y+o.height/2-i/2;return{x:l,y:c,width:s,height:i,crop:null}});A(this,"updateImageCache",async(o,n=this.files)=>{let{updatedFiles:r,erroredFiles:a}=await Bq({imageCache:this.imageCache,fileIds:o.map(i=>i.fileId),files:n});return a.size&&(this.store.scheduleAction(po.NEVER),this.scene.replaceAllElements(this.scene.getElementsIncludingDeleted().map(i=>Fd(i)&&a.has(i.fileId)?_a(i,{status:"error"}):i))),{updatedFiles:r,erroredFiles:a}});A(this,"addNewImagesToImageCache",async(o=Nq(this.scene.getNonDeletedElements()),n=this.files)=>{let r=o.filter(a=>!a.isDeleted&&!this.imageCache.has(a.fileId));if(r.length){let{updatedFiles:a}=await this.updateImageCache(r,n);if(a.size)for(let i of r)a.has(i.fileId)&&zd.delete(i);a.size&&this.scene.triggerUpdate()}});A(this,"scheduleImageRefresh",Rj(()=>{this.addNewImagesToImageCache()},Gj));A(this,"updateBindingEnabledOnPointerMove",o=>{let n=wq(o);this.state.isBindingEnabled!==n&&this.setState({isBindingEnabled:n})});A(this,"handleInteractiveCanvasRef",o=>{o!==null?(this.interactiveCanvas=o,this.interactiveCanvas.addEventListener(he.TOUCH_START,this.onTouchStart,{passive:!1}),this.interactiveCanvas.addEventListener(he.TOUCH_END,this.onTouchEnd)):(this.interactiveCanvas?.removeEventListener(he.TOUCH_START,this.onTouchStart),this.interactiveCanvas?.removeEventListener(he.TOUCH_END,this.onTouchEnd))});A(this,"insertImages",async(o,n,r)=>{let a=50/this.state.zoom.value,i=M6(o.map(()=>this.newImagePlaceholder({sceneX:n,sceneY:r})),n,r,a);i.forEach(d=>this.scene.insertElement(d));let s=await Promise.all(i.map(async(d,u)=>{try{return await this.initializeImage(d,await ec(o[u]))}catch(h){return this.setState({errorMessage:h.message||f("errors.imageInsertError")}),_a(d,{isDeleted:!0})}})),l=Bg(s),c=M6(s.filter(d=>!d.isDeleted),n,r,a),m=Bg(c),p=this.scene.getElementsIncludingDeleted().map(d=>m.get(d.id)??l.get(d.id)??d);this.updateScene({appState:{selectedElementIds:ze(Object.fromEntries(c.map(d=>[d.id,!0])),this.state)},elements:p,captureUpdate:po.IMMEDIATELY}),this.setState({},()=>{this.actionManager.executeAction(ro)})});A(this,"handleAppOnDrop",async o=>{let{x:n,y:r}=rt(o,this.state),a=await As(o),i=a.getFiles();if(i.length===1){let{file:p,fileHandle:d}=i[0];if(p&&(p.type===rr.png||p.type===rr.svg))try{let u=await lm(p,this.state,this.scene.getElementsIncludingDeleted(),d);this.syncActionResult({...u,appState:{...u.appState||this.state,isLoading:!1},replaceFiles:!0,captureUpdate:po.IMMEDIATELY});return}catch(u){if(u.name!=="EncodingError")throw new Error(f("alerts.couldNotLoadInvalidFile"))}}let s=i.map(p=>p.file).filter(p=>dh(p));if(s.length>0&&this.isToolSupported("image"))return this.insertImages(s,n,r);let l=a.getData(rr.excalidrawlibIds),c=a.getData(rr.excalidrawlib);if(l||c){try{let p=null;if(l){let{itemIds:d}=JSON.parse(l);p=(await this.library.getLatestLibrary()).filter(h=>d.includes(h.id))}else c&&(p=fE(c));p?.length&&(p=p.map(d=>({...d,elements:Y1({type:"everything",elements:d.elements,randomizeSeed:!0}).duplicatedElements})),this.addElementsFromPasteOrLibrary({elements:Zs(p),position:o,files:null}))}catch(p){this.setState({errorMessage:p.message})}return}if(i.length>0){let{file:p,fileHandle:d}=i[0];p&&await this.loadFileToCanvas(p,d)}let m=a.findByType(rr.text);if(m){let p=m.value;if(p&&j1(p,this.props.validateEmbeddable)&&(/^(http|https):\/\/[^\s/$.?#].[^\s]*$/.test(p)||Hg(p)?.type==="video")){let d=this.insertEmbeddableElement({sceneX:n,sceneY:r,link:O1(p)});d&&(this.store.scheduleCapture(),this.setState({selectedElementIds:{[d.id]:!0}}))}}});A(this,"loadFileToCanvas",async(o,n)=>{o=await ec(o);try{let r=this.scene.getElementsIncludingDeleted(),a;try{a=await mh(o,this.state,r,n)}catch(i){let s=i instanceof aE;if(s&&i.code==="IMAGE_NOT_CONTAINS_SCENE_DATA"&&!this.isToolSupported("image")){this.setState({isLoading:!1,errorMessage:f("errors.imageToolNotSupported")});return}let l=s?f("alerts.cannotRestoreFromImage"):f("alerts.couldNotLoadInvalidFile");this.setState({isLoading:!1,errorMessage:l})}if(!a)return;a.type===rr.excalidraw?(O6(r.concat(a.data.elements)),this.store.scheduleMicroAction({action:po.NEVER,elements:r,appState:void 0}),this.setState({isLoading:!0}),this.syncActionResult({...a.data,appState:{...a.data.appState||this.state,isLoading:!1},replaceFiles:!0,captureUpdate:po.IMMEDIATELY})):a.type===rr.excalidrawlib&&await this.library.updateLibrary({libraryItems:o,merge:!0,openLibraryMenu:!0}).catch(i=>{console.error(i),this.setState({errorMessage:f("errors.importLibraryError")})})}catch(r){this.setState({isLoading:!1,errorMessage:r.message})}});A(this,"handleCanvasContextMenu",o=>{if(o.preventDefault(),("pointerType"in o.nativeEvent&&o.nativeEvent.pointerType==="touch"||"pointerType"in o.nativeEvent&&o.nativeEvent.pointerType==="pen"&&o.button!==Aa.SECONDARY)&&this.state.activeTool.type!==this.state.preferredSelectionTool.type)return;let{x:n,y:r}=rt(o,this.state),a=this.getElementAtPosition(n,r,{preferSelected:!0,includeLockedElements:!0}),i=this.scene.getSelectedElements(this.state),s=this.isHittingCommonBoundingBoxOfSelectedElements({x:n,y:r},i),l=a||s?"element":"canvas",c=this.excalidrawContainerRef.current,{top:m,left:p}=c.getBoundingClientRect(),d=o.clientX-p,u=o.clientY-m;be("contextMenu","openContextMenu",l),this.setState({...a&&!this.state.selectedElementIds[a.id]?{...this.state,...cn({editingGroupId:this.state.editingGroupId,selectedElementIds:{[a.id]:!0}},this.scene.getNonDeletedElements(),this.state,this),selectedLinearElement:mo(a)?new _e(a,this.scene.getNonDeletedElementsMap()):null}:this.state,showHyperlinkPopup:!1},()=>{this.setState({contextMenu:{top:u,left:d,items:this.getContextMenuItems(l)}})})});A(this,"maybeDragNewGenericElement",(o,n,r=!0)=>{let a=this.state.selectionElement,i=o.lastCoords;if(a&&o.boxSelection.hasOccurred&&this.state.activeTool.type!=="eraser"){T6({newElement:a,elementType:this.state.activeTool.type,originX:o.origin.x,originY:o.origin.y,x:i.x,y:i.y,width:Bl(o.origin.x,i.x),height:Bl(o.origin.y,i.y),shouldMaintainAspectRatio:Dd(n),shouldResizeFromCenter:!1,scene:this.scene,zoom:this.state.zoom.value,informMutation:!1});return}let s=this.state.newElement;if(!s)return;let[l,c]=Jt(i.x,i.y,n[ne.CTRL_OR_CMD]?null:this.getEffectiveGridSize()),m=Fd(s)&&this.imageCache.get(s.fileId)?.image,p=m&&!(m instanceof Promise)?m.width/m.height:null;this.maybeCacheReferenceSnapPoints(n,[s]);let{snapOffset:d,snapLines:u}=hk(s,this,n,{x:o.originInGrid.x+(this.state.originSnapOffset?.x??0),y:o.originInGrid.y+(this.state.originSnapOffset?.y??0)},{x:l-o.originInGrid.x,y:c-o.originInGrid.y},this.scene.getNonDeletedElementsMap());l+=d.x,c+=d.y,this.setState({snapLines:u}),lr(s)||T6({newElement:s,elementType:this.state.activeTool.type,originX:o.originInGrid.x,originY:o.originInGrid.y,x:l,y:c,width:Bl(o.originInGrid.x,l),height:Bl(o.originInGrid.y,c),shouldMaintainAspectRatio:Da(s)?!Dd(n):Dd(n),shouldResizeFromCenter:GP(n),zoom:this.state.zoom.value,scene:this.scene,widthAspectRatio:p,originOffset:this.state.originSnapOffset,informMutation:r}),this.setState({newElement:s}),(this.state.activeTool.type===ar.frame||this.state.activeTool.type===ar.magicframe)&&this.setState({elementsToHighlight:ty(this.scene.getNonDeletedElements(),s,this.state,this.scene.getNonDeletedElementsMap())})});A(this,"maybeHandleCrop",(o,n)=>{if(!this.state.croppingElementId)return!1;let r=o.resize.handleType,a=o.lastCoords,[i,s]=Jt(a.x-o.resize.offset.x,a.y-o.resize.offset.y,n[ne.CTRL_OR_CMD]?null:this.getEffectiveGridSize()),l=this.scene.getNonDeletedElementsMap().get(this.state.croppingElementId);if(r&&l&&Da(l)){let c=o.originalElements.get(l.id),m=Fd(l)&&this.imageCache.get(l.fileId)?.image;if(c&&Da(c)&&m&&!(m instanceof Promise)){let[p,d]=Jt(a.x,a.y,n[ne.CTRL_OR_CMD]?null:this.getEffectiveGridSize()),u={x:p-o.originInGrid.x,y:d-o.originInGrid.y};this.maybeCacheReferenceSnapPoints(n,[l]);let{snapOffset:h,snapLines:g}=D0([l],[c],this,n,u,r);this.scene.mutateElement(l,Jq(l,this.scene.getNonDeletedElementsMap(),r,m.naturalWidth,m.naturalHeight,i+h.x,s+h.y,n.shiftKey?c.width/c.height:void 0)),zg(l,this.scene),this.setState({isCropping:r&&r!=="rotation",snapLines:g})}return!0}return!1});A(this,"maybeHandleResize",(o,n)=>{let r=this.scene.getSelectedElements(this.state),a=r.filter(p=>Qt(p)),i=o.resize.handleType;if(a.length>0&&i==="rotation"||r.length===1&&To(r[0])||this.state.croppingElementId)return!1;this.setState({isResizing:i&&i!=="rotation",isRotating:i==="rotation",activeEmbeddable:null});let s=o.lastCoords,[l,c]=Jt(s.x-o.resize.offset.x,s.y-o.resize.offset.y,n[ne.CTRL_OR_CMD]?null:this.getEffectiveGridSize()),m=new Map;if(a.forEach(p=>{Q1(this.scene.getNonDeletedElements(),p.id).forEach(u=>{m.set(p.id+u.id,{x:u.x-p.x,y:u.y-p.y})})}),!this.state.selectedElementsAreBeingDragged){let[p,d]=Jt(s.x,s.y,n[ne.CTRL_OR_CMD]?null:this.getEffectiveGridSize()),u={x:p-o.originInGrid.x,y:d-o.originInGrid.y},h=[...o.originalElements.values()];this.maybeCacheReferenceSnapPoints(n,r);let{snapOffset:g,snapLines:x}=D0(r,de(h,this.state),this,n,u,i);l+=g.x,c+=g.y,this.setState({snapLines:x})}if(fJ(o.originalElements,i,r,this.scene,UP(n),GP(n),r.some(p=>Da(p))?!Dd(n):Dd(n),l,c,o.resize.center.x,o.resize.center.y)){let p=new Set;return a.forEach(d=>{ty(this.scene.getNonDeletedElements(),d,this.state,this.scene.getNonDeletedElementsMap()).forEach(u=>p.add(u))}),this.setState({elementsToHighlight:[...p]}),!0}return!1});A(this,"getContextMenuItems",o=>{let n=[];if(n.push(yp,xp),o==="canvas")return this.state.viewModeEnabled?[...n,zs,ta,ii,oa]:[eb,vt,yp,xp,Ep,vt,Kh,hT,vt,zs,_c,ta,ii,oa];if(n.push(Ep),this.state.viewModeEnabled)return[Os,...n];let r=this.editorInterface.formFactor==="desktop"?[vt,Wh,Yh,$h,Vh]:[];return[vt,bp,Os,eb,vt,V5,K5,X5,vt,ed,vt,...n,vt,Yf,$f,vt,Kf,ok,nb,rb,eT,Xf,vt,qf,...r,vt,Jf,Qf,vt,il,vt,Nc,Mp,vt,Xh,Bc,vt,dc]});A(this,"handleWheel",pt(o=>{if(!(o.target instanceof HTMLCanvasElement||o.target instanceof HTMLTextAreaElement||o.target instanceof HTMLIFrameElement||o.target instanceof HTMLElement&&o.target.classList.contains(U1.FRAME_NAME))){o[ne.CTRL_OR_CMD]&&o.preventDefault();return}if(o.preventDefault(),Ud)return;let{deltaX:n,deltaY:r}=o;if(o.metaKey||o.ctrlKey){let a=Math.sign(r),i=Xj*100,s=Math.abs(r),l=r;s>i&&(l=i*a);let c=this.state.zoom.value-l/100;c+=Math.log10(Math.max(1,this.state.zoom.value))*-a*Math.min(1,s/20),this.translateCanvas(m=>({...br({viewportX:this.lastViewportPosition.x,viewportY:this.lastViewportPosition.y,nextZoom:Ln(c)},m),shouldCacheIgnoreZoom:!0})),this.resetShouldCacheIgnoreZoomDebounced();return}if(o.shiftKey){this.translateCanvas(({zoom:a,scrollX:i})=>({scrollX:i-(r||n)/a.value}));return}this.translateCanvas(({zoom:a,scrollX:i,scrollY:s})=>({scrollX:i-n/a.value,scrollY:s-r/a.value}))}));A(this,"savePointer",(o,n,r)=>{if(!o||!n)return;let{x:a,y:i}=rt({clientX:o,clientY:n},this.state);isNaN(a)||isNaN(i);let s={x:a,y:i,tool:this.state.activeTool.type==="laser"?"laser":"pointer"};this.props.onPointerUpdate?.({pointer:s,button:r,pointersMap:Ne.pointers})});A(this,"resetShouldCacheIgnoreZoomDebounced",ZP(()=>{this.unmounted||this.setState({shouldCacheIgnoreZoom:!1})},300));A(this,"updateDOMRect",o=>{if(this.excalidrawContainerRef?.current){let n=this.excalidrawContainerRef.current,{width:r,height:a,left:i,top:s}=n.getBoundingClientRect(),{width:l,height:c,offsetTop:m,offsetLeft:p}=this.state;if(r===l&&a===c&&i===p&&s===m){o&&o();return}this.setState({width:r,height:a,offsetLeft:i,offsetTop:s},()=>{o&&o()})}});A(this,"refresh",()=>{this.setState({...this.getCanvasOffsets()})});A(this,"watchState",()=>{});let n=Or(),{excalidrawAPI:r,viewModeEnabled:a=!1,zenModeEnabled:i=!1,gridModeEnabled:s=!1,objectsSnapModeEnabled:l=!1,theme:c=n.theme,name:m=`${f("labels.untitled")}-${qP()}`}=o;if(this.state={...n,theme:c,isLoading:!0,...this.getCanvasOffsets(),viewModeEnabled:a,zenModeEnabled:i,objectsSnapModeEnabled:l,gridModeEnabled:s??n.gridModeEnabled,name:m,width:window.innerWidth,height:window.innerHeight},this.refreshEditorInterface(),this.stylesPanelMode=Wg(this.editorInterface),this.id=R1(),this.library=new GT(this),this.actionManager=new mu(this.syncActionResult,()=>this.state,()=>this.scene.getElementsIncludingDeleted(),this),this.scene=new k6,this.canvas=document.createElement("canvas"),this.rc=Nj.canvas(this.canvas),this.renderer=new rd(this.scene),this.visibleElements=[],this.store=new yJ(this),this.history=new td(this.store),r){let p={updateScene:this.updateScene,applyDeltas:this.applyDeltas,mutateElement:this.mutateElement,updateLibrary:this.library.updateLibrary,addFiles:this.addFiles,resetScene:this.resetScene,getSceneElementsIncludingDeleted:this.getSceneElementsIncludingDeleted,getSceneElementsMapIncludingDeleted:this.getSceneElementsMapIncludingDeleted,history:{clear:this.resetHistory},scrollToContent:this.scrollToContent,getSceneElements:this.getSceneElements,getAppState:()=>this.state,getFiles:()=>this.files,getName:this.getName,registerAction:d=>{this.actionManager.registerAction(d)},refresh:this.refresh,setToast:this.setToast,id:this.id,setActiveTool:this.setActiveTool,setCursor:this.setCursor,resetCursor:this.resetCursor,getEditorInterface:()=>this.editorInterface,updateFrameRendering:this.updateFrameRendering,toggleSidebar:this.toggleSidebar,onChange:d=>this.onChangeEmitter.on(d),onIncrement:d=>this.store.onStoreIncrementEmitter.on(d),onPointerDown:d=>this.onPointerDownEmitter.on(d),onPointerUp:d=>this.onPointerUpEmitter.on(d),onScrollChange:d=>this.onScrollChangeEmitter.on(d),onUserFollow:d=>this.onUserFollowEmitter.on(d)};typeof r=="function"?r(p):console.error("excalidrawAPI should be a function!")}this.excalidrawContainerValue={container:this.excalidrawContainerRef.current,id:this.id},this.fonts=new Ho(this.scene),this.history=new td(this.store),this.actionManager.registerAll(km),this.actionManager.registerAction(J5(this.history)),this.actionManager.registerAction(Q5(this.history))}onWindowMessage(o){if(o.origin!=="https://player.vimeo.com"&&o.origin!=="https://www.youtube.com")return;let n=null;try{n=JSON.parse(o.data)}catch{}if(n)switch(o.origin){case"https://player.vimeo.com":if(n.method==="paused"){let r=null,a=document.body.querySelectorAll("iframe.excalidraw__embeddable");if(!a)break;for(let i of a)i.contentWindow===o.source&&(r=i.contentWindow);r?.postMessage(JSON.stringify({method:n.value?"play":"pause",value:!0}),"*")}break;case"https://www.youtube.com":if(n.event==="infoDelivery"&&n.info&&n.id&&typeof n.info.playerState=="number"){let r=n.id,a=n.info.playerState;Object.values(Rg).includes(a)&&dy.set(r,a)}break}}handleSkipBindMode(){if(this.state.selectedLinearElement?.initialState&&!this.state.selectedLinearElement.initialState.arrowStartIsInside){sr(this.lastPointerMoveCoords,"Missing last pointer move coords when changing bind skip mode for arrow start");let o=this.scene.getNonDeletedElementsMap(),n=Cn(pe(this.lastPointerMoveCoords.x,this.lastPointerMoveCoords.y),this.scene.getNonDeletedElements(),o),r=_e.getElement(this.state.selectedLinearElement.elementId,o);r?.startBinding&&n?.id===r.startBinding.elementId&&this.setState({selectedLinearElement:{...this.state.selectedLinearElement,initialState:{...this.state.selectedLinearElement.initialState,arrowStartIsInside:!0}}})}if(this.state.bindMode==="orbit"&&(this.bindModeHandler&&(clearTimeout(this.bindModeHandler),this.bindModeHandler=null),Io(()=>{this.setState({bindMode:"skip"})}),this.lastPointerMoveCoords&&this.state.selectedLinearElement?.selectedPointsIndices&&this.state.selectedLinearElement?.selectedPointsIndices.length)){let{x:o,y:n}=this.lastPointerMoveCoords,r=this.lastPointerMoveEvent??this.lastPointerDownEvent?.nativeEvent;sr(r,"Last event must exist");let a=o-this.state.selectedLinearElement.pointerOffset.x,i=n-this.state.selectedLinearElement.pointerOffset.y,s=this.state.multiElement?_e.handlePointerMove(r,this,a,i,this.state.selectedLinearElement):_e.handlePointDragging(r,this,a,i,this.state.selectedLinearElement);s&&this.setState(s)}}resetDelayedBindMode(){this.bindModeHandler&&(clearTimeout(this.bindModeHandler),this.bindModeHandler=null),this.state.bindMode!=="orbit"&&setTimeout(()=>this.setState({bindMode:"orbit"}))}handleDelayedBindModeChange(o,n){if(o.isDeleted||To(o))return;let r=()=>{if(this.bindModeHandler=null,sr(this.lastPointerMoveCoords,"Expected lastPointerMoveCoords to be set"),!this.state.multiElement){if(!this.state.selectedLinearElement||!this.state.selectedLinearElement.selectedPointsIndices||!this.state.selectedLinearElement.selectedPointsIndices.length)return;let h=this.state.selectedLinearElement.selectedPointsIndices.includes(0),g=this.state.selectedLinearElement.selectedPointsIndices.includes(o.points.length-1);if(!h&&!g||h&&g)return}let{x:p,y:d}=this.lastPointerMoveCoords,u=Cn(pe(p,d),this.scene.getNonDeletedElements(),this.scene.getNonDeletedElementsMap());if(u&&this.state.bindMode!=="skip"){sr(this.state.selectedLinearElement?.elementId===o.id,"The selectedLinearElement is expected to not change while a bind mode timeout is ticking");let h=this.state.selectedLinearElement.initialState.arrowStartIsInside||o.startBinding?.elementId===u.id;Io(()=>{sr(this.state.selectedLinearElement,"this.state.selectedLinearElement must exist"),this.setState({bindMode:"inside",selectedLinearElement:{...this.state.selectedLinearElement,initialState:{...this.state.selectedLinearElement.initialState,arrowStartIsInside:h}}})});let g=this.lastPointerMoveEvent??this.lastPointerDownEvent?.nativeEvent;sr(g,"Last event must exist");let x=p-this.state.selectedLinearElement.pointerOffset.x,E=d-this.state.selectedLinearElement.pointerOffset.y,y=this.state.multiElement?_e.handlePointerMove(g,this,x,E,this.state.selectedLinearElement):_e.handlePointDragging(g,this,x,E,this.state.selectedLinearElement);y&&this.setState(y)}},a=!1;if(this.state.selectedLinearElement?.selectedPointsIndices){let p=this.scene.getNonDeletedElementsMap(),d=this.state.selectedLinearElement.selectedPointsIndices.includes(0),u=this.state.selectedLinearElement.selectedPointsIndices.includes(o.points.length-1),h=d?n:o.startBinding&&p.get(o.startBinding.elementId),g=u?n:o.endBinding&&p.get(o.endBinding.elementId),x=h&&A6(h,p),E=g&&A6(g,p);a=!!(x&&E&&h.id!==g.id&&vJ(x,E))}let i=this.state.selectedLinearElement?.selectedPointsIndices?.includes(0),s=this.state.selectedLinearElement?.selectedPointsIndices?.includes(o.points.length-1),l=i?"startBinding":s?"endBinding":null,c=i?"endBinding":s?"startBinding":null,m=c&&o[c]?.mode==="inside"&&o[c]?.elementId===n?.id||l&&o[l]?.mode==="inside"&&n?.id===o[l]?.elementId;l&&c&&o[l]?.mode==="inside"&&n?.id!==o[l]?.elementId&&o[c]?.elementId!==o[l]?.elementId&&this.scene.mutateElement(o,{[l]:{...o[l],mode:"orbit"}},{informMutation:!1,isDragging:!0}),!n||this.previousHoveredBindableElement&&n.id!==this.previousHoveredBindableElement.id?(this.bindModeHandler&&(clearTimeout(this.bindModeHandler),this.bindModeHandler=null),this.state.bindMode==="inside"&&Io(()=>{this.setState({bindMode:"orbit"})}),this.previousHoveredBindableElement=null):!this.bindModeHandler&&(!this.state.newElement||!o.startBinding||a)&&!m&&(this.bindModeHandler=setTimeout(r,pq)),this.previousHoveredBindableElement=n}cacheEmbeddableRef(o,n){n&&this.iFrameRefs.set(o.id,n)}getHTMLIFrameElement(o){return this.iFrameRefs.get(o.id)}handleIframeLikeCenterClick(){if(!this.lastPointerDownEvent||!this.lastPointerUpEvent||this.lastPointerDownEvent.button!==Aa.MAIN||Ra||!QP(this.state.activeTool.type,["laser","selection","lasso"]))return!1;let o=pe(rt({clientX:this.lastPointerDownEvent.clientX,clientY:this.lastPointerDownEvent.clientY},this.state)),n=pe(rt({clientX:this.lastPointerUpEvent.clientX,clientY:this.lastPointerUpEvent.clientY},this.state));if(Pa(o,n)>YP)return!1;let a=this.getElementAtPosition(o[0],o[1]);if(!(a&&this.lastPointerUpEvent.timeStamp-this.lastPointerDownEvent.timeStamp<=300&&Ne.pointers.size<2&&V1(a)&&(this.state.viewModeEnabled||this.state.activeTool.type==="laser"||this.isIframeLikeElementCenter(a,this.lastPointerUpEvent,n[0],n[1]))))return!1;let s=a;if(this.state.activeEmbeddable?.element===s&&this.state.activeEmbeddable?.state==="active"||(setTimeout(()=>{this.setState({activeEmbeddable:{element:s,state:"active"},selectedElementIds:{[s.id]:!0},newElement:null,selectionElement:null})},100),zl(s)))return!0;let l=this.getHTMLIFrameElement(s);if(!l?.contentWindow)return!0;if(l.src.includes("youtube")){let c=dy.get(s.id);switch(c||(dy.set(s.id,Rg.UNSTARTED),l.contentWindow.postMessage(JSON.stringify({event:"listening",id:s.id}),"*")),c){case Rg.PLAYING:case Rg.BUFFERING:l.contentWindow?.postMessage(JSON.stringify({event:"command",func:"pauseVideo",args:""}),"*");break;default:l.contentWindow?.postMessage(JSON.stringify({event:"command",func:"playVideo",args:""}),"*")}}return l.src.includes("player.vimeo.com")&&l.contentWindow.postMessage(JSON.stringify({method:"paused"}),"*"),!0}isIframeLikeElementCenter(o,n,r,a){return o&&!n.altKey&&!n.shiftKey&&!n.metaKey&&!n.ctrlKey&&(this.state.activeEmbeddable?.element!==o||this.state.activeEmbeddable?.state==="hover"||!this.state.activeEmbeddable)&&r>=o.x+o.width/3&&r<=o.x+2*o.width/3&&a>=o.y+o.height/3&&a<=o.y+2*o.height/3}renderEmbeddables(){let o=this.state.zoom.value,n=this.state.width,r=this.state.height,a=this.scene.getNonDeletedElements().filter(i=>Nr(i)&&this.embedsValidationStatus.get(i.id)===!0||zl(i));return Se(R6,{children:a.map(i=>{let{x:s,y:l}=Ng({sceneX:i.x,sceneY:i.y},this.state),c=l6(i,n,r,this.state,this.scene.getNonDeletedElementsMap()),m=this.initializedEmbeds.has(i.id);if(c&&!m&&this.initializedEmbeds.add(i.id),!(c||m))return null;let d;if(zl(i)){d=null;let g=(i.customData?.generationData??this.magicGenerations.get(i.id))||{status:"error",message:"No generation data",code:"ERR_NO_GENERATION_DATA"};if(g.status==="done"){let x=g.html;d={intrinsicSize:{w:i.width,h:i.height},type:"document",srcdoc:()=>x}}else if(g.status==="pending")d={intrinsicSize:{w:i.width,h:i.height},type:"document",srcdoc:()=>m6(`
|
|
218
|
+
Please fix the Mermaid syntax and regenerate a valid diagram.`;await E({prompt:Q,isRepairFlow:!0})},B=async L=>{let F=m.messages.findIndex($=>$.id===L.id);if(F>0){let $=m.messages[F-1];$.type==="user"&&typeof $.content=="string"&&(g(),await E({prompt:$.content,isRepairFlow:!0}))}},O=()=>{vd({app:a,data:x})},N=L=>{let F=m.messages.findIndex(Q=>Q.id===L&&Q.type==="assistant"),$=m.messages.slice(0,F-1);p({...m,messages:$})},z=L=>{p(F=>({...F,currentPrompt:L}))};return DV("div",{className:`ttd-dialog-layout ${d?"ttd-dialog-layout--split":"ttd-dialog-layout--chat-only"}`,children:[jx(BM,{chatId:m.id,messages:m.messages,currentPrompt:m.currentPrompt,onPromptChange:z,onGenerate:E,isGenerating:h?.isGenerating??!1,generatedResponse:h?.content,isMenuOpen:w,onMenuToggle:P,onMenuClose:S,onNewChat:C,onRestoreChat:v,onDeleteChat:I,savedChats:u,activeSessionId:m.id,onAbort:y,onMermaidTabClick:_,onAiRepairClick:M,onDeleteMessage:N,onInsertMessage:k,onRetry:B,onViewAsMermaid:D,renderWarning:n,renderWelcomeScreen:o}),d&&jx(OM,{canvasRef:s,hideErrorDetails:h?.errorType==="parse",error:l,loaded:e.loaded,onInsert:O})]})},_V=({mermaidToExcalidrawLib:e,onTextSubmit:t,renderWelcomeScreen:o,renderWarning:n,persistenceAdapter:r})=>jx(LV,{mermaidToExcalidrawLib:e,onTextSubmit:t,renderWelcomeScreen:o,renderWarning:n,persistenceAdapter:r}),zM=_V;import{Tabs as RV}from"radix-ui";import{useRef as HM}from"react";import{isMemberOf as NV}from"@orangecatai/common";import{jsx as BV}from"react/jsx-runtime";var GM=e=>{let t=Ce(),o=HM(null),n=HM(0);return BV(RV.Root,{ref:o,className:"ttd-dialog-tabs-root",value:e.tab,onValueChange:r=>{if(!r)return;let a=o.current?.closest(".Modal__content");if(a){let i=a.offsetHeight||0;i>n.current&&(n.current=i,a.style.minHeight=`min(${n.current}px, 100%)`)}e.dialog==="ttd"&&NV(["text-to-diagram","mermaid"],r)&&t({openDialog:{name:e.dialog,tab:r}})},children:e.children})};GM.displayName="TTDDialogTabs";var UM=GM;import{Tabs as FV}from"radix-ui";import{jsx as OV}from"react/jsx-runtime";var qx=({children:e,...t})=>OV(FV.List,{className:"ttd-dialog-triggers",...t,children:e});qx.displayName="TTDDialogTabTriggers";import{Tabs as zV}from"radix-ui";import{jsx as WM}from"react/jsx-runtime";var ug=({children:e,tab:t,onSelect:o,...n})=>WM(zV.Trigger,{value:t,asChild:!0,onSelect:o,children:WM("button",{type:"button",className:"ttd-dialog-tab-trigger",...n,children:e})});ug.displayName="TTDDialogTabTrigger";import{Tabs as HV}from"radix-ui";import{jsx as GV}from"react/jsx-runtime";var gg=({tab:e,children:t,...o})=>GV(HV.Content,{...o,value:e,children:t});gg.displayName="TTDDialogTab";import{jsx as or,jsxs as Jx}from"react/jsx-runtime";var hg=e=>{let t=Ie();return t.openDialog?.name!=="ttd"?null:or(YV,{...e,tab:t.openDialog.tab})};hg.WelcomeMessage=lg;var YV=_r("TTDDialogBase",({tab:e,...t})=>{let o=tt(),[n,r]=WV({loaded:!1,api:import("@excalidraw/mermaid-to-excalidraw")});return UV(()=>{(async()=>{await n.api,r(i=>({...i,loaded:!0}))})()},[n.api]),or(bt,{className:"ttd-dialog",onCloseRequest:()=>{o.setOpenDialog(null)},size:1520,title:!1,...t,autofocus:!1,children:Jx(UM,{dialog:"ttd",tab:e,children:["__fallback"in t&&t.__fallback?or("p",{className:"dialog-mermaid-title",children:f("mermaid.title")}):Jx(qx,{children:[or(ug,{tab:"text-to-diagram",children:Jx("div",{className:"ttd-dialog-tab-trigger__content",children:[f("labels.textToDiagram"),or("div",{className:"ttd-dialog-tab-trigger__badge",children:f("chat.aiBeta")})]})}),or(ug,{tab:"mermaid",children:f("mermaid.label")})]}),!("__fallback"in t)&&or(gg,{className:"ttd-dialog-content",tab:"text-to-diagram",children:or(zM,{mermaidToExcalidrawLib:n,onTextSubmit:t.onTextSubmit,renderWelcomeScreen:t.renderWelcomeScreen,renderWarning:t.renderWarning,persistenceAdapter:t.persistenceAdapter})}),or(gg,{className:"ttd-dialog-content",tab:"mermaid",children:or(wM,{mermaidToExcalidrawLib:n,isActive:e==="mermaid"})})]})})});import{round as A4}from"@orangecatai/math";import rX from"clsx";import aX from"lodash.throttle";import{useEffect as L4,useMemo as p1,useState as iX,memo as sX}from"react";import{STATS_PANELS as Ig}from"@orangecatai/common";import{getCommonBounds as lX}from"@orangecatai/element";import{getUncroppedWidthAndHeight as cX}from"@orangecatai/element";import{isImageElement as u1}from"@orangecatai/element";import{frameAndChildrenSelectedTogether as dX}from"@orangecatai/element";import{elementsAreInSameGroup as mX}from"@orangecatai/element";import{degreesToRadians as qM,radiansToDegrees as t4}from"@orangecatai/math";import{getBoundTextElement as JM}from"@orangecatai/element";import{isArrowElement as QM,isElbowArrow as nK}from"@orangecatai/element";import{updateBindings as e4}from"@orangecatai/element";import qV from"clsx";import{useEffect as ZM,useRef as bg,useState as JV}from"react";import{EVENT as Ml,KEYS as QV,cloneJSON as Qx}from"@orangecatai/common";import{deepCopyElement as eK}from"@orangecatai/element";import{CaptureUpdateAction as jM}from"@orangecatai/element";import{pointFrom as Ia,pointRotateRads as fg}from"@orangecatai/math";import{getBoundTextElement as $V,isBindingElement as VV,unbindBindingElement as YM}from"@orangecatai/element";import{isFrameLikeElement as KM}from"@orangecatai/element";import{getSelectedGroupIds as KV,getElementsInGroup as XV,isInGroup as ZV}from"@orangecatai/element";import{getFrameChildren as jV}from"@orangecatai/element";import{updateBindings as $M}from"@orangecatai/element";import{DRAGGING_THRESHOLD as VM}from"@orangecatai/common";var XM=.01,kd=10,wo=(e,t)=>!(t==="angle"&&KM(e)),st=(e,t)=>{let o=e+t/2;return o-o%t},kl=(e,t,o)=>Object.keys(e).map(n=>({original:(o??t).get(n),latest:t.get(n)})).filter(n=>n.original!==void 0&&n.latest!==void 0);var Mi=(e,t,o,n,r,a,i=!0)=>{if(VV(o)&&(o.startBinding||o.endBinding)){if(Math.abs(e-o.x)<VM&&Math.abs(t-o.y)<VM)return;YM(o,"start",n),YM(o,"end",n)}let s=n.getNonDeletedElementsMap(),l=s.get(o.id);if(!l)return;let[c,m]=[o.x+o.width/2,o.y+o.height/2],[p,d]=fg(Ia(o.x,o.y),Ia(c,m),o.angle),u=e-p,h=t-d,[g,x]=fg(Ia(e,t),Ia(c+u,m+h),-o.angle);n.mutateElement(l,{x:g,y:x},{informMutation:i,isDragging:!1}),$M(l,n,r);let E=$V(o,a);if(E){let y=s.get(E.id);y&&n.mutateElement(y,{x:E.x+u,y:E.y+h},{informMutation:i,isDragging:!1})}if(KM(o)){let y=jV(a,o.id);y.forEach(w=>{let v=s.get(w.id);if(!v)return;let[I,C]=[w.x+w.width/2,w.y+w.height/2],[P,S]=fg(Ia(w.x,w.y),Ia(I,C),w.angle),D=Math.round(P+u),_=Math.round(S+h),[k,M]=fg(Ia(D,_),Ia(I+u,C+h),-w.angle);n.mutateElement(v,{x:k,y:M},{informMutation:i,isDragging:!1}),$M(v,n,r,{simultaneouslyUpdated:y})})}},Sl=(e,t)=>{let n=KV(t).map(r=>XV(e,r).reduce((a,i)=>(a[i.id]=!0,a),{}));return e.filter(r=>!ZV(r)).forEach(r=>{n.push({[r.id]:!0})}),n};import{jsx as e1,jsxs as oK}from"react/jsx-runtime";var tK=({label:e,icon:t,dragInputCallback:o,value:n,elements:r,editable:a=!0,shouldKeepAspectRatio:i,property:s,scene:l,appState:c,sensitivity:m=1,dragFinishedCallback:p})=>{let d=tt(),u=Ce(),h=bg(null),g=bg(null),[x,E]=JV(n.toString()),y=bg(null);y.current||(y.current={originalAppState:Qx(c),originalElements:r,lastUpdatedValue:x,updatePending:!1}),ZM(()=>{let I=n.toString();E(I),y.current.lastUpdatedValue=I},[n]);let w=(I,C,P)=>{if(!y.current.updatePending)return!1;y.current.updatePending=!1;let S=Number(I);if(isNaN(S)){E(n.toString());return}let D=Number(S.toFixed(2)),_=Number(n);(isNaN(_)||Math.abs(D-_)>=XM)&&(y.current.lastUpdatedValue=I,o({accumulatedChange:0,instantChange:0,originalElements:C,originalElementsMap:d.scene.getNonDeletedElementsMap(),shouldKeepAspectRatio:i,shouldChangeByStepSize:!1,scene:l,nextValue:D,property:s,originalAppState:P,setInputValue:k=>E(String(k)),app:d,setAppState:u}),d.syncActionResult({captureUpdate:jM.IMMEDIATELY}))},v=bg({});return v.current.handleInputValue=w,ZM(()=>{let I=h.current,C=v.current;return()=>{let P=I?.value;P&&C.handleInputValue?.(P,y.current.originalElements,y.current.originalAppState),window.removeEventListener(Ml.POINTER_MOVE,C.onPointerMove,!1),window.removeEventListener(Ml.POINTER_UP,C.onPointerUp,!1)}},[a]),a?oK("div",{className:qV("drag-input-container",!a&&"disabled"),"data-testid":e,children:[e1("div",{className:"drag-input-label",ref:g,onPointerDown:I=>{if(h.current&&a){document.body.classList.add("excalidraw-cursor-resize");let C=Number(h.current.value);isNaN(C)&&(C=0);let P=null,S=d.scene.getNonDeletedElements().reduce((N,z)=>(N.set(z.id,eK(z)),N),new Map),D=r.map(N=>S.get(N.id)),_=Qx(c),k=0,M=0,B=N=>{if(P&&S!==null&&D!==null){let z=N.clientX-P.x;z!==0&&(M+=z,Math.abs(M)>=m&&(M=Math.sign(M)*Math.floor(Math.abs(M)/m),k+=M,o({accumulatedChange:k,instantChange:M,originalElements:D,originalElementsMap:S,shouldKeepAspectRatio:i,shouldChangeByStepSize:N.shiftKey,property:s,scene:l,originalAppState:_,setInputValue:L=>E(String(L)),app:d,setAppState:u}),M=0))}P={x:N.clientX,y:N.clientY}},O=()=>{window.removeEventListener(Ml.POINTER_MOVE,B,!1),d.syncActionResult({captureUpdate:jM.IMMEDIATELY}),p?.({app:d,setAppState:u,originalElements:D,originalAppState:_}),P=null,k=0,M=0,D=null,S=null,document.body.classList.remove("excalidraw-cursor-resize"),window.removeEventListener(Ml.POINTER_UP,O,!1)};v.current.onPointerMove=B,v.current.onPointerUp=O,window.addEventListener(Ml.POINTER_MOVE,B,!1),window.addEventListener(Ml.POINTER_UP,O,!1)}},onPointerEnter:()=>{g.current&&(g.current.style.cursor="ew-resize")},children:t?e1(Gn,{icon:t}):e}),e1("input",{className:"drag-input",autoComplete:"off",spellCheck:"false",onKeyDown:I=>{if(a){let C=I.target;C instanceof HTMLInputElement&&I.key===QV.ENTER&&(w(C.value,r,c),d.focusContainer())}},ref:h,value:x,onChange:I=>{y.current.updatePending=!0,E(I.target.value)},onFocus:I=>{I.target.select(),y.current.originalElements=r,y.current.originalAppState=Qx(c)},onBlur:I=>{x?a&&w(I.target.value,y.current.originalElements,y.current.originalAppState):E(n.toString())},disabled:!a})]}):null},zt=tK;import{jsx as sK}from"react/jsx-runtime";var rK=15,aK=({accumulatedChange:e,originalElements:t,shouldChangeByStepSize:o,nextValue:n,scene:r,app:a})=>{let i=r.getNonDeletedElementsMap(),s=t[0];if(s&&!nK(s)){let l=i.get(s.id);if(!l)return;if(n!==void 0){let h=qM(n);r.mutateElement(l,{angle:h}),e4(l,r,a.state);let g=JM(l,i);g&&!QM(l)&&r.mutateElement(g,{angle:h});return}let c=Math.round(t4(s.angle)*100)/100,m=Math.round(e),p=(c+m)%360;o&&(p=st(p,rK)),p=p<0?p+360:p;let d=qM(p);r.mutateElement(l,{angle:d}),e4(l,r,a.state);let u=JM(l,i);u&&!QM(l)&&r.mutateElement(u,{angle:d})}},iK=({element:e,scene:t,appState:o,property:n})=>sK(zt,{label:"A",icon:vm,value:Math.round(t4(e.angle)%360*100)/100,elements:[e],dragInputCallback:aK,editable:wo(e,"angle"),scene:t,appState:o,property:n}),o4=iK;import{jsx as cK}from"react/jsx-runtime";var n4=5,lK=({property:e,scene:t,appState:o,setAppState:n})=>cK(zt,{label:"Grid step",sensitivity:8,elements:[],dragInputCallback:({nextValue:r,instantChange:a,shouldChangeByStepSize:i,setInputValue:s})=>{n(l=>{let c;return r?c=r:a&&(c=i?st(l.gridStep+n4*Math.sign(a),n4):l.gridStep+a),c?(c=nE(c),s(c),{gridStep:c}):(s(l.gridStep),null)})},scene:t,value:o.gridStep,property:e,appState:o}),r4=lK;import{clamp as xg,round as t1}from"@orangecatai/math";import{MIN_WIDTH_OR_HEIGHT as yg}from"@orangecatai/common";import{MINIMAL_CROP_SIZE as a4,getUncroppedWidthAndHeight as l4}from"@orangecatai/element";import{resizeSingleElement as i4}from"@orangecatai/element";import{isImageElement as c4}from"@orangecatai/element";import{isFrameLikeElement as o1}from"@orangecatai/element";import{getElementsInResizingFrame as n1}from"@orangecatai/element";import{replaceAllElementsInFrame as d4}from"@orangecatai/element";import{jsx as gK}from"react/jsx-runtime";var s4=10,dK=e=>e.type==="image",mK=({accumulatedChange:e,originalElements:t,originalElementsMap:o,shouldKeepAspectRatio:n,shouldChangeByStepSize:r,nextValue:a,property:i,originalAppState:s,instantChange:l,scene:c,app:m,setAppState:p})=>{let d=c.getNonDeletedElementsMap(),u=t[0],h=d.get(u.id);if(u&&h){let g=n||dK(u),x=u.width/u.height;if(s.croppingElementId===u.id){let E=d.get(u.id);if(!E||!c4(E)||!E.crop)return;let y=E.crop,w={...y},v=E.scale[0]===-1,I=E.scale[1]===-1,{width:C,height:P}=l4(E),S=y.naturalWidth/C,D=y.naturalHeight/P,_=v?y.width+y.x:y.naturalWidth-y.x,k=I?y.height+y.y:y.naturalHeight-y.y,M=a4*S,B=a4*D;if(a!==void 0){if(i==="width"){let F=a*S,$=xg(F,M,_);w={...w,width:$,x:v?y.x+y.width-$:y.x}}else if(i==="height"){let F=a*D,$=xg(F,B,k);w={...w,height:$,y:I?y.y+y.height-$:y.y}}c.mutateElement(E,{crop:w,width:w.width/(y.naturalWidth/C),height:w.height/(y.naturalHeight/P)});return}let O=i==="width"?l:0,N=i==="height"?l:0,z=xg(y.width+O,M,_),L=xg(y.height+N,M,k);w={...y,x:v?y.x+y.width-z:y.x,y:I?y.y+y.height-L:y.y,width:z,height:L},c.mutateElement(E,{crop:w,width:w.width/(y.naturalWidth/C),height:w.height/(y.naturalHeight/P)});return}if(a!==void 0){let E=Math.max(i==="width"?a:g?a*x:u.width,yg),y=Math.max(i==="height"?a:g?a/x:u.height,yg);if(i4(E,y,h,u,o,c,i==="width"?"e":"s",{shouldMaintainAspectRatio:g}),o1(h)){let w=n1(c.getElementsIncludingDeleted(),h,s,c.getNonDeletedElementsMap()),v=d4(c.getElementsIncludingDeleted(),w,h,m);c.replaceAllElements(v)}return}{let E=i==="width"?e:0,y=i==="height"?e:0,w=Math.max(0,u.width+E);i==="width"&&(r?w=st(w,s4):w=Math.round(w));let v=Math.max(0,u.height+y);if(i==="height"&&(r?v=st(v,s4):v=Math.round(v)),g&&(i==="width"?v=Math.round(w/x*100)/100:w=Math.round(v*x*100)/100),v=Math.max(yg,v),w=Math.max(yg,w),i4(w,v,h,u,o,c,i==="width"?"e":"s",{shouldMaintainAspectRatio:g}),o1(h)){let I=n1(c.getElementsIncludingDeleted(),h,s,c.getNonDeletedElementsMap());p({elementsToHighlight:I})}}}},pK=({setAppState:e,app:t,originalElements:o,originalAppState:n})=>{let r=t.scene.getNonDeletedElementsMap(),a=o?.[0],i=a&&r.get(a.id);if(i&&o1(i)){let s=n1(t.scene.getElementsIncludingDeleted(),i,n,t.scene.getNonDeletedElementsMap()),l=d4(t.scene.getElementsIncludingDeleted(),s,i,t);t.scene.replaceAllElements(l),e({elementsToHighlight:null})}},uK=({property:e,element:t,scene:o,appState:n})=>{let r=t1(e==="width"?t.width:t.height,2);if(n.croppingElementId&&n.croppingElementId===t.id&&c4(t)&&t.crop){let{width:a,height:i}=l4(t);if(e==="width"){let s=a/t.crop.naturalWidth;r=t1(t.crop.width*s,2)}if(e==="height"){let s=i/t.crop.naturalHeight;r=t1(t.crop.height*s,2)}}return gK(zt,{label:e==="width"?"W":"H",elements:[t],dragInputCallback:mK,value:r,editable:wo(t,e),scene:o,appState:n,property:e,dragFinishedCallback:pK})},r1=uK;import{getBoundTextElement as hK,redrawTextBoundingBox as fK}from"@orangecatai/element";import{hasBoundTextElement as bK,isTextElement as p4}from"@orangecatai/element";import{jsx as wK}from"react/jsx-runtime";var m4=4,xK=4,yK=({accumulatedChange:e,originalElements:t,shouldChangeByStepSize:o,nextValue:n,scene:r})=>{let a=r.getNonDeletedElementsMap(),i=t[0];if(i){let s=a.get(i.id);if(!s||!p4(s))return;let l;if(n!==void 0)l=Math.max(Math.round(n),m4);else if(i.type==="text"){let c=Math.round(i.fontSize),m=Math.round(e);l=Math.max(c+m,m4),o&&(l=st(l,xK))}l&&(r.mutateElement(s,{fontSize:l}),fK(s,r.getContainerElement(s),r))}},EK=({element:e,scene:t,appState:o,property:n})=>{let r=p4(e)?e:bK(e)?hK(e,t.getNonDeletedElementsMap()):null;return r?wK(zt,{label:"F",value:Math.round(r.fontSize*10)/10,elements:[r],dragInputCallback:yK,icon:Va,appState:o,scene:t,property:n}):null},u4=EK;import{degreesToRadians as g4,radiansToDegrees as b4}from"@orangecatai/math";import{getBoundTextElement as h4}from"@orangecatai/element";import{isArrowElement as f4}from"@orangecatai/element";import{isInGroup as a1}from"@orangecatai/element";import{jsx as CK}from"react/jsx-runtime";var vK=15,IK=({accumulatedChange:e,originalElements:t,shouldChangeByStepSize:o,nextValue:n,property:r,scene:a})=>{let i=a.getNonDeletedElementsMap(),s=t.map(c=>i.get(c.id)).filter(c=>c&&!a1(c)&&wo(c,r)),l=t.filter(c=>!a1(c)&&wo(c,r));if(n!==void 0){let c=g4(n);for(let m of s){if(!m)continue;a.mutateElement(m,{angle:c});let p=h4(m,i);p&&!f4(m)&&a.mutateElement(p,{angle:c})}a.triggerUpdate();return}for(let c=0;c<s.length;c++){let m=s[c];if(!m)continue;let p=l[c],d=Math.round(b4(p.angle)*100)/100,u=Math.round(e),h=(d+u)%360;o&&(h=st(h,vK)),h=h<0?h+360:h;let g=g4(h);a.mutateElement(m,{angle:g});let x=h4(m,i);x&&!f4(m)&&a.mutateElement(x,{angle:g})}a.triggerUpdate()},TK=({elements:e,scene:t,appState:o,property:n})=>{let r=e.filter(l=>!a1(l)&&wo(l,"angle")),a=r.map(l=>Math.round(b4(l.angle)%360*100)/100),i=new Set(a).size===1?a[0]:"Mixed",s=r.some(l=>wo(l,"angle"));return CK(zt,{label:"A",icon:vm,value:i,elements:e,dragInputCallback:IK,editable:s,appState:o,scene:t,property:n})},x4=TK;import{pointFrom as y4}from"@orangecatai/math";import{useMemo as kK}from"react";import{MIN_WIDTH_OR_HEIGHT as Ta}from"@orangecatai/common";import{getElementsInResizingFrame as i1,isFrameLikeElement as s1,replaceAllElementsInFrame as v4,updateBoundElements as SK}from"@orangecatai/element";import{rescalePointsInElement as MK,resizeSingleElement as E4}from"@orangecatai/element";import{getBoundTextElement as PK,handleBindTextResize as AK}from"@orangecatai/element";import{isTextElement as I4}from"@orangecatai/element";import{getCommonBounds as Eg}from"@orangecatai/element";import{jsx as BK}from"react/jsx-runtime";var Pl=10,LK=(e,t,o,n)=>{let r=n.x-e,a=n.y-t,i=n.width*o,s=n.height*o,l=e+r*o,c=t+a*o;return{width:i,height:s,x:l,y:c,...MK(n,i,s,!1),...I4(n)?{fontSize:n.fontSize*o}:{}}},_K=(e,t,o,n,r,a,i,s)=>{let l=s.getNonDeletedElementsMap(),c=LK(e,t,n,a);s.mutateElement(r,c);let m=PK(a,i);if(m){let p=m.fontSize*n;SK(r,s);let d=l.get(m.id);d&&I4(d)&&(s.mutateElement(d,{fontSize:p}),AK(r,s,o==="width"?"e":"s",!0))}},w4=(e,t,o,n,r,a,i,s,l,c)=>{a==="width"?t=Math.round(e/n*100)/100:e=Math.round(t*n*100)/100;let m=t/o;for(let p=0;p<s.length;p++){let d=s[p],u=i[p];_K(r[0],r[1],a,m,u,d,l,c)}},DK=({accumulatedChange:e,originalElements:t,originalElementsMap:o,originalAppState:n,shouldChangeByStepSize:r,nextValue:a,scene:i,property:s,setAppState:l,app:c})=>{let m=i.getNonDeletedElementsMap(),p=Sl(t,n);if(a!==void 0){for(let g of p){let x=kl(g,m,o);if(x.length>1){let E=x.map(M=>M.latest),y=x.map(M=>M.original),[w,v,I,C]=Eg(y),P=I-w,S=C-v,D=P/S,_=Math.max(Ta,s==="width"?Math.max(0,a):P),k=Math.max(Ta,s==="height"?Math.max(0,a):S);w4(_,k,S,D,y4(w,v),s,E,y,o,i)}else{let[E]=x,y=E?.latest,w=E?.original;if(y&&w&&wo(y,s)){let v=s==="width"?Math.max(0,a):y.width;s==="width"&&(r?v=st(v,Pl):v=Math.round(v));let I=s==="height"?Math.max(0,a):y.height;if(s==="height"&&(r?I=st(I,Pl):I=Math.round(I)),v=Math.max(Ta,v),I=Math.max(Ta,I),E4(v,I,y,w,o,i,s==="width"?"e":"s",{shouldInformMutation:!1}),s1(y)){let C=i1(i.getElementsIncludingDeleted(),y,n,i.getNonDeletedElementsMap()),P=v4(i.getElementsIncludingDeleted(),C,y,c);i.replaceAllElements(P)}}}}i.triggerUpdate();return}let d=s==="width"?e:0,u=s==="height"?e:0,h=[];for(let g of p){let x=kl(g,m,o);if(x.length>1){let E=x.map(M=>M.latest),y=x.map(M=>M.original),[w,v,I,C]=Eg(y),P=I-w,S=C-v,D=P/S,_=Math.max(0,P+d);s==="width"&&(r?_=st(_,Pl):_=Math.round(_));let k=Math.max(0,S+u);s==="height"&&(r?k=st(k,Pl):k=Math.round(k)),_=Math.max(Ta,_),k=Math.max(Ta,k),w4(_,k,S,D,y4(w,v),s,E,y,o,i)}else{let[E]=x,y=E?.latest,w=E?.original;if(y&&w&&wo(y,s)){let v=Math.max(0,w.width+d);s==="width"&&(r?v=st(v,Pl):v=Math.round(v));let I=Math.max(0,w.height+u);if(s==="height"&&(r?I=st(I,Pl):I=Math.round(I)),v=Math.max(Ta,v),I=Math.max(Ta,I),E4(v,I,y,w,o,i,s==="width"?"e":"s",{shouldInformMutation:!1}),s1(y)){let C=i1(i.getElementsIncludingDeleted(),y,n,i.getNonDeletedElementsMap());h.push(...C)}}}}l({elementsToHighlight:h}),i.triggerUpdate()},RK=({setAppState:e,app:t,originalElements:o,originalAppState:n})=>{let r=t.scene.getNonDeletedElementsMap(),a=o?.[0],i=a&&r.get(a.id);if(i&&s1(i)){let s=i1(t.scene.getElementsIncludingDeleted(),i,n,t.scene.getNonDeletedElementsMap()),l=v4(t.scene.getElementsIncludingDeleted(),s,i,t);t.scene.replaceAllElements(l),e({elementsToHighlight:null})}},NK=({property:e,elements:t,elementsMap:o,atomicUnits:n,scene:r,appState:a})=>{let i=kK(()=>n.map(c=>{let m=kl(c,o);if(m.length>1){let[d,u,h,g]=Eg(m.map(x=>x.latest));return Math.round((e==="width"?h-d:g-u)*100)/100}let[p]=m;return Math.round((e==="width"?p.latest.width:p.latest.height)*100)/100}),[o,n,e]),s=new Set(i).size===1?Math.round(i[0]*100)/100:"Mixed",l=i.length>0;return BK(zt,{label:e==="width"?"W":"H",elements:t,dragInputCallback:DK,value:s,editable:l,appState:a,property:e,scene:r,dragFinishedCallback:RK})},l1=NK;import{getBoundTextElement as FK,redrawTextBoundingBox as T4}from"@orangecatai/element";import{hasBoundTextElement as OK,isTextElement as zK}from"@orangecatai/element";import{isInGroup as HK}from"@orangecatai/element";import{jsx as $K}from"react/jsx-runtime";var C4=4,GK=4,UK=(e,t)=>e.reduce((o,n)=>{if(!n||HK(n))return o;if(zK(n))return o.push(n),o;if(OK(n)){let r=FK(n,t);if(r)return o.push(r),o}return o},[]),WK=({accumulatedChange:e,originalElements:t,shouldChangeByStepSize:o,nextValue:n,scene:r})=>{let a=r.getNonDeletedElementsMap(),i=t.map(l=>a.get(l.id)),s;if(n){s=Math.max(Math.round(n),C4);for(let l of i)r.mutateElement(l,{fontSize:s}),T4(l,r.getContainerElement(l),r);r.triggerUpdate()}else{let l=t;for(let c=0;c<i.length;c++){let m=i[c],p=l[c],d=Math.round(p.fontSize),u=Math.round(e),h=Math.max(d+u,C4);o&&(h=st(h,GK)),r.mutateElement(m,{fontSize:h}),T4(m,r.getContainerElement(m),r)}r.triggerUpdate()}},YK=({elements:e,scene:t,appState:o,property:n,elementsMap:r})=>{let a=UK(e,r);if(!a.length)return null;let i=a.map(c=>Math.round(c.fontSize*10)/10),s=new Set(i).size===1?i[0]:"Mixed",l=i.length>0;return $K(zt,{label:"F",icon:Va,elements:a,dragInputCallback:WK,value:s,editable:l,scene:t,property:n,appState:o})},k4=YK;import{pointFrom as Ca,pointRotateRads as wg}from"@orangecatai/math";import{useMemo as VK}from"react";import{isTextElement as KK}from"@orangecatai/element";import{getCommonBounds as c1}from"@orangecatai/element";import{jsx as JK}from"react/jsx-runtime";var XK=(e,t,o,n,r,a,i)=>{for(let s=0;s<n.length;s++){let l=n[s],[c,m]=[l.x+l.width/2,l.y+l.height/2],[p,d]=wg(Ca(l.x,l.y),Ca(c,m),l.angle),u=e==="x"?Math.round(p+t):p,h=e==="y"?Math.round(d+o):d;Mi(u,h,l,a,i,r,!1)}},ZK=(e,t,o,n,r,a)=>{let i=r.getNonDeletedElementsMap(),[s,l,,]=c1(o),c=e-s,m=t-l;for(let p=0;p<o.length;p++){let d=o[p],u=i.get(d.id);if(u&&(!KK(u)||!u.containerId)){let[h,g]=[u.x+u.width/2,u.y+u.height/2],[x,E]=wg(Ca(u.x,u.y),Ca(h,g),u.angle);Mi(x+c,E+m,d,r,a,n,!1)}}},jK=({accumulatedChange:e,originalElements:t,originalElementsMap:o,shouldChangeByStepSize:n,nextValue:r,property:a,scene:i,originalAppState:s,app:l})=>{let c=i.getNonDeletedElementsMap();if(r!==void 0){for(let u of Sl(t,s)){let h=kl(u,c,o);if(h.length>1){let[g,x,,]=c1(h.map(w=>w.latest));ZK(a==="x"?r:g,a==="y"?r:x,h.map(w=>w.original),o,i,l.state)}else{let g=h[0]?.original,x=h[0]?.latest;if(g&&x&&wo(x,a)){let[E,y]=[g.x+g.width/2,g.y+g.height/2],[w,v]=wg(Ca(g.x,g.y),Ca(E,y),g.angle);Mi(a==="x"?r:w,a==="y"?r:v,g,i,l.state,o,!1)}}}i.triggerUpdate();return}let m=n?st(e,kd):e;XK(a,a==="x"?m:0,a==="y"?m:0,t,o,i,l.state),i.triggerUpdate()},qK=({property:e,elements:t,elementsMap:o,atomicUnits:n,scene:r,appState:a})=>{let i=VK(()=>n.map(l=>{let c=Object.keys(l).map(g=>o.get(g)).filter(g=>g!==void 0);if(c.length>1){let[g,x]=c1(c);return Math.round((e==="x"?g:x)*100)/100}let[m]=c,[p,d]=[m.x+m.width/2,m.y+m.height/2],[u,h]=wg(Ca(m.x,m.y),Ca(p,d),m.angle);return Math.round((e==="x"?u:h)*100)/100}),[n,o,e]),s=new Set(i).size===1?i[0]:"Mixed";return JK(zt,{label:e==="x"?"X":"Y",elements:t,dragInputCallback:jK,value:s,property:e,scene:r,appState:a})},d1=qK;import{clamp as Sd,pointFrom as vg,pointRotateRads as M4,round as S4}from"@orangecatai/math";import{getFlipAdjustedCropPosition as QK,getUncroppedWidthAndHeight as eX}from"@orangecatai/element";import{isImageElement as P4}from"@orangecatai/element";import{jsx as nX}from"react/jsx-runtime";var tX=({accumulatedChange:e,instantChange:t,originalElements:o,originalElementsMap:n,shouldChangeByStepSize:r,nextValue:a,property:i,scene:s,originalAppState:l,app:c})=>{let m=s.getNonDeletedElementsMap(),p=o[0],[d,u]=[p.x+p.width/2,p.y+p.height/2],[h,g]=M4(vg(p.x,p.y),vg(d,u),p.angle);if(l.croppingElementId===p.id){let v=m.get(p.id);if(!v||!P4(v)||!v.crop)return;let I=v.crop,C=I,P=v.scale[0]===-1,S=v.scale[1]===-1,{width:D,height:_}=eX(v);if(a!==void 0){if(i==="x"){let B=a*(I.naturalWidth/D);P?C={...I,x:Sd(I.naturalWidth-B-I.width,0,I.naturalWidth-I.width)}:C={...I,x:Sd(a*(I.naturalWidth/D),0,I.naturalWidth-I.width)}}i==="y"&&(C={...I,y:Sd(a*(I.naturalHeight/_),0,I.naturalHeight-I.height)}),s.mutateElement(v,{crop:C});return}let k=(i==="x"?t:0)*(P?-1:1),M=(i==="y"?t:0)*(S?-1:1);C={...I,x:Sd(I.x+k,0,I.naturalWidth-I.width),y:Sd(I.y+M,0,I.naturalHeight-I.height)},s.mutateElement(v,{crop:C});return}if(a!==void 0){Mi(i==="x"?a:h,i==="y"?a:g,p,s,c.state,n);return}let x=i==="x"?e:0,E=i==="y"?e:0,y=i==="x"?Math.round(r?st(p.x+x,kd):h+x):h,w=i==="y"?Math.round(r?st(p.y+E,kd):g+E):g;Mi(y,w,p,s,c.state,n)},oX=({property:e,element:t,elementsMap:o,scene:n,appState:r})=>{let[a,i]=M4(vg(t.x,t.y),vg(t.x+t.width/2,t.y+t.height/2),t.angle),s=S4(e==="x"?a:i,2);if(r.croppingElementId===t.id&&P4(t)&&t.crop){let l=QK(t);l&&(s=S4(e==="x"?l.x:l.y,2))}return nX(zt,{label:e==="x"?"X":"Y",elements:[t],dragInputCallback:tX,scene:n,value:s,property:e,appState:r})},m1=oX;import{Fragment as g1,jsx as me,jsxs as vo}from"react/jsx-runtime";var pX=50,Md=e=>{let t=$o(),o=e.app.scene.getSceneNonce()||1,n=e.app.scene.getSelectedElements({selectedElementIds:t.selectedElementIds,includeBoundTextElement:!1}),r=ma(e.app);return me(uX,{...e,appState:t,sceneNonce:o,selectedElements:n,gridModeEnabled:r})},ot=({children:e,columns:t=1,heading:o,style:n,...r})=>me("div",{className:rX("exc-stats__row",{"exc-stats__row--heading":o}),style:{gridTemplateColumns:`repeat(${t}, 1fr)`,...n},...r,children:e});ot.displayName="StatsRow";var Tg=({children:e,order:t,style:o,...n})=>me("div",{className:"exc-stats__rows",style:{order:t,...o},...n,children:e});Tg.displayName="StatsRows";Md.StatsRow=ot;Md.StatsRows=Tg;var uX=sX(({app:e,onClose:t,renderCustomStats:o,selectedElements:n,appState:r,sceneNonce:a,gridModeEnabled:i})=>{let s=e.scene,l=s.getNonDeletedElements(),c=s.getNonDeletedElementsMap(),m=Ce(),p=n.length===1?n[0]:null,d=n.length>1?n:null,u=r.croppingElementId&&u1(p),h=u?cX(p):null,[g,x]=iX({width:0,height:0}),E=p1(()=>aX(v=>{let I=lX(v);x({width:Math.round(I[2])-Math.round(I[0]),height:Math.round(I[3])-Math.round(I[1])})},pX),[]);L4(()=>{E(l)},[a,l,E]),L4(()=>()=>E.cancel(),[E]);let y=p1(()=>Sl(n,r),[n,r]),w=p1(()=>dX(n),[n]);return me("div",{className:"exc-stats",children:vo(gt,{padding:3,children:[vo("div",{className:"title",children:[me("h2",{children:f("stats.title")}),me("div",{className:"close",onClick:t,children:Go})]}),vo(wc,{label:me("h3",{children:f("stats.generalStats")}),open:!!(r.stats.panels&Ig.generalStats),openTrigger:()=>m(v=>({stats:{open:!0,panels:v.stats.panels^Ig.generalStats}})),children:[vo(Tg,{children:[me(ot,{heading:!0,children:f("stats.scene")}),vo(ot,{columns:2,children:[me("div",{children:f("stats.shapes")}),me("div",{children:l.length})]}),vo(ot,{columns:2,children:[me("div",{children:f("stats.width")}),me("div",{children:g.width})]}),vo(ot,{columns:2,children:[me("div",{children:f("stats.height")}),me("div",{children:g.height})]}),i&&vo(g1,{children:[me(ot,{heading:!0,children:"Canvas"}),me(ot,{children:me(r4,{property:"gridStep",scene:s,appState:r,setAppState:m})})]})]}),o?.(l,r)]}),!w&&n.length>0&&me("div",{id:"elementStats",style:{marginTop:12},children:me(wc,{label:me("h3",{children:f("stats.elementProperties")}),open:!!(r.stats.panels&Ig.elementProperties),openTrigger:()=>m(v=>({stats:{open:!0,panels:v.stats.panels^Ig.elementProperties}})),children:vo(Tg,{children:[p&&vo(g1,{children:[u&&me(ot,{heading:!0,children:f("labels.unCroppedDimension")}),r.croppingElementId&&u1(p)&&h&&vo(ot,{columns:2,children:[me("div",{children:f("stats.width")}),me("div",{children:A4(h.width,2)})]}),r.croppingElementId&&u1(p)&&h&&vo(ot,{columns:2,children:[me("div",{children:f("stats.height")}),me("div",{children:A4(h.height,2)})]}),me(ot,{heading:!0,"data-testid":"stats-element-type",style:{margin:"0.3125rem 0"},children:r.croppingElementId?f("labels.imageCropping"):f(`element.${p.type}`)}),me(ot,{children:me(m1,{element:p,property:"x",elementsMap:c,scene:s,appState:r})}),me(ot,{children:me(m1,{element:p,property:"y",elementsMap:c,scene:s,appState:r})}),me(ot,{children:me(r1,{property:"width",element:p,scene:s,appState:r})}),me(ot,{children:me(r1,{property:"height",element:p,scene:s,appState:r})}),me(ot,{children:me(o4,{property:"angle",element:p,scene:s,appState:r})}),me(ot,{children:me(u4,{property:"fontSize",element:p,scene:s,appState:r})})]}),d&&vo(g1,{children:[mX(d)&&me(ot,{heading:!0,children:f("element.group")}),vo(ot,{columns:2,style:{margin:"0.3125rem 0"},children:[me("div",{children:f("stats.shapes")}),me("div",{children:n.length})]}),me(ot,{children:me(d1,{property:"x",elements:d,elementsMap:c,atomicUnits:y,scene:s,appState:r})}),me(ot,{children:me(d1,{property:"y",elements:d,elementsMap:c,atomicUnits:y,scene:s,appState:r})}),me(ot,{children:me(l1,{property:"width",elements:d,elementsMap:c,atomicUnits:y,scene:s,appState:r})}),me(ot,{children:me(l1,{property:"height",elements:d,elementsMap:c,atomicUnits:y,scene:s,appState:r})}),me(ot,{children:me(x4,{property:"angle",elements:d,scene:s,appState:r})}),me(ot,{children:me(k4,{property:"fontSize",elements:d,scene:s,appState:r,elementsMap:c})})]})]})})})]})})},(e,t)=>e.sceneNonce===t.sceneNonce&&e.selectedElements===t.selectedElements&&e.appState.stats.panels===t.appState.stats.panels&&e.gridModeEnabled===t.gridModeEnabled&&e.appState.gridStep===t.appState.gridStep&&e.appState.croppingElementId===t.appState.croppingElementId);import{useCallback as gX,useEffect as _4,useState as D4}from"react";import{normalizeLink as hX,KEYS as h1}from"@orangecatai/common";import{defaultGetElementLinkFromSelection as fX,getLinkIdAndTypeFromSelection as bX}from"@orangecatai/element";import{jsx as Al,jsxs as Cg}from"react/jsx-runtime";var xX=({sourceElementId:e,onClose:t,appState:o,scene:n,generateLinkForSelection:r=fX})=>{let a=n.getNonDeletedElementsMap(),i=a.get(e)?.link??null,[s,l]=D4(i),[c,m]=D4(!1);_4(()=>{let d=de(a,o),u=i;if(d.length>0&&r){let h=bX(d,o);h&&(u=hX(r(h.id,h.type)))}l(u)},[a,o,o.selectedElementIds,i,r]);let p=gX(()=>{if(s&&s!==a.get(e)?.link){let d=a.get(e);d&&n.mutateElement(d,{link:s})}if(!s&&c&&e){let d=a.get(e);d&&n.mutateElement(d,{link:null})}t?.()},[e,s,a,c,n,t]);return _4(()=>{let d=u=>{o.openDialog?.name==="elementLinkSelector"&&u.key===h1.ENTER&&p(),o.openDialog?.name==="elementLinkSelector"&&u.key===h1.ESCAPE&&t?.()};return window.addEventListener("keydown",d),()=>{window.removeEventListener("keydown",d)}},[o,t,p]),Cg("div",{className:"ElementLinkDialog",children:[Cg("div",{className:"ElementLinkDialog__header",children:[Al("h2",{children:f("elementLink.title")}),Al("p",{children:f("elementLink.desc")})]}),Cg("div",{className:"ElementLinkDialog__input",children:[Al(ia,{value:s??"",onChange:d=>{c||m(!0),l(d)},onKeyDown:d=>{d.key===h1.ENTER&&p()},className:"ElementLinkDialog__input-field",selectOnRender:!0}),i&&s&&Al(ie,{type:"button",title:f("buttons.remove"),"aria-label":f("buttons.remove"),label:f("buttons.remove"),onClick:()=>{l(null),m(!0)},className:"ElementLinkDialog__remove",icon:Ut})]}),Cg("div",{className:"ElementLinkDialog__actions",children:[Al(vr,{label:f("buttons.cancel"),onClick:()=>{t?.()},style:{marginRight:10}}),Al(vr,{label:f("buttons.confirm"),onClick:p,actionType:"primary"})]})]})},R4=xX;import yX,{useState as EX}from"react";import{Fragment as wX,jsx as f1}from"react/jsx-runtime";var N4=({children:e,onClose:t})=>{let[o,n]=EX(!!e),{container:r}=Qe(),a=yX.useCallback(()=>{n(!1),t&&t(),r?.focus()},[t,r]);return f1(wX,{children:o&&f1(bt,{size:"small",onCloseRequest:a,title:f("errorDialog.title"),children:f1("div",{style:{whiteSpace:"pre-wrap"},children:e})})})};import vX from"react";import{isDarwin as B4,isFirefox as F4,isWindows as IX}from"@orangecatai/common";import{KEYS as ut}from"@orangecatai/common";import{Fragment as z4,jsx as j,jsxs as No}from"react/jsx-runtime";var TX=()=>No("div",{className:"HelpDialog__header",children:[No("a",{className:"HelpDialog__btn",href:"https://docs.excalidraw.com",target:"_blank",rel:"noopener",children:[j("div",{className:"HelpDialog__link-icon",children:xh}),f("helpDialog.documentation")]}),No("a",{className:"HelpDialog__btn",href:"https://plus.excalidraw.com/blog",target:"_blank",rel:"noopener",children:[j("div",{className:"HelpDialog__link-icon",children:xh}),f("helpDialog.blog")]}),No("a",{className:"HelpDialog__btn",href:"https://github.com/excalidraw/excalidraw/issues",target:"_blank",rel:"noopener noreferrer",children:[j("div",{className:"HelpDialog__link-icon",children:fm}),f("helpDialog.github")]}),No("a",{className:"HelpDialog__btn",href:"https://youtube.com/@excalidraw",target:"_blank",rel:"noopener noreferrer",children:[j("div",{className:"HelpDialog__link-icon",children:lv}),"YouTube"]})]}),CX=e=>No(z4,{children:[j("h3",{children:e.title}),j("div",{className:"HelpDialog__islands-container",children:e.children})]}),b1=e=>No("div",{className:`HelpDialog__island ${e.className}`,children:[j("h4",{className:"HelpDialog__island-title",children:e.caption}),j("div",{className:"HelpDialog__island-content",children:e.children})]});function*kX(e,t){let o=!0;for(let n of e)o||(yield t),o=!1,yield n}var SX=e=>e.replace(/\b[a-z]\b/,t=>t.toUpperCase()),oe=({label:e,shortcuts:t,isOr:o=!0})=>{let n=t.map(r=>(r.endsWith("++")?[...r.slice(0,-2).split("+"),"+"]:r.split("+")).map(i=>j(MX,{children:SX(i)},i)));return No("div",{className:"HelpDialog__shortcut",children:[j("div",{children:e}),j("div",{className:"HelpDialog__key-container",children:[...kX(n,o?f("helpDialog.or"):null)]})]})},MX=e=>j("kbd",{className:"HelpDialog__key",...e}),O4=({onClose:e})=>{let t=vX.useCallback(()=>{e&&e()},[e]);return j(z4,{children:No(bt,{onCloseRequest:t,title:f("helpDialog.title"),className:"HelpDialog",children:[j(TX,{}),No(CX,{title:f("helpDialog.shortcuts"),children:[No(b1,{className:"HelpDialog__island--tools",caption:f("helpDialog.tools"),children:[j(oe,{label:f("toolBar.hand"),shortcuts:[ut.H]}),j(oe,{label:f("toolBar.selection"),shortcuts:[ut.V,ut[1]]}),j(oe,{label:f("toolBar.rectangle"),shortcuts:[ut.R,ut[2]]}),j(oe,{label:f("toolBar.diamond"),shortcuts:[ut.D,ut[3]]}),j(oe,{label:f("toolBar.ellipse"),shortcuts:[ut.O,ut[4]]}),j(oe,{label:f("toolBar.arrow"),shortcuts:[ut.A,ut[5]]}),j(oe,{label:f("toolBar.line"),shortcuts:[ut.L,ut[6]]}),j(oe,{label:f("toolBar.freedraw"),shortcuts:[ut.P,ut[7]]}),j(oe,{label:f("toolBar.text"),shortcuts:[ut.T,ut[8]]}),j(oe,{label:f("toolBar.image"),shortcuts:[ut[9]]}),j(oe,{label:f("toolBar.eraser"),shortcuts:[ut.E,ut[0]]}),j(oe,{label:f("toolBar.frame"),shortcuts:[ut.F]}),j(oe,{label:f("toolBar.laser"),shortcuts:[ut.K]}),j(oe,{label:f("labels.eyeDropper"),shortcuts:[ut.I,"Shift+S","Shift+G"]}),j(oe,{label:f("helpDialog.editLineArrowPoints"),shortcuts:[G("CtrlOrCmd+Enter")]}),j(oe,{label:f("helpDialog.editText"),shortcuts:[G("Enter")]}),j(oe,{label:f("helpDialog.textNewLine"),shortcuts:[G("Enter"),G("Shift+Enter")]}),j(oe,{label:f("helpDialog.textFinish"),shortcuts:[G("Esc"),G("CtrlOrCmd+Enter")]}),j(oe,{label:f("helpDialog.curvedArrow"),shortcuts:["A",f("helpDialog.click"),f("helpDialog.click"),f("helpDialog.click")],isOr:!1}),j(oe,{label:f("helpDialog.curvedLine"),shortcuts:["L",f("helpDialog.click"),f("helpDialog.click"),f("helpDialog.click")],isOr:!1}),j(oe,{label:f("helpDialog.cropStart"),shortcuts:[f("helpDialog.doubleClick"),G("Enter")],isOr:!0}),j(oe,{label:f("helpDialog.cropFinish"),shortcuts:[G("Enter"),G("Escape")],isOr:!0}),j(oe,{label:f("toolBar.lock"),shortcuts:[ut.Q]}),j(oe,{label:f("helpDialog.preventBinding"),shortcuts:[G("CtrlOrCmd")]}),j(oe,{label:f("toolBar.link"),shortcuts:[G("CtrlOrCmd+K")]}),j(oe,{label:f("toolBar.convertElementType"),shortcuts:["Tab","Shift+Tab"],isOr:!0})]}),No(b1,{className:"HelpDialog__island--view",caption:f("helpDialog.view"),children:[j(oe,{label:f("buttons.zoomIn"),shortcuts:[G("CtrlOrCmd++")]}),j(oe,{label:f("buttons.zoomOut"),shortcuts:[G("CtrlOrCmd+-")]}),j(oe,{label:f("buttons.resetZoom"),shortcuts:[G("CtrlOrCmd+0")]}),j(oe,{label:f("helpDialog.zoomToFit"),shortcuts:["Shift+1"]}),j(oe,{label:f("helpDialog.zoomToSelection"),shortcuts:["Shift+2"]}),j(oe,{label:f("helpDialog.movePageUpDown"),shortcuts:["PgUp/PgDn"]}),j(oe,{label:f("helpDialog.movePageLeftRight"),shortcuts:["Shift+PgUp/PgDn"]}),j(oe,{label:f("buttons.zenMode"),shortcuts:[G("Alt+Z")]}),j(oe,{label:f("buttons.objectsSnapMode"),shortcuts:[G("Alt+S")]}),j(oe,{label:f("labels.toggleGrid"),shortcuts:[G("CtrlOrCmd+'")]}),j(oe,{label:f("labels.viewMode"),shortcuts:[G("Alt+R")]}),j(oe,{label:f("labels.toggleTheme"),shortcuts:[G("Alt+Shift+D")]}),j(oe,{label:f("stats.fullTitle"),shortcuts:[G("Alt+/")]}),j(oe,{label:f("search.title"),shortcuts:[Xe("searchMenu")]}),j(oe,{label:f("commandPalette.title"),shortcuts:F4?[Xe("commandPalette")]:[Xe("commandPalette"),Xe("commandPalette",1)]})]}),No(b1,{className:"HelpDialog__island--editor",caption:f("helpDialog.editor"),children:[j(oe,{label:f("helpDialog.createFlowchart"),shortcuts:[G("CtrlOrCmd+Arrow Key")],isOr:!0}),j(oe,{label:f("helpDialog.navigateFlowchart"),shortcuts:[G("Alt+Arrow Key")],isOr:!0}),j(oe,{label:f("labels.moveCanvas"),shortcuts:[G(`Space+${f("helpDialog.drag")}`),G(`Wheel+${f("helpDialog.drag")}`)],isOr:!0}),j(oe,{label:f("buttons.clearReset"),shortcuts:[G("CtrlOrCmd+Delete")]}),j(oe,{label:f("labels.delete"),shortcuts:[G("Delete")]}),j(oe,{label:f("labels.cut"),shortcuts:[G("CtrlOrCmd+X")]}),j(oe,{label:f("labels.copy"),shortcuts:[G("CtrlOrCmd+C")]}),j(oe,{label:f("labels.paste"),shortcuts:[G("CtrlOrCmd+V")]}),j(oe,{label:f("labels.pasteAsPlaintext"),shortcuts:[G("CtrlOrCmd+Shift+V")]}),j(oe,{label:f("labels.selectAll"),shortcuts:[G("CtrlOrCmd+A")]}),j(oe,{label:f("labels.multiSelect"),shortcuts:[G(`Shift+${f("helpDialog.click")}`)]}),j(oe,{label:f("helpDialog.deepSelect"),shortcuts:[G(`CtrlOrCmd+${f("helpDialog.click")}`)]}),j(oe,{label:f("helpDialog.deepBoxSelect"),shortcuts:[G(`CtrlOrCmd+${f("helpDialog.drag")}`)]}),(Ps||F4)&&j(oe,{label:f("labels.copyAsPng"),shortcuts:[G("Shift+Alt+C")]}),j(oe,{label:f("labels.copyStyles"),shortcuts:[G("CtrlOrCmd+Alt+C")]}),j(oe,{label:f("labels.pasteStyles"),shortcuts:[G("CtrlOrCmd+Alt+V")]}),j(oe,{label:f("labels.sendToBack"),shortcuts:[B4?G("CtrlOrCmd+Alt+["):G("CtrlOrCmd+Shift+[")]}),j(oe,{label:f("labels.bringToFront"),shortcuts:[B4?G("CtrlOrCmd+Alt+]"):G("CtrlOrCmd+Shift+]")]}),j(oe,{label:f("labels.sendBackward"),shortcuts:[G("CtrlOrCmd+[")]}),j(oe,{label:f("labels.bringForward"),shortcuts:[G("CtrlOrCmd+]")]}),j(oe,{label:f("labels.alignTop"),shortcuts:[G("CtrlOrCmd+Shift+Up")]}),j(oe,{label:f("labels.alignBottom"),shortcuts:[G("CtrlOrCmd+Shift+Down")]}),j(oe,{label:f("labels.alignLeft"),shortcuts:[G("CtrlOrCmd+Shift+Left")]}),j(oe,{label:f("labels.alignRight"),shortcuts:[G("CtrlOrCmd+Shift+Right")]}),j(oe,{label:f("labels.duplicateSelection"),shortcuts:[G("CtrlOrCmd+D"),G(`Alt+${f("helpDialog.drag")}`)]}),j(oe,{label:f("helpDialog.toggleElementLock"),shortcuts:[G("CtrlOrCmd+Shift+L")]}),j(oe,{label:f("buttons.undo"),shortcuts:[G("CtrlOrCmd+Z")]}),j(oe,{label:f("buttons.redo"),shortcuts:IX?[G("CtrlOrCmd+Y"),G("CtrlOrCmd+Shift+Z")]:[G("CtrlOrCmd+Shift+Z")]}),j(oe,{label:f("labels.group"),shortcuts:[G("CtrlOrCmd+G")]}),j(oe,{label:f("labels.ungroup"),shortcuts:[G("CtrlOrCmd+Shift+G")]}),j(oe,{label:f("labels.flipHorizontal"),shortcuts:[G("Shift+H")]}),j(oe,{label:f("labels.flipVertical"),shortcuts:[G("Shift+V")]}),j(oe,{label:f("labels.showStroke"),shortcuts:[G("S")]}),j(oe,{label:f("labels.showBackground"),shortcuts:[G("G")]}),j(oe,{label:f("labels.showFonts"),shortcuts:[G("Shift+F")]}),j(oe,{label:f("labels.decreaseFontSize"),shortcuts:[G("CtrlOrCmd+Shift+<")]}),j(oe,{label:f("labels.increaseFontSize"),shortcuts:[G("CtrlOrCmd+Shift+>")]})]})]})]})})};import{CANVAS_SEARCH_TAB as PX,DEFAULT_SIDEBAR as AX}from"@orangecatai/common";import{isFlowchartNodeElement as LX,isImageElement as H4,isLinearElement as G4,isLineElement as _X,isTextBindableContainer as DX,isTextElement as RX}from"@orangecatai/element";import{isNodeInFlowchart as NX}from"@orangecatai/element";import{jsx as x1}from"react/jsx-runtime";var Oe=e=>Array.isArray(e)?`<kbd>${e.map(G).join(" + ")}</kbd>`:`<kbd>${G(e)}</kbd>`,BX=({appState:e,isMobile:t,editorInterface:o,app:n})=>{let{activeTool:r,isResizing:a,isRotating:i,lastPointerDownWith:s}=e,l=e.multiElement!==null;if(e.openSidebar?.name===AX.name&&e.openSidebar.tab===PX&&e.searchMatches?.matches.length)return f("hints.dismissSearch",{shortcut:Oe("Escape")});if(e.openSidebar&&!o.canFitSidebar)return null;if(ho(e))return f("hints.eraserRevert",{shortcut:Oe("Alt")});let c=n.scene.getSelectedElements(e);if(e.selectedLinearElement?.isDragging&&c[0]?.type==="arrow")return f("hints.arrowBindModifiers",{shortcut_1:Oe("Ctrl"),shortcut_2:Oe("Alt")});if(r.type==="arrow"||r.type==="line")return l?f("hints.linearElementMulti",{shortcut_1:Oe("Escape"),shortcut_2:Oe("Enter")}):r.type==="arrow"?f("hints.arrowTool",{shortcut:Oe("A")}):f("hints.linearElement");if(r.type==="freedraw")return f("hints.freeDraw");if(r.type==="text")return f("hints.text");if(r.type==="embeddable")return f("hints.embeddable");if(a&&s==="mouse"&&c.length===1){let m=c[0];return G4(m)&&m.points.length===2?f("hints.lockAngle",{shortcut:Oe("Shift")}):H4(m)?f("hints.resizeImage",{shortcut_1:Oe("Shift"),shortcut_2:Oe("Alt")}):f("hints.resize",{shortcut_1:Oe("Shift"),shortcut_2:Oe("Alt")})}if(i&&s==="mouse")return f("hints.rotate",{shortcut:Oe("Shift")});if(c.length===1&&RX(c[0]))return f("hints.text_selected",{shortcut:Oe("Enter")});if(e.editingTextElement)return f("hints.text_editing",{shortcut_1:Oe("Escape"),shortcut_2:Oe(["CtrlOrCmd","Enter"])});if(e.croppingElementId)return f("hints.leaveCropEditor",{shortcut_1:Oe("Enter"),shortcut_2:Oe("Escape")});if(c.length===1&&H4(c[0]))return f("hints.enterCropEditor",{shortcut:Oe("Enter")});if(r.type==="selection"){if(e.selectionElement&&!c.length&&!e.editingTextElement&&!e.selectedLinearElement?.isEditing)return f("hints.deepBoxSelect",{shortcut:Oe("CtrlOrCmd")});if(ma(n)&&e.selectedElementsAreBeingDragged)return f("hints.disableSnapping",{shortcut:Oe("CtrlOrCmd")});if(!c.length&&!t)return f("hints.canvasPanning",{shortcut_1:Oe(f("keys.mmb")),shortcut_2:Oe("Space")});if(c.length===1){if(G4(c[0]))return e.selectedLinearElement?.isEditing?e.selectedLinearElement.selectedPointsIndices?f("hints.lineEditor_pointSelected",{shortcut_1:Oe("Delete"),shortcut_2:Oe(["CtrlOrCmd","D"])}):f("hints.lineEditor_nothingSelected",{shortcut_1:Oe("Shift"),shortcut_2:Oe("Alt")}):_X(c[0])?f("hints.lineEditor_line_info",{shortcut:Oe("Enter")}):f("hints.lineEditor_info",{shortcut_1:Oe("CtrlOrCmd"),shortcut_2:Oe(["CtrlOrCmd","Enter"])});if(!e.newElement&&!e.selectedElementsAreBeingDragged&&DX(c[0])){let m=f("hints.bindTextToElement",{shortcut:Oe("Enter")}),p=f("hints.createFlowchart",{shortcut:Oe(["CtrlOrCmd","\u2191\u2193"])});return LX(c[0])?NX(c[0],n.scene.getNonDeletedElementsMap())?[m,p]:[m,p]:m}}}return null},U4=({appState:e,isMobile:t,editorInterface:o,app:n})=>{let r=BX({appState:e,isMobile:t,editorInterface:o,app:n});if(!r)return null;let i=(Array.isArray(r)?r.map(s=>s.replace(/\. ?$/,"")).join(", "):r).split(/(<kbd>[^<]+<\/kbd>)/g).map((s,l)=>{if(l%2===1){let c=s[0]==="<"&&s.match(/^<kbd>([^<]+)<\/kbd>$/);return x1("kbd",{children:c?c[1]:s},l)}return s});return x1("div",{className:"HintViewer",children:x1("span",{children:i})})};import{useEffect as $4,useRef as UX,useState as ka}from"react";import{DEFAULT_EXPORT_PADDING as WX,EXPORT_IMAGE_TYPES as y1,isFirefox as YX,EXPORT_SCALES as $X,cloneJSON as V4}from"@orangecatai/common";import{useCallback as FX,useRef as OX,useState as zX}from"react";var HX=2e3,W4=()=>{let[e,t]=zX(null),o=OX(0),n=()=>{clearTimeout(o.current),t("success"),o.current=window.setTimeout(()=>{t(null)},HX)},r=FX(()=>{t(null)},[]);return{copyStatus:e,resetCopyStatus:r,onCopy:n}};import GX from"clsx";import{jsx as Y4}from"react/jsx-runtime";var Pd=({title:e,name:t,checked:o,onChange:n,disabled:r=!1})=>Y4("div",{className:GX("Switch",{toggled:o,disabled:r}),children:Y4("input",{name:t,id:t,title:e,type:"checkbox",checked:o,disabled:r,onChange:()=>n(!o),onKeyDown:a=>{a.key===" "&&n(!o)}})});import{jsx as nt,jsxs as Sa}from"react/jsx-runtime";var VX=()=>Sa("div",{children:[nt("h3",{children:f("canvasError.cannotShowPreview")}),nt("p",{children:nt("span",{children:f("canvasError.canvasTooBig")})}),Sa("em",{children:["(",f("canvasError.canvasTooBigTip"),")"]})]}),KX=({appStateSnapshot:e,elementsSnapshot:t,files:o,actionManager:n,onExportImage:r,name:a})=>{let i=Ge(t,e),[s,l]=ka(a),[c,m]=ka(i),[p,d]=ka(e.exportBackground),[u,h]=ka(e.exportWithDarkMode),[g,x]=ka(e.exportEmbedScene),[E,y]=ka(e.exportScale),w=UX(null),[v,I]=ka(null),{onCopy:C,copyStatus:P,resetCopyStatus:S}=W4();$4(()=>{S()},[s,p,u,E,g,S]);let{exportedElements:D,exportingFrame:_}=Qa(t,e,c);return $4(()=>{let k=w.current;if(!k)return;let M=k.offsetWidth,B=k.offsetHeight;M&&na({elements:D,appState:{...e,name:s,exportBackground:p,exportWithDarkMode:u,exportScale:E,exportEmbedScene:g},files:o,exportPadding:WX,maxWidthOrHeight:Math.max(M,B),exportingFrame:_}).then(O=>(I(null),Ua(O).then(()=>{k.replaceChildren(O)}).catch(N=>{throw N.name==="CANVAS_POSSIBLY_TOO_BIG"?new Error(f("canvasError.canvasTooBig")):N}))).catch(O=>{console.error(O),I(O)})},[e,o,D,_,s,p,u,E,g]),Sa("div",{className:"ImageExportModal",children:[nt("h3",{children:f("imageExportDialog.header")}),Sa("div",{className:"ImageExportModal__preview",children:[nt("div",{className:"ImageExportModal__preview__canvas",ref:w,children:v&&nt(VX,{})}),nt("div",{className:"ImageExportModal__preview__filename",children:!Wi&&nt("input",{type:"text",className:"TextInput",value:s,style:{width:"30ch"},onChange:k=>{l(k.target.value),n.executeAction(Hf,"ui",k.target.value)}})})]}),Sa("div",{className:"ImageExportModal__settings",children:[nt("h3",{children:f("imageExportDialog.header")}),i&&nt(Ad,{label:f("imageExportDialog.label.onlySelected"),name:"exportOnlySelected",children:nt(Pd,{name:"exportOnlySelected",checked:c,onChange:k=>{m(k)}})}),nt(Ad,{label:f("imageExportDialog.label.withBackground"),name:"exportBackgroundSwitch",children:nt(Pd,{name:"exportBackgroundSwitch",checked:p,onChange:k=>{d(k),n.executeAction(Gf,"ui",k)}})}),nt(Ad,{label:f("imageExportDialog.label.darkMode"),name:"exportDarkModeSwitch",children:nt(Pd,{name:"exportDarkModeSwitch",checked:u,onChange:k=>{h(k),n.executeAction(bI,"ui",k)}})}),nt(Ad,{label:f("imageExportDialog.label.embedScene"),tooltip:f("imageExportDialog.tooltip.embedScene"),name:"exportEmbedSwitch",children:nt(Pd,{name:"exportEmbedSwitch",checked:g,onChange:k=>{x(k),n.executeAction(cp,"ui",k)}})}),nt(Ad,{label:f("imageExportDialog.label.scale"),name:"exportScale",children:nt(Qu,{name:"exportScale",value:E,onChange:k=>{y(k),n.executeAction(fI,"ui",k)},choices:$X.map(k=>({value:k,label:`${k}\xD7`}))})}),Sa("div",{className:"ImageExportModal__settings__buttons",children:[nt(on,{className:"ImageExportModal__settings__buttons__button",label:f("imageExportDialog.title.exportToPng"),onClick:()=>r(y1.png,D,{exportingFrame:_}),icon:Nh,children:f("imageExportDialog.button.exportToPng")}),nt(on,{className:"ImageExportModal__settings__buttons__button",label:f("imageExportDialog.title.exportToSvg"),onClick:()=>r(y1.svg,D,{exportingFrame:_}),icon:Nh,children:f("imageExportDialog.button.exportToSvg")}),(Ps||YX)&&nt(on,{className:"ImageExportModal__settings__buttons__button",label:f("imageExportDialog.title.copyPngToClipboard"),status:P,onClick:async()=>{await r(y1.clipboard,D,{exportingFrame:_}),C()},icon:is,children:f("imageExportDialog.button.copyPngToClipboard")})]})]})]})},Ad=({label:e,children:t,tooltip:o,name:n})=>Sa("div",{className:"ImageExportModal__settings__setting",title:e,children:[Sa("label",{htmlFor:n,className:"ImageExportModal__settings__setting__label",children:[e,o&&nt(Xt,{label:o,long:!0,children:zw})]}),nt("div",{className:"ImageExportModal__settings__setting__content",children:t})]}),K4=({elements:e,appState:t,files:o,actionManager:n,onExportImage:r,onCloseRequest:a,name:i})=>{let[{appStateSnapshot:s,elementsSnapshot:l}]=ka(()=>({appStateSnapshot:V4(t),elementsSnapshot:V4(e)}));return nt(bt,{onCloseRequest:a,size:"wide",title:!1,children:nt(KX,{elementsSnapshot:l,appStateSnapshot:s,files:o,actionManager:n,onExportImage:r,name:i})})};import ZX from"react";import{getFrame as jX}from"@orangecatai/common";import{jsx as XX}from"react/jsx-runtime";var E1={primary:{base:"var(--color-primary)",darker:"var(--color-primary-darker)",darkest:"var(--color-primary-darkest)"},lime:{base:"#74b816",darker:"#66a80f",darkest:"#5c940d"},pink:{base:"#d6336c",darker:"#c2255c",darkest:"#a61e4d"}},w1=({children:e,color:t})=>XX("div",{className:"Card",style:{"--card-color":E1[t].base,"--card-color-darker":E1[t].darker,"--card-color-darkest":E1[t].darkest},children:e});import{Fragment as JX,jsx as Tn,jsxs as kg}from"react/jsx-runtime";var qX=({elements:e,appState:t,setAppState:o,files:n,actionManager:r,exportOpts:a,canvas:i,onCloseRequest:s})=>{let{onExportToBackend:l}=a;return Tn("div",{className:"ExportDialog ExportDialog--json",children:kg("div",{className:"ExportDialog-cards",children:[a.saveFileToDisk&&kg(w1,{color:"lime",children:[Tn("div",{className:"Card-icon",children:VE}),Tn("h2",{children:f("exportDialog.disk_title")}),kg("div",{className:"Card-details",children:[f("exportDialog.disk_details"),!Wi&&r.renderAction("changeProjectName")]}),Tn(ie,{className:"Card-button",type:"button",title:f("exportDialog.disk_button"),"aria-label":f("exportDialog.disk_button"),showAriaLabel:!0,onClick:()=>{r.executeAction(Ac,"ui")}})]}),l&&kg(w1,{color:"pink",children:[Tn("div",{className:"Card-icon",children:rc}),Tn("h2",{children:f("exportDialog.link_title")}),Tn("div",{className:"Card-details",children:f("exportDialog.link_details")}),Tn(ie,{className:"Card-button",type:"button",title:f("exportDialog.link_button"),"aria-label":f("exportDialog.link_button"),showAriaLabel:!0,onClick:async()=>{try{be("export","link",`ui (${jX()})`),await l(e,t,n),s()}catch(c){o({errorMessage:c.message})}}})]}),a.renderCustomUI&&a.renderCustomUI(e,t,n,i)]})})},X4=({elements:e,appState:t,files:o,actionManager:n,exportOpts:r,canvas:a,setAppState:i})=>{let s=ZX.useCallback(()=>{i({openDialog:null})},[i]);return Tn(JX,{children:t.openDialog?.name==="jsonExport"&&Tn(bt,{onCloseRequest:s,title:f("buttons.export"),children:Tn(qX,{elements:e,appState:t,setAppState:i,files:o,actionManager:n,onCloseRequest:s,exportOpts:r,canvas:a})})})};import QX from"clsx";import{jsx as Z4,jsxs as tZ}from"react/jsx-runtime";var eZ="small",j4=e=>tZ("label",{className:QX("ToolIcon ToolIcon__LaserPointer",`ToolIcon_size_${eZ}`,{"is-mobile":e.isMobile}),title:`${e.title}`,children:[Z4("input",{className:"ToolIcon_type_checkbox",type:"checkbox",name:e.name,onChange:e.onChange,checked:e.checked,"aria-label":e.title,"data-testid":"toolbar-LaserPointer"}),Z4("div",{className:"ToolIcon__icon",children:zn})]});import{Fragment as Q4,jsx as ce,jsxs as Bo}from"react/jsx-runtime";var cZ=({UIOptions:e})=>Bo(jt,{__fallback:!0,children:[ce(jt.DefaultItems.LoadScene,{}),ce(jt.DefaultItems.SaveToActiveFile,{}),e.canvasActions.export&&ce(jt.DefaultItems.Export,{}),e.canvasActions.saveAsImage&&ce(jt.DefaultItems.SaveAsImage,{}),ce(jt.DefaultItems.SearchMenu,{}),ce(jt.DefaultItems.Help,{}),ce(jt.DefaultItems.ClearCanvas,{}),ce(jt.Separator,{}),ce(jt.Group,{title:"Excalidraw links",children:ce(jt.DefaultItems.Socials,{})}),ce(jt.Separator,{}),ce(jt.DefaultItems.ToggleTheme,{}),ce(jt.DefaultItems.ChangeCanvasBackground,{})]}),dZ=()=>Bo(ng,{__fallback:!0,children:[ce(ng.Actions.SaveToDisk,{}),ce(ng.Actions.ExportToImage,{})]}),mZ=({actionManager:e,appState:t,files:o,setAppState:n,elements:r,canvas:a,onLockToggle:i,onHandToolToggle:s,onPenModeToggle:l,showExitZenModeBtn:c,renderTopLeftUI:m,renderTopRightUI:p,renderCustomStats:d,UIOptions:u,onExportImage:h,renderWelcomeScreen:g,children:x,app:E,isCollaborating:y,generateLinkForSelection:w})=>{let v=Te(),C=Dt()==="compact",P=HC(),S=C?{menuTopGap:4,toolbarColGap:4,toolbarRowGap:1,toolbarInnerRowGap:.5,islandPadding:1,collabMarginLeft:8}:{menuTopGap:6,toolbarColGap:4,toolbarRowGap:1,toolbarInnerRowGap:1,islandPadding:1,collabMarginLeft:8},D=P.tunnelsJotai.Provider,[_,k]=le(Yr),M=()=>u.canvasActions.export?ce(X4,{elements:r,appState:t,files:o,actionManager:e,exportOpts:u.canvasActions.export,canvas:a,setAppState:n}):null,B=()=>!u.canvasActions.saveAsImage||t.openDialog?.name!=="imageExport"?null:ce(K4,{elements:r,appState:t,files:o,actionManager:e,onExportImage:h,onCloseRequest:()=>n({openDialog:null}),name:E.getName()}),O=()=>Bo("div",{style:{position:"relative"},children:[ce(P.MainMenuTunnel.Out,{}),g&&ce(P.WelcomeScreenMenuHintTunnel.Out,{})]}),N=()=>{let Q=C;return ce(gd,{heading:"selectedShapeActions",className:Pi("selected-shape-actions zen-mode-transition",{"transition-left":t.zenModeEnabled}),children:Q?ce(gt,{className:Pi("compact-shape-actions-island"),padding:0,style:{maxHeight:`${t.height-166}px`},children:ce(e5,{appState:t,elementsMap:E.scene.getNonDeletedElementsMap(),renderAction:e.renderAction,app:E,setAppState:n})}):ce(gt,{className:nZ.SHAPE_ACTIONS_MENU,padding:2,style:{maxHeight:`${t.height-166}px`},children:ce(ZC,{appState:t,elementsMap:E.scene.getNonDeletedElementsMap(),renderAction:e.renderAction,app:E})})})},z=()=>{let Q=sZ(t,r),Z=t.stats.open&&!t.zenModeEnabled&&!t.viewModeEnabled&&t.openDialog?.name!=="elementLinkSelector";return ce($u,{side:"top",children:Bo("div",{className:"App-menu App-menu_top",children:[Bo(Rt.Col,{gap:S.menuTopGap,className:Pi("App-menu_top__left"),children:[O(),ce("div",{className:Pi("selected-shape-actions-container",{"selected-shape-actions-container--compact":C}),children:Q&&N()})]}),!t.viewModeEnabled&&t.openDialog?.name!=="elementLinkSelector"&&ce(gd,{heading:"shapes",className:"shapes-section",children:U=>Bo("div",{style:{position:"relative"},children:[g&&ce(P.WelcomeScreenToolbarHintTunnel.Out,{}),ce(Rt.Col,{gap:S.toolbarColGap,align:"start",children:Bo(Rt.Row,{gap:S.toolbarRowGap,className:Pi("App-toolbar-container",{"zen-mode":t.zenModeEnabled}),children:[Bo(gt,{padding:S.islandPadding,className:Pi("App-toolbar",{"zen-mode":t.zenModeEnabled,"App-toolbar--compact":C}),children:[ce(U4,{appState:t,isMobile:v.formFactor==="phone",editorInterface:v,app:E}),U,Bo(Rt.Row,{gap:S.toolbarInnerRowGap,children:[ce(Vu,{zenModeEnabled:t.zenModeEnabled,checked:t.penMode,onChange:()=>l(null),title:f("toolBar.penMode"),penDetected:t.penDetected}),ce(j3,{checked:t.activeTool.locked,onChange:i,title:f("toolBar.lock")}),ce("div",{className:"App-toolbar__divider"}),ce(o5,{setAppState:n,activeTool:t.activeTool,UIOptions:u,app:E})]})]}),y&&ce(gt,{style:{marginLeft:S.collabMarginLeft,alignSelf:"center",height:"fit-content"},children:ce(j4,{title:f("toolBar.laser"),checked:t.activeTool.type===q4.laser,onChange:()=>E.setActiveTool({type:q4.laser}),isMobile:!0})})]})})]})}),Bo("div",{className:Pi("layer-ui__wrapper__top-right zen-mode-transition",{"transition-right":t.zenModeEnabled,"layer-ui__wrapper__top-right--compact":C}),children:[t.collaborators.size>0&&ce(ju,{collaborators:t.collaborators,userToFollow:t.userToFollow?.socketId||null}),p?.(v.formFactor==="phone",t),E.props.showLibraryButton===!0&&!t.viewModeEnabled&&t.openDialog?.name!=="elementLinkSelector"&&(!F||t.openSidebar?.name!==v1.name)&&ce(P.DefaultSidebarTriggerTunnel.Out,{}),Z&&ce(Md,{app:E,onClose:()=>{e.executeAction(oa)},renderCustomStats:d})]})]})})},L=()=>ce(ig,{__fallback:!0,onDock:Q=>{be("sidebar",`toggleDock (${Q?"dock":"undock"})`,`(${v.formFactor==="phone"?"mobile":"desktop"})`)}}),F=Ki(xd),$=Bo(Q4,{children:[x,ce(cZ,{UIOptions:u}),ce(ig.Trigger,{__fallback:!0,icon:fv,title:aZ(f("toolBar.library")),onToggle:Q=>{Q&&be("sidebar",`${v1.name} (open)`,`button (${v.formFactor==="phone"?"mobile":"desktop"})`)},tab:v1.defaultTab}),ce(dZ,{}),t.openDialog?.name==="ttd"&&ce(hg,{__fallback:!0}),t.isLoading&&ce(Uu,{delay:250}),t.errorMessage&&ce(N4,{onClose:()=>n({errorMessage:null}),children:t.errorMessage}),_&&v.formFactor!=="phone"&&ce(Rv,{colorPickerType:_.colorPickerType,onCancel:()=>{k(null)},onChange:(Q,Z,U,{altKey:q})=>{if(!(Q!=="elementBackground"&&Q!=="elementStroke"))if(U.length){for(let ae of U)iZ(ae,rZ(r),{[q&&_.swapPreviewOnAlt?Q==="elementBackground"?"strokeColor":"backgroundColor":Q==="elementBackground"?"backgroundColor":"strokeColor"]:Z}),lZ.delete(ae);E.scene.triggerUpdate()}else n(Q==="elementBackground"?{currentItemBackgroundColor:Z}:{currentItemStrokeColor:Z})},onSelect:(Q,Z)=>{k(U=>U?.keepOpenOnAlt&&Z.altKey?U:null),_?.onSelect?.(Q,Z)}}),t.openDialog?.name==="help"&&ce(O4,{onClose:()=>{n({openDialog:null})}}),ce(l5,{}),t.openDialog?.name==="elementLinkSelector"&&ce(R4,{sourceElementId:t.openDialog.sourceElementId,onClose:()=>{n({openDialog:null})},scene:E.scene,appState:t,generateLinkForSelection:w}),ce(P.OverwriteConfirmDialogTunnel.Out,{}),B(),M(),t.pasteDialog.shown&&ce(aS,{setAppState:n,appState:t,onClose:()=>n({pasteDialog:{shown:!1,data:null}})}),v.formFactor==="phone"&&ce(nS,{app:E,appState:t,elements:r,actionManager:e,renderJSONExportDialog:M,renderImageExportDialog:B,setAppState:n,onHandToolToggle:s,onPenModeToggle:l,renderTopLeftUI:m,renderTopRightUI:p,renderSidebars:L,renderWelcomeScreen:g,UIOptions:u}),v.formFactor!=="phone"&&Bo(Q4,{children:[Bo("div",{className:"layer-ui__wrapper",style:t.openSidebar&&F&&v.canFitSidebar?{width:"calc(100% - var(--right-sidebar-width))"}:{},children:[g&&ce(P.WelcomeScreenCenterTunnel.Out,{}),z(),ce(uS,{appState:t,actionManager:e,showExitZenModeBtn:c,renderWelcomeScreen:g}),t.scrolledOutside&&ce("button",{type:"button",className:"scroll-back-to-content",onClick:()=>{n(Q=>({...Ha(r,Q)}))},children:f("buttons.scrollBackToContent")})]}),L()]})]});return ce(jh.Provider,{value:t,children:ce(D,{children:ce(qb.Provider,{value:P,children:$})})})},J4=e=>{let{startBoundElement:t,cursorButton:o,scrollX:n,scrollY:r,...a}=e;return a},pZ=(e,t)=>{if(e.children!==t.children)return!1;let{canvas:o,appState:n,...r}=e,{canvas:a,appState:i,...s}=t;return Sg(J4(n),J4(i),{selectedElementIds:Sg,selectedGroupIds:Sg})&&Sg(r,s)},eP=oZ.memo(mZ,pZ);import uZ from"clsx";import{jsx as tP,jsxs as hZ}from"react/jsx-runtime";var gZ="small",Mg=e=>hZ("label",{className:uZ("ToolIcon ToolIcon__MagicButton",`ToolIcon_size_${gZ}`,{"is-mobile":e.isMobile}),title:`${e.title}`,children:[tP("input",{className:"ToolIcon_type_checkbox",type:"checkbox",name:e.name,onChange:e.onChange,checked:e.checked,"aria-label":e.title}),tP("div",{className:"ToolIcon__icon",children:e.icon})]});import{useEffect as fZ,useRef as bZ}from"react";import{jsx as oP}from"react/jsx-runtime";var nP=({trails:e})=>{let t=bZ(null);return fZ(()=>{if(t.current)for(let o of e)o.start(t.current);return()=>{for(let o of e)o.stop()}},e),oP("div",{className:"SVGLayer",children:oP("svg",{ref:t})})};import tj,{useEffect as oj,useRef as EP}from"react";import{CURSOR_TYPE as wP,isShallowEqual as nj,sceneCoordsToViewportCoords as rj}from"@orangecatai/common";var Ht=class Ht{static start(t,o){let n=o({deltaTime:0,state:void 0});n&&(Ht.animations.set(t,{animation:o,lastTime:0,state:n}),Ht.isRunning||(Ht.isRunning=!0,wi()?requestAnimationFrame(Ht.tick):setTimeout(Ht.tick,0)))}static tick(){if(Ht.animations.size>0){for(let[t,o]of Ht.animations){let n=performance.now(),r=o.lastTime===0?0:n-o.lastTime,a=o.animation({deltaTime:r,state:o.state});if(a)o.lastTime=n,o.state=a;else if(Ht.animations.delete(t),Ht.animations.size===0){Ht.isRunning=!1;return}}wi()?requestAnimationFrame(Ht.tick):setTimeout(Ht.tick,0)}}static running(t){return Ht.animations.has(t)}static cancel(t){Ht.animations.delete(t)}};A(Ht,"isRunning",!1),A(Ht,"animations",new Map);var Ld=Ht;import{clamp as k1,pointFrom as Ll,pointsEqual as TZ,bezierEquation as hP,pointRotateRads as Pg,pointDistance as CZ}from"@orangecatai/math";import{arrayToMap as kZ,BIND_MODE_TIMEOUT as _d,DEFAULT_TRANSFORM_HANDLE_SPACING as A1,FRAME_STYLE as sn,getFeatureFlag as SZ,invariant as lP,THEME as Ma}from"@orangecatai/common";import{deconstructDiamondElement as S1,deconstructRectanguloidElement as fP,elementCenterPoint as _l,getDiamondBaseCorners as MZ,FOCUS_POINT_SIZE as PZ,getOmitSidesForEditorInterface as I1,getTransformHandles as AZ,getTransformHandlesFromCoords as LZ,hasBoundingBox as _Z,hitElementItself as DZ,isArrowElement as RZ,isBindableElement as bP,isElbowArrow as Dl,isFrameLikeElement as Rl,isImageElement as cP,isLinearElement as NZ,isLineElement as BZ,maxBindingDistance_simple as FZ,isTextElement as dP,LinearElementEditor as nr}from"@orangecatai/element";import{renderSelectionElement as OZ}from"@orangecatai/element";import{getElementsInGroup as M1,getSelectedGroupIds as zZ,isSelectedViaGroup as HZ,selectGroupsFromGivenElements as GZ}from"@orangecatai/element";import{getCommonBounds as P1,getElementAbsoluteCoords as Ag}from"@orangecatai/element";import{getGlobalFixedPointForBindableElement as mP,isFocusPointVisible as UZ}from"@orangecatai/element";import{pointFrom as qt}from"@orangecatai/math";import{THEME as xZ}from"@orangecatai/common";var yZ="#ff6b6b",EZ="#ff0000",rP=1,aP=2,iP=(e,t)=>{if(!t.snapLines.length)return;let o=t.theme===xZ.LIGHT||t.zenModeEnabled?yZ:EZ,n=(t.zenModeEnabled?rP*1.5:rP)/t.zoom.value;e.save(),e.translate(t.scrollX,t.scrollY);for(let r of t.snapLines)r.type==="pointer"?(e.lineWidth=n,e.strokeStyle=o,vZ(r,e,t)):r.type==="gap"?(e.lineWidth=n,e.strokeStyle=o,IZ(r.points[0],r.points[1],r.direction,t,e)):r.type==="points"&&(e.lineWidth=n,e.strokeStyle=o,wZ(r,e,t));e.restore()},wZ=(e,t,o)=>{if(!o.zenModeEnabled){let n=e.points[0],r=e.points[e.points.length-1];an(n,r,t)}for(let n of e.points)sP(n,o,t)},vZ=(e,t,o)=>{sP(e.points[0],o,t),o.zenModeEnabled||an(e.points[0],e.points[1],t)},sP=([e,t],o,n)=>{n.save();let r=(o.zenModeEnabled?aP*1.5:aP)/o.zoom.value;n.beginPath(),n.moveTo(e-r,t-r),n.lineTo(e+r,t+r),n.moveTo(e+r,t-r),n.lineTo(e-r,t+r),n.stroke(),n.restore()},an=(e,t,o)=>{o.beginPath(),o.lineTo(e[0],e[1]),o.lineTo(t[0],t[1]),o.stroke()},IZ=(e,t,o,n,r)=>{let a=8/n.zoom.value,i=a/2,s=a/4;if(o==="horizontal"){let l=[(e[0]+t[0])/2,e[1]];n.zenModeEnabled||an(qt(e[0],e[1]-a),qt(e[0],e[1]+a),r),an(qt(l[0]-s,l[1]-i),qt(l[0]-s,l[1]+i),r),an(qt(l[0]+s,l[1]-i),qt(l[0]+s,l[1]+i),r),n.zenModeEnabled||(an(qt(t[0],t[1]-a),qt(t[0],t[1]+a),r),an(e,t,r))}else{let l=[e[0],(e[1]+t[1])/2];n.zenModeEnabled||an(qt(e[0]-a,e[1]),qt(e[0]+a,e[1]),r),an(qt(l[0]-i,l[1]-s),qt(l[0]+i,l[1]-s),r),an(qt(l[0]-i,l[1]+s),qt(l[0]+i,l[1]+s),r),n.zenModeEnabled||(an(qt(t[0]-a,t[1]),qt(t[0]+a,t[1]),r),an(e,t,r))}};var WZ=(e,t)=>{lP(t.selectedLinearElement,"selectedLinearElement is null");let{segmentMidPointHoveredCoords:o}=t.selectedLinearElement;lP(o,"midPointCoords is null"),e.save(),e.translate(t.scrollX,t.scrollY),L1(o,e,t),e.restore()},YZ=(e,t,o)=>{let{elementId:n,hoverPointIndex:r}=t.selectedLinearElement;if(t.selectedLinearElement?.isEditing&&t.selectedLinearElement?.selectedPointsIndices?.includes(r)||t.selectedLinearElement?.isDragging)return;let a=nr.getElement(n,o);if(!a)return;let i=nr.getPointAtIndexGlobalCoordinates(a,r,o);e.save(),e.translate(t.scrollX,t.scrollY),L1(i,e,t),e.restore()},L1=(e,t,o)=>{t.fillStyle="rgba(105, 101, 219, 0.4)",ql(t,e[0],e[1],nr.POINT_HANDLE_SIZE/o.zoom.value,!1)},$Z=(e,t,o)=>{e.save(),e.translate(t.scrollX,t.scrollY),L1(o,e,t),e.restore()},T1=(e,t,o,n,r,a,i)=>{e.strokeStyle="#5e5ad8",e.setLineDash([]),e.fillStyle="rgba(255, 255, 255, 0.9)",r?e.fillStyle="rgba(134, 131, 226, 0.9)":a&&(e.fillStyle="rgba(177, 151, 252, 0.7)"),ql(e,o[0],o[1],(i?n*(t.selectedLinearElement?.isEditing?1.5:2):n)/t.zoom.value,!a,!i||r)},VZ=(e,t,o,n,r)=>{let a=t.element.frameId&&o.get(t.element.frameId);switch(a&&Rl(a)&&(e.translate(a.x,a.y),e.beginPath(),sn.radius&&e.roundRect?e.roundRect(-1,-1,a.width+1,a.height+1,sn.radius/n.zoom.value):e.rect(-1,-1,a.width+1,a.height+1),e.clip(),e.translate(-a.x,-a.y)),t.element.type){case"magicframe":case"frame":e.save(),e.translate(t.element.x,t.element.y),e.lineWidth=sn.strokeWidth/n.zoom.value,e.strokeStyle=n.theme===Ma.DARK?"rgba(3, 93, 161, 1)":"rgba(106, 189, 252, 1)",sn.radius&&e.roundRect?(e.beginPath(),e.roundRect(0,0,t.element.width,t.element.height,sn.radius/n.zoom.value),e.stroke(),e.closePath()):e.strokeRect(0,0,t.element.width,t.element.height),e.restore();break;default:e.save();let i=_l(t.element,o);switch(e.translate(i[0],i[1]),e.rotate(t.element.angle),e.translate(-i[0],-i[1]),e.translate(t.element.x,t.element.y),e.lineWidth=k1(1.75,t.element.strokeWidth,4)/Math.max(.25,n.zoom.value),e.strokeStyle=n.theme===Ma.DARK?"rgba(3, 93, 161, 1)":"rgba(106, 189, 252, 1)",t.element.type){case"ellipse":e.beginPath(),e.ellipse(t.element.width/2,t.element.height/2,t.element.width/2,t.element.height/2,0,0,2*Math.PI),e.closePath(),e.stroke();break;case"diamond":{let[s,l]=S1(t.element);s.forEach(c=>{e.beginPath(),e.moveTo(c[0][0]-t.element.x,c[0][1]-t.element.y),e.lineTo(c[1][0]-t.element.x,c[1][1]-t.element.y),e.stroke()}),l.forEach(c=>{let[m,p,d,u]=c;e.beginPath(),e.moveTo(m[0]-t.element.x,m[1]-t.element.y),e.bezierCurveTo(p[0]-t.element.x,p[1]-t.element.y,d[0]-t.element.x,d[1]-t.element.y,u[0]-t.element.x,u[1]-t.element.y),e.stroke()})}break;default:{let[s,l]=fP(t.element);s.forEach(c=>{e.beginPath(),e.moveTo(c[0][0]-t.element.x,c[0][1]-t.element.y),e.lineTo(c[1][0]-t.element.x,c[1][1]-t.element.y),e.stroke()}),l.forEach(c=>{let[m,p,d,u]=c;e.beginPath(),e.moveTo(m[0]-t.element.x,m[1]-t.element.y),e.bezierCurveTo(p[0]-t.element.x,p[1]-t.element.y,d[0]-t.element.x,d[1]-t.element.y,u[0]-t.element.x,u[1]-t.element.y),e.stroke()})}break}e.restore();break}if(Rl(t.element)||bP(t.element)){let i=n.selectedLinearElement,s=i?.elementId&&nr.getElement(i?.elementId,o),l=r&&DZ({point:r,element:t.element,elementsMap:o,threshold:0,overrideShouldTestInside:!0}),c=s&&Dl(s)||n.activeTool.type==="arrow"&&n.currentItemArrowType==="elbow";if(!l||c){e.save();let m=_l(t.element,o),p;if(t.element.type==="diamond"){let g=_l(t.element,o);p=MZ(t.element).map(x=>{let E=hP(x,.5),y=Pg(E,g,t.element.angle);return Ll(y[0],y[1])})}else p=[{x:t.element.width,y:t.element.height/2},{x:t.element.width/2,y:t.element.height},{x:0,y:t.element.height/2},{x:t.element.width/2,y:0}].map(x=>{let E=Ll(x.x+t.element.x,x.y+t.element.y),y=Pg(E,m,t.element.angle);return Ll(y[0],y[1])});let d=r&&p.reduce((g,x,E)=>{let y=CZ(x,r);return E===-1||y<g.distance?{idx:E,distance:y}:g},{idx:-1,distance:1/0}),u=4/n.zoom.value,h=FZ(n.zoom)+t.element.strokeWidth/2;p.forEach((g,x)=>{let E=(!l||c)&&d?.idx===x&&d.distance<=h,y=!E&&(c||x===d?.idx&&d.distance<=h*2);E?(e.fillStyle=n.theme===Ma.DARK?"rgba(3, 93, 161, 1)":"rgba(106, 189, 252, 1)",e.beginPath(),e.arc(g[0],g[1],u,0,2*Math.PI),e.fill()):y&&(e.fillStyle=n.theme===Ma.DARK?"rgba(0, 0, 0, 0.8)":"rgba(65, 65, 65, 0.5)",e.beginPath(),e.arc(g[0],g[1],u,0,2*Math.PI),e.fill())}),e.restore()}}},KZ=(e,t,o,n,r,a,i)=>{let s=e.state.bindMode==="orbit"&&e.bindModeHandler!==null,l=_d-(i?.runtime??(s?0:_d)),c=k1(1/_d*l,1e-4,1),m=o.strokeWidth/2,p=o.frameId&&n.get(o.frameId);switch(p&&Rl(p)&&(t.translate(p.x,p.y),t.beginPath(),sn.radius&&t.roundRect?t.roundRect(-1,-1,p.width+1,p.height+1,sn.radius/r.zoom.value):t.rect(-1,-1,p.width+1,p.height+1),t.clip(),t.translate(-p.x,-p.y)),o.type){case"magicframe":case"frame":t.save(),t.translate(o.x,o.y),t.lineWidth=sn.strokeWidth/r.zoom.value,t.strokeStyle=r.theme===Ma.DARK?`rgba(3, 93, 161, ${c})`:`rgba(106, 189, 252, ${c})`,sn.radius&&t.roundRect?(t.beginPath(),t.roundRect(0,0,o.width,o.height,sn.radius/r.zoom.value),t.stroke(),t.closePath()):t.strokeRect(0,0,o.width,o.height),t.restore();break;default:t.save();let u=_l(o,n),h=u[0]+r.scrollX,g=u[1]+r.scrollY;switch(t.translate(h,g),t.rotate(o.angle),t.translate(-h,-g),t.translate(o.x+r.scrollX-m,o.y+r.scrollY-m),t.lineWidth=k1(2.5,o.strokeWidth*1.75,4)/Math.max(.25,r.zoom.value),t.strokeStyle=r.theme===Ma.DARK?`rgba(3, 93, 161, ${c/2})`:`rgba(106, 189, 252, ${c/2})`,o.type){case"ellipse":t.beginPath(),t.ellipse((o.width+m*2)/2,(o.height+m*2)/2,(o.width+m*2)/2,(o.height+m*2)/2,0,0,2*Math.PI),t.closePath(),t.stroke();break;case"diamond":{let[x,E]=S1(o,m);x.forEach(y=>{t.beginPath(),t.moveTo(y[0][0]-o.x+m,y[0][1]-o.y+m),t.lineTo(y[1][0]-o.x+m,y[1][1]-o.y+m),t.stroke()}),E.forEach(y=>{let[w,v,I,C]=y;t.beginPath(),t.moveTo(w[0]-o.x+m,w[1]-o.y+m),t.bezierCurveTo(v[0]-o.x+m,v[1]-o.y+m,I[0]-o.x+m,I[1]-o.y+m,C[0]-o.x+m,C[1]-o.y+m),t.stroke()})}break;default:{let[x,E]=fP(o,m);x.forEach(y=>{t.beginPath(),t.moveTo(y[0][0]-o.x+m,y[0][1]-o.y+m),t.lineTo(y[1][0]-o.x+m,y[1][1]-o.y+m),t.stroke()}),E.forEach(y=>{let[w,v,I,C]=y;t.beginPath(),t.moveTo(w[0]-o.x+m,w[1]-o.y+m),t.bezierCurveTo(v[0]-o.x+m,v[1]-o.y+m,I[0]-o.x+m,I[1]-o.y+m,C[0]-o.x+m,C[1]-o.y+m),t.stroke()})}break}t.restore();break}if(!s||(i?.runtime??0)>_d)return;let d=.5*(Math.min(o.width,o.height)/2);if(!Rl(o)){t.save(),t.translate(o.x+r.scrollX,o.y+r.scrollY);let u=1/_d*l;t.strokeStyle="rgba(0, 0, 0, 0.2)",t.lineWidth=1/r.zoom.value,t.setLineDash([4/r.zoom.value,4/r.zoom.value]),t.lineDashOffset=-u*10/r.zoom.value,t.beginPath(),t.ellipse(o.width/2,o.height/2,d,d,0,0,2*Math.PI),t.stroke(),t.fillStyle="rgba(0, 0, 0, 0.04)",t.beginPath(),t.ellipse(o.width/2,o.height/2,d*(1-c),d*(1-c),0,0,2*Math.PI),t.fill(),t.restore(),t.save(),t.translate(o.x+r.scrollX,o.y+r.scrollY);let h=5/r.zoom.value,g=5/r.zoom.value,x=h+g,E;if(o.type==="diamond"){let[,y]=S1(o),w=_l(o,n);E=y.map(v=>{let I=hP(v,.5),C=Pg(I,w,o.angle);return{x:C[0]-o.x,y:C[1]-o.y}})}else{let y=_l(o,n);E=[{x:o.width/2,y:0},{x:o.width,y:o.height/2},{x:o.width/2,y:o.height},{x:0,y:o.height/2}].map(v=>{let I=Ll(v.x+o.x,v.y+o.y),C=Pg(I,y,o.angle);return{x:C[0]-o.x,y:C[1]-o.y}})}E.forEach(y=>{t.clearRect(y.x-x,y.y-x,x*2,x*2)}),t.fillStyle=r.theme===Ma.DARK?`rgba(3, 93, 161, ${c})`:`rgba(106, 189, 252, ${c})`,E.forEach(y=>{t.beginPath(),t.arc(y.x,y.y,h,0,2*Math.PI),t.fill()}),t.restore()}return{runtime:(i?.runtime??0)+a}},XZ=(e,t,o,n,r,a,i)=>{if(o===null)return;if(SZ("COMPLEX_BINDINGS"))return KZ(e,t,o.element,n,r,a,i);t.save(),t.translate(r.scrollX,r.scrollY);let s=e.lastPointerMoveCoords?Ll(e.lastPointerMoveCoords.x,e.lastPointerMoveCoords.y):null;VZ(t,o,n,r,s),t.restore()},xP=(e,t,o)=>{let{angle:n,x1:r,y1:a,x2:i,y2:s,selectionColors:l,cx:c,cy:m,dashed:p,activeEmbeddable:d}=o,u=i-r,h=s-a,x=(o.padding??A1*2)/t.zoom.value,E=8/t.zoom.value,y=4/t.zoom.value;e.save(),e.translate(t.scrollX,t.scrollY),e.lineWidth=(d?4:1)/t.zoom.value;let w=l.length;for(let v=0;v<w;++v)e.strokeStyle=l[v],p&&e.setLineDash([E,y+(E+y)*(w-1)]),e.lineDashOffset=(E+y)*v,Jl(e,r-x,a-x,u+x*2,h+x*2,c,m,n);e.restore()},ZZ=(e,t,o,n)=>{let[r,a,i,s]=Ag(o,n),l=i-r,c=s-a;e.strokeStyle="rgb(0,118,255)",e.lineWidth=sn.strokeWidth/t.zoom.value,e.save(),e.translate(t.scrollX,t.scrollY),Jl(e,r,a,l,c,r+l/2,a+c/2,o.angle,!1,sn.radius/t.zoom.value),e.restore()},pP=(e,t,o,n)=>{let{colors:r=["rgb(0,118,255)"],dashed:a=!1}=n||{},i=o.filter(m=>m.groupIds.length===0),s=o.filter(m=>m.groupIds.length>0),l=m=>{let[p,d,u,h]=P1(m);return{angle:0,x1:p,x2:u,y1:d,y2:h,selectionColors:r,dashed:a,cx:p+(u-p)/2,cy:d+(h-d)/2,activeEmbeddable:!1}},c=m=>{let p=M1(o,m);return l(p)};Object.entries(GZ(s,t)).filter(([m,p])=>p).map(([m,p])=>m).map(m=>c(m)).concat(i.map(m=>l([m]))).forEach(m=>xP(e,t,m))},C1=(e,t,o,n)=>{if(!t.selectedLinearElement)return;e.save(),e.translate(t.scrollX,t.scrollY),e.lineWidth=1/t.zoom.value;let r=nr.getPointsGlobalCoordinates(o,n),{POINT_HANDLE_SIZE:a}=nr,i=t.selectedLinearElement?.isEditing?a:a/2,s=Dl(o),l=BZ(o);if(r.forEach((c,m)=>{if(s&&m!==0&&m!==r.length-1)return;let p=m>0&&(m!==r.length-1||!l||!o.polygon)&&TZ(c,m===r.length-1?r[0]:r[m-1],2/t.zoom.value),d=!!t.selectedLinearElement?.isEditing&&!!t.selectedLinearElement?.selectedPointsIndices?.includes(m);l&&o.polygon&&!d&&m===o.points.length-1&&t.selectedLinearElement?.isEditing&&t.selectedLinearElement?.selectedPointsIndices?.includes(0)&&(d=!0),T1(e,t,c,i,d,!1,p)}),Dl(o)){let c=o.fixedSegments?.map(m=>m.index)||[];r.slice(0,-1).forEach((m,p)=>{nr.isSegmentTooShort(o,r[p+1],r[p],p,t.zoom)||T1(e,t,Ll((m[0]+r[p+1][0])/2,(m[1]+r[p+1][1])/2),a/2,!1,!c.includes(p+1),!1)})}else nr.getEditorMidPoints(o,n,t).filter((m,p,d)=>m!==null&&!(Dl(o)&&(p===0||p===d.length-1))).forEach(m=>{(t.selectedLinearElement?.isEditing||r.length===2)&&T1(e,t,m,a/2,!1,!0,!1)});e.restore()},jZ=(e,t,o,n)=>{e.save(),e.translate(t.scrollX,t.scrollY),e.strokeStyle="rgba(134, 131, 226, 0.6)",e.lineWidth=1/t.zoom.value,e.setLineDash([4/t.zoom.value,4/t.zoom.value]),e.beginPath(),e.moveTo(o[0],o[1]),e.lineTo(n[0],n[1]),e.stroke(),e.restore()},qZ=(e,t,o,n,r)=>{e.save(),e.translate(t.scrollX,t.scrollY),e.strokeStyle="rgba(134, 131, 226, 0.6)",e.lineWidth=1/t.zoom.value,e.setLineDash([]),e.fillStyle=r?"rgba(134, 131, 226, 0.9)":"rgba(255, 255, 255, 0.9)",ql(e,o[0],o[1],n/t.zoom.value,!0,!0),e.restore()},uP=({arrow:e,appState:t,type:o,context:n,elementsMap:r})=>{let a=o==="start"?e.startBinding:e.endBinding,i=a?.elementId&&r.get(a.elementId);if(!i||!bP(i)||i.isDeleted)return;let s=mP(a.fixedPoint,i,r);if(!UZ(s,e,i,r,t,o))return;let l=t.selectedLinearElement,c=!!l?.isDragging,m=o==="start"?0:e.points.length-1,p=!!l?.selectedPointsIndices?.includes(m);if(l?.hoveredFocusPointBinding===o&&!l.draggedFocusPointBinding&&$Z(n,t,s),!(p&&c)){let d=mP(a.fixedPoint,i,r),u=l?.hoveredFocusPointBinding===o,h=nr.getPointAtIndexGlobalCoordinates(e,m,r);jZ(n,t,h,d),qZ(n,t,d,PZ/1.5,u)}},gP=(e,t,o,n,r)=>{Object.keys(n).forEach(a=>{let i=n[a];if(i!==void 0){let[s,l,c,m]=i;e.save(),e.lineWidth=1/o.zoom.value,t.selectionColor&&(e.strokeStyle=t.selectionColor),a==="rotation"?ql(e,s+c/2,l+m/2,c/2,!0):e.roundRect?(e.beginPath(),e.roundRect(s,l,c,m,2/o.zoom.value),e.fill(),e.stroke()):Jl(e,s,l,c,m,s+c/2,l+m/2,r,!0),e.restore()}})},JZ=(e,t,o,n,r)=>{let[a,i,,,s,l]=Ag(n,r),c=3,m=20,p=c/o.zoom.value,d=p/2,u=s-a+p,h=l-i+p,g=Math.min(m/o.zoom.value,u),x=Math.min(m/o.zoom.value,h);e.save(),e.fillStyle=t.selectionColor,e.strokeStyle=t.selectionColor,e.lineWidth=p,[[[-u,-h],[0,d],[g,d],[d,0],[d,x]],[[u-d,-h],[d,d],[-g+d,d],[0,0],[0,x]],[[-u,h],[0,-d],[g,-d],[d,0],[d,-x]],[[u-d,h],[d,-d],[-g+d,-d],[0,0],[0,-x]]].forEach(y=>{let[[w,v],[I,C],[P,S],[D,_],[k,M]]=y;e.save(),e.translate(s,l),e.rotate(n.angle),e.beginPath(),e.moveTo(w+I,v+C),e.lineTo(w+P,v+S),e.stroke(),e.beginPath(),e.moveTo(w+D,v+_),e.lineTo(w+k,v+M),e.stroke(),e.restore()}),e.restore()},QZ=(e,t,o,n)=>{t.save();let r=A1*2/o.zoom.value,a=e.width+r*2,i=e.height+r*2,s=e.x+a/2,l=e.y+i/2,c=-(a/2+r),m=-(i/2+r);t.translate(s+o.scrollX,l+o.scrollY),t.rotate(e.angle),t.lineWidth=1/o.zoom.value,t.strokeStyle=n,t.strokeRect(c,m,a,i),t.restore()},ej=({app:e,canvas:t,elementsMap:o,visibleElements:n,selectedElements:r,allElementsMap:a,scale:i,appState:s,renderConfig:l,editorInterface:c,animationState:m,deltaTime:p})=>{if(t===null)return{atLeastOneVisibleElement:!1,elementsMap:o};let[d,u]=am(t,i),h=m,g=im({canvas:t,scale:i,normalizedWidth:d,normalizedHeight:u});g.save(),g.scale(s.zoom.value,s.zoom.value);let x;if(n.forEach(I=>{s.selectedLinearElement?.isEditing&&s.selectedLinearElement.elementId===I.id&&I&&(x=I)}),x&&C1(g,s,x,o),s.selectionElement&&!s.isCropping)try{OZ(s.selectionElement,g,s,l.selectionColor)}catch(I){console.error(I)}if(s.editingTextElement&&dP(s.editingTextElement)){let I=a.get(s.editingTextElement.id);I&&!I.autoResize&&QZ(I,g,s,l.selectionColor)}if(s.isBindingEnabled&&s.suggestedBinding?h={...m,bindingHighlight:XZ(e,g,s.suggestedBinding,a,s,p,m?.bindingHighlight)}:h={...m,bindingHighlight:void 0},s.frameToHighlight&&ZZ(g,s,s.frameToHighlight,o),s.elementsToHighlight&&pP(g,s,s.elementsToHighlight),s.activeLockedId){let I=a.get(s.activeLockedId),C=I?[I]:M1(a,s.activeLockedId);pP(g,s,C,{colors:["#ced4da"],dashed:!0})}let E=r.some(I=>Rl(I));r.length===1&&s.selectedLinearElement?.isEditing&&s.selectedLinearElement.elementId===r[0].id&&C1(g,s,r[0],o);let y=s.selectedLinearElement,w=y&&nr.getElement(y.elementId,a);if(w&&(s.selectedLinearElement.isDragging||(y.segmentMidPointHoveredCoords?WZ(g,s):(Dl(w)?y.hoverPointIndex===0||y.hoverPointIndex===w.points.length-1:y.hoverPointIndex>=0)&&YZ(g,s,o)),RZ(w)&&(uP({arrow:w,elementsMap:a,appState:s,context:g,type:"start"}),uP({arrow:w,elementsMap:a,appState:s,context:g,type:"end"}))),!s.multiElement&&!s.newElement&&!s.selectedLinearElement?.isEditing){let I=_Z(r,s,c),C=r.length===1&&NZ(r[0]);C&&s.selectedLinearElement?.elementId===r[0].id&&!r[0].locked&&C1(g,s,r[0],o);let P=l.selectionColor||"#000";if(I){let S=kZ(r),D=[];for(let k of o.values()){let M=[],B=l.remoteSelectedElementIds.get(k.id);if(C&&Dl(k)&&(k.startBinding||k.endBinding)||(S.has(k.id)&&!HZ(s,k)&&M.push(P),B&&M.push(...B.map(O=>ni(O,s.collaborators.get(O))))),M.length){let[O,N,z,L,F,$]=Ag(k,o,!0);D.push({angle:k.angle,x1:O,y1:N,x2:z,y2:L,selectionColors:k.locked?["#ced4da"]:M,dashed:!!B||k.locked,cx:F,cy:$,activeEmbeddable:s.activeEmbeddable?.element===k&&s.activeEmbeddable.state==="active",padding:k.id===s.croppingElementId||cP(k)?0:void 0})}}let _=k=>{let M=M1(o,k),[B,O,N,z]=P1(M);D.push({angle:0,x1:B,x2:N,y1:O,y2:z,selectionColors:M.some(L=>L.locked)?["#ced4da"]:["#000"],dashed:!0,cx:B+(N-B)/2,cy:O+(z-O)/2,activeEmbeddable:!1})};for(let k of zZ(s))_(k);s.editingGroupId&&_(s.editingGroupId),D.forEach(k=>xP(g,s,k))}if(g.save(),g.translate(s.scrollX,s.scrollY),r.length===1){g.fillStyle="#fff";let S=AZ(r[0],s.zoom,o,"mouse",I1(c));if(!s.viewModeEnabled&&I&&!dP(s.editingTextElement)&&!s.croppingElementId&&gP(g,l,s,S,r[0].angle),s.croppingElementId&&!s.isCropping){let D=o.get(s.croppingElementId);D&&cP(D)&&JZ(g,l,s,D,o)}}else if(r.length>1&&!s.isRotating&&!r.some(S=>S.locked)){let S=A1*2/s.zoom.value;g.fillStyle="#fff";let[D,_,k,M]=P1(r,o),B=g.getLineDash();g.setLineDash([2/s.zoom.value]);let O=g.lineWidth;g.lineWidth=1/s.zoom.value,g.strokeStyle=P,Jl(g,D-S,_-S,k-D+S*2,M-_+S*2,(D+k)/2,(_+M)/2,0),g.lineWidth=O,g.setLineDash(B);let N=LZ([D,_,k,M,(D+k)/2,(_+M)/2],0,s.zoom,"mouse",E?{...I1(c),rotation:!0}:I1(c));r.some(z=>!z.locked)&&gP(g,l,s,N,0)}g.restore()}s.searchMatches?.matches.forEach(({id:I,focus:C,matchedLines:P})=>{let S=o.get(I);if(S){let[D,_,,,k,M]=Ag(S,o,!0);g.save(),s.theme===Ma.LIGHT?C?g.fillStyle="rgba(255, 124, 0, 0.4)":g.fillStyle="rgba(255, 226, 0, 0.4)":C?g.fillStyle="rgba(229, 82, 0, 0.4)":g.fillStyle="rgba(99, 52, 0, 0.4)";let B=Rl(S)?s.zoom.value:1;g.translate(s.scrollX,s.scrollY),g.translate(k,M),g.rotate(S.angle),P.forEach(O=>{(O.showOnCanvas||C)&&g.fillRect(D+O.offsetX/B-k,_+O.offsetY/B-M,O.width/B,O.height/B)}),g.restore()}}),iP(g,s),g.restore(),SI({context:g,renderConfig:l,appState:s,normalizedWidth:d,normalizedHeight:u});let v;return l.renderScrollbars&&(v=T3(o,d,u,s),g.save(),g.fillStyle=I3,g.strokeStyle="rgba(255,255,255,0.8)",[v.horizontal,v.vertical].forEach(I=>{I&&gp(g,I.x,I.y,I.width,I.height,Jo/2)}),g.restore()),{scrollBars:v,atLeastOneVisibleElement:n.length>0,elementsMap:o,animationState:h}},yP=e=>{let t=ej(e);return e.callback(t),t};import{jsx as sj}from"react/jsx-runtime";var vP="animateInteractiveScene",aj=e=>{let t=EP(!1),o=EP(null);return oj(()=>{if(!t.current){t.current=!0;return}let n=new Map,r=new Map,a=new Map,i=new Map,s=new Map;e.appState.collaborators.forEach((c,m)=>{if(c.selectedElementIds)for(let p of Object.keys(c.selectedElementIds))a.has(p)||a.set(p,[]),a.get(p).push(m);!c.pointer||c.pointer.renderCursor===!1||(c.username&&i.set(m,c.username),c.userState&&s.set(m,c.userState),r.set(m,rj({sceneX:c.pointer.x,sceneY:c.pointer.y},e.appState)),n.set(m,c.button))});let l=e.containerRef?.current&&getComputedStyle(e.containerRef.current).getPropertyValue("--color-selection")||"#6965db";o.current={app:e.app,canvas:e.canvas,elementsMap:e.elementsMap,visibleElements:e.visibleElements,selectedElements:e.selectedElements,allElementsMap:e.allElementsMap,scale:window.devicePixelRatio,appState:e.appState,renderConfig:{remotePointerViewportCoords:r,remotePointerButton:n,remoteSelectedElementIds:a,remotePointerUsernames:i,remotePointerUserStates:s,selectionColor:l,renderScrollbars:e.renderScrollbars,lastViewportPosition:e.app.lastViewportPosition},editorInterface:e.editorInterface,callback:e.renderInteractiveSceneCallback,animationState:{bindingHighlight:void 0},deltaTime:0},Ld.running(vP)||Ld.start(vP,({deltaTime:c,state:m})=>{let p=yP({...o.current,deltaTime:c,animationState:m}).animationState;if(p){for(let d in p)if(p[d]!==void 0)return p}})}),sj("canvas",{className:"excalidraw__canvas interactive",style:{width:e.appState.width,height:e.appState.height,cursor:e.appState.viewModeEnabled&&e.appState.activeTool.type!=="laser"?wP.GRAB:wP.AUTO},width:e.appState.width*e.scale,height:e.appState.height*e.scale,ref:e.handleCanvasRef,onContextMenu:e.onContextMenu,onPointerMove:e.onPointerMove,onPointerUp:e.onPointerUp,onPointerCancel:e.onPointerCancel,onTouchMove:e.onTouchMove,onPointerDown:e.onPointerDown,onDoubleClick:e.appState.viewModeEnabled?void 0:e.onDoubleClick,children:f("labels.drawingCanvas")})},IP=e=>({zoom:e.zoom,scrollX:e.scrollX,scrollY:e.scrollY,width:e.width,height:e.height,viewModeEnabled:e.viewModeEnabled,activeTool:e.activeTool,openDialog:e.openDialog,editingGroupId:e.editingGroupId,selectedElementIds:e.selectedElementIds,frameToHighlight:e.frameToHighlight,offsetLeft:e.offsetLeft,offsetTop:e.offsetTop,theme:e.theme,selectionElement:e.selectionElement,selectedGroupIds:e.selectedGroupIds,selectedLinearElement:e.selectedLinearElement,multiElement:e.multiElement,newElement:e.newElement,isBindingEnabled:e.isBindingEnabled,suggestedBinding:e.suggestedBinding,isRotating:e.isRotating,elementsToHighlight:e.elementsToHighlight,collaborators:e.collaborators,activeEmbeddable:e.activeEmbeddable,snapLines:e.snapLines,zenModeEnabled:e.zenModeEnabled,editingTextElement:e.editingTextElement,isCropping:e.isCropping,croppingElementId:e.croppingElementId,searchMatches:e.searchMatches,activeLockedId:e.activeLockedId,hoveredElementIds:e.hoveredElementIds,frameRendering:e.frameRendering,shouldCacheIgnoreZoom:e.shouldCacheIgnoreZoom,exportScale:e.exportScale,currentItemArrowType:e.currentItemArrowType}),ij=(e,t)=>e.selectionNonce!==t.selectionNonce||e.sceneNonce!==t.sceneNonce||e.scale!==t.scale||e.elementsMap!==t.elementsMap||e.visibleElements!==t.visibleElements||e.selectedElements!==t.selectedElements||e.renderScrollbars!==t.renderScrollbars?!1:nj(IP(e.appState),IP(t.appState)),_1=tj.memo(aj,ij);import lj,{useEffect as TP,useRef as CP}from"react";import{isShallowEqual as kP}from"@orangecatai/common";import{jsx as mj}from"react/jsx-runtime";var cj=e=>{let t=CP(null),o=CP(!1);return TP(()=>{e.canvas.style.width=`${e.appState.width}px`,e.canvas.style.height=`${e.appState.height}px`,e.canvas.width=e.appState.width*e.scale,e.canvas.height=e.appState.height*e.scale},[e.appState.height,e.appState.width,e.canvas,e.scale]),TP(()=>{let n=t.current;if(!n)return;let r=e.canvas;o.current||(o.current=!0,n.replaceChildren(r),r.classList.add("excalidraw__canvas","static")),dE({canvas:r,rc:e.rc,scale:e.scale,elementsMap:e.elementsMap,allElementsMap:e.allElementsMap,visibleElements:e.visibleElements,appState:e.appState,renderConfig:e.renderConfig},wi())}),mj("div",{className:"excalidraw__canvas-wrapper",ref:t})},SP=e=>({zoom:e.zoom,scrollX:e.scrollX,scrollY:e.scrollY,width:e.width,height:e.height,viewModeEnabled:e.viewModeEnabled,openDialog:e.openDialog,hoveredElementIds:e.hoveredElementIds,offsetLeft:e.offsetLeft,offsetTop:e.offsetTop,theme:e.theme,shouldCacheIgnoreZoom:e.shouldCacheIgnoreZoom,viewBackgroundColor:e.viewBackgroundColor,exportScale:e.exportScale,selectedElementsAreBeingDragged:e.selectedElementsAreBeingDragged,gridSize:e.gridSize,gridStep:e.gridStep,frameRendering:e.frameRendering,selectedElementIds:e.selectedElementIds,frameToHighlight:e.frameToHighlight,editingGroupId:e.editingGroupId,currentHoveredFontFamily:e.currentHoveredFontFamily,croppingElementId:e.croppingElementId,suggestedBinding:e.suggestedBinding}),dj=(e,t)=>e.sceneNonce!==t.sceneNonce||e.scale!==t.scale||e.elementsMap!==t.elementsMap||e.visibleElements!==t.visibleElements?!1:kP(SP(e.appState),SP(t.appState))&&kP(e.renderConfig,t.renderConfig),D1=lj.memo(cj,dj);import{useEffect as xj,useRef as yj}from"react";import{throttleRAF as pj}from"@orangecatai/common";import{getTargetFrame as uj,isInvisiblySmallElement as gj,renderElement as hj,shouldApplyFrameClip as fj}from"@orangecatai/element";var MP=({canvas:e,rc:t,newElement:o,elementsMap:n,allElementsMap:r,scale:a,appState:i,renderConfig:s})=>{if(e){let[l,c]=am(e,a),m=im({canvas:e,scale:a,normalizedWidth:l,normalizedHeight:c});if(m.save(),m.scale(i.zoom.value,i.zoom.value),o&&o.type!=="selection"){if(gj(o))return;if((o.frameId||i.frameToHighlight?.id)&&i.frameRendering.enabled&&i.frameRendering.clip){let d=uj(o,n,i);d&&fj(o,d,i,n)&&lE(d,m,s,i)}hj(o,n,r,t,m,s,i)}else m.clearRect(0,0,l,c);m.restore()}},bj=pj(e=>{MP(e)},{trailing:!0}),PP=(e,t)=>{if(t){bj(e);return}MP(e)};import{jsx as wj}from"react/jsx-runtime";var Ej=e=>{let t=yj(null);return xj(()=>{t.current&&PP({canvas:t.current,scale:e.scale,newElement:e.appState.newElement,elementsMap:e.elementsMap,allElementsMap:e.allElementsMap,rc:e.rc,renderConfig:e.renderConfig,appState:e.appState},wi())}),wj("canvas",{className:"excalidraw__canvas",style:{width:e.appState.width,height:e.appState.height},width:e.appState.width*e.scale,height:e.appState.height*e.scale,ref:t})},AP=Ej;import{useCallback as vj,useEffect as Ij,useRef as Tj}from"react";import{jsx as LP,jsxs as kj}from"react/jsx-runtime";var Cj=5e3,_P=({message:e,onClose:t,closable:o=!1,duration:n=Cj,style:r})=>{let a=Tj(0),i=n!==1/0,s=vj(()=>{i&&(a.current=window.setTimeout(()=>t(),n))},[t,n,i]);return Ij(()=>{if(i)return s(),()=>clearTimeout(a.current)},[s,e,n,i]),kj("div",{className:"Toast",onMouseEnter:i?()=>clearTimeout(a?.current):void 0,onMouseLeave:i?s:void 0,style:r,children:[LP("p",{className:"Toast__message",children:e}),o&&LP(ie,{icon:Go,"aria-label":"close",type:"icon",onClick:t,className:"close"})]})};import{getCommonBounds as Sj,getElementsInGroup as Mj,selectGroupsFromGivenElements as Pj}from"@orangecatai/element";import{sceneCoordsToViewportCoords as Aj}from"@orangecatai/common";import{flushSync as Lj}from"react-dom";import{jsx as Dj}from"react/jsx-runtime";var _j=({app:e,activeLockedId:t})=>{let o=e.scene.getElement(t),n=o?[o]:Mj(e.scene.getNonDeletedElementsMap(),t);if(n.length===0)return null;let[r,a]=Sj(n),{x:i,y:s}=Aj({sceneX:r,sceneY:a},e.state);return Dj("div",{className:"UnlockPopup",style:{bottom:`${e.state.height+12-s+e.state.offsetTop}px`,left:`${i-e.state.offsetLeft}px`},onClick:()=>{Lj(()=>{let l=Pj(n,e.state);e.setState({selectedElementIds:n.reduce((c,m)=>({...c,[m.id]:!0}),{}),selectedGroupIds:l,activeLockedId:null})}),e.actionManager.executeAction(Bc)},title:f("labels.elementLock.unlock"),children:_E})},DP=_j;import{Fragment as R6,jsx as Se,jsxs as Vd}from"react/jsx-runtime";var z6=cr.createContext(null),H6=cr.createContext(null),py={formFactor:"desktop",desktopUIMode:"full",userAgent:F6(typeof navigator<"u"?navigator.userAgent:""),isTouchScreen:!1,canFitSidebar:!1,isLandscape:!0},gy=cr.createContext(py);gy.displayName="EditorInterfaceContext";var hy=cr.createContext({container:null,id:null});hy.displayName="ExcalidrawContainerContext";var fy=cr.createContext([]);fy.displayName="ExcalidrawElementsContext";var by=cr.createContext({...Or(),width:0,height:0,offsetLeft:0,offsetTop:0});by.displayName="ExcalidrawAppStateContext";var xy=cr.createContext(()=>{console.warn("Uninitialized ExcalidrawSetAppStateContext context!")});xy.displayName="ExcalidrawSetAppStateContext";var yy=cr.createContext(null);yy.displayName="ExcalidrawActionManagerContext";var tt=()=>Ba(z6),Hn=()=>Ba(H6),Te=()=>Ba(gy),Dt=()=>Wg(Te()),Qe=()=>Ba(hy),$r=()=>Ba(fy),$o=()=>Ba(by),Ce=()=>Ba(xy),at=()=>Ba(yy),Hd=!1,ly=0,Gd=null,Ra=!1,Ud=!1,cy=!1,Wd={horizontal:null,vertical:null},Na=0,Yd=!1,dy=new Map,my=!1,_6=0,D6=!1,$d=null,Ne={pointers:new Map,lastCenter:null,initialDistance:null,initialScale:null},uy=class e extends cr.Component{constructor(o){super(o);A(this,"canvas");A(this,"interactiveCanvas",null);A(this,"rc");A(this,"unmounted",!1);A(this,"actionManager");A(this,"editorInterface",py);A(this,"stylesPanelMode",Wg(py));A(this,"excalidrawContainerRef",cr.createRef());A(this,"scene");A(this,"fonts");A(this,"renderer");A(this,"visibleElements");A(this,"resizeObserver");A(this,"library");A(this,"libraryItemsFromStorage");A(this,"id");A(this,"store");A(this,"history");A(this,"excalidrawContainerValue");A(this,"files",{});A(this,"imageCache",new Map);A(this,"iFrameRefs",new Map);A(this,"embedsValidationStatus",new Map);A(this,"initializedEmbeds",new Set);A(this,"handleToastClose",()=>{this.setToast(null)});A(this,"elementsPendingErasure",new Set);A(this,"flowChartCreator",new jq);A(this,"flowChartNavigator",new qq);A(this,"bindModeHandler",null);A(this,"hitLinkElement");A(this,"lastPointerDownEvent",null);A(this,"lastPointerUpEvent",null);A(this,"lastPointerMoveEvent",null);A(this,"lastPointerMoveCoords",null);A(this,"previousPointerMoveCoords",null);A(this,"lastViewportPosition",{x:0,y:0});A(this,"animationFrameHandler",new pu);A(this,"laserTrails",new Bu(this.animationFrameHandler,this));A(this,"eraserTrail",new Gu(this.animationFrameHandler,this));A(this,"lassoTrail",new Hu(this.animationFrameHandler,this));A(this,"onChangeEmitter",new Ai);A(this,"onPointerDownEmitter",new Ai);A(this,"onPointerUpEmitter",new Ai);A(this,"onUserFollowEmitter",new Ai);A(this,"onScrollChangeEmitter",new Ai);A(this,"missingPointerEventCleanupEmitter",new Ai);A(this,"onRemoveEventListenersEmitter",new Ai);A(this,"updateEditorAtom",(o,...n)=>{let r=Et.set(o,...n);return this.triggerRender(),r});A(this,"previousHoveredBindableElement",null);A(this,"getEffectiveGridSize",()=>ma(this)?this.state.gridSize:null);A(this,"handleIframeLikeElementHover",({hitElement:o,scenePointer:n,moveEvent:r})=>o&&V1(o)&&(this.state.viewModeEnabled||this.state.activeTool.type==="laser"||this.isIframeLikeElementCenter(o,r,n.x,n.y))?(Be(this.interactiveCanvas,lt.POINTER),this.setState({activeEmbeddable:{element:o,state:"hover"}}),!0):(this.state.activeEmbeddable?.state==="hover"&&this.setState({activeEmbeddable:null}),!1));A(this,"updateEmbedValidationStatus",(o,n)=>{this.embedsValidationStatus.set(o.id,n),zd.delete(o)});A(this,"updateEmbeddables",()=>{let o=new Set,n=!1;this.scene.getNonDeletedElements().filter(r=>{if(Nr(r)){if(o.add(r.id),!this.embedsValidationStatus.has(r.id)){n=!0;let a=j1(r.link,this.props.validateEmbeddable);this.updateEmbedValidationStatus(r,a)}}else zl(r)&&o.add(r.id);return!1}),n&&this.scene.triggerUpdate(),this.iFrameRefs.forEach((r,a)=>{o.has(a)||this.iFrameRefs.delete(a)})});A(this,"getFrameNameDOMId",o=>`${this.id}-frame-name-${o.id}`);A(this,"frameNameBoundsCache",{get:o=>{let n=this.frameNameBoundsCache._cache.get(o.id);if(!n||n.zoom!==this.state.zoom.value||n.versionNonce!==o.versionNonce){let r=document.getElementById(this.getFrameNameDOMId(o));if(r){let a=r.getBoundingClientRect(),i=rt({clientX:a.x,clientY:a.y},this.state),s=rt({clientX:a.right,clientY:a.bottom},this.state);return n={x:i.x,y:i.y,width:s.x-i.x,height:s.y-i.y,angle:0,zoom:this.state.zoom.value,versionNonce:o.versionNonce},this.frameNameBoundsCache._cache.set(o.id,n),n}return null}return n},_cache:new Map});A(this,"resetEditingFrame",o=>{o&&this.scene.mutateElement(o,{name:o.name?.trim()||null}),this.setState({editingFrame:null})});A(this,"renderFrameNames",()=>{if(!this.state.frameRendering.enabled||!this.state.frameRendering.name)return this.state.editingFrame&&this.resetEditingFrame(null),null;let o=this.state.theme===Dg.DARK,n=this.scene.getNonDeletedFramesLikes(),r=n.length>0&&this.state.searchMatches?.focusedId&&Qt(this.scene.getElement(this.state.searchMatches.focusedId))?this.state.searchMatches.matches.find(a=>a.focus):null;return n.map(a=>{if(!l6(a,this.canvas.width/window.devicePixelRatio,this.canvas.height/window.devicePixelRatio,{offsetLeft:this.state.offsetLeft,offsetTop:this.state.offsetTop,scrollX:this.state.scrollX,scrollY:this.state.scrollY,zoom:this.state.zoom},this.scene.getNonDeletedElementsMap()))return this.state.editingFrame===a.id&&this.resetEditingFrame(a),null;let{x:i,y:s}=Ng({sceneX:a.x,sceneY:a.y},this.state),l=6,c,m=Yq(a),p=`${Math.round(a.width)} x ${Math.round(a.height)}`;if(a.id===this.state.editingFrame){let d=m;c=Se("input",{autoFocus:!0,value:d,onChange:u=>{this.scene.mutateElement(a,{name:u.target.value})},onFocus:u=>u.target.select(),onBlur:()=>this.resetEditingFrame(a),onKeyDown:u=>{(u.key===re.ESCAPE||u.key===re.ENTER)&&this.resetEditingFrame(a)},style:{background:o?lq(this.state.viewBackgroundColor):this.state.viewBackgroundColor,zIndex:2,border:"none",display:"block",padding:`${l}px`,borderRadius:4,boxShadow:"inset 0 0 0 1px var(--color-primary)",fontFamily:"Assistant",fontSize:`${ln.nameFontSize}px`,transform:`translate(-${l}px, ${l}px)`,color:o?ln.nameColorDarkTheme:ln.nameColorLightTheme,overflow:"hidden",maxWidth:`${document.body.clientWidth-i-l}px`},size:d.length+1||1,dir:"auto",autoComplete:"off",autoCapitalize:"off",autoCorrect:"off"})}else c=Vd(R6,{children:[Se("span",{children:m}),Se("span",{style:{marginLeft:8,opacity:.7,fontSize:ln.nameFontSize-1},children:p})]});return Se("div",{id:this.getFrameNameDOMId(a),className:U1.FRAME_NAME,style:{position:"absolute",bottom:`${this.state.height+ln.nameOffsetY-s+this.state.offsetTop}px`,left:`${i-this.state.offsetLeft}px`,zIndex:2,fontSize:ln.nameFontSize,color:o?ln.nameColorDarkTheme:ln.nameColorLightTheme,lineHeight:ln.nameLineHeight,width:"max-content",maxWidth:r?.id===a.id&&r?.focus?"none":`${a.width*this.state.zoom.value}px`,overflow:a.id===this.state.editingFrame?"visible":"hidden",whiteSpace:"nowrap",textOverflow:"ellipsis",cursor:lt.MOVE,pointerEvents:this.state.viewModeEnabled?Nl.disabled:Nl.enabled},onPointerDown:d=>this.handleCanvasPointerDown(d),onWheel:d=>this.handleWheel(d),onContextMenu:this.handleCanvasContextMenu,onDoubleClick:()=>{this.setState({editingFrame:a.id})},children:c},a.id)})});A(this,"focusContainer",()=>{this.excalidrawContainerRef.current?.focus()});A(this,"getSceneElementsIncludingDeleted",()=>this.scene.getElementsIncludingDeleted());A(this,"getSceneElementsMapIncludingDeleted",()=>this.scene.getElementsMapIncludingDeleted());A(this,"getSceneElements",()=>this.scene.getNonDeletedElements());A(this,"onInsertElements",o=>{this.addElementsFromPasteOrLibrary({elements:o,position:"center",files:null})});A(this,"onExportImage",async(o,n,r)=>{be("export",o,"ui");let a=await ei(o,n,this.state,this.files,{exportBackground:this.state.exportBackground,name:this.getName(),viewBackgroundColor:this.state.viewBackgroundColor,exportingFrame:r.exportingFrame}).catch(aq).catch(i=>{console.error(i),this.setState({errorMessage:i.message})});this.state.exportEmbedScene&&a&&sm(a)&&this.setState({fileHandle:a})});A(this,"magicGenerations",new Map);A(this,"updateMagicGeneration",({frameElement:o,data:n})=>{n.status==="pending"?this.scene.mutateElement(o,{customData:{generationData:void 0}},{informMutation:!1,isDragging:!1}):this.scene.mutateElement(o,{customData:{generationData:n}},{informMutation:!1,isDragging:!1}),this.magicGenerations.set(o.id,n),this.triggerRender()});A(this,"plugins",{});A(this,"onMagicframeToolSelect",()=>{let o=this.scene.getSelectedElements({selectedElementIds:this.state.selectedElementIds});if(o.length===0)this.setActiveTool({type:ar.magicframe}),be("ai","tool-select (empty-selection)","d2c");else{let n=o.length===1&&K1(o[0])&&o[0];if(!n&&o.some(a=>Qt(a)||a.frameId)){this.setActiveTool({type:ar.magicframe});return}be("ai","tool-select (existing selection)","d2c");let r;if(n)r=n;else{let[a,i,s,l]=Fl(o),c=50;r=n6({...ln,x:a-c,y:i-c,width:s-a+c*2,height:l-i+c*2,opacity:100,locked:!1}),this.scene.insertElement(r);for(let m of o)this.scene.mutateElement(m,{frameId:r.id});this.setState({selectedElementIds:{[r.id]:!0}})}this.onMagicFrameGenerate(r,"upstream")}});A(this,"onImageGeneratorSelect",()=>{let r=(this.canvas.width/window.devicePixelRatio/2-this.state.offsetLeft)/this.state.zoom.value-this.state.scrollX,a=(this.canvas.height/window.devicePixelRatio/2-this.state.offsetTop)/this.state.zoom.value-this.state.scrollY,i=t6({...ln,x:r-896/2,y:a-1344/2,width:896,height:1344,opacity:100,locked:!1,backgroundColor:"#cce8f5",fillStyle:"solid",customData:{type:"image-generator",imageGeneratorAutoFitPending:!0}});this.scene.insertElement(i),this.setActiveTool({type:"selection"}),this.setState({selectedElementIds:{[i.id]:!0}})});A(this,"insertGeneratedImageIntoFrame",async(o,n)=>{let r=R1(),a=W1({type:"image",x:n.x,y:n.y,width:n.width,height:n.height,fileId:r,status:"pending",scale:[1,1],frameId:null});this.scene.insertElement(a),this.scene.mutateElement(a,{frameId:n.id}),this.addFiles([{id:r,dataURL:o,mimeType:So(o),created:Date.now(),lastRetrieved:Date.now()}])});A(this,"insertGeneratedImageNearElement",async(o,n,r,a)=>{let s=this.scene.getNonDeletedElementsMap(),l=this.scene.getNonDeletedElements().filter(y=>y.id!==n.id),[c,m,p,d]=Og(n,s),u=[{x:p+25,y:m},{x:c,y:d+25},{x:c-r-25,y:m},{x:c,y:m-a-25}],h=(y,w)=>{let v=y+r,I=w+a,C=y-25,P=w-25,S=v+25,D=I+25;return l.some(_=>{let[k,M,B,O]=Og(_,s);return k<S&&B>C&&M<D&&O>P})},g=u.find(y=>!h(y.x,y.y))??u[0],x=R1(),E=W1({type:"image",x:g.x,y:g.y,width:r,height:a,fileId:x,status:"pending",scale:[1,1],frameId:null});this.scene.insertElement(E),this.addFiles([{id:x,dataURL:o,mimeType:So(o),created:Date.now(),lastRetrieved:Date.now()}]),this.setState({selectedElementIds:{[E.id]:!0}})});A(this,"openEyeDropper",({type:o})=>{this.updateEditorAtom(Yr,{swapPreviewOnAlt:!0,colorPickerType:o==="stroke"?"elementStroke":"elementBackground",onSelect:(n,r)=>{let a=o==="background"&&r.altKey||o==="stroke"&&!r.altKey;!this.scene.getSelectedElements(this.state).length||this.state.activeTool.type!=="selection"?a?this.syncActionResult({appState:{...this.state,currentItemStrokeColor:n},captureUpdate:po.IMMEDIATELY}):this.syncActionResult({appState:{...this.state,currentItemBackgroundColor:n},captureUpdate:po.IMMEDIATELY}):this.updateScene({elements:this.scene.getElementsIncludingDeleted().map(s=>this.state.selectedElementIds[s.id]?_a(s,{[a?"strokeColor":"backgroundColor"]:n}):s),captureUpdate:po.IMMEDIATELY})},keepOpenOnAlt:!1})});A(this,"dismissLinearEditor",()=>{setTimeout(()=>{this.state.selectedLinearElement?.isEditing&&this.setState({selectedLinearElement:{...this.state.selectedLinearElement,isEditing:!1}})})});A(this,"syncActionResult",pt(o=>{if(this.unmounted||o===!1)return;this.store.scheduleAction(o.captureUpdate);let n=!1,r=null;if(o.elements&&(this.scene.replaceAllElements(o.elements),n=!0),o.files&&(this.addMissingFiles(o.files,o.replaceFiles),this.addNewImagesToImageCache()),o.appState||r||this.state.contextMenu){let a=o?.appState?.viewModeEnabled||!1,i=o?.appState?.zenModeEnabled||!1,s=o?.appState?.theme||this.props.theme||Dg.LIGHT,l=o?.appState?.name??this.state.name,c=o?.appState?.errorMessage??this.state.errorMessage;typeof this.props.viewModeEnabled<"u"&&(a=this.props.viewModeEnabled),typeof this.props.zenModeEnabled<"u"&&(i=this.props.zenModeEnabled),r=o.appState?.editingTextElement||null,o.elements&&r&&o.elements.forEach(m=>{r?.id===m.id&&r!==m&&C6(m)&&kn(m)&&(r=m)}),r?.isDeleted&&(r=null),this.setState(m=>{let p=o.appState||{};return{...m,...p,contextMenu:null,editingTextElement:r,viewModeEnabled:a,zenModeEnabled:i,theme:s,name:l,errorMessage:c}}),n=!0}n||this.scene.triggerUpdate()}));A(this,"onBlur",pt(()=>{Ra=!1,this.setState({isBindingEnabled:!0})}));A(this,"onUnload",()=>{this.onBlur()});A(this,"disableEvent",o=>{o.preventDefault()});A(this,"resetHistory",()=>{this.history.clear()});A(this,"resetStore",()=>{this.store.clear()});A(this,"resetScene",pt(o=>{this.scene.replaceAllElements([]),this.setState(n=>({...Or(),isLoading:o?.resetLoadingState?!1:n.isLoading,theme:this.state.theme})),this.resetStore(),this.resetHistory()}));A(this,"initializeScene",async()=>{"launchQueue"in window&&"LaunchParams"in window&&window.launchQueue.setConsumer(async i=>{if(!i.files.length)return;let s=i.files[0],l=await s.getFile();this.loadFileToCanvas(new File([l],l.name||"",{type:l.type}),s)}),this.props.theme&&this.setState({theme:this.props.theme}),this.state.isLoading||this.setState({isLoading:!0});let o=null;try{typeof this.props.initialData=="function"?o=await this.props.initialData()||null:o=await this.props.initialData||null,o?.libraryItems&&this.library.updateLibrary({libraryItems:o.libraryItems,merge:!0}).catch(i=>{console.error(i)})}catch(i){console.error(i),o={appState:{errorMessage:i.message||"Encountered an error during importing or restoring scene data"}}}let n=Ga(o?.elements,null,{repairBindings:!0,deleteInvisibleElements:!0}),r=$i(o?.appState,null),a=r.activeTool;r.preferredSelectionTool.initialized||(r.preferredSelectionTool={type:this.editorInterface.formFactor==="phone"?"lasso":"selection",initialized:!0}),r={...r,theme:this.props.theme||r.theme,openSidebar:r?.openSidebar||this.state.openSidebar,activeTool:a.type==="image"||a.type==="lasso"||a.type==="selection"?{...a,type:r.preferredSelectionTool.type}:r.activeTool,isLoading:!1,toast:this.state.toast},o?.scrollToContent&&(r={...r,...Ha(n,{...r,width:this.state.width,height:this.state.height,offsetTop:this.state.offsetTop,offsetLeft:this.state.offsetLeft})}),this.resetStore(),this.resetHistory(),this.syncActionResult({elements:n,appState:r,files:o?.files,captureUpdate:po.NEVER}),this.clearImageShapeCache(),this.fonts.loadSceneFonts().then(i=>{this.fonts.onLoaded(i)}),ny(window.location.href)&&this.scrollToContent(window.location.href,{animate:!1})});A(this,"getFormFactor",(o,n)=>this.props.UIOptions.getFormFactor?.(o,n)??uq(o,n));A(this,"refreshEditorInterface",()=>{let o=this.excalidrawContainerRef.current;if(!o)return;let{width:n,height:r}=o.getBoundingClientRect(),a=bq(),i=F6(typeof navigator<"u"?navigator.userAgent:""),s=this.props.UIOptions.dockedSidebarBreakpoint!=null?this.props.UIOptions.dockedSidebarBreakpoint:Uj,l=G1(this.editorInterface,{desktopUIMode:a??this.editorInterface.desktopUIMode,formFactor:this.getFormFactor(n,r),userAgent:i,canFitSidebar:n>s,isLandscape:n>r});this.editorInterface=l,this.reconcileStylesPanelMode(l)});A(this,"reconcileStylesPanelMode",o=>{let n=Wg(o);if(n===this.stylesPanelMode)return;let r=this.stylesPanelMode;this.stylesPanelMode=n,r!=="full"&&n==="full"&&this.setState(a=>({preferredSelectionTool:{type:"selection",initialized:!0}}))});A(this,"setDesktopUIMode",o=>{let n=xq(o);this.editorInterface=G1(this.editorInterface,{desktopUIMode:n}),this.reconcileStylesPanelMode(this.editorInterface)});A(this,"onResize",pt(()=>{this.scene.getElementsIncludingDeleted().forEach(o=>zd.delete(o)),this.refreshEditorInterface(),this.updateDOMRect(),this.setState({})}));A(this,"onFullscreenChange",()=>{!document.fullscreenElement&&this.state.activeEmbeddable?.state==="active"&&this.setState({activeEmbeddable:null})});A(this,"renderInteractiveSceneCallback",({atLeastOneVisibleElement:o,scrollBars:n,elementsMap:r})=>{n&&(Wd=n);let a=this.state.editingTextElement?!1:!o&&r.size>0;this.state.scrolledOutside!==a&&this.setState({scrolledOutside:a}),this.scheduleImageRefresh()});A(this,"onScroll",ZP(()=>{let{offsetTop:o,offsetLeft:n}=this.getCanvasOffsets();this.setState(r=>r.offsetLeft===n&&r.offsetTop===o?null:{offsetTop:o,offsetLeft:n})},Wj));A(this,"onCut",pt(o=>{!this.excalidrawContainerRef.current?.contains(document.activeElement)||Rd(o.target)||(this.actionManager.executeAction(bp,"keyboard",o),o.preventDefault(),o.stopPropagation())}));A(this,"onCopy",pt(o=>{!this.excalidrawContainerRef.current?.contains(document.activeElement)||Rd(o.target)||(this.actionManager.executeAction(Os,"keyboard",o),o.preventDefault(),o.stopPropagation())}));A(this,"onTouchStart",o=>{if(gq&&o.preventDefault(),!Hd){Hd=!0,o.touches.length===1&&(Gd={x:o.touches[0].clientX,y:o.touches[0].clientY}),clearTimeout(ly),ly=window.setTimeout(e.resetTapTwice,Yj);return}if(Hd&&o.touches.length===1&&Gd){let n=o.touches[0];Pa(pe(n.clientX,n.clientY),pe(Gd.x,Gd.y))<=mq&&(this.lassoTrail.endPath(),this.deselectElements(),this.handleCanvasDoubleClick({clientX:n.clientX,clientY:n.clientY})),Hd=!1,clearTimeout(ly)}o.touches.length===2&&this.setState({selectedElementIds:ze({},this.state),activeEmbeddable:null})});A(this,"onTouchEnd",o=>{this.resetContextMenuTimer(),o.touches.length>0?this.setState({previousSelectedElementIds:{},selectedElementIds:ze(this.state.previousSelectedElementIds,this.state)}):Ne.pointers.clear()});A(this,"pasteFromClipboard",pt(async o=>{let n=!!my,r=document.activeElement,a=this.excalidrawContainerRef.current?.contains(r);if(o&&!a)return;let i=document.elementFromPoint(this.lastViewportPosition.x,this.lastViewportPosition.y);if(o&&(!(i instanceof HTMLCanvasElement)||Rd(r)))return;let s=await As(o),l=s.getFiles(),c=await sp(s,n);if(this.props.onPaste)try{if(await this.props.onPaste(c,o)===!1)return}catch(m){console.error(m)}await this.insertClipboardContent(c,l,n),this.setActiveTool({type:this.state.preferredSelectionTool.type},!0),o?.preventDefault()}));A(this,"addElementsFromPasteOrLibrary",o=>{let n=Ga(o.elements,null,{deleteInvisibleElements:!0}),[r,a,i,s]=Fl(n),l=Bl(r,i)/2,c=Bl(a,s)/2,m=typeof o.position=="object"?o.position.clientX:o.position==="cursor"?this.lastViewportPosition.x:this.state.width/2+this.state.offsetLeft,p=typeof o.position=="object"?o.position.clientY:o.position==="cursor"?this.lastViewportPosition.y:this.state.height/2+this.state.offsetTop,{x:d,y:u}=rt({clientX:m,clientY:p},this.state),h=d-l,g=u-c,[x,E]=Jt(h,g,this.getEffectiveGridSize()),{duplicatedElements:y}=Y1({type:"everything",elements:n.map(S=>_a(S,{x:S.x+x-r,y:S.y+E-a})),randomizeSeed:!o.retainSeed}),w=this.scene.getElementsIncludingDeleted(),v=[...w,...y];v=this.props.onDuplicate?.(v,w)||v,E6(v,Bg(y));let C=this.getTopLayerFrameAtSceneCoords({x:d,y:u});if(C){let S=Vq(y,C);ey(v,S,C,this.state)}this.scene.replaceAllElements(v),y.forEach(S=>{if(kn(S)&&$1(S)){let D=u6(S,this.scene.getElementsMapIncludingDeleted());Oq(S,D,this.scene)}}),fq&&Ho.loadElementsFonts(y).then(S=>{this.fonts.onLoaded(S)}),o.files&&this.addMissingFiles(o.files);let P=pJ(y);this.store.scheduleCapture(),this.setState({...this.state,openSidebar:this.state.openSidebar&&this.editorInterface.canFitSidebar&&Et.get(xd)?this.state.openSidebar:null,...cn({editingGroupId:null,selectedElementIds:P.reduce((S,D)=>($1(D)||(S[D.id]=!0),S),{})},this.scene.getNonDeletedElements(),this.state,this)},()=>{o.files&&this.addNewImagesToImageCache()}),this.setActiveTool({type:this.state.preferredSelectionTool.type},!0),o.fitToContent&&this.scrollToContent(y,{fitToContent:!0,canvasOffsets:this.getEditorUIOffsets()})});A(this,"setAppState",(o,n)=>{this.setState(o,n)});A(this,"removePointer",o=>{Na&&this.resetContextMenuTimer(),Ne.pointers.delete(o.pointerId)});A(this,"toggleLock",(o="ui")=>{this.state.activeTool.locked||be("toolbar","toggleLock",`${o} (${this.editorInterface.formFactor==="phone"?"mobile":"desktop"})`),this.setState(n=>({activeTool:{...n.activeTool,...ir(this.state,n.activeTool.locked?{type:this.state.preferredSelectionTool.type}:n.activeTool),locked:!n.activeTool.locked}}))});A(this,"updateFrameRendering",o=>{this.setState(n=>{let r=typeof o=="function"?o(n.frameRendering):o;return{frameRendering:{enabled:r?.enabled??n.frameRendering.enabled,clip:r?.clip??n.frameRendering.clip,name:r?.name??n.frameRendering.name,outline:r?.outline??n.frameRendering.outline}}})});A(this,"togglePenMode",o=>{this.setState(n=>({penMode:o??!n.penMode,penDetected:!0}))});A(this,"onHandToolToggle",()=>{this.actionManager.executeAction(F2)});A(this,"zoomCanvas",o=>{this.setState({...br({viewportX:this.state.width/2+this.state.offsetLeft,viewportY:this.state.height/2+this.state.offsetTop,nextZoom:Ln(o)},this.state)})});A(this,"cancelInProgressAnimation",null);A(this,"scrollToContent",(o=this.scene.getNonDeletedElements(),n)=>{if(typeof o=="string"){let l;if(ny(o)?l=eJ(o):l=o,l){let c=this.scene.getElementsFromId(l);c?.length?this.scrollToContent(c,{fitToContent:n?.fitToContent??!0,animate:n?.animate??!0}):ny(o)&&this.setState({toast:{message:f("elementLink.notFound"),duration:3e3,closable:!0}})}return}this.cancelInProgressAnimation?.();let r=Array.isArray(o)?o:[o],a=this.state.zoom,i=this.state.scrollX,s=this.state.scrollY;if(n?.fitToContent||n?.fitToViewport){let{appState:l}=Ss({canvasOffsets:n.canvasOffsets,targetElements:r,appState:this.state,fitToViewport:!!n?.fitToViewport,viewportZoomFactor:n?.viewportZoomFactor,minZoom:n?.minZoom,maxZoom:n?.maxZoom});a=l.zoom,i=l.scrollX,s=l.scrollY}else{let l=Ha(r,this.state);i=l.scrollX,s=l.scrollY}if(n?.animate){let l=this.state.scrollX,c=this.state.scrollY,m=this.state.zoom.value,p=rq({fromValues:{scrollX:l,scrollY:c,zoom:m},toValues:{scrollX:i,scrollY:s,zoom:a.value},interpolateValue:(d,u,h,g)=>{if(g==="zoom")return d*Math.pow(u/d,iq(h))},onStep:({scrollX:d,scrollY:u,zoom:h})=>{this.setState({scrollX:d,scrollY:u,zoom:{value:h}})},onStart:()=>{this.setState({shouldCacheIgnoreZoom:!0})},onEnd:()=>{this.setState({shouldCacheIgnoreZoom:!1})},onCancel:()=>{this.setState({shouldCacheIgnoreZoom:!1})},duration:n?.duration??500});this.cancelInProgressAnimation=()=>{p(),this.cancelInProgressAnimation=null}}else this.setState({scrollX:i,scrollY:s,zoom:a})});A(this,"maybeUnfollowRemoteUser",()=>{this.state.userToFollow&&this.setState({userToFollow:null})});A(this,"translateCanvas",o=>{this.cancelInProgressAnimation?.(),this.maybeUnfollowRemoteUser(),this.setState(o)});A(this,"setToast",o=>{this.setState({toast:o})});A(this,"restoreFileFromShare",async()=>{try{let o=await caches.open("web-share-target"),n=await o.match("shared-file");if(n){let r=await n.blob(),a=new File([r],r.name||"",{type:r.type});this.loadFileToCanvas(a,null),await o.delete("shared-file"),window.history.replaceState(null,Fj,window.location.pathname)}}catch(o){this.setState({errorMessage:o.message})}});A(this,"addFiles",pt(o=>{let{addedFiles:n}=this.addMissingFiles(o);this.clearImageShapeCache(n),this.scene.triggerUpdate(),this.addNewImagesToImageCache()}));A(this,"addMissingFiles",(o,n=!1)=>{let r=n?{}:{...this.files},a={},i=Array.isArray(o)?o:Object.values(o);for(let s of i)if(!r[s.id]&&(a[s.id]=s,r[s.id]=s,s.mimeType===rr.svg))try{let l=xE(p6(yE(s.dataURL)),rr.svg);s.dataURL!==l&&(s.version=(s.version??1)+1,s.dataURL=l)}catch(l){console.error(l)}return this.files=r,{addedFiles:a}});A(this,"updateScene",pt(o=>{let{elements:n,appState:r,collaborators:a,captureUpdate:i}=o;if(i){let s=n||void 0,l=r?yq({...this.store.snapshot.appState,...r}):void 0;this.store.scheduleMicroAction({action:i,elements:s,appState:l})}r&&this.setState(r),n&&this.scene.replaceAllElements(n),a&&this.setState({collaborators:a})}));A(this,"applyDeltas",(o,n)=>{let r=S6.squash(...o),a={...this.state},i=new Map(this.scene.getElementsMapIncludingDeleted());return S6.applyTo(r,i,a,n)});A(this,"mutateElement",(o,n,r=!0)=>this.scene.mutateElement(o,n,{informMutation:r,isDragging:!1}));A(this,"triggerRender",o=>{o===!0?this.scene.triggerUpdate():this.setState({})});A(this,"toggleSidebar",({name:o,tab:n,force:r})=>{let a;r===void 0?a=this.state.openSidebar?.name===o&&this.state.openSidebar?.tab===n?null:o:a=r?o:null;let i=a?{name:a}:null;return i&&n&&(i.tab=n),this.setState({openSidebar:i}),!!a});A(this,"updateCurrentCursorPosition",pt(o=>{this.lastViewportPosition.x=o.clientX,this.lastViewportPosition.y=o.clientY}));A(this,"getEditorUIOffsets",()=>{let o=this.excalidrawContainerRef?.current?.querySelector(".App-toolbar")?.getBoundingClientRect()?.bottom??0,n=this.excalidrawContainerRef?.current?.querySelector(".sidebar")?.getBoundingClientRect(),r=this.excalidrawContainerRef?.current?.querySelector(".App-menu__left")?.getBoundingClientRect(),a=16;return ur().rtl?{top:o+a,right:Math.max(this.state.width-(r?.left??this.state.width),0)+a,bottom:a,left:Math.max(n?.right??0,0)+a}:{top:o+a,right:Math.max(this.state.width-(n?.left??this.state.width)+a,0),bottom:a,left:Math.max(r?.right??0,0)+a}});A(this,"onKeyDown",pt(o=>{if("Proxy"in window&&(!o.shiftKey&&/^[A-Z]$/.test(o.key)||o.shiftKey&&/^[a-z]$/.test(o.key))&&(o=new Proxy(o,{get(s,l){let c=s[l];return typeof c=="function"?c.bind(s):l==="key"?o.shiftKey?s.key.toUpperCase():s.key.toLowerCase():c}})),!jP(o.target)){if((o.key===re.ESCAPE||o.key===re.ENTER)&&this.state.croppingElementId){this.finishImageCropping();return}let s=de(this.scene.getNonDeletedElementsMap(),this.state);if(s.length===1&&Da(s[0])&&o.key===re.ENTER){this.startImageCropping(s[0]);return}if(o.key===re.ESCAPE)this.updateEditorAtom(bn,null);else if(o.key===re.TAB&&(document.activeElement===this.excalidrawContainerRef?.current||document.activeElement?.classList.contains(U1.CONVERT_ELEMENT_TYPE_POPUP))){o.preventDefault();let c=$s(s);Et.get(bn)?.type==="panel"&&Tb(this,{conversionType:c,direction:o.shiftKey?"left":"right"})&&this.store.scheduleCapture(),c&&this.updateEditorAtom(bn,{type:"panel"})}if(o.key===re.ESCAPE&&this.flowChartCreator.isCreatingChart){this.flowChartCreator.clear(),this.triggerRender(!0);return}let l=Lg(o.key);if(o[re.CTRL_OR_CMD]&&l&&!o.shiftKey){o.preventDefault();let c=de(this.scene.getNonDeletedElementsMap(),this.state);c.length===1&&Lq(c[0])&&this.flowChartCreator.createNodes(c[0],this.state,b6(o.key),this.scene),this.flowChartCreator.pendingNodes?.length&&!Z1(this.flowChartCreator.pendingNodes,this.canvas.width/window.devicePixelRatio,this.canvas.height/window.devicePixelRatio,{offsetLeft:this.state.offsetLeft,offsetTop:this.state.offsetTop,scrollX:this.state.scrollX,scrollY:this.state.scrollY,zoom:this.state.zoom},this.scene.getNonDeletedElementsMap(),this.getEditorUIOffsets())&&this.scrollToContent(this.flowChartCreator.pendingNodes,{animate:!0,duration:300,fitToContent:!0,canvasOffsets:this.getEditorUIOffsets()});return}if(o.altKey){let c=de(this.scene.getNonDeletedElementsMap(),this.state);if(c.length===1&&l){o.preventDefault();let m=this.flowChartNavigator.exploreByDirection(c[0],this.scene.getNonDeletedElementsMap(),b6(o.key));if(m){this.setState(d=>({selectedElementIds:ze({[m]:!0},d)}));let p=this.scene.getNonDeletedElementsMap().get(m);p&&!Z1([p],this.canvas.width/window.devicePixelRatio,this.canvas.height/window.devicePixelRatio,{offsetLeft:this.state.offsetLeft,offsetTop:this.state.offsetTop,scrollX:this.state.scrollX,scrollY:this.state.scrollY,zoom:this.state.zoom},this.scene.getNonDeletedElementsMap(),this.getEditorUIOffsets())&&this.scrollToContent(p,{animate:!0,duration:300,canvasOffsets:this.getEditorUIOffsets()})}return}}}if(o[re.CTRL_OR_CMD]&&o.key===re.P&&!o.shiftKey&&!o.altKey){this.setToast({message:f("commandPalette.shortcutHint",{shortcut:Xe("commandPalette")})}),o.preventDefault();return}if(o[re.CTRL_OR_CMD]&&o.key.toLowerCase()===re.V&&(my=o.shiftKey,clearTimeout(_6),_6=window.setTimeout(()=>{my=!1},100)),o[re.CTRL_OR_CMD]&&Rd(o.target)&&(o.code===HP.MINUS||o.code===HP.EQUAL)){o.preventDefault();return}if(Rd(o.target)&&o.key!==re.ESCAPE||Lg(o.key)&&jP(o.target))return;if(o.key===re.QUESTION_MARK){this.setState({openDialog:{name:"help"}});return}else if(o.key.toLowerCase()===re.E&&o.shiftKey&&o[re.CTRL_OR_CMD]){o.preventDefault(),this.setState({openDialog:{name:"imageExport"}});return}if(o.key===re.PAGE_UP||o.key===re.PAGE_DOWN){let s=(o.shiftKey?this.state.width:this.state.height)/this.state.zoom.value;o.key===re.PAGE_DOWN&&(s=-s),o.shiftKey?this.translateCanvas(l=>({scrollX:l.scrollX+s})):this.translateCanvas(l=>({scrollY:l.scrollY+s}))}if(this.state.openDialog?.name==="elementLinkSelector"||(o.key===re.ALT&&(Rr("COMPLEX_BINDINGS")?this.handleSkipBindMode():Ug({app:this,event:o})),this.actionManager.handleKeyDown(o)))return;let n=this.props.viewModeEnabled===!0;if(!n&&this.state.viewModeEnabled&&o.key===re.ESCAPE){this.setActiveTool({type:"hand"});return}if(!n&&!o.ctrlKey&&!o.altKey&&!o.metaKey&&!this.state.newElement&&!this.state.selectionElement&&!this.state.selectedElementsAreBeingDragged){let s=zC(o.key,this);if(this.state.viewModeEnabled&&!QP(s,["laser","hand"]))return;if(s){this.state.activeTool.type!==s&&be("toolbar",s,`keyboard (${this.editorInterface.formFactor==="phone"?"mobile":"desktop"})`),s==="arrow"&&this.state.activeTool.type==="arrow"&&this.setState(l=>({currentItemArrowType:l.currentItemArrowType===La.sharp?La.round:l.currentItemArrowType===La.round?La.elbow:La.sharp})),s==="lasso"&&this.state.activeTool.type==="laser"?this.setActiveTool({type:this.state.preferredSelectionTool.type}):this.setActiveTool({type:s}),o.stopPropagation();return}else if(o.key===re.Q){this.toggleLock("keyboard"),o.stopPropagation();return}}if(this.state.viewModeEnabled)return;if(o[re.CTRL_OR_CMD]&&this.state.isBindingEnabled&&(Rr("COMPLEX_BINDINGS")&&this.resetDelayedBindMode(),Io(()=>{this.setState({isBindingEnabled:!1})}),Ug({app:this,event:o})),Lg(o.key)){let s=this.scene.getSelectedElements({selectedElementIds:this.state.selectedElementIds,includeBoundTextElement:!0,includeElementsInFrames:!0}),l=new Set;s.filter(d=>lr(d)).filter(d=>{let u=d.startBinding&&!s.some(g=>g.id===d.startBinding?.elementId),h=d.endBinding&&!s.some(g=>g.id===d.endBinding?.elementId);return u||h}).forEach(d=>l.add(d.id)),s=s.filter(d=>!l.has(d.id));let c=this.getEffectiveGridSize()&&(o.shiftKey?$P:this.getEffectiveGridSize())||(o.shiftKey?zj:$P),m=0,p=0;o.key===re.ARROW_LEFT?m=-c:o.key===re.ARROW_RIGHT?m=c:o.key===re.ARROW_UP?p=-c:o.key===re.ARROW_DOWN&&(p=c),s.forEach(d=>{this.scene.mutateElement(d,{x:d.x+m,y:d.y+p},{informMutation:!1,isDragging:!1}),zg(d,this.scene,{simultaneouslyUpdated:s})}),this.scene.triggerUpdate(),o.preventDefault()}else if(o.key===re.ENTER){let s=this.scene.getSelectedElements(this.state);if(s.length===1){let l=s[0];if(o[re.CTRL_OR_CMD]||ry(l))mo(l)&&(!this.state.selectedLinearElement?.isEditing||this.state.selectedLinearElement.elementId!==l.id)&&(this.store.scheduleCapture(),To(l)||this.actionManager.executeAction(il));else if(kn(l)||Fq(l)){let c;kn(l)||(c=l);let m=J1(l,this.state,this.scene.getNonDeletedElementsMap()),p=m.x,d=m.y;this.startTextEditing({sceneX:p,sceneY:d,container:c}),o.preventDefault();return}else Qt(l)&&this.setState({editingFrame:l.id})}}if(o.key===re.SPACE&&Ne.pointers.size===0&&(Ra=!0,Be(this.interactiveCanvas,lt.GRAB),o.preventDefault()),(o.key===re.G||o.key===re.S)&&!o.altKey&&!o[re.CTRL_OR_CMD]){let s=this.scene.getSelectedElements(this.state);if(this.state.activeTool.type==="selection"&&!s.length)return;o.key===re.G&&(_n(this.state.activeTool.type)||s.some(l=>_n(l.type)))&&(this.setState({openPopup:"elementBackground"}),o.stopPropagation()),o.key===re.S&&(this.setState({openPopup:"elementStroke"}),o.stopPropagation())}if(!o[re.CTRL_OR_CMD]&&o.shiftKey&&o.key.toLowerCase()===re.F){let s=this.scene.getSelectedElements(this.state);if(this.state.activeTool.type==="selection"&&!s.length)return;(this.state.activeTool.type==="text"||s.find(l=>kn(l)||q1(l,this.scene.getNonDeletedElementsMap())))&&(o.preventDefault(),this.setState({openPopup:"fontFamily"}))}o[re.CTRL_OR_CMD]&&(o.key===re.BACKSPACE||o.key===re.DELETE)&&this.updateEditorAtom(si,"clearCanvas");let r=o.key.toLocaleLowerCase(),a=r===re.S&&o.shiftKey,i=o.key===re.I||r===re.G&&o.shiftKey;(a||i)&&this.openEyeDropper({type:a?"stroke":"background"})}));A(this,"onKeyUp",pt(o=>{if(o.key===re.SPACE&&(this.state.viewModeEnabled&&this.state.activeTool.type!=="laser"||this.state.openDialog?.name==="elementLinkSelector"?Be(this.interactiveCanvas,lt.GRAB):Fg(this.state.activeTool.type)?Po(this.interactiveCanvas):(Ao(this.interactiveCanvas,this.state),this.setState({selectedElementIds:ze({},this.state),selectedGroupIds:{},editingGroupId:null,activeEmbeddable:null})),Ra=!1),o.key===re.ALT&&Ug({app:this,event:o}),(o.key===re.ALT&&this.state.bindMode==="skip"||!o[re.CTRL_OR_CMD]&&!Bd(this.state))&&(this.setState({bindMode:"orbit"}),this.lastPointerMoveEvent&&Rr("COMPLEX_BINDINGS"))){let n=rt({clientX:this.lastPointerMoveEvent.clientX,clientY:this.lastPointerMoveEvent.clientY},this.state),r=Cn(pe(n.x,n.y),this.scene.getNonDeletedElements(),this.scene.getNonDeletedElementsMap());if(this.state.selectedLinearElement){let a=_e.getElement(this.state.selectedLinearElement.elementId,this.scene.getNonDeletedElementsMap());lr(a)&&this.handleDelayedBindModeChange(a,r)}}if(!o[re.CTRL_OR_CMD]&&!this.state.isBindingEnabled&&(Io(()=>{this.setState({isBindingEnabled:!0})}),Ug({app:this,event:o})),Lg(o.key)){e6(this.scene.getSelectedElements(this.state).filter(Ol),this.scene,this.state);let n=this.scene.getNonDeletedElementsMap();this.scene.getSelectedElements(this.state).filter(ay).forEach(r=>{r.startBinding&&this.scene.mutateElement(r,{startBinding:{...r.startBinding,...P6(r,n.get(r.startBinding.elementId),"start",n)}}),r.endBinding&&this.scene.mutateElement(r,{endBinding:{...r.endBinding,...P6(r,n.get(r.endBinding.elementId),"end",n)}})}),this.setState({suggestedBinding:null})}if(o.altKey||this.flowChartNavigator.isExploring&&(this.flowChartNavigator.clear(),this.syncActionResult({captureUpdate:po.IMMEDIATELY})),!o[re.CTRL_OR_CMD]&&this.flowChartCreator.isCreatingChart){this.flowChartCreator.pendingNodes?.length&&this.scene.insertElements(this.flowChartCreator.pendingNodes);let n=this.flowChartCreator.pendingNodes?.[0];n&&(this.setState(r=>({selectedElementIds:ze({[n.id]:!0},r)})),Z1([n],this.canvas.width/window.devicePixelRatio,this.canvas.height/window.devicePixelRatio,{offsetLeft:this.state.offsetLeft,offsetTop:this.state.offsetTop,scrollX:this.state.scrollX,scrollY:this.state.scrollY,zoom:this.state.zoom},this.scene.getNonDeletedElementsMap(),this.getEditorUIOffsets())||this.scrollToContent(n,{animate:!0,duration:300,canvasOffsets:this.getEditorUIOffsets()})),this.flowChartCreator.clear(),this.syncActionResult({captureUpdate:po.IMMEDIATELY})}}));A(this,"isToolSupported",o=>this.props.UIOptions.tools?.[o]!==!1);A(this,"setActiveTool",(o,n=!1)=>{if(!this.isToolSupported(o.type)){console.warn(`"${o.type}" tool is disabled via "UIOptions.canvasActions.tools.${o.type}"`);return}let r=ir(this.state,o);r.type==="hand"?Be(this.interactiveCanvas,lt.GRAB):Ra||Ao(this.interactiveCanvas,{...this.state,activeTool:r}),tq(document.activeElement)&&this.focusContainer(),Pq(r.type)||this.setState({suggestedBinding:null}),r.type==="image"&&this.onImageToolbarButtonClick(),this.setState(a=>{let i={snapLines:a.snapLines.length?[]:a.snapLines,originSnapOffset:null,activeEmbeddable:null,selectedLinearElement:Fg(r.type)?a.selectedLinearElement:null};return r.type==="freedraw"&&this.store.scheduleCapture(),r.type==="lasso"?{...a,...i,activeTool:r,...n?{}:{selectedElementIds:ze({},a),selectedGroupIds:ze({},a),editingGroupId:null,multiElement:null}}:r.type!=="selection"?{...a,...i,activeTool:r,selectedElementIds:ze({},a),selectedGroupIds:ze({},a),editingGroupId:null,multiElement:null}:{...a,...i,activeTool:r}})});A(this,"setOpenDialog",o=>{this.setState({openDialog:o})});A(this,"setCursor",o=>{Be(this.interactiveCanvas,o)});A(this,"resetCursor",()=>{Po(this.interactiveCanvas)});A(this,"isTouchScreenMultiTouchGesture",()=>Ne.pointers.size>=2);A(this,"getName",()=>this.state.name||this.props.name||`${f("labels.untitled")}-${qP()}`);A(this,"onGestureStart",pt(o=>{o.preventDefault(),this.isTouchScreenMultiTouchGesture()&&this.setState({selectedElementIds:ze({},this.state),activeEmbeddable:null}),Ne.initialScale=this.state.zoom.value}));A(this,"onGestureChange",pt(o=>{if(o.preventDefault(),this.isTouchScreenMultiTouchGesture())return;let n=Ne.initialScale;n&&this.setState(r=>({...br({viewportX:this.lastViewportPosition.x,viewportY:this.lastViewportPosition.y,nextZoom:Ln(n*o.scale)},r)}))}));A(this,"onGestureEnd",pt(o=>{o.preventDefault(),this.isTouchScreenMultiTouchGesture()&&this.setState({previousSelectedElementIds:{},selectedElementIds:ze(this.state.previousSelectedElementIds,this.state)}),Ne.initialScale=null}));A(this,"startTextEditing",({sceneX:o,sceneY:n,insertAtParentCenter:r=!0,container:a,autoEdit:i=!0})=>{let s=!1,l=r&&this.getTextWysiwygSnappedToCenterPosition(o,n,this.state,a);a&&l&&(q1(a,this.scene.getNonDeletedElementsMap())||(s=!0));let c=null,m=this.scene.getSelectedElements(this.state);m.length===1?kn(m[0])?c=m[0]:a?c=q1(m[0],this.scene.getNonDeletedElementsMap()):c=this.getTextElementAtPosition(o,n):c=this.getTextElementAtPosition(o,n);let p=c?.fontFamily||this.state.currentItemFontFamily,d=c?.lineHeight||XP(p),u=this.state.currentItemFontSize;if(!c&&s&&a&&!Ol(a)){let E=rJ(z1({fontSize:u,fontFamily:p}),d),y=aJ(u,d),w=Math.max(a.height,y),v=Math.max(a.width,E);this.scene.mutateElement(a,{height:w,width:v}),o=a.x+v/2,n=a.y+w/2,l&&(l=this.getTextWysiwygSnappedToCenterPosition(o,n,this.state,a))}let h=this.getTopLayerFrameAtSceneCoords({x:o,y:n}),g=c||r6({x:l?l.elementCenterX:o,y:l?l.elementCenterY:n,strokeColor:this.state.currentItemStrokeColor,backgroundColor:this.state.currentItemBackgroundColor,fillStyle:this.state.currentItemFillStyle,strokeWidth:this.state.currentItemStrokeWidth,strokeStyle:this.state.currentItemStrokeStyle,roughness:this.state.currentItemRoughness,opacity:this.state.currentItemOpacity,text:"",fontSize:u,fontFamily:p,textAlign:l?"center":this.state.currentItemTextAlign,verticalAlign:l?Kj.MIDDLE:WP,containerId:s?a?.id:void 0,groupIds:a?.groupIds??[],lineHeight:d,angle:a?Ol(a)?0:a.angle:0,frameId:h?h.id:null});if(!c&&s&&a&&this.scene.mutateElement(a,{boundElements:(a.boundElements||[]).concat({type:"text",id:g.id})}),this.setState({editingTextElement:g}),!c)if(a&&s){let x=this.scene.getElementIndex(a.id);this.scene.insertElementAtIndex(g,x+1)}else this.scene.insertElement(g);i||c||a?this.handleTextWysiwyg(g,{isExistingElement:!!c}):this.setState({newElement:g,multiElement:null})});A(this,"startImageCropping",o=>{this.store.scheduleCapture(),this.setState({croppingElementId:o.id})});A(this,"finishImageCropping",()=>{this.state.croppingElementId&&(this.store.scheduleCapture(),this.setState({croppingElementId:null}))});A(this,"handleCanvasDoubleClick",o=>{if(this.state.multiElement||this.state.activeTool.type!==this.state.preferredSelectionTool.type)return;let n=this.scene.getSelectedElements(this.state),{x:r,y:a}=rt(o,this.state);if(n.length===1&&mo(n[0])){let s=n[0];if((o[re.CTRL_OR_CMD]&&ay(s)||ry(s))&&(!this.state.selectedLinearElement?.isEditing||this.state.selectedLinearElement.elementId!==s.id)){this.actionManager.executeAction(il);return}else if(this.state.selectedLinearElement&&To(n[0])){let l=_e.getSegmentMidpointHitCoords(this.state.selectedLinearElement,{x:r,y:a},this.state,this.scene.getNonDeletedElementsMap()),c=l?_e.getSegmentMidPointIndex(this.state.selectedLinearElement,this.state,l,this.scene.getNonDeletedElementsMap()):-1;if(c&&c>-1){this.store.scheduleCapture(),_e.deleteFixedSegment(n[0],this.scene,c);let m=_e.getSegmentMidpointHitCoords({...this.state.selectedLinearElement,segmentMidPointHoveredCoords:null},{x:r,y:a},this.state,this.scene.getNonDeletedElementsMap()),p=m?_e.getSegmentMidPointIndex(this.state.selectedLinearElement,this.state,m,this.scene.getNonDeletedElementsMap()):null;this.setState({selectedLinearElement:{...this.state.selectedLinearElement,initialState:{...this.state.selectedLinearElement.initialState,segmentMidpoint:{index:p,value:l,added:!1}},segmentMidPointHoveredCoords:m}});return}}else if(this.state.selectedLinearElement?.isEditing&&this.state.selectedLinearElement.elementId===s.id&&ry(s))return}if(n.length===1&&Da(n[0])){this.startImageCropping(n[0]);return}if(Po(this.interactiveCanvas),dJ(this.state).length>0){let s=this.getElementAtPosition(r,a),l=s&&cJ(s,this.state.selectedGroupIds);if(l){this.store.scheduleCapture(),this.setState(c=>({...c,...cn({editingGroupId:l,selectedElementIds:{[s.id]:!0}},this.scene.getNonDeletedElements(),c,this)}));return}}if(Po(this.interactiveCanvas),!o[re.CTRL_OR_CMD]&&!this.state.viewModeEnabled){let s=this.getElementAtPosition(r,a);if(V1(s)){this.setState({activeEmbeddable:{element:s,state:"active"}});return}if(!this.state.selectedLinearElement?.isEditing){let l=this.getTextBindableContainerAtPosition(r,a);if(l&&(i6(l)||!nq(l.backgroundColor)||Od({point:pe(r,a),element:l,elementsMap:this.scene.getNonDeletedElementsMap(),threshold:this.getElementHitThreshold(l)}))){let c=J1(l,this.state,this.scene.getNonDeletedElementsMap());r=c.x,a=c.y}this.startTextEditing({sceneX:r,sceneY:a,insertAtParentCenter:!o.altKey,container:l})}}});A(this,"getElementLinkAtPosition",(o,n)=>{if(n&&n.locked)return;let r=this.scene.getNonDeletedElements(),a=-1;for(let i=r.length-1;i>=0;i--){let s=r[i];if(n&&s.id===n.id&&(a=i),s.link&&i>=a&&rm(s,this.scene.getNonDeletedElementsMap(),this.state,pe(o.x,o.y),this.editorInterface.formFactor==="phone"))return s}});A(this,"handleElementLinkClick",o=>{let n=Pa(pe(this.lastPointerDownEvent.clientX,this.lastPointerDownEvent.clientY),pe(this.lastPointerUpEvent.clientX,this.lastPointerUpEvent.clientY));if(!this.hitLinkElement||n>YP)return;let r=rt(this.lastPointerDownEvent,this.state),a=this.scene.getNonDeletedElementsMap(),i=rm(this.hitLinkElement,a,this.state,pe(r.x,r.y),this.editorInterface.formFactor==="phone"),s=rt(this.lastPointerUpEvent,this.state),l=rm(this.hitLinkElement,a,this.state,pe(s.x,s.y),this.editorInterface.formFactor==="phone");if(i&&l){ub();let c=this.hitLinkElement.link;if(c){c=O1(c);let m;if(this.props.onLinkOpen&&(m=oq(fe.EXCALIDRAW_LINK,o.nativeEvent),this.props.onLinkOpen({...this.hitLinkElement,link:c},m)),!m?.defaultPrevented){let p=Jj(c)?"_self":"_blank",d=window.open(void 0,p);d&&(d.opener=null,d.location=c)}}}});A(this,"getTopLayerFrameAtSceneCoords",o=>{let n=this.scene.getNonDeletedElementsMap(),r=this.scene.getNonDeletedFramesLikes().filter(a=>!a.locked&&g6(o,a,n));return r.length?r[r.length-1]:null});A(this,"handleCanvasPointerMove",o=>{this.savePointer(o.clientX,o.clientY,this.state.cursorButton),this.lastPointerMoveEvent=o.nativeEvent;let n=rt(o,this.state),{x:r,y:a}=n;this.lastPointerMoveCoords={x:r,y:a},Ne.pointers.has(o.pointerId)&&Ne.pointers.set(o.pointerId,{x:o.clientX,y:o.clientY});let i=Ne.initialScale;if(Ne.pointers.size===2&&Ne.lastCenter&&i&&Ne.initialDistance){let g=M0(Ne.pointers),x=g.x-Ne.lastCenter.x,E=g.y-Ne.lastCenter.y;Ne.lastCenter=g;let y=P0(Array.from(Ne.pointers.values())),w=this.state.activeTool.type==="freedraw"&&this.state.penMode?1:y/Ne.initialDistance,v=w?Ln(i*w):this.state.zoom.value;this.setState(I=>{let C=br({viewportX:g.x,viewportY:g.y,nextZoom:v},I);return this.translateCanvas({zoom:C.zoom,scrollX:C.scrollX+2*(x/v),scrollY:C.scrollY+2*(E/v),shouldCacheIgnoreZoom:!0}),null}),this.resetShouldCacheIgnoreZoomDebounced()}else Ne.lastCenter=Ne.initialDistance=Ne.initialScale=null;if(Ra||Ud||cy||pr(this.state))return;let l=ix(Wd,o.clientX-this.state.offsetLeft,o.clientY-this.state.offsetTop).isOverEither;if(!this.state.newElement&&!this.state.selectionElement&&!this.state.selectedElementsAreBeingDragged&&!this.state.multiElement&&(l?Po(this.interactiveCanvas):Ao(this.interactiveCanvas,this.state)),!this.state.newElement&&bk(this.state.activeTool.type)){let{originOffset:g,snapLines:x}=fk(this.scene.getNonDeletedElements(),this,{x:r,y:a},o,this.scene.getNonDeletedElementsMap());this.setState(E=>{let y=Nd(E.snapLines,x),w=E.originSnapOffset?Nd(E.originSnapOffset,g):g;return E.snapLines===y&&E.originSnapOffset===w?null:{snapLines:y,originSnapOffset:w}})}else!this.state.newElement&&!this.state.selectedElementsAreBeingDragged&&!this.state.selectionElement&&this.setState(g=>g.snapLines.length?{snapLines:[]}:null);if(this.state.selectedLinearElement?.isEditing&&!this.state.selectedLinearElement.isDragging){let g=this.state.newElement?null:_e.handlePointerMoveInEditMode(o,r,a,this);g&&g!==this.state.selectedLinearElement&&Io(()=>{this.setState({selectedLinearElement:g})})}if(Mq(this.state.activeTool.type)){let{newElement:g}=this.state;if(!g&&Bd(this.state)){let x=pe(r,a),E=this.scene.getNonDeletedElementsMap(),y=Cn(x,this.scene.getNonDeletedElements(),E,iy(this.state.zoom));y?this.setState({suggestedBinding:{element:y,midPoint:sy(x,y,E,this.state.zoom)}}):this.state.suggestedBinding&&this.setState({suggestedBinding:null})}}if(this.state.multiElement&&this.state.selectedLinearElement){let{multiElement:g,selectedLinearElement:x}=this.state,{x:E,y,points:w}=g,v=w[w.length-1],{lastCommittedPoint:I}=x;if(Ao(this.interactiveCanvas,this.state),v===I)Ol(this.state.newElement)&&Bd(this.state)&&Cn(pe(r,a),this.scene.getNonDeletedElements(),this.scene.getNonDeletedElementsMap(),iy(this.state.zoom))?(this.actionManager.executeAction(ro,"ui",{event:o.nativeEvent,sceneCoords:{x:r,y:a}}),this.setState({suggestedBinding:null,startBoundElement:null}),this.state.activeTool.locked||(Po(this.interactiveCanvas),this.setState(P=>({newElement:null,activeTool:ir(this.state,{type:this.state.preferredSelectionTool.type}),selectedElementIds:ze({...P.selectedElementIds,[g.id]:!0},P),selectedLinearElement:new _e(g,this.scene.getNonDeletedElementsMap())})))):Pa(pe(r-E,a-y),v)>=F1?(this.scene.mutateElement(g,{points:[...w,pe(r-E,a-y)]},{informMutation:!1,isDragging:!1}),sr(this.state.selectedLinearElement?.initialState,"initialState must be set"),this.setState({selectedLinearElement:{...this.state.selectedLinearElement,lastCommittedPoint:w[w.length-1],selectedPointsIndices:[g.points.length-1],initialState:{...this.state.selectedLinearElement.initialState,lastClickedPoint:g.points.length-1}}})):Be(this.interactiveCanvas,lt.POINTER);else if(w.length>2&&I&&Pa(pe(r-E,a-y),I)<F1)Be(this.interactiveCanvas,lt.POINTER),this.scene.mutateElement(g,{points:w.slice(0,-1)},{informMutation:!1,isDragging:!1}),this.setState({selectedLinearElement:{...x,selectedPointsIndices:x.selectedPointsIndices?.includes(g.points.length)?[...x.selectedPointsIndices.filter(C=>C!==g.points.length&&C!==g.points.length-1),g.points.length-1]:x.selectedPointsIndices,lastCommittedPoint:g.points[g.points.length-1],initialState:{...x.initialState,lastClickedPoint:g.points.length-1}}});else{d6(w,this.state.zoom.value)&&Be(this.interactiveCanvas,lt.POINTER);let C=this.scene.getNonDeletedElementsMap();if(ay(g)){let S=Cn(pe(r,a),this.scene.getNonDeletedElements(),C);Rr("COMPLEX_BINDINGS")&&this.handleDelayedBindModeChange(g,S)}sr(this.state.selectedLinearElement,"Expected selectedLinearElement to be set to operate on a linear element");let P=_e.handlePointerMove(o.nativeEvent,this,r,a,this.state.selectedLinearElement);P&&this.setState(P)}return}if(this.state.activeTool.type==="arrow"){let g=Cn(pe(r,a),this.scene.getNonDeletedElements(),this.scene.getNonDeletedElementsMap(),iy(this.state.zoom)),x=pe(r,a),E=this.scene.getNonDeletedElementsMap();g&&!IJ(x,g,E)&&this.setState({suggestedBinding:{element:g,midPoint:sy(x,g,E,this.state.zoom)}})}let c=!!o.buttons,m=this.state.activeTool.type==="laser";if(c||!m&&this.state.activeTool.type!=="selection"&&this.state.activeTool.type!=="lasso"&&this.state.activeTool.type!=="text"&&this.state.activeTool.type!=="eraser")return;let p=this.scene.getNonDeletedElements(),d=this.scene.getSelectedElements(this.state);if(d.length===1&&!l&&!this.state.selectedLinearElement?.isEditing){if(this.state.selectedLinearElement&&this.handleHoverSelectedLinearElement(this.state.selectedLinearElement,r,a),(!this.state.selectedLinearElement||this.state.selectedLinearElement.hoverPointIndex===-1)&&this.state.openDialog?.name!=="elementLinkSelector"&&!(d.length===1&&To(d[0]))&&!(mo(d[0])&&(this.editorInterface.userAgent.isMobileDevice||d[0].points.length===2))){let g=v6(p,this.state,r,a,this.state.zoom,o.pointerType,this.scene.getNonDeletedElementsMap(),this.editorInterface);if(g&&g.transformHandleType){Be(this.interactiveCanvas,w6(g));return}}}else if(d.length>1&&!l&&this.state.openDialog?.name!=="elementLinkSelector"){let g=I6(Fl(d),r,a,this.state.zoom,o.pointerType,this.editorInterface);if(g){Be(this.interactiveCanvas,w6({transformHandleType:g}));return}}if(ho(this.state))return;let u=this.getElementAtPosition(r,a,{preferSelected:!0,includeLockedElements:!0}),h=null;if(u&&u.locked?h=null:h=u,this.handleIframeLikeElementHover({hitElement:h,scenePointer:n,moveEvent:o})||(this.hitLinkElement=this.getElementLinkAtPosition(n,u)),this.hitLinkElement&&!this.state.selectedElementIds[this.hitLinkElement.id])Be(this.interactiveCanvas,lt.POINTER),cT(this.hitLinkElement,this.state,this.scene.getNonDeletedElementsMap());else{if(ub(),m)return;h&&(h.link||Nr(h))&&this.state.selectedElementIds[h.id]&&!this.state.contextMenu&&!this.state.showHyperlinkPopup?this.setState({showHyperlinkPopup:"info"}):this.state.activeTool.type==="text"?Be(this.interactiveCanvas,kn(h)?lt.TEXT:lt.CROSSHAIR):this.state.viewModeEnabled?Be(this.interactiveCanvas,lt.GRAB):this.state.openDialog?.name==="elementLinkSelector"?Be(this.interactiveCanvas,lt.AUTO):l?Be(this.interactiveCanvas,lt.AUTO):o[re.CTRL_OR_CMD]?Be(this.interactiveCanvas,lt.AUTO):(h||this.isHittingCommonBoundingBoxOfSelectedElements(n,d))&&!h?.locked&&(!h||!To(h)||!(h.startBinding||h.endBinding))&&(this.state.activeTool.type!=="lasso"||d.length>0)&&Be(this.interactiveCanvas,lt.MOVE),this.state.selectedLinearElement&&this.handleHoverSelectedLinearElement(this.state.selectedLinearElement,r,a)}this.state.openDialog?.name==="elementLinkSelector"&&h?this.setState(g=>({hoveredElementIds:Nd(g.hoveredElementIds,cn({editingGroupId:g.editingGroupId,selectedElementIds:{[h.id]:!0}},this.scene.getNonDeletedElements(),g,this).selectedElementIds)})):this.state.openDialog?.name==="elementLinkSelector"&&!h&&this.setState(g=>({hoveredElementIds:Nd(g.hoveredElementIds,{})}))});A(this,"handleEraser",(o,n)=>{let r=this.eraserTrail.addPointToPath(n.x,n.y,o.altKey);this.elementsPendingErasure=new Set(r),this.triggerRender()});A(this,"handleTouchMove",o=>{Yd=!0});A(this,"handleCanvasPointerDown",o=>{let n=rt(o,this.state),{x:r,y:a}=n;this.lastPointerMoveCoords={x:r,y:a};let i=o.target;if(i.setPointerCapture&&i.setPointerCapture(o.pointerId),this.maybeCleanupAfterMissingPointerUp(o.nativeEvent),this.maybeUnfollowRemoteUser(),this.state.searchMatches&&(this.setState(h=>({searchMatches:h.searchMatches&&{focusedId:null,matches:h.searchMatches.matches.map(g=>({...g,focus:!1}))}})),this.updateEditorAtom(Ox,null)),Et.get(bn)&&this.updateEditorAtom(bn,null),this.state.contextMenu&&this.setState({contextMenu:null}),this.state.snapLines&&this.setAppState({snapLines:[]}),this.state.openPopup&&this.setState({openPopup:null}),this.updateGestureOnPointerDown(o),o.pointerType==="touch"&&this.state.newElement&&this.state.newElement.type==="freedraw"){let h=this.state.newElement;this.updateScene({...h.points.length<10?{elements:this.scene.getElementsIncludingDeleted().filter(g=>g.id!==h.id)}:{},appState:{newElement:null,editingTextElement:null,startBoundElement:null,suggestedBinding:null,selectedElementIds:ze(Object.keys(this.state.selectedElementIds).filter(g=>g!==h.id).reduce((g,x)=>(g[x]=this.state.selectedElementIds[x],g),{}),this.state)},captureUpdate:this.state.openDialog?.name==="elementLinkSelector"?po.EVENTUALLY:po.NEVER});return}let s=document.getSelection();if(s?.anchorNode&&s.removeAllRanges(),this.maybeOpenContextMenuAfterPointerDownOnTouchDevices(o),!this.state.penDetected&&o.pointerType==="pen"&&this.setState(h=>({penMode:!0,penDetected:!0})),!this.editorInterface.isTouchScreen&&["pen","touch"].includes(o.pointerType)&&(this.editorInterface=G1(this.editorInterface,{isTouchScreen:!0})),Ud||(this.lastPointerDownEvent=o,this.handleCanvasPanUsingWheelOrSpaceDrag(o)))return;if(this.setState({lastPointerDownWith:o.pointerType,cursorButton:"down"}),this.savePointer(o.clientX,o.clientY,"down"),o.button===Aa.ERASER&&this.state.activeTool.type!==ar.eraser){this.setState({activeTool:ir(this.state,{type:ar.eraser,lastActiveToolBeforeEraser:this.state.activeTool})},()=>{this.handleCanvasPointerDown(o);let h=()=>{g(),x?.(),ho(this.state)&&this.setState({activeTool:ir(this.state,{...this.state.activeTool.lastActiveTool||{type:ar.selection},lastActiveToolBeforeEraser:null})})},g=ht(window,fe.POINTER_UP,h,{once:!0}),x;requestAnimationFrame(()=>{x=this.missingPointerEventCleanupEmitter.once(h)})});return}if(o.button!==Aa.MAIN&&o.button!==Aa.TOUCH&&o.button!==Aa.ERASER||Ne.pointers.size>1)return;let l=this.initialPointerDownState(o);if(this.setState({selectedElementsAreBeingDragged:!1}),this.handleDraggingScrollBar(o,l)||(this.clearSelectionIfNotUsingSelection(),this.updateBindingEnabledOnPointerMove(o),this.handleSelectionOnPointerDown(o,l))||!(!this.state.penMode||o.pointerType!=="touch"||this.state.activeTool.type==="selection"||this.state.activeTool.type==="lasso"||this.state.activeTool.type==="text"||this.state.activeTool.type==="image"))return;if(this.state.activeTool.type==="lasso"){let h=l.hit.element&&this.isASelectedElement(l.hit.element);!l.hit.hasHitCommonBoundingBoxOfSelectedElements&&!l.resize.handleType&&!h&&(this.lassoTrail.startPath(l.origin.x,l.origin.y,o.shiftKey),l.drag.blockDragging=this.editorInterface.formFactor==="desktop"),this.editorInterface.formFactor!=="desktop"&&l.hit.element&&!h&&(this.setState(g=>{let x={...g.selectedElementIds,[l.hit.element.id]:!0},E=[];Object.keys(g.selectedElementIds).forEach(w=>{let v=this.scene.getElement(w);v&&E.push(v)});let y=l.hit.element;if(Qt(y))Q1(E,y.id).forEach(w=>{delete x[w.id]});else if(y.frameId)x[y.frameId]&&delete x[y.id];else{let w=y.groupIds,v=new Set(w.flatMap(I=>Li(this.scene.getNonDeletedElements(),I)).filter(I=>Qt(I)).map(I=>I.id));v.size>0&&E.forEach(I=>{I.frameId&&v.has(I.frameId)&&(delete x[I.id],I.groupIds.flatMap(C=>Li(this.scene.getNonDeletedElements(),C)).forEach(C=>{delete x[C.id]}))})}return{...cn({editingGroupId:g.editingGroupId,selectedElementIds:x},this.scene.getNonDeletedElements(),g,this),showHyperlinkPopup:y.link||Nr(y)?"info":!1}}),l.hit.wasAddedToSelection=!0)}else this.state.activeTool.type==="text"?this.handleTextOnPointerDown(o,l):this.state.activeTool.type==="arrow"||this.state.activeTool.type==="line"?this.handleLinearElementOnPointerDown(o,this.state.activeTool.type,l):this.state.activeTool.type==="freedraw"?this.handleFreeDrawElementOnPointerDown(o,this.state.activeTool.type,l):this.state.activeTool.type==="custom"?Ao(this.interactiveCanvas,this.state):this.state.activeTool.type===ar.frame||this.state.activeTool.type===ar.magicframe?this.createFrameElementOnPointerDown(l,this.state.activeTool.type):this.state.activeTool.type==="laser"?this.laserTrails.startPath(l.lastCoords.x,l.lastCoords.y):this.state.activeTool.type!=="eraser"&&this.state.activeTool.type!=="hand"&&this.state.activeTool.type!=="image"&&this.createGenericElementOnPointerDown(this.state.activeTool.type,l);this.props?.onPointerDown?.(this.state.activeTool,l),this.onPointerDownEmitter.trigger(this.state.activeTool,l,o),this.state.activeTool.type==="eraser"&&this.eraserTrail.startPath(l.lastCoords.x,l.lastCoords.y);let m=this.onPointerMoveFromPointerDownHandler(l),p=this.onPointerUpFromPointerDownHandler(l),d=this.onKeyDownFromPointerDownHandler(l),u=this.onKeyUpFromPointerDownHandler(l);this.missingPointerEventCleanupEmitter.once(h=>p(h||o.nativeEvent)),(!this.state.viewModeEnabled||this.state.activeTool.type==="laser")&&(window.addEventListener(fe.POINTER_MOVE,m),window.addEventListener(fe.POINTER_UP,p),window.addEventListener(fe.KEYDOWN,d),window.addEventListener(fe.KEYUP,u),l.eventListeners.onMove=m,l.eventListeners.onUp=p,l.eventListeners.onKeyUp=u,l.eventListeners.onKeyDown=d)});A(this,"handleCanvasPointerUp",o=>{Rr("COMPLEX_BINDINGS")&&this.resetDelayedBindMode(),this.removePointer(o),this.lastPointerUpEvent=o;let n=rt({clientX:o.clientX,clientY:o.clientY},this.state),{x:r,y:a}=n;if(this.lastPointerMoveCoords={x:r,y:a},!this.handleIframeLikeCenterClick()){if(this.editorInterface.isTouchScreen){let i=this.getElementAtPosition(n.x,n.y,{includeLockedElements:!0});this.hitLinkElement=this.getElementLinkAtPosition(n,i)}this.hitLinkElement&&!this.state.selectedElementIds[this.hitLinkElement.id]?this.handleElementLinkClick(o):this.state.viewModeEnabled&&this.setState({activeEmbeddable:null,selectedElementIds:{}})}});A(this,"maybeOpenContextMenuAfterPointerDownOnTouchDevices",o=>{o.pointerType==="touch"&&(Yd=!1,Na?Yd=!0:Na=window.setTimeout(()=>{Na=0,Yd||this.handleCanvasContextMenu(o)},Vj))});A(this,"resetContextMenuTimer",()=>{clearTimeout(Na),Na=0,Yd=!1});A(this,"maybeCleanupAfterMissingPointerUp",o=>{$d?.(),this.missingPointerEventCleanupEmitter.trigger(o).clear()});A(this,"handleCanvasPanUsingWheelOrSpaceDrag",o=>{if(!(Ne.pointers.size<=1&&(o.button===Aa.WHEEL||o.button===Aa.MAIN&&Ra||pr(this.state)||this.state.viewModeEnabled&&this.state.activeTool.type!=="laser")))return!1;Ud=!0,this.focusContainer(),this.state.editingTextElement||o.preventDefault();let n=!1,r=typeof window===void 0?!1:/Linux/.test(window.navigator.platform);Be(this.interactiveCanvas,lt.GRABBING);let{clientX:a,clientY:i}=o,s=Fu(c=>{let m=a-c.clientX,p=i-c.clientY;if(a=c.clientX,i=c.clientY,r&&!n&&(Math.abs(m)>1||Math.abs(p)>1)){n=!0;let d=h=>{document.body.removeEventListener(fe.PASTE,d),h.stopPropagation()},u=()=>{setTimeout(()=>{document.body.removeEventListener(fe.PASTE,d),window.removeEventListener(fe.POINTER_UP,u)},100)};document.body.addEventListener(fe.PASTE,d),window.addEventListener(fe.POINTER_UP,u)}this.translateCanvas({scrollX:this.state.scrollX-m/this.state.zoom.value,scrollY:this.state.scrollY-p/this.state.zoom.value})}),l=pt($d=()=>{$d=null,Ud=!1,Ra||(this.state.viewModeEnabled&&this.state.activeTool.type!=="laser"?Be(this.interactiveCanvas,lt.GRAB):Ao(this.interactiveCanvas,this.state)),this.setState({cursorButton:"up"}),this.savePointer(o.clientX,o.clientY,"up"),window.removeEventListener(fe.POINTER_MOVE,s),window.removeEventListener(fe.POINTER_UP,l),window.removeEventListener(fe.BLUR,l),s.flush()});return window.addEventListener(fe.BLUR,l),window.addEventListener(fe.POINTER_MOVE,s,{passive:!0}),window.addEventListener(fe.POINTER_UP,l),!0});A(this,"clearSelectionIfNotUsingSelection",()=>{Fg(this.state.activeTool.type)||this.setState({selectedElementIds:ze({},this.state),selectedGroupIds:{},editingGroupId:null,activeEmbeddable:null})});A(this,"handleSelectionOnPointerDown",(o,n)=>{if(Fg(this.state.activeTool.type)){let r=this.scene.getNonDeletedElements(),a=this.scene.getNonDeletedElementsMap(),i=this.scene.getSelectedElements(this.state);if(i.length===1&&!this.state.selectedLinearElement?.isEditing&&!To(i[0])&&!(mo(i[0])&&(this.editorInterface.userAgent.isMobileDevice||i[0].points.length===2))&&!(this.state.selectedLinearElement&&this.state.selectedLinearElement.hoverPointIndex!==-1)){let s=v6(r,this.state,n.origin.x,n.origin.y,this.state.zoom,o.pointerType,this.scene.getNonDeletedElementsMap(),this.editorInterface);s!=null&&(s.transformHandleType==="rotation"?(this.setState({resizingElement:s.element}),n.resize.handleType=s.transformHandleType):(this.state.croppingElementId||this.setState({resizingElement:s.element}),n.resize.handleType=s.transformHandleType))}else i.length>1&&(n.resize.handleType=I6(Fl(i),n.origin.x,n.origin.y,this.state.zoom,o.pointerType,this.editorInterface));if(n.resize.handleType)n.resize.isResizing=!0,n.resize.offset=H1(gJ(n.resize.handleType,i,a,n.origin.x,n.origin.y)),i.length===1&&mo(i[0])&&i[0].points.length===2&&(n.resize.arrowDirection=hJ(n.resize.handleType,i[0]));else{if(this.state.selectedLinearElement){let d=this.state.selectedLinearElement,u=_e.handlePointerDown(o,this,this.store,n.origin,d,this.scene);if(u.hitElement&&(n.hit.element=u.hitElement),u.linearElementEditor&&this.setState({selectedLinearElement:u.linearElementEditor}),u.didAddPoint)return!0;let h=this.scene.getNonDeletedElementsMap(),g=_e.getElement(d.elementId,h);if(g&&lr(g)){let{hitFocusPoint:x,pointerOffset:E}=kJ(g,n,h,this.state);if(x)return this.setState({selectedLinearElement:{...d,hoveredFocusPointBinding:x,draggedFocusPointBinding:x,pointerOffset:E}}),!1}}let s=this.getElementsAtPosition(n.origin.x,n.origin.y,{includeLockedElements:!0}),l=s.filter(d=>!d.locked),c=this.getElementAtPosition(n.origin.x,n.origin.y,{allHitElements:s});if((!c||c.id!==this.state.activeLockedId)&&this.setState({activeLockedId:null}),c&&c.locked&&!l.some(d=>this.state.selectedElementIds[d.id])?n.hit.element=null:n.hit.element=n.hit.element??this.getElementAtPosition(n.origin.x,n.origin.y),this.hitLinkElement=this.getElementLinkAtPosition(n.origin,c),this.hitLinkElement)return!0;if(this.state.croppingElementId&&n.hit.element?.id!==this.state.croppingElementId&&this.finishImageCropping(),n.hit.element&&this.getElementLinkAtPosition({x:n.origin.x,y:n.origin.y},n.hit.element))return!1;n.hit.allHitElements=l;let m=n.hit.element,p=n.hit.allHitElements.some(d=>this.isASelectedElement(d));if((m===null||!p)&&!o.shiftKey&&!n.hit.hasHitCommonBoundingBoxOfSelectedElements&&(!this.state.selectedLinearElement?.isEditing||m&&m?.id!==this.state.selectedLinearElement?.elementId)&&this.clearSelection(m),this.state.selectedLinearElement?.isEditing)this.setState(d=>({selectedLinearElement:d.selectedLinearElement?{...d.selectedLinearElement,isEditing:!!m&&m.id===this.state.selectedLinearElement?.elementId}:null,selectedElementIds:d.selectedLinearElement?ze({[d.selectedLinearElement.elementId]:!0},this.state):ze({},d)}));else if(m!=null){if(o[re.CTRL_OR_CMD])return o.altKey?(this.state.openDialog?.name==="elementLinkSelector"&&this.setOpenDialog(null),this.lassoTrail.startPath(n.origin.x,n.origin.y,o.shiftKey),this.setActiveTool({type:"lasso",fromSelection:!0}),!1):(this.state.selectedElementIds[m.id]||(n.hit.wasAddedToSelection=!0),this.setState(d=>({...lJ(d,m),previousSelectedElementIds:this.state.selectedElementIds})),!1);this.state.selectedElementIds[m.id]||(this.state.editingGroupId&&!y6(m,this.state.editingGroupId)&&this.setState({selectedElementIds:ze({},this.state),selectedGroupIds:{},editingGroupId:null,activeEmbeddable:null}),!p&&!n.hit.hasHitCommonBoundingBoxOfSelectedElements&&(this.setState(d=>{let u={...d.selectedElementIds,[m.id]:!0},h=[];if(Object.keys(d.selectedElementIds).forEach(g=>{let x=this.scene.getElement(g);x&&h.push(x)}),Qt(m))Q1(h,m.id).forEach(g=>{delete u[g.id]});else if(m.frameId)u[m.frameId]&&delete u[m.id];else{let g=m.groupIds,x=new Set(g.flatMap(E=>Li(this.scene.getNonDeletedElements(),E)).filter(E=>Qt(E)).map(E=>E.id));x.size>0&&h.forEach(E=>{E.frameId&&x.has(E.frameId)&&(delete u[E.id],E.groupIds.flatMap(y=>Li(this.scene.getNonDeletedElements(),y)).forEach(y=>{delete u[y.id]}))})}return d.openDialog?.name==="elementLinkSelector"&&(m.groupIds.some(g=>d.selectedGroupIds[g])||(u={[m.id]:!0})),{...cn({editingGroupId:d.editingGroupId,selectedElementIds:u},this.scene.getNonDeletedElements(),d,this),showHyperlinkPopup:m.link||Nr(m)?"info":!1}}),n.hit.wasAddedToSelection=!0))}this.setState({previousSelectedElementIds:this.state.selectedElementIds})}}return!1});A(this,"handleTextOnPointerDown",(o,n)=>{if(this.state.editingTextElement)return;let r=n.origin.x,a=n.origin.y,i=this.getElementAtPosition(r,a,{includeBoundTextElement:!0}),s=this.getTextBindableContainerAtPosition(r,a);i6(i)&&(s=i,r=i.x+i.width/2,a=i.y+i.height/2),this.startTextEditing({sceneX:r,sceneY:a,insertAtParentCenter:!o.altKey,container:s,autoEdit:!1}),Po(this.interactiveCanvas),this.state.activeTool.locked||this.setState({activeTool:ir(this.state,{type:this.state.preferredSelectionTool.type})})});A(this,"handleFreeDrawElementOnPointerDown",(o,n,r)=>{let[a,i]=Jt(r.origin.x,r.origin.y,null),s=this.getTopLayerFrameAtSceneCoords({x:a,y:i}),l=o.pressure===.5,c=vq({type:n,x:a,y:i,strokeColor:this.state.currentItemStrokeColor,backgroundColor:this.state.currentItemBackgroundColor,fillStyle:this.state.currentItemFillStyle,strokeWidth:this.state.currentItemStrokeWidth,strokeStyle:this.state.currentItemStrokeStyle,roughness:this.state.currentItemRoughness,opacity:this.state.currentItemOpacity,roundness:null,simulatePressure:l,locked:!1,frameId:s?s.id:null,points:[pe(0,0)],pressures:l?[]:[o.pressure]});this.scene.insertElement(c),this.setState(p=>{let d={...p.selectedElementIds};return delete d[c.id],{selectedElementIds:ze(d,p)}});let m=Cn(pe(r.origin.x,r.origin.y),this.scene.getNonDeletedElements(),this.scene.getNonDeletedElementsMap());this.setState({newElement:c,startBoundElement:m,suggestedBinding:null})});A(this,"insertIframeElement",({sceneX:o,sceneY:n,width:r,height:a})=>{let[i,s]=Jt(o,n,this.lastPointerDownEvent?.[re.CTRL_OR_CMD]?null:this.getEffectiveGridSize()),l=Iq({type:"iframe",x:i,y:s,strokeColor:"transparent",backgroundColor:"transparent",fillStyle:this.state.currentItemFillStyle,strokeWidth:this.state.currentItemStrokeWidth,strokeStyle:this.state.currentItemStrokeStyle,roughness:this.state.currentItemRoughness,roundness:this.getCurrentItemRoundness("iframe"),opacity:this.state.currentItemOpacity,locked:!1,width:r,height:a});return this.scene.insertElement(l),l});A(this,"insertEmbeddableElement",({sceneX:o,sceneY:n,link:r})=>{let[a,i]=Jt(o,n,this.lastPointerDownEvent?.[re.CTRL_OR_CMD]?null:this.getEffectiveGridSize()),s=Hg(r);if(!s)return;s.error instanceof URIError&&this.setToast({message:f("toast.unrecognizedLinkFormat"),closable:!0});let l=o6({type:"embeddable",x:a,y:i,strokeColor:"transparent",backgroundColor:"transparent",fillStyle:this.state.currentItemFillStyle,strokeWidth:this.state.currentItemStrokeWidth,strokeStyle:this.state.currentItemStrokeStyle,roughness:this.state.currentItemRoughness,roundness:this.getCurrentItemRoundness("embeddable"),opacity:this.state.currentItemOpacity,locked:!1,width:s.intrinsicSize.w,height:s.intrinsicSize.h,link:r});return this.scene.insertElement(l),l});A(this,"newImagePlaceholder",({sceneX:o,sceneY:n,addToFrameUnderCursor:r=!0})=>{let[a,i]=Jt(o,n,this.lastPointerDownEvent?.[re.CTRL_OR_CMD]?null:this.getEffectiveGridSize()),s=r?this.getTopLayerFrameAtSceneCoords({x:a,y:i}):null,l=100/this.state.zoom.value;return W1({type:"image",strokeColor:this.state.currentItemStrokeColor,backgroundColor:this.state.currentItemBackgroundColor,fillStyle:this.state.currentItemFillStyle,strokeWidth:this.state.currentItemStrokeWidth,strokeStyle:this.state.currentItemStrokeStyle,roughness:this.state.currentItemRoughness,roundness:null,opacity:this.state.currentItemOpacity,locked:!1,frameId:s?s.id:null,x:a-l/2,y:i-l/2,width:l,height:l})});A(this,"handleLinearElementOnPointerDown",(o,n,r)=>{if(o.ctrlKey&&Io(()=>{this.setState({isBindingEnabled:!1})}),this.state.multiElement){let{multiElement:a,selectedLinearElement:i}=this.state;if(sr(i,"selectedLinearElement is expected to be set"),a.type==="line"&&d6(a.points,this.state.zoom.value)){Io(()=>{this.setState({selectedLinearElement:{...i,lastCommittedPoint:a.points[a.points.length-1],initialState:{...i.initialState,lastClickedPoint:-1}}})}),this.actionManager.executeAction(ro);return}if(To(a)&&a.points.length>1){this.actionManager.executeAction(ro,"ui",{event:o.nativeEvent,sceneCoords:{x:r.origin.x,y:r.origin.y}});return}let{x:s,y:l}=a,{lastCommittedPoint:c}=i,m=Bd(this.state)&&Cn(pe(this.lastPointerMoveCoords?.x??s+a.points[a.points.length-1][0],this.lastPointerMoveCoords?.y??l+a.points[a.points.length-1][1]),this.scene.getNonDeletedElements(),this.scene.getNonDeletedElementsMap());if(lr(a)&&m||a.points.length>1&&c&&Pa(pe(r.origin.x-s,r.origin.y-l),c)<F1){this.actionManager.executeAction(ro,"ui",{event:o.nativeEvent,sceneCoords:{x:r.origin.x,y:r.origin.y}});return}this.setState(p=>({selectedElementIds:ze({...p.selectedElementIds,[a.id]:!0},p)})),Be(this.interactiveCanvas,lt.POINTER)}else{let[a,i]=Jt(r.origin.x,r.origin.y,o[re.CTRL_OR_CMD]?null:this.getEffectiveGridSize()),s=this.getTopLayerFrameAtSceneCoords({x:a,y:i}),{currentItemStartArrowhead:l,currentItemEndArrowhead:c}=this.state,[m,p]=n==="arrow"?[l,c]:[null,null],d=n==="arrow"?Tq({type:n,x:a,y:i,strokeColor:this.state.currentItemStrokeColor,backgroundColor:this.state.currentItemBackgroundColor,fillStyle:this.state.currentItemFillStyle,strokeWidth:this.state.currentItemStrokeWidth,strokeStyle:this.state.currentItemStrokeStyle,roughness:this.state.currentItemRoughness,opacity:this.state.currentItemOpacity,roundness:this.state.currentItemArrowType===La.round?{type:_g.PROPORTIONAL_RADIUS}:null,startArrowhead:m,endArrowhead:p,locked:!1,frameId:s?s.id:null,elbowed:this.state.currentItemArrowType===La.elbow,fixedSegments:this.state.currentItemArrowType===La.elbow?[]:null}):kq({type:n,x:a,y:i,strokeColor:this.state.currentItemStrokeColor,backgroundColor:this.state.currentItemBackgroundColor,fillStyle:this.state.currentItemFillStyle,strokeWidth:this.state.currentItemStrokeWidth,strokeStyle:this.state.currentItemStrokeStyle,roughness:this.state.currentItemRoughness,opacity:this.state.currentItemOpacity,roundness:this.state.currentItemRoundness==="round"?{type:_g.PROPORTIONAL_RADIUS}:null,locked:!1,frameId:s?s.id:null}),u=pe(r.origin.x,r.origin.y),h=this.scene.getNonDeletedElementsMap(),g=Bd(this.state)?Cn(u,this.scene.getNonDeletedElements(),h):null;this.scene.mutateElement(d,{points:[pe(0,0),pe(0,0)]}),this.scene.insertElement(d),lr(d)&&wJ(d,new Map([[0,{point:pe(0,0),isDragging:!1}]]),u[0],u[1],this.scene,this.state,{newArrow:!0,altKey:o.altKey,initialBinding:!0,angleLocked:UP(o.nativeEvent)}),Io(()=>{this.setState(x=>{let E=null,y=x.selectedElementIds;if(mo(d)){E=new _e(d,this.scene.getNonDeletedElementsMap());let w=d.points.length-1;E={...E,selectedPointsIndices:[w],initialState:{...E.initialState,arrowStartIsInside:o.altKey,lastClickedPoint:w,origin:pe(r.origin.x,r.origin.y)}}}return y=this.state.activeTool.locked?x.selectedElementIds:ze({[d.id]:!0},x),{...x,bindMode:"orbit",newElement:d,startBoundElement:g,suggestedBinding:g&&lr(d)?{element:g,midPoint:sy(u,g,h,this.state.zoom)}:null,selectedElementIds:y,selectedLinearElement:E}})}),lr(d)&&Rr("COMPLEX_BINDINGS")&&this.handleDelayedBindModeChange(d,g)}});A(this,"createGenericElementOnPointerDown",(o,n)=>{let[r,a]=Jt(n.origin.x,n.origin.y,this.lastPointerDownEvent?.[re.CTRL_OR_CMD]?null:this.getEffectiveGridSize()),i=this.getTopLayerFrameAtSceneCoords({x:r,y:a}),s={x:r,y:a,strokeColor:this.state.currentItemStrokeColor,backgroundColor:this.state.currentItemBackgroundColor,fillStyle:this.state.currentItemFillStyle,strokeWidth:this.state.currentItemStrokeWidth,strokeStyle:this.state.currentItemStrokeStyle,roughness:this.state.currentItemRoughness,opacity:this.state.currentItemOpacity,roundness:this.getCurrentItemRoundness(o),locked:!1,frameId:i?i.id:null},l;o==="embeddable"?l=o6({type:"embeddable",...s}):l=Cq({type:o,...s}),l.type==="selection"?this.setState({selectionElement:l}):(this.scene.insertElement(l),this.setState({multiElement:null,newElement:l}))});A(this,"createFrameElementOnPointerDown",(o,n)=>{let[r,a]=Jt(o.origin.x,o.origin.y,this.lastPointerDownEvent?.[re.CTRL_OR_CMD]?null:this.getEffectiveGridSize()),i={x:r,y:a,opacity:this.state.currentItemOpacity,locked:!1,...ln},s=n===ar.magicframe?n6(i):t6(i);this.scene.insertElement(s),this.setState({multiElement:null,newElement:s})});A(this,"restoreReadyToEraseElements",()=>{this.elementsPendingErasure=new Set,this.triggerRender()});A(this,"eraseElements",()=>{let o=!1;this.elementsPendingErasure.forEach(r=>{let a=this.scene.getElement(r);if(lr(a)){if(a.startBinding){let i=this.scene.getElement(a.startBinding.elementId);Gg(i,this.scene.getElementsMapIncludingDeleted(),{boundElements:i.boundElements.filter(s=>s.id!==a.id)})}if(a.endBinding){let i=this.scene.getElement(a.endBinding.elementId);Gg(i,this.scene.getElementsMapIncludingDeleted(),{boundElements:i.boundElements.filter(s=>s.id!==a.id)})}}else X1(a)&&a.boundElements?.forEach(i=>{if(i.type==="arrow"){let s=this.scene.getElement(i.id);s?.startBinding?.elementId===a.id&&Gg(s,this.scene.getElementsMapIncludingDeleted(),{startBinding:null}),s?.endBinding?.elementId===a.id&&Gg(s,this.scene.getElementsMapIncludingDeleted(),{endBinding:null})}})});let n=this.scene.getElementsIncludingDeleted().map(r=>this.elementsPendingErasure.has(r.id)||r.frameId&&this.elementsPendingErasure.has(r.frameId)||$1(r)&&this.elementsPendingErasure.has(r.containerId)?(o=!0,_a(r,{isDeleted:!0})):r);this.elementsPendingErasure=new Set,o&&(this.store.scheduleCapture(),this.scene.replaceAllElements(n))});A(this,"initializeImage",async(o,n)=>{if(!dh(n))throw new Error(f("errors.unsupportedFileType"));let r=n.type;if(Be(this.interactiveCanvas,"wait"),r===rr.svg)try{n=gh(p6(await n.text()),n.name)}catch(l){throw console.warn(l),new Error(f("errors.svgImageInsertError"))}let a=await(this.props.generateIdForFile?.(n)||bE(n));if(!a)throw console.warn("Couldn't generate file id or the supplied `generateIdForFile` didn't resolve to one."),new Error(f("errors.imageInsertError"));if(!this.files[a]?.dataURL){try{n=await cm(n,{maxWidthOrHeight:Oj})}catch(l){console.error("Error trying to resizing image file on insertion",l)}if(n.size>VP)throw new Error(f("errors.fileTooBig",{maxSize:`${Math.trunc(VP/1024/1024)}MB`}))}let s=this.files[a]?.dataURL||await Vi(n);return new Promise(async(l,c)=>{try{let m=this.getLatestInitializedImageElement(o,a);if(this.addMissingFiles([{mimeType:r,id:a,dataURL:s,created:Date.now(),lastRetrieved:Date.now()}]),!this.imageCache.get(a)){this.addNewImagesToImageCache();let{erroredFiles:d}=await this.updateImageCache([m]);if(d.size)throw new Error("Image cache update resulted with an error.")}let p=await this.imageCache.get(a)?.image;if(p&&this.state.newElement?.id!==m.id){m=this.getLatestInitializedImageElement(o,a);let d=this.getImageNaturalDimensions(m,p);Object.assign(m,d)}l(m)}catch(m){console.error(m),c(new Error(f("errors.imageInsertError")))}})});A(this,"getLatestInitializedImageElement",(o,n)=>{let r=this.scene.getElement(o.id)??o;return _a(r,{fileId:n})});A(this,"onImageToolbarButtonClick",async()=>{try{let o=this.state.width/2+this.state.offsetLeft,n=this.state.height/2+this.state.offsetTop,{x:r,y:a}=rt({clientX:o,clientY:n},this.state),i=await om({description:"Image",extensions:Object.keys(Hj),multiple:!0});this.insertImages(i,r,a)}catch(o){o.name!=="AbortError"?console.error(o):console.warn(o),this.setState({newElement:null,activeTool:ir(this.state,{type:this.state.preferredSelectionTool.type})},()=>{this.actionManager.executeAction(ro)})}});A(this,"getImageNaturalDimensions",(o,n)=>{let r=Math.max(this.state.height-120,160),a=Math.min(r,Math.floor(this.state.height*.5)/this.state.zoom.value),i=Math.min(n.naturalHeight,a),s=i*(n.naturalWidth/n.naturalHeight),l=o.x+o.width/2-s/2,c=o.y+o.height/2-i/2;return{x:l,y:c,width:s,height:i,crop:null}});A(this,"updateImageCache",async(o,n=this.files)=>{let{updatedFiles:r,erroredFiles:a}=await Bq({imageCache:this.imageCache,fileIds:o.map(i=>i.fileId),files:n});return a.size&&(this.store.scheduleAction(po.NEVER),this.scene.replaceAllElements(this.scene.getElementsIncludingDeleted().map(i=>Fd(i)&&a.has(i.fileId)?_a(i,{status:"error"}):i))),{updatedFiles:r,erroredFiles:a}});A(this,"addNewImagesToImageCache",async(o=Nq(this.scene.getNonDeletedElements()),n=this.files)=>{let r=o.filter(a=>!a.isDeleted&&!this.imageCache.has(a.fileId));if(r.length){let{updatedFiles:a}=await this.updateImageCache(r,n);if(a.size)for(let i of r)a.has(i.fileId)&&zd.delete(i);a.size&&this.scene.triggerUpdate()}});A(this,"scheduleImageRefresh",Rj(()=>{this.addNewImagesToImageCache()},Gj));A(this,"updateBindingEnabledOnPointerMove",o=>{let n=wq(o);this.state.isBindingEnabled!==n&&this.setState({isBindingEnabled:n})});A(this,"handleInteractiveCanvasRef",o=>{o!==null?(this.interactiveCanvas=o,this.interactiveCanvas.addEventListener(fe.TOUCH_START,this.onTouchStart,{passive:!1}),this.interactiveCanvas.addEventListener(fe.TOUCH_END,this.onTouchEnd)):(this.interactiveCanvas?.removeEventListener(fe.TOUCH_START,this.onTouchStart),this.interactiveCanvas?.removeEventListener(fe.TOUCH_END,this.onTouchEnd))});A(this,"insertImages",async(o,n,r)=>{let a=50/this.state.zoom.value,i=M6(o.map(()=>this.newImagePlaceholder({sceneX:n,sceneY:r})),n,r,a);i.forEach(d=>this.scene.insertElement(d));let s=await Promise.all(i.map(async(d,u)=>{try{return await this.initializeImage(d,await ec(o[u]))}catch(h){return this.setState({errorMessage:h.message||f("errors.imageInsertError")}),_a(d,{isDeleted:!0})}})),l=Bg(s),c=M6(s.filter(d=>!d.isDeleted),n,r,a),m=Bg(c),p=this.scene.getElementsIncludingDeleted().map(d=>m.get(d.id)??l.get(d.id)??d);this.updateScene({appState:{selectedElementIds:ze(Object.fromEntries(c.map(d=>[d.id,!0])),this.state)},elements:p,captureUpdate:po.IMMEDIATELY}),this.setState({},()=>{this.actionManager.executeAction(ro)})});A(this,"handleAppOnDrop",async o=>{let{x:n,y:r}=rt(o,this.state),a=await As(o),i=a.getFiles();if(i.length===1){let{file:p,fileHandle:d}=i[0];if(p&&(p.type===rr.png||p.type===rr.svg))try{let u=await lm(p,this.state,this.scene.getElementsIncludingDeleted(),d);this.syncActionResult({...u,appState:{...u.appState||this.state,isLoading:!1},replaceFiles:!0,captureUpdate:po.IMMEDIATELY});return}catch(u){if(u.name!=="EncodingError")throw new Error(f("alerts.couldNotLoadInvalidFile"))}}let s=i.map(p=>p.file).filter(p=>dh(p));if(s.length>0&&this.isToolSupported("image"))return this.insertImages(s,n,r);let l=a.getData(rr.excalidrawlibIds),c=a.getData(rr.excalidrawlib);if(l||c){try{let p=null;if(l){let{itemIds:d}=JSON.parse(l);p=(await this.library.getLatestLibrary()).filter(h=>d.includes(h.id))}else c&&(p=fE(c));p?.length&&(p=p.map(d=>({...d,elements:Y1({type:"everything",elements:d.elements,randomizeSeed:!0}).duplicatedElements})),this.addElementsFromPasteOrLibrary({elements:Zs(p),position:o,files:null}))}catch(p){this.setState({errorMessage:p.message})}return}if(i.length>0){let{file:p,fileHandle:d}=i[0];p&&await this.loadFileToCanvas(p,d)}let m=a.findByType(rr.text);if(m){let p=m.value;if(p&&j1(p,this.props.validateEmbeddable)&&(/^(http|https):\/\/[^\s/$.?#].[^\s]*$/.test(p)||Hg(p)?.type==="video")){let d=this.insertEmbeddableElement({sceneX:n,sceneY:r,link:O1(p)});d&&(this.store.scheduleCapture(),this.setState({selectedElementIds:{[d.id]:!0}}))}}});A(this,"loadFileToCanvas",async(o,n)=>{o=await ec(o);try{let r=this.scene.getElementsIncludingDeleted(),a;try{a=await mh(o,this.state,r,n)}catch(i){let s=i instanceof aE;if(s&&i.code==="IMAGE_NOT_CONTAINS_SCENE_DATA"&&!this.isToolSupported("image")){this.setState({isLoading:!1,errorMessage:f("errors.imageToolNotSupported")});return}let l=s?f("alerts.cannotRestoreFromImage"):f("alerts.couldNotLoadInvalidFile");this.setState({isLoading:!1,errorMessage:l})}if(!a)return;a.type===rr.excalidraw?(O6(r.concat(a.data.elements)),this.store.scheduleMicroAction({action:po.NEVER,elements:r,appState:void 0}),this.setState({isLoading:!0}),this.syncActionResult({...a.data,appState:{...a.data.appState||this.state,isLoading:!1},replaceFiles:!0,captureUpdate:po.IMMEDIATELY})):a.type===rr.excalidrawlib&&await this.library.updateLibrary({libraryItems:o,merge:!0,openLibraryMenu:!0}).catch(i=>{console.error(i),this.setState({errorMessage:f("errors.importLibraryError")})})}catch(r){this.setState({isLoading:!1,errorMessage:r.message})}});A(this,"handleCanvasContextMenu",o=>{if(o.preventDefault(),("pointerType"in o.nativeEvent&&o.nativeEvent.pointerType==="touch"||"pointerType"in o.nativeEvent&&o.nativeEvent.pointerType==="pen"&&o.button!==Aa.SECONDARY)&&this.state.activeTool.type!==this.state.preferredSelectionTool.type)return;let{x:n,y:r}=rt(o,this.state),a=this.getElementAtPosition(n,r,{preferSelected:!0,includeLockedElements:!0}),i=this.scene.getSelectedElements(this.state),s=this.isHittingCommonBoundingBoxOfSelectedElements({x:n,y:r},i),l=a||s?"element":"canvas",c=this.excalidrawContainerRef.current,{top:m,left:p}=c.getBoundingClientRect(),d=o.clientX-p,u=o.clientY-m;be("contextMenu","openContextMenu",l),this.setState({...a&&!this.state.selectedElementIds[a.id]?{...this.state,...cn({editingGroupId:this.state.editingGroupId,selectedElementIds:{[a.id]:!0}},this.scene.getNonDeletedElements(),this.state,this),selectedLinearElement:mo(a)?new _e(a,this.scene.getNonDeletedElementsMap()):null}:this.state,showHyperlinkPopup:!1},()=>{this.setState({contextMenu:{top:u,left:d,items:this.getContextMenuItems(l)}})})});A(this,"maybeDragNewGenericElement",(o,n,r=!0)=>{let a=this.state.selectionElement,i=o.lastCoords;if(a&&o.boxSelection.hasOccurred&&this.state.activeTool.type!=="eraser"){T6({newElement:a,elementType:this.state.activeTool.type,originX:o.origin.x,originY:o.origin.y,x:i.x,y:i.y,width:Bl(o.origin.x,i.x),height:Bl(o.origin.y,i.y),shouldMaintainAspectRatio:Dd(n),shouldResizeFromCenter:!1,scene:this.scene,zoom:this.state.zoom.value,informMutation:!1});return}let s=this.state.newElement;if(!s)return;let[l,c]=Jt(i.x,i.y,n[re.CTRL_OR_CMD]?null:this.getEffectiveGridSize()),m=Fd(s)&&this.imageCache.get(s.fileId)?.image,p=m&&!(m instanceof Promise)?m.width/m.height:null;this.maybeCacheReferenceSnapPoints(n,[s]);let{snapOffset:d,snapLines:u}=hk(s,this,n,{x:o.originInGrid.x+(this.state.originSnapOffset?.x??0),y:o.originInGrid.y+(this.state.originSnapOffset?.y??0)},{x:l-o.originInGrid.x,y:c-o.originInGrid.y},this.scene.getNonDeletedElementsMap());l+=d.x,c+=d.y,this.setState({snapLines:u}),lr(s)||T6({newElement:s,elementType:this.state.activeTool.type,originX:o.originInGrid.x,originY:o.originInGrid.y,x:l,y:c,width:Bl(o.originInGrid.x,l),height:Bl(o.originInGrid.y,c),shouldMaintainAspectRatio:Da(s)?!Dd(n):Dd(n),shouldResizeFromCenter:GP(n),zoom:this.state.zoom.value,scene:this.scene,widthAspectRatio:p,originOffset:this.state.originSnapOffset,informMutation:r}),this.setState({newElement:s}),(this.state.activeTool.type===ar.frame||this.state.activeTool.type===ar.magicframe)&&this.setState({elementsToHighlight:ty(this.scene.getNonDeletedElements(),s,this.state,this.scene.getNonDeletedElementsMap())})});A(this,"maybeHandleCrop",(o,n)=>{if(!this.state.croppingElementId)return!1;let r=o.resize.handleType,a=o.lastCoords,[i,s]=Jt(a.x-o.resize.offset.x,a.y-o.resize.offset.y,n[re.CTRL_OR_CMD]?null:this.getEffectiveGridSize()),l=this.scene.getNonDeletedElementsMap().get(this.state.croppingElementId);if(r&&l&&Da(l)){let c=o.originalElements.get(l.id),m=Fd(l)&&this.imageCache.get(l.fileId)?.image;if(c&&Da(c)&&m&&!(m instanceof Promise)){let[p,d]=Jt(a.x,a.y,n[re.CTRL_OR_CMD]?null:this.getEffectiveGridSize()),u={x:p-o.originInGrid.x,y:d-o.originInGrid.y};this.maybeCacheReferenceSnapPoints(n,[l]);let{snapOffset:h,snapLines:g}=D0([l],[c],this,n,u,r);this.scene.mutateElement(l,Jq(l,this.scene.getNonDeletedElementsMap(),r,m.naturalWidth,m.naturalHeight,i+h.x,s+h.y,n.shiftKey?c.width/c.height:void 0)),zg(l,this.scene),this.setState({isCropping:r&&r!=="rotation",snapLines:g})}return!0}return!1});A(this,"maybeHandleResize",(o,n)=>{let r=this.scene.getSelectedElements(this.state),a=r.filter(p=>Qt(p)),i=o.resize.handleType;if(a.length>0&&i==="rotation"||r.length===1&&To(r[0])||this.state.croppingElementId)return!1;this.setState({isResizing:i&&i!=="rotation",isRotating:i==="rotation",activeEmbeddable:null});let s=o.lastCoords,[l,c]=Jt(s.x-o.resize.offset.x,s.y-o.resize.offset.y,n[re.CTRL_OR_CMD]?null:this.getEffectiveGridSize()),m=new Map;if(a.forEach(p=>{Q1(this.scene.getNonDeletedElements(),p.id).forEach(u=>{m.set(p.id+u.id,{x:u.x-p.x,y:u.y-p.y})})}),!this.state.selectedElementsAreBeingDragged){let[p,d]=Jt(s.x,s.y,n[re.CTRL_OR_CMD]?null:this.getEffectiveGridSize()),u={x:p-o.originInGrid.x,y:d-o.originInGrid.y},h=[...o.originalElements.values()];this.maybeCacheReferenceSnapPoints(n,r);let{snapOffset:g,snapLines:x}=D0(r,de(h,this.state),this,n,u,i);l+=g.x,c+=g.y,this.setState({snapLines:x})}if(fJ(o.originalElements,i,r,this.scene,UP(n),GP(n),r.some(p=>Da(p))?!Dd(n):Dd(n),l,c,o.resize.center.x,o.resize.center.y)){let p=new Set;return a.forEach(d=>{ty(this.scene.getNonDeletedElements(),d,this.state,this.scene.getNonDeletedElementsMap()).forEach(u=>p.add(u))}),this.setState({elementsToHighlight:[...p]}),!0}return!1});A(this,"getContextMenuItems",o=>{let n=[];if(n.push(yp,xp),o==="canvas")return this.state.viewModeEnabled?[...n,zs,ta,ii,oa]:[eb,vt,yp,xp,Ep,vt,Kh,hT,vt,zs,_c,ta,ii,oa];if(n.push(Ep),this.state.viewModeEnabled)return[Os,...n];let r=this.editorInterface.formFactor==="desktop"?[vt,Wh,Yh,$h,Vh]:[];return[vt,bp,Os,eb,vt,V5,K5,X5,vt,ed,vt,...n,vt,Yf,$f,vt,Kf,ok,nb,rb,eT,Xf,vt,qf,...r,vt,Jf,Qf,vt,il,vt,Nc,Mp,vt,Xh,Bc,vt,dc]});A(this,"handleWheel",pt(o=>{if(!(o.target instanceof HTMLCanvasElement||o.target instanceof HTMLTextAreaElement||o.target instanceof HTMLIFrameElement||o.target instanceof HTMLElement&&o.target.classList.contains(U1.FRAME_NAME))){o[re.CTRL_OR_CMD]&&o.preventDefault();return}if(o.preventDefault(),Ud)return;let{deltaX:n,deltaY:r}=o;if(o.metaKey||o.ctrlKey){let a=Math.sign(r),i=Xj*100,s=Math.abs(r),l=r;s>i&&(l=i*a);let c=this.state.zoom.value-l/100;c+=Math.log10(Math.max(1,this.state.zoom.value))*-a*Math.min(1,s/20),this.translateCanvas(m=>({...br({viewportX:this.lastViewportPosition.x,viewportY:this.lastViewportPosition.y,nextZoom:Ln(c)},m),shouldCacheIgnoreZoom:!0})),this.resetShouldCacheIgnoreZoomDebounced();return}if(o.shiftKey){this.translateCanvas(({zoom:a,scrollX:i})=>({scrollX:i-(r||n)/a.value}));return}this.translateCanvas(({zoom:a,scrollX:i,scrollY:s})=>({scrollX:i-n/a.value,scrollY:s-r/a.value}))}));A(this,"savePointer",(o,n,r)=>{if(!o||!n)return;let{x:a,y:i}=rt({clientX:o,clientY:n},this.state);isNaN(a)||isNaN(i);let s={x:a,y:i,tool:this.state.activeTool.type==="laser"?"laser":"pointer"};this.props.onPointerUpdate?.({pointer:s,button:r,pointersMap:Ne.pointers})});A(this,"resetShouldCacheIgnoreZoomDebounced",ZP(()=>{this.unmounted||this.setState({shouldCacheIgnoreZoom:!1})},300));A(this,"updateDOMRect",o=>{if(this.excalidrawContainerRef?.current){let n=this.excalidrawContainerRef.current,{width:r,height:a,left:i,top:s}=n.getBoundingClientRect(),{width:l,height:c,offsetTop:m,offsetLeft:p}=this.state;if(r===l&&a===c&&i===p&&s===m){o&&o();return}this.setState({width:r,height:a,offsetLeft:i,offsetTop:s},()=>{o&&o()})}});A(this,"refresh",()=>{this.setState({...this.getCanvasOffsets()})});A(this,"watchState",()=>{});let n=Or(),{excalidrawAPI:r,viewModeEnabled:a=!1,zenModeEnabled:i=!1,gridModeEnabled:s=!1,objectsSnapModeEnabled:l=!1,theme:c=n.theme,name:m=`${f("labels.untitled")}-${qP()}`}=o;if(this.state={...n,theme:c,isLoading:!0,...this.getCanvasOffsets(),viewModeEnabled:a,zenModeEnabled:i,objectsSnapModeEnabled:l,gridModeEnabled:s??n.gridModeEnabled,name:m,width:window.innerWidth,height:window.innerHeight},this.refreshEditorInterface(),this.stylesPanelMode=Wg(this.editorInterface),this.id=R1(),this.library=new GT(this),this.actionManager=new mu(this.syncActionResult,()=>this.state,()=>this.scene.getElementsIncludingDeleted(),this),this.scene=new k6,this.canvas=document.createElement("canvas"),this.rc=Nj.canvas(this.canvas),this.renderer=new rd(this.scene),this.visibleElements=[],this.store=new yJ(this),this.history=new td(this.store),r){let p={updateScene:this.updateScene,applyDeltas:this.applyDeltas,mutateElement:this.mutateElement,updateLibrary:this.library.updateLibrary,addFiles:this.addFiles,resetScene:this.resetScene,getSceneElementsIncludingDeleted:this.getSceneElementsIncludingDeleted,getSceneElementsMapIncludingDeleted:this.getSceneElementsMapIncludingDeleted,history:{clear:this.resetHistory},scrollToContent:this.scrollToContent,getSceneElements:this.getSceneElements,getAppState:()=>this.state,getFiles:()=>this.files,getName:this.getName,registerAction:d=>{this.actionManager.registerAction(d)},refresh:this.refresh,setToast:this.setToast,id:this.id,setActiveTool:this.setActiveTool,setCursor:this.setCursor,resetCursor:this.resetCursor,getEditorInterface:()=>this.editorInterface,updateFrameRendering:this.updateFrameRendering,toggleSidebar:this.toggleSidebar,onChange:d=>this.onChangeEmitter.on(d),onIncrement:d=>this.store.onStoreIncrementEmitter.on(d),onPointerDown:d=>this.onPointerDownEmitter.on(d),onPointerUp:d=>this.onPointerUpEmitter.on(d),onScrollChange:d=>this.onScrollChangeEmitter.on(d),onUserFollow:d=>this.onUserFollowEmitter.on(d)};typeof r=="function"?r(p):console.error("excalidrawAPI should be a function!")}this.excalidrawContainerValue={container:this.excalidrawContainerRef.current,id:this.id},this.fonts=new Ho(this.scene),this.history=new td(this.store),this.actionManager.registerAll(km),this.actionManager.registerAction(J5(this.history)),this.actionManager.registerAction(Q5(this.history))}onWindowMessage(o){if(o.origin!=="https://player.vimeo.com"&&o.origin!=="https://www.youtube.com")return;let n=null;try{n=JSON.parse(o.data)}catch{}if(n)switch(o.origin){case"https://player.vimeo.com":if(n.method==="paused"){let r=null,a=document.body.querySelectorAll("iframe.excalidraw__embeddable");if(!a)break;for(let i of a)i.contentWindow===o.source&&(r=i.contentWindow);r?.postMessage(JSON.stringify({method:n.value?"play":"pause",value:!0}),"*")}break;case"https://www.youtube.com":if(n.event==="infoDelivery"&&n.info&&n.id&&typeof n.info.playerState=="number"){let r=n.id,a=n.info.playerState;Object.values(Rg).includes(a)&&dy.set(r,a)}break}}handleSkipBindMode(){if(this.state.selectedLinearElement?.initialState&&!this.state.selectedLinearElement.initialState.arrowStartIsInside){sr(this.lastPointerMoveCoords,"Missing last pointer move coords when changing bind skip mode for arrow start");let o=this.scene.getNonDeletedElementsMap(),n=Cn(pe(this.lastPointerMoveCoords.x,this.lastPointerMoveCoords.y),this.scene.getNonDeletedElements(),o),r=_e.getElement(this.state.selectedLinearElement.elementId,o);r?.startBinding&&n?.id===r.startBinding.elementId&&this.setState({selectedLinearElement:{...this.state.selectedLinearElement,initialState:{...this.state.selectedLinearElement.initialState,arrowStartIsInside:!0}}})}if(this.state.bindMode==="orbit"&&(this.bindModeHandler&&(clearTimeout(this.bindModeHandler),this.bindModeHandler=null),Io(()=>{this.setState({bindMode:"skip"})}),this.lastPointerMoveCoords&&this.state.selectedLinearElement?.selectedPointsIndices&&this.state.selectedLinearElement?.selectedPointsIndices.length)){let{x:o,y:n}=this.lastPointerMoveCoords,r=this.lastPointerMoveEvent??this.lastPointerDownEvent?.nativeEvent;sr(r,"Last event must exist");let a=o-this.state.selectedLinearElement.pointerOffset.x,i=n-this.state.selectedLinearElement.pointerOffset.y,s=this.state.multiElement?_e.handlePointerMove(r,this,a,i,this.state.selectedLinearElement):_e.handlePointDragging(r,this,a,i,this.state.selectedLinearElement);s&&this.setState(s)}}resetDelayedBindMode(){this.bindModeHandler&&(clearTimeout(this.bindModeHandler),this.bindModeHandler=null),this.state.bindMode!=="orbit"&&setTimeout(()=>this.setState({bindMode:"orbit"}))}handleDelayedBindModeChange(o,n){if(o.isDeleted||To(o))return;let r=()=>{if(this.bindModeHandler=null,sr(this.lastPointerMoveCoords,"Expected lastPointerMoveCoords to be set"),!this.state.multiElement){if(!this.state.selectedLinearElement||!this.state.selectedLinearElement.selectedPointsIndices||!this.state.selectedLinearElement.selectedPointsIndices.length)return;let h=this.state.selectedLinearElement.selectedPointsIndices.includes(0),g=this.state.selectedLinearElement.selectedPointsIndices.includes(o.points.length-1);if(!h&&!g||h&&g)return}let{x:p,y:d}=this.lastPointerMoveCoords,u=Cn(pe(p,d),this.scene.getNonDeletedElements(),this.scene.getNonDeletedElementsMap());if(u&&this.state.bindMode!=="skip"){sr(this.state.selectedLinearElement?.elementId===o.id,"The selectedLinearElement is expected to not change while a bind mode timeout is ticking");let h=this.state.selectedLinearElement.initialState.arrowStartIsInside||o.startBinding?.elementId===u.id;Io(()=>{sr(this.state.selectedLinearElement,"this.state.selectedLinearElement must exist"),this.setState({bindMode:"inside",selectedLinearElement:{...this.state.selectedLinearElement,initialState:{...this.state.selectedLinearElement.initialState,arrowStartIsInside:h}}})});let g=this.lastPointerMoveEvent??this.lastPointerDownEvent?.nativeEvent;sr(g,"Last event must exist");let x=p-this.state.selectedLinearElement.pointerOffset.x,E=d-this.state.selectedLinearElement.pointerOffset.y,y=this.state.multiElement?_e.handlePointerMove(g,this,x,E,this.state.selectedLinearElement):_e.handlePointDragging(g,this,x,E,this.state.selectedLinearElement);y&&this.setState(y)}},a=!1;if(this.state.selectedLinearElement?.selectedPointsIndices){let p=this.scene.getNonDeletedElementsMap(),d=this.state.selectedLinearElement.selectedPointsIndices.includes(0),u=this.state.selectedLinearElement.selectedPointsIndices.includes(o.points.length-1),h=d?n:o.startBinding&&p.get(o.startBinding.elementId),g=u?n:o.endBinding&&p.get(o.endBinding.elementId),x=h&&A6(h,p),E=g&&A6(g,p);a=!!(x&&E&&h.id!==g.id&&vJ(x,E))}let i=this.state.selectedLinearElement?.selectedPointsIndices?.includes(0),s=this.state.selectedLinearElement?.selectedPointsIndices?.includes(o.points.length-1),l=i?"startBinding":s?"endBinding":null,c=i?"endBinding":s?"startBinding":null,m=c&&o[c]?.mode==="inside"&&o[c]?.elementId===n?.id||l&&o[l]?.mode==="inside"&&n?.id===o[l]?.elementId;l&&c&&o[l]?.mode==="inside"&&n?.id!==o[l]?.elementId&&o[c]?.elementId!==o[l]?.elementId&&this.scene.mutateElement(o,{[l]:{...o[l],mode:"orbit"}},{informMutation:!1,isDragging:!0}),!n||this.previousHoveredBindableElement&&n.id!==this.previousHoveredBindableElement.id?(this.bindModeHandler&&(clearTimeout(this.bindModeHandler),this.bindModeHandler=null),this.state.bindMode==="inside"&&Io(()=>{this.setState({bindMode:"orbit"})}),this.previousHoveredBindableElement=null):!this.bindModeHandler&&(!this.state.newElement||!o.startBinding||a)&&!m&&(this.bindModeHandler=setTimeout(r,pq)),this.previousHoveredBindableElement=n}cacheEmbeddableRef(o,n){n&&this.iFrameRefs.set(o.id,n)}getHTMLIFrameElement(o){return this.iFrameRefs.get(o.id)}handleIframeLikeCenterClick(){if(!this.lastPointerDownEvent||!this.lastPointerUpEvent||this.lastPointerDownEvent.button!==Aa.MAIN||Ra||!QP(this.state.activeTool.type,["laser","selection","lasso"]))return!1;let o=pe(rt({clientX:this.lastPointerDownEvent.clientX,clientY:this.lastPointerDownEvent.clientY},this.state)),n=pe(rt({clientX:this.lastPointerUpEvent.clientX,clientY:this.lastPointerUpEvent.clientY},this.state));if(Pa(o,n)>YP)return!1;let a=this.getElementAtPosition(o[0],o[1]);if(!(a&&this.lastPointerUpEvent.timeStamp-this.lastPointerDownEvent.timeStamp<=300&&Ne.pointers.size<2&&V1(a)&&(this.state.viewModeEnabled||this.state.activeTool.type==="laser"||this.isIframeLikeElementCenter(a,this.lastPointerUpEvent,n[0],n[1]))))return!1;let s=a;if(this.state.activeEmbeddable?.element===s&&this.state.activeEmbeddable?.state==="active"||(setTimeout(()=>{this.setState({activeEmbeddable:{element:s,state:"active"},selectedElementIds:{[s.id]:!0},newElement:null,selectionElement:null})},100),zl(s)))return!0;let l=this.getHTMLIFrameElement(s);if(!l?.contentWindow)return!0;if(l.src.includes("youtube")){let c=dy.get(s.id);switch(c||(dy.set(s.id,Rg.UNSTARTED),l.contentWindow.postMessage(JSON.stringify({event:"listening",id:s.id}),"*")),c){case Rg.PLAYING:case Rg.BUFFERING:l.contentWindow?.postMessage(JSON.stringify({event:"command",func:"pauseVideo",args:""}),"*");break;default:l.contentWindow?.postMessage(JSON.stringify({event:"command",func:"playVideo",args:""}),"*")}}return l.src.includes("player.vimeo.com")&&l.contentWindow.postMessage(JSON.stringify({method:"paused"}),"*"),!0}isIframeLikeElementCenter(o,n,r,a){return o&&!n.altKey&&!n.shiftKey&&!n.metaKey&&!n.ctrlKey&&(this.state.activeEmbeddable?.element!==o||this.state.activeEmbeddable?.state==="hover"||!this.state.activeEmbeddable)&&r>=o.x+o.width/3&&r<=o.x+2*o.width/3&&a>=o.y+o.height/3&&a<=o.y+2*o.height/3}renderEmbeddables(){let o=this.state.zoom.value,n=this.state.width,r=this.state.height,a=this.scene.getNonDeletedElements().filter(i=>Nr(i)&&this.embedsValidationStatus.get(i.id)===!0||zl(i));return Se(R6,{children:a.map(i=>{let{x:s,y:l}=Ng({sceneX:i.x,sceneY:i.y},this.state),c=l6(i,n,r,this.state,this.scene.getNonDeletedElementsMap()),m=this.initializedEmbeds.has(i.id);if(c&&!m&&this.initializedEmbeds.add(i.id),!(c||m))return null;let d;if(zl(i)){d=null;let g=(i.customData?.generationData??this.magicGenerations.get(i.id))||{status:"error",message:"No generation data",code:"ERR_NO_GENERATION_DATA"};if(g.status==="done"){let x=g.html;d={intrinsicSize:{w:i.width,h:i.height},type:"document",srcdoc:()=>x}}else if(g.status==="pending")d={intrinsicSize:{w:i.width,h:i.height},type:"document",srcdoc:()=>m6(`
|
|
219
219
|
<style>
|
|
220
220
|
html, body {
|
|
221
221
|
width: 100%;
|
|
@@ -306,10 +306,10 @@ Please fix the Mermaid syntax and regenerate a valid diagram.`;await E({prompt:Q
|
|
|
306
306
|
</style>
|
|
307
307
|
<h1>Error!</h1>
|
|
308
308
|
<h3>${x}</h3>
|
|
309
|
-
`)}}}else d=Hg(Qj(i.link||""));let u=this.state.activeEmbeddable?.element===i&&this.state.activeEmbeddable?.state==="active",h=this.state.activeEmbeddable?.element===i&&this.state.activeEmbeddable?.state==="hover";return Se("div",{className:RP("excalidraw__embeddable-container",{"is-hovered":h}),style:{transform:c?`translate(${s-this.state.offsetLeft}px, ${l-this.state.offsetTop}px) scale(${o})`:"none",display:c?"block":"none",opacity:sJ(i,oy(i,this.scene.getNonDeletedElementsMap()),this.elementsPendingErasure,null,this.state.openDialog?.name==="elementLinkSelector"?qj:1),"--embeddable-radius":`${Dq(Math.min(i.width,i.height),i)}px`},children:Vd("div",{className:"excalidraw__embeddable-container__inner",style:{width:c?`${i.width}px`:0,height:c?`${i.height}px`:0,transform:c?`rotate(${i.angle}rad)`:"none",pointerEvents:u?Nl.enabled:Nl.disabled},children:[h&&Se("div",{className:"excalidraw__embeddable-hint",children:f("buttons.embeddableInteractionButton")}),Se("div",{className:"excalidraw__embeddable__outer",style:{padding:`${i.strokeWidth}px`},children:(Nr(i)?this.props.renderEmbeddable?.(i,this.state):null)??Se("iframe",{ref:g=>this.cacheEmbeddableRef(i,g),className:"excalidraw__embeddable",srcDoc:d?.type==="document"?d.srcdoc(this.state.theme):void 0,src:d?.type!=="document"?d?.link??"":void 0,scrolling:"no",referrerPolicy:"no-referrer-when-downgrade",title:"Excalidraw Embedded Content",allow:"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture",allowFullScreen:!0,sandbox:`${d?.sandbox?.allowSameOrigin?"allow-same-origin":""} allow-scripts allow-forms allow-popups allow-popups-to-escape-sandbox allow-presentation allow-downloads`})})]})},i.id)})})}toggleOverscrollBehavior(o){document.documentElement.style.overscrollBehaviorX=o.type==="pointerenter"?"none":"auto"}render(){let o=this.scene.getSelectedElements(this.state),{renderTopRightUI:n,renderTopLeftUI:r,renderCustomStats:a}=this.props,i=this.scene.getSceneNonce(),{elementsMap:s,visibleElements:l}=this.renderer.getRenderableElements({sceneNonce:i,zoom:this.state.zoom,offsetLeft:this.state.offsetLeft,offsetTop:this.state.offsetTop,scrollX:this.state.scrollX,scrollY:this.state.scrollY,height:this.state.height,width:this.state.width,editingTextElement:this.state.editingTextElement,newElementId:this.state.newElement?.id});this.visibleElements=l;let c=this.scene.getNonDeletedElementsMap(),m="setPointerCapture"in HTMLElement.prototype?!1:this.state.selectionElement||this.state.newElement||this.state.selectedElementsAreBeingDragged||this.state.resizingElement||this.state.activeTool.type==="laser"&&this.state.cursorButton==="down",p=o[0],d=Et.get(bn)?.type==="panel";return Se("div",{translate:"no",className:RP("excalidraw excalidraw-container notranslate",{"excalidraw--view-mode":this.state.viewModeEnabled||this.state.openDialog?.name==="elementLinkSelector","excalidraw--mobile":this.editorInterface.formFactor==="phone"}),style:{"--ui-pointerEvents":m?Nl.disabled:Nl.enabled,"--right-sidebar-width":"302px"},ref:this.excalidrawContainerRef,onDrop:this.handleAppOnDrop,tabIndex:0,onKeyDown:this.props.handleKeyboardGlobally?void 0:this.onKeyDown,onPointerEnter:this.toggleOverscrollBehavior,onPointerLeave:this.toggleOverscrollBehavior,children:Se(z6.Provider,{value:this,children:Se(H6.Provider,{value:this.props,children:Se(hy.Provider,{value:this.excalidrawContainerValue,children:Se(gy.Provider,{value:this.editorInterface,children:Se(xy.Provider,{value:this.setAppState,children:Se(by.Provider,{value:this.state,children:Vd(fy.Provider,{value:this.scene.getNonDeletedElements(),children:[Vd(yy.Provider,{value:this.actionManager,children:[Se(eP,{canvas:this.canvas,appState:this.state,files:this.files,setAppState:this.setAppState,actionManager:this.actionManager,elements:this.scene.getNonDeletedElements(),onLockToggle:this.toggleLock,onPenModeToggle:this.togglePenMode,onHandToolToggle:this.onHandToolToggle,langCode:ur().code,renderTopLeftUI:r,renderTopRightUI:n,renderCustomStats:a,showExitZenModeBtn:typeof this.props?.zenModeEnabled>"u"&&this.state.zenModeEnabled,UIOptions:this.props.UIOptions,onExportImage:this.onExportImage,renderWelcomeScreen:!this.state.isLoading&&this.state.showWelcomeScreen&&this.state.activeTool.type===this.state.preferredSelectionTool.type&&!this.state.zenModeEnabled&&!this.scene.getElementsIncludingDeleted().length,app:this,isCollaborating:this.props.isCollaborating,generateLinkForSelection:this.props.generateLinkForSelection,children:this.props.children}),Se("div",{className:"excalidraw-textEditorContainer"}),Se("div",{className:"excalidraw-contextMenuContainer"}),Se("div",{className:"excalidraw-eye-dropper-container"}),Se(nP,{trails:[this.laserTrails,this.lassoTrail,this.eraserTrail]}),o.length===1&&this.state.openDialog?.name!=="elementLinkSelector"&&this.state.showHyperlinkPopup&&Se(sT,{element:p,scene:this.scene,setAppState:this.setAppState,onLinkOpen:this.props.onLinkOpen,setToast:this.setToast,updateEmbedValidationStatus:this.updateEmbedValidationStatus},p.id),this.props.aiEnabled!==!1&&o.length===1&&K1(p)&&Se(R0,{element:p,elementsMap:s,children:Se(Mg,{title:f("labels.convertToCode"),icon:Ka,checked:!1,onChange:()=>this.onMagicFrameGenerate(p,"button")})}),o.length===1&&zl(p)&&p.customData?.generationData?.status==="done"&&Vd(R0,{element:p,elementsMap:s,children:[Se(Mg,{title:f("labels.copySource"),icon:is,checked:!1,onChange:()=>this.onIframeSrcCopy(p)}),Se(Mg,{title:"Enter fullscreen",icon:$w,checked:!1,onChange:()=>{let u=this.getHTMLIFrameElement(p);if(u)try{u.requestFullscreen(),this.setState({activeEmbeddable:{element:p,state:"active"},selectedElementIds:{[p.id]:!0},newElement:null,selectionElement:null})}catch(h){console.warn(h),this.setState({errorMessage:"Couldn't enter fullscreen"})}}})]}),o.length===1&&Qt(p)&&p.customData?.type!=="image-generator"&&!this.state.viewModeEnabled&&Se(Ek,{element:p,app:this}),Se(vk,{}),Se(Kk,{app:this}),Se(e3,{app:this}),o.length===1&&Qt(p)&&p.customData?.type==="image-generator"&&!this.state.viewModeEnabled&&Se(Mk,{element:p,app:this,onBeforeImageGen:this.props.onBeforeImageGen,onAfterImageGen:this.props.onAfterImageGen}),o.length===1&&Da(p)&&!this.state.viewModeEnabled&&Se(c3,{element:p,app:this,callbacks:this.props.imageEditToolbarCallbacks}),this.state.toast!==null&&Se(_P,{message:this.state.toast.message,onClose:this.handleToastClose,duration:this.state.toast.duration,closable:this.state.toast.closable}),this.state.contextMenu&&Se($3,{items:this.state.contextMenu.items,top:this.state.contextMenu.top,left:this.state.contextMenu.left,actionManager:this.actionManager,onClose:u=>{this.setState({contextMenu:null},()=>{this.focusContainer(),u?.()})}}),Se(D1,{canvas:this.canvas,rc:this.rc,elementsMap:s,allElementsMap:c,visibleElements:l,sceneNonce:i,selectionNonce:this.state.selectionElement?.versionNonce,scale:window.devicePixelRatio,appState:this.state,renderConfig:{imageCache:this.imageCache,isExporting:!1,renderGrid:ma(this),canvasBackgroundColor:this.state.viewBackgroundColor,embedsValidationStatus:this.embedsValidationStatus,elementsPendingErasure:this.elementsPendingErasure,pendingFlowchartNodes:this.flowChartCreator.pendingNodes,theme:this.state.theme}}),this.state.newElement&&Se(AP,{appState:this.state,scale:window.devicePixelRatio,rc:this.rc,elementsMap:s,allElementsMap:c,renderConfig:{imageCache:this.imageCache,isExporting:!1,renderGrid:!1,canvasBackgroundColor:this.state.viewBackgroundColor,embedsValidationStatus:this.embedsValidationStatus,elementsPendingErasure:this.elementsPendingErasure,pendingFlowchartNodes:null,theme:this.state.theme}}),Se(_1,{app:this,containerRef:this.excalidrawContainerRef,canvas:this.interactiveCanvas,elementsMap:s,visibleElements:l,allElementsMap:c,selectedElements:o,sceneNonce:i,selectionNonce:this.state.selectionElement?.versionNonce,scale:window.devicePixelRatio,appState:this.state,renderScrollbars:this.props.renderScrollbars===!0,editorInterface:this.editorInterface,renderInteractiveSceneCallback:this.renderInteractiveSceneCallback,handleCanvasRef:this.handleInteractiveCanvasRef,onContextMenu:this.handleCanvasContextMenu,onPointerMove:this.handleCanvasPointerMove,onPointerUp:this.handleCanvasPointerUp,onPointerCancel:this.removePointer,onTouchMove:this.handleTouchMove,onPointerDown:this.handleCanvasPointerDown,onDoubleClick:this.handleCanvasDoubleClick}),this.state.userToFollow&&Se(K3,{width:this.state.width,height:this.state.height,userToFollow:this.state.userToFollow,onDisconnect:this.maybeUnfollowRemoteUser}),this.renderFrameNames(),this.state.activeLockedId&&Se(DP,{app:this,activeLockedId:this.state.activeLockedId}),d&&Se(TT,{app:this})]}),this.renderEmbeddables()]})})})})})})})})}setPlugins(o){Object.assign(this.plugins,o)}async onMagicFrameGenerate(o,n){let r=this.plugins.diagramToCode?.generate;if(!r){this.setState({errorMessage:"No diagram to code plugin found"});return}let a=$q(this.scene.getNonDeletedElements(),o).filter(s=>!K1(s));if(!a.length){n==="button"?(this.setState({errorMessage:"Cannot generate from an empty frame"}),be("ai","generate (no-children)","d2c")):this.setActiveTool({type:"magicframe"});return}let i=this.insertIframeElement({sceneX:o.x+o.width+30,sceneY:o.y,width:o.width,height:o.height});if(i){this.updateMagicGeneration({frameElement:i,data:{status:"pending"}}),this.setState({selectedElementIds:{[i.id]:!0}}),be("ai","generate (start)","d2c");try{let{html:s}=await r({frame:o,children:a});if(be("ai","generate (success)","d2c"),!s.trim()){this.updateMagicGeneration({frameElement:i,data:{status:"error",code:"ERR_OAI",message:"Nothing genereated :("}});return}let l=s.includes("<!DOCTYPE html>")&&s.includes("</html>")?s.slice(s.indexOf("<!DOCTYPE html>"),s.indexOf("</html>")+7):s;this.updateMagicGeneration({frameElement:i,data:{status:"done",html:l}})}catch(s){be("ai","generate (failed)","d2c"),this.updateMagicGeneration({frameElement:i,data:{status:"error",code:"ERR_OAI",message:s.message||"Unknown error during generation"}})}}}onIframeSrcCopy(o){o.customData?.generationData?.status==="done"&&(hn(o.customData.generationData.html),this.setToast({message:"copied to clipboard",closable:!1,duration:1500}))}clearImageShapeCache(o){let n=o??this.files;this.scene.getNonDeletedElements().forEach(r=>{Fd(r)&&n[r.fileId]&&(this.imageCache.delete(r.fileId),zd.delete(r))})}async componentDidMount(){if(this.unmounted=!1,this.excalidrawContainerValue.container=this.excalidrawContainerRef.current,N6()||B6()){let r=this.setState.bind(this);Object.defineProperties(window.h,{state:{configurable:!0,get:()=>this.state},setState:{configurable:!0,value:(...a)=>this.setState(...a)},app:{configurable:!0,value:this},history:{configurable:!0,value:this.history},store:{configurable:!0,value:this.store},fonts:{configurable:!0,value:this.fonts}})}this.store.onDurableIncrementEmitter.on(r=>{this.history.record(r.delta)});let{onIncrement:o}=this.props;o&&this.store.onStoreIncrementEmitter.on(r=>{o(r)}),this.scene.onUpdate(this.triggerRender),this.addEventListeners(),this.props.autoFocus&&this.excalidrawContainerRef.current&&this.focusContainer(),Zj&&this.excalidrawContainerRef.current&&(this.resizeObserver=new ResizeObserver(()=>{this.refreshEditorInterface(),this.updateDOMRect()}),this.resizeObserver?.observe(this.excalidrawContainerRef.current)),new URLSearchParams(window.location.search.slice(1)).has("web-share-target")?this.restoreFileFromShare():this.updateDOMRect(this.initializeScene),hq()&&!tJ()&&this.setState({errorMessage:Se(G3,{})})}componentWillUnmount(){window.launchQueue?.setConsumer(()=>{}),this.renderer.destroy(),this.scene.destroy(),this.scene=new k6,this.fonts=new Ho(this.scene),this.renderer=new rd(this.scene),this.files={},this.imageCache.clear(),this.resizeObserver?.disconnect(),this.unmounted=!0,this.removeEventListeners(),this.library.destroy(),this.laserTrails.stop(),this.eraserTrail.stop(),this.onChangeEmitter.clear(),this.store.onStoreIncrementEmitter.clear(),this.store.onDurableIncrementEmitter.clear(),zd.destroy(),jo.destroy(),clearTimeout(Na),Ge.clearCache(),cn.clearCache(),Na=0,document.documentElement.style.overscrollBehaviorX=""}removeEventListeners(){this.onRemoveEventListenersEmitter.trigger()}addEventListeners(){this.removeEventListeners(),this.props.handleKeyboardGlobally&&this.onRemoveEventListenersEmitter.once(ht(document,he.KEYDOWN,this.onKeyDown,!1)),this.onRemoveEventListenersEmitter.once(ht(this.excalidrawContainerRef.current,he.WHEEL,this.handleWheel,{passive:!1}),ht(window,he.MESSAGE,this.onWindowMessage,!1),ht(document,he.POINTER_UP,this.removePointer,{passive:!1}),ht(document,he.COPY,this.onCopy,{passive:!1}),ht(document,he.KEYUP,this.onKeyUp,{passive:!0}),ht(document,he.POINTER_MOVE,this.updateCurrentCursorPosition,{passive:!1}),ht(document.fonts,"loadingdone",o=>{let n=o.fontfaces;this.fonts.onLoaded(n)},{passive:!1}),ht(document,he.GESTURE_START,this.onGestureStart,!1),ht(document,he.GESTURE_CHANGE,this.onGestureChange,!1),ht(document,he.GESTURE_END,this.onGestureEnd,!1),ht(window,he.FOCUS,()=>{this.maybeCleanupAfterMissingPointerUp(null),this.triggerRender(!0)},{passive:!1})),!this.state.viewModeEnabled&&(this.onRemoveEventListenersEmitter.once(ht(document,he.FULLSCREENCHANGE,this.onFullscreenChange,{passive:!1}),ht(document,he.PASTE,this.pasteFromClipboard,{passive:!1}),ht(document,he.CUT,this.onCut,{passive:!1}),ht(window,he.RESIZE,this.onResize,!1),ht(window,he.UNLOAD,this.onUnload,!1),ht(window,he.BLUR,this.onBlur,!1),ht(this.excalidrawContainerRef.current,he.WHEEL,this.handleWheel,{passive:!1}),ht(this.excalidrawContainerRef.current,he.DRAG_OVER,this.disableEvent,!1),ht(this.excalidrawContainerRef.current,he.DROP,this.disableEvent,!1)),this.props.detectScroll&&this.onRemoveEventListenersEmitter.once(ht(eq(this.excalidrawContainerRef.current),he.SCROLL,this.onScroll,{passive:!1})))}componentDidUpdate(o,n){this.updateEmbeddables();let r=this.scene.getElementsIncludingDeleted(),a=this.scene.getElementsMapIncludingDeleted();!this.state.showWelcomeScreen&&!r.length&&this.setState({showWelcomeScreen:!0}),n.userToFollow&&!this.state.collaborators.has(n.userToFollow.socketId)&&this.maybeUnfollowRemoteUser(),(n.zoom.value!==this.state.zoom.value||n.scrollX!==this.state.scrollX||n.scrollY!==this.state.scrollY)&&(this.props?.onScrollChange?.(this.state.scrollX,this.state.scrollY,this.state.zoom),this.onScrollChangeEmitter.trigger(this.state.scrollX,this.state.scrollY,this.state.zoom)),n.userToFollow!==this.state.userToFollow&&(n.userToFollow&&this.onUserFollowEmitter.trigger({userToFollow:n.userToFollow,action:"UNFOLLOW"}),this.state.userToFollow&&this.onUserFollowEmitter.trigger({userToFollow:this.state.userToFollow,action:"FOLLOW"})),Object.keys(this.state.selectedElementIds).length&&ho(this.state)&&this.setState({activeTool:ir(this.state,{type:"selection"})}),this.state.activeTool.type==="eraser"&&n.theme!==this.state.theme&&Lf(this.interactiveCanvas,this.state.theme),n.activeTool.type==="selection"&&this.state.activeTool.type!=="selection"&&this.state.showHyperlinkPopup&&this.setState({showHyperlinkPopup:!1}),o.langCode!==this.props.langCode&&this.updateLanguage(),ho(n)&&!ho(this.state)&&this.eraserTrail.endPath(),o.viewModeEnabled!==this.props.viewModeEnabled&&this.setState({viewModeEnabled:!!this.props.viewModeEnabled}),n.viewModeEnabled!==this.state.viewModeEnabled&&(this.addEventListeners(),this.deselectElements()),(n.openDialog?.name==="elementLinkSelector"||this.state.openDialog?.name==="elementLinkSelector")&&n.openDialog?.name!==this.state.openDialog?.name&&(this.deselectElements(),this.setState({hoveredElementIds:{}})),o.zenModeEnabled!==this.props.zenModeEnabled&&this.setState({zenModeEnabled:!!this.props.zenModeEnabled}),o.theme!==this.props.theme&&this.props.theme&&this.setState({theme:this.props.theme}),this.excalidrawContainerRef.current?.classList.toggle("theme--dark",this.state.theme===Dg.DARK),this.state.selectedLinearElement?.isEditing&&!this.state.selectedElementIds[this.state.selectedLinearElement.elementId]&&setTimeout(()=>{this.state.selectedLinearElement?.isEditing&&this.actionManager.executeAction(ro)}),this.state.editingTextElement?.isDeleted&&this.setState({editingTextElement:null}),this.store.commit(a,this.state),this.state.isLoading||(this.props.onChange?.(r,this.state,this.files),this.onChangeEmitter.trigger(r,this.state,this.files))}static resetTapTwice(){Hd=!1,Gd=null}async insertClipboardContent(o,n,r){let{x:a,y:i}=rt({clientX:this.lastViewportPosition.x,clientY:this.lastViewportPosition.y},this.state);if(o.errorMessage){this.setState({errorMessage:o.errorMessage});return}if(n.length===0&&!r&&o.mixedContent){await this.addElementsFromMixedContentPaste(o.mixedContent,{isPlainPaste:r,sceneX:a,sceneY:i});return}if(o.spreadsheet&&!r){this.setState({pasteDialog:{data:o.spreadsheet,shown:!0}});return}let s=n.map(m=>m.file);if(s.length===0&&o.text&&!r){let m=o.text.trim();m.startsWith("<svg")&&m.endsWith("</svg>")&&s.push(gh(m))}if(s.length>0){this.isToolSupported("image")?await this.insertImages(s,a,i):this.setState({errorMessage:f("errors.imageToolNotSupported")});return}if(o.elements){let m=o.programmaticAPI?L6(o.elements):o.elements;this.addElementsFromPasteOrLibrary({elements:m,files:o.files||null,position:this.editorInterface.formFactor==="desktop"?"cursor":"center",retainSeed:r});return}if(!o.text)return;if(!r&&C3(o.text)){let m=await import("@excalidraw/mermaid-to-excalidraw");try{let{elements:p,files:d}=await m.parseMermaidToExcalidraw(o.text),u=L6(p,{regenerateIds:!0});this.addElementsFromPasteOrLibrary({elements:u,files:d,position:this.editorInterface.formFactor==="desktop"?"cursor":"center"});return}catch(p){console.warn(`parsing pasted text as mermaid definition failed: ${p.message}`)}}let l=sq(o.text).split(/\n+/).map(m=>m.trim()).filter(Boolean),c=l.map(m=>Rq(m)).filter(m=>j1(m,this.props.validateEmbeddable)&&(/^(http|https):\/\/[^\s/$.?#].[^\s]*$/.test(m)||Hg(m)?.type==="video"));if(!r&&c.length>0&&c.length===l.length){let m=[];for(let p of c){let d=m[m.length-1],u=this.insertEmbeddableElement({sceneX:d?d.x+d.width+20:a,sceneY:i,link:O1(p)});u&&m.push(u)}m.length&&(this.store.scheduleCapture(),this.setState({selectedElementIds:Object.fromEntries(m.map(p=>[p.id,!0]))}));return}this.addTextFromPaste(o.text,r)}async addElementsFromMixedContentPaste(o,{isPlainPaste:n,sceneX:r,sceneY:a}){if(!n&&o.some(i=>i.type==="imageUrl")&&this.isToolSupported("image")){let i=o.filter(m=>m.type==="imageUrl").map(m=>m.value),s=await Promise.all(i.map(async m=>{try{return{file:await EE(m)}}catch(p){let d=p.message;return p.cause==="FETCH_ERROR"?d=f("errors.failedToFetchImage"):p.cause==="UNSUPPORTED"&&(d=f("errors.unsupportedFileType")),{errorMessage:d}}})),l=s.filter(m=>!!m.file).map(m=>m.file);await this.insertImages(l,r,a);let c=s.find(m=>!!m.errorMessage);c&&c.errorMessage&&this.setState({errorMessage:c.errorMessage})}else{let i=o.filter(s=>s.type==="text");i.length&&this.addTextFromPaste(i.map(s=>s.value).join(`
|
|
309
|
+
`)}}}else d=Hg(Qj(i.link||""));let u=this.state.activeEmbeddable?.element===i&&this.state.activeEmbeddable?.state==="active",h=this.state.activeEmbeddable?.element===i&&this.state.activeEmbeddable?.state==="hover";return Se("div",{className:RP("excalidraw__embeddable-container",{"is-hovered":h}),style:{transform:c?`translate(${s-this.state.offsetLeft}px, ${l-this.state.offsetTop}px) scale(${o})`:"none",display:c?"block":"none",opacity:sJ(i,oy(i,this.scene.getNonDeletedElementsMap()),this.elementsPendingErasure,null,this.state.openDialog?.name==="elementLinkSelector"?qj:1),"--embeddable-radius":`${Dq(Math.min(i.width,i.height),i)}px`},children:Vd("div",{className:"excalidraw__embeddable-container__inner",style:{width:c?`${i.width}px`:0,height:c?`${i.height}px`:0,transform:c?`rotate(${i.angle}rad)`:"none",pointerEvents:u?Nl.enabled:Nl.disabled},children:[h&&Se("div",{className:"excalidraw__embeddable-hint",children:f("buttons.embeddableInteractionButton")}),Se("div",{className:"excalidraw__embeddable__outer",style:{padding:`${i.strokeWidth}px`},children:(Nr(i)?this.props.renderEmbeddable?.(i,this.state):null)??Se("iframe",{ref:g=>this.cacheEmbeddableRef(i,g),className:"excalidraw__embeddable",srcDoc:d?.type==="document"?d.srcdoc(this.state.theme):void 0,src:d?.type!=="document"?d?.link??"":void 0,scrolling:"no",referrerPolicy:"no-referrer-when-downgrade",title:"Excalidraw Embedded Content",allow:"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture",allowFullScreen:!0,sandbox:`${d?.sandbox?.allowSameOrigin?"allow-same-origin":""} allow-scripts allow-forms allow-popups allow-popups-to-escape-sandbox allow-presentation allow-downloads`})})]})},i.id)})})}toggleOverscrollBehavior(o){document.documentElement.style.overscrollBehaviorX=o.type==="pointerenter"?"none":"auto"}render(){let o=this.scene.getSelectedElements(this.state),{renderTopRightUI:n,renderTopLeftUI:r,renderCustomStats:a}=this.props,i=this.scene.getSceneNonce(),{elementsMap:s,visibleElements:l}=this.renderer.getRenderableElements({sceneNonce:i,zoom:this.state.zoom,offsetLeft:this.state.offsetLeft,offsetTop:this.state.offsetTop,scrollX:this.state.scrollX,scrollY:this.state.scrollY,height:this.state.height,width:this.state.width,editingTextElement:this.state.editingTextElement,newElementId:this.state.newElement?.id});this.visibleElements=l;let c=this.scene.getNonDeletedElementsMap(),m="setPointerCapture"in HTMLElement.prototype?!1:this.state.selectionElement||this.state.newElement||this.state.selectedElementsAreBeingDragged||this.state.resizingElement||this.state.activeTool.type==="laser"&&this.state.cursorButton==="down",p=o[0],d=Et.get(bn)?.type==="panel";return Se("div",{translate:"no",className:RP("excalidraw excalidraw-container notranslate",{"excalidraw--view-mode":this.state.viewModeEnabled||this.state.openDialog?.name==="elementLinkSelector","excalidraw--mobile":this.editorInterface.formFactor==="phone"}),style:{"--ui-pointerEvents":m?Nl.disabled:Nl.enabled,"--right-sidebar-width":"302px"},ref:this.excalidrawContainerRef,onDrop:this.handleAppOnDrop,tabIndex:0,onKeyDown:this.props.handleKeyboardGlobally?void 0:this.onKeyDown,onPointerEnter:this.toggleOverscrollBehavior,onPointerLeave:this.toggleOverscrollBehavior,children:Se(z6.Provider,{value:this,children:Se(H6.Provider,{value:this.props,children:Se(hy.Provider,{value:this.excalidrawContainerValue,children:Se(gy.Provider,{value:this.editorInterface,children:Se(xy.Provider,{value:this.setAppState,children:Se(by.Provider,{value:this.state,children:Vd(fy.Provider,{value:this.scene.getNonDeletedElements(),children:[Vd(yy.Provider,{value:this.actionManager,children:[Se(eP,{canvas:this.canvas,appState:this.state,files:this.files,setAppState:this.setAppState,actionManager:this.actionManager,elements:this.scene.getNonDeletedElements(),onLockToggle:this.toggleLock,onPenModeToggle:this.togglePenMode,onHandToolToggle:this.onHandToolToggle,langCode:ur().code,renderTopLeftUI:r,renderTopRightUI:n,renderCustomStats:a,showExitZenModeBtn:typeof this.props?.zenModeEnabled>"u"&&this.state.zenModeEnabled,UIOptions:this.props.UIOptions,onExportImage:this.onExportImage,renderWelcomeScreen:!this.state.isLoading&&this.state.showWelcomeScreen&&this.state.activeTool.type===this.state.preferredSelectionTool.type&&!this.state.zenModeEnabled&&!this.scene.getElementsIncludingDeleted().length,app:this,isCollaborating:this.props.isCollaborating,generateLinkForSelection:this.props.generateLinkForSelection,children:this.props.children}),Se("div",{className:"excalidraw-textEditorContainer"}),Se("div",{className:"excalidraw-contextMenuContainer"}),Se("div",{className:"excalidraw-eye-dropper-container"}),Se(nP,{trails:[this.laserTrails,this.lassoTrail,this.eraserTrail]}),o.length===1&&this.state.openDialog?.name!=="elementLinkSelector"&&this.state.showHyperlinkPopup&&Se(sT,{element:p,scene:this.scene,setAppState:this.setAppState,onLinkOpen:this.props.onLinkOpen,setToast:this.setToast,updateEmbedValidationStatus:this.updateEmbedValidationStatus},p.id),this.props.aiEnabled!==!1&&o.length===1&&K1(p)&&Se(R0,{element:p,elementsMap:s,children:Se(Mg,{title:f("labels.convertToCode"),icon:Ka,checked:!1,onChange:()=>this.onMagicFrameGenerate(p,"button")})}),o.length===1&&zl(p)&&p.customData?.generationData?.status==="done"&&Vd(R0,{element:p,elementsMap:s,children:[Se(Mg,{title:f("labels.copySource"),icon:is,checked:!1,onChange:()=>this.onIframeSrcCopy(p)}),Se(Mg,{title:"Enter fullscreen",icon:$w,checked:!1,onChange:()=>{let u=this.getHTMLIFrameElement(p);if(u)try{u.requestFullscreen(),this.setState({activeEmbeddable:{element:p,state:"active"},selectedElementIds:{[p.id]:!0},newElement:null,selectionElement:null})}catch(h){console.warn(h),this.setState({errorMessage:"Couldn't enter fullscreen"})}}})]}),o.length===1&&Qt(p)&&p.customData?.type!=="image-generator"&&!this.state.viewModeEnabled&&Se(Ek,{element:p,app:this}),Se(vk,{}),Se(Kk,{app:this}),Se(e3,{app:this}),o.length===1&&Qt(p)&&p.customData?.type==="image-generator"&&!this.state.viewModeEnabled&&Se(Mk,{element:p,app:this,onBeforeImageGen:this.props.onBeforeImageGen,onAfterImageGen:this.props.onAfterImageGen}),o.length===1&&Da(p)&&!this.state.viewModeEnabled&&Se(c3,{element:p,app:this,callbacks:this.props.imageEditToolbarCallbacks}),this.state.toast!==null&&Se(_P,{message:this.state.toast.message,onClose:this.handleToastClose,duration:this.state.toast.duration,closable:this.state.toast.closable}),this.state.contextMenu&&Se($3,{items:this.state.contextMenu.items,top:this.state.contextMenu.top,left:this.state.contextMenu.left,actionManager:this.actionManager,onClose:u=>{this.setState({contextMenu:null},()=>{this.focusContainer(),u?.()})}}),Se(D1,{canvas:this.canvas,rc:this.rc,elementsMap:s,allElementsMap:c,visibleElements:l,sceneNonce:i,selectionNonce:this.state.selectionElement?.versionNonce,scale:window.devicePixelRatio,appState:this.state,renderConfig:{imageCache:this.imageCache,isExporting:!1,renderGrid:ma(this),canvasBackgroundColor:this.state.viewBackgroundColor,embedsValidationStatus:this.embedsValidationStatus,elementsPendingErasure:this.elementsPendingErasure,pendingFlowchartNodes:this.flowChartCreator.pendingNodes,theme:this.state.theme}}),this.state.newElement&&Se(AP,{appState:this.state,scale:window.devicePixelRatio,rc:this.rc,elementsMap:s,allElementsMap:c,renderConfig:{imageCache:this.imageCache,isExporting:!1,renderGrid:!1,canvasBackgroundColor:this.state.viewBackgroundColor,embedsValidationStatus:this.embedsValidationStatus,elementsPendingErasure:this.elementsPendingErasure,pendingFlowchartNodes:null,theme:this.state.theme}}),Se(_1,{app:this,containerRef:this.excalidrawContainerRef,canvas:this.interactiveCanvas,elementsMap:s,visibleElements:l,allElementsMap:c,selectedElements:o,sceneNonce:i,selectionNonce:this.state.selectionElement?.versionNonce,scale:window.devicePixelRatio,appState:this.state,renderScrollbars:this.props.renderScrollbars===!0,editorInterface:this.editorInterface,renderInteractiveSceneCallback:this.renderInteractiveSceneCallback,handleCanvasRef:this.handleInteractiveCanvasRef,onContextMenu:this.handleCanvasContextMenu,onPointerMove:this.handleCanvasPointerMove,onPointerUp:this.handleCanvasPointerUp,onPointerCancel:this.removePointer,onTouchMove:this.handleTouchMove,onPointerDown:this.handleCanvasPointerDown,onDoubleClick:this.handleCanvasDoubleClick}),this.state.userToFollow&&Se(K3,{width:this.state.width,height:this.state.height,userToFollow:this.state.userToFollow,onDisconnect:this.maybeUnfollowRemoteUser}),this.renderFrameNames(),this.state.activeLockedId&&Se(DP,{app:this,activeLockedId:this.state.activeLockedId}),d&&Se(TT,{app:this})]}),this.renderEmbeddables()]})})})})})})})})}setPlugins(o){Object.assign(this.plugins,o)}async onMagicFrameGenerate(o,n){let r=this.plugins.diagramToCode?.generate;if(!r){this.setState({errorMessage:"No diagram to code plugin found"});return}let a=$q(this.scene.getNonDeletedElements(),o).filter(s=>!K1(s));if(!a.length){n==="button"?(this.setState({errorMessage:"Cannot generate from an empty frame"}),be("ai","generate (no-children)","d2c")):this.setActiveTool({type:"magicframe"});return}let i=this.insertIframeElement({sceneX:o.x+o.width+30,sceneY:o.y,width:o.width,height:o.height});if(i){this.updateMagicGeneration({frameElement:i,data:{status:"pending"}}),this.setState({selectedElementIds:{[i.id]:!0}}),be("ai","generate (start)","d2c");try{let{html:s}=await r({frame:o,children:a});if(be("ai","generate (success)","d2c"),!s.trim()){this.updateMagicGeneration({frameElement:i,data:{status:"error",code:"ERR_OAI",message:"Nothing genereated :("}});return}let l=s.includes("<!DOCTYPE html>")&&s.includes("</html>")?s.slice(s.indexOf("<!DOCTYPE html>"),s.indexOf("</html>")+7):s;this.updateMagicGeneration({frameElement:i,data:{status:"done",html:l}})}catch(s){be("ai","generate (failed)","d2c"),this.updateMagicGeneration({frameElement:i,data:{status:"error",code:"ERR_OAI",message:s.message||"Unknown error during generation"}})}}}onIframeSrcCopy(o){o.customData?.generationData?.status==="done"&&(hn(o.customData.generationData.html),this.setToast({message:"copied to clipboard",closable:!1,duration:1500}))}clearImageShapeCache(o){let n=o??this.files;this.scene.getNonDeletedElements().forEach(r=>{Fd(r)&&n[r.fileId]&&(this.imageCache.delete(r.fileId),zd.delete(r))})}async componentDidMount(){if(this.unmounted=!1,this.excalidrawContainerValue.container=this.excalidrawContainerRef.current,N6()||B6()){let r=this.setState.bind(this);Object.defineProperties(window.h,{state:{configurable:!0,get:()=>this.state},setState:{configurable:!0,value:(...a)=>this.setState(...a)},app:{configurable:!0,value:this},history:{configurable:!0,value:this.history},store:{configurable:!0,value:this.store},fonts:{configurable:!0,value:this.fonts}})}this.store.onDurableIncrementEmitter.on(r=>{this.history.record(r.delta)});let{onIncrement:o}=this.props;o&&this.store.onStoreIncrementEmitter.on(r=>{o(r)}),this.scene.onUpdate(this.triggerRender),this.addEventListeners(),this.props.autoFocus&&this.excalidrawContainerRef.current&&this.focusContainer(),Zj&&this.excalidrawContainerRef.current&&(this.resizeObserver=new ResizeObserver(()=>{this.refreshEditorInterface(),this.updateDOMRect()}),this.resizeObserver?.observe(this.excalidrawContainerRef.current)),new URLSearchParams(window.location.search.slice(1)).has("web-share-target")?this.restoreFileFromShare():this.updateDOMRect(this.initializeScene),hq()&&!tJ()&&this.setState({errorMessage:Se(G3,{})})}componentWillUnmount(){window.launchQueue?.setConsumer(()=>{}),this.renderer.destroy(),this.scene.destroy(),this.scene=new k6,this.fonts=new Ho(this.scene),this.renderer=new rd(this.scene),this.files={},this.imageCache.clear(),this.resizeObserver?.disconnect(),this.unmounted=!0,this.removeEventListeners(),this.library.destroy(),this.laserTrails.stop(),this.eraserTrail.stop(),this.onChangeEmitter.clear(),this.store.onStoreIncrementEmitter.clear(),this.store.onDurableIncrementEmitter.clear(),zd.destroy(),jo.destroy(),clearTimeout(Na),Ge.clearCache(),cn.clearCache(),Na=0,document.documentElement.style.overscrollBehaviorX=""}removeEventListeners(){this.onRemoveEventListenersEmitter.trigger()}addEventListeners(){this.removeEventListeners(),this.props.handleKeyboardGlobally&&this.onRemoveEventListenersEmitter.once(ht(document,fe.KEYDOWN,this.onKeyDown,!1)),this.onRemoveEventListenersEmitter.once(ht(this.excalidrawContainerRef.current,fe.WHEEL,this.handleWheel,{passive:!1}),ht(window,fe.MESSAGE,this.onWindowMessage,!1),ht(document,fe.POINTER_UP,this.removePointer,{passive:!1}),ht(document,fe.COPY,this.onCopy,{passive:!1}),ht(document,fe.KEYUP,this.onKeyUp,{passive:!0}),ht(document,fe.POINTER_MOVE,this.updateCurrentCursorPosition,{passive:!1}),ht(document.fonts,"loadingdone",o=>{let n=o.fontfaces;this.fonts.onLoaded(n)},{passive:!1}),ht(document,fe.GESTURE_START,this.onGestureStart,!1),ht(document,fe.GESTURE_CHANGE,this.onGestureChange,!1),ht(document,fe.GESTURE_END,this.onGestureEnd,!1),ht(window,fe.FOCUS,()=>{this.maybeCleanupAfterMissingPointerUp(null),this.triggerRender(!0)},{passive:!1})),!this.state.viewModeEnabled&&(this.onRemoveEventListenersEmitter.once(ht(document,fe.FULLSCREENCHANGE,this.onFullscreenChange,{passive:!1}),ht(document,fe.PASTE,this.pasteFromClipboard,{passive:!1}),ht(document,fe.CUT,this.onCut,{passive:!1}),ht(window,fe.RESIZE,this.onResize,!1),ht(window,fe.UNLOAD,this.onUnload,!1),ht(window,fe.BLUR,this.onBlur,!1),ht(this.excalidrawContainerRef.current,fe.WHEEL,this.handleWheel,{passive:!1}),ht(this.excalidrawContainerRef.current,fe.DRAG_OVER,this.disableEvent,!1),ht(this.excalidrawContainerRef.current,fe.DROP,this.disableEvent,!1)),this.props.detectScroll&&this.onRemoveEventListenersEmitter.once(ht(eq(this.excalidrawContainerRef.current),fe.SCROLL,this.onScroll,{passive:!1})))}componentDidUpdate(o,n){this.updateEmbeddables();let r=this.scene.getElementsIncludingDeleted(),a=this.scene.getElementsMapIncludingDeleted();!this.state.showWelcomeScreen&&!r.length&&this.setState({showWelcomeScreen:!0}),n.userToFollow&&!this.state.collaborators.has(n.userToFollow.socketId)&&this.maybeUnfollowRemoteUser(),(n.zoom.value!==this.state.zoom.value||n.scrollX!==this.state.scrollX||n.scrollY!==this.state.scrollY)&&(this.props?.onScrollChange?.(this.state.scrollX,this.state.scrollY,this.state.zoom),this.onScrollChangeEmitter.trigger(this.state.scrollX,this.state.scrollY,this.state.zoom)),n.userToFollow!==this.state.userToFollow&&(n.userToFollow&&this.onUserFollowEmitter.trigger({userToFollow:n.userToFollow,action:"UNFOLLOW"}),this.state.userToFollow&&this.onUserFollowEmitter.trigger({userToFollow:this.state.userToFollow,action:"FOLLOW"})),Object.keys(this.state.selectedElementIds).length&&ho(this.state)&&this.setState({activeTool:ir(this.state,{type:"selection"})}),this.state.activeTool.type==="eraser"&&n.theme!==this.state.theme&&Lf(this.interactiveCanvas,this.state.theme),n.activeTool.type==="selection"&&this.state.activeTool.type!=="selection"&&this.state.showHyperlinkPopup&&this.setState({showHyperlinkPopup:!1}),o.langCode!==this.props.langCode&&this.updateLanguage(),ho(n)&&!ho(this.state)&&this.eraserTrail.endPath(),o.viewModeEnabled!==this.props.viewModeEnabled&&this.setState({viewModeEnabled:!!this.props.viewModeEnabled}),n.viewModeEnabled!==this.state.viewModeEnabled&&(this.addEventListeners(),this.deselectElements()),(n.openDialog?.name==="elementLinkSelector"||this.state.openDialog?.name==="elementLinkSelector")&&n.openDialog?.name!==this.state.openDialog?.name&&(this.deselectElements(),this.setState({hoveredElementIds:{}})),o.zenModeEnabled!==this.props.zenModeEnabled&&this.setState({zenModeEnabled:!!this.props.zenModeEnabled}),o.theme!==this.props.theme&&this.props.theme&&this.setState({theme:this.props.theme}),this.excalidrawContainerRef.current?.classList.toggle("theme--dark",this.state.theme===Dg.DARK),this.state.selectedLinearElement?.isEditing&&!this.state.selectedElementIds[this.state.selectedLinearElement.elementId]&&setTimeout(()=>{this.state.selectedLinearElement?.isEditing&&this.actionManager.executeAction(ro)}),this.state.editingTextElement?.isDeleted&&this.setState({editingTextElement:null}),this.store.commit(a,this.state),this.state.isLoading||(this.props.onChange?.(r,this.state,this.files),this.onChangeEmitter.trigger(r,this.state,this.files))}static resetTapTwice(){Hd=!1,Gd=null}async insertClipboardContent(o,n,r){let{x:a,y:i}=rt({clientX:this.lastViewportPosition.x,clientY:this.lastViewportPosition.y},this.state);if(o.errorMessage){this.setState({errorMessage:o.errorMessage});return}if(n.length===0&&!r&&o.mixedContent){await this.addElementsFromMixedContentPaste(o.mixedContent,{isPlainPaste:r,sceneX:a,sceneY:i});return}if(o.spreadsheet&&!r){this.setState({pasteDialog:{data:o.spreadsheet,shown:!0}});return}let s=n.map(m=>m.file);if(s.length===0&&o.text&&!r){let m=o.text.trim();m.startsWith("<svg")&&m.endsWith("</svg>")&&s.push(gh(m))}if(s.length>0){this.isToolSupported("image")?await this.insertImages(s,a,i):this.setState({errorMessage:f("errors.imageToolNotSupported")});return}if(o.elements){let m=o.programmaticAPI?L6(o.elements):o.elements;this.addElementsFromPasteOrLibrary({elements:m,files:o.files||null,position:this.editorInterface.formFactor==="desktop"?"cursor":"center",retainSeed:r});return}if(!o.text)return;if(!r&&C3(o.text)){let m=await import("@excalidraw/mermaid-to-excalidraw");try{let{elements:p,files:d}=await m.parseMermaidToExcalidraw(o.text),u=L6(p,{regenerateIds:!0});this.addElementsFromPasteOrLibrary({elements:u,files:d,position:this.editorInterface.formFactor==="desktop"?"cursor":"center"});return}catch(p){console.warn(`parsing pasted text as mermaid definition failed: ${p.message}`)}}let l=sq(o.text).split(/\n+/).map(m=>m.trim()).filter(Boolean),c=l.map(m=>Rq(m)).filter(m=>j1(m,this.props.validateEmbeddable)&&(/^(http|https):\/\/[^\s/$.?#].[^\s]*$/.test(m)||Hg(m)?.type==="video"));if(!r&&c.length>0&&c.length===l.length){let m=[];for(let p of c){let d=m[m.length-1],u=this.insertEmbeddableElement({sceneX:d?d.x+d.width+20:a,sceneY:i,link:O1(p)});u&&m.push(u)}m.length&&(this.store.scheduleCapture(),this.setState({selectedElementIds:Object.fromEntries(m.map(p=>[p.id,!0]))}));return}this.addTextFromPaste(o.text,r)}async addElementsFromMixedContentPaste(o,{isPlainPaste:n,sceneX:r,sceneY:a}){if(!n&&o.some(i=>i.type==="imageUrl")&&this.isToolSupported("image")){let i=o.filter(m=>m.type==="imageUrl").map(m=>m.value),s=await Promise.all(i.map(async m=>{try{return{file:await EE(m)}}catch(p){let d=p.message;return p.cause==="FETCH_ERROR"?d=f("errors.failedToFetchImage"):p.cause==="UNSUPPORTED"&&(d=f("errors.unsupportedFileType")),{errorMessage:d}}})),l=s.filter(m=>!!m.file).map(m=>m.file);await this.insertImages(l,r,a);let c=s.find(m=>!!m.errorMessage);c&&c.errorMessage&&this.setState({errorMessage:c.errorMessage})}else{let i=o.filter(s=>s.type==="text");i.length&&this.addTextFromPaste(i.map(s=>s.value).join(`
|
|
310
310
|
|
|
311
311
|
`),n)}}addTextFromPaste(o,n=!1){let{x:r,y:a}=rt({clientX:this.lastViewportPosition.x,clientY:this.lastViewportPosition.y},this.state),i={x:r,y:a,strokeColor:this.state.currentItemStrokeColor,backgroundColor:this.state.currentItemBackgroundColor,fillStyle:this.state.currentItemFillStyle,strokeWidth:this.state.currentItemStrokeWidth,strokeStyle:this.state.currentItemStrokeStyle,roundness:null,roughness:this.state.currentItemRoughness,opacity:this.state.currentItemOpacity,text:o,fontSize:this.state.currentItemFontSize,fontFamily:this.state.currentItemFontFamily,textAlign:jj,verticalAlign:WP,locked:!1},s=z1({fontSize:i.fontSize,fontFamily:i.fontFamily}),l=XP(i.fontFamily),[c,,m]=Zq(this.state),p=Math.max(Math.min((m-c)*.5,800),200),d=10,u=a,h=n?[o]:o.split(`
|
|
312
|
-
`),g=h.reduce((x,E,y)=>{let w=oJ(E).trim();if(w.length){let v=this.getTopLayerFrameAtSceneCoords({x:r,y:u}),I=x6(w,s,l),C=I.width>p,P=C?Qq(w,s,p):w;I=C?x6(P,s,l):I;let S=r-I.width/2,D=u-I.height/2,_=r6({...i,x:S,y:D,text:P,originalText:w,lineHeight:l,autoResize:!C,frameId:v?v.id:null});x.push(_),u+=_.height+d}else h[y-1]?.trim()&&(u+=nJ(i.fontSize,l)+d);return x},[]);g.length!==0&&(this.scene.insertElements(g),this.store.scheduleCapture(),this.setState({selectedElementIds:ze(Object.fromEntries(g.map(x=>[x.id,!0])),this.state)}),!n&&g.length>1&&D6===!1&&this.editorInterface.formFactor!=="phone"&&(this.setToast({message:f("toast.pasteAsSingleElement",{shortcut:G("CtrlOrCmd+Shift+V")}),duration:5e3}),D6=!0))}handleTextWysiwyg(o,{isExistingElement:n=!1}){let r=this.scene.getElementsMapIncludingDeleted(),a=(i,s)=>{this.scene.replaceAllElements([...this.scene.getElementsIncludingDeleted().map(l=>l.id===o.id&&kn(l)?_a(l,{originalText:i,isDeleted:s??l.isDeleted,...Sq(l,u6(l,r),r,i)}):l)])};v3({id:o.id,canvas:this.canvas,getViewportCoords:(i,s)=>{let{x:l,y:c}=Ng({sceneX:i,sceneY:s},this.state);return[l-this.state.offsetLeft,c-this.state.offsetTop]},onChange:pt(i=>{a(i,!1),C6(o)&&zg(o,this.scene)}),onSubmit:pt(({viaKeyboard:i,nextOriginalText:s})=>{let l=!s.trim();if(a(s,l),!l&&i){let c=o.containerId?o.containerId:o.id;Io(()=>{this.setState(m=>({selectedElementIds:ze({...m.selectedElementIds,[c]:!0},m)}))})}l&&Eq(this.scene.getNonDeletedElements(),[o]),(!l||n)&&this.store.scheduleCapture(),Io(()=>{this.setState({newElement:null,editingTextElement:null})}),this.state.activeTool.locked&&Ao(this.interactiveCanvas,this.state),this.focusContainer()}),element:o,excalidrawContainer:this.excalidrawContainerRef.current,app:this,autoSelect:!this.editorInterface.isTouchScreen}),this.deselectElements(),a(o.originalText,!1)}deselectElements(){this.setState({selectedElementIds:ze({},this.state),selectedGroupIds:{},editingGroupId:null,activeEmbeddable:null})}getTextElementAtPosition(o,n){let r=this.getElementAtPosition(o,n,{includeBoundTextElement:!0});return r&&kn(r)&&!r.isDeleted?r:null}getElementAtPosition(o,n,r){let a=[];if(r&&"allHitElements"in r?a=r?.allHitElements||[]:a=this.getElementsAtPosition(o,n,{includeBoundTextElement:r?.includeBoundTextElement,includeLockedElements:r?.includeLockedElements}),a.length>1){if(r?.preferSelected){for(let s=a.length-1;s>-1;s--)if(this.state.selectedElementIds[a[s].id])return a[s]}let i=a[a.length-1];return Od({point:pe(o,n),element:i,threshold:this.getElementHitThreshold(i)/2,elementsMap:this.scene.getNonDeletedElementsMap(),frameNameBound:Qt(i)?this.frameNameBoundsCache.get(i):null})?i:a[a.length-2]}return a.length===1?a[0]:null}getElementsAtPosition(o,n,r){let a=[],i=this.scene.getNonDeletedElementsMap();return(r?.includeBoundTextElement&&r?.includeLockedElements?this.scene.getNonDeletedElements():this.scene.getNonDeletedElements().filter(l=>(r?.includeLockedElements||!l.locked)&&(r?.includeBoundTextElement||!(kn(l)&&l.containerId)))).filter(l=>this.hitElement(o,n,l)).filter(l=>{let c=oy(l,i);return c&&this.state.frameRendering.enabled&&this.state.frameRendering.clip?g6({x:o,y:n},c,i):!0}).filter(l=>zl(l)?(a.push(l),!1):!0).concat(a)}getElementHitThreshold(o){return Math.max(o.strokeWidth/2+.1,.85*(KP/this.state.zoom.value))}hitElement(o,n,r,a=!0){return a&&this.state.selectedElementIds[r.id]&&zq([r],this.state,this.editorInterface)&&EJ(pe(o,n),r,this.scene.getNonDeletedElementsMap(),this.getElementHitThreshold(r))||Kq(pe(o,n),r,this.scene.getNonDeletedElementsMap())?!0:Od({point:pe(o,n),element:r,threshold:this.getElementHitThreshold(r),elementsMap:this.scene.getNonDeletedElementsMap(),frameNameBound:Qt(r)?this.frameNameBoundsCache.get(r):null})}getTextBindableContainerAtPosition(o,n){let r=this.scene.getNonDeletedElements(),a=this.scene.getSelectedElements(this.state);if(a.length===1)return s6(a[0],!1)?a[0]:null;let i=null;for(let s=r.length-1;s>=0;--s){if(r[s].isDeleted)continue;let[l,c,m,p]=Og(r[s],this.scene.getNonDeletedElementsMap());if(Ol(r[s])&&Od({point:pe(o,n),element:r[s],elementsMap:this.scene.getNonDeletedElementsMap(),threshold:this.getElementHitThreshold(r[s])})){i=r[s];break}else if(l<o&&o<m&&c<n&&n<p){i=r[s];break}}return s6(i,!1)?i:null}handleHoverSelectedLinearElement(o,n,r){let a=this.scene.getNonDeletedElementsMap(),i=_e.getElement(o.elementId,a);if(i)if(this.state.selectedLinearElement){let s=-1,l=null;Od({point:pe(n,r),element:i,elementsMap:a,threshold:this.getElementHitThreshold(i)})?(s=_e.getPointIndexUnderCursor(i,a,this.state.zoom,n,r),l=_e.getSegmentMidpointHitCoords(o,{x:n,y:r},this.state,this.scene.getNonDeletedElementsMap()),(To(i)?s===0||s===i.points.length-1:s>=0)||l?Be(this.interactiveCanvas,lt.POINTER):this.hitElement(n,r,i)&&(!To(i)||!(i.startBinding||i.endBinding))&&(this.state.activeTool.type!=="lasso"||Object.keys(this.state.selectedElementIds).length>0)&&Be(this.interactiveCanvas,lt.MOVE)):this.hitElement(n,r,i)&&(!To(i)||!(i.startBinding||i.endBinding))&&(this.state.activeTool.type!=="lasso"||Object.keys(this.state.selectedElementIds).length>0)&&Be(this.interactiveCanvas,lt.MOVE),this.state.selectedLinearElement.hoverPointIndex!==s&&this.setState({selectedLinearElement:{...this.state.selectedLinearElement,hoverPointIndex:s}}),_e.arePointsEqual(this.state.selectedLinearElement.segmentMidPointHoveredCoords,l)||this.setState({selectedLinearElement:{...this.state.selectedLinearElement,segmentMidPointHoveredCoords:l}});let c=null,m=i;(m.startBinding||m.endBinding)&&(c=CJ(i,n,r,this.scene,this.state)),this.state.selectedLinearElement.hoveredFocusPointBinding!==c&&this.setState({selectedLinearElement:{...this.state.selectedLinearElement,isDragging:!1,hoveredFocusPointBinding:c}}),c&&Be(this.interactiveCanvas,lt.POINTER)}else Be(this.interactiveCanvas,lt.AUTO)}updateGestureOnPointerDown(o){Ne.pointers.set(o.pointerId,{x:o.clientX,y:o.clientY}),Ne.pointers.size===2&&(Ne.lastCenter=M0(Ne.pointers),Ne.initialScale=this.state.zoom.value,Ne.initialDistance=P0(Array.from(Ne.pointers.values())))}initialPointerDownState(o){let n=rt(o,this.state),r=this.scene.getSelectedElements(this.state),[a,i,s,l]=Fl(r),c=r.findIndex(To)===0;return{origin:n,withCmdOrCtrl:o[ne.CTRL_OR_CMD],originInGrid:H1(Jt(n.x,n.y,o[ne.CTRL_OR_CMD]||c?null:this.getEffectiveGridSize())),scrollbars:ix(Wd,o.clientX-this.state.offsetLeft,o.clientY-this.state.offsetTop),lastCoords:{...n},originalElements:this.scene.getNonDeletedElements().reduce((m,p)=>(m.set(p.id,a6(p)),m),new Map),resize:{handleType:!1,isResizing:!1,offset:{x:0,y:0},arrowDirection:"origin",center:{x:(s+a)/2,y:(l+i)/2}},hit:{element:null,allHitElements:[],wasAddedToSelection:!1,hasBeenDuplicated:!1,hasHitCommonBoundingBoxOfSelectedElements:this.isHittingCommonBoundingBoxOfSelectedElements(n,r)},drag:{hasOccurred:!1,offset:null,origin:{...n},blockDragging:!1},eventListeners:{onMove:null,onUp:null,onKeyUp:null,onKeyDown:null},boxSelection:{hasOccurred:!1}}}handleDraggingScrollBar(o,n){if(!(n.scrollbars.isOverEither&&!this.state.multiElement))return!1;cy=!0,n.lastCoords.x=o.clientX,n.lastCoords.y=o.clientY;let r=Fu(i=>{i.target instanceof HTMLElement&&this.handlePointerMoveOverScrollbars(i,n)}),a=pt(()=>{$d=null,cy=!1,Ao(this.interactiveCanvas,this.state),this.setState({cursorButton:"up"}),this.savePointer(o.clientX,o.clientY,"up"),window.removeEventListener(he.POINTER_MOVE,r),window.removeEventListener(he.POINTER_UP,a),r.flush()});return $d=a,window.addEventListener(he.POINTER_MOVE,r),window.addEventListener(he.POINTER_UP,a),!0}isASelectedElement(o){return o!=null&&this.state.selectedElementIds[o.id]}isHittingCommonBoundingBoxOfSelectedElements(o,n){if(n.length<2)return!1;let r=Math.max(KP/this.state.zoom.value,1),[a,i,s,l]=Fl(n);return o.x>a-r&&o.x<s+r&&o.y>i-r&&o.y<l+r}getCurrentItemRoundness(o){return this.state.currentItemRoundness==="round"?{type:Aq(o)?_g.ADAPTIVE_RADIUS:_g.PROPORTIONAL_RADIUS}:null}maybeCacheReferenceSnapPoints(o,n,r=!1){kr({event:o,app:this,selectedElements:n})&&(r||!jo.getReferenceSnapPoints())&&jo.setReferenceSnapPoints(uk(this.scene.getNonDeletedElements(),n,this.state,this.scene.getNonDeletedElementsMap()))}maybeCacheVisibleGaps(o,n,r=!1){kr({event:o,app:this,selectedElements:n})&&(r||!jo.getVisibleGaps())&&jo.setVisibleGaps(pk(this.scene.getNonDeletedElements(),n,this.state,this.scene.getNonDeletedElementsMap()))}onKeyDownFromPointerDownHandler(o){return pt(n=>{this.maybeHandleResize(o,n)||this.maybeDragNewGenericElement(o,n)})}onKeyUpFromPointerDownHandler(o){return pt(n=>{n.key===ne.ALT&&n.preventDefault(),!this.maybeHandleResize(o,n)&&this.maybeDragNewGenericElement(o,n)})}onPointerMoveFromPointerDownHandler(o){return Fu(n=>{if(this.state.openDialog?.name==="elementLinkSelector")return;let r=rt(n,this.state);if(this.state.activeLockedId&&this.setState({activeLockedId:null}),this.state.selectedLinearElement&&this.state.selectedLinearElement.elbowed&&this.state.selectedLinearElement.initialState.segmentMidpoint.index){let[d,u]=Jt(r.x,r.y,n[ne.CTRL_OR_CMD]?null:this.getEffectiveGridSize()),h=this.state.selectedLinearElement.initialState.segmentMidpoint.index;if(h<0){let x=_e.getSegmentMidpointHitCoords({...this.state.selectedLinearElement,segmentMidPointHoveredCoords:null},{x:d,y:u},this.state,this.scene.getNonDeletedElementsMap());h=x?_e.getSegmentMidPointIndex(this.state.selectedLinearElement,this.state,x,this.scene.getNonDeletedElementsMap()):-1}let g=_e.moveFixedSegment(this.state.selectedLinearElement,h,d,u,this.scene);this.setState({selectedLinearElement:{...this.state.selectedLinearElement,isDragging:!0,segmentMidPointHoveredCoords:g.segmentMidPointHoveredCoords,initialState:g.initialState}});return}let a=this.previousPointerMoveCoords??o.origin;if(this.previousPointerMoveCoords=r,o.drag.offset===null&&(o.drag.offset=H1(xJ(this.scene.getSelectedElements(this.state),o.origin.x,o.origin.y))),!(n.target instanceof HTMLElement)||this.handlePointerMoveOverScrollbars(n,o))return;if(ho(this.state)){this.handleEraser(n,r);return}this.state.activeTool.type==="laser"&&this.laserTrails.addPointToPath(r.x,r.y);let[s,l]=Jt(r.x,r.y,n[ne.CTRL_OR_CMD]?null:this.getEffectiveGridSize());if(o.resize.isResizing&&(o.lastCoords.x=r.x,o.lastCoords.y=r.y,this.maybeHandleCrop(o,n)||this.maybeHandleResize(o,n)))return!0;let c=this.scene.getNonDeletedElementsMap();if(this.state.selectedLinearElement){let d=this.state.selectedLinearElement;if(d.draggedFocusPointBinding){TJ(d,c,r,this.scene,this.state,this.getEffectiveGridSize(),n.altKey),this.setState({selectedLinearElement:{...d,isDragging:!1,selectedPointsIndices:[],initialState:{...d.initialState,lastClickedPoint:-1}}});return}if(_e.shouldAddMidpoint(this.state.selectedLinearElement,r,this.state,c)){let u=_e.addMidpoint(this.state.selectedLinearElement,r,this,!n[ne.CTRL_OR_CMD],this.scene);if(!u)return;Io(()=>{this.state.selectedLinearElement&&this.setState({selectedLinearElement:{...this.state.selectedLinearElement,initialState:u.pointerDownState,selectedPointsIndices:u.selectedPointsIndices,segmentMidPointHoveredCoords:null}})});return}else{if(d.initialState.segmentMidpoint.value!==null&&!d.initialState.segmentMidpoint.added)return;if(d.initialState.lastClickedPoint>-1){let u=_e.getElement(d.elementId,c);if(u?.isDeleted)return;if(lr(u)){let g=Cn(pe(r.x,r.y),this.scene.getNonDeletedElements(),c);Rr("COMPLEX_BINDINGS")&&this.handleDelayedBindModeChange(u,g)}if(n.altKey&&!this.state.selectedLinearElement?.initialState?.arrowStartIsInside&&Rr("COMPLEX_BINDINGS")&&this.handleSkipBindMode(),d.initialState.lastClickedPoint===-1)return;let h=_e.handlePointDragging(n,this,r.x,r.y,d);if(h){o.lastCoords.x=r.x,o.lastCoords.y=r.y,o.drag.hasOccurred=!0,(h.suggestedBinding!==this.state.suggestedBinding||!JP(h.selectedLinearElement?.selectedPointsIndices??[],this.state.selectedLinearElement?.selectedPointsIndices??[])||h.selectedLinearElement?.hoverPointIndex!==this.state.selectedLinearElement?.hoverPointIndex||h.selectedLinearElement?.customLineAngle!==this.state.selectedLinearElement?.customLineAngle||this.state.selectedLinearElement.isDragging!==h.selectedLinearElement?.isDragging||this.state.selectedLinearElement?.initialState?.altFocusPoint!==h.selectedLinearElement?.initialState?.altFocusPoint)&&this.setState(h);return}}}}let m=o.hit.allHitElements.some(d=>this.isASelectedElement(d)),p=this.state.selectedLinearElement?.isEditing&&n.shiftKey&&this.state.selectedLinearElement.elementId===o.hit.element?.id;if((m||o.hit.hasHitCommonBoundingBoxOfSelectedElements)&&!p&&!o.drag.blockDragging){let d=this.scene.getSelectedElements(this.state);if(d.length>0&&d.every(x=>x.locked))return;let u=d.find(x=>Qt(x)),h=this.getTopLayerFrameAtSceneCoords(r),g=h&&!u?h:null;if(this.state.frameToHighlight!==g&&Io(()=>{this.setState({frameToHighlight:g})}),o.drag.hasOccurred=!0,this.state.activeTool.type==="lasso"&&this.lassoTrail.hasCurrentTrail&&!(this.editorInterface.formFactor!=="desktop"&&o.hit.element)&&!this.state.activeTool.fromSelection)return;if(this.state.activeTool.type==="lasso"&&d.length>0&&o.drag.hasOccurred&&!this.state.activeTool.fromSelection&&this.lassoTrail.endPath(),d.length>0&&!o.withCmdOrCtrl&&!this.state.editingTextElement&&this.state.activeEmbeddable?.state!=="active"){let x={x:r.x-o.drag.origin.x,y:r.y-o.drag.origin.y},E=[...o.originalElements.values()],y=n.shiftKey;if(y){let I=Math.abs(x.x),C=Math.abs(x.y),P=y&&I<C,S=y&&I>C;P&&(x.x=0),S&&(x.y=0)}if(this.state.croppingElementId){let I=this.scene.getNonDeletedElementsMap().get(this.state.croppingElementId);if(I&&Da(I)&&I.crop!==null&&o.hit.element===I){let C=I.crop,P=Fd(I)&&this.imageCache.get(I.fileId)?.image;if(P&&!(P instanceof Promise)){let S=MJ(I),D=BP(r.x-a.x,r.y-a.y);D[0]*=P.naturalWidth/S.width,D[1]*=P.naturalHeight/S.height;let[_,k,M,B,O,N]=Og(I,c),z=B1(N1(pe(_,k),pe(O,N),I.angle)),L=B1(N1(pe(M,k),pe(O,N),I.angle)),F=B1(N1(pe(_,B),pe(O,N),I.angle)),$=zP(FP(L,z)),Q=zP(FP(F,z)),Z=BP(OP(D,$),OP(D,Q)),U={...C,x:NP(C.x-Z[0]*Math.sign(I.scale[0]),0,P.naturalWidth-C.width),y:NP(C.y-Z[1]*Math.sign(I.scale[1]),0,P.naturalHeight-C.height)};this.scene.mutateElement(I,{crop:U});return}}}this.maybeCacheVisibleGaps(n,d),this.maybeCacheReferenceSnapPoints(n,d);let{snapOffset:w,snapLines:v}=gk(E,x,this,n,this.scene.getNonDeletedElementsMap());if(this.setState({snapLines:v}),this.state.editingFrame||bJ(o,d,x,this.scene,w,n[ne.CTRL_OR_CMD]?null:this.getEffectiveGridSize()),this.setState({selectedElementsAreBeingDragged:!0,selectionElement:null}),n.altKey&&!o.hit.hasBeenDuplicated){o.hit.hasBeenDuplicated=!0;let I=this.scene.getElementsIncludingDeleted(),C=o.hit.element,P=this.scene.getSelectedElements({selectedElementIds:this.state.selectedElementIds,includeBoundTextElement:!0,includeElementsInFrames:!0});C&&o.hit.wasAddedToSelection&&!P.find(z=>z.id===C.id)&&P.push(C);let S=new Map(P.map(z=>[z.id,z])),{duplicatedElements:D,duplicateElementsMap:_,elementsWithDuplicates:k,origIdToDuplicateId:M}=Y1({type:"in-place",elements:I,appState:this.state,randomizeSeed:!0,idsOfElementsToDuplicate:S,overrides:({duplicateElement:z,origElement:L})=>({frameId:z.frameId??L.frameId,seed:cq()})});D.forEach(z=>{o.originalElements.set(z.id,a6(z))});let B=k.map(z=>{if(S.has(z.id)){let L=o.originalElements.get(z.id);if(L)return _a(z,{x:L.x,y:L.y})}return z}),O=this.props.onDuplicate?.(B,I),N=E6(O||B,Bg(D));Io(()=>{if(o.hit.element){let z=M.get(o.hit.element.id),L=z&&_.get(z);o.hit.element=L||null}o.hit.allHitElements=o.hit.allHitElements.reduce((z,L)=>{let F=M.get(L.id),$=F&&_.get(F);return $&&z.push($),z},[]),o.drag.origin=rt(n,this.state),this.setState(z=>({...uJ(D,this.scene.getNonDeletedElements(),z)})),this.scene.replaceAllElements(N),P.forEach(z=>{X1(z)&&z.boundElements?.some(L=>L.type==="arrow")&&zg(z,this.scene)}),this.maybeCacheVisibleGaps(n,P,!0),this.maybeCacheReferenceSnapPoints(n,P,!0)})}return}}if(this.state.selectionElement){if(o.lastCoords.x=r.x,o.lastCoords.y=r.y,n.altKey){this.setActiveTool({type:"lasso",fromSelection:!0},n.shiftKey),this.lassoTrail.startPath(o.origin.x,o.origin.y,n.shiftKey),this.setAppState({selectionElement:null});return}this.maybeDragNewGenericElement(o,n)}else if(this.state.activeTool.type==="lasso")!n.altKey&&this.state.activeTool.fromSelection?(this.setActiveTool({type:"selection"}),this.createGenericElementOnPointerDown("selection",o),o.lastCoords.x=r.x,o.lastCoords.y=r.y,this.maybeDragNewGenericElement(o,n),this.lassoTrail.endPath()):this.lassoTrail.addPointToPath(r.x,r.y,n.shiftKey);else{let d=this.state.newElement;if(!d)return;if(d.type==="freedraw"){let u=d.points,h=r.x-d.x,g=r.y-d.y,x=u.length>0&&u[u.length-1];if(!(x&&x[0]===h&&x[1]===g)){let y=d.simulatePressure?d.pressures:[...d.pressures,n.pressure];this.scene.mutateElement(d,{points:[...u,pe(h,g)],pressures:y},{informMutation:!1,isDragging:!1}),this.setState({newElement:d})}}else if(mo(d)&&!d.isDeleted){o.drag.hasOccurred=!0;let u=d.points;sr(u.length>1,"Do not create linear elements with less than 2 points");let h=this.state.selectedLinearElement;h||(h=new _e(d,this.scene.getNonDeletedElementsMap()),h={...h,selectedPointsIndices:[1],initialState:{...h.initialState,lastClickedPoint:1}}),this.setState({newElement:d,..._e.handlePointDragging(n,this,s,l,h)})}else o.lastCoords.x=r.x,o.lastCoords.y=r.y,this.maybeDragNewGenericElement(o,n,!1)}if(this.state.activeTool.type==="selection"){o.boxSelection.hasOccurred=!0;let d=this.scene.getNonDeletedElements();if(this.state.selectedLinearElement?.isEditing)_e.handleBoxSelection(n,this.state,this.setState.bind(this),this.scene.getNonDeletedElementsMap());else{let u=!0;!n.shiftKey&&Ge(d,this.state)&&(o.withCmdOrCtrl&&o.hit.element?this.setState(g=>cn({...g,selectedElementIds:{[o.hit.element.id]:!0}},this.scene.getNonDeletedElements(),g,this)):u=!1);let h=this.state.selectionElement?rE(d,this.state.selectionElement,this.scene.getNonDeletedElementsMap(),!1):[];this.setState(g=>{let x={...u&&g.selectedElementIds,...h.reduce((E,y)=>(E[y.id]=!0,E),{})};return o.hit.element&&(h.length?delete x[o.hit.element.id]:x[o.hit.element.id]=!0),g=u?g:{...g,selectedGroupIds:{},editingGroupId:null},{...cn({editingGroupId:g.editingGroupId,selectedElementIds:x},this.scene.getNonDeletedElements(),g,this),selectedLinearElement:h.length===1&&mo(h[0])?new _e(h[0],this.scene.getNonDeletedElementsMap()):null,showHyperlinkPopup:h.length===1&&(h[0].link||Nr(h[0]))?"info":!1}})}}})}handlePointerMoveOverScrollbars(o,n){if(n.scrollbars.isOverHorizontal){let r=o.clientX,a=r-n.lastCoords.x;return this.translateCanvas({scrollX:this.state.scrollX-a*(Wd.horizontal?.deltaMultiplier||1)/this.state.zoom.value}),n.lastCoords.x=r,!0}if(n.scrollbars.isOverVertical){let r=o.clientY,a=r-n.lastCoords.y;return this.translateCanvas({scrollY:this.state.scrollY-a*(Wd.vertical?.deltaMultiplier||1)/this.state.zoom.value}),n.lastCoords.y=r,!0}return!1}onPointerUpFromPointerDownHandler(o){return pt(n=>{let r=this.scene.getNonDeletedElementsMap();this.removePointer(n),o.drag.blockDragging=!1,o.eventListeners.onMove&&o.eventListeners.onMove.flush();let{newElement:a,resizingElement:i,croppingElementId:s,multiElement:l,activeTool:c,isResizing:m,isRotating:p,isCropping:d}=this.state;this.setState(y=>({isResizing:!1,isRotating:!1,isCropping:!1,resizingElement:null,selectionElement:null,frameToHighlight:null,elementsToHighlight:null,cursorButton:"up",snapLines:Nd(y.snapLines,[]),originSnapOffset:null})),this.lassoTrail.endPath(),this.previousPointerMoveCoords=null,jo.setReferenceSnapPoints(null),jo.setVisibleGaps(null),this.savePointer(n.clientX,n.clientY,"up");let u=o.hit.allHitElements,h=rt({clientX:n.clientX,clientY:n.clientY},this.state);if(this.state.activeTool.type==="selection"&&!o.boxSelection.hasOccurred&&!o.resize.isResizing&&!u.some(y=>this.state.selectedElementIds[y.id])){let y=this.getElementAtPosition(h.x,h.y,{includeLockedElements:!0});this.store.scheduleCapture(),y?.locked?this.setState({activeLockedId:y.groupIds.length>0?y.groupIds.at(-1)||"":y.id}):this.setState({activeLockedId:null})}else this.setState({activeLockedId:null});if(Rr("COMPLEX_BINDINGS")&&this.resetDelayedBindMode(),this.setState({selectedElementsAreBeingDragged:!1,bindMode:"orbit"}),o.drag.hasOccurred&&o.hit?.element?.id){let y=r.get(o.hit.element.id);X1(y)&&y.boundElements?.filter(w=>w.type==="arrow").map(w=>r.get(w.id)).filter(w=>To(w)).forEach(w=>{w&&this.scene.mutateElement(w,{})})}if(this.state.selectedLinearElement?.isEditing&&!this.state.newElement&&this.state.selectedLinearElement.draggedFocusPointBinding===null)if(!o.boxSelection.hasOccurred&&o.hit?.element?.id!==this.state.selectedLinearElement.elementId&&this.state.selectedLinearElement.draggedFocusPointBinding===null)this.actionManager.executeAction(ro);else{let y=_e.handlePointerUp(n,this.state.selectedLinearElement,this.state,this.scene);this.actionManager.executeAction(ro,"ui",{event:n,sceneCoords:h}),y!==this.state.selectedLinearElement&&this.setState({selectedLinearElement:y,suggestedBinding:null})}else if(this.state.selectedLinearElement){if(this.state.selectedLinearElement.elbowed){let y=_e.getElement(this.state.selectedLinearElement.elementId,this.scene.getNonDeletedElementsMap());y&&this.scene.mutateElement(y,{})}if(this.state.selectedLinearElement.draggedFocusPointBinding?(SJ(this.state.selectedLinearElement,this.scene),this.setState({selectedLinearElement:{...this.state.selectedLinearElement,draggedFocusPointBinding:null}})):o.hit?.element?.id!==this.state.selectedLinearElement.elementId?this.scene.getSelectedElements(this.state).length>1&&this.setState({selectedLinearElement:null}):this.state.selectedLinearElement.isDragging&&(this.setState({selectedLinearElement:{...this.state.selectedLinearElement,isDragging:!1}}),this.actionManager.executeAction(ro,"ui",{event:n,sceneCoords:h})),this.state.newElement&&this.state.multiElement&&mo(this.state.newElement)&&this.state.selectedLinearElement){let{multiElement:y}=this.state;this.setState({selectedLinearElement:{...this.state.selectedLinearElement,lastCommittedPoint:y.points[y.points.length-1]}})}}if(this.missingPointerEventCleanupEmitter.clear(),window.removeEventListener(he.POINTER_MOVE,o.eventListeners.onMove),window.removeEventListener(he.POINTER_UP,o.eventListeners.onUp),window.removeEventListener(he.KEYDOWN,o.eventListeners.onKeyDown),window.removeEventListener(he.KEYUP,o.eventListeners.onKeyUp),this.props?.onPointerUp?.(c,o),this.onPointerUpEmitter.trigger(this.state.activeTool,o,n),a?.type==="freedraw"){let y=rt(n,this.state),w=a.points,v=y.x-a.x,I=y.y-a.y;v===w[0][0]&&I===w[0][1]&&(I+=1e-4,v+=1e-4);let C=a.simulatePressure?[]:[...a.pressures,n.pressure];this.scene.mutateElement(a,{points:[...w,pe(v,I)],pressures:C}),this.actionManager.executeAction(ro);return}if(mo(a)){a.points.length>1&&a.points[1][0]!==0&&a.points[1][1]!==0&&this.store.scheduleCapture();let y=rt(n,this.state),w=Pa(pe(y.x,y.y),pe(o.origin.x,o.origin.y))*this.state.zoom.value;if((!o.drag.hasOccurred||w<dq)&&a&&!l)if(this.editorInterface.isTouchScreen){let v=Math.min(this.state.width*.7/this.state.zoom.value,100);this.scene.mutateElement(a,{x:a.x-v/2,points:[pe(0,0),pe(v,0)]},{informMutation:!1,isDragging:!1}),this.actionManager.executeAction(ro)}else{let v=y.x-a.x,I=y.y-a.y;this.scene.mutateElement(a,{points:[a.points[0],pe(v,I)]},{informMutation:!1,isDragging:!1}),this.setState({multiElement:a,newElement:a})}else o.drag.hasOccurred&&!l&&(mo(a)&&this.actionManager.executeAction(ro,"ui",{event:n,sceneCoords:h}),this.setState({suggestedBinding:null,startBoundElement:null}),c.locked?this.setState(v=>({newElement:null})):(Po(this.interactiveCanvas),this.setState(v=>({newElement:null,activeTool:ir(this.state,{type:this.state.preferredSelectionTool.type}),selectedElementIds:ze({...v.selectedElementIds,[a.id]:!0},v),selectedLinearElement:new _e(a,this.scene.getNonDeletedElementsMap())}))),this.scene.triggerUpdate());return}if(kn(a)){let y=iJ(z1({fontSize:a.fontSize,fontFamily:a.fontFamily}),a.lineHeight);a.width<y&&this.scene.mutateElement(a,{autoResize:!0}),this.resetCursor(),this.handleTextWysiwyg(a,{isExistingElement:!0})}if(c.type!=="selection"&&a&&c6(a)){this.updateScene({elements:this.scene.getElementsIncludingDeleted().filter(y=>y.id!==a.id),appState:{newElement:null},captureUpdate:po.NEVER});return}if(Qt(a)){let y=Uq(this.scene.getElementsIncludingDeleted(),a,this.scene.getNonDeletedElementsMap());this.scene.replaceAllElements(ey(this.scene.getElementsMapIncludingDeleted(),y,a,this.state))}if(a&&(this.scene.mutateElement(a,_q(a),{informMutation:!1,isDragging:!1}),this.scene.triggerUpdate()),o.drag.hasOccurred){let y=rt(n,this.state);if(this.state.selectedLinearElement&&this.state.selectedLinearElement.isDragging){let w=this.scene.getElement(this.state.selectedLinearElement.elementId);if(w?.frameId){let v=oy(w,r);v&&w&&(Wq(w,v,this.scene.getNonDeletedElementsMap())||(this.scene.mutateElement(w,{groupIds:[]}),Gq([w],this.scene.getNonDeletedElementsMap()),this.scene.triggerUpdate()))}}else{let w=this.getTopLayerFrameAtSceneCoords(y),v=this.scene.getSelectedElements(this.state),I=this.scene.getElementsMapIncludingDeleted(),C=P=>{if(P.length>0){for(let S of P){let D=S.groupIds.indexOf(this.state.editingGroupId);this.scene.mutateElement(S,{groupIds:S.groupIds.slice(0,D)},{informMutation:!1,isDragging:!1})}I.forEach(S=>{S.groupIds.length&&Li(I,S.groupIds[S.groupIds.length-1]).length<2&&this.scene.mutateElement(S,{groupIds:[]},{informMutation:!1,isDragging:!1})}),this.setState({editingGroupId:null})}};if(w&&!this.state.selectedElementIds[w.id]){let P=v.filter(S=>S.frameId!==w.id&&f6(S,I,this.state));this.state.editingGroupId&&C(P),I=ey(I,P,w,this.state)}else if(!w&&this.state.editingGroupId){let P=v.filter(S=>S.frameId&&!f6(S,I,this.state));C(P)}I=h6(I,this.state,this),this.scene.replaceAllElements(I)}}if(i&&this.store.scheduleCapture(),i&&c6(i)&&this.updateScene({elements:this.scene.getElementsIncludingDeleted().filter(y=>y.id!==i.id),captureUpdate:po.NEVER}),o.resize.isResizing){let y=h6(this.scene.getElementsIncludingDeleted(),this.state,this),w=this.scene.getSelectedElements(this.state).filter(v=>Qt(v));for(let v of w)y=Hq(y,ty(this.scene.getElementsIncludingDeleted(),v,this.state,r),v,this);this.scene.replaceAllElements(y)}let g=o.hit.element;this.state.selectedLinearElement?.elementId!==g?.id&&mo(g)&&this.scene.getSelectedElements(this.state).length===1&&this.setState({selectedLinearElement:new _e(g,this.scene.getNonDeletedElementsMap())}),(!s||s&&(!g&&!d||g&&g.id!==s))&&this.finishImageCropping();let x=this.lastPointerDownEvent,E=this.lastPointerUpEvent||this.lastPointerMoveEvent;if(ho(this.state)&&x&&E){if(this.eraserTrail.endPath(),Pa(pe(x.clientX,x.clientY),pe(E.clientX,E.clientY))===0){let w=rt({clientX:E.clientX,clientY:E.clientY},this.state);this.getElementsAtPosition(w.x,w.y).forEach(I=>this.elementsPendingErasure.add(I.id))}this.eraseElements();return}else this.elementsPendingErasure.size&&this.restoreReadyToEraseElements();if(g&&!o.drag.hasOccurred&&!o.hit.wasAddedToSelection&&(!this.state.selectedLinearElement?.isEditing||!o.boxSelection.hasOccurred)&&this.state.activeTool.type!=="lasso"&&(n.shiftKey&&!this.state.selectedLinearElement?.isEditing?this.state.selectedElementIds[g.id]?mJ(this.state,g)?this.setState(y=>{let w={...y.selectedElementIds};for(let v of g.groupIds.flatMap(I=>Li(this.scene.getNonDeletedElements(),I)))delete w[v.id];return{selectedGroupIds:{...y.selectedElementIds,...g.groupIds.map(v=>({[v]:!1})).reduce((v,I)=>({...v,...I}),{})},selectedElementIds:ze(w,y)}}):this.state.selectedLinearElement?.isDragging||this.setState(y=>{let w={...y.selectedElementIds};delete w[g.id];let v=de(this.scene.getNonDeletedElements(),{selectedElementIds:w});return{...cn({editingGroupId:y.editingGroupId,selectedElementIds:w},this.scene.getNonDeletedElements(),y,this),selectedLinearElement:v.length===1&&mo(v[0])?new _e(v[0],this.scene.getNonDeletedElementsMap()):y.selectedLinearElement}}):g.frameId&&this.state.selectedElementIds[g.frameId]?this.setState(y=>{let w={...y.selectedElementIds,[g.id]:!0};return delete w[g.frameId],(this.scene.getElement(g.frameId)?.groupIds??[]).flatMap(v=>Li(this.scene.getNonDeletedElements(),v)).forEach(v=>{delete w[v.id]}),{...cn({editingGroupId:y.editingGroupId,selectedElementIds:w},this.scene.getNonDeletedElements(),y,this),showHyperlinkPopup:g.link||Nr(g)?"info":!1}}):this.setState(y=>({selectedElementIds:ze({...y.selectedElementIds,[g.id]:!0},y)})):this.setState(y=>({...cn({editingGroupId:y.editingGroupId,selectedElementIds:{[g.id]:!0}},this.scene.getNonDeletedElements(),y,this),selectedLinearElement:mo(g)&&y.selectedLinearElement?.elementId!==g.id?new _e(g,this.scene.getNonDeletedElementsMap()):y.selectedLinearElement}))),this.state.activeTool.type!=="lasso"&&!(g&&To(g))&&!o.drag.hasOccurred&&!this.state.isResizing&&(g&&Xq({point:pe(o.origin.x,o.origin.y),element:g,elementsMap:r,threshold:this.getElementHitThreshold(g),frameNameBound:Qt(g)?this.frameNameBoundsCache.get(g):null},r)||!g&&o.hit.hasHitCommonBoundingBoxOfSelectedElements)){this.state.selectedLinearElement?.isEditing?this.actionManager.executeAction(il):this.setState({selectedElementIds:ze({},this.state),selectedGroupIds:{},editingGroupId:null,activeEmbeddable:null}),Be(this.interactiveCanvas,lt.AUTO);return}if(!c.locked&&c.type!=="freedraw"&&a&&this.setState(y=>({selectedElementIds:ze({...y.selectedElementIds,[a.id]:!0},y),showHyperlinkPopup:Nr(a)&&!a.link?"editor":y.showHyperlinkPopup})),(c.type!=="selection"||Ge(this.scene.getNonDeletedElements(),this.state)||!JP(this.state.previousSelectedElementIds,this.state.selectedElementIds))&&this.store.scheduleCapture(),o.drag.hasOccurred&&!this.state.selectedLinearElement||m||p||d){let y=this.scene.getSelectedElements(this.state).filter(Ol);e6(y,this.scene,this.state)}if(c.type==="laser"){this.laserTrails.endPath();return}!c.locked&&c.type!=="freedraw"&&(c.type!=="lasso"||c.type==="lasso"&&c.fromSelection)?(Po(this.interactiveCanvas),this.setState({newElement:null,suggestedBinding:null,activeTool:ir(this.state,{type:this.state.preferredSelectionTool.type})})):this.setState({newElement:null,suggestedBinding:null})})}clearSelection(o){this.setState(n=>({selectedElementIds:ze({},n),activeEmbeddable:null,selectedGroupIds:{},editingGroupId:n.editingGroupId&&o!=null&&y6(o,n.editingGroupId)?n.editingGroupId:null})),this.setState({selectedElementIds:ze({},this.state),activeEmbeddable:null,previousSelectedElementIds:this.state.selectedElementIds,selectedLinearElement:null})}getTextWysiwygSnappedToCenterPosition(o,n,r,a){if(a){let i=a.x+a.width/2,s=a.y+a.height/2,l=J1(a,r,this.scene.getNonDeletedElementsMap());if(l&&(i=l.x,s=l.y),Math.hypot(o-i,n-s)<$j){let{x:p,y:d}=Ng({sceneX:i,sceneY:s},r);return{viewportX:p,viewportY:d,elementCenterX:i,elementCenterY:s}}}}getCanvasOffsets(){if(this.excalidrawContainerRef?.current){let o=this.excalidrawContainerRef.current,{left:n,top:r}=o.getBoundingClientRect();return{offsetLeft:n,offsetTop:r}}return{offsetLeft:0,offsetTop:0}}async updateLanguage(){let o=Zi.find(n=>n.code===this.props.langCode)||Nn;await pm(o),this.setAppState({})}},PJ=()=>{(N6()||B6())&&(window.h=window.h||{},Object.defineProperties(window.h,{elements:{configurable:!0,get(){return this.app?.scene.getElementsIncludingDeleted()},set(e){return this.app?.scene.replaceAllElements(O6(e))}},scene:{configurable:!0,get(){return this.app?.scene}}}))};PJ();var G6=uy;import{useEffect as AJ,useState as LJ}from"react";import{jsx as _J}from"react/jsx-runtime";var U6=e=>{let[t,o]=LJ(!0);return AJ(()=>{let n=async()=>{await pm(r),o(!1)},r=Zi.find(a=>a.code===e.langCode)||Nn;n()},[e.langCode]),t?_J(Uu,{theme:e.theme}):e.children};import DJ from"clsx";import{jsx as W6}from"react/jsx-runtime";var Y6=({children:e})=>{let{FooterCenterTunnel:t}=Ze(),o=Ie();return W6(t.In,{children:W6("div",{className:DJ("footer-center zen-mode-transition",{"layer-ui__wrapper__footer-left--transition-bottom":o.zenModeEnabled}),children:e})})},RJ=Y6;Y6.displayName="FooterCenter";import NJ from"clsx";import{MQ_MIN_WIDTH_DESKTOP as BJ}from"@orangecatai/common";import{jsx as OJ,jsxs as zJ}from"react/jsx-runtime";var $6=({isCollaborating:e,onSelect:t,editorInterface:o,...n})=>{let r=Ie(),a=o?.formFactor!=="desktop"||r.width<BJ;return zJ(so,{...n,className:NJ("collab-button",{active:e}),type:"button",onSelect:t,style:{position:"relative",width:a?void 0:"auto"},title:f("labels.liveCollaboration"),children:[a?ZE:f("labels.share"),r.collaborators.size>0&&OJ("div",{className:"CollabButton-collaborators",children:r.collaborators.size})]})},FJ=$6;$6.displayName="LiveCollaborationTrigger";import{jsx as Fa,jsxs as K6}from"react/jsx-runtime";var HJ=()=>Fa("svg",{viewBox:"0 0 40 40",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:"ExcalidrawLogo-icon",children:Fa("path",{d:"M39.9 32.889a.326.326 0 0 0-.279-.056c-2.094-3.083-4.774-6-7.343-8.833l-.419-.472a.212.212 0 0 0-.056-.139.586.586 0 0 0-.167-.111l-.084-.083-.056-.056c-.084-.167-.28-.278-.475-.167-.782.39-1.507.973-2.206 1.528-.92.722-1.842 1.445-2.708 2.25a8.405 8.405 0 0 0-.977 1.028c-.14.194-.028.361.14.444-.615.611-1.23 1.223-1.843 1.861a.315.315 0 0 0-.084.223c0 .083.056.166.111.194l1.09.833v.028c1.535 1.528 4.244 3.611 7.12 5.861.418.334.865.667 1.284 1 .195.223.39.473.558.695.084.11.28.139.391.055.056.056.14.111.196.167a.398.398 0 0 0 .167.056.255.255 0 0 0 .224-.111.394.394 0 0 0 .055-.167c.029 0 .028.028.056.028a.318.318 0 0 0 .224-.084l5.082-5.528a.309.309 0 0 0 0-.444Zm-14.63-1.917a.485.485 0 0 0 .111.14c.586.5 1.2 1 1.843 1.555l-2.569-1.945-.251-.166c-.056-.028-.112-.084-.168-.111l-.195-.167.056-.056.055-.055.112-.111c.866-.861 2.346-2.306 3.1-3.028-.81.805-2.43 3.167-2.095 3.944Zm8.767 6.89-2.122-1.612a44.713 44.713 0 0 0-2.625-2.5c1.145.861 2.122 1.611 2.262 1.75 1.117.972 1.06.806 1.815 1.445l.921.666a1.06 1.06 0 0 1-.251.25Zm.558.416-.056-.028c.084-.055.168-.111.252-.194l-.196.222ZM1.089 5.75c.055.361.14.722.195 1.056.335 1.833.67 3.5 1.284 4.75l.252.944c.084.361.223.806.363.917 1.424 1.25 3.602 3.11 5.947 4.889a.295.295 0 0 0 .363 0s0 .027.028.027a.254.254 0 0 0 .196.084.318.318 0 0 0 .223-.084c2.988-3.305 5.221-6.027 6.813-8.305.112-.111.14-.278.14-.417.111-.111.195-.25.307-.333.111-.111.111-.306 0-.39l-.028-.027c0-.055-.028-.139-.084-.167-.698-.666-1.2-1.138-1.731-1.638-.922-.862-1.871-1.75-3.881-3.75l-.028-.028c-.028-.028-.056-.056-.112-.056-.558-.194-1.703-.389-3.127-.639C6.087 2.223 3.21 1.723.614.944c0 0-.168 0-.196.028l-.083.084c-.028.027-.056.055-.224.11h.056-.056c.028.167.028.278.084.473 0 .055.112.5.112.555l.782 3.556Zm15.496 3.278-.335-.334c.084.112.196.195.335.334Zm-3.546 4.666-.056.056c0-.028.028-.056.056-.056Zm-2.038-10c.168.167.866.834 1.033.973-.726-.334-2.54-1.167-3.379-1.445.838.167 1.983.334 2.346.472ZM1.424 2.306c.419.722.754 3.222 1.089 5.666-.196-.778-.335-1.555-.503-2.278-.251-1.277-.503-2.416-.838-3.416.056 0 .14 0 .252.028Zm-.168-.584c-.112 0-.223-.028-.307-.028 0-.027 0-.055-.028-.055.14 0 .223.028.335.083Zm-1.089.222c0-.027 0-.027 0 0ZM39.453 1.333c.028-.11-.558-.61-.363-.639.42-.027.42-.666 0-.666-.558.028-1.144.166-1.675.25-.977.194-1.982.389-2.96.61-2.205.473-4.383.973-6.561 1.557-.67.194-1.424.333-2.066.666-.224.111-.196.333-.084.472-.056.028-.084.028-.14.056-.195.028-.363.056-.558.083-.168.028-.252.167-.224.334 0 .027.028.083.028.11-1.173 1.556-2.485 3.195-3.909 4.945-1.396 1.611-2.876 3.306-4.356 5.056-4.719 5.5-10.052 11.75-15.943 17.25a.268.268 0 0 0 0 .389c.028.027.056.055.084.055-.084.084-.168.14-.252.222-.056.056-.084.111-.084.167a.605.605 0 0 0-.111.139c-.112.111-.112.305.028.389.111.11.307.11.39-.028.029-.028.029-.056.056-.056a.44.44 0 0 1 .615 0c.335.362.67.723.977 1.028l-.698-.583c-.112-.111-.307-.083-.39.028-.113.11-.085.305.027.389l7.427 6.194c.056.056.112.056.196.056s.14-.028.195-.084l.168-.166c.028.027.083.027.111.027.084 0 .14-.027.196-.083 10.052-10.055 18.15-17.639 27.42-24.417.083-.055.111-.166.111-.25.112 0 .196-.083.251-.194 1.704-5.194 2.039-9.806 2.15-12.083v-.028c0-.028.028-.056.028-.083.028-.056.028-.084.028-.084a1.626 1.626 0 0 0-.111-1.028ZM21.472 9.5c.446-.5.893-1.028 1.34-1.5-2.876 3.778-7.65 9.583-14.408 16.5 4.607-5.083 9.242-10.333 13.068-15ZM5.193 35.778h.084-.084Zm3.462 3.194c-.027-.028-.027-.028 0-.028v.028Zm4.16-3.583c.224-.25.448-.472.699-.722 0 0 0 .027.028.027-.252.223-.475.445-.726.695Zm1.146-1.111c.14-.14.279-.334.446-.5l.028-.028c1.648-1.694 3.351-3.389 5.082-5.111l.028-.028c.419-.333.921-.694 1.368-1.028a379.003 379.003 0 0 0-6.952 6.695ZM24.794 6.472c-.921 1.195-1.954 2.778-2.82 4.028-2.736 3.944-11.532 13.583-11.727 13.75a1976.983 1976.983 0 0 1-8.042 7.639l-.167.167c-.14-.167-.14-.417.028-.556C14.49 19.861 22.03 10.167 25.074 5.917c-.084.194-.14.36-.28.555Zm4.83 5.695c-1.116-.64-1.646-1.64-1.34-2.611l.084-.334c.028-.083.084-.194.14-.277.307-.5.754-.917 1.257-1.167.027 0 .055 0 .083-.028-.028-.056-.028-.139-.028-.222.028-.167.14-.278.335-.278.335 0 1.369.306 1.76.639.111.083.223.194.335.305.14.167.363.445.474.667.056.028.112.306.196.445.056.222.111.472.084.694-.028.028 0 .194-.028.194a2.668 2.668 0 0 1-.363 1.028c-.028.028-.028.056-.056.084l-.028.027c-.14.223-.335.417-.53.556-.643.444-1.369.583-2.095.389 0 0-.195-.084-.28-.111Zm8.154-.834a39.098 39.098 0 0 1-.893 3.167c0 .028-.028.083 0 .111-.056 0-.084.028-.14.056-2.206 1.61-4.356 3.305-6.506 5.028 1.843-1.64 3.686-3.306 5.613-4.945.558-.5.949-1.139 1.06-1.861l.28-1.667v-.055c.14-.334.67-.195.586.166Z",fill:"currentColor"})}),GJ=()=>K6("svg",{viewBox:"0 0 450 55",xmlns:"http://www.w3.org/2000/svg",fill:"none",className:"ExcalidrawLogo-text",children:[Fa("path",{d:"M429.27 96.74c2.47-1.39 4.78-3.02 6.83-4.95 1.43-1.35 2.73-2.86 3.81-4.51-.66.9-1.4 1.77-2.23 2.59-2.91 2.84-5.72 5.09-8.42 6.87h.01ZM343.6 69.36c.33 3.13.58 6.27.79 9.4.09 1.37.18 2.75.25 4.12-.12-4.46-.27-8.93-.5-13.39-.11-2.08-.24-4.16-.4-6.24-.06 1.79-.11 3.85-.13 6.11h-.01ZM378.47 98.34c.01-.37.07-1.13.01-6.51-.11 1.9-.22 3.81-.31 5.71-.07 1.42-.22 2.91-.16 4.35.39.03.78.07 1.17.1-.92-.85-.76-2.01-.72-3.66l.01.01ZM344.09 86.12c-.09-2.41-.22-4.83-.39-7.24v12.21c.15-.05.32-.09.47-.14.05-1.61-.03-3.23-.09-4.83h.01ZM440.69 66.79c-.22-.34-.45-.67-.69-.99-3.71-4.87-9.91-7.14-15.65-8.55-1.05-.26-2.12-.49-3.18-.71 2.29.59 4.48 1.26 6.64 2.02 7.19 2.54 10.57 5.41 12.88 8.23ZM305.09 72.46l1.2 3.6c.84 2.53 1.67 5.06 2.46 7.61.24.78.5 1.57.73 2.36.22-.04.44-.08.67-.12a776.9 776.9 0 0 1-5.01-13.57c-.02.04-.03.09-.05.13v-.01ZM345.49 90.25v.31c1.48-.42 3.05-.83 4.66-1.2-1.56.25-3.12.52-4.66.89ZM371.02 90.22c0-.57-.04-1.14-.11-1.71-.06-.02-.12-.04-.19-.05-.21-.05-.43-.08-.65-.11.42.16.74.88.95 1.87ZM398.93 54.23c-.13 0-.27-.01-.4-.02l.03.4c.11-.15.23-.27.37-.38ZM401.57 62.28v-.15c-1.22-.24-2.86-.61-3.23-1.25-.09-.15-.18-.51-.27-.98-.09.37-.2.73-.33 1.09 1.24.56 2.52.98 3.83 1.29ZM421.73 88.68c-2.97 1.65-6.28 3.12-9.69 3.68v.18c4.72-.14 11.63-3.85 16.33-8.38-2.04 1.75-4.33 3.24-6.63 4.53l-.01-.01ZM411.28 80.92c-.05-1.2-.09-2.4-.15-3.6-.21 5.66-.46 11.38-.47 14.51.24-.02.48-.04.71-.07.15-3.61.05-7.23-.09-10.83v-.01Z",transform:"translate(-144.023 -51.76)"}),Fa("path",{d:"M425.38 67.41c-3.5-1.45-7.19-2.57-14.06-3.62.09 1.97.06 4.88-.03 8.12.03.04.06.09.06.15.19 1.36.28 2.73.37 4.1.25 3.77.39 7.55.41 11.33 0 1.38-.01 2.76-.07 4.13 1.4-.25 2.78-.65 4.12-1.15 4.07-1.5 7.94-3.78 11.28-6.54 2.33-1.92 5.13-4.49 5.88-7.58.63-3.53-2.45-6.68-7.97-8.96l.01.02ZM411.35 92.53v-.06l-.34.03c.11.01.22.03.34.03ZM314.26 64.06c-.23-.59-.47-1.17-.7-1.75.57 1.62 1.11 3.25 1.6 4.9l.15.54 2.35 6.05c.32.82.66 1.64.98 2.46-1.38-4.1-2.83-8.17-4.39-12.2h.01ZM156.82 103.07c-.18.13-.38.23-.58.33 1.32-.03 2.66-.2 3.93-.34.86-.09 1.72-.22 2.58-.33-2.12.1-4.12.17-5.94.34h.01ZM210.14 68.88s.03.04.05.07c.18-.31.39-.64.58-.96-.21.3-.42.6-.64.89h.01ZM201.65 82.8c-.5.77-1.02 1.56-1.49 2.37 1.11-1.55 2.21-3.1 3.2-4.59-.23.23-.49.51-.75.79-.32.47-.65.95-.96 1.43ZM194.03 98.66c-.33-.4-.65-.84-1.05-1.17-.24-.2-.07-.49.17-.56-.23-.26-.42-.5-.63-.75 1.51-2.55 3.93-5.87 6.4-9.28-.17-.08-.29-.28-.2-.49.04-.09.09-.17.13-.26-1.21 1.78-2.42 3.55-3.61 5.33-.87 1.31-1.74 2.64-2.54 4-.29.5-.63 1.04-.87 1.61.81.65 1.63 1.27 2.47 1.88-.09-.11-.18-.21-.27-.32v.01ZM307.79 82.93c-1-3.17-2.05-6.32-3.1-9.48-1.62 4.08-3.69 9.17-6.16 15.19 3.32-1.04 6.77-1.87 10.27-2.5-.32-1.08-.67-2.15-1.01-3.21ZM149.5 80.7c.05-1.71.04-3.43 0-5.14-.1 2.26-.16 4.51-.22 6.77-.02.73-.03 1.46-.04 2.19.14-1.27.2-2.55.24-3.82h.02ZM228.98 98.3c.39 1.25.91 3.03.94 3.91.06-.03.12-.07.17-.1.08-1.29-.55-2.65-1.11-3.81ZM307.72 53.36c.81.5 1.53 1.04 2.07 1.49-.38-.8-.78-1.58-1.21-2.35-.17.03-.34.06-.51.11-.43.12-.86.26-1.29.41.35-.01.53.1.94.34ZM283.69 96.14c3.91-7.25 6.89-13.35 8.88-18.15l1.1-2.66c-1.27 2.64-2.56 5.27-3.83 7.9-1.53 3.15-3.06 6.31-4.58 9.47-.87 1.81-1.76 3.62-2.54 5.47.04.02.07.04.11.07.05.05.1.09.15.14.05-.73.27-1.48.71-2.24ZM289.92 103.23s-.04.01-.05.03c0-.02.04-.03.05-.04.05-.05.11-.1.16-.15l.21-.21c-.55 0-1.5-.27-2.55-.72.4.26.8.51 1.22.74.24.13.48.26.73.37.05.02.1.03.14.05a.27.27 0 0 1 .08-.07h.01ZM269.23 68.49c-.39-.19-.82-.48-1.33-.87-3.06-1.56-6.31-2.78-9.36-2.35-3.5.49-5.7 1.11-7.74 2.44 5.71-2.6 12.82-2.07 18.44.79l-.01-.01ZM177.87 53.69l1.06.03c-.96-.22-2-.25-2.89-.3-4.95-.26-9.99.33-14.86 1.19-2.44.43-4.88.95-7.28 1.59 9.09-1.76 15.69-2.77 23.97-2.51ZM219.85 55.51c-.18.12-.36.27-.56.45-.45.53-.86 1.11-1.26 1.66-1.91 2.61-3.71 5.31-5.57 7.95l-.12.18 8.05-10.11c-.18-.05-.36-.1-.55-.13h.01ZM510.71 54.1c.12-.15.29-.3.53-.45.69-.4 3.72-.63 5.87-.74-.36-.02-.73-.04-1.09-.05-1.84-.03-3.67.09-5.49.35.05.3.12.59.18.88v.01ZM510.76 86.02c1.37-3.07 2.49-6.27 3.57-9.46.55-1.64 1.12-3.3 1.6-4.97-1.59 4.01-3.67 9.14-6.2 15.3.24-.08.5-.14.74-.22.1-.22.19-.44.29-.65ZM566.95 75.76c.11-.02.23.03.31.11-.05-.13-.09-.26-.14-.39-.05.09-.11.18-.17.28ZM511.33 86.41c3.08-.89 6.24-1.62 9.46-2.14-1.51-3.98-2.98-7.96-4.39-11.87-.05.15-.09.31-.14.46-1.02 3.32-2.15 6.61-3.39 9.85-.48 1.25-.98 2.49-1.53 3.7h-.01ZM578.24 74.45c.11-.44.23-.87.35-1.31-.31.7-.64 1.39-.97 2.08.09.21.19.4.28.61.12-.46.23-.92.35-1.38h-.01ZM520.62 53.11c-.09 0-.18-.01-.28-.02.38.34.29 1.08.93 2.53l6.65 17.15c2.2 5.68 4.69 11.36 7.41 16.87l1.06 2.17c-2.95-7.05-5.92-14.08-8.87-21.13-1.58-3.79-3.16-7.59-4.7-11.4-.78-1.92-1.73-3.89-2.25-5.91-.03-.1 0-.19.04-.26h.01ZM578.78 77.87c1.45-5.77 3.07-10.43 3.58-13.36.05-.34.16-.88.31-1.55-.67 1.79-1.37 3.56-2.08 5.33-.12.43-.23.86-.35 1.29-.65 2.43-1.29 4.86-1.9 7.3.14.33.29.65.43 1l.01-.01ZM545.3 94.66c.02-.44.03-.83.05-1.12.02-1.01.05-2.02.11-3.02.03-6.66-.46-14.33-1.46-22.8-.13-.42-.27-1.24-.56-2.89 0-.02 0-.04-.01-.06.62 6.61.95 13.25 1.32 19.87.17 3.08.33 6.16.52 9.23.02.25.03.52.04.78l-.01.01ZM580.77 102.81c.13.2.27.38.37.49.27-.11.53-.22.8-.32-.43.09-.82.05-1.17-.16v-.01ZM530.48 104.07h.33c-.36-.13-.71-.32-1.04-.56.14.24.3.47.45.7.06-.08.14-.13.26-.13v-.01ZM542.63 58.82c.06.23.11.47.15.71.14-.33.36-.62.7-.86-.28.05-.57.11-.85.15ZM583.81 57.87c.15-.7.29-1.41.42-2.11-.14.45-.28.9-.42 1.34-.46 1.44-.89 2.89-1.31 4.34.44-1.19.88-2.37 1.31-3.57ZM523.62 91.48c-4.66 1.17-9.05 2.89-14.02 5.27 4.65-1.84 9.48-3.29 14.28-4.63-.09-.22-.17-.41-.26-.64ZM460.64 78.3c-.04-2.9-.11-5.81-.28-8.71-.1-1.68-.17-3.43-.5-5.09-.07.02-.14.03-.2.05.3 6.54.45 12.17.51 17.12.17-.07.34-.14.51-.2 0-1.06-.01-2.11-.03-3.17h-.01ZM470.63 63.24c-3.38-.26-6.81.32-10.1 1.1.41 2.01.47 4.14.57 6.18.18 3.55.25 7.11.27 10.67 3.31-1.38 6.5-3.12 9.3-5.35 1.96-1.56 3.86-3.41 5.02-5.66.73-1.41 1.19-3.22.26-4.65-1.09-1.7-3.46-2.14-5.32-2.29ZM460.29 63.68c1-.24 2.01-.46 3.04-.65-1.15.16-2.37.38-3.71.69v.13c.07-.02.15-.04.22-.05.11-.13.3-.18.45-.11v-.01ZM457.24 100.96c.43-.03.86-.07 1.29-.11.14-.49.27-.99.38-1.49-.44.7-1 1.23-1.67 1.6ZM482.88 104.98c-.18.23-.36.38-.55.47.14.09.27.19.4.28a70.76 70.76 0 0 0 4.37-4.63c.76-.89 1.52-1.81 2.19-2.77-.3-.27-.61-.53-.92-.79-.07 1.94-4.62 6.32-5.49 7.45v-.01Z",transform:"translate(-144.023 -51.76)"}),Fa("path",{d:"M474.36 63.31c-.4-.16-.84-.27-1.29-.37 1.56.42 3.08 1.22 3.76 2.74.62 1.4.32 2.95-.28 4.32.7-1.22.94-2.34.74-3.47-.24-1.33-1.19-2.54-2.93-3.21v-.01ZM477.34 89.18c-1.2-.81-2.4-1.62-3.6-2.42-.14.1-.26.19-.4.29 1.4.67 2.73 1.39 4 2.13ZM465.88 93.85c.37.25.74.5 1.1.75.46.32.92.65 1.38.97-1.57-1.2-2.01-1.61-2.49-1.72h.01ZM574.92 90.06c-2.28-5.21-4.93-11.13-5.67-12.26-.1-.15-1.57-3.01-1.63-3.08 0 0-.01.02-.02.02.4 1.37 1.09 2.69 1.65 3.99 2.14 4.95 4.36 9.86 6.67 14.73.6 1.26 1.21 2.52 1.83 3.78-.75-2.01-1.64-4.45-2.83-7.18ZM448.73 65.29c.1.2.22.38.34.57.22-.02.43-.06.65-.08v-.08c-.14-.05-.25 0-.99-.41ZM460.16 94.81c-.02.31-.06.59-.1.89-.03 1.71-.33 3.43-.79 5.07.15-.02.3-.03.45-.05.01-.04.02-.08.03-.11.09-.34.15-.69.2-1.03.17-1.07.25-2.16.33-3.24.05-.69.08-1.39.12-2.08-.27.1-.27.26-.24.57v-.02Z",transform:"translate(-144.023 -51.76)"}),Fa("path",{d:"m328.67 98.12-3.22-6.58c-1.29-2.63-2.53-5.29-3.72-7.97-.25-.85-.52-1.69-.79-2.53-.81-2.57-1.67-5.12-2.55-7.67-1.92-5.53-3.9-11.08-6.32-16.41-.72-1.58-1.46-3.44-2.63-4.79-.03-.17-.16-.29-.34-.36a.282.282 0 0 0-.23-.04c-.06-.01-.12 0-.18.01-.74.06-1.5.38-2.19.61-2.22.77-4.4 1.64-6.63 2.38-.03-.08-.06-.16-.09-.25-.15-.42-.82-.24-.67.19.03.09.07.19.1.28l-.18.06c-.36.11-.28.6 0 .68.18 1.18.63 2.36.98 3.49.03.09.06.17.08.26-.08.23-.17.46-.24.64-.37.98-.79 1.94-1.21 2.9-1.27 2.89-2.62 5.75-3.98 8.6-3.18 6.67-6.44 13.31-9.64 19.97-1.08 2.25-2.2 4.5-3.15 6.81-.13.32.24.5.5.37 1.34 1.33 2.84 2.5 4.4 3.57.65.44 1.31.87 2.01 1.24.4.22.86.48 1.33.5.24.01.35-.19.33-.37.11-.1.21-.21.28-.28.41-.41.81-.84 1.2-1.26.85-.92 1.69-1.87 2.5-2.84 6.31-2.34 12.6-4.31 18.71-5.84 2.14 5.3 3.43 8.43 3.97 9.58.55 1.05 1.15 1.88 1.82 2.52 1.32.56 6.96-.03 9.23-1.96.87-1.28 1.19-2.67.93-4.15-.09-.5-.22-.95-.4-1.33l-.01-.03Zm-20.09-45.61c.43.77.83 1.56 1.21 2.35-.54-.45-1.27-.99-2.07-1.49-.42-.24-.6-.35-.94-.34.43-.15.85-.29 1.29-.41.17-.05.34-.08.51-.11Zm-25.86 45.66c.78-1.85 1.67-3.66 2.54-5.47 1.51-3.16 3.05-6.31 4.58-9.47 1.28-2.63 2.56-5.26 3.83-7.9l-1.1 2.66c-1.99 4.79-4.97 10.9-8.88 18.15-.43.76-.66 1.51-.71 2.24-.05-.05-.1-.09-.15-.14a.259.259 0 0 0-.11-.07Zm6.24 4.71c-.42-.23-.82-.48-1.22-.74 1.05.45 2 .72 2.55.72l-.21.21c-.05.05-.11.1-.16.15-.01.01-.04.03-.05.04 0-.02.03-.02.05-.03a.27.27 0 0 0-.08.07c-.05-.02-.1-.03-.14-.05-.25-.1-.49-.24-.73-.37h-.01Zm15.73-29.43c1.05 3.15 2.1 6.31 3.1 9.48.34 1.06.69 2.13 1.01 3.21-3.5.63-6.95 1.46-10.27 2.5 2.48-6.03 4.54-11.11 6.16-15.19Zm4.79 12.57c-.23-.79-.49-1.58-.73-2.36-.79-2.54-1.63-5.08-2.46-7.61l-1.2-3.6c.02-.04.04-.09.05-.13 1.6 4.45 3.28 9 5.01 13.57l-.67.12v.01Zm5.83-18.27-.15-.54c-.49-1.64-1.03-3.28-1.6-4.9.23.58.47 1.17.7 1.75 1.56 4.03 3.01 8.1 4.39 12.2-.33-.82-.67-1.64-.98-2.46l-2.35-6.05h-.01ZM390.43 79.37c-.13-10.43-.22-17.5-.24-19.97-.24-1.6.21-2.88-.65-3.65-.14-.13-.32-.23-.52-.32h.03c.45 0 .45-.69 0-.7-1.75-.03-3.5-.04-5.25-.14-1.38-.08-2.76-.21-4.15-.31-.07 0-.12.01-.17.04-.21-.07-.47.03-.45.31l.03.45c-.11.14-.19.3-.22.5-.21 1.26-.32 13.67-.36 23.59-.32 5.79-.67 11.57-.97 17.36-.09 1.73-.29 3.54-.21 5.3-.39.02-.38.64.04.69v.12c.05.44.74.45.7 0v-.06c1.1.09 2.2.21 3.3.3 1.14.19 2.44.2 3.29.17 1.73-.05 2.92-.05 3.8-.37.45-.05.9-.11 1.35-.17.44-.06.25-.73-.19-.67h-.01c.24-.32.45-.72.62-1.25.66-1.84.41-6.36.34-11.33l-.13-9.9.02.01Zm-12.26 18.17c.09-1.91.2-3.81.31-5.71.06 5.38 0 6.14-.01 6.51-.05 1.65-.21 2.81.72 3.66-.39-.04-.78-.07-1.17-.1-.06-1.44.09-2.93.16-4.35l-.01-.01ZM588.97 53.85c-2.06-.25-3.17-.51-3.76-.6a.3.3 0 0 1 .04-.08c.22-.39-.39-.75-.6-.35-.56 1.02-.9 2.19-1.26 3.29-.61 1.88-1.17 3.78-1.72 5.68-.63 2.19-1.24 4.39-1.83 6.59-.81 2.03-1.67 4.05-2.61 6.03-1.7-3.64-3.11-6.04-4.03-7.57-2.26-3.74-2.85-5.48-3.57-6.08l.31-.09c.43-.12.25-.8-.19-.67-1.06.3-2.12.6-3.17.95-.93.32-1.85.69-2.76 1.07-.13.05-.19.16-.22.27-.04.02-.08.05-.11.07-.04-.06-.07-.12-.11-.18a.354.354 0 0 0-.48-.12c-.16.09-.22.32-.13.48l.33.54c0 .09.02.18.06.28.51 1.16.78 1.38.72 1.47-2.42 3.44-5.41 7.86-6.2 9.1-1.27 1.97-2.01 3.14-2.45 3.84l-.91-6.56-.43-4.1c-.19-1.85-.37-3.23-.53-4.13-.19-1.1-.3-2.15-.45-3.16-.2-1.36-.29-2.06-.47-2.42h.04c.45.02.45-.68 0-.7-3.43-.16-6.81.94-10.17 1.48-.24-.22-.73-.04-.58.32.24.59.33 1.25.43 1.87.17 1.06.29 2.13.4 3.2.32 3.09.53 6.2.74 9.3.44 6.75.77 13.51 1.17 20.26.11 1.95.13 3.96.46 5.89.05.3.37.31.55.14.74 1.71 2.87 1.27 6.13 1.27 1.34 0 2.39.04 2.99-.11.02.32.48.53.63.18 3.61-8.26 7.41-16.46 12.05-24.2.03-.05.04-.1.05-.15.3.73.64 1.45.94 2.16.97 2.26 1.97 4.52 2.98 6.76 2.26 5.03 4.54 10.07 7.09 14.96.47.9.94 1.79 1.47 2.65.2.32.4.67.66.96-.18.25 0 .68.34.54.91-.38 1.82-.75 2.76-1.07 1.04-.35 2.11-.65 3.17-.95.39-.11.28-.66-.07-.68.62-.4.95-.96.87-1.91-.3-3.34.72-7.47.86-8.52l2.14-11.43c1.75-10.74 3.13-17.51 3.23-20.86.02-.49.08-2.84.13-3.24.17-1.25.48-1-4.96-1.65l.03-.02Zm-46.19 5.67c-.04-.24-.09-.48-.15-.71l.85-.15c-.34.24-.56.53-.7.86Zm1.95 25.12c-.36-6.63-.7-13.26-1.32-19.87 0 .02 0 .04.01.06.29 1.65.44 2.47.56 2.89 1 8.46 1.5 16.14 1.46 22.8-.06.99-.1 2-.11 3.02-.01.29-.03.68-.05 1.12-.01-.26-.03-.53-.04-.78-.19-3.08-.35-6.16-.52-9.23l.01-.01Zm36.4 18.66c-.11-.11-.24-.29-.37-.49.35.21.74.26 1.17.16-.27.11-.53.22-.8.32v.01Zm-.89-33.72c.12-.43.23-.86.35-1.29.71-1.77 1.41-3.55 2.08-5.33-.15.68-.26 1.22-.31 1.55-.5 2.94-2.13 7.59-3.58 13.36-.15-.35-.29-.66-.43-1 .61-2.44 1.25-4.87 1.9-7.3l-.01.01Zm3.56-12.48c.14-.44.28-.89.42-1.34-.13.7-.27 1.41-.42 2.11-.43 1.19-.86 2.38-1.31 3.57.42-1.45.85-2.9 1.31-4.34Zm-5.22 16.05c-.11.44-.23.87-.35 1.31-.12.46-.23.92-.35 1.38-.1-.22-.19-.4-.28-.61.34-.69.66-1.38.97-2.08h.01Zm-11.64 2.62c.06-.1.12-.19.17-.28.05.13.09.26.14.39a.398.398 0 0 0-.31-.11Zm2.3 2.98c-.56-1.3-1.25-2.63-1.65-3.99 0 0 .01-.02.02-.02.06.08 1.52 2.93 1.63 3.08.73 1.13 3.38 7.04 5.67 12.26 1.2 2.73 2.08 5.17 2.83 7.18-.62-1.25-1.23-2.51-1.83-3.78-2.31-4.87-4.53-9.78-6.67-14.73ZM275.92 87.03c-1.06-2.18-1.13-3.45-2.44-2.93-1.52.57-2.94 1.3-4.5 2.1-1.4.72-2.68 1.44-3.92 2.12.01-.25-.24-.5-.51-.34-4.8 2.93-12.41 4.7-17.28 1.31-1.98-1.77-3.32-4.15-3.97-5.78-.29-.95-.49-1.94-.63-2.93-.14-3.34 1.58-6.53 3.9-9.12.8-.79 1.68-1.51 2.66-2.12 3.7-2.3 8.22-3.07 12.51-2.51 2.71.35 5.32 1.24 7.71 2.55.39.22.75-.39.35-.6-.18-.1-.37-.18-.55-.27.56.27 1.03.33 1.51.19l-.48.39c-.15.11-.23.3-.13.48.09.15.33.24.48.13 1.3-.97 2.46-2.09 3.45-3.37.37-.29.64-.6.65-.97v-.02c.08-.33-.03-.7-.21-1.08-.31-.87-.98-2.01-2.19-3.26-2.43-2.52-3.79-3.45-5.68-4.26-1.14-.49-3.12-1.06-4.42-1.23-3.28-.42-10.64-1.21-18.18 4.11-7.74 5.46-11.94 12.3-12.23 20.61-.08 2.06.04 3.98.34 5.71.74 4.18 2.57 8 5.44 11.34 4.26 4.99 9.76 7.52 16.34 7.52 4.85 0 9.69-1.77 14.89-4.62.23-.12.45-.23.68-.35 2.19-1.1 4.37-2.23 6.46-3.5.49-.3 1.03-.61 1.5-.98 1.47-.87 1.11-1.12.49-2.95-.39-1.14-.76-2.7-2.06-5.36l.02-.01Zm-17.38-21.76c3.05-.42 6.31.79 9.36 2.35.51.39.94.68 1.33.87-5.61-2.86-12.72-3.39-18.44-.79 2.05-1.33 4.24-1.95 7.74-2.44l.01.01ZM443.67 72.67c-.4-2.2-1.15-4.33-2.37-6.22-1.49-2.32-3.58-4.19-5.91-5.64-6.17-3.81-13.75-5.11-20.83-6.01-3.23-.41-6.47-.69-9.72-.92l-1.39-.12c-.85-.07-1.52-.1-2.05-.1-1.08-.06-2.17-.12-3.25-.17-.08 0-.14.02-.19.05-.1.05-.18.14-.16.3.27 2.55-.01 5.12-.92 7.52-.15.38.4.56.62.28 1.32.59 2.68 1.05 4.08 1.37 0 2.78-.14 7.58-.33 12.91 0 0 0 .02-.01.03-.61 3.66-.79 7.42-1 11.12-.23 4.01-.43 8.03-.44 12.05 0 .64 0 1.28.03 1.93.02.31 0 .68.15.96.06.11.14.16.24.17-.2.17-.21.54.11.59 3.83.67 7.78.71 11.68.25 2.3-.19 4.87-.65 7.65-1.56 1.85-.54 3.67-1.18 5.43-1.91 7.2-3.02 14.31-8.07 17.35-15.53.76-1.86 1.17-3.8 1.31-5.75.3-1.93.28-3.82-.09-5.58l.01-.02Zm-19.32-15.42c5.74 1.41 11.94 3.68 15.65 8.55.25.32.47.65.69.99-2.3-2.82-5.68-5.69-12.88-8.23-2.16-.76-4.35-1.43-6.64-2.02 1.06.21 2.13.45 3.18.71Zm-25.82-3.04c.13 0 .27.01.4.02-.14.1-.26.23-.37.38 0-.13-.02-.26-.03-.4Zm34.82 22.17c-.75 3.09-3.55 5.66-5.88 7.58-3.35 2.76-7.21 5.03-11.28 6.54-1.33.49-2.71.9-4.12 1.15.06-1.38.08-2.76.07-4.13-.02-3.78-.16-7.56-.41-11.33-.09-1.37-.18-2.74-.37-4.1 0-.06-.03-.11-.06-.15.09-3.25.12-6.16.03-8.12 6.86 1.05 10.56 2.17 14.06 3.62 5.52 2.28 8.59 5.44 7.97 8.96l-.01-.02Zm-22 16.15c-.12 0-.23-.02-.34-.03l.34-.03v.06Zm-.69-.7c0-3.13.26-8.84.47-14.51.06 1.2.11 2.41.15 3.6.15 3.6.25 7.23.09 10.83-.24.03-.48.05-.71.07v.01Zm-12.33-30.94c.37.63 2.01 1.01 3.23 1.25v.15c-1.31-.31-2.59-.73-3.83-1.29.12-.36.23-.72.33-1.09.08.48.18.84.27.98Zm13.7 31.65v-.18c3.41-.56 6.71-2.02 9.69-3.68 2.31-1.28 4.59-2.78 6.63-4.53-4.69 4.53-11.61 8.24-16.33 8.38l.01.01Zm24.07-.75c-2.05 1.93-4.37 3.56-6.83 4.95 2.7-1.78 5.52-4.03 8.42-6.87.82-.82 1.56-1.69 2.23-2.59-1.08 1.65-2.38 3.16-3.81 4.51h-.01ZM187.16 92.14c-.79-2.47-2.1-7.12-3.1-6.87-.19-.01-2.09.77-4.08 1.54-3.06 1.18-5.91 2.13-10.09 2.82-2.74.42-5.87 1.01-10.61 1.06.04-3.34.05-6.01.05-7.99 7.97-.65 12.33-2.11 16.37-3.55 1.11-.39 2.69-1.01 2.63-1.8-.08-.35-.55-1.39-1.17-2.61-.47-1.16-.98-2.31-1.61-3.38-.42-.71-1.04-1.69-1.86-2.06-.11-.08-.22-.13-.29-.12-.02 0-.04 0-.07.01-.19-.04-.39-.05-.6-.01-.17.03-.24.15-.25.28-.04.02-.09.04-.14.05-4.33 1.48-8.85 2.33-13.24 3.61a499.1 499.1 0 0 0-.31-8.19c4.51-.99 8.88-1.38 13.11-1.82 3.68-.38 6.28.12 7.47.34.59.11.9.16 1.16.18h.1c-.1.37.44.66.62.28.02-.04.03-.08.05-.13.15.2.53.22.62-.1.17-.58.19-1.21.21-1.81v-.36c.03-.15.05-.3.07-.45.52-2.47.33-5.09-.64-7.44-.11-.27-.44-.28-.6-.14-.08-.21-.15-.42-.24-.62-.19-.41-.79-.05-.6.35.03.07.05.15.09.22-.98-.42-2.15-.54-3.17-.63-2.17-.19-4.37-.14-6.54 0-5.7.35-11.4 1.3-16.91 2.79-2.08.56-4.13 1.22-6.14 2-4.54 1.05-3.79 1.51-2.17 6.07.18.51.46 1.68.54 1.94.82 2.47 1.08 2.13 3.1 2.13s0 .05 0 .08h.52c-.48 2.66-.51 5.45-.62 8.13-.15 3.48-.22 6.96-.28 10.45 0 .41-.01.82-.02 1.23-.16.29-.33.57-.51.85-.05.38-.09.77-.14 1.18-.42 3.52-.59 6.48-.52 8.8v.34c.02.47.05.76.06.87.16 1.57-.26 3.47 1.35 3.79 1.61.32 3.5.55 4.85.55.11 0 .22-.02.33-.02 1.79.24 3.67.05 5.45-.12 2.85-.28 5.69-.7 8.51-1.19 3.03-.53 6.05-1.14 9.04-1.86 2.4-.58 4.82-1.19 7.13-2.06.51-.19 1.73-.57 2.46-1.14 1.81-.68 2.18-1 1.57-2.67-.23-.62-.48-1.49-.91-2.78l-.03-.02Zm-11.12-38.71c.89.05 1.93.08 2.89.3-.33 0-.68-.02-1.06-.03-8.28-.26-14.88.75-23.97 2.51 2.41-.64 4.85-1.16 7.28-1.59 4.87-.86 9.91-1.45 14.86-1.19Zm-26.53 22.13c.03 1.71.04 3.43 0 5.14-.04 1.27-.11 2.55-.24 3.82 0-.73.02-1.46.04-2.19.05-2.26.12-4.51.22-6.77h-.02Zm6.73 27.85c.2-.1.4-.21.58-.33 1.82-.17 3.82-.24 5.94-.34-.86.11-1.72.24-2.58.33-1.27.14-2.61.31-3.93.34h-.01ZM534.48 85.44c-3.52-8.38-7.07-16.75-10.5-25.17-.63-1.54-1.25-3.09-1.86-4.65-.31-.8-.65-1.6-.87-2.43-.04-.17-.17-.24-.31-.25.1-.2 0-.51-.29-.53-1.59-.08-3.18-.22-4.78-.25-1.96-.03-3.91.13-5.84.42-.31.05-.31.38-.13.56-.03.06-.05.14-.04.22.23 1.54.63 3.06 1.16 4.53.13.35.27.7.41 1.06l-2.68 6.18c-.11.03-.2.09-.25.22-.67 1.9-1.52 3.73-2.34 5.56a536.85 536.85 0 0 1-3.9 8.45c-2.64 5.64-5.34 11.25-7.91 16.93-.44.97-.88 1.94-1.29 2.93-.2.48-.47 1-.55 1.52v.05c-.02.12.02.26.16.34 1.19.73 2.41 1.41 3.66 2.05 1.2.62 2.45 1.25 3.76 1.61.43.12.62-.55.19-.67-1.13-.31-2.2-.83-3.24-1.36 1.09.36 2.1.69 2.75.93 2.82 1.01 2.38 1.1 4.3-3.75 2.1-1.09 4.34-1.96 6.53-2.79 4.35-1.64 8.8-3.03 13.27-4.29.82 2.01 1.77 3.97 2.72 5.92.35.83.62 1.45.79 1.82.22.42.45.8.69 1.15.17.33.33.67.5 1 .42.8.84 1.63 1.4 2.35.23.29.6 0 .55-.31 1.53-.02 3.06-.07 4.58-.27.92-.12 1.82-.32 2.71-.54 1.39-.27 3.85-1.11 3.74-1.42-.67-1.96-1.55-3.87-2.34-5.78-1.57-3.78-3.16-7.56-4.75-11.33v-.01Zm-11.65-26.16c1.54 3.81 3.12 7.6 4.7 11.4 2.94 7.05 5.91 14.09 8.87 21.13l-1.06-2.17c-2.71-5.51-5.2-11.19-7.41-16.87l-6.65-17.15c-.65-1.45-.55-2.19-.93-2.53.09 0 .18.01.28.02a.29.29 0 0 0-.04.26c.52 2.02 1.47 3.98 2.25 5.91h-.01Zm-6.58 13.58c.05-.15.09-.31.14-.46 1.41 3.92 2.88 7.9 4.39 11.87-3.22.52-6.38 1.25-9.46 2.14.55-1.22 1.05-2.46 1.53-3.7 1.24-3.24 2.37-6.53 3.39-9.85h.01Zm-.23-20c.36 0 .73.03 1.09.05-2.15.1-5.18.33-5.87.74-.24.15-.41.3-.53.45-.06-.29-.13-.58-.18-.88 1.82-.26 3.65-.39 5.49-.35v-.01Zm-.09 18.72c-.49 1.67-1.05 3.33-1.6 4.97-1.07 3.19-2.19 6.38-3.57 9.46-.09.21-.19.43-.29.65-.25.07-.5.14-.74.22 2.53-6.16 4.61-11.29 6.2-15.3Zm-6.34 25.16c4.97-2.38 9.37-4.1 14.02-5.27l.26.64c-4.8 1.35-9.63 2.8-14.28 4.63Zm20.17 6.76c.33.23.68.42 1.04.56h-.33c-.12 0-.21.06-.26.13-.15-.23-.31-.45-.45-.7v.01ZM226.57 91.75c-3.55-4.74-6.68-9.11-9.31-12.99 9.2-15.25 10.05-17.81 10.35-18.38.17-.34 1.09-2.27.64-2.53-1.13-.65-1.03-.65-2.97-1.71-1.19-.65-3.04-1.61-4.53-2.12-1.71-.59-1.24-.36-3 2.77-.06.1-.11.2-.17.3-.75 1.02-1.48 2.05-2.2 3.09-1.88 2.71-3.73 5.45-5.69 8.1-3.68-4.91-6.88-8.76-9.51-11.43-.15-.15-.3-.29-.46-.42-1.27-1.28-7.24 3.53-7.93 5.58-.09.09-.19.16-.28.25-.27.26.03.64.33.58.19.65.5 1.29.94 1.91 3.85 5.06 7.19 9.76 9.94 14-1.23 2.61-3.06 5-4.67 7.38l-2.28 3.33c-.5.66-.93 1.23-1.29 1.69-.67.93-2.09 2.61-2.3 3.87-.51.85-1.16 1.84-1.29 2.83-.06.44.61.63.67.19.01-.08.04-.15.06-.22 1.36 1.08 2.76 2.11 4.19 3.11 1.3.91 2.62 1.85 4.04 2.56.21.1.4 0 .48-.17.24.07.48.14.72.2.44.1.62-.57.19-.67-2.02-.48-3.77-1.57-5.23-3.02-.47-.46-.9-.96-1.32-1.46 1.74 1.35 4.2 2.89 5.89 4.14 1.39 1.03 2.85-2.27 4.22-4.2 1.86-2.64 3.96-5.86 5.52-8.29l10.39 14.51c.67.81 1.14 1.21 1.57 1.36-.05.24.12.51.41.4 1.53-.58 3.05-1.19 4.54-1.87 1.52-.69 3.06-1.45 4.36-2.5a.28.28 0 0 0 .12-.23c1.66-1.1.81-1.74-1.41-4.91-1.13-1.58-1.71-2.36-3.7-5.01l-.03-.02Zm2.41 6.54c.56 1.15 1.19 2.52 1.11 3.81-.06.04-.12.07-.17.1-.03-.88-.55-2.66-.94-3.91Zm-16.51-32.73c1.86-2.65 3.65-5.35 5.57-7.95.4-.55.81-1.13 1.26-1.66.19-.18.38-.33.56-.45.18.03.36.08.55.13l-8.05 10.11.12-.18h-.01ZM192.7 95.48c.79-1.37 1.66-2.69 2.54-4 1.19-1.79 2.4-3.56 3.61-5.33-.04.09-.09.17-.13.26-.1.22.03.41.2.49-2.47 3.42-4.89 6.73-6.4 9.28.21.24.4.48.63.75-.24.07-.4.36-.17.56.4.33.72.77 1.05 1.17.09.11.18.21.27.32-.84-.61-1.66-1.24-2.47-1.88.24-.57.58-1.11.87-1.61v-.01Zm7.46-10.32c.47-.81.98-1.59 1.49-2.37.31-.48.64-.95.96-1.43.26-.29.52-.56.75-.79-.99 1.48-2.09 3.03-3.2 4.59Zm10.03-16.22s-.03-.05-.05-.07c.22-.29.43-.59.64-.89-.2.32-.4.65-.58.96h-.01ZM371.54 87.96c-.01-.08-.01-.16-.03-.23-.06-.38-.58-.29-.66.03-.3-.05-.6-.08-.81-.11-1.14-.15-2.29-.19-3.44-.2 1.04-.09 2.09-.18 3.14-.23.45-.02.45-.72 0-.7-6.57.35-13.14 1.23-19.65 2.11-1.53.21-3.05.42-4.57.68-.01 0-.02.01-.04.01-.04-3.33-.13-6.66-.24-9.99-.19-5.7-.4-11.41-.88-17.1-.13-1.51-.23-3.07-.49-4.58 0-.25 0-.48-.02-.68-.06-1.19-.04-2.61-.68-2.78-.16-.07-.72-.16-1.5-.24.22-.17.16-.62-.2-.63-1.19-.04-2.39.09-3.57.23-1.2.14-2.41.32-3.59.6-.16-.1-.41-.06-.5.12-.06.02-.13.03-.19.05-.35.1-.29.55-.03.66-.26.6-.19 2.27-.21 3-.02.66-.66 33.73-.9 40.3-.03.65.06 1.12.04 1.45-.16 3.05.87 4.96 6.34 3.93 1.09-.08 2.75-.77 5.36-1.43 4.13-1.04 5.78-1.52 6.2-1.65 6.43-1.69 6.78-1.97 11.72-2.43.55-.05 4.8-.38 6.03-.3.64.04 1.19.07 1.65.1.09 0 .16-.03.24-.05.1.27.56.33.66-.02.39-1.32.61-2.71.78-4.08.2-1.61.29-3.24.15-4.86.24.03.52-.23.38-.53-.09-.2-.27-.33-.49-.43v-.02Zm-.63.56c.07.57.11 1.14.11 1.71-.21-.99-.53-1.71-.95-1.87.22.03.44.06.65.11.06.01.12.04.19.05Zm-25.41 1.73c1.54-.36 3.1-.64 4.66-.89-1.61.37-3.18.77-4.66 1.2v-.31Zm-.86-7.37c-.07-1.37-.16-2.75-.25-4.12-.21-3.13-.45-6.27-.79-9.4.02-2.25.08-4.31.13-6.11.16 2.08.29 4.16.4 6.24.23 4.46.38 8.93.5 13.39h.01Zm-.94-4c.16 2.41.29 4.83.39 7.24.06 1.6.14 3.22.09 4.83-.15.05-.32.09-.47.14V78.88h-.01ZM483.72 92.83c-3.05-2.28-6.22-4.4-9.38-6.51 8.86-6.49 13.49-12.95 13.73-19.23.04-.76 0-1.5-.13-2.2-.67-3.82-3.5-6.68-8.39-8.48.13.04.27.08.4.13 3.92 1.39 7.74 4.23 8.5 8.56.34 1.95-.05 3.96-.98 5.69-.21.4.39.75.6.35 1.86-3.46 1.46-7.55-.97-10.63-3.53-4.47-9.76-5.88-15.16-6.16-2.32-.12-4.64-.04-6.95.19-6 .32-12.71 1.68-17.63 3.21-.37.11-.67.23-.92.35-.2-.17-.62.02-.57.37v.03c-.64.68-.18 1.64.48 3.21.38.91.67 1.89 1.15 2.58.32.76.68 1.51 1.13 2.19.14.21.38.19.53.07.19-.02.38-.05.57-.08v1.57c-.06.06-.1.13-.11.23-.27 4.18-.34 8.38-.48 12.57l-.3 9.03c-.24 3.91-.44 6.77-.46 7.26-.05.88-.11 1.95.07 2.81-.01.22-.02.43-.04.65 0 .11-.02.23-.03.35 0 .05-.03.27-.01.16-.05.4.5.59.64.28.05.04.12.08.2.08 1.75.13 3.5.28 5.25.3 1.69.02 3.38-.12 5.06-.32.08.23.36.39.55.15.06-.08.11-.17.16-.26.18-.09.24-.32.18-.48.05-.2.1-.4.13-.6.16-.86.25-1.74.33-2.62.11-1.17.17-2.34.23-3.51.15-.01.32-.03.52-.04.36-.03 1.73-.15 2.06-.15.39 0 .7-.02.95-.04 1.76 1.11 3.45 2.35 5.14 3.55 2.83 2.01 5.64 4.04 8.47 6.04 1.42 1 2.85 2 4.29 2.97.1.06.19.07.27.04.08 0 .17-.02.25-.1 1.61-1.56 3.15-3.18 4.6-4.88.75-.88 1.49-1.78 2.15-2.73.01.01.03.02.04.03.34.3.83-.2.49-.49-2.16-1.9-4.34-3.76-6.64-5.48l.03-.01Zm-6.38-3.65a55.72 55.72 0 0 0-4-2.13c.14-.1.26-.19.4-.29 1.2.81 2.4 1.61 3.6 2.42Zm-20.1 11.78c.67-.37 1.23-.91 1.67-1.6-.11.5-.24 1-.38 1.49-.43.04-.86.08-1.29.11Zm2.38-37.24c1.34-.31 2.56-.52 3.71-.69-1.03.19-2.04.41-3.04.65-.14-.07-.34-.02-.45.11-.07.02-.15.04-.22.05v-.13.01Zm.04.84c.07-.02.14-.03.2-.05.34 1.66.41 3.41.5 5.09.17 2.9.24 5.81.28 8.71l.03 3.17c-.17.07-.34.14-.51.2-.06-4.96-.21-10.58-.51-17.12h.01Zm16.04 5.62c-1.16 2.25-3.06 4.1-5.02 5.66-2.8 2.23-5.99 3.97-9.3 5.35-.01-3.56-.09-7.12-.27-10.67-.1-2.04-.16-4.16-.57-6.18 3.3-.78 6.72-1.36 10.1-1.1 1.85.14 4.23.59 5.32 2.29.92 1.43.46 3.24-.26 4.65Zm.85-.18c.6-1.37.9-2.92.28-4.32-.67-1.52-2.2-2.32-3.76-2.74.46.1.89.21 1.29.37 1.74.67 2.69 1.88 2.93 3.21.2 1.13-.05 2.25-.74 3.47V70Zm-27.47-4.14c-.12-.19-.23-.38-.34-.57.74.42.85.36.99.41v.08c-.22.03-.43.06-.65.08Zm11.21 30.46c-.08 1.08-.16 2.17-.33 3.24-.05.35-.11.69-.2 1.03 0 .04-.02.07-.03.11-.15.02-.3.04-.45.05.45-1.64.76-3.36.79-5.07.03-.29.08-.57.1-.89-.03-.31-.03-.47.24-.57-.04.69-.07 1.39-.12 2.08v.02Zm5.6-2.47c.48.11.92.52 2.49 1.72-.46-.32-.92-.65-1.38-.97-.37-.25-.73-.5-1.1-.75h-.01Zm21.23 7.24a70.76 70.76 0 0 1-4.37 4.63c-.14-.09-.27-.19-.4-.28.19-.09.37-.24.55-.47.87-1.14 5.43-5.51 5.49-7.45.31.26.62.53.92.79-.67.97-1.42 1.88-2.19 2.77v.01Z",fill:"currentColor",transform:"translate(-144.023 -51.76)"})]}),V6=({style:e,size:t="small",withText:o})=>K6("div",{className:`ExcalidrawLogo is-${t}`,style:e,children:[Fa(HJ,{}),o&&Fa(GJ,{})]});import{Fragment as j6,jsx as Ct,jsxs as Ey}from"react/jsx-runtime";var wy=({icon:e,shortcut:t,children:o})=>{let n=Te();return Ey(j6,{children:[Ct("div",{className:"welcome-screen-menu-item__icon",children:e}),Ct("div",{className:"welcome-screen-menu-item__text",children:o}),t&&n.formFactor!=="phone"&&Ct("div",{className:"welcome-screen-menu-item__shortcut",children:t})]})};wy.displayName="WelcomeScreenMenuItemContent";var Kd=({onSelect:e,children:t,icon:o,shortcut:n,className:r="",...a})=>Ct("button",{...a,type:"button",className:`welcome-screen-menu-item ${r}`,onClick:e,children:Ct(wy,{icon:o,shortcut:n,children:t})});Kd.displayName="WelcomeScreenMenuItem";var X6=({children:e,href:t,icon:o,shortcut:n,className:r="",...a})=>Ct("a",{...a,className:`welcome-screen-menu-item ${r}`,href:t,target:"_blank",rel:"noopener",children:Ct(wy,{icon:o,shortcut:n,children:e})});X6.displayName="WelcomeScreenMenuItemLink";var dn=({children:e})=>{let{WelcomeScreenCenterTunnel:t}=Ze();return Ct(t.In,{children:Ct("div",{className:"welcome-screen-center",children:e||Ey(j6,{children:[Ct(vy,{}),Ct(Iy,{children:f("welcomeScreen.defaults.center_heading")}),Ey(Ty,{children:[Ct(ky,{}),Ct(Cy,{})]})]})})})};dn.displayName="Center";var vy=({children:e})=>Ct("div",{className:"welcome-screen-center__logo excalifont welcome-screen-decor",children:e||Ct(V6,{withText:!0})});vy.displayName="Logo";var Iy=({children:e})=>Ct("div",{className:"welcome-screen-center__heading welcome-screen-decor excalifont",children:e});Iy.displayName="Heading";var Ty=({children:e})=>Ct("div",{className:"welcome-screen-menu",children:e});Ty.displayName="Menu";var Cy=()=>{let e=at();return Ct(Kd,{onSelect:()=>e.executeAction(oi),shortcut:"?",icon:ns,children:f("helpDialog.title")})};Cy.displayName="MenuItemHelp";var ky=()=>{let e=Ie(),t=at();return e.viewModeEnabled?null:Ct(Kd,{onSelect:()=>t.executeAction(_s),shortcut:Xe("loadScene"),icon:rs,children:f("buttons.load")})};ky.displayName="MenuItemLoadScene";var Z6=({onSelect:e})=>{let{t}=Ue();return Ct(Kd,{shortcut:null,onSelect:e,icon:Em,children:t("labels.liveCollaboration")})};Z6.displayName="MenuItemLiveCollaborationTrigger";dn.Logo=vy;dn.Heading=Iy;dn.Menu=Ty;dn.MenuItem=Kd;dn.MenuItemLink=X6;dn.MenuItemHelp=Cy;dn.MenuItemLoadScene=ky;dn.MenuItemLiveCollaborationTrigger=Z6;import{jsx as Hl,jsxs as Sy}from"react/jsx-runtime";var Yg=({children:e})=>{let{WelcomeScreenMenuHintTunnel:t}=Ze();return Hl(t.In,{children:Sy("div",{className:"excalifont welcome-screen-decor welcome-screen-decor-hint welcome-screen-decor-hint--menu",children:[DE,Hl("div",{className:"welcome-screen-decor-hint__label",children:e||f("welcomeScreen.defaults.menuHint")})]})})};Yg.displayName="MenuHint";var $g=({children:e})=>{let{WelcomeScreenToolbarHintTunnel:t}=Ze();return Hl(t.In,{children:Sy("div",{className:"excalifont welcome-screen-decor welcome-screen-decor-hint welcome-screen-decor-hint--toolbar",children:[Hl("div",{className:"welcome-screen-decor-hint__label",children:e||f("welcomeScreen.defaults.toolbarHint")}),NE]})})};$g.displayName="ToolbarHint";var Vg=({children:e})=>{let{WelcomeScreenHelpHintTunnel:t}=Ze();return Hl(t.In,{children:Sy("div",{className:"excalifont welcome-screen-decor welcome-screen-decor-hint welcome-screen-decor-hint--help",children:[Hl("div",{children:e||f("welcomeScreen.defaults.helpHint")}),RE]})})};Vg.displayName="HelpHint";import{Fragment as q6,jsx as Xd,jsxs as WJ}from"react/jsx-runtime";var Kg=e=>Xd(q6,{children:e.children||WJ(q6,{children:[Xd(dn,{}),Xd(Yg,{}),Xd($g,{}),Xd(Vg,{})]})});Kg.displayName="WelcomeScreen";Kg.Center=dn;Kg.Hints={MenuHint:Yg,ToolbarHint:$g,HelpHint:Vg};var UJ=Kg;var YJ=()=>{Array.prototype.at||Object.defineProperty(Array.prototype,"at",{value:function(e){if(e=Math.trunc(e)||0,e<0&&(e+=this.length),!(e<0||e>=this.length))return this[e]},writable:!0,enumerable:!1,configurable:!0}),Element.prototype.replaceChildren||(Element.prototype.replaceChildren=function(...e){this.innerHTML="",this.append(...e)})},J6=YJ;import{getSceneVersion as Xqe,hashElementsVersion as Zqe,hashString as jqe,getNonDeletedElements as qqe}from"@orangecatai/element";import{getTextFromElements as Qqe}from"@orangecatai/element";import{isInvisiblySmallElement as tJe}from"@orangecatai/element";import $J from"lodash.throttle";import{arrayToMap as VJ,isDevEnv as Q6,isTestEnv as eA}from"@orangecatai/common";import{orderByFractionalIndex as KJ,syncInvalidIndices as tA,validateFractionalIndices as XJ}from"@orangecatai/element";var ZJ=(e,t,o)=>!!(t&&(t.id===e.editingTextElement?.id||t.id===e.resizingElement?.id||t.id===e.newElement?.id||t.version>o.version||t.version===o.version&&t.versionNonce<=o.versionNonce)),jJ=$J((e,t,o)=>{if(Q6()||eA()||window?.DEBUG_FRACTIONAL_INDICES){let n=tA(e.map(r=>({...r})));XJ(n,{shouldThrow:eA()||Q6(),includeBoundTextValidation:!0,reconciliationContext:{localElements:t,remoteElements:o}})}},1e3*60,{leading:!0,trailing:!1}),qJ=(e,t,o)=>{let n=VJ(e),r=[],a=new Set;for(let s of t)if(!a.has(s.id)){let l=n.get(s.id),c=ZJ(o,l,s);l&&c?(r.push(l),a.add(l.id)):(r.push(s),a.add(s.id))}for(let s of e)a.has(s.id)||(r.push(s),a.add(s.id));let i=KJ(r);return jJ(i,e,t),tA(i),i};import{isLinearElement as dJe}from"@orangecatai/element";import{FONT_FAMILY as pJe,THEME as gM,MIME_TYPES as uJe,ROUNDNESS as Cp,DEFAULT_LASER_COLOR as gJe,UserIdleState as hJe,normalizeLink as fJe,sceneCoordsToViewportCoords as CT,viewportCoordsToSceneCoords as bJe,getFormFactor as xJe}from"@orangecatai/common";import{mutateElement as Sp,newElementWith as EJe,bumpVersion as Us}from"@orangecatai/element";import{CaptureUpdateAction as vJe}from"@orangecatai/element";import{jsx as My}from"react/jsx-runtime";var oA=({children:e,icon:t})=>{let{t:o}=Ue(),{TTDDialogTriggerTunnel:n}=Ze(),r=Ce();return My(n.In,{children:My(ye.Item,{onSelect:()=>{be("ai","dialog open","ttd"),r({openDialog:{name:"ttd",tab:"text-to-diagram"}})},icon:t??Kw,badge:My(ye.Item.Badge,{children:"AI"}),children:e??o("labels.textToDiagram")})})};oA.displayName="TTDDialogTrigger";function JJ(e){let t=e.get("X-Ratelimit-Limit"),o=e.get("X-Ratelimit-Remaining");return{rateLimit:t?parseInt(t,10):void 0,rateLimitRemaining:o?parseInt(o,10):void 0}}async function*Py(e){let t=new TextDecoder,o="";try{for(;;){let{done:n,value:r}=await e.read();if(n)break;o+=t.decode(r,{stream:!0});let a=o.split(`
|
|
312
|
+
`),g=h.reduce((x,E,y)=>{let w=oJ(E).trim();if(w.length){let v=this.getTopLayerFrameAtSceneCoords({x:r,y:u}),I=x6(w,s,l),C=I.width>p,P=C?Qq(w,s,p):w;I=C?x6(P,s,l):I;let S=r-I.width/2,D=u-I.height/2,_=r6({...i,x:S,y:D,text:P,originalText:w,lineHeight:l,autoResize:!C,frameId:v?v.id:null});x.push(_),u+=_.height+d}else h[y-1]?.trim()&&(u+=nJ(i.fontSize,l)+d);return x},[]);g.length!==0&&(this.scene.insertElements(g),this.store.scheduleCapture(),this.setState({selectedElementIds:ze(Object.fromEntries(g.map(x=>[x.id,!0])),this.state)}),!n&&g.length>1&&D6===!1&&this.editorInterface.formFactor!=="phone"&&(this.setToast({message:f("toast.pasteAsSingleElement",{shortcut:G("CtrlOrCmd+Shift+V")}),duration:5e3}),D6=!0))}handleTextWysiwyg(o,{isExistingElement:n=!1}){let r=this.scene.getElementsMapIncludingDeleted(),a=(i,s)=>{this.scene.replaceAllElements([...this.scene.getElementsIncludingDeleted().map(l=>l.id===o.id&&kn(l)?_a(l,{originalText:i,isDeleted:s??l.isDeleted,...Sq(l,u6(l,r),r,i)}):l)])};v3({id:o.id,canvas:this.canvas,getViewportCoords:(i,s)=>{let{x:l,y:c}=Ng({sceneX:i,sceneY:s},this.state);return[l-this.state.offsetLeft,c-this.state.offsetTop]},onChange:pt(i=>{a(i,!1),C6(o)&&zg(o,this.scene)}),onSubmit:pt(({viaKeyboard:i,nextOriginalText:s})=>{let l=!s.trim();if(a(s,l),!l&&i){let c=o.containerId?o.containerId:o.id;Io(()=>{this.setState(m=>({selectedElementIds:ze({...m.selectedElementIds,[c]:!0},m)}))})}l&&Eq(this.scene.getNonDeletedElements(),[o]),(!l||n)&&this.store.scheduleCapture(),Io(()=>{this.setState({newElement:null,editingTextElement:null})}),this.state.activeTool.locked&&Ao(this.interactiveCanvas,this.state),this.focusContainer()}),element:o,excalidrawContainer:this.excalidrawContainerRef.current,app:this,autoSelect:!this.editorInterface.isTouchScreen}),this.deselectElements(),a(o.originalText,!1)}deselectElements(){this.setState({selectedElementIds:ze({},this.state),selectedGroupIds:{},editingGroupId:null,activeEmbeddable:null})}getTextElementAtPosition(o,n){let r=this.getElementAtPosition(o,n,{includeBoundTextElement:!0});return r&&kn(r)&&!r.isDeleted?r:null}getElementAtPosition(o,n,r){let a=[];if(r&&"allHitElements"in r?a=r?.allHitElements||[]:a=this.getElementsAtPosition(o,n,{includeBoundTextElement:r?.includeBoundTextElement,includeLockedElements:r?.includeLockedElements}),a.length>1){if(r?.preferSelected){for(let s=a.length-1;s>-1;s--)if(this.state.selectedElementIds[a[s].id])return a[s]}let i=a[a.length-1];return Od({point:pe(o,n),element:i,threshold:this.getElementHitThreshold(i)/2,elementsMap:this.scene.getNonDeletedElementsMap(),frameNameBound:Qt(i)?this.frameNameBoundsCache.get(i):null})?i:a[a.length-2]}return a.length===1?a[0]:null}getElementsAtPosition(o,n,r){let a=[],i=this.scene.getNonDeletedElementsMap();return(r?.includeBoundTextElement&&r?.includeLockedElements?this.scene.getNonDeletedElements():this.scene.getNonDeletedElements().filter(l=>(r?.includeLockedElements||!l.locked)&&(r?.includeBoundTextElement||!(kn(l)&&l.containerId)))).filter(l=>this.hitElement(o,n,l)).filter(l=>{let c=oy(l,i);return c&&this.state.frameRendering.enabled&&this.state.frameRendering.clip?g6({x:o,y:n},c,i):!0}).filter(l=>zl(l)?(a.push(l),!1):!0).concat(a)}getElementHitThreshold(o){return Math.max(o.strokeWidth/2+.1,.85*(KP/this.state.zoom.value))}hitElement(o,n,r,a=!0){return a&&this.state.selectedElementIds[r.id]&&zq([r],this.state,this.editorInterface)&&EJ(pe(o,n),r,this.scene.getNonDeletedElementsMap(),this.getElementHitThreshold(r))||Kq(pe(o,n),r,this.scene.getNonDeletedElementsMap())?!0:Od({point:pe(o,n),element:r,threshold:this.getElementHitThreshold(r),elementsMap:this.scene.getNonDeletedElementsMap(),frameNameBound:Qt(r)?this.frameNameBoundsCache.get(r):null})}getTextBindableContainerAtPosition(o,n){let r=this.scene.getNonDeletedElements(),a=this.scene.getSelectedElements(this.state);if(a.length===1)return s6(a[0],!1)?a[0]:null;let i=null;for(let s=r.length-1;s>=0;--s){if(r[s].isDeleted)continue;let[l,c,m,p]=Og(r[s],this.scene.getNonDeletedElementsMap());if(Ol(r[s])&&Od({point:pe(o,n),element:r[s],elementsMap:this.scene.getNonDeletedElementsMap(),threshold:this.getElementHitThreshold(r[s])})){i=r[s];break}else if(l<o&&o<m&&c<n&&n<p){i=r[s];break}}return s6(i,!1)?i:null}handleHoverSelectedLinearElement(o,n,r){let a=this.scene.getNonDeletedElementsMap(),i=_e.getElement(o.elementId,a);if(i)if(this.state.selectedLinearElement){let s=-1,l=null;Od({point:pe(n,r),element:i,elementsMap:a,threshold:this.getElementHitThreshold(i)})?(s=_e.getPointIndexUnderCursor(i,a,this.state.zoom,n,r),l=_e.getSegmentMidpointHitCoords(o,{x:n,y:r},this.state,this.scene.getNonDeletedElementsMap()),(To(i)?s===0||s===i.points.length-1:s>=0)||l?Be(this.interactiveCanvas,lt.POINTER):this.hitElement(n,r,i)&&(!To(i)||!(i.startBinding||i.endBinding))&&(this.state.activeTool.type!=="lasso"||Object.keys(this.state.selectedElementIds).length>0)&&Be(this.interactiveCanvas,lt.MOVE)):this.hitElement(n,r,i)&&(!To(i)||!(i.startBinding||i.endBinding))&&(this.state.activeTool.type!=="lasso"||Object.keys(this.state.selectedElementIds).length>0)&&Be(this.interactiveCanvas,lt.MOVE),this.state.selectedLinearElement.hoverPointIndex!==s&&this.setState({selectedLinearElement:{...this.state.selectedLinearElement,hoverPointIndex:s}}),_e.arePointsEqual(this.state.selectedLinearElement.segmentMidPointHoveredCoords,l)||this.setState({selectedLinearElement:{...this.state.selectedLinearElement,segmentMidPointHoveredCoords:l}});let c=null,m=i;(m.startBinding||m.endBinding)&&(c=CJ(i,n,r,this.scene,this.state)),this.state.selectedLinearElement.hoveredFocusPointBinding!==c&&this.setState({selectedLinearElement:{...this.state.selectedLinearElement,isDragging:!1,hoveredFocusPointBinding:c}}),c&&Be(this.interactiveCanvas,lt.POINTER)}else Be(this.interactiveCanvas,lt.AUTO)}updateGestureOnPointerDown(o){Ne.pointers.set(o.pointerId,{x:o.clientX,y:o.clientY}),Ne.pointers.size===2&&(Ne.lastCenter=M0(Ne.pointers),Ne.initialScale=this.state.zoom.value,Ne.initialDistance=P0(Array.from(Ne.pointers.values())))}initialPointerDownState(o){let n=rt(o,this.state),r=this.scene.getSelectedElements(this.state),[a,i,s,l]=Fl(r),c=r.findIndex(To)===0;return{origin:n,withCmdOrCtrl:o[re.CTRL_OR_CMD],originInGrid:H1(Jt(n.x,n.y,o[re.CTRL_OR_CMD]||c?null:this.getEffectiveGridSize())),scrollbars:ix(Wd,o.clientX-this.state.offsetLeft,o.clientY-this.state.offsetTop),lastCoords:{...n},originalElements:this.scene.getNonDeletedElements().reduce((m,p)=>(m.set(p.id,a6(p)),m),new Map),resize:{handleType:!1,isResizing:!1,offset:{x:0,y:0},arrowDirection:"origin",center:{x:(s+a)/2,y:(l+i)/2}},hit:{element:null,allHitElements:[],wasAddedToSelection:!1,hasBeenDuplicated:!1,hasHitCommonBoundingBoxOfSelectedElements:this.isHittingCommonBoundingBoxOfSelectedElements(n,r)},drag:{hasOccurred:!1,offset:null,origin:{...n},blockDragging:!1},eventListeners:{onMove:null,onUp:null,onKeyUp:null,onKeyDown:null},boxSelection:{hasOccurred:!1}}}handleDraggingScrollBar(o,n){if(!(n.scrollbars.isOverEither&&!this.state.multiElement))return!1;cy=!0,n.lastCoords.x=o.clientX,n.lastCoords.y=o.clientY;let r=Fu(i=>{i.target instanceof HTMLElement&&this.handlePointerMoveOverScrollbars(i,n)}),a=pt(()=>{$d=null,cy=!1,Ao(this.interactiveCanvas,this.state),this.setState({cursorButton:"up"}),this.savePointer(o.clientX,o.clientY,"up"),window.removeEventListener(fe.POINTER_MOVE,r),window.removeEventListener(fe.POINTER_UP,a),r.flush()});return $d=a,window.addEventListener(fe.POINTER_MOVE,r),window.addEventListener(fe.POINTER_UP,a),!0}isASelectedElement(o){return o!=null&&this.state.selectedElementIds[o.id]}isHittingCommonBoundingBoxOfSelectedElements(o,n){if(n.length<2)return!1;let r=Math.max(KP/this.state.zoom.value,1),[a,i,s,l]=Fl(n);return o.x>a-r&&o.x<s+r&&o.y>i-r&&o.y<l+r}getCurrentItemRoundness(o){return this.state.currentItemRoundness==="round"?{type:Aq(o)?_g.ADAPTIVE_RADIUS:_g.PROPORTIONAL_RADIUS}:null}maybeCacheReferenceSnapPoints(o,n,r=!1){kr({event:o,app:this,selectedElements:n})&&(r||!jo.getReferenceSnapPoints())&&jo.setReferenceSnapPoints(uk(this.scene.getNonDeletedElements(),n,this.state,this.scene.getNonDeletedElementsMap()))}maybeCacheVisibleGaps(o,n,r=!1){kr({event:o,app:this,selectedElements:n})&&(r||!jo.getVisibleGaps())&&jo.setVisibleGaps(pk(this.scene.getNonDeletedElements(),n,this.state,this.scene.getNonDeletedElementsMap()))}onKeyDownFromPointerDownHandler(o){return pt(n=>{this.maybeHandleResize(o,n)||this.maybeDragNewGenericElement(o,n)})}onKeyUpFromPointerDownHandler(o){return pt(n=>{n.key===re.ALT&&n.preventDefault(),!this.maybeHandleResize(o,n)&&this.maybeDragNewGenericElement(o,n)})}onPointerMoveFromPointerDownHandler(o){return Fu(n=>{if(this.state.openDialog?.name==="elementLinkSelector")return;let r=rt(n,this.state);if(this.state.activeLockedId&&this.setState({activeLockedId:null}),this.state.selectedLinearElement&&this.state.selectedLinearElement.elbowed&&this.state.selectedLinearElement.initialState.segmentMidpoint.index){let[d,u]=Jt(r.x,r.y,n[re.CTRL_OR_CMD]?null:this.getEffectiveGridSize()),h=this.state.selectedLinearElement.initialState.segmentMidpoint.index;if(h<0){let x=_e.getSegmentMidpointHitCoords({...this.state.selectedLinearElement,segmentMidPointHoveredCoords:null},{x:d,y:u},this.state,this.scene.getNonDeletedElementsMap());h=x?_e.getSegmentMidPointIndex(this.state.selectedLinearElement,this.state,x,this.scene.getNonDeletedElementsMap()):-1}let g=_e.moveFixedSegment(this.state.selectedLinearElement,h,d,u,this.scene);this.setState({selectedLinearElement:{...this.state.selectedLinearElement,isDragging:!0,segmentMidPointHoveredCoords:g.segmentMidPointHoveredCoords,initialState:g.initialState}});return}let a=this.previousPointerMoveCoords??o.origin;if(this.previousPointerMoveCoords=r,o.drag.offset===null&&(o.drag.offset=H1(xJ(this.scene.getSelectedElements(this.state),o.origin.x,o.origin.y))),!(n.target instanceof HTMLElement)||this.handlePointerMoveOverScrollbars(n,o))return;if(ho(this.state)){this.handleEraser(n,r);return}this.state.activeTool.type==="laser"&&this.laserTrails.addPointToPath(r.x,r.y);let[s,l]=Jt(r.x,r.y,n[re.CTRL_OR_CMD]?null:this.getEffectiveGridSize());if(o.resize.isResizing&&(o.lastCoords.x=r.x,o.lastCoords.y=r.y,this.maybeHandleCrop(o,n)||this.maybeHandleResize(o,n)))return!0;let c=this.scene.getNonDeletedElementsMap();if(this.state.selectedLinearElement){let d=this.state.selectedLinearElement;if(d.draggedFocusPointBinding){TJ(d,c,r,this.scene,this.state,this.getEffectiveGridSize(),n.altKey),this.setState({selectedLinearElement:{...d,isDragging:!1,selectedPointsIndices:[],initialState:{...d.initialState,lastClickedPoint:-1}}});return}if(_e.shouldAddMidpoint(this.state.selectedLinearElement,r,this.state,c)){let u=_e.addMidpoint(this.state.selectedLinearElement,r,this,!n[re.CTRL_OR_CMD],this.scene);if(!u)return;Io(()=>{this.state.selectedLinearElement&&this.setState({selectedLinearElement:{...this.state.selectedLinearElement,initialState:u.pointerDownState,selectedPointsIndices:u.selectedPointsIndices,segmentMidPointHoveredCoords:null}})});return}else{if(d.initialState.segmentMidpoint.value!==null&&!d.initialState.segmentMidpoint.added)return;if(d.initialState.lastClickedPoint>-1){let u=_e.getElement(d.elementId,c);if(u?.isDeleted)return;if(lr(u)){let g=Cn(pe(r.x,r.y),this.scene.getNonDeletedElements(),c);Rr("COMPLEX_BINDINGS")&&this.handleDelayedBindModeChange(u,g)}if(n.altKey&&!this.state.selectedLinearElement?.initialState?.arrowStartIsInside&&Rr("COMPLEX_BINDINGS")&&this.handleSkipBindMode(),d.initialState.lastClickedPoint===-1)return;let h=_e.handlePointDragging(n,this,r.x,r.y,d);if(h){o.lastCoords.x=r.x,o.lastCoords.y=r.y,o.drag.hasOccurred=!0,(h.suggestedBinding!==this.state.suggestedBinding||!JP(h.selectedLinearElement?.selectedPointsIndices??[],this.state.selectedLinearElement?.selectedPointsIndices??[])||h.selectedLinearElement?.hoverPointIndex!==this.state.selectedLinearElement?.hoverPointIndex||h.selectedLinearElement?.customLineAngle!==this.state.selectedLinearElement?.customLineAngle||this.state.selectedLinearElement.isDragging!==h.selectedLinearElement?.isDragging||this.state.selectedLinearElement?.initialState?.altFocusPoint!==h.selectedLinearElement?.initialState?.altFocusPoint)&&this.setState(h);return}}}}let m=o.hit.allHitElements.some(d=>this.isASelectedElement(d)),p=this.state.selectedLinearElement?.isEditing&&n.shiftKey&&this.state.selectedLinearElement.elementId===o.hit.element?.id;if((m||o.hit.hasHitCommonBoundingBoxOfSelectedElements)&&!p&&!o.drag.blockDragging){let d=this.scene.getSelectedElements(this.state);if(d.length>0&&d.every(x=>x.locked))return;let u=d.find(x=>Qt(x)),h=this.getTopLayerFrameAtSceneCoords(r),g=h&&!u?h:null;if(this.state.frameToHighlight!==g&&Io(()=>{this.setState({frameToHighlight:g})}),o.drag.hasOccurred=!0,this.state.activeTool.type==="lasso"&&this.lassoTrail.hasCurrentTrail&&!(this.editorInterface.formFactor!=="desktop"&&o.hit.element)&&!this.state.activeTool.fromSelection)return;if(this.state.activeTool.type==="lasso"&&d.length>0&&o.drag.hasOccurred&&!this.state.activeTool.fromSelection&&this.lassoTrail.endPath(),d.length>0&&!o.withCmdOrCtrl&&!this.state.editingTextElement&&this.state.activeEmbeddable?.state!=="active"){let x={x:r.x-o.drag.origin.x,y:r.y-o.drag.origin.y},E=[...o.originalElements.values()],y=n.shiftKey;if(y){let I=Math.abs(x.x),C=Math.abs(x.y),P=y&&I<C,S=y&&I>C;P&&(x.x=0),S&&(x.y=0)}if(this.state.croppingElementId){let I=this.scene.getNonDeletedElementsMap().get(this.state.croppingElementId);if(I&&Da(I)&&I.crop!==null&&o.hit.element===I){let C=I.crop,P=Fd(I)&&this.imageCache.get(I.fileId)?.image;if(P&&!(P instanceof Promise)){let S=MJ(I),D=BP(r.x-a.x,r.y-a.y);D[0]*=P.naturalWidth/S.width,D[1]*=P.naturalHeight/S.height;let[_,k,M,B,O,N]=Og(I,c),z=B1(N1(pe(_,k),pe(O,N),I.angle)),L=B1(N1(pe(M,k),pe(O,N),I.angle)),F=B1(N1(pe(_,B),pe(O,N),I.angle)),$=zP(FP(L,z)),Q=zP(FP(F,z)),Z=BP(OP(D,$),OP(D,Q)),U={...C,x:NP(C.x-Z[0]*Math.sign(I.scale[0]),0,P.naturalWidth-C.width),y:NP(C.y-Z[1]*Math.sign(I.scale[1]),0,P.naturalHeight-C.height)};this.scene.mutateElement(I,{crop:U});return}}}this.maybeCacheVisibleGaps(n,d),this.maybeCacheReferenceSnapPoints(n,d);let{snapOffset:w,snapLines:v}=gk(E,x,this,n,this.scene.getNonDeletedElementsMap());if(this.setState({snapLines:v}),this.state.editingFrame||bJ(o,d,x,this.scene,w,n[re.CTRL_OR_CMD]?null:this.getEffectiveGridSize()),this.setState({selectedElementsAreBeingDragged:!0,selectionElement:null}),n.altKey&&!o.hit.hasBeenDuplicated){o.hit.hasBeenDuplicated=!0;let I=this.scene.getElementsIncludingDeleted(),C=o.hit.element,P=this.scene.getSelectedElements({selectedElementIds:this.state.selectedElementIds,includeBoundTextElement:!0,includeElementsInFrames:!0});C&&o.hit.wasAddedToSelection&&!P.find(z=>z.id===C.id)&&P.push(C);let S=new Map(P.map(z=>[z.id,z])),{duplicatedElements:D,duplicateElementsMap:_,elementsWithDuplicates:k,origIdToDuplicateId:M}=Y1({type:"in-place",elements:I,appState:this.state,randomizeSeed:!0,idsOfElementsToDuplicate:S,overrides:({duplicateElement:z,origElement:L})=>({frameId:z.frameId??L.frameId,seed:cq()})});D.forEach(z=>{o.originalElements.set(z.id,a6(z))});let B=k.map(z=>{if(S.has(z.id)){let L=o.originalElements.get(z.id);if(L)return _a(z,{x:L.x,y:L.y})}return z}),O=this.props.onDuplicate?.(B,I),N=E6(O||B,Bg(D));Io(()=>{if(o.hit.element){let z=M.get(o.hit.element.id),L=z&&_.get(z);o.hit.element=L||null}o.hit.allHitElements=o.hit.allHitElements.reduce((z,L)=>{let F=M.get(L.id),$=F&&_.get(F);return $&&z.push($),z},[]),o.drag.origin=rt(n,this.state),this.setState(z=>({...uJ(D,this.scene.getNonDeletedElements(),z)})),this.scene.replaceAllElements(N),P.forEach(z=>{X1(z)&&z.boundElements?.some(L=>L.type==="arrow")&&zg(z,this.scene)}),this.maybeCacheVisibleGaps(n,P,!0),this.maybeCacheReferenceSnapPoints(n,P,!0)})}return}}if(this.state.selectionElement){if(o.lastCoords.x=r.x,o.lastCoords.y=r.y,n.altKey){this.setActiveTool({type:"lasso",fromSelection:!0},n.shiftKey),this.lassoTrail.startPath(o.origin.x,o.origin.y,n.shiftKey),this.setAppState({selectionElement:null});return}this.maybeDragNewGenericElement(o,n)}else if(this.state.activeTool.type==="lasso")!n.altKey&&this.state.activeTool.fromSelection?(this.setActiveTool({type:"selection"}),this.createGenericElementOnPointerDown("selection",o),o.lastCoords.x=r.x,o.lastCoords.y=r.y,this.maybeDragNewGenericElement(o,n),this.lassoTrail.endPath()):this.lassoTrail.addPointToPath(r.x,r.y,n.shiftKey);else{let d=this.state.newElement;if(!d)return;if(d.type==="freedraw"){let u=d.points,h=r.x-d.x,g=r.y-d.y,x=u.length>0&&u[u.length-1];if(!(x&&x[0]===h&&x[1]===g)){let y=d.simulatePressure?d.pressures:[...d.pressures,n.pressure];this.scene.mutateElement(d,{points:[...u,pe(h,g)],pressures:y},{informMutation:!1,isDragging:!1}),this.setState({newElement:d})}}else if(mo(d)&&!d.isDeleted){o.drag.hasOccurred=!0;let u=d.points;sr(u.length>1,"Do not create linear elements with less than 2 points");let h=this.state.selectedLinearElement;h||(h=new _e(d,this.scene.getNonDeletedElementsMap()),h={...h,selectedPointsIndices:[1],initialState:{...h.initialState,lastClickedPoint:1}}),this.setState({newElement:d,..._e.handlePointDragging(n,this,s,l,h)})}else o.lastCoords.x=r.x,o.lastCoords.y=r.y,this.maybeDragNewGenericElement(o,n,!1)}if(this.state.activeTool.type==="selection"){o.boxSelection.hasOccurred=!0;let d=this.scene.getNonDeletedElements();if(this.state.selectedLinearElement?.isEditing)_e.handleBoxSelection(n,this.state,this.setState.bind(this),this.scene.getNonDeletedElementsMap());else{let u=!0;!n.shiftKey&&Ge(d,this.state)&&(o.withCmdOrCtrl&&o.hit.element?this.setState(g=>cn({...g,selectedElementIds:{[o.hit.element.id]:!0}},this.scene.getNonDeletedElements(),g,this)):u=!1);let h=this.state.selectionElement?rE(d,this.state.selectionElement,this.scene.getNonDeletedElementsMap(),!1):[];this.setState(g=>{let x={...u&&g.selectedElementIds,...h.reduce((E,y)=>(E[y.id]=!0,E),{})};return o.hit.element&&(h.length?delete x[o.hit.element.id]:x[o.hit.element.id]=!0),g=u?g:{...g,selectedGroupIds:{},editingGroupId:null},{...cn({editingGroupId:g.editingGroupId,selectedElementIds:x},this.scene.getNonDeletedElements(),g,this),selectedLinearElement:h.length===1&&mo(h[0])?new _e(h[0],this.scene.getNonDeletedElementsMap()):null,showHyperlinkPopup:h.length===1&&(h[0].link||Nr(h[0]))?"info":!1}})}}})}handlePointerMoveOverScrollbars(o,n){if(n.scrollbars.isOverHorizontal){let r=o.clientX,a=r-n.lastCoords.x;return this.translateCanvas({scrollX:this.state.scrollX-a*(Wd.horizontal?.deltaMultiplier||1)/this.state.zoom.value}),n.lastCoords.x=r,!0}if(n.scrollbars.isOverVertical){let r=o.clientY,a=r-n.lastCoords.y;return this.translateCanvas({scrollY:this.state.scrollY-a*(Wd.vertical?.deltaMultiplier||1)/this.state.zoom.value}),n.lastCoords.y=r,!0}return!1}onPointerUpFromPointerDownHandler(o){return pt(n=>{let r=this.scene.getNonDeletedElementsMap();this.removePointer(n),o.drag.blockDragging=!1,o.eventListeners.onMove&&o.eventListeners.onMove.flush();let{newElement:a,resizingElement:i,croppingElementId:s,multiElement:l,activeTool:c,isResizing:m,isRotating:p,isCropping:d}=this.state;this.setState(y=>({isResizing:!1,isRotating:!1,isCropping:!1,resizingElement:null,selectionElement:null,frameToHighlight:null,elementsToHighlight:null,cursorButton:"up",snapLines:Nd(y.snapLines,[]),originSnapOffset:null})),this.lassoTrail.endPath(),this.previousPointerMoveCoords=null,jo.setReferenceSnapPoints(null),jo.setVisibleGaps(null),this.savePointer(n.clientX,n.clientY,"up");let u=o.hit.allHitElements,h=rt({clientX:n.clientX,clientY:n.clientY},this.state);if(this.state.activeTool.type==="selection"&&!o.boxSelection.hasOccurred&&!o.resize.isResizing&&!u.some(y=>this.state.selectedElementIds[y.id])){let y=this.getElementAtPosition(h.x,h.y,{includeLockedElements:!0});this.store.scheduleCapture(),y?.locked?this.setState({activeLockedId:y.groupIds.length>0?y.groupIds.at(-1)||"":y.id}):this.setState({activeLockedId:null})}else this.setState({activeLockedId:null});if(Rr("COMPLEX_BINDINGS")&&this.resetDelayedBindMode(),this.setState({selectedElementsAreBeingDragged:!1,bindMode:"orbit"}),o.drag.hasOccurred&&o.hit?.element?.id){let y=r.get(o.hit.element.id);X1(y)&&y.boundElements?.filter(w=>w.type==="arrow").map(w=>r.get(w.id)).filter(w=>To(w)).forEach(w=>{w&&this.scene.mutateElement(w,{})})}if(this.state.selectedLinearElement?.isEditing&&!this.state.newElement&&this.state.selectedLinearElement.draggedFocusPointBinding===null)if(!o.boxSelection.hasOccurred&&o.hit?.element?.id!==this.state.selectedLinearElement.elementId&&this.state.selectedLinearElement.draggedFocusPointBinding===null)this.actionManager.executeAction(ro);else{let y=_e.handlePointerUp(n,this.state.selectedLinearElement,this.state,this.scene);this.actionManager.executeAction(ro,"ui",{event:n,sceneCoords:h}),y!==this.state.selectedLinearElement&&this.setState({selectedLinearElement:y,suggestedBinding:null})}else if(this.state.selectedLinearElement){if(this.state.selectedLinearElement.elbowed){let y=_e.getElement(this.state.selectedLinearElement.elementId,this.scene.getNonDeletedElementsMap());y&&this.scene.mutateElement(y,{})}if(this.state.selectedLinearElement.draggedFocusPointBinding?(SJ(this.state.selectedLinearElement,this.scene),this.setState({selectedLinearElement:{...this.state.selectedLinearElement,draggedFocusPointBinding:null}})):o.hit?.element?.id!==this.state.selectedLinearElement.elementId?this.scene.getSelectedElements(this.state).length>1&&this.setState({selectedLinearElement:null}):this.state.selectedLinearElement.isDragging&&(this.setState({selectedLinearElement:{...this.state.selectedLinearElement,isDragging:!1}}),this.actionManager.executeAction(ro,"ui",{event:n,sceneCoords:h})),this.state.newElement&&this.state.multiElement&&mo(this.state.newElement)&&this.state.selectedLinearElement){let{multiElement:y}=this.state;this.setState({selectedLinearElement:{...this.state.selectedLinearElement,lastCommittedPoint:y.points[y.points.length-1]}})}}if(this.missingPointerEventCleanupEmitter.clear(),window.removeEventListener(fe.POINTER_MOVE,o.eventListeners.onMove),window.removeEventListener(fe.POINTER_UP,o.eventListeners.onUp),window.removeEventListener(fe.KEYDOWN,o.eventListeners.onKeyDown),window.removeEventListener(fe.KEYUP,o.eventListeners.onKeyUp),this.props?.onPointerUp?.(c,o),this.onPointerUpEmitter.trigger(this.state.activeTool,o,n),a?.type==="freedraw"){let y=rt(n,this.state),w=a.points,v=y.x-a.x,I=y.y-a.y;v===w[0][0]&&I===w[0][1]&&(I+=1e-4,v+=1e-4);let C=a.simulatePressure?[]:[...a.pressures,n.pressure];this.scene.mutateElement(a,{points:[...w,pe(v,I)],pressures:C}),this.actionManager.executeAction(ro);return}if(mo(a)){a.points.length>1&&a.points[1][0]!==0&&a.points[1][1]!==0&&this.store.scheduleCapture();let y=rt(n,this.state),w=Pa(pe(y.x,y.y),pe(o.origin.x,o.origin.y))*this.state.zoom.value;if((!o.drag.hasOccurred||w<dq)&&a&&!l)if(this.editorInterface.isTouchScreen){let v=Math.min(this.state.width*.7/this.state.zoom.value,100);this.scene.mutateElement(a,{x:a.x-v/2,points:[pe(0,0),pe(v,0)]},{informMutation:!1,isDragging:!1}),this.actionManager.executeAction(ro)}else{let v=y.x-a.x,I=y.y-a.y;this.scene.mutateElement(a,{points:[a.points[0],pe(v,I)]},{informMutation:!1,isDragging:!1}),this.setState({multiElement:a,newElement:a})}else o.drag.hasOccurred&&!l&&(mo(a)&&this.actionManager.executeAction(ro,"ui",{event:n,sceneCoords:h}),this.setState({suggestedBinding:null,startBoundElement:null}),c.locked?this.setState(v=>({newElement:null})):(Po(this.interactiveCanvas),this.setState(v=>({newElement:null,activeTool:ir(this.state,{type:this.state.preferredSelectionTool.type}),selectedElementIds:ze({...v.selectedElementIds,[a.id]:!0},v),selectedLinearElement:new _e(a,this.scene.getNonDeletedElementsMap())}))),this.scene.triggerUpdate());return}if(kn(a)){let y=iJ(z1({fontSize:a.fontSize,fontFamily:a.fontFamily}),a.lineHeight);a.width<y&&this.scene.mutateElement(a,{autoResize:!0}),this.resetCursor(),this.handleTextWysiwyg(a,{isExistingElement:!0})}if(c.type!=="selection"&&a&&c6(a)){this.updateScene({elements:this.scene.getElementsIncludingDeleted().filter(y=>y.id!==a.id),appState:{newElement:null},captureUpdate:po.NEVER});return}if(Qt(a)){let y=Uq(this.scene.getElementsIncludingDeleted(),a,this.scene.getNonDeletedElementsMap());this.scene.replaceAllElements(ey(this.scene.getElementsMapIncludingDeleted(),y,a,this.state))}if(a&&(this.scene.mutateElement(a,_q(a),{informMutation:!1,isDragging:!1}),this.scene.triggerUpdate()),o.drag.hasOccurred){let y=rt(n,this.state);if(this.state.selectedLinearElement&&this.state.selectedLinearElement.isDragging){let w=this.scene.getElement(this.state.selectedLinearElement.elementId);if(w?.frameId){let v=oy(w,r);v&&w&&(Wq(w,v,this.scene.getNonDeletedElementsMap())||(this.scene.mutateElement(w,{groupIds:[]}),Gq([w],this.scene.getNonDeletedElementsMap()),this.scene.triggerUpdate()))}}else{let w=this.getTopLayerFrameAtSceneCoords(y),v=this.scene.getSelectedElements(this.state),I=this.scene.getElementsMapIncludingDeleted(),C=P=>{if(P.length>0){for(let S of P){let D=S.groupIds.indexOf(this.state.editingGroupId);this.scene.mutateElement(S,{groupIds:S.groupIds.slice(0,D)},{informMutation:!1,isDragging:!1})}I.forEach(S=>{S.groupIds.length&&Li(I,S.groupIds[S.groupIds.length-1]).length<2&&this.scene.mutateElement(S,{groupIds:[]},{informMutation:!1,isDragging:!1})}),this.setState({editingGroupId:null})}};if(w&&!this.state.selectedElementIds[w.id]){let P=v.filter(S=>S.frameId!==w.id&&f6(S,I,this.state));this.state.editingGroupId&&C(P),I=ey(I,P,w,this.state)}else if(!w&&this.state.editingGroupId){let P=v.filter(S=>S.frameId&&!f6(S,I,this.state));C(P)}I=h6(I,this.state,this),this.scene.replaceAllElements(I)}}if(i&&this.store.scheduleCapture(),i&&c6(i)&&this.updateScene({elements:this.scene.getElementsIncludingDeleted().filter(y=>y.id!==i.id),captureUpdate:po.NEVER}),o.resize.isResizing){let y=h6(this.scene.getElementsIncludingDeleted(),this.state,this),w=this.scene.getSelectedElements(this.state).filter(v=>Qt(v));for(let v of w)y=Hq(y,ty(this.scene.getElementsIncludingDeleted(),v,this.state,r),v,this);this.scene.replaceAllElements(y)}let g=o.hit.element;this.state.selectedLinearElement?.elementId!==g?.id&&mo(g)&&this.scene.getSelectedElements(this.state).length===1&&this.setState({selectedLinearElement:new _e(g,this.scene.getNonDeletedElementsMap())}),(!s||s&&(!g&&!d||g&&g.id!==s))&&this.finishImageCropping();let x=this.lastPointerDownEvent,E=this.lastPointerUpEvent||this.lastPointerMoveEvent;if(ho(this.state)&&x&&E){if(this.eraserTrail.endPath(),Pa(pe(x.clientX,x.clientY),pe(E.clientX,E.clientY))===0){let w=rt({clientX:E.clientX,clientY:E.clientY},this.state);this.getElementsAtPosition(w.x,w.y).forEach(I=>this.elementsPendingErasure.add(I.id))}this.eraseElements();return}else this.elementsPendingErasure.size&&this.restoreReadyToEraseElements();if(g&&!o.drag.hasOccurred&&!o.hit.wasAddedToSelection&&(!this.state.selectedLinearElement?.isEditing||!o.boxSelection.hasOccurred)&&this.state.activeTool.type!=="lasso"&&(n.shiftKey&&!this.state.selectedLinearElement?.isEditing?this.state.selectedElementIds[g.id]?mJ(this.state,g)?this.setState(y=>{let w={...y.selectedElementIds};for(let v of g.groupIds.flatMap(I=>Li(this.scene.getNonDeletedElements(),I)))delete w[v.id];return{selectedGroupIds:{...y.selectedElementIds,...g.groupIds.map(v=>({[v]:!1})).reduce((v,I)=>({...v,...I}),{})},selectedElementIds:ze(w,y)}}):this.state.selectedLinearElement?.isDragging||this.setState(y=>{let w={...y.selectedElementIds};delete w[g.id];let v=de(this.scene.getNonDeletedElements(),{selectedElementIds:w});return{...cn({editingGroupId:y.editingGroupId,selectedElementIds:w},this.scene.getNonDeletedElements(),y,this),selectedLinearElement:v.length===1&&mo(v[0])?new _e(v[0],this.scene.getNonDeletedElementsMap()):y.selectedLinearElement}}):g.frameId&&this.state.selectedElementIds[g.frameId]?this.setState(y=>{let w={...y.selectedElementIds,[g.id]:!0};return delete w[g.frameId],(this.scene.getElement(g.frameId)?.groupIds??[]).flatMap(v=>Li(this.scene.getNonDeletedElements(),v)).forEach(v=>{delete w[v.id]}),{...cn({editingGroupId:y.editingGroupId,selectedElementIds:w},this.scene.getNonDeletedElements(),y,this),showHyperlinkPopup:g.link||Nr(g)?"info":!1}}):this.setState(y=>({selectedElementIds:ze({...y.selectedElementIds,[g.id]:!0},y)})):this.setState(y=>({...cn({editingGroupId:y.editingGroupId,selectedElementIds:{[g.id]:!0}},this.scene.getNonDeletedElements(),y,this),selectedLinearElement:mo(g)&&y.selectedLinearElement?.elementId!==g.id?new _e(g,this.scene.getNonDeletedElementsMap()):y.selectedLinearElement}))),this.state.activeTool.type!=="lasso"&&!(g&&To(g))&&!o.drag.hasOccurred&&!this.state.isResizing&&(g&&Xq({point:pe(o.origin.x,o.origin.y),element:g,elementsMap:r,threshold:this.getElementHitThreshold(g),frameNameBound:Qt(g)?this.frameNameBoundsCache.get(g):null},r)||!g&&o.hit.hasHitCommonBoundingBoxOfSelectedElements)){this.state.selectedLinearElement?.isEditing?this.actionManager.executeAction(il):this.setState({selectedElementIds:ze({},this.state),selectedGroupIds:{},editingGroupId:null,activeEmbeddable:null}),Be(this.interactiveCanvas,lt.AUTO);return}if(!c.locked&&c.type!=="freedraw"&&a&&this.setState(y=>({selectedElementIds:ze({...y.selectedElementIds,[a.id]:!0},y),showHyperlinkPopup:Nr(a)&&!a.link?"editor":y.showHyperlinkPopup})),(c.type!=="selection"||Ge(this.scene.getNonDeletedElements(),this.state)||!JP(this.state.previousSelectedElementIds,this.state.selectedElementIds))&&this.store.scheduleCapture(),o.drag.hasOccurred&&!this.state.selectedLinearElement||m||p||d){let y=this.scene.getSelectedElements(this.state).filter(Ol);e6(y,this.scene,this.state)}if(c.type==="laser"){this.laserTrails.endPath();return}!c.locked&&c.type!=="freedraw"&&(c.type!=="lasso"||c.type==="lasso"&&c.fromSelection)?(Po(this.interactiveCanvas),this.setState({newElement:null,suggestedBinding:null,activeTool:ir(this.state,{type:this.state.preferredSelectionTool.type})})):this.setState({newElement:null,suggestedBinding:null})})}clearSelection(o){this.setState(n=>({selectedElementIds:ze({},n),activeEmbeddable:null,selectedGroupIds:{},editingGroupId:n.editingGroupId&&o!=null&&y6(o,n.editingGroupId)?n.editingGroupId:null})),this.setState({selectedElementIds:ze({},this.state),activeEmbeddable:null,previousSelectedElementIds:this.state.selectedElementIds,selectedLinearElement:null})}getTextWysiwygSnappedToCenterPosition(o,n,r,a){if(a){let i=a.x+a.width/2,s=a.y+a.height/2,l=J1(a,r,this.scene.getNonDeletedElementsMap());if(l&&(i=l.x,s=l.y),Math.hypot(o-i,n-s)<$j){let{x:p,y:d}=Ng({sceneX:i,sceneY:s},r);return{viewportX:p,viewportY:d,elementCenterX:i,elementCenterY:s}}}}getCanvasOffsets(){if(this.excalidrawContainerRef?.current){let o=this.excalidrawContainerRef.current,{left:n,top:r}=o.getBoundingClientRect();return{offsetLeft:n,offsetTop:r}}return{offsetLeft:0,offsetTop:0}}async updateLanguage(){let o=Zi.find(n=>n.code===this.props.langCode)||Nn;await pm(o),this.setAppState({})}},PJ=()=>{(N6()||B6())&&(window.h=window.h||{},Object.defineProperties(window.h,{elements:{configurable:!0,get(){return this.app?.scene.getElementsIncludingDeleted()},set(e){return this.app?.scene.replaceAllElements(O6(e))}},scene:{configurable:!0,get(){return this.app?.scene}}}))};PJ();var G6=uy;import{useEffect as AJ,useState as LJ}from"react";import{jsx as _J}from"react/jsx-runtime";var U6=e=>{let[t,o]=LJ(!0);return AJ(()=>{let n=async()=>{await pm(r),o(!1)},r=Zi.find(a=>a.code===e.langCode)||Nn;n()},[e.langCode]),t?_J(Uu,{theme:e.theme}):e.children};import DJ from"clsx";import{jsx as W6}from"react/jsx-runtime";var Y6=({children:e})=>{let{FooterCenterTunnel:t}=Ze(),o=Ie();return W6(t.In,{children:W6("div",{className:DJ("footer-center zen-mode-transition",{"layer-ui__wrapper__footer-left--transition-bottom":o.zenModeEnabled}),children:e})})},RJ=Y6;Y6.displayName="FooterCenter";import NJ from"clsx";import{MQ_MIN_WIDTH_DESKTOP as BJ}from"@orangecatai/common";import{jsx as OJ,jsxs as zJ}from"react/jsx-runtime";var $6=({isCollaborating:e,onSelect:t,editorInterface:o,...n})=>{let r=Ie(),a=o?.formFactor!=="desktop"||r.width<BJ;return zJ(so,{...n,className:NJ("collab-button",{active:e}),type:"button",onSelect:t,style:{position:"relative",width:a?void 0:"auto"},title:f("labels.liveCollaboration"),children:[a?ZE:f("labels.share"),r.collaborators.size>0&&OJ("div",{className:"CollabButton-collaborators",children:r.collaborators.size})]})},FJ=$6;$6.displayName="LiveCollaborationTrigger";import{jsx as Fa,jsxs as K6}from"react/jsx-runtime";var HJ=()=>Fa("svg",{viewBox:"0 0 40 40",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:"ExcalidrawLogo-icon",children:Fa("path",{d:"M39.9 32.889a.326.326 0 0 0-.279-.056c-2.094-3.083-4.774-6-7.343-8.833l-.419-.472a.212.212 0 0 0-.056-.139.586.586 0 0 0-.167-.111l-.084-.083-.056-.056c-.084-.167-.28-.278-.475-.167-.782.39-1.507.973-2.206 1.528-.92.722-1.842 1.445-2.708 2.25a8.405 8.405 0 0 0-.977 1.028c-.14.194-.028.361.14.444-.615.611-1.23 1.223-1.843 1.861a.315.315 0 0 0-.084.223c0 .083.056.166.111.194l1.09.833v.028c1.535 1.528 4.244 3.611 7.12 5.861.418.334.865.667 1.284 1 .195.223.39.473.558.695.084.11.28.139.391.055.056.056.14.111.196.167a.398.398 0 0 0 .167.056.255.255 0 0 0 .224-.111.394.394 0 0 0 .055-.167c.029 0 .028.028.056.028a.318.318 0 0 0 .224-.084l5.082-5.528a.309.309 0 0 0 0-.444Zm-14.63-1.917a.485.485 0 0 0 .111.14c.586.5 1.2 1 1.843 1.555l-2.569-1.945-.251-.166c-.056-.028-.112-.084-.168-.111l-.195-.167.056-.056.055-.055.112-.111c.866-.861 2.346-2.306 3.1-3.028-.81.805-2.43 3.167-2.095 3.944Zm8.767 6.89-2.122-1.612a44.713 44.713 0 0 0-2.625-2.5c1.145.861 2.122 1.611 2.262 1.75 1.117.972 1.06.806 1.815 1.445l.921.666a1.06 1.06 0 0 1-.251.25Zm.558.416-.056-.028c.084-.055.168-.111.252-.194l-.196.222ZM1.089 5.75c.055.361.14.722.195 1.056.335 1.833.67 3.5 1.284 4.75l.252.944c.084.361.223.806.363.917 1.424 1.25 3.602 3.11 5.947 4.889a.295.295 0 0 0 .363 0s0 .027.028.027a.254.254 0 0 0 .196.084.318.318 0 0 0 .223-.084c2.988-3.305 5.221-6.027 6.813-8.305.112-.111.14-.278.14-.417.111-.111.195-.25.307-.333.111-.111.111-.306 0-.39l-.028-.027c0-.055-.028-.139-.084-.167-.698-.666-1.2-1.138-1.731-1.638-.922-.862-1.871-1.75-3.881-3.75l-.028-.028c-.028-.028-.056-.056-.112-.056-.558-.194-1.703-.389-3.127-.639C6.087 2.223 3.21 1.723.614.944c0 0-.168 0-.196.028l-.083.084c-.028.027-.056.055-.224.11h.056-.056c.028.167.028.278.084.473 0 .055.112.5.112.555l.782 3.556Zm15.496 3.278-.335-.334c.084.112.196.195.335.334Zm-3.546 4.666-.056.056c0-.028.028-.056.056-.056Zm-2.038-10c.168.167.866.834 1.033.973-.726-.334-2.54-1.167-3.379-1.445.838.167 1.983.334 2.346.472ZM1.424 2.306c.419.722.754 3.222 1.089 5.666-.196-.778-.335-1.555-.503-2.278-.251-1.277-.503-2.416-.838-3.416.056 0 .14 0 .252.028Zm-.168-.584c-.112 0-.223-.028-.307-.028 0-.027 0-.055-.028-.055.14 0 .223.028.335.083Zm-1.089.222c0-.027 0-.027 0 0ZM39.453 1.333c.028-.11-.558-.61-.363-.639.42-.027.42-.666 0-.666-.558.028-1.144.166-1.675.25-.977.194-1.982.389-2.96.61-2.205.473-4.383.973-6.561 1.557-.67.194-1.424.333-2.066.666-.224.111-.196.333-.084.472-.056.028-.084.028-.14.056-.195.028-.363.056-.558.083-.168.028-.252.167-.224.334 0 .027.028.083.028.11-1.173 1.556-2.485 3.195-3.909 4.945-1.396 1.611-2.876 3.306-4.356 5.056-4.719 5.5-10.052 11.75-15.943 17.25a.268.268 0 0 0 0 .389c.028.027.056.055.084.055-.084.084-.168.14-.252.222-.056.056-.084.111-.084.167a.605.605 0 0 0-.111.139c-.112.111-.112.305.028.389.111.11.307.11.39-.028.029-.028.029-.056.056-.056a.44.44 0 0 1 .615 0c.335.362.67.723.977 1.028l-.698-.583c-.112-.111-.307-.083-.39.028-.113.11-.085.305.027.389l7.427 6.194c.056.056.112.056.196.056s.14-.028.195-.084l.168-.166c.028.027.083.027.111.027.084 0 .14-.027.196-.083 10.052-10.055 18.15-17.639 27.42-24.417.083-.055.111-.166.111-.25.112 0 .196-.083.251-.194 1.704-5.194 2.039-9.806 2.15-12.083v-.028c0-.028.028-.056.028-.083.028-.056.028-.084.028-.084a1.626 1.626 0 0 0-.111-1.028ZM21.472 9.5c.446-.5.893-1.028 1.34-1.5-2.876 3.778-7.65 9.583-14.408 16.5 4.607-5.083 9.242-10.333 13.068-15ZM5.193 35.778h.084-.084Zm3.462 3.194c-.027-.028-.027-.028 0-.028v.028Zm4.16-3.583c.224-.25.448-.472.699-.722 0 0 0 .027.028.027-.252.223-.475.445-.726.695Zm1.146-1.111c.14-.14.279-.334.446-.5l.028-.028c1.648-1.694 3.351-3.389 5.082-5.111l.028-.028c.419-.333.921-.694 1.368-1.028a379.003 379.003 0 0 0-6.952 6.695ZM24.794 6.472c-.921 1.195-1.954 2.778-2.82 4.028-2.736 3.944-11.532 13.583-11.727 13.75a1976.983 1976.983 0 0 1-8.042 7.639l-.167.167c-.14-.167-.14-.417.028-.556C14.49 19.861 22.03 10.167 25.074 5.917c-.084.194-.14.36-.28.555Zm4.83 5.695c-1.116-.64-1.646-1.64-1.34-2.611l.084-.334c.028-.083.084-.194.14-.277.307-.5.754-.917 1.257-1.167.027 0 .055 0 .083-.028-.028-.056-.028-.139-.028-.222.028-.167.14-.278.335-.278.335 0 1.369.306 1.76.639.111.083.223.194.335.305.14.167.363.445.474.667.056.028.112.306.196.445.056.222.111.472.084.694-.028.028 0 .194-.028.194a2.668 2.668 0 0 1-.363 1.028c-.028.028-.028.056-.056.084l-.028.027c-.14.223-.335.417-.53.556-.643.444-1.369.583-2.095.389 0 0-.195-.084-.28-.111Zm8.154-.834a39.098 39.098 0 0 1-.893 3.167c0 .028-.028.083 0 .111-.056 0-.084.028-.14.056-2.206 1.61-4.356 3.305-6.506 5.028 1.843-1.64 3.686-3.306 5.613-4.945.558-.5.949-1.139 1.06-1.861l.28-1.667v-.055c.14-.334.67-.195.586.166Z",fill:"currentColor"})}),GJ=()=>K6("svg",{viewBox:"0 0 450 55",xmlns:"http://www.w3.org/2000/svg",fill:"none",className:"ExcalidrawLogo-text",children:[Fa("path",{d:"M429.27 96.74c2.47-1.39 4.78-3.02 6.83-4.95 1.43-1.35 2.73-2.86 3.81-4.51-.66.9-1.4 1.77-2.23 2.59-2.91 2.84-5.72 5.09-8.42 6.87h.01ZM343.6 69.36c.33 3.13.58 6.27.79 9.4.09 1.37.18 2.75.25 4.12-.12-4.46-.27-8.93-.5-13.39-.11-2.08-.24-4.16-.4-6.24-.06 1.79-.11 3.85-.13 6.11h-.01ZM378.47 98.34c.01-.37.07-1.13.01-6.51-.11 1.9-.22 3.81-.31 5.71-.07 1.42-.22 2.91-.16 4.35.39.03.78.07 1.17.1-.92-.85-.76-2.01-.72-3.66l.01.01ZM344.09 86.12c-.09-2.41-.22-4.83-.39-7.24v12.21c.15-.05.32-.09.47-.14.05-1.61-.03-3.23-.09-4.83h.01ZM440.69 66.79c-.22-.34-.45-.67-.69-.99-3.71-4.87-9.91-7.14-15.65-8.55-1.05-.26-2.12-.49-3.18-.71 2.29.59 4.48 1.26 6.64 2.02 7.19 2.54 10.57 5.41 12.88 8.23ZM305.09 72.46l1.2 3.6c.84 2.53 1.67 5.06 2.46 7.61.24.78.5 1.57.73 2.36.22-.04.44-.08.67-.12a776.9 776.9 0 0 1-5.01-13.57c-.02.04-.03.09-.05.13v-.01ZM345.49 90.25v.31c1.48-.42 3.05-.83 4.66-1.2-1.56.25-3.12.52-4.66.89ZM371.02 90.22c0-.57-.04-1.14-.11-1.71-.06-.02-.12-.04-.19-.05-.21-.05-.43-.08-.65-.11.42.16.74.88.95 1.87ZM398.93 54.23c-.13 0-.27-.01-.4-.02l.03.4c.11-.15.23-.27.37-.38ZM401.57 62.28v-.15c-1.22-.24-2.86-.61-3.23-1.25-.09-.15-.18-.51-.27-.98-.09.37-.2.73-.33 1.09 1.24.56 2.52.98 3.83 1.29ZM421.73 88.68c-2.97 1.65-6.28 3.12-9.69 3.68v.18c4.72-.14 11.63-3.85 16.33-8.38-2.04 1.75-4.33 3.24-6.63 4.53l-.01-.01ZM411.28 80.92c-.05-1.2-.09-2.4-.15-3.6-.21 5.66-.46 11.38-.47 14.51.24-.02.48-.04.71-.07.15-3.61.05-7.23-.09-10.83v-.01Z",transform:"translate(-144.023 -51.76)"}),Fa("path",{d:"M425.38 67.41c-3.5-1.45-7.19-2.57-14.06-3.62.09 1.97.06 4.88-.03 8.12.03.04.06.09.06.15.19 1.36.28 2.73.37 4.1.25 3.77.39 7.55.41 11.33 0 1.38-.01 2.76-.07 4.13 1.4-.25 2.78-.65 4.12-1.15 4.07-1.5 7.94-3.78 11.28-6.54 2.33-1.92 5.13-4.49 5.88-7.58.63-3.53-2.45-6.68-7.97-8.96l.01.02ZM411.35 92.53v-.06l-.34.03c.11.01.22.03.34.03ZM314.26 64.06c-.23-.59-.47-1.17-.7-1.75.57 1.62 1.11 3.25 1.6 4.9l.15.54 2.35 6.05c.32.82.66 1.64.98 2.46-1.38-4.1-2.83-8.17-4.39-12.2h.01ZM156.82 103.07c-.18.13-.38.23-.58.33 1.32-.03 2.66-.2 3.93-.34.86-.09 1.72-.22 2.58-.33-2.12.1-4.12.17-5.94.34h.01ZM210.14 68.88s.03.04.05.07c.18-.31.39-.64.58-.96-.21.3-.42.6-.64.89h.01ZM201.65 82.8c-.5.77-1.02 1.56-1.49 2.37 1.11-1.55 2.21-3.1 3.2-4.59-.23.23-.49.51-.75.79-.32.47-.65.95-.96 1.43ZM194.03 98.66c-.33-.4-.65-.84-1.05-1.17-.24-.2-.07-.49.17-.56-.23-.26-.42-.5-.63-.75 1.51-2.55 3.93-5.87 6.4-9.28-.17-.08-.29-.28-.2-.49.04-.09.09-.17.13-.26-1.21 1.78-2.42 3.55-3.61 5.33-.87 1.31-1.74 2.64-2.54 4-.29.5-.63 1.04-.87 1.61.81.65 1.63 1.27 2.47 1.88-.09-.11-.18-.21-.27-.32v.01ZM307.79 82.93c-1-3.17-2.05-6.32-3.1-9.48-1.62 4.08-3.69 9.17-6.16 15.19 3.32-1.04 6.77-1.87 10.27-2.5-.32-1.08-.67-2.15-1.01-3.21ZM149.5 80.7c.05-1.71.04-3.43 0-5.14-.1 2.26-.16 4.51-.22 6.77-.02.73-.03 1.46-.04 2.19.14-1.27.2-2.55.24-3.82h.02ZM228.98 98.3c.39 1.25.91 3.03.94 3.91.06-.03.12-.07.17-.1.08-1.29-.55-2.65-1.11-3.81ZM307.72 53.36c.81.5 1.53 1.04 2.07 1.49-.38-.8-.78-1.58-1.21-2.35-.17.03-.34.06-.51.11-.43.12-.86.26-1.29.41.35-.01.53.1.94.34ZM283.69 96.14c3.91-7.25 6.89-13.35 8.88-18.15l1.1-2.66c-1.27 2.64-2.56 5.27-3.83 7.9-1.53 3.15-3.06 6.31-4.58 9.47-.87 1.81-1.76 3.62-2.54 5.47.04.02.07.04.11.07.05.05.1.09.15.14.05-.73.27-1.48.71-2.24ZM289.92 103.23s-.04.01-.05.03c0-.02.04-.03.05-.04.05-.05.11-.1.16-.15l.21-.21c-.55 0-1.5-.27-2.55-.72.4.26.8.51 1.22.74.24.13.48.26.73.37.05.02.1.03.14.05a.27.27 0 0 1 .08-.07h.01ZM269.23 68.49c-.39-.19-.82-.48-1.33-.87-3.06-1.56-6.31-2.78-9.36-2.35-3.5.49-5.7 1.11-7.74 2.44 5.71-2.6 12.82-2.07 18.44.79l-.01-.01ZM177.87 53.69l1.06.03c-.96-.22-2-.25-2.89-.3-4.95-.26-9.99.33-14.86 1.19-2.44.43-4.88.95-7.28 1.59 9.09-1.76 15.69-2.77 23.97-2.51ZM219.85 55.51c-.18.12-.36.27-.56.45-.45.53-.86 1.11-1.26 1.66-1.91 2.61-3.71 5.31-5.57 7.95l-.12.18 8.05-10.11c-.18-.05-.36-.1-.55-.13h.01ZM510.71 54.1c.12-.15.29-.3.53-.45.69-.4 3.72-.63 5.87-.74-.36-.02-.73-.04-1.09-.05-1.84-.03-3.67.09-5.49.35.05.3.12.59.18.88v.01ZM510.76 86.02c1.37-3.07 2.49-6.27 3.57-9.46.55-1.64 1.12-3.3 1.6-4.97-1.59 4.01-3.67 9.14-6.2 15.3.24-.08.5-.14.74-.22.1-.22.19-.44.29-.65ZM566.95 75.76c.11-.02.23.03.31.11-.05-.13-.09-.26-.14-.39-.05.09-.11.18-.17.28ZM511.33 86.41c3.08-.89 6.24-1.62 9.46-2.14-1.51-3.98-2.98-7.96-4.39-11.87-.05.15-.09.31-.14.46-1.02 3.32-2.15 6.61-3.39 9.85-.48 1.25-.98 2.49-1.53 3.7h-.01ZM578.24 74.45c.11-.44.23-.87.35-1.31-.31.7-.64 1.39-.97 2.08.09.21.19.4.28.61.12-.46.23-.92.35-1.38h-.01ZM520.62 53.11c-.09 0-.18-.01-.28-.02.38.34.29 1.08.93 2.53l6.65 17.15c2.2 5.68 4.69 11.36 7.41 16.87l1.06 2.17c-2.95-7.05-5.92-14.08-8.87-21.13-1.58-3.79-3.16-7.59-4.7-11.4-.78-1.92-1.73-3.89-2.25-5.91-.03-.1 0-.19.04-.26h.01ZM578.78 77.87c1.45-5.77 3.07-10.43 3.58-13.36.05-.34.16-.88.31-1.55-.67 1.79-1.37 3.56-2.08 5.33-.12.43-.23.86-.35 1.29-.65 2.43-1.29 4.86-1.9 7.3.14.33.29.65.43 1l.01-.01ZM545.3 94.66c.02-.44.03-.83.05-1.12.02-1.01.05-2.02.11-3.02.03-6.66-.46-14.33-1.46-22.8-.13-.42-.27-1.24-.56-2.89 0-.02 0-.04-.01-.06.62 6.61.95 13.25 1.32 19.87.17 3.08.33 6.16.52 9.23.02.25.03.52.04.78l-.01.01ZM580.77 102.81c.13.2.27.38.37.49.27-.11.53-.22.8-.32-.43.09-.82.05-1.17-.16v-.01ZM530.48 104.07h.33c-.36-.13-.71-.32-1.04-.56.14.24.3.47.45.7.06-.08.14-.13.26-.13v-.01ZM542.63 58.82c.06.23.11.47.15.71.14-.33.36-.62.7-.86-.28.05-.57.11-.85.15ZM583.81 57.87c.15-.7.29-1.41.42-2.11-.14.45-.28.9-.42 1.34-.46 1.44-.89 2.89-1.31 4.34.44-1.19.88-2.37 1.31-3.57ZM523.62 91.48c-4.66 1.17-9.05 2.89-14.02 5.27 4.65-1.84 9.48-3.29 14.28-4.63-.09-.22-.17-.41-.26-.64ZM460.64 78.3c-.04-2.9-.11-5.81-.28-8.71-.1-1.68-.17-3.43-.5-5.09-.07.02-.14.03-.2.05.3 6.54.45 12.17.51 17.12.17-.07.34-.14.51-.2 0-1.06-.01-2.11-.03-3.17h-.01ZM470.63 63.24c-3.38-.26-6.81.32-10.1 1.1.41 2.01.47 4.14.57 6.18.18 3.55.25 7.11.27 10.67 3.31-1.38 6.5-3.12 9.3-5.35 1.96-1.56 3.86-3.41 5.02-5.66.73-1.41 1.19-3.22.26-4.65-1.09-1.7-3.46-2.14-5.32-2.29ZM460.29 63.68c1-.24 2.01-.46 3.04-.65-1.15.16-2.37.38-3.71.69v.13c.07-.02.15-.04.22-.05.11-.13.3-.18.45-.11v-.01ZM457.24 100.96c.43-.03.86-.07 1.29-.11.14-.49.27-.99.38-1.49-.44.7-1 1.23-1.67 1.6ZM482.88 104.98c-.18.23-.36.38-.55.47.14.09.27.19.4.28a70.76 70.76 0 0 0 4.37-4.63c.76-.89 1.52-1.81 2.19-2.77-.3-.27-.61-.53-.92-.79-.07 1.94-4.62 6.32-5.49 7.45v-.01Z",transform:"translate(-144.023 -51.76)"}),Fa("path",{d:"M474.36 63.31c-.4-.16-.84-.27-1.29-.37 1.56.42 3.08 1.22 3.76 2.74.62 1.4.32 2.95-.28 4.32.7-1.22.94-2.34.74-3.47-.24-1.33-1.19-2.54-2.93-3.21v-.01ZM477.34 89.18c-1.2-.81-2.4-1.62-3.6-2.42-.14.1-.26.19-.4.29 1.4.67 2.73 1.39 4 2.13ZM465.88 93.85c.37.25.74.5 1.1.75.46.32.92.65 1.38.97-1.57-1.2-2.01-1.61-2.49-1.72h.01ZM574.92 90.06c-2.28-5.21-4.93-11.13-5.67-12.26-.1-.15-1.57-3.01-1.63-3.08 0 0-.01.02-.02.02.4 1.37 1.09 2.69 1.65 3.99 2.14 4.95 4.36 9.86 6.67 14.73.6 1.26 1.21 2.52 1.83 3.78-.75-2.01-1.64-4.45-2.83-7.18ZM448.73 65.29c.1.2.22.38.34.57.22-.02.43-.06.65-.08v-.08c-.14-.05-.25 0-.99-.41ZM460.16 94.81c-.02.31-.06.59-.1.89-.03 1.71-.33 3.43-.79 5.07.15-.02.3-.03.45-.05.01-.04.02-.08.03-.11.09-.34.15-.69.2-1.03.17-1.07.25-2.16.33-3.24.05-.69.08-1.39.12-2.08-.27.1-.27.26-.24.57v-.02Z",transform:"translate(-144.023 -51.76)"}),Fa("path",{d:"m328.67 98.12-3.22-6.58c-1.29-2.63-2.53-5.29-3.72-7.97-.25-.85-.52-1.69-.79-2.53-.81-2.57-1.67-5.12-2.55-7.67-1.92-5.53-3.9-11.08-6.32-16.41-.72-1.58-1.46-3.44-2.63-4.79-.03-.17-.16-.29-.34-.36a.282.282 0 0 0-.23-.04c-.06-.01-.12 0-.18.01-.74.06-1.5.38-2.19.61-2.22.77-4.4 1.64-6.63 2.38-.03-.08-.06-.16-.09-.25-.15-.42-.82-.24-.67.19.03.09.07.19.1.28l-.18.06c-.36.11-.28.6 0 .68.18 1.18.63 2.36.98 3.49.03.09.06.17.08.26-.08.23-.17.46-.24.64-.37.98-.79 1.94-1.21 2.9-1.27 2.89-2.62 5.75-3.98 8.6-3.18 6.67-6.44 13.31-9.64 19.97-1.08 2.25-2.2 4.5-3.15 6.81-.13.32.24.5.5.37 1.34 1.33 2.84 2.5 4.4 3.57.65.44 1.31.87 2.01 1.24.4.22.86.48 1.33.5.24.01.35-.19.33-.37.11-.1.21-.21.28-.28.41-.41.81-.84 1.2-1.26.85-.92 1.69-1.87 2.5-2.84 6.31-2.34 12.6-4.31 18.71-5.84 2.14 5.3 3.43 8.43 3.97 9.58.55 1.05 1.15 1.88 1.82 2.52 1.32.56 6.96-.03 9.23-1.96.87-1.28 1.19-2.67.93-4.15-.09-.5-.22-.95-.4-1.33l-.01-.03Zm-20.09-45.61c.43.77.83 1.56 1.21 2.35-.54-.45-1.27-.99-2.07-1.49-.42-.24-.6-.35-.94-.34.43-.15.85-.29 1.29-.41.17-.05.34-.08.51-.11Zm-25.86 45.66c.78-1.85 1.67-3.66 2.54-5.47 1.51-3.16 3.05-6.31 4.58-9.47 1.28-2.63 2.56-5.26 3.83-7.9l-1.1 2.66c-1.99 4.79-4.97 10.9-8.88 18.15-.43.76-.66 1.51-.71 2.24-.05-.05-.1-.09-.15-.14a.259.259 0 0 0-.11-.07Zm6.24 4.71c-.42-.23-.82-.48-1.22-.74 1.05.45 2 .72 2.55.72l-.21.21c-.05.05-.11.1-.16.15-.01.01-.04.03-.05.04 0-.02.03-.02.05-.03a.27.27 0 0 0-.08.07c-.05-.02-.1-.03-.14-.05-.25-.1-.49-.24-.73-.37h-.01Zm15.73-29.43c1.05 3.15 2.1 6.31 3.1 9.48.34 1.06.69 2.13 1.01 3.21-3.5.63-6.95 1.46-10.27 2.5 2.48-6.03 4.54-11.11 6.16-15.19Zm4.79 12.57c-.23-.79-.49-1.58-.73-2.36-.79-2.54-1.63-5.08-2.46-7.61l-1.2-3.6c.02-.04.04-.09.05-.13 1.6 4.45 3.28 9 5.01 13.57l-.67.12v.01Zm5.83-18.27-.15-.54c-.49-1.64-1.03-3.28-1.6-4.9.23.58.47 1.17.7 1.75 1.56 4.03 3.01 8.1 4.39 12.2-.33-.82-.67-1.64-.98-2.46l-2.35-6.05h-.01ZM390.43 79.37c-.13-10.43-.22-17.5-.24-19.97-.24-1.6.21-2.88-.65-3.65-.14-.13-.32-.23-.52-.32h.03c.45 0 .45-.69 0-.7-1.75-.03-3.5-.04-5.25-.14-1.38-.08-2.76-.21-4.15-.31-.07 0-.12.01-.17.04-.21-.07-.47.03-.45.31l.03.45c-.11.14-.19.3-.22.5-.21 1.26-.32 13.67-.36 23.59-.32 5.79-.67 11.57-.97 17.36-.09 1.73-.29 3.54-.21 5.3-.39.02-.38.64.04.69v.12c.05.44.74.45.7 0v-.06c1.1.09 2.2.21 3.3.3 1.14.19 2.44.2 3.29.17 1.73-.05 2.92-.05 3.8-.37.45-.05.9-.11 1.35-.17.44-.06.25-.73-.19-.67h-.01c.24-.32.45-.72.62-1.25.66-1.84.41-6.36.34-11.33l-.13-9.9.02.01Zm-12.26 18.17c.09-1.91.2-3.81.31-5.71.06 5.38 0 6.14-.01 6.51-.05 1.65-.21 2.81.72 3.66-.39-.04-.78-.07-1.17-.1-.06-1.44.09-2.93.16-4.35l-.01-.01ZM588.97 53.85c-2.06-.25-3.17-.51-3.76-.6a.3.3 0 0 1 .04-.08c.22-.39-.39-.75-.6-.35-.56 1.02-.9 2.19-1.26 3.29-.61 1.88-1.17 3.78-1.72 5.68-.63 2.19-1.24 4.39-1.83 6.59-.81 2.03-1.67 4.05-2.61 6.03-1.7-3.64-3.11-6.04-4.03-7.57-2.26-3.74-2.85-5.48-3.57-6.08l.31-.09c.43-.12.25-.8-.19-.67-1.06.3-2.12.6-3.17.95-.93.32-1.85.69-2.76 1.07-.13.05-.19.16-.22.27-.04.02-.08.05-.11.07-.04-.06-.07-.12-.11-.18a.354.354 0 0 0-.48-.12c-.16.09-.22.32-.13.48l.33.54c0 .09.02.18.06.28.51 1.16.78 1.38.72 1.47-2.42 3.44-5.41 7.86-6.2 9.1-1.27 1.97-2.01 3.14-2.45 3.84l-.91-6.56-.43-4.1c-.19-1.85-.37-3.23-.53-4.13-.19-1.1-.3-2.15-.45-3.16-.2-1.36-.29-2.06-.47-2.42h.04c.45.02.45-.68 0-.7-3.43-.16-6.81.94-10.17 1.48-.24-.22-.73-.04-.58.32.24.59.33 1.25.43 1.87.17 1.06.29 2.13.4 3.2.32 3.09.53 6.2.74 9.3.44 6.75.77 13.51 1.17 20.26.11 1.95.13 3.96.46 5.89.05.3.37.31.55.14.74 1.71 2.87 1.27 6.13 1.27 1.34 0 2.39.04 2.99-.11.02.32.48.53.63.18 3.61-8.26 7.41-16.46 12.05-24.2.03-.05.04-.1.05-.15.3.73.64 1.45.94 2.16.97 2.26 1.97 4.52 2.98 6.76 2.26 5.03 4.54 10.07 7.09 14.96.47.9.94 1.79 1.47 2.65.2.32.4.67.66.96-.18.25 0 .68.34.54.91-.38 1.82-.75 2.76-1.07 1.04-.35 2.11-.65 3.17-.95.39-.11.28-.66-.07-.68.62-.4.95-.96.87-1.91-.3-3.34.72-7.47.86-8.52l2.14-11.43c1.75-10.74 3.13-17.51 3.23-20.86.02-.49.08-2.84.13-3.24.17-1.25.48-1-4.96-1.65l.03-.02Zm-46.19 5.67c-.04-.24-.09-.48-.15-.71l.85-.15c-.34.24-.56.53-.7.86Zm1.95 25.12c-.36-6.63-.7-13.26-1.32-19.87 0 .02 0 .04.01.06.29 1.65.44 2.47.56 2.89 1 8.46 1.5 16.14 1.46 22.8-.06.99-.1 2-.11 3.02-.01.29-.03.68-.05 1.12-.01-.26-.03-.53-.04-.78-.19-3.08-.35-6.16-.52-9.23l.01-.01Zm36.4 18.66c-.11-.11-.24-.29-.37-.49.35.21.74.26 1.17.16-.27.11-.53.22-.8.32v.01Zm-.89-33.72c.12-.43.23-.86.35-1.29.71-1.77 1.41-3.55 2.08-5.33-.15.68-.26 1.22-.31 1.55-.5 2.94-2.13 7.59-3.58 13.36-.15-.35-.29-.66-.43-1 .61-2.44 1.25-4.87 1.9-7.3l-.01.01Zm3.56-12.48c.14-.44.28-.89.42-1.34-.13.7-.27 1.41-.42 2.11-.43 1.19-.86 2.38-1.31 3.57.42-1.45.85-2.9 1.31-4.34Zm-5.22 16.05c-.11.44-.23.87-.35 1.31-.12.46-.23.92-.35 1.38-.1-.22-.19-.4-.28-.61.34-.69.66-1.38.97-2.08h.01Zm-11.64 2.62c.06-.1.12-.19.17-.28.05.13.09.26.14.39a.398.398 0 0 0-.31-.11Zm2.3 2.98c-.56-1.3-1.25-2.63-1.65-3.99 0 0 .01-.02.02-.02.06.08 1.52 2.93 1.63 3.08.73 1.13 3.38 7.04 5.67 12.26 1.2 2.73 2.08 5.17 2.83 7.18-.62-1.25-1.23-2.51-1.83-3.78-2.31-4.87-4.53-9.78-6.67-14.73ZM275.92 87.03c-1.06-2.18-1.13-3.45-2.44-2.93-1.52.57-2.94 1.3-4.5 2.1-1.4.72-2.68 1.44-3.92 2.12.01-.25-.24-.5-.51-.34-4.8 2.93-12.41 4.7-17.28 1.31-1.98-1.77-3.32-4.15-3.97-5.78-.29-.95-.49-1.94-.63-2.93-.14-3.34 1.58-6.53 3.9-9.12.8-.79 1.68-1.51 2.66-2.12 3.7-2.3 8.22-3.07 12.51-2.51 2.71.35 5.32 1.24 7.71 2.55.39.22.75-.39.35-.6-.18-.1-.37-.18-.55-.27.56.27 1.03.33 1.51.19l-.48.39c-.15.11-.23.3-.13.48.09.15.33.24.48.13 1.3-.97 2.46-2.09 3.45-3.37.37-.29.64-.6.65-.97v-.02c.08-.33-.03-.7-.21-1.08-.31-.87-.98-2.01-2.19-3.26-2.43-2.52-3.79-3.45-5.68-4.26-1.14-.49-3.12-1.06-4.42-1.23-3.28-.42-10.64-1.21-18.18 4.11-7.74 5.46-11.94 12.3-12.23 20.61-.08 2.06.04 3.98.34 5.71.74 4.18 2.57 8 5.44 11.34 4.26 4.99 9.76 7.52 16.34 7.52 4.85 0 9.69-1.77 14.89-4.62.23-.12.45-.23.68-.35 2.19-1.1 4.37-2.23 6.46-3.5.49-.3 1.03-.61 1.5-.98 1.47-.87 1.11-1.12.49-2.95-.39-1.14-.76-2.7-2.06-5.36l.02-.01Zm-17.38-21.76c3.05-.42 6.31.79 9.36 2.35.51.39.94.68 1.33.87-5.61-2.86-12.72-3.39-18.44-.79 2.05-1.33 4.24-1.95 7.74-2.44l.01.01ZM443.67 72.67c-.4-2.2-1.15-4.33-2.37-6.22-1.49-2.32-3.58-4.19-5.91-5.64-6.17-3.81-13.75-5.11-20.83-6.01-3.23-.41-6.47-.69-9.72-.92l-1.39-.12c-.85-.07-1.52-.1-2.05-.1-1.08-.06-2.17-.12-3.25-.17-.08 0-.14.02-.19.05-.1.05-.18.14-.16.3.27 2.55-.01 5.12-.92 7.52-.15.38.4.56.62.28 1.32.59 2.68 1.05 4.08 1.37 0 2.78-.14 7.58-.33 12.91 0 0 0 .02-.01.03-.61 3.66-.79 7.42-1 11.12-.23 4.01-.43 8.03-.44 12.05 0 .64 0 1.28.03 1.93.02.31 0 .68.15.96.06.11.14.16.24.17-.2.17-.21.54.11.59 3.83.67 7.78.71 11.68.25 2.3-.19 4.87-.65 7.65-1.56 1.85-.54 3.67-1.18 5.43-1.91 7.2-3.02 14.31-8.07 17.35-15.53.76-1.86 1.17-3.8 1.31-5.75.3-1.93.28-3.82-.09-5.58l.01-.02Zm-19.32-15.42c5.74 1.41 11.94 3.68 15.65 8.55.25.32.47.65.69.99-2.3-2.82-5.68-5.69-12.88-8.23-2.16-.76-4.35-1.43-6.64-2.02 1.06.21 2.13.45 3.18.71Zm-25.82-3.04c.13 0 .27.01.4.02-.14.1-.26.23-.37.38 0-.13-.02-.26-.03-.4Zm34.82 22.17c-.75 3.09-3.55 5.66-5.88 7.58-3.35 2.76-7.21 5.03-11.28 6.54-1.33.49-2.71.9-4.12 1.15.06-1.38.08-2.76.07-4.13-.02-3.78-.16-7.56-.41-11.33-.09-1.37-.18-2.74-.37-4.1 0-.06-.03-.11-.06-.15.09-3.25.12-6.16.03-8.12 6.86 1.05 10.56 2.17 14.06 3.62 5.52 2.28 8.59 5.44 7.97 8.96l-.01-.02Zm-22 16.15c-.12 0-.23-.02-.34-.03l.34-.03v.06Zm-.69-.7c0-3.13.26-8.84.47-14.51.06 1.2.11 2.41.15 3.6.15 3.6.25 7.23.09 10.83-.24.03-.48.05-.71.07v.01Zm-12.33-30.94c.37.63 2.01 1.01 3.23 1.25v.15c-1.31-.31-2.59-.73-3.83-1.29.12-.36.23-.72.33-1.09.08.48.18.84.27.98Zm13.7 31.65v-.18c3.41-.56 6.71-2.02 9.69-3.68 2.31-1.28 4.59-2.78 6.63-4.53-4.69 4.53-11.61 8.24-16.33 8.38l.01.01Zm24.07-.75c-2.05 1.93-4.37 3.56-6.83 4.95 2.7-1.78 5.52-4.03 8.42-6.87.82-.82 1.56-1.69 2.23-2.59-1.08 1.65-2.38 3.16-3.81 4.51h-.01ZM187.16 92.14c-.79-2.47-2.1-7.12-3.1-6.87-.19-.01-2.09.77-4.08 1.54-3.06 1.18-5.91 2.13-10.09 2.82-2.74.42-5.87 1.01-10.61 1.06.04-3.34.05-6.01.05-7.99 7.97-.65 12.33-2.11 16.37-3.55 1.11-.39 2.69-1.01 2.63-1.8-.08-.35-.55-1.39-1.17-2.61-.47-1.16-.98-2.31-1.61-3.38-.42-.71-1.04-1.69-1.86-2.06-.11-.08-.22-.13-.29-.12-.02 0-.04 0-.07.01-.19-.04-.39-.05-.6-.01-.17.03-.24.15-.25.28-.04.02-.09.04-.14.05-4.33 1.48-8.85 2.33-13.24 3.61a499.1 499.1 0 0 0-.31-8.19c4.51-.99 8.88-1.38 13.11-1.82 3.68-.38 6.28.12 7.47.34.59.11.9.16 1.16.18h.1c-.1.37.44.66.62.28.02-.04.03-.08.05-.13.15.2.53.22.62-.1.17-.58.19-1.21.21-1.81v-.36c.03-.15.05-.3.07-.45.52-2.47.33-5.09-.64-7.44-.11-.27-.44-.28-.6-.14-.08-.21-.15-.42-.24-.62-.19-.41-.79-.05-.6.35.03.07.05.15.09.22-.98-.42-2.15-.54-3.17-.63-2.17-.19-4.37-.14-6.54 0-5.7.35-11.4 1.3-16.91 2.79-2.08.56-4.13 1.22-6.14 2-4.54 1.05-3.79 1.51-2.17 6.07.18.51.46 1.68.54 1.94.82 2.47 1.08 2.13 3.1 2.13s0 .05 0 .08h.52c-.48 2.66-.51 5.45-.62 8.13-.15 3.48-.22 6.96-.28 10.45 0 .41-.01.82-.02 1.23-.16.29-.33.57-.51.85-.05.38-.09.77-.14 1.18-.42 3.52-.59 6.48-.52 8.8v.34c.02.47.05.76.06.87.16 1.57-.26 3.47 1.35 3.79 1.61.32 3.5.55 4.85.55.11 0 .22-.02.33-.02 1.79.24 3.67.05 5.45-.12 2.85-.28 5.69-.7 8.51-1.19 3.03-.53 6.05-1.14 9.04-1.86 2.4-.58 4.82-1.19 7.13-2.06.51-.19 1.73-.57 2.46-1.14 1.81-.68 2.18-1 1.57-2.67-.23-.62-.48-1.49-.91-2.78l-.03-.02Zm-11.12-38.71c.89.05 1.93.08 2.89.3-.33 0-.68-.02-1.06-.03-8.28-.26-14.88.75-23.97 2.51 2.41-.64 4.85-1.16 7.28-1.59 4.87-.86 9.91-1.45 14.86-1.19Zm-26.53 22.13c.03 1.71.04 3.43 0 5.14-.04 1.27-.11 2.55-.24 3.82 0-.73.02-1.46.04-2.19.05-2.26.12-4.51.22-6.77h-.02Zm6.73 27.85c.2-.1.4-.21.58-.33 1.82-.17 3.82-.24 5.94-.34-.86.11-1.72.24-2.58.33-1.27.14-2.61.31-3.93.34h-.01ZM534.48 85.44c-3.52-8.38-7.07-16.75-10.5-25.17-.63-1.54-1.25-3.09-1.86-4.65-.31-.8-.65-1.6-.87-2.43-.04-.17-.17-.24-.31-.25.1-.2 0-.51-.29-.53-1.59-.08-3.18-.22-4.78-.25-1.96-.03-3.91.13-5.84.42-.31.05-.31.38-.13.56-.03.06-.05.14-.04.22.23 1.54.63 3.06 1.16 4.53.13.35.27.7.41 1.06l-2.68 6.18c-.11.03-.2.09-.25.22-.67 1.9-1.52 3.73-2.34 5.56a536.85 536.85 0 0 1-3.9 8.45c-2.64 5.64-5.34 11.25-7.91 16.93-.44.97-.88 1.94-1.29 2.93-.2.48-.47 1-.55 1.52v.05c-.02.12.02.26.16.34 1.19.73 2.41 1.41 3.66 2.05 1.2.62 2.45 1.25 3.76 1.61.43.12.62-.55.19-.67-1.13-.31-2.2-.83-3.24-1.36 1.09.36 2.1.69 2.75.93 2.82 1.01 2.38 1.1 4.3-3.75 2.1-1.09 4.34-1.96 6.53-2.79 4.35-1.64 8.8-3.03 13.27-4.29.82 2.01 1.77 3.97 2.72 5.92.35.83.62 1.45.79 1.82.22.42.45.8.69 1.15.17.33.33.67.5 1 .42.8.84 1.63 1.4 2.35.23.29.6 0 .55-.31 1.53-.02 3.06-.07 4.58-.27.92-.12 1.82-.32 2.71-.54 1.39-.27 3.85-1.11 3.74-1.42-.67-1.96-1.55-3.87-2.34-5.78-1.57-3.78-3.16-7.56-4.75-11.33v-.01Zm-11.65-26.16c1.54 3.81 3.12 7.6 4.7 11.4 2.94 7.05 5.91 14.09 8.87 21.13l-1.06-2.17c-2.71-5.51-5.2-11.19-7.41-16.87l-6.65-17.15c-.65-1.45-.55-2.19-.93-2.53.09 0 .18.01.28.02a.29.29 0 0 0-.04.26c.52 2.02 1.47 3.98 2.25 5.91h-.01Zm-6.58 13.58c.05-.15.09-.31.14-.46 1.41 3.92 2.88 7.9 4.39 11.87-3.22.52-6.38 1.25-9.46 2.14.55-1.22 1.05-2.46 1.53-3.7 1.24-3.24 2.37-6.53 3.39-9.85h.01Zm-.23-20c.36 0 .73.03 1.09.05-2.15.1-5.18.33-5.87.74-.24.15-.41.3-.53.45-.06-.29-.13-.58-.18-.88 1.82-.26 3.65-.39 5.49-.35v-.01Zm-.09 18.72c-.49 1.67-1.05 3.33-1.6 4.97-1.07 3.19-2.19 6.38-3.57 9.46-.09.21-.19.43-.29.65-.25.07-.5.14-.74.22 2.53-6.16 4.61-11.29 6.2-15.3Zm-6.34 25.16c4.97-2.38 9.37-4.1 14.02-5.27l.26.64c-4.8 1.35-9.63 2.8-14.28 4.63Zm20.17 6.76c.33.23.68.42 1.04.56h-.33c-.12 0-.21.06-.26.13-.15-.23-.31-.45-.45-.7v.01ZM226.57 91.75c-3.55-4.74-6.68-9.11-9.31-12.99 9.2-15.25 10.05-17.81 10.35-18.38.17-.34 1.09-2.27.64-2.53-1.13-.65-1.03-.65-2.97-1.71-1.19-.65-3.04-1.61-4.53-2.12-1.71-.59-1.24-.36-3 2.77-.06.1-.11.2-.17.3-.75 1.02-1.48 2.05-2.2 3.09-1.88 2.71-3.73 5.45-5.69 8.1-3.68-4.91-6.88-8.76-9.51-11.43-.15-.15-.3-.29-.46-.42-1.27-1.28-7.24 3.53-7.93 5.58-.09.09-.19.16-.28.25-.27.26.03.64.33.58.19.65.5 1.29.94 1.91 3.85 5.06 7.19 9.76 9.94 14-1.23 2.61-3.06 5-4.67 7.38l-2.28 3.33c-.5.66-.93 1.23-1.29 1.69-.67.93-2.09 2.61-2.3 3.87-.51.85-1.16 1.84-1.29 2.83-.06.44.61.63.67.19.01-.08.04-.15.06-.22 1.36 1.08 2.76 2.11 4.19 3.11 1.3.91 2.62 1.85 4.04 2.56.21.1.4 0 .48-.17.24.07.48.14.72.2.44.1.62-.57.19-.67-2.02-.48-3.77-1.57-5.23-3.02-.47-.46-.9-.96-1.32-1.46 1.74 1.35 4.2 2.89 5.89 4.14 1.39 1.03 2.85-2.27 4.22-4.2 1.86-2.64 3.96-5.86 5.52-8.29l10.39 14.51c.67.81 1.14 1.21 1.57 1.36-.05.24.12.51.41.4 1.53-.58 3.05-1.19 4.54-1.87 1.52-.69 3.06-1.45 4.36-2.5a.28.28 0 0 0 .12-.23c1.66-1.1.81-1.74-1.41-4.91-1.13-1.58-1.71-2.36-3.7-5.01l-.03-.02Zm2.41 6.54c.56 1.15 1.19 2.52 1.11 3.81-.06.04-.12.07-.17.1-.03-.88-.55-2.66-.94-3.91Zm-16.51-32.73c1.86-2.65 3.65-5.35 5.57-7.95.4-.55.81-1.13 1.26-1.66.19-.18.38-.33.56-.45.18.03.36.08.55.13l-8.05 10.11.12-.18h-.01ZM192.7 95.48c.79-1.37 1.66-2.69 2.54-4 1.19-1.79 2.4-3.56 3.61-5.33-.04.09-.09.17-.13.26-.1.22.03.41.2.49-2.47 3.42-4.89 6.73-6.4 9.28.21.24.4.48.63.75-.24.07-.4.36-.17.56.4.33.72.77 1.05 1.17.09.11.18.21.27.32-.84-.61-1.66-1.24-2.47-1.88.24-.57.58-1.11.87-1.61v-.01Zm7.46-10.32c.47-.81.98-1.59 1.49-2.37.31-.48.64-.95.96-1.43.26-.29.52-.56.75-.79-.99 1.48-2.09 3.03-3.2 4.59Zm10.03-16.22s-.03-.05-.05-.07c.22-.29.43-.59.64-.89-.2.32-.4.65-.58.96h-.01ZM371.54 87.96c-.01-.08-.01-.16-.03-.23-.06-.38-.58-.29-.66.03-.3-.05-.6-.08-.81-.11-1.14-.15-2.29-.19-3.44-.2 1.04-.09 2.09-.18 3.14-.23.45-.02.45-.72 0-.7-6.57.35-13.14 1.23-19.65 2.11-1.53.21-3.05.42-4.57.68-.01 0-.02.01-.04.01-.04-3.33-.13-6.66-.24-9.99-.19-5.7-.4-11.41-.88-17.1-.13-1.51-.23-3.07-.49-4.58 0-.25 0-.48-.02-.68-.06-1.19-.04-2.61-.68-2.78-.16-.07-.72-.16-1.5-.24.22-.17.16-.62-.2-.63-1.19-.04-2.39.09-3.57.23-1.2.14-2.41.32-3.59.6-.16-.1-.41-.06-.5.12-.06.02-.13.03-.19.05-.35.1-.29.55-.03.66-.26.6-.19 2.27-.21 3-.02.66-.66 33.73-.9 40.3-.03.65.06 1.12.04 1.45-.16 3.05.87 4.96 6.34 3.93 1.09-.08 2.75-.77 5.36-1.43 4.13-1.04 5.78-1.52 6.2-1.65 6.43-1.69 6.78-1.97 11.72-2.43.55-.05 4.8-.38 6.03-.3.64.04 1.19.07 1.65.1.09 0 .16-.03.24-.05.1.27.56.33.66-.02.39-1.32.61-2.71.78-4.08.2-1.61.29-3.24.15-4.86.24.03.52-.23.38-.53-.09-.2-.27-.33-.49-.43v-.02Zm-.63.56c.07.57.11 1.14.11 1.71-.21-.99-.53-1.71-.95-1.87.22.03.44.06.65.11.06.01.12.04.19.05Zm-25.41 1.73c1.54-.36 3.1-.64 4.66-.89-1.61.37-3.18.77-4.66 1.2v-.31Zm-.86-7.37c-.07-1.37-.16-2.75-.25-4.12-.21-3.13-.45-6.27-.79-9.4.02-2.25.08-4.31.13-6.11.16 2.08.29 4.16.4 6.24.23 4.46.38 8.93.5 13.39h.01Zm-.94-4c.16 2.41.29 4.83.39 7.24.06 1.6.14 3.22.09 4.83-.15.05-.32.09-.47.14V78.88h-.01ZM483.72 92.83c-3.05-2.28-6.22-4.4-9.38-6.51 8.86-6.49 13.49-12.95 13.73-19.23.04-.76 0-1.5-.13-2.2-.67-3.82-3.5-6.68-8.39-8.48.13.04.27.08.4.13 3.92 1.39 7.74 4.23 8.5 8.56.34 1.95-.05 3.96-.98 5.69-.21.4.39.75.6.35 1.86-3.46 1.46-7.55-.97-10.63-3.53-4.47-9.76-5.88-15.16-6.16-2.32-.12-4.64-.04-6.95.19-6 .32-12.71 1.68-17.63 3.21-.37.11-.67.23-.92.35-.2-.17-.62.02-.57.37v.03c-.64.68-.18 1.64.48 3.21.38.91.67 1.89 1.15 2.58.32.76.68 1.51 1.13 2.19.14.21.38.19.53.07.19-.02.38-.05.57-.08v1.57c-.06.06-.1.13-.11.23-.27 4.18-.34 8.38-.48 12.57l-.3 9.03c-.24 3.91-.44 6.77-.46 7.26-.05.88-.11 1.95.07 2.81-.01.22-.02.43-.04.65 0 .11-.02.23-.03.35 0 .05-.03.27-.01.16-.05.4.5.59.64.28.05.04.12.08.2.08 1.75.13 3.5.28 5.25.3 1.69.02 3.38-.12 5.06-.32.08.23.36.39.55.15.06-.08.11-.17.16-.26.18-.09.24-.32.18-.48.05-.2.1-.4.13-.6.16-.86.25-1.74.33-2.62.11-1.17.17-2.34.23-3.51.15-.01.32-.03.52-.04.36-.03 1.73-.15 2.06-.15.39 0 .7-.02.95-.04 1.76 1.11 3.45 2.35 5.14 3.55 2.83 2.01 5.64 4.04 8.47 6.04 1.42 1 2.85 2 4.29 2.97.1.06.19.07.27.04.08 0 .17-.02.25-.1 1.61-1.56 3.15-3.18 4.6-4.88.75-.88 1.49-1.78 2.15-2.73.01.01.03.02.04.03.34.3.83-.2.49-.49-2.16-1.9-4.34-3.76-6.64-5.48l.03-.01Zm-6.38-3.65a55.72 55.72 0 0 0-4-2.13c.14-.1.26-.19.4-.29 1.2.81 2.4 1.61 3.6 2.42Zm-20.1 11.78c.67-.37 1.23-.91 1.67-1.6-.11.5-.24 1-.38 1.49-.43.04-.86.08-1.29.11Zm2.38-37.24c1.34-.31 2.56-.52 3.71-.69-1.03.19-2.04.41-3.04.65-.14-.07-.34-.02-.45.11-.07.02-.15.04-.22.05v-.13.01Zm.04.84c.07-.02.14-.03.2-.05.34 1.66.41 3.41.5 5.09.17 2.9.24 5.81.28 8.71l.03 3.17c-.17.07-.34.14-.51.2-.06-4.96-.21-10.58-.51-17.12h.01Zm16.04 5.62c-1.16 2.25-3.06 4.1-5.02 5.66-2.8 2.23-5.99 3.97-9.3 5.35-.01-3.56-.09-7.12-.27-10.67-.1-2.04-.16-4.16-.57-6.18 3.3-.78 6.72-1.36 10.1-1.1 1.85.14 4.23.59 5.32 2.29.92 1.43.46 3.24-.26 4.65Zm.85-.18c.6-1.37.9-2.92.28-4.32-.67-1.52-2.2-2.32-3.76-2.74.46.1.89.21 1.29.37 1.74.67 2.69 1.88 2.93 3.21.2 1.13-.05 2.25-.74 3.47V70Zm-27.47-4.14c-.12-.19-.23-.38-.34-.57.74.42.85.36.99.41v.08c-.22.03-.43.06-.65.08Zm11.21 30.46c-.08 1.08-.16 2.17-.33 3.24-.05.35-.11.69-.2 1.03 0 .04-.02.07-.03.11-.15.02-.3.04-.45.05.45-1.64.76-3.36.79-5.07.03-.29.08-.57.1-.89-.03-.31-.03-.47.24-.57-.04.69-.07 1.39-.12 2.08v.02Zm5.6-2.47c.48.11.92.52 2.49 1.72-.46-.32-.92-.65-1.38-.97-.37-.25-.73-.5-1.1-.75h-.01Zm21.23 7.24a70.76 70.76 0 0 1-4.37 4.63c-.14-.09-.27-.19-.4-.28.19-.09.37-.24.55-.47.87-1.14 5.43-5.51 5.49-7.45.31.26.62.53.92.79-.67.97-1.42 1.88-2.19 2.77v.01Z",fill:"currentColor",transform:"translate(-144.023 -51.76)"})]}),V6=({style:e,size:t="small",withText:o})=>K6("div",{className:`ExcalidrawLogo is-${t}`,style:e,children:[Fa(HJ,{}),o&&Fa(GJ,{})]});import{Fragment as j6,jsx as Ct,jsxs as Ey}from"react/jsx-runtime";var wy=({icon:e,shortcut:t,children:o})=>{let n=Te();return Ey(j6,{children:[Ct("div",{className:"welcome-screen-menu-item__icon",children:e}),Ct("div",{className:"welcome-screen-menu-item__text",children:o}),t&&n.formFactor!=="phone"&&Ct("div",{className:"welcome-screen-menu-item__shortcut",children:t})]})};wy.displayName="WelcomeScreenMenuItemContent";var Kd=({onSelect:e,children:t,icon:o,shortcut:n,className:r="",...a})=>Ct("button",{...a,type:"button",className:`welcome-screen-menu-item ${r}`,onClick:e,children:Ct(wy,{icon:o,shortcut:n,children:t})});Kd.displayName="WelcomeScreenMenuItem";var X6=({children:e,href:t,icon:o,shortcut:n,className:r="",...a})=>Ct("a",{...a,className:`welcome-screen-menu-item ${r}`,href:t,target:"_blank",rel:"noopener",children:Ct(wy,{icon:o,shortcut:n,children:e})});X6.displayName="WelcomeScreenMenuItemLink";var dn=({children:e})=>{let{WelcomeScreenCenterTunnel:t}=Ze();return Ct(t.In,{children:Ct("div",{className:"welcome-screen-center",children:e||Ey(j6,{children:[Ct(vy,{}),Ct(Iy,{children:f("welcomeScreen.defaults.center_heading")}),Ey(Ty,{children:[Ct(ky,{}),Ct(Cy,{})]})]})})})};dn.displayName="Center";var vy=({children:e})=>Ct("div",{className:"welcome-screen-center__logo excalifont welcome-screen-decor",children:e||Ct(V6,{withText:!0})});vy.displayName="Logo";var Iy=({children:e})=>Ct("div",{className:"welcome-screen-center__heading welcome-screen-decor excalifont",children:e});Iy.displayName="Heading";var Ty=({children:e})=>Ct("div",{className:"welcome-screen-menu",children:e});Ty.displayName="Menu";var Cy=()=>{let e=at();return Ct(Kd,{onSelect:()=>e.executeAction(oi),shortcut:"?",icon:ns,children:f("helpDialog.title")})};Cy.displayName="MenuItemHelp";var ky=()=>{let e=Ie(),t=at();return e.viewModeEnabled?null:Ct(Kd,{onSelect:()=>t.executeAction(_s),shortcut:Xe("loadScene"),icon:rs,children:f("buttons.load")})};ky.displayName="MenuItemLoadScene";var Z6=({onSelect:e})=>{let{t}=Ue();return Ct(Kd,{shortcut:null,onSelect:e,icon:Em,children:t("labels.liveCollaboration")})};Z6.displayName="MenuItemLiveCollaborationTrigger";dn.Logo=vy;dn.Heading=Iy;dn.Menu=Ty;dn.MenuItem=Kd;dn.MenuItemLink=X6;dn.MenuItemHelp=Cy;dn.MenuItemLoadScene=ky;dn.MenuItemLiveCollaborationTrigger=Z6;import{jsx as Hl,jsxs as Sy}from"react/jsx-runtime";var Yg=({children:e})=>{let{WelcomeScreenMenuHintTunnel:t}=Ze();return Hl(t.In,{children:Sy("div",{className:"excalifont welcome-screen-decor welcome-screen-decor-hint welcome-screen-decor-hint--menu",children:[DE,Hl("div",{className:"welcome-screen-decor-hint__label",children:e||f("welcomeScreen.defaults.menuHint")})]})})};Yg.displayName="MenuHint";var $g=({children:e})=>{let{WelcomeScreenToolbarHintTunnel:t}=Ze();return Hl(t.In,{children:Sy("div",{className:"excalifont welcome-screen-decor welcome-screen-decor-hint welcome-screen-decor-hint--toolbar",children:[Hl("div",{className:"welcome-screen-decor-hint__label",children:e||f("welcomeScreen.defaults.toolbarHint")}),NE]})})};$g.displayName="ToolbarHint";var Vg=({children:e})=>{let{WelcomeScreenHelpHintTunnel:t}=Ze();return Hl(t.In,{children:Sy("div",{className:"excalifont welcome-screen-decor welcome-screen-decor-hint welcome-screen-decor-hint--help",children:[Hl("div",{children:e||f("welcomeScreen.defaults.helpHint")}),RE]})})};Vg.displayName="HelpHint";import{Fragment as q6,jsx as Xd,jsxs as WJ}from"react/jsx-runtime";var Kg=e=>Xd(q6,{children:e.children||WJ(q6,{children:[Xd(dn,{}),Xd(Yg,{}),Xd($g,{}),Xd(Vg,{})]})});Kg.displayName="WelcomeScreen";Kg.Center=dn;Kg.Hints={MenuHint:Yg,ToolbarHint:$g,HelpHint:Vg};var UJ=Kg;var YJ=()=>{Array.prototype.at||Object.defineProperty(Array.prototype,"at",{value:function(e){if(e=Math.trunc(e)||0,e<0&&(e+=this.length),!(e<0||e>=this.length))return this[e]},writable:!0,enumerable:!1,configurable:!0}),Element.prototype.replaceChildren||(Element.prototype.replaceChildren=function(...e){this.innerHTML="",this.append(...e)})},J6=YJ;import{getSceneVersion as Xqe,hashElementsVersion as Zqe,hashString as jqe,getNonDeletedElements as qqe}from"@orangecatai/element";import{getTextFromElements as Qqe}from"@orangecatai/element";import{isInvisiblySmallElement as tJe}from"@orangecatai/element";import $J from"lodash.throttle";import{arrayToMap as VJ,isDevEnv as Q6,isTestEnv as eA}from"@orangecatai/common";import{orderByFractionalIndex as KJ,syncInvalidIndices as tA,validateFractionalIndices as XJ}from"@orangecatai/element";var ZJ=(e,t,o)=>!!(t&&(t.id===e.editingTextElement?.id||t.id===e.resizingElement?.id||t.id===e.newElement?.id||t.version>o.version||t.version===o.version&&t.versionNonce<=o.versionNonce)),jJ=$J((e,t,o)=>{if(Q6()||eA()||window?.DEBUG_FRACTIONAL_INDICES){let n=tA(e.map(r=>({...r})));XJ(n,{shouldThrow:eA()||Q6(),includeBoundTextValidation:!0,reconciliationContext:{localElements:t,remoteElements:o}})}},1e3*60,{leading:!0,trailing:!1}),qJ=(e,t,o)=>{let n=VJ(e),r=[],a=new Set;for(let s of t)if(!a.has(s.id)){let l=n.get(s.id),c=ZJ(o,l,s);l&&c?(r.push(l),a.add(l.id)):(r.push(s),a.add(s.id))}for(let s of e)a.has(s.id)||(r.push(s),a.add(s.id));let i=KJ(r);return jJ(i,e,t),tA(i),i};import{isLinearElement as dJe}from"@orangecatai/element";import{FONT_FAMILY as pJe,THEME as gM,MIME_TYPES as uJe,ROUNDNESS as Cp,DEFAULT_LASER_COLOR as gJe,UserIdleState as hJe,normalizeLink as fJe,sceneCoordsToViewportCoords as CT,viewportCoordsToSceneCoords as bJe,getFormFactor as xJe}from"@orangecatai/common";import{mutateElement as Sp,newElementWith as EJe,bumpVersion as Us}from"@orangecatai/element";import{CaptureUpdateAction as vJe}from"@orangecatai/element";import{jsx as My}from"react/jsx-runtime";var oA=({children:e,icon:t})=>{let{t:o}=Ue(),{TTDDialogTriggerTunnel:n}=Ze(),r=Ce();return My(n.In,{children:My(ye.Item,{onSelect:()=>{be("ai","dialog open","ttd"),r({openDialog:{name:"ttd",tab:"text-to-diagram"}})},icon:t??Kw,badge:My(ye.Item.Badge,{children:"AI"}),children:e??o("labels.textToDiagram")})})};oA.displayName="TTDDialogTrigger";function JJ(e){let t=e.get("X-Ratelimit-Limit"),o=e.get("X-Ratelimit-Remaining");return{rateLimit:t?parseInt(t,10):void 0,rateLimitRemaining:o?parseInt(o,10):void 0}}async function*Py(e){let t=new TextDecoder,o="";try{for(;;){let{done:n,value:r}=await e.read();if(n)break;o+=t.decode(r,{stream:!0});let a=o.split(`
|
|
313
313
|
`);o=a.pop()||"";for(let i of a){let s=i.trim();s&&s.startsWith("data: ")&&(yield s.slice(6))}}}finally{e.releaseLock()}}async function QJ(e){let{url:t,messages:o,onChunk:n,onStreamCreated:r,extractRateLimits:a=!0,signal:i}=e;try{let s="",l={},c=null,m=await fetch(t,{method:"POST",headers:{Accept:"text/event-stream","Content-Type":"application/json"},body:JSON.stringify({messages:o}),signal:i});if(a&&(l=JJ(m.headers)),!m.ok){if(m.status===429)return{...l,error:new Dn({message:"Rate limit exceeded",status:429})};let d=await m.text();throw new Dn({message:d||"Generation failed...",status:m.status})}let p=m.body?.getReader();if(!p)throw new Dn({message:"Couldn't get reader from response body",status:500});r?.();try{for await(let d of Py(p)){if(d==="[DONE]")break;try{let u=JSON.parse(d);if(u===null)break;switch(u.type){case"content":{let h=u.delta;h&&(s+=h,n?.(h));break}case"error":c=new Dn({message:u.error.message,status:500});break;case"done":break}}catch(u){console.warn("Failed to parse SSE data:",d,u)}}}catch(d){d.name==="AbortError"?c=new Dn({message:"Request aborted",status:499}):c=new Dn({message:d.message||"Streaming error",status:500})}return c?{...l,error:c}:s?{generatedResponse:s,error:null,...l}:{...l,error:new Dn({message:"Generation failed...",status:m.status})}}catch(s){return s.name==="AbortError"?{error:new Dn({message:"Request aborted",status:499})}:{error:new Dn({message:s.message||"Request failed",status:500})}}}import{getCommonBounds as NJe,getVisibleSceneBounds as BJe,convertToExcalidrawElements as hM}from"@orangecatai/element";import{useLayoutEffect as eQ}from"react";var tQ=e=>{let t=tt();return eQ(()=>{t.setPlugins({diagramToCode:{generate:e.generate}})},[t,e.generate]),null};import{isElementLink as GJe}from"@orangecatai/element";import{setCustomTextMetricsProvider as WJe}from"@orangecatai/element";import qQ,{useCallback as Co,useEffect as Wy,useImperativeHandle as JQ,useMemo as QQ,useRef as Fo,useState as xt}from"react";import{ArrowUp as eee,AtSign as _A,Check as DA,ChevronDown as tee,ChevronRight as FA,Copy as RA,Globe as oee,MessageSquare as NA,Mic as nee,MicOff as ree,Paperclip as Yy,Plus as BA,Search as aee,Wrench as iee,X as $y}from"lucide-react";import{nanoid as Ly}from"nanoid";import{newFrameElement as oQ,newElement as Zg,newTextElement as nA,newImageElement as _y,getFrameChildren as Gl,isFrameLikeElement as Dy,syncMovedIndices as _i,wrapText as nQ,measureText as rQ}from"@orangecatai/element";import{FRAME_STYLE as aQ,arrayToMap as Di,getFontString as iQ}from"@orangecatai/common";var rA=[{type:"function",function:{name:"create_frame",description:"Create a new frame on the canvas. Frames act as artboards that clip their children. Default size is 512x512.",parameters:{type:"object",properties:{width:{type:"number",description:"Frame width in pixels (default 512)"},height:{type:"number",description:"Frame height in pixels (default 512)"},name:{type:"string",description:"Optional display name for the frame"}},required:[],additionalProperties:!1}}},{type:"function",function:{name:"add_rectangle",description:"Add a filled rectangle inside a frame. Commonly used for solid background fills behind images and text.",parameters:{type:"object",properties:{frameId:{type:"string",description:"ID of the parent frame"},x:{type:"number",description:"X position relative to canvas (use the frame's x for full coverage)"},y:{type:"number",description:"Y position relative to canvas (use the frame's y for full coverage)"},width:{type:"number",description:"Rectangle width in pixels"},height:{type:"number",description:"Rectangle height in pixels"},backgroundColor:{type:"string",description:'Fill color as hex string e.g. "#1a1a2e". Use "transparent" for no fill.'},fillStyle:{type:"string",enum:["solid","hachure","cross-hatch"],description:'Fill style (default "solid")'},strokeColor:{type:"string",description:'Stroke/border color as hex (default "transparent")'},strokeWidth:{type:"number",description:"Stroke width in pixels (default 0)"},opacity:{type:"number",description:"Opacity 0-100 (default 100)"}},required:["frameId","x","y","width","height","backgroundColor"],additionalProperties:!1}}},{type:"function",function:{name:"add_text",description:"Add a text element inside a frame. Use for headlines, subheads, body copy, CTAs etc.",parameters:{type:"object",properties:{frameId:{type:"string",description:"ID of the parent frame"},x:{type:"number",description:"X position (canvas coordinates)"},y:{type:"number",description:"Y position (canvas coordinates)"},text:{type:"string",description:"The text content"},fontSize:{type:"number",description:"Font size in pixels (default 20)"},fontFamily:{type:"number",enum:[1,2,3,4,5],description:"Font family: 1=Excalifont(hand), 2=Nunito(sans), 3=Comic Shanns(code), 4=Liberation Sans(clean sans), 5=Cascadia(code). Default 2."},strokeColor:{type:"string",description:'Text color as hex string (default "#000000")'},textAlign:{type:"string",enum:["left","center","right"],description:"Horizontal alignment (default left)"},width:{type:"number",description:"Optional fixed width for text wrapping"}},required:["frameId","x","y","text"],additionalProperties:!1}}},{type:"function",function:{name:"generate_image",description:"Generate an image using AI (Gemini) from a text prompt and place it inside a frame. Use for hero images, product shots, backgrounds, illustrations etc.",parameters:{type:"object",properties:{frameId:{type:"string",description:"ID of the parent frame to insert the image into"},prompt:{type:"string",description:"Detailed image generation prompt describing what to create"},x:{type:"number",description:"X position for the image (canvas coordinates)"},y:{type:"number",description:"Y position for the image (canvas coordinates)"},width:{type:"number",description:"Image width in pixels"},height:{type:"number",description:"Image height in pixels"}},required:["frameId","prompt","x","y","width","height"],additionalProperties:!1}}},{type:"function",function:{name:"update_element",description:"Update properties of an existing element (move, resize, recolor, change text, etc.)",parameters:{type:"object",properties:{elementId:{type:"string",description:"ID of the element to update"},x:{type:"number",description:"New X position"},y:{type:"number",description:"New Y position"},width:{type:"number",description:"New width"},height:{type:"number",description:"New height"},backgroundColor:{type:"string",description:"New background/fill color"},strokeColor:{type:"string",description:"New stroke/text color"},opacity:{type:"number",description:"New opacity 0-100"},fontSize:{type:"number",description:"New font size (text elements only)"},text:{type:"string",description:"New text content (text elements only)"},fillStyle:{type:"string",enum:["solid","hachure","cross-hatch"],description:"New fill style"}},required:["elementId"],additionalProperties:!1}}},{type:"function",function:{name:"delete_element",description:"Delete an element from the canvas",parameters:{type:"object",properties:{elementId:{type:"string",description:"ID of the element to delete"}},required:["elementId"],additionalProperties:!1}}},{type:"function",function:{name:"get_frame_elements",description:"Get all child elements inside a frame. Returns their IDs, types, positions, sizes, colors, and text content. Use this to understand the current layout before making changes.",parameters:{type:"object",properties:{frameId:{type:"string",description:"ID of the frame to inspect"}},required:["frameId"],additionalProperties:!1}}}];var aA=[{type:"function",function:{name:"create_frame",description:"Create a new frame on the canvas to act as the root container for your banner. Default size is 512x512. ALWAYS call this FIRST before generating images or HTML.",parameters:{type:"object",properties:{width:{type:"number",description:"Frame width in pixels (default 512)"},height:{type:"number",description:"Frame height in pixels (default 512)"},name:{type:"string",description:"Optional display name for the frame"}},required:[],additionalProperties:!1}}},{type:"function",function:{name:"generate_image",description:"Generate an image using AI (Gemini) and place it onto the canvas. Always call this for any photo or image content \u2014 even when the user has attached a reference image. The attached image is passed to Gemini as visual reference; Gemini generates the final output. Use referenceImageIndex to tell Gemini which user attachment to reference. IMPORTANT: your prompt must describe a purely visual scene \u2014 NO text, NO typography, NO words, NO captions, NO watermarks. All copy is handled by the HTML layer. A 'no text' safety suffix will be auto-appended, but you must also describe composition clearly (e.g. which side should be left open/empty for the HTML text).",parameters:{type:"object",properties:{frameId:{type:"string",description:"ID of the parent frame to insert the image into"},prompt:{type:"string",description:"Detailed generation prompt. When using a reference image, describe what you want Gemini to produce \u2014 e.g. 'use this building as the subject, wide cinematic crop with open sky on the left for text overlay'."},x:{type:"number",description:"X position relative to the frame's top-left corner"},y:{type:"number",description:"Y position relative to the frame's top-left corner"},width:{type:"number",description:"Image width in pixels"},height:{type:"number",description:"Image height in pixels"},referenceImageIndex:{type:"number",description:"0-based index of the user's attached image to pass to Gemini as reference. Always use 0 when the user has attached an image."}},required:["frameId","prompt","x","y","width","height"],additionalProperties:!1}}},{type:"function",function:{name:"generate_html_banner",description:"Place HTML/CSS text and shape elements into an EXISTING frame on the canvas. Always call create_frame first to get a frameId, then generate_image, then call this with that frameId. frameId is required \u2014 this tool does NOT create frames.",parameters:{type:"object",properties:{html:{type:"string",description:"Complete self-contained HTML with inline <style>. All layer elements must use position:absolute with explicit left/top/width/height in px. Root div must have class='canvas'."},frameId:{type:"string",description:"Required. The ID of the frame created by create_frame. Adds HTML elements into this existing frame, preserving existing children like images."}},required:["html","frameId"],additionalProperties:!1}}},{type:"function",function:{name:"get_frame_elements",description:"Get all child elements inside a frame. Use when editing an existing banner to understand its current state before replacing.",parameters:{type:"object",properties:{frameId:{type:"string",description:"ID of the frame to inspect"}},required:["frameId"],additionalProperties:!1}}},{type:"function",function:{name:"update_element",description:"Update properties of an existing element. Use for minor targeted fixes after the banner is placed.",parameters:{type:"object",properties:{elementId:{type:"string"},x:{type:"number"},y:{type:"number"},width:{type:"number"},height:{type:"number"},backgroundColor:{type:"string"},strokeColor:{type:"string"},opacity:{type:"number"},fontSize:{type:"number"},text:{type:"string"},fillStyle:{type:"string",enum:["solid","hachure","cross-hatch"]}},required:["elementId"],additionalProperties:!1}}},{type:"function",function:{name:"delete_element",description:"Delete an element from the canvas.",parameters:{type:"object",properties:{elementId:{type:"string",description:"ID of the element to delete"}},required:["elementId"],additionalProperties:!1}}},{type:"function",function:{name:"search_brand_assets",description:"Search the brand asset bank for existing product shots, logos, and lifestyle images. ALWAYS call this before generate_image to check if a brand asset already exists.",parameters:{type:"object",properties:{query:{type:"string",description:"Search query \u2014 name or tag keywords"},type:{type:"string",enum:["product","logo","lifestyle","auxiliary"],description:"Optional filter by asset type"}},required:["query"],additionalProperties:!1}}},{type:"function",function:{name:"list_brand_templates",description:`List available brand templates by keyword search across template names, campaign tags, and labels.
|
|
314
314
|
|
|
315
315
|
MANDATORY SEARCH PROTOCOL \u2014 follow exactly, no shortcuts:
|
|
@@ -327,7 +327,7 @@ ONLY after both attempts return empty \u2192 tell the user no matching template
|
|
|
327
327
|
If no search context exists, call with an empty keywords array to list all templates.`,parameters:{type:"object",properties:{keywords:{type:"array",items:{type:"string"},description:"Up to 20 keyword variations to search across template names, campaign tags, and labels. All are OR-matched case-insensitively. Generate 10 tag synonyms + 10 name variations from the user's request."}},required:[],additionalProperties:!1}}},{type:"function",function:{name:"get_template_variant",description:"Fetch the full canvas JSON for a specific template by its ID.",parameters:{type:"object",properties:{variantId:{type:"string",description:"The template ID to fetch"}},required:["variantId"],additionalProperties:!1}}},{type:"function",function:{name:"load_template_into_frame",description:"Load a template into an existing frame, replacing its contents with the template elements.",parameters:{type:"object",properties:{frameId:{type:"string",description:"The frame ID to load the template into"},variantId:{type:"string",description:"The template ID to load (from list_brand_templates)"}},required:["frameId","variantId"],additionalProperties:!1}}},{type:"function",function:{name:"fill_template_slots",description:"Fill the slot elements inside a frame with content. Use this after load_template_into_frame to populate slots with actual content.",parameters:{type:"object",properties:{frameId:{type:"string",description:"The frame ID containing slot elements"},headline:{type:"string",description:"Text for the headline slot"},subhead:{type:"string",description:"Text for the subhead slot"},cta:{type:"string",description:"Text for the CTA slot"},signoff:{type:"string",description:"Text for the signoff slot"},product_image_url:{type:"string",description:"URL for the product image slot (from search_brand_assets blobUrl, or a generated image data URL)"},product_image_asset_id:{type:"string",description:"Asset ID for the product image (from search_brand_assets [id:...] field). Required when using a brand asset so the image can be swapped later."},logo_url:{type:"string",description:"URL for the logo slot (from search_brand_assets blobUrl)"},logo_asset_id:{type:"string",description:"Asset ID for the logo (from search_brand_assets [id:...] field). Required when using a brand asset."},auxiliary_image_url:{type:"string",description:"URL for the auxiliary image slot"},auxiliary_image_asset_id:{type:"string",description:"Asset ID for the auxiliary image (from search_brand_assets [id:...] field). Required when using a brand asset."},background_color:{type:"string",description:"Hex color (e.g. #000000) for the background slot"}},required:["frameId"],additionalProperties:!1}}},{type:"function",function:{name:"finalize_ad",description:"Call this when ALL elements are placed on the canvas \u2014 brand assets, generated images, and the HTML text overlay. Captures a screenshot of the complete frame for review. Do NOT call this before all assets are in place.",parameters:{type:"object",properties:{frameId:{type:"string",description:"ID of the frame to capture for review"}},required:["frameId"],additionalProperties:!1}}}];function Ry(e){let t={id:e.id,type:e.type,x:Math.round(e.x),y:Math.round(e.y),width:Math.round(e.width),height:Math.round(e.height)};if(e.backgroundColor&&e.backgroundColor!=="transparent"&&(t.backgroundColor=e.backgroundColor),e.strokeColor&&e.strokeColor!=="#1e1e1e"&&(t.strokeColor=e.strokeColor),e.opacity!==100&&(t.opacity=e.opacity),e.fillStyle&&e.fillStyle!=="solid"&&(t.fillStyle=e.fillStyle),e.type==="text"){let o=e;t.text=o.text,t.fontSize=o.fontSize,t.fontFamily=o.fontFamily,t.textAlign=o.textAlign}if(e.type==="image"&&(t.type="image"),e.type==="frame"){let o=e;o.name&&(t.name=o.name)}return t}function iA(e){return e.map(Ry)}function sA(e){let t=e.getSceneElements(),o=[];for(let n of t)if(Dy(n)){let r=Gl(t,n.id),a=n;o.push({id:n.id,name:a.name||`Frame ${Math.round(n.width)}\xD7${Math.round(n.height)}`,width:Math.round(n.width),height:Math.round(n.height),childCount:r.length})}return o}async function Ul(e,t){let o=e.getSceneElements(),n=o.find(s=>s.id===t);if(!n||!Dy(n))return null;let r=e.getAppState(),a=e.getFiles(),i=Gl(o,t);try{return(await zr([...i,n],r,a,{exportBackground:!0,viewBackgroundColor:r.viewBackgroundColor,exportingFrame:n,exportPadding:0})).toDataURL("image/jpeg",.7)}catch{return null}}function lA(e,t){let o=e.getSceneElements(),n=o.find(l=>l.id===t);if(!n||!Dy(n))return null;let r=Gl(o,t),a=n,i={id:n.id,name:a.name||`Frame ${Math.round(n.width)}\xD7${Math.round(n.height)}`,width:Math.round(n.width),height:Math.round(n.height),childCount:r.length},s={frame:Ry(n),children:iA(r)};return{serialized:JSON.stringify(s,null,2),frameInfo:i}}async function cA(e,t,o){let n;try{n=JSON.parse(t)}catch{return{success:!1,error:"Invalid JSON arguments",statusMessage:"Failed to parse tool arguments"}}switch(e){case"create_frame":return cQ(n,o);case"add_rectangle":return dQ(n,o);case"add_text":return mQ(n,o);case"generate_image":return pQ(n,o);case"update_element":return uQ(n,o);case"delete_element":return gQ(n,o);case"get_frame_elements":return hQ(n,o);case"generate_html_banner":return fQ(n,o);case"search_brand_assets":return bQ(n,o);case"list_brand_templates":return yQ(n,o);case"get_template_variant":return EQ(n,o);case"load_template_into_frame":return wQ(n,o);case"fill_template_slots":return TQ(n,o);case"finalize_ad":return xQ(n,o);default:return{success:!1,error:`Unknown tool: ${e}`,statusMessage:`Unknown tool: ${e}`}}}function sQ(e){let t=e.getAppState(),o=-t.scrollX+t.width/2/t.zoom.value,n=-t.scrollY+t.height/2/t.zoom.value;return{x:o,y:n}}var Xg=10;function lQ(e,t,o,n,r){return Math.abs(e-r.x)<Xg&&Math.abs(t-r.y)<Xg&&Math.abs(o-r.width)<Xg&&Math.abs(n-r.height)<Xg}function dA(e,t,o,n,r,a){return e==="text"?3:e==="image"?1:lQ(t,o,n,r,a)?0:2}function Ny(e,t,o){let n=e[t],r=n.id,a=t+1;for(let i=t+1;i<e.length;i++){let s=e[i];if(s.frameId!==r)continue;if(dA(s.type,s.x,s.y,s.width,s.height,n)>o)return i;a=i+1}return a}function cQ(e,t){let o=e.width||512,n=e.height||512,r=e.name||null,a=sQ(t.excalidrawAPI),i=oQ({...aQ,x:a.x-o/2,y:a.y-n/2,width:o,height:n,opacity:100,locked:!1,name:r??void 0}),l=[...t.excalidrawAPI.getSceneElements(),i];return _i(l,Di([i])),t.excalidrawAPI.updateScene({elements:l}),t.excalidrawAPI.scrollToContent(i,{fitToViewport:!1}),{success:!0,data:{frameId:i.id,x:Math.round(i.x),y:Math.round(i.y),width:o,height:n},statusMessage:`Created frame "${r||"Ad Frame"}" (${o}\xD7${n})`}}function dQ(e,t){let o=e.frameId;if(!o)return{success:!1,error:"frameId is required",statusMessage:"Failed: missing frameId"};let n=Zg({type:"rectangle",x:e.x,y:e.y,width:e.width,height:e.height,backgroundColor:e.backgroundColor||"transparent",fillStyle:e.fillStyle||"solid",strokeColor:e.strokeColor||"transparent",strokeWidth:e.strokeWidth??0,opacity:e.opacity??100,roughness:0}),r=t.excalidrawAPI.getSceneElements(),a=r.findIndex(d=>d.id===o);if(a===-1)return{success:!1,error:`Frame ${o} not found`,statusMessage:"Failed: frame not found"};let i=r[a],s=dA("rectangle",e.x,e.y,e.width,e.height,i),l={...n,frameId:o},c=[...r],m=Ny(c,a,s);c.splice(m,0,l),_i(c,Di([l])),t.excalidrawAPI.updateScene({elements:c});let p=s===0;return{success:!0,data:{elementId:n.id,type:"rectangle",x:Math.round(n.x),y:Math.round(n.y),width:Math.round(n.width),height:Math.round(n.height),backgroundColor:n.backgroundColor,isBackground:p},statusMessage:`Added ${p?"background ":""}rectangle (${Math.round(n.width)}\xD7${Math.round(n.height)}) with fill ${n.backgroundColor}`}}function mQ(e,t){let o=e.frameId;if(!o)return{success:!1,error:"frameId is required",statusMessage:"Failed: missing frameId"};let n=t.brandBodyFontId??t.brandHeadlineFontId??e.fontFamily??2,r=nA({x:e.x,y:e.y,text:e.text,fontSize:e.fontSize||20,fontFamily:n,strokeColor:e.strokeColor||"#000000",textAlign:e.textAlign||"left",width:e.width,roughness:0}),a=t.excalidrawAPI.getSceneElements(),i=a.findIndex(m=>m.id===o);if(i===-1)return{success:!1,error:`Frame ${o} not found`,statusMessage:"Failed: frame not found"};let s={...r,frameId:o},l=[...a],c=Ny(l,i,3);return l.splice(c,0,s),_i(l,Di([s])),t.excalidrawAPI.updateScene({elements:l}),{success:!0,data:{elementId:r.id,type:"text",x:Math.round(r.x),y:Math.round(r.y),text:e.text,fontSize:e.fontSize||20},statusMessage:`Added text "${e.text.slice(0,40)}${e.text.length>40?"\u2026":""}"`}}async function pQ(e,t){let o=e.frameId,n=e.prompt,r=e.x,a=e.y,i=e.width,s=e.height,l=e.referenceImageIndex,c=l!==void 0?t.fileAttachments?.[l]?.dataUrl:void 0,m=t.brandHeadlineFontName?` Brand typography: ${t.brandHeadlineFontName}.`:t.brandBodyFontName?` Brand typography: ${t.brandBodyFontName}.`:"",p=`${n}${m} \u2014 NO text, NO typography, NO words, NO captions, NO watermarks, NO overlaid copy. Pure clean visual image only.`;if(!o||!n)return{success:!1,error:"frameId and prompt are required",statusMessage:"Failed: missing required parameters"};if(!t.geminiApiKey)return{success:!1,error:"No Gemini API key configured. Set geminiApiKey prop or VITE_APP_GEMINI_API_KEY.",statusMessage:"Failed: no Gemini API key"};let d=t.excalidrawAPI.getSceneElements(),u=d.findIndex(w=>w.id===o);if(u===-1)return{success:!1,error:`Frame ${o} not found`,statusMessage:"Failed: frame not found"};let h=d[u],g=r<h.width&&a<h.height&&Math.abs(r-h.x)>50,x=g?h.x+r:r,E=g?h.y+a:a,y=i>=s?i/s>1.3?"16:9":"1:1":"9:16";try{let w=await yi(p,t.agentImageModel||"gemini-3.1-flash-image-preview",y,"1K",!1,!1,t.geminiApiKey,c,t.signal);if(t.signal?.aborted)return{success:!1,error:"Cancelled",statusMessage:"Image generation cancelled"};let v=Ly(),I=_y({type:"image",x,y:E,width:i,height:s,fileId:v,status:"pending",scale:[1,1]}),C=t.excalidrawAPI.getSceneElements(),P=C.findIndex(k=>k.id===o);if(P===-1)return{success:!1,error:`Frame ${o} was removed during image generation`,statusMessage:"Failed: frame no longer exists"};let S={...I,frameId:o},D=[...C],_=Ny(D,P,1);return D.splice(_,0,S),_i(D,Di([S])),t.excalidrawAPI.updateScene({elements:D}),t.excalidrawAPI.addFiles([{id:v,dataURL:w,mimeType:So(w),created:Date.now(),lastRetrieved:Date.now()}]),{success:!0,data:{elementId:I.id,frameId:S.frameId,type:"image",x:Math.round(x),y:Math.round(E),width:Math.round(i),height:Math.round(s)},statusMessage:`Generated image from prompt "${n.slice(0,50)}${n.length>50?"\u2026":""}"`}}catch(w){let v=w instanceof Error?w.message:"Image generation failed";return{success:!1,error:v,statusMessage:`Image generation failed: ${v}`}}}function uQ(e,t){let o=e.elementId;if(!o)return{success:!1,error:"elementId is required",statusMessage:"Failed: missing elementId"};let r=t.excalidrawAPI.getSceneElements().find(s=>s.id===o);if(!r)return{success:!1,error:`Element ${o} not found`,statusMessage:"Failed: element not found"};let a={},i=["x","y","width","height","backgroundColor","strokeColor","opacity","fontSize","text","fillStyle"];for(let s of i)e[s]!==void 0&&(a[s]=e[s]);return Object.keys(a).length===0?{success:!1,error:"No valid properties to update",statusMessage:"Failed: nothing to update"}:a.text!==void 0&&r.type==="text"&&(a.width===void 0||a.height===void 0)?{success:!1,error:"Updating text content requires providing new width and height to avoid clipping.",statusMessage:"Failed: text update requires width and height"}:(t.excalidrawAPI.mutateElement(r,a),{success:!0,data:{elementId:o,updated:Object.keys(a)},statusMessage:`Updated element (${Object.keys(a).join(", ")})`})}function gQ(e,t){let o=e.elementId;if(!o)return{success:!1,error:"elementId is required",statusMessage:"Failed: missing elementId"};let r=t.excalidrawAPI.getSceneElements().find(a=>a.id===o);return r?(t.excalidrawAPI.mutateElement(r,{isDeleted:!0}),{success:!0,data:{elementId:o},statusMessage:`Deleted element ${o}`}):{success:!1,error:`Element ${o} not found`,statusMessage:"Failed: element not found"}}function hQ(e,t){let o=e.frameId;if(!o)return{success:!1,error:"frameId is required",statusMessage:"Failed: missing frameId"};let n=t.excalidrawAPI.getSceneElements(),r=n.find(s=>s.id===o);if(!r)return{success:!1,error:`Frame ${o} not found`,statusMessage:"Failed: frame not found"};let a=Gl(n,o),i=iA(a);return{success:!0,data:{frameId:o,frame:Ry(r),children:i,childCount:i.length},statusMessage:`Found ${i.length} elements in frame`}}async function fQ(e,t){let o=e.html,n=e.frameId;if(!o||typeof o!="string")return{success:!1,error:"html is required",statusMessage:"Failed: missing html"};if(!n)return{success:!1,error:"frameId is required. Call create_frame first to get a frameId, then generate_image with that frameId, then call generate_html_banner with that frameId.",statusMessage:"Failed: frameId is required"};let r=t.excalidrawAPI.getSceneElements(),a=r.find(k=>k.id===n);if(!a)return{success:!1,error:`Frame ${n} not found`,statusMessage:"Failed: frame not found"};let i=a,s=i.x,l=i.y,c=Math.round(i.width),m=Math.round(i.height),d=Gl(r,n).filter(k=>k.customData?.generatedByHtml===!0);for(let k of d)t.excalidrawAPI.mutateElement(k,{isDeleted:!0});let u;try{u=await Su(o,s,l,c,m,t.customFontMap)}catch(k){let M=k instanceof Error?k.message:"HTML parse failed";return{success:!1,error:M,statusMessage:`HTML banner parse failed: ${M}`}}if(u.length===0){let k=o.match(/\.(?:bg|canvas)[^{]*\{[^}]*background(?:-color)?:\s*(#[0-9a-fA-F]{3,8}|rgba?\([^)]+\))/),M=k?k[1]:null;if(M){let B=Zg({type:"rectangle",x:s,y:l,width:c,height:m,backgroundColor:M.startsWith("#")?M:"#ffffff",fillStyle:"solid",strokeColor:"transparent",strokeWidth:0,opacity:100,roughness:0,customData:{generatedByHtml:!0}}),N=[...t.excalidrawAPI.getSceneElements(),B];_i(N,Di([B])),t.excalidrawAPI.updateScene({elements:N})}return{success:!1,error:"Parser produced no elements \u2014 check HTML structure. Try simpler HTML: fewer elements, explicit px values for all positions, no nested divs.",statusMessage:"Failed: no elements parsed from HTML"}}let h=[],g=[];for(let k of u)if(k.kind==="rectangle"){let M=Zg({type:"rectangle",x:k.x,y:k.y,width:k.width,height:k.height,backgroundColor:k.backgroundColor,fillStyle:"solid",strokeColor:k.strokeColor,strokeWidth:k.strokeWidth,opacity:k.opacity,roughness:0,...k.borderRadius>0?{roundness:{type:3,value:k.borderRadius}}:{},customData:{generatedByHtml:!0}});h.push({...M,frameId:i.id})}else if(k.kind==="ellipse"){let M=Zg({type:"ellipse",x:k.x,y:k.y,width:k.width,height:k.height,backgroundColor:k.backgroundColor,fillStyle:"solid",strokeColor:k.strokeColor,strokeWidth:k.strokeWidth,opacity:k.opacity,roughness:0});h.push({...M,frameId:i.id})}else if(k.kind==="text"){let M=nA({x:k.x,y:k.y,text:k.text,fontSize:k.fontSize,fontFamily:k.fontFamily,strokeColor:k.color,textAlign:k.textAlign,width:k.width,opacity:k.opacity,roughness:0,customData:{generatedByHtml:!0}});h.push({...M,frameId:i.id})}else if(k.kind==="image"){let M=Ly(),B=_y({type:"image",x:k.x,y:k.y,width:k.width,height:k.height,fileId:M,status:"pending",scale:[1,1],customData:{generatedByHtml:!0}});h.push({...B,frameId:i.id}),g.push({id:M,dataURL:k.dataUrl,mimeType:So(k.dataUrl),created:Date.now(),lastRetrieved:Date.now()})}let x=c*m,E=[],y=[];for(let k of h)k.type==="rectangle"&&k.width*k.height>=x*.25?E.push(k):y.push(k);let w=t.excalidrawAPI.getSceneElements(),v=w.findIndex(k=>k.id===i.id),I=Gl(w,i.id),C=I.length>0?w.findIndex(k=>k.id===I[0].id):v+1,P=I.length>0?w.findIndex(k=>k.id===I[I.length-1].id)+1:v+1,S=[...w.slice(0,C),...E,...w.slice(C,P),...y,...w.slice(P)],D=[...E,...y];_i(S,Di(D)),t.excalidrawAPI.updateScene({elements:S}),g.length>0&&t.excalidrawAPI.addFiles(g),t.excalidrawAPI.scrollToContent(i,{fitToViewport:!1});let _=await Ul(t.excalidrawAPI,i.id);return{success:!0,data:{frameId:i.id,x:Math.round(s),y:Math.round(l),width:c,height:m,elementCount:h.length},statusMessage:`Banner updated: ${h.length} elements in frame "${e.name||"Banner"}" (${c}\xD7${m})`,screenshot:_??void 0}}async function bQ(e,t){let o=e.query,n=e.type;if(!t.onSearchBrandAssets)return{success:!0,statusMessage:"No asset search configured"};try{let r=await t.onSearchBrandAssets(o,n);if(r.length===0)return{success:!0,data:{assets:[]},statusMessage:`No brand assets found for "${o}"`};let a=r.map(i=>`- ${i.name} (${i.assetType}) [id:${i.id}]: ${i.blobUrl}`).join(`
|
|
328
328
|
`);return{success:!0,data:{assets:r,summary:`Found ${r.length} brand asset(s):
|
|
329
329
|
${a}`},statusMessage:`Found ${r.length} assets`}}catch{return{success:!1,error:"Failed to search brand assets.",statusMessage:"Asset search failed"}}}async function xQ(e,t){let o=e.frameId,n=await Ul(t.excalidrawAPI,o);return{success:!0,data:{frameId:o},statusMessage:"Ad finalized, ready for review",screenshot:n??void 0}}async function yQ(e,t){let o;if(Array.isArray(e.keywords)&&e.keywords.length>0?o=e.keywords:(e.query||e.campaignTag)&&(o=[e.query??e.campaignTag]),!t.onListBrandTemplates)return{success:!0,statusMessage:"No template list configured"};try{let n=await t.onListBrandTemplates(o);if(n.length===0)return{success:!0,data:{templates:[]},statusMessage:"No templates found"};let r=n.map(a=>{let i=a.width&&a.height?` (${a.width}x${a.height})`:"";return`Template: ${a.name}${a.campaignTag?` [${a.campaignTag}]`:""}${i} [id:${a.id}]`}).join(`
|
|
330
|
-
`);return{success:!0,data:{templates:n,summary:r},statusMessage:`Found ${n.length} template(s)`}}catch{return{success:!1,error:"Failed to list brand templates.",statusMessage:"Template list failed"}}}async function EQ(e,t){let o=e.variantId;if(!t.onGetTemplateVariant)return{success:!1,error:"Template fetching not configured.",statusMessage:"No template fetch configured"};try{let{canvasJson:n}=await t.onGetTemplateVariant(o);return t._templateJsonCache||(t._templateJsonCache=new Map),t._templateJsonCache.set(o,n),{success:!0,data:{canvasJson:n},statusMessage:"Template fetched"}}catch{return{success:!1,error:"Failed to fetch template.",statusMessage:"Template fetch failed"}}}async function wQ(e,t){let o=e.frameId,n=e.variantId;if(!t.onGetTemplateVariant)return{success:!1,error:"Template fetching not configured.",statusMessage:"No template fetch configured"};try{let r=t._templateJsonCache?.get(n),{canvasJson:a}=r?{canvasJson:r}:await t.onGetTemplateVariant(n),i=JSON.parse(a),s=i.elements??[],l=i.frame;if(!l)return{success:!1,error:"Template has no frame data. Re-save the template from the canvas (select the frame \u2192 click Template in the toolbar \u2192 Save Template).",statusMessage:"Template frame data missing"};if(s.length===0)return{success:!1,error:"Template has no elements. Add content to the frame before saving it as a template.",statusMessage:"Template is empty"};let c=t.excalidrawAPI.getSceneElements(),m=c.find(v=>v.id===o);if(!m)return{success:!1,error:`Frame ${o} not found.`,statusMessage:"Frame not found"};let p=c.filter(v=>v.frameId!==o),d=m.width/(l.width||1),u=m.height/(l.height||1),h=m.x-l.x*d,g=m.y-l.y*u,x=s.map(v=>({...v,id:Math.random().toString(36).substr(2,9),frameId:o,x:v.x*d+h,y:v.y*u+g,width:v.width*d,height:v.height*u})),E=[...p,...x],y=_i(E,Di(E));t.excalidrawAPI.updateScene({elements:y});let w=i.files;if(w&&Object.keys(w).length>0&&t.excalidrawAPI.addFiles(Object.entries(w).map(([v,I])=>({id:v,dataURL:I.dataURL,mimeType:I.mimeType,created:Date.now(),lastRetrieved:Date.now()}))),n){let v=t.excalidrawAPI.getSceneElements().find(I=>I.id===o);v&&t.excalidrawAPI.mutateElement(v,{customData:{...v.customData,templateId:n}})}return{success:!0,data:{frameId:o},statusMessage:"Template loaded"}}catch(r){return{success:!1,error:`Failed to load template into frame: ${r.message}`,statusMessage:"Template load failed"}}}var Ay=6;function vQ(e,t){let o=t,n=o.width,r=o.height,a=o.lineHeight??1.25,i=o.fontFamily??1,s=x=>{let E=iQ({fontSize:x,fontFamily:i}),y=nQ(e,E,n),{height:w}=rQ(y,E,a);return{wrapped:y,height:w,fits:w<=r}},l=o.fontSize??16,c=s(l);if(c.fits)return{fontSize:l,wrappedText:c.wrapped,height:c.height,autoResize:!1};let m=Ay,p=l-1,d=-1,u="",h=0;for(;m<=p;){let x=Math.floor((m+p)/2),{wrapped:E,height:y,fits:w}=s(x);w?(d=x,u=E,h=y,m=x+1):p=x-1}if(d!==-1)return{fontSize:d,wrappedText:u,height:h,autoResize:!1};let g=s(Ay);return{fontSize:Ay,wrappedText:g.wrapped,height:g.height,autoResize:!0}}function IQ(e,t,o,n,r,a){if(!r||!a)return{x:e,y:t,width:o,height:n};let i=Math.min(o/r,n/a),s=r*i,l=a*i;return{x:e+(o-s)/2,y:t+(n-l)/2,width:s,height:l}}async function TQ(e,t){let o=e.frameId,n=t.excalidrawAPI.getSceneElements(),r={product_image:e.product_image_url,logo:e.logo_url,auxiliary_image:e.auxiliary_image_url},a={product_image:e.product_image_asset_id,logo:e.logo_asset_id,auxiliary_image:e.auxiliary_image_asset_id},i=[];n.forEach((d,u)=>{let h=d;if(h.frameId!==o)return;let g=h.customData?.slotType,x=g?r[g]:void 0;x&&i.push({index:u,url:x,fileId:"",dataURL:"",el:d,naturalWidth:0,naturalHeight:0})}),await Promise.all(i.map(async d=>{try{let u=await fetch(d.url);if(!u.ok)return;let h=await u.blob(),g=await new Promise((x,E)=>{let y=new FileReader;y.onloadend=()=>x(y.result),y.onerror=E,y.readAsDataURL(h)});d.dataURL=g,d.fileId=Ly()}catch{}})),await Promise.all(i.map(d=>new Promise(u=>{if(!d.dataURL)return u();let h=new Image;h.onload=()=>{d.naturalWidth=h.naturalWidth,d.naturalHeight=h.naturalHeight,u()},h.onerror=()=>u(),h.src=d.dataURL})));let s=new Map;for(let d of i){if(!d.fileId)continue;let{x:u,y:h,width:g,height:x}=IQ(d.el.x,d.el.y,d.el.width,d.el.height,d.naturalWidth,d.naturalHeight),E=_y({type:"image",x:u,y:h,width:g,height:x,fileId:d.fileId,status:"pending",scale:[1,1]}),y=d.el,w=y.customData?.slotType,v=w?a[w]:void 0;s.set(d.index,{...E,id:d.el.id,frameId:y.frameId,customData:v?{...y.customData,brandAssetId:v}:y.customData,_fileData:{id:d.fileId,dataURL:d.dataURL,mimeType:So(d.dataURL)}})}let l=0,m=n.map((d,u)=>{let h=d;if(h.frameId!==o)return d;let g=h.customData?.slotType;if(!g)return d;if(s.has(u))return l++,s.get(u);let x={},E=(y,w=!1)=>{let{
|
|
330
|
+
`);return{success:!0,data:{templates:n,summary:r},statusMessage:`Found ${n.length} template(s)`}}catch{return{success:!1,error:"Failed to list brand templates.",statusMessage:"Template list failed"}}}async function EQ(e,t){let o=e.variantId;if(!t.onGetTemplateVariant)return{success:!1,error:"Template fetching not configured.",statusMessage:"No template fetch configured"};try{let{canvasJson:n}=await t.onGetTemplateVariant(o);return t._templateJsonCache||(t._templateJsonCache=new Map),t._templateJsonCache.set(o,n),{success:!0,data:{canvasJson:n},statusMessage:"Template fetched"}}catch{return{success:!1,error:"Failed to fetch template.",statusMessage:"Template fetch failed"}}}async function wQ(e,t){let o=e.frameId,n=e.variantId;if(!t.onGetTemplateVariant)return{success:!1,error:"Template fetching not configured.",statusMessage:"No template fetch configured"};try{let r=t._templateJsonCache?.get(n),{canvasJson:a}=r?{canvasJson:r}:await t.onGetTemplateVariant(n),i=JSON.parse(a),s=i.elements??[],l=i.frame;if(!l)return{success:!1,error:"Template has no frame data. Re-save the template from the canvas (select the frame \u2192 click Template in the toolbar \u2192 Save Template).",statusMessage:"Template frame data missing"};if(s.length===0)return{success:!1,error:"Template has no elements. Add content to the frame before saving it as a template.",statusMessage:"Template is empty"};let c=t.excalidrawAPI.getSceneElements(),m=c.find(v=>v.id===o);if(!m)return{success:!1,error:`Frame ${o} not found.`,statusMessage:"Frame not found"};let p=c.filter(v=>v.frameId!==o),d=m.width/(l.width||1),u=m.height/(l.height||1),h=m.x-l.x*d,g=m.y-l.y*u,x=s.map(v=>({...v,id:Math.random().toString(36).substr(2,9),frameId:o,x:v.x*d+h,y:v.y*u+g,width:v.width*d,height:v.height*u})),E=[...p,...x],y=_i(E,Di(E));t.excalidrawAPI.updateScene({elements:y});let w=i.files;if(w&&Object.keys(w).length>0&&t.excalidrawAPI.addFiles(Object.entries(w).map(([v,I])=>({id:v,dataURL:I.dataURL,mimeType:I.mimeType,created:Date.now(),lastRetrieved:Date.now()}))),n){let v=t.excalidrawAPI.getSceneElements().find(I=>I.id===o);v&&t.excalidrawAPI.mutateElement(v,{customData:{...v.customData,templateId:n}})}return{success:!0,data:{frameId:o},statusMessage:"Template loaded"}}catch(r){return{success:!1,error:`Failed to load template into frame: ${r.message}`,statusMessage:"Template load failed"}}}var Ay=6;function vQ(e,t){let o=t,n=o.width,r=o.height,a=o.lineHeight??1.25,i=o.fontFamily??1,s=x=>{let E=iQ({fontSize:x,fontFamily:i}),y=nQ(e,E,n),{height:w}=rQ(y,E,a);return{wrapped:y,height:w,fits:w<=r}},l=o.fontSize??16,c=s(l);if(c.fits)return{fontSize:l,wrappedText:c.wrapped,height:c.height,autoResize:!1};let m=Ay,p=l-1,d=-1,u="",h=0;for(;m<=p;){let x=Math.floor((m+p)/2),{wrapped:E,height:y,fits:w}=s(x);w?(d=x,u=E,h=y,m=x+1):p=x-1}if(d!==-1)return{fontSize:d,wrappedText:u,height:h,autoResize:!1};let g=s(Ay);return{fontSize:Ay,wrappedText:g.wrapped,height:g.height,autoResize:!0}}function IQ(e,t,o,n,r,a){if(!r||!a)return{x:e,y:t,width:o,height:n};let i=Math.min(o/r,n/a),s=r*i,l=a*i;return{x:e+(o-s)/2,y:t+(n-l)/2,width:s,height:l}}async function TQ(e,t){let o=e.frameId,n=t.excalidrawAPI.getSceneElements(),r={product_image:e.product_image_url,logo:e.logo_url,auxiliary_image:e.auxiliary_image_url},a={product_image:e.product_image_asset_id,logo:e.logo_asset_id,auxiliary_image:e.auxiliary_image_asset_id},i=[];n.forEach((d,u)=>{let h=d;if(h.frameId!==o)return;let g=h.customData?.slotType,x=g?r[g]:void 0;x&&i.push({index:u,url:x,fileId:"",dataURL:"",el:d,naturalWidth:0,naturalHeight:0})}),await Promise.all(i.map(async d=>{try{let u=await fetch(d.url);if(!u.ok)return;let h=await u.blob(),g=await new Promise((x,E)=>{let y=new FileReader;y.onloadend=()=>x(y.result),y.onerror=E,y.readAsDataURL(h)});d.dataURL=g,d.fileId=Ly()}catch{}})),await Promise.all(i.map(d=>new Promise(u=>{if(!d.dataURL)return u();let h=new Image;h.onload=()=>{d.naturalWidth=h.naturalWidth,d.naturalHeight=h.naturalHeight,u()},h.onerror=()=>u(),h.src=d.dataURL})));let s=new Map;for(let d of i){if(!d.fileId)continue;let{x:u,y:h,width:g,height:x}=IQ(d.el.x,d.el.y,d.el.width,d.el.height,d.naturalWidth,d.naturalHeight),E=_y({type:"image",x:u,y:h,width:g,height:x,fileId:d.fileId,status:"pending",scale:[1,1]}),y=d.el,w=y.customData?.slotType,v=w?a[w]:void 0;s.set(d.index,{...E,id:d.el.id,frameId:y.frameId,customData:v?{...y.customData,brandAssetId:v}:y.customData,_fileData:{id:d.fileId,dataURL:d.dataURL,mimeType:So(d.dataURL)}})}let l=0,m=n.map((d,u)=>{let h=d;if(h.frameId!==o)return d;let g=h.customData?.slotType;if(!g)return d;if(s.has(u))return l++,s.get(u);let x={},E=(y,w=!1)=>{let v=w?t.brandHeadlineFontId??t.brandBodyFontId:t.brandBodyFontId,I=v!==void 0?{...d,fontFamily:v}:d,{fontSize:C,wrappedText:P,height:S,autoResize:D}=vQ(y,I);return{text:P,originalText:y,fontSize:C,height:S,autoResize:D,...v!==void 0?{fontFamily:v}:{}}};return g==="headline"&&e.headline?x=E(e.headline,!0):g==="subhead"&&e.subhead?x=E(e.subhead):g==="cta"&&e.cta?x=E(e.cta):g==="signoff"&&e.signoff?x=E(e.signoff):g==="background"&&e.background_color&&(x={backgroundColor:e.background_color}),Object.keys(x).length>0?(l++,{...d,...x}):d}).map(d=>{let{_fileData:u,...h}=d;return h});t.excalidrawAPI.updateScene({elements:m});let p=[...s.values()].map(d=>({id:d._fileData.id,dataURL:d._fileData.dataURL,mimeType:d._fileData.mimeType,created:Date.now(),lastRetrieved:Date.now()}));return p.length>0&&t.excalidrawAPI.addFiles(p),{success:!0,data:{frameId:o,filledCount:l},statusMessage:`Filled ${l} slots`}}function CQ(e){try{let o=JSON.parse(e)?.choices?.[0];return o?{content:o.delta?.content??null,toolCalls:o.delta?.tool_calls??null,finishReason:o.finish_reason??null}:null}catch{return null}}async function*jg(e){let t=e.body?.getReader();if(t)for await(let o of Py(t)){if(o==="[DONE]")break;let n=CQ(o);n&&(yield n)}}function mA(e,t){if(!t.toolCalls)return e;for(let o of t.toolCalls){let n=o.index;if(n>=e.length||o.id){for(;e.length<=n;)e.push({id:"",type:"function",function:{name:"",arguments:""}});e[n]={id:o.id||e[n].id,type:"function",function:{name:o.function?.name||e[n].function.name,arguments:o.function?.arguments||""}}}else o.function?.arguments&&(e[n].function.arguments+=o.function.arguments),o.function?.name&&(e[n].function.name=o.function.name)}return e}function pA(e){return e.filter(t=>t.id&&t.function.name).map(t=>({id:t.id,type:"function",function:{name:t.function.name,arguments:t.function.arguments}}))}function qg(e){return e.body?(e.headers.get("content-type")||"").includes("text/event-stream"):!1}var kQ=`You are an expert HTML/CSS banner designer embedded inside a canvas editor. You create beautiful advertisement banners by writing clean, self-contained HTML/CSS code. Your HTML is parsed by a DOM renderer that converts each element into individually editable canvas elements \u2014 so you must follow the layout rules strictly.
|
|
331
331
|
|
|
332
332
|
## Your Workflow
|
|
333
333
|
|
|
@@ -558,23 +558,23 @@ Never write full sentences or long phrases for any text slot. Tight, punchy copy
|
|
|
558
558
|
FINALIZING THE AD: When ALL elements are placed \u2014 brand assets, generated images, and the HTML text overlay \u2014 call finalize_ad(frameId) to signal completion. Do not call it before all assets are in place. This triggers the final quality review.`,SQ=15;async function MQ(e,t,o,n,r,a,i=rA){let s=r||"google/gemini-3.1-flash-lite-preview",c={model:n?`${s}:online`:s,stream:!0,messages:e.map(u=>u.role==="assistant"&&u.tool_calls?{role:u.role,content:u.content,tool_calls:u.tool_calls}:u.role==="tool"?{role:u.role,tool_call_id:u.tool_call_id,content:u.content}:{role:u.role,content:u.content}),tools:i,tool_choice:"auto"};n&&(c.plugins=[{id:"web",max_results:5}]);let m=await fetch("https://openrouter.ai/api/v1/chat/completions",{method:"POST",signal:o,headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json"},body:JSON.stringify(c)});if(!m.ok){let u=`OpenRouter error ${m.status}`;try{let h=await m.json();h?.error?.message&&(u=h.error.message)}catch{}throw new Error(u)}if(qg(m)){let u="",h=[];for await(let x of jg(m))x.content&&(u+=x.content,a?.(x.content)),x.toolCalls&&mA(h,x);let g=pA(h);return{content:u||null,tool_calls:g.length>0?g:void 0}}let d=(await m.json())?.choices?.[0]?.message;if(!d)throw new Error("No response returned by the API.");return{content:d.content??null,tool_calls:d.tool_calls??void 0}}var uA={display:"48\u201372px",large:"32\u201348px",medium:"20\u201328px",small:"14\u201318px"};function PQ(e){let t=["## Brand Identity \u2014 apply these guidelines to all ads you create"];if(e.colors){let{primary:o,secondary:n,accent:r,background:a}=e.colors,i=[o&&`Primary: ${o}`,n&&`Secondary: ${n}`,r&&`Accent/CTA: ${r}`,a&&`Background: ${a}`].filter(Boolean);i.length&&t.push(`**Colors**: ${i.join(", ")}`)}if(e.typography){let{headline:o,body:n}=e.typography;if(o?.family){let r=o.sizeScale?` (suggested size: ${uA[o.sizeScale]??o.sizeScale})`:"",a=o.fontFamilyId?` \u2014 MANDATORY: use \`font-family: "${o.family}", sans-serif\` in ALL HTML CSS for headlines. Do NOT use any other font.`:` \u2014 no custom font file loaded; use \`font-family: "${o.family}", Arial, sans-serif\` in your HTML CSS (will render as Arial on canvas)`,i=o.fontName?` [file: ${o.fontName}]`:"";t.push(`**Headline font**: ${o.family}${o.weight?` weight ${o.weight}`:""}${r}${a}${i}`)}if(n?.family){let r=n.sizeScale?` (suggested size: ${uA[n.sizeScale]??n.sizeScale})`:"",a=n.fontFamilyId?` \u2014 MANDATORY: use \`font-family: "${n.family}", sans-serif\` in ALL HTML CSS for body copy, subheads, CTAs, and any other text. Do NOT use any other font.`:` \u2014 no custom font file loaded; use \`font-family: "${n.family}", Arial, sans-serif\` in your HTML CSS (will render as Arial on canvas)`,i=n.fontName?` [file: ${n.fontName}]`:"";t.push(`**Body font**: ${n.family}${n.weight?` weight ${n.weight}`:""}${r}${a}${i}`)}}if(e.visualStyle&&t.push(`**Visual style**: ${e.visualStyle}`),e.layoutPattern&&t.push(`**Layout pattern**: ${e.layoutPattern}`),e.toneOfVoice){let{register:o,vocabulary:n,ctaStyle:r,sentenceLength:a,person:i}=e.toneOfVoice,s=[o&&`register: ${o}`,n&&`vocabulary: ${n}`,r&&`CTA style: ${r}`,a&&`sentence length: ${a}`,i&&`person: ${i}`].filter(Boolean);s.length&&t.push(`**Tone of voice**: ${s.join(", ")}`)}if(e.imagery){let{type:o,lighting:n,composition:r,subjects:a,grading:i,depthOfField:s,environment:l,negativeSpace:c}=e.imagery,m=[o&&`type: ${o}`,a&&`subjects: ${a}`,n&&`lighting: ${n}`,i&&`grading: ${i}`,s&&`depth of field: ${s}`,l&&`environment: ${l}`,c&&`negative space: ${c}`,r&&`composition: ${r}`].filter(Boolean);m.length&&t.push(`**Imagery direction**: ${m.join(", ")}`)}return t.join(`
|
|
559
559
|
`)}async function gA(e){let{userMessages:t,elementContext:o,frameScreenshot:n,fileAttachments:r,webSearchEnabled:a,apiKey:i,chatModel:s,agentImageModel:l,toolCtx:c,onUpdate:m,signal:p,onBeforeImageGen:d,onAfterImageGen:u,brandContext:h,reviewerModel:g,maxReviewRounds:x}=e,E={};if(h?.typography){let{headline:L,body:F}=h.typography;L?.family&&L.fontFamilyId&&(E[L.family.toLowerCase().trim()]=L.fontFamilyId),F?.family&&F.fontFamilyId&&(E[F.family.toLowerCase().trim()]=F.fontFamilyId)}let y=r?.filter(L=>L.type==="image")??[],w=t.flatMap(L=>(L.imageAttachments??[]).map(F=>({name:F.name,type:"image",dataUrl:F.dataUrl}))),v=new Set,I=[];for(let L of[...w,...y]){let F=L.dataUrl??L.name;v.has(F)||(v.add(F),I.push(L))}let C={...c,...Object.keys(E).length?{customFontMap:E}:{},...I.length?{fileAttachments:I}:{},...h?.typography?.headline?.fontName?{brandHeadlineFontName:h.typography.headline.fontName}:{},...h?.typography?.body?.fontName?{brandBodyFontName:h.typography.body.fontName}:{},...h?.typography?.headline?.fontFamilyId?{brandHeadlineFontId:h.typography.headline.fontFamilyId}:{},...h?.typography?.body?.fontFamilyId?{brandBodyFontId:h.typography.body.fontFamilyId}:{}},P=[{role:"system",content:kQ}];h&&P.push({role:"system",content:PQ(h)}),o&&P.push({role:"system",content:`The user has referenced a frame (via @ mention). Here are the frame details and its child elements. Use these IDs and properties when modifying or working with these elements:
|
|
560
560
|
|
|
561
|
-
${o}`});for(let L=0;L<t.length;L++){let F=t[L],$=L===t.length-1,Q=$&&r?r.filter(J=>J.type==="image"&&J.dataUrl):[],Z=F.imageAttachments??[],U=Z.length>0||Q.length>0,q=$&&!!n,
|
|
561
|
+
${o}`});for(let L=0;L<t.length;L++){let F=t[L],$=L===t.length-1,Q=$&&r?r.filter(J=>J.type==="image"&&J.dataUrl):[],Z=F.imageAttachments??[],U=Z.length>0||Q.length>0,q=$&&!!n,ae=$&&r&&r.some(J=>J.type==="text");if(F.role==="user"&&(U||q||ae)){let J=[];q&&J.push({type:"image_url",image_url:{url:n}});for(let ue of Z)J.push({type:"image_url",image_url:{url:ue.dataUrl}});for(let ue of Q)J.push({type:"image_url",image_url:{url:ue.dataUrl}});let te=F.content;if(q&&(te=`[Screenshot of the referenced frame is attached above]
|
|
562
562
|
|
|
563
|
-
${
|
|
563
|
+
${te}`),ae&&r){let ue=r.filter(Me=>Me.type==="text");ue.length>0&&(te+=`
|
|
564
564
|
|
|
565
|
-
${
|
|
565
|
+
${ue.map(Me=>`[File: ${Me.name}]
|
|
566
566
|
${Me.textContent}`).join(`
|
|
567
567
|
|
|
568
|
-
`)}`)}J.push({type:"text",text:
|
|
569
|
-
1. Call add_rectangle to create the background zone (left side of the frame: x=0, y=0, width=${k.x>0?k.x:Math.round(J*.45)}, height=${Math.round(C.excalidrawAPI.getSceneElements().find(
|
|
568
|
+
`)}`)}J.push({type:"text",text:te}),P.push({role:"user",content:J})}else P.push({role:F.role,content:F.content})}let S=[],D=0,_,k,M=0,B=!1,O=0,N=x??2;for(;D<SQ;){D++,m({type:"status",message:D===1?"Thinking\u2026":"Processing tool results\u2026"});let L=await MQ(P,i,p,a,s,F=>m({type:"content_delta",message:F}),aA);if(!L.tool_calls||L.tool_calls.length===0){let F=L.content||"",Q=F.includes("<controls>")||F.includes("<functions.")?"I ran into a formatting issue. Your banner image has been placed \u2014 please describe any text changes you'd like and I'll apply them.":F||"Done!";return m({type:"final",message:Q}),{reply:Q,toolActions:S}}P.push({role:"assistant",content:L.content,tool_calls:L.tool_calls});for(let F of L.tool_calls){let{name:$,arguments:Q}=F.function,Z={};try{Z=JSON.parse(Q)}catch{}if(m({type:"tool_start",message:AQ($,Z)}),$==="generate_image"&&d){let J;try{J=await d()}catch{J={allowed:!1,error:"Credit check failed"}}let{allowed:te,error:ue}=J;if(!te){let Me={success:!1,error:ue||"Insufficient credits for image generation",statusMessage:ue||"Insufficient credits for image generation"},ct={result:{success:Me.success,statusMessage:Me.statusMessage}};S.push(ct),m({type:"tool_done",message:Me.statusMessage,toolAction:ct}),P.push({role:"tool",tool_call_id:F.id,content:JSON.stringify({success:!1,error:Me.error})});continue}}if($==="create_frame"&&_&&C.excalidrawAPI.getSceneElements().some(te=>te.id===_&&!te.isDeleted)){let te={success:!1,error:`DUPLICATE FRAME BLOCKED: You already created frame "${_}" in this turn. Do NOT call create_frame again. Reuse this frameId for every subsequent tool call (generate_image, load_template_into_frame, fill_template_slots, etc.). If the frame needs different dimensions, call update_element on this frameId instead.`,statusMessage:`Blocked: reuse existing frame ${_}`},ue={result:{success:te.success,statusMessage:te.statusMessage}};S.push(ue),m({type:"tool_done",message:te.statusMessage,toolAction:ue}),P.push({role:"tool",tool_call_id:F.id,content:JSON.stringify({success:!1,error:te.error,existingFrameId:_})});continue}if($==="generate_html_banner"&&B){let J={success:!1,error:"WRONG TOOL: A template is already loaded in the frame. The template's text slots have already been filled by fill_template_slots \u2014 do NOT call generate_html_banner. The ad is complete.",statusMessage:"Blocked: template already provides text slots"},te={result:{success:J.success,statusMessage:J.statusMessage}};S.push(te),m({type:"tool_done",message:J.statusMessage,toolAction:te}),P.push({role:"tool",tool_call_id:F.id,content:JSON.stringify({success:!1,error:J.error})});continue}let U=await cA($,Q,C);$==="create_frame"&&U.success&&U.data?.frameId&&(_=U.data.frameId),$==="load_template_into_frame"&&U.success&&(B=!0),$==="generate_image"&&U.success&&U.data&&(k={frameId:U.data.frameId,x:U.data.x,y:U.data.y,width:U.data.width,height:U.data.height},u&&u());let q={result:{success:U.success,statusMessage:U.statusMessage}};if(S.push(q),m({type:"tool_done",message:U.statusMessage,toolAction:q}),$==="generate_html_banner"){if(U.success)M=0;else if(M++,M>=2&&k){let J=Math.round(C.excalidrawAPI.getSceneElements().find(te=>te.id===k.frameId)?.width??512);P.push({role:"user",content:`generate_html_banner has failed ${M} times. STOP trying generate_html_banner. Instead, build the text layer using primitive tools in this order:
|
|
569
|
+
1. Call add_rectangle to create the background zone (left side of the frame: x=0, y=0, width=${k.x>0?k.x:Math.round(J*.45)}, height=${Math.round(C.excalidrawAPI.getSceneElements().find(te=>te.id===k.frameId)?.height??512)} inside frameId="${k.frameId}")
|
|
570
570
|
2. Call add_text for each text element (headline, subheadline, CTA label) inside the same frameId
|
|
571
571
|
3. Call add_rectangle for the CTA button background with a border-radius
|
|
572
572
|
|
|
573
|
-
Use the frameId="${k.frameId}" for all elements. Keep all elements within x=0..${k.x>0?k.x:Math.round(J*.45)}.`})}}let
|
|
574
|
-
\u2192 FIX: ${Me.preciseInstruction}`}),
|
|
575
|
-
`);P.push({role:"user",content:[{type:"image_url",image_url:{url:
|
|
573
|
+
Use the frameId="${k.frameId}" for all elements. Keep all elements within x=0..${k.x>0?k.x:Math.round(J*.45)}.`})}}let ae=$==="finalize_ad"&&U.success?U.screenshot:void 0;if(P.push({role:"tool",tool_call_id:F.id,content:JSON.stringify(U.success?{success:!0,...U.data,screenshot:void 0}:{success:!1,error:U.error})}),ae&&!B&&O<N){m({type:"review_start",message:"Reviewing design\u2026"}),O++;let J;try{J=await Mu({screenshotDataUrl:ae,htmlSource:Z.html??"",frame:{id:k?.frameId??"",width:k?(()=>{let te=C.excalidrawAPI.getSceneElements().find(ue=>ue.id===k.frameId);return Math.round(te?.width??512)})():512,height:k?(()=>{let te=C.excalidrawAPI.getSceneElements().find(ue=>ue.id===k.frameId);return Math.round(te?.height??512)})():512},imagePlacement:k?{x:k.x,y:k.y,width:k.width,height:k.height}:void 0,userBrief:typeof t[0]?.content=="string"?t[0].content:"",brandContext:h,apiKey:i,reviewerModel:g??s,signal:p,iteration:O})}catch(te){if(te instanceof Error&&te.name==="AbortError")throw te;J={approved:!0,issues:[],summary:"Reviewer failed; skipping.",iteration:O}}if(m({type:"review_done",message:J.summary,feedback:J}),!J.approved&&J.issues.length>0){let te=J.issues.map((Me,ct)=>{let Lt=`[${Me.severity}]`;return`${ct+1}) ${Lt} ${Me.element.toUpperCase()}: ${Me.problem}
|
|
574
|
+
\u2192 FIX: ${Me.preciseInstruction}`}),ue=[`Expert reviewer found ${J.issues.length} issue(s) in the banner:`,"",...te,"",`Overall verdict: ${J.summary}`,"",`Apply ALL fixes above by calling generate_html_banner again with the corrected layout. Use frameId="${k?.frameId??""}" in additive mode. Prioritise critical issues first. IMPORTANT: Do NOT call generate_image \u2014 fix HTML and CSS properties only. Any image size or position adjustments must be done via CSS inside the HTML (e.g. width/height/object-fit on the <img> element), NOT by generating a new image.`].join(`
|
|
575
|
+
`);P.push({role:"user",content:[{type:"image_url",image_url:{url:ae}},{type:"text",text:ue}]})}else P.push({role:"user",content:[{type:"image_url",image_url:{url:ae}},{type:"text",text:`Expert reviewer approved the banner: ${J.summary}
|
|
576
576
|
|
|
577
|
-
Describe the final banner to the user and stop.`}]})}if($==="generate_image"&&U.success&&k){m({type:"status",message:"Preparing text layout\u2026"});let J=await(async()=>{try{return await Ul(c.excalidrawAPI,k.frameId)}catch{return null}})(),
|
|
577
|
+
Describe the final banner to the user and stop.`}]})}if($==="generate_image"&&U.success&&k){m({type:"status",message:"Preparing text layout\u2026"});let J=await(async()=>{try{return await Ul(c.excalidrawAPI,k.frameId)}catch{return null}})(),te=[];J&&te.push({type:"image_url",image_url:{url:J}}),te.push({type:"text",text:`Image placed successfully. DO NOT OUTPUT ANY TEXT \u2014 call generate_html_banner immediately with frameId="${k.frameId}".
|
|
578
578
|
|
|
579
579
|
Image occupies: x=${k.x}, y=${k.y}, width=${k.width}, height=${k.height} (right edge: x=${k.x+k.width}, bottom edge: y=${k.y+k.height}) inside frameId="${k.frameId}".
|
|
580
580
|
|
|
@@ -588,10 +588,10 @@ Call generate_html_banner NOW with frameId="${k.frameId}". Your HTML must place
|
|
|
588
588
|
- If image fills full frame (x=0, y=0): text floats on top \u2014 use the composition to place text in the open/clear zone described in your image prompt. Do NOT add a background div.
|
|
589
589
|
- A full-frame background rectangle IS allowed only for Pattern A (solid color zone behind text). Never for Pattern B.
|
|
590
590
|
|
|
591
|
-
**ZONE-FILL REMINDER:** For structured layouts (Pattern A), the image must completely fill its designated zone with no accidental gaps. If the image is in a split layout (occupying a half or side of the frame), it should span the full height and width of that zone \u2014 no random thin strips of empty space. If it's a centered/inset product shot, deliberate padding is fine but the dimensions should be intentional.`}),P.push({role:"user",content:se})}}}let z="I've completed the available operations. Let me know if you'd like any adjustments!";return m({type:"final",message:z}),{reply:z,toolActions:S}}function AQ(e,t){switch(e){case"generate_html_banner":{let o=t.width||512,n=t.height||512;return`Generating HTML banner (${o}\xD7${n}) and placing on canvas\u2026`}case"create_frame":return`Creating frame (${t.width||512}\xD7${t.height||512})\u2026`;case"add_rectangle":return"Adding background rectangle\u2026";case"add_text":return`Adding text "${String(t.text||"").slice(0,30)}"\u2026`;case"generate_image":return"Generating image \u2014 this may take a moment\u2026";case"update_element":return"Updating element\u2026";case"delete_element":return"Deleting element\u2026";case"get_frame_elements":return"Inspecting frame contents\u2026";default:return`Running ${e}\u2026`}}async function hA(e){let t=await e.arrayBuffer(),o=new AudioContext,n=await o.decodeAudioData(t);await o.close();let r=n.numberOfChannels,a=n.sampleRate,i=n.length,s=2,l=i*r*s,c=44+l,m=new ArrayBuffer(c),p=new DataView(m),d=(E,y)=>{for(let w=0;w<y.length;w++)p.setUint8(E+w,y.charCodeAt(w))};d(0,"RIFF"),p.setUint32(4,36+l,!0),d(8,"WAVE"),d(12,"fmt "),p.setUint32(16,16,!0),p.setUint16(20,1,!0),p.setUint16(22,r,!0),p.setUint32(24,a,!0),p.setUint32(28,a*r*s,!0),p.setUint16(32,r*s,!0),p.setUint16(34,16,!0),d(36,"data"),p.setUint32(40,l,!0);let u=44;for(let E=0;E<i;E++)for(let y=0;y<r;y++){let w=n.getChannelData(y)[E],v=Math.max(-1,Math.min(1,w)),I=v<0?v*32768:v*32767;p.setInt16(u,I,!0),u+=2}let h=new Uint8Array(m),g=8192,x="";for(let E=0;E<h.length;E+=g)x+=String.fromCharCode(...h.subarray(E,E+g));return btoa(x)}async function fA(e,t,o,n){let r=n||"mistralai/voxtral-small-24b-2507",a=await fetch("https://openrouter.ai/api/v1/chat/completions",{method:"POST",headers:{Authorization:`Bearer ${o}`,"Content-Type":"application/json"},body:JSON.stringify({model:r,messages:[{role:"user",content:[{type:"text",text:"Transcribe this audio. Return only the transcription text, nothing else."},{type:"input_audio",input_audio:{data:e,format:t}}]}]})});if(!a.ok){let s=`Transcription error ${a.status}`;try{let l=await a.json();l?.error?.message&&(s=l.error.message)}catch{}throw new Error(s)}return(await a.json())?.choices?.[0]?.message?.content||""}import{StickToBottom as bA}from"use-stick-to-bottom";import{jsx as EA}from"react/jsx-runtime";function xA({children:e,className:t,...o}){return EA(bA,{className:je("flex overflow-y-auto",t),resize:"smooth",initial:"instant",role:"log",...o,children:e})}function yA({children:e,className:t,...o}){return EA(bA.Content,{className:je("flex w-full flex-col",t),...o,children:e})}import{marked as RQ}from"marked";import{memo as IA,useId as NQ,useMemo as BQ}from"react";import FQ from"react-markdown";import OQ from"remark-breaks";import zQ from"remark-gfm";import{useEffect as LQ,useState as _Q}from"react";import{codeToHtml as DQ}from"shiki";import{jsx as Zd}from"react/jsx-runtime";function wA({children:e,className:t,...o}){return Zd("div",{className:je("not-prose flex w-full flex-col overflow-clip border","border-zinc-200 bg-white text-zinc-950 rounded-xl dark:border-zinc-800 dark:bg-zinc-950 dark:text-zinc-50",t),...o,children:e})}function vA({code:e,language:t="tsx",theme:o="github-light",className:n,...r}){let[a,i]=_Q(null);LQ(()=>{async function l(){if(!e){i("<pre><code></code></pre>");return}let c=await DQ(e,{lang:t,theme:o});i(c)}l()},[e,t,o]);let s=je("w-full overflow-x-auto text-[13px] [&>pre]:px-4 [&>pre]:py-4",n);return a?Zd("div",{className:s,dangerouslySetInnerHTML:{__html:a},...r}):Zd("div",{className:s,...r,children:Zd("pre",{children:Zd("code",{children:e})})})}import{Fragment as WQ,jsx as Ri}from"react/jsx-runtime";function HQ(e){return RQ.lexer(e).map(o=>o.raw)}function GQ(e){if(!e)return"plaintext";let t=e.match(/language-(\w+)/);return t?t[1]:"plaintext"}var TA={code:function({className:t,children:o,...n}){if(!n.node?.position?.start.line||n.node?.position?.start.line===n.node?.position?.end.line)return Ri("span",{className:je("bg-zinc-50 rounded-sm px-1 font-mono text-sm dark:bg-zinc-900",t),...n,children:o});let a=GQ(t);return Ri(wA,{className:t,children:Ri(vA,{code:o,language:a})})},pre:function({children:t}){return Ri(WQ,{children:t})}},CA=IA(({content:e,components:t=TA})=>Ri(FQ,{remarkPlugins:[zQ,OQ],components:t,children:e}),(e,t)=>e.content===t.content);CA.displayName="MemoizedMarkdownBlock";function UQ({children:e,id:t,className:o,components:n=TA}){let r=NQ(),a=t??r,i=BQ(()=>HQ(e),[e]);return Ri("div",{className:o,children:i.map((s,l)=>Ri(CA,{content:s,components:n},`${a}-block-${l}`))})}var By=IA(UQ);By.displayName="Markdown";import*as Jg from"react";import*as Br from"@radix-ui/react-avatar";import{jsx as Fy}from"react/jsx-runtime";var kA=Jg.forwardRef(({className:e,...t},o)=>Fy(Br.Root,{ref:o,className:je("relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",e),...t}));kA.displayName=Br.Root.displayName;var SA=Jg.forwardRef(({className:e,...t},o)=>Fy(Br.Image,{ref:o,className:je("aspect-square h-full w-full",e),...t}));SA.displayName=Br.Image.displayName;var MA=Jg.forwardRef(({className:e,...t},o)=>Fy(Br.Fallback,{ref:o,className:je("flex h-full w-full items-center justify-center rounded-full bg-zinc-100 dark:bg-zinc-800",e),...t}));MA.displayName=Br.Fallback.displayName;import{jsx as Ni,jsxs as YQ}from"react/jsx-runtime";var Oy=({children:e,className:t,...o})=>Ni("div",{className:je("flex gap-3",t),...o,children:e});var zy=({children:e,markdown:t=!1,className:o,...n})=>{let r=je("rounded-lg p-2 text-zinc-950 bg-zinc-100 prose break-words whitespace-normal dark:text-zinc-50 dark:bg-zinc-800",o);return t?Ni(By,{className:r,...n,children:e}):Ni("div",{className:r,...n,children:e})},Hy=({children:e,className:t,...o})=>Ni("div",{className:je("text-zinc-500 flex items-center gap-2 dark:text-zinc-400",t),...o,children:e}),Gy=({tooltip:e,children:t,className:o,side:n="top",...r})=>Ni(Tu,{children:YQ(Cu,{...r,children:[Ni(ku,{asChild:!0,children:t}),Ni(cd,{side:n,className:o,children:e})]})});import{ChevronDown as ZQ}from"lucide-react";import{useStickToBottomContext as jQ}from"use-stick-to-bottom";import*as PA from"react";import{Slot as $Q}from"@radix-ui/react-slot";import{cva as VQ}from"class-variance-authority";import{jsx as XQ}from"react/jsx-runtime";var KQ=VQ("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-zinc-950 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0 dark:focus-visible:ring-zinc-300",{variants:{variant:{default:"bg-zinc-900 text-zinc-50 shadow hover:bg-zinc-900/90 dark:bg-zinc-50 dark:text-zinc-900 dark:hover:bg-zinc-50/90",destructive:"bg-red-500 text-zinc-50 shadow-sm hover:bg-red-500/90 dark:bg-red-900 dark:text-zinc-50 dark:hover:bg-red-900/90",outline:"border border-zinc-200 bg-white shadow-sm hover:bg-zinc-100 hover:text-zinc-900 dark:border-zinc-800 dark:bg-zinc-950 dark:hover:bg-zinc-800 dark:hover:text-zinc-50",secondary:"bg-zinc-100 text-zinc-900 shadow-sm hover:bg-zinc-100/80 dark:bg-zinc-800 dark:text-zinc-50 dark:hover:bg-zinc-800/80",ghost:"hover:bg-zinc-100 hover:text-zinc-900 dark:hover:bg-zinc-800 dark:hover:text-zinc-50",link:"text-zinc-900 underline-offset-4 hover:underline dark:text-zinc-50"},size:{default:"h-9 px-4 py-2",sm:"h-8 rounded-md px-3 text-xs",lg:"h-10 rounded-md px-8",icon:"h-9 w-9"}},defaultVariants:{variant:"default",size:"default"}}),Uy=PA.forwardRef(({className:e,variant:t,size:o,asChild:n=!1,...r},a)=>XQ(n?$Q:"button",{className:je(KQ({variant:t,size:o,className:e})),ref:a,...r}));Uy.displayName="Button";import{jsx as AA}from"react/jsx-runtime";function LA({className:e,variant:t="outline",size:o="sm",...n}){let{isAtBottom:r,scrollToBottom:a}=jQ();return AA(Uy,{variant:t,size:o,className:je("h-10 w-10 rounded-full transition-all duration-150 ease-out",r?"pointer-events-none translate-y-4 scale-95 opacity-0":"translate-y-0 scale-100 opacity-100",e),onClick:()=>a(),...n,children:AA(ZQ,{className:"h-5 w-5"})})}import{jsx as X,jsxs as Le}from"react/jsx-runtime";function Wl(){return Math.random().toString(36).slice(2,10)}var Qg=3,see=10*1024*1024,lee=["Create a pasta ad","Design a sale banner","Make a product showcase","Help me design"],OA=qQ.forwardRef(({isOpen:e,onClose:t,apiKey:o,excalidrawAPI:n,geminiApiKey:r,initialMessages:a,initialSessionId:i,initialSessions:s,onMessagesChange:l,onSessionCreate:c,onSessionSwitch:m,onBeforeSend:p,onAfterSend:d,onBeforeImageGen:u,onAfterImageGen:h,chatModel:g,voiceModel:x,agentImageModel:E,brandContext:y,onSearchBrandAssets:w,onListBrandTemplates:v,onGetTemplateVariant:I,reviewerModel:C,maxReviewRounds:P},S)=>{let[D,_]=xt(""),[k,M]=xt(!1),[B,O]=xt(""),[N,z]=xt(a??[]),[L,F]=xt(s??[]),[$,Q]=xt(i??Wl),[Z,U]=xt(!1),[q,re]=xt(""),[J,se]=xt(null),[fe,Me]=xt(null),[ct,Lt]=xt(!1),[Sn,Mn]=xt([]),[eo,Gt]=xt([]),[yt,dr]=xt(!1),[Y,oe]=xt(!1),[De,ft]=xt(!1),[$t,Oo]=xt(!1),[Pn,Fr]=xt(null),Oa=Fo(null),Yl=Fo(null),eh=Fo(null),jd=Fo(null),Ky=Fo(null),th=Fo([]),An=Fo(""),Bi=Fo(!1),oh=Fo($),[HA,Fi]=xt(!1),mr=Fo(!1),zo=Fo(""),qe=Fo(null),nh=Fo(null),GA=QQ(()=>{let V=[];return y?.typography?.headline?.fontFamilyId&&V.push(y.typography.headline.fontFamilyId),y?.typography?.body?.fontFamilyId&&V.push(y.typography.body.fontFamilyId),V},[y]);Wy(()=>{oh.current=$},[$]),Wy(()=>{let V=Re=>{Oa.current&&!Oa.current.contains(Re.target)&&U(!1),eh.current&&!eh.current.contains(Re.target)&&Lt(!1)};return document.addEventListener("mousedown",V),()=>document.removeEventListener("mousedown",V)},[]),Wy(()=>{e||(Yl.current?.abort(),qe.current&&(cancelAnimationFrame(qe.current),qe.current=null),zo.current="",mr.current=!1,Fi(!1))},[e]);let UA=(()=>{let V=L.find(Re=>Re.id===$)?.title;return V||(N.length>0?N[0].content.slice(0,30)+(N[0].content.length>30?"\u2026":""):"New chat")})(),qd=Co(()=>{if(N.length===0)return;let V=N[0].content.slice(0,40)+(N[0].content.length>40?"\u2026":"");F(Re=>{let $e=Re.findIndex(He=>He.id===$),et={id:$,title:V,messages:N};if($e>=0){let He=[...Re];return He[$e]=et,He}return[et,...Re]})},[N,$]),Xy=Co(()=>{qd();let V=Wl();z([]),Q(V),oe(!1),U(!1),se(null),_(""),Me(null),Gt([]),O("")},[qd]),WA=Co(V=>{qd(),Q(V.id),U(!1),se(null),V.messages.length>0?(z(V.messages),oe(!1)):(z([]),oe(!0),m&&m(V.id))},[qd,m]),YA=Co(V=>{let Re=An.current;_(V),An.current=V,n&&V.length>Re.length&&V.endsWith("@")&&(Mn(sA(n)),Lt(!0))},[n]),$A=Co(async V=>{if(!n)return;Lt(!1),_(He=>{let Ve=He.lastIndexOf("@");return Ve>=0?He.slice(0,Ve):He});let Re=An.current.lastIndexOf("@");An.current=Re>=0?An.current.slice(0,Re):An.current;let $e=lA(n,V.id);if(!$e)return;let et=await Ul(n,V.id);Me({frameId:V.id,label:$e.frameInfo.name,serialized:$e.serialized,screenshot:et??void 0})},[n]),VA=Co(()=>{Me(null)},[]),KA=Co(V=>{let Re=V.target.files;if(!Re)return;let $e=Qg-eo.length;if($e<=0)return;let et=Array.from(Re).slice(0,$e);for(let He of et){if(He.size>see){se(`"${He.name}" is too large (max 10 MB).`);continue}let Ve=Wl(),uo=He.type.startsWith("image/"),go=new FileReader;uo?(go.onload=()=>{Gt(mn=>mn.length<Qg?[...mn,{id:Ve,file:He,name:He.name,type:"image",dataUrl:go.result}]:mn)},go.readAsDataURL(He)):(go.onload=()=>{Gt(mn=>mn.length<Qg?[...mn,{id:Ve,file:He,name:He.name,type:"text",textContent:go.result}]:mn)},go.readAsText(He))}jd.current&&(jd.current.value="")},[eo.length]),XA=Co(V=>{Gt(Re=>Re.filter($e=>$e.id!==V))},[]),ZA=Co(()=>{dr(V=>!V)},[]),jA=Co(async()=>{if(De){Ky.current?.stop(),ft(!1),Bi.current=!0;return}let V=null;try{V=await navigator.mediaDevices.getUserMedia({audio:!0});let Re=MediaRecorder.isTypeSupported("audio/webm")?"audio/webm":"audio/mp4",$e=new MediaRecorder(V,{mimeType:Re});Ky.current=$e,th.current=[],$e.ondataavailable=et=>{et.data.size>0&&th.current.push(et.data)},$e.onstop=async()=>{V?.getTracks().forEach(Ve=>Ve.stop());let et=new Blob(th.current,{type:$e.mimeType}),He=ld(o);if(!He){se("No API key for voice transcription.");return}Oo(!0),O("Transcribing\u2026");try{let Ve=await hA(et),uo=await fA(Ve,"wav",He,x),go=(An.current?`${An.current} `:"")+uo;An.current=go,_(go)}catch(Ve){Bi.current=!1,se(Ve instanceof Error?Ve.message:"Transcription failed")}finally{Oo(!1),O("")}},$e.start(),ft(!0)}catch{V?.getTracks().forEach(Re=>Re.stop()),se("Could not access microphone. Check browser permissions.")}},[De,o]),Zy=Co((V,Re)=>{navigator.clipboard.writeText(Re).then(()=>{Fr(V),setTimeout(()=>Fr(null),2e3)},()=>{se("Copy failed \u2014 please grant clipboard permission.")})},[]),Jd=Co(async V=>{let Re=(V??D).trim(),$e=ld(o);if(!Re||k){Bi.current=!1;return}if(!$e){Bi.current=!1,se("No OpenRouter API key. Set VITE_APP_OPENROUTER_API_KEY in .env or pass the key via the `apiKey` prop.");return}let et=[...eo],He=yt,Ve=fe,uo={id:Wl(),role:"user",content:Re,timestamp:new Date,attachments:et.length>0?et.map(Vt=>({name:Vt.name,type:Vt.type,dataUrl:Vt.dataUrl})):void 0},go=N.length===0,mn=N,Oi=[...N,uo];z(Oi),_(""),An.current="",Gt([]),Me(null),se(null);let Qd=new AbortController;Yl.current=Qd,M(!0),O("Thinking\u2026");let rh=Bi.current;if(Bi.current=!1,p){let{allowed:Vt,error:$l}=await p({hasVoice:rh});if(!Vt){z(mn),se($l||"Insufficient credits"),M(!1),O("");return}}if(!n){let Vt=Wl(),$l={id:Vt,role:"assistant",content:"",timestamp:new Date},em=[...Oi,$l];z(em);try{let Je=await mee(Oi,$e,Qd.signal,{webSearchEnabled:He,attachments:et,chatModel:g,brandContext:y,onChunk:za=>{mr.current||(mr.current=!0,Fi(!0),O("")),zo.current+=za,qe.current||(qe.current=requestAnimationFrame(()=>{let tm=zo.current;zo.current="",qe.current=null,z(QA=>{let Vl=[...QA],Jy=Vl[Vl.length-1];return Vl[Vl.length-1]={...Jy,content:Jy.content+tm},Vl})}))}});qe.current&&(cancelAnimationFrame(qe.current),qe.current=null);let ko={id:Vt,role:"assistant",content:Je,timestamp:new Date},zi=[...Oi,ko];z(zi),d&&d({hasVoice:rh}),go&&c&&c({id:$,title:Re.slice(0,40)}),l&&l(zi,$)}catch(Je){Je instanceof Error&&Je.name!=="AbortError"&&se(Je.message)}finally{qe.current&&(cancelAnimationFrame(qe.current),qe.current=null),zo.current="",mr.current=!1,Fi(!1),Yl.current=null,M(!1),O("")}return}let qy=Wl(),ah=!1;nh.current=null;try{let Vt=await gA({userMessages:Oi.map(Je=>({role:Je.role,content:Je.content,imageAttachments:Je.attachments?.filter(ko=>ko.type==="image"&&ko.dataUrl).map(ko=>({name:ko.name,dataUrl:ko.dataUrl}))})),elementContext:Ve?.serialized,frameScreenshot:Ve?.screenshot,fileAttachments:et.length>0?et.map(Je=>({name:Je.name,type:Je.type,dataUrl:Je.dataUrl,textContent:Je.textContent})):void 0,webSearchEnabled:He,apiKey:$e,chatModel:g,agentImageModel:E,brandContext:y,customFontIds:GA,toolCtx:{excalidrawAPI:n,geminiApiKey:r||"",signal:Qd.signal,agentImageModel:E,onSearchBrandAssets:w,onListBrandTemplates:v,onGetTemplateVariant:I},onUpdate:Je=>{if(Je.type==="content_delta"){if(!ah){ah=!0;let ko={id:qy,role:"assistant",content:"",timestamp:new Date};z(zi=>[...zi,ko]),mr.current||(mr.current=!0,Fi(!0),O(""))}zo.current+=Je.message,qe.current||(qe.current=requestAnimationFrame(()=>{let ko=zo.current;zo.current="",qe.current=null,z(zi=>{let za=[...zi],tm=za[za.length-1];return za[za.length-1]={...tm,content:tm.content+ko},za})}))}else if(Je.type==="status"||Je.type==="tool_start"||Je.type==="tool_done")mr.current&&(qe.current&&(cancelAnimationFrame(qe.current),qe.current=null),zo.current="",mr.current=!1,Fi(!1),ah=!1),O(Je.message);else if(Je.type==="review_start")O(Je.message);else if(Je.type==="review_done"){nh.current=Je.feedback;let ko=Je.feedback.approved?"Design approved \u2713":`${Je.feedback.issues.length} issue(s) found \u2014 refining\u2026`;O(ko)}},signal:Qd.signal,onBeforeImageGen:u,onAfterImageGen:h,reviewerModel:C,maxReviewRounds:P});qe.current&&(cancelAnimationFrame(qe.current),qe.current=null),zo.current="";let $l={id:qy,role:"assistant",content:Vt.reply,timestamp:new Date,toolActions:Vt.toolActions.length>0?Vt.toolActions:void 0,reviewFeedback:nh.current??void 0},em=[...Oi,$l];z(em),d&&d({hasVoice:rh}),go&&c&&c({id:$,title:Re.slice(0,40)}),l&&l(em,$)}catch(Vt){Vt instanceof Error&&Vt.name!=="AbortError"&&se(Vt.message)}finally{qe.current&&(cancelAnimationFrame(qe.current),qe.current=null),zo.current="",mr.current=!1,Fi(!1),Yl.current=null,M(!1),O("")}},[D,k,N,o,n,r,fe,eo,yt,$,p,d,l,c,u,h]);JQ(S,()=>({setMessages:(V,Re)=>{let $e=Re??oh.current;F(et=>{let He=et.findIndex(Ve=>Ve.id===$e);if(He>=0){let Ve=[...et],uo=Ve[He],go=!uo.title||uo.title==="New chat",mn=V.length>0?V[0].content.slice(0,40)+(V[0].content.length>40?"\u2026":""):uo.title;return Ve[He]={...uo,messages:V,title:go?mn:uo.title},Ve}return et}),$e===oh.current&&(z(V),oe(!1))},send:V=>Jd(V)}),[Jd]);let qA=Co(()=>{Yl.current?.abort(),qe.current&&(cancelAnimationFrame(qe.current),qe.current=null),zo.current=""},[]),JA=Co(V=>{_(V)},[]),jy=L.filter(V=>q?V.title.toLowerCase().includes(q.toLowerCase()):!0);return e?X("div",{className:"acp",onPointerDown:V=>V.stopPropagation(),onClick:V=>V.stopPropagation(),children:Le("div",{className:"acp-panel",children:[Le("div",{className:"acp-header",ref:Oa,children:[Le("button",{className:"acp-title-btn",onClick:()=>U(V=>!V),title:"Chat history",children:[X("span",{children:UA}),X(tee,{size:13})]}),Le("div",{className:"acp-header-right",children:[X("button",{className:"acp-icon-btn",onClick:Xy,title:"New chat",children:X(BA,{size:15})}),X("button",{className:"acp-icon-btn",onClick:t,title:"Close",children:X($y,{size:15})})]}),Z&&Le("div",{className:"acp-history-dropdown",children:[Le("div",{className:"acp-history-search",children:[X(aee,{size:13}),X("input",{type:"search",placeholder:"Search chats\u2026",value:q,onChange:V=>re(V.target.value),autoFocus:!0})]}),Le("div",{className:"acp-history-list",children:[Le("button",{className:"acp-history-item acp-history-item--new",onClick:Xy,children:[X(BA,{size:13}),X("span",{children:"New chat"})]}),jy.map(V=>Le("button",{className:"acp-history-item",onClick:()=>WA(V),children:[X(NA,{size:13}),X("span",{children:V.title})]},V.id)),jy.length===0&&q&&X("div",{className:"acp-history-empty",children:"No matching chats"})]})]})]}),X("div",{className:"acp-messages-wrap",children:Y?X("div",{className:"acp-empty",children:Le("div",{className:"acp-loading-session",children:[Le("div",{className:"acp-loading-dots",children:[X("span",{}),X("span",{}),X("span",{})]}),X("span",{className:"acp-status-text",children:"Loading chat\u2026"})]})}):N.length===0&&!k?Le("div",{className:"acp-empty",children:[X("div",{className:"acp-empty-icon",children:X(NA,{size:22})}),Le("div",{children:[X("div",{className:"acp-empty-title",children:"AI Ad Designer"}),X("div",{className:"acp-empty-sub",children:"Describe an ad and I'll create it on the canvas. Type @ to reference frames."})]}),X("div",{className:"acp-chips",children:lee.map(V=>X("button",{className:"acp-chip",onClick:()=>JA(V),children:V},V))})]}):Le(xA,{className:"acp-chat-root",children:[Le(yA,{className:"acp-chat-content",children:[N.filter((V,Re,$e)=>$e.findIndex(et=>et.id===V.id)===Re).map((V,Re,$e)=>{let et=V.role==="assistant",He=Re===$e.length-1;return X(Oy,{className:`acp-msg ${et?"acp-msg--assistant":"acp-msg--user"}`,children:et?Le("div",{className:"acp-msg-inner",children:[V.toolActions&&V.toolActions.length>0&&X(cee,{actions:V.toolActions}),V.reviewFeedback&&X(dee,{feedback:V.reviewFeedback}),X(zy,{markdown:!0,className:"acp-content-assistant",children:V.content}),X(Hy,{className:`acp-msg-actions${He?" acp-msg-actions--visible":""}`,children:X(Gy,{tooltip:"Copy",delayDuration:100,children:X("button",{className:"acp-action-btn",onClick:()=>Zy(V.id,V.content),children:Pn===V.id?X(DA,{size:14}):X(RA,{size:14})})})})]}):Le("div",{className:"acp-msg-inner",children:[V.attachments&&V.attachments.length>0&&X("div",{className:"acp-msg-attachments",children:V.attachments.map((Ve,uo)=>Ve.type==="image"&&Ve.dataUrl?X("img",{src:Ve.dataUrl,alt:Ve.name,className:"acp-msg-att-thumb",title:Ve.name},uo):Le("span",{className:"acp-msg-att-pill",children:[X(Yy,{size:11}),Ve.name]},uo))}),X(zy,{className:"acp-content-user",children:V.content}),X(Hy,{className:"acp-msg-actions",children:X(Gy,{tooltip:"Copy",delayDuration:100,children:X("button",{className:"acp-action-btn",onClick:()=>Zy(V.id,V.content),children:Pn===V.id?X(DA,{size:14}):X(RA,{size:14})})})})]})},V.id)}),k&&X(Oy,{className:"acp-msg acp-msg--assistant",children:X("div",{className:"acp-msg-inner",children:Le("div",{className:"acp-status-indicator",children:[Le("div",{className:"acp-loading-dots",children:[X("span",{}),X("span",{}),X("span",{})]}),!HA&&B&&X("span",{className:"acp-status-text",children:B})]})})})]}),X("div",{className:"acp-scroll-anchor",children:X(LA,{className:"acp-scroll-btn"})})]})}),J&&X("div",{className:"acp-error",children:J}),fe&&X("div",{className:"acp-ref-area",children:Le("div",{className:"acp-ref-pill",children:[X(_A,{size:12}),X("span",{children:fe.label}),X("button",{className:"acp-ref-remove",onClick:VA,title:"Remove reference",children:X($y,{size:10})})]})}),eo.length>0&&X("div",{className:"acp-attachments-area",children:eo.map(V=>Le("div",{className:"acp-attachment-pill",children:[V.type==="image"&&V.dataUrl?X("img",{src:V.dataUrl,alt:V.name,className:"acp-attachment-thumb"}):X(Yy,{size:12}),X("span",{children:V.name}),X("button",{className:"acp-attachment-remove",onClick:()=>XA(V.id),title:"Remove file",children:X($y,{size:10})})]},V.id))}),X("div",{className:"acp-input-area",children:Le("div",{className:"acp-input-wrapper",ref:eh,children:[ct&&X("div",{className:"acp-mention-menu",children:Sn.length>0?Sn.map(V=>Le("button",{className:"acp-mention-item",onClick:()=>$A(V),children:[X(_A,{size:14}),Le("span",{children:[V.name," ",Le("span",{className:"acp-mention-dim",children:["(",V.width,"x",V.height,", ",V.childCount," items)"]})]})]},V.id)):X("div",{className:"acp-mention-empty",children:"No frames on the canvas. Create a frame first, then type @ to reference it."})}),X("input",{ref:jd,type:"file",multiple:!0,accept:"image/*,.txt,.json,.csv,.md,.html,.css,.js,.ts,.tsx,.jsx,.py,.xml",onChange:KA,style:{display:"none"}}),Le(ml,{isLoading:k,value:D,onValueChange:YA,onSubmit:()=>Jd(),className:"acp-prompt-input",children:[X(pl,{placeholder:n?"Describe an ad to create\u2026 (@ for frames)":"Ask anything",className:"acp-textarea"}),Le(ul,{className:"acp-actions-bar",children:[Le("div",{className:"acp-actions-left",children:[X(Pr,{tooltip:"Attach files (max 3)",children:X("button",{className:"acp-pill-btn acp-pill-btn--icon",onClick:()=>jd.current?.click(),disabled:eo.length>=Qg,children:X(Yy,{size:16})})}),X(Pr,{tooltip:yt?"Web search enabled":"Enable web search",children:Le("button",{className:`acp-pill-btn${yt?" acp-pill-btn--active":""}`,onClick:ZA,children:[X(oee,{size:15}),X("span",{children:"Search"})]})})]}),Le("div",{className:"acp-actions-right",children:[X(Pr,{tooltip:$t?"Transcribing\u2026":De?"Stop recording":"Voice input",children:X("button",{className:`acp-pill-btn acp-pill-btn--icon${De?" acp-pill-btn--recording":""}${$t?" acp-pill-btn--transcribing":""}`,onClick:jA,disabled:$t,children:$t?X("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"acp-mic-spinner",children:X("path",{d:"M21 12a9 9 0 1 1-6.219-8.56"})}):De?X(ree,{size:16}):X(nee,{size:16})})}),X("button",{className:"acp-send-btn",onClick:k?qA:()=>Jd(),disabled:!k&&!D.trim(),title:k?"Stop":"Send",children:k?X("span",{className:"acp-stop-square"}):X(eee,{size:16})})]})]})]})]})})]})}):null});OA.displayName="AIChatPanel";function cee({actions:e}){let[t,o]=xt(!1);return Le("div",{className:"acp-tool-actions",children:[Le("button",{className:"acp-tool-actions-toggle",onClick:()=>o(n=>!n),children:[X(iee,{size:13}),Le("span",{children:[e.length," action",e.length!==1?"s":""," performed"]}),X(FA,{size:12,className:`acp-tool-chevron ${t?"acp-tool-chevron--open":""}`})]}),t&&X("div",{className:"acp-tool-actions-list",children:e.map((n,r)=>Le("div",{className:`acp-tool-action-item ${n.result.success?"acp-tool-action-item--ok":"acp-tool-action-item--err"}`,children:[X("span",{className:"acp-tool-action-dot"}),X("span",{children:n.result.statusMessage})]},r))})]})}function dee({feedback:e}){let[t,o]=xt(!1),n=a=>a==="critical"?"acp-review-issue--critical":a==="major"?"acp-review-issue--major":"acp-review-issue--minor",r=e.approved;return Le("div",{className:`acp-review-card ${r?"acp-review-card--ok":"acp-review-card--issues"}`,children:[Le("button",{className:"acp-review-toggle",onClick:()=>o(a=>!a),children:[X("span",{className:`acp-review-badge ${r?"acp-review-badge--ok":"acp-review-badge--issues"}`,children:r?"\u2713 Design approved":`${e.issues.length} issue${e.issues.length!==1?"s":""} found`}),X("span",{className:"acp-review-summary",children:e.summary}),!r&&e.issues.length>0&&X(FA,{size:12,className:`acp-tool-chevron ${t?"acp-tool-chevron--open":""}`})]}),t&&!r&&e.issues.length>0&&X("div",{className:"acp-review-issues",children:e.issues.map((a,i)=>Le("div",{className:`acp-review-issue ${n(a.severity)}`,children:[Le("div",{className:"acp-review-issue-header",children:[X("span",{className:"acp-review-issue-severity",children:a.severity}),X("span",{className:"acp-review-issue-element",children:a.element}),X("span",{className:"acp-review-issue-problem",children:a.problem})]}),Le("div",{className:"acp-review-issue-fix",children:["\u2192 ",a.preciseInstruction]})]},i))})]})}async function mee(e,t,o,n){let r=n?.chatModel||"google/gemini-3.1-flash-lite-preview",a=n?.webSearchEnabled?`${r}:online`:r,i=[];n?.brandContext&&i.push({role:"system",content:pee(n.brandContext)});let s=[...i,...e.map((d,u)=>{if(u===e.length-1&&d.role==="user"&&n?.attachments?.length){let g=[];for(let y of n.attachments)y.type==="image"&&y.dataUrl&&g.push({type:"image_url",image_url:{url:y.dataUrl}});let x=d.content,E=n.attachments.filter(y=>y.type==="text");return E.length>0&&(x+=`
|
|
591
|
+
**ZONE-FILL REMINDER:** For structured layouts (Pattern A), the image must completely fill its designated zone with no accidental gaps. If the image is in a split layout (occupying a half or side of the frame), it should span the full height and width of that zone \u2014 no random thin strips of empty space. If it's a centered/inset product shot, deliberate padding is fine but the dimensions should be intentional.`}),P.push({role:"user",content:te})}}}let z="I've completed the available operations. Let me know if you'd like any adjustments!";return m({type:"final",message:z}),{reply:z,toolActions:S}}function AQ(e,t){switch(e){case"generate_html_banner":{let o=t.width||512,n=t.height||512;return`Generating HTML banner (${o}\xD7${n}) and placing on canvas\u2026`}case"create_frame":return`Creating frame (${t.width||512}\xD7${t.height||512})\u2026`;case"add_rectangle":return"Adding background rectangle\u2026";case"add_text":return`Adding text "${String(t.text||"").slice(0,30)}"\u2026`;case"generate_image":return"Generating image \u2014 this may take a moment\u2026";case"update_element":return"Updating element\u2026";case"delete_element":return"Deleting element\u2026";case"get_frame_elements":return"Inspecting frame contents\u2026";default:return`Running ${e}\u2026`}}async function hA(e){let t=await e.arrayBuffer(),o=new AudioContext,n=await o.decodeAudioData(t);await o.close();let r=n.numberOfChannels,a=n.sampleRate,i=n.length,s=2,l=i*r*s,c=44+l,m=new ArrayBuffer(c),p=new DataView(m),d=(E,y)=>{for(let w=0;w<y.length;w++)p.setUint8(E+w,y.charCodeAt(w))};d(0,"RIFF"),p.setUint32(4,36+l,!0),d(8,"WAVE"),d(12,"fmt "),p.setUint32(16,16,!0),p.setUint16(20,1,!0),p.setUint16(22,r,!0),p.setUint32(24,a,!0),p.setUint32(28,a*r*s,!0),p.setUint16(32,r*s,!0),p.setUint16(34,16,!0),d(36,"data"),p.setUint32(40,l,!0);let u=44;for(let E=0;E<i;E++)for(let y=0;y<r;y++){let w=n.getChannelData(y)[E],v=Math.max(-1,Math.min(1,w)),I=v<0?v*32768:v*32767;p.setInt16(u,I,!0),u+=2}let h=new Uint8Array(m),g=8192,x="";for(let E=0;E<h.length;E+=g)x+=String.fromCharCode(...h.subarray(E,E+g));return btoa(x)}async function fA(e,t,o,n){let r=n||"mistralai/voxtral-small-24b-2507",a=await fetch("https://openrouter.ai/api/v1/chat/completions",{method:"POST",headers:{Authorization:`Bearer ${o}`,"Content-Type":"application/json"},body:JSON.stringify({model:r,messages:[{role:"user",content:[{type:"text",text:"Transcribe this audio. Return only the transcription text, nothing else."},{type:"input_audio",input_audio:{data:e,format:t}}]}]})});if(!a.ok){let s=`Transcription error ${a.status}`;try{let l=await a.json();l?.error?.message&&(s=l.error.message)}catch{}throw new Error(s)}return(await a.json())?.choices?.[0]?.message?.content||""}import{StickToBottom as bA}from"use-stick-to-bottom";import{jsx as EA}from"react/jsx-runtime";function xA({children:e,className:t,...o}){return EA(bA,{className:je("flex overflow-y-auto",t),resize:"smooth",initial:"instant",role:"log",...o,children:e})}function yA({children:e,className:t,...o}){return EA(bA.Content,{className:je("flex w-full flex-col",t),...o,children:e})}import{marked as RQ}from"marked";import{memo as IA,useId as NQ,useMemo as BQ}from"react";import FQ from"react-markdown";import OQ from"remark-breaks";import zQ from"remark-gfm";import{useEffect as LQ,useState as _Q}from"react";import{codeToHtml as DQ}from"shiki";import{jsx as Zd}from"react/jsx-runtime";function wA({children:e,className:t,...o}){return Zd("div",{className:je("not-prose flex w-full flex-col overflow-clip border","border-zinc-200 bg-white text-zinc-950 rounded-xl dark:border-zinc-800 dark:bg-zinc-950 dark:text-zinc-50",t),...o,children:e})}function vA({code:e,language:t="tsx",theme:o="github-light",className:n,...r}){let[a,i]=_Q(null);LQ(()=>{async function l(){if(!e){i("<pre><code></code></pre>");return}let c=await DQ(e,{lang:t,theme:o});i(c)}l()},[e,t,o]);let s=je("w-full overflow-x-auto text-[13px] [&>pre]:px-4 [&>pre]:py-4",n);return a?Zd("div",{className:s,dangerouslySetInnerHTML:{__html:a},...r}):Zd("div",{className:s,...r,children:Zd("pre",{children:Zd("code",{children:e})})})}import{Fragment as WQ,jsx as Ri}from"react/jsx-runtime";function HQ(e){return RQ.lexer(e).map(o=>o.raw)}function GQ(e){if(!e)return"plaintext";let t=e.match(/language-(\w+)/);return t?t[1]:"plaintext"}var TA={code:function({className:t,children:o,...n}){if(!n.node?.position?.start.line||n.node?.position?.start.line===n.node?.position?.end.line)return Ri("span",{className:je("bg-zinc-50 rounded-sm px-1 font-mono text-sm dark:bg-zinc-900",t),...n,children:o});let a=GQ(t);return Ri(wA,{className:t,children:Ri(vA,{code:o,language:a})})},pre:function({children:t}){return Ri(WQ,{children:t})}},CA=IA(({content:e,components:t=TA})=>Ri(FQ,{remarkPlugins:[zQ,OQ],components:t,children:e}),(e,t)=>e.content===t.content);CA.displayName="MemoizedMarkdownBlock";function UQ({children:e,id:t,className:o,components:n=TA}){let r=NQ(),a=t??r,i=BQ(()=>HQ(e),[e]);return Ri("div",{className:o,children:i.map((s,l)=>Ri(CA,{content:s,components:n},`${a}-block-${l}`))})}var By=IA(UQ);By.displayName="Markdown";import*as Jg from"react";import*as Br from"@radix-ui/react-avatar";import{jsx as Fy}from"react/jsx-runtime";var kA=Jg.forwardRef(({className:e,...t},o)=>Fy(Br.Root,{ref:o,className:je("relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",e),...t}));kA.displayName=Br.Root.displayName;var SA=Jg.forwardRef(({className:e,...t},o)=>Fy(Br.Image,{ref:o,className:je("aspect-square h-full w-full",e),...t}));SA.displayName=Br.Image.displayName;var MA=Jg.forwardRef(({className:e,...t},o)=>Fy(Br.Fallback,{ref:o,className:je("flex h-full w-full items-center justify-center rounded-full bg-zinc-100 dark:bg-zinc-800",e),...t}));MA.displayName=Br.Fallback.displayName;import{jsx as Ni,jsxs as YQ}from"react/jsx-runtime";var Oy=({children:e,className:t,...o})=>Ni("div",{className:je("flex gap-3",t),...o,children:e});var zy=({children:e,markdown:t=!1,className:o,...n})=>{let r=je("rounded-lg p-2 text-zinc-950 bg-zinc-100 prose break-words whitespace-normal dark:text-zinc-50 dark:bg-zinc-800",o);return t?Ni(By,{className:r,...n,children:e}):Ni("div",{className:r,...n,children:e})},Hy=({children:e,className:t,...o})=>Ni("div",{className:je("text-zinc-500 flex items-center gap-2 dark:text-zinc-400",t),...o,children:e}),Gy=({tooltip:e,children:t,className:o,side:n="top",...r})=>Ni(Tu,{children:YQ(Cu,{...r,children:[Ni(ku,{asChild:!0,children:t}),Ni(cd,{side:n,className:o,children:e})]})});import{ChevronDown as ZQ}from"lucide-react";import{useStickToBottomContext as jQ}from"use-stick-to-bottom";import*as PA from"react";import{Slot as $Q}from"@radix-ui/react-slot";import{cva as VQ}from"class-variance-authority";import{jsx as XQ}from"react/jsx-runtime";var KQ=VQ("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-zinc-950 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0 dark:focus-visible:ring-zinc-300",{variants:{variant:{default:"bg-zinc-900 text-zinc-50 shadow hover:bg-zinc-900/90 dark:bg-zinc-50 dark:text-zinc-900 dark:hover:bg-zinc-50/90",destructive:"bg-red-500 text-zinc-50 shadow-sm hover:bg-red-500/90 dark:bg-red-900 dark:text-zinc-50 dark:hover:bg-red-900/90",outline:"border border-zinc-200 bg-white shadow-sm hover:bg-zinc-100 hover:text-zinc-900 dark:border-zinc-800 dark:bg-zinc-950 dark:hover:bg-zinc-800 dark:hover:text-zinc-50",secondary:"bg-zinc-100 text-zinc-900 shadow-sm hover:bg-zinc-100/80 dark:bg-zinc-800 dark:text-zinc-50 dark:hover:bg-zinc-800/80",ghost:"hover:bg-zinc-100 hover:text-zinc-900 dark:hover:bg-zinc-800 dark:hover:text-zinc-50",link:"text-zinc-900 underline-offset-4 hover:underline dark:text-zinc-50"},size:{default:"h-9 px-4 py-2",sm:"h-8 rounded-md px-3 text-xs",lg:"h-10 rounded-md px-8",icon:"h-9 w-9"}},defaultVariants:{variant:"default",size:"default"}}),Uy=PA.forwardRef(({className:e,variant:t,size:o,asChild:n=!1,...r},a)=>XQ(n?$Q:"button",{className:je(KQ({variant:t,size:o,className:e})),ref:a,...r}));Uy.displayName="Button";import{jsx as AA}from"react/jsx-runtime";function LA({className:e,variant:t="outline",size:o="sm",...n}){let{isAtBottom:r,scrollToBottom:a}=jQ();return AA(Uy,{variant:t,size:o,className:je("h-10 w-10 rounded-full transition-all duration-150 ease-out",r?"pointer-events-none translate-y-4 scale-95 opacity-0":"translate-y-0 scale-100 opacity-100",e),onClick:()=>a(),...n,children:AA(ZQ,{className:"h-5 w-5"})})}import{jsx as X,jsxs as Le}from"react/jsx-runtime";function Wl(){return Math.random().toString(36).slice(2,10)}var Qg=3,see=10*1024*1024,lee=["Create a pasta ad","Design a sale banner","Make a product showcase","Help me design"],OA=qQ.forwardRef(({isOpen:e,onClose:t,apiKey:o,excalidrawAPI:n,geminiApiKey:r,initialMessages:a,initialSessionId:i,initialSessions:s,onMessagesChange:l,onSessionCreate:c,onSessionSwitch:m,onBeforeSend:p,onAfterSend:d,onBeforeImageGen:u,onAfterImageGen:h,chatModel:g,voiceModel:x,agentImageModel:E,brandContext:y,onSearchBrandAssets:w,onListBrandTemplates:v,onGetTemplateVariant:I,reviewerModel:C,maxReviewRounds:P},S)=>{let[D,_]=xt(""),[k,M]=xt(!1),[B,O]=xt(""),[N,z]=xt(a??[]),[L,F]=xt(s??[]),[$,Q]=xt(i??Wl),[Z,U]=xt(!1),[q,ae]=xt(""),[J,te]=xt(null),[ue,Me]=xt(null),[ct,Lt]=xt(!1),[Sn,Mn]=xt([]),[eo,Gt]=xt([]),[yt,dr]=xt(!1),[Y,ne]=xt(!1),[De,ft]=xt(!1),[$t,Oo]=xt(!1),[Pn,Fr]=xt(null),Oa=Fo(null),Yl=Fo(null),eh=Fo(null),jd=Fo(null),Ky=Fo(null),th=Fo([]),An=Fo(""),Bi=Fo(!1),oh=Fo($),[HA,Fi]=xt(!1),mr=Fo(!1),zo=Fo(""),qe=Fo(null),nh=Fo(null),GA=QQ(()=>{let V=[];return y?.typography?.headline?.fontFamilyId&&V.push(y.typography.headline.fontFamilyId),y?.typography?.body?.fontFamilyId&&V.push(y.typography.body.fontFamilyId),V},[y]);Wy(()=>{oh.current=$},[$]),Wy(()=>{let V=Re=>{Oa.current&&!Oa.current.contains(Re.target)&&U(!1),eh.current&&!eh.current.contains(Re.target)&&Lt(!1)};return document.addEventListener("mousedown",V),()=>document.removeEventListener("mousedown",V)},[]),Wy(()=>{e||(Yl.current?.abort(),qe.current&&(cancelAnimationFrame(qe.current),qe.current=null),zo.current="",mr.current=!1,Fi(!1))},[e]);let UA=(()=>{let V=L.find(Re=>Re.id===$)?.title;return V||(N.length>0?N[0].content.slice(0,30)+(N[0].content.length>30?"\u2026":""):"New chat")})(),qd=Co(()=>{if(N.length===0)return;let V=N[0].content.slice(0,40)+(N[0].content.length>40?"\u2026":"");F(Re=>{let $e=Re.findIndex(He=>He.id===$),et={id:$,title:V,messages:N};if($e>=0){let He=[...Re];return He[$e]=et,He}return[et,...Re]})},[N,$]),Xy=Co(()=>{qd();let V=Wl();z([]),Q(V),ne(!1),U(!1),te(null),_(""),Me(null),Gt([]),O("")},[qd]),WA=Co(V=>{qd(),Q(V.id),U(!1),te(null),V.messages.length>0?(z(V.messages),ne(!1)):(z([]),ne(!0),m&&m(V.id))},[qd,m]),YA=Co(V=>{let Re=An.current;_(V),An.current=V,n&&V.length>Re.length&&V.endsWith("@")&&(Mn(sA(n)),Lt(!0))},[n]),$A=Co(async V=>{if(!n)return;Lt(!1),_(He=>{let Ve=He.lastIndexOf("@");return Ve>=0?He.slice(0,Ve):He});let Re=An.current.lastIndexOf("@");An.current=Re>=0?An.current.slice(0,Re):An.current;let $e=lA(n,V.id);if(!$e)return;let et=await Ul(n,V.id);Me({frameId:V.id,label:$e.frameInfo.name,serialized:$e.serialized,screenshot:et??void 0})},[n]),VA=Co(()=>{Me(null)},[]),KA=Co(V=>{let Re=V.target.files;if(!Re)return;let $e=Qg-eo.length;if($e<=0)return;let et=Array.from(Re).slice(0,$e);for(let He of et){if(He.size>see){te(`"${He.name}" is too large (max 10 MB).`);continue}let Ve=Wl(),uo=He.type.startsWith("image/"),go=new FileReader;uo?(go.onload=()=>{Gt(mn=>mn.length<Qg?[...mn,{id:Ve,file:He,name:He.name,type:"image",dataUrl:go.result}]:mn)},go.readAsDataURL(He)):(go.onload=()=>{Gt(mn=>mn.length<Qg?[...mn,{id:Ve,file:He,name:He.name,type:"text",textContent:go.result}]:mn)},go.readAsText(He))}jd.current&&(jd.current.value="")},[eo.length]),XA=Co(V=>{Gt(Re=>Re.filter($e=>$e.id!==V))},[]),ZA=Co(()=>{dr(V=>!V)},[]),jA=Co(async()=>{if(De){Ky.current?.stop(),ft(!1),Bi.current=!0;return}let V=null;try{V=await navigator.mediaDevices.getUserMedia({audio:!0});let Re=MediaRecorder.isTypeSupported("audio/webm")?"audio/webm":"audio/mp4",$e=new MediaRecorder(V,{mimeType:Re});Ky.current=$e,th.current=[],$e.ondataavailable=et=>{et.data.size>0&&th.current.push(et.data)},$e.onstop=async()=>{V?.getTracks().forEach(Ve=>Ve.stop());let et=new Blob(th.current,{type:$e.mimeType}),He=ld(o);if(!He){te("No API key for voice transcription.");return}Oo(!0),O("Transcribing\u2026");try{let Ve=await hA(et),uo=await fA(Ve,"wav",He,x),go=(An.current?`${An.current} `:"")+uo;An.current=go,_(go)}catch(Ve){Bi.current=!1,te(Ve instanceof Error?Ve.message:"Transcription failed")}finally{Oo(!1),O("")}},$e.start(),ft(!0)}catch{V?.getTracks().forEach(Re=>Re.stop()),te("Could not access microphone. Check browser permissions.")}},[De,o]),Zy=Co((V,Re)=>{navigator.clipboard.writeText(Re).then(()=>{Fr(V),setTimeout(()=>Fr(null),2e3)},()=>{te("Copy failed \u2014 please grant clipboard permission.")})},[]),Jd=Co(async V=>{let Re=(V??D).trim(),$e=ld(o);if(!Re||k){Bi.current=!1;return}if(!$e){Bi.current=!1,te("No OpenRouter API key. Set VITE_APP_OPENROUTER_API_KEY in .env or pass the key via the `apiKey` prop.");return}let et=[...eo],He=yt,Ve=ue,uo={id:Wl(),role:"user",content:Re,timestamp:new Date,attachments:et.length>0?et.map(Vt=>({name:Vt.name,type:Vt.type,dataUrl:Vt.dataUrl})):void 0},go=N.length===0,mn=N,Oi=[...N,uo];z(Oi),_(""),An.current="",Gt([]),Me(null),te(null);let Qd=new AbortController;Yl.current=Qd,M(!0),O("Thinking\u2026");let rh=Bi.current;if(Bi.current=!1,p){let{allowed:Vt,error:$l}=await p({hasVoice:rh});if(!Vt){z(mn),te($l||"Insufficient credits"),M(!1),O("");return}}if(!n){let Vt=Wl(),$l={id:Vt,role:"assistant",content:"",timestamp:new Date},em=[...Oi,$l];z(em);try{let Je=await mee(Oi,$e,Qd.signal,{webSearchEnabled:He,attachments:et,chatModel:g,brandContext:y,onChunk:za=>{mr.current||(mr.current=!0,Fi(!0),O("")),zo.current+=za,qe.current||(qe.current=requestAnimationFrame(()=>{let tm=zo.current;zo.current="",qe.current=null,z(QA=>{let Vl=[...QA],Jy=Vl[Vl.length-1];return Vl[Vl.length-1]={...Jy,content:Jy.content+tm},Vl})}))}});qe.current&&(cancelAnimationFrame(qe.current),qe.current=null);let ko={id:Vt,role:"assistant",content:Je,timestamp:new Date},zi=[...Oi,ko];z(zi),d&&d({hasVoice:rh}),go&&c&&c({id:$,title:Re.slice(0,40)}),l&&l(zi,$)}catch(Je){Je instanceof Error&&Je.name!=="AbortError"&&te(Je.message)}finally{qe.current&&(cancelAnimationFrame(qe.current),qe.current=null),zo.current="",mr.current=!1,Fi(!1),Yl.current=null,M(!1),O("")}return}let qy=Wl(),ah=!1;nh.current=null;try{let Vt=await gA({userMessages:Oi.map(Je=>({role:Je.role,content:Je.content,imageAttachments:Je.attachments?.filter(ko=>ko.type==="image"&&ko.dataUrl).map(ko=>({name:ko.name,dataUrl:ko.dataUrl}))})),elementContext:Ve?.serialized,frameScreenshot:Ve?.screenshot,fileAttachments:et.length>0?et.map(Je=>({name:Je.name,type:Je.type,dataUrl:Je.dataUrl,textContent:Je.textContent})):void 0,webSearchEnabled:He,apiKey:$e,chatModel:g,agentImageModel:E,brandContext:y,customFontIds:GA,toolCtx:{excalidrawAPI:n,geminiApiKey:r||"",signal:Qd.signal,agentImageModel:E,onSearchBrandAssets:w,onListBrandTemplates:v,onGetTemplateVariant:I},onUpdate:Je=>{if(Je.type==="content_delta"){if(!ah){ah=!0;let ko={id:qy,role:"assistant",content:"",timestamp:new Date};z(zi=>[...zi,ko]),mr.current||(mr.current=!0,Fi(!0),O(""))}zo.current+=Je.message,qe.current||(qe.current=requestAnimationFrame(()=>{let ko=zo.current;zo.current="",qe.current=null,z(zi=>{let za=[...zi],tm=za[za.length-1];return za[za.length-1]={...tm,content:tm.content+ko},za})}))}else if(Je.type==="status"||Je.type==="tool_start"||Je.type==="tool_done")mr.current&&(qe.current&&(cancelAnimationFrame(qe.current),qe.current=null),zo.current="",mr.current=!1,Fi(!1),ah=!1),O(Je.message);else if(Je.type==="review_start")O(Je.message);else if(Je.type==="review_done"){nh.current=Je.feedback;let ko=Je.feedback.approved?"Design approved \u2713":`${Je.feedback.issues.length} issue(s) found \u2014 refining\u2026`;O(ko)}},signal:Qd.signal,onBeforeImageGen:u,onAfterImageGen:h,reviewerModel:C,maxReviewRounds:P});qe.current&&(cancelAnimationFrame(qe.current),qe.current=null),zo.current="";let $l={id:qy,role:"assistant",content:Vt.reply,timestamp:new Date,toolActions:Vt.toolActions.length>0?Vt.toolActions:void 0,reviewFeedback:nh.current??void 0},em=[...Oi,$l];z(em),d&&d({hasVoice:rh}),go&&c&&c({id:$,title:Re.slice(0,40)}),l&&l(em,$)}catch(Vt){Vt instanceof Error&&Vt.name!=="AbortError"&&te(Vt.message)}finally{qe.current&&(cancelAnimationFrame(qe.current),qe.current=null),zo.current="",mr.current=!1,Fi(!1),Yl.current=null,M(!1),O("")}},[D,k,N,o,n,r,ue,eo,yt,$,p,d,l,c,u,h]);JQ(S,()=>({setMessages:(V,Re)=>{let $e=Re??oh.current;F(et=>{let He=et.findIndex(Ve=>Ve.id===$e);if(He>=0){let Ve=[...et],uo=Ve[He],go=!uo.title||uo.title==="New chat",mn=V.length>0?V[0].content.slice(0,40)+(V[0].content.length>40?"\u2026":""):uo.title;return Ve[He]={...uo,messages:V,title:go?mn:uo.title},Ve}return et}),$e===oh.current&&(z(V),ne(!1))},send:V=>Jd(V)}),[Jd]);let qA=Co(()=>{Yl.current?.abort(),qe.current&&(cancelAnimationFrame(qe.current),qe.current=null),zo.current=""},[]),JA=Co(V=>{_(V)},[]),jy=L.filter(V=>q?V.title.toLowerCase().includes(q.toLowerCase()):!0);return e?X("div",{className:"acp",onPointerDown:V=>V.stopPropagation(),onClick:V=>V.stopPropagation(),children:Le("div",{className:"acp-panel",children:[Le("div",{className:"acp-header",ref:Oa,children:[Le("button",{className:"acp-title-btn",onClick:()=>U(V=>!V),title:"Chat history",children:[X("span",{children:UA}),X(tee,{size:13})]}),Le("div",{className:"acp-header-right",children:[X("button",{className:"acp-icon-btn",onClick:Xy,title:"New chat",children:X(BA,{size:15})}),X("button",{className:"acp-icon-btn",onClick:t,title:"Close",children:X($y,{size:15})})]}),Z&&Le("div",{className:"acp-history-dropdown",children:[Le("div",{className:"acp-history-search",children:[X(aee,{size:13}),X("input",{type:"search",placeholder:"Search chats\u2026",value:q,onChange:V=>ae(V.target.value),autoFocus:!0})]}),Le("div",{className:"acp-history-list",children:[Le("button",{className:"acp-history-item acp-history-item--new",onClick:Xy,children:[X(BA,{size:13}),X("span",{children:"New chat"})]}),jy.map(V=>Le("button",{className:"acp-history-item",onClick:()=>WA(V),children:[X(NA,{size:13}),X("span",{children:V.title})]},V.id)),jy.length===0&&q&&X("div",{className:"acp-history-empty",children:"No matching chats"})]})]})]}),X("div",{className:"acp-messages-wrap",children:Y?X("div",{className:"acp-empty",children:Le("div",{className:"acp-loading-session",children:[Le("div",{className:"acp-loading-dots",children:[X("span",{}),X("span",{}),X("span",{})]}),X("span",{className:"acp-status-text",children:"Loading chat\u2026"})]})}):N.length===0&&!k?Le("div",{className:"acp-empty",children:[X("div",{className:"acp-empty-icon",children:X(NA,{size:22})}),Le("div",{children:[X("div",{className:"acp-empty-title",children:"AI Ad Designer"}),X("div",{className:"acp-empty-sub",children:"Describe an ad and I'll create it on the canvas. Type @ to reference frames."})]}),X("div",{className:"acp-chips",children:lee.map(V=>X("button",{className:"acp-chip",onClick:()=>JA(V),children:V},V))})]}):Le(xA,{className:"acp-chat-root",children:[Le(yA,{className:"acp-chat-content",children:[N.filter((V,Re,$e)=>$e.findIndex(et=>et.id===V.id)===Re).map((V,Re,$e)=>{let et=V.role==="assistant",He=Re===$e.length-1;return X(Oy,{className:`acp-msg ${et?"acp-msg--assistant":"acp-msg--user"}`,children:et?Le("div",{className:"acp-msg-inner",children:[V.toolActions&&V.toolActions.length>0&&X(cee,{actions:V.toolActions}),V.reviewFeedback&&X(dee,{feedback:V.reviewFeedback}),X(zy,{markdown:!0,className:"acp-content-assistant",children:V.content}),X(Hy,{className:`acp-msg-actions${He?" acp-msg-actions--visible":""}`,children:X(Gy,{tooltip:"Copy",delayDuration:100,children:X("button",{className:"acp-action-btn",onClick:()=>Zy(V.id,V.content),children:Pn===V.id?X(DA,{size:14}):X(RA,{size:14})})})})]}):Le("div",{className:"acp-msg-inner",children:[V.attachments&&V.attachments.length>0&&X("div",{className:"acp-msg-attachments",children:V.attachments.map((Ve,uo)=>Ve.type==="image"&&Ve.dataUrl?X("img",{src:Ve.dataUrl,alt:Ve.name,className:"acp-msg-att-thumb",title:Ve.name},uo):Le("span",{className:"acp-msg-att-pill",children:[X(Yy,{size:11}),Ve.name]},uo))}),X(zy,{className:"acp-content-user",children:V.content}),X(Hy,{className:"acp-msg-actions",children:X(Gy,{tooltip:"Copy",delayDuration:100,children:X("button",{className:"acp-action-btn",onClick:()=>Zy(V.id,V.content),children:Pn===V.id?X(DA,{size:14}):X(RA,{size:14})})})})]})},V.id)}),k&&X(Oy,{className:"acp-msg acp-msg--assistant",children:X("div",{className:"acp-msg-inner",children:Le("div",{className:"acp-status-indicator",children:[Le("div",{className:"acp-loading-dots",children:[X("span",{}),X("span",{}),X("span",{})]}),!HA&&B&&X("span",{className:"acp-status-text",children:B})]})})})]}),X("div",{className:"acp-scroll-anchor",children:X(LA,{className:"acp-scroll-btn"})})]})}),J&&X("div",{className:"acp-error",children:J}),ue&&X("div",{className:"acp-ref-area",children:Le("div",{className:"acp-ref-pill",children:[X(_A,{size:12}),X("span",{children:ue.label}),X("button",{className:"acp-ref-remove",onClick:VA,title:"Remove reference",children:X($y,{size:10})})]})}),eo.length>0&&X("div",{className:"acp-attachments-area",children:eo.map(V=>Le("div",{className:"acp-attachment-pill",children:[V.type==="image"&&V.dataUrl?X("img",{src:V.dataUrl,alt:V.name,className:"acp-attachment-thumb"}):X(Yy,{size:12}),X("span",{children:V.name}),X("button",{className:"acp-attachment-remove",onClick:()=>XA(V.id),title:"Remove file",children:X($y,{size:10})})]},V.id))}),X("div",{className:"acp-input-area",children:Le("div",{className:"acp-input-wrapper",ref:eh,children:[ct&&X("div",{className:"acp-mention-menu",children:Sn.length>0?Sn.map(V=>Le("button",{className:"acp-mention-item",onClick:()=>$A(V),children:[X(_A,{size:14}),Le("span",{children:[V.name," ",Le("span",{className:"acp-mention-dim",children:["(",V.width,"x",V.height,", ",V.childCount," items)"]})]})]},V.id)):X("div",{className:"acp-mention-empty",children:"No frames on the canvas. Create a frame first, then type @ to reference it."})}),X("input",{ref:jd,type:"file",multiple:!0,accept:"image/*,.txt,.json,.csv,.md,.html,.css,.js,.ts,.tsx,.jsx,.py,.xml",onChange:KA,style:{display:"none"}}),Le(ml,{isLoading:k,value:D,onValueChange:YA,onSubmit:()=>Jd(),className:"acp-prompt-input",children:[X(pl,{placeholder:n?"Describe an ad to create\u2026 (@ for frames)":"Ask anything",className:"acp-textarea"}),Le(ul,{className:"acp-actions-bar",children:[Le("div",{className:"acp-actions-left",children:[X(Pr,{tooltip:"Attach files (max 3)",children:X("button",{className:"acp-pill-btn acp-pill-btn--icon",onClick:()=>jd.current?.click(),disabled:eo.length>=Qg,children:X(Yy,{size:16})})}),X(Pr,{tooltip:yt?"Web search enabled":"Enable web search",children:Le("button",{className:`acp-pill-btn${yt?" acp-pill-btn--active":""}`,onClick:ZA,children:[X(oee,{size:15}),X("span",{children:"Search"})]})})]}),Le("div",{className:"acp-actions-right",children:[X(Pr,{tooltip:$t?"Transcribing\u2026":De?"Stop recording":"Voice input",children:X("button",{className:`acp-pill-btn acp-pill-btn--icon${De?" acp-pill-btn--recording":""}${$t?" acp-pill-btn--transcribing":""}`,onClick:jA,disabled:$t,children:$t?X("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"acp-mic-spinner",children:X("path",{d:"M21 12a9 9 0 1 1-6.219-8.56"})}):De?X(ree,{size:16}):X(nee,{size:16})})}),X("button",{className:"acp-send-btn",onClick:k?qA:()=>Jd(),disabled:!k&&!D.trim(),title:k?"Stop":"Send",children:k?X("span",{className:"acp-stop-square"}):X(eee,{size:16})})]})]})]})]})})]})}):null});OA.displayName="AIChatPanel";function cee({actions:e}){let[t,o]=xt(!1);return Le("div",{className:"acp-tool-actions",children:[Le("button",{className:"acp-tool-actions-toggle",onClick:()=>o(n=>!n),children:[X(iee,{size:13}),Le("span",{children:[e.length," action",e.length!==1?"s":""," performed"]}),X(FA,{size:12,className:`acp-tool-chevron ${t?"acp-tool-chevron--open":""}`})]}),t&&X("div",{className:"acp-tool-actions-list",children:e.map((n,r)=>Le("div",{className:`acp-tool-action-item ${n.result.success?"acp-tool-action-item--ok":"acp-tool-action-item--err"}`,children:[X("span",{className:"acp-tool-action-dot"}),X("span",{children:n.result.statusMessage})]},r))})]})}function dee({feedback:e}){let[t,o]=xt(!1),n=a=>a==="critical"?"acp-review-issue--critical":a==="major"?"acp-review-issue--major":"acp-review-issue--minor",r=e.approved;return Le("div",{className:`acp-review-card ${r?"acp-review-card--ok":"acp-review-card--issues"}`,children:[Le("button",{className:"acp-review-toggle",onClick:()=>o(a=>!a),children:[X("span",{className:`acp-review-badge ${r?"acp-review-badge--ok":"acp-review-badge--issues"}`,children:r?"\u2713 Design approved":`${e.issues.length} issue${e.issues.length!==1?"s":""} found`}),X("span",{className:"acp-review-summary",children:e.summary}),!r&&e.issues.length>0&&X(FA,{size:12,className:`acp-tool-chevron ${t?"acp-tool-chevron--open":""}`})]}),t&&!r&&e.issues.length>0&&X("div",{className:"acp-review-issues",children:e.issues.map((a,i)=>Le("div",{className:`acp-review-issue ${n(a.severity)}`,children:[Le("div",{className:"acp-review-issue-header",children:[X("span",{className:"acp-review-issue-severity",children:a.severity}),X("span",{className:"acp-review-issue-element",children:a.element}),X("span",{className:"acp-review-issue-problem",children:a.problem})]}),Le("div",{className:"acp-review-issue-fix",children:["\u2192 ",a.preciseInstruction]})]},i))})]})}async function mee(e,t,o,n){let r=n?.chatModel||"google/gemini-3.1-flash-lite-preview",a=n?.webSearchEnabled?`${r}:online`:r,i=[];n?.brandContext&&i.push({role:"system",content:pee(n.brandContext)});let s=[...i,...e.map((d,u)=>{if(u===e.length-1&&d.role==="user"&&n?.attachments?.length){let g=[];for(let y of n.attachments)y.type==="image"&&y.dataUrl&&g.push({type:"image_url",image_url:{url:y.dataUrl}});let x=d.content,E=n.attachments.filter(y=>y.type==="text");return E.length>0&&(x+=`
|
|
592
592
|
|
|
593
593
|
${E.map(y=>`[File: ${y.name}]
|
|
594
594
|
${y.textContent}`).join(`
|
|
595
595
|
|
|
596
596
|
`)}`),g.push({type:"text",text:x}),{role:d.role,content:g}}return{role:d.role,content:d.content}})],l={model:a,messages:s};n?.webSearchEnabled&&(l.plugins=[{id:"web",max_results:5}]),n?.onChunk&&(l.stream=!0);let c=await fetch("https://openrouter.ai/api/v1/chat/completions",{method:"POST",signal:o,headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json"},body:JSON.stringify(l)});if(!c.ok){let d=`OpenRouter error ${c.status}`;try{let u=await c.json();u?.error?.message&&(d=u.error.message)}catch{}throw new Error(d)}if(n?.onChunk&&qg(c)){let d="";try{for await(let u of jg(c))u.content&&(d+=u.content,n.onChunk(u.content))}catch(u){if(u.name==="AbortError")throw u;if(d)return d;throw u}if(!d)throw new Error("No response returned by the API.");return d}let p=(await c.json())?.choices?.[0]?.message?.content;if(!p)throw new Error("No response returned by the API.");return p}function pee(e){let t=["## Brand Identity \u2014 use these guidelines for copywriting and design suggestions"];if(e.colors){let{primary:o,secondary:n,accent:r,background:a}=e.colors,i=[o&&`Primary: ${o}`,n&&`Secondary: ${n}`,r&&`Accent/CTA: ${r}`,a&&`Background: ${a}`].filter(Boolean);i.length&&t.push(`**Colors**: ${i.join(", ")}`)}if(e.typography){let{headline:o,body:n}=e.typography;o?.family&&t.push(`**Headline font**: ${o.family}${o.weight?` weight ${o.weight}`:""}`),n?.family&&t.push(`**Body font**: ${n.family}${n.weight?` weight ${n.weight}`:""}`)}if(e.visualStyle&&t.push(`**Visual style**: ${e.visualStyle}`),e.layoutPattern&&t.push(`**Layout pattern**: ${e.layoutPattern}`),e.toneOfVoice){let{register:o,vocabulary:n,ctaStyle:r}=e.toneOfVoice,a=[o&&`register: ${o}`,n&&`vocabulary: ${n}`,r&&`CTA style: ${r}`].filter(Boolean);a.length&&t.push(`**Tone of voice**: ${a.join(", ")}`)}if(e.imagery){let{type:o,lighting:n,composition:r}=e.imagery,a=[o&&`type: ${o}`,n&&`lighting: ${n}`,r&&`composition: ${r}`].filter(Boolean);a.length&&t.push(`**Imagery direction**: ${a.join(", ")}`)}return t.join(`
|
|
597
|
-
`)}import{jsx as Vy}from"react/jsx-runtime";J6();var bee=e=>{let{onChange:t,onIncrement:o,initialData:n,excalidrawAPI:r,isCollaborating:a=!1,onPointerUpdate:i,renderTopLeftUI:s,renderTopRightUI:l,langCode:c=Nn.code,viewModeEnabled:m,zenModeEnabled:p,gridModeEnabled:d,libraryReturnUrl:u,theme:h,name:g,renderCustomStats:x,onPaste:E,detectScroll:y=!0,handleKeyboardGlobally:w=!1,onLibraryChange:v,autoFocus:I=!1,generateIdForFile:C,onLinkOpen:P,generateLinkForSelection:S,onPointerDown:D,onPointerUp:_,onScrollChange:k,onDuplicate:M,children:B,validateEmbeddable:O,renderEmbeddable:N,aiEnabled:z,showDeprecatedFonts:L,geminiApiKey:F,leonardoApiKey:$,openRouterApiKey:Q,removeBgApiKey:Z,renderScrollbars:U,onBeforeImageGen:q,onAfterImageGen:
|
|
597
|
+
`)}import{jsx as Vy}from"react/jsx-runtime";J6();var bee=e=>{let{onChange:t,onIncrement:o,initialData:n,excalidrawAPI:r,isCollaborating:a=!1,onPointerUpdate:i,renderTopLeftUI:s,renderTopRightUI:l,langCode:c=Nn.code,viewModeEnabled:m,zenModeEnabled:p,gridModeEnabled:d,libraryReturnUrl:u,theme:h,name:g,renderCustomStats:x,onPaste:E,detectScroll:y=!0,handleKeyboardGlobally:w=!1,onLibraryChange:v,autoFocus:I=!1,generateIdForFile:C,onLinkOpen:P,generateLinkForSelection:S,onPointerDown:D,onPointerUp:_,onScrollChange:k,onDuplicate:M,children:B,validateEmbeddable:O,renderEmbeddable:N,aiEnabled:z,showDeprecatedFonts:L,geminiApiKey:F,leonardoApiKey:$,openRouterApiKey:Q,removeBgApiKey:Z,renderScrollbars:U,onBeforeImageGen:q,onAfterImageGen:ae,onBeforeUpscale:J,onAfterUpscale:te,onBeforeRemoveBg:ue,onAfterRemoveBg:Me,onBeforeAutoResize:ct,onAfterAutoResize:Lt,agentImageModel:Sn,chatModel:Mn,showLibraryButton:eo,imageEditToolbarCallbacks:Gt,customFonts:yt,onSaveTemplate:dr,onFetchAllAssets:Y,onSearchBrandAssets:ne,onListBrandTemplates:De,onGetTemplateVariant:ft}=e,$t=e.UIOptions?.canvasActions,Oo={...e.UIOptions,canvasActions:{...zA.canvasActions,...$t},tools:{image:e.UIOptions?.tools?.image??!0}};return $t?.export&&(Oo.canvasActions.export.saveFileToDisk=$t.export?.saveFileToDisk??zA.canvasActions.export.saveFileToDisk),Oo.canvasActions.toggleTheme===null&&typeof h>"u"&&(Oo.canvasActions.toggleTheme=!0),gee(()=>{(async()=>{await import("canvas-roundrect-polyfill")})();let Fr=Oa=>{typeof Oa.scale=="number"&&Oa.scale!==1&&Oa.preventDefault()};return document.addEventListener("touchmove",Fr,{passive:!1}),()=>{document.removeEventListener("touchmove",Fr)}},[]),hee(()=>{for(let Pn of yt??[])Ho.registerCustomFont(Pn)},[yt]),Vy(TE,{store:Et,children:Vy(U6,{langCode:c,theme:h,children:Vy(G6,{onChange:t,onIncrement:o,initialData:n,excalidrawAPI:r,isCollaborating:a,onPointerUpdate:i,renderTopLeftUI:s,renderTopRightUI:l,langCode:c,viewModeEnabled:m,zenModeEnabled:p,gridModeEnabled:d,libraryReturnUrl:u,theme:h,name:g,renderCustomStats:x,UIOptions:Oo,onPaste:E,detectScroll:y,handleKeyboardGlobally:w,onLibraryChange:v,autoFocus:I,generateIdForFile:C,onLinkOpen:P,generateLinkForSelection:S,onPointerDown:D,onPointerUp:_,onScrollChange:k,onDuplicate:M,validateEmbeddable:O,renderEmbeddable:N,aiEnabled:z!==!1,showDeprecatedFonts:L,geminiApiKey:F,leonardoApiKey:$,openRouterApiKey:Q,removeBgApiKey:Z,renderScrollbars:U,onBeforeImageGen:q,onAfterImageGen:ae,onBeforeUpscale:J,onAfterUpscale:te,onBeforeRemoveBg:ue,onAfterRemoveBg:Me,onBeforeAutoResize:ct,onAfterAutoResize:Lt,agentImageModel:Sn,chatModel:Mn,showLibraryButton:eo,imageEditToolbarCallbacks:Gt,onSaveTemplate:dr,onFetchAllAssets:Y,onSearchBrandAssets:ne,onListBrandTemplates:De,onGetTemplateVariant:ft,children:B})})})},xee=(e,t)=>{if(e.children!==t.children)return!1;let{initialData:o,UIOptions:n={},...r}=e,{initialData:a,UIOptions:i={},...s}=t,l=Object.keys(n),c=Object.keys(i);return l.length!==c.length?!1:l.every(p=>p==="getFormFactor"?!0:p==="canvasActions"?Object.keys(n.canvasActions).every(u=>u==="export"&&n?.canvasActions?.export&&i?.canvasActions?.export?n.canvasActions.export.saveFileToDisk===i.canvasActions.export.saveFileToDisk:n?.canvasActions?.[u]===i?.canvasActions?.[u]):n[p]===i[p])&&fee(r,s)},yee=uee.memo(bee,xee);yee.displayName="Excalidraw";export{OA as AIChatPanel,so as Button,vJe as CaptureUpdateAction,_O as CommandPalette,gJe as DEFAULT_LASER_COLOR,ig as DefaultSidebar,tQ as DiagramToCodePlugin,xc as Ellipsify,yee as Excalidraw,pJe as FONT_FAMILY,RJ as Footer,FJ as LiveCollaborationTrigger,uJe as MIME_TYPES,jt as MainMenu,Cp as ROUNDNESS,tn as Sidebar,Md as Stats,gM as THEME,hg as TTDDialog,oA as TTDDialogTrigger,QJ as TTDStreamFetch,hJe as UserIdleState,UJ as WelcomeScreen,Us as bumpVersion,hM as convertToExcalidrawElements,Nn as defaultLang,S5 as elementPartiallyOverlapsWithOrContainsBBox,M5 as elementsOverlappingBBox,AT as exportToBlob,na as exportToCanvas,K9 as exportToClipboard,Vs as exportToSvg,NJe as getCommonBounds,Vi as getDataURL,xJe as getFormFactor,_p as getLibraryItemsHash,qqe as getNonDeletedElements,Xqe as getSceneVersion,Qqe as getTextFromElements,BJe as getVisibleSceneBounds,Zqe as hashElementsVersion,jqe as hashString,x0 as isElementInsideBBox,GJe as isElementLink,tJe as isInvisiblySmallElement,dJe as isLinearElement,Zi as languages,lm as loadFromBlob,ph as loadLibraryFromBlob,mh as loadSceneOrLibraryFromBlob,zT as mergeLibraryItems,Sp as mutateElement,EJe as newElementWith,fJe as normalizeLink,_b as parseLibraryTokensFromUrl,qJ as reconcileElements,$i as restoreAppState,tL as restoreElement,Ga as restoreElements,Ql as restoreLibraryItems,CT as sceneCoordsToViewportCoords,jl as serializeAsJSON,eL as serializeLibraryAsJSON,WJe as setCustomTextMetricsProvider,Te as useEditorInterface,cB as useHandleLibrary,Ue as useI18n,Dt as useStylesPanelMode,bJe as viewportCoordsToSceneCoords,B2 as zoomToFitBounds};
|