mirror of
https://github.com/dwolfe884/obsidian-x86-flow-graph.git
synced 2026-07-22 07:30:26 +00:00
243 lines
8.4 KiB
JavaScript
243 lines
8.4 KiB
JavaScript
/*
|
|
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
|
|
if you want to view the source, please visit the github repository of this plugin
|
|
*/
|
|
|
|
var __defProp = Object.defineProperty;
|
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
var __export = (target, all) => {
|
|
for (var name in all)
|
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
};
|
|
var __copyProps = (to, from, except, desc) => {
|
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
for (let key of __getOwnPropNames(from))
|
|
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
}
|
|
return to;
|
|
};
|
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
|
|
// src/index.ts
|
|
var src_exports = {};
|
|
__export(src_exports, {
|
|
default: () => MyPlugin
|
|
});
|
|
module.exports = __toCommonJS(src_exports);
|
|
var import_obsidian = require("obsidian");
|
|
var nodeid = 1;
|
|
var edgeid = 5555;
|
|
var workingx = 0;
|
|
var workingy = 0;
|
|
var nodes = [];
|
|
var edges = [];
|
|
var lines = [];
|
|
var fromnode = -1;
|
|
var locations = {};
|
|
var visitslocs = {};
|
|
var DEFAULT_SETTINGS = {
|
|
mySetting: "default"
|
|
};
|
|
var MyPlugin = class extends import_obsidian.Plugin {
|
|
async onload() {
|
|
await this.loadSettings();
|
|
const ribbonIconEl = this.addRibbonIcon("dice", "Sample Plugin", (evt) => {
|
|
new import_obsidian.Notice("This is a notice!");
|
|
});
|
|
ribbonIconEl.addClass("my-plugin-ribbon-class");
|
|
const statusBarItemEl = this.addStatusBarItem();
|
|
statusBarItemEl.setText("Status Bar Text");
|
|
this.addCommand({
|
|
id: "create-flow-diagram",
|
|
name: "Convert x86 assembly into a flow diagram on a canvas",
|
|
editorCallback: (editor, view) => {
|
|
console.log(editor.getSelection());
|
|
console.log(this.app.vault.getName());
|
|
lines = [];
|
|
nodes = [];
|
|
nodes = [];
|
|
edges = [];
|
|
nodeid = 1;
|
|
edgeid = 5555;
|
|
workingx = 0;
|
|
workingy = 0;
|
|
var tmp = editor.getSelection().split("\n");
|
|
tmp.forEach((element) => {
|
|
if (element != "") {
|
|
lines.push(element);
|
|
}
|
|
});
|
|
lines.forEach((line, linenum) => {
|
|
if (line.split("")[0] != " " && line.split("")[0] != " ") {
|
|
var newkey = line.trim().split("#")[0].trim();
|
|
if (!locations[newkey]) {
|
|
locations[newkey] = linenum;
|
|
visitslocs[newkey] = 0;
|
|
}
|
|
}
|
|
});
|
|
generatenodes(0, lines, fromnode);
|
|
this.app.vault.create("/pleasegod.canvas", '{ "nodes":' + JSON.stringify(nodes) + ',"edges":' + JSON.stringify(edges) + "}");
|
|
console.log('{ "nodes":' + JSON.stringify(nodes) + ',"edges":' + JSON.stringify(edges) + "}");
|
|
}
|
|
});
|
|
this.addCommand({
|
|
id: "open-sample-modal-complex",
|
|
name: "Open sample modal (complex)",
|
|
checkCallback: (checking) => {
|
|
const markdownView = this.app.workspace.getActiveViewOfType(import_obsidian.MarkdownView);
|
|
if (markdownView) {
|
|
if (!checking) {
|
|
new SampleModal(this.app).open();
|
|
}
|
|
return true;
|
|
}
|
|
}
|
|
});
|
|
this.addSettingTab(new SampleSettingTab(this.app, this));
|
|
this.registerInterval(window.setInterval(() => console.log("setInterval"), 5 * 60 * 1e3));
|
|
}
|
|
onunload() {
|
|
}
|
|
async loadSettings() {
|
|
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
|
|
}
|
|
async saveSettings() {
|
|
await this.saveData(this.settings);
|
|
}
|
|
};
|
|
var SampleModal = class extends import_obsidian.Modal {
|
|
constructor(app) {
|
|
super(app);
|
|
}
|
|
onOpen() {
|
|
const { contentEl } = this;
|
|
contentEl.setText("Woah!");
|
|
}
|
|
onClose() {
|
|
const { contentEl } = this;
|
|
contentEl.empty();
|
|
}
|
|
};
|
|
var SampleSettingTab = class extends import_obsidian.PluginSettingTab {
|
|
constructor(app, plugin) {
|
|
super(app, plugin);
|
|
this.plugin = plugin;
|
|
}
|
|
display() {
|
|
const { containerEl } = this;
|
|
containerEl.empty();
|
|
containerEl.createEl("h2", { text: "Settings for my awesome plugin." });
|
|
new import_obsidian.Setting(containerEl).setName("Setting #1").setDesc("It's a secret").addText((text) => text.setPlaceholder("Enter your secret").setValue(this.plugin.settings.mySetting).onChange(async (value) => {
|
|
console.log("Secret: " + value);
|
|
this.plugin.settings.mySetting = value;
|
|
await this.plugin.saveSettings();
|
|
}));
|
|
}
|
|
};
|
|
function generatenodes(linenum, text, fromnode2) {
|
|
console.log(locations);
|
|
var retarray = MakeNodeFromLineToNextJump(linenum, text, fromnode2);
|
|
var newnode = retarray[0];
|
|
fromnode2 = newnode["id"];
|
|
console.log("fromnode is " + fromnode2);
|
|
var whereto = retarray[1];
|
|
var wegood = nodeAlredyAdded(newnode);
|
|
if (wegood) {
|
|
return;
|
|
} else {
|
|
nodes.push(newnode);
|
|
}
|
|
console.log('{ "nodes":' + JSON.stringify(nodes) + "}");
|
|
console.log("need to jump here: " + whereto);
|
|
if (whereto == "fin") {
|
|
return;
|
|
}
|
|
generatenodes(locations[whereto[0]], text, fromnode2);
|
|
if (whereto.length == 2) {
|
|
console.log("Oh boy, we at a split");
|
|
console.log("going to line: " + whereto[1]);
|
|
generatenodes(whereto[1], text, fromnode2);
|
|
}
|
|
return;
|
|
}
|
|
function nodeAlredyAdded(checknode) {
|
|
var retval = false;
|
|
nodes.forEach((node) => {
|
|
if (checknode["startline"] == node["startline"] && checknode["endline"] == node["endline"]) {
|
|
retval = true;
|
|
}
|
|
});
|
|
return retval;
|
|
}
|
|
function MakeNodeFromLineToNextJump(linenum, text, fromnode2) {
|
|
var currnode = "```\n";
|
|
var i = linenum;
|
|
var newnode;
|
|
var jmploc;
|
|
var newedge = {};
|
|
console.log("curr line: " + i);
|
|
while (i < text.length) {
|
|
var line = text[i];
|
|
console.log("currently processing this line: " + line);
|
|
if (line.split("")[0] == " " || line.split("")[0] == " ") {
|
|
if (line.trim().split("")[0] == "j") {
|
|
currnode = currnode + line + "\n```";
|
|
newnode = { "id": nodeid, "x": workingx, "y": workingy, "width": 550, "height": 25 * currnode.split("\n").length, "type": "text", "text": currnode, "startline": linenum, "endline": i };
|
|
nodeid = nodeid + 1;
|
|
workingy = workingy + 350;
|
|
console.log(line.trim().slice(0, 3));
|
|
if (fromnode2 != -1) {
|
|
newedge = { "id": edgeid, "fromNode": fromnode2, "fromSide": "bottom", "toNode": newnode["id"], "toSide": "top", "label": "" };
|
|
edges.push(newedge);
|
|
edgeid = edgeid + 1;
|
|
}
|
|
if (line.trim().slice(0, 3) == "jmp") {
|
|
jmploc = [line.trim().slice(line.trim().indexOf(" ") + 1, line.length).split("#")[0].trim()];
|
|
} else {
|
|
jmploc = [line.trim().slice(line.trim().indexOf(" ") + 1, line.length).split("#")[0].trim(), i + 1];
|
|
}
|
|
i = text.length + 20;
|
|
} else {
|
|
currnode = currnode + line + "\n";
|
|
}
|
|
} else {
|
|
if (visitslocs[line.trim()] == 0) {
|
|
currnode = currnode + line + "\n";
|
|
visitslocs[line.trim()] = nodeid;
|
|
} else {
|
|
currnode = currnode + "\n```";
|
|
newnode = { "id": nodeid, "x": workingx, "y": workingy, "width": 550, "height": 25 * currnode.split("\n").length, "type": "text", "text": currnode, "startline": linenum, "endline": i };
|
|
workingy = workingy + 350;
|
|
if (fromnode2 != -1) {
|
|
newedge = { "id": edgeid, "fromNode": fromnode2, "fromSide": "bottom", "toNode": newnode["id"], "toSide": "top", "label": "" };
|
|
edges.push(newedge);
|
|
edgeid = edgeid + 1;
|
|
newedge = { "id": edgeid, "fromNode": nodeid, "fromSide": "bottom", "toNode": visitslocs[line.trim()], "toSide": "top", "label": "" };
|
|
edges.push(newedge);
|
|
edgeid = edgeid + 1;
|
|
}
|
|
nodeid = nodeid + 1;
|
|
i = text.length + 20;
|
|
jmploc = "fin";
|
|
}
|
|
}
|
|
i = i + 1;
|
|
}
|
|
if (i != text.length + 21) {
|
|
currnode = currnode + "```";
|
|
newnode = { "id": nodeid, "x": workingx, "y": workingy, "width": 550, "height": 25 * currnode.split("\n").length, "type": "text", "text": currnode, "startline": linenum, "endline": i };
|
|
jmploc = "fin";
|
|
nodeid = nodeid + 1;
|
|
workingy = workingy + 350;
|
|
if (fromnode2 != -1) {
|
|
newedge = { "id": edgeid, "fromNode": fromnode2, "fromSide": "bottom", "toNode": newnode["id"], "toSide": "top", "label": "" };
|
|
edges.push(newedge);
|
|
edgeid = edgeid + 1;
|
|
}
|
|
}
|
|
return [newnode, jmploc];
|
|
}
|