import{r as e}from"./rolldown-runtime-DCMCV6zW.js";import{t}from"./types-DW97iHDr.js";import{er as n,gr as r,hr as i,i as a,o,tr as s}from"./dialogService-Cqui0UMO.js";import{t as c}from"./dialogStore-CXD5Bcfy.js";const l=[{combo:{ctrl:!0,key:`Enter`},commandId:`Comfy.QueuePrompt`},{combo:{ctrl:!0,shift:!0,key:`Enter`},commandId:`Comfy.QueuePromptFront`},{combo:{ctrl:!0,alt:!0,key:`Enter`},commandId:`Comfy.Interrupt`},{combo:{key:`r`},commandId:`Comfy.RefreshNodeDefinitions`},{combo:{key:`w`},commandId:`Workspace.ToggleSidebarTab.workflows`},{combo:{key:`n`},commandId:`Workspace.ToggleSidebarTab.node-library`},{combo:{key:`m`},commandId:`Workspace.ToggleSidebarTab.model-library`},{combo:{key:`a`},commandId:`Workspace.ToggleSidebarTab.assets`},{combo:{ctrl:!0,shift:!0,key:`a`},commandId:`Comfy.ToggleLinear`},{combo:{key:`s`,ctrl:!0},commandId:`Comfy.SaveWorkflow`},{combo:{key:`o`,ctrl:!0},commandId:`Comfy.OpenWorkflow`},{combo:{key:`g`,ctrl:!0},commandId:`Comfy.Graph.GroupSelectedNodes`},{combo:{key:`,`,ctrl:!0},commandId:`Comfy.ShowSettingsDialog`},{combo:{key:`=`,alt:!0},commandId:`Comfy.Canvas.ZoomIn`,targetElementId:`graph-canvas`},{combo:{key:`+`,alt:!0,shift:!0},commandId:`Comfy.Canvas.ZoomIn`,targetElementId:`graph-canvas`},{combo:{key:`+`,alt:!0},commandId:`Comfy.Canvas.ZoomIn`,targetElementId:`graph-canvas`},{combo:{key:`-`,alt:!0},commandId:`Comfy.Canvas.ZoomOut`,targetElementId:`graph-canvas`},{combo:{key:`.`},commandId:`Comfy.Canvas.FitView`,targetElementId:`graph-canvas-container`},{combo:{key:`p`},commandId:`Comfy.Canvas.ToggleSelected.Pin`,targetElementId:`graph-canvas-container`},{combo:{key:`c`,alt:!0},commandId:`Comfy.Canvas.ToggleSelectedNodes.Collapse`,targetElementId:`graph-canvas-container`},{combo:{key:`b`,ctrl:!0},commandId:`Comfy.Canvas.ToggleSelectedNodes.Bypass`,targetElementId:`graph-canvas-container`},{combo:{key:`m`,ctrl:!0},commandId:`Comfy.Canvas.ToggleSelectedNodes.Mute`,targetElementId:`graph-canvas-container`},{combo:{key:"`",ctrl:!0},commandId:`Workspace.ToggleBottomPanelTab.logs-terminal`},{combo:{key:`e`,ctrl:!0,shift:!0},commandId:`Comfy.Graph.ConvertToSubgraph`},{combo:{key:`m`,alt:!0},commandId:`Comfy.Canvas.ToggleMinimap`},{combo:{ctrl:!0,shift:!0,key:`k`},commandId:`Workspace.ToggleBottomPanel.Shortcuts`},{combo:{key:`v`},commandId:`Comfy.Canvas.Unlock`},{combo:{key:`h`},commandId:`Comfy.Canvas.Lock`},{combo:{key:`Escape`},commandId:`Comfy.Graph.ExitSubgraph`}];function useKeybindingService(){let e=r(),u=i(),d=a(),f=c();function shouldForwardToCanvas(e){return e.ctrlKey||e.altKey||e.metaKey?!1:[`Delete`,`Backspace`].includes(e.key)}async function keybindHandler(t){let n=s.fromEvent(t);if(n.isModifier)return;let r=t.composedPath()[0];if(n.isReservedByTextInput&&(r.tagName===`TEXTAREA`||r.tagName===`INPUT`||r.contentEditable===`true`||r.tagName===`SPAN`&&r.classList.contains(`property_value`)))return;let i=e.getKeybinding(n);if(i&&i.targetElementId!==`graph-canvas`){if(t.key===`Escape`&&!t.ctrlKey&&!t.altKey&&!t.metaKey&&f.dialogStack.length>0)return;t.preventDefault(),new Set([`Comfy.QueuePrompt`,`Comfy.QueuePromptFront`,`Comfy.QueueSelectedOutputNodes`]).has(i.commandId)?await u.execute(i.commandId,{metadata:{trigger_source:`keybinding`}}):await u.execute(i.commandId);return}if(!i&&shouldForwardToCanvas(t)){let e=o.canvas;if(e&&e.processKey&&typeof e.processKey==`function`){e.processKey(t);return}}if(!(t.ctrlKey||t.altKey||t.metaKey)&&t.key===`Escape`){let e=document.querySelectorAll(`.comfy-modal`);for(let t of e)if(window.getComputedStyle(t).getPropertyValue(`display`)!==`none`){t.style.display=`none`;break}for(let e of document.querySelectorAll(`dialog`))e.close()}}function registerCoreKeybindings(){for(let r of l)t&&r.commandId===`Workspace.ToggleBottomPanelTab.logs-terminal`||e.addDefaultKeybinding(new n(r))}function registerUserKeybindings(){let r=d.get(`Comfy.Keybinding.UnsetBindings`);for(let t of r)e.unsetKeybinding(new n(t));let i=d.get(`Comfy.Keybinding.NewBindings`);for(let r of i)t&&r.commandId===`Workspace.ToggleBottomPanelTab.logs-terminal`||e.addUserKeybinding(new n(r))}async function persistUserKeybindings(){await d.setMany({"Comfy.Keybinding.NewBindings":Object.values(e.getUserKeybindings()),"Comfy.Keybinding.UnsetBindings":Object.values(e.getUserUnsetKeybindings())})}return{keybindHandler,registerCoreKeybindings,registerUserKeybindings,persistUserKeybindings}}export{useKeybindingService as t};
//# sourceMappingURL=keybindingService-9tanJu34.js.map