@orangecatai/adgen-canvas 0.0.2 → 0.0.4
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-UV7ECD7A.js → chunk-3FGOYDLK.js} +3 -3
- package/dist/dev/{chunk-X2WWSILD.js → chunk-IRIUFXMO.js} +2 -2
- package/dist/dev/data/{image-H4O52A73.js → image-HH4XNQRO.js} +3 -3
- package/dist/dev/index.css +880 -1
- package/dist/dev/index.css.map +3 -3
- package/dist/dev/index.js +2970 -232
- package/dist/dev/index.js.map +4 -4
- package/dist/dev/subset-shared.chunk.js +1 -1
- package/dist/dev/subset-worker.chunk.js +1 -1
- package/dist/prod/{chunk-DOJFO2UO.js → chunk-LUZI7MFZ.js} +2 -2
- package/dist/prod/{chunk-O3WJMHIE.js → chunk-SG4RCQVC.js} +1 -1
- package/dist/prod/data/image-J2ZJZU4A.js +1 -0
- package/dist/prod/index.css +1 -1
- package/dist/prod/index.js +84 -29
- package/dist/prod/subset-shared.chunk.js +1 -1
- package/dist/prod/subset-worker.chunk.js +1 -1
- package/dist/types/excalidraw/actions/actionAddToLibrary.d.ts +1 -1
- package/dist/types/excalidraw/actions/actionCanvas.d.ts +177 -0
- package/dist/types/excalidraw/actions/actionClipboard.d.ts +7 -7
- package/dist/types/excalidraw/actions/actionCropEditor.d.ts +2 -2
- package/dist/types/excalidraw/actions/actionDuplicateSelection.d.ts +2 -2
- package/dist/types/excalidraw/actions/actionElementLink.d.ts +6 -6
- package/dist/types/excalidraw/actions/actionEmbeddable.d.ts +1 -1
- package/dist/types/excalidraw/actions/actionLinearEditor.d.ts +7 -7
- package/dist/types/excalidraw/actions/actionLink.d.ts +3 -3
- package/dist/types/excalidraw/actions/actionMenu.d.ts +1 -1
- package/dist/types/excalidraw/actions/actionSelectAll.d.ts +4 -4
- package/dist/types/excalidraw/actions/actionStyles.d.ts +2 -2
- package/dist/types/excalidraw/actions/actionToggleObjectsSnapMode.d.ts +4 -4
- package/dist/types/excalidraw/actions/actionToggleShapeSwitch.d.ts +3 -3
- package/dist/types/excalidraw/actions/actionToggleStats.d.ts +2 -2
- package/dist/types/excalidraw/actions/actionToggleViewMode.d.ts +4 -4
- package/dist/types/excalidraw/actions/actionToggleZenMode.d.ts +4 -4
- package/dist/types/excalidraw/actions/actionZindex.d.ts +8 -8
- package/dist/types/excalidraw/actions/index.d.ts +1 -1
- package/dist/types/excalidraw/actions/types.d.ts +1 -1
- package/dist/types/excalidraw/components/AIChatPanel.d.ts +49 -3
- package/dist/types/excalidraw/components/Actions.d.ts +3 -0
- package/dist/types/excalidraw/components/DefaultSidebar.d.ts +1 -1
- package/dist/types/excalidraw/components/ImageGeneratorPanel.d.ts +6 -1
- package/dist/types/excalidraw/components/ImageQuickEditPanel.d.ts +6 -1
- package/dist/types/excalidraw/components/Sidebar/Sidebar.d.ts +2 -2
- package/dist/types/excalidraw/components/ai-chat/agentLoop.d.ts +13 -0
- package/dist/types/excalidraw/components/ai-chat/audioUtils.d.ts +10 -0
- package/dist/types/excalidraw/index.d.ts +5 -0
- package/dist/types/excalidraw/types.d.ts +14 -0
- package/dist/types/excalidraw/utils/openRouterApiKey.d.ts +1 -0
- package/package.json +1 -1
- package/dist/prod/data/image-43FV5SMF.js +0 -1
- /package/dist/dev/{chunk-UV7ECD7A.js.map → chunk-3FGOYDLK.js.map} +0 -0
- /package/dist/dev/{chunk-X2WWSILD.js.map → chunk-IRIUFXMO.js.map} +0 -0
- /package/dist/dev/data/{image-H4O52A73.js.map → image-HH4XNQRO.js.map} +0 -0
package/dist/prod/index.js
CHANGED
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
import{$ as uu,A as mu,B as Uk,C as Lb,D as Ab,E as wc,F as Ss,G as vc,H as Tc,I as ks,J as Db,K as _b,L as Rb,M as Ic,N as Ni,O as Nb,P as Wk,Q as Vr,R as Bi,S as Ms,U as Bb,W as Fb,X as Ob,Y as Cc,Z as zb,_ as pu,a as Sb,aa as Sc,b as Yr,ba as Hb,c as Go,ca as gu,d as kb,da as Kr,e as Le,ea as Gb,f as Mb,fa as hu,g as ne,ga as Ub,h as Ai,ha as fu,i as Uo,ia as Wb,j as vs,ja as kc,k as Ts,ka as bu,l as Di,la as Yb,m as Is,ma as Vb,n as _i,na as Kb,o as Pb,oa as Ps,p as cu,q as Wo,r as Yn,s as Vn,t as Gt,u as wn,v as Ri,w as Ec,x as du,y as Cs,z as yc}from"./chunk-DOJFO2UO.js";import{a as I}from"./chunk-O3WJMHIE.js";import{M as lu}from"./chunk-MSBJ7C4T.js";import{c as Cb}from"./chunk-3PELD44J.js";import{b as Tb,c as Ib,d as k}from"./chunk-SRAX5OIU.js";import sX,{useEffect as lX}from"react";import{DEFAULT_UI_OPTIONS as Gk,isShallowEqual as cX}from"@orangecatai/common";import x4 from"clsx";import OY from"lodash.throttle";import En,{useContext as Gr}from"react";import{flushSync as Xt}from"react-dom";import zY from"roughjs/bin/rough";import{nanoid as S0}from"nanoid";import{clamp as E4,pointFrom as ie,pointDistance as Rr,vector as y4,pointRotateRads as k0,vectorFromPoint as M0,vectorSubtract as w4,vectorDot as v4,vectorNormalize as T4}from"@orangecatai/math";import{COLOR_PALETTE as HY,CODES as I4,shouldResizeFromCenter as C4,shouldMaintainAspectRatio as oc,shouldRotateWithDiscreteAngle as S4,isArrowKey as Yp,KEYS as j,APP_NAME as GY,CURSOR_TYPE as Ke,DEFAULT_MAX_IMAGE_WIDTH_OR_HEIGHT as UY,DEFAULT_VERTICAL_ALIGN as k4,DRAGGING_THRESHOLD as M4,ELEMENT_SHIFT_TRANSLATE_AMOUNT as WY,ELEMENT_TRANSLATE_AMOUNT as P4,EVENT as ce,FRAME_STYLE as To,IMAGE_MIME_TYPES as YY,IMAGE_RENDER_TIMEOUT as VY,LINE_CONFIRM_THRESHOLD as P0,MAX_ALLOWED_FILE_BYTES as L4,MIME_TYPES as gn,MQ_RIGHT_SIDEBAR_MIN_WIDTH as KY,POINTER_BUTTON as Nr,ROUNDNESS as Vp,SCROLL_TIMEOUT as XY,TAP_TWICE_TIMEOUT as $Y,TEXT_TO_CENTER_SNAP_THRESHOLD as ZY,THEME as Kp,TOUCH_CTX_MENU_TIMEOUT as jY,VERTICAL_ALIGN as qY,YOUTUBE_STATES as Xp,ZOOM_STEP as JY,POINTER_EVENTS as hs,TOOL_TYPE as hn,supportsResizeObserver as QY,DEFAULT_COLLISION_THRESHOLD as A4,DEFAULT_TEXT_ALIGN as eV,ARROW_TYPE as Br,DEFAULT_REDUCED_GLOBAL_ALPHA as tV,isLocalLink as oV,normalizeLink as L0,toValidURL as nV,getGridPoint as Pt,getLineHeight as D4,debounce as _4,distance as fs,getFontString as A0,getNearestScrollableContainer as rV,isInputLike as R4,isToolIcon as iV,isWritableElement as nc,sceneCoordsToViewportCoords as $p,tupleToCoors as D0,viewportCoordsToSceneCoords as Ue,wrapEvent as aV,updateObject as _0,updateActiveTool as fn,isTransparent as sV,easeToValuesRAF as lV,muteFSAbortError as cV,isTestEnv as Ek,isDevEnv as yk,easeOut as dV,updateStable as rc,addEventListener as Je,normalizeEOL as mV,getDateTime as N4,isShallowEqual as B4,arrayToMap as Zp,applyDarkModeFilter as pV,randomInteger as uV,CLASSES as R0,Emitter as Pi,MINIMUM_ARROW_SIZE as gV,DOUBLE_TAP_POSITION_THRESHOLD as hV,BIND_MODE_TIMEOUT as fV,invariant as bn,getFeatureFlag as Un,createUserAgentDescriptor as wk,getFormFactor as bV,deriveStylesPanelMode as ou,isIOS as xV,isBrave as EV,isSafari as yV,loadDesktopUIModePreference as wV,setDesktopUIMode as vV,isSelectionLikeTool as jp,oneOf as F4}from"@orangecatai/common";import{getObservedAppState as TV,getCommonBounds as bs,getElementAbsoluteCoords as qp,bindOrUnbindBindingElements as O4,fixBindingsAfterDeletion as IV,getHoveredElementForBinding as zo,isBindingEnabled as ic,shouldEnableBindingForPointerEvent as CV,updateBoundElements as Jp,LinearElementEditor as ve,newElementWith as Fr,newFrameElement as z4,newFreeDrawElement as SV,newEmbeddableElement as H4,newMagicFrameElement as G4,newIframeElement as kV,newArrowElement as MV,newElement as PV,newImageElement as N0,newLinearElement as LV,newTextElement as U4,refreshTextDimensions as AV,deepCopyElement as W4,duplicateElements as B0,hasBoundTextElement as Y4,isArrowElement as xs,isBindingElement as xn,isBindingElementType as DV,isBoundToContainer as F0,isFrameLikeElement as Lt,isImageElement as Or,isEmbeddableElement as Wn,isInitializedImageElement as ac,isLinearElement as zt,isLinearElementType as _V,isUsingAdaptiveRadius as RV,isIframeElement as Es,isIframeLikeElement as O0,isMagicFrameElement as z0,isTextBindableContainer as V4,isElbowArrow as $t,isFlowchartNodeElement as NV,isBindableElement as H0,isTextElement as Ho,getNormalizedDimensions as BV,isElementCompletelyInViewport as G0,isElementInViewport as K4,isInvisiblySmallElement as X4,getCornerRadius as FV,isPathALoop as $4,createSrcDoc as Z4,embeddableURLValidator as U0,maybeParseEmbedSrc as OV,getEmbedLink as Qp,getInitializedImageElements as zV,normalizeSVG as j4,updateImageCache as HV,getBoundTextElement as W0,getContainerCenter as Y0,getContainerElement as q4,isValidTextContainer as GV,redrawTextBoundingBox as UV,hasBoundingBox as WV,getFrameChildren as V0,isCursorInFrame as J4,addElementsToFrame as K0,replaceAllElementsInFrame as YV,removeElementsFromFrame as VV,getElementsInResizingFrame as X0,getElementsInNewFrame as KV,getContainingFrame as $0,elementOverlapsWithFrame as XV,updateFrameMembershipOfSelectedElements as Q4,isElementInFrame as ek,getFrameLikeTitle as $V,getElementsOverlappingFrame as ZV,filterElementsEligibleAsFrameChildren as jV,hitElementBoundText as qV,hitElementBoundingBoxOnly as JV,hitElementItself as sc,getVisibleSceneBounds as QV,FlowChartCreator as eK,FlowChartNavigator as tK,getLinkDirectionFromKey as tk,cropElement as oK,wrapText as nK,isElementLink as Z0,parseElementLinkFromURL as rK,isMeasureTextSupported as iK,normalizeText as aK,measureText as ok,getLineHeightInPx as sK,getApproxMinLineWidth as lK,getApproxMinLineHeight as cK,getMinTextElementWidth as dK,ShapeCache as lc,getRenderOpacity as mK,editGroupForSelectedElement as pK,getElementsInGroup as Li,getSelectedGroupIdForElement as uK,getSelectedGroupIds as gK,isElementInGroup as nk,isSelectedViaGroup as hK,selectGroupsForSelectedElements as Io,syncInvalidIndices as vk,syncMovedIndices as rk,excludeElementsInFramesFromSelection as fK,getSelectionStateForElements as bK,makeNextSelectedElementIds as Pe,getResizeOffsetXY as xK,getResizeArrowDirection as EK,transformElements as yK,getCursorForResizingElement as ik,getElementWithTransformHandleType as ak,getTransformHandleTypeFromCoords as sk,dragNewElement as lk,dragSelectedElements as wK,getDragOffsetXY as vK,isNonDeletedElement as ck,Scene as dk,Store as TK,CaptureUpdateAction as Ht,hitElementBoundingBox as IK,isLineElement as j0,isSimpleArrow as q0,StoreDelta as mk,positionElementsOnGrid as pk,calculateFixedPointForNonElbowArrowBinding as uk,bindOrUnbindBindingElement as CK,mutateElement as eu,getElementBounds as gk,doBoundsIntersect as SK,isPointInElement as kK,maxBindingDistance_simple as J0,convertToExcalidrawElements as hk,getSnapOutlineMidPoint as Q0,handleFocusPointDrag as MK,handleFocusPointHover as PK,handleFocusPointPointerDown as LK,handleFocusPointPointerUp as AK,maybeHandleArrowPointlikeDrag as tu,getUncroppedWidthAndHeight as DK}from"@orangecatai/element";import{KEYS as Wu,MOBILE_ACTION_BUTTON_BG as o6,updateActiveTool as n6}from"@orangecatai/common";import{getNonDeletedElements as Yu}from"@orangecatai/element";import{fixBindingsAfterDeletion as r6}from"@orangecatai/element";import{LinearElementEditor as VE}from"@orangecatai/element";import{newElementWith as $c}from"@orangecatai/element";import{getContainerElement as KE}from"@orangecatai/element";import{isBoundToContainer as Kc,isElbowArrow as i6,isFrameLikeElement as a6}from"@orangecatai/element";import{getFrameChildren as s6}from"@orangecatai/element";import{getElementsInGroup as Vu,selectGroupsForSelectedElements as l6}from"@orangecatai/element";import{CaptureUpdateAction as Xc}from"@orangecatai/element";import{isDevEnv as Xk}from"@orangecatai/common";import{atom as ye,createStore as Yk}from"jotai";import{createIsolation as Vk}from"jotai-scope";var Xb=Vk();var{useAtom:ee,useSetAtom:Yo,useAtomValue:Fi,useStore:hX}=Xb,$b=Xb.Provider,ot=Yk();var Kk=Tb({"./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 $k=85,Vo={code:"en",label:"English"},zi=[Vo,...[{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=>Cb[e.code]>=$k).sort((e,o)=>e.label>o.label?1:-1)],Pc="__test__";Xk()&&zi.unshift({code:Pc,label:"test language"},{code:`${Pc}.rtl`,label:"\u202Atest language (rtl)\u202C",rtl:!0});var Oi=Vo,Mc={},Lc=async e=>{if(Oi=e,document.documentElement.dir=Oi.rtl?"rtl":"ltr",document.documentElement.lang=Oi.code,e.code.startsWith(Pc))Mc={};else try{Mc=await Kk(`./locales/${Oi.code}.json`)}catch(o){console.error(`Failed to load language ${e.code}:`,o.message),Mc=lu}ot.set(jb,e.code)},vn=()=>Oi,Zb=(e,o)=>{for(let t=0;t<o.length;++t){let n=o[t];if(e[n]===void 0)return;e=e[n]}if(typeof e=="string")return e},h=(e,o,t)=>{if(Oi.code.startsWith(Pc))return`\u202A[[${o?`${e}(${JSON.stringify(o).slice(1,-1)})`:e}]]\u202C`;let n=e.split("."),r=Zb(Mc,n)||Zb(lu,n)||t;if(r===void 0){let i=`Can't find translation for ${e}`;if(I.PROD)return console.warn(i),"";throw new Error(i)}if(o)for(let i in o)r=r.replace(`{{${i}}}`,String(o[i]));return r},jb=ye(Vo.code),Ae=()=>{let e=Fi(jb);return{t:h,langCode:e}};import Zk from"clsx";import pt from"react";import{THEME as jk}from"@orangecatai/common";import{Fragment as De,jsx as f,jsxs as B}from"react/jsx-runtime";var So=e=>"var(--icon-fill-color)",qb=e=>e===jk.LIGHT?"#fff":"#1e1e1e",L=(e,o=512)=>{let{width:t=512,height:n=t,mirror:r,style:i,...a}=typeof o=="number"?{width:o}:o;return f("svg",{"aria-hidden":"true",focusable:"false",role:"img",viewBox:`0 0 ${t} ${n}`,className:Zk({"rtl-mirror":r}),style:i,...a,children:typeof e=="string"?f("path",{fill:"currentColor",d:e}):e})},U={width:24,height:24,fill:"none",strokeWidth:2,stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round"},de={width:20,height:20,fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round"},LX=L(B("g",{strokeWidth:"1.5",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("rect",{x:3,y:8,width:18,height:4,rx:1}),f("line",{x1:12,y1:8,x2:12,y2:21}),f("path",{d:"M19 12v7a2 2 0 0 1 -2 2h-10a2 2 0 0 1 -2 -2v-7"}),f("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"})]}),U),Ac=L(B("g",{strokeWidth:"1.25",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M3 19a9 9 0 0 1 9 0a9 9 0 0 1 9 0"}),f("path",{d:"M3 6a9 9 0 0 1 9 0a9 9 0 0 1 9 0"}),f("line",{x1:"3",y1:"6",x2:"3",y2:"19"}),f("line",{x1:"12",y1:"6",x2:"12",y2:"19"}),f("line",{x1:"21",y1:"6",x2:"21",y2:"19"})]}),U),Jb=L(B("svg",{strokeWidth:"1.5",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),f("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]}),U),Qb=L(B("g",{strokeWidth:"1.5",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("circle",{cx:"12",cy:"12",r:"1"}),f("circle",{cx:"12",cy:"19",r:"1"}),f("circle",{cx:"12",cy:"5",r:"1"})]}),U),ex=L(B("g",{strokeWidth:"1.5",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M5 12m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0"}),f("path",{d:"M12 12m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0"}),f("path",{d:"M19 12m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0"})]}),U),tx=L(B("svg",{strokeWidth:"1.5",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M9 4v6l-2 4v2h10v-2l-2 -4v-6"}),f("line",{x1:"12",y1:"16",x2:"12",y2:"21"}),f("line",{x1:"8",y1:"4",x2:"16",y2:"4"})]}),U),xu=L(B("g",{strokeWidth:1.25,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M12 5m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"}),f("path",{d:"M19 8m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"}),f("path",{d:"M5 11m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"}),f("path",{d:"M15 19m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"}),f("path",{d:"M6.5 9.5l3.5 -3"}),f("path",{d:"M14 5.5l3 1.5"}),f("path",{d:"M18.5 10l-2.5 7"}),f("path",{d:"M13.5 17.5l-7 -5"})]}),U),Xr=L(B("g",{children:[f("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"}),f("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"}),f("mask",{id:"UnlockedIcon",style:{maskType:"alpha"},maskUnits:"userSpaceOnUse",x:6,y:1,width:9,height:9,children:f("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"})}),f("g",{mask:"url(#UnlockedIcon)",children:f("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"})})]}),de),Hi=L(B("g",{strokeWidth:"1.25",children:[f("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"}),f("path",{d:"M10 13.958a1.042 1.042 0 1 0 0-2.083 1.042 1.042 0 0 0 0 2.083Z"}),f("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"})]}),de),ox=L(f("g",{fill:"currentColor",children:f("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}),nx=L(B(De,{children:[f("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"}),f("path",{fillRule:"evenodd",clipRule:"evenodd",d:"m12.005 10.478 7.905 14.423L6 25.75l6.005-15.273Z",fill:"currentColor"}),f("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"}),rx=L(B(De,{children:[f("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"}),f("path",{fillRule:"evenodd",clipRule:"evenodd",d:"m72.181 59.247-13.058-10-2.948 13.62 16.006-3.62Z",fill:"currentColor"}),f("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"}),ix=L(B(De,{children:[f("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"}),f("path",{fillRule:"evenodd",clipRule:"evenodd",d:"m24.165 1.093-2.132 16.309 13.27-4.258-11.138-12.05Z",fill:"currentColor"}),f("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"}),AX=L(f("g",{fill:"currentColor",children:f("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"}),$r=L(B("g",{stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("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"}),f("path",{d:"M13.5 13.5l4.5 4.5"})]}),{fill:"none",width:22,height:22,strokeWidth:1.25}),Kn=L(B("g",{stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,children:[f("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"}),f("path",{d:"M5 15m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"}),f("path",{d:"M5 17c0 1.42 .316 2.805 1 4"})]}),{fill:"none",width:22,height:22,strokeWidth:1.25}),Gi=L(B("g",{strokeWidth:"1.5",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"})]}),U),Ui=L(B("g",{strokeWidth:"1.5",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("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"})]}),U),Wi=L(B("g",{strokeWidth:"1.5",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("circle",{cx:"12",cy:"12",r:"9"})]}),U),Dc=L(B("g",{strokeWidth:"1.5",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("line",{x1:"5",y1:"12",x2:"19",y2:"12"}),f("line",{x1:"15",y1:"16",x2:"19",y2:"12"}),f("line",{x1:"15",y1:"8",x2:"19",y2:"12"})]}),U),Yi=L(f("path",{d:"M4.167 10h11.666",strokeWidth:"1.5"}),de),ax=L(B("g",{strokeWidth:"1.25",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M20 17v-12c0 -1.121 -.879 -2 -2 -2s-2 .879 -2 2v12l2 2l2 -2z"}),f("path",{d:"M16 7h4"}),f("path",{d:"M18 19h-13a2 2 0 1 1 0 -4h4a2 2 0 1 0 0 -4h-3"})]}),U),Ko=L(B("g",{strokeWidth:"1.25",children:[f("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"}),f("path",{d:"m11.25 5.417 3.333 3.333"})]}),de),Xo=L(B("g",{strokeWidth:"1.5",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("line",{x1:"4",y1:"20",x2:"7",y2:"20"}),f("line",{x1:"14",y1:"20",x2:"21",y2:"20"}),f("line",{x1:"6.9",y1:"15",x2:"13.8",y2:"15"}),f("line",{x1:"10.2",y1:"6.3",x2:"16",y2:"20"}),f("polyline",{points:"5 20 11 4 13 4 20 20"})]}),U),sx=L(B("g",{stroke:"currentColor",strokeWidth:"1.5",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M3 7v-2h13v2"}),f("path",{d:"M10 5v14"}),f("path",{d:"M12 19h-4"}),f("path",{d:"M15 13v-1h6v1"}),f("path",{d:"M18 12v7"}),f("path",{d:"M17 19h2"})]}),U),Xn=L(B("g",{strokeWidth:"1.25",children:[f("path",{d:"M12.5 6.667h.01"}),f("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"}),f("path",{d:"m3.333 12.5 3.334-3.333c.773-.745 1.726-.745 2.5 0l4.166 4.166"}),f("path",{d:"m11.667 11.667.833-.834c.774-.744 1.726-.744 2.5 0l1.667 1.667"})]}),de),_c=L(B("g",{strokeWidth:"1.5",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("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"}),f("path",{d:"M18 13.3l-6.3 -6.3"})]}),U),Eu=L(f("path",{strokeWidth:"1.25",d:"M10 4.167v11.666M4.167 10h11.666"}),de),yu=L(f("path",{d:"M5 10h10",strokeWidth:"1.25"}),de),lx=L(B("g",{strokeWidth:1.25,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M21 21l-6 -6"}),f("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"}),f("path",{d:"M3 4v4h4"})]}),U),yt=L(f("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"}),de),Vi=L(B("g",{strokeWidth:"1.5",children:[f("polyline",{points:"12 16 18 10 12 4"}),f("polyline",{points:"8 4 2 10 8 16"})]}),de),Ls=L(B("g",{strokeWidth:"1.25",children:[f("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"}),f("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"})]}),de),As=L(f("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"}),de),Ds=L(f("g",{stroke:"currentColor",strokeLinejoin:"round",children:f("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"})}),{...de,strokeWidth:1.5}),cx=L(B("g",{strokeWidth:"1.5",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("line",{x1:"4",y1:"6",x2:"20",y2:"6"}),f("line",{x1:"4",y1:"12",x2:"20",y2:"12"}),f("line",{x1:"4",y1:"18",x2:"20",y2:"18"})]}),U),Zr=L(f("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"}),de),Ki=L(B("g",{strokeWidth:"1.5",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("circle",{cx:"12",cy:"12",r:"9"}),f("line",{x1:"12",y1:"17",x2:"12",y2:"17.01"}),f("path",{d:"M12 13.5a1.5 1.5 0 0 1 1 -1.5a2.6 2.6 0 1 0 -3 -4"})]}),U),dx=L(B("g",{strokeWidth:"1.25",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("circle",{cx:"12",cy:"12",r:"9"}),f("line",{x1:"12",y1:"17",x2:"12",y2:"17.01"}),f("path",{d:"M12 13.5a1.5 1.5 0 0 1 1 -1.5a2.6 2.6 0 1 0 -3 -4"})]}),U),wu=L(f("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"}),de),Rc=L(f("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"}),de),mx=L(B("g",{strokeWidth:"1.25",children:[f("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"}),f("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"})]}),de),px=L(B("g",{strokeWidth:"1.25",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M4 4l11.733 16h4.267l-11.733 -16z"}),f("path",{d:"M4 20l6.768 -6.768m2.46 -2.46l6.772 -6.772"})]}),U),Nc=L(f("polyline",{fill:"none",stroke:"currentColor",points:"20 6 9 17 4 12"}),{width:24,height:24}),_s=L(B("g",{strokeWidth:"1.25",children:[f("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"}),f("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"})]}),de),ux=L("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}),gx=L("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}),Xi=L(f("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"}),de),DX=L("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}),_X=L("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"),Bc=L(B("g",{strokeWidth:1.25,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M5 16l1.465 1.638a2 2 0 1 1 -3.015 .099l1.55 -1.737z"}),f("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"}),f("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"})]}),U),hx=L(f("g",{strokeWidth:1.5,children:f("path",{d:"M6 18l12 -12"})}),U),Fc=L(B("g",{strokeWidth:"1.25",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M15 8h.01"}),f("path",{d:"M12 20h-5a3 3 0 0 1 -3 -3v-10a3 3 0 0 1 3 -3h10a3 3 0 0 1 3 3v5"}),f("path",{d:"M4 15l4 -4c.928 -.893 2.072 -.893 3 0l4 4"}),f("path",{d:"M14 14l1 -1c.617 -.593 1.328 -.793 2.009 -.598"}),f("path",{d:"M19 16v6"}),f("path",{d:"M22 19l-3 3l-3 -3"})]}),U),fx=L("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}),RX=L("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}),NX=L("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}),bx=L("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"),BX=L("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"),vu=L(f("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"}),de),Tu=L(f("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"}),de),xx=L("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}),Ex=L(f("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"}),de),FX=L("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"),OX=L("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}),zX=L(B("g",{strokeWidth:1.25,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("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"}),f("path",{d:"M12 14v-11"}),f("path",{d:"M9 6l3 -3l3 3"})]}),U),HX=L(B(De,{children:[f("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"}),f("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}),GX=L(f("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}),yx=B("g",{strokeWidth:1.5,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M12 10l0 10"}),f("path",{d:"M12 10l4 4"}),f("path",{d:"M12 10l-4 4"}),f("path",{d:"M4 4l16 0"})]}),wx=B("g",{strokeWidth:1.5,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M12 5l0 14"}),f("path",{d:"M16 9l-4 -4"}),f("path",{d:"M8 9l4 -4"})]}),Iu=L(wx,U),Cu=L(wx,{...U,style:{transform:"rotate(180deg)"}}),Su=L(yx,U),ku=L(yx,{...U,style:{transform:"rotate(180deg)"}}),Mu=L(B(De,{children:[B("g",{clipPath:"url(#a)",stroke:"currentColor",strokeWidth:"1.25",children:[f("path",{d:"M3.333 3.333h13.334",strokeLinecap:"round",strokeLinejoin:"round"}),f("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"})]}),f("defs",{children:f("clipPath",{id:"a",children:f("path",{fill:"#fff",d:"M0 0h20v20H0z"})})})]}),de),Pu=L(B(De,{children:[B("g",{clipPath:"url(#a)",stroke:"currentColor",strokeWidth:"1.25",children:[f("path",{d:"M3.333 16.667h13.334",strokeLinecap:"round",strokeLinejoin:"round"}),f("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"})]}),f("defs",{children:f("clipPath",{id:"a",children:f("path",{fill:"#fff",d:"M0 0h20v20H0z"})})})]}),de),Lu=L(B(De,{children:[B("g",{clipPath:"url(#a)",stroke:"currentColor",strokeWidth:"1.25",children:[f("path",{d:"M3.333 3.333v13.334",strokeLinecap:"round",strokeLinejoin:"round"}),f("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"})]}),f("defs",{children:f("clipPath",{id:"a",children:f("path",{fill:"#fff",d:"M0 0h20v20H0z"})})})]}),de),Au=L(B(De,{children:[B("g",{clipPath:"url(#a)",stroke:"currentColor",strokeWidth:"1.25",children:[f("path",{d:"M16.667 3.333v13.334",strokeLinecap:"round",strokeLinejoin:"round"}),f("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"})]}),f("defs",{children:f("clipPath",{id:"a",children:f("path",{fill:"#fff",d:"M0 0h20v20H0z"})})})]}),de),vx=L(B(De,{children:[B("g",{clipPath:"url(#a)",stroke:"currentColor",strokeWidth:"1.25",children:[f("path",{d:"M16.667 3.333v13.334M3.333 3.333v13.334",strokeLinecap:"round",strokeLinejoin:"round"}),f("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"})]}),f("defs",{children:f("clipPath",{id:"a",children:f("path",{fill:"#fff",d:"M0 0h20v20H0z"})})})]}),de),Tx=L(B(De,{children:[B("g",{clipPath:"url(#a)",stroke:"currentColor",strokeWidth:"1.25",children:[f("path",{d:"M3.333 3.333h13.334M3.333 16.667h13.334",strokeLinecap:"round",strokeLinejoin:"round"}),f("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"})]}),f("defs",{children:f("clipPath",{id:"a",children:f("path",{fill:"#fff",d:"M0 0h20v20H0z"})})})]}),de),Du=L(B("g",{stroke:"currentColor",strokeWidth:"1.25",children:[f("path",{d:"M1.667 10h2.916",strokeLinecap:"round",strokeLinejoin:"round"}),f("path",{d:"M8.333 10h3.334",strokeLinejoin:"round"}),f("path",{d:"M15.417 10h2.916",strokeLinecap:"round",strokeLinejoin:"round"}),f("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"})]}),de),_u=L(B("g",{stroke:"currentColor",strokeWidth:"1.25",children:[f("path",{d:"M10 18.333v-2.916",strokeLinecap:"round",strokeLinejoin:"round"}),f("path",{d:"M10 11.667V8.333",strokeLinejoin:"round"}),f("path",{d:"M10 4.583V1.667",strokeLinecap:"round",strokeLinejoin:"round"}),f("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"})]}),de),Oc=L(B("g",{strokeWidth:"1.5",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("circle",{cx:"9",cy:"7",r:"4"}),f("path",{d:"M3 21v-2a4 4 0 0 1 4 -4h4a4 4 0 0 1 4 4v2"}),f("path",{d:"M16 3.13a4 4 0 0 1 0 7.75"}),f("path",{d:"M21 21v-2a4 4 0 0 0 -3 -3.85"})]}),U),UX=L("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"),Ix=L("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"),io=L(B(De,{children:[f("g",{clipPath:"url(#a)",stroke:"currentColor",strokeWidth:"1.25",strokeLinecap:"round",strokeLinejoin:"round",children:f("path",{d:"M15 5 5 15M5 5l10 10"})}),f("defs",{children:f("clipPath",{id:"a",children:f("path",{fill:"#fff",d:"M0 0h20v20H0z"})})})]}),de),WX=L("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}),YX=L("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}),VX=L("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}),Ru=pt.memo(({theme:e})=>L(B(De,{children:[f("path",{d:"M25 26H111V111H25",fill:So(e)}),f("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:So(e),strokeWidth:"2"}),f("path",{d:"M100 100H160V160H100",fill:So(e)}),f("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:So(e),strokeWidth:"2"}),B("g",{fill:qb(e),stroke:So(e),strokeWidth:"6",children:[f("rect",{x:"2.5",y:"2.5",width:"30",height:"30"}),f("rect",{x:"2.5",y:"149.5",width:"30",height:"30"}),f("rect",{x:"147.5",y:"149.5",width:"30",height:"30"}),f("rect",{x:"147.5",y:"2.5",width:"30",height:"30"})]})]}),{width:182,height:182,mirror:!0})),Nu=pt.memo(({theme:e})=>L(B(De,{children:[f("path",{d:"M25 26H111V111H25",fill:So(e)}),f("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:So(e),strokeWidth:"2"}),f("path",{d:"M100 100H160V160H100",fill:So(e)}),f("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:So(e),strokeWidth:"2"}),B("g",{fill:qb(e),stroke:So(e),strokeWidth:"6",children:[f("rect",{x:"2.5",y:"2.5",width:"30",height:"30"}),f("rect",{x:"78.5",y:"149.5",width:"30",height:"30"}),f("rect",{x:"147.5",y:"149.5",width:"30",height:"30"}),f("rect",{x:"147.5",y:"78.5",width:"30",height:"30"}),f("rect",{x:"105.5",y:"2.5",width:"30",height:"30"}),f("rect",{x:"2.5",y:"102.5",width:"30",height:"30"})]})]}),{width:182,height:182,mirror:!0})),Cx=L(f("g",{strokeWidth:1.25,children:f("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"})}),de),Sx=L(B(De,{children:[f("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"}),f("mask",{id:"FillHachureIcon",style:{maskType:"alpha"},maskUnits:"userSpaceOnUse",x:2,y:2,width:16,height:16,children:f("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"})}),f("g",{mask:"url(#FillHachureIcon)",children:f("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"})})]}),de),kx=L(B(De,{children:[B("g",{clipPath:"url(#a)",children:[f("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"}),f("mask",{id:"FillCrossHatchIcon",style:{maskType:"alpha"},maskUnits:"userSpaceOnUse",x:-1,y:-1,width:22,height:22,children:f("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"})}),f("g",{mask:"url(#FillCrossHatchIcon)",children:f("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"})})]}),f("defs",{children:f("clipPath",{id:"a",children:f("path",{fill:"#fff",d:"M0 0h20v20H0z"})})})]}),de),Mx=L(B(De,{children:[f("g",{clipPath:"url(#a)",children:f("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"})}),f("defs",{children:f("clipPath",{id:"a",children:f("path",{fill:"#fff",d:"M0 0h20v20H0z"})})})]}),{...de,fill:"currentColor"}),Bu=L(f(De,{children:f("path",{d:"M4.167 10h11.666",stroke:"currentColor",strokeWidth:"1.25",strokeLinecap:"round",strokeLinejoin:"round"})}),de),Px=L(f("path",{d:"M5 10h10",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round"}),de),Lx=L(f("path",{d:"M5 10h10",stroke:"currentColor",strokeWidth:"3.75",strokeLinecap:"round",strokeLinejoin:"round"}),de),KX=pt.memo(({theme:e})=>L(f("path",{d:"M6 10H34",stroke:So(e),strokeWidth:2,fill:"none",strokeLinecap:"round"}),{width:40,height:20})),Ax=L(B("g",{strokeWidth:"2",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M5 12h2"}),f("path",{d:"M17 12h2"}),f("path",{d:"M11 12h2"})]}),U),Dx=L(B("g",{strokeWidth:"2",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M4 12v.01"}),f("path",{d:"M8 12v.01"}),f("path",{d:"M12 12v.01"}),f("path",{d:"M16 12v.01"}),f("path",{d:"M20 12v.01"})]}),U),_x=L(f("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"}),de),Rx=L(f("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"}),de),Nx=L(f("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"}),de),Bx=L(B("svg",{strokeWidth:"1.5",children:[f("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"}),f("path",{d:"M13.3333 3.33331V3.34331"}),f("path",{d:"M16.6667 3.33331V3.34331"}),f("path",{d:"M16.6667 6.66669V6.67669"}),f("path",{d:"M16.6667 10V10.01"}),f("path",{d:"M3.33334 13.3333V13.3433"}),f("path",{d:"M16.6667 13.3333V13.3433"}),f("path",{d:"M3.33334 16.6667V16.6767"}),f("path",{d:"M6.66666 16.6667V16.6767"}),f("path",{d:"M10 16.6667V16.6767"}),f("path",{d:"M13.3333 16.6667V16.6767"}),f("path",{d:"M16.6667 16.6667V16.6767"})]}),de),Fx=L(B("g",{strokeWidth:"1.5",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M4 12v-4a4 4 0 0 1 4 -4h4"}),f("line",{x1:"16",y1:"4",x2:"16",y2:"4.01"}),f("line",{x1:"20",y1:"4",x2:"20",y2:"4.01"}),f("line",{x1:"20",y1:"8",x2:"20",y2:"8.01"}),f("line",{x1:"20",y1:"12",x2:"20",y2:"12.01"}),f("line",{x1:"4",y1:"16",x2:"4",y2:"16.01"}),f("line",{x1:"20",y1:"16",x2:"20",y2:"16.01"}),f("line",{x1:"4",y1:"20",x2:"4",y2:"20.01"}),f("line",{x1:"8",y1:"20",x2:"8",y2:"20.01"}),f("line",{x1:"12",y1:"20",x2:"12",y2:"20.01"}),f("line",{x1:"16",y1:"20",x2:"16",y2:"20.01"}),f("line",{x1:"20",y1:"20",x2:"20",y2:"20.01"})]}),U),Ox=pt.memo(({flip:e=!1})=>L(B("g",{transform:e?"translate(24, 0) scale(-1, 1)":"",stroke:"currentColor",opacity:.3,strokeWidth:2,children:[f("path",{d:"M12 12l-9 0"}),f("path",{d:"M21 9l-6 6"}),f("path",{d:"M21 15l-6 -6"})]}),U)),zx=pt.memo(({flip:e=!1})=>L(B("g",{transform:e?"translate(40, 0) scale(-1, 1)":"",stroke:"currentColor",strokeWidth:2,fill:"none",children:[f("path",{d:"M34 10H6M34 10L27 5M34 10L27 15"}),f("path",{d:"M27.5 5L34.5 10L27.5 15"})]}),{width:40,height:20})),Hx=pt.memo(({flip:e=!1})=>L(B("g",{stroke:"currentColor",fill:"currentColor",transform:e?"translate(40, 0) scale(-1, 1)":"",children:[f("path",{d:"M32 10L6 10",strokeWidth:2}),f("circle",{r:"4",transform:"matrix(-1 0 0 1 30 10)"})]}),{width:40,height:20})),Gx=pt.memo(({flip:e=!1})=>L(B("g",{stroke:"currentColor",fill:"none",transform:e?"translate(40, 0) scale(-1, 1)":"",strokeWidth:2,children:[f("path",{d:"M26 10L6 10"}),f("circle",{r:"4",transform:"matrix(-1 0 0 1 30 10)"})]}),{width:40,height:20})),Ux=pt.memo(({flip:e=!1})=>L(f("g",{transform:e?"translate(40, 0) scale(-1, 1)":"",children:f("path",{d:"M34 10H5.99996M34 10L34 5M34 10L34 15",stroke:"currentColor",strokeWidth:2,fill:"none"})}),{width:40,height:20})),Wx=pt.memo(({flip:e=!1})=>L(B("g",{stroke:"currentColor",fill:"currentColor",transform:e?"translate(40, 0) scale(-1, 1)":"",children:[f("path",{d:"M32 10L6 10",strokeWidth:2}),f("path",{d:"M27.5 5.5L34.5 10L27.5 14.5L27.5 5.5"})]}),{width:40,height:20})),Yx=pt.memo(({flip:e=!1})=>L(B("g",{stroke:"currentColor",fill:"none",transform:e?"translate(40, 0) scale(-1, 1)":"",strokeWidth:2,strokeLinejoin:"round",children:[f("path",{d:"M6,9.5H27"}),f("path",{d:"M27,5L34,10L27,14Z",fill:"none"})]}),{width:40,height:20})),Vx=pt.memo(({flip:e=!1})=>L(B("g",{stroke:"currentColor",fill:"currentColor",transform:e?"translate(40, 0) scale(-1, 1)":"",strokeLinejoin:"round",strokeWidth:2,children:[f("path",{d:"M6,9.5H20"}),f("path",{d:"M27,5L34,10L27,14L20,9.5Z"})]}),{width:40,height:20})),Kx=pt.memo(({flip:e=!1})=>L(B("g",{stroke:"currentColor",fill:"none",transform:e?"translate(40, 0) scale(-1, 1)":"",strokeLinejoin:"round",strokeWidth:2,children:[f("path",{d:"M6,9.5H20"}),f("path",{d:"M27,5L34,10L27,14L20,9.5Z"})]}),{width:40,height:20})),Xx=pt.memo(({flip:e=!1})=>L(f("g",{stroke:"currentColor",fill:"none",transform:e?"":"translate(40, 0) scale(-1, 1)",strokeLinejoin:"round",strokeWidth:2,children:f("path",{d:"M34,10 H6 M15,10 L7,5 M15,10 L7,15"})}),{width:40,height:20})),$x=pt.memo(({flip:e=!1})=>L(f("g",{stroke:"currentColor",fill:"none",transform:e?"":"translate(40, 0) scale(-1, 1)",strokeLinejoin:"round",strokeWidth:2,children:f("path",{d:"M34,10 H6 M15,10 L15,15 L15,5"})}),{width:40,height:20})),Zx=pt.memo(({flip:e=!1})=>L(f("g",{stroke:"currentColor",fill:"none",transform:e?"":"translate(40, 0) scale(-1, 1)",strokeLinejoin:"round",strokeWidth:2,children:f("path",{d:"M34,10 H6 M15,10 L15,16 L15,4 M15,10 L7,5 M15,10 L7,15"})}),{width:40,height:20})),jx=L(B(De,{children:[f("g",{clipPath:"url(#a)",children:f("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"})}),f("defs",{children:f("clipPath",{id:"a",children:f("path",{fill:"#fff",d:"M0 0h20v20H0z"})})})]}),de),qx=L(B(De,{children:[f("g",{clipPath:"url(#a)",children:f("path",{d:"M5 16.667V3.333L10 15l5-11.667v13.334",stroke:"currentColor",strokeWidth:"1.25",strokeLinecap:"round",strokeLinejoin:"round"})}),f("defs",{children:f("clipPath",{id:"a",children:f("path",{fill:"#fff",d:"M0 0h20v20H0z"})})})]}),de),Jx=L(B(De,{children:[f("g",{clipPath:"url(#a)",children:f("path",{d:"M5.833 3.333v13.334h8.334",stroke:"currentColor",strokeWidth:"1.25",strokeLinecap:"round",strokeLinejoin:"round"})}),f("defs",{children:f("clipPath",{id:"a",children:f("path",{fill:"#fff",d:"M0 0h20v20H0z"})})})]}),de),Qx=L(f(De,{children:f("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"})}),de),jr=L(B("g",{strokeWidth:1.25,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M3 7v-2h13v2"}),f("path",{d:"M10 5v14"}),f("path",{d:"M12 19h-4"}),f("path",{d:"M15 13v-1h6v1"}),f("path",{d:"M18 12v7"}),f("path",{d:"M17 19h2"})]}),U),eE=L(f(De,{children:B("g",{stroke:"currentColor",strokeWidth:"1.25",strokeLinecap:"round",strokeLinejoin:"round",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M7 12h10"}),f("path",{d:"M7 5v14"}),f("path",{d:"M17 5v14"}),f("path",{d:"M15 19h4"}),f("path",{d:"M15 5h4"}),f("path",{d:"M5 19h4"}),f("path",{d:"M5 5h4"})]})}),U),Rs=L(f(De,{children:f("g",{stroke:"currentColor",strokeWidth:"1.25",strokeLinecap:"round",strokeLinejoin:"round",children:f("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"})})}),de),Fu=L(B("g",{strokeWidth:"1.5",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M7 8l-4 4l4 4"}),f("path",{d:"M17 8l4 4l-4 4"}),f("path",{d:"M14 4l-4 16"})]}),U),zc=Fu,tE=L(B("g",{stroke:"currentColor",fill:"none",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("line",{x1:"4",y1:"8",x2:"20",y2:"8"}),f("line",{x1:"4",y1:"12",x2:"12",y2:"12"}),f("line",{x1:"4",y1:"16",x2:"16",y2:"16"})]}),U),oE=L(B("g",{stroke:"currentColor",fill:"none",strokeLinecap:"round",strokeLinejoin:"round",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("line",{x1:"4",y1:"8",x2:"20",y2:"8"}),f("line",{x1:"8",y1:"12",x2:"16",y2:"12"}),f("line",{x1:"6",y1:"16",x2:"18",y2:"16"})]}),U),nE=L(B("g",{stroke:"currentColor",fill:"none",strokeLinecap:"round",strokeLinejoin:"round",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("line",{x1:"4",y1:"8",x2:"20",y2:"8"}),f("line",{x1:"10",y1:"12",x2:"20",y2:"12"}),f("line",{x1:"8",y1:"16",x2:"20",y2:"16"})]}),U),rE=pt.memo(({theme:e})=>L(B("g",{strokeWidth:"1.5",stroke:"currentColor",fill:"none",strokeLinecap:"round",strokeLinejoin:"round",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("line",{x1:"4",y1:"4",x2:"20",y2:"4"}),f("rect",{x:"9",y:"8",width:"6",height:"12",rx:"2"})]}),U)),iE=pt.memo(({theme:e})=>L(B("g",{strokeWidth:"2",stroke:"currentColor",fill:"none",strokeLinecap:"round",strokeLinejoin:"round",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("line",{x1:"4",y1:"20",x2:"20",y2:"20"}),f("rect",{x:"9",y:"4",width:"6",height:"12",rx:"2"})]}),U)),aE=pt.memo(({theme:e})=>L(B("g",{strokeWidth:"1.5",stroke:"currentColor",fill:"none",strokeLinecap:"round",strokeLinejoin:"round",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("line",{x1:"4",y1:"12",x2:"9",y2:"12"}),f("line",{x1:"15",y1:"12",x2:"20",y2:"12"}),f("rect",{x:"9",y:"6",width:"6",height:"12",rx:"2"})]}),U)),Hc=L(B("g",{children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M21 19h-18l9 -15"}),f("path",{d:"M20.615 15.171h.015"}),f("path",{d:"M19.515 11.771h.015"}),f("path",{d:"M17.715 8.671h.015"}),f("path",{d:"M15.415 5.971h.015"})]}),U),sE=L(f("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}),XX=L(f("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"})),$i=L(B("g",{strokeWidth:1.25,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M8 13v-7.5a1.5 1.5 0 0 1 3 0v6.5"}),f("path",{d:"M11 5.5v-2a1.5 1.5 0 1 1 3 0v8.5"}),f("path",{d:"M14 5.5a1.5 1.5 0 0 1 3 0v6.5"}),f("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"})]}),U),Ou=L(B(De,{children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M4 17v2a2 2 0 0 0 2 2h12a2 2 0 0 0 2 -2v-2"}),f("path",{d:"M7 11l5 5l5 -5"}),f("path",{d:"M12 4l0 12"})]}),U),Zi=L(B(De,{children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("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"}),f("path",{d:"M16 8v-2a2 2 0 0 0 -2 -2h-8a2 2 0 0 0 -2 2v8a2 2 0 0 0 2 2h2"})]}),U),lE=L(B("g",{strokeWidth:1.25,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M7 17m-3 0a3 3 0 1 0 6 0a3 3 0 1 0 -6 0"}),f("path",{d:"M17 17m-3 0a3 3 0 1 0 6 0a3 3 0 1 0 -6 0"}),f("path",{d:"M9.15 14.85l8.85 -10.85"}),f("path",{d:"M6 4l8.85 10.85"})]}),U),cE=L(B(De,{children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M12 12m-9 0a9 9 0 1 0 18 0a9 9 0 1 0 -18 0"}),f("path",{d:"M12 17l0 .01"}),f("path",{d:"M12 13.5a1.5 1.5 0 0 1 1 -1.5a2.6 2.6 0 1 0 -3 -4"})]}),U),$X=L(B(De,{children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M7 4v16l13 -8z"})]}),U),ZX=L(B(De,{children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("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"})]}),U),dE=L(B(De,{children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M5 12l5 5l10 -10"})]}),U),Gc=L(B(De,{children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("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"}),f("path",{d:"M12 9v4"}),f("path",{d:"M12 17h.01"})]}),U),mE=L(B("g",{strokeWidth:1.25,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M11 7l6 6"}),f("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"})]}),U),Ns=L(B("g",{strokeWidth:1.5,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M12 3l-4 7h8z"}),f("path",{d:"M17 17m-3 0a3 3 0 1 0 6 0a3 3 0 1 0 -6 0"}),f("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"})]}),U),ko=L(B("g",{strokeWidth:1.5,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M4 7l16 0"}),f("path",{d:"M4 17l16 0"}),f("path",{d:"M7 4l0 16"}),f("path",{d:"M17 4l0 16"})]}),U),ji=L(f("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"})),pE=L(B("g",{strokeWidth:"1.5",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M20 11a8.1 8.1 0 0 0 -15.5 -2m-.5 -4v4h4"}),f("path",{d:"M4 13a8.1 8.1 0 0 0 15.5 2m.5 4v-4h-4"})]}),U),uE=L(B("g",{children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M6 10l-2 1l8 4l8 -4l-2 -1"}),f("path",{d:"M4 15l8 4l8 -4"}),f("path",{d:"M12 4v7"}),f("path",{d:"M15 8l-3 3l-3 -3"})]}),U),$n=L(B("g",{strokeWidth:"1.25",children:[f("path",{d:"M4.16602 10H15.8327"}),f("path",{d:"M12.5 13.3333L15.8333 10"}),f("path",{d:"M12.5 6.66666L15.8333 9.99999"})]}),de),$o=L(B("g",{fill:"none",stroke:"currentColor",strokeWidth:"1.25",strokeLinecap:"round",strokeLinejoin:"round",transform:"rotate(90 10 10)",children:[f("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"}),f("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),qr=L(B("g",{stroke:"currentColor",fill:"none",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z"}),f("path",{d:"M6 21l15 -15l-3 -3l-15 15l3 3"}),f("path",{d:"M15 6l3 3"}),f("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"}),f("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"})]}),U),jX=L(B("g",{strokeWidth:1.25,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z"}),f("path",{d:"M6 21l15 -15l-3 -3l-15 15l3 3"}),f("path",{d:"M15 6l3 3"}),f("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"}),f("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"})]}),U),qX=L(B("g",{stroke:"currentColor",fill:"none",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M11.217 19.384a3.501 3.501 0 0 0 6.783 -1.217v-5.167l-6 -3.35"}),f("path",{d:"M5.214 15.014a3.501 3.501 0 0 0 4.446 5.266l4.34 -2.534v-6.946"}),f("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"}),f("path",{d:"M12.783 4.616a3.501 3.501 0 0 0 -6.783 1.217v5.067l6 3.45"}),f("path",{d:"M18.786 8.986a3.501 3.501 0 0 0 -4.446 -5.266l-4.34 2.534v6.946"}),f("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"})]}),U),gE=L(B("g",{stroke:"currentColor",fill:"none",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M4 8v-2a2 2 0 0 1 2 -2h2"}),f("path",{d:"M4 16v2a2 2 0 0 0 2 2h2"}),f("path",{d:"M16 4h2a2 2 0 0 1 2 2v2"}),f("path",{d:"M16 20h2a2 2 0 0 0 2 -2v-2"})]}),U),qi=L(B("g",{stroke:"currentColor",fill:"none",strokeWidth:1.5,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M10 12a2 2 0 1 0 4 0a2 2 0 0 0 -4 0"}),f("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"})]}),U),hE=L(B("g",{stroke:"currentColor",fill:"none",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M10.585 10.587a2 2 0 0 0 2.829 2.828"}),f("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"}),f("path",{d:"M3 3l18 18"})]}),U),fE=L(B("g",{stroke:"currentColor",fill:"none",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("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"}),f("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"}),f("path",{d:"M17.5 16a3.5 3.5 0 0 0 0 -7h-.5"}),f("path",{d:"M19 9.3v-2.8a3.5 3.5 0 0 0 -7 0"}),f("path",{d:"M6.5 16a3.5 3.5 0 0 1 0 -7h.5"}),f("path",{d:"M5 9.3v-2.8a3.5 3.5 0 0 1 7 0v10"})]}),U),bE=L(B("g",{strokeWidth:1.25,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("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"}),f("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"}),f("path",{d:"M17.5 16a3.5 3.5 0 0 0 0 -7h-.5"}),f("path",{d:"M19 9.3v-2.8a3.5 3.5 0 0 0 -7 0"}),f("path",{d:"M6.5 16a3.5 3.5 0 0 1 0 -7h.5"}),f("path",{d:"M5 9.3v-2.8a3.5 3.5 0 0 1 7 0v10"})]}),U),jt=L(B("g",{strokeWidth:1.5,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M10 10m-7 0a7 7 0 1 0 14 0a7 7 0 1 0 -14 0"}),f("path",{d:"M21 21l-6 -6"})]}),U),xE=L(B("g",{strokeWidth:1.5,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M20.984 12.53a9 9 0 1 0 -7.552 8.355"}),f("path",{d:"M12 7v5l3 3"}),f("path",{d:"M19 16l-2 3h4l-2 3"})]}),U),EE=L(B("g",{strokeWidth:1.5,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M12 8l0 4l2 2"}),f("path",{d:"M3.05 11a9 9 0 1 1 .5 4m-.5 5v-5h5"})]}),U),yE=L(B("g",{strokeWidth:1.5,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("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"}),f("path",{d:"M5 10a7 7 0 0 0 14 0"}),f("path",{d:"M8 21l8 0"}),f("path",{d:"M12 17l0 4"})]}),U),wE=L(B("g",{strokeWidth:1.5,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M3 3l18 18"}),f("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"}),f("path",{d:"M5 10a7 7 0 0 0 10.846 5.85m2 -2a6.967 6.967 0 0 0 1.152 -3.85"}),f("path",{d:"M8 21l8 0"}),f("path",{d:"M12 17l0 4"})]}),U),Bs=L(B("g",{strokeWidth:1.25,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M13 3l0 7l6 0l-8 11l0 -7l-6 0l8 -11"})]}),U),vE=L(B("g",{children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("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"}),f("path",{d:"M12 20v.01"}),f("path",{d:"M16 20v.01"}),f("path",{d:"M8 20v.01"}),f("path",{d:"M4 20v.01"}),f("path",{d:"M4 16v.01"}),f("path",{d:"M4 12v.01"}),f("path",{d:"M4 8v.01"}),f("path",{d:"M4 4v.01"}),f("path",{d:"M8 4v.01"}),f("path",{d:"M12 4v.01"}),f("path",{d:"M16 4v.01"}),f("path",{d:"M20 4v.01"}),f("path",{d:"M20 8v.01"}),f("path",{d:"M20 12v.01"}),f("path",{d:"M20 16v.01"}),f("path",{d:"M20 20v.01"})]}),U),TE=L(B("g",{strokeWidth:1.25,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M5 3v18"}),f("path",{d:"M19 21v-18"}),f("path",{d:"M5 7h14"}),f("path",{d:"M5 15h14"}),f("path",{d:"M8 13v4"}),f("path",{d:"M11 13v4"}),f("path",{d:"M16 13v4"}),f("path",{d:"M14 5v4"}),f("path",{d:"M11 5v4"}),f("path",{d:"M8 5v4"}),f("path",{d:"M3 21h18"})]}),U),IE=L(B("g",{strokeWidth:1.25,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M3 12l18 0"}),f("path",{d:"M7 16l10 0l-10 5l0 -5"}),f("path",{d:"M7 8l10 0l-10 -5l0 5"})]}),U),CE=L(B("g",{strokeWidth:1.25,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M12 3l0 18"}),f("path",{d:"M16 7l0 10l5 0l-5 -10"}),f("path",{d:"M8 7l0 10l-5 0l5 -10"})]}),U),zu=L(B("g",{strokeWidth:1.25,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("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"}),f("path",{d:"M19 6h1a2 2 0 0 1 2 2a5 5 0 0 1 -5 5l-5 0v2"}),f("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"})]}),U),Uc=L(B("g",{strokeWidth:1.25,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M15 15m-5 0a5 5 0 1 0 10 0a5 5 0 1 0 -10 0"}),f("path",{d:"M22 22l-3 -3"}),f("path",{d:"M6 18h-1a2 2 0 0 1 -2 -2v-1"}),f("path",{d:"M3 11v-1"}),f("path",{d:"M3 6v-1a2 2 0 0 1 2 -2h1"}),f("path",{d:"M10 3h1"}),f("path",{d:"M15 3h1a2 2 0 0 1 2 2v1"})]}),U),SE=L(B("g",{strokeWidth:1.25,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M14 3v4a1 1 0 0 0 1 1h4"}),f("path",{d:"M5 12v-7a2 2 0 0 1 2 -2h7l5 5v4"}),f("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"}),f("path",{d:"M10 15l2 6l2 -6"}),f("path",{d:"M20 15h-1a2 2 0 0 0 -2 2v2a2 2 0 0 0 2 2h1v-3"})]}),U),kE=L(B("g",{strokeWidth:1.25,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M14 3v4a1 1 0 0 0 1 1h4"}),f("path",{d:"M5 12v-7a2 2 0 0 1 2 -2h7l5 5v4"}),f("path",{d:"M20 15h-1a2 2 0 0 0 -2 2v2a2 2 0 0 0 2 2h1v-3"}),f("path",{d:"M5 18h1.5a1.5 1.5 0 0 0 0 -3h-1.5v6"}),f("path",{d:"M11 21v-6l3 6v-6"})]}),U),ME=L(B("g",{strokeWidth:1.25,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("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"}),f("path",{d:"M4 8l5 0"}),f("path",{d:"M15 8l4 0"})]}),U),PE=L(B("g",{strokeWidth:1.25,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("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"}),f("path",{d:"M8 3a2.4 2.4 0 0 0 -1 2a2.4 2.4 0 0 0 1 2"}),f("path",{d:"M12 3a2.4 2.4 0 0 0 -1 2a2.4 2.4 0 0 0 1 2"}),f("path",{d:"M3 10h14v5a6 6 0 0 1 -6 6h-2a6 6 0 0 1 -6 -6v-5z"}),f("path",{d:"M16.746 16.726a3 3 0 1 0 .252 -5.555"})]}),U),LE=L(B("g",{stroke:"currentColor",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("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"})]}),{...U,strokeWidth:1.5}),JX=L(B("g",{strokeWidth:1.5,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("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"}),f("path",{d:"M21 12h-13l3 -3"}),f("path",{d:"M11 15l-3 -3"})]}),U),AE=L(B("g",{children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("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"}),f("path",{d:"M10 9l5 3l-5 3z"})]}),U),DE=L(B("g",{strokeWidth:1.5,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M3 6h18"}),f("path",{d:"M3 12h18"}),f("path",{d:"M3 18h18"}),f("path",{d:"M6 3v18"}),f("path",{d:"M12 3v18"}),f("path",{d:"M18 3v18"})]}),U),_E=L(B("g",{strokeWidth:1.5,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("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"}),f("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"}),f("path",{d:"M17 5c-6.627 0 -12 5.373 -12 12"})]}),U),Ji=L(B("g",{children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M6 18l12 -12"}),f("path",{d:"M18 10v-4h-4"})]}),U),Qi=L(B("g",{children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M4,19L10,19C11.097,19 12,18.097 12,17L12,9C12,7.903 12.903,7 14,7L21,7"}),f("path",{d:"M18 4l3 3l-3 3"})]}),U),ea=L(B("g",{children:[f("path",{d:"M16,12L20,9L16,6"}),f("path",{d:"M6 20c0 -6.075 4.925 -11 11 -11h3"})]}),U),Wc=L(B("g",{children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M6 9l6 6l6 -6"})]}),U),RE=L(B("g",{children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M6 15l6 -6l6 6"})]}),U),NE=L(B("g",{children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M6 15l6 -6l6 6"})]}),U),Hu=L(B("g",{strokeWidth:"1.25",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M8 5v10a1 1 0 0 0 1 1h10"}),f("path",{d:"M5 8h10a1 1 0 0 1 1 1v10"})]}),U),Yc=L(B("g",{children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M5 5m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"}),f("path",{d:"M19 5m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"}),f("path",{d:"M5 19m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"}),f("path",{d:"M19 19m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"}),f("path",{d:"M5 7l0 10"}),f("path",{d:"M7 5l10 0"}),f("path",{d:"M7 19l10 0"}),f("path",{d:"M19 7l0 10"})]}),U),QX=L(B("g",{strokeWidth:1.5,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("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"}),f("path",{d:"M4 12h7a1 1 0 0 1 1 1v7"})]}),U),BE=L(B("g",{strokeWidth:1.5,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M14 6m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"}),f("path",{d:"M4 6l8 0"}),f("path",{d:"M16 6l4 0"}),f("path",{d:"M8 12m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"}),f("path",{d:"M4 12l2 0"}),f("path",{d:"M10 12l10 0"}),f("path",{d:"M17 18m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"}),f("path",{d:"M4 18l11 0"}),f("path",{d:"M19 18l1 0"})]}),U),FE=L(B("g",{strokeWidth:1,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M6 10l4 -4 L6 14l8 -8 L6 18l12 -12 L10 18l8 -8 L14 18l4 -4"})]}),U),OE=L(B("g",{strokeWidth:1.25,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M4 20h4l10.5 -10.5a2.828 2.828 0 1 0 -4 -4l-10.5 10.5v4"}),f("path",{d:"M13.5 6.5l4 4"})]}),U),e$=L(B("g",{strokeWidth:1,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M11 7l-5 5l5 5"}),f("path",{d:"M17 7l-5 5l5 5"})]}),U),zE=L(B("g",{strokeWidth:"1.75",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("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"}),f("path",{d:"M15 4l0 16"})]}),U),t$=L(B("g",{strokeWidth:"1.25",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("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"})]}),U),o$=L(B("g",{strokeWidth:"1.25",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M3 4l18 0"}),f("path",{d:"M4 4v10a2 2 0 0 0 2 2h12a2 2 0 0 0 2 -2v-10"}),f("path",{d:"M12 16l0 4"}),f("path",{d:"M9 20l6 0"}),f("path",{d:"M8 12l3 -3l2 2l3 -3"})]}),U),HE=f("div",{style:{width:"1rem",height:"1rem"}}),GE=L(B("g",{strokeWidth:"1.5",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("polyline",{points:"9 6 15 12 9 18"})]}),U),UE=L(B("g",{strokeWidth:1.25,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M14 6m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"}),f("path",{d:"M4 6l8 0"}),f("path",{d:"M16 6l4 0"}),f("path",{d:"M8 12m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"}),f("path",{d:"M4 12l2 0"}),f("path",{d:"M10 12l10 0"}),f("path",{d:"M17 18m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"}),f("path",{d:"M4 18l11 0"}),f("path",{d:"M19 18l1 0"})]}),U);import WE from"clsx";import Uu,{useEffect as Qk,useRef as YE,useState as e6}from"react";import{isPromiseLike as t6}from"@orangecatai/common";import qk from"react";import{jsx as Gu}from"react/jsx-runtime";var Jk=({size:e="1em",circleWidth:o=8,synchronized:t=!1,className:n=""})=>{let i=-(qk.useRef(Date.now()).current%1600);return Gu("div",{className:`Spinner ${n}`,children:Gu("svg",{viewBox:"0 0 100 100",style:{width:e,height:e,"--spinner-delay":t?`${i}ms`:0},children:Gu("circle",{cx:"50",cy:"50",r:50-o/2,strokeWidth:o,fill:"none",strokeMiterlimit:"10"})})})},wt=Jk;import{jsx as Fs,jsxs as Os}from"react/jsx-runtime";var Q=Uu.forwardRef(({size:e="medium",visible:o=!0,className:t="",...n},r)=>{let{id:i}=Oe(),a=Uu.useRef(null);Uu.useImperativeHandle(r,()=>a.current);let s=`ToolIcon_size_${e}`,[l,c]=e6(!1),m=YE(!0),p=async u=>{let b="onClick"in n&&n.onClick?.(u);if(t6(b))try{c(!0),await b}catch(g){if(g instanceof _i)console.warn(g);else throw g}finally{m.current&&c(!1)}};Qk(()=>(m.current=!0,()=>{m.current=!1}),[]);let d=YE(null);if(n.type==="button"||n.type==="icon"||n.type==="submit"){let u=n.type==="icon"?"button":n.type;return Os("button",{className:WE("ToolIcon_type_button",s,t,o&&!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:a,disabled:l||n.isLoading||!!n.disabled,children:[(n.icon||n.label)&&Os("div",{className:"ToolIcon__icon","aria-hidden":"true","aria-disabled":!!n.disabled,children:[n.icon||n.label,n.keyBindingLabel&&Fs("span",{className:"ToolIcon__keybinding",children:n.keyBindingLabel}),n.isLoading&&Fs(wt,{})]}),n.showAriaLabel&&Os("div",{className:"ToolIcon__label",children:[n["aria-label"]," ",l&&Fs(wt,{})]}),n.children]})}return Os("label",{className:WE("ToolIcon",t),title:n.title,onPointerDown:u=>{d.current=u.pointerType||null,n.onPointerDown?.({pointerType:u.pointerType||null})},onPointerUp:()=>{requestAnimationFrame(()=>{d.current=null})},children:[Fs("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:`${i}-${n.id}`,onChange:()=>{n.onChange?.({pointerType:d.current})},checked:n.checked,ref:a}),Os("div",{className:"ToolIcon__icon",children:[n.icon,n.keyBindingLabel&&Fs("span",{className:"ToolIcon__keybinding",children:n.keyBindingLabel})]})]})});Q.displayName="ToolButton";var Vc=[],O=e=>(Vc=Vc.concat(e),e);import{jsx as d6}from"react/jsx-runtime";var c6=(e,o,t)=>{let n=new Set(ne(e.filter(m=>a6(m)),o).map(m=>m.id)),r={},i=t.scene.getNonDeletedElementsMap(),a=new Set;for(let m of n){let p=s6(e,m);for(let d of p)if(!a.has(d.id)){if(Kc(d)){let u=KE(d,i);u&&(r[u.id]=!0)}else r[d.id]=!0;a.add(d.id)}}let s=!0,l=e.map(m=>{if(o.selectedElementIds[m.id]){let p=Kc(m)?KE(m,i):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=t.scene.getNonDeletedElementsMap().get(d.id);u&&i6(u)&&t.scene.mutateElement(u,{startBinding:m.id===u.startBinding?.elementId?null:u.startBinding,endBinding:m.id===u.endBinding?.elementId?null:u.endBinding})}),$c(m,{isDeleted:!0}))}return m.frameId&&n.has(m.frameId)?(s=!1,Kc(m)||(r[m.id]=!0),$c(m,{frameId:null})):Kc(m)&&o.selectedElementIds[m.containerId]?$c(m,{isDeleted:!0}):m}),c=o.editingGroupId;if(s&&o.editingGroupId){let m=Vu(l,o.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(b=>b===o.editingGroupId),u=p.groupIds[d+1];if(u){let b=Vu(l,u).filter(g=>!g.isDeleted);b.length>1&&(c=u,b.forEach(g=>{r[g.id]=!0}))}}}}return{elements:l,appState:{...o,...l6({selectedElementIds:r,editingGroupId:c},l,o,null)}}},XE=(e,o)=>{if(e.editingGroupId){let t=Vu(Yu(o),e.editingGroupId);if(t.length)return{...e,selectedElementIds:{[t[0].id]:!0}}}return e},zs=O({name:"deleteSelectedElements",label:"labels.delete",icon:yt,trackEvent:{category:"element",action:"delete"},perform:(e,o,t,n)=>{if(o.selectedLinearElement?.isEditing){let{elementId:a,selectedPointsIndices:s}=o.selectedLinearElement,l=n.scene.getNonDeletedElementsMap(),c=VE.getElement(a,l);if(!c||s==null)return!1;if(s.length>=c.points.length){let m=e.map(d=>d.id===c.id?$c(d,{isDeleted:!0}):d),p=XE(o,m);return{elements:m,appState:{...p,selectedLinearElement:null},captureUpdate:Xc.IMMEDIATELY}}return VE.deletePoints(c,n,s),{elements:e,appState:{...o,selectedLinearElement:{...o.selectedLinearElement,selectedPointsIndices:s?.[0]>0?[s[0]-1]:[0]}},captureUpdate:Xc.IMMEDIATELY}}let{elements:r,appState:i}=c6(e,o,n);return r6(r,r.filter(a=>a.isDeleted)),i=XE(i,r),{elements:r,appState:{...i,activeTool:n6(o,{type:n.state.preferredSelectionTool.type}),multiElement:null,newElement:null,activeEmbeddable:null,selectedLinearElement:null},captureUpdate:Le(Yu(e),o)?Xc.IMMEDIATELY:Xc.EVENTUALLY}},keyTest:(e,o,t)=>(e.key===Wu.BACKSPACE||e.key===Wu.DELETE)&&!e[Wu.CTRL_OR_CMD],PanelComponent:({elements:e,appState:o,updateData:t,app:n})=>{let r=ut()==="mobile";return d6(Q,{type:"button",icon:yt,title:h("labels.delete"),"aria-label":h("labels.delete"),onClick:()=>t(null),disabled:!Le(Yu(e),o),style:{...r&&o.openPopup!=="compactOtherProperties"?o6:{}}})}});import{KEYS as ta,CODES as oa,isDarwin as Zc}from"@orangecatai/common";import{moveOneLeft as m6,moveOneRight as p6,moveAllLeft as u6,moveAllRight as g6}from"@orangecatai/element";import{CaptureUpdateAction as jc}from"@orangecatai/element";import{isDarwin as $E}from"@orangecatai/common";var N=e=>e.replace(/\b(Opt(?:ion)?|Alt)\b/i,$E?h("keys.option"):h("keys.alt")).replace(/\bShift\b/i,h("keys.shift")).replace(/\b(Enter|Return)\b/i,h("keys.enter")).replace(/\b(Ctrl|Cmd|Command|CtrlOrCmd)\b/gi,$E?h("keys.cmd"):h("keys.ctrl")).replace(/\b(Esc(?:ape)?)\b/i,h("keys.escape")).replace(/\b(Space(?:bar)?)\b/i,h("keys.spacebar")).replace(/\b(Del(?:ete)?)\b/i,h("keys.delete"));import{jsx as qc}from"react/jsx-runtime";var Ku=O({name:"sendBackward",label:"labels.sendBackward",keywords:["move down","zindex","layer"],icon:Cu,trackEvent:{category:"element"},perform:(e,o,t,n)=>({elements:m6(e,o,n.scene),appState:o,captureUpdate:jc.IMMEDIATELY}),keyPriority:40,keyTest:e=>e[ta.CTRL_OR_CMD]&&!e.shiftKey&&e.code===oa.BRACKET_LEFT,PanelComponent:({updateData:e,appState:o})=>qc("button",{type:"button",className:"zIndexButton",onClick:()=>e(null),title:`${h("labels.sendBackward")} \u2014 ${N("CtrlOrCmd+[")}`,children:Cu})}),Xu=O({name:"bringForward",label:"labels.bringForward",keywords:["move up","zindex","layer"],icon:Iu,trackEvent:{category:"element"},perform:(e,o,t,n)=>({elements:p6(e,o,n.scene),appState:o,captureUpdate:jc.IMMEDIATELY}),keyPriority:40,keyTest:e=>e[ta.CTRL_OR_CMD]&&!e.shiftKey&&e.code===oa.BRACKET_RIGHT,PanelComponent:({updateData:e,appState:o})=>qc("button",{type:"button",className:"zIndexButton",onClick:()=>e(null),title:`${h("labels.bringForward")} \u2014 ${N("CtrlOrCmd+]")}`,children:Iu})}),$u=O({name:"sendToBack",label:"labels.sendToBack",keywords:["move down","zindex","layer"],icon:ku,trackEvent:{category:"element"},perform:(e,o)=>({elements:u6(e,o),appState:o,captureUpdate:jc.IMMEDIATELY}),keyTest:e=>Zc?e[ta.CTRL_OR_CMD]&&e.altKey&&e.code===oa.BRACKET_LEFT:e[ta.CTRL_OR_CMD]&&e.shiftKey&&e.code===oa.BRACKET_LEFT,PanelComponent:({updateData:e,appState:o})=>qc("button",{type:"button",className:"zIndexButton",onClick:()=>e(null),title:`${h("labels.sendToBack")} \u2014 ${Zc?N("CtrlOrCmd+Alt+["):N("CtrlOrCmd+Shift+[")}`,children:ku})}),Zu=O({name:"bringToFront",label:"labels.bringToFront",keywords:["move up","zindex","layer"],icon:Su,trackEvent:{category:"element"},perform:(e,o)=>({elements:g6(e,o),appState:o,captureUpdate:jc.IMMEDIATELY}),keyTest:e=>Zc?e[ta.CTRL_OR_CMD]&&e.altKey&&e.code===oa.BRACKET_RIGHT:e[ta.CTRL_OR_CMD]&&e.shiftKey&&e.code===oa.BRACKET_RIGHT,PanelComponent:({updateData:e,appState:o})=>qc("button",{type:"button",className:"zIndexButton",onClick:t=>e(null),title:`${h("labels.bringToFront")} \u2014 ${Zc?N("CtrlOrCmd+Alt+]"):N("CtrlOrCmd+Shift+]")}`,children:Su})});import{getNonDeletedElements as h6}from"@orangecatai/element";import{LinearElementEditor as f6}from"@orangecatai/element";import{isLinearElement as b6,isTextElement as x6}from"@orangecatai/element";import{arrayToMap as E6,KEYS as ZE}from"@orangecatai/common";import{selectGroupsForSelectedElements as y6}from"@orangecatai/element";import{CaptureUpdateAction as w6}from"@orangecatai/element";var ju=O({name:"selectAll",label:"labels.selectAll",icon:vE,trackEvent:{category:"canvas"},viewMode:!1,perform:(e,o,t,n)=>{if(o.selectedLinearElement?.isEditing)return!1;let r=e.filter(i=>!i.isDeleted&&!(x6(i)&&i.containerId)&&!i.locked).reduce((i,a)=>(i[a.id]=!0,i),{});return{appState:{...o,...y6({editingGroupId:null,selectedElementIds:r},h6(e),o,n),selectedLinearElement:Object.keys(r).length===1&&b6(e[0])?new f6(e[0],E6(e)):null},captureUpdate:w6.IMMEDIATELY}},keyTest:e=>e[ZE.CTRL_OR_CMD]&&e.key===ZE.A});import{DEFAULT_GRID_SIZE as jE,KEYS as qE,MOBILE_ACTION_BUTTON_BG as v6,arrayToMap as JE}from"@orangecatai/common";import{getNonDeletedElements as QE}from"@orangecatai/element";import{LinearElementEditor as T6}from"@orangecatai/element";import{getSelectedElements as I6,getSelectionStateForElements as C6}from"@orangecatai/element";import{syncMovedIndices as S6}from"@orangecatai/element";import{duplicateElements as k6}from"@orangecatai/element";import{CaptureUpdateAction as ey}from"@orangecatai/element";import{jsx as M6}from"react/jsx-runtime";var qu=O({name:"duplicateSelection",label:"labels.duplicateSelection",icon:Ls,trackEvent:{category:"element"},perform:(e,o,t,n)=>{if(o.selectedElementsAreBeingDragged)return!1;if(o.selectedLinearElement?.isEditing)try{let a=T6.duplicateSelectedPoints(o,n.scene);return{elements:e,appState:a,captureUpdate:ey.IMMEDIATELY}}catch{return!1}let{duplicatedElements:r,elementsWithDuplicates:i}=k6({type:"in-place",elements:e,idsOfElementsToDuplicate:JE(I6(e,o,{includeBoundTextElement:!0,includeElementsInFrames:!0})),appState:o,randomizeSeed:!0,overrides:({origElement:a,origIdToDuplicateId:s})=>{let l=a.frameId&&s.get(a.frameId);return{x:a.x+jE/2,y:a.y+jE/2,frameId:l??a.frameId}}});if(n.props.onDuplicate&&i){let a=n.props.onDuplicate(i,e);a&&(i=a)}return{elements:S6(i,JE(r)),appState:{...o,...C6(r,QE(i),o)},captureUpdate:ey.IMMEDIATELY}},keyTest:e=>e[qE.CTRL_OR_CMD]&&e.key===qE.D,PanelComponent:({elements:e,appState:o,updateData:t,app:n})=>{let r=ut()==="mobile";return M6(Q,{type:"button",icon:Ls,title:`${h("labels.duplicateSelection")} \u2014 ${N("CtrlOrCmd+D")}`,"aria-label":h("labels.duplicateSelection"),onClick:()=>t(null),disabled:!Le(QE(e),o),style:{...r&&o.openPopup!=="compactOtherProperties"?v6:{}}})}});import{pointFrom as MP}from"@orangecatai/math";import{useEffect as yg,useMemo as PP,useRef as wg,useState as LP}from"react";import{DEFAULT_ELEMENT_BACKGROUND_COLOR_PALETTE as AP,DEFAULT_ELEMENT_BACKGROUND_PICKS as DP,DEFAULT_ELEMENT_STROKE_COLOR_PALETTE as _P,DEFAULT_ELEMENT_STROKE_PICKS as RP,ARROW_TYPE as co,DEFAULT_FONT_FAMILY as NP,DEFAULT_FONT_SIZE as BP,FONT_FAMILY as FP,ROUNDNESS as gd,STROKE_WIDTH as vg,VERTICAL_ALIGN as pd,KEYS as da,randomInteger as OP,arrayToMap as Ig,getFontFamilyString as zP,getLineHeight as HP,isTransparent as GP,reduceToCommonValue as UP,invariant as Cg,FONT_SIZES as ud}from"@orangecatai/common";import{canBecomePolygon as WP,getNonDeletedElements as Yy}from"@orangecatai/element";import{bindBindingElement as Hy,calculateFixedPointForElbowArrowBinding as Gy,updateBoundElements as YP}from"@orangecatai/element";import{LinearElementEditor as ei}from"@orangecatai/element";import{newElementWith as lt}from"@orangecatai/element";import{getBoundTextElement as rr,redrawTextBoundingBox as qs}from"@orangecatai/element";import{isArrowElement as hd,isBoundToContainer as VP,isElbowArrow as Vy,isLinearElement as Tg,isLineElement as Uy,isTextElement as Ut,isUsingAdaptiveRadius as KP}from"@orangecatai/element";import{hasStrokeColor as XP}from"@orangecatai/element";import{updateElbowArrowPoints as $P,CaptureUpdateAction as ct,toggleLinePolygonState as ZP}from"@orangecatai/element";import{deriveStylesPanelMode as jP}from"@orangecatai/common";import{isDevEnv as P6}from"@orangecatai/common";var L6=new Set(["command_palette","export"]),me=(e,o,t,n)=>{try{if(typeof window>"u"||I.VITE_WORKER_ID||I.VITE_APP_ENABLE_TRACKING!=="true"||!L6.has(e)||P6())return;I.PROD||console.info("trackEvent",{category:e,action:o,label:t,value:n}),window.sa_event&&window.sa_event(o,{category:e,label:t,value:n})}catch(r){console.error("error during analytics",r)}};import R6 from"clsx";import A6 from"clsx";import{forwardRef as D6}from"react";import{jsx as _6}from"react/jsx-runtime";var na=D6((e,o)=>{let{title:t,className:n,testId:r,active:i,standalone:a,icon:s,onClick:l}=e;return _6("button",{type:"button",ref:o,title:t,"data-testid":r,className:A6(n,{standalone:a,active:i}),onClick:l,style:e.style,children:s},t)});import{Fragment as B6,jsx as Ju,jsxs as N6}from"react/jsx-runtime";var ao=e=>Ju(B6,{children:e.options.map(o=>e.type==="button"?Ju(na,{icon:o.icon,title:o.text,testId:o.testId,active:o.active??e.value===o.value,onClick:t=>e.onClick(o.value,t)},o.text):N6("label",{className:R6({active:e.value===o.value}),title:o.text,children:[Ju("input",{type:"radio",name:e.group,onChange:()=>e.onChange(o.value),checked:e.value===o.value,"data-testid":o.testId}),o.icon]},o.text))});import{Popover as yy}from"radix-ui";import wy from"clsx";import{useRef as vy,useEffect as OM}from"react";import{COLOR_OUTLINE_CONTRAST_THRESHOLD as xy,COLOR_PALETTE as Ty,isColorDark as Ey,isWritableElement as zM}from"@orangecatai/common";import{jsx as F6}from"react/jsx-runtime";var Jc=()=>F6("div",{style:{width:1,height:"1rem",backgroundColor:"var(--default-border-color)",margin:"0 auto"}});import{useEffect as U6,useRef as W6}from"react";import{createPortal as Y6}from"react-dom";import{EVENT as jn,KEYS as V6,rgbToHex as K6}from"@orangecatai/common";import ty from"react";var Qu=ty.createContext(null),he=()=>ty.useContext(Qu);import{useState as O6,useLayoutEffect as oy}from"react";import{THEME as z6}from"@orangecatai/common";var Qc=e=>{let[o,t]=O6(null),n=fe(),{theme:r}=he(),{container:i}=Oe();return oy(()=>{o&&(o.className="",o.classList.add("excalidraw",...e?.className?.split(/\s+/)||[]),o.classList.toggle("excalidraw--mobile",n.formFactor==="phone"),o.classList.toggle("theme--dark",r===z6.DARK))},[o,r,n.formFactor,e?.className]),oy(()=>{let a=e?.parentSelector?i?.querySelector(e.parentSelector):document.body;if(!a)return;let s=document.createElement("div");return a.appendChild(s),t(s),()=>{a.removeChild(s)}},[i,e?.parentSelector]),o};import{useEffect as H6}from"react";import{EVENT as ed}from"@orangecatai/common";function ra(e,o,t){H6(()=>{function n(r){let i=r;if(!e.current)return;let a=t?.(i,e.current);if(a===!0)return;if(a===!1)return o(i);e.current.contains(i.target)||!document.documentElement.contains(i.target)||i.target.closest("[data-radix-portal]")||i.target===document.documentElement&&document.body.style.pointerEvents==="none"||i.target.closest("[data-prevent-outside-click]")||o(i)}return document.addEventListener(ed.POINTER_DOWN,n),document.addEventListener(ed.TOUCH_START,n),()=>{document.removeEventListener(ed.POINTER_DOWN,n),document.removeEventListener(ed.TOUCH_START,n)}},[e,o,t])}import{useRef as G6}from"react";var Zn=e=>{let o=G6(e);return Object.assign(o.current,e),o.current};import{jsx as X6}from"react/jsx-runtime";var qn=ye(null),ny=({onCancel:e,onChange:o,onSelect:t,colorPickerType:n})=>{let r=Qc({className:"excalidraw-eye-dropper-backdrop",parentSelector:".excalidraw-eye-dropper-container"}),i=he(),a=Jn(),s=ze(),l=ne(a,i),c=Zn({app:s,onCancel:e,onChange:o,onSelect:t,selectedElements:l}),{container:m}=Oe();U6(()=>{let d=p.current;if(!d||!s.canvas||!r)return;let u=!1,b=s.canvas.getContext("2d"),g=({clientX:C,clientY:M})=>{let S=b.getImageData((C-i.offsetLeft)*window.devicePixelRatio,(M-i.offsetTop)*window.devicePixelRatio,1,1).data;return K6(S[0],S[1],S[2])},E=({clientX:C,clientY:M,altKey:S})=>{d.style.top=`${M+20}px`,d.style.left=`${C+20}px`;let D=g({clientX:C,clientY:M});u&&c.onChange(n,D,c.selectedElements,{altKey:S}),d.style.background=D},w=()=>{c.onCancel()},x=(C,M)=>{c.onSelect(C,M)},y=C=>{u=!0,C.stopImmediatePropagation()},v=C=>{u=!1,m?.focus(),C.stopImmediatePropagation(),C.preventDefault(),x(g(C),C)},T=C=>{C.key===V6.ESCAPE&&(C.preventDefault(),C.stopImmediatePropagation(),w())};return r.tabIndex=-1,r.focus(),E({clientX:c.app.lastViewportPosition.x,clientY:c.app.lastViewportPosition.y,altKey:!1}),r.addEventListener(jn.KEYDOWN,T),r.addEventListener(jn.POINTER_DOWN,y),r.addEventListener(jn.POINTER_UP,v),window.addEventListener("pointermove",E,{passive:!0}),window.addEventListener(jn.BLUR,w),()=>{u=!1,r.removeEventListener(jn.KEYDOWN,T),r.removeEventListener(jn.POINTER_DOWN,y),r.removeEventListener(jn.POINTER_UP,v),window.removeEventListener("pointermove",E),window.removeEventListener(jn.BLUR,w)}},[c,s.canvas,r,n,m,i.offsetLeft,i.offsetTop]);let p=W6(null);return ra(p,()=>{e()},d=>!!d.target.closest(".excalidraw-eye-dropper-trigger, .excalidraw-eye-dropper-backdrop")),r?Y6(X6("div",{ref:p,className:"excalidraw-eye-dropper-preview"}),r):null};import{Popover as eg}from"radix-ui";import q6 from"clsx";import J6 from"react";import{isInteractive as Q6}from"@orangecatai/common";import $6 from"react";import Z6 from"clsx";import{jsx as j6}from"react/jsx-runtime";var qe=$6.forwardRef(({children:e,padding:o,className:t,style:n},r)=>j6("div",{className:Z6("Island",t),style:{"--padding":o,...n},ref:r,children:e}));import{jsx as tg,jsxs as eM}from"react/jsx-runtime";var Tn=J6.forwardRef(({className:e,container:o,children:t,style:n,onClose:r,onKeyDown:i,onFocusOutside:a,onPointerLeave:s,onPointerDownOutside:l,preventAutoFocusOnTouch:c=!1},m)=>{let p=fe(),d=p.formFactor==="phone"&&!p.isLandscape;return tg(eg.Portal,{container:o,children:eM(eg.Content,{ref:m,className:q6("focus-visible-none",e),"data-prevent-outside-click":!0,side:d?"bottom":"right",align:d?"center":"start",alignOffset:-16,sideOffset:20,collisionBoundary:o??void 0,style:{zIndex:"var(--zIndex-ui-styles-popup)",marginLeft:p.formFactor==="phone"?"0.5rem":void 0},onPointerLeave:s,onKeyDown:i,onFocusOutside:a,onPointerDownOutside:l,onOpenAutoFocus:u=>{c&&p.isTouchScreen&&u.preventDefault()},onCloseAutoFocus:u=>{u.stopPropagation(),u.preventDefault(),o&&!Q6(document.activeElement)&&o.focus(),r()},children:[tg(qe,{padding:3,style:n,children:t}),tg(eg.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 tM,useCallback as og}from"react";var td=()=>document.querySelector(".excalidraw-wysiwyg"),od=()=>{let e=td();return e?{start:e.selectionStart,end:e.selectionEnd}:null},Hs=e=>{setTimeout(()=>{let o=td();o&&(o.focus(),e&&(o.selectionStart=e.start,o.selectionEnd=e.end))},0)},Gs=(e,o,t,n)=>{o&&n&&n();let r=o&&t?od():null;e(),o&&t&&Hs(r)},ry=()=>{let[e,o]=tM(null),t=og(()=>{let i=od();o(i)},[]),n=og(()=>{setTimeout(()=>{let i=td();i&&(i.focus(),e&&(i.selectionStart=e.start,i.selectionEnd=e.end,o(null)))},0)},[e]),r=og(()=>{o(null)},[]);return{saveCaretPosition:t,restoreCaretPosition:n,clearSavedPosition:r,hasSavedPosition:!!e}},iy=(e=100)=>{let o=td();if(o){let t=o.onblur;o.onblur=null,setTimeout(()=>{o.onblur=t},e)}};import nM from"clsx";import{useCallback as rM,useEffect as rg,useRef as sy,useState as iM}from"react";import{KEYS as ig,normalizeInputColor as aM}from"@orangecatai/common";import{MAX_CUSTOM_COLORS_USED_IN_CANVAS as oM}from"@orangecatai/common";var Qn=({palette:e,color:o})=>{if(!o)return null;for(let[t,n]of Object.entries(e))if(Array.isArray(n)){let r=n.indexOf(o);if(r>-1)return{colorName:t,shade:r}}else if(n===o)return{colorName:t,shade:null};return null},Us=[["q","w","e","r","t"],["a","s","d","f","g"],["z","x","c","v","b"]].flat(),ng=({color:e,palette:o})=>!Object.values(o).flat().includes(e),ay=(e,o,t)=>{let n={elementBackground:"backgroundColor",elementStroke:"strokeColor"},r=e.filter(a=>{if(a.isDeleted)return!1;let s=a[n[o]];return ng({color:s,palette:t})}),i=new Map;return r.forEach(a=>{let s=a[n[o]];i.has(s)?i.set(s,i.get(s)+1):i.set(s,1)}),[...i.entries()].sort((a,s)=>s[1]-a[1]).map(a=>a[0]).slice(0,oM)},so=ye(null);import{Fragment as sM,jsx as nd,jsxs as ly}from"react/jsx-runtime";var cy=({color:e,onChange:o,label:t,colorPickerType:n,placeholder:r})=>{let i=fe(),[a,s]=iM(e),[l,c]=ee(so);rg(()=>{s(e)},[e]);let m=rM(g=>{let E=g.toLowerCase(),w=aM(E);w&&o(w),s(E)},[o]),p=sy(null),d=sy(null);rg(()=>{p.current&&p.current.focus()},[l]);let[u,b]=ee(qn);return rg(()=>()=>{b(null)},[b]),ly("div",{className:"color-picker__input-label",children:[nd("div",{className:"color-picker__input-hash",children:"#"}),nd("input",{ref:l==="hex"?p:void 0,style:{border:0,padding:0},spellCheck:!1,className:"color-picker-input","aria-label":t,onChange:g=>{m(g.target.value)},value:(a||"").replace(/^#/,""),onBlur:()=>{s(e)},tabIndex:-1,onFocus:()=>c("hex"),onKeyDown:g=>{g.key!==ig.TAB&&(g.key===ig.ESCAPE&&d.current?.focus(),g.stopPropagation())},placeholder:r}),i.formFactor!=="phone"&&ly(sM,{children:[nd("div",{style:{width:"1px",height:"1.25rem",backgroundColor:"var(--default-border-color)"}}),nd("div",{ref:d,className:nM("excalidraw-eye-dropper-trigger",{selected:u}),onClick:()=>b(g=>g?null:{keepOpenOnAlt:!1,onSelect:E=>o(E),colorPickerType:n}),title:`${h("labels.eyeDropper")} \u2014 ${ig.I.toLocaleUpperCase()} or ${N("Alt")} `,children:mE})]})]})};import cg,{useEffect as dg,useImperativeHandle as kM,useState as MM}from"react";import{EVENT as hy}from"@orangecatai/common";import{DEFAULT_ELEMENT_BACKGROUND_COLOR_INDEX as PM,DEFAULT_ELEMENT_STROKE_COLOR_INDEX as LM,KEYS as AM}from"@orangecatai/common";import mM from"clsx";import{useEffect as pM,useRef as uM}from"react";import{isColorDark as lM}from"@orangecatai/common";import{jsxs as dM}from"react/jsx-runtime";var cM=({color:e,keyLabel:o,isShade:t=!1})=>dM("div",{className:"color-picker__button__hotkey-label",style:{color:lM(e)?"#fff":"#000"},children:[t&&"\u21E7",o]}),ia=cM;import{jsx as ag,jsxs as gM}from"react/jsx-runtime";var dy=({colors:e,color:o,onChange:t,label:n})=>{let[r,i]=ee(so),a=uM(null);return pM(()=>{a.current&&a.current.focus()},[o,r]),ag("div",{className:"color-picker-content--default",children:e.map((s,l)=>gM("button",{ref:o===s?a:void 0,tabIndex:-1,type:"button",className:mM("color-picker__button color-picker__button--large has-outline",{active:o===s,"is-transparent":s==="transparent"||!s}),onClick:()=>{t(s),i("custom")},title:s,"aria-label":n,style:{"--swatch-color":s},children:[ag("div",{className:"color-picker__button-outline"}),ag(ia,{color:s,keyLabel:l+1})]},l))})};import hM from"clsx";import{useEffect as fM,useRef as bM}from"react";import{jsx as sg,jsxs as EM}from"react/jsx-runtime";var xM=({palette:e,color:o,onChange:t,activeShade:n,showHotKey:r=!0})=>{let i=Qn({color:o,palette:e}),[a,s]=ee(so),l=bM(null);return fM(()=>{l.current&&a==="baseColors"&&l.current.focus()},[i?.colorName,a]),sg("div",{className:"color-picker-content--default",children:Object.entries(e).map(([c,m],p)=>{let d=(Array.isArray(m)?m[n]:m)||"transparent",u=Us[p],b=h(`colors.${c.replace(/\d+/,"")}`,null,"");return EM("button",{ref:i?.colorName===c?l:void 0,tabIndex:-1,type:"button",className:hM("color-picker__button color-picker__button--large has-outline",{active:i?.colorName===c,"is-transparent":d==="transparent"||!d}),onClick:()=>{t(d),s("baseColors")},title:`${b}${d.startsWith("#")?` ${d}`:""} \u2014 ${u}`,"aria-label":`${b} \u2014 ${u}`,style:d?{"--swatch-color":d}:void 0,"data-testid":`color-${c}`,children:[sg("div",{className:"color-picker__button-outline"}),r&&sg(ia,{color:d,keyLabel:u})]},c)})})},my=xM;import{jsx as wM}from"react/jsx-runtime";var yM=({children:e})=>wM("div",{className:"color-picker__heading",children:e}),aa=yM;import vM from"clsx";import{useEffect as TM,useRef as IM}from"react";import{jsx as Ws,jsxs as py}from"react/jsx-runtime";var uy=({color:e,onChange:o,palette:t,showHotKey:n})=>{let r=Qn({color:e||"transparent",palette:t}),[i,a]=ee(so),s=IM(null);if(TM(()=>{s.current&&i==="shades"&&s.current.focus()},[r,i]),r){let{colorName:l,shade:c}=r,m=t[l];if(Array.isArray(m))return Ws("div",{className:"color-picker-content--default shades",children:m.map((p,d)=>py("button",{ref:d===c&&i==="shades"?s:void 0,tabIndex:-1,type:"button",className:vM("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:()=>{o(p),a("shades")},children:[Ws("div",{className:"color-picker__button-outline"}),n&&Ws(ia,{color:p,keyLabel:d+1,isShade:!0})]},d))})}return py("div",{className:"color-picker-content--default",style:{position:"relative"},tabIndex:-1,children:[Ws("button",{type:"button",tabIndex:-1,className:"color-picker__button color-picker__button--large color-picker__button--no-focus-visible"}),Ws("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:h("colorPicker.noShades")})]})};import{COLORS_PER_ROW as sa,COLOR_PALETTE as CM,KEYS as Ys}from"@orangecatai/common";var lg=(e,o,t)=>{let n=Math.ceil(t/sa);switch(o=o??-1,e){case"ArrowLeft":{let r=o-1;return r<0?t-1:r}case"ArrowRight":return(o+1)%t;case"ArrowDown":{let r=o+sa;return r>=t?o%sa:r}case"ArrowUp":{let r=o-sa,i=r<0?sa*n+r:r;return i>=t?void 0:i}}},SM=({e,colorObj:o,onChange:t,palette:n,customColors:r,setActiveColorPickerSection:i,activeShade:a})=>{if(o?.shade!=null&&["Digit1","Digit2","Digit3","Digit4","Digit5"].includes(e.code)&&e.shiftKey){let s=Number(e.code.slice(-1))-1;return t(n[o.colorName][s]),i("shades"),!0}if(["1","2","3","4","5"].includes(e.key)&&r[Number(e.key)-1])return t(r[Number(e.key)-1]),i("custom"),!0;if(Us.includes(e.key)){let s=Us.indexOf(e.key),l=Object.keys(n)[s],c=n[l],m=Array.isArray(c)?c[a]:c;return t(m),i("baseColors"),!0}return!1},gy=({event:e,activeColorPickerSection:o,palette:t,color:n,onChange:r,customColors:i,setActiveColorPickerSection:a,updateData:s,activeShade:l,onEyeDropperToggle:c,onEscape:m})=>{if(e[Ys.CTRL_OR_CMD])return!1;if(e.key===Ys.ESCAPE)return m(e),!0;if(e.key===Ys.ALT)return c(!0),!0;if(e.key===Ys.I)return c(),!0;let p=Qn({color:n,palette:t});if(e.key===Ys.TAB){let d={custom:!!i.length,baseColors:!0,shades:p?.shade!=null,hex:!0},u=Object.entries(d).reduce((x,[y,v])=>(v&&x.push(y),x),[]),b=u.indexOf(o),g=e.shiftKey?-1:1,E=b+g>u.length-1?0:b+g<0?u.length-1:b+g,w=u[E];return w&&a(w),w==="custom"?r(i[0]):w==="baseColors"&&(Object.entries(t).find(([y,v])=>Array.isArray(v)?v.includes(n):v===n?y:null)||r(CM.black)),e.preventDefault(),e.stopPropagation(),!0}if(SM({e,colorObj:p,onChange:r,palette:t,customColors:i,setActiveColorPickerSection:a,activeShade:l}))return!0;if(o==="shades"&&p){let{shade:d}=p,u=lg(e.key,d,sa);if(u!==void 0)return r(t[p.colorName][u]),!0}if(o==="baseColors"&&p){let{colorName:d}=p,u=Object.keys(t),b=u.indexOf(d),g=lg(e.key,b,u.length);if(g!==void 0){let E=u[g],w=t[E];return r(Array.isArray(w)?w[l]:w),!0}}if(o==="custom"){let d=n!=null?i.indexOf(n):0,u=lg(e.key,d,i.length);if(u!==void 0){let b=i[u];return r(b),!0}}return!1};import{jsx as er,jsxs as rd}from"react/jsx-runtime";var fy=cg.forwardRef(({color:e,onChange:o,type:t,elements:n,palette:r,updateData:i,children:a,showTitle:s,onEyeDropperToggle:l,onEscape:c,showHotKey:m=!0},p)=>{let d=s?t==="elementStroke"?h("labels.stroke"):t==="elementBackground"?h("labels.background"):null:null,[u]=cg.useState(()=>t==="canvasBackground"?[]:ay(n,t,r)),[b,g]=ee(so),E=Qn({color:e,palette:r});dg(()=>{if(!b){let v=!!e&&ng({color:e,palette:r}),T=v&&!u.includes(e);g(T?null:v?"custom":E?.shade!=null?"shades":"baseColors")}},[b,e,r,g,E,u]);let[w,x]=MM(E?.shade??(t==="elementBackground"?PM:LM));dg(()=>{E?.shade!=null&&x(E.shade);let v=T=>{T.key===AM.ALT&&l(!1)};return document.addEventListener(hy.KEYUP,v,{capture:!0}),()=>{document.removeEventListener(hy.KEYUP,v,{capture:!0})}},[E,l]);let y=cg.useRef(null);return kM(p,()=>y.current),dg(()=>{y?.current?.focus()},[]),er("div",{role:"dialog","aria-modal":"true","aria-label":h("labels.colorPicker"),children:rd("div",{ref:y,onKeyDown:v=>{gy({event:v,activeColorPickerSection:b,palette:r,color:e,onChange:o,onEyeDropperToggle:l,customColors:u,setActiveColorPickerSection:g,updateData:i,activeShade:w,onEscape:c})&&(v.preventDefault(),v.stopPropagation())},className:"color-picker-content properties-content",tabIndex:-1,children:[d&&er("div",{className:"color-picker__title",children:d}),!!u.length&&rd("div",{children:[er(aa,{children:h("colorPicker.mostUsedCustomColors")}),er(dy,{colors:u,color:e,label:h("colorPicker.mostUsedCustomColors"),onChange:o})]}),rd("div",{children:[er(aa,{children:h("colorPicker.colors")}),er(my,{color:e,palette:r,onChange:o,activeShade:w,showHotKey:m})]}),rd("div",{children:[er(aa,{children:h("colorPicker.shades")}),er(uy,{color:e,onChange:o,palette:r,showHotKey:m})]}),a]})})});import DM from"clsx";import{COLOR_OUTLINE_CONTRAST_THRESHOLD as _M,DEFAULT_CANVAS_BACKGROUND_PICKS as RM,DEFAULT_ELEMENT_BACKGROUND_PICKS as NM,DEFAULT_ELEMENT_STROKE_PICKS as BM,isColorDark as FM}from"@orangecatai/common";import{jsx as mg}from"react/jsx-runtime";var by=({onChange:e,type:o,activeColor:t,topPicks:n})=>{let r;return o==="elementStroke"&&(r=BM),o==="elementBackground"&&(r=NM),o==="canvasBackground"&&(r=RM),n&&(r=n),r?mg("div",{className:"color-picker__top-picks",children:r.map(i=>mg("button",{className:DM("color-picker__button",{active:i===t,"is-transparent":i==="transparent"||!i,"has-outline":!FM(i,_M)}),style:{"--swatch-color":i},type:"button",title:i,onClick:()=>e(i),"data-testid":`color-top-pick-${i}`,children:mg("div",{className:"color-picker__button-outline"})},i))}):(console.error("Invalid type for TopPicks"),null)};import{jsx as lo,jsxs as id}from"react/jsx-runtime";var HM=({type:e,color:o,onChange:t,label:n,elements:r,palette:i=Ty,updateData:a,getOpenPopup:s,appState:l})=>{let{container:c}=Oe(),m=ut(),p=m!=="full",d=m==="mobile",[,u]=ee(so),[b,g]=ee(qn),E=id("div",{children:[lo(aa,{children:h("colorPicker.hexCode")}),lo(cy,{color:o||"",label:n,onChange:y=>{t(y)},colorPickerType:e,placeholder:h("colorPicker.color")})]}),w=vy(null),x=()=>{w.current?.focus()};return lo(Tn,{container:c,style:{maxWidth:"13rem"},preventAutoFocusOnTouch:!!l.editingTextElement,onFocusOutside:y=>{zM(y.target)||x(),y.preventDefault()},onPointerDownOutside:y=>{b&&y.preventDefault()},onClose:()=>{s()===e&&a({openPopup:null}),u(null),l.editingTextElement&&setTimeout(()=>{let y=document.querySelector(".excalidraw-wysiwyg");y&&y.focus()},0)},children:i?lo(fy,{ref:w,palette:i,color:o,onChange:y=>{let v=l.editingTextElement?od():null;t(y),l.editingTextElement&&v&&Hs(v)},onEyeDropperToggle:y=>{g(v=>y?(v=v||{keepOpenOnAlt:!0,onSelect:t,colorPickerType:e},v.keepOpenOnAlt=!0,v):y===!1||v?null:{keepOpenOnAlt:!1,onSelect:t,colorPickerType:e})},onEscape:y=>{b?g(null):a({openPopup:null})},type:e,elements:r,updateData:a,showTitle:p,showHotKey:!d,children:E}):E})},GM=({label:e,color:o,type:t,mode:n="background",onToggle:r,editingTextElement:i})=>{let a=ut(),s=a!=="full",l=a==="mobile",c=m=>{m.preventDefault(),m.stopPropagation(),i&&iy(),r()};return id(yy.Trigger,{type:"button",className:wy("color-picker__button active-color properties-trigger",{"is-transparent":!o||o==="transparent","has-outline":!o||!Ey(o,xy),"compact-sizing":s,"mobile-border":l}),"aria-label":e,style:o?{"--swatch-color":o}:void 0,title:t==="elementStroke"?h("labels.showStroke"):h("labels.showBackground"),"data-openpopup":t,onClick:c,children:[lo("div",{className:"color-picker__button-outline",children:!o&&hx}),s&&o&&n==="stroke"&&lo("div",{className:"color-picker__button-background",children:lo("span",{style:{color:o&&Ey(o,xy)?"#fff":"#111"},children:FE})})]})},Vs=({type:e,color:o,onChange:t,label:n,elements:r,palette:i=Ty,topPicks:a,updateData:s,appState:l})=>{let c=vy(l.openPopup);OM(()=>{c.current=l.openPopup},[l.openPopup]);let p=ut()!=="full";return lo("div",{children:id("div",{role:"dialog","aria-modal":"true",className:wy("color-picker-container",{"color-picker-container--no-top-picks":p}),children:[!p&&lo(by,{activeColor:o,onChange:t,type:e,topPicks:a}),!p&&lo(Jc,{}),id(yy.Root,{open:l.openPopup===e,onOpenChange:d=>{d&&s({openPopup:e})},children:[lo(GM,{color:o,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&&lo(HM,{type:e,color:o,onChange:t,label:n,elements:r,palette:i,updateData:s,getOpenPopup:()=>c.current,appState:l})]})]})})};import{Popover as gP}from"radix-ui";import hP from"clsx";import fP,{useCallback as bP,useMemo as xP}from"react";import{FONT_FAMILY as hg}from"@orangecatai/common";import iP,{useMemo as nr,useState as aP,useRef as ky,useEffect as My,useCallback as Py}from"react";import{arrayToList as sP,debounce as lP,FONT_FAMILY as Jr,getFontFamilyString as cP}from"@orangecatai/common";import UM from"clsx";import WM from"react";import{jsx as YM,jsxs as VM}from"react/jsx-runtime";var ad=WM.forwardRef(({className:e,placeholder:o,onChange:t},n)=>VM("div",{className:UM("QuickSearch__wrapper",e),children:[jt,YM("input",{ref:n,className:"QuickSearch__input",type:"text",placeholder:o,onChange:r=>t(r.target.value.trim().toLowerCase())})]}));import KM from"clsx";import{Children as XM}from"react";import{jsx as Iy}from"react/jsx-runtime";var sd=({className:e,placeholder:o,children:t})=>{let n=!XM.count(t);return Iy("div",{className:KM("ScrollableList__wrapper",e),role:"menu",children:n?Iy("div",{className:"empty",children:o}):t})};import{jsx as $M,jsxs as ZM}from"react/jsx-runtime";var Cy=({children:e,className:o="",style:t,title:n})=>ZM("div",{className:`dropdown-menu-group ${o}`,style:t,children:[n&&$M("p",{className:"dropdown-menu-group-title",children:n}),e]}),Ks=Cy;Cy.displayName="DropdownMenuGroup";import{THEME as nP}from"@orangecatai/common";import{DropdownMenu as rP}from"radix-ui";import jM,{useContext as qM}from"react";import{composeEventHandlers as JM}from"@orangecatai/common";var pg=jM.createContext({}),tr=(e="",o=!1,t=!1)=>`dropdown-menu-item dropdown-menu-item-base ${e} ${o?"dropdown-menu-item--selected":""} ${t?"dropdown-menu-item--hovered":""}`.trim(),ld=e=>{let o=qM(pg);return JM(e,t=>{o.onSelect?.(t)})};import{jsx as QM}from"react/jsx-runtime";var Xs=({children:e,...o})=>QM("span",{...o,style:{textOverflow:"ellipsis",overflow:"hidden",whiteSpace:"nowrap",...o.style},children:e});import{Fragment as tP,jsx as $s,jsxs as oP}from"react/jsx-runtime";var eP=({textStyle:e,icon:o,shortcut:t,children:n,badge:r})=>{let i=fe();return oP(tP,{children:[o&&$s("div",{className:"dropdown-menu-item__icon",children:o}),$s("div",{style:e,className:"dropdown-menu-item__text",children:$s(Xs,{children:n})}),r&&$s("div",{className:"dropdown-menu-item__badge",children:r}),t&&i.formFactor!=="phone"&&$s("div",{className:"dropdown-menu-item__shortcut",children:t})]})},or=eP;import{jsx as cd}from"react/jsx-runtime";var ug=({icon:e,badge:o,value:t,children:n,shortcut:r,className:i,selected:a,onSelect:s,...l})=>{let c=ld(s);return cd(rP.Item,{className:"radix-menu-item",onSelect:c,asChild:!0,children:cd("button",{...l,value:t,className:tr(i,a),title:l.title??l["aria-label"],children:cd(or,{icon:e,shortcut:r,badge:o,children:n})})})};ug.displayName="DropdownMenuItem";var la={GREEN:"green",RED:"red",BLUE:"blue"},dd=({type:e=la.BLUE,children:o})=>{let{theme:t}=Zo(),n={display:"inline-flex",marginLeft:"auto",padding:"2px 4px",borderRadius:6,fontSize:9,fontFamily:"Cascadia, monospace",border:t===nP.LIGHT?"1.5px solid white":"none"};switch(e){case la.GREEN:Object.assign(n,{backgroundColor:"var(--background-color-badge)",color:"var(--color-badge)"});break;case la.RED:Object.assign(n,{backgroundColor:"pink",color:"darkred"});break;case la.BLUE:default:Object.assign(n,{background:"var(--color-promo)",color:"var(--color-surface-lowest)"})}return cd("div",{className:"DropDownMenuItemBadge",style:n,children:o})};dd.displayName="DropdownMenuItemBadge";ug.Badge=dd;var At=ug;import{KEYS as ca}from"@orangecatai/common";var Sy=({event:e,inputRef:o,hoveredFont:t,filteredFonts:n,onClose:r,onSelect:i,onHover:a})=>{if(!e[ca.CTRL_OR_CMD]&&e.shiftKey&&e.key.toLowerCase()===ca.F)return o.current?.focus(),!0;if(e.key===ca.ESCAPE)return r(),!0;if(e.key===ca.ENTER)return t?.value&&i(t.value),!0;if(e.key===ca.ARROW_DOWN)return t?.next?a(t.next.value):n[0]?.value&&a(n[0].value),!0;if(e.key===ca.ARROW_UP)return t?.prev?a(t.prev.value):n[n.length-1]?.value&&a(n[n.length-1].value),!0};import{jsx as In,jsxs as mP}from"react/jsx-runtime";var dP=e=>{switch(e){case Jr.Excalifont:case Jr.Virgil:return Ko;case Jr.Nunito:case Jr.Helvetica:return Rs;case Jr["Lilita One"]:return eE;case Jr["Comic Shanns"]:case Jr.Cascadia:return zc;default:return Rs}},Ly=iP.memo(({selectedFontFamily:e,hoveredFontFamily:o,onSelect:t,onHover:n,onLeave:r,onOpen:i,onClose:a})=>{let{container:s}=Oe(),l=ze(),{fonts:c}=l,{showDeprecatedFonts:m}=jo(),p=ut(),[d,u]=aP(""),b=ky(null),g=nr(()=>Array.from(Yn.registered.entries()).filter(([P,{metadata:A}])=>!A.private&&!A.fallback).map(([P,{metadata:A,fontFaces:z}])=>{let V={value:P,icon:dP(P),text:z[0]?.fontFace?.family??"Unknown"};return A.deprecated&&Object.assign(V,{deprecated:A.deprecated,badge:{type:la.RED,placeholder:h("fontList.badge.old")}}),V}).sort((P,A)=>P.text.toLowerCase()>A.text.toLowerCase()?1:-1),[]),E=nr(()=>new Set(c.getSceneFamilies()),[e]),w=nr(()=>g.filter(P=>E.has(P.value)),[g,E]),x=nr(()=>g.filter(P=>!E.has(P.value)&&(m||!P.deprecated)),[g,E,m]),y=nr(()=>sP([...w,...x].filter(P=>P.text?.toLowerCase().includes(d))),[w,x,d]),v=nr(()=>{let P;return o?P=y.find(A=>A.value===o):e&&(P=y.find(A=>A.value===e)),!P&&d&&(y[0]?.value?n(y[0].value):r()),P},[o,e,d,y,n,r]),T=Py(P=>{let A=null;if(l.state.editingTextElement){let z=document.querySelector(".excalidraw-wysiwyg");z&&(A={start:z.selectionStart,end:z.selectionEnd})}t(P),l.state.editingTextElement&&A&&setTimeout(()=>{let z=document.querySelector(".excalidraw-wysiwyg");z&&A&&(z.focus(),z.selectionStart=A.start,z.selectionEnd=A.end)},0)},[t,l.state.editingTextElement]),C=Py(P=>{Sy({event:P,inputRef:b,hoveredFont:v,filteredFonts:y,onSelect:T,onHover:n,onClose:a})&&(P.preventDefault(),P.stopPropagation())},[v,y,T,n,a]);My(()=>(i(),()=>{a()}),[]);let M=nr(()=>y.filter(P=>E.has(P.value)),[y,E]),S=nr(()=>y.filter(P=>!E.has(P.value)),[y,E]),D=({font:P,order:A})=>{let z=ky(null),V=P.value===v?.value,G=P.value===e;return My(()=>{V&&(A===0?z.current?.scrollIntoView?.({block:"end"}):z.current?.scrollIntoView?.({block:"nearest"}))},[V,A]),In("button",{ref:z,type:"button",value:P.value,className:tr("",G,V),title:P.text,tabIndex:G?0:-1,onClick:Y=>{T(Number(Y.currentTarget.value))},onMouseMove:()=>{v?.value!==P.value&&n(P.value)},children:In(or,{icon:P.icon,badge:P.badge&&In(dd,{type:P.badge.type,children:P.badge.placeholder}),textStyle:{fontFamily:cP({fontFamily:P.value})},children:P.text})})},_=[];return M.length&&_.push(In(Ks,{title:h("fontList.sceneFonts"),children:M.map((P,A)=>In(D,{font:P,order:A},P.value))},"group_1")),S.length&&_.push(In(Ks,{title:h("fontList.availableFonts"),children:S.map((P,A)=>In(D,{font:P,order:A+M.length},P.value))},"group_2")),mP(Tn,{className:"properties-content",container:s,style:{width:"15rem"},onClose:()=>{a(),l.state.editingTextElement&&setTimeout(()=>{let P=document.querySelector(".excalidraw-wysiwyg");P&&P.focus()},0)},onPointerLeave:r,onKeyDown:C,preventAutoFocusOnTouch:!!l.state.editingTextElement,children:[p==="full"&&In(ad,{ref:b,placeholder:h("quickSearch.placeholder"),onChange:lP(u,20)}),In(sd,{className:"dropdown-menu fonts manual-hover",placeholder:h("fontList.empty"),children:_.length?_:null})]})},(e,o)=>e.selectedFontFamily===o.selectedFontFamily&&e.hoveredFontFamily===o.hoveredFontFamily);import{Popover as pP}from"radix-ui";import{MOBILE_ACTION_BUTTON_BG as uP}from"@orangecatai/common";import{jsx as gg}from"react/jsx-runtime";var Ay=({selectedFontFamily:e,isOpened:o=!1,compactMode:t=!1})=>{let n=be(),r=t?{...uP,width:"2rem",height:"2rem"}:{};return gg(pP.Trigger,{asChild:!0,children:gg("div",{"data-openpopup":"fontFamily",className:"properties-trigger",children:gg(na,{standalone:!0,icon:Xo,title:h("labels.showFonts"),className:"properties-trigger",testId:"font-family-show-fonts",active:o,onClick:()=>{n(i=>({openPopup:i.openPopup==="fontFamily"?null:i.openPopup}))},style:{border:"none",...r}})})})};import{jsx as Zs,jsxs as Dy}from"react/jsx-runtime";var _y=[{value:hg.Excalifont,icon:Ko,text:h("labels.handDrawn"),testId:"font-family-hand-drawn"},{value:hg.Nunito,icon:Rs,text:h("labels.normal"),testId:"font-family-normal"},{value:hg["Comic Shanns"],icon:zc,text:h("labels.code"),testId:"font-family-code"}],pee=new Set(_y.map(e=>e.value));var Ry=fP.memo(({isOpened:e,selectedFontFamily:o,hoveredFontFamily:t,onSelect:n,onHover:r,onLeave:i,onPopupChange:a,compactMode:s=!1})=>{let l=xP(()=>_y,[]),c=bP(m=>{m&&n(m)},[n]);return Dy("div",{role:"dialog","aria-modal":"true",className:hP("FontPicker__container",{"FontPicker__container--compact":s}),children:[!s&&Zs("div",{className:"buttonList",children:Zs(ao,{type:"button",options:l,value:o,onClick:c})}),!s&&Zs(Jc,{}),Dy(gP.Root,{open:e,onOpenChange:a,children:[Zs(Ay,{selectedFontFamily:o,isOpened:e,compactMode:s}),e&&Zs(Ly,{selectedFontFamily:o,hoveredFontFamily:t,onSelect:c,onHover:r,onLeave:i,onOpen:()=>a(!0),onClose:()=>a(!1)})]})]})},(e,o)=>e.isOpened===o.isOpened&&e.selectedFontFamily===o.selectedFontFamily&&e.hoveredFontFamily===o.hoveredFontFamily);import{Popover as fg}from"radix-ui";import vP from"clsx";import md,{useEffect as TP}from"react";import{isArrowKey as IP,KEYS as Cn}from"@orangecatai/common";import{jsx as EP}from"react/jsx-runtime";var qo=({className:e,icon:o,size:t="1em"})=>EP("span",{className:e,style:{width:t,height:"100%",margin:"0 0.5ex 0 0.5ex",display:"inline-flex",lineHeight:0,verticalAlign:"middle",flex:"0 0 auto"},children:o});import{Fragment as wP,jsx as Ny,jsxs as By}from"react/jsx-runtime";var yP=({label:e,open:o,openTrigger:t,children:n,className:r,showCollapsedIcon:i=!0})=>By(wP,{children:[By("div",{style:{cursor:"pointer",display:"flex",justifyContent:"space-between",alignItems:"center"},className:r,onClick:t,children:[e,i&&Ny(qo,{icon:o?RE:Wc})]}),o&&Ny("div",{style:{display:"flex",flexDirection:"column"},children:n})]}),js=yP;import{jsx as Qr,jsxs as bg}from"react/jsx-runtime";var CP=ye(!1);function SP({options:e,value:o,label:t,onChange:n,onClose:r,numberOfOptionsToAlwaysShow:i=e.length}){let a=fe(),{container:s}=Oe(),l=g=>{let E=e.find(w=>w.keyBinding===g.key.toLowerCase());if(!(g.metaKey||g.altKey||g.ctrlKey)&&E)n(E.value),g.preventDefault();else if(g.key===Cn.TAB){let w=e.findIndex(y=>y.value===o),x=g.shiftKey?(e.length+w-1)%e.length:(w+1)%e.length;n(e[x].value)}else if(IP(g.key)){let w=vn().rtl,x=e.findIndex(y=>y.value===o);if(x!==-1){let y=e.length,v=x;switch(g.key){case(w?Cn.ARROW_LEFT:Cn.ARROW_RIGHT):v=(x+1)%y;break;case(w?Cn.ARROW_RIGHT:Cn.ARROW_LEFT):v=(y+x-1)%y;break;case Cn.ARROW_DOWN:{v=(x+(i??1))%y;break}case Cn.ARROW_UP:{v=(y+x-(i??1))%y;break}}n(e[v].value)}g.preventDefault()}else(g.key===Cn.ESCAPE||g.key===Cn.ENTER)&&(g.preventDefault(),r());g.nativeEvent.stopImmediatePropagation(),g.stopPropagation()},[c,m]=ee(CP),p=md.useMemo(()=>e.slice(0,i),[e,i]),d=md.useMemo(()=>e.slice(i),[e,i]);TP(()=>{p.some(g=>g.value===o)||m(!0)},[o,p,m]);let u=g=>Qr("div",{className:"picker-content",children:g.map((E,w)=>bg("button",{type:"button",className:vP("picker-option",{active:o===E.value}),onClick:x=>{n(E.value)},title:`${E.text} ${E.keyBinding&&`\u2014 ${E.keyBinding.toUpperCase()}`}`,"aria-label":E.text||"none","aria-keyshortcuts":E.keyBinding||void 0,ref:x=>{o===E.value&&setTimeout(()=>{x?.focus()},0)},children:[E.icon,E.keyBinding&&Qr("span",{className:"picker-keybinding",children:E.keyBinding})]},E.text))}),b=a.formFactor==="phone";return Qr(fg.Content,{side:b?"right":"bottom",align:"start",sideOffset:b?8:12,style:{zIndex:"var(--zIndex-ui-styles-popup)"},onKeyDown:l,collisionBoundary:s??void 0,children:bg("div",{className:"picker",role:"dialog","aria-modal":"true","aria-label":t,children:[u(p),d.length>0&&Qr(js,{label:h("labels.more_options"),open:c,openTrigger:()=>{m(g=>!g)},className:"picker-collapsible",children:u(d)})]})})}function xg({value:e,label:o,options:t,onChange:n,group:r="",numberOfOptionsToAlwaysShow:i}){let[a,s]=md.useState(!1),l=md.useRef(null);return Qr("div",{children:bg(fg.Root,{open:a,onOpenChange:c=>s(c),children:[Qr(fg.Trigger,{name:r,type:"button","aria-label":o,onClick:()=>s(!a),ref:l,className:a?"active":"",children:t.find(c=>c.value===e)?.icon}),a&&Qr(SP,{options:t,value:e,label:o,onChange:n,onClose:()=>{s(!1)},numberOfOptionsToAlwaysShow:i})]})})}import Fy,{useEffect as kP}from"react";import{jsx as Eg,jsxs as Oy}from"react/jsx-runtime";var zy=({updateData:e,app:o,testId:t})=>{let n=Fy.useRef(null),r=Fy.useRef(null),i=o.scene.getSelectedElements(o.state),a=!0,s=i.at(0),c=i.reduce((m,p)=>(m!=null&&m!==p.opacity&&(a=!1),m==null||m>p.opacity?p.opacity:m),s?.opacity??null)??o.state.currentItemOpacity;return kP(()=>{if(n.current&&r.current){let m=n.current,p=r.current,d=m.offsetWidth,u=15,b=c/100*(d-u)+u/2;p.style.left=`${b}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]),Oy("label",{className:"control-label",children:[h("labels.opacity"),Oy("div",{className:"range-wrapper",children:[Eg("input",{style:{"--color-slider-track":a?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":t}),Eg("div",{className:"value-bubble",ref:r,children:c!==0?c:null}),Eg("div",{className:"zero-label",children:"0"})]})]})};import{Fragment as Pg,jsx as ae,jsxs as _t}from"react/jsx-runtime";var Ky=.1,ma=e=>{let o=jP(e.editorInterface);return{stylesPanelMode:o,isCompact:o!=="full",isMobile:o==="mobile"}},Dt=(e,o,t,n=!1)=>{let r=Ig(ne(e,o,{includeBoundTextElement:n}));return e.map(i=>r.get(i.id)||i.id===o.editingTextElement?.id?t(i):i)},It=function(e,o,t,n,r){let i=o.state.editingTextElement,a=Yy(e),s=null;if(i&&(s=t(i)),!s)if(Le(a,o.state)){let c=o.scene.getSelectedElements(o.state),m=n===!0?c:c.filter(p=>n(p));s=UP(m,t)??(typeof r=="function"?r(!0):r)}else s=typeof r=="function"?r(!1):r;return s},qP=(e,o,t)=>VP(o)||!o.autoResize?o:t.mutateElement(o,{x:e.textAlign==="left"?e.x:e.x+(e.width-o.width)/(e.textAlign==="center"?2:1),y:e.y+(e.height-o.height)/2}),Sg=(e,o,t,n,r)=>{let i=new Set,a=Dt(e,o,s=>{if(Ut(s)){let l=n(s);i.add(l);let c=lt(s,{fontSize:l});return qs(c,t.scene.getContainerElement(s),t.scene),c=qP(s,c,t.scene),c}return s},!0);return ne(e,o,{includeBoundTextElement:!0}).forEach(s=>{Ut(s)&&YP(s,t.scene)}),{elements:a,appState:{...o,currentItemFontSize:i.size===1?[...i][0]:r??o.currentItemFontSize},captureUpdate:ct.IMMEDIATELY}},JP=O({name:"changeStrokeColor",label:"labels.stroke",trackEvent:!1,perform:(e,o,t)=>({...t?.currentItemStrokeColor&&{elements:Dt(e,o,n=>XP(n.type)?lt(n,{strokeColor:t.currentItemStrokeColor}):n,!0)},appState:{...o,...t},captureUpdate:t?.currentItemStrokeColor?ct.IMMEDIATELY:ct.EVENTUALLY}),PanelComponent:({elements:e,appState:o,updateData:t,app:n,data:r})=>{let{stylesPanelMode:i}=ma(n);return _t(Pg,{children:[i==="full"&&ae("h3",{"aria-hidden":"true",children:h("labels.stroke")}),ae(Vs,{topPicks:RP,palette:_P,type:"elementStroke",label:h("labels.stroke"),color:It(e,n,a=>a.strokeColor,!0,a=>a?null:o.currentItemStrokeColor),onChange:a=>t({currentItemStrokeColor:a}),elements:e,appState:o,updateData:t})]})}}),QP=O({name:"changeBackgroundColor",label:"labels.changeBackground",trackEvent:!1,perform:(e,o,t,n)=>{if(!t?.currentItemBackgroundColor)return{appState:{...o,...t},captureUpdate:ct.EVENTUALLY};let r,i=n.scene.getSelectedElements(o);if(!GP(t.currentItemBackgroundColor)&&i.every(s=>Uy(s)&&WP(s.points))){let s=Ig(i);r=e.map(l=>s.has(l.id)&&Uy(l)?lt(l,{backgroundColor:t.currentItemBackgroundColor,...ZP(l,!0)}):l)}else r=Dt(e,o,s=>lt(s,{backgroundColor:t.currentItemBackgroundColor}));return{elements:r,appState:{...o,...t},captureUpdate:ct.IMMEDIATELY}},PanelComponent:({elements:e,appState:o,updateData:t,app:n,data:r})=>{let{stylesPanelMode:i}=ma(n);return _t(Pg,{children:[i==="full"&&ae("h3",{"aria-hidden":"true",children:h("labels.background")}),ae(Vs,{topPicks:DP,palette:AP,type:"elementBackground",label:h("labels.background"),color:It(e,n,a=>a.backgroundColor,!0,a=>a?null:o.currentItemBackgroundColor),onChange:a=>t({currentItemBackgroundColor:a}),elements:e,appState:o,updateData:t})]})}}),eL=O({name:"changeFillStyle",label:"labels.fill",trackEvent:!1,perform:(e,o,t,n)=>(me("element","changeFillStyle",`${t} (${n.editorInterface.formFactor==="phone"?"mobile":"desktop"})`),{elements:Dt(e,o,r=>lt(r,{fillStyle:t})),appState:{...o,currentItemFillStyle:t},captureUpdate:ct.IMMEDIATELY}),PanelComponent:({elements:e,appState:o,updateData:t,app:n})=>{let r=ne(e,o),i=r.length>0&&r.every(a=>a.fillStyle==="zigzag");return _t("fieldset",{children:[ae("legend",{children:h("labels.fill")}),ae("div",{className:"buttonList",children:ae(ao,{type:"button",options:[{value:"hachure",text:`${i?h("labels.zigzag"):h("labels.hachure")} (${N("Alt-Click")})`,icon:i?Cx:Sx,active:i?!0:void 0,testId:"fill-hachure"},{value:"cross-hatch",text:h("labels.crossHatch"),icon:kx,testId:"fill-cross-hatch"},{value:"solid",text:h("labels.solid"),icon:Mx,testId:"fill-solid"}],value:It(e,n,a=>a.fillStyle,a=>a.hasOwnProperty("fillStyle"),a=>a?null:o.currentItemFillStyle),onClick:(a,s)=>{let l=s.altKey&&a==="hachure"&&r.every(c=>c.fillStyle==="hachure")?"zigzag":a;t(l)}})})]})}}),tL=O({name:"changeStrokeWidth",label:"labels.strokeWidth",trackEvent:!1,perform:(e,o,t)=>({elements:Dt(e,o,n=>lt(n,{strokeWidth:t})),appState:{...o,currentItemStrokeWidth:t},captureUpdate:ct.IMMEDIATELY}),PanelComponent:({elements:e,appState:o,updateData:t,app:n,data:r})=>_t("fieldset",{children:[ae("legend",{children:h("labels.strokeWidth")}),ae("div",{className:"buttonList",children:ae(ao,{group:"stroke-width",options:[{value:vg.thin,text:h("labels.thin"),icon:Bu,testId:"strokeWidth-thin"},{value:vg.bold,text:h("labels.bold"),icon:Px,testId:"strokeWidth-bold"},{value:vg.extraBold,text:h("labels.extraBold"),icon:Lx,testId:"strokeWidth-extraBold"}],value:It(e,n,i=>i.strokeWidth,i=>i.hasOwnProperty("strokeWidth"),i=>i?null:o.currentItemStrokeWidth),onChange:i=>t(i)})})]})}),oL=O({name:"changeSloppiness",label:"labels.sloppiness",trackEvent:!1,perform:(e,o,t)=>({elements:Dt(e,o,n=>lt(n,{seed:OP(),roughness:t})),appState:{...o,currentItemRoughness:t},captureUpdate:ct.IMMEDIATELY}),PanelComponent:({elements:e,appState:o,updateData:t,app:n,data:r})=>_t("fieldset",{children:[ae("legend",{children:h("labels.sloppiness")}),ae("div",{className:"buttonList",children:ae(ao,{group:"sloppiness",options:[{value:0,text:h("labels.architect"),icon:_x},{value:1,text:h("labels.artist"),icon:Rx},{value:2,text:h("labels.cartoonist"),icon:Nx}],value:It(e,n,i=>i.roughness,i=>i.hasOwnProperty("roughness"),i=>i?null:o.currentItemRoughness),onChange:i=>t(i)})})]})}),bte=O({name:"changeStrokeStyle",label:"labels.strokeStyle",trackEvent:!1,perform:(e,o,t)=>({elements:Dt(e,o,n=>lt(n,{strokeStyle:t})),appState:{...o,currentItemStrokeStyle:t},captureUpdate:ct.IMMEDIATELY}),PanelComponent:({elements:e,appState:o,updateData:t,app:n,data:r})=>_t("fieldset",{children:[ae("legend",{children:h("labels.strokeStyle")}),ae("div",{className:"buttonList",children:ae(ao,{group:"strokeStyle",options:[{value:"solid",text:h("labels.strokeStyle_solid"),icon:Bu},{value:"dashed",text:h("labels.strokeStyle_dashed"),icon:Ax},{value:"dotted",text:h("labels.strokeStyle_dotted"),icon:Dx}],value:It(e,n,i=>i.strokeStyle,i=>i.hasOwnProperty("strokeStyle"),i=>i?null:o.currentItemStrokeStyle),onChange:i=>t(i)})})]})}),nL=O({name:"changeOpacity",label:"labels.opacity",trackEvent:!1,perform:(e,o,t)=>({elements:Dt(e,o,n=>lt(n,{opacity:t}),!0),appState:{...o,currentItemOpacity:t},captureUpdate:ct.IMMEDIATELY}),PanelComponent:({app:e,updateData:o})=>ae(zy,{updateData:o,app:e,testId:"opacity"})}),rL=O({name:"changeFontSize",label:"labels.fontSize",trackEvent:!1,perform:(e,o,t,n)=>Sg(e,o,n,()=>(Cg(t,"actionChangeFontSize: Expected a font size value"),t),t),PanelComponent:({elements:e,appState:o,updateData:t,app:n,data:r})=>{let{isCompact:i}=ma(n);return _t("fieldset",{children:[ae("legend",{children:h("labels.fontSize")}),ae("div",{className:"buttonList",children:ae(ao,{group:"font-size",options:[{value:ud.sm,text:h("labels.small"),icon:jx,testId:"fontSize-small"},{value:ud.md,text:h("labels.medium"),icon:qx,testId:"fontSize-medium"},{value:ud.lg,text:h("labels.large"),icon:Jx,testId:"fontSize-large"},{value:ud.xl,text:h("labels.veryLarge"),icon:Qx,testId:"fontSize-veryLarge"}],value:It(e,n,a=>{if(Ut(a))return a.fontSize;let s=rr(a,n.scene.getNonDeletedElementsMap());return s?s.fontSize:null},a=>Ut(a)||rr(a,n.scene.getNonDeletedElementsMap())!==null,a=>a?null:o.currentItemFontSize||BP),onChange:a=>{Gs(()=>t(a),i,!!o.editingTextElement,r?.onPreventClose)}})})]})}}),kg=O({name:"decreaseFontSize",label:"labels.decreaseFontSize",icon:jr,trackEvent:!1,perform:(e,o,t,n)=>Sg(e,o,n,r=>Math.round(1/(1+Ky)*r.fontSize)),keyTest:e=>e[da.CTRL_OR_CMD]&&e.shiftKey&&(e.key===da.CHEVRON_LEFT||e.key===da.COMMA)}),Mg=O({name:"increaseFontSize",label:"labels.increaseFontSize",icon:jr,trackEvent:!1,perform:(e,o,t,n)=>Sg(e,o,n,r=>Math.round(r.fontSize*(1+Ky))),keyTest:e=>e[da.CTRL_OR_CMD]&&e.shiftKey&&(e.key===da.CHEVRON_RIGHT||e.key===da.PERIOD)}),iL=O({name:"changeFontFamily",label:"labels.fontFamily",trackEvent:!1,perform:(e,o,t,n)=>{let{cachedElements:r,resetAll:i,resetContainers:a,...s}=t;if(i)return{elements:Dt(e,o,g=>{let E=r?.get(g.id);return E?lt(g,{...E}):g},!0),appState:{...o,...s},captureUpdate:ct.NEVER};Cg(t,"actionChangeFontFamily: value must be defined");let{currentItemFontFamily:l,currentHoveredFontFamily:c}=t,m=ct.EVENTUALLY,p,d=!1;if(l)p=l,m=ct.IMMEDIATELY;else if(c){p=c,m=ct.EVENTUALLY;let b=ne(e,o,{includeBoundTextElement:!0}).filter(g=>Ut(g));if(b.length>200)d=!0;else{let g=0,E=0;for(;g<b.length&&E<5e3;){let w=b[g];E+=w?.originalText.length||0,g++}E>5e3&&(d=!0)}}let u={appState:{...o,...s},captureUpdate:m};if(p&&!d){let b=new Map,g=new Set,E=!1,w=Array.from(Yn.loadedFontsCache.values()),x=Object.entries(FP).find(([T,C])=>C===p)?.[0];c&&x&&w.some(T=>T.startsWith(x))&&(E=!0),Object.assign(u,{elements:Dt(e,o,T=>{if(Ut(T)&&(T.fontFamily!==p||l)){let C=lt(T,{fontFamily:p,lineHeight:HP(p)}),M=r?.get(T.containerId||"")||{},S=n.scene.getContainerElement(T);return a&&S&&M&&n.scene.mutateElement(S,{...M}),E||(g=new Set([...g,...Array.from(C.originalText)])),b.set(C,S),C}return T},!0)});let y=`10px ${zP({fontFamily:p})}`,v=Array.from(g.values()).join();if(E||window.document.fonts.check(y,v))for(let[T,C]of b)qs(T,C,n.scene);else window.document.fonts.load(y,v).then(T=>{for(let[C,M]of b){let S=n.scene.getElement(C.id),D=M?n.scene.getElement(M.id):null;S&&qs(S,D,n.scene)}n.fonts.onLoaded(T)})}return u},PanelComponent:({elements:e,appState:o,app:t,updateData:n})=>{let r=wg(new Map),i=wg(null),[a,s]=LP({}),l=wg(!0),{stylesPanelMode:c,isCompact:m}=ma(t),p=PP(()=>{let d=(u,b)=>It(u,t,g=>{if(Ut(g))return g.fontFamily;let E=rr(g,b);return E?E.fontFamily:null},g=>Ut(g)||rr(g,b)!==null,g=>g?null:o.currentItemFontFamily||NP);return a.openPopup==="fontFamily"&&o.openPopup==="fontFamily"?d(Array.from(r.current?.values()??[]),r.current):!a.openPopup&&o.openPopup!=="fontFamily"?d(e,t.scene.getNonDeletedElementsMap()):i.current},[a.openPopup,o,e,t]);return yg(()=>{i.current=p},[p]),yg(()=>{Object.keys(a).length&&(n(a),s({}))},[a]),yg(()=>(l.current=!1,()=>{l.current=!0}),[]),_t(Pg,{children:[c==="full"&&ae("legend",{children:h("labels.fontFamily")}),ae(Ry,{isOpened:o.openPopup==="fontFamily",selectedFontFamily:p,hoveredFontFamily:o.currentHoveredFontFamily,compactMode:c!=="full",onSelect:d=>{Gs(()=>{s({openPopup:null,currentHoveredFontFamily:null,currentItemFontFamily:d}),r.current.clear()},m,!!o.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}=o;if(u?.type==="text"){let b=t.scene.getElement(u.id);r.current.set(u.id,lt(b||u,{},!0))}else{let b=ne(e,o,{includeBoundTextElement:!0});for(let g of b)r.current.set(g.id,lt(g,{},!0))}s({...a,openPopup:"fontFamily"})}else{let u={currentHoveredFontFamily:null,cachedElements:new Map(r.current),resetAll:!0};s({...u}),r.current.clear(),m&&o.editingTextElement&&Hs(null)}}})]})}}),aL=O({name:"changeTextAlign",label:"Change text alignment",trackEvent:!1,perform:(e,o,t,n)=>({elements:Dt(e,o,r=>{if(Ut(r)){let i=lt(r,{textAlign:t});return qs(i,n.scene.getContainerElement(r),n.scene),i}return r},!0),appState:{...o,currentItemTextAlign:t},captureUpdate:ct.IMMEDIATELY}),PanelComponent:({elements:e,appState:o,updateData:t,app:n,data:r})=>{let i=n.scene.getNonDeletedElementsMap(),{isCompact:a}=ma(n);return _t("fieldset",{children:[ae("legend",{children:h("labels.textAlign")}),ae("div",{className:"buttonList",children:ae(ao,{group:"text-align",options:[{value:"left",text:h("labels.left"),icon:tE,testId:"align-left"},{value:"center",text:h("labels.center"),icon:oE,testId:"align-horizontal-center"},{value:"right",text:h("labels.right"),icon:nE,testId:"align-right"}],value:It(e,n,s=>{if(Ut(s))return s.textAlign;let l=rr(s,i);return l?l.textAlign:null},s=>Ut(s)||rr(s,i)!==null,s=>s?null:o.currentItemTextAlign),onChange:s=>{Gs(()=>t(s),a,!!o.editingTextElement,r?.onPreventClose)}})})]})}}),sL=O({name:"changeVerticalAlign",label:"Change vertical alignment",trackEvent:{category:"element"},perform:(e,o,t,n)=>({elements:Dt(e,o,r=>{if(Ut(r)){let i=lt(r,{verticalAlign:t});return qs(i,n.scene.getContainerElement(r),n.scene),i}return r},!0),appState:{...o},captureUpdate:ct.IMMEDIATELY}),PanelComponent:({elements:e,appState:o,updateData:t,app:n,data:r})=>{let{isCompact:i}=ma(n);return ae("fieldset",{children:ae("div",{className:"buttonList",children:ae(ao,{group:"text-align",options:[{value:pd.TOP,text:h("labels.alignTop"),icon:ae(rE,{theme:o.theme}),testId:"align-top"},{value:pd.MIDDLE,text:h("labels.centerVertically"),icon:ae(aE,{theme:o.theme}),testId:"align-middle"},{value:pd.BOTTOM,text:h("labels.alignBottom"),icon:ae(iE,{theme:o.theme}),testId:"align-bottom"}],value:It(e,n,a=>{if(Ut(a)&&a.containerId)return a.verticalAlign;let s=rr(a,n.scene.getNonDeletedElementsMap());return s?s.verticalAlign:null},a=>Ut(a)||rr(a,n.scene.getNonDeletedElementsMap())!==null,a=>a?null:pd.MIDDLE),onChange:a=>{Gs(()=>t(a),i,!!o.editingTextElement,r?.onPreventClose)}})})})}}),xte=O({name:"changeRoundness",label:"Change edge roundness",trackEvent:!1,perform:(e,o,t)=>({elements:Dt(e,o,n=>Vy(n)?n:lt(n,{roundness:t==="round"?{type:KP(n.type)?gd.ADAPTIVE_RADIUS:gd.PROPORTIONAL_RADIUS}:null})),appState:{...o,currentItemRoundness:t},captureUpdate:ct.IMMEDIATELY}),PanelComponent:({elements:e,appState:o,updateData:t,app:n,renderAction:r})=>{let a=Ai(Yy(e),o).some(s=>s.roundness?.type===gd.LEGACY);return _t("fieldset",{children:[ae("legend",{children:h("labels.edges")}),_t("div",{className:"buttonList",children:[ae(ao,{group:"edges",options:[{value:"sharp",text:h("labels.sharp"),icon:Bx},{value:"round",text:h("labels.round"),icon:Fx}],value:It(e,n,s=>a?null:s.roundness?"round":"sharp",s=>!hd(s)&&s.hasOwnProperty("roundness"),s=>s?null:o.currentItemRoundness),onChange:s=>t(s)}),r("togglePolygon")]})]})}}),Wy=e=>[{value:null,text:h("labels.arrowhead_none"),keyBinding:"q",icon:ae(Ox,{flip:e})},{value:"arrow",text:h("labels.arrowhead_arrow"),keyBinding:"w",icon:ae(zx,{flip:e})},{value:"triangle",text:h("labels.arrowhead_triangle"),icon:ae(Wx,{flip:e}),keyBinding:"e"},{value:"triangle_outline",text:h("labels.arrowhead_triangle_outline"),icon:ae(Yx,{flip:e}),keyBinding:"r"},{value:"circle",text:h("labels.arrowhead_circle"),keyBinding:"a",icon:ae(Hx,{flip:e})},{value:"circle_outline",text:h("labels.arrowhead_circle_outline"),keyBinding:"s",icon:ae(Gx,{flip:e})},{value:"diamond",text:h("labels.arrowhead_diamond"),icon:ae(Vx,{flip:e}),keyBinding:"d"},{value:"diamond_outline",text:h("labels.arrowhead_diamond_outline"),icon:ae(Kx,{flip:e}),keyBinding:"f"},{value:"bar",text:h("labels.arrowhead_bar"),keyBinding:"z",icon:ae(Ux,{flip:e})},{value:"crowfoot_one",text:h("labels.arrowhead_crowfoot_one"),icon:ae($x,{flip:e}),keyBinding:"x"},{value:"crowfoot_many",text:h("labels.arrowhead_crowfoot_many"),icon:ae(Xx,{flip:e}),keyBinding:"c"},{value:"crowfoot_one_or_many",text:h("labels.arrowhead_crowfoot_one_or_many"),icon:ae(Zx,{flip:e}),keyBinding:"v"}],Ete=O({name:"changeArrowhead",label:"Change arrowheads",trackEvent:!1,perform:(e,o,t)=>(Cg(t,"actionChangeArrowhead: value must be defined"),{elements:Dt(e,o,n=>{if(Tg(n)){let{position:r,type:i}=t;if(r==="start")return lt(n,{startArrowhead:i});if(r==="end")return lt(n,{endArrowhead:i})}return n}),appState:{...o,[t.position==="start"?"currentItemStartArrowhead":"currentItemEndArrowhead"]:t.type},captureUpdate:ct.IMMEDIATELY}),PanelComponent:({elements:e,appState:o,updateData:t,app:n})=>{let r=vn().rtl;return _t("fieldset",{children:[ae("legend",{children:h("labels.arrowheads")}),_t("div",{className:"iconSelectList buttonList",children:[ae(xg,{label:"arrowhead_start",options:Wy(!r),value:It(e,n,i=>Tg(i)&&Di(i.type)?i.startArrowhead:o.currentItemStartArrowhead,!0,i=>i?null:o.currentItemStartArrowhead),onChange:i=>t({position:"start",type:i}),numberOfOptionsToAlwaysShow:4}),ae(xg,{label:"arrowhead_end",group:"arrowheads",options:Wy(!!r),value:It(e,n,i=>Tg(i)&&Di(i.type)?i.endArrowhead:o.currentItemEndArrowhead,!0,i=>i?null:o.currentItemEndArrowhead),onChange:i=>t({position:"end",type:i}),numberOfOptionsToAlwaysShow:4})]})]})}}),lL=O({name:"changeArrowProperties",label:"Change arrow properties",trackEvent:!1,perform:(e,o,t,n)=>!1,PanelComponent:({elements:e,appState:o,updateData:t,app:n,renderAction:r})=>_t("div",{className:"selected-shape-actions",children:[r("changeArrowhead"),r("changeArrowType")]})}),yte=O({name:"changeArrowType",label:"Change arrow types",trackEvent:!1,perform:(e,o,t,n)=>{let r=Dt(e,o,s=>{if(!hd(s))return s;let l=n.scene.getNonDeletedElementsMap(),c=ei.getPointAtIndexGlobalCoordinates(s,0,l),m=ei.getPointAtIndexGlobalCoordinates(s,-1,l),p=lt(s,{x:t===co.elbow?c[0]:s.x,y:t===co.elbow?c[1]:s.y,roundness:t===co.round?{type:gd.PROPORTIONAL_RADIUS}:null,elbowed:t===co.elbow,angle:t===co.elbow?0:s.angle,points:t===co.elbow||s.elbowed?[ei.pointFromAbsoluteCoords({...s,x:c[0],y:c[1],angle:0},c,l),ei.pointFromAbsoluteCoords({...s,x:c[0],y:c[1],angle:0},m,l)]:s.points});if(Vy(p)){p.fixedSegments=null;let d=n.scene.getNonDeletedElementsMap();n.dismissLinearEditor();let u=ei.getPointAtIndexGlobalCoordinates(p,0,d),b=ei.getPointAtIndexGlobalCoordinates(p,-1,d),g=p.startBinding&&d.get(p.startBinding.elementId),E=p.endBinding&&d.get(p.endBinding.elementId),w=g&&p.startBinding?{...p.startBinding,...Gy(p,g,"start",d)}:null,x=E&&p.endBinding?{...p.endBinding,...Gy(p,E,"end",d)}:null;p={...p,startBinding:w,endBinding:x,...$P(p,d,{points:[u,b].map(y=>MP(y[0]-p.x,y[1]-p.y)),startBinding:w,endBinding:x,fixedSegments:null})}}else{let d=n.scene.getNonDeletedElementsMap();if(p.startBinding){let u=d.get(p.startBinding.elementId);u&&Hy(p,u,o.bindMode==="inside"?"inside":"orbit","start",n.scene)}if(p.endBinding){let u=d.get(p.endBinding.elementId);u&&Hy(p,u,o.bindMode==="inside"?"inside":"orbit","end",n.scene)}}return p}),i={...o,currentItemArrowType:t},a=o.selectedLinearElement?.elementId;if(a){let s=r.find(l=>l.id===a);s&&(i.selectedLinearElement=new ei(s,Ig(e)))}return{elements:r,appState:i,captureUpdate:ct.IMMEDIATELY}},PanelComponent:({elements:e,appState:o,updateData:t,app:n})=>_t("fieldset",{children:[ae("legend",{children:h("labels.arrowtypes")}),ae("div",{className:"buttonList",children:ae(ao,{group:"arrowtypes",options:[{value:co.sharp,text:h("labels.arrowtype_sharp"),icon:Ji,testId:"sharp-arrow"},{value:co.round,text:h("labels.arrowtype_round"),icon:ea,testId:"round-arrow"},{value:co.elbow,text:h("labels.arrowtype_elbowed"),icon:Qi,testId:"elbow-arrow"}],value:It(e,n,r=>hd(r)?r.elbowed?co.elbow:r.roundness?co.round:co.sharp:null,r=>hd(r),r=>r?null:o.currentItemArrowType),onChange:r=>t(r)})})]})});import{clamp as Rg,roundToStep as hL}from"@orangecatai/math";import{DEFAULT_CANVAS_BACKGROUND_PICKS as fL,CURSOR_TYPE as qy,MAX_ZOOM as Jy,MIN_ZOOM as Qy,THEME as Js,ZOOM_STEP as Ng,updateActiveTool as ua,CODES as Qo,KEYS as kn}from"@orangecatai/common";import{getNonDeletedElements as bL}from"@orangecatai/element";import{newElementWith as xL}from"@orangecatai/element";import{getCommonBounds as EL}from"@orangecatai/element";import{CaptureUpdateAction as Mo}from"@orangecatai/element";import{useEffect as cL}from"react";import{jsx as mL}from"react/jsx-runtime";var pa=()=>{let e=document.querySelector(".excalidraw-tooltip");if(e)return e;let o=document.createElement("div");return document.body.appendChild(o),o.classList.add("excalidraw-tooltip"),o},Lg=(e,o,t="bottom")=>{let n=e.getBoundingClientRect(),r=window.innerWidth,i=window.innerHeight,a=5,s=o.left+o.width/2-n.width/2;s<0?s=a:s+n.width>=r&&(s=r-n.width-a);let l;t==="bottom"?(l=o.top+o.height+a,l+n.height>=i&&(l=o.top-n.height-a)):(l=o.top-n.height-a,l<0&&(l=o.top+o.height+a)),Object.assign(e.style,{top:`${l}px`,left:`${s}px`})},dL=(e,o,t,n)=>{o.classList.add("excalidraw-tooltip--visible"),o.style.minWidth=n?"50ch":"10ch",o.style.maxWidth=n?"50ch":"15ch",o.textContent=t;let r=e.getBoundingClientRect();Lg(o,r)},qt=({children:e,label:o,long:t=!1,style:n,disabled:r})=>(cL(()=>()=>pa().classList.remove("excalidraw-tooltip--visible"),[]),r?null:mL("div",{className:"excalidraw-tooltip-wrapper",onPointerEnter:i=>dL(i.currentTarget,pa(),o,t),onPointerLeave:()=>pa().classList.remove("excalidraw-tooltip--visible"),style:n,children:e}));import{CURSOR_TYPE as Ag,MIME_TYPES as Dg,THEME as $y}from"@orangecatai/common";var Zy='<svg viewBox="0 0 24 24" stroke-width="1" width="28" height="28" xmlns="http://www.w3.org/2000/svg">',pL='<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"/>',jy='<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"/>',uL=`data:${Dg.svg},${encodeURIComponent(`${Zy}${jy}</svg>`)}`,gL=`data:${Dg.svg},${encodeURIComponent(`${Zy}${pL}${jy}</svg>`)}`,Jt=e=>{e&&(e.style.cursor="")},Se=(e,o)=>{e&&(e.style.cursor=o)},Jo,Xy,_g=(e,o)=>{let n=()=>{let r=o===$y.DARK;Jo=document.createElement("canvas"),Jo.theme=o,Jo.height=20,Jo.width=20;let i=Jo.getContext("2d");i.lineWidth=1,i.beginPath(),i.arc(Jo.width/2,Jo.height/2,5,0,2*Math.PI),i.fillStyle=r?"#000":"#fff",i.fill(),i.strokeStyle=r?"#fff":"#000",i.stroke(),Xy=Jo.toDataURL(Dg.svg)};(!Jo||Jo.theme!==o)&&n(),Se(e,`url(${Xy}) ${20/2} ${20/2}, auto`)},Qt=(e,o)=>{if(e)if(o.activeTool.type==="selection")Jt(e);else if(wn(o))e.style.cursor=Ag.GRAB;else if(Gt(o))_g(e,o.theme);else if(o.activeTool.type==="laser"){let t=o.theme===$y.LIGHT?uL:gL;e.style.cursor=`url(${t}), auto`}else["image","custom"].includes(o.activeTool.type)?o.activeTool.type!=="image"&&(e.style.cursor=Ag.AUTO):e.style.cursor=Ag.CROSSHAIR};var Sn=({viewportX:e,viewportY:o,nextZoom:t},n)=>{let r=e-n.offsetLeft,i=o-n.offsetTop,a=n.zoom.value,s=n.scrollX+(r-r/a),l=n.scrollY+(i-i/a),c=-(r-r/t),m=-(i-i/t);return{scrollX:s+c,scrollY:l+m,zoom:{value:t}}};import{jsx as Ed,jsxs as TL}from"react/jsx-runtime";var yL=O({name:"changeViewBackgroundColor",label:"labels.canvasBackground",trackEvent:!1,predicate:(e,o,t,n)=>!!n.props.UIOptions.canvasActions.changeViewBackgroundColor&&!o.viewModeEnabled,perform:(e,o,t)=>({appState:{...o,...t},captureUpdate:t?.viewBackgroundColor?Mo.IMMEDIATELY:Mo.EVENTUALLY}),PanelComponent:({elements:e,appState:o,updateData:t,appProps:n,data:r})=>Ed(Vs,{palette:null,topPicks:fL,label:h("labels.canvasBackground"),type:"canvasBackground",color:o.viewBackgroundColor,onChange:i=>t({viewBackgroundColor:i}),"data-testid":"canvas-background-picker",elements:e,appState:o,updateData:t})}),Mn=O({name:"clearCanvas",label:"labels.clearCanvas",icon:yt,trackEvent:{category:"canvas"},predicate:(e,o,t,n)=>!!n.props.UIOptions.canvasActions.clearCanvas&&!o.viewModeEnabled&&o.openDialog?.name!=="elementLinkSelector",perform:(e,o,t,n)=>(n.imageCache.clear(),{elements:e.map(r=>xL(r,{isDeleted:!0})),appState:{...Vn(),files:{},theme:o.theme,penMode:o.penMode,penDetected:o.penDetected,exportBackground:o.exportBackground,exportEmbedScene:o.exportEmbedScene,gridSize:o.gridSize,gridStep:o.gridStep,gridModeEnabled:o.gridModeEnabled,stats:o.stats,pasteDialog:o.pasteDialog,activeTool:o.activeTool.type==="image"?{...o.activeTool,type:n.state.preferredSelectionTool.type}:o.activeTool},captureUpdate:Mo.IMMEDIATELY})}),fd=O({name:"zoomIn",label:"buttons.zoomIn",viewMode:!0,icon:Eu,trackEvent:{category:"canvas"},perform:(e,o,t,n)=>({appState:{...o,...Sn({viewportX:o.width/2+o.offsetLeft,viewportY:o.height/2+o.offsetTop,nextZoom:Go(o.zoom.value+Ng)},o),userToFollow:null},captureUpdate:Mo.EVENTUALLY}),PanelComponent:({updateData:e,appState:o})=>Ed(Q,{type:"button",className:"zoom-in-button zoom-button",icon:Eu,title:`${h("buttons.zoomIn")} \u2014 ${N("CtrlOrCmd++")}`,"aria-label":h("buttons.zoomIn"),disabled:o.zoom.value>=Jy,onClick:()=>{e(null)}}),keyTest:e=>(e.code===Qo.EQUAL||e.code===Qo.NUM_ADD)&&(e[kn.CTRL_OR_CMD]||e.shiftKey)}),bd=O({name:"zoomOut",label:"buttons.zoomOut",icon:yu,viewMode:!0,trackEvent:{category:"canvas"},perform:(e,o,t,n)=>({appState:{...o,...Sn({viewportX:o.width/2+o.offsetLeft,viewportY:o.height/2+o.offsetTop,nextZoom:Go(o.zoom.value-Ng)},o),userToFollow:null},captureUpdate:Mo.EVENTUALLY}),PanelComponent:({updateData:e,appState:o})=>Ed(Q,{type:"button",className:"zoom-out-button zoom-button",icon:yu,title:`${h("buttons.zoomOut")} \u2014 ${N("CtrlOrCmd+-")}`,"aria-label":h("buttons.zoomOut"),disabled:o.zoom.value<=Qy,onClick:()=>{e(null)}}),keyTest:e=>(e.code===Qo.MINUS||e.code===Qo.NUM_SUBTRACT)&&(e[kn.CTRL_OR_CMD]||e.shiftKey)}),xd=O({name:"resetZoom",label:"buttons.resetZoom",icon:lx,viewMode:!0,trackEvent:{category:"canvas"},perform:(e,o,t,n)=>({appState:{...o,...Sn({viewportX:o.width/2+o.offsetLeft,viewportY:o.height/2+o.offsetTop,nextZoom:Go(1)},o),userToFollow:null},captureUpdate:Mo.EVENTUALLY}),PanelComponent:({updateData:e,appState:o})=>Ed(qt,{label:h("buttons.resetZoom"),style:{height:"100%"},children:TL(Q,{type:"button",className:"reset-zoom-button zoom-button",title:h("buttons.resetZoom"),"aria-label":h("buttons.resetZoom"),onClick:()=>{e(null)},children:[(o.zoom.value*100).toFixed(0),"%"]})}),keyTest:e=>(e.code===Qo.ZERO||e.code===Qo.NUM_ZERO)&&(e[kn.CTRL_OR_CMD]||e.shiftKey)}),wL=(e,o,t=1)=>{let[n,r,i,a]=e,s=i-n,l=o.width/s,c=a-r,m=o.height/c,d=Math.min(l,m)*Rg(t,.1,1);return Math.min(d,1)},ew=({bounds:e,appState:o,canvasOffsets:t,fitToViewport:n=!1,viewportZoomFactor:r=1,minZoom:i=-1/0,maxZoom:a=1/0})=>{r=Rg(r,Qy,Jy);let[s,l,c,m]=e,p=(s+c)/2,d=(l+m)/2,u=t?.left??0,b=t?.top??0,g=t?.right??0,E=t?.bottom??0,w=o.width-u-g,x=o.height-b-E,y;if(n){let C=c-s,M=m-l;y=Math.min(w/C,x/M)*r}else y=wL(e,{width:w,height:x},r);let v=Go(Rg(hL(y,Ng,"floor"),i,a)),T=Sb({scenePoint:{x:p,y:d},viewportDimensions:{width:o.width,height:o.height},offsets:t,zoom:{value:v}});return{appState:{...o,scrollX:T.scrollX,scrollY:T.scrollY,zoom:{value:v}},captureUpdate:Mo.EVENTUALLY}},Qs=({canvasOffsets:e,targetElements:o,appState:t,fitToViewport:n,viewportZoomFactor:r,minZoom:i,maxZoom:a})=>{let s=EL(bL(o));return ew({canvasOffsets:e,bounds:s,appState:t,fitToViewport:n,viewportZoomFactor:r,minZoom:i,maxZoom:a})},ooe=O({name:"zoomToFitSelectionInViewport",label:"labels.zoomToFitViewport",icon:Uc,trackEvent:{category:"canvas"},perform:(e,o,t,n)=>{let r=n.scene.getSelectedElements(o);return Qs({targetElements:r.length?r:e,appState:{...o,userToFollow:null},fitToViewport:!1,canvasOffsets:n.getEditorUIOffsets()})},keyTest:e=>e.code===Qo.TWO&&e.shiftKey&&!e.altKey&&!e[kn.CTRL_OR_CMD]}),noe=O({name:"zoomToFitSelection",label:"helpDialog.zoomToSelection",icon:Uc,trackEvent:{category:"canvas"},perform:(e,o,t,n)=>{let r=n.scene.getSelectedElements(o);return Qs({targetElements:r.length?r:e,appState:{...o,userToFollow:null},fitToViewport:!0,canvasOffsets:n.getEditorUIOffsets()})},keyTest:e=>e.code===Qo.THREE&&e.shiftKey&&!e.altKey&&!e[kn.CTRL_OR_CMD]}),vL=O({name:"zoomToFit",label:"helpDialog.zoomToFit",icon:Uc,viewMode:!0,trackEvent:{category:"canvas"},perform:(e,o,t,n)=>Qs({targetElements:e,appState:{...o,userToFollow:null},fitToViewport:!1,canvasOffsets:n.getEditorUIOffsets()}),keyTest:e=>e.code===Qo.ONE&&e.shiftKey&&!e.altKey&&!e[kn.CTRL_OR_CMD]}),ti=O({name:"toggleTheme",label:(e,o)=>o.theme===Js.DARK?"buttons.lightMode":"buttons.darkMode",keywords:["toggle","dark","light","mode","theme"],icon:(e,o)=>e.theme===Js.LIGHT?As:Ds,viewMode:!0,trackEvent:{category:"canvas"},perform:(e,o,t)=>({appState:{...o,theme:t||(o.theme===Js.LIGHT?Js.DARK:Js.LIGHT)},captureUpdate:Mo.EVENTUALLY}),keyTest:e=>e.altKey&&e.shiftKey&&e.code===Qo.D,predicate:(e,o,t,n)=>!!n.props.UIOptions.canvasActions.toggleTheme}),roe=O({name:"toggleEraserTool",label:"toolBar.eraser",trackEvent:{category:"toolbar"},perform:(e,o,t,n)=>{let r;return Gt(o)?r=ua(o,{...o.activeTool.lastActiveTool||{type:n.state.preferredSelectionTool.type},lastActiveToolBeforeEraser:null}):r=ua(o,{type:"eraser",lastActiveToolBeforeEraser:o.activeTool}),{appState:{...o,selectedElementIds:{},selectedGroupIds:{},activeEmbeddable:null,activeTool:r},captureUpdate:Mo.IMMEDIATELY}},keyTest:e=>e.key===kn.E}),ioe=O({name:"toggleLassoTool",label:"toolBar.lasso",icon:Kn,trackEvent:{category:"toolbar"},predicate:(e,o,t,n)=>n.state.preferredSelectionTool.type!=="lasso",perform:(e,o,t,n)=>{let r;return o.activeTool.type!=="lasso"?(r=ua(o,{type:"lasso",fromSelection:!1}),Se(n.interactiveCanvas,qy.CROSSHAIR)):r=ua(o,{type:"selection"}),{appState:{...o,selectedElementIds:{},selectedGroupIds:{},activeEmbeddable:null,activeTool:r},captureUpdate:Mo.NEVER}}}),tw=O({name:"toggleHandTool",label:"toolBar.hand",trackEvent:{category:"toolbar"},icon:$i,viewMode:!1,perform:(e,o,t,n)=>{let r;return wn(o)?r=ua(o,{...o.activeTool.lastActiveTool||{type:"selection"},lastActiveToolBeforeEraser:null}):(r=ua(o,{type:"hand",lastActiveToolBeforeEraser:o.activeTool}),Se(n.interactiveCanvas,qy.GRAB)),{appState:{...o,selectedElementIds:{},selectedGroupIds:{},activeEmbeddable:null,activeTool:r},captureUpdate:Mo.IMMEDIATELY}},keyTest:e=>!e.altKey&&!e[kn.CTRL_OR_CMD]&&e.key===kn.H});import{updateActiveTool as ow}from"@orangecatai/common";import{CaptureUpdateAction as IL}from"@orangecatai/element";var CL=O({name:"setEmbeddableAsActiveTool",trackEvent:{category:"toolbar"},target:"Tool",label:"toolBar.embeddable",perform:(e,o,t,n)=>{let r=ow(o,{type:"embeddable"});return Qt(n.canvas,{...o,activeTool:r}),{elements:e,appState:{...o,activeTool:ow(o,{type:"embeddable"})},captureUpdate:IL.EVENTUALLY}}});import{pointFrom as nw}from"@orangecatai/math";import{bindOrUnbindBindingElement as SL}from"@orangecatai/element/binding";import{isValidPolygon as rw,LinearElementEditor as yd,newElementWith as Bg}from"@orangecatai/element";import{isBindingElement as iw,isFreeDrawElement as aw,isLinearElement as sw,isLineElement as wd}from"@orangecatai/element";import{KEYS as Fg,arrayToMap as kL,invariant as lw,shouldRotateWithDiscreteAngle as ML,updateActiveTool as cw}from"@orangecatai/common";import{isPathALoop as PL}from"@orangecatai/element";import{isInvisiblySmallElement as Og}from"@orangecatai/element";import{CaptureUpdateAction as dw}from"@orangecatai/element";import{jsx as LL}from"react/jsx-runtime";var Rt=O({name:"finalize",label:"",trackEvent:!1,perform:(e,o,t,n)=>{let r=e,{interactiveCanvas:i,focusContainer:a,scene:s}=n,l=s.getNonDeletedElementsMap();if(t&&o.selectedLinearElement){let{event:d,sceneCoords:u}=t,b=yd.getElement(o.selectedLinearElement.elementId,l);lw(b,"Arrow element should exist if selectedLinearElement is set"),lw(u,"sceneCoords should be defined if actionFinalize is called with event");let g=yd.handlePointerUp(d,o.selectedLinearElement,o,n.scene);if(iw(b)&&!o.selectedLinearElement.segmentMidPointHoveredCoords){let E=!!o.newElement,x=(E||!o.selectedLinearElement.selectedPointsIndices?[b.points.length-1]:o.selectedLinearElement.selectedPointsIndices).reduce((y,v)=>(y.set(v,{point:yd.pointFromAbsoluteCoords(b,nw(u.x-g.pointerOffset.x,u.y-g.pointerOffset.y),l)}),y),new Map)??new Map;SL(b,x,u.x-g.pointerOffset.x,u.y-g.pointerOffset.y,s,o,{newArrow:E,altKey:d.altKey,angleLocked:ML(d)})}else wd(b)&&o.selectedLinearElement?.isEditing&&!o.newElement&&!rw(b.points)&&s.mutateElement(b,{polygon:!1});if(g!==o.selectedLinearElement){b&&Og(b)&&(r=r.map(w=>w.id===b.id?Bg(w,{isDeleted:!0}):w));let E=o.activeTool?.locked;return{elements:b.points.length<2||Og(b)?e.map(w=>w.id===b.id?Bg(w,{isDeleted:!0}):w):r,appState:{...o,cursorButton:"up",selectedLinearElement:E?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:dw.IMMEDIATELY}}}window.document.activeElement instanceof HTMLElement&&a();let c=null;if(o.multiElement)c=o.multiElement;else if(o.newElement?.type==="freedraw"||iw(o.newElement))c=o.newElement;else if(Object.keys(o.selectedElementIds).length===1){let d=l.get(Object.keys(o.selectedElementIds)[0]);d&&(c=d)}if(c){if(o.selectedLinearElement&&o.multiElement&&c.type!=="freedraw"&&o.lastPointerDownWith!=="touch"){let{points:d}=c,{lastCommittedPoint:u}=o.selectedLinearElement;(!u||d[d.length-1]!==u)&&s.mutateElement(c,{points:c.points.slice(0,-1)})}if(c&&Og(c)&&(r=r.map(d=>d.id===c?.id?Bg(d,{isDeleted:!0}):d)),sw(c)||aw(c)){if(PL(c.points,o.zoom.value)&&(wd(c)||aw(c))){let u=c.points,b=u[0],g=u.map((E,w)=>w===u.length-1?nw(b[0],b[1]):E);wd(c)?s.mutateElement(c,{points:g,polygon:!0}):s.mutateElement(c,{points:g})}wd(c)&&!rw(c.points)&&s.mutateElement(c,{polygon:!1})}}(!o.activeTool.locked&&o.activeTool.type!=="freedraw"||!c)&&Jt(i);let m;o.activeTool.type==="eraser"?m=cw(o,{...o.activeTool.lastActiveTool||{type:n.state.preferredSelectionTool.type},lastActiveToolBeforeEraser:null}):m=cw(o,{type:n.state.preferredSelectionTool.type});let p=c&&sw(c)?new yd(c,kL(r)):o.selectedLinearElement;return p=p&&{...p,isEditing:o.newElement?!1:p.isEditing,initialState:{...p.initialState,lastClickedPoint:-1,origin:null}},{elements:r,appState:{...o,cursorButton:"up",activeTool:(o.activeTool.locked||o.activeTool.type==="freedraw")&&c?o.activeTool:m,activeEmbeddable:null,newElement:null,selectionElement:null,multiElement:null,editingTextElement:null,startBoundElement:null,suggestedBinding:null,selectedElementIds:c&&!o.activeTool.locked&&o.activeTool.type!=="freedraw"?{...o.selectedElementIds,[c.id]:!0}:o.selectedElementIds,selectedLinearElement:p},captureUpdate:dw.IMMEDIATELY}},keyTest:(e,o)=>e.key===Fg.ESCAPE&&(o.selectedLinearElement?.isEditing||!o.newElement&&o.multiElement===null)||(e.key===Fg.ESCAPE||e.key===Fg.ENTER)&&o.multiElement!==null,PanelComponent:({appState:e,updateData:o,data:t})=>LL(Q,{type:"button",icon:bx,title:h("buttons.done"),"aria-label":h("buttons.done"),onClick:o,visible:e.multiElement!=null,size:t?.size||"medium",style:{pointerEvents:"all"}})});import{KEYS as ba,DEFAULT_EXPORT_PADDING as yA,EXPORT_SCALES as wA,THEME as Gg}from"@orangecatai/common";import{getNonDeletedElements as vA}from"@orangecatai/element";import{CaptureUpdateAction as Ao}from"@orangecatai/element";import AL from"clsx";import{jsx as mw,jsxs as DL}from"react/jsx-runtime";var el=({children:e,checked:o,onChange:t,className:n})=>DL("div",{className:AL("Checkbox",n,{"is-checked":o}),onClick:r=>{t(!o,r),r.currentTarget.querySelector(".Checkbox-box").focus()},children:[mw("button",{type:"button",className:"Checkbox-box",role:"checkbox","aria-checked":o,children:Nc}),mw("div",{className:"Checkbox-label",children:e})]});import{THEME as tl}from"@orangecatai/common";import{jsx as ol}from"react/jsx-runtime";var uw=e=>{let o=e.title||(e.value===tl.DARK?h("buttons.lightMode"):h("buttons.darkMode"));return ol(Q,{type:"icon",icon:e.value===tl.LIGHT?pw.MOON:pw.SUN,title:o,"aria-label":o,onClick:()=>e.onChange(e.value===tl.DARK?tl.LIGHT:tl.DARK),"data-testid":"toggle-dark-mode"})},pw={SUN:ol("svg",{width:"512",height:"512",className:"rtl-mirror",viewBox:"0 0 512 512",children:ol("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:ol("svg",{width:"512",height:"512",className:"rtl-mirror",viewBox:"0 0 512 512",children:ol("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 _L}from"react";import{focusNearestParent as RL,KEYS as NL}from"@orangecatai/common";import{jsx as gw,jsxs as BL}from"react/jsx-runtime";var hw=e=>{let{id:o}=Oe(),[t,n]=_L(e.value),r=a=>{e.ignoreFocus||RL(a.target);let s=a.target.value;s!==e.value&&e.onChange(s)},i=a=>{if(a.key===NL.ENTER){if(a.preventDefault(),a.nativeEvent.isComposing||a.keyCode===229)return;a.currentTarget.blur()}};return BL("div",{className:"ProjectName",children:[gw("label",{className:"ProjectName-label",htmlFor:"filename",children:`${e.label}:`}),gw("input",{type:"text",className:"TextInput",onBlur:r,onKeyDown:i,id:`${o}-filename`,value:t,onChange:a=>n(a.target.value)})]})};import{DEFAULT_EXPORT_PADDING as mA,DEFAULT_FILENAME as pA,IMAGE_MIME_TYPES as Dw,isFirefox as uA,MIME_TYPES as gA,cloneJSON as hA,SVG_DOCUMENT_PREAMBLE as fA}from"@orangecatai/common";import{getNonDeletedElements as bA}from"@orangecatai/element";import{isFrameLikeElement as xA}from"@orangecatai/element";import{getElementsOverlappingFrame as EA}from"@orangecatai/element";import{ALLOWED_PASTE_MIME_TYPES as $L,EXPORT_DATA_TYPES as il,MIME_TYPES as eo,arrayToMap as ZL,isMemberOf as jL,isPromiseLike as qL,EVENT as Id}from"@orangecatai/common";import{mutateElement as JL}from"@orangecatai/element";import{deepCopyElement as QL}from"@orangecatai/element";import{isFrameLikeElement as eA,isInitializedImageElement as tA}from"@orangecatai/element";import{getContainingFrame as Sw}from"@orangecatai/element";import{pointFrom as ir}from"@orangecatai/math";import{COLOR_PALETTE as bw,DEFAULT_CHART_COLOR_INDEX as FL,getAllColorsSpecificShade as OL,DEFAULT_FONT_FAMILY as zL,DEFAULT_FONT_SIZE as xw,VERTICAL_ALIGN as HL,randomId as Ew,isDevEnv as yw,FONT_SIZES as GL}from"@orangecatai/common";import{newTextElement as vd,newLinearElement as rl,newElement as Hg}from"@orangecatai/element";var Po=32,Ne=12,ar=256,ww=50,oi="NOT_SPREADSHEET",ga="VALID_SPREADSHEET",nl=e=>{let o=/^([-+]?)[$€£¥₩]?([-+]?)([\d.,]+)[%]?$/.exec(e);return o?parseFloat(`${(o[1]||o[2])+o[3]}`.replace(/,/g,"")):null},zg=(e,o)=>e.slice(1).every(t=>nl(t[o])!==null),fw=e=>{let o=e[0].length;if(o>2)return{type:oi,reason:"More than 2 columns"};if(o===1){if(!zg(e,0))return{type:oi,reason:"Value is not numeric"};let l=nl(e[0][0])===null,c=(l?e.slice(1):e).map(m=>nl(m[0]));return c.length<2?{type:oi,reason:"Less than two rows"}:{type:ga,spreadsheet:{title:l?e[0][0]:null,labels:null,values:c}}}let t=zg(e,0),n=zg(e,1);if(!t&&!n)return{type:oi,reason:"Value is not numeric"};let[r,i]=n?[0,1]:[1,0],a=nl(e[0][i])===null,s=a?e.slice(1):e;return s.length<2?{type:oi,reason:"Less than 2 rows"}:{type:ga,spreadsheet:{title:a?e[0][i]:null,labels:s.map(l=>l[r]),values:s.map(l=>nl(l[i]))}}},UL=e=>{let o=[];for(let t=0;t<e[0].length;t++){let n=[];for(let r=0;r<e.length;r++)n.push(e[r][t]);o.push(n)}return o},vw=e=>{let o=e.trim().split(`
|
|
2
|
-
`).map(i=>i.trim().split(" "));if(
|
|
3
|
-
`).map(i=>i.trim().split(","))),
|
|
4
|
-
`).trim()}:n:{type:"text",value:(e.getData(
|
|
5
|
-
|
|
6
|
-
${h("hints.firefox_clipboard_write")}`):new Error(h("alerts.couldNotCopyToClipboard"))}else throw new Error("Unsupported export type")};var _w=async(e,o,t,n)=>{let{exportBackground:r,viewBackgroundColor:i,fileHandle:a}=o,s=Fb(a);if(!a||!Ob(s))throw new Error("fileHandle should exist and should be of type svg or png when resaving");o={...o,exportEmbedScene:!0};let{exportedElements:l,exportingFrame:c}=ni(e,o,!1);return await ri(s,l,o,t,{exportBackground:r,viewBackgroundColor:i,name:n,fileHandle:a,exportingFrame:c}),{fileHandle:a}};import{Fragment as TA,jsx as Pn,jsxs as IA}from"react/jsx-runtime";var Ug=O({name:"changeProjectName",label:"labels.fileTitle",trackEvent:!1,perform:(e,o,t)=>({appState:{...o,name:t},captureUpdate:Ao.EVENTUALLY}),PanelComponent:({appState:e,updateData:o,appProps:t,data:n,app:r})=>Pn(hw,{label:h("labels.fileTitle"),value:r.getName(),onChange:i=>o(i),ignoreFocus:n?.ignoreFocus??!1})}),Rw=O({name:"changeExportScale",label:"imageExportDialog.scale",trackEvent:{category:"export",action:"scale"},perform:(e,o,t)=>({appState:{...o,exportScale:t},captureUpdate:Ao.EVENTUALLY}),PanelComponent:({elements:e,appState:o,updateData:t})=>{let n=vA(e),i=Le(n,o)?ne(n,o):n;return Pn(TA,{children:wA.map(a=>{let[s,l]=Nb(i,yA,a),c=`${h("imageExportDialog.label.scale")} ${a}x (${s}x${l})`;return Pn(Q,{size:"small",type:"radio",icon:`${a}x`,name:"export-canvas-scale",title:c,"aria-label":c,id:"export-canvas-scale",checked:a===o.exportScale,onChange:()=>t(a)},a)})})}}),Wg=O({name:"changeExportBackground",label:"imageExportDialog.label.withBackground",trackEvent:{category:"export",action:"toggleBackground"},perform:(e,o,t)=>({appState:{...o,exportBackground:t},captureUpdate:Ao.EVENTUALLY}),PanelComponent:({appState:e,updateData:o})=>Pn(el,{checked:e.exportBackground,onChange:t=>o(t),children:h("imageExportDialog.label.withBackground")})}),Pd=O({name:"changeExportEmbedScene",label:"imageExportDialog.tooltip.embedScene",trackEvent:{category:"export",action:"embedScene"},perform:(e,o,t)=>({appState:{...o,exportEmbedScene:t},captureUpdate:Ao.EVENTUALLY}),PanelComponent:({appState:e,updateData:o})=>IA(el,{checked:e.exportEmbedScene,onChange:t=>o(t),children:[h("imageExportDialog.label.embedScene"),Pn(qt,{label:h("imageExportDialog.tooltip.embedScene"),long:!0,children:Pn("div",{className:"excalidraw-tooltip-icon",children:xx})})]})}),ii=O({name:"saveToActiveFile",label:"buttons.save",icon:Zr,trackEvent:{category:"export"},predicate:(e,o,t,n)=>!!n.props.UIOptions.canvasActions.saveToActiveFile&&!!o.fileHandle&&!o.viewModeEnabled,perform:async(e,o,t,n)=>{let r=!!o.fileHandle;try{let{fileHandle:i}=Cc(o.fileHandle)?await _w(e,o,n.files,n.getName()):await yc(e,o,n.files,n.getName());return{captureUpdate:Ao.EVENTUALLY,appState:{...o,fileHandle:i,toast:r?{message:i?.name?h("toast.fileSavedToFilename").replace("{filename}",`"${i.name}"`):h("toast.fileSaved")}:null}}}catch(i){return i?.name!=="AbortError"?console.error(i):console.warn(i),{captureUpdate:Ao.EVENTUALLY}}},keyTest:e=>e.key===ba.S&&e[ba.CTRL_OR_CMD]&&!e.shiftKey}),al=O({name:"saveFileToDisk",label:"exportDialog.disk_title",icon:Zr,viewMode:!0,trackEvent:{category:"export"},perform:async(e,o,t,n)=>{try{let{fileHandle:r}=await yc(e,{...o,fileHandle:null},n.files,n.getName());return{captureUpdate:Ao.EVENTUALLY,appState:{...o,openDialog:null,fileHandle:r,toast:{message:h("toast.fileSaved")}}}}catch(r){return r?.name!=="AbortError"?console.error(r):console.warn(r),{captureUpdate:Ao.EVENTUALLY}}},keyTest:e=>e.key===ba.S&&e.shiftKey&&e[ba.CTRL_OR_CMD],PanelComponent:({updateData:e})=>Pn(Q,{type:"button",icon:gx,title:h("buttons.saveAs"),"aria-label":h("buttons.saveAs"),showAriaLabel:fe().formFactor==="phone",hidden:!Ri,onClick:()=>e(null),"data-testid":"save-as-button"})}),xa=O({name:"loadScene",label:"buttons.load",trackEvent:{category:"export"},predicate:(e,o,t,n)=>!!n.props.UIOptions.canvasActions.loadScene&&!o.viewModeEnabled,perform:async(e,o,t,n)=>{try{let{elements:r,appState:i,files:a}=await mu(o,e);return{elements:r,appState:i,files:a,captureUpdate:Ao.IMMEDIATELY}}catch(r){return r?.name==="AbortError"?(console.warn(r),!1):{elements:e,appState:{...o,errorMessage:r.message},files:n.files,captureUpdate:Ao.EVENTUALLY}}},keyTest:e=>e[ba.CTRL_OR_CMD]&&e.key===ba.O}),Nw=O({name:"exportWithDarkMode",label:"imageExportDialog.label.darkMode",trackEvent:{category:"export",action:"toggleTheme"},perform:(e,o,t)=>({appState:{...o,exportWithDarkMode:t},captureUpdate:Ao.EVENTUALLY}),PanelComponent:({appState:e,updateData:o})=>Pn("div",{style:{display:"flex",justifyContent:"flex-end",marginTop:"-45px",marginBottom:"10px"},children:Pn(uw,{value:e.exportWithDarkMode?Gg.DARK:Gg.LIGHT,onChange:t=>{o(t===Gg.DARK)},title:h("imageExportDialog.label.darkMode")})})});import{DEFAULT_FONT_SIZE as CA,DEFAULT_FONT_FAMILY as SA,DEFAULT_TEXT_ALIGN as kA,CODES as Bw,KEYS as Fw,getLineHeight as MA}from"@orangecatai/common";import{newElementWith as Ld}from"@orangecatai/element";import{hasBoundTextElement as PA,canApplyRoundnessTypeToElement as LA,getDefaultRoundnessTypeForElement as AA,isFrameLikeElement as DA,isArrowElement as _A,isExcalidrawElement as RA,isTextElement as Yg}from"@orangecatai/element";import{getBoundTextElement as NA,redrawTextBoundingBox as BA}from"@orangecatai/element";import{CaptureUpdateAction as Vg}from"@orangecatai/element";var Ow="{}",Kg=O({name:"copyStyles",label:"labels.copyStyles",icon:zu,trackEvent:{category:"element"},perform:(e,o,t,n)=>{let r=[],i=e.find(a=>o.selectedElementIds[a.id]);if(r.push(i),i&&PA(i)){let a=NA(i,n.scene.getNonDeletedElementsMap());r.push(a)}return i&&(Ow=JSON.stringify(r)),{appState:{...o,toast:{message:h("toast.copyStyles")}},captureUpdate:Vg.EVENTUALLY}},keyTest:e=>e[Fw.CTRL_OR_CMD]&&e.altKey&&e.code===Bw.C}),Xg=O({name:"pasteStyles",label:"labels.pasteStyles",icon:zu,trackEvent:{category:"element"},perform:(e,o,t,n)=>{let r=JSON.parse(Ow),i=r[0],a=r[1];if(!RA(i))return{elements:e,captureUpdate:Vg.EVENTUALLY};let s=ne(e,o,{includeBoundTextElement:!0}),l=s.map(c=>c.id);return{elements:e.map(c=>{if(l.includes(c.id)){let m=i;if(Yg(c)&&c.containerId&&(m=a),!m)return c;let p=Ld(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?LA(m.roundness.type,c)?m.roundness:AA(c):null});if(Yg(p)){let d=m.fontSize||CA,u=m.fontFamily||SA;p=Ld(p,{fontSize:d,fontFamily:u,textAlign:m.textAlign||kA,lineHeight:m.lineHeight||MA(u)});let b=null;p.containerId&&(b=s.find(g=>Yg(p)&&g.id===p.containerId)||null),BA(p,b,n.scene)}return p.type==="arrow"&&_A(m)&&(p=Ld(p,{startArrowhead:m.startArrowhead,endArrowhead:m.endArrowhead})),DA(c)&&(p=Ld(p,{roundness:null,backgroundColor:"transparent"})),p}return c}),captureUpdate:Vg.IMMEDIATELY}},keyTest:e=>e[Fw.CTRL_OR_CMD]&&e.altKey&&e.code===Bw.V});import{KEYS as FA}from"@orangecatai/common";import{CaptureUpdateAction as OA}from"@orangecatai/element";var ai=O({name:"toggleShortcuts",label:"welcomeScreen.defaults.helpHint",icon:dx,viewMode:!0,trackEvent:{category:"menu",action:"toggleHelpDialog"},perform:(e,o,t,{focusContainer:n})=>(o.openDialog?.name==="help"&&n(),{appState:{...o,openDialog:o.openDialog?.name==="help"?null:{name:"help"},openMenu:null,openPopup:null},captureUpdate:OA.EVENTUALLY}),keyTest:e=>e.key===FA.QUESTION_MARK});import{getNonDeletedElements as Dd}from"@orangecatai/element";import{newElementWith as Gw}from"@orangecatai/element";import{isBoundToContainer as zA}from"@orangecatai/element";import{frameAndChildrenSelectedTogether as HA,getElementsInResizingFrame as GA,getFrameLikeElements as UA,getRootElements as WA,groupByFrameLikes as YA,removeElementsFromFrame as VA,replaceAllElementsInFrame as KA}from"@orangecatai/element";import{KEYS as _d,randomId as XA,arrayToMap as $g}from"@orangecatai/common";import{getSelectedGroupIds as Ad,selectGroup as $A,selectGroupsForSelectedElements as ZA,getElementsInGroup as zw,addToGroup as jA,removeFromSelectedGroups as qA,isElementInGroup as Uw}from"@orangecatai/element";import{syncMovedIndices as JA}from"@orangecatai/element";import{CaptureUpdateAction as sl}from"@orangecatai/element";import{jsx as Ea}from"react/jsx-runtime";var QA=e=>{if(e.length>=2){let o=e[0].groupIds;for(let t of o)if(e.reduce((n,r)=>n&&Uw(r,t),!0))return!0}return!1},Hw=(e,o,t)=>{let n=t.scene.getSelectedElements({selectedElementIds:o.selectedElementIds,includeBoundTextElement:!0});return n.length>=2&&!QA(n)&&!HA(n)},Zg=O({name:"group",label:"labels.group",icon:e=>Ea(Ru,{theme:e.theme}),trackEvent:{category:"element"},perform:(e,o,t,n)=>{let r=WA(n.scene.getSelectedElements({selectedElementIds:o.selectedElementIds,includeBoundTextElement:!0}));if(r.length<2)return{appState:o,elements:e,captureUpdate:sl.EVENTUALLY};let i=Ad(o);if(i.length===1){let E=i[0],w=new Set(zw(e,E).map(v=>v.id)),x=new Set(r.map(v=>v.id));if(new Set([...Array.from(w),...Array.from(x)]).size===w.size)return{appState:o,elements:e,captureUpdate:sl.EVENTUALLY}}let a=[...e];new Set(r.map(E=>E.frameId)).size>1&&YA(r).forEach((w,x)=>{VA(w,n.scene.getNonDeletedElementsMap())});let l=XA(),c=$g(r);a=a.map(E=>c.get(E.id)?Gw(E,{groupIds:jA(E.groupIds,l,o.editingGroupId)}):E);let m=zw(a,l),p=m[m.length-1],d=a.lastIndexOf(p),u=a.slice(d+1),b=a.slice(0,d).filter(E=>!Uw(E,l)),g=JA([...b,...m,...u],$g(m));return{appState:{...o,...$A(l,{...o,selectedGroupIds:{}},Dd(a))},elements:g,captureUpdate:sl.IMMEDIATELY}},predicate:(e,o,t,n)=>Hw(e,o,n),keyTest:e=>!e.shiftKey&&e[_d.CTRL_OR_CMD]&&e.key===_d.G,PanelComponent:({elements:e,appState:o,updateData:t,app:n})=>Ea(Q,{hidden:!Hw(e,o,n),type:"button",icon:Ea(Ru,{theme:o.theme}),onClick:()=>t(null),title:`${h("labels.group")} \u2014 ${N("CtrlOrCmd+G")}`,"aria-label":h("labels.group"),visible:Le(Dd(e),o)})}),jg=O({name:"ungroup",label:"labels.ungroup",icon:e=>Ea(Nu,{theme:e.theme}),trackEvent:{category:"element"},perform:(e,o,t,n)=>{let r=Ad(o),i=$g(e);if(r.length===0)return{appState:o,elements:e,captureUpdate:sl.EVENTUALLY};let a=[...e],s=[];a=a.map(d=>{zA(d)&&s.push(d.id);let u=qA(d.groupIds,o.selectedGroupIds);return u.length===d.groupIds.length?d:Gw(d,{groupIds:u})});let l=ZA(o,Dd(a),o,null),c=n.scene.getSelectedElements(o),m=new Set(c.filter(d=>d.frameId).map(d=>d.frameId));return UA(e).filter(d=>m.has(d.id)).forEach(d=>{d&&(a=KA(a,GA(a,d,o,i),d,n))}),l.selectedElementIds=Object.entries(l.selectedElementIds).reduce((d,[u,b])=>(b&&!s.includes(u)&&(d[u]=!0),d),{}),{appState:{...o,...l},elements:a,captureUpdate:sl.IMMEDIATELY}},keyTest:e=>e.shiftKey&&e[_d.CTRL_OR_CMD]&&e.key===_d.G.toUpperCase(),predicate:(e,o)=>Ad(o).length>0,PanelComponent:({elements:e,appState:o,updateData:t})=>Ea(Q,{type:"button",hidden:Ad(o).length===0,icon:Ea(Nu,{theme:o.theme}),onClick:()=>t(null),title:`${h("labels.ungroup")} \u2014 ${N("CtrlOrCmd+Shift+G")}`,"aria-label":h("labels.ungroup"),visible:Le(Dd(e),o)})});import a8 from"clsx";import{CaptureUpdateAction as Xw}from"@orangecatai/element";import{invariant as s8}from"@orangecatai/common";import{COLOR_CHARCOAL_BLACK as e8,COLOR_VOICE_CALL as t8,COLOR_WHITE as Nd,THEME as o8,UserIdleState as Ww}from"@orangecatai/common";var Rd=(e,o,t,n,r,i,a)=>{e.beginPath(),e.moveTo(o+i,t),e.lineTo(o+n-i,t),e.quadraticCurveTo(o+n,t,o+n,t+i),e.lineTo(o+n,t+r-i),e.quadraticCurveTo(o+n,t+r,o+n-i,t+r),e.lineTo(o+i,t+r),e.quadraticCurveTo(o,t+r,o,t+r-i),e.lineTo(o,t+i),e.quadraticCurveTo(o,t,o+i,t),e.closePath(),e.fill(),a&&(e.strokeStyle=a),e.stroke()};function n8(e){let o=0;if(e.length===0)return o;for(let t=0;t<e.length;t++){let n=e.charCodeAt(t);o=(o<<5)-o+n}return o}var si=(e,o)=>`hsl(${Math.abs(n8(o?.id||e))%37*10}, 100%, 83%)`,Yw=e=>{let o=e?.trim()?.codePointAt(0);return(o?String.fromCodePoint(o):"?").toUpperCase()},Vw=({context:e,renderConfig:o,appState:t,normalizedWidth:n,normalizedHeight:r})=>{for(let[i,a]of o.remotePointerViewportCoords){let{x:s,y:l}=a,c=t.collaborators.get(i);s-=t.offsetLeft,l-=t.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=si(i,c);e.save(),e.strokeStyle=u,e.fillStyle=u;let b=o.remotePointerUserStates.get(i),g=d||b===Ww.IDLE||b===Ww.AWAY;g&&(e.globalAlpha=.3),o.remotePointerButton.get(i)==="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 E=t.theme===o8.DARK?"#2f6330":t8,w=c?.isSpeaking;w&&(e.fillStyle=E,e.strokeStyle=E,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=Nd,e.strokeStyle=Nd,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 x=o.remotePointerUsernames.get(i)||"";if(!d&&x){e.font="600 12px sans-serif";let y=(w?s+0:s)+m/2,v=(w?l+0:l)+p+2,T=5,C=3,M=e.measureText(x),S=M.actualBoundingBoxDescent+M.actualBoundingBoxAscent,D=Math.max(S,12),_=y-1,P=v-1,A=M.width+2+T*2+2,z=D+2+C*2+2;if(e.roundRect?(e.beginPath(),e.roundRect(_,P,A,z,8),e.fillStyle=u,e.fill(),e.strokeStyle=Nd,e.stroke(),w&&(e.beginPath(),e.roundRect(_-2,P-2,A+4,z+4,8),e.strokeStyle=E,e.stroke())):Rd(e,_,P,A,z,8,Nd),e.fillStyle=e8,e.fillText(x,y+T+1,v+C+M.actualBoundingBoxAscent+Math.floor((D-S)/2)+2),w){e.fillStyle=E;let V=8,G=8,Y=5;e.fillRect(_+A+G,P+(z/2-V/2),2,V),e.fillRect(_+A+G+Y,P+(z/2-V*2/2),2,V*2),e.fillRect(_+A+G+Y*2,P+(z/2-V/2),2,V)}}e.restore(),e.closePath()}};import r8 from"clsx";import{useState as i8}from"react";import{jsx as Kw}from"react/jsx-runtime";var qg=({color:e,onClick:o,name:t,src:n,className:r})=>{let i=Yw(t),[a,s]=i8(!1),l=!a&&n,c=l?void 0:{background:e};return Kw("div",{className:r8("Avatar",r),style:c,onClick:o,children:l?Kw("img",{className:"Avatar-img",src:n,alt:i,referrerPolicy:"no-referrer",onError:()=>s(!0)}):i})};import{jsx as en,jsxs as Bd}from"react/jsx-runtime";var l8=O({name:"goToCollaborator",label:"Go to a collaborator",viewMode:!0,trackEvent:{category:"collab"},perform:(e,o,t)=>(s8(t,"actionGoToCollaborator: collaborator should be defined when actionGoToCollaborator is called"),!t.socketId||o.userToFollow?.socketId===t.socketId||t.isCurrentUser?{appState:{...o,userToFollow:null},captureUpdate:Xw.EVENTUALLY}:{appState:{...o,userToFollow:{socketId:t.socketId,username:t.username||""},openMenu:o.openMenu==="canvas"?null:o.openMenu},captureUpdate:Xw.EVENTUALLY}),PanelComponent:({updateData:e,data:o,appState:t})=>{let{socketId:n,collaborator:r,withName:i,isBeingFollowed:a}=o,s=si(n,r),l=a8({"is-followed":a,"is-current-user":r.isCurrentUser===!0,"is-speaking":r.isSpeaking,"is-in-call":r.isInCall,"is-muted":r.isMuted}),c=r.isInCall?r.isSpeaking?Bd("div",{className:"UserList__collaborator-status-icon-speaking-indicator",title:h("userList.hint.isSpeaking"),children:[en("div",{}),en("div",{}),en("div",{})]}):r.isMuted?en("div",{className:"UserList__collaborator-status-icon-microphone-muted",title:h("userList.hint.micMuted"),children:wE}):en("div",{title:h("userList.hint.inCall"),children:yE}):null;return i?Bd("div",{className:`dropdown-menu-item dropdown-menu-item-base UserList__collaborator ${l}`,style:{"--avatar-size":"1.5rem"},onClick:()=>e(r),children:[en(qg,{color:s,onClick:()=>{},name:r.username||"",src:r.avatarUrl,className:l}),en("div",{className:"UserList__collaborator-name",children:r.username}),Bd("div",{className:"UserList__collaborator-status-icons","aria-hidden":!0,children:[a&&en("div",{className:"UserList__collaborator-status-icon-is-followed",title:h("userList.hint.followStatus"),children:qi}),c]})]}):Bd("div",{className:`UserList__collaborator UserList__collaborator--avatar-only ${l}`,children:[en(qg,{color:s,onClick:()=>{e(r)},name:r.username||"",src:r.avatarUrl,className:l}),c&&en("div",{className:"UserList__collaborator-status-icon",children:c})]})}});import{LIBRARY_DISABLED_TYPES as c8,randomId as d8}from"@orangecatai/common";import{deepCopyElement as m8}from"@orangecatai/element";import{CaptureUpdateAction as Jg}from"@orangecatai/element";var Qg=O({name:"addToLibrary",trackEvent:{category:"element"},perform:(e,o,t,n)=>{let r=n.scene.getSelectedElements({selectedElementIds:o.selectedElementIds,includeBoundTextElement:!0,includeElementsInFrames:!0});for(let i of c8)if(r.some(a=>a.type===i))return{captureUpdate:Jg.EVENTUALLY,appState:{...o,errorMessage:h(`errors.libraryElementTypeError.${i}`)}};return n.library.getLatestLibrary().then(i=>n.library.setLibrary([{id:d8(),status:"unpublished",elements:r.map(m8),created:Date.now()},...i])).then(()=>({captureUpdate:Jg.EVENTUALLY,appState:{...o,toast:{message:h("toast.addedToLibrary")}}})).catch(i=>({captureUpdate:Jg.EVENTUALLY,appState:{...o,errorMessage:i.message}}))},label:"labels.addToLibrary"});import{getNonDeletedElements as ya}from"@orangecatai/element";import{isFrameLikeElement as p8}from"@orangecatai/element";import{updateFrameMembershipOfSelectedElements as u8}from"@orangecatai/element";import{KEYS as sr,arrayToMap as g8}from"@orangecatai/common";import{alignElements as h8}from"@orangecatai/element";import{CaptureUpdateAction as wa}from"@orangecatai/element";import{getSelectedElementsByGroup as f8}from"@orangecatai/element";import{jsx as Ta}from"react/jsx-runtime";var Nt=(e,o)=>{let t=o.scene.getSelectedElements(e);return f8(t,o.scene.getNonDeletedElementsMap(),e).length>1&&!t.some(n=>p8(n))},va=(e,o,t,n)=>{let r=t.scene.getSelectedElements(o),i=h8(r,n,t.scene,o),a=g8(i);return u8(e.map(s=>a.get(s.id)||s),o,t)},b8=O({name:"alignTop",label:"labels.alignTop",icon:Mu,trackEvent:{category:"element"},predicate:(e,o,t,n)=>Nt(o,n),perform:(e,o,t,n)=>({appState:o,elements:va(e,o,n,{position:"start",axis:"y"}),captureUpdate:wa.IMMEDIATELY}),keyTest:e=>e[sr.CTRL_OR_CMD]&&e.shiftKey&&e.key===sr.ARROW_UP,PanelComponent:({elements:e,appState:o,updateData:t,app:n})=>Ta(Q,{hidden:!Nt(o,n),type:"button",icon:Mu,onClick:()=>t(null),title:`${h("labels.alignTop")} \u2014 ${N("CtrlOrCmd+Shift+Up")}`,"aria-label":h("labels.alignTop"),visible:Le(ya(e),o)})}),x8=O({name:"alignBottom",label:"labels.alignBottom",icon:Pu,trackEvent:{category:"element"},predicate:(e,o,t,n)=>Nt(o,n),perform:(e,o,t,n)=>({appState:o,elements:va(e,o,n,{position:"end",axis:"y"}),captureUpdate:wa.IMMEDIATELY}),keyTest:e=>e[sr.CTRL_OR_CMD]&&e.shiftKey&&e.key===sr.ARROW_DOWN,PanelComponent:({elements:e,appState:o,updateData:t,app:n})=>Ta(Q,{hidden:!Nt(o,n),type:"button",icon:Pu,onClick:()=>t(null),title:`${h("labels.alignBottom")} \u2014 ${N("CtrlOrCmd+Shift+Down")}`,"aria-label":h("labels.alignBottom"),visible:Le(ya(e),o)})}),E8=O({name:"alignLeft",label:"labels.alignLeft",icon:Lu,trackEvent:{category:"element"},predicate:(e,o,t,n)=>Nt(o,n),perform:(e,o,t,n)=>({appState:o,elements:va(e,o,n,{position:"start",axis:"x"}),captureUpdate:wa.IMMEDIATELY}),keyTest:e=>e[sr.CTRL_OR_CMD]&&e.shiftKey&&e.key===sr.ARROW_LEFT,PanelComponent:({elements:e,appState:o,updateData:t,app:n})=>Ta(Q,{hidden:!Nt(o,n),type:"button",icon:Lu,onClick:()=>t(null),title:`${h("labels.alignLeft")} \u2014 ${N("CtrlOrCmd+Shift+Left")}`,"aria-label":h("labels.alignLeft"),visible:Le(ya(e),o)})}),y8=O({name:"alignRight",label:"labels.alignRight",icon:Au,trackEvent:{category:"element"},predicate:(e,o,t,n)=>Nt(o,n),perform:(e,o,t,n)=>({appState:o,elements:va(e,o,n,{position:"end",axis:"x"}),captureUpdate:wa.IMMEDIATELY}),keyTest:e=>e[sr.CTRL_OR_CMD]&&e.shiftKey&&e.key===sr.ARROW_RIGHT,PanelComponent:({elements:e,appState:o,updateData:t,app:n})=>Ta(Q,{hidden:!Nt(o,n),type:"button",icon:Au,onClick:()=>t(null),title:`${h("labels.alignRight")} \u2014 ${N("CtrlOrCmd+Shift+Right")}`,"aria-label":h("labels.alignRight"),visible:Le(ya(e),o)})}),w8=O({name:"alignVerticallyCentered",label:"labels.centerVertically",icon:Du,trackEvent:{category:"element"},predicate:(e,o,t,n)=>Nt(o,n),perform:(e,o,t,n)=>({appState:o,elements:va(e,o,n,{position:"center",axis:"y"}),captureUpdate:wa.IMMEDIATELY}),PanelComponent:({elements:e,appState:o,updateData:t,app:n})=>Ta(Q,{hidden:!Nt(o,n),type:"button",icon:Du,onClick:()=>t(null),title:h("labels.centerVertically"),"aria-label":h("labels.centerVertically"),visible:Le(ya(e),o)})}),v8=O({name:"alignHorizontallyCentered",label:"labels.centerHorizontally",icon:_u,trackEvent:{category:"element"},predicate:(e,o,t,n)=>Nt(o,n),perform:(e,o,t,n)=>({appState:o,elements:va(e,o,n,{position:"center",axis:"x"}),captureUpdate:wa.IMMEDIATELY}),PanelComponent:({elements:e,appState:o,updateData:t,app:n})=>Ta(Q,{hidden:!Nt(o,n),type:"button",icon:_u,onClick:()=>t(null),title:h("labels.centerHorizontally"),"aria-label":h("labels.centerHorizontally"),visible:Le(ya(e),o)})});import{getNonDeletedElements as $w}from"@orangecatai/element";import{isFrameLikeElement as T8}from"@orangecatai/element";import{CODES as Zw,KEYS as jw,arrayToMap as I8}from"@orangecatai/common";import{updateFrameMembershipOfSelectedElements as C8}from"@orangecatai/element";import{distributeElements as S8}from"@orangecatai/element";import{CaptureUpdateAction as qw}from"@orangecatai/element";import{getSelectedElementsByGroup as k8}from"@orangecatai/element";import{jsx as ev}from"react/jsx-runtime";var Jw=(e,o)=>{let t=o.scene.getSelectedElements(e);return k8(t,o.scene.getNonDeletedElementsMap(),e).length>2&&!t.some(n=>T8(n))},Qw=(e,o,t,n)=>{let r=t.scene.getSelectedElements(o),i=S8(r,t.scene.getNonDeletedElementsMap(),n,o,t.scene),a=I8(i);return C8(e.map(s=>a.get(s.id)||s),o,t)},M8=O({name:"distributeHorizontally",label:"labels.distributeHorizontally",trackEvent:{category:"element"},perform:(e,o,t,n)=>({appState:o,elements:Qw(e,o,n,{space:"between",axis:"x"}),captureUpdate:qw.IMMEDIATELY}),keyTest:e=>!e[jw.CTRL_OR_CMD]&&e.altKey&&e.code===Zw.H,PanelComponent:({elements:e,appState:o,updateData:t,app:n})=>ev(Q,{hidden:!Jw(o,n),type:"button",icon:vx,onClick:()=>t(null),title:`${h("labels.distributeHorizontally")} \u2014 ${N("Alt+H")}`,"aria-label":h("labels.distributeHorizontally"),visible:Le($w(e),o)})}),P8=O({name:"distributeVertically",label:"labels.distributeVertically",trackEvent:{category:"element"},perform:(e,o,t,n)=>({appState:o,elements:Qw(e,o,n,{space:"between",axis:"y"}),captureUpdate:qw.IMMEDIATELY}),keyTest:e=>!e[jw.CTRL_OR_CMD]&&e.altKey&&e.code===Zw.V,PanelComponent:({elements:e,appState:o,updateData:t,app:n})=>ev(Q,{hidden:!Jw(o,n),type:"button",icon:Tx,onClick:()=>t(null),title:`${h("labels.distributeVertically")} \u2014 ${N("Alt+V")}`,"aria-label":h("labels.distributeVertically"),visible:Le($w(e),o)})});import{getNonDeletedElements as L8}from"@orangecatai/element";import{bindOrUnbindBindingElements as A8}from"@orangecatai/element";import{getCommonBoundingBox as tv}from"@orangecatai/element";import{newElementWith as D8}from"@orangecatai/element";import{deepCopyElement as _8}from"@orangecatai/element";import{resizeMultipleElements as R8}from"@orangecatai/element";import{isArrowElement as ov,isElbowArrow as N8}from"@orangecatai/element";import{updateFrameMembershipOfSelectedElements as nv}from"@orangecatai/element";import{CODES as rv,KEYS as B8,arrayToMap as F8}from"@orangecatai/common";import{CaptureUpdateAction as iv}from"@orangecatai/element";var eh=O({name:"flipHorizontal",label:"labels.flipHorizontal",icon:CE,trackEvent:{category:"element"},perform:(e,o,t,n)=>({elements:nv(av(e,n.scene.getNonDeletedElementsMap(),o,"horizontal",n),o,n),appState:o,captureUpdate:iv.IMMEDIATELY}),keyTest:e=>e.shiftKey&&e.code===rv.H}),th=O({name:"flipVertical",label:"labels.flipVertical",icon:IE,trackEvent:{category:"element"},perform:(e,o,t,n)=>({elements:nv(av(e,n.scene.getNonDeletedElementsMap(),o,"vertical",n),o,n),appState:o,captureUpdate:iv.IMMEDIATELY}),keyTest:e=>e.shiftKey&&e.code===rv.V&&!e[B8.CTRL_OR_CMD]}),av=(e,o,t,n,r)=>{let i=ne(L8(e),t,{includeBoundTextElement:!0,includeElementsInFrames:!0}),a=O8(i,o,n,r),s=F8(a);return e.map(l=>s.get(l.id)||l)},O8=(e,o,t,n)=>{if(e.every(d=>ov(d)&&(d.startBinding||d.endBinding)))return e.map(d=>{let u=d;return D8(u,{startArrowhead:u.endArrowhead,endArrowhead:u.startArrowhead})});let{midX:r,midY:i}=tv(e);R8(e,o,"nw",n.scene,new Map(Array.from(o.values()).map(d=>[d.id,_8(d)])),{flipByX:t==="horizontal",flipByY:t==="vertical",shouldResizeFromCenter:!0,shouldMaintainAspectRatio:!0}),A8(e.filter(ov),n.scene,n.state);let{elbowArrows:a,otherElements:s}=e.reduce((d,u)=>N8(u)?{...d,elbowArrows:d.elbowArrows.concat(u)}:{...d,otherElements:d.otherElements.concat(u)},{elbowArrows:[],otherElements:[]}),{midX:l,midY:c}=tv(e),[m,p]=[r-l,i-c];return s.forEach(d=>n.scene.mutateElement(d,{x:d.x+m,y:d.y+p})),a.forEach(d=>n.scene.mutateElement(d,{x:d.x+m,y:d.y+p})),e};import{isTextElement as z8}from"@orangecatai/element";import{getTextFromElements as H8}from"@orangecatai/element";import{CODES as G8,KEYS as sv,isFirefox as U8}from"@orangecatai/common";import{CaptureUpdateAction as to}from"@orangecatai/element";var Ia=O({name:"copy",label:"labels.copy",icon:Ls,trackEvent:{category:"element"},perform:async(e,o,t,n)=>{let r=n.scene.getSelectedElements({selectedElementIds:o.selectedElementIds,includeBoundTextElement:!0,includeElementsInFrames:!0});try{await Sd(r,n.files,t)}catch(i){return{captureUpdate:to.EVENTUALLY,appState:{...o,errorMessage:i.message}}}return{captureUpdate:to.EVENTUALLY}},keyTest:void 0}),oh=O({name:"paste",label:"labels.paste",trackEvent:{category:"element"},perform:async(e,o,t,n)=>{let r;try{r=await Pw()}catch(i){return i.name==="AbortError"||i.name==="NotAllowedError"?!1:(console.error(`actionPaste ${i.name}: ${i.message}`),U8?{captureUpdate:to.EVENTUALLY,appState:{...o,errorMessage:h("hints.firefox_clipboard_write")}}:{captureUpdate:to.EVENTUALLY,appState:{...o,errorMessage:h("errors.asyncPasteFailedOnRead")}})}try{n.pasteFromClipboard(kw({types:r}))}catch(i){return console.error(i),{captureUpdate:to.EVENTUALLY,appState:{...o,errorMessage:h("errors.asyncPasteFailedOnParse")}}}return{captureUpdate:to.EVENTUALLY}},keyTest:void 0}),Fd=O({name:"cut",label:"labels.cut",icon:lE,trackEvent:{category:"element"},perform:(e,o,t,n)=>(Ia.perform(e,o,t,n),zs.perform(e,o,null,n)),keyTest:e=>e[sv.CTRL_OR_CMD]&&e.key===sv.X}),Od=O({name:"copyAsSvg",label:"labels.copyAsSvg",icon:SE,trackEvent:{category:"element"},perform:async(e,o,t,n)=>{if(!n.canvas)return{captureUpdate:to.EVENTUALLY};let{exportedElements:r,exportingFrame:i}=ni(e,o,!0);try{await ri("clipboard-svg",r,o,n.files,{...o,exportingFrame:i,name:n.getName()});let a=n.scene.getSelectedElements({selectedElementIds:o.selectedElementIds,includeBoundTextElement:!0,includeElementsInFrames:!0});return{appState:{toast:{message:h("toast.copyToClipboardAsSvg",{exportSelection:a.length?h("toast.selection"):h("toast.canvas"),exportColorScheme:o.exportWithDarkMode?h("buttons.darkMode"):h("buttons.lightMode")})}},captureUpdate:to.EVENTUALLY}}catch(a){return console.error(a),{appState:{errorMessage:a.message},captureUpdate:to.EVENTUALLY}}},predicate:e=>Cd&&e.length>0,keywords:["svg","clipboard","copy"]}),zd=O({name:"copyAsPng",label:"labels.copyAsPng",icon:kE,trackEvent:{category:"element"},perform:async(e,o,t,n)=>{if(!n.canvas)return{captureUpdate:to.EVENTUALLY};let r=n.scene.getSelectedElements({selectedElementIds:o.selectedElementIds,includeBoundTextElement:!0,includeElementsInFrames:!0}),{exportedElements:i,exportingFrame:a}=ni(e,o,!0);try{return await ri("clipboard",i,o,n.files,{...o,exportingFrame:a,name:n.getName()}),{appState:{...o,toast:{message:h("toast.copyToClipboardAsPng",{exportSelection:r.length?h("toast.selection"):h("toast.canvas"),exportColorScheme:o.exportWithDarkMode?h("buttons.darkMode"):h("buttons.lightMode")})}},captureUpdate:to.EVENTUALLY}}catch(s){return console.error(s),{appState:{...o,errorMessage:s.message},captureUpdate:to.EVENTUALLY}}},predicate:e=>ha&&e.length>0,keyTest:e=>e.code===G8.C&&e.altKey&&e.shiftKey,keywords:["png","clipboard","copy"]}),Hd=O({name:"copyText",label:"labels.copyText",trackEvent:{category:"element"},perform:(e,o,t,n)=>{let r=n.scene.getSelectedElements({selectedElementIds:o.selectedElementIds,includeBoundTextElement:!0});try{Lo(H8(r))}catch{throw new Error(h("errors.copyToSystemClipboardFailed"))}return{captureUpdate:to.EVENTUALLY}},predicate:(e,o,t,n)=>Cd&&n.scene.getSelectedElements({selectedElementIds:o.selectedElementIds,includeBoundTextElement:!0}).some(z8),keywords:["text","clipboard","copy"]});import{CODES as W8,KEYS as Y8}from"@orangecatai/common";import{CaptureUpdateAction as V8}from"@orangecatai/element";var Ca=O({name:"gridMode",icon:DE,keywords:["snap"],label:"labels.toggleGrid",viewMode:!0,trackEvent:{category:"canvas",predicate:e=>e.gridModeEnabled},perform(e,o){return{appState:{...o,gridModeEnabled:!this.checked(o),objectsSnapModeEnabled:!1},captureUpdate:V8.EVENTUALLY}},checked:e=>e.gridModeEnabled,predicate:(e,o,t)=>t.gridModeEnabled===void 0,keyTest:e=>e[Y8.CTRL_OR_CMD]&&e.code===W8.QUOTE});import{CODES as K8,KEYS as X8}from"@orangecatai/common";import{CaptureUpdateAction as $8}from"@orangecatai/element";var lr=O({name:"zenMode",label:"buttons.zenMode",icon:PE,viewMode:!0,trackEvent:{category:"canvas",predicate:e=>!e.zenModeEnabled},perform(e,o){return{appState:{...o,zenModeEnabled:!this.checked(o)},captureUpdate:$8.EVENTUALLY}},checked:e=>e.zenModeEnabled,predicate:(e,o,t,n)=>n.editorInterface.formFactor!=="phone"&&typeof t.zenModeEnabled>"u",keyTest:e=>!e[X8.CTRL_OR_CMD]&&e.altKey&&e.code===K8.Z});import{CODES as Z8,KEYS as j8}from"@orangecatai/common";import{CaptureUpdateAction as q8}from"@orangecatai/element";var ll=O({name:"objectsSnapMode",label:"buttons.objectsSnapMode",icon:ME,viewMode:!1,trackEvent:{category:"canvas",predicate:e=>!e.objectsSnapModeEnabled},perform(e,o){return{appState:{...o,objectsSnapModeEnabled:!this.checked(o),gridModeEnabled:!1},captureUpdate:q8.EVENTUALLY}},checked:e=>e.objectsSnapModeEnabled,predicate:(e,o,t)=>typeof t.objectsSnapModeEnabled>"u",keyTest:e=>!e[j8.CTRL_OR_CMD]&&e.altKey&&e.code===Z8.S});import{CODES as J8,KEYS as Q8}from"@orangecatai/common";import{CaptureUpdateAction as eD}from"@orangecatai/element";var cr=O({name:"stats",label:"stats.fullTitle",icon:TE,viewMode:!0,trackEvent:{category:"menu"},keywords:["edit","attributes","customize"],perform(e,o){return{appState:{...o,stats:{...o.stats,open:!this.checked(o)}},captureUpdate:eD.EVENTUALLY}},checked:e=>e.stats.open,keyTest:e=>!e[Q8.CTRL_OR_CMD]&&e.altKey&&e.code===J8.SLASH});import{BOUND_TEXT_PADDING as lv,ROUNDNESS as cv,TEXT_ALIGN as pv,VERTICAL_ALIGN as uv,arrayToMap as gv,getFontString as tD}from"@orangecatai/common";import{getOriginalContainerHeightFromCache as oD,isBoundToContainer as dv,resetOriginalContainerCache as nD,updateOriginalContainerCache as rD}from"@orangecatai/element";import{computeBoundTextPosition as iD,computeContainerDimensionForBoundText as mv,getBoundTextElement as hv,redrawTextBoundingBox as fv}from"@orangecatai/element";import{hasBoundTextElement as aD,isArrowElement as sD,isTextBindableContainer as nh,isTextElement as cl,isUsingAdaptiveRadius as lD}from"@orangecatai/element";import{measureText as cD}from"@orangecatai/element";import{syncMovedIndices as bv}from"@orangecatai/element";import{newElement as dD}from"@orangecatai/element";import{CaptureUpdateAction as rh}from"@orangecatai/element";var ih=O({name:"unbindText",label:"labels.unbindText",trackEvent:{category:"element"},predicate:(e,o,t,n)=>n.scene.getSelectedElements(o).some(i=>aD(i)),perform:(e,o,t,n)=>{let r=n.scene.getSelectedElements(o),i=n.scene.getNonDeletedElementsMap();return r.forEach(a=>{let s=hv(a,i);if(s){let{width:l,height:c}=cD(s.originalText,tD(s),s.lineHeight),m=oD(a.id);nD(a.id);let{x:p,y:d}=iD(a,s,i);n.scene.mutateElement(s,{containerId:null,width:l,height:c,text:s.originalText,x:p,y:d}),n.scene.mutateElement(a,{boundElements:a.boundElements?.filter(u=>u.id!==s.id),height:m||a.height})}}),{elements:e,appState:o,captureUpdate:rh.IMMEDIATELY}}}),ah=O({name:"bindText",label:"labels.bindText",trackEvent:{category:"element"},predicate:(e,o,t,n)=>{let r=n.scene.getSelectedElements(o);if(r.length===2){let i=cl(r[0])||cl(r[1]),a;if(nh(r[0])?a=r[0]:nh(r[1])&&(a=r[1]),i&&a&&hv(a,n.scene.getNonDeletedElementsMap())===null)return!0}return!1},perform:(e,o,t,n)=>{let r=n.scene.getSelectedElements(o),i,a;cl(r[0])&&nh(r[1])?(i=r[0],a=r[1]):(i=r[1],a=r[0]),n.scene.mutateElement(i,{containerId:a.id,verticalAlign:uv.MIDDLE,textAlign:pv.CENTER,autoResize:!0,angle:sD(a)?0:a?.angle??0}),n.scene.mutateElement(a,{boundElements:(a.boundElements||[]).concat({type:"text",id:i.id})});let s=a.height;return fv(i,a,n.scene),rD(a.id,s),{elements:mD(e,a,i),appState:{...o,selectedElementIds:{[a.id]:!0}},captureUpdate:rh.IMMEDIATELY}}}),mD=(e,o,t)=>{let n=e.slice(),r=n.findIndex(a=>a.id===t.id);n.splice(r,1);let i=n.findIndex(a=>a.id===o.id);return n.splice(i+1,0,t),bv(n,gv([o,t])),n},pD=(e,o,t)=>{let n=e.slice(),r=n.findIndex(a=>a.id===o.id);n.splice(r,1);let i=n.findIndex(a=>a.id===t.id);return n.splice(i,0,o),bv(n,gv([o,t])),n},xv=O({name:"wrapTextInContainer",label:"labels.createContainerFromText",trackEvent:{category:"element"},predicate:(e,o,t,n)=>{let r=n.scene.getSelectedElements(o),i=r.some(a=>cl(a)&&!dv(a));return r.length>0&&i},perform:(e,o,t,n)=>{let r=n.scene.getSelectedElements(o),i=e.slice(),a={};for(let s of r)if(cl(s)&&!dv(s)){let l=dD({type:"rectangle",backgroundColor:o.currentItemBackgroundColor,boundElements:[...s.boundElements||[],{id:s.id,type:"text"}],angle:s.angle,fillStyle:o.currentItemFillStyle,strokeColor:o.currentItemStrokeColor,roughness:o.currentItemRoughness,strokeWidth:o.currentItemStrokeWidth,strokeStyle:o.currentItemStrokeStyle,roundness:o.currentItemRoundness==="round"?{type:lD("rectangle")?cv.ADAPTIVE_RADIUS:cv.PROPORTIONAL_RADIUS}:null,opacity:100,locked:!1,x:s.x-lv,y:s.y-lv,width:mv(s.width,"rectangle"),height:mv(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);i.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:uv.MIDDLE,boundElements:null,textAlign:pv.CENTER,autoResize:!0}),fv(s,l,n.scene),i=pD([...i,l],l,s),a[l.id]=!0}return{elements:i,appState:{...o,selectedElementIds:a},captureUpdate:rh.IMMEDIATELY}}});import{isEmbeddableElement as PD}from"@orangecatai/element";import{KEYS as Mv}from"@orangecatai/common";import{CaptureUpdateAction as LD}from"@orangecatai/element";import{pointFrom as vv}from"@orangecatai/math";import uD from"clsx";import{useCallback as Ev,useEffect as yv,useLayoutEffect as gD,useRef as hD,useState as fD}from"react";import{EVENT as sh,HYPERLINK_TOOLTIP_DELAY as bD,KEYS as Gd}from"@orangecatai/common";import{getElementAbsoluteCoords as ph}from"@orangecatai/element";import{hitElementBoundingBox as xD}from"@orangecatai/element";import{isElementLink as ED}from"@orangecatai/element";import{getEmbedLink as yD,embeddableURLValidator as wD}from"@orangecatai/element";import{sceneCoordsToViewportCoords as Tv,viewportCoordsToSceneCoords as vD,wrapEvent as TD,isLocalLink as ID,normalizeLink as lh}from"@orangecatai/common";import{isEmbeddableElement as ch}from"@orangecatai/element";import{jsx as Sa,jsxs as wv}from"react/jsx-runtime";var uh=380,CD=42,dh=5,Iv=85,SD=500,mh=!1,Ud=new Map,Cv=({element:e,scene:o,setAppState:t,onLinkOpen:n,setToast:r,updateEmbedValidationStatus:i})=>{let a=o.getNonDeletedElementsMap(),s=Zo(),l=jo(),c=fe(),m=e.link||"",[p,d]=fD(m),u=hD(null),b=s.showHyperlinkPopup==="editor",g=Ev(()=>{if(!u.current)return;let v=lh(u.current.value)||null;if(!e.link&&v&&me("hyperlink","create"),ch(e)){if(s.activeEmbeddable?.element===e&&t({activeEmbeddable:null}),!v){o.mutateElement(e,{link:null}),i(e,!1);return}if(!wD(v,l.validateEmbeddable))v&&r({message:h("toast.unableToEmbed"),closable:!0}),e.link&&Ud.set(e.id,e.link),o.mutateElement(e,{link:v}),i(e,!1);else{let{width:T,height:C}=e,M=yD(v);M?.error instanceof URIError&&r({message:h("toast.unrecognizedLinkFormat"),closable:!0});let S=M?M.intrinsicSize.w/M.intrinsicSize.h:1,D=Ud.get(e.id)!==e.link;o.mutateElement(e,{...D?{width:M?.type==="video"?T>C?T:C*S:T,height:M?.type==="video"&&T>C?T/S:C}:{},link:v}),i(e,!0),Ud.has(e.id)&&Ud.delete(e.id)}}else o.mutateElement(e,{link:v})},[e,o,r,l.validateEmbeddable,s.activeEmbeddable,t,i]);gD(()=>()=>{g()},[g]),yv(()=>{b&&u?.current&&!(c.formFactor==="phone"||c.isTouchScreen)&&u.current.select()},[b,c.formFactor,c.isTouchScreen]),yv(()=>{let v=null,T=C=>{if(b)return;v&&clearTimeout(v),MD(e,a,s,vv(C.clientX,C.clientY))&&(v=window.setTimeout(()=>{t({showHyperlinkPopup:!1})},SD))};return window.addEventListener(sh.POINTER_MOVE,T,!1),()=>{window.removeEventListener(sh.POINTER_MOVE,T,!1),v&&clearTimeout(v)}},[s,e,b,t,a]);let E=Ev(()=>{me("hyperlink","delete"),o.mutateElement(e,{link:null}),t({showHyperlinkPopup:!1})},[t,e,o]),w=()=>{me("hyperlink","edit","popup-ui"),t({showHyperlinkPopup:"editor"})},{x,y}=Sv(e,s,a);return s.contextMenu||s.selectedElementsAreBeingDragged||s.resizingElement||s.isRotating||s.openMenu||s.viewModeEnabled?null:wv("div",{className:"excalidraw-hyperlinkContainer",style:{top:`${y}px`,left:`${x}px`,width:uh,padding:dh},children:[b?Sa("input",{className:uD("excalidraw-hyperlinkContainer-input"),placeholder:h("labels.link.hint"),ref:u,value:p,onChange:v=>d(v.target.value),autoFocus:!0,onKeyDown:v=>{v.stopPropagation(),v[Gd.CTRL_OR_CMD]&&v.key===Gd.K&&v.preventDefault(),(v.key===Gd.ENTER||v.key===Gd.ESCAPE)&&(g(),t({showHyperlinkPopup:"info"}))}}):e.link?Sa("a",{href:lh(e.link||""),className:"excalidraw-hyperlinkContainer-link",target:ID(e.link)?"_self":"_blank",onClick:v=>{if(e.link&&n){let T=TD(sh.EXCALIDRAW_LINK,v.nativeEvent);n({...e,link:lh(e.link)},T),T.defaultPrevented&&v.preventDefault()}},rel:"noopener noreferrer",children:e.link}):Sa("div",{className:"excalidraw-hyperlinkContainer-link",children:h("labels.link.empty")}),wv("div",{className:"excalidraw-hyperlinkContainer__buttons",children:[!b&&Sa(Q,{type:"button",title:h("buttons.edit"),"aria-label":h("buttons.edit"),label:h("buttons.edit"),onClick:w,className:"excalidraw-hyperlinkContainer--edit",icon:Ko}),Sa(Q,{type:"button",title:h("labels.linkToElement"),"aria-label":h("labels.linkToElement"),label:h("labels.linkToElement"),onClick:()=>{t({openDialog:{name:"elementLinkSelector",sourceElementId:e.id}})},icon:Yc}),m&&!ch(e)&&Sa(Q,{type:"button",title:h("buttons.remove"),"aria-label":h("buttons.remove"),label:h("buttons.remove"),onClick:E,className:"excalidraw-hyperlinkContainer--remove",icon:yt})]})]})},Sv=(e,o,t)=>{let[n,r]=ph(e,t),{x:i,y:a}=Tv({sceneX:n+e.width/2,sceneY:r},o),s=i-o.offsetLeft-uh/2,l=a-o.offsetTop-Iv;return{x:s,y:l}},gh=(e,o)=>{let t=ne(e,o);return ch(t[0])?"labels.link.editEmbed":t[0]?.link?"labels.link.edit":"labels.link.create"},dl=null,kv=(e,o,t)=>{dl&&clearTimeout(dl),dl=window.setTimeout(()=>kD(e,o,t),bD)},kD=(e,o,t)=>{if(!e.link)return;let n=pa();n.classList.add("excalidraw-tooltip--visible"),n.style.maxWidth="20rem",n.textContent=ED(e.link)?h("labels.link.goToElement"):e.link;let[r,i,a,s]=ph(e,t),[l,c,m,p]=Ab([r,i,a,s],e.angle,o),d=Tv({sceneX:l,sceneY:c},o);Lg(n,{left:d.x,top:d.y,width:m,height:p},"top"),me("hyperlink","tooltip","link-icon"),mh=!0},hh=()=>{dl&&clearTimeout(dl),mh&&(mh=!1,pa().classList.remove("excalidraw-tooltip--visible"))},MD=(e,o,t,[n,r])=>{let{x:i,y:a}=vD({clientX:n,clientY:r},t),s=15/t.zoom.value;if(xD(vv(i,a),e,o))return!1;let[l,c,m]=ph(e,o);if(i>=l&&i<=m&&a>=c-Iv&&a<=c)return!1;let{x:p,y:d}=Sv(e,t,o);return!(n>=p-s&&n<=p+uh+dh*2+s&&r>=d-s&&r<=d+s+dh*2+CD)};import{jsx as AD}from"react/jsx-runtime";var ml=O({name:"hyperlink",label:(e,o)=>gh(e,o),icon:_s,perform:(e,o)=>o.showHyperlinkPopup==="editor"?!1:{elements:e,appState:{...o,showHyperlinkPopup:"editor",openMenu:null},captureUpdate:LD.IMMEDIATELY},trackEvent:{category:"hyperlink",action:"click"},keyTest:e=>e[Mv.CTRL_OR_CMD]&&e.key===Mv.K,predicate:(e,o)=>ne(e,o).length===1,PanelComponent:({elements:e,appState:o,updateData:t})=>{let n=ne(e,o);return AD(Q,{type:"button",icon:_s,"aria-label":h(gh(e,o)),title:`${PD(e[0])?h("labels.link.labelEmbed"):h("labels.link.label")} - ${N("CtrlOrCmd+K")}`,onClick:()=>t(null),selected:n.length===1&&!!n[0].link})}});import{KEYS as Pv,arrayToMap as bh,randomId as DD}from"@orangecatai/common";import{elementsAreInSameGroup as _D,newElementWith as Lv,selectGroupsFromGivenElements as Av}from"@orangecatai/element";import{CaptureUpdateAction as Dv}from"@orangecatai/element";var fh=e=>e.every(o=>!o.locked),pl=O({name:"toggleElementLock",label:(e,o,t)=>{let n=t.scene.getSelectedElements({selectedElementIds:o.selectedElementIds,includeBoundTextElement:!1});return fh(n)?"labels.elementLock.lock":"labels.elementLock.unlock"},icon:(e,o)=>{let t=ne(o,e);return fh(t)?Hi:Xr},trackEvent:{category:"element"},predicate:(e,o,t,n)=>{let r=n.scene.getSelectedElements(o);return r.length>0&&!r.some(i=>i.locked&&i.frameId)},perform:(e,o,t,n)=>{let r=n.scene.getSelectedElements({selectedElementIds:o.selectedElementIds,includeBoundTextElement:!0,includeElementsInFrames:!0});if(!r.length)return!1;let i=fh(r),a=bh(r),s=r.length>1&&_D(r),c=r.length===1||s?null:DD(),m={...o.lockedMultiSelections};if(i)m={...o.lockedMultiSelections,...c?{[c]:!0}:{}};else if(s){let w=r[0].groupIds.at(-1);delete m[w]}let p=e.map(w=>{if(!a.has(w.id))return w;let x=w.groupIds;return i?c&&(x=[...x,c]):x=x.filter(y=>!o.lockedMultiSelections[y]),Lv(w,{locked:i,groupIds:x.length!==w.groupIds.length?x:w.groupIds})}),d=bh(p),u=i?{}:Object.fromEntries(r.map(w=>[w.id,!0])),b=r.map(w=>d.get(w.id)||w),g=i?{}:Av(b,o),E=i?c||(s?r[0].groupIds.at(-1):r[0].id):null;return{elements:p,appState:{...o,selectedElementIds:u,selectedGroupIds:g,selectedLinearElement:i?null:o.selectedLinearElement,lockedMultiSelections:m,activeLockedId:E},captureUpdate:Dv.IMMEDIATELY}},keyTest:(e,o,t,n)=>e.key.toLocaleLowerCase()===Pv.L&&e[Pv.CTRL_OR_CMD]&&e.shiftKey&&n.scene.getSelectedElements({selectedElementIds:o.selectedElementIds,includeBoundTextElement:!1}).length>0}),_v=O({name:"unlockAllElements",trackEvent:{category:"canvas"},viewMode:!1,icon:Xr,predicate:(e,o)=>ne(e,o).length===0&&e.some(n=>n.locked),perform:(e,o)=>{let t=e.filter(a=>a.locked),n=e.map(a=>{if(a.locked){let s=a.groupIds.filter(l=>!o.lockedMultiSelections[l]);return Lv(a,{locked:!1,groupIds:a.groupIds.length!==s.length?s:a.groupIds})}return a}),r=bh(n),i=t.map(a=>r.get(a.id)||a);return{elements:n,appState:{...o,selectedElementIds:Object.fromEntries(t.map(a=>[a.id,!0])),selectedGroupIds:Av(i,o),lockedMultiSelections:{},activeLockedId:null},captureUpdate:Dv.IMMEDIATELY}},label:"labels.elementLock.unlockAll"});import{isElbowArrow as x9,isLinearElement as E9,isLineElement as Ka}from"@orangecatai/element";import{arrayToMap as y9,invariant as Sf}from"@orangecatai/common";import{toggleLinePolygonState as w9,CaptureUpdateAction as o3}from"@orangecatai/element";import LT from"clsx";import lN from"fuzzy";import{useEffect as bm,useRef as AT,useMemo as cN,useState as fm}from"react";import{DEFAULT_SIDEBAR as kT,EVENT as Em,KEYS as Ro,capitalizeString as dN,isWritableElement as mN}from"@orangecatai/common";import{CaptureUpdateAction as h_}from"@orangecatai/element";import{useEffect as hl,useMemo as Rv,useRef as wh,useState as RD}from"react";import{getLinearElementSubType as Pa,updateElbowArrowPoints as ND}from"@orangecatai/element";import{pointFrom as Yd,pointRotateRads as BD}from"@orangecatai/math";import{hasBoundTextElement as FD,isArrowBoundToElement as OD,isArrowElement as zD,isElbowArrow as HD,isLinearElement as Ch,isUsingAdaptiveRadius as GD}from"@orangecatai/element";import{getCommonBoundingBox as UD,getElementAbsoluteCoords as WD}from"@orangecatai/element";import{getBoundTextElement as zv,getBoundTextMaxHeight as YD,getBoundTextMaxWidth as VD,redrawTextBoundingBox as KD}from"@orangecatai/element";import{wrapText as XD}from"@orangecatai/element";import{assertNever as $D,CLASSES as ZD,getFontString as xh,isProdEnv as jD,mapFind as qD,reduceToCommonValue as JD,updateActiveTool as Nv}from"@orangecatai/common";import{measureText as Bv}from"@orangecatai/element";import{LinearElementEditor as QD}from"@orangecatai/element";import{newArrowElement as Eh,newElement as e_,newLinearElement as t_}from"@orangecatai/element";import{ShapeCache as o_}from"@orangecatai/element";import{updateBindings as n_}from"@orangecatai/element";import{jsx as Ih}from"react/jsx-runtime";var r_=8,i_=10,ul=["rectangle","diamond","ellipse"],gl=["line","sharpArrow","curvedArrow","elbowArrow"],a_=new Set(ul),s_=new Set(gl),La=e=>a_.has(e),Kd=e=>e==="arrow"||s_.has(e),Do=ye(null),fl=new Map,bl=new Map,l_=({app:e})=>{let o=e.scene.getSelectedElements(e.state),t=wh(null);return hl(()=>{if(o.length===0){e.updateEditorAtom(Do,null);return}let n=Aa(o);n&&!t.current?t.current=n:(t.current&&!n||t.current&&n!==t.current)&&(e.updateEditorAtom(Do,null),t.current=null)},[o,e]),hl(()=>()=>{fl.clear(),bl.clear()},[]),Ih(c_,{app:e,elements:o})},c_=({app:e,elements:o})=>{let t=Aa(o),n=Rv(()=>t==="generic"?Gv(o):[],[t,o]),r=Rv(()=>t==="linear"?Th(o):[],[t,o]),i=t==="generic"?n.every(p=>p.type===n[0].type):t==="linear"?r.every(p=>Pa(p)===Pa(r[0])):!1,[a,s]=RD({x:0,y:0}),l=wh(""),c=wh(null);hl(()=>{let p=[...n,...r].sort((E,w)=>E.id.localeCompare(w.id)),d=`
|
|
7
|
-
${e.state.scrollX}${e.state.scrollY}${e.state.offsetTop}${e.state.offsetLeft}${e.state.zoom.value}${p.map(E=>E.id).join(",")}`;if(d===l.current)return;l.current=d;let u;if(p.length===1){let[E,,,w,x,y]=WD(p[0],e.scene.getNonDeletedElementsMap());u=BD(Yd(E,w),Yd(x,y),p[0].angle)}else{let{minX:E,maxY:w}=UD(p);u=Yd(E,w)}let{x:b,y:g}=Wv({sceneX:u[0],sceneY:u[1]},e.state);s({x:b,y:g})},[n,r,e.scene,e.state]),hl(()=>{for(let p of r){let d=vh(p.id,g_(p));bl.has(d)||bl.set(d,p)}},[r]),hl(()=>{for(let p of n)if(!fl.has(p.id)){let d=zv(p,e.scene.getNonDeletedElementsMap());d&&fl.set(p.id,{fontSize:d.fontSize})}},[n,e.scene]);let m=t==="linear"?[["line",Yi],["sharpArrow",Ji],["curvedArrow",ea],["elbowArrow",Qi]]:t==="generic"?[["rectangle",Gi],["diamond",Ui],["ellipse",Wi]]:[];return Ih("div",{ref:c,tabIndex:-1,style:{position:"absolute",top:`${a.y+(i_+8)*e.state.zoom.value-e.state.offsetTop}px`,left:`${a.x-e.state.offsetLeft-r_}px`,zIndex:2},className:ZD.CONVERT_ELEMENT_TYPE_POPUP,children:m.map(([p,d])=>{let u=i&&(t==="generic"&&n[0].type===p||t==="linear"&&Pa(r[0])===p);return Ih(Q,{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&&me("convertElementType",p,"ui"),Sh(e,{conversionType:t,nextType:p}),c.current?.focus()}},`${o[0].id}${o[0].version}_${p}`)})})},d_=(e,o,t)=>{let n=VD(e,o),r=YD(e,o),i=XD(o.text,xh(o),n),a=Bv(i,xh(o),o.lineHeight),s=o.fontSize;for(;(a.width>n||a.height>r)&&s>0;){s-=1;let l={...o,fontSize:s};a=Bv(o.text,xh(l),o.lineHeight)}Xd(o,t.getNonDeletedElementsMap(),{fontSize:s,width:a.width,height:a.height}),KD(o,e,t)},Sh=(e,{conversionType:o,nextType:t,direction:n="right"})=>{if(!o)return!1;let r=e.scene.getSelectedElements(e.state),i=r.reduce((s,l)=>({...s,[l.id]:!0}),{}),a=n==="right"?1:-1;if(o==="generic"){let s=Gv(r),c=s.every(m=>m.type===s[0].type)?ul.indexOf(s[0].type):-1;if(t=t??ul[(c+ul.length+a)%ul.length],t&&La(t)){let m={};for(let d of s){let u=Ov(d,t,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=zv(d,e.scene.getNonDeletedElementsMap());u&&(fl.get(d.id)&&Xd(u,e.scene.getNonDeletedElementsMap(),{fontSize:fl.get(d.id)?.fontSize??u.fontSize}),d_(d,u,e.scene))}e.setState(d=>({selectedElementIds:i,activeTool:Nv(d,{type:"selection"})}))}}if(o==="linear"){let s=Th(r);if(!t){let c=JD(s,Pa),m=c?gl.indexOf(c):-1;t=gl[(m+gl.length+a)%gl.length]}if(Kd(t)){let c=[],m=e.scene.getElementsMapIncludingDeleted();for(let p of s){let d=bl.get(vh(p.id,t));if(d&&Pa(d)===t)m.set(d.id,d),c.push(d);else{let u=Ov(p,t,e);m.set(u.id,u),c.push(u)}}e.scene.replaceAllElements(m);for(let p of c)if(Ch(p))if(HD(p)){let d=m_(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 b=ND(p,e.scene.getNonDeletedElementsMap(),{points:d,fixedSegments:u});Xd(p,e.scene.getNonDeletedElementsMap(),{...b,endArrowhead:"arrow"})}else{let d=qD(["line","sharpArrow","curvedArrow"],u=>bl.get(vh(p.id,u)));if(d){let u=d.points;e.scene.mutateElement(p,{points:u})}}}let l=Th(e.scene.getSelectedElements(e.state));e.setState(c=>({selectedElementIds:i,selectedLinearElement:l.length===1?new QD(l[0],e.scene.getNonDeletedElementsMap()):null,activeTool:Nv(c,{type:"selection"})}))}return!0},Aa=e=>{if(e.length===0)return null;let o=!1;for(let t of e){if(La(t.type))return"generic";Hv(t)&&(o=!0)}return o?"linear":null},Hv=e=>Ch(e)&&(!zD(e)||!OD(e)&&!FD(e)),vh=(e,o)=>`${e}:${o}`,Gv=e=>e.filter(o=>La(o.type)),Th=e=>e.filter(o=>Hv(o)),Wd=20,ka=(e,o)=>e[0]===o[0],yh=(e,o)=>e[1]===o[1],Fv=(e,o)=>ka(e,o)?Math.abs(e[1]-o[1]):Math.abs(e[0]-o[0]),m_=e=>{let o=[e.points[0]],t=p_(e.points);for(let i=1;i<t.length;++i){let a=o[o.length-1],s=[...t[i]];Math.abs(s[0]-a[0])<Wd?s[0]=a[0]:Math.abs(s[1]-a[1])<Wd&&(s[1]=a[1]),ka(a,s)||yh(a,s)||o.push(Yd(a[0],s[1])),o.push(s)}let n=[o[0]];for(let i=1;i<o.length-1;++i)ka(o[i-1],o[i])&&ka(o[i],o[i+1])||yh(o[i-1],o[i])&&yh(o[i],o[i+1])||n.push(o[i]);n.push(o[o.length-1]);let r=[n[0]];for(let i=1;i<n.length-1;++i){let a=r[r.length-1],s=n[i],l=n[i+1],c=ka(a,s),m=ka(s,l);if(c!==m){let p=Fv(a,s),d=Fv(s,l);if(p<Wd||d<Wd){if(d<p)c?l[0]=a[0]:l[1]=a[1];else if(m)for(let u=r.length-1;u>=0&&r[u][0]===a[0];--u)r[u][0]=s[0];else for(let u=r.length-1;u>=0&&r[u][1]===a[1];--u)r[u][1]=s[1];continue}}r.push(s)}return r.push(n[n.length-1]),r},p_=e=>{if(e.length===0)return[];let o=[e[0]];for(let t=1;t<e.length;t++){let[n,r]=o[o.length-1],[i,a]=e[t];(n!==i||r!==a)&&o.push(e[t])}return o},Ov=(e,o,t)=>{if(!u_(e.type,o)){if(!jD())throw Error(`Invalid conversion from ${e.type} to ${o}.`);return e}if(e.type===o)return e;if(o_.delete(e),La(o)){let n=Ma(e_({...e,type:o,roundness:o==="diamond"&&e.roundness?{type:GD(o)?Vd.ADAPTIVE_RADIUS:Vd.PROPORTIONAL_RADIUS}:e.roundness}));return n_(n,t.scene,t.state),n}if(Kd(o))switch(o){case"line":return Ma(t_({...e,type:"line"}));case"sharpArrow":return Ma(Eh({...e,type:"arrow",elbowed:!1,roundness:null,startArrowhead:t.state.currentItemStartArrowhead,endArrowhead:t.state.currentItemEndArrowhead}));case"curvedArrow":return Ma(Eh({...e,type:"arrow",elbowed:!1,roundness:{type:Vd.PROPORTIONAL_RADIUS},startArrowhead:t.state.currentItemStartArrowhead,endArrowhead:t.state.currentItemEndArrowhead}));case"elbowArrow":return Ma(Eh({...e,type:"arrow",elbowed:!0,fixedSegments:null,roundness:null}))}return $D(o,`unhandled conversion type: ${o}`),e},u_=(e,o)=>!!(La(e)&&La(o)||Kd(e)&&Kd(o)),g_=e=>Ch(e)?Pa(e):e.type,Uv=l_;var Yv=O({name:"toggleShapeSwitch",label:"labels.shapeSwitch",icon:()=>null,viewMode:!0,trackEvent:{category:"shape_switch",action:"toggle"},keywords:["change","switch","swap"],perform(e,o,t,n){return ot.set(Do,{type:"panel"}),{captureUpdate:h_.NEVER}},checked:e=>e.gridModeEnabled,predicate:(e,o,t)=>Aa(e)!==null});import{canCreateLinkFromElements as kh,defaultGetElementLinkFromSelection as f_,getLinkIdAndTypeFromSelection as b_}from"@orangecatai/element";import{CaptureUpdateAction as xl}from"@orangecatai/element";var $d=O({name:"copyElementLink",label:"labels.copyElementLink",icon:Zi,trackEvent:{category:"element"},perform:async(e,o,t,n)=>{let r=ne(e,o);try{if(window.location){let i=b_(r,o);return i?(await Lo(n.props.generateLinkForSelection?n.props.generateLinkForSelection(i.id,i.type):f_(i.id,i.type)),{appState:{toast:{message:h("toast.elementLinkCopied"),closable:!0}},captureUpdate:xl.EVENTUALLY}):{appState:o,elements:e,app:n,captureUpdate:xl.EVENTUALLY}}}catch(i){console.error(i)}return{appState:o,elements:e,app:n,captureUpdate:xl.EVENTUALLY}},predicate:(e,o)=>kh(ne(e,o))}),Vv=O({name:"linkToElement",label:"labels.linkToElement",icon:Yc,perform:(e,o,t,n)=>{let r=ne(e,o);return r.length!==1||!kh(r)?{elements:e,appState:o,app:n,captureUpdate:xl.EVENTUALLY}:{appState:{...o,openDialog:{name:"elementLinkSelector",sourceElementId:ne(e,o)[0].id}},captureUpdate:xl.IMMEDIATELY}},predicate:(e,o,t,n)=>{let r=ne(e,o);return o.openDialog?.name!=="elementLinkSelector"&&r.length===1&&kh(r)},trackEvent:!1});import{isDarwin as Kv}from"@orangecatai/common";var x_={toggleTheme:[N("Shift+Alt+D")],saveScene:[N("CtrlOrCmd+S")],loadScene:[N("CtrlOrCmd+O")],clearCanvas:[N("CtrlOrCmd+Delete")],imageExport:[N("CtrlOrCmd+Shift+E")],commandPalette:[N("CtrlOrCmd+/"),N("CtrlOrCmd+Shift+P")],cut:[N("CtrlOrCmd+X")],copy:[N("CtrlOrCmd+C")],paste:[N("CtrlOrCmd+V")],copyStyles:[N("CtrlOrCmd+Alt+C")],pasteStyles:[N("CtrlOrCmd+Alt+V")],selectAll:[N("CtrlOrCmd+A")],deleteSelectedElements:[N("Delete")],duplicateSelection:[N("CtrlOrCmd+D"),N(`Alt+${h("helpDialog.drag")}`)],sendBackward:[N("CtrlOrCmd+[")],bringForward:[N("CtrlOrCmd+]")],sendToBack:[Kv?N("CtrlOrCmd+Alt+["):N("CtrlOrCmd+Shift+[")],bringToFront:[Kv?N("CtrlOrCmd+Alt+]"):N("CtrlOrCmd+Shift+]")],copyAsPng:[N("Shift+Alt+C")],group:[N("CtrlOrCmd+G")],ungroup:[N("CtrlOrCmd+Shift+G")],gridMode:[N("CtrlOrCmd+'")],zenMode:[N("Alt+Z")],objectsSnapMode:[N("Alt+S")],stats:[N("Alt+/")],addToLibrary:[],flipHorizontal:[N("Shift+H")],flipVertical:[N("Shift+V")],viewMode:[N("Alt+R")],hyperlink:[N("CtrlOrCmd+K")],toggleElementLock:[N("CtrlOrCmd+Shift+L")],resetZoom:[N("CtrlOrCmd+0")],zoomOut:[N("CtrlOrCmd+-")],zoomIn:[N("CtrlOrCmd++")],zoomToFitSelection:[N("Shift+3")],zoomToFit:[N("Shift+1")],zoomToFitSelectionInViewport:[N("Shift+2")],toggleEraserTool:[N("E")],toggleHandTool:[N("H")],setFrameAsActiveTool:[N("F")],saveFileToDisk:[N("CtrlOrCmd+S")],saveToActiveFile:[N("CtrlOrCmd+S")],toggleShortcuts:[N("?")],searchMenu:[N("CtrlOrCmd+F")],wrapSelectionInFrame:[],toolLock:[N("Q")]},Be=(e,o=0)=>{let t=x_[e];return t&&t.length>0?t[o]||t[0]:""};var E_="\\u0300-\\u036f",y_="\\ufe20-\\ufe2f",w_="\\u20d0-\\u20ff",v_=E_+y_+w_,T_=`[${v_}]`,I_=RegExp(T_,"g"),C_=/[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g,S_={\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"},li=e=>e.replace(C_,o=>S_[o]||o).replace(I_,"");import GR from"clsx";import{useEffect as UR,useState as WR}from"react";import{KEYS as YR,queryFocusableElements as oT}from"@orangecatai/common";import{useCallback as k_,useState as M_}from"react";var Xv=()=>{let[e,o]=M_(null),t=k_(n=>o(n),[]);return[e,t]};import{useState as j2,useCallback as Zh,useMemo as q2,useEffect as jh,memo as J2,useRef as SR}from"react";import{LIBRARY_DISABLED_TYPES as kR,randomId as MR,isShallowEqual as PR,KEYS as LR,isWritableElement as AR,addEventListener as DR,EVENT as _R,CLASSES as X2}from"@orangecatai/common";import{useEffect as qv,useRef as Jv}from"react";import{URL_HASH_KEYS as Lh,URL_QUERY_KEYS as Ah,APP_NAME as Qv,EVENT as jd,DEFAULT_SIDEBAR as D_,LIBRARY_SIDEBAR_TAB as __,arrayToMap as Dh,cloneJSON as R_,preventUnload as N_,promiseTry as e2,resolvablePromise as B_,toValidURL as F_,Queue as O_,Emitter as z_}from"@orangecatai/common";import{hashElementsVersion as H_,hashString as G_}from"@orangecatai/element";import{getCommonBoundingBox as Ph}from"@orangecatai/element";import{MIME_TYPES as ci}from"@orangecatai/common";var dr=({elements:e,appState:o,files:t,maxWidthOrHeight:n,getDimensions:r,exportPadding:i,exportingFrame:a})=>{let s=Vr(e,null,{deleteInvisibleElements:!0}),l=Bi(o,null),{exportBackground:c,viewBackgroundColor:m}=l;return Ic(s,{...l,offsetTop:0,offsetLeft:0,width:0,height:0},t||{},{exportBackground:c,exportPadding:i,viewBackgroundColor:m,exportingFrame:a},(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),E=n<g?n/g:o?.exportScale??1;return u.width=p*E,u.height=d*E,{canvas:u,scale:E}}let b=r?.(p,d)||{width:p,height:d};return u.width=b.width,u.height=b.height,{canvas:u,scale:b.scale??1}})},$v=async e=>{let{mimeType:o=ci.png,quality:t}=e;o===ci.png&&typeof t=="number"&&console.warn(`"quality" will be ignored for "${ci.png}" mimeType`),o==="image/jpg"&&(o=ci.jpg),o===ci.jpg&&!e.appState?.exportBackground&&(console.warn(`Defaulting "exportBackground" to "true" for "${ci.jpg}" mimeType`),e={...e,appState:{...e.appState,exportBackground:!0}});let n=await dr(e);return t=t||(/image\/jpe?g/.test(o)?.92:.8),new Promise((r,i)=>{n.toBlob(async a=>{if(!a)return i(new Error("couldn't export to blob"));a&&o===ci.png&&e.appState?.exportEmbedScene&&(a=await Bb({blob:a,metadata:Cs(e.elements,e.appState,e.files||{},"local")})),r(a)},o,t)})},Da=async({elements:e,appState:o=Vn(),files:t={},exportPadding:n,renderEmbeddables:r,exportingFrame:i,skipInliningFonts:a,reuseImages:s})=>{let l=Vr(e,null,{deleteInvisibleElements:!0}),m={...Bi(o,null),exportPadding:n};return Ni(l,m,t,{exportingFrame:i,renderEmbeddables:r,skipInliningFonts:a,reuseImages:s})},P_=async e=>{if(e.type==="svg"){let o=await Da(e);await Lo(o.outerHTML)}else if(e.type==="png")await Md($v(e));else if(e.type==="json")await Sd(e.elements,e.files);else throw new Error("Invalid export type")};import{useEffect as Zv,useState as L_}from"react";import{COLOR_PALETTE as A_}from"@orangecatai/common";var Mh=ye(new Map),jv=async e=>await Da({elements:e,appState:{exportBackground:!1,viewBackgroundColor:A_.white},files:null,renderEmbeddables:!1,skipInliningFonts:!0}),Zd=(e,o,t,n)=>{let[r,i]=L_();return Zv(()=>{if(o)if(e){let a=t.get(e);a?i(a):(async()=>{let s=await jv(o);s.querySelector(".style-fonts")?.remove(),s&&(t.set(e,s),i(s))})()}else(async()=>{let a=await jv(o);i(a)})()},[e,o,t,i]),Zv(()=>{let a=n.current;if(a)return r&&(a.innerHTML=r.outerHTML),()=>{a.innerHTML=""}},[r,n]),r},_a=()=>{let[e]=ee(Mh);return{clearLibraryCache:()=>e.clear(),deleteItemsFromLibraryCache:n=>{n.forEach(r=>e.delete(r))},svgCache:e}};var U_=["excalidraw.com","raw.githubusercontent.com/excalidraw/excalidraw-libraries"],o2=new z_,Ln=ye({status:"loaded",isInitialized:!1,libraryItems:[]}),El=e=>R_(e),W_=(e,o)=>!e.find(t=>t.elements.length!==o.elements.length?!1:t.elements.every((n,r)=>n.id===o.elements[r].id&&n.versionNonce===o.elements[r].versionNonce)),n2=(e,o)=>{let t=[];for(let n of o)W_(e,n)&&t.push(n);return[...t,...e]},r2=(e,o)=>{let t=Dh(o),n={deletedItems:new Map,addedItems:new Map,updatedItems:new Map};for(let i of e)t.has(i.id)||n.deletedItems.set(i.id,i);let r=Dh(e);for(let i of o){let a=r.get(i.id);a?Nh(a)!==Nh(i)&&n.updatedItems.set(i.id,i):n.addedItems.set(i.id,i)}return n},_h=class{constructor(o){k(this,"currLibraryItems",[]);k(this,"prevLibraryItems",El(this.currLibraryItems));k(this,"app");k(this,"updateQueue",[]);k(this,"getLastUpdateTask",()=>this.updateQueue[this.updateQueue.length-1]);k(this,"notifyListeners",()=>{if(this.updateQueue.length>0)ot.set(Ln,o=>({status:"loading",libraryItems:this.currLibraryItems,isInitialized:o.isInitialized}));else{ot.set(Ln,{status:"loaded",libraryItems:this.currLibraryItems,isInitialized:!0});try{let o=this.prevLibraryItems;this.prevLibraryItems=El(this.currLibraryItems);let t=El(this.currLibraryItems);this.app.props.onLibraryChange?.(t),o2.trigger(r2(o,t),t)}catch(o){console.error(o)}}});k(this,"destroy",()=>{this.updateQueue=[],this.currLibraryItems=[],ot.set(Mh,new Map)});k(this,"resetLibrary",()=>this.setLibrary([]));k(this,"getLatestLibrary",()=>new Promise(async o=>{try{let t=await(this.getLastUpdateTask()||this.currLibraryItems);this.updateQueue.length>0?o(this.getLatestLibrary()):o(El(t))}catch{return o(this.currLibraryItems)}}));k(this,"updateLibrary",async({libraryItems:o,prompt:t=!1,merge:n=!1,openLibraryMenu:r=!1,defaultStatus:i="unpublished"})=>(r&&this.app.setState({openSidebar:{name:D_.name,tab:__}}),this.setLibrary(()=>new Promise(async(a,s)=>{try{let l=await(typeof o=="function"&&!(o instanceof Blob)?o(this.currLibraryItems):o),c;l instanceof Blob?c=await gu(l,i):c=Ms(l,i),!t||window.confirm(h("alerts.confirmAddLibrary",{numShapes:c.length}))?(t&&this.app.focusContainer(),a(n?n2(this.currLibraryItems,c):c)):s(new _i)}catch(l){s(l)}}))));k(this,"setLibrary",o=>{let t=new Promise(async(n,r)=>{try{await this.getLastUpdateTask(),typeof o=="function"&&(o=o(this.currLibraryItems)),this.currLibraryItems=El(await o),n(this.currLibraryItems)}catch(i){r(i)}}).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!==t),this.notifyListeners()});return this.updateQueue.push(t),this.notifyListeners(),t});this.app=o}},i2=_h,Na=e=>{let t=Math.ceil(Math.sqrt(e.length)),n=[],r=u=>e.slice(u*t,u*t+t).reduce((g,E)=>{let{height:w}=Ph(E.elements);return Math.max(g,w)},0),i=u=>{let b=0,g=0,E=0;for(let w of e){if(b%t===0&&(g=0),g===u){let{width:x}=Ph(w.elements);E=Math.max(E,x)}b++,g++}return E},a=0,s=0,l=0,c=0,m=0,p=0,d=0;for(let u of e){m&&m%t===0&&(s+=l+50,a=0,p=0,d++),p===0&&(l=r(d)),c=i(p);let{minX:b,minY:g,width:E,height:w}=Ph(u.elements),x=(c-E)/2,y=(l-w)/2;n.push(...u.elements.map(v=>({...v,x:v.x+a+x-b,y:v.y+s+y-g}))),a+=c+50,m++,p++}return n},Y_=(e,o=U_)=>{if(typeof o=="function"?o(e):o.some(t=>{let n=new URL(`https://${t.replace(/^https?:\/\//,"")}`),{hostname:r,pathname:i}=new URL(e);return new RegExp(`(^|\\.)${n.hostname}$`).test(r)&&new RegExp(`^${n.pathname.replace(/\/+$/,"")}(/+|$)`).test(i)}))return!0;throw new Error(`Invalid or disallowed library URL: "${e}"`)},Rh=()=>{let e=new URLSearchParams(window.location.hash.slice(1)).get(Lh.addLibrary)||new URLSearchParams(window.location.search).get(Ah.addLibrary),o=e?new URLSearchParams(window.location.hash.slice(1)).get("token"):null;return e?{libraryUrl:e,idToken:o}:null},mr=class mr{constructor(o){k(this,"adapter");this.adapter=o}static async getLibraryItems(o,t,n=!0){let r=()=>new Promise(async(i,a)=>{try{let s=await o.load({source:t});i(Ms(s?.libraryItems||[],"published"))}catch(s){a(s)}});return n?mr.queue.push(r):r()}getLibraryItems(o){return mr.getLibraryItems(this.adapter,o,!1)}};k(mr,"queue",new O_),k(mr,"run",async(o,t)=>{let n=new mr(o);return mr.queue.push(()=>t(n))});var Ra=mr,yl=0,qd=0,Nh=e=>`${e.id}:${e.name||""}:${H_(e.elements)}`,Jd=e=>G_(e.map(o=>Nh(o)).sort().join()),t2=async(e,o)=>{try{return qd++,await Ra.run(e,async t=>{let n=Dh(await t.getLibraryItems("save"));for(let[s]of o.deletedItems)n.delete(s);let r=[];for(let[s,l]of o.addedItems)n.has(s)?n.set(s,l):r.push(l);if(o.updatedItems)for(let[s,l]of o.updatedItems)n.set(s,l);let i=r.concat(Array.from(n.values())),a=Jd(i);return a!==yl&&await e.save({libraryItems:i}),yl=a,i})}finally{qd--}},V_=e=>{let{excalidrawAPI:o}=e,t=Jv(e);t.current=e;let n=Jv(!1);qv(()=>{if(!o)return;n.current=!1;let r=async({libraryUrl:s,idToken:l})=>{let c=new Promise(async(p,d)=>{try{s=decodeURIComponent(s),s=F_(s),Y_(s,t.current.validateLibraryUrl);let b=await(await fetch(s)).blob();p(b)}catch(u){d(u)}}),m=l!==o.id;await(m&&document.hidden?new Promise(p=>{window.addEventListener("focus",()=>p(),{once:!0})}):null);try{await o.updateLibrary({libraryItems:c,prompt:m,merge:!0,defaultStatus:"published",openLibraryMenu:!0})}catch(p){throw o.updateScene({appState:{errorMessage:p.message}}),p}finally{if(window.location.hash.includes(Lh.addLibrary)){let p=new URLSearchParams(window.location.hash.slice(1));p.delete(Lh.addLibrary),window.history.replaceState({},Qv,`#${p.toString()}`)}else if(window.location.search.includes(Ah.addLibrary)){let p=new URLSearchParams(window.location.search);p.delete(Ah.addLibrary),window.history.replaceState({},Qv,`?${p.toString()}`)}}},i=s=>{s.preventDefault();let l=Rh();l&&(s.stopImmediatePropagation(),window.history.replaceState({},"",s.oldURL),r(l))},a=Rh();if(a&&r(a),"getInitialLibraryItems"in t.current&&t.current.getInitialLibraryItems&&(console.warn("useHandleLibrar `opts.getInitialLibraryItems` is deprecated. Use `opts.adapter` instead."),Promise.resolve(t.current.getInitialLibraryItems()).then(s=>{o.updateLibrary({libraryItems:s,merge:!0})}).catch(s=>{console.error(`UseHandeLibrary getInitialLibraryItems failed: ${s?.message}`)})),"adapter"in t.current&&t.current.adapter){let s=t.current.adapter,l=t.current.migrationAdapter,c=B_();l?c.resolve(e2(l.load).then(async m=>{let p=null;try{if(!m)return Ra.getLibraryItems(s,"load");p=Ms(m.libraryItems||[],"published");let d=await t2(s,r2([],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}`),Ra.getLibraryItems(s,"load")))):c.resolve(e2(Ra.getLibraryItems,s,"load")),o.updateLibrary({libraryItems:c.then(m=>{let p=m||[];return yl=Jd(p),p}),merge:!0}).finally(()=>{n.current=!0})}return window.addEventListener(jd.HASHCHANGE,i),()=>{window.removeEventListener(jd.HASHCHANGE,i)}},[o]),qv(()=>{let r=o2.on(async(a,s)=>{let l=n.current,c="adapter"in t.current&&t.current.adapter||null;try{c&&yl!==Jd(s)&&await t2(c,a)}catch(m){console.error(`couldn't persist library update: ${m.message}`,a),l&&t.current.excalidrawAPI&&t.current.excalidrawAPI.updateScene({appState:{errorMessage:h("errors.saveLibraryError")}})}}),i=a=>{qd&&N_(a)};return window.addEventListener(jd.BEFORE_UNLOAD,i),()=>{window.removeEventListener(jd.BEFORE_UNLOAD,i),r(),yl=0,qd=0}},[])};import Z_ from"clsx";import{VERSIONS as K_}from"@orangecatai/common";import{jsx as $_}from"react/jsx-runtime";var X_=({theme:e,id:o,libraryReturnUrl:t})=>{let n=t||window.location.origin+window.location.pathname;return $_("a",{className:"library-menu-browse-button",href:`${I.VITE_APP_LIBRARY_URL}?target=${window.name||"_blank"}&referrer=${n}&useHash=true&token=${o}&theme=${e}&version=${K_.excalidrawLibrary}`,target:"_excalidraw_libraries",children:h("labels.libraries")})},a2=X_;import{jsx as j_,jsxs as q_}from"react/jsx-runtime";var Qd=({libraryReturnUrl:e,theme:o,id:t,style:n,children:r,className:i})=>q_("div",{className:Z_("library-menu-control-buttons",i),style:n,children:[j_(a2,{id:t,libraryReturnUrl:e,theme:o}),r]});import{useCallback as Oa,useEffect as Vh,useMemo as Kh,useRef as Y2,useState as V2}from"react";import{MIME_TYPES as ER,arrayToMap as yR,nextAnimationFrame as wR}from"@orangecatai/common";import{duplicateElements as vR}from"@orangecatai/element";import TR from"clsx";import J_ from"lodash.throttle";import{useEffect as Q_}from"react";var e7=ye(0),s2=e=>{let[o,t]=ee(e7);return Q_(()=>{let{current:n}=e;if(!n)return;let r=J_(()=>{let{scrollTop:i}=n;t(i)},200);return n.addEventListener("scroll",r),()=>{r.cancel(),n.removeEventListener("scroll",r)}},[e,t]),o};import Z7 from"clsx";import{useCallback as j7,useState as Uh}from"react";import{muteFSAbortError as q7}from"@orangecatai/common";import{flushSync as l2}from"react-dom";import t7 from"clsx";import{jsx as em,jsxs as n7}from"react/jsx-runtime";var o7=({label:e,onClick:o,className:t,children:n,actionType:r,type:i="button",isLoading:a,...s})=>{let l=r?`Dialog__action-button--${r}`:"";return n7("button",{className:t7("Dialog__action-button",l,t),type:i,"aria-label":e,onClick:o,...s,children:[n&&em("div",{style:a?{visibility:"hidden"}:{},children:n}),em("div",{style:a?{visibility:"hidden"}:{},children:e}),a&&em("div",{style:{position:"absolute",inset:0},children:em(wt,{})})]})},An=o7;import{jsx as c2,jsxs as d2}from"react/jsx-runtime";var r7=e=>{let{onConfirm:o,onCancel:t,children:n,confirmText:r=h("buttons.confirm"),cancelText:i=h("buttons.cancel"),className:a="",...s}=e,l=be(),c=Yo(Ba),{container:m}=Oe();return d2(Qe,{onCloseRequest:t,size:"small",...s,className:`confirm-dialog ${a}`,children:[n,d2("div",{className:"confirm-dialog-buttons",children:[c2(An,{label:i,onClick:()=>{l({openMenu:null}),c(!1),l2(()=>{t()}),m?.focus()}}),c2(An,{label:r,onClick:()=>{l({openMenu:null}),c(!1),l2(()=>{o()}),m?.focus()},actionType:"danger"})]})]})},tm=r7;import{useCallback as m7,useEffect as Oh,useRef as m2,useState as Bh}from"react";import{EDITOR_LS_KEYS as Fh,EXPORT_DATA_TYPES as p7,MIME_TYPES as p2,VERSIONS as u7,chunk as g7,getExportSource as h7}from"@orangecatai/common";var po=class{static has(o){try{return!!window.localStorage.getItem(o)}catch(t){return console.warn(`localStorage.getItem error: ${t.message}`),!1}}static get(o){try{let t=window.localStorage.getItem(o);return t?JSON.parse(t):null}catch(t){return console.warn(`localStorage.getItem error: ${t.message}`),null}}};k(po,"set",(o,t)=>{try{return window.localStorage.setItem(o,JSON.stringify(t)),!0}catch(n){return console.warn(`localStorage.setItem error: ${n.message}`),!1}}),k(po,"delete",o=>{try{window.localStorage.removeItem(o)}catch(t){console.warn(`localStorage.removeItem error: ${t.message}`)}});import om from"react";var i7=/({{[\w-]+}})|(<[\w-]+>)|(<\/[\w-]+>)/g,a7=/{{([\w-]+)}}/,s7=/<([\w-]+)>/,l7=/<\/([\w-]+)>/,c7=(e,o)=>{let t=[{name:"",children:[]}];return e.split(i7).filter(Boolean).forEach(n=>{let r=n.match(s7),i=n.match(l7),a=n.match(a7);if(r!==null){let s=r[1];o.hasOwnProperty(s)?t.push({name:s,children:[]}):console.warn(`Trans: missed to pass in prop ${s} for interpolating ${e}`)}else if(i!==null)if(i[1]===t[t.length-1].name){let l=t.pop(),c=om.createElement(om.Fragment,{},...l.children),m=o[l.name];typeof m=="function"&&t[t.length-1].children.push(m(c))}else console.warn(`Trans: unexpected end tag ${n} for interpolating ${e}`);else if(a!==null){let s=a[1];o.hasOwnProperty(s)?t[t.length-1].children.push(o[s]):console.warn(`Trans: key ${s} not in props for interpolating ${e}`)}else t[t.length-1].children.push(n)}),t.length!==1&&console.warn(`Trans: stack not empty for interpolating ${e}`),t[0].children},d7=({i18nKey:e,children:o,...t})=>{let{t:n}=Ae();return om.createElement(om.Fragment,{},...c7(n(e),t))},Bt=d7;import{jsx as we,jsxs as Ct}from"react/jsx-runtime";var f7=async e=>{let n=Math.round(8),r=Math.max(Math.round(128/64),2),i=g7(e,6),a=document.createElement("canvas");a.width=i[0].length*128+(i[0].length+1)*(n*2)-n*2,a.height=i.length*128+(i.length+1)*(n*2)-n*2;let s=a.getContext("2d");s.fillStyle="#fff",s.fillRect(0,0,a.width,a.height);for(let[l,c]of e.entries()){let m=await dr({elements:c.elements,files:null,maxWidthOrHeight:128}),{width:p,height:d}=m,u=Math.floor(l/6)*(128+n*2),b=l%6*(128+n*2);s.drawImage(m,b+(128-p)/2+n,u+(128-d)/2+n),s.lineWidth=r,s.strokeStyle="#ced4da",s.strokeRect(b+n/2,u+n/2,128+n,128+n)}return await kc(new File([await Kr(a)],"preview",{type:p2.png}),{outputType:p2.jpg,maxWidthOrHeight:5e3})},b7=({libItem:e,appState:o,index:t,onChange:n,onRemove:r})=>{let i=m2(null),a=m2(null);return Oh(()=>{let s=i.current;s&&(async()=>{let l=await Da({elements:e.elements,appState:{...o,viewBackgroundColor:"#fff",exportBackground:!0},files:null,skipInliningFonts:!0});s.innerHTML=l.outerHTML})()},[e.elements,o]),Ct("div",{className:"single-library-item",children:[e.status==="published"&&we("span",{className:"single-library-item-status",children:h("labels.statusPublished")}),we("div",{ref:i,className:"single-library-item__svg"}),we(Q,{"aria-label":h("buttons.remove"),type:"button",icon:io,className:"single-library-item--remove",onClick:r.bind(null,e.id),title:h("buttons.remove")}),Ct("div",{style:{display:"flex",margin:"0.8rem 0",width:"100%",fontSize:"14px",fontWeight:500,flexDirection:"column"},children:[Ct("label",{style:{display:"flex",justifyContent:"space-between",flexDirection:"column"},children:[Ct("div",{style:{padding:"0.5em 0"},children:[we("span",{style:{fontWeight:500,color:"#868e96"},children:h("publishDialog.itemName")}),we("span",{"aria-hidden":"true",className:"required",children:"*"})]}),we("input",{type:"text",ref:a,style:{width:"80%",padding:"0.2rem"},defaultValue:e.name,placeholder:"Item name",onChange:s=>{n(s.target.value,t)}})]}),we("span",{className:"error",children:e.error})]})]})},x7=({onClose:e,libraryItems:o,appState:t,onSuccess:n,onError:r,updateItemsInStorage:i,onRemove:a})=>{let[s,l]=Bh({authorName:"",githubHandle:"",name:"",description:"",twitterHandle:"",website:""}),[c,m]=Bh(!1);Oh(()=>{let y=po.get(Fh.PUBLISH_LIBRARY);y&&l(y)},[]);let[p,d]=Bh(o.slice());Oh(()=>{d(o.slice())},[o]);let u=y=>{l({...s,[y.target.name]:y.target.value})},b=async y=>{y.preventDefault(),m(!0);let v=[],T=!1;if(p.forEach(P=>{let A="";P.name||(A=h("publishDialog.errors.required"),T=!0),v.push({...P,error:A})}),T){d(v),m(!1);return}let C=await f7(p),M={type:p7.excalidrawLibrary,version:u7.excalidrawLibrary,source:h7(),libraryItems:p},S=JSON.stringify(M,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(`${I.VITE_APP_LIBRARY_BACKEND}/submit`,{method:"post",body:_}).then(P=>P.ok?P.json().then(({url:A})=>{po.delete(Fh.PUBLISH_LIBRARY),n({url:A,authorName:s.authorName,items:p})}):P.json().catch(()=>{throw new Error(P.statusText||"something went wrong")}).then(A=>{throw new Error(A.message||P.statusText||"something went wrong")}),P=>{console.error(P),r(P),m(!1)}).catch(P=>{console.error(P),r(P),m(!1)})},g=()=>{let y=[];return p.forEach((v,T)=>{y.push(we("div",{className:"single-library-item-wrapper",children:we(b7,{libItem:v,appState:t,index:T,onChange:(C,M)=>{let S=p.slice();S[M].name=C,d(S)},onRemove:a})},T))}),we("div",{className:"selected-library-items",children:y})},E=m7(()=>{i(p),po.set(Fh.PUBLISH_LIBRARY,s),e()},[p,e,i,s]),w=!!o.length,x=o.some(y=>y.status==="published");return we(Qe,{onCloseRequest:E,title:h("publishDialog.title"),className:"publish-library",children:w?Ct("form",{onSubmit:b,children:[we("div",{className:"publish-library-note",children:we(Bt,{i18nKey:"publishDialog.noteDescription",link:y=>we("a",{href:"https://libraries.excalidraw.com",target:"_blank",rel:"noopener",children:y})})}),we("span",{className:"publish-library-note",children:we(Bt,{i18nKey:"publishDialog.noteGuidelines",link:y=>we("a",{href:"https://github.com/excalidraw/excalidraw-libraries#guidelines",target:"_blank",rel:"noopener noreferrer",children:y})})}),we("div",{className:"publish-library-note",children:h("publishDialog.noteItems")}),x&&we("span",{className:"publish-library-note publish-library-warning",children:h("publishDialog.republishWarning")}),g(),Ct("div",{className:"publish-library__fields",children:[Ct("label",{children:[Ct("div",{children:[we("span",{children:h("publishDialog.libraryName")}),we("span",{"aria-hidden":"true",className:"required",children:"*"})]}),we("input",{type:"text",name:"name",required:!0,value:s.name,onChange:u,placeholder:h("publishDialog.placeholder.libraryName")})]}),Ct("label",{style:{alignItems:"flex-start"},children:[Ct("div",{children:[we("span",{children:h("publishDialog.libraryDesc")}),we("span",{"aria-hidden":"true",className:"required",children:"*"})]}),we("textarea",{name:"description",rows:4,required:!0,value:s.description,onChange:u,placeholder:h("publishDialog.placeholder.libraryDesc")})]}),Ct("label",{children:[Ct("div",{children:[we("span",{children:h("publishDialog.authorName")}),we("span",{"aria-hidden":"true",className:"required",children:"*"})]}),we("input",{type:"text",name:"authorName",required:!0,value:s.authorName,onChange:u,placeholder:h("publishDialog.placeholder.authorName")})]}),Ct("label",{children:[we("span",{children:h("publishDialog.githubUsername")}),we("input",{type:"text",name:"githubHandle",value:s.githubHandle,onChange:u,placeholder:h("publishDialog.placeholder.githubHandle")})]}),Ct("label",{children:[we("span",{children:h("publishDialog.twitterUsername")}),we("input",{type:"text",name:"twitterHandle",value:s.twitterHandle,onChange:u,placeholder:h("publishDialog.placeholder.twitterHandle")})]}),Ct("label",{children:[we("span",{children:h("publishDialog.website")}),we("input",{type:"text",name:"website",pattern:"https?://.+",title:h("publishDialog.errors.website"),value:s.website,onChange:u,placeholder:h("publishDialog.placeholder.website")})]}),we("span",{className:"publish-library-note",children:we(Bt,{i18nKey:"publishDialog.noteLicense",link:y=>we("a",{href:"https://github.com/excalidraw/excalidraw-libraries/blob/main/LICENSE",target:"_blank",rel:"noopener noreferrer",children:y})})})]}),Ct("div",{className:"publish-library__buttons",children:[we(An,{label:h("buttons.saveLibNames"),onClick:E,"data-testid":"cancel-clear-canvas-button"}),we(An,{type:"submit",label:h("buttons.submit"),actionType:"primary",isLoading:c})]})]}):we("p",{style:{padding:"1em",textAlign:"center",fontWeight:500},children:h("publishDialog.atleastOneLibItem")})})},u2=x7;import F2 from"react";import{DropdownMenu as V7}from"radix-ui";import{CLASSES as K7}from"@orangecatai/common";import w7 from"clsx";import{useCallback as v7,useEffect as T7,useRef as I7}from"react";import{CLASSES as C7,EVENT as b2,KEYS as S7}from"@orangecatai/common";import{DropdownMenu as k7}from"radix-ui";import{forwardRef as g2}from"react";import h2 from"clsx";import{jsx as f2}from"react/jsx-runtime";var E7=g2(({children:e,gap:o,align:t,justifyContent:n,className:r,style:i},a)=>f2("div",{className:h2("Stack Stack_horizontal",r),style:{"--gap":o,alignItems:t,justifyContent:n,...i},ref:a,children:e})),y7=g2(({children:e,gap:o,align:t,justifyContent:n,className:r,style:i},a)=>f2("div",{className:h2("Stack Stack_vertical",r),style:{"--gap":o,justifyItems:t,justifyContent:n,...i},ref:a,children:e})),St={Row:E7,Col:y7};import{jsx as nm}from"react/jsx-runtime";var x2=({children:e,onClickOutside:o,className:t="",onSelect:n,open:r=!0,align:i="end",style:a})=>{let s=fe(),l=I7(null),c=Zn({onClickOutside:o});ra(l,v7(p=>{l.current?.closest(`.${C7.DROPDOWN_MENU_EVENT_WRAPPER}`)?.contains(p.target)||c.onClickOutside?.()},[c])),T7(()=>{if(!r)return;let p=u=>{u.key===S7.ESCAPE&&(u.stopImmediatePropagation(),c.onClickOutside?.())},d={capture:!0};return document.addEventListener(b2.KEYDOWN,p,d),()=>{document.removeEventListener(b2.KEYDOWN,p,d)}},[c,r]);let m=w7(`dropdown-menu ${t}`,{"dropdown-menu--mobile":s.formFactor==="phone"}).trim();return nm(pg.Provider,{value:{onSelect:n},children:nm(k7.Content,{ref:l,className:m,style:a,"data-testid":"dropdown-menu",align:i,sideOffset:8,onCloseAutoFocus:p=>p.preventDefault(),children:s.formFactor==="phone"?nm(St.Col,{className:"dropdown-menu-container",children:e}):nm(qe,{className:"dropdown-menu-container",padding:2,children:e})})})};x2.displayName="DropdownMenuContent";var E2=x2;import{jsx as P7}from"react/jsx-runtime";var M7=({children:e,className:o="",selected:t,...n})=>P7("div",{...n,className:`dropdown-menu-item-base dropdown-menu-item-custom ${o} ${t?"dropdown-menu-item--selected":""}`.trim(),children:e}),y2=M7;import{DropdownMenu as L7}from"radix-ui";import{jsx as zh}from"react/jsx-runtime";var w2=({icon:e,shortcut:o,href:t,children:n,onSelect:r,className:i="",selected:a,rel:s="noopener",...l})=>{let c=ld(r);return zh(L7.Item,{className:"radix-menu-item",onSelect:c,asChild:!0,children:zh("a",{...l,href:t,target:"_blank",rel:`noopener ${s}`,className:tr(i,a),title:l.title??l["aria-label"],children:zh(or,{icon:e,shortcut:o,children:n})})})},Fa=w2;w2.displayName="DropdownMenuItemLink";import{jsx as A7}from"react/jsx-runtime";var v2=()=>A7("div",{style:{height:"1px",backgroundColor:"var(--default-border-color)",margin:"6px 0",flex:"0 0 auto"}}),T2=v2;v2.displayName="DropdownMenuSeparator";import{DropdownMenu as O7}from"radix-ui";import D7 from"clsx";import{DropdownMenu as _7}from"radix-ui";import{useCallback as R7,useState as I2}from"react";import{jsx as Gh}from"react/jsx-runtime";var Hh=-4,N7=4,C2=({children:e,className:o})=>{let t=fe(),n=D7(`dropdown-menu dropdown-submenu ${o}`,{"dropdown-menu--mobile":t.formFactor==="phone"}).trim(),r=R7(c=>{if(c){let p=c.closest(".dropdown-menu-container")?.getBoundingClientRect();if(p){let d=c.getBoundingClientRect().width,b=window.innerWidth-p.right;b<d+20&&(a(b-d+Hh),l(Hh+8))}}},[]),[i,a]=I2(N7),[s,l]=I2(Hh);return Gh(_7.SubContent,{className:n,sideOffset:i,alignOffset:s,collisionPadding:8,ref:r,children:t.formFactor==="phone"?Gh(St.Col,{className:"dropdown-menu-container",children:e}):Gh(qe,{className:"dropdown-menu-container",padding:2,style:{zIndex:1},children:e})})},S2=C2;C2.displayName="DropdownMenuSubContent";import{DropdownMenu as B7}from"radix-ui";import{jsx as k2,jsxs as F7}from"react/jsx-runtime";var M2=({children:e,icon:o,shortcut:t,className:n})=>F7(B7.SubTrigger,{className:`${tr(n)} dropdown-menu__submenu-trigger`,children:[k2(or,{icon:o,shortcut:t,children:e}),k2("div",{className:"dropdown-menu__submenu-trigger-icon",children:GE})]}),P2=M2;M2.displayName="DropdownMenuSubTrigger";import L2 from"react";var rm=e=>o=>{let t=L2.Children.toArray(o).find(n=>L2.isValidElement(n)&&typeof n.type!="string"&&n?.type.displayName&&n.type.displayName===e);return t||null},A2=rm("DropdownMenuTrigger"),D2=rm("DropdownMenuContent"),_2=rm("DropdownMenuSubTrigger"),R2=rm("DropdownMenuSubContent");import{jsxs as z7}from"react/jsx-runtime";var im=({children:e})=>{let o=_2(e),t=R2(e);return z7(O7.Sub,{children:[o,t]})};im.Trigger=P2;im.Content=S2;im.displayName="DropdownMenuSub";var pr=im;import H7 from"clsx";import{DropdownMenu as G7}from"radix-ui";import{jsx as U7}from"react/jsx-runtime";var N2=({className:e="",children:o,onToggle:t,title:n,...r})=>{let i=fe(),a=H7(`dropdown-menu-button ${e}`,"zen-mode-transition",{"dropdown-menu-button--mobile":i.formFactor==="phone"}).trim();return U7(G7.Trigger,{className:a,onClick:t,type:"button","data-testid":"dropdown-menu-button",title:n,...r,children:o})},B2=N2;N2.displayName="DropdownMenuTrigger";import{jsx as Y7}from"react/jsx-runtime";var W7=e=>Y7(At,{...e,icon:e.checked?Nc:HE}),Dn=W7;import{jsx as $7,jsxs as X7}from"react/jsx-runtime";var _o=({children:e,open:o})=>{let t=A2(e),n=D2(e),r=n&&F2.isValidElement(n)?F2.cloneElement(n,{open:o}):n;return $7(V7.Root,{open:o,modal:!1,children:X7("div",{className:K7.DROPDOWN_MENU_EVENT_WRAPPER,style:{display:"contents"},children:[t,r]})})};_o.Trigger=B2;_o.Content=E2;_o.Item=At;_o.ItemCheckbox=Dn;_o.ItemLink=Fa;_o.ItemCustom=y2;_o.Group=Ks;_o.Separator=T2;_o.Sub=pr;var se=_o;_o.displayName="DropdownMenu";import{jsx as Wt,jsxs as am}from"react/jsx-runtime";var J7=(e,o)=>e.filter(t=>o.includes(t.id)),Q7=({setAppState:e,selectedItems:o,library:t,onRemoveFromLibrary:n,resetLibrary:r,onSelectItems:i,appState:a,className:s})=>{let[l]=ee(Ln),[c,m]=ee(Ba),p=()=>{let _=o.length?h("alerts.removeItemsFromsLibrary",{count:o.length}):h("alerts.resetLibrary"),P=o.length?h("confirmDialog.removeItemsFromLib"):h("confirmDialog.resetLibrary");return Wt(tm,{onConfirm:()=>{o.length?n():r(),u(!1)},onCancel:()=>{u(!1)},title:P,children:Wt("p",{children:_})})},[d,u]=Uh(!1),b=!!o.length,g=b?l.libraryItems.filter(_=>o.includes(_.id)):l.libraryItems,E=b?h("buttons.remove"):h("buttons.resetLibrary"),[w,x]=Uh(!1),[y,v]=Uh(null),T=j7(()=>am(Qe,{onCloseRequest:()=>v(null),title:h("publishSuccessDialog.title"),className:"publish-library-success",size:"small",children:[Wt("p",{children:Wt(Bt,{i18nKey:"publishSuccessDialog.content",authorName:y.authorName,link:_=>Wt("a",{href:y?.url,target:"_blank",rel:"noopener noreferrer",children:_})})}),Wt(Q,{type:"button",title:h("buttons.close"),"aria-label":h("buttons.close"),label:h("buttons.close"),onClick:()=>v(null),"data-testid":"publish-library-success-close",className:"publish-library-success-close"})]}),[v,y]),C=(_,P)=>{x(!1),v({url:_.url,authorName:_.authorName});let A=P.slice();A.forEach(z=>{o.includes(z.id)&&(z.status="published")}),t.setLibrary(A)},M=async()=>{try{await t.updateLibrary({libraryItems:Ec({description:"Excalidraw library files"}),merge:!0,openLibraryMenu:!0})}catch(_){if(_?.name==="AbortError"){console.warn(_);return}e({errorMessage:h("errors.importLibraryError")})}},S=async()=>{let _=b?g:await t.getLatestLibrary();Lb(_).catch(q7).catch(P=>{e({errorMessage:P.message})})},D=()=>am(se,{open:c,children:[Wt(se.Trigger,{onToggle:()=>m(!c),children:Qb}),am(se.Content,{onClickOutside:()=>m(!1),onSelect:()=>m(!1),className:"library-menu",children:[!b&&Wt(se.Item,{onSelect:M,icon:Xi,"data-testid":"lib-dropdown--load",children:h("buttons.load")}),!!g.length&&Wt(se.Item,{onSelect:S,icon:Zr,"data-testid":"lib-dropdown--export",children:h("buttons.export")}),b&&Wt(se.Item,{icon:sE,onSelect:()=>x(!0),"data-testid":"lib-dropdown--remove",children:h("buttons.publishLibrary")}),!!g.length&&Wt(se.Item,{onSelect:()=>u(!0),icon:yt,children:E})]})]});return am("div",{className:Z7("library-menu-dropdown-container",s),children:[D(),o.length>0&&Wt("div",{className:"library-actions-counter",children:o.length}),d&&p(),w&&Wt(u2,{onClose:()=>x(!1),libraryItems:J7(l.libraryItems,o),appState:a,onSuccess:_=>C(_,l.libraryItems),onError:_=>window.alert(_),updateItemsInStorage:()=>t.setLibrary(l.libraryItems),onRemove:_=>i(o.filter(P=>P!==_))}),y&&T()]})},O2=({selectedItems:e,onSelectItems:o,className:t})=>{let{library:n}=ze(),{clearLibraryCache:r,deleteItemsFromLibraryCache:i}=_a(),a=he(),s=be(),[l]=ee(Ln),c=async p=>{let d=p.filter(u=>!e.includes(u.id));n.setLibrary(d).catch(()=>{s({errorMessage:h("alerts.errorRemovingFromLibrary")})}),i(e),o([])};return Wt(Q7,{appState:a,setAppState:s,selectedItems:e,onSelectItems:o,library:n,onRemoveFromLibrary:()=>c(l.libraryItems),resetLibrary:()=>{n.resetLibrary(),r()},className:t})};import{memo as sR,useEffect as lR,useState as cR}from"react";import eR,{useCallback as tR}from"react";function oR(){return[!1,tR(o=>o(),[])]}var z2=eR.useTransition||oR;import H2 from"clsx";import{memo as nR,useRef as rR,useState as iR}from"react";import{jsx as sm,jsxs as aR}from"react/jsx-runtime";var G2=nR(({id:e,elements:o,isPending:t,onClick:n,selected:r,onToggle:i,onDrag:a,svgCache:s})=>{let l=rR(null),c=Zd(e,o,s,l),[m,p]=iR(!1),d=fe().formFactor==="phone",u=t&&sm("div",{className:"library-unit__adder",children:Jb});return aR("div",{className:H2("library-unit",{"library-unit__active":o,"library-unit--hover":o&&m,"library-unit--selected":r,"library-unit--skeleton":!c}),onMouseEnter:()=>p(!0),onMouseLeave:()=>p(!1),children:[sm("div",{className:H2("library-unit__dragger",{"library-unit__pulse":!!t}),ref:l,draggable:!!o,onClick:o||t?b=>{e&&b.shiftKey?i(e,b):n(e)}:void 0,onDragStart:b=>{if(!e){b.preventDefault();return}p(!1),a(e,b)}}),u,e&&o&&(m||d||r)&&sm(el,{checked:r,onChange:(b,g)=>i(e,g),className:"library-unit__checkbox"})]})}),U2=()=>sm("div",{className:"library-unit library-unit--skeleton"});import{Fragment as dR,jsx as lm}from"react/jsx-runtime";var cm=({children:e})=>lm("div",{className:"library-menu-items-container__grid",children:e}),wl=sR(({items:e,onItemSelectToggle:o,onItemDrag:t,isItemSelected:n,onClick:r,svgCache:i,itemsRenderedPerBatch:a})=>{let[,s]=z2(),[l,c]=cR(0);return lR(()=>{l<e.length&&s(()=>{c(l+a)})},[l,e.length,s,a]),lm(dR,{children:e.map((m,p)=>p<l?lm(G2,{elements:m?.elements,isPending:!m?.id&&!!m?.elements,onClick:r,svgCache:i,id:m?.id,selected:n(m.id),onToggle:o,onDrag:t},m?.id??p):lm(U2,{},p))})});import Wh from"clsx";import{forwardRef as gR,useRef as hR,useImperativeHandle as fR,useLayoutEffect as bR,useState as xR}from"react";import mR from"clsx";import{composeEventHandlers as pR}from"@orangecatai/common";import{jsx as uR}from"react/jsx-runtime";var Ft=({type:e="button",onSelect:o,selected:t,children:n,className:r="",...i})=>uR("button",{onClick:pR(i.onClick,a=>{o()}),type:e,className:mR("excalidraw-button",r,{selected:t}),...i,children:n});import{jsx as Yh,jsxs as W2}from"react/jsx-runtime";var ur=gR(({onChange:e,label:o,fullWidth:t,placeholder:n,readonly:r,selectOnRender:i,onKeyDown:a,isRedacted:s=!1,icon:l,className:c,type:m,...p},d)=>{let u=hR(null);fR(d,()=>u.current),bR(()=>{i&&(u.current?.focus(),u.current?.select())},[i]);let[b,g]=xR(!1);return W2("div",{className:Wh("ExcTextField",c,{"ExcTextField--fullWidth":t,"ExcTextField--hasIcon":!!l}),onClick:()=>{u.current?.focus()},children:[l,o&&Yh("div",{className:"ExcTextField__label",children:o}),W2("div",{className:Wh("ExcTextField__input",{"ExcTextField__input--readonly":r}),children:[Yh("input",{className:Wh({"is-redacted":"value"in p&&p.value&&s&&!b}),readOnly:r,value:"value"in p?p.value:void 0,defaultValue:"defaultValue"in p?p.defaultValue:void 0,placeholder:n,ref:u,onChange:E=>e?.(E.target.value),onKeyDown:a,type:m}),s&&Yh(Ft,{onSelect:()=>g(!b),style:{border:0,userSelect:"none"},children:b?hE:qi})]})]})});import{Fragment as K2,jsx as gt,jsxs as tn}from"react/jsx-runtime";var IR=17,CR=64;function Xh({isLoading:e,libraryItems:o,onAddToLibrary:t,onInsertLibraryItems:n,pendingElements:r,theme:i,id:a,libraryReturnUrl:s,onSelectItems:l,selectedItems:c}){let m=fe(),p=Y2(null),d=s2(p);Vh(()=>{d>0&&p.current?.scrollTo(0,d)},[]);let{svgCache:u}=_a(),[b,g]=V2(null),[E,w]=V2(""),x=!o.length&&!r.length,y=!x&&!!E.trim(),v=Kh(()=>{let R=li(E.trim().toLowerCase());return R?o.filter(F=>{let K=F.name||"";return K.trim()&&li(K.toLowerCase()).includes(R)}):[]},[o,E]),T=Kh(()=>o.filter(R=>R.status!=="published"),[o]),C=Kh(()=>o.filter(R=>R.status==="published"),[o]),M=Oa((R,F)=>{let K=!c.includes(R),J=[...T,...C];if(K){if(F.shiftKey&&b){let Z=J.findIndex(st=>st.id===b),le=J.findIndex(st=>st.id===R);if(Z===-1||le===-1){l([...c,R]);return}let Ee=yR(c),ue=Math.min(Z,le),_e=Math.max(Z,le),et=J.reduce((st,Tt,Zt)=>((Zt>=ue&&Zt<=_e||Ee.has(Tt.id))&&st.push(Tt.id),st),[]);l(et)}else l([...c,R]);g(R)}else g(null),l(c.filter(Z=>Z!==R))},[b,l,C,c,T]);Vh(()=>{c.length||g(null)},[c]);let S=Oa(R=>{let F;return c.includes(R)?F=o.filter(K=>c.includes(K.id)):F=o.filter(K=>K.id===R),F.map(K=>({...K,elements:vR({type:"everything",elements:K.elements,randomizeSeed:!0}).duplicatedElements}))},[o,c]),D=Oa((R,F)=>{let K={itemIds:c.includes(R)?c:[R]};F.dataTransfer.setData(ER.excalidrawlibIds,JSON.stringify(K))},[c]),_=Oa(R=>R?c.includes(R):!1,[c]),P=Oa(()=>{t(r)},[r,t]),A=Oa(R=>{R&&n(S(R))},[S,n]),z=u.size>=(v.length?v:o).length?CR:IR,V=Y2(null);Vh(()=>{wR(()=>{V.current?.focus()})},[]);let G=!y&&tn(K2,{children:[!x&>("div",{className:"library-menu-items-container__header",children:h("labels.personalLib")}),!r.length&&!T.length?tn("div",{className:"library-menu-items__no-items",children:[!C.length&>("div",{className:"library-menu-items__no-items__label",children:h("library.noItems")}),gt("div",{className:"library-menu-items__no-items__hint",children:C.length>0?h("library.hint_emptyPrivateLibrary"):h("library.hint_emptyLibrary")})]}):tn(cm,{children:[r.length>0&>(wl,{itemsRenderedPerBatch:z,items:[{id:null,elements:r}],onItemSelectToggle:M,onItemDrag:D,onClick:P,isItemSelected:_,svgCache:u}),gt(wl,{itemsRenderedPerBatch:z,items:T,onItemSelectToggle:M,onItemDrag:D,onClick:A,isItemSelected:_,svgCache:u})]}),C.length>0&>("div",{className:"library-menu-items-container__header",style:{marginTop:"0.75rem"},children:h("labels.excalidrawLib")}),C.length>0&>(cm,{children:gt(wl,{itemsRenderedPerBatch:z,items:C,onItemSelectToggle:M,onItemDrag:D,onClick:A,isItemSelected:_,svgCache:u})})]}),Y=y&&tn(K2,{children:[tn("div",{className:"library-menu-items-container__header",children:[h("library.search.heading"),!e&&tn("div",{className:"library-menu-items-container__header__hint",style:{cursor:"pointer"},onPointerDown:R=>R.preventDefault(),onClick:R=>{w("")},children:[gt("kbd",{children:"esc"})," to clear"]})]}),v.length>0?gt(cm,{children:gt(wl,{itemsRenderedPerBatch:z,items:v,onItemSelectToggle:M,onItemDrag:D,onClick:A,isItemSelected:_,svgCache:u})}):tn("div",{className:"library-menu-items__no-items",children:[gt("div",{className:"library-menu-items__no-items__hint",children:h("library.search.noResults")}),gt(Ft,{onPointerDown:R=>R.preventDefault(),onSelect:()=>{w("")},style:{width:"auto",marginTop:"1rem"},children:h("library.search.clearSearch")})]})]});return tn("div",{className:"library-menu-items-container",style:r.length||T.length||C.length?{justifyContent:"flex-start"}:{borderBottom:0},children:[tn("div",{className:"library-menu-items-header",children:[!x&>(ur,{ref:V,type:"search",className:TR("library-menu-items-container__search",{hideCancelButton:m.formFactor!=="phone"}),placeholder:h("library.search.inputPlaceholder"),value:E,onChange:R=>w(R)}),gt(O2,{selectedItems:c,onSelectItems:l,className:"library-menu-dropdown-container--in-heading"})]}),tn(St.Col,{className:"library-menu-items-container__items",align:"start",gap:1,style:{flex:C.length>0?1:"0 1 auto",margin:x?"auto":0},ref:p,children:[e&>("div",{style:{position:"absolute",top:"var(--container-padding-y)",right:"var(--container-padding-x)",transform:"translateY(50%)"},children:gt(wt,{})}),G,Y,x&>(Qd,{style:{padding:"16px 0",width:"100%"},id:a,libraryReturnUrl:s,theme:i})]})]})}import{jsx as gr,jsxs as Z2}from"react/jsx-runtime";var Ba=ye(!1),$2=({children:e})=>gr("div",{className:"layer-ui__library",children:e}),RR=J2(({onInsertLibraryItems:e,pendingElements:o,onAddToLibrary:t,setAppState:n,libraryReturnUrl:r,library:i,id:a,theme:s,selectedItems:l,onSelectItems:c})=>{let[m]=ee(Ln),p=Zh(b=>{(async(E,w)=>{me("element","addToLibrary","ui");for(let y of kR)if(E.some(v=>v.type===y))return n({errorMessage:h(`errors.libraryElementTypeError.${y}`)});let x=[{status:"unpublished",elements:E,id:MR(),created:Date.now()},...w];t(),i.setLibrary(x).catch(()=>{n({errorMessage:h("alerts.errorAddingToLibrary")})})})(b,m.libraryItems)},[t,i,n,m.libraryItems]),d=q2(()=>m.libraryItems,[m]);if(m.status==="loading"&&!m.isInitialized)return gr($2,{children:gr("div",{className:"layer-ui__library-message",children:Z2("div",{children:[gr(wt,{size:"2em"}),gr("span",{children:h("labels.libraryLoadingMessage")})]})})});let u=m.libraryItems.length>0||o.length>0;return Z2($2,{children:[gr(Xh,{isLoading:m.status==="loading",libraryItems:d,onAddToLibrary:p,onInsertLibraryItems:e,pendingElements:o,id:a,libraryReturnUrl:r,theme:s,onSelectItems:c,selectedItems:l}),u&&gr(Qd,{className:"library-menu-control-buttons--at-bottom",style:{padding:"16px 12px 0 12px"},id:a,libraryReturnUrl:r,theme:s})]})}),$h=(e,o)=>({elements:e,pending:ne(e,{selectedElementIds:o},{includeBoundTextElement:!0,includeElementsInFrames:!0}),selectedElementIds:o}),NR=(e,o)=>{let t=Jn(),[n,r]=j2(()=>$h(t,e.selectedElementIds)),i=SR(new Map);return jh(()=>{for(let a of n.pending)i.current.set(a.id,a.version)},[n.pending]),jh(()=>{o.state.cursorButton==="up"&&o.state.activeTool.type==="selection"&&r(a=>{if(!PR(a.selectedElementIds,e.selectedElementIds))return i.current.clear(),$h(t,e.selectedElementIds);let s=o.scene.getNonDeletedElementsMap();for(let l of Object.keys(e.selectedElementIds)){let c=s.get(l)?.version;if(c&&c!==i.current.get(l))return $h(t,e.selectedElementIds)}return a})},[o,o.state.cursorButton,o.state.activeTool.type,e.selectedElementIds,t]),n.pending},Q2=J2(()=>{let e=ze(),{onInsertElements:o}=e,t=jo(),n=he(),r=be(),[i,a]=j2([]),s=q2(()=>e.library,[e.library]),l=NR(n,e);jh(()=>DR(document,_R.KEYDOWN,p=>{if(p.key===LR.ESCAPE&&p.target instanceof HTMLElement){let d=p.target;if(d.closest(`.${X2.SIDEBAR}`))i.length>0?(p.stopPropagation(),a([])):AR(d)&&d instanceof HTMLInputElement&&!d.value&&(p.stopPropagation(),r({openSidebar:null}),e.focusContainer());else if(i.length>0){let{x:u,y:b}=e.lastViewportPosition;document.elementFromPoint(u,b)?.closest(`.${X2.SIDEBAR}`)&&(p.stopPropagation(),a([]))}}},{capture:!0}),[i,r,e]);let c=Zh(p=>{o(Na(p)),e.focusContainer()},[o,e]),m=Zh(()=>{r({selectedElementIds:{},selectedGroupIds:{},activeEmbeddable:null})},[r]);return gr(RR,{pendingElements:l,onInsertLibraryItems:c,onAddToLibrary:m,setAppState:r,libraryReturnUrl:t.libraryReturnUrl,library:s,id:e.id,theme:n.theme,selectedItems:i,onSelectItems:a})});import BR from"clsx";import{useRef as FR}from"react";import{createPortal as OR}from"react-dom";import{KEYS as zR}from"@orangecatai/common";import{jsx as eT,jsxs as HR}from"react/jsx-runtime";var tT=e=>{let{closeOnClickOutside:o=!0}=e,t=Qc({className:"excalidraw-modal-container"}),n=FR(document.body.classList.contains("excalidraw-animations-disabled"));if(!t)return null;let r=i=>{i.key===zR.ESCAPE&&(i.nativeEvent.stopImmediatePropagation(),i.stopPropagation(),e.onCloseRequest())};return OR(HR("div",{className:BR("Modal",e.className,{"animations-disabled":n.current}),role:"dialog","aria-modal":"true",onKeyDown:r,"aria-labelledby":e.labelledBy,children:[eT("div",{className:"Modal__background",onClick:o?e.onCloseRequest:void 0}),eT("div",{className:"Modal__content",style:{"--max-width":`${e.maxWidth}px`},tabIndex:0,children:e.children})]}),t)};import{jsx as vl,jsxs as KR}from"react/jsx-runtime";function VR(e){if(e&&typeof e=="number")return e;switch(e){case"small":return 550;case"wide":return 1024;case"regular":default:return 800}}var Qe=e=>{let[o,t]=Xv(),[n]=WR(document.activeElement),{id:r}=Oe(),i=fe().formFactor==="phone";UR(()=>{if(!o)return;let c=oT(o);setTimeout(()=>{c.length>0&&e.autofocus!==!1&&(c[1]||c[0]).focus()});let m=p=>{if(p.key===YR.TAB){let d=oT(o),{activeElement:u}=document,b=d.findIndex(g=>g===u);b===0&&p.shiftKey?(d[d.length-1].focus(),p.preventDefault()):b===d.length-1&&!p.shiftKey&&(d[0].focus(),p.preventDefault())}};return o.addEventListener("keydown",m),()=>o.removeEventListener("keydown",m)},[o,e.autofocus]);let a=be(),s=Yo(Ba),l=()=>{a({openMenu:null}),s(!1),n.focus(),e.onCloseRequest()};return vl(tT,{className:GR("Dialog",e.className,{"Dialog--fullscreen":i}),labelledBy:"dialog-title",maxWidth:VR(e.size),onCloseRequest:l,closeOnClickOutside:e.closeOnClickOutside,children:KR(qe,{ref:t,children:[e.title&&vl("h2",{id:`${r}-dialog-title`,className:"Dialog__title",children:vl("span",{className:"Dialog__titleContent",children:e.title})}),i&&vl("button",{className:"Dialog__close",onClick:l,title:h("buttons.close"),"aria-label":h("buttons.close"),type:"button",children:io}),vl("div",{className:"Dialog__content",children:e.children})]})})};import{KEYS as Xe}from"@orangecatai/common";var dm=[{icon:$i,value:"hand",key:Xe.H,numericKey:null,fillable:!1,toolbar:!0},{icon:$r,value:"selection",key:Xe.V,numericKey:Xe[1],fillable:!0,toolbar:!0},{icon:Gi,value:"rectangle",key:Xe.R,numericKey:Xe[2],fillable:!0,toolbar:!0},{icon:Ui,value:"diamond",key:Xe.D,numericKey:Xe[3],fillable:!0,toolbar:!0},{icon:Wi,value:"ellipse",key:Xe.O,numericKey:Xe[4],fillable:!0,toolbar:!0},{icon:Dc,value:"arrow",key:Xe.A,numericKey:Xe[5],fillable:!0,toolbar:!0},{icon:Yi,value:"line",key:Xe.L,numericKey:Xe[6],fillable:!0,toolbar:!0},{icon:Ko,value:"freedraw",key:[Xe.P,Xe.X],numericKey:Xe[7],fillable:!1,toolbar:!0},{icon:Xo,value:"text",key:Xe.T,numericKey:Xe[8],fillable:!1,toolbar:!0},{icon:Xn,value:"image",key:null,numericKey:Xe[9],fillable:!1,toolbar:!0},{icon:_c,value:"eraser",key:Xe.E,numericKey:Xe[0],fillable:!1,toolbar:!0},{icon:$o,value:"laser",key:Xe.K,numericKey:null,fillable:!1,toolbar:!1}],qh=e=>e.state.preferredSelectionTool.type==="lasso"?[{value:"lasso",icon:$r,key:Xe.V,numericKey:Xe[1],fillable:!0,toolbar:!0},...dm.slice(1)]:dm,nT=(e,o)=>qh(o).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 nn from"clsx";import{useRef as tN,useState as oN}from"react";import{Popover as hr}from"radix-ui";import{CLASSES as dT,KEYS as sT,capitalizeString as Ha,isTransparent as pm}from"@orangecatai/common";import{shouldAllowVerticalAlign as mT,suppportsHorizontalAlign as pT,hasBoundTextElement as um,isElbowArrow as tf,isImageElement as uT,isLinearElement as of,isTextElement as hm,isArrowElement as lT,hasStrokeColor as cT,toolIsArrow as gm}from"@orangecatai/element";import{createIsolation as XR}from"jotai-scope";import Jh from"react";import on from"tunnel-rat";var Qh=Jh.createContext(null),Fe=()=>Jh.useContext(Qh),$R=XR(),rT=()=>Jh.useMemo(()=>({MainMenuTunnel:on(),WelcomeScreenMenuHintTunnel:on(),WelcomeScreenToolbarHintTunnel:on(),WelcomeScreenHelpHintTunnel:on(),WelcomeScreenCenterTunnel:on(),FooterCenterTunnel:on(),DefaultSidebarTriggerTunnel:on(),DefaultSidebarTabTriggersTunnel:on(),OverwriteConfirmDialogTunnel:on(),TTDDialogTriggerTunnel:on(),tunnelsJotai:$R}),[]);import{CODES as ZR,KEYS as jR}from"@orangecatai/common";import{CaptureUpdateAction as qR}from"@orangecatai/element";var di=O({name:"viewMode",label:"labels.viewMode",icon:qi,viewMode:!0,trackEvent:{category:"canvas",predicate:e=>!e.viewModeEnabled},perform(e,o){return{appState:{...o,viewModeEnabled:!this.checked(o)},captureUpdate:qR.EVENTUALLY}},checked:e=>e.viewModeEnabled,predicate:(e,o,t)=>typeof t.viewModeEnabled>"u",keyTest:e=>!e[jR.CTRL_OR_CMD]&&e.altKey&&e.code===ZR.R});import{useEffect as JR,useState as QR}from"react";import iT from"clsx";import{capitalizeString as aT}from"@orangecatai/common";import{Popover as ef}from"radix-ui";import{jsx as mm,jsxs as eN}from"react/jsx-runtime";var za=({app:e,options:o,activeTool:t,defaultOption:n,className:r="Shape",namePrefix:i,title:a,"data-testid":s,onToolChange:l,displayedOption:c,fillable:m=!1})=>{let[p,d]=QR(!1),u=t.type,b=c.type===u,g=32/2+10,{container:E}=Oe();return!o.some(w=>w.type===u)&&p&&d(!1),JR(()=>{let w=e.onPointerDownEmitter.on(()=>{d(!1)});return()=>w?.()},[e]),eN(ef.Root,{open:p,children:[mm(ef.Trigger,{asChild:!0,children:mm(Q,{className:iT(r,{fillable:m,active:o.some(w=>w.type===t.type)}),type:"radio",icon:c.icon,checked:b,name:"editor-current-shape",title:a,"aria-label":a,"data-testid":s,onPointerDown:()=>{d(w=>!w),l(n)}})}),mm(ef.Content,{className:"tool-popover-content",sideOffset:g,collisionBoundary:E??void 0,children:o.map(({type:w,icon:x,title:y})=>mm(Q,{className:iT(r,{active:u===w}),type:"radio",icon:x,checked:u===w,name:`${i}-option`,title:y||aT(w),keyBindingLabel:"","aria-label":y||aT(w),"data-testid":`toolbar-${w}`,onChange:()=>{e.state.activeTool.type!==w&&me("toolbar",w,"ui"),e.setActiveTool({type:w}),l?.(w)}},w))})]})};import{Fragment as oo,jsx as q,jsxs as xe}from"react/jsx-runtime";var nf=nn([dT.SHAPE_ACTIONS_THEME_SCOPE,"properties-content"]),Tl=(e,o)=>{let t=o[0]?.type||null;for(let n of o)if(n.type!==t){t=null;break}return cT(e.activeTool.type)&&t!=="image"&&t!=="frame"&&t!=="magicframe"||o.some(n=>cT(n.type))},Il=(e,o)=>Uo(e.activeTool.type)||o.some(t=>Uo(t.type)),gT=({appState:e,elementsMap:o,renderAction:t,app:n})=>{let r=Ai(o,e),i=!1;r.length===2&&(um(r[0])||um(r[1]))&&(i=!0);let a=!!(e.editingTextElement||e.newElement),s=fe(),l=document.documentElement.getAttribute("dir")==="rtl",c=Uo(e.activeTool.type)&&!pm(e.currentItemBackgroundColor)||r.some(b=>Uo(b.type)&&!pm(b.backgroundColor)),m=r.length===1||i,p=!e.selectedLinearElement?.isEditing&&r.length===1&&of(r[0])&&!tf(r[0]),d=!e.croppingElementId&&r.length===1&&uT(r[0]),u=!i&&Nt(e,n);return xe("div",{className:"selected-shape-actions",children:[q("div",{children:Tl(e,r)&&t("changeStrokeColor")}),Il(e,r)&&q("div",{children:t("changeBackgroundColor")}),c&&t("changeFillStyle"),(vs(e.activeTool.type)||r.some(b=>vs(b.type)))&&t("changeStrokeWidth"),(e.activeTool.type==="freedraw"||r.some(b=>b.type==="freedraw"))&&t("changeStrokeShape"),(Ts(e.activeTool.type)||r.some(b=>Ts(b.type)))&&xe(oo,{children:[t("changeStrokeStyle"),t("changeSloppiness")]}),(Is(e.activeTool.type)||r.some(b=>Is(b.type)))&&q(oo,{children:t("changeRoundness")}),(gm(e.activeTool.type)||r.some(b=>gm(b.type)))&&q(oo,{children:t("changeArrowType")}),(e.activeTool.type==="text"||r.some(hm))&&xe(oo,{children:[t("changeFontFamily"),t("changeFontSize"),(e.activeTool.type==="text"||pT(r,o))&&t("changeTextAlign")]}),mT(r,o)&&t("changeVerticalAlign"),(Di(e.activeTool.type)||r.some(b=>Di(b.type)))&&q(oo,{children:t("changeArrowhead")}),t("changeOpacity"),xe("fieldset",{children:[q("legend",{children:h("labels.layers")}),xe("div",{className:"buttonList",children:[t("sendToBack"),t("sendBackward"),t("bringForward"),t("bringToFront")]})]}),u&&!i&&xe("fieldset",{children:[q("legend",{children:h("labels.align")}),xe("div",{className:"buttonList",children:[l?xe(oo,{children:[t("alignRight"),t("alignHorizontallyCentered"),t("alignLeft")]}):xe(oo,{children:[t("alignLeft"),t("alignHorizontallyCentered"),t("alignRight")]}),r.length>2&&t("distributeHorizontally"),q("div",{style:{flexBasis:"100%",height:0}}),xe("div",{style:{display:"flex",flexWrap:"wrap",gap:".5rem",marginTop:"-0.5rem"},children:[t("alignTop"),t("alignVerticallyCentered"),t("alignBottom"),r.length>2&&t("distributeVertically")]})]})]}),!a&&r.length>0&&xe("fieldset",{children:[q("legend",{children:h("labels.actions")}),xe("div",{className:"buttonList",children:[s.formFactor!=="phone"&&t("duplicateSelection"),s.formFactor!=="phone"&&t("deleteSelectedElements"),t("group"),t("ungroup"),m&&t("hyperlink"),d&&t("cropEditor"),p&&t("toggleLinearEditor")]})]})]})},hT=({appState:e,renderAction:o,setAppState:t,targetElements:n,container:r})=>{let i=Uo(e.activeTool.type)&&!pm(e.currentItemBackgroundColor)||n.some(l=>Uo(l.type)&&!pm(l.backgroundColor)),a=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 a?q("div",{className:"compact-action-item",children:xe(hr.Root,{open:s,onOpenChange:l=>{t(l?{openPopup:"compactStrokeStyles"}:{openPopup:null})},children:[q(hr.Trigger,{asChild:!0,children:q("button",{type:"button",className:nn("compact-action-button properties-trigger",{active:s}),title:h("labels.stroke"),onClick:l=>{l.preventDefault(),l.stopPropagation(),t({openPopup:s?null:"compactStrokeStyles"})},children:BE})}),s&&q(Tn,{className:nf,container:r,style:{maxWidth:"13rem"},onClose:()=>{},children:xe("div",{className:"selected-shape-actions",children:[i&&o("changeFillStyle"),(vs(e.activeTool.type)||n.some(l=>vs(l.type)))&&o("changeStrokeWidth"),(Ts(e.activeTool.type)||n.some(l=>Ts(l.type)))&&xe(oo,{children:[o("changeStrokeStyle"),o("changeSloppiness")]}),(Is(e.activeTool.type)||n.some(l=>Is(l.type)))&&o("changeRoundness"),o("changeOpacity")]})})]})}):null},fT=({appState:e,renderAction:o,setAppState:t,targetElements:n,container:r,app:i})=>{let a=gm(e.activeTool.type)||n.some(l=>gm(l.type)),s=e.openPopup==="compactArrowProperties";return a?q("div",{className:"compact-action-item",children:xe(hr.Root,{open:s,onOpenChange:l=>{t(l?{openPopup:"compactArrowProperties"}:{openPopup:null})},children:[q(hr.Trigger,{asChild:!0,children:q("button",{type:"button",className:nn("compact-action-button properties-trigger",{active:s}),title:h("labels.arrowtypes"),onClick:l=>{l.preventDefault(),l.stopPropagation(),t({openPopup:s?null:"compactArrowProperties"})},children:(()=>{let l=It(n,i,c=>lT(c)?c.elbowed?"elbow":c.roundness?"round":"sharp":null,c=>lT(c),c=>c?null:e.currentItemArrowType);return l==="elbow"?Qi:l==="round"?ea:Ji})()})}),s&&q(Tn,{container:r,className:"properties-content",style:{maxWidth:"13rem"},onClose:()=>{},children:o("changeArrowProperties")})]})}):null},bT=({appState:e,renderAction:o,setAppState:t,targetElements:n,container:r,elementsMap:i})=>{let{saveCaretPosition:a,restoreCaretPosition:s}=ry(),l=e.openPopup==="compactTextProperties";return q("div",{className:"compact-action-item",children:xe(hr.Root,{open:l,onOpenChange:c=>{c?(e.editingTextElement&&a(),t({openPopup:"compactTextProperties"})):(t({openPopup:null}),e.editingTextElement&&s())},children:[q(hr.Trigger,{asChild:!0,children:q("button",{type:"button",className:nn("compact-action-button properties-trigger",{active:l}),title:h("labels.textAlign"),onClick:c=>{c.preventDefault(),c.stopPropagation(),l?t({openPopup:null}):(e.editingTextElement&&a(),t({openPopup:"compactTextProperties"}))},children:sx})}),e.openPopup==="compactTextProperties"&&q(Tn,{className:nf,container:r,style:{maxWidth:"13rem"},preventAutoFocusOnTouch:!!e.editingTextElement,onClose:()=>{e.editingTextElement&&s()},children:xe("div",{className:"selected-shape-actions",children:[(e.activeTool.type==="text"||n.some(hm))&&o("changeFontSize"),(e.activeTool.type==="text"||pT(n,i))&&o("changeTextAlign"),mT(n,i)&&o("changeVerticalAlign")]})})]})})},xT=({appState:e,renderAction:o,targetElements:t,setAppState:n,container:r,app:i,showDuplicate:a,showDelete:s})=>{let l=!!(e.editingTextElement||e.newElement),c=!e.croppingElementId&&t.length===1&&uT(t[0]),m=t.length===1,p=Nt(e,i),d=!1;t.length===2&&(um(t[0])||um(t[1]))&&(d=!0);let u=document.documentElement.getAttribute("dir")==="rtl",b=e.openPopup==="compactOtherProperties";return l||t.length===0?null:q("div",{className:"compact-action-item",children:xe(hr.Root,{open:b,onOpenChange:g=>{n(g?{openPopup:"compactOtherProperties"}:{openPopup:null})},children:[q(hr.Trigger,{asChild:!0,children:q("button",{type:"button",className:nn("compact-action-button properties-trigger",{active:b}),title:h("labels.actions"),onClick:g=>{g.preventDefault(),g.stopPropagation(),n({openPopup:b?null:"compactOtherProperties"})},children:ex})}),b&&q(Tn,{className:nf,container:r,style:{maxWidth:"12rem",justifyContent:"center",alignItems:"center"},onClose:()=>{},children:xe("div",{className:"selected-shape-actions",children:[xe("fieldset",{children:[q("legend",{children:h("labels.layers")}),xe("div",{className:"buttonList",children:[o("sendToBack"),o("sendBackward"),o("bringForward"),o("bringToFront")]})]}),p&&!d&&xe("fieldset",{children:[q("legend",{children:h("labels.align")}),xe("div",{className:"buttonList",children:[u?xe(oo,{children:[o("alignRight"),o("alignHorizontallyCentered"),o("alignLeft")]}):xe(oo,{children:[o("alignLeft"),o("alignHorizontallyCentered"),o("alignRight")]}),t.length>2&&o("distributeHorizontally"),q("div",{style:{flexBasis:"100%",height:0}}),xe("div",{style:{display:"flex",flexWrap:"wrap",gap:".5rem",marginTop:"-0.5rem"},children:[o("alignTop"),o("alignVerticallyCentered"),o("alignBottom"),t.length>2&&o("distributeVertically")]})]})]}),xe("fieldset",{children:[q("legend",{children:h("labels.actions")}),xe("div",{className:"buttonList",children:[o("group"),o("ungroup"),m&&o("hyperlink"),c&&o("cropEditor"),a&&o("duplicateSelection"),s&&o("deleteSelectedElements")]})]})]})})]})})},nN=({appState:e,renderAction:o,targetElements:t})=>!e.selectedLinearElement?.isEditing&&t.length===1&&of(t[0])&&!tf(t[0])?q("div",{className:"compact-action-item",children:o("toggleLinearEditor")}):null,ET=({appState:e,elementsMap:o,renderAction:t,app:n,setAppState:r})=>{let i=Ai(o,e),{container:a}=Oe(),s=!!(e.editingTextElement||e.newElement),l=!e.selectedLinearElement?.isEditing&&i.length===1&&of(i[0])&&!tf(i[0]);return xe("div",{className:"compact-shape-actions",children:[Tl(e,i)&&q("div",{className:nn("compact-action-item"),children:t("changeStrokeColor")}),Il(e,i)&&q("div",{className:"compact-action-item",children:t("changeBackgroundColor")}),q(hT,{appState:e,renderAction:t,setAppState:r,targetElements:i,container:a}),q(fT,{appState:e,renderAction:t,setAppState:r,targetElements:i,container:a,app:n}),l&&q("div",{className:"compact-action-item",children:t("toggleLinearEditor")}),(e.activeTool.type==="text"||i.some(hm))&&xe(oo,{children:[q("div",{className:"compact-action-item",children:t("changeFontFamily")}),q(bT,{appState:e,renderAction:t,setAppState:r,targetElements:i,container:a,elementsMap:o})]}),!s&&i.length>0&&q("div",{className:"compact-action-item",children:t("duplicateSelection")}),!s&&i.length>0&&q("div",{className:"compact-action-item",children:t("deleteSelectedElements")}),q(xT,{appState:e,renderAction:t,targetElements:i,setAppState:r,container:a,app:n})]})},yT=({appState:e,elementsMap:o,renderAction:t,app:n,setAppState:r})=>{let i=Ai(o,e),{container:a}=Oe(),s=tN(null),l=s.current?.getBoundingClientRect()?.width??0,c=9,m=6,p=32,d=c*p+(c-1)*m,u=p+m,b=l>=d+u,g=l>=d+2*u;return xe(qe,{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:[xe("div",{style:{display:"flex",flexDirection:"row",gap:m,flex:1},children:[Tl(e,i)&&q("div",{className:nn("compact-action-item"),children:t("changeStrokeColor")}),Il(e,i)&&q("div",{className:"compact-action-item",children:t("changeBackgroundColor")}),q(hT,{appState:e,renderAction:t,setAppState:r,targetElements:i,container:a}),q(fT,{appState:e,renderAction:t,setAppState:r,targetElements:i,container:a,app:n}),q(nN,{appState:e,renderAction:t,targetElements:i}),(e.activeTool.type==="text"||i.some(hm))&&xe(oo,{children:[q("div",{className:"compact-action-item",children:t("changeFontFamily")}),q(bT,{appState:e,renderAction:t,setAppState:r,targetElements:i,container:a,elementsMap:o})]}),q(xT,{appState:e,renderAction:t,targetElements:i,setAppState:r,container:a,app:n,showDuplicate:!g,showDelete:!b})]}),xe("div",{style:{display:"flex",flexDirection:"row",gap:m},children:[q("div",{className:"compact-action-item",children:t("undo")}),q("div",{className:"compact-action-item",children:t("redo")}),g&&q("div",{className:"compact-action-item",children:t("duplicateSelection")}),b&&q("div",{className:"compact-action-item",children:t("deleteSelectedElements")})]})]})},wT=({activeTool:e,setAppState:o,app:t,UIOptions:n})=>{let[r,i]=oN(!1),a=ut(),s=a==="full",l=a==="compact",c=[{type:"selection",icon:$r,title:Ha(h("toolBar.selection"))},{type:"lasso",icon:Kn,title:Ha(h("toolBar.lasso"))}],m=e.type==="frame",p=e.type==="laser",d=s&&e.type==="lasso"&&t.state.preferredSelectionTool.type!=="lasso",u=e.type==="embeddable",{TTDDialogTriggerTunnel:b}=Fe();return xe(oo,{children:[qh(t).map(({value:g,icon:E,key:w,numericKey:x,fillable:y,toolbar:v})=>{if(v===!1||n.tools?.[g]===!1)return null;let T=h(`toolBar.${g}`),C=w&&Ha(typeof w=="string"?w:w[0]),M=C?`${C} ${h("helpDialog.or")} ${x}`:`${x}`,S=g==="hand"?void 0:x||C;return(g==="selection"||g==="lasso")&&l?q(za,{app:t,options:c,activeTool:e,defaultOption:t.state.preferredSelectionTool.type,namePrefix:"selectionType",title:Ha(h("toolBar.selection")),"data-testid":"toolbar-selection",onToolChange:D=>{(D==="selection"||D==="lasso")&&(t.setActiveTool({type:D}),o({preferredSelectionTool:{type:D,initialized:!0}}))},displayedOption:c.find(D=>D.type===t.state.preferredSelectionTool.type)||c[0],fillable:e.type==="selection"},"selection-popover"):q(Q,{className:nn("Shape",{fillable:y}),type:"radio",icon:E,checked:e.type===g,name:"editor-current-shape",title:`${Ha(T)} \u2014 ${M}`,keyBindingLabel:S,"aria-label":Ha(T),"aria-keyshortcuts":M,"data-testid":`toolbar-${g}`,onPointerDown:({pointerType:D})=>{!t.state.penDetected&&D==="pen"&&t.togglePenMode(!0),g==="selection"&&(t.state.activeTool.type==="selection"?t.setActiveTool({type:"lasso"}):t.setActiveTool({type:"selection"}))},onChange:({pointerType:D})=>{t.state.activeTool.type!==g&&me("toolbar",g,"ui"),g==="image"?t.setActiveTool({type:g}):t.setActiveTool({type:g})}},g)}),q("div",{className:"App-toolbar__divider"}),xe(se,{open:r,children:[q(se.Trigger,{className:nn("App-toolbar__extra-tools-trigger",{"App-toolbar__extra-tools-trigger--selected":m||u||d||p&&!t.props.isCollaborating}),onToggle:()=>{i(!r),o({openMenu:null,openPopup:null})},title:h("toolBar.extraTools"),children:m?ko:u?Vi:p&&!t.props.isCollaborating?$o:d?Kn:Ns}),xe(se.Content,{onClickOutside:()=>i(!1),onSelect:()=>i(!1),className:"App-toolbar__extra-tools-dropdown",children:[q(se.Item,{onSelect:()=>t.setActiveTool({type:"frame"}),icon:ko,shortcut:sT.F.toLocaleUpperCase(),"data-testid":"toolbar-frame",selected:m,children:h("toolBar.frame")}),q(se.Item,{onSelect:()=>t.setActiveTool({type:"embeddable"}),icon:Vi,"data-testid":"toolbar-embeddable",selected:u,children:h("toolBar.embeddable")}),q(se.Item,{onSelect:()=>t.setActiveTool({type:"laser"}),icon:$o,"data-testid":"toolbar-laser",selected:p,shortcut:sT.K.toLocaleUpperCase(),children:h("toolBar.laser")}),s&&q(se.Item,{onSelect:()=>t.setActiveTool({type:"lasso"}),icon:Kn,"data-testid":"toolbar-lasso",selected:d,children:h("toolBar.lasso")}),q("div",{style:{margin:"6px 0",fontSize:14,fontWeight:600},children:"Generate"}),t.props.aiEnabled!==!1&&q(b.Out,{}),q(se.Item,{onSelect:()=>t.onImageGeneratorSelect(),icon:Xn,"data-testid":"toolbar-image-generator",badge:q(se.Item.Badge,{children:"AI"}),children:"Image Generator"}),q(se.Item,{onSelect:()=>t.setOpenDialog({name:"ttd",tab:"mermaid"}),icon:ji,"data-testid":"toolbar-embeddable",children:h("toolBar.mermaidToExcalidraw")}),t.props.aiEnabled!==!1&&t.plugins.diagramToCode&&q(se.Item,{onSelect:()=>t.onMagicframeToolSelect(),icon:qr,"data-testid":"toolbar-magicframe",badge:q(se.Item.Badge,{children:"AI"}),children:h("toolBar.magicframe")})]})]})]})},vT=({renderAction:e,zoom:o})=>q(St.Col,{gap:1,className:dT.ZOOM_ACTIONS,children:xe(St.Row,{align:"center",children:[e("zoomOut"),e("resetZoom"),e("zoomIn")]})}),TT=({renderAction:e,className:o})=>xe("div",{className:`undo-redo-buttons ${o}`,children:[q("div",{className:"undo-button-container",children:q(qt,{label:h("buttons.undo"),children:e("undo")})}),q("div",{className:"redo-button-container",children:xe(qt,{label:h("buttons.redo"),children:[" ",e("redo")]})})]}),IT=({actionManager:e,showExitZenModeBtn:o})=>q("button",{type:"button",className:nn("disable-zen-mode",{"disable-zen-mode--visible":o}),onClick:()=>e.executeAction(lr),children:h("buttons.exitZenMode")}),CT=({actionManager:e})=>q("button",{type:"button",className:"disable-view-mode",onClick:()=>e.executeAction(di),children:OE});import{useRef as rN}from"react";var rf=e=>{let o=rN({userFn:e});return o.current.userFn=e,o.current.stableFn||(o.current.stableFn=(...t)=>o.current.userFn(...t)),o.current.stableFn};import{jsx as aN,jsxs as iN}from"react/jsx-runtime";var mi=ye(null),ST=()=>{let[e,o]=ee(mi),t=We();return e&&e==="clearCanvas"?aN(tm,{onConfirm:()=>{t.executeAction(Mn),o(null)},onCancel:()=>o(null),title:h("clearCanvasDialog.title"),children:iN("p",{className:"clear-canvas__content",children:[" ",h("alerts.clearReset")]})}):null};var af={};Ib(af,{toggleTheme:()=>sN});var sN={...ti,category:"App",label:"Toggle theme",perform:({actionManager:e})=>{e.executeAction(ti,"commandPalette")}};import{jsx as ht,jsxs as rn}from"react/jsx-runtime";var pN=ye(null),Ye={app:"App",export:"Export",tools:"Tools",editor:"Editor",elements:"Elements",links:"Links",library:"Library"},MT=e=>{switch(e){case Ye.app:return 1;case Ye.export:return 2;case Ye.editor:return 3;case Ye.tools:return 4;case Ye.elements:return 5;case Ye.links:return 6;default:return 10}},xm=({shortcut:e,className:o,children:t})=>{let n=e.replace("++","+$").split("+");return rn("div",{className:LT("shortcut",o),children:[n.map((r,i)=>ht("div",{className:"shortcut-wrapper",children:ht("div",{className:"shortcut-key",children:r==="$"?"+":r})},r)),ht("div",{className:"shortcut-desc",children:t})]})},DT=e=>!e.altKey&&e[Ro.CTRL_OR_CMD]&&(e.shiftKey&&e.key.toLowerCase()===Ro.P||e.key===Ro.SLASH),uN=Object.assign(e=>{let o=he(),t=be();return bm(()=>{let n=r=>{DT(r)&&(r.preventDefault(),r.stopPropagation(),t(i=>{let a=i.openDialog?.name==="commandPalette"?null:{name:"commandPalette"};return a&&me("command_palette","open","shortcut"),{openDialog:a}}))};return window.addEventListener(Em.KEYDOWN,n,{capture:!0}),()=>window.removeEventListener(Em.KEYDOWN,n,{capture:!0})},[t]),o.openDialog?.name!=="commandPalette"?null:ht(gN,{...e})},{defaultItems:af});function gN({customCommandPaletteItems:e}){let o=ze(),t=he(),n=be(),r=jo(),i=We(),[a,s]=ee(pN),[l,c]=fm(null),m=AT(null),p=Zn({uiAppState:t,customCommandPaletteItems:e,appProps:r}),[d]=ee(Ln),u=cN(()=>d.libraryItems?.filter(S=>!!S.name).map(S=>({label:S.name,icon:ht(hN,{id:S.id,elements:S.elements}),category:"Library",order:MT("Library"),haystack:li(S.name),perform:()=>{o.onInsertElements(Na([S]))}}))||[],[o,d.libraryItems]);bm(()=>{let{uiAppState:S,customCommandPaletteItems:D,appProps:_}=p,P=G=>{let Y="";return G.label&&(typeof G.label=="function"?Y=h(G.label(o.scene.getNonDeletedElements(),S,o)):Y=h(G.label)),Y},A=G=>typeof G.icon=="function"?G.icon(S,o.scene.getNonDeletedElements()):G.icon,z=[],V=(G,Y,R)=>{let F={label:P(G),icon:A(G),category:Y,shortcut:Be(G.name),keywords:G.keywords,predicate:G.predicate,viewMode:G.viewMode,perform:()=>{i.executeAction(G,"commandPalette")}};return R?R(F,G):F};if(S&&o.scene&&i){let G=[i.actions.group,i.actions.ungroup,i.actions.cut,i.actions.copy,i.actions.deleteSelectedElements,i.actions.wrapSelectionInFrame,i.actions.copyStyles,i.actions.pasteStyles,i.actions.bringToFront,i.actions.bringForward,i.actions.sendBackward,i.actions.sendToBack,i.actions.alignTop,i.actions.alignBottom,i.actions.alignLeft,i.actions.alignRight,i.actions.alignVerticallyCentered,i.actions.alignHorizontallyCentered,i.actions.duplicateSelection,i.actions.flipHorizontal,i.actions.flipVertical,i.actions.zoomToFitSelection,i.actions.zoomToFitSelectionInViewport,i.actions.increaseFontSize,i.actions.decreaseFontSize,i.actions.toggleLinearEditor,i.actions.cropEditor,i.actions.togglePolygon,ml,$d,Vv].map(Z=>V(Z,Ye.elements,(le,Ee)=>({...le,predicate:Ee.predicate?Ee.predicate:(ue,_e,et,st)=>ne(ue,_e).length>0}))),Y=[i.actions.toggleHandTool,i.actions.setFrameAsActiveTool,i.actions.toggleLassoTool].map(Z=>V(Z,Ye.tools)),R=[i.actions.undo,i.actions.redo,i.actions.zoomIn,i.actions.zoomOut,i.actions.resetZoom,i.actions.zoomToFit,i.actions.zenMode,i.actions.viewMode,i.actions.gridMode,i.actions.objectsSnapMode,i.actions.toggleShortcuts,i.actions.selectAll,i.actions.toggleElementLock,i.actions.unlockAllElements,i.actions.stats].map(Z=>V(Z,Ye.editor)),F=[i.actions.saveToActiveFile,i.actions.saveFileToDisk,i.actions.copyAsPng,i.actions.copyAsSvg].map(Z=>V(Z,Ye.export));z=[...G,...R,{label:P(Mn),icon:A(Mn),shortcut:Be(Mn.name),category:Ye.editor,keywords:["delete","destroy"],viewMode:!1,perform:()=>{ot.set(mi,"clearCanvas")}},{label:h("buttons.exportImage"),category:Ye.export,icon:Fc,shortcut:Be("imageExport"),keywords:["export","image","png","jpeg","svg","clipboard","picture"],perform:()=>{n({openDialog:{name:"imageExport"}})}},...F];let K=[{label:h("toolBar.library"),category:Ye.app,icon:Ac,viewMode:!1,perform:()=>{S.openSidebar?n({openSidebar:null}):n({openSidebar:{name:kT.name,tab:kT.defaultTab}})}},{label:h("search.title"),category:Ye.app,icon:jt,viewMode:!0,perform:()=>{i.executeAction(Cl)}},{label:h("labels.shapeSwitch"),category:Ye.elements,icon:Bs,perform:()=>{i.executeAction(Yv)}},{label:h("labels.changeStroke"),keywords:["color","outline"],category:Ye.elements,icon:Bc,viewMode:!1,predicate:(Z,le)=>{let Ee=ne(Z,le);return Ee.length>0&&Tl(le,Ee)},perform:()=>{n(Z=>({openPopup:"elementStroke"}))}},{label:h("labels.changeBackground"),keywords:["color","fill"],icon:Bc,category:Ye.elements,viewMode:!1,predicate:(Z,le)=>{let Ee=ne(Z,le);return Ee.length>0&&Il(le,Ee)},perform:()=>{n(Z=>({openPopup:"elementBackground"}))}},{label:h("labels.canvasBackground"),keywords:["color"],icon:Bc,category:Ye.editor,viewMode:!1,perform:()=>{n(Z=>({openMenu:Z.openMenu==="canvas"?null:"canvas",openPopup:"canvasBackground"}))}},...dm.reduce((Z,le)=>{let{value:Ee,icon:ue,key:_e,numericKey:et}=le;if(_.UIOptions.tools?.[Ee]===!1)return Z;let Tt=_e&&dN(typeof _e=="string"?_e:_e[0])||et,Zt={label:h(`toolBar.${Ee}`),category:Ye.tools,shortcut:Tt,icon:ue,keywords:["toolbar"],viewMode:!1,perform:({event:Wr})=>{Ee==="image"?o.setActiveTool({type:Ee}):o.setActiveTool({type:Ee})}};return Z.push(Zt),Z},[]),...Y,{label:h("toolBar.lock"),category:Ye.tools,icon:S.activeTool.locked?Hi:Xr,shortcut:Ro.Q.toLocaleUpperCase(),viewMode:!1,perform:()=>{o.toggleLock()}},{label:`${h("labels.textToDiagram")}...`,category:Ye.tools,icon:bE,viewMode:!1,predicate:_.aiEnabled,perform:()=>{n(Z=>({...Z,openDialog:{name:"ttd",tab:"text-to-diagram"}}))}},{label:`${h("toolBar.mermaidToExcalidraw")}...`,category:Ye.tools,icon:ji,viewMode:!1,predicate:_.aiEnabled,perform:()=>{n(Z=>({...Z,openDialog:{name:"ttd",tab:"mermaid"}}))}}],J=[...z,...K,...D||[]].map(Z=>({...Z,icon:Z.icon||Bs,order:Z.order??MT(Z.category),haystack:`${li(Z.label.toLocaleLowerCase())} ${Z.keywords?.join(" ")||""}`}));c(J),s([...J,...u].find(Z=>Z.label===a?.label)??null)}},[p,o,i,c,a?.label,s,n,u]);let[b,g]=fm(""),[E,w]=fm(null),[x,y]=fm({}),v=S=>{n({openDialog:null},S),g("")},T=(S,D)=>{t.openDialog?.name==="commandPalette"&&(D.stopPropagation(),D.preventDefault(),document.body.classList.add("excalidraw-animations-disabled"),v(()=>{S.perform({actionManager:i,event:D}),s(S),requestAnimationFrame(()=>{document.body.classList.remove("excalidraw-animations-disabled")})}))},C=rf(S=>S.viewMode===!1&&t.viewModeEnabled?!1:typeof S.predicate=="function"?S.predicate(o.scene.getNonDeletedElements(),t,r,o):S.predicate===void 0||S.predicate),M=rf(S=>{let D=mN(S.target)||DT(S)||S.key===Ro.ESCAPE;if(D&&S.key!==Ro.ARROW_UP&&S.key!==Ro.ARROW_DOWN&&S.key!==Ro.ENTER)return;let _=Object.values(x).flat(),P=a&&!b&&C(a);if(S.key===Ro.ARROW_UP){S.preventDefault();let A=_.findIndex(G=>G.label===E?.label);if(P){if(A===0){w(a);return}if(E===a){let G=_[_.length-1];G&&w(G);return}}let z;A===-1?z=_.length-1:z=A===0?_.length-1:(A-1)%_.length;let V=_[z];V&&w(V);return}if(S.key===Ro.ARROW_DOWN){S.preventDefault();let A=_.findIndex(G=>G.label===E?.label);if(P){if(!E||A===_.length-1){w(a);return}if(E===a){let G=_[0];G&&w(G);return}}let z=(A+1)%_.length,V=_[z];V&&w(V);return}if(S.key===Ro.ENTER&&E&&setTimeout(()=>{T(E,S)}),!D){if(S.stopPropagation(),/^[a-zA-Z0-9]$/.test(S.key)){m?.current?.focus();return}S.preventDefault()}});return bm(()=>(window.addEventListener(Em.KEYDOWN,M,{capture:!0}),()=>window.removeEventListener(Em.KEYDOWN,M,{capture:!0})),[M]),bm(()=>{if(!l)return;let S=A=>{let z={};for(let V of A)z[V.category]?z[V.category].push(V):z[V.category]=[V];return z},D=b?.length>1?[...l.filter(C).sort((A,z)=>A.order-z.order),...u]:l.filter(C).sort((A,z)=>A.order-z.order),_=!b&&a&&C(a);if(!b){y(S(_?D.filter(A=>A.label!==a?.label):D)),w(_?a:D[0]||null);return}let P=li(b.toLocaleLowerCase().replace(/[<>_| -]/g,""));D=lN.filter(P,D,{extract:A=>A.haystack??""}).sort((A,z)=>z.score-A.score).map(A=>A.original),y(S(D)),w(D[0]??null)},[b,l,C,a,u]),rn(Qe,{onCloseRequest:()=>v(),closeOnClickOutside:!0,title:!1,size:720,autofocus:!0,className:"command-palette-dialog",children:[ht(ur,{value:b,placeholder:h("commandPalette.search.placeholder"),onChange:S=>{g(S)},selectOnRender:!0,ref:m}),o.editorInterface.formFactor!=="phone"&&rn("div",{className:"shortcuts-wrapper",children:[ht(xm,{shortcut:"\u2191\u2193",children:h("commandPalette.shortcuts.select")}),ht(xm,{shortcut:"\u21B5",children:h("commandPalette.shortcuts.confirm")}),ht(xm,{shortcut:N("Esc"),children:h("commandPalette.shortcuts.close")})]}),rn("div",{className:"commands",children:[a&&!b&&rn("div",{className:"command-category",children:[rn("div",{className:"command-category-title",children:[h("commandPalette.recents"),ht("div",{className:"icon",style:{marginLeft:"6px"},children:xE})]}),ht(PT,{command:a,isSelected:a.label===E?.label,onClick:S=>T(a,S),disabled:!C(a),onMouseMove:()=>w(a),showShortcut:o.editorInterface.formFactor!=="phone",appState:t})]}),Object.keys(x).length>0?Object.keys(x).map((S,D)=>rn("div",{className:"command-category",children:[ht("div",{className:"command-category-title",children:S}),x[S].map(_=>ht(PT,{command:_,isSelected:_.label===E?.label,onClick:P=>T(_,P),onMouseMove:()=>w(_),showShortcut:o.editorInterface.formFactor!=="phone",appState:t,size:S==="Library"?"large":"small"},_.label))]},S)):l?rn("div",{className:"no-match",children:[ht("div",{className:"icon",children:jt})," ",h("commandPalette.search.noMatch")]}):null]})]})}var hN=({id:e,elements:o})=>{let t=AT(null),{svgCache:n}=_a();return Zd(e,o,n,t),ht("div",{className:"library-item-icon",ref:t})},PT=({command:e,isSelected:o,disabled:t,onMouseMove:n,onClick:r,showShortcut:i,appState:a,size:s="small"})=>{let l=()=>{};return rn("div",{className:LT("command-item",{"item-selected":o,"item-disabled":t,"command-item-large":s==="large"}),ref:c=>{o&&!t&&c?.scrollIntoView?.({block:"nearest"})},onClick:t?l:r,onMouseMove:t?l:n,title:t?h("commandPalette.itemNotAvailable"):"",children:[rn("div",{className:"name",children:[e.icon&&ht(qo,{className:"icon",size:"var(--icon-size, 1rem)",icon:typeof e.icon=="function"?e.icon(a,[]):e.icon}),ht(Xs,{children:e.label})]}),i&&e.shortcut&&ht(xm,{shortcut:e.shortcut})]})};import{getSizeFromPoints as Zve,randomInteger as f9,getUpdatedTimestamp as b9}from"@orangecatai/common";import{simplify as t9}from"points-on-curve";import{getStroke as o9}from"perfect-freehand";import{pointsOnBezierCurves as Nfe}from"points-on-curve";import{invariant as Ffe}from"@orangecatai/common";import{curve as zfe,lineSegment as Hfe,pointFrom as Gfe,pointDistance as Ufe,pointFromArray as Wfe,pointFromVector as Yfe,pointRotateRads as Vfe,polygon as Kfe,polygonFromPoints as Xfe,PRECISION as $fe,segmentsIntersectAt as Zfe,vector as jfe,vectorAdd as qfe,vectorFromPoint as Jfe,vectorScale as Qfe}from"@orangecatai/math";import{getElementAbsoluteCoords as t1e}from"@orangecatai/element";var sf=e=>{if(!e)return[];for(let o of e.sets)if(o.type==="path")return o.ops;return e.sets[0].ops};import{pointFrom as n9,pointDistance as jT,pointRotateRads as Rve}from"@orangecatai/math";import{ROUGHNESS as r9,THEME as Cf,isTransparent as Pl,assertNever as i9,COLOR_PALETTE as a9,LINE_POLYGON_POINT_MERGE_DISTANCE as Bve,applyDarkModeFilter as Pm}from"@orangecatai/common";import{RoughGenerator as s9}from"roughjs/bin/generator";import Ywe from"roughjs/bin/rough";import{isRightAngleRads as Kwe,lineSegment as Xwe,pointFrom as $we,pointRotateRads as Zwe}from"@orangecatai/math";import{BOUND_TEXT_PADDING as qwe,DEFAULT_REDUCED_GLOBAL_ALPHA as Jwe,ELEMENT_READY_TO_ERASE_OPACITY as Qwe,FRAME_STYLE as eve,DARK_THEME_FILTER as tve,MIME_TYPES as $T,THEME as ove,distance as nve,getFontString as rve,isRTL as ive,getVerticalOffset as ave,invariant as sve,applyDarkModeFilter as lve,isSafari as cve}from"@orangecatai/common";import oye from"roughjs/bin/rough";import{arrayToMap as rye,invariant as GT,rescalePoints as iye,sizeOf as aye}from"@orangecatai/common";import{degreesToRadians as Ef,lineSegment as lye,pointDistance as cye,pointFrom as vt,pointFromArray as FN,pointRotateRads as Va}from"@orangecatai/math";import{pointsOnBezierCurves as pye}from"points-on-curve";import{pointCenter as bEe,pointFrom as xEe,pointRotateRads as EEe,pointsEqual as yEe,pointDistance as wEe,vectorFromPoint as vEe,curveLength as TEe,curvePointAtLength as IEe}from"@orangecatai/math";import{DRAGGING_THRESHOLD as kEe,KEYS as MEe,shouldRotateWithDiscreteAngle as PEe,getGridPoint as LEe,invariant as AEe,isShallowEqual as DEe,getFeatureFlag as _Ee}from"@orangecatai/common";import{deconstructLinearOrFreeDrawElement as NEe,getSnapOutlineMidPoint as BEe,isPathALoop as FEe,moveArrowAboveBindable as OEe,projectFixedPointOntoDiagonal as zEe}from"@orangecatai/element";import{KEYS as bxe,arrayToMap as xxe,getFeatureFlag as Exe,invariant as yxe,isTransparent as wxe}from"@orangecatai/common";import{PRECISION as Txe,clamp as Ixe,lineSegment as Cxe,pointDistance as Sxe,pointDistanceSq as kxe,pointFrom as Mxe,pointFromVector as Pxe,pointRotateRads as Lxe,pointsEqual as Axe,vectorFromPoint as Dxe,vectorNormalize as _xe,vectorScale as Rxe}from"@orangecatai/math";import{invariant as W0e,isTransparent as Y0e}from"@orangecatai/common";import{curveIntersectLineSegment as K0e,isPointWithinBounds as X0e,lineSegment as $0e,lineSegmentIntersectionPoints as Z0e,pointFrom as j0e,pointFromVector as q0e,pointRotateRads as J0e,pointsEqual as Q0e,vectorFromPoint as ebe,vectorNormalize as tbe,vectorScale as obe}from"@orangecatai/math";import{ellipse as rbe,ellipseSegmentInterceptPoints as ibe}from"@orangecatai/math/ellipse";import{DEFAULT_ADAPTIVE_RADIUS as xN,DEFAULT_PROPORTIONAL_RADIUS as cf,invariant as p1e,LINE_CONFIRM_THRESHOLD as EN,ROUNDNESS as df}from"@orangecatai/common";import{bezierEquation as g1e,curve as h1e,curveCatmullRomCubicApproxPoints as f1e,curveOffsetPoints as b1e,lineSegment as x1e,lineSegmentIntersectionPoints as E1e,pointDistance as yN,pointFrom as y1e,pointFromArray as w1e,pointFromVector as v1e,pointRotateRads as T1e,pointTranslate as I1e,rectangle as C1e,vectorFromPoint as S1e,vectorNormalize as k1e,vectorScale as M1e}from"@orangecatai/math";import{ROUNDNESS as i1e,assertNever as a1e}from"@orangecatai/common";import{pointsEqual as l1e}from"@orangecatai/math";var _T=e=>!!e&&e.type==="embeddable",RT=e=>!!e&&e.type==="iframe",lf=e=>!!e&&(e.type==="iframe"||e.type==="embeddable"),pi=e=>e!=null&&e.type==="text";var ym=e=>e!=null&&(e.type==="frame"||e.type==="magicframe");var ui=e=>e!=null&&fN(e.type);var gi=e=>e!=null&&e.type==="arrow",Sl=e=>gi(e)&&e.elbowed;var fN=e=>e==="arrow"||e==="line";var Ga=e=>e!==null&&"containerId"in e&&e.containerId!==null&&pi(e);var wm=(e,o=1)=>{if(e.length>=3){let[t,n]=[e[0],e[e.length-1]];return yN(t,n)<=EN/o}return!1},kl=(e,o)=>{if(o.roundness?.type===df.PROPORTIONAL_RADIUS||o.roundness?.type===df.LEGACY)return e*cf;if(o.roundness?.type===df.ADAPTIVE_RADIUS){let t=o.roundness?.value??xN,n=t/cf;return e<=n?e*cf:t}return 0};import{ARROW_LABEL_FONT_SIZE_TO_MIN_WIDTH_RATIO as p0e,ARROW_LABEL_WIDTH_FRACTION as u0e,BOUND_TEXT_PADDING as g0e,DEFAULT_FONT_SIZE as h0e,TEXT_ALIGN as f0e,VERTICAL_ALIGN as b0e,getFontString as x0e,isProdEnv as E0e,invariant as y0e}from"@orangecatai/common";import{pointFrom as v0e,pointRotateRads as T0e}from"@orangecatai/math";import{BOUND_TEXT_PADDING as W1e,DEFAULT_FONT_SIZE as Y1e,DEFAULT_FONT_FAMILY as V1e,getFontString as K1e,isTestEnv as X1e,normalizeEOL as $1e}from"@orangecatai/common";var Z1e="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".toLocaleUpperCase();import{isDevEnv as o0e,isTestEnv as n0e}from"@orangecatai/common";import{curvePointDistance as D0e,distanceToLineSegment as _0e,pointRotateRads as R0e}from"@orangecatai/math";import{ellipse as B0e,ellipseDistanceFromPoint as F0e}from"@orangecatai/math/ellipse";import{invariant as Ebe,isDevEnv as ybe,isTestEnv as wbe}from"@orangecatai/common";import{pointFrom as Tbe,pointFromVector as Ibe,pointRotateRads as Cbe,pointScaleFromOrigin as Sbe,pointsEqual as kbe,triangleIncludesPoint as Mbe,vectorCross as Pbe,vectorFromPoint as LN,vectorScale as Lbe}from"@orangecatai/math";var bf=[1,0],FT=[0,1],xf=[-1,0],OT=[0,-1],Im=e=>{let[o,t]=e,n=Math.abs(o),r=Math.abs(t);return o>r?bf:o<=-r?xf:t>n?FT:OT},zT=(e,o)=>Im(LN(e,o)),Cm=(e,o)=>Sm(zT(e,o)),ff=(e,o)=>e[0]===o[0]&&e[1]===o[1],Sm=e=>ff(e,bf)||ff(e,xf);import{clamp as Bbe,pointDistance as Fbe,pointFrom as Obe,pointScaleFromOrigin as zbe,pointsEqual as Hbe,pointTranslate as Gbe,vector as Ube,vectorCross as Wbe,vectorFromPoint as Ybe,vectorScale as Vbe}from"@orangecatai/math";import{BinaryHeap as Xbe,invariant as $be,isAnyTrue as Zbe,getSizeFromPoints as jbe,isDevEnv as qbe,arrayToMap as Jbe}from"@orangecatai/common";var Kxe=10/1.5;import{SHIFT_LOCKING_ANGLE as qxe,viewportCoordsToSceneCoords as Jxe}from"@orangecatai/common";import{normalizeRadians as eEe,radiansBetweenAngles as tEe,radiansDifference as oEe}from"@orangecatai/math";import{pointsEqual as rEe}from"@orangecatai/math";var vm=e=>{let o=Math.floor(e.width/2)+1,t=0,n=e.width,r=Math.floor(e.height/2)+1,i=o,a=e.height;return[o,t,n,r,i,a,0,r]};var ON=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}},zN=e=>{switch(e){case"bar":return 90;case"arrow":return 20;default:return 25}},yf=(e,o,t,n)=>{if(o.length<1)return null;let r=sf(o[0]);if(r.length<1)return null;let i=t==="start"?1:r.length-1,a=r[i].data;GT(a.length===6,"Op data length is not 6");let s=vt(a[4],a[5]),l=vt(a[2],a[3]),c=vt(a[0],a[1]),m=r[i-1],p=vt(0,0);if(m.op==="move"){let G=FN(m.data);GT(G!=null,"Op data is not a point"),p=G}else m.op==="bcurveTo"&&(p=vt(m.data[4],m.data[5]));let d=(G,Y)=>Math.pow(1-G,3)*s[Y]+3*G*Math.pow(1-G,2)*l[Y]+3*Math.pow(G,2)*(1-G)*c[Y]+p[Y]*Math.pow(G,3),[u,b]=t==="start"?p:s,[g,E]=[d(.3,0),d(.3,1)],w=Math.hypot(u-g,b-E),x=(u-g)/w,y=(b-E)/w,v=ON(n),T=0;{let[G,Y]=t==="end"?e.points[e.points.length-1]:e.points[0],[R,F]=e.points.length>1?t==="end"?e.points[e.points.length-2]:e.points[1]:[0,0];T=Math.hypot(G-R,Y-F)}let M=Math.min(v,T*(n==="diamond"||n==="diamond_outline"?.25:.5)),S=u-x*M,D=b-y*M;if(n==="dot"||n==="circle"||n==="circle_outline"){let G=Math.hypot(D-b,S-u)+e.strokeWidth-2;return[u,b,G]}let _=zN(n);if(n==="crowfoot_many"||n==="crowfoot_one_or_many"){let[G,Y]=Va(vt(u,b),vt(S,D),Ef(-_)),[R,F]=Va(vt(u,b),vt(S,D),Ef(_));return[S,D,G,Y,R,F]}let[P,A]=Va(vt(S,D),vt(u,b),-_*Math.PI/180),[z,V]=Va(vt(S,D),vt(u,b),Ef(_));if(n==="diamond"||n==="diamond_outline"){let G,Y;if(t==="start"){let[R,F]=e.points.length>1?e.points[1]:[0,0];[G,Y]=Va(vt(u+M*2,b),vt(u,b),Math.atan2(F-b,R-u))}else{let[R,F]=e.points.length>1?e.points[e.points.length-2]:[0,0];[G,Y]=Va(vt(u-M*2,b),vt(u,b),Math.atan2(b-F,u-R))}return[u,b,P,A,G,Y,z,V]}return[u,b,P,A,z,V]};import{pointFrom as Sye,pointCenter as kye,pointRotateRads as Mye,vectorFromPoint as Pye,vectorNormalize as Lye,vectorSubtract as Aye,vectorAdd as Dye,vectorScale as _ye,pointFromVector as Rye,clamp as Nye,isCloseTo as Bye}from"@orangecatai/math";import{arrayToMap as vwe}from"@orangecatai/common";import{isPointWithinBounds as Iwe,pointFrom as Cwe}from"@orangecatai/math";import{vectorCross as Gye,vectorFromPoint as Uye}from"@orangecatai/math";import{arrayToMap as HN}from"@orangecatai/common";import{getElementBounds as GN}from"@orangecatai/element";import{isArrowElement as UN,isExcalidrawElement as WN,isFreeDrawElement as YN,isLinearElement as VN,isTextElement as KN}from"@orangecatai/element";import{rangeIncludesValue as km,pointFrom as Rn,pointRotateRads as XN,rangeInclusive as Mm}from"@orangecatai/math";var $N=e=>e.type==="diamond"?[Rn(e.width/2,0),Rn(e.width,e.height/2),Rn(e.width/2,e.height),Rn(0,e.height/2)]:[Rn(0,0),Rn(0+e.width,0),Rn(0+e.width,e.height),Rn(0,e.height)],ZN=e=>VN(e)||YN(e)?e.points:$N(e),WT=e=>{let o=e.reduce((t,[n,r])=>(t.minY=Math.min(t.minY,r),t.minX=Math.min(t.minX,n),t.maxX=Math.max(t.maxX,n),t.maxY=Math.max(t.maxY,r),t),{minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0,cx:0,cy:0});return o.cx=(o.maxX+o.minX)/2,o.cy=(o.maxY+o.minY)/2,o},YT=e=>{let o=ZN(e),{cx:t,cy:n}=WT(o),r=Rn(t,n),i=o.map(m=>XN(m,r,e.angle)),{minX:a,minY:s,maxX:l,maxY:c}=WT(i);return[a+e.x,s+e.y,l+e.x,c+e.y]},wf=(e,o,t=!1)=>{let n=YT(e),r=o[0]<=n[0]&&o[2]>=n[2]&&o[1]<=n[1]&&o[3]>=n[3];return t?r?!0:n[0]<=o[0]&&n[2]>=o[2]&&n[1]<=o[1]&&n[3]>=o[3]:r},VT=(e,o)=>{let t=YT(e);return(km(t[0],Mm(o[0],o[2]))||km(o[0],Mm(t[0],t[2])))&&(km(t[1],Mm(o[1],o[3]))||km(o[1],Mm(t[1],t[3])))},KT=({elements:e,bounds:o,type:t,errorMargin:n=0})=>{WN(o)&&(o=GN(o,HN(e)));let r=[o[0]-n,o[1]-n,o[2]+n,o[3]+n],i=new Set;for(let a of e){if(i.has(a.id))continue;if(t==="overlap"?VT(a,r):t==="inside"?wf(a,r):wf(a,r,!0)){if(i.add(a.id),a.boundElements)for(let l of a.boundElements)i.add(l.id);KN(a)&&a.containerId&&i.add(a.containerId),UN(a)&&(a.startBinding&&i.add(a.startBinding.elementId),a.endBinding&&i.add(a.endBinding?.elementId))}}return e.filter(a=>i.has(a.id))};import{arrayToMap as rwe,isShallowEqual as qN}from"@orangecatai/common";var jN=function(){let e=null,o=null,t=null,n=(i,a,s,l)=>{if(t!==void 0&&a===o&&i===e&&s.editingGroupId===t?.editingGroupId)return t;let c={};for(let d of i){let u=d.groupIds;if(s.editingGroupId){let b=u.indexOf(s.editingGroupId);b>-1&&(u=u.slice(0,b))}if(u.length>0){let b=u[u.length-1];c[b]=!0}}let m={},p=a.reduce((d,u)=>{if(u.isDeleted)return d;let b=u.groupIds.find(g=>c[g]);return b&&(d[u.id]=!0,Array.isArray(m[b])?m[b].push(u.id):m[b]=[u.id]),d},{});for(let d of Object.keys(m))m[d].length<2&&c[d]&&(c[d]=!1);return o=a,e=i,t={editingGroupId:s.editingGroupId,selectedGroupIds:c,selectedElementIds:vf({...s.selectedElementIds,...p},l)},t},r=(i,a,s,l)=>{let c=l?l.scene.getSelectedElements({selectedElementIds:i.selectedElementIds,elements:a}):Tf(a,i);return c.length?n(c,a,i,s):{selectedGroupIds:{},editingGroupId:null,selectedElementIds:vf(i.selectedElementIds,s)}};return r.clearCache=()=>{o=null,e=null,t=null},r}();var mwe=function(){let e=null,o=null,t=null,n=(r,i)=>(t!=null&&r===e&&i.selectedElementIds===o||(t=r.some(a=>i.selectedElementIds[a.id]),e=r,o=i.selectedElementIds),t);return n.clearCache=()=>{e=null,o=null,t=null},n}(),Tf=(e,o,t)=>{let n=new Set,r=[];for(let i of e.values()){if(o.selectedElementIds[i.id]){r.push(i),n.add(i.id);continue}if(t?.includeBoundTextElement&&Ga(i)&&o.selectedElementIds[i?.containerId]){r.push(i),n.add(i.id);continue}}if(t?.includeElementsInFrames){let i=[];return r.forEach(a=>{ym(a)&&XT(e,a.id).forEach(s=>!n.has(s.id)&&i.push(s)),i.push(a)}),i}return r};var vf=(e,o)=>qN(o.selectedElementIds,e)?o.selectedElementIds:e;var XT=(e,o)=>{let t=[];for(let n of e.values())n.frameId===o&&t.push(n);return t};var QN=typeof document<"u"?document.createElement("img"):{src:""};QN.src=`data:${$T.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 e9=typeof document<"u"?document.createElement("img"):{src:""};e9.src=`data:${$T.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 If=new WeakMap;var ZT=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="line"||e==="diamond"||e==="image";var Yt=class Yt{};k(Yt,"rg",new s9),k(Yt,"cache",new WeakMap),k(Yt,"get",(o,t)=>{let n=Yt.cache.get(o);if(n&&(t===null||n.theme===t))return n.shape}),k(Yt,"delete",o=>{Yt.cache.delete(o),If.delete(o)}),k(Yt,"destroy",()=>{Yt.cache=new WeakMap}),k(Yt,"generateElementShape",(o,t)=>{let n=t?.isExporting?void 0:Yt.get(o,t?t.theme:null);if(n!==void 0)return n;If.delete(o);let r=d9(o,Yt.rg,t||{isExporting:!1,canvasBackgroundColor:a9.white,embedsValidationStatus:null,theme:Cf.LIGHT});return t?.isExporting||Yt.cache.set(o,{shape:r,theme:t?.theme||Cf.LIGHT}),r});var Ya=Yt,l9=e=>[8,8+e],e3=e=>[1.5,6+e];function c9(e){let o=e.roughness,t=Math.max(e.width,e.height),n=Math.min(e.width,e.height);return n>=20&&t>=50||n>=15&&e.roundness&&ZT(e.type)||ui(e)&&t>=50?o:Math.min(o/(t<10?3:2),2.5)}var _n=(e,o=!1,t=!1)=>{let n={seed:e.seed,strokeLineDash:e.strokeStyle==="dashed"?l9(e.strokeWidth):e.strokeStyle==="dotted"?e3(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:c9(e),stroke:t?Pm(e.strokeColor):e.strokeColor,preserveVertices:o||e.roughness<r9.cartoonist};switch(e.type){case"rectangle":case"iframe":case"embeddable":case"diamond":case"ellipse":return n.fillStyle=e.fillStyle,n.fill=Pl(e.backgroundColor)?void 0:t?Pm(e.backgroundColor):e.backgroundColor,e.type==="ellipse"&&(n.curveFitting=1),n;case"line":case"freedraw":return wm(e.points)&&(n.fillStyle=e.fillStyle,n.fill=e.backgroundColor==="transparent"?void 0:t?Pm(e.backgroundColor):e.backgroundColor),n;case"arrow":return n;default:throw new Error(`Unimplemented type ${e.type}`)}},qT=(e,o,t)=>lf(e)&&(o||_T(e)&&t?.get(e.id)!==!0)&&Pl(e.backgroundColor)&&Pl(e.strokeColor)?{...e,roughness:0,backgroundColor:"#d3d3d3",fillStyle:"solid"}:RT(e)?{...e,strokeColor:Pl(e.strokeColor)?"#000000":e.strokeColor,backgroundColor:Pl(e.backgroundColor)?"#f4f4f6":e.backgroundColor}:e,JT=(e,o,t,n,r,i,a,s)=>{let l=yf(e,o,t,n);if(l===null)return[];let c=(p,d)=>{if(p===null)return[];let[,,u,b,g,E]=p;return[r.line(u,b,g,E,d)]},m=s?Pm(e.strokeColor):e.strokeColor;switch(n){case"dot":case"circle":case"circle_outline":{let[p,d,u]=l;return delete i.strokeLineDash,[r.circle(p,d,u,{...i,fill:n==="circle_outline"?a:m,fillStyle:"solid",stroke:m,roughness:Math.min(.5,i.roughness||0)})]}case"triangle":case"triangle_outline":{let[p,d,u,b,g,E]=l;return delete i.strokeLineDash,[r.polygon([[p,d],[u,b],[g,E],[p,d]],{...i,fill:n==="triangle_outline"?a:m,fillStyle:"solid",roughness:Math.min(1,i.roughness||0)})]}case"diamond":case"diamond_outline":{let[p,d,u,b,g,E,w,x]=l;return delete i.strokeLineDash,[r.polygon([[p,d],[u,b],[g,E],[w,x],[p,d]],{...i,fill:n==="diamond_outline"?a:m,fillStyle:"solid",roughness:Math.min(1,i.roughness||0)})]}case"crowfoot_one":return c(l,i);case"bar":case"arrow":case"crowfoot_many":case"crowfoot_one_or_many":default:{let[p,d,u,b,g,E]=l;if(e.strokeStyle==="dotted"){let w=e3(e.strokeWidth-1);i.strokeLineDash=[w[0],w[1]-1]}else delete i.strokeLineDash;return i.roughness=Math.min(1,i.roughness||0),[r.line(u,b,p,d,i),r.line(g,E,p,d,i),...n==="crowfoot_one_or_many"?c(yf(e,o,t,"crowfoot_one"),i):[]]}}};var d9=(e,o,{isExporting:t,canvasBackgroundColor:n,embedsValidationStatus:r,theme:i})=>{let a=i===Cf.DARK;switch(e.type){case"rectangle":case"iframe":case"embeddable":{let s;if(e.roundness){let l=e.width,c=e.height,m=kl(Math.min(l,c),e);s=o.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`,_n(qT(e,t,r),!0,a))}else s=o.rectangle(0,0,e.width,e.height,_n(qT(e,t,r),!1,a));return s}case"diamond":{let s,[l,c,m,p,d,u,b,g]=vm(e);if(e.roundness){let E=kl(Math.abs(l-b),e),w=kl(Math.abs(p-c),e);s=o.path(`M ${l+E} ${c+w} L ${m-E} ${p-w}
|
|
8
|
-
C ${m} ${p}, ${m} ${p}, ${m-E} ${p+
|
|
9
|
-
L ${d+E} ${u-
|
|
10
|
-
C ${d} ${u}, ${d} ${u}, ${d-E} ${u-
|
|
11
|
-
L ${b+E} ${g+
|
|
12
|
-
C ${b} ${g}, ${b} ${g}, ${b+E} ${g-
|
|
13
|
-
L ${l-E} ${c+
|
|
14
|
-
C ${l} ${c}, ${l} ${c}, ${l+E} ${c+w}`,_n(e,!0,a))}else s=o.polygon([[l,c],[m,p],[d,u],[b,g]],_n(e,!1,a));return s}case"ellipse":return o.ellipse(e.width/2,e.height/2,e.width,e.height,_n(e,!1,a));case"line":case"arrow":{let s,l=_n(e,!1,a),c=e.points.length?e.points:[n9(0,0)];if(Sl(e)?c.every(m=>Math.abs(m[0])<=1e6&&Math.abs(m[1])<=1e6)?s=[o.path(m9(c,16),_n(e,!0,a))]:(console.error("Elbow arrow with extreme point positions detected. Arrow not rendered.",e.id,JSON.stringify(c)),s=[]):e.roundness?s=[o.curve(c,l)]:l.fill?s=[o.polygon(c,l)]:s=[o.linearPath(c,l)],e.type==="arrow"){let{startArrowhead:m=null,endArrowhead:p="arrow"}=e;if(m!==null){let d=JT(e,s,"start",m,o,l,n,a);s.push(...d)}if(p!==null){let d=JT(e,s,"end",p,o,l,n,a);s.push(...d)}}return s}case"freedraw":{let s=[];if(wm(e.points)){let l=t9(e.points,.75);s.push(o.curve(l,{..._n(e,!1,a),stroke:"none"}))}return s.push(p9(e)),s}case"frame":case"magicframe":case"text":case"image":return null;default:return i9(e,`generateElementShape(): Unimplemented type ${e?.type}`),null}},m9=(e,o)=>{let t=[];for(let r=1;r<e.length-1;r+=1){let i=e[r-1],a=e[r+1],s=e[r],l=Cm(s,i),c=Cm(a,s),m=Math.min(o,jT(e[r],a)/2,jT(e[r],i)/2);l?i[0]<s[0]?t.push([e[r][0]-m,e[r][1]]):t.push([e[r][0]+m,e[r][1]]):i[1]<s[1]?t.push([e[r][0],e[r][1]-m]):t.push([e[r][0],e[r][1]+m]),t.push(e[r]),c?a[0]<s[0]?t.push([e[r][0]-m,e[r][1]]):t.push([e[r][0]+m,e[r][1]]):a[1]<s[1]?t.push([e[r][0],e[r][1]-m]):t.push([e[r][0],e[r][1]+m])}let n=[`M ${e[0][0]} ${e[0][1]}`];for(let r=0;r<t.length;r+=3)n.push(`L ${t[r][0]} ${t[r][1]}`),n.push(`Q ${t[r+1][0]} ${t[r+1][1]}, ${t[r+2][0]} ${t[r+2][1]}`);return n.push(`L ${e[e.length-1][0]} ${e[e.length-1][1]}`),n.join(" ")};var p9=e=>h9(u9(e)),u9=e=>{let o=e.simulatePressure?e.points:e.points.length?e.points.map(([t,n],r)=>[t,n,e.pressures[r]]):[[0,0,.5]];return o9(o,{simulatePressure:e.simulatePressure,size:e.strokeWidth*4.25,thinning:.6,smoothing:.5,streamline:.5,easing:t=>Math.sin(t*Math.PI/2),last:!0})},QT=(e,o)=>[(e[0]+o[0])/2,(e[1]+o[1])/2],g9=/(\s?[A-Z]?,?-?[0-9]*\.[0-9]{0,2})(([0-9]|e|-)*)/g,h9=e=>{if(!e.length)return"";let o=e.length-1;return e.reduce((t,n,r,i)=>(r===o?t.push(n,QT(n,i[0]),"L",i[0],"Z"):t.push(n,QT(n,i[r+1])),t),["M",e[0],"Q"]).join(" ").replace(g9,"$1")};var t3=(e,o,t=!1)=>{let n=!1;for(let r in o){let i=o[r];if(typeof i<"u"){if(e[r]===i&&(typeof i!="object"||i===null))continue;n=!0}}return!n&&!t?e:{...e,...o,version:o.version??e.version+1,versionNonce:o.versionNonce??f9(),updated:b9()}};import{jsx as n3}from"react/jsx-runtime";var Xa=O({name:"toggleLinearEditor",category:Ye.elements,label:(e,o,t)=>t.scene.getSelectedElements({selectedElementIds:o.selectedElementIds})[0]?.type==="arrow"?"labels.lineEditor.editArrow":"labels.lineEditor.edit",keywords:["line"],trackEvent:{category:"element"},predicate:(e,o,t,n)=>{let r=n.scene.getSelectedElements(o);return!!(!o.selectedLinearElement?.isEditing&&r.length===1&&E9(r[0])&&!x9(r[0]))},perform(e,o,t,n){let r=n.scene.getSelectedElements({selectedElementIds:o.selectedElementIds,includeBoundTextElement:!0})[0];Sf(r,"No selected element found"),Sf(o.selectedLinearElement,"No selected linear element found"),Sf(r.id===o.selectedLinearElement.elementId,"Selected element ID and linear editor elementId does not match");let i={...o.selectedLinearElement,isEditing:!o.selectedLinearElement.isEditing};return{appState:{...o,selectedLinearElement:i},captureUpdate:o3.IMMEDIATELY}},PanelComponent:({appState:e,updateData:o,app:t})=>{let n=t.scene.getSelectedElements({selectedElementIds:e.selectedElementIds})[0];if(!n)return null;let r=h(n.type==="arrow"?"labels.lineEditor.editArrow":"labels.lineEditor.edit");return n3(Q,{type:"button",icon:_E,title:r,"aria-label":r,onClick:()=>o(null)})}}),m2e=O({name:"togglePolygon",category:Ye.elements,icon:xu,keywords:["loop"],label:(e,o,t)=>!t.scene.getSelectedElements({selectedElementIds:o.selectedElementIds}).some(i=>!Ka(i)||!i.polygon)?"labels.polygon.breakPolygon":"labels.polygon.convertToPolygon",trackEvent:{category:"element"},predicate:(e,o,t,n)=>{let r=n.scene.getSelectedElements({selectedElementIds:o.selectedElementIds});return r.length>0&&r.every(i=>Ka(i)&&i.points.length>=4)},perform(e,o,t,n){let r=n.scene.getSelectedElements(o);if(r.some(l=>!Ka(l)))return!1;let i=r,a=i.some(l=>!l.polygon),s=y9(i);return{elements:e.map(l=>!s.has(l.id)||!Ka(l)?l:t3(l,{backgroundColor:a?l.backgroundColor:"transparent",...w9(l,a)})),appState:o,captureUpdate:o3.IMMEDIATELY}},PanelComponent:({appState:e,updateData:o,app:t})=>{let n=t.scene.getSelectedElements({selectedElementIds:e.selectedElementIds});if(n.length===0||n.some(a=>!Ka(a)||!a.polygon||a.points.length<3))return null;let r=n.every(a=>Ka(a)&&a.polygon),i=h(r?"labels.polygon.breakPolygon":"labels.polygon.convertToPolygon");return n3(na,{icon:xu,title:i,"aria-label":i,active:r,onClick:()=>o(null),style:{marginLeft:"auto"}})}});import{KEYS as r3,CANVAS_SEARCH_TAB as i3,CLASSES as v9,DEFAULT_SIDEBAR as a3}from"@orangecatai/common";import{CaptureUpdateAction as T9}from"@orangecatai/element";var Cl=O({name:"searchMenu",icon:jt,keywords:["search","find"],label:"search.title",viewMode:!0,trackEvent:{category:"search_menu",action:"toggle",predicate:e=>e.gridModeEnabled},perform(e,o,t,n){if(o.openDialog)return!1;if(o.openSidebar?.name===a3.name&&o.openSidebar.tab===i3){let r=n.excalidrawContainerValue.container?.querySelector(`.${v9.SEARCH_MENU_INPUT_WRAPPER} input`);return r?.focus(),r?.select(),!1}return{appState:{...o,openSidebar:{name:a3.name,tab:i3},openDialog:null},captureUpdate:T9.EVENTUALLY}},checked:e=>e.gridModeEnabled,predicate:(e,o,t)=>t.gridModeEnabled===void 0,keyTest:e=>e[r3.CTRL_OR_CMD]&&e.key===r3.F});import{isImageElement as I9}from"@orangecatai/element";import{CaptureUpdateAction as C9}from"@orangecatai/element";import{jsx as S9}from"react/jsx-runtime";var kf=O({name:"cropEditor",label:"helpDialog.cropStart",icon:Hu,viewMode:!0,trackEvent:{category:"menu"},keywords:["image","crop"],perform(e,o,t,n){let r=n.scene.getSelectedElements({selectedElementIds:o.selectedElementIds,includeBoundTextElement:!0})[0];return{appState:{...o,isCropping:!1,croppingElementId:r.id},captureUpdate:C9.IMMEDIATELY}},predicate:(e,o,t,n)=>{let r=n.scene.getSelectedElements(o);return!!(!o.croppingElementId&&r.length===1&&I9(r[0]))},PanelComponent:({appState:e,updateData:o,app:t})=>{let n=h("helpDialog.cropStart");return S9(Q,{type:"button",icon:Hu,title:n,"aria-label":n,onClick:()=>o(null)})}});import{getNonDeletedElements as k9}from"@orangecatai/element";import{mutateElement as M9}from"@orangecatai/element";import{newFrameElement as P9}from"@orangecatai/element";import{isFrameLikeElement as Lm}from"@orangecatai/element";import{addElementsToFrame as L9,removeAllElementsFromFrame as A9}from"@orangecatai/element";import{getFrameChildren as D9}from"@orangecatai/element";import{KEYS as s3,updateActiveTool as l3}from"@orangecatai/common";import{getElementsInGroup as _9}from"@orangecatai/element";import{getCommonBounds as R9}from"@orangecatai/element";import{CaptureUpdateAction as hi}from"@orangecatai/element";var c3=(e,o)=>{let t=o.scene.getSelectedElements(e);return t.length===1&&Lm(t[0])},d3=O({name:"selectAllElementsInFrame",label:"labels.selectAllElementsInFrame",trackEvent:{category:"canvas"},perform:(e,o,t,n)=>{let r=n.scene.getSelectedElements(o).at(0)||null;if(Lm(r)){let i=D9(k9(e),r.id).filter(a=>!(a.type==="text"&&a.containerId));return{elements:e,appState:{...o,selectedElementIds:i.reduce((a,s)=>(a[s.id]=!0,a),{})},captureUpdate:hi.IMMEDIATELY}}return{elements:e,appState:o,captureUpdate:hi.EVENTUALLY}},predicate:(e,o,t,n)=>c3(o,n)}),m3=O({name:"removeAllElementsFromFrame",label:"labels.removeAllElementsFromFrame",trackEvent:{category:"history"},perform:(e,o,t,n)=>{let r=n.scene.getSelectedElements(o).at(0)||null;return Lm(r)?{elements:A9(e,r),appState:{...o,selectedElementIds:{[r.id]:!0}},captureUpdate:hi.IMMEDIATELY}:{elements:e,appState:o,captureUpdate:hi.EVENTUALLY}},predicate:(e,o,t,n)=>c3(o,n)}),yTe=O({name:"updateFrameRendering",label:"labels.updateFrameRendering",viewMode:!0,trackEvent:{category:"canvas"},perform:(e,o)=>({elements:e,appState:{...o,frameRendering:{...o.frameRendering,enabled:!o.frameRendering.enabled}},captureUpdate:hi.EVENTUALLY}),checked:e=>e.frameRendering.enabled}),wTe=O({name:"setFrameAsActiveTool",label:"toolBar.frame",trackEvent:{category:"toolbar"},icon:ko,viewMode:!1,perform:(e,o,t,n)=>{let r=l3(o,{type:"frame"});return Qt(n.interactiveCanvas,{...o,activeTool:r}),{elements:e,appState:{...o,activeTool:l3(o,{type:"frame"})},captureUpdate:hi.EVENTUALLY}},keyTest:e=>!e[s3.CTRL_OR_CMD]&&!e.shiftKey&&!e.altKey&&e.key.toLocaleLowerCase()===s3.F}),p3=O({name:"wrapSelectionInFrame",label:"labels.wrapSelectionInFrame",trackEvent:{category:"element"},predicate:(e,o,t,n)=>{let r=ne(e,o);return r.length>0&&!r.some(i=>Lm(i))},perform:(e,o,t,n)=>{let r=ne(e,o),i=n.scene.getNonDeletedElementsMap(),[a,s,l,c]=R9(r,i),m=16,p=P9({x:a-m,y:s-m,width:l-a+m*2,height:c-s+m*2});if(o.editingGroupId){let u=_9(r,o.editingGroupId);for(let b of u){let g=b.groupIds.indexOf(o.editingGroupId);M9(b,i,{groupIds:b.groupIds.slice(0,g)})}}return{elements:L9([...n.scene.getElementsIncludingDeleted(),p],r,p,o),appState:{selectedElementIds:{[p.id]:!0}},captureUpdate:hi.IMMEDIATELY}}});import{isWindows as G9,KEYS as Al,matchKey as Lf,arrayToMap as u3,MOBILE_ACTION_BUTTON_BG as g3}from"@orangecatai/common";import{CaptureUpdateAction as Pf}from"@orangecatai/element";import{orderByFractionalIndex as U9}from"@orangecatai/element";import{Emitter as N9}from"@orangecatai/common";import{CaptureUpdateAction as B9,StoreChange as F9,StoreDelta as O9}from"@orangecatai/element";var $a=class extends O9{applyTo(o,t,n){let[r,i]=this.elements.applyTo(o,n.elements,{excludedProperties:new Set(["version","versionNonce"])}),[a,s]=this.appState.applyTo(t,r);return[r,a,i||s]}static calculate(o,t){return super.calculate(o,t)}static inverse(o){return super.inverse(o)}static applyLatestChanges(o,t,n,r){return super.applyLatestChanges(o,t,n,r)}},fi=class{constructor(o=!0,t=!0){this.isUndoStackEmpty=o;this.isRedoStackEmpty=t}},Ll=class e{constructor(o){this.store=o;k(this,"onHistoryChangedEmitter",new N9);k(this,"undoStack",[]);k(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(o){if(o.isEmpty()||o instanceof $a)return;let t=$a.inverse(o);this.undoStack.push(t),t.elements.isEmpty()||(this.redoStack.length=0),this.onHistoryChangedEmitter.trigger(new fi(this.isUndoStackEmpty,this.isRedoStackEmpty))}undo(o,t){return this.perform(o,t,()=>e.pop(this.undoStack),n=>e.push(this.redoStack,n))}redo(o,t){return this.perform(o,t,()=>e.pop(this.redoStack),n=>e.push(this.undoStack,n))}perform(o,t,n,r){try{let i=n();if(i===null)return;let a=B9.IMMEDIATELY,s=this.store.snapshot,l=o,c=t,m=!1;for(;i;){try{[l,c,m]=i.applyTo(l,c,s);let p=s.elements,d=s.maybeClone(a,l,c),u=F9.create(s,d),b=$a.applyLatestChanges(i,p,l);b.isEmpty()||(this.store.scheduleMicroAction({action:a,change:u,delta:b}),i=b),s=d}finally{r(i)}if(m)break;i=n()}return[l,c]}finally{this.onHistoryChangedEmitter.trigger(new fi(this.isUndoStackEmpty,this.isRedoStackEmpty))}}static pop(o){if(!o.length)return null;let t=o.pop();return t!==void 0?t:null}static push(o,t){let n=$a.inverse(t);return o.push(n)}};import{useEffect as z9,useState as H9}from"react";var Mf=(e,o)=>{let[t,n]=H9(o);return z9(()=>{let r=e.on(i=>{n(i)});return()=>{r()}},[e]),t};import{jsx as x3}from"react/jsx-runtime";var h3=(e,o,t)=>{if(!o.multiElement&&!o.resizingElement&&!o.editingTextElement&&!o.newElement&&!o.selectedElementsAreBeingDragged&&!o.selectionElement&&!e.flowChartCreator.isCreatingChart){let n=t();if(!n)return{captureUpdate:Pf.EVENTUALLY};let[r,i]=n,a=U9(Array.from(r.values()));return{appState:i,elements:a,captureUpdate:Pf.NEVER}}return{captureUpdate:Pf.EVENTUALLY}},f3=e=>({name:"undo",label:"buttons.undo",icon:vu,trackEvent:{category:"history"},viewMode:!1,perform:(o,t,n,r)=>h3(r,t,()=>e.undo(u3(o),t)),keyTest:o=>o[Al.CTRL_OR_CMD]&&Lf(o,Al.Z)&&!o.shiftKey,PanelComponent:({appState:o,updateData:t,data:n,app:r})=>{let{isUndoStackEmpty:i}=Mf(e.onHistoryChangedEmitter,new fi(e.isUndoStackEmpty,e.isRedoStackEmpty)),a=ut()==="mobile";return x3(Q,{type:"button",icon:vu,"aria-label":h("buttons.undo"),onClick:t,size:n?.size||"medium",disabled:i,"data-testid":"button-undo",style:{...a?g3:{}}})}}),b3=e=>({name:"redo",label:"buttons.redo",icon:Tu,trackEvent:{category:"history"},viewMode:!1,perform:(o,t,n,r)=>h3(r,t,()=>e.redo(u3(o),t)),keyTest:o=>o[Al.CTRL_OR_CMD]&&o.shiftKey&&Lf(o,Al.Z)||G9&&o.ctrlKey&&!o.shiftKey&&Lf(o,Al.Y),PanelComponent:({appState:o,updateData:t,data:n,app:r})=>{let{isRedoStackEmpty:i}=Mf(e.onHistoryChangedEmitter,new fi(e.isUndoStackEmpty,e.isRedoStackEmpty)),a=ut()==="mobile";return x3(Q,{type:"button",icon:Tu,"aria-label":h("buttons.redo"),onClick:t,size:n?.size||"medium",disabled:i,"data-testid":"button-redo",style:{...a?g3:{}}})}});import{getFontString as W9}from"@orangecatai/common";import{newElementWith as Y9}from"@orangecatai/element";import{measureText as V9}from"@orangecatai/element";import{isTextElement as E3}from"@orangecatai/element";import{CaptureUpdateAction as K9}from"@orangecatai/element";var y3=O({name:"autoResize",label:"labels.autoResize",icon:null,trackEvent:{category:"element"},predicate:(e,o,t,n)=>{let r=ne(e,o);return r.length===1&&E3(r[0])&&!r[0].autoResize},perform:(e,o,t,n)=>{let r=ne(e,o);return{appState:o,elements:e.map(i=>{if(i.id===r[0].id&&E3(i)){let a=V9(i.originalText,W9(i),i.lineHeight);return Y9(i,{autoResize:!0,width:a.width,height:a.height,text:i.originalText})}return i}),captureUpdate:K9.IMMEDIATELY}}});import{isPromiseLike as X9}from"@orangecatai/common";import{jsx as $9}from"react/jsx-runtime";var Af=(e,o,t,n,r,i)=>{if(e.trackEvent)try{typeof e.trackEvent=="object"&&(!e.trackEvent.predicate||e.trackEvent.predicate(t,n,i))&&me(e.trackEvent.category,e.trackEvent.action||e.name,`${o} (${r.editorInterface.formFactor==="phone"?"mobile":"desktop"})`)}catch(a){console.error("error while logging action:",a)}},Am=class{constructor(o,t,n,r){k(this,"actions",{});k(this,"updater");k(this,"getAppState");k(this,"getElementsIncludingDeleted");k(this,"app");k(this,"renderAction",(o,t)=>{let n=this.app.props.UIOptions.canvasActions;if(this.actions[o]&&"PanelComponent"in this.actions[o]&&(!(o in n)||n[o])){let r=this.actions[o],i=r.PanelComponent;i.displayName="PanelComponent";let a=this.getElementsIncludingDeleted(),s=this.getAppState(),l=c=>{Af(r,"ui",s,a,this.app,c),this.updater(r.perform(this.getElementsIncludingDeleted(),this.getAppState(),c,this.app))};return $9(i,{elements:this.getElementsIncludingDeleted(),appState:this.getAppState(),updateData:l,appProps:this.app.props,app:this.app,data:t,renderAction:this.renderAction})}return null});k(this,"isActionEnabled",o=>{let t=this.getElementsIncludingDeleted(),n=this.getAppState();return!o.predicate||o.predicate(t,n,this.app.props,this.app)});this.updater=i=>{if(X9(i))i.then(a=>o(a));else return o(i)},this.getAppState=t,this.getElementsIncludingDeleted=n,this.app=r}registerAction(o){this.actions[o.name]=o}registerAll(o){o.forEach(t=>this.registerAction(t))}handleKeyDown(o){let t=this.app.props.UIOptions.canvasActions,n=Object.values(this.actions).sort((l,c)=>(c.keyPriority||0)-(l.keyPriority||0)).filter(l=>(l.name in t?t[l.name]:!0)&&l.keyTest&&l.keyTest(o,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 i=this.getElementsIncludingDeleted(),a=this.getAppState(),s=null;return Af(r,"keyboard",a,i,this.app,null),o.preventDefault(),o.stopPropagation(),this.updater(n[0].perform(i,a,s,this.app)),!0}executeAction(o,t="api",n=null){let r=this.getElementsIncludingDeleted(),i=this.getAppState();Af(o,t,i,r,this.app,n),this.updater(o.perform(r,i,n,this.app))}};var Dm=class{constructor(){k(this,"targets",new WeakMap);k(this,"rafIds",new WeakMap)}register(o,t){this.targets.set(o,{callback:t,stopped:!0})}start(o){let t=this.targets.get(o);t&&(this.rafIds.has(o)||(this.targets.set(o,{...t,stopped:!1}),this.scheduleFrame(o)))}stop(o){let t=this.targets.get(o);t&&!t.stopped&&this.targets.set(o,{...t,stopped:!0}),this.cancelFrame(o)}constructFrame(o){return t=>{let n=this.targets.get(o);if(!n)return;let r=this.onFrame(n,t);!n.stopped&&!r?this.scheduleFrame(o):this.cancelFrame(o)}}scheduleFrame(o){let t=requestAnimationFrame(this.constructFrame(o));this.rafIds.set(o,t)}cancelFrame(o){if(this.rafIds.has(o)){let t=this.rafIds.get(o);cancelAnimationFrame(t)}this.rafIds.delete(o)}onFrame(o,t){return o.callback(t)??!1}};var Df=e=>{let o=Array.from(e.values());return{x:w3(o,t=>t.x)/o.length,y:w3(o,t=>t.y)/o.length}},_f=([e,o])=>Math.hypot(e.x-o.x,e.y-o.y),w3=(e,o)=>e.reduce((t,n)=>t+o(n),0);import{pointFrom as X,pointRotateRads as fr,rangeInclusive as uo,rangeIntersection as _m,rangesOverlap as Rm}from"@orangecatai/math";import{TOOL_TYPE as bi,KEYS as v3}from"@orangecatai/common";import{getCommonBounds as Rf,getDraggedElementsBounds as Nf,getElementAbsoluteCoords as Z9}from"@orangecatai/element";import{isBoundToContainer as S3}from"@orangecatai/element";import{getMaximumGroups as k3}from"@orangecatai/element";import{getSelectedElements as j9,getVisibleAndNonSelectedElements as M3}from"@orangecatai/element";var q9=8,T3=99999,Nm=e=>q9/e,Ot=class Ot{};k(Ot,"referenceSnapPoints",null),k(Ot,"visibleGaps",null),k(Ot,"setReferenceSnapPoints",o=>{Ot.referenceSnapPoints=o}),k(Ot,"getReferenceSnapPoints",()=>Ot.referenceSnapPoints),k(Ot,"setVisibleGaps",o=>{Ot.visibleGaps=o}),k(Ot,"getVisibleGaps",()=>Ot.visibleGaps),k(Ot,"destroy",()=>{Ot.referenceSnapPoints=null,Ot.visibleGaps=null});var go=Ot,br=e=>e.props.gridModeEnabled??e.state.gridModeEnabled,Nn=({event:e,app:o,selectedElements:t})=>{if(e){let n=o.state.activeTool.type==="lasso"&&o.state.selectedElementsAreBeingDragged;return(o.state.activeTool.type!=="lasso"||n)&&(o.state.objectsSnapModeEnabled&&!e[v3.CTRL_OR_CMD]||!o.state.objectsSnapModeEnabled&&e[v3.CTRL_OR_CMD]&&!br(o))}return t.length===1&&t[0].type==="arrow"?!1:o.state.objectsSnapModeEnabled},J9=(e,o,t=.01)=>Math.abs(e-o)<=t,Dl=(e,o,{omitCenter:t,boundingBoxCorners:n,dragOffset:r}={omitCenter:!1,boundingBoxCorners:!1})=>{let i=[];if(e.length===1){let a=e[0],[s,l,c,m,p,d]=Z9(a,o);r&&(s+=r.x,c+=r.x,p+=r.x,l+=r.y,m+=r.y,d+=r.y);let u=(c-s)/2,b=(m-l)/2;if((a.type==="diamond"||a.type==="ellipse")&&!n){let g=fr(X(s,l+b),X(p,d),a.angle),E=fr(X(s+u,l),X(p,d),a.angle),w=fr(X(c,l+b),X(p,d),a.angle),x=fr(X(s+u,m),X(p,d),a.angle),y=X(p,d);i=t?[g,E,w,x]:[g,E,w,x,y]}else{let g=fr(X(s,l),X(p,d),a.angle),E=fr(X(c,l),X(p,d),a.angle),w=fr(X(s,m),X(p,d),a.angle),x=fr(X(c,m),X(p,d),a.angle),y=X(p,d);i=t?[g,E,w,x]:[g,E,w,x,y]}}else if(e.length>1){let[a,s,l,c]=Nf(e,r??{x:0,y:0}),m=l-a,p=c-s,d=X(a,s),u=X(l,s),b=X(a,c),g=X(l,c),E=X(a+m/2,s+p/2);i=t?[d,u,b,g]:[d,u,b,g,E]}return i.map(a=>X($e(a[0]),$e(a[1])))},P3=(e,o,t,n)=>M3(e,o,t,n),L3=(e,o,t,n)=>{let r=P3(e,o,t,n),i=k3(r,n).filter(p=>!(p.length===1&&S3(p[0]))).map(p=>Rf(p).map(d=>$e(d))),a=i.sort((p,d)=>p[0]-d[0]),s=[],l=0;e:for(let p=0;p<a.length;p++){let d=a[p];for(let u=p+1;u<a.length;u++){if(++l>T3)break e;let b=a[u],[,g,E,w]=d,[x,y,,v]=b;E<x&&Rm(uo(g,w),uo(y,v))&&s.push({startBounds:d,endBounds:b,startSide:[X(E,g),X(E,w)],endSide:[X(x,y),X(x,v)],length:x-E,overlap:_m(uo(g,w),uo(y,v))})}}let c=i.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>T3)break e;let b=c[u],[g,,E,w]=d,[x,y,v]=b;w<y&&Rm(uo(g,E),uo(x,v))&&m.push({startBounds:d,endBounds:b,startSide:[X(g,w),X(E,w)],endSide:[X(x,y),X(v,y)],length:y-w,overlap:_m(uo(g,E),uo(x,v))})}}return{horizontalGaps:s,verticalGaps:m}},I3=(e,o,t,n,r,i,a)=>{if(!Nn({app:t,event:n,selectedElements:e}))return[];if(e.length===0)return[];let s=go.getVisibleGaps();if(s){let{horizontalGaps:l,verticalGaps:c}=s,[m,p,d,u]=Nf(e,o).map(E=>$e(E)),b=(m+d)/2,g=(p+u)/2;for(let E of l){if(!Rm(uo(p,u),E.overlap))continue;let w=E.startSide[0][0]+E.length/2,x=$e(w-b);if(E.length>d-m&&Math.abs(x)<=a.x){Math.abs(x)<a.x&&(r.length=0),a.x=Math.abs(x);let _={type:"gap",direction:"center_horizontal",gap:E,offset:x};r.push(_);continue}let[,,v]=E.endBounds,T=m-v,C=$e(E.length-T);if(Math.abs(C)<=a.x){Math.abs(C)<a.x&&(r.length=0),a.x=Math.abs(C);let _={type:"gap",direction:"side_right",gap:E,offset:C};r.push(_);continue}let[M,,,]=E.startBounds,S=M-d,D=$e(S-E.length);if(Math.abs(D)<=a.x){Math.abs(D)<a.x&&(r.length=0),a.x=Math.abs(D);let _={type:"gap",direction:"side_left",gap:E,offset:D};r.push(_);continue}}for(let E of c){if(!Rm(uo(m,d),E.overlap))continue;let w=E.startSide[0][1]+E.length/2,x=$e(w-g);if(E.length>u-p&&Math.abs(x)<=a.y){Math.abs(x)<a.y&&(i.length=0),a.y=Math.abs(x);let _={type:"gap",direction:"center_vertical",gap:E,offset:x};i.push(_);continue}let[,v,,]=E.startBounds,T=v-u,C=$e(T-E.length);if(Math.abs(C)<=a.y){Math.abs(C)<a.y&&(i.length=0),a.y=Math.abs(C);let _={type:"gap",direction:"side_top",gap:E,offset:C};i.push(_);continue}let[,,,M]=E.endBounds,S=$e(p-M),D=E.length-S;if(Math.abs(D)<=a.y){Math.abs(D)<a.y&&(i.length=0),a.y=Math.abs(D);let _={type:"gap",direction:"side_bottom",gap:E,offset:D};i.push(_);continue}}}},A3=(e,o,t,n)=>{let r=P3(e,o,t,n);return k3(r,n).filter(i=>!(i.length===1&&S3(i[0]))).flatMap(i=>Dl(i,n))},Za=(e,o,t,n,r,i,a)=>{if(!Nn({app:t,event:n,selectedElements:e})||e.length===0&&o.length===0)return[];let s=go.getReferenceSnapPoints();if(s)for(let l of o)for(let c of s){let m=c[0]-l[0],p=c[1]-l[1];Math.abs(m)<=a.x&&(Math.abs(m)<a.x&&(r.length=0),r.push({type:"point",points:[l,c],offset:m}),a.x=Math.abs(m)),Math.abs(p)<=a.y&&(Math.abs(p)<a.y&&(i.length=0),i.push({type:"point",points:[l,c],offset:p}),a.y=Math.abs(p))}},D3=(e,o,t,n,r)=>{let i=t.state,a=j9(e,i);if(!Nn({app:t,event:n,selectedElements:a})||a.length===0)return{snapOffset:{x:0,y:0},snapLines:[]};o.x=$e(o.x),o.y=$e(o.y);let s=[],l=[],c=Nm(i.zoom.value),m={x:c,y:c},p=Dl(a,r,{dragOffset:o});Za(a,p,t,n,s,l,m),I3(a,o,t,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:$e(o.x+d.x),y:$e(o.y+d.y)};Za(a,Dl(a,r,{dragOffset:u}),t,n,s,l,m),I3(a,u,t,n,s,l,m);let b=Bf(s,l),g=eB(a,u,[...s,...l].filter(E=>E.type==="gap"));return{snapOffset:d,snapLines:[...b,...g]}},$e=e=>Math.round(e*10**6)/10**6,C3=e=>{let o=new Map;for(let t of e){let n=t.join(",");o.has(n)||o.set(n,t)}return Array.from(o.values())},Bf=(e,o)=>{let t={},n={};if(e.length>0){for(let r of e)if(r.type==="point"){let i=$e(r.points[0][0]);t[i]||(t[i]=[]),t[i].push(...r.points.map(a=>X($e(a[0]),$e(a[1]))))}}if(o.length>0){for(let r of o)if(r.type==="point"){let i=$e(r.points[0][1]);n[i]||(n[i]=[]),n[i].push(...r.points.map(a=>X($e(a[0]),$e(a[1]))))}}return Object.entries(t).map(([r,i])=>({type:"points",points:C3(i.map(a=>X(Number(r),a[1])).sort((a,s)=>a[1]-s[1]))})).concat(Object.entries(n).map(([r,i])=>({type:"points",points:C3(i.map(a=>X(a[0],Number(r))).sort((a,s)=>a[0]-s[0]))})))},Q9=e=>{let o=new Map;for(let t of e){let n=t.points.flat().map(r=>[$e(r)]).join(",");o.has(n)||o.set(n,t)}return Array.from(o.values())},eB=(e,o,t)=>{let[n,r,i,a]=Nf(e,o),s=[];for(let l of t){let[c,m,p,d]=l.gap.startBounds,[u,b,g,E]=l.gap.endBounds,w=_m(uo(r,a),l.gap.overlap),x=_m(uo(n,i),l.gap.overlap);switch(l.direction){case"center_horizontal":{if(w){let y=(w[0]+w[1])/2;s.push({type:"gap",direction:"horizontal",points:[X(l.gap.startSide[0][0],y),X(n,y)]},{type:"gap",direction:"horizontal",points:[X(i,y),X(l.gap.endSide[0][0],y)]})}break}case"center_vertical":{if(x){let y=(x[0]+x[1])/2;s.push({type:"gap",direction:"vertical",points:[X(y,l.gap.startSide[0][1]),X(y,r)]},{type:"gap",direction:"vertical",points:[X(y,a),X(y,l.gap.endSide[0][1])]})}break}case"side_right":{if(w){let y=(w[0]+w[1])/2;s.push({type:"gap",direction:"horizontal",points:[X(p,y),X(u,y)]},{type:"gap",direction:"horizontal",points:[X(g,y),X(n,y)]})}break}case"side_left":{if(w){let y=(w[0]+w[1])/2;s.push({type:"gap",direction:"horizontal",points:[X(i,y),X(c,y)]},{type:"gap",direction:"horizontal",points:[X(p,y),X(u,y)]})}break}case"side_top":{if(x){let y=(x[0]+x[1])/2;s.push({type:"gap",direction:"vertical",points:[X(y,a),X(y,m)]},{type:"gap",direction:"vertical",points:[X(y,d),X(y,b)]})}break}case"side_bottom":{if(x){let y=(x[0]+x[1])/2;s.push({type:"gap",direction:"vertical",points:[X(y,d),X(y,b)]},{type:"gap",direction:"vertical",points:[X(y,E),X(y,r)]})}break}}}return Q9(s.map(l=>({...l,points:l.points.map(c=>X($e(c[0]),$e(c[1])))})))},Ff=(e,o,t,n,r,i)=>{if(!Nn({event:n,selectedElements:e,app:t})||e.length===0||e.length===1&&!J9(e[0].angle,0))return{snapOffset:{x:0,y:0},snapLines:[]};let[a,s,l,c]=Rf(o);i&&(i.includes("e")?l+=r.x:i.includes("w")&&(a+=r.x),i.includes("n")?s+=r.y:i.includes("s")&&(c+=r.y));let m=[];if(i)switch(i){case"e":{m.push(X(l,s),X(l,c));break}case"w":{m.push(X(a,s),X(a,c));break}case"n":{m.push(X(a,s),X(l,s));break}case"s":{m.push(X(a,c),X(l,c));break}case"ne":{m.push(X(l,s));break}case"nw":{m.push(X(a,s));break}case"se":{m.push(X(l,c));break}case"sw":{m.push(X(a,c));break}}let p=Nm(t.state.zoom.value),d={x:p,y:p},u=[],b=[];Za(o,m,t,n,u,b,d);let g={x:u[0]?.offset??0,y:b[0]?.offset??0};d.x=0,d.y=0,u.length=0,b.length=0;let[E,w,x,y]=Rf(e).map(C=>$e(C)),v=[X(E,w),X(E,y),X(x,w),X(x,y)];Za(e,v,t,n,u,b,d);let T=Bf(u,b);return{snapOffset:g,snapLines:T}},_3=(e,o,t,n,r,i)=>{if(!Nn({event:t,selectedElements:[e],app:o}))return{snapOffset:{x:0,y:0},snapLines:[]};let a=[X(n.x+r.x,n.y+r.y)],s=Nm(o.state.zoom.value),l={x:s,y:s},c=[],m=[];Za([e],a,o,t,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=Dl([e],i,{boundingBoxCorners:!0,omitCenter:!0});Za([e],d,o,t,c,m,l);let u=Bf(c,m);return{snapOffset:p,snapLines:u}},R3=(e,o,t,n,r)=>{if(!Nn({event:n,selectedElements:[],app:o}))return{originOffset:{x:0,y:0},snapLines:[]};let i=M3(e,[],o.state,r),a=Nm(o.state.zoom.value),s={x:a,y:a},l=[],c=[];for(let m of i){let p=Dl([m],r);for(let d of p){let u=d[0]-t.x;Math.abs(u)<=Math.abs(s.x)&&(Math.abs(u)<Math.abs(s.x)&&(c.length=0),c.push({type:"pointer",points:[d,X(d[0],t.y)],direction:"vertical"}),s.x=u);let b=d[1]-t.y;Math.abs(b)<=Math.abs(s.y)&&(Math.abs(b)<Math.abs(s.y)&&(l.length=0),l.push({type:"pointer",points:[d,X(t.x,d[1])],direction:"horizontal"}),s.y=b)}}return{originOffset:{x:c.length>0?c[0].points[0][0]-t.x:0,y:l.length>0?l[0].points[0][1]-t.y:0},snapLines:[...c,...l]}},N3=e=>e===bi.rectangle||e===bi.ellipse||e===bi.diamond||e===bi.frame||e===bi.magicframe||e===bi.image||e===bi.text;import{isElementInViewport as tB}from"@orangecatai/element";import{memoize as oB,toBrandedType as nB}from"@orangecatai/common";var _l=class{constructor(o){k(this,"scene");k(this,"getRenderableElements",(()=>{let o=({elementsMap:n,zoom:r,offsetLeft:i,offsetTop:a,scrollX:s,scrollY:l,height:c,width:m})=>{let p=[];for(let d of n.values())tB(d,m,c,{zoom:r,offsetLeft:i,offsetTop:a,scrollX:s,scrollY:l},n)&&p.push(d);return p},t=({elements:n,editingTextElement:r,newElementId:i})=>{let a=nB(new Map);for(let s of n)i!==s.id&&(!r||r.type!=="text"||s.id!==r.id)&&a.set(s.id,s);return a};return oB(({zoom:n,offsetLeft:r,offsetTop:i,scrollX:a,scrollY:s,height:l,width:c,editingTextElement:m,newElementId:p,sceneNonce:d})=>{let u=this.scene.getNonDeletedElements(),b=t({elements:u,editingTextElement:m,newElementId:p}),g=o({elementsMap:b,zoom:n,offsetLeft:r,offsetTop:i,scrollX:a,scrollY:s,height:l,width:c});return{elementsMap:b,visibleElements:g}})})());this.scene=o}destroy(){_b.cancel(),this.getRenderableElements.clear()}};import{sceneCoordsToViewportCoords as rB}from"@orangecatai/common";import{getElementAbsoluteCoords as iB}from"@orangecatai/element";import{jsx as lB}from"react/jsx-runtime";var aB=5,sB=(e,o,t)=>{let[n,r]=iB(e,t),{x:i,y:a}=rB({sceneX:n+e.width,sceneY:r},o),s=i-o.offsetLeft+10,l=a-o.offsetTop;return{x:s,y:l}},Of=({children:e,element:o,elementsMap:t})=>{let n=Zo();if(n.contextMenu||n.newElement||n.resizingElement||n.isRotating||n.openMenu||n.viewModeEnabled)return null;let{x:r,y:i}=sB(o,n,t);return lB("div",{className:"excalidraw-canvas-buttons",style:{top:`${i}px`,left:`${r}px`,padding:aB},children:e})};import{useCallback as Rl,useEffect as B3,useRef as cB,useState as Bm}from"react";import{sceneCoordsToViewportCoords as dB}from"@orangecatai/common";import{getElementAbsoluteCoords as mB}from"@orangecatai/element";import{isFrameLikeElement as pB}from"@orangecatai/element";import{Fragment as F3,jsx as Ie,jsxs as No}from"react/jsx-runtime";var O3=[{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"}],zf=e=>{let o={border:"1.5px solid currentColor",borderRadius:2,boxSizing:"border-box"};switch(e){case"square":return Ie("div",{style:{...o,width:14,height:14}});case"portrait":return Ie("div",{style:{...o,width:10,height:14}});case"portrait-tall":return Ie("div",{style:{...o,width:8,height:14}});case"landscape":return Ie("div",{style:{...o,width:14,height:10}});case"landscape-wide":return Ie("div",{style:{...o,width:14,height:8}});default:return Ie("div",{style:{...o,width:14,height:14}})}},uB=({active:e})=>Ie("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:e?No(F3,{children:[Ie("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"}),Ie("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"}),Ie("line",{x1:"5",y1:"7",x2:"9",y2:"7",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]}):No(F3,{children:[Ie("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"}),Ie("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"})]})}),gB=()=>No("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[Ie("path",{d:"M8 2V10M8 10L5 7M8 10L11 7",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"}),Ie("path",{d:"M3 12H13",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]}),hB=()=>Ie("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:Ie("path",{d:"M2.5 3.75L5 6.25L7.5 3.75",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),fB=()=>Ie("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:Ie("path",{d:"M3.5 8.5L6.5 11.5L12.5 4.5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),bB=(e,o)=>O3.find(t=>t.width===e&&t.height===o)||null,z3=({element:e,app:o})=>{let t=o.state,[n,r]=Bm(!1),[i,a]=Bm(!0),[s,l]=Bm(Math.round(e.width)),[c,m]=Bm(Math.round(e.height)),p=cB(null);B3(()=>{l(Math.round(e.width)),m(Math.round(e.height))},[e.width,e.height]),B3(()=>{let S=D=>{p.current&&!p.current.contains(D.target)&&r(!1)};if(n)return document.addEventListener("mousedown",S),()=>document.removeEventListener("mousedown",S)},[n]);let d=bB(Math.round(e.width),Math.round(e.height)),[u,b]=mB(e,o.scene.getNonDeletedElementsMap()),{x:g,y:E}=dB({sceneX:u+e.width/2,sceneY:b},t),w=g-t.offsetLeft,x=Math.max(E-t.offsetTop-82,8),y=Rl((S,D)=>{S>0&&D>0&&o.scene.mutateElement(e,{width:S,height:D})},[o.scene,e]),v=Rl(S=>{let D=parseInt(S,10);if(!isNaN(D)&&D>0)if(l(D),i){let _=e.height/e.width,P=Math.round(D*_);m(P),y(D,P)}else y(D,e.height)},[i,e.width,e.height,y]),T=Rl(S=>{let D=parseInt(S,10);if(!isNaN(D)&&D>0)if(m(D),i){let _=e.width/e.height,P=Math.round(D*_);l(P),y(P,D)}else y(e.width,D)},[i,e.width,e.height,y]),C=Rl(S=>{l(S.width),m(S.height),y(S.width,S.height),r(!1)},[y]),M=Rl(()=>{pB(e)&&o.onExportImage("png",o.getSceneElements(),{exportingFrame:e})},[o,e]);return t.contextMenu||t.newElement||t.resizingElement||t.isRotating||t.openMenu||t.viewModeEnabled||t.selectedElementsAreBeingDragged?null:No("div",{className:"frame-toolbar",style:{left:`${w}px`,top:`${x}px`},onPointerDown:S=>S.stopPropagation(),onClick:S=>S.stopPropagation(),children:[No("div",{className:"frame-toolbar__section",ref:p,children:[No("button",{className:"frame-toolbar__ratio-btn",onClick:()=>r(!n),title:"Frame format",children:[zf(d?d.icon:"square"),Ie("span",{children:d?.label||"Custom"}),Ie(hB,{})]}),n&&No("div",{className:"frame-toolbar__dropdown",children:[Ie("div",{style:{padding:"6px 12px",fontSize:11,fontWeight:600,color:"var(--text-secondary-color, #888)",textTransform:"uppercase",letterSpacing:"0.5px"},children:"Format"}),O3.map(S=>{let D=d?.label===S.label;return No("button",{className:"frame-toolbar__dropdown-item",onClick:()=>C(S),children:[zf(S.icon),Ie("span",{className:"frame-toolbar__dropdown-item-label",children:S.label}),No("span",{className:"frame-toolbar__dropdown-item-dims",children:[S.width,"*",S.height]}),D&&Ie("span",{className:"frame-toolbar__dropdown-item-check",children:Ie(fB,{})})]},S.label)})]})]}),Ie("div",{className:"frame-toolbar__divider"}),No("div",{className:"frame-toolbar__input-group",children:[Ie("label",{children:"W"}),Ie("input",{type:"number",value:s,onChange:S=>v(S.target.value),onPointerDown:S=>S.stopPropagation(),min:1})]}),Ie("button",{className:`frame-toolbar__constrain-btn ${i?"frame-toolbar__constrain-btn--active":""}`,onClick:()=>a(!i),title:i?"Unlock proportions":"Constrain proportions",children:Ie(uB,{active:i})}),No("div",{className:"frame-toolbar__input-group",children:[Ie("label",{children:"H"}),Ie("input",{type:"number",value:c,onChange:S=>T(S.target.value),onPointerDown:S=>S.stopPropagation(),min:1})]}),Ie("div",{className:"frame-toolbar__divider"}),Ie("button",{className:"frame-toolbar__export-btn",onClick:M,title:"Export frame as PNG",children:Ie(gB,{})})]})};import{useCallback as Fl,useEffect as $m,useRef as yr,useState as an}from"react";import{sceneCoordsToViewportCoords as MB}from"@orangecatai/common";import{CaptureUpdateAction as Uf,getElementAbsoluteCoords as PB}from"@orangecatai/element";import{ArrowUp as LB,ImagePlus as AB,X as DB}from"lucide-react";function Fm(e){return e??(typeof import.meta<"u"&&I?.VITE_APP_GEMINI_API_KEY?I.VITE_APP_GEMINI_API_KEY:"")??""}var Bn=new Map;function Om(e,o,t,n){Bn.set(e,{subscribers:new Set,prompt:o,settings:t,controller:n})}function zm(e,o){let t=Bn.get(e);t&&(t.finishedError=o,t.subscribers.forEach(n=>n(o)))}function Hm(e,o){let t=Bn.get(e);return t?(t.subscribers.add(o),t.finishedError!==void 0&&o(t.finishedError),!0):!1}function Gm(e,o){Bn.get(e)?.subscribers.delete(o)}function Um(e){Bn.delete(e)}function Wm(e){Bn.get(e)?.controller.abort()}function Ym(e){return Bn.get(e)?.prompt??""}function xr(e){return Bn.get(e)?.settings??null}function Nl(e){return Bn.has(e)}import wB,{createContext as vB,useContext as TB,useLayoutEffect as IB,useRef as CB,useState as SB}from"react";import{clsx as xB}from"clsx";import{twMerge as EB}from"tailwind-merge";function Er(...e){return EB(xB(e))}import*as H3 from"react";import{jsx as yB}from"react/jsx-runtime";var Hf=H3.forwardRef(({className:e,...o},t)=>yB("textarea",{className:Er("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:t,...o}));Hf.displayName="Textarea";import*as U3 from"react";import*as Bo from"@radix-ui/react-tooltip";import{jsx as G3}from"react/jsx-runtime";var W3=Bo.Provider,Y3=Bo.Root,V3=Bo.Trigger,Gf=U3.forwardRef(({className:e,sideOffset:o=4,...t},n)=>G3(Bo.Portal,{children:G3(Bo.Content,{ref:n,sideOffset:o,className:Er("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),...t})}));Gf.displayName=Bo.Content.displayName;import{jsx as xi,jsxs as kB}from"react/jsx-runtime";var K3=vB({isLoading:!1,value:"",setValue:()=>{},maxHeight:240,onSubmit:void 0,disabled:!1,textareaRef:wB.createRef()});function X3(){return TB(K3)}function Vm({className:e,isLoading:o=!1,maxHeight:t=240,value:n,onValueChange:r,onSubmit:i,children:a,disabled:s=!1,onClick:l,...c}){let[m,p]=SB(n||""),d=CB(null),u=g=>{p(g),r?.(g)},b=g=>{s||d.current?.focus(),l?.(g)};return xi(W3,{children:xi(K3.Provider,{value:{isLoading:o,value:n??m,setValue:r??u,maxHeight:t,onSubmit:i,disabled:s,textareaRef:d},children:xi("div",{onClick:b,className:Er("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:a})})})}function Km({className:e,onKeyDown:o,disableAutosize:t=!1,...n}){let{value:r,setValue:i,maxHeight:a,onSubmit:s,disabled:l,textareaRef:c}=X3(),m=b=>{!b||t||(b.style.height="auto",typeof a=="number"?b.style.height=`${Math.min(b.scrollHeight,a)}px`:b.style.height=`min(${b.scrollHeight}px, ${a})`)},p=b=>{c.current=b,m(b)};return IB(()=>{if(!c.current||t)return;let b=c.current;b.style.height="auto",typeof a=="number"?b.style.height=`${Math.min(b.scrollHeight,a)}px`:b.style.height=`min(${b.scrollHeight}px, ${a})`},[r,a,t]),xi(Hf,{ref:p,value:r,onChange:b=>{m(b.target),i(b.target.value)},onKeyDown:b=>{b.key==="Enter"&&!b.shiftKey&&(b.preventDefault(),s?.()),o?.(b)},className:Er("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 Xm({children:e,className:o,...t}){return xi("div",{className:Er("flex items-center gap-2",o),...t,children:e})}function Bl({tooltip:e,children:o,className:t,side:n="top",...r}){let{disabled:i}=X3();return kB(Y3,{...r,children:[xi(V3,{asChild:!0,disabled:i,onClick:a=>a.stopPropagation(),children:o}),xi(Gf,{side:n,className:t,children:e})]})}import{jsx as pe,jsxs as dt}from"react/jsx-runtime";var wr={"Gemini 2.5 Flash":{geminiModelId:"gemini-2.5-flash-image",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"]}},Vf=Object.keys(wr),_B={"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 Ei(e,o,t){let r=_B[e][o];if(!r)return{width:1024,height:1024};let i=r[t];if(!i){let a=Object.values(r)[0];return{width:a.w,height:a.h}}return{width:i.w,height:i.h}}function RB(e){return e==="0.5K"?"512px":e}async function Kf(e,o,t,n,r,i,a,s,l){let c=[{text:e}];if(s){let x=s.match(/^data:([^;]+);base64,(.+)$/);x&&c.unshift({inlineData:{mimeType:x[1],data:x[2]}})}let m={aspectRatio:t};r&&(m.imageSize=RB(n));let p={responseModalities:["IMAGE","TEXT"],imageConfig:m};i&&(p.thinkingConfig={thinkingLevel:"High",includeThoughts:!0});let d={contents:[{parts:c}],generationConfig:p},u=await fetch(`https://generativelanguage.googleapis.com/v1beta/models/${o}:generateContent`,{method:"POST",signal:l,headers:{"x-goog-api-key":a,"Content-Type":"application/json"},body:JSON.stringify(d)});if(!u.ok){let x=`Gemini API error ${u.status}`;try{let y=await u.json();y?.error?.message&&(x=y.error.message)}catch{}throw new Error(x)}let E=((await u.json())?.candidates?.[0]?.content?.parts??[]).find(x=>x.inlineData?.data);if(!E?.inlineData?.data)throw new Error("No image was returned by the API.");return`data:${E.inlineData.mimeType??"image/png"};base64,${E.inlineData.data}`}var Wf=()=>pe("svg",{width:"9",height:"9",viewBox:"0 0 10 10",fill:"none",children:pe("path",{d:"M2.5 3.75L5 6.25L7.5 3.75",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round"})}),Yf=()=>pe("svg",{width:"12",height:"12",viewBox:"0 0 14 14",fill:"none",children:pe("path",{d:"M2.5 7.5L5.5 10.5L11.5 3.5",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round"})}),NB=()=>pe("svg",{width:"13",height:"13",viewBox:"0 0 16 16",fill:"none",children:pe("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"})}),BB=()=>dt("svg",{width:"12",height:"12",viewBox:"0 0 14 14",fill:"none",children:[pe("circle",{cx:"7",cy:"7",r:"5.5",stroke:"currentColor",strokeWidth:"1.2"}),pe("path",{d:"M7 6.5V10",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round"}),pe("circle",{cx:"7",cy:"4.5",r:"0.75",fill:"currentColor"})]}),FB=()=>pe("svg",{width:"15",height:"15",viewBox:"0 0 14 14",fill:"none",className:"igp-spinner",children:pe("circle",{cx:"7",cy:"7",r:"5.5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeDasharray:"20 14"})}),OB=({label:e})=>{let t={"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 pe("div",{style:{border:"1.5px solid currentColor",borderRadius:2,boxSizing:"border-box",display:"inline-block",flexShrink:0,color:"#999",...t}})},$3=({element:e,app:o})=>{let t=o.state,n=Fm(o.props.geminiApiKey),[r,i]=an(()=>Ym(e.id)),[a,s]=an(()=>xr(e.id)?.model??"Gemini 3.1 Flash"),l=wr[a],c=l.supportedRatios,m=l.supportedResolutions,p=c.includes("2:3")?"2:3":c[0],d=m.includes("2K")?"2K":m[m.length-1],[u,b]=an(()=>xr(e.id)?.ratio??p),[g,E]=an(()=>xr(e.id)?.resolution??d),w=yr(!0);$m(()=>{if(w.current){w.current=!1;return}let H=wr[a],oe=H.supportedRatios,Re=oe.includes(u),tt=u;Re||(tt=oe.includes("2:3")?"2:3":oe[0],b(tt));let yn=H.supportedResolutions,xc=yn.includes(g),su=g;xc||(su=yn.includes("2K")?"2K":yn[yn.length-1],E(su));let vb=Ei(a,tt,su);o.scene.mutateElement(e,{width:vb.width,height:vb.height}),o.syncActionResult({captureUpdate:Uf.IMMEDIATELY})},[a]);let[x,y]=an(()=>Nl(e.id)),[v,T]=an(null),[C,M]=an(null),[S,D]=an(!1),[_,P]=an(!1),[A,z]=an(!1),V=yr(null),G=yr(null),Y=yr(null),R=yr(null),F=yr(null),K=yr(e),J=yr(o);$m(()=>{K.current=e,J.current=o});let Z=Fl(H=>{b(H),D(!1);let oe=Ei(a,H,g);J.current.scene.mutateElement(K.current,{width:oe.width,height:oe.height}),J.current.syncActionResult({captureUpdate:Uf.IMMEDIATELY})},[a,g]),le=Fl(H=>{E(H),P(!1);let oe=Ei(a,u,H);J.current.scene.mutateElement(K.current,{width:oe.width,height:oe.height}),J.current.syncActionResult({captureUpdate:Uf.IMMEDIATELY})},[a,u]);$m(()=>{let H=oe=>{V.current&&!V.current.contains(oe.target)&&D(!1),G.current&&!G.current.contains(oe.target)&&P(!1),Y.current&&!Y.current.contains(oe.target)&&z(!1)};return document.addEventListener("mousedown",H),()=>document.removeEventListener("mousedown",H)},[]),$m(()=>{let H=oe=>{y(!1),oe?oe!=="aborted"&&T(oe):T(null)};return Hm(e.id,H),()=>Gm(e.id,H)},[e.id]);let Ee=Fl(H=>{let oe=H.target.files?.[0];if(!oe)return;let Re=new FileReader;Re.onload=()=>M(Re.result),Re.readAsDataURL(oe),H.target.value=""},[]),ue=Fl(()=>{Wm(e.id)},[e.id]),_e=Fl(async()=>{if(!r.trim()){T("Please enter a prompt.");return}if(!n){T("No Gemini API key found. Set VITE_APP_GEMINI_API_KEY in .env.");return}let H=new AbortController;F.current=H,Om(e.id,r,{model:a,ratio:u,resolution:g},H),y(!0),T(null);let oe=null;try{let Re=wr[a],tt=await Kf(r,Re.geminiModelId,u,g,Re.supportsImageSize,Re.supportsThinking,n,C??void 0,H.signal);await o.insertGeneratedImageIntoFrame(tt,e)}catch(Re){Re instanceof Error&&(Re.name==="AbortError"?oe="aborted":oe=Re.message)}finally{F.current=null,zm(e.id,oe),y(!1),oe===null?(Um(e.id),i(""),M(null),T(null)):oe!=="aborted"&&T(oe)}},[r,n,a,u,g,C,o,e]);if(t.contextMenu||t.newElement||t.resizingElement||t.isRotating||t.openMenu||t.viewModeEnabled||t.selectedElementsAreBeingDragged)return null;let[et,,,st]=PB(e,o.scene.getNonDeletedElementsMap()),{x:Tt,y:Zt}=MB({sceneX:et+e.width/2,sceneY:st},t),Wr=Tt-t.offsetLeft,ws=Zt-t.offsetTop+16;return dt("div",{className:"igp",style:{left:`${Wr}px`,top:`${ws}px`},onPointerDown:H=>H.stopPropagation(),onClick:H=>H.stopPropagation(),children:[pe("input",{ref:R,type:"file",accept:"image/*",style:{display:"none"},onChange:Ee}),dt(Vm,{isLoading:x,value:r,onValueChange:i,onSubmit:_e,className:"igp-container",children:[C&&dt("div",{className:"igp-ref-chip",children:[pe("img",{src:C,alt:"Reference"}),pe("span",{children:"Reference image"}),pe("button",{onClick:()=>M(null),title:"Remove",children:pe(DB,{size:10})})]}),pe(Km,{placeholder:"What are we creating today\u2026",className:"igp-textarea",disableAutosize:!1}),v&&pe("div",{className:"igp-error",children:v}),dt(Xm,{className:"igp-actions",children:[dt("div",{className:"igp-actions-left",children:[dt("div",{className:"igp-dropdown-root",ref:Y,children:[pe(Bl,{tooltip:"Select model",side:"top",children:dt("button",{className:"igp-btn",onClick:()=>{z(H=>!H),D(!1),P(!1)},disabled:x,children:[pe(NB,{}),pe("span",{children:a}),pe(Wf,{})]})}),A&&pe("div",{className:"igp-dropdown igp-dropdown--up igp-dropdown--left",children:Vf.map(H=>dt("button",{className:"igp-dropdown-item",onClick:()=>{s(H),z(!1)},children:[pe("span",{style:{flex:1},children:H}),H===a&&pe("span",{className:"igp-check",children:pe(Yf,{})})]},H))})]}),pe(Bl,{tooltip:"Add reference image",side:"top",children:pe("button",{className:`igp-btn igp-btn--icon${C?" igp-btn--active":""}`,onClick:()=>R.current?.click(),disabled:x,children:pe(AB,{size:15})})})]}),dt("div",{className:"igp-actions-right",children:[dt("div",{className:"igp-dropdown-root",ref:G,children:[dt("button",{className:"igp-btn igp-btn--compact",onClick:()=>{m.length<=1||(P(H=>!H),D(!1),z(!1))},disabled:x||m.length<=1,title:m.length<=1?"Fixed resolution for this model":void 0,children:[pe("span",{children:g}),m.length>1&&pe(Wf,{})]}),_&&m.length>1&&pe("div",{className:"igp-dropdown igp-dropdown--up igp-dropdown--right",children:m.map(H=>dt("button",{className:"igp-dropdown-item",onClick:()=>le(H),children:[pe("span",{style:{flex:1},children:H}),H===g&&pe("span",{className:"igp-check",children:pe(Yf,{})})]},H))})]}),dt("div",{className:"igp-dropdown-root",ref:V,children:[dt("button",{className:"igp-btn igp-btn--compact",onClick:()=>{D(H=>!H),P(!1),z(!1)},disabled:x,children:[pe("span",{children:u}),pe(Wf,{})]}),S&&dt("div",{className:"igp-dropdown igp-dropdown--up igp-dropdown--right igp-dropdown--ratio",children:[dt("div",{className:"igp-dropdown-header",children:[pe("span",{children:"Format"}),pe(BB,{})]}),c.map(H=>{let oe=Ei(a,H,g);return dt("button",{className:"igp-dropdown-item",onClick:()=>Z(H),children:[pe(OB,{label:H}),pe("span",{style:{flex:1},children:H}),dt("span",{className:"igp-dims",children:[oe.width,"\xD7",oe.height]}),H===u&&pe("span",{className:"igp-check",children:pe(Yf,{})})]},H)})]})]}),pe("button",{className:"igp-generate",onClick:x?ue:_e,disabled:!x&&!r.trim(),title:x?"Stop generation":"Generate image",children:x?pe(FB,{}):pe(LB,{size:16})})]})]})]})]})};import{useCallback as Xf,useEffect as $f,useRef as Zm,useState as sn}from"react";import{sceneCoordsToViewportCoords as Z3}from"@orangecatai/common";import{getElementAbsoluteCoords as zB}from"@orangecatai/element";import{ArrowUp as HB}from"lucide-react";import{Fragment as KB,jsx as ge,jsxs as ft}from"react/jsx-runtime";var Zf=()=>ge("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",children:ge("path",{d:"M2.5 3.75L5 6.25L7.5 3.75",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),jf=()=>ge("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",children:ge("path",{d:"M2.5 7.5L5.5 10.5L11.5 3.5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),GB=()=>ge("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:ge("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"})}),UB=()=>ft("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",children:[ge("circle",{cx:"7",cy:"7",r:"5.5",stroke:"currentColor",strokeWidth:"1.2"}),ge("path",{d:"M7 6.5V10",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round"}),ge("circle",{cx:"7",cy:"4.5",r:"0.75",fill:"currentColor"})]}),WB=()=>ge("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",className:"igp-spinner",children:ge("circle",{cx:"7",cy:"7",r:"5.5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeDasharray:"20 14"})}),YB=()=>ge("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",children:ge("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"})}),VB=({label:e})=>{let o={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 ge("div",{style:{...o,...n}})},j3=({element:e,app:o})=>{let t=o.state,n=Fm(o.props.geminiApiKey),[r,i]=sn(()=>Nl(e.id)),[a,s]=sn(()=>Ym(e.id)),[l,c]=sn(()=>xr(e.id)?.model??"Gemini 3.1 Flash"),m=wr[l],p=m.supportedRatios,d=m.supportedResolutions,u=p.includes("1:1")?"1:1":p[0],b=d.includes("2K")?"2K":d[d.length-1],[g,E]=sn(()=>xr(e.id)?.ratio??u),[w,x]=sn(()=>xr(e.id)?.resolution??b);$f(()=>{let H=wr[l],oe=H.supportedRatios;oe.includes(g)||E(oe.includes("1:1")?"1:1":oe[0]);let tt=H.supportedResolutions;tt.includes(w)||x(tt.includes("2K")?"2K":tt[tt.length-1])},[l]);let[y,v]=sn(()=>Nl(e.id)),[T,C]=sn(null),[M,S]=sn(!1),[D,_]=sn(!1),[P,A]=sn(!1),z=Zm(null),V=Zm(null),G=Zm(null),Y=Zm(null),R=Xf(H=>{E(H),S(!1)},[]);$f(()=>{let H=oe=>{v(!1),oe?oe!=="aborted"&&C(oe):(i(!1),s(""))};return Hm(e.id,H),()=>Gm(e.id,H)},[e.id]),$f(()=>{let H=oe=>{z.current&&!z.current.contains(oe.target)&&S(!1),V.current&&!V.current.contains(oe.target)&&_(!1),G.current&&!G.current.contains(oe.target)&&A(!1)};return document.addEventListener("mousedown",H),()=>document.removeEventListener("mousedown",H)},[]);let F=Xf(()=>{Wm(e.id)},[e.id]),K=Xf(async()=>{if(!a.trim()){C("Please enter a prompt.");return}if(!n){C("No Gemini API key found. Set VITE_APP_GEMINI_API_KEY in .env or pass geminiApiKey as a prop.");return}let H=new AbortController;Y.current=H,Om(e.id,a,{model:l,ratio:g,resolution:w},H),v(!0),C(null);let oe=null;try{let Re=wr[l],tt=e.fileId?o.files[e.fileId]?.dataURL:void 0,yn=await Kf(a,Re.geminiModelId,g,w,Re.supportsImageSize,Re.supportsThinking,n,tt,H.signal),xc=Ei(l,g,w);await o.insertGeneratedImageNearElement(yn,e,xc.width,xc.height)}catch(Re){Re instanceof Error&&(Re.name==="AbortError"?oe="aborted":oe=Re.message)}finally{Y.current=null,zm(e.id,oe),v(!1),oe===null?(Um(e.id),i(!1),s(""),C(null)):oe!=="aborted"&&C(oe)}},[a,n,l,g,w,o,e]);if(t.contextMenu||t.newElement||t.resizingElement||t.isRotating||t.openMenu||t.viewModeEnabled||t.selectedElementsAreBeingDragged)return null;let J=o.scene.getNonDeletedElementsMap(),[Z,le,,Ee]=zB(e,J),{x:ue,y:_e}=Z3({sceneX:Z+e.width/2,sceneY:le},t),et=ue-t.offsetLeft,st=Math.max(_e-t.offsetTop-44,8),{x:Tt,y:Zt}=Z3({sceneX:Z+e.width/2,sceneY:Ee},t),Wr=Tt-t.offsetLeft,ws=Zt-t.offsetTop+16;return ft(KB,{children:[ge("div",{className:"iqep__trigger-bar",style:{left:`${et}px`,top:`${st}px`},onPointerDown:H=>H.stopPropagation(),onClick:H=>H.stopPropagation(),children:ft("button",{className:"iqep__trigger-btn",onClick:()=>i(H=>!H),title:"Quick AI edit",children:[ge(YB,{}),ge("span",{children:"AI Edit"})]})}),r&&ge("div",{className:"igp iqep__panel",style:{left:`${Wr}px`,top:`${ws}px`},onPointerDown:H=>H.stopPropagation(),onClick:H=>H.stopPropagation(),children:ft(Vm,{isLoading:y,value:a,onValueChange:s,onSubmit:K,className:"igp-container",children:[ge(Km,{placeholder:"Describe your edit\u2026",className:"igp-textarea",disableAutosize:!1}),T&&ge("div",{className:"igp-error",children:T}),ft(Xm,{className:"igp-actions",children:[ge("div",{className:"igp-actions-left",children:ft("div",{className:"igp-dropdown-root",ref:G,children:[ge(Bl,{tooltip:"Select model",side:"top",children:ft("button",{className:"igp-btn",onClick:()=>{A(H=>!H),S(!1),_(!1)},disabled:y,children:[ge(GB,{}),ge("span",{children:l}),ge(Zf,{})]})}),P&&ge("div",{className:"igp-dropdown igp-dropdown--up igp-dropdown--left",children:Vf.map(H=>ft("button",{className:"igp-dropdown-item",onClick:()=>{c(H),A(!1)},children:[ge("span",{style:{flex:1},children:H}),H===l&&ge("span",{className:"igp-check",children:ge(jf,{})})]},H))})]})}),ft("div",{className:"igp-actions-right",children:[ft("div",{className:"igp-dropdown-root",ref:V,children:[ft("button",{className:"igp-btn igp-btn--compact",onClick:()=>{d.length<=1||(_(H=>!H),S(!1),A(!1))},disabled:y||d.length<=1,title:d.length<=1?"Fixed resolution for this model":void 0,children:[ge("span",{children:w}),d.length>1&&ge(Zf,{})]}),D&&d.length>1&&ge("div",{className:"igp-dropdown igp-dropdown--up igp-dropdown--right",children:d.map(H=>ft("button",{className:"igp-dropdown-item",onClick:()=>{x(H),_(!1)},children:[ge("span",{style:{flex:1},children:H}),H===w&&ge("span",{className:"igp-check",children:ge(jf,{})})]},H))})]}),ft("div",{className:"igp-dropdown-root",ref:z,children:[ft("button",{className:"igp-btn igp-btn--compact",onClick:()=>{S(H=>!H),_(!1),A(!1)},disabled:y,children:[ge("span",{children:g}),ge(Zf,{})]}),M&&ft("div",{className:"igp-dropdown igp-dropdown--up igp-dropdown--right igp-dropdown--ratio",children:[ft("div",{className:"igp-dropdown-header",children:[ge("span",{children:"Output format"}),ge(UB,{})]}),p.map(H=>{let oe=Ei(l,H,w);return ft("button",{className:"igp-dropdown-item",onClick:()=>R(H),children:[ge(VB,{label:H}),ge("span",{style:{flex:1},children:H}),ft("span",{className:"igp-dims",children:[oe.width,"\xD7",oe.height]}),H===g&&ge("span",{className:"igp-check",children:ge(jf,{})})]},H)})]})]}),ge("button",{className:"igp-generate",onClick:y?F:K,disabled:!y&&!a.trim(),title:y?"Stop generation":"Generate edit",children:y?ge(WB,{}):ge(HB,{size:16})})]})]})]})})]})};import{DEFAULT_LASER_COLOR as jB,easeOut as J3}from"@orangecatai/common";import{LaserPointer as XB}from"@excalidraw/laser-pointer";import{SVG_NS as q3,getSvgPathFromStroke as $B,sceneCoordsToViewportCoords as ZB}from"@orangecatai/common";var Fn=class{constructor(o,t,n){this.animationFrameHandler=o;this.app=t;this.options=n;k(this,"currentTrail");k(this,"pastTrails",[]);k(this,"container");k(this,"trailElement");k(this,"trailAnimation");this.animationFrameHandler.register(this,this.onFrame.bind(this)),this.trailElement=document.createElementNS(q3,"path"),this.options.animateTrail&&(this.trailAnimation=document.createElementNS(q3,"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(o,t){if(this.currentTrail){let n=this.currentTrail.originalPoints.length;return this.currentTrail.originalPoints[n-1][0]===o&&this.currentTrail.originalPoints[n-1][1]===t}return!1}start(o){o&&(this.container=o),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(o,t){this.currentTrail=new XB(this.options),this.currentTrail.addPoint([o,t,performance.now()]),this.update()}addPointToPath(o,t){this.currentTrail&&(this.currentTrail.addPoint([o,t,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 o=[];for(let n of this.pastTrails)o.push(this.drawTrail(n,this.app.state));if(this.currentTrail){let n=this.drawTrail(this.currentTrail,this.app.state);o.push(n)}this.pastTrails=this.pastTrails.filter(n=>n.getStrokeOutline().length!==0),o.length===0&&this.stop();let t=o.join(" ").trim();this.trailElement.setAttribute("d",t),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(o,t){let n=o.getStrokeOutline(o.options.size/t.zoom.value).map(([i,a])=>{let s=ZB({sceneX:i,sceneY:a},t);return[s.x,s.y]}),r=this.trailAnimation?n.slice(0,n.length/2):n;return $B(r,!0)}};var jm=class{constructor(o,t){this.animationFrameHandler=o;this.app=t;k(this,"localTrail");k(this,"collabTrails",new Map);k(this,"container");this.animationFrameHandler.register(this,this.onFrame.bind(this)),this.localTrail=new Fn(o,t,{...this.getTrailOptions(),fill:()=>jB})}getTrailOptions(){return{simplify:0,streamline:.4,sizeMapping:o=>{let r=Math.max(0,1-(performance.now()-o.pressure)/1e3),i=(50-Math.min(50,o.totalLength-o.currentIndex))/50;return Math.min(J3(i),J3(r))}}}startPath(o,t){this.localTrail.startPath(o,t)}addPointToPath(o,t){this.localTrail.addPointToPath(o,t)}endPath(){this.localTrail.endPath()}start(o){this.container=o,this.animationFrameHandler.start(this),this.localTrail.start(o)}stop(){this.animationFrameHandler.stop(this),this.localTrail.stop()}onFrame(){this.updateCollabTrails()}updateCollabTrails(){if(!(!this.container||this.app.state.collaborators.size===0)){for(let[o,t]of this.app.state.collaborators.entries()){let n;this.collabTrails.has(o)?n=this.collabTrails.get(o):(n=new Fn(this.animationFrameHandler,this.app,{...this.getTrailOptions(),fill:()=>t.pointer?.laserColor||si(o,t)}),n.start(this.container),this.collabTrails.set(o,n)),t.pointer&&t.pointer.tool==="laser"&&(t.button==="down"&&!n.hasCurrentTrail&&n.startPath(t.pointer.x,t.pointer.y),t.button==="down"&&n.hasCurrentTrail&&!n.hasLastPoint(t.pointer.x,t.pointer.y)&&n.addPointToPath(t.pointer.x,t.pointer.y),t.button==="up"&&n.hasCurrentTrail&&(n.addPointToPath(t.pointer.x,t.pointer.y),n.endPath()))}for(let o of this.collabTrails.keys())this.app.state.collaborators.has(o)||(this.collabTrails.get(o).stop(),this.collabTrails.delete(o))}}};import{version as qB}from"react";import{unstable_batchedUpdates as Q3}from"react-dom";import{throttleRAF as JB}from"@orangecatai/common";var Ze=e=>o=>{Q3(e,o)},qm=e=>JB(o=>{Q3(e,o)}),yi=(()=>{let e;try{let t=qB.split(".");e=Number(t[0])>17}catch{e=!1}let o=!1;return()=>window.EXCALIDRAW_THROTTLE_RENDER===!0?e?!0:(o||(o=!0,console.warn("Excalidraw: render throttling is disabled on React versions < 18.")),!1):!1})();import{CODES as qf,KEYS as Ol,CLASSES as Jf,POINTER_BUTTON as QB,THEME as eF,isWritableElement as tF,getFontString as eI,getFontFamilyString as tI,isTestEnv as oI,MIME_TYPES as Qf,applyDarkModeFilter as oF}from"@orangecatai/common";import{getTextFromElements as nF,originalContainerCache as rF,updateBoundElements as nI,updateOriginalContainerCache as rI}from"@orangecatai/element";import{LinearElementEditor as iF}from"@orangecatai/element";import{bumpVersion as aF}from"@orangecatai/element";import{getBoundTextElementId as sF,getContainerElement as e1,getTextElementAngle as lF,redrawTextBoundingBox as cF,getBoundTextMaxHeight as dF,getBoundTextMaxWidth as iI,computeContainerDimensionForBoundText as aI,computeBoundTextPosition as mF,getBoundTextElement as pF}from"@orangecatai/element";import{getTextWidth as uF}from"@orangecatai/element";import{normalizeText as sI}from"@orangecatai/element";import{wrapText as gF}from"@orangecatai/element";import{isArrowElement as Jm,isBoundToContainer as hF,isTextElement as lI}from"@orangecatai/element";var fF=(e,o,t,n,r,i)=>{let{zoom:a}=n,s=180*t/Math.PI,l=e*(a.value-1)/2,c=o*(a.value-1)/2;return e>r&&a.value!==1&&(l=r*(a.value-1)/2),o>i&&a.value!==1&&(c=i*(a.value-1)/2),`translate(${l}px, ${c}px) scale(${a.value}) rotate(${s}deg)`},cI=({id:e,onChange:o,onSubmit:t,getViewportCoords:n,element:r,canvas:i,excalidrawContainer:a,app:s,autoSelect:l=!0})=>{let c=(R,F)=>{if(!F.style.fontFamily||!F.style.fontSize)return!1;let K=F.style.fontFamily.replace(/"/g,"");return tI({fontFamily:R.fontFamily})!==K||`${R.fontSize}px`!==F.style.fontSize},m=s.state.theme,p=()=>{m=s.state.theme;let R=s.state,F=s.scene.getElement(e);if(!F)return;let{textAlign:K,verticalAlign:J}=F,Z=s.scene.getNonDeletedElementsMap();if(F&&lI(F)){let le=F.x,Ee=F.y,ue=e1(F,s.scene.getNonDeletedElementsMap()),_e=F.width,et=F.height,st=F.width,Tt=F.height;if(ue&&F.containerId){if(Jm(ue)){let tt=iF.getBoundTextElementPosition(ue,F,Z);le=tt.x,Ee=tt.y}let oe=c(F,d),Re;if(oe?Re=rI(ue.id,ue.height):(Re=rF[ue.id],Re||(Re=rI(ue.id,ue.height))),st=iI(ue,F),Tt=dF(ue,F),!Jm(ue)&&et>Tt){let tt=aI(et,ue.type);s.scene.mutateElement(ue,{height:tt}),nI(ue,s.scene);return}else if(!Jm(ue)&&ue.height>Re.height&&et<Tt){let tt=aI(et,ue.type);s.scene.mutateElement(ue,{height:tt}),nI(ue,s.scene)}else{let{x:tt,y:yn}=mF(ue,F,Z);le=tt,Ee=yn}}let[Zt,Wr]=n(le,Ee);ue?_e+=.5:(st=(R.width-8-Zt)/R.zoom.value,_e=Math.min(_e,st)),et*=1.05;let ws=eI(F),H=(R.height-Wr)/R.zoom.value;Object.assign(d.style,{font:ws,lineHeight:F.lineHeight,width:`${_e}px`,height:`${et}px`,left:`${Zt}px`,top:`${Wr}px`,transform:fF(_e,et,lF(F,ue),R,st,H),textAlign:K,verticalAlign:J,color:R.theme===eF.DARK?oF(F.strokeColor):F.strokeColor,opacity:F.opacity/100,maxHeight:`${H}px`}),d.scrollTop=0,oI()&&(d.style.fontFamily=tI(F)),s.scene.mutateElement(F,{x:le,y:Ee})}},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",b="normal";(hF(r)||!r.autoResize)&&(u="pre-wrap",b="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:b,whiteSpace:u,overflowWrap:"break-word",boxSizing:"content-box"}),d.value=r.originalText,p(),o&&(d.onpaste=async R=>{let F=Lw(R),K=null;if(F.has(Qf.excalidrawClipboard)||F.has(Qf.excalidraw)){R.preventDefault(),K=await fa(R);try{let ue=await kd(K);if(ue.elements){let _e=nF(ue.elements);if(_e){let{selectionStart:et,selectionEnd:st,value:Tt}=d;d.value=Tt.slice(0,et)+_e+Tt.slice(st);let Zt=et+_e.length;d.selectionStart=d.selectionEnd=Zt,d.dispatchEvent(new Event("input"))}}return}catch{console.warn("failed to parse excalidraw clipboard data")}}K=K||await fa(R);let J=K.findByType(Qf.text);if(!J)return;let Z=sI(J.value);if(!Z)return;let le=e1(r,s.scene.getNonDeletedElementsMap()),Ee=eI({fontSize:s.state.currentItemFontSize,fontFamily:s.state.currentItemFontFamily});if(le){let ue=pF(le,s.scene.getNonDeletedElementsMap()),_e=gF(`${d.value}${Z}`,Ee,iI(le,ue)),et=uF(_e,Ee);d.style.width=`${et}px`}},d.oninput=()=>{let R=sI(d.value);if(d.value!==R){let F=d.selectionStart;d.value=R,d.selectionStart=F,d.selectionEnd=F}o(d.value)}),d.onkeydown=R=>{if(!R.shiftKey&&fd.keyTest(R))R.preventDefault(),s.actionManager.executeAction(fd),p();else if(!R.shiftKey&&bd.keyTest(R))R.preventDefault(),s.actionManager.executeAction(bd),p();else if(!R.shiftKey&&xd.keyTest(R))R.preventDefault(),s.actionManager.executeAction(xd),p();else if(kg.keyTest(R))s.actionManager.executeAction(kg);else if(Mg.keyTest(R))s.actionManager.executeAction(Mg);else if(R.key===Ol.ESCAPE)R.preventDefault(),C=!0,M();else if(ii.keyTest(R))R.preventDefault(),M(),s.actionManager.executeAction(ii);else if(R.key===Ol.ENTER&&R[Ol.CTRL_OR_CMD]){if(R.preventDefault(),R.isComposing||R.keyCode===229)return;C=!0,M()}else if(R.key===Ol.TAB||R[Ol.CTRL_OR_CMD]&&(R.code===qf.BRACKET_LEFT||R.code===qf.BRACKET_RIGHT)){if(R.preventDefault(),R.isComposing)return;R.shiftKey||R.code===qf.BRACKET_LEFT?y():x(),d.dispatchEvent(new Event("input"))}};let g=4,E=" ".repeat(g),w=new RegExp(`^ {1,${g}}`),x=()=>{let{selectionStart:R,selectionEnd:F}=d,K=v(),J=d.value;K.forEach(Z=>{let le=J.slice(0,Z),Ee=J.slice(Z);J=`${le}${E}${Ee}`}),d.value=J,d.selectionStart=R+g,d.selectionEnd=F+g*K.length},y=()=>{let{selectionStart:R,selectionEnd:F}=d,K=v(),J=[],Z=d.value;K.forEach(le=>{let Ee=Z.slice(le,le+g).match(w);if(Ee){let ue=Z.slice(0,le),_e=Z.slice(le+Ee[0].length);Z=`${ue}${_e}`,J.push(le)}}),d.value=Z,J.length&&(R>J[J.length-1]?d.selectionStart=Math.max(R-g,J[J.length-1]):d.selectionStart=R,d.selectionEnd=Math.max(d.selectionStart,F-g*J.length))},v=()=>{let{selectionStart:R,selectionEnd:F,value:K}=d,J=K.slice(0,R).match(/[^\n]*$/)[0].length;return R=R-J,K.slice(R,F).split(`
|
|
15
|
-
`).reduce((le,Ee,ue,_e)=>le.concat(ue?le[ue-1]+_e[ue-1].length+1:R),[]).reverse()},T=R=>{R.target instanceof HTMLCanvasElement&&(R.preventDefault(),R.stopPropagation())},C=!1,M=()=>{if(G)return;G=!0,S();let R=s.scene.getElement(r.id);if(!R)return;let F=e1(R,s.scene.getNonDeletedElementsMap());if(F){if(d.value.trim()){let K=sF(F);!K||K!==r.id?s.scene.mutateElement(F,{boundElements:(F.boundElements||[]).concat({type:"text",id:r.id})}):Jm(F)&&aF(F)}else s.scene.mutateElement(F,{boundElements:F.boundElements?.filter(K=>!lI(K))});cF(R,F,s.scene)}t({viaKeyboard:C,nextOriginalText:d.value})},S=()=>{d.onblur=null,d.oninput=null,d.onkeydown=null,Y&&Y.disconnect(),window.removeEventListener("resize",p),window.removeEventListener("wheel",T,!0),window.removeEventListener("pointerdown",P),window.removeEventListener("pointerup",D),window.removeEventListener("blur",M),window.removeEventListener("beforeunload",M),z(),A(),V(),d.remove()},D=R=>{window.removeEventListener("pointerup",D);let F=R?.target,K=F instanceof HTMLElement&&F.classList.contains("properties-trigger"),J=(F instanceof HTMLElement||F instanceof SVGElement)&&!!F.closest(".properties-content"),Z=(F instanceof HTMLElement||F instanceof SVGElement)&&(!!F.closest(`.${Jf.SHAPE_ACTIONS_MENU}`)||!!F.closest(".compact-shape-actions-island"));setTimeout(()=>{Z||K||J||(d.onblur=M,d.focus())})},_=()=>{d.onblur=null,window.addEventListener("pointerup",D),window.addEventListener("blur",M)},P=R=>{let F=R?.target;if(R.button===QB.WHEEL){F instanceof HTMLTextAreaElement&&(R.preventDefault(),s.handleCanvasPanUsingWheelOrSpaceDrag(R)),_();return}let K=F instanceof HTMLElement&&F.classList.contains("properties-trigger"),J=(F instanceof HTMLElement||F instanceof SVGElement)&&!!F.closest(".properties-content");(R.target instanceof HTMLElement||R.target instanceof SVGElement)&&(R.target.closest(`.${Jf.SHAPE_ACTIONS_MENU}, .${Jf.ZOOM_ACTIONS}`)||R.target.closest(".compact-shape-actions-island"))&&!tF(R.target)||K||J?_():R.target instanceof HTMLCanvasElement&&!oI()&&requestAnimationFrame(()=>{M()})},A=s.onChangeEmitter.on(R=>{s.state.theme!==m&&p()}),z=s.scene.onUpdate(()=>{p(),!!document.activeElement?.closest(".properties-content")||d.focus()}),V=s.onScrollChangeEmitter.on(()=>{p()}),G=!1;l&&d.select(),D();let Y=null;return i&&"ResizeObserver"in window?(Y=new window.ResizeObserver(()=>{p()}),Y.observe(i)):window.addEventListener("resize",p),d.onpointerdown=R=>R.stopPropagation(),requestAnimationFrame(()=>{window.addEventListener("pointerdown",P,{capture:!0})}),window.addEventListener("beforeunload",M),a?.querySelector(".excalidraw-textEditorContainer").appendChild(d),M};import{getGlobalCSSVariable as Qm}from"@orangecatai/common";import{getCommonBounds as bF}from"@orangecatai/element";var On=4,ho=6,dI="rgba(0,0,0,0.3)",mI=(e,o,t,n)=>{if(!e.size)return{horizontal:null,vertical:null};let[r,i,a,s]=bF(e),l=o/n.zoom.value,c=t/n.zoom.value,m={top:parseInt(Qm("sat"))||0,bottom:parseInt(Qm("sab"))||0,left:parseInt(Qm("sal"))||0,right:parseInt(Qm("sar"))||0},p=vn().rtl,d=-n.scrollX+m.left,u=-n.scrollY+m.top,b=d+l-m.right,g=u+c-m.bottom,E=Math.min(r,d),w=Math.min(i,u),x=Math.max(a,b),y=Math.max(s,g),v=a-r,T=s-i,C=x-E,M=y-w,S=Math.max(On*2,m.left+m.right)+ho*2,D=o*(l/C)-S,_=Math.max(On*2,m.top+m.bottom)+ho*2,P=t*(c/M)-_,A=C>v?C*n.zoom.value/(D+S):o/(D+S),z=M>T?M*n.zoom.value/(P+_):t/(P+_);return{horizontal:d===E&&b===x?null:{x:Math.max(m.left,On)+ho+(d-E)/C*o,y:t-ho-Math.max(On,m.bottom),width:D,height:ho,deltaMultiplier:A},vertical:u===w&&g===y?null:{x:p?Math.max(m.left,On):o-ho-Math.max(m.right,On),y:Math.max(m.top,On)+ho+(u-w)/M*t,width:ho,height:P,deltaMultiplier:z}}},t1=(e,o,t)=>{let[n,r]=[e.horizontal,e.vertical].map(a=>a!=null&&a.x<=o&&o<=a.x+a.width&&a.y<=t&&t<=a.y+a.height);return{isOverEither:n||r,isOverHorizontal:n,isOverVertical:r}};var pI=e=>{let o=["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(?:${o.map(n=>`\\s*${n}(-beta)?`).join("|")})\\b`).test(e.trim())};import{pointFrom as kF}from"@orangecatai/math";import{getElementLineSegments as MF}from"@orangecatai/element";import{LinearElementEditor as PF}from"@orangecatai/element";import{isFrameLikeElement as LF,isLinearElement as AF,isTextElement as DF}from"@orangecatai/element";import{getFrameChildren as _F}from"@orangecatai/element";import{selectGroupsForSelectedElements as RF}from"@orangecatai/element";import{getContainerElement as NF}from"@orangecatai/element";import{arrayToMap as BF,easeOut as fI,isShallowEqual as FF}from"@orangecatai/common";import{simplify as xF}from"points-on-curve";import{polygonFromPoints as EF,lineSegment as uI,polygonIncludesPointNonZero as yF}from"@orangecatai/math";import{computeBoundTextPosition as wF,doBoundsIntersect as vF,getBoundTextElement as TF,getElementBounds as IF,intersectElementWithLineSegment as gI}from"@orangecatai/element";var hI=e=>{let{lassoPath:o,elements:t,elementsMap:n,elementsSegments:r,intersectedElements:i,enclosedElements:a,simplifyDistance:s}=e,l=o;s&&(l=xF(o,s));let c=t.filter(d=>!d.locked);a.clear(),i.clear();let m=o.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=IF(d,n);vF(m,u)&&!i.has(d.id)&&!a.has(d.id)&&(CF(l,d,r)?a.add(d.id):SF(l,d,n)&&i.add(d.id))}return{selectedElementIds:[...i,...a]}},CF=(e,o,t)=>{let n=EF(e),r=t.get(o.id);return r?r.some(i=>i.some(a=>yF(a,n))):!1},SF=(e,o,t)=>{let n=e.slice(1).map((i,a)=>uI(e[a],i)).concat([uI(e[e.length-1],e[0])]),r=TF(o,t);return n.some(i=>gI(o,t,i,0,!0).length>0||!!r&&gI({...r,...wF(o,r,t)},t,i,0,!0).length>0)};var ep=class extends Fn{constructor(t,n){super(t,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(fI(l),fI(s))},fill:()=>"rgba(105,101,219,0.05)",stroke:()=>"rgba(105,101,219)"});k(this,"intersectedElements",new Set);k(this,"enclosedElements",new Set);k(this,"elementsSegments",null);k(this,"canvasTranslate",null);k(this,"keepPreviousSelection",!1);k(this,"selectElementsFromIds",t=>{this.app.setState(n=>{let r=t.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&&DF(c)){let m=NF(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&&LF(c)){let m=_F(this.app.scene.getNonDeletedElementsMap(),c.id);for(let p of m)delete r[p.id]}}let i=RF({editingGroupId:n.editingGroupId,selectedElementIds:r},this.app.scene.getNonDeletedElements(),n,this.app),a=[...Object.keys(i.selectedElementIds)],s=[...Object.keys(i.selectedGroupIds)];return{selectedElementIds:i.selectedElementIds,selectedGroupIds:i.selectedGroupIds,selectedLinearElement:a.length===1&&!s.length&&AF(this.app.scene.getNonDeletedElement(a[0]))?new PF(this.app.scene.getNonDeletedElement(a[0]),this.app.scene.getNonDeletedElementsMap()):null}})});k(this,"addPointToPath",(t,n,r=!1)=>{super.addPointToPath(t,n),this.keepPreviousSelection=r,this.updateSelection()});k(this,"updateSelection",()=>{let t=super.getCurrentTrail()?.originalPoints?.map(r=>kF(r[0],r[1])),n={scrollX:this.app.state.scrollX,scrollY:this.app.state.scrollY,zoom:this.app.state.zoom.value};if(!this.elementsSegments||!FF(n,this.canvasTranslate??{})){this.canvasTranslate=n,this.elementsSegments=new Map;let r=BF(this.app.visibleElements);for(let i of this.app.visibleElements){let a=MF(i,r);this.elementsSegments.set(i.id,a)}}if(t){let{selectedElementIds:r}=hI({lassoPath:t,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(t,n,r=!1){this.endPath(),super.startPath(t,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 OF,easeOut as bI,THEME as zF}from"@orangecatai/common";import{computeBoundTextPosition as HF,doBoundsIntersect as GF,getBoundTextElement as UF,getElementBounds as WF,getElementLineSegments as YF,getFreedrawOutlineAsSegments as VF,getFreedrawOutlinePoints as KF,intersectElementWithLineSegment as xI,isArrowElement as XF,isFreeDrawElement as EI,isLineElement as $F,isPointInElement as ZF}from"@orangecatai/element";import{lineSegment as jF,lineSegmentsDistance as yI,pointFrom as SI,polygon as qF,polygonIncludesPointNonZero as JF}from"@orangecatai/math";import{getElementsInGroup as wI}from"@orangecatai/element";import{shouldTestInside as QF}from"@orangecatai/element";import{hasBoundTextElement as vI,isBoundToContainer as TI}from"@orangecatai/element";import{getBoundTextElementId as II}from"@orangecatai/element";var tp=class extends Fn{constructor(t,n){super(t,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(bI(l),bI(s))},fill:()=>n.state.theme===zF.LIGHT?"rgba(0, 0, 0, 0.2)":"rgba(255, 255, 255, 0.2)"});k(this,"elementsToErase",new Set);k(this,"groupsToErase",new Set)}startPath(t,n){this.endPath(),super.startPath(t,n),this.elementsToErase.clear()}addPointToPath(t,n,r=!1){return super.addPointToPath(t,n),this.updateElementsToBeErased(r)}updateElementsToBeErased(t){let n=super.getCurrentTrail()?.originalPoints?.map(s=>SI(s[0],s[1]))||[];if(n.length<2)return[];let r=jF(n[n.length-1],n[n.length-2]),i=this.app.visibleElements.filter(s=>!s.locked),a=OF(i);for(let s of i)if(t&&this.elementsToErase.has(s.id)){if(CI(r,s,a,this.app.state.zoom.value)){let c=s.groupIds.at(-1);if(this.groupsToErase.has(c)){let m=wI(this.app.scene.getNonDeletedElementsMap(),c);for(let p of m)this.elementsToErase.delete(p.id);this.groupsToErase.delete(c)}if(TI(s)&&this.elementsToErase.delete(s.containerId),vI(s)){let m=II(s);m&&this.elementsToErase.delete(m)}this.elementsToErase.delete(s.id)}}else if(!t&&!this.elementsToErase.has(s.id)&&CI(r,s,a,this.app.state.zoom.value)){let c=s.groupIds.at(-1);if(!this.groupsToErase.has(c)){let m=wI(this.app.scene.getNonDeletedElementsMap(),c);for(let p of m)this.elementsToErase.add(p.id);this.groupsToErase.add(c)}if(vI(s)){let m=II(s);m&&this.elementsToErase.add(m)}TI(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()}},CI=(e,o,t,n)=>{let r=e[1],i=EI(o)?15:o.strokeWidth/2,a=[Math.min(e[0][0],e[1][0])-i,Math.min(e[0][1],e[1][1])-i,Math.max(e[0][0],e[1][0])+i,Math.max(e[0][1],e[1][1])+i],s=WF(o,t),l=[s[0]-i,s[1]-i,s[2]+i,s[3]+i];if(!GF(a,l))return!1;if(QF(o)&&ZF(r,o,t))return!0;if(EI(o)){let m=KF(o),p=VF(o,m,t),d=Math.max(2.25,5/n);for(let b of p)if(yI(b,e)<=d)return!0;let u=qF(...m.map(([b,g])=>SI(o.x+b,o.y+g)));return!!JF(e[0],u)}let c=UF(o,t);if(XF(o)||$F(o)&&!o.polygon){let m=Math.max(o.strokeWidth,o.strokeWidth*2/n),p=YF(o,t);for(let d of p)if(yI(d,e)<=m)return!0;return!1}return xI(o,t,e,0,!0).length>0||!!c&&xI({...c,...HF(o,c,t)},t,e,0,!0).length>0};import{jsx as fo,jsxs as kI}from"react/jsx-runtime";var eO=()=>kI("div",{"data-testid":"brave-measure-text-error",children:[fo("p",{children:fo(Bt,{i18nKey:"errors.brave_measure_text_error.line1",bold:e=>fo("span",{style:{fontWeight:600},children:e})})}),fo("p",{children:fo(Bt,{i18nKey:"errors.brave_measure_text_error.line2",bold:e=>fo("span",{style:{fontWeight:600},children:e})})}),fo("p",{children:fo(Bt,{i18nKey:"errors.brave_measure_text_error.line3",link:e=>fo("a",{href:"http://docs.excalidraw.com/docs/@orangecatai/adgen-canvas/faq#turning-off-aggresive-block-fingerprinting-in-brave-browser",children:e})})}),fo("p",{children:fo(Bt,{i18nKey:"errors.brave_measure_text_error.line4",issueLink:e=>fo("a",{href:"https://github.com/excalidraw/excalidraw/issues/new",children:e}),discordLink:e=>kI("a",{href:"https://discord.gg/UexuTaE",children:[e,"."]})})})]}),MI=eO;import sO from"clsx";import lO from"react";import{useLayoutEffect as tO,useRef as PI,useEffect as LI}from"react";import{unstable_batchedUpdates as oO}from"react-dom";import{KEYS as nO,queryFocusableElements as rO}from"@orangecatai/common";import iO from"clsx";import{jsx as aO}from"react/jsx-runtime";var AI=({children:e,left:o,top:t,onCloseRequest:n,fitInViewport:r=!1,offsetLeft:i=0,offsetTop:a=0,viewportWidth:s=window.innerWidth,viewportHeight:l=window.innerHeight,className:c})=>{let m=PI(null);LI(()=>{let d=m.current;if(!d)return;d.contains(document.activeElement)||d.focus();let u=b=>{if(b.key===nO.TAB){let g=rO(d),{activeElement:E}=document,w=g.findIndex(x=>x===E);E===d?(b.shiftKey?g[g.length-1]?.focus():g[0].focus(),b.preventDefault(),b.stopImmediatePropagation()):w===0&&b.shiftKey?(g[g.length-1]?.focus(),b.preventDefault(),b.stopImmediatePropagation()):w===g.length-1&&!b.shiftKey&&(g[0]?.focus(),b.preventDefault(),b.stopImmediatePropagation())}};return d.addEventListener("keydown",u),()=>d.removeEventListener("keydown",u)},[]);let p=PI(null);return tO(()=>{if(r&&m.current&&t!=null&&o!=null){let d=m.current,{width:u,height:b}=d.getBoundingClientRect();if(p.current?.top===t&&p.current?.left===o)return;p.current={top:t,left:o},u>=s?(d.style.width=`${s}px`,d.style.left="0px",d.style.overflowX="scroll"):o+u-i>s?d.style.left=`${s-u-10}px`:d.style.left=`${o}px`,b>=l?(d.style.height=`${l-20}px`,d.style.top="10px",d.style.overflowY="scroll"):t+b-a>l?d.style.top=`${l-b}px`:d.style.top=`${t}px`}},[t,o,r,s,l,i,a]),LI(()=>{if(n){let d=u=>{m.current?.contains(u.target)||oO(()=>n(u))};return document.addEventListener("pointerdown",d,!1),()=>document.removeEventListener("pointerdown",d,!1)}},[n]),aO("div",{className:iO("popover",c),ref:m,tabIndex:-1,children:e})};import{jsx as ja,jsxs as cO}from"react/jsx-runtime";var nt="separator",DI=lO.memo(({actionManager:e,items:o,top:t,left:n,onClose:r})=>{let i=Zo(),a=Jn(),s=o.reduce((l,c)=>(c&&(c===nt||!c.predicate||c.predicate(a,i,e.app.props,e.app))&&l.push(c),l),[]);return ja(AI,{onCloseRequest:()=>{r()},top:t,left:n,fitInViewport:!0,offsetLeft:i.offsetLeft,offsetTop:i.offsetTop,viewportWidth:i.width,viewportHeight:i.height,className:"context-menu-popover",children:ja("ul",{className:"context-menu",onContextMenu:l=>l.preventDefault(),children:s.map((l,c)=>{if(l===nt)return!s[c-1]||s[c-1]===nt?null:ja("hr",{className:"context-menu-item-separator"},c);let m=l.name,p="";return l.label&&(typeof l.label=="function"?p=h(l.label(a,i,e.app)):p=h(l.label)),ja("li",{"data-testid":m,onClick:()=>{r(()=>{e.executeAction(l,"contextMenu")})},children:cO("button",{type:"button",className:sO("context-menu-item",{dangerous:m==="deleteSelectedElements",checkmark:l.checked?.(i)}),children:[ja("div",{className:"context-menu-item__label",children:p}),ja("kbd",{className:"context-menu-item__shortcut",children:m?Be(m):""})]})},c)})})})});import{jsx as o1,jsxs as _I}from"react/jsx-runtime";var dO=({height:e,width:o,userToFollow:t,onDisconnect:n})=>o1("div",{className:"follow-mode",style:{width:o,height:e},children:_I("div",{className:"follow-mode__badge",children:[_I("div",{className:"follow-mode__badge__label",children:["Following"," ",o1("span",{className:"follow-mode__badge__username",title:t.username,children:t.username})]}),o1("button",{type:"button",onClick:n,className:"follow-mode__disconnect-btn",children:io})]})}),RI=dO;import Mi from"clsx";import aW from"react";import{CLASSES as sW,DEFAULT_SIDEBAR as g0,TOOL_TYPE as NS,arrayToMap as lW,capitalizeString as cW,isShallowEqual as Hp}from"@orangecatai/common";import{mutateElement as dW}from"@orangecatai/element";import{showSelectedShapeActions as mW}from"@orangecatai/element";import{ShapeCache as pW}from"@orangecatai/element";import mO from"clsx";import{useState as pO,useEffect as uO}from"react";import{THEME as gO}from"@orangecatai/common";import{jsx as n1,jsxs as hO}from"react/jsx-runtime";var op=({delay:e,theme:o})=>{let[t,n]=pO(!!e);return uO(()=>{if(!e)return;let r=setTimeout(()=>{n(!1)},e);return()=>clearTimeout(r)},[e]),t?null:hO("div",{className:mO("LoadingMessage",{"LoadingMessage--dark":o===gO.DARK}),children:[n1("div",{children:n1(wt,{})}),n1("div",{className:"LoadingMessage-text",children:h("labels.loadingScene")})]})};import fO from"clsx";import{jsx as BI,jsxs as xO}from"react/jsx-runtime";var bO="medium",NI={CHECKED:Hi,UNCHECKED:Xr},FI=e=>xO("label",{className:fO("ToolIcon ToolIcon__lock",`ToolIcon_size_${bO}`,{"is-mobile":e.isMobile}),title:`${e.title} \u2014 Q`,children:[BI("input",{className:"ToolIcon_type_checkbox",type:"checkbox",name:e.name,onChange:e.onChange,checked:e.checked,"aria-label":e.title,"data-testid":"toolbar-lock"}),BI("div",{className:"ToolIcon__icon",children:e.checked?NI.CHECKED:NI.UNCHECKED})]});import{useState as np,useEffect as HI}from"react";import qa from"clsx";import{KEYS as r1,capitalizeString as it}from"@orangecatai/common";import EO from"clsx";import{KEYS as OI}from"@orangecatai/common";import{jsx as yO}from"react/jsx-runtime";var zI=e=>yO(Q,{className:EO("Shape",{fillable:!1,active:e.checked}),type:"radio",icon:$i,name:"editor-current-shape",checked:e.checked,title:`${e.title} \u2014 H`,keyBindingLabel:e.isMobile?void 0:OI.H.toLocaleUpperCase(),"aria-label":`${e.title} \u2014 H`,"aria-keyshortcuts":OI.H,"data-testid":"toolbar-hand",onChange:()=>e.onChange?.()});import{Fragment as wO,jsx as rt,jsxs as rp}from"react/jsx-runtime";var i1=[{type:"rectangle",icon:Gi,title:it(h("toolBar.rectangle"))},{type:"diamond",icon:Ui,title:it(h("toolBar.diamond"))},{type:"ellipse",icon:Wi,title:it(h("toolBar.ellipse"))}],a1=[{type:"selection",icon:$r,title:it(h("toolBar.selection"))},{type:"lasso",icon:Kn,title:it(h("toolBar.lasso"))}],s1=[{type:"arrow",icon:Dc,title:it(h("toolBar.arrow"))},{type:"line",icon:Yi,title:it(h("toolBar.line"))}],GI=({app:e,onHandToolToggle:o,setAppState:t})=>{let n=e.state.activeTool,[r,i]=np(!1),[a,s]=np("rectangle"),[l,c]=np("arrow");HI(()=>{(n.type==="rectangle"||n.type==="diamond"||n.type==="ellipse")&&s(n.type)},[n.type]),HI(()=>{(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}=Fe(),b=(A,z)=>{e.state.activeTool.type!==A&&me("toolbar",A,"ui"),A==="selection"?e.state.activeTool.type==="selection"||e.setActiveTool({type:"selection"}):e.setActiveTool({type:A})},[g,E]=np(0),w=36,x=4,y=7,v=y*w+(y-1)*x,T=w+x,C=g>=v+1*T,M=g>=v+2*T,S=g>=v+3*T,_=["text","frame","embeddable","laser","magicframe"].filter(A=>!(C&&A==="text"||M&&A==="image"||S&&A==="frame")).includes(n.type),P=_?n.type==="text"?Xo:n.type==="image"?Xn:n.type==="frame"?ko:n.type==="embeddable"?Vi:n.type==="laser"?$o:n.type==="magicframe"?qr:Ns:Ns;return rp("div",{className:"mobile-toolbar",ref:A=>{A&&E(A.getBoundingClientRect().width)},children:[rt(zI,{checked:wn(e.state),onChange:o,title:h("toolBar.hand"),isMobile:!0}),rt(za,{app:e,options:a1,activeTool:n,defaultOption:e.state.preferredSelectionTool.type,namePrefix:"selectionType",title:it(h("toolBar.selection")),"data-testid":"toolbar-selection",onToolChange:A=>{(A==="selection"||A==="lasso")&&(e.setActiveTool({type:A}),t({preferredSelectionTool:{type:A,initialized:!0}}))},displayedOption:a1.find(A=>A.type===e.state.preferredSelectionTool.type)||a1[0]}),rt(Q,{className:qa({active:n.type==="freedraw"}),type:"radio",icon:Ko,checked:n.type==="freedraw",name:"editor-current-shape",title:`${it(h("toolBar.freedraw"))}`,"aria-label":it(h("toolBar.freedraw")),"data-testid":"toolbar-freedraw",onChange:()=>b("freedraw")}),rt(Q,{className:qa({active:n.type==="eraser"}),type:"radio",icon:_c,checked:n.type==="eraser",name:"editor-current-shape",title:`${it(h("toolBar.eraser"))}`,"aria-label":it(h("toolBar.eraser")),"data-testid":"toolbar-eraser",onChange:()=>b("eraser")}),rt(za,{app:e,options:i1,activeTool:n,defaultOption:a,namePrefix:"shapeType",title:it(h(a==="rectangle"?"toolBar.rectangle":a==="diamond"?"toolBar.diamond":a==="ellipse"?"toolBar.ellipse":"toolBar.rectangle")),"data-testid":"toolbar-rectangle",onToolChange:A=>{(A==="rectangle"||A==="diamond"||A==="ellipse")&&(s(A),e.setActiveTool({type:A}))},displayedOption:i1.find(A=>A.type===a)||i1[0]}),rt(za,{app:e,options:s1,activeTool:n,defaultOption:l,namePrefix:"linearElementType",title:it(h(l==="arrow"?"toolBar.arrow":"toolBar.line")),"data-testid":"toolbar-arrow",fillable:!0,onToolChange:A=>{(A==="arrow"||A==="line")&&(c(A),e.setActiveTool({type:A}))},displayedOption:s1.find(A=>A.type===l)||s1[0]}),C&&rt(Q,{className:qa({active:n.type==="text"}),type:"radio",icon:Xo,checked:n.type==="text",name:"editor-current-shape",title:`${it(h("toolBar.text"))}`,"aria-label":it(h("toolBar.text")),"data-testid":"toolbar-text",onChange:()=>b("text")}),M&&rt(Q,{className:qa({active:n.type==="image"}),type:"radio",icon:Xn,checked:n.type==="image",name:"editor-current-shape",title:`${it(h("toolBar.image"))}`,"aria-label":it(h("toolBar.image")),"data-testid":"toolbar-image",onChange:()=>b("image")}),S&&rt(Q,{className:qa({active:m}),type:"radio",icon:ko,checked:m,name:"editor-current-shape",title:`${it(h("toolBar.frame"))}`,"aria-label":it(h("toolBar.frame")),"data-testid":"toolbar-frame",onChange:()=>b("frame")}),rp(se,{open:r,children:[rt(se.Trigger,{className:qa("App-toolbar__extra-tools-trigger App-toolbar__extra-tools-trigger--mobile",{"App-toolbar__extra-tools-trigger--selected":_||r}),onToggle:()=>{i(!r),t({openMenu:null,openPopup:null})},title:h("toolBar.extraTools"),style:{width:w,height:w,display:"flex",alignItems:"center",justifyContent:"center"},children:P}),rp(se.Content,{onClickOutside:()=>i(!1),onSelect:()=>i(!1),className:"App-toolbar__extra-tools-dropdown",align:"start",children:[!C&&rt(se.Item,{onSelect:()=>e.setActiveTool({type:"text"}),icon:Xo,shortcut:r1.T.toLocaleUpperCase(),"data-testid":"toolbar-text",selected:n.type==="text",children:h("toolBar.text")}),!M&&rt(se.Item,{onSelect:()=>e.setActiveTool({type:"image"}),icon:Xn,"data-testid":"toolbar-image",selected:n.type==="image",children:h("toolBar.image")}),!S&&rt(se.Item,{onSelect:()=>e.setActiveTool({type:"frame"}),icon:ko,shortcut:r1.F.toLocaleUpperCase(),"data-testid":"toolbar-frame",selected:m,children:h("toolBar.frame")}),rt(se.Item,{onSelect:()=>e.setActiveTool({type:"embeddable"}),icon:Vi,"data-testid":"toolbar-embeddable",selected:d,children:h("toolBar.embeddable")}),rt(se.Item,{onSelect:()=>e.setActiveTool({type:"laser"}),icon:$o,"data-testid":"toolbar-laser",selected:p,shortcut:r1.K.toLocaleUpperCase(),children:h("toolBar.laser")}),rt("div",{style:{margin:"6px 0",fontSize:14,fontWeight:600},children:"Generate"}),e.props.aiEnabled!==!1&&rt(u.Out,{}),rt(se.Item,{onSelect:()=>e.setOpenDialog({name:"ttd",tab:"mermaid"}),icon:ji,"data-testid":"toolbar-embeddable",children:h("toolBar.mermaidToExcalidraw")}),e.props.aiEnabled!==!1&&e.plugins.diagramToCode&&rt(wO,{children:rp(se.Item,{onSelect:()=>e.onMagicframeToolSelect(),icon:qr,"data-testid":"toolbar-magicframe",children:[h("toolBar.magicframe"),rt(se.Item.Badge,{children:"AI"})]})})]})]})]})};import vO from"clsx";import{jsx as TO}from"react/jsx-runtime";var ip=({children:e,side:o,className:t})=>TO("div",{className:vO("FixedSideContainer",`FixedSideContainer_side_${o}`,t),children:e});import IO from"clsx";import{jsx as UI,jsxs as SO}from"react/jsx-runtime";var CO="medium",ap=e=>e.penDetected?SO("label",{className:IO("ToolIcon ToolIcon__penMode",`ToolIcon_size_${CO}`,{"is-mobile":e.isMobile}),title:`${e.title}`,children:[UI("input",{className:"ToolIcon_type_checkbox",type:"checkbox",name:e.name,onChange:e.onChange,checked:e.checked,"aria-label":e.title}),UI("div",{className:"ToolIcon__icon",children:ax})]}):null;import{Fragment as WI,jsx as ln,jsxs as wi}from"react/jsx-runtime";var YI=({appState:e,elements:o,actionManager:t,setAppState:n,onHandToolToggle:r,renderTopLeftUI:i,renderTopRightUI:a,renderSidebars:s,renderWelcomeScreen:l,UIOptions:c,app:m,onPenModeToggle:p})=>{let{WelcomeScreenCenterTunnel:d,MainMenuTunnel:u,DefaultSidebarTriggerTunnel:b}=Fe(),g=()=>{if(e.openDialog?.name==="elementLinkSelector")return null;let w=wi("div",{className:"excalidraw-ui-top-right",children:[a?.(!0,e)??(!e.viewModeEnabled&&wi(WI,{children:[ln(ap,{checked:e.penMode,onChange:()=>p(null),title:h("toolBar.penMode"),isMobile:!0,penDetected:e.penDetected}),ln(b.Out,{})]})),e.viewModeEnabled&&ln(CT,{actionManager:t})]}),x=wi("div",{className:"excalidraw-ui-top-left",children:[i?.(!0,e),ln(u.Out,{})]});return wi("div",{className:"App-toolbar-content",style:{display:"flex",flexDirection:"row",justifyContent:"space-between"},children:[x,w]})},E=()=>ln(GI,{app:m,onHandToolToggle:r,setAppState:n});return wi(WI,{children:[s(),ln("div",{className:"App-welcome-screen",children:l&&ln(d.Out,{})}),!e.viewModeEnabled&&wi("div",{className:"App-bottom-bar",style:{marginBottom:ho+On},children:[ln(yT,{appState:e,elementsMap:m.scene.getNonDeletedElementsMap(),renderAction:t.renderAction,app:m,setAppState:n}),wi(qe,{className:"App-toolbar",children:[!e.viewModeEnabled&&e.openDialog?.name!=="elementLinkSelector"&&E(),e.scrolledOutside&&!e.openMenu&&!e.openSidebar&&ln("button",{type:"button",className:"scroll-back-to-content",onClick:()=>{n(w=>({...Yr(o,w)}))},children:h("buttons.scrollBackToContent")})]})]}),ln(ip,{side:"top",className:"App-top-bar",children:g()})]})};import kO,{useLayoutEffect as MO,useRef as PO,useState as LO}from"react";import{jsx as zl,jsxs as AO}from"react/jsx-runtime";var VI=e=>{let o=PO(null),[t,n]=LO(null);return MO(()=>{if(!e.spreadsheet)return;let r=Cw(e.chartType,e.spreadsheet,0,0);n(r);let i,a=o.current;return(async()=>(i=await Ni(r,{exportBackground:!1,viewBackgroundColor:"#fff"},null,{skipInliningFonts:!0}),i.querySelector(".style-fonts")?.remove(),a.replaceChildren(),a.appendChild(i),e.selected&&a.parentNode.focus()))(),()=>{a.replaceChildren()}},[e.spreadsheet,e.chartType,e.selected]),zl("button",{type:"button",className:"ChartPreview",onClick:()=>{t&&e.onClick(e.chartType,t)},children:zl("div",{ref:o})})},KI=({setAppState:e,appState:o,onClose:t})=>{let{onInsertElements:n}=ze(),r=kO.useCallback(()=>{t&&t()},[t]),i=(a,s)=>{n(s),me("paste","chart",a),e({currentChartType:a,pasteDialog:{shown:!1,data:null}})};return zl(Qe,{size:"small",onCloseRequest:r,title:h("labels.pasteCharts"),className:"PasteChartDialog",autofocus:!1,children:AO("div",{className:"container",children:[zl(VI,{chartType:"bar",spreadsheet:o.pasteDialog.data,selected:o.currentChartType==="bar",onClick:i}),zl(VI,{chartType:"line",spreadsheet:o.pasteDialog.data,selected:o.currentChartType==="line",onClick:i})]})})};import{Fragment as DO,jsx as XI,jsxs as _O}from"react/jsx-runtime";var Hl=({heading:e,children:o,...t})=>{let{id:n}=Oe(),r=XI("h2",{className:"visually-hidden",id:`${n}-${e}-title`,children:h(`headings.${e}`)});return XI("section",{...t,"aria-labelledby":`${n}-${e}-title`,children:typeof o=="function"?o(r):_O(DO,{children:[r,o]})})};import{Popover as sp}from"radix-ui";import $I from"clsx";import lp,{useLayoutEffect as RO}from"react";import{supportsResizeObserver as NO,isShallowEqual as BO}from"@orangecatai/common";import{Fragment as GO,jsx as cn,jsxs as cp}from"react/jsx-runtime";var FO=4,OO=8,zO=({shouldWrap:e,children:o,username:t})=>e?cn(qt,{label:t||"Unknown user",children:o}):cn(GO,{children:o}),l1=({actionManager:e,collaborator:o,socketId:t,withName:n=!1,shouldWrapWithTooltip:r=!1,isBeingFollowed:i})=>{let a={socketId:t,collaborator:o,withName:n,isBeingFollowed:i},s=e.renderAction("goToCollaborator",a);return cn(zO,{username:o.username,shouldWrap:r,children:s},t)},HO=["avatarUrl","id","socketId","username","isInCall","isSpeaking","isMuted"],dp=lp.memo(({className:e,mobile:o,collaborators:t,userToFollow:n})=>{let r=We(),i=new Map;t.forEach((g,E)=>{let w=g.id||E;i.set(w,{...g,socketId:E})});let a=Array.from(i.values()).filter(g=>g.username?.trim()),[s,l]=lp.useState(""),c=a.filter(g=>g.username?.toLowerCase().includes(s)),m=lp.useRef(null);RO(()=>{if(m.current){let g=w=>{let x=Math.max(1,Math.min(8,Math.floor(w/38)));d(x)};if(g(m.current.clientWidth),!NO)return;let E=new ResizeObserver(w=>{for(let x of w){let{width:y}=x.contentRect;g(y)}});return E.observe(m.current),()=>{E.disconnect()}}},[]);let[p,d]=lp.useState(FO),b=a.slice(0,p-1).map(g=>l1({actionManager:r,collaborator:g,socketId:g.socketId,shouldWrapWithTooltip:!0,isBeingFollowed:g.socketId===n}));return o?cn("div",{className:$I("UserList UserList_mobile",e),children:a.map(g=>l1({actionManager:r,collaborator:g,socketId:g.socketId,shouldWrapWithTooltip:!0,isBeingFollowed:g.socketId===n}))}):cn("div",{className:"UserList__wrapper",ref:m,children:cp("div",{className:$I("UserList",e),style:{"--max-avatars":p},children:[b,a.length>p-1&&cp(sp.Root,{children:[cp(sp.Trigger,{className:"UserList__more",children:["+",a.length-p+1]}),cn(sp.Content,{style:{zIndex:2,width:"15rem",textAlign:"left"},align:"end",sideOffset:10,children:cp(qe,{padding:2,children:[a.length>=OO&&cn(ad,{placeholder:h("quickSearch.placeholder"),onChange:l}),cn(sd,{className:"dropdown-menu UserList__collaborators",placeholder:h("userList.empty"),children:c.length>0?[cn("div",{className:"hint",children:h("userList.hint.text")}),c.map(g=>l1({actionManager:r,collaborator:g,socketId:g.socketId,withName:!0,isBeingFollowed:g.socketId===n}))]:[]}),cn(sp.Arrow,{width:20,height:10,style:{fill:"var(--popup-bg-color)",filter:"drop-shadow(rgba(0, 0, 0, 0.05) 0px 3px 2px)"}})]})})]})]})})},(e,o)=>{if(e.collaborators.size!==o.collaborators.size||e.mobile!==o.mobile||e.className!==o.className||e.userToFollow!==o.userToFollow)return!1;let t=o.collaborators.keys();for(let[n,r]of e.collaborators){let i=o.collaborators.get(n);if(!i||n!==t.next().value||!BO(r,i,HO))return!1}return!0});import c1 from"clsx";import{jsx as UO}from"react/jsx-runtime";var ZI=e=>UO("button",{className:"help-icon",onClick:e.onClick,type:"button",title:`${h("helpDialog.title")} \u2014 ?`,"aria-label":h("helpDialog.title"),children:Ki});import{jsx as zn,jsxs as d1}from"react/jsx-runtime";var jI=({appState:e,actionManager:o,showExitZenModeBtn:t,renderWelcomeScreen:n})=>{let{FooterCenterTunnel:r,WelcomeScreenHelpHintTunnel:i}=Fe();return d1("footer",{role:"contentinfo",className:"layer-ui__wrapper__footer App-menu App-menu_bottom",children:[zn("div",{className:c1("layer-ui__wrapper__footer-left zen-mode-transition",{"layer-ui__wrapper__footer-left--transition-left":e.zenModeEnabled}),children:zn(St.Col,{gap:2,children:d1(Hl,{heading:"canvasActions",children:[zn(vT,{renderAction:o.renderAction,zoom:e.zoom}),!e.viewModeEnabled&&zn(TT,{renderAction:o.renderAction,className:c1("zen-mode-transition",{"layer-ui__wrapper__footer-left--transition-bottom":e.zenModeEnabled})})]})})}),zn(r.Out,{}),zn("div",{className:c1("layer-ui__wrapper__footer-right zen-mode-transition",{"transition-right":e.zenModeEnabled}),children:d1("div",{style:{position:"relative"},children:[n&&zn(i.Out,{}),zn(ZI,{onClick:()=>o.executeAction(ai)})]})}),zn(IT,{actionManager:o,showExitZenModeBtn:t})]})},qI=jI;jI.displayName="Footer";import ez from"clsx";import{useEffect as r5,useLayoutEffect as i5,useRef as E1,useState as tz,forwardRef as a5,useImperativeHandle as oz,useCallback as t5}from"react";import{CLASSES as nz,EVENT as o5,isDevEnv as rz,KEYS as iz,updateObject as az}from"@orangecatai/common";import YO from"clsx";import{useContext as VO}from"react";import WO from"react";var mp=WO.createContext({});import{jsx as m1,jsxs as JI}from"react/jsx-runtime";var p1=({children:e,className:o})=>{let t=fe(),n=VO(mp),r=!!(t.canFitSidebar&&n.shouldRenderDockButton);return JI("div",{className:YO("sidebar__header",o),"data-testid":"sidebar-header",children:[e,JI("div",{className:"sidebar__header__buttons",children:[r&&m1(qt,{label:h("labels.sidebarLock"),children:m1(Ft,{onSelect:()=>n.onDock?.(!n.docked),selected:!!n.docked,className:"sidebar__dock","data-testid":"sidebar-dock","aria-label":h("labels.sidebarLock"),children:tx})}),m1(Ft,{"data-testid":"sidebar-close",className:"sidebar__close",onSelect:n.onCloseRequest,"aria-label":h("buttons.close"),children:io})]})]})};p1.displayName="SidebarHeader";import{Tabs as KO}from"radix-ui";import{jsx as QI}from"react/jsx-runtime";var u1=({children:e,tab:o,onSelect:t,...n})=>QI(KO.Trigger,{value:o,asChild:!0,onSelect:t,children:QI("button",{type:"button",className:"excalidraw-button sidebar-tab-trigger",...n,children:e})});u1.displayName="SidebarTabTrigger";import{Tabs as XO}from"radix-ui";import{jsx as $O}from"react/jsx-runtime";var g1=({children:e,...o})=>$O(XO.List,{className:"sidebar-triggers",...o,children:e});g1.displayName="SidebarTabTriggers";import ZO from"clsx";import{jsx as h1,jsxs as e5}from"react/jsx-runtime";var f1=({name:e,tab:o,icon:t,title:n,children:r,onToggle:i,className:a,style:s})=>{let l=be(),c=he();return e5("label",{title:n,className:"sidebar-trigger__label-element",children:[h1("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:o}:null,openMenu:null,openPopup:null}),i?.(p)},checked:c.openSidebar?.name===e,"aria-label":n,"aria-keyshortcuts":"0"}),e5("div",{className:ZO("sidebar-trigger",a),style:s,children:[t&&h1("div",{children:t}),r&&h1("div",{className:"sidebar-trigger__label",children:r})]})]})};f1.displayName="SidebarTrigger";import{Tabs as jO}from"radix-ui";import{jsx as qO}from"react/jsx-runtime";var b1=({children:e,...o})=>{let t=he(),n=be();if(!t.openSidebar)return null;let{name:r}=t.openSidebar;return qO(jO.Root,{className:"sidebar-tabs-root",value:t.openSidebar.tab,onValueChange:i=>n(a=>({...a,openSidebar:{...a.openSidebar,name:r,tab:i}})),...o,children:e})};b1.displayName="SidebarTabs";import{Tabs as JO}from"radix-ui";import{jsx as QO}from"react/jsx-runtime";var x1=({tab:e,children:o,...t})=>QO(JO.Content,{...t,value:e,"data-testid":e,children:o});x1.displayName="SidebarTab";import{jsx as n5}from"react/jsx-runtime";import{createElement as sz}from"react";var Gl=ye(!1),s5=a5(({name:e,children:o,onDock:t,docked:n,className:r,...i},a)=>{rz()&&t&&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=be(),l=Yo(Gl);i5(()=>(l(!!n),()=>{l(!1)}),[l,n]);let c=E1({});c.current.onCloseRequest=()=>{s({openSidebar:null})},c.current.onDock=u=>t?.(u),c.current=az(c.current,{docked:n,shouldRenderDockButton:!!t&&n!=null});let m=E1(null);oz(a,()=>m.current);let p=fe(),d=t5(()=>{document.querySelector(".Dialog")||s({openSidebar:null})},[s]);return ra(m,t5(u=>{u.target.closest(".sidebar-trigger")||(!n||!p.canFitSidebar)&&d()},[d,n,p.canFitSidebar])),r5(()=>{let u=b=>{b.key===iz.ESCAPE&&(!n||!p.canFitSidebar)&&d()};return document.addEventListener(o5.KEYDOWN,u),()=>{document.removeEventListener(o5.KEYDOWN,u)}},[d,n,p.canFitSidebar]),n5(qe,{...i,className:ez(nz.SIDEBAR,{"sidebar--docked":n},r),ref:m,children:n5(mp.Provider,{value:c.current,children:o})})});s5.displayName="SidebarInner";var bo=Object.assign(a5((e,o)=>{let t=he()??{openSidebar:null},{onStateChange:n}=e,r=E1(t.openSidebar);r5(()=>{(!t.openSidebar&&r?.current?.name===e.name||t.openSidebar?.name===e.name&&r?.current?.name!==e.name||r.current?.name===e.name)&&t.openSidebar!==r.current&&n?.(t.openSidebar?.name!==e.name?null:t.openSidebar),r.current=t.openSidebar},[t.openSidebar,n,e.name]);let[i,a]=tz(!1);return i5(()=>(a(!0),()=>a(!1)),[]),i&&t.openSidebar?.name===e.name?sz(s5,{...e,ref:o,key:e.name}):null}),{Header:p1,TabTriggers:g1,TabTrigger:u1,Tabs:b1,Tab:x1,Trigger:f1});bo.displayName="Sidebar";import{composeEventHandlers as hz}from"@orangecatai/common";import{useLayoutEffect as lz,useRef as cz}from"react";import{jsx as dz}from"react/jsx-runtime";var Hn=(e,o)=>{let t=ye(0),n=r=>{let{tunnelsJotai:{useAtom:i}}=Fe(),[,a]=i(t),s=cz({preferHost:!1,counter:0});return lz(()=>{let l=s.current;return a(c=>{let m=c+1;return l.counter=m,m}),()=>{a(c=>{let m=c-1;return l.counter=m,m||(l.preferHost=!1),m})}},[a]),r.__fallback||(s.current.preferHost=!0),!s.current.counter&&r.__fallback&&s.current.preferHost||s.current.counter>1&&r.__fallback?null:dz(o,{...r})};return n.displayName=e,n};var I1={};Ib(I1,{ChangeCanvasBackground:()=>w5,ClearCanvas:()=>E5,CommandPalette:()=>f5,Export:()=>v5,Help:()=>x5,LiveCollaborationTrigger:()=>I5,LoadScene:()=>u5,Preferences:()=>Tr,PreferencesToggleGridModeItem:()=>v1,PreferencesToggleZenModeItem:()=>T1,SaveAsImage:()=>h5,SaveToActiveFile:()=>g5,SearchMenu:()=>b5,Socials:()=>T5,ToggleTheme:()=>y5});import gz from"clsx";import{THEME as vr}from"@orangecatai/common";var y1=ye({active:!1});async function l5({title:e,description:o,actionLabel:t,color:n}){return new Promise(r=>{ot.set(y1,{active:!0,onConfirm:()=>r(!0),onClose:()=>r(!1),onReject:()=>r(!1),title:e,description:o,actionLabel:t,color:n})})}import mz from"clsx";import{jsx as c5,jsxs as pz}from"react/jsx-runtime";var pp=function({onChange:e,value:o,choices:t,name:n}){return c5("div",{className:"RadioGroup",children:t.map(r=>pz("div",{className:mz("RadioGroup__choice",{active:r.value===o}),title:r.ariaLabel,children:[c5("input",{name:n,type:"radio",checked:r.value===o,onChange:()=>e(r.value),"aria-label":r.ariaLabel}),r.label]},String(r.value)))})};import{Fragment as uz,jsx as w1,jsxs as d5}from"react/jsx-runtime";var m5=({value:e,shortcut:o,onChange:t,choices:n,children:r,name:i})=>{let a=fe();return d5(uz,{children:[d5("div",{className:"dropdown-menu-item-base dropdown-menu-item-bare",children:[w1("label",{className:"dropdown-menu-item__text",children:r}),w1(pp,{name:i,value:e,onChange:t,choices:n})]}),o&&a.formFactor!=="phone"&&w1("div",{className:"dropdown-menu-item__shortcut dropdown-menu-item__shortcut--orphaned",children:o})]})};m5.displayName="DropdownMenuItemContentRadio";var p5=m5;import{Fragment as P5,jsx as ke,jsxs as Ul}from"react/jsx-runtime";var u5=()=>{let{t:e}=Ae(),o=We(),t=Jn();return o.isActionEnabled(xa)?ke(At,{icon:Xi,onSelect:async()=>{(!t.length||await l5({title:e("overwriteConfirm.modal.loadFromFile.title"),actionLabel:e("overwriteConfirm.modal.loadFromFile.button"),color:"warning",description:ke(Bt,{i18nKey:"overwriteConfirm.modal.loadFromFile.description",bold:r=>ke("strong",{children:r}),br:()=>ke("br",{})})}))&&o.executeAction(xa)},"data-testid":"load-button",shortcut:Be("loadScene"),"aria-label":e("buttons.load"),children:e("buttons.load")}):null};u5.displayName="LoadScene";var g5=()=>{let{t:e}=Ae(),o=We();return o.isActionEnabled(ii)?ke(At,{shortcut:Be("saveScene"),"data-testid":"save-button",onSelect:()=>o.executeAction(ii),icon:ux,"aria-label":`${e("buttons.save")}`,children:`${e("buttons.save")}`}):null};g5.displayName="SaveToActiveFile";var h5=()=>{let e=be(),{t:o}=Ae();return ke(At,{icon:Fc,"data-testid":"image-export-button",onSelect:()=>e({openDialog:{name:"imageExport"}}),shortcut:Be("imageExport"),"aria-label":o("buttons.exportImage"),children:o("buttons.exportImage")})};h5.displayName="SaveAsImage";var f5=e=>{let o=be(),{t}=Ae();return ke(At,{icon:Bs,"data-testid":"command-palette-button",onSelect:()=>{me("command_palette","open","menu"),o({openDialog:{name:"commandPalette"}})},shortcut:Be("commandPalette"),"aria-label":t("commandPalette.title"),className:e?.className,children:t("commandPalette.title")})};f5.displayName="CommandPalette";var b5=e=>{let{t:o}=Ae(),t=We();return ke(At,{icon:jt,"data-testid":"search-menu-button",onSelect:()=>{t.executeAction(Cl)},shortcut:Be("searchMenu"),"aria-label":o("search.title"),className:e?.className,children:o("search.title")})};b5.displayName="SearchMenu";var x5=()=>{let{t:e}=Ae(),o=We();return ke(At,{"data-testid":"help-menu-item",icon:Ki,onSelect:()=>o.executeAction(ai),shortcut:"?","aria-label":e("helpDialog.title"),children:e("helpDialog.title")})};x5.displayName="Help";var E5=()=>{let{t:e}=Ae(),o=Yo(mi);return We().isActionEnabled(Mn)?ke(At,{icon:yt,onSelect:()=>o("clearCanvas"),"data-testid":"clear-canvas-button","aria-label":e("buttons.clearReset"),children:e("buttons.clearReset")}):null};E5.displayName="ClearCanvas";var y5=e=>{let{t:o}=Ae(),t=he(),n=We(),r=Be("toggleTheme");return n.isActionEnabled(ti)?e?.allowSystemTheme?ke(p5,{name:"theme",value:e.theme,onChange:i=>e.onSelect(i),choices:[{value:vr.LIGHT,label:Ds,ariaLabel:`${o("buttons.lightMode")} - ${r}`},{value:vr.DARK,label:As,ariaLabel:`${o("buttons.darkMode")} - ${r}`},{value:"system",label:LE,ariaLabel:o("buttons.systemMode")}],children:o("labels.theme")}):ke(At,{onSelect:i=>{if(i.preventDefault(),e?.onSelect)e.onSelect(t.theme===vr.DARK?vr.LIGHT:vr.DARK);else return n.executeAction(ti)},icon:t.theme===vr.DARK?Ds:As,"data-testid":"toggle-dark-mode",shortcut:r,"aria-label":t.theme===vr.DARK?o("buttons.lightMode"):o("buttons.darkMode"),children:t.theme===vr.DARK?o("buttons.lightMode"):o("buttons.darkMode")}):null};y5.displayName="ToggleTheme";var w5=()=>{let{t:e}=Ae(),o=he(),t=We(),n=jo();return o.viewModeEnabled||!n.UIOptions.canvasActions.changeViewBackgroundColor?null:Ul("div",{style:{marginTop:"0.75rem"},children:[ke("div",{"data-testid":"canvas-background-label",style:{fontSize:"0.875rem",marginBottom:"0.25rem",marginLeft:"0.5rem"},children:e("labels.canvasBackground")}),ke("div",{style:{padding:"0 0.625rem"},children:t.renderAction("changeViewBackgroundColor")})]})};w5.displayName="ChangeCanvasBackground";var v5=()=>{let{t:e}=Ae(),o=be();return ke(At,{icon:Zr,onSelect:()=>{o({openDialog:{name:"jsonExport"}})},"data-testid":"json-export-button","aria-label":e("buttons.export"),children:e("buttons.export")})};v5.displayName="Export";var T5=()=>{let{t:e}=Ae();return Ul(P5,{children:[ke(Fa,{icon:Rc,href:"https://github.com/excalidraw/excalidraw","aria-label":"GitHub",children:"GitHub"}),ke(Fa,{icon:px,href:"https://x.com/excalidraw","aria-label":"X",children:e("labels.followUs")}),ke(Fa,{icon:mx,href:"https://discord.gg/UexuTaE","aria-label":"Discord",children:e("labels.discordChat")})]})};T5.displayName="Socials";var I5=({onSelect:e,isCollaborating:o})=>{let{t}=Ae();return ke(At,{"data-testid":"collab-button",icon:Oc,className:gz({"active-collab":o}),onSelect:e,children:t("labels.liveCollaboration")})};I5.displayName="LiveCollaborationTrigger";var C5=()=>{let{t:e}=Ae(),o=ze(),t=he();return ke(Dn,{checked:t.activeTool.locked,shortcut:Be("toolLock"),onSelect:n=>{o.toggleLock(),n.preventDefault()},children:e("labels.preferences_toolLock")})},S5=()=>{let{t:e}=Ae(),o=We(),t=he();return ke(Dn,{checked:t.objectsSnapModeEnabled,shortcut:Be("objectsSnapMode"),onSelect:n=>{o.executeAction(ll),n.preventDefault()},children:e("buttons.objectsSnapMode")})},v1=()=>{let{t:e}=Ae(),o=We(),t=he();return ke(Dn,{checked:t.gridModeEnabled,shortcut:Be("gridMode"),onSelect:n=>{o.executeAction(Ca),n.preventDefault()},children:e("labels.toggleGrid")})},T1=()=>{let{t:e}=Ae(),o=We(),t=he();return ke(Dn,{checked:t.zenModeEnabled,shortcut:Be("zenMode"),onSelect:n=>{o.executeAction(lr),n.preventDefault()},children:e("buttons.zenMode")})},k5=()=>{let{t:e}=Ae(),o=We(),t=he();return ke(Dn,{checked:t.viewModeEnabled,shortcut:Be("viewMode"),onSelect:n=>{o.executeAction(di),n.preventDefault()},children:e("labels.viewMode")})},M5=()=>{let{t:e}=Ae(),o=We(),t=he();return ke(Dn,{checked:t.stats.open,shortcut:Be("stats"),onSelect:n=>{o.executeAction(cr),n.preventDefault()},children:e("stats.fullTitle")})},Tr=({children:e,additionalItems:o})=>{let{t}=Ae();return Ul(pr,{children:[ke(pr.Trigger,{icon:UE,children:t("labels.preferences")}),Ul(pr.Content,{className:"excalidraw-main-menu-preferences-submenu",children:[e||Ul(P5,{children:[ke(C5,{}),ke(S5,{}),ke(v1,{}),ke(T1,{}),ke(k5,{}),ke(M5,{})]}),o]})]})};Tr.ToggleToolLock=C5;Tr.ToggleSnapMode=S5;Tr.ToggleGridMode=v1;Tr.ToggleZenMode=T1;Tr.ToggleViewMode=k5;Tr.ToggleElementProperties=M5;Tr.displayName="Preferences";import{jsx as up,jsxs as C1}from"react/jsx-runtime";var fz=Object.assign(Hn("MainMenu",({children:e,onSelect:o})=>{let{MainMenuTunnel:t}=Fe(),n=fe(),r=he(),i=be();return up(t.In,{children:C1(se,{open:r.openMenu==="canvas",children:[up(se.Trigger,{onToggle:()=>{i({openMenu:r.openMenu==="canvas"?null:"canvas",openPopup:null,openDialog:null})},"data-testid":"main-menu-trigger",className:"main-menu-trigger",children:cx}),C1(se.Content,{onClickOutside:()=>i({openMenu:null}),onSelect:hz(o,()=>{i({openMenu:null})}),className:"main-menu",align:"start",children:[e,n.formFactor==="phone"&&r.collaborators.size>0&&C1("fieldset",{className:"UserList-Wrapper",children:[up("legend",{children:h("labels.collaborators")}),up(dp,{mobile:!0,collaborators:r.collaborators,userToFollow:r.userToFollow?.socketId||null})]})]})]})})}),{Trigger:se.Trigger,Item:se.Item,ItemLink:se.ItemLink,ItemCustom:se.ItemCustom,Group:se.Group,Separator:se.Separator,Sub:pr,DefaultItems:I1}),kt=fz;import bz from"clsx";import{forwardRef as xz,useState as Ez}from"react";import{isPromiseLike as yz}from"@orangecatai/common";import{jsx as gp,jsxs as wz}from"react/jsx-runtime";var xo=xz(({children:e,icon:o,onClick:t,label:n,variant:r="filled",color:i="primary",size:a="medium",fullWidth:s,className:l,status:c,disabled:m},p)=>{let[d,u]=Ez(!1),b=async E=>{let w=t?.(E);if(yz(w)){let x=window.setTimeout(()=>{u(!0)},50);try{await w}catch(y){if(y instanceof _i)console.warn(y);else throw y}finally{clearTimeout(x),u(!1)}}},g=d?"loading":c;return i=g==="success"?"success":i,gp("button",{className:bz("ExcButton",`ExcButton--color-${i}`,`ExcButton--variant-${r}`,`ExcButton--size-${a}`,`ExcButton--status-${g}`,{"ExcButton--fullWidth":s},l),onClick:b,type:"button","aria-label":n,ref:p,disabled:m||g==="loading"||g==="success",children:wz("div",{className:"ExcButton__contents",children:[g==="loading"?gp(wt,{className:"ExcButton__statusIcon"}):g==="success"&&gp("div",{className:"ExcButton__statusIcon",children:dE}),o&&gp("div",{className:"ExcButton__icon","aria-hidden":!0,children:o}),r!=="icon"&&(e??n)]})})});import{jsx as Ja,jsxs as Iz}from"react/jsx-runtime";var hp=({title:e,children:o,actionLabel:t,onClick:n})=>Iz("div",{className:"OverwriteConfirm__Actions__Action",children:[Ja("h4",{children:e}),Ja("div",{className:"OverwriteConfirm__Actions__Action__content",children:o}),Ja(xo,{variant:"outlined",color:"muted",label:t,size:"large",fullWidth:!0,onClick:n})]}),vz=()=>{let{t:e}=Ae(),o=We(),t=be();return Ja(hp,{title:e("overwriteConfirm.action.exportToImage.title"),actionLabel:e("overwriteConfirm.action.exportToImage.button"),onClick:()=>{o.executeAction(Pd,"ui",!0),t({openDialog:{name:"imageExport"}})},children:e("overwriteConfirm.action.exportToImage.description")})},Tz=()=>{let{t:e}=Ae(),o=We();return Ja(hp,{title:e("overwriteConfirm.action.saveToDisk.title"),actionLabel:e("overwriteConfirm.action.saveToDisk.button"),onClick:()=>{o.executeAction(al,"ui")},children:e("overwriteConfirm.action.saveToDisk.description")})},S1=Object.assign(({children:e})=>Ja("div",{className:"OverwriteConfirm__Actions",children:e}),{ExportToImage:vz,SaveToDisk:Tz});import{jsx as Ir,jsxs as L5}from"react/jsx-runtime";var fp=Object.assign(Hn("OverwriteConfirmDialog",({children:e})=>{let{OverwriteConfirmDialogTunnel:o}=Fe(),[t,n]=ee(y1);if(!t.active)return null;let r=()=>{t.onClose(),n(a=>({...a,active:!1}))},i=()=>{t.onConfirm(),n(a=>({...a,active:!1}))};return Ir(o.In,{children:Ir(Qe,{onCloseRequest:r,title:!1,size:916,children:L5("div",{className:"OverwriteConfirm",children:[Ir("h3",{children:t.title}),L5("div",{className:`OverwriteConfirm__Description OverwriteConfirm__Description--color-${t.color}`,children:[Ir("div",{className:"OverwriteConfirm__Description__icon",children:Gc}),Ir("div",{children:t.description}),Ir("div",{className:"OverwriteConfirm__Description__spacer"}),Ir(xo,{color:t.color,size:"large",label:t.actionLabel,onClick:i})]}),Ir(S1,{children:e})]})})})}),{Actions:S1,Action:hp});import Kz from"clsx";import{CANVAS_SEARCH_TAB as A1,DEFAULT_SIDEBAR as Xz,LIBRARY_SIDEBAR_TAB as H5,composeEventHandlers as $z}from"@orangecatai/common";import{round as Cz}from"@orangecatai/math";import Sz from"clsx";import kz from"lodash.debounce";import{Fragment as Mz,memo as Pz,useEffect as Wl,useMemo as A5,useRef as k1,useState as D5}from"react";import{CLASSES as Lz,EVENT as Az,FONT_FAMILY as M1,FRAME_STYLE as P1,getLineHeight as Dz}from"@orangecatai/common";import{isElementCompletelyInViewport as _z}from"@orangecatai/element";import{measureText as Yl}from"@orangecatai/element";import{KEYS as Qa,randomInteger as _5,addEventListener as Rz,getFontString as bp}from"@orangecatai/common";import{newTextElement as Nz}from"@orangecatai/element";import{isTextElement as F5,isFrameLikeElement as xp}from"@orangecatai/element";import{getDefaultFrameName as O5}from"@orangecatai/element/frame";import{Fragment as Vz,jsx as bt,jsxs as dn}from"react/jsx-runtime";var Bz=ye(""),L1=ye(null),Fz=350,z5=()=>{let e=ze(),o=be(),t=k1(null),[n,r]=ee(Bz),i=n.trim(),[a,s]=D5(!1),[l,c]=D5({nonce:null,items:[]}),m=k1(null),p=k1(void 0),[d,u]=ee(L1),b=e.scene.getNonDeletedElementsMap();Wl(()=>{a||(i!==m.current||e.scene.getSceneNonce()!==p.current)&&(m.current=null,B5(i,e,(y,v)=>{c({nonce:_5(),items:y}),m.current=i,p.current=e.scene.getSceneNonce(),o({searchMatches:y.length?{focusedId:null,matches:y.map(T=>({id:T.element.id,focus:!1,matchedLines:T.matchedLines}))}:null})}))},[a,i,b,e,o,u,p]);let g=()=>{l.items.length>0&&u(y=>y===null?0:(y+1)%l.items.length)},E=()=>{l.items.length>0&&u(y=>y===null?0:y-1<0?l.items.length-1:y-1)};Wl(()=>{o(y=>y.searchMatches?{searchMatches:{focusedId:d!==null&&y.searchMatches?.matches[d]?.id||null,matches:y.searchMatches.matches.map((T,C)=>C===d?{...T,focus:!0}:{...T,focus:!1})}}:null)},[d,o]),Wl(()=>{if(l.items.length>0&&d!==null){let y=l.items[d];if(y){let v=e.state.zoom.value,T=Nz({text:y.searchQuery,x:y.element.x+(y.matchedLines[0]?.offsetX??0),y:y.element.y+(y.matchedLines[0]?.offsetY??0),width:y.matchedLines[0]?.width,height:y.matchedLines[0]?.height,fontSize:xp(y.element)?P1.nameFontSize:y.element.fontSize,fontFamily:xp(y.element)?M1.Assistant:y.element.fontFamily}),C=14,M=T.fontSize,S=M*v<C;if(!_z([T],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?M>=C?D={fitToContent:!0}:D={fitToViewport:!0,maxZoom:Cz(C/M,1)}:D={fitToContent:!0},e.scrollToContent(T,{animate:!0,duration:300,...D,canvasOffsets:e.getEditorUIOffsets()})}}}},[d,l,e]),Wl(()=>()=>{u(null),m.current=null,p.current=void 0,o({searchMatches:null}),s(!1)},[o,u]);let w=Zn({goToNextItem:g,goToPreviousItem:E,searchMatches:l});Wl(()=>{let y=v=>{if(v.key===Qa.ESCAPE&&!e.state.openDialog&&!e.state.openPopup){v.preventDefault(),v.stopPropagation(),o({openSidebar:null});return}if(v[Qa.CTRL_OR_CMD]&&v.key===Qa.F){if(v.preventDefault(),v.stopPropagation(),e.state.openDialog)return;t.current?.matches(":focus")||(e.state.openDialog&&o({openDialog:null}),t.current?.focus(),t.current?.select())}v.target instanceof HTMLElement&&v.target.closest(".layer-ui__search")&&w.searchMatches.items.length&&(v.key===Qa.ENTER&&(v.stopPropagation(),w.goToNextItem()),v.key===Qa.ARROW_UP?(v.stopPropagation(),w.goToPreviousItem()):v.key===Qa.ARROW_DOWN&&(v.stopPropagation(),w.goToNextItem()))};return Rz(window,Az.KEYDOWN,y,{capture:!0,passive:!1})},[o,w,e]);let x=`${l.items.length} ${l.items.length===1?h("search.singleResult"):h("search.multipleResults")}`;return dn("div",{className:"layer-ui__search",children:[bt("div",{className:"layer-ui__search-header",children:bt(ur,{className:Lz.SEARCH_MENU_INPUT_WRAPPER,value:n,ref:t,placeholder:h("search.placeholder"),icon:jt,onChange:y=>{r(y),s(!0);let v=y.trim();B5(v,e,(T,C)=>{c({nonce:_5(),items:T}),u(C),m.current=v,p.current=e.scene.getSceneNonce(),o({searchMatches:T.length?{focusedId:null,matches:T.map(M=>({id:M.element.id,focus:!1,matchedLines:M.matchedLines}))}:null}),s(!1)})},selectOnRender:!0})}),dn("div",{className:"layer-ui__search-count",children:[l.items.length>0&&dn(Vz,{children:[d!==null&&d>-1?dn("div",{children:[d+1," / ",x]}):bt("div",{children:x}),dn("div",{className:"result-nav",children:[bt(Ft,{onSelect:()=>{g()},className:"result-nav-btn",children:Wc}),bt(Ft,{onSelect:()=>{E()},className:"result-nav-btn",children:NE})]})]}),l.items.length===0&&i&&m.current&&bt("div",{style:{margin:"1rem auto"},children:h("search.noMatch")})]}),bt(Hz,{matches:l,onItemClick:u,focusIndex:d,searchQuery:i})]})},R5=e=>{let o=[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 bt("div",{tabIndex:-1,className:Sz("layer-ui__result-item",{active:e.highlighted}),onClick:e.onClick,ref:t=>{e.highlighted&&t?.scrollIntoView({behavior:"auto",block:"nearest"})},children:bt("div",{className:"preview-text",children:o.flatMap((t,n)=>bt(Mz,{children:n===2?bt("b",{children:t}):t},n))})})},Oz=e=>{let o=A5(()=>e.matches.items.filter(n=>xp(n.element)),[e.matches]),t=A5(()=>e.matches.items.filter(n=>F5(n.element)),[e.matches]);return dn("div",{children:[o.length>0&&dn("div",{className:"layer-ui__search-result-container",children:[dn("div",{className:"layer-ui__search-result-title",children:[bt("div",{className:"title-icon",children:ko}),bt("div",{children:h("search.frames")})]}),o.map((n,r)=>bt(R5,{searchQuery:e.searchQuery,preview:n.preview,highlighted:r===e.focusIndex,onClick:()=>e.onItemClick(r)},n.element.id+n.index)),t.length>0&&bt("div",{className:"layer-ui__divider"})]}),t.length>0&&dn("div",{className:"layer-ui__search-result-container",children:[dn("div",{className:"layer-ui__search-result-title",children:[bt("div",{className:"title-icon",children:Xo}),bt("div",{children:h("search.texts")})]}),t.map((n,r)=>bt(R5,{searchQuery:e.searchQuery,preview:n.preview,highlighted:r+o.length===e.focusIndex,onClick:()=>e.onItemClick(r+o.length)},n.element.id+n.index))]})]})},zz=(e,o)=>e.matches.nonce===o.matches.nonce&&e.focusIndex===o.focusIndex,Hz=Pz(Oz,zz),N5=(e,o,t)=>{let i=e.slice(0,o),a=i.split(/\s+/),s=i.endsWith(" "),l=a.length-2-1-(s?0:1),c=a.slice(l<=0?0:l).join(" ")+(s?" ":""),m=20;c=c.length>m?c.slice(-m):c;let p=e.slice(o+t.length),d=p.split(/\s+/),u=!p.startsWith(" "),b=u?6:5,g=(u?"":" ")+d.slice(0,b).join(" ");return{indexInSearchQuery:c.length,previewText:c+t+g,moreBefore:l>0,moreAfter:d.length>b}},Gz=(e,o)=>{let t=e.split(`
|
|
16
|
-
`),n=[],r=0;for(let i=0;i<
|
|
17
|
-
`)},
|
|
18
|
-
`),i=[],a=0,s=0;for(let p of r){let d=a,u=d+p.length-1;i.push({line:p,startIndex:d,endIndex:u,lineNumber:s}),a=u+1,s++}let l=
|
|
1
|
+
import{$ as tg,A as Qu,B as L6,C as Mx,D as Px,E as ld,F as dl,G as cd,H as dd,I as ml,J as Ax,K as Lx,L as _x,M as ca,N as da,O as Dx,P as _6,Q as hi,R as ma,S as pl,U as Rx,W as Nx,X as Bx,Y as md,Z as Fx,_ as eg,a as Ix,aa as pd,b as gi,ba as zx,c as ln,ca as og,d as Cx,da as fi,e as ze,ea as Ox,f as kx,fa as ng,g as se,ga as Hx,h as ia,ha as ul,i as cn,ia as Gx,j as al,ja as ud,k as sl,ka as rg,l as aa,la as Ux,m as ll,ma as Wx,n as sa,na as Yx,o as Sx,oa as gl,p as qu,q as dn,r as hr,s as fr,t as oo,u as Un,v as la,w as ad,x as Ju,y as cl,z as sd}from"./chunk-LUZI7MFZ.js";import{a as I}from"./chunk-SG4RCQVC.js";import{M as ju}from"./chunk-MSBJ7C4T.js";import{c as Tx}from"./chunk-3PELD44J.js";import{b as wx,c as vx,d as S}from"./chunk-SRAX5OIU.js";import ej,{useEffect as tj}from"react";import{DEFAULT_UI_OPTIONS as y6,isShallowEqual as oj}from"@orangecatai/common";import E4 from"clsx";import _K from"lodash.throttle";import On,{useContext as mi}from"react";import{flushSync as co}from"react-dom";import DK from"roughjs/bin/rough";import{nanoid as d1}from"nanoid";import{clamp as y4,pointFrom as ce,pointDistance as ri,vector as w4,pointRotateRads as m1,vectorFromPoint as p1,vectorSubtract as v4,vectorDot as T4,vectorNormalize as I4}from"@orangecatai/math";import{COLOR_PALETTE as RK,CODES as C4,shouldResizeFromCenter as k4,shouldMaintainAspectRatio as Gc,shouldRotateWithDiscreteAngle as S4,isArrowKey as Mu,KEYS as J,APP_NAME as NK,CURSOR_TYPE as et,DEFAULT_MAX_IMAGE_WIDTH_OR_HEIGHT as BK,DEFAULT_VERTICAL_ALIGN as M4,DRAGGING_THRESHOLD as P4,ELEMENT_SHIFT_TRANSLATE_AMOUNT as FK,ELEMENT_TRANSLATE_AMOUNT as A4,EVENT as ue,FRAME_STYLE as Ho,IMAGE_MIME_TYPES as zK,IMAGE_RENDER_TIMEOUT as OK,LINE_CONFIRM_THRESHOLD as u1,MAX_ALLOWED_FILE_BYTES as L4,MIME_TYPES as Rn,MQ_RIGHT_SIDEBAR_MIN_WIDTH as HK,POINTER_BUTTON as ii,ROUNDNESS as Pu,SCROLL_TIMEOUT as GK,TAP_TWICE_TIMEOUT as UK,TEXT_TO_CENTER_SNAP_THRESHOLD as WK,THEME as Au,TOUCH_CTX_MENU_TIMEOUT as YK,VERTICAL_ALIGN as VK,YOUTUBE_STATES as Lu,ZOOM_STEP as KK,POINTER_EVENTS as js,TOOL_TYPE as Nn,supportsResizeObserver as XK,DEFAULT_COLLISION_THRESHOLD as _4,DEFAULT_TEXT_ALIGN as $K,ARROW_TYPE as ai,DEFAULT_REDUCED_GLOBAL_ALPHA as ZK,isLocalLink as jK,normalizeLink as g1,toValidURL as qK,getGridPoint as Yt,getLineHeight as D4,debounce as R4,distance as qs,getFontString as h1,getNearestScrollableContainer as JK,isInputLike as N4,isToolIcon as QK,isWritableElement as Uc,sceneCoordsToViewportCoords as _u,tupleToCoors as f1,viewportCoordsToSceneCoords as je,wrapEvent as eX,updateObject as b1,updateActiveTool as Bn,isTransparent as tX,easeToValuesRAF as oX,muteFSAbortError as nX,isTestEnv as yM,isDevEnv as wM,easeOut as rX,updateStable as Wc,addEventListener as lt,normalizeEOL as iX,getDateTime as B4,isShallowEqual as F4,arrayToMap as Du,applyDarkModeFilter as aX,randomInteger as sX,CLASSES as x1,Emitter as ea,MINIMUM_ARROW_SIZE as lX,DOUBLE_TAP_POSITION_THRESHOLD as cX,BIND_MODE_TIMEOUT as dX,invariant as Fn,getFeatureFlag as cr,createUserAgentDescriptor as vM,getFormFactor as mX,deriveStylesPanelMode as Hu,isIOS as pX,isBrave as uX,isSafari as gX,loadDesktopUIModePreference as hX,setDesktopUIMode as fX,isSelectionLikeTool as Ru,oneOf as z4}from"@orangecatai/common";import{getObservedAppState as bX,getCommonBounds as Js,getElementAbsoluteCoords as Nu,bindOrUnbindBindingElements as O4,fixBindingsAfterDeletion as xX,getHoveredElementForBinding as rn,isBindingEnabled as Yc,shouldEnableBindingForPointerEvent as EX,updateBoundElements as Bu,LinearElementEditor as ke,newElementWith as si,newFrameElement as H4,newFreeDrawElement as yX,newEmbeddableElement as G4,newMagicFrameElement as U4,newIframeElement as wX,newArrowElement as vX,newElement as TX,newImageElement as E1,newLinearElement as IX,newTextElement as W4,refreshTextDimensions as CX,deepCopyElement as Y4,duplicateElements as y1,hasBoundTextElement as V4,isArrowElement as Qs,isBindingElement as zn,isBindingElementType as kX,isBoundToContainer as w1,isFrameLikeElement as Vt,isImageElement as li,isEmbeddableElement as dr,isInitializedImageElement as Vc,isLinearElement as eo,isLinearElementType as SX,isUsingAdaptiveRadius as MX,isIframeElement as el,isIframeLikeElement as v1,isMagicFrameElement as T1,isTextBindableContainer as K4,isElbowArrow as mo,isFlowchartNodeElement as PX,isBindableElement as I1,isTextElement as an,getNormalizedDimensions as AX,isElementCompletelyInViewport as C1,isElementInViewport as X4,isInvisiblySmallElement as $4,getCornerRadius as LX,isPathALoop as Z4,createSrcDoc as j4,embeddableURLValidator as k1,maybeParseEmbedSrc as _X,getEmbedLink as Fu,getInitializedImageElements as DX,normalizeSVG as q4,updateImageCache as RX,getBoundTextElement as S1,getContainerCenter as M1,getContainerElement as J4,isValidTextContainer as NX,redrawTextBoundingBox as BX,hasBoundingBox as FX,getFrameChildren as P1,isCursorInFrame as Q4,addElementsToFrame as A1,replaceAllElementsInFrame as zX,removeElementsFromFrame as OX,getElementsInResizingFrame as L1,getElementsInNewFrame as HX,getContainingFrame as _1,elementOverlapsWithFrame as GX,updateFrameMembershipOfSelectedElements as eM,isElementInFrame as tM,getFrameLikeTitle as UX,getElementsOverlappingFrame as WX,filterElementsEligibleAsFrameChildren as YX,hitElementBoundText as VX,hitElementBoundingBoxOnly as KX,hitElementItself as Kc,getVisibleSceneBounds as XX,FlowChartCreator as $X,FlowChartNavigator as ZX,getLinkDirectionFromKey as oM,cropElement as jX,wrapText as qX,isElementLink as D1,parseElementLinkFromURL as JX,isMeasureTextSupported as QX,normalizeText as e$,measureText as nM,getLineHeightInPx as t$,getApproxMinLineWidth as o$,getApproxMinLineHeight as n$,getMinTextElementWidth as r$,ShapeCache as Xc,getRenderOpacity as i$,editGroupForSelectedElement as a$,getElementsInGroup as ta,getSelectedGroupIdForElement as s$,getSelectedGroupIds as l$,isElementInGroup as rM,isSelectedViaGroup as c$,selectGroupsForSelectedElements as Go,syncInvalidIndices as TM,syncMovedIndices as iM,excludeElementsInFramesFromSelection as d$,getSelectionStateForElements as m$,makeNextSelectedElementIds as Be,getResizeOffsetXY as p$,getResizeArrowDirection as u$,transformElements as g$,getCursorForResizingElement as aM,getElementWithTransformHandleType as sM,getTransformHandleTypeFromCoords as lM,dragNewElement as cM,dragSelectedElements as h$,getDragOffsetXY as f$,isNonDeletedElement as dM,Scene as mM,Store as b$,CaptureUpdateAction as to,hitElementBoundingBox as x$,isLineElement as R1,isSimpleArrow as N1,StoreDelta as pM,positionElementsOnGrid as uM,calculateFixedPointForNonElbowArrowBinding as gM,bindOrUnbindBindingElement as E$,mutateElement as zu,getElementBounds as hM,doBoundsIntersect as y$,isPointInElement as w$,maxBindingDistance_simple as B1,convertToExcalidrawElements as fM,getSnapOutlineMidPoint as F1,handleFocusPointDrag as v$,handleFocusPointHover as T$,handleFocusPointPointerDown as I$,handleFocusPointPointerUp as C$,maybeHandleArrowPointlikeDrag as Ou,getUncroppedWidthAndHeight as k$}from"@orangecatai/element";import{KEYS as Ag,MOBILE_ACTION_BUTTON_BG as V6,updateActiveTool as K6}from"@orangecatai/common";import{getNonDeletedElements as Lg}from"@orangecatai/element";import{fixBindingsAfterDeletion as X6}from"@orangecatai/element";import{LinearElementEditor as Wy}from"@orangecatai/element";import{newElementWith as Dd}from"@orangecatai/element";import{getContainerElement as Yy}from"@orangecatai/element";import{isBoundToContainer as Ld,isElbowArrow as $6,isFrameLikeElement as Z6}from"@orangecatai/element";import{getFrameChildren as j6}from"@orangecatai/element";import{getElementsInGroup as _g,selectGroupsForSelectedElements as q6}from"@orangecatai/element";import{CaptureUpdateAction as _d}from"@orangecatai/element";import{isDevEnv as B6}from"@orangecatai/common";import{atom as Ie,createStore as D6}from"jotai";import{createIsolation as R6}from"jotai-scope";var Vx=R6();var{useAtom:ne,useSetAtom:mn,useAtomValue:pa,useStore:lj}=Vx,Kx=Vx.Provider,pt=D6();var N6=wx({"./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 F6=85,pn={code:"en",label:"English"},ga=[pn,...[{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=>Tx[e.code]>=F6).sort((e,t)=>e.label>t.label?1:-1)],hd="__test__";B6()&&ga.unshift({code:hd,label:"test language"},{code:`${hd}.rtl`,label:"\u202Atest language (rtl)\u202C",rtl:!0});var ua=pn,gd={},fd=async e=>{if(ua=e,document.documentElement.dir=ua.rtl?"rtl":"ltr",document.documentElement.lang=ua.code,e.code.startsWith(hd))gd={};else try{gd=await N6(`./locales/${ua.code}.json`)}catch(t){console.error(`Failed to load language ${e.code}:`,t.message),gd=ju}pt.set($x,e.code)},Wn=()=>ua,Xx=(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},h=(e,t,o)=>{if(ua.code.startsWith(hd))return`\u202A[[${t?`${e}(${JSON.stringify(t).slice(1,-1)})`:e}]]\u202C`;let n=e.split("."),r=Xx(gd,n)||Xx(ju,n)||o;if(r===void 0){let i=`Can't find translation for ${e}`;if(I.PROD)return console.warn(i),"";throw new Error(i)}if(t)for(let i in t)r=r.replace(`{{${i}}}`,String(t[i]));return r},$x=Ie(pn.code),Oe=()=>{let e=pa($x);return{t:h,langCode:e}};import z6 from"clsx";import Ct from"react";import{THEME as O6}from"@orangecatai/common";import{Fragment as He,jsx as f,jsxs as B}from"react/jsx-runtime";var Yo=e=>"var(--icon-fill-color)",Zx=e=>e===O6.LIGHT?"#fff":"#1e1e1e",L=(e,t=512)=>{let{width:o=512,height:n=o,mirror:r,style:i,...a}=typeof t=="number"?{width:t}:t;return f("svg",{"aria-hidden":"true",focusable:"false",role:"img",viewBox:`0 0 ${o} ${n}`,className:z6({"rtl-mirror":r}),style:i,...a,children:typeof e=="string"?f("path",{fill:"currentColor",d:e}):e})},G={width:24,height:24,fill:"none",strokeWidth:2,stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round"},ge={width:20,height:20,fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round"},Tj=L(B("g",{strokeWidth:"1.5",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("rect",{x:3,y:8,width:18,height:4,rx:1}),f("line",{x1:12,y1:8,x2:12,y2:21}),f("path",{d:"M19 12v7a2 2 0 0 1 -2 2h-10a2 2 0 0 1 -2 -2v-7"}),f("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"})]}),G),bd=L(B("g",{strokeWidth:"1.25",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M3 19a9 9 0 0 1 9 0a9 9 0 0 1 9 0"}),f("path",{d:"M3 6a9 9 0 0 1 9 0a9 9 0 0 1 9 0"}),f("line",{x1:"3",y1:"6",x2:"3",y2:"19"}),f("line",{x1:"12",y1:"6",x2:"12",y2:"19"}),f("line",{x1:"21",y1:"6",x2:"21",y2:"19"})]}),G),jx=L(B("svg",{strokeWidth:"1.5",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),f("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]}),G),qx=L(B("g",{strokeWidth:"1.5",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("circle",{cx:"12",cy:"12",r:"1"}),f("circle",{cx:"12",cy:"19",r:"1"}),f("circle",{cx:"12",cy:"5",r:"1"})]}),G),Jx=L(B("g",{strokeWidth:"1.5",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M5 12m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0"}),f("path",{d:"M12 12m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0"}),f("path",{d:"M19 12m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0"})]}),G),Qx=L(B("svg",{strokeWidth:"1.5",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M9 4v6l-2 4v2h10v-2l-2 -4v-6"}),f("line",{x1:"12",y1:"16",x2:"12",y2:"21"}),f("line",{x1:"8",y1:"4",x2:"16",y2:"4"})]}),G),ig=L(B("g",{strokeWidth:1.25,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M12 5m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"}),f("path",{d:"M19 8m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"}),f("path",{d:"M5 11m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"}),f("path",{d:"M15 19m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"}),f("path",{d:"M6.5 9.5l3.5 -3"}),f("path",{d:"M14 5.5l3 1.5"}),f("path",{d:"M18.5 10l-2.5 7"}),f("path",{d:"M13.5 17.5l-7 -5"})]}),G),bi=L(B("g",{children:[f("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"}),f("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"}),f("mask",{id:"UnlockedIcon",style:{maskType:"alpha"},maskUnits:"userSpaceOnUse",x:6,y:1,width:9,height:9,children:f("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"})}),f("g",{mask:"url(#UnlockedIcon)",children:f("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"})})]}),ge),ha=L(B("g",{strokeWidth:"1.25",children:[f("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"}),f("path",{d:"M10 13.958a1.042 1.042 0 1 0 0-2.083 1.042 1.042 0 0 0 0 2.083Z"}),f("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"})]}),ge),eE=L(f("g",{fill:"currentColor",children:f("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}),tE=L(B(He,{children:[f("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"}),f("path",{fillRule:"evenodd",clipRule:"evenodd",d:"m12.005 10.478 7.905 14.423L6 25.75l6.005-15.273Z",fill:"currentColor"}),f("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"}),oE=L(B(He,{children:[f("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"}),f("path",{fillRule:"evenodd",clipRule:"evenodd",d:"m72.181 59.247-13.058-10-2.948 13.62 16.006-3.62Z",fill:"currentColor"}),f("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=L(B(He,{children:[f("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"}),f("path",{fillRule:"evenodd",clipRule:"evenodd",d:"m24.165 1.093-2.132 16.309 13.27-4.258-11.138-12.05Z",fill:"currentColor"}),f("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"}),Ij=L(f("g",{fill:"currentColor",children:f("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"}),xi=L(B("g",{stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("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"}),f("path",{d:"M13.5 13.5l4.5 4.5"})]}),{fill:"none",width:22,height:22,strokeWidth:1.25}),br=L(B("g",{stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,children:[f("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"}),f("path",{d:"M5 15m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"}),f("path",{d:"M5 17c0 1.42 .316 2.805 1 4"})]}),{fill:"none",width:22,height:22,strokeWidth:1.25}),fa=L(B("g",{strokeWidth:"1.5",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"})]}),G),ba=L(B("g",{strokeWidth:"1.5",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("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"})]}),G),xa=L(B("g",{strokeWidth:"1.5",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("circle",{cx:"12",cy:"12",r:"9"})]}),G),xd=L(B("g",{strokeWidth:"1.5",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("line",{x1:"5",y1:"12",x2:"19",y2:"12"}),f("line",{x1:"15",y1:"16",x2:"19",y2:"12"}),f("line",{x1:"15",y1:"8",x2:"19",y2:"12"})]}),G),Ea=L(f("path",{d:"M4.167 10h11.666",strokeWidth:"1.5"}),ge),rE=L(B("g",{strokeWidth:"1.25",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M20 17v-12c0 -1.121 -.879 -2 -2 -2s-2 .879 -2 2v12l2 2l2 -2z"}),f("path",{d:"M16 7h4"}),f("path",{d:"M18 19h-13a2 2 0 1 1 0 -4h4a2 2 0 1 0 0 -4h-3"})]}),G),un=L(B("g",{strokeWidth:"1.25",children:[f("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"}),f("path",{d:"m11.25 5.417 3.333 3.333"})]}),ge),gn=L(B("g",{strokeWidth:"1.5",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("line",{x1:"4",y1:"20",x2:"7",y2:"20"}),f("line",{x1:"14",y1:"20",x2:"21",y2:"20"}),f("line",{x1:"6.9",y1:"15",x2:"13.8",y2:"15"}),f("line",{x1:"10.2",y1:"6.3",x2:"16",y2:"20"}),f("polyline",{points:"5 20 11 4 13 4 20 20"})]}),G),iE=L(B("g",{stroke:"currentColor",strokeWidth:"1.5",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M3 7v-2h13v2"}),f("path",{d:"M10 5v14"}),f("path",{d:"M12 19h-4"}),f("path",{d:"M15 13v-1h6v1"}),f("path",{d:"M18 12v7"}),f("path",{d:"M17 19h2"})]}),G),xr=L(B("g",{strokeWidth:"1.25",children:[f("path",{d:"M12.5 6.667h.01"}),f("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"}),f("path",{d:"m3.333 12.5 3.334-3.333c.773-.745 1.726-.745 2.5 0l4.166 4.166"}),f("path",{d:"m11.667 11.667.833-.834c.774-.744 1.726-.744 2.5 0l1.667 1.667"})]}),ge),Ed=L(B("g",{strokeWidth:"1.5",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("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"}),f("path",{d:"M18 13.3l-6.3 -6.3"})]}),G),ag=L(f("path",{strokeWidth:"1.25",d:"M10 4.167v11.666M4.167 10h11.666"}),ge),sg=L(f("path",{d:"M5 10h10",strokeWidth:"1.25"}),ge),aE=L(B("g",{strokeWidth:1.25,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M21 21l-6 -6"}),f("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"}),f("path",{d:"M3 4v4h4"})]}),G),Nt=L(f("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"}),ge),ya=L(B("g",{strokeWidth:"1.5",children:[f("polyline",{points:"12 16 18 10 12 4"}),f("polyline",{points:"8 4 2 10 8 16"})]}),ge),hl=L(B("g",{strokeWidth:"1.25",children:[f("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"}),f("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"})]}),ge),fl=L(f("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"}),ge),bl=L(f("g",{stroke:"currentColor",strokeLinejoin:"round",children:f("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"})}),{...ge,strokeWidth:1.5}),sE=L(B("g",{strokeWidth:"1.5",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("line",{x1:"4",y1:"6",x2:"20",y2:"6"}),f("line",{x1:"4",y1:"12",x2:"20",y2:"12"}),f("line",{x1:"4",y1:"18",x2:"20",y2:"18"})]}),G),Ei=L(f("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"}),ge),wa=L(B("g",{strokeWidth:"1.5",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("circle",{cx:"12",cy:"12",r:"9"}),f("line",{x1:"12",y1:"17",x2:"12",y2:"17.01"}),f("path",{d:"M12 13.5a1.5 1.5 0 0 1 1 -1.5a2.6 2.6 0 1 0 -3 -4"})]}),G),lE=L(B("g",{strokeWidth:"1.25",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("circle",{cx:"12",cy:"12",r:"9"}),f("line",{x1:"12",y1:"17",x2:"12",y2:"17.01"}),f("path",{d:"M12 13.5a1.5 1.5 0 0 1 1 -1.5a2.6 2.6 0 1 0 -3 -4"})]}),G),lg=L(f("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"}),ge),yd=L(f("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"}),ge),cE=L(B("g",{strokeWidth:"1.25",children:[f("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"}),f("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"})]}),ge),dE=L(B("g",{strokeWidth:"1.25",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M4 4l11.733 16h4.267l-11.733 -16z"}),f("path",{d:"M4 20l6.768 -6.768m2.46 -2.46l6.772 -6.772"})]}),G),wd=L(f("polyline",{fill:"none",stroke:"currentColor",points:"20 6 9 17 4 12"}),{width:24,height:24}),xl=L(B("g",{strokeWidth:"1.25",children:[f("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"}),f("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"})]}),ge),mE=L("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}),pE=L("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}),va=L(f("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"}),ge),Cj=L("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}),kj=L("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"),vd=L(B("g",{strokeWidth:1.25,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M5 16l1.465 1.638a2 2 0 1 1 -3.015 .099l1.55 -1.737z"}),f("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"}),f("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"})]}),G),uE=L(f("g",{strokeWidth:1.5,children:f("path",{d:"M6 18l12 -12"})}),G),Td=L(B("g",{strokeWidth:"1.25",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M15 8h.01"}),f("path",{d:"M12 20h-5a3 3 0 0 1 -3 -3v-10a3 3 0 0 1 3 -3h10a3 3 0 0 1 3 3v5"}),f("path",{d:"M4 15l4 -4c.928 -.893 2.072 -.893 3 0l4 4"}),f("path",{d:"M14 14l1 -1c.617 -.593 1.328 -.793 2.009 -.598"}),f("path",{d:"M19 16v6"}),f("path",{d:"M22 19l-3 3l-3 -3"})]}),G),gE=L("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}),Sj=L("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}),Mj=L("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}),hE=L("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"),Pj=L("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"),cg=L(f("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"}),ge),dg=L(f("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"}),ge),fE=L("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}),bE=L(f("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"}),ge),Aj=L("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"),Lj=L("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}),_j=L(B("g",{strokeWidth:1.25,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("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"}),f("path",{d:"M12 14v-11"}),f("path",{d:"M9 6l3 -3l3 3"})]}),G),Dj=L(B(He,{children:[f("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"}),f("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}),Rj=L(f("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}),xE=B("g",{strokeWidth:1.5,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M12 10l0 10"}),f("path",{d:"M12 10l4 4"}),f("path",{d:"M12 10l-4 4"}),f("path",{d:"M4 4l16 0"})]}),EE=B("g",{strokeWidth:1.5,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M12 5l0 14"}),f("path",{d:"M16 9l-4 -4"}),f("path",{d:"M8 9l4 -4"})]}),mg=L(EE,G),pg=L(EE,{...G,style:{transform:"rotate(180deg)"}}),ug=L(xE,G),gg=L(xE,{...G,style:{transform:"rotate(180deg)"}}),hg=L(B(He,{children:[B("g",{clipPath:"url(#a)",stroke:"currentColor",strokeWidth:"1.25",children:[f("path",{d:"M3.333 3.333h13.334",strokeLinecap:"round",strokeLinejoin:"round"}),f("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"})]}),f("defs",{children:f("clipPath",{id:"a",children:f("path",{fill:"#fff",d:"M0 0h20v20H0z"})})})]}),ge),fg=L(B(He,{children:[B("g",{clipPath:"url(#a)",stroke:"currentColor",strokeWidth:"1.25",children:[f("path",{d:"M3.333 16.667h13.334",strokeLinecap:"round",strokeLinejoin:"round"}),f("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"})]}),f("defs",{children:f("clipPath",{id:"a",children:f("path",{fill:"#fff",d:"M0 0h20v20H0z"})})})]}),ge),bg=L(B(He,{children:[B("g",{clipPath:"url(#a)",stroke:"currentColor",strokeWidth:"1.25",children:[f("path",{d:"M3.333 3.333v13.334",strokeLinecap:"round",strokeLinejoin:"round"}),f("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"})]}),f("defs",{children:f("clipPath",{id:"a",children:f("path",{fill:"#fff",d:"M0 0h20v20H0z"})})})]}),ge),xg=L(B(He,{children:[B("g",{clipPath:"url(#a)",stroke:"currentColor",strokeWidth:"1.25",children:[f("path",{d:"M16.667 3.333v13.334",strokeLinecap:"round",strokeLinejoin:"round"}),f("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"})]}),f("defs",{children:f("clipPath",{id:"a",children:f("path",{fill:"#fff",d:"M0 0h20v20H0z"})})})]}),ge),yE=L(B(He,{children:[B("g",{clipPath:"url(#a)",stroke:"currentColor",strokeWidth:"1.25",children:[f("path",{d:"M16.667 3.333v13.334M3.333 3.333v13.334",strokeLinecap:"round",strokeLinejoin:"round"}),f("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"})]}),f("defs",{children:f("clipPath",{id:"a",children:f("path",{fill:"#fff",d:"M0 0h20v20H0z"})})})]}),ge),wE=L(B(He,{children:[B("g",{clipPath:"url(#a)",stroke:"currentColor",strokeWidth:"1.25",children:[f("path",{d:"M3.333 3.333h13.334M3.333 16.667h13.334",strokeLinecap:"round",strokeLinejoin:"round"}),f("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"})]}),f("defs",{children:f("clipPath",{id:"a",children:f("path",{fill:"#fff",d:"M0 0h20v20H0z"})})})]}),ge),Eg=L(B("g",{stroke:"currentColor",strokeWidth:"1.25",children:[f("path",{d:"M1.667 10h2.916",strokeLinecap:"round",strokeLinejoin:"round"}),f("path",{d:"M8.333 10h3.334",strokeLinejoin:"round"}),f("path",{d:"M15.417 10h2.916",strokeLinecap:"round",strokeLinejoin:"round"}),f("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"})]}),ge),yg=L(B("g",{stroke:"currentColor",strokeWidth:"1.25",children:[f("path",{d:"M10 18.333v-2.916",strokeLinecap:"round",strokeLinejoin:"round"}),f("path",{d:"M10 11.667V8.333",strokeLinejoin:"round"}),f("path",{d:"M10 4.583V1.667",strokeLinecap:"round",strokeLinejoin:"round"}),f("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"})]}),ge),Id=L(B("g",{strokeWidth:"1.5",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("circle",{cx:"9",cy:"7",r:"4"}),f("path",{d:"M3 21v-2a4 4 0 0 1 4 -4h4a4 4 0 0 1 4 4v2"}),f("path",{d:"M16 3.13a4 4 0 0 1 0 7.75"}),f("path",{d:"M21 21v-2a4 4 0 0 0 -3 -3.85"})]}),G),Nj=L("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"),vE=L("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"),To=L(B(He,{children:[f("g",{clipPath:"url(#a)",stroke:"currentColor",strokeWidth:"1.25",strokeLinecap:"round",strokeLinejoin:"round",children:f("path",{d:"M15 5 5 15M5 5l10 10"})}),f("defs",{children:f("clipPath",{id:"a",children:f("path",{fill:"#fff",d:"M0 0h20v20H0z"})})})]}),ge),Bj=L("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}),Fj=L("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}),zj=L("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}),wg=Ct.memo(({theme:e})=>L(B(He,{children:[f("path",{d:"M25 26H111V111H25",fill:Yo(e)}),f("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:Yo(e),strokeWidth:"2"}),f("path",{d:"M100 100H160V160H100",fill:Yo(e)}),f("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:Yo(e),strokeWidth:"2"}),B("g",{fill:Zx(e),stroke:Yo(e),strokeWidth:"6",children:[f("rect",{x:"2.5",y:"2.5",width:"30",height:"30"}),f("rect",{x:"2.5",y:"149.5",width:"30",height:"30"}),f("rect",{x:"147.5",y:"149.5",width:"30",height:"30"}),f("rect",{x:"147.5",y:"2.5",width:"30",height:"30"})]})]}),{width:182,height:182,mirror:!0})),vg=Ct.memo(({theme:e})=>L(B(He,{children:[f("path",{d:"M25 26H111V111H25",fill:Yo(e)}),f("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:Yo(e),strokeWidth:"2"}),f("path",{d:"M100 100H160V160H100",fill:Yo(e)}),f("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:Yo(e),strokeWidth:"2"}),B("g",{fill:Zx(e),stroke:Yo(e),strokeWidth:"6",children:[f("rect",{x:"2.5",y:"2.5",width:"30",height:"30"}),f("rect",{x:"78.5",y:"149.5",width:"30",height:"30"}),f("rect",{x:"147.5",y:"149.5",width:"30",height:"30"}),f("rect",{x:"147.5",y:"78.5",width:"30",height:"30"}),f("rect",{x:"105.5",y:"2.5",width:"30",height:"30"}),f("rect",{x:"2.5",y:"102.5",width:"30",height:"30"})]})]}),{width:182,height:182,mirror:!0})),TE=L(f("g",{strokeWidth:1.25,children:f("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"})}),ge),IE=L(B(He,{children:[f("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"}),f("mask",{id:"FillHachureIcon",style:{maskType:"alpha"},maskUnits:"userSpaceOnUse",x:2,y:2,width:16,height:16,children:f("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"})}),f("g",{mask:"url(#FillHachureIcon)",children:f("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"})})]}),ge),CE=L(B(He,{children:[B("g",{clipPath:"url(#a)",children:[f("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"}),f("mask",{id:"FillCrossHatchIcon",style:{maskType:"alpha"},maskUnits:"userSpaceOnUse",x:-1,y:-1,width:22,height:22,children:f("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"})}),f("g",{mask:"url(#FillCrossHatchIcon)",children:f("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"})})]}),f("defs",{children:f("clipPath",{id:"a",children:f("path",{fill:"#fff",d:"M0 0h20v20H0z"})})})]}),ge),kE=L(B(He,{children:[f("g",{clipPath:"url(#a)",children:f("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"})}),f("defs",{children:f("clipPath",{id:"a",children:f("path",{fill:"#fff",d:"M0 0h20v20H0z"})})})]}),{...ge,fill:"currentColor"}),Tg=L(f(He,{children:f("path",{d:"M4.167 10h11.666",stroke:"currentColor",strokeWidth:"1.25",strokeLinecap:"round",strokeLinejoin:"round"})}),ge),SE=L(f("path",{d:"M5 10h10",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round"}),ge),ME=L(f("path",{d:"M5 10h10",stroke:"currentColor",strokeWidth:"3.75",strokeLinecap:"round",strokeLinejoin:"round"}),ge),Oj=Ct.memo(({theme:e})=>L(f("path",{d:"M6 10H34",stroke:Yo(e),strokeWidth:2,fill:"none",strokeLinecap:"round"}),{width:40,height:20})),PE=L(B("g",{strokeWidth:"2",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M5 12h2"}),f("path",{d:"M17 12h2"}),f("path",{d:"M11 12h2"})]}),G),AE=L(B("g",{strokeWidth:"2",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M4 12v.01"}),f("path",{d:"M8 12v.01"}),f("path",{d:"M12 12v.01"}),f("path",{d:"M16 12v.01"}),f("path",{d:"M20 12v.01"})]}),G),LE=L(f("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"}),ge),_E=L(f("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"}),ge),DE=L(f("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"}),ge),RE=L(B("svg",{strokeWidth:"1.5",children:[f("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"}),f("path",{d:"M13.3333 3.33331V3.34331"}),f("path",{d:"M16.6667 3.33331V3.34331"}),f("path",{d:"M16.6667 6.66669V6.67669"}),f("path",{d:"M16.6667 10V10.01"}),f("path",{d:"M3.33334 13.3333V13.3433"}),f("path",{d:"M16.6667 13.3333V13.3433"}),f("path",{d:"M3.33334 16.6667V16.6767"}),f("path",{d:"M6.66666 16.6667V16.6767"}),f("path",{d:"M10 16.6667V16.6767"}),f("path",{d:"M13.3333 16.6667V16.6767"}),f("path",{d:"M16.6667 16.6667V16.6767"})]}),ge),NE=L(B("g",{strokeWidth:"1.5",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M4 12v-4a4 4 0 0 1 4 -4h4"}),f("line",{x1:"16",y1:"4",x2:"16",y2:"4.01"}),f("line",{x1:"20",y1:"4",x2:"20",y2:"4.01"}),f("line",{x1:"20",y1:"8",x2:"20",y2:"8.01"}),f("line",{x1:"20",y1:"12",x2:"20",y2:"12.01"}),f("line",{x1:"4",y1:"16",x2:"4",y2:"16.01"}),f("line",{x1:"20",y1:"16",x2:"20",y2:"16.01"}),f("line",{x1:"4",y1:"20",x2:"4",y2:"20.01"}),f("line",{x1:"8",y1:"20",x2:"8",y2:"20.01"}),f("line",{x1:"12",y1:"20",x2:"12",y2:"20.01"}),f("line",{x1:"16",y1:"20",x2:"16",y2:"20.01"}),f("line",{x1:"20",y1:"20",x2:"20",y2:"20.01"})]}),G),BE=Ct.memo(({flip:e=!1})=>L(B("g",{transform:e?"translate(24, 0) scale(-1, 1)":"",stroke:"currentColor",opacity:.3,strokeWidth:2,children:[f("path",{d:"M12 12l-9 0"}),f("path",{d:"M21 9l-6 6"}),f("path",{d:"M21 15l-6 -6"})]}),G)),FE=Ct.memo(({flip:e=!1})=>L(B("g",{transform:e?"translate(40, 0) scale(-1, 1)":"",stroke:"currentColor",strokeWidth:2,fill:"none",children:[f("path",{d:"M34 10H6M34 10L27 5M34 10L27 15"}),f("path",{d:"M27.5 5L34.5 10L27.5 15"})]}),{width:40,height:20})),zE=Ct.memo(({flip:e=!1})=>L(B("g",{stroke:"currentColor",fill:"currentColor",transform:e?"translate(40, 0) scale(-1, 1)":"",children:[f("path",{d:"M32 10L6 10",strokeWidth:2}),f("circle",{r:"4",transform:"matrix(-1 0 0 1 30 10)"})]}),{width:40,height:20})),OE=Ct.memo(({flip:e=!1})=>L(B("g",{stroke:"currentColor",fill:"none",transform:e?"translate(40, 0) scale(-1, 1)":"",strokeWidth:2,children:[f("path",{d:"M26 10L6 10"}),f("circle",{r:"4",transform:"matrix(-1 0 0 1 30 10)"})]}),{width:40,height:20})),HE=Ct.memo(({flip:e=!1})=>L(f("g",{transform:e?"translate(40, 0) scale(-1, 1)":"",children:f("path",{d:"M34 10H5.99996M34 10L34 5M34 10L34 15",stroke:"currentColor",strokeWidth:2,fill:"none"})}),{width:40,height:20})),GE=Ct.memo(({flip:e=!1})=>L(B("g",{stroke:"currentColor",fill:"currentColor",transform:e?"translate(40, 0) scale(-1, 1)":"",children:[f("path",{d:"M32 10L6 10",strokeWidth:2}),f("path",{d:"M27.5 5.5L34.5 10L27.5 14.5L27.5 5.5"})]}),{width:40,height:20})),UE=Ct.memo(({flip:e=!1})=>L(B("g",{stroke:"currentColor",fill:"none",transform:e?"translate(40, 0) scale(-1, 1)":"",strokeWidth:2,strokeLinejoin:"round",children:[f("path",{d:"M6,9.5H27"}),f("path",{d:"M27,5L34,10L27,14Z",fill:"none"})]}),{width:40,height:20})),WE=Ct.memo(({flip:e=!1})=>L(B("g",{stroke:"currentColor",fill:"currentColor",transform:e?"translate(40, 0) scale(-1, 1)":"",strokeLinejoin:"round",strokeWidth:2,children:[f("path",{d:"M6,9.5H20"}),f("path",{d:"M27,5L34,10L27,14L20,9.5Z"})]}),{width:40,height:20})),YE=Ct.memo(({flip:e=!1})=>L(B("g",{stroke:"currentColor",fill:"none",transform:e?"translate(40, 0) scale(-1, 1)":"",strokeLinejoin:"round",strokeWidth:2,children:[f("path",{d:"M6,9.5H20"}),f("path",{d:"M27,5L34,10L27,14L20,9.5Z"})]}),{width:40,height:20})),VE=Ct.memo(({flip:e=!1})=>L(f("g",{stroke:"currentColor",fill:"none",transform:e?"":"translate(40, 0) scale(-1, 1)",strokeLinejoin:"round",strokeWidth:2,children:f("path",{d:"M34,10 H6 M15,10 L7,5 M15,10 L7,15"})}),{width:40,height:20})),KE=Ct.memo(({flip:e=!1})=>L(f("g",{stroke:"currentColor",fill:"none",transform:e?"":"translate(40, 0) scale(-1, 1)",strokeLinejoin:"round",strokeWidth:2,children:f("path",{d:"M34,10 H6 M15,10 L15,15 L15,5"})}),{width:40,height:20})),XE=Ct.memo(({flip:e=!1})=>L(f("g",{stroke:"currentColor",fill:"none",transform:e?"":"translate(40, 0) scale(-1, 1)",strokeLinejoin:"round",strokeWidth:2,children:f("path",{d:"M34,10 H6 M15,10 L15,16 L15,4 M15,10 L7,5 M15,10 L7,15"})}),{width:40,height:20})),$E=L(B(He,{children:[f("g",{clipPath:"url(#a)",children:f("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"})}),f("defs",{children:f("clipPath",{id:"a",children:f("path",{fill:"#fff",d:"M0 0h20v20H0z"})})})]}),ge),ZE=L(B(He,{children:[f("g",{clipPath:"url(#a)",children:f("path",{d:"M5 16.667V3.333L10 15l5-11.667v13.334",stroke:"currentColor",strokeWidth:"1.25",strokeLinecap:"round",strokeLinejoin:"round"})}),f("defs",{children:f("clipPath",{id:"a",children:f("path",{fill:"#fff",d:"M0 0h20v20H0z"})})})]}),ge),jE=L(B(He,{children:[f("g",{clipPath:"url(#a)",children:f("path",{d:"M5.833 3.333v13.334h8.334",stroke:"currentColor",strokeWidth:"1.25",strokeLinecap:"round",strokeLinejoin:"round"})}),f("defs",{children:f("clipPath",{id:"a",children:f("path",{fill:"#fff",d:"M0 0h20v20H0z"})})})]}),ge),qE=L(f(He,{children:f("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"})}),ge),yi=L(B("g",{strokeWidth:1.25,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M3 7v-2h13v2"}),f("path",{d:"M10 5v14"}),f("path",{d:"M12 19h-4"}),f("path",{d:"M15 13v-1h6v1"}),f("path",{d:"M18 12v7"}),f("path",{d:"M17 19h2"})]}),G),JE=L(f(He,{children:B("g",{stroke:"currentColor",strokeWidth:"1.25",strokeLinecap:"round",strokeLinejoin:"round",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M7 12h10"}),f("path",{d:"M7 5v14"}),f("path",{d:"M17 5v14"}),f("path",{d:"M15 19h4"}),f("path",{d:"M15 5h4"}),f("path",{d:"M5 19h4"}),f("path",{d:"M5 5h4"})]})}),G),El=L(f(He,{children:f("g",{stroke:"currentColor",strokeWidth:"1.25",strokeLinecap:"round",strokeLinejoin:"round",children:f("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"})})}),ge),Ig=L(B("g",{strokeWidth:"1.5",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M7 8l-4 4l4 4"}),f("path",{d:"M17 8l4 4l-4 4"}),f("path",{d:"M14 4l-4 16"})]}),G),Cd=Ig,QE=L(B("g",{stroke:"currentColor",fill:"none",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("line",{x1:"4",y1:"8",x2:"20",y2:"8"}),f("line",{x1:"4",y1:"12",x2:"12",y2:"12"}),f("line",{x1:"4",y1:"16",x2:"16",y2:"16"})]}),G),ey=L(B("g",{stroke:"currentColor",fill:"none",strokeLinecap:"round",strokeLinejoin:"round",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("line",{x1:"4",y1:"8",x2:"20",y2:"8"}),f("line",{x1:"8",y1:"12",x2:"16",y2:"12"}),f("line",{x1:"6",y1:"16",x2:"18",y2:"16"})]}),G),ty=L(B("g",{stroke:"currentColor",fill:"none",strokeLinecap:"round",strokeLinejoin:"round",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("line",{x1:"4",y1:"8",x2:"20",y2:"8"}),f("line",{x1:"10",y1:"12",x2:"20",y2:"12"}),f("line",{x1:"8",y1:"16",x2:"20",y2:"16"})]}),G),oy=Ct.memo(({theme:e})=>L(B("g",{strokeWidth:"1.5",stroke:"currentColor",fill:"none",strokeLinecap:"round",strokeLinejoin:"round",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("line",{x1:"4",y1:"4",x2:"20",y2:"4"}),f("rect",{x:"9",y:"8",width:"6",height:"12",rx:"2"})]}),G)),ny=Ct.memo(({theme:e})=>L(B("g",{strokeWidth:"2",stroke:"currentColor",fill:"none",strokeLinecap:"round",strokeLinejoin:"round",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("line",{x1:"4",y1:"20",x2:"20",y2:"20"}),f("rect",{x:"9",y:"4",width:"6",height:"12",rx:"2"})]}),G)),ry=Ct.memo(({theme:e})=>L(B("g",{strokeWidth:"1.5",stroke:"currentColor",fill:"none",strokeLinecap:"round",strokeLinejoin:"round",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("line",{x1:"4",y1:"12",x2:"9",y2:"12"}),f("line",{x1:"15",y1:"12",x2:"20",y2:"12"}),f("rect",{x:"9",y:"6",width:"6",height:"12",rx:"2"})]}),G)),kd=L(B("g",{children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M21 19h-18l9 -15"}),f("path",{d:"M20.615 15.171h.015"}),f("path",{d:"M19.515 11.771h.015"}),f("path",{d:"M17.715 8.671h.015"}),f("path",{d:"M15.415 5.971h.015"})]}),G),iy=L(f("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}),Hj=L(f("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"})),Ta=L(B("g",{strokeWidth:1.25,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M8 13v-7.5a1.5 1.5 0 0 1 3 0v6.5"}),f("path",{d:"M11 5.5v-2a1.5 1.5 0 1 1 3 0v8.5"}),f("path",{d:"M14 5.5a1.5 1.5 0 0 1 3 0v6.5"}),f("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"})]}),G),Cg=L(B(He,{children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M4 17v2a2 2 0 0 0 2 2h12a2 2 0 0 0 2 -2v-2"}),f("path",{d:"M7 11l5 5l5 -5"}),f("path",{d:"M12 4l0 12"})]}),G),Ia=L(B(He,{children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("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"}),f("path",{d:"M16 8v-2a2 2 0 0 0 -2 -2h-8a2 2 0 0 0 -2 2v8a2 2 0 0 0 2 2h2"})]}),G),ay=L(B("g",{strokeWidth:1.25,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M7 17m-3 0a3 3 0 1 0 6 0a3 3 0 1 0 -6 0"}),f("path",{d:"M17 17m-3 0a3 3 0 1 0 6 0a3 3 0 1 0 -6 0"}),f("path",{d:"M9.15 14.85l8.85 -10.85"}),f("path",{d:"M6 4l8.85 10.85"})]}),G),sy=L(B(He,{children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M12 12m-9 0a9 9 0 1 0 18 0a9 9 0 1 0 -18 0"}),f("path",{d:"M12 17l0 .01"}),f("path",{d:"M12 13.5a1.5 1.5 0 0 1 1 -1.5a2.6 2.6 0 1 0 -3 -4"})]}),G),Gj=L(B(He,{children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M7 4v16l13 -8z"})]}),G),Uj=L(B(He,{children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("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"})]}),G),ly=L(B(He,{children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M5 12l5 5l10 -10"})]}),G),Sd=L(B(He,{children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("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"}),f("path",{d:"M12 9v4"}),f("path",{d:"M12 17h.01"})]}),G),cy=L(B("g",{strokeWidth:1.25,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M11 7l6 6"}),f("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"})]}),G),yl=L(B("g",{strokeWidth:1.5,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M12 3l-4 7h8z"}),f("path",{d:"M17 17m-3 0a3 3 0 1 0 6 0a3 3 0 1 0 -6 0"}),f("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"})]}),G),Vo=L(B("g",{strokeWidth:1.5,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M4 7l16 0"}),f("path",{d:"M4 17l16 0"}),f("path",{d:"M7 4l0 16"}),f("path",{d:"M17 4l0 16"})]}),G),Ca=L(f("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"})),dy=L(B("g",{strokeWidth:"1.5",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M20 11a8.1 8.1 0 0 0 -15.5 -2m-.5 -4v4h4"}),f("path",{d:"M4 13a8.1 8.1 0 0 0 15.5 2m.5 4v-4h-4"})]}),G),my=L(B("g",{children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M6 10l-2 1l8 4l8 -4l-2 -1"}),f("path",{d:"M4 15l8 4l8 -4"}),f("path",{d:"M12 4v7"}),f("path",{d:"M15 8l-3 3l-3 -3"})]}),G),Er=L(B("g",{strokeWidth:"1.25",children:[f("path",{d:"M4.16602 10H15.8327"}),f("path",{d:"M12.5 13.3333L15.8333 10"}),f("path",{d:"M12.5 6.66666L15.8333 9.99999"})]}),ge),hn=L(B("g",{fill:"none",stroke:"currentColor",strokeWidth:"1.25",strokeLinecap:"round",strokeLinejoin:"round",transform:"rotate(90 10 10)",children:[f("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"}),f("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),wi=L(B("g",{stroke:"currentColor",fill:"none",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z"}),f("path",{d:"M6 21l15 -15l-3 -3l-15 15l3 3"}),f("path",{d:"M15 6l3 3"}),f("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"}),f("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"})]}),G),Wj=L(B("g",{strokeWidth:1.25,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z"}),f("path",{d:"M6 21l15 -15l-3 -3l-15 15l3 3"}),f("path",{d:"M15 6l3 3"}),f("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"}),f("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"})]}),G),Yj=L(B("g",{stroke:"currentColor",fill:"none",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M11.217 19.384a3.501 3.501 0 0 0 6.783 -1.217v-5.167l-6 -3.35"}),f("path",{d:"M5.214 15.014a3.501 3.501 0 0 0 4.446 5.266l4.34 -2.534v-6.946"}),f("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"}),f("path",{d:"M12.783 4.616a3.501 3.501 0 0 0 -6.783 1.217v5.067l6 3.45"}),f("path",{d:"M18.786 8.986a3.501 3.501 0 0 0 -4.446 -5.266l-4.34 2.534v6.946"}),f("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"})]}),G),py=L(B("g",{stroke:"currentColor",fill:"none",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M4 8v-2a2 2 0 0 1 2 -2h2"}),f("path",{d:"M4 16v2a2 2 0 0 0 2 2h2"}),f("path",{d:"M16 4h2a2 2 0 0 1 2 2v2"}),f("path",{d:"M16 20h2a2 2 0 0 0 2 -2v-2"})]}),G),ka=L(B("g",{stroke:"currentColor",fill:"none",strokeWidth:1.5,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M10 12a2 2 0 1 0 4 0a2 2 0 0 0 -4 0"}),f("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"})]}),G),uy=L(B("g",{stroke:"currentColor",fill:"none",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M10.585 10.587a2 2 0 0 0 2.829 2.828"}),f("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"}),f("path",{d:"M3 3l18 18"})]}),G),gy=L(B("g",{stroke:"currentColor",fill:"none",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("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"}),f("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"}),f("path",{d:"M17.5 16a3.5 3.5 0 0 0 0 -7h-.5"}),f("path",{d:"M19 9.3v-2.8a3.5 3.5 0 0 0 -7 0"}),f("path",{d:"M6.5 16a3.5 3.5 0 0 1 0 -7h.5"}),f("path",{d:"M5 9.3v-2.8a3.5 3.5 0 0 1 7 0v10"})]}),G),hy=L(B("g",{strokeWidth:1.25,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("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"}),f("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"}),f("path",{d:"M17.5 16a3.5 3.5 0 0 0 0 -7h-.5"}),f("path",{d:"M19 9.3v-2.8a3.5 3.5 0 0 0 -7 0"}),f("path",{d:"M6.5 16a3.5 3.5 0 0 1 0 -7h.5"}),f("path",{d:"M5 9.3v-2.8a3.5 3.5 0 0 1 7 0v10"})]}),G),ho=L(B("g",{strokeWidth:1.5,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M10 10m-7 0a7 7 0 1 0 14 0a7 7 0 1 0 -14 0"}),f("path",{d:"M21 21l-6 -6"})]}),G),fy=L(B("g",{strokeWidth:1.5,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M20.984 12.53a9 9 0 1 0 -7.552 8.355"}),f("path",{d:"M12 7v5l3 3"}),f("path",{d:"M19 16l-2 3h4l-2 3"})]}),G),by=L(B("g",{strokeWidth:1.5,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M12 8l0 4l2 2"}),f("path",{d:"M3.05 11a9 9 0 1 1 .5 4m-.5 5v-5h5"})]}),G),xy=L(B("g",{strokeWidth:1.5,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("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"}),f("path",{d:"M5 10a7 7 0 0 0 14 0"}),f("path",{d:"M8 21l8 0"}),f("path",{d:"M12 17l0 4"})]}),G),Ey=L(B("g",{strokeWidth:1.5,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M3 3l18 18"}),f("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"}),f("path",{d:"M5 10a7 7 0 0 0 10.846 5.85m2 -2a6.967 6.967 0 0 0 1.152 -3.85"}),f("path",{d:"M8 21l8 0"}),f("path",{d:"M12 17l0 4"})]}),G),wl=L(B("g",{strokeWidth:1.25,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M13 3l0 7l6 0l-8 11l0 -7l-6 0l8 -11"})]}),G),yy=L(B("g",{children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("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"}),f("path",{d:"M12 20v.01"}),f("path",{d:"M16 20v.01"}),f("path",{d:"M8 20v.01"}),f("path",{d:"M4 20v.01"}),f("path",{d:"M4 16v.01"}),f("path",{d:"M4 12v.01"}),f("path",{d:"M4 8v.01"}),f("path",{d:"M4 4v.01"}),f("path",{d:"M8 4v.01"}),f("path",{d:"M12 4v.01"}),f("path",{d:"M16 4v.01"}),f("path",{d:"M20 4v.01"}),f("path",{d:"M20 8v.01"}),f("path",{d:"M20 12v.01"}),f("path",{d:"M20 16v.01"}),f("path",{d:"M20 20v.01"})]}),G),wy=L(B("g",{strokeWidth:1.25,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M5 3v18"}),f("path",{d:"M19 21v-18"}),f("path",{d:"M5 7h14"}),f("path",{d:"M5 15h14"}),f("path",{d:"M8 13v4"}),f("path",{d:"M11 13v4"}),f("path",{d:"M16 13v4"}),f("path",{d:"M14 5v4"}),f("path",{d:"M11 5v4"}),f("path",{d:"M8 5v4"}),f("path",{d:"M3 21h18"})]}),G),vy=L(B("g",{strokeWidth:1.25,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M3 12l18 0"}),f("path",{d:"M7 16l10 0l-10 5l0 -5"}),f("path",{d:"M7 8l10 0l-10 -5l0 5"})]}),G),Ty=L(B("g",{strokeWidth:1.25,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M12 3l0 18"}),f("path",{d:"M16 7l0 10l5 0l-5 -10"}),f("path",{d:"M8 7l0 10l-5 0l5 -10"})]}),G),kg=L(B("g",{strokeWidth:1.25,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("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"}),f("path",{d:"M19 6h1a2 2 0 0 1 2 2a5 5 0 0 1 -5 5l-5 0v2"}),f("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"})]}),G),Sa=L(B("g",{strokeWidth:1.25,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M15 15m-5 0a5 5 0 1 0 10 0a5 5 0 1 0 -10 0"}),f("path",{d:"M22 22l-3 -3"}),f("path",{d:"M6 18h-1a2 2 0 0 1 -2 -2v-1"}),f("path",{d:"M3 11v-1"}),f("path",{d:"M3 6v-1a2 2 0 0 1 2 -2h1"}),f("path",{d:"M10 3h1"}),f("path",{d:"M15 3h1a2 2 0 0 1 2 2v1"})]}),G),Iy=L(B("g",{strokeWidth:1.25,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M14 3v4a1 1 0 0 0 1 1h4"}),f("path",{d:"M5 12v-7a2 2 0 0 1 2 -2h7l5 5v4"}),f("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"}),f("path",{d:"M10 15l2 6l2 -6"}),f("path",{d:"M20 15h-1a2 2 0 0 0 -2 2v2a2 2 0 0 0 2 2h1v-3"})]}),G),Cy=L(B("g",{strokeWidth:1.25,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M14 3v4a1 1 0 0 0 1 1h4"}),f("path",{d:"M5 12v-7a2 2 0 0 1 2 -2h7l5 5v4"}),f("path",{d:"M20 15h-1a2 2 0 0 0 -2 2v2a2 2 0 0 0 2 2h1v-3"}),f("path",{d:"M5 18h1.5a1.5 1.5 0 0 0 0 -3h-1.5v6"}),f("path",{d:"M11 21v-6l3 6v-6"})]}),G),ky=L(B("g",{strokeWidth:1.25,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("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"}),f("path",{d:"M4 8l5 0"}),f("path",{d:"M15 8l4 0"})]}),G),Sy=L(B("g",{strokeWidth:1.25,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("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"}),f("path",{d:"M8 3a2.4 2.4 0 0 0 -1 2a2.4 2.4 0 0 0 1 2"}),f("path",{d:"M12 3a2.4 2.4 0 0 0 -1 2a2.4 2.4 0 0 0 1 2"}),f("path",{d:"M3 10h14v5a6 6 0 0 1 -6 6h-2a6 6 0 0 1 -6 -6v-5z"}),f("path",{d:"M16.746 16.726a3 3 0 1 0 .252 -5.555"})]}),G),My=L(B("g",{stroke:"currentColor",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("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"})]}),{...G,strokeWidth:1.5}),Vj=L(B("g",{strokeWidth:1.5,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("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"}),f("path",{d:"M21 12h-13l3 -3"}),f("path",{d:"M11 15l-3 -3"})]}),G),Py=L(B("g",{children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("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"}),f("path",{d:"M10 9l5 3l-5 3z"})]}),G),Ay=L(B("g",{strokeWidth:1.5,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M3 6h18"}),f("path",{d:"M3 12h18"}),f("path",{d:"M3 18h18"}),f("path",{d:"M6 3v18"}),f("path",{d:"M12 3v18"}),f("path",{d:"M18 3v18"})]}),G),Ly=L(B("g",{strokeWidth:1.5,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("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"}),f("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"}),f("path",{d:"M17 5c-6.627 0 -12 5.373 -12 12"})]}),G),Ma=L(B("g",{children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M6 18l12 -12"}),f("path",{d:"M18 10v-4h-4"})]}),G),Pa=L(B("g",{children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M4,19L10,19C11.097,19 12,18.097 12,17L12,9C12,7.903 12.903,7 14,7L21,7"}),f("path",{d:"M18 4l3 3l-3 3"})]}),G),Aa=L(B("g",{children:[f("path",{d:"M16,12L20,9L16,6"}),f("path",{d:"M6 20c0 -6.075 4.925 -11 11 -11h3"})]}),G),Md=L(B("g",{children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M6 9l6 6l6 -6"})]}),G),_y=L(B("g",{children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M6 15l6 -6l6 6"})]}),G),Dy=L(B("g",{children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M6 15l6 -6l6 6"})]}),G),Sg=L(B("g",{strokeWidth:"1.25",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M8 5v10a1 1 0 0 0 1 1h10"}),f("path",{d:"M5 8h10a1 1 0 0 1 1 1v10"})]}),G),Pd=L(B("g",{children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M5 5m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"}),f("path",{d:"M19 5m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"}),f("path",{d:"M5 19m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"}),f("path",{d:"M19 19m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"}),f("path",{d:"M5 7l0 10"}),f("path",{d:"M7 5l10 0"}),f("path",{d:"M7 19l10 0"}),f("path",{d:"M19 7l0 10"})]}),G),Kj=L(B("g",{strokeWidth:1.5,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("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"}),f("path",{d:"M4 12h7a1 1 0 0 1 1 1v7"})]}),G),Ry=L(B("g",{strokeWidth:1.5,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M14 6m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"}),f("path",{d:"M4 6l8 0"}),f("path",{d:"M16 6l4 0"}),f("path",{d:"M8 12m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"}),f("path",{d:"M4 12l2 0"}),f("path",{d:"M10 12l10 0"}),f("path",{d:"M17 18m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"}),f("path",{d:"M4 18l11 0"}),f("path",{d:"M19 18l1 0"})]}),G),Ny=L(B("g",{strokeWidth:1,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M6 10l4 -4 L6 14l8 -8 L6 18l12 -12 L10 18l8 -8 L14 18l4 -4"})]}),G),By=L(B("g",{strokeWidth:1.25,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M4 20h4l10.5 -10.5a2.828 2.828 0 1 0 -4 -4l-10.5 10.5v4"}),f("path",{d:"M13.5 6.5l4 4"})]}),G),Xj=L(B("g",{strokeWidth:1,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M11 7l-5 5l5 5"}),f("path",{d:"M17 7l-5 5l5 5"})]}),G),Fy=L(B("g",{strokeWidth:"1.75",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("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"}),f("path",{d:"M15 4l0 16"})]}),G),$j=L(B("g",{strokeWidth:"1.25",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("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"})]}),G),Zj=L(B("g",{strokeWidth:"1.25",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M3 4l18 0"}),f("path",{d:"M4 4v10a2 2 0 0 0 2 2h12a2 2 0 0 0 2 -2v-10"}),f("path",{d:"M12 16l0 4"}),f("path",{d:"M9 20l6 0"}),f("path",{d:"M8 12l3 -3l2 2l3 -3"})]}),G),zy=f("div",{style:{width:"1rem",height:"1rem"}}),Oy=L(B("g",{strokeWidth:"1.5",children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("polyline",{points:"9 6 15 12 9 18"})]}),G),Hy=L(B("g",{strokeWidth:1.25,children:[f("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),f("path",{d:"M14 6m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"}),f("path",{d:"M4 6l8 0"}),f("path",{d:"M16 6l4 0"}),f("path",{d:"M8 12m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"}),f("path",{d:"M4 12l2 0"}),f("path",{d:"M10 12l10 0"}),f("path",{d:"M17 18m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"}),f("path",{d:"M4 18l11 0"}),f("path",{d:"M19 18l1 0"})]}),G);import Gy from"clsx";import Pg,{useEffect as U6,useRef as Uy,useState as W6}from"react";import{isPromiseLike as Y6}from"@orangecatai/common";import H6 from"react";import{jsx as Mg}from"react/jsx-runtime";var G6=({size:e="1em",circleWidth:t=8,synchronized:o=!1,className:n=""})=>{let i=-(H6.useRef(Date.now()).current%1600);return Mg("div",{className:`Spinner ${n}`,children:Mg("svg",{viewBox:"0 0 100 100",style:{width:e,height:e,"--spinner-delay":o?`${i}ms`:0},children:Mg("circle",{cx:"50",cy:"50",r:50-t/2,strokeWidth:t,fill:"none",strokeMiterlimit:"10"})})})},Bt=G6;import{jsx as vl,jsxs as Tl}from"react/jsx-runtime";var ee=Pg.forwardRef(({size:e="medium",visible:t=!0,className:o="",...n},r)=>{let{id:i}=Ke(),a=Pg.useRef(null);Pg.useImperativeHandle(r,()=>a.current);let s=`ToolIcon_size_${e}`,[l,c]=W6(!1),m=Uy(!0),p=async u=>{let b="onClick"in n&&n.onClick?.(u);if(Y6(b))try{c(!0),await b}catch(g){if(g instanceof sa)console.warn(g);else throw g}finally{m.current&&c(!1)}};U6(()=>(m.current=!0,()=>{m.current=!1}),[]);let d=Uy(null);if(n.type==="button"||n.type==="icon"||n.type==="submit"){let u=n.type==="icon"?"button":n.type;return Tl("button",{className:Gy("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:a,disabled:l||n.isLoading||!!n.disabled,children:[(n.icon||n.label)&&Tl("div",{className:"ToolIcon__icon","aria-hidden":"true","aria-disabled":!!n.disabled,children:[n.icon||n.label,n.keyBindingLabel&&vl("span",{className:"ToolIcon__keybinding",children:n.keyBindingLabel}),n.isLoading&&vl(Bt,{})]}),n.showAriaLabel&&Tl("div",{className:"ToolIcon__label",children:[n["aria-label"]," ",l&&vl(Bt,{})]}),n.children]})}return Tl("label",{className:Gy("ToolIcon",o),title:n.title,onPointerDown:u=>{d.current=u.pointerType||null,n.onPointerDown?.({pointerType:u.pointerType||null})},onPointerUp:()=>{requestAnimationFrame(()=>{d.current=null})},children:[vl("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:`${i}-${n.id}`,onChange:()=>{n.onChange?.({pointerType:d.current})},checked:n.checked,ref:a}),Tl("div",{className:"ToolIcon__icon",children:[n.icon,n.keyBindingLabel&&vl("span",{className:"ToolIcon__keybinding",children:n.keyBindingLabel})]})]})});ee.displayName="ToolButton";var Ad=[],z=e=>(Ad=Ad.concat(e),e);import{jsx as Q6}from"react/jsx-runtime";var J6=(e,t,o)=>{let n=new Set(se(e.filter(m=>Z6(m)),t).map(m=>m.id)),r={},i=o.scene.getNonDeletedElementsMap(),a=new Set;for(let m of n){let p=j6(e,m);for(let d of p)if(!a.has(d.id)){if(Ld(d)){let u=Yy(d,i);u&&(r[u.id]=!0)}else r[d.id]=!0;a.add(d.id)}}let s=!0,l=e.map(m=>{if(t.selectedElementIds[m.id]){let p=Ld(m)?Yy(m,i):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&&$6(u)&&o.scene.mutateElement(u,{startBinding:m.id===u.startBinding?.elementId?null:u.startBinding,endBinding:m.id===u.endBinding?.elementId?null:u.endBinding})}),Dd(m,{isDeleted:!0}))}return m.frameId&&n.has(m.frameId)?(s=!1,Ld(m)||(r[m.id]=!0),Dd(m,{frameId:null})):Ld(m)&&t.selectedElementIds[m.containerId]?Dd(m,{isDeleted:!0}):m}),c=t.editingGroupId;if(s&&t.editingGroupId){let m=_g(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(b=>b===t.editingGroupId),u=p.groupIds[d+1];if(u){let b=_g(l,u).filter(g=>!g.isDeleted);b.length>1&&(c=u,b.forEach(g=>{r[g.id]=!0}))}}}}return{elements:l,appState:{...t,...q6({selectedElementIds:r,editingGroupId:c},l,t,null)}}},Vy=(e,t)=>{if(e.editingGroupId){let o=_g(Lg(t),e.editingGroupId);if(o.length)return{...e,selectedElementIds:{[o[0].id]:!0}}}return e},Il=z({name:"deleteSelectedElements",label:"labels.delete",icon:Nt,trackEvent:{category:"element",action:"delete"},perform:(e,t,o,n)=>{if(t.selectedLinearElement?.isEditing){let{elementId:a,selectedPointsIndices:s}=t.selectedLinearElement,l=n.scene.getNonDeletedElementsMap(),c=Wy.getElement(a,l);if(!c||s==null)return!1;if(s.length>=c.points.length){let m=e.map(d=>d.id===c.id?Dd(d,{isDeleted:!0}):d),p=Vy(t,m);return{elements:m,appState:{...p,selectedLinearElement:null},captureUpdate:_d.IMMEDIATELY}}return Wy.deletePoints(c,n,s),{elements:e,appState:{...t,selectedLinearElement:{...t.selectedLinearElement,selectedPointsIndices:s?.[0]>0?[s[0]-1]:[0]}},captureUpdate:_d.IMMEDIATELY}}let{elements:r,appState:i}=J6(e,t,n);return X6(r,r.filter(a=>a.isDeleted)),i=Vy(i,r),{elements:r,appState:{...i,activeTool:K6(t,{type:n.state.preferredSelectionTool.type}),multiElement:null,newElement:null,activeEmbeddable:null,selectedLinearElement:null},captureUpdate:ze(Lg(e),t)?_d.IMMEDIATELY:_d.EVENTUALLY}},keyTest:(e,t,o)=>(e.key===Ag.BACKSPACE||e.key===Ag.DELETE)&&!e[Ag.CTRL_OR_CMD],PanelComponent:({elements:e,appState:t,updateData:o,app:n})=>{let r=kt()==="mobile";return Q6(ee,{type:"button",icon:Nt,title:h("labels.delete"),"aria-label":h("labels.delete"),onClick:()=>o(null),disabled:!ze(Lg(e),t),style:{...r&&t.openPopup!=="compactOtherProperties"?V6:{}}})}});import{KEYS as La,CODES as _a,isDarwin as Rd}from"@orangecatai/common";import{moveOneLeft as eP,moveOneRight as tP,moveAllLeft as oP,moveAllRight as nP}from"@orangecatai/element";import{CaptureUpdateAction as Nd}from"@orangecatai/element";import{isDarwin as Ky}from"@orangecatai/common";var N=e=>e.replace(/\b(Opt(?:ion)?|Alt)\b/i,Ky?h("keys.option"):h("keys.alt")).replace(/\bShift\b/i,h("keys.shift")).replace(/\b(Enter|Return)\b/i,h("keys.enter")).replace(/\b(Ctrl|Cmd|Command|CtrlOrCmd)\b/gi,Ky?h("keys.cmd"):h("keys.ctrl")).replace(/\b(Esc(?:ape)?)\b/i,h("keys.escape")).replace(/\b(Space(?:bar)?)\b/i,h("keys.spacebar")).replace(/\b(Del(?:ete)?)\b/i,h("keys.delete"));import{jsx as Bd}from"react/jsx-runtime";var Dg=z({name:"sendBackward",label:"labels.sendBackward",keywords:["move down","zindex","layer"],icon:pg,trackEvent:{category:"element"},perform:(e,t,o,n)=>({elements:eP(e,t,n.scene),appState:t,captureUpdate:Nd.IMMEDIATELY}),keyPriority:40,keyTest:e=>e[La.CTRL_OR_CMD]&&!e.shiftKey&&e.code===_a.BRACKET_LEFT,PanelComponent:({updateData:e,appState:t})=>Bd("button",{type:"button",className:"zIndexButton",onClick:()=>e(null),title:`${h("labels.sendBackward")} \u2014 ${N("CtrlOrCmd+[")}`,children:pg})}),Rg=z({name:"bringForward",label:"labels.bringForward",keywords:["move up","zindex","layer"],icon:mg,trackEvent:{category:"element"},perform:(e,t,o,n)=>({elements:tP(e,t,n.scene),appState:t,captureUpdate:Nd.IMMEDIATELY}),keyPriority:40,keyTest:e=>e[La.CTRL_OR_CMD]&&!e.shiftKey&&e.code===_a.BRACKET_RIGHT,PanelComponent:({updateData:e,appState:t})=>Bd("button",{type:"button",className:"zIndexButton",onClick:()=>e(null),title:`${h("labels.bringForward")} \u2014 ${N("CtrlOrCmd+]")}`,children:mg})}),Ng=z({name:"sendToBack",label:"labels.sendToBack",keywords:["move down","zindex","layer"],icon:gg,trackEvent:{category:"element"},perform:(e,t)=>({elements:oP(e,t),appState:t,captureUpdate:Nd.IMMEDIATELY}),keyTest:e=>Rd?e[La.CTRL_OR_CMD]&&e.altKey&&e.code===_a.BRACKET_LEFT:e[La.CTRL_OR_CMD]&&e.shiftKey&&e.code===_a.BRACKET_LEFT,PanelComponent:({updateData:e,appState:t})=>Bd("button",{type:"button",className:"zIndexButton",onClick:()=>e(null),title:`${h("labels.sendToBack")} \u2014 ${Rd?N("CtrlOrCmd+Alt+["):N("CtrlOrCmd+Shift+[")}`,children:gg})}),Bg=z({name:"bringToFront",label:"labels.bringToFront",keywords:["move up","zindex","layer"],icon:ug,trackEvent:{category:"element"},perform:(e,t)=>({elements:nP(e,t),appState:t,captureUpdate:Nd.IMMEDIATELY}),keyTest:e=>Rd?e[La.CTRL_OR_CMD]&&e.altKey&&e.code===_a.BRACKET_RIGHT:e[La.CTRL_OR_CMD]&&e.shiftKey&&e.code===_a.BRACKET_RIGHT,PanelComponent:({updateData:e,appState:t})=>Bd("button",{type:"button",className:"zIndexButton",onClick:o=>e(null),title:`${h("labels.bringToFront")} \u2014 ${Rd?N("CtrlOrCmd+Alt+]"):N("CtrlOrCmd+Shift+]")}`,children:ug})});import{getNonDeletedElements as rP}from"@orangecatai/element";import{LinearElementEditor as iP}from"@orangecatai/element";import{isLinearElement as aP,isTextElement as sP}from"@orangecatai/element";import{arrayToMap as lP,KEYS as Xy}from"@orangecatai/common";import{selectGroupsForSelectedElements as cP}from"@orangecatai/element";import{CaptureUpdateAction as dP}from"@orangecatai/element";var Fg=z({name:"selectAll",label:"labels.selectAll",icon:yy,trackEvent:{category:"canvas"},viewMode:!1,perform:(e,t,o,n)=>{if(t.selectedLinearElement?.isEditing)return!1;let r=e.filter(i=>!i.isDeleted&&!(sP(i)&&i.containerId)&&!i.locked).reduce((i,a)=>(i[a.id]=!0,i),{});return{appState:{...t,...cP({editingGroupId:null,selectedElementIds:r},rP(e),t,n),selectedLinearElement:Object.keys(r).length===1&&aP(e[0])?new iP(e[0],lP(e)):null},captureUpdate:dP.IMMEDIATELY}},keyTest:e=>e[Xy.CTRL_OR_CMD]&&e.key===Xy.A});import{DEFAULT_GRID_SIZE as $y,KEYS as Zy,MOBILE_ACTION_BUTTON_BG as mP,arrayToMap as jy}from"@orangecatai/common";import{getNonDeletedElements as qy}from"@orangecatai/element";import{LinearElementEditor as pP}from"@orangecatai/element";import{getSelectedElements as uP,getSelectionStateForElements as gP}from"@orangecatai/element";import{syncMovedIndices as hP}from"@orangecatai/element";import{duplicateElements as fP}from"@orangecatai/element";import{CaptureUpdateAction as Jy}from"@orangecatai/element";import{jsx as bP}from"react/jsx-runtime";var zg=z({name:"duplicateSelection",label:"labels.duplicateSelection",icon:hl,trackEvent:{category:"element"},perform:(e,t,o,n)=>{if(t.selectedElementsAreBeingDragged)return!1;if(t.selectedLinearElement?.isEditing)try{let a=pP.duplicateSelectedPoints(t,n.scene);return{elements:e,appState:a,captureUpdate:Jy.IMMEDIATELY}}catch{return!1}let{duplicatedElements:r,elementsWithDuplicates:i}=fP({type:"in-place",elements:e,idsOfElementsToDuplicate:jy(uP(e,t,{includeBoundTextElement:!0,includeElementsInFrames:!0})),appState:t,randomizeSeed:!0,overrides:({origElement:a,origIdToDuplicateId:s})=>{let l=a.frameId&&s.get(a.frameId);return{x:a.x+$y/2,y:a.y+$y/2,frameId:l??a.frameId}}});if(n.props.onDuplicate&&i){let a=n.props.onDuplicate(i,e);a&&(i=a)}return{elements:hP(i,jy(r)),appState:{...t,...gP(r,qy(i),t)},captureUpdate:Jy.IMMEDIATELY}},keyTest:e=>e[Zy.CTRL_OR_CMD]&&e.key===Zy.D,PanelComponent:({elements:e,appState:t,updateData:o,app:n})=>{let r=kt()==="mobile";return bP(ee,{type:"button",icon:hl,title:`${h("labels.duplicateSelection")} \u2014 ${N("CtrlOrCmd+D")}`,"aria-label":h("labels.duplicateSelection"),onClick:()=>o(null),disabled:!ze(qy(e),t),style:{...r&&t.openPopup!=="compactOtherProperties"?mP:{}}})}});import{pointFrom as bL}from"@orangecatai/math";import{useEffect as sh,useMemo as xL,useRef as lh,useState as EL}from"react";import{DEFAULT_ELEMENT_BACKGROUND_COLOR_PALETTE as yL,DEFAULT_ELEMENT_BACKGROUND_PICKS as wL,DEFAULT_ELEMENT_STROKE_COLOR_PALETTE as vL,DEFAULT_ELEMENT_STROKE_PICKS as TL,ARROW_TYPE as So,DEFAULT_FONT_FAMILY as IL,DEFAULT_FONT_SIZE as CL,FONT_FAMILY as kL,ROUNDNESS as Qd,STROKE_WIDTH as ch,VERTICAL_ALIGN as qd,KEYS as Ha,randomInteger as SL,arrayToMap as mh,getFontFamilyString as ML,getLineHeight as PL,isTransparent as AL,reduceToCommonValue as LL,invariant as ph,FONT_SIZES as Jd}from"@orangecatai/common";import{canBecomePolygon as _L,getNonDeletedElements as Uw}from"@orangecatai/element";import{bindBindingElement as zw,calculateFixedPointForElbowArrowBinding as Ow,updateBoundElements as DL}from"@orangecatai/element";import{LinearElementEditor as Ii}from"@orangecatai/element";import{newElementWith as Et}from"@orangecatai/element";import{getBoundTextElement as Pr,redrawTextBoundingBox as Bl}from"@orangecatai/element";import{isArrowElement as em,isBoundToContainer as RL,isElbowArrow as Ww,isLinearElement as dh,isLineElement as Hw,isTextElement as no,isUsingAdaptiveRadius as NL}from"@orangecatai/element";import{hasStrokeColor as BL}from"@orangecatai/element";import{updateElbowArrowPoints as FL,CaptureUpdateAction as yt,toggleLinePolygonState as zL}from"@orangecatai/element";import{deriveStylesPanelMode as OL}from"@orangecatai/common";import{isDevEnv as xP}from"@orangecatai/common";var EP=new Set(["command_palette","export"]),he=(e,t,o,n)=>{try{if(typeof window>"u"||I.VITE_WORKER_ID||I.VITE_APP_ENABLE_TRACKING!=="true"||!EP.has(e)||xP())return;I.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 TP from"clsx";import yP from"clsx";import{forwardRef as wP}from"react";import{jsx as vP}from"react/jsx-runtime";var Da=wP((e,t)=>{let{title:o,className:n,testId:r,active:i,standalone:a,icon:s,onClick:l}=e;return vP("button",{type:"button",ref:t,title:o,"data-testid":r,className:yP(n,{standalone:a,active:i}),onClick:l,style:e.style,children:s},o)});import{Fragment as CP,jsx as Og,jsxs as IP}from"react/jsx-runtime";var Io=e=>Og(CP,{children:e.options.map(t=>e.type==="button"?Og(Da,{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):IP("label",{className:TP({active:e.value===t.value}),title:t.text,children:[Og("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 xw}from"radix-ui";import Ew from"clsx";import{useRef as yw,useEffect as SA}from"react";import{COLOR_OUTLINE_CONTRAST_THRESHOLD as fw,COLOR_PALETTE as ww,isColorDark as bw,isWritableElement as MA}from"@orangecatai/common";import{jsx as kP}from"react/jsx-runtime";var Fd=()=>kP("div",{style:{width:1,height:"1rem",backgroundColor:"var(--default-border-color)",margin:"0 auto"}});import{useEffect as LP,useRef as _P}from"react";import{createPortal as DP}from"react-dom";import{EVENT as wr,KEYS as RP,rgbToHex as NP}from"@orangecatai/common";import Qy from"react";var Hg=Qy.createContext(null),Ee=()=>Qy.useContext(Hg);import{useState as SP,useLayoutEffect as ew}from"react";import{THEME as MP}from"@orangecatai/common";var zd=e=>{let[t,o]=SP(null),n=ye(),{theme:r}=Ee(),{container:i}=Ke();return ew(()=>{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===MP.DARK))},[t,r,n.formFactor,e?.className]),ew(()=>{let a=e?.parentSelector?i?.querySelector(e.parentSelector):document.body;if(!a)return;let s=document.createElement("div");return a.appendChild(s),o(s),()=>{a.removeChild(s)}},[i,e?.parentSelector]),t};import{useEffect as PP}from"react";import{EVENT as Od}from"@orangecatai/common";function Ra(e,t,o){PP(()=>{function n(r){let i=r;if(!e.current)return;let a=o?.(i,e.current);if(a===!0)return;if(a===!1)return t(i);e.current.contains(i.target)||!document.documentElement.contains(i.target)||i.target.closest("[data-radix-portal]")||i.target===document.documentElement&&document.body.style.pointerEvents==="none"||i.target.closest("[data-prevent-outside-click]")||t(i)}return document.addEventListener(Od.POINTER_DOWN,n),document.addEventListener(Od.TOUCH_START,n),()=>{document.removeEventListener(Od.POINTER_DOWN,n),document.removeEventListener(Od.TOUCH_START,n)}},[e,t,o])}import{useRef as AP}from"react";var yr=e=>{let t=AP(e);return Object.assign(t.current,e),t.current};import{jsx as BP}from"react/jsx-runtime";var vr=Ie(null),tw=({onCancel:e,onChange:t,onSelect:o,colorPickerType:n})=>{let r=zd({className:"excalidraw-eye-dropper-backdrop",parentSelector:".excalidraw-eye-dropper-container"}),i=Ee(),a=Tr(),s=Xe(),l=se(a,i),c=yr({app:s,onCancel:e,onChange:t,onSelect:o,selectedElements:l}),{container:m}=Ke();LP(()=>{let d=p.current;if(!d||!s.canvas||!r)return;let u=!1,b=s.canvas.getContext("2d"),g=({clientX:C,clientY:M})=>{let k=b.getImageData((C-i.offsetLeft)*window.devicePixelRatio,(M-i.offsetTop)*window.devicePixelRatio,1,1).data;return NP(k[0],k[1],k[2])},E=({clientX:C,clientY:M,altKey:k})=>{d.style.top=`${M+20}px`,d.style.left=`${C+20}px`;let R=g({clientX:C,clientY:M});u&&c.onChange(n,R,c.selectedElements,{altKey:k}),d.style.background=R},y=()=>{c.onCancel()},x=(C,M)=>{c.onSelect(C,M)},w=C=>{u=!0,C.stopImmediatePropagation()},v=C=>{u=!1,m?.focus(),C.stopImmediatePropagation(),C.preventDefault(),x(g(C),C)},T=C=>{C.key===RP.ESCAPE&&(C.preventDefault(),C.stopImmediatePropagation(),y())};return r.tabIndex=-1,r.focus(),E({clientX:c.app.lastViewportPosition.x,clientY:c.app.lastViewportPosition.y,altKey:!1}),r.addEventListener(wr.KEYDOWN,T),r.addEventListener(wr.POINTER_DOWN,w),r.addEventListener(wr.POINTER_UP,v),window.addEventListener("pointermove",E,{passive:!0}),window.addEventListener(wr.BLUR,y),()=>{u=!1,r.removeEventListener(wr.KEYDOWN,T),r.removeEventListener(wr.POINTER_DOWN,w),r.removeEventListener(wr.POINTER_UP,v),window.removeEventListener("pointermove",E),window.removeEventListener(wr.BLUR,y)}},[c,s.canvas,r,n,m,i.offsetLeft,i.offsetTop]);let p=_P(null);return Ra(p,()=>{e()},d=>!!d.target.closest(".excalidraw-eye-dropper-trigger, .excalidraw-eye-dropper-backdrop")),r?DP(BP("div",{ref:p,className:"excalidraw-eye-dropper-preview"}),r):null};import{Popover as Gg}from"radix-ui";import HP from"clsx";import GP from"react";import{isInteractive as UP}from"@orangecatai/common";import FP from"react";import zP from"clsx";import{jsx as OP}from"react/jsx-runtime";var st=FP.forwardRef(({children:e,padding:t,className:o,style:n},r)=>OP("div",{className:zP("Island",o),style:{"--padding":t,...n},ref:r,children:e}));import{jsx as Ug,jsxs as WP}from"react/jsx-runtime";var Yn=GP.forwardRef(({className:e,container:t,children:o,style:n,onClose:r,onKeyDown:i,onFocusOutside:a,onPointerLeave:s,onPointerDownOutside:l,preventAutoFocusOnTouch:c=!1},m)=>{let p=ye(),d=p.formFactor==="phone"&&!p.isLandscape;return Ug(Gg.Portal,{container:t,children:WP(Gg.Content,{ref:m,className:HP("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:i,onFocusOutside:a,onPointerDownOutside:l,onOpenAutoFocus:u=>{c&&p.isTouchScreen&&u.preventDefault()},onCloseAutoFocus:u=>{u.stopPropagation(),u.preventDefault(),t&&!UP(document.activeElement)&&t.focus(),r()},children:[Ug(st,{padding:3,style:n,children:o}),Ug(Gg.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 YP,useCallback as Wg}from"react";var Hd=()=>document.querySelector(".excalidraw-wysiwyg"),Gd=()=>{let e=Hd();return e?{start:e.selectionStart,end:e.selectionEnd}:null},Cl=e=>{setTimeout(()=>{let t=Hd();t&&(t.focus(),e&&(t.selectionStart=e.start,t.selectionEnd=e.end))},0)},kl=(e,t,o,n)=>{t&&n&&n();let r=t&&o?Gd():null;e(),t&&o&&Cl(r)},ow=()=>{let[e,t]=YP(null),o=Wg(()=>{let i=Gd();t(i)},[]),n=Wg(()=>{setTimeout(()=>{let i=Hd();i&&(i.focus(),e&&(i.selectionStart=e.start,i.selectionEnd=e.end,t(null)))},0)},[e]),r=Wg(()=>{t(null)},[]);return{saveCaretPosition:o,restoreCaretPosition:n,clearSavedPosition:r,hasSavedPosition:!!e}},nw=(e=100)=>{let t=Hd();if(t){let o=t.onblur;t.onblur=null,setTimeout(()=>{t.onblur=o},e)}};import KP from"clsx";import{useCallback as XP,useEffect as Vg,useRef as iw,useState as $P}from"react";import{KEYS as Kg,normalizeInputColor as ZP}from"@orangecatai/common";import{MAX_CUSTOM_COLORS_USED_IN_CANVAS as VP}from"@orangecatai/common";var Ir=({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},Sl=[["q","w","e","r","t"],["a","s","d","f","g"],["z","x","c","v","b"]].flat(),Yg=({color:e,palette:t})=>!Object.values(t).flat().includes(e),rw=(e,t,o)=>{let n={elementBackground:"backgroundColor",elementStroke:"strokeColor"},r=e.filter(a=>{if(a.isDeleted)return!1;let s=a[n[t]];return Yg({color:s,palette:o})}),i=new Map;return r.forEach(a=>{let s=a[n[t]];i.has(s)?i.set(s,i.get(s)+1):i.set(s,1)}),[...i.entries()].sort((a,s)=>s[1]-a[1]).map(a=>a[0]).slice(0,VP)},Co=Ie(null);import{Fragment as jP,jsx as Ud,jsxs as aw}from"react/jsx-runtime";var sw=({color:e,onChange:t,label:o,colorPickerType:n,placeholder:r})=>{let i=ye(),[a,s]=$P(e),[l,c]=ne(Co);Vg(()=>{s(e)},[e]);let m=XP(g=>{let E=g.toLowerCase(),y=ZP(E);y&&t(y),s(E)},[t]),p=iw(null),d=iw(null);Vg(()=>{p.current&&p.current.focus()},[l]);let[u,b]=ne(vr);return Vg(()=>()=>{b(null)},[b]),aw("div",{className:"color-picker__input-label",children:[Ud("div",{className:"color-picker__input-hash",children:"#"}),Ud("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:(a||"").replace(/^#/,""),onBlur:()=>{s(e)},tabIndex:-1,onFocus:()=>c("hex"),onKeyDown:g=>{g.key!==Kg.TAB&&(g.key===Kg.ESCAPE&&d.current?.focus(),g.stopPropagation())},placeholder:r}),i.formFactor!=="phone"&&aw(jP,{children:[Ud("div",{style:{width:"1px",height:"1.25rem",backgroundColor:"var(--default-border-color)"}}),Ud("div",{ref:d,className:KP("excalidraw-eye-dropper-trigger",{selected:u}),onClick:()=>b(g=>g?null:{keepOpenOnAlt:!1,onSelect:E=>t(E),colorPickerType:n}),title:`${h("labels.eyeDropper")} \u2014 ${Kg.I.toLocaleUpperCase()} or ${N("Alt")} `,children:cy})]})]})};import jg,{useEffect as qg,useImperativeHandle as fA,useState as bA}from"react";import{EVENT as uw}from"@orangecatai/common";import{DEFAULT_ELEMENT_BACKGROUND_COLOR_INDEX as xA,DEFAULT_ELEMENT_STROKE_COLOR_INDEX as EA,KEYS as yA}from"@orangecatai/common";import eA from"clsx";import{useEffect as tA,useRef as oA}from"react";import{isColorDark as qP}from"@orangecatai/common";import{jsxs as QP}from"react/jsx-runtime";var JP=({color:e,keyLabel:t,isShade:o=!1})=>QP("div",{className:"color-picker__button__hotkey-label",style:{color:qP(e)?"#fff":"#000"},children:[o&&"\u21E7",t]}),Na=JP;import{jsx as Xg,jsxs as nA}from"react/jsx-runtime";var lw=({colors:e,color:t,onChange:o,label:n})=>{let[r,i]=ne(Co),a=oA(null);return tA(()=>{a.current&&a.current.focus()},[t,r]),Xg("div",{className:"color-picker-content--default",children:e.map((s,l)=>nA("button",{ref:t===s?a:void 0,tabIndex:-1,type:"button",className:eA("color-picker__button color-picker__button--large has-outline",{active:t===s,"is-transparent":s==="transparent"||!s}),onClick:()=>{o(s),i("custom")},title:s,"aria-label":n,style:{"--swatch-color":s},children:[Xg("div",{className:"color-picker__button-outline"}),Xg(Na,{color:s,keyLabel:l+1})]},l))})};import rA from"clsx";import{useEffect as iA,useRef as aA}from"react";import{jsx as $g,jsxs as lA}from"react/jsx-runtime";var sA=({palette:e,color:t,onChange:o,activeShade:n,showHotKey:r=!0})=>{let i=Ir({color:t,palette:e}),[a,s]=ne(Co),l=aA(null);return iA(()=>{l.current&&a==="baseColors"&&l.current.focus()},[i?.colorName,a]),$g("div",{className:"color-picker-content--default",children:Object.entries(e).map(([c,m],p)=>{let d=(Array.isArray(m)?m[n]:m)||"transparent",u=Sl[p],b=h(`colors.${c.replace(/\d+/,"")}`,null,"");return lA("button",{ref:i?.colorName===c?l:void 0,tabIndex:-1,type:"button",className:rA("color-picker__button color-picker__button--large has-outline",{active:i?.colorName===c,"is-transparent":d==="transparent"||!d}),onClick:()=>{o(d),s("baseColors")},title:`${b}${d.startsWith("#")?` ${d}`:""} \u2014 ${u}`,"aria-label":`${b} \u2014 ${u}`,style:d?{"--swatch-color":d}:void 0,"data-testid":`color-${c}`,children:[$g("div",{className:"color-picker__button-outline"}),r&&$g(Na,{color:d,keyLabel:u})]},c)})})},cw=sA;import{jsx as dA}from"react/jsx-runtime";var cA=({children:e})=>dA("div",{className:"color-picker__heading",children:e}),Ba=cA;import mA from"clsx";import{useEffect as pA,useRef as uA}from"react";import{jsx as Ml,jsxs as dw}from"react/jsx-runtime";var mw=({color:e,onChange:t,palette:o,showHotKey:n})=>{let r=Ir({color:e||"transparent",palette:o}),[i,a]=ne(Co),s=uA(null);if(pA(()=>{s.current&&i==="shades"&&s.current.focus()},[r,i]),r){let{colorName:l,shade:c}=r,m=o[l];if(Array.isArray(m))return Ml("div",{className:"color-picker-content--default shades",children:m.map((p,d)=>dw("button",{ref:d===c&&i==="shades"?s:void 0,tabIndex:-1,type:"button",className:mA("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),a("shades")},children:[Ml("div",{className:"color-picker__button-outline"}),n&&Ml(Na,{color:p,keyLabel:d+1,isShade:!0})]},d))})}return dw("div",{className:"color-picker-content--default",style:{position:"relative"},tabIndex:-1,children:[Ml("button",{type:"button",tabIndex:-1,className:"color-picker__button color-picker__button--large color-picker__button--no-focus-visible"}),Ml("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:h("colorPicker.noShades")})]})};import{COLORS_PER_ROW as Fa,COLOR_PALETTE as gA,KEYS as Pl}from"@orangecatai/common";var Zg=(e,t,o)=>{let n=Math.ceil(o/Fa);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+Fa;return r>=o?t%Fa:r}case"ArrowUp":{let r=t-Fa,i=r<0?Fa*n+r:r;return i>=o?void 0:i}}},hA=({e,colorObj:t,onChange:o,palette:n,customColors:r,setActiveColorPickerSection:i,activeShade:a})=>{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]),i("shades"),!0}if(["1","2","3","4","5"].includes(e.key)&&r[Number(e.key)-1])return o(r[Number(e.key)-1]),i("custom"),!0;if(Sl.includes(e.key)){let s=Sl.indexOf(e.key),l=Object.keys(n)[s],c=n[l],m=Array.isArray(c)?c[a]:c;return o(m),i("baseColors"),!0}return!1},pw=({event:e,activeColorPickerSection:t,palette:o,color:n,onChange:r,customColors:i,setActiveColorPickerSection:a,updateData:s,activeShade:l,onEyeDropperToggle:c,onEscape:m})=>{if(e[Pl.CTRL_OR_CMD])return!1;if(e.key===Pl.ESCAPE)return m(e),!0;if(e.key===Pl.ALT)return c(!0),!0;if(e.key===Pl.I)return c(),!0;let p=Ir({color:n,palette:o});if(e.key===Pl.TAB){let d={custom:!!i.length,baseColors:!0,shades:p?.shade!=null,hex:!0},u=Object.entries(d).reduce((x,[w,v])=>(v&&x.push(w),x),[]),b=u.indexOf(t),g=e.shiftKey?-1:1,E=b+g>u.length-1?0:b+g<0?u.length-1:b+g,y=u[E];return y&&a(y),y==="custom"?r(i[0]):y==="baseColors"&&(Object.entries(o).find(([w,v])=>Array.isArray(v)?v.includes(n):v===n?w:null)||r(gA.black)),e.preventDefault(),e.stopPropagation(),!0}if(hA({e,colorObj:p,onChange:r,palette:o,customColors:i,setActiveColorPickerSection:a,activeShade:l}))return!0;if(t==="shades"&&p){let{shade:d}=p,u=Zg(e.key,d,Fa);if(u!==void 0)return r(o[p.colorName][u]),!0}if(t==="baseColors"&&p){let{colorName:d}=p,u=Object.keys(o),b=u.indexOf(d),g=Zg(e.key,b,u.length);if(g!==void 0){let E=u[g],y=o[E];return r(Array.isArray(y)?y[l]:y),!0}}if(t==="custom"){let d=n!=null?i.indexOf(n):0,u=Zg(e.key,d,i.length);if(u!==void 0){let b=i[u];return r(b),!0}}return!1};import{jsx as Cr,jsxs as Wd}from"react/jsx-runtime";var gw=jg.forwardRef(({color:e,onChange:t,type:o,elements:n,palette:r,updateData:i,children:a,showTitle:s,onEyeDropperToggle:l,onEscape:c,showHotKey:m=!0},p)=>{let d=s?o==="elementStroke"?h("labels.stroke"):o==="elementBackground"?h("labels.background"):null:null,[u]=jg.useState(()=>o==="canvasBackground"?[]:rw(n,o,r)),[b,g]=ne(Co),E=Ir({color:e,palette:r});qg(()=>{if(!b){let v=!!e&&Yg({color:e,palette:r}),T=v&&!u.includes(e);g(T?null:v?"custom":E?.shade!=null?"shades":"baseColors")}},[b,e,r,g,E,u]);let[y,x]=bA(E?.shade??(o==="elementBackground"?xA:EA));qg(()=>{E?.shade!=null&&x(E.shade);let v=T=>{T.key===yA.ALT&&l(!1)};return document.addEventListener(uw.KEYUP,v,{capture:!0}),()=>{document.removeEventListener(uw.KEYUP,v,{capture:!0})}},[E,l]);let w=jg.useRef(null);return fA(p,()=>w.current),qg(()=>{w?.current?.focus()},[]),Cr("div",{role:"dialog","aria-modal":"true","aria-label":h("labels.colorPicker"),children:Wd("div",{ref:w,onKeyDown:v=>{pw({event:v,activeColorPickerSection:b,palette:r,color:e,onChange:t,onEyeDropperToggle:l,customColors:u,setActiveColorPickerSection:g,updateData:i,activeShade:y,onEscape:c})&&(v.preventDefault(),v.stopPropagation())},className:"color-picker-content properties-content",tabIndex:-1,children:[d&&Cr("div",{className:"color-picker__title",children:d}),!!u.length&&Wd("div",{children:[Cr(Ba,{children:h("colorPicker.mostUsedCustomColors")}),Cr(lw,{colors:u,color:e,label:h("colorPicker.mostUsedCustomColors"),onChange:t})]}),Wd("div",{children:[Cr(Ba,{children:h("colorPicker.colors")}),Cr(cw,{color:e,palette:r,onChange:t,activeShade:y,showHotKey:m})]}),Wd("div",{children:[Cr(Ba,{children:h("colorPicker.shades")}),Cr(mw,{color:e,onChange:t,palette:r,showHotKey:m})]}),a]})})});import wA from"clsx";import{COLOR_OUTLINE_CONTRAST_THRESHOLD as vA,DEFAULT_CANVAS_BACKGROUND_PICKS as TA,DEFAULT_ELEMENT_BACKGROUND_PICKS as IA,DEFAULT_ELEMENT_STROKE_PICKS as CA,isColorDark as kA}from"@orangecatai/common";import{jsx as Jg}from"react/jsx-runtime";var hw=({onChange:e,type:t,activeColor:o,topPicks:n})=>{let r;return t==="elementStroke"&&(r=CA),t==="elementBackground"&&(r=IA),t==="canvasBackground"&&(r=TA),n&&(r=n),r?Jg("div",{className:"color-picker__top-picks",children:r.map(i=>Jg("button",{className:wA("color-picker__button",{active:i===o,"is-transparent":i==="transparent"||!i,"has-outline":!kA(i,vA)}),style:{"--swatch-color":i},type:"button",title:i,onClick:()=>e(i),"data-testid":`color-top-pick-${i}`,children:Jg("div",{className:"color-picker__button-outline"})},i))}):(console.error("Invalid type for TopPicks"),null)};import{jsx as ko,jsxs as Yd}from"react/jsx-runtime";var PA=({type:e,color:t,onChange:o,label:n,elements:r,palette:i=ww,updateData:a,getOpenPopup:s,appState:l})=>{let{container:c}=Ke(),m=kt(),p=m!=="full",d=m==="mobile",[,u]=ne(Co),[b,g]=ne(vr),E=Yd("div",{children:[ko(Ba,{children:h("colorPicker.hexCode")}),ko(sw,{color:t||"",label:n,onChange:w=>{o(w)},colorPickerType:e,placeholder:h("colorPicker.color")})]}),y=yw(null),x=()=>{y.current?.focus()};return ko(Yn,{container:c,style:{maxWidth:"13rem"},preventAutoFocusOnTouch:!!l.editingTextElement,onFocusOutside:w=>{MA(w.target)||x(),w.preventDefault()},onPointerDownOutside:w=>{b&&w.preventDefault()},onClose:()=>{s()===e&&a({openPopup:null}),u(null),l.editingTextElement&&setTimeout(()=>{let w=document.querySelector(".excalidraw-wysiwyg");w&&w.focus()},0)},children:i?ko(gw,{ref:y,palette:i,color:t,onChange:w=>{let v=l.editingTextElement?Gd():null;o(w),l.editingTextElement&&v&&Cl(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=>{b?g(null):a({openPopup:null})},type:e,elements:r,updateData:a,showTitle:p,showHotKey:!d,children:E}):E})},AA=({label:e,color:t,type:o,mode:n="background",onToggle:r,editingTextElement:i})=>{let a=kt(),s=a!=="full",l=a==="mobile",c=m=>{m.preventDefault(),m.stopPropagation(),i&&nw(),r()};return Yd(xw.Trigger,{type:"button",className:Ew("color-picker__button active-color properties-trigger",{"is-transparent":!t||t==="transparent","has-outline":!t||!bw(t,fw),"compact-sizing":s,"mobile-border":l}),"aria-label":e,style:t?{"--swatch-color":t}:void 0,title:o==="elementStroke"?h("labels.showStroke"):h("labels.showBackground"),"data-openpopup":o,onClick:c,children:[ko("div",{className:"color-picker__button-outline",children:!t&&uE}),s&&t&&n==="stroke"&&ko("div",{className:"color-picker__button-background",children:ko("span",{style:{color:t&&bw(t,fw)?"#fff":"#111"},children:Ny})})]})},Al=({type:e,color:t,onChange:o,label:n,elements:r,palette:i=ww,topPicks:a,updateData:s,appState:l})=>{let c=yw(l.openPopup);SA(()=>{c.current=l.openPopup},[l.openPopup]);let p=kt()!=="full";return ko("div",{children:Yd("div",{role:"dialog","aria-modal":"true",className:Ew("color-picker-container",{"color-picker-container--no-top-picks":p}),children:[!p&&ko(hw,{activeColor:t,onChange:o,type:e,topPicks:a}),!p&&ko(Fd,{}),Yd(xw.Root,{open:l.openPopup===e,onOpenChange:d=>{d&&s({openPopup:e})},children:[ko(AA,{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&&ko(PA,{type:e,color:t,onChange:o,label:n,elements:r,palette:i,updateData:s,getOpenPopup:()=>c.current,appState:l})]})]})})};import{Popover as nL}from"radix-ui";import rL from"clsx";import iL,{useCallback as aL,useMemo as sL}from"react";import{FONT_FAMILY as oh}from"@orangecatai/common";import $A,{useMemo as Mr,useState as ZA,useRef as Cw,useEffect as kw,useCallback as Sw}from"react";import{arrayToList as jA,debounce as qA,FONT_FAMILY as vi,getFontFamilyString as JA}from"@orangecatai/common";import LA from"clsx";import _A from"react";import{jsx as DA,jsxs as RA}from"react/jsx-runtime";var Vd=_A.forwardRef(({className:e,placeholder:t,onChange:o},n)=>RA("div",{className:LA("QuickSearch__wrapper",e),children:[ho,DA("input",{ref:n,className:"QuickSearch__input",type:"text",placeholder:t,onChange:r=>o(r.target.value.trim().toLowerCase())})]}));import NA from"clsx";import{Children as BA}from"react";import{jsx as vw}from"react/jsx-runtime";var Kd=({className:e,placeholder:t,children:o})=>{let n=!BA.count(o);return vw("div",{className:NA("ScrollableList__wrapper",e),role:"menu",children:n?vw("div",{className:"empty",children:t}):o})};import{jsx as FA,jsxs as zA}from"react/jsx-runtime";var Tw=({children:e,className:t="",style:o,title:n})=>zA("div",{className:`dropdown-menu-group ${t}`,style:o,children:[n&&FA("p",{className:"dropdown-menu-group-title",children:n}),e]}),Ll=Tw;Tw.displayName="DropdownMenuGroup";import{THEME as KA}from"@orangecatai/common";import{DropdownMenu as XA}from"radix-ui";import OA,{useContext as HA}from"react";import{composeEventHandlers as GA}from"@orangecatai/common";var Qg=OA.createContext({}),kr=(e="",t=!1,o=!1)=>`dropdown-menu-item dropdown-menu-item-base ${e} ${t?"dropdown-menu-item--selected":""} ${o?"dropdown-menu-item--hovered":""}`.trim(),Xd=e=>{let t=HA(Qg);return GA(e,o=>{t.onSelect?.(o)})};import{jsx as UA}from"react/jsx-runtime";var _l=({children:e,...t})=>UA("span",{...t,style:{textOverflow:"ellipsis",overflow:"hidden",whiteSpace:"nowrap",...t.style},children:e});import{Fragment as YA,jsx as Dl,jsxs as VA}from"react/jsx-runtime";var WA=({textStyle:e,icon:t,shortcut:o,children:n,badge:r})=>{let i=ye();return VA(YA,{children:[t&&Dl("div",{className:"dropdown-menu-item__icon",children:t}),Dl("div",{style:e,className:"dropdown-menu-item__text",children:Dl(_l,{children:n})}),r&&Dl("div",{className:"dropdown-menu-item__badge",children:r}),o&&i.formFactor!=="phone"&&Dl("div",{className:"dropdown-menu-item__shortcut",children:o})]})},Sr=WA;import{jsx as $d}from"react/jsx-runtime";var eh=({icon:e,badge:t,value:o,children:n,shortcut:r,className:i,selected:a,onSelect:s,...l})=>{let c=Xd(s);return $d(XA.Item,{className:"radix-menu-item",onSelect:c,asChild:!0,children:$d("button",{...l,value:o,className:kr(i,a),title:l.title??l["aria-label"],children:$d(Sr,{icon:e,shortcut:r,badge:t,children:n})})})};eh.displayName="DropdownMenuItem";var za={GREEN:"green",RED:"red",BLUE:"blue"},Zd=({type:e=za.BLUE,children:t})=>{let{theme:o}=fn(),n={display:"inline-flex",marginLeft:"auto",padding:"2px 4px",borderRadius:6,fontSize:9,fontFamily:"Cascadia, monospace",border:o===KA.LIGHT?"1.5px solid white":"none"};switch(e){case za.GREEN:Object.assign(n,{backgroundColor:"var(--background-color-badge)",color:"var(--color-badge)"});break;case za.RED:Object.assign(n,{backgroundColor:"pink",color:"darkred"});break;case za.BLUE:default:Object.assign(n,{background:"var(--color-promo)",color:"var(--color-surface-lowest)"})}return $d("div",{className:"DropDownMenuItemBadge",style:n,children:t})};Zd.displayName="DropdownMenuItemBadge";eh.Badge=Zd;var Kt=eh;import{KEYS as Oa}from"@orangecatai/common";var Iw=({event:e,inputRef:t,hoveredFont:o,filteredFonts:n,onClose:r,onSelect:i,onHover:a})=>{if(!e[Oa.CTRL_OR_CMD]&&e.shiftKey&&e.key.toLowerCase()===Oa.F)return t.current?.focus(),!0;if(e.key===Oa.ESCAPE)return r(),!0;if(e.key===Oa.ENTER)return o?.value&&i(o.value),!0;if(e.key===Oa.ARROW_DOWN)return o?.next?a(o.next.value):n[0]?.value&&a(n[0].value),!0;if(e.key===Oa.ARROW_UP)return o?.prev?a(o.prev.value):n[n.length-1]?.value&&a(n[n.length-1].value),!0};import{jsx as Vn,jsxs as eL}from"react/jsx-runtime";var QA=e=>{switch(e){case vi.Excalifont:case vi.Virgil:return un;case vi.Nunito:case vi.Helvetica:return El;case vi["Lilita One"]:return JE;case vi["Comic Shanns"]:case vi.Cascadia:return Cd;default:return El}},Mw=$A.memo(({selectedFontFamily:e,hoveredFontFamily:t,onSelect:o,onHover:n,onLeave:r,onOpen:i,onClose:a})=>{let{container:s}=Ke(),l=Xe(),{fonts:c}=l,{showDeprecatedFonts:m}=bn(),p=kt(),[d,u]=ZA(""),b=Cw(null),g=Mr(()=>Array.from(hr.registered.entries()).filter(([P,{metadata:_}])=>!_.private&&!_.fallback).map(([P,{metadata:_,fontFaces:O}])=>{let U={value:P,icon:QA(P),text:O[0]?.fontFace?.family??"Unknown"};return _.deprecated&&Object.assign(U,{deprecated:_.deprecated,badge:{type:za.RED,placeholder:h("fontList.badge.old")}}),U}).sort((P,_)=>P.text.toLowerCase()>_.text.toLowerCase()?1:-1),[]),E=Mr(()=>new Set(c.getSceneFamilies()),[e]),y=Mr(()=>g.filter(P=>E.has(P.value)),[g,E]),x=Mr(()=>g.filter(P=>!E.has(P.value)&&(m||!P.deprecated)),[g,E,m]),w=Mr(()=>jA([...y,...x].filter(P=>P.text?.toLowerCase().includes(d))),[y,x,d]),v=Mr(()=>{let P;return t?P=w.find(_=>_.value===t):e&&(P=w.find(_=>_.value===e)),!P&&d&&(w[0]?.value?n(w[0].value):r()),P},[t,e,d,w,n,r]),T=Sw(P=>{let _=null;if(l.state.editingTextElement){let O=document.querySelector(".excalidraw-wysiwyg");O&&(_={start:O.selectionStart,end:O.selectionEnd})}o(P),l.state.editingTextElement&&_&&setTimeout(()=>{let O=document.querySelector(".excalidraw-wysiwyg");O&&_&&(O.focus(),O.selectionStart=_.start,O.selectionEnd=_.end)},0)},[o,l.state.editingTextElement]),C=Sw(P=>{Iw({event:P,inputRef:b,hoveredFont:v,filteredFonts:w,onSelect:T,onHover:n,onClose:a})&&(P.preventDefault(),P.stopPropagation())},[v,w,T,n,a]);kw(()=>(i(),()=>{a()}),[]);let M=Mr(()=>w.filter(P=>E.has(P.value)),[w,E]),k=Mr(()=>w.filter(P=>!E.has(P.value)),[w,E]),R=({font:P,order:_})=>{let O=Cw(null),U=P.value===v?.value,H=P.value===e;return kw(()=>{U&&(_===0?O.current?.scrollIntoView?.({block:"end"}):O.current?.scrollIntoView?.({block:"nearest"}))},[U,_]),Vn("button",{ref:O,type:"button",value:P.value,className:kr("",H,U),title:P.text,tabIndex:H?0:-1,onClick:W=>{T(Number(W.currentTarget.value))},onMouseMove:()=>{v?.value!==P.value&&n(P.value)},children:Vn(Sr,{icon:P.icon,badge:P.badge&&Vn(Zd,{type:P.badge.type,children:P.badge.placeholder}),textStyle:{fontFamily:JA({fontFamily:P.value})},children:P.text})})},A=[];return M.length&&A.push(Vn(Ll,{title:h("fontList.sceneFonts"),children:M.map((P,_)=>Vn(R,{font:P,order:_},P.value))},"group_1")),k.length&&A.push(Vn(Ll,{title:h("fontList.availableFonts"),children:k.map((P,_)=>Vn(R,{font:P,order:_+M.length},P.value))},"group_2")),eL(Yn,{className:"properties-content",container:s,style:{width:"15rem"},onClose:()=>{a(),l.state.editingTextElement&&setTimeout(()=>{let P=document.querySelector(".excalidraw-wysiwyg");P&&P.focus()},0)},onPointerLeave:r,onKeyDown:C,preventAutoFocusOnTouch:!!l.state.editingTextElement,children:[p==="full"&&Vn(Vd,{ref:b,placeholder:h("quickSearch.placeholder"),onChange:qA(u,20)}),Vn(Kd,{className:"dropdown-menu fonts manual-hover",placeholder:h("fontList.empty"),children:A.length?A:null})]})},(e,t)=>e.selectedFontFamily===t.selectedFontFamily&&e.hoveredFontFamily===t.hoveredFontFamily);import{Popover as tL}from"radix-ui";import{MOBILE_ACTION_BUTTON_BG as oL}from"@orangecatai/common";import{jsx as th}from"react/jsx-runtime";var Pw=({selectedFontFamily:e,isOpened:t=!1,compactMode:o=!1})=>{let n=ve(),r=o?{...oL,width:"2rem",height:"2rem"}:{};return th(tL.Trigger,{asChild:!0,children:th("div",{"data-openpopup":"fontFamily",className:"properties-trigger",children:th(Da,{standalone:!0,icon:gn,title:h("labels.showFonts"),className:"properties-trigger",testId:"font-family-show-fonts",active:t,onClick:()=>{n(i=>({openPopup:i.openPopup==="fontFamily"?null:i.openPopup}))},style:{border:"none",...r}})})})};import{jsx as Rl,jsxs as Aw}from"react/jsx-runtime";var Lw=[{value:oh.Excalifont,icon:un,text:h("labels.handDrawn"),testId:"font-family-hand-drawn"},{value:oh.Nunito,icon:El,text:h("labels.normal"),testId:"font-family-normal"},{value:oh["Comic Shanns"],icon:Cd,text:h("labels.code"),testId:"font-family-code"}],ine=new Set(Lw.map(e=>e.value));var _w=iL.memo(({isOpened:e,selectedFontFamily:t,hoveredFontFamily:o,onSelect:n,onHover:r,onLeave:i,onPopupChange:a,compactMode:s=!1})=>{let l=sL(()=>Lw,[]),c=aL(m=>{m&&n(m)},[n]);return Aw("div",{role:"dialog","aria-modal":"true",className:rL("FontPicker__container",{"FontPicker__container--compact":s}),children:[!s&&Rl("div",{className:"buttonList",children:Rl(Io,{type:"button",options:l,value:t,onClick:c})}),!s&&Rl(Fd,{}),Aw(nL.Root,{open:e,onOpenChange:a,children:[Rl(Pw,{selectedFontFamily:t,isOpened:e,compactMode:s}),e&&Rl(Mw,{selectedFontFamily:t,hoveredFontFamily:o,onSelect:c,onHover:r,onLeave:i,onOpen:()=>a(!0),onClose:()=>a(!1)})]})]})},(e,t)=>e.isOpened===t.isOpened&&e.selectedFontFamily===t.selectedFontFamily&&e.hoveredFontFamily===t.hoveredFontFamily);import{Popover as nh}from"radix-ui";import mL from"clsx";import jd,{useEffect as pL}from"react";import{isArrowKey as uL,KEYS as Kn}from"@orangecatai/common";import{jsx as lL}from"react/jsx-runtime";var xn=({className:e,icon:t,size:o="1em"})=>lL("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 dL,jsx as Dw,jsxs as Rw}from"react/jsx-runtime";var cL=({label:e,open:t,openTrigger:o,children:n,className:r,showCollapsedIcon:i=!0})=>Rw(dL,{children:[Rw("div",{style:{cursor:"pointer",display:"flex",justifyContent:"space-between",alignItems:"center"},className:r,onClick:o,children:[e,i&&Dw(xn,{icon:t?_y:Md})]}),t&&Dw("div",{style:{display:"flex",flexDirection:"column"},children:n})]}),Nl=cL;import{jsx as Ti,jsxs as rh}from"react/jsx-runtime";var gL=Ie(!1);function hL({options:e,value:t,label:o,onChange:n,onClose:r,numberOfOptionsToAlwaysShow:i=e.length}){let a=ye(),{container:s}=Ke(),l=g=>{let E=e.find(y=>y.keyBinding===g.key.toLowerCase());if(!(g.metaKey||g.altKey||g.ctrlKey)&&E)n(E.value),g.preventDefault();else if(g.key===Kn.TAB){let y=e.findIndex(w=>w.value===t),x=g.shiftKey?(e.length+y-1)%e.length:(y+1)%e.length;n(e[x].value)}else if(uL(g.key)){let y=Wn().rtl,x=e.findIndex(w=>w.value===t);if(x!==-1){let w=e.length,v=x;switch(g.key){case(y?Kn.ARROW_LEFT:Kn.ARROW_RIGHT):v=(x+1)%w;break;case(y?Kn.ARROW_RIGHT:Kn.ARROW_LEFT):v=(w+x-1)%w;break;case Kn.ARROW_DOWN:{v=(x+(i??1))%w;break}case Kn.ARROW_UP:{v=(w+x-(i??1))%w;break}}n(e[v].value)}g.preventDefault()}else(g.key===Kn.ESCAPE||g.key===Kn.ENTER)&&(g.preventDefault(),r());g.nativeEvent.stopImmediatePropagation(),g.stopPropagation()},[c,m]=ne(gL),p=jd.useMemo(()=>e.slice(0,i),[e,i]),d=jd.useMemo(()=>e.slice(i),[e,i]);pL(()=>{p.some(g=>g.value===t)||m(!0)},[t,p,m]);let u=g=>Ti("div",{className:"picker-content",children:g.map((E,y)=>rh("button",{type:"button",className:mL("picker-option",{active:t===E.value}),onClick:x=>{n(E.value)},title:`${E.text} ${E.keyBinding&&`\u2014 ${E.keyBinding.toUpperCase()}`}`,"aria-label":E.text||"none","aria-keyshortcuts":E.keyBinding||void 0,ref:x=>{t===E.value&&setTimeout(()=>{x?.focus()},0)},children:[E.icon,E.keyBinding&&Ti("span",{className:"picker-keybinding",children:E.keyBinding})]},E.text))}),b=a.formFactor==="phone";return Ti(nh.Content,{side:b?"right":"bottom",align:"start",sideOffset:b?8:12,style:{zIndex:"var(--zIndex-ui-styles-popup)"},onKeyDown:l,collisionBoundary:s??void 0,children:rh("div",{className:"picker",role:"dialog","aria-modal":"true","aria-label":o,children:[u(p),d.length>0&&Ti(Nl,{label:h("labels.more_options"),open:c,openTrigger:()=>{m(g=>!g)},className:"picker-collapsible",children:u(d)})]})})}function ih({value:e,label:t,options:o,onChange:n,group:r="",numberOfOptionsToAlwaysShow:i}){let[a,s]=jd.useState(!1),l=jd.useRef(null);return Ti("div",{children:rh(nh.Root,{open:a,onOpenChange:c=>s(c),children:[Ti(nh.Trigger,{name:r,type:"button","aria-label":t,onClick:()=>s(!a),ref:l,className:a?"active":"",children:o.find(c=>c.value===e)?.icon}),a&&Ti(hL,{options:o,value:e,label:t,onChange:n,onClose:()=>{s(!1)},numberOfOptionsToAlwaysShow:i})]})})}import Nw,{useEffect as fL}from"react";import{jsx as ah,jsxs as Bw}from"react/jsx-runtime";var Fw=({updateData:e,app:t,testId:o})=>{let n=Nw.useRef(null),r=Nw.useRef(null),i=t.scene.getSelectedElements(t.state),a=!0,s=i.at(0),c=i.reduce((m,p)=>(m!=null&&m!==p.opacity&&(a=!1),m==null||m>p.opacity?p.opacity:m),s?.opacity??null)??t.state.currentItemOpacity;return fL(()=>{if(n.current&&r.current){let m=n.current,p=r.current,d=m.offsetWidth,u=15,b=c/100*(d-u)+u/2;p.style.left=`${b}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]),Bw("label",{className:"control-label",children:[h("labels.opacity"),Bw("div",{className:"range-wrapper",children:[ah("input",{style:{"--color-slider-track":a?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}),ah("div",{className:"value-bubble",ref:r,children:c!==0?c:null}),ah("div",{className:"zero-label",children:"0"})]})]})};import{Fragment as fh,jsx as me,jsxs as $t}from"react/jsx-runtime";var Yw=.1,Ga=e=>{let t=OL(e.editorInterface);return{stylesPanelMode:t,isCompact:t!=="full",isMobile:t==="mobile"}},Xt=(e,t,o,n=!1)=>{let r=mh(se(e,t,{includeBoundTextElement:n}));return e.map(i=>r.get(i.id)||i.id===t.editingTextElement?.id?o(i):i)},Ht=function(e,t,o,n,r){let i=t.state.editingTextElement,a=Uw(e),s=null;if(i&&(s=o(i)),!s)if(ze(a,t.state)){let c=t.scene.getSelectedElements(t.state),m=n===!0?c:c.filter(p=>n(p));s=LL(m,o)??(typeof r=="function"?r(!0):r)}else s=typeof r=="function"?r(!1):r;return s},HL=(e,t,o)=>RL(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}),uh=(e,t,o,n,r)=>{let i=new Set,a=Xt(e,t,s=>{if(no(s)){let l=n(s);i.add(l);let c=Et(s,{fontSize:l});return Bl(c,o.scene.getContainerElement(s),o.scene),c=HL(s,c,o.scene),c}return s},!0);return se(e,t,{includeBoundTextElement:!0}).forEach(s=>{no(s)&&DL(s,o.scene)}),{elements:a,appState:{...t,currentItemFontSize:i.size===1?[...i][0]:r??t.currentItemFontSize},captureUpdate:yt.IMMEDIATELY}},GL=z({name:"changeStrokeColor",label:"labels.stroke",trackEvent:!1,perform:(e,t,o)=>({...o?.currentItemStrokeColor&&{elements:Xt(e,t,n=>BL(n.type)?Et(n,{strokeColor:o.currentItemStrokeColor}):n,!0)},appState:{...t,...o},captureUpdate:o?.currentItemStrokeColor?yt.IMMEDIATELY:yt.EVENTUALLY}),PanelComponent:({elements:e,appState:t,updateData:o,app:n,data:r})=>{let{stylesPanelMode:i}=Ga(n);return $t(fh,{children:[i==="full"&&me("h3",{"aria-hidden":"true",children:h("labels.stroke")}),me(Al,{topPicks:TL,palette:vL,type:"elementStroke",label:h("labels.stroke"),color:Ht(e,n,a=>a.strokeColor,!0,a=>a?null:t.currentItemStrokeColor),onChange:a=>o({currentItemStrokeColor:a}),elements:e,appState:t,updateData:o})]})}}),UL=z({name:"changeBackgroundColor",label:"labels.changeBackground",trackEvent:!1,perform:(e,t,o,n)=>{if(!o?.currentItemBackgroundColor)return{appState:{...t,...o},captureUpdate:yt.EVENTUALLY};let r,i=n.scene.getSelectedElements(t);if(!AL(o.currentItemBackgroundColor)&&i.every(s=>Hw(s)&&_L(s.points))){let s=mh(i);r=e.map(l=>s.has(l.id)&&Hw(l)?Et(l,{backgroundColor:o.currentItemBackgroundColor,...zL(l,!0)}):l)}else r=Xt(e,t,s=>Et(s,{backgroundColor:o.currentItemBackgroundColor}));return{elements:r,appState:{...t,...o},captureUpdate:yt.IMMEDIATELY}},PanelComponent:({elements:e,appState:t,updateData:o,app:n,data:r})=>{let{stylesPanelMode:i}=Ga(n);return $t(fh,{children:[i==="full"&&me("h3",{"aria-hidden":"true",children:h("labels.background")}),me(Al,{topPicks:wL,palette:yL,type:"elementBackground",label:h("labels.background"),color:Ht(e,n,a=>a.backgroundColor,!0,a=>a?null:t.currentItemBackgroundColor),onChange:a=>o({currentItemBackgroundColor:a}),elements:e,appState:t,updateData:o})]})}}),WL=z({name:"changeFillStyle",label:"labels.fill",trackEvent:!1,perform:(e,t,o,n)=>(he("element","changeFillStyle",`${o} (${n.editorInterface.formFactor==="phone"?"mobile":"desktop"})`),{elements:Xt(e,t,r=>Et(r,{fillStyle:o})),appState:{...t,currentItemFillStyle:o},captureUpdate:yt.IMMEDIATELY}),PanelComponent:({elements:e,appState:t,updateData:o,app:n})=>{let r=se(e,t),i=r.length>0&&r.every(a=>a.fillStyle==="zigzag");return $t("fieldset",{children:[me("legend",{children:h("labels.fill")}),me("div",{className:"buttonList",children:me(Io,{type:"button",options:[{value:"hachure",text:`${i?h("labels.zigzag"):h("labels.hachure")} (${N("Alt-Click")})`,icon:i?TE:IE,active:i?!0:void 0,testId:"fill-hachure"},{value:"cross-hatch",text:h("labels.crossHatch"),icon:CE,testId:"fill-cross-hatch"},{value:"solid",text:h("labels.solid"),icon:kE,testId:"fill-solid"}],value:Ht(e,n,a=>a.fillStyle,a=>a.hasOwnProperty("fillStyle"),a=>a?null:t.currentItemFillStyle),onClick:(a,s)=>{let l=s.altKey&&a==="hachure"&&r.every(c=>c.fillStyle==="hachure")?"zigzag":a;o(l)}})})]})}}),YL=z({name:"changeStrokeWidth",label:"labels.strokeWidth",trackEvent:!1,perform:(e,t,o)=>({elements:Xt(e,t,n=>Et(n,{strokeWidth:o})),appState:{...t,currentItemStrokeWidth:o},captureUpdate:yt.IMMEDIATELY}),PanelComponent:({elements:e,appState:t,updateData:o,app:n,data:r})=>$t("fieldset",{children:[me("legend",{children:h("labels.strokeWidth")}),me("div",{className:"buttonList",children:me(Io,{group:"stroke-width",options:[{value:ch.thin,text:h("labels.thin"),icon:Tg,testId:"strokeWidth-thin"},{value:ch.bold,text:h("labels.bold"),icon:SE,testId:"strokeWidth-bold"},{value:ch.extraBold,text:h("labels.extraBold"),icon:ME,testId:"strokeWidth-extraBold"}],value:Ht(e,n,i=>i.strokeWidth,i=>i.hasOwnProperty("strokeWidth"),i=>i?null:t.currentItemStrokeWidth),onChange:i=>o(i)})})]})}),VL=z({name:"changeSloppiness",label:"labels.sloppiness",trackEvent:!1,perform:(e,t,o)=>({elements:Xt(e,t,n=>Et(n,{seed:SL(),roughness:o})),appState:{...t,currentItemRoughness:o},captureUpdate:yt.IMMEDIATELY}),PanelComponent:({elements:e,appState:t,updateData:o,app:n,data:r})=>$t("fieldset",{children:[me("legend",{children:h("labels.sloppiness")}),me("div",{className:"buttonList",children:me(Io,{group:"sloppiness",options:[{value:0,text:h("labels.architect"),icon:LE},{value:1,text:h("labels.artist"),icon:_E},{value:2,text:h("labels.cartoonist"),icon:DE}],value:Ht(e,n,i=>i.roughness,i=>i.hasOwnProperty("roughness"),i=>i?null:t.currentItemRoughness),onChange:i=>o(i)})})]})}),dre=z({name:"changeStrokeStyle",label:"labels.strokeStyle",trackEvent:!1,perform:(e,t,o)=>({elements:Xt(e,t,n=>Et(n,{strokeStyle:o})),appState:{...t,currentItemStrokeStyle:o},captureUpdate:yt.IMMEDIATELY}),PanelComponent:({elements:e,appState:t,updateData:o,app:n,data:r})=>$t("fieldset",{children:[me("legend",{children:h("labels.strokeStyle")}),me("div",{className:"buttonList",children:me(Io,{group:"strokeStyle",options:[{value:"solid",text:h("labels.strokeStyle_solid"),icon:Tg},{value:"dashed",text:h("labels.strokeStyle_dashed"),icon:PE},{value:"dotted",text:h("labels.strokeStyle_dotted"),icon:AE}],value:Ht(e,n,i=>i.strokeStyle,i=>i.hasOwnProperty("strokeStyle"),i=>i?null:t.currentItemStrokeStyle),onChange:i=>o(i)})})]})}),KL=z({name:"changeOpacity",label:"labels.opacity",trackEvent:!1,perform:(e,t,o)=>({elements:Xt(e,t,n=>Et(n,{opacity:o}),!0),appState:{...t,currentItemOpacity:o},captureUpdate:yt.IMMEDIATELY}),PanelComponent:({app:e,updateData:t})=>me(Fw,{updateData:t,app:e,testId:"opacity"})}),XL=z({name:"changeFontSize",label:"labels.fontSize",trackEvent:!1,perform:(e,t,o,n)=>uh(e,t,n,()=>(ph(o,"actionChangeFontSize: Expected a font size value"),o),o),PanelComponent:({elements:e,appState:t,updateData:o,app:n,data:r})=>{let{isCompact:i}=Ga(n);return $t("fieldset",{children:[me("legend",{children:h("labels.fontSize")}),me("div",{className:"buttonList",children:me(Io,{group:"font-size",options:[{value:Jd.sm,text:h("labels.small"),icon:$E,testId:"fontSize-small"},{value:Jd.md,text:h("labels.medium"),icon:ZE,testId:"fontSize-medium"},{value:Jd.lg,text:h("labels.large"),icon:jE,testId:"fontSize-large"},{value:Jd.xl,text:h("labels.veryLarge"),icon:qE,testId:"fontSize-veryLarge"}],value:Ht(e,n,a=>{if(no(a))return a.fontSize;let s=Pr(a,n.scene.getNonDeletedElementsMap());return s?s.fontSize:null},a=>no(a)||Pr(a,n.scene.getNonDeletedElementsMap())!==null,a=>a?null:t.currentItemFontSize||CL),onChange:a=>{kl(()=>o(a),i,!!t.editingTextElement,r?.onPreventClose)}})})]})}}),gh=z({name:"decreaseFontSize",label:"labels.decreaseFontSize",icon:yi,trackEvent:!1,perform:(e,t,o,n)=>uh(e,t,n,r=>Math.round(1/(1+Yw)*r.fontSize)),keyTest:e=>e[Ha.CTRL_OR_CMD]&&e.shiftKey&&(e.key===Ha.CHEVRON_LEFT||e.key===Ha.COMMA)}),hh=z({name:"increaseFontSize",label:"labels.increaseFontSize",icon:yi,trackEvent:!1,perform:(e,t,o,n)=>uh(e,t,n,r=>Math.round(r.fontSize*(1+Yw))),keyTest:e=>e[Ha.CTRL_OR_CMD]&&e.shiftKey&&(e.key===Ha.CHEVRON_RIGHT||e.key===Ha.PERIOD)}),$L=z({name:"changeFontFamily",label:"labels.fontFamily",trackEvent:!1,perform:(e,t,o,n)=>{let{cachedElements:r,resetAll:i,resetContainers:a,...s}=o;if(i)return{elements:Xt(e,t,g=>{let E=r?.get(g.id);return E?Et(g,{...E}):g},!0),appState:{...t,...s},captureUpdate:yt.NEVER};ph(o,"actionChangeFontFamily: value must be defined");let{currentItemFontFamily:l,currentHoveredFontFamily:c}=o,m=yt.EVENTUALLY,p,d=!1;if(l)p=l,m=yt.IMMEDIATELY;else if(c){p=c,m=yt.EVENTUALLY;let b=se(e,t,{includeBoundTextElement:!0}).filter(g=>no(g));if(b.length>200)d=!0;else{let g=0,E=0;for(;g<b.length&&E<5e3;){let y=b[g];E+=y?.originalText.length||0,g++}E>5e3&&(d=!0)}}let u={appState:{...t,...s},captureUpdate:m};if(p&&!d){let b=new Map,g=new Set,E=!1,y=Array.from(hr.loadedFontsCache.values()),x=Object.entries(kL).find(([T,C])=>C===p)?.[0];c&&x&&y.some(T=>T.startsWith(x))&&(E=!0),Object.assign(u,{elements:Xt(e,t,T=>{if(no(T)&&(T.fontFamily!==p||l)){let C=Et(T,{fontFamily:p,lineHeight:PL(p)}),M=r?.get(T.containerId||"")||{},k=n.scene.getContainerElement(T);return a&&k&&M&&n.scene.mutateElement(k,{...M}),E||(g=new Set([...g,...Array.from(C.originalText)])),b.set(C,k),C}return T},!0)});let w=`10px ${ML({fontFamily:p})}`,v=Array.from(g.values()).join();if(E||window.document.fonts.check(w,v))for(let[T,C]of b)Bl(T,C,n.scene);else window.document.fonts.load(w,v).then(T=>{for(let[C,M]of b){let k=n.scene.getElement(C.id),R=M?n.scene.getElement(M.id):null;k&&Bl(k,R,n.scene)}n.fonts.onLoaded(T)})}return u},PanelComponent:({elements:e,appState:t,app:o,updateData:n})=>{let r=lh(new Map),i=lh(null),[a,s]=EL({}),l=lh(!0),{stylesPanelMode:c,isCompact:m}=Ga(o),p=xL(()=>{let d=(u,b)=>Ht(u,o,g=>{if(no(g))return g.fontFamily;let E=Pr(g,b);return E?E.fontFamily:null},g=>no(g)||Pr(g,b)!==null,g=>g?null:t.currentItemFontFamily||IL);return a.openPopup==="fontFamily"&&t.openPopup==="fontFamily"?d(Array.from(r.current?.values()??[]),r.current):!a.openPopup&&t.openPopup!=="fontFamily"?d(e,o.scene.getNonDeletedElementsMap()):i.current},[a.openPopup,t,e,o]);return sh(()=>{i.current=p},[p]),sh(()=>{Object.keys(a).length&&(n(a),s({}))},[a]),sh(()=>(l.current=!1,()=>{l.current=!0}),[]),$t(fh,{children:[c==="full"&&me("legend",{children:h("labels.fontFamily")}),me(_w,{isOpened:t.openPopup==="fontFamily",selectedFontFamily:p,hoveredFontFamily:t.currentHoveredFontFamily,compactMode:c!=="full",onSelect:d=>{kl(()=>{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 b=o.scene.getElement(u.id);r.current.set(u.id,Et(b||u,{},!0))}else{let b=se(e,t,{includeBoundTextElement:!0});for(let g of b)r.current.set(g.id,Et(g,{},!0))}s({...a,openPopup:"fontFamily"})}else{let u={currentHoveredFontFamily:null,cachedElements:new Map(r.current),resetAll:!0};s({...u}),r.current.clear(),m&&t.editingTextElement&&Cl(null)}}})]})}}),ZL=z({name:"changeTextAlign",label:"Change text alignment",trackEvent:!1,perform:(e,t,o,n)=>({elements:Xt(e,t,r=>{if(no(r)){let i=Et(r,{textAlign:o});return Bl(i,n.scene.getContainerElement(r),n.scene),i}return r},!0),appState:{...t,currentItemTextAlign:o},captureUpdate:yt.IMMEDIATELY}),PanelComponent:({elements:e,appState:t,updateData:o,app:n,data:r})=>{let i=n.scene.getNonDeletedElementsMap(),{isCompact:a}=Ga(n);return $t("fieldset",{children:[me("legend",{children:h("labels.textAlign")}),me("div",{className:"buttonList",children:me(Io,{group:"text-align",options:[{value:"left",text:h("labels.left"),icon:QE,testId:"align-left"},{value:"center",text:h("labels.center"),icon:ey,testId:"align-horizontal-center"},{value:"right",text:h("labels.right"),icon:ty,testId:"align-right"}],value:Ht(e,n,s=>{if(no(s))return s.textAlign;let l=Pr(s,i);return l?l.textAlign:null},s=>no(s)||Pr(s,i)!==null,s=>s?null:t.currentItemTextAlign),onChange:s=>{kl(()=>o(s),a,!!t.editingTextElement,r?.onPreventClose)}})})]})}}),jL=z({name:"changeVerticalAlign",label:"Change vertical alignment",trackEvent:{category:"element"},perform:(e,t,o,n)=>({elements:Xt(e,t,r=>{if(no(r)){let i=Et(r,{verticalAlign:o});return Bl(i,n.scene.getContainerElement(r),n.scene),i}return r},!0),appState:{...t},captureUpdate:yt.IMMEDIATELY}),PanelComponent:({elements:e,appState:t,updateData:o,app:n,data:r})=>{let{isCompact:i}=Ga(n);return me("fieldset",{children:me("div",{className:"buttonList",children:me(Io,{group:"text-align",options:[{value:qd.TOP,text:h("labels.alignTop"),icon:me(oy,{theme:t.theme}),testId:"align-top"},{value:qd.MIDDLE,text:h("labels.centerVertically"),icon:me(ry,{theme:t.theme}),testId:"align-middle"},{value:qd.BOTTOM,text:h("labels.alignBottom"),icon:me(ny,{theme:t.theme}),testId:"align-bottom"}],value:Ht(e,n,a=>{if(no(a)&&a.containerId)return a.verticalAlign;let s=Pr(a,n.scene.getNonDeletedElementsMap());return s?s.verticalAlign:null},a=>no(a)||Pr(a,n.scene.getNonDeletedElementsMap())!==null,a=>a?null:qd.MIDDLE),onChange:a=>{kl(()=>o(a),i,!!t.editingTextElement,r?.onPreventClose)}})})})}}),mre=z({name:"changeRoundness",label:"Change edge roundness",trackEvent:!1,perform:(e,t,o)=>({elements:Xt(e,t,n=>Ww(n)?n:Et(n,{roundness:o==="round"?{type:NL(n.type)?Qd.ADAPTIVE_RADIUS:Qd.PROPORTIONAL_RADIUS}:null})),appState:{...t,currentItemRoundness:o},captureUpdate:yt.IMMEDIATELY}),PanelComponent:({elements:e,appState:t,updateData:o,app:n,renderAction:r})=>{let a=ia(Uw(e),t).some(s=>s.roundness?.type===Qd.LEGACY);return $t("fieldset",{children:[me("legend",{children:h("labels.edges")}),$t("div",{className:"buttonList",children:[me(Io,{group:"edges",options:[{value:"sharp",text:h("labels.sharp"),icon:RE},{value:"round",text:h("labels.round"),icon:NE}],value:Ht(e,n,s=>a?null:s.roundness?"round":"sharp",s=>!em(s)&&s.hasOwnProperty("roundness"),s=>s?null:t.currentItemRoundness),onChange:s=>o(s)}),r("togglePolygon")]})]})}}),Gw=e=>[{value:null,text:h("labels.arrowhead_none"),keyBinding:"q",icon:me(BE,{flip:e})},{value:"arrow",text:h("labels.arrowhead_arrow"),keyBinding:"w",icon:me(FE,{flip:e})},{value:"triangle",text:h("labels.arrowhead_triangle"),icon:me(GE,{flip:e}),keyBinding:"e"},{value:"triangle_outline",text:h("labels.arrowhead_triangle_outline"),icon:me(UE,{flip:e}),keyBinding:"r"},{value:"circle",text:h("labels.arrowhead_circle"),keyBinding:"a",icon:me(zE,{flip:e})},{value:"circle_outline",text:h("labels.arrowhead_circle_outline"),keyBinding:"s",icon:me(OE,{flip:e})},{value:"diamond",text:h("labels.arrowhead_diamond"),icon:me(WE,{flip:e}),keyBinding:"d"},{value:"diamond_outline",text:h("labels.arrowhead_diamond_outline"),icon:me(YE,{flip:e}),keyBinding:"f"},{value:"bar",text:h("labels.arrowhead_bar"),keyBinding:"z",icon:me(HE,{flip:e})},{value:"crowfoot_one",text:h("labels.arrowhead_crowfoot_one"),icon:me(KE,{flip:e}),keyBinding:"x"},{value:"crowfoot_many",text:h("labels.arrowhead_crowfoot_many"),icon:me(VE,{flip:e}),keyBinding:"c"},{value:"crowfoot_one_or_many",text:h("labels.arrowhead_crowfoot_one_or_many"),icon:me(XE,{flip:e}),keyBinding:"v"}],pre=z({name:"changeArrowhead",label:"Change arrowheads",trackEvent:!1,perform:(e,t,o)=>(ph(o,"actionChangeArrowhead: value must be defined"),{elements:Xt(e,t,n=>{if(dh(n)){let{position:r,type:i}=o;if(r==="start")return Et(n,{startArrowhead:i});if(r==="end")return Et(n,{endArrowhead:i})}return n}),appState:{...t,[o.position==="start"?"currentItemStartArrowhead":"currentItemEndArrowhead"]:o.type},captureUpdate:yt.IMMEDIATELY}),PanelComponent:({elements:e,appState:t,updateData:o,app:n})=>{let r=Wn().rtl;return $t("fieldset",{children:[me("legend",{children:h("labels.arrowheads")}),$t("div",{className:"iconSelectList buttonList",children:[me(ih,{label:"arrowhead_start",options:Gw(!r),value:Ht(e,n,i=>dh(i)&&aa(i.type)?i.startArrowhead:t.currentItemStartArrowhead,!0,i=>i?null:t.currentItemStartArrowhead),onChange:i=>o({position:"start",type:i}),numberOfOptionsToAlwaysShow:4}),me(ih,{label:"arrowhead_end",group:"arrowheads",options:Gw(!!r),value:Ht(e,n,i=>dh(i)&&aa(i.type)?i.endArrowhead:t.currentItemEndArrowhead,!0,i=>i?null:t.currentItemEndArrowhead),onChange:i=>o({position:"end",type:i}),numberOfOptionsToAlwaysShow:4})]})]})}}),qL=z({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})=>$t("div",{className:"selected-shape-actions",children:[r("changeArrowhead"),r("changeArrowType")]})}),ure=z({name:"changeArrowType",label:"Change arrow types",trackEvent:!1,perform:(e,t,o,n)=>{let r=Xt(e,t,s=>{if(!em(s))return s;let l=n.scene.getNonDeletedElementsMap(),c=Ii.getPointAtIndexGlobalCoordinates(s,0,l),m=Ii.getPointAtIndexGlobalCoordinates(s,-1,l),p=Et(s,{x:o===So.elbow?c[0]:s.x,y:o===So.elbow?c[1]:s.y,roundness:o===So.round?{type:Qd.PROPORTIONAL_RADIUS}:null,elbowed:o===So.elbow,angle:o===So.elbow?0:s.angle,points:o===So.elbow||s.elbowed?[Ii.pointFromAbsoluteCoords({...s,x:c[0],y:c[1],angle:0},c,l),Ii.pointFromAbsoluteCoords({...s,x:c[0],y:c[1],angle:0},m,l)]:s.points});if(Ww(p)){p.fixedSegments=null;let d=n.scene.getNonDeletedElementsMap();n.dismissLinearEditor();let u=Ii.getPointAtIndexGlobalCoordinates(p,0,d),b=Ii.getPointAtIndexGlobalCoordinates(p,-1,d),g=p.startBinding&&d.get(p.startBinding.elementId),E=p.endBinding&&d.get(p.endBinding.elementId),y=g&&p.startBinding?{...p.startBinding,...Ow(p,g,"start",d)}:null,x=E&&p.endBinding?{...p.endBinding,...Ow(p,E,"end",d)}:null;p={...p,startBinding:y,endBinding:x,...FL(p,d,{points:[u,b].map(w=>bL(w[0]-p.x,w[1]-p.y)),startBinding:y,endBinding:x,fixedSegments:null})}}else{let d=n.scene.getNonDeletedElementsMap();if(p.startBinding){let u=d.get(p.startBinding.elementId);u&&zw(p,u,t.bindMode==="inside"?"inside":"orbit","start",n.scene)}if(p.endBinding){let u=d.get(p.endBinding.elementId);u&&zw(p,u,t.bindMode==="inside"?"inside":"orbit","end",n.scene)}}return p}),i={...t,currentItemArrowType:o},a=t.selectedLinearElement?.elementId;if(a){let s=r.find(l=>l.id===a);s&&(i.selectedLinearElement=new Ii(s,mh(e)))}return{elements:r,appState:i,captureUpdate:yt.IMMEDIATELY}},PanelComponent:({elements:e,appState:t,updateData:o,app:n})=>$t("fieldset",{children:[me("legend",{children:h("labels.arrowtypes")}),me("div",{className:"buttonList",children:me(Io,{group:"arrowtypes",options:[{value:So.sharp,text:h("labels.arrowtype_sharp"),icon:Ma,testId:"sharp-arrow"},{value:So.round,text:h("labels.arrowtype_round"),icon:Aa,testId:"round-arrow"},{value:So.elbow,text:h("labels.arrowtype_elbowed"),icon:Pa,testId:"elbow-arrow"}],value:Ht(e,n,r=>em(r)?r.elbowed?So.elbow:r.roundness?So.round:So.sharp:null,r=>em(r),r=>r?null:t.currentItemArrowType),onChange:r=>o(r)})})]})});import{clamp as wh,roundToStep as r8}from"@orangecatai/math";import{DEFAULT_CANVAS_BACKGROUND_PICKS as i8,CURSOR_TYPE as Jw,MAX_ZOOM as Qw,MIN_ZOOM as ev,THEME as Fl,ZOOM_STEP as vh,updateActiveTool as Wa,CODES as yn,KEYS as $n,viewportCoordsToSceneCoords as a8}from"@orangecatai/common";import{getElementAbsoluteCoords as Zw,getNonDeletedElements as tv,getVisibleElements as s8}from"@orangecatai/element";import{newElementWith as l8}from"@orangecatai/element";import{getCommonBounds as ov}from"@orangecatai/element";import{CaptureUpdateAction as Ko}from"@orangecatai/element";import{useEffect as JL}from"react";import{jsx as e8}from"react/jsx-runtime";var Ua=()=>{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},bh=(e,t,o="bottom")=>{let n=e.getBoundingClientRect(),r=window.innerWidth,i=window.innerHeight,a=5,s=t.left+t.width/2-n.width/2;s<0?s=a:s+n.width>=r&&(s=r-n.width-a);let l;o==="bottom"?(l=t.top+t.height+a,l+n.height>=i&&(l=t.top-n.height-a)):(l=t.top-n.height-a,l<0&&(l=t.top+t.height+a)),Object.assign(e.style,{top:`${l}px`,left:`${s}px`})},QL=(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();bh(t,r)},ro=({children:e,label:t,long:o=!1,style:n,disabled:r})=>(JL(()=>()=>Ua().classList.remove("excalidraw-tooltip--visible"),[]),r?null:e8("div",{className:"excalidraw-tooltip-wrapper",onPointerEnter:i=>QL(i.currentTarget,Ua(),t,o),onPointerLeave:()=>Ua().classList.remove("excalidraw-tooltip--visible"),style:n,children:e}));import{CURSOR_TYPE as xh,MIME_TYPES as Eh,THEME as Kw}from"@orangecatai/common";var Xw='<svg viewBox="0 0 24 24" stroke-width="1" width="28" height="28" xmlns="http://www.w3.org/2000/svg">',t8='<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"/>',$w='<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"/>',o8=`data:${Eh.svg},${encodeURIComponent(`${Xw}${$w}</svg>`)}`,n8=`data:${Eh.svg},${encodeURIComponent(`${Xw}${t8}${$w}</svg>`)}`,fo=e=>{e&&(e.style.cursor="")},De=(e,t)=>{e&&(e.style.cursor=t)},En,Vw,yh=(e,t)=>{let n=()=>{let r=t===Kw.DARK;En=document.createElement("canvas"),En.theme=t,En.height=20,En.width=20;let i=En.getContext("2d");i.lineWidth=1,i.beginPath(),i.arc(En.width/2,En.height/2,5,0,2*Math.PI),i.fillStyle=r?"#000":"#fff",i.fill(),i.strokeStyle=r?"#fff":"#000",i.stroke(),Vw=En.toDataURL(Eh.svg)};(!En||En.theme!==t)&&n(),De(e,`url(${Vw}) ${20/2} ${20/2}, auto`)},bo=(e,t)=>{if(e)if(t.activeTool.type==="selection")fo(e);else if(Un(t))e.style.cursor=xh.GRAB;else if(oo(t))yh(e,t.theme);else if(t.activeTool.type==="laser"){let o=t.theme===Kw.LIGHT?o8:n8;e.style.cursor=`url(${o}), auto`}else["image","custom"].includes(t.activeTool.type)?t.activeTool.type!=="image"&&(e.style.cursor=xh.AUTO):e.style.cursor=xh.CROSSHAIR};var Xn=({viewportX:e,viewportY:t,nextZoom:o},n)=>{let r=e-n.offsetLeft,i=t-n.offsetTop,a=n.zoom.value,s=n.scrollX+(r-r/a),l=n.scrollY+(i-i/a),c=-(r-r/o),m=-(i-i/o);return{scrollX:s+c,scrollY:l+m,zoom:{value:o}}};import{jsx as Ya,jsxs as b8}from"react/jsx-runtime";var c8=z({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?Ko.IMMEDIATELY:Ko.EVENTUALLY}),PanelComponent:({elements:e,appState:t,updateData:o,appProps:n,data:r})=>Ya(Al,{palette:null,topPicks:i8,label:h("labels.canvasBackground"),type:"canvasBackground",color:t.viewBackgroundColor,onChange:i=>o({viewBackgroundColor:i}),"data-testid":"canvas-background-picker",elements:e,appState:t,updateData:o})}),Zn=z({name:"clearCanvas",label:"labels.clearCanvas",icon:Nt,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=>l8(r,{isDeleted:!0})),appState:{...fr(),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:Ko.IMMEDIATELY})}),tm=z({name:"zoomIn",label:"buttons.zoomIn",viewMode:!0,icon:ag,trackEvent:{category:"canvas"},perform:(e,t,o,n)=>({appState:{...t,...Xn({viewportX:t.width/2+t.offsetLeft,viewportY:t.height/2+t.offsetTop,nextZoom:ln(t.zoom.value+vh)},t),userToFollow:null},captureUpdate:Ko.EVENTUALLY}),PanelComponent:({updateData:e,appState:t})=>Ya(ee,{type:"button",className:"zoom-in-button zoom-button",icon:ag,title:`${h("buttons.zoomIn")} \u2014 ${N("CtrlOrCmd++")}`,"aria-label":h("buttons.zoomIn"),disabled:t.zoom.value>=Qw,onClick:()=>{e(null)}}),keyTest:e=>(e.code===yn.EQUAL||e.code===yn.NUM_ADD)&&(e[$n.CTRL_OR_CMD]||e.shiftKey)}),om=z({name:"zoomOut",label:"buttons.zoomOut",icon:sg,viewMode:!0,trackEvent:{category:"canvas"},perform:(e,t,o,n)=>({appState:{...t,...Xn({viewportX:t.width/2+t.offsetLeft,viewportY:t.height/2+t.offsetTop,nextZoom:ln(t.zoom.value-vh)},t),userToFollow:null},captureUpdate:Ko.EVENTUALLY}),PanelComponent:({updateData:e,appState:t})=>Ya(ee,{type:"button",className:"zoom-out-button zoom-button",icon:sg,title:`${h("buttons.zoomOut")} \u2014 ${N("CtrlOrCmd+-")}`,"aria-label":h("buttons.zoomOut"),disabled:t.zoom.value<=ev,onClick:()=>{e(null)}}),keyTest:e=>(e.code===yn.MINUS||e.code===yn.NUM_SUBTRACT)&&(e[$n.CTRL_OR_CMD]||e.shiftKey)}),nm=z({name:"resetZoom",label:"buttons.resetZoom",icon:aE,viewMode:!0,trackEvent:{category:"canvas"},perform:(e,t,o,n)=>({appState:{...t,...Xn({viewportX:t.width/2+t.offsetLeft,viewportY:t.height/2+t.offsetTop,nextZoom:ln(1)},t),userToFollow:null},captureUpdate:Ko.EVENTUALLY}),PanelComponent:({updateData:e,appState:t})=>Ya(ro,{label:h("buttons.resetZoom"),style:{height:"100%"},children:b8(ee,{type:"button",className:"reset-zoom-button zoom-button",title:h("buttons.resetZoom"),"aria-label":h("buttons.resetZoom"),onClick:()=>{e(null)},children:[(t.zoom.value*100).toFixed(0),"%"]})}),keyTest:e=>(e.code===yn.ZERO||e.code===yn.NUM_ZERO)&&(e[$n.CTRL_OR_CMD]||e.shiftKey)}),d8=(e,t,o=1)=>{let[n,r,i,a]=e,s=i-n,l=t.width/s,c=a-r,m=t.height/c,d=Math.min(l,m)*wh(o,.1,1);return Math.min(d,1)},m8=.8,p8=(e,t)=>e[0]<=t[2]&&e[2]>=t[0]&&e[1]<=t[3]&&e[3]>=t[1],u8=(e,t)=>[e[0]-t,e[1]-t,e[2]+t,e[3]+t],jw=(e,t)=>{let o=(e[0]+e[2])/2,n=(e[1]+e[3])/2;return Math.hypot(o-t.x,n-t.y)},qw=e=>[e[0],e[1],e[2],e[3]],g8=(e,t)=>{let o=tv(e);if(!o.length)return[];let n=s8(o),r=n.length?n:o,i=new Map(o.map(d=>[d.id,d])),a=a8({clientX:t.offsetLeft+t.width/2,clientY:t.offsetTop+t.height/2},t),s=r.reduce((d,u)=>{let b=qw(Zw(u,i));return d?jw(b,a)<jw(d.bounds,a)?{element:u,bounds:b}:d:{element:u,bounds:b}},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=u8(m,l);for(let u of r){if(c.has(u.id))continue;let b=qw(Zw(u,i));p8(b,d)&&(c.set(u.id,u),m=ov([...c.values()]),p=!0)}}return[...c.values()]},nv=({bounds:e,appState:t,canvasOffsets:o,fitToViewport:n=!1,viewportZoomFactor:r=1,minZoom:i=-1/0,maxZoom:a=1/0})=>{r=wh(r,ev,Qw);let[s,l,c,m]=e,p=(s+c)/2,d=(l+m)/2,u=o?.left??0,b=o?.top??0,g=o?.right??0,E=o?.bottom??0,y=t.width-u-g,x=t.height-b-E,w;if(n){let C=c-s,M=m-l;w=Math.min(y/C,x/M)*r}else w=d8(e,{width:y,height:x},r);let v=ln(wh(r8(w,vh,"floor"),i,a)),T=Ix({scenePoint:{x:p,y:d},viewportDimensions:{width:t.width,height:t.height},offsets:o,zoom:{value:v}});return{appState:{...t,scrollX:T.scrollX,scrollY:T.scrollY,zoom:{value:v}},captureUpdate:Ko.EVENTUALLY}},Va=({canvasOffsets:e,targetElements:t,appState:o,fitToViewport:n,viewportZoomFactor:r,minZoom:i,maxZoom:a})=>{let s=ov(tv(t));return nv({canvasOffsets:e,bounds:s,appState:o,fitToViewport:n,viewportZoomFactor:r,minZoom:i,maxZoom:a})},Zre=z({name:"zoomToFitSelectionInViewport",label:"labels.zoomToFitViewport",icon:Sa,trackEvent:{category:"canvas"},perform:(e,t,o,n)=>{let r=n.scene.getSelectedElements(t);return Va({targetElements:r.length?r:e,appState:{...t,userToFollow:null},fitToViewport:!1,canvasOffsets:n.getEditorUIOffsets()})},keyTest:e=>e.code===yn.TWO&&e.shiftKey&&!e.altKey&&!e[$n.CTRL_OR_CMD]}),jre=z({name:"zoomToFitSelection",label:"helpDialog.zoomToSelection",icon:Sa,trackEvent:{category:"canvas"},perform:(e,t,o,n)=>{let r=n.scene.getSelectedElements(t);return Va({targetElements:r.length?r:e,appState:{...t,userToFollow:null},fitToViewport:!0,canvasOffsets:n.getEditorUIOffsets()})},keyTest:e=>e.code===yn.THREE&&e.shiftKey&&!e.altKey&&!e[$n.CTRL_OR_CMD]}),h8=z({name:"zoomToFit",label:"helpDialog.zoomToFit",icon:Sa,viewMode:!0,trackEvent:{category:"canvas"},perform:(e,t,o,n)=>Va({targetElements:e,appState:{...t,userToFollow:null},fitToViewport:!1,canvasOffsets:n.getEditorUIOffsets()}),keyTest:e=>e.code===yn.ONE&&e.shiftKey&&!e.altKey&&!e[$n.CTRL_OR_CMD]}),f8=z({name:"scrollBackToContent",label:"buttons.scrollBackToContent",icon:Sa,viewMode:!0,trackEvent:{category:"canvas"},perform:(e,t,o,n)=>{let r=n.scene.getSelectedElements(t),i=r.length?r:g8(e,t);return i.length?Va({targetElements:i,appState:{...t,userToFollow:null},fitToViewport:!0,viewportZoomFactor:m8,canvasOffsets:n.getEditorUIOffsets()}):!1},PanelComponent:({updateData:e})=>Ya(ro,{label:h("buttons.scrollBackToContent"),style:{height:"100%"},children:Ya(ee,{type:"button",className:"scroll-back-to-content-button zoom-button",icon:Sa,title:h("buttons.scrollBackToContent"),"aria-label":h("buttons.scrollBackToContent"),onClick:()=>{e(null)}})})}),Ci=z({name:"toggleTheme",label:(e,t)=>t.theme===Fl.DARK?"buttons.lightMode":"buttons.darkMode",keywords:["toggle","dark","light","mode","theme"],icon:(e,t)=>e.theme===Fl.LIGHT?fl:bl,viewMode:!0,trackEvent:{category:"canvas"},perform:(e,t,o)=>({appState:{...t,theme:o||(t.theme===Fl.LIGHT?Fl.DARK:Fl.LIGHT)},captureUpdate:Ko.EVENTUALLY}),keyTest:e=>e.altKey&&e.shiftKey&&e.code===yn.D,predicate:(e,t,o,n)=>!!n.props.UIOptions.canvasActions.toggleTheme}),qre=z({name:"toggleEraserTool",label:"toolBar.eraser",trackEvent:{category:"toolbar"},perform:(e,t,o,n)=>{let r;return oo(t)?r=Wa(t,{...t.activeTool.lastActiveTool||{type:n.state.preferredSelectionTool.type},lastActiveToolBeforeEraser:null}):r=Wa(t,{type:"eraser",lastActiveToolBeforeEraser:t.activeTool}),{appState:{...t,selectedElementIds:{},selectedGroupIds:{},activeEmbeddable:null,activeTool:r},captureUpdate:Ko.IMMEDIATELY}},keyTest:e=>e.key===$n.E}),Jre=z({name:"toggleLassoTool",label:"toolBar.lasso",icon:br,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=Wa(t,{type:"lasso",fromSelection:!1}),De(n.interactiveCanvas,Jw.CROSSHAIR)):r=Wa(t,{type:"selection"}),{appState:{...t,selectedElementIds:{},selectedGroupIds:{},activeEmbeddable:null,activeTool:r},captureUpdate:Ko.NEVER}}}),rv=z({name:"toggleHandTool",label:"toolBar.hand",trackEvent:{category:"toolbar"},icon:Ta,viewMode:!1,perform:(e,t,o,n)=>{let r;return Un(t)?r=Wa(t,{...t.activeTool.lastActiveTool||{type:"selection"},lastActiveToolBeforeEraser:null}):(r=Wa(t,{type:"hand",lastActiveToolBeforeEraser:t.activeTool}),De(n.interactiveCanvas,Jw.GRAB)),{appState:{...t,selectedElementIds:{},selectedGroupIds:{},activeEmbeddable:null,activeTool:r},captureUpdate:Ko.IMMEDIATELY}},keyTest:e=>!e.altKey&&!e[$n.CTRL_OR_CMD]&&e.key===$n.H});import{updateActiveTool as iv}from"@orangecatai/common";import{CaptureUpdateAction as x8}from"@orangecatai/element";var E8=z({name:"setEmbeddableAsActiveTool",trackEvent:{category:"toolbar"},target:"Tool",label:"toolBar.embeddable",perform:(e,t,o,n)=>{let r=iv(t,{type:"embeddable"});return bo(n.canvas,{...t,activeTool:r}),{elements:e,appState:{...t,activeTool:iv(t,{type:"embeddable"})},captureUpdate:x8.EVENTUALLY}}});import{pointFrom as av}from"@orangecatai/math";import{bindOrUnbindBindingElement as y8}from"@orangecatai/element/binding";import{isValidPolygon as sv,LinearElementEditor as rm,newElementWith as Th}from"@orangecatai/element";import{isBindingElement as lv,isFreeDrawElement as cv,isLinearElement as dv,isLineElement as im}from"@orangecatai/element";import{KEYS as Ih,arrayToMap as w8,invariant as mv,shouldRotateWithDiscreteAngle as v8,updateActiveTool as pv}from"@orangecatai/common";import{isPathALoop as T8}from"@orangecatai/element";import{isInvisiblySmallElement as Ch}from"@orangecatai/element";import{CaptureUpdateAction as uv}from"@orangecatai/element";import{jsx as I8}from"react/jsx-runtime";var Zt=z({name:"finalize",label:"",trackEvent:!1,perform:(e,t,o,n)=>{let r=e,{interactiveCanvas:i,focusContainer:a,scene:s}=n,l=s.getNonDeletedElementsMap();if(o&&t.selectedLinearElement){let{event:d,sceneCoords:u}=o,b=rm.getElement(t.selectedLinearElement.elementId,l);mv(b,"Arrow element should exist if selectedLinearElement is set"),mv(u,"sceneCoords should be defined if actionFinalize is called with event");let g=rm.handlePointerUp(d,t.selectedLinearElement,t,n.scene);if(lv(b)&&!t.selectedLinearElement.segmentMidPointHoveredCoords){let E=!!t.newElement,x=(E||!t.selectedLinearElement.selectedPointsIndices?[b.points.length-1]:t.selectedLinearElement.selectedPointsIndices).reduce((w,v)=>(w.set(v,{point:rm.pointFromAbsoluteCoords(b,av(u.x-g.pointerOffset.x,u.y-g.pointerOffset.y),l)}),w),new Map)??new Map;y8(b,x,u.x-g.pointerOffset.x,u.y-g.pointerOffset.y,s,t,{newArrow:E,altKey:d.altKey,angleLocked:v8(d)})}else im(b)&&t.selectedLinearElement?.isEditing&&!t.newElement&&!sv(b.points)&&s.mutateElement(b,{polygon:!1});if(g!==t.selectedLinearElement){b&&Ch(b)&&(r=r.map(y=>y.id===b.id?Th(y,{isDeleted:!0}):y));let E=t.activeTool?.locked;return{elements:b.points.length<2||Ch(b)?e.map(y=>y.id===b.id?Th(y,{isDeleted:!0}):y):r,appState:{...t,cursorButton:"up",selectedLinearElement:E?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:uv.IMMEDIATELY}}}window.document.activeElement instanceof HTMLElement&&a();let c=null;if(t.multiElement)c=t.multiElement;else if(t.newElement?.type==="freedraw"||lv(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&&Ch(c)&&(r=r.map(d=>d.id===c?.id?Th(d,{isDeleted:!0}):d)),dv(c)||cv(c)){if(T8(c.points,t.zoom.value)&&(im(c)||cv(c))){let u=c.points,b=u[0],g=u.map((E,y)=>y===u.length-1?av(b[0],b[1]):E);im(c)?s.mutateElement(c,{points:g,polygon:!0}):s.mutateElement(c,{points:g})}im(c)&&!sv(c.points)&&s.mutateElement(c,{polygon:!1})}}(!t.activeTool.locked&&t.activeTool.type!=="freedraw"||!c)&&fo(i);let m;t.activeTool.type==="eraser"?m=pv(t,{...t.activeTool.lastActiveTool||{type:n.state.preferredSelectionTool.type},lastActiveToolBeforeEraser:null}):m=pv(t,{type:n.state.preferredSelectionTool.type});let p=c&&dv(c)?new rm(c,w8(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:uv.IMMEDIATELY}},keyTest:(e,t)=>e.key===Ih.ESCAPE&&(t.selectedLinearElement?.isEditing||!t.newElement&&t.multiElement===null)||(e.key===Ih.ESCAPE||e.key===Ih.ENTER)&&t.multiElement!==null,PanelComponent:({appState:e,updateData:t,data:o})=>I8(ee,{type:"button",icon:hE,title:h("buttons.done"),"aria-label":h("buttons.done"),onClick:t,visible:e.multiElement!=null,size:o?.size||"medium",style:{pointerEvents:"all"}})});import{KEYS as Za,DEFAULT_EXPORT_PADDING as g_,EXPORT_SCALES as h_,THEME as Mh}from"@orangecatai/common";import{getNonDeletedElements as f_}from"@orangecatai/element";import{CaptureUpdateAction as Zo}from"@orangecatai/element";import C8 from"clsx";import{jsx as gv,jsxs as k8}from"react/jsx-runtime";var zl=({children:e,checked:t,onChange:o,className:n})=>k8("div",{className:C8("Checkbox",n,{"is-checked":t}),onClick:r=>{o(!t,r),r.currentTarget.querySelector(".Checkbox-box").focus()},children:[gv("button",{type:"button",className:"Checkbox-box",role:"checkbox","aria-checked":t,children:wd}),gv("div",{className:"Checkbox-label",children:e})]});import{THEME as Ol}from"@orangecatai/common";import{jsx as Hl}from"react/jsx-runtime";var fv=e=>{let t=e.title||(e.value===Ol.DARK?h("buttons.lightMode"):h("buttons.darkMode"));return Hl(ee,{type:"icon",icon:e.value===Ol.LIGHT?hv.MOON:hv.SUN,title:t,"aria-label":t,onClick:()=>e.onChange(e.value===Ol.DARK?Ol.LIGHT:Ol.DARK),"data-testid":"toggle-dark-mode"})},hv={SUN:Hl("svg",{width:"512",height:"512",className:"rtl-mirror",viewBox:"0 0 512 512",children:Hl("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:Hl("svg",{width:"512",height:"512",className:"rtl-mirror",viewBox:"0 0 512 512",children:Hl("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 S8}from"react";import{focusNearestParent as M8,KEYS as P8}from"@orangecatai/common";import{jsx as bv,jsxs as A8}from"react/jsx-runtime";var xv=e=>{let{id:t}=Ke(),[o,n]=S8(e.value),r=a=>{e.ignoreFocus||M8(a.target);let s=a.target.value;s!==e.value&&e.onChange(s)},i=a=>{if(a.key===P8.ENTER){if(a.preventDefault(),a.nativeEvent.isComposing||a.keyCode===229)return;a.currentTarget.blur()}};return A8("div",{className:"ProjectName",children:[bv("label",{className:"ProjectName-label",htmlFor:"filename",children:`${e.label}:`}),bv("input",{type:"text",className:"TextInput",onBlur:r,onKeyDown:i,id:`${t}-filename`,value:o,onChange:a=>n(a.target.value)})]})};import{DEFAULT_EXPORT_PADDING as i_,DEFAULT_FILENAME as a_,IMAGE_MIME_TYPES as Nv,isFirefox as s_,MIME_TYPES as l_,cloneJSON as c_,SVG_DOCUMENT_PREAMBLE as d_}from"@orangecatai/common";import{getNonDeletedElements as m_}from"@orangecatai/element";import{isFrameLikeElement as p_}from"@orangecatai/element";import{getElementsOverlappingFrame as u_}from"@orangecatai/element";import{ALLOWED_PASTE_MIME_TYPES as U8,EXPORT_DATA_TYPES as Wl,MIME_TYPES as xo,arrayToMap as W8,isMemberOf as Y8,isPromiseLike as V8,EVENT as lm}from"@orangecatai/common";import{mutateElement as K8}from"@orangecatai/element";import{deepCopyElement as X8}from"@orangecatai/element";import{isFrameLikeElement as $8,isInitializedImageElement as Z8}from"@orangecatai/element";import{getContainingFrame as Pv}from"@orangecatai/element";import{pointFrom as Ar}from"@orangecatai/math";import{COLOR_PALETTE as yv,DEFAULT_CHART_COLOR_INDEX as L8,getAllColorsSpecificShade as _8,DEFAULT_FONT_FAMILY as D8,DEFAULT_FONT_SIZE as wv,VERTICAL_ALIGN as R8,randomId as vv,isDevEnv as Tv,FONT_SIZES as N8}from"@orangecatai/common";import{newTextElement as am,newLinearElement as Ul,newElement as Sh}from"@orangecatai/element";var Xo=32,Ge=12,Lr=256,Iv=50,ki="NOT_SPREADSHEET",Ka="VALID_SPREADSHEET",Gl=e=>{let t=/^([-+]?)[$€£¥₩]?([-+]?)([\d.,]+)[%]?$/.exec(e);return t?parseFloat(`${(t[1]||t[2])+t[3]}`.replace(/,/g,"")):null},kh=(e,t)=>e.slice(1).every(o=>Gl(o[t])!==null),Ev=e=>{let t=e[0].length;if(t>2)return{type:ki,reason:"More than 2 columns"};if(t===1){if(!kh(e,0))return{type:ki,reason:"Value is not numeric"};let l=Gl(e[0][0])===null,c=(l?e.slice(1):e).map(m=>Gl(m[0]));return c.length<2?{type:ki,reason:"Less than two rows"}:{type:Ka,spreadsheet:{title:l?e[0][0]:null,labels:null,values:c}}}let o=kh(e,0),n=kh(e,1);if(!o&&!n)return{type:ki,reason:"Value is not numeric"};let[r,i]=n?[0,1]:[1,0],a=Gl(e[0][i])===null,s=a?e.slice(1):e;return s.length<2?{type:ki,reason:"Less than 2 rows"}:{type:Ka,spreadsheet:{title:a?e[0][i]:null,labels:s.map(l=>l[r]),values:s.map(l=>Gl(l[i]))}}},B8=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},Cv=e=>{let t=e.trim().split(`
|
|
2
|
+
`).map(i=>i.trim().split(" "));if(t.length&&t[0].length!==2&&(t=e.trim().split(`
|
|
3
|
+
`).map(i=>i.trim().split(","))),t.length===0)return{type:ki,reason:"No values"};let o=t[0].length;if(!t.every(i=>i.length===o))return{type:ki,reason:"All rows don't have same number of columns"};let r=Ev(t);if(r.type!==Ka){let i=Ev(B8(t));if(i.type===Ka)return i}return r},sm=_8(L8),Mo={fillStyle:"hachure",fontFamily:D8,fontSize:wv,opacity:100,roughness:1,strokeColor:yv.black,roundness:null,strokeStyle:"solid",strokeWidth:1,verticalAlign:R8.MIDDLE,locked:!1},kv=e=>{let t=(Xo+Ge)*e.values.length+Ge,o=Lr+Ge*2;return{chartWidth:t,chartHeight:o}},F8=(e,t,o,n,r)=>e.labels?.map((i,a)=>am({groupIds:[n],backgroundColor:r,...Mo,text:i.length>8?`${i.slice(0,5)}...`:i,x:t+a*(Xo+Ge)+Ge*2,y:o+Ge/2,width:Xo,angle:5.87,fontSize:N8.sm,textAlign:"center",verticalAlign:"top"}))||[],z8=(e,t,o,n,r)=>{let i=am({groupIds:[n],backgroundColor:r,...Mo,x:t-Ge,y:o-Ge,text:"0",textAlign:"right"}),a=am({groupIds:[n],backgroundColor:r,...Mo,x:t-Ge,y:o-Lr-i.height/2,text:Math.max(...e.values).toLocaleString(),textAlign:"right"});return[i,a]},O8=(e,t,o,n,r)=>{let{chartWidth:i,chartHeight:a}=kv(e),s=Ul({backgroundColor:r,groupIds:[n],...Mo,type:"line",x:t,y:o,width:i,points:[Ar(0,0),Ar(i,0)]}),l=Ul({backgroundColor:r,groupIds:[n],...Mo,type:"line",x:t,y:o,height:a,points:[Ar(0,0),Ar(0,-a)]}),c=Ul({backgroundColor:r,groupIds:[n],...Mo,type:"line",x:t,y:o-Lr-Ge,strokeStyle:"dotted",width:i,opacity:Iv,points:[Ar(0,0),Ar(i,0)]});return[s,l,c]},Sv=(e,t,o,n,r,i)=>{let{chartWidth:a,chartHeight:s}=kv(e),l=e.title?am({backgroundColor:r,groupIds:[n],...Mo,text:e.title,x:t+a/2,y:o-Lr-Ge*2-wv,roundness:null,textAlign:"center"}):null,c=i?Sh({backgroundColor:r,groupIds:[n],...Mo,type:"rectangle",x:t,y:o-s,width:a,height:s,strokeColor:yv.black,fillStyle:"solid",opacity:6}):null;return[...c?[c]:[],...l?[l]:[],...F8(e,t,o,n,r),...z8(e,t,o,n,r),...O8(e,t,o,n,r)]},H8=(e,t,o)=>{let n=Math.max(...e.values),r=vv(),i=sm[Math.floor(Math.random()*sm.length)];return[...e.values.map((s,l)=>{let c=s/n*Lr;return Sh({backgroundColor:i,groupIds:[r],...Mo,type:"rectangle",x:t+l*(Xo+Ge)+Ge,y:o-c-Ge,width:Xo,height:c})}),...Sv(e,t,o,r,i,Tv())]},G8=(e,t,o)=>{let n=Math.max(...e.values),r=vv(),i=sm[Math.floor(Math.random()*sm.length)],a=0,s=[];for(let g of e.values){let E=a*(Xo+Ge),y=-(g/n)*Lr;s.push([E,y]),a++}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=Ul({backgroundColor:i,groupIds:[r],...Mo,type:"line",x:t+Ge+Xo/2,y:o-Ge,height:c-p,width:l-m,strokeWidth:2,points:s}),u=e.values.map((g,E)=>{let y=E*(Xo+Ge)+Ge/2,x=-(g/n)*Lr+Ge/2;return Sh({backgroundColor:i,groupIds:[r],...Mo,fillStyle:"solid",strokeWidth:2,type:"ellipse",x:t+y+Xo/2,y:o+x-Ge*2,width:Ge,height:Ge})}),b=e.values.map((g,E)=>{let y=E*(Xo+Ge)+Ge/2,x=g/n*Lr+Ge/2+Ge;return Ul({backgroundColor:i,groupIds:[r],...Mo,type:"line",x:t+y+Xo/2+Ge/2,y:o-x,height:x,strokeStyle:"dotted",opacity:Iv,points:[Ar(0,0),Ar(0,x)]})});return[...Sv(e,t,o,r,i,Tv()),d,...b,...u]},Mv=(e,t,o,n)=>e==="line"?G8(t,o,n):H8(t,o,n);var mae="clipboard"in navigator&&"readText"in navigator.clipboard,cm="clipboard"in navigator&&"writeText"in navigator.clipboard,Xa="clipboard"in navigator&&"write"in navigator.clipboard&&"ClipboardItem"in window&&"toBlob"in HTMLCanvasElement.prototype,j8=e=>!!([Wl.excalidraw,Wl.excalidrawClipboard,Wl.excalidrawClipboardWithAPI].includes(e?.type)&&Array.isArray(e.elements)),Av=({types:e,files:t})=>{!e&&!t&&console.warn("createPasteEvent: no types or files provided");let o=new ClipboardEvent(lm.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(i){throw new Error(i.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(i){throw new Error(i.message)}}}return o},q8=({elements:e,files:t})=>{let o=W8(e),n=new Set(e.filter(s=>$8(s))),r=!1,i=e.reduce((s,l)=>(Z8(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 a={type:Wl.excalidrawClipboard,elements:e.map(s=>{if(Pv(s,o)&&!n.has(Pv(s,o))){let l=X8(s);return K8(l,o,{frameId:null}),l}return s}),files:t?i:void 0};return JSON.stringify(a)},dm=async(e,t,o)=>{let n=q8({elements:e,files:t});await $o({[xo.excalidrawClipboard]:n,[xo.text]:n},o)},J8=e=>{let t=Cv(e);return t.type===Ka?{spreadsheet:t.spreadsheet}:null};function Lv(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(Lv(o));return t}var Q8=e=>{let t=e.value;try{let o=new DOMParser().parseFromString(t,xo.html),n=Lv(o.body);if(n.length)return{type:"mixedContent",value:n}}catch(o){console.error(`error in parseHTMLFromPaste: ${o.message}`)}return null},_v=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{[xo.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(Y8(U8,n))try{if(n===xo.text||n===xo.html)e[n]=await(await o.getType(n)).text();else if(Fx(n)){let r=await o.getType(n),i=Yx(r,n,void 0);e[n]=i}else throw new qu(`Unsupported clipboard type: ${n}`)}catch(r){console.warn(r instanceof qu?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},e_=async(e,t=!1)=>{try{let o=e.findByType(xo.html),n=!t&&o&&Q8(o);return n?n.value.every(r=>r.type==="text")?{type:"text",value:e.getData(xo.text)??n.value.map(r=>r.value).join(`
|
|
4
|
+
`).trim()}:n:{type:"text",value:(e.getData(xo.text)||"").trim()}}catch{return{type:"text",value:""}}},t_=function(e){return this.find(t=>t.type===e)||null},o_=function(e){return this.find(o=>o.type===e)?.value??null},n_=function(){return this.filter(e=>e.kind==="file")},Dv=e=>{let t;Rv(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},$a=async e=>{let t;Rv(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 i=await Wx(n);return r=await gl(r),{type:r.type,kind:"file",file:r,fileHandle:i}}}else if(n.kind==="string"){let{type:r}=n,i;return"clipboardData"in e&&e.clipboardData?i=e.clipboardData?.getData(r):i=await new Promise(a=>{n.getAsString(s=>a(s))}),{type:r,kind:"string",value:i}}return null}))).filter(n=>n!=null);return Object.assign(o,{findByType:t_,getData:o_,getFiles:n_})},mm=async(e,t=!1)=>{let o=await e_(e,t);if(o.type==="mixedContent")return{mixedContent:o.value};try{let n=!t&&J8(o.value);if(n)return n}catch(n){console.error(n)}try{let n=JSON.parse(o.value),r=n.type===Wl.excalidrawClipboardWithAPI;if(j8(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}},pm=async e=>{try{await navigator.clipboard.write([new ClipboardItem({[xo.png]:e})])}catch(t){if(V8(e))await navigator.clipboard.write([new ClipboardItem({[xo.png]:await e})]);else throw t}},$o=async(e,t)=>{e=e||"";let o=Object.entries(typeof e=="string"?{[xo.text]:e}:e);try{if(t){for(let[r,i]of o)if(t.clipboardData?.setData(r,i),t.clipboardData?.getData(r)!==i)throw new Error("Failed to setData on clipboardEvent");return}}catch(r){console.error(r)}let n=o.find(([r])=>r===xo.text);if(cm&&n)try{await navigator.clipboard.writeText(n[1]);return}catch(r){console.error(r)}if(n&&!r_(n[1]))throw new Error("Error copying to clipboard.")},r_=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(i){console.error(i)}return o.remove(),r},Rv=e=>e.type===lm.PASTE||e.type===lm.COPY||e.type===lm.CUT;var Si=(e,{selectedElementIds:t},o)=>{e=m_(e);let n=o&&ze(e,{selectedElementIds:t}),r=null,i=n?se(e,{selectedElementIds:t},{includeBoundTextElement:!0}):e;return n&&(i.length===1&&p_(i[0])?(r=i[0],i=u_(e,r)):i.length>1&&(i=se(e,{selectedElementIds:t},{includeBoundTextElement:!0,includeElementsInFrames:!0}))),{exportingFrame:r,exportedElements:c_(i)}},Mi=async(e,t,o,n,{exportBackground:r,exportPadding:i=i_,viewBackgroundColor:a,name:s=o.name||a_,fileHandle:l=null,exportingFrame:c=null})=>{if(t.length===0)throw new Error(h("alerts.cannotExportEmptyCanvas"));if(e==="svg"||e==="clipboard-svg"){let p=da(t,{exportBackground:r,exportWithDarkMode:o.exportWithDarkMode,viewBackgroundColor:a,exportPadding:i,exportScale:o.exportScale,exportEmbedScene:o.exportEmbedScene&&e==="svg"},n,{exportingFrame:c});if(e==="svg")return Ju(p.then(d=>new Blob([d_+d.outerHTML],{type:l_.svg})),{description:"Export to SVG",name:s,extension:o.exportEmbedScene?"excalidraw.svg":"svg",mimeTypes:[Nv.svg],fileHandle:l});if(e==="clipboard-svg"){let d=await p.then(u=>u.outerHTML);try{await $o(d)}catch{throw new Error(h("errors.copyToSystemClipboardFailed"))}return}}let m=ca(t,o,n,{exportBackground:r,viewBackgroundColor:a,exportPadding:i,exportingFrame:c});if(e==="png"){let p=fi(m);return o.exportEmbedScene&&(p=p.then(d=>import("./data/image-J2ZJZU4A.js").then(({encodePngMetadata:u})=>u({blob:d,metadata:cl(t,o,n,"local")})))),Ju(p,{description:"Export to PNG",name:s,extension:o.exportEmbedScene?"excalidraw.png":"png",mimeTypes:[Nv.png],fileHandle:l})}else if(e==="clipboard")try{let p=fi(m);await pm(p)}catch(p){throw console.warn(p),p.name==="CANVAS_POSSIBLY_TOO_BIG"?new Error(h("canvasError.canvasTooBig")):s_&&p.name==="TypeError"?new Error(`${h("alerts.couldNotCopyToClipboard")}
|
|
5
|
+
|
|
6
|
+
${h("hints.firefox_clipboard_write")}`):new Error(h("alerts.couldNotCopyToClipboard"))}else throw new Error("Unsupported export type")};var Bv=async(e,t,o,n)=>{let{exportBackground:r,viewBackgroundColor:i,fileHandle:a}=t,s=Nx(a);if(!a||!Bx(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}=Si(e,t,!1);return await Mi(s,l,t,o,{exportBackground:r,viewBackgroundColor:i,name:n,fileHandle:a,exportingFrame:c}),{fileHandle:a}};import{Fragment as b_,jsx as jn,jsxs as x_}from"react/jsx-runtime";var Ph=z({name:"changeProjectName",label:"labels.fileTitle",trackEvent:!1,perform:(e,t,o)=>({appState:{...t,name:o},captureUpdate:Zo.EVENTUALLY}),PanelComponent:({appState:e,updateData:t,appProps:o,data:n,app:r})=>jn(xv,{label:h("labels.fileTitle"),value:r.getName(),onChange:i=>t(i),ignoreFocus:n?.ignoreFocus??!1})}),Fv=z({name:"changeExportScale",label:"imageExportDialog.scale",trackEvent:{category:"export",action:"scale"},perform:(e,t,o)=>({appState:{...t,exportScale:o},captureUpdate:Zo.EVENTUALLY}),PanelComponent:({elements:e,appState:t,updateData:o})=>{let n=f_(e),i=ze(n,t)?se(n,t):n;return jn(b_,{children:h_.map(a=>{let[s,l]=Dx(i,g_,a),c=`${h("imageExportDialog.label.scale")} ${a}x (${s}x${l})`;return jn(ee,{size:"small",type:"radio",icon:`${a}x`,name:"export-canvas-scale",title:c,"aria-label":c,id:"export-canvas-scale",checked:a===t.exportScale,onChange:()=>o(a)},a)})})}}),Ah=z({name:"changeExportBackground",label:"imageExportDialog.label.withBackground",trackEvent:{category:"export",action:"toggleBackground"},perform:(e,t,o)=>({appState:{...t,exportBackground:o},captureUpdate:Zo.EVENTUALLY}),PanelComponent:({appState:e,updateData:t})=>jn(zl,{checked:e.exportBackground,onChange:o=>t(o),children:h("imageExportDialog.label.withBackground")})}),um=z({name:"changeExportEmbedScene",label:"imageExportDialog.tooltip.embedScene",trackEvent:{category:"export",action:"embedScene"},perform:(e,t,o)=>({appState:{...t,exportEmbedScene:o},captureUpdate:Zo.EVENTUALLY}),PanelComponent:({appState:e,updateData:t})=>x_(zl,{checked:e.exportEmbedScene,onChange:o=>t(o),children:[h("imageExportDialog.label.embedScene"),jn(ro,{label:h("imageExportDialog.tooltip.embedScene"),long:!0,children:jn("div",{className:"excalidraw-tooltip-icon",children:fE})})]})}),Pi=z({name:"saveToActiveFile",label:"buttons.save",icon:Ei,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:i}=md(t.fileHandle)?await Bv(e,t,n.files,n.getName()):await sd(e,t,n.files,n.getName());return{captureUpdate:Zo.EVENTUALLY,appState:{...t,fileHandle:i,toast:r?{message:i?.name?h("toast.fileSavedToFilename").replace("{filename}",`"${i.name}"`):h("toast.fileSaved")}:null}}}catch(i){return i?.name!=="AbortError"?console.error(i):console.warn(i),{captureUpdate:Zo.EVENTUALLY}}},keyTest:e=>e.key===Za.S&&e[Za.CTRL_OR_CMD]&&!e.shiftKey}),Yl=z({name:"saveFileToDisk",label:"exportDialog.disk_title",icon:Ei,viewMode:!0,trackEvent:{category:"export"},perform:async(e,t,o,n)=>{try{let{fileHandle:r}=await sd(e,{...t,fileHandle:null},n.files,n.getName());return{captureUpdate:Zo.EVENTUALLY,appState:{...t,openDialog:null,fileHandle:r,toast:{message:h("toast.fileSaved")}}}}catch(r){return r?.name!=="AbortError"?console.error(r):console.warn(r),{captureUpdate:Zo.EVENTUALLY}}},keyTest:e=>e.key===Za.S&&e.shiftKey&&e[Za.CTRL_OR_CMD],PanelComponent:({updateData:e})=>jn(ee,{type:"button",icon:pE,title:h("buttons.saveAs"),"aria-label":h("buttons.saveAs"),showAriaLabel:ye().formFactor==="phone",hidden:!la,onClick:()=>e(null),"data-testid":"save-as-button"})}),ja=z({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:i,files:a}=await Qu(t,e);return{elements:r,appState:i,files:a,captureUpdate:Zo.IMMEDIATELY}}catch(r){return r?.name==="AbortError"?(console.warn(r),!1):{elements:e,appState:{...t,errorMessage:r.message},files:n.files,captureUpdate:Zo.EVENTUALLY}}},keyTest:e=>e[Za.CTRL_OR_CMD]&&e.key===Za.O}),zv=z({name:"exportWithDarkMode",label:"imageExportDialog.label.darkMode",trackEvent:{category:"export",action:"toggleTheme"},perform:(e,t,o)=>({appState:{...t,exportWithDarkMode:o},captureUpdate:Zo.EVENTUALLY}),PanelComponent:({appState:e,updateData:t})=>jn("div",{style:{display:"flex",justifyContent:"flex-end",marginTop:"-45px",marginBottom:"10px"},children:jn(fv,{value:e.exportWithDarkMode?Mh.DARK:Mh.LIGHT,onChange:o=>{t(o===Mh.DARK)},title:h("imageExportDialog.label.darkMode")})})});import{DEFAULT_FONT_SIZE as E_,DEFAULT_FONT_FAMILY as y_,DEFAULT_TEXT_ALIGN as w_,CODES as Ov,KEYS as Hv,getLineHeight as v_}from"@orangecatai/common";import{newElementWith as gm}from"@orangecatai/element";import{hasBoundTextElement as T_,canApplyRoundnessTypeToElement as I_,getDefaultRoundnessTypeForElement as C_,isFrameLikeElement as k_,isArrowElement as S_,isExcalidrawElement as M_,isTextElement as Lh}from"@orangecatai/element";import{getBoundTextElement as P_,redrawTextBoundingBox as A_}from"@orangecatai/element";import{CaptureUpdateAction as _h}from"@orangecatai/element";var Gv="{}",Dh=z({name:"copyStyles",label:"labels.copyStyles",icon:kg,trackEvent:{category:"element"},perform:(e,t,o,n)=>{let r=[],i=e.find(a=>t.selectedElementIds[a.id]);if(r.push(i),i&&T_(i)){let a=P_(i,n.scene.getNonDeletedElementsMap());r.push(a)}return i&&(Gv=JSON.stringify(r)),{appState:{...t,toast:{message:h("toast.copyStyles")}},captureUpdate:_h.EVENTUALLY}},keyTest:e=>e[Hv.CTRL_OR_CMD]&&e.altKey&&e.code===Ov.C}),Rh=z({name:"pasteStyles",label:"labels.pasteStyles",icon:kg,trackEvent:{category:"element"},perform:(e,t,o,n)=>{let r=JSON.parse(Gv),i=r[0],a=r[1];if(!M_(i))return{elements:e,captureUpdate:_h.EVENTUALLY};let s=se(e,t,{includeBoundTextElement:!0}),l=s.map(c=>c.id);return{elements:e.map(c=>{if(l.includes(c.id)){let m=i;if(Lh(c)&&c.containerId&&(m=a),!m)return c;let p=gm(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?I_(m.roundness.type,c)?m.roundness:C_(c):null});if(Lh(p)){let d=m.fontSize||E_,u=m.fontFamily||y_;p=gm(p,{fontSize:d,fontFamily:u,textAlign:m.textAlign||w_,lineHeight:m.lineHeight||v_(u)});let b=null;p.containerId&&(b=s.find(g=>Lh(p)&&g.id===p.containerId)||null),A_(p,b,n.scene)}return p.type==="arrow"&&S_(m)&&(p=gm(p,{startArrowhead:m.startArrowhead,endArrowhead:m.endArrowhead})),k_(c)&&(p=gm(p,{roundness:null,backgroundColor:"transparent"})),p}return c}),captureUpdate:_h.IMMEDIATELY}},keyTest:e=>e[Hv.CTRL_OR_CMD]&&e.altKey&&e.code===Ov.V});import{KEYS as L_}from"@orangecatai/common";import{CaptureUpdateAction as __}from"@orangecatai/element";var Ai=z({name:"toggleShortcuts",label:"welcomeScreen.defaults.helpHint",icon:lE,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:__.EVENTUALLY}),keyTest:e=>e.key===L_.QUESTION_MARK});import{getNonDeletedElements as fm}from"@orangecatai/element";import{newElementWith as Yv}from"@orangecatai/element";import{isBoundToContainer as D_}from"@orangecatai/element";import{frameAndChildrenSelectedTogether as R_,getElementsInResizingFrame as N_,getFrameLikeElements as B_,getRootElements as F_,groupByFrameLikes as z_,removeElementsFromFrame as O_,replaceAllElementsInFrame as H_}from"@orangecatai/element";import{KEYS as bm,randomId as G_,arrayToMap as Nh}from"@orangecatai/common";import{getSelectedGroupIds as hm,selectGroup as U_,selectGroupsForSelectedElements as W_,getElementsInGroup as Uv,addToGroup as Y_,removeFromSelectedGroups as V_,isElementInGroup as Vv}from"@orangecatai/element";import{syncMovedIndices as K_}from"@orangecatai/element";import{CaptureUpdateAction as Vl}from"@orangecatai/element";import{jsx as qa}from"react/jsx-runtime";var X_=e=>{if(e.length>=2){let t=e[0].groupIds;for(let o of t)if(e.reduce((n,r)=>n&&Vv(r,o),!0))return!0}return!1},Wv=(e,t,o)=>{let n=o.scene.getSelectedElements({selectedElementIds:t.selectedElementIds,includeBoundTextElement:!0});return n.length>=2&&!X_(n)&&!R_(n)},Bh=z({name:"group",label:"labels.group",icon:e=>qa(wg,{theme:e.theme}),trackEvent:{category:"element"},perform:(e,t,o,n)=>{let r=F_(n.scene.getSelectedElements({selectedElementIds:t.selectedElementIds,includeBoundTextElement:!0}));if(r.length<2)return{appState:t,elements:e,captureUpdate:Vl.EVENTUALLY};let i=hm(t);if(i.length===1){let E=i[0],y=new Set(Uv(e,E).map(v=>v.id)),x=new Set(r.map(v=>v.id));if(new Set([...Array.from(y),...Array.from(x)]).size===y.size)return{appState:t,elements:e,captureUpdate:Vl.EVENTUALLY}}let a=[...e];new Set(r.map(E=>E.frameId)).size>1&&z_(r).forEach((y,x)=>{O_(y,n.scene.getNonDeletedElementsMap())});let l=G_(),c=Nh(r);a=a.map(E=>c.get(E.id)?Yv(E,{groupIds:Y_(E.groupIds,l,t.editingGroupId)}):E);let m=Uv(a,l),p=m[m.length-1],d=a.lastIndexOf(p),u=a.slice(d+1),b=a.slice(0,d).filter(E=>!Vv(E,l)),g=K_([...b,...m,...u],Nh(m));return{appState:{...t,...U_(l,{...t,selectedGroupIds:{}},fm(a))},elements:g,captureUpdate:Vl.IMMEDIATELY}},predicate:(e,t,o,n)=>Wv(e,t,n),keyTest:e=>!e.shiftKey&&e[bm.CTRL_OR_CMD]&&e.key===bm.G,PanelComponent:({elements:e,appState:t,updateData:o,app:n})=>qa(ee,{hidden:!Wv(e,t,n),type:"button",icon:qa(wg,{theme:t.theme}),onClick:()=>o(null),title:`${h("labels.group")} \u2014 ${N("CtrlOrCmd+G")}`,"aria-label":h("labels.group"),visible:ze(fm(e),t)})}),Fh=z({name:"ungroup",label:"labels.ungroup",icon:e=>qa(vg,{theme:e.theme}),trackEvent:{category:"element"},perform:(e,t,o,n)=>{let r=hm(t),i=Nh(e);if(r.length===0)return{appState:t,elements:e,captureUpdate:Vl.EVENTUALLY};let a=[...e],s=[];a=a.map(d=>{D_(d)&&s.push(d.id);let u=V_(d.groupIds,t.selectedGroupIds);return u.length===d.groupIds.length?d:Yv(d,{groupIds:u})});let l=W_(t,fm(a),t,null),c=n.scene.getSelectedElements(t),m=new Set(c.filter(d=>d.frameId).map(d=>d.frameId));return B_(e).filter(d=>m.has(d.id)).forEach(d=>{d&&(a=H_(a,N_(a,d,t,i),d,n))}),l.selectedElementIds=Object.entries(l.selectedElementIds).reduce((d,[u,b])=>(b&&!s.includes(u)&&(d[u]=!0),d),{}),{appState:{...t,...l},elements:a,captureUpdate:Vl.IMMEDIATELY}},keyTest:e=>e.shiftKey&&e[bm.CTRL_OR_CMD]&&e.key===bm.G.toUpperCase(),predicate:(e,t)=>hm(t).length>0,PanelComponent:({elements:e,appState:t,updateData:o})=>qa(ee,{type:"button",hidden:hm(t).length===0,icon:qa(vg,{theme:t.theme}),onClick:()=>o(null),title:`${h("labels.ungroup")} \u2014 ${N("CtrlOrCmd+Shift+G")}`,"aria-label":h("labels.ungroup"),visible:ze(fm(e),t)})});import eD from"clsx";import{CaptureUpdateAction as jv}from"@orangecatai/element";import{invariant as tD}from"@orangecatai/common";import{COLOR_CHARCOAL_BLACK as $_,COLOR_VOICE_CALL as Z_,COLOR_WHITE as Em,THEME as j_,UserIdleState as Kv}from"@orangecatai/common";var xm=(e,t,o,n,r,i,a)=>{e.beginPath(),e.moveTo(t+i,o),e.lineTo(t+n-i,o),e.quadraticCurveTo(t+n,o,t+n,o+i),e.lineTo(t+n,o+r-i),e.quadraticCurveTo(t+n,o+r,t+n-i,o+r),e.lineTo(t+i,o+r),e.quadraticCurveTo(t,o+r,t,o+r-i),e.lineTo(t,o+i),e.quadraticCurveTo(t,o,t+i,o),e.closePath(),e.fill(),a&&(e.strokeStyle=a),e.stroke()};function q_(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 Li=(e,t)=>`hsl(${Math.abs(q_(t?.id||e))%37*10}, 100%, 83%)`,Xv=e=>{let t=e?.trim()?.codePointAt(0);return(t?String.fromCodePoint(t):"?").toUpperCase()},$v=({context:e,renderConfig:t,appState:o,normalizedWidth:n,normalizedHeight:r})=>{for(let[i,a]of t.remotePointerViewportCoords){let{x:s,y:l}=a,c=o.collaborators.get(i);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=Li(i,c);e.save(),e.strokeStyle=u,e.fillStyle=u;let b=t.remotePointerUserStates.get(i),g=d||b===Kv.IDLE||b===Kv.AWAY;g&&(e.globalAlpha=.3),t.remotePointerButton.get(i)==="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 E=o.theme===j_.DARK?"#2f6330":Z_,y=c?.isSpeaking;y&&(e.fillStyle=E,e.strokeStyle=E,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=Em,e.strokeStyle=Em,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 x=t.remotePointerUsernames.get(i)||"";if(!d&&x){e.font="600 12px sans-serif";let w=(y?s+0:s)+m/2,v=(y?l+0:l)+p+2,T=5,C=3,M=e.measureText(x),k=M.actualBoundingBoxDescent+M.actualBoundingBoxAscent,R=Math.max(k,12),A=w-1,P=v-1,_=M.width+2+T*2+2,O=R+2+C*2+2;if(e.roundRect?(e.beginPath(),e.roundRect(A,P,_,O,8),e.fillStyle=u,e.fill(),e.strokeStyle=Em,e.stroke(),y&&(e.beginPath(),e.roundRect(A-2,P-2,_+4,O+4,8),e.strokeStyle=E,e.stroke())):xm(e,A,P,_,O,8,Em),e.fillStyle=$_,e.fillText(x,w+T+1,v+C+M.actualBoundingBoxAscent+Math.floor((R-k)/2)+2),y){e.fillStyle=E;let U=8,H=8,W=5;e.fillRect(A+_+H,P+(O/2-U/2),2,U),e.fillRect(A+_+H+W,P+(O/2-U*2/2),2,U*2),e.fillRect(A+_+H+W*2,P+(O/2-U/2),2,U)}}e.restore(),e.closePath()}};import J_ from"clsx";import{useState as Q_}from"react";import{jsx as Zv}from"react/jsx-runtime";var zh=({color:e,onClick:t,name:o,src:n,className:r})=>{let i=Xv(o),[a,s]=Q_(!1),l=!a&&n,c=l?void 0:{background:e};return Zv("div",{className:J_("Avatar",r),style:c,onClick:t,children:l?Zv("img",{className:"Avatar-img",src:n,alt:i,referrerPolicy:"no-referrer",onError:()=>s(!0)}):i})};import{jsx as wn,jsxs as ym}from"react/jsx-runtime";var oD=z({name:"goToCollaborator",label:"Go to a collaborator",viewMode:!0,trackEvent:{category:"collab"},perform:(e,t,o)=>(tD(o,"actionGoToCollaborator: collaborator should be defined when actionGoToCollaborator is called"),!o.socketId||t.userToFollow?.socketId===o.socketId||o.isCurrentUser?{appState:{...t,userToFollow:null},captureUpdate:jv.EVENTUALLY}:{appState:{...t,userToFollow:{socketId:o.socketId,username:o.username||""},openMenu:t.openMenu==="canvas"?null:t.openMenu},captureUpdate:jv.EVENTUALLY}),PanelComponent:({updateData:e,data:t,appState:o})=>{let{socketId:n,collaborator:r,withName:i,isBeingFollowed:a}=t,s=Li(n,r),l=eD({"is-followed":a,"is-current-user":r.isCurrentUser===!0,"is-speaking":r.isSpeaking,"is-in-call":r.isInCall,"is-muted":r.isMuted}),c=r.isInCall?r.isSpeaking?ym("div",{className:"UserList__collaborator-status-icon-speaking-indicator",title:h("userList.hint.isSpeaking"),children:[wn("div",{}),wn("div",{}),wn("div",{})]}):r.isMuted?wn("div",{className:"UserList__collaborator-status-icon-microphone-muted",title:h("userList.hint.micMuted"),children:Ey}):wn("div",{title:h("userList.hint.inCall"),children:xy}):null;return i?ym("div",{className:`dropdown-menu-item dropdown-menu-item-base UserList__collaborator ${l}`,style:{"--avatar-size":"1.5rem"},onClick:()=>e(r),children:[wn(zh,{color:s,onClick:()=>{},name:r.username||"",src:r.avatarUrl,className:l}),wn("div",{className:"UserList__collaborator-name",children:r.username}),ym("div",{className:"UserList__collaborator-status-icons","aria-hidden":!0,children:[a&&wn("div",{className:"UserList__collaborator-status-icon-is-followed",title:h("userList.hint.followStatus"),children:ka}),c]})]}):ym("div",{className:`UserList__collaborator UserList__collaborator--avatar-only ${l}`,children:[wn(zh,{color:s,onClick:()=>{e(r)},name:r.username||"",src:r.avatarUrl,className:l}),c&&wn("div",{className:"UserList__collaborator-status-icon",children:c})]})}});import{LIBRARY_DISABLED_TYPES as nD,randomId as rD}from"@orangecatai/common";import{deepCopyElement as iD}from"@orangecatai/element";import{CaptureUpdateAction as Oh}from"@orangecatai/element";var Hh=z({name:"addToLibrary",trackEvent:{category:"element"},perform:(e,t,o,n)=>{let r=n.scene.getSelectedElements({selectedElementIds:t.selectedElementIds,includeBoundTextElement:!0,includeElementsInFrames:!0});for(let i of nD)if(r.some(a=>a.type===i))return{captureUpdate:Oh.EVENTUALLY,appState:{...t,errorMessage:h(`errors.libraryElementTypeError.${i}`)}};return n.library.getLatestLibrary().then(i=>n.library.setLibrary([{id:rD(),status:"unpublished",elements:r.map(iD),created:Date.now()},...i])).then(()=>({captureUpdate:Oh.EVENTUALLY,appState:{...t,toast:{message:h("toast.addedToLibrary")}}})).catch(i=>({captureUpdate:Oh.EVENTUALLY,appState:{...t,errorMessage:i.message}}))},label:"labels.addToLibrary"});import{getNonDeletedElements as Ja}from"@orangecatai/element";import{isFrameLikeElement as aD}from"@orangecatai/element";import{updateFrameMembershipOfSelectedElements as sD}from"@orangecatai/element";import{KEYS as _r,arrayToMap as lD}from"@orangecatai/common";import{alignElements as cD}from"@orangecatai/element";import{CaptureUpdateAction as Qa}from"@orangecatai/element";import{getSelectedElementsByGroup as dD}from"@orangecatai/element";import{jsx as ts}from"react/jsx-runtime";var jt=(e,t)=>{let o=t.scene.getSelectedElements(e);return dD(o,t.scene.getNonDeletedElementsMap(),e).length>1&&!o.some(n=>aD(n))},es=(e,t,o,n)=>{let r=o.scene.getSelectedElements(t),i=cD(r,n,o.scene,t),a=lD(i);return sD(e.map(s=>a.get(s.id)||s),t,o)},mD=z({name:"alignTop",label:"labels.alignTop",icon:hg,trackEvent:{category:"element"},predicate:(e,t,o,n)=>jt(t,n),perform:(e,t,o,n)=>({appState:t,elements:es(e,t,n,{position:"start",axis:"y"}),captureUpdate:Qa.IMMEDIATELY}),keyTest:e=>e[_r.CTRL_OR_CMD]&&e.shiftKey&&e.key===_r.ARROW_UP,PanelComponent:({elements:e,appState:t,updateData:o,app:n})=>ts(ee,{hidden:!jt(t,n),type:"button",icon:hg,onClick:()=>o(null),title:`${h("labels.alignTop")} \u2014 ${N("CtrlOrCmd+Shift+Up")}`,"aria-label":h("labels.alignTop"),visible:ze(Ja(e),t)})}),pD=z({name:"alignBottom",label:"labels.alignBottom",icon:fg,trackEvent:{category:"element"},predicate:(e,t,o,n)=>jt(t,n),perform:(e,t,o,n)=>({appState:t,elements:es(e,t,n,{position:"end",axis:"y"}),captureUpdate:Qa.IMMEDIATELY}),keyTest:e=>e[_r.CTRL_OR_CMD]&&e.shiftKey&&e.key===_r.ARROW_DOWN,PanelComponent:({elements:e,appState:t,updateData:o,app:n})=>ts(ee,{hidden:!jt(t,n),type:"button",icon:fg,onClick:()=>o(null),title:`${h("labels.alignBottom")} \u2014 ${N("CtrlOrCmd+Shift+Down")}`,"aria-label":h("labels.alignBottom"),visible:ze(Ja(e),t)})}),uD=z({name:"alignLeft",label:"labels.alignLeft",icon:bg,trackEvent:{category:"element"},predicate:(e,t,o,n)=>jt(t,n),perform:(e,t,o,n)=>({appState:t,elements:es(e,t,n,{position:"start",axis:"x"}),captureUpdate:Qa.IMMEDIATELY}),keyTest:e=>e[_r.CTRL_OR_CMD]&&e.shiftKey&&e.key===_r.ARROW_LEFT,PanelComponent:({elements:e,appState:t,updateData:o,app:n})=>ts(ee,{hidden:!jt(t,n),type:"button",icon:bg,onClick:()=>o(null),title:`${h("labels.alignLeft")} \u2014 ${N("CtrlOrCmd+Shift+Left")}`,"aria-label":h("labels.alignLeft"),visible:ze(Ja(e),t)})}),gD=z({name:"alignRight",label:"labels.alignRight",icon:xg,trackEvent:{category:"element"},predicate:(e,t,o,n)=>jt(t,n),perform:(e,t,o,n)=>({appState:t,elements:es(e,t,n,{position:"end",axis:"x"}),captureUpdate:Qa.IMMEDIATELY}),keyTest:e=>e[_r.CTRL_OR_CMD]&&e.shiftKey&&e.key===_r.ARROW_RIGHT,PanelComponent:({elements:e,appState:t,updateData:o,app:n})=>ts(ee,{hidden:!jt(t,n),type:"button",icon:xg,onClick:()=>o(null),title:`${h("labels.alignRight")} \u2014 ${N("CtrlOrCmd+Shift+Right")}`,"aria-label":h("labels.alignRight"),visible:ze(Ja(e),t)})}),hD=z({name:"alignVerticallyCentered",label:"labels.centerVertically",icon:Eg,trackEvent:{category:"element"},predicate:(e,t,o,n)=>jt(t,n),perform:(e,t,o,n)=>({appState:t,elements:es(e,t,n,{position:"center",axis:"y"}),captureUpdate:Qa.IMMEDIATELY}),PanelComponent:({elements:e,appState:t,updateData:o,app:n})=>ts(ee,{hidden:!jt(t,n),type:"button",icon:Eg,onClick:()=>o(null),title:h("labels.centerVertically"),"aria-label":h("labels.centerVertically"),visible:ze(Ja(e),t)})}),fD=z({name:"alignHorizontallyCentered",label:"labels.centerHorizontally",icon:yg,trackEvent:{category:"element"},predicate:(e,t,o,n)=>jt(t,n),perform:(e,t,o,n)=>({appState:t,elements:es(e,t,n,{position:"center",axis:"x"}),captureUpdate:Qa.IMMEDIATELY}),PanelComponent:({elements:e,appState:t,updateData:o,app:n})=>ts(ee,{hidden:!jt(t,n),type:"button",icon:yg,onClick:()=>o(null),title:h("labels.centerHorizontally"),"aria-label":h("labels.centerHorizontally"),visible:ze(Ja(e),t)})});import{getNonDeletedElements as qv}from"@orangecatai/element";import{isFrameLikeElement as bD}from"@orangecatai/element";import{CODES as Jv,KEYS as Qv,arrayToMap as xD}from"@orangecatai/common";import{updateFrameMembershipOfSelectedElements as ED}from"@orangecatai/element";import{distributeElements as yD}from"@orangecatai/element";import{CaptureUpdateAction as e2}from"@orangecatai/element";import{getSelectedElementsByGroup as wD}from"@orangecatai/element";import{jsx as n2}from"react/jsx-runtime";var t2=(e,t)=>{let o=t.scene.getSelectedElements(e);return wD(o,t.scene.getNonDeletedElementsMap(),e).length>2&&!o.some(n=>bD(n))},o2=(e,t,o,n)=>{let r=o.scene.getSelectedElements(t),i=yD(r,o.scene.getNonDeletedElementsMap(),n,t,o.scene),a=xD(i);return ED(e.map(s=>a.get(s.id)||s),t,o)},vD=z({name:"distributeHorizontally",label:"labels.distributeHorizontally",trackEvent:{category:"element"},perform:(e,t,o,n)=>({appState:t,elements:o2(e,t,n,{space:"between",axis:"x"}),captureUpdate:e2.IMMEDIATELY}),keyTest:e=>!e[Qv.CTRL_OR_CMD]&&e.altKey&&e.code===Jv.H,PanelComponent:({elements:e,appState:t,updateData:o,app:n})=>n2(ee,{hidden:!t2(t,n),type:"button",icon:yE,onClick:()=>o(null),title:`${h("labels.distributeHorizontally")} \u2014 ${N("Alt+H")}`,"aria-label":h("labels.distributeHorizontally"),visible:ze(qv(e),t)})}),TD=z({name:"distributeVertically",label:"labels.distributeVertically",trackEvent:{category:"element"},perform:(e,t,o,n)=>({appState:t,elements:o2(e,t,n,{space:"between",axis:"y"}),captureUpdate:e2.IMMEDIATELY}),keyTest:e=>!e[Qv.CTRL_OR_CMD]&&e.altKey&&e.code===Jv.V,PanelComponent:({elements:e,appState:t,updateData:o,app:n})=>n2(ee,{hidden:!t2(t,n),type:"button",icon:wE,onClick:()=>o(null),title:`${h("labels.distributeVertically")} \u2014 ${N("Alt+V")}`,"aria-label":h("labels.distributeVertically"),visible:ze(qv(e),t)})});import{getNonDeletedElements as ID}from"@orangecatai/element";import{bindOrUnbindBindingElements as CD}from"@orangecatai/element";import{getCommonBoundingBox as r2}from"@orangecatai/element";import{newElementWith as kD}from"@orangecatai/element";import{deepCopyElement as SD}from"@orangecatai/element";import{resizeMultipleElements as MD}from"@orangecatai/element";import{isArrowElement as i2,isElbowArrow as PD}from"@orangecatai/element";import{updateFrameMembershipOfSelectedElements as a2}from"@orangecatai/element";import{CODES as s2,KEYS as AD,arrayToMap as LD}from"@orangecatai/common";import{CaptureUpdateAction as l2}from"@orangecatai/element";var Gh=z({name:"flipHorizontal",label:"labels.flipHorizontal",icon:Ty,trackEvent:{category:"element"},perform:(e,t,o,n)=>({elements:a2(c2(e,n.scene.getNonDeletedElementsMap(),t,"horizontal",n),t,n),appState:t,captureUpdate:l2.IMMEDIATELY}),keyTest:e=>e.shiftKey&&e.code===s2.H}),Uh=z({name:"flipVertical",label:"labels.flipVertical",icon:vy,trackEvent:{category:"element"},perform:(e,t,o,n)=>({elements:a2(c2(e,n.scene.getNonDeletedElementsMap(),t,"vertical",n),t,n),appState:t,captureUpdate:l2.IMMEDIATELY}),keyTest:e=>e.shiftKey&&e.code===s2.V&&!e[AD.CTRL_OR_CMD]}),c2=(e,t,o,n,r)=>{let i=se(ID(e),o,{includeBoundTextElement:!0,includeElementsInFrames:!0}),a=_D(i,t,n,r),s=LD(a);return e.map(l=>s.get(l.id)||l)},_D=(e,t,o,n)=>{if(e.every(d=>i2(d)&&(d.startBinding||d.endBinding)))return e.map(d=>{let u=d;return kD(u,{startArrowhead:u.endArrowhead,endArrowhead:u.startArrowhead})});let{midX:r,midY:i}=r2(e);MD(e,t,"nw",n.scene,new Map(Array.from(t.values()).map(d=>[d.id,SD(d)])),{flipByX:o==="horizontal",flipByY:o==="vertical",shouldResizeFromCenter:!0,shouldMaintainAspectRatio:!0}),CD(e.filter(i2),n.scene,n.state);let{elbowArrows:a,otherElements:s}=e.reduce((d,u)=>PD(u)?{...d,elbowArrows:d.elbowArrows.concat(u)}:{...d,otherElements:d.otherElements.concat(u)},{elbowArrows:[],otherElements:[]}),{midX:l,midY:c}=r2(e),[m,p]=[r-l,i-c];return s.forEach(d=>n.scene.mutateElement(d,{x:d.x+m,y:d.y+p})),a.forEach(d=>n.scene.mutateElement(d,{x:d.x+m,y:d.y+p})),e};import{isTextElement as DD}from"@orangecatai/element";import{getTextFromElements as RD}from"@orangecatai/element";import{CODES as ND,KEYS as d2,isFirefox as BD}from"@orangecatai/common";import{CaptureUpdateAction as Eo}from"@orangecatai/element";var os=z({name:"copy",label:"labels.copy",icon:hl,trackEvent:{category:"element"},perform:async(e,t,o,n)=>{let r=n.scene.getSelectedElements({selectedElementIds:t.selectedElementIds,includeBoundTextElement:!0,includeElementsInFrames:!0});try{await dm(r,n.files,o)}catch(i){return{captureUpdate:Eo.EVENTUALLY,appState:{...t,errorMessage:i.message}}}return{captureUpdate:Eo.EVENTUALLY}},keyTest:void 0}),Wh=z({name:"paste",label:"labels.paste",trackEvent:{category:"element"},perform:async(e,t,o,n)=>{let r;try{r=await _v()}catch(i){return i.name==="AbortError"||i.name==="NotAllowedError"?!1:(console.error(`actionPaste ${i.name}: ${i.message}`),BD?{captureUpdate:Eo.EVENTUALLY,appState:{...t,errorMessage:h("hints.firefox_clipboard_write")}}:{captureUpdate:Eo.EVENTUALLY,appState:{...t,errorMessage:h("errors.asyncPasteFailedOnRead")}})}try{n.pasteFromClipboard(Av({types:r}))}catch(i){return console.error(i),{captureUpdate:Eo.EVENTUALLY,appState:{...t,errorMessage:h("errors.asyncPasteFailedOnParse")}}}return{captureUpdate:Eo.EVENTUALLY}},keyTest:void 0}),wm=z({name:"cut",label:"labels.cut",icon:ay,trackEvent:{category:"element"},perform:(e,t,o,n)=>(os.perform(e,t,o,n),Il.perform(e,t,null,n)),keyTest:e=>e[d2.CTRL_OR_CMD]&&e.key===d2.X}),vm=z({name:"copyAsSvg",label:"labels.copyAsSvg",icon:Iy,trackEvent:{category:"element"},perform:async(e,t,o,n)=>{if(!n.canvas)return{captureUpdate:Eo.EVENTUALLY};let{exportedElements:r,exportingFrame:i}=Si(e,t,!0);try{await Mi("clipboard-svg",r,t,n.files,{...t,exportingFrame:i,name:n.getName()});let a=n.scene.getSelectedElements({selectedElementIds:t.selectedElementIds,includeBoundTextElement:!0,includeElementsInFrames:!0});return{appState:{toast:{message:h("toast.copyToClipboardAsSvg",{exportSelection:a.length?h("toast.selection"):h("toast.canvas"),exportColorScheme:t.exportWithDarkMode?h("buttons.darkMode"):h("buttons.lightMode")})}},captureUpdate:Eo.EVENTUALLY}}catch(a){return console.error(a),{appState:{errorMessage:a.message},captureUpdate:Eo.EVENTUALLY}}},predicate:e=>cm&&e.length>0,keywords:["svg","clipboard","copy"]}),Tm=z({name:"copyAsPng",label:"labels.copyAsPng",icon:Cy,trackEvent:{category:"element"},perform:async(e,t,o,n)=>{if(!n.canvas)return{captureUpdate:Eo.EVENTUALLY};let r=n.scene.getSelectedElements({selectedElementIds:t.selectedElementIds,includeBoundTextElement:!0,includeElementsInFrames:!0}),{exportedElements:i,exportingFrame:a}=Si(e,t,!0);try{return await Mi("clipboard",i,t,n.files,{...t,exportingFrame:a,name:n.getName()}),{appState:{...t,toast:{message:h("toast.copyToClipboardAsPng",{exportSelection:r.length?h("toast.selection"):h("toast.canvas"),exportColorScheme:t.exportWithDarkMode?h("buttons.darkMode"):h("buttons.lightMode")})}},captureUpdate:Eo.EVENTUALLY}}catch(s){return console.error(s),{appState:{...t,errorMessage:s.message},captureUpdate:Eo.EVENTUALLY}}},predicate:e=>Xa&&e.length>0,keyTest:e=>e.code===ND.C&&e.altKey&&e.shiftKey,keywords:["png","clipboard","copy"]}),Im=z({name:"copyText",label:"labels.copyText",trackEvent:{category:"element"},perform:(e,t,o,n)=>{let r=n.scene.getSelectedElements({selectedElementIds:t.selectedElementIds,includeBoundTextElement:!0});try{$o(RD(r))}catch{throw new Error(h("errors.copyToSystemClipboardFailed"))}return{captureUpdate:Eo.EVENTUALLY}},predicate:(e,t,o,n)=>cm&&n.scene.getSelectedElements({selectedElementIds:t.selectedElementIds,includeBoundTextElement:!0}).some(DD),keywords:["text","clipboard","copy"]});import{CODES as FD,KEYS as zD}from"@orangecatai/common";import{CaptureUpdateAction as OD}from"@orangecatai/element";var ns=z({name:"gridMode",icon:Ay,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:OD.EVENTUALLY}},checked:e=>e.gridModeEnabled,predicate:(e,t,o)=>o.gridModeEnabled===void 0,keyTest:e=>e[zD.CTRL_OR_CMD]&&e.code===FD.QUOTE});import{CODES as HD,KEYS as GD}from"@orangecatai/common";import{CaptureUpdateAction as UD}from"@orangecatai/element";var Dr=z({name:"zenMode",label:"buttons.zenMode",icon:Sy,viewMode:!0,trackEvent:{category:"canvas",predicate:e=>!e.zenModeEnabled},perform(e,t){return{appState:{...t,zenModeEnabled:!this.checked(t)},captureUpdate:UD.EVENTUALLY}},checked:e=>e.zenModeEnabled,predicate:(e,t,o,n)=>n.editorInterface.formFactor!=="phone"&&typeof o.zenModeEnabled>"u",keyTest:e=>!e[GD.CTRL_OR_CMD]&&e.altKey&&e.code===HD.Z});import{CODES as WD,KEYS as YD}from"@orangecatai/common";import{CaptureUpdateAction as VD}from"@orangecatai/element";var Kl=z({name:"objectsSnapMode",label:"buttons.objectsSnapMode",icon:ky,viewMode:!1,trackEvent:{category:"canvas",predicate:e=>!e.objectsSnapModeEnabled},perform(e,t){return{appState:{...t,objectsSnapModeEnabled:!this.checked(t),gridModeEnabled:!1},captureUpdate:VD.EVENTUALLY}},checked:e=>e.objectsSnapModeEnabled,predicate:(e,t,o)=>typeof o.objectsSnapModeEnabled>"u",keyTest:e=>!e[YD.CTRL_OR_CMD]&&e.altKey&&e.code===WD.S});import{CODES as KD,KEYS as XD}from"@orangecatai/common";import{CaptureUpdateAction as $D}from"@orangecatai/element";var Rr=z({name:"stats",label:"stats.fullTitle",icon:wy,viewMode:!0,trackEvent:{category:"menu"},keywords:["edit","attributes","customize"],perform(e,t){return{appState:{...t,stats:{...t.stats,open:!this.checked(t)}},captureUpdate:$D.EVENTUALLY}},checked:e=>e.stats.open,keyTest:e=>!e[XD.CTRL_OR_CMD]&&e.altKey&&e.code===KD.SLASH});import{BOUND_TEXT_PADDING as m2,ROUNDNESS as p2,TEXT_ALIGN as h2,VERTICAL_ALIGN as f2,arrayToMap as b2,getFontString as ZD}from"@orangecatai/common";import{getOriginalContainerHeightFromCache as jD,isBoundToContainer as u2,resetOriginalContainerCache as qD,updateOriginalContainerCache as JD}from"@orangecatai/element";import{computeBoundTextPosition as QD,computeContainerDimensionForBoundText as g2,getBoundTextElement as x2,redrawTextBoundingBox as E2}from"@orangecatai/element";import{hasBoundTextElement as e7,isArrowElement as t7,isTextBindableContainer as Yh,isTextElement as Xl,isUsingAdaptiveRadius as o7}from"@orangecatai/element";import{measureText as n7}from"@orangecatai/element";import{syncMovedIndices as y2}from"@orangecatai/element";import{newElement as r7}from"@orangecatai/element";import{CaptureUpdateAction as Vh}from"@orangecatai/element";var Kh=z({name:"unbindText",label:"labels.unbindText",trackEvent:{category:"element"},predicate:(e,t,o,n)=>n.scene.getSelectedElements(t).some(i=>e7(i)),perform:(e,t,o,n)=>{let r=n.scene.getSelectedElements(t),i=n.scene.getNonDeletedElementsMap();return r.forEach(a=>{let s=x2(a,i);if(s){let{width:l,height:c}=n7(s.originalText,ZD(s),s.lineHeight),m=jD(a.id);qD(a.id);let{x:p,y:d}=QD(a,s,i);n.scene.mutateElement(s,{containerId:null,width:l,height:c,text:s.originalText,x:p,y:d}),n.scene.mutateElement(a,{boundElements:a.boundElements?.filter(u=>u.id!==s.id),height:m||a.height})}}),{elements:e,appState:t,captureUpdate:Vh.IMMEDIATELY}}}),Xh=z({name:"bindText",label:"labels.bindText",trackEvent:{category:"element"},predicate:(e,t,o,n)=>{let r=n.scene.getSelectedElements(t);if(r.length===2){let i=Xl(r[0])||Xl(r[1]),a;if(Yh(r[0])?a=r[0]:Yh(r[1])&&(a=r[1]),i&&a&&x2(a,n.scene.getNonDeletedElementsMap())===null)return!0}return!1},perform:(e,t,o,n)=>{let r=n.scene.getSelectedElements(t),i,a;Xl(r[0])&&Yh(r[1])?(i=r[0],a=r[1]):(i=r[1],a=r[0]),n.scene.mutateElement(i,{containerId:a.id,verticalAlign:f2.MIDDLE,textAlign:h2.CENTER,autoResize:!0,angle:t7(a)?0:a?.angle??0}),n.scene.mutateElement(a,{boundElements:(a.boundElements||[]).concat({type:"text",id:i.id})});let s=a.height;return E2(i,a,n.scene),JD(a.id,s),{elements:i7(e,a,i),appState:{...t,selectedElementIds:{[a.id]:!0}},captureUpdate:Vh.IMMEDIATELY}}}),i7=(e,t,o)=>{let n=e.slice(),r=n.findIndex(a=>a.id===o.id);n.splice(r,1);let i=n.findIndex(a=>a.id===t.id);return n.splice(i+1,0,o),y2(n,b2([t,o])),n},a7=(e,t,o)=>{let n=e.slice(),r=n.findIndex(a=>a.id===t.id);n.splice(r,1);let i=n.findIndex(a=>a.id===o.id);return n.splice(i,0,t),y2(n,b2([t,o])),n},w2=z({name:"wrapTextInContainer",label:"labels.createContainerFromText",trackEvent:{category:"element"},predicate:(e,t,o,n)=>{let r=n.scene.getSelectedElements(t),i=r.some(a=>Xl(a)&&!u2(a));return r.length>0&&i},perform:(e,t,o,n)=>{let r=n.scene.getSelectedElements(t),i=e.slice(),a={};for(let s of r)if(Xl(s)&&!u2(s)){let l=r7({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:o7("rectangle")?p2.ADAPTIVE_RADIUS:p2.PROPORTIONAL_RADIUS}:null,opacity:100,locked:!1,x:s.x-m2,y:s.y-m2,width:g2(s.width,"rectangle"),height:g2(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);i.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:f2.MIDDLE,boundElements:null,textAlign:h2.CENTER,autoResize:!0}),E2(s,l,n.scene),i=a7([...i,l],l,s),a[l.id]=!0}return{elements:i,appState:{...t,selectedElementIds:a},captureUpdate:Vh.IMMEDIATELY}}});import{isEmbeddableElement as T7}from"@orangecatai/element";import{KEYS as L2}from"@orangecatai/common";import{CaptureUpdateAction as I7}from"@orangecatai/element";import{pointFrom as C2}from"@orangecatai/math";import s7 from"clsx";import{useCallback as v2,useEffect as T2,useLayoutEffect as l7,useRef as c7,useState as d7}from"react";import{EVENT as $h,HYPERLINK_TOOLTIP_DELAY as m7,KEYS as Cm}from"@orangecatai/common";import{getElementAbsoluteCoords as Qh}from"@orangecatai/element";import{hitElementBoundingBox as p7}from"@orangecatai/element";import{isElementLink as u7}from"@orangecatai/element";import{getEmbedLink as g7,embeddableURLValidator as h7}from"@orangecatai/element";import{sceneCoordsToViewportCoords as k2,viewportCoordsToSceneCoords as f7,wrapEvent as b7,isLocalLink as x7,normalizeLink as Zh}from"@orangecatai/common";import{isEmbeddableElement as jh}from"@orangecatai/element";import{jsx as rs,jsxs as I2}from"react/jsx-runtime";var ef=380,E7=42,qh=5,S2=85,y7=500,Jh=!1,km=new Map,M2=({element:e,scene:t,setAppState:o,onLinkOpen:n,setToast:r,updateEmbedValidationStatus:i})=>{let a=t.getNonDeletedElementsMap(),s=fn(),l=bn(),c=ye(),m=e.link||"",[p,d]=d7(m),u=c7(null),b=s.showHyperlinkPopup==="editor",g=v2(()=>{if(!u.current)return;let v=Zh(u.current.value)||null;if(!e.link&&v&&he("hyperlink","create"),jh(e)){if(s.activeEmbeddable?.element===e&&o({activeEmbeddable:null}),!v){t.mutateElement(e,{link:null}),i(e,!1);return}if(!h7(v,l.validateEmbeddable))v&&r({message:h("toast.unableToEmbed"),closable:!0}),e.link&&km.set(e.id,e.link),t.mutateElement(e,{link:v}),i(e,!1);else{let{width:T,height:C}=e,M=g7(v);M?.error instanceof URIError&&r({message:h("toast.unrecognizedLinkFormat"),closable:!0});let k=M?M.intrinsicSize.w/M.intrinsicSize.h:1,R=km.get(e.id)!==e.link;t.mutateElement(e,{...R?{width:M?.type==="video"?T>C?T:C*k:T,height:M?.type==="video"&&T>C?T/k:C}:{},link:v}),i(e,!0),km.has(e.id)&&km.delete(e.id)}}else t.mutateElement(e,{link:v})},[e,t,r,l.validateEmbeddable,s.activeEmbeddable,o,i]);l7(()=>()=>{g()},[g]),T2(()=>{b&&u?.current&&!(c.formFactor==="phone"||c.isTouchScreen)&&u.current.select()},[b,c.formFactor,c.isTouchScreen]),T2(()=>{let v=null,T=C=>{if(b)return;v&&clearTimeout(v),v7(e,a,s,C2(C.clientX,C.clientY))&&(v=window.setTimeout(()=>{o({showHyperlinkPopup:!1})},y7))};return window.addEventListener($h.POINTER_MOVE,T,!1),()=>{window.removeEventListener($h.POINTER_MOVE,T,!1),v&&clearTimeout(v)}},[s,e,b,o,a]);let E=v2(()=>{he("hyperlink","delete"),t.mutateElement(e,{link:null}),o({showHyperlinkPopup:!1})},[o,e,t]),y=()=>{he("hyperlink","edit","popup-ui"),o({showHyperlinkPopup:"editor"})},{x,y:w}=P2(e,s,a);return s.contextMenu||s.selectedElementsAreBeingDragged||s.resizingElement||s.isRotating||s.openMenu||s.viewModeEnabled?null:I2("div",{className:"excalidraw-hyperlinkContainer",style:{top:`${w}px`,left:`${x}px`,width:ef,padding:qh},children:[b?rs("input",{className:s7("excalidraw-hyperlinkContainer-input"),placeholder:h("labels.link.hint"),ref:u,value:p,onChange:v=>d(v.target.value),autoFocus:!0,onKeyDown:v=>{v.stopPropagation(),v[Cm.CTRL_OR_CMD]&&v.key===Cm.K&&v.preventDefault(),(v.key===Cm.ENTER||v.key===Cm.ESCAPE)&&(g(),o({showHyperlinkPopup:"info"}))}}):e.link?rs("a",{href:Zh(e.link||""),className:"excalidraw-hyperlinkContainer-link",target:x7(e.link)?"_self":"_blank",onClick:v=>{if(e.link&&n){let T=b7($h.EXCALIDRAW_LINK,v.nativeEvent);n({...e,link:Zh(e.link)},T),T.defaultPrevented&&v.preventDefault()}},rel:"noopener noreferrer",children:e.link}):rs("div",{className:"excalidraw-hyperlinkContainer-link",children:h("labels.link.empty")}),I2("div",{className:"excalidraw-hyperlinkContainer__buttons",children:[!b&&rs(ee,{type:"button",title:h("buttons.edit"),"aria-label":h("buttons.edit"),label:h("buttons.edit"),onClick:y,className:"excalidraw-hyperlinkContainer--edit",icon:un}),rs(ee,{type:"button",title:h("labels.linkToElement"),"aria-label":h("labels.linkToElement"),label:h("labels.linkToElement"),onClick:()=>{o({openDialog:{name:"elementLinkSelector",sourceElementId:e.id}})},icon:Pd}),m&&!jh(e)&&rs(ee,{type:"button",title:h("buttons.remove"),"aria-label":h("buttons.remove"),label:h("buttons.remove"),onClick:E,className:"excalidraw-hyperlinkContainer--remove",icon:Nt})]})]})},P2=(e,t,o)=>{let[n,r]=Qh(e,o),{x:i,y:a}=k2({sceneX:n+e.width/2,sceneY:r},t),s=i-t.offsetLeft-ef/2,l=a-t.offsetTop-S2;return{x:s,y:l}},tf=(e,t)=>{let o=se(e,t);return jh(o[0])?"labels.link.editEmbed":o[0]?.link?"labels.link.edit":"labels.link.create"},$l=null,A2=(e,t,o)=>{$l&&clearTimeout($l),$l=window.setTimeout(()=>w7(e,t,o),m7)},w7=(e,t,o)=>{if(!e.link)return;let n=Ua();n.classList.add("excalidraw-tooltip--visible"),n.style.maxWidth="20rem",n.textContent=u7(e.link)?h("labels.link.goToElement"):e.link;let[r,i,a,s]=Qh(e,o),[l,c,m,p]=Px([r,i,a,s],e.angle,t),d=k2({sceneX:l,sceneY:c},t);bh(n,{left:d.x,top:d.y,width:m,height:p},"top"),he("hyperlink","tooltip","link-icon"),Jh=!0},of=()=>{$l&&clearTimeout($l),Jh&&(Jh=!1,Ua().classList.remove("excalidraw-tooltip--visible"))},v7=(e,t,o,[n,r])=>{let{x:i,y:a}=f7({clientX:n,clientY:r},o),s=15/o.zoom.value;if(p7(C2(i,a),e,t))return!1;let[l,c,m]=Qh(e,t);if(i>=l&&i<=m&&a>=c-S2&&a<=c)return!1;let{x:p,y:d}=P2(e,o,t);return!(n>=p-s&&n<=p+ef+qh*2+s&&r>=d-s&&r<=d+s+qh*2+E7)};import{jsx as C7}from"react/jsx-runtime";var Zl=z({name:"hyperlink",label:(e,t)=>tf(e,t),icon:xl,perform:(e,t)=>t.showHyperlinkPopup==="editor"?!1:{elements:e,appState:{...t,showHyperlinkPopup:"editor",openMenu:null},captureUpdate:I7.IMMEDIATELY},trackEvent:{category:"hyperlink",action:"click"},keyTest:e=>e[L2.CTRL_OR_CMD]&&e.key===L2.K,predicate:(e,t)=>se(e,t).length===1,PanelComponent:({elements:e,appState:t,updateData:o})=>{let n=se(e,t);return C7(ee,{type:"button",icon:xl,"aria-label":h(tf(e,t)),title:`${T7(e[0])?h("labels.link.labelEmbed"):h("labels.link.label")} - ${N("CtrlOrCmd+K")}`,onClick:()=>o(null),selected:n.length===1&&!!n[0].link})}});import{KEYS as _2,arrayToMap as rf,randomId as k7}from"@orangecatai/common";import{elementsAreInSameGroup as S7,newElementWith as D2,selectGroupsFromGivenElements as R2}from"@orangecatai/element";import{CaptureUpdateAction as N2}from"@orangecatai/element";var nf=e=>e.every(t=>!t.locked),jl=z({name:"toggleElementLock",label:(e,t,o)=>{let n=o.scene.getSelectedElements({selectedElementIds:t.selectedElementIds,includeBoundTextElement:!1});return nf(n)?"labels.elementLock.lock":"labels.elementLock.unlock"},icon:(e,t)=>{let o=se(t,e);return nf(o)?ha:bi},trackEvent:{category:"element"},predicate:(e,t,o,n)=>{let r=n.scene.getSelectedElements(t);return r.length>0&&!r.some(i=>i.locked&&i.frameId)},perform:(e,t,o,n)=>{let r=n.scene.getSelectedElements({selectedElementIds:t.selectedElementIds,includeBoundTextElement:!0,includeElementsInFrames:!0});if(!r.length)return!1;let i=nf(r),a=rf(r),s=r.length>1&&S7(r),c=r.length===1||s?null:k7(),m={...t.lockedMultiSelections};if(i)m={...t.lockedMultiSelections,...c?{[c]:!0}:{}};else if(s){let y=r[0].groupIds.at(-1);delete m[y]}let p=e.map(y=>{if(!a.has(y.id))return y;let x=y.groupIds;return i?c&&(x=[...x,c]):x=x.filter(w=>!t.lockedMultiSelections[w]),D2(y,{locked:i,groupIds:x.length!==y.groupIds.length?x:y.groupIds})}),d=rf(p),u=i?{}:Object.fromEntries(r.map(y=>[y.id,!0])),b=r.map(y=>d.get(y.id)||y),g=i?{}:R2(b,t),E=i?c||(s?r[0].groupIds.at(-1):r[0].id):null;return{elements:p,appState:{...t,selectedElementIds:u,selectedGroupIds:g,selectedLinearElement:i?null:t.selectedLinearElement,lockedMultiSelections:m,activeLockedId:E},captureUpdate:N2.IMMEDIATELY}},keyTest:(e,t,o,n)=>e.key.toLocaleLowerCase()===_2.L&&e[_2.CTRL_OR_CMD]&&e.shiftKey&&n.scene.getSelectedElements({selectedElementIds:t.selectedElementIds,includeBoundTextElement:!1}).length>0}),B2=z({name:"unlockAllElements",trackEvent:{category:"canvas"},viewMode:!1,icon:bi,predicate:(e,t)=>se(e,t).length===0&&e.some(n=>n.locked),perform:(e,t)=>{let o=e.filter(a=>a.locked),n=e.map(a=>{if(a.locked){let s=a.groupIds.filter(l=>!t.lockedMultiSelections[l]);return D2(a,{locked:!1,groupIds:a.groupIds.length!==s.length?s:a.groupIds})}return a}),r=rf(n),i=o.map(a=>r.get(a.id)||a);return{elements:n,appState:{...t,selectedElementIds:Object.fromEntries(o.map(a=>[a.id,!0])),selectedGroupIds:R2(i,t),lockedMultiSelections:{},activeLockedId:null},captureUpdate:N2.IMMEDIATELY}},label:"labels.elementLock.unlockAll"});import{isElbowArrow as pF,isLinearElement as uF,isLineElement as Is}from"@orangecatai/element";import{arrayToMap as gF,invariant as u0}from"@orangecatai/common";import{toggleLinePolygonState as hF,CaptureUpdateAction as a3}from"@orangecatai/element";import RI from"clsx";import oB from"fuzzy";import{useEffect as tp,useRef as NI,useMemo as nB,useState as ep}from"react";import{DEFAULT_SIDEBAR as LI,EVENT as np,KEYS as Jo,capitalizeString as rB,isWritableElement as iB}from"@orangecatai/common";import{CaptureUpdateAction as cR}from"@orangecatai/element";import{useEffect as Ql,useMemo as F2,useRef as cf,useState as M7}from"react";import{getLinearElementSubType as ss,updateElbowArrowPoints as P7}from"@orangecatai/element";import{pointFrom as Mm,pointRotateRads as A7}from"@orangecatai/math";import{hasBoundTextElement as L7,isArrowBoundToElement as _7,isArrowElement as D7,isElbowArrow as R7,isLinearElement as uf,isUsingAdaptiveRadius as N7}from"@orangecatai/element";import{getCommonBoundingBox as B7,getElementAbsoluteCoords as F7}from"@orangecatai/element";import{getBoundTextElement as U2,getBoundTextMaxHeight as z7,getBoundTextMaxWidth as O7,redrawTextBoundingBox as H7}from"@orangecatai/element";import{wrapText as G7}from"@orangecatai/element";import{assertNever as U7,CLASSES as W7,getFontString as af,isProdEnv as Y7,mapFind as V7,reduceToCommonValue as K7,updateActiveTool as z2}from"@orangecatai/common";import{measureText as O2}from"@orangecatai/element";import{LinearElementEditor as X7}from"@orangecatai/element";import{newArrowElement as sf,newElement as $7,newLinearElement as Z7}from"@orangecatai/element";import{ShapeCache as j7}from"@orangecatai/element";import{updateBindings as q7}from"@orangecatai/element";import{jsx as pf}from"react/jsx-runtime";var J7=8,Q7=10,ql=["rectangle","diamond","ellipse"],Jl=["line","sharpArrow","curvedArrow","elbowArrow"],eR=new Set(ql),tR=new Set(Jl),ls=e=>eR.has(e),Am=e=>e==="arrow"||tR.has(e),jo=Ie(null),ec=new Map,tc=new Map,oR=({app:e})=>{let t=e.scene.getSelectedElements(e.state),o=cf(null);return Ql(()=>{if(t.length===0){e.updateEditorAtom(jo,null);return}let n=cs(t);n&&!o.current?o.current=n:(o.current&&!n||o.current&&n!==o.current)&&(e.updateEditorAtom(jo,null),o.current=null)},[t,e]),Ql(()=>()=>{ec.clear(),tc.clear()},[]),pf(nR,{app:e,elements:t})},nR=({app:e,elements:t})=>{let o=cs(t),n=F2(()=>o==="generic"?Y2(t):[],[o,t]),r=F2(()=>o==="linear"?mf(t):[],[o,t]),i=o==="generic"?n.every(p=>p.type===n[0].type):o==="linear"?r.every(p=>ss(p)===ss(r[0])):!1,[a,s]=M7({x:0,y:0}),l=cf(""),c=cf(null);Ql(()=>{let p=[...n,...r].sort((E,y)=>E.id.localeCompare(y.id)),d=`
|
|
7
|
+
${e.state.scrollX}${e.state.scrollY}${e.state.offsetTop}${e.state.offsetLeft}${e.state.zoom.value}${p.map(E=>E.id).join(",")}`;if(d===l.current)return;l.current=d;let u;if(p.length===1){let[E,,,y,x,w]=F7(p[0],e.scene.getNonDeletedElementsMap());u=A7(Mm(E,y),Mm(x,w),p[0].angle)}else{let{minX:E,maxY:y}=B7(p);u=Mm(E,y)}let{x:b,y:g}=K2({sceneX:u[0],sceneY:u[1]},e.state);s({x:b,y:g})},[n,r,e.scene,e.state]),Ql(()=>{for(let p of r){let d=df(p.id,lR(p));tc.has(d)||tc.set(d,p)}},[r]),Ql(()=>{for(let p of n)if(!ec.has(p.id)){let d=U2(p,e.scene.getNonDeletedElementsMap());d&&ec.set(p.id,{fontSize:d.fontSize})}},[n,e.scene]);let m=o==="linear"?[["line",Ea],["sharpArrow",Ma],["curvedArrow",Aa],["elbowArrow",Pa]]:o==="generic"?[["rectangle",fa],["diamond",ba],["ellipse",xa]]:[];return pf("div",{ref:c,tabIndex:-1,style:{position:"absolute",top:`${a.y+(Q7+8)*e.state.zoom.value-e.state.offsetTop}px`,left:`${a.x-e.state.offsetLeft-J7}px`,zIndex:2},className:W7.CONVERT_ELEMENT_TYPE_POPUP,children:m.map(([p,d])=>{let u=i&&(o==="generic"&&n[0].type===p||o==="linear"&&ss(r[0])===p);return pf(ee,{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&&he("convertElementType",p,"ui"),gf(e,{conversionType:o,nextType:p}),c.current?.focus()}},`${t[0].id}${t[0].version}_${p}`)})})},rR=(e,t,o)=>{let n=O7(e,t),r=z7(e,t),i=G7(t.text,af(t),n),a=O2(i,af(t),t.lineHeight),s=t.fontSize;for(;(a.width>n||a.height>r)&&s>0;){s-=1;let l={...t,fontSize:s};a=O2(t.text,af(l),t.lineHeight)}Lm(t,o.getNonDeletedElementsMap(),{fontSize:s,width:a.width,height:a.height}),H7(t,e,o)},gf=(e,{conversionType:t,nextType:o,direction:n="right"})=>{if(!t)return!1;let r=e.scene.getSelectedElements(e.state),i=r.reduce((s,l)=>({...s,[l.id]:!0}),{}),a=n==="right"?1:-1;if(t==="generic"){let s=Y2(r),c=s.every(m=>m.type===s[0].type)?ql.indexOf(s[0].type):-1;if(o=o??ql[(c+ql.length+a)%ql.length],o&&ls(o)){let m={};for(let d of s){let u=G2(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=U2(d,e.scene.getNonDeletedElementsMap());u&&(ec.get(d.id)&&Lm(u,e.scene.getNonDeletedElementsMap(),{fontSize:ec.get(d.id)?.fontSize??u.fontSize}),rR(d,u,e.scene))}e.setState(d=>({selectedElementIds:i,activeTool:z2(d,{type:"selection"})}))}}if(t==="linear"){let s=mf(r);if(!o){let c=K7(s,ss),m=c?Jl.indexOf(c):-1;o=Jl[(m+Jl.length+a)%Jl.length]}if(Am(o)){let c=[],m=e.scene.getElementsMapIncludingDeleted();for(let p of s){let d=tc.get(df(p.id,o));if(d&&ss(d)===o)m.set(d.id,d),c.push(d);else{let u=G2(p,o,e);m.set(u.id,u),c.push(u)}}e.scene.replaceAllElements(m);for(let p of c)if(uf(p))if(R7(p)){let d=iR(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 b=P7(p,e.scene.getNonDeletedElementsMap(),{points:d,fixedSegments:u});Lm(p,e.scene.getNonDeletedElementsMap(),{...b,endArrowhead:"arrow"})}else{let d=V7(["line","sharpArrow","curvedArrow"],u=>tc.get(df(p.id,u)));if(d){let u=d.points;e.scene.mutateElement(p,{points:u})}}}let l=mf(e.scene.getSelectedElements(e.state));e.setState(c=>({selectedElementIds:i,selectedLinearElement:l.length===1?new X7(l[0],e.scene.getNonDeletedElementsMap()):null,activeTool:z2(c,{type:"selection"})}))}return!0},cs=e=>{if(e.length===0)return null;let t=!1;for(let o of e){if(ls(o.type))return"generic";W2(o)&&(t=!0)}return t?"linear":null},W2=e=>uf(e)&&(!D7(e)||!_7(e)&&!L7(e)),df=(e,t)=>`${e}:${t}`,Y2=e=>e.filter(t=>ls(t.type)),mf=e=>e.filter(t=>W2(t)),Sm=20,is=(e,t)=>e[0]===t[0],lf=(e,t)=>e[1]===t[1],H2=(e,t)=>is(e,t)?Math.abs(e[1]-t[1]):Math.abs(e[0]-t[0]),iR=e=>{let t=[e.points[0]],o=aR(e.points);for(let i=1;i<o.length;++i){let a=t[t.length-1],s=[...o[i]];Math.abs(s[0]-a[0])<Sm?s[0]=a[0]:Math.abs(s[1]-a[1])<Sm&&(s[1]=a[1]),is(a,s)||lf(a,s)||t.push(Mm(a[0],s[1])),t.push(s)}let n=[t[0]];for(let i=1;i<t.length-1;++i)is(t[i-1],t[i])&&is(t[i],t[i+1])||lf(t[i-1],t[i])&&lf(t[i],t[i+1])||n.push(t[i]);n.push(t[t.length-1]);let r=[n[0]];for(let i=1;i<n.length-1;++i){let a=r[r.length-1],s=n[i],l=n[i+1],c=is(a,s),m=is(s,l);if(c!==m){let p=H2(a,s),d=H2(s,l);if(p<Sm||d<Sm){if(d<p)c?l[0]=a[0]:l[1]=a[1];else if(m)for(let u=r.length-1;u>=0&&r[u][0]===a[0];--u)r[u][0]=s[0];else for(let u=r.length-1;u>=0&&r[u][1]===a[1];--u)r[u][1]=s[1];continue}}r.push(s)}return r.push(n[n.length-1]),r},aR=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],[i,a]=e[o];(n!==i||r!==a)&&t.push(e[o])}return t},G2=(e,t,o)=>{if(!sR(e.type,t)){if(!Y7())throw Error(`Invalid conversion from ${e.type} to ${t}.`);return e}if(e.type===t)return e;if(j7.delete(e),ls(t)){let n=as($7({...e,type:t,roundness:t==="diamond"&&e.roundness?{type:N7(t)?Pm.ADAPTIVE_RADIUS:Pm.PROPORTIONAL_RADIUS}:e.roundness}));return q7(n,o.scene,o.state),n}if(Am(t))switch(t){case"line":return as(Z7({...e,type:"line"}));case"sharpArrow":return as(sf({...e,type:"arrow",elbowed:!1,roundness:null,startArrowhead:o.state.currentItemStartArrowhead,endArrowhead:o.state.currentItemEndArrowhead}));case"curvedArrow":return as(sf({...e,type:"arrow",elbowed:!1,roundness:{type:Pm.PROPORTIONAL_RADIUS},startArrowhead:o.state.currentItemStartArrowhead,endArrowhead:o.state.currentItemEndArrowhead}));case"elbowArrow":return as(sf({...e,type:"arrow",elbowed:!0,fixedSegments:null,roundness:null}))}return U7(t,`unhandled conversion type: ${t}`),e},sR=(e,t)=>!!(ls(e)&&ls(t)||Am(e)&&Am(t)),lR=e=>uf(e)?ss(e):e.type,V2=oR;var X2=z({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 pt.set(jo,{type:"panel"}),{captureUpdate:cR.NEVER}},checked:e=>e.gridModeEnabled,predicate:(e,t,o)=>cs(e)!==null});import{canCreateLinkFromElements as hf,defaultGetElementLinkFromSelection as dR,getLinkIdAndTypeFromSelection as mR}from"@orangecatai/element";import{CaptureUpdateAction as oc}from"@orangecatai/element";var _m=z({name:"copyElementLink",label:"labels.copyElementLink",icon:Ia,trackEvent:{category:"element"},perform:async(e,t,o,n)=>{let r=se(e,t);try{if(window.location){let i=mR(r,t);return i?(await $o(n.props.generateLinkForSelection?n.props.generateLinkForSelection(i.id,i.type):dR(i.id,i.type)),{appState:{toast:{message:h("toast.elementLinkCopied"),closable:!0}},captureUpdate:oc.EVENTUALLY}):{appState:t,elements:e,app:n,captureUpdate:oc.EVENTUALLY}}}catch(i){console.error(i)}return{appState:t,elements:e,app:n,captureUpdate:oc.EVENTUALLY}},predicate:(e,t)=>hf(se(e,t))}),$2=z({name:"linkToElement",label:"labels.linkToElement",icon:Pd,perform:(e,t,o,n)=>{let r=se(e,t);return r.length!==1||!hf(r)?{elements:e,appState:t,app:n,captureUpdate:oc.EVENTUALLY}:{appState:{...t,openDialog:{name:"elementLinkSelector",sourceElementId:se(e,t)[0].id}},captureUpdate:oc.IMMEDIATELY}},predicate:(e,t,o,n)=>{let r=se(e,t);return t.openDialog?.name!=="elementLinkSelector"&&r.length===1&&hf(r)},trackEvent:!1});import{isDarwin as Z2}from"@orangecatai/common";var pR={toggleTheme:[N("Shift+Alt+D")],saveScene:[N("CtrlOrCmd+S")],loadScene:[N("CtrlOrCmd+O")],clearCanvas:[N("CtrlOrCmd+Delete")],imageExport:[N("CtrlOrCmd+Shift+E")],commandPalette:[N("CtrlOrCmd+/"),N("CtrlOrCmd+Shift+P")],cut:[N("CtrlOrCmd+X")],copy:[N("CtrlOrCmd+C")],paste:[N("CtrlOrCmd+V")],copyStyles:[N("CtrlOrCmd+Alt+C")],pasteStyles:[N("CtrlOrCmd+Alt+V")],selectAll:[N("CtrlOrCmd+A")],deleteSelectedElements:[N("Delete")],duplicateSelection:[N("CtrlOrCmd+D"),N(`Alt+${h("helpDialog.drag")}`)],sendBackward:[N("CtrlOrCmd+[")],bringForward:[N("CtrlOrCmd+]")],sendToBack:[Z2?N("CtrlOrCmd+Alt+["):N("CtrlOrCmd+Shift+[")],bringToFront:[Z2?N("CtrlOrCmd+Alt+]"):N("CtrlOrCmd+Shift+]")],copyAsPng:[N("Shift+Alt+C")],group:[N("CtrlOrCmd+G")],ungroup:[N("CtrlOrCmd+Shift+G")],gridMode:[N("CtrlOrCmd+'")],zenMode:[N("Alt+Z")],objectsSnapMode:[N("Alt+S")],stats:[N("Alt+/")],addToLibrary:[],flipHorizontal:[N("Shift+H")],flipVertical:[N("Shift+V")],viewMode:[N("Alt+R")],hyperlink:[N("CtrlOrCmd+K")],toggleElementLock:[N("CtrlOrCmd+Shift+L")],resetZoom:[N("CtrlOrCmd+0")],zoomOut:[N("CtrlOrCmd+-")],zoomIn:[N("CtrlOrCmd++")],zoomToFitSelection:[N("Shift+3")],zoomToFit:[N("Shift+1")],zoomToFitSelectionInViewport:[N("Shift+2")],toggleEraserTool:[N("E")],toggleHandTool:[N("H")],setFrameAsActiveTool:[N("F")],saveFileToDisk:[N("CtrlOrCmd+S")],saveToActiveFile:[N("CtrlOrCmd+S")],toggleShortcuts:[N("?")],searchMenu:[N("CtrlOrCmd+F")],wrapSelectionInFrame:[],toolLock:[N("Q")]},Ue=(e,t=0)=>{let o=pR[e];return o&&o.length>0?o[t]||o[0]:""};var uR="\\u0300-\\u036f",gR="\\ufe20-\\ufe2f",hR="\\u20d0-\\u20ff",fR=uR+gR+hR,bR=`[${fR}]`,xR=RegExp(bR,"g"),ER=/[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g,yR={\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"},_i=e=>e.replace(ER,t=>yR[t]||t).replace(xR,"");import N9 from"clsx";import{useEffect as B9,useState as F9}from"react";import{KEYS as z9,queryFocusableElements as iI}from"@orangecatai/common";import{useCallback as wR,useState as vR}from"react";var j2=()=>{let[e,t]=vR(null),o=wR(n=>t(n),[]);return[e,o]};import{useState as QT,useCallback as Ff,useMemo as eI,useEffect as zf,memo as tI,useRef as y9}from"react";import{LIBRARY_DISABLED_TYPES as w9,randomId as v9,isShallowEqual as T9,KEYS as I9,isWritableElement as C9,addEventListener as k9,EVENT as S9,CLASSES as jT}from"@orangecatai/common";import{useEffect as eT,useRef as tT}from"react";import{URL_HASH_KEYS as xf,URL_QUERY_KEYS as Ef,APP_NAME as oT,EVENT as Rm,DEFAULT_SIDEBAR as kR,LIBRARY_SIDEBAR_TAB as SR,arrayToMap as yf,cloneJSON as MR,preventUnload as PR,promiseTry as nT,resolvablePromise as AR,toValidURL as LR,Queue as _R,Emitter as DR}from"@orangecatai/common";import{hashElementsVersion as RR,hashString as NR}from"@orangecatai/element";import{getCommonBoundingBox as bf}from"@orangecatai/element";import{MIME_TYPES as Di}from"@orangecatai/common";var Nr=({elements:e,appState:t,files:o,maxWidthOrHeight:n,getDimensions:r,exportPadding:i,exportingFrame:a})=>{let s=hi(e,null,{deleteInvisibleElements:!0}),l=ma(t,null),{exportBackground:c,viewBackgroundColor:m}=l;return ca(s,{...l,offsetTop:0,offsetLeft:0,width:0,height:0},o||{},{exportBackground:c,exportPadding:i,viewBackgroundColor:m,exportingFrame:a},(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),E=n<g?n/g:t?.exportScale??1;return u.width=p*E,u.height=d*E,{canvas:u,scale:E}}let b=r?.(p,d)||{width:p,height:d};return u.width=b.width,u.height=b.height,{canvas:u,scale:b.scale??1}})},q2=async e=>{let{mimeType:t=Di.png,quality:o}=e;t===Di.png&&typeof o=="number"&&console.warn(`"quality" will be ignored for "${Di.png}" mimeType`),t==="image/jpg"&&(t=Di.jpg),t===Di.jpg&&!e.appState?.exportBackground&&(console.warn(`Defaulting "exportBackground" to "true" for "${Di.jpg}" mimeType`),e={...e,appState:{...e.appState,exportBackground:!0}});let n=await Nr(e);return o=o||(/image\/jpe?g/.test(t)?.92:.8),new Promise((r,i)=>{n.toBlob(async a=>{if(!a)return i(new Error("couldn't export to blob"));a&&t===Di.png&&e.appState?.exportEmbedScene&&(a=await Rx({blob:a,metadata:cl(e.elements,e.appState,e.files||{},"local")})),r(a)},t,o)})},ds=async({elements:e,appState:t=fr(),files:o={},exportPadding:n,renderEmbeddables:r,exportingFrame:i,skipInliningFonts:a,reuseImages:s})=>{let l=hi(e,null,{deleteInvisibleElements:!0}),m={...ma(t,null),exportPadding:n};return da(l,m,o,{exportingFrame:i,renderEmbeddables:r,skipInliningFonts:a,reuseImages:s})},TR=async e=>{if(e.type==="svg"){let t=await ds(e);await $o(t.outerHTML)}else if(e.type==="png")await pm(q2(e));else if(e.type==="json")await dm(e.elements,e.files);else throw new Error("Invalid export type")};import{useEffect as J2,useState as IR}from"react";import{COLOR_PALETTE as CR}from"@orangecatai/common";var ff=Ie(new Map),Q2=async e=>await ds({elements:e,appState:{exportBackground:!1,viewBackgroundColor:CR.white},files:null,renderEmbeddables:!1,skipInliningFonts:!0}),Dm=(e,t,o,n)=>{let[r,i]=IR();return J2(()=>{if(t)if(e){let a=o.get(e);a?i(a):(async()=>{let s=await Q2(t);s.querySelector(".style-fonts")?.remove(),s&&(o.set(e,s),i(s))})()}else(async()=>{let a=await Q2(t);i(a)})()},[e,t,o,i]),J2(()=>{let a=n.current;if(a)return r&&(a.innerHTML=r.outerHTML),()=>{a.innerHTML=""}},[r,n]),r},ms=()=>{let[e]=ne(ff);return{clearLibraryCache:()=>e.clear(),deleteItemsFromLibraryCache:n=>{n.forEach(r=>e.delete(r))},svgCache:e}};var BR=["excalidraw.com","raw.githubusercontent.com/excalidraw/excalidraw-libraries"],iT=new DR,qn=Ie({status:"loaded",isInitialized:!1,libraryItems:[]}),nc=e=>MR(e),FR=(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)),aT=(e,t)=>{let o=[];for(let n of t)FR(e,n)&&o.push(n);return[...o,...e]},sT=(e,t)=>{let o=yf(t),n={deletedItems:new Map,addedItems:new Map,updatedItems:new Map};for(let i of e)o.has(i.id)||n.deletedItems.set(i.id,i);let r=yf(e);for(let i of t){let a=r.get(i.id);a?Tf(a)!==Tf(i)&&n.updatedItems.set(i.id,i):n.addedItems.set(i.id,i)}return n},wf=class{constructor(t){S(this,"currLibraryItems",[]);S(this,"prevLibraryItems",nc(this.currLibraryItems));S(this,"app");S(this,"updateQueue",[]);S(this,"getLastUpdateTask",()=>this.updateQueue[this.updateQueue.length-1]);S(this,"notifyListeners",()=>{if(this.updateQueue.length>0)pt.set(qn,t=>({status:"loading",libraryItems:this.currLibraryItems,isInitialized:t.isInitialized}));else{pt.set(qn,{status:"loaded",libraryItems:this.currLibraryItems,isInitialized:!0});try{let t=this.prevLibraryItems;this.prevLibraryItems=nc(this.currLibraryItems);let o=nc(this.currLibraryItems);this.app.props.onLibraryChange?.(o),iT.trigger(sT(t,o),o)}catch(t){console.error(t)}}});S(this,"destroy",()=>{this.updateQueue=[],this.currLibraryItems=[],pt.set(ff,new Map)});S(this,"resetLibrary",()=>this.setLibrary([]));S(this,"getLatestLibrary",()=>new Promise(async t=>{try{let o=await(this.getLastUpdateTask()||this.currLibraryItems);this.updateQueue.length>0?t(this.getLatestLibrary()):t(nc(o))}catch{return t(this.currLibraryItems)}}));S(this,"updateLibrary",async({libraryItems:t,prompt:o=!1,merge:n=!1,openLibraryMenu:r=!1,defaultStatus:i="unpublished"})=>(r&&this.app.setState({openSidebar:{name:kR.name,tab:SR}}),this.setLibrary(()=>new Promise(async(a,s)=>{try{let l=await(typeof t=="function"&&!(t instanceof Blob)?t(this.currLibraryItems):t),c;l instanceof Blob?c=await og(l,i):c=pl(l,i),!o||window.confirm(h("alerts.confirmAddLibrary",{numShapes:c.length}))?(o&&this.app.focusContainer(),a(n?aT(this.currLibraryItems,c):c)):s(new sa)}catch(l){s(l)}}))));S(this,"setLibrary",t=>{let o=new Promise(async(n,r)=>{try{await this.getLastUpdateTask(),typeof t=="function"&&(t=t(this.currLibraryItems)),this.currLibraryItems=nc(await t),n(this.currLibraryItems)}catch(i){r(i)}}).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}},lT=wf,us=e=>{let o=Math.ceil(Math.sqrt(e.length)),n=[],r=u=>e.slice(u*o,u*o+o).reduce((g,E)=>{let{height:y}=bf(E.elements);return Math.max(g,y)},0),i=u=>{let b=0,g=0,E=0;for(let y of e){if(b%o===0&&(g=0),g===u){let{width:x}=bf(y.elements);E=Math.max(E,x)}b++,g++}return E},a=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,a=0,p=0,d++),p===0&&(l=r(d)),c=i(p);let{minX:b,minY:g,width:E,height:y}=bf(u.elements),x=(c-E)/2,w=(l-y)/2;n.push(...u.elements.map(v=>({...v,x:v.x+a+x-b,y:v.y+s+w-g}))),a+=c+50,m++,p++}return n},zR=(e,t=BR)=>{if(typeof t=="function"?t(e):t.some(o=>{let n=new URL(`https://${o.replace(/^https?:\/\//,"")}`),{hostname:r,pathname:i}=new URL(e);return new RegExp(`(^|\\.)${n.hostname}$`).test(r)&&new RegExp(`^${n.pathname.replace(/\/+$/,"")}(/+|$)`).test(i)}))return!0;throw new Error(`Invalid or disallowed library URL: "${e}"`)},vf=()=>{let e=new URLSearchParams(window.location.hash.slice(1)).get(xf.addLibrary)||new URLSearchParams(window.location.search).get(Ef.addLibrary),t=e?new URLSearchParams(window.location.hash.slice(1)).get("token"):null;return e?{libraryUrl:e,idToken:t}:null},Br=class Br{constructor(t){S(this,"adapter");this.adapter=t}static async getLibraryItems(t,o,n=!0){let r=()=>new Promise(async(i,a)=>{try{let s=await t.load({source:o});i(pl(s?.libraryItems||[],"published"))}catch(s){a(s)}});return n?Br.queue.push(r):r()}getLibraryItems(t){return Br.getLibraryItems(this.adapter,t,!1)}};S(Br,"queue",new _R),S(Br,"run",async(t,o)=>{let n=new Br(t);return Br.queue.push(()=>o(n))});var ps=Br,rc=0,Nm=0,Tf=e=>`${e.id}:${e.name||""}:${RR(e.elements)}`,Bm=e=>NR(e.map(t=>Tf(t)).sort().join()),rT=async(e,t)=>{try{return Nm++,await ps.run(e,async o=>{let n=yf(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 i=r.concat(Array.from(n.values())),a=Bm(i);return a!==rc&&await e.save({libraryItems:i}),rc=a,i})}finally{Nm--}},OR=e=>{let{excalidrawAPI:t}=e,o=tT(e);o.current=e;let n=tT(!1);eT(()=>{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=LR(s),zR(s,o.current.validateLibraryUrl);let b=await(await fetch(s)).blob();p(b)}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(xf.addLibrary)){let p=new URLSearchParams(window.location.hash.slice(1));p.delete(xf.addLibrary),window.history.replaceState({},oT,`#${p.toString()}`)}else if(window.location.search.includes(Ef.addLibrary)){let p=new URLSearchParams(window.location.search);p.delete(Ef.addLibrary),window.history.replaceState({},oT,`?${p.toString()}`)}}},i=s=>{s.preventDefault();let l=vf();l&&(s.stopImmediatePropagation(),window.history.replaceState({},"",s.oldURL),r(l))},a=vf();if(a&&r(a),"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=AR();l?c.resolve(nT(l.load).then(async m=>{let p=null;try{if(!m)return ps.getLibraryItems(s,"load");p=pl(m.libraryItems||[],"published");let d=await rT(s,sT([],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}`),ps.getLibraryItems(s,"load")))):c.resolve(nT(ps.getLibraryItems,s,"load")),t.updateLibrary({libraryItems:c.then(m=>{let p=m||[];return rc=Bm(p),p}),merge:!0}).finally(()=>{n.current=!0})}return window.addEventListener(Rm.HASHCHANGE,i),()=>{window.removeEventListener(Rm.HASHCHANGE,i)}},[t]),eT(()=>{let r=iT.on(async(a,s)=>{let l=n.current,c="adapter"in o.current&&o.current.adapter||null;try{c&&rc!==Bm(s)&&await rT(c,a)}catch(m){console.error(`couldn't persist library update: ${m.message}`,a),l&&o.current.excalidrawAPI&&o.current.excalidrawAPI.updateScene({appState:{errorMessage:h("errors.saveLibraryError")}})}}),i=a=>{Nm&&PR(a)};return window.addEventListener(Rm.BEFORE_UNLOAD,i),()=>{window.removeEventListener(Rm.BEFORE_UNLOAD,i),r(),rc=0,Nm=0}},[])};import WR from"clsx";import{VERSIONS as HR}from"@orangecatai/common";import{jsx as UR}from"react/jsx-runtime";var GR=({theme:e,id:t,libraryReturnUrl:o})=>{let n=o||window.location.origin+window.location.pathname;return UR("a",{className:"library-menu-browse-button",href:`${I.VITE_APP_LIBRARY_URL}?target=${window.name||"_blank"}&referrer=${n}&useHash=true&token=${t}&theme=${e}&version=${HR.excalidrawLibrary}`,target:"_excalidraw_libraries",children:h("labels.libraries")})},cT=GR;import{jsx as YR,jsxs as VR}from"react/jsx-runtime";var Fm=({libraryReturnUrl:e,theme:t,id:o,style:n,children:r,className:i})=>VR("div",{className:WR("library-menu-control-buttons",i),style:n,children:[YR(cT,{id:o,libraryReturnUrl:e,theme:t}),r]});import{useCallback as fs,useEffect as Df,useMemo as Rf,useRef as XT,useState as $T}from"react";import{MIME_TYPES as u9,arrayToMap as g9,nextAnimationFrame as h9}from"@orangecatai/common";import{duplicateElements as f9}from"@orangecatai/element";import b9 from"clsx";import KR from"lodash.throttle";import{useEffect as XR}from"react";var $R=Ie(0),dT=e=>{let[t,o]=ne($R);return XR(()=>{let{current:n}=e;if(!n)return;let r=KR(()=>{let{scrollTop:i}=n;o(i)},200);return n.addEventListener("scroll",r),()=>{r.cancel(),n.removeEventListener("scroll",r)}},[e,o]),t};import WN from"clsx";import{useCallback as YN,useState as Af}from"react";import{muteFSAbortError as VN}from"@orangecatai/common";import{flushSync as mT}from"react-dom";import ZR from"clsx";import{jsx as zm,jsxs as qR}from"react/jsx-runtime";var jR=({label:e,onClick:t,className:o,children:n,actionType:r,type:i="button",isLoading:a,...s})=>{let l=r?`Dialog__action-button--${r}`:"";return qR("button",{className:ZR("Dialog__action-button",l,o),type:i,"aria-label":e,onClick:t,...s,children:[n&&zm("div",{style:a?{visibility:"hidden"}:{},children:n}),zm("div",{style:a?{visibility:"hidden"}:{},children:e}),a&&zm("div",{style:{position:"absolute",inset:0},children:zm(Bt,{})})]})},Jn=jR;import{jsx as pT,jsxs as uT}from"react/jsx-runtime";var JR=e=>{let{onConfirm:t,onCancel:o,children:n,confirmText:r=h("buttons.confirm"),cancelText:i=h("buttons.cancel"),className:a="",...s}=e,l=ve(),c=mn(gs),{container:m}=Ke();return uT(dt,{onCloseRequest:o,size:"small",...s,className:`confirm-dialog ${a}`,children:[n,uT("div",{className:"confirm-dialog-buttons",children:[pT(Jn,{label:i,onClick:()=>{l({openMenu:null}),c(!1),mT(()=>{o()}),m?.focus()}}),pT(Jn,{label:r,onClick:()=>{l({openMenu:null}),c(!1),mT(()=>{t()}),m?.focus()},actionType:"danger"})]})]})},Om=JR;import{useCallback as iN,useEffect as kf,useRef as gT,useState as If}from"react";import{EDITOR_LS_KEYS as Cf,EXPORT_DATA_TYPES as aN,MIME_TYPES as hT,VERSIONS as sN,chunk as lN,getExportSource as cN}from"@orangecatai/common";var Po=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}}};S(Po,"set",(t,o)=>{try{return window.localStorage.setItem(t,JSON.stringify(o)),!0}catch(n){return console.warn(`localStorage.setItem error: ${n.message}`),!1}}),S(Po,"delete",t=>{try{window.localStorage.removeItem(t)}catch(o){console.warn(`localStorage.removeItem error: ${o.message}`)}});import Hm from"react";var QR=/({{[\w-]+}})|(<[\w-]+>)|(<\/[\w-]+>)/g,eN=/{{([\w-]+)}}/,tN=/<([\w-]+)>/,oN=/<\/([\w-]+)>/,nN=(e,t)=>{let o=[{name:"",children:[]}];return e.split(QR).filter(Boolean).forEach(n=>{let r=n.match(tN),i=n.match(oN),a=n.match(eN);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(i!==null)if(i[1]===o[o.length-1].name){let l=o.pop(),c=Hm.createElement(Hm.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(a!==null){let s=a[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},rN=({i18nKey:e,children:t,...o})=>{let{t:n}=Oe();return Hm.createElement(Hm.Fragment,{},...nN(n(e),o))},qt=rN;import{jsx as Ce,jsxs as Gt}from"react/jsx-runtime";var dN=async e=>{let n=Math.round(8),r=Math.max(Math.round(128/64),2),i=lN(e,6),a=document.createElement("canvas");a.width=i[0].length*128+(i[0].length+1)*(n*2)-n*2,a.height=i.length*128+(i.length+1)*(n*2)-n*2;let s=a.getContext("2d");s.fillStyle="#fff",s.fillRect(0,0,a.width,a.height);for(let[l,c]of e.entries()){let m=await Nr({elements:c.elements,files:null,maxWidthOrHeight:128}),{width:p,height:d}=m,u=Math.floor(l/6)*(128+n*2),b=l%6*(128+n*2);s.drawImage(m,b+(128-p)/2+n,u+(128-d)/2+n),s.lineWidth=r,s.strokeStyle="#ced4da",s.strokeRect(b+n/2,u+n/2,128+n,128+n)}return await ud(new File([await fi(a)],"preview",{type:hT.png}),{outputType:hT.jpg,maxWidthOrHeight:5e3})},mN=({libItem:e,appState:t,index:o,onChange:n,onRemove:r})=>{let i=gT(null),a=gT(null);return kf(()=>{let s=i.current;s&&(async()=>{let l=await ds({elements:e.elements,appState:{...t,viewBackgroundColor:"#fff",exportBackground:!0},files:null,skipInliningFonts:!0});s.innerHTML=l.outerHTML})()},[e.elements,t]),Gt("div",{className:"single-library-item",children:[e.status==="published"&&Ce("span",{className:"single-library-item-status",children:h("labels.statusPublished")}),Ce("div",{ref:i,className:"single-library-item__svg"}),Ce(ee,{"aria-label":h("buttons.remove"),type:"button",icon:To,className:"single-library-item--remove",onClick:r.bind(null,e.id),title:h("buttons.remove")}),Gt("div",{style:{display:"flex",margin:"0.8rem 0",width:"100%",fontSize:"14px",fontWeight:500,flexDirection:"column"},children:[Gt("label",{style:{display:"flex",justifyContent:"space-between",flexDirection:"column"},children:[Gt("div",{style:{padding:"0.5em 0"},children:[Ce("span",{style:{fontWeight:500,color:"#868e96"},children:h("publishDialog.itemName")}),Ce("span",{"aria-hidden":"true",className:"required",children:"*"})]}),Ce("input",{type:"text",ref:a,style:{width:"80%",padding:"0.2rem"},defaultValue:e.name,placeholder:"Item name",onChange:s=>{n(s.target.value,o)}})]}),Ce("span",{className:"error",children:e.error})]})]})},pN=({onClose:e,libraryItems:t,appState:o,onSuccess:n,onError:r,updateItemsInStorage:i,onRemove:a})=>{let[s,l]=If({authorName:"",githubHandle:"",name:"",description:"",twitterHandle:"",website:""}),[c,m]=If(!1);kf(()=>{let w=Po.get(Cf.PUBLISH_LIBRARY);w&&l(w)},[]);let[p,d]=If(t.slice());kf(()=>{d(t.slice())},[t]);let u=w=>{l({...s,[w.target.name]:w.target.value})},b=async w=>{w.preventDefault(),m(!0);let v=[],T=!1;if(p.forEach(P=>{let _="";P.name||(_=h("publishDialog.errors.required"),T=!0),v.push({...P,error:_})}),T){d(v),m(!1);return}let C=await dN(p),M={type:aN.excalidrawLibrary,version:sN.excalidrawLibrary,source:cN(),libraryItems:p},k=JSON.stringify(M,null,2),R=new Blob([k],{type:"application/json"}),A=new FormData;A.append("excalidrawLib",R),A.append("previewImage",C),A.append("previewImageType",C.type),A.append("title",s.name),A.append("authorName",s.authorName),A.append("githubHandle",s.githubHandle),A.append("name",s.name),A.append("description",s.description),A.append("twitterHandle",s.twitterHandle),A.append("website",s.website),fetch(`${I.VITE_APP_LIBRARY_BACKEND}/submit`,{method:"post",body:A}).then(P=>P.ok?P.json().then(({url:_})=>{Po.delete(Cf.PUBLISH_LIBRARY),n({url:_,authorName:s.authorName,items:p})}):P.json().catch(()=>{throw new Error(P.statusText||"something went wrong")}).then(_=>{throw new Error(_.message||P.statusText||"something went wrong")}),P=>{console.error(P),r(P),m(!1)}).catch(P=>{console.error(P),r(P),m(!1)})},g=()=>{let w=[];return p.forEach((v,T)=>{w.push(Ce("div",{className:"single-library-item-wrapper",children:Ce(mN,{libItem:v,appState:o,index:T,onChange:(C,M)=>{let k=p.slice();k[M].name=C,d(k)},onRemove:a})},T))}),Ce("div",{className:"selected-library-items",children:w})},E=iN(()=>{i(p),Po.set(Cf.PUBLISH_LIBRARY,s),e()},[p,e,i,s]),y=!!t.length,x=t.some(w=>w.status==="published");return Ce(dt,{onCloseRequest:E,title:h("publishDialog.title"),className:"publish-library",children:y?Gt("form",{onSubmit:b,children:[Ce("div",{className:"publish-library-note",children:Ce(qt,{i18nKey:"publishDialog.noteDescription",link:w=>Ce("a",{href:"https://libraries.excalidraw.com",target:"_blank",rel:"noopener",children:w})})}),Ce("span",{className:"publish-library-note",children:Ce(qt,{i18nKey:"publishDialog.noteGuidelines",link:w=>Ce("a",{href:"https://github.com/excalidraw/excalidraw-libraries#guidelines",target:"_blank",rel:"noopener noreferrer",children:w})})}),Ce("div",{className:"publish-library-note",children:h("publishDialog.noteItems")}),x&&Ce("span",{className:"publish-library-note publish-library-warning",children:h("publishDialog.republishWarning")}),g(),Gt("div",{className:"publish-library__fields",children:[Gt("label",{children:[Gt("div",{children:[Ce("span",{children:h("publishDialog.libraryName")}),Ce("span",{"aria-hidden":"true",className:"required",children:"*"})]}),Ce("input",{type:"text",name:"name",required:!0,value:s.name,onChange:u,placeholder:h("publishDialog.placeholder.libraryName")})]}),Gt("label",{style:{alignItems:"flex-start"},children:[Gt("div",{children:[Ce("span",{children:h("publishDialog.libraryDesc")}),Ce("span",{"aria-hidden":"true",className:"required",children:"*"})]}),Ce("textarea",{name:"description",rows:4,required:!0,value:s.description,onChange:u,placeholder:h("publishDialog.placeholder.libraryDesc")})]}),Gt("label",{children:[Gt("div",{children:[Ce("span",{children:h("publishDialog.authorName")}),Ce("span",{"aria-hidden":"true",className:"required",children:"*"})]}),Ce("input",{type:"text",name:"authorName",required:!0,value:s.authorName,onChange:u,placeholder:h("publishDialog.placeholder.authorName")})]}),Gt("label",{children:[Ce("span",{children:h("publishDialog.githubUsername")}),Ce("input",{type:"text",name:"githubHandle",value:s.githubHandle,onChange:u,placeholder:h("publishDialog.placeholder.githubHandle")})]}),Gt("label",{children:[Ce("span",{children:h("publishDialog.twitterUsername")}),Ce("input",{type:"text",name:"twitterHandle",value:s.twitterHandle,onChange:u,placeholder:h("publishDialog.placeholder.twitterHandle")})]}),Gt("label",{children:[Ce("span",{children:h("publishDialog.website")}),Ce("input",{type:"text",name:"website",pattern:"https?://.+",title:h("publishDialog.errors.website"),value:s.website,onChange:u,placeholder:h("publishDialog.placeholder.website")})]}),Ce("span",{className:"publish-library-note",children:Ce(qt,{i18nKey:"publishDialog.noteLicense",link:w=>Ce("a",{href:"https://github.com/excalidraw/excalidraw-libraries/blob/main/LICENSE",target:"_blank",rel:"noopener noreferrer",children:w})})})]}),Gt("div",{className:"publish-library__buttons",children:[Ce(Jn,{label:h("buttons.saveLibNames"),onClick:E,"data-testid":"cancel-clear-canvas-button"}),Ce(Jn,{type:"submit",label:h("buttons.submit"),actionType:"primary",isLoading:c})]})]}):Ce("p",{style:{padding:"1em",textAlign:"center",fontWeight:500},children:h("publishDialog.atleastOneLibItem")})})},fT=pN;import HT from"react";import{DropdownMenu as ON}from"radix-ui";import{CLASSES as HN}from"@orangecatai/common";import hN from"clsx";import{useCallback as fN,useEffect as bN,useRef as xN}from"react";import{CLASSES as EN,EVENT as yT,KEYS as yN}from"@orangecatai/common";import{DropdownMenu as wN}from"radix-ui";import{forwardRef as bT}from"react";import xT from"clsx";import{jsx as ET}from"react/jsx-runtime";var uN=bT(({children:e,gap:t,align:o,justifyContent:n,className:r,style:i},a)=>ET("div",{className:xT("Stack Stack_horizontal",r),style:{"--gap":t,alignItems:o,justifyContent:n,...i},ref:a,children:e})),gN=bT(({children:e,gap:t,align:o,justifyContent:n,className:r,style:i},a)=>ET("div",{className:xT("Stack Stack_vertical",r),style:{"--gap":t,justifyItems:o,justifyContent:n,...i},ref:a,children:e})),Ft={Row:uN,Col:gN};import{jsx as Gm}from"react/jsx-runtime";var wT=({children:e,onClickOutside:t,className:o="",onSelect:n,open:r=!0,align:i="end",style:a})=>{let s=ye(),l=xN(null),c=yr({onClickOutside:t});Ra(l,fN(p=>{l.current?.closest(`.${EN.DROPDOWN_MENU_EVENT_WRAPPER}`)?.contains(p.target)||c.onClickOutside?.()},[c])),bN(()=>{if(!r)return;let p=u=>{u.key===yN.ESCAPE&&(u.stopImmediatePropagation(),c.onClickOutside?.())},d={capture:!0};return document.addEventListener(yT.KEYDOWN,p,d),()=>{document.removeEventListener(yT.KEYDOWN,p,d)}},[c,r]);let m=hN(`dropdown-menu ${o}`,{"dropdown-menu--mobile":s.formFactor==="phone"}).trim();return Gm(Qg.Provider,{value:{onSelect:n},children:Gm(wN.Content,{ref:l,className:m,style:a,"data-testid":"dropdown-menu",align:i,sideOffset:8,onCloseAutoFocus:p=>p.preventDefault(),children:s.formFactor==="phone"?Gm(Ft.Col,{className:"dropdown-menu-container",children:e}):Gm(st,{className:"dropdown-menu-container",padding:2,children:e})})})};wT.displayName="DropdownMenuContent";var vT=wT;import{jsx as TN}from"react/jsx-runtime";var vN=({children:e,className:t="",selected:o,...n})=>TN("div",{...n,className:`dropdown-menu-item-base dropdown-menu-item-custom ${t} ${o?"dropdown-menu-item--selected":""}`.trim(),children:e}),TT=vN;import{DropdownMenu as IN}from"radix-ui";import{jsx as Sf}from"react/jsx-runtime";var IT=({icon:e,shortcut:t,href:o,children:n,onSelect:r,className:i="",selected:a,rel:s="noopener",...l})=>{let c=Xd(r);return Sf(IN.Item,{className:"radix-menu-item",onSelect:c,asChild:!0,children:Sf("a",{...l,href:o,target:"_blank",rel:`noopener ${s}`,className:kr(i,a),title:l.title??l["aria-label"],children:Sf(Sr,{icon:e,shortcut:t,children:n})})})},hs=IT;IT.displayName="DropdownMenuItemLink";import{jsx as CN}from"react/jsx-runtime";var CT=()=>CN("div",{style:{height:"1px",backgroundColor:"var(--default-border-color)",margin:"6px 0",flex:"0 0 auto"}}),kT=CT;CT.displayName="DropdownMenuSeparator";import{DropdownMenu as _N}from"radix-ui";import kN from"clsx";import{DropdownMenu as SN}from"radix-ui";import{useCallback as MN,useState as ST}from"react";import{jsx as Pf}from"react/jsx-runtime";var Mf=-4,PN=4,MT=({children:e,className:t})=>{let o=ye(),n=kN(`dropdown-menu dropdown-submenu ${t}`,{"dropdown-menu--mobile":o.formFactor==="phone"}).trim(),r=MN(c=>{if(c){let p=c.closest(".dropdown-menu-container")?.getBoundingClientRect();if(p){let d=c.getBoundingClientRect().width,b=window.innerWidth-p.right;b<d+20&&(a(b-d+Mf),l(Mf+8))}}},[]),[i,a]=ST(PN),[s,l]=ST(Mf);return Pf(SN.SubContent,{className:n,sideOffset:i,alignOffset:s,collisionPadding:8,ref:r,children:o.formFactor==="phone"?Pf(Ft.Col,{className:"dropdown-menu-container",children:e}):Pf(st,{className:"dropdown-menu-container",padding:2,style:{zIndex:1},children:e})})},PT=MT;MT.displayName="DropdownMenuSubContent";import{DropdownMenu as AN}from"radix-ui";import{jsx as AT,jsxs as LN}from"react/jsx-runtime";var LT=({children:e,icon:t,shortcut:o,className:n})=>LN(AN.SubTrigger,{className:`${kr(n)} dropdown-menu__submenu-trigger`,children:[AT(Sr,{icon:t,shortcut:o,children:e}),AT("div",{className:"dropdown-menu__submenu-trigger-icon",children:Oy})]}),_T=LT;LT.displayName="DropdownMenuSubTrigger";import DT from"react";var Um=e=>t=>{let o=DT.Children.toArray(t).find(n=>DT.isValidElement(n)&&typeof n.type!="string"&&n?.type.displayName&&n.type.displayName===e);return o||null},RT=Um("DropdownMenuTrigger"),NT=Um("DropdownMenuContent"),BT=Um("DropdownMenuSubTrigger"),FT=Um("DropdownMenuSubContent");import{jsxs as DN}from"react/jsx-runtime";var Wm=({children:e})=>{let t=BT(e),o=FT(e);return DN(_N.Sub,{children:[t,o]})};Wm.Trigger=_T;Wm.Content=PT;Wm.displayName="DropdownMenuSub";var Fr=Wm;import RN from"clsx";import{DropdownMenu as NN}from"radix-ui";import{jsx as BN}from"react/jsx-runtime";var zT=({className:e="",children:t,onToggle:o,title:n,...r})=>{let i=ye(),a=RN(`dropdown-menu-button ${e}`,"zen-mode-transition",{"dropdown-menu-button--mobile":i.formFactor==="phone"}).trim();return BN(NN.Trigger,{className:a,onClick:o,type:"button","data-testid":"dropdown-menu-button",title:n,...r,children:t})},OT=zT;zT.displayName="DropdownMenuTrigger";import{jsx as zN}from"react/jsx-runtime";var FN=e=>zN(Kt,{...e,icon:e.checked?wd:zy}),Qn=FN;import{jsx as UN,jsxs as GN}from"react/jsx-runtime";var qo=({children:e,open:t})=>{let o=RT(e),n=NT(e),r=n&&HT.isValidElement(n)?HT.cloneElement(n,{open:t}):n;return UN(ON.Root,{open:t,modal:!1,children:GN("div",{className:HN.DROPDOWN_MENU_EVENT_WRAPPER,style:{display:"contents"},children:[o,r]})})};qo.Trigger=OT;qo.Content=vT;qo.Item=Kt;qo.ItemCheckbox=Qn;qo.ItemLink=hs;qo.ItemCustom=TT;qo.Group=Ll;qo.Separator=kT;qo.Sub=Fr;var pe=qo;qo.displayName="DropdownMenu";import{jsx as io,jsxs as Ym}from"react/jsx-runtime";var KN=(e,t)=>e.filter(o=>t.includes(o.id)),XN=({setAppState:e,selectedItems:t,library:o,onRemoveFromLibrary:n,resetLibrary:r,onSelectItems:i,appState:a,className:s})=>{let[l]=ne(qn),[c,m]=ne(gs),p=()=>{let A=t.length?h("alerts.removeItemsFromsLibrary",{count:t.length}):h("alerts.resetLibrary"),P=t.length?h("confirmDialog.removeItemsFromLib"):h("confirmDialog.resetLibrary");return io(Om,{onConfirm:()=>{t.length?n():r(),u(!1)},onCancel:()=>{u(!1)},title:P,children:io("p",{children:A})})},[d,u]=Af(!1),b=!!t.length,g=b?l.libraryItems.filter(A=>t.includes(A.id)):l.libraryItems,E=b?h("buttons.remove"):h("buttons.resetLibrary"),[y,x]=Af(!1),[w,v]=Af(null),T=YN(()=>Ym(dt,{onCloseRequest:()=>v(null),title:h("publishSuccessDialog.title"),className:"publish-library-success",size:"small",children:[io("p",{children:io(qt,{i18nKey:"publishSuccessDialog.content",authorName:w.authorName,link:A=>io("a",{href:w?.url,target:"_blank",rel:"noopener noreferrer",children:A})})}),io(ee,{type:"button",title:h("buttons.close"),"aria-label":h("buttons.close"),label:h("buttons.close"),onClick:()=>v(null),"data-testid":"publish-library-success-close",className:"publish-library-success-close"})]}),[v,w]),C=(A,P)=>{x(!1),v({url:A.url,authorName:A.authorName});let _=P.slice();_.forEach(O=>{t.includes(O.id)&&(O.status="published")}),o.setLibrary(_)},M=async()=>{try{await o.updateLibrary({libraryItems:ad({description:"Excalidraw library files"}),merge:!0,openLibraryMenu:!0})}catch(A){if(A?.name==="AbortError"){console.warn(A);return}e({errorMessage:h("errors.importLibraryError")})}},k=async()=>{let A=b?g:await o.getLatestLibrary();Mx(A).catch(VN).catch(P=>{e({errorMessage:P.message})})},R=()=>Ym(pe,{open:c,children:[io(pe.Trigger,{onToggle:()=>m(!c),children:qx}),Ym(pe.Content,{onClickOutside:()=>m(!1),onSelect:()=>m(!1),className:"library-menu",children:[!b&&io(pe.Item,{onSelect:M,icon:va,"data-testid":"lib-dropdown--load",children:h("buttons.load")}),!!g.length&&io(pe.Item,{onSelect:k,icon:Ei,"data-testid":"lib-dropdown--export",children:h("buttons.export")}),b&&io(pe.Item,{icon:iy,onSelect:()=>x(!0),"data-testid":"lib-dropdown--remove",children:h("buttons.publishLibrary")}),!!g.length&&io(pe.Item,{onSelect:()=>u(!0),icon:Nt,children:E})]})]});return Ym("div",{className:WN("library-menu-dropdown-container",s),children:[R(),t.length>0&&io("div",{className:"library-actions-counter",children:t.length}),d&&p(),y&&io(fT,{onClose:()=>x(!1),libraryItems:KN(l.libraryItems,t),appState:a,onSuccess:A=>C(A,l.libraryItems),onError:A=>window.alert(A),updateItemsInStorage:()=>o.setLibrary(l.libraryItems),onRemove:A=>i(t.filter(P=>P!==A))}),w&&T()]})},GT=({selectedItems:e,onSelectItems:t,className:o})=>{let{library:n}=Xe(),{clearLibraryCache:r,deleteItemsFromLibraryCache:i}=ms(),a=Ee(),s=ve(),[l]=ne(qn),c=async p=>{let d=p.filter(u=>!e.includes(u.id));n.setLibrary(d).catch(()=>{s({errorMessage:h("alerts.errorRemovingFromLibrary")})}),i(e),t([])};return io(XN,{appState:a,setAppState:s,selectedItems:e,onSelectItems:t,library:n,onRemoveFromLibrary:()=>c(l.libraryItems),resetLibrary:()=>{n.resetLibrary(),r()},className:o})};import{memo as t9,useEffect as o9,useState as n9}from"react";import $N,{useCallback as ZN}from"react";function jN(){return[!1,ZN(t=>t(),[])]}var UT=$N.useTransition||jN;import WT from"clsx";import{memo as qN,useRef as JN,useState as QN}from"react";import{jsx as Vm,jsxs as e9}from"react/jsx-runtime";var YT=qN(({id:e,elements:t,isPending:o,onClick:n,selected:r,onToggle:i,onDrag:a,svgCache:s})=>{let l=JN(null),c=Dm(e,t,s,l),[m,p]=QN(!1),d=ye().formFactor==="phone",u=o&&Vm("div",{className:"library-unit__adder",children:jx});return e9("div",{className:WT("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:[Vm("div",{className:WT("library-unit__dragger",{"library-unit__pulse":!!o}),ref:l,draggable:!!t,onClick:t||o?b=>{e&&b.shiftKey?i(e,b):n(e)}:void 0,onDragStart:b=>{if(!e){b.preventDefault();return}p(!1),a(e,b)}}),u,e&&t&&(m||d||r)&&Vm(zl,{checked:r,onChange:(b,g)=>i(e,g),className:"library-unit__checkbox"})]})}),VT=()=>Vm("div",{className:"library-unit library-unit--skeleton"});import{Fragment as r9,jsx as Km}from"react/jsx-runtime";var Xm=({children:e})=>Km("div",{className:"library-menu-items-container__grid",children:e}),ic=t9(({items:e,onItemSelectToggle:t,onItemDrag:o,isItemSelected:n,onClick:r,svgCache:i,itemsRenderedPerBatch:a})=>{let[,s]=UT(),[l,c]=n9(0);return o9(()=>{l<e.length&&s(()=>{c(l+a)})},[l,e.length,s,a]),Km(r9,{children:e.map((m,p)=>p<l?Km(YT,{elements:m?.elements,isPending:!m?.id&&!!m?.elements,onClick:r,svgCache:i,id:m?.id,selected:n(m.id),onToggle:t,onDrag:o},m?.id??p):Km(VT,{},p))})});import Lf from"clsx";import{forwardRef as l9,useRef as c9,useImperativeHandle as d9,useLayoutEffect as m9,useState as p9}from"react";import i9 from"clsx";import{composeEventHandlers as a9}from"@orangecatai/common";import{jsx as s9}from"react/jsx-runtime";var Jt=({type:e="button",onSelect:t,selected:o,children:n,className:r="",...i})=>s9("button",{onClick:a9(i.onClick,a=>{t()}),type:e,className:i9("excalidraw-button",r,{selected:o}),...i,children:n});import{jsx as _f,jsxs as KT}from"react/jsx-runtime";var zr=l9(({onChange:e,label:t,fullWidth:o,placeholder:n,readonly:r,selectOnRender:i,onKeyDown:a,isRedacted:s=!1,icon:l,className:c,type:m,...p},d)=>{let u=c9(null);d9(d,()=>u.current),m9(()=>{i&&(u.current?.focus(),u.current?.select())},[i]);let[b,g]=p9(!1);return KT("div",{className:Lf("ExcTextField",c,{"ExcTextField--fullWidth":o,"ExcTextField--hasIcon":!!l}),onClick:()=>{u.current?.focus()},children:[l,t&&_f("div",{className:"ExcTextField__label",children:t}),KT("div",{className:Lf("ExcTextField__input",{"ExcTextField__input--readonly":r}),children:[_f("input",{className:Lf({"is-redacted":"value"in p&&p.value&&s&&!b}),readOnly:r,value:"value"in p?p.value:void 0,defaultValue:"defaultValue"in p?p.defaultValue:void 0,placeholder:n,ref:u,onChange:E=>e?.(E.target.value),onKeyDown:a,type:m}),s&&_f(Jt,{onSelect:()=>g(!b),style:{border:0,userSelect:"none"},children:b?uy:ka})]})]})});import{Fragment as ZT,jsx as St,jsxs as vn}from"react/jsx-runtime";var x9=17,E9=64;function Nf({isLoading:e,libraryItems:t,onAddToLibrary:o,onInsertLibraryItems:n,pendingElements:r,theme:i,id:a,libraryReturnUrl:s,onSelectItems:l,selectedItems:c}){let m=ye(),p=XT(null),d=dT(p);Df(()=>{d>0&&p.current?.scrollTo(0,d)},[]);let{svgCache:u}=ms(),[b,g]=$T(null),[E,y]=$T(""),x=!t.length&&!r.length,w=!x&&!!E.trim(),v=Rf(()=>{let D=_i(E.trim().toLowerCase());return D?t.filter(F=>{let X=F.name||"";return X.trim()&&_i(X.toLowerCase()).includes(D)}):[]},[t,E]),T=Rf(()=>t.filter(D=>D.status!=="published"),[t]),C=Rf(()=>t.filter(D=>D.status==="published"),[t]),M=fs((D,F)=>{let X=!c.includes(D),te=[...T,...C];if(X){if(F.shiftKey&&b){let $=te.findIndex(mt=>mt.id===b),ae=te.findIndex(mt=>mt.id===D);if($===-1||ae===-1){l([...c,D]);return}let xe=g9(c),re=Math.min($,ae),we=Math.max($,ae),Fe=te.reduce((mt,ct,Ot)=>((Ot>=re&&Ot<=we||xe.has(ct.id))&&mt.push(ct.id),mt),[]);l(Fe)}else l([...c,D]);g(D)}else g(null),l(c.filter($=>$!==D))},[b,l,C,c,T]);Df(()=>{c.length||g(null)},[c]);let k=fs(D=>{let F;return c.includes(D)?F=t.filter(X=>c.includes(X.id)):F=t.filter(X=>X.id===D),F.map(X=>({...X,elements:f9({type:"everything",elements:X.elements,randomizeSeed:!0}).duplicatedElements}))},[t,c]),R=fs((D,F)=>{let X={itemIds:c.includes(D)?c:[D]};F.dataTransfer.setData(u9.excalidrawlibIds,JSON.stringify(X))},[c]),A=fs(D=>D?c.includes(D):!1,[c]),P=fs(()=>{o(r)},[r,o]),_=fs(D=>{D&&n(k(D))},[k,n]),O=u.size>=(v.length?v:t).length?E9:x9,U=XT(null);Df(()=>{h9(()=>{U.current?.focus()})},[]);let H=!w&&vn(ZT,{children:[!x&&St("div",{className:"library-menu-items-container__header",children:h("labels.personalLib")}),!r.length&&!T.length?vn("div",{className:"library-menu-items__no-items",children:[!C.length&&St("div",{className:"library-menu-items__no-items__label",children:h("library.noItems")}),St("div",{className:"library-menu-items__no-items__hint",children:C.length>0?h("library.hint_emptyPrivateLibrary"):h("library.hint_emptyLibrary")})]}):vn(Xm,{children:[r.length>0&&St(ic,{itemsRenderedPerBatch:O,items:[{id:null,elements:r}],onItemSelectToggle:M,onItemDrag:R,onClick:P,isItemSelected:A,svgCache:u}),St(ic,{itemsRenderedPerBatch:O,items:T,onItemSelectToggle:M,onItemDrag:R,onClick:_,isItemSelected:A,svgCache:u})]}),C.length>0&&St("div",{className:"library-menu-items-container__header",style:{marginTop:"0.75rem"},children:h("labels.excalidrawLib")}),C.length>0&&St(Xm,{children:St(ic,{itemsRenderedPerBatch:O,items:C,onItemSelectToggle:M,onItemDrag:R,onClick:_,isItemSelected:A,svgCache:u})})]}),W=w&&vn(ZT,{children:[vn("div",{className:"library-menu-items-container__header",children:[h("library.search.heading"),!e&&vn("div",{className:"library-menu-items-container__header__hint",style:{cursor:"pointer"},onPointerDown:D=>D.preventDefault(),onClick:D=>{y("")},children:[St("kbd",{children:"esc"})," to clear"]})]}),v.length>0?St(Xm,{children:St(ic,{itemsRenderedPerBatch:O,items:v,onItemSelectToggle:M,onItemDrag:R,onClick:_,isItemSelected:A,svgCache:u})}):vn("div",{className:"library-menu-items__no-items",children:[St("div",{className:"library-menu-items__no-items__hint",children:h("library.search.noResults")}),St(Jt,{onPointerDown:D=>D.preventDefault(),onSelect:()=>{y("")},style:{width:"auto",marginTop:"1rem"},children:h("library.search.clearSearch")})]})]});return vn("div",{className:"library-menu-items-container",style:r.length||T.length||C.length?{justifyContent:"flex-start"}:{borderBottom:0},children:[vn("div",{className:"library-menu-items-header",children:[!x&&St(zr,{ref:U,type:"search",className:b9("library-menu-items-container__search",{hideCancelButton:m.formFactor!=="phone"}),placeholder:h("library.search.inputPlaceholder"),value:E,onChange:D=>y(D)}),St(GT,{selectedItems:c,onSelectItems:l,className:"library-menu-dropdown-container--in-heading"})]}),vn(Ft.Col,{className:"library-menu-items-container__items",align:"start",gap:1,style:{flex:C.length>0?1:"0 1 auto",margin:x?"auto":0},ref:p,children:[e&&St("div",{style:{position:"absolute",top:"var(--container-padding-y)",right:"var(--container-padding-x)",transform:"translateY(50%)"},children:St(Bt,{})}),H,W,x&&St(Fm,{style:{padding:"16px 0",width:"100%"},id:a,libraryReturnUrl:s,theme:i})]})]})}import{jsx as Or,jsxs as JT}from"react/jsx-runtime";var gs=Ie(!1),qT=({children:e})=>Or("div",{className:"layer-ui__library",children:e}),M9=tI(({onInsertLibraryItems:e,pendingElements:t,onAddToLibrary:o,setAppState:n,libraryReturnUrl:r,library:i,id:a,theme:s,selectedItems:l,onSelectItems:c})=>{let[m]=ne(qn),p=Ff(b=>{(async(E,y)=>{he("element","addToLibrary","ui");for(let w of w9)if(E.some(v=>v.type===w))return n({errorMessage:h(`errors.libraryElementTypeError.${w}`)});let x=[{status:"unpublished",elements:E,id:v9(),created:Date.now()},...y];o(),i.setLibrary(x).catch(()=>{n({errorMessage:h("alerts.errorAddingToLibrary")})})})(b,m.libraryItems)},[o,i,n,m.libraryItems]),d=eI(()=>m.libraryItems,[m]);if(m.status==="loading"&&!m.isInitialized)return Or(qT,{children:Or("div",{className:"layer-ui__library-message",children:JT("div",{children:[Or(Bt,{size:"2em"}),Or("span",{children:h("labels.libraryLoadingMessage")})]})})});let u=m.libraryItems.length>0||t.length>0;return JT(qT,{children:[Or(Nf,{isLoading:m.status==="loading",libraryItems:d,onAddToLibrary:p,onInsertLibraryItems:e,pendingElements:t,id:a,libraryReturnUrl:r,theme:s,onSelectItems:c,selectedItems:l}),u&&Or(Fm,{className:"library-menu-control-buttons--at-bottom",style:{padding:"16px 12px 0 12px"},id:a,libraryReturnUrl:r,theme:s})]})}),Bf=(e,t)=>({elements:e,pending:se(e,{selectedElementIds:t},{includeBoundTextElement:!0,includeElementsInFrames:!0}),selectedElementIds:t}),P9=(e,t)=>{let o=Tr(),[n,r]=QT(()=>Bf(o,e.selectedElementIds)),i=y9(new Map);return zf(()=>{for(let a of n.pending)i.current.set(a.id,a.version)},[n.pending]),zf(()=>{t.state.cursorButton==="up"&&t.state.activeTool.type==="selection"&&r(a=>{if(!T9(a.selectedElementIds,e.selectedElementIds))return i.current.clear(),Bf(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!==i.current.get(l))return Bf(o,e.selectedElementIds)}return a})},[t,t.state.cursorButton,t.state.activeTool.type,e.selectedElementIds,o]),n.pending},oI=tI(()=>{let e=Xe(),{onInsertElements:t}=e,o=bn(),n=Ee(),r=ve(),[i,a]=QT([]),s=eI(()=>e.library,[e.library]),l=P9(n,e);zf(()=>k9(document,S9.KEYDOWN,p=>{if(p.key===I9.ESCAPE&&p.target instanceof HTMLElement){let d=p.target;if(d.closest(`.${jT.SIDEBAR}`))i.length>0?(p.stopPropagation(),a([])):C9(d)&&d instanceof HTMLInputElement&&!d.value&&(p.stopPropagation(),r({openSidebar:null}),e.focusContainer());else if(i.length>0){let{x:u,y:b}=e.lastViewportPosition;document.elementFromPoint(u,b)?.closest(`.${jT.SIDEBAR}`)&&(p.stopPropagation(),a([]))}}},{capture:!0}),[i,r,e]);let c=Ff(p=>{t(us(p)),e.focusContainer()},[t,e]),m=Ff(()=>{r({selectedElementIds:{},selectedGroupIds:{},activeEmbeddable:null})},[r]);return Or(M9,{pendingElements:l,onInsertLibraryItems:c,onAddToLibrary:m,setAppState:r,libraryReturnUrl:o.libraryReturnUrl,library:s,id:e.id,theme:n.theme,selectedItems:i,onSelectItems:a})});import A9 from"clsx";import{useRef as L9}from"react";import{createPortal as _9}from"react-dom";import{KEYS as D9}from"@orangecatai/common";import{jsx as nI,jsxs as R9}from"react/jsx-runtime";var rI=e=>{let{closeOnClickOutside:t=!0}=e,o=zd({className:"excalidraw-modal-container"}),n=L9(document.body.classList.contains("excalidraw-animations-disabled"));if(!o)return null;let r=i=>{i.key===D9.ESCAPE&&(i.nativeEvent.stopImmediatePropagation(),i.stopPropagation(),e.onCloseRequest())};return _9(R9("div",{className:A9("Modal",e.className,{"animations-disabled":n.current}),role:"dialog","aria-modal":"true",onKeyDown:r,"aria-labelledby":e.labelledBy,children:[nI("div",{className:"Modal__background",onClick:t?e.onCloseRequest:void 0}),nI("div",{className:"Modal__content",style:{"--max-width":`${e.maxWidth}px`},tabIndex:0,children:e.children})]}),o)};import{jsx as ac,jsxs as H9}from"react/jsx-runtime";function O9(e){if(e&&typeof e=="number")return e;switch(e){case"small":return 550;case"wide":return 1024;case"regular":default:return 800}}var dt=e=>{let[t,o]=j2(),[n]=F9(document.activeElement),{id:r}=Ke(),i=ye().formFactor==="phone";B9(()=>{if(!t)return;let c=iI(t);setTimeout(()=>{c.length>0&&e.autofocus!==!1&&(c[1]||c[0]).focus()});let m=p=>{if(p.key===z9.TAB){let d=iI(t),{activeElement:u}=document,b=d.findIndex(g=>g===u);b===0&&p.shiftKey?(d[d.length-1].focus(),p.preventDefault()):b===d.length-1&&!p.shiftKey&&(d[0].focus(),p.preventDefault())}};return t.addEventListener("keydown",m),()=>t.removeEventListener("keydown",m)},[t,e.autofocus]);let a=ve(),s=mn(gs),l=()=>{a({openMenu:null}),s(!1),n.focus(),e.onCloseRequest()};return ac(rI,{className:N9("Dialog",e.className,{"Dialog--fullscreen":i}),labelledBy:"dialog-title",maxWidth:O9(e.size),onCloseRequest:l,closeOnClickOutside:e.closeOnClickOutside,children:H9(st,{ref:o,children:[e.title&&ac("h2",{id:`${r}-dialog-title`,className:"Dialog__title",children:ac("span",{className:"Dialog__titleContent",children:e.title})}),i&&ac("button",{className:"Dialog__close",onClick:l,title:h("buttons.close"),"aria-label":h("buttons.close"),type:"button",children:To}),ac("div",{className:"Dialog__content",children:e.children})]})})};import{KEYS as nt}from"@orangecatai/common";var $m=[{icon:Ta,value:"hand",key:nt.H,numericKey:null,fillable:!1,toolbar:!0},{icon:xi,value:"selection",key:nt.V,numericKey:nt[1],fillable:!0,toolbar:!0},{icon:fa,value:"rectangle",key:nt.R,numericKey:nt[2],fillable:!0,toolbar:!0},{icon:ba,value:"diamond",key:nt.D,numericKey:nt[3],fillable:!0,toolbar:!0},{icon:xa,value:"ellipse",key:nt.O,numericKey:nt[4],fillable:!0,toolbar:!0},{icon:xd,value:"arrow",key:nt.A,numericKey:nt[5],fillable:!0,toolbar:!0},{icon:Ea,value:"line",key:nt.L,numericKey:nt[6],fillable:!0,toolbar:!0},{icon:un,value:"freedraw",key:[nt.P,nt.X],numericKey:nt[7],fillable:!1,toolbar:!0},{icon:gn,value:"text",key:nt.T,numericKey:nt[8],fillable:!1,toolbar:!0},{icon:xr,value:"image",key:null,numericKey:nt[9],fillable:!1,toolbar:!0},{icon:Ed,value:"eraser",key:nt.E,numericKey:nt[0],fillable:!1,toolbar:!0},{icon:hn,value:"laser",key:nt.K,numericKey:null,fillable:!1,toolbar:!1}],Of=e=>e.state.preferredSelectionTool.type==="lasso"?[{value:"lasso",icon:xi,key:nt.V,numericKey:nt[1],fillable:!0,toolbar:!0},...$m.slice(1)]:$m,aI=(e,t)=>Of(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 In from"clsx";import{useRef as Z9,useState as j9}from"react";import{Popover as Hr}from"radix-ui";import{CLASSES as uI,KEYS as dI,capitalizeString as xs,isTransparent as jm}from"@orangecatai/common";import{shouldAllowVerticalAlign as gI,suppportsHorizontalAlign as hI,hasBoundTextElement as qm,isElbowArrow as Wf,isImageElement as fI,isLinearElement as Yf,isTextElement as Qm,isArrowElement as mI,hasStrokeColor as pI,toolIsArrow as Jm}from"@orangecatai/element";import{createIsolation as G9}from"jotai-scope";import Hf from"react";import Tn from"tunnel-rat";var Gf=Hf.createContext(null),We=()=>Hf.useContext(Gf),U9=G9(),sI=()=>Hf.useMemo(()=>({MainMenuTunnel:Tn(),WelcomeScreenMenuHintTunnel:Tn(),WelcomeScreenToolbarHintTunnel:Tn(),WelcomeScreenHelpHintTunnel:Tn(),WelcomeScreenCenterTunnel:Tn(),FooterCenterTunnel:Tn(),DefaultSidebarTriggerTunnel:Tn(),DefaultSidebarTabTriggersTunnel:Tn(),OverwriteConfirmDialogTunnel:Tn(),TTDDialogTriggerTunnel:Tn(),tunnelsJotai:U9}),[]);import{CODES as W9,KEYS as Y9}from"@orangecatai/common";import{CaptureUpdateAction as V9}from"@orangecatai/element";var Ri=z({name:"viewMode",label:"labels.viewMode",icon:ka,viewMode:!0,trackEvent:{category:"canvas",predicate:e=>!e.viewModeEnabled},perform(e,t){return{appState:{...t,viewModeEnabled:!this.checked(t)},captureUpdate:V9.EVENTUALLY}},checked:e=>e.viewModeEnabled,predicate:(e,t,o)=>typeof o.viewModeEnabled>"u",keyTest:e=>!e[Y9.CTRL_OR_CMD]&&e.altKey&&e.code===W9.R});import{useEffect as K9,useState as X9}from"react";import lI from"clsx";import{capitalizeString as cI}from"@orangecatai/common";import{Popover as Uf}from"radix-ui";import{jsx as Zm,jsxs as $9}from"react/jsx-runtime";var bs=({app:e,options:t,activeTool:o,defaultOption:n,className:r="Shape",namePrefix:i,title:a,"data-testid":s,onToolChange:l,displayedOption:c,fillable:m=!1})=>{let[p,d]=X9(!1),u=o.type,b=c.type===u,g=32/2+10,{container:E}=Ke();return!t.some(y=>y.type===u)&&p&&d(!1),K9(()=>{let y=e.onPointerDownEmitter.on(()=>{d(!1)});return()=>y?.()},[e]),$9(Uf.Root,{open:p,children:[Zm(Uf.Trigger,{asChild:!0,children:Zm(ee,{className:lI(r,{fillable:m,active:t.some(y=>y.type===o.type)}),type:"radio",icon:c.icon,checked:b,name:"editor-current-shape",title:a,"aria-label":a,"data-testid":s,onPointerDown:()=>{d(y=>!y),l(n)}})}),Zm(Uf.Content,{className:"tool-popover-content",sideOffset:g,collisionBoundary:E??void 0,children:t.map(({type:y,icon:x,title:w})=>Zm(ee,{className:lI(r,{active:u===y}),type:"radio",icon:x,checked:u===y,name:`${i}-option`,title:w||cI(y),keyBindingLabel:"","aria-label":w||cI(y),"data-testid":`toolbar-${y}`,onChange:()=>{e.state.activeTool.type!==y&&he("toolbar",y,"ui"),e.setActiveTool({type:y}),l?.(y)}},y))})]})};import{Fragment as yo,jsx as Q,jsxs as Te}from"react/jsx-runtime";var Vf=In([uI.SHAPE_ACTIONS_THEME_SCOPE,"properties-content"]),sc=(e,t)=>{let o=t[0]?.type||null;for(let n of t)if(n.type!==o){o=null;break}return pI(e.activeTool.type)&&o!=="image"&&o!=="frame"&&o!=="magicframe"||t.some(n=>pI(n.type))},lc=(e,t)=>cn(e.activeTool.type)||t.some(o=>cn(o.type)),bI=({appState:e,elementsMap:t,renderAction:o,app:n})=>{let r=ia(t,e),i=!1;r.length===2&&(qm(r[0])||qm(r[1]))&&(i=!0);let a=!!(e.editingTextElement||e.newElement),s=ye(),l=document.documentElement.getAttribute("dir")==="rtl",c=cn(e.activeTool.type)&&!jm(e.currentItemBackgroundColor)||r.some(b=>cn(b.type)&&!jm(b.backgroundColor)),m=r.length===1||i,p=!e.selectedLinearElement?.isEditing&&r.length===1&&Yf(r[0])&&!Wf(r[0]),d=!e.croppingElementId&&r.length===1&&fI(r[0]),u=!i&&jt(e,n);return Te("div",{className:"selected-shape-actions",children:[Q("div",{children:sc(e,r)&&o("changeStrokeColor")}),lc(e,r)&&Q("div",{children:o("changeBackgroundColor")}),c&&o("changeFillStyle"),(al(e.activeTool.type)||r.some(b=>al(b.type)))&&o("changeStrokeWidth"),(e.activeTool.type==="freedraw"||r.some(b=>b.type==="freedraw"))&&o("changeStrokeShape"),(sl(e.activeTool.type)||r.some(b=>sl(b.type)))&&Te(yo,{children:[o("changeStrokeStyle"),o("changeSloppiness")]}),(ll(e.activeTool.type)||r.some(b=>ll(b.type)))&&Q(yo,{children:o("changeRoundness")}),(Jm(e.activeTool.type)||r.some(b=>Jm(b.type)))&&Q(yo,{children:o("changeArrowType")}),(e.activeTool.type==="text"||r.some(Qm))&&Te(yo,{children:[o("changeFontFamily"),o("changeFontSize"),(e.activeTool.type==="text"||hI(r,t))&&o("changeTextAlign")]}),gI(r,t)&&o("changeVerticalAlign"),(aa(e.activeTool.type)||r.some(b=>aa(b.type)))&&Q(yo,{children:o("changeArrowhead")}),o("changeOpacity"),Te("fieldset",{children:[Q("legend",{children:h("labels.layers")}),Te("div",{className:"buttonList",children:[o("sendToBack"),o("sendBackward"),o("bringForward"),o("bringToFront")]})]}),u&&!i&&Te("fieldset",{children:[Q("legend",{children:h("labels.align")}),Te("div",{className:"buttonList",children:[l?Te(yo,{children:[o("alignRight"),o("alignHorizontallyCentered"),o("alignLeft")]}):Te(yo,{children:[o("alignLeft"),o("alignHorizontallyCentered"),o("alignRight")]}),r.length>2&&o("distributeHorizontally"),Q("div",{style:{flexBasis:"100%",height:0}}),Te("div",{style:{display:"flex",flexWrap:"wrap",gap:".5rem",marginTop:"-0.5rem"},children:[o("alignTop"),o("alignVerticallyCentered"),o("alignBottom"),r.length>2&&o("distributeVertically")]})]})]}),!a&&r.length>0&&Te("fieldset",{children:[Q("legend",{children:h("labels.actions")}),Te("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")]})]})]})},xI=({appState:e,renderAction:t,setAppState:o,targetElements:n,container:r})=>{let i=cn(e.activeTool.type)&&!jm(e.currentItemBackgroundColor)||n.some(l=>cn(l.type)&&!jm(l.backgroundColor)),a=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 a?Q("div",{className:"compact-action-item",children:Te(Hr.Root,{open:s,onOpenChange:l=>{o(l?{openPopup:"compactStrokeStyles"}:{openPopup:null})},children:[Q(Hr.Trigger,{asChild:!0,children:Q("button",{type:"button",className:In("compact-action-button properties-trigger",{active:s}),title:h("labels.stroke"),onClick:l=>{l.preventDefault(),l.stopPropagation(),o({openPopup:s?null:"compactStrokeStyles"})},children:Ry})}),s&&Q(Yn,{className:Vf,container:r,style:{maxWidth:"13rem"},onClose:()=>{},children:Te("div",{className:"selected-shape-actions",children:[i&&t("changeFillStyle"),(al(e.activeTool.type)||n.some(l=>al(l.type)))&&t("changeStrokeWidth"),(sl(e.activeTool.type)||n.some(l=>sl(l.type)))&&Te(yo,{children:[t("changeStrokeStyle"),t("changeSloppiness")]}),(ll(e.activeTool.type)||n.some(l=>ll(l.type)))&&t("changeRoundness"),t("changeOpacity")]})})]})}):null},EI=({appState:e,renderAction:t,setAppState:o,targetElements:n,container:r,app:i})=>{let a=Jm(e.activeTool.type)||n.some(l=>Jm(l.type)),s=e.openPopup==="compactArrowProperties";return a?Q("div",{className:"compact-action-item",children:Te(Hr.Root,{open:s,onOpenChange:l=>{o(l?{openPopup:"compactArrowProperties"}:{openPopup:null})},children:[Q(Hr.Trigger,{asChild:!0,children:Q("button",{type:"button",className:In("compact-action-button properties-trigger",{active:s}),title:h("labels.arrowtypes"),onClick:l=>{l.preventDefault(),l.stopPropagation(),o({openPopup:s?null:"compactArrowProperties"})},children:(()=>{let l=Ht(n,i,c=>mI(c)?c.elbowed?"elbow":c.roundness?"round":"sharp":null,c=>mI(c),c=>c?null:e.currentItemArrowType);return l==="elbow"?Pa:l==="round"?Aa:Ma})()})}),s&&Q(Yn,{container:r,className:"properties-content",style:{maxWidth:"13rem"},onClose:()=>{},children:t("changeArrowProperties")})]})}):null},yI=({appState:e,renderAction:t,setAppState:o,targetElements:n,container:r,elementsMap:i})=>{let{saveCaretPosition:a,restoreCaretPosition:s}=ow(),l=e.openPopup==="compactTextProperties";return Q("div",{className:"compact-action-item",children:Te(Hr.Root,{open:l,onOpenChange:c=>{c?(e.editingTextElement&&a(),o({openPopup:"compactTextProperties"})):(o({openPopup:null}),e.editingTextElement&&s())},children:[Q(Hr.Trigger,{asChild:!0,children:Q("button",{type:"button",className:In("compact-action-button properties-trigger",{active:l}),title:h("labels.textAlign"),onClick:c=>{c.preventDefault(),c.stopPropagation(),l?o({openPopup:null}):(e.editingTextElement&&a(),o({openPopup:"compactTextProperties"}))},children:iE})}),e.openPopup==="compactTextProperties"&&Q(Yn,{className:Vf,container:r,style:{maxWidth:"13rem"},preventAutoFocusOnTouch:!!e.editingTextElement,onClose:()=>{e.editingTextElement&&s()},children:Te("div",{className:"selected-shape-actions",children:[(e.activeTool.type==="text"||n.some(Qm))&&t("changeFontSize"),(e.activeTool.type==="text"||hI(n,i))&&t("changeTextAlign"),gI(n,i)&&t("changeVerticalAlign")]})})]})})},wI=({appState:e,renderAction:t,targetElements:o,setAppState:n,container:r,app:i,showDuplicate:a,showDelete:s})=>{let l=!!(e.editingTextElement||e.newElement),c=!e.croppingElementId&&o.length===1&&fI(o[0]),m=o.length===1,p=jt(e,i),d=!1;o.length===2&&(qm(o[0])||qm(o[1]))&&(d=!0);let u=document.documentElement.getAttribute("dir")==="rtl",b=e.openPopup==="compactOtherProperties";return l||o.length===0?null:Q("div",{className:"compact-action-item",children:Te(Hr.Root,{open:b,onOpenChange:g=>{n(g?{openPopup:"compactOtherProperties"}:{openPopup:null})},children:[Q(Hr.Trigger,{asChild:!0,children:Q("button",{type:"button",className:In("compact-action-button properties-trigger",{active:b}),title:h("labels.actions"),onClick:g=>{g.preventDefault(),g.stopPropagation(),n({openPopup:b?null:"compactOtherProperties"})},children:Jx})}),b&&Q(Yn,{className:Vf,container:r,style:{maxWidth:"12rem",justifyContent:"center",alignItems:"center"},onClose:()=>{},children:Te("div",{className:"selected-shape-actions",children:[Te("fieldset",{children:[Q("legend",{children:h("labels.layers")}),Te("div",{className:"buttonList",children:[t("sendToBack"),t("sendBackward"),t("bringForward"),t("bringToFront")]})]}),p&&!d&&Te("fieldset",{children:[Q("legend",{children:h("labels.align")}),Te("div",{className:"buttonList",children:[u?Te(yo,{children:[t("alignRight"),t("alignHorizontallyCentered"),t("alignLeft")]}):Te(yo,{children:[t("alignLeft"),t("alignHorizontallyCentered"),t("alignRight")]}),o.length>2&&t("distributeHorizontally"),Q("div",{style:{flexBasis:"100%",height:0}}),Te("div",{style:{display:"flex",flexWrap:"wrap",gap:".5rem",marginTop:"-0.5rem"},children:[t("alignTop"),t("alignVerticallyCentered"),t("alignBottom"),o.length>2&&t("distributeVertically")]})]})]}),Te("fieldset",{children:[Q("legend",{children:h("labels.actions")}),Te("div",{className:"buttonList",children:[t("group"),t("ungroup"),m&&t("hyperlink"),c&&t("cropEditor"),a&&t("duplicateSelection"),s&&t("deleteSelectedElements")]})]})]})})]})})},q9=({appState:e,renderAction:t,targetElements:o})=>!e.selectedLinearElement?.isEditing&&o.length===1&&Yf(o[0])&&!Wf(o[0])?Q("div",{className:"compact-action-item",children:t("toggleLinearEditor")}):null,vI=({appState:e,elementsMap:t,renderAction:o,app:n,setAppState:r})=>{let i=ia(t,e),{container:a}=Ke(),s=!!(e.editingTextElement||e.newElement),l=!e.selectedLinearElement?.isEditing&&i.length===1&&Yf(i[0])&&!Wf(i[0]);return Te("div",{className:"compact-shape-actions",children:[sc(e,i)&&Q("div",{className:In("compact-action-item"),children:o("changeStrokeColor")}),lc(e,i)&&Q("div",{className:"compact-action-item",children:o("changeBackgroundColor")}),Q(xI,{appState:e,renderAction:o,setAppState:r,targetElements:i,container:a}),Q(EI,{appState:e,renderAction:o,setAppState:r,targetElements:i,container:a,app:n}),l&&Q("div",{className:"compact-action-item",children:o("toggleLinearEditor")}),(e.activeTool.type==="text"||i.some(Qm))&&Te(yo,{children:[Q("div",{className:"compact-action-item",children:o("changeFontFamily")}),Q(yI,{appState:e,renderAction:o,setAppState:r,targetElements:i,container:a,elementsMap:t})]}),!s&&i.length>0&&Q("div",{className:"compact-action-item",children:o("duplicateSelection")}),!s&&i.length>0&&Q("div",{className:"compact-action-item",children:o("deleteSelectedElements")}),Q(wI,{appState:e,renderAction:o,targetElements:i,setAppState:r,container:a,app:n})]})},TI=({appState:e,elementsMap:t,renderAction:o,app:n,setAppState:r})=>{let i=ia(t,e),{container:a}=Ke(),s=Z9(null),l=s.current?.getBoundingClientRect()?.width??0,c=9,m=6,p=32,d=c*p+(c-1)*m,u=p+m,b=l>=d+u,g=l>=d+2*u;return Te(st,{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:[Te("div",{style:{display:"flex",flexDirection:"row",gap:m,flex:1},children:[sc(e,i)&&Q("div",{className:In("compact-action-item"),children:o("changeStrokeColor")}),lc(e,i)&&Q("div",{className:"compact-action-item",children:o("changeBackgroundColor")}),Q(xI,{appState:e,renderAction:o,setAppState:r,targetElements:i,container:a}),Q(EI,{appState:e,renderAction:o,setAppState:r,targetElements:i,container:a,app:n}),Q(q9,{appState:e,renderAction:o,targetElements:i}),(e.activeTool.type==="text"||i.some(Qm))&&Te(yo,{children:[Q("div",{className:"compact-action-item",children:o("changeFontFamily")}),Q(yI,{appState:e,renderAction:o,setAppState:r,targetElements:i,container:a,elementsMap:t})]}),Q(wI,{appState:e,renderAction:o,targetElements:i,setAppState:r,container:a,app:n,showDuplicate:!g,showDelete:!b})]}),Te("div",{style:{display:"flex",flexDirection:"row",gap:m},children:[Q("div",{className:"compact-action-item",children:o("undo")}),Q("div",{className:"compact-action-item",children:o("redo")}),g&&Q("div",{className:"compact-action-item",children:o("duplicateSelection")}),b&&Q("div",{className:"compact-action-item",children:o("deleteSelectedElements")})]})]})},II=({activeTool:e,setAppState:t,app:o,UIOptions:n})=>{let[r,i]=j9(!1),a=kt(),s=a==="full",l=a==="compact",c=[{type:"selection",icon:xi,title:xs(h("toolBar.selection"))},{type:"lasso",icon:br,title:xs(h("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:b}=We();return Te(yo,{children:[Of(o).map(({value:g,icon:E,key:y,numericKey:x,fillable:w,toolbar:v})=>{if(v===!1||n.tools?.[g]===!1)return null;let T=h(`toolBar.${g}`),C=y&&xs(typeof y=="string"?y:y[0]),M=C?`${C} ${h("helpDialog.or")} ${x}`:`${x}`,k=g==="hand"?void 0:x||C;return(g==="selection"||g==="lasso")&&l?Q(bs,{app:o,options:c,activeTool:e,defaultOption:o.state.preferredSelectionTool.type,namePrefix:"selectionType",title:xs(h("toolBar.selection")),"data-testid":"toolbar-selection",onToolChange:R=>{(R==="selection"||R==="lasso")&&(o.setActiveTool({type:R}),t({preferredSelectionTool:{type:R,initialized:!0}}))},displayedOption:c.find(R=>R.type===o.state.preferredSelectionTool.type)||c[0],fillable:e.type==="selection"},"selection-popover"):Q(ee,{className:In("Shape",{fillable:w}),type:"radio",icon:E,checked:e.type===g,name:"editor-current-shape",title:`${xs(T)} \u2014 ${M}`,keyBindingLabel:k,"aria-label":xs(T),"aria-keyshortcuts":M,"data-testid":`toolbar-${g}`,onPointerDown:({pointerType:R})=>{!o.state.penDetected&&R==="pen"&&o.togglePenMode(!0),g==="selection"&&(o.state.activeTool.type==="selection"?o.setActiveTool({type:"lasso"}):o.setActiveTool({type:"selection"}))},onChange:({pointerType:R})=>{o.state.activeTool.type!==g&&he("toolbar",g,"ui"),g==="image"?o.setActiveTool({type:g}):o.setActiveTool({type:g})}},g)}),Q("div",{className:"App-toolbar__divider"}),Te(pe,{open:r,children:[Q(pe.Trigger,{className:In("App-toolbar__extra-tools-trigger",{"App-toolbar__extra-tools-trigger--selected":m||u||d||p&&!o.props.isCollaborating}),onToggle:()=>{i(!r),t({openMenu:null,openPopup:null})},title:h("toolBar.extraTools"),children:m?Vo:u?ya:p&&!o.props.isCollaborating?hn:d?br:yl}),Te(pe.Content,{onClickOutside:()=>i(!1),onSelect:()=>i(!1),className:"App-toolbar__extra-tools-dropdown",children:[Q(pe.Item,{onSelect:()=>o.setActiveTool({type:"frame"}),icon:Vo,shortcut:dI.F.toLocaleUpperCase(),"data-testid":"toolbar-frame",selected:m,children:h("toolBar.frame")}),Q(pe.Item,{onSelect:()=>o.setActiveTool({type:"embeddable"}),icon:ya,"data-testid":"toolbar-embeddable",selected:u,children:h("toolBar.embeddable")}),Q(pe.Item,{onSelect:()=>o.setActiveTool({type:"laser"}),icon:hn,"data-testid":"toolbar-laser",selected:p,shortcut:dI.K.toLocaleUpperCase(),children:h("toolBar.laser")}),s&&Q(pe.Item,{onSelect:()=>o.setActiveTool({type:"lasso"}),icon:br,"data-testid":"toolbar-lasso",selected:d,children:h("toolBar.lasso")}),Q("div",{style:{margin:"6px 0",fontSize:14,fontWeight:600},children:"Generate"}),o.props.aiEnabled!==!1&&Q(b.Out,{}),Q(pe.Item,{onSelect:()=>o.onImageGeneratorSelect(),icon:xr,"data-testid":"toolbar-image-generator",badge:Q(pe.Item.Badge,{children:"AI"}),children:"Image Generator"}),Q(pe.Item,{onSelect:()=>o.setOpenDialog({name:"ttd",tab:"mermaid"}),icon:Ca,"data-testid":"toolbar-embeddable",children:h("toolBar.mermaidToExcalidraw")}),o.props.aiEnabled!==!1&&o.plugins.diagramToCode&&Q(pe.Item,{onSelect:()=>o.onMagicframeToolSelect(),icon:wi,"data-testid":"toolbar-magicframe",badge:Q(pe.Item.Badge,{children:"AI"}),children:h("toolBar.magicframe")})]})]})]})},CI=({renderAction:e})=>e("scrollBackToContent"),kI=({renderAction:e,zoom:t})=>Te(Ft.Row,{align:"center",className:uI.ZOOM_ACTIONS,children:[e("zoomOut"),e("resetZoom"),e("zoomIn")]}),SI=({renderAction:e,className:t})=>Te("div",{className:`undo-redo-buttons ${t}`,children:[Q("div",{className:"undo-button-container",children:Q(ro,{label:h("buttons.undo"),children:e("undo")})}),Q("div",{className:"redo-button-container",children:Te(ro,{label:h("buttons.redo"),children:[" ",e("redo")]})})]}),MI=({actionManager:e,showExitZenModeBtn:t})=>Q("button",{type:"button",className:In("disable-zen-mode",{"disable-zen-mode--visible":t}),onClick:()=>e.executeAction(Dr),children:h("buttons.exitZenMode")}),PI=({actionManager:e})=>Q("button",{type:"button",className:"disable-view-mode",onClick:()=>e.executeAction(Ri),children:By});import{useRef as J9}from"react";var Kf=e=>{let t=J9({userFn:e});return t.current.userFn=e,t.current.stableFn||(t.current.stableFn=(...o)=>t.current.userFn(...o)),t.current.stableFn};import{jsx as eB,jsxs as Q9}from"react/jsx-runtime";var Ni=Ie(null),AI=()=>{let[e,t]=ne(Ni),o=qe();return e&&e==="clearCanvas"?eB(Om,{onConfirm:()=>{o.executeAction(Zn),t(null)},onCancel:()=>t(null),title:h("clearCanvasDialog.title"),children:Q9("p",{className:"clear-canvas__content",children:[" ",h("alerts.clearReset")]})}):null};var Xf={};vx(Xf,{toggleTheme:()=>tB});var tB={...Ci,category:"App",label:"Toggle theme",perform:({actionManager:e})=>{e.executeAction(Ci,"commandPalette")}};import{jsx as Mt,jsxs as Cn}from"react/jsx-runtime";var aB=Ie(null),Je={app:"App",export:"Export",tools:"Tools",editor:"Editor",elements:"Elements",links:"Links",library:"Library"},_I=e=>{switch(e){case Je.app:return 1;case Je.export:return 2;case Je.editor:return 3;case Je.tools:return 4;case Je.elements:return 5;case Je.links:return 6;default:return 10}},op=({shortcut:e,className:t,children:o})=>{let n=e.replace("++","+$").split("+");return Cn("div",{className:RI("shortcut",t),children:[n.map((r,i)=>Mt("div",{className:"shortcut-wrapper",children:Mt("div",{className:"shortcut-key",children:r==="$"?"+":r})},r)),Mt("div",{className:"shortcut-desc",children:o})]})},BI=e=>!e.altKey&&e[Jo.CTRL_OR_CMD]&&(e.shiftKey&&e.key.toLowerCase()===Jo.P||e.key===Jo.SLASH),sB=Object.assign(e=>{let t=Ee(),o=ve();return tp(()=>{let n=r=>{BI(r)&&(r.preventDefault(),r.stopPropagation(),o(i=>{let a=i.openDialog?.name==="commandPalette"?null:{name:"commandPalette"};return a&&he("command_palette","open","shortcut"),{openDialog:a}}))};return window.addEventListener(np.KEYDOWN,n,{capture:!0}),()=>window.removeEventListener(np.KEYDOWN,n,{capture:!0})},[o]),t.openDialog?.name!=="commandPalette"?null:Mt(lB,{...e})},{defaultItems:Xf});function lB({customCommandPaletteItems:e}){let t=Xe(),o=Ee(),n=ve(),r=bn(),i=qe(),[a,s]=ne(aB),[l,c]=ep(null),m=NI(null),p=yr({uiAppState:o,customCommandPaletteItems:e,appProps:r}),[d]=ne(qn),u=nB(()=>d.libraryItems?.filter(k=>!!k.name).map(k=>({label:k.name,icon:Mt(cB,{id:k.id,elements:k.elements}),category:"Library",order:_I("Library"),haystack:_i(k.name),perform:()=>{t.onInsertElements(us([k]))}}))||[],[t,d.libraryItems]);tp(()=>{let{uiAppState:k,customCommandPaletteItems:R,appProps:A}=p,P=H=>{let W="";return H.label&&(typeof H.label=="function"?W=h(H.label(t.scene.getNonDeletedElements(),k,t)):W=h(H.label)),W},_=H=>typeof H.icon=="function"?H.icon(k,t.scene.getNonDeletedElements()):H.icon,O=[],U=(H,W,D)=>{let F={label:P(H),icon:_(H),category:W,shortcut:Ue(H.name),keywords:H.keywords,predicate:H.predicate,viewMode:H.viewMode,perform:()=>{i.executeAction(H,"commandPalette")}};return D?D(F,H):F};if(k&&t.scene&&i){let H=[i.actions.group,i.actions.ungroup,i.actions.cut,i.actions.copy,i.actions.deleteSelectedElements,i.actions.wrapSelectionInFrame,i.actions.copyStyles,i.actions.pasteStyles,i.actions.bringToFront,i.actions.bringForward,i.actions.sendBackward,i.actions.sendToBack,i.actions.alignTop,i.actions.alignBottom,i.actions.alignLeft,i.actions.alignRight,i.actions.alignVerticallyCentered,i.actions.alignHorizontallyCentered,i.actions.duplicateSelection,i.actions.flipHorizontal,i.actions.flipVertical,i.actions.zoomToFitSelection,i.actions.zoomToFitSelectionInViewport,i.actions.increaseFontSize,i.actions.decreaseFontSize,i.actions.toggleLinearEditor,i.actions.cropEditor,i.actions.togglePolygon,Zl,_m,$2].map($=>U($,Je.elements,(ae,xe)=>({...ae,predicate:xe.predicate?xe.predicate:(re,we,Fe,mt)=>se(re,we).length>0}))),W=[i.actions.toggleHandTool,i.actions.setFrameAsActiveTool,i.actions.toggleLassoTool].map($=>U($,Je.tools)),D=[i.actions.undo,i.actions.redo,i.actions.zoomIn,i.actions.zoomOut,i.actions.resetZoom,i.actions.zoomToFit,i.actions.zenMode,i.actions.viewMode,i.actions.gridMode,i.actions.objectsSnapMode,i.actions.toggleShortcuts,i.actions.selectAll,i.actions.toggleElementLock,i.actions.unlockAllElements,i.actions.stats].map($=>U($,Je.editor)),F=[i.actions.saveToActiveFile,i.actions.saveFileToDisk,i.actions.copyAsPng,i.actions.copyAsSvg].map($=>U($,Je.export));O=[...H,...D,{label:P(Zn),icon:_(Zn),shortcut:Ue(Zn.name),category:Je.editor,keywords:["delete","destroy"],viewMode:!1,perform:()=>{pt.set(Ni,"clearCanvas")}},{label:h("buttons.exportImage"),category:Je.export,icon:Td,shortcut:Ue("imageExport"),keywords:["export","image","png","jpeg","svg","clipboard","picture"],perform:()=>{n({openDialog:{name:"imageExport"}})}},...F];let X=[{label:h("toolBar.library"),category:Je.app,icon:bd,viewMode:!1,perform:()=>{k.openSidebar?n({openSidebar:null}):n({openSidebar:{name:LI.name,tab:LI.defaultTab}})}},{label:h("search.title"),category:Je.app,icon:ho,viewMode:!0,perform:()=>{i.executeAction(cc)}},{label:h("labels.shapeSwitch"),category:Je.elements,icon:wl,perform:()=>{i.executeAction(X2)}},{label:h("labels.changeStroke"),keywords:["color","outline"],category:Je.elements,icon:vd,viewMode:!1,predicate:($,ae)=>{let xe=se($,ae);return xe.length>0&&sc(ae,xe)},perform:()=>{n($=>({openPopup:"elementStroke"}))}},{label:h("labels.changeBackground"),keywords:["color","fill"],icon:vd,category:Je.elements,viewMode:!1,predicate:($,ae)=>{let xe=se($,ae);return xe.length>0&&lc(ae,xe)},perform:()=>{n($=>({openPopup:"elementBackground"}))}},{label:h("labels.canvasBackground"),keywords:["color"],icon:vd,category:Je.editor,viewMode:!1,perform:()=>{n($=>({openMenu:$.openMenu==="canvas"?null:"canvas",openPopup:"canvasBackground"}))}},...$m.reduce(($,ae)=>{let{value:xe,icon:re,key:we,numericKey:Fe}=ae;if(A.UIOptions.tools?.[xe]===!1)return $;let ct=we&&rB(typeof we=="string"?we:we[0])||Fe,Ot={label:h(`toolBar.${xe}`),category:Je.tools,shortcut:ct,icon:re,keywords:["toolbar"],viewMode:!1,perform:({event:uo})=>{xe==="image"?t.setActiveTool({type:xe}):t.setActiveTool({type:xe})}};return $.push(Ot),$},[]),...W,{label:h("toolBar.lock"),category:Je.tools,icon:k.activeTool.locked?ha:bi,shortcut:Jo.Q.toLocaleUpperCase(),viewMode:!1,perform:()=>{t.toggleLock()}},{label:`${h("labels.textToDiagram")}...`,category:Je.tools,icon:hy,viewMode:!1,predicate:A.aiEnabled,perform:()=>{n($=>({...$,openDialog:{name:"ttd",tab:"text-to-diagram"}}))}},{label:`${h("toolBar.mermaidToExcalidraw")}...`,category:Je.tools,icon:Ca,viewMode:!1,predicate:A.aiEnabled,perform:()=>{n($=>({...$,openDialog:{name:"ttd",tab:"mermaid"}}))}}],te=[...O,...X,...R||[]].map($=>({...$,icon:$.icon||wl,order:$.order??_I($.category),haystack:`${_i($.label.toLocaleLowerCase())} ${$.keywords?.join(" ")||""}`}));c(te),s([...te,...u].find($=>$.label===a?.label)??null)}},[p,t,i,c,a?.label,s,n,u]);let[b,g]=ep(""),[E,y]=ep(null),[x,w]=ep({}),v=k=>{n({openDialog:null},k),g("")},T=(k,R)=>{o.openDialog?.name==="commandPalette"&&(R.stopPropagation(),R.preventDefault(),document.body.classList.add("excalidraw-animations-disabled"),v(()=>{k.perform({actionManager:i,event:R}),s(k),requestAnimationFrame(()=>{document.body.classList.remove("excalidraw-animations-disabled")})}))},C=Kf(k=>k.viewMode===!1&&o.viewModeEnabled?!1:typeof k.predicate=="function"?k.predicate(t.scene.getNonDeletedElements(),o,r,t):k.predicate===void 0||k.predicate),M=Kf(k=>{let R=iB(k.target)||BI(k)||k.key===Jo.ESCAPE;if(R&&k.key!==Jo.ARROW_UP&&k.key!==Jo.ARROW_DOWN&&k.key!==Jo.ENTER)return;let A=Object.values(x).flat(),P=a&&!b&&C(a);if(k.key===Jo.ARROW_UP){k.preventDefault();let _=A.findIndex(H=>H.label===E?.label);if(P){if(_===0){y(a);return}if(E===a){let H=A[A.length-1];H&&y(H);return}}let O;_===-1?O=A.length-1:O=_===0?A.length-1:(_-1)%A.length;let U=A[O];U&&y(U);return}if(k.key===Jo.ARROW_DOWN){k.preventDefault();let _=A.findIndex(H=>H.label===E?.label);if(P){if(!E||_===A.length-1){y(a);return}if(E===a){let H=A[0];H&&y(H);return}}let O=(_+1)%A.length,U=A[O];U&&y(U);return}if(k.key===Jo.ENTER&&E&&setTimeout(()=>{T(E,k)}),!R){if(k.stopPropagation(),/^[a-zA-Z0-9]$/.test(k.key)){m?.current?.focus();return}k.preventDefault()}});return tp(()=>(window.addEventListener(np.KEYDOWN,M,{capture:!0}),()=>window.removeEventListener(np.KEYDOWN,M,{capture:!0})),[M]),tp(()=>{if(!l)return;let k=_=>{let O={};for(let U of _)O[U.category]?O[U.category].push(U):O[U.category]=[U];return O},R=b?.length>1?[...l.filter(C).sort((_,O)=>_.order-O.order),...u]:l.filter(C).sort((_,O)=>_.order-O.order),A=!b&&a&&C(a);if(!b){w(k(A?R.filter(_=>_.label!==a?.label):R)),y(A?a:R[0]||null);return}let P=_i(b.toLocaleLowerCase().replace(/[<>_| -]/g,""));R=oB.filter(P,R,{extract:_=>_.haystack??""}).sort((_,O)=>O.score-_.score).map(_=>_.original),w(k(R)),y(R[0]??null)},[b,l,C,a,u]),Cn(dt,{onCloseRequest:()=>v(),closeOnClickOutside:!0,title:!1,size:720,autofocus:!0,className:"command-palette-dialog",children:[Mt(zr,{value:b,placeholder:h("commandPalette.search.placeholder"),onChange:k=>{g(k)},selectOnRender:!0,ref:m}),t.editorInterface.formFactor!=="phone"&&Cn("div",{className:"shortcuts-wrapper",children:[Mt(op,{shortcut:"\u2191\u2193",children:h("commandPalette.shortcuts.select")}),Mt(op,{shortcut:"\u21B5",children:h("commandPalette.shortcuts.confirm")}),Mt(op,{shortcut:N("Esc"),children:h("commandPalette.shortcuts.close")})]}),Cn("div",{className:"commands",children:[a&&!b&&Cn("div",{className:"command-category",children:[Cn("div",{className:"command-category-title",children:[h("commandPalette.recents"),Mt("div",{className:"icon",style:{marginLeft:"6px"},children:fy})]}),Mt(DI,{command:a,isSelected:a.label===E?.label,onClick:k=>T(a,k),disabled:!C(a),onMouseMove:()=>y(a),showShortcut:t.editorInterface.formFactor!=="phone",appState:o})]}),Object.keys(x).length>0?Object.keys(x).map((k,R)=>Cn("div",{className:"command-category",children:[Mt("div",{className:"command-category-title",children:k}),x[k].map(A=>Mt(DI,{command:A,isSelected:A.label===E?.label,onClick:P=>T(A,P),onMouseMove:()=>y(A),showShortcut:t.editorInterface.formFactor!=="phone",appState:o,size:k==="Library"?"large":"small"},A.label))]},k)):l?Cn("div",{className:"no-match",children:[Mt("div",{className:"icon",children:ho})," ",h("commandPalette.search.noMatch")]}):null]})]})}var cB=({id:e,elements:t})=>{let o=NI(null),{svgCache:n}=ms();return Dm(e,t,n,o),Mt("div",{className:"library-item-icon",ref:o})},DI=({command:e,isSelected:t,disabled:o,onMouseMove:n,onClick:r,showShortcut:i,appState:a,size:s="small"})=>{let l=()=>{};return Cn("div",{className:RI("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?h("commandPalette.itemNotAvailable"):"",children:[Cn("div",{className:"name",children:[e.icon&&Mt(xn,{className:"icon",size:"var(--icon-size, 1rem)",icon:typeof e.icon=="function"?e.icon(a,[]):e.icon}),Mt(_l,{children:e.label})]}),i&&e.shortcut&&Mt(op,{shortcut:e.shortcut})]})};import{getSizeFromPoints as UIe,randomInteger as dF,getUpdatedTimestamp as mF}from"@orangecatai/common";import{simplify as ZB}from"points-on-curve";import{getStroke as jB}from"perfect-freehand";import{pointsOnBezierCurves as M1e}from"points-on-curve";import{invariant as A1e}from"@orangecatai/common";import{curve as _1e,lineSegment as D1e,pointFrom as R1e,pointDistance as N1e,pointFromArray as B1e,pointFromVector as F1e,pointRotateRads as z1e,polygon as O1e,polygonFromPoints as H1e,PRECISION as G1e,segmentsIntersectAt as U1e,vector as W1e,vectorAdd as Y1e,vectorFromPoint as V1e,vectorScale as K1e}from"@orangecatai/math";import{getElementAbsoluteCoords as $1e}from"@orangecatai/element";var $f=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 qB,pointDistance as e3,pointRotateRads as SIe}from"@orangecatai/math";import{ROUGHNESS as JB,THEME as p0,isTransparent as uc,assertNever as QB,COLOR_PALETTE as eF,LINE_POLYGON_POINT_MERGE_DISTANCE as PIe,applyDarkModeFilter as up}from"@orangecatai/common";import{RoughGenerator as tF}from"roughjs/bin/generator";import FTe from"roughjs/bin/rough";import{isRightAngleRads as OTe,lineSegment as HTe,pointFrom as GTe,pointRotateRads as UTe}from"@orangecatai/math";import{BOUND_TEXT_PADDING as YTe,DEFAULT_REDUCED_GLOBAL_ALPHA as VTe,ELEMENT_READY_TO_ERASE_OPACITY as KTe,FRAME_STYLE as XTe,DARK_THEME_FILTER as $Te,MIME_TYPES as JI,THEME as ZTe,distance as jTe,getFontString as qTe,isRTL as JTe,getVerticalOffset as QTe,invariant as eIe,applyDarkModeFilter as tIe,isSafari as oIe}from"@orangecatai/common";import Zve from"roughjs/bin/rough";import{arrayToMap as qve,invariant as VI,rescalePoints as Jve,sizeOf as Qve}from"@orangecatai/common";import{degreesToRadians as a0,lineSegment as t2e,pointDistance as o2e,pointFrom as zt,pointFromArray as LB,pointRotateRads as Ts}from"@orangecatai/math";import{pointsOnBezierCurves as i2e}from"points-on-curve";import{pointCenter as dve,pointFrom as mve,pointRotateRads as pve,pointsEqual as uve,pointDistance as gve,vectorFromPoint as hve,curveLength as fve,curvePointAtLength as bve}from"@orangecatai/math";import{DRAGGING_THRESHOLD as yve,KEYS as wve,shouldRotateWithDiscreteAngle as vve,getGridPoint as Tve,invariant as Ive,isShallowEqual as Cve,getFeatureFlag as kve}from"@orangecatai/common";import{deconstructLinearOrFreeDrawElement as Mve,getSnapOutlineMidPoint as Pve,isPathALoop as Ave,moveArrowAboveBindable as Lve,projectFixedPointOntoDiagonal as _ve}from"@orangecatai/element";import{KEYS as dwe,arrayToMap as mwe,getFeatureFlag as pwe,invariant as uwe,isTransparent as gwe}from"@orangecatai/common";import{PRECISION as fwe,clamp as bwe,lineSegment as xwe,pointDistance as Ewe,pointDistanceSq as ywe,pointFrom as wwe,pointFromVector as vwe,pointRotateRads as Twe,pointsEqual as Iwe,vectorFromPoint as Cwe,vectorNormalize as kwe,vectorScale as Swe}from"@orangecatai/math";import{invariant as BEe,isTransparent as FEe}from"@orangecatai/common";import{curveIntersectLineSegment as OEe,isPointWithinBounds as HEe,lineSegment as GEe,lineSegmentIntersectionPoints as UEe,pointFrom as WEe,pointFromVector as YEe,pointRotateRads as VEe,pointsEqual as KEe,vectorFromPoint as XEe,vectorNormalize as $Ee,vectorScale as ZEe}from"@orangecatai/math";import{ellipse as qEe,ellipseSegmentInterceptPoints as JEe}from"@orangecatai/math/ellipse";import{DEFAULT_ADAPTIVE_RADIUS as pB,DEFAULT_PROPORTIONAL_RADIUS as jf,invariant as ixe,LINE_CONFIRM_THRESHOLD as uB,ROUNDNESS as qf}from"@orangecatai/common";import{bezierEquation as sxe,curve as lxe,curveCatmullRomCubicApproxPoints as cxe,curveOffsetPoints as dxe,lineSegment as mxe,lineSegmentIntersectionPoints as pxe,pointDistance as gB,pointFrom as uxe,pointFromArray as gxe,pointFromVector as hxe,pointRotateRads as fxe,pointTranslate as bxe,rectangle as xxe,vectorFromPoint as Exe,vectorNormalize as yxe,vectorScale as wxe}from"@orangecatai/math";import{ROUNDNESS as J1e,assertNever as Q1e}from"@orangecatai/common";import{pointsEqual as txe}from"@orangecatai/math";var FI=e=>!!e&&e.type==="embeddable",zI=e=>!!e&&e.type==="iframe",Zf=e=>!!e&&(e.type==="iframe"||e.type==="embeddable"),Bi=e=>e!=null&&e.type==="text";var rp=e=>e!=null&&(e.type==="frame"||e.type==="magicframe");var Fi=e=>e!=null&&dB(e.type);var zi=e=>e!=null&&e.type==="arrow",dc=e=>zi(e)&&e.elbowed;var dB=e=>e==="arrow"||e==="line";var Es=e=>e!==null&&"containerId"in e&&e.containerId!==null&&Bi(e);var ip=(e,t=1)=>{if(e.length>=3){let[o,n]=[e[0],e[e.length-1]];return gB(o,n)<=uB/t}return!1},mc=(e,t)=>{if(t.roundness?.type===qf.PROPORTIONAL_RADIUS||t.roundness?.type===qf.LEGACY)return e*jf;if(t.roundness?.type===qf.ADAPTIVE_RADIUS){let o=t.roundness?.value??pB,n=o/jf;return e<=n?e*jf:o}return 0};import{ARROW_LABEL_FONT_SIZE_TO_MIN_WIDTH_RATIO as iEe,ARROW_LABEL_WIDTH_FRACTION as aEe,BOUND_TEXT_PADDING as sEe,DEFAULT_FONT_SIZE as lEe,TEXT_ALIGN as cEe,VERTICAL_ALIGN as dEe,getFontString as mEe,isProdEnv as pEe,invariant as uEe}from"@orangecatai/common";import{pointFrom as hEe,pointRotateRads as fEe}from"@orangecatai/math";import{BOUND_TEXT_PADDING as Bxe,DEFAULT_FONT_SIZE as Fxe,DEFAULT_FONT_FAMILY as zxe,getFontString as Oxe,isTestEnv as Hxe,normalizeEOL as Gxe}from"@orangecatai/common";var Uxe="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".toLocaleUpperCase();import{isDevEnv as Zxe,isTestEnv as jxe}from"@orangecatai/common";import{curvePointDistance as CEe,distanceToLineSegment as kEe,pointRotateRads as SEe}from"@orangecatai/math";import{ellipse as PEe,ellipseDistanceFromPoint as AEe}from"@orangecatai/math/ellipse";import{invariant as pye,isDevEnv as uye,isTestEnv as gye}from"@orangecatai/common";import{pointFrom as fye,pointFromVector as bye,pointRotateRads as xye,pointScaleFromOrigin as Eye,pointsEqual as yye,triangleIncludesPoint as wye,vectorCross as vye,vectorFromPoint as IB,vectorScale as Tye}from"@orangecatai/math";var r0=[1,0],GI=[0,1],i0=[-1,0],UI=[0,-1],lp=e=>{let[t,o]=e,n=Math.abs(t),r=Math.abs(o);return t>r?r0:t<=-r?i0:o>n?GI:UI},WI=(e,t)=>lp(IB(e,t)),cp=(e,t)=>dp(WI(e,t)),n0=(e,t)=>e[0]===t[0]&&e[1]===t[1],dp=e=>n0(e,r0)||n0(e,i0);import{clamp as Pye,pointDistance as Aye,pointFrom as Lye,pointScaleFromOrigin as _ye,pointsEqual as Dye,pointTranslate as Rye,vector as Nye,vectorCross as Bye,vectorFromPoint as Fye,vectorScale as zye}from"@orangecatai/math";import{BinaryHeap as Hye,invariant as Gye,isAnyTrue as Uye,getSizeFromPoints as Wye,isDevEnv as Yye,arrayToMap as Vye}from"@orangecatai/common";var Owe=10/1.5;import{SHIFT_LOCKING_ANGLE as Ywe,viewportCoordsToSceneCoords as Vwe}from"@orangecatai/common";import{normalizeRadians as Xwe,radiansBetweenAngles as $we,radiansDifference as Zwe}from"@orangecatai/math";import{pointsEqual as qwe}from"@orangecatai/math";var ap=e=>{let t=Math.floor(e.width/2)+1,o=0,n=e.width,r=Math.floor(e.height/2)+1,i=t,a=e.height;return[t,o,n,r,i,a,0,r]};var _B=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}},DB=e=>{switch(e){case"bar":return 90;case"arrow":return 20;default:return 25}},s0=(e,t,o,n)=>{if(t.length<1)return null;let r=$f(t[0]);if(r.length<1)return null;let i=o==="start"?1:r.length-1,a=r[i].data;VI(a.length===6,"Op data length is not 6");let s=zt(a[4],a[5]),l=zt(a[2],a[3]),c=zt(a[0],a[1]),m=r[i-1],p=zt(0,0);if(m.op==="move"){let H=LB(m.data);VI(H!=null,"Op data is not a point"),p=H}else m.op==="bcurveTo"&&(p=zt(m.data[4],m.data[5]));let d=(H,W)=>Math.pow(1-H,3)*s[W]+3*H*Math.pow(1-H,2)*l[W]+3*Math.pow(H,2)*(1-H)*c[W]+p[W]*Math.pow(H,3),[u,b]=o==="start"?p:s,[g,E]=[d(.3,0),d(.3,1)],y=Math.hypot(u-g,b-E),x=(u-g)/y,w=(b-E)/y,v=_B(n),T=0;{let[H,W]=o==="end"?e.points[e.points.length-1]:e.points[0],[D,F]=e.points.length>1?o==="end"?e.points[e.points.length-2]:e.points[1]:[0,0];T=Math.hypot(H-D,W-F)}let M=Math.min(v,T*(n==="diamond"||n==="diamond_outline"?.25:.5)),k=u-x*M,R=b-w*M;if(n==="dot"||n==="circle"||n==="circle_outline"){let H=Math.hypot(R-b,k-u)+e.strokeWidth-2;return[u,b,H]}let A=DB(n);if(n==="crowfoot_many"||n==="crowfoot_one_or_many"){let[H,W]=Ts(zt(u,b),zt(k,R),a0(-A)),[D,F]=Ts(zt(u,b),zt(k,R),a0(A));return[k,R,H,W,D,F]}let[P,_]=Ts(zt(k,R),zt(u,b),-A*Math.PI/180),[O,U]=Ts(zt(k,R),zt(u,b),a0(A));if(n==="diamond"||n==="diamond_outline"){let H,W;if(o==="start"){let[D,F]=e.points.length>1?e.points[1]:[0,0];[H,W]=Ts(zt(u+M*2,b),zt(u,b),Math.atan2(F-b,D-u))}else{let[D,F]=e.points.length>1?e.points[e.points.length-2]:[0,0];[H,W]=Ts(zt(u-M*2,b),zt(u,b),Math.atan2(b-F,u-D))}return[u,b,P,_,H,W,O,U]}return[u,b,P,_,O,U]};import{pointFrom as E2e,pointCenter as y2e,pointRotateRads as w2e,vectorFromPoint as v2e,vectorNormalize as T2e,vectorSubtract as I2e,vectorAdd as C2e,vectorScale as k2e,pointFromVector as S2e,clamp as M2e,isCloseTo as P2e}from"@orangecatai/math";import{arrayToMap as hTe}from"@orangecatai/common";import{isPointWithinBounds as bTe,pointFrom as xTe}from"@orangecatai/math";import{vectorCross as R2e,vectorFromPoint as N2e}from"@orangecatai/math";import{arrayToMap as RB}from"@orangecatai/common";import{getElementBounds as NB}from"@orangecatai/element";import{isArrowElement as BB,isExcalidrawElement as FB,isFreeDrawElement as zB,isLinearElement as OB,isTextElement as HB}from"@orangecatai/element";import{rangeIncludesValue as mp,pointFrom as tr,pointRotateRads as GB,rangeInclusive as pp}from"@orangecatai/math";var UB=e=>e.type==="diamond"?[tr(e.width/2,0),tr(e.width,e.height/2),tr(e.width/2,e.height),tr(0,e.height/2)]:[tr(0,0),tr(0+e.width,0),tr(0+e.width,e.height),tr(0,e.height)],WB=e=>OB(e)||zB(e)?e.points:UB(e),XI=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},$I=e=>{let t=WB(e),{cx:o,cy:n}=XI(t),r=tr(o,n),i=t.map(m=>GB(m,r,e.angle)),{minX:a,minY:s,maxX:l,maxY:c}=XI(i);return[a+e.x,s+e.y,l+e.x,c+e.y]},l0=(e,t,o=!1)=>{let n=$I(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},ZI=(e,t)=>{let o=$I(e);return(mp(o[0],pp(t[0],t[2]))||mp(t[0],pp(o[0],o[2])))&&(mp(o[1],pp(t[1],t[3]))||mp(t[1],pp(o[1],o[3])))},jI=({elements:e,bounds:t,type:o,errorMargin:n=0})=>{FB(t)&&(t=NB(t,RB(e)));let r=[t[0]-n,t[1]-n,t[2]+n,t[3]+n],i=new Set;for(let a of e){if(i.has(a.id))continue;if(o==="overlap"?ZI(a,r):o==="inside"?l0(a,r):l0(a,r,!0)){if(i.add(a.id),a.boundElements)for(let l of a.boundElements)i.add(l.id);HB(a)&&a.containerId&&i.add(a.containerId),BB(a)&&(a.startBinding&&i.add(a.startBinding.elementId),a.endBinding&&i.add(a.endBinding?.elementId))}}return e.filter(a=>i.has(a.id))};import{arrayToMap as q2e,isShallowEqual as VB}from"@orangecatai/common";var YB=function(){let e=null,t=null,o=null,n=(i,a,s,l)=>{if(o!==void 0&&a===t&&i===e&&s.editingGroupId===o?.editingGroupId)return o;let c={};for(let d of i){let u=d.groupIds;if(s.editingGroupId){let b=u.indexOf(s.editingGroupId);b>-1&&(u=u.slice(0,b))}if(u.length>0){let b=u[u.length-1];c[b]=!0}}let m={},p=a.reduce((d,u)=>{if(u.isDeleted)return d;let b=u.groupIds.find(g=>c[g]);return b&&(d[u.id]=!0,Array.isArray(m[b])?m[b].push(u.id):m[b]=[u.id]),d},{});for(let d of Object.keys(m))m[d].length<2&&c[d]&&(c[d]=!1);return t=a,e=i,o={editingGroupId:s.editingGroupId,selectedGroupIds:c,selectedElementIds:c0({...s.selectedElementIds,...p},l)},o},r=(i,a,s,l)=>{let c=l?l.scene.getSelectedElements({selectedElementIds:i.selectedElementIds,elements:a}):d0(a,i);return c.length?n(c,a,i,s):{selectedGroupIds:{},editingGroupId:null,selectedElementIds:c0(i.selectedElementIds,s)}};return r.clearCache=()=>{t=null,e=null,o=null},r}();var rTe=function(){let e=null,t=null,o=null,n=(r,i)=>(o!=null&&r===e&&i.selectedElementIds===t||(o=r.some(a=>i.selectedElementIds[a.id]),e=r,t=i.selectedElementIds),o);return n.clearCache=()=>{e=null,t=null,o=null},n}(),d0=(e,t,o)=>{let n=new Set,r=[];for(let i of e.values()){if(t.selectedElementIds[i.id]){r.push(i),n.add(i.id);continue}if(o?.includeBoundTextElement&&Es(i)&&t.selectedElementIds[i?.containerId]){r.push(i),n.add(i.id);continue}}if(o?.includeElementsInFrames){let i=[];return r.forEach(a=>{rp(a)&&qI(e,a.id).forEach(s=>!n.has(s.id)&&i.push(s)),i.push(a)}),i}return r};var c0=(e,t)=>VB(t.selectedElementIds,e)?t.selectedElementIds:e;var qI=(e,t)=>{let o=[];for(let n of e.values())n.frameId===t&&o.push(n);return o};var XB=typeof document<"u"?document.createElement("img"):{src:""};XB.src=`data:${JI.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 $B=typeof document<"u"?document.createElement("img"):{src:""};$B.src=`data:${JI.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 m0=new WeakMap;var QI=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="line"||e==="diamond"||e==="image";var ao=class ao{};S(ao,"rg",new tF),S(ao,"cache",new WeakMap),S(ao,"get",(t,o)=>{let n=ao.cache.get(t);if(n&&(o===null||n.theme===o))return n.shape}),S(ao,"delete",t=>{ao.cache.delete(t),m0.delete(t)}),S(ao,"destroy",()=>{ao.cache=new WeakMap}),S(ao,"generateElementShape",(t,o)=>{let n=o?.isExporting?void 0:ao.get(t,o?o.theme:null);if(n!==void 0)return n;m0.delete(t);let r=rF(t,ao.rg,o||{isExporting:!1,canvasBackgroundColor:eF.white,embedsValidationStatus:null,theme:p0.LIGHT});return o?.isExporting||ao.cache.set(t,{shape:r,theme:o?.theme||p0.LIGHT}),r});var vs=ao,oF=e=>[8,8+e],r3=e=>[1.5,6+e];function nF(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&&QI(e.type)||Fi(e)&&o>=50?t:Math.min(t/(o<10?3:2),2.5)}var er=(e,t=!1,o=!1)=>{let n={seed:e.seed,strokeLineDash:e.strokeStyle==="dashed"?oF(e.strokeWidth):e.strokeStyle==="dotted"?r3(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:nF(e),stroke:o?up(e.strokeColor):e.strokeColor,preserveVertices:t||e.roughness<JB.cartoonist};switch(e.type){case"rectangle":case"iframe":case"embeddable":case"diamond":case"ellipse":return n.fillStyle=e.fillStyle,n.fill=uc(e.backgroundColor)?void 0:o?up(e.backgroundColor):e.backgroundColor,e.type==="ellipse"&&(n.curveFitting=1),n;case"line":case"freedraw":return ip(e.points)&&(n.fillStyle=e.fillStyle,n.fill=e.backgroundColor==="transparent"?void 0:o?up(e.backgroundColor):e.backgroundColor),n;case"arrow":return n;default:throw new Error(`Unimplemented type ${e.type}`)}},t3=(e,t,o)=>Zf(e)&&(t||FI(e)&&o?.get(e.id)!==!0)&&uc(e.backgroundColor)&&uc(e.strokeColor)?{...e,roughness:0,backgroundColor:"#d3d3d3",fillStyle:"solid"}:zI(e)?{...e,strokeColor:uc(e.strokeColor)?"#000000":e.strokeColor,backgroundColor:uc(e.backgroundColor)?"#f4f4f6":e.backgroundColor}:e,o3=(e,t,o,n,r,i,a,s)=>{let l=s0(e,t,o,n);if(l===null)return[];let c=(p,d)=>{if(p===null)return[];let[,,u,b,g,E]=p;return[r.line(u,b,g,E,d)]},m=s?up(e.strokeColor):e.strokeColor;switch(n){case"dot":case"circle":case"circle_outline":{let[p,d,u]=l;return delete i.strokeLineDash,[r.circle(p,d,u,{...i,fill:n==="circle_outline"?a:m,fillStyle:"solid",stroke:m,roughness:Math.min(.5,i.roughness||0)})]}case"triangle":case"triangle_outline":{let[p,d,u,b,g,E]=l;return delete i.strokeLineDash,[r.polygon([[p,d],[u,b],[g,E],[p,d]],{...i,fill:n==="triangle_outline"?a:m,fillStyle:"solid",roughness:Math.min(1,i.roughness||0)})]}case"diamond":case"diamond_outline":{let[p,d,u,b,g,E,y,x]=l;return delete i.strokeLineDash,[r.polygon([[p,d],[u,b],[g,E],[y,x],[p,d]],{...i,fill:n==="diamond_outline"?a:m,fillStyle:"solid",roughness:Math.min(1,i.roughness||0)})]}case"crowfoot_one":return c(l,i);case"bar":case"arrow":case"crowfoot_many":case"crowfoot_one_or_many":default:{let[p,d,u,b,g,E]=l;if(e.strokeStyle==="dotted"){let y=r3(e.strokeWidth-1);i.strokeLineDash=[y[0],y[1]-1]}else delete i.strokeLineDash;return i.roughness=Math.min(1,i.roughness||0),[r.line(u,b,p,d,i),r.line(g,E,p,d,i),...n==="crowfoot_one_or_many"?c(s0(e,t,o,"crowfoot_one"),i):[]]}}};var rF=(e,t,{isExporting:o,canvasBackgroundColor:n,embedsValidationStatus:r,theme:i})=>{let a=i===p0.DARK;switch(e.type){case"rectangle":case"iframe":case"embeddable":{let s;if(e.roundness){let l=e.width,c=e.height,m=mc(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`,er(t3(e,o,r),!0,a))}else s=t.rectangle(0,0,e.width,e.height,er(t3(e,o,r),!1,a));return s}case"diamond":{let s,[l,c,m,p,d,u,b,g]=ap(e);if(e.roundness){let E=mc(Math.abs(l-b),e),y=mc(Math.abs(p-c),e);s=t.path(`M ${l+E} ${c+y} L ${m-E} ${p-y}
|
|
8
|
+
C ${m} ${p}, ${m} ${p}, ${m-E} ${p+y}
|
|
9
|
+
L ${d+E} ${u-y}
|
|
10
|
+
C ${d} ${u}, ${d} ${u}, ${d-E} ${u-y}
|
|
11
|
+
L ${b+E} ${g+y}
|
|
12
|
+
C ${b} ${g}, ${b} ${g}, ${b+E} ${g-y}
|
|
13
|
+
L ${l-E} ${c+y}
|
|
14
|
+
C ${l} ${c}, ${l} ${c}, ${l+E} ${c+y}`,er(e,!0,a))}else s=t.polygon([[l,c],[m,p],[d,u],[b,g]],er(e,!1,a));return s}case"ellipse":return t.ellipse(e.width/2,e.height/2,e.width,e.height,er(e,!1,a));case"line":case"arrow":{let s,l=er(e,!1,a),c=e.points.length?e.points:[qB(0,0)];if(dc(e)?c.every(m=>Math.abs(m[0])<=1e6&&Math.abs(m[1])<=1e6)?s=[t.path(iF(c,16),er(e,!0,a))]:(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=o3(e,s,"start",m,t,l,n,a);s.push(...d)}if(p!==null){let d=o3(e,s,"end",p,t,l,n,a);s.push(...d)}}return s}case"freedraw":{let s=[];if(ip(e.points)){let l=ZB(e.points,.75);s.push(t.curve(l,{...er(e,!1,a),stroke:"none"}))}return s.push(aF(e)),s}case"frame":case"magicframe":case"text":case"image":return null;default:return QB(e,`generateElementShape(): Unimplemented type ${e?.type}`),null}},iF=(e,t)=>{let o=[];for(let r=1;r<e.length-1;r+=1){let i=e[r-1],a=e[r+1],s=e[r],l=cp(s,i),c=cp(a,s),m=Math.min(t,e3(e[r],a)/2,e3(e[r],i)/2);l?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]),o.push(e[r]),c?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])}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 aF=e=>cF(sF(e)),sF=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 jB(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})},n3=(e,t)=>[(e[0]+t[0])/2,(e[1]+t[1])/2],lF=/(\s?[A-Z]?,?-?[0-9]*\.[0-9]{0,2})(([0-9]|e|-)*)/g,cF=e=>{if(!e.length)return"";let t=e.length-1;return e.reduce((o,n,r,i)=>(r===t?o.push(n,n3(n,i[0]),"L",i[0],"Z"):o.push(n,n3(n,i[r+1])),o),["M",e[0],"Q"]).join(" ").replace(lF,"$1")};var i3=(e,t,o=!1)=>{let n=!1;for(let r in t){let i=t[r];if(typeof i<"u"){if(e[r]===i&&(typeof i!="object"||i===null))continue;n=!0}}return!n&&!o?e:{...e,...t,version:t.version??e.version+1,versionNonce:t.versionNonce??dF(),updated:mF()}};import{jsx as s3}from"react/jsx-runtime";var Cs=z({name:"toggleLinearEditor",category:Je.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&&uF(r[0])&&!pF(r[0]))},perform(e,t,o,n){let r=n.scene.getSelectedElements({selectedElementIds:t.selectedElementIds,includeBoundTextElement:!0})[0];u0(r,"No selected element found"),u0(t.selectedLinearElement,"No selected linear element found"),u0(r.id===t.selectedLinearElement.elementId,"Selected element ID and linear editor elementId does not match");let i={...t.selectedLinearElement,isEditing:!t.selectedLinearElement.isEditing};return{appState:{...t,selectedLinearElement:i},captureUpdate:a3.IMMEDIATELY}},PanelComponent:({appState:e,updateData:t,app:o})=>{let n=o.scene.getSelectedElements({selectedElementIds:e.selectedElementIds})[0];if(!n)return null;let r=h(n.type==="arrow"?"labels.lineEditor.editArrow":"labels.lineEditor.edit");return s3(ee,{type:"button",icon:Ly,title:r,"aria-label":r,onClick:()=>t(null)})}}),r3e=z({name:"togglePolygon",category:Je.elements,icon:ig,keywords:["loop"],label:(e,t,o)=>!o.scene.getSelectedElements({selectedElementIds:t.selectedElementIds}).some(i=>!Is(i)||!i.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(i=>Is(i)&&i.points.length>=4)},perform(e,t,o,n){let r=n.scene.getSelectedElements(t);if(r.some(l=>!Is(l)))return!1;let i=r,a=i.some(l=>!l.polygon),s=gF(i);return{elements:e.map(l=>!s.has(l.id)||!Is(l)?l:i3(l,{backgroundColor:a?l.backgroundColor:"transparent",...hF(l,a)})),appState:t,captureUpdate:a3.IMMEDIATELY}},PanelComponent:({appState:e,updateData:t,app:o})=>{let n=o.scene.getSelectedElements({selectedElementIds:e.selectedElementIds});if(n.length===0||n.some(a=>!Is(a)||!a.polygon||a.points.length<3))return null;let r=n.every(a=>Is(a)&&a.polygon),i=h(r?"labels.polygon.breakPolygon":"labels.polygon.convertToPolygon");return s3(Da,{icon:ig,title:i,"aria-label":i,active:r,onClick:()=>t(null),style:{marginLeft:"auto"}})}});import{KEYS as l3,CANVAS_SEARCH_TAB as c3,CLASSES as fF,DEFAULT_SIDEBAR as d3}from"@orangecatai/common";import{CaptureUpdateAction as bF}from"@orangecatai/element";var cc=z({name:"searchMenu",icon:ho,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===d3.name&&t.openSidebar.tab===c3){let r=n.excalidrawContainerValue.container?.querySelector(`.${fF.SEARCH_MENU_INPUT_WRAPPER} input`);return r?.focus(),r?.select(),!1}return{appState:{...t,openSidebar:{name:d3.name,tab:c3},openDialog:null},captureUpdate:bF.EVENTUALLY}},checked:e=>e.gridModeEnabled,predicate:(e,t,o)=>o.gridModeEnabled===void 0,keyTest:e=>e[l3.CTRL_OR_CMD]&&e.key===l3.F});import{isImageElement as xF}from"@orangecatai/element";import{CaptureUpdateAction as EF}from"@orangecatai/element";import{jsx as yF}from"react/jsx-runtime";var g0=z({name:"cropEditor",label:"helpDialog.cropStart",icon:Sg,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:EF.IMMEDIATELY}},predicate:(e,t,o,n)=>{let r=n.scene.getSelectedElements(t);return!!(!t.croppingElementId&&r.length===1&&xF(r[0]))},PanelComponent:({appState:e,updateData:t,app:o})=>{let n=h("helpDialog.cropStart");return yF(ee,{type:"button",icon:Sg,title:n,"aria-label":n,onClick:()=>t(null)})}});import{getNonDeletedElements as wF}from"@orangecatai/element";import{mutateElement as vF}from"@orangecatai/element";import{newFrameElement as TF}from"@orangecatai/element";import{isFrameLikeElement as gp}from"@orangecatai/element";import{addElementsToFrame as IF,removeAllElementsFromFrame as CF}from"@orangecatai/element";import{getFrameChildren as kF}from"@orangecatai/element";import{KEYS as m3,updateActiveTool as p3}from"@orangecatai/common";import{getElementsInGroup as SF}from"@orangecatai/element";import{getCommonBounds as MF}from"@orangecatai/element";import{CaptureUpdateAction as Oi}from"@orangecatai/element";var u3=(e,t)=>{let o=t.scene.getSelectedElements(e);return o.length===1&&gp(o[0])},g3=z({name:"selectAllElementsInFrame",label:"labels.selectAllElementsInFrame",trackEvent:{category:"canvas"},perform:(e,t,o,n)=>{let r=n.scene.getSelectedElements(t).at(0)||null;if(gp(r)){let i=kF(wF(e),r.id).filter(a=>!(a.type==="text"&&a.containerId));return{elements:e,appState:{...t,selectedElementIds:i.reduce((a,s)=>(a[s.id]=!0,a),{})},captureUpdate:Oi.IMMEDIATELY}}return{elements:e,appState:t,captureUpdate:Oi.EVENTUALLY}},predicate:(e,t,o,n)=>u3(t,n)}),h3=z({name:"removeAllElementsFromFrame",label:"labels.removeAllElementsFromFrame",trackEvent:{category:"history"},perform:(e,t,o,n)=>{let r=n.scene.getSelectedElements(t).at(0)||null;return gp(r)?{elements:CF(e,r),appState:{...t,selectedElementIds:{[r.id]:!0}},captureUpdate:Oi.IMMEDIATELY}:{elements:e,appState:t,captureUpdate:Oi.EVENTUALLY}},predicate:(e,t,o,n)=>u3(t,n)}),u5e=z({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:Oi.EVENTUALLY}),checked:e=>e.frameRendering.enabled}),g5e=z({name:"setFrameAsActiveTool",label:"toolBar.frame",trackEvent:{category:"toolbar"},icon:Vo,viewMode:!1,perform:(e,t,o,n)=>{let r=p3(t,{type:"frame"});return bo(n.interactiveCanvas,{...t,activeTool:r}),{elements:e,appState:{...t,activeTool:p3(t,{type:"frame"})},captureUpdate:Oi.EVENTUALLY}},keyTest:e=>!e[m3.CTRL_OR_CMD]&&!e.shiftKey&&!e.altKey&&e.key.toLocaleLowerCase()===m3.F}),f3=z({name:"wrapSelectionInFrame",label:"labels.wrapSelectionInFrame",trackEvent:{category:"element"},predicate:(e,t,o,n)=>{let r=se(e,t);return r.length>0&&!r.some(i=>gp(i))},perform:(e,t,o,n)=>{let r=se(e,t),i=n.scene.getNonDeletedElementsMap(),[a,s,l,c]=MF(r,i),m=16,p=TF({x:a-m,y:s-m,width:l-a+m*2,height:c-s+m*2});if(t.editingGroupId){let u=SF(r,t.editingGroupId);for(let b of u){let g=b.groupIds.indexOf(t.editingGroupId);vF(b,i,{groupIds:b.groupIds.slice(0,g)})}}return{elements:IF([...n.scene.getElementsIncludingDeleted(),p],r,p,t),appState:{selectedElementIds:{[p.id]:!0}},captureUpdate:Oi.IMMEDIATELY}}});import{isWindows as NF,KEYS as hc,matchKey as b0,arrayToMap as b3,MOBILE_ACTION_BUTTON_BG as x3}from"@orangecatai/common";import{CaptureUpdateAction as f0}from"@orangecatai/element";import{orderByFractionalIndex as BF}from"@orangecatai/element";import{Emitter as PF}from"@orangecatai/common";import{CaptureUpdateAction as AF,StoreChange as LF,StoreDelta as _F}from"@orangecatai/element";var ks=class extends _F{applyTo(t,o,n){let[r,i]=this.elements.applyTo(t,n.elements,{excludedProperties:new Set(["version","versionNonce"])}),[a,s]=this.appState.applyTo(o,r);return[r,a,i||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)}},Hi=class{constructor(t=!0,o=!0){this.isUndoStackEmpty=t;this.isRedoStackEmpty=o}},gc=class e{constructor(t){this.store=t;S(this,"onHistoryChangedEmitter",new PF);S(this,"undoStack",[]);S(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 ks)return;let o=ks.inverse(t);this.undoStack.push(o),o.elements.isEmpty()||(this.redoStack.length=0),this.onHistoryChangedEmitter.trigger(new Hi(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 i=n();if(i===null)return;let a=AF.IMMEDIATELY,s=this.store.snapshot,l=t,c=o,m=!1;for(;i;){try{[l,c,m]=i.applyTo(l,c,s);let p=s.elements,d=s.maybeClone(a,l,c),u=LF.create(s,d),b=ks.applyLatestChanges(i,p,l);b.isEmpty()||(this.store.scheduleMicroAction({action:a,change:u,delta:b}),i=b),s=d}finally{r(i)}if(m)break;i=n()}return[l,c]}finally{this.onHistoryChangedEmitter.trigger(new Hi(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=ks.inverse(o);return t.push(n)}};import{useEffect as DF,useState as RF}from"react";var h0=(e,t)=>{let[o,n]=RF(t);return DF(()=>{let r=e.on(i=>{n(i)});return()=>{r()}},[e]),o};import{jsx as v3}from"react/jsx-runtime";var E3=(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:f0.EVENTUALLY};let[r,i]=n,a=BF(Array.from(r.values()));return{appState:i,elements:a,captureUpdate:f0.NEVER}}return{captureUpdate:f0.EVENTUALLY}},y3=e=>({name:"undo",label:"buttons.undo",icon:cg,trackEvent:{category:"history"},viewMode:!1,perform:(t,o,n,r)=>E3(r,o,()=>e.undo(b3(t),o)),keyTest:t=>t[hc.CTRL_OR_CMD]&&b0(t,hc.Z)&&!t.shiftKey,PanelComponent:({appState:t,updateData:o,data:n,app:r})=>{let{isUndoStackEmpty:i}=h0(e.onHistoryChangedEmitter,new Hi(e.isUndoStackEmpty,e.isRedoStackEmpty)),a=kt()==="mobile";return v3(ee,{type:"button",icon:cg,"aria-label":h("buttons.undo"),onClick:o,size:n?.size||"medium",disabled:i,"data-testid":"button-undo",style:{...a?x3:{}}})}}),w3=e=>({name:"redo",label:"buttons.redo",icon:dg,trackEvent:{category:"history"},viewMode:!1,perform:(t,o,n,r)=>E3(r,o,()=>e.redo(b3(t),o)),keyTest:t=>t[hc.CTRL_OR_CMD]&&t.shiftKey&&b0(t,hc.Z)||NF&&t.ctrlKey&&!t.shiftKey&&b0(t,hc.Y),PanelComponent:({appState:t,updateData:o,data:n,app:r})=>{let{isRedoStackEmpty:i}=h0(e.onHistoryChangedEmitter,new Hi(e.isUndoStackEmpty,e.isRedoStackEmpty)),a=kt()==="mobile";return v3(ee,{type:"button",icon:dg,"aria-label":h("buttons.redo"),onClick:o,size:n?.size||"medium",disabled:i,"data-testid":"button-redo",style:{...a?x3:{}}})}});import{getFontString as FF}from"@orangecatai/common";import{newElementWith as zF}from"@orangecatai/element";import{measureText as OF}from"@orangecatai/element";import{isTextElement as T3}from"@orangecatai/element";import{CaptureUpdateAction as HF}from"@orangecatai/element";var I3=z({name:"autoResize",label:"labels.autoResize",icon:null,trackEvent:{category:"element"},predicate:(e,t,o,n)=>{let r=se(e,t);return r.length===1&&T3(r[0])&&!r[0].autoResize},perform:(e,t,o,n)=>{let r=se(e,t);return{appState:t,elements:e.map(i=>{if(i.id===r[0].id&&T3(i)){let a=OF(i.originalText,FF(i),i.lineHeight);return zF(i,{autoResize:!0,width:a.width,height:a.height,text:i.originalText})}return i}),captureUpdate:HF.IMMEDIATELY}}});import{isPromiseLike as GF}from"@orangecatai/common";import{jsx as UF}from"react/jsx-runtime";var x0=(e,t,o,n,r,i)=>{if(e.trackEvent)try{typeof e.trackEvent=="object"&&(!e.trackEvent.predicate||e.trackEvent.predicate(o,n,i))&&he(e.trackEvent.category,e.trackEvent.action||e.name,`${t} (${r.editorInterface.formFactor==="phone"?"mobile":"desktop"})`)}catch(a){console.error("error while logging action:",a)}},hp=class{constructor(t,o,n,r){S(this,"actions",{});S(this,"updater");S(this,"getAppState");S(this,"getElementsIncludingDeleted");S(this,"app");S(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],i=r.PanelComponent;i.displayName="PanelComponent";let a=this.getElementsIncludingDeleted(),s=this.getAppState(),l=c=>{x0(r,"ui",s,a,this.app,c),this.updater(r.perform(this.getElementsIncludingDeleted(),this.getAppState(),c,this.app))};return UF(i,{elements:this.getElementsIncludingDeleted(),appState:this.getAppState(),updateData:l,appProps:this.app.props,app:this.app,data:o,renderAction:this.renderAction})}return null});S(this,"isActionEnabled",t=>{let o=this.getElementsIncludingDeleted(),n=this.getAppState();return!t.predicate||t.predicate(o,n,this.app.props,this.app)});this.updater=i=>{if(GF(i))i.then(a=>t(a));else return t(i)},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 i=this.getElementsIncludingDeleted(),a=this.getAppState(),s=null;return x0(r,"keyboard",a,i,this.app,null),t.preventDefault(),t.stopPropagation(),this.updater(n[0].perform(i,a,s,this.app)),!0}executeAction(t,o="api",n=null){let r=this.getElementsIncludingDeleted(),i=this.getAppState();x0(t,o,i,r,this.app,n),this.updater(t.perform(r,i,n,this.app))}};var fp=class{constructor(){S(this,"targets",new WeakMap);S(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 E0=e=>{let t=Array.from(e.values());return{x:C3(t,o=>o.x)/t.length,y:C3(t,o=>o.y)/t.length}},y0=([e,t])=>Math.hypot(e.x-t.x,e.y-t.y),C3=(e,t)=>e.reduce((o,n)=>o+t(n),0);import{pointFrom as j,pointRotateRads as Gr,rangeInclusive as Ao,rangeIntersection as bp,rangesOverlap as xp}from"@orangecatai/math";import{TOOL_TYPE as Gi,KEYS as k3}from"@orangecatai/common";import{getCommonBounds as w0,getDraggedElementsBounds as v0,getElementAbsoluteCoords as WF}from"@orangecatai/element";import{isBoundToContainer as A3}from"@orangecatai/element";import{getMaximumGroups as L3}from"@orangecatai/element";import{getSelectedElements as YF,getVisibleAndNonSelectedElements as _3}from"@orangecatai/element";var VF=8,S3=99999,Ep=e=>VF/e,Qt=class Qt{};S(Qt,"referenceSnapPoints",null),S(Qt,"visibleGaps",null),S(Qt,"setReferenceSnapPoints",t=>{Qt.referenceSnapPoints=t}),S(Qt,"getReferenceSnapPoints",()=>Qt.referenceSnapPoints),S(Qt,"setVisibleGaps",t=>{Qt.visibleGaps=t}),S(Qt,"getVisibleGaps",()=>Qt.visibleGaps),S(Qt,"destroy",()=>{Qt.referenceSnapPoints=null,Qt.visibleGaps=null});var Lo=Qt,Ur=e=>e.props.gridModeEnabled??e.state.gridModeEnabled,or=({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[k3.CTRL_OR_CMD]||!t.state.objectsSnapModeEnabled&&e[k3.CTRL_OR_CMD]&&!Ur(t))}return o.length===1&&o[0].type==="arrow"?!1:t.state.objectsSnapModeEnabled},KF=(e,t,o=.01)=>Math.abs(e-t)<=o,fc=(e,t,{omitCenter:o,boundingBoxCorners:n,dragOffset:r}={omitCenter:!1,boundingBoxCorners:!1})=>{let i=[];if(e.length===1){let a=e[0],[s,l,c,m,p,d]=WF(a,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,b=(m-l)/2;if((a.type==="diamond"||a.type==="ellipse")&&!n){let g=Gr(j(s,l+b),j(p,d),a.angle),E=Gr(j(s+u,l),j(p,d),a.angle),y=Gr(j(c,l+b),j(p,d),a.angle),x=Gr(j(s+u,m),j(p,d),a.angle),w=j(p,d);i=o?[g,E,y,x]:[g,E,y,x,w]}else{let g=Gr(j(s,l),j(p,d),a.angle),E=Gr(j(c,l),j(p,d),a.angle),y=Gr(j(s,m),j(p,d),a.angle),x=Gr(j(c,m),j(p,d),a.angle),w=j(p,d);i=o?[g,E,y,x]:[g,E,y,x,w]}}else if(e.length>1){let[a,s,l,c]=v0(e,r??{x:0,y:0}),m=l-a,p=c-s,d=j(a,s),u=j(l,s),b=j(a,c),g=j(l,c),E=j(a+m/2,s+p/2);i=o?[d,u,b,g]:[d,u,b,g,E]}return i.map(a=>j(rt(a[0]),rt(a[1])))},D3=(e,t,o,n)=>_3(e,t,o,n),R3=(e,t,o,n)=>{let r=D3(e,t,o,n),i=L3(r,n).filter(p=>!(p.length===1&&A3(p[0]))).map(p=>w0(p).map(d=>rt(d))),a=i.sort((p,d)=>p[0]-d[0]),s=[],l=0;e:for(let p=0;p<a.length;p++){let d=a[p];for(let u=p+1;u<a.length;u++){if(++l>S3)break e;let b=a[u],[,g,E,y]=d,[x,w,,v]=b;E<x&&xp(Ao(g,y),Ao(w,v))&&s.push({startBounds:d,endBounds:b,startSide:[j(E,g),j(E,y)],endSide:[j(x,w),j(x,v)],length:x-E,overlap:bp(Ao(g,y),Ao(w,v))})}}let c=i.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>S3)break e;let b=c[u],[g,,E,y]=d,[x,w,v]=b;y<w&&xp(Ao(g,E),Ao(x,v))&&m.push({startBounds:d,endBounds:b,startSide:[j(g,y),j(E,y)],endSide:[j(x,w),j(v,w)],length:w-y,overlap:bp(Ao(g,E),Ao(x,v))})}}return{horizontalGaps:s,verticalGaps:m}},M3=(e,t,o,n,r,i,a)=>{if(!or({app:o,event:n,selectedElements:e}))return[];if(e.length===0)return[];let s=Lo.getVisibleGaps();if(s){let{horizontalGaps:l,verticalGaps:c}=s,[m,p,d,u]=v0(e,t).map(E=>rt(E)),b=(m+d)/2,g=(p+u)/2;for(let E of l){if(!xp(Ao(p,u),E.overlap))continue;let y=E.startSide[0][0]+E.length/2,x=rt(y-b);if(E.length>d-m&&Math.abs(x)<=a.x){Math.abs(x)<a.x&&(r.length=0),a.x=Math.abs(x);let A={type:"gap",direction:"center_horizontal",gap:E,offset:x};r.push(A);continue}let[,,v]=E.endBounds,T=m-v,C=rt(E.length-T);if(Math.abs(C)<=a.x){Math.abs(C)<a.x&&(r.length=0),a.x=Math.abs(C);let A={type:"gap",direction:"side_right",gap:E,offset:C};r.push(A);continue}let[M,,,]=E.startBounds,k=M-d,R=rt(k-E.length);if(Math.abs(R)<=a.x){Math.abs(R)<a.x&&(r.length=0),a.x=Math.abs(R);let A={type:"gap",direction:"side_left",gap:E,offset:R};r.push(A);continue}}for(let E of c){if(!xp(Ao(m,d),E.overlap))continue;let y=E.startSide[0][1]+E.length/2,x=rt(y-g);if(E.length>u-p&&Math.abs(x)<=a.y){Math.abs(x)<a.y&&(i.length=0),a.y=Math.abs(x);let A={type:"gap",direction:"center_vertical",gap:E,offset:x};i.push(A);continue}let[,v,,]=E.startBounds,T=v-u,C=rt(T-E.length);if(Math.abs(C)<=a.y){Math.abs(C)<a.y&&(i.length=0),a.y=Math.abs(C);let A={type:"gap",direction:"side_top",gap:E,offset:C};i.push(A);continue}let[,,,M]=E.endBounds,k=rt(p-M),R=E.length-k;if(Math.abs(R)<=a.y){Math.abs(R)<a.y&&(i.length=0),a.y=Math.abs(R);let A={type:"gap",direction:"side_bottom",gap:E,offset:R};i.push(A);continue}}}},N3=(e,t,o,n)=>{let r=D3(e,t,o,n);return L3(r,n).filter(i=>!(i.length===1&&A3(i[0]))).flatMap(i=>fc(i,n))},Ss=(e,t,o,n,r,i,a)=>{if(!or({app:o,event:n,selectedElements:e})||e.length===0&&t.length===0)return[];let s=Lo.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)<=a.x&&(Math.abs(m)<a.x&&(r.length=0),r.push({type:"point",points:[l,c],offset:m}),a.x=Math.abs(m)),Math.abs(p)<=a.y&&(Math.abs(p)<a.y&&(i.length=0),i.push({type:"point",points:[l,c],offset:p}),a.y=Math.abs(p))}},B3=(e,t,o,n,r)=>{let i=o.state,a=YF(e,i);if(!or({app:o,event:n,selectedElements:a})||a.length===0)return{snapOffset:{x:0,y:0},snapLines:[]};t.x=rt(t.x),t.y=rt(t.y);let s=[],l=[],c=Ep(i.zoom.value),m={x:c,y:c},p=fc(a,r,{dragOffset:t});Ss(a,p,o,n,s,l,m),M3(a,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:rt(t.x+d.x),y:rt(t.y+d.y)};Ss(a,fc(a,r,{dragOffset:u}),o,n,s,l,m),M3(a,u,o,n,s,l,m);let b=T0(s,l),g=$F(a,u,[...s,...l].filter(E=>E.type==="gap"));return{snapOffset:d,snapLines:[...b,...g]}},rt=e=>Math.round(e*10**6)/10**6,P3=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())},T0=(e,t)=>{let o={},n={};if(e.length>0){for(let r of e)if(r.type==="point"){let i=rt(r.points[0][0]);o[i]||(o[i]=[]),o[i].push(...r.points.map(a=>j(rt(a[0]),rt(a[1]))))}}if(t.length>0){for(let r of t)if(r.type==="point"){let i=rt(r.points[0][1]);n[i]||(n[i]=[]),n[i].push(...r.points.map(a=>j(rt(a[0]),rt(a[1]))))}}return Object.entries(o).map(([r,i])=>({type:"points",points:P3(i.map(a=>j(Number(r),a[1])).sort((a,s)=>a[1]-s[1]))})).concat(Object.entries(n).map(([r,i])=>({type:"points",points:P3(i.map(a=>j(a[0],Number(r))).sort((a,s)=>a[0]-s[0]))})))},XF=e=>{let t=new Map;for(let o of e){let n=o.points.flat().map(r=>[rt(r)]).join(",");t.has(n)||t.set(n,o)}return Array.from(t.values())},$F=(e,t,o)=>{let[n,r,i,a]=v0(e,t),s=[];for(let l of o){let[c,m,p,d]=l.gap.startBounds,[u,b,g,E]=l.gap.endBounds,y=bp(Ao(r,a),l.gap.overlap),x=bp(Ao(n,i),l.gap.overlap);switch(l.direction){case"center_horizontal":{if(y){let w=(y[0]+y[1])/2;s.push({type:"gap",direction:"horizontal",points:[j(l.gap.startSide[0][0],w),j(n,w)]},{type:"gap",direction:"horizontal",points:[j(i,w),j(l.gap.endSide[0][0],w)]})}break}case"center_vertical":{if(x){let w=(x[0]+x[1])/2;s.push({type:"gap",direction:"vertical",points:[j(w,l.gap.startSide[0][1]),j(w,r)]},{type:"gap",direction:"vertical",points:[j(w,a),j(w,l.gap.endSide[0][1])]})}break}case"side_right":{if(y){let w=(y[0]+y[1])/2;s.push({type:"gap",direction:"horizontal",points:[j(p,w),j(u,w)]},{type:"gap",direction:"horizontal",points:[j(g,w),j(n,w)]})}break}case"side_left":{if(y){let w=(y[0]+y[1])/2;s.push({type:"gap",direction:"horizontal",points:[j(i,w),j(c,w)]},{type:"gap",direction:"horizontal",points:[j(p,w),j(u,w)]})}break}case"side_top":{if(x){let w=(x[0]+x[1])/2;s.push({type:"gap",direction:"vertical",points:[j(w,a),j(w,m)]},{type:"gap",direction:"vertical",points:[j(w,d),j(w,b)]})}break}case"side_bottom":{if(x){let w=(x[0]+x[1])/2;s.push({type:"gap",direction:"vertical",points:[j(w,d),j(w,b)]},{type:"gap",direction:"vertical",points:[j(w,E),j(w,r)]})}break}}}return XF(s.map(l=>({...l,points:l.points.map(c=>j(rt(c[0]),rt(c[1])))})))},I0=(e,t,o,n,r,i)=>{if(!or({event:n,selectedElements:e,app:o})||e.length===0||e.length===1&&!KF(e[0].angle,0))return{snapOffset:{x:0,y:0},snapLines:[]};let[a,s,l,c]=w0(t);i&&(i.includes("e")?l+=r.x:i.includes("w")&&(a+=r.x),i.includes("n")?s+=r.y:i.includes("s")&&(c+=r.y));let m=[];if(i)switch(i){case"e":{m.push(j(l,s),j(l,c));break}case"w":{m.push(j(a,s),j(a,c));break}case"n":{m.push(j(a,s),j(l,s));break}case"s":{m.push(j(a,c),j(l,c));break}case"ne":{m.push(j(l,s));break}case"nw":{m.push(j(a,s));break}case"se":{m.push(j(l,c));break}case"sw":{m.push(j(a,c));break}}let p=Ep(o.state.zoom.value),d={x:p,y:p},u=[],b=[];Ss(t,m,o,n,u,b,d);let g={x:u[0]?.offset??0,y:b[0]?.offset??0};d.x=0,d.y=0,u.length=0,b.length=0;let[E,y,x,w]=w0(e).map(C=>rt(C)),v=[j(E,y),j(E,w),j(x,y),j(x,w)];Ss(e,v,o,n,u,b,d);let T=T0(u,b);return{snapOffset:g,snapLines:T}},F3=(e,t,o,n,r,i)=>{if(!or({event:o,selectedElements:[e],app:t}))return{snapOffset:{x:0,y:0},snapLines:[]};let a=[j(n.x+r.x,n.y+r.y)],s=Ep(t.state.zoom.value),l={x:s,y:s},c=[],m=[];Ss([e],a,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=fc([e],i,{boundingBoxCorners:!0,omitCenter:!0});Ss([e],d,t,o,c,m,l);let u=T0(c,m);return{snapOffset:p,snapLines:u}},z3=(e,t,o,n,r)=>{if(!or({event:n,selectedElements:[],app:t}))return{originOffset:{x:0,y:0},snapLines:[]};let i=_3(e,[],t.state,r),a=Ep(t.state.zoom.value),s={x:a,y:a},l=[],c=[];for(let m of i){let p=fc([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,j(d[0],o.y)],direction:"vertical"}),s.x=u);let b=d[1]-o.y;Math.abs(b)<=Math.abs(s.y)&&(Math.abs(b)<Math.abs(s.y)&&(l.length=0),l.push({type:"pointer",points:[d,j(o.x,d[1])],direction:"horizontal"}),s.y=b)}}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]}},O3=e=>e===Gi.rectangle||e===Gi.ellipse||e===Gi.diamond||e===Gi.frame||e===Gi.magicframe||e===Gi.image||e===Gi.text;import{isElementInViewport as ZF}from"@orangecatai/element";import{memoize as jF,toBrandedType as qF}from"@orangecatai/common";var bc=class{constructor(t){S(this,"scene");S(this,"getRenderableElements",(()=>{let t=({elementsMap:n,zoom:r,offsetLeft:i,offsetTop:a,scrollX:s,scrollY:l,height:c,width:m})=>{let p=[];for(let d of n.values())ZF(d,m,c,{zoom:r,offsetLeft:i,offsetTop:a,scrollX:s,scrollY:l},n)&&p.push(d);return p},o=({elements:n,editingTextElement:r,newElementId:i})=>{let a=qF(new Map);for(let s of n)i!==s.id&&(!r||r.type!=="text"||s.id!==r.id)&&a.set(s.id,s);return a};return jF(({zoom:n,offsetLeft:r,offsetTop:i,scrollX:a,scrollY:s,height:l,width:c,editingTextElement:m,newElementId:p,sceneNonce:d})=>{let u=this.scene.getNonDeletedElements(),b=o({elements:u,editingTextElement:m,newElementId:p}),g=t({elementsMap:b,zoom:n,offsetLeft:r,offsetTop:i,scrollX:a,scrollY:s,height:l,width:c});return{elementsMap:b,visibleElements:g}})})());this.scene=t}destroy(){Lx.cancel(),this.getRenderableElements.clear()}};import{sceneCoordsToViewportCoords as JF}from"@orangecatai/common";import{getElementAbsoluteCoords as QF}from"@orangecatai/element";import{jsx as oz}from"react/jsx-runtime";var ez=5,tz=(e,t,o)=>{let[n,r]=QF(e,o),{x:i,y:a}=JF({sceneX:n+e.width,sceneY:r},t),s=i-t.offsetLeft+10,l=a-t.offsetTop;return{x:s,y:l}},C0=({children:e,element:t,elementsMap:o})=>{let n=fn();if(n.contextMenu||n.newElement||n.resizingElement||n.isRotating||n.openMenu||n.viewModeEnabled)return null;let{x:r,y:i}=tz(t,n,o);return oz("div",{className:"excalidraw-canvas-buttons",style:{top:`${i}px`,left:`${r}px`,padding:ez},children:e})};import{useCallback as xc,useEffect as H3,useRef as nz,useState as yp}from"react";import{sceneCoordsToViewportCoords as rz}from"@orangecatai/common";import{getElementAbsoluteCoords as iz}from"@orangecatai/element";import{isFrameLikeElement as az}from"@orangecatai/element";import{Fragment as G3,jsx as Ae,jsxs as Qo}from"react/jsx-runtime";var U3=[{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"}],k0=e=>{let t={border:"1.5px solid currentColor",borderRadius:2,boxSizing:"border-box"};switch(e){case"square":return Ae("div",{style:{...t,width:14,height:14}});case"portrait":return Ae("div",{style:{...t,width:10,height:14}});case"portrait-tall":return Ae("div",{style:{...t,width:8,height:14}});case"landscape":return Ae("div",{style:{...t,width:14,height:10}});case"landscape-wide":return Ae("div",{style:{...t,width:14,height:8}});default:return Ae("div",{style:{...t,width:14,height:14}})}},sz=({active:e})=>Ae("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:e?Qo(G3,{children:[Ae("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"}),Ae("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"}),Ae("line",{x1:"5",y1:"7",x2:"9",y2:"7",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]}):Qo(G3,{children:[Ae("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"}),Ae("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"})]})}),lz=()=>Qo("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[Ae("path",{d:"M8 2V10M8 10L5 7M8 10L11 7",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"}),Ae("path",{d:"M3 12H13",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]}),cz=()=>Ae("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:Ae("path",{d:"M2.5 3.75L5 6.25L7.5 3.75",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),dz=()=>Ae("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:Ae("path",{d:"M3.5 8.5L6.5 11.5L12.5 4.5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),mz=(e,t)=>U3.find(o=>o.width===e&&o.height===t)||null,W3=({element:e,app:t})=>{let o=t.state,[n,r]=yp(!1),[i,a]=yp(!0),[s,l]=yp(Math.round(e.width)),[c,m]=yp(Math.round(e.height)),p=nz(null);H3(()=>{l(Math.round(e.width)),m(Math.round(e.height))},[e.width,e.height]),H3(()=>{let k=R=>{p.current&&!p.current.contains(R.target)&&r(!1)};if(n)return document.addEventListener("mousedown",k),()=>document.removeEventListener("mousedown",k)},[n]);let d=mz(Math.round(e.width),Math.round(e.height)),[u,b]=iz(e,t.scene.getNonDeletedElementsMap()),{x:g,y:E}=rz({sceneX:u+e.width/2,sceneY:b},o),y=g-o.offsetLeft,x=Math.max(E-o.offsetTop-82,8),w=xc((k,R)=>{k>0&&R>0&&t.scene.mutateElement(e,{width:k,height:R})},[t.scene,e]),v=xc(k=>{let R=parseInt(k,10);if(!isNaN(R)&&R>0)if(l(R),i){let A=e.height/e.width,P=Math.round(R*A);m(P),w(R,P)}else w(R,e.height)},[i,e.width,e.height,w]),T=xc(k=>{let R=parseInt(k,10);if(!isNaN(R)&&R>0)if(m(R),i){let A=e.width/e.height,P=Math.round(R*A);l(P),w(P,R)}else w(e.width,R)},[i,e.width,e.height,w]),C=xc(k=>{l(k.width),m(k.height),w(k.width,k.height),r(!1)},[w]),M=xc(()=>{az(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:Qo("div",{className:"frame-toolbar",style:{left:`${y}px`,top:`${x}px`},onPointerDown:k=>k.stopPropagation(),onClick:k=>k.stopPropagation(),children:[Qo("div",{className:"frame-toolbar__section",ref:p,children:[Qo("button",{className:"frame-toolbar__ratio-btn",onClick:()=>r(!n),title:"Frame format",children:[k0(d?d.icon:"square"),Ae("span",{children:d?.label||"Custom"}),Ae(cz,{})]}),n&&Qo("div",{className:"frame-toolbar__dropdown",children:[Ae("div",{style:{padding:"6px 12px",fontSize:11,fontWeight:600,color:"var(--text-secondary-color, #888)",textTransform:"uppercase",letterSpacing:"0.5px"},children:"Format"}),U3.map(k=>{let R=d?.label===k.label;return Qo("button",{className:"frame-toolbar__dropdown-item",onClick:()=>C(k),children:[k0(k.icon),Ae("span",{className:"frame-toolbar__dropdown-item-label",children:k.label}),Qo("span",{className:"frame-toolbar__dropdown-item-dims",children:[k.width,"*",k.height]}),R&&Ae("span",{className:"frame-toolbar__dropdown-item-check",children:Ae(dz,{})})]},k.label)})]})]}),Ae("div",{className:"frame-toolbar__divider"}),Qo("div",{className:"frame-toolbar__input-group",children:[Ae("label",{children:"W"}),Ae("input",{type:"number",value:s,onChange:k=>v(k.target.value),onPointerDown:k=>k.stopPropagation(),min:1})]}),Ae("button",{className:`frame-toolbar__constrain-btn ${i?"frame-toolbar__constrain-btn--active":""}`,onClick:()=>a(!i),title:i?"Unlock proportions":"Constrain proportions",children:Ae(sz,{active:i})}),Qo("div",{className:"frame-toolbar__input-group",children:[Ae("label",{children:"H"}),Ae("input",{type:"number",value:c,onChange:k=>T(k.target.value),onPointerDown:k=>k.stopPropagation(),min:1})]}),Ae("div",{className:"frame-toolbar__divider"}),Ae("button",{className:"frame-toolbar__export-btn",onClick:M,title:"Export frame as PNG",children:Ae(lz,{})})]})};import{useCallback as Wi,useEffect as wc,useRef as Yr,useState as kn}from"react";import{sceneCoordsToViewportCoords as vz}from"@orangecatai/common";import{CaptureUpdateAction as M0,getElementAbsoluteCoords as Tz}from"@orangecatai/element";import{ArrowUp as Iz,ImagePlus as Cz,X as kz}from"lucide-react";function wp(e){let t=e?.trim();return(t||void 0)??(typeof import.meta<"u"&&I?.VITE_APP_GEMINI_API_KEY?I.VITE_APP_GEMINI_API_KEY:"")??""}var nr=new Map;function vp(e,t,o,n){nr.set(e,{subscribers:new Set,prompt:t,settings:o,controller:n})}function Tp(e,t){let o=nr.get(e);o&&(o.finishedError=t,o.subscribers.forEach(n=>n(t)))}function Ip(e,t){let o=nr.get(e);return o?(o.subscribers.add(t),o.finishedError!==void 0&&t(o.finishedError),!0):!1}function Cp(e,t){nr.get(e)?.subscribers.delete(t)}function kp(e){nr.delete(e)}function Sp(e){nr.get(e)?.controller.abort()}function Mp(e){return nr.get(e)?.prompt??""}function Wr(e){return nr.get(e)?.settings??null}function Ec(e){return nr.has(e)}import hz,{createContext as fz,useContext as bz,useLayoutEffect as xz,useRef as Ez,useState as yz}from"react";import{clsx as pz}from"clsx";import{twMerge as uz}from"tailwind-merge";function Ye(...e){return uz(pz(e))}import*as Y3 from"react";import{jsx as gz}from"react/jsx-runtime";var S0=Y3.forwardRef(({className:e,...t},o)=>gz("textarea",{className:Ye("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}));S0.displayName="Textarea";import*as K3 from"react";import*as en from"@radix-ui/react-tooltip";import{jsx as V3}from"react/jsx-runtime";var Pp=en.Provider,Ap=en.Root,Lp=en.Trigger,yc=K3.forwardRef(({className:e,sideOffset:t=4,...o},n)=>V3(en.Portal,{children:V3(en.Content,{ref:n,sideOffset:t,className:Ye("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})}));yc.displayName=en.Content.displayName;import{jsx as Ui,jsxs as wz}from"react/jsx-runtime";var X3=fz({isLoading:!1,value:"",setValue:()=>{},maxHeight:240,onSubmit:void 0,disabled:!1,textareaRef:hz.createRef()});function $3(){return bz(X3)}function Ms({className:e,isLoading:t=!1,maxHeight:o=240,value:n,onValueChange:r,onSubmit:i,children:a,disabled:s=!1,onClick:l,...c}){let[m,p]=yz(n||""),d=Ez(null),u=g=>{p(g),r?.(g)},b=g=>{s||d.current?.focus(),l?.(g)};return Ui(Pp,{children:Ui(X3.Provider,{value:{isLoading:t,value:n??m,setValue:r??u,maxHeight:o,onSubmit:i,disabled:s,textareaRef:d},children:Ui("div",{onClick:b,className:Ye("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:a})})})}function Ps({className:e,onKeyDown:t,disableAutosize:o=!1,...n}){let{value:r,setValue:i,maxHeight:a,onSubmit:s,disabled:l,textareaRef:c}=$3(),m=b=>{!b||o||(b.style.height="auto",typeof a=="number"?b.style.height=`${Math.min(b.scrollHeight,a)}px`:b.style.height=`min(${b.scrollHeight}px, ${a})`)},p=b=>{c.current=b,m(b)};return xz(()=>{if(!c.current||o)return;let b=c.current;b.style.height="auto",typeof a=="number"?b.style.height=`${Math.min(b.scrollHeight,a)}px`:b.style.height=`min(${b.scrollHeight}px, ${a})`},[r,a,o]),Ui(S0,{ref:p,value:r,onChange:b=>{m(b.target),i(b.target.value)},onKeyDown:b=>{b.key==="Enter"&&!b.shiftKey&&(b.preventDefault(),s?.()),t?.(b)},className:Ye("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 As({children:e,className:t,...o}){return Ui("div",{className:Ye("flex items-center gap-2",t),...o,children:e})}function rr({tooltip:e,children:t,className:o,side:n="top",...r}){let{disabled:i}=$3();return wz(Ap,{...r,children:[Ui(Lp,{asChild:!0,disabled:i,onClick:a=>a.stopPropagation(),children:t}),Ui(yc,{side:n,className:o,children:e})]})}import{jsx as fe,jsxs as wt}from"react/jsx-runtime";var Vr={"Gemini 2.5 Flash":{geminiModelId:"gemini-2.5-flash-image",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"]}},L0=Object.keys(Vr),Sz={"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 Yi(e,t,o){let r=Sz[e][t];if(!r)return{width:1024,height:1024};let i=r[o];if(!i){let a=Object.values(r)[0];return{width:a.w,height:a.h}}return{width:i.w,height:i.h}}function Mz(e){return e==="0.5K"?"512px":e}async function vc(e,t,o,n,r,i,a,s,l){let c=[{text:e}];if(s){let x=s.match(/^data:([^;]+);base64,(.+)$/);x&&c.unshift({inlineData:{mimeType:x[1],data:x[2]}})}let m={aspectRatio:o};r&&(m.imageSize=Mz(n));let p={responseModalities:["IMAGE","TEXT"],imageConfig:m};i&&(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":a,"Content-Type":"application/json"},body:JSON.stringify(d)});if(!u.ok){let x=`Gemini API error ${u.status}`;try{let w=await u.json();w?.error?.message&&(x=w.error.message)}catch{}throw new Error(x)}let E=((await u.json())?.candidates?.[0]?.content?.parts??[]).find(x=>x.inlineData?.data);if(!E?.inlineData?.data)throw new Error("No image was returned by the API.");return`data:${E.inlineData.mimeType??"image/png"};base64,${E.inlineData.data}`}var P0=()=>fe("svg",{width:"9",height:"9",viewBox:"0 0 10 10",fill:"none",children:fe("path",{d:"M2.5 3.75L5 6.25L7.5 3.75",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round"})}),A0=()=>fe("svg",{width:"12",height:"12",viewBox:"0 0 14 14",fill:"none",children:fe("path",{d:"M2.5 7.5L5.5 10.5L11.5 3.5",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round"})}),Pz=()=>fe("svg",{width:"13",height:"13",viewBox:"0 0 16 16",fill:"none",children:fe("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"})}),Az=()=>wt("svg",{width:"12",height:"12",viewBox:"0 0 14 14",fill:"none",children:[fe("circle",{cx:"7",cy:"7",r:"5.5",stroke:"currentColor",strokeWidth:"1.2"}),fe("path",{d:"M7 6.5V10",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round"}),fe("circle",{cx:"7",cy:"4.5",r:"0.75",fill:"currentColor"})]}),Lz=()=>fe("svg",{width:"15",height:"15",viewBox:"0 0 14 14",fill:"none",className:"igp-spinner",children:fe("circle",{cx:"7",cy:"7",r:"5.5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeDasharray:"20 14"})}),_z=({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 fe("div",{style:{border:"1.5px solid currentColor",borderRadius:2,boxSizing:"border-box",display:"inline-block",flexShrink:0,color:"#999",...o}})},Z3=({element:e,app:t,onBeforeImageGen:o,onAfterImageGen:n})=>{let r=Z=>{let de=Z.customData?.imageGenerator;return de?{model:de.model,ratio:de.ratio,resolution:de.resolution}:null},i=t.state,a=wp(t.props.geminiApiKey),[s,l]=kn(()=>Mp(e.id)),[c,m]=kn(()=>{let Z=r(e),de=Wr(e.id);return Z?.model??de?.model??"Gemini 3.1 Flash"}),p=Vr[c],d=p.supportedRatios,u=p.supportedResolutions,b=d.includes("2:3")?"2:3":d[0],g=u.includes("2K")?"2K":u[u.length-1],[E,y]=kn(()=>{let Z=r(e),de=Wr(e.id);return Z?.ratio??de?.ratio??b}),[x,w]=kn(()=>{let Z=r(e),de=Wr(e.id);return Z?.resolution??de?.resolution??g}),v=Wi(Z=>{t.scene.mutateElement(e,{customData:{...e.customData??{},imageGenerator:Z}})},[t.scene,e]),T=Wi((Z,de=!1)=>{t.scrollToContent(Z,{fitToViewport:!0,viewportZoomFactor:.8,animate:de,canvasOffsets:t.getEditorUIOffsets()})},[t]),C=Yr(!0);wc(()=>{if(C.current){C.current=!1;return}let Z=Vr[c],de=Z.supportedRatios,tt=de.includes(E),bt=E;tt||(bt=de.includes("2:3")?"2:3":de[0],y(bt));let gr=Z.supportedResolutions,Zu=gr.includes(x),Gn=x;Zu||(Gn=gr.includes("2K")?"2K":gr[gr.length-1],w(Gn));let nl=Yi(c,bt,Gn);t.scene.mutateElement(e,{width:nl.width,height:nl.height}),v({model:c,ratio:bt,resolution:Gn}),t.syncActionResult({captureUpdate:M0.IMMEDIATELY})},[c,t,e,v]);let[M,k]=kn(()=>Ec(e.id)),[R,A]=kn(null),[P,_]=kn(null),[O,U]=kn(!1),[H,W]=kn(!1),[D,F]=kn(!1),X=Yr(null),te=Yr(null),$=Yr(null),ae=Yr(null),xe=Yr(null),re=Yr(e),we=Yr(t);wc(()=>{re.current=e,we.current=t}),wc(()=>{if(!e.customData?.imageGeneratorAutoFitPending)return;let Z=0,de=!1,tt=()=>{de||(T(e),t.scene.mutateElement(e,{customData:{...e.customData??{},imageGeneratorAutoFitPending:!1}}))};return Z=window.requestAnimationFrame(()=>{Z=window.requestAnimationFrame(tt)}),()=>{de=!0,window.cancelAnimationFrame(Z)}},[t.scene,e,T]);let Fe=Wi(Z=>{y(Z),U(!1);let de=Yi(c,Z,x);we.current.scene.mutateElement(re.current,{width:de.width,height:de.height,customData:{...re.current.customData??{},imageGenerator:{model:c,ratio:Z,resolution:x}}}),we.current.syncActionResult({captureUpdate:M0.IMMEDIATELY})},[c,x]),mt=Wi(Z=>{w(Z),W(!1);let de=Yi(c,E,Z);we.current.scene.mutateElement(re.current,{width:de.width,height:de.height,customData:{...re.current.customData??{},imageGenerator:{model:c,ratio:E,resolution:Z}}}),we.current.syncActionResult({captureUpdate:M0.IMMEDIATELY})},[c,E]);wc(()=>{let Z=de=>{X.current&&!X.current.contains(de.target)&&U(!1),te.current&&!te.current.contains(de.target)&&W(!1),$.current&&!$.current.contains(de.target)&&F(!1)};return document.addEventListener("mousedown",Z),()=>document.removeEventListener("mousedown",Z)},[]),wc(()=>{let Z=de=>{k(!1),de?de!=="aborted"&&A(de):A(null)};return Ip(e.id,Z),()=>Cp(e.id,Z)},[e.id]);let ct=Wi(Z=>{let de=Z.target.files?.[0];if(!de)return;let tt=new FileReader;tt.onload=()=>_(tt.result),tt.readAsDataURL(de),Z.target.value=""},[]),Ot=Wi(()=>{Sp(e.id)},[e.id]),uo=Wi(async()=>{if(!s.trim()){A("Please enter a prompt.");return}if(!a){A("No Gemini API key found. Set VITE_APP_GEMINI_API_KEY in .env.");return}if(o)try{let{allowed:tt,error:bt}=await o();if(!tt){A(bt||"Insufficient credits for image generation");return}}catch{A("Credit check failed");return}let Z=new AbortController;xe.current=Z,vp(e.id,s,{model:c,ratio:E,resolution:x},Z),k(!0),A(null);let de=null;try{let tt=Vr[c],bt=await vc(s,tt.geminiModelId,E,x,tt.supportsImageSize,tt.supportsThinking,a,P??void 0,Z.signal);await t.insertGeneratedImageIntoFrame(bt,e),n?.()}catch(tt){tt instanceof Error&&(tt.name==="AbortError"?de="aborted":de=tt.message)}finally{xe.current=null,Tp(e.id,de),k(!1),de===null?(kp(e.id),l(""),_(null),A(null)):de!=="aborted"&&A(de)}},[s,a,c,E,x,P,t,e,o,n]);if(i.contextMenu||i.newElement||i.resizingElement||i.isRotating||i.openMenu||i.viewModeEnabled||i.selectedElementsAreBeingDragged)return null;let[pr,,,Hn]=Tz(e,t.scene.getNonDeletedElementsMap()),{x:ur,y:oe}=vz({sceneX:pr+e.width/2,sceneY:Hn},i),Se=ur-i.offsetLeft,Tt=oe-i.offsetTop+16;return wt("div",{className:"igp",style:{left:`${Se}px`,top:`${Tt}px`},onPointerDown:Z=>Z.stopPropagation(),onClick:Z=>Z.stopPropagation(),children:[fe("input",{ref:ae,type:"file",accept:"image/*",style:{display:"none"},onChange:ct}),wt(Ms,{isLoading:M,value:s,onValueChange:l,onSubmit:uo,className:"igp-container",children:[P&&wt("div",{className:"igp-ref-chip",children:[fe("img",{src:P,alt:"Reference"}),fe("span",{children:"Reference image"}),fe("button",{onClick:()=>_(null),title:"Remove",children:fe(kz,{size:10})})]}),fe(Ps,{placeholder:"What are we creating today\u2026",className:"igp-textarea",disableAutosize:!1}),R&&fe("div",{className:"igp-error",children:R}),wt(As,{className:"igp-actions",children:[wt("div",{className:"igp-actions-left",children:[wt("div",{className:"igp-dropdown-root",ref:$,children:[fe(rr,{tooltip:"Select model",side:"top",children:wt("button",{className:"igp-btn",onClick:()=>{F(Z=>!Z),U(!1),W(!1)},disabled:M,children:[fe(Pz,{}),fe("span",{children:c}),fe(P0,{})]})}),D&&fe("div",{className:"igp-dropdown igp-dropdown--up igp-dropdown--left",children:L0.map(Z=>wt("button",{className:"igp-dropdown-item",onClick:()=>{v({model:Z,ratio:E,resolution:x}),m(Z),F(!1)},children:[fe("span",{style:{flex:1},children:Z}),Z===c&&fe("span",{className:"igp-check",children:fe(A0,{})})]},Z))})]}),fe(rr,{tooltip:"Add reference image",side:"top",children:fe("button",{className:`igp-btn igp-btn--icon${P?" igp-btn--active":""}`,onClick:()=>ae.current?.click(),disabled:M,children:fe(Cz,{size:15})})})]}),wt("div",{className:"igp-actions-right",children:[wt("div",{className:"igp-dropdown-root",ref:te,children:[wt("button",{className:"igp-btn igp-btn--compact",onClick:()=>{u.length<=1||(W(Z=>!Z),U(!1),F(!1))},disabled:M||u.length<=1,title:u.length<=1?"Fixed resolution for this model":void 0,children:[fe("span",{children:x}),u.length>1&&fe(P0,{})]}),H&&u.length>1&&fe("div",{className:"igp-dropdown igp-dropdown--up igp-dropdown--right",children:u.map(Z=>wt("button",{className:"igp-dropdown-item",onClick:()=>mt(Z),children:[fe("span",{style:{flex:1},children:Z}),Z===x&&fe("span",{className:"igp-check",children:fe(A0,{})})]},Z))})]}),wt("div",{className:"igp-dropdown-root",ref:X,children:[wt("button",{className:"igp-btn igp-btn--compact",onClick:()=>{U(Z=>!Z),W(!1),F(!1)},disabled:M,children:[fe("span",{children:E}),fe(P0,{})]}),O&&wt("div",{className:"igp-dropdown igp-dropdown--up igp-dropdown--right igp-dropdown--ratio",children:[wt("div",{className:"igp-dropdown-header",children:[fe("span",{children:"Format"}),fe(Az,{})]}),d.map(Z=>{let de=Yi(c,Z,x);return wt("button",{className:"igp-dropdown-item",onClick:()=>Fe(Z),children:[fe(_z,{label:Z}),fe("span",{style:{flex:1},children:Z}),wt("span",{className:"igp-dims",children:[de.width,"\xD7",de.height]}),Z===E&&fe("span",{className:"igp-check",children:fe(A0,{})})]},Z)})]})]}),fe("button",{className:"igp-generate",onClick:M?Ot:uo,disabled:!M&&!s.trim(),title:M?"Stop generation":"Generate image",children:M?fe(Lz,{}):fe(Iz,{size:16})})]})]})]})]})};import{useCallback as _0,useEffect as D0,useRef as _p,useState as Sn}from"react";import{sceneCoordsToViewportCoords as j3}from"@orangecatai/common";import{getElementAbsoluteCoords as Dz}from"@orangecatai/element";import{ArrowUp as Rz}from"lucide-react";import{Fragment as Hz,jsx as be,jsxs as Pt}from"react/jsx-runtime";var R0=()=>be("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",children:be("path",{d:"M2.5 3.75L5 6.25L7.5 3.75",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),N0=()=>be("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",children:be("path",{d:"M2.5 7.5L5.5 10.5L11.5 3.5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),Nz=()=>be("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:be("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"})}),Bz=()=>Pt("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",children:[be("circle",{cx:"7",cy:"7",r:"5.5",stroke:"currentColor",strokeWidth:"1.2"}),be("path",{d:"M7 6.5V10",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round"}),be("circle",{cx:"7",cy:"4.5",r:"0.75",fill:"currentColor"})]}),Fz=()=>be("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",className:"igp-spinner",children:be("circle",{cx:"7",cy:"7",r:"5.5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeDasharray:"20 14"})}),zz=()=>be("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",children:be("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"})}),Oz=({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 be("div",{style:{...t,...n}})},q3=({element:e,app:t,onBeforeImageGen:o,onAfterImageGen:n})=>{let r=t.state,i=wp(t.props.geminiApiKey),[a,s]=Sn(()=>Ec(e.id)),[l,c]=Sn(()=>Mp(e.id)),[m,p]=Sn(()=>Wr(e.id)?.model??"Gemini 3.1 Flash"),d=Vr[m],u=d.supportedRatios,b=d.supportedResolutions,g=u.includes("1:1")?"1:1":u[0],E=b.includes("2K")?"2K":b[b.length-1],[y,x]=Sn(()=>Wr(e.id)?.ratio??g),[w,v]=Sn(()=>Wr(e.id)?.resolution??E);D0(()=>{let oe=Vr[m],Se=oe.supportedRatios;Se.includes(y)||x(Se.includes("1:1")?"1:1":Se[0]);let Z=oe.supportedResolutions;Z.includes(w)||v(Z.includes("2K")?"2K":Z[Z.length-1])},[m]);let[T,C]=Sn(()=>Ec(e.id)),[M,k]=Sn(null),[R,A]=Sn(!1),[P,_]=Sn(!1),[O,U]=Sn(!1),H=_p(null),W=_p(null),D=_p(null),F=_p(null),X=_0(oe=>{x(oe),A(!1)},[]);D0(()=>{let oe=Se=>{C(!1),Se?Se!=="aborted"&&k(Se):(s(!1),c(""))};return Ip(e.id,oe),()=>Cp(e.id,oe)},[e.id]),D0(()=>{let oe=Se=>{H.current&&!H.current.contains(Se.target)&&A(!1),W.current&&!W.current.contains(Se.target)&&_(!1),D.current&&!D.current.contains(Se.target)&&U(!1)};return document.addEventListener("mousedown",oe),()=>document.removeEventListener("mousedown",oe)},[]);let te=_0(()=>{Sp(e.id)},[e.id]),$=_0(async()=>{if(!l.trim()){k("Please enter a prompt.");return}if(!i){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:Tt,error:Z}=await o();if(!Tt){k(Z||"Insufficient credits for image generation");return}}catch{k("Credit check failed");return}let oe=new AbortController;F.current=oe,vp(e.id,l,{model:m,ratio:y,resolution:w},oe),C(!0),k(null);let Se=null;try{let Tt=Vr[m],Z=e.fileId?t.files[e.fileId]?.dataURL:void 0,de=await vc(l,Tt.geminiModelId,y,w,Tt.supportsImageSize,Tt.supportsThinking,i,Z,oe.signal),tt=Yi(m,y,w);await t.insertGeneratedImageNearElement(de,e,tt.width,tt.height),n?.()}catch(Tt){Tt instanceof Error&&(Tt.name==="AbortError"?Se="aborted":Se=Tt.message)}finally{F.current=null,Tp(e.id,Se),C(!1),Se===null?(kp(e.id),s(!1),c(""),k(null)):Se!=="aborted"&&k(Se)}},[l,i,m,y,w,t,e,o,n]);if(r.contextMenu||r.newElement||r.resizingElement||r.isRotating||r.openMenu||r.viewModeEnabled||r.selectedElementsAreBeingDragged)return null;let ae=t.scene.getNonDeletedElementsMap(),[xe,re,,we]=Dz(e,ae),{x:Fe,y:mt}=j3({sceneX:xe+e.width/2,sceneY:re},r),ct=Fe-r.offsetLeft,Ot=Math.max(mt-r.offsetTop-44,8),{x:uo,y:pr}=j3({sceneX:xe+e.width/2,sceneY:we},r),Hn=uo-r.offsetLeft,ur=pr-r.offsetTop+16;return Pt(Hz,{children:[be("div",{className:"iqep__trigger-bar",style:{left:`${ct}px`,top:`${Ot}px`},onPointerDown:oe=>oe.stopPropagation(),onClick:oe=>oe.stopPropagation(),children:Pt("button",{className:"iqep__trigger-btn",onClick:()=>s(oe=>!oe),title:"Quick AI edit",children:[be(zz,{}),be("span",{children:"AI Edit"})]})}),a&&be("div",{className:"igp iqep__panel",style:{left:`${Hn}px`,top:`${ur}px`},onPointerDown:oe=>oe.stopPropagation(),onClick:oe=>oe.stopPropagation(),children:Pt(Ms,{isLoading:T,value:l,onValueChange:c,onSubmit:$,className:"igp-container",children:[be(Ps,{placeholder:"Describe your edit\u2026",className:"igp-textarea",disableAutosize:!1}),M&&be("div",{className:"igp-error",children:M}),Pt(As,{className:"igp-actions",children:[be("div",{className:"igp-actions-left",children:Pt("div",{className:"igp-dropdown-root",ref:D,children:[be(rr,{tooltip:"Select model",side:"top",children:Pt("button",{className:"igp-btn",onClick:()=>{U(oe=>!oe),A(!1),_(!1)},disabled:T,children:[be(Nz,{}),be("span",{children:m}),be(R0,{})]})}),O&&be("div",{className:"igp-dropdown igp-dropdown--up igp-dropdown--left",children:L0.map(oe=>Pt("button",{className:"igp-dropdown-item",onClick:()=>{p(oe),U(!1)},children:[be("span",{style:{flex:1},children:oe}),oe===m&&be("span",{className:"igp-check",children:be(N0,{})})]},oe))})]})}),Pt("div",{className:"igp-actions-right",children:[Pt("div",{className:"igp-dropdown-root",ref:W,children:[Pt("button",{className:"igp-btn igp-btn--compact",onClick:()=>{b.length<=1||(_(oe=>!oe),A(!1),U(!1))},disabled:T||b.length<=1,title:b.length<=1?"Fixed resolution for this model":void 0,children:[be("span",{children:w}),b.length>1&&be(R0,{})]}),P&&b.length>1&&be("div",{className:"igp-dropdown igp-dropdown--up igp-dropdown--right",children:b.map(oe=>Pt("button",{className:"igp-dropdown-item",onClick:()=>{v(oe),_(!1)},children:[be("span",{style:{flex:1},children:oe}),oe===w&&be("span",{className:"igp-check",children:be(N0,{})})]},oe))})]}),Pt("div",{className:"igp-dropdown-root",ref:H,children:[Pt("button",{className:"igp-btn igp-btn--compact",onClick:()=>{A(oe=>!oe),_(!1),U(!1)},disabled:T,children:[be("span",{children:y}),be(R0,{})]}),R&&Pt("div",{className:"igp-dropdown igp-dropdown--up igp-dropdown--right igp-dropdown--ratio",children:[Pt("div",{className:"igp-dropdown-header",children:[be("span",{children:"Output format"}),be(Bz,{})]}),u.map(oe=>{let Se=Yi(m,oe,w);return Pt("button",{className:"igp-dropdown-item",onClick:()=>X(oe),children:[be(Oz,{label:oe}),be("span",{style:{flex:1},children:oe}),Pt("span",{className:"igp-dims",children:[Se.width,"\xD7",Se.height]}),oe===y&&be("span",{className:"igp-check",children:be(N0,{})})]},oe)})]})]}),be("button",{className:"igp-generate",onClick:T?te:$,disabled:!T&&!l.trim(),title:T?"Stop generation":"Generate edit",children:T?be(Fz,{}):be(Rz,{size:16})})]})]})]})})]})};import{DEFAULT_LASER_COLOR as Yz,easeOut as Q3}from"@orangecatai/common";import{LaserPointer as Gz}from"@excalidraw/laser-pointer";import{SVG_NS as J3,getSvgPathFromStroke as Uz,sceneCoordsToViewportCoords as Wz}from"@orangecatai/common";var ir=class{constructor(t,o,n){this.animationFrameHandler=t;this.app=o;this.options=n;S(this,"currentTrail");S(this,"pastTrails",[]);S(this,"container");S(this,"trailElement");S(this,"trailAnimation");this.animationFrameHandler.register(this,this.onFrame.bind(this)),this.trailElement=document.createElementNS(J3,"path"),this.options.animateTrail&&(this.trailAnimation=document.createElementNS(J3,"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 Gz(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(([i,a])=>{let s=Wz({sceneX:i,sceneY:a},o);return[s.x,s.y]}),r=this.trailAnimation?n.slice(0,n.length/2):n;return Uz(r,!0)}};var Dp=class{constructor(t,o){this.animationFrameHandler=t;this.app=o;S(this,"localTrail");S(this,"collabTrails",new Map);S(this,"container");this.animationFrameHandler.register(this,this.onFrame.bind(this)),this.localTrail=new ir(t,o,{...this.getTrailOptions(),fill:()=>Yz})}getTrailOptions(){return{simplify:0,streamline:.4,sizeMapping:t=>{let r=Math.max(0,1-(performance.now()-t.pressure)/1e3),i=(50-Math.min(50,t.totalLength-t.currentIndex))/50;return Math.min(Q3(i),Q3(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 ir(this.animationFrameHandler,this.app,{...this.getTrailOptions(),fill:()=>o.pointer?.laserColor||Li(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 Vz}from"react";import{unstable_batchedUpdates as e5}from"react-dom";import{throttleRAF as Kz}from"@orangecatai/common";var it=e=>t=>{e5(e,t)},Rp=e=>Kz(t=>{e5(e,t)}),Vi=(()=>{let e;try{let o=Vz.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 B0,KEYS as Tc,CLASSES as F0,POINTER_BUTTON as Xz,THEME as $z,isWritableElement as Zz,getFontString as t5,getFontFamilyString as o5,isTestEnv as n5,MIME_TYPES as z0,applyDarkModeFilter as jz}from"@orangecatai/common";import{getTextFromElements as qz,originalContainerCache as Jz,updateBoundElements as r5,updateOriginalContainerCache as i5}from"@orangecatai/element";import{LinearElementEditor as Qz}from"@orangecatai/element";import{bumpVersion as eO}from"@orangecatai/element";import{getBoundTextElementId as tO,getContainerElement as O0,getTextElementAngle as oO,redrawTextBoundingBox as nO,getBoundTextMaxHeight as rO,getBoundTextMaxWidth as a5,computeContainerDimensionForBoundText as s5,computeBoundTextPosition as iO,getBoundTextElement as aO}from"@orangecatai/element";import{getTextWidth as sO}from"@orangecatai/element";import{normalizeText as l5}from"@orangecatai/element";import{wrapText as lO}from"@orangecatai/element";import{isArrowElement as Np,isBoundToContainer as cO,isTextElement as c5}from"@orangecatai/element";var dO=(e,t,o,n,r,i)=>{let{zoom:a}=n,s=180*o/Math.PI,l=e*(a.value-1)/2,c=t*(a.value-1)/2;return e>r&&a.value!==1&&(l=r*(a.value-1)/2),t>i&&a.value!==1&&(c=i*(a.value-1)/2),`translate(${l}px, ${c}px) scale(${a.value}) rotate(${s}deg)`},d5=({id:e,onChange:t,onSubmit:o,getViewportCoords:n,element:r,canvas:i,excalidrawContainer:a,app:s,autoSelect:l=!0})=>{let c=(D,F)=>{if(!F.style.fontFamily||!F.style.fontSize)return!1;let X=F.style.fontFamily.replace(/"/g,"");return o5({fontFamily:D.fontFamily})!==X||`${D.fontSize}px`!==F.style.fontSize},m=s.state.theme,p=()=>{m=s.state.theme;let D=s.state,F=s.scene.getElement(e);if(!F)return;let{textAlign:X,verticalAlign:te}=F,$=s.scene.getNonDeletedElementsMap();if(F&&c5(F)){let ae=F.x,xe=F.y,re=O0(F,s.scene.getNonDeletedElementsMap()),we=F.width,Fe=F.height,mt=F.width,ct=F.height;if(re&&F.containerId){if(Np(re)){let Se=Qz.getBoundTextElementPosition(re,F,$);ae=Se.x,xe=Se.y}let ur=c(F,d),oe;if(ur?oe=i5(re.id,re.height):(oe=Jz[re.id],oe||(oe=i5(re.id,re.height))),mt=a5(re,F),ct=rO(re,F),!Np(re)&&Fe>ct){let Se=s5(Fe,re.type);s.scene.mutateElement(re,{height:Se}),r5(re,s.scene);return}else if(!Np(re)&&re.height>oe.height&&Fe<ct){let Se=s5(Fe,re.type);s.scene.mutateElement(re,{height:Se}),r5(re,s.scene)}else{let{x:Se,y:Tt}=iO(re,F,$);ae=Se,xe=Tt}}let[Ot,uo]=n(ae,xe);re?we+=.5:(mt=(D.width-8-Ot)/D.zoom.value,we=Math.min(we,mt)),Fe*=1.05;let pr=t5(F),Hn=(D.height-uo)/D.zoom.value;Object.assign(d.style,{font:pr,lineHeight:F.lineHeight,width:`${we}px`,height:`${Fe}px`,left:`${Ot}px`,top:`${uo}px`,transform:dO(we,Fe,oO(F,re),D,mt,Hn),textAlign:X,verticalAlign:te,color:D.theme===$z.DARK?jz(F.strokeColor):F.strokeColor,opacity:F.opacity/100,maxHeight:`${Hn}px`}),d.scrollTop=0,n5()&&(d.style.fontFamily=o5(F)),s.scene.mutateElement(F,{x:ae,y:xe})}},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",b="normal";(cO(r)||!r.autoResize)&&(u="pre-wrap",b="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:b,whiteSpace:u,overflowWrap:"break-word",boxSizing:"content-box"}),d.value=r.originalText,p(),t&&(d.onpaste=async D=>{let F=Dv(D),X=null;if(F.has(z0.excalidrawClipboard)||F.has(z0.excalidraw)){D.preventDefault(),X=await $a(D);try{let re=await mm(X);if(re.elements){let we=qz(re.elements);if(we){let{selectionStart:Fe,selectionEnd:mt,value:ct}=d;d.value=ct.slice(0,Fe)+we+ct.slice(mt);let Ot=Fe+we.length;d.selectionStart=d.selectionEnd=Ot,d.dispatchEvent(new Event("input"))}}return}catch{console.warn("failed to parse excalidraw clipboard data")}}X=X||await $a(D);let te=X.findByType(z0.text);if(!te)return;let $=l5(te.value);if(!$)return;let ae=O0(r,s.scene.getNonDeletedElementsMap()),xe=t5({fontSize:s.state.currentItemFontSize,fontFamily:s.state.currentItemFontFamily});if(ae){let re=aO(ae,s.scene.getNonDeletedElementsMap()),we=lO(`${d.value}${$}`,xe,a5(ae,re)),Fe=sO(we,xe);d.style.width=`${Fe}px`}},d.oninput=()=>{let D=l5(d.value);if(d.value!==D){let F=d.selectionStart;d.value=D,d.selectionStart=F,d.selectionEnd=F}t(d.value)}),d.onkeydown=D=>{if(!D.shiftKey&&tm.keyTest(D))D.preventDefault(),s.actionManager.executeAction(tm),p();else if(!D.shiftKey&&om.keyTest(D))D.preventDefault(),s.actionManager.executeAction(om),p();else if(!D.shiftKey&&nm.keyTest(D))D.preventDefault(),s.actionManager.executeAction(nm),p();else if(gh.keyTest(D))s.actionManager.executeAction(gh);else if(hh.keyTest(D))s.actionManager.executeAction(hh);else if(D.key===Tc.ESCAPE)D.preventDefault(),C=!0,M();else if(Pi.keyTest(D))D.preventDefault(),M(),s.actionManager.executeAction(Pi);else if(D.key===Tc.ENTER&&D[Tc.CTRL_OR_CMD]){if(D.preventDefault(),D.isComposing||D.keyCode===229)return;C=!0,M()}else if(D.key===Tc.TAB||D[Tc.CTRL_OR_CMD]&&(D.code===B0.BRACKET_LEFT||D.code===B0.BRACKET_RIGHT)){if(D.preventDefault(),D.isComposing)return;D.shiftKey||D.code===B0.BRACKET_LEFT?w():x(),d.dispatchEvent(new Event("input"))}};let g=4,E=" ".repeat(g),y=new RegExp(`^ {1,${g}}`),x=()=>{let{selectionStart:D,selectionEnd:F}=d,X=v(),te=d.value;X.forEach($=>{let ae=te.slice(0,$),xe=te.slice($);te=`${ae}${E}${xe}`}),d.value=te,d.selectionStart=D+g,d.selectionEnd=F+g*X.length},w=()=>{let{selectionStart:D,selectionEnd:F}=d,X=v(),te=[],$=d.value;X.forEach(ae=>{let xe=$.slice(ae,ae+g).match(y);if(xe){let re=$.slice(0,ae),we=$.slice(ae+xe[0].length);$=`${re}${we}`,te.push(ae)}}),d.value=$,te.length&&(D>te[te.length-1]?d.selectionStart=Math.max(D-g,te[te.length-1]):d.selectionStart=D,d.selectionEnd=Math.max(d.selectionStart,F-g*te.length))},v=()=>{let{selectionStart:D,selectionEnd:F,value:X}=d,te=X.slice(0,D).match(/[^\n]*$/)[0].length;return D=D-te,X.slice(D,F).split(`
|
|
15
|
+
`).reduce((ae,xe,re,we)=>ae.concat(re?ae[re-1]+we[re-1].length+1:D),[]).reverse()},T=D=>{D.target instanceof HTMLCanvasElement&&(D.preventDefault(),D.stopPropagation())},C=!1,M=()=>{if(H)return;H=!0,k();let D=s.scene.getElement(r.id);if(!D)return;let F=O0(D,s.scene.getNonDeletedElementsMap());if(F){if(d.value.trim()){let X=tO(F);!X||X!==r.id?s.scene.mutateElement(F,{boundElements:(F.boundElements||[]).concat({type:"text",id:r.id})}):Np(F)&&eO(F)}else s.scene.mutateElement(F,{boundElements:F.boundElements?.filter(X=>!c5(X))});nO(D,F,s.scene)}o({viaKeyboard:C,nextOriginalText:d.value})},k=()=>{d.onblur=null,d.oninput=null,d.onkeydown=null,W&&W.disconnect(),window.removeEventListener("resize",p),window.removeEventListener("wheel",T,!0),window.removeEventListener("pointerdown",P),window.removeEventListener("pointerup",R),window.removeEventListener("blur",M),window.removeEventListener("beforeunload",M),O(),_(),U(),d.remove()},R=D=>{window.removeEventListener("pointerup",R);let F=D?.target,X=F instanceof HTMLElement&&F.classList.contains("properties-trigger"),te=(F instanceof HTMLElement||F instanceof SVGElement)&&!!F.closest(".properties-content"),$=(F instanceof HTMLElement||F instanceof SVGElement)&&(!!F.closest(`.${F0.SHAPE_ACTIONS_MENU}`)||!!F.closest(".compact-shape-actions-island"));setTimeout(()=>{$||X||te||(d.onblur=M,d.focus())})},A=()=>{d.onblur=null,window.addEventListener("pointerup",R),window.addEventListener("blur",M)},P=D=>{let F=D?.target;if(D.button===Xz.WHEEL){F instanceof HTMLTextAreaElement&&(D.preventDefault(),s.handleCanvasPanUsingWheelOrSpaceDrag(D)),A();return}let X=F instanceof HTMLElement&&F.classList.contains("properties-trigger"),te=(F instanceof HTMLElement||F instanceof SVGElement)&&!!F.closest(".properties-content");(D.target instanceof HTMLElement||D.target instanceof SVGElement)&&(D.target.closest(`.${F0.SHAPE_ACTIONS_MENU}, .${F0.ZOOM_ACTIONS}`)||D.target.closest(".compact-shape-actions-island"))&&!Zz(D.target)||X||te?A():D.target instanceof HTMLCanvasElement&&!n5()&&requestAnimationFrame(()=>{M()})},_=s.onChangeEmitter.on(D=>{s.state.theme!==m&&p()}),O=s.scene.onUpdate(()=>{p(),!!document.activeElement?.closest(".properties-content")||d.focus()}),U=s.onScrollChangeEmitter.on(()=>{p()}),H=!1;l&&d.select(),R();let W=null;return i&&"ResizeObserver"in window?(W=new window.ResizeObserver(()=>{p()}),W.observe(i)):window.addEventListener("resize",p),d.onpointerdown=D=>D.stopPropagation(),requestAnimationFrame(()=>{window.addEventListener("pointerdown",P,{capture:!0})}),window.addEventListener("beforeunload",M),a?.querySelector(".excalidraw-textEditorContainer").appendChild(d),M};import{getGlobalCSSVariable as Bp}from"@orangecatai/common";import{getCommonBounds as mO}from"@orangecatai/element";var ar=4,_o=6,m5="rgba(0,0,0,0.3)",p5=(e,t,o,n)=>{if(!e.size)return{horizontal:null,vertical:null};let[r,i,a,s]=mO(e),l=t/n.zoom.value,c=o/n.zoom.value,m={top:parseInt(Bp("sat"))||0,bottom:parseInt(Bp("sab"))||0,left:parseInt(Bp("sal"))||0,right:parseInt(Bp("sar"))||0},p=Wn().rtl,d=-n.scrollX+m.left,u=-n.scrollY+m.top,b=d+l-m.right,g=u+c-m.bottom,E=Math.min(r,d),y=Math.min(i,u),x=Math.max(a,b),w=Math.max(s,g),v=a-r,T=s-i,C=x-E,M=w-y,k=Math.max(ar*2,m.left+m.right)+_o*2,R=t*(l/C)-k,A=Math.max(ar*2,m.top+m.bottom)+_o*2,P=o*(c/M)-A,_=C>v?C*n.zoom.value/(R+k):t/(R+k),O=M>T?M*n.zoom.value/(P+A):o/(P+A);return{horizontal:d===E&&b===x?null:{x:Math.max(m.left,ar)+_o+(d-E)/C*t,y:o-_o-Math.max(ar,m.bottom),width:R,height:_o,deltaMultiplier:_},vertical:u===y&&g===w?null:{x:p?Math.max(m.left,ar):t-_o-Math.max(m.right,ar),y:Math.max(m.top,ar)+_o+(u-y)/M*o,width:_o,height:P,deltaMultiplier:O}}},H0=(e,t,o)=>{let[n,r]=[e.horizontal,e.vertical].map(a=>a!=null&&a.x<=t&&t<=a.x+a.width&&a.y<=o&&o<=a.y+a.height);return{isOverEither:n||r,isOverHorizontal:n,isOverVertical:r}};var u5=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 wO}from"@orangecatai/math";import{getElementLineSegments as vO}from"@orangecatai/element";import{LinearElementEditor as TO}from"@orangecatai/element";import{isFrameLikeElement as IO,isLinearElement as CO,isTextElement as kO}from"@orangecatai/element";import{getFrameChildren as SO}from"@orangecatai/element";import{selectGroupsForSelectedElements as MO}from"@orangecatai/element";import{getContainerElement as PO}from"@orangecatai/element";import{arrayToMap as AO,easeOut as b5,isShallowEqual as LO}from"@orangecatai/common";import{simplify as pO}from"points-on-curve";import{polygonFromPoints as uO,lineSegment as g5,polygonIncludesPointNonZero as gO}from"@orangecatai/math";import{computeBoundTextPosition as hO,doBoundsIntersect as fO,getBoundTextElement as bO,getElementBounds as xO,intersectElementWithLineSegment as h5}from"@orangecatai/element";var f5=e=>{let{lassoPath:t,elements:o,elementsMap:n,elementsSegments:r,intersectedElements:i,enclosedElements:a,simplifyDistance:s}=e,l=t;s&&(l=pO(t,s));let c=o.filter(d=>!d.locked);a.clear(),i.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=xO(d,n);fO(m,u)&&!i.has(d.id)&&!a.has(d.id)&&(EO(l,d,r)?a.add(d.id):yO(l,d,n)&&i.add(d.id))}return{selectedElementIds:[...i,...a]}},EO=(e,t,o)=>{let n=uO(e),r=o.get(t.id);return r?r.some(i=>i.some(a=>gO(a,n))):!1},yO=(e,t,o)=>{let n=e.slice(1).map((i,a)=>g5(e[a],i)).concat([g5(e[e.length-1],e[0])]),r=bO(t,o);return n.some(i=>h5(t,o,i,0,!0).length>0||!!r&&h5({...r,...hO(t,r,o)},o,i,0,!0).length>0)};var Fp=class extends ir{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(b5(l),b5(s))},fill:()=>"rgba(105,101,219,0.05)",stroke:()=>"rgba(105,101,219)"});S(this,"intersectedElements",new Set);S(this,"enclosedElements",new Set);S(this,"elementsSegments",null);S(this,"canvasTranslate",null);S(this,"keepPreviousSelection",!1);S(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&&kO(c)){let m=PO(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&&IO(c)){let m=SO(this.app.scene.getNonDeletedElementsMap(),c.id);for(let p of m)delete r[p.id]}}let i=MO({editingGroupId:n.editingGroupId,selectedElementIds:r},this.app.scene.getNonDeletedElements(),n,this.app),a=[...Object.keys(i.selectedElementIds)],s=[...Object.keys(i.selectedGroupIds)];return{selectedElementIds:i.selectedElementIds,selectedGroupIds:i.selectedGroupIds,selectedLinearElement:a.length===1&&!s.length&&CO(this.app.scene.getNonDeletedElement(a[0]))?new TO(this.app.scene.getNonDeletedElement(a[0]),this.app.scene.getNonDeletedElementsMap()):null}})});S(this,"addPointToPath",(o,n,r=!1)=>{super.addPointToPath(o,n),this.keepPreviousSelection=r,this.updateSelection()});S(this,"updateSelection",()=>{let o=super.getCurrentTrail()?.originalPoints?.map(r=>wO(r[0],r[1])),n={scrollX:this.app.state.scrollX,scrollY:this.app.state.scrollY,zoom:this.app.state.zoom.value};if(!this.elementsSegments||!LO(n,this.canvasTranslate??{})){this.canvasTranslate=n,this.elementsSegments=new Map;let r=AO(this.app.visibleElements);for(let i of this.app.visibleElements){let a=vO(i,r);this.elementsSegments.set(i.id,a)}}if(o){let{selectedElementIds:r}=f5({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 _O,easeOut as x5,THEME as DO}from"@orangecatai/common";import{computeBoundTextPosition as RO,doBoundsIntersect as NO,getBoundTextElement as BO,getElementBounds as FO,getElementLineSegments as zO,getFreedrawOutlineAsSegments as OO,getFreedrawOutlinePoints as HO,intersectElementWithLineSegment as E5,isArrowElement as GO,isFreeDrawElement as y5,isLineElement as UO,isPointInElement as WO}from"@orangecatai/element";import{lineSegment as YO,lineSegmentsDistance as w5,pointFrom as S5,polygon as VO,polygonIncludesPointNonZero as KO}from"@orangecatai/math";import{getElementsInGroup as v5}from"@orangecatai/element";import{shouldTestInside as XO}from"@orangecatai/element";import{hasBoundTextElement as T5,isBoundToContainer as I5}from"@orangecatai/element";import{getBoundTextElementId as C5}from"@orangecatai/element";var zp=class extends ir{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(x5(l),x5(s))},fill:()=>n.state.theme===DO.LIGHT?"rgba(0, 0, 0, 0.2)":"rgba(255, 255, 255, 0.2)"});S(this,"elementsToErase",new Set);S(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=>S5(s[0],s[1]))||[];if(n.length<2)return[];let r=YO(n[n.length-1],n[n.length-2]),i=this.app.visibleElements.filter(s=>!s.locked),a=_O(i);for(let s of i)if(o&&this.elementsToErase.has(s.id)){if(k5(r,s,a,this.app.state.zoom.value)){let c=s.groupIds.at(-1);if(this.groupsToErase.has(c)){let m=v5(this.app.scene.getNonDeletedElementsMap(),c);for(let p of m)this.elementsToErase.delete(p.id);this.groupsToErase.delete(c)}if(I5(s)&&this.elementsToErase.delete(s.containerId),T5(s)){let m=C5(s);m&&this.elementsToErase.delete(m)}this.elementsToErase.delete(s.id)}}else if(!o&&!this.elementsToErase.has(s.id)&&k5(r,s,a,this.app.state.zoom.value)){let c=s.groupIds.at(-1);if(!this.groupsToErase.has(c)){let m=v5(this.app.scene.getNonDeletedElementsMap(),c);for(let p of m)this.elementsToErase.add(p.id);this.groupsToErase.add(c)}if(T5(s)){let m=C5(s);m&&this.elementsToErase.add(m)}I5(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()}},k5=(e,t,o,n)=>{let r=e[1],i=y5(t)?15:t.strokeWidth/2,a=[Math.min(e[0][0],e[1][0])-i,Math.min(e[0][1],e[1][1])-i,Math.max(e[0][0],e[1][0])+i,Math.max(e[0][1],e[1][1])+i],s=FO(t,o),l=[s[0]-i,s[1]-i,s[2]+i,s[3]+i];if(!NO(a,l))return!1;if(XO(t)&&WO(r,t,o))return!0;if(y5(t)){let m=HO(t),p=OO(t,m,o),d=Math.max(2.25,5/n);for(let b of p)if(w5(b,e)<=d)return!0;let u=VO(...m.map(([b,g])=>S5(t.x+b,t.y+g)));return!!KO(e[0],u)}let c=BO(t,o);if(GO(t)||UO(t)&&!t.polygon){let m=Math.max(t.strokeWidth,t.strokeWidth*2/n),p=zO(t,o);for(let d of p)if(w5(d,e)<=m)return!0;return!1}return E5(t,o,e,0,!0).length>0||!!c&&E5({...c,...RO(t,c,o)},o,e,0,!0).length>0};import{jsx as Do,jsxs as M5}from"react/jsx-runtime";var $O=()=>M5("div",{"data-testid":"brave-measure-text-error",children:[Do("p",{children:Do(qt,{i18nKey:"errors.brave_measure_text_error.line1",bold:e=>Do("span",{style:{fontWeight:600},children:e})})}),Do("p",{children:Do(qt,{i18nKey:"errors.brave_measure_text_error.line2",bold:e=>Do("span",{style:{fontWeight:600},children:e})})}),Do("p",{children:Do(qt,{i18nKey:"errors.brave_measure_text_error.line3",link:e=>Do("a",{href:"http://docs.excalidraw.com/docs/@orangecatai/adgen-canvas/faq#turning-off-aggresive-block-fingerprinting-in-brave-browser",children:e})})}),Do("p",{children:Do(qt,{i18nKey:"errors.brave_measure_text_error.line4",issueLink:e=>Do("a",{href:"https://github.com/excalidraw/excalidraw/issues/new",children:e}),discordLink:e=>M5("a",{href:"https://discord.gg/UexuTaE",children:[e,"."]})})})]}),P5=$O;import tH from"clsx";import oH from"react";import{useLayoutEffect as ZO,useRef as A5,useEffect as L5}from"react";import{unstable_batchedUpdates as jO}from"react-dom";import{KEYS as qO,queryFocusableElements as JO}from"@orangecatai/common";import QO from"clsx";import{jsx as eH}from"react/jsx-runtime";var _5=({children:e,left:t,top:o,onCloseRequest:n,fitInViewport:r=!1,offsetLeft:i=0,offsetTop:a=0,viewportWidth:s=window.innerWidth,viewportHeight:l=window.innerHeight,className:c})=>{let m=A5(null);L5(()=>{let d=m.current;if(!d)return;d.contains(document.activeElement)||d.focus();let u=b=>{if(b.key===qO.TAB){let g=JO(d),{activeElement:E}=document,y=g.findIndex(x=>x===E);E===d?(b.shiftKey?g[g.length-1]?.focus():g[0].focus(),b.preventDefault(),b.stopImmediatePropagation()):y===0&&b.shiftKey?(g[g.length-1]?.focus(),b.preventDefault(),b.stopImmediatePropagation()):y===g.length-1&&!b.shiftKey&&(g[0]?.focus(),b.preventDefault(),b.stopImmediatePropagation())}};return d.addEventListener("keydown",u),()=>d.removeEventListener("keydown",u)},[]);let p=A5(null);return ZO(()=>{if(r&&m.current&&o!=null&&t!=null){let d=m.current,{width:u,height:b}=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-i>s?d.style.left=`${s-u-10}px`:d.style.left=`${t}px`,b>=l?(d.style.height=`${l-20}px`,d.style.top="10px",d.style.overflowY="scroll"):o+b-a>l?d.style.top=`${l-b}px`:d.style.top=`${o}px`}},[o,t,r,s,l,i,a]),L5(()=>{if(n){let d=u=>{m.current?.contains(u.target)||jO(()=>n(u))};return document.addEventListener("pointerdown",d,!1),()=>document.removeEventListener("pointerdown",d,!1)}},[n]),eH("div",{className:QO("popover",c),ref:m,tabIndex:-1,children:e})};import{jsx as Ls,jsxs as nH}from"react/jsx-runtime";var ut="separator",D5=oH.memo(({actionManager:e,items:t,top:o,left:n,onClose:r})=>{let i=fn(),a=Tr(),s=t.reduce((l,c)=>(c&&(c===ut||!c.predicate||c.predicate(a,i,e.app.props,e.app))&&l.push(c),l),[]);return Ls(_5,{onCloseRequest:()=>{r()},top:o,left:n,fitInViewport:!0,offsetLeft:i.offsetLeft,offsetTop:i.offsetTop,viewportWidth:i.width,viewportHeight:i.height,className:"context-menu-popover",children:Ls("ul",{className:"context-menu",onContextMenu:l=>l.preventDefault(),children:s.map((l,c)=>{if(l===ut)return!s[c-1]||s[c-1]===ut?null:Ls("hr",{className:"context-menu-item-separator"},c);let m=l.name,p="";return l.label&&(typeof l.label=="function"?p=h(l.label(a,i,e.app)):p=h(l.label)),Ls("li",{"data-testid":m,onClick:()=>{r(()=>{e.executeAction(l,"contextMenu")})},children:nH("button",{type:"button",className:tH("context-menu-item",{dangerous:m==="deleteSelectedElements",checkmark:l.checked?.(i)}),children:[Ls("div",{className:"context-menu-item__label",children:p}),Ls("kbd",{className:"context-menu-item__shortcut",children:m?Ue(m):""})]})},c)})})})});import{jsx as G0,jsxs as R5}from"react/jsx-runtime";var rH=({height:e,width:t,userToFollow:o,onDisconnect:n})=>G0("div",{className:"follow-mode",style:{width:t,height:e},children:R5("div",{className:"follow-mode__badge",children:[R5("div",{className:"follow-mode__badge__label",children:["Following"," ",G0("span",{className:"follow-mode__badge__username",title:o.username,children:o.username})]}),G0("button",{type:"button",onClick:n,className:"follow-mode__disconnect-btn",children:To})]})}),N5=rH;import Qi from"clsx";import eV from"react";import{CLASSES as tV,DEFAULT_SIDEBAR as Jb,TOOL_TYPE as BS,arrayToMap as oV,capitalizeString as nV,isShallowEqual as Iu}from"@orangecatai/common";import{mutateElement as rV}from"@orangecatai/element";import{showSelectedShapeActions as iV}from"@orangecatai/element";import{ShapeCache as aV}from"@orangecatai/element";import iH from"clsx";import{useState as aH,useEffect as sH}from"react";import{THEME as lH}from"@orangecatai/common";import{jsx as U0,jsxs as cH}from"react/jsx-runtime";var Op=({delay:e,theme:t})=>{let[o,n]=aH(!!e);return sH(()=>{if(!e)return;let r=setTimeout(()=>{n(!1)},e);return()=>clearTimeout(r)},[e]),o?null:cH("div",{className:iH("LoadingMessage",{"LoadingMessage--dark":t===lH.DARK}),children:[U0("div",{children:U0(Bt,{})}),U0("div",{className:"LoadingMessage-text",children:h("labels.loadingScene")})]})};import dH from"clsx";import{jsx as F5,jsxs as pH}from"react/jsx-runtime";var mH="medium",B5={CHECKED:ha,UNCHECKED:bi},z5=e=>pH("label",{className:dH("ToolIcon ToolIcon__lock",`ToolIcon_size_${mH}`,{"is-mobile":e.isMobile}),title:`${e.title} \u2014 Q`,children:[F5("input",{className:"ToolIcon_type_checkbox",type:"checkbox",name:e.name,onChange:e.onChange,checked:e.checked,"aria-label":e.title,"data-testid":"toolbar-lock"}),F5("div",{className:"ToolIcon__icon",children:e.checked?B5.CHECKED:B5.UNCHECKED})]});import{useState as Hp,useEffect as G5}from"react";import _s from"clsx";import{KEYS as W0,capitalizeString as ht}from"@orangecatai/common";import uH from"clsx";import{KEYS as O5}from"@orangecatai/common";import{jsx as gH}from"react/jsx-runtime";var H5=e=>gH(ee,{className:uH("Shape",{fillable:!1,active:e.checked}),type:"radio",icon:Ta,name:"editor-current-shape",checked:e.checked,title:`${e.title} \u2014 H`,keyBindingLabel:e.isMobile?void 0:O5.H.toLocaleUpperCase(),"aria-label":`${e.title} \u2014 H`,"aria-keyshortcuts":O5.H,"data-testid":"toolbar-hand",onChange:()=>e.onChange?.()});import{Fragment as hH,jsx as gt,jsxs as Gp}from"react/jsx-runtime";var Y0=[{type:"rectangle",icon:fa,title:ht(h("toolBar.rectangle"))},{type:"diamond",icon:ba,title:ht(h("toolBar.diamond"))},{type:"ellipse",icon:xa,title:ht(h("toolBar.ellipse"))}],V0=[{type:"selection",icon:xi,title:ht(h("toolBar.selection"))},{type:"lasso",icon:br,title:ht(h("toolBar.lasso"))}],K0=[{type:"arrow",icon:xd,title:ht(h("toolBar.arrow"))},{type:"line",icon:Ea,title:ht(h("toolBar.line"))}],U5=({app:e,onHandToolToggle:t,setAppState:o})=>{let n=e.state.activeTool,[r,i]=Hp(!1),[a,s]=Hp("rectangle"),[l,c]=Hp("arrow");G5(()=>{(n.type==="rectangle"||n.type==="diamond"||n.type==="ellipse")&&s(n.type)},[n.type]),G5(()=>{(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}=We(),b=(_,O)=>{e.state.activeTool.type!==_&&he("toolbar",_,"ui"),_==="selection"?e.state.activeTool.type==="selection"||e.setActiveTool({type:"selection"}):e.setActiveTool({type:_})},[g,E]=Hp(0),y=36,x=4,w=7,v=w*y+(w-1)*x,T=y+x,C=g>=v+1*T,M=g>=v+2*T,k=g>=v+3*T,A=["text","frame","embeddable","laser","magicframe"].filter(_=>!(C&&_==="text"||M&&_==="image"||k&&_==="frame")).includes(n.type),P=A?n.type==="text"?gn:n.type==="image"?xr:n.type==="frame"?Vo:n.type==="embeddable"?ya:n.type==="laser"?hn:n.type==="magicframe"?wi:yl:yl;return Gp("div",{className:"mobile-toolbar",ref:_=>{_&&E(_.getBoundingClientRect().width)},children:[gt(H5,{checked:Un(e.state),onChange:t,title:h("toolBar.hand"),isMobile:!0}),gt(bs,{app:e,options:V0,activeTool:n,defaultOption:e.state.preferredSelectionTool.type,namePrefix:"selectionType",title:ht(h("toolBar.selection")),"data-testid":"toolbar-selection",onToolChange:_=>{(_==="selection"||_==="lasso")&&(e.setActiveTool({type:_}),o({preferredSelectionTool:{type:_,initialized:!0}}))},displayedOption:V0.find(_=>_.type===e.state.preferredSelectionTool.type)||V0[0]}),gt(ee,{className:_s({active:n.type==="freedraw"}),type:"radio",icon:un,checked:n.type==="freedraw",name:"editor-current-shape",title:`${ht(h("toolBar.freedraw"))}`,"aria-label":ht(h("toolBar.freedraw")),"data-testid":"toolbar-freedraw",onChange:()=>b("freedraw")}),gt(ee,{className:_s({active:n.type==="eraser"}),type:"radio",icon:Ed,checked:n.type==="eraser",name:"editor-current-shape",title:`${ht(h("toolBar.eraser"))}`,"aria-label":ht(h("toolBar.eraser")),"data-testid":"toolbar-eraser",onChange:()=>b("eraser")}),gt(bs,{app:e,options:Y0,activeTool:n,defaultOption:a,namePrefix:"shapeType",title:ht(h(a==="rectangle"?"toolBar.rectangle":a==="diamond"?"toolBar.diamond":a==="ellipse"?"toolBar.ellipse":"toolBar.rectangle")),"data-testid":"toolbar-rectangle",onToolChange:_=>{(_==="rectangle"||_==="diamond"||_==="ellipse")&&(s(_),e.setActiveTool({type:_}))},displayedOption:Y0.find(_=>_.type===a)||Y0[0]}),gt(bs,{app:e,options:K0,activeTool:n,defaultOption:l,namePrefix:"linearElementType",title:ht(h(l==="arrow"?"toolBar.arrow":"toolBar.line")),"data-testid":"toolbar-arrow",fillable:!0,onToolChange:_=>{(_==="arrow"||_==="line")&&(c(_),e.setActiveTool({type:_}))},displayedOption:K0.find(_=>_.type===l)||K0[0]}),C&>(ee,{className:_s({active:n.type==="text"}),type:"radio",icon:gn,checked:n.type==="text",name:"editor-current-shape",title:`${ht(h("toolBar.text"))}`,"aria-label":ht(h("toolBar.text")),"data-testid":"toolbar-text",onChange:()=>b("text")}),M&>(ee,{className:_s({active:n.type==="image"}),type:"radio",icon:xr,checked:n.type==="image",name:"editor-current-shape",title:`${ht(h("toolBar.image"))}`,"aria-label":ht(h("toolBar.image")),"data-testid":"toolbar-image",onChange:()=>b("image")}),k&>(ee,{className:_s({active:m}),type:"radio",icon:Vo,checked:m,name:"editor-current-shape",title:`${ht(h("toolBar.frame"))}`,"aria-label":ht(h("toolBar.frame")),"data-testid":"toolbar-frame",onChange:()=>b("frame")}),Gp(pe,{open:r,children:[gt(pe.Trigger,{className:_s("App-toolbar__extra-tools-trigger App-toolbar__extra-tools-trigger--mobile",{"App-toolbar__extra-tools-trigger--selected":A||r}),onToggle:()=>{i(!r),o({openMenu:null,openPopup:null})},title:h("toolBar.extraTools"),style:{width:y,height:y,display:"flex",alignItems:"center",justifyContent:"center"},children:P}),Gp(pe.Content,{onClickOutside:()=>i(!1),onSelect:()=>i(!1),className:"App-toolbar__extra-tools-dropdown",align:"start",children:[!C&>(pe.Item,{onSelect:()=>e.setActiveTool({type:"text"}),icon:gn,shortcut:W0.T.toLocaleUpperCase(),"data-testid":"toolbar-text",selected:n.type==="text",children:h("toolBar.text")}),!M&>(pe.Item,{onSelect:()=>e.setActiveTool({type:"image"}),icon:xr,"data-testid":"toolbar-image",selected:n.type==="image",children:h("toolBar.image")}),!k&>(pe.Item,{onSelect:()=>e.setActiveTool({type:"frame"}),icon:Vo,shortcut:W0.F.toLocaleUpperCase(),"data-testid":"toolbar-frame",selected:m,children:h("toolBar.frame")}),gt(pe.Item,{onSelect:()=>e.setActiveTool({type:"embeddable"}),icon:ya,"data-testid":"toolbar-embeddable",selected:d,children:h("toolBar.embeddable")}),gt(pe.Item,{onSelect:()=>e.setActiveTool({type:"laser"}),icon:hn,"data-testid":"toolbar-laser",selected:p,shortcut:W0.K.toLocaleUpperCase(),children:h("toolBar.laser")}),gt("div",{style:{margin:"6px 0",fontSize:14,fontWeight:600},children:"Generate"}),e.props.aiEnabled!==!1&>(u.Out,{}),gt(pe.Item,{onSelect:()=>e.setOpenDialog({name:"ttd",tab:"mermaid"}),icon:Ca,"data-testid":"toolbar-embeddable",children:h("toolBar.mermaidToExcalidraw")}),e.props.aiEnabled!==!1&&e.plugins.diagramToCode&>(hH,{children:Gp(pe.Item,{onSelect:()=>e.onMagicframeToolSelect(),icon:wi,"data-testid":"toolbar-magicframe",children:[h("toolBar.magicframe"),gt(pe.Item.Badge,{children:"AI"})]})})]})]})]})};import fH from"clsx";import{jsx as bH}from"react/jsx-runtime";var Up=({children:e,side:t,className:o})=>bH("div",{className:fH("FixedSideContainer",`FixedSideContainer_side_${t}`,o),children:e});import xH from"clsx";import{jsx as W5,jsxs as yH}from"react/jsx-runtime";var EH="medium",Wp=e=>e.penDetected?yH("label",{className:xH("ToolIcon ToolIcon__penMode",`ToolIcon_size_${EH}`,{"is-mobile":e.isMobile}),title:`${e.title}`,children:[W5("input",{className:"ToolIcon_type_checkbox",type:"checkbox",name:e.name,onChange:e.onChange,checked:e.checked,"aria-label":e.title}),W5("div",{className:"ToolIcon__icon",children:rE})]}):null;import{Fragment as Y5,jsx as Mn,jsxs as Ki}from"react/jsx-runtime";var V5=({appState:e,elements:t,actionManager:o,setAppState:n,onHandToolToggle:r,renderTopLeftUI:i,renderTopRightUI:a,renderSidebars:s,renderWelcomeScreen:l,UIOptions:c,app:m,onPenModeToggle:p})=>{let{WelcomeScreenCenterTunnel:d,MainMenuTunnel:u,DefaultSidebarTriggerTunnel:b}=We(),g=()=>{if(e.openDialog?.name==="elementLinkSelector")return null;let y=Ki("div",{className:"excalidraw-ui-top-right",children:[a?.(!0,e)??(!e.viewModeEnabled&&Ki(Y5,{children:[Mn(Wp,{checked:e.penMode,onChange:()=>p(null),title:h("toolBar.penMode"),isMobile:!0,penDetected:e.penDetected}),Mn(b.Out,{})]})),e.viewModeEnabled&&Mn(PI,{actionManager:o})]}),x=Ki("div",{className:"excalidraw-ui-top-left",children:[i?.(!0,e),Mn(u.Out,{})]});return Ki("div",{className:"App-toolbar-content",style:{display:"flex",flexDirection:"row",justifyContent:"space-between"},children:[x,y]})},E=()=>Mn(U5,{app:m,onHandToolToggle:r,setAppState:n});return Ki(Y5,{children:[s(),Mn("div",{className:"App-welcome-screen",children:l&&Mn(d.Out,{})}),!e.viewModeEnabled&&Ki("div",{className:"App-bottom-bar",style:{marginBottom:_o+ar},children:[Mn(TI,{appState:e,elementsMap:m.scene.getNonDeletedElementsMap(),renderAction:o.renderAction,app:m,setAppState:n}),Ki(st,{className:"App-toolbar",children:[!e.viewModeEnabled&&e.openDialog?.name!=="elementLinkSelector"&&E(),e.scrolledOutside&&!e.openMenu&&!e.openSidebar&&Mn("button",{type:"button",className:"scroll-back-to-content",onClick:()=>{n(y=>({...gi(t,y)}))},children:h("buttons.scrollBackToContent")})]})]}),Mn(Up,{side:"top",className:"App-top-bar",children:g()})]})};import wH,{useLayoutEffect as vH,useRef as TH,useState as IH}from"react";import{jsx as Ic,jsxs as CH}from"react/jsx-runtime";var K5=e=>{let t=TH(null),[o,n]=IH(null);return vH(()=>{if(!e.spreadsheet)return;let r=Mv(e.chartType,e.spreadsheet,0,0);n(r);let i,a=t.current;return(async()=>(i=await da(r,{exportBackground:!1,viewBackgroundColor:"#fff"},null,{skipInliningFonts:!0}),i.querySelector(".style-fonts")?.remove(),a.replaceChildren(),a.appendChild(i),e.selected&&a.parentNode.focus()))(),()=>{a.replaceChildren()}},[e.spreadsheet,e.chartType,e.selected]),Ic("button",{type:"button",className:"ChartPreview",onClick:()=>{o&&e.onClick(e.chartType,o)},children:Ic("div",{ref:t})})},X5=({setAppState:e,appState:t,onClose:o})=>{let{onInsertElements:n}=Xe(),r=wH.useCallback(()=>{o&&o()},[o]),i=(a,s)=>{n(s),he("paste","chart",a),e({currentChartType:a,pasteDialog:{shown:!1,data:null}})};return Ic(dt,{size:"small",onCloseRequest:r,title:h("labels.pasteCharts"),className:"PasteChartDialog",autofocus:!1,children:CH("div",{className:"container",children:[Ic(K5,{chartType:"bar",spreadsheet:t.pasteDialog.data,selected:t.currentChartType==="bar",onClick:i}),Ic(K5,{chartType:"line",spreadsheet:t.pasteDialog.data,selected:t.currentChartType==="line",onClick:i})]})})};import{Fragment as kH,jsx as $5,jsxs as SH}from"react/jsx-runtime";var Cc=({heading:e,children:t,...o})=>{let{id:n}=Ke(),r=$5("h2",{className:"visually-hidden",id:`${n}-${e}-title`,children:h(`headings.${e}`)});return $5("section",{...o,"aria-labelledby":`${n}-${e}-title`,children:typeof t=="function"?t(r):SH(kH,{children:[r,t]})})};import{Popover as Yp}from"radix-ui";import Z5 from"clsx";import Vp,{useLayoutEffect as MH}from"react";import{supportsResizeObserver as PH,isShallowEqual as AH}from"@orangecatai/common";import{Fragment as NH,jsx as Pn,jsxs as Kp}from"react/jsx-runtime";var LH=4,_H=8,DH=({shouldWrap:e,children:t,username:o})=>e?Pn(ro,{label:o||"Unknown user",children:t}):Pn(NH,{children:t}),X0=({actionManager:e,collaborator:t,socketId:o,withName:n=!1,shouldWrapWithTooltip:r=!1,isBeingFollowed:i})=>{let a={socketId:o,collaborator:t,withName:n,isBeingFollowed:i},s=e.renderAction("goToCollaborator",a);return Pn(DH,{username:t.username,shouldWrap:r,children:s},o)},RH=["avatarUrl","id","socketId","username","isInCall","isSpeaking","isMuted"],Xp=Vp.memo(({className:e,mobile:t,collaborators:o,userToFollow:n})=>{let r=qe(),i=new Map;o.forEach((g,E)=>{let y=g.id||E;i.set(y,{...g,socketId:E})});let a=Array.from(i.values()).filter(g=>g.username?.trim()),[s,l]=Vp.useState(""),c=a.filter(g=>g.username?.toLowerCase().includes(s)),m=Vp.useRef(null);MH(()=>{if(m.current){let g=y=>{let x=Math.max(1,Math.min(8,Math.floor(y/38)));d(x)};if(g(m.current.clientWidth),!PH)return;let E=new ResizeObserver(y=>{for(let x of y){let{width:w}=x.contentRect;g(w)}});return E.observe(m.current),()=>{E.disconnect()}}},[]);let[p,d]=Vp.useState(LH),b=a.slice(0,p-1).map(g=>X0({actionManager:r,collaborator:g,socketId:g.socketId,shouldWrapWithTooltip:!0,isBeingFollowed:g.socketId===n}));return t?Pn("div",{className:Z5("UserList UserList_mobile",e),children:a.map(g=>X0({actionManager:r,collaborator:g,socketId:g.socketId,shouldWrapWithTooltip:!0,isBeingFollowed:g.socketId===n}))}):Pn("div",{className:"UserList__wrapper",ref:m,children:Kp("div",{className:Z5("UserList",e),style:{"--max-avatars":p},children:[b,a.length>p-1&&Kp(Yp.Root,{children:[Kp(Yp.Trigger,{className:"UserList__more",children:["+",a.length-p+1]}),Pn(Yp.Content,{style:{zIndex:2,width:"15rem",textAlign:"left"},align:"end",sideOffset:10,children:Kp(st,{padding:2,children:[a.length>=_H&&Pn(Vd,{placeholder:h("quickSearch.placeholder"),onChange:l}),Pn(Kd,{className:"dropdown-menu UserList__collaborators",placeholder:h("userList.empty"),children:c.length>0?[Pn("div",{className:"hint",children:h("userList.hint.text")}),c.map(g=>X0({actionManager:r,collaborator:g,socketId:g.socketId,withName:!0,isBeingFollowed:g.socketId===n}))]:[]}),Pn(Yp.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 i=t.collaborators.get(n);if(!i||n!==o.next().value||!AH(r,i,RH))return!1}return!0});import $0 from"clsx";import{jsx as BH}from"react/jsx-runtime";var j5=e=>BH("button",{className:"help-icon",onClick:e.onClick,type:"button",title:`${h("helpDialog.title")} \u2014 ?`,"aria-label":h("helpDialog.title"),children:wa});import{jsx as tn,jsxs as $p}from"react/jsx-runtime";var q5=({appState:e,actionManager:t,showExitZenModeBtn:o,renderWelcomeScreen:n})=>{let{FooterCenterTunnel:r,WelcomeScreenHelpHintTunnel:i}=We();return $p("footer",{role:"contentinfo",className:"layer-ui__wrapper__footer App-menu App-menu_bottom",children:[tn("div",{className:$0("layer-ui__wrapper__footer-left zen-mode-transition",{"layer-ui__wrapper__footer-left--transition-left":e.zenModeEnabled}),children:tn(Ft.Col,{gap:2,children:tn(Cc,{heading:"canvasActions",children:$p(Ft.Col,{gap:1,className:"footer-canvas-actions",children:[tn(CI,{renderAction:t.renderAction}),$p(Ft.Row,{align:"center",gap:1,className:"footer-canvas-actions-row",children:[tn(kI,{renderAction:t.renderAction,zoom:e.zoom}),!e.viewModeEnabled&&tn(SI,{renderAction:t.renderAction,className:$0("zen-mode-transition",{"layer-ui__wrapper__footer-left--transition-bottom":e.zenModeEnabled})})]})]})})})}),tn(r.Out,{}),tn("div",{className:$0("layer-ui__wrapper__footer-right zen-mode-transition",{"transition-right":e.zenModeEnabled}),children:$p("div",{style:{position:"relative"},children:[n&&tn(i.Out,{}),tn(j5,{onClick:()=>t.executeAction(Ai)})]})}),tn(MI,{actionManager:t,showExitZenModeBtn:o})]})},J5=q5;q5.displayName="Footer";import $H from"clsx";import{useEffect as iC,useLayoutEffect as aC,useRef as nb,useState as ZH,forwardRef as sC,useImperativeHandle as jH,useCallback as oC}from"react";import{CLASSES as qH,EVENT as nC,isDevEnv as JH,KEYS as QH,updateObject as eG}from"@orangecatai/common";import zH from"clsx";import{useContext as OH}from"react";import FH from"react";var Zp=FH.createContext({});import{jsx as Z0,jsxs as Q5}from"react/jsx-runtime";var j0=({children:e,className:t})=>{let o=ye(),n=OH(Zp),r=!!(o.canFitSidebar&&n.shouldRenderDockButton);return Q5("div",{className:zH("sidebar__header",t),"data-testid":"sidebar-header",children:[e,Q5("div",{className:"sidebar__header__buttons",children:[r&&Z0(ro,{label:h("labels.sidebarLock"),children:Z0(Jt,{onSelect:()=>n.onDock?.(!n.docked),selected:!!n.docked,className:"sidebar__dock","data-testid":"sidebar-dock","aria-label":h("labels.sidebarLock"),children:Qx})}),Z0(Jt,{"data-testid":"sidebar-close",className:"sidebar__close",onSelect:n.onCloseRequest,"aria-label":h("buttons.close"),children:To})]})]})};j0.displayName="SidebarHeader";import{Tabs as HH}from"radix-ui";import{jsx as eC}from"react/jsx-runtime";var q0=({children:e,tab:t,onSelect:o,...n})=>eC(HH.Trigger,{value:t,asChild:!0,onSelect:o,children:eC("button",{type:"button",className:"excalidraw-button sidebar-tab-trigger",...n,children:e})});q0.displayName="SidebarTabTrigger";import{Tabs as GH}from"radix-ui";import{jsx as UH}from"react/jsx-runtime";var J0=({children:e,...t})=>UH(GH.List,{className:"sidebar-triggers",...t,children:e});J0.displayName="SidebarTabTriggers";import WH from"clsx";import{jsx as Q0,jsxs as tC}from"react/jsx-runtime";var eb=({name:e,tab:t,icon:o,title:n,children:r,onToggle:i,className:a,style:s})=>{let l=ve(),c=Ee();return tC("label",{title:n,className:"sidebar-trigger__label-element",children:[Q0("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}),i?.(p)},checked:c.openSidebar?.name===e,"aria-label":n,"aria-keyshortcuts":"0"}),tC("div",{className:WH("sidebar-trigger",a),style:s,children:[o&&Q0("div",{children:o}),r&&Q0("div",{className:"sidebar-trigger__label",children:r})]})]})};eb.displayName="SidebarTrigger";import{Tabs as YH}from"radix-ui";import{jsx as VH}from"react/jsx-runtime";var tb=({children:e,...t})=>{let o=Ee(),n=ve();if(!o.openSidebar)return null;let{name:r}=o.openSidebar;return VH(YH.Root,{className:"sidebar-tabs-root",value:o.openSidebar.tab,onValueChange:i=>n(a=>({...a,openSidebar:{...a.openSidebar,name:r,tab:i}})),...t,children:e})};tb.displayName="SidebarTabs";import{Tabs as KH}from"radix-ui";import{jsx as XH}from"react/jsx-runtime";var ob=({tab:e,children:t,...o})=>XH(KH.Content,{...o,value:e,"data-testid":e,children:t});ob.displayName="SidebarTab";import{jsx as rC}from"react/jsx-runtime";import{createElement as tG}from"react";var kc=Ie(!1),lC=sC(({name:e,children:t,onDock:o,docked:n,className:r,...i},a)=>{JH()&&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=ve(),l=mn(kc);aC(()=>(l(!!n),()=>{l(!1)}),[l,n]);let c=nb({});c.current.onCloseRequest=()=>{s({openSidebar:null})},c.current.onDock=u=>o?.(u),c.current=eG(c.current,{docked:n,shouldRenderDockButton:!!o&&n!=null});let m=nb(null);jH(a,()=>m.current);let p=ye(),d=oC(()=>{document.querySelector(".Dialog")||s({openSidebar:null})},[s]);return Ra(m,oC(u=>{u.target.closest(".sidebar-trigger")||(!n||!p.canFitSidebar)&&d()},[d,n,p.canFitSidebar])),iC(()=>{let u=b=>{b.key===QH.ESCAPE&&(!n||!p.canFitSidebar)&&d()};return document.addEventListener(nC.KEYDOWN,u),()=>{document.removeEventListener(nC.KEYDOWN,u)}},[d,n,p.canFitSidebar]),rC(st,{...i,className:$H(qH.SIDEBAR,{"sidebar--docked":n},r),ref:m,children:rC(Zp.Provider,{value:c.current,children:t})})});lC.displayName="SidebarInner";var Ro=Object.assign(sC((e,t)=>{let o=Ee()??{openSidebar:null},{onStateChange:n}=e,r=nb(o.openSidebar);iC(()=>{(!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[i,a]=ZH(!1);return aC(()=>(a(!0),()=>a(!1)),[]),i&&o.openSidebar?.name===e.name?tG(lC,{...e,ref:t,key:e.name}):null}),{Header:j0,TabTriggers:J0,TabTrigger:q0,Tabs:tb,Tab:ob,Trigger:eb});Ro.displayName="Sidebar";import{composeEventHandlers as cG}from"@orangecatai/common";import{useLayoutEffect as oG,useRef as nG}from"react";import{jsx as rG}from"react/jsx-runtime";var sr=(e,t)=>{let o=Ie(0),n=r=>{let{tunnelsJotai:{useAtom:i}}=We(),[,a]=i(o),s=nG({preferHost:!1,counter:0});return oG(()=>{let l=s.current;return a(c=>{let m=c+1;return l.counter=m,m}),()=>{a(c=>{let m=c-1;return l.counter=m,m||(l.preferHost=!1),m})}},[a]),r.__fallback||(s.current.preferHost=!0),!s.current.counter&&r.__fallback&&s.current.preferHost||s.current.counter>1&&r.__fallback?null:rG(t,{...r})};return n.displayName=e,n};var lb={};vx(lb,{ChangeCanvasBackground:()=>vC,ClearCanvas:()=>yC,CommandPalette:()=>bC,Export:()=>TC,Help:()=>EC,LiveCollaborationTrigger:()=>CC,LoadScene:()=>gC,Preferences:()=>Xr,PreferencesToggleGridModeItem:()=>ab,PreferencesToggleZenModeItem:()=>sb,SaveAsImage:()=>fC,SaveToActiveFile:()=>hC,SearchMenu:()=>xC,Socials:()=>IC,ToggleTheme:()=>wC});import lG from"clsx";import{THEME as Kr}from"@orangecatai/common";var rb=Ie({active:!1});async function cC({title:e,description:t,actionLabel:o,color:n}){return new Promise(r=>{pt.set(rb,{active:!0,onConfirm:()=>r(!0),onClose:()=>r(!1),onReject:()=>r(!1),title:e,description:t,actionLabel:o,color:n})})}import iG from"clsx";import{jsx as dC,jsxs as aG}from"react/jsx-runtime";var jp=function({onChange:e,value:t,choices:o,name:n}){return dC("div",{className:"RadioGroup",children:o.map(r=>aG("div",{className:iG("RadioGroup__choice",{active:r.value===t}),title:r.ariaLabel,children:[dC("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 sG,jsx as ib,jsxs as mC}from"react/jsx-runtime";var pC=({value:e,shortcut:t,onChange:o,choices:n,children:r,name:i})=>{let a=ye();return mC(sG,{children:[mC("div",{className:"dropdown-menu-item-base dropdown-menu-item-bare",children:[ib("label",{className:"dropdown-menu-item__text",children:r}),ib(jp,{name:i,value:e,onChange:o,choices:n})]}),t&&a.formFactor!=="phone"&&ib("div",{className:"dropdown-menu-item__shortcut dropdown-menu-item__shortcut--orphaned",children:t})]})};pC.displayName="DropdownMenuItemContentRadio";var uC=pC;import{Fragment as AC,jsx as Re,jsxs as Sc}from"react/jsx-runtime";var gC=()=>{let{t:e}=Oe(),t=qe(),o=Tr();return t.isActionEnabled(ja)?Re(Kt,{icon:va,onSelect:async()=>{(!o.length||await cC({title:e("overwriteConfirm.modal.loadFromFile.title"),actionLabel:e("overwriteConfirm.modal.loadFromFile.button"),color:"warning",description:Re(qt,{i18nKey:"overwriteConfirm.modal.loadFromFile.description",bold:r=>Re("strong",{children:r}),br:()=>Re("br",{})})}))&&t.executeAction(ja)},"data-testid":"load-button",shortcut:Ue("loadScene"),"aria-label":e("buttons.load"),children:e("buttons.load")}):null};gC.displayName="LoadScene";var hC=()=>{let{t:e}=Oe(),t=qe();return t.isActionEnabled(Pi)?Re(Kt,{shortcut:Ue("saveScene"),"data-testid":"save-button",onSelect:()=>t.executeAction(Pi),icon:mE,"aria-label":`${e("buttons.save")}`,children:`${e("buttons.save")}`}):null};hC.displayName="SaveToActiveFile";var fC=()=>{let e=ve(),{t}=Oe();return Re(Kt,{icon:Td,"data-testid":"image-export-button",onSelect:()=>e({openDialog:{name:"imageExport"}}),shortcut:Ue("imageExport"),"aria-label":t("buttons.exportImage"),children:t("buttons.exportImage")})};fC.displayName="SaveAsImage";var bC=e=>{let t=ve(),{t:o}=Oe();return Re(Kt,{icon:wl,"data-testid":"command-palette-button",onSelect:()=>{he("command_palette","open","menu"),t({openDialog:{name:"commandPalette"}})},shortcut:Ue("commandPalette"),"aria-label":o("commandPalette.title"),className:e?.className,children:o("commandPalette.title")})};bC.displayName="CommandPalette";var xC=e=>{let{t}=Oe(),o=qe();return Re(Kt,{icon:ho,"data-testid":"search-menu-button",onSelect:()=>{o.executeAction(cc)},shortcut:Ue("searchMenu"),"aria-label":t("search.title"),className:e?.className,children:t("search.title")})};xC.displayName="SearchMenu";var EC=()=>{let{t:e}=Oe(),t=qe();return Re(Kt,{"data-testid":"help-menu-item",icon:wa,onSelect:()=>t.executeAction(Ai),shortcut:"?","aria-label":e("helpDialog.title"),children:e("helpDialog.title")})};EC.displayName="Help";var yC=()=>{let{t:e}=Oe(),t=mn(Ni);return qe().isActionEnabled(Zn)?Re(Kt,{icon:Nt,onSelect:()=>t("clearCanvas"),"data-testid":"clear-canvas-button","aria-label":e("buttons.clearReset"),children:e("buttons.clearReset")}):null};yC.displayName="ClearCanvas";var wC=e=>{let{t}=Oe(),o=Ee(),n=qe(),r=Ue("toggleTheme");return n.isActionEnabled(Ci)?e?.allowSystemTheme?Re(uC,{name:"theme",value:e.theme,onChange:i=>e.onSelect(i),choices:[{value:Kr.LIGHT,label:bl,ariaLabel:`${t("buttons.lightMode")} - ${r}`},{value:Kr.DARK,label:fl,ariaLabel:`${t("buttons.darkMode")} - ${r}`},{value:"system",label:My,ariaLabel:t("buttons.systemMode")}],children:t("labels.theme")}):Re(Kt,{onSelect:i=>{if(i.preventDefault(),e?.onSelect)e.onSelect(o.theme===Kr.DARK?Kr.LIGHT:Kr.DARK);else return n.executeAction(Ci)},icon:o.theme===Kr.DARK?bl:fl,"data-testid":"toggle-dark-mode",shortcut:r,"aria-label":o.theme===Kr.DARK?t("buttons.lightMode"):t("buttons.darkMode"),children:o.theme===Kr.DARK?t("buttons.lightMode"):t("buttons.darkMode")}):null};wC.displayName="ToggleTheme";var vC=()=>{let{t:e}=Oe(),t=Ee(),o=qe(),n=bn();return t.viewModeEnabled||!n.UIOptions.canvasActions.changeViewBackgroundColor?null:Sc("div",{style:{marginTop:"0.75rem"},children:[Re("div",{"data-testid":"canvas-background-label",style:{fontSize:"0.875rem",marginBottom:"0.25rem",marginLeft:"0.5rem"},children:e("labels.canvasBackground")}),Re("div",{style:{padding:"0 0.625rem"},children:o.renderAction("changeViewBackgroundColor")})]})};vC.displayName="ChangeCanvasBackground";var TC=()=>{let{t:e}=Oe(),t=ve();return Re(Kt,{icon:Ei,onSelect:()=>{t({openDialog:{name:"jsonExport"}})},"data-testid":"json-export-button","aria-label":e("buttons.export"),children:e("buttons.export")})};TC.displayName="Export";var IC=()=>{let{t:e}=Oe();return Sc(AC,{children:[Re(hs,{icon:yd,href:"https://github.com/excalidraw/excalidraw","aria-label":"GitHub",children:"GitHub"}),Re(hs,{icon:dE,href:"https://x.com/excalidraw","aria-label":"X",children:e("labels.followUs")}),Re(hs,{icon:cE,href:"https://discord.gg/UexuTaE","aria-label":"Discord",children:e("labels.discordChat")})]})};IC.displayName="Socials";var CC=({onSelect:e,isCollaborating:t})=>{let{t:o}=Oe();return Re(Kt,{"data-testid":"collab-button",icon:Id,className:lG({"active-collab":t}),onSelect:e,children:o("labels.liveCollaboration")})};CC.displayName="LiveCollaborationTrigger";var kC=()=>{let{t:e}=Oe(),t=Xe(),o=Ee();return Re(Qn,{checked:o.activeTool.locked,shortcut:Ue("toolLock"),onSelect:n=>{t.toggleLock(),n.preventDefault()},children:e("labels.preferences_toolLock")})},SC=()=>{let{t:e}=Oe(),t=qe(),o=Ee();return Re(Qn,{checked:o.objectsSnapModeEnabled,shortcut:Ue("objectsSnapMode"),onSelect:n=>{t.executeAction(Kl),n.preventDefault()},children:e("buttons.objectsSnapMode")})},ab=()=>{let{t:e}=Oe(),t=qe(),o=Ee();return Re(Qn,{checked:o.gridModeEnabled,shortcut:Ue("gridMode"),onSelect:n=>{t.executeAction(ns),n.preventDefault()},children:e("labels.toggleGrid")})},sb=()=>{let{t:e}=Oe(),t=qe(),o=Ee();return Re(Qn,{checked:o.zenModeEnabled,shortcut:Ue("zenMode"),onSelect:n=>{t.executeAction(Dr),n.preventDefault()},children:e("buttons.zenMode")})},MC=()=>{let{t:e}=Oe(),t=qe(),o=Ee();return Re(Qn,{checked:o.viewModeEnabled,shortcut:Ue("viewMode"),onSelect:n=>{t.executeAction(Ri),n.preventDefault()},children:e("labels.viewMode")})},PC=()=>{let{t:e}=Oe(),t=qe(),o=Ee();return Re(Qn,{checked:o.stats.open,shortcut:Ue("stats"),onSelect:n=>{t.executeAction(Rr),n.preventDefault()},children:e("stats.fullTitle")})},Xr=({children:e,additionalItems:t})=>{let{t:o}=Oe();return Sc(Fr,{children:[Re(Fr.Trigger,{icon:Hy,children:o("labels.preferences")}),Sc(Fr.Content,{className:"excalidraw-main-menu-preferences-submenu",children:[e||Sc(AC,{children:[Re(kC,{}),Re(SC,{}),Re(ab,{}),Re(sb,{}),Re(MC,{}),Re(PC,{})]}),t]})]})};Xr.ToggleToolLock=kC;Xr.ToggleSnapMode=SC;Xr.ToggleGridMode=ab;Xr.ToggleZenMode=sb;Xr.ToggleViewMode=MC;Xr.ToggleElementProperties=PC;Xr.displayName="Preferences";import{jsx as qp,jsxs as cb}from"react/jsx-runtime";var dG=Object.assign(sr("MainMenu",({children:e,onSelect:t})=>{let{MainMenuTunnel:o}=We(),n=ye(),r=Ee(),i=ve();return qp(o.In,{children:cb(pe,{open:r.openMenu==="canvas",children:[qp(pe.Trigger,{onToggle:()=>{i({openMenu:r.openMenu==="canvas"?null:"canvas",openPopup:null,openDialog:null})},"data-testid":"main-menu-trigger",className:"main-menu-trigger",children:sE}),cb(pe.Content,{onClickOutside:()=>i({openMenu:null}),onSelect:cG(t,()=>{i({openMenu:null})}),className:"main-menu",align:"start",children:[e,n.formFactor==="phone"&&r.collaborators.size>0&&cb("fieldset",{className:"UserList-Wrapper",children:[qp("legend",{children:h("labels.collaborators")}),qp(Xp,{mobile:!0,collaborators:r.collaborators,userToFollow:r.userToFollow?.socketId||null})]})]})]})})}),{Trigger:pe.Trigger,Item:pe.Item,ItemLink:pe.ItemLink,ItemCustom:pe.ItemCustom,Group:pe.Group,Separator:pe.Separator,Sub:Fr,DefaultItems:lb}),Ut=dG;import mG from"clsx";import{forwardRef as pG,useState as uG}from"react";import{isPromiseLike as gG}from"@orangecatai/common";import{jsx as Jp,jsxs as hG}from"react/jsx-runtime";var No=pG(({children:e,icon:t,onClick:o,label:n,variant:r="filled",color:i="primary",size:a="medium",fullWidth:s,className:l,status:c,disabled:m},p)=>{let[d,u]=uG(!1),b=async E=>{let y=o?.(E);if(gG(y)){let x=window.setTimeout(()=>{u(!0)},50);try{await y}catch(w){if(w instanceof sa)console.warn(w);else throw w}finally{clearTimeout(x),u(!1)}}},g=d?"loading":c;return i=g==="success"?"success":i,Jp("button",{className:mG("ExcButton",`ExcButton--color-${i}`,`ExcButton--variant-${r}`,`ExcButton--size-${a}`,`ExcButton--status-${g}`,{"ExcButton--fullWidth":s},l),onClick:b,type:"button","aria-label":n,ref:p,disabled:m||g==="loading"||g==="success",children:hG("div",{className:"ExcButton__contents",children:[g==="loading"?Jp(Bt,{className:"ExcButton__statusIcon"}):g==="success"&&Jp("div",{className:"ExcButton__statusIcon",children:ly}),t&&Jp("div",{className:"ExcButton__icon","aria-hidden":!0,children:t}),r!=="icon"&&(e??n)]})})});import{jsx as Ds,jsxs as xG}from"react/jsx-runtime";var Qp=({title:e,children:t,actionLabel:o,onClick:n})=>xG("div",{className:"OverwriteConfirm__Actions__Action",children:[Ds("h4",{children:e}),Ds("div",{className:"OverwriteConfirm__Actions__Action__content",children:t}),Ds(No,{variant:"outlined",color:"muted",label:o,size:"large",fullWidth:!0,onClick:n})]}),fG=()=>{let{t:e}=Oe(),t=qe(),o=ve();return Ds(Qp,{title:e("overwriteConfirm.action.exportToImage.title"),actionLabel:e("overwriteConfirm.action.exportToImage.button"),onClick:()=>{t.executeAction(um,"ui",!0),o({openDialog:{name:"imageExport"}})},children:e("overwriteConfirm.action.exportToImage.description")})},bG=()=>{let{t:e}=Oe(),t=qe();return Ds(Qp,{title:e("overwriteConfirm.action.saveToDisk.title"),actionLabel:e("overwriteConfirm.action.saveToDisk.button"),onClick:()=>{t.executeAction(Yl,"ui")},children:e("overwriteConfirm.action.saveToDisk.description")})},db=Object.assign(({children:e})=>Ds("div",{className:"OverwriteConfirm__Actions",children:e}),{ExportToImage:fG,SaveToDisk:bG});import{jsx as $r,jsxs as LC}from"react/jsx-runtime";var eu=Object.assign(sr("OverwriteConfirmDialog",({children:e})=>{let{OverwriteConfirmDialogTunnel:t}=We(),[o,n]=ne(rb);if(!o.active)return null;let r=()=>{o.onClose(),n(a=>({...a,active:!1}))},i=()=>{o.onConfirm(),n(a=>({...a,active:!1}))};return $r(t.In,{children:$r(dt,{onCloseRequest:r,title:!1,size:916,children:LC("div",{className:"OverwriteConfirm",children:[$r("h3",{children:o.title}),LC("div",{className:`OverwriteConfirm__Description OverwriteConfirm__Description--color-${o.color}`,children:[$r("div",{className:"OverwriteConfirm__Description__icon",children:Sd}),$r("div",{children:o.description}),$r("div",{className:"OverwriteConfirm__Description__spacer"}),$r(No,{color:o.color,size:"large",label:o.actionLabel,onClick:i})]}),$r(db,{children:e})]})})})}),{Actions:db,Action:Qp});import HG from"clsx";import{CANVAS_SEARCH_TAB as hb,DEFAULT_SIDEBAR as GG,LIBRARY_SIDEBAR_TAB as GC,composeEventHandlers as UG}from"@orangecatai/common";import{round as EG}from"@orangecatai/math";import yG from"clsx";import wG from"lodash.debounce";import{Fragment as vG,memo as TG,useEffect as Mc,useMemo as _C,useRef as mb,useState as DC}from"react";import{CLASSES as IG,EVENT as CG,FONT_FAMILY as pb,FRAME_STYLE as ub,getLineHeight as kG}from"@orangecatai/common";import{isElementCompletelyInViewport as SG}from"@orangecatai/element";import{measureText as Pc}from"@orangecatai/element";import{KEYS as Rs,randomInteger as RC,addEventListener as MG,getFontString as tu}from"@orangecatai/common";import{newTextElement as PG}from"@orangecatai/element";import{isTextElement as zC,isFrameLikeElement as ou}from"@orangecatai/element";import{getDefaultFrameName as OC}from"@orangecatai/element/frame";import{Fragment as OG,jsx as At,jsxs as An}from"react/jsx-runtime";var AG=Ie(""),gb=Ie(null),LG=350,HC=()=>{let e=Xe(),t=ve(),o=mb(null),[n,r]=ne(AG),i=n.trim(),[a,s]=DC(!1),[l,c]=DC({nonce:null,items:[]}),m=mb(null),p=mb(void 0),[d,u]=ne(gb),b=e.scene.getNonDeletedElementsMap();Mc(()=>{a||(i!==m.current||e.scene.getSceneNonce()!==p.current)&&(m.current=null,FC(i,e,(w,v)=>{c({nonce:RC(),items:w}),m.current=i,p.current=e.scene.getSceneNonce(),t({searchMatches:w.length?{focusedId:null,matches:w.map(T=>({id:T.element.id,focus:!1,matchedLines:T.matchedLines}))}:null})}))},[a,i,b,e,t,u,p]);let g=()=>{l.items.length>0&&u(w=>w===null?0:(w+1)%l.items.length)},E=()=>{l.items.length>0&&u(w=>w===null?0:w-1<0?l.items.length-1:w-1)};Mc(()=>{t(w=>w.searchMatches?{searchMatches:{focusedId:d!==null&&w.searchMatches?.matches[d]?.id||null,matches:w.searchMatches.matches.map((T,C)=>C===d?{...T,focus:!0}:{...T,focus:!1})}}:null)},[d,t]),Mc(()=>{if(l.items.length>0&&d!==null){let w=l.items[d];if(w){let v=e.state.zoom.value,T=PG({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:ou(w.element)?ub.nameFontSize:w.element.fontSize,fontFamily:ou(w.element)?pb.Assistant:w.element.fontFamily}),C=14,M=T.fontSize,k=M*v<C;if(!SG([T],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())||k){let R;k?M>=C?R={fitToContent:!0}:R={fitToViewport:!0,maxZoom:EG(C/M,1)}:R={fitToContent:!0},e.scrollToContent(T,{animate:!0,duration:300,...R,canvasOffsets:e.getEditorUIOffsets()})}}}},[d,l,e]),Mc(()=>()=>{u(null),m.current=null,p.current=void 0,t({searchMatches:null}),s(!1)},[t,u]);let y=yr({goToNextItem:g,goToPreviousItem:E,searchMatches:l});Mc(()=>{let w=v=>{if(v.key===Rs.ESCAPE&&!e.state.openDialog&&!e.state.openPopup){v.preventDefault(),v.stopPropagation(),t({openSidebar:null});return}if(v[Rs.CTRL_OR_CMD]&&v.key===Rs.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")&&y.searchMatches.items.length&&(v.key===Rs.ENTER&&(v.stopPropagation(),y.goToNextItem()),v.key===Rs.ARROW_UP?(v.stopPropagation(),y.goToPreviousItem()):v.key===Rs.ARROW_DOWN&&(v.stopPropagation(),y.goToNextItem()))};return MG(window,CG.KEYDOWN,w,{capture:!0,passive:!1})},[t,y,e]);let x=`${l.items.length} ${l.items.length===1?h("search.singleResult"):h("search.multipleResults")}`;return An("div",{className:"layer-ui__search",children:[At("div",{className:"layer-ui__search-header",children:At(zr,{className:IG.SEARCH_MENU_INPUT_WRAPPER,value:n,ref:o,placeholder:h("search.placeholder"),icon:ho,onChange:w=>{r(w),s(!0);let v=w.trim();FC(v,e,(T,C)=>{c({nonce:RC(),items:T}),u(C),m.current=v,p.current=e.scene.getSceneNonce(),t({searchMatches:T.length?{focusedId:null,matches:T.map(M=>({id:M.element.id,focus:!1,matchedLines:M.matchedLines}))}:null}),s(!1)})},selectOnRender:!0})}),An("div",{className:"layer-ui__search-count",children:[l.items.length>0&&An(OG,{children:[d!==null&&d>-1?An("div",{children:[d+1," / ",x]}):At("div",{children:x}),An("div",{className:"result-nav",children:[At(Jt,{onSelect:()=>{g()},className:"result-nav-btn",children:Md}),At(Jt,{onSelect:()=>{E()},className:"result-nav-btn",children:Dy})]})]}),l.items.length===0&&i&&m.current&&At("div",{style:{margin:"1rem auto"},children:h("search.noMatch")})]}),At(RG,{matches:l,onItemClick:u,focusIndex:d,searchQuery:i})]})},NC=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 At("div",{tabIndex:-1,className:yG("layer-ui__result-item",{active:e.highlighted}),onClick:e.onClick,ref:o=>{e.highlighted&&o?.scrollIntoView({behavior:"auto",block:"nearest"})},children:At("div",{className:"preview-text",children:t.flatMap((o,n)=>At(vG,{children:n===2?At("b",{children:o}):o},n))})})},_G=e=>{let t=_C(()=>e.matches.items.filter(n=>ou(n.element)),[e.matches]),o=_C(()=>e.matches.items.filter(n=>zC(n.element)),[e.matches]);return An("div",{children:[t.length>0&&An("div",{className:"layer-ui__search-result-container",children:[An("div",{className:"layer-ui__search-result-title",children:[At("div",{className:"title-icon",children:Vo}),At("div",{children:h("search.frames")})]}),t.map((n,r)=>At(NC,{searchQuery:e.searchQuery,preview:n.preview,highlighted:r===e.focusIndex,onClick:()=>e.onItemClick(r)},n.element.id+n.index)),o.length>0&&At("div",{className:"layer-ui__divider"})]}),o.length>0&&An("div",{className:"layer-ui__search-result-container",children:[An("div",{className:"layer-ui__search-result-title",children:[At("div",{className:"title-icon",children:gn}),At("div",{children:h("search.texts")})]}),o.map((n,r)=>At(NC,{searchQuery:e.searchQuery,preview:n.preview,highlighted:r+t.length===e.focusIndex,onClick:()=>e.onItemClick(r+t.length)},n.element.id+n.index))]})]})},DG=(e,t)=>e.matches.nonce===t.matches.nonce&&e.focusIndex===t.focusIndex,RG=TG(_G,DG),BC=(e,t,o)=>{let i=e.slice(0,t),a=i.split(/\s+/),s=i.endsWith(" "),l=a.length-2-1-(s?0:1),c=a.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(" "),b=u?6:5,g=(u?"":" ")+d.slice(0,b).join(" ");return{indexInSearchQuery:c.length,previewText:c+o+g,moreBefore:l>0,moreAfter:d.length>b}},NG=(e,t)=>{let o=e.split(`
|
|
16
|
+
`),n=[],r=0;for(let i=0;i<o.length;i++){let a=o[i],s=o[i+1];if(s){let l=t.indexOf(s,r);if(l>a.length+r){let c=l-(a.length+r);for(;c>0;)a+=" ",c--}}n.push(a),r=r+a.length}return n.join(`
|
|
17
|
+
`)},BG=(e,t,o)=>{let r=NG(e.text,e.originalText).split(`
|
|
18
|
+
`),i=[],a=0,s=0;for(let p of r){let d=a,u=d+p.length-1;i.push({line:p,startIndex:d,endIndex:u,lineNumber:s}),a=u+1,s++}let l=o,c=e.originalText.slice(o,o+t.length),m=[];for(let p of i){if(c==="")break;if(l>=p.startIndex&&l<=p.endIndex){let d=p.endIndex+1-l,u=p.line.slice(0,l-p.startIndex),b=c.slice(0,d);c=c.slice(d);let g=Pc(u,tu(e),e.lineHeight);if(u===""&&(g.width=0),e.textAlign!=="left"&&p.line.length>0){let v=Pc(p.line,tu(e),e.lineHeight),T=e.textAlign==="center"?(e.width-v.width)/2:e.width-v.width;g.width+=T}let{width:E,height:y}=Pc(b,tu(e),e.lineHeight),x=g.width,w=p.lineNumber*g.height;m.push({offsetX:x,offsetY:w,width:E,height:y,showOnCanvas:!0}),l+=d}}return m},FG=(e,t,o,n)=>{let r=e.name??OC(e),i=r.slice(o,o+t.length),a=r.slice(0,o),s=tu({fontSize:ub.nameFontSize,fontFamily:pb.Assistant}),l=kG(pb.Assistant),c=Pc(a,s,l);a===""&&(c.width=0);let m=Pc(i,s,l),p=c.width,d=-c.height-ub.strokeWidth,u=m.width;return[{offsetX:p,offsetY:d,width:u,height:m.height,showOnCanvas:p+u<=e.width*n}]},zG=e=>e.replace(/[.*+?^${}()|[\]\\-]/g,"\\$&"),FC=wG((e,t,o)=>{if(!e||e===""){o([],null);return}let n=t.scene.getNonDeletedElements(),r=n.filter(d=>zC(d)),i=n.filter(d=>ou(d));r.sort((d,u)=>d.y-u.y),i.sort((d,u)=>d.y-u.y);let a=[],s=new RegExp(zG(e),"gi");for(let d of r){let u=null,b=d.originalText;for(;(u=s.exec(b))!==null;){let g=BC(b,u.index,e),E=BG(d,e,u.index);E.length>0&&a.push({element:d,searchQuery:e,preview:g,index:u.index,matchedLines:E})}}let l=[];for(let d of i){let u=null,b=d.name??OC(d);for(;(u=s.exec(b))!==null;){let g=BC(b,u.index,e),E=FG(d,e,u.index,t.state.zoom.value);E.length>0&&l.push({element:d,searchQuery:e,preview:g,index:u.index,matchedLines:E})}}let c=new Set(t.visibleElements.map(d=>d.id)),m=[...l,...a],p=m.findIndex(d=>c.has(d.element.id))??null;o(m,p)},LG);import{jsx as on,jsxs as UC}from"react/jsx-runtime";import{createElement as WG}from"react";var WC=sr("DefaultSidebarTrigger",e=>{let{DefaultSidebarTriggerTunnel:t}=We();return on(t.In,{children:on(Ro.Trigger,{...e,className:"default-sidebar-trigger",name:GG.name})})});WC.displayName="DefaultSidebarTrigger";var YC=({children:e})=>{let{DefaultSidebarTabTriggersTunnel:t}=We();return on(t.In,{children:e})};YC.displayName="DefaultTabTriggers";var nu=Object.assign(sr("DefaultSidebar",({children:e,className:t,onDock:o,docked:n,...r})=>{let i=Ee(),a=ve(),{DefaultSidebarTabTriggersTunnel:s}=We(),l=i.openSidebar?.tab===hb;return WG(Ro,{...r,name:"default",key:"default",className:HG("default-sidebar",t),docked:l||(n??i.defaultSidebarDockedPreference),onDock:l||o===!1||!o&&n!=null?void 0:UG(o,c=>{a({defaultSidebarDockedPreference:c})})},UC(Ro.Tabs,{children:[on(Ro.Header,{children:UC(Ro.TabTriggers,{children:[on(Ro.TabTrigger,{tab:hb,children:ho}),on(Ro.TabTrigger,{tab:GC,children:bd}),on(s.Out,{})]})}),on(Ro.Tab,{tab:GC,children:on(oI,{})}),on(Ro.Tab,{tab:hb,children:on(HC,{})}),e]}))}),{Trigger:WC,TabTriggers:YC});import{useEffect as HU,useState as GU}from"react";import{useState as tk,useRef as ok,useEffect as nk,useDeferredValue as JG}from"react";import{EDITOR_LS_KEYS as QG,debounce as eU,isDevEnv as tU}from"@orangecatai/common";import{useEffect as YG,useRef as VC}from"react";import{EVENT as KC,KEYS as XC}from"@orangecatai/common";import{jsx as VG}from"react/jsx-runtime";var $C=({input:e,placeholder:t,onChange:o,onKeyboardSubmit:n})=>{let r=VC(null),i=VC(n);return i.current=n,YG(()=>{if(!i.current)return;let a=r.current;if(a){let s=l=>{l[XC.CTRL_OR_CMD]&&l.key===XC.ENTER&&(l.preventDefault(),i.current?.())};return a.focus(),a.addEventListener(KC.KEYDOWN,s),()=>{a.removeEventListener(KC.KEYDOWN,s)}}},[]),VG("textarea",{className:"ttd-dialog-input",onChange:o,value:e,placeholder:t,ref:r})};import KG from"clsx";import{jsx as Xi,jsxs as ZC}from"react/jsx-runtime";var ru=({error:e,canvasRef:t,loaded:o,hideErrorDetails:n})=>ZC("div",{className:`ttd-dialog-output-wrapper ${e?"ttd-dialog-output-wrapper--error":""}`,children:[e&&Xi("div",{"data-testid":"ttd-dialog-output-error",className:"ttd-dialog-output-error",children:ZC("div",{className:"ttd-dialog-output-error-content",children:[Xi("div",{className:"ttd-dialog-output-error-icon",children:Sd}),Xi("div",{className:"ttd-dialog-output-error-title",children:h("ttd.error")}),Xi("div",{className:"ttd-dialog-output-error-message",children:n?h("chat.errors.mermaidParseError"):e.message})]})},"error"),o?Xi("div",{className:KG("ttd-dialog-output-canvas-container",{invisible:!!e}),children:Xi("div",{ref:t,className:"ttd-dialog-output-canvas-content"})},"canvas"):Xi(Bt,{size:"2rem"})]});import Ns from"clsx";import{Fragment as XG}from"react";import{jsx as Bs,jsxs as Fs}from"react/jsx-runtime";var $i=({label:e,children:t,panelActions:o=[],onTextSubmitInProgess:n,renderTopRight:r,renderSubmitShortcut:i,className:a,panelActionJustifyContent:s="flex-start"})=>{let l=c=>{if(c?.variant==="link")return Fs("button",{className:Ns("ttd-dialog-panel-action-link",c.className),onClick:c.action,disabled:c?.disabled||n,type:"button",children:[c.label,c.icon&&Bs("span",{className:"ttd-dialog-panel-action-link__icon",children:c.icon})]});if(c?.variant==="button")return Fs(Jt,{className:Ns("ttd-dialog-panel-button",c.className),onSelect:c.action?c.action:()=>{},disabled:c?.disabled||n,children:[Fs("div",{className:Ns({invisible:n}),children:[c?.label,c?.icon&&Bs("span",{children:c.icon})]}),n&&Bs(Bt,{})]});if(c?.variant==="rateLimit")return Bs("div",{className:Ns("ttd-dialog-panel__rate-limit",c.className),children:c.label})};return Fs("div",{className:Ns("ttd-dialog-panel",a),children:[(e||r)&&Fs("div",{className:"ttd-dialog-panel__header",children:[typeof e=="string"?Bs("label",{children:e}):e,r?.()]}),t,Fs("div",{className:Ns("ttd-dialog-panel-button-container",{invisible:!o.length}),style:{justifyContent:s},children:[o.filter(Boolean).map(c=>Bs(XG,{children:l(c)},c.label)),!n&&i?.()]})]})};import{jsx as $G}from"react/jsx-runtime";var jC=({children:e})=>$G("div",{className:"ttd-dialog-panels",children:e});import{jsx as qC,jsxs as ZG}from"react/jsx-runtime";var JC=()=>ZG("div",{className:"ttd-dialog-submit-shortcut",children:[qC("div",{className:"ttd-dialog-submit-shortcut__key",children:N("CtrlOrCmd")}),qC("div",{className:"ttd-dialog-submit-shortcut__key",children:N("Enter")})]});import{DEFAULT_EXPORT_PADDING as jG,EDITOR_LS_KEYS as qG}from"@orangecatai/common";var fb=({canvasRef:e,setError:t})=>{let o=e.current;if(!o)return;let n=o.parentElement;n&&(n.style.background="",t(null),o.replaceChildren())},zs=async({canvasRef:e,mermaidToExcalidrawLib:t,mermaidDefinition:o,setError:n,data:r,theme:i})=>{let a=e.current,s=a?.parentElement;if(!a||!s)return{success:!1};if(!o)return fb({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:ek(m,{regenerateIds:!0}),files:p};let d=await Nr({elements:r.current.elements,files:r.current.files,exportPadding:jG,maxWidthOrHeight:Math.max(s.offsetWidth,s.offsetHeight)*window.devicePixelRatio,appState:{exportWithDarkMode:i===QC.DARK}});return s.style.background="var(--default-bg-color)",a.replaceChildren(d),{success:!0}}catch(c){return s.style.background="var(--default-bg-color)",o&&n(c),{success:!1,error:c}}},Os=e=>{Po.set(qG.MERMAID_TO_EXCALIDRAW,e)},Ac=({app:e,data:t,text:o,shouldSaveMermaidDataToStorage:n})=>{let{elements:r,files:i}=t.current;r.length&&(e.addElementsFromPasteOrLibrary({elements:r,files:i,position:"center",fitToContent:!0}),e.setOpenDialog(null),n&&o&&Os(o))};import{Fragment as rU,jsx as Ln,jsxs as ik}from"react/jsx-runtime";var oU=`flowchart TD
|
|
19
19
|
A[Christmas] -->|Get money| B(Go shopping)
|
|
20
20
|
B --> C{Let me think}
|
|
21
21
|
C -->|One| D[Laptop]
|
|
22
22
|
C -->|Two| E[iPhone]
|
|
23
|
-
C -->|Three| F[Car]`,nC=aH(rs,300),cH=({mermaidToExcalidrawLib:e,isActive:o})=>{let[t,n]=eC(()=>po.get(iH.MERMAID_TO_EXCALIDRAW)||lH),r=rH(t.trim()),[i,a]=eC(null),s=tC(null),l=tC({elements:[],files:null}),c=ze(),{theme:m}=he();oC(()=>{o&&((async()=>{try{if(!r){D1({canvasRef:s,setError:a});return}let u=await ns({canvasRef:s,data:l,mermaidToExcalidrawLib:e,setError:a,mermaidDefinition:r,theme:m});if(!u.success){let b=u.error??new Error("Invalid mermaid definition");a(b)}}catch(u){sH()&&console.error("Failed to parse mermaid definition",u)}})(),nC(r))},[r,e,o,m]),oC(()=>()=>{nC.flush()},[]);let p=()=>{Vl({app:c,data:l,text:t,shouldSaveMermaidDataToStorage:!0})};return rC(dH,{children:[mn("div",{className:"ttd-dialog-desc",children:mn(Bt,{i18nKey:"mermaid.description",flowchartLink:d=>mn("a",{href:"https://mermaid.js.org/syntax/flowchart.html",children:d}),sequenceLink:d=>mn("a",{href:"https://mermaid.js.org/syntax/sequenceDiagram.html",children:d}),classLink:d=>mn("a",{href:"https://mermaid.js.org/syntax/classDiagram.html",children:d})})}),rC(Z5,{children:[mn(Ti,{children:mn(X5,{input:t,placeholder:h("mermaid.inputPlaceholder"),onChange:d=>n(d.target.value),onKeyboardSubmit:()=>{p()}})}),mn(Ti,{panelActions:[{action:()=>{p()},label:h("mermaid.button"),icon:$n,variant:"button"}],renderSubmitShortcut:()=>mn(q5,{}),children:mn(yp,{canvasRef:s,loaded:e.loaded,error:i})})]})]})},iC=cH;import{useRef as RH}from"react";import{useRef as sC,useEffect as hH,useLayoutEffect as fH}from"react";import{KEYS as bH}from"@orangecatai/common";import{jsx as _1,jsxs as mH}from"react/jsx-runtime";var wp=()=>mH("div",{className:"chat-interface__welcome-screen__welcome-message",children:[_1("h3",{children:h("chat.placeholder.title")}),_1("p",{children:h("chat.placeholder.description")}),_1("p",{children:h("chat.placeholder.hint")})]});import pH from"clsx";import{useState as uH,useEffect as gH}from"react";import{Fragment as aC,jsx as mt,jsxs as Eo}from"react/jsx-runtime";var R1=({message:e,onMermaidTabClick:o,onAiRepairClick:t,onDeleteMessage:n,onInsertMessage:r,onRetry:i,rateLimitRemaining:a,isLastMessage:s,renderWarning:l,allowFixingParseError:c})=>{let[m,p]=uH(!1);gH(()=>{if(!e.error||!s)return;if(e.error&&!e.lastAttemptAt){p(!0);return}let u=Date.now()-e.lastAttemptAt,b=Math.max(0,5e3-u);if(b===0){p(!0);return}p(!1);let g=setTimeout(()=>{p(!0)},b);return()=>clearTimeout(g)},[e.error,e.lastAttemptAt,s]);let d=u=>u.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"});if(e.type==="warning"){let u=l?.(e);return mt("div",{className:"chat-message chat-message--system",children:Eo("div",{className:"chat-message__content",children:[Eo("div",{className:"chat-message__header",children:[mt("span",{className:"chat-message__role",children:h("chat.role.system")}),mt("span",{className:"chat-message__timestamp",children:d(e.timestamp)})]}),mt("div",{className:"chat-message__body",children:mt("div",{className:"chat-message__text",children:u||(e.warningType==="messageLimitExceeded"?Eo(aC,{children:[h("chat.rateLimit.messageLimit"),mt("div",{style:{marginTop:"10px"},children:mt(xo,{onClick:()=>{window.open(`${I.VITE_APP_PLUS_LP}/plus?utm_source=excalidraw&utm_medium=app&utm_content=ttdChatBanner#excalidraw-redirect`,"_blank","noopener")},children:h("chat.upsellBtnLabel")})})]}):h("chat.rateLimit.generalRateLimit"))})})]})})}return Eo("div",{className:`chat-message chat-message--${e.type}`,children:[Eo("div",{className:"chat-message__content",children:[Eo("div",{className:"chat-message__header",children:[mt("span",{className:"chat-message__role",children:e.type==="user"?h("chat.role.user"):h("chat.role.assistant")}),mt("span",{className:"chat-message__timestamp",children:d(e.timestamp)})]}),mt("div",{className:"chat-message__body",children:e.error?Eo(aC,{children:[mt("div",{className:"chat-message__error",children:e.content}),e.errorType!=="parse"&&Eo("div",{className:"chat-message__error_message",children:["Error: ",e.error||h("chat.errors.generationFailed")]}),e.errorType==="parse"&&c&&Eo("div",{className:"chat-message__error_message",children:[mt("p",{children:h("chat.errors.invalidDiagram")}),Eo("div",{className:"chat-message__error-actions",children:[o&&mt("button",{className:"chat-message__error-link",onClick:()=>o(e),type:"button",children:h("chat.errors.fixInMermaid")}),t&&mt("button",{className:"chat-message__error-link",onClick:()=>t(e),disabled:a===0,type:"button",children:h("chat.errors.aiRepair")})]})]})]}):Eo("div",{className:"chat-message__text",children:[e.content,e.isGenerating&&mt("span",{className:"chat-message__cursor",children:"\u258B"})]})})]}),e.type==="assistant"&&!e.isGenerating&&Eo("div",{className:"chat-message__actions",children:[!e.error&&r&&mt("button",{className:"chat-message__action",onClick:()=>r(e),type:"button","aria-label":h("chat.insert"),title:h("chat.insert"),children:uE}),o&&e.content&&mt("button",{className:"chat-message__action",onClick:()=>o(e),type:"button","aria-label":h("chat.viewAsMermaid"),title:h("chat.viewAsMermaid"),children:Fu}),n&&e.errorType!=="network"&&mt("button",{className:"chat-message__action chat-message__action--danger",onClick:()=>n(e.id),type:"button","aria-label":h("chat.deleteMessage"),title:h("chat.deleteMessage"),children:yt}),e.errorType==="network"&&i&&s&&mt("button",{className:pH("chat-message__action",{invisible:!m}),onClick:()=>i(e),type:"button","aria-label":h("chat.retry"),title:h("chat.retry"),children:pE})]})]})};import{jsx as Gn,jsxs as N1}from"react/jsx-runtime";var B1=({chatId:e,messages:o,currentPrompt:t,onPromptChange:n,onGenerate:r,isGenerating:i,rateLimits:a,onAbort:s,onMermaidTabClick:l,onAiRepairClick:c,onDeleteMessage:m,onInsertMessage:p,onRetry:d,renderWelcomeScreen:u,renderWarning:b})=>{let g=sC(null),E=sC(null);fH(()=>{g.current?.scrollIntoView()},[o]),hH(()=>{E.current&&E.current.focus()},[e]);let w=M=>{let S=M.target.value;n(S)},x=()=>{if(i&&s){s();return}let M=t.trim();M&&(r({prompt:M}),n(""))},y=M=>{M.key===bH.ENTER&&!M.shiftKey&&(M.preventDefault(),i||x())},v=t.trim().length>3&&!i&&(a?.rateLimitRemaining??1)>0,T=i&&!!s,C=M=>{let S=M.target;S.style.height="auto",S.style.height=`${Math.min(S.scrollHeight,120)}px`};return N1("div",{className:"chat-interface",children:[N1("div",{className:"chat-interface__messages",children:[o.length===0?Gn("div",{className:"chat-interface__welcome-screen",children:u?u({rateLimits:a??null}):Gn(wp,{})}):o.map((M,S)=>Gn(R1,{message:M,onMermaidTabClick:l,onAiRepairClick:c,onDeleteMessage:m,onInsertMessage:p,onRetry:d,rateLimitRemaining:a?.rateLimitRemaining,isLastMessage:S===o.length-1,renderWarning:b,allowFixingParseError:M.errorType==="parse"&&S===o.length-1},M.id)),Gn("div",{ref:g,id:"messages-end"})]}),Gn("div",{className:"chat-interface__input-container",children:Gn("div",{className:"chat-interface__input-outer",children:N1("div",{className:"chat-interface__input-wrapper",style:{borderColor:i?"var(--dialog-border-color)":void 0},children:[Gn("textarea",{ref:E,autoFocus:!0,className:"chat-interface__input",value:t,onChange:w,onKeyDown:y,placeholder:i?h("chat.generating"):a?.rateLimitRemaining===0?h("chat.rateLimit.messageLimitInputPlaceholder"):o.length>0?h("chat.inputPlaceholderWithMessages"):h("chat.inputPlaceholder",{shortcut:"Shift + Enter"}),disabled:a?.rateLimitRemaining===0,rows:1,cols:30,onInput:C}),Gn("button",{className:"chat-interface__send-button",onClick:x,disabled:!v&&!T,type:"button",children:Gn(qo,{size:"1.5em",icon:i?Ix:$n})})]})})})]})};import{randomId as xH}from"@orangecatai/common";var vp=ye(null),Tp=ye(!1),Cr=ye(null),yo=ye({id:xH(),messages:[],currentPrompt:""});import{findLastIndex as F1,randomId as EH}from"@orangecatai/common";var Sr=(e,o)=>{let{messages:t}=e,n=F1(t,a=>a.type==="assistant");if(n===-1)return e;let r=t[n],i=t.slice();return i[n]={...r,...o},{...e,messages:i}},kr=e=>{let{messages:o}=e,t=F1(o,n=>n.type==="assistant");return o[t]},Kl=(e,o)=>{let t=o.map(n=>({...n,id:EH(),timestamp:new Date}));return{...e,messages:[...e.messages,...t]}},lC=e=>{let o=F1(e.messages??[],t=>t.type==="assistant");return o!==-1?{...e,messages:e.messages.filter((t,n)=>n!==o)}:e},cC=e=>{let o=[];for(let t of e.messages)t.content&&(t.type==="user"||t.type==="assistant")&&o.push({role:t.type,content:t.content});return o};var Xl=()=>{let[e,o]=ee(yo);return{addUserMessage:a=>{o(s=>Kl(s,[{type:"user",content:a}]))},addAssistantMessage:()=>{o(a=>Kl(a,[{type:"assistant",content:"",isGenerating:!0}]))},setAssistantError:(a,s="other",l)=>{let c=l?JSON.stringify({name:l instanceof Error?l.name:"Error",message:l instanceof Error?l.message:String(l),stack:l instanceof Error?l.stack:void 0}):void 0;o(m=>Sr(m,{isGenerating:!1,error:a,errorType:s,errorDetails:c}))},chatHistory:e,setChatHistory:o,setLastRetryAttempt:()=>{o(a=>Sr(a,{lastAttemptAt:Date.now()}))}}};import{useCallback as $l,useEffect as dC,useRef as yH}from"react";import{randomId as wH}from"@orangecatai/common";var vH=e=>{let o=e.trim();return o.length<=50?o:`${o.substring(0,47)}...`},TH=ye([]),IH=ye(!1),CH=ye(!1),Ip=({persistenceAdapter:e})=>{let[o]=ee(yo),[t,n]=ee(TH),[r,i]=ee(IH),[a,s]=ee(CH),l=yH(t);l.current=t;let c=o?.messages[o?.messages.length-1],m=$l(async()=>{if(!(a||r)){i(!0);try{let g=await e.loadChats();n(g),s(!0)}catch(g){console.warn("Failed to load chats:",g),n([]),s(!0)}finally{i(!1)}}},[a,r,n,i,s,e]);dC(()=>{m()},[]);let p=$l(async()=>{if(o.messages.length===0)return;let g=o.messages.find(C=>C.type==="user");if(!g||typeof g.content!="string")return;let E=vH(g.content),w=l.current,x=w.find(C=>C.id===o.id),y=!x||x.messages.length!==o.messages.length||x.messages.some((C,M)=>C.id!==o.messages[M]?.id||C.content!==o.messages[M]?.content),v={id:o.id,title:E,messages:o.messages.filter(C=>C.type==="user"||C.type==="assistant").map(C=>({...C,timestamp:C.timestamp instanceof Date?C.timestamp:new Date(C.timestamp)})),currentPrompt:o.currentPrompt,timestamp:y?Date.now():x?.timestamp??Date.now()},T=[...w.filter(C=>C.id!==o.id),v].sort((C,M)=>M.timestamp-C.timestamp).slice(0,10);n(T);try{await e.saveChats(T)}catch(C){console.warn("Failed to save chats:",C)}},[o,n,e]);dC(()=>{c?.isGenerating||p()},[o.messages?.length,c?.id,c?.isGenerating]);let d=$l(async g=>{let E=l.current.filter(w=>w.id!==g);n(E);try{await e.saveChats(E)}catch(w){console.warn("Failed to save after delete:",w)}return E},[n,e]),u=$l(g=>g,[]),b=$l(async()=>(await p(),wH()),[p]);return{savedChats:t,saveCurrentChat:p,deleteChat:d,restoreChat:u,createNewChatId:b}};import{useCallback as pC,useEffect as Cp,useMemo as uC,useRef as Ii}from"react";var mC=e=>{let o=e.trim();if(!o)return!1;let t=(o.match(/\[/g)||[]).length,n=(o.match(/\]/g)||[]).length,r=(o.match(/\{/g)||[]).length,i=(o.match(/\}/g)||[]).length,a=(o.match(/\(/g)||[]).length,s=(o.match(/\)/g)||[]).length;if(t!==n||r!==i||a!==s)return!1;let l=o.split(`
|
|
24
|
-
`).pop()?.trim()||"";return![/-->$/,/--$/,/-\.$/,/==>$/,/==$/,/~~$/,/::$/,/:$/,/\|$/,/&$/].some(m=>m.test(l))};var
|
|
23
|
+
C -->|Three| F[Car]`,rk=eU(Os,300),nU=({mermaidToExcalidrawLib:e,isActive:t})=>{let[o,n]=tk(()=>Po.get(QG.MERMAID_TO_EXCALIDRAW)||oU),r=JG(o.trim()),[i,a]=tk(null),s=ok(null),l=ok({elements:[],files:null}),c=Xe(),{theme:m}=Ee();nk(()=>{t&&((async()=>{try{if(!r){fb({canvasRef:s,setError:a});return}let u=await zs({canvasRef:s,data:l,mermaidToExcalidrawLib:e,setError:a,mermaidDefinition:r,theme:m});if(!u.success){let b=u.error??new Error("Invalid mermaid definition");a(b)}}catch(u){tU()&&console.error("Failed to parse mermaid definition",u)}})(),rk(r))},[r,e,t,m]),nk(()=>()=>{rk.flush()},[]);let p=()=>{Ac({app:c,data:l,text:o,shouldSaveMermaidDataToStorage:!0})};return ik(rU,{children:[Ln("div",{className:"ttd-dialog-desc",children:Ln(qt,{i18nKey:"mermaid.description",flowchartLink:d=>Ln("a",{href:"https://mermaid.js.org/syntax/flowchart.html",children:d}),sequenceLink:d=>Ln("a",{href:"https://mermaid.js.org/syntax/sequenceDiagram.html",children:d}),classLink:d=>Ln("a",{href:"https://mermaid.js.org/syntax/classDiagram.html",children:d})})}),ik(jC,{children:[Ln($i,{children:Ln($C,{input:o,placeholder:h("mermaid.inputPlaceholder"),onChange:d=>n(d.target.value),onKeyboardSubmit:()=>{p()}})}),Ln($i,{panelActions:[{action:()=>{p()},label:h("mermaid.button"),icon:Er,variant:"button"}],renderSubmitShortcut:()=>Ln(JC,{}),children:Ln(ru,{canvasRef:s,loaded:e.loaded,error:i})})]})]})},ak=nU;import{useRef as MU}from"react";import{useRef as lk,useEffect as cU,useLayoutEffect as dU}from"react";import{KEYS as mU}from"@orangecatai/common";import{jsx as bb,jsxs as iU}from"react/jsx-runtime";var iu=()=>iU("div",{className:"chat-interface__welcome-screen__welcome-message",children:[bb("h3",{children:h("chat.placeholder.title")}),bb("p",{children:h("chat.placeholder.description")}),bb("p",{children:h("chat.placeholder.hint")})]});import aU from"clsx";import{useState as sU,useEffect as lU}from"react";import{Fragment as sk,jsx as vt,jsxs as Bo}from"react/jsx-runtime";var xb=({message:e,onMermaidTabClick:t,onAiRepairClick:o,onDeleteMessage:n,onInsertMessage:r,onRetry:i,rateLimitRemaining:a,isLastMessage:s,renderWarning:l,allowFixingParseError:c})=>{let[m,p]=sU(!1);lU(()=>{if(!e.error||!s)return;if(e.error&&!e.lastAttemptAt){p(!0);return}let u=Date.now()-e.lastAttemptAt,b=Math.max(0,5e3-u);if(b===0){p(!0);return}p(!1);let g=setTimeout(()=>{p(!0)},b);return()=>clearTimeout(g)},[e.error,e.lastAttemptAt,s]);let d=u=>u.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"});if(e.type==="warning"){let u=l?.(e);return vt("div",{className:"chat-message chat-message--system",children:Bo("div",{className:"chat-message__content",children:[Bo("div",{className:"chat-message__header",children:[vt("span",{className:"chat-message__role",children:h("chat.role.system")}),vt("span",{className:"chat-message__timestamp",children:d(e.timestamp)})]}),vt("div",{className:"chat-message__body",children:vt("div",{className:"chat-message__text",children:u||(e.warningType==="messageLimitExceeded"?Bo(sk,{children:[h("chat.rateLimit.messageLimit"),vt("div",{style:{marginTop:"10px"},children:vt(No,{onClick:()=>{window.open(`${I.VITE_APP_PLUS_LP}/plus?utm_source=excalidraw&utm_medium=app&utm_content=ttdChatBanner#excalidraw-redirect`,"_blank","noopener")},children:h("chat.upsellBtnLabel")})})]}):h("chat.rateLimit.generalRateLimit"))})})]})})}return Bo("div",{className:`chat-message chat-message--${e.type}`,children:[Bo("div",{className:"chat-message__content",children:[Bo("div",{className:"chat-message__header",children:[vt("span",{className:"chat-message__role",children:e.type==="user"?h("chat.role.user"):h("chat.role.assistant")}),vt("span",{className:"chat-message__timestamp",children:d(e.timestamp)})]}),vt("div",{className:"chat-message__body",children:e.error?Bo(sk,{children:[vt("div",{className:"chat-message__error",children:e.content}),e.errorType!=="parse"&&Bo("div",{className:"chat-message__error_message",children:["Error: ",e.error||h("chat.errors.generationFailed")]}),e.errorType==="parse"&&c&&Bo("div",{className:"chat-message__error_message",children:[vt("p",{children:h("chat.errors.invalidDiagram")}),Bo("div",{className:"chat-message__error-actions",children:[t&&vt("button",{className:"chat-message__error-link",onClick:()=>t(e),type:"button",children:h("chat.errors.fixInMermaid")}),o&&vt("button",{className:"chat-message__error-link",onClick:()=>o(e),disabled:a===0,type:"button",children:h("chat.errors.aiRepair")})]})]})]}):Bo("div",{className:"chat-message__text",children:[e.content,e.isGenerating&&vt("span",{className:"chat-message__cursor",children:"\u258B"})]})})]}),e.type==="assistant"&&!e.isGenerating&&Bo("div",{className:"chat-message__actions",children:[!e.error&&r&&vt("button",{className:"chat-message__action",onClick:()=>r(e),type:"button","aria-label":h("chat.insert"),title:h("chat.insert"),children:my}),t&&e.content&&vt("button",{className:"chat-message__action",onClick:()=>t(e),type:"button","aria-label":h("chat.viewAsMermaid"),title:h("chat.viewAsMermaid"),children:Ig}),n&&e.errorType!=="network"&&vt("button",{className:"chat-message__action chat-message__action--danger",onClick:()=>n(e.id),type:"button","aria-label":h("chat.deleteMessage"),title:h("chat.deleteMessage"),children:Nt}),e.errorType==="network"&&i&&s&&vt("button",{className:aU("chat-message__action",{invisible:!m}),onClick:()=>i(e),type:"button","aria-label":h("chat.retry"),title:h("chat.retry"),children:dy})]})]})};import{jsx as lr,jsxs as Eb}from"react/jsx-runtime";var yb=({chatId:e,messages:t,currentPrompt:o,onPromptChange:n,onGenerate:r,isGenerating:i,rateLimits:a,onAbort:s,onMermaidTabClick:l,onAiRepairClick:c,onDeleteMessage:m,onInsertMessage:p,onRetry:d,renderWelcomeScreen:u,renderWarning:b})=>{let g=lk(null),E=lk(null);dU(()=>{g.current?.scrollIntoView()},[t]),cU(()=>{E.current&&E.current.focus()},[e]);let y=M=>{let k=M.target.value;n(k)},x=()=>{if(i&&s){s();return}let M=o.trim();M&&(r({prompt:M}),n(""))},w=M=>{M.key===mU.ENTER&&!M.shiftKey&&(M.preventDefault(),i||x())},v=o.trim().length>3&&!i&&(a?.rateLimitRemaining??1)>0,T=i&&!!s,C=M=>{let k=M.target;k.style.height="auto",k.style.height=`${Math.min(k.scrollHeight,120)}px`};return Eb("div",{className:"chat-interface",children:[Eb("div",{className:"chat-interface__messages",children:[t.length===0?lr("div",{className:"chat-interface__welcome-screen",children:u?u({rateLimits:a??null}):lr(iu,{})}):t.map((M,k)=>lr(xb,{message:M,onMermaidTabClick:l,onAiRepairClick:c,onDeleteMessage:m,onInsertMessage:p,onRetry:d,rateLimitRemaining:a?.rateLimitRemaining,isLastMessage:k===t.length-1,renderWarning:b,allowFixingParseError:M.errorType==="parse"&&k===t.length-1},M.id)),lr("div",{ref:g,id:"messages-end"})]}),lr("div",{className:"chat-interface__input-container",children:lr("div",{className:"chat-interface__input-outer",children:Eb("div",{className:"chat-interface__input-wrapper",style:{borderColor:i?"var(--dialog-border-color)":void 0},children:[lr("textarea",{ref:E,autoFocus:!0,className:"chat-interface__input",value:o,onChange:y,onKeyDown:w,placeholder:i?h("chat.generating"):a?.rateLimitRemaining===0?h("chat.rateLimit.messageLimitInputPlaceholder"):t.length>0?h("chat.inputPlaceholderWithMessages"):h("chat.inputPlaceholder",{shortcut:"Shift + Enter"}),disabled:a?.rateLimitRemaining===0,rows:1,cols:30,onInput:C}),lr("button",{className:"chat-interface__send-button",onClick:x,disabled:!v&&!T,type:"button",children:lr(xn,{size:"1.5em",icon:i?vE:Er})})]})})})]})};import{randomId as pU}from"@orangecatai/common";var au=Ie(null),su=Ie(!1),Zr=Ie(null),Fo=Ie({id:pU(),messages:[],currentPrompt:""});import{findLastIndex as wb,randomId as uU}from"@orangecatai/common";var jr=(e,t)=>{let{messages:o}=e,n=wb(o,a=>a.type==="assistant");if(n===-1)return e;let r=o[n],i=o.slice();return i[n]={...r,...t},{...e,messages:i}},qr=e=>{let{messages:t}=e,o=wb(t,n=>n.type==="assistant");return t[o]},Lc=(e,t)=>{let o=t.map(n=>({...n,id:uU(),timestamp:new Date}));return{...e,messages:[...e.messages,...o]}},ck=e=>{let t=wb(e.messages??[],o=>o.type==="assistant");return t!==-1?{...e,messages:e.messages.filter((o,n)=>n!==t)}:e},dk=e=>{let t=[];for(let o of e.messages)o.content&&(o.type==="user"||o.type==="assistant")&&t.push({role:o.type,content:o.content});return t};var _c=()=>{let[e,t]=ne(Fo);return{addUserMessage:a=>{t(s=>Lc(s,[{type:"user",content:a}]))},addAssistantMessage:()=>{t(a=>Lc(a,[{type:"assistant",content:"",isGenerating:!0}]))},setAssistantError:(a,s="other",l)=>{let c=l?JSON.stringify({name:l instanceof Error?l.name:"Error",message:l instanceof Error?l.message:String(l),stack:l instanceof Error?l.stack:void 0}):void 0;t(m=>jr(m,{isGenerating:!1,error:a,errorType:s,errorDetails:c}))},chatHistory:e,setChatHistory:t,setLastRetryAttempt:()=>{t(a=>jr(a,{lastAttemptAt:Date.now()}))}}};import{useCallback as Dc,useEffect as mk,useRef as gU}from"react";import{randomId as hU}from"@orangecatai/common";var fU=e=>{let t=e.trim();return t.length<=50?t:`${t.substring(0,47)}...`},bU=Ie([]),xU=Ie(!1),EU=Ie(!1),lu=({persistenceAdapter:e})=>{let[t]=ne(Fo),[o,n]=ne(bU),[r,i]=ne(xU),[a,s]=ne(EU),l=gU(o);l.current=o;let c=t?.messages[t?.messages.length-1],m=Dc(async()=>{if(!(a||r)){i(!0);try{let g=await e.loadChats();n(g),s(!0)}catch(g){console.warn("Failed to load chats:",g),n([]),s(!0)}finally{i(!1)}}},[a,r,n,i,s,e]);mk(()=>{m()},[]);let p=Dc(async()=>{if(t.messages.length===0)return;let g=t.messages.find(C=>C.type==="user");if(!g||typeof g.content!="string")return;let E=fU(g.content),y=l.current,x=y.find(C=>C.id===t.id),w=!x||x.messages.length!==t.messages.length||x.messages.some((C,M)=>C.id!==t.messages[M]?.id||C.content!==t.messages[M]?.content),v={id:t.id,title:E,messages:t.messages.filter(C=>C.type==="user"||C.type==="assistant").map(C=>({...C,timestamp:C.timestamp instanceof Date?C.timestamp:new Date(C.timestamp)})),currentPrompt:t.currentPrompt,timestamp:w?Date.now():x?.timestamp??Date.now()},T=[...y.filter(C=>C.id!==t.id),v].sort((C,M)=>M.timestamp-C.timestamp).slice(0,10);n(T);try{await e.saveChats(T)}catch(C){console.warn("Failed to save chats:",C)}},[t,n,e]);mk(()=>{c?.isGenerating||p()},[t.messages?.length,c?.id,c?.isGenerating]);let d=Dc(async g=>{let E=l.current.filter(y=>y.id!==g);n(E);try{await e.saveChats(E)}catch(y){console.warn("Failed to save after delete:",y)}return E},[n,e]),u=Dc(g=>g,[]),b=Dc(async()=>(await p(),hU()),[p]);return{savedChats:o,saveCurrentChat:p,deleteChat:d,restoreChat:u,createNewChatId:b}};import{useCallback as uk,useEffect as cu,useMemo as gk,useRef as Zi}from"react";var pk=e=>{let t=e.trim();if(!t)return!1;let o=(t.match(/\[/g)||[]).length,n=(t.match(/\]/g)||[]).length,r=(t.match(/\{/g)||[]).length,i=(t.match(/\}/g)||[]).length,a=(t.match(/\(/g)||[]).length,s=(t.match(/\)/g)||[]).length;if(o!==n||r!==i||a!==s)return!1;let l=t.split(`
|
|
24
|
+
`).pop()?.trim()||"";return![/-->$/,/--$/,/-\.$/,/==>$/,/==$/,/~~$/,/::$/,/:$/,/\|$/,/&$/].some(m=>m.test(l))};var vb=300,yU=3e3,wU=100,hk=100,fk=({mermaidToExcalidrawLib:e,canvasRef:t})=>{let[o]=ne(Fo),[,n]=ne(Zr),[r,i]=ne(su),a=Zi(!1),s=gk(()=>qr(o),[o]),l=Zi(s);cu(()=>{l.current=s},[s]);let c=Zi({elements:[],files:null}),m=Zi(0),p=Zi(null),d=Zi(!1),u=Zi(vb),{theme:b}=Ee(),g=uk(async x=>{if(!x.trim()||!e.loaded||a.current)return!1;a.current=!0;let w=performance.now(),v=await zs({canvasRef:t,data:c,mermaidToExcalidrawLib:e,setError:n,mermaidDefinition:x,theme:b});return performance.now()-w<wU?u.current=vb:u.current=yU,a.current=!1,v.success},[t,e,n,b]),E=gk(()=>{let x=async w=>{let v=Date.now(),T=v-m.current,C=u.current;if(!pk(w)){d.current||(m.current=Math.max(m.current,v-C+hk),d.current=!0),p.current=w;return}if(d.current=!1,T<C){p.current=w;return}p.current=null;let M=await g(w);m.current=Date.now(),M||(m.current=m.current-C+hk,d.current=!0)};return x.flush=async()=>{if(p.current){let w=p.current;p.current=null,await g(w),m.current=Date.now()}},x.cancel=()=>{p.current=null},x},[g]),y=uk(()=>{m.current=0,p.current=null,d.current=!1,u.current=vb},[]);return cu(()=>{s?.content&&s?.isGenerating?E(s.content):s?.isGenerating||(E.flush(),y(),s?.content&&E(s.content))},[y,E,s?.isGenerating,s?.content]),cu(()=>{let x=l.current;!x?.content||x.error||r&&g(x.content)},[o?.id,g,r]),cu(()=>{if(o.messages?.filter(x=>x.type==="assistant").length)r||i(!0);else{let x=t.current;if(x){let w=x.parentElement;w&&(w.style.background="",x.replaceChildren())}i(!1)}},[o.messages,i,t,r]),{data:c}};import{useRef as vU}from"react";import{parseMermaidToExcalidraw as TU}from"@excalidraw/mermaid-to-excalidraw";import{isFiniteNumber as bk}from"@orangecatai/math";var Tb=3,Ib=1e4,xk=({onTextSubmit:e})=>{let[,t]=ne(Zr),[o,n]=ne(au),[r,i]=ne(Fo),{addUserMessage:a,addAssistantMessage:s,setAssistantError:l}=_c(),c=vU(null),m=u=>u.length>Ib||u.length<Tb||o?.rateLimitRemaining===0?(u.length<Tb&&t(new Error(h("chat.errors.promptTooShort",{min:Tb}))),u.length>Ib&&t(new Error(h("chat.errors.promptTooLong",{max:Ib}))),!1):!0;return{onGenerate:async({prompt:u,isRepairFlow:b=!1})=>{if(!m(u))return;c.current&&c.current.abort(),t(null);let g=new AbortController;c.current=g,b?i(E=>jr(E,{isGenerating:!0,content:"",error:void 0,errorType:void 0,errorDetails:void 0})):(a(u),s());try{he("ai","generate","ttd");let y=[...dk(r).slice(-3),{role:"user",content:u}],{generatedResponse:x,error:w,rateLimit:v,rateLimitRemaining:T}=await e({messages:y,onStreamCreated:()=>{b&&i(C=>jr(C,{content:"",error:"",isGenerating:!0}))},onChunk:C=>{i(M=>{let k=qr(M);return jr(M,{content:k.content+C})})},signal:g.signal});if(i(C=>jr(C,{isGenerating:!1})),bk(v)&&bk(T)&&n({rateLimit:v,rateLimitRemaining:T}),(w?.status===429||T===0)&&i(C=>(w?.status===429&&(C=ck(C)),C={...C,messages:C.messages.filter(k=>k.type!=="warning"||k.warningType==="rateLimitExceeded"||k.warningType==="messageLimitExceeded")},Lc(C,[{type:"warning",warningType:T===0?"messageLimitExceeded":"rateLimitExceeded"}]))),w){if(w.name==="AbortError"||w.message==="Aborted"||g.signal.aborted)return;let M=new Error(w.message||h("chat.errors.requestFailed"));w.status!==429&&l(M.message,"network"),t(M);return}try{await TU(x??""),he("ai","mermaid parse success","ttd")}catch(C){he("ai","mermaid parse failed","ttd");let M=new Error(C.message||h("chat.errors.mermaidParseError"));l(M.message,"parse"),t(M)}}catch(E){let y=new Error(E.message||h("chat.errors.generationFailed"));l(y.message,"other"),t(y)}finally{c.current=null}},handleAbort:()=>{c.current&&c.current.abort()}}};import{useCallback as ji,useState as IU}from"react";var Ek=({persistenceAdapter:e})=>{let t=mn(Zr),[o,n]=ne(Fo),[r,i]=IU(!1),{restoreChat:a,deleteChat:s,createNewChatId:l}=lu({persistenceAdapter:e}),c=ji(E=>{let y=E.messages.map(v=>({...v,timestamp:v.timestamp instanceof Date?v.timestamp:new Date(v.timestamp)})),x={id:E.id,messages:y,currentPrompt:""},w=qr(x);t(w?.error?new Error(w?.error):null),n(x)},[t,n]),m=ji(async()=>{let E=await l();n({id:E,messages:[],currentPrompt:""}),t(null)},[l,n,t]),p=ji(E=>{let y=a(E);c(y),i(!1)},[a,c]),d=ji(async(E,y)=>{y.stopPropagation();let x=E===o.id,w=await s(E);if(x)if(w.length>0){let v=w[0];c(v)}else await m()},[o.id,s,c,m]),u=ji(async()=>{await m(),i(!1)},[m]),b=ji(()=>{i(E=>!E)},[]),g=ji(()=>{i(!1)},[]);return{isMenuOpen:r,onRestoreChat:p,handleDeleteChat:d,handleNewChat:u,handleMenuToggle:b,handleMenuClose:g}};import CU from"clsx";import{Fragment as kU,jsx as qi,jsxs as Cb}from"react/jsx-runtime";var yk=({isOpen:e,onToggle:t,onClose:o,onNewChat:n,onRestoreChat:r,onDeleteChat:i,isNewChatBtnVisible:a,savedChats:s,activeSessionId:l,disabled:c})=>Cb("div",{className:"ttd-chat-history-menu",children:[a&&qi(No,{onClick:n,disabled:c,children:h("chat.newChat")}),s.length>0&&qi("div",{className:"ttd-dialog-panel__menu-wrapper",children:Cb(pe,{open:e,children:[qi(pe.Trigger,{onToggle:t,className:"ttd-dialog-menu-trigger",disabled:c,title:h("chat.menu"),"aria-label":h("chat.menu"),children:by}),qi(pe.Content,{onClickOutside:o,onSelect:o,children:qi(kU,{children:s.map(m=>Cb(pe.ItemCustom,{className:CU("ttd-chat-menu-item",{"ttd-chat-menu-item--active":m.id===l}),onClick:()=>{r(m)},children:[qi("span",{className:"ttd-chat-menu-item__title",children:m.title}),qi("button",{className:"ttd-chat-menu-item__delete",onClick:p=>i(m.id,p),title:h("chat.deleteChat"),"aria-label":h("chat.deleteChat"),type:"button",children:Nt})]},m.id))})})]})})]});import{jsx as Hs,jsxs as SU}from"react/jsx-runtime";var wk=({chatId:e,messages:t,currentPrompt:o,onPromptChange:n,onGenerate:r,isGenerating:i,generatedResponse:a,isMenuOpen:s,onMenuToggle:l,onMenuClose:c,onNewChat:m,onRestoreChat:p,onDeleteChat:d,savedChats:u,activeSessionId:b,onAbort:g,onMermaidTabClick:E,onAiRepairClick:y,onDeleteMessage:x,onInsertMessage:w,onRetry:v,onViewAsMermaid:T,renderWelcomeScreen:C,renderWarning:M})=>{let[k]=ne(au),A=(()=>{let _=[];return k&&_.push({label:h("chat.rateLimitRemaining",{count:k.rateLimitRemaining}),variant:"rateLimit",className:k.rateLimitRemaining<5?"ttd-dialog-panel__rate-limit--danger":""}),a&&_.push({action:T,label:h("chat.viewAsMermaid"),icon:Hs(xn,{icon:Er}),variant:"link"}),_})(),P=()=>A.length===2?"space-between":A.length===1&&A[0].variant==="rateLimit"?"flex-start":"flex-end";return Hs($i,{label:SU("div",{className:"ttd-dialog-panel__label-wrapper",children:[Hs("div",{className:"ttd-dialog-panel__label-group"}),Hs("div",{className:"ttd-dialog-panel__header-right",children:Hs(yk,{isNewChatBtnVisible:!!t.length,isOpen:s,onToggle:l,onClose:c,onNewChat:m,onRestoreChat:p,onDeleteChat:d,savedChats:u,activeSessionId:b,disabled:i})})]}),className:"ttd-dialog-chat-panel",panelActionJustifyContent:P(),panelActions:A,children:Hs(yb,{chatId:e,messages:t,currentPrompt:o,onPromptChange:n,onGenerate:r,isGenerating:i,generatedResponse:a,onAbort:g,onMermaidTabClick:E,onAiRepairClick:y,onDeleteMessage:x,onInsertMessage:w,onRetry:v,rateLimits:k,renderWelcomeScreen:C,renderWarning:M})})};import{jsx as vk}from"react/jsx-runtime";var Tk=({canvasRef:e,error:t,loaded:o,onInsert:n,hideErrorDetails:r})=>{let i=[{action:n,label:h("chat.insert"),icon:Er,variant:"button"}];return vk($i,{panelActionJustifyContent:"flex-end",panelActions:i,className:"ttd-dialog-preview-panel",children:vk(ru,{canvasRef:e,error:t,loaded:o,hideErrorDetails:r})})};import{jsx as kb,jsxs as LU}from"react/jsx-runtime";var PU=({mermaidToExcalidrawLib:e,onTextSubmit:t,renderWelcomeScreen:o,renderWarning:n,persistenceAdapter:r})=>{let i=Xe(),a=ve(),s=MU(null),[l,c]=ne(Zr),[m,p]=ne(Fo),d=pa(su),{savedChats:u}=lu({persistenceAdapter:r}),b=qr(m),{setLastRetryAttempt:g}=_c(),{data:E}=fk({canvasRef:s,mermaidToExcalidrawLib:e}),{onGenerate:y,handleAbort:x}=xk({onTextSubmit:t}),{isMenuOpen:w,onRestoreChat:v,handleDeleteChat:T,handleNewChat:C,handleMenuToggle:M,handleMenuClose:k}=Ek({persistenceAdapter:r}),R=()=>{typeof b?.content=="string"&&(Os(b.content),a({openDialog:{name:"ttd",tab:"mermaid"}}))},A=D=>{let F=D.content||"";F&&(Os(F),a({openDialog:{name:"ttd",tab:"mermaid"}}))},P=async D=>{let F=D.content||"";if(!F.trim()||!e.loaded)return;let X={current:{elements:[],files:null}};(await zs({canvasRef:s,data:X,mermaidToExcalidrawLib:e,setError:c,mermaidDefinition:F,theme:i.state.theme})).success&&Ac({app:i,data:X,text:F,shouldSaveMermaidDataToStorage:!0})},_=async D=>{let F=D.content||"",X=D.error||"";if(!F)return;let te=`Fix the error in this Mermaid diagram. The diagram is:
|
|
25
25
|
|
|
26
26
|
\`\`\`mermaid
|
|
27
27
|
${F}
|
|
28
28
|
\`\`\`
|
|
29
29
|
|
|
30
|
-
The exception/error is: ${
|
|
30
|
+
The exception/error is: ${X}
|
|
31
31
|
|
|
32
|
-
Please fix the Mermaid syntax and regenerate a valid diagram.`;await w({prompt:J,isRepairFlow:!0})},z=async R=>{let F=m.messages.findIndex(K=>K.id===R.id);if(F>0){let K=m.messages[F-1];K.type==="user"&&typeof K.content=="string"&&(g(),await w({prompt:K.content,isRepairFlow:!0}))}},V=()=>{Vl({app:i,data:E})},G=R=>{let F=m.messages.findIndex(J=>J.id===R&&J.type==="assistant"),K=m.messages.slice(0,F-1);p({...m,messages:K})},Y=R=>{p(F=>({...F,currentPrompt:R}))};return FH("div",{className:`ttd-dialog-layout ${d?"ttd-dialog-layout--split":"ttd-dialog-layout--chat-only"}`,children:[U1(yC,{chatId:m.id,messages:m.messages,currentPrompt:m.currentPrompt,onPromptChange:Y,onGenerate:w,isGenerating:b?.isGenerating??!1,generatedResponse:b?.content,isMenuOpen:y,onMenuToggle:M,onMenuClose:S,onNewChat:C,onRestoreChat:v,onDeleteChat:T,savedChats:u,activeSessionId:m.id,onAbort:x,onMermaidTabClick:_,onAiRepairClick:A,onDeleteMessage:G,onInsertMessage:P,onRetry:z,onViewAsMermaid:D,renderWarning:n,renderWelcomeScreen:t}),d&&U1(vC,{canvasRef:s,hideErrorDetails:b?.errorType==="parse",error:l,loaded:e.loaded,onInsert:V})]})},BH=({mermaidToExcalidrawLib:e,onTextSubmit:o,renderWelcomeScreen:t,renderWarning:n,persistenceAdapter:r})=>U1(NH,{mermaidToExcalidrawLib:e,onTextSubmit:o,renderWelcomeScreen:t,renderWarning:n,persistenceAdapter:r}),TC=BH;import{Tabs as OH}from"radix-ui";import{useRef as IC}from"react";import{isMemberOf as zH}from"@orangecatai/common";import{jsx as HH}from"react/jsx-runtime";var CC=e=>{let o=be(),t=IC(null),n=IC(0);return HH(OH.Root,{ref:t,className:"ttd-dialog-tabs-root",value:e.tab,onValueChange:r=>{if(!r)return;let i=t.current?.closest(".Modal__content");if(i){let a=i.offsetHeight||0;a>n.current&&(n.current=a,i.style.minHeight=`min(${n.current}px, 100%)`)}e.dialog==="ttd"&&zH(["text-to-diagram","mermaid"],r)&&o({openDialog:{name:e.dialog,tab:r}})},children:e.children})};CC.displayName="TTDDialogTabs";var SC=CC;import{Tabs as GH}from"radix-ui";import{jsx as UH}from"react/jsx-runtime";var W1=({children:e,...o})=>UH(GH.List,{className:"ttd-dialog-triggers",...o,children:e});W1.displayName="TTDDialogTabTriggers";import{Tabs as WH}from"radix-ui";import{jsx as kC}from"react/jsx-runtime";var Sp=({children:e,tab:o,onSelect:t,...n})=>kC(WH.Trigger,{value:o,asChild:!0,onSelect:t,children:kC("button",{type:"button",className:"ttd-dialog-tab-trigger",...n,children:e})});Sp.displayName="TTDDialogTabTrigger";import{Tabs as YH}from"radix-ui";import{jsx as VH}from"react/jsx-runtime";var kp=({tab:e,children:o,...t})=>VH(YH.Content,{...t,value:e,children:o});kp.displayName="TTDDialogTab";import{jsx as pn,jsxs as Y1}from"react/jsx-runtime";var Mp=e=>{let o=he();return o.openDialog?.name!=="ttd"?null:pn($H,{...e,tab:o.openDialog.tab})};Mp.WelcomeMessage=wp;var $H=Hn("TTDDialogBase",({tab:e,...o})=>{let t=ze(),[n,r]=XH({loaded:!1,api:import("@excalidraw/mermaid-to-excalidraw")});return KH(()=>{(async()=>{await n.api,r(a=>({...a,loaded:!0}))})()},[n.api]),pn(Qe,{className:"ttd-dialog",onCloseRequest:()=>{t.setOpenDialog(null)},size:1520,title:!1,...o,autofocus:!1,children:Y1(SC,{dialog:"ttd",tab:e,children:["__fallback"in o&&o.__fallback?pn("p",{className:"dialog-mermaid-title",children:h("mermaid.title")}):Y1(W1,{children:[pn(Sp,{tab:"text-to-diagram",children:Y1("div",{className:"ttd-dialog-tab-trigger__content",children:[h("labels.textToDiagram"),pn("div",{className:"ttd-dialog-tab-trigger__badge",children:h("chat.aiBeta")})]})}),pn(Sp,{tab:"mermaid",children:h("mermaid.label")})]}),!("__fallback"in o)&&pn(kp,{className:"ttd-dialog-content",tab:"text-to-diagram",children:pn(TC,{mermaidToExcalidrawLib:n,onTextSubmit:o.onTextSubmit,renderWelcomeScreen:o.renderWelcomeScreen,renderWarning:o.renderWarning,persistenceAdapter:o.persistenceAdapter})}),pn(kp,{className:"ttd-dialog-content",tab:"mermaid",children:pn(iC,{mermaidToExcalidrawLib:n,isActive:e==="mermaid"})})]})})});import{round as gS}from"@orangecatai/math";import lU from"clsx";import cU from"lodash.throttle";import{useEffect as hS,useMemo as r0,useState as dU,memo as mU}from"react";import{STATS_PANELS as Bp}from"@orangecatai/common";import{getCommonBounds as pU}from"@orangecatai/element";import{getUncroppedWidthAndHeight as uU}from"@orangecatai/element";import{isImageElement as i0}from"@orangecatai/element";import{frameAndChildrenSelectedTogether as gU}from"@orangecatai/element";import{elementsAreInSameGroup as hU}from"@orangecatai/element";import{degreesToRadians as NC,radiansToDegrees as zC}from"@orangecatai/math";import{getBoundTextElement as BC}from"@orangecatai/element";import{isArrowElement as FC,isElbowArrow as sG}from"@orangecatai/element";import{updateBindings as OC}from"@orangecatai/element";import tG from"clsx";import{useEffect as _C,useRef as Lp,useState as oG}from"react";import{EVENT as ls,KEYS as nG,cloneJSON as V1}from"@orangecatai/common";import{deepCopyElement as rG}from"@orangecatai/element";import{CaptureUpdateAction as RC}from"@orangecatai/element";import{pointFrom as Mr,pointRotateRads as Pp}from"@orangecatai/math";import{getBoundTextElement as ZH,isBindingElement as jH,unbindBindingElement as MC}from"@orangecatai/element";import{isFrameLikeElement as AC}from"@orangecatai/element";import{getSelectedGroupIds as qH,getElementsInGroup as JH,isInGroup as QH}from"@orangecatai/element";import{getFrameChildren as eG}from"@orangecatai/element";import{updateBindings as PC}from"@orangecatai/element";import{DRAGGING_THRESHOLD as LC}from"@orangecatai/common";var DC=.01,Zl=10,Vt=(e,o)=>!(o==="angle"&&AC(e)),Ve=(e,o)=>{let t=e+o/2;return t-t%o},as=(e,o,t)=>Object.keys(e).map(n=>({original:(t??o).get(n),latest:o.get(n)})).filter(n=>n.original!==void 0&&n.latest!==void 0);var ki=(e,o,t,n,r,i,a=!0)=>{if(jH(t)&&(t.startBinding||t.endBinding)){if(Math.abs(e-t.x)<LC&&Math.abs(o-t.y)<LC)return;MC(t,"start",n),MC(t,"end",n)}let s=n.getNonDeletedElementsMap(),l=s.get(t.id);if(!l)return;let[c,m]=[t.x+t.width/2,t.y+t.height/2],[p,d]=Pp(Mr(t.x,t.y),Mr(c,m),t.angle),u=e-p,b=o-d,[g,E]=Pp(Mr(e,o),Mr(c+u,m+b),-t.angle);n.mutateElement(l,{x:g,y:E},{informMutation:a,isDragging:!1}),PC(l,n,r);let w=ZH(t,i);if(w){let x=s.get(w.id);x&&n.mutateElement(x,{x:w.x+u,y:w.y+b},{informMutation:a,isDragging:!1})}if(AC(t)){let x=eG(i,t.id);x.forEach(y=>{let v=s.get(y.id);if(!v)return;let[T,C]=[y.x+y.width/2,y.y+y.height/2],[M,S]=Pp(Mr(y.x,y.y),Mr(T,C),y.angle),D=Math.round(M+u),_=Math.round(S+b),[P,A]=Pp(Mr(D,_),Mr(T+u,C+b),-y.angle);n.mutateElement(v,{x:P,y:A},{informMutation:a,isDragging:!1}),PC(v,n,r,{simultaneouslyUpdated:x})})}},ss=(e,o)=>{let n=qH(o).map(r=>JH(e,r).reduce((i,a)=>(i[a.id]=!0,i),{}));return e.filter(r=>!QH(r)).forEach(r=>{n.push({[r.id]:!0})}),n};import{jsx as K1,jsxs as aG}from"react/jsx-runtime";var iG=({label:e,icon:o,dragInputCallback:t,value:n,elements:r,editable:i=!0,shouldKeepAspectRatio:a,property:s,scene:l,appState:c,sensitivity:m=1,dragFinishedCallback:p})=>{let d=ze(),u=be(),b=Lp(null),g=Lp(null),[E,w]=oG(n.toString()),x=Lp(null);x.current||(x.current={originalAppState:V1(c),originalElements:r,lastUpdatedValue:E,updatePending:!1}),_C(()=>{let T=n.toString();w(T),x.current.lastUpdatedValue=T},[n]);let y=(T,C,M)=>{if(!x.current.updatePending)return!1;x.current.updatePending=!1;let S=Number(T);if(isNaN(S)){w(n.toString());return}let D=Number(S.toFixed(2)),_=Number(n);(isNaN(_)||Math.abs(D-_)>=DC)&&(x.current.lastUpdatedValue=T,t({accumulatedChange:0,instantChange:0,originalElements:C,originalElementsMap:d.scene.getNonDeletedElementsMap(),shouldKeepAspectRatio:a,shouldChangeByStepSize:!1,scene:l,nextValue:D,property:s,originalAppState:M,setInputValue:P=>w(String(P)),app:d,setAppState:u}),d.syncActionResult({captureUpdate:RC.IMMEDIATELY}))},v=Lp({});return v.current.handleInputValue=y,_C(()=>{let T=b.current,C=v.current;return()=>{let M=T?.value;M&&C.handleInputValue?.(M,x.current.originalElements,x.current.originalAppState),window.removeEventListener(ls.POINTER_MOVE,C.onPointerMove,!1),window.removeEventListener(ls.POINTER_UP,C.onPointerUp,!1)}},[i]),i?aG("div",{className:tG("drag-input-container",!i&&"disabled"),"data-testid":e,children:[K1("div",{className:"drag-input-label",ref:g,onPointerDown:T=>{if(b.current&&i){document.body.classList.add("excalidraw-cursor-resize");let C=Number(b.current.value);isNaN(C)&&(C=0);let M=null,S=d.scene.getNonDeletedElements().reduce((G,Y)=>(G.set(Y.id,rG(Y)),G),new Map),D=r.map(G=>S.get(G.id)),_=V1(c),P=0,A=0,z=G=>{if(M&&S!==null&&D!==null){let Y=G.clientX-M.x;Y!==0&&(A+=Y,Math.abs(A)>=m&&(A=Math.sign(A)*Math.floor(Math.abs(A)/m),P+=A,t({accumulatedChange:P,instantChange:A,originalElements:D,originalElementsMap:S,shouldKeepAspectRatio:a,shouldChangeByStepSize:G.shiftKey,property:s,scene:l,originalAppState:_,setInputValue:R=>w(String(R)),app:d,setAppState:u}),A=0))}M={x:G.clientX,y:G.clientY}},V=()=>{window.removeEventListener(ls.POINTER_MOVE,z,!1),d.syncActionResult({captureUpdate:RC.IMMEDIATELY}),p?.({app:d,setAppState:u,originalElements:D,originalAppState:_}),M=null,P=0,A=0,D=null,S=null,document.body.classList.remove("excalidraw-cursor-resize"),window.removeEventListener(ls.POINTER_UP,V,!1)};v.current.onPointerMove=z,v.current.onPointerUp=V,window.addEventListener(ls.POINTER_MOVE,z,!1),window.addEventListener(ls.POINTER_UP,V,!1)}},onPointerEnter:()=>{g.current&&(g.current.style.cursor="ew-resize")},children:o?K1(qo,{icon:o}):e}),K1("input",{className:"drag-input",autoComplete:"off",spellCheck:"false",onKeyDown:T=>{if(i){let C=T.target;C instanceof HTMLInputElement&&T.key===nG.ENTER&&(y(C.value,r,c),d.focusContainer())}},ref:b,value:E,onChange:T=>{x.current.updatePending=!0,w(T.target.value)},onFocus:T=>{T.target.select(),x.current.originalElements=r,x.current.originalAppState=V1(c)},onBlur:T=>{E?i&&y(T.target.value,x.current.originalElements,x.current.originalAppState):w(n.toString())},disabled:!i})]}):null},xt=iG;import{jsx as mG}from"react/jsx-runtime";var lG=15,cG=({accumulatedChange:e,originalElements:o,shouldChangeByStepSize:t,nextValue:n,scene:r,app:i})=>{let a=r.getNonDeletedElementsMap(),s=o[0];if(s&&!sG(s)){let l=a.get(s.id);if(!l)return;if(n!==void 0){let b=NC(n);r.mutateElement(l,{angle:b}),OC(l,r,i.state);let g=BC(l,a);g&&!FC(l)&&r.mutateElement(g,{angle:b});return}let c=Math.round(zC(s.angle)*100)/100,m=Math.round(e),p=(c+m)%360;t&&(p=Ve(p,lG)),p=p<0?p+360:p;let d=NC(p);r.mutateElement(l,{angle:d}),OC(l,r,i.state);let u=BC(l,a);u&&!FC(l)&&r.mutateElement(u,{angle:d})}},dG=({element:e,scene:o,appState:t,property:n})=>mG(xt,{label:"A",icon:Hc,value:Math.round(zC(e.angle)%360*100)/100,elements:[e],dragInputCallback:cG,editable:Vt(e,"angle"),scene:o,appState:t,property:n}),HC=dG;import{jsx as uG}from"react/jsx-runtime";var GC=5,pG=({property:e,scene:o,appState:t,setAppState:n})=>uG(xt,{label:"Grid step",sensitivity:8,elements:[],dragInputCallback:({nextValue:r,instantChange:i,shouldChangeByStepSize:a,setInputValue:s})=>{n(l=>{let c;return r?c=r:i&&(c=a?Ve(l.gridStep+GC*Math.sign(i),GC):l.gridStep+i),c?(c=kb(c),s(c),{gridStep:c}):(s(l.gridStep),null)})},scene:o,value:t.gridStep,property:e,appState:t}),UC=pG;import{clamp as Ap,round as X1}from"@orangecatai/math";import{MIN_WIDTH_OR_HEIGHT as Dp}from"@orangecatai/common";import{MINIMAL_CROP_SIZE as WC,getUncroppedWidthAndHeight as KC}from"@orangecatai/element";import{resizeSingleElement as YC}from"@orangecatai/element";import{isImageElement as XC}from"@orangecatai/element";import{isFrameLikeElement as $1}from"@orangecatai/element";import{getElementsInResizingFrame as Z1}from"@orangecatai/element";import{replaceAllElementsInFrame as $C}from"@orangecatai/element";import{jsx as xG}from"react/jsx-runtime";var VC=10,gG=e=>e.type==="image",hG=({accumulatedChange:e,originalElements:o,originalElementsMap:t,shouldKeepAspectRatio:n,shouldChangeByStepSize:r,nextValue:i,property:a,originalAppState:s,instantChange:l,scene:c,app:m,setAppState:p})=>{let d=c.getNonDeletedElementsMap(),u=o[0],b=d.get(u.id);if(u&&b){let g=n||gG(u),E=u.width/u.height;if(s.croppingElementId===u.id){let w=d.get(u.id);if(!w||!XC(w)||!w.crop)return;let x=w.crop,y={...x},v=w.scale[0]===-1,T=w.scale[1]===-1,{width:C,height:M}=KC(w),S=x.naturalWidth/C,D=x.naturalHeight/M,_=v?x.width+x.x:x.naturalWidth-x.x,P=T?x.height+x.y:x.naturalHeight-x.y,A=WC*S,z=WC*D;if(i!==void 0){if(a==="width"){let F=i*S,K=Ap(F,A,_);y={...y,width:K,x:v?x.x+x.width-K:x.x}}else if(a==="height"){let F=i*D,K=Ap(F,z,P);y={...y,height:K,y:T?x.y+x.height-K:x.y}}c.mutateElement(w,{crop:y,width:y.width/(x.naturalWidth/C),height:y.height/(x.naturalHeight/M)});return}let V=a==="width"?l:0,G=a==="height"?l:0,Y=Ap(x.width+V,A,_),R=Ap(x.height+G,A,P);y={...x,x:v?x.x+x.width-Y:x.x,y:T?x.y+x.height-R:x.y,width:Y,height:R},c.mutateElement(w,{crop:y,width:y.width/(x.naturalWidth/C),height:y.height/(x.naturalHeight/M)});return}if(i!==void 0){let w=Math.max(a==="width"?i:g?i*E:u.width,Dp),x=Math.max(a==="height"?i:g?i/E:u.height,Dp);if(YC(w,x,b,u,t,c,a==="width"?"e":"s",{shouldMaintainAspectRatio:g}),$1(b)){let y=Z1(c.getElementsIncludingDeleted(),b,s,c.getNonDeletedElementsMap()),v=$C(c.getElementsIncludingDeleted(),y,b,m);c.replaceAllElements(v)}return}{let w=a==="width"?e:0,x=a==="height"?e:0,y=Math.max(0,u.width+w);a==="width"&&(r?y=Ve(y,VC):y=Math.round(y));let v=Math.max(0,u.height+x);if(a==="height"&&(r?v=Ve(v,VC):v=Math.round(v)),g&&(a==="width"?v=Math.round(y/E*100)/100:y=Math.round(v*E*100)/100),v=Math.max(Dp,v),y=Math.max(Dp,y),YC(y,v,b,u,t,c,a==="width"?"e":"s",{shouldMaintainAspectRatio:g}),$1(b)){let T=Z1(c.getElementsIncludingDeleted(),b,s,c.getNonDeletedElementsMap());p({elementsToHighlight:T})}}}},fG=({setAppState:e,app:o,originalElements:t,originalAppState:n})=>{let r=o.scene.getNonDeletedElementsMap(),i=t?.[0],a=i&&r.get(i.id);if(a&&$1(a)){let s=Z1(o.scene.getElementsIncludingDeleted(),a,n,o.scene.getNonDeletedElementsMap()),l=$C(o.scene.getElementsIncludingDeleted(),s,a,o);o.scene.replaceAllElements(l),e({elementsToHighlight:null})}},bG=({property:e,element:o,scene:t,appState:n})=>{let r=X1(e==="width"?o.width:o.height,2);if(n.croppingElementId&&n.croppingElementId===o.id&&XC(o)&&o.crop){let{width:i,height:a}=KC(o);if(e==="width"){let s=i/o.crop.naturalWidth;r=X1(o.crop.width*s,2)}if(e==="height"){let s=a/o.crop.naturalHeight;r=X1(o.crop.height*s,2)}}return xG(xt,{label:e==="width"?"W":"H",elements:[o],dragInputCallback:hG,value:r,editable:Vt(o,e),scene:t,appState:n,property:e,dragFinishedCallback:fG})},j1=bG;import{getBoundTextElement as EG,redrawTextBoundingBox as yG}from"@orangecatai/element";import{hasBoundTextElement as wG,isTextElement as jC}from"@orangecatai/element";import{jsx as CG}from"react/jsx-runtime";var ZC=4,vG=4,TG=({accumulatedChange:e,originalElements:o,shouldChangeByStepSize:t,nextValue:n,scene:r})=>{let i=r.getNonDeletedElementsMap(),a=o[0];if(a){let s=i.get(a.id);if(!s||!jC(s))return;let l;if(n!==void 0)l=Math.max(Math.round(n),ZC);else if(a.type==="text"){let c=Math.round(a.fontSize),m=Math.round(e);l=Math.max(c+m,ZC),t&&(l=Ve(l,vG))}l&&(r.mutateElement(s,{fontSize:l}),yG(s,r.getContainerElement(s),r))}},IG=({element:e,scene:o,appState:t,property:n})=>{let r=jC(e)?e:wG(e)?EG(e,o.getNonDeletedElementsMap()):null;return r?CG(xt,{label:"F",value:Math.round(r.fontSize*10)/10,elements:[r],dragInputCallback:TG,icon:jr,appState:t,scene:o,property:n}):null},qC=IG;import{degreesToRadians as JC,radiansToDegrees as tS}from"@orangecatai/math";import{getBoundTextElement as QC}from"@orangecatai/element";import{isArrowElement as eS}from"@orangecatai/element";import{isInGroup as q1}from"@orangecatai/element";import{jsx as PG}from"react/jsx-runtime";var SG=15,kG=({accumulatedChange:e,originalElements:o,shouldChangeByStepSize:t,nextValue:n,property:r,scene:i})=>{let a=i.getNonDeletedElementsMap(),s=o.map(c=>a.get(c.id)).filter(c=>c&&!q1(c)&&Vt(c,r)),l=o.filter(c=>!q1(c)&&Vt(c,r));if(n!==void 0){let c=JC(n);for(let m of s){if(!m)continue;i.mutateElement(m,{angle:c});let p=QC(m,a);p&&!eS(m)&&i.mutateElement(p,{angle:c})}i.triggerUpdate();return}for(let c=0;c<s.length;c++){let m=s[c];if(!m)continue;let p=l[c],d=Math.round(tS(p.angle)*100)/100,u=Math.round(e),b=(d+u)%360;t&&(b=Ve(b,SG)),b=b<0?b+360:b;let g=JC(b);i.mutateElement(m,{angle:g});let E=QC(m,a);E&&!eS(m)&&i.mutateElement(E,{angle:g})}i.triggerUpdate()},MG=({elements:e,scene:o,appState:t,property:n})=>{let r=e.filter(l=>!q1(l)&&Vt(l,"angle")),i=r.map(l=>Math.round(tS(l.angle)%360*100)/100),a=new Set(i).size===1?i[0]:"Mixed",s=r.some(l=>Vt(l,"angle"));return PG(xt,{label:"A",icon:Hc,value:a,elements:e,dragInputCallback:kG,editable:s,appState:t,scene:o,property:n})},oS=MG;import{pointFrom as nS}from"@orangecatai/math";import{useMemo as LG}from"react";import{MIN_WIDTH_OR_HEIGHT as Pr}from"@orangecatai/common";import{getElementsInResizingFrame as J1,isFrameLikeElement as Q1,replaceAllElementsInFrame as aS,updateBoundElements as AG}from"@orangecatai/element";import{rescalePointsInElement as DG,resizeSingleElement as rS}from"@orangecatai/element";import{getBoundTextElement as _G,handleBindTextResize as RG}from"@orangecatai/element";import{isTextElement as sS}from"@orangecatai/element";import{getCommonBounds as _p}from"@orangecatai/element";import{jsx as HG}from"react/jsx-runtime";var cs=10,NG=(e,o,t,n)=>{let r=n.x-e,i=n.y-o,a=n.width*t,s=n.height*t,l=e+r*t,c=o+i*t;return{width:a,height:s,x:l,y:c,...DG(n,a,s,!1),...sS(n)?{fontSize:n.fontSize*t}:{}}},BG=(e,o,t,n,r,i,a,s)=>{let l=s.getNonDeletedElementsMap(),c=NG(e,o,n,i);s.mutateElement(r,c);let m=_G(i,a);if(m){let p=m.fontSize*n;AG(r,s);let d=l.get(m.id);d&&sS(d)&&(s.mutateElement(d,{fontSize:p}),RG(r,s,t==="width"?"e":"s",!0))}},iS=(e,o,t,n,r,i,a,s,l,c)=>{i==="width"?o=Math.round(e/n*100)/100:e=Math.round(o*n*100)/100;let m=o/t;for(let p=0;p<s.length;p++){let d=s[p],u=a[p];BG(r[0],r[1],i,m,u,d,l,c)}},FG=({accumulatedChange:e,originalElements:o,originalElementsMap:t,originalAppState:n,shouldChangeByStepSize:r,nextValue:i,scene:a,property:s,setAppState:l,app:c})=>{let m=a.getNonDeletedElementsMap(),p=ss(o,n);if(i!==void 0){for(let g of p){let E=as(g,m,t);if(E.length>1){let w=E.map(A=>A.latest),x=E.map(A=>A.original),[y,v,T,C]=_p(x),M=T-y,S=C-v,D=M/S,_=Math.max(Pr,s==="width"?Math.max(0,i):M),P=Math.max(Pr,s==="height"?Math.max(0,i):S);iS(_,P,S,D,nS(y,v),s,w,x,t,a)}else{let[w]=E,x=w?.latest,y=w?.original;if(x&&y&&Vt(x,s)){let v=s==="width"?Math.max(0,i):x.width;s==="width"&&(r?v=Ve(v,cs):v=Math.round(v));let T=s==="height"?Math.max(0,i):x.height;if(s==="height"&&(r?T=Ve(T,cs):T=Math.round(T)),v=Math.max(Pr,v),T=Math.max(Pr,T),rS(v,T,x,y,t,a,s==="width"?"e":"s",{shouldInformMutation:!1}),Q1(x)){let C=J1(a.getElementsIncludingDeleted(),x,n,a.getNonDeletedElementsMap()),M=aS(a.getElementsIncludingDeleted(),C,x,c);a.replaceAllElements(M)}}}}a.triggerUpdate();return}let d=s==="width"?e:0,u=s==="height"?e:0,b=[];for(let g of p){let E=as(g,m,t);if(E.length>1){let w=E.map(A=>A.latest),x=E.map(A=>A.original),[y,v,T,C]=_p(x),M=T-y,S=C-v,D=M/S,_=Math.max(0,M+d);s==="width"&&(r?_=Ve(_,cs):_=Math.round(_));let P=Math.max(0,S+u);s==="height"&&(r?P=Ve(P,cs):P=Math.round(P)),_=Math.max(Pr,_),P=Math.max(Pr,P),iS(_,P,S,D,nS(y,v),s,w,x,t,a)}else{let[w]=E,x=w?.latest,y=w?.original;if(x&&y&&Vt(x,s)){let v=Math.max(0,y.width+d);s==="width"&&(r?v=Ve(v,cs):v=Math.round(v));let T=Math.max(0,y.height+u);if(s==="height"&&(r?T=Ve(T,cs):T=Math.round(T)),v=Math.max(Pr,v),T=Math.max(Pr,T),rS(v,T,x,y,t,a,s==="width"?"e":"s",{shouldInformMutation:!1}),Q1(x)){let C=J1(a.getElementsIncludingDeleted(),x,n,a.getNonDeletedElementsMap());b.push(...C)}}}}l({elementsToHighlight:b}),a.triggerUpdate()},OG=({setAppState:e,app:o,originalElements:t,originalAppState:n})=>{let r=o.scene.getNonDeletedElementsMap(),i=t?.[0],a=i&&r.get(i.id);if(a&&Q1(a)){let s=J1(o.scene.getElementsIncludingDeleted(),a,n,o.scene.getNonDeletedElementsMap()),l=aS(o.scene.getElementsIncludingDeleted(),s,a,o);o.scene.replaceAllElements(l),e({elementsToHighlight:null})}},zG=({property:e,elements:o,elementsMap:t,atomicUnits:n,scene:r,appState:i})=>{let a=LG(()=>n.map(c=>{let m=as(c,t);if(m.length>1){let[d,u,b,g]=_p(m.map(E=>E.latest));return Math.round((e==="width"?b-d:g-u)*100)/100}let[p]=m;return Math.round((e==="width"?p.latest.width:p.latest.height)*100)/100}),[t,n,e]),s=new Set(a).size===1?Math.round(a[0]*100)/100:"Mixed",l=a.length>0;return HG(xt,{label:e==="width"?"W":"H",elements:o,dragInputCallback:FG,value:s,editable:l,appState:i,property:e,scene:r,dragFinishedCallback:OG})},e0=zG;import{getBoundTextElement as GG,redrawTextBoundingBox as lS}from"@orangecatai/element";import{hasBoundTextElement as UG,isTextElement as WG}from"@orangecatai/element";import{isInGroup as YG}from"@orangecatai/element";import{jsx as ZG}from"react/jsx-runtime";var cS=4,VG=4,KG=(e,o)=>e.reduce((t,n)=>{if(!n||YG(n))return t;if(WG(n))return t.push(n),t;if(UG(n)){let r=GG(n,o);if(r)return t.push(r),t}return t},[]),XG=({accumulatedChange:e,originalElements:o,shouldChangeByStepSize:t,nextValue:n,scene:r})=>{let i=r.getNonDeletedElementsMap(),a=o.map(l=>i.get(l.id)),s;if(n){s=Math.max(Math.round(n),cS);for(let l of a)r.mutateElement(l,{fontSize:s}),lS(l,r.getContainerElement(l),r);r.triggerUpdate()}else{let l=o;for(let c=0;c<a.length;c++){let m=a[c],p=l[c],d=Math.round(p.fontSize),u=Math.round(e),b=Math.max(d+u,cS);t&&(b=Ve(b,VG)),r.mutateElement(m,{fontSize:b}),lS(m,r.getContainerElement(m),r)}r.triggerUpdate()}},$G=({elements:e,scene:o,appState:t,property:n,elementsMap:r})=>{let i=KG(e,r);if(!i.length)return null;let a=i.map(c=>Math.round(c.fontSize*10)/10),s=new Set(a).size===1?a[0]:"Mixed",l=a.length>0;return ZG(xt,{label:"F",icon:jr,elements:i,dragInputCallback:XG,value:s,editable:l,scene:o,property:n,appState:t})},dS=$G;import{pointFrom as Lr,pointRotateRads as Rp}from"@orangecatai/math";import{useMemo as jG}from"react";import{isTextElement as qG}from"@orangecatai/element";import{getCommonBounds as t0}from"@orangecatai/element";import{jsx as oU}from"react/jsx-runtime";var JG=(e,o,t,n,r,i,a)=>{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]=Rp(Lr(l.x,l.y),Lr(c,m),l.angle),u=e==="x"?Math.round(p+o):p,b=e==="y"?Math.round(d+t):d;ki(u,b,l,i,a,r,!1)}},QG=(e,o,t,n,r,i)=>{let a=r.getNonDeletedElementsMap(),[s,l,,]=t0(t),c=e-s,m=o-l;for(let p=0;p<t.length;p++){let d=t[p],u=a.get(d.id);if(u&&(!qG(u)||!u.containerId)){let[b,g]=[u.x+u.width/2,u.y+u.height/2],[E,w]=Rp(Lr(u.x,u.y),Lr(b,g),u.angle);ki(E+c,w+m,d,r,i,n,!1)}}},eU=({accumulatedChange:e,originalElements:o,originalElementsMap:t,shouldChangeByStepSize:n,nextValue:r,property:i,scene:a,originalAppState:s,app:l})=>{let c=a.getNonDeletedElementsMap();if(r!==void 0){for(let u of ss(o,s)){let b=as(u,c,t);if(b.length>1){let[g,E,,]=t0(b.map(y=>y.latest));QG(i==="x"?r:g,i==="y"?r:E,b.map(y=>y.original),t,a,l.state)}else{let g=b[0]?.original,E=b[0]?.latest;if(g&&E&&Vt(E,i)){let[w,x]=[g.x+g.width/2,g.y+g.height/2],[y,v]=Rp(Lr(g.x,g.y),Lr(w,x),g.angle);ki(i==="x"?r:y,i==="y"?r:v,g,a,l.state,t,!1)}}}a.triggerUpdate();return}let m=n?Ve(e,Zl):e;JG(i,i==="x"?m:0,i==="y"?m:0,o,t,a,l.state),a.triggerUpdate()},tU=({property:e,elements:o,elementsMap:t,atomicUnits:n,scene:r,appState:i})=>{let a=jG(()=>n.map(l=>{let c=Object.keys(l).map(g=>t.get(g)).filter(g=>g!==void 0);if(c.length>1){let[g,E]=t0(c);return Math.round((e==="x"?g:E)*100)/100}let[m]=c,[p,d]=[m.x+m.width/2,m.y+m.height/2],[u,b]=Rp(Lr(m.x,m.y),Lr(p,d),m.angle);return Math.round((e==="x"?u:b)*100)/100}),[n,t,e]),s=new Set(a).size===1?a[0]:"Mixed";return oU(xt,{label:e==="x"?"X":"Y",elements:o,dragInputCallback:eU,value:s,property:e,scene:r,appState:i})},o0=tU;import{clamp as jl,pointFrom as Np,pointRotateRads as pS,round as mS}from"@orangecatai/math";import{getFlipAdjustedCropPosition as nU,getUncroppedWidthAndHeight as rU}from"@orangecatai/element";import{isImageElement as uS}from"@orangecatai/element";import{jsx as sU}from"react/jsx-runtime";var iU=({accumulatedChange:e,instantChange:o,originalElements:t,originalElementsMap:n,shouldChangeByStepSize:r,nextValue:i,property:a,scene:s,originalAppState:l,app:c})=>{let m=s.getNonDeletedElementsMap(),p=t[0],[d,u]=[p.x+p.width/2,p.y+p.height/2],[b,g]=pS(Np(p.x,p.y),Np(d,u),p.angle);if(l.croppingElementId===p.id){let v=m.get(p.id);if(!v||!uS(v)||!v.crop)return;let T=v.crop,C=T,M=v.scale[0]===-1,S=v.scale[1]===-1,{width:D,height:_}=rU(v);if(i!==void 0){if(a==="x"){let z=i*(T.naturalWidth/D);M?C={...T,x:jl(T.naturalWidth-z-T.width,0,T.naturalWidth-T.width)}:C={...T,x:jl(i*(T.naturalWidth/D),0,T.naturalWidth-T.width)}}a==="y"&&(C={...T,y:jl(i*(T.naturalHeight/_),0,T.naturalHeight-T.height)}),s.mutateElement(v,{crop:C});return}let P=(a==="x"?o:0)*(M?-1:1),A=(a==="y"?o:0)*(S?-1:1);C={...T,x:jl(T.x+P,0,T.naturalWidth-T.width),y:jl(T.y+A,0,T.naturalHeight-T.height)},s.mutateElement(v,{crop:C});return}if(i!==void 0){ki(a==="x"?i:b,a==="y"?i:g,p,s,c.state,n);return}let E=a==="x"?e:0,w=a==="y"?e:0,x=a==="x"?Math.round(r?Ve(p.x+E,Zl):b+E):b,y=a==="y"?Math.round(r?Ve(p.y+w,Zl):g+w):g;ki(x,y,p,s,c.state,n)},aU=({property:e,element:o,elementsMap:t,scene:n,appState:r})=>{let[i,a]=pS(Np(o.x,o.y),Np(o.x+o.width/2,o.y+o.height/2),o.angle),s=mS(e==="x"?i:a,2);if(r.croppingElementId===o.id&&uS(o)&&o.crop){let l=nU(o);l&&(s=mS(e==="x"?l.x:l.y,2))}return sU(xt,{label:e==="x"?"X":"Y",elements:[o],dragInputCallback:iU,scene:n,value:s,property:e,appState:r})},n0=aU;import{Fragment as a0,jsx as re,jsxs as Kt}from"react/jsx-runtime";var fU=50,ql=e=>{let o=Zo(),t=e.app.scene.getSceneNonce()||1,n=e.app.scene.getSelectedElements({selectedElementIds:o.selectedElementIds,includeBoundTextElement:!1}),r=br(e.app);return re(bU,{...e,appState:o,sceneNonce:t,selectedElements:n,gridModeEnabled:r})},He=({children:e,columns:o=1,heading:t,style:n,...r})=>re("div",{className:lU("exc-stats__row",{"exc-stats__row--heading":t}),style:{gridTemplateColumns:`repeat(${o}, 1fr)`,...n},...r,children:e});He.displayName="StatsRow";var Fp=({children:e,order:o,style:t,...n})=>re("div",{className:"exc-stats__rows",style:{order:o,...t},...n,children:e});Fp.displayName="StatsRows";ql.StatsRow=He;ql.StatsRows=Fp;var bU=mU(({app:e,onClose:o,renderCustomStats:t,selectedElements:n,appState:r,sceneNonce:i,gridModeEnabled:a})=>{let s=e.scene,l=s.getNonDeletedElements(),c=s.getNonDeletedElementsMap(),m=be(),p=n.length===1?n[0]:null,d=n.length>1?n:null,u=r.croppingElementId&&i0(p),b=u?uU(p):null,[g,E]=dU({width:0,height:0}),w=r0(()=>cU(v=>{let T=pU(v);E({width:Math.round(T[2])-Math.round(T[0]),height:Math.round(T[3])-Math.round(T[1])})},fU),[]);hS(()=>{w(l)},[i,l,w]),hS(()=>()=>w.cancel(),[w]);let x=r0(()=>ss(n,r),[n,r]),y=r0(()=>gU(n),[n]);return re("div",{className:"exc-stats",children:Kt(qe,{padding:3,children:[Kt("div",{className:"title",children:[re("h2",{children:h("stats.title")}),re("div",{className:"close",onClick:o,children:io})]}),Kt(js,{label:re("h3",{children:h("stats.generalStats")}),open:!!(r.stats.panels&Bp.generalStats),openTrigger:()=>m(v=>({stats:{open:!0,panels:v.stats.panels^Bp.generalStats}})),children:[Kt(Fp,{children:[re(He,{heading:!0,children:h("stats.scene")}),Kt(He,{columns:2,children:[re("div",{children:h("stats.shapes")}),re("div",{children:l.length})]}),Kt(He,{columns:2,children:[re("div",{children:h("stats.width")}),re("div",{children:g.width})]}),Kt(He,{columns:2,children:[re("div",{children:h("stats.height")}),re("div",{children:g.height})]}),a&&Kt(a0,{children:[re(He,{heading:!0,children:"Canvas"}),re(He,{children:re(UC,{property:"gridStep",scene:s,appState:r,setAppState:m})})]})]}),t?.(l,r)]}),!y&&n.length>0&&re("div",{id:"elementStats",style:{marginTop:12},children:re(js,{label:re("h3",{children:h("stats.elementProperties")}),open:!!(r.stats.panels&Bp.elementProperties),openTrigger:()=>m(v=>({stats:{open:!0,panels:v.stats.panels^Bp.elementProperties}})),children:Kt(Fp,{children:[p&&Kt(a0,{children:[u&&re(He,{heading:!0,children:h("labels.unCroppedDimension")}),r.croppingElementId&&i0(p)&&b&&Kt(He,{columns:2,children:[re("div",{children:h("stats.width")}),re("div",{children:gS(b.width,2)})]}),r.croppingElementId&&i0(p)&&b&&Kt(He,{columns:2,children:[re("div",{children:h("stats.height")}),re("div",{children:gS(b.height,2)})]}),re(He,{heading:!0,"data-testid":"stats-element-type",style:{margin:"0.3125rem 0"},children:r.croppingElementId?h("labels.imageCropping"):h(`element.${p.type}`)}),re(He,{children:re(n0,{element:p,property:"x",elementsMap:c,scene:s,appState:r})}),re(He,{children:re(n0,{element:p,property:"y",elementsMap:c,scene:s,appState:r})}),re(He,{children:re(j1,{property:"width",element:p,scene:s,appState:r})}),re(He,{children:re(j1,{property:"height",element:p,scene:s,appState:r})}),re(He,{children:re(HC,{property:"angle",element:p,scene:s,appState:r})}),re(He,{children:re(qC,{property:"fontSize",element:p,scene:s,appState:r})})]}),d&&Kt(a0,{children:[hU(d)&&re(He,{heading:!0,children:h("element.group")}),Kt(He,{columns:2,style:{margin:"0.3125rem 0"},children:[re("div",{children:h("stats.shapes")}),re("div",{children:n.length})]}),re(He,{children:re(o0,{property:"x",elements:d,elementsMap:c,atomicUnits:x,scene:s,appState:r})}),re(He,{children:re(o0,{property:"y",elements:d,elementsMap:c,atomicUnits:x,scene:s,appState:r})}),re(He,{children:re(e0,{property:"width",elements:d,elementsMap:c,atomicUnits:x,scene:s,appState:r})}),re(He,{children:re(e0,{property:"height",elements:d,elementsMap:c,atomicUnits:x,scene:s,appState:r})}),re(He,{children:re(oS,{property:"angle",elements:d,scene:s,appState:r})}),re(He,{children:re(dS,{property:"fontSize",elements:d,scene:s,appState:r,elementsMap:c})})]})]})})})]})})},(e,o)=>e.sceneNonce===o.sceneNonce&&e.selectedElements===o.selectedElements&&e.appState.stats.panels===o.appState.stats.panels&&e.gridModeEnabled===o.gridModeEnabled&&e.appState.gridStep===o.appState.gridStep&&e.appState.croppingElementId===o.appState.croppingElementId);import{useCallback as xU,useEffect as fS,useState as bS}from"react";import{normalizeLink as EU,KEYS as s0}from"@orangecatai/common";import{defaultGetElementLinkFromSelection as yU,getLinkIdAndTypeFromSelection as wU}from"@orangecatai/element";import{jsx as ds,jsxs as Op}from"react/jsx-runtime";var vU=({sourceElementId:e,onClose:o,appState:t,scene:n,generateLinkForSelection:r=yU})=>{let i=n.getNonDeletedElementsMap(),a=i.get(e)?.link??null,[s,l]=bS(a),[c,m]=bS(!1);fS(()=>{let d=ne(i,t),u=a;if(d.length>0&&r){let b=wU(d,t);b&&(u=EU(r(b.id,b.type)))}l(u)},[i,t,t.selectedElementIds,a,r]);let p=xU(()=>{if(s&&s!==i.get(e)?.link){let d=i.get(e);d&&n.mutateElement(d,{link:s})}if(!s&&c&&e){let d=i.get(e);d&&n.mutateElement(d,{link:null})}o?.()},[e,s,i,c,n,o]);return fS(()=>{let d=u=>{t.openDialog?.name==="elementLinkSelector"&&u.key===s0.ENTER&&p(),t.openDialog?.name==="elementLinkSelector"&&u.key===s0.ESCAPE&&o?.()};return window.addEventListener("keydown",d),()=>{window.removeEventListener("keydown",d)}},[t,o,p]),Op("div",{className:"ElementLinkDialog",children:[Op("div",{className:"ElementLinkDialog__header",children:[ds("h2",{children:h("elementLink.title")}),ds("p",{children:h("elementLink.desc")})]}),Op("div",{className:"ElementLinkDialog__input",children:[ds(ur,{value:s??"",onChange:d=>{c||m(!0),l(d)},onKeyDown:d=>{d.key===s0.ENTER&&p()},className:"ElementLinkDialog__input-field",selectOnRender:!0}),a&&s&&ds(Q,{type:"button",title:h("buttons.remove"),"aria-label":h("buttons.remove"),label:h("buttons.remove"),onClick:()=>{l(null),m(!0)},className:"ElementLinkDialog__remove",icon:yt})]}),Op("div",{className:"ElementLinkDialog__actions",children:[ds(An,{label:h("buttons.cancel"),onClick:()=>{o?.()},style:{marginRight:10}}),ds(An,{label:h("buttons.confirm"),onClick:p,actionType:"primary"})]})]})},xS=vU;import TU,{useState as IU}from"react";import{Fragment as CU,jsx as l0}from"react/jsx-runtime";var ES=({children:e,onClose:o})=>{let[t,n]=IU(!!e),{container:r}=Oe(),i=TU.useCallback(()=>{n(!1),o&&o(),r?.focus()},[o,r]);return l0(CU,{children:t&&l0(Qe,{size:"small",onCloseRequest:i,title:h("errorDialog.title"),children:l0("div",{style:{whiteSpace:"pre-wrap"},children:e})})})};import SU from"react";import{isDarwin as yS,isFirefox as wS,isWindows as kU}from"@orangecatai/common";import{KEYS as je}from"@orangecatai/common";import{Fragment as TS,jsx as W,jsxs as no}from"react/jsx-runtime";var MU=()=>no("div",{className:"HelpDialog__header",children:[no("a",{className:"HelpDialog__btn",href:"https://docs.excalidraw.com",target:"_blank",rel:"noopener",children:[W("div",{className:"HelpDialog__link-icon",children:wu}),h("helpDialog.documentation")]}),no("a",{className:"HelpDialog__btn",href:"https://plus.excalidraw.com/blog",target:"_blank",rel:"noopener",children:[W("div",{className:"HelpDialog__link-icon",children:wu}),h("helpDialog.blog")]}),no("a",{className:"HelpDialog__btn",href:"https://github.com/excalidraw/excalidraw/issues",target:"_blank",rel:"noopener noreferrer",children:[W("div",{className:"HelpDialog__link-icon",children:Rc}),h("helpDialog.github")]}),no("a",{className:"HelpDialog__btn",href:"https://youtube.com/@excalidraw",target:"_blank",rel:"noopener noreferrer",children:[W("div",{className:"HelpDialog__link-icon",children:AE}),"YouTube"]})]}),PU=e=>no(TS,{children:[W("h3",{children:e.title}),W("div",{className:"HelpDialog__islands-container",children:e.children})]}),c0=e=>no("div",{className:`HelpDialog__island ${e.className}`,children:[W("h4",{className:"HelpDialog__island-title",children:e.caption}),W("div",{className:"HelpDialog__island-content",children:e.children})]});function*LU(e,o){let t=!0;for(let n of e)t||(yield o),t=!1,yield n}var AU=e=>e.replace(/\b[a-z]\b/,o=>o.toUpperCase()),$=({label:e,shortcuts:o,isOr:t=!0})=>{let n=o.map(r=>(r.endsWith("++")?[...r.slice(0,-2).split("+"),"+"]:r.split("+")).map(a=>W(DU,{children:AU(a)},a)));return no("div",{className:"HelpDialog__shortcut",children:[W("div",{children:e}),W("div",{className:"HelpDialog__key-container",children:[...LU(n,t?h("helpDialog.or"):null)]})]})},DU=e=>W("kbd",{className:"HelpDialog__key",...e}),vS=({onClose:e})=>{let o=SU.useCallback(()=>{e&&e()},[e]);return W(TS,{children:no(Qe,{onCloseRequest:o,title:h("helpDialog.title"),className:"HelpDialog",children:[W(MU,{}),no(PU,{title:h("helpDialog.shortcuts"),children:[no(c0,{className:"HelpDialog__island--tools",caption:h("helpDialog.tools"),children:[W($,{label:h("toolBar.hand"),shortcuts:[je.H]}),W($,{label:h("toolBar.selection"),shortcuts:[je.V,je[1]]}),W($,{label:h("toolBar.rectangle"),shortcuts:[je.R,je[2]]}),W($,{label:h("toolBar.diamond"),shortcuts:[je.D,je[3]]}),W($,{label:h("toolBar.ellipse"),shortcuts:[je.O,je[4]]}),W($,{label:h("toolBar.arrow"),shortcuts:[je.A,je[5]]}),W($,{label:h("toolBar.line"),shortcuts:[je.L,je[6]]}),W($,{label:h("toolBar.freedraw"),shortcuts:[je.P,je[7]]}),W($,{label:h("toolBar.text"),shortcuts:[je.T,je[8]]}),W($,{label:h("toolBar.image"),shortcuts:[je[9]]}),W($,{label:h("toolBar.eraser"),shortcuts:[je.E,je[0]]}),W($,{label:h("toolBar.frame"),shortcuts:[je.F]}),W($,{label:h("toolBar.laser"),shortcuts:[je.K]}),W($,{label:h("labels.eyeDropper"),shortcuts:[je.I,"Shift+S","Shift+G"]}),W($,{label:h("helpDialog.editLineArrowPoints"),shortcuts:[N("CtrlOrCmd+Enter")]}),W($,{label:h("helpDialog.editText"),shortcuts:[N("Enter")]}),W($,{label:h("helpDialog.textNewLine"),shortcuts:[N("Enter"),N("Shift+Enter")]}),W($,{label:h("helpDialog.textFinish"),shortcuts:[N("Esc"),N("CtrlOrCmd+Enter")]}),W($,{label:h("helpDialog.curvedArrow"),shortcuts:["A",h("helpDialog.click"),h("helpDialog.click"),h("helpDialog.click")],isOr:!1}),W($,{label:h("helpDialog.curvedLine"),shortcuts:["L",h("helpDialog.click"),h("helpDialog.click"),h("helpDialog.click")],isOr:!1}),W($,{label:h("helpDialog.cropStart"),shortcuts:[h("helpDialog.doubleClick"),N("Enter")],isOr:!0}),W($,{label:h("helpDialog.cropFinish"),shortcuts:[N("Enter"),N("Escape")],isOr:!0}),W($,{label:h("toolBar.lock"),shortcuts:[je.Q]}),W($,{label:h("helpDialog.preventBinding"),shortcuts:[N("CtrlOrCmd")]}),W($,{label:h("toolBar.link"),shortcuts:[N("CtrlOrCmd+K")]}),W($,{label:h("toolBar.convertElementType"),shortcuts:["Tab","Shift+Tab"],isOr:!0})]}),no(c0,{className:"HelpDialog__island--view",caption:h("helpDialog.view"),children:[W($,{label:h("buttons.zoomIn"),shortcuts:[N("CtrlOrCmd++")]}),W($,{label:h("buttons.zoomOut"),shortcuts:[N("CtrlOrCmd+-")]}),W($,{label:h("buttons.resetZoom"),shortcuts:[N("CtrlOrCmd+0")]}),W($,{label:h("helpDialog.zoomToFit"),shortcuts:["Shift+1"]}),W($,{label:h("helpDialog.zoomToSelection"),shortcuts:["Shift+2"]}),W($,{label:h("helpDialog.movePageUpDown"),shortcuts:["PgUp/PgDn"]}),W($,{label:h("helpDialog.movePageLeftRight"),shortcuts:["Shift+PgUp/PgDn"]}),W($,{label:h("buttons.zenMode"),shortcuts:[N("Alt+Z")]}),W($,{label:h("buttons.objectsSnapMode"),shortcuts:[N("Alt+S")]}),W($,{label:h("labels.toggleGrid"),shortcuts:[N("CtrlOrCmd+'")]}),W($,{label:h("labels.viewMode"),shortcuts:[N("Alt+R")]}),W($,{label:h("labels.toggleTheme"),shortcuts:[N("Alt+Shift+D")]}),W($,{label:h("stats.fullTitle"),shortcuts:[N("Alt+/")]}),W($,{label:h("search.title"),shortcuts:[Be("searchMenu")]}),W($,{label:h("commandPalette.title"),shortcuts:wS?[Be("commandPalette")]:[Be("commandPalette"),Be("commandPalette",1)]})]}),no(c0,{className:"HelpDialog__island--editor",caption:h("helpDialog.editor"),children:[W($,{label:h("helpDialog.createFlowchart"),shortcuts:[N("CtrlOrCmd+Arrow Key")],isOr:!0}),W($,{label:h("helpDialog.navigateFlowchart"),shortcuts:[N("Alt+Arrow Key")],isOr:!0}),W($,{label:h("labels.moveCanvas"),shortcuts:[N(`Space+${h("helpDialog.drag")}`),N(`Wheel+${h("helpDialog.drag")}`)],isOr:!0}),W($,{label:h("buttons.clearReset"),shortcuts:[N("CtrlOrCmd+Delete")]}),W($,{label:h("labels.delete"),shortcuts:[N("Delete")]}),W($,{label:h("labels.cut"),shortcuts:[N("CtrlOrCmd+X")]}),W($,{label:h("labels.copy"),shortcuts:[N("CtrlOrCmd+C")]}),W($,{label:h("labels.paste"),shortcuts:[N("CtrlOrCmd+V")]}),W($,{label:h("labels.pasteAsPlaintext"),shortcuts:[N("CtrlOrCmd+Shift+V")]}),W($,{label:h("labels.selectAll"),shortcuts:[N("CtrlOrCmd+A")]}),W($,{label:h("labels.multiSelect"),shortcuts:[N(`Shift+${h("helpDialog.click")}`)]}),W($,{label:h("helpDialog.deepSelect"),shortcuts:[N(`CtrlOrCmd+${h("helpDialog.click")}`)]}),W($,{label:h("helpDialog.deepBoxSelect"),shortcuts:[N(`CtrlOrCmd+${h("helpDialog.drag")}`)]}),(ha||wS)&&W($,{label:h("labels.copyAsPng"),shortcuts:[N("Shift+Alt+C")]}),W($,{label:h("labels.copyStyles"),shortcuts:[N("CtrlOrCmd+Alt+C")]}),W($,{label:h("labels.pasteStyles"),shortcuts:[N("CtrlOrCmd+Alt+V")]}),W($,{label:h("labels.sendToBack"),shortcuts:[yS?N("CtrlOrCmd+Alt+["):N("CtrlOrCmd+Shift+[")]}),W($,{label:h("labels.bringToFront"),shortcuts:[yS?N("CtrlOrCmd+Alt+]"):N("CtrlOrCmd+Shift+]")]}),W($,{label:h("labels.sendBackward"),shortcuts:[N("CtrlOrCmd+[")]}),W($,{label:h("labels.bringForward"),shortcuts:[N("CtrlOrCmd+]")]}),W($,{label:h("labels.alignTop"),shortcuts:[N("CtrlOrCmd+Shift+Up")]}),W($,{label:h("labels.alignBottom"),shortcuts:[N("CtrlOrCmd+Shift+Down")]}),W($,{label:h("labels.alignLeft"),shortcuts:[N("CtrlOrCmd+Shift+Left")]}),W($,{label:h("labels.alignRight"),shortcuts:[N("CtrlOrCmd+Shift+Right")]}),W($,{label:h("labels.duplicateSelection"),shortcuts:[N("CtrlOrCmd+D"),N(`Alt+${h("helpDialog.drag")}`)]}),W($,{label:h("helpDialog.toggleElementLock"),shortcuts:[N("CtrlOrCmd+Shift+L")]}),W($,{label:h("buttons.undo"),shortcuts:[N("CtrlOrCmd+Z")]}),W($,{label:h("buttons.redo"),shortcuts:kU?[N("CtrlOrCmd+Y"),N("CtrlOrCmd+Shift+Z")]:[N("CtrlOrCmd+Shift+Z")]}),W($,{label:h("labels.group"),shortcuts:[N("CtrlOrCmd+G")]}),W($,{label:h("labels.ungroup"),shortcuts:[N("CtrlOrCmd+Shift+G")]}),W($,{label:h("labels.flipHorizontal"),shortcuts:[N("Shift+H")]}),W($,{label:h("labels.flipVertical"),shortcuts:[N("Shift+V")]}),W($,{label:h("labels.showStroke"),shortcuts:[N("S")]}),W($,{label:h("labels.showBackground"),shortcuts:[N("G")]}),W($,{label:h("labels.showFonts"),shortcuts:[N("Shift+F")]}),W($,{label:h("labels.decreaseFontSize"),shortcuts:[N("CtrlOrCmd+Shift+<")]}),W($,{label:h("labels.increaseFontSize"),shortcuts:[N("CtrlOrCmd+Shift+>")]})]})]})]})})};import{CANVAS_SEARCH_TAB as _U,DEFAULT_SIDEBAR as RU}from"@orangecatai/common";import{isFlowchartNodeElement as NU,isImageElement as IS,isLinearElement as CS,isLineElement as BU,isTextBindableContainer as FU,isTextElement as OU}from"@orangecatai/element";import{isNodeInFlowchart as zU}from"@orangecatai/element";import{jsx as d0}from"react/jsx-runtime";var Me=e=>Array.isArray(e)?`<kbd>${e.map(N).join(" + ")}</kbd>`:`<kbd>${N(e)}</kbd>`,HU=({appState:e,isMobile:o,editorInterface:t,app:n})=>{let{activeTool:r,isResizing:i,isRotating:a,lastPointerDownWith:s}=e,l=e.multiElement!==null;if(e.openSidebar?.name===RU.name&&e.openSidebar.tab===_U&&e.searchMatches?.matches.length)return h("hints.dismissSearch",{shortcut:Me("Escape")});if(e.openSidebar&&!t.canFitSidebar)return null;if(Gt(e))return h("hints.eraserRevert",{shortcut:Me("Alt")});let c=n.scene.getSelectedElements(e);if(e.selectedLinearElement?.isDragging&&c[0]?.type==="arrow")return h("hints.arrowBindModifiers",{shortcut_1:Me("Ctrl"),shortcut_2:Me("Alt")});if(r.type==="arrow"||r.type==="line")return l?h("hints.linearElementMulti",{shortcut_1:Me("Escape"),shortcut_2:Me("Enter")}):r.type==="arrow"?h("hints.arrowTool",{shortcut:Me("A")}):h("hints.linearElement");if(r.type==="freedraw")return h("hints.freeDraw");if(r.type==="text")return h("hints.text");if(r.type==="embeddable")return h("hints.embeddable");if(i&&s==="mouse"&&c.length===1){let m=c[0];return CS(m)&&m.points.length===2?h("hints.lockAngle",{shortcut:Me("Shift")}):IS(m)?h("hints.resizeImage",{shortcut_1:Me("Shift"),shortcut_2:Me("Alt")}):h("hints.resize",{shortcut_1:Me("Shift"),shortcut_2:Me("Alt")})}if(a&&s==="mouse")return h("hints.rotate",{shortcut:Me("Shift")});if(c.length===1&&OU(c[0]))return h("hints.text_selected",{shortcut:Me("Enter")});if(e.editingTextElement)return h("hints.text_editing",{shortcut_1:Me("Escape"),shortcut_2:Me(["CtrlOrCmd","Enter"])});if(e.croppingElementId)return h("hints.leaveCropEditor",{shortcut_1:Me("Enter"),shortcut_2:Me("Escape")});if(c.length===1&&IS(c[0]))return h("hints.enterCropEditor",{shortcut:Me("Enter")});if(r.type==="selection"){if(e.selectionElement&&!c.length&&!e.editingTextElement&&!e.selectedLinearElement?.isEditing)return h("hints.deepBoxSelect",{shortcut:Me("CtrlOrCmd")});if(br(n)&&e.selectedElementsAreBeingDragged)return h("hints.disableSnapping",{shortcut:Me("CtrlOrCmd")});if(!c.length&&!o)return h("hints.canvasPanning",{shortcut_1:Me(h("keys.mmb")),shortcut_2:Me("Space")});if(c.length===1){if(CS(c[0]))return e.selectedLinearElement?.isEditing?e.selectedLinearElement.selectedPointsIndices?h("hints.lineEditor_pointSelected",{shortcut_1:Me("Delete"),shortcut_2:Me(["CtrlOrCmd","D"])}):h("hints.lineEditor_nothingSelected",{shortcut_1:Me("Shift"),shortcut_2:Me("Alt")}):BU(c[0])?h("hints.lineEditor_line_info",{shortcut:Me("Enter")}):h("hints.lineEditor_info",{shortcut_1:Me("CtrlOrCmd"),shortcut_2:Me(["CtrlOrCmd","Enter"])});if(!e.newElement&&!e.selectedElementsAreBeingDragged&&FU(c[0])){let m=h("hints.bindTextToElement",{shortcut:Me("Enter")}),p=h("hints.createFlowchart",{shortcut:Me(["CtrlOrCmd","\u2191\u2193"])});return NU(c[0])?zU(c[0],n.scene.getNonDeletedElementsMap())?[m,p]:[m,p]:m}}}return null},SS=({appState:e,isMobile:o,editorInterface:t,app:n})=>{let r=HU({appState:e,isMobile:o,editorInterface:t,app:n});if(!r)return null;let a=(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 d0("kbd",{children:c?c[1]:s},l)}return s});return d0("div",{className:"HintViewer",children:d0("span",{children:a})})};import{useEffect as PS,useRef as KU,useState as Ar}from"react";import{DEFAULT_EXPORT_PADDING as XU,EXPORT_IMAGE_TYPES as m0,isFirefox as $U,EXPORT_SCALES as ZU,cloneJSON as LS}from"@orangecatai/common";import{useCallback as GU,useRef as UU,useState as WU}from"react";var YU=2e3,kS=()=>{let[e,o]=WU(null),t=UU(0),n=()=>{clearTimeout(t.current),o("success"),t.current=window.setTimeout(()=>{o(null)},YU)},r=GU(()=>{o(null)},[]);return{copyStatus:e,resetCopyStatus:r,onCopy:n}};import VU from"clsx";import{jsx as MS}from"react/jsx-runtime";var Jl=({title:e,name:o,checked:t,onChange:n,disabled:r=!1})=>MS("div",{className:VU("Switch",{toggled:t,disabled:r}),children:MS("input",{name:o,id:o,title:e,type:"checkbox",checked:t,disabled:r,onChange:()=>n(!t),onKeyDown:i=>{i.key===" "&&n(!t)}})});import{jsx as Ge,jsxs as Dr}from"react/jsx-runtime";var jU=()=>Dr("div",{children:[Ge("h3",{children:h("canvasError.cannotShowPreview")}),Ge("p",{children:Ge("span",{children:h("canvasError.canvasTooBig")})}),Dr("em",{children:["(",h("canvasError.canvasTooBigTip"),")"]})]}),qU=({appStateSnapshot:e,elementsSnapshot:o,files:t,actionManager:n,onExportImage:r,name:i})=>{let a=Le(o,e),[s,l]=Ar(i),[c,m]=Ar(a),[p,d]=Ar(e.exportBackground),[u,b]=Ar(e.exportWithDarkMode),[g,E]=Ar(e.exportEmbedScene),[w,x]=Ar(e.exportScale),y=KU(null),[v,T]=Ar(null),{onCopy:C,copyStatus:M,resetCopyStatus:S}=kS();PS(()=>{S()},[s,p,u,w,g,S]);let{exportedElements:D,exportingFrame:_}=ni(o,e,c);return PS(()=>{let P=y.current;if(!P)return;let A=P.offsetWidth,z=P.offsetHeight;A&&dr({elements:D,appState:{...e,name:s,exportBackground:p,exportWithDarkMode:u,exportScale:w,exportEmbedScene:g},files:t,exportPadding:XU,maxWidthOrHeight:Math.max(A,z),exportingFrame:_}).then(V=>(T(null),Kr(V).then(()=>{P.replaceChildren(V)}).catch(G=>{throw G.name==="CANVAS_POSSIBLY_TOO_BIG"?new Error(h("canvasError.canvasTooBig")):G}))).catch(V=>{console.error(V),T(V)})},[e,t,D,_,s,p,u,w,g]),Dr("div",{className:"ImageExportModal",children:[Ge("h3",{children:h("imageExportDialog.header")}),Dr("div",{className:"ImageExportModal__preview",children:[Ge("div",{className:"ImageExportModal__preview__canvas",ref:y,children:v&&Ge(jU,{})}),Ge("div",{className:"ImageExportModal__preview__filename",children:!Ri&&Ge("input",{type:"text",className:"TextInput",value:s,style:{width:"30ch"},onChange:P=>{l(P.target.value),n.executeAction(Ug,"ui",P.target.value)}})})]}),Dr("div",{className:"ImageExportModal__settings",children:[Ge("h3",{children:h("imageExportDialog.header")}),a&&Ge(Ql,{label:h("imageExportDialog.label.onlySelected"),name:"exportOnlySelected",children:Ge(Jl,{name:"exportOnlySelected",checked:c,onChange:P=>{m(P)}})}),Ge(Ql,{label:h("imageExportDialog.label.withBackground"),name:"exportBackgroundSwitch",children:Ge(Jl,{name:"exportBackgroundSwitch",checked:p,onChange:P=>{d(P),n.executeAction(Wg,"ui",P)}})}),Ge(Ql,{label:h("imageExportDialog.label.darkMode"),name:"exportDarkModeSwitch",children:Ge(Jl,{name:"exportDarkModeSwitch",checked:u,onChange:P=>{b(P),n.executeAction(Nw,"ui",P)}})}),Ge(Ql,{label:h("imageExportDialog.label.embedScene"),tooltip:h("imageExportDialog.tooltip.embedScene"),name:"exportEmbedSwitch",children:Ge(Jl,{name:"exportEmbedSwitch",checked:g,onChange:P=>{E(P),n.executeAction(Pd,"ui",P)}})}),Ge(Ql,{label:h("imageExportDialog.label.scale"),name:"exportScale",children:Ge(pp,{name:"exportScale",value:w,onChange:P=>{x(P),n.executeAction(Rw,"ui",P)},choices:ZU.map(P=>({value:P,label:`${P}\xD7`}))})}),Dr("div",{className:"ImageExportModal__settings__buttons",children:[Ge(xo,{className:"ImageExportModal__settings__buttons__button",label:h("imageExportDialog.title.exportToPng"),onClick:()=>r(m0.png,D,{exportingFrame:_}),icon:Ou,children:h("imageExportDialog.button.exportToPng")}),Ge(xo,{className:"ImageExportModal__settings__buttons__button",label:h("imageExportDialog.title.exportToSvg"),onClick:()=>r(m0.svg,D,{exportingFrame:_}),icon:Ou,children:h("imageExportDialog.button.exportToSvg")}),(ha||$U)&&Ge(xo,{className:"ImageExportModal__settings__buttons__button",label:h("imageExportDialog.title.copyPngToClipboard"),status:M,onClick:async()=>{await r(m0.clipboard,D,{exportingFrame:_}),C()},icon:Zi,children:h("imageExportDialog.button.copyPngToClipboard")})]})]})]})},Ql=({label:e,children:o,tooltip:t,name:n})=>Dr("div",{className:"ImageExportModal__settings__setting",title:e,children:[Dr("label",{htmlFor:n,className:"ImageExportModal__settings__setting__label",children:[e,t&&Ge(qt,{label:t,long:!0,children:cE})]}),Ge("div",{className:"ImageExportModal__settings__setting__content",children:o})]}),AS=({elements:e,appState:o,files:t,actionManager:n,onExportImage:r,onCloseRequest:i,name:a})=>{let[{appStateSnapshot:s,elementsSnapshot:l}]=Ar(()=>({appStateSnapshot:LS(o),elementsSnapshot:LS(e)}));return Ge(Qe,{onCloseRequest:i,size:"wide",title:!1,children:Ge(qU,{elementsSnapshot:l,appStateSnapshot:s,files:t,actionManager:n,onExportImage:r,name:a})})};import QU from"react";import{getFrame as eW}from"@orangecatai/common";import{jsx as JU}from"react/jsx-runtime";var p0={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"}},u0=({children:e,color:o})=>JU("div",{className:"Card",style:{"--card-color":p0[o].base,"--card-color-darker":p0[o].darker,"--card-color-darkest":p0[o].darkest},children:e});import{Fragment as oW,jsx as Oo,jsxs as zp}from"react/jsx-runtime";var tW=({elements:e,appState:o,setAppState:t,files:n,actionManager:r,exportOpts:i,canvas:a,onCloseRequest:s})=>{let{onExportToBackend:l}=i;return Oo("div",{className:"ExportDialog ExportDialog--json",children:zp("div",{className:"ExportDialog-cards",children:[i.saveFileToDisk&&zp(u0,{color:"lime",children:[Oo("div",{className:"Card-icon",children:fx}),Oo("h2",{children:h("exportDialog.disk_title")}),zp("div",{className:"Card-details",children:[h("exportDialog.disk_details"),!Ri&&r.renderAction("changeProjectName")]}),Oo(Q,{className:"Card-button",type:"button",title:h("exportDialog.disk_button"),"aria-label":h("exportDialog.disk_button"),showAriaLabel:!0,onClick:()=>{r.executeAction(al,"ui")}})]}),l&&zp(u0,{color:"pink",children:[Oo("div",{className:"Card-icon",children:_s}),Oo("h2",{children:h("exportDialog.link_title")}),Oo("div",{className:"Card-details",children:h("exportDialog.link_details")}),Oo(Q,{className:"Card-button",type:"button",title:h("exportDialog.link_button"),"aria-label":h("exportDialog.link_button"),showAriaLabel:!0,onClick:async()=>{try{me("export","link",`ui (${eW()})`),await l(e,o,n),s()}catch(c){t({errorMessage:c.message})}}})]}),i.renderCustomUI&&i.renderCustomUI(e,o,n,a)]})})},DS=({elements:e,appState:o,files:t,actionManager:n,exportOpts:r,canvas:i,setAppState:a})=>{let s=QU.useCallback(()=>{a({openDialog:null})},[a]);return Oo(oW,{children:o.openDialog?.name==="jsonExport"&&Oo(Qe,{onCloseRequest:s,title:h("buttons.export"),children:Oo(tW,{elements:e,appState:o,setAppState:a,files:t,actionManager:n,onCloseRequest:s,exportOpts:r,canvas:i})})})};import nW from"clsx";import{jsx as _S,jsxs as iW}from"react/jsx-runtime";var rW="small",RS=e=>iW("label",{className:nW("ToolIcon ToolIcon__LaserPointer",`ToolIcon_size_${rW}`,{"is-mobile":e.isMobile}),title:`${e.title}`,children:[_S("input",{className:"ToolIcon_type_checkbox",type:"checkbox",name:e.name,onChange:e.onChange,checked:e.checked,"aria-label":e.title,"data-testid":"toolbar-LaserPointer"}),_S("div",{className:"ToolIcon__icon",children:$o})]});import{Fragment as FS,jsx as te,jsxs as ro}from"react/jsx-runtime";var uW=({UIOptions:e})=>ro(kt,{__fallback:!0,children:[te(kt.DefaultItems.LoadScene,{}),te(kt.DefaultItems.SaveToActiveFile,{}),e.canvasActions.export&&te(kt.DefaultItems.Export,{}),e.canvasActions.saveAsImage&&te(kt.DefaultItems.SaveAsImage,{}),te(kt.DefaultItems.SearchMenu,{}),te(kt.DefaultItems.Help,{}),te(kt.DefaultItems.ClearCanvas,{}),te(kt.Separator,{}),te(kt.Group,{title:"Excalidraw links",children:te(kt.DefaultItems.Socials,{})}),te(kt.Separator,{}),te(kt.DefaultItems.ToggleTheme,{}),te(kt.DefaultItems.ChangeCanvasBackground,{})]}),gW=()=>ro(fp,{__fallback:!0,children:[te(fp.Actions.SaveToDisk,{}),te(fp.Actions.ExportToImage,{})]}),hW=({actionManager:e,appState:o,files:t,setAppState:n,elements:r,canvas:i,onLockToggle:a,onHandToolToggle:s,onPenModeToggle:l,showExitZenModeBtn:c,renderTopLeftUI:m,renderTopRightUI:p,renderCustomStats:d,UIOptions:u,onExportImage:b,renderWelcomeScreen:g,children:E,app:w,isCollaborating:x,generateLinkForSelection:y})=>{let v=fe(),C=ut()==="compact",M=rT(),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=M.tunnelsJotai.Provider,[_,P]=ee(qn),A=()=>u.canvasActions.export?te(DS,{elements:r,appState:o,files:t,actionManager:e,exportOpts:u.canvasActions.export,canvas:i,setAppState:n}):null,z=()=>!u.canvasActions.saveAsImage||o.openDialog?.name!=="imageExport"?null:te(AS,{elements:r,appState:o,files:t,actionManager:e,onExportImage:b,onCloseRequest:()=>n({openDialog:null}),name:w.getName()}),V=()=>ro("div",{style:{position:"relative"},children:[te(M.MainMenuTunnel.Out,{}),g&&te(M.WelcomeScreenMenuHintTunnel.Out,{})]}),G=()=>{let J=C;return te(Hl,{heading:"selectedShapeActions",className:Mi("selected-shape-actions zen-mode-transition",{"transition-left":o.zenModeEnabled}),children:J?te(qe,{className:Mi("compact-shape-actions-island"),padding:0,style:{maxHeight:`${o.height-166}px`},children:te(ET,{appState:o,elementsMap:w.scene.getNonDeletedElementsMap(),renderAction:e.renderAction,app:w,setAppState:n})}):te(qe,{className:sW.SHAPE_ACTIONS_MENU,padding:2,style:{maxHeight:`${o.height-166}px`},children:te(gT,{appState:o,elementsMap:w.scene.getNonDeletedElementsMap(),renderAction:e.renderAction,app:w})})})},Y=()=>{let J=mW(o,r),Z=o.stats.open&&!o.zenModeEnabled&&!o.viewModeEnabled&&o.openDialog?.name!=="elementLinkSelector";return te(ip,{side:"top",children:ro("div",{className:"App-menu App-menu_top",children:[ro(St.Col,{gap:S.menuTopGap,className:Mi("App-menu_top__left"),children:[V(),te("div",{className:Mi("selected-shape-actions-container",{"selected-shape-actions-container--compact":C}),children:J&&G()})]}),!o.viewModeEnabled&&o.openDialog?.name!=="elementLinkSelector"&&te(Hl,{heading:"shapes",className:"shapes-section",children:le=>ro("div",{style:{position:"relative"},children:[g&&te(M.WelcomeScreenToolbarHintTunnel.Out,{}),te(St.Col,{gap:S.toolbarColGap,align:"start",children:ro(St.Row,{gap:S.toolbarRowGap,className:Mi("App-toolbar-container",{"zen-mode":o.zenModeEnabled}),children:[ro(qe,{padding:S.islandPadding,className:Mi("App-toolbar",{"zen-mode":o.zenModeEnabled,"App-toolbar--compact":C}),children:[te(SS,{appState:o,isMobile:v.formFactor==="phone",editorInterface:v,app:w}),le,ro(St.Row,{gap:S.toolbarInnerRowGap,children:[te(ap,{zenModeEnabled:o.zenModeEnabled,checked:o.penMode,onChange:()=>l(null),title:h("toolBar.penMode"),penDetected:o.penDetected}),te(FI,{checked:o.activeTool.locked,onChange:a,title:h("toolBar.lock")}),te("div",{className:"App-toolbar__divider"}),te(wT,{setAppState:n,activeTool:o.activeTool,UIOptions:u,app:w})]})]}),x&&te(qe,{style:{marginLeft:S.collabMarginLeft,alignSelf:"center",height:"fit-content"},children:te(RS,{title:h("toolBar.laser"),checked:o.activeTool.type===NS.laser,onChange:()=>w.setActiveTool({type:NS.laser}),isMobile:!0})})]})})]})}),ro("div",{className:Mi("layer-ui__wrapper__top-right zen-mode-transition",{"transition-right":o.zenModeEnabled,"layer-ui__wrapper__top-right--compact":C}),children:[o.collaborators.size>0&&te(dp,{collaborators:o.collaborators,userToFollow:o.userToFollow?.socketId||null}),p?.(v.formFactor==="phone",o),!o.viewModeEnabled&&o.openDialog?.name!=="elementLinkSelector"&&(!F||o.openSidebar?.name!==g0.name)&&te(M.DefaultSidebarTriggerTunnel.Out,{}),Z&&te(ql,{app:w,onClose:()=>{e.executeAction(cr)},renderCustomStats:d})]})]})})},R=()=>te(Ep,{__fallback:!0,onDock:J=>{me("sidebar",`toggleDock (${J?"dock":"undock"})`,`(${v.formFactor==="phone"?"mobile":"desktop"})`)}}),F=Fi(Gl),K=ro(FS,{children:[E,te(uW,{UIOptions:u}),te(Ep.Trigger,{__fallback:!0,icon:zE,title:cW(h("toolBar.library")),onToggle:J=>{J&&me("sidebar",`${g0.name} (open)`,`button (${v.formFactor==="phone"?"mobile":"desktop"})`)},tab:g0.defaultTab}),te(gW,{}),o.openDialog?.name==="ttd"&&te(Mp,{__fallback:!0}),o.isLoading&&te(op,{delay:250}),o.errorMessage&&te(ES,{onClose:()=>n({errorMessage:null}),children:o.errorMessage}),_&&v.formFactor!=="phone"&&te(ny,{colorPickerType:_.colorPickerType,onCancel:()=>{P(null)},onChange:(J,Z,le,{altKey:Ee})=>{if(!(J!=="elementBackground"&&J!=="elementStroke"))if(le.length){for(let ue of le)dW(ue,lW(r),{[Ee&&_.swapPreviewOnAlt?J==="elementBackground"?"strokeColor":"backgroundColor":J==="elementBackground"?"backgroundColor":"strokeColor"]:Z}),pW.delete(ue);w.scene.triggerUpdate()}else n(J==="elementBackground"?{currentItemBackgroundColor:Z}:{currentItemStrokeColor:Z})},onSelect:(J,Z)=>{P(le=>le?.keepOpenOnAlt&&Z.altKey?le:null),_?.onSelect?.(J,Z)}}),o.openDialog?.name==="help"&&te(vS,{onClose:()=>{n({openDialog:null})}}),te(ST,{}),o.openDialog?.name==="elementLinkSelector"&&te(xS,{sourceElementId:o.openDialog.sourceElementId,onClose:()=>{n({openDialog:null})},scene:w.scene,appState:o,generateLinkForSelection:y}),te(M.OverwriteConfirmDialogTunnel.Out,{}),z(),A(),o.pasteDialog.shown&&te(KI,{setAppState:n,appState:o,onClose:()=>n({pasteDialog:{shown:!1,data:null}})}),v.formFactor==="phone"&&te(YI,{app:w,appState:o,elements:r,actionManager:e,renderJSONExportDialog:A,renderImageExportDialog:z,setAppState:n,onHandToolToggle:s,onPenModeToggle:l,renderTopLeftUI:m,renderTopRightUI:p,renderSidebars:R,renderWelcomeScreen:g,UIOptions:u}),v.formFactor!=="phone"&&ro(FS,{children:[ro("div",{className:"layer-ui__wrapper",style:o.openSidebar&&F&&v.canFitSidebar?{width:"calc(100% - var(--right-sidebar-width))"}:{},children:[g&&te(M.WelcomeScreenCenterTunnel.Out,{}),Y(),te(qI,{appState:o,actionManager:e,showExitZenModeBtn:c,renderWelcomeScreen:g}),o.scrolledOutside&&te("button",{type:"button",className:"scroll-back-to-content",onClick:()=>{n(J=>({...Yr(r,J)}))},children:h("buttons.scrollBackToContent")})]}),R()]})]});return te(Qu.Provider,{value:o,children:te(D,{children:te(Qh.Provider,{value:M,children:K})})})},BS=e=>{let{startBoundElement:o,cursorButton:t,scrollX:n,scrollY:r,...i}=e;return i},fW=(e,o)=>{if(e.children!==o.children)return!1;let{canvas:t,appState:n,...r}=e,{canvas:i,appState:a,...s}=o;return Hp(BS(n),BS(a),{selectedElementIds:Hp,selectedGroupIds:Hp})&&Hp(r,s)},OS=aW.memo(hW,fW);import bW from"clsx";import{jsx as zS,jsxs as EW}from"react/jsx-runtime";var xW="small",Gp=e=>EW("label",{className:bW("ToolIcon ToolIcon__MagicButton",`ToolIcon_size_${xW}`,{"is-mobile":e.isMobile}),title:`${e.title}`,children:[zS("input",{className:"ToolIcon_type_checkbox",type:"checkbox",name:e.name,onChange:e.onChange,checked:e.checked,"aria-label":e.title}),zS("div",{className:"ToolIcon__icon",children:e.icon})]});import{useEffect as yW,useRef as wW}from"react";import{jsx as HS}from"react/jsx-runtime";var GS=({trails:e})=>{let o=wW(null);return yW(()=>{if(o.current)for(let t of e)t.start(o.current);return()=>{for(let t of e)t.stop()}},e),HS("div",{className:"SVGLayer",children:HS("svg",{ref:o})})};import iY,{useEffect as aY,useRef as r4}from"react";import{CURSOR_TYPE as i4,isShallowEqual as sY,sceneCoordsToViewportCoords as lY}from"@orangecatai/common";var Et=class Et{static start(o,t){let n=t({deltaTime:0,state:void 0});n&&(Et.animations.set(o,{animation:t,lastTime:0,state:n}),Et.isRunning||(Et.isRunning=!0,yi()?requestAnimationFrame(Et.tick):setTimeout(Et.tick,0)))}static tick(){if(Et.animations.size>0){for(let[o,t]of Et.animations){let n=performance.now(),r=t.lastTime===0?0:n-t.lastTime,i=t.animation({deltaTime:r,state:t.state});if(i)t.lastTime=n,t.state=i;else if(Et.animations.delete(o),Et.animations.size===0){Et.isRunning=!1;return}}yi()?requestAnimationFrame(Et.tick):setTimeout(Et.tick,0)}}static running(o){return Et.animations.has(o)}static cancel(o){Et.animations.delete(o)}};k(Et,"isRunning",!1),k(Et,"animations",new Map);var ec=Et;import{clamp as x0,pointFrom as ms,pointsEqual as MW,bezierEquation as QS,pointRotateRads as Up,pointDistance as PW}from"@orangecatai/math";import{arrayToMap as LW,BIND_MODE_TIMEOUT as tc,DEFAULT_TRANSFORM_HANDLE_SPACING as v0,FRAME_STYLE as vo,getFeatureFlag as AW,invariant as KS,THEME as _r}from"@orangecatai/common";import{deconstructDiamondElement as E0,deconstructRectanguloidElement as e4,elementCenterPoint as ps,getDiamondBaseCorners as DW,FOCUS_POINT_SIZE as _W,getOmitSidesForEditorInterface as h0,getTransformHandles as RW,getTransformHandlesFromCoords as NW,hasBoundingBox as BW,hitElementItself as FW,isArrowElement as OW,isBindableElement as t4,isElbowArrow as us,isFrameLikeElement as gs,isImageElement as XS,isLinearElement as zW,isLineElement as HW,maxBindingDistance_simple as GW,isTextElement as $S,LinearElementEditor as un}from"@orangecatai/element";import{renderSelectionElement as UW}from"@orangecatai/element";import{getElementsInGroup as y0,getSelectedGroupIds as WW,isSelectedViaGroup as YW,selectGroupsFromGivenElements as VW}from"@orangecatai/element";import{getCommonBounds as w0,getElementAbsoluteCoords as Wp}from"@orangecatai/element";import{getGlobalFixedPointForBindableElement as ZS,isFocusPointVisible as KW}from"@orangecatai/element";import{pointFrom as Mt}from"@orangecatai/math";import{THEME as vW}from"@orangecatai/common";var TW="#ff6b6b",IW="#ff0000",US=1,WS=2,YS=(e,o)=>{if(!o.snapLines.length)return;let t=o.theme===vW.LIGHT||o.zenModeEnabled?TW:IW,n=(o.zenModeEnabled?US*1.5:US)/o.zoom.value;e.save(),e.translate(o.scrollX,o.scrollY);for(let r of o.snapLines)r.type==="pointer"?(e.lineWidth=n,e.strokeStyle=t,SW(r,e,o)):r.type==="gap"?(e.lineWidth=n,e.strokeStyle=t,kW(r.points[0],r.points[1],r.direction,o,e)):r.type==="points"&&(e.lineWidth=n,e.strokeStyle=t,CW(r,e,o));e.restore()},CW=(e,o,t)=>{if(!t.zenModeEnabled){let n=e.points[0],r=e.points[e.points.length-1];wo(n,r,o)}for(let n of e.points)VS(n,t,o)},SW=(e,o,t)=>{VS(e.points[0],t,o),t.zenModeEnabled||wo(e.points[0],e.points[1],o)},VS=([e,o],t,n)=>{n.save();let r=(t.zenModeEnabled?WS*1.5:WS)/t.zoom.value;n.beginPath(),n.moveTo(e-r,o-r),n.lineTo(e+r,o+r),n.moveTo(e+r,o-r),n.lineTo(e-r,o+r),n.stroke(),n.restore()},wo=(e,o,t)=>{t.beginPath(),t.lineTo(e[0],e[1]),t.lineTo(o[0],o[1]),t.stroke()},kW=(e,o,t,n,r)=>{let i=8/n.zoom.value,a=i/2,s=i/4;if(t==="horizontal"){let l=[(e[0]+o[0])/2,e[1]];n.zenModeEnabled||wo(Mt(e[0],e[1]-i),Mt(e[0],e[1]+i),r),wo(Mt(l[0]-s,l[1]-a),Mt(l[0]-s,l[1]+a),r),wo(Mt(l[0]+s,l[1]-a),Mt(l[0]+s,l[1]+a),r),n.zenModeEnabled||(wo(Mt(o[0],o[1]-i),Mt(o[0],o[1]+i),r),wo(e,o,r))}else{let l=[e[0],(e[1]+o[1])/2];n.zenModeEnabled||wo(Mt(e[0]-i,e[1]),Mt(e[0]+i,e[1]),r),wo(Mt(l[0]-a,l[1]-s),Mt(l[0]+a,l[1]-s),r),wo(Mt(l[0]-a,l[1]+s),Mt(l[0]+a,l[1]+s),r),n.zenModeEnabled||(wo(Mt(o[0]-i,o[1]),Mt(o[0]+i,o[1]),r),wo(e,o,r))}};var XW=(e,o)=>{KS(o.selectedLinearElement,"selectedLinearElement is null");let{segmentMidPointHoveredCoords:t}=o.selectedLinearElement;KS(t,"midPointCoords is null"),e.save(),e.translate(o.scrollX,o.scrollY),T0(t,e,o),e.restore()},$W=(e,o,t)=>{let{elementId:n,hoverPointIndex:r}=o.selectedLinearElement;if(o.selectedLinearElement?.isEditing&&o.selectedLinearElement?.selectedPointsIndices?.includes(r)||o.selectedLinearElement?.isDragging)return;let i=un.getElement(n,t);if(!i)return;let a=un.getPointAtIndexGlobalCoordinates(i,r,t);e.save(),e.translate(o.scrollX,o.scrollY),T0(a,e,o),e.restore()},T0=(e,o,t)=>{o.fillStyle="rgba(105, 101, 219, 0.4)",Ss(o,e[0],e[1],un.POINT_HANDLE_SIZE/t.zoom.value,!1)},ZW=(e,o,t)=>{e.save(),e.translate(o.scrollX,o.scrollY),T0(t,e,o),e.restore()},f0=(e,o,t,n,r,i,a)=>{e.strokeStyle="#5e5ad8",e.setLineDash([]),e.fillStyle="rgba(255, 255, 255, 0.9)",r?e.fillStyle="rgba(134, 131, 226, 0.9)":i&&(e.fillStyle="rgba(177, 151, 252, 0.7)"),Ss(e,t[0],t[1],(a?n*(o.selectedLinearElement?.isEditing?1.5:2):n)/o.zoom.value,!i,!a||r)},jW=(e,o,t,n,r)=>{let i=o.element.frameId&&t.get(o.element.frameId);switch(i&&gs(i)&&(e.translate(i.x,i.y),e.beginPath(),vo.radius&&e.roundRect?e.roundRect(-1,-1,i.width+1,i.height+1,vo.radius/n.zoom.value):e.rect(-1,-1,i.width+1,i.height+1),e.clip(),e.translate(-i.x,-i.y)),o.element.type){case"magicframe":case"frame":e.save(),e.translate(o.element.x,o.element.y),e.lineWidth=vo.strokeWidth/n.zoom.value,e.strokeStyle=n.theme===_r.DARK?"rgba(3, 93, 161, 1)":"rgba(106, 189, 252, 1)",vo.radius&&e.roundRect?(e.beginPath(),e.roundRect(0,0,o.element.width,o.element.height,vo.radius/n.zoom.value),e.stroke(),e.closePath()):e.strokeRect(0,0,o.element.width,o.element.height),e.restore();break;default:e.save();let a=ps(o.element,t);switch(e.translate(a[0],a[1]),e.rotate(o.element.angle),e.translate(-a[0],-a[1]),e.translate(o.element.x,o.element.y),e.lineWidth=x0(1.75,o.element.strokeWidth,4)/Math.max(.25,n.zoom.value),e.strokeStyle=n.theme===_r.DARK?"rgba(3, 93, 161, 1)":"rgba(106, 189, 252, 1)",o.element.type){case"ellipse":e.beginPath(),e.ellipse(o.element.width/2,o.element.height/2,o.element.width/2,o.element.height/2,0,0,2*Math.PI),e.closePath(),e.stroke();break;case"diamond":{let[s,l]=E0(o.element);s.forEach(c=>{e.beginPath(),e.moveTo(c[0][0]-o.element.x,c[0][1]-o.element.y),e.lineTo(c[1][0]-o.element.x,c[1][1]-o.element.y),e.stroke()}),l.forEach(c=>{let[m,p,d,u]=c;e.beginPath(),e.moveTo(m[0]-o.element.x,m[1]-o.element.y),e.bezierCurveTo(p[0]-o.element.x,p[1]-o.element.y,d[0]-o.element.x,d[1]-o.element.y,u[0]-o.element.x,u[1]-o.element.y),e.stroke()})}break;default:{let[s,l]=e4(o.element);s.forEach(c=>{e.beginPath(),e.moveTo(c[0][0]-o.element.x,c[0][1]-o.element.y),e.lineTo(c[1][0]-o.element.x,c[1][1]-o.element.y),e.stroke()}),l.forEach(c=>{let[m,p,d,u]=c;e.beginPath(),e.moveTo(m[0]-o.element.x,m[1]-o.element.y),e.bezierCurveTo(p[0]-o.element.x,p[1]-o.element.y,d[0]-o.element.x,d[1]-o.element.y,u[0]-o.element.x,u[1]-o.element.y),e.stroke()})}break}e.restore();break}if(gs(o.element)||t4(o.element)){let a=n.selectedLinearElement,s=a?.elementId&&un.getElement(a?.elementId,t),l=r&&FW({point:r,element:o.element,elementsMap:t,threshold:0,overrideShouldTestInside:!0}),c=s&&us(s)||n.activeTool.type==="arrow"&&n.currentItemArrowType==="elbow";if(!l||c){e.save();let m=ps(o.element,t),p;if(o.element.type==="diamond"){let g=ps(o.element,t);p=DW(o.element).map(E=>{let w=QS(E,.5),x=Up(w,g,o.element.angle);return ms(x[0],x[1])})}else p=[{x:o.element.width,y:o.element.height/2},{x:o.element.width/2,y:o.element.height},{x:0,y:o.element.height/2},{x:o.element.width/2,y:0}].map(E=>{let w=ms(E.x+o.element.x,E.y+o.element.y),x=Up(w,m,o.element.angle);return ms(x[0],x[1])});let d=r&&p.reduce((g,E,w)=>{let x=PW(E,r);return w===-1||x<g.distance?{idx:w,distance:x}:g},{idx:-1,distance:1/0}),u=4/n.zoom.value,b=GW(n.zoom)+o.element.strokeWidth/2;p.forEach((g,E)=>{let w=(!l||c)&&d?.idx===E&&d.distance<=b,x=!w&&(c||E===d?.idx&&d.distance<=b*2);w?(e.fillStyle=n.theme===_r.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()):x&&(e.fillStyle=n.theme===_r.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()}}},qW=(e,o,t,n,r,i,a)=>{let s=e.state.bindMode==="orbit"&&e.bindModeHandler!==null,l=tc-(a?.runtime??(s?0:tc)),c=x0(1/tc*l,1e-4,1),m=t.strokeWidth/2,p=t.frameId&&n.get(t.frameId);switch(p&&gs(p)&&(o.translate(p.x,p.y),o.beginPath(),vo.radius&&o.roundRect?o.roundRect(-1,-1,p.width+1,p.height+1,vo.radius/r.zoom.value):o.rect(-1,-1,p.width+1,p.height+1),o.clip(),o.translate(-p.x,-p.y)),t.type){case"magicframe":case"frame":o.save(),o.translate(t.x,t.y),o.lineWidth=vo.strokeWidth/r.zoom.value,o.strokeStyle=r.theme===_r.DARK?`rgba(3, 93, 161, ${c})`:`rgba(106, 189, 252, ${c})`,vo.radius&&o.roundRect?(o.beginPath(),o.roundRect(0,0,t.width,t.height,vo.radius/r.zoom.value),o.stroke(),o.closePath()):o.strokeRect(0,0,t.width,t.height),o.restore();break;default:o.save();let u=ps(t,n),b=u[0]+r.scrollX,g=u[1]+r.scrollY;switch(o.translate(b,g),o.rotate(t.angle),o.translate(-b,-g),o.translate(t.x+r.scrollX-m,t.y+r.scrollY-m),o.lineWidth=x0(2.5,t.strokeWidth*1.75,4)/Math.max(.25,r.zoom.value),o.strokeStyle=r.theme===_r.DARK?`rgba(3, 93, 161, ${c/2})`:`rgba(106, 189, 252, ${c/2})`,t.type){case"ellipse":o.beginPath(),o.ellipse((t.width+m*2)/2,(t.height+m*2)/2,(t.width+m*2)/2,(t.height+m*2)/2,0,0,2*Math.PI),o.closePath(),o.stroke();break;case"diamond":{let[E,w]=E0(t,m);E.forEach(x=>{o.beginPath(),o.moveTo(x[0][0]-t.x+m,x[0][1]-t.y+m),o.lineTo(x[1][0]-t.x+m,x[1][1]-t.y+m),o.stroke()}),w.forEach(x=>{let[y,v,T,C]=x;o.beginPath(),o.moveTo(y[0]-t.x+m,y[1]-t.y+m),o.bezierCurveTo(v[0]-t.x+m,v[1]-t.y+m,T[0]-t.x+m,T[1]-t.y+m,C[0]-t.x+m,C[1]-t.y+m),o.stroke()})}break;default:{let[E,w]=e4(t,m);E.forEach(x=>{o.beginPath(),o.moveTo(x[0][0]-t.x+m,x[0][1]-t.y+m),o.lineTo(x[1][0]-t.x+m,x[1][1]-t.y+m),o.stroke()}),w.forEach(x=>{let[y,v,T,C]=x;o.beginPath(),o.moveTo(y[0]-t.x+m,y[1]-t.y+m),o.bezierCurveTo(v[0]-t.x+m,v[1]-t.y+m,T[0]-t.x+m,T[1]-t.y+m,C[0]-t.x+m,C[1]-t.y+m),o.stroke()})}break}o.restore();break}if(!s||(a?.runtime??0)>tc)return;let d=.5*(Math.min(t.width,t.height)/2);if(!gs(t)){o.save(),o.translate(t.x+r.scrollX,t.y+r.scrollY);let u=1/tc*l;o.strokeStyle="rgba(0, 0, 0, 0.2)",o.lineWidth=1/r.zoom.value,o.setLineDash([4/r.zoom.value,4/r.zoom.value]),o.lineDashOffset=-u*10/r.zoom.value,o.beginPath(),o.ellipse(t.width/2,t.height/2,d,d,0,0,2*Math.PI),o.stroke(),o.fillStyle="rgba(0, 0, 0, 0.04)",o.beginPath(),o.ellipse(t.width/2,t.height/2,d*(1-c),d*(1-c),0,0,2*Math.PI),o.fill(),o.restore(),o.save(),o.translate(t.x+r.scrollX,t.y+r.scrollY);let b=5/r.zoom.value,g=5/r.zoom.value,E=b+g,w;if(t.type==="diamond"){let[,x]=E0(t),y=ps(t,n);w=x.map(v=>{let T=QS(v,.5),C=Up(T,y,t.angle);return{x:C[0]-t.x,y:C[1]-t.y}})}else{let x=ps(t,n);w=[{x:t.width/2,y:0},{x:t.width,y:t.height/2},{x:t.width/2,y:t.height},{x:0,y:t.height/2}].map(v=>{let T=ms(v.x+t.x,v.y+t.y),C=Up(T,x,t.angle);return{x:C[0]-t.x,y:C[1]-t.y}})}w.forEach(x=>{o.clearRect(x.x-E,x.y-E,E*2,E*2)}),o.fillStyle=r.theme===_r.DARK?`rgba(3, 93, 161, ${c})`:`rgba(106, 189, 252, ${c})`,w.forEach(x=>{o.beginPath(),o.arc(x.x,x.y,b,0,2*Math.PI),o.fill()}),o.restore()}return{runtime:(a?.runtime??0)+i}},JW=(e,o,t,n,r,i,a)=>{if(t===null)return;if(AW("COMPLEX_BINDINGS"))return qW(e,o,t.element,n,r,i,a);o.save(),o.translate(r.scrollX,r.scrollY);let s=e.lastPointerMoveCoords?ms(e.lastPointerMoveCoords.x,e.lastPointerMoveCoords.y):null;jW(o,t,n,r,s),o.restore()},o4=(e,o,t)=>{let{angle:n,x1:r,y1:i,x2:a,y2:s,selectionColors:l,cx:c,cy:m,dashed:p,activeEmbeddable:d}=t,u=a-r,b=s-i,E=(t.padding??v0*2)/o.zoom.value,w=8/o.zoom.value,x=4/o.zoom.value;e.save(),e.translate(o.scrollX,o.scrollY),e.lineWidth=(d?4:1)/o.zoom.value;let y=l.length;for(let v=0;v<y;++v)e.strokeStyle=l[v],p&&e.setLineDash([w,x+(w+x)*(y-1)]),e.lineDashOffset=(w+x)*v,ks(e,r-E,i-E,u+E*2,b+E*2,c,m,n);e.restore()},QW=(e,o,t,n)=>{let[r,i,a,s]=Wp(t,n),l=a-r,c=s-i;e.strokeStyle="rgb(0,118,255)",e.lineWidth=vo.strokeWidth/o.zoom.value,e.save(),e.translate(o.scrollX,o.scrollY),ks(e,r,i,l,c,r+l/2,i+c/2,t.angle,!1,vo.radius/o.zoom.value),e.restore()},jS=(e,o,t,n)=>{let{colors:r=["rgb(0,118,255)"],dashed:i=!1}=n||{},a=t.filter(m=>m.groupIds.length===0),s=t.filter(m=>m.groupIds.length>0),l=m=>{let[p,d,u,b]=w0(m);return{angle:0,x1:p,x2:u,y1:d,y2:b,selectionColors:r,dashed:i,cx:p+(u-p)/2,cy:d+(b-d)/2,activeEmbeddable:!1}},c=m=>{let p=y0(t,m);return l(p)};Object.entries(VW(s,o)).filter(([m,p])=>p).map(([m,p])=>m).map(m=>c(m)).concat(a.map(m=>l([m]))).forEach(m=>o4(e,o,m))},b0=(e,o,t,n)=>{if(!o.selectedLinearElement)return;e.save(),e.translate(o.scrollX,o.scrollY),e.lineWidth=1/o.zoom.value;let r=un.getPointsGlobalCoordinates(t,n),{POINT_HANDLE_SIZE:i}=un,a=o.selectedLinearElement?.isEditing?i:i/2,s=us(t),l=HW(t);if(r.forEach((c,m)=>{if(s&&m!==0&&m!==r.length-1)return;let p=m>0&&(m!==r.length-1||!l||!t.polygon)&&MW(c,m===r.length-1?r[0]:r[m-1],2/o.zoom.value),d=!!o.selectedLinearElement?.isEditing&&!!o.selectedLinearElement?.selectedPointsIndices?.includes(m);l&&t.polygon&&!d&&m===t.points.length-1&&o.selectedLinearElement?.isEditing&&o.selectedLinearElement?.selectedPointsIndices?.includes(0)&&(d=!0),f0(e,o,c,a,d,!1,p)}),us(t)){let c=t.fixedSegments?.map(m=>m.index)||[];r.slice(0,-1).forEach((m,p)=>{un.isSegmentTooShort(t,r[p+1],r[p],p,o.zoom)||f0(e,o,ms((m[0]+r[p+1][0])/2,(m[1]+r[p+1][1])/2),i/2,!1,!c.includes(p+1),!1)})}else un.getEditorMidPoints(t,n,o).filter((m,p,d)=>m!==null&&!(us(t)&&(p===0||p===d.length-1))).forEach(m=>{(o.selectedLinearElement?.isEditing||r.length===2)&&f0(e,o,m,i/2,!1,!0,!1)});e.restore()},eY=(e,o,t,n)=>{e.save(),e.translate(o.scrollX,o.scrollY),e.strokeStyle="rgba(134, 131, 226, 0.6)",e.lineWidth=1/o.zoom.value,e.setLineDash([4/o.zoom.value,4/o.zoom.value]),e.beginPath(),e.moveTo(t[0],t[1]),e.lineTo(n[0],n[1]),e.stroke(),e.restore()},tY=(e,o,t,n,r)=>{e.save(),e.translate(o.scrollX,o.scrollY),e.strokeStyle="rgba(134, 131, 226, 0.6)",e.lineWidth=1/o.zoom.value,e.setLineDash([]),e.fillStyle=r?"rgba(134, 131, 226, 0.9)":"rgba(255, 255, 255, 0.9)",Ss(e,t[0],t[1],n/o.zoom.value,!0,!0),e.restore()},qS=({arrow:e,appState:o,type:t,context:n,elementsMap:r})=>{let i=t==="start"?e.startBinding:e.endBinding,a=i?.elementId&&r.get(i.elementId);if(!a||!t4(a)||a.isDeleted)return;let s=ZS(i.fixedPoint,a,r);if(!KW(s,e,a,r,o,t))return;let l=o.selectedLinearElement,c=!!l?.isDragging,m=t==="start"?0:e.points.length-1,p=!!l?.selectedPointsIndices?.includes(m);if(l?.hoveredFocusPointBinding===t&&!l.draggedFocusPointBinding&&ZW(n,o,s),!(p&&c)){let d=ZS(i.fixedPoint,a,r),u=l?.hoveredFocusPointBinding===t,b=un.getPointAtIndexGlobalCoordinates(e,m,r);eY(n,o,b,d),tY(n,o,d,_W/1.5,u)}},JS=(e,o,t,n,r)=>{Object.keys(n).forEach(i=>{let a=n[i];if(a!==void 0){let[s,l,c,m]=a;e.save(),e.lineWidth=1/t.zoom.value,o.selectionColor&&(e.strokeStyle=o.selectionColor),i==="rotation"?Ss(e,s+c/2,l+m/2,c/2,!0):e.roundRect?(e.beginPath(),e.roundRect(s,l,c,m,2/t.zoom.value),e.fill(),e.stroke()):ks(e,s,l,c,m,s+c/2,l+m/2,r,!0),e.restore()}})},oY=(e,o,t,n,r)=>{let[i,a,,,s,l]=Wp(n,r),c=3,m=20,p=c/t.zoom.value,d=p/2,u=s-i+p,b=l-a+p,g=Math.min(m/t.zoom.value,u),E=Math.min(m/t.zoom.value,b);e.save(),e.fillStyle=o.selectionColor,e.strokeStyle=o.selectionColor,e.lineWidth=p,[[[-u,-b],[0,d],[g,d],[d,0],[d,E]],[[u-d,-b],[d,d],[-g+d,d],[0,0],[0,E]],[[-u,b],[0,-d],[g,-d],[d,0],[d,-E]],[[u-d,b],[d,-d],[-g+d,-d],[0,0],[0,-E]]].forEach(x=>{let[[y,v],[T,C],[M,S],[D,_],[P,A]]=x;e.save(),e.translate(s,l),e.rotate(n.angle),e.beginPath(),e.moveTo(y+T,v+C),e.lineTo(y+M,v+S),e.stroke(),e.beginPath(),e.moveTo(y+D,v+_),e.lineTo(y+P,v+A),e.stroke(),e.restore()}),e.restore()},nY=(e,o,t,n)=>{o.save();let r=v0*2/t.zoom.value,i=e.width+r*2,a=e.height+r*2,s=e.x+i/2,l=e.y+a/2,c=-(i/2+r),m=-(a/2+r);o.translate(s+t.scrollX,l+t.scrollY),o.rotate(e.angle),o.lineWidth=1/t.zoom.value,o.strokeStyle=n,o.strokeRect(c,m,i,a),o.restore()},rY=({app:e,canvas:o,elementsMap:t,visibleElements:n,selectedElements:r,allElementsMap:i,scale:a,appState:s,renderConfig:l,editorInterface:c,animationState:m,deltaTime:p})=>{if(o===null)return{atLeastOneVisibleElement:!1,elementsMap:t};let[d,u]=vc(o,a),b=m,g=Tc({canvas:o,scale:a,normalizedWidth:d,normalizedHeight:u});g.save(),g.scale(s.zoom.value,s.zoom.value);let E;if(n.forEach(T=>{s.selectedLinearElement?.isEditing&&s.selectedLinearElement.elementId===T.id&&T&&(E=T)}),E&&b0(g,s,E,t),s.selectionElement&&!s.isCropping)try{UW(s.selectionElement,g,s,l.selectionColor)}catch(T){console.error(T)}if(s.editingTextElement&&$S(s.editingTextElement)){let T=i.get(s.editingTextElement.id);T&&!T.autoResize&&nY(T,g,s,l.selectionColor)}if(s.isBindingEnabled&&s.suggestedBinding?b={...m,bindingHighlight:JW(e,g,s.suggestedBinding,i,s,p,m?.bindingHighlight)}:b={...m,bindingHighlight:void 0},s.frameToHighlight&&QW(g,s,s.frameToHighlight,t),s.elementsToHighlight&&jS(g,s,s.elementsToHighlight),s.activeLockedId){let T=i.get(s.activeLockedId),C=T?[T]:y0(i,s.activeLockedId);jS(g,s,C,{colors:["#ced4da"],dashed:!0})}let w=r.some(T=>gs(T));r.length===1&&s.selectedLinearElement?.isEditing&&s.selectedLinearElement.elementId===r[0].id&&b0(g,s,r[0],t);let x=s.selectedLinearElement,y=x&&un.getElement(x.elementId,i);if(y&&(s.selectedLinearElement.isDragging||(x.segmentMidPointHoveredCoords?XW(g,s):(us(y)?x.hoverPointIndex===0||x.hoverPointIndex===y.points.length-1:x.hoverPointIndex>=0)&&$W(g,s,t)),OW(y)&&(qS({arrow:y,elementsMap:i,appState:s,context:g,type:"start"}),qS({arrow:y,elementsMap:i,appState:s,context:g,type:"end"}))),!s.multiElement&&!s.newElement&&!s.selectedLinearElement?.isEditing){let T=BW(r,s,c),C=r.length===1&&zW(r[0]);C&&s.selectedLinearElement?.elementId===r[0].id&&!r[0].locked&&b0(g,s,r[0],t);let M=l.selectionColor||"#000";if(T){let S=LW(r),D=[];for(let P of t.values()){let A=[],z=l.remoteSelectedElementIds.get(P.id);if(C&&us(P)&&(P.startBinding||P.endBinding)||(S.has(P.id)&&!YW(s,P)&&A.push(M),z&&A.push(...z.map(V=>si(V,s.collaborators.get(V))))),A.length){let[V,G,Y,R,F,K]=Wp(P,t,!0);D.push({angle:P.angle,x1:V,y1:G,x2:Y,y2:R,selectionColors:P.locked?["#ced4da"]:A,dashed:!!z||P.locked,cx:F,cy:K,activeEmbeddable:s.activeEmbeddable?.element===P&&s.activeEmbeddable.state==="active",padding:P.id===s.croppingElementId||XS(P)?0:void 0})}}let _=P=>{let A=y0(t,P),[z,V,G,Y]=w0(A);D.push({angle:0,x1:z,x2:G,y1:V,y2:Y,selectionColors:A.some(R=>R.locked)?["#ced4da"]:["#000"],dashed:!0,cx:z+(G-z)/2,cy:V+(Y-V)/2,activeEmbeddable:!1})};for(let P of WW(s))_(P);s.editingGroupId&&_(s.editingGroupId),D.forEach(P=>o4(g,s,P))}if(g.save(),g.translate(s.scrollX,s.scrollY),r.length===1){g.fillStyle="#fff";let S=RW(r[0],s.zoom,t,"mouse",h0(c));if(!s.viewModeEnabled&&T&&!$S(s.editingTextElement)&&!s.croppingElementId&&JS(g,l,s,S,r[0].angle),s.croppingElementId&&!s.isCropping){let D=t.get(s.croppingElementId);D&&XS(D)&&oY(g,l,s,D,t)}}else if(r.length>1&&!s.isRotating&&!r.some(S=>S.locked)){let S=v0*2/s.zoom.value;g.fillStyle="#fff";let[D,_,P,A]=w0(r,t),z=g.getLineDash();g.setLineDash([2/s.zoom.value]);let V=g.lineWidth;g.lineWidth=1/s.zoom.value,g.strokeStyle=M,ks(g,D-S,_-S,P-D+S*2,A-_+S*2,(D+P)/2,(_+A)/2,0),g.lineWidth=V,g.setLineDash(z);let G=NW([D,_,P,A,(D+P)/2,(_+A)/2],0,s.zoom,"mouse",w?{...h0(c),rotation:!0}:h0(c));r.some(Y=>!Y.locked)&&JS(g,l,s,G,0)}g.restore()}s.searchMatches?.matches.forEach(({id:T,focus:C,matchedLines:M})=>{let S=t.get(T);if(S){let[D,_,,,P,A]=Wp(S,t,!0);g.save(),s.theme===_r.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 z=gs(S)?s.zoom.value:1;g.translate(s.scrollX,s.scrollY),g.translate(P,A),g.rotate(S.angle),M.forEach(V=>{(V.showOnCanvas||C)&&g.fillRect(D+V.offsetX/z-P,_+V.offsetY/z-A,V.width/z,V.height/z)}),g.restore()}}),YS(g,s),g.restore(),Vw({context:g,renderConfig:l,appState:s,normalizedWidth:d,normalizedHeight:u});let v;return l.renderScrollbars&&(v=mI(t,d,u,s),g.save(),g.fillStyle=dI,g.strokeStyle="rgba(255,255,255,0.8)",[v.horizontal,v.vertical].forEach(T=>{T&&Rd(g,T.x,T.y,T.width,T.height,ho/2)}),g.restore()),{scrollBars:v,atLeastOneVisibleElement:n.length>0,elementsMap:t,animationState:b}},n4=e=>{let o=rY(e);return e.callback(o),o};import{jsx as mY}from"react/jsx-runtime";var a4="animateInteractiveScene",cY=e=>{let o=r4(!1),t=r4(null);return aY(()=>{if(!o.current){o.current=!0;return}let n=new Map,r=new Map,i=new Map,a=new Map,s=new Map;e.appState.collaborators.forEach((c,m)=>{if(c.selectedElementIds)for(let p of Object.keys(c.selectedElementIds))i.has(p)||i.set(p,[]),i.get(p).push(m);!c.pointer||c.pointer.renderCursor===!1||(c.username&&a.set(m,c.username),c.userState&&s.set(m,c.userState),r.set(m,lY({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";t.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:i,remotePointerUsernames:a,remotePointerUserStates:s,selectionColor:l,renderScrollbars:e.renderScrollbars,lastViewportPosition:e.app.lastViewportPosition},editorInterface:e.editorInterface,callback:e.renderInteractiveSceneCallback,animationState:{bindingHighlight:void 0},deltaTime:0},ec.running(a4)||ec.start(a4,({deltaTime:c,state:m})=>{let p=n4({...t.current,deltaTime:c,animationState:m}).animationState;if(p){for(let d in p)if(p[d]!==void 0)return p}})}),mY("canvas",{className:"excalidraw__canvas interactive",style:{width:e.appState.width,height:e.appState.height,cursor:e.appState.viewModeEnabled&&e.appState.activeTool.type!=="laser"?i4.GRAB:i4.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:h("labels.drawingCanvas")})},s4=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}),dY=(e,o)=>e.selectionNonce!==o.selectionNonce||e.sceneNonce!==o.sceneNonce||e.scale!==o.scale||e.elementsMap!==o.elementsMap||e.visibleElements!==o.visibleElements||e.selectedElements!==o.selectedElements||e.renderScrollbars!==o.renderScrollbars?!1:sY(s4(e.appState),s4(o.appState)),I0=iY.memo(cY,dY);import pY,{useEffect as l4,useRef as c4}from"react";import{isShallowEqual as d4}from"@orangecatai/common";import{jsx as hY}from"react/jsx-runtime";var uY=e=>{let o=c4(null),t=c4(!1);return l4(()=>{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]),l4(()=>{let n=o.current;if(!n)return;let r=e.canvas;t.current||(t.current=!0,n.replaceChildren(r),r.classList.add("excalidraw__canvas","static")),Rb({canvas:r,rc:e.rc,scale:e.scale,elementsMap:e.elementsMap,allElementsMap:e.allElementsMap,visibleElements:e.visibleElements,appState:e.appState,renderConfig:e.renderConfig},yi())}),hY("div",{className:"excalidraw__canvas-wrapper",ref:o})},m4=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}),gY=(e,o)=>e.sceneNonce!==o.sceneNonce||e.scale!==o.scale||e.elementsMap!==o.elementsMap||e.visibleElements!==o.visibleElements?!1:d4(m4(e.appState),m4(o.appState))&&d4(e.renderConfig,o.renderConfig),C0=pY.memo(uY,gY);import{useEffect as vY,useRef as TY}from"react";import{throttleRAF as fY}from"@orangecatai/common";import{getTargetFrame as bY,isInvisiblySmallElement as xY,renderElement as EY,shouldApplyFrameClip as yY}from"@orangecatai/element";var p4=({canvas:e,rc:o,newElement:t,elementsMap:n,allElementsMap:r,scale:i,appState:a,renderConfig:s})=>{if(e){let[l,c]=vc(e,i),m=Tc({canvas:e,scale:i,normalizedWidth:l,normalizedHeight:c});if(m.save(),m.scale(a.zoom.value,a.zoom.value),t&&t.type!=="selection"){if(xY(t))return;if((t.frameId||a.frameToHighlight?.id)&&a.frameRendering.enabled&&a.frameRendering.clip){let d=bY(t,n,a);d&&yY(t,d,a,n)&&Db(d,m,s,a)}EY(t,n,r,o,m,s,a)}else m.clearRect(0,0,l,c);m.restore()}},wY=fY(e=>{p4(e)},{trailing:!0}),u4=(e,o)=>{if(o){wY(e);return}p4(e)};import{jsx as CY}from"react/jsx-runtime";var IY=e=>{let o=TY(null);return vY(()=>{o.current&&u4({canvas:o.current,scale:e.scale,newElement:e.appState.newElement,elementsMap:e.elementsMap,allElementsMap:e.allElementsMap,rc:e.rc,renderConfig:e.renderConfig,appState:e.appState},yi())}),CY("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:o})},g4=IY;import{useCallback as SY,useEffect as kY,useRef as MY}from"react";import{jsx as h4,jsxs as LY}from"react/jsx-runtime";var PY=5e3,f4=({message:e,onClose:o,closable:t=!1,duration:n=PY,style:r})=>{let i=MY(0),a=n!==1/0,s=SY(()=>{a&&(i.current=window.setTimeout(()=>o(),n))},[o,n,a]);return kY(()=>{if(a)return s(),()=>clearTimeout(i.current)},[s,e,n,a]),LY("div",{className:"Toast",onMouseEnter:a?()=>clearTimeout(i?.current):void 0,onMouseLeave:a?s:void 0,style:r,children:[h4("p",{className:"Toast__message",children:e}),t&&h4(Q,{icon:io,"aria-label":"close",type:"icon",onClick:o,className:"close"})]})};import{getCommonBounds as AY,getElementsInGroup as DY,selectGroupsFromGivenElements as _Y}from"@orangecatai/element";import{sceneCoordsToViewportCoords as RY}from"@orangecatai/common";import{flushSync as NY}from"react-dom";import{jsx as FY}from"react/jsx-runtime";var BY=({app:e,activeLockedId:o})=>{let t=e.scene.getElement(o),n=t?[t]:DY(e.scene.getNonDeletedElementsMap(),o);if(n.length===0)return null;let[r,i]=AY(n),{x:a,y:s}=RY({sceneX:r,sceneY:i},e.state);return FY("div",{className:"UnlockPopup",style:{bottom:`${e.state.height+12-s+e.state.offsetTop}px`,left:`${a-e.state.offsetLeft}px`},onClick:()=>{NY(()=>{let l=_Y(n,e.state);e.setState({selectedElementIds:n.reduce((c,m)=>({...c,[m.id]:!0}),{}),selectedGroupIds:l,activeLockedId:null})}),e.actionManager.executeAction(pl)},title:h("labels.elementLock.unlock"),children:ox})},b4=BY;import{Fragment as xk,jsx as Te,jsxs as hc}from"react/jsx-runtime";var Tk=En.createContext(null),Ik=En.createContext(null),rb={formFactor:"desktop",desktopUIMode:"full",userAgent:wk(typeof navigator<"u"?navigator.userAgent:""),isTouchScreen:!1,canFitSidebar:!1,isLandscape:!0},ab=En.createContext(rb);ab.displayName="EditorInterfaceContext";var sb=En.createContext({container:null,id:null});sb.displayName="ExcalidrawContainerContext";var lb=En.createContext([]);lb.displayName="ExcalidrawElementsContext";var cb=En.createContext({...Vn(),width:0,height:0,offsetLeft:0,offsetTop:0});cb.displayName="ExcalidrawAppStateContext";var db=En.createContext(()=>{console.warn("Uninitialized ExcalidrawSetAppStateContext context!")});db.displayName="ExcalidrawSetAppStateContext";var mb=En.createContext(null);mb.displayName="ExcalidrawActionManagerContext";var ze=()=>Gr(Tk),jo=()=>Gr(Ik),fe=()=>Gr(ab),ut=()=>ou(fe()),Oe=()=>Gr(sb),Jn=()=>Gr(lb),Zo=()=>Gr(cb),be=()=>Gr(db),We=()=>Gr(mb),cc=!1,eb=0,dc=null,zr=!1,mc=!1,tb=!1,pc={horizontal:null,vertical:null},Hr=0,uc=!1,ob=new Map,nb=!1,fk=0,bk=!1,gc=null,Ce={pointers:new Map,lastCenter:null,initialDistance:null,initialScale:null},ib=class e extends En.Component{constructor(t){super(t);k(this,"canvas");k(this,"interactiveCanvas",null);k(this,"rc");k(this,"unmounted",!1);k(this,"actionManager");k(this,"editorInterface",rb);k(this,"stylesPanelMode",ou(rb));k(this,"excalidrawContainerRef",En.createRef());k(this,"scene");k(this,"fonts");k(this,"renderer");k(this,"visibleElements");k(this,"resizeObserver");k(this,"library");k(this,"libraryItemsFromStorage");k(this,"id");k(this,"store");k(this,"history");k(this,"excalidrawContainerValue");k(this,"files",{});k(this,"imageCache",new Map);k(this,"iFrameRefs",new Map);k(this,"embedsValidationStatus",new Map);k(this,"initializedEmbeds",new Set);k(this,"handleToastClose",()=>{this.setToast(null)});k(this,"elementsPendingErasure",new Set);k(this,"flowChartCreator",new eK);k(this,"flowChartNavigator",new tK);k(this,"bindModeHandler",null);k(this,"hitLinkElement");k(this,"lastPointerDownEvent",null);k(this,"lastPointerUpEvent",null);k(this,"lastPointerMoveEvent",null);k(this,"lastPointerMoveCoords",null);k(this,"previousPointerMoveCoords",null);k(this,"lastViewportPosition",{x:0,y:0});k(this,"animationFrameHandler",new Dm);k(this,"laserTrails",new jm(this.animationFrameHandler,this));k(this,"eraserTrail",new tp(this.animationFrameHandler,this));k(this,"lassoTrail",new ep(this.animationFrameHandler,this));k(this,"onChangeEmitter",new Pi);k(this,"onPointerDownEmitter",new Pi);k(this,"onPointerUpEmitter",new Pi);k(this,"onUserFollowEmitter",new Pi);k(this,"onScrollChangeEmitter",new Pi);k(this,"missingPointerEventCleanupEmitter",new Pi);k(this,"onRemoveEventListenersEmitter",new Pi);k(this,"updateEditorAtom",(t,...n)=>{let r=ot.set(t,...n);return this.triggerRender(),r});k(this,"previousHoveredBindableElement",null);k(this,"getEffectiveGridSize",()=>br(this)?this.state.gridSize:null);k(this,"handleIframeLikeElementHover",({hitElement:t,scenePointer:n,moveEvent:r})=>t&&O0(t)&&(this.state.viewModeEnabled||this.state.activeTool.type==="laser"||this.isIframeLikeElementCenter(t,r,n.x,n.y))?(Se(this.interactiveCanvas,Ke.POINTER),this.setState({activeEmbeddable:{element:t,state:"hover"}}),!0):(this.state.activeEmbeddable?.state==="hover"&&this.setState({activeEmbeddable:null}),!1));k(this,"updateEmbedValidationStatus",(t,n)=>{this.embedsValidationStatus.set(t.id,n),lc.delete(t)});k(this,"updateEmbeddables",()=>{let t=new Set,n=!1;this.scene.getNonDeletedElements().filter(r=>{if(Wn(r)){if(t.add(r.id),!this.embedsValidationStatus.has(r.id)){n=!0;let i=U0(r.link,this.props.validateEmbeddable);this.updateEmbedValidationStatus(r,i)}}else Es(r)&&t.add(r.id);return!1}),n&&this.scene.triggerUpdate(),this.iFrameRefs.forEach((r,i)=>{t.has(i)||this.iFrameRefs.delete(i)})});k(this,"getFrameNameDOMId",t=>`${this.id}-frame-name-${t.id}`);k(this,"frameNameBoundsCache",{get:t=>{let n=this.frameNameBoundsCache._cache.get(t.id);if(!n||n.zoom!==this.state.zoom.value||n.versionNonce!==t.versionNonce){let r=document.getElementById(this.getFrameNameDOMId(t));if(r){let i=r.getBoundingClientRect(),a=Ue({clientX:i.x,clientY:i.y},this.state),s=Ue({clientX:i.right,clientY:i.bottom},this.state);return n={x:a.x,y:a.y,width:s.x-a.x,height:s.y-a.y,angle:0,zoom:this.state.zoom.value,versionNonce:t.versionNonce},this.frameNameBoundsCache._cache.set(t.id,n),n}return null}return n},_cache:new Map});k(this,"resetEditingFrame",t=>{t&&this.scene.mutateElement(t,{name:t.name?.trim()||null}),this.setState({editingFrame:null})});k(this,"renderFrameNames",()=>{if(!this.state.frameRendering.enabled||!this.state.frameRendering.name)return this.state.editingFrame&&this.resetEditingFrame(null),null;let t=this.state.theme===Kp.DARK,n=this.scene.getNonDeletedFramesLikes(),r=n.length>0&&this.state.searchMatches?.focusedId&&Lt(this.scene.getElement(this.state.searchMatches.focusedId))?this.state.searchMatches.matches.find(i=>i.focus):null;return n.map(i=>{if(!K4(i,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===i.id&&this.resetEditingFrame(i),null;let{x:a,y:s}=$p({sceneX:i.x,sceneY:i.y},this.state),l=6,c,m=$V(i),p=`${Math.round(i.width)} x ${Math.round(i.height)}`;if(i.id===this.state.editingFrame){let d=m;c=Te("input",{autoFocus:!0,value:d,onChange:u=>{this.scene.mutateElement(i,{name:u.target.value})},onFocus:u=>u.target.select(),onBlur:()=>this.resetEditingFrame(i),onKeyDown:u=>{(u.key===j.ESCAPE||u.key===j.ENTER)&&this.resetEditingFrame(i)},style:{background:t?pV(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:`${To.nameFontSize}px`,transform:`translate(-${l}px, ${l}px)`,color:t?To.nameColorDarkTheme:To.nameColorLightTheme,overflow:"hidden",maxWidth:`${document.body.clientWidth-a-l}px`},size:d.length+1||1,dir:"auto",autoComplete:"off",autoCapitalize:"off",autoCorrect:"off"})}else c=hc(xk,{children:[Te("span",{children:m}),Te("span",{style:{marginLeft:8,opacity:.7,fontSize:To.nameFontSize-1},children:p})]});return Te("div",{id:this.getFrameNameDOMId(i),className:R0.FRAME_NAME,style:{position:"absolute",bottom:`${this.state.height+To.nameOffsetY-s+this.state.offsetTop}px`,left:`${a-this.state.offsetLeft}px`,zIndex:2,fontSize:To.nameFontSize,color:t?To.nameColorDarkTheme:To.nameColorLightTheme,lineHeight:To.nameLineHeight,width:"max-content",maxWidth:r?.id===i.id&&r?.focus?"none":`${i.width*this.state.zoom.value}px`,overflow:i.id===this.state.editingFrame?"visible":"hidden",whiteSpace:"nowrap",textOverflow:"ellipsis",cursor:Ke.MOVE,pointerEvents:this.state.viewModeEnabled?hs.disabled:hs.enabled},onPointerDown:d=>this.handleCanvasPointerDown(d),onWheel:d=>this.handleWheel(d),onContextMenu:this.handleCanvasContextMenu,onDoubleClick:()=>{this.setState({editingFrame:i.id})},children:c},i.id)})});k(this,"focusContainer",()=>{this.excalidrawContainerRef.current?.focus()});k(this,"getSceneElementsIncludingDeleted",()=>this.scene.getElementsIncludingDeleted());k(this,"getSceneElementsMapIncludingDeleted",()=>this.scene.getElementsMapIncludingDeleted());k(this,"getSceneElements",()=>this.scene.getNonDeletedElements());k(this,"onInsertElements",t=>{this.addElementsFromPasteOrLibrary({elements:t,position:"center",files:null})});k(this,"onExportImage",async(t,n,r)=>{me("export",t,"ui");let i=await ri(t,n,this.state,this.files,{exportBackground:this.state.exportBackground,name:this.getName(),viewBackgroundColor:this.state.viewBackgroundColor,exportingFrame:r.exportingFrame}).catch(cV).catch(a=>{console.error(a),this.setState({errorMessage:a.message})});this.state.exportEmbedScene&&i&&Cc(i)&&this.setState({fileHandle:i})});k(this,"magicGenerations",new Map);k(this,"updateMagicGeneration",({frameElement:t,data:n})=>{n.status==="pending"?this.scene.mutateElement(t,{customData:{generationData:void 0}},{informMutation:!1,isDragging:!1}):this.scene.mutateElement(t,{customData:{generationData:n}},{informMutation:!1,isDragging:!1}),this.magicGenerations.set(t.id,n),this.triggerRender()});k(this,"plugins",{});k(this,"onMagicframeToolSelect",()=>{let t=this.scene.getSelectedElements({selectedElementIds:this.state.selectedElementIds});if(t.length===0)this.setActiveTool({type:hn.magicframe}),me("ai","tool-select (empty-selection)","d2c");else{let n=t.length===1&&z0(t[0])&&t[0];if(!n&&t.some(i=>Lt(i)||i.frameId)){this.setActiveTool({type:hn.magicframe});return}me("ai","tool-select (existing selection)","d2c");let r;if(n)r=n;else{let[i,a,s,l]=bs(t),c=50;r=G4({...To,x:i-c,y:a-c,width:s-i+c*2,height:l-a+c*2,opacity:100,locked:!1}),this.scene.insertElement(r);for(let m of t)this.scene.mutateElement(m,{frameId:r.id});this.setState({selectedElementIds:{[r.id]:!0}})}this.onMagicFrameGenerate(r,"upstream")}});k(this,"onImageGeneratorSelect",()=>{let r=(this.canvas.width/window.devicePixelRatio/2-this.state.offsetLeft)/this.state.zoom.value-this.state.scrollX,i=(this.canvas.height/window.devicePixelRatio/2-this.state.offsetTop)/this.state.zoom.value-this.state.scrollY,a=z4({...To,x:r-896/2,y:i-1344/2,width:896,height:1344,opacity:100,locked:!1,backgroundColor:"#cce8f5",fillStyle:"solid",customData:{type:"image-generator"}});this.scene.insertElement(a),this.setActiveTool({type:"selection"}),this.setState({selectedElementIds:{[a.id]:!0}})});k(this,"insertGeneratedImageIntoFrame",async(t,n)=>{let r=S0(),i=N0({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(i),this.scene.mutateElement(i,{frameId:n.id}),this.addFiles([{id:r,dataURL:t,mimeType:fu(t),created:Date.now(),lastRetrieved:Date.now()}])});k(this,"insertGeneratedImageNearElement",async(t,n,r,i)=>{let s=this.scene.getNonDeletedElementsMap(),l=this.scene.getNonDeletedElements().filter(x=>x.id!==n.id),[c,m,p,d]=qp(n,s),u=[{x:p+25,y:m},{x:c,y:d+25},{x:c-r-25,y:m},{x:c,y:m-i-25}],b=(x,y)=>{let v=x+r,T=y+i,C=x-25,M=y-25,S=v+25,D=T+25;return l.some(_=>{let[P,A,z,V]=qp(_,s);return P<S&&z>C&&A<D&&V>M})},g=u.find(x=>!b(x.x,x.y))??u[0],E=S0(),w=N0({type:"image",x:g.x,y:g.y,width:r,height:i,fileId:E,status:"pending",scale:[1,1],frameId:null});this.scene.insertElement(w),this.addFiles([{id:E,dataURL:t,mimeType:fu(t),created:Date.now(),lastRetrieved:Date.now()}]),this.setState({selectedElementIds:{[w.id]:!0}})});k(this,"openEyeDropper",({type:t})=>{this.updateEditorAtom(qn,{swapPreviewOnAlt:!0,colorPickerType:t==="stroke"?"elementStroke":"elementBackground",onSelect:(n,r)=>{let i=t==="background"&&r.altKey||t==="stroke"&&!r.altKey;!this.scene.getSelectedElements(this.state).length||this.state.activeTool.type!=="selection"?i?this.syncActionResult({appState:{...this.state,currentItemStrokeColor:n},captureUpdate:Ht.IMMEDIATELY}):this.syncActionResult({appState:{...this.state,currentItemBackgroundColor:n},captureUpdate:Ht.IMMEDIATELY}):this.updateScene({elements:this.scene.getElementsIncludingDeleted().map(s=>this.state.selectedElementIds[s.id]?Fr(s,{[i?"strokeColor":"backgroundColor"]:n}):s),captureUpdate:Ht.IMMEDIATELY})},keepOpenOnAlt:!1})});k(this,"dismissLinearEditor",()=>{setTimeout(()=>{this.state.selectedLinearElement?.isEditing&&this.setState({selectedLinearElement:{...this.state.selectedLinearElement,isEditing:!1}})})});k(this,"syncActionResult",Ze(t=>{if(this.unmounted||t===!1)return;this.store.scheduleAction(t.captureUpdate);let n=!1,r=null;if(t.elements&&(this.scene.replaceAllElements(t.elements),n=!0),t.files&&(this.addMissingFiles(t.files,t.replaceFiles),this.addNewImagesToImageCache()),t.appState||r||this.state.contextMenu){let i=t?.appState?.viewModeEnabled||!1,a=t?.appState?.zenModeEnabled||!1,s=t?.appState?.theme||this.props.theme||Kp.LIGHT,l=t?.appState?.name??this.state.name,c=t?.appState?.errorMessage??this.state.errorMessage;typeof this.props.viewModeEnabled<"u"&&(i=this.props.viewModeEnabled),typeof this.props.zenModeEnabled<"u"&&(a=this.props.zenModeEnabled),r=t.appState?.editingTextElement||null,t.elements&&r&&t.elements.forEach(m=>{r?.id===m.id&&r!==m&&ck(m)&&Ho(m)&&(r=m)}),r?.isDeleted&&(r=null),this.setState(m=>{let p=t.appState||{};return{...m,...p,contextMenu:null,editingTextElement:r,viewModeEnabled:i,zenModeEnabled:a,theme:s,name:l,errorMessage:c}}),n=!0}n||this.scene.triggerUpdate()}));k(this,"onBlur",Ze(()=>{zr=!1,this.setState({isBindingEnabled:!0})}));k(this,"onUnload",()=>{this.onBlur()});k(this,"disableEvent",t=>{t.preventDefault()});k(this,"resetHistory",()=>{this.history.clear()});k(this,"resetStore",()=>{this.store.clear()});k(this,"resetScene",Ze(t=>{this.scene.replaceAllElements([]),this.setState(n=>({...Vn(),isLoading:t?.resetLoadingState?!1:n.isLoading,theme:this.state.theme})),this.resetStore(),this.resetHistory()}));k(this,"initializeScene",async()=>{"launchQueue"in window&&"LaunchParams"in window&&window.launchQueue.setConsumer(async a=>{if(!a.files.length)return;let s=a.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 t=null;try{typeof this.props.initialData=="function"?t=await this.props.initialData()||null:t=await this.props.initialData||null,t?.libraryItems&&this.library.updateLibrary({libraryItems:t.libraryItems,merge:!0}).catch(a=>{console.error(a)})}catch(a){console.error(a),t={appState:{errorMessage:a.message||"Encountered an error during importing or restoring scene data"}}}let n=Vr(t?.elements,null,{repairBindings:!0,deleteInvisibleElements:!0}),r=Bi(t?.appState,null),i=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:i.type==="image"||i.type==="lasso"||i.type==="selection"?{...i,type:r.preferredSelectionTool.type}:r.activeTool,isLoading:!1,toast:this.state.toast},t?.scrollToContent&&(r={...r,...Yr(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:t?.files,captureUpdate:Ht.NEVER}),this.clearImageShapeCache(),this.fonts.loadSceneFonts().then(a=>{this.fonts.onLoaded(a)}),Z0(window.location.href)&&this.scrollToContent(window.location.href,{animate:!1})});k(this,"getFormFactor",(t,n)=>this.props.UIOptions.getFormFactor?.(t,n)??bV(t,n));k(this,"refreshEditorInterface",()=>{let t=this.excalidrawContainerRef.current;if(!t)return;let{width:n,height:r}=t.getBoundingClientRect(),i=wV(),a=wk(typeof navigator<"u"?navigator.userAgent:""),s=this.props.UIOptions.dockedSidebarBreakpoint!=null?this.props.UIOptions.dockedSidebarBreakpoint:KY,l=_0(this.editorInterface,{desktopUIMode:i??this.editorInterface.desktopUIMode,formFactor:this.getFormFactor(n,r),userAgent:a,canFitSidebar:n>s,isLandscape:n>r});this.editorInterface=l,this.reconcileStylesPanelMode(l)});k(this,"reconcileStylesPanelMode",t=>{let n=ou(t);if(n===this.stylesPanelMode)return;let r=this.stylesPanelMode;this.stylesPanelMode=n,r!=="full"&&n==="full"&&this.setState(i=>({preferredSelectionTool:{type:"selection",initialized:!0}}))});k(this,"setDesktopUIMode",t=>{let n=vV(t);this.editorInterface=_0(this.editorInterface,{desktopUIMode:n}),this.reconcileStylesPanelMode(this.editorInterface)});k(this,"onResize",Ze(()=>{this.scene.getElementsIncludingDeleted().forEach(t=>lc.delete(t)),this.refreshEditorInterface(),this.updateDOMRect(),this.setState({})}));k(this,"onFullscreenChange",()=>{!document.fullscreenElement&&this.state.activeEmbeddable?.state==="active"&&this.setState({activeEmbeddable:null})});k(this,"renderInteractiveSceneCallback",({atLeastOneVisibleElement:t,scrollBars:n,elementsMap:r})=>{n&&(pc=n);let i=this.state.editingTextElement?!1:!t&&r.size>0;this.state.scrolledOutside!==i&&this.setState({scrolledOutside:i}),this.scheduleImageRefresh()});k(this,"onScroll",_4(()=>{let{offsetTop:t,offsetLeft:n}=this.getCanvasOffsets();this.setState(r=>r.offsetLeft===n&&r.offsetTop===t?null:{offsetTop:t,offsetLeft:n})},XY));k(this,"onCut",Ze(t=>{!this.excalidrawContainerRef.current?.contains(document.activeElement)||nc(t.target)||(this.actionManager.executeAction(Fd,"keyboard",t),t.preventDefault(),t.stopPropagation())}));k(this,"onCopy",Ze(t=>{!this.excalidrawContainerRef.current?.contains(document.activeElement)||nc(t.target)||(this.actionManager.executeAction(Ia,"keyboard",t),t.preventDefault(),t.stopPropagation())}));k(this,"onTouchStart",t=>{if(xV&&t.preventDefault(),!cc){cc=!0,t.touches.length===1&&(dc={x:t.touches[0].clientX,y:t.touches[0].clientY}),clearTimeout(eb),eb=window.setTimeout(e.resetTapTwice,$Y);return}if(cc&&t.touches.length===1&&dc){let n=t.touches[0];Rr(ie(n.clientX,n.clientY),ie(dc.x,dc.y))<=hV&&(this.lassoTrail.endPath(),this.deselectElements(),this.handleCanvasDoubleClick({clientX:n.clientX,clientY:n.clientY})),cc=!1,clearTimeout(eb)}t.touches.length===2&&this.setState({selectedElementIds:Pe({},this.state),activeEmbeddable:null})});k(this,"onTouchEnd",t=>{this.resetContextMenuTimer(),t.touches.length>0?this.setState({previousSelectedElementIds:{},selectedElementIds:Pe(this.state.previousSelectedElementIds,this.state)}):Ce.pointers.clear()});k(this,"pasteFromClipboard",Ze(async t=>{let n=!!nb,r=document.activeElement,i=this.excalidrawContainerRef.current?.contains(r);if(t&&!i)return;let a=document.elementFromPoint(this.lastViewportPosition.x,this.lastViewportPosition.y);if(t&&(!(a instanceof HTMLCanvasElement)||nc(r)))return;let s=await fa(t),l=s.getFiles(),c=await kd(s,n);if(this.props.onPaste)try{if(await this.props.onPaste(c,t)===!1)return}catch(m){console.error(m)}await this.insertClipboardContent(c,l,n),this.setActiveTool({type:this.state.preferredSelectionTool.type},!0),t?.preventDefault()}));k(this,"addElementsFromPasteOrLibrary",t=>{let n=Vr(t.elements,null,{deleteInvisibleElements:!0}),[r,i,a,s]=bs(n),l=fs(r,a)/2,c=fs(i,s)/2,m=typeof t.position=="object"?t.position.clientX:t.position==="cursor"?this.lastViewportPosition.x:this.state.width/2+this.state.offsetLeft,p=typeof t.position=="object"?t.position.clientY:t.position==="cursor"?this.lastViewportPosition.y:this.state.height/2+this.state.offsetTop,{x:d,y:u}=Ue({clientX:m,clientY:p},this.state),b=d-l,g=u-c,[E,w]=Pt(b,g,this.getEffectiveGridSize()),{duplicatedElements:x}=B0({type:"everything",elements:n.map(S=>Fr(S,{x:S.x+E-r,y:S.y+w-i})),randomizeSeed:!t.retainSeed}),y=this.scene.getElementsIncludingDeleted(),v=[...y,...x];v=this.props.onDuplicate?.(v,y)||v,rk(v,Zp(x));let C=this.getTopLayerFrameAtSceneCoords({x:d,y:u});if(C){let S=jV(x,C);K0(v,S,C,this.state)}this.scene.replaceAllElements(v),x.forEach(S=>{if(Ho(S)&&F0(S)){let D=q4(S,this.scene.getElementsMapIncludingDeleted());UV(S,D,this.scene)}}),yV&&Yn.loadElementsFonts(x).then(S=>{this.fonts.onLoaded(S)}),t.files&&this.addMissingFiles(t.files);let M=fK(x);this.store.scheduleCapture(),this.setState({...this.state,openSidebar:this.state.openSidebar&&this.editorInterface.canFitSidebar&&ot.get(Gl)?this.state.openSidebar:null,...Io({editingGroupId:null,selectedElementIds:M.reduce((S,D)=>(F0(D)||(S[D.id]=!0),S),{})},this.scene.getNonDeletedElements(),this.state,this)},()=>{t.files&&this.addNewImagesToImageCache()}),this.setActiveTool({type:this.state.preferredSelectionTool.type},!0),t.fitToContent&&this.scrollToContent(x,{fitToContent:!0,canvasOffsets:this.getEditorUIOffsets()})});k(this,"setAppState",(t,n)=>{this.setState(t,n)});k(this,"removePointer",t=>{Hr&&this.resetContextMenuTimer(),Ce.pointers.delete(t.pointerId)});k(this,"toggleLock",(t="ui")=>{this.state.activeTool.locked||me("toolbar","toggleLock",`${t} (${this.editorInterface.formFactor==="phone"?"mobile":"desktop"})`),this.setState(n=>({activeTool:{...n.activeTool,...fn(this.state,n.activeTool.locked?{type:this.state.preferredSelectionTool.type}:n.activeTool),locked:!n.activeTool.locked}}))});k(this,"updateFrameRendering",t=>{this.setState(n=>{let r=typeof t=="function"?t(n.frameRendering):t;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}}})});k(this,"togglePenMode",t=>{this.setState(n=>({penMode:t??!n.penMode,penDetected:!0}))});k(this,"onHandToolToggle",()=>{this.actionManager.executeAction(tw)});k(this,"zoomCanvas",t=>{this.setState({...Sn({viewportX:this.state.width/2+this.state.offsetLeft,viewportY:this.state.height/2+this.state.offsetTop,nextZoom:Go(t)},this.state)})});k(this,"cancelInProgressAnimation",null);k(this,"scrollToContent",(t=this.scene.getNonDeletedElements(),n)=>{if(typeof t=="string"){let l;if(Z0(t)?l=rK(t):l=t,l){let c=this.scene.getElementsFromId(l);c?.length?this.scrollToContent(c,{fitToContent:n?.fitToContent??!0,animate:n?.animate??!0}):Z0(t)&&this.setState({toast:{message:h("elementLink.notFound"),duration:3e3,closable:!0}})}return}this.cancelInProgressAnimation?.();let r=Array.isArray(t)?t:[t],i=this.state.zoom,a=this.state.scrollX,s=this.state.scrollY;if(n?.fitToContent||n?.fitToViewport){let{appState:l}=Qs({canvasOffsets:n.canvasOffsets,targetElements:r,appState:this.state,fitToViewport:!!n?.fitToViewport,viewportZoomFactor:n?.viewportZoomFactor,minZoom:n?.minZoom,maxZoom:n?.maxZoom});i=l.zoom,a=l.scrollX,s=l.scrollY}else{let l=Yr(r,this.state);a=l.scrollX,s=l.scrollY}if(n?.animate){let l=this.state.scrollX,c=this.state.scrollY,m=this.state.zoom.value,p=lV({fromValues:{scrollX:l,scrollY:c,zoom:m},toValues:{scrollX:a,scrollY:s,zoom:i.value},interpolateValue:(d,u,b,g)=>{if(g==="zoom")return d*Math.pow(u/d,dV(b))},onStep:({scrollX:d,scrollY:u,zoom:b})=>{this.setState({scrollX:d,scrollY:u,zoom:{value:b}})},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:a,scrollY:s,zoom:i})});k(this,"maybeUnfollowRemoteUser",()=>{this.state.userToFollow&&this.setState({userToFollow:null})});k(this,"translateCanvas",t=>{this.cancelInProgressAnimation?.(),this.maybeUnfollowRemoteUser(),this.setState(t)});k(this,"setToast",t=>{this.setState({toast:t})});k(this,"restoreFileFromShare",async()=>{try{let t=await caches.open("web-share-target"),n=await t.match("shared-file");if(n){let r=await n.blob(),i=new File([r],r.name||"",{type:r.type});this.loadFileToCanvas(i,null),await t.delete("shared-file"),window.history.replaceState(null,GY,window.location.pathname)}}catch(t){this.setState({errorMessage:t.message})}});k(this,"addFiles",Ze(t=>{let{addedFiles:n}=this.addMissingFiles(t);this.clearImageShapeCache(n),this.scene.triggerUpdate(),this.addNewImagesToImageCache()}));k(this,"addMissingFiles",(t,n=!1)=>{let r=n?{}:{...this.files},i={},a=Array.isArray(t)?t:Object.values(t);for(let s of a)if(!r[s.id]&&(i[s.id]=s,r[s.id]=s,s.mimeType===gn.svg))try{let l=Ub(j4(Wb(s.dataURL)),gn.svg);s.dataURL!==l&&(s.version=(s.version??1)+1,s.dataURL=l)}catch(l){console.error(l)}return this.files=r,{addedFiles:i}});k(this,"updateScene",Ze(t=>{let{elements:n,appState:r,collaborators:i,captureUpdate:a}=t;if(a){let s=n||void 0,l=r?TV({...this.store.snapshot.appState,...r}):void 0;this.store.scheduleMicroAction({action:a,elements:s,appState:l})}r&&this.setState(r),n&&this.scene.replaceAllElements(n),i&&this.setState({collaborators:i})}));k(this,"applyDeltas",(t,n)=>{let r=mk.squash(...t),i={...this.state},a=new Map(this.scene.getElementsMapIncludingDeleted());return mk.applyTo(r,a,i,n)});k(this,"mutateElement",(t,n,r=!0)=>this.scene.mutateElement(t,n,{informMutation:r,isDragging:!1}));k(this,"triggerRender",t=>{t===!0?this.scene.triggerUpdate():this.setState({})});k(this,"toggleSidebar",({name:t,tab:n,force:r})=>{let i;r===void 0?i=this.state.openSidebar?.name===t&&this.state.openSidebar?.tab===n?null:t:i=r?t:null;let a=i?{name:i}:null;return a&&n&&(a.tab=n),this.setState({openSidebar:a}),!!i});k(this,"updateCurrentCursorPosition",Ze(t=>{this.lastViewportPosition.x=t.clientX,this.lastViewportPosition.y=t.clientY}));k(this,"getEditorUIOffsets",()=>{let t=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(),i=16;return vn().rtl?{top:t+i,right:Math.max(this.state.width-(r?.left??this.state.width),0)+i,bottom:i,left:Math.max(n?.right??0,0)+i}:{top:t+i,right:Math.max(this.state.width-(n?.left??this.state.width)+i,0),bottom:i,left:Math.max(r?.right??0,0)+i}});k(this,"onKeyDown",Ze(t=>{if("Proxy"in window&&(!t.shiftKey&&/^[A-Z]$/.test(t.key)||t.shiftKey&&/^[a-z]$/.test(t.key))&&(t=new Proxy(t,{get(s,l){let c=s[l];return typeof c=="function"?c.bind(s):l==="key"?t.shiftKey?s.key.toUpperCase():s.key.toLowerCase():c}})),!R4(t.target)){if((t.key===j.ESCAPE||t.key===j.ENTER)&&this.state.croppingElementId){this.finishImageCropping();return}let s=ne(this.scene.getNonDeletedElementsMap(),this.state);if(s.length===1&&Or(s[0])&&t.key===j.ENTER){this.startImageCropping(s[0]);return}if(t.key===j.ESCAPE)this.updateEditorAtom(Do,null);else if(t.key===j.TAB&&(document.activeElement===this.excalidrawContainerRef?.current||document.activeElement?.classList.contains(R0.CONVERT_ELEMENT_TYPE_POPUP))){t.preventDefault();let c=Aa(s);ot.get(Do)?.type==="panel"&&Sh(this,{conversionType:c,direction:t.shiftKey?"left":"right"})&&this.store.scheduleCapture(),c&&this.updateEditorAtom(Do,{type:"panel"})}if(t.key===j.ESCAPE&&this.flowChartCreator.isCreatingChart){this.flowChartCreator.clear(),this.triggerRender(!0);return}let l=Yp(t.key);if(t[j.CTRL_OR_CMD]&&l&&!t.shiftKey){t.preventDefault();let c=ne(this.scene.getNonDeletedElementsMap(),this.state);c.length===1&&NV(c[0])&&this.flowChartCreator.createNodes(c[0],this.state,tk(t.key),this.scene),this.flowChartCreator.pendingNodes?.length&&!G0(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(t.altKey){let c=ne(this.scene.getNonDeletedElementsMap(),this.state);if(c.length===1&&l){t.preventDefault();let m=this.flowChartNavigator.exploreByDirection(c[0],this.scene.getNonDeletedElementsMap(),tk(t.key));if(m){this.setState(d=>({selectedElementIds:Pe({[m]:!0},d)}));let p=this.scene.getNonDeletedElementsMap().get(m);p&&!G0([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(t[j.CTRL_OR_CMD]&&t.key===j.P&&!t.shiftKey&&!t.altKey){this.setToast({message:h("commandPalette.shortcutHint",{shortcut:Be("commandPalette")})}),t.preventDefault();return}if(t[j.CTRL_OR_CMD]&&t.key.toLowerCase()===j.V&&(nb=t.shiftKey,clearTimeout(fk),fk=window.setTimeout(()=>{nb=!1},100)),t[j.CTRL_OR_CMD]&&nc(t.target)&&(t.code===I4.MINUS||t.code===I4.EQUAL)){t.preventDefault();return}if(nc(t.target)&&t.key!==j.ESCAPE||Yp(t.key)&&R4(t.target))return;if(t.key===j.QUESTION_MARK){this.setState({openDialog:{name:"help"}});return}else if(t.key.toLowerCase()===j.E&&t.shiftKey&&t[j.CTRL_OR_CMD]){t.preventDefault(),this.setState({openDialog:{name:"imageExport"}});return}if(t.key===j.PAGE_UP||t.key===j.PAGE_DOWN){let s=(t.shiftKey?this.state.width:this.state.height)/this.state.zoom.value;t.key===j.PAGE_DOWN&&(s=-s),t.shiftKey?this.translateCanvas(l=>({scrollX:l.scrollX+s})):this.translateCanvas(l=>({scrollY:l.scrollY+s}))}if(this.state.openDialog?.name==="elementLinkSelector"||(t.key===j.ALT&&(Un("COMPLEX_BINDINGS")?this.handleSkipBindMode():tu({app:this,event:t})),this.actionManager.handleKeyDown(t)))return;let n=this.props.viewModeEnabled===!0;if(!n&&this.state.viewModeEnabled&&t.key===j.ESCAPE){this.setActiveTool({type:"hand"});return}if(!n&&!t.ctrlKey&&!t.altKey&&!t.metaKey&&!this.state.newElement&&!this.state.selectionElement&&!this.state.selectedElementsAreBeingDragged){let s=nT(t.key,this);if(this.state.viewModeEnabled&&!F4(s,["laser","hand"]))return;if(s){this.state.activeTool.type!==s&&me("toolbar",s,`keyboard (${this.editorInterface.formFactor==="phone"?"mobile":"desktop"})`),s==="arrow"&&this.state.activeTool.type==="arrow"&&this.setState(l=>({currentItemArrowType:l.currentItemArrowType===Br.sharp?Br.round:l.currentItemArrowType===Br.round?Br.elbow:Br.sharp})),s==="lasso"&&this.state.activeTool.type==="laser"?this.setActiveTool({type:this.state.preferredSelectionTool.type}):this.setActiveTool({type:s}),t.stopPropagation();return}else if(t.key===j.Q){this.toggleLock("keyboard"),t.stopPropagation();return}}if(this.state.viewModeEnabled)return;if(t[j.CTRL_OR_CMD]&&this.state.isBindingEnabled&&(Un("COMPLEX_BINDINGS")&&this.resetDelayedBindMode(),Xt(()=>{this.setState({isBindingEnabled:!1})}),tu({app:this,event:t})),Yp(t.key)){let s=this.scene.getSelectedElements({selectedElementIds:this.state.selectedElementIds,includeBoundTextElement:!0,includeElementsInFrames:!0}),l=new Set;s.filter(d=>xn(d)).filter(d=>{let u=d.startBinding&&!s.some(g=>g.id===d.startBinding?.elementId),b=d.endBinding&&!s.some(g=>g.id===d.endBinding?.elementId);return u||b}).forEach(d=>l.add(d.id)),s=s.filter(d=>!l.has(d.id));let c=this.getEffectiveGridSize()&&(t.shiftKey?P4:this.getEffectiveGridSize())||(t.shiftKey?WY:P4),m=0,p=0;t.key===j.ARROW_LEFT?m=-c:t.key===j.ARROW_RIGHT?m=c:t.key===j.ARROW_UP?p=-c:t.key===j.ARROW_DOWN&&(p=c),s.forEach(d=>{this.scene.mutateElement(d,{x:d.x+m,y:d.y+p},{informMutation:!1,isDragging:!1}),Jp(d,this.scene,{simultaneouslyUpdated:s})}),this.scene.triggerUpdate(),t.preventDefault()}else if(t.key===j.ENTER){let s=this.scene.getSelectedElements(this.state);if(s.length===1){let l=s[0];if(t[j.CTRL_OR_CMD]||j0(l))zt(l)&&(!this.state.selectedLinearElement?.isEditing||this.state.selectedLinearElement.elementId!==l.id)&&(this.store.scheduleCapture(),$t(l)||this.actionManager.executeAction(Xa));else if(Ho(l)||GV(l)){let c;Ho(l)||(c=l);let m=Y0(l,this.state,this.scene.getNonDeletedElementsMap()),p=m.x,d=m.y;this.startTextEditing({sceneX:p,sceneY:d,container:c}),t.preventDefault();return}else Lt(l)&&this.setState({editingFrame:l.id})}}if(t.key===j.SPACE&&Ce.pointers.size===0&&(zr=!0,Se(this.interactiveCanvas,Ke.GRAB),t.preventDefault()),(t.key===j.G||t.key===j.S)&&!t.altKey&&!t[j.CTRL_OR_CMD]){let s=this.scene.getSelectedElements(this.state);if(this.state.activeTool.type==="selection"&&!s.length)return;t.key===j.G&&(Uo(this.state.activeTool.type)||s.some(l=>Uo(l.type)))&&(this.setState({openPopup:"elementBackground"}),t.stopPropagation()),t.key===j.S&&(this.setState({openPopup:"elementStroke"}),t.stopPropagation())}if(!t[j.CTRL_OR_CMD]&&t.shiftKey&&t.key.toLowerCase()===j.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=>Ho(l)||W0(l,this.scene.getNonDeletedElementsMap())))&&(t.preventDefault(),this.setState({openPopup:"fontFamily"}))}t[j.CTRL_OR_CMD]&&(t.key===j.BACKSPACE||t.key===j.DELETE)&&this.updateEditorAtom(mi,"clearCanvas");let r=t.key.toLocaleLowerCase(),i=r===j.S&&t.shiftKey,a=t.key===j.I||r===j.G&&t.shiftKey;(i||a)&&this.openEyeDropper({type:i?"stroke":"background"})}));k(this,"onKeyUp",Ze(t=>{if(t.key===j.SPACE&&(this.state.viewModeEnabled&&this.state.activeTool.type!=="laser"||this.state.openDialog?.name==="elementLinkSelector"?Se(this.interactiveCanvas,Ke.GRAB):jp(this.state.activeTool.type)?Jt(this.interactiveCanvas):(Qt(this.interactiveCanvas,this.state),this.setState({selectedElementIds:Pe({},this.state),selectedGroupIds:{},editingGroupId:null,activeEmbeddable:null})),zr=!1),t.key===j.ALT&&tu({app:this,event:t}),(t.key===j.ALT&&this.state.bindMode==="skip"||!t[j.CTRL_OR_CMD]&&!ic(this.state))&&(this.setState({bindMode:"orbit"}),this.lastPointerMoveEvent&&Un("COMPLEX_BINDINGS"))){let n=Ue({clientX:this.lastPointerMoveEvent.clientX,clientY:this.lastPointerMoveEvent.clientY},this.state),r=zo(ie(n.x,n.y),this.scene.getNonDeletedElements(),this.scene.getNonDeletedElementsMap());if(this.state.selectedLinearElement){let i=ve.getElement(this.state.selectedLinearElement.elementId,this.scene.getNonDeletedElementsMap());xn(i)&&this.handleDelayedBindModeChange(i,r)}}if(!t[j.CTRL_OR_CMD]&&!this.state.isBindingEnabled&&(Xt(()=>{this.setState({isBindingEnabled:!0})}),tu({app:this,event:t})),Yp(t.key)){O4(this.scene.getSelectedElements(this.state).filter(xs),this.scene,this.state);let n=this.scene.getNonDeletedElementsMap();this.scene.getSelectedElements(this.state).filter(q0).forEach(r=>{r.startBinding&&this.scene.mutateElement(r,{startBinding:{...r.startBinding,...uk(r,n.get(r.startBinding.elementId),"start",n)}}),r.endBinding&&this.scene.mutateElement(r,{endBinding:{...r.endBinding,...uk(r,n.get(r.endBinding.elementId),"end",n)}})}),this.setState({suggestedBinding:null})}if(t.altKey||this.flowChartNavigator.isExploring&&(this.flowChartNavigator.clear(),this.syncActionResult({captureUpdate:Ht.IMMEDIATELY})),!t[j.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:Pe({[n.id]:!0},r)})),G0([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:Ht.IMMEDIATELY})}}));k(this,"isToolSupported",t=>this.props.UIOptions.tools?.[t]!==!1);k(this,"setActiveTool",(t,n=!1)=>{if(!this.isToolSupported(t.type)){console.warn(`"${t.type}" tool is disabled via "UIOptions.canvasActions.tools.${t.type}"`);return}let r=fn(this.state,t);r.type==="hand"?Se(this.interactiveCanvas,Ke.GRAB):zr||Qt(this.interactiveCanvas,{...this.state,activeTool:r}),iV(document.activeElement)&&this.focusContainer(),_V(r.type)||this.setState({suggestedBinding:null}),r.type==="image"&&this.onImageToolbarButtonClick(),this.setState(i=>{let a={snapLines:i.snapLines.length?[]:i.snapLines,originSnapOffset:null,activeEmbeddable:null,selectedLinearElement:jp(r.type)?i.selectedLinearElement:null};return r.type==="freedraw"&&this.store.scheduleCapture(),r.type==="lasso"?{...i,...a,activeTool:r,...n?{}:{selectedElementIds:Pe({},i),selectedGroupIds:Pe({},i),editingGroupId:null,multiElement:null}}:r.type!=="selection"?{...i,...a,activeTool:r,selectedElementIds:Pe({},i),selectedGroupIds:Pe({},i),editingGroupId:null,multiElement:null}:{...i,...a,activeTool:r}})});k(this,"setOpenDialog",t=>{this.setState({openDialog:t})});k(this,"setCursor",t=>{Se(this.interactiveCanvas,t)});k(this,"resetCursor",()=>{Jt(this.interactiveCanvas)});k(this,"isTouchScreenMultiTouchGesture",()=>Ce.pointers.size>=2);k(this,"getName",()=>this.state.name||this.props.name||`${h("labels.untitled")}-${N4()}`);k(this,"onGestureStart",Ze(t=>{t.preventDefault(),this.isTouchScreenMultiTouchGesture()&&this.setState({selectedElementIds:Pe({},this.state),activeEmbeddable:null}),Ce.initialScale=this.state.zoom.value}));k(this,"onGestureChange",Ze(t=>{if(t.preventDefault(),this.isTouchScreenMultiTouchGesture())return;let n=Ce.initialScale;n&&this.setState(r=>({...Sn({viewportX:this.lastViewportPosition.x,viewportY:this.lastViewportPosition.y,nextZoom:Go(n*t.scale)},r)}))}));k(this,"onGestureEnd",Ze(t=>{t.preventDefault(),this.isTouchScreenMultiTouchGesture()&&this.setState({previousSelectedElementIds:{},selectedElementIds:Pe(this.state.previousSelectedElementIds,this.state)}),Ce.initialScale=null}));k(this,"startTextEditing",({sceneX:t,sceneY:n,insertAtParentCenter:r=!0,container:i,autoEdit:a=!0})=>{let s=!1,l=r&&this.getTextWysiwygSnappedToCenterPosition(t,n,this.state,i);i&&l&&(W0(i,this.scene.getNonDeletedElementsMap())||(s=!0));let c=null,m=this.scene.getSelectedElements(this.state);m.length===1?Ho(m[0])?c=m[0]:i?c=W0(m[0],this.scene.getNonDeletedElementsMap()):c=this.getTextElementAtPosition(t,n):c=this.getTextElementAtPosition(t,n);let p=c?.fontFamily||this.state.currentItemFontFamily,d=c?.lineHeight||D4(p),u=this.state.currentItemFontSize;if(!c&&s&&i&&!xs(i)){let w=lK(A0({fontSize:u,fontFamily:p}),d),x=cK(u,d),y=Math.max(i.height,x),v=Math.max(i.width,w);this.scene.mutateElement(i,{height:y,width:v}),t=i.x+v/2,n=i.y+y/2,l&&(l=this.getTextWysiwygSnappedToCenterPosition(t,n,this.state,i))}let b=this.getTopLayerFrameAtSceneCoords({x:t,y:n}),g=c||U4({x:l?l.elementCenterX:t,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?qY.MIDDLE:k4,containerId:s?i?.id:void 0,groupIds:i?.groupIds??[],lineHeight:d,angle:i?xs(i)?0:i.angle:0,frameId:b?b.id:null});if(!c&&s&&i&&this.scene.mutateElement(i,{boundElements:(i.boundElements||[]).concat({type:"text",id:g.id})}),this.setState({editingTextElement:g}),!c)if(i&&s){let E=this.scene.getElementIndex(i.id);this.scene.insertElementAtIndex(g,E+1)}else this.scene.insertElement(g);a||c||i?this.handleTextWysiwyg(g,{isExistingElement:!!c}):this.setState({newElement:g,multiElement:null})});k(this,"startImageCropping",t=>{this.store.scheduleCapture(),this.setState({croppingElementId:t.id})});k(this,"finishImageCropping",()=>{this.state.croppingElementId&&(this.store.scheduleCapture(),this.setState({croppingElementId:null}))});k(this,"handleCanvasDoubleClick",t=>{if(this.state.multiElement||this.state.activeTool.type!==this.state.preferredSelectionTool.type)return;let n=this.scene.getSelectedElements(this.state),{x:r,y:i}=Ue(t,this.state);if(n.length===1&&zt(n[0])){let s=n[0];if((t[j.CTRL_OR_CMD]&&q0(s)||j0(s))&&(!this.state.selectedLinearElement?.isEditing||this.state.selectedLinearElement.elementId!==s.id)){this.actionManager.executeAction(Xa);return}else if(this.state.selectedLinearElement&&$t(n[0])){let l=ve.getSegmentMidpointHitCoords(this.state.selectedLinearElement,{x:r,y:i},this.state,this.scene.getNonDeletedElementsMap()),c=l?ve.getSegmentMidPointIndex(this.state.selectedLinearElement,this.state,l,this.scene.getNonDeletedElementsMap()):-1;if(c&&c>-1){this.store.scheduleCapture(),ve.deleteFixedSegment(n[0],this.scene,c);let m=ve.getSegmentMidpointHitCoords({...this.state.selectedLinearElement,segmentMidPointHoveredCoords:null},{x:r,y:i},this.state,this.scene.getNonDeletedElementsMap()),p=m?ve.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&&j0(s))return}if(n.length===1&&Or(n[0])){this.startImageCropping(n[0]);return}if(Jt(this.interactiveCanvas),gK(this.state).length>0){let s=this.getElementAtPosition(r,i),l=s&&uK(s,this.state.selectedGroupIds);if(l){this.store.scheduleCapture(),this.setState(c=>({...c,...Io({editingGroupId:l,selectedElementIds:{[s.id]:!0}},this.scene.getNonDeletedElements(),c,this)}));return}}if(Jt(this.interactiveCanvas),!t[j.CTRL_OR_CMD]&&!this.state.viewModeEnabled){let s=this.getElementAtPosition(r,i);if(O0(s)){this.setState({activeEmbeddable:{element:s,state:"active"}});return}if(!this.state.selectedLinearElement?.isEditing){let l=this.getTextBindableContainerAtPosition(r,i);if(l&&(Y4(l)||!sV(l.backgroundColor)||sc({point:ie(r,i),element:l,elementsMap:this.scene.getNonDeletedElementsMap(),threshold:this.getElementHitThreshold(l)}))){let c=Y0(l,this.state,this.scene.getNonDeletedElementsMap());r=c.x,i=c.y}this.startTextEditing({sceneX:r,sceneY:i,insertAtParentCenter:!t.altKey,container:l})}}});k(this,"getElementLinkAtPosition",(t,n)=>{if(n&&n.locked)return;let r=this.scene.getNonDeletedElements(),i=-1;for(let a=r.length-1;a>=0;a--){let s=r[a];if(n&&s.id===n.id&&(i=a),s.link&&a>=i&&wc(s,this.scene.getNonDeletedElementsMap(),this.state,ie(t.x,t.y),this.editorInterface.formFactor==="phone"))return s}});k(this,"handleElementLinkClick",t=>{let n=Rr(ie(this.lastPointerDownEvent.clientX,this.lastPointerDownEvent.clientY),ie(this.lastPointerUpEvent.clientX,this.lastPointerUpEvent.clientY));if(!this.hitLinkElement||n>M4)return;let r=Ue(this.lastPointerDownEvent,this.state),i=this.scene.getNonDeletedElementsMap(),a=wc(this.hitLinkElement,i,this.state,ie(r.x,r.y),this.editorInterface.formFactor==="phone"),s=Ue(this.lastPointerUpEvent,this.state),l=wc(this.hitLinkElement,i,this.state,ie(s.x,s.y),this.editorInterface.formFactor==="phone");if(a&&l){hh();let c=this.hitLinkElement.link;if(c){c=L0(c);let m;if(this.props.onLinkOpen&&(m=aV(ce.EXCALIDRAW_LINK,t.nativeEvent),this.props.onLinkOpen({...this.hitLinkElement,link:c},m)),!m?.defaultPrevented){let p=oV(c)?"_self":"_blank",d=window.open(void 0,p);d&&(d.opener=null,d.location=c)}}}});k(this,"getTopLayerFrameAtSceneCoords",t=>{let n=this.scene.getNonDeletedElementsMap(),r=this.scene.getNonDeletedFramesLikes().filter(i=>!i.locked&&J4(t,i,n));return r.length?r[r.length-1]:null});k(this,"handleCanvasPointerMove",t=>{this.savePointer(t.clientX,t.clientY,this.state.cursorButton),this.lastPointerMoveEvent=t.nativeEvent;let n=Ue(t,this.state),{x:r,y:i}=n;this.lastPointerMoveCoords={x:r,y:i},Ce.pointers.has(t.pointerId)&&Ce.pointers.set(t.pointerId,{x:t.clientX,y:t.clientY});let a=Ce.initialScale;if(Ce.pointers.size===2&&Ce.lastCenter&&a&&Ce.initialDistance){let g=Df(Ce.pointers),E=g.x-Ce.lastCenter.x,w=g.y-Ce.lastCenter.y;Ce.lastCenter=g;let x=_f(Array.from(Ce.pointers.values())),y=this.state.activeTool.type==="freedraw"&&this.state.penMode?1:x/Ce.initialDistance,v=y?Go(a*y):this.state.zoom.value;this.setState(T=>{let C=Sn({viewportX:g.x,viewportY:g.y,nextZoom:v},T);return this.translateCanvas({zoom:C.zoom,scrollX:C.scrollX+2*(E/v),scrollY:C.scrollY+2*(w/v),shouldCacheIgnoreZoom:!0}),null}),this.resetShouldCacheIgnoreZoomDebounced()}else Ce.lastCenter=Ce.initialDistance=Ce.initialScale=null;if(zr||mc||tb||wn(this.state))return;let l=t1(pc,t.clientX-this.state.offsetLeft,t.clientY-this.state.offsetTop).isOverEither;if(!this.state.newElement&&!this.state.selectionElement&&!this.state.selectedElementsAreBeingDragged&&!this.state.multiElement&&(l?Jt(this.interactiveCanvas):Qt(this.interactiveCanvas,this.state)),!this.state.newElement&&N3(this.state.activeTool.type)){let{originOffset:g,snapLines:E}=R3(this.scene.getNonDeletedElements(),this,{x:r,y:i},t,this.scene.getNonDeletedElementsMap());this.setState(w=>{let x=rc(w.snapLines,E),y=w.originSnapOffset?rc(w.originSnapOffset,g):g;return w.snapLines===x&&w.originSnapOffset===y?null:{snapLines:x,originSnapOffset:y}})}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:ve.handlePointerMoveInEditMode(t,r,i,this);g&&g!==this.state.selectedLinearElement&&Xt(()=>{this.setState({selectedLinearElement:g})})}if(DV(this.state.activeTool.type)){let{newElement:g}=this.state;if(!g&&ic(this.state)){let E=ie(r,i),w=this.scene.getNonDeletedElementsMap(),x=zo(E,this.scene.getNonDeletedElements(),w,J0(this.state.zoom));x?this.setState({suggestedBinding:{element:x,midPoint:Q0(E,x,w,this.state.zoom)}}):this.state.suggestedBinding&&this.setState({suggestedBinding:null})}}if(this.state.multiElement&&this.state.selectedLinearElement){let{multiElement:g,selectedLinearElement:E}=this.state,{x:w,y:x,points:y}=g,v=y[y.length-1],{lastCommittedPoint:T}=E;if(Qt(this.interactiveCanvas,this.state),v===T)xs(this.state.newElement)&&ic(this.state)&&zo(ie(r,i),this.scene.getNonDeletedElements(),this.scene.getNonDeletedElementsMap(),J0(this.state.zoom))?(this.actionManager.executeAction(Rt,"ui",{event:t.nativeEvent,sceneCoords:{x:r,y:i}}),this.setState({suggestedBinding:null,startBoundElement:null}),this.state.activeTool.locked||(Jt(this.interactiveCanvas),this.setState(M=>({newElement:null,activeTool:fn(this.state,{type:this.state.preferredSelectionTool.type}),selectedElementIds:Pe({...M.selectedElementIds,[g.id]:!0},M),selectedLinearElement:new ve(g,this.scene.getNonDeletedElementsMap())})))):Rr(ie(r-w,i-x),v)>=P0?(this.scene.mutateElement(g,{points:[...y,ie(r-w,i-x)]},{informMutation:!1,isDragging:!1}),bn(this.state.selectedLinearElement?.initialState,"initialState must be set"),this.setState({selectedLinearElement:{...this.state.selectedLinearElement,lastCommittedPoint:y[y.length-1],selectedPointsIndices:[g.points.length-1],initialState:{...this.state.selectedLinearElement.initialState,lastClickedPoint:g.points.length-1}}})):Se(this.interactiveCanvas,Ke.POINTER);else if(y.length>2&&T&&Rr(ie(r-w,i-x),T)<P0)Se(this.interactiveCanvas,Ke.POINTER),this.scene.mutateElement(g,{points:y.slice(0,-1)},{informMutation:!1,isDragging:!1}),this.setState({selectedLinearElement:{...E,selectedPointsIndices:E.selectedPointsIndices?.includes(g.points.length)?[...E.selectedPointsIndices.filter(C=>C!==g.points.length&&C!==g.points.length-1),g.points.length-1]:E.selectedPointsIndices,lastCommittedPoint:g.points[g.points.length-1],initialState:{...E.initialState,lastClickedPoint:g.points.length-1}}});else{$4(y,this.state.zoom.value)&&Se(this.interactiveCanvas,Ke.POINTER);let C=this.scene.getNonDeletedElementsMap();if(q0(g)){let S=zo(ie(r,i),this.scene.getNonDeletedElements(),C);Un("COMPLEX_BINDINGS")&&this.handleDelayedBindModeChange(g,S)}bn(this.state.selectedLinearElement,"Expected selectedLinearElement to be set to operate on a linear element");let M=ve.handlePointerMove(t.nativeEvent,this,r,i,this.state.selectedLinearElement);M&&this.setState(M)}return}if(this.state.activeTool.type==="arrow"){let g=zo(ie(r,i),this.scene.getNonDeletedElements(),this.scene.getNonDeletedElementsMap(),J0(this.state.zoom)),E=ie(r,i),w=this.scene.getNonDeletedElementsMap();g&&!kK(E,g,w)&&this.setState({suggestedBinding:{element:g,midPoint:Q0(E,g,w,this.state.zoom)}})}let c=!!t.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,i),(!this.state.selectedLinearElement||this.state.selectedLinearElement.hoverPointIndex===-1)&&this.state.openDialog?.name!=="elementLinkSelector"&&!(d.length===1&&$t(d[0]))&&!(zt(d[0])&&(this.editorInterface.userAgent.isMobileDevice||d[0].points.length===2))){let g=ak(p,this.state,r,i,this.state.zoom,t.pointerType,this.scene.getNonDeletedElementsMap(),this.editorInterface);if(g&&g.transformHandleType){Se(this.interactiveCanvas,ik(g));return}}}else if(d.length>1&&!l&&this.state.openDialog?.name!=="elementLinkSelector"){let g=sk(bs(d),r,i,this.state.zoom,t.pointerType,this.editorInterface);if(g){Se(this.interactiveCanvas,ik({transformHandleType:g}));return}}if(Gt(this.state))return;let u=this.getElementAtPosition(r,i,{preferSelected:!0,includeLockedElements:!0}),b=null;if(u&&u.locked?b=null:b=u,this.handleIframeLikeElementHover({hitElement:b,scenePointer:n,moveEvent:t})||(this.hitLinkElement=this.getElementLinkAtPosition(n,u)),this.hitLinkElement&&!this.state.selectedElementIds[this.hitLinkElement.id])Se(this.interactiveCanvas,Ke.POINTER),kv(this.hitLinkElement,this.state,this.scene.getNonDeletedElementsMap());else{if(hh(),m)return;b&&(b.link||Wn(b))&&this.state.selectedElementIds[b.id]&&!this.state.contextMenu&&!this.state.showHyperlinkPopup?this.setState({showHyperlinkPopup:"info"}):this.state.activeTool.type==="text"?Se(this.interactiveCanvas,Ho(b)?Ke.TEXT:Ke.CROSSHAIR):this.state.viewModeEnabled?Se(this.interactiveCanvas,Ke.GRAB):this.state.openDialog?.name==="elementLinkSelector"?Se(this.interactiveCanvas,Ke.AUTO):l?Se(this.interactiveCanvas,Ke.AUTO):t[j.CTRL_OR_CMD]?Se(this.interactiveCanvas,Ke.AUTO):(b||this.isHittingCommonBoundingBoxOfSelectedElements(n,d))&&!b?.locked&&(!b||!$t(b)||!(b.startBinding||b.endBinding))&&(this.state.activeTool.type!=="lasso"||d.length>0)&&Se(this.interactiveCanvas,Ke.MOVE),this.state.selectedLinearElement&&this.handleHoverSelectedLinearElement(this.state.selectedLinearElement,r,i)}this.state.openDialog?.name==="elementLinkSelector"&&b?this.setState(g=>({hoveredElementIds:rc(g.hoveredElementIds,Io({editingGroupId:g.editingGroupId,selectedElementIds:{[b.id]:!0}},this.scene.getNonDeletedElements(),g,this).selectedElementIds)})):this.state.openDialog?.name==="elementLinkSelector"&&!b&&this.setState(g=>({hoveredElementIds:rc(g.hoveredElementIds,{})}))});k(this,"handleEraser",(t,n)=>{let r=this.eraserTrail.addPointToPath(n.x,n.y,t.altKey);this.elementsPendingErasure=new Set(r),this.triggerRender()});k(this,"handleTouchMove",t=>{uc=!0});k(this,"handleCanvasPointerDown",t=>{let n=Ue(t,this.state),{x:r,y:i}=n;this.lastPointerMoveCoords={x:r,y:i};let a=t.target;if(a.setPointerCapture&&a.setPointerCapture(t.pointerId),this.maybeCleanupAfterMissingPointerUp(t.nativeEvent),this.maybeUnfollowRemoteUser(),this.state.searchMatches&&(this.setState(b=>({searchMatches:b.searchMatches&&{focusedId:null,matches:b.searchMatches.matches.map(g=>({...g,focus:!1}))}})),this.updateEditorAtom(L1,null)),ot.get(Do)&&this.updateEditorAtom(Do,null),this.state.contextMenu&&this.setState({contextMenu:null}),this.state.snapLines&&this.setAppState({snapLines:[]}),this.state.openPopup&&this.setState({openPopup:null}),this.updateGestureOnPointerDown(t),t.pointerType==="touch"&&this.state.newElement&&this.state.newElement.type==="freedraw"){let b=this.state.newElement;this.updateScene({...b.points.length<10?{elements:this.scene.getElementsIncludingDeleted().filter(g=>g.id!==b.id)}:{},appState:{newElement:null,editingTextElement:null,startBoundElement:null,suggestedBinding:null,selectedElementIds:Pe(Object.keys(this.state.selectedElementIds).filter(g=>g!==b.id).reduce((g,E)=>(g[E]=this.state.selectedElementIds[E],g),{}),this.state)},captureUpdate:this.state.openDialog?.name==="elementLinkSelector"?Ht.EVENTUALLY:Ht.NEVER});return}let s=document.getSelection();if(s?.anchorNode&&s.removeAllRanges(),this.maybeOpenContextMenuAfterPointerDownOnTouchDevices(t),!this.state.penDetected&&t.pointerType==="pen"&&this.setState(b=>({penMode:!0,penDetected:!0})),!this.editorInterface.isTouchScreen&&["pen","touch"].includes(t.pointerType)&&(this.editorInterface=_0(this.editorInterface,{isTouchScreen:!0})),mc||(this.lastPointerDownEvent=t,this.handleCanvasPanUsingWheelOrSpaceDrag(t)))return;if(this.setState({lastPointerDownWith:t.pointerType,cursorButton:"down"}),this.savePointer(t.clientX,t.clientY,"down"),t.button===Nr.ERASER&&this.state.activeTool.type!==hn.eraser){this.setState({activeTool:fn(this.state,{type:hn.eraser,lastActiveToolBeforeEraser:this.state.activeTool})},()=>{this.handleCanvasPointerDown(t);let b=()=>{g(),E?.(),Gt(this.state)&&this.setState({activeTool:fn(this.state,{...this.state.activeTool.lastActiveTool||{type:hn.selection},lastActiveToolBeforeEraser:null})})},g=Je(window,ce.POINTER_UP,b,{once:!0}),E;requestAnimationFrame(()=>{E=this.missingPointerEventCleanupEmitter.once(b)})});return}if(t.button!==Nr.MAIN&&t.button!==Nr.TOUCH&&t.button!==Nr.ERASER||Ce.pointers.size>1)return;let l=this.initialPointerDownState(t);if(this.setState({selectedElementsAreBeingDragged:!1}),this.handleDraggingScrollBar(t,l)||(this.clearSelectionIfNotUsingSelection(),this.updateBindingEnabledOnPointerMove(t),this.handleSelectionOnPointerDown(t,l))||!(!this.state.penMode||t.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 b=l.hit.element&&this.isASelectedElement(l.hit.element);!l.hit.hasHitCommonBoundingBoxOfSelectedElements&&!l.resize.handleType&&!b&&(this.lassoTrail.startPath(l.origin.x,l.origin.y,t.shiftKey),l.drag.blockDragging=this.editorInterface.formFactor==="desktop"),this.editorInterface.formFactor!=="desktop"&&l.hit.element&&!b&&(this.setState(g=>{let E={...g.selectedElementIds,[l.hit.element.id]:!0},w=[];Object.keys(g.selectedElementIds).forEach(y=>{let v=this.scene.getElement(y);v&&w.push(v)});let x=l.hit.element;if(Lt(x))V0(w,x.id).forEach(y=>{delete E[y.id]});else if(x.frameId)E[x.frameId]&&delete E[x.id];else{let y=x.groupIds,v=new Set(y.flatMap(T=>Li(this.scene.getNonDeletedElements(),T)).filter(T=>Lt(T)).map(T=>T.id));v.size>0&&w.forEach(T=>{T.frameId&&v.has(T.frameId)&&(delete E[T.id],T.groupIds.flatMap(C=>Li(this.scene.getNonDeletedElements(),C)).forEach(C=>{delete E[C.id]}))})}return{...Io({editingGroupId:g.editingGroupId,selectedElementIds:E},this.scene.getNonDeletedElements(),g,this),showHyperlinkPopup:x.link||Wn(x)?"info":!1}}),l.hit.wasAddedToSelection=!0)}else this.state.activeTool.type==="text"?this.handleTextOnPointerDown(t,l):this.state.activeTool.type==="arrow"||this.state.activeTool.type==="line"?this.handleLinearElementOnPointerDown(t,this.state.activeTool.type,l):this.state.activeTool.type==="freedraw"?this.handleFreeDrawElementOnPointerDown(t,this.state.activeTool.type,l):this.state.activeTool.type==="custom"?Qt(this.interactiveCanvas,this.state):this.state.activeTool.type===hn.frame||this.state.activeTool.type===hn.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,t),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(b=>p(b||t.nativeEvent)),(!this.state.viewModeEnabled||this.state.activeTool.type==="laser")&&(window.addEventListener(ce.POINTER_MOVE,m),window.addEventListener(ce.POINTER_UP,p),window.addEventListener(ce.KEYDOWN,d),window.addEventListener(ce.KEYUP,u),l.eventListeners.onMove=m,l.eventListeners.onUp=p,l.eventListeners.onKeyUp=u,l.eventListeners.onKeyDown=d)});k(this,"handleCanvasPointerUp",t=>{Un("COMPLEX_BINDINGS")&&this.resetDelayedBindMode(),this.removePointer(t),this.lastPointerUpEvent=t;let n=Ue({clientX:t.clientX,clientY:t.clientY},this.state),{x:r,y:i}=n;if(this.lastPointerMoveCoords={x:r,y:i},!this.handleIframeLikeCenterClick()){if(this.editorInterface.isTouchScreen){let a=this.getElementAtPosition(n.x,n.y,{includeLockedElements:!0});this.hitLinkElement=this.getElementLinkAtPosition(n,a)}this.hitLinkElement&&!this.state.selectedElementIds[this.hitLinkElement.id]?this.handleElementLinkClick(t):this.state.viewModeEnabled&&this.setState({activeEmbeddable:null,selectedElementIds:{}})}});k(this,"maybeOpenContextMenuAfterPointerDownOnTouchDevices",t=>{t.pointerType==="touch"&&(uc=!1,Hr?uc=!0:Hr=window.setTimeout(()=>{Hr=0,uc||this.handleCanvasContextMenu(t)},jY))});k(this,"resetContextMenuTimer",()=>{clearTimeout(Hr),Hr=0,uc=!1});k(this,"maybeCleanupAfterMissingPointerUp",t=>{gc?.(),this.missingPointerEventCleanupEmitter.trigger(t).clear()});k(this,"handleCanvasPanUsingWheelOrSpaceDrag",t=>{if(!(Ce.pointers.size<=1&&(t.button===Nr.WHEEL||t.button===Nr.MAIN&&zr||wn(this.state)||this.state.viewModeEnabled&&this.state.activeTool.type!=="laser")))return!1;mc=!0,this.focusContainer(),this.state.editingTextElement||t.preventDefault();let n=!1,r=typeof window===void 0?!1:/Linux/.test(window.navigator.platform);Se(this.interactiveCanvas,Ke.GRABBING);let{clientX:i,clientY:a}=t,s=qm(c=>{let m=i-c.clientX,p=a-c.clientY;if(i=c.clientX,a=c.clientY,r&&!n&&(Math.abs(m)>1||Math.abs(p)>1)){n=!0;let d=b=>{document.body.removeEventListener(ce.PASTE,d),b.stopPropagation()},u=()=>{setTimeout(()=>{document.body.removeEventListener(ce.PASTE,d),window.removeEventListener(ce.POINTER_UP,u)},100)};document.body.addEventListener(ce.PASTE,d),window.addEventListener(ce.POINTER_UP,u)}this.translateCanvas({scrollX:this.state.scrollX-m/this.state.zoom.value,scrollY:this.state.scrollY-p/this.state.zoom.value})}),l=Ze(gc=()=>{gc=null,mc=!1,zr||(this.state.viewModeEnabled&&this.state.activeTool.type!=="laser"?Se(this.interactiveCanvas,Ke.GRAB):Qt(this.interactiveCanvas,this.state)),this.setState({cursorButton:"up"}),this.savePointer(t.clientX,t.clientY,"up"),window.removeEventListener(ce.POINTER_MOVE,s),window.removeEventListener(ce.POINTER_UP,l),window.removeEventListener(ce.BLUR,l),s.flush()});return window.addEventListener(ce.BLUR,l),window.addEventListener(ce.POINTER_MOVE,s,{passive:!0}),window.addEventListener(ce.POINTER_UP,l),!0});k(this,"clearSelectionIfNotUsingSelection",()=>{jp(this.state.activeTool.type)||this.setState({selectedElementIds:Pe({},this.state),selectedGroupIds:{},editingGroupId:null,activeEmbeddable:null})});k(this,"handleSelectionOnPointerDown",(t,n)=>{if(jp(this.state.activeTool.type)){let r=this.scene.getNonDeletedElements(),i=this.scene.getNonDeletedElementsMap(),a=this.scene.getSelectedElements(this.state);if(a.length===1&&!this.state.selectedLinearElement?.isEditing&&!$t(a[0])&&!(zt(a[0])&&(this.editorInterface.userAgent.isMobileDevice||a[0].points.length===2))&&!(this.state.selectedLinearElement&&this.state.selectedLinearElement.hoverPointIndex!==-1)){let s=ak(r,this.state,n.origin.x,n.origin.y,this.state.zoom,t.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 a.length>1&&(n.resize.handleType=sk(bs(a),n.origin.x,n.origin.y,this.state.zoom,t.pointerType,this.editorInterface));if(n.resize.handleType)n.resize.isResizing=!0,n.resize.offset=D0(xK(n.resize.handleType,a,i,n.origin.x,n.origin.y)),a.length===1&&zt(a[0])&&a[0].points.length===2&&(n.resize.arrowDirection=EK(n.resize.handleType,a[0]));else{if(this.state.selectedLinearElement){let d=this.state.selectedLinearElement,u=ve.handlePointerDown(t,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 b=this.scene.getNonDeletedElementsMap(),g=ve.getElement(d.elementId,b);if(g&&xn(g)){let{hitFocusPoint:E,pointerOffset:w}=LK(g,n,b,this.state);if(E)return this.setState({selectedLinearElement:{...d,hoveredFocusPointBinding:E,draggedFocusPointBinding:E,pointerOffset:w}}),!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)&&!t.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?Pe({[d.selectedLinearElement.elementId]:!0},this.state):Pe({},d)}));else if(m!=null){if(t[j.CTRL_OR_CMD])return t.altKey?(this.state.openDialog?.name==="elementLinkSelector"&&this.setOpenDialog(null),this.lassoTrail.startPath(n.origin.x,n.origin.y,t.shiftKey),this.setActiveTool({type:"lasso",fromSelection:!0}),!1):(this.state.selectedElementIds[m.id]||(n.hit.wasAddedToSelection=!0),this.setState(d=>({...pK(d,m),previousSelectedElementIds:this.state.selectedElementIds})),!1);this.state.selectedElementIds[m.id]||(this.state.editingGroupId&&!nk(m,this.state.editingGroupId)&&this.setState({selectedElementIds:Pe({},this.state),selectedGroupIds:{},editingGroupId:null,activeEmbeddable:null}),!p&&!n.hit.hasHitCommonBoundingBoxOfSelectedElements&&(this.setState(d=>{let u={...d.selectedElementIds,[m.id]:!0},b=[];if(Object.keys(d.selectedElementIds).forEach(g=>{let E=this.scene.getElement(g);E&&b.push(E)}),Lt(m))V0(b,m.id).forEach(g=>{delete u[g.id]});else if(m.frameId)u[m.frameId]&&delete u[m.id];else{let g=m.groupIds,E=new Set(g.flatMap(w=>Li(this.scene.getNonDeletedElements(),w)).filter(w=>Lt(w)).map(w=>w.id));E.size>0&&b.forEach(w=>{w.frameId&&E.has(w.frameId)&&(delete u[w.id],w.groupIds.flatMap(x=>Li(this.scene.getNonDeletedElements(),x)).forEach(x=>{delete u[x.id]}))})}return d.openDialog?.name==="elementLinkSelector"&&(m.groupIds.some(g=>d.selectedGroupIds[g])||(u={[m.id]:!0})),{...Io({editingGroupId:d.editingGroupId,selectedElementIds:u},this.scene.getNonDeletedElements(),d,this),showHyperlinkPopup:m.link||Wn(m)?"info":!1}}),n.hit.wasAddedToSelection=!0))}this.setState({previousSelectedElementIds:this.state.selectedElementIds})}}return!1});k(this,"handleTextOnPointerDown",(t,n)=>{if(this.state.editingTextElement)return;let r=n.origin.x,i=n.origin.y,a=this.getElementAtPosition(r,i,{includeBoundTextElement:!0}),s=this.getTextBindableContainerAtPosition(r,i);Y4(a)&&(s=a,r=a.x+a.width/2,i=a.y+a.height/2),this.startTextEditing({sceneX:r,sceneY:i,insertAtParentCenter:!t.altKey,container:s,autoEdit:!1}),Jt(this.interactiveCanvas),this.state.activeTool.locked||this.setState({activeTool:fn(this.state,{type:this.state.preferredSelectionTool.type})})});k(this,"handleFreeDrawElementOnPointerDown",(t,n,r)=>{let[i,a]=Pt(r.origin.x,r.origin.y,null),s=this.getTopLayerFrameAtSceneCoords({x:i,y:a}),l=t.pressure===.5,c=SV({type:n,x:i,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:null,simulatePressure:l,locked:!1,frameId:s?s.id:null,points:[ie(0,0)],pressures:l?[]:[t.pressure]});this.scene.insertElement(c),this.setState(p=>{let d={...p.selectedElementIds};return delete d[c.id],{selectedElementIds:Pe(d,p)}});let m=zo(ie(r.origin.x,r.origin.y),this.scene.getNonDeletedElements(),this.scene.getNonDeletedElementsMap());this.setState({newElement:c,startBoundElement:m,suggestedBinding:null})});k(this,"insertIframeElement",({sceneX:t,sceneY:n,width:r,height:i})=>{let[a,s]=Pt(t,n,this.lastPointerDownEvent?.[j.CTRL_OR_CMD]?null:this.getEffectiveGridSize()),l=kV({type:"iframe",x:a,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:i});return this.scene.insertElement(l),l});k(this,"insertEmbeddableElement",({sceneX:t,sceneY:n,link:r})=>{let[i,a]=Pt(t,n,this.lastPointerDownEvent?.[j.CTRL_OR_CMD]?null:this.getEffectiveGridSize()),s=Qp(r);if(!s)return;s.error instanceof URIError&&this.setToast({message:h("toast.unrecognizedLinkFormat"),closable:!0});let l=H4({type:"embeddable",x:i,y:a,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});k(this,"newImagePlaceholder",({sceneX:t,sceneY:n,addToFrameUnderCursor:r=!0})=>{let[i,a]=Pt(t,n,this.lastPointerDownEvent?.[j.CTRL_OR_CMD]?null:this.getEffectiveGridSize()),s=r?this.getTopLayerFrameAtSceneCoords({x:i,y:a}):null,l=100/this.state.zoom.value;return N0({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:i-l/2,y:a-l/2,width:l,height:l})});k(this,"handleLinearElementOnPointerDown",(t,n,r)=>{if(t.ctrlKey&&Xt(()=>{this.setState({isBindingEnabled:!1})}),this.state.multiElement){let{multiElement:i,selectedLinearElement:a}=this.state;if(bn(a,"selectedLinearElement is expected to be set"),i.type==="line"&&$4(i.points,this.state.zoom.value)){Xt(()=>{this.setState({selectedLinearElement:{...a,lastCommittedPoint:i.points[i.points.length-1],initialState:{...a.initialState,lastClickedPoint:-1}}})}),this.actionManager.executeAction(Rt);return}if($t(i)&&i.points.length>1){this.actionManager.executeAction(Rt,"ui",{event:t.nativeEvent,sceneCoords:{x:r.origin.x,y:r.origin.y}});return}let{x:s,y:l}=i,{lastCommittedPoint:c}=a,m=ic(this.state)&&zo(ie(this.lastPointerMoveCoords?.x??s+i.points[i.points.length-1][0],this.lastPointerMoveCoords?.y??l+i.points[i.points.length-1][1]),this.scene.getNonDeletedElements(),this.scene.getNonDeletedElementsMap());if(xn(i)&&m||i.points.length>1&&c&&Rr(ie(r.origin.x-s,r.origin.y-l),c)<P0){this.actionManager.executeAction(Rt,"ui",{event:t.nativeEvent,sceneCoords:{x:r.origin.x,y:r.origin.y}});return}this.setState(p=>({selectedElementIds:Pe({...p.selectedElementIds,[i.id]:!0},p)})),Se(this.interactiveCanvas,Ke.POINTER)}else{let[i,a]=Pt(r.origin.x,r.origin.y,t[j.CTRL_OR_CMD]?null:this.getEffectiveGridSize()),s=this.getTopLayerFrameAtSceneCoords({x:i,y:a}),{currentItemStartArrowhead:l,currentItemEndArrowhead:c}=this.state,[m,p]=n==="arrow"?[l,c]:[null,null],d=n==="arrow"?MV({type:n,x:i,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.state.currentItemArrowType===Br.round?{type:Vp.PROPORTIONAL_RADIUS}:null,startArrowhead:m,endArrowhead:p,locked:!1,frameId:s?s.id:null,elbowed:this.state.currentItemArrowType===Br.elbow,fixedSegments:this.state.currentItemArrowType===Br.elbow?[]:null}):LV({type:n,x:i,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.state.currentItemRoundness==="round"?{type:Vp.PROPORTIONAL_RADIUS}:null,locked:!1,frameId:s?s.id:null}),u=ie(r.origin.x,r.origin.y),b=this.scene.getNonDeletedElementsMap(),g=ic(this.state)?zo(u,this.scene.getNonDeletedElements(),b):null;this.scene.mutateElement(d,{points:[ie(0,0),ie(0,0)]}),this.scene.insertElement(d),xn(d)&&CK(d,new Map([[0,{point:ie(0,0),isDragging:!1}]]),u[0],u[1],this.scene,this.state,{newArrow:!0,altKey:t.altKey,initialBinding:!0,angleLocked:S4(t.nativeEvent)}),Xt(()=>{this.setState(E=>{let w=null,x=E.selectedElementIds;if(zt(d)){w=new ve(d,this.scene.getNonDeletedElementsMap());let y=d.points.length-1;w={...w,selectedPointsIndices:[y],initialState:{...w.initialState,arrowStartIsInside:t.altKey,lastClickedPoint:y,origin:ie(r.origin.x,r.origin.y)}}}return x=this.state.activeTool.locked?E.selectedElementIds:Pe({[d.id]:!0},E),{...E,bindMode:"orbit",newElement:d,startBoundElement:g,suggestedBinding:g&&xn(d)?{element:g,midPoint:Q0(u,g,b,this.state.zoom)}:null,selectedElementIds:x,selectedLinearElement:w}})}),xn(d)&&Un("COMPLEX_BINDINGS")&&this.handleDelayedBindModeChange(d,g)}});k(this,"createGenericElementOnPointerDown",(t,n)=>{let[r,i]=Pt(n.origin.x,n.origin.y,this.lastPointerDownEvent?.[j.CTRL_OR_CMD]?null:this.getEffectiveGridSize()),a=this.getTopLayerFrameAtSceneCoords({x:r,y:i}),s={x:r,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.getCurrentItemRoundness(t),locked:!1,frameId:a?a.id:null},l;t==="embeddable"?l=H4({type:"embeddable",...s}):l=PV({type:t,...s}),l.type==="selection"?this.setState({selectionElement:l}):(this.scene.insertElement(l),this.setState({multiElement:null,newElement:l}))});k(this,"createFrameElementOnPointerDown",(t,n)=>{let[r,i]=Pt(t.origin.x,t.origin.y,this.lastPointerDownEvent?.[j.CTRL_OR_CMD]?null:this.getEffectiveGridSize()),a={x:r,y:i,opacity:this.state.currentItemOpacity,locked:!1,...To},s=n===hn.magicframe?G4(a):z4(a);this.scene.insertElement(s),this.setState({multiElement:null,newElement:s})});k(this,"restoreReadyToEraseElements",()=>{this.elementsPendingErasure=new Set,this.triggerRender()});k(this,"eraseElements",()=>{let t=!1;this.elementsPendingErasure.forEach(r=>{let i=this.scene.getElement(r);if(xn(i)){if(i.startBinding){let a=this.scene.getElement(i.startBinding.elementId);eu(a,this.scene.getElementsMapIncludingDeleted(),{boundElements:a.boundElements.filter(s=>s.id!==i.id)})}if(i.endBinding){let a=this.scene.getElement(i.endBinding.elementId);eu(a,this.scene.getElementsMapIncludingDeleted(),{boundElements:a.boundElements.filter(s=>s.id!==i.id)})}}else H0(i)&&i.boundElements?.forEach(a=>{if(a.type==="arrow"){let s=this.scene.getElement(a.id);s?.startBinding?.elementId===i.id&&eu(s,this.scene.getElementsMapIncludingDeleted(),{startBinding:null}),s?.endBinding?.elementId===i.id&&eu(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)||F0(r)&&this.elementsPendingErasure.has(r.containerId)?(t=!0,Fr(r,{isDeleted:!0})):r);this.elementsPendingErasure=new Set,t&&(this.store.scheduleCapture(),this.scene.replaceAllElements(n))});k(this,"initializeImage",async(t,n)=>{if(!pu(n))throw new Error(h("errors.unsupportedFileType"));let r=n.type;if(Se(this.interactiveCanvas,"wait"),r===gn.svg)try{n=bu(j4(await n.text()),n.name)}catch(l){throw console.warn(l),new Error(h("errors.svgImageInsertError"))}let i=await(this.props.generateIdForFile?.(n)||Gb(n));if(!i)throw console.warn("Couldn't generate file id or the supplied `generateIdForFile` didn't resolve to one."),new Error(h("errors.imageInsertError"));if(!this.files[i]?.dataURL){try{n=await kc(n,{maxWidthOrHeight:UY})}catch(l){console.error("Error trying to resizing image file on insertion",l)}if(n.size>L4)throw new Error(h("errors.fileTooBig",{maxSize:`${Math.trunc(L4/1024/1024)}MB`}))}let s=this.files[i]?.dataURL||await hu(n);return new Promise(async(l,c)=>{try{let m=this.getLatestInitializedImageElement(t,i);if(this.addMissingFiles([{mimeType:r,id:i,dataURL:s,created:Date.now(),lastRetrieved:Date.now()}]),!this.imageCache.get(i)){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(i)?.image;if(p&&this.state.newElement?.id!==m.id){m=this.getLatestInitializedImageElement(t,i);let d=this.getImageNaturalDimensions(m,p);Object.assign(m,d)}l(m)}catch(m){console.error(m),c(new Error(h("errors.imageInsertError")))}})});k(this,"getLatestInitializedImageElement",(t,n)=>{let r=this.scene.getElement(t.id)??t;return Fr(r,{fileId:n})});k(this,"onImageToolbarButtonClick",async()=>{try{let t=this.state.width/2+this.state.offsetLeft,n=this.state.height/2+this.state.offsetTop,{x:r,y:i}=Ue({clientX:t,clientY:n},this.state),a=await Ec({description:"Image",extensions:Object.keys(YY),multiple:!0});this.insertImages(a,r,i)}catch(t){t.name!=="AbortError"?console.error(t):console.warn(t),this.setState({newElement:null,activeTool:fn(this.state,{type:this.state.preferredSelectionTool.type})},()=>{this.actionManager.executeAction(Rt)})}});k(this,"getImageNaturalDimensions",(t,n)=>{let r=Math.max(this.state.height-120,160),i=Math.min(r,Math.floor(this.state.height*.5)/this.state.zoom.value),a=Math.min(n.naturalHeight,i),s=a*(n.naturalWidth/n.naturalHeight),l=t.x+t.width/2-s/2,c=t.y+t.height/2-a/2;return{x:l,y:c,width:s,height:a,crop:null}});k(this,"updateImageCache",async(t,n=this.files)=>{let{updatedFiles:r,erroredFiles:i}=await HV({imageCache:this.imageCache,fileIds:t.map(a=>a.fileId),files:n});return i.size&&(this.store.scheduleAction(Ht.NEVER),this.scene.replaceAllElements(this.scene.getElementsIncludingDeleted().map(a=>ac(a)&&i.has(a.fileId)?Fr(a,{status:"error"}):a))),{updatedFiles:r,erroredFiles:i}});k(this,"addNewImagesToImageCache",async(t=zV(this.scene.getNonDeletedElements()),n=this.files)=>{let r=t.filter(i=>!i.isDeleted&&!this.imageCache.has(i.fileId));if(r.length){let{updatedFiles:i}=await this.updateImageCache(r,n);if(i.size)for(let a of r)i.has(a.fileId)&&lc.delete(a);i.size&&this.scene.triggerUpdate()}});k(this,"scheduleImageRefresh",OY(()=>{this.addNewImagesToImageCache()},VY));k(this,"updateBindingEnabledOnPointerMove",t=>{let n=CV(t);this.state.isBindingEnabled!==n&&this.setState({isBindingEnabled:n})});k(this,"handleInteractiveCanvasRef",t=>{t!==null?(this.interactiveCanvas=t,this.interactiveCanvas.addEventListener(ce.TOUCH_START,this.onTouchStart,{passive:!1}),this.interactiveCanvas.addEventListener(ce.TOUCH_END,this.onTouchEnd)):(this.interactiveCanvas?.removeEventListener(ce.TOUCH_START,this.onTouchStart),this.interactiveCanvas?.removeEventListener(ce.TOUCH_END,this.onTouchEnd))});k(this,"insertImages",async(t,n,r)=>{let i=50/this.state.zoom.value,a=pk(t.map(()=>this.newImagePlaceholder({sceneX:n,sceneY:r})),n,r,i);a.forEach(d=>this.scene.insertElement(d));let s=await Promise.all(a.map(async(d,u)=>{try{return await this.initializeImage(d,await Ps(t[u]))}catch(b){return this.setState({errorMessage:b.message||h("errors.imageInsertError")}),Fr(d,{isDeleted:!0})}})),l=Zp(s),c=pk(s.filter(d=>!d.isDeleted),n,r,i),m=Zp(c),p=this.scene.getElementsIncludingDeleted().map(d=>m.get(d.id)??l.get(d.id)??d);this.updateScene({appState:{selectedElementIds:Pe(Object.fromEntries(c.map(d=>[d.id,!0])),this.state)},elements:p,captureUpdate:Ht.IMMEDIATELY}),this.setState({},()=>{this.actionManager.executeAction(Rt)})});k(this,"handleAppOnDrop",async t=>{let{x:n,y:r}=Ue(t,this.state),i=await fa(t),a=i.getFiles();if(a.length===1){let{file:p,fileHandle:d}=a[0];if(p&&(p.type===gn.png||p.type===gn.svg))try{let u=await Sc(p,this.state,this.scene.getElementsIncludingDeleted(),d);this.syncActionResult({...u,appState:{...u.appState||this.state,isLoading:!1},replaceFiles:!0,captureUpdate:Ht.IMMEDIATELY});return}catch(u){if(u.name!=="EncodingError")throw new Error(h("alerts.couldNotLoadInvalidFile"))}}let s=a.map(p=>p.file).filter(p=>pu(p));if(s.length>0&&this.isToolSupported("image"))return this.insertImages(s,n,r);let l=i.getData(gn.excalidrawlibIds),c=i.getData(gn.excalidrawlib);if(l||c){try{let p=null;if(l){let{itemIds:d}=JSON.parse(l);p=(await this.library.getLatestLibrary()).filter(b=>d.includes(b.id))}else c&&(p=Hb(c));p?.length&&(p=p.map(d=>({...d,elements:B0({type:"everything",elements:d.elements,randomizeSeed:!0}).duplicatedElements})),this.addElementsFromPasteOrLibrary({elements:Na(p),position:t,files:null}))}catch(p){this.setState({errorMessage:p.message})}return}if(a.length>0){let{file:p,fileHandle:d}=a[0];p&&await this.loadFileToCanvas(p,d)}let m=i.findByType(gn.text);if(m){let p=m.value;if(p&&U0(p,this.props.validateEmbeddable)&&(/^(http|https):\/\/[^\s/$.?#].[^\s]*$/.test(p)||Qp(p)?.type==="video")){let d=this.insertEmbeddableElement({sceneX:n,sceneY:r,link:L0(p)});d&&(this.store.scheduleCapture(),this.setState({selectedElementIds:{[d.id]:!0}}))}}});k(this,"loadFileToCanvas",async(t,n)=>{t=await Ps(t);try{let r=this.scene.getElementsIncludingDeleted(),i;try{i=await uu(t,this.state,r,n)}catch(a){let s=a instanceof Pb;if(s&&a.code==="IMAGE_NOT_CONTAINS_SCENE_DATA"&&!this.isToolSupported("image")){this.setState({isLoading:!1,errorMessage:h("errors.imageToolNotSupported")});return}let l=s?h("alerts.cannotRestoreFromImage"):h("alerts.couldNotLoadInvalidFile");this.setState({isLoading:!1,errorMessage:l})}if(!i)return;i.type===gn.excalidraw?(vk(r.concat(i.data.elements)),this.store.scheduleMicroAction({action:Ht.NEVER,elements:r,appState:void 0}),this.setState({isLoading:!0}),this.syncActionResult({...i.data,appState:{...i.data.appState||this.state,isLoading:!1},replaceFiles:!0,captureUpdate:Ht.IMMEDIATELY})):i.type===gn.excalidrawlib&&await this.library.updateLibrary({libraryItems:t,merge:!0,openLibraryMenu:!0}).catch(a=>{console.error(a),this.setState({errorMessage:h("errors.importLibraryError")})})}catch(r){this.setState({isLoading:!1,errorMessage:r.message})}});k(this,"handleCanvasContextMenu",t=>{if(t.preventDefault(),("pointerType"in t.nativeEvent&&t.nativeEvent.pointerType==="touch"||"pointerType"in t.nativeEvent&&t.nativeEvent.pointerType==="pen"&&t.button!==Nr.SECONDARY)&&this.state.activeTool.type!==this.state.preferredSelectionTool.type)return;let{x:n,y:r}=Ue(t,this.state),i=this.getElementAtPosition(n,r,{preferSelected:!0,includeLockedElements:!0}),a=this.scene.getSelectedElements(this.state),s=this.isHittingCommonBoundingBoxOfSelectedElements({x:n,y:r},a),l=i||s?"element":"canvas",c=this.excalidrawContainerRef.current,{top:m,left:p}=c.getBoundingClientRect(),d=t.clientX-p,u=t.clientY-m;me("contextMenu","openContextMenu",l),this.setState({...i&&!this.state.selectedElementIds[i.id]?{...this.state,...Io({editingGroupId:this.state.editingGroupId,selectedElementIds:{[i.id]:!0}},this.scene.getNonDeletedElements(),this.state,this),selectedLinearElement:zt(i)?new ve(i,this.scene.getNonDeletedElementsMap()):null}:this.state,showHyperlinkPopup:!1},()=>{this.setState({contextMenu:{top:u,left:d,items:this.getContextMenuItems(l)}})})});k(this,"maybeDragNewGenericElement",(t,n,r=!0)=>{let i=this.state.selectionElement,a=t.lastCoords;if(i&&t.boxSelection.hasOccurred&&this.state.activeTool.type!=="eraser"){lk({newElement:i,elementType:this.state.activeTool.type,originX:t.origin.x,originY:t.origin.y,x:a.x,y:a.y,width:fs(t.origin.x,a.x),height:fs(t.origin.y,a.y),shouldMaintainAspectRatio:oc(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]=Pt(a.x,a.y,n[j.CTRL_OR_CMD]?null:this.getEffectiveGridSize()),m=ac(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}=_3(s,this,n,{x:t.originInGrid.x+(this.state.originSnapOffset?.x??0),y:t.originInGrid.y+(this.state.originSnapOffset?.y??0)},{x:l-t.originInGrid.x,y:c-t.originInGrid.y},this.scene.getNonDeletedElementsMap());l+=d.x,c+=d.y,this.setState({snapLines:u}),xn(s)||lk({newElement:s,elementType:this.state.activeTool.type,originX:t.originInGrid.x,originY:t.originInGrid.y,x:l,y:c,width:fs(t.originInGrid.x,l),height:fs(t.originInGrid.y,c),shouldMaintainAspectRatio:Or(s)?!oc(n):oc(n),shouldResizeFromCenter:C4(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===hn.frame||this.state.activeTool.type===hn.magicframe)&&this.setState({elementsToHighlight:X0(this.scene.getNonDeletedElements(),s,this.state,this.scene.getNonDeletedElementsMap())})});k(this,"maybeHandleCrop",(t,n)=>{if(!this.state.croppingElementId)return!1;let r=t.resize.handleType,i=t.lastCoords,[a,s]=Pt(i.x-t.resize.offset.x,i.y-t.resize.offset.y,n[j.CTRL_OR_CMD]?null:this.getEffectiveGridSize()),l=this.scene.getNonDeletedElementsMap().get(this.state.croppingElementId);if(r&&l&&Or(l)){let c=t.originalElements.get(l.id),m=ac(l)&&this.imageCache.get(l.fileId)?.image;if(c&&Or(c)&&m&&!(m instanceof Promise)){let[p,d]=Pt(i.x,i.y,n[j.CTRL_OR_CMD]?null:this.getEffectiveGridSize()),u={x:p-t.originInGrid.x,y:d-t.originInGrid.y};this.maybeCacheReferenceSnapPoints(n,[l]);let{snapOffset:b,snapLines:g}=Ff([l],[c],this,n,u,r);this.scene.mutateElement(l,oK(l,this.scene.getNonDeletedElementsMap(),r,m.naturalWidth,m.naturalHeight,a+b.x,s+b.y,n.shiftKey?c.width/c.height:void 0)),Jp(l,this.scene),this.setState({isCropping:r&&r!=="rotation",snapLines:g})}return!0}return!1});k(this,"maybeHandleResize",(t,n)=>{let r=this.scene.getSelectedElements(this.state),i=r.filter(p=>Lt(p)),a=t.resize.handleType;if(i.length>0&&a==="rotation"||r.length===1&&$t(r[0])||this.state.croppingElementId)return!1;this.setState({isResizing:a&&a!=="rotation",isRotating:a==="rotation",activeEmbeddable:null});let s=t.lastCoords,[l,c]=Pt(s.x-t.resize.offset.x,s.y-t.resize.offset.y,n[j.CTRL_OR_CMD]?null:this.getEffectiveGridSize()),m=new Map;if(i.forEach(p=>{V0(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]=Pt(s.x,s.y,n[j.CTRL_OR_CMD]?null:this.getEffectiveGridSize()),u={x:p-t.originInGrid.x,y:d-t.originInGrid.y},b=[...t.originalElements.values()];this.maybeCacheReferenceSnapPoints(n,r);let{snapOffset:g,snapLines:E}=Ff(r,ne(b,this.state),this,n,u,a);l+=g.x,c+=g.y,this.setState({snapLines:E})}if(yK(t.originalElements,a,r,this.scene,S4(n),C4(n),r.some(p=>Or(p))?!oc(n):oc(n),l,c,t.resize.center.x,t.resize.center.y)){let p=new Set;return i.forEach(d=>{X0(this.scene.getNonDeletedElements(),d,this.state,this.scene.getNonDeletedElementsMap()).forEach(u=>p.add(u))}),this.setState({elementsToHighlight:[...p]}),!0}return!1});k(this,"getContextMenuItems",t=>{let n=[];if(n.push(zd,Od),t==="canvas")return this.state.viewModeEnabled?[...n,Ca,lr,di,cr]:[oh,nt,zd,Od,Hd,nt,ju,_v,nt,Ca,ll,lr,di,cr];if(n.push(Hd),this.state.viewModeEnabled)return[Ia,...n];let r=this.editorInterface.formFactor==="desktop"?[nt,Ku,Xu,$u,Zu]:[];return[nt,Fd,Ia,oh,nt,d3,m3,p3,nt,kf,nt,...n,nt,Kg,Xg,nt,Zg,y3,ih,ah,xv,jg,nt,Qg,...r,nt,eh,th,nt,Xa,nt,ml,$d,nt,qu,pl,nt,zs]});k(this,"handleWheel",Ze(t=>{if(!(t.target instanceof HTMLCanvasElement||t.target instanceof HTMLTextAreaElement||t.target instanceof HTMLIFrameElement||t.target instanceof HTMLElement&&t.target.classList.contains(R0.FRAME_NAME))){t[j.CTRL_OR_CMD]&&t.preventDefault();return}if(t.preventDefault(),mc)return;let{deltaX:n,deltaY:r}=t;if(t.metaKey||t.ctrlKey){let i=Math.sign(r),a=JY*100,s=Math.abs(r),l=r;s>a&&(l=a*i);let c=this.state.zoom.value-l/100;c+=Math.log10(Math.max(1,this.state.zoom.value))*-i*Math.min(1,s/20),this.translateCanvas(m=>({...Sn({viewportX:this.lastViewportPosition.x,viewportY:this.lastViewportPosition.y,nextZoom:Go(c)},m),shouldCacheIgnoreZoom:!0})),this.resetShouldCacheIgnoreZoomDebounced();return}if(t.shiftKey){this.translateCanvas(({zoom:i,scrollX:a})=>({scrollX:a-(r||n)/i.value}));return}this.translateCanvas(({zoom:i,scrollX:a,scrollY:s})=>({scrollX:a-n/i.value,scrollY:s-r/i.value}))}));k(this,"savePointer",(t,n,r)=>{if(!t||!n)return;let{x:i,y:a}=Ue({clientX:t,clientY:n},this.state);isNaN(i)||isNaN(a);let s={x:i,y:a,tool:this.state.activeTool.type==="laser"?"laser":"pointer"};this.props.onPointerUpdate?.({pointer:s,button:r,pointersMap:Ce.pointers})});k(this,"resetShouldCacheIgnoreZoomDebounced",_4(()=>{this.unmounted||this.setState({shouldCacheIgnoreZoom:!1})},300));k(this,"updateDOMRect",t=>{if(this.excalidrawContainerRef?.current){let n=this.excalidrawContainerRef.current,{width:r,height:i,left:a,top:s}=n.getBoundingClientRect(),{width:l,height:c,offsetTop:m,offsetLeft:p}=this.state;if(r===l&&i===c&&a===p&&s===m){t&&t();return}this.setState({width:r,height:i,offsetLeft:a,offsetTop:s},()=>{t&&t()})}});k(this,"refresh",()=>{this.setState({...this.getCanvasOffsets()})});k(this,"watchState",()=>{});let n=Vn(),{excalidrawAPI:r,viewModeEnabled:i=!1,zenModeEnabled:a=!1,gridModeEnabled:s=!1,objectsSnapModeEnabled:l=!1,theme:c=n.theme,name:m=`${h("labels.untitled")}-${N4()}`}=t;if(this.state={...n,theme:c,isLoading:!0,...this.getCanvasOffsets(),viewModeEnabled:i,zenModeEnabled:a,objectsSnapModeEnabled:l,gridModeEnabled:s??n.gridModeEnabled,name:m,width:window.innerWidth,height:window.innerHeight},this.refreshEditorInterface(),this.stylesPanelMode=ou(this.editorInterface),this.id=S0(),this.library=new i2(this),this.actionManager=new Am(this.syncActionResult,()=>this.state,()=>this.scene.getElementsIncludingDeleted(),this),this.scene=new dk,this.canvas=document.createElement("canvas"),this.rc=zY.canvas(this.canvas),this.renderer=new _l(this.scene),this.visibleElements=[],this.store=new TK(this),this.history=new Ll(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 Yn(this.scene),this.history=new Ll(this.store),this.actionManager.registerAll(Vc),this.actionManager.registerAction(f3(this.history)),this.actionManager.registerAction(b3(this.history))}onWindowMessage(t){if(t.origin!=="https://player.vimeo.com"&&t.origin!=="https://www.youtube.com")return;let n=null;try{n=JSON.parse(t.data)}catch{}if(n)switch(t.origin){case"https://player.vimeo.com":if(n.method==="paused"){let r=null,i=document.body.querySelectorAll("iframe.excalidraw__embeddable");if(!i)break;for(let a of i)a.contentWindow===t.source&&(r=a.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,i=n.info.playerState;Object.values(Xp).includes(i)&&ob.set(r,i)}break}}handleSkipBindMode(){if(this.state.selectedLinearElement?.initialState&&!this.state.selectedLinearElement.initialState.arrowStartIsInside){bn(this.lastPointerMoveCoords,"Missing last pointer move coords when changing bind skip mode for arrow start");let t=this.scene.getNonDeletedElementsMap(),n=zo(ie(this.lastPointerMoveCoords.x,this.lastPointerMoveCoords.y),this.scene.getNonDeletedElements(),t),r=ve.getElement(this.state.selectedLinearElement.elementId,t);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),Xt(()=>{this.setState({bindMode:"skip"})}),this.lastPointerMoveCoords&&this.state.selectedLinearElement?.selectedPointsIndices&&this.state.selectedLinearElement?.selectedPointsIndices.length)){let{x:t,y:n}=this.lastPointerMoveCoords,r=this.lastPointerMoveEvent??this.lastPointerDownEvent?.nativeEvent;bn(r,"Last event must exist");let i=t-this.state.selectedLinearElement.pointerOffset.x,a=n-this.state.selectedLinearElement.pointerOffset.y,s=this.state.multiElement?ve.handlePointerMove(r,this,i,a,this.state.selectedLinearElement):ve.handlePointDragging(r,this,i,a,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(t,n){if(t.isDeleted||$t(t))return;let r=()=>{if(this.bindModeHandler=null,bn(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 b=this.state.selectedLinearElement.selectedPointsIndices.includes(0),g=this.state.selectedLinearElement.selectedPointsIndices.includes(t.points.length-1);if(!b&&!g||b&&g)return}let{x:p,y:d}=this.lastPointerMoveCoords,u=zo(ie(p,d),this.scene.getNonDeletedElements(),this.scene.getNonDeletedElementsMap());if(u&&this.state.bindMode!=="skip"){bn(this.state.selectedLinearElement?.elementId===t.id,"The selectedLinearElement is expected to not change while a bind mode timeout is ticking");let b=this.state.selectedLinearElement.initialState.arrowStartIsInside||t.startBinding?.elementId===u.id;Xt(()=>{bn(this.state.selectedLinearElement,"this.state.selectedLinearElement must exist"),this.setState({bindMode:"inside",selectedLinearElement:{...this.state.selectedLinearElement,initialState:{...this.state.selectedLinearElement.initialState,arrowStartIsInside:b}}})});let g=this.lastPointerMoveEvent??this.lastPointerDownEvent?.nativeEvent;bn(g,"Last event must exist");let E=p-this.state.selectedLinearElement.pointerOffset.x,w=d-this.state.selectedLinearElement.pointerOffset.y,x=this.state.multiElement?ve.handlePointerMove(g,this,E,w,this.state.selectedLinearElement):ve.handlePointDragging(g,this,E,w,this.state.selectedLinearElement);x&&this.setState(x)}},i=!1;if(this.state.selectedLinearElement?.selectedPointsIndices){let p=this.scene.getNonDeletedElementsMap(),d=this.state.selectedLinearElement.selectedPointsIndices.includes(0),u=this.state.selectedLinearElement.selectedPointsIndices.includes(t.points.length-1),b=d?n:t.startBinding&&p.get(t.startBinding.elementId),g=u?n:t.endBinding&&p.get(t.endBinding.elementId),E=b&&gk(b,p),w=g&&gk(g,p);i=!!(E&&w&&b.id!==g.id&&SK(E,w))}let a=this.state.selectedLinearElement?.selectedPointsIndices?.includes(0),s=this.state.selectedLinearElement?.selectedPointsIndices?.includes(t.points.length-1),l=a?"startBinding":s?"endBinding":null,c=a?"endBinding":s?"startBinding":null,m=c&&t[c]?.mode==="inside"&&t[c]?.elementId===n?.id||l&&t[l]?.mode==="inside"&&n?.id===t[l]?.elementId;l&&c&&t[l]?.mode==="inside"&&n?.id!==t[l]?.elementId&&t[c]?.elementId!==t[l]?.elementId&&this.scene.mutateElement(t,{[l]:{...t[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"&&Xt(()=>{this.setState({bindMode:"orbit"})}),this.previousHoveredBindableElement=null):!this.bindModeHandler&&(!this.state.newElement||!t.startBinding||i)&&!m&&(this.bindModeHandler=setTimeout(r,fV)),this.previousHoveredBindableElement=n}cacheEmbeddableRef(t,n){n&&this.iFrameRefs.set(t.id,n)}getHTMLIFrameElement(t){return this.iFrameRefs.get(t.id)}handleIframeLikeCenterClick(){if(!this.lastPointerDownEvent||!this.lastPointerUpEvent||this.lastPointerDownEvent.button!==Nr.MAIN||zr||!F4(this.state.activeTool.type,["laser","selection","lasso"]))return!1;let t=ie(Ue({clientX:this.lastPointerDownEvent.clientX,clientY:this.lastPointerDownEvent.clientY},this.state)),n=ie(Ue({clientX:this.lastPointerUpEvent.clientX,clientY:this.lastPointerUpEvent.clientY},this.state));if(Rr(t,n)>M4)return!1;let i=this.getElementAtPosition(t[0],t[1]);if(!(i&&this.lastPointerUpEvent.timeStamp-this.lastPointerDownEvent.timeStamp<=300&&Ce.pointers.size<2&&O0(i)&&(this.state.viewModeEnabled||this.state.activeTool.type==="laser"||this.isIframeLikeElementCenter(i,this.lastPointerUpEvent,n[0],n[1]))))return!1;let s=i;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),Es(s)))return!0;let l=this.getHTMLIFrameElement(s);if(!l?.contentWindow)return!0;if(l.src.includes("youtube")){let c=ob.get(s.id);switch(c||(ob.set(s.id,Xp.UNSTARTED),l.contentWindow.postMessage(JSON.stringify({event:"listening",id:s.id}),"*")),c){case Xp.PLAYING:case Xp.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(t,n,r,i){return t&&!n.altKey&&!n.shiftKey&&!n.metaKey&&!n.ctrlKey&&(this.state.activeEmbeddable?.element!==t||this.state.activeEmbeddable?.state==="hover"||!this.state.activeEmbeddable)&&r>=t.x+t.width/3&&r<=t.x+2*t.width/3&&i>=t.y+t.height/3&&i<=t.y+2*t.height/3}renderEmbeddables(){let t=this.state.zoom.value,n=this.state.width,r=this.state.height,i=this.scene.getNonDeletedElements().filter(a=>Wn(a)&&this.embedsValidationStatus.get(a.id)===!0||Es(a));return Te(xk,{children:i.map(a=>{let{x:s,y:l}=$p({sceneX:a.x,sceneY:a.y},this.state),c=K4(a,n,r,this.state,this.scene.getNonDeletedElementsMap()),m=this.initializedEmbeds.has(a.id);if(c&&!m&&this.initializedEmbeds.add(a.id),!(c||m))return null;let d;if(Es(a)){d=null;let g=(a.customData?.generationData??this.magicGenerations.get(a.id))||{status:"error",message:"No generation data",code:"ERR_NO_GENERATION_DATA"};if(g.status==="done"){let E=g.html;d={intrinsicSize:{w:a.width,h:a.height},type:"document",srcdoc:()=>E}}else if(g.status==="pending")d={intrinsicSize:{w:a.width,h:a.height},type:"document",srcdoc:()=>Z4(`
|
|
32
|
+
Please fix the Mermaid syntax and regenerate a valid diagram.`;await y({prompt:te,isRepairFlow:!0})},O=async D=>{let F=m.messages.findIndex(X=>X.id===D.id);if(F>0){let X=m.messages[F-1];X.type==="user"&&typeof X.content=="string"&&(g(),await y({prompt:X.content,isRepairFlow:!0}))}},U=()=>{Ac({app:i,data:E})},H=D=>{let F=m.messages.findIndex(te=>te.id===D&&te.type==="assistant"),X=m.messages.slice(0,F-1);p({...m,messages:X})},W=D=>{p(F=>({...F,currentPrompt:D}))};return LU("div",{className:`ttd-dialog-layout ${d?"ttd-dialog-layout--split":"ttd-dialog-layout--chat-only"}`,children:[kb(wk,{chatId:m.id,messages:m.messages,currentPrompt:m.currentPrompt,onPromptChange:W,onGenerate:y,isGenerating:b?.isGenerating??!1,generatedResponse:b?.content,isMenuOpen:w,onMenuToggle:M,onMenuClose:k,onNewChat:C,onRestoreChat:v,onDeleteChat:T,savedChats:u,activeSessionId:m.id,onAbort:x,onMermaidTabClick:A,onAiRepairClick:_,onDeleteMessage:H,onInsertMessage:P,onRetry:O,onViewAsMermaid:R,renderWarning:n,renderWelcomeScreen:o}),d&&kb(Tk,{canvasRef:s,hideErrorDetails:b?.errorType==="parse",error:l,loaded:e.loaded,onInsert:U})]})},AU=({mermaidToExcalidrawLib:e,onTextSubmit:t,renderWelcomeScreen:o,renderWarning:n,persistenceAdapter:r})=>kb(PU,{mermaidToExcalidrawLib:e,onTextSubmit:t,renderWelcomeScreen:o,renderWarning:n,persistenceAdapter:r}),Ik=AU;import{Tabs as _U}from"radix-ui";import{useRef as Ck}from"react";import{isMemberOf as DU}from"@orangecatai/common";import{jsx as RU}from"react/jsx-runtime";var kk=e=>{let t=ve(),o=Ck(null),n=Ck(0);return RU(_U.Root,{ref:o,className:"ttd-dialog-tabs-root",value:e.tab,onValueChange:r=>{if(!r)return;let i=o.current?.closest(".Modal__content");if(i){let a=i.offsetHeight||0;a>n.current&&(n.current=a,i.style.minHeight=`min(${n.current}px, 100%)`)}e.dialog==="ttd"&&DU(["text-to-diagram","mermaid"],r)&&t({openDialog:{name:e.dialog,tab:r}})},children:e.children})};kk.displayName="TTDDialogTabs";var Sk=kk;import{Tabs as NU}from"radix-ui";import{jsx as BU}from"react/jsx-runtime";var Sb=({children:e,...t})=>BU(NU.List,{className:"ttd-dialog-triggers",...t,children:e});Sb.displayName="TTDDialogTabTriggers";import{Tabs as FU}from"radix-ui";import{jsx as Mk}from"react/jsx-runtime";var du=({children:e,tab:t,onSelect:o,...n})=>Mk(FU.Trigger,{value:t,asChild:!0,onSelect:o,children:Mk("button",{type:"button",className:"ttd-dialog-tab-trigger",...n,children:e})});du.displayName="TTDDialogTabTrigger";import{Tabs as zU}from"radix-ui";import{jsx as OU}from"react/jsx-runtime";var mu=({tab:e,children:t,...o})=>OU(zU.Content,{...o,value:e,children:t});mu.displayName="TTDDialogTab";import{jsx as _n,jsxs as Mb}from"react/jsx-runtime";var pu=e=>{let t=Ee();return t.openDialog?.name!=="ttd"?null:_n(UU,{...e,tab:t.openDialog.tab})};pu.WelcomeMessage=iu;var UU=sr("TTDDialogBase",({tab:e,...t})=>{let o=Xe(),[n,r]=GU({loaded:!1,api:import("@excalidraw/mermaid-to-excalidraw")});return HU(()=>{(async()=>{await n.api,r(a=>({...a,loaded:!0}))})()},[n.api]),_n(dt,{className:"ttd-dialog",onCloseRequest:()=>{o.setOpenDialog(null)},size:1520,title:!1,...t,autofocus:!1,children:Mb(Sk,{dialog:"ttd",tab:e,children:["__fallback"in t&&t.__fallback?_n("p",{className:"dialog-mermaid-title",children:h("mermaid.title")}):Mb(Sb,{children:[_n(du,{tab:"text-to-diagram",children:Mb("div",{className:"ttd-dialog-tab-trigger__content",children:[h("labels.textToDiagram"),_n("div",{className:"ttd-dialog-tab-trigger__badge",children:h("chat.aiBeta")})]})}),_n(du,{tab:"mermaid",children:h("mermaid.label")})]}),!("__fallback"in t)&&_n(mu,{className:"ttd-dialog-content",tab:"text-to-diagram",children:_n(Ik,{mermaidToExcalidrawLib:n,onTextSubmit:t.onTextSubmit,renderWelcomeScreen:t.renderWelcomeScreen,renderWarning:t.renderWarning,persistenceAdapter:t.persistenceAdapter})}),_n(mu,{className:"ttd-dialog-content",tab:"mermaid",children:_n(ak,{mermaidToExcalidrawLib:n,isActive:e==="mermaid"})})]})})});import{round as hS}from"@orangecatai/math";import oY from"clsx";import nY from"lodash.throttle";import{useEffect as fS,useMemo as Ub,useState as rY,memo as iY}from"react";import{STATS_PANELS as yu}from"@orangecatai/common";import{getCommonBounds as aY}from"@orangecatai/element";import{getUncroppedWidthAndHeight as sY}from"@orangecatai/element";import{isImageElement as Wb}from"@orangecatai/element";import{frameAndChildrenSelectedTogether as lY}from"@orangecatai/element";import{elementsAreInSameGroup as cY}from"@orangecatai/element";import{degreesToRadians as Bk,radiansToDegrees as Hk}from"@orangecatai/math";import{getBoundTextElement as Fk}from"@orangecatai/element";import{isArrowElement as zk,isElbowArrow as tW}from"@orangecatai/element";import{updateBindings as Ok}from"@orangecatai/element";import ZU from"clsx";import{useEffect as Rk,useRef as gu,useState as jU}from"react";import{EVENT as Ws,KEYS as qU,cloneJSON as Pb}from"@orangecatai/common";import{deepCopyElement as JU}from"@orangecatai/element";import{CaptureUpdateAction as Nk}from"@orangecatai/element";import{pointFrom as Jr,pointRotateRads as uu}from"@orangecatai/math";import{getBoundTextElement as WU,isBindingElement as YU,unbindBindingElement as Pk}from"@orangecatai/element";import{isFrameLikeElement as _k}from"@orangecatai/element";import{getSelectedGroupIds as VU,getElementsInGroup as KU,isInGroup as XU}from"@orangecatai/element";import{getFrameChildren as $U}from"@orangecatai/element";import{updateBindings as Ak}from"@orangecatai/element";import{DRAGGING_THRESHOLD as Lk}from"@orangecatai/common";var Dk=.01,Rc=10,so=(e,t)=>!(t==="angle"&&_k(e)),Qe=(e,t)=>{let o=e+t/2;return o-o%t},Gs=(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 Ji=(e,t,o,n,r,i,a=!0)=>{if(YU(o)&&(o.startBinding||o.endBinding)){if(Math.abs(e-o.x)<Lk&&Math.abs(t-o.y)<Lk)return;Pk(o,"start",n),Pk(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]=uu(Jr(o.x,o.y),Jr(c,m),o.angle),u=e-p,b=t-d,[g,E]=uu(Jr(e,t),Jr(c+u,m+b),-o.angle);n.mutateElement(l,{x:g,y:E},{informMutation:a,isDragging:!1}),Ak(l,n,r);let y=WU(o,i);if(y){let x=s.get(y.id);x&&n.mutateElement(x,{x:y.x+u,y:y.y+b},{informMutation:a,isDragging:!1})}if(_k(o)){let x=$U(i,o.id);x.forEach(w=>{let v=s.get(w.id);if(!v)return;let[T,C]=[w.x+w.width/2,w.y+w.height/2],[M,k]=uu(Jr(w.x,w.y),Jr(T,C),w.angle),R=Math.round(M+u),A=Math.round(k+b),[P,_]=uu(Jr(R,A),Jr(T+u,C+b),-w.angle);n.mutateElement(v,{x:P,y:_},{informMutation:a,isDragging:!1}),Ak(v,n,r,{simultaneouslyUpdated:x})})}},Us=(e,t)=>{let n=VU(t).map(r=>KU(e,r).reduce((i,a)=>(i[a.id]=!0,i),{}));return e.filter(r=>!XU(r)).forEach(r=>{n.push({[r.id]:!0})}),n};import{jsx as Ab,jsxs as eW}from"react/jsx-runtime";var QU=({label:e,icon:t,dragInputCallback:o,value:n,elements:r,editable:i=!0,shouldKeepAspectRatio:a,property:s,scene:l,appState:c,sensitivity:m=1,dragFinishedCallback:p})=>{let d=Xe(),u=ve(),b=gu(null),g=gu(null),[E,y]=jU(n.toString()),x=gu(null);x.current||(x.current={originalAppState:Pb(c),originalElements:r,lastUpdatedValue:E,updatePending:!1}),Rk(()=>{let T=n.toString();y(T),x.current.lastUpdatedValue=T},[n]);let w=(T,C,M)=>{if(!x.current.updatePending)return!1;x.current.updatePending=!1;let k=Number(T);if(isNaN(k)){y(n.toString());return}let R=Number(k.toFixed(2)),A=Number(n);(isNaN(A)||Math.abs(R-A)>=Dk)&&(x.current.lastUpdatedValue=T,o({accumulatedChange:0,instantChange:0,originalElements:C,originalElementsMap:d.scene.getNonDeletedElementsMap(),shouldKeepAspectRatio:a,shouldChangeByStepSize:!1,scene:l,nextValue:R,property:s,originalAppState:M,setInputValue:P=>y(String(P)),app:d,setAppState:u}),d.syncActionResult({captureUpdate:Nk.IMMEDIATELY}))},v=gu({});return v.current.handleInputValue=w,Rk(()=>{let T=b.current,C=v.current;return()=>{let M=T?.value;M&&C.handleInputValue?.(M,x.current.originalElements,x.current.originalAppState),window.removeEventListener(Ws.POINTER_MOVE,C.onPointerMove,!1),window.removeEventListener(Ws.POINTER_UP,C.onPointerUp,!1)}},[i]),i?eW("div",{className:ZU("drag-input-container",!i&&"disabled"),"data-testid":e,children:[Ab("div",{className:"drag-input-label",ref:g,onPointerDown:T=>{if(b.current&&i){document.body.classList.add("excalidraw-cursor-resize");let C=Number(b.current.value);isNaN(C)&&(C=0);let M=null,k=d.scene.getNonDeletedElements().reduce((H,W)=>(H.set(W.id,JU(W)),H),new Map),R=r.map(H=>k.get(H.id)),A=Pb(c),P=0,_=0,O=H=>{if(M&&k!==null&&R!==null){let W=H.clientX-M.x;W!==0&&(_+=W,Math.abs(_)>=m&&(_=Math.sign(_)*Math.floor(Math.abs(_)/m),P+=_,o({accumulatedChange:P,instantChange:_,originalElements:R,originalElementsMap:k,shouldKeepAspectRatio:a,shouldChangeByStepSize:H.shiftKey,property:s,scene:l,originalAppState:A,setInputValue:D=>y(String(D)),app:d,setAppState:u}),_=0))}M={x:H.clientX,y:H.clientY}},U=()=>{window.removeEventListener(Ws.POINTER_MOVE,O,!1),d.syncActionResult({captureUpdate:Nk.IMMEDIATELY}),p?.({app:d,setAppState:u,originalElements:R,originalAppState:A}),M=null,P=0,_=0,R=null,k=null,document.body.classList.remove("excalidraw-cursor-resize"),window.removeEventListener(Ws.POINTER_UP,U,!1)};v.current.onPointerMove=O,v.current.onPointerUp=U,window.addEventListener(Ws.POINTER_MOVE,O,!1),window.addEventListener(Ws.POINTER_UP,U,!1)}},onPointerEnter:()=>{g.current&&(g.current.style.cursor="ew-resize")},children:t?Ab(xn,{icon:t}):e}),Ab("input",{className:"drag-input",autoComplete:"off",spellCheck:"false",onKeyDown:T=>{if(i){let C=T.target;C instanceof HTMLInputElement&&T.key===qU.ENTER&&(w(C.value,r,c),d.focusContainer())}},ref:b,value:E,onChange:T=>{x.current.updatePending=!0,y(T.target.value)},onFocus:T=>{T.target.select(),x.current.originalElements=r,x.current.originalAppState=Pb(c)},onBlur:T=>{E?i&&w(T.target.value,x.current.originalElements,x.current.originalAppState):y(n.toString())},disabled:!i})]}):null},Lt=QU;import{jsx as iW}from"react/jsx-runtime";var oW=15,nW=({accumulatedChange:e,originalElements:t,shouldChangeByStepSize:o,nextValue:n,scene:r,app:i})=>{let a=r.getNonDeletedElementsMap(),s=t[0];if(s&&!tW(s)){let l=a.get(s.id);if(!l)return;if(n!==void 0){let b=Bk(n);r.mutateElement(l,{angle:b}),Ok(l,r,i.state);let g=Fk(l,a);g&&!zk(l)&&r.mutateElement(g,{angle:b});return}let c=Math.round(Hk(s.angle)*100)/100,m=Math.round(e),p=(c+m)%360;o&&(p=Qe(p,oW)),p=p<0?p+360:p;let d=Bk(p);r.mutateElement(l,{angle:d}),Ok(l,r,i.state);let u=Fk(l,a);u&&!zk(l)&&r.mutateElement(u,{angle:d})}},rW=({element:e,scene:t,appState:o,property:n})=>iW(Lt,{label:"A",icon:kd,value:Math.round(Hk(e.angle)%360*100)/100,elements:[e],dragInputCallback:nW,editable:so(e,"angle"),scene:t,appState:o,property:n}),Gk=rW;import{jsx as sW}from"react/jsx-runtime";var Uk=5,aW=({property:e,scene:t,appState:o,setAppState:n})=>sW(Lt,{label:"Grid step",sensitivity:8,elements:[],dragInputCallback:({nextValue:r,instantChange:i,shouldChangeByStepSize:a,setInputValue:s})=>{n(l=>{let c;return r?c=r:i&&(c=a?Qe(l.gridStep+Uk*Math.sign(i),Uk):l.gridStep+i),c?(c=Cx(c),s(c),{gridStep:c}):(s(l.gridStep),null)})},scene:t,value:o.gridStep,property:e,appState:o}),Wk=aW;import{clamp as hu,round as Lb}from"@orangecatai/math";import{MIN_WIDTH_OR_HEIGHT as fu}from"@orangecatai/common";import{MINIMAL_CROP_SIZE as Yk,getUncroppedWidthAndHeight as Xk}from"@orangecatai/element";import{resizeSingleElement as Vk}from"@orangecatai/element";import{isImageElement as $k}from"@orangecatai/element";import{isFrameLikeElement as _b}from"@orangecatai/element";import{getElementsInResizingFrame as Db}from"@orangecatai/element";import{replaceAllElementsInFrame as Zk}from"@orangecatai/element";import{jsx as pW}from"react/jsx-runtime";var Kk=10,lW=e=>e.type==="image",cW=({accumulatedChange:e,originalElements:t,originalElementsMap:o,shouldKeepAspectRatio:n,shouldChangeByStepSize:r,nextValue:i,property:a,originalAppState:s,instantChange:l,scene:c,app:m,setAppState:p})=>{let d=c.getNonDeletedElementsMap(),u=t[0],b=d.get(u.id);if(u&&b){let g=n||lW(u),E=u.width/u.height;if(s.croppingElementId===u.id){let y=d.get(u.id);if(!y||!$k(y)||!y.crop)return;let x=y.crop,w={...x},v=y.scale[0]===-1,T=y.scale[1]===-1,{width:C,height:M}=Xk(y),k=x.naturalWidth/C,R=x.naturalHeight/M,A=v?x.width+x.x:x.naturalWidth-x.x,P=T?x.height+x.y:x.naturalHeight-x.y,_=Yk*k,O=Yk*R;if(i!==void 0){if(a==="width"){let F=i*k,X=hu(F,_,A);w={...w,width:X,x:v?x.x+x.width-X:x.x}}else if(a==="height"){let F=i*R,X=hu(F,O,P);w={...w,height:X,y:T?x.y+x.height-X:x.y}}c.mutateElement(y,{crop:w,width:w.width/(x.naturalWidth/C),height:w.height/(x.naturalHeight/M)});return}let U=a==="width"?l:0,H=a==="height"?l:0,W=hu(x.width+U,_,A),D=hu(x.height+H,_,P);w={...x,x:v?x.x+x.width-W:x.x,y:T?x.y+x.height-D:x.y,width:W,height:D},c.mutateElement(y,{crop:w,width:w.width/(x.naturalWidth/C),height:w.height/(x.naturalHeight/M)});return}if(i!==void 0){let y=Math.max(a==="width"?i:g?i*E:u.width,fu),x=Math.max(a==="height"?i:g?i/E:u.height,fu);if(Vk(y,x,b,u,o,c,a==="width"?"e":"s",{shouldMaintainAspectRatio:g}),_b(b)){let w=Db(c.getElementsIncludingDeleted(),b,s,c.getNonDeletedElementsMap()),v=Zk(c.getElementsIncludingDeleted(),w,b,m);c.replaceAllElements(v)}return}{let y=a==="width"?e:0,x=a==="height"?e:0,w=Math.max(0,u.width+y);a==="width"&&(r?w=Qe(w,Kk):w=Math.round(w));let v=Math.max(0,u.height+x);if(a==="height"&&(r?v=Qe(v,Kk):v=Math.round(v)),g&&(a==="width"?v=Math.round(w/E*100)/100:w=Math.round(v*E*100)/100),v=Math.max(fu,v),w=Math.max(fu,w),Vk(w,v,b,u,o,c,a==="width"?"e":"s",{shouldMaintainAspectRatio:g}),_b(b)){let T=Db(c.getElementsIncludingDeleted(),b,s,c.getNonDeletedElementsMap());p({elementsToHighlight:T})}}}},dW=({setAppState:e,app:t,originalElements:o,originalAppState:n})=>{let r=t.scene.getNonDeletedElementsMap(),i=o?.[0],a=i&&r.get(i.id);if(a&&_b(a)){let s=Db(t.scene.getElementsIncludingDeleted(),a,n,t.scene.getNonDeletedElementsMap()),l=Zk(t.scene.getElementsIncludingDeleted(),s,a,t);t.scene.replaceAllElements(l),e({elementsToHighlight:null})}},mW=({property:e,element:t,scene:o,appState:n})=>{let r=Lb(e==="width"?t.width:t.height,2);if(n.croppingElementId&&n.croppingElementId===t.id&&$k(t)&&t.crop){let{width:i,height:a}=Xk(t);if(e==="width"){let s=i/t.crop.naturalWidth;r=Lb(t.crop.width*s,2)}if(e==="height"){let s=a/t.crop.naturalHeight;r=Lb(t.crop.height*s,2)}}return pW(Lt,{label:e==="width"?"W":"H",elements:[t],dragInputCallback:cW,value:r,editable:so(t,e),scene:o,appState:n,property:e,dragFinishedCallback:dW})},Rb=mW;import{getBoundTextElement as uW,redrawTextBoundingBox as gW}from"@orangecatai/element";import{hasBoundTextElement as hW,isTextElement as qk}from"@orangecatai/element";import{jsx as EW}from"react/jsx-runtime";var jk=4,fW=4,bW=({accumulatedChange:e,originalElements:t,shouldChangeByStepSize:o,nextValue:n,scene:r})=>{let i=r.getNonDeletedElementsMap(),a=t[0];if(a){let s=i.get(a.id);if(!s||!qk(s))return;let l;if(n!==void 0)l=Math.max(Math.round(n),jk);else if(a.type==="text"){let c=Math.round(a.fontSize),m=Math.round(e);l=Math.max(c+m,jk),o&&(l=Qe(l,fW))}l&&(r.mutateElement(s,{fontSize:l}),gW(s,r.getContainerElement(s),r))}},xW=({element:e,scene:t,appState:o,property:n})=>{let r=qk(e)?e:hW(e)?uW(e,t.getNonDeletedElementsMap()):null;return r?EW(Lt,{label:"F",value:Math.round(r.fontSize*10)/10,elements:[r],dragInputCallback:bW,icon:yi,appState:o,scene:t,property:n}):null},Jk=xW;import{degreesToRadians as Qk,radiansToDegrees as oS}from"@orangecatai/math";import{getBoundTextElement as eS}from"@orangecatai/element";import{isArrowElement as tS}from"@orangecatai/element";import{isInGroup as Nb}from"@orangecatai/element";import{jsx as TW}from"react/jsx-runtime";var yW=15,wW=({accumulatedChange:e,originalElements:t,shouldChangeByStepSize:o,nextValue:n,property:r,scene:i})=>{let a=i.getNonDeletedElementsMap(),s=t.map(c=>a.get(c.id)).filter(c=>c&&!Nb(c)&&so(c,r)),l=t.filter(c=>!Nb(c)&&so(c,r));if(n!==void 0){let c=Qk(n);for(let m of s){if(!m)continue;i.mutateElement(m,{angle:c});let p=eS(m,a);p&&!tS(m)&&i.mutateElement(p,{angle:c})}i.triggerUpdate();return}for(let c=0;c<s.length;c++){let m=s[c];if(!m)continue;let p=l[c],d=Math.round(oS(p.angle)*100)/100,u=Math.round(e),b=(d+u)%360;o&&(b=Qe(b,yW)),b=b<0?b+360:b;let g=Qk(b);i.mutateElement(m,{angle:g});let E=eS(m,a);E&&!tS(m)&&i.mutateElement(E,{angle:g})}i.triggerUpdate()},vW=({elements:e,scene:t,appState:o,property:n})=>{let r=e.filter(l=>!Nb(l)&&so(l,"angle")),i=r.map(l=>Math.round(oS(l.angle)%360*100)/100),a=new Set(i).size===1?i[0]:"Mixed",s=r.some(l=>so(l,"angle"));return TW(Lt,{label:"A",icon:kd,value:a,elements:e,dragInputCallback:wW,editable:s,appState:o,scene:t,property:n})},nS=vW;import{pointFrom as rS}from"@orangecatai/math";import{useMemo as IW}from"react";import{MIN_WIDTH_OR_HEIGHT as Qr}from"@orangecatai/common";import{getElementsInResizingFrame as Bb,isFrameLikeElement as Fb,replaceAllElementsInFrame as sS,updateBoundElements as CW}from"@orangecatai/element";import{rescalePointsInElement as kW,resizeSingleElement as iS}from"@orangecatai/element";import{getBoundTextElement as SW,handleBindTextResize as MW}from"@orangecatai/element";import{isTextElement as lS}from"@orangecatai/element";import{getCommonBounds as bu}from"@orangecatai/element";import{jsx as RW}from"react/jsx-runtime";var Ys=10,PW=(e,t,o,n)=>{let r=n.x-e,i=n.y-t,a=n.width*o,s=n.height*o,l=e+r*o,c=t+i*o;return{width:a,height:s,x:l,y:c,...kW(n,a,s,!1),...lS(n)?{fontSize:n.fontSize*o}:{}}},AW=(e,t,o,n,r,i,a,s)=>{let l=s.getNonDeletedElementsMap(),c=PW(e,t,n,i);s.mutateElement(r,c);let m=SW(i,a);if(m){let p=m.fontSize*n;CW(r,s);let d=l.get(m.id);d&&lS(d)&&(s.mutateElement(d,{fontSize:p}),MW(r,s,o==="width"?"e":"s",!0))}},aS=(e,t,o,n,r,i,a,s,l,c)=>{i==="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=a[p];AW(r[0],r[1],i,m,u,d,l,c)}},LW=({accumulatedChange:e,originalElements:t,originalElementsMap:o,originalAppState:n,shouldChangeByStepSize:r,nextValue:i,scene:a,property:s,setAppState:l,app:c})=>{let m=a.getNonDeletedElementsMap(),p=Us(t,n);if(i!==void 0){for(let g of p){let E=Gs(g,m,o);if(E.length>1){let y=E.map(_=>_.latest),x=E.map(_=>_.original),[w,v,T,C]=bu(x),M=T-w,k=C-v,R=M/k,A=Math.max(Qr,s==="width"?Math.max(0,i):M),P=Math.max(Qr,s==="height"?Math.max(0,i):k);aS(A,P,k,R,rS(w,v),s,y,x,o,a)}else{let[y]=E,x=y?.latest,w=y?.original;if(x&&w&&so(x,s)){let v=s==="width"?Math.max(0,i):x.width;s==="width"&&(r?v=Qe(v,Ys):v=Math.round(v));let T=s==="height"?Math.max(0,i):x.height;if(s==="height"&&(r?T=Qe(T,Ys):T=Math.round(T)),v=Math.max(Qr,v),T=Math.max(Qr,T),iS(v,T,x,w,o,a,s==="width"?"e":"s",{shouldInformMutation:!1}),Fb(x)){let C=Bb(a.getElementsIncludingDeleted(),x,n,a.getNonDeletedElementsMap()),M=sS(a.getElementsIncludingDeleted(),C,x,c);a.replaceAllElements(M)}}}}a.triggerUpdate();return}let d=s==="width"?e:0,u=s==="height"?e:0,b=[];for(let g of p){let E=Gs(g,m,o);if(E.length>1){let y=E.map(_=>_.latest),x=E.map(_=>_.original),[w,v,T,C]=bu(x),M=T-w,k=C-v,R=M/k,A=Math.max(0,M+d);s==="width"&&(r?A=Qe(A,Ys):A=Math.round(A));let P=Math.max(0,k+u);s==="height"&&(r?P=Qe(P,Ys):P=Math.round(P)),A=Math.max(Qr,A),P=Math.max(Qr,P),aS(A,P,k,R,rS(w,v),s,y,x,o,a)}else{let[y]=E,x=y?.latest,w=y?.original;if(x&&w&&so(x,s)){let v=Math.max(0,w.width+d);s==="width"&&(r?v=Qe(v,Ys):v=Math.round(v));let T=Math.max(0,w.height+u);if(s==="height"&&(r?T=Qe(T,Ys):T=Math.round(T)),v=Math.max(Qr,v),T=Math.max(Qr,T),iS(v,T,x,w,o,a,s==="width"?"e":"s",{shouldInformMutation:!1}),Fb(x)){let C=Bb(a.getElementsIncludingDeleted(),x,n,a.getNonDeletedElementsMap());b.push(...C)}}}}l({elementsToHighlight:b}),a.triggerUpdate()},_W=({setAppState:e,app:t,originalElements:o,originalAppState:n})=>{let r=t.scene.getNonDeletedElementsMap(),i=o?.[0],a=i&&r.get(i.id);if(a&&Fb(a)){let s=Bb(t.scene.getElementsIncludingDeleted(),a,n,t.scene.getNonDeletedElementsMap()),l=sS(t.scene.getElementsIncludingDeleted(),s,a,t);t.scene.replaceAllElements(l),e({elementsToHighlight:null})}},DW=({property:e,elements:t,elementsMap:o,atomicUnits:n,scene:r,appState:i})=>{let a=IW(()=>n.map(c=>{let m=Gs(c,o);if(m.length>1){let[d,u,b,g]=bu(m.map(E=>E.latest));return Math.round((e==="width"?b-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(a).size===1?Math.round(a[0]*100)/100:"Mixed",l=a.length>0;return RW(Lt,{label:e==="width"?"W":"H",elements:t,dragInputCallback:LW,value:s,editable:l,appState:i,property:e,scene:r,dragFinishedCallback:_W})},zb=DW;import{getBoundTextElement as NW,redrawTextBoundingBox as cS}from"@orangecatai/element";import{hasBoundTextElement as BW,isTextElement as FW}from"@orangecatai/element";import{isInGroup as zW}from"@orangecatai/element";import{jsx as WW}from"react/jsx-runtime";var dS=4,OW=4,HW=(e,t)=>e.reduce((o,n)=>{if(!n||zW(n))return o;if(FW(n))return o.push(n),o;if(BW(n)){let r=NW(n,t);if(r)return o.push(r),o}return o},[]),GW=({accumulatedChange:e,originalElements:t,shouldChangeByStepSize:o,nextValue:n,scene:r})=>{let i=r.getNonDeletedElementsMap(),a=t.map(l=>i.get(l.id)),s;if(n){s=Math.max(Math.round(n),dS);for(let l of a)r.mutateElement(l,{fontSize:s}),cS(l,r.getContainerElement(l),r);r.triggerUpdate()}else{let l=t;for(let c=0;c<a.length;c++){let m=a[c],p=l[c],d=Math.round(p.fontSize),u=Math.round(e),b=Math.max(d+u,dS);o&&(b=Qe(b,OW)),r.mutateElement(m,{fontSize:b}),cS(m,r.getContainerElement(m),r)}r.triggerUpdate()}},UW=({elements:e,scene:t,appState:o,property:n,elementsMap:r})=>{let i=HW(e,r);if(!i.length)return null;let a=i.map(c=>Math.round(c.fontSize*10)/10),s=new Set(a).size===1?a[0]:"Mixed",l=a.length>0;return WW(Lt,{label:"F",icon:yi,elements:i,dragInputCallback:GW,value:s,editable:l,scene:t,property:n,appState:o})},mS=UW;import{pointFrom as ei,pointRotateRads as xu}from"@orangecatai/math";import{useMemo as YW}from"react";import{isTextElement as VW}from"@orangecatai/element";import{getCommonBounds as Ob}from"@orangecatai/element";import{jsx as jW}from"react/jsx-runtime";var KW=(e,t,o,n,r,i,a)=>{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]=xu(ei(l.x,l.y),ei(c,m),l.angle),u=e==="x"?Math.round(p+t):p,b=e==="y"?Math.round(d+o):d;Ji(u,b,l,i,a,r,!1)}},XW=(e,t,o,n,r,i)=>{let a=r.getNonDeletedElementsMap(),[s,l,,]=Ob(o),c=e-s,m=t-l;for(let p=0;p<o.length;p++){let d=o[p],u=a.get(d.id);if(u&&(!VW(u)||!u.containerId)){let[b,g]=[u.x+u.width/2,u.y+u.height/2],[E,y]=xu(ei(u.x,u.y),ei(b,g),u.angle);Ji(E+c,y+m,d,r,i,n,!1)}}},$W=({accumulatedChange:e,originalElements:t,originalElementsMap:o,shouldChangeByStepSize:n,nextValue:r,property:i,scene:a,originalAppState:s,app:l})=>{let c=a.getNonDeletedElementsMap();if(r!==void 0){for(let u of Us(t,s)){let b=Gs(u,c,o);if(b.length>1){let[g,E,,]=Ob(b.map(w=>w.latest));XW(i==="x"?r:g,i==="y"?r:E,b.map(w=>w.original),o,a,l.state)}else{let g=b[0]?.original,E=b[0]?.latest;if(g&&E&&so(E,i)){let[y,x]=[g.x+g.width/2,g.y+g.height/2],[w,v]=xu(ei(g.x,g.y),ei(y,x),g.angle);Ji(i==="x"?r:w,i==="y"?r:v,g,a,l.state,o,!1)}}}a.triggerUpdate();return}let m=n?Qe(e,Rc):e;KW(i,i==="x"?m:0,i==="y"?m:0,t,o,a,l.state),a.triggerUpdate()},ZW=({property:e,elements:t,elementsMap:o,atomicUnits:n,scene:r,appState:i})=>{let a=YW(()=>n.map(l=>{let c=Object.keys(l).map(g=>o.get(g)).filter(g=>g!==void 0);if(c.length>1){let[g,E]=Ob(c);return Math.round((e==="x"?g:E)*100)/100}let[m]=c,[p,d]=[m.x+m.width/2,m.y+m.height/2],[u,b]=xu(ei(m.x,m.y),ei(p,d),m.angle);return Math.round((e==="x"?u:b)*100)/100}),[n,o,e]),s=new Set(a).size===1?a[0]:"Mixed";return jW(Lt,{label:e==="x"?"X":"Y",elements:t,dragInputCallback:$W,value:s,property:e,scene:r,appState:i})},Hb=ZW;import{clamp as Nc,pointFrom as Eu,pointRotateRads as uS,round as pS}from"@orangecatai/math";import{getFlipAdjustedCropPosition as qW,getUncroppedWidthAndHeight as JW}from"@orangecatai/element";import{isImageElement as gS}from"@orangecatai/element";import{jsx as tY}from"react/jsx-runtime";var QW=({accumulatedChange:e,instantChange:t,originalElements:o,originalElementsMap:n,shouldChangeByStepSize:r,nextValue:i,property:a,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],[b,g]=uS(Eu(p.x,p.y),Eu(d,u),p.angle);if(l.croppingElementId===p.id){let v=m.get(p.id);if(!v||!gS(v)||!v.crop)return;let T=v.crop,C=T,M=v.scale[0]===-1,k=v.scale[1]===-1,{width:R,height:A}=JW(v);if(i!==void 0){if(a==="x"){let O=i*(T.naturalWidth/R);M?C={...T,x:Nc(T.naturalWidth-O-T.width,0,T.naturalWidth-T.width)}:C={...T,x:Nc(i*(T.naturalWidth/R),0,T.naturalWidth-T.width)}}a==="y"&&(C={...T,y:Nc(i*(T.naturalHeight/A),0,T.naturalHeight-T.height)}),s.mutateElement(v,{crop:C});return}let P=(a==="x"?t:0)*(M?-1:1),_=(a==="y"?t:0)*(k?-1:1);C={...T,x:Nc(T.x+P,0,T.naturalWidth-T.width),y:Nc(T.y+_,0,T.naturalHeight-T.height)},s.mutateElement(v,{crop:C});return}if(i!==void 0){Ji(a==="x"?i:b,a==="y"?i:g,p,s,c.state,n);return}let E=a==="x"?e:0,y=a==="y"?e:0,x=a==="x"?Math.round(r?Qe(p.x+E,Rc):b+E):b,w=a==="y"?Math.round(r?Qe(p.y+y,Rc):g+y):g;Ji(x,w,p,s,c.state,n)},eY=({property:e,element:t,elementsMap:o,scene:n,appState:r})=>{let[i,a]=uS(Eu(t.x,t.y),Eu(t.x+t.width/2,t.y+t.height/2),t.angle),s=pS(e==="x"?i:a,2);if(r.croppingElementId===t.id&&gS(t)&&t.crop){let l=qW(t);l&&(s=pS(e==="x"?l.x:l.y,2))}return tY(Lt,{label:e==="x"?"X":"Y",elements:[t],dragInputCallback:QW,scene:n,value:s,property:e,appState:r})},Gb=eY;import{Fragment as Yb,jsx as le,jsxs as lo}from"react/jsx-runtime";var dY=50,Bc=e=>{let t=fn(),o=e.app.scene.getSceneNonce()||1,n=e.app.scene.getSelectedElements({selectedElementIds:t.selectedElementIds,includeBoundTextElement:!1}),r=Ur(e.app);return le(mY,{...e,appState:t,sceneNonce:o,selectedElements:n,gridModeEnabled:r})},$e=({children:e,columns:t=1,heading:o,style:n,...r})=>le("div",{className:oY("exc-stats__row",{"exc-stats__row--heading":o}),style:{gridTemplateColumns:`repeat(${t}, 1fr)`,...n},...r,children:e});$e.displayName="StatsRow";var wu=({children:e,order:t,style:o,...n})=>le("div",{className:"exc-stats__rows",style:{order:t,...o},...n,children:e});wu.displayName="StatsRows";Bc.StatsRow=$e;Bc.StatsRows=wu;var mY=iY(({app:e,onClose:t,renderCustomStats:o,selectedElements:n,appState:r,sceneNonce:i,gridModeEnabled:a})=>{let s=e.scene,l=s.getNonDeletedElements(),c=s.getNonDeletedElementsMap(),m=ve(),p=n.length===1?n[0]:null,d=n.length>1?n:null,u=r.croppingElementId&&Wb(p),b=u?sY(p):null,[g,E]=rY({width:0,height:0}),y=Ub(()=>nY(v=>{let T=aY(v);E({width:Math.round(T[2])-Math.round(T[0]),height:Math.round(T[3])-Math.round(T[1])})},dY),[]);fS(()=>{y(l)},[i,l,y]),fS(()=>()=>y.cancel(),[y]);let x=Ub(()=>Us(n,r),[n,r]),w=Ub(()=>lY(n),[n]);return le("div",{className:"exc-stats",children:lo(st,{padding:3,children:[lo("div",{className:"title",children:[le("h2",{children:h("stats.title")}),le("div",{className:"close",onClick:t,children:To})]}),lo(Nl,{label:le("h3",{children:h("stats.generalStats")}),open:!!(r.stats.panels&yu.generalStats),openTrigger:()=>m(v=>({stats:{open:!0,panels:v.stats.panels^yu.generalStats}})),children:[lo(wu,{children:[le($e,{heading:!0,children:h("stats.scene")}),lo($e,{columns:2,children:[le("div",{children:h("stats.shapes")}),le("div",{children:l.length})]}),lo($e,{columns:2,children:[le("div",{children:h("stats.width")}),le("div",{children:g.width})]}),lo($e,{columns:2,children:[le("div",{children:h("stats.height")}),le("div",{children:g.height})]}),a&&lo(Yb,{children:[le($e,{heading:!0,children:"Canvas"}),le($e,{children:le(Wk,{property:"gridStep",scene:s,appState:r,setAppState:m})})]})]}),o?.(l,r)]}),!w&&n.length>0&&le("div",{id:"elementStats",style:{marginTop:12},children:le(Nl,{label:le("h3",{children:h("stats.elementProperties")}),open:!!(r.stats.panels&yu.elementProperties),openTrigger:()=>m(v=>({stats:{open:!0,panels:v.stats.panels^yu.elementProperties}})),children:lo(wu,{children:[p&&lo(Yb,{children:[u&&le($e,{heading:!0,children:h("labels.unCroppedDimension")}),r.croppingElementId&&Wb(p)&&b&&lo($e,{columns:2,children:[le("div",{children:h("stats.width")}),le("div",{children:hS(b.width,2)})]}),r.croppingElementId&&Wb(p)&&b&&lo($e,{columns:2,children:[le("div",{children:h("stats.height")}),le("div",{children:hS(b.height,2)})]}),le($e,{heading:!0,"data-testid":"stats-element-type",style:{margin:"0.3125rem 0"},children:r.croppingElementId?h("labels.imageCropping"):h(`element.${p.type}`)}),le($e,{children:le(Gb,{element:p,property:"x",elementsMap:c,scene:s,appState:r})}),le($e,{children:le(Gb,{element:p,property:"y",elementsMap:c,scene:s,appState:r})}),le($e,{children:le(Rb,{property:"width",element:p,scene:s,appState:r})}),le($e,{children:le(Rb,{property:"height",element:p,scene:s,appState:r})}),le($e,{children:le(Gk,{property:"angle",element:p,scene:s,appState:r})}),le($e,{children:le(Jk,{property:"fontSize",element:p,scene:s,appState:r})})]}),d&&lo(Yb,{children:[cY(d)&&le($e,{heading:!0,children:h("element.group")}),lo($e,{columns:2,style:{margin:"0.3125rem 0"},children:[le("div",{children:h("stats.shapes")}),le("div",{children:n.length})]}),le($e,{children:le(Hb,{property:"x",elements:d,elementsMap:c,atomicUnits:x,scene:s,appState:r})}),le($e,{children:le(Hb,{property:"y",elements:d,elementsMap:c,atomicUnits:x,scene:s,appState:r})}),le($e,{children:le(zb,{property:"width",elements:d,elementsMap:c,atomicUnits:x,scene:s,appState:r})}),le($e,{children:le(zb,{property:"height",elements:d,elementsMap:c,atomicUnits:x,scene:s,appState:r})}),le($e,{children:le(nS,{property:"angle",elements:d,scene:s,appState:r})}),le($e,{children:le(mS,{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 pY,useEffect as bS,useState as xS}from"react";import{normalizeLink as uY,KEYS as Vb}from"@orangecatai/common";import{defaultGetElementLinkFromSelection as gY,getLinkIdAndTypeFromSelection as hY}from"@orangecatai/element";import{jsx as Vs,jsxs as vu}from"react/jsx-runtime";var fY=({sourceElementId:e,onClose:t,appState:o,scene:n,generateLinkForSelection:r=gY})=>{let i=n.getNonDeletedElementsMap(),a=i.get(e)?.link??null,[s,l]=xS(a),[c,m]=xS(!1);bS(()=>{let d=se(i,o),u=a;if(d.length>0&&r){let b=hY(d,o);b&&(u=uY(r(b.id,b.type)))}l(u)},[i,o,o.selectedElementIds,a,r]);let p=pY(()=>{if(s&&s!==i.get(e)?.link){let d=i.get(e);d&&n.mutateElement(d,{link:s})}if(!s&&c&&e){let d=i.get(e);d&&n.mutateElement(d,{link:null})}t?.()},[e,s,i,c,n,t]);return bS(()=>{let d=u=>{o.openDialog?.name==="elementLinkSelector"&&u.key===Vb.ENTER&&p(),o.openDialog?.name==="elementLinkSelector"&&u.key===Vb.ESCAPE&&t?.()};return window.addEventListener("keydown",d),()=>{window.removeEventListener("keydown",d)}},[o,t,p]),vu("div",{className:"ElementLinkDialog",children:[vu("div",{className:"ElementLinkDialog__header",children:[Vs("h2",{children:h("elementLink.title")}),Vs("p",{children:h("elementLink.desc")})]}),vu("div",{className:"ElementLinkDialog__input",children:[Vs(zr,{value:s??"",onChange:d=>{c||m(!0),l(d)},onKeyDown:d=>{d.key===Vb.ENTER&&p()},className:"ElementLinkDialog__input-field",selectOnRender:!0}),a&&s&&Vs(ee,{type:"button",title:h("buttons.remove"),"aria-label":h("buttons.remove"),label:h("buttons.remove"),onClick:()=>{l(null),m(!0)},className:"ElementLinkDialog__remove",icon:Nt})]}),vu("div",{className:"ElementLinkDialog__actions",children:[Vs(Jn,{label:h("buttons.cancel"),onClick:()=>{t?.()},style:{marginRight:10}}),Vs(Jn,{label:h("buttons.confirm"),onClick:p,actionType:"primary"})]})]})},ES=fY;import bY,{useState as xY}from"react";import{Fragment as EY,jsx as Kb}from"react/jsx-runtime";var yS=({children:e,onClose:t})=>{let[o,n]=xY(!!e),{container:r}=Ke(),i=bY.useCallback(()=>{n(!1),t&&t(),r?.focus()},[t,r]);return Kb(EY,{children:o&&Kb(dt,{size:"small",onCloseRequest:i,title:h("errorDialog.title"),children:Kb("div",{style:{whiteSpace:"pre-wrap"},children:e})})})};import yY from"react";import{isDarwin as wS,isFirefox as vS,isWindows as wY}from"@orangecatai/common";import{KEYS as at}from"@orangecatai/common";import{Fragment as IS,jsx as Y,jsxs as wo}from"react/jsx-runtime";var vY=()=>wo("div",{className:"HelpDialog__header",children:[wo("a",{className:"HelpDialog__btn",href:"https://docs.excalidraw.com",target:"_blank",rel:"noopener",children:[Y("div",{className:"HelpDialog__link-icon",children:lg}),h("helpDialog.documentation")]}),wo("a",{className:"HelpDialog__btn",href:"https://plus.excalidraw.com/blog",target:"_blank",rel:"noopener",children:[Y("div",{className:"HelpDialog__link-icon",children:lg}),h("helpDialog.blog")]}),wo("a",{className:"HelpDialog__btn",href:"https://github.com/excalidraw/excalidraw/issues",target:"_blank",rel:"noopener noreferrer",children:[Y("div",{className:"HelpDialog__link-icon",children:yd}),h("helpDialog.github")]}),wo("a",{className:"HelpDialog__btn",href:"https://youtube.com/@excalidraw",target:"_blank",rel:"noopener noreferrer",children:[Y("div",{className:"HelpDialog__link-icon",children:Py}),"YouTube"]})]}),TY=e=>wo(IS,{children:[Y("h3",{children:e.title}),Y("div",{className:"HelpDialog__islands-container",children:e.children})]}),Xb=e=>wo("div",{className:`HelpDialog__island ${e.className}`,children:[Y("h4",{className:"HelpDialog__island-title",children:e.caption}),Y("div",{className:"HelpDialog__island-content",children:e.children})]});function*IY(e,t){let o=!0;for(let n of e)o||(yield t),o=!1,yield n}var CY=e=>e.replace(/\b[a-z]\b/,t=>t.toUpperCase()),q=({label:e,shortcuts:t,isOr:o=!0})=>{let n=t.map(r=>(r.endsWith("++")?[...r.slice(0,-2).split("+"),"+"]:r.split("+")).map(a=>Y(kY,{children:CY(a)},a)));return wo("div",{className:"HelpDialog__shortcut",children:[Y("div",{children:e}),Y("div",{className:"HelpDialog__key-container",children:[...IY(n,o?h("helpDialog.or"):null)]})]})},kY=e=>Y("kbd",{className:"HelpDialog__key",...e}),TS=({onClose:e})=>{let t=yY.useCallback(()=>{e&&e()},[e]);return Y(IS,{children:wo(dt,{onCloseRequest:t,title:h("helpDialog.title"),className:"HelpDialog",children:[Y(vY,{}),wo(TY,{title:h("helpDialog.shortcuts"),children:[wo(Xb,{className:"HelpDialog__island--tools",caption:h("helpDialog.tools"),children:[Y(q,{label:h("toolBar.hand"),shortcuts:[at.H]}),Y(q,{label:h("toolBar.selection"),shortcuts:[at.V,at[1]]}),Y(q,{label:h("toolBar.rectangle"),shortcuts:[at.R,at[2]]}),Y(q,{label:h("toolBar.diamond"),shortcuts:[at.D,at[3]]}),Y(q,{label:h("toolBar.ellipse"),shortcuts:[at.O,at[4]]}),Y(q,{label:h("toolBar.arrow"),shortcuts:[at.A,at[5]]}),Y(q,{label:h("toolBar.line"),shortcuts:[at.L,at[6]]}),Y(q,{label:h("toolBar.freedraw"),shortcuts:[at.P,at[7]]}),Y(q,{label:h("toolBar.text"),shortcuts:[at.T,at[8]]}),Y(q,{label:h("toolBar.image"),shortcuts:[at[9]]}),Y(q,{label:h("toolBar.eraser"),shortcuts:[at.E,at[0]]}),Y(q,{label:h("toolBar.frame"),shortcuts:[at.F]}),Y(q,{label:h("toolBar.laser"),shortcuts:[at.K]}),Y(q,{label:h("labels.eyeDropper"),shortcuts:[at.I,"Shift+S","Shift+G"]}),Y(q,{label:h("helpDialog.editLineArrowPoints"),shortcuts:[N("CtrlOrCmd+Enter")]}),Y(q,{label:h("helpDialog.editText"),shortcuts:[N("Enter")]}),Y(q,{label:h("helpDialog.textNewLine"),shortcuts:[N("Enter"),N("Shift+Enter")]}),Y(q,{label:h("helpDialog.textFinish"),shortcuts:[N("Esc"),N("CtrlOrCmd+Enter")]}),Y(q,{label:h("helpDialog.curvedArrow"),shortcuts:["A",h("helpDialog.click"),h("helpDialog.click"),h("helpDialog.click")],isOr:!1}),Y(q,{label:h("helpDialog.curvedLine"),shortcuts:["L",h("helpDialog.click"),h("helpDialog.click"),h("helpDialog.click")],isOr:!1}),Y(q,{label:h("helpDialog.cropStart"),shortcuts:[h("helpDialog.doubleClick"),N("Enter")],isOr:!0}),Y(q,{label:h("helpDialog.cropFinish"),shortcuts:[N("Enter"),N("Escape")],isOr:!0}),Y(q,{label:h("toolBar.lock"),shortcuts:[at.Q]}),Y(q,{label:h("helpDialog.preventBinding"),shortcuts:[N("CtrlOrCmd")]}),Y(q,{label:h("toolBar.link"),shortcuts:[N("CtrlOrCmd+K")]}),Y(q,{label:h("toolBar.convertElementType"),shortcuts:["Tab","Shift+Tab"],isOr:!0})]}),wo(Xb,{className:"HelpDialog__island--view",caption:h("helpDialog.view"),children:[Y(q,{label:h("buttons.zoomIn"),shortcuts:[N("CtrlOrCmd++")]}),Y(q,{label:h("buttons.zoomOut"),shortcuts:[N("CtrlOrCmd+-")]}),Y(q,{label:h("buttons.resetZoom"),shortcuts:[N("CtrlOrCmd+0")]}),Y(q,{label:h("helpDialog.zoomToFit"),shortcuts:["Shift+1"]}),Y(q,{label:h("helpDialog.zoomToSelection"),shortcuts:["Shift+2"]}),Y(q,{label:h("helpDialog.movePageUpDown"),shortcuts:["PgUp/PgDn"]}),Y(q,{label:h("helpDialog.movePageLeftRight"),shortcuts:["Shift+PgUp/PgDn"]}),Y(q,{label:h("buttons.zenMode"),shortcuts:[N("Alt+Z")]}),Y(q,{label:h("buttons.objectsSnapMode"),shortcuts:[N("Alt+S")]}),Y(q,{label:h("labels.toggleGrid"),shortcuts:[N("CtrlOrCmd+'")]}),Y(q,{label:h("labels.viewMode"),shortcuts:[N("Alt+R")]}),Y(q,{label:h("labels.toggleTheme"),shortcuts:[N("Alt+Shift+D")]}),Y(q,{label:h("stats.fullTitle"),shortcuts:[N("Alt+/")]}),Y(q,{label:h("search.title"),shortcuts:[Ue("searchMenu")]}),Y(q,{label:h("commandPalette.title"),shortcuts:vS?[Ue("commandPalette")]:[Ue("commandPalette"),Ue("commandPalette",1)]})]}),wo(Xb,{className:"HelpDialog__island--editor",caption:h("helpDialog.editor"),children:[Y(q,{label:h("helpDialog.createFlowchart"),shortcuts:[N("CtrlOrCmd+Arrow Key")],isOr:!0}),Y(q,{label:h("helpDialog.navigateFlowchart"),shortcuts:[N("Alt+Arrow Key")],isOr:!0}),Y(q,{label:h("labels.moveCanvas"),shortcuts:[N(`Space+${h("helpDialog.drag")}`),N(`Wheel+${h("helpDialog.drag")}`)],isOr:!0}),Y(q,{label:h("buttons.clearReset"),shortcuts:[N("CtrlOrCmd+Delete")]}),Y(q,{label:h("labels.delete"),shortcuts:[N("Delete")]}),Y(q,{label:h("labels.cut"),shortcuts:[N("CtrlOrCmd+X")]}),Y(q,{label:h("labels.copy"),shortcuts:[N("CtrlOrCmd+C")]}),Y(q,{label:h("labels.paste"),shortcuts:[N("CtrlOrCmd+V")]}),Y(q,{label:h("labels.pasteAsPlaintext"),shortcuts:[N("CtrlOrCmd+Shift+V")]}),Y(q,{label:h("labels.selectAll"),shortcuts:[N("CtrlOrCmd+A")]}),Y(q,{label:h("labels.multiSelect"),shortcuts:[N(`Shift+${h("helpDialog.click")}`)]}),Y(q,{label:h("helpDialog.deepSelect"),shortcuts:[N(`CtrlOrCmd+${h("helpDialog.click")}`)]}),Y(q,{label:h("helpDialog.deepBoxSelect"),shortcuts:[N(`CtrlOrCmd+${h("helpDialog.drag")}`)]}),(Xa||vS)&&Y(q,{label:h("labels.copyAsPng"),shortcuts:[N("Shift+Alt+C")]}),Y(q,{label:h("labels.copyStyles"),shortcuts:[N("CtrlOrCmd+Alt+C")]}),Y(q,{label:h("labels.pasteStyles"),shortcuts:[N("CtrlOrCmd+Alt+V")]}),Y(q,{label:h("labels.sendToBack"),shortcuts:[wS?N("CtrlOrCmd+Alt+["):N("CtrlOrCmd+Shift+[")]}),Y(q,{label:h("labels.bringToFront"),shortcuts:[wS?N("CtrlOrCmd+Alt+]"):N("CtrlOrCmd+Shift+]")]}),Y(q,{label:h("labels.sendBackward"),shortcuts:[N("CtrlOrCmd+[")]}),Y(q,{label:h("labels.bringForward"),shortcuts:[N("CtrlOrCmd+]")]}),Y(q,{label:h("labels.alignTop"),shortcuts:[N("CtrlOrCmd+Shift+Up")]}),Y(q,{label:h("labels.alignBottom"),shortcuts:[N("CtrlOrCmd+Shift+Down")]}),Y(q,{label:h("labels.alignLeft"),shortcuts:[N("CtrlOrCmd+Shift+Left")]}),Y(q,{label:h("labels.alignRight"),shortcuts:[N("CtrlOrCmd+Shift+Right")]}),Y(q,{label:h("labels.duplicateSelection"),shortcuts:[N("CtrlOrCmd+D"),N(`Alt+${h("helpDialog.drag")}`)]}),Y(q,{label:h("helpDialog.toggleElementLock"),shortcuts:[N("CtrlOrCmd+Shift+L")]}),Y(q,{label:h("buttons.undo"),shortcuts:[N("CtrlOrCmd+Z")]}),Y(q,{label:h("buttons.redo"),shortcuts:wY?[N("CtrlOrCmd+Y"),N("CtrlOrCmd+Shift+Z")]:[N("CtrlOrCmd+Shift+Z")]}),Y(q,{label:h("labels.group"),shortcuts:[N("CtrlOrCmd+G")]}),Y(q,{label:h("labels.ungroup"),shortcuts:[N("CtrlOrCmd+Shift+G")]}),Y(q,{label:h("labels.flipHorizontal"),shortcuts:[N("Shift+H")]}),Y(q,{label:h("labels.flipVertical"),shortcuts:[N("Shift+V")]}),Y(q,{label:h("labels.showStroke"),shortcuts:[N("S")]}),Y(q,{label:h("labels.showBackground"),shortcuts:[N("G")]}),Y(q,{label:h("labels.showFonts"),shortcuts:[N("Shift+F")]}),Y(q,{label:h("labels.decreaseFontSize"),shortcuts:[N("CtrlOrCmd+Shift+<")]}),Y(q,{label:h("labels.increaseFontSize"),shortcuts:[N("CtrlOrCmd+Shift+>")]})]})]})]})})};import{CANVAS_SEARCH_TAB as SY,DEFAULT_SIDEBAR as MY}from"@orangecatai/common";import{isFlowchartNodeElement as PY,isImageElement as CS,isLinearElement as kS,isLineElement as AY,isTextBindableContainer as LY,isTextElement as _Y}from"@orangecatai/element";import{isNodeInFlowchart as DY}from"@orangecatai/element";import{jsx as $b}from"react/jsx-runtime";var Ne=e=>Array.isArray(e)?`<kbd>${e.map(N).join(" + ")}</kbd>`:`<kbd>${N(e)}</kbd>`,RY=({appState:e,isMobile:t,editorInterface:o,app:n})=>{let{activeTool:r,isResizing:i,isRotating:a,lastPointerDownWith:s}=e,l=e.multiElement!==null;if(e.openSidebar?.name===MY.name&&e.openSidebar.tab===SY&&e.searchMatches?.matches.length)return h("hints.dismissSearch",{shortcut:Ne("Escape")});if(e.openSidebar&&!o.canFitSidebar)return null;if(oo(e))return h("hints.eraserRevert",{shortcut:Ne("Alt")});let c=n.scene.getSelectedElements(e);if(e.selectedLinearElement?.isDragging&&c[0]?.type==="arrow")return h("hints.arrowBindModifiers",{shortcut_1:Ne("Ctrl"),shortcut_2:Ne("Alt")});if(r.type==="arrow"||r.type==="line")return l?h("hints.linearElementMulti",{shortcut_1:Ne("Escape"),shortcut_2:Ne("Enter")}):r.type==="arrow"?h("hints.arrowTool",{shortcut:Ne("A")}):h("hints.linearElement");if(r.type==="freedraw")return h("hints.freeDraw");if(r.type==="text")return h("hints.text");if(r.type==="embeddable")return h("hints.embeddable");if(i&&s==="mouse"&&c.length===1){let m=c[0];return kS(m)&&m.points.length===2?h("hints.lockAngle",{shortcut:Ne("Shift")}):CS(m)?h("hints.resizeImage",{shortcut_1:Ne("Shift"),shortcut_2:Ne("Alt")}):h("hints.resize",{shortcut_1:Ne("Shift"),shortcut_2:Ne("Alt")})}if(a&&s==="mouse")return h("hints.rotate",{shortcut:Ne("Shift")});if(c.length===1&&_Y(c[0]))return h("hints.text_selected",{shortcut:Ne("Enter")});if(e.editingTextElement)return h("hints.text_editing",{shortcut_1:Ne("Escape"),shortcut_2:Ne(["CtrlOrCmd","Enter"])});if(e.croppingElementId)return h("hints.leaveCropEditor",{shortcut_1:Ne("Enter"),shortcut_2:Ne("Escape")});if(c.length===1&&CS(c[0]))return h("hints.enterCropEditor",{shortcut:Ne("Enter")});if(r.type==="selection"){if(e.selectionElement&&!c.length&&!e.editingTextElement&&!e.selectedLinearElement?.isEditing)return h("hints.deepBoxSelect",{shortcut:Ne("CtrlOrCmd")});if(Ur(n)&&e.selectedElementsAreBeingDragged)return h("hints.disableSnapping",{shortcut:Ne("CtrlOrCmd")});if(!c.length&&!t)return h("hints.canvasPanning",{shortcut_1:Ne(h("keys.mmb")),shortcut_2:Ne("Space")});if(c.length===1){if(kS(c[0]))return e.selectedLinearElement?.isEditing?e.selectedLinearElement.selectedPointsIndices?h("hints.lineEditor_pointSelected",{shortcut_1:Ne("Delete"),shortcut_2:Ne(["CtrlOrCmd","D"])}):h("hints.lineEditor_nothingSelected",{shortcut_1:Ne("Shift"),shortcut_2:Ne("Alt")}):AY(c[0])?h("hints.lineEditor_line_info",{shortcut:Ne("Enter")}):h("hints.lineEditor_info",{shortcut_1:Ne("CtrlOrCmd"),shortcut_2:Ne(["CtrlOrCmd","Enter"])});if(!e.newElement&&!e.selectedElementsAreBeingDragged&&LY(c[0])){let m=h("hints.bindTextToElement",{shortcut:Ne("Enter")}),p=h("hints.createFlowchart",{shortcut:Ne(["CtrlOrCmd","\u2191\u2193"])});return PY(c[0])?DY(c[0],n.scene.getNonDeletedElementsMap())?[m,p]:[m,p]:m}}}return null},SS=({appState:e,isMobile:t,editorInterface:o,app:n})=>{let r=RY({appState:e,isMobile:t,editorInterface:o,app:n});if(!r)return null;let a=(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 $b("kbd",{children:c?c[1]:s},l)}return s});return $b("div",{className:"HintViewer",children:$b("span",{children:a})})};import{useEffect as AS,useRef as HY,useState as ti}from"react";import{DEFAULT_EXPORT_PADDING as GY,EXPORT_IMAGE_TYPES as Zb,isFirefox as UY,EXPORT_SCALES as WY,cloneJSON as LS}from"@orangecatai/common";import{useCallback as NY,useRef as BY,useState as FY}from"react";var zY=2e3,MS=()=>{let[e,t]=FY(null),o=BY(0),n=()=>{clearTimeout(o.current),t("success"),o.current=window.setTimeout(()=>{t(null)},zY)},r=NY(()=>{t(null)},[]);return{copyStatus:e,resetCopyStatus:r,onCopy:n}};import OY from"clsx";import{jsx as PS}from"react/jsx-runtime";var Fc=({title:e,name:t,checked:o,onChange:n,disabled:r=!1})=>PS("div",{className:OY("Switch",{toggled:o,disabled:r}),children:PS("input",{name:t,id:t,title:e,type:"checkbox",checked:o,disabled:r,onChange:()=>n(!o),onKeyDown:i=>{i.key===" "&&n(!o)}})});import{jsx as Ze,jsxs as oi}from"react/jsx-runtime";var YY=()=>oi("div",{children:[Ze("h3",{children:h("canvasError.cannotShowPreview")}),Ze("p",{children:Ze("span",{children:h("canvasError.canvasTooBig")})}),oi("em",{children:["(",h("canvasError.canvasTooBigTip"),")"]})]}),VY=({appStateSnapshot:e,elementsSnapshot:t,files:o,actionManager:n,onExportImage:r,name:i})=>{let a=ze(t,e),[s,l]=ti(i),[c,m]=ti(a),[p,d]=ti(e.exportBackground),[u,b]=ti(e.exportWithDarkMode),[g,E]=ti(e.exportEmbedScene),[y,x]=ti(e.exportScale),w=HY(null),[v,T]=ti(null),{onCopy:C,copyStatus:M,resetCopyStatus:k}=MS();AS(()=>{k()},[s,p,u,y,g,k]);let{exportedElements:R,exportingFrame:A}=Si(t,e,c);return AS(()=>{let P=w.current;if(!P)return;let _=P.offsetWidth,O=P.offsetHeight;_&&Nr({elements:R,appState:{...e,name:s,exportBackground:p,exportWithDarkMode:u,exportScale:y,exportEmbedScene:g},files:o,exportPadding:GY,maxWidthOrHeight:Math.max(_,O),exportingFrame:A}).then(U=>(T(null),fi(U).then(()=>{P.replaceChildren(U)}).catch(H=>{throw H.name==="CANVAS_POSSIBLY_TOO_BIG"?new Error(h("canvasError.canvasTooBig")):H}))).catch(U=>{console.error(U),T(U)})},[e,o,R,A,s,p,u,y,g]),oi("div",{className:"ImageExportModal",children:[Ze("h3",{children:h("imageExportDialog.header")}),oi("div",{className:"ImageExportModal__preview",children:[Ze("div",{className:"ImageExportModal__preview__canvas",ref:w,children:v&&Ze(YY,{})}),Ze("div",{className:"ImageExportModal__preview__filename",children:!la&&Ze("input",{type:"text",className:"TextInput",value:s,style:{width:"30ch"},onChange:P=>{l(P.target.value),n.executeAction(Ph,"ui",P.target.value)}})})]}),oi("div",{className:"ImageExportModal__settings",children:[Ze("h3",{children:h("imageExportDialog.header")}),a&&Ze(zc,{label:h("imageExportDialog.label.onlySelected"),name:"exportOnlySelected",children:Ze(Fc,{name:"exportOnlySelected",checked:c,onChange:P=>{m(P)}})}),Ze(zc,{label:h("imageExportDialog.label.withBackground"),name:"exportBackgroundSwitch",children:Ze(Fc,{name:"exportBackgroundSwitch",checked:p,onChange:P=>{d(P),n.executeAction(Ah,"ui",P)}})}),Ze(zc,{label:h("imageExportDialog.label.darkMode"),name:"exportDarkModeSwitch",children:Ze(Fc,{name:"exportDarkModeSwitch",checked:u,onChange:P=>{b(P),n.executeAction(zv,"ui",P)}})}),Ze(zc,{label:h("imageExportDialog.label.embedScene"),tooltip:h("imageExportDialog.tooltip.embedScene"),name:"exportEmbedSwitch",children:Ze(Fc,{name:"exportEmbedSwitch",checked:g,onChange:P=>{E(P),n.executeAction(um,"ui",P)}})}),Ze(zc,{label:h("imageExportDialog.label.scale"),name:"exportScale",children:Ze(jp,{name:"exportScale",value:y,onChange:P=>{x(P),n.executeAction(Fv,"ui",P)},choices:WY.map(P=>({value:P,label:`${P}\xD7`}))})}),oi("div",{className:"ImageExportModal__settings__buttons",children:[Ze(No,{className:"ImageExportModal__settings__buttons__button",label:h("imageExportDialog.title.exportToPng"),onClick:()=>r(Zb.png,R,{exportingFrame:A}),icon:Cg,children:h("imageExportDialog.button.exportToPng")}),Ze(No,{className:"ImageExportModal__settings__buttons__button",label:h("imageExportDialog.title.exportToSvg"),onClick:()=>r(Zb.svg,R,{exportingFrame:A}),icon:Cg,children:h("imageExportDialog.button.exportToSvg")}),(Xa||UY)&&Ze(No,{className:"ImageExportModal__settings__buttons__button",label:h("imageExportDialog.title.copyPngToClipboard"),status:M,onClick:async()=>{await r(Zb.clipboard,R,{exportingFrame:A}),C()},icon:Ia,children:h("imageExportDialog.button.copyPngToClipboard")})]})]})]})},zc=({label:e,children:t,tooltip:o,name:n})=>oi("div",{className:"ImageExportModal__settings__setting",title:e,children:[oi("label",{htmlFor:n,className:"ImageExportModal__settings__setting__label",children:[e,o&&Ze(ro,{label:o,long:!0,children:sy})]}),Ze("div",{className:"ImageExportModal__settings__setting__content",children:t})]}),_S=({elements:e,appState:t,files:o,actionManager:n,onExportImage:r,onCloseRequest:i,name:a})=>{let[{appStateSnapshot:s,elementsSnapshot:l}]=ti(()=>({appStateSnapshot:LS(t),elementsSnapshot:LS(e)}));return Ze(dt,{onCloseRequest:i,size:"wide",title:!1,children:Ze(VY,{elementsSnapshot:l,appStateSnapshot:s,files:o,actionManager:n,onExportImage:r,name:a})})};import XY from"react";import{getFrame as $Y}from"@orangecatai/common";import{jsx as KY}from"react/jsx-runtime";var jb={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"}},qb=({children:e,color:t})=>KY("div",{className:"Card",style:{"--card-color":jb[t].base,"--card-color-darker":jb[t].darker,"--card-color-darkest":jb[t].darkest},children:e});import{Fragment as jY,jsx as nn,jsxs as Tu}from"react/jsx-runtime";var ZY=({elements:e,appState:t,setAppState:o,files:n,actionManager:r,exportOpts:i,canvas:a,onCloseRequest:s})=>{let{onExportToBackend:l}=i;return nn("div",{className:"ExportDialog ExportDialog--json",children:Tu("div",{className:"ExportDialog-cards",children:[i.saveFileToDisk&&Tu(qb,{color:"lime",children:[nn("div",{className:"Card-icon",children:gE}),nn("h2",{children:h("exportDialog.disk_title")}),Tu("div",{className:"Card-details",children:[h("exportDialog.disk_details"),!la&&r.renderAction("changeProjectName")]}),nn(ee,{className:"Card-button",type:"button",title:h("exportDialog.disk_button"),"aria-label":h("exportDialog.disk_button"),showAriaLabel:!0,onClick:()=>{r.executeAction(Yl,"ui")}})]}),l&&Tu(qb,{color:"pink",children:[nn("div",{className:"Card-icon",children:xl}),nn("h2",{children:h("exportDialog.link_title")}),nn("div",{className:"Card-details",children:h("exportDialog.link_details")}),nn(ee,{className:"Card-button",type:"button",title:h("exportDialog.link_button"),"aria-label":h("exportDialog.link_button"),showAriaLabel:!0,onClick:async()=>{try{he("export","link",`ui (${$Y()})`),await l(e,t,n),s()}catch(c){o({errorMessage:c.message})}}})]}),i.renderCustomUI&&i.renderCustomUI(e,t,n,a)]})})},DS=({elements:e,appState:t,files:o,actionManager:n,exportOpts:r,canvas:i,setAppState:a})=>{let s=XY.useCallback(()=>{a({openDialog:null})},[a]);return nn(jY,{children:t.openDialog?.name==="jsonExport"&&nn(dt,{onCloseRequest:s,title:h("buttons.export"),children:nn(ZY,{elements:e,appState:t,setAppState:a,files:o,actionManager:n,onCloseRequest:s,exportOpts:r,canvas:i})})})};import qY from"clsx";import{jsx as RS,jsxs as QY}from"react/jsx-runtime";var JY="small",NS=e=>QY("label",{className:qY("ToolIcon ToolIcon__LaserPointer",`ToolIcon_size_${JY}`,{"is-mobile":e.isMobile}),title:`${e.title}`,children:[RS("input",{className:"ToolIcon_type_checkbox",type:"checkbox",name:e.name,onChange:e.onChange,checked:e.checked,"aria-label":e.title,"data-testid":"toolbar-LaserPointer"}),RS("div",{className:"ToolIcon__icon",children:hn})]});import{Fragment as zS,jsx as ie,jsxs as vo}from"react/jsx-runtime";var sV=({UIOptions:e})=>vo(Ut,{__fallback:!0,children:[ie(Ut.DefaultItems.LoadScene,{}),ie(Ut.DefaultItems.SaveToActiveFile,{}),e.canvasActions.export&&ie(Ut.DefaultItems.Export,{}),e.canvasActions.saveAsImage&&ie(Ut.DefaultItems.SaveAsImage,{}),ie(Ut.DefaultItems.SearchMenu,{}),ie(Ut.DefaultItems.Help,{}),ie(Ut.DefaultItems.ClearCanvas,{}),ie(Ut.Separator,{}),ie(Ut.Group,{title:"Excalidraw links",children:ie(Ut.DefaultItems.Socials,{})}),ie(Ut.Separator,{}),ie(Ut.DefaultItems.ToggleTheme,{}),ie(Ut.DefaultItems.ChangeCanvasBackground,{})]}),lV=()=>vo(eu,{__fallback:!0,children:[ie(eu.Actions.SaveToDisk,{}),ie(eu.Actions.ExportToImage,{})]}),cV=({actionManager:e,appState:t,files:o,setAppState:n,elements:r,canvas:i,onLockToggle:a,onHandToolToggle:s,onPenModeToggle:l,showExitZenModeBtn:c,renderTopLeftUI:m,renderTopRightUI:p,renderCustomStats:d,UIOptions:u,onExportImage:b,renderWelcomeScreen:g,children:E,app:y,isCollaborating:x,generateLinkForSelection:w})=>{let v=ye(),C=kt()==="compact",M=sI(),k=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},R=M.tunnelsJotai.Provider,[A,P]=ne(vr),_=()=>u.canvasActions.export?ie(DS,{elements:r,appState:t,files:o,actionManager:e,exportOpts:u.canvasActions.export,canvas:i,setAppState:n}):null,O=()=>!u.canvasActions.saveAsImage||t.openDialog?.name!=="imageExport"?null:ie(_S,{elements:r,appState:t,files:o,actionManager:e,onExportImage:b,onCloseRequest:()=>n({openDialog:null}),name:y.getName()}),U=()=>vo("div",{style:{position:"relative"},children:[ie(M.MainMenuTunnel.Out,{}),g&&ie(M.WelcomeScreenMenuHintTunnel.Out,{})]}),H=()=>{let te=C;return ie(Cc,{heading:"selectedShapeActions",className:Qi("selected-shape-actions zen-mode-transition",{"transition-left":t.zenModeEnabled}),children:te?ie(st,{className:Qi("compact-shape-actions-island"),padding:0,style:{maxHeight:`${t.height-166}px`},children:ie(vI,{appState:t,elementsMap:y.scene.getNonDeletedElementsMap(),renderAction:e.renderAction,app:y,setAppState:n})}):ie(st,{className:tV.SHAPE_ACTIONS_MENU,padding:2,style:{maxHeight:`${t.height-166}px`},children:ie(bI,{appState:t,elementsMap:y.scene.getNonDeletedElementsMap(),renderAction:e.renderAction,app:y})})})},W=()=>{let te=iV(t,r),$=t.stats.open&&!t.zenModeEnabled&&!t.viewModeEnabled&&t.openDialog?.name!=="elementLinkSelector";return ie(Up,{side:"top",children:vo("div",{className:"App-menu App-menu_top",children:[vo(Ft.Col,{gap:k.menuTopGap,className:Qi("App-menu_top__left"),children:[U(),ie("div",{className:Qi("selected-shape-actions-container",{"selected-shape-actions-container--compact":C}),children:te&&H()})]}),!t.viewModeEnabled&&t.openDialog?.name!=="elementLinkSelector"&&ie(Cc,{heading:"shapes",className:"shapes-section",children:ae=>vo("div",{style:{position:"relative"},children:[g&&ie(M.WelcomeScreenToolbarHintTunnel.Out,{}),ie(Ft.Col,{gap:k.toolbarColGap,align:"start",children:vo(Ft.Row,{gap:k.toolbarRowGap,className:Qi("App-toolbar-container",{"zen-mode":t.zenModeEnabled}),children:[vo(st,{padding:k.islandPadding,className:Qi("App-toolbar",{"zen-mode":t.zenModeEnabled,"App-toolbar--compact":C}),children:[ie(SS,{appState:t,isMobile:v.formFactor==="phone",editorInterface:v,app:y}),ae,vo(Ft.Row,{gap:k.toolbarInnerRowGap,children:[ie(Wp,{zenModeEnabled:t.zenModeEnabled,checked:t.penMode,onChange:()=>l(null),title:h("toolBar.penMode"),penDetected:t.penDetected}),ie(z5,{checked:t.activeTool.locked,onChange:a,title:h("toolBar.lock")}),ie("div",{className:"App-toolbar__divider"}),ie(II,{setAppState:n,activeTool:t.activeTool,UIOptions:u,app:y})]})]}),x&&ie(st,{style:{marginLeft:k.collabMarginLeft,alignSelf:"center",height:"fit-content"},children:ie(NS,{title:h("toolBar.laser"),checked:t.activeTool.type===BS.laser,onChange:()=>y.setActiveTool({type:BS.laser}),isMobile:!0})})]})})]})}),vo("div",{className:Qi("layer-ui__wrapper__top-right zen-mode-transition",{"transition-right":t.zenModeEnabled,"layer-ui__wrapper__top-right--compact":C}),children:[t.collaborators.size>0&&ie(Xp,{collaborators:t.collaborators,userToFollow:t.userToFollow?.socketId||null}),p?.(v.formFactor==="phone",t),!t.viewModeEnabled&&t.openDialog?.name!=="elementLinkSelector"&&(!F||t.openSidebar?.name!==Jb.name)&&ie(M.DefaultSidebarTriggerTunnel.Out,{}),$&&ie(Bc,{app:y,onClose:()=>{e.executeAction(Rr)},renderCustomStats:d})]})]})})},D=()=>ie(nu,{__fallback:!0,onDock:te=>{he("sidebar",`toggleDock (${te?"dock":"undock"})`,`(${v.formFactor==="phone"?"mobile":"desktop"})`)}}),F=pa(kc),X=vo(zS,{children:[E,ie(sV,{UIOptions:u}),ie(nu.Trigger,{__fallback:!0,icon:Fy,title:nV(h("toolBar.library")),onToggle:te=>{te&&he("sidebar",`${Jb.name} (open)`,`button (${v.formFactor==="phone"?"mobile":"desktop"})`)},tab:Jb.defaultTab}),ie(lV,{}),t.openDialog?.name==="ttd"&&ie(pu,{__fallback:!0}),t.isLoading&&ie(Op,{delay:250}),t.errorMessage&&ie(yS,{onClose:()=>n({errorMessage:null}),children:t.errorMessage}),A&&v.formFactor!=="phone"&&ie(tw,{colorPickerType:A.colorPickerType,onCancel:()=>{P(null)},onChange:(te,$,ae,{altKey:xe})=>{if(!(te!=="elementBackground"&&te!=="elementStroke"))if(ae.length){for(let re of ae)rV(re,oV(r),{[xe&&A.swapPreviewOnAlt?te==="elementBackground"?"strokeColor":"backgroundColor":te==="elementBackground"?"backgroundColor":"strokeColor"]:$}),aV.delete(re);y.scene.triggerUpdate()}else n(te==="elementBackground"?{currentItemBackgroundColor:$}:{currentItemStrokeColor:$})},onSelect:(te,$)=>{P(ae=>ae?.keepOpenOnAlt&&$.altKey?ae:null),A?.onSelect?.(te,$)}}),t.openDialog?.name==="help"&&ie(TS,{onClose:()=>{n({openDialog:null})}}),ie(AI,{}),t.openDialog?.name==="elementLinkSelector"&&ie(ES,{sourceElementId:t.openDialog.sourceElementId,onClose:()=>{n({openDialog:null})},scene:y.scene,appState:t,generateLinkForSelection:w}),ie(M.OverwriteConfirmDialogTunnel.Out,{}),O(),_(),t.pasteDialog.shown&&ie(X5,{setAppState:n,appState:t,onClose:()=>n({pasteDialog:{shown:!1,data:null}})}),v.formFactor==="phone"&&ie(V5,{app:y,appState:t,elements:r,actionManager:e,renderJSONExportDialog:_,renderImageExportDialog:O,setAppState:n,onHandToolToggle:s,onPenModeToggle:l,renderTopLeftUI:m,renderTopRightUI:p,renderSidebars:D,renderWelcomeScreen:g,UIOptions:u}),v.formFactor!=="phone"&&vo(zS,{children:[vo("div",{className:"layer-ui__wrapper",style:t.openSidebar&&F&&v.canFitSidebar?{width:"calc(100% - var(--right-sidebar-width))"}:{},children:[g&&ie(M.WelcomeScreenCenterTunnel.Out,{}),W(),ie(J5,{appState:t,actionManager:e,showExitZenModeBtn:c,renderWelcomeScreen:g}),t.scrolledOutside&&ie("button",{type:"button",className:"scroll-back-to-content",onClick:()=>{n(te=>({...gi(r,te)}))},children:h("buttons.scrollBackToContent")})]}),D()]})]});return ie(Hg.Provider,{value:t,children:ie(R,{children:ie(Gf.Provider,{value:M,children:X})})})},FS=e=>{let{startBoundElement:t,cursorButton:o,scrollX:n,scrollY:r,...i}=e;return i},dV=(e,t)=>{if(e.children!==t.children)return!1;let{canvas:o,appState:n,...r}=e,{canvas:i,appState:a,...s}=t;return Iu(FS(n),FS(a),{selectedElementIds:Iu,selectedGroupIds:Iu})&&Iu(r,s)},OS=eV.memo(cV,dV);import mV from"clsx";import{jsx as HS,jsxs as uV}from"react/jsx-runtime";var pV="small",Cu=e=>uV("label",{className:mV("ToolIcon ToolIcon__MagicButton",`ToolIcon_size_${pV}`,{"is-mobile":e.isMobile}),title:`${e.title}`,children:[HS("input",{className:"ToolIcon_type_checkbox",type:"checkbox",name:e.name,onChange:e.onChange,checked:e.checked,"aria-label":e.title}),HS("div",{className:"ToolIcon__icon",children:e.icon})]});import{useEffect as gV,useRef as hV}from"react";import{jsx as GS}from"react/jsx-runtime";var US=({trails:e})=>{let t=hV(null);return gV(()=>{if(t.current)for(let o of e)o.start(t.current);return()=>{for(let o of e)o.stop()}},e),GS("div",{className:"SVGLayer",children:GS("svg",{ref:t})})};import QV,{useEffect as eK,useRef as i4}from"react";import{CURSOR_TYPE as a4,isShallowEqual as tK,sceneCoordsToViewportCoords as oK}from"@orangecatai/common";var _t=class _t{static start(t,o){let n=o({deltaTime:0,state:void 0});n&&(_t.animations.set(t,{animation:o,lastTime:0,state:n}),_t.isRunning||(_t.isRunning=!0,Vi()?requestAnimationFrame(_t.tick):setTimeout(_t.tick,0)))}static tick(){if(_t.animations.size>0){for(let[t,o]of _t.animations){let n=performance.now(),r=o.lastTime===0?0:n-o.lastTime,i=o.animation({deltaTime:r,state:o.state});if(i)o.lastTime=n,o.state=i;else if(_t.animations.delete(t),_t.animations.size===0){_t.isRunning=!1;return}}Vi()?requestAnimationFrame(_t.tick):setTimeout(_t.tick,0)}}static running(t){return _t.animations.has(t)}static cancel(t){_t.animations.delete(t)}};S(_t,"isRunning",!1),S(_t,"animations",new Map);var Oc=_t;import{clamp as o1,pointFrom as Ks,pointsEqual as vV,bezierEquation as e4,pointRotateRads as ku,pointDistance as TV}from"@orangecatai/math";import{arrayToMap as IV,BIND_MODE_TIMEOUT as Hc,DEFAULT_TRANSFORM_HANDLE_SPACING as a1,FRAME_STYLE as Oo,getFeatureFlag as CV,invariant as XS,THEME as ni}from"@orangecatai/common";import{deconstructDiamondElement as n1,deconstructRectanguloidElement as t4,elementCenterPoint as Xs,getDiamondBaseCorners as kV,FOCUS_POINT_SIZE as SV,getOmitSidesForEditorInterface as Qb,getTransformHandles as MV,getTransformHandlesFromCoords as PV,hasBoundingBox as AV,hitElementItself as LV,isArrowElement as _V,isBindableElement as o4,isElbowArrow as $s,isFrameLikeElement as Zs,isImageElement as $S,isLinearElement as DV,isLineElement as RV,maxBindingDistance_simple as NV,isTextElement as ZS,LinearElementEditor as Dn}from"@orangecatai/element";import{renderSelectionElement as BV}from"@orangecatai/element";import{getElementsInGroup as r1,getSelectedGroupIds as FV,isSelectedViaGroup as zV,selectGroupsFromGivenElements as OV}from"@orangecatai/element";import{getCommonBounds as i1,getElementAbsoluteCoords as Su}from"@orangecatai/element";import{getGlobalFixedPointForBindableElement as jS,isFocusPointVisible as HV}from"@orangecatai/element";import{pointFrom as Wt}from"@orangecatai/math";import{THEME as fV}from"@orangecatai/common";var bV="#ff6b6b",xV="#ff0000",WS=1,YS=2,VS=(e,t)=>{if(!t.snapLines.length)return;let o=t.theme===fV.LIGHT||t.zenModeEnabled?bV:xV,n=(t.zenModeEnabled?WS*1.5:WS)/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,yV(r,e,t)):r.type==="gap"?(e.lineWidth=n,e.strokeStyle=o,wV(r.points[0],r.points[1],r.direction,t,e)):r.type==="points"&&(e.lineWidth=n,e.strokeStyle=o,EV(r,e,t));e.restore()},EV=(e,t,o)=>{if(!o.zenModeEnabled){let n=e.points[0],r=e.points[e.points.length-1];zo(n,r,t)}for(let n of e.points)KS(n,o,t)},yV=(e,t,o)=>{KS(e.points[0],o,t),o.zenModeEnabled||zo(e.points[0],e.points[1],t)},KS=([e,t],o,n)=>{n.save();let r=(o.zenModeEnabled?YS*1.5:YS)/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()},zo=(e,t,o)=>{o.beginPath(),o.lineTo(e[0],e[1]),o.lineTo(t[0],t[1]),o.stroke()},wV=(e,t,o,n,r)=>{let i=8/n.zoom.value,a=i/2,s=i/4;if(o==="horizontal"){let l=[(e[0]+t[0])/2,e[1]];n.zenModeEnabled||zo(Wt(e[0],e[1]-i),Wt(e[0],e[1]+i),r),zo(Wt(l[0]-s,l[1]-a),Wt(l[0]-s,l[1]+a),r),zo(Wt(l[0]+s,l[1]-a),Wt(l[0]+s,l[1]+a),r),n.zenModeEnabled||(zo(Wt(t[0],t[1]-i),Wt(t[0],t[1]+i),r),zo(e,t,r))}else{let l=[e[0],(e[1]+t[1])/2];n.zenModeEnabled||zo(Wt(e[0]-i,e[1]),Wt(e[0]+i,e[1]),r),zo(Wt(l[0]-a,l[1]-s),Wt(l[0]+a,l[1]-s),r),zo(Wt(l[0]-a,l[1]+s),Wt(l[0]+a,l[1]+s),r),n.zenModeEnabled||(zo(Wt(t[0]-i,t[1]),Wt(t[0]+i,t[1]),r),zo(e,t,r))}};var GV=(e,t)=>{XS(t.selectedLinearElement,"selectedLinearElement is null");let{segmentMidPointHoveredCoords:o}=t.selectedLinearElement;XS(o,"midPointCoords is null"),e.save(),e.translate(t.scrollX,t.scrollY),s1(o,e,t),e.restore()},UV=(e,t,o)=>{let{elementId:n,hoverPointIndex:r}=t.selectedLinearElement;if(t.selectedLinearElement?.isEditing&&t.selectedLinearElement?.selectedPointsIndices?.includes(r)||t.selectedLinearElement?.isDragging)return;let i=Dn.getElement(n,o);if(!i)return;let a=Dn.getPointAtIndexGlobalCoordinates(i,r,o);e.save(),e.translate(t.scrollX,t.scrollY),s1(a,e,t),e.restore()},s1=(e,t,o)=>{t.fillStyle="rgba(105, 101, 219, 0.4)",dl(t,e[0],e[1],Dn.POINT_HANDLE_SIZE/o.zoom.value,!1)},WV=(e,t,o)=>{e.save(),e.translate(t.scrollX,t.scrollY),s1(o,e,t),e.restore()},e1=(e,t,o,n,r,i,a)=>{e.strokeStyle="#5e5ad8",e.setLineDash([]),e.fillStyle="rgba(255, 255, 255, 0.9)",r?e.fillStyle="rgba(134, 131, 226, 0.9)":i&&(e.fillStyle="rgba(177, 151, 252, 0.7)"),dl(e,o[0],o[1],(a?n*(t.selectedLinearElement?.isEditing?1.5:2):n)/t.zoom.value,!i,!a||r)},YV=(e,t,o,n,r)=>{let i=t.element.frameId&&o.get(t.element.frameId);switch(i&&Zs(i)&&(e.translate(i.x,i.y),e.beginPath(),Oo.radius&&e.roundRect?e.roundRect(-1,-1,i.width+1,i.height+1,Oo.radius/n.zoom.value):e.rect(-1,-1,i.width+1,i.height+1),e.clip(),e.translate(-i.x,-i.y)),t.element.type){case"magicframe":case"frame":e.save(),e.translate(t.element.x,t.element.y),e.lineWidth=Oo.strokeWidth/n.zoom.value,e.strokeStyle=n.theme===ni.DARK?"rgba(3, 93, 161, 1)":"rgba(106, 189, 252, 1)",Oo.radius&&e.roundRect?(e.beginPath(),e.roundRect(0,0,t.element.width,t.element.height,Oo.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 a=Xs(t.element,o);switch(e.translate(a[0],a[1]),e.rotate(t.element.angle),e.translate(-a[0],-a[1]),e.translate(t.element.x,t.element.y),e.lineWidth=o1(1.75,t.element.strokeWidth,4)/Math.max(.25,n.zoom.value),e.strokeStyle=n.theme===ni.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]=n1(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]=t4(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(Zs(t.element)||o4(t.element)){let a=n.selectedLinearElement,s=a?.elementId&&Dn.getElement(a?.elementId,o),l=r&&LV({point:r,element:t.element,elementsMap:o,threshold:0,overrideShouldTestInside:!0}),c=s&&$s(s)||n.activeTool.type==="arrow"&&n.currentItemArrowType==="elbow";if(!l||c){e.save();let m=Xs(t.element,o),p;if(t.element.type==="diamond"){let g=Xs(t.element,o);p=kV(t.element).map(E=>{let y=e4(E,.5),x=ku(y,g,t.element.angle);return Ks(x[0],x[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(E=>{let y=Ks(E.x+t.element.x,E.y+t.element.y),x=ku(y,m,t.element.angle);return Ks(x[0],x[1])});let d=r&&p.reduce((g,E,y)=>{let x=TV(E,r);return y===-1||x<g.distance?{idx:y,distance:x}:g},{idx:-1,distance:1/0}),u=4/n.zoom.value,b=NV(n.zoom)+t.element.strokeWidth/2;p.forEach((g,E)=>{let y=(!l||c)&&d?.idx===E&&d.distance<=b,x=!y&&(c||E===d?.idx&&d.distance<=b*2);y?(e.fillStyle=n.theme===ni.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()):x&&(e.fillStyle=n.theme===ni.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()}}},VV=(e,t,o,n,r,i,a)=>{let s=e.state.bindMode==="orbit"&&e.bindModeHandler!==null,l=Hc-(a?.runtime??(s?0:Hc)),c=o1(1/Hc*l,1e-4,1),m=o.strokeWidth/2,p=o.frameId&&n.get(o.frameId);switch(p&&Zs(p)&&(t.translate(p.x,p.y),t.beginPath(),Oo.radius&&t.roundRect?t.roundRect(-1,-1,p.width+1,p.height+1,Oo.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=Oo.strokeWidth/r.zoom.value,t.strokeStyle=r.theme===ni.DARK?`rgba(3, 93, 161, ${c})`:`rgba(106, 189, 252, ${c})`,Oo.radius&&t.roundRect?(t.beginPath(),t.roundRect(0,0,o.width,o.height,Oo.radius/r.zoom.value),t.stroke(),t.closePath()):t.strokeRect(0,0,o.width,o.height),t.restore();break;default:t.save();let u=Xs(o,n),b=u[0]+r.scrollX,g=u[1]+r.scrollY;switch(t.translate(b,g),t.rotate(o.angle),t.translate(-b,-g),t.translate(o.x+r.scrollX-m,o.y+r.scrollY-m),t.lineWidth=o1(2.5,o.strokeWidth*1.75,4)/Math.max(.25,r.zoom.value),t.strokeStyle=r.theme===ni.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[E,y]=n1(o,m);E.forEach(x=>{t.beginPath(),t.moveTo(x[0][0]-o.x+m,x[0][1]-o.y+m),t.lineTo(x[1][0]-o.x+m,x[1][1]-o.y+m),t.stroke()}),y.forEach(x=>{let[w,v,T,C]=x;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,T[0]-o.x+m,T[1]-o.y+m,C[0]-o.x+m,C[1]-o.y+m),t.stroke()})}break;default:{let[E,y]=t4(o,m);E.forEach(x=>{t.beginPath(),t.moveTo(x[0][0]-o.x+m,x[0][1]-o.y+m),t.lineTo(x[1][0]-o.x+m,x[1][1]-o.y+m),t.stroke()}),y.forEach(x=>{let[w,v,T,C]=x;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,T[0]-o.x+m,T[1]-o.y+m,C[0]-o.x+m,C[1]-o.y+m),t.stroke()})}break}t.restore();break}if(!s||(a?.runtime??0)>Hc)return;let d=.5*(Math.min(o.width,o.height)/2);if(!Zs(o)){t.save(),t.translate(o.x+r.scrollX,o.y+r.scrollY);let u=1/Hc*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 b=5/r.zoom.value,g=5/r.zoom.value,E=b+g,y;if(o.type==="diamond"){let[,x]=n1(o),w=Xs(o,n);y=x.map(v=>{let T=e4(v,.5),C=ku(T,w,o.angle);return{x:C[0]-o.x,y:C[1]-o.y}})}else{let x=Xs(o,n);y=[{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 T=Ks(v.x+o.x,v.y+o.y),C=ku(T,x,o.angle);return{x:C[0]-o.x,y:C[1]-o.y}})}y.forEach(x=>{t.clearRect(x.x-E,x.y-E,E*2,E*2)}),t.fillStyle=r.theme===ni.DARK?`rgba(3, 93, 161, ${c})`:`rgba(106, 189, 252, ${c})`,y.forEach(x=>{t.beginPath(),t.arc(x.x,x.y,b,0,2*Math.PI),t.fill()}),t.restore()}return{runtime:(a?.runtime??0)+i}},KV=(e,t,o,n,r,i,a)=>{if(o===null)return;if(CV("COMPLEX_BINDINGS"))return VV(e,t,o.element,n,r,i,a);t.save(),t.translate(r.scrollX,r.scrollY);let s=e.lastPointerMoveCoords?Ks(e.lastPointerMoveCoords.x,e.lastPointerMoveCoords.y):null;YV(t,o,n,r,s),t.restore()},n4=(e,t,o)=>{let{angle:n,x1:r,y1:i,x2:a,y2:s,selectionColors:l,cx:c,cy:m,dashed:p,activeEmbeddable:d}=o,u=a-r,b=s-i,E=(o.padding??a1*2)/t.zoom.value,y=8/t.zoom.value,x=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([y,x+(y+x)*(w-1)]),e.lineDashOffset=(y+x)*v,ml(e,r-E,i-E,u+E*2,b+E*2,c,m,n);e.restore()},XV=(e,t,o,n)=>{let[r,i,a,s]=Su(o,n),l=a-r,c=s-i;e.strokeStyle="rgb(0,118,255)",e.lineWidth=Oo.strokeWidth/t.zoom.value,e.save(),e.translate(t.scrollX,t.scrollY),ml(e,r,i,l,c,r+l/2,i+c/2,o.angle,!1,Oo.radius/t.zoom.value),e.restore()},qS=(e,t,o,n)=>{let{colors:r=["rgb(0,118,255)"],dashed:i=!1}=n||{},a=o.filter(m=>m.groupIds.length===0),s=o.filter(m=>m.groupIds.length>0),l=m=>{let[p,d,u,b]=i1(m);return{angle:0,x1:p,x2:u,y1:d,y2:b,selectionColors:r,dashed:i,cx:p+(u-p)/2,cy:d+(b-d)/2,activeEmbeddable:!1}},c=m=>{let p=r1(o,m);return l(p)};Object.entries(OV(s,t)).filter(([m,p])=>p).map(([m,p])=>m).map(m=>c(m)).concat(a.map(m=>l([m]))).forEach(m=>n4(e,t,m))},t1=(e,t,o,n)=>{if(!t.selectedLinearElement)return;e.save(),e.translate(t.scrollX,t.scrollY),e.lineWidth=1/t.zoom.value;let r=Dn.getPointsGlobalCoordinates(o,n),{POINT_HANDLE_SIZE:i}=Dn,a=t.selectedLinearElement?.isEditing?i:i/2,s=$s(o),l=RV(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)&&vV(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),e1(e,t,c,a,d,!1,p)}),$s(o)){let c=o.fixedSegments?.map(m=>m.index)||[];r.slice(0,-1).forEach((m,p)=>{Dn.isSegmentTooShort(o,r[p+1],r[p],p,t.zoom)||e1(e,t,Ks((m[0]+r[p+1][0])/2,(m[1]+r[p+1][1])/2),i/2,!1,!c.includes(p+1),!1)})}else Dn.getEditorMidPoints(o,n,t).filter((m,p,d)=>m!==null&&!($s(o)&&(p===0||p===d.length-1))).forEach(m=>{(t.selectedLinearElement?.isEditing||r.length===2)&&e1(e,t,m,i/2,!1,!0,!1)});e.restore()},$V=(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()},ZV=(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)",dl(e,o[0],o[1],n/t.zoom.value,!0,!0),e.restore()},JS=({arrow:e,appState:t,type:o,context:n,elementsMap:r})=>{let i=o==="start"?e.startBinding:e.endBinding,a=i?.elementId&&r.get(i.elementId);if(!a||!o4(a)||a.isDeleted)return;let s=jS(i.fixedPoint,a,r);if(!HV(s,e,a,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&&WV(n,t,s),!(p&&c)){let d=jS(i.fixedPoint,a,r),u=l?.hoveredFocusPointBinding===o,b=Dn.getPointAtIndexGlobalCoordinates(e,m,r);$V(n,t,b,d),ZV(n,t,d,SV/1.5,u)}},QS=(e,t,o,n,r)=>{Object.keys(n).forEach(i=>{let a=n[i];if(a!==void 0){let[s,l,c,m]=a;e.save(),e.lineWidth=1/o.zoom.value,t.selectionColor&&(e.strokeStyle=t.selectionColor),i==="rotation"?dl(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()):ml(e,s,l,c,m,s+c/2,l+m/2,r,!0),e.restore()}})},jV=(e,t,o,n,r)=>{let[i,a,,,s,l]=Su(n,r),c=3,m=20,p=c/o.zoom.value,d=p/2,u=s-i+p,b=l-a+p,g=Math.min(m/o.zoom.value,u),E=Math.min(m/o.zoom.value,b);e.save(),e.fillStyle=t.selectionColor,e.strokeStyle=t.selectionColor,e.lineWidth=p,[[[-u,-b],[0,d],[g,d],[d,0],[d,E]],[[u-d,-b],[d,d],[-g+d,d],[0,0],[0,E]],[[-u,b],[0,-d],[g,-d],[d,0],[d,-E]],[[u-d,b],[d,-d],[-g+d,-d],[0,0],[0,-E]]].forEach(x=>{let[[w,v],[T,C],[M,k],[R,A],[P,_]]=x;e.save(),e.translate(s,l),e.rotate(n.angle),e.beginPath(),e.moveTo(w+T,v+C),e.lineTo(w+M,v+k),e.stroke(),e.beginPath(),e.moveTo(w+R,v+A),e.lineTo(w+P,v+_),e.stroke(),e.restore()}),e.restore()},qV=(e,t,o,n)=>{t.save();let r=a1*2/o.zoom.value,i=e.width+r*2,a=e.height+r*2,s=e.x+i/2,l=e.y+a/2,c=-(i/2+r),m=-(a/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,i,a),t.restore()},JV=({app:e,canvas:t,elementsMap:o,visibleElements:n,selectedElements:r,allElementsMap:i,scale:a,appState:s,renderConfig:l,editorInterface:c,animationState:m,deltaTime:p})=>{if(t===null)return{atLeastOneVisibleElement:!1,elementsMap:o};let[d,u]=cd(t,a),b=m,g=dd({canvas:t,scale:a,normalizedWidth:d,normalizedHeight:u});g.save(),g.scale(s.zoom.value,s.zoom.value);let E;if(n.forEach(T=>{s.selectedLinearElement?.isEditing&&s.selectedLinearElement.elementId===T.id&&T&&(E=T)}),E&&t1(g,s,E,o),s.selectionElement&&!s.isCropping)try{BV(s.selectionElement,g,s,l.selectionColor)}catch(T){console.error(T)}if(s.editingTextElement&&ZS(s.editingTextElement)){let T=i.get(s.editingTextElement.id);T&&!T.autoResize&&qV(T,g,s,l.selectionColor)}if(s.isBindingEnabled&&s.suggestedBinding?b={...m,bindingHighlight:KV(e,g,s.suggestedBinding,i,s,p,m?.bindingHighlight)}:b={...m,bindingHighlight:void 0},s.frameToHighlight&&XV(g,s,s.frameToHighlight,o),s.elementsToHighlight&&qS(g,s,s.elementsToHighlight),s.activeLockedId){let T=i.get(s.activeLockedId),C=T?[T]:r1(i,s.activeLockedId);qS(g,s,C,{colors:["#ced4da"],dashed:!0})}let y=r.some(T=>Zs(T));r.length===1&&s.selectedLinearElement?.isEditing&&s.selectedLinearElement.elementId===r[0].id&&t1(g,s,r[0],o);let x=s.selectedLinearElement,w=x&&Dn.getElement(x.elementId,i);if(w&&(s.selectedLinearElement.isDragging||(x.segmentMidPointHoveredCoords?GV(g,s):($s(w)?x.hoverPointIndex===0||x.hoverPointIndex===w.points.length-1:x.hoverPointIndex>=0)&&UV(g,s,o)),_V(w)&&(JS({arrow:w,elementsMap:i,appState:s,context:g,type:"start"}),JS({arrow:w,elementsMap:i,appState:s,context:g,type:"end"}))),!s.multiElement&&!s.newElement&&!s.selectedLinearElement?.isEditing){let T=AV(r,s,c),C=r.length===1&&DV(r[0]);C&&s.selectedLinearElement?.elementId===r[0].id&&!r[0].locked&&t1(g,s,r[0],o);let M=l.selectionColor||"#000";if(T){let k=IV(r),R=[];for(let P of o.values()){let _=[],O=l.remoteSelectedElementIds.get(P.id);if(C&&$s(P)&&(P.startBinding||P.endBinding)||(k.has(P.id)&&!zV(s,P)&&_.push(M),O&&_.push(...O.map(U=>Li(U,s.collaborators.get(U))))),_.length){let[U,H,W,D,F,X]=Su(P,o,!0);R.push({angle:P.angle,x1:U,y1:H,x2:W,y2:D,selectionColors:P.locked?["#ced4da"]:_,dashed:!!O||P.locked,cx:F,cy:X,activeEmbeddable:s.activeEmbeddable?.element===P&&s.activeEmbeddable.state==="active",padding:P.id===s.croppingElementId||$S(P)?0:void 0})}}let A=P=>{let _=r1(o,P),[O,U,H,W]=i1(_);R.push({angle:0,x1:O,x2:H,y1:U,y2:W,selectionColors:_.some(D=>D.locked)?["#ced4da"]:["#000"],dashed:!0,cx:O+(H-O)/2,cy:U+(W-U)/2,activeEmbeddable:!1})};for(let P of FV(s))A(P);s.editingGroupId&&A(s.editingGroupId),R.forEach(P=>n4(g,s,P))}if(g.save(),g.translate(s.scrollX,s.scrollY),r.length===1){g.fillStyle="#fff";let k=MV(r[0],s.zoom,o,"mouse",Qb(c));if(!s.viewModeEnabled&&T&&!ZS(s.editingTextElement)&&!s.croppingElementId&&QS(g,l,s,k,r[0].angle),s.croppingElementId&&!s.isCropping){let R=o.get(s.croppingElementId);R&&$S(R)&&jV(g,l,s,R,o)}}else if(r.length>1&&!s.isRotating&&!r.some(k=>k.locked)){let k=a1*2/s.zoom.value;g.fillStyle="#fff";let[R,A,P,_]=i1(r,o),O=g.getLineDash();g.setLineDash([2/s.zoom.value]);let U=g.lineWidth;g.lineWidth=1/s.zoom.value,g.strokeStyle=M,ml(g,R-k,A-k,P-R+k*2,_-A+k*2,(R+P)/2,(A+_)/2,0),g.lineWidth=U,g.setLineDash(O);let H=PV([R,A,P,_,(R+P)/2,(A+_)/2],0,s.zoom,"mouse",y?{...Qb(c),rotation:!0}:Qb(c));r.some(W=>!W.locked)&&QS(g,l,s,H,0)}g.restore()}s.searchMatches?.matches.forEach(({id:T,focus:C,matchedLines:M})=>{let k=o.get(T);if(k){let[R,A,,,P,_]=Su(k,o,!0);g.save(),s.theme===ni.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 O=Zs(k)?s.zoom.value:1;g.translate(s.scrollX,s.scrollY),g.translate(P,_),g.rotate(k.angle),M.forEach(U=>{(U.showOnCanvas||C)&&g.fillRect(R+U.offsetX/O-P,A+U.offsetY/O-_,U.width/O,U.height/O)}),g.restore()}}),VS(g,s),g.restore(),$v({context:g,renderConfig:l,appState:s,normalizedWidth:d,normalizedHeight:u});let v;return l.renderScrollbars&&(v=p5(o,d,u,s),g.save(),g.fillStyle=m5,g.strokeStyle="rgba(255,255,255,0.8)",[v.horizontal,v.vertical].forEach(T=>{T&&xm(g,T.x,T.y,T.width,T.height,_o/2)}),g.restore()),{scrollBars:v,atLeastOneVisibleElement:n.length>0,elementsMap:o,animationState:b}},r4=e=>{let t=JV(e);return e.callback(t),t};import{jsx as iK}from"react/jsx-runtime";var s4="animateInteractiveScene",nK=e=>{let t=i4(!1),o=i4(null);return eK(()=>{if(!t.current){t.current=!0;return}let n=new Map,r=new Map,i=new Map,a=new Map,s=new Map;e.appState.collaborators.forEach((c,m)=>{if(c.selectedElementIds)for(let p of Object.keys(c.selectedElementIds))i.has(p)||i.set(p,[]),i.get(p).push(m);!c.pointer||c.pointer.renderCursor===!1||(c.username&&a.set(m,c.username),c.userState&&s.set(m,c.userState),r.set(m,oK({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:i,remotePointerUsernames:a,remotePointerUserStates:s,selectionColor:l,renderScrollbars:e.renderScrollbars,lastViewportPosition:e.app.lastViewportPosition},editorInterface:e.editorInterface,callback:e.renderInteractiveSceneCallback,animationState:{bindingHighlight:void 0},deltaTime:0},Oc.running(s4)||Oc.start(s4,({deltaTime:c,state:m})=>{let p=r4({...o.current,deltaTime:c,animationState:m}).animationState;if(p){for(let d in p)if(p[d]!==void 0)return p}})}),iK("canvas",{className:"excalidraw__canvas interactive",style:{width:e.appState.width,height:e.appState.height,cursor:e.appState.viewModeEnabled&&e.appState.activeTool.type!=="laser"?a4.GRAB:a4.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:h("labels.drawingCanvas")})},l4=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}),rK=(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:tK(l4(e.appState),l4(t.appState)),l1=QV.memo(nK,rK);import aK,{useEffect as c4,useRef as d4}from"react";import{isShallowEqual as m4}from"@orangecatai/common";import{jsx as cK}from"react/jsx-runtime";var sK=e=>{let t=d4(null),o=d4(!1);return c4(()=>{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]),c4(()=>{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")),_x({canvas:r,rc:e.rc,scale:e.scale,elementsMap:e.elementsMap,allElementsMap:e.allElementsMap,visibleElements:e.visibleElements,appState:e.appState,renderConfig:e.renderConfig},Vi())}),cK("div",{className:"excalidraw__canvas-wrapper",ref:t})},p4=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}),lK=(e,t)=>e.sceneNonce!==t.sceneNonce||e.scale!==t.scale||e.elementsMap!==t.elementsMap||e.visibleElements!==t.visibleElements?!1:m4(p4(e.appState),p4(t.appState))&&m4(e.renderConfig,t.renderConfig),c1=aK.memo(sK,lK);import{useEffect as fK,useRef as bK}from"react";import{throttleRAF as dK}from"@orangecatai/common";import{getTargetFrame as mK,isInvisiblySmallElement as pK,renderElement as uK,shouldApplyFrameClip as gK}from"@orangecatai/element";var u4=({canvas:e,rc:t,newElement:o,elementsMap:n,allElementsMap:r,scale:i,appState:a,renderConfig:s})=>{if(e){let[l,c]=cd(e,i),m=dd({canvas:e,scale:i,normalizedWidth:l,normalizedHeight:c});if(m.save(),m.scale(a.zoom.value,a.zoom.value),o&&o.type!=="selection"){if(pK(o))return;if((o.frameId||a.frameToHighlight?.id)&&a.frameRendering.enabled&&a.frameRendering.clip){let d=mK(o,n,a);d&&gK(o,d,a,n)&&Ax(d,m,s,a)}uK(o,n,r,t,m,s,a)}else m.clearRect(0,0,l,c);m.restore()}},hK=dK(e=>{u4(e)},{trailing:!0}),g4=(e,t)=>{if(t){hK(e);return}u4(e)};import{jsx as EK}from"react/jsx-runtime";var xK=e=>{let t=bK(null);return fK(()=>{t.current&&g4({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},Vi())}),EK("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})},h4=xK;import{useCallback as yK,useEffect as wK,useRef as vK}from"react";import{jsx as f4,jsxs as IK}from"react/jsx-runtime";var TK=5e3,b4=({message:e,onClose:t,closable:o=!1,duration:n=TK,style:r})=>{let i=vK(0),a=n!==1/0,s=yK(()=>{a&&(i.current=window.setTimeout(()=>t(),n))},[t,n,a]);return wK(()=>{if(a)return s(),()=>clearTimeout(i.current)},[s,e,n,a]),IK("div",{className:"Toast",onMouseEnter:a?()=>clearTimeout(i?.current):void 0,onMouseLeave:a?s:void 0,style:r,children:[f4("p",{className:"Toast__message",children:e}),o&&f4(ee,{icon:To,"aria-label":"close",type:"icon",onClick:t,className:"close"})]})};import{getCommonBounds as CK,getElementsInGroup as kK,selectGroupsFromGivenElements as SK}from"@orangecatai/element";import{sceneCoordsToViewportCoords as MK}from"@orangecatai/common";import{flushSync as PK}from"react-dom";import{jsx as LK}from"react/jsx-runtime";var AK=({app:e,activeLockedId:t})=>{let o=e.scene.getElement(t),n=o?[o]:kK(e.scene.getNonDeletedElementsMap(),t);if(n.length===0)return null;let[r,i]=CK(n),{x:a,y:s}=MK({sceneX:r,sceneY:i},e.state);return LK("div",{className:"UnlockPopup",style:{bottom:`${e.state.height+12-s+e.state.offsetTop}px`,left:`${a-e.state.offsetLeft}px`},onClick:()=>{PK(()=>{let l=SK(n,e.state);e.setState({selectedElementIds:n.reduce((c,m)=>({...c,[m.id]:!0}),{}),selectedGroupIds:l,activeLockedId:null})}),e.actionManager.executeAction(jl)},title:h("labels.elementLock.unlock"),children:eE})},x4=AK;import{Fragment as EM,jsx as Me,jsxs as ed}from"react/jsx-runtime";var IM=On.createContext(null),CM=On.createContext(null),U1={formFactor:"desktop",desktopUIMode:"full",userAgent:vM(typeof navigator<"u"?navigator.userAgent:""),isTouchScreen:!1,canFitSidebar:!1,isLandscape:!0},Y1=On.createContext(U1);Y1.displayName="EditorInterfaceContext";var V1=On.createContext({container:null,id:null});V1.displayName="ExcalidrawContainerContext";var K1=On.createContext([]);K1.displayName="ExcalidrawElementsContext";var X1=On.createContext({...fr(),width:0,height:0,offsetLeft:0,offsetTop:0});X1.displayName="ExcalidrawAppStateContext";var $1=On.createContext(()=>{console.warn("Uninitialized ExcalidrawSetAppStateContext context!")});$1.displayName="ExcalidrawSetAppStateContext";var Z1=On.createContext(null);Z1.displayName="ExcalidrawActionManagerContext";var Xe=()=>mi(IM),bn=()=>mi(CM),ye=()=>mi(Y1),kt=()=>Hu(ye()),Ke=()=>mi(V1),Tr=()=>mi(K1),fn=()=>mi(X1),ve=()=>mi($1),qe=()=>mi(Z1),$c=!1,z1=0,Zc=null,ci=!1,jc=!1,O1=!1,qc={horizontal:null,vertical:null},di=0,Jc=!1,H1=new Map,G1=!1,bM=0,xM=!1,Qc=null,Le={pointers:new Map,lastCenter:null,initialDistance:null,initialScale:null},W1=class e extends On.Component{constructor(o){super(o);S(this,"canvas");S(this,"interactiveCanvas",null);S(this,"rc");S(this,"unmounted",!1);S(this,"actionManager");S(this,"editorInterface",U1);S(this,"stylesPanelMode",Hu(U1));S(this,"excalidrawContainerRef",On.createRef());S(this,"scene");S(this,"fonts");S(this,"renderer");S(this,"visibleElements");S(this,"resizeObserver");S(this,"library");S(this,"libraryItemsFromStorage");S(this,"id");S(this,"store");S(this,"history");S(this,"excalidrawContainerValue");S(this,"files",{});S(this,"imageCache",new Map);S(this,"iFrameRefs",new Map);S(this,"embedsValidationStatus",new Map);S(this,"initializedEmbeds",new Set);S(this,"handleToastClose",()=>{this.setToast(null)});S(this,"elementsPendingErasure",new Set);S(this,"flowChartCreator",new $X);S(this,"flowChartNavigator",new ZX);S(this,"bindModeHandler",null);S(this,"hitLinkElement");S(this,"lastPointerDownEvent",null);S(this,"lastPointerUpEvent",null);S(this,"lastPointerMoveEvent",null);S(this,"lastPointerMoveCoords",null);S(this,"previousPointerMoveCoords",null);S(this,"lastViewportPosition",{x:0,y:0});S(this,"animationFrameHandler",new fp);S(this,"laserTrails",new Dp(this.animationFrameHandler,this));S(this,"eraserTrail",new zp(this.animationFrameHandler,this));S(this,"lassoTrail",new Fp(this.animationFrameHandler,this));S(this,"onChangeEmitter",new ea);S(this,"onPointerDownEmitter",new ea);S(this,"onPointerUpEmitter",new ea);S(this,"onUserFollowEmitter",new ea);S(this,"onScrollChangeEmitter",new ea);S(this,"missingPointerEventCleanupEmitter",new ea);S(this,"onRemoveEventListenersEmitter",new ea);S(this,"updateEditorAtom",(o,...n)=>{let r=pt.set(o,...n);return this.triggerRender(),r});S(this,"previousHoveredBindableElement",null);S(this,"getEffectiveGridSize",()=>Ur(this)?this.state.gridSize:null);S(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))?(De(this.interactiveCanvas,et.POINTER),this.setState({activeEmbeddable:{element:o,state:"hover"}}),!0):(this.state.activeEmbeddable?.state==="hover"&&this.setState({activeEmbeddable:null}),!1));S(this,"updateEmbedValidationStatus",(o,n)=>{this.embedsValidationStatus.set(o.id,n),Xc.delete(o)});S(this,"updateEmbeddables",()=>{let o=new Set,n=!1;this.scene.getNonDeletedElements().filter(r=>{if(dr(r)){if(o.add(r.id),!this.embedsValidationStatus.has(r.id)){n=!0;let i=k1(r.link,this.props.validateEmbeddable);this.updateEmbedValidationStatus(r,i)}}else el(r)&&o.add(r.id);return!1}),n&&this.scene.triggerUpdate(),this.iFrameRefs.forEach((r,i)=>{o.has(i)||this.iFrameRefs.delete(i)})});S(this,"getFrameNameDOMId",o=>`${this.id}-frame-name-${o.id}`);S(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 i=r.getBoundingClientRect(),a=je({clientX:i.x,clientY:i.y},this.state),s=je({clientX:i.right,clientY:i.bottom},this.state);return n={x:a.x,y:a.y,width:s.x-a.x,height:s.y-a.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});S(this,"resetEditingFrame",o=>{o&&this.scene.mutateElement(o,{name:o.name?.trim()||null}),this.setState({editingFrame:null})});S(this,"renderFrameNames",()=>{if(!this.state.frameRendering.enabled||!this.state.frameRendering.name)return this.state.editingFrame&&this.resetEditingFrame(null),null;let o=this.state.theme===Au.DARK,n=this.scene.getNonDeletedFramesLikes(),r=n.length>0&&this.state.searchMatches?.focusedId&&Vt(this.scene.getElement(this.state.searchMatches.focusedId))?this.state.searchMatches.matches.find(i=>i.focus):null;return n.map(i=>{if(!X4(i,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===i.id&&this.resetEditingFrame(i),null;let{x:a,y:s}=_u({sceneX:i.x,sceneY:i.y},this.state),l=6,c,m=UX(i),p=`${Math.round(i.width)} x ${Math.round(i.height)}`;if(i.id===this.state.editingFrame){let d=m;c=Me("input",{autoFocus:!0,value:d,onChange:u=>{this.scene.mutateElement(i,{name:u.target.value})},onFocus:u=>u.target.select(),onBlur:()=>this.resetEditingFrame(i),onKeyDown:u=>{(u.key===J.ESCAPE||u.key===J.ENTER)&&this.resetEditingFrame(i)},style:{background:o?aX(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:`${Ho.nameFontSize}px`,transform:`translate(-${l}px, ${l}px)`,color:o?Ho.nameColorDarkTheme:Ho.nameColorLightTheme,overflow:"hidden",maxWidth:`${document.body.clientWidth-a-l}px`},size:d.length+1||1,dir:"auto",autoComplete:"off",autoCapitalize:"off",autoCorrect:"off"})}else c=ed(EM,{children:[Me("span",{children:m}),Me("span",{style:{marginLeft:8,opacity:.7,fontSize:Ho.nameFontSize-1},children:p})]});return Me("div",{id:this.getFrameNameDOMId(i),className:x1.FRAME_NAME,style:{position:"absolute",bottom:`${this.state.height+Ho.nameOffsetY-s+this.state.offsetTop}px`,left:`${a-this.state.offsetLeft}px`,zIndex:2,fontSize:Ho.nameFontSize,color:o?Ho.nameColorDarkTheme:Ho.nameColorLightTheme,lineHeight:Ho.nameLineHeight,width:"max-content",maxWidth:r?.id===i.id&&r?.focus?"none":`${i.width*this.state.zoom.value}px`,overflow:i.id===this.state.editingFrame?"visible":"hidden",whiteSpace:"nowrap",textOverflow:"ellipsis",cursor:et.MOVE,pointerEvents:this.state.viewModeEnabled?js.disabled:js.enabled},onPointerDown:d=>this.handleCanvasPointerDown(d),onWheel:d=>this.handleWheel(d),onContextMenu:this.handleCanvasContextMenu,onDoubleClick:()=>{this.setState({editingFrame:i.id})},children:c},i.id)})});S(this,"focusContainer",()=>{this.excalidrawContainerRef.current?.focus()});S(this,"getSceneElementsIncludingDeleted",()=>this.scene.getElementsIncludingDeleted());S(this,"getSceneElementsMapIncludingDeleted",()=>this.scene.getElementsMapIncludingDeleted());S(this,"getSceneElements",()=>this.scene.getNonDeletedElements());S(this,"onInsertElements",o=>{this.addElementsFromPasteOrLibrary({elements:o,position:"center",files:null})});S(this,"onExportImage",async(o,n,r)=>{he("export",o,"ui");let i=await Mi(o,n,this.state,this.files,{exportBackground:this.state.exportBackground,name:this.getName(),viewBackgroundColor:this.state.viewBackgroundColor,exportingFrame:r.exportingFrame}).catch(nX).catch(a=>{console.error(a),this.setState({errorMessage:a.message})});this.state.exportEmbedScene&&i&&md(i)&&this.setState({fileHandle:i})});S(this,"magicGenerations",new Map);S(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()});S(this,"plugins",{});S(this,"onMagicframeToolSelect",()=>{let o=this.scene.getSelectedElements({selectedElementIds:this.state.selectedElementIds});if(o.length===0)this.setActiveTool({type:Nn.magicframe}),he("ai","tool-select (empty-selection)","d2c");else{let n=o.length===1&&T1(o[0])&&o[0];if(!n&&o.some(i=>Vt(i)||i.frameId)){this.setActiveTool({type:Nn.magicframe});return}he("ai","tool-select (existing selection)","d2c");let r;if(n)r=n;else{let[i,a,s,l]=Js(o),c=50;r=U4({...Ho,x:i-c,y:a-c,width:s-i+c*2,height:l-a+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")}});S(this,"onImageGeneratorSelect",()=>{let r=(this.canvas.width/window.devicePixelRatio/2-this.state.offsetLeft)/this.state.zoom.value-this.state.scrollX,i=(this.canvas.height/window.devicePixelRatio/2-this.state.offsetTop)/this.state.zoom.value-this.state.scrollY,a=H4({...Ho,x:r-896/2,y:i-1344/2,width:896,height:1344,opacity:100,locked:!1,backgroundColor:"#cce8f5",fillStyle:"solid",customData:{type:"image-generator",imageGeneratorAutoFitPending:!0}});this.scene.insertElement(a),this.setActiveTool({type:"selection"}),this.setState({selectedElementIds:{[a.id]:!0}})});S(this,"insertGeneratedImageIntoFrame",async(o,n)=>{let r=d1(),i=E1({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(i),this.scene.mutateElement(i,{frameId:n.id}),this.addFiles([{id:r,dataURL:o,mimeType:ul(o),created:Date.now(),lastRetrieved:Date.now()}])});S(this,"insertGeneratedImageNearElement",async(o,n,r,i)=>{let s=this.scene.getNonDeletedElementsMap(),l=this.scene.getNonDeletedElements().filter(x=>x.id!==n.id),[c,m,p,d]=Nu(n,s),u=[{x:p+25,y:m},{x:c,y:d+25},{x:c-r-25,y:m},{x:c,y:m-i-25}],b=(x,w)=>{let v=x+r,T=w+i,C=x-25,M=w-25,k=v+25,R=T+25;return l.some(A=>{let[P,_,O,U]=Nu(A,s);return P<k&&O>C&&_<R&&U>M})},g=u.find(x=>!b(x.x,x.y))??u[0],E=d1(),y=E1({type:"image",x:g.x,y:g.y,width:r,height:i,fileId:E,status:"pending",scale:[1,1],frameId:null});this.scene.insertElement(y),this.addFiles([{id:E,dataURL:o,mimeType:ul(o),created:Date.now(),lastRetrieved:Date.now()}]),this.setState({selectedElementIds:{[y.id]:!0}})});S(this,"openEyeDropper",({type:o})=>{this.updateEditorAtom(vr,{swapPreviewOnAlt:!0,colorPickerType:o==="stroke"?"elementStroke":"elementBackground",onSelect:(n,r)=>{let i=o==="background"&&r.altKey||o==="stroke"&&!r.altKey;!this.scene.getSelectedElements(this.state).length||this.state.activeTool.type!=="selection"?i?this.syncActionResult({appState:{...this.state,currentItemStrokeColor:n},captureUpdate:to.IMMEDIATELY}):this.syncActionResult({appState:{...this.state,currentItemBackgroundColor:n},captureUpdate:to.IMMEDIATELY}):this.updateScene({elements:this.scene.getElementsIncludingDeleted().map(s=>this.state.selectedElementIds[s.id]?si(s,{[i?"strokeColor":"backgroundColor"]:n}):s),captureUpdate:to.IMMEDIATELY})},keepOpenOnAlt:!1})});S(this,"dismissLinearEditor",()=>{setTimeout(()=>{this.state.selectedLinearElement?.isEditing&&this.setState({selectedLinearElement:{...this.state.selectedLinearElement,isEditing:!1}})})});S(this,"syncActionResult",it(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 i=o?.appState?.viewModeEnabled||!1,a=o?.appState?.zenModeEnabled||!1,s=o?.appState?.theme||this.props.theme||Au.LIGHT,l=o?.appState?.name??this.state.name,c=o?.appState?.errorMessage??this.state.errorMessage;typeof this.props.viewModeEnabled<"u"&&(i=this.props.viewModeEnabled),typeof this.props.zenModeEnabled<"u"&&(a=this.props.zenModeEnabled),r=o.appState?.editingTextElement||null,o.elements&&r&&o.elements.forEach(m=>{r?.id===m.id&&r!==m&&dM(m)&&an(m)&&(r=m)}),r?.isDeleted&&(r=null),this.setState(m=>{let p=o.appState||{};return{...m,...p,contextMenu:null,editingTextElement:r,viewModeEnabled:i,zenModeEnabled:a,theme:s,name:l,errorMessage:c}}),n=!0}n||this.scene.triggerUpdate()}));S(this,"onBlur",it(()=>{ci=!1,this.setState({isBindingEnabled:!0})}));S(this,"onUnload",()=>{this.onBlur()});S(this,"disableEvent",o=>{o.preventDefault()});S(this,"resetHistory",()=>{this.history.clear()});S(this,"resetStore",()=>{this.store.clear()});S(this,"resetScene",it(o=>{this.scene.replaceAllElements([]),this.setState(n=>({...fr(),isLoading:o?.resetLoadingState?!1:n.isLoading,theme:this.state.theme})),this.resetStore(),this.resetHistory()}));S(this,"initializeScene",async()=>{"launchQueue"in window&&"LaunchParams"in window&&window.launchQueue.setConsumer(async a=>{if(!a.files.length)return;let s=a.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(a=>{console.error(a)})}catch(a){console.error(a),o={appState:{errorMessage:a.message||"Encountered an error during importing or restoring scene data"}}}let n=hi(o?.elements,null,{repairBindings:!0,deleteInvisibleElements:!0}),r=ma(o?.appState,null),i=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:i.type==="image"||i.type==="lasso"||i.type==="selection"?{...i,type:r.preferredSelectionTool.type}:r.activeTool,isLoading:!1,toast:this.state.toast},o?.scrollToContent&&(r={...r,...gi(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:to.NEVER}),this.clearImageShapeCache(),this.fonts.loadSceneFonts().then(a=>{this.fonts.onLoaded(a)}),D1(window.location.href)&&this.scrollToContent(window.location.href,{animate:!1})});S(this,"getFormFactor",(o,n)=>this.props.UIOptions.getFormFactor?.(o,n)??mX(o,n));S(this,"refreshEditorInterface",()=>{let o=this.excalidrawContainerRef.current;if(!o)return;let{width:n,height:r}=o.getBoundingClientRect(),i=hX(),a=vM(typeof navigator<"u"?navigator.userAgent:""),s=this.props.UIOptions.dockedSidebarBreakpoint!=null?this.props.UIOptions.dockedSidebarBreakpoint:HK,l=b1(this.editorInterface,{desktopUIMode:i??this.editorInterface.desktopUIMode,formFactor:this.getFormFactor(n,r),userAgent:a,canFitSidebar:n>s,isLandscape:n>r});this.editorInterface=l,this.reconcileStylesPanelMode(l)});S(this,"reconcileStylesPanelMode",o=>{let n=Hu(o);if(n===this.stylesPanelMode)return;let r=this.stylesPanelMode;this.stylesPanelMode=n,r!=="full"&&n==="full"&&this.setState(i=>({preferredSelectionTool:{type:"selection",initialized:!0}}))});S(this,"setDesktopUIMode",o=>{let n=fX(o);this.editorInterface=b1(this.editorInterface,{desktopUIMode:n}),this.reconcileStylesPanelMode(this.editorInterface)});S(this,"onResize",it(()=>{this.scene.getElementsIncludingDeleted().forEach(o=>Xc.delete(o)),this.refreshEditorInterface(),this.updateDOMRect(),this.setState({})}));S(this,"onFullscreenChange",()=>{!document.fullscreenElement&&this.state.activeEmbeddable?.state==="active"&&this.setState({activeEmbeddable:null})});S(this,"renderInteractiveSceneCallback",({atLeastOneVisibleElement:o,scrollBars:n,elementsMap:r})=>{n&&(qc=n);let i=this.state.editingTextElement?!1:!o&&r.size>0;this.state.scrolledOutside!==i&&this.setState({scrolledOutside:i}),this.scheduleImageRefresh()});S(this,"onScroll",R4(()=>{let{offsetTop:o,offsetLeft:n}=this.getCanvasOffsets();this.setState(r=>r.offsetLeft===n&&r.offsetTop===o?null:{offsetTop:o,offsetLeft:n})},GK));S(this,"onCut",it(o=>{!this.excalidrawContainerRef.current?.contains(document.activeElement)||Uc(o.target)||(this.actionManager.executeAction(wm,"keyboard",o),o.preventDefault(),o.stopPropagation())}));S(this,"onCopy",it(o=>{!this.excalidrawContainerRef.current?.contains(document.activeElement)||Uc(o.target)||(this.actionManager.executeAction(os,"keyboard",o),o.preventDefault(),o.stopPropagation())}));S(this,"onTouchStart",o=>{if(pX&&o.preventDefault(),!$c){$c=!0,o.touches.length===1&&(Zc={x:o.touches[0].clientX,y:o.touches[0].clientY}),clearTimeout(z1),z1=window.setTimeout(e.resetTapTwice,UK);return}if($c&&o.touches.length===1&&Zc){let n=o.touches[0];ri(ce(n.clientX,n.clientY),ce(Zc.x,Zc.y))<=cX&&(this.lassoTrail.endPath(),this.deselectElements(),this.handleCanvasDoubleClick({clientX:n.clientX,clientY:n.clientY})),$c=!1,clearTimeout(z1)}o.touches.length===2&&this.setState({selectedElementIds:Be({},this.state),activeEmbeddable:null})});S(this,"onTouchEnd",o=>{this.resetContextMenuTimer(),o.touches.length>0?this.setState({previousSelectedElementIds:{},selectedElementIds:Be(this.state.previousSelectedElementIds,this.state)}):Le.pointers.clear()});S(this,"pasteFromClipboard",it(async o=>{let n=!!G1,r=document.activeElement,i=this.excalidrawContainerRef.current?.contains(r);if(o&&!i)return;let a=document.elementFromPoint(this.lastViewportPosition.x,this.lastViewportPosition.y);if(o&&(!(a instanceof HTMLCanvasElement)||Uc(r)))return;let s=await $a(o),l=s.getFiles(),c=await mm(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()}));S(this,"addElementsFromPasteOrLibrary",o=>{let n=hi(o.elements,null,{deleteInvisibleElements:!0}),[r,i,a,s]=Js(n),l=qs(r,a)/2,c=qs(i,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}=je({clientX:m,clientY:p},this.state),b=d-l,g=u-c,[E,y]=Yt(b,g,this.getEffectiveGridSize()),{duplicatedElements:x}=y1({type:"everything",elements:n.map(k=>si(k,{x:k.x+E-r,y:k.y+y-i})),randomizeSeed:!o.retainSeed}),w=this.scene.getElementsIncludingDeleted(),v=[...w,...x];v=this.props.onDuplicate?.(v,w)||v,iM(v,Du(x));let C=this.getTopLayerFrameAtSceneCoords({x:d,y:u});if(C){let k=YX(x,C);A1(v,k,C,this.state)}this.scene.replaceAllElements(v),x.forEach(k=>{if(an(k)&&w1(k)){let R=J4(k,this.scene.getElementsMapIncludingDeleted());BX(k,R,this.scene)}}),gX&&hr.loadElementsFonts(x).then(k=>{this.fonts.onLoaded(k)}),o.files&&this.addMissingFiles(o.files);let M=d$(x);this.store.scheduleCapture(),this.setState({...this.state,openSidebar:this.state.openSidebar&&this.editorInterface.canFitSidebar&&pt.get(kc)?this.state.openSidebar:null,...Go({editingGroupId:null,selectedElementIds:M.reduce((k,R)=>(w1(R)||(k[R.id]=!0),k),{})},this.scene.getNonDeletedElements(),this.state,this)},()=>{o.files&&this.addNewImagesToImageCache()}),this.setActiveTool({type:this.state.preferredSelectionTool.type},!0),o.fitToContent&&this.scrollToContent(x,{fitToContent:!0,canvasOffsets:this.getEditorUIOffsets()})});S(this,"setAppState",(o,n)=>{this.setState(o,n)});S(this,"removePointer",o=>{di&&this.resetContextMenuTimer(),Le.pointers.delete(o.pointerId)});S(this,"toggleLock",(o="ui")=>{this.state.activeTool.locked||he("toolbar","toggleLock",`${o} (${this.editorInterface.formFactor==="phone"?"mobile":"desktop"})`),this.setState(n=>({activeTool:{...n.activeTool,...Bn(this.state,n.activeTool.locked?{type:this.state.preferredSelectionTool.type}:n.activeTool),locked:!n.activeTool.locked}}))});S(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}}})});S(this,"togglePenMode",o=>{this.setState(n=>({penMode:o??!n.penMode,penDetected:!0}))});S(this,"onHandToolToggle",()=>{this.actionManager.executeAction(rv)});S(this,"zoomCanvas",o=>{this.setState({...Xn({viewportX:this.state.width/2+this.state.offsetLeft,viewportY:this.state.height/2+this.state.offsetTop,nextZoom:ln(o)},this.state)})});S(this,"cancelInProgressAnimation",null);S(this,"scrollToContent",(o=this.scene.getNonDeletedElements(),n)=>{if(typeof o=="string"){let l;if(D1(o)?l=JX(o):l=o,l){let c=this.scene.getElementsFromId(l);c?.length?this.scrollToContent(c,{fitToContent:n?.fitToContent??!0,animate:n?.animate??!0}):D1(o)&&this.setState({toast:{message:h("elementLink.notFound"),duration:3e3,closable:!0}})}return}this.cancelInProgressAnimation?.();let r=Array.isArray(o)?o:[o],i=this.state.zoom,a=this.state.scrollX,s=this.state.scrollY;if(n?.fitToContent||n?.fitToViewport){let{appState:l}=Va({canvasOffsets:n.canvasOffsets,targetElements:r,appState:this.state,fitToViewport:!!n?.fitToViewport,viewportZoomFactor:n?.viewportZoomFactor,minZoom:n?.minZoom,maxZoom:n?.maxZoom});i=l.zoom,a=l.scrollX,s=l.scrollY}else{let l=gi(r,this.state);a=l.scrollX,s=l.scrollY}if(n?.animate){let l=this.state.scrollX,c=this.state.scrollY,m=this.state.zoom.value,p=oX({fromValues:{scrollX:l,scrollY:c,zoom:m},toValues:{scrollX:a,scrollY:s,zoom:i.value},interpolateValue:(d,u,b,g)=>{if(g==="zoom")return d*Math.pow(u/d,rX(b))},onStep:({scrollX:d,scrollY:u,zoom:b})=>{this.setState({scrollX:d,scrollY:u,zoom:{value:b}})},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:a,scrollY:s,zoom:i})});S(this,"maybeUnfollowRemoteUser",()=>{this.state.userToFollow&&this.setState({userToFollow:null})});S(this,"translateCanvas",o=>{this.cancelInProgressAnimation?.(),this.maybeUnfollowRemoteUser(),this.setState(o)});S(this,"setToast",o=>{this.setState({toast:o})});S(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(),i=new File([r],r.name||"",{type:r.type});this.loadFileToCanvas(i,null),await o.delete("shared-file"),window.history.replaceState(null,NK,window.location.pathname)}}catch(o){this.setState({errorMessage:o.message})}});S(this,"addFiles",it(o=>{let{addedFiles:n}=this.addMissingFiles(o);this.clearImageShapeCache(n),this.scene.triggerUpdate(),this.addNewImagesToImageCache()}));S(this,"addMissingFiles",(o,n=!1)=>{let r=n?{}:{...this.files},i={},a=Array.isArray(o)?o:Object.values(o);for(let s of a)if(!r[s.id]&&(i[s.id]=s,r[s.id]=s,s.mimeType===Rn.svg))try{let l=Hx(q4(Gx(s.dataURL)),Rn.svg);s.dataURL!==l&&(s.version=(s.version??1)+1,s.dataURL=l)}catch(l){console.error(l)}return this.files=r,{addedFiles:i}});S(this,"updateScene",it(o=>{let{elements:n,appState:r,collaborators:i,captureUpdate:a}=o;if(a){let s=n||void 0,l=r?bX({...this.store.snapshot.appState,...r}):void 0;this.store.scheduleMicroAction({action:a,elements:s,appState:l})}r&&this.setState(r),n&&this.scene.replaceAllElements(n),i&&this.setState({collaborators:i})}));S(this,"applyDeltas",(o,n)=>{let r=pM.squash(...o),i={...this.state},a=new Map(this.scene.getElementsMapIncludingDeleted());return pM.applyTo(r,a,i,n)});S(this,"mutateElement",(o,n,r=!0)=>this.scene.mutateElement(o,n,{informMutation:r,isDragging:!1}));S(this,"triggerRender",o=>{o===!0?this.scene.triggerUpdate():this.setState({})});S(this,"toggleSidebar",({name:o,tab:n,force:r})=>{let i;r===void 0?i=this.state.openSidebar?.name===o&&this.state.openSidebar?.tab===n?null:o:i=r?o:null;let a=i?{name:i}:null;return a&&n&&(a.tab=n),this.setState({openSidebar:a}),!!i});S(this,"updateCurrentCursorPosition",it(o=>{this.lastViewportPosition.x=o.clientX,this.lastViewportPosition.y=o.clientY}));S(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(),i=16;return Wn().rtl?{top:o+i,right:Math.max(this.state.width-(r?.left??this.state.width),0)+i,bottom:i,left:Math.max(n?.right??0,0)+i}:{top:o+i,right:Math.max(this.state.width-(n?.left??this.state.width)+i,0),bottom:i,left:Math.max(r?.right??0,0)+i}});S(this,"onKeyDown",it(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}})),!N4(o.target)){if((o.key===J.ESCAPE||o.key===J.ENTER)&&this.state.croppingElementId){this.finishImageCropping();return}let s=se(this.scene.getNonDeletedElementsMap(),this.state);if(s.length===1&&li(s[0])&&o.key===J.ENTER){this.startImageCropping(s[0]);return}if(o.key===J.ESCAPE)this.updateEditorAtom(jo,null);else if(o.key===J.TAB&&(document.activeElement===this.excalidrawContainerRef?.current||document.activeElement?.classList.contains(x1.CONVERT_ELEMENT_TYPE_POPUP))){o.preventDefault();let c=cs(s);pt.get(jo)?.type==="panel"&&gf(this,{conversionType:c,direction:o.shiftKey?"left":"right"})&&this.store.scheduleCapture(),c&&this.updateEditorAtom(jo,{type:"panel"})}if(o.key===J.ESCAPE&&this.flowChartCreator.isCreatingChart){this.flowChartCreator.clear(),this.triggerRender(!0);return}let l=Mu(o.key);if(o[J.CTRL_OR_CMD]&&l&&!o.shiftKey){o.preventDefault();let c=se(this.scene.getNonDeletedElementsMap(),this.state);c.length===1&&PX(c[0])&&this.flowChartCreator.createNodes(c[0],this.state,oM(o.key),this.scene),this.flowChartCreator.pendingNodes?.length&&!C1(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=se(this.scene.getNonDeletedElementsMap(),this.state);if(c.length===1&&l){o.preventDefault();let m=this.flowChartNavigator.exploreByDirection(c[0],this.scene.getNonDeletedElementsMap(),oM(o.key));if(m){this.setState(d=>({selectedElementIds:Be({[m]:!0},d)}));let p=this.scene.getNonDeletedElementsMap().get(m);p&&!C1([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[J.CTRL_OR_CMD]&&o.key===J.P&&!o.shiftKey&&!o.altKey){this.setToast({message:h("commandPalette.shortcutHint",{shortcut:Ue("commandPalette")})}),o.preventDefault();return}if(o[J.CTRL_OR_CMD]&&o.key.toLowerCase()===J.V&&(G1=o.shiftKey,clearTimeout(bM),bM=window.setTimeout(()=>{G1=!1},100)),o[J.CTRL_OR_CMD]&&Uc(o.target)&&(o.code===C4.MINUS||o.code===C4.EQUAL)){o.preventDefault();return}if(Uc(o.target)&&o.key!==J.ESCAPE||Mu(o.key)&&N4(o.target))return;if(o.key===J.QUESTION_MARK){this.setState({openDialog:{name:"help"}});return}else if(o.key.toLowerCase()===J.E&&o.shiftKey&&o[J.CTRL_OR_CMD]){o.preventDefault(),this.setState({openDialog:{name:"imageExport"}});return}if(o.key===J.PAGE_UP||o.key===J.PAGE_DOWN){let s=(o.shiftKey?this.state.width:this.state.height)/this.state.zoom.value;o.key===J.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===J.ALT&&(cr("COMPLEX_BINDINGS")?this.handleSkipBindMode():Ou({app:this,event:o})),this.actionManager.handleKeyDown(o)))return;let n=this.props.viewModeEnabled===!0;if(!n&&this.state.viewModeEnabled&&o.key===J.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=aI(o.key,this);if(this.state.viewModeEnabled&&!z4(s,["laser","hand"]))return;if(s){this.state.activeTool.type!==s&&he("toolbar",s,`keyboard (${this.editorInterface.formFactor==="phone"?"mobile":"desktop"})`),s==="arrow"&&this.state.activeTool.type==="arrow"&&this.setState(l=>({currentItemArrowType:l.currentItemArrowType===ai.sharp?ai.round:l.currentItemArrowType===ai.round?ai.elbow:ai.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===J.Q){this.toggleLock("keyboard"),o.stopPropagation();return}}if(this.state.viewModeEnabled)return;if(o[J.CTRL_OR_CMD]&&this.state.isBindingEnabled&&(cr("COMPLEX_BINDINGS")&&this.resetDelayedBindMode(),co(()=>{this.setState({isBindingEnabled:!1})}),Ou({app:this,event:o})),Mu(o.key)){let s=this.scene.getSelectedElements({selectedElementIds:this.state.selectedElementIds,includeBoundTextElement:!0,includeElementsInFrames:!0}),l=new Set;s.filter(d=>zn(d)).filter(d=>{let u=d.startBinding&&!s.some(g=>g.id===d.startBinding?.elementId),b=d.endBinding&&!s.some(g=>g.id===d.endBinding?.elementId);return u||b}).forEach(d=>l.add(d.id)),s=s.filter(d=>!l.has(d.id));let c=this.getEffectiveGridSize()&&(o.shiftKey?A4:this.getEffectiveGridSize())||(o.shiftKey?FK:A4),m=0,p=0;o.key===J.ARROW_LEFT?m=-c:o.key===J.ARROW_RIGHT?m=c:o.key===J.ARROW_UP?p=-c:o.key===J.ARROW_DOWN&&(p=c),s.forEach(d=>{this.scene.mutateElement(d,{x:d.x+m,y:d.y+p},{informMutation:!1,isDragging:!1}),Bu(d,this.scene,{simultaneouslyUpdated:s})}),this.scene.triggerUpdate(),o.preventDefault()}else if(o.key===J.ENTER){let s=this.scene.getSelectedElements(this.state);if(s.length===1){let l=s[0];if(o[J.CTRL_OR_CMD]||R1(l))eo(l)&&(!this.state.selectedLinearElement?.isEditing||this.state.selectedLinearElement.elementId!==l.id)&&(this.store.scheduleCapture(),mo(l)||this.actionManager.executeAction(Cs));else if(an(l)||NX(l)){let c;an(l)||(c=l);let m=M1(l,this.state,this.scene.getNonDeletedElementsMap()),p=m.x,d=m.y;this.startTextEditing({sceneX:p,sceneY:d,container:c}),o.preventDefault();return}else Vt(l)&&this.setState({editingFrame:l.id})}}if(o.key===J.SPACE&&Le.pointers.size===0&&(ci=!0,De(this.interactiveCanvas,et.GRAB),o.preventDefault()),(o.key===J.G||o.key===J.S)&&!o.altKey&&!o[J.CTRL_OR_CMD]){let s=this.scene.getSelectedElements(this.state);if(this.state.activeTool.type==="selection"&&!s.length)return;o.key===J.G&&(cn(this.state.activeTool.type)||s.some(l=>cn(l.type)))&&(this.setState({openPopup:"elementBackground"}),o.stopPropagation()),o.key===J.S&&(this.setState({openPopup:"elementStroke"}),o.stopPropagation())}if(!o[J.CTRL_OR_CMD]&&o.shiftKey&&o.key.toLowerCase()===J.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=>an(l)||S1(l,this.scene.getNonDeletedElementsMap())))&&(o.preventDefault(),this.setState({openPopup:"fontFamily"}))}o[J.CTRL_OR_CMD]&&(o.key===J.BACKSPACE||o.key===J.DELETE)&&this.updateEditorAtom(Ni,"clearCanvas");let r=o.key.toLocaleLowerCase(),i=r===J.S&&o.shiftKey,a=o.key===J.I||r===J.G&&o.shiftKey;(i||a)&&this.openEyeDropper({type:i?"stroke":"background"})}));S(this,"onKeyUp",it(o=>{if(o.key===J.SPACE&&(this.state.viewModeEnabled&&this.state.activeTool.type!=="laser"||this.state.openDialog?.name==="elementLinkSelector"?De(this.interactiveCanvas,et.GRAB):Ru(this.state.activeTool.type)?fo(this.interactiveCanvas):(bo(this.interactiveCanvas,this.state),this.setState({selectedElementIds:Be({},this.state),selectedGroupIds:{},editingGroupId:null,activeEmbeddable:null})),ci=!1),o.key===J.ALT&&Ou({app:this,event:o}),(o.key===J.ALT&&this.state.bindMode==="skip"||!o[J.CTRL_OR_CMD]&&!Yc(this.state))&&(this.setState({bindMode:"orbit"}),this.lastPointerMoveEvent&&cr("COMPLEX_BINDINGS"))){let n=je({clientX:this.lastPointerMoveEvent.clientX,clientY:this.lastPointerMoveEvent.clientY},this.state),r=rn(ce(n.x,n.y),this.scene.getNonDeletedElements(),this.scene.getNonDeletedElementsMap());if(this.state.selectedLinearElement){let i=ke.getElement(this.state.selectedLinearElement.elementId,this.scene.getNonDeletedElementsMap());zn(i)&&this.handleDelayedBindModeChange(i,r)}}if(!o[J.CTRL_OR_CMD]&&!this.state.isBindingEnabled&&(co(()=>{this.setState({isBindingEnabled:!0})}),Ou({app:this,event:o})),Mu(o.key)){O4(this.scene.getSelectedElements(this.state).filter(Qs),this.scene,this.state);let n=this.scene.getNonDeletedElementsMap();this.scene.getSelectedElements(this.state).filter(N1).forEach(r=>{r.startBinding&&this.scene.mutateElement(r,{startBinding:{...r.startBinding,...gM(r,n.get(r.startBinding.elementId),"start",n)}}),r.endBinding&&this.scene.mutateElement(r,{endBinding:{...r.endBinding,...gM(r,n.get(r.endBinding.elementId),"end",n)}})}),this.setState({suggestedBinding:null})}if(o.altKey||this.flowChartNavigator.isExploring&&(this.flowChartNavigator.clear(),this.syncActionResult({captureUpdate:to.IMMEDIATELY})),!o[J.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:Be({[n.id]:!0},r)})),C1([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:to.IMMEDIATELY})}}));S(this,"isToolSupported",o=>this.props.UIOptions.tools?.[o]!==!1);S(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=Bn(this.state,o);r.type==="hand"?De(this.interactiveCanvas,et.GRAB):ci||bo(this.interactiveCanvas,{...this.state,activeTool:r}),QK(document.activeElement)&&this.focusContainer(),SX(r.type)||this.setState({suggestedBinding:null}),r.type==="image"&&this.onImageToolbarButtonClick(),this.setState(i=>{let a={snapLines:i.snapLines.length?[]:i.snapLines,originSnapOffset:null,activeEmbeddable:null,selectedLinearElement:Ru(r.type)?i.selectedLinearElement:null};return r.type==="freedraw"&&this.store.scheduleCapture(),r.type==="lasso"?{...i,...a,activeTool:r,...n?{}:{selectedElementIds:Be({},i),selectedGroupIds:Be({},i),editingGroupId:null,multiElement:null}}:r.type!=="selection"?{...i,...a,activeTool:r,selectedElementIds:Be({},i),selectedGroupIds:Be({},i),editingGroupId:null,multiElement:null}:{...i,...a,activeTool:r}})});S(this,"setOpenDialog",o=>{this.setState({openDialog:o})});S(this,"setCursor",o=>{De(this.interactiveCanvas,o)});S(this,"resetCursor",()=>{fo(this.interactiveCanvas)});S(this,"isTouchScreenMultiTouchGesture",()=>Le.pointers.size>=2);S(this,"getName",()=>this.state.name||this.props.name||`${h("labels.untitled")}-${B4()}`);S(this,"onGestureStart",it(o=>{o.preventDefault(),this.isTouchScreenMultiTouchGesture()&&this.setState({selectedElementIds:Be({},this.state),activeEmbeddable:null}),Le.initialScale=this.state.zoom.value}));S(this,"onGestureChange",it(o=>{if(o.preventDefault(),this.isTouchScreenMultiTouchGesture())return;let n=Le.initialScale;n&&this.setState(r=>({...Xn({viewportX:this.lastViewportPosition.x,viewportY:this.lastViewportPosition.y,nextZoom:ln(n*o.scale)},r)}))}));S(this,"onGestureEnd",it(o=>{o.preventDefault(),this.isTouchScreenMultiTouchGesture()&&this.setState({previousSelectedElementIds:{},selectedElementIds:Be(this.state.previousSelectedElementIds,this.state)}),Le.initialScale=null}));S(this,"startTextEditing",({sceneX:o,sceneY:n,insertAtParentCenter:r=!0,container:i,autoEdit:a=!0})=>{let s=!1,l=r&&this.getTextWysiwygSnappedToCenterPosition(o,n,this.state,i);i&&l&&(S1(i,this.scene.getNonDeletedElementsMap())||(s=!0));let c=null,m=this.scene.getSelectedElements(this.state);m.length===1?an(m[0])?c=m[0]:i?c=S1(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||D4(p),u=this.state.currentItemFontSize;if(!c&&s&&i&&!Qs(i)){let y=o$(h1({fontSize:u,fontFamily:p}),d),x=n$(u,d),w=Math.max(i.height,x),v=Math.max(i.width,y);this.scene.mutateElement(i,{height:w,width:v}),o=i.x+v/2,n=i.y+w/2,l&&(l=this.getTextWysiwygSnappedToCenterPosition(o,n,this.state,i))}let b=this.getTopLayerFrameAtSceneCoords({x:o,y:n}),g=c||W4({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?VK.MIDDLE:M4,containerId:s?i?.id:void 0,groupIds:i?.groupIds??[],lineHeight:d,angle:i?Qs(i)?0:i.angle:0,frameId:b?b.id:null});if(!c&&s&&i&&this.scene.mutateElement(i,{boundElements:(i.boundElements||[]).concat({type:"text",id:g.id})}),this.setState({editingTextElement:g}),!c)if(i&&s){let E=this.scene.getElementIndex(i.id);this.scene.insertElementAtIndex(g,E+1)}else this.scene.insertElement(g);a||c||i?this.handleTextWysiwyg(g,{isExistingElement:!!c}):this.setState({newElement:g,multiElement:null})});S(this,"startImageCropping",o=>{this.store.scheduleCapture(),this.setState({croppingElementId:o.id})});S(this,"finishImageCropping",()=>{this.state.croppingElementId&&(this.store.scheduleCapture(),this.setState({croppingElementId:null}))});S(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:i}=je(o,this.state);if(n.length===1&&eo(n[0])){let s=n[0];if((o[J.CTRL_OR_CMD]&&N1(s)||R1(s))&&(!this.state.selectedLinearElement?.isEditing||this.state.selectedLinearElement.elementId!==s.id)){this.actionManager.executeAction(Cs);return}else if(this.state.selectedLinearElement&&mo(n[0])){let l=ke.getSegmentMidpointHitCoords(this.state.selectedLinearElement,{x:r,y:i},this.state,this.scene.getNonDeletedElementsMap()),c=l?ke.getSegmentMidPointIndex(this.state.selectedLinearElement,this.state,l,this.scene.getNonDeletedElementsMap()):-1;if(c&&c>-1){this.store.scheduleCapture(),ke.deleteFixedSegment(n[0],this.scene,c);let m=ke.getSegmentMidpointHitCoords({...this.state.selectedLinearElement,segmentMidPointHoveredCoords:null},{x:r,y:i},this.state,this.scene.getNonDeletedElementsMap()),p=m?ke.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&&R1(s))return}if(n.length===1&&li(n[0])){this.startImageCropping(n[0]);return}if(fo(this.interactiveCanvas),l$(this.state).length>0){let s=this.getElementAtPosition(r,i),l=s&&s$(s,this.state.selectedGroupIds);if(l){this.store.scheduleCapture(),this.setState(c=>({...c,...Go({editingGroupId:l,selectedElementIds:{[s.id]:!0}},this.scene.getNonDeletedElements(),c,this)}));return}}if(fo(this.interactiveCanvas),!o[J.CTRL_OR_CMD]&&!this.state.viewModeEnabled){let s=this.getElementAtPosition(r,i);if(v1(s)){this.setState({activeEmbeddable:{element:s,state:"active"}});return}if(!this.state.selectedLinearElement?.isEditing){let l=this.getTextBindableContainerAtPosition(r,i);if(l&&(V4(l)||!tX(l.backgroundColor)||Kc({point:ce(r,i),element:l,elementsMap:this.scene.getNonDeletedElementsMap(),threshold:this.getElementHitThreshold(l)}))){let c=M1(l,this.state,this.scene.getNonDeletedElementsMap());r=c.x,i=c.y}this.startTextEditing({sceneX:r,sceneY:i,insertAtParentCenter:!o.altKey,container:l})}}});S(this,"getElementLinkAtPosition",(o,n)=>{if(n&&n.locked)return;let r=this.scene.getNonDeletedElements(),i=-1;for(let a=r.length-1;a>=0;a--){let s=r[a];if(n&&s.id===n.id&&(i=a),s.link&&a>=i&&ld(s,this.scene.getNonDeletedElementsMap(),this.state,ce(o.x,o.y),this.editorInterface.formFactor==="phone"))return s}});S(this,"handleElementLinkClick",o=>{let n=ri(ce(this.lastPointerDownEvent.clientX,this.lastPointerDownEvent.clientY),ce(this.lastPointerUpEvent.clientX,this.lastPointerUpEvent.clientY));if(!this.hitLinkElement||n>P4)return;let r=je(this.lastPointerDownEvent,this.state),i=this.scene.getNonDeletedElementsMap(),a=ld(this.hitLinkElement,i,this.state,ce(r.x,r.y),this.editorInterface.formFactor==="phone"),s=je(this.lastPointerUpEvent,this.state),l=ld(this.hitLinkElement,i,this.state,ce(s.x,s.y),this.editorInterface.formFactor==="phone");if(a&&l){of();let c=this.hitLinkElement.link;if(c){c=g1(c);let m;if(this.props.onLinkOpen&&(m=eX(ue.EXCALIDRAW_LINK,o.nativeEvent),this.props.onLinkOpen({...this.hitLinkElement,link:c},m)),!m?.defaultPrevented){let p=jK(c)?"_self":"_blank",d=window.open(void 0,p);d&&(d.opener=null,d.location=c)}}}});S(this,"getTopLayerFrameAtSceneCoords",o=>{let n=this.scene.getNonDeletedElementsMap(),r=this.scene.getNonDeletedFramesLikes().filter(i=>!i.locked&&Q4(o,i,n));return r.length?r[r.length-1]:null});S(this,"handleCanvasPointerMove",o=>{this.savePointer(o.clientX,o.clientY,this.state.cursorButton),this.lastPointerMoveEvent=o.nativeEvent;let n=je(o,this.state),{x:r,y:i}=n;this.lastPointerMoveCoords={x:r,y:i},Le.pointers.has(o.pointerId)&&Le.pointers.set(o.pointerId,{x:o.clientX,y:o.clientY});let a=Le.initialScale;if(Le.pointers.size===2&&Le.lastCenter&&a&&Le.initialDistance){let g=E0(Le.pointers),E=g.x-Le.lastCenter.x,y=g.y-Le.lastCenter.y;Le.lastCenter=g;let x=y0(Array.from(Le.pointers.values())),w=this.state.activeTool.type==="freedraw"&&this.state.penMode?1:x/Le.initialDistance,v=w?ln(a*w):this.state.zoom.value;this.setState(T=>{let C=Xn({viewportX:g.x,viewportY:g.y,nextZoom:v},T);return this.translateCanvas({zoom:C.zoom,scrollX:C.scrollX+2*(E/v),scrollY:C.scrollY+2*(y/v),shouldCacheIgnoreZoom:!0}),null}),this.resetShouldCacheIgnoreZoomDebounced()}else Le.lastCenter=Le.initialDistance=Le.initialScale=null;if(ci||jc||O1||Un(this.state))return;let l=H0(qc,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?fo(this.interactiveCanvas):bo(this.interactiveCanvas,this.state)),!this.state.newElement&&O3(this.state.activeTool.type)){let{originOffset:g,snapLines:E}=z3(this.scene.getNonDeletedElements(),this,{x:r,y:i},o,this.scene.getNonDeletedElementsMap());this.setState(y=>{let x=Wc(y.snapLines,E),w=y.originSnapOffset?Wc(y.originSnapOffset,g):g;return y.snapLines===x&&y.originSnapOffset===w?null:{snapLines:x,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:ke.handlePointerMoveInEditMode(o,r,i,this);g&&g!==this.state.selectedLinearElement&&co(()=>{this.setState({selectedLinearElement:g})})}if(kX(this.state.activeTool.type)){let{newElement:g}=this.state;if(!g&&Yc(this.state)){let E=ce(r,i),y=this.scene.getNonDeletedElementsMap(),x=rn(E,this.scene.getNonDeletedElements(),y,B1(this.state.zoom));x?this.setState({suggestedBinding:{element:x,midPoint:F1(E,x,y,this.state.zoom)}}):this.state.suggestedBinding&&this.setState({suggestedBinding:null})}}if(this.state.multiElement&&this.state.selectedLinearElement){let{multiElement:g,selectedLinearElement:E}=this.state,{x:y,y:x,points:w}=g,v=w[w.length-1],{lastCommittedPoint:T}=E;if(bo(this.interactiveCanvas,this.state),v===T)Qs(this.state.newElement)&&Yc(this.state)&&rn(ce(r,i),this.scene.getNonDeletedElements(),this.scene.getNonDeletedElementsMap(),B1(this.state.zoom))?(this.actionManager.executeAction(Zt,"ui",{event:o.nativeEvent,sceneCoords:{x:r,y:i}}),this.setState({suggestedBinding:null,startBoundElement:null}),this.state.activeTool.locked||(fo(this.interactiveCanvas),this.setState(M=>({newElement:null,activeTool:Bn(this.state,{type:this.state.preferredSelectionTool.type}),selectedElementIds:Be({...M.selectedElementIds,[g.id]:!0},M),selectedLinearElement:new ke(g,this.scene.getNonDeletedElementsMap())})))):ri(ce(r-y,i-x),v)>=u1?(this.scene.mutateElement(g,{points:[...w,ce(r-y,i-x)]},{informMutation:!1,isDragging:!1}),Fn(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}}})):De(this.interactiveCanvas,et.POINTER);else if(w.length>2&&T&&ri(ce(r-y,i-x),T)<u1)De(this.interactiveCanvas,et.POINTER),this.scene.mutateElement(g,{points:w.slice(0,-1)},{informMutation:!1,isDragging:!1}),this.setState({selectedLinearElement:{...E,selectedPointsIndices:E.selectedPointsIndices?.includes(g.points.length)?[...E.selectedPointsIndices.filter(C=>C!==g.points.length&&C!==g.points.length-1),g.points.length-1]:E.selectedPointsIndices,lastCommittedPoint:g.points[g.points.length-1],initialState:{...E.initialState,lastClickedPoint:g.points.length-1}}});else{Z4(w,this.state.zoom.value)&&De(this.interactiveCanvas,et.POINTER);let C=this.scene.getNonDeletedElementsMap();if(N1(g)){let k=rn(ce(r,i),this.scene.getNonDeletedElements(),C);cr("COMPLEX_BINDINGS")&&this.handleDelayedBindModeChange(g,k)}Fn(this.state.selectedLinearElement,"Expected selectedLinearElement to be set to operate on a linear element");let M=ke.handlePointerMove(o.nativeEvent,this,r,i,this.state.selectedLinearElement);M&&this.setState(M)}return}if(this.state.activeTool.type==="arrow"){let g=rn(ce(r,i),this.scene.getNonDeletedElements(),this.scene.getNonDeletedElementsMap(),B1(this.state.zoom)),E=ce(r,i),y=this.scene.getNonDeletedElementsMap();g&&!w$(E,g,y)&&this.setState({suggestedBinding:{element:g,midPoint:F1(E,g,y,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,i),(!this.state.selectedLinearElement||this.state.selectedLinearElement.hoverPointIndex===-1)&&this.state.openDialog?.name!=="elementLinkSelector"&&!(d.length===1&&mo(d[0]))&&!(eo(d[0])&&(this.editorInterface.userAgent.isMobileDevice||d[0].points.length===2))){let g=sM(p,this.state,r,i,this.state.zoom,o.pointerType,this.scene.getNonDeletedElementsMap(),this.editorInterface);if(g&&g.transformHandleType){De(this.interactiveCanvas,aM(g));return}}}else if(d.length>1&&!l&&this.state.openDialog?.name!=="elementLinkSelector"){let g=lM(Js(d),r,i,this.state.zoom,o.pointerType,this.editorInterface);if(g){De(this.interactiveCanvas,aM({transformHandleType:g}));return}}if(oo(this.state))return;let u=this.getElementAtPosition(r,i,{preferSelected:!0,includeLockedElements:!0}),b=null;if(u&&u.locked?b=null:b=u,this.handleIframeLikeElementHover({hitElement:b,scenePointer:n,moveEvent:o})||(this.hitLinkElement=this.getElementLinkAtPosition(n,u)),this.hitLinkElement&&!this.state.selectedElementIds[this.hitLinkElement.id])De(this.interactiveCanvas,et.POINTER),A2(this.hitLinkElement,this.state,this.scene.getNonDeletedElementsMap());else{if(of(),m)return;b&&(b.link||dr(b))&&this.state.selectedElementIds[b.id]&&!this.state.contextMenu&&!this.state.showHyperlinkPopup?this.setState({showHyperlinkPopup:"info"}):this.state.activeTool.type==="text"?De(this.interactiveCanvas,an(b)?et.TEXT:et.CROSSHAIR):this.state.viewModeEnabled?De(this.interactiveCanvas,et.GRAB):this.state.openDialog?.name==="elementLinkSelector"?De(this.interactiveCanvas,et.AUTO):l?De(this.interactiveCanvas,et.AUTO):o[J.CTRL_OR_CMD]?De(this.interactiveCanvas,et.AUTO):(b||this.isHittingCommonBoundingBoxOfSelectedElements(n,d))&&!b?.locked&&(!b||!mo(b)||!(b.startBinding||b.endBinding))&&(this.state.activeTool.type!=="lasso"||d.length>0)&&De(this.interactiveCanvas,et.MOVE),this.state.selectedLinearElement&&this.handleHoverSelectedLinearElement(this.state.selectedLinearElement,r,i)}this.state.openDialog?.name==="elementLinkSelector"&&b?this.setState(g=>({hoveredElementIds:Wc(g.hoveredElementIds,Go({editingGroupId:g.editingGroupId,selectedElementIds:{[b.id]:!0}},this.scene.getNonDeletedElements(),g,this).selectedElementIds)})):this.state.openDialog?.name==="elementLinkSelector"&&!b&&this.setState(g=>({hoveredElementIds:Wc(g.hoveredElementIds,{})}))});S(this,"handleEraser",(o,n)=>{let r=this.eraserTrail.addPointToPath(n.x,n.y,o.altKey);this.elementsPendingErasure=new Set(r),this.triggerRender()});S(this,"handleTouchMove",o=>{Jc=!0});S(this,"handleCanvasPointerDown",o=>{let n=je(o,this.state),{x:r,y:i}=n;this.lastPointerMoveCoords={x:r,y:i};let a=o.target;if(a.setPointerCapture&&a.setPointerCapture(o.pointerId),this.maybeCleanupAfterMissingPointerUp(o.nativeEvent),this.maybeUnfollowRemoteUser(),this.state.searchMatches&&(this.setState(b=>({searchMatches:b.searchMatches&&{focusedId:null,matches:b.searchMatches.matches.map(g=>({...g,focus:!1}))}})),this.updateEditorAtom(gb,null)),pt.get(jo)&&this.updateEditorAtom(jo,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 b=this.state.newElement;this.updateScene({...b.points.length<10?{elements:this.scene.getElementsIncludingDeleted().filter(g=>g.id!==b.id)}:{},appState:{newElement:null,editingTextElement:null,startBoundElement:null,suggestedBinding:null,selectedElementIds:Be(Object.keys(this.state.selectedElementIds).filter(g=>g!==b.id).reduce((g,E)=>(g[E]=this.state.selectedElementIds[E],g),{}),this.state)},captureUpdate:this.state.openDialog?.name==="elementLinkSelector"?to.EVENTUALLY:to.NEVER});return}let s=document.getSelection();if(s?.anchorNode&&s.removeAllRanges(),this.maybeOpenContextMenuAfterPointerDownOnTouchDevices(o),!this.state.penDetected&&o.pointerType==="pen"&&this.setState(b=>({penMode:!0,penDetected:!0})),!this.editorInterface.isTouchScreen&&["pen","touch"].includes(o.pointerType)&&(this.editorInterface=b1(this.editorInterface,{isTouchScreen:!0})),jc||(this.lastPointerDownEvent=o,this.handleCanvasPanUsingWheelOrSpaceDrag(o)))return;if(this.setState({lastPointerDownWith:o.pointerType,cursorButton:"down"}),this.savePointer(o.clientX,o.clientY,"down"),o.button===ii.ERASER&&this.state.activeTool.type!==Nn.eraser){this.setState({activeTool:Bn(this.state,{type:Nn.eraser,lastActiveToolBeforeEraser:this.state.activeTool})},()=>{this.handleCanvasPointerDown(o);let b=()=>{g(),E?.(),oo(this.state)&&this.setState({activeTool:Bn(this.state,{...this.state.activeTool.lastActiveTool||{type:Nn.selection},lastActiveToolBeforeEraser:null})})},g=lt(window,ue.POINTER_UP,b,{once:!0}),E;requestAnimationFrame(()=>{E=this.missingPointerEventCleanupEmitter.once(b)})});return}if(o.button!==ii.MAIN&&o.button!==ii.TOUCH&&o.button!==ii.ERASER||Le.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 b=l.hit.element&&this.isASelectedElement(l.hit.element);!l.hit.hasHitCommonBoundingBoxOfSelectedElements&&!l.resize.handleType&&!b&&(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&&!b&&(this.setState(g=>{let E={...g.selectedElementIds,[l.hit.element.id]:!0},y=[];Object.keys(g.selectedElementIds).forEach(w=>{let v=this.scene.getElement(w);v&&y.push(v)});let x=l.hit.element;if(Vt(x))P1(y,x.id).forEach(w=>{delete E[w.id]});else if(x.frameId)E[x.frameId]&&delete E[x.id];else{let w=x.groupIds,v=new Set(w.flatMap(T=>ta(this.scene.getNonDeletedElements(),T)).filter(T=>Vt(T)).map(T=>T.id));v.size>0&&y.forEach(T=>{T.frameId&&v.has(T.frameId)&&(delete E[T.id],T.groupIds.flatMap(C=>ta(this.scene.getNonDeletedElements(),C)).forEach(C=>{delete E[C.id]}))})}return{...Go({editingGroupId:g.editingGroupId,selectedElementIds:E},this.scene.getNonDeletedElements(),g,this),showHyperlinkPopup:x.link||dr(x)?"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"?bo(this.interactiveCanvas,this.state):this.state.activeTool.type===Nn.frame||this.state.activeTool.type===Nn.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(b=>p(b||o.nativeEvent)),(!this.state.viewModeEnabled||this.state.activeTool.type==="laser")&&(window.addEventListener(ue.POINTER_MOVE,m),window.addEventListener(ue.POINTER_UP,p),window.addEventListener(ue.KEYDOWN,d),window.addEventListener(ue.KEYUP,u),l.eventListeners.onMove=m,l.eventListeners.onUp=p,l.eventListeners.onKeyUp=u,l.eventListeners.onKeyDown=d)});S(this,"handleCanvasPointerUp",o=>{cr("COMPLEX_BINDINGS")&&this.resetDelayedBindMode(),this.removePointer(o),this.lastPointerUpEvent=o;let n=je({clientX:o.clientX,clientY:o.clientY},this.state),{x:r,y:i}=n;if(this.lastPointerMoveCoords={x:r,y:i},!this.handleIframeLikeCenterClick()){if(this.editorInterface.isTouchScreen){let a=this.getElementAtPosition(n.x,n.y,{includeLockedElements:!0});this.hitLinkElement=this.getElementLinkAtPosition(n,a)}this.hitLinkElement&&!this.state.selectedElementIds[this.hitLinkElement.id]?this.handleElementLinkClick(o):this.state.viewModeEnabled&&this.setState({activeEmbeddable:null,selectedElementIds:{}})}});S(this,"maybeOpenContextMenuAfterPointerDownOnTouchDevices",o=>{o.pointerType==="touch"&&(Jc=!1,di?Jc=!0:di=window.setTimeout(()=>{di=0,Jc||this.handleCanvasContextMenu(o)},YK))});S(this,"resetContextMenuTimer",()=>{clearTimeout(di),di=0,Jc=!1});S(this,"maybeCleanupAfterMissingPointerUp",o=>{Qc?.(),this.missingPointerEventCleanupEmitter.trigger(o).clear()});S(this,"handleCanvasPanUsingWheelOrSpaceDrag",o=>{if(!(Le.pointers.size<=1&&(o.button===ii.WHEEL||o.button===ii.MAIN&&ci||Un(this.state)||this.state.viewModeEnabled&&this.state.activeTool.type!=="laser")))return!1;jc=!0,this.focusContainer(),this.state.editingTextElement||o.preventDefault();let n=!1,r=typeof window===void 0?!1:/Linux/.test(window.navigator.platform);De(this.interactiveCanvas,et.GRABBING);let{clientX:i,clientY:a}=o,s=Rp(c=>{let m=i-c.clientX,p=a-c.clientY;if(i=c.clientX,a=c.clientY,r&&!n&&(Math.abs(m)>1||Math.abs(p)>1)){n=!0;let d=b=>{document.body.removeEventListener(ue.PASTE,d),b.stopPropagation()},u=()=>{setTimeout(()=>{document.body.removeEventListener(ue.PASTE,d),window.removeEventListener(ue.POINTER_UP,u)},100)};document.body.addEventListener(ue.PASTE,d),window.addEventListener(ue.POINTER_UP,u)}this.translateCanvas({scrollX:this.state.scrollX-m/this.state.zoom.value,scrollY:this.state.scrollY-p/this.state.zoom.value})}),l=it(Qc=()=>{Qc=null,jc=!1,ci||(this.state.viewModeEnabled&&this.state.activeTool.type!=="laser"?De(this.interactiveCanvas,et.GRAB):bo(this.interactiveCanvas,this.state)),this.setState({cursorButton:"up"}),this.savePointer(o.clientX,o.clientY,"up"),window.removeEventListener(ue.POINTER_MOVE,s),window.removeEventListener(ue.POINTER_UP,l),window.removeEventListener(ue.BLUR,l),s.flush()});return window.addEventListener(ue.BLUR,l),window.addEventListener(ue.POINTER_MOVE,s,{passive:!0}),window.addEventListener(ue.POINTER_UP,l),!0});S(this,"clearSelectionIfNotUsingSelection",()=>{Ru(this.state.activeTool.type)||this.setState({selectedElementIds:Be({},this.state),selectedGroupIds:{},editingGroupId:null,activeEmbeddable:null})});S(this,"handleSelectionOnPointerDown",(o,n)=>{if(Ru(this.state.activeTool.type)){let r=this.scene.getNonDeletedElements(),i=this.scene.getNonDeletedElementsMap(),a=this.scene.getSelectedElements(this.state);if(a.length===1&&!this.state.selectedLinearElement?.isEditing&&!mo(a[0])&&!(eo(a[0])&&(this.editorInterface.userAgent.isMobileDevice||a[0].points.length===2))&&!(this.state.selectedLinearElement&&this.state.selectedLinearElement.hoverPointIndex!==-1)){let s=sM(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 a.length>1&&(n.resize.handleType=lM(Js(a),n.origin.x,n.origin.y,this.state.zoom,o.pointerType,this.editorInterface));if(n.resize.handleType)n.resize.isResizing=!0,n.resize.offset=f1(p$(n.resize.handleType,a,i,n.origin.x,n.origin.y)),a.length===1&&eo(a[0])&&a[0].points.length===2&&(n.resize.arrowDirection=u$(n.resize.handleType,a[0]));else{if(this.state.selectedLinearElement){let d=this.state.selectedLinearElement,u=ke.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 b=this.scene.getNonDeletedElementsMap(),g=ke.getElement(d.elementId,b);if(g&&zn(g)){let{hitFocusPoint:E,pointerOffset:y}=I$(g,n,b,this.state);if(E)return this.setState({selectedLinearElement:{...d,hoveredFocusPointBinding:E,draggedFocusPointBinding:E,pointerOffset:y}}),!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?Be({[d.selectedLinearElement.elementId]:!0},this.state):Be({},d)}));else if(m!=null){if(o[J.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=>({...a$(d,m),previousSelectedElementIds:this.state.selectedElementIds})),!1);this.state.selectedElementIds[m.id]||(this.state.editingGroupId&&!rM(m,this.state.editingGroupId)&&this.setState({selectedElementIds:Be({},this.state),selectedGroupIds:{},editingGroupId:null,activeEmbeddable:null}),!p&&!n.hit.hasHitCommonBoundingBoxOfSelectedElements&&(this.setState(d=>{let u={...d.selectedElementIds,[m.id]:!0},b=[];if(Object.keys(d.selectedElementIds).forEach(g=>{let E=this.scene.getElement(g);E&&b.push(E)}),Vt(m))P1(b,m.id).forEach(g=>{delete u[g.id]});else if(m.frameId)u[m.frameId]&&delete u[m.id];else{let g=m.groupIds,E=new Set(g.flatMap(y=>ta(this.scene.getNonDeletedElements(),y)).filter(y=>Vt(y)).map(y=>y.id));E.size>0&&b.forEach(y=>{y.frameId&&E.has(y.frameId)&&(delete u[y.id],y.groupIds.flatMap(x=>ta(this.scene.getNonDeletedElements(),x)).forEach(x=>{delete u[x.id]}))})}return d.openDialog?.name==="elementLinkSelector"&&(m.groupIds.some(g=>d.selectedGroupIds[g])||(u={[m.id]:!0})),{...Go({editingGroupId:d.editingGroupId,selectedElementIds:u},this.scene.getNonDeletedElements(),d,this),showHyperlinkPopup:m.link||dr(m)?"info":!1}}),n.hit.wasAddedToSelection=!0))}this.setState({previousSelectedElementIds:this.state.selectedElementIds})}}return!1});S(this,"handleTextOnPointerDown",(o,n)=>{if(this.state.editingTextElement)return;let r=n.origin.x,i=n.origin.y,a=this.getElementAtPosition(r,i,{includeBoundTextElement:!0}),s=this.getTextBindableContainerAtPosition(r,i);V4(a)&&(s=a,r=a.x+a.width/2,i=a.y+a.height/2),this.startTextEditing({sceneX:r,sceneY:i,insertAtParentCenter:!o.altKey,container:s,autoEdit:!1}),fo(this.interactiveCanvas),this.state.activeTool.locked||this.setState({activeTool:Bn(this.state,{type:this.state.preferredSelectionTool.type})})});S(this,"handleFreeDrawElementOnPointerDown",(o,n,r)=>{let[i,a]=Yt(r.origin.x,r.origin.y,null),s=this.getTopLayerFrameAtSceneCoords({x:i,y:a}),l=o.pressure===.5,c=yX({type:n,x:i,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:null,simulatePressure:l,locked:!1,frameId:s?s.id:null,points:[ce(0,0)],pressures:l?[]:[o.pressure]});this.scene.insertElement(c),this.setState(p=>{let d={...p.selectedElementIds};return delete d[c.id],{selectedElementIds:Be(d,p)}});let m=rn(ce(r.origin.x,r.origin.y),this.scene.getNonDeletedElements(),this.scene.getNonDeletedElementsMap());this.setState({newElement:c,startBoundElement:m,suggestedBinding:null})});S(this,"insertIframeElement",({sceneX:o,sceneY:n,width:r,height:i})=>{let[a,s]=Yt(o,n,this.lastPointerDownEvent?.[J.CTRL_OR_CMD]?null:this.getEffectiveGridSize()),l=wX({type:"iframe",x:a,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:i});return this.scene.insertElement(l),l});S(this,"insertEmbeddableElement",({sceneX:o,sceneY:n,link:r})=>{let[i,a]=Yt(o,n,this.lastPointerDownEvent?.[J.CTRL_OR_CMD]?null:this.getEffectiveGridSize()),s=Fu(r);if(!s)return;s.error instanceof URIError&&this.setToast({message:h("toast.unrecognizedLinkFormat"),closable:!0});let l=G4({type:"embeddable",x:i,y:a,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});S(this,"newImagePlaceholder",({sceneX:o,sceneY:n,addToFrameUnderCursor:r=!0})=>{let[i,a]=Yt(o,n,this.lastPointerDownEvent?.[J.CTRL_OR_CMD]?null:this.getEffectiveGridSize()),s=r?this.getTopLayerFrameAtSceneCoords({x:i,y:a}):null,l=100/this.state.zoom.value;return E1({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:i-l/2,y:a-l/2,width:l,height:l})});S(this,"handleLinearElementOnPointerDown",(o,n,r)=>{if(o.ctrlKey&&co(()=>{this.setState({isBindingEnabled:!1})}),this.state.multiElement){let{multiElement:i,selectedLinearElement:a}=this.state;if(Fn(a,"selectedLinearElement is expected to be set"),i.type==="line"&&Z4(i.points,this.state.zoom.value)){co(()=>{this.setState({selectedLinearElement:{...a,lastCommittedPoint:i.points[i.points.length-1],initialState:{...a.initialState,lastClickedPoint:-1}}})}),this.actionManager.executeAction(Zt);return}if(mo(i)&&i.points.length>1){this.actionManager.executeAction(Zt,"ui",{event:o.nativeEvent,sceneCoords:{x:r.origin.x,y:r.origin.y}});return}let{x:s,y:l}=i,{lastCommittedPoint:c}=a,m=Yc(this.state)&&rn(ce(this.lastPointerMoveCoords?.x??s+i.points[i.points.length-1][0],this.lastPointerMoveCoords?.y??l+i.points[i.points.length-1][1]),this.scene.getNonDeletedElements(),this.scene.getNonDeletedElementsMap());if(zn(i)&&m||i.points.length>1&&c&&ri(ce(r.origin.x-s,r.origin.y-l),c)<u1){this.actionManager.executeAction(Zt,"ui",{event:o.nativeEvent,sceneCoords:{x:r.origin.x,y:r.origin.y}});return}this.setState(p=>({selectedElementIds:Be({...p.selectedElementIds,[i.id]:!0},p)})),De(this.interactiveCanvas,et.POINTER)}else{let[i,a]=Yt(r.origin.x,r.origin.y,o[J.CTRL_OR_CMD]?null:this.getEffectiveGridSize()),s=this.getTopLayerFrameAtSceneCoords({x:i,y:a}),{currentItemStartArrowhead:l,currentItemEndArrowhead:c}=this.state,[m,p]=n==="arrow"?[l,c]:[null,null],d=n==="arrow"?vX({type:n,x:i,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.state.currentItemArrowType===ai.round?{type:Pu.PROPORTIONAL_RADIUS}:null,startArrowhead:m,endArrowhead:p,locked:!1,frameId:s?s.id:null,elbowed:this.state.currentItemArrowType===ai.elbow,fixedSegments:this.state.currentItemArrowType===ai.elbow?[]:null}):IX({type:n,x:i,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.state.currentItemRoundness==="round"?{type:Pu.PROPORTIONAL_RADIUS}:null,locked:!1,frameId:s?s.id:null}),u=ce(r.origin.x,r.origin.y),b=this.scene.getNonDeletedElementsMap(),g=Yc(this.state)?rn(u,this.scene.getNonDeletedElements(),b):null;this.scene.mutateElement(d,{points:[ce(0,0),ce(0,0)]}),this.scene.insertElement(d),zn(d)&&E$(d,new Map([[0,{point:ce(0,0),isDragging:!1}]]),u[0],u[1],this.scene,this.state,{newArrow:!0,altKey:o.altKey,initialBinding:!0,angleLocked:S4(o.nativeEvent)}),co(()=>{this.setState(E=>{let y=null,x=E.selectedElementIds;if(eo(d)){y=new ke(d,this.scene.getNonDeletedElementsMap());let w=d.points.length-1;y={...y,selectedPointsIndices:[w],initialState:{...y.initialState,arrowStartIsInside:o.altKey,lastClickedPoint:w,origin:ce(r.origin.x,r.origin.y)}}}return x=this.state.activeTool.locked?E.selectedElementIds:Be({[d.id]:!0},E),{...E,bindMode:"orbit",newElement:d,startBoundElement:g,suggestedBinding:g&&zn(d)?{element:g,midPoint:F1(u,g,b,this.state.zoom)}:null,selectedElementIds:x,selectedLinearElement:y}})}),zn(d)&&cr("COMPLEX_BINDINGS")&&this.handleDelayedBindModeChange(d,g)}});S(this,"createGenericElementOnPointerDown",(o,n)=>{let[r,i]=Yt(n.origin.x,n.origin.y,this.lastPointerDownEvent?.[J.CTRL_OR_CMD]?null:this.getEffectiveGridSize()),a=this.getTopLayerFrameAtSceneCoords({x:r,y:i}),s={x:r,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.getCurrentItemRoundness(o),locked:!1,frameId:a?a.id:null},l;o==="embeddable"?l=G4({type:"embeddable",...s}):l=TX({type:o,...s}),l.type==="selection"?this.setState({selectionElement:l}):(this.scene.insertElement(l),this.setState({multiElement:null,newElement:l}))});S(this,"createFrameElementOnPointerDown",(o,n)=>{let[r,i]=Yt(o.origin.x,o.origin.y,this.lastPointerDownEvent?.[J.CTRL_OR_CMD]?null:this.getEffectiveGridSize()),a={x:r,y:i,opacity:this.state.currentItemOpacity,locked:!1,...Ho},s=n===Nn.magicframe?U4(a):H4(a);this.scene.insertElement(s),this.setState({multiElement:null,newElement:s})});S(this,"restoreReadyToEraseElements",()=>{this.elementsPendingErasure=new Set,this.triggerRender()});S(this,"eraseElements",()=>{let o=!1;this.elementsPendingErasure.forEach(r=>{let i=this.scene.getElement(r);if(zn(i)){if(i.startBinding){let a=this.scene.getElement(i.startBinding.elementId);zu(a,this.scene.getElementsMapIncludingDeleted(),{boundElements:a.boundElements.filter(s=>s.id!==i.id)})}if(i.endBinding){let a=this.scene.getElement(i.endBinding.elementId);zu(a,this.scene.getElementsMapIncludingDeleted(),{boundElements:a.boundElements.filter(s=>s.id!==i.id)})}}else I1(i)&&i.boundElements?.forEach(a=>{if(a.type==="arrow"){let s=this.scene.getElement(a.id);s?.startBinding?.elementId===i.id&&zu(s,this.scene.getElementsMapIncludingDeleted(),{startBinding:null}),s?.endBinding?.elementId===i.id&&zu(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)||w1(r)&&this.elementsPendingErasure.has(r.containerId)?(o=!0,si(r,{isDeleted:!0})):r);this.elementsPendingErasure=new Set,o&&(this.store.scheduleCapture(),this.scene.replaceAllElements(n))});S(this,"initializeImage",async(o,n)=>{if(!eg(n))throw new Error(h("errors.unsupportedFileType"));let r=n.type;if(De(this.interactiveCanvas,"wait"),r===Rn.svg)try{n=rg(q4(await n.text()),n.name)}catch(l){throw console.warn(l),new Error(h("errors.svgImageInsertError"))}let i=await(this.props.generateIdForFile?.(n)||Ox(n));if(!i)throw console.warn("Couldn't generate file id or the supplied `generateIdForFile` didn't resolve to one."),new Error(h("errors.imageInsertError"));if(!this.files[i]?.dataURL){try{n=await ud(n,{maxWidthOrHeight:BK})}catch(l){console.error("Error trying to resizing image file on insertion",l)}if(n.size>L4)throw new Error(h("errors.fileTooBig",{maxSize:`${Math.trunc(L4/1024/1024)}MB`}))}let s=this.files[i]?.dataURL||await ng(n);return new Promise(async(l,c)=>{try{let m=this.getLatestInitializedImageElement(o,i);if(this.addMissingFiles([{mimeType:r,id:i,dataURL:s,created:Date.now(),lastRetrieved:Date.now()}]),!this.imageCache.get(i)){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(i)?.image;if(p&&this.state.newElement?.id!==m.id){m=this.getLatestInitializedImageElement(o,i);let d=this.getImageNaturalDimensions(m,p);Object.assign(m,d)}l(m)}catch(m){console.error(m),c(new Error(h("errors.imageInsertError")))}})});S(this,"getLatestInitializedImageElement",(o,n)=>{let r=this.scene.getElement(o.id)??o;return si(r,{fileId:n})});S(this,"onImageToolbarButtonClick",async()=>{try{let o=this.state.width/2+this.state.offsetLeft,n=this.state.height/2+this.state.offsetTop,{x:r,y:i}=je({clientX:o,clientY:n},this.state),a=await ad({description:"Image",extensions:Object.keys(zK),multiple:!0});this.insertImages(a,r,i)}catch(o){o.name!=="AbortError"?console.error(o):console.warn(o),this.setState({newElement:null,activeTool:Bn(this.state,{type:this.state.preferredSelectionTool.type})},()=>{this.actionManager.executeAction(Zt)})}});S(this,"getImageNaturalDimensions",(o,n)=>{let r=Math.max(this.state.height-120,160),i=Math.min(r,Math.floor(this.state.height*.5)/this.state.zoom.value),a=Math.min(n.naturalHeight,i),s=a*(n.naturalWidth/n.naturalHeight),l=o.x+o.width/2-s/2,c=o.y+o.height/2-a/2;return{x:l,y:c,width:s,height:a,crop:null}});S(this,"updateImageCache",async(o,n=this.files)=>{let{updatedFiles:r,erroredFiles:i}=await RX({imageCache:this.imageCache,fileIds:o.map(a=>a.fileId),files:n});return i.size&&(this.store.scheduleAction(to.NEVER),this.scene.replaceAllElements(this.scene.getElementsIncludingDeleted().map(a=>Vc(a)&&i.has(a.fileId)?si(a,{status:"error"}):a))),{updatedFiles:r,erroredFiles:i}});S(this,"addNewImagesToImageCache",async(o=DX(this.scene.getNonDeletedElements()),n=this.files)=>{let r=o.filter(i=>!i.isDeleted&&!this.imageCache.has(i.fileId));if(r.length){let{updatedFiles:i}=await this.updateImageCache(r,n);if(i.size)for(let a of r)i.has(a.fileId)&&Xc.delete(a);i.size&&this.scene.triggerUpdate()}});S(this,"scheduleImageRefresh",_K(()=>{this.addNewImagesToImageCache()},OK));S(this,"updateBindingEnabledOnPointerMove",o=>{let n=EX(o);this.state.isBindingEnabled!==n&&this.setState({isBindingEnabled:n})});S(this,"handleInteractiveCanvasRef",o=>{o!==null?(this.interactiveCanvas=o,this.interactiveCanvas.addEventListener(ue.TOUCH_START,this.onTouchStart,{passive:!1}),this.interactiveCanvas.addEventListener(ue.TOUCH_END,this.onTouchEnd)):(this.interactiveCanvas?.removeEventListener(ue.TOUCH_START,this.onTouchStart),this.interactiveCanvas?.removeEventListener(ue.TOUCH_END,this.onTouchEnd))});S(this,"insertImages",async(o,n,r)=>{let i=50/this.state.zoom.value,a=uM(o.map(()=>this.newImagePlaceholder({sceneX:n,sceneY:r})),n,r,i);a.forEach(d=>this.scene.insertElement(d));let s=await Promise.all(a.map(async(d,u)=>{try{return await this.initializeImage(d,await gl(o[u]))}catch(b){return this.setState({errorMessage:b.message||h("errors.imageInsertError")}),si(d,{isDeleted:!0})}})),l=Du(s),c=uM(s.filter(d=>!d.isDeleted),n,r,i),m=Du(c),p=this.scene.getElementsIncludingDeleted().map(d=>m.get(d.id)??l.get(d.id)??d);this.updateScene({appState:{selectedElementIds:Be(Object.fromEntries(c.map(d=>[d.id,!0])),this.state)},elements:p,captureUpdate:to.IMMEDIATELY}),this.setState({},()=>{this.actionManager.executeAction(Zt)})});S(this,"handleAppOnDrop",async o=>{let{x:n,y:r}=je(o,this.state),i=await $a(o),a=i.getFiles();if(a.length===1){let{file:p,fileHandle:d}=a[0];if(p&&(p.type===Rn.png||p.type===Rn.svg))try{let u=await pd(p,this.state,this.scene.getElementsIncludingDeleted(),d);this.syncActionResult({...u,appState:{...u.appState||this.state,isLoading:!1},replaceFiles:!0,captureUpdate:to.IMMEDIATELY});return}catch(u){if(u.name!=="EncodingError")throw new Error(h("alerts.couldNotLoadInvalidFile"))}}let s=a.map(p=>p.file).filter(p=>eg(p));if(s.length>0&&this.isToolSupported("image"))return this.insertImages(s,n,r);let l=i.getData(Rn.excalidrawlibIds),c=i.getData(Rn.excalidrawlib);if(l||c){try{let p=null;if(l){let{itemIds:d}=JSON.parse(l);p=(await this.library.getLatestLibrary()).filter(b=>d.includes(b.id))}else c&&(p=zx(c));p?.length&&(p=p.map(d=>({...d,elements:y1({type:"everything",elements:d.elements,randomizeSeed:!0}).duplicatedElements})),this.addElementsFromPasteOrLibrary({elements:us(p),position:o,files:null}))}catch(p){this.setState({errorMessage:p.message})}return}if(a.length>0){let{file:p,fileHandle:d}=a[0];p&&await this.loadFileToCanvas(p,d)}let m=i.findByType(Rn.text);if(m){let p=m.value;if(p&&k1(p,this.props.validateEmbeddable)&&(/^(http|https):\/\/[^\s/$.?#].[^\s]*$/.test(p)||Fu(p)?.type==="video")){let d=this.insertEmbeddableElement({sceneX:n,sceneY:r,link:g1(p)});d&&(this.store.scheduleCapture(),this.setState({selectedElementIds:{[d.id]:!0}}))}}});S(this,"loadFileToCanvas",async(o,n)=>{o=await gl(o);try{let r=this.scene.getElementsIncludingDeleted(),i;try{i=await tg(o,this.state,r,n)}catch(a){let s=a instanceof Sx;if(s&&a.code==="IMAGE_NOT_CONTAINS_SCENE_DATA"&&!this.isToolSupported("image")){this.setState({isLoading:!1,errorMessage:h("errors.imageToolNotSupported")});return}let l=s?h("alerts.cannotRestoreFromImage"):h("alerts.couldNotLoadInvalidFile");this.setState({isLoading:!1,errorMessage:l})}if(!i)return;i.type===Rn.excalidraw?(TM(r.concat(i.data.elements)),this.store.scheduleMicroAction({action:to.NEVER,elements:r,appState:void 0}),this.setState({isLoading:!0}),this.syncActionResult({...i.data,appState:{...i.data.appState||this.state,isLoading:!1},replaceFiles:!0,captureUpdate:to.IMMEDIATELY})):i.type===Rn.excalidrawlib&&await this.library.updateLibrary({libraryItems:o,merge:!0,openLibraryMenu:!0}).catch(a=>{console.error(a),this.setState({errorMessage:h("errors.importLibraryError")})})}catch(r){this.setState({isLoading:!1,errorMessage:r.message})}});S(this,"handleCanvasContextMenu",o=>{if(o.preventDefault(),("pointerType"in o.nativeEvent&&o.nativeEvent.pointerType==="touch"||"pointerType"in o.nativeEvent&&o.nativeEvent.pointerType==="pen"&&o.button!==ii.SECONDARY)&&this.state.activeTool.type!==this.state.preferredSelectionTool.type)return;let{x:n,y:r}=je(o,this.state),i=this.getElementAtPosition(n,r,{preferSelected:!0,includeLockedElements:!0}),a=this.scene.getSelectedElements(this.state),s=this.isHittingCommonBoundingBoxOfSelectedElements({x:n,y:r},a),l=i||s?"element":"canvas",c=this.excalidrawContainerRef.current,{top:m,left:p}=c.getBoundingClientRect(),d=o.clientX-p,u=o.clientY-m;he("contextMenu","openContextMenu",l),this.setState({...i&&!this.state.selectedElementIds[i.id]?{...this.state,...Go({editingGroupId:this.state.editingGroupId,selectedElementIds:{[i.id]:!0}},this.scene.getNonDeletedElements(),this.state,this),selectedLinearElement:eo(i)?new ke(i,this.scene.getNonDeletedElementsMap()):null}:this.state,showHyperlinkPopup:!1},()=>{this.setState({contextMenu:{top:u,left:d,items:this.getContextMenuItems(l)}})})});S(this,"maybeDragNewGenericElement",(o,n,r=!0)=>{let i=this.state.selectionElement,a=o.lastCoords;if(i&&o.boxSelection.hasOccurred&&this.state.activeTool.type!=="eraser"){cM({newElement:i,elementType:this.state.activeTool.type,originX:o.origin.x,originY:o.origin.y,x:a.x,y:a.y,width:qs(o.origin.x,a.x),height:qs(o.origin.y,a.y),shouldMaintainAspectRatio:Gc(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]=Yt(a.x,a.y,n[J.CTRL_OR_CMD]?null:this.getEffectiveGridSize()),m=Vc(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}=F3(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}),zn(s)||cM({newElement:s,elementType:this.state.activeTool.type,originX:o.originInGrid.x,originY:o.originInGrid.y,x:l,y:c,width:qs(o.originInGrid.x,l),height:qs(o.originInGrid.y,c),shouldMaintainAspectRatio:li(s)?!Gc(n):Gc(n),shouldResizeFromCenter:k4(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===Nn.frame||this.state.activeTool.type===Nn.magicframe)&&this.setState({elementsToHighlight:L1(this.scene.getNonDeletedElements(),s,this.state,this.scene.getNonDeletedElementsMap())})});S(this,"maybeHandleCrop",(o,n)=>{if(!this.state.croppingElementId)return!1;let r=o.resize.handleType,i=o.lastCoords,[a,s]=Yt(i.x-o.resize.offset.x,i.y-o.resize.offset.y,n[J.CTRL_OR_CMD]?null:this.getEffectiveGridSize()),l=this.scene.getNonDeletedElementsMap().get(this.state.croppingElementId);if(r&&l&&li(l)){let c=o.originalElements.get(l.id),m=Vc(l)&&this.imageCache.get(l.fileId)?.image;if(c&&li(c)&&m&&!(m instanceof Promise)){let[p,d]=Yt(i.x,i.y,n[J.CTRL_OR_CMD]?null:this.getEffectiveGridSize()),u={x:p-o.originInGrid.x,y:d-o.originInGrid.y};this.maybeCacheReferenceSnapPoints(n,[l]);let{snapOffset:b,snapLines:g}=I0([l],[c],this,n,u,r);this.scene.mutateElement(l,jX(l,this.scene.getNonDeletedElementsMap(),r,m.naturalWidth,m.naturalHeight,a+b.x,s+b.y,n.shiftKey?c.width/c.height:void 0)),Bu(l,this.scene),this.setState({isCropping:r&&r!=="rotation",snapLines:g})}return!0}return!1});S(this,"maybeHandleResize",(o,n)=>{let r=this.scene.getSelectedElements(this.state),i=r.filter(p=>Vt(p)),a=o.resize.handleType;if(i.length>0&&a==="rotation"||r.length===1&&mo(r[0])||this.state.croppingElementId)return!1;this.setState({isResizing:a&&a!=="rotation",isRotating:a==="rotation",activeEmbeddable:null});let s=o.lastCoords,[l,c]=Yt(s.x-o.resize.offset.x,s.y-o.resize.offset.y,n[J.CTRL_OR_CMD]?null:this.getEffectiveGridSize()),m=new Map;if(i.forEach(p=>{P1(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]=Yt(s.x,s.y,n[J.CTRL_OR_CMD]?null:this.getEffectiveGridSize()),u={x:p-o.originInGrid.x,y:d-o.originInGrid.y},b=[...o.originalElements.values()];this.maybeCacheReferenceSnapPoints(n,r);let{snapOffset:g,snapLines:E}=I0(r,se(b,this.state),this,n,u,a);l+=g.x,c+=g.y,this.setState({snapLines:E})}if(g$(o.originalElements,a,r,this.scene,S4(n),k4(n),r.some(p=>li(p))?!Gc(n):Gc(n),l,c,o.resize.center.x,o.resize.center.y)){let p=new Set;return i.forEach(d=>{L1(this.scene.getNonDeletedElements(),d,this.state,this.scene.getNonDeletedElementsMap()).forEach(u=>p.add(u))}),this.setState({elementsToHighlight:[...p]}),!0}return!1});S(this,"getContextMenuItems",o=>{let n=[];if(n.push(Tm,vm),o==="canvas")return this.state.viewModeEnabled?[...n,ns,Dr,Ri,Rr]:[Wh,ut,Tm,vm,Im,ut,Fg,B2,ut,ns,Kl,Dr,Ri,Rr];if(n.push(Im),this.state.viewModeEnabled)return[os,...n];let r=this.editorInterface.formFactor==="desktop"?[ut,Dg,Rg,Ng,Bg]:[];return[ut,wm,os,Wh,ut,g3,h3,f3,ut,g0,ut,...n,ut,Dh,Rh,ut,Bh,I3,Kh,Xh,w2,Fh,ut,Hh,...r,ut,Gh,Uh,ut,Cs,ut,Zl,_m,ut,zg,jl,ut,Il]});S(this,"handleWheel",it(o=>{if(!(o.target instanceof HTMLCanvasElement||o.target instanceof HTMLTextAreaElement||o.target instanceof HTMLIFrameElement||o.target instanceof HTMLElement&&o.target.classList.contains(x1.FRAME_NAME))){o[J.CTRL_OR_CMD]&&o.preventDefault();return}if(o.preventDefault(),jc)return;let{deltaX:n,deltaY:r}=o;if(o.metaKey||o.ctrlKey){let i=Math.sign(r),a=KK*100,s=Math.abs(r),l=r;s>a&&(l=a*i);let c=this.state.zoom.value-l/100;c+=Math.log10(Math.max(1,this.state.zoom.value))*-i*Math.min(1,s/20),this.translateCanvas(m=>({...Xn({viewportX:this.lastViewportPosition.x,viewportY:this.lastViewportPosition.y,nextZoom:ln(c)},m),shouldCacheIgnoreZoom:!0})),this.resetShouldCacheIgnoreZoomDebounced();return}if(o.shiftKey){this.translateCanvas(({zoom:i,scrollX:a})=>({scrollX:a-(r||n)/i.value}));return}this.translateCanvas(({zoom:i,scrollX:a,scrollY:s})=>({scrollX:a-n/i.value,scrollY:s-r/i.value}))}));S(this,"savePointer",(o,n,r)=>{if(!o||!n)return;let{x:i,y:a}=je({clientX:o,clientY:n},this.state);isNaN(i)||isNaN(a);let s={x:i,y:a,tool:this.state.activeTool.type==="laser"?"laser":"pointer"};this.props.onPointerUpdate?.({pointer:s,button:r,pointersMap:Le.pointers})});S(this,"resetShouldCacheIgnoreZoomDebounced",R4(()=>{this.unmounted||this.setState({shouldCacheIgnoreZoom:!1})},300));S(this,"updateDOMRect",o=>{if(this.excalidrawContainerRef?.current){let n=this.excalidrawContainerRef.current,{width:r,height:i,left:a,top:s}=n.getBoundingClientRect(),{width:l,height:c,offsetTop:m,offsetLeft:p}=this.state;if(r===l&&i===c&&a===p&&s===m){o&&o();return}this.setState({width:r,height:i,offsetLeft:a,offsetTop:s},()=>{o&&o()})}});S(this,"refresh",()=>{this.setState({...this.getCanvasOffsets()})});S(this,"watchState",()=>{});let n=fr(),{excalidrawAPI:r,viewModeEnabled:i=!1,zenModeEnabled:a=!1,gridModeEnabled:s=!1,objectsSnapModeEnabled:l=!1,theme:c=n.theme,name:m=`${h("labels.untitled")}-${B4()}`}=o;if(this.state={...n,theme:c,isLoading:!0,...this.getCanvasOffsets(),viewModeEnabled:i,zenModeEnabled:a,objectsSnapModeEnabled:l,gridModeEnabled:s??n.gridModeEnabled,name:m,width:window.innerWidth,height:window.innerHeight},this.refreshEditorInterface(),this.stylesPanelMode=Hu(this.editorInterface),this.id=d1(),this.library=new lT(this),this.actionManager=new hp(this.syncActionResult,()=>this.state,()=>this.scene.getElementsIncludingDeleted(),this),this.scene=new mM,this.canvas=document.createElement("canvas"),this.rc=DK.canvas(this.canvas),this.renderer=new bc(this.scene),this.visibleElements=[],this.store=new b$(this),this.history=new gc(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 hr(this.scene),this.history=new gc(this.store),this.actionManager.registerAll(Ad),this.actionManager.registerAction(y3(this.history)),this.actionManager.registerAction(w3(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,i=document.body.querySelectorAll("iframe.excalidraw__embeddable");if(!i)break;for(let a of i)a.contentWindow===o.source&&(r=a.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,i=n.info.playerState;Object.values(Lu).includes(i)&&H1.set(r,i)}break}}handleSkipBindMode(){if(this.state.selectedLinearElement?.initialState&&!this.state.selectedLinearElement.initialState.arrowStartIsInside){Fn(this.lastPointerMoveCoords,"Missing last pointer move coords when changing bind skip mode for arrow start");let o=this.scene.getNonDeletedElementsMap(),n=rn(ce(this.lastPointerMoveCoords.x,this.lastPointerMoveCoords.y),this.scene.getNonDeletedElements(),o),r=ke.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),co(()=>{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;Fn(r,"Last event must exist");let i=o-this.state.selectedLinearElement.pointerOffset.x,a=n-this.state.selectedLinearElement.pointerOffset.y,s=this.state.multiElement?ke.handlePointerMove(r,this,i,a,this.state.selectedLinearElement):ke.handlePointDragging(r,this,i,a,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||mo(o))return;let r=()=>{if(this.bindModeHandler=null,Fn(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 b=this.state.selectedLinearElement.selectedPointsIndices.includes(0),g=this.state.selectedLinearElement.selectedPointsIndices.includes(o.points.length-1);if(!b&&!g||b&&g)return}let{x:p,y:d}=this.lastPointerMoveCoords,u=rn(ce(p,d),this.scene.getNonDeletedElements(),this.scene.getNonDeletedElementsMap());if(u&&this.state.bindMode!=="skip"){Fn(this.state.selectedLinearElement?.elementId===o.id,"The selectedLinearElement is expected to not change while a bind mode timeout is ticking");let b=this.state.selectedLinearElement.initialState.arrowStartIsInside||o.startBinding?.elementId===u.id;co(()=>{Fn(this.state.selectedLinearElement,"this.state.selectedLinearElement must exist"),this.setState({bindMode:"inside",selectedLinearElement:{...this.state.selectedLinearElement,initialState:{...this.state.selectedLinearElement.initialState,arrowStartIsInside:b}}})});let g=this.lastPointerMoveEvent??this.lastPointerDownEvent?.nativeEvent;Fn(g,"Last event must exist");let E=p-this.state.selectedLinearElement.pointerOffset.x,y=d-this.state.selectedLinearElement.pointerOffset.y,x=this.state.multiElement?ke.handlePointerMove(g,this,E,y,this.state.selectedLinearElement):ke.handlePointDragging(g,this,E,y,this.state.selectedLinearElement);x&&this.setState(x)}},i=!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),b=d?n:o.startBinding&&p.get(o.startBinding.elementId),g=u?n:o.endBinding&&p.get(o.endBinding.elementId),E=b&&hM(b,p),y=g&&hM(g,p);i=!!(E&&y&&b.id!==g.id&&y$(E,y))}let a=this.state.selectedLinearElement?.selectedPointsIndices?.includes(0),s=this.state.selectedLinearElement?.selectedPointsIndices?.includes(o.points.length-1),l=a?"startBinding":s?"endBinding":null,c=a?"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"&&co(()=>{this.setState({bindMode:"orbit"})}),this.previousHoveredBindableElement=null):!this.bindModeHandler&&(!this.state.newElement||!o.startBinding||i)&&!m&&(this.bindModeHandler=setTimeout(r,dX)),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!==ii.MAIN||ci||!z4(this.state.activeTool.type,["laser","selection","lasso"]))return!1;let o=ce(je({clientX:this.lastPointerDownEvent.clientX,clientY:this.lastPointerDownEvent.clientY},this.state)),n=ce(je({clientX:this.lastPointerUpEvent.clientX,clientY:this.lastPointerUpEvent.clientY},this.state));if(ri(o,n)>P4)return!1;let i=this.getElementAtPosition(o[0],o[1]);if(!(i&&this.lastPointerUpEvent.timeStamp-this.lastPointerDownEvent.timeStamp<=300&&Le.pointers.size<2&&v1(i)&&(this.state.viewModeEnabled||this.state.activeTool.type==="laser"||this.isIframeLikeElementCenter(i,this.lastPointerUpEvent,n[0],n[1]))))return!1;let s=i;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),el(s)))return!0;let l=this.getHTMLIFrameElement(s);if(!l?.contentWindow)return!0;if(l.src.includes("youtube")){let c=H1.get(s.id);switch(c||(H1.set(s.id,Lu.UNSTARTED),l.contentWindow.postMessage(JSON.stringify({event:"listening",id:s.id}),"*")),c){case Lu.PLAYING:case Lu.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,i){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&&i>=o.y+o.height/3&&i<=o.y+2*o.height/3}renderEmbeddables(){let o=this.state.zoom.value,n=this.state.width,r=this.state.height,i=this.scene.getNonDeletedElements().filter(a=>dr(a)&&this.embedsValidationStatus.get(a.id)===!0||el(a));return Me(EM,{children:i.map(a=>{let{x:s,y:l}=_u({sceneX:a.x,sceneY:a.y},this.state),c=X4(a,n,r,this.state,this.scene.getNonDeletedElementsMap()),m=this.initializedEmbeds.has(a.id);if(c&&!m&&this.initializedEmbeds.add(a.id),!(c||m))return null;let d;if(el(a)){d=null;let g=(a.customData?.generationData??this.magicGenerations.get(a.id))||{status:"error",message:"No generation data",code:"ERR_NO_GENERATION_DATA"};if(g.status==="done"){let E=g.html;d={intrinsicSize:{w:a.width,h:a.height},type:"document",srcdoc:()=>E}}else if(g.status==="pending")d={intrinsicSize:{w:a.width,h:a.height},type:"document",srcdoc:()=>j4(`
|
|
33
33
|
<style>
|
|
34
34
|
html, body {
|
|
35
35
|
width: 100%;
|
|
36
36
|
height: 100%;
|
|
37
|
-
color: ${this.state.theme===
|
|
37
|
+
color: ${this.state.theme===Au.DARK?"white":"black"};
|
|
38
38
|
}
|
|
39
39
|
body {
|
|
40
40
|
display: flex;
|
|
@@ -101,7 +101,7 @@ Please fix the Mermaid syntax and regenerate a valid diagram.`;await w({prompt:J
|
|
|
101
101
|
</svg>
|
|
102
102
|
</div>
|
|
103
103
|
<div>Generating...</div>
|
|
104
|
-
`)};else{let E;g.code==="ERR_GENERATION_INTERRUPTED"?E="Generation was interrupted...":E=g.message||"Generation failed",d={intrinsicSize:{w:a.width,h:a.height},type:"document",srcdoc:()=>
|
|
104
|
+
`)};else{let E;g.code==="ERR_GENERATION_INTERRUPTED"?E="Generation was interrupted...":E=g.message||"Generation failed",d={intrinsicSize:{w:a.width,h:a.height},type:"document",srcdoc:()=>j4(`
|
|
105
105
|
<style>
|
|
106
106
|
html, body {
|
|
107
107
|
height: 100%;
|
|
@@ -111,7 +111,7 @@ Please fix the Mermaid syntax and regenerate a valid diagram.`;await w({prompt:J
|
|
|
111
111
|
flex-direction: column;
|
|
112
112
|
align-items: center;
|
|
113
113
|
justify-content: center;
|
|
114
|
-
color: ${
|
|
114
|
+
color: ${RK.red[3]};
|
|
115
115
|
}
|
|
116
116
|
h1, h3 {
|
|
117
117
|
margin-top: 0;
|
|
@@ -120,8 +120,63 @@ Please fix the Mermaid syntax and regenerate a valid diagram.`;await w({prompt:J
|
|
|
120
120
|
</style>
|
|
121
121
|
<h1>Error!</h1>
|
|
122
122
|
<h3>${E}</h3>
|
|
123
|
-
`)}}}else d=Qp(nV(a.link||""));let u=this.state.activeEmbeddable?.element===a&&this.state.activeEmbeddable?.state==="active",b=this.state.activeEmbeddable?.element===a&&this.state.activeEmbeddable?.state==="hover";return Te("div",{className:x4("excalidraw__embeddable-container",{"is-hovered":b}),style:{transform:c?`translate(${s-this.state.offsetLeft}px, ${l-this.state.offsetTop}px) scale(${t})`:"none",display:c?"block":"none",opacity:mK(a,$0(a,this.scene.getNonDeletedElementsMap()),this.elementsPendingErasure,null,this.state.openDialog?.name==="elementLinkSelector"?tV:1),"--embeddable-radius":`${FV(Math.min(a.width,a.height),a)}px`},children:hc("div",{className:"excalidraw__embeddable-container__inner",style:{width:c?`${a.width}px`:0,height:c?`${a.height}px`:0,transform:c?`rotate(${a.angle}rad)`:"none",pointerEvents:u?hs.enabled:hs.disabled},children:[b&&Te("div",{className:"excalidraw__embeddable-hint",children:h("buttons.embeddableInteractionButton")}),Te("div",{className:"excalidraw__embeddable__outer",style:{padding:`${a.strokeWidth}px`},children:(Wn(a)?this.props.renderEmbeddable?.(a,this.state):null)??Te("iframe",{ref:g=>this.cacheEmbeddableRef(a,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`})})]})},a.id)})})}toggleOverscrollBehavior(t){document.documentElement.style.overscrollBehaviorX=t.type==="pointerenter"?"none":"auto"}render(){let t=this.scene.getSelectedElements(this.state),{renderTopRightUI:n,renderTopLeftUI:r,renderCustomStats:i}=this.props,a=this.scene.getSceneNonce(),{elementsMap:s,visibleElements:l}=this.renderer.getRenderableElements({sceneNonce:a,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=t[0],d=ot.get(Do)?.type==="panel";return Te("div",{translate:"no",className:x4("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?hs.disabled:hs.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:Te(Tk.Provider,{value:this,children:Te(Ik.Provider,{value:this.props,children:Te(sb.Provider,{value:this.excalidrawContainerValue,children:Te(ab.Provider,{value:this.editorInterface,children:Te(db.Provider,{value:this.setAppState,children:Te(cb.Provider,{value:this.state,children:hc(lb.Provider,{value:this.scene.getNonDeletedElements(),children:[hc(mb.Provider,{value:this.actionManager,children:[Te(OS,{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:vn().code,renderTopLeftUI:r,renderTopRightUI:n,renderCustomStats:i,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}),Te("div",{className:"excalidraw-textEditorContainer"}),Te("div",{className:"excalidraw-contextMenuContainer"}),Te("div",{className:"excalidraw-eye-dropper-container"}),Te(GS,{trails:[this.laserTrails,this.lassoTrail,this.eraserTrail]}),t.length===1&&this.state.openDialog?.name!=="elementLinkSelector"&&this.state.showHyperlinkPopup&&Te(Cv,{element:p,scene:this.scene,setAppState:this.setAppState,onLinkOpen:this.props.onLinkOpen,setToast:this.setToast,updateEmbedValidationStatus:this.updateEmbedValidationStatus},p.id),this.props.aiEnabled!==!1&&t.length===1&&z0(p)&&Te(Of,{element:p,elementsMap:s,children:Te(Gp,{title:h("labels.convertToCode"),icon:qr,checked:!1,onChange:()=>this.onMagicFrameGenerate(p,"button")})}),t.length===1&&Es(p)&&p.customData?.generationData?.status==="done"&&hc(Of,{element:p,elementsMap:s,children:[Te(Gp,{title:h("labels.copySource"),icon:Zi,checked:!1,onChange:()=>this.onIframeSrcCopy(p)}),Te(Gp,{title:"Enter fullscreen",icon:gE,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(b){console.warn(b),this.setState({errorMessage:"Couldn't enter fullscreen"})}}})]}),t.length===1&&Lt(p)&&p.customData?.type!=="image-generator"&&!this.state.viewModeEnabled&&Te(z3,{element:p,app:this}),t.length===1&&Lt(p)&&p.customData?.type==="image-generator"&&!this.state.viewModeEnabled&&Te($3,{element:p,app:this}),t.length===1&&Or(p)&&!this.state.viewModeEnabled&&Te(j3,{element:p,app:this}),this.state.toast!==null&&Te(f4,{message:this.state.toast.message,onClose:this.handleToastClose,duration:this.state.toast.duration,closable:this.state.toast.closable}),this.state.contextMenu&&Te(DI,{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?.()})}}),Te(C0,{canvas:this.canvas,rc:this.rc,elementsMap:s,allElementsMap:c,visibleElements:l,sceneNonce:a,selectionNonce:this.state.selectionElement?.versionNonce,scale:window.devicePixelRatio,appState:this.state,renderConfig:{imageCache:this.imageCache,isExporting:!1,renderGrid:br(this),canvasBackgroundColor:this.state.viewBackgroundColor,embedsValidationStatus:this.embedsValidationStatus,elementsPendingErasure:this.elementsPendingErasure,pendingFlowchartNodes:this.flowChartCreator.pendingNodes,theme:this.state.theme}}),this.state.newElement&&Te(g4,{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}}),Te(I0,{app:this,containerRef:this.excalidrawContainerRef,canvas:this.interactiveCanvas,elementsMap:s,visibleElements:l,allElementsMap:c,selectedElements:t,sceneNonce:a,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&&Te(RI,{width:this.state.width,height:this.state.height,userToFollow:this.state.userToFollow,onDisconnect:this.maybeUnfollowRemoteUser}),this.renderFrameNames(),this.state.activeLockedId&&Te(b4,{app:this,activeLockedId:this.state.activeLockedId}),d&&Te(Uv,{app:this})]}),this.renderEmbeddables()]})})})})})})})})}setPlugins(t){Object.assign(this.plugins,t)}async onMagicFrameGenerate(t,n){let r=this.plugins.diagramToCode?.generate;if(!r){this.setState({errorMessage:"No diagram to code plugin found"});return}let i=ZV(this.scene.getNonDeletedElements(),t).filter(s=>!z0(s));if(!i.length){n==="button"?(this.setState({errorMessage:"Cannot generate from an empty frame"}),me("ai","generate (no-children)","d2c")):this.setActiveTool({type:"magicframe"});return}let a=this.insertIframeElement({sceneX:t.x+t.width+30,sceneY:t.y,width:t.width,height:t.height});if(a){this.updateMagicGeneration({frameElement:a,data:{status:"pending"}}),this.setState({selectedElementIds:{[a.id]:!0}}),me("ai","generate (start)","d2c");try{let{html:s}=await r({frame:t,children:i});if(me("ai","generate (success)","d2c"),!s.trim()){this.updateMagicGeneration({frameElement:a,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:a,data:{status:"done",html:l}})}catch(s){me("ai","generate (failed)","d2c"),this.updateMagicGeneration({frameElement:a,data:{status:"error",code:"ERR_OAI",message:s.message||"Unknown error during generation"}})}}}onIframeSrcCopy(t){t.customData?.generationData?.status==="done"&&(Lo(t.customData.generationData.html),this.setToast({message:"copied to clipboard",closable:!1,duration:1500}))}clearImageShapeCache(t){let n=t??this.files;this.scene.getNonDeletedElements().forEach(r=>{ac(r)&&n[r.fileId]&&(this.imageCache.delete(r.fileId),lc.delete(r))})}async componentDidMount(){if(this.unmounted=!1,this.excalidrawContainerValue.container=this.excalidrawContainerRef.current,Ek()||yk()){let r=this.setState.bind(this);Object.defineProperties(window.h,{state:{configurable:!0,get:()=>this.state},setState:{configurable:!0,value:(...i)=>this.setState(...i)},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:t}=this.props;t&&this.store.onStoreIncrementEmitter.on(r=>{t(r)}),this.scene.onUpdate(this.triggerRender),this.addEventListeners(),this.props.autoFocus&&this.excalidrawContainerRef.current&&this.focusContainer(),QY&&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),EV()&&!iK()&&this.setState({errorMessage:Te(MI,{})})}componentWillUnmount(){window.launchQueue?.setConsumer(()=>{}),this.renderer.destroy(),this.scene.destroy(),this.scene=new dk,this.fonts=new Yn(this.scene),this.renderer=new _l(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(),lc.destroy(),go.destroy(),clearTimeout(Hr),Le.clearCache(),Io.clearCache(),Hr=0,document.documentElement.style.overscrollBehaviorX=""}removeEventListeners(){this.onRemoveEventListenersEmitter.trigger()}addEventListeners(){this.removeEventListeners(),this.props.handleKeyboardGlobally&&this.onRemoveEventListenersEmitter.once(Je(document,ce.KEYDOWN,this.onKeyDown,!1)),this.onRemoveEventListenersEmitter.once(Je(this.excalidrawContainerRef.current,ce.WHEEL,this.handleWheel,{passive:!1}),Je(window,ce.MESSAGE,this.onWindowMessage,!1),Je(document,ce.POINTER_UP,this.removePointer,{passive:!1}),Je(document,ce.COPY,this.onCopy,{passive:!1}),Je(document,ce.KEYUP,this.onKeyUp,{passive:!0}),Je(document,ce.POINTER_MOVE,this.updateCurrentCursorPosition,{passive:!1}),Je(document.fonts,"loadingdone",t=>{let n=t.fontfaces;this.fonts.onLoaded(n)},{passive:!1}),Je(document,ce.GESTURE_START,this.onGestureStart,!1),Je(document,ce.GESTURE_CHANGE,this.onGestureChange,!1),Je(document,ce.GESTURE_END,this.onGestureEnd,!1),Je(window,ce.FOCUS,()=>{this.maybeCleanupAfterMissingPointerUp(null),this.triggerRender(!0)},{passive:!1})),!this.state.viewModeEnabled&&(this.onRemoveEventListenersEmitter.once(Je(document,ce.FULLSCREENCHANGE,this.onFullscreenChange,{passive:!1}),Je(document,ce.PASTE,this.pasteFromClipboard,{passive:!1}),Je(document,ce.CUT,this.onCut,{passive:!1}),Je(window,ce.RESIZE,this.onResize,!1),Je(window,ce.UNLOAD,this.onUnload,!1),Je(window,ce.BLUR,this.onBlur,!1),Je(this.excalidrawContainerRef.current,ce.WHEEL,this.handleWheel,{passive:!1}),Je(this.excalidrawContainerRef.current,ce.DRAG_OVER,this.disableEvent,!1),Je(this.excalidrawContainerRef.current,ce.DROP,this.disableEvent,!1)),this.props.detectScroll&&this.onRemoveEventListenersEmitter.once(Je(rV(this.excalidrawContainerRef.current),ce.SCROLL,this.onScroll,{passive:!1})))}componentDidUpdate(t,n){this.updateEmbeddables();let r=this.scene.getElementsIncludingDeleted(),i=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&&Gt(this.state)&&this.setState({activeTool:fn(this.state,{type:"selection"})}),this.state.activeTool.type==="eraser"&&n.theme!==this.state.theme&&_g(this.interactiveCanvas,this.state.theme),n.activeTool.type==="selection"&&this.state.activeTool.type!=="selection"&&this.state.showHyperlinkPopup&&this.setState({showHyperlinkPopup:!1}),t.langCode!==this.props.langCode&&this.updateLanguage(),Gt(n)&&!Gt(this.state)&&this.eraserTrail.endPath(),t.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:{}})),t.zenModeEnabled!==this.props.zenModeEnabled&&this.setState({zenModeEnabled:!!this.props.zenModeEnabled}),t.theme!==this.props.theme&&this.props.theme&&this.setState({theme:this.props.theme}),this.excalidrawContainerRef.current?.classList.toggle("theme--dark",this.state.theme===Kp.DARK),this.state.selectedLinearElement?.isEditing&&!this.state.selectedElementIds[this.state.selectedLinearElement.elementId]&&setTimeout(()=>{this.state.selectedLinearElement?.isEditing&&this.actionManager.executeAction(Rt)}),this.state.editingTextElement?.isDeleted&&this.setState({editingTextElement:null}),this.store.commit(i,this.state),this.state.isLoading||(this.props.onChange?.(r,this.state,this.files),this.onChangeEmitter.trigger(r,this.state,this.files))}static resetTapTwice(){cc=!1,dc=null}async insertClipboardContent(t,n,r){let{x:i,y:a}=Ue({clientX:this.lastViewportPosition.x,clientY:this.lastViewportPosition.y},this.state);if(t.errorMessage){this.setState({errorMessage:t.errorMessage});return}if(n.length===0&&!r&&t.mixedContent){await this.addElementsFromMixedContentPaste(t.mixedContent,{isPlainPaste:r,sceneX:i,sceneY:a});return}if(t.spreadsheet&&!r){this.setState({pasteDialog:{data:t.spreadsheet,shown:!0}});return}let s=n.map(m=>m.file);if(s.length===0&&t.text&&!r){let m=t.text.trim();m.startsWith("<svg")&&m.endsWith("</svg>")&&s.push(bu(m))}if(s.length>0){this.isToolSupported("image")?await this.insertImages(s,i,a):this.setState({errorMessage:h("errors.imageToolNotSupported")});return}if(t.elements){let m=t.programmaticAPI?hk(t.elements):t.elements;this.addElementsFromPasteOrLibrary({elements:m,files:t.files||null,position:this.editorInterface.formFactor==="desktop"?"cursor":"center",retainSeed:r});return}if(!t.text)return;if(!r&&pI(t.text)){let m=await import("@excalidraw/mermaid-to-excalidraw");try{let{elements:p,files:d}=await m.parseMermaidToExcalidraw(t.text),u=hk(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=mV(t.text).split(/\n+/).map(m=>m.trim()).filter(Boolean),c=l.map(m=>OV(m)).filter(m=>U0(m,this.props.validateEmbeddable)&&(/^(http|https):\/\/[^\s/$.?#].[^\s]*$/.test(m)||Qp(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:i,sceneY:a,link:L0(p)});u&&m.push(u)}m.length&&(this.store.scheduleCapture(),this.setState({selectedElementIds:Object.fromEntries(m.map(p=>[p.id,!0]))}));return}this.addTextFromPaste(t.text,r)}async addElementsFromMixedContentPaste(t,{isPlainPaste:n,sceneX:r,sceneY:i}){if(!n&&t.some(a=>a.type==="imageUrl")&&this.isToolSupported("image")){let a=t.filter(m=>m.type==="imageUrl").map(m=>m.value),s=await Promise.all(a.map(async m=>{try{return{file:await Yb(m)}}catch(p){let d=p.message;return p.cause==="FETCH_ERROR"?d=h("errors.failedToFetchImage"):p.cause==="UNSUPPORTED"&&(d=h("errors.unsupportedFileType")),{errorMessage:d}}})),l=s.filter(m=>!!m.file).map(m=>m.file);await this.insertImages(l,r,i);let c=s.find(m=>!!m.errorMessage);c&&c.errorMessage&&this.setState({errorMessage:c.errorMessage})}else{let a=t.filter(s=>s.type==="text");a.length&&this.addTextFromPaste(a.map(s=>s.value).join(`
|
|
123
|
+
`)}}}else d=Fu(qK(a.link||""));let u=this.state.activeEmbeddable?.element===a&&this.state.activeEmbeddable?.state==="active",b=this.state.activeEmbeddable?.element===a&&this.state.activeEmbeddable?.state==="hover";return Me("div",{className:E4("excalidraw__embeddable-container",{"is-hovered":b}),style:{transform:c?`translate(${s-this.state.offsetLeft}px, ${l-this.state.offsetTop}px) scale(${o})`:"none",display:c?"block":"none",opacity:i$(a,_1(a,this.scene.getNonDeletedElementsMap()),this.elementsPendingErasure,null,this.state.openDialog?.name==="elementLinkSelector"?ZK:1),"--embeddable-radius":`${LX(Math.min(a.width,a.height),a)}px`},children:ed("div",{className:"excalidraw__embeddable-container__inner",style:{width:c?`${a.width}px`:0,height:c?`${a.height}px`:0,transform:c?`rotate(${a.angle}rad)`:"none",pointerEvents:u?js.enabled:js.disabled},children:[b&&Me("div",{className:"excalidraw__embeddable-hint",children:h("buttons.embeddableInteractionButton")}),Me("div",{className:"excalidraw__embeddable__outer",style:{padding:`${a.strokeWidth}px`},children:(dr(a)?this.props.renderEmbeddable?.(a,this.state):null)??Me("iframe",{ref:g=>this.cacheEmbeddableRef(a,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`})})]})},a.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:i}=this.props,a=this.scene.getSceneNonce(),{elementsMap:s,visibleElements:l}=this.renderer.getRenderableElements({sceneNonce:a,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=pt.get(jo)?.type==="panel";return Me("div",{translate:"no",className:E4("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?js.disabled:js.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:Me(IM.Provider,{value:this,children:Me(CM.Provider,{value:this.props,children:Me(V1.Provider,{value:this.excalidrawContainerValue,children:Me(Y1.Provider,{value:this.editorInterface,children:Me($1.Provider,{value:this.setAppState,children:Me(X1.Provider,{value:this.state,children:ed(K1.Provider,{value:this.scene.getNonDeletedElements(),children:[ed(Z1.Provider,{value:this.actionManager,children:[Me(OS,{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:Wn().code,renderTopLeftUI:r,renderTopRightUI:n,renderCustomStats:i,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}),Me("div",{className:"excalidraw-textEditorContainer"}),Me("div",{className:"excalidraw-contextMenuContainer"}),Me("div",{className:"excalidraw-eye-dropper-container"}),Me(US,{trails:[this.laserTrails,this.lassoTrail,this.eraserTrail]}),o.length===1&&this.state.openDialog?.name!=="elementLinkSelector"&&this.state.showHyperlinkPopup&&Me(M2,{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&&T1(p)&&Me(C0,{element:p,elementsMap:s,children:Me(Cu,{title:h("labels.convertToCode"),icon:wi,checked:!1,onChange:()=>this.onMagicFrameGenerate(p,"button")})}),o.length===1&&el(p)&&p.customData?.generationData?.status==="done"&&ed(C0,{element:p,elementsMap:s,children:[Me(Cu,{title:h("labels.copySource"),icon:Ia,checked:!1,onChange:()=>this.onIframeSrcCopy(p)}),Me(Cu,{title:"Enter fullscreen",icon:py,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(b){console.warn(b),this.setState({errorMessage:"Couldn't enter fullscreen"})}}})]}),o.length===1&&Vt(p)&&p.customData?.type!=="image-generator"&&!this.state.viewModeEnabled&&Me(W3,{element:p,app:this}),o.length===1&&Vt(p)&&p.customData?.type==="image-generator"&&!this.state.viewModeEnabled&&Me(Z3,{element:p,app:this,onBeforeImageGen:this.props.onBeforeImageGen,onAfterImageGen:this.props.onAfterImageGen}),o.length===1&&li(p)&&!this.state.viewModeEnabled&&Me(q3,{element:p,app:this,onBeforeImageGen:this.props.onBeforeImageGen,onAfterImageGen:this.props.onAfterImageGen}),this.state.toast!==null&&Me(b4,{message:this.state.toast.message,onClose:this.handleToastClose,duration:this.state.toast.duration,closable:this.state.toast.closable}),this.state.contextMenu&&Me(D5,{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?.()})}}),Me(c1,{canvas:this.canvas,rc:this.rc,elementsMap:s,allElementsMap:c,visibleElements:l,sceneNonce:a,selectionNonce:this.state.selectionElement?.versionNonce,scale:window.devicePixelRatio,appState:this.state,renderConfig:{imageCache:this.imageCache,isExporting:!1,renderGrid:Ur(this),canvasBackgroundColor:this.state.viewBackgroundColor,embedsValidationStatus:this.embedsValidationStatus,elementsPendingErasure:this.elementsPendingErasure,pendingFlowchartNodes:this.flowChartCreator.pendingNodes,theme:this.state.theme}}),this.state.newElement&&Me(h4,{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}}),Me(l1,{app:this,containerRef:this.excalidrawContainerRef,canvas:this.interactiveCanvas,elementsMap:s,visibleElements:l,allElementsMap:c,selectedElements:o,sceneNonce:a,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&&Me(N5,{width:this.state.width,height:this.state.height,userToFollow:this.state.userToFollow,onDisconnect:this.maybeUnfollowRemoteUser}),this.renderFrameNames(),this.state.activeLockedId&&Me(x4,{app:this,activeLockedId:this.state.activeLockedId}),d&&Me(V2,{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 i=WX(this.scene.getNonDeletedElements(),o).filter(s=>!T1(s));if(!i.length){n==="button"?(this.setState({errorMessage:"Cannot generate from an empty frame"}),he("ai","generate (no-children)","d2c")):this.setActiveTool({type:"magicframe"});return}let a=this.insertIframeElement({sceneX:o.x+o.width+30,sceneY:o.y,width:o.width,height:o.height});if(a){this.updateMagicGeneration({frameElement:a,data:{status:"pending"}}),this.setState({selectedElementIds:{[a.id]:!0}}),he("ai","generate (start)","d2c");try{let{html:s}=await r({frame:o,children:i});if(he("ai","generate (success)","d2c"),!s.trim()){this.updateMagicGeneration({frameElement:a,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:a,data:{status:"done",html:l}})}catch(s){he("ai","generate (failed)","d2c"),this.updateMagicGeneration({frameElement:a,data:{status:"error",code:"ERR_OAI",message:s.message||"Unknown error during generation"}})}}}onIframeSrcCopy(o){o.customData?.generationData?.status==="done"&&($o(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=>{Vc(r)&&n[r.fileId]&&(this.imageCache.delete(r.fileId),Xc.delete(r))})}async componentDidMount(){if(this.unmounted=!1,this.excalidrawContainerValue.container=this.excalidrawContainerRef.current,yM()||wM()){let r=this.setState.bind(this);Object.defineProperties(window.h,{state:{configurable:!0,get:()=>this.state},setState:{configurable:!0,value:(...i)=>this.setState(...i)},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(),XK&&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),uX()&&!QX()&&this.setState({errorMessage:Me(P5,{})})}componentWillUnmount(){window.launchQueue?.setConsumer(()=>{}),this.renderer.destroy(),this.scene.destroy(),this.scene=new mM,this.fonts=new hr(this.scene),this.renderer=new bc(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(),Xc.destroy(),Lo.destroy(),clearTimeout(di),ze.clearCache(),Go.clearCache(),di=0,document.documentElement.style.overscrollBehaviorX=""}removeEventListeners(){this.onRemoveEventListenersEmitter.trigger()}addEventListeners(){this.removeEventListeners(),this.props.handleKeyboardGlobally&&this.onRemoveEventListenersEmitter.once(lt(document,ue.KEYDOWN,this.onKeyDown,!1)),this.onRemoveEventListenersEmitter.once(lt(this.excalidrawContainerRef.current,ue.WHEEL,this.handleWheel,{passive:!1}),lt(window,ue.MESSAGE,this.onWindowMessage,!1),lt(document,ue.POINTER_UP,this.removePointer,{passive:!1}),lt(document,ue.COPY,this.onCopy,{passive:!1}),lt(document,ue.KEYUP,this.onKeyUp,{passive:!0}),lt(document,ue.POINTER_MOVE,this.updateCurrentCursorPosition,{passive:!1}),lt(document.fonts,"loadingdone",o=>{let n=o.fontfaces;this.fonts.onLoaded(n)},{passive:!1}),lt(document,ue.GESTURE_START,this.onGestureStart,!1),lt(document,ue.GESTURE_CHANGE,this.onGestureChange,!1),lt(document,ue.GESTURE_END,this.onGestureEnd,!1),lt(window,ue.FOCUS,()=>{this.maybeCleanupAfterMissingPointerUp(null),this.triggerRender(!0)},{passive:!1})),!this.state.viewModeEnabled&&(this.onRemoveEventListenersEmitter.once(lt(document,ue.FULLSCREENCHANGE,this.onFullscreenChange,{passive:!1}),lt(document,ue.PASTE,this.pasteFromClipboard,{passive:!1}),lt(document,ue.CUT,this.onCut,{passive:!1}),lt(window,ue.RESIZE,this.onResize,!1),lt(window,ue.UNLOAD,this.onUnload,!1),lt(window,ue.BLUR,this.onBlur,!1),lt(this.excalidrawContainerRef.current,ue.WHEEL,this.handleWheel,{passive:!1}),lt(this.excalidrawContainerRef.current,ue.DRAG_OVER,this.disableEvent,!1),lt(this.excalidrawContainerRef.current,ue.DROP,this.disableEvent,!1)),this.props.detectScroll&&this.onRemoveEventListenersEmitter.once(lt(JK(this.excalidrawContainerRef.current),ue.SCROLL,this.onScroll,{passive:!1})))}componentDidUpdate(o,n){this.updateEmbeddables();let r=this.scene.getElementsIncludingDeleted(),i=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&&oo(this.state)&&this.setState({activeTool:Bn(this.state,{type:"selection"})}),this.state.activeTool.type==="eraser"&&n.theme!==this.state.theme&&yh(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(),oo(n)&&!oo(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===Au.DARK),this.state.selectedLinearElement?.isEditing&&!this.state.selectedElementIds[this.state.selectedLinearElement.elementId]&&setTimeout(()=>{this.state.selectedLinearElement?.isEditing&&this.actionManager.executeAction(Zt)}),this.state.editingTextElement?.isDeleted&&this.setState({editingTextElement:null}),this.store.commit(i,this.state),this.state.isLoading||(this.props.onChange?.(r,this.state,this.files),this.onChangeEmitter.trigger(r,this.state,this.files))}static resetTapTwice(){$c=!1,Zc=null}async insertClipboardContent(o,n,r){let{x:i,y:a}=je({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:i,sceneY:a});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(rg(m))}if(s.length>0){this.isToolSupported("image")?await this.insertImages(s,i,a):this.setState({errorMessage:h("errors.imageToolNotSupported")});return}if(o.elements){let m=o.programmaticAPI?fM(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&&u5(o.text)){let m=await import("@excalidraw/mermaid-to-excalidraw");try{let{elements:p,files:d}=await m.parseMermaidToExcalidraw(o.text),u=fM(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=iX(o.text).split(/\n+/).map(m=>m.trim()).filter(Boolean),c=l.map(m=>_X(m)).filter(m=>k1(m,this.props.validateEmbeddable)&&(/^(http|https):\/\/[^\s/$.?#].[^\s]*$/.test(m)||Fu(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:i,sceneY:a,link:g1(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:i}){if(!n&&o.some(a=>a.type==="imageUrl")&&this.isToolSupported("image")){let a=o.filter(m=>m.type==="imageUrl").map(m=>m.value),s=await Promise.all(a.map(async m=>{try{return{file:await Ux(m)}}catch(p){let d=p.message;return p.cause==="FETCH_ERROR"?d=h("errors.failedToFetchImage"):p.cause==="UNSUPPORTED"&&(d=h("errors.unsupportedFileType")),{errorMessage:d}}})),l=s.filter(m=>!!m.file).map(m=>m.file);await this.insertImages(l,r,i);let c=s.find(m=>!!m.errorMessage);c&&c.errorMessage&&this.setState({errorMessage:c.errorMessage})}else{let a=o.filter(s=>s.type==="text");a.length&&this.addTextFromPaste(a.map(s=>s.value).join(`
|
|
124
|
+
|
|
125
|
+
`),n)}}addTextFromPaste(o,n=!1){let{x:r,y:i}=je({clientX:this.lastViewportPosition.x,clientY:this.lastViewportPosition.y},this.state),a={x:r,y:i,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:$K,verticalAlign:M4,locked:!1},s=h1({fontSize:a.fontSize,fontFamily:a.fontFamily}),l=D4(a.fontFamily),[c,,m]=XX(this.state),p=Math.max(Math.min((m-c)*.5,800),200),d=10,u=i,b=n?[o]:o.split(`
|
|
126
|
+
`),g=b.reduce((E,y,x)=>{let w=e$(y).trim();if(w.length){let v=this.getTopLayerFrameAtSceneCoords({x:r,y:u}),T=nM(w,s,l),C=T.width>p,M=C?qX(w,s,p):w;T=C?nM(M,s,l):T;let k=r-T.width/2,R=u-T.height/2,A=W4({...a,x:k,y:R,text:M,originalText:w,lineHeight:l,autoResize:!C,frameId:v?v.id:null});E.push(A),u+=A.height+d}else b[x-1]?.trim()&&(u+=t$(a.fontSize,l)+d);return E},[]);g.length!==0&&(this.scene.insertElements(g),this.store.scheduleCapture(),this.setState({selectedElementIds:Be(Object.fromEntries(g.map(E=>[E.id,!0])),this.state)}),!n&&g.length>1&&xM===!1&&this.editorInterface.formFactor!=="phone"&&(this.setToast({message:h("toast.pasteAsSingleElement",{shortcut:N("CtrlOrCmd+Shift+V")}),duration:5e3}),xM=!0))}handleTextWysiwyg(o,{isExistingElement:n=!1}){let r=this.scene.getElementsMapIncludingDeleted(),i=(a,s)=>{this.scene.replaceAllElements([...this.scene.getElementsIncludingDeleted().map(l=>l.id===o.id&&an(l)?si(l,{originalText:a,isDeleted:s??l.isDeleted,...CX(l,J4(l,r),r,a)}):l)])};d5({id:o.id,canvas:this.canvas,getViewportCoords:(a,s)=>{let{x:l,y:c}=_u({sceneX:a,sceneY:s},this.state);return[l-this.state.offsetLeft,c-this.state.offsetTop]},onChange:it(a=>{i(a,!1),dM(o)&&Bu(o,this.scene)}),onSubmit:it(({viaKeyboard:a,nextOriginalText:s})=>{let l=!s.trim();if(i(s,l),!l&&a){let c=o.containerId?o.containerId:o.id;co(()=>{this.setState(m=>({selectedElementIds:Be({...m.selectedElementIds,[c]:!0},m)}))})}l&&xX(this.scene.getNonDeletedElements(),[o]),(!l||n)&&this.store.scheduleCapture(),co(()=>{this.setState({newElement:null,editingTextElement:null})}),this.state.activeTool.locked&&bo(this.interactiveCanvas,this.state),this.focusContainer()}),element:o,excalidrawContainer:this.excalidrawContainerRef.current,app:this,autoSelect:!this.editorInterface.isTouchScreen}),this.deselectElements(),i(o.originalText,!1)}deselectElements(){this.setState({selectedElementIds:Be({},this.state),selectedGroupIds:{},editingGroupId:null,activeEmbeddable:null})}getTextElementAtPosition(o,n){let r=this.getElementAtPosition(o,n,{includeBoundTextElement:!0});return r&&an(r)&&!r.isDeleted?r:null}getElementAtPosition(o,n,r){let i=[];if(r&&"allHitElements"in r?i=r?.allHitElements||[]:i=this.getElementsAtPosition(o,n,{includeBoundTextElement:r?.includeBoundTextElement,includeLockedElements:r?.includeLockedElements}),i.length>1){if(r?.preferSelected){for(let s=i.length-1;s>-1;s--)if(this.state.selectedElementIds[i[s].id])return i[s]}let a=i[i.length-1];return Kc({point:ce(o,n),element:a,threshold:this.getElementHitThreshold(a)/2,elementsMap:this.scene.getNonDeletedElementsMap(),frameNameBound:Vt(a)?this.frameNameBoundsCache.get(a):null})?a:i[i.length-2]}return i.length===1?i[0]:null}getElementsAtPosition(o,n,r){let i=[],a=this.scene.getNonDeletedElementsMap();return(r?.includeBoundTextElement&&r?.includeLockedElements?this.scene.getNonDeletedElements():this.scene.getNonDeletedElements().filter(l=>(r?.includeLockedElements||!l.locked)&&(r?.includeBoundTextElement||!(an(l)&&l.containerId)))).filter(l=>this.hitElement(o,n,l)).filter(l=>{let c=_1(l,a);return c&&this.state.frameRendering.enabled&&this.state.frameRendering.clip?Q4({x:o,y:n},c,a):!0}).filter(l=>el(l)?(i.push(l),!1):!0).concat(i)}getElementHitThreshold(o){return Math.max(o.strokeWidth/2+.1,.85*(_4/this.state.zoom.value))}hitElement(o,n,r,i=!0){return i&&this.state.selectedElementIds[r.id]&&FX([r],this.state,this.editorInterface)&&x$(ce(o,n),r,this.scene.getNonDeletedElementsMap(),this.getElementHitThreshold(r))||VX(ce(o,n),r,this.scene.getNonDeletedElementsMap())?!0:Kc({point:ce(o,n),element:r,threshold:this.getElementHitThreshold(r),elementsMap:this.scene.getNonDeletedElementsMap(),frameNameBound:Vt(r)?this.frameNameBoundsCache.get(r):null})}getTextBindableContainerAtPosition(o,n){let r=this.scene.getNonDeletedElements(),i=this.scene.getSelectedElements(this.state);if(i.length===1)return K4(i[0],!1)?i[0]:null;let a=null;for(let s=r.length-1;s>=0;--s){if(r[s].isDeleted)continue;let[l,c,m,p]=Nu(r[s],this.scene.getNonDeletedElementsMap());if(Qs(r[s])&&Kc({point:ce(o,n),element:r[s],elementsMap:this.scene.getNonDeletedElementsMap(),threshold:this.getElementHitThreshold(r[s])})){a=r[s];break}else if(l<o&&o<m&&c<n&&n<p){a=r[s];break}}return K4(a,!1)?a:null}handleHoverSelectedLinearElement(o,n,r){let i=this.scene.getNonDeletedElementsMap(),a=ke.getElement(o.elementId,i);if(a)if(this.state.selectedLinearElement){let s=-1,l=null;Kc({point:ce(n,r),element:a,elementsMap:i,threshold:this.getElementHitThreshold(a)})?(s=ke.getPointIndexUnderCursor(a,i,this.state.zoom,n,r),l=ke.getSegmentMidpointHitCoords(o,{x:n,y:r},this.state,this.scene.getNonDeletedElementsMap()),(mo(a)?s===0||s===a.points.length-1:s>=0)||l?De(this.interactiveCanvas,et.POINTER):this.hitElement(n,r,a)&&(!mo(a)||!(a.startBinding||a.endBinding))&&(this.state.activeTool.type!=="lasso"||Object.keys(this.state.selectedElementIds).length>0)&&De(this.interactiveCanvas,et.MOVE)):this.hitElement(n,r,a)&&(!mo(a)||!(a.startBinding||a.endBinding))&&(this.state.activeTool.type!=="lasso"||Object.keys(this.state.selectedElementIds).length>0)&&De(this.interactiveCanvas,et.MOVE),this.state.selectedLinearElement.hoverPointIndex!==s&&this.setState({selectedLinearElement:{...this.state.selectedLinearElement,hoverPointIndex:s}}),ke.arePointsEqual(this.state.selectedLinearElement.segmentMidPointHoveredCoords,l)||this.setState({selectedLinearElement:{...this.state.selectedLinearElement,segmentMidPointHoveredCoords:l}});let c=null,m=a;(m.startBinding||m.endBinding)&&(c=T$(a,n,r,this.scene,this.state)),this.state.selectedLinearElement.hoveredFocusPointBinding!==c&&this.setState({selectedLinearElement:{...this.state.selectedLinearElement,isDragging:!1,hoveredFocusPointBinding:c}}),c&&De(this.interactiveCanvas,et.POINTER)}else De(this.interactiveCanvas,et.AUTO)}updateGestureOnPointerDown(o){Le.pointers.set(o.pointerId,{x:o.clientX,y:o.clientY}),Le.pointers.size===2&&(Le.lastCenter=E0(Le.pointers),Le.initialScale=this.state.zoom.value,Le.initialDistance=y0(Array.from(Le.pointers.values())))}initialPointerDownState(o){let n=je(o,this.state),r=this.scene.getSelectedElements(this.state),[i,a,s,l]=Js(r),c=r.findIndex(mo)===0;return{origin:n,withCmdOrCtrl:o[J.CTRL_OR_CMD],originInGrid:f1(Yt(n.x,n.y,o[J.CTRL_OR_CMD]||c?null:this.getEffectiveGridSize())),scrollbars:H0(qc,o.clientX-this.state.offsetLeft,o.clientY-this.state.offsetTop),lastCoords:{...n},originalElements:this.scene.getNonDeletedElements().reduce((m,p)=>(m.set(p.id,Y4(p)),m),new Map),resize:{handleType:!1,isResizing:!1,offset:{x:0,y:0},arrowDirection:"origin",center:{x:(s+i)/2,y:(l+a)/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;O1=!0,n.lastCoords.x=o.clientX,n.lastCoords.y=o.clientY;let r=Rp(a=>{a.target instanceof HTMLElement&&this.handlePointerMoveOverScrollbars(a,n)}),i=it(()=>{Qc=null,O1=!1,bo(this.interactiveCanvas,this.state),this.setState({cursorButton:"up"}),this.savePointer(o.clientX,o.clientY,"up"),window.removeEventListener(ue.POINTER_MOVE,r),window.removeEventListener(ue.POINTER_UP,i),r.flush()});return Qc=i,window.addEventListener(ue.POINTER_MOVE,r),window.addEventListener(ue.POINTER_UP,i),!0}isASelectedElement(o){return o!=null&&this.state.selectedElementIds[o.id]}isHittingCommonBoundingBoxOfSelectedElements(o,n){if(n.length<2)return!1;let r=Math.max(_4/this.state.zoom.value,1),[i,a,s,l]=Js(n);return o.x>i-r&&o.x<s+r&&o.y>a-r&&o.y<l+r}getCurrentItemRoundness(o){return this.state.currentItemRoundness==="round"?{type:MX(o)?Pu.ADAPTIVE_RADIUS:Pu.PROPORTIONAL_RADIUS}:null}maybeCacheReferenceSnapPoints(o,n,r=!1){or({event:o,app:this,selectedElements:n})&&(r||!Lo.getReferenceSnapPoints())&&Lo.setReferenceSnapPoints(N3(this.scene.getNonDeletedElements(),n,this.state,this.scene.getNonDeletedElementsMap()))}maybeCacheVisibleGaps(o,n,r=!1){or({event:o,app:this,selectedElements:n})&&(r||!Lo.getVisibleGaps())&&Lo.setVisibleGaps(R3(this.scene.getNonDeletedElements(),n,this.state,this.scene.getNonDeletedElementsMap()))}onKeyDownFromPointerDownHandler(o){return it(n=>{this.maybeHandleResize(o,n)||this.maybeDragNewGenericElement(o,n)})}onKeyUpFromPointerDownHandler(o){return it(n=>{n.key===J.ALT&&n.preventDefault(),!this.maybeHandleResize(o,n)&&this.maybeDragNewGenericElement(o,n)})}onPointerMoveFromPointerDownHandler(o){return Rp(n=>{if(this.state.openDialog?.name==="elementLinkSelector")return;let r=je(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]=Yt(r.x,r.y,n[J.CTRL_OR_CMD]?null:this.getEffectiveGridSize()),b=this.state.selectedLinearElement.initialState.segmentMidpoint.index;if(b<0){let E=ke.getSegmentMidpointHitCoords({...this.state.selectedLinearElement,segmentMidPointHoveredCoords:null},{x:d,y:u},this.state,this.scene.getNonDeletedElementsMap());b=E?ke.getSegmentMidPointIndex(this.state.selectedLinearElement,this.state,E,this.scene.getNonDeletedElementsMap()):-1}let g=ke.moveFixedSegment(this.state.selectedLinearElement,b,d,u,this.scene);this.setState({selectedLinearElement:{...this.state.selectedLinearElement,isDragging:!0,segmentMidPointHoveredCoords:g.segmentMidPointHoveredCoords,initialState:g.initialState}});return}let i=this.previousPointerMoveCoords??o.origin;if(this.previousPointerMoveCoords=r,o.drag.offset===null&&(o.drag.offset=f1(f$(this.scene.getSelectedElements(this.state),o.origin.x,o.origin.y))),!(n.target instanceof HTMLElement)||this.handlePointerMoveOverScrollbars(n,o))return;if(oo(this.state)){this.handleEraser(n,r);return}this.state.activeTool.type==="laser"&&this.laserTrails.addPointToPath(r.x,r.y);let[s,l]=Yt(r.x,r.y,n[J.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){v$(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(ke.shouldAddMidpoint(this.state.selectedLinearElement,r,this.state,c)){let u=ke.addMidpoint(this.state.selectedLinearElement,r,this,!n[J.CTRL_OR_CMD],this.scene);if(!u)return;co(()=>{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=ke.getElement(d.elementId,c);if(u?.isDeleted)return;if(zn(u)){let g=rn(ce(r.x,r.y),this.scene.getNonDeletedElements(),c);cr("COMPLEX_BINDINGS")&&this.handleDelayedBindModeChange(u,g)}if(n.altKey&&!this.state.selectedLinearElement?.initialState?.arrowStartIsInside&&cr("COMPLEX_BINDINGS")&&this.handleSkipBindMode(),d.initialState.lastClickedPoint===-1)return;let b=ke.handlePointDragging(n,this,r.x,r.y,d);if(b){o.lastCoords.x=r.x,o.lastCoords.y=r.y,o.drag.hasOccurred=!0,(b.suggestedBinding!==this.state.suggestedBinding||!F4(b.selectedLinearElement?.selectedPointsIndices??[],this.state.selectedLinearElement?.selectedPointsIndices??[])||b.selectedLinearElement?.hoverPointIndex!==this.state.selectedLinearElement?.hoverPointIndex||b.selectedLinearElement?.customLineAngle!==this.state.selectedLinearElement?.customLineAngle||this.state.selectedLinearElement.isDragging!==b.selectedLinearElement?.isDragging||this.state.selectedLinearElement?.initialState?.altFocusPoint!==b.selectedLinearElement?.initialState?.altFocusPoint)&&this.setState(b);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(E=>E.locked))return;let u=d.find(E=>Vt(E)),b=this.getTopLayerFrameAtSceneCoords(r),g=b&&!u?b:null;if(this.state.frameToHighlight!==g&&co(()=>{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 E={x:r.x-o.drag.origin.x,y:r.y-o.drag.origin.y},y=[...o.originalElements.values()],x=n.shiftKey;if(x){let T=Math.abs(E.x),C=Math.abs(E.y),M=x&&T<C,k=x&&T>C;M&&(E.x=0),k&&(E.y=0)}if(this.state.croppingElementId){let T=this.scene.getNonDeletedElementsMap().get(this.state.croppingElementId);if(T&&li(T)&&T.crop!==null&&o.hit.element===T){let C=T.crop,M=Vc(T)&&this.imageCache.get(T.fileId)?.image;if(M&&!(M instanceof Promise)){let k=k$(T),R=w4(r.x-i.x,r.y-i.y);R[0]*=M.naturalWidth/k.width,R[1]*=M.naturalHeight/k.height;let[A,P,_,O,U,H]=Nu(T,c),W=p1(m1(ce(A,P),ce(U,H),T.angle)),D=p1(m1(ce(_,P),ce(U,H),T.angle)),F=p1(m1(ce(A,O),ce(U,H),T.angle)),X=I4(v4(D,W)),te=I4(v4(F,W)),$=w4(T4(R,X),T4(R,te)),ae={...C,x:y4(C.x-$[0]*Math.sign(T.scale[0]),0,M.naturalWidth-C.width),y:y4(C.y-$[1]*Math.sign(T.scale[1]),0,M.naturalHeight-C.height)};this.scene.mutateElement(T,{crop:ae});return}}}this.maybeCacheVisibleGaps(n,d),this.maybeCacheReferenceSnapPoints(n,d);let{snapOffset:w,snapLines:v}=B3(y,E,this,n,this.scene.getNonDeletedElementsMap());if(this.setState({snapLines:v}),this.state.editingFrame||h$(o,d,E,this.scene,w,n[J.CTRL_OR_CMD]?null:this.getEffectiveGridSize()),this.setState({selectedElementsAreBeingDragged:!0,selectionElement:null}),n.altKey&&!o.hit.hasBeenDuplicated){o.hit.hasBeenDuplicated=!0;let T=this.scene.getElementsIncludingDeleted(),C=o.hit.element,M=this.scene.getSelectedElements({selectedElementIds:this.state.selectedElementIds,includeBoundTextElement:!0,includeElementsInFrames:!0});C&&o.hit.wasAddedToSelection&&!M.find(W=>W.id===C.id)&&M.push(C);let k=new Map(M.map(W=>[W.id,W])),{duplicatedElements:R,duplicateElementsMap:A,elementsWithDuplicates:P,origIdToDuplicateId:_}=y1({type:"in-place",elements:T,appState:this.state,randomizeSeed:!0,idsOfElementsToDuplicate:k,overrides:({duplicateElement:W,origElement:D})=>({frameId:W.frameId??D.frameId,seed:sX()})});R.forEach(W=>{o.originalElements.set(W.id,Y4(W))});let O=P.map(W=>{if(k.has(W.id)){let D=o.originalElements.get(W.id);if(D)return si(W,{x:D.x,y:D.y})}return W}),U=this.props.onDuplicate?.(O,T),H=iM(U||O,Du(R));co(()=>{if(o.hit.element){let W=_.get(o.hit.element.id),D=W&&A.get(W);o.hit.element=D||null}o.hit.allHitElements=o.hit.allHitElements.reduce((W,D)=>{let F=_.get(D.id),X=F&&A.get(F);return X&&W.push(X),W},[]),o.drag.origin=je(n,this.state),this.setState(W=>({...m$(R,this.scene.getNonDeletedElements(),W)})),this.scene.replaceAllElements(H),M.forEach(W=>{I1(W)&&W.boundElements?.some(D=>D.type==="arrow")&&Bu(W,this.scene)}),this.maybeCacheVisibleGaps(n,M,!0),this.maybeCacheReferenceSnapPoints(n,M,!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,b=r.x-d.x,g=r.y-d.y,E=u.length>0&&u[u.length-1];if(!(E&&E[0]===b&&E[1]===g)){let x=d.simulatePressure?d.pressures:[...d.pressures,n.pressure];this.scene.mutateElement(d,{points:[...u,ce(b,g)],pressures:x},{informMutation:!1,isDragging:!1}),this.setState({newElement:d})}}else if(eo(d)&&!d.isDeleted){o.drag.hasOccurred=!0;let u=d.points;Fn(u.length>1,"Do not create linear elements with less than 2 points");let b=this.state.selectedLinearElement;b||(b=new ke(d,this.scene.getNonDeletedElementsMap()),b={...b,selectedPointsIndices:[1],initialState:{...b.initialState,lastClickedPoint:1}}),this.setState({newElement:d,...ke.handlePointDragging(n,this,s,l,b)})}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)ke.handleBoxSelection(n,this.state,this.setState.bind(this),this.scene.getNonDeletedElementsMap());else{let u=!0;!n.shiftKey&&ze(d,this.state)&&(o.withCmdOrCtrl&&o.hit.element?this.setState(g=>Go({...g,selectedElementIds:{[o.hit.element.id]:!0}},this.scene.getNonDeletedElements(),g,this)):u=!1);let b=this.state.selectionElement?kx(d,this.state.selectionElement,this.scene.getNonDeletedElementsMap(),!1):[];this.setState(g=>{let E={...u&&g.selectedElementIds,...b.reduce((y,x)=>(y[x.id]=!0,y),{})};return o.hit.element&&(b.length?delete E[o.hit.element.id]:E[o.hit.element.id]=!0),g=u?g:{...g,selectedGroupIds:{},editingGroupId:null},{...Go({editingGroupId:g.editingGroupId,selectedElementIds:E},this.scene.getNonDeletedElements(),g,this),selectedLinearElement:b.length===1&&eo(b[0])?new ke(b[0],this.scene.getNonDeletedElementsMap()):null,showHyperlinkPopup:b.length===1&&(b[0].link||dr(b[0]))?"info":!1}})}}})}handlePointerMoveOverScrollbars(o,n){if(n.scrollbars.isOverHorizontal){let r=o.clientX,i=r-n.lastCoords.x;return this.translateCanvas({scrollX:this.state.scrollX-i*(qc.horizontal?.deltaMultiplier||1)/this.state.zoom.value}),n.lastCoords.x=r,!0}if(n.scrollbars.isOverVertical){let r=o.clientY,i=r-n.lastCoords.y;return this.translateCanvas({scrollY:this.state.scrollY-i*(qc.vertical?.deltaMultiplier||1)/this.state.zoom.value}),n.lastCoords.y=r,!0}return!1}onPointerUpFromPointerDownHandler(o){return it(n=>{let r=this.scene.getNonDeletedElementsMap();this.removePointer(n),o.drag.blockDragging=!1,o.eventListeners.onMove&&o.eventListeners.onMove.flush();let{newElement:i,resizingElement:a,croppingElementId:s,multiElement:l,activeTool:c,isResizing:m,isRotating:p,isCropping:d}=this.state;this.setState(x=>({isResizing:!1,isRotating:!1,isCropping:!1,resizingElement:null,selectionElement:null,frameToHighlight:null,elementsToHighlight:null,cursorButton:"up",snapLines:Wc(x.snapLines,[]),originSnapOffset:null})),this.lassoTrail.endPath(),this.previousPointerMoveCoords=null,Lo.setReferenceSnapPoints(null),Lo.setVisibleGaps(null),this.savePointer(n.clientX,n.clientY,"up");let u=o.hit.allHitElements,b=je({clientX:n.clientX,clientY:n.clientY},this.state);if(this.state.activeTool.type==="selection"&&!o.boxSelection.hasOccurred&&!o.resize.isResizing&&!u.some(x=>this.state.selectedElementIds[x.id])){let x=this.getElementAtPosition(b.x,b.y,{includeLockedElements:!0});this.store.scheduleCapture(),x?.locked?this.setState({activeLockedId:x.groupIds.length>0?x.groupIds.at(-1)||"":x.id}):this.setState({activeLockedId:null})}else this.setState({activeLockedId:null});if(cr("COMPLEX_BINDINGS")&&this.resetDelayedBindMode(),this.setState({selectedElementsAreBeingDragged:!1,bindMode:"orbit"}),o.drag.hasOccurred&&o.hit?.element?.id){let x=r.get(o.hit.element.id);I1(x)&&x.boundElements?.filter(w=>w.type==="arrow").map(w=>r.get(w.id)).filter(w=>mo(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(Zt);else{let x=ke.handlePointerUp(n,this.state.selectedLinearElement,this.state,this.scene);this.actionManager.executeAction(Zt,"ui",{event:n,sceneCoords:b}),x!==this.state.selectedLinearElement&&this.setState({selectedLinearElement:x,suggestedBinding:null})}else if(this.state.selectedLinearElement){if(this.state.selectedLinearElement.elbowed){let x=ke.getElement(this.state.selectedLinearElement.elementId,this.scene.getNonDeletedElementsMap());x&&this.scene.mutateElement(x,{})}if(this.state.selectedLinearElement.draggedFocusPointBinding?(C$(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(Zt,"ui",{event:n,sceneCoords:b})),this.state.newElement&&this.state.multiElement&&eo(this.state.newElement)&&this.state.selectedLinearElement){let{multiElement:x}=this.state;this.setState({selectedLinearElement:{...this.state.selectedLinearElement,lastCommittedPoint:x.points[x.points.length-1]}})}}if(this.missingPointerEventCleanupEmitter.clear(),window.removeEventListener(ue.POINTER_MOVE,o.eventListeners.onMove),window.removeEventListener(ue.POINTER_UP,o.eventListeners.onUp),window.removeEventListener(ue.KEYDOWN,o.eventListeners.onKeyDown),window.removeEventListener(ue.KEYUP,o.eventListeners.onKeyUp),this.props?.onPointerUp?.(c,o),this.onPointerUpEmitter.trigger(this.state.activeTool,o,n),i?.type==="freedraw"){let x=je(n,this.state),w=i.points,v=x.x-i.x,T=x.y-i.y;v===w[0][0]&&T===w[0][1]&&(T+=1e-4,v+=1e-4);let C=i.simulatePressure?[]:[...i.pressures,n.pressure];this.scene.mutateElement(i,{points:[...w,ce(v,T)],pressures:C}),this.actionManager.executeAction(Zt);return}if(eo(i)){i.points.length>1&&i.points[1][0]!==0&&i.points[1][1]!==0&&this.store.scheduleCapture();let x=je(n,this.state),w=ri(ce(x.x,x.y),ce(o.origin.x,o.origin.y))*this.state.zoom.value;if((!o.drag.hasOccurred||w<lX)&&i&&!l)if(this.editorInterface.isTouchScreen){let v=Math.min(this.state.width*.7/this.state.zoom.value,100);this.scene.mutateElement(i,{x:i.x-v/2,points:[ce(0,0),ce(v,0)]},{informMutation:!1,isDragging:!1}),this.actionManager.executeAction(Zt)}else{let v=x.x-i.x,T=x.y-i.y;this.scene.mutateElement(i,{points:[i.points[0],ce(v,T)]},{informMutation:!1,isDragging:!1}),this.setState({multiElement:i,newElement:i})}else o.drag.hasOccurred&&!l&&(eo(i)&&this.actionManager.executeAction(Zt,"ui",{event:n,sceneCoords:b}),this.setState({suggestedBinding:null,startBoundElement:null}),c.locked?this.setState(v=>({newElement:null})):(fo(this.interactiveCanvas),this.setState(v=>({newElement:null,activeTool:Bn(this.state,{type:this.state.preferredSelectionTool.type}),selectedElementIds:Be({...v.selectedElementIds,[i.id]:!0},v),selectedLinearElement:new ke(i,this.scene.getNonDeletedElementsMap())}))),this.scene.triggerUpdate());return}if(an(i)){let x=r$(h1({fontSize:i.fontSize,fontFamily:i.fontFamily}),i.lineHeight);i.width<x&&this.scene.mutateElement(i,{autoResize:!0}),this.resetCursor(),this.handleTextWysiwyg(i,{isExistingElement:!0})}if(c.type!=="selection"&&i&&$4(i)){this.updateScene({elements:this.scene.getElementsIncludingDeleted().filter(x=>x.id!==i.id),appState:{newElement:null},captureUpdate:to.NEVER});return}if(Vt(i)){let x=HX(this.scene.getElementsIncludingDeleted(),i,this.scene.getNonDeletedElementsMap());this.scene.replaceAllElements(A1(this.scene.getElementsMapIncludingDeleted(),x,i,this.state))}if(i&&(this.scene.mutateElement(i,AX(i),{informMutation:!1,isDragging:!1}),this.scene.triggerUpdate()),o.drag.hasOccurred){let x=je(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=_1(w,r);v&&w&&(GX(w,v,this.scene.getNonDeletedElementsMap())||(this.scene.mutateElement(w,{groupIds:[]}),OX([w],this.scene.getNonDeletedElementsMap()),this.scene.triggerUpdate()))}}else{let w=this.getTopLayerFrameAtSceneCoords(x),v=this.scene.getSelectedElements(this.state),T=this.scene.getElementsMapIncludingDeleted(),C=M=>{if(M.length>0){for(let k of M){let R=k.groupIds.indexOf(this.state.editingGroupId);this.scene.mutateElement(k,{groupIds:k.groupIds.slice(0,R)},{informMutation:!1,isDragging:!1})}T.forEach(k=>{k.groupIds.length&&ta(T,k.groupIds[k.groupIds.length-1]).length<2&&this.scene.mutateElement(k,{groupIds:[]},{informMutation:!1,isDragging:!1})}),this.setState({editingGroupId:null})}};if(w&&!this.state.selectedElementIds[w.id]){let M=v.filter(k=>k.frameId!==w.id&&tM(k,T,this.state));this.state.editingGroupId&&C(M),T=A1(T,M,w,this.state)}else if(!w&&this.state.editingGroupId){let M=v.filter(k=>k.frameId&&!tM(k,T,this.state));C(M)}T=eM(T,this.state,this),this.scene.replaceAllElements(T)}}if(a&&this.store.scheduleCapture(),a&&$4(a)&&this.updateScene({elements:this.scene.getElementsIncludingDeleted().filter(x=>x.id!==a.id),captureUpdate:to.NEVER}),o.resize.isResizing){let x=eM(this.scene.getElementsIncludingDeleted(),this.state,this),w=this.scene.getSelectedElements(this.state).filter(v=>Vt(v));for(let v of w)x=zX(x,L1(this.scene.getElementsIncludingDeleted(),v,this.state,r),v,this);this.scene.replaceAllElements(x)}let g=o.hit.element;this.state.selectedLinearElement?.elementId!==g?.id&&eo(g)&&this.scene.getSelectedElements(this.state).length===1&&this.setState({selectedLinearElement:new ke(g,this.scene.getNonDeletedElementsMap())}),(!s||s&&(!g&&!d||g&&g.id!==s))&&this.finishImageCropping();let E=this.lastPointerDownEvent,y=this.lastPointerUpEvent||this.lastPointerMoveEvent;if(oo(this.state)&&E&&y){if(this.eraserTrail.endPath(),ri(ce(E.clientX,E.clientY),ce(y.clientX,y.clientY))===0){let w=je({clientX:y.clientX,clientY:y.clientY},this.state);this.getElementsAtPosition(w.x,w.y).forEach(T=>this.elementsPendingErasure.add(T.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]?c$(this.state,g)?this.setState(x=>{let w={...x.selectedElementIds};for(let v of g.groupIds.flatMap(T=>ta(this.scene.getNonDeletedElements(),T)))delete w[v.id];return{selectedGroupIds:{...x.selectedElementIds,...g.groupIds.map(v=>({[v]:!1})).reduce((v,T)=>({...v,...T}),{})},selectedElementIds:Be(w,x)}}):this.state.selectedLinearElement?.isDragging||this.setState(x=>{let w={...x.selectedElementIds};delete w[g.id];let v=se(this.scene.getNonDeletedElements(),{selectedElementIds:w});return{...Go({editingGroupId:x.editingGroupId,selectedElementIds:w},this.scene.getNonDeletedElements(),x,this),selectedLinearElement:v.length===1&&eo(v[0])?new ke(v[0],this.scene.getNonDeletedElementsMap()):x.selectedLinearElement}}):g.frameId&&this.state.selectedElementIds[g.frameId]?this.setState(x=>{let w={...x.selectedElementIds,[g.id]:!0};return delete w[g.frameId],(this.scene.getElement(g.frameId)?.groupIds??[]).flatMap(v=>ta(this.scene.getNonDeletedElements(),v)).forEach(v=>{delete w[v.id]}),{...Go({editingGroupId:x.editingGroupId,selectedElementIds:w},this.scene.getNonDeletedElements(),x,this),showHyperlinkPopup:g.link||dr(g)?"info":!1}}):this.setState(x=>({selectedElementIds:Be({...x.selectedElementIds,[g.id]:!0},x)})):this.setState(x=>({...Go({editingGroupId:x.editingGroupId,selectedElementIds:{[g.id]:!0}},this.scene.getNonDeletedElements(),x,this),selectedLinearElement:eo(g)&&x.selectedLinearElement?.elementId!==g.id?new ke(g,this.scene.getNonDeletedElementsMap()):x.selectedLinearElement}))),this.state.activeTool.type!=="lasso"&&!(g&&mo(g))&&!o.drag.hasOccurred&&!this.state.isResizing&&(g&&KX({point:ce(o.origin.x,o.origin.y),element:g,elementsMap:r,threshold:this.getElementHitThreshold(g),frameNameBound:Vt(g)?this.frameNameBoundsCache.get(g):null},r)||!g&&o.hit.hasHitCommonBoundingBoxOfSelectedElements)){this.state.selectedLinearElement?.isEditing?this.actionManager.executeAction(Cs):this.setState({selectedElementIds:Be({},this.state),selectedGroupIds:{},editingGroupId:null,activeEmbeddable:null}),De(this.interactiveCanvas,et.AUTO);return}if(!c.locked&&c.type!=="freedraw"&&i&&this.setState(x=>({selectedElementIds:Be({...x.selectedElementIds,[i.id]:!0},x),showHyperlinkPopup:dr(i)&&!i.link?"editor":x.showHyperlinkPopup})),(c.type!=="selection"||ze(this.scene.getNonDeletedElements(),this.state)||!F4(this.state.previousSelectedElementIds,this.state.selectedElementIds))&&this.store.scheduleCapture(),o.drag.hasOccurred&&!this.state.selectedLinearElement||m||p||d){let x=this.scene.getSelectedElements(this.state).filter(Qs);O4(x,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)?(fo(this.interactiveCanvas),this.setState({newElement:null,suggestedBinding:null,activeTool:Bn(this.state,{type:this.state.preferredSelectionTool.type})})):this.setState({newElement:null,suggestedBinding:null})})}clearSelection(o){this.setState(n=>({selectedElementIds:Be({},n),activeEmbeddable:null,selectedGroupIds:{},editingGroupId:n.editingGroupId&&o!=null&&rM(o,n.editingGroupId)?n.editingGroupId:null})),this.setState({selectedElementIds:Be({},this.state),activeEmbeddable:null,previousSelectedElementIds:this.state.selectedElementIds,selectedLinearElement:null})}getTextWysiwygSnappedToCenterPosition(o,n,r,i){if(i){let a=i.x+i.width/2,s=i.y+i.height/2,l=M1(i,r,this.scene.getNonDeletedElementsMap());if(l&&(a=l.x,s=l.y),Math.hypot(o-a,n-s)<WK){let{x:p,y:d}=_u({sceneX:a,sceneY:s},r);return{viewportX:p,viewportY:d,elementCenterX:a,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=ga.find(n=>n.code===this.props.langCode)||pn;await fd(o),this.setAppState({})}},S$=()=>{(yM()||wM())&&(window.h=window.h||{},Object.defineProperties(window.h,{elements:{configurable:!0,get(){return this.app?.scene.getElementsIncludingDeleted()},set(e){return this.app?.scene.replaceAllElements(TM(e))}},scene:{configurable:!0,get(){return this.app?.scene}}}))};S$();var kM=W1;import{useEffect as M$,useState as P$}from"react";import{jsx as A$}from"react/jsx-runtime";var SM=e=>{let[t,o]=P$(!0);return M$(()=>{let n=async()=>{await fd(r),o(!1)},r=ga.find(i=>i.code===e.langCode)||pn;n()},[e.langCode]),t?A$(Op,{theme:e.theme}):e.children};import L$ from"clsx";import{jsx as MM}from"react/jsx-runtime";var PM=({children:e})=>{let{FooterCenterTunnel:t}=We(),o=Ee();return MM(t.In,{children:MM("div",{className:L$("footer-center zen-mode-transition",{"layer-ui__wrapper__footer-left--transition-bottom":o.zenModeEnabled}),children:e})})},_$=PM;PM.displayName="FooterCenter";import D$ from"clsx";import{MQ_MIN_WIDTH_DESKTOP as R$}from"@orangecatai/common";import{jsx as B$,jsxs as F$}from"react/jsx-runtime";var AM=({isCollaborating:e,onSelect:t,editorInterface:o,...n})=>{let r=Ee(),i=o?.formFactor!=="desktop"||r.width<R$;return F$(Jt,{...n,className:D$("collab-button",{active:e}),type:"button",onSelect:t,style:{position:"relative",width:i?void 0:"auto"},title:h("labels.liveCollaboration"),children:[i?bE:h("labels.share"),r.collaborators.size>0&&B$("div",{className:"CollabButton-collaborators",children:r.collaborators.size})]})},N$=AM;AM.displayName="LiveCollaborationTrigger";import{jsx as pi,jsxs as _M}from"react/jsx-runtime";var z$=()=>pi("svg",{viewBox:"0 0 40 40",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:"ExcalidrawLogo-icon",children:pi("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"})}),O$=()=>_M("svg",{viewBox:"0 0 450 55",xmlns:"http://www.w3.org/2000/svg",fill:"none",className:"ExcalidrawLogo-text",children:[pi("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)"}),pi("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)"}),pi("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)"}),pi("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)"})]}),LM=({style:e,size:t="small",withText:o})=>_M("div",{className:`ExcalidrawLogo is-${t}`,style:e,children:[pi(z$,{}),o&&pi(O$,{})]});import{Fragment as NM,jsx as ft,jsxs as j1}from"react/jsx-runtime";var q1=({icon:e,shortcut:t,children:o})=>{let n=ye();return j1(NM,{children:[ft("div",{className:"welcome-screen-menu-item__icon",children:e}),ft("div",{className:"welcome-screen-menu-item__text",children:o}),t&&n.formFactor!=="phone"&&ft("div",{className:"welcome-screen-menu-item__shortcut",children:t})]})};q1.displayName="WelcomeScreenMenuItemContent";var td=({onSelect:e,children:t,icon:o,shortcut:n,className:r="",...i})=>ft("button",{...i,type:"button",className:`welcome-screen-menu-item ${r}`,onClick:e,children:ft(q1,{icon:o,shortcut:n,children:t})});td.displayName="WelcomeScreenMenuItem";var DM=({children:e,href:t,icon:o,shortcut:n,className:r="",...i})=>ft("a",{...i,className:`welcome-screen-menu-item ${r}`,href:t,target:"_blank",rel:"noopener",children:ft(q1,{icon:o,shortcut:n,children:e})});DM.displayName="WelcomeScreenMenuItemLink";var Uo=({children:e})=>{let{WelcomeScreenCenterTunnel:t}=We();return ft(t.In,{children:ft("div",{className:"welcome-screen-center",children:e||j1(NM,{children:[ft(J1,{}),ft(Q1,{children:h("welcomeScreen.defaults.center_heading")}),j1(ex,{children:[ft(ox,{}),ft(tx,{})]})]})})})};Uo.displayName="Center";var J1=({children:e})=>ft("div",{className:"welcome-screen-center__logo excalifont welcome-screen-decor",children:e||ft(LM,{withText:!0})});J1.displayName="Logo";var Q1=({children:e})=>ft("div",{className:"welcome-screen-center__heading welcome-screen-decor excalifont",children:e});Q1.displayName="Heading";var ex=({children:e})=>ft("div",{className:"welcome-screen-menu",children:e});ex.displayName="Menu";var tx=()=>{let e=qe();return ft(td,{onSelect:()=>e.executeAction(Ai),shortcut:"?",icon:wa,children:h("helpDialog.title")})};tx.displayName="MenuItemHelp";var ox=()=>{let e=Ee(),t=qe();return e.viewModeEnabled?null:ft(td,{onSelect:()=>t.executeAction(ja),shortcut:Ue("loadScene"),icon:va,children:h("buttons.load")})};ox.displayName="MenuItemLoadScene";var RM=({onSelect:e})=>{let{t}=Oe();return ft(td,{shortcut:null,onSelect:e,icon:Id,children:t("labels.liveCollaboration")})};RM.displayName="MenuItemLiveCollaborationTrigger";Uo.Logo=J1;Uo.Heading=Q1;Uo.Menu=ex;Uo.MenuItem=td;Uo.MenuItemLink=DM;Uo.MenuItemHelp=tx;Uo.MenuItemLoadScene=ox;Uo.MenuItemLiveCollaborationTrigger=RM;import{jsx as tl,jsxs as nx}from"react/jsx-runtime";var Gu=({children:e})=>{let{WelcomeScreenMenuHintTunnel:t}=We();return tl(t.In,{children:nx("div",{className:"excalifont welcome-screen-decor welcome-screen-decor-hint welcome-screen-decor-hint--menu",children:[tE,tl("div",{className:"welcome-screen-decor-hint__label",children:e||h("welcomeScreen.defaults.menuHint")})]})})};Gu.displayName="MenuHint";var Uu=({children:e})=>{let{WelcomeScreenToolbarHintTunnel:t}=We();return tl(t.In,{children:nx("div",{className:"excalifont welcome-screen-decor welcome-screen-decor-hint welcome-screen-decor-hint--toolbar",children:[tl("div",{className:"welcome-screen-decor-hint__label",children:e||h("welcomeScreen.defaults.toolbarHint")}),nE]})})};Uu.displayName="ToolbarHint";var Wu=({children:e})=>{let{WelcomeScreenHelpHintTunnel:t}=We();return tl(t.In,{children:nx("div",{className:"excalifont welcome-screen-decor welcome-screen-decor-hint welcome-screen-decor-hint--help",children:[tl("div",{children:e||h("welcomeScreen.defaults.helpHint")}),oE]})})};Wu.displayName="HelpHint";import{Fragment as BM,jsx as od,jsxs as G$}from"react/jsx-runtime";var Yu=e=>od(BM,{children:e.children||G$(BM,{children:[od(Uo,{}),od(Gu,{}),od(Uu,{}),od(Wu,{})]})});Yu.displayName="WelcomeScreen";Yu.Center=Uo;Yu.Hints={MenuHint:Gu,ToolbarHint:Uu,HelpHint:Wu};var H$=Yu;var U$=()=>{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)})},FM=U$;import{getSceneVersion as wVe,hashElementsVersion as vVe,hashString as TVe,getNonDeletedElements as IVe}from"@orangecatai/element";import{getTextFromElements as kVe}from"@orangecatai/element";import{isInvisiblySmallElement as MVe}from"@orangecatai/element";import W$ from"lodash.throttle";import{arrayToMap as Y$,isDevEnv as zM,isTestEnv as OM}from"@orangecatai/common";import{orderByFractionalIndex as V$,syncInvalidIndices as HM,validateFractionalIndices as K$}from"@orangecatai/element";var X$=(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)),$$=W$((e,t,o)=>{if(zM()||OM()||window?.DEBUG_FRACTIONAL_INDICES){let n=HM(e.map(r=>({...r})));K$(n,{shouldThrow:OM()||zM(),includeBoundTextValidation:!0,reconciliationContext:{localElements:t,remoteElements:o}})}},1e3*60,{leading:!0,trailing:!1}),Z$=(e,t,o)=>{let n=Y$(e),r=[],i=new Set;for(let s of t)if(!i.has(s.id)){let l=n.get(s.id),c=X$(o,l,s);l&&c?(r.push(l),i.add(l.id)):(r.push(s),i.add(s.id))}for(let s of e)i.has(s.id)||(r.push(s),i.add(s.id));let a=V$(r);return $$(a,e,t),HM(a),a};import{isLinearElement as FVe}from"@orangecatai/element";import{FONT_FAMILY as OVe,THEME as QC,MIME_TYPES as HVe,ROUNDNESS as Pm,DEFAULT_LASER_COLOR as GVe,UserIdleState as UVe,normalizeLink as WVe,sceneCoordsToViewportCoords as K2,viewportCoordsToSceneCoords as YVe,getFormFactor as VVe}from"@orangecatai/common";import{mutateElement as Lm,newElementWith as XVe,bumpVersion as as}from"@orangecatai/element";import{CaptureUpdateAction as ZVe}from"@orangecatai/element";import{jsx as rx}from"react/jsx-runtime";var GM=({children:e,icon:t})=>{let{t:o}=Oe(),{TTDDialogTriggerTunnel:n}=We(),r=ve();return rx(n.In,{children:rx(pe.Item,{onSelect:()=>{he("ai","dialog open","ttd"),r({openDialog:{name:"ttd",tab:"text-to-diagram"}})},icon:t??gy,badge:rx(pe.Item.Badge,{children:"AI"}),children:e??o("labels.textToDiagram")})})};GM.displayName="TTDDialogTrigger";function j$(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*q$(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 i=o.split(`
|
|
127
|
+
`);o=i.pop()||"";for(let a of i){let s=a.trim();s&&s.startsWith("data: ")&&(yield s.slice(6))}}}finally{e.releaseLock()}}async function J$(e){let{url:t,messages:o,onChunk:n,onStreamCreated:r,extractRateLimits:i=!0,signal:a}=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:a});if(i&&(l=j$(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 q$(p)){if(d==="[DONE]")break;try{let u=JSON.parse(d);if(u===null)break;switch(u.type){case"content":{let b=u.delta;b&&(s+=b,n?.(b));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 lKe,getVisibleSceneBounds as cKe,convertToExcalidrawElements as ek}from"@orangecatai/element";import{useLayoutEffect as Q$}from"react";var eZ=e=>{let t=Xe();return Q$(()=>{t.setPlugins({diagramToCode:{generate:e.generate}})},[t,e.generate]),null};import{isElementLink as gKe}from"@orangecatai/element";import{setCustomTextMetricsProvider as fKe}from"@orangecatai/element";import HZ,{useCallback as po,useEffect as u6,useImperativeHandle as GZ,useRef as ui,useState as Dt}from"react";import{ArrowUp as UZ,AtSign as g6,Check as h6,ChevronDown as WZ,ChevronRight as YZ,Copy as f6,Globe as VZ,MessageSquare as b6,Mic as KZ,MicOff as XZ,Paperclip as fx,Plus as x6,Search as $Z,Wrench as ZZ,X as bx}from"lucide-react";function ix(e){let t=e?.trim();return(t||void 0)??(typeof import.meta<"u"&&I?.VITE_APP_OPENROUTER_API_KEY?I.VITE_APP_OPENROUTER_API_KEY:"")??""}import{nanoid as tZ}from"nanoid";import{newFrameElement as oZ,newElement as nZ,newTextElement as rZ,newImageElement as iZ,getFrameChildren as Ku,isFrameLikeElement as ax}from"@orangecatai/element";import{FRAME_STYLE as aZ}from"@orangecatai/common";var UM=[{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}}}];function sx(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 WM(e){return e.map(sx)}function YM(e){let t=e.getSceneElements(),o=[];for(let n of t)if(ax(n)){let r=Ku(t,n.id),i=n;o.push({id:n.id,name:i.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 VM(e,t){let o=e.getSceneElements(),n=o.find(s=>s.id===t);if(!n||!ax(n))return null;let r=e.getAppState(),i=e.getFiles(),a=Ku(o,t);try{return(await ca([...a,n],r,i,{exportBackground:!0,viewBackgroundColor:r.viewBackgroundColor,exportingFrame:n,exportPadding:0})).toDataURL("image/jpeg",.7)}catch{return null}}function KM(e,t){let o=e.getSceneElements(),n=o.find(l=>l.id===t);if(!n||!ax(n))return null;let r=Ku(o,t),i=n,a={id:n.id,name:i.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:sx(n),children:WM(r)};return{serialized:JSON.stringify(s,null,2),frameInfo:a}}async function XM(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 cZ(n,o);case"add_rectangle":return dZ(n,o);case"add_text":return mZ(n,o);case"generate_image":return pZ(n,o);case"update_element":return uZ(n,o);case"delete_element":return gZ(n,o);case"get_frame_elements":return hZ(n,o);default:return{success:!1,error:`Unknown tool: ${e}`,statusMessage:`Unknown tool: ${e}`}}}function sZ(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 Vu=10;function lZ(e,t,o,n,r){return Math.abs(e-r.x)<Vu&&Math.abs(t-r.y)<Vu&&Math.abs(o-r.width)<Vu&&Math.abs(n-r.height)<Vu}function $M(e,t,o,n,r,i){return e==="text"?3:e==="image"?1:lZ(t,o,n,r,i)?0:2}function lx(e,t,o){let n=e[t],r=n.id,i=t+1;for(let a=t+1;a<e.length;a++){let s=e[a];if(s.frameId!==r)continue;if($M(s.type,s.x,s.y,s.width,s.height,n)>o)return a;i=a+1}return i}function cZ(e,t){let o=e.width||512,n=e.height||512,r=e.name||null,i=sZ(t.excalidrawAPI),a=oZ({...aZ,x:i.x-o/2,y:i.y-n/2,width:o,height:n,opacity:100,locked:!1,name:r??void 0}),s=t.excalidrawAPI.getSceneElements();return t.excalidrawAPI.updateScene({elements:[...s,a]}),t.excalidrawAPI.scrollToContent(a,{fitToViewport:!1}),{success:!0,data:{frameId:a.id,x:Math.round(a.x),y:Math.round(a.y),width:o,height:n},statusMessage:`Created frame "${r||"Ad Frame"}" (${o}\xD7${n})`}}function dZ(e,t){let o=e.frameId;if(!o)return{success:!1,error:"frameId is required",statusMessage:"Failed: missing frameId"};let n=nZ({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}),r=t.excalidrawAPI.getSceneElements(),i=r.findIndex(d=>d.id===o);if(i===-1)return{success:!1,error:`Frame ${o} not found`,statusMessage:"Failed: frame not found"};let a=r[i],s=$M("rectangle",e.x,e.y,e.width,e.height,a),l={...n,frameId:o},c=[...r],m=lx(c,i,s);c.splice(m,0,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 mZ(e,t){let o=e.frameId;if(!o)return{success:!1,error:"frameId is required",statusMessage:"Failed: missing frameId"};let n=rZ({x:e.x,y:e.y,text:e.text,fontSize:e.fontSize||20,fontFamily:e.fontFamily||2,strokeColor:e.strokeColor||"#000000",textAlign:e.textAlign||"left",width:e.width}),r=t.excalidrawAPI.getSceneElements(),i=r.findIndex(c=>c.id===o);if(i===-1)return{success:!1,error:`Frame ${o} not found`,statusMessage:"Failed: frame not found"};let a={...n,frameId:o},s=[...r],l=lx(s,i,3);return s.splice(l,0,a),t.excalidrawAPI.updateScene({elements:s}),{success:!0,data:{elementId:n.id,type:"text",x:Math.round(n.x),y:Math.round(n.y),text:e.text,fontSize:e.fontSize||20},statusMessage:`Added text "${e.text.slice(0,40)}${e.text.length>40?"\u2026":""}"`}}async function pZ(e,t){let o=e.frameId,n=e.prompt,r=e.x,i=e.y,a=e.width,s=e.height;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"};if(t.excalidrawAPI.getSceneElements().findIndex(p=>p.id===o)===-1)return{success:!1,error:`Frame ${o} not found`,statusMessage:"Failed: frame not found"};let m=a>=s?a/s>1.3?"16:9":"1:1":"9:16";try{let p=await vc(n,"gemini-2.5-flash-image",m,"1K",!1,!1,t.geminiApiKey,void 0,t.signal);if(t.signal?.aborted)return{success:!1,error:"Cancelled",statusMessage:"Image generation cancelled"};let d=tZ(),u=iZ({type:"image",x:r,y:i,width:a,height:s,fileId:d,status:"pending",scale:[1,1]}),b=t.excalidrawAPI.getSceneElements(),g=b.findIndex(w=>w.id===o);if(g===-1)return{success:!1,error:`Frame ${o} was removed during image generation`,statusMessage:"Failed: frame no longer exists"};let E={...u,frameId:o},y=[...b],x=lx(y,g,1);return y.splice(x,0,E),t.excalidrawAPI.updateScene({elements:y}),t.excalidrawAPI.addFiles([{id:d,dataURL:p,mimeType:ul(p),created:Date.now(),lastRetrieved:Date.now()}]),{success:!0,data:{elementId:u.id,type:"image",x:Math.round(r),y:Math.round(i),width:Math.round(a),height:Math.round(s)},statusMessage:`Generated image from prompt "${n.slice(0,50)}${n.length>50?"\u2026":""}"`}}catch(p){let d=p instanceof Error?p.message:"Image generation failed";return{success:!1,error:d,statusMessage:`Image generation failed: ${d}`}}}function uZ(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 i={},a=["x","y","width","height","backgroundColor","strokeColor","opacity","fontSize","text","fillStyle"];for(let s of a)e[s]!==void 0&&(i[s]=e[s]);return Object.keys(i).length===0?{success:!1,error:"No valid properties to update",statusMessage:"Failed: nothing to update"}:i.text!==void 0&&r.type==="text"&&(i.width===void 0||i.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,i),{success:!0,data:{elementId:o,updated:Object.keys(i)},statusMessage:`Updated element (${Object.keys(i).join(", ")})`})}function gZ(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(i=>i.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 hZ(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 i=Ku(n,o),a=WM(i);return{success:!0,data:{frameId:o,frame:sx(r),children:a,childCount:a.length},statusMessage:`Found ${a.length} elements in frame`}}var fZ=`You are an AI ad designer assistant embedded in a canvas editor (Excalidraw-based). You create advertisements, graphics, and visual compositions by calling tools that manipulate canvas elements.
|
|
128
|
+
|
|
129
|
+
## Your Capabilities
|
|
130
|
+
You have tools to: create frames, add rectangles (for backgrounds/shapes), add text, generate AI images, update elements, delete elements, and inspect frame contents.
|
|
131
|
+
|
|
132
|
+
## Design Process
|
|
133
|
+
When asked to create an ad or visual from scratch:
|
|
134
|
+
1. **Create a frame** first (default 512\xD7512 unless the user specifies a size). This is the artboard.
|
|
135
|
+
2. **Add a background** \u2014 use add_rectangle at the frame's exact position and size with a solid fill color. This is the base layer.
|
|
136
|
+
3. **Generate a hero image** \u2014 use generate_image to create the main visual. Position it within the frame. It can be full-bleed (same size/position as frame) or partial.
|
|
137
|
+
4. **Add headline text** \u2014 large, bold text. Position it where it's readable against the background/image. Use contrasting colors (white text on dark images, dark text on light backgrounds).
|
|
138
|
+
5. **Add subhead text** \u2014 smaller supporting text below the headline.
|
|
139
|
+
|
|
140
|
+
## Layout & Z-ordering Rules
|
|
141
|
+
- Elements are rendered in insertion order. Add background rectangle FIRST, then images, then text ON TOP.
|
|
142
|
+
- All element positions use absolute canvas coordinates. The frame's x,y is the top-left corner.
|
|
143
|
+
- To place an element at a frame's top-left: use the frame's x,y values.
|
|
144
|
+
- To center text horizontally in a frame: set text x = frame.x + (frame.width - estimated_text_width) / 2
|
|
145
|
+
- Leave padding from edges (at least 20px from frame borders for text).
|
|
146
|
+
- Headline font size: 28-48px depending on frame size. Subhead: 16-24px.
|
|
147
|
+
|
|
148
|
+
## Color & Typography
|
|
149
|
+
- Use font family 2 (Nunito/clean sans-serif) for professional ads.
|
|
150
|
+
- For dark backgrounds: use white (#ffffff) or light text.
|
|
151
|
+
- For light backgrounds: use dark (#1a1a2e or #000000) text.
|
|
152
|
+
- Popular ad background colors: deep navy (#1a1a2e), warm red (#c0392b), forest green (#27ae60), elegant black (#111111), soft cream (#fdf6e3).
|
|
153
|
+
|
|
154
|
+
## When modifying existing elements (@ context provided)
|
|
155
|
+
- The user may reference existing elements via @ mentions. Their current state will be described in the message.
|
|
156
|
+
- Use get_frame_elements to see the full current state of a frame before making changes.
|
|
157
|
+
- Use update_element to modify properties. Use delete_element to remove things.
|
|
158
|
+
- Preserve existing elements unless explicitly asked to change them.
|
|
159
|
+
|
|
160
|
+
## Image Generation Tips
|
|
161
|
+
- Write detailed, descriptive prompts for generate_image. Include style, mood, composition, colors.
|
|
162
|
+
- Example: "A steaming bowl of creamy pasta on a rustic wooden table, warm golden lighting, top-down view, food photography style, appetizing, high quality"
|
|
163
|
+
- The image will be generated by Gemini AI and placed at the coordinates you specify.
|
|
164
|
+
|
|
165
|
+
## Important
|
|
166
|
+
- Always respond with a brief summary of what you created/modified after completing the tools.
|
|
167
|
+
- If the user's request is unclear, use the available tools to create a reasonable default and explain what you did.
|
|
168
|
+
- Coordinates: frame x,y is the top-left corner. Width extends right, height extends down.`,bZ=15;async function xZ(e,t,o,n){let i={model:n?"openai/gpt-4.1-mini:online":"openai/gpt-4.1-mini",messages:e.map(c=>c.role==="assistant"&&c.tool_calls?{role:c.role,content:c.content,tool_calls:c.tool_calls}:c.role==="tool"?{role:c.role,tool_call_id:c.tool_call_id,content:c.content}:{role:c.role,content:c.content}),tools:UM,tool_choice:"auto"};n&&(i.plugins=[{id:"web",max_results:5}]);let a=await fetch("https://openrouter.ai/api/v1/chat/completions",{method:"POST",signal:o,headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json"},body:JSON.stringify(i)});if(!a.ok){let c=`OpenRouter error ${a.status}`;try{let m=await a.json();m?.error?.message&&(c=m.error.message)}catch{}throw new Error(c)}let l=(await a.json())?.choices?.[0]?.message;if(!l)throw new Error("No response returned by the API.");return{content:l.content??null,tool_calls:l.tool_calls??void 0}}async function ZM(e){let{userMessages:t,elementContext:o,frameScreenshot:n,fileAttachments:r,webSearchEnabled:i,apiKey:a,toolCtx:s,onUpdate:l,signal:c,onBeforeImageGen:m,onAfterImageGen:p}=e,d=[{role:"system",content:fZ}];o&&d.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:
|
|
169
|
+
|
|
170
|
+
${o}`});for(let E=0;E<t.length;E++){let y=t[E],x=E===t.length-1,w=x&&y.role==="user"&&(n||r&&r.some(T=>T.type==="image")),v=x&&y.role==="user"&&r&&r.some(T=>T.type==="text");if(w||v){let T=[];if(n&&T.push({type:"image_url",image_url:{url:n}}),r)for(let M of r)M.type==="image"&&M.dataUrl&&T.push({type:"image_url",image_url:{url:M.dataUrl}});let C=y.content;if(n&&(C=`[Screenshot of the referenced frame is attached above]
|
|
171
|
+
|
|
172
|
+
${C}`),r){let M=r.filter(k=>k.type==="text");M.length>0&&(C+=`
|
|
173
|
+
|
|
174
|
+
${M.map(k=>`[File: ${k.name}]
|
|
175
|
+
${k.textContent}`).join(`
|
|
176
|
+
|
|
177
|
+
`)}`)}T.push({type:"text",text:C}),d.push({role:"user",content:T})}else d.push({role:y.role,content:y.content})}let u=[],b=0;for(;b<bZ;){b++,l({type:"status",message:b===1?"Thinking\u2026":"Processing tool results\u2026"});let E=await xZ(d,a,c,i);if(!E.tool_calls||E.tool_calls.length===0){let y=E.content||"Done!";return l({type:"final",message:y}),{reply:y,toolActions:u}}d.push({role:"assistant",content:E.content,tool_calls:E.tool_calls});for(let y of E.tool_calls){let{name:x,arguments:w}=y.function,v={};try{v=JSON.parse(w)}catch{}if(l({type:"tool_start",message:EZ(x,v)}),x==="generate_image"&&m){let{allowed:M,error:k}=await m();if(!M){let R={success:!1,error:k||"Insufficient credits for image generation",statusMessage:k||"Insufficient credits for image generation"},A={toolName:x,args:v,result:R};u.push(A),l({type:"tool_done",message:R.statusMessage,toolAction:A}),d.push({role:"tool",tool_call_id:y.id,content:JSON.stringify({success:!1,error:R.error})});continue}}let T=await XM(x,w,s);x==="generate_image"&&T.success&&p&&p();let C={toolName:x,args:v,result:T};u.push(C),l({type:"tool_done",message:T.statusMessage,toolAction:C}),d.push({role:"tool",tool_call_id:y.id,content:JSON.stringify(T.success?{success:!0,...T.data}:{success:!1,error:T.error})})}}let g="I've completed the available operations. Let me know if you'd like any adjustments!";return l({type:"final",message:g}),{reply:g,toolActions:u}}function EZ(e,t){switch(e){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 jM(e){let t=await e.arrayBuffer(),o=new AudioContext,n=await o.decodeAudioData(t);await o.close();let r=n.numberOfChannels,i=n.sampleRate,a=n.length,s=2,l=a*r*s,c=44+l,m=new ArrayBuffer(c),p=new DataView(m),d=(y,x)=>{for(let w=0;w<x.length;w++)p.setUint8(y+w,x.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,i,!0),p.setUint32(28,i*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 y=0;y<a;y++)for(let x=0;x<r;x++){let w=n.getChannelData(x)[y],v=Math.max(-1,Math.min(1,w)),T=v<0?v*32768:v*32767;p.setInt16(u,T,!0),u+=2}let b=new Uint8Array(m),g=8192,E="";for(let y=0;y<b.length;y+=g)E+=String.fromCharCode(...b.subarray(y,y+g));return btoa(E)}async function qM(e,t,o){let n=await fetch("https://openrouter.ai/api/v1/chat/completions",{method:"POST",headers:{Authorization:`Bearer ${o}`,"Content-Type":"application/json"},body:JSON.stringify({model:"mistralai/voxtral-small-24b-2507",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(!n.ok){let i=`Transcription error ${n.status}`;try{let a=await n.json();a?.error?.message&&(i=a.error.message)}catch{}throw new Error(i)}return(await n.json())?.choices?.[0]?.message?.content||""}import{StickToBottom as JM}from"use-stick-to-bottom";import{jsx as t6}from"react/jsx-runtime";function QM({children:e,className:t,...o}){return t6(JM,{className:Ye("flex overflow-y-auto",t),resize:"smooth",initial:"instant",role:"log",...o,children:e})}function e6({children:e,className:t,...o}){return t6(JM.Content,{className:Ye("flex w-full flex-col",t),...o,children:e})}import{marked as TZ}from"marked";import{memo as r6,useId as IZ,useMemo as CZ}from"react";import kZ from"react-markdown";import SZ from"remark-breaks";import MZ from"remark-gfm";import{useEffect as yZ,useState as wZ}from"react";import{codeToHtml as vZ}from"shiki";import{jsx as nd}from"react/jsx-runtime";function o6({children:e,className:t,...o}){return nd("div",{className:Ye("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 n6({code:e,language:t="tsx",theme:o="github-light",className:n,...r}){let[i,a]=wZ(null);yZ(()=>{async function l(){if(!e){a("<pre><code></code></pre>");return}let c=await vZ(e,{lang:t,theme:o});a(c)}l()},[e,t,o]);let s=Ye("w-full overflow-x-auto text-[13px] [&>pre]:px-4 [&>pre]:py-4",n);return i?nd("div",{className:s,dangerouslySetInnerHTML:{__html:i},...r}):nd("div",{className:s,...r,children:nd("pre",{children:nd("code",{children:e})})})}import{Fragment as _Z,jsx as oa}from"react/jsx-runtime";function PZ(e){return TZ.lexer(e).map(o=>o.raw)}function AZ(e){if(!e)return"plaintext";let t=e.match(/language-(\w+)/);return t?t[1]:"plaintext"}var i6={code:function({className:t,children:o,...n}){if(!n.node?.position?.start.line||n.node?.position?.start.line===n.node?.position?.end.line)return oa("span",{className:Ye("bg-zinc-50 rounded-sm px-1 font-mono text-sm dark:bg-zinc-900",t),...n,children:o});let i=AZ(t);return oa(o6,{className:t,children:oa(n6,{code:o,language:i})})},pre:function({children:t}){return oa(_Z,{children:t})}},a6=r6(({content:e,components:t=i6})=>oa(kZ,{remarkPlugins:[MZ,SZ],components:t,children:e}),(e,t)=>e.content===t.content);a6.displayName="MemoizedMarkdownBlock";function LZ({children:e,id:t,className:o,components:n=i6}){let r=IZ(),i=t??r,a=CZ(()=>PZ(e),[e]);return oa("div",{className:o,children:a.map((s,l)=>oa(a6,{content:s,components:n},`${i}-block-${l}`))})}var cx=r6(LZ);cx.displayName="Markdown";import*as Xu from"react";import*as mr from"@radix-ui/react-avatar";import{jsx as dx}from"react/jsx-runtime";var s6=Xu.forwardRef(({className:e,...t},o)=>dx(mr.Root,{ref:o,className:Ye("relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",e),...t}));s6.displayName=mr.Root.displayName;var l6=Xu.forwardRef(({className:e,...t},o)=>dx(mr.Image,{ref:o,className:Ye("aspect-square h-full w-full",e),...t}));l6.displayName=mr.Image.displayName;var c6=Xu.forwardRef(({className:e,...t},o)=>dx(mr.Fallback,{ref:o,className:Ye("flex h-full w-full items-center justify-center rounded-full bg-zinc-100 dark:bg-zinc-800",e),...t}));c6.displayName=mr.Fallback.displayName;import{jsx as na,jsxs as DZ}from"react/jsx-runtime";var mx=({children:e,className:t,...o})=>na("div",{className:Ye("flex gap-3",t),...o,children:e});var px=({children:e,markdown:t=!1,className:o,...n})=>{let r=Ye("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?na(cx,{className:r,...n,children:e}):na("div",{className:r,...n,children:e})},ux=({children:e,className:t,...o})=>na("div",{className:Ye("text-zinc-500 flex items-center gap-2 dark:text-zinc-400",t),...o,children:e}),gx=({tooltip:e,children:t,className:o,side:n="top",...r})=>na(Pp,{children:DZ(Ap,{...r,children:[na(Lp,{asChild:!0,children:t}),na(yc,{side:n,className:o,children:e})]})});import{ChevronDown as zZ}from"lucide-react";import{useStickToBottomContext as OZ}from"use-stick-to-bottom";import*as d6 from"react";import{Slot as RZ}from"@radix-ui/react-slot";import{cva as NZ}from"class-variance-authority";import{jsx as FZ}from"react/jsx-runtime";var BZ=NZ("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"}}),hx=d6.forwardRef(({className:e,variant:t,size:o,asChild:n=!1,...r},i)=>FZ(n?RZ:"button",{className:Ye(BZ({variant:t,size:o,className:e})),ref:i,...r}));hx.displayName="Button";import{jsx as m6}from"react/jsx-runtime";function p6({className:e,variant:t="outline",size:o="sm",...n}){let{isAtBottom:r,scrollToBottom:i}=OZ();return m6(hx,{variant:t,size:o,className:Ye("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:()=>i(),...n,children:m6(zZ,{className:"h-5 w-5"})})}import{jsx as K,jsxs as _e}from"react/jsx-runtime";function ol(){return Math.random().toString(36).slice(2,10)}var $u=3,jZ=10*1024*1024,qZ=["Create a pasta ad","Design a sale banner","Make a product showcase","Help me design"],E6=HZ.forwardRef(({isOpen:e,onClose:t,apiKey:o,excalidrawAPI:n,geminiApiKey:r,initialMessages:i,initialSessionId:a,initialSessions:s,onMessagesChange:l,onSessionCreate:c,onSessionSwitch:m,onBeforeSend:p,onAfterSend:d,onBeforeImageGen:u,onAfterImageGen:b},g)=>{let[E,y]=Dt(""),[x,w]=Dt(!1),[v,T]=Dt(""),[C,M]=Dt(i??[]),[k,R]=Dt(s??[]),[A,P]=Dt(a??ol),[_,O]=Dt(!1),[U,H]=Dt(""),[W,D]=Dt(null),[F,X]=Dt(null),[te,$]=Dt(!1),[ae,xe]=Dt([]),[re,we]=Dt([]),[Fe,mt]=Dt(!1),[ct,Ot]=Dt(!1),[uo,pr]=Dt(!1),[Hn,ur]=Dt(null),oe=ui(null),Se=ui(null),Tt=ui(null),Z=ui(null),de=ui(null),tt=ui([]),bt=ui(""),gr=ui(!1);u6(()=>{let V=Ve=>{oe.current&&!oe.current.contains(Ve.target)&&O(!1),Tt.current&&!Tt.current.contains(Ve.target)&&$(!1)};return document.addEventListener("mousedown",V),()=>document.removeEventListener("mousedown",V)},[]),u6(()=>{e||Se.current?.abort()},[e]);let Zu=C.length>0?C[0].content.slice(0,30)+(C[0].content.length>30?"\u2026":""):"New chat",Gn=po(()=>{if(C.length===0)return;let V=C[0].content.slice(0,40)+(C[0].content.length>40?"\u2026":"");R(Ve=>{let ot=Ve.findIndex(Pe=>Pe.id===A),Rt={id:A,title:V,messages:C};if(ot>=0){let Pe=[...Ve];return Pe[ot]=Rt,Pe}return[Rt,...Ve]})},[C,A]),nl=po(()=>{Gn();let V=ol();M([]),P(V),O(!1),D(null),y(""),X(null),we([]),T(""),c&&c({id:V,title:"New chat"})},[Gn,c]),w6=po(V=>{Gn(),M(V.messages),P(V.id),O(!1),D(null),m&&m(V.id)},[Gn,m]),v6=po(V=>{let Ve=bt.current;y(V),bt.current=V,n&&V.length>Ve.length&&V.endsWith("@")&&(xe(YM(n)),$(!0))},[n]),T6=po(async V=>{if(!n)return;$(!1),y(Pe=>{let It=Pe.lastIndexOf("@");return It>=0?Pe.slice(0,It):Pe});let Ve=bt.current.lastIndexOf("@");bt.current=Ve>=0?bt.current.slice(0,Ve):bt.current;let ot=KM(n,V.id);if(!ot)return;let Rt=await VM(n,V.id);X({frameId:V.id,label:ot.frameInfo.name,serialized:ot.serialized,screenshot:Rt??void 0})},[n]),I6=po(()=>{X(null)},[]),C6=po(V=>{let Ve=V.target.files;if(!Ve)return;let ot=$u-re.length;if(ot<=0)return;let Rt=Array.from(Ve).slice(0,ot);for(let Pe of Rt){if(Pe.size>jZ){D(`"${Pe.name}" is too large (max 10 MB).`);continue}let It=ol(),ra=Pe.type.startsWith("image/"),Wo=new FileReader;ra?(Wo.onload=()=>{we(go=>go.length<$u?[...go,{id:It,file:Pe,name:Pe.name,type:"image",dataUrl:Wo.result}]:go)},Wo.readAsDataURL(Pe)):(Wo.onload=()=>{we(go=>go.length<$u?[...go,{id:It,file:Pe,name:Pe.name,type:"text",textContent:Wo.result}]:go)},Wo.readAsText(Pe))}Z.current&&(Z.current.value="")},[re.length]),k6=po(V=>{we(Ve=>Ve.filter(ot=>ot.id!==V))},[]),S6=po(()=>{mt(V=>!V)},[]),M6=po(async()=>{if(ct){de.current?.stop(),Ot(!1),gr.current=!0;return}let V=null;try{V=await navigator.mediaDevices.getUserMedia({audio:!0});let Ve=MediaRecorder.isTypeSupported("audio/webm")?"audio/webm":"audio/mp4",ot=new MediaRecorder(V,{mimeType:Ve});de.current=ot,tt.current=[],ot.ondataavailable=Rt=>{Rt.data.size>0&&tt.current.push(Rt.data)},ot.onstop=async()=>{V?.getTracks().forEach(It=>It.stop());let Rt=new Blob(tt.current,{type:ot.mimeType}),Pe=ix(o);if(!Pe){D("No API key for voice transcription.");return}pr(!0),T("Transcribing\u2026");try{let It=await jM(Rt),ra=await qM(It,"wav",Pe),Wo=(bt.current?`${bt.current} `:"")+ra;bt.current=Wo,y(Wo)}catch(It){D(It instanceof Error?It.message:"Transcription failed")}finally{pr(!1),T("")}},ot.start(),Ot(!0)}catch{V?.getTracks().forEach(Ve=>Ve.stop()),D("Could not access microphone. Check browser permissions.")}},[ct,o]),Ex=po((V,Ve)=>{navigator.clipboard.writeText(Ve).then(()=>{ur(V),setTimeout(()=>ur(null),2e3)},()=>{D("Copy failed \u2014 please grant clipboard permission.")})},[]),rd=po(async V=>{let Ve=(V??E).trim(),ot=ix(o);if(!Ve||x)return;if(!ot){D("No OpenRouter API key. Set VITE_APP_OPENROUTER_API_KEY in .env or pass the key via the `apiKey` prop.");return}let Rt=gr.current;if(gr.current=!1,p){let{allowed:xt,error:rl}=await p({hasVoice:Rt});if(!xt){D(rl||"Insufficient credits");return}}let Pe=[...re],It=Fe,ra=F,Wo={id:ol(),role:"user",content:Ve,timestamp:new Date,attachments:Pe.length>0?Pe.map(xt=>({name:xt.name,type:xt.type,dataUrl:xt.dataUrl})):void 0},go=[...C,Wo];M(go),y(""),bt.current="",we([]),X(null);let id=new AbortController;if(Se.current=id,w(!0),D(null),T("Thinking\u2026"),!n){try{let xt=await QZ(go,ot,id.signal,{webSearchEnabled:It,attachments:Pe}),rl={id:ol(),role:"assistant",content:xt,timestamp:new Date},il=[...go,rl];M(il),d&&d({hasVoice:Rt}),l&&l(il,A)}catch(xt){xt instanceof Error&&xt.name!=="AbortError"&&D(xt.message)}finally{Se.current=null,w(!1),T("")}return}try{let xt=await ZM({userMessages:go.map(sn=>({role:sn.role,content:sn.content})),elementContext:ra?.serialized,frameScreenshot:ra?.screenshot,fileAttachments:Pe.length>0?Pe.map(sn=>({name:sn.name,type:sn.type,dataUrl:sn.dataUrl,textContent:sn.textContent})):void 0,webSearchEnabled:It,apiKey:ot,toolCtx:{excalidrawAPI:n,geminiApiKey:r||"",signal:id.signal},onUpdate:sn=>{sn.type!=="final"&&T(sn.message)},signal:id.signal,onBeforeImageGen:u,onAfterImageGen:b}),rl={id:ol(),role:"assistant",content:xt.reply,timestamp:new Date,toolActions:xt.toolActions.length>0?xt.toolActions:void 0},il=[...go,rl];M(il),d&&d({hasVoice:Rt}),l&&l(il,A)}catch(xt){xt instanceof Error&&xt.name!=="AbortError"&&D(xt.message)}finally{Se.current=null,w(!1),T("")}},[E,x,C,o,n,r,F,re,Fe,A,p,d,l,u,b]);GZ(g,()=>({setMessages:M,send:V=>rd(V)}),[M,rd]);let P6=po(()=>{Se.current?.abort()},[]),A6=po(V=>{y(V)},[]),yx=k.filter(V=>U?V.title.toLowerCase().includes(U.toLowerCase()):!0);return e?K("div",{className:"acp",onPointerDown:V=>V.stopPropagation(),onClick:V=>V.stopPropagation(),children:_e("div",{className:"acp-panel",children:[_e("div",{className:"acp-header",ref:oe,children:[_e("button",{className:"acp-title-btn",onClick:()=>O(V=>!V),title:"Chat history",children:[K("span",{children:Zu}),K(WZ,{size:13})]}),_e("div",{className:"acp-header-right",children:[K("button",{className:"acp-icon-btn",onClick:nl,title:"New chat",children:K(x6,{size:15})}),K("button",{className:"acp-icon-btn",onClick:t,title:"Close",children:K(bx,{size:15})})]}),_&&_e("div",{className:"acp-history-dropdown",children:[_e("div",{className:"acp-history-search",children:[K($Z,{size:13}),K("input",{type:"search",placeholder:"Search chats\u2026",value:U,onChange:V=>H(V.target.value),autoFocus:!0})]}),_e("div",{className:"acp-history-list",children:[_e("button",{className:"acp-history-item acp-history-item--new",onClick:nl,children:[K(x6,{size:13}),K("span",{children:"New chat"})]}),yx.map(V=>_e("button",{className:"acp-history-item",onClick:()=>w6(V),children:[K(b6,{size:13}),K("span",{children:V.title})]},V.id)),yx.length===0&&U&&K("div",{className:"acp-history-empty",children:"No matching chats"})]})]})]}),K("div",{className:"acp-messages-wrap",children:C.length===0&&!x?_e("div",{className:"acp-empty",children:[K("div",{className:"acp-empty-icon",children:K(b6,{size:22})}),_e("div",{children:[K("div",{className:"acp-empty-title",children:"AI Ad Designer"}),K("div",{className:"acp-empty-sub",children:"Describe an ad and I'll create it on the canvas. Type @ to reference frames."})]}),K("div",{className:"acp-chips",children:qZ.map(V=>K("button",{className:"acp-chip",onClick:()=>A6(V),children:V},V))})]}):_e(QM,{className:"acp-chat-root",children:[_e(e6,{className:"acp-chat-content",children:[C.map((V,Ve)=>{let ot=V.role==="assistant",Rt=Ve===C.length-1;return K(mx,{className:`acp-msg ${ot?"acp-msg--assistant":"acp-msg--user"}`,children:ot?_e("div",{className:"acp-msg-inner",children:[V.toolActions&&V.toolActions.length>0&&K(JZ,{actions:V.toolActions}),K(px,{markdown:!0,className:"acp-content-assistant",children:V.content}),K(ux,{className:`acp-msg-actions${Rt?" acp-msg-actions--visible":""}`,children:K(gx,{tooltip:"Copy",delayDuration:100,children:K("button",{className:"acp-action-btn",onClick:()=>Ex(V.id,V.content),children:Hn===V.id?K(h6,{size:14}):K(f6,{size:14})})})})]}):_e("div",{className:"acp-msg-inner",children:[V.attachments&&V.attachments.length>0&&K("div",{className:"acp-msg-attachments",children:V.attachments.map((Pe,It)=>Pe.type==="image"&&Pe.dataUrl?K("img",{src:Pe.dataUrl,alt:Pe.name,className:"acp-msg-att-thumb",title:Pe.name},It):_e("span",{className:"acp-msg-att-pill",children:[K(fx,{size:11}),Pe.name]},It))}),K(px,{className:"acp-content-user",children:V.content}),K(ux,{className:"acp-msg-actions",children:K(gx,{tooltip:"Copy",delayDuration:100,children:K("button",{className:"acp-action-btn",onClick:()=>Ex(V.id,V.content),children:Hn===V.id?K(h6,{size:14}):K(f6,{size:14})})})})]})},V.id)}),x&&K(mx,{className:"acp-msg acp-msg--assistant",children:K("div",{className:"acp-msg-inner",children:_e("div",{className:"acp-status-indicator",children:[_e("div",{className:"acp-loading-dots",children:[K("span",{}),K("span",{}),K("span",{})]}),v&&K("span",{className:"acp-status-text",children:v})]})})})]}),K("div",{className:"acp-scroll-anchor",children:K(p6,{className:"acp-scroll-btn"})})]})}),W&&K("div",{className:"acp-error",children:W}),F&&K("div",{className:"acp-ref-area",children:_e("div",{className:"acp-ref-pill",children:[K(g6,{size:12}),K("span",{children:F.label}),K("button",{className:"acp-ref-remove",onClick:I6,title:"Remove reference",children:K(bx,{size:10})})]})}),re.length>0&&K("div",{className:"acp-attachments-area",children:re.map(V=>_e("div",{className:"acp-attachment-pill",children:[V.type==="image"&&V.dataUrl?K("img",{src:V.dataUrl,alt:V.name,className:"acp-attachment-thumb"}):K(fx,{size:12}),K("span",{children:V.name}),K("button",{className:"acp-attachment-remove",onClick:()=>k6(V.id),title:"Remove file",children:K(bx,{size:10})})]},V.id))}),K("div",{className:"acp-input-area",children:_e("div",{className:"acp-input-wrapper",ref:Tt,children:[te&&K("div",{className:"acp-mention-menu",children:ae.length>0?ae.map(V=>_e("button",{className:"acp-mention-item",onClick:()=>T6(V),children:[K(g6,{size:14}),_e("span",{children:[V.name," ",_e("span",{className:"acp-mention-dim",children:["(",V.width,"x",V.height,", ",V.childCount," items)"]})]})]},V.id)):K("div",{className:"acp-mention-empty",children:"No frames on the canvas. Create a frame first, then type @ to reference it."})}),K("input",{ref:Z,type:"file",multiple:!0,accept:"image/*,.txt,.json,.csv,.md,.html,.css,.js,.ts,.tsx,.jsx,.py,.xml",onChange:C6,style:{display:"none"}}),_e(Ms,{isLoading:x,value:E,onValueChange:v6,onSubmit:()=>rd(),className:"acp-prompt-input",children:[K(Ps,{placeholder:n?"Describe an ad to create\u2026 (@ for frames)":"Ask anything",className:"acp-textarea"}),_e(As,{className:"acp-actions-bar",children:[_e("div",{className:"acp-actions-left",children:[K(rr,{tooltip:"Attach files (max 3)",children:K("button",{className:"acp-pill-btn acp-pill-btn--icon",onClick:()=>Z.current?.click(),disabled:re.length>=$u,children:K(fx,{size:16})})}),K(rr,{tooltip:Fe?"Web search enabled":"Enable web search",children:_e("button",{className:`acp-pill-btn${Fe?" acp-pill-btn--active":""}`,onClick:S6,children:[K(VZ,{size:15}),K("span",{children:"Search"})]})})]}),_e("div",{className:"acp-actions-right",children:[K(rr,{tooltip:uo?"Transcribing\u2026":ct?"Stop recording":"Voice input",children:K("button",{className:`acp-pill-btn acp-pill-btn--icon${ct?" acp-pill-btn--recording":""}${uo?" acp-pill-btn--transcribing":""}`,onClick:M6,disabled:uo,children:uo?K("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:K("path",{d:"M21 12a9 9 0 1 1-6.219-8.56"})}):ct?K(XZ,{size:16}):K(KZ,{size:16})})}),K("button",{className:"acp-send-btn",onClick:x?P6:()=>rd(),disabled:!x&&!E.trim(),title:x?"Stop":"Send",children:x?K("span",{className:"acp-stop-square"}):K(UZ,{size:16})})]})]})]})]})})]})}):null});E6.displayName="AIChatPanel";function JZ({actions:e}){let[t,o]=Dt(!1);return _e("div",{className:"acp-tool-actions",children:[_e("button",{className:"acp-tool-actions-toggle",onClick:()=>o(n=>!n),children:[K(ZZ,{size:13}),_e("span",{children:[e.length," action",e.length!==1?"s":""," performed"]}),K(YZ,{size:12,className:`acp-tool-chevron ${t?"acp-tool-chevron--open":""}`})]}),t&&K("div",{className:"acp-tool-actions-list",children:e.map((n,r)=>_e("div",{className:`acp-tool-action-item ${n.result.success?"acp-tool-action-item--ok":"acp-tool-action-item--err"}`,children:[K("span",{className:"acp-tool-action-dot"}),K("span",{children:n.result.statusMessage})]},r))})]})}async function QZ(e,t,o,n){let r=n?.webSearchEnabled?"openai/gpt-4.1-mini:online":"openai/gpt-4.1-mini",i=e.map((m,p)=>{if(p===e.length-1&&m.role==="user"&&n?.attachments?.length){let u=[];for(let E of n.attachments)E.type==="image"&&E.dataUrl&&u.push({type:"image_url",image_url:{url:E.dataUrl}});let b=m.content,g=n.attachments.filter(E=>E.type==="text");return g.length>0&&(b+=`
|
|
178
|
+
|
|
179
|
+
${g.map(E=>`[File: ${E.name}]
|
|
180
|
+
${E.textContent}`).join(`
|
|
124
181
|
|
|
125
|
-
`),
|
|
126
|
-
`),g=b.reduce((E,w,x)=>{let y=aK(w).trim();if(y.length){let v=this.getTopLayerFrameAtSceneCoords({x:r,y:u}),T=ok(y,s,l),C=T.width>p,M=C?nK(y,s,p):y;T=C?ok(M,s,l):T;let S=r-T.width/2,D=u-T.height/2,_=U4({...a,x:S,y:D,text:M,originalText:y,lineHeight:l,autoResize:!C,frameId:v?v.id:null});E.push(_),u+=_.height+d}else b[x-1]?.trim()&&(u+=sK(a.fontSize,l)+d);return E},[]);g.length!==0&&(this.scene.insertElements(g),this.store.scheduleCapture(),this.setState({selectedElementIds:Pe(Object.fromEntries(g.map(E=>[E.id,!0])),this.state)}),!n&&g.length>1&&bk===!1&&this.editorInterface.formFactor!=="phone"&&(this.setToast({message:h("toast.pasteAsSingleElement",{shortcut:N("CtrlOrCmd+Shift+V")}),duration:5e3}),bk=!0))}handleTextWysiwyg(t,{isExistingElement:n=!1}){let r=this.scene.getElementsMapIncludingDeleted(),i=(a,s)=>{this.scene.replaceAllElements([...this.scene.getElementsIncludingDeleted().map(l=>l.id===t.id&&Ho(l)?Fr(l,{originalText:a,isDeleted:s??l.isDeleted,...AV(l,q4(l,r),r,a)}):l)])};cI({id:t.id,canvas:this.canvas,getViewportCoords:(a,s)=>{let{x:l,y:c}=$p({sceneX:a,sceneY:s},this.state);return[l-this.state.offsetLeft,c-this.state.offsetTop]},onChange:Ze(a=>{i(a,!1),ck(t)&&Jp(t,this.scene)}),onSubmit:Ze(({viaKeyboard:a,nextOriginalText:s})=>{let l=!s.trim();if(i(s,l),!l&&a){let c=t.containerId?t.containerId:t.id;Xt(()=>{this.setState(m=>({selectedElementIds:Pe({...m.selectedElementIds,[c]:!0},m)}))})}l&&IV(this.scene.getNonDeletedElements(),[t]),(!l||n)&&this.store.scheduleCapture(),Xt(()=>{this.setState({newElement:null,editingTextElement:null})}),this.state.activeTool.locked&&Qt(this.interactiveCanvas,this.state),this.focusContainer()}),element:t,excalidrawContainer:this.excalidrawContainerRef.current,app:this,autoSelect:!this.editorInterface.isTouchScreen}),this.deselectElements(),i(t.originalText,!1)}deselectElements(){this.setState({selectedElementIds:Pe({},this.state),selectedGroupIds:{},editingGroupId:null,activeEmbeddable:null})}getTextElementAtPosition(t,n){let r=this.getElementAtPosition(t,n,{includeBoundTextElement:!0});return r&&Ho(r)&&!r.isDeleted?r:null}getElementAtPosition(t,n,r){let i=[];if(r&&"allHitElements"in r?i=r?.allHitElements||[]:i=this.getElementsAtPosition(t,n,{includeBoundTextElement:r?.includeBoundTextElement,includeLockedElements:r?.includeLockedElements}),i.length>1){if(r?.preferSelected){for(let s=i.length-1;s>-1;s--)if(this.state.selectedElementIds[i[s].id])return i[s]}let a=i[i.length-1];return sc({point:ie(t,n),element:a,threshold:this.getElementHitThreshold(a)/2,elementsMap:this.scene.getNonDeletedElementsMap(),frameNameBound:Lt(a)?this.frameNameBoundsCache.get(a):null})?a:i[i.length-2]}return i.length===1?i[0]:null}getElementsAtPosition(t,n,r){let i=[],a=this.scene.getNonDeletedElementsMap();return(r?.includeBoundTextElement&&r?.includeLockedElements?this.scene.getNonDeletedElements():this.scene.getNonDeletedElements().filter(l=>(r?.includeLockedElements||!l.locked)&&(r?.includeBoundTextElement||!(Ho(l)&&l.containerId)))).filter(l=>this.hitElement(t,n,l)).filter(l=>{let c=$0(l,a);return c&&this.state.frameRendering.enabled&&this.state.frameRendering.clip?J4({x:t,y:n},c,a):!0}).filter(l=>Es(l)?(i.push(l),!1):!0).concat(i)}getElementHitThreshold(t){return Math.max(t.strokeWidth/2+.1,.85*(A4/this.state.zoom.value))}hitElement(t,n,r,i=!0){return i&&this.state.selectedElementIds[r.id]&&WV([r],this.state,this.editorInterface)&&IK(ie(t,n),r,this.scene.getNonDeletedElementsMap(),this.getElementHitThreshold(r))||qV(ie(t,n),r,this.scene.getNonDeletedElementsMap())?!0:sc({point:ie(t,n),element:r,threshold:this.getElementHitThreshold(r),elementsMap:this.scene.getNonDeletedElementsMap(),frameNameBound:Lt(r)?this.frameNameBoundsCache.get(r):null})}getTextBindableContainerAtPosition(t,n){let r=this.scene.getNonDeletedElements(),i=this.scene.getSelectedElements(this.state);if(i.length===1)return V4(i[0],!1)?i[0]:null;let a=null;for(let s=r.length-1;s>=0;--s){if(r[s].isDeleted)continue;let[l,c,m,p]=qp(r[s],this.scene.getNonDeletedElementsMap());if(xs(r[s])&&sc({point:ie(t,n),element:r[s],elementsMap:this.scene.getNonDeletedElementsMap(),threshold:this.getElementHitThreshold(r[s])})){a=r[s];break}else if(l<t&&t<m&&c<n&&n<p){a=r[s];break}}return V4(a,!1)?a:null}handleHoverSelectedLinearElement(t,n,r){let i=this.scene.getNonDeletedElementsMap(),a=ve.getElement(t.elementId,i);if(a)if(this.state.selectedLinearElement){let s=-1,l=null;sc({point:ie(n,r),element:a,elementsMap:i,threshold:this.getElementHitThreshold(a)})?(s=ve.getPointIndexUnderCursor(a,i,this.state.zoom,n,r),l=ve.getSegmentMidpointHitCoords(t,{x:n,y:r},this.state,this.scene.getNonDeletedElementsMap()),($t(a)?s===0||s===a.points.length-1:s>=0)||l?Se(this.interactiveCanvas,Ke.POINTER):this.hitElement(n,r,a)&&(!$t(a)||!(a.startBinding||a.endBinding))&&(this.state.activeTool.type!=="lasso"||Object.keys(this.state.selectedElementIds).length>0)&&Se(this.interactiveCanvas,Ke.MOVE)):this.hitElement(n,r,a)&&(!$t(a)||!(a.startBinding||a.endBinding))&&(this.state.activeTool.type!=="lasso"||Object.keys(this.state.selectedElementIds).length>0)&&Se(this.interactiveCanvas,Ke.MOVE),this.state.selectedLinearElement.hoverPointIndex!==s&&this.setState({selectedLinearElement:{...this.state.selectedLinearElement,hoverPointIndex:s}}),ve.arePointsEqual(this.state.selectedLinearElement.segmentMidPointHoveredCoords,l)||this.setState({selectedLinearElement:{...this.state.selectedLinearElement,segmentMidPointHoveredCoords:l}});let c=null,m=a;(m.startBinding||m.endBinding)&&(c=PK(a,n,r,this.scene,this.state)),this.state.selectedLinearElement.hoveredFocusPointBinding!==c&&this.setState({selectedLinearElement:{...this.state.selectedLinearElement,isDragging:!1,hoveredFocusPointBinding:c}}),c&&Se(this.interactiveCanvas,Ke.POINTER)}else Se(this.interactiveCanvas,Ke.AUTO)}updateGestureOnPointerDown(t){Ce.pointers.set(t.pointerId,{x:t.clientX,y:t.clientY}),Ce.pointers.size===2&&(Ce.lastCenter=Df(Ce.pointers),Ce.initialScale=this.state.zoom.value,Ce.initialDistance=_f(Array.from(Ce.pointers.values())))}initialPointerDownState(t){let n=Ue(t,this.state),r=this.scene.getSelectedElements(this.state),[i,a,s,l]=bs(r),c=r.findIndex($t)===0;return{origin:n,withCmdOrCtrl:t[j.CTRL_OR_CMD],originInGrid:D0(Pt(n.x,n.y,t[j.CTRL_OR_CMD]||c?null:this.getEffectiveGridSize())),scrollbars:t1(pc,t.clientX-this.state.offsetLeft,t.clientY-this.state.offsetTop),lastCoords:{...n},originalElements:this.scene.getNonDeletedElements().reduce((m,p)=>(m.set(p.id,W4(p)),m),new Map),resize:{handleType:!1,isResizing:!1,offset:{x:0,y:0},arrowDirection:"origin",center:{x:(s+i)/2,y:(l+a)/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(t,n){if(!(n.scrollbars.isOverEither&&!this.state.multiElement))return!1;tb=!0,n.lastCoords.x=t.clientX,n.lastCoords.y=t.clientY;let r=qm(a=>{a.target instanceof HTMLElement&&this.handlePointerMoveOverScrollbars(a,n)}),i=Ze(()=>{gc=null,tb=!1,Qt(this.interactiveCanvas,this.state),this.setState({cursorButton:"up"}),this.savePointer(t.clientX,t.clientY,"up"),window.removeEventListener(ce.POINTER_MOVE,r),window.removeEventListener(ce.POINTER_UP,i),r.flush()});return gc=i,window.addEventListener(ce.POINTER_MOVE,r),window.addEventListener(ce.POINTER_UP,i),!0}isASelectedElement(t){return t!=null&&this.state.selectedElementIds[t.id]}isHittingCommonBoundingBoxOfSelectedElements(t,n){if(n.length<2)return!1;let r=Math.max(A4/this.state.zoom.value,1),[i,a,s,l]=bs(n);return t.x>i-r&&t.x<s+r&&t.y>a-r&&t.y<l+r}getCurrentItemRoundness(t){return this.state.currentItemRoundness==="round"?{type:RV(t)?Vp.ADAPTIVE_RADIUS:Vp.PROPORTIONAL_RADIUS}:null}maybeCacheReferenceSnapPoints(t,n,r=!1){Nn({event:t,app:this,selectedElements:n})&&(r||!go.getReferenceSnapPoints())&&go.setReferenceSnapPoints(A3(this.scene.getNonDeletedElements(),n,this.state,this.scene.getNonDeletedElementsMap()))}maybeCacheVisibleGaps(t,n,r=!1){Nn({event:t,app:this,selectedElements:n})&&(r||!go.getVisibleGaps())&&go.setVisibleGaps(L3(this.scene.getNonDeletedElements(),n,this.state,this.scene.getNonDeletedElementsMap()))}onKeyDownFromPointerDownHandler(t){return Ze(n=>{this.maybeHandleResize(t,n)||this.maybeDragNewGenericElement(t,n)})}onKeyUpFromPointerDownHandler(t){return Ze(n=>{n.key===j.ALT&&n.preventDefault(),!this.maybeHandleResize(t,n)&&this.maybeDragNewGenericElement(t,n)})}onPointerMoveFromPointerDownHandler(t){return qm(n=>{if(this.state.openDialog?.name==="elementLinkSelector")return;let r=Ue(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]=Pt(r.x,r.y,n[j.CTRL_OR_CMD]?null:this.getEffectiveGridSize()),b=this.state.selectedLinearElement.initialState.segmentMidpoint.index;if(b<0){let E=ve.getSegmentMidpointHitCoords({...this.state.selectedLinearElement,segmentMidPointHoveredCoords:null},{x:d,y:u},this.state,this.scene.getNonDeletedElementsMap());b=E?ve.getSegmentMidPointIndex(this.state.selectedLinearElement,this.state,E,this.scene.getNonDeletedElementsMap()):-1}let g=ve.moveFixedSegment(this.state.selectedLinearElement,b,d,u,this.scene);this.setState({selectedLinearElement:{...this.state.selectedLinearElement,isDragging:!0,segmentMidPointHoveredCoords:g.segmentMidPointHoveredCoords,initialState:g.initialState}});return}let i=this.previousPointerMoveCoords??t.origin;if(this.previousPointerMoveCoords=r,t.drag.offset===null&&(t.drag.offset=D0(vK(this.scene.getSelectedElements(this.state),t.origin.x,t.origin.y))),!(n.target instanceof HTMLElement)||this.handlePointerMoveOverScrollbars(n,t))return;if(Gt(this.state)){this.handleEraser(n,r);return}this.state.activeTool.type==="laser"&&this.laserTrails.addPointToPath(r.x,r.y);let[s,l]=Pt(r.x,r.y,n[j.CTRL_OR_CMD]?null:this.getEffectiveGridSize());if(t.resize.isResizing&&(t.lastCoords.x=r.x,t.lastCoords.y=r.y,this.maybeHandleCrop(t,n)||this.maybeHandleResize(t,n)))return!0;let c=this.scene.getNonDeletedElementsMap();if(this.state.selectedLinearElement){let d=this.state.selectedLinearElement;if(d.draggedFocusPointBinding){MK(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(ve.shouldAddMidpoint(this.state.selectedLinearElement,r,this.state,c)){let u=ve.addMidpoint(this.state.selectedLinearElement,r,this,!n[j.CTRL_OR_CMD],this.scene);if(!u)return;Xt(()=>{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=ve.getElement(d.elementId,c);if(u?.isDeleted)return;if(xn(u)){let g=zo(ie(r.x,r.y),this.scene.getNonDeletedElements(),c);Un("COMPLEX_BINDINGS")&&this.handleDelayedBindModeChange(u,g)}if(n.altKey&&!this.state.selectedLinearElement?.initialState?.arrowStartIsInside&&Un("COMPLEX_BINDINGS")&&this.handleSkipBindMode(),d.initialState.lastClickedPoint===-1)return;let b=ve.handlePointDragging(n,this,r.x,r.y,d);if(b){t.lastCoords.x=r.x,t.lastCoords.y=r.y,t.drag.hasOccurred=!0,(b.suggestedBinding!==this.state.suggestedBinding||!B4(b.selectedLinearElement?.selectedPointsIndices??[],this.state.selectedLinearElement?.selectedPointsIndices??[])||b.selectedLinearElement?.hoverPointIndex!==this.state.selectedLinearElement?.hoverPointIndex||b.selectedLinearElement?.customLineAngle!==this.state.selectedLinearElement?.customLineAngle||this.state.selectedLinearElement.isDragging!==b.selectedLinearElement?.isDragging||this.state.selectedLinearElement?.initialState?.altFocusPoint!==b.selectedLinearElement?.initialState?.altFocusPoint)&&this.setState(b);return}}}}let m=t.hit.allHitElements.some(d=>this.isASelectedElement(d)),p=this.state.selectedLinearElement?.isEditing&&n.shiftKey&&this.state.selectedLinearElement.elementId===t.hit.element?.id;if((m||t.hit.hasHitCommonBoundingBoxOfSelectedElements)&&!p&&!t.drag.blockDragging){let d=this.scene.getSelectedElements(this.state);if(d.length>0&&d.every(E=>E.locked))return;let u=d.find(E=>Lt(E)),b=this.getTopLayerFrameAtSceneCoords(r),g=b&&!u?b:null;if(this.state.frameToHighlight!==g&&Xt(()=>{this.setState({frameToHighlight:g})}),t.drag.hasOccurred=!0,this.state.activeTool.type==="lasso"&&this.lassoTrail.hasCurrentTrail&&!(this.editorInterface.formFactor!=="desktop"&&t.hit.element)&&!this.state.activeTool.fromSelection)return;if(this.state.activeTool.type==="lasso"&&d.length>0&&t.drag.hasOccurred&&!this.state.activeTool.fromSelection&&this.lassoTrail.endPath(),d.length>0&&!t.withCmdOrCtrl&&!this.state.editingTextElement&&this.state.activeEmbeddable?.state!=="active"){let E={x:r.x-t.drag.origin.x,y:r.y-t.drag.origin.y},w=[...t.originalElements.values()],x=n.shiftKey;if(x){let T=Math.abs(E.x),C=Math.abs(E.y),M=x&&T<C,S=x&&T>C;M&&(E.x=0),S&&(E.y=0)}if(this.state.croppingElementId){let T=this.scene.getNonDeletedElementsMap().get(this.state.croppingElementId);if(T&&Or(T)&&T.crop!==null&&t.hit.element===T){let C=T.crop,M=ac(T)&&this.imageCache.get(T.fileId)?.image;if(M&&!(M instanceof Promise)){let S=DK(T),D=y4(r.x-i.x,r.y-i.y);D[0]*=M.naturalWidth/S.width,D[1]*=M.naturalHeight/S.height;let[_,P,A,z,V,G]=qp(T,c),Y=M0(k0(ie(_,P),ie(V,G),T.angle)),R=M0(k0(ie(A,P),ie(V,G),T.angle)),F=M0(k0(ie(_,z),ie(V,G),T.angle)),K=T4(w4(R,Y)),J=T4(w4(F,Y)),Z=y4(v4(D,K),v4(D,J)),le={...C,x:E4(C.x-Z[0]*Math.sign(T.scale[0]),0,M.naturalWidth-C.width),y:E4(C.y-Z[1]*Math.sign(T.scale[1]),0,M.naturalHeight-C.height)};this.scene.mutateElement(T,{crop:le});return}}}this.maybeCacheVisibleGaps(n,d),this.maybeCacheReferenceSnapPoints(n,d);let{snapOffset:y,snapLines:v}=D3(w,E,this,n,this.scene.getNonDeletedElementsMap());if(this.setState({snapLines:v}),this.state.editingFrame||wK(t,d,E,this.scene,y,n[j.CTRL_OR_CMD]?null:this.getEffectiveGridSize()),this.setState({selectedElementsAreBeingDragged:!0,selectionElement:null}),n.altKey&&!t.hit.hasBeenDuplicated){t.hit.hasBeenDuplicated=!0;let T=this.scene.getElementsIncludingDeleted(),C=t.hit.element,M=this.scene.getSelectedElements({selectedElementIds:this.state.selectedElementIds,includeBoundTextElement:!0,includeElementsInFrames:!0});C&&t.hit.wasAddedToSelection&&!M.find(Y=>Y.id===C.id)&&M.push(C);let S=new Map(M.map(Y=>[Y.id,Y])),{duplicatedElements:D,duplicateElementsMap:_,elementsWithDuplicates:P,origIdToDuplicateId:A}=B0({type:"in-place",elements:T,appState:this.state,randomizeSeed:!0,idsOfElementsToDuplicate:S,overrides:({duplicateElement:Y,origElement:R})=>({frameId:Y.frameId??R.frameId,seed:uV()})});D.forEach(Y=>{t.originalElements.set(Y.id,W4(Y))});let z=P.map(Y=>{if(S.has(Y.id)){let R=t.originalElements.get(Y.id);if(R)return Fr(Y,{x:R.x,y:R.y})}return Y}),V=this.props.onDuplicate?.(z,T),G=rk(V||z,Zp(D));Xt(()=>{if(t.hit.element){let Y=A.get(t.hit.element.id),R=Y&&_.get(Y);t.hit.element=R||null}t.hit.allHitElements=t.hit.allHitElements.reduce((Y,R)=>{let F=A.get(R.id),K=F&&_.get(F);return K&&Y.push(K),Y},[]),t.drag.origin=Ue(n,this.state),this.setState(Y=>({...bK(D,this.scene.getNonDeletedElements(),Y)})),this.scene.replaceAllElements(G),M.forEach(Y=>{H0(Y)&&Y.boundElements?.some(R=>R.type==="arrow")&&Jp(Y,this.scene)}),this.maybeCacheVisibleGaps(n,M,!0),this.maybeCacheReferenceSnapPoints(n,M,!0)})}return}}if(this.state.selectionElement){if(t.lastCoords.x=r.x,t.lastCoords.y=r.y,n.altKey){this.setActiveTool({type:"lasso",fromSelection:!0},n.shiftKey),this.lassoTrail.startPath(t.origin.x,t.origin.y,n.shiftKey),this.setAppState({selectionElement:null});return}this.maybeDragNewGenericElement(t,n)}else if(this.state.activeTool.type==="lasso")!n.altKey&&this.state.activeTool.fromSelection?(this.setActiveTool({type:"selection"}),this.createGenericElementOnPointerDown("selection",t),t.lastCoords.x=r.x,t.lastCoords.y=r.y,this.maybeDragNewGenericElement(t,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,b=r.x-d.x,g=r.y-d.y,E=u.length>0&&u[u.length-1];if(!(E&&E[0]===b&&E[1]===g)){let x=d.simulatePressure?d.pressures:[...d.pressures,n.pressure];this.scene.mutateElement(d,{points:[...u,ie(b,g)],pressures:x},{informMutation:!1,isDragging:!1}),this.setState({newElement:d})}}else if(zt(d)&&!d.isDeleted){t.drag.hasOccurred=!0;let u=d.points;bn(u.length>1,"Do not create linear elements with less than 2 points");let b=this.state.selectedLinearElement;b||(b=new ve(d,this.scene.getNonDeletedElementsMap()),b={...b,selectedPointsIndices:[1],initialState:{...b.initialState,lastClickedPoint:1}}),this.setState({newElement:d,...ve.handlePointDragging(n,this,s,l,b)})}else t.lastCoords.x=r.x,t.lastCoords.y=r.y,this.maybeDragNewGenericElement(t,n,!1)}if(this.state.activeTool.type==="selection"){t.boxSelection.hasOccurred=!0;let d=this.scene.getNonDeletedElements();if(this.state.selectedLinearElement?.isEditing)ve.handleBoxSelection(n,this.state,this.setState.bind(this),this.scene.getNonDeletedElementsMap());else{let u=!0;!n.shiftKey&&Le(d,this.state)&&(t.withCmdOrCtrl&&t.hit.element?this.setState(g=>Io({...g,selectedElementIds:{[t.hit.element.id]:!0}},this.scene.getNonDeletedElements(),g,this)):u=!1);let b=this.state.selectionElement?Mb(d,this.state.selectionElement,this.scene.getNonDeletedElementsMap(),!1):[];this.setState(g=>{let E={...u&&g.selectedElementIds,...b.reduce((w,x)=>(w[x.id]=!0,w),{})};return t.hit.element&&(b.length?delete E[t.hit.element.id]:E[t.hit.element.id]=!0),g=u?g:{...g,selectedGroupIds:{},editingGroupId:null},{...Io({editingGroupId:g.editingGroupId,selectedElementIds:E},this.scene.getNonDeletedElements(),g,this),selectedLinearElement:b.length===1&&zt(b[0])?new ve(b[0],this.scene.getNonDeletedElementsMap()):null,showHyperlinkPopup:b.length===1&&(b[0].link||Wn(b[0]))?"info":!1}})}}})}handlePointerMoveOverScrollbars(t,n){if(n.scrollbars.isOverHorizontal){let r=t.clientX,i=r-n.lastCoords.x;return this.translateCanvas({scrollX:this.state.scrollX-i*(pc.horizontal?.deltaMultiplier||1)/this.state.zoom.value}),n.lastCoords.x=r,!0}if(n.scrollbars.isOverVertical){let r=t.clientY,i=r-n.lastCoords.y;return this.translateCanvas({scrollY:this.state.scrollY-i*(pc.vertical?.deltaMultiplier||1)/this.state.zoom.value}),n.lastCoords.y=r,!0}return!1}onPointerUpFromPointerDownHandler(t){return Ze(n=>{let r=this.scene.getNonDeletedElementsMap();this.removePointer(n),t.drag.blockDragging=!1,t.eventListeners.onMove&&t.eventListeners.onMove.flush();let{newElement:i,resizingElement:a,croppingElementId:s,multiElement:l,activeTool:c,isResizing:m,isRotating:p,isCropping:d}=this.state;this.setState(x=>({isResizing:!1,isRotating:!1,isCropping:!1,resizingElement:null,selectionElement:null,frameToHighlight:null,elementsToHighlight:null,cursorButton:"up",snapLines:rc(x.snapLines,[]),originSnapOffset:null})),this.lassoTrail.endPath(),this.previousPointerMoveCoords=null,go.setReferenceSnapPoints(null),go.setVisibleGaps(null),this.savePointer(n.clientX,n.clientY,"up");let u=t.hit.allHitElements,b=Ue({clientX:n.clientX,clientY:n.clientY},this.state);if(this.state.activeTool.type==="selection"&&!t.boxSelection.hasOccurred&&!t.resize.isResizing&&!u.some(x=>this.state.selectedElementIds[x.id])){let x=this.getElementAtPosition(b.x,b.y,{includeLockedElements:!0});this.store.scheduleCapture(),x?.locked?this.setState({activeLockedId:x.groupIds.length>0?x.groupIds.at(-1)||"":x.id}):this.setState({activeLockedId:null})}else this.setState({activeLockedId:null});if(Un("COMPLEX_BINDINGS")&&this.resetDelayedBindMode(),this.setState({selectedElementsAreBeingDragged:!1,bindMode:"orbit"}),t.drag.hasOccurred&&t.hit?.element?.id){let x=r.get(t.hit.element.id);H0(x)&&x.boundElements?.filter(y=>y.type==="arrow").map(y=>r.get(y.id)).filter(y=>$t(y)).forEach(y=>{y&&this.scene.mutateElement(y,{})})}if(this.state.selectedLinearElement?.isEditing&&!this.state.newElement&&this.state.selectedLinearElement.draggedFocusPointBinding===null)if(!t.boxSelection.hasOccurred&&t.hit?.element?.id!==this.state.selectedLinearElement.elementId&&this.state.selectedLinearElement.draggedFocusPointBinding===null)this.actionManager.executeAction(Rt);else{let x=ve.handlePointerUp(n,this.state.selectedLinearElement,this.state,this.scene);this.actionManager.executeAction(Rt,"ui",{event:n,sceneCoords:b}),x!==this.state.selectedLinearElement&&this.setState({selectedLinearElement:x,suggestedBinding:null})}else if(this.state.selectedLinearElement){if(this.state.selectedLinearElement.elbowed){let x=ve.getElement(this.state.selectedLinearElement.elementId,this.scene.getNonDeletedElementsMap());x&&this.scene.mutateElement(x,{})}if(this.state.selectedLinearElement.draggedFocusPointBinding?(AK(this.state.selectedLinearElement,this.scene),this.setState({selectedLinearElement:{...this.state.selectedLinearElement,draggedFocusPointBinding:null}})):t.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(Rt,"ui",{event:n,sceneCoords:b})),this.state.newElement&&this.state.multiElement&&zt(this.state.newElement)&&this.state.selectedLinearElement){let{multiElement:x}=this.state;this.setState({selectedLinearElement:{...this.state.selectedLinearElement,lastCommittedPoint:x.points[x.points.length-1]}})}}if(this.missingPointerEventCleanupEmitter.clear(),window.removeEventListener(ce.POINTER_MOVE,t.eventListeners.onMove),window.removeEventListener(ce.POINTER_UP,t.eventListeners.onUp),window.removeEventListener(ce.KEYDOWN,t.eventListeners.onKeyDown),window.removeEventListener(ce.KEYUP,t.eventListeners.onKeyUp),this.props?.onPointerUp?.(c,t),this.onPointerUpEmitter.trigger(this.state.activeTool,t,n),i?.type==="freedraw"){let x=Ue(n,this.state),y=i.points,v=x.x-i.x,T=x.y-i.y;v===y[0][0]&&T===y[0][1]&&(T+=1e-4,v+=1e-4);let C=i.simulatePressure?[]:[...i.pressures,n.pressure];this.scene.mutateElement(i,{points:[...y,ie(v,T)],pressures:C}),this.actionManager.executeAction(Rt);return}if(zt(i)){i.points.length>1&&i.points[1][0]!==0&&i.points[1][1]!==0&&this.store.scheduleCapture();let x=Ue(n,this.state),y=Rr(ie(x.x,x.y),ie(t.origin.x,t.origin.y))*this.state.zoom.value;if((!t.drag.hasOccurred||y<gV)&&i&&!l)if(this.editorInterface.isTouchScreen){let v=Math.min(this.state.width*.7/this.state.zoom.value,100);this.scene.mutateElement(i,{x:i.x-v/2,points:[ie(0,0),ie(v,0)]},{informMutation:!1,isDragging:!1}),this.actionManager.executeAction(Rt)}else{let v=x.x-i.x,T=x.y-i.y;this.scene.mutateElement(i,{points:[i.points[0],ie(v,T)]},{informMutation:!1,isDragging:!1}),this.setState({multiElement:i,newElement:i})}else t.drag.hasOccurred&&!l&&(zt(i)&&this.actionManager.executeAction(Rt,"ui",{event:n,sceneCoords:b}),this.setState({suggestedBinding:null,startBoundElement:null}),c.locked?this.setState(v=>({newElement:null})):(Jt(this.interactiveCanvas),this.setState(v=>({newElement:null,activeTool:fn(this.state,{type:this.state.preferredSelectionTool.type}),selectedElementIds:Pe({...v.selectedElementIds,[i.id]:!0},v),selectedLinearElement:new ve(i,this.scene.getNonDeletedElementsMap())}))),this.scene.triggerUpdate());return}if(Ho(i)){let x=dK(A0({fontSize:i.fontSize,fontFamily:i.fontFamily}),i.lineHeight);i.width<x&&this.scene.mutateElement(i,{autoResize:!0}),this.resetCursor(),this.handleTextWysiwyg(i,{isExistingElement:!0})}if(c.type!=="selection"&&i&&X4(i)){this.updateScene({elements:this.scene.getElementsIncludingDeleted().filter(x=>x.id!==i.id),appState:{newElement:null},captureUpdate:Ht.NEVER});return}if(Lt(i)){let x=KV(this.scene.getElementsIncludingDeleted(),i,this.scene.getNonDeletedElementsMap());this.scene.replaceAllElements(K0(this.scene.getElementsMapIncludingDeleted(),x,i,this.state))}if(i&&(this.scene.mutateElement(i,BV(i),{informMutation:!1,isDragging:!1}),this.scene.triggerUpdate()),t.drag.hasOccurred){let x=Ue(n,this.state);if(this.state.selectedLinearElement&&this.state.selectedLinearElement.isDragging){let y=this.scene.getElement(this.state.selectedLinearElement.elementId);if(y?.frameId){let v=$0(y,r);v&&y&&(XV(y,v,this.scene.getNonDeletedElementsMap())||(this.scene.mutateElement(y,{groupIds:[]}),VV([y],this.scene.getNonDeletedElementsMap()),this.scene.triggerUpdate()))}}else{let y=this.getTopLayerFrameAtSceneCoords(x),v=this.scene.getSelectedElements(this.state),T=this.scene.getElementsMapIncludingDeleted(),C=M=>{if(M.length>0){for(let S of M){let D=S.groupIds.indexOf(this.state.editingGroupId);this.scene.mutateElement(S,{groupIds:S.groupIds.slice(0,D)},{informMutation:!1,isDragging:!1})}T.forEach(S=>{S.groupIds.length&&Li(T,S.groupIds[S.groupIds.length-1]).length<2&&this.scene.mutateElement(S,{groupIds:[]},{informMutation:!1,isDragging:!1})}),this.setState({editingGroupId:null})}};if(y&&!this.state.selectedElementIds[y.id]){let M=v.filter(S=>S.frameId!==y.id&&ek(S,T,this.state));this.state.editingGroupId&&C(M),T=K0(T,M,y,this.state)}else if(!y&&this.state.editingGroupId){let M=v.filter(S=>S.frameId&&!ek(S,T,this.state));C(M)}T=Q4(T,this.state,this),this.scene.replaceAllElements(T)}}if(a&&this.store.scheduleCapture(),a&&X4(a)&&this.updateScene({elements:this.scene.getElementsIncludingDeleted().filter(x=>x.id!==a.id),captureUpdate:Ht.NEVER}),t.resize.isResizing){let x=Q4(this.scene.getElementsIncludingDeleted(),this.state,this),y=this.scene.getSelectedElements(this.state).filter(v=>Lt(v));for(let v of y)x=YV(x,X0(this.scene.getElementsIncludingDeleted(),v,this.state,r),v,this);this.scene.replaceAllElements(x)}let g=t.hit.element;this.state.selectedLinearElement?.elementId!==g?.id&&zt(g)&&this.scene.getSelectedElements(this.state).length===1&&this.setState({selectedLinearElement:new ve(g,this.scene.getNonDeletedElementsMap())}),(!s||s&&(!g&&!d||g&&g.id!==s))&&this.finishImageCropping();let E=this.lastPointerDownEvent,w=this.lastPointerUpEvent||this.lastPointerMoveEvent;if(Gt(this.state)&&E&&w){if(this.eraserTrail.endPath(),Rr(ie(E.clientX,E.clientY),ie(w.clientX,w.clientY))===0){let y=Ue({clientX:w.clientX,clientY:w.clientY},this.state);this.getElementsAtPosition(y.x,y.y).forEach(T=>this.elementsPendingErasure.add(T.id))}this.eraseElements();return}else this.elementsPendingErasure.size&&this.restoreReadyToEraseElements();if(g&&!t.drag.hasOccurred&&!t.hit.wasAddedToSelection&&(!this.state.selectedLinearElement?.isEditing||!t.boxSelection.hasOccurred)&&this.state.activeTool.type!=="lasso"&&(n.shiftKey&&!this.state.selectedLinearElement?.isEditing?this.state.selectedElementIds[g.id]?hK(this.state,g)?this.setState(x=>{let y={...x.selectedElementIds};for(let v of g.groupIds.flatMap(T=>Li(this.scene.getNonDeletedElements(),T)))delete y[v.id];return{selectedGroupIds:{...x.selectedElementIds,...g.groupIds.map(v=>({[v]:!1})).reduce((v,T)=>({...v,...T}),{})},selectedElementIds:Pe(y,x)}}):this.state.selectedLinearElement?.isDragging||this.setState(x=>{let y={...x.selectedElementIds};delete y[g.id];let v=ne(this.scene.getNonDeletedElements(),{selectedElementIds:y});return{...Io({editingGroupId:x.editingGroupId,selectedElementIds:y},this.scene.getNonDeletedElements(),x,this),selectedLinearElement:v.length===1&&zt(v[0])?new ve(v[0],this.scene.getNonDeletedElementsMap()):x.selectedLinearElement}}):g.frameId&&this.state.selectedElementIds[g.frameId]?this.setState(x=>{let y={...x.selectedElementIds,[g.id]:!0};return delete y[g.frameId],(this.scene.getElement(g.frameId)?.groupIds??[]).flatMap(v=>Li(this.scene.getNonDeletedElements(),v)).forEach(v=>{delete y[v.id]}),{...Io({editingGroupId:x.editingGroupId,selectedElementIds:y},this.scene.getNonDeletedElements(),x,this),showHyperlinkPopup:g.link||Wn(g)?"info":!1}}):this.setState(x=>({selectedElementIds:Pe({...x.selectedElementIds,[g.id]:!0},x)})):this.setState(x=>({...Io({editingGroupId:x.editingGroupId,selectedElementIds:{[g.id]:!0}},this.scene.getNonDeletedElements(),x,this),selectedLinearElement:zt(g)&&x.selectedLinearElement?.elementId!==g.id?new ve(g,this.scene.getNonDeletedElementsMap()):x.selectedLinearElement}))),this.state.activeTool.type!=="lasso"&&!(g&&$t(g))&&!t.drag.hasOccurred&&!this.state.isResizing&&(g&&JV({point:ie(t.origin.x,t.origin.y),element:g,elementsMap:r,threshold:this.getElementHitThreshold(g),frameNameBound:Lt(g)?this.frameNameBoundsCache.get(g):null},r)||!g&&t.hit.hasHitCommonBoundingBoxOfSelectedElements)){this.state.selectedLinearElement?.isEditing?this.actionManager.executeAction(Xa):this.setState({selectedElementIds:Pe({},this.state),selectedGroupIds:{},editingGroupId:null,activeEmbeddable:null}),Se(this.interactiveCanvas,Ke.AUTO);return}if(!c.locked&&c.type!=="freedraw"&&i&&this.setState(x=>({selectedElementIds:Pe({...x.selectedElementIds,[i.id]:!0},x),showHyperlinkPopup:Wn(i)&&!i.link?"editor":x.showHyperlinkPopup})),(c.type!=="selection"||Le(this.scene.getNonDeletedElements(),this.state)||!B4(this.state.previousSelectedElementIds,this.state.selectedElementIds))&&this.store.scheduleCapture(),t.drag.hasOccurred&&!this.state.selectedLinearElement||m||p||d){let x=this.scene.getSelectedElements(this.state).filter(xs);O4(x,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)?(Jt(this.interactiveCanvas),this.setState({newElement:null,suggestedBinding:null,activeTool:fn(this.state,{type:this.state.preferredSelectionTool.type})})):this.setState({newElement:null,suggestedBinding:null})})}clearSelection(t){this.setState(n=>({selectedElementIds:Pe({},n),activeEmbeddable:null,selectedGroupIds:{},editingGroupId:n.editingGroupId&&t!=null&&nk(t,n.editingGroupId)?n.editingGroupId:null})),this.setState({selectedElementIds:Pe({},this.state),activeEmbeddable:null,previousSelectedElementIds:this.state.selectedElementIds,selectedLinearElement:null})}getTextWysiwygSnappedToCenterPosition(t,n,r,i){if(i){let a=i.x+i.width/2,s=i.y+i.height/2,l=Y0(i,r,this.scene.getNonDeletedElementsMap());if(l&&(a=l.x,s=l.y),Math.hypot(t-a,n-s)<ZY){let{x:p,y:d}=$p({sceneX:a,sceneY:s},r);return{viewportX:p,viewportY:d,elementCenterX:a,elementCenterY:s}}}}getCanvasOffsets(){if(this.excalidrawContainerRef?.current){let t=this.excalidrawContainerRef.current,{left:n,top:r}=t.getBoundingClientRect();return{offsetLeft:n,offsetTop:r}}return{offsetLeft:0,offsetTop:0}}async updateLanguage(){let t=zi.find(n=>n.code===this.props.langCode)||Vo;await Lc(t),this.setAppState({})}},_K=()=>{(Ek()||yk())&&(window.h=window.h||{},Object.defineProperties(window.h,{elements:{configurable:!0,get(){return this.app?.scene.getElementsIncludingDeleted()},set(e){return this.app?.scene.replaceAllElements(vk(e))}},scene:{configurable:!0,get(){return this.app?.scene}}}))};_K();var Ck=ib;import{useEffect as RK,useState as NK}from"react";import{jsx as BK}from"react/jsx-runtime";var Sk=e=>{let[o,t]=NK(!0);return RK(()=>{let n=async()=>{await Lc(r),t(!1)},r=zi.find(i=>i.code===e.langCode)||Vo;n()},[e.langCode]),o?BK(op,{theme:e.theme}):e.children};import FK from"clsx";import{jsx as kk}from"react/jsx-runtime";var Mk=({children:e})=>{let{FooterCenterTunnel:o}=Fe(),t=he();return kk(o.In,{children:kk("div",{className:FK("footer-center zen-mode-transition",{"layer-ui__wrapper__footer-left--transition-bottom":t.zenModeEnabled}),children:e})})},OK=Mk;Mk.displayName="FooterCenter";import zK from"clsx";import{MQ_MIN_WIDTH_DESKTOP as HK}from"@orangecatai/common";import{jsx as UK,jsxs as WK}from"react/jsx-runtime";var Pk=({isCollaborating:e,onSelect:o,editorInterface:t,...n})=>{let r=he(),i=t?.formFactor!=="desktop"||r.width<HK;return WK(Ft,{...n,className:zK("collab-button",{active:e}),type:"button",onSelect:o,style:{position:"relative",width:i?void 0:"auto"},title:h("labels.liveCollaboration"),children:[i?Ex:h("labels.share"),r.collaborators.size>0&&UK("div",{className:"CollabButton-collaborators",children:r.collaborators.size})]})},GK=Pk;Pk.displayName="LiveCollaborationTrigger";import{jsx as Ur,jsxs as Ak}from"react/jsx-runtime";var YK=()=>Ur("svg",{viewBox:"0 0 40 40",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:"ExcalidrawLogo-icon",children:Ur("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"})}),VK=()=>Ak("svg",{viewBox:"0 0 450 55",xmlns:"http://www.w3.org/2000/svg",fill:"none",className:"ExcalidrawLogo-text",children:[Ur("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)"}),Ur("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)"}),Ur("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)"}),Ur("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)"})]}),Lk=({style:e,size:o="small",withText:t})=>Ak("div",{className:`ExcalidrawLogo is-${o}`,style:e,children:[Ur(YK,{}),t&&Ur(VK,{})]});import{Fragment as Rk,jsx as at,jsxs as pb}from"react/jsx-runtime";var ub=({icon:e,shortcut:o,children:t})=>{let n=fe();return pb(Rk,{children:[at("div",{className:"welcome-screen-menu-item__icon",children:e}),at("div",{className:"welcome-screen-menu-item__text",children:t}),o&&n.formFactor!=="phone"&&at("div",{className:"welcome-screen-menu-item__shortcut",children:o})]})};ub.displayName="WelcomeScreenMenuItemContent";var fc=({onSelect:e,children:o,icon:t,shortcut:n,className:r="",...i})=>at("button",{...i,type:"button",className:`welcome-screen-menu-item ${r}`,onClick:e,children:at(ub,{icon:t,shortcut:n,children:o})});fc.displayName="WelcomeScreenMenuItem";var Dk=({children:e,href:o,icon:t,shortcut:n,className:r="",...i})=>at("a",{...i,className:`welcome-screen-menu-item ${r}`,href:o,target:"_blank",rel:"noopener",children:at(ub,{icon:t,shortcut:n,children:e})});Dk.displayName="WelcomeScreenMenuItemLink";var Co=({children:e})=>{let{WelcomeScreenCenterTunnel:o}=Fe();return at(o.In,{children:at("div",{className:"welcome-screen-center",children:e||pb(Rk,{children:[at(gb,{}),at(hb,{children:h("welcomeScreen.defaults.center_heading")}),pb(fb,{children:[at(xb,{}),at(bb,{})]})]})})})};Co.displayName="Center";var gb=({children:e})=>at("div",{className:"welcome-screen-center__logo excalifont welcome-screen-decor",children:e||at(Lk,{withText:!0})});gb.displayName="Logo";var hb=({children:e})=>at("div",{className:"welcome-screen-center__heading welcome-screen-decor excalifont",children:e});hb.displayName="Heading";var fb=({children:e})=>at("div",{className:"welcome-screen-menu",children:e});fb.displayName="Menu";var bb=()=>{let e=We();return at(fc,{onSelect:()=>e.executeAction(ai),shortcut:"?",icon:Ki,children:h("helpDialog.title")})};bb.displayName="MenuItemHelp";var xb=()=>{let e=he(),o=We();return e.viewModeEnabled?null:at(fc,{onSelect:()=>o.executeAction(xa),shortcut:Be("loadScene"),icon:Xi,children:h("buttons.load")})};xb.displayName="MenuItemLoadScene";var _k=({onSelect:e})=>{let{t:o}=Ae();return at(fc,{shortcut:null,onSelect:e,icon:Oc,children:o("labels.liveCollaboration")})};_k.displayName="MenuItemLiveCollaborationTrigger";Co.Logo=gb;Co.Heading=hb;Co.Menu=fb;Co.MenuItem=fc;Co.MenuItemLink=Dk;Co.MenuItemHelp=bb;Co.MenuItemLoadScene=xb;Co.MenuItemLiveCollaborationTrigger=_k;import{jsx as ys,jsxs as Eb}from"react/jsx-runtime";var nu=({children:e})=>{let{WelcomeScreenMenuHintTunnel:o}=Fe();return ys(o.In,{children:Eb("div",{className:"excalifont welcome-screen-decor welcome-screen-decor-hint welcome-screen-decor-hint--menu",children:[nx,ys("div",{className:"welcome-screen-decor-hint__label",children:e||h("welcomeScreen.defaults.menuHint")})]})})};nu.displayName="MenuHint";var ru=({children:e})=>{let{WelcomeScreenToolbarHintTunnel:o}=Fe();return ys(o.In,{children:Eb("div",{className:"excalifont welcome-screen-decor welcome-screen-decor-hint welcome-screen-decor-hint--toolbar",children:[ys("div",{className:"welcome-screen-decor-hint__label",children:e||h("welcomeScreen.defaults.toolbarHint")}),ix]})})};ru.displayName="ToolbarHint";var iu=({children:e})=>{let{WelcomeScreenHelpHintTunnel:o}=Fe();return ys(o.In,{children:Eb("div",{className:"excalifont welcome-screen-decor welcome-screen-decor-hint welcome-screen-decor-hint--help",children:[ys("div",{children:e||h("welcomeScreen.defaults.helpHint")}),rx]})})};iu.displayName="HelpHint";import{Fragment as Nk,jsx as bc,jsxs as XK}from"react/jsx-runtime";var au=e=>bc(Nk,{children:e.children||XK(Nk,{children:[bc(Co,{}),bc(nu,{}),bc(ru,{}),bc(iu,{})]})});au.displayName="WelcomeScreen";au.Center=Co;au.Hints={MenuHint:nu,ToolbarHint:ru,HelpHint:iu};var KK=au;var $K=()=>{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)})},Bk=$K;import{getSceneVersion as iGe,hashElementsVersion as aGe,hashString as sGe,getNonDeletedElements as lGe}from"@orangecatai/element";import{getTextFromElements as dGe}from"@orangecatai/element";import{isInvisiblySmallElement as pGe}from"@orangecatai/element";import ZK from"lodash.throttle";import{arrayToMap as jK,isDevEnv as Fk,isTestEnv as Ok}from"@orangecatai/common";import{orderByFractionalIndex as qK,syncInvalidIndices as zk,validateFractionalIndices as JK}from"@orangecatai/element";var QK=(e,o,t)=>!!(o&&(o.id===e.editingTextElement?.id||o.id===e.resizingElement?.id||o.id===e.newElement?.id||o.version>t.version||o.version===t.version&&o.versionNonce<=t.versionNonce)),eX=ZK((e,o,t)=>{if(Fk()||Ok()||window?.DEBUG_FRACTIONAL_INDICES){let n=zk(e.map(r=>({...r})));JK(n,{shouldThrow:Ok()||Fk(),includeBoundTextValidation:!0,reconciliationContext:{localElements:o,remoteElements:t}})}},1e3*60,{leading:!0,trailing:!1}),tX=(e,o,t)=>{let n=jK(e),r=[],i=new Set;for(let s of o)if(!i.has(s.id)){let l=n.get(s.id),c=QK(t,l,s);l&&c?(r.push(l),i.add(l.id)):(r.push(s),i.add(s.id))}for(let s of e)i.has(s.id)||(r.push(s),i.add(s.id));let a=qK(r);return eX(a,e,o),zk(a),a};import{isLinearElement as wGe}from"@orangecatai/element";import{FONT_FAMILY as TGe,THEME as J5,MIME_TYPES as IGe,ROUNDNESS as Vd,DEFAULT_LASER_COLOR as CGe,UserIdleState as SGe,normalizeLink as kGe,sceneCoordsToViewportCoords as Wv,viewportCoordsToSceneCoords as MGe,getFormFactor as PGe}from"@orangecatai/common";import{mutateElement as Xd,newElementWith as AGe,bumpVersion as Ma}from"@orangecatai/element";import{CaptureUpdateAction as _Ge}from"@orangecatai/element";import{jsx as yb}from"react/jsx-runtime";var Hk=({children:e,icon:o})=>{let{t}=Ae(),{TTDDialogTriggerTunnel:n}=Fe(),r=be();return yb(n.In,{children:yb(se.Item,{onSelect:()=>{me("ai","dialog open","ttd"),r({openDialog:{name:"ttd",tab:"text-to-diagram"}})},icon:o??fE,badge:yb(se.Item.Badge,{children:"AI"}),children:e??t("labels.textToDiagram")})})};Hk.displayName="TTDDialogTrigger";function oX(e){let o=e.get("X-Ratelimit-Limit"),t=e.get("X-Ratelimit-Remaining");return{rateLimit:o?parseInt(o,10):void 0,rateLimitRemaining:t?parseInt(t,10):void 0}}async function*nX(e){let o=new TextDecoder,t="";try{for(;;){let{done:n,value:r}=await e.read();if(n)break;t+=o.decode(r,{stream:!0});let i=t.split(`
|
|
127
|
-
`);t=i.pop()||"";for(let a of i){let s=a.trim();s&&s.startsWith("data: ")&&(yield s.slice(6))}}}finally{e.releaseLock()}}async function rX(e){let{url:o,messages:t,onChunk:n,onStreamCreated:r,extractRateLimits:i=!0,signal:a}=e;try{let s="",l={},c=null,m=await fetch(o,{method:"POST",headers:{Accept:"text/event-stream","Content-Type":"application/json"},body:JSON.stringify({messages:t}),signal:a});if(i&&(l=oX(m.headers)),!m.ok){if(m.status===429)return{...l,error:new Wo({message:"Rate limit exceeded",status:429})};let d=await m.text();throw new Wo({message:d||"Generation failed...",status:m.status})}let p=m.body?.getReader();if(!p)throw new Wo({message:"Couldn't get reader from response body",status:500});r?.();try{for await(let d of nX(p)){if(d==="[DONE]")break;try{let u=JSON.parse(d);if(u===null)break;switch(u.type){case"content":{let b=u.delta;b&&(s+=b,n?.(b));break}case"error":c=new Wo({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 Wo({message:"Request aborted",status:499}):c=new Wo({message:d.message||"Streaming error",status:500})}return c?{...l,error:c}:s?{generatedResponse:s,error:null,...l}:{...l,error:new Wo({message:"Generation failed...",status:m.status})}}catch(s){return s.name==="AbortError"?{error:new Wo({message:"Request aborted",status:499})}:{error:new Wo({message:s.message||"Request failed",status:500})}}}import{getCommonBounds as KGe,getVisibleSceneBounds as XGe,convertToExcalidrawElements as Q5}from"@orangecatai/element";import{useLayoutEffect as iX}from"react";var aX=e=>{let o=ze();return iX(()=>{o.setPlugins({diagramToCode:{generate:e.generate}})},[o,e.generate]),null};import{isElementLink as JGe}from"@orangecatai/element";import{setCustomTextMetricsProvider as eUe}from"@orangecatai/element";import{jsx as wb}from"react/jsx-runtime";Bk();var dX=e=>{let{onChange:o,onIncrement:t,initialData:n,excalidrawAPI:r,isCollaborating:i=!1,onPointerUpdate:a,renderTopLeftUI:s,renderTopRightUI:l,langCode:c=Vo.code,viewModeEnabled:m,zenModeEnabled:p,gridModeEnabled:d,libraryReturnUrl:u,theme:b,name:g,renderCustomStats:E,onPaste:w,detectScroll:x=!0,handleKeyboardGlobally:y=!1,onLibraryChange:v,autoFocus:T=!1,generateIdForFile:C,onLinkOpen:M,generateLinkForSelection:S,onPointerDown:D,onPointerUp:_,onScrollChange:P,onDuplicate:A,children:z,validateEmbeddable:V,renderEmbeddable:G,aiEnabled:Y,showDeprecatedFonts:R,renderScrollbars:F}=e,K=e.UIOptions?.canvasActions,J={...e.UIOptions,canvasActions:{...Gk.canvasActions,...K},tools:{image:e.UIOptions?.tools?.image??!0}};return K?.export&&(J.canvasActions.export.saveFileToDisk=K.export?.saveFileToDisk??Gk.canvasActions.export.saveFileToDisk),J.canvasActions.toggleTheme===null&&typeof b>"u"&&(J.canvasActions.toggleTheme=!0),lX(()=>{(async()=>{await import("canvas-roundrect-polyfill")})();let le=Ee=>{typeof Ee.scale=="number"&&Ee.scale!==1&&Ee.preventDefault()};return document.addEventListener("touchmove",le,{passive:!1}),()=>{document.removeEventListener("touchmove",le)}},[]),wb($b,{store:ot,children:wb(Sk,{langCode:c,theme:b,children:wb(Ck,{onChange:o,onIncrement:t,initialData:n,excalidrawAPI:r,isCollaborating:i,onPointerUpdate:a,renderTopLeftUI:s,renderTopRightUI:l,langCode:c,viewModeEnabled:m,zenModeEnabled:p,gridModeEnabled:d,libraryReturnUrl:u,theme:b,name:g,renderCustomStats:E,UIOptions:J,onPaste:w,detectScroll:x,handleKeyboardGlobally:y,onLibraryChange:v,autoFocus:T,generateIdForFile:C,onLinkOpen:M,generateLinkForSelection:S,onPointerDown:D,onPointerUp:_,onScrollChange:P,onDuplicate:A,validateEmbeddable:V,renderEmbeddable:G,aiEnabled:Y!==!1,showDeprecatedFonts:R,renderScrollbars:F,children:z})})})},mX=(e,o)=>{if(e.children!==o.children)return!1;let{initialData:t,UIOptions:n={},...r}=e,{initialData:i,UIOptions:a={},...s}=o,l=Object.keys(n),c=Object.keys(a);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&&a?.canvasActions?.export?n.canvasActions.export.saveFileToDisk===a.canvasActions.export.saveFileToDisk:n?.canvasActions?.[u]===a?.canvasActions?.[u]):n[p]===a[p])&&cX(r,s)},pX=sX.memo(dX,mX);pX.displayName="Excalidraw";export{Ft as Button,_Ge as CaptureUpdateAction,uN as CommandPalette,CGe as DEFAULT_LASER_COLOR,Ep as DefaultSidebar,aX as DiagramToCodePlugin,Xs as Ellipsify,pX as Excalidraw,TGe as FONT_FAMILY,OK as Footer,GK as LiveCollaborationTrigger,IGe as MIME_TYPES,kt as MainMenu,Vd as ROUNDNESS,bo as Sidebar,ql as Stats,J5 as THEME,Mp as TTDDialog,Hk as TTDDialogTrigger,rX as TTDStreamFetch,SGe as UserIdleState,KK as WelcomeScreen,Ma as bumpVersion,Q5 as convertToExcalidrawElements,Vo as defaultLang,VT as elementPartiallyOverlapsWithOrContainsBBox,KT as elementsOverlappingBBox,$v as exportToBlob,dr as exportToCanvas,P_ as exportToClipboard,Da as exportToSvg,KGe as getCommonBounds,hu as getDataURL,PGe as getFormFactor,Jd as getLibraryItemsHash,lGe as getNonDeletedElements,iGe as getSceneVersion,dGe as getTextFromElements,XGe as getVisibleSceneBounds,aGe as hashElementsVersion,sGe as hashString,wf as isElementInsideBBox,JGe as isElementLink,pGe as isInvisiblySmallElement,wGe as isLinearElement,zi as languages,Sc as loadFromBlob,gu as loadLibraryFromBlob,uu as loadSceneOrLibraryFromBlob,n2 as mergeLibraryItems,Xd as mutateElement,AGe as newElementWith,kGe as normalizeLink,Rh as parseLibraryTokensFromUrl,tX as reconcileElements,Bi as restoreAppState,Wk as restoreElement,Vr as restoreElements,Ms as restoreLibraryItems,Wv as sceneCoordsToViewportCoords,Cs as serializeAsJSON,Uk as serializeLibraryAsJSON,eUe as setCustomTextMetricsProvider,fe as useEditorInterface,V_ as useHandleLibrary,Ae as useI18n,ut as useStylesPanelMode,MGe as viewportCoordsToSceneCoords,ew as zoomToFitBounds};
|
|
182
|
+
`)}`),u.push({type:"text",text:b}),{role:m.role,content:u}}return{role:m.role,content:m.content}}),a={model:r,messages:i};n?.webSearchEnabled&&(a.plugins=[{id:"web",max_results:5}]);let s=await fetch("https://openrouter.ai/api/v1/chat/completions",{method:"POST",signal:o,headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json"},body:JSON.stringify(a)});if(!s.ok){let m=`OpenRouter error ${s.status}`;try{let p=await s.json();p?.error?.message&&(m=p.error.message)}catch{}throw new Error(m)}let c=(await s.json())?.choices?.[0]?.message?.content;if(!c)throw new Error("No response returned by the API.");return c}import{jsx as xx}from"react/jsx-runtime";FM();var nj=e=>{let{onChange:t,onIncrement:o,initialData:n,excalidrawAPI:r,isCollaborating:i=!1,onPointerUpdate:a,renderTopLeftUI:s,renderTopRightUI:l,langCode:c=pn.code,viewModeEnabled:m,zenModeEnabled:p,gridModeEnabled:d,libraryReturnUrl:u,theme:b,name:g,renderCustomStats:E,onPaste:y,detectScroll:x=!0,handleKeyboardGlobally:w=!1,onLibraryChange:v,autoFocus:T=!1,generateIdForFile:C,onLinkOpen:M,generateLinkForSelection:k,onPointerDown:R,onPointerUp:A,onScrollChange:P,onDuplicate:_,children:O,validateEmbeddable:U,renderEmbeddable:H,aiEnabled:W,showDeprecatedFonts:D,geminiApiKey:F,renderScrollbars:X,onBeforeImageGen:te,onAfterImageGen:$}=e,ae=e.UIOptions?.canvasActions,xe={...e.UIOptions,canvasActions:{...y6.canvasActions,...ae},tools:{image:e.UIOptions?.tools?.image??!0}};return ae?.export&&(xe.canvasActions.export.saveFileToDisk=ae.export?.saveFileToDisk??y6.canvasActions.export.saveFileToDisk),xe.canvasActions.toggleTheme===null&&typeof b>"u"&&(xe.canvasActions.toggleTheme=!0),tj(()=>{(async()=>{await import("canvas-roundrect-polyfill")})();let we=Fe=>{typeof Fe.scale=="number"&&Fe.scale!==1&&Fe.preventDefault()};return document.addEventListener("touchmove",we,{passive:!1}),()=>{document.removeEventListener("touchmove",we)}},[]),xx(Kx,{store:pt,children:xx(SM,{langCode:c,theme:b,children:xx(kM,{onChange:t,onIncrement:o,initialData:n,excalidrawAPI:r,isCollaborating:i,onPointerUpdate:a,renderTopLeftUI:s,renderTopRightUI:l,langCode:c,viewModeEnabled:m,zenModeEnabled:p,gridModeEnabled:d,libraryReturnUrl:u,theme:b,name:g,renderCustomStats:E,UIOptions:xe,onPaste:y,detectScroll:x,handleKeyboardGlobally:w,onLibraryChange:v,autoFocus:T,generateIdForFile:C,onLinkOpen:M,generateLinkForSelection:k,onPointerDown:R,onPointerUp:A,onScrollChange:P,onDuplicate:_,validateEmbeddable:U,renderEmbeddable:H,aiEnabled:W!==!1,showDeprecatedFonts:D,geminiApiKey:F,renderScrollbars:X,onBeforeImageGen:te,onAfterImageGen:$,children:O})})})},rj=(e,t)=>{if(e.children!==t.children)return!1;let{initialData:o,UIOptions:n={},...r}=e,{initialData:i,UIOptions:a={},...s}=t,l=Object.keys(n),c=Object.keys(a);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&&a?.canvasActions?.export?n.canvasActions.export.saveFileToDisk===a.canvasActions.export.saveFileToDisk:n?.canvasActions?.[u]===a?.canvasActions?.[u]):n[p]===a[p])&&oj(r,s)},ij=ej.memo(nj,rj);ij.displayName="Excalidraw";export{E6 as AIChatPanel,Jt as Button,ZVe as CaptureUpdateAction,sB as CommandPalette,GVe as DEFAULT_LASER_COLOR,nu as DefaultSidebar,eZ as DiagramToCodePlugin,_l as Ellipsify,ij as Excalidraw,OVe as FONT_FAMILY,_$ as Footer,N$ as LiveCollaborationTrigger,HVe as MIME_TYPES,Ut as MainMenu,Pm as ROUNDNESS,Ro as Sidebar,Bc as Stats,QC as THEME,pu as TTDDialog,GM as TTDDialogTrigger,J$ as TTDStreamFetch,UVe as UserIdleState,H$ as WelcomeScreen,as as bumpVersion,ek as convertToExcalidrawElements,pn as defaultLang,ZI as elementPartiallyOverlapsWithOrContainsBBox,jI as elementsOverlappingBBox,q2 as exportToBlob,Nr as exportToCanvas,TR as exportToClipboard,ds as exportToSvg,lKe as getCommonBounds,ng as getDataURL,VVe as getFormFactor,Bm as getLibraryItemsHash,IVe as getNonDeletedElements,wVe as getSceneVersion,kVe as getTextFromElements,cKe as getVisibleSceneBounds,vVe as hashElementsVersion,TVe as hashString,l0 as isElementInsideBBox,gKe as isElementLink,MVe as isInvisiblySmallElement,FVe as isLinearElement,ga as languages,pd as loadFromBlob,og as loadLibraryFromBlob,tg as loadSceneOrLibraryFromBlob,aT as mergeLibraryItems,Lm as mutateElement,XVe as newElementWith,WVe as normalizeLink,vf as parseLibraryTokensFromUrl,Z$ as reconcileElements,ma as restoreAppState,_6 as restoreElement,hi as restoreElements,pl as restoreLibraryItems,K2 as sceneCoordsToViewportCoords,cl as serializeAsJSON,L6 as serializeLibraryAsJSON,fKe as setCustomTextMetricsProvider,ye as useEditorInterface,OR as useHandleLibrary,Oe as useI18n,kt as useStylesPanelMode,YVe as viewportCoordsToSceneCoords,nv as zoomToFitBounds};
|