From 2b1f62b357dbbb4c8eba08064e014150796e11ff Mon Sep 17 00:00:00 2001 From: pikaqiu Date: Sat, 16 May 2026 21:45:08 +0800 Subject: [PATCH] Add create mind map command --- plugin/main.js | 19 ++++---- src/main.ts | 120 ++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 130 insertions(+), 9 deletions(-) diff --git a/plugin/main.js b/plugin/main.js index 08e1f5e..c913e8e 100644 --- a/plugin/main.js +++ b/plugin/main.js @@ -1,13 +1,16 @@ /* OneMind - Obsidian mind map plugin */ -var K=Object.defineProperty;var we=Object.getOwnPropertyDescriptor;var xe=Object.getOwnPropertyNames;var ye=Object.prototype.hasOwnProperty;var Se=(o,s)=>{for(var e in s)K(o,e,{get:s[e],enumerable:!0})},Me=(o,s,e,t)=>{if(s&&typeof s=="object"||typeof s=="function")for(let i of xe(s))!ye.call(o,i)&&i!==e&&K(o,i,{get:()=>s[i],enumerable:!(t=we(s,i))||t.enumerable});return o};var be=o=>Me(K({},"__esModule",{value:!0}),o);var Fe={};Se(Fe,{default:()=>V});module.exports=be(Fe);var h=require("obsidian"),L="onemind-view",te=["\u{1F4A1}","\u2705","\u{1F525}","\u2B50","\u{1F3AF}","\u{1F680}","\u{1F4CC}","\u{1F4CE}","\u{1F9E0}","\u{1F4DD}","\u{1F4DA}","\u{1F50D}","\u26A1","\u2764\uFE0F","\u2753","\u26A0\uFE0F","\u{1F331}","\u{1F3C1}","\u{1F527}","\u{1F4AC}","\u{1F3A8}","\u{1F9E9}","\u{1F4CA}","\u{1F517}"],$={autoSaveDelay:300,branchColors:["#5b8def","#45b36b","#e89b3c","#9b72e7","#df6f9f"],defaultExpandDepth:99,animations:!0,layoutDirection:"right",exportScale:2,exportTransparentBackground:!1,language:"zh",showAssociationLinks:!0},ie={en:{openRibbon:"Open OneMind",openMindMap:"Open current note as mind map",returnMarkdown:"Return to Markdown editor",addChild:"Add child node",addSibling:"Add sibling node",duplicateNode:"Duplicate selected node",moveUp:"Move selected node up",moveDown:"Move selected node down",indentNode:"Indent selected node",outdentNode:"Outdent selected node",editNode:"Edit selected node",deleteNode:"Delete selected node",toggleNode:"Toggle selected node",setEmoji:"Set selected node emoji",clearEmoji:"Clear selected node emoji",addTag:"Add tag to selected nodes",clearTags:"Clear tags from selected nodes",copyBranch:"Copy selected branch as Markdown",pasteChild:"Paste Markdown as child nodes",pasteSibling:"Paste Markdown as sibling nodes",selectAll:"Select all nodes",expandAll:"Expand all nodes",collapseAll:"Collapse all nodes",fitMap:"Fit mind map to view",focusNode:"Focus selected node",searchNodes:"Search nodes",filterByTag:"Filter by tag",clearTagFilter:"Clear tag filter",toggleOutline:"Toggle outline",copyNodeLink:"Copy selected node link",exportSvg:"Export mind map as SVG",exportPng:"Export mind map as PNG",exportSelectedSvg:"Export selected branch as SVG",exportSelectedPng:"Export selected branch as PNG",markdown:"Markdown",addChildShort:"Add child",addSiblingShort:"Add sibling",duplicateShort:"Duplicate",setEmojiIcon:"Set emoji icon",addTagShort:"Add tag",deleteShort:"Delete",fitShort:"Fit",exportSvgShort:"Export SVG",exportPngShort:"Export PNG",copyLinkShort:"Copy node link",outline:"Outline",hideOutline:"Hide outline",openMarkdownFirst:"Open a Markdown note first.",emptyView:"Open a Markdown note to use OneMind.",reloadedExternal:"OneMind reloaded the external Markdown changes.",keptLocal:"OneMind kept the mind map edits and wrote them to Markdown.",exported:"Exported",copiedLink:"Copied OneMind node link.",copiedBranch:"Copied branch Markdown.",pastedMarkdown:"Pasted Markdown into OneMind.",clipboardEmpty:"Clipboard does not contain Markdown nodes.",tagFilterActive:"Tag filter",chooseEmoji:"Choose an emoji icon",enterTag:"Enter tag name",conflictTitle:"OneMind conflict",conflictBody:"This note changed on disk while the mind map has unsaved local edits. Choose which version should win.",reloadMarkdown:"Reload Markdown",keepEdits:"Keep OneMind edits",settingsTitle:"OneMind",language:"Language",languageDesc:"Choose the language used by OneMind UI.",english:"English",chinese:"\u4E2D\u6587",autoSaveDelay:"Auto-save delay",autoSaveDelayDesc:"Milliseconds to wait after a mind map edit before writing Markdown.",defaultExpandDepth:"Default expand depth",defaultExpandDepthDesc:"How many levels are expanded when a note opens. Use 99 for all.",layoutDirection:"Layout direction",layoutDirectionDesc:"Choose a classic right-facing tree or a balanced map with branches on both sides.",horizontalRight:"Horizontal right",balanced:"Balanced",layoutAnimation:"Layout animation",layoutAnimationDesc:"Animate node movement after edits.",branchColors:"Branch colors",branchColorsDesc:"Comma-separated CSS colors used for first-level branches.",resetBranchColors:"Reset branch colors",pngScale:"PNG export scale",pngScaleDesc:"Resolution multiplier used when exporting PNG files.",transparentPng:"Transparent PNG background",transparentPngDesc:"Leave PNG exports transparent instead of filling the Obsidian background color.",showAssociationLinks:"Show association links",showAssociationLinksDesc:"Draw dashed cross-branch links for local wikilinks like [[#Heading]] or [[Heading]].",saved:"Saved",unsaved:"Unsaved",saving:"Saving",nodesLabel:"nodes",selectedLabel:"selected",zoomLabel:"zoom"},zh:{openRibbon:"\u6253\u5F00 OneMind",openMindMap:"\u4EE5\u601D\u7EF4\u5BFC\u56FE\u6253\u5F00\u5F53\u524D\u7B14\u8BB0",returnMarkdown:"\u8FD4\u56DE Markdown \u7F16\u8F91\u5668",addChild:"\u6DFB\u52A0\u5B50\u8282\u70B9",addSibling:"\u6DFB\u52A0\u540C\u7EA7\u8282\u70B9",duplicateNode:"\u590D\u5236\u9009\u4E2D\u8282\u70B9",moveUp:"\u4E0A\u79FB\u9009\u4E2D\u8282\u70B9",moveDown:"\u4E0B\u79FB\u9009\u4E2D\u8282\u70B9",indentNode:"\u7F29\u8FDB\u9009\u4E2D\u8282\u70B9",outdentNode:"\u53D6\u6D88\u7F29\u8FDB\u9009\u4E2D\u8282\u70B9",editNode:"\u7F16\u8F91\u9009\u4E2D\u8282\u70B9",deleteNode:"\u5220\u9664\u9009\u4E2D\u8282\u70B9",toggleNode:"\u6298\u53E0/\u5C55\u5F00\u9009\u4E2D\u8282\u70B9",setEmoji:"\u8BBE\u7F6E\u9009\u4E2D\u8282\u70B9 Emoji",clearEmoji:"\u6E05\u9664\u9009\u4E2D\u8282\u70B9 Emoji",addTag:"\u7ED9\u9009\u4E2D\u8282\u70B9\u6DFB\u52A0\u6807\u7B7E",clearTags:"\u6E05\u9664\u9009\u4E2D\u8282\u70B9\u6807\u7B7E",copyBranch:"\u590D\u5236\u9009\u4E2D\u5206\u652F\u4E3A Markdown",pasteChild:"\u7C98\u8D34 Markdown \u4E3A\u5B50\u8282\u70B9",pasteSibling:"\u7C98\u8D34 Markdown \u4E3A\u540C\u7EA7\u8282\u70B9",selectAll:"\u9009\u62E9\u5168\u90E8\u8282\u70B9",expandAll:"\u5C55\u5F00\u5168\u90E8\u8282\u70B9",collapseAll:"\u6298\u53E0\u5168\u90E8\u8282\u70B9",fitMap:"\u9002\u5E94\u7A97\u53E3",focusNode:"\u805A\u7126\u9009\u4E2D\u8282\u70B9",searchNodes:"\u641C\u7D22\u8282\u70B9",filterByTag:"\u6309\u6807\u7B7E\u8FC7\u6EE4",clearTagFilter:"\u6E05\u9664\u6807\u7B7E\u8FC7\u6EE4",toggleOutline:"\u663E\u793A/\u9690\u85CF\u5927\u7EB2",copyNodeLink:"\u590D\u5236\u9009\u4E2D\u8282\u70B9\u94FE\u63A5",exportSvg:"\u5BFC\u51FA\u601D\u7EF4\u5BFC\u56FE\u4E3A SVG",exportPng:"\u5BFC\u51FA\u601D\u7EF4\u5BFC\u56FE\u4E3A PNG",exportSelectedSvg:"\u5BFC\u51FA\u9009\u4E2D\u5206\u652F\u4E3A SVG",exportSelectedPng:"\u5BFC\u51FA\u9009\u4E2D\u5206\u652F\u4E3A PNG",markdown:"Markdown",addChildShort:"\u6DFB\u52A0\u5B50\u8282\u70B9",addSiblingShort:"\u6DFB\u52A0\u540C\u7EA7",duplicateShort:"\u590D\u5236\u8282\u70B9",setEmojiIcon:"\u8BBE\u7F6E Emoji \u56FE\u6807",addTagShort:"\u6DFB\u52A0\u6807\u7B7E",deleteShort:"\u5220\u9664",fitShort:"\u9002\u5E94\u7A97\u53E3",exportSvgShort:"\u5BFC\u51FA SVG",exportPngShort:"\u5BFC\u51FA PNG",copyLinkShort:"\u590D\u5236\u8282\u70B9\u94FE\u63A5",outline:"\u5927\u7EB2",hideOutline:"\u9690\u85CF\u5927\u7EB2",openMarkdownFirst:"\u8BF7\u5148\u6253\u5F00\u4E00\u7BC7 Markdown \u7B14\u8BB0\u3002",emptyView:"\u6253\u5F00 Markdown \u7B14\u8BB0\u540E\u5373\u53EF\u4F7F\u7528 OneMind\u3002",reloadedExternal:"OneMind \u5DF2\u91CD\u65B0\u52A0\u8F7D\u5916\u90E8 Markdown \u4FEE\u6539\u3002",keptLocal:"OneMind \u5DF2\u4FDD\u7559\u5BFC\u56FE\u7F16\u8F91\u5E76\u5199\u56DE Markdown\u3002",exported:"\u5DF2\u5BFC\u51FA",copiedLink:"\u5DF2\u590D\u5236 OneMind \u8282\u70B9\u94FE\u63A5\u3002",copiedBranch:"\u5DF2\u590D\u5236\u5206\u652F Markdown\u3002",pastedMarkdown:"\u5DF2\u5C06 Markdown \u7C98\u8D34\u5230 OneMind\u3002",clipboardEmpty:"\u526A\u8D34\u677F\u91CC\u6CA1\u6709\u53EF\u7528\u7684 Markdown \u8282\u70B9\u3002",tagFilterActive:"\u6807\u7B7E\u8FC7\u6EE4",chooseEmoji:"\u9009\u62E9 Emoji \u56FE\u6807",enterTag:"\u8F93\u5165\u6807\u7B7E\u540D",conflictTitle:"OneMind \u51B2\u7A81",conflictBody:"\u8FD9\u7BC7\u7B14\u8BB0\u5728\u78C1\u76D8\u4E0A\u53D1\u751F\u4E86\u53D8\u5316\uFF0C\u540C\u65F6\u601D\u7EF4\u5BFC\u56FE\u91CC\u8FD8\u6709\u672A\u4FDD\u5B58\u7F16\u8F91\u3002\u8BF7\u9009\u62E9\u8981\u4FDD\u7559\u7684\u7248\u672C\u3002",reloadMarkdown:"\u91CD\u65B0\u52A0\u8F7D Markdown",keepEdits:"\u4FDD\u7559 OneMind \u7F16\u8F91",settingsTitle:"OneMind",language:"\u8BED\u8A00",languageDesc:"\u9009\u62E9 OneMind \u754C\u9762\u8BED\u8A00\u3002",english:"English",chinese:"\u4E2D\u6587",autoSaveDelay:"\u81EA\u52A8\u4FDD\u5B58\u5EF6\u8FDF",autoSaveDelayDesc:"\u5BFC\u56FE\u7F16\u8F91\u540E\u7B49\u5F85\u591A\u5C11\u6BEB\u79D2\u518D\u5199\u56DE Markdown\u3002",defaultExpandDepth:"\u9ED8\u8BA4\u5C55\u5F00\u6DF1\u5EA6",defaultExpandDepthDesc:"\u6253\u5F00\u7B14\u8BB0\u65F6\u9ED8\u8BA4\u5C55\u5F00\u7684\u5C42\u7EA7\u300299 \u8868\u793A\u5168\u90E8\u5C55\u5F00\u3002",layoutDirection:"\u5E03\u5C40\u65B9\u5411",layoutDirectionDesc:"\u9009\u62E9\u7ECF\u5178\u5411\u53F3\u6811\u5F62\u5E03\u5C40\uFF0C\u6216\u6839\u8282\u70B9\u5C45\u4E2D\u7684\u53CC\u5411\u5E73\u8861\u5E03\u5C40\u3002",horizontalRight:"\u6C34\u5E73\u5411\u53F3",balanced:"\u53CC\u5411\u5E73\u8861",layoutAnimation:"\u5E03\u5C40\u52A8\u753B",layoutAnimationDesc:"\u7F16\u8F91\u540E\u4E3A\u8282\u70B9\u79FB\u52A8\u6DFB\u52A0\u52A8\u753B\u3002",branchColors:"\u5206\u652F\u989C\u8272",branchColorsDesc:"\u4E00\u7EA7\u5206\u652F\u4F7F\u7528\u7684 CSS \u989C\u8272\uFF0C\u4F7F\u7528\u82F1\u6587\u9017\u53F7\u5206\u9694\u3002",resetBranchColors:"\u91CD\u7F6E\u5206\u652F\u989C\u8272",pngScale:"PNG \u5BFC\u51FA\u500D\u7387",pngScaleDesc:"\u5BFC\u51FA PNG \u6587\u4EF6\u65F6\u4F7F\u7528\u7684\u5206\u8FA8\u7387\u500D\u7387\u3002",transparentPng:"\u900F\u660E PNG \u80CC\u666F",transparentPngDesc:"\u5BFC\u51FA PNG \u65F6\u4FDD\u7559\u900F\u660E\u80CC\u666F\uFF0C\u800C\u4E0D\u662F\u586B\u5145 Obsidian \u80CC\u666F\u8272\u3002",showAssociationLinks:"\u663E\u793A\u5173\u8054\u7EBF",showAssociationLinksDesc:"\u4E3A [[#\u6807\u9898]] \u6216 [[\u6807\u9898]] \u8FD9\u7C7B\u672C\u5730 wikilink \u7ED8\u5236\u8DE8\u5206\u652F\u865A\u7EBF\u5173\u8054\u3002",saved:"\u5DF2\u4FDD\u5B58",unsaved:"\u672A\u4FDD\u5B58",saving:"\u4FDD\u5B58\u4E2D",nodesLabel:"\u8282\u70B9",selectedLabel:"\u5DF2\u9009",zoomLabel:"\u7F29\u653E"}},ke=180,S=42,X=230,C=18,Ee=4,V=class extends h.Plugin{constructor(){super(...arguments);this.settings=$}async onload(){this.settings=Object.assign({},$,await this.loadData()),this.registerView(L,e=>new T(e,this)),this.addRibbonIcon("git-fork",this.t("openRibbon"),()=>{this.openMindMap()}),this.addCommand({id:"open-onemind-view",name:this.t("openMindMap"),checkCallback:e=>{let t=this.getActiveMarkdownFile();return t?(e||this.openMindMap(t,this.getActiveHeadingAnchor()),!0):!1}}),this.addCommand({id:"return-to-markdown",name:this.t("returnMarkdown"),callback:()=>{let e=this.app.workspace.getActiveViewOfType(T);e&&e.openMarkdown()}}),this.addMindMapCommand("add-child-node",this.t("addChild"),e=>e.addChildNode()),this.addMindMapCommand("add-sibling-node",this.t("addSibling"),e=>e.addSiblingNode()),this.addMindMapCommand("duplicate-node",this.t("duplicateNode"),e=>e.duplicateSelectedNode()),this.addMindMapCommand("move-node-up",this.t("moveUp"),e=>e.moveSelectedNode("up")),this.addMindMapCommand("move-node-down",this.t("moveDown"),e=>e.moveSelectedNode("down")),this.addMindMapCommand("indent-node",this.t("indentNode"),e=>e.moveSelectedNode("indent")),this.addMindMapCommand("outdent-node",this.t("outdentNode"),e=>e.moveSelectedNode("outdent")),this.addMindMapCommand("edit-selected-node",this.t("editNode"),e=>e.editSelectedNode()),this.addMindMapCommand("delete-selected-node",this.t("deleteNode"),e=>e.deleteSelectedNode()),this.addMindMapCommand("toggle-selected-node",this.t("toggleNode"),e=>e.toggleSelectedNode()),this.addMindMapCommand("set-node-emoji",this.t("setEmoji"),e=>e.openEmojiPicker()),this.addMindMapCommand("clear-node-emoji",this.t("clearEmoji"),e=>e.clearSelectedEmoji()),this.addMindMapCommand("add-node-tag",this.t("addTag"),e=>e.openTagModal()),this.addMindMapCommand("clear-node-tags",this.t("clearTags"),e=>e.clearSelectedTags()),this.addMindMapCommand("select-all-nodes",this.t("selectAll"),e=>e.selectAllNodes()),this.addMindMapCommand("expand-all-nodes",this.t("expandAll"),e=>e.expandAllNodes()),this.addMindMapCommand("collapse-all-nodes",this.t("collapseAll"),e=>e.collapseAllNodes()),this.addMindMapCommand("fit-mind-map",this.t("fitMap"),e=>e.fitToView()),this.addMindMapCommand("focus-selected-node",this.t("focusNode"),e=>e.focusSelected()),this.addMindMapCommand("search-nodes",this.t("searchNodes"),e=>e.focusSearch()),this.addMindMapCommand("filter-by-tag",this.t("filterByTag"),e=>e.openTagFilterModal()),this.addMindMapCommand("clear-tag-filter",this.t("clearTagFilter"),e=>e.clearTagFilter()),this.addMindMapCommand("toggle-outline",this.t("toggleOutline"),e=>e.toggleOutline()),this.addMindMapCommand("copy-node-link",this.t("copyNodeLink"),e=>void e.copySelectedNodeLink()),this.addMindMapCommand("copy-branch-markdown",this.t("copyBranch"),e=>void e.copySelectedBranchMarkdown()),this.addMindMapCommand("paste-markdown-child",this.t("pasteChild"),e=>void e.pasteMarkdownAsChild()),this.addMindMapCommand("paste-markdown-sibling",this.t("pasteSibling"),e=>void e.pasteMarkdownAsSibling()),this.addMindMapCommand("export-svg",this.t("exportSvg"),e=>void e.exportSvg()),this.addMindMapCommand("export-png",this.t("exportPng"),e=>void e.exportPng()),this.addMindMapCommand("export-selected-svg",this.t("exportSelectedSvg"),e=>void e.exportSelectedSvg()),this.addMindMapCommand("export-selected-png",this.t("exportSelectedPng"),e=>void e.exportSelectedPng()),this.addSettingTab(new G(this.app,this))}onunload(){this.app.workspace.detachLeavesOfType(L)}async saveSettings(){await this.saveData(this.settings)}t(e){var t,i;return(i=(t=ie[this.settings.language])==null?void 0:t[e])!=null?i:ie.en[e]}refreshOpenViews(){this.app.workspace.getLeavesOfType(L).forEach(e=>{let t=e.view;t instanceof T&&t.applySettings()})}addMindMapCommand(e,t,i){this.addCommand({id:e,name:t,checkCallback:n=>{let r=this.app.workspace.getActiveViewOfType(T);return r?(n||i(r),!0):!1}})}getActiveMarkdownFile(){var t;let e=this.app.workspace.getActiveViewOfType(h.MarkdownView);return(t=e==null?void 0:e.file)!=null?t:null}getActiveHeadingAnchor(){let e=this.app.workspace.getActiveViewOfType(h.MarkdownView);if(!e)return null;let t=e.editor.getCursor();for(let i=t.line;i>=0;i-=1){let n=/^(#{1,6})\s+(.+?)\s*$/.exec(e.editor.getLine(i));if(n)return N(n[2])}return null}async openMindMap(e=this.getActiveMarkdownFile(),t=null){if(!e){new h.Notice(this.t("openMarkdownFirst"));return}await this.app.workspace.getLeaf(!1).setViewState({type:L,state:{file:e.path,heading:t!=null?t:void 0},active:!0})}},T=class extends h.ItemView{constructor(e,t){super(e);this.file=null;this.root=null;this.selectedId=null;this.selectedIds=new Set;this.positions=[];this.searchQuery="";this.searchMatches=[];this.activeSearchIndex=-1;this.saveTimer=null;this.isSaving=!1;this.history=[];this.future=[];this.scale=1;this.panX=80;this.panY=80;this.panning=null;this.dragState=null;this.longPressTimer=null;this.dropTarget=null;this.dragMarkerEl=null;this.lastSavedMarkdown="";this.hasLocalUnsavedChange=!1;this.documentPrefix="";this.conflictModalOpen=!1;this.pendingFocus=null;this.outlineVisible=!0;this.tagFilter=null;this.plugin=t}getViewType(){return L}getDisplayText(){return this.file?`OneMind: ${this.file.basename}`:"OneMind"}getIcon(){return"git-fork"}async setState(e,t){await super.setState(e,t),this.file=e.file?this.app.vault.getAbstractFileByPath(e.file):null,this.pendingFocus={node:e.node,heading:e.heading},await this.loadFile()}getState(){var e,t,i;return{file:(t=(e=this.file)==null?void 0:e.path)!=null?t:"",node:(i=this.selectedId)!=null?i:void 0}}async onOpen(){this.contentEl.empty(),this.contentEl.addClass("onemind-view"),this.contentEl.toggleClass("is-animation-disabled",!this.plugin.settings.animations);let e=this.contentEl.createDiv({cls:"onemind-toolbar"});this.addIconButton(e,"file-text",this.plugin.t("markdown"),()=>void this.openMarkdown()),this.addIconButton(e,"plus",this.plugin.t("addChildShort"),()=>this.addChildNode()),this.addIconButton(e,"corner-down-right",this.plugin.t("addSiblingShort"),()=>this.addSiblingNode()),this.addIconButton(e,"copy-plus",this.plugin.t("duplicateShort"),()=>this.duplicateSelectedNode()),this.addIconButton(e,"smile",this.plugin.t("setEmojiIcon"),()=>this.openEmojiPicker()),this.addIconButton(e,"tag",this.plugin.t("addTagShort"),()=>this.openTagModal()),this.addIconButton(e,"filter",this.plugin.t("filterByTag"),()=>this.openTagFilterModal()),this.addIconButton(e,"trash-2",this.plugin.t("deleteShort"),()=>this.deleteSelectedNode()),this.addIconButton(e,"unfold-vertical",this.plugin.t("expandAll"),()=>this.expandAllNodes()),this.addIconButton(e,"fold-vertical",this.plugin.t("collapseAll"),()=>this.collapseAllNodes()),this.addIconButton(e,"minimize",this.plugin.t("fitShort"),()=>this.fitToView()),this.addIconButton(e,"download",this.plugin.t("exportSvgShort"),()=>void this.exportSvg()),this.addIconButton(e,"image",this.plugin.t("exportPngShort"),()=>void this.exportPng()),this.addIconButton(e,"link",this.plugin.t("copyLinkShort"),()=>void this.copySelectedNodeLink()),this.addIconButton(e,"copy",this.plugin.t("copyBranch"),()=>void this.copySelectedBranchMarkdown()),this.addIconButton(e,"list-tree",this.plugin.t("toggleOutline"),()=>this.toggleOutline()),this.addIconButton(e,"search",this.plugin.t("searchNodes"),()=>this.searchInputEl.focus());let t=e.createDiv({cls:"onemind-search"});this.searchInputEl=t.createEl("input",{cls:"onemind-search-input",attr:{type:"search",placeholder:this.plugin.t("searchNodes"),"aria-label":this.plugin.t("searchNodes")}}),this.searchCountEl=t.createEl("span",{cls:"onemind-search-count"}),this.searchInputEl.addEventListener("input",()=>this.updateSearch(this.searchInputEl.value)),this.searchInputEl.addEventListener("keydown",n=>this.onSearchKeyDown(n)),this.canvasEl=this.contentEl.createDiv({cls:"onemind-canvas"}),this.sceneEl=this.canvasEl.createDiv({cls:"onemind-scene"}),this.svgEl=U("svg"),this.svgEl.addClass("onemind-links"),this.nodesEl=this.sceneEl.createDiv({cls:"onemind-nodes"}),this.sceneEl.prepend(this.svgEl),this.outlineEl=this.canvasEl.createDiv({cls:"onemind-outline"});let i=this.outlineEl.createDiv({cls:"onemind-outline-header"});i.createSpan({text:this.plugin.t("outline")}),this.addIconButton(i,"x",this.plugin.t("hideOutline"),()=>this.toggleOutline(!1)),this.outlineListEl=this.outlineEl.createDiv({cls:"onemind-outline-list"}),this.statusEl=this.canvasEl.createDiv({cls:"onemind-status"}),this.registerDomEvent(this.canvasEl,"wheel",n=>this.onWheel(n)),this.registerDomEvent(this.canvasEl,"pointerdown",n=>this.onPointerDown(n)),this.registerDomEvent(window,"pointermove",n=>this.onPointerMove(n)),this.registerDomEvent(window,"pointerup",n=>this.onPointerUp(n)),this.registerDomEvent(this.contentEl,"keydown",n=>this.onKeyDown(n)),this.registerEvent(this.app.vault.on("modify",async n=>{if(!(!this.file||n.path!==this.file.path||this.isSaving)){if(this.hasLocalUnsavedChange){this.showConflictModal();return}this.loadFile()}})),await this.loadFile()}async openMarkdown(){this.file&&await this.leaf.setViewState({type:"markdown",state:{file:this.file.path},active:!0})}applySettings(){this.contentEl.toggleClass("is-animation-disabled",!this.plugin.settings.animations),this.render()}addIconButton(e,t,i,n){let r=e.createEl("button",{cls:"clickable-icon onemind-tool-button",attr:{"aria-label":i,title:i}});(0,h.setIcon)(r,t),r.onClickEvent(n)}async loadFile(){if(!this.file||!(this.file instanceof h.TFile)){this.renderEmpty(this.plugin.t("emptyView"));return}let e=await this.app.vault.read(this.file),t=A(e,this.file.basename);this.root=t.root,this.documentPrefix=t.prefix,ue(this.root,this.plugin.settings.defaultExpandDepth),this.lastSavedMarkdown=e,this.hasLocalUnsavedChange=!1,this.history=[],this.future=[],this.selectedId=this.selectedId&&y(this.root,this.selectedId)?this.selectedId:this.root.id,this.selectedIds=new Set([this.selectedId]),this.render(),this.applyPendingFocus()}renderEmpty(e){var t,i;this.root=null,(t=this.nodesEl)==null||t.empty(),(i=this.svgEl)==null||i.empty(),this.contentEl.createDiv({cls:"onemind-empty",text:e})}render(){if(!this.root)return;let e=this.tagFilter?he(this.root,this.tagFilter):this.root;if(this.positions=e?oe(e,this.plugin.settings.branchColors,this.plugin.settings.layoutDirection):[],this.refreshSearchMatches(),this.nodesEl.empty(),this.svgEl.empty(),this.dragMarkerEl=null,this.positions.length===0){this.renderOutline(),this.applyTransform();return}let t=ee(this.positions);this.svgEl.setAttrs({width:`${Math.max(1,t.width+300)}`,height:`${Math.max(1,t.height+180)}`,viewBox:`${t.minX-80} ${t.minY-80} ${t.width+160} ${t.height+160}`});for(let i of this.positions)i.parent&&this.drawLink(i);this.plugin.settings.showAssociationLinks&&this.drawAssociationLinks();for(let i of this.positions)this.renderNode(i);this.renderOutline(),this.updateStatus(),this.applyTransform()}renderOutline(){if(!this.root||!this.outlineListEl)return;if(this.outlineEl.toggleClass("is-hidden",!this.outlineVisible),this.outlineListEl.empty(),this.tagFilter){let t=this.outlineListEl.createDiv({cls:"onemind-outline-filter"});t.createSpan({text:`${this.plugin.t("tagFilterActive")}: #${this.tagFilter}`}),t.createEl("button",{text:"x"}).onClickEvent(()=>this.clearTagFilter())}let e=(t,i)=>{if(this.tagFilter&&!ce(t,this.tagFilter))return;let n=this.outlineListEl.createDiv({cls:"onemind-outline-row"});n.toggleClass("is-selected",this.selectedIds.has(t.id)),n.style.paddingLeft=`${8+i*14}px`;let r=k(t.text);if(r.emoji&&n.createSpan({cls:"onemind-outline-emoji",text:r.emoji}),n.createSpan({cls:"onemind-outline-label",text:H(r.displayLabel)}),t.collapsed&&t.children.length>0&&n.createSpan({cls:"onemind-outline-count",text:`${t.children.length}`}),n.onClickEvent(d=>{d.stopPropagation(),this.selectAndFocusNode(t.id)}),!t.collapsed)for(let d of t.children)e(d,i+1)};e(this.root,0)}renderNode(e){let t=this.nodesEl.createDiv({cls:"onemind-node"});t.toggleClass("is-root",e.depth===0),t.toggleClass("is-selected",this.selectedIds.has(e.node.id)),t.toggleClass("is-primary-selected",e.node.id===this.selectedId),t.toggleClass("is-search-match",this.searchMatches.includes(e.node.id)),t.toggleClass("is-active-search-match",this.activeSearchIndex>=0&&this.searchMatches[this.activeSearchIndex]===e.node.id),t.toggleClass("is-collapsed",e.node.collapsed),t.setAttr("data-node-id",e.node.id),t.setAttr("data-node-anchor",N(e.node.text)),t.setAttr("tabindex","0"),t.style.left=`${e.x}px`,t.style.top=`${e.y}px`,t.style.width=`${e.width}px`,t.style.borderColor=e.color;let i=k(e.node.text);i.emoji&&(t.createDiv({cls:"onemind-node-emoji",text:i.emoji}),t.addClass("has-emoji"));let n=t.createDiv({cls:"onemind-node-content"});if(Te(n,i.displayLabel,this.app),i.tags.length>0){let r=t.createDiv({cls:"onemind-node-tags"});for(let d of i.tags){let a=r.createSpan({cls:"onemind-node-tag",text:`#${d}`});a.toggleClass("is-active",this.tagFilter===d),a.onClickEvent(c=>{c.stopPropagation(),this.setTagFilter(d)})}}if(e.node.children.length>0){let r=t.createDiv({cls:"onemind-collapse"});(0,h.setIcon)(r,e.node.collapsed?"chevron-right":"chevron-down"),r.onClickEvent(d=>{d.stopPropagation(),this.toggleCollapse(e.node.id)})}t.onClickEvent(r=>this.handleNodeClick(r,e.node.id)),t.ondblclick=()=>this.editNode(e.node.id),t.addEventListener("pointerdown",r=>this.onNodePointerDown(r,e)),t.addEventListener("pointermove",()=>this.clearLongPressTimer()),t.addEventListener("pointerleave",()=>this.clearLongPressTimer()),t.addEventListener("contextmenu",r=>this.openNodeMenu(r,e.node.id))}openNodeMenu(e,t){e.preventDefault(),e.stopPropagation(),this.selectedIds.has(t)||(this.selectedId=t,this.selectedIds=new Set([t]),this.render());let i=new h.Menu;i.addItem(n=>n.setTitle(this.plugin.t("addChild")).setIcon("plus").onClick(()=>this.addChildNode())),i.addItem(n=>n.setTitle(this.plugin.t("addSibling")).setIcon("corner-down-right").onClick(()=>this.addSiblingNode())),i.addItem(n=>n.setTitle(this.plugin.t("editNode")).setIcon("pencil").onClick(()=>this.editSelectedNode())),i.addSeparator(),i.addItem(n=>n.setTitle(this.plugin.t("duplicateNode")).setIcon("copy-plus").onClick(()=>this.duplicateSelectedNode())),i.addItem(n=>n.setTitle(this.plugin.t("copyBranch")).setIcon("copy").onClick(()=>void this.copySelectedBranchMarkdown())),i.addItem(n=>n.setTitle(this.plugin.t("copyNodeLink")).setIcon("link").onClick(()=>void this.copySelectedNodeLink())),i.addSeparator(),i.addItem(n=>n.setTitle(this.plugin.t("setEmoji")).setIcon("smile").onClick(()=>this.openEmojiPicker())),i.addItem(n=>n.setTitle(this.plugin.t("addTag")).setIcon("tag").onClick(()=>this.openTagModal())),i.addItem(n=>n.setTitle(this.plugin.t("clearTags")).setIcon("tag").onClick(()=>this.clearSelectedTags())),i.addSeparator(),i.addItem(n=>n.setTitle(this.plugin.t("exportSelectedSvg")).setIcon("download").onClick(()=>void this.exportSelectedSvg())),i.addItem(n=>n.setTitle(this.plugin.t("exportSelectedPng")).setIcon("image").onClick(()=>void this.exportSelectedPng())),i.addSeparator(),i.addItem(n=>n.setTitle(this.plugin.t("deleteNode")).setIcon("trash-2").onClick(()=>this.deleteSelectedNode())),i.showAtMouseEvent(e)}openNodeMenuAt(e,t,i){let n=new MouseEvent("contextmenu",{clientX:t,clientY:i,bubbles:!0,cancelable:!0});this.openNodeMenu(n,e)}drawLink(e){let t=this.positions.find(v=>v.node===e.parent);if(!t)return;let i=U("path"),n=e.x>=t.x,r=n?t.x+t.width:t.x,d=t.y+S/2,a=n?e.x:e.x+e.width,c=e.y+S/2,u=Math.max(60,Math.abs(a-r)*.45)*(n?1:-1);i.setAttrs({d:`M ${r} ${d} C ${r+u} ${d}, ${a-u} ${c}, ${a} ${c}`,stroke:e.color,fill:"none"}),this.svgEl.appendChild(i)}drawAssociationLinks(){let e=new Map;for(let i of this.positions)e.set(N(i.node.text),i);let t=new Set;for(let i of this.positions){let n=ae(i.node.text,this.file);for(let r of n){let d=e.get(r);if(!d||d.node.id===i.node.id)continue;let a=[i.node.id,d.node.id].sort().join(":");t.has(a)||(t.add(a),this.drawAssociationLink(i,d))}}}drawAssociationLink(e,t){let i=U("path");i.addClass("onemind-association-link");let n=e.x+e.width/2,r=e.y+S/2,d=t.x+t.width/2,a=t.y+S/2,c=(n+d)/2,u=Math.max(80,Math.abs(a-r)*.35),v=Math.min(r,a)-u;i.setAttrs({d:`M ${n} ${r} Q ${c} ${v}, ${d} ${a}`,fill:"none"}),this.svgEl.appendChild(i)}selectNode(e){this.selectedId=e,this.selectedIds=new Set([e]),this.render()}selectAndFocusNode(e){this.selectedId=e,this.selectedIds=new Set([e]),this.expandAncestors(e),this.render(),this.focusSelected()}applyPendingFocus(){if(!this.root||!this.pendingFocus)return;let e=this.resolveFocusTarget(this.pendingFocus);this.pendingFocus=null,e&&window.setTimeout(()=>this.selectAndFocusNode(e.id),0)}resolveFocusTarget(e){if(!this.root)return null;if(e.node){let t=y(this.root,e.node);if(t)return t;let i=Z(this.root,e.node);if(i)return i}return e.heading?Z(this.root,e.heading):null}handleNodeClick(e,t){if(e.metaKey||e.ctrlKey){this.toggleNodeSelection(t);return}if(e.shiftKey&&this.selectedId){this.selectRange(this.selectedId,t);return}this.selectNode(t)}toggleNodeSelection(e){var t;this.selectedIds.has(e)&&this.selectedIds.size>1?(this.selectedIds.delete(e),this.selectedId===e&&(this.selectedId=(t=this.selectedIds.values().next().value)!=null?t:null)):(this.selectedIds.add(e),this.selectedId=e),this.render()}selectRange(e,t){let i=this.positions.map(c=>c.node.id),n=i.indexOf(e),r=i.indexOf(t);if(n===-1||r===-1){this.selectNode(t);return}let[d,a]=nthis.setSelectedEmoji(e)).open()}clearSelectedEmoji(){this.setSelectedEmoji(null)}openTagModal(){!this.root||this.selectedIds.size===0||new W(this.app,this.plugin.t("enterTag"),e=>this.addTagToSelected(e)).open()}openTagFilterModal(){this.root&&new Q(this.app,this.getAllTags(),this.plugin.t("filterByTag"),e=>this.setTagFilter(e)).open()}clearTagFilter(){this.tagFilter=null,this.render()}setTagFilter(e){let t=J(e);if(!t)return;this.tagFilter=t,this.render();let i=this.positions.find(n=>k(n.node.text).tags.includes(t));i&&this.selectAndFocusNode(i.node.id)}getAllTags(){return this.root?[...new Set(B(this.root).flatMap(e=>k(e.text).tags))].sort():[]}clearSelectedTags(){if(!this.root)return;let e=this.getSelectedNodes();if(e.length!==0){this.pushHistory();for(let t of e)t.text=Pe(t.text);this.scheduleSave(),this.render()}}addTagToSelected(e){if(!this.root)return;let t=J(e);if(!t)return;let i=this.getSelectedNodes();if(i.length!==0){this.pushHistory();for(let n of i)n.text=De(n.text,t);this.scheduleSave(),this.render()}}setSelectedEmoji(e){if(!this.root)return;let t=this.getSelectedNodes();if(t.length!==0){this.pushHistory();for(let i of t){let n=re(i.text);i.text=e?`${e} ${n.label}`:n.label}this.scheduleSave(),this.render()}}editNode(e){if(!this.root)return;let t=y(this.root,e),i=this.nodesEl.querySelector(`[data-node-id="${e}"]`);if(!t||!i)return;this.selectedId=e,i.empty(),i.addClass("is-editing");let n=i.createEl("textarea",{cls:"onemind-editor"});n.value=t.text,n.focus(),n.select();let r=!1,d=()=>{if(r)return;r=!0;let a=n.value.trim()||"Untitled";this.pushHistory(),t.text=a,this.scheduleSave(),this.render()};n.addEventListener("keydown",a=>{a.key==="Enter"&&!a.shiftKey&&(a.preventDefault(),d()),a.key==="Escape"&&(a.preventDefault(),this.render())}),n.addEventListener("blur",d,{once:!0})}addChildNode(){var i,n;if(!this.root)return;let e=(n=y(this.root,(i=this.selectedId)!=null?i:this.root.id))!=null?n:this.root;this.pushHistory();let t=E("New idea",R(e,I(this.root,e.id)));e.children.push(t),e.collapsed=!1,this.selectedId=t.id,this.scheduleSave(),this.render(),window.setTimeout(()=>this.editNode(t.id),20)}addSiblingNode(){if(!this.root||!this.selectedId||this.selectedId===this.root.id){this.addChildNode();return}let e=b(this.root,this.selectedId),t=y(this.root,this.selectedId);if(!e||!t)return;this.pushHistory();let i=e.children.findIndex(r=>r.id===t.id),n=E("New idea",t.kind);e.children.splice(i+1,0,n),this.selectedId=n.id,this.scheduleSave(),this.render(),window.setTimeout(()=>this.editNode(n.id),20)}duplicateSelectedNode(){if(!this.root||!this.selectedId||this.selectedId===this.root.id)return;let e=b(this.root,this.selectedId),t=y(this.root,this.selectedId);if(!e||!t)return;this.pushHistory();let i=e.children.findIndex(r=>r.id===t.id),n=le(t);e.children.splice(i+1,0,n),this.selectedId=n.id,this.selectedIds=new Set([n.id]),this.scheduleSave(),this.render(),this.focusSelected()}moveSelectedNode(e){if(!this.root||!this.selectedId||this.selectedId===this.root.id)return;if(this.pushHistory(),!Oe(this.root,this.selectedId,e)){this.history.pop();return}this.scheduleSave(),this.render(),this.focusSelected()}deleteSelectedNode(){var i;if(!this.root)return;let e=this.getEditableSelectedIds();if(e.length===0)return;this.pushHistory();let t=this.selectedId?b(this.root,this.selectedId):null;ge(this.root,new Set(e)),this.selectedId=(i=t==null?void 0:t.id)!=null?i:this.root.id,this.selectedIds=new Set([this.selectedId]),this.scheduleSave(),this.render()}toggleCollapse(e){if(!this.root)return;let t=y(this.root,e);t&&(t.collapsed=!t.collapsed,this.render())}toggleSelectedNode(){if(!this.root)return;let e=this.getSelectedNodes();if(e.length===0)return;let t=e.some(i=>!i.collapsed&&i.children.length>0);for(let i of e)i.children.length>0&&(i.collapsed=t);this.render()}expandAllNodes(){this.root&&(j(this.root,!1),this.render())}collapseAllNodes(){this.root&&(j(this.root,!0),this.root.collapsed=!1,this.selectedId=this.root.id,this.render(),this.focusSelected())}scheduleSave(){!this.root||!this.file||(this.hasLocalUnsavedChange=!0,this.updateStatus(),this.saveTimer&&window.clearTimeout(this.saveTimer),this.saveTimer=window.setTimeout(()=>void this.saveNow(),this.plugin.settings.autoSaveDelay))}showConflictModal(){this.conflictModalOpen||(this.conflictModalOpen=!0,new q(this.app,{title:this.plugin.t("conflictTitle"),body:this.plugin.t("conflictBody"),reload:this.plugin.t("reloadMarkdown"),keep:this.plugin.t("keepEdits")},async()=>{this.conflictModalOpen=!1,await this.loadFile(),new h.Notice(this.plugin.t("reloadedExternal"))},async()=>{this.conflictModalOpen=!1,await this.saveNow(),new h.Notice(this.plugin.t("keptLocal"))},()=>{this.conflictModalOpen=!1}).open())}async saveNow(){if(!this.root||!this.file)return;let e=this.serializeCurrentMarkdown();this.isSaving=!0,this.updateStatus(),await this.app.vault.modify(this.file,e),this.lastSavedMarkdown=e,this.hasLocalUnsavedChange=!1,this.isSaving=!1,this.updateStatus()}pushHistory(){this.root&&(this.history.push(this.serializeCurrentMarkdown()),this.history.length>80&&this.history.shift(),this.future=[])}undo(){var i,n;if(!this.root||this.history.length===0)return;this.future.push(this.serializeCurrentMarkdown());let e=this.history.pop();if(!e)return;let t=A(e,(n=(i=this.file)==null?void 0:i.basename)!=null?n:"Mind map");this.root=t.root,this.documentPrefix=t.prefix,this.selectedId=this.root.id,this.selectedIds=new Set([this.root.id]),this.render(),this.saveNow()}redo(){var i,n;if(!this.root)return;let e=this.future.pop();if(!e)return;this.history.push(this.serializeCurrentMarkdown());let t=A(e,(n=(i=this.file)==null?void 0:i.basename)!=null?n:"Mind map");this.root=t.root,this.documentPrefix=t.prefix,this.selectedId=this.root.id,this.selectedIds=new Set([this.root.id]),this.render(),this.saveNow()}onKeyDown(e){if(e.target instanceof HTMLTextAreaElement)return;let t=e.ctrlKey||e.metaKey;if(t&&e.key.toLowerCase()==="z"&&e.shiftKey){e.preventDefault(),this.redo();return}if(t&&e.key.toLowerCase()==="z"){e.preventDefault(),this.undo();return}if(t&&e.key.toLowerCase()==="a"){e.preventDefault(),this.selectAllNodes();return}if(t&&e.key==="="){e.preventDefault(),this.zoomAtCenter(1.1);return}if(t&&e.key==="-"){e.preventDefault(),this.zoomAtCenter(.9);return}if(t&&e.shiftKey&&e.key.toLowerCase()==="f"){e.preventDefault(),this.fitToView();return}if(t&&e.key.toLowerCase()==="f"){e.preventDefault(),this.focusSelected();return}if(e.altKey&&e.key==="ArrowUp"){e.preventDefault(),this.moveSelectedNode("up");return}if(e.altKey&&e.key==="ArrowDown"){e.preventDefault(),this.moveSelectedNode("down");return}if(e.altKey&&e.key==="ArrowRight"){e.preventDefault(),this.moveSelectedNode("indent");return}if(e.altKey&&e.key==="ArrowLeft"){e.preventDefault(),this.moveSelectedNode("outdent");return}e.key==="Tab"?(e.preventDefault(),this.addChildNode()):e.key==="/"?(e.preventDefault(),this.focusSearch()):e.key==="Enter"?(e.preventDefault(),this.addSiblingNode()):e.key==="F2"?(e.preventDefault(),this.selectedId&&this.editNode(this.selectedId)):e.key==="Delete"||e.key==="Backspace"?(e.preventDefault(),this.deleteSelectedNode()):e.key===" "?(e.preventDefault(),this.selectedId&&this.toggleCollapse(this.selectedId)):e.key.startsWith("Arrow")&&(e.preventDefault(),this.moveSelection(e.key))}onSearchKeyDown(e){e.key==="Enter"?(e.preventDefault(),this.jumpSearch(e.shiftKey?-1:1)):e.key==="Escape"?(e.preventDefault(),this.searchInputEl.value="",this.updateSearch(""),this.contentEl.focus()):(e.key==="ArrowDown"||e.key==="ArrowUp")&&(e.preventDefault(),this.jumpSearch(e.key==="ArrowDown"?1:-1))}focusSearch(){this.searchInputEl.focus(),this.searchInputEl.select()}toggleOutline(e){this.outlineVisible=e!=null?e:!this.outlineVisible,this.renderOutline()}selectAllNodes(){this.root&&(this.selectedIds=new Set(B(this.root).map(e=>e.id)),this.selectedId=this.root.id,this.render())}async exportSvg(){!this.root||!this.file||this.positions.length===0||await this.exportSvgFromPositions(this.positions,this.file.basename,this.getExportPath("svg"))}async exportPng(){!this.root||!this.file||this.positions.length===0||await this.exportPngFromPositions(this.positions,this.file.basename,this.getExportPath("png"))}async exportSelectedSvg(){let e=this.getSelectedBranchExport();e&&await this.exportSvgFromPositions(e.positions,e.title,this.getExportPath("svg",e.slug))}async exportSelectedPng(){let e=this.getSelectedBranchExport();e&&await this.exportPngFromPositions(e.positions,e.title,this.getExportPath("png",e.slug))}async exportSvgFromPositions(e,t,i){let n=se(e,t,this.plugin.settings.showAssociationLinks);await this.writeTextFile(i,n),new h.Notice(`${this.plugin.t("exported")} ${i}`)}async exportPngFromPositions(e,t,i){let n=se(e,t,this.plugin.settings.showAssociationLinks),r=await Ie(n,this.plugin.settings.exportScale,this.plugin.settings.exportTransparentBackground),d=this.app.vault.getAbstractFileByPath(i);d instanceof h.TFile?await this.app.vault.modifyBinary(d,r):await this.app.vault.createBinary(i,r),new h.Notice(`${this.plugin.t("exported")} ${i}`)}getSelectedBranchExport(){if(!this.root||!this.selectedId)return null;let e=y(this.root,this.selectedId);if(!e)return null;let t=F(e);j(t,!1);let i=oe(t,this.plugin.settings.branchColors,this.plugin.settings.layoutDirection),n=de(e.text);return{positions:i,title:n,slug:N(e.text)||"branch"}}async copySelectedNodeLink(){if(!this.file||!this.root||!this.selectedId)return;let e=y(this.root,this.selectedId);if(!e)return;let t=this.app.vault.getName(),i=this.file.path,n=N(e.text),r=`obsidian://open?vault=${encodeURIComponent(t)}&file=${encodeURIComponent(i)}#${encodeURIComponent(n)}`;await navigator.clipboard.writeText(r),new h.Notice(this.plugin.t("copiedLink"))}async copySelectedBranchMarkdown(){if(!this.root||!this.selectedId)return;let e=y(this.root,this.selectedId);e&&(await navigator.clipboard.writeText(ne(F(e))),new h.Notice(this.plugin.t("copiedBranch")))}async pasteMarkdownAsChild(){var i,n;if(!this.root)return;let e=(n=y(this.root,(i=this.selectedId)!=null?i:this.root.id))!=null?n:this.root,t=await this.readClipboardNodes(e.kind,I(this.root,e.id)+1);t.length!==0&&(this.pushHistory(),e.children.push(...t),e.collapsed=!1,this.selectedId=t[0].id,this.selectedIds=new Set([t[0].id]),this.scheduleSave(),this.render(),new h.Notice(this.plugin.t("pastedMarkdown")))}async pasteMarkdownAsSibling(){if(!this.root||!this.selectedId||this.selectedId===this.root.id){await this.pasteMarkdownAsChild();return}let e=y(this.root,this.selectedId),t=b(this.root,this.selectedId);if(!e||!t)return;let i=await this.readClipboardNodes(e.kind,I(this.root,e.id));if(i.length===0)return;this.pushHistory();let n=t.children.findIndex(r=>r.id===e.id);t.children.splice(n+1,0,...i),this.selectedId=i[0].id,this.selectedIds=new Set([i[0].id]),this.scheduleSave(),this.render(),new h.Notice(this.plugin.t("pastedMarkdown"))}async readClipboardNodes(e,t){let i=await navigator.clipboard.readText();if(!i.trim())return new h.Notice(this.plugin.t("clipboardEmpty")),[];let n=A(i,"Clipboard"),d=(n.root.text==="Clipboard"&&n.root.children.length>0?n.root.children:[n.root]).map(a=>F(a));for(let a of d)pe(a,e,t);return d.length===0&&new h.Notice(this.plugin.t("clipboardEmpty")),d}updateSearch(e){if(this.searchQuery=e.trim().toLowerCase(),this.refreshSearchMatches(),this.activeSearchIndex=this.searchMatches.length>0?0:-1,this.activeSearchIndex>=0){let t=this.searchMatches[this.activeSearchIndex];t&&this.selectAndFocusNode(t)}else this.render();this.updateSearchCount()}refreshSearchMatches(){if(!this.root||this.searchQuery.length===0){this.searchMatches=[],this.activeSearchIndex=-1,this.updateSearchCount();return}this.searchMatches=B(this.root).filter(e=>e.text.toLowerCase().includes(this.searchQuery)).map(e=>e.id),this.activeSearchIndex>=this.searchMatches.length&&(this.activeSearchIndex=this.searchMatches.length-1),this.searchMatches.length===0&&(this.activeSearchIndex=-1),this.updateSearchCount()}updateSearchCount(){if(!this.searchCountEl)return;if(this.searchQuery.length===0){this.searchCountEl.setText("");return}let e=this.activeSearchIndex>=0?this.activeSearchIndex+1:0;this.searchCountEl.setText(`${e}/${this.searchMatches.length}`)}jumpSearch(e){if(this.searchMatches.length===0)return;this.activeSearchIndex=(this.activeSearchIndex+e+this.searchMatches.length)%this.searchMatches.length;let t=this.searchMatches[this.activeSearchIndex];t&&this.selectAndFocusNode(t),this.updateSearchCount()}moveSelection(e){if(!this.root||!this.selectedId)return;let t=y(this.root,this.selectedId);if(!t)return;if(e==="ArrowRight"){if(t.collapsed&&t.children.length>0){this.toggleCollapse(t.id);return}let d=t.children[0];d&&this.selectAndFocusNode(d.id);return}if(e==="ArrowLeft"){let d=b(this.root,t.id);t.children.length>0&&!t.collapsed?this.toggleCollapse(t.id):d&&this.selectAndFocusNode(d.id);return}let i=this.positions.slice().sort((d,a)=>d.y-a.y||d.x-a.x),n=i.findIndex(d=>d.node.id===t.id),r=i[n+(e==="ArrowDown"?1:-1)];r&&this.selectAndFocusNode(r.node.id)}expandAncestors(e){if(!this.root)return;let t=fe(this.root,e);for(let i of t.slice(0,-1))i.collapsed=!1}getSelectedNodes(){return this.root?[...this.selectedIds].map(e=>y(this.root,e)).filter(e=>!!e):[]}getEditableSelectedNodes(){return this.root?this.getSelectedNodes().filter(e=>{var t;return e.id!==((t=this.root)==null?void 0:t.id)}):[]}getEditableSelectedIds(){return this.getEditableSelectedNodes().map(e=>e.id)}onWheel(e){e.preventDefault();let t=e.deltaY>0?.92:1.08;this.scale=D(this.scale*t,.35,2.2),this.applyTransform()}onPointerDown(e){let t=e.target;t.closest(".onemind-node")||t.closest(".onemind-toolbar")||(this.panning={x:e.clientX,y:e.clientY,panX:this.panX,panY:this.panY},this.canvasEl.setPointerCapture(e.pointerId))}onPointerMove(e){if(this.dragState){this.onNodePointerMove(e);return}this.panning&&(this.panX=this.panning.panX+e.clientX-this.panning.x,this.panY=this.panning.panY+e.clientY-this.panning.y,this.applyTransform())}onPointerUp(e){if(this.dragState){this.finishNodeDrag(e);return}this.stopPanning()}stopPanning(){this.panning=null}onNodePointerDown(e,t){var r;if(e.button!==0||t.node.id===((r=this.root)==null?void 0:r.id)||e.target instanceof HTMLTextAreaElement)return;let i=e.target;if(i.closest(".onemind-collapse")||i.closest(".onemind-wikilink"))return;e.stopPropagation(),this.selectedId=t.node.id,this.selectedIds=new Set([t.node.id]),this.nodesEl.querySelectorAll(".is-selected").forEach(d=>d.removeClass("is-selected")),e.currentTarget.addClass("is-selected");let n=this.toScenePoint(e.clientX,e.clientY);this.dragState={nodeId:t.node.id,pointerId:e.pointerId,startClientX:e.clientX,startClientY:e.clientY,offsetX:n.x-t.x,offsetY:n.y-t.y,originalX:t.x,originalY:t.y,dragging:!1,el:e.currentTarget},this.dragState.el.setPointerCapture(e.pointerId),(e.pointerType==="touch"||e.pointerType==="pen")&&(this.longPressTimer=window.setTimeout(()=>{this.dragState=null,this.openNodeMenuAt(t.node.id,e.clientX,e.clientY)},560))}onNodePointerMove(e){if(!this.dragState)return;this.clearLongPressTimer();let t=e.clientX-this.dragState.startClientX,i=e.clientY-this.dragState.startClientY;if(!this.dragState.dragging&&Math.hypot(t,i)!n.has(l.node.id)),d=r.find(l=>e>=l.x&&e<=l.x+l.width&&t>=l.y&&t<=l.y+l.height);if(d)return{mode:"child",parentId:d.node.id,index:d.node.children.length,targetId:d.node.id};let a=null,c=Number.POSITIVE_INFINITY;for(let l of r){if(l.node.id===this.root.id)continue;let f=Math.hypot(e-(l.x+l.width/2),t-(l.y+l.height/2));fl.id===a.node.id),p=t{var d;return r.node.id===((d=this.dropTarget)==null?void 0:d.targetId)});if(!e)return;this.dragMarkerEl=this.nodesEl.createDiv({cls:"onemind-drop-marker"});let t=this.dropTarget.index<=((n=(i=b(this.root,this.dropTarget.targetId))==null?void 0:i.children.findIndex(r=>{var d;return r.id===((d=this.dropTarget)==null?void 0:d.targetId)}))!=null?n:0);this.dragMarkerEl.style.left=`${e.x-10}px`,this.dragMarkerEl.style.top=`${t?e.y-C/2:e.y+e.height+C/2}px`,this.dragMarkerEl.style.width=`${e.width+20}px`}clearDropTarget(){var e;this.nodesEl.querySelectorAll(".is-drop-child").forEach(t=>t.removeClass("is-drop-child")),(e=this.dragMarkerEl)==null||e.remove(),this.dragMarkerEl=null}clearLongPressTimer(){this.longPressTimer&&(window.clearTimeout(this.longPressTimer),this.longPressTimer=null)}toScenePoint(e,t){let i=this.canvasEl.getBoundingClientRect();return{x:(e-i.left-this.panX)/this.scale,y:(t-i.top-this.panY)/this.scale}}serializeCurrentMarkdown(){return this.root?`${this.documentPrefix}${ne(this.root)}`:this.documentPrefix}getExportPath(e,t){var r,d,a,c;let i=(d=(r=this.file)==null?void 0:r.parent)!=null&&d.path&&this.file.parent.path!=="/"?`${this.file.parent.path}/`:"",n=t?`.${t}`:"";return`${i}${(c=(a=this.file)==null?void 0:a.basename)!=null?c:"mind-map"}.onemind${n}.${e}`}async writeTextFile(e,t){let i=this.app.vault.getAbstractFileByPath(e);i instanceof h.TFile?await this.app.vault.modify(i,t):await this.app.vault.create(e,t)}zoomAtCenter(e){this.scale=D(this.scale*e,.35,2.2),this.applyTransform()}focusSelected(){let e=this.positions.find(i=>i.node.id===this.selectedId);if(!e)return;let t=this.canvasEl.getBoundingClientRect();this.panX=t.width/2-(e.x+e.width/2)*this.scale,this.panY=t.height/2-(e.y+S/2)*this.scale,this.applyTransform()}fitToView(){if(this.positions.length===0)return;let e=ee(this.positions),t=this.canvasEl.getBoundingClientRect(),i=(t.width-120)/Math.max(e.width,1),n=(t.height-120)/Math.max(e.height,1);this.scale=D(Math.min(i,n),.35,1.4),this.panX=t.width/2-(e.minX+e.width/2)*this.scale,this.panY=t.height/2-(e.minY+e.height/2)*this.scale,this.applyTransform()}applyTransform(){this.sceneEl&&(this.sceneEl.style.transform=`translate(${this.panX}px, ${this.panY}px) scale(${this.scale})`,this.updateStatus())}updateStatus(){if(!this.statusEl)return;let e=this.root?B(this.root).length:0,t=this.positions.length,i=this.isSaving?this.plugin.t("saving"):this.hasLocalUnsavedChange?this.plugin.t("unsaved"):this.plugin.t("saved"),n=this.tagFilter?`#${this.tagFilter}`:"";this.statusEl.setText([`${t}/${e} ${this.plugin.t("nodesLabel")}`,`${this.selectedIds.size} ${this.plugin.t("selectedLabel")}`,`${this.plugin.t("zoomLabel")} ${Math.round(this.scale*100)}%`,n,i].filter(Boolean).join(" \xB7 "))}},G=class extends h.PluginSettingTab{constructor(s,e){super(s,e),this.plugin=e}display(){let{containerEl:s}=this;s.empty(),s.createEl("h2",{text:this.plugin.t("settingsTitle")}),new h.Setting(s).setName(this.plugin.t("language")).setDesc(this.plugin.t("languageDesc")).addDropdown(t=>{t.addOption("zh",this.plugin.t("chinese")).addOption("en",this.plugin.t("english")).setValue(this.plugin.settings.language).onChange(async i=>{this.plugin.settings.language=i,await this.plugin.saveSettings(),this.plugin.refreshOpenViews(),this.display()})}),new h.Setting(s).setName(this.plugin.t("autoSaveDelay")).setDesc(this.plugin.t("autoSaveDelayDesc")).addText(t=>{t.setPlaceholder("300").setValue(String(this.plugin.settings.autoSaveDelay)).onChange(async i=>{let n=Number.parseInt(i,10);this.plugin.settings.autoSaveDelay=Number.isFinite(n)?D(n,0,5e3):$.autoSaveDelay,await this.plugin.saveSettings(),this.plugin.refreshOpenViews()})}),new h.Setting(s).setName(this.plugin.t("defaultExpandDepth")).setDesc(this.plugin.t("defaultExpandDepthDesc")).addSlider(t=>{t.setLimits(1,99,1).setDynamicTooltip().setValue(this.plugin.settings.defaultExpandDepth).onChange(async i=>{this.plugin.settings.defaultExpandDepth=i,await this.plugin.saveSettings(),this.plugin.refreshOpenViews()})}),new h.Setting(s).setName(this.plugin.t("layoutDirection")).setDesc(this.plugin.t("layoutDirectionDesc")).addDropdown(t=>{t.addOption("right",this.plugin.t("horizontalRight")).addOption("balanced",this.plugin.t("balanced")).setValue(this.plugin.settings.layoutDirection).onChange(async i=>{this.plugin.settings.layoutDirection=i,await this.plugin.saveSettings(),this.plugin.refreshOpenViews()})}),new h.Setting(s).setName(this.plugin.t("layoutAnimation")).setDesc(this.plugin.t("layoutAnimationDesc")).addToggle(t=>{t.setValue(this.plugin.settings.animations).onChange(async i=>{this.plugin.settings.animations=i,await this.plugin.saveSettings(),this.plugin.refreshOpenViews()})}),new h.Setting(s).setName(this.plugin.t("showAssociationLinks")).setDesc(this.plugin.t("showAssociationLinksDesc")).addToggle(t=>{t.setValue(this.plugin.settings.showAssociationLinks).onChange(async i=>{this.plugin.settings.showAssociationLinks=i,await this.plugin.saveSettings(),this.plugin.refreshOpenViews()})}),new h.Setting(s).setName(this.plugin.t("branchColors")).setDesc(this.plugin.t("branchColorsDesc")).addTextArea(t=>{t.setValue(this.plugin.settings.branchColors.join(", ")).onChange(async i=>{let n=i.split(",").map(r=>r.trim()).filter(Boolean);this.plugin.settings.branchColors=n.length>0?n:$.branchColors,await this.plugin.saveSettings(),this.plugin.refreshOpenViews()}),t.inputEl.rows=2});let e=s.createDiv({cls:"onemind-settings-palette"});this.plugin.settings.branchColors.forEach((t,i)=>{new h.Setting(e).setName(`${this.plugin.t("branchColors")} ${i+1}`).addColorPicker(n=>{n.setValue(t).onChange(async r=>{this.plugin.settings.branchColors[i]=r,await this.plugin.saveSettings(),this.plugin.refreshOpenViews()})})}),new h.Setting(s).setName(this.plugin.t("resetBranchColors")).addButton(t=>{t.setButtonText(this.plugin.t("resetBranchColors")).onClick(async()=>{this.plugin.settings.branchColors=[...$.branchColors],await this.plugin.saveSettings(),this.plugin.refreshOpenViews(),this.display()})}),new h.Setting(s).setName(this.plugin.t("pngScale")).setDesc(this.plugin.t("pngScaleDesc")).addSlider(t=>{t.setLimits(1,4,1).setDynamicTooltip().setValue(this.plugin.settings.exportScale).onChange(async i=>{this.plugin.settings.exportScale=i,await this.plugin.saveSettings()})}),new h.Setting(s).setName(this.plugin.t("transparentPng")).setDesc(this.plugin.t("transparentPngDesc")).addToggle(t=>{t.setValue(this.plugin.settings.exportTransparentBackground).onChange(async i=>{this.plugin.settings.exportTransparentBackground=i,await this.plugin.saveSettings()})})}},_=class extends h.SuggestModal{constructor(s,e,t){super(s),this.onChoose=t,this.setPlaceholder(e)}getSuggestions(s){let e=s.trim().toLowerCase();return e?te.filter(t=>t.includes(e)):te}renderSuggestion(s,e){e.createSpan({cls:"onemind-emoji-suggestion",text:s})}onChooseSuggestion(s){this.onChoose(s)}},W=class extends h.Modal{constructor(s,e,t){super(s),this.placeholder=e,this.onSubmit=t}onOpen(){this.contentEl.empty();let s=this.contentEl.createEl("input",{cls:"onemind-tag-input",attr:{type:"text",placeholder:this.placeholder}});s.focus(),s.addEventListener("keydown",e=>{e.key==="Enter"?(e.preventDefault(),this.onSubmit(s.value),this.close()):e.key==="Escape"&&(e.preventDefault(),this.close())})}onClose(){this.contentEl.empty()}},Q=class extends h.SuggestModal{constructor(s,e,t,i){super(s),this.tags=e,this.onChoose=i,this.setPlaceholder(t)}getSuggestions(s){let e=J(s).toLowerCase(),t=e?this.tags.filter(i=>i.toLowerCase().includes(e)):this.tags;return e&&!t.includes(e)?[e,...t]:t}renderSuggestion(s,e){e.createSpan({cls:"onemind-tag-suggestion",text:`#${s}`})}onChooseSuggestion(s){this.onChoose(s)}},q=class extends h.Modal{constructor(s,e,t,i,n){super(s),this.labels=e,this.onReload=t,this.onKeep=i,this.onCloseCallback=n}onOpen(){let{contentEl:s}=this;s.empty(),s.createEl("h2",{text:this.labels.title}),s.createEl("p",{text:this.labels.body});let e=s.createDiv({cls:"onemind-modal-actions"});e.createEl("button",{text:this.labels.reload}).onClickEvent(async()=>{this.close(),await this.onReload()}),e.createEl("button",{cls:"mod-cta",text:this.labels.keep}).onClickEvent(async()=>{this.close(),await this.onKeep()})}onClose(){this.contentEl.empty(),this.onCloseCallback()}};function A(o,s){let e=o.split(/\r?\n/),t=0;if(e[0]==="---"){let a=e.findIndex((c,u)=>u>0&&c==="---");a>0&&(t=a+1)}for(;tc0?`${e.slice(0,n).join(` +var K=Object.defineProperty;var Me=Object.getOwnPropertyDescriptor;var xe=Object.getOwnPropertyNames;var ye=Object.prototype.hasOwnProperty;var Se=(o,s)=>{for(var e in s)K(o,e,{get:s[e],enumerable:!0})},be=(o,s,e,t)=>{if(s&&typeof s=="object"||typeof s=="function")for(let i of xe(s))!ye.call(o,i)&&i!==e&&K(o,i,{get:()=>s[i],enumerable:!(t=Me(s,i))||t.enumerable});return o};var ke=o=>be(K({},"__esModule",{value:!0}),o);var Ve={};Se(Ve,{default:()=>V});module.exports=ke(Ve);var l=require("obsidian"),L="onemind-view",ie=["\u{1F4A1}","\u2705","\u{1F525}","\u2B50","\u{1F3AF}","\u{1F680}","\u{1F4CC}","\u{1F4CE}","\u{1F9E0}","\u{1F4DD}","\u{1F4DA}","\u{1F50D}","\u26A1","\u2764\uFE0F","\u2753","\u26A0\uFE0F","\u{1F331}","\u{1F3C1}","\u{1F527}","\u{1F4AC}","\u{1F3A8}","\u{1F9E9}","\u{1F4CA}","\u{1F517}"],$={autoSaveDelay:300,branchColors:["#5b8def","#45b36b","#e89b3c","#9b72e7","#df6f9f"],defaultExpandDepth:99,animations:!0,layoutDirection:"right",exportScale:2,exportTransparentBackground:!1,language:"zh",showAssociationLinks:!0},ne={en:{openRibbon:"Open OneMind",openMindMap:"Open current note as mind map",createMindMap:"Create new mind map",newMindMapTitle:"New mind map",mindMapNamePlaceholder:"Mind map name",createButton:"Create",createdMindMap:"Created mind map",returnMarkdown:"Return to Markdown editor",addChild:"Add child node",addSibling:"Add sibling node",duplicateNode:"Duplicate selected node",moveUp:"Move selected node up",moveDown:"Move selected node down",indentNode:"Indent selected node",outdentNode:"Outdent selected node",editNode:"Edit selected node",deleteNode:"Delete selected node",toggleNode:"Toggle selected node",setEmoji:"Set selected node emoji",clearEmoji:"Clear selected node emoji",addTag:"Add tag to selected nodes",clearTags:"Clear tags from selected nodes",copyBranch:"Copy selected branch as Markdown",pasteChild:"Paste Markdown as child nodes",pasteSibling:"Paste Markdown as sibling nodes",selectAll:"Select all nodes",expandAll:"Expand all nodes",collapseAll:"Collapse all nodes",fitMap:"Fit mind map to view",focusNode:"Focus selected node",searchNodes:"Search nodes",filterByTag:"Filter by tag",clearTagFilter:"Clear tag filter",toggleOutline:"Toggle outline",copyNodeLink:"Copy selected node link",exportSvg:"Export mind map as SVG",exportPng:"Export mind map as PNG",exportSelectedSvg:"Export selected branch as SVG",exportSelectedPng:"Export selected branch as PNG",markdown:"Markdown",addChildShort:"Add child",addSiblingShort:"Add sibling",duplicateShort:"Duplicate",setEmojiIcon:"Set emoji icon",addTagShort:"Add tag",deleteShort:"Delete",fitShort:"Fit",exportSvgShort:"Export SVG",exportPngShort:"Export PNG",copyLinkShort:"Copy node link",outline:"Outline",hideOutline:"Hide outline",openMarkdownFirst:"Open a Markdown note first.",emptyView:"Open a Markdown note to use OneMind.",reloadedExternal:"OneMind reloaded the external Markdown changes.",keptLocal:"OneMind kept the mind map edits and wrote them to Markdown.",exported:"Exported",copiedLink:"Copied OneMind node link.",copiedBranch:"Copied branch Markdown.",pastedMarkdown:"Pasted Markdown into OneMind.",clipboardEmpty:"Clipboard does not contain Markdown nodes.",tagFilterActive:"Tag filter",chooseEmoji:"Choose an emoji icon",enterTag:"Enter tag name",conflictTitle:"OneMind conflict",conflictBody:"This note changed on disk while the mind map has unsaved local edits. Choose which version should win.",reloadMarkdown:"Reload Markdown",keepEdits:"Keep OneMind edits",settingsTitle:"OneMind",language:"Language",languageDesc:"Choose the language used by OneMind UI.",english:"English",chinese:"\u4E2D\u6587",autoSaveDelay:"Auto-save delay",autoSaveDelayDesc:"Milliseconds to wait after a mind map edit before writing Markdown.",defaultExpandDepth:"Default expand depth",defaultExpandDepthDesc:"How many levels are expanded when a note opens. Use 99 for all.",layoutDirection:"Layout direction",layoutDirectionDesc:"Choose a classic right-facing tree or a balanced map with branches on both sides.",horizontalRight:"Horizontal right",balanced:"Balanced",layoutAnimation:"Layout animation",layoutAnimationDesc:"Animate node movement after edits.",branchColors:"Branch colors",branchColorsDesc:"Comma-separated CSS colors used for first-level branches.",resetBranchColors:"Reset branch colors",pngScale:"PNG export scale",pngScaleDesc:"Resolution multiplier used when exporting PNG files.",transparentPng:"Transparent PNG background",transparentPngDesc:"Leave PNG exports transparent instead of filling the Obsidian background color.",showAssociationLinks:"Show association links",showAssociationLinksDesc:"Draw dashed cross-branch links for local wikilinks like [[#Heading]] or [[Heading]].",saved:"Saved",unsaved:"Unsaved",saving:"Saving",nodesLabel:"nodes",selectedLabel:"selected",zoomLabel:"zoom"},zh:{openRibbon:"\u6253\u5F00 OneMind",openMindMap:"\u4EE5\u601D\u7EF4\u5BFC\u56FE\u6253\u5F00\u5F53\u524D\u7B14\u8BB0",createMindMap:"\u65B0\u5EFA\u601D\u7EF4\u5BFC\u56FE",newMindMapTitle:"\u65B0\u5EFA\u601D\u7EF4\u5BFC\u56FE",mindMapNamePlaceholder:"\u601D\u7EF4\u5BFC\u56FE\u540D\u79F0",createButton:"\u521B\u5EFA",createdMindMap:"\u5DF2\u521B\u5EFA\u601D\u7EF4\u5BFC\u56FE",returnMarkdown:"\u8FD4\u56DE Markdown \u7F16\u8F91\u5668",addChild:"\u6DFB\u52A0\u5B50\u8282\u70B9",addSibling:"\u6DFB\u52A0\u540C\u7EA7\u8282\u70B9",duplicateNode:"\u590D\u5236\u9009\u4E2D\u8282\u70B9",moveUp:"\u4E0A\u79FB\u9009\u4E2D\u8282\u70B9",moveDown:"\u4E0B\u79FB\u9009\u4E2D\u8282\u70B9",indentNode:"\u7F29\u8FDB\u9009\u4E2D\u8282\u70B9",outdentNode:"\u53D6\u6D88\u7F29\u8FDB\u9009\u4E2D\u8282\u70B9",editNode:"\u7F16\u8F91\u9009\u4E2D\u8282\u70B9",deleteNode:"\u5220\u9664\u9009\u4E2D\u8282\u70B9",toggleNode:"\u6298\u53E0/\u5C55\u5F00\u9009\u4E2D\u8282\u70B9",setEmoji:"\u8BBE\u7F6E\u9009\u4E2D\u8282\u70B9 Emoji",clearEmoji:"\u6E05\u9664\u9009\u4E2D\u8282\u70B9 Emoji",addTag:"\u7ED9\u9009\u4E2D\u8282\u70B9\u6DFB\u52A0\u6807\u7B7E",clearTags:"\u6E05\u9664\u9009\u4E2D\u8282\u70B9\u6807\u7B7E",copyBranch:"\u590D\u5236\u9009\u4E2D\u5206\u652F\u4E3A Markdown",pasteChild:"\u7C98\u8D34 Markdown \u4E3A\u5B50\u8282\u70B9",pasteSibling:"\u7C98\u8D34 Markdown \u4E3A\u540C\u7EA7\u8282\u70B9",selectAll:"\u9009\u62E9\u5168\u90E8\u8282\u70B9",expandAll:"\u5C55\u5F00\u5168\u90E8\u8282\u70B9",collapseAll:"\u6298\u53E0\u5168\u90E8\u8282\u70B9",fitMap:"\u9002\u5E94\u7A97\u53E3",focusNode:"\u805A\u7126\u9009\u4E2D\u8282\u70B9",searchNodes:"\u641C\u7D22\u8282\u70B9",filterByTag:"\u6309\u6807\u7B7E\u8FC7\u6EE4",clearTagFilter:"\u6E05\u9664\u6807\u7B7E\u8FC7\u6EE4",toggleOutline:"\u663E\u793A/\u9690\u85CF\u5927\u7EB2",copyNodeLink:"\u590D\u5236\u9009\u4E2D\u8282\u70B9\u94FE\u63A5",exportSvg:"\u5BFC\u51FA\u601D\u7EF4\u5BFC\u56FE\u4E3A SVG",exportPng:"\u5BFC\u51FA\u601D\u7EF4\u5BFC\u56FE\u4E3A PNG",exportSelectedSvg:"\u5BFC\u51FA\u9009\u4E2D\u5206\u652F\u4E3A SVG",exportSelectedPng:"\u5BFC\u51FA\u9009\u4E2D\u5206\u652F\u4E3A PNG",markdown:"Markdown",addChildShort:"\u6DFB\u52A0\u5B50\u8282\u70B9",addSiblingShort:"\u6DFB\u52A0\u540C\u7EA7",duplicateShort:"\u590D\u5236\u8282\u70B9",setEmojiIcon:"\u8BBE\u7F6E Emoji \u56FE\u6807",addTagShort:"\u6DFB\u52A0\u6807\u7B7E",deleteShort:"\u5220\u9664",fitShort:"\u9002\u5E94\u7A97\u53E3",exportSvgShort:"\u5BFC\u51FA SVG",exportPngShort:"\u5BFC\u51FA PNG",copyLinkShort:"\u590D\u5236\u8282\u70B9\u94FE\u63A5",outline:"\u5927\u7EB2",hideOutline:"\u9690\u85CF\u5927\u7EB2",openMarkdownFirst:"\u8BF7\u5148\u6253\u5F00\u4E00\u7BC7 Markdown \u7B14\u8BB0\u3002",emptyView:"\u6253\u5F00 Markdown \u7B14\u8BB0\u540E\u5373\u53EF\u4F7F\u7528 OneMind\u3002",reloadedExternal:"OneMind \u5DF2\u91CD\u65B0\u52A0\u8F7D\u5916\u90E8 Markdown \u4FEE\u6539\u3002",keptLocal:"OneMind \u5DF2\u4FDD\u7559\u5BFC\u56FE\u7F16\u8F91\u5E76\u5199\u56DE Markdown\u3002",exported:"\u5DF2\u5BFC\u51FA",copiedLink:"\u5DF2\u590D\u5236 OneMind \u8282\u70B9\u94FE\u63A5\u3002",copiedBranch:"\u5DF2\u590D\u5236\u5206\u652F Markdown\u3002",pastedMarkdown:"\u5DF2\u5C06 Markdown \u7C98\u8D34\u5230 OneMind\u3002",clipboardEmpty:"\u526A\u8D34\u677F\u91CC\u6CA1\u6709\u53EF\u7528\u7684 Markdown \u8282\u70B9\u3002",tagFilterActive:"\u6807\u7B7E\u8FC7\u6EE4",chooseEmoji:"\u9009\u62E9 Emoji \u56FE\u6807",enterTag:"\u8F93\u5165\u6807\u7B7E\u540D",conflictTitle:"OneMind \u51B2\u7A81",conflictBody:"\u8FD9\u7BC7\u7B14\u8BB0\u5728\u78C1\u76D8\u4E0A\u53D1\u751F\u4E86\u53D8\u5316\uFF0C\u540C\u65F6\u601D\u7EF4\u5BFC\u56FE\u91CC\u8FD8\u6709\u672A\u4FDD\u5B58\u7F16\u8F91\u3002\u8BF7\u9009\u62E9\u8981\u4FDD\u7559\u7684\u7248\u672C\u3002",reloadMarkdown:"\u91CD\u65B0\u52A0\u8F7D Markdown",keepEdits:"\u4FDD\u7559 OneMind \u7F16\u8F91",settingsTitle:"OneMind",language:"\u8BED\u8A00",languageDesc:"\u9009\u62E9 OneMind \u754C\u9762\u8BED\u8A00\u3002",english:"English",chinese:"\u4E2D\u6587",autoSaveDelay:"\u81EA\u52A8\u4FDD\u5B58\u5EF6\u8FDF",autoSaveDelayDesc:"\u5BFC\u56FE\u7F16\u8F91\u540E\u7B49\u5F85\u591A\u5C11\u6BEB\u79D2\u518D\u5199\u56DE Markdown\u3002",defaultExpandDepth:"\u9ED8\u8BA4\u5C55\u5F00\u6DF1\u5EA6",defaultExpandDepthDesc:"\u6253\u5F00\u7B14\u8BB0\u65F6\u9ED8\u8BA4\u5C55\u5F00\u7684\u5C42\u7EA7\u300299 \u8868\u793A\u5168\u90E8\u5C55\u5F00\u3002",layoutDirection:"\u5E03\u5C40\u65B9\u5411",layoutDirectionDesc:"\u9009\u62E9\u7ECF\u5178\u5411\u53F3\u6811\u5F62\u5E03\u5C40\uFF0C\u6216\u6839\u8282\u70B9\u5C45\u4E2D\u7684\u53CC\u5411\u5E73\u8861\u5E03\u5C40\u3002",horizontalRight:"\u6C34\u5E73\u5411\u53F3",balanced:"\u53CC\u5411\u5E73\u8861",layoutAnimation:"\u5E03\u5C40\u52A8\u753B",layoutAnimationDesc:"\u7F16\u8F91\u540E\u4E3A\u8282\u70B9\u79FB\u52A8\u6DFB\u52A0\u52A8\u753B\u3002",branchColors:"\u5206\u652F\u989C\u8272",branchColorsDesc:"\u4E00\u7EA7\u5206\u652F\u4F7F\u7528\u7684 CSS \u989C\u8272\uFF0C\u4F7F\u7528\u82F1\u6587\u9017\u53F7\u5206\u9694\u3002",resetBranchColors:"\u91CD\u7F6E\u5206\u652F\u989C\u8272",pngScale:"PNG \u5BFC\u51FA\u500D\u7387",pngScaleDesc:"\u5BFC\u51FA PNG \u6587\u4EF6\u65F6\u4F7F\u7528\u7684\u5206\u8FA8\u7387\u500D\u7387\u3002",transparentPng:"\u900F\u660E PNG \u80CC\u666F",transparentPngDesc:"\u5BFC\u51FA PNG \u65F6\u4FDD\u7559\u900F\u660E\u80CC\u666F\uFF0C\u800C\u4E0D\u662F\u586B\u5145 Obsidian \u80CC\u666F\u8272\u3002",showAssociationLinks:"\u663E\u793A\u5173\u8054\u7EBF",showAssociationLinksDesc:"\u4E3A [[#\u6807\u9898]] \u6216 [[\u6807\u9898]] \u8FD9\u7C7B\u672C\u5730 wikilink \u7ED8\u5236\u8DE8\u5206\u652F\u865A\u7EBF\u5173\u8054\u3002",saved:"\u5DF2\u4FDD\u5B58",unsaved:"\u672A\u4FDD\u5B58",saving:"\u4FDD\u5B58\u4E2D",nodesLabel:"\u8282\u70B9",selectedLabel:"\u5DF2\u9009",zoomLabel:"\u7F29\u653E"}},Ee=180,y=42,X=230,C=18,Ne=4,V=class extends l.Plugin{constructor(){super(...arguments);this.settings=$}async onload(){this.settings=Object.assign({},$,await this.loadData()),this.registerView(L,e=>new I(e,this)),this.addRibbonIcon("git-fork",this.t("openRibbon"),()=>{let e=this.getActiveMarkdownFile();e?this.openMindMap(e,this.getActiveHeadingAnchor()):this.createMindMap()}),this.addCommand({id:"create-onemind-note",name:this.t("createMindMap"),callback:()=>this.createMindMap()}),this.addCommand({id:"open-onemind-view",name:this.t("openMindMap"),checkCallback:e=>{let t=this.getActiveMarkdownFile();return t?(e||this.openMindMap(t,this.getActiveHeadingAnchor()),!0):!1}}),this.addCommand({id:"return-to-markdown",name:this.t("returnMarkdown"),callback:()=>{let e=this.app.workspace.getActiveViewOfType(I);e&&e.openMarkdown()}}),this.addMindMapCommand("add-child-node",this.t("addChild"),e=>e.addChildNode()),this.addMindMapCommand("add-sibling-node",this.t("addSibling"),e=>e.addSiblingNode()),this.addMindMapCommand("duplicate-node",this.t("duplicateNode"),e=>e.duplicateSelectedNode()),this.addMindMapCommand("move-node-up",this.t("moveUp"),e=>e.moveSelectedNode("up")),this.addMindMapCommand("move-node-down",this.t("moveDown"),e=>e.moveSelectedNode("down")),this.addMindMapCommand("indent-node",this.t("indentNode"),e=>e.moveSelectedNode("indent")),this.addMindMapCommand("outdent-node",this.t("outdentNode"),e=>e.moveSelectedNode("outdent")),this.addMindMapCommand("edit-selected-node",this.t("editNode"),e=>e.editSelectedNode()),this.addMindMapCommand("delete-selected-node",this.t("deleteNode"),e=>e.deleteSelectedNode()),this.addMindMapCommand("toggle-selected-node",this.t("toggleNode"),e=>e.toggleSelectedNode()),this.addMindMapCommand("set-node-emoji",this.t("setEmoji"),e=>e.openEmojiPicker()),this.addMindMapCommand("clear-node-emoji",this.t("clearEmoji"),e=>e.clearSelectedEmoji()),this.addMindMapCommand("add-node-tag",this.t("addTag"),e=>e.openTagModal()),this.addMindMapCommand("clear-node-tags",this.t("clearTags"),e=>e.clearSelectedTags()),this.addMindMapCommand("select-all-nodes",this.t("selectAll"),e=>e.selectAllNodes()),this.addMindMapCommand("expand-all-nodes",this.t("expandAll"),e=>e.expandAllNodes()),this.addMindMapCommand("collapse-all-nodes",this.t("collapseAll"),e=>e.collapseAllNodes()),this.addMindMapCommand("fit-mind-map",this.t("fitMap"),e=>e.fitToView()),this.addMindMapCommand("focus-selected-node",this.t("focusNode"),e=>e.focusSelected()),this.addMindMapCommand("search-nodes",this.t("searchNodes"),e=>e.focusSearch()),this.addMindMapCommand("filter-by-tag",this.t("filterByTag"),e=>e.openTagFilterModal()),this.addMindMapCommand("clear-tag-filter",this.t("clearTagFilter"),e=>e.clearTagFilter()),this.addMindMapCommand("toggle-outline",this.t("toggleOutline"),e=>e.toggleOutline()),this.addMindMapCommand("copy-node-link",this.t("copyNodeLink"),e=>void e.copySelectedNodeLink()),this.addMindMapCommand("copy-branch-markdown",this.t("copyBranch"),e=>void e.copySelectedBranchMarkdown()),this.addMindMapCommand("paste-markdown-child",this.t("pasteChild"),e=>void e.pasteMarkdownAsChild()),this.addMindMapCommand("paste-markdown-sibling",this.t("pasteSibling"),e=>void e.pasteMarkdownAsSibling()),this.addMindMapCommand("export-svg",this.t("exportSvg"),e=>void e.exportSvg()),this.addMindMapCommand("export-png",this.t("exportPng"),e=>void e.exportPng()),this.addMindMapCommand("export-selected-svg",this.t("exportSelectedSvg"),e=>void e.exportSelectedSvg()),this.addMindMapCommand("export-selected-png",this.t("exportSelectedPng"),e=>void e.exportSelectedPng()),this.addSettingTab(new G(this.app,this))}onunload(){this.app.workspace.detachLeavesOfType(L)}async saveSettings(){await this.saveData(this.settings)}t(e){var t,i;return(i=(t=ne[this.settings.language])==null?void 0:t[e])!=null?i:ne.en[e]}refreshOpenViews(){this.app.workspace.getLeavesOfType(L).forEach(e=>{let t=e.view;t instanceof I&&t.applySettings()})}addMindMapCommand(e,t,i){this.addCommand({id:e,name:t,checkCallback:n=>{let r=this.app.workspace.getActiveViewOfType(I);return r?(n||i(r),!0):!1}})}getActiveMarkdownFile(){var t;let e=this.app.workspace.getActiveViewOfType(l.MarkdownView);return(t=e==null?void 0:e.file)!=null?t:null}getActiveHeadingAnchor(){let e=this.app.workspace.getActiveViewOfType(l.MarkdownView);if(!e)return null;let t=e.editor.getCursor();for(let i=t.line;i>=0;i-=1){let n=/^(#{1,6})\s+(.+?)\s*$/.exec(e.editor.getLine(i));if(n)return N(n[2])}return null}async openMindMap(e=this.getActiveMarkdownFile(),t=null){if(!e){new l.Notice(this.t("openMarkdownFirst"));return}await this.app.workspace.getLeaf(!1).setViewState({type:L,state:{file:e.path,heading:t!=null?t:void 0},active:!0})}createMindMap(){new Q(this.app,this.t("createMindMap"),this.t("mindMapNamePlaceholder"),this.t("createButton"),this.t("newMindMapTitle"),async e=>{let t=await this.createMindMapFile(e);new l.Notice(`${this.t("createdMindMap")}: ${t.basename}`),await this.openMindMap(t)}).open()}async createMindMapFile(e){var c,u;let t=this.t("newMindMapTitle"),i=e.trim()||t,n=Te(i)||t,r=(u=(c=this.getActiveMarkdownFile())==null?void 0:c.parent)==null?void 0:u.path,a=r&&r!=="/"?`${r}/`:"",d=this.getAvailablePath(a,n);return await this.app.vault.create(d,`# ${i} + +- New idea +`)}getAvailablePath(e,t){let i=0;for(;;){let n=i===0?"":` ${i+1}`,r=`${e}${t}${n}.md`;if(!this.app.vault.getAbstractFileByPath(r))return r;i+=1}}},I=class extends l.ItemView{constructor(e,t){super(e);this.file=null;this.root=null;this.selectedId=null;this.selectedIds=new Set;this.positions=[];this.searchQuery="";this.searchMatches=[];this.activeSearchIndex=-1;this.saveTimer=null;this.isSaving=!1;this.history=[];this.future=[];this.scale=1;this.panX=80;this.panY=80;this.panning=null;this.dragState=null;this.longPressTimer=null;this.dropTarget=null;this.dragMarkerEl=null;this.lastSavedMarkdown="";this.hasLocalUnsavedChange=!1;this.documentPrefix="";this.conflictModalOpen=!1;this.pendingFocus=null;this.outlineVisible=!0;this.tagFilter=null;this.plugin=t}getViewType(){return L}getDisplayText(){return this.file?`OneMind: ${this.file.basename}`:"OneMind"}getIcon(){return"git-fork"}async setState(e,t){await super.setState(e,t),this.file=e.file?this.app.vault.getAbstractFileByPath(e.file):null,this.pendingFocus={node:e.node,heading:e.heading},await this.loadFile()}getState(){var e,t,i;return{file:(t=(e=this.file)==null?void 0:e.path)!=null?t:"",node:(i=this.selectedId)!=null?i:void 0}}async onOpen(){this.contentEl.empty(),this.contentEl.addClass("onemind-view"),this.contentEl.toggleClass("is-animation-disabled",!this.plugin.settings.animations);let e=this.contentEl.createDiv({cls:"onemind-toolbar"});this.addIconButton(e,"file-text",this.plugin.t("markdown"),()=>void this.openMarkdown()),this.addIconButton(e,"plus",this.plugin.t("addChildShort"),()=>this.addChildNode()),this.addIconButton(e,"corner-down-right",this.plugin.t("addSiblingShort"),()=>this.addSiblingNode()),this.addIconButton(e,"copy-plus",this.plugin.t("duplicateShort"),()=>this.duplicateSelectedNode()),this.addIconButton(e,"smile",this.plugin.t("setEmojiIcon"),()=>this.openEmojiPicker()),this.addIconButton(e,"tag",this.plugin.t("addTagShort"),()=>this.openTagModal()),this.addIconButton(e,"filter",this.plugin.t("filterByTag"),()=>this.openTagFilterModal()),this.addIconButton(e,"trash-2",this.plugin.t("deleteShort"),()=>this.deleteSelectedNode()),this.addIconButton(e,"unfold-vertical",this.plugin.t("expandAll"),()=>this.expandAllNodes()),this.addIconButton(e,"fold-vertical",this.plugin.t("collapseAll"),()=>this.collapseAllNodes()),this.addIconButton(e,"minimize",this.plugin.t("fitShort"),()=>this.fitToView()),this.addIconButton(e,"download",this.plugin.t("exportSvgShort"),()=>void this.exportSvg()),this.addIconButton(e,"image",this.plugin.t("exportPngShort"),()=>void this.exportPng()),this.addIconButton(e,"link",this.plugin.t("copyLinkShort"),()=>void this.copySelectedNodeLink()),this.addIconButton(e,"copy",this.plugin.t("copyBranch"),()=>void this.copySelectedBranchMarkdown()),this.addIconButton(e,"list-tree",this.plugin.t("toggleOutline"),()=>this.toggleOutline()),this.addIconButton(e,"search",this.plugin.t("searchNodes"),()=>this.searchInputEl.focus());let t=e.createDiv({cls:"onemind-search"});this.searchInputEl=t.createEl("input",{cls:"onemind-search-input",attr:{type:"search",placeholder:this.plugin.t("searchNodes"),"aria-label":this.plugin.t("searchNodes")}}),this.searchCountEl=t.createEl("span",{cls:"onemind-search-count"}),this.searchInputEl.addEventListener("input",()=>this.updateSearch(this.searchInputEl.value)),this.searchInputEl.addEventListener("keydown",n=>this.onSearchKeyDown(n)),this.canvasEl=this.contentEl.createDiv({cls:"onemind-canvas"}),this.sceneEl=this.canvasEl.createDiv({cls:"onemind-scene"}),this.svgEl=U("svg"),this.svgEl.addClass("onemind-links"),this.nodesEl=this.sceneEl.createDiv({cls:"onemind-nodes"}),this.sceneEl.prepend(this.svgEl),this.outlineEl=this.canvasEl.createDiv({cls:"onemind-outline"});let i=this.outlineEl.createDiv({cls:"onemind-outline-header"});i.createSpan({text:this.plugin.t("outline")}),this.addIconButton(i,"x",this.plugin.t("hideOutline"),()=>this.toggleOutline(!1)),this.outlineListEl=this.outlineEl.createDiv({cls:"onemind-outline-list"}),this.statusEl=this.canvasEl.createDiv({cls:"onemind-status"}),this.registerDomEvent(this.canvasEl,"wheel",n=>this.onWheel(n)),this.registerDomEvent(this.canvasEl,"pointerdown",n=>this.onPointerDown(n)),this.registerDomEvent(window,"pointermove",n=>this.onPointerMove(n)),this.registerDomEvent(window,"pointerup",n=>this.onPointerUp(n)),this.registerDomEvent(this.contentEl,"keydown",n=>this.onKeyDown(n)),this.registerEvent(this.app.vault.on("modify",async n=>{if(!(!this.file||n.path!==this.file.path||this.isSaving)){if(this.hasLocalUnsavedChange){this.showConflictModal();return}this.loadFile()}})),await this.loadFile()}async openMarkdown(){this.file&&await this.leaf.setViewState({type:"markdown",state:{file:this.file.path},active:!0})}applySettings(){this.contentEl.toggleClass("is-animation-disabled",!this.plugin.settings.animations),this.render()}addIconButton(e,t,i,n){let r=e.createEl("button",{cls:"clickable-icon onemind-tool-button",attr:{"aria-label":i,title:i}});(0,l.setIcon)(r,t),r.onClickEvent(n)}async loadFile(){if(!this.file||!(this.file instanceof l.TFile)){this.renderEmpty(this.plugin.t("emptyView"));return}let e=await this.app.vault.read(this.file),t=A(e,this.file.basename);this.root=t.root,this.documentPrefix=t.prefix,ge(this.root,this.plugin.settings.defaultExpandDepth),this.lastSavedMarkdown=e,this.hasLocalUnsavedChange=!1,this.history=[],this.future=[],this.selectedId=this.selectedId&&x(this.root,this.selectedId)?this.selectedId:this.root.id,this.selectedIds=new Set([this.selectedId]),this.render(),this.applyPendingFocus()}renderEmpty(e){var t,i;this.root=null,(t=this.nodesEl)==null||t.empty(),(i=this.svgEl)==null||i.empty(),this.contentEl.createDiv({cls:"onemind-empty",text:e})}render(){if(!this.root)return;let e=this.tagFilter?ce(this.root,this.tagFilter):this.root;if(this.positions=e?re(e,this.plugin.settings.branchColors,this.plugin.settings.layoutDirection):[],this.refreshSearchMatches(),this.nodesEl.empty(),this.svgEl.empty(),this.dragMarkerEl=null,this.positions.length===0){this.renderOutline(),this.applyTransform();return}let t=te(this.positions);this.svgEl.setAttrs({width:`${Math.max(1,t.width+300)}`,height:`${Math.max(1,t.height+180)}`,viewBox:`${t.minX-80} ${t.minY-80} ${t.width+160} ${t.height+160}`});for(let i of this.positions)i.parent&&this.drawLink(i);this.plugin.settings.showAssociationLinks&&this.drawAssociationLinks();for(let i of this.positions)this.renderNode(i);this.renderOutline(),this.updateStatus(),this.applyTransform()}renderOutline(){if(!this.root||!this.outlineListEl)return;if(this.outlineEl.toggleClass("is-hidden",!this.outlineVisible),this.outlineListEl.empty(),this.tagFilter){let t=this.outlineListEl.createDiv({cls:"onemind-outline-filter"});t.createSpan({text:`${this.plugin.t("tagFilterActive")}: #${this.tagFilter}`}),t.createEl("button",{text:"x"}).onClickEvent(()=>this.clearTagFilter())}let e=(t,i)=>{if(this.tagFilter&&!pe(t,this.tagFilter))return;let n=this.outlineListEl.createDiv({cls:"onemind-outline-row"});n.toggleClass("is-selected",this.selectedIds.has(t.id)),n.style.paddingLeft=`${8+i*14}px`;let r=k(t.text);if(r.emoji&&n.createSpan({cls:"onemind-outline-emoji",text:r.emoji}),n.createSpan({cls:"onemind-outline-label",text:H(r.displayLabel)}),t.collapsed&&t.children.length>0&&n.createSpan({cls:"onemind-outline-count",text:`${t.children.length}`}),n.onClickEvent(a=>{a.stopPropagation(),this.selectAndFocusNode(t.id)}),!t.collapsed)for(let a of t.children)e(a,i+1)};e(this.root,0)}renderNode(e){let t=this.nodesEl.createDiv({cls:"onemind-node"});t.toggleClass("is-root",e.depth===0),t.toggleClass("is-selected",this.selectedIds.has(e.node.id)),t.toggleClass("is-primary-selected",e.node.id===this.selectedId),t.toggleClass("is-search-match",this.searchMatches.includes(e.node.id)),t.toggleClass("is-active-search-match",this.activeSearchIndex>=0&&this.searchMatches[this.activeSearchIndex]===e.node.id),t.toggleClass("is-collapsed",e.node.collapsed),t.setAttr("data-node-id",e.node.id),t.setAttr("data-node-anchor",N(e.node.text)),t.setAttr("tabindex","0"),t.style.left=`${e.x}px`,t.style.top=`${e.y}px`,t.style.width=`${e.width}px`,t.style.borderColor=e.color;let i=k(e.node.text);i.emoji&&(t.createDiv({cls:"onemind-node-emoji",text:i.emoji}),t.addClass("has-emoji"));let n=t.createDiv({cls:"onemind-node-content"});if(Pe(n,i.displayLabel,this.app),i.tags.length>0){let r=t.createDiv({cls:"onemind-node-tags"});for(let a of i.tags){let d=r.createSpan({cls:"onemind-node-tag",text:`#${a}`});d.toggleClass("is-active",this.tagFilter===a),d.onClickEvent(c=>{c.stopPropagation(),this.setTagFilter(a)})}}if(e.node.children.length>0){let r=t.createDiv({cls:"onemind-collapse"});(0,l.setIcon)(r,e.node.collapsed?"chevron-right":"chevron-down"),r.onClickEvent(a=>{a.stopPropagation(),this.toggleCollapse(e.node.id)})}t.onClickEvent(r=>this.handleNodeClick(r,e.node.id)),t.ondblclick=()=>this.editNode(e.node.id),t.addEventListener("pointerdown",r=>this.onNodePointerDown(r,e)),t.addEventListener("pointermove",()=>this.clearLongPressTimer()),t.addEventListener("pointerleave",()=>this.clearLongPressTimer()),t.addEventListener("contextmenu",r=>this.openNodeMenu(r,e.node.id))}openNodeMenu(e,t){e.preventDefault(),e.stopPropagation(),this.selectedIds.has(t)||(this.selectedId=t,this.selectedIds=new Set([t]),this.render());let i=new l.Menu;i.addItem(n=>n.setTitle(this.plugin.t("addChild")).setIcon("plus").onClick(()=>this.addChildNode())),i.addItem(n=>n.setTitle(this.plugin.t("addSibling")).setIcon("corner-down-right").onClick(()=>this.addSiblingNode())),i.addItem(n=>n.setTitle(this.plugin.t("editNode")).setIcon("pencil").onClick(()=>this.editSelectedNode())),i.addSeparator(),i.addItem(n=>n.setTitle(this.plugin.t("duplicateNode")).setIcon("copy-plus").onClick(()=>this.duplicateSelectedNode())),i.addItem(n=>n.setTitle(this.plugin.t("copyBranch")).setIcon("copy").onClick(()=>void this.copySelectedBranchMarkdown())),i.addItem(n=>n.setTitle(this.plugin.t("copyNodeLink")).setIcon("link").onClick(()=>void this.copySelectedNodeLink())),i.addSeparator(),i.addItem(n=>n.setTitle(this.plugin.t("setEmoji")).setIcon("smile").onClick(()=>this.openEmojiPicker())),i.addItem(n=>n.setTitle(this.plugin.t("addTag")).setIcon("tag").onClick(()=>this.openTagModal())),i.addItem(n=>n.setTitle(this.plugin.t("clearTags")).setIcon("tag").onClick(()=>this.clearSelectedTags())),i.addSeparator(),i.addItem(n=>n.setTitle(this.plugin.t("exportSelectedSvg")).setIcon("download").onClick(()=>void this.exportSelectedSvg())),i.addItem(n=>n.setTitle(this.plugin.t("exportSelectedPng")).setIcon("image").onClick(()=>void this.exportSelectedPng())),i.addSeparator(),i.addItem(n=>n.setTitle(this.plugin.t("deleteNode")).setIcon("trash-2").onClick(()=>this.deleteSelectedNode())),i.showAtMouseEvent(e)}openNodeMenuAt(e,t,i){let n=new MouseEvent("contextmenu",{clientX:t,clientY:i,bubbles:!0,cancelable:!0});this.openNodeMenu(n,e)}drawLink(e){let t=this.positions.find(v=>v.node===e.parent);if(!t)return;let i=U("path"),n=e.x>=t.x,r=n?t.x+t.width:t.x,a=t.y+y/2,d=n?e.x:e.x+e.width,c=e.y+y/2,u=Math.max(60,Math.abs(d-r)*.45)*(n?1:-1);i.setAttrs({d:`M ${r} ${a} C ${r+u} ${a}, ${d-u} ${c}, ${d} ${c}`,stroke:e.color,fill:"none"}),this.svgEl.appendChild(i)}drawAssociationLinks(){let e=new Map;for(let i of this.positions)e.set(N(i.node.text),i);let t=new Set;for(let i of this.positions){let n=le(i.node.text,this.file);for(let r of n){let a=e.get(r);if(!a||a.node.id===i.node.id)continue;let d=[i.node.id,a.node.id].sort().join(":");t.has(d)||(t.add(d),this.drawAssociationLink(i,a))}}}drawAssociationLink(e,t){let i=U("path");i.addClass("onemind-association-link");let n=e.x+e.width/2,r=e.y+y/2,a=t.x+t.width/2,d=t.y+y/2,c=(n+a)/2,u=Math.max(80,Math.abs(d-r)*.35),v=Math.min(r,d)-u;i.setAttrs({d:`M ${n} ${r} Q ${c} ${v}, ${a} ${d}`,fill:"none"}),this.svgEl.appendChild(i)}selectNode(e){this.selectedId=e,this.selectedIds=new Set([e]),this.render()}selectAndFocusNode(e){this.selectedId=e,this.selectedIds=new Set([e]),this.expandAncestors(e),this.render(),this.focusSelected()}applyPendingFocus(){if(!this.root||!this.pendingFocus)return;let e=this.resolveFocusTarget(this.pendingFocus);this.pendingFocus=null,e&&window.setTimeout(()=>this.selectAndFocusNode(e.id),0)}resolveFocusTarget(e){if(!this.root)return null;if(e.node){let t=x(this.root,e.node);if(t)return t;let i=ee(this.root,e.node);if(i)return i}return e.heading?ee(this.root,e.heading):null}handleNodeClick(e,t){if(e.metaKey||e.ctrlKey){this.toggleNodeSelection(t);return}if(e.shiftKey&&this.selectedId){this.selectRange(this.selectedId,t);return}this.selectNode(t)}toggleNodeSelection(e){var t;this.selectedIds.has(e)&&this.selectedIds.size>1?(this.selectedIds.delete(e),this.selectedId===e&&(this.selectedId=(t=this.selectedIds.values().next().value)!=null?t:null)):(this.selectedIds.add(e),this.selectedId=e),this.render()}selectRange(e,t){let i=this.positions.map(c=>c.node.id),n=i.indexOf(e),r=i.indexOf(t);if(n===-1||r===-1){this.selectNode(t);return}let[a,d]=nthis.setSelectedEmoji(e)).open()}clearSelectedEmoji(){this.setSelectedEmoji(null)}openTagModal(){!this.root||this.selectedIds.size===0||new W(this.app,this.plugin.t("enterTag"),e=>this.addTagToSelected(e)).open()}openTagFilterModal(){this.root&&new q(this.app,this.getAllTags(),this.plugin.t("filterByTag"),e=>this.setTagFilter(e)).open()}clearTagFilter(){this.tagFilter=null,this.render()}setTagFilter(e){let t=Z(e);if(!t)return;this.tagFilter=t,this.render();let i=this.positions.find(n=>k(n.node.text).tags.includes(t));i&&this.selectAndFocusNode(i.node.id)}getAllTags(){return this.root?[...new Set(B(this.root).flatMap(e=>k(e.text).tags))].sort():[]}clearSelectedTags(){if(!this.root)return;let e=this.getSelectedNodes();if(e.length!==0){this.pushHistory();for(let t of e)t.text=$e(t.text);this.scheduleSave(),this.render()}}addTagToSelected(e){if(!this.root)return;let t=Z(e);if(!t)return;let i=this.getSelectedNodes();if(i.length!==0){this.pushHistory();for(let n of i)n.text=Le(n.text,t);this.scheduleSave(),this.render()}}setSelectedEmoji(e){if(!this.root)return;let t=this.getSelectedNodes();if(t.length!==0){this.pushHistory();for(let i of t){let n=ae(i.text);i.text=e?`${e} ${n.label}`:n.label}this.scheduleSave(),this.render()}}editNode(e){if(!this.root)return;let t=x(this.root,e),i=this.nodesEl.querySelector(`[data-node-id="${e}"]`);if(!t||!i)return;this.selectedId=e,i.empty(),i.addClass("is-editing");let n=i.createEl("textarea",{cls:"onemind-editor"});n.value=t.text,n.focus(),n.select();let r=!1,a=()=>{if(r)return;r=!0;let d=n.value.trim()||"Untitled";this.pushHistory(),t.text=d,this.scheduleSave(),this.render()};n.addEventListener("keydown",d=>{d.key==="Enter"&&!d.shiftKey&&(d.preventDefault(),a()),d.key==="Escape"&&(d.preventDefault(),this.render())}),n.addEventListener("blur",a,{once:!0})}addChildNode(){var i,n;if(!this.root)return;let e=(n=x(this.root,(i=this.selectedId)!=null?i:this.root.id))!=null?n:this.root;this.pushHistory();let t=E("New idea",R(e,T(this.root,e.id)));e.children.push(t),e.collapsed=!1,this.selectedId=t.id,this.scheduleSave(),this.render(),window.setTimeout(()=>this.editNode(t.id),20)}addSiblingNode(){if(!this.root||!this.selectedId||this.selectedId===this.root.id){this.addChildNode();return}let e=b(this.root,this.selectedId),t=x(this.root,this.selectedId);if(!e||!t)return;this.pushHistory();let i=e.children.findIndex(r=>r.id===t.id),n=E("New idea",t.kind);e.children.splice(i+1,0,n),this.selectedId=n.id,this.scheduleSave(),this.render(),window.setTimeout(()=>this.editNode(n.id),20)}duplicateSelectedNode(){if(!this.root||!this.selectedId||this.selectedId===this.root.id)return;let e=b(this.root,this.selectedId),t=x(this.root,this.selectedId);if(!e||!t)return;this.pushHistory();let i=e.children.findIndex(r=>r.id===t.id),n=he(t);e.children.splice(i+1,0,n),this.selectedId=n.id,this.selectedIds=new Set([n.id]),this.scheduleSave(),this.render(),this.focusSelected()}moveSelectedNode(e){if(!this.root||!this.selectedId||this.selectedId===this.root.id)return;if(this.pushHistory(),!Fe(this.root,this.selectedId,e)){this.history.pop();return}this.scheduleSave(),this.render(),this.focusSelected()}deleteSelectedNode(){var i;if(!this.root)return;let e=this.getEditableSelectedIds();if(e.length===0)return;this.pushHistory();let t=this.selectedId?b(this.root,this.selectedId):null;fe(this.root,new Set(e)),this.selectedId=(i=t==null?void 0:t.id)!=null?i:this.root.id,this.selectedIds=new Set([this.selectedId]),this.scheduleSave(),this.render()}toggleCollapse(e){if(!this.root)return;let t=x(this.root,e);t&&(t.collapsed=!t.collapsed,this.render())}toggleSelectedNode(){if(!this.root)return;let e=this.getSelectedNodes();if(e.length===0)return;let t=e.some(i=>!i.collapsed&&i.children.length>0);for(let i of e)i.children.length>0&&(i.collapsed=t);this.render()}expandAllNodes(){this.root&&(j(this.root,!1),this.render())}collapseAllNodes(){this.root&&(j(this.root,!0),this.root.collapsed=!1,this.selectedId=this.root.id,this.render(),this.focusSelected())}scheduleSave(){!this.root||!this.file||(this.hasLocalUnsavedChange=!0,this.updateStatus(),this.saveTimer&&window.clearTimeout(this.saveTimer),this.saveTimer=window.setTimeout(()=>void this.saveNow(),this.plugin.settings.autoSaveDelay))}showConflictModal(){this.conflictModalOpen||(this.conflictModalOpen=!0,new J(this.app,{title:this.plugin.t("conflictTitle"),body:this.plugin.t("conflictBody"),reload:this.plugin.t("reloadMarkdown"),keep:this.plugin.t("keepEdits")},async()=>{this.conflictModalOpen=!1,await this.loadFile(),new l.Notice(this.plugin.t("reloadedExternal"))},async()=>{this.conflictModalOpen=!1,await this.saveNow(),new l.Notice(this.plugin.t("keptLocal"))},()=>{this.conflictModalOpen=!1}).open())}async saveNow(){if(!this.root||!this.file)return;let e=this.serializeCurrentMarkdown();this.isSaving=!0,this.updateStatus(),await this.app.vault.modify(this.file,e),this.lastSavedMarkdown=e,this.hasLocalUnsavedChange=!1,this.isSaving=!1,this.updateStatus()}pushHistory(){this.root&&(this.history.push(this.serializeCurrentMarkdown()),this.history.length>80&&this.history.shift(),this.future=[])}undo(){var i,n;if(!this.root||this.history.length===0)return;this.future.push(this.serializeCurrentMarkdown());let e=this.history.pop();if(!e)return;let t=A(e,(n=(i=this.file)==null?void 0:i.basename)!=null?n:"Mind map");this.root=t.root,this.documentPrefix=t.prefix,this.selectedId=this.root.id,this.selectedIds=new Set([this.root.id]),this.render(),this.saveNow()}redo(){var i,n;if(!this.root)return;let e=this.future.pop();if(!e)return;this.history.push(this.serializeCurrentMarkdown());let t=A(e,(n=(i=this.file)==null?void 0:i.basename)!=null?n:"Mind map");this.root=t.root,this.documentPrefix=t.prefix,this.selectedId=this.root.id,this.selectedIds=new Set([this.root.id]),this.render(),this.saveNow()}onKeyDown(e){if(e.target instanceof HTMLTextAreaElement)return;let t=e.ctrlKey||e.metaKey;if(t&&e.key.toLowerCase()==="z"&&e.shiftKey){e.preventDefault(),this.redo();return}if(t&&e.key.toLowerCase()==="z"){e.preventDefault(),this.undo();return}if(t&&e.key.toLowerCase()==="a"){e.preventDefault(),this.selectAllNodes();return}if(t&&e.key==="="){e.preventDefault(),this.zoomAtCenter(1.1);return}if(t&&e.key==="-"){e.preventDefault(),this.zoomAtCenter(.9);return}if(t&&e.shiftKey&&e.key.toLowerCase()==="f"){e.preventDefault(),this.fitToView();return}if(t&&e.key.toLowerCase()==="f"){e.preventDefault(),this.focusSelected();return}if(e.altKey&&e.key==="ArrowUp"){e.preventDefault(),this.moveSelectedNode("up");return}if(e.altKey&&e.key==="ArrowDown"){e.preventDefault(),this.moveSelectedNode("down");return}if(e.altKey&&e.key==="ArrowRight"){e.preventDefault(),this.moveSelectedNode("indent");return}if(e.altKey&&e.key==="ArrowLeft"){e.preventDefault(),this.moveSelectedNode("outdent");return}e.key==="Tab"?(e.preventDefault(),this.addChildNode()):e.key==="/"?(e.preventDefault(),this.focusSearch()):e.key==="Enter"?(e.preventDefault(),this.addSiblingNode()):e.key==="F2"?(e.preventDefault(),this.selectedId&&this.editNode(this.selectedId)):e.key==="Delete"||e.key==="Backspace"?(e.preventDefault(),this.deleteSelectedNode()):e.key===" "?(e.preventDefault(),this.selectedId&&this.toggleCollapse(this.selectedId)):e.key.startsWith("Arrow")&&(e.preventDefault(),this.moveSelection(e.key))}onSearchKeyDown(e){e.key==="Enter"?(e.preventDefault(),this.jumpSearch(e.shiftKey?-1:1)):e.key==="Escape"?(e.preventDefault(),this.searchInputEl.value="",this.updateSearch(""),this.contentEl.focus()):(e.key==="ArrowDown"||e.key==="ArrowUp")&&(e.preventDefault(),this.jumpSearch(e.key==="ArrowDown"?1:-1))}focusSearch(){this.searchInputEl.focus(),this.searchInputEl.select()}toggleOutline(e){this.outlineVisible=e!=null?e:!this.outlineVisible,this.renderOutline()}selectAllNodes(){this.root&&(this.selectedIds=new Set(B(this.root).map(e=>e.id)),this.selectedId=this.root.id,this.render())}async exportSvg(){!this.root||!this.file||this.positions.length===0||await this.exportSvgFromPositions(this.positions,this.file.basename,this.getExportPath("svg"))}async exportPng(){!this.root||!this.file||this.positions.length===0||await this.exportPngFromPositions(this.positions,this.file.basename,this.getExportPath("png"))}async exportSelectedSvg(){let e=this.getSelectedBranchExport();e&&await this.exportSvgFromPositions(e.positions,e.title,this.getExportPath("svg",e.slug))}async exportSelectedPng(){let e=this.getSelectedBranchExport();e&&await this.exportPngFromPositions(e.positions,e.title,this.getExportPath("png",e.slug))}async exportSvgFromPositions(e,t,i){let n=oe(e,t,this.plugin.settings.showAssociationLinks);await this.writeTextFile(i,n),new l.Notice(`${this.plugin.t("exported")} ${i}`)}async exportPngFromPositions(e,t,i){let n=oe(e,t,this.plugin.settings.showAssociationLinks),r=await De(n,this.plugin.settings.exportScale,this.plugin.settings.exportTransparentBackground),a=this.app.vault.getAbstractFileByPath(i);a instanceof l.TFile?await this.app.vault.modifyBinary(a,r):await this.app.vault.createBinary(i,r),new l.Notice(`${this.plugin.t("exported")} ${i}`)}getSelectedBranchExport(){if(!this.root||!this.selectedId)return null;let e=x(this.root,this.selectedId);if(!e)return null;let t=F(e);j(t,!1);let i=re(t,this.plugin.settings.branchColors,this.plugin.settings.layoutDirection),n=de(e.text);return{positions:i,title:n,slug:N(e.text)||"branch"}}async copySelectedNodeLink(){if(!this.file||!this.root||!this.selectedId)return;let e=x(this.root,this.selectedId);if(!e)return;let t=this.app.vault.getName(),i=this.file.path,n=N(e.text),r=`obsidian://open?vault=${encodeURIComponent(t)}&file=${encodeURIComponent(i)}#${encodeURIComponent(n)}`;await navigator.clipboard.writeText(r),new l.Notice(this.plugin.t("copiedLink"))}async copySelectedBranchMarkdown(){if(!this.root||!this.selectedId)return;let e=x(this.root,this.selectedId);e&&(await navigator.clipboard.writeText(se(F(e))),new l.Notice(this.plugin.t("copiedBranch")))}async pasteMarkdownAsChild(){var i,n;if(!this.root)return;let e=(n=x(this.root,(i=this.selectedId)!=null?i:this.root.id))!=null?n:this.root,t=await this.readClipboardNodes(e.kind,T(this.root,e.id)+1);t.length!==0&&(this.pushHistory(),e.children.push(...t),e.collapsed=!1,this.selectedId=t[0].id,this.selectedIds=new Set([t[0].id]),this.scheduleSave(),this.render(),new l.Notice(this.plugin.t("pastedMarkdown")))}async pasteMarkdownAsSibling(){if(!this.root||!this.selectedId||this.selectedId===this.root.id){await this.pasteMarkdownAsChild();return}let e=x(this.root,this.selectedId),t=b(this.root,this.selectedId);if(!e||!t)return;let i=await this.readClipboardNodes(e.kind,T(this.root,e.id));if(i.length===0)return;this.pushHistory();let n=t.children.findIndex(r=>r.id===e.id);t.children.splice(n+1,0,...i),this.selectedId=i[0].id,this.selectedIds=new Set([i[0].id]),this.scheduleSave(),this.render(),new l.Notice(this.plugin.t("pastedMarkdown"))}async readClipboardNodes(e,t){let i=await navigator.clipboard.readText();if(!i.trim())return new l.Notice(this.plugin.t("clipboardEmpty")),[];let n=A(i,"Clipboard"),a=(n.root.text==="Clipboard"&&n.root.children.length>0?n.root.children:[n.root]).map(d=>F(d));for(let d of a)ue(d,e,t);return a.length===0&&new l.Notice(this.plugin.t("clipboardEmpty")),a}updateSearch(e){if(this.searchQuery=e.trim().toLowerCase(),this.refreshSearchMatches(),this.activeSearchIndex=this.searchMatches.length>0?0:-1,this.activeSearchIndex>=0){let t=this.searchMatches[this.activeSearchIndex];t&&this.selectAndFocusNode(t)}else this.render();this.updateSearchCount()}refreshSearchMatches(){if(!this.root||this.searchQuery.length===0){this.searchMatches=[],this.activeSearchIndex=-1,this.updateSearchCount();return}this.searchMatches=B(this.root).filter(e=>e.text.toLowerCase().includes(this.searchQuery)).map(e=>e.id),this.activeSearchIndex>=this.searchMatches.length&&(this.activeSearchIndex=this.searchMatches.length-1),this.searchMatches.length===0&&(this.activeSearchIndex=-1),this.updateSearchCount()}updateSearchCount(){if(!this.searchCountEl)return;if(this.searchQuery.length===0){this.searchCountEl.setText("");return}let e=this.activeSearchIndex>=0?this.activeSearchIndex+1:0;this.searchCountEl.setText(`${e}/${this.searchMatches.length}`)}jumpSearch(e){if(this.searchMatches.length===0)return;this.activeSearchIndex=(this.activeSearchIndex+e+this.searchMatches.length)%this.searchMatches.length;let t=this.searchMatches[this.activeSearchIndex];t&&this.selectAndFocusNode(t),this.updateSearchCount()}moveSelection(e){if(!this.root||!this.selectedId)return;let t=x(this.root,this.selectedId);if(!t)return;if(e==="ArrowRight"){if(t.collapsed&&t.children.length>0){this.toggleCollapse(t.id);return}let a=t.children[0];a&&this.selectAndFocusNode(a.id);return}if(e==="ArrowLeft"){let a=b(this.root,t.id);t.children.length>0&&!t.collapsed?this.toggleCollapse(t.id):a&&this.selectAndFocusNode(a.id);return}let i=this.positions.slice().sort((a,d)=>a.y-d.y||a.x-d.x),n=i.findIndex(a=>a.node.id===t.id),r=i[n+(e==="ArrowDown"?1:-1)];r&&this.selectAndFocusNode(r.node.id)}expandAncestors(e){if(!this.root)return;let t=me(this.root,e);for(let i of t.slice(0,-1))i.collapsed=!1}getSelectedNodes(){return this.root?[...this.selectedIds].map(e=>x(this.root,e)).filter(e=>!!e):[]}getEditableSelectedNodes(){return this.root?this.getSelectedNodes().filter(e=>{var t;return e.id!==((t=this.root)==null?void 0:t.id)}):[]}getEditableSelectedIds(){return this.getEditableSelectedNodes().map(e=>e.id)}onWheel(e){e.preventDefault();let t=e.deltaY>0?.92:1.08;this.scale=D(this.scale*t,.35,2.2),this.applyTransform()}onPointerDown(e){let t=e.target;t.closest(".onemind-node")||t.closest(".onemind-toolbar")||(this.panning={x:e.clientX,y:e.clientY,panX:this.panX,panY:this.panY},this.canvasEl.setPointerCapture(e.pointerId))}onPointerMove(e){if(this.dragState){this.onNodePointerMove(e);return}this.panning&&(this.panX=this.panning.panX+e.clientX-this.panning.x,this.panY=this.panning.panY+e.clientY-this.panning.y,this.applyTransform())}onPointerUp(e){if(this.dragState){this.finishNodeDrag(e);return}this.stopPanning()}stopPanning(){this.panning=null}onNodePointerDown(e,t){var r;if(e.button!==0||t.node.id===((r=this.root)==null?void 0:r.id)||e.target instanceof HTMLTextAreaElement)return;let i=e.target;if(i.closest(".onemind-collapse")||i.closest(".onemind-wikilink"))return;e.stopPropagation(),this.selectedId=t.node.id,this.selectedIds=new Set([t.node.id]),this.nodesEl.querySelectorAll(".is-selected").forEach(a=>a.removeClass("is-selected")),e.currentTarget.addClass("is-selected");let n=this.toScenePoint(e.clientX,e.clientY);this.dragState={nodeId:t.node.id,pointerId:e.pointerId,startClientX:e.clientX,startClientY:e.clientY,offsetX:n.x-t.x,offsetY:n.y-t.y,originalX:t.x,originalY:t.y,dragging:!1,el:e.currentTarget},this.dragState.el.setPointerCapture(e.pointerId),(e.pointerType==="touch"||e.pointerType==="pen")&&(this.longPressTimer=window.setTimeout(()=>{this.dragState=null,this.openNodeMenuAt(t.node.id,e.clientX,e.clientY)},560))}onNodePointerMove(e){if(!this.dragState)return;this.clearLongPressTimer();let t=e.clientX-this.dragState.startClientX,i=e.clientY-this.dragState.startClientY;if(!this.dragState.dragging&&Math.hypot(t,i)!n.has(h.node.id)),a=r.find(h=>e>=h.x&&e<=h.x+h.width&&t>=h.y&&t<=h.y+h.height);if(a)return{mode:"child",parentId:a.node.id,index:a.node.children.length,targetId:a.node.id};let d=null,c=Number.POSITIVE_INFINITY;for(let h of r){if(h.node.id===this.root.id)continue;let f=Math.hypot(e-(h.x+h.width/2),t-(h.y+h.height/2));fh.id===d.node.id),p=t{var a;return r.node.id===((a=this.dropTarget)==null?void 0:a.targetId)});if(!e)return;this.dragMarkerEl=this.nodesEl.createDiv({cls:"onemind-drop-marker"});let t=this.dropTarget.index<=((n=(i=b(this.root,this.dropTarget.targetId))==null?void 0:i.children.findIndex(r=>{var a;return r.id===((a=this.dropTarget)==null?void 0:a.targetId)}))!=null?n:0);this.dragMarkerEl.style.left=`${e.x-10}px`,this.dragMarkerEl.style.top=`${t?e.y-C/2:e.y+e.height+C/2}px`,this.dragMarkerEl.style.width=`${e.width+20}px`}clearDropTarget(){var e;this.nodesEl.querySelectorAll(".is-drop-child").forEach(t=>t.removeClass("is-drop-child")),(e=this.dragMarkerEl)==null||e.remove(),this.dragMarkerEl=null}clearLongPressTimer(){this.longPressTimer&&(window.clearTimeout(this.longPressTimer),this.longPressTimer=null)}toScenePoint(e,t){let i=this.canvasEl.getBoundingClientRect();return{x:(e-i.left-this.panX)/this.scale,y:(t-i.top-this.panY)/this.scale}}serializeCurrentMarkdown(){return this.root?`${this.documentPrefix}${se(this.root)}`:this.documentPrefix}getExportPath(e,t){var r,a,d,c;let i=(a=(r=this.file)==null?void 0:r.parent)!=null&&a.path&&this.file.parent.path!=="/"?`${this.file.parent.path}/`:"",n=t?`.${t}`:"";return`${i}${(c=(d=this.file)==null?void 0:d.basename)!=null?c:"mind-map"}.onemind${n}.${e}`}async writeTextFile(e,t){let i=this.app.vault.getAbstractFileByPath(e);i instanceof l.TFile?await this.app.vault.modify(i,t):await this.app.vault.create(e,t)}zoomAtCenter(e){this.scale=D(this.scale*e,.35,2.2),this.applyTransform()}focusSelected(){let e=this.positions.find(i=>i.node.id===this.selectedId);if(!e)return;let t=this.canvasEl.getBoundingClientRect();this.panX=t.width/2-(e.x+e.width/2)*this.scale,this.panY=t.height/2-(e.y+y/2)*this.scale,this.applyTransform()}fitToView(){if(this.positions.length===0)return;let e=te(this.positions),t=this.canvasEl.getBoundingClientRect(),i=(t.width-120)/Math.max(e.width,1),n=(t.height-120)/Math.max(e.height,1);this.scale=D(Math.min(i,n),.35,1.4),this.panX=t.width/2-(e.minX+e.width/2)*this.scale,this.panY=t.height/2-(e.minY+e.height/2)*this.scale,this.applyTransform()}applyTransform(){this.sceneEl&&(this.sceneEl.style.transform=`translate(${this.panX}px, ${this.panY}px) scale(${this.scale})`,this.updateStatus())}updateStatus(){if(!this.statusEl)return;let e=this.root?B(this.root).length:0,t=this.positions.length,i=this.isSaving?this.plugin.t("saving"):this.hasLocalUnsavedChange?this.plugin.t("unsaved"):this.plugin.t("saved"),n=this.tagFilter?`#${this.tagFilter}`:"";this.statusEl.setText([`${t}/${e} ${this.plugin.t("nodesLabel")}`,`${this.selectedIds.size} ${this.plugin.t("selectedLabel")}`,`${this.plugin.t("zoomLabel")} ${Math.round(this.scale*100)}%`,n,i].filter(Boolean).join(" \xB7 "))}},G=class extends l.PluginSettingTab{constructor(s,e){super(s,e),this.plugin=e}display(){let{containerEl:s}=this;s.empty(),s.createEl("h2",{text:this.plugin.t("settingsTitle")}),new l.Setting(s).setName(this.plugin.t("language")).setDesc(this.plugin.t("languageDesc")).addDropdown(t=>{t.addOption("zh",this.plugin.t("chinese")).addOption("en",this.plugin.t("english")).setValue(this.plugin.settings.language).onChange(async i=>{this.plugin.settings.language=i,await this.plugin.saveSettings(),this.plugin.refreshOpenViews(),this.display()})}),new l.Setting(s).setName(this.plugin.t("autoSaveDelay")).setDesc(this.plugin.t("autoSaveDelayDesc")).addText(t=>{t.setPlaceholder("300").setValue(String(this.plugin.settings.autoSaveDelay)).onChange(async i=>{let n=Number.parseInt(i,10);this.plugin.settings.autoSaveDelay=Number.isFinite(n)?D(n,0,5e3):$.autoSaveDelay,await this.plugin.saveSettings(),this.plugin.refreshOpenViews()})}),new l.Setting(s).setName(this.plugin.t("defaultExpandDepth")).setDesc(this.plugin.t("defaultExpandDepthDesc")).addSlider(t=>{t.setLimits(1,99,1).setDynamicTooltip().setValue(this.plugin.settings.defaultExpandDepth).onChange(async i=>{this.plugin.settings.defaultExpandDepth=i,await this.plugin.saveSettings(),this.plugin.refreshOpenViews()})}),new l.Setting(s).setName(this.plugin.t("layoutDirection")).setDesc(this.plugin.t("layoutDirectionDesc")).addDropdown(t=>{t.addOption("right",this.plugin.t("horizontalRight")).addOption("balanced",this.plugin.t("balanced")).setValue(this.plugin.settings.layoutDirection).onChange(async i=>{this.plugin.settings.layoutDirection=i,await this.plugin.saveSettings(),this.plugin.refreshOpenViews()})}),new l.Setting(s).setName(this.plugin.t("layoutAnimation")).setDesc(this.plugin.t("layoutAnimationDesc")).addToggle(t=>{t.setValue(this.plugin.settings.animations).onChange(async i=>{this.plugin.settings.animations=i,await this.plugin.saveSettings(),this.plugin.refreshOpenViews()})}),new l.Setting(s).setName(this.plugin.t("showAssociationLinks")).setDesc(this.plugin.t("showAssociationLinksDesc")).addToggle(t=>{t.setValue(this.plugin.settings.showAssociationLinks).onChange(async i=>{this.plugin.settings.showAssociationLinks=i,await this.plugin.saveSettings(),this.plugin.refreshOpenViews()})}),new l.Setting(s).setName(this.plugin.t("branchColors")).setDesc(this.plugin.t("branchColorsDesc")).addTextArea(t=>{t.setValue(this.plugin.settings.branchColors.join(", ")).onChange(async i=>{let n=i.split(",").map(r=>r.trim()).filter(Boolean);this.plugin.settings.branchColors=n.length>0?n:$.branchColors,await this.plugin.saveSettings(),this.plugin.refreshOpenViews()}),t.inputEl.rows=2});let e=s.createDiv({cls:"onemind-settings-palette"});this.plugin.settings.branchColors.forEach((t,i)=>{new l.Setting(e).setName(`${this.plugin.t("branchColors")} ${i+1}`).addColorPicker(n=>{n.setValue(t).onChange(async r=>{this.plugin.settings.branchColors[i]=r,await this.plugin.saveSettings(),this.plugin.refreshOpenViews()})})}),new l.Setting(s).setName(this.plugin.t("resetBranchColors")).addButton(t=>{t.setButtonText(this.plugin.t("resetBranchColors")).onClick(async()=>{this.plugin.settings.branchColors=[...$.branchColors],await this.plugin.saveSettings(),this.plugin.refreshOpenViews(),this.display()})}),new l.Setting(s).setName(this.plugin.t("pngScale")).setDesc(this.plugin.t("pngScaleDesc")).addSlider(t=>{t.setLimits(1,4,1).setDynamicTooltip().setValue(this.plugin.settings.exportScale).onChange(async i=>{this.plugin.settings.exportScale=i,await this.plugin.saveSettings()})}),new l.Setting(s).setName(this.plugin.t("transparentPng")).setDesc(this.plugin.t("transparentPngDesc")).addToggle(t=>{t.setValue(this.plugin.settings.exportTransparentBackground).onChange(async i=>{this.plugin.settings.exportTransparentBackground=i,await this.plugin.saveSettings()})})}},_=class extends l.SuggestModal{constructor(s,e,t){super(s),this.onChoose=t,this.setPlaceholder(e)}getSuggestions(s){let e=s.trim().toLowerCase();return e?ie.filter(t=>t.includes(e)):ie}renderSuggestion(s,e){e.createSpan({cls:"onemind-emoji-suggestion",text:s})}onChooseSuggestion(s){this.onChoose(s)}},W=class extends l.Modal{constructor(s,e,t){super(s),this.placeholder=e,this.onSubmit=t}onOpen(){this.contentEl.empty();let s=this.contentEl.createEl("input",{cls:"onemind-tag-input",attr:{type:"text",placeholder:this.placeholder}});s.focus(),s.addEventListener("keydown",e=>{e.key==="Enter"?(e.preventDefault(),this.onSubmit(s.value),this.close()):e.key==="Escape"&&(e.preventDefault(),this.close())})}onClose(){this.contentEl.empty()}},Q=class extends l.Modal{constructor(s,e,t,i,n,r){super(s),this.title=e,this.placeholder=t,this.buttonText=i,this.defaultValue=n,this.onSubmit=r}onOpen(){this.contentEl.empty(),this.contentEl.createEl("h2",{text:this.title});let s=this.contentEl.createEl("input",{cls:"onemind-tag-input",attr:{type:"text",placeholder:this.placeholder,value:this.defaultValue}}),t=this.contentEl.createDiv({cls:"onemind-modal-actions"}).createEl("button",{cls:"mod-cta",text:this.buttonText}),i=()=>{this.onSubmit(s.value),this.close()};t.addEventListener("click",i),s.addEventListener("keydown",n=>{n.key==="Enter"?(n.preventDefault(),i()):n.key==="Escape"&&(n.preventDefault(),this.close())}),s.focus(),s.select()}onClose(){this.contentEl.empty()}},q=class extends l.SuggestModal{constructor(s,e,t,i){super(s),this.tags=e,this.onChoose=i,this.setPlaceholder(t)}getSuggestions(s){let e=Z(s).toLowerCase(),t=e?this.tags.filter(i=>i.toLowerCase().includes(e)):this.tags;return e&&!t.includes(e)?[e,...t]:t}renderSuggestion(s,e){e.createSpan({cls:"onemind-tag-suggestion",text:`#${s}`})}onChooseSuggestion(s){this.onChoose(s)}},J=class extends l.Modal{constructor(s,e,t,i,n){super(s),this.labels=e,this.onReload=t,this.onKeep=i,this.onCloseCallback=n}onOpen(){let{contentEl:s}=this;s.empty(),s.createEl("h2",{text:this.labels.title}),s.createEl("p",{text:this.labels.body});let e=s.createDiv({cls:"onemind-modal-actions"});e.createEl("button",{text:this.labels.reload}).onClickEvent(async()=>{this.close(),await this.onReload()}),e.createEl("button",{cls:"mod-cta",text:this.labels.keep}).onClickEvent(async()=>{this.close(),await this.onKeep()})}onClose(){this.contentEl.empty(),this.onCloseCallback()}};function A(o,s){let e=o.split(/\r?\n/),t=0;if(e[0]==="---"){let d=e.findIndex((c,u)=>u>0&&c==="---");d>0&&(t=d+1)}for(;tc0?`${e.slice(0,n).join(` `).replace(/\s*$/,"")} -`:"",d=e.slice(n).join(` -`);return{root:Ne(d,s),prefix:r}}function Ne(o,s){var d,a,c,u;let e=o.split(/\r?\n/),t=null,i=1,n=[],r=()=>(t||(t=E(s||"Center topic","heading"),n.push({depth:1,node:t})),t);for(let v of e){let p=/^(#{1,6})\s+(.+?)\s*$/.exec(v);if(p){let f=p[1].length,w=E(p[2],"heading");if(!t&&f===1)t=w,n.length=0,n.push({depth:1,node:w});else{for(r();n.length>0&&n[n.length-1].depth>=f;)n.pop();((a=(d=n[n.length-1])==null?void 0:d.node)!=null?a:t).children.push(w),n.push({depth:f,node:w})}i=f;continue}let l=/^(\s*)[-*+]\s+(.+?)\s*$/.exec(v);if(l){r();let f=Math.floor(l[1].replace(/\t/g," ").length/2),w=i+f+1,g=E(l[2],"list");for(;n.length>0&&n[n.length-1].depth>=w;)n.pop();((u=(c=n[n.length-1])==null?void 0:c.node)!=null?u:t).children.push(g),n.push({depth:w,node:g})}}return t!=null?t:E(s||"Center topic","heading")}function ne(o){let s=[],e=(t,i,n)=>{let r=t.kind==="heading"&&!n&&i<=6;r?s.push(`${"#".repeat(i)} ${t.text}`):s.push(`${" ".repeat(Math.max(0,i-2))}- ${t.text}`);for(let d of t.children)e(d,i+1,n||!r)};return e(o,1,!1),`${s.join(` +`:"",a=e.slice(n).join(` +`);return{root:Ce(a,s),prefix:r}}function Ce(o,s){var a,d,c,u;let e=o.split(/\r?\n/),t=null,i=1,n=[],r=()=>(t||(t=E(s||"Center topic","heading"),n.push({depth:1,node:t})),t);for(let v of e){let p=/^(#{1,6})\s+(.+?)\s*$/.exec(v);if(p){let f=p[1].length,w=E(p[2],"heading");if(!t&&f===1)t=w,n.length=0,n.push({depth:1,node:w});else{for(r();n.length>0&&n[n.length-1].depth>=f;)n.pop();((d=(a=n[n.length-1])==null?void 0:a.node)!=null?d:t).children.push(w),n.push({depth:f,node:w})}i=f;continue}let h=/^(\s*)[-*+]\s+(.+?)\s*$/.exec(v);if(h){r();let f=Math.floor(h[1].replace(/\t/g," ").length/2),w=i+f+1,g=E(h[2],"list");for(;n.length>0&&n[n.length-1].depth>=w;)n.pop();((u=(c=n[n.length-1])==null?void 0:c.node)!=null?u:t).children.push(g),n.push({depth:w,node:g})}}return t!=null?t:E(s||"Center topic","heading")}function se(o){let s=[],e=(t,i,n)=>{let r=t.kind==="heading"&&!n&&i<=6;r?s.push(`${"#".repeat(i)} ${t.text}`):s.push(`${" ".repeat(Math.max(0,i-2))}- ${t.text}`);for(let a of t.children)e(a,i+1,n||!r)};return e(o,1,!1),`${s.join(` `)} -`}function se(o,s,e=!0){let t=ee(o),i=80,n=Math.ceil(t.width+i*2),r=Math.ceil(t.height+i*2),d=t.minX-i,a=t.minY-i,c=o.filter(p=>p.parent).map(p=>{let l=o.find(P=>P.node===p.parent);if(!l)return"";let f=p.x>=l.x,w=f?l.x+l.width:l.x,g=l.y+S/2,m=f?p.x:p.x+p.width,x=p.y+S/2,M=Math.max(60,Math.abs(m-w)*.45)*(f?1:-1);return``}).join(` -`),u=e?Ce(o):"",v=o.map(p=>{let l=p.depth===0,f=p.width,w=l?18:14,g=l?700:400,m=k(p.node.text),x=[m.emoji?`${m.emoji} ${H(m.displayLabel)}`:H(m.displayLabel),m.tags.map(z=>`#${z}`).join(" ")].filter(Boolean).join(" "),M=Le(x,l?20:22),P=M.map((z,me)=>{let ve=me===0?0:w+3;return`${O(z)}`}).join(""),Y=Math.max(S,24+M.length*(w+3));return[``,`${P}`].join(` +`}function Te(o){return o.replace(/[\\/:*?"<>|#^[\]]+/g," ").replace(/\s+/g," ").trim()}function oe(o,s,e=!0){let t=te(o),i=80,n=Math.ceil(t.width+i*2),r=Math.ceil(t.height+i*2),a=t.minX-i,d=t.minY-i,c=o.filter(p=>p.parent).map(p=>{let h=o.find(P=>P.node===p.parent);if(!h)return"";let f=p.x>=h.x,w=f?h.x+h.width:h.x,g=h.y+y/2,m=f?p.x:p.x+p.width,M=p.y+y/2,S=Math.max(60,Math.abs(m-w)*.45)*(f?1:-1);return``}).join(` +`),u=e?Ie(o):"",v=o.map(p=>{let h=p.depth===0,f=p.width,w=h?18:14,g=h?700:400,m=k(p.node.text),M=[m.emoji?`${m.emoji} ${H(m.displayLabel)}`:H(m.displayLabel),m.tags.map(z=>`#${z}`).join(" ")].filter(Boolean).join(" "),S=Ae(M,h?20:22),P=S.map((z,ve)=>{let we=ve===0?0:w+3;return`${O(z)}`}).join(""),Y=Math.max(y,24+S.length*(w+3));return[``,`${P}`].join(` `)}).join(` -`);return['',``,"",c,u,v,""].join(` -`)}function Ce(o){let s=new Map;for(let t of o)s.set(N(t.node.text),t);let e=new Set;return o.flatMap(t=>ae(t.node.text,null).map(i=>{let n=s.get(i);if(!n||n.node.id===t.node.id)return"";let r=[t.node.id,n.node.id].sort().join(":");if(e.has(r))return"";e.add(r);let d=t.x+t.width/2,a=t.y+S/2,c=n.x+n.width/2,u=n.y+S/2,v=(d+c)/2,p=Math.max(80,Math.abs(u-a)*.35),l=Math.min(a,u)-p;return``})).filter(Boolean).join(` -`)}async function Ie(o,s,e){var a,c,u,v;let t=Number((c=(a=/width="(\d+)"/.exec(o))==null?void 0:a[1])!=null?c:1200),i=Number((v=(u=/height="(\d+)"/.exec(o))==null?void 0:u[1])!=null?v:800),n=D(Math.round(s),1,4),r=new Blob([o],{type:"image/svg+xml;charset=utf-8"}),d=URL.createObjectURL(r);try{let p=await new Promise((g,m)=>{let x=new Image;x.onload=()=>g(x),x.onerror=()=>m(new Error("Could not render SVG export.")),x.src=d}),l=document.createElement("canvas");l.width=t*n,l.height=i*n;let f=l.getContext("2d");if(!f)throw new Error("Canvas is not available.");return e||(f.fillStyle=getComputedStyle(document.body).getPropertyValue("--background-primary").trim()||"#ffffff",f.fillRect(0,0,l.width,l.height)),f.scale(n,n),f.drawImage(p,0,0,t,i),await(await new Promise((g,m)=>{l.toBlob(x=>x?g(x):m(new Error("Could not encode PNG export.")),"image/png")})).arrayBuffer()}finally{URL.revokeObjectURL(d)}}function oe(o,s,e){let t=[],i=d=>d.collapsed?[]:d.children,n=d=>{let a=i(d);return a.length===0?S:Math.max(S,a.reduce((c,u)=>c+n(u),0)+C*(a.length-1))},r=(d,a,c,u,v,p,l)=>{let f=n(d),w=v+f/2-S/2,g=c===0?200:ke;t.push({node:d,parent:a,depth:c,x:u,y:w,width:g,height:S,color:p,side:l});let m=v;i(d).forEach((M,P)=>{let Y=c===0?s[P%s.length]:p;r(M,d,c+1,u+l*X,m,Y,l),m+=n(M)+C})};if(e==="balanced"&&!o.collapsed&&o.children.length>1){let d=i(o),a=d.filter((g,m)=>m%2===1),c=d.filter((g,m)=>m%2===0),u=g=>g.length===0?S:g.reduce((m,x)=>m+n(x),0)+C*(g.length-1),v=u(a),p=u(c),l=Math.max(v,p,S);t.push({node:o,parent:null,depth:0,x:0,y:l/2-S/2,width:200,height:S,color:s[0],side:1});let f=l/2-v/2;a.forEach((g,m)=>{let x=d.findIndex(M=>M===g);r(g,o,1,-X,f,s[x%s.length],-1),f+=n(g)+C});let w=l/2-p/2;c.forEach(g=>{let m=d.findIndex(x=>x===g);r(g,o,1,X,w,s[m%s.length],1),w+=n(g)+C})}else r(o,null,0,0,0,s[0],1);return t}function Te(o,s,e){let t=/(\[\[[^\]]+\]\]|`[^`]+`|\*\*[^*]+\*\*)/g,i=0;for(let n of s.matchAll(t)){if(n.index===void 0)continue;n.index>i&&o.appendText(s.slice(i,n.index));let r=n[0];if(r.startsWith("[[")){let d=r.slice(2,-2);o.createEl("span",{cls:"onemind-wikilink",text:d}).onClickEvent(c=>{c.stopPropagation(),e.workspace.openLinkText(d,"",!1)})}else r.startsWith("`")?o.createEl("code",{text:r.slice(1,-1)}):o.createEl("strong",{text:r.slice(2,-2)});i=n.index+r.length}i(e.push(r),n)).replace(/\s{2,}/g," ").trim()||s.label;return{...s,tags:e,displayLabel:t}}function J(o){return o.trim().replace(/^#/,"").replace(/[^\p{Letter}\p{Number}_/-]/gu,"")}function De(o,s){return k(o).tags.includes(s)?o:`${o.trim()} #${s}`}function Pe(o){let s=k(o);return`${s.emoji?`${s.emoji} `:""}${s.displayLabel}`.trim()||"Untitled"}function de(o){let s=k(o);return H(`${s.emoji?`${s.emoji} `:""}${s.displayLabel}${s.tags.length>0?` ${s.tags.map(e=>`#${e}`).join(" ")}`:""}`)}function H(o){return o.replace(/\[\[([^\]|]+)(?:\|([^\]]+))?\]\]/g,(s,e,t)=>t!=null?t:e).replace(/`([^`]+)`/g,"$1").replace(/\*\*([^*]+)\*\*/g,"$1")}function ae(o,s){let e=[],t=s==null?void 0:s.basename.toLowerCase(),i=s==null?void 0:s.path.replace(/\.md$/i,"").toLowerCase(),n=/\[\[([^\]|]+)(?:\|[^\]]+)?\]\]/g;for(let r of o.matchAll(n)){let d=r[1].trim();if(!d)continue;let[a,c]=d.includes("#")?d.split("#",2):["",d],u=a.trim().replace(/\.md$/i,"").toLowerCase();u&&u!==t&&u!==i||e.push(N(c))}return e.filter(Boolean)}function Le(o,s){let e=o.trim().split(/\s+/).filter(Boolean);if(e.length===0)return["Untitled"];let t=[],i="";for(let n of e){if(n.length>s){i&&t.push(i);for(let d=0;ds&&i?(t.push(i),i=n):i=r}return i&&t.push(i),t.slice(0,4)}function O(o){return o.replace(/&/g,"&").replace(//g,">").replace(/"/g,""")}function E(o,s){return{id:`node-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`,text:o.trim()||"Untitled",kind:s,children:[],collapsed:!1}}function F(o){return{id:o.id,text:o.text,kind:o.kind,collapsed:o.collapsed,children:o.children.map(s=>F(s))}}function le(o){return{id:E(o.text,o.kind).id,text:o.text,kind:o.kind,collapsed:o.collapsed,children:o.children.map(s=>le(s))}}function he(o,s){let e=o.children.map(t=>he(t,s)).filter(t=>!!t);return k(o.text).tags.includes(s)||e.length>0?{...o,collapsed:!1,children:e}:null}function ce(o,s){return k(o.text).tags.includes(s)||o.children.some(e=>ce(e,s))}function pe(o,s,e){o.id=E(o.text,o.kind).id,o.kind=s==="heading"&&e<=5?"heading":"list";for(let t of o.children)pe(t,o.kind,e+1)}function ue(o,s,e=0){o.collapsed=e>=s;for(let t of o.children)ue(t,s,e+1)}function j(o,s){o.collapsed=s;for(let e of o.children)j(e,s)}function R(o,s){return o.kind==="heading"&&s<5?"heading":"list"}function y(o,s){if(o.id===s)return o;for(let e of o.children){let t=y(e,s);if(t)return t}return null}function Z(o,s){let e=Be(s);if(N(o.text)===e)return o;for(let t of o.children){let i=Z(t,e);if(i)return i}return null}function b(o,s){for(let e of o.children){if(e.id===s)return o;let t=b(e,s);if(t)return t}return null}function ge(o,s){o.children=o.children.filter(e=>!s.has(e.id));for(let e of o.children)ge(e,s)}function B(o){let s=[],e=t=>{s.push(t);for(let i of t.children)e(i)};return e(o),s}function fe(o,s){if(o.id===s)return[o];for(let e of o.children){let t=fe(e,s);if(t.length>0)return[o,...t]}return[]}function $e(o){if(!o)return[];let s=[],e=t=>{for(let i of t.children)s.push(i.id),e(i)};return e(o),s}function Ae(o,s,e){if(s===o.id||s===e.parentId)return!1;let t=b(o,s),i=y(o,e.parentId);if(!t||!i)return!1;let n=t.children.findIndex(a=>a.id===s);if(n===-1)return!1;let[r]=t.children.splice(n,1);if(!r)return!1;let d=e.mode==="child"?i.children.length:e.index;return t.id===i.id&&na.id===s);if(n===-1)return!1;if(e==="up")return n===0?!1:([t.children[n-1],t.children[n]]=[t.children[n],t.children[n-1]],!0);if(e==="down")return n>=t.children.length-1?!1:([t.children[n],t.children[n+1]]=[t.children[n+1],t.children[n]],!0);if(e==="indent"){if(n===0)return!1;let a=t.children[n-1];return t.children.splice(n,1),i.kind=R(a,I(o,a.id)),a.children.push(i),a.collapsed=!1,!0}let r=b(o,t.id);if(!r)return!1;t.children.splice(n,1);let d=r.children.findIndex(a=>a.id===t.id);return i.kind=R(r,I(o,r.id)),r.children.splice(d+1,0,i),!0}function Be(o){return decodeURIComponent(o).replace(/^#+/,"").trim().toLowerCase().replace(/\s+/g,"-")}function N(o){return de(o).trim().toLowerCase().replace(/[^\p{Letter}\p{Number}\p{Emoji_Presentation}\s-]/gu,"").replace(/\s+/g,"-")}function I(o,s,e=0){if(o.id===s)return e;for(let t of o.children){let i=I(t,s,e+1);if(i!==-1)return i}return-1}function ee(o){let s=Math.min(...o.map(n=>n.x)),e=Math.min(...o.map(n=>n.y)),t=Math.max(...o.map(n=>n.x+n.width)),i=Math.max(...o.map(n=>n.y+n.height));return{minX:s,minY:e,width:t-s,height:i-e}}function D(o,s,e){return Math.max(s,Math.min(e,o))}function U(o){return document.createElementNS("http://www.w3.org/2000/svg",o)} +`);return['',``,"",c,u,v,""].join(` +`)}function Ie(o){let s=new Map;for(let t of o)s.set(N(t.node.text),t);let e=new Set;return o.flatMap(t=>le(t.node.text,null).map(i=>{let n=s.get(i);if(!n||n.node.id===t.node.id)return"";let r=[t.node.id,n.node.id].sort().join(":");if(e.has(r))return"";e.add(r);let a=t.x+t.width/2,d=t.y+y/2,c=n.x+n.width/2,u=n.y+y/2,v=(a+c)/2,p=Math.max(80,Math.abs(u-d)*.35),h=Math.min(d,u)-p;return``})).filter(Boolean).join(` +`)}async function De(o,s,e){var d,c,u,v;let t=Number((c=(d=/width="(\d+)"/.exec(o))==null?void 0:d[1])!=null?c:1200),i=Number((v=(u=/height="(\d+)"/.exec(o))==null?void 0:u[1])!=null?v:800),n=D(Math.round(s),1,4),r=new Blob([o],{type:"image/svg+xml;charset=utf-8"}),a=URL.createObjectURL(r);try{let p=await new Promise((g,m)=>{let M=new Image;M.onload=()=>g(M),M.onerror=()=>m(new Error("Could not render SVG export.")),M.src=a}),h=document.createElement("canvas");h.width=t*n,h.height=i*n;let f=h.getContext("2d");if(!f)throw new Error("Canvas is not available.");return e||(f.fillStyle=getComputedStyle(document.body).getPropertyValue("--background-primary").trim()||"#ffffff",f.fillRect(0,0,h.width,h.height)),f.scale(n,n),f.drawImage(p,0,0,t,i),await(await new Promise((g,m)=>{h.toBlob(M=>M?g(M):m(new Error("Could not encode PNG export.")),"image/png")})).arrayBuffer()}finally{URL.revokeObjectURL(a)}}function re(o,s,e){let t=[],i=a=>a.collapsed?[]:a.children,n=a=>{let d=i(a);return d.length===0?y:Math.max(y,d.reduce((c,u)=>c+n(u),0)+C*(d.length-1))},r=(a,d,c,u,v,p,h)=>{let f=n(a),w=v+f/2-y/2,g=c===0?200:Ee;t.push({node:a,parent:d,depth:c,x:u,y:w,width:g,height:y,color:p,side:h});let m=v;i(a).forEach((S,P)=>{let Y=c===0?s[P%s.length]:p;r(S,a,c+1,u+h*X,m,Y,h),m+=n(S)+C})};if(e==="balanced"&&!o.collapsed&&o.children.length>1){let a=i(o),d=a.filter((g,m)=>m%2===1),c=a.filter((g,m)=>m%2===0),u=g=>g.length===0?y:g.reduce((m,M)=>m+n(M),0)+C*(g.length-1),v=u(d),p=u(c),h=Math.max(v,p,y);t.push({node:o,parent:null,depth:0,x:0,y:h/2-y/2,width:200,height:y,color:s[0],side:1});let f=h/2-v/2;d.forEach((g,m)=>{let M=a.findIndex(S=>S===g);r(g,o,1,-X,f,s[M%s.length],-1),f+=n(g)+C});let w=h/2-p/2;c.forEach(g=>{let m=a.findIndex(M=>M===g);r(g,o,1,X,w,s[m%s.length],1),w+=n(g)+C})}else r(o,null,0,0,0,s[0],1);return t}function Pe(o,s,e){let t=/(\[\[[^\]]+\]\]|`[^`]+`|\*\*[^*]+\*\*)/g,i=0;for(let n of s.matchAll(t)){if(n.index===void 0)continue;n.index>i&&o.appendText(s.slice(i,n.index));let r=n[0];if(r.startsWith("[[")){let a=r.slice(2,-2);o.createEl("span",{cls:"onemind-wikilink",text:a}).onClickEvent(c=>{c.stopPropagation(),e.workspace.openLinkText(a,"",!1)})}else r.startsWith("`")?o.createEl("code",{text:r.slice(1,-1)}):o.createEl("strong",{text:r.slice(2,-2)});i=n.index+r.length}i(e.push(r),n)).replace(/\s{2,}/g," ").trim()||s.label;return{...s,tags:e,displayLabel:t}}function Z(o){return o.trim().replace(/^#/,"").replace(/[^\p{Letter}\p{Number}_/-]/gu,"")}function Le(o,s){return k(o).tags.includes(s)?o:`${o.trim()} #${s}`}function $e(o){let s=k(o);return`${s.emoji?`${s.emoji} `:""}${s.displayLabel}`.trim()||"Untitled"}function de(o){let s=k(o);return H(`${s.emoji?`${s.emoji} `:""}${s.displayLabel}${s.tags.length>0?` ${s.tags.map(e=>`#${e}`).join(" ")}`:""}`)}function H(o){return o.replace(/\[\[([^\]|]+)(?:\|([^\]]+))?\]\]/g,(s,e,t)=>t!=null?t:e).replace(/`([^`]+)`/g,"$1").replace(/\*\*([^*]+)\*\*/g,"$1")}function le(o,s){let e=[],t=s==null?void 0:s.basename.toLowerCase(),i=s==null?void 0:s.path.replace(/\.md$/i,"").toLowerCase(),n=/\[\[([^\]|]+)(?:\|[^\]]+)?\]\]/g;for(let r of o.matchAll(n)){let a=r[1].trim();if(!a)continue;let[d,c]=a.includes("#")?a.split("#",2):["",a],u=d.trim().replace(/\.md$/i,"").toLowerCase();u&&u!==t&&u!==i||e.push(N(c))}return e.filter(Boolean)}function Ae(o,s){let e=o.trim().split(/\s+/).filter(Boolean);if(e.length===0)return["Untitled"];let t=[],i="";for(let n of e){if(n.length>s){i&&t.push(i);for(let a=0;as&&i?(t.push(i),i=n):i=r}return i&&t.push(i),t.slice(0,4)}function O(o){return o.replace(/&/g,"&").replace(//g,">").replace(/"/g,""")}function E(o,s){return{id:`node-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`,text:o.trim()||"Untitled",kind:s,children:[],collapsed:!1}}function F(o){return{id:o.id,text:o.text,kind:o.kind,collapsed:o.collapsed,children:o.children.map(s=>F(s))}}function he(o){return{id:E(o.text,o.kind).id,text:o.text,kind:o.kind,collapsed:o.collapsed,children:o.children.map(s=>he(s))}}function ce(o,s){let e=o.children.map(t=>ce(t,s)).filter(t=>!!t);return k(o.text).tags.includes(s)||e.length>0?{...o,collapsed:!1,children:e}:null}function pe(o,s){return k(o.text).tags.includes(s)||o.children.some(e=>pe(e,s))}function ue(o,s,e){o.id=E(o.text,o.kind).id,o.kind=s==="heading"&&e<=5?"heading":"list";for(let t of o.children)ue(t,o.kind,e+1)}function ge(o,s,e=0){o.collapsed=e>=s;for(let t of o.children)ge(t,s,e+1)}function j(o,s){o.collapsed=s;for(let e of o.children)j(e,s)}function R(o,s){return o.kind==="heading"&&s<5?"heading":"list"}function x(o,s){if(o.id===s)return o;for(let e of o.children){let t=x(e,s);if(t)return t}return null}function ee(o,s){let e=je(s);if(N(o.text)===e)return o;for(let t of o.children){let i=ee(t,e);if(i)return i}return null}function b(o,s){for(let e of o.children){if(e.id===s)return o;let t=b(e,s);if(t)return t}return null}function fe(o,s){o.children=o.children.filter(e=>!s.has(e.id));for(let e of o.children)fe(e,s)}function B(o){let s=[],e=t=>{s.push(t);for(let i of t.children)e(i)};return e(o),s}function me(o,s){if(o.id===s)return[o];for(let e of o.children){let t=me(e,s);if(t.length>0)return[o,...t]}return[]}function Oe(o){if(!o)return[];let s=[],e=t=>{for(let i of t.children)s.push(i.id),e(i)};return e(o),s}function Be(o,s,e){if(s===o.id||s===e.parentId)return!1;let t=b(o,s),i=x(o,e.parentId);if(!t||!i)return!1;let n=t.children.findIndex(d=>d.id===s);if(n===-1)return!1;let[r]=t.children.splice(n,1);if(!r)return!1;let a=e.mode==="child"?i.children.length:e.index;return t.id===i.id&&nd.id===s);if(n===-1)return!1;if(e==="up")return n===0?!1:([t.children[n-1],t.children[n]]=[t.children[n],t.children[n-1]],!0);if(e==="down")return n>=t.children.length-1?!1:([t.children[n],t.children[n+1]]=[t.children[n+1],t.children[n]],!0);if(e==="indent"){if(n===0)return!1;let d=t.children[n-1];return t.children.splice(n,1),i.kind=R(d,T(o,d.id)),d.children.push(i),d.collapsed=!1,!0}let r=b(o,t.id);if(!r)return!1;t.children.splice(n,1);let a=r.children.findIndex(d=>d.id===t.id);return i.kind=R(r,T(o,r.id)),r.children.splice(a+1,0,i),!0}function je(o){return decodeURIComponent(o).replace(/^#+/,"").trim().toLowerCase().replace(/\s+/g,"-")}function N(o){return de(o).trim().toLowerCase().replace(/[^\p{Letter}\p{Number}\p{Emoji_Presentation}\s-]/gu,"").replace(/\s+/g,"-")}function T(o,s,e=0){if(o.id===s)return e;for(let t of o.children){let i=T(t,s,e+1);if(i!==-1)return i}return-1}function te(o){let s=Math.min(...o.map(n=>n.x)),e=Math.min(...o.map(n=>n.y)),t=Math.max(...o.map(n=>n.x+n.width)),i=Math.max(...o.map(n=>n.y+n.height));return{minX:s,minY:e,width:t-s,height:i-e}}function D(o,s,e){return Math.max(s,Math.min(e,o))}function U(o){return document.createElementNS("http://www.w3.org/2000/svg",o)} diff --git a/src/main.ts b/src/main.ts index f166250..9a608f0 100644 --- a/src/main.ts +++ b/src/main.ts @@ -97,6 +97,11 @@ const I18N = { en: { openRibbon: "Open OneMind", openMindMap: "Open current note as mind map", + createMindMap: "Create new mind map", + newMindMapTitle: "New mind map", + mindMapNamePlaceholder: "Mind map name", + createButton: "Create", + createdMindMap: "Created mind map", returnMarkdown: "Return to Markdown editor", addChild: "Add child node", addSibling: "Add sibling node", @@ -192,6 +197,11 @@ const I18N = { zh: { openRibbon: "打开 OneMind", openMindMap: "以思维导图打开当前笔记", + createMindMap: "新建思维导图", + newMindMapTitle: "新建思维导图", + mindMapNamePlaceholder: "思维导图名称", + createButton: "创建", + createdMindMap: "已创建思维导图", returnMarkdown: "返回 Markdown 编辑器", addChild: "添加子节点", addSibling: "添加同级节点", @@ -326,7 +336,18 @@ export default class OneMindPlugin extends Plugin { ); this.addRibbonIcon("git-fork", this.t("openRibbon"), () => { - void this.openMindMap(); + const file = this.getActiveMarkdownFile(); + if (file) { + void this.openMindMap(file, this.getActiveHeadingAnchor()); + } else { + this.createMindMap(); + } + }); + + this.addCommand({ + id: "create-onemind-note", + name: this.t("createMindMap"), + callback: () => this.createMindMap() }); this.addCommand({ @@ -445,6 +466,41 @@ export default class OneMindPlugin extends Plugin { active: true }); } + + createMindMap(): void { + new MindMapNameModal( + this.app, + this.t("createMindMap"), + this.t("mindMapNamePlaceholder"), + this.t("createButton"), + this.t("newMindMapTitle"), + async (title) => { + const file = await this.createMindMapFile(title); + new Notice(`${this.t("createdMindMap")}: ${file.basename}`); + await this.openMindMap(file); + } + ).open(); + } + + private async createMindMapFile(title: string): Promise { + const fallbackTitle = this.t("newMindMapTitle"); + const displayTitle = title.trim() || fallbackTitle; + const fileName = sanitizeFileName(displayTitle) || fallbackTitle; + const folder = this.getActiveMarkdownFile()?.parent?.path; + const folderPrefix = folder && folder !== "/" ? `${folder}/` : ""; + const path = this.getAvailablePath(folderPrefix, fileName); + return await this.app.vault.create(path, `# ${displayTitle}\n\n- New idea\n`); + } + + private getAvailablePath(folderPrefix: string, fileName: string): string { + let index = 0; + while (true) { + const suffix = index === 0 ? "" : ` ${index + 1}`; + const path = `${folderPrefix}${fileName}${suffix}.md`; + if (!this.app.vault.getAbstractFileByPath(path)) return path; + index += 1; + } + } } class OneMindView extends ItemView { @@ -2035,6 +2091,61 @@ class TagInputModal extends Modal { } } +class MindMapNameModal extends Modal { + private title: string; + private placeholder: string; + private buttonText: string; + private defaultValue: string; + private onSubmit: (title: string) => void; + + constructor( + app: App, + title: string, + placeholder: string, + buttonText: string, + defaultValue: string, + onSubmit: (title: string) => void + ) { + super(app); + this.title = title; + this.placeholder = placeholder; + this.buttonText = buttonText; + this.defaultValue = defaultValue; + this.onSubmit = onSubmit; + } + + onOpen(): void { + this.contentEl.empty(); + this.contentEl.createEl("h2", { text: this.title }); + const input = this.contentEl.createEl("input", { + cls: "onemind-tag-input", + attr: { type: "text", placeholder: this.placeholder, value: this.defaultValue } + }); + const actions = this.contentEl.createDiv({ cls: "onemind-modal-actions" }); + const createButton = actions.createEl("button", { cls: "mod-cta", text: this.buttonText }); + const submit = (): void => { + this.onSubmit(input.value); + this.close(); + }; + createButton.addEventListener("click", submit); + input.addEventListener("keydown", (event) => { + if (event.key === "Enter") { + event.preventDefault(); + submit(); + } else if (event.key === "Escape") { + event.preventDefault(); + this.close(); + } + }); + input.focus(); + input.select(); + } + + onClose(): void { + this.contentEl.empty(); + } +} + class TagSuggestModal extends SuggestModal { private tags: string[]; private onChoose: (tag: string) => void; @@ -2190,6 +2301,13 @@ function serializeMarkdown(root: MindNode): string { return `${lines.join("\n")}\n`; } +function sanitizeFileName(value: string): string { + return value + .replace(/[\\/:*?"<>|#^[\]]+/g, " ") + .replace(/\s+/g, " ") + .trim(); +} + function renderSvgDocument(items: PositionedNode[], title: string, showAssociationLinks = true): string { const bounds = getBounds(items); const pad = 80;