import{r as e}from"./rolldown-runtime-DIIn1E2Q.js";import{t}from"./types-Bc3W4AWd.js";import{Ci as n,Ji as r,i,nr as a,tr as o,wi as s}from"./dialogService-CHXiZnuQ.js";const c=[{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`},{combo:{ctrl:!0,key:`a`},commandId:`Comfy.Canvas.SelectAll`,targetElementId:`graph-canvas-container`},{combo:{ctrl:!0,key:`c`},commandId:`Comfy.Canvas.CopySelected`,targetElementId:`graph-canvas-container`},{combo:{ctrl:!0,key:`v`},commandId:`Comfy.Canvas.PasteFromClipboard`,targetElementId:`graph-canvas-container`},{combo:{ctrl:!0,shift:!0,key:`v`},commandId:`Comfy.Canvas.PasteFromClipboardWithConnect`,targetElementId:`graph-canvas-container`},{combo:{key:`Delete`},commandId:`Comfy.Canvas.DeleteSelectedItems`,targetElementId:`graph-canvas-container`},{combo:{key:`Backspace`},commandId:`Comfy.Canvas.DeleteSelectedItems`,targetElementId:`graph-canvas-container`}];function useKeybindingService(){let e=s(),l=n(),u=i(),d=r();async function keybindHandler(t){let n=a.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){let e=i.targetElementId===`graph-canvas`?`graph-canvas-container`:i.targetElementId;if(e&&!document.getElementById(e)?.contains(r)||t.key===`Escape`&&!t.ctrlKey&&!t.altKey&&!t.metaKey&&d.dialogStack.length>0)return;t.preventDefault(),new Set([`Comfy.QueuePrompt`,`Comfy.QueuePromptFront`,`Comfy.QueueSelectedOutputNodes`]).has(i.commandId)?await l.execute(i.commandId,{metadata:{trigger_source:`keybinding`}}):await l.execute(i.commandId);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 n of c)t&&n.commandId===`Workspace.ToggleBottomPanelTab.logs-terminal`||e.addDefaultKeybinding(new o(n))}function registerUserKeybindings(){let n=u.get(`Comfy.Keybinding.UnsetBindings`);for(let t of n)e.unsetKeybinding(new o(t));let r=u.get(`Comfy.Keybinding.NewBindings`);for(let n of r)t&&n.commandId===`Workspace.ToggleBottomPanelTab.logs-terminal`||e.addUserKeybinding(new o(n))}async function persistUserKeybindings(){await u.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-BuzA464t.js.map