2023-02-03 18:11:50 +00:00
/ *
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" ) ;
2023-02-04 02:31:12 +00:00
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 = { } ;
2023-02-03 18:11:50 +00:00
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 ( {
2023-02-03 22:30:39 +00:00
id : "create-flow-diagram" ,
name : "Convert x86 assembly into a flow diagram on a canvas" ,
2023-02-03 18:11:50 +00:00
editorCallback : ( editor , view ) => {
console . log ( editor . getSelection ( ) ) ;
console . log ( this . app . vault . getName ( ) ) ;
2023-02-04 02:31:12 +00:00
lines = [ ] ;
nodes = [ ] ;
nodes = [ ] ;
edges = [ ] ;
nodeid = 1 ;
edgeid = 5555 ;
workingx = 0 ;
workingy = 0 ;
2023-02-03 22:30:39 +00:00
var tmp = editor . getSelection ( ) . split ( "\n" ) ;
tmp . forEach ( ( element ) => {
if ( element != "" ) {
lines . push ( element ) ;
}
} ) ;
lines . forEach ( ( line , linenum ) => {
2023-02-04 02:31:12 +00:00
if ( line . split ( "" ) [ 0 ] != " " && line . split ( "" ) [ 0 ] != " " ) {
var newkey = line . trim ( ) . split ( "#" ) [ 0 ] . trim ( ) ;
if ( ! locations [ newkey ] ) {
locations [ newkey ] = linenum ;
visitslocs [ newkey ] = 0 ;
2023-02-03 22:30:39 +00:00
}
}
} ) ;
2023-02-04 02:31:12 +00:00
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 ) + "}" ) ;
2023-02-03 18:11:50 +00:00
}
} ) ;
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 ( ) ;
} ) ) ;
}
} ;
2023-02-04 02:31:12 +00:00
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 ] ;
}