/ *
THIS IS A GENERATED / BUNDLED FILE BY ESBUILD
if you want to view the source , please visit the github repository of this plugin
* /
var _ _create = Object . create ;
var _ _defProp = Object . defineProperty ;
var _ _getOwnPropDesc = Object . getOwnPropertyDescriptor ;
var _ _getOwnPropNames = Object . getOwnPropertyNames ;
var _ _getProtoOf = Object . getPrototypeOf ;
var _ _hasOwnProp = Object . prototype . hasOwnProperty ;
var _ _markAsModule = ( target ) => _ _defProp ( target , "__esModule" , { value : true } ) ;
var _ _export = ( target , all ) => {
_ _markAsModule ( target ) ;
for ( var name in all )
_ _defProp ( target , name , { get : all [ name ] , enumerable : true } ) ;
} ;
var _ _reExport = ( target , module2 , desc ) => {
if ( module2 && typeof module2 === "object" || typeof module2 === "function" ) {
for ( let key of _ _getOwnPropNames ( module2 ) )
if ( ! _ _hasOwnProp . call ( target , key ) && key !== "default" )
_ _defProp ( target , key , { get : ( ) => module2 [ key ] , enumerable : ! ( desc = _ _getOwnPropDesc ( module2 , key ) ) || desc . enumerable } ) ;
}
return target ;
} ;
var _ _toModule = ( module2 ) => {
return _ _reExport ( _ _markAsModule ( _ _defProp ( module2 != null ? _ _create ( _ _getProtoOf ( module2 ) ) : { } , "default" , module2 && module2 . _ _esModule && "default" in module2 ? { get : ( ) => module2 . default , enumerable : true } : { value : module2 , enumerable : true } ) ) , module2 ) ;
} ;
var _ _async = ( _ _this , _ _arguments , generator ) => {
return new Promise ( ( resolve , reject ) => {
var fulfilled = ( value ) => {
try {
step ( generator . next ( value ) ) ;
} catch ( e ) {
reject ( e ) ;
}
} ;
var rejected = ( value ) => {
try {
step ( generator . throw ( value ) ) ;
} catch ( e ) {
reject ( e ) ;
}
} ;
var step = ( x ) => x . done ? resolve ( x . value ) : Promise . resolve ( x . value ) . then ( fulfilled , rejected ) ;
step ( ( generator = generator . apply ( _ _this , _ _arguments ) ) . next ( ) ) ;
} ) ;
} ;
// src/main.ts
_ _export ( exports , {
default : ( ) => DialoguePlugin
} ) ;
var import _obsidian2 = _ _toModule ( require ( "obsidian" ) ) ;
// src/types/dialogueTitleMode.ts
var DialogueTitleMode ;
( function ( DialogueTitleMode2 ) {
DialogueTitleMode2 [ "Disabled" ] = "disabled" ;
DialogueTitleMode2 [ "First" ] = "first" ;
DialogueTitleMode2 [ "All" ] = "all" ;
} ) ( DialogueTitleMode || ( DialogueTitleMode = { } ) ) ;
// src/constants/classes.ts
var CLASSES = class {
} ;
CLASSES . DIALOGUE _WRAPPER = "dialogue-plugin-wrapper" ;
CLASSES . BLOCK _WRAPPER = "dialogue-plugin-block-wrapper" ;
CLASSES . MESSAGE _WRAPPER _LEFT = "dialogue-plugin-message-wrapper-left" ;
CLASSES . MESSAGE _WRAPPER _RIGHT = "dialogue-plugin-message-wrapper-right" ;
CLASSES . MESSAGE = "dialogue-plugin-message" ;
CLASSES . MESSAGE _TITLE = "dialogue-plugin-message-title" ;
CLASSES . MESSAGE _CONTENT = "dialogue-plugin-message-content" ;
CLASSES . DELIMITER _WRAPPER = "dialogue-plugin-delimiter-wrapper" ;
CLASSES . DELIMITER = "dialogue-plugin-delimiter" ;
CLASSES . DELIMITER _DOT = "dialogue-plugin-delimiter-dot" ;
CLASSES . COMMENT _WRAPPER = "dialogue-plugin-comment-wrapper" ;
CLASSES . COMMENT = "dialogue-plugin-comment" ;
// src/components/message.ts
var SIDES = class {
} ;
SIDES . LEFT = "left" ;
SIDES . RIGHT = "right" ;
var Message = class {
constructor ( content , side , dialogueSettings ) {
this . content = content ;
this . side = side ;
this . dialogueSettings = dialogueSettings ;
this . participant = this . side == SIDES . LEFT ? this . dialogueSettings . leftParticipant : this . dialogueSettings . rightParticipant ;
this . renderMessage ( ) ;
}
renderMessage ( ) {
const messageEl = this . createMessageEl ( ) ;
if ( this . titleShouldRender ( ) ) {
messageEl . createDiv ( { cls : CLASSES . MESSAGE _TITLE , text : this . participant . title } ) ;
}
messageEl . createDiv ( { cls : CLASSES . MESSAGE _CONTENT , text : this . content } ) ;
}
createMessageEl ( ) {
var _a ;
const sideClass = this . side == SIDES . LEFT ? CLASSES . MESSAGE _WRAPPER _LEFT : CLASSES . MESSAGE _WRAPPER _RIGHT ;
const messageWrapperEl = this . dialogueSettings . parent . createDiv ( {
cls : ` ${ CLASSES . BLOCK _WRAPPER } ${ sideClass } `
} ) ;
return messageWrapperEl . createDiv ( {
cls : CLASSES . MESSAGE ,
attr : {
style : ` max-width: ${ this . dialogueSettings . messageMaxWidth } ; ` ,
"data-participant-name" : this . participant . title ,
"data-participant-id" : ( _a = this . participant . enforcedId ) != null ? _a : this . dialogueSettings . participants . get ( this . participant . title )
}
} ) ;
}
titleShouldRender ( ) {
if ( this . participant . title . length < 1 )
return false ;
switch ( this . dialogueSettings . titleMode ) {
case DialogueTitleMode . Disabled :
return false ;
case DialogueTitleMode . All :
return true ;
case DialogueTitleMode . First : {
if ( this . participant . renderedOnce )
return false ;
this . participant . renderedOnce = true ;
return true ;
}
default :
return false ;
}
}
} ;
// src/components/delimiter.ts
var Delimiter = class {
constructor ( dialogueSettings ) {
this . dialogueSettings = dialogueSettings ;
this . renderDelimiter ( ) ;
}
renderDelimiter ( ) {
const delimiterWrapperEl = this . dialogueSettings . parent . createDiv ( {
cls : ` ${ CLASSES . BLOCK _WRAPPER } ${ CLASSES . DELIMITER _WRAPPER } `
} ) ;
const delimiterEl = delimiterWrapperEl . createDiv ( { cls : CLASSES . DELIMITER } ) ;
delimiterEl . createEl ( "div" , { cls : CLASSES . DELIMITER _DOT } ) ;
delimiterEl . createEl ( "div" , { cls : CLASSES . DELIMITER _DOT } ) ;
delimiterEl . createEl ( "div" , { cls : CLASSES . DELIMITER _DOT } ) ;
}
} ;
// src/components/comment.ts
var Comment = class {
constructor ( content , dialogueSettings ) {
this . content = content ;
this . dialogueSettings = dialogueSettings ;
this . renderComment ( ) ;
}
renderComment ( ) {
const commentEl = this . dialogueSettings . parent . createDiv ( {
cls : ` ${ CLASSES . BLOCK _WRAPPER } ${ CLASSES . COMMENT _WRAPPER } `
} ) ;
return commentEl . createDiv ( {
cls : CLASSES . COMMENT ,
text : this . content ,
attr : {
style : ` max-width: ${ this . dialogueSettings . commentMaxWidth } ; `
}
} ) ;
}
} ;
// src/dialogue.ts
var KEYWORDS = class {
} ;
KEYWORDS . LEFT _PATTERN = /^l(?:eft)?(?:-(\d+))?:/i ;
KEYWORDS . RIGHT _PATTERN = /^r(?:ight)?(?:-(\d+))?:/i ;
KEYWORDS . TITLE _MODE = "titleMode:" ;
KEYWORDS . MESSAGE _MAX _WIDTH = "messageMaxWidth:" ;
KEYWORDS . COMMENT _MAX _WIDTH = "commentMaxWidth:" ;
KEYWORDS . DELIMITER = /^-|delimiter/ ;
KEYWORDS . COMMENT = "#" ;
KEYWORDS . MESSAGE _LEFT = "<" ;
KEYWORDS . MESSAGE _RIGHT = ">" ;
var DialogueRenderer = class {
constructor ( src , parent , settings ) {
this . src = src ;
this . dialogueWrapperEl = parent . createDiv ( { cls : CLASSES . DIALOGUE _WRAPPER } ) ;
this . dialogueSettings = {
parent : this . dialogueWrapperEl ,
leftParticipant : {
title : settings . defaultLeftTitle ,
renderedOnce : false ,
enforcedId : null
} ,
rightParticipant : {
title : settings . defaultRightTitle ,
renderedOnce : false ,
enforcedId : null
} ,
titleMode : settings . defaultTitleMode ,
messageMaxWidth : settings . defaultMessageMaxWidth ,
commentMaxWidth : settings . defaultCommentMaxWidth ,
participants : new Map ( )
} ;
this . renderDialogue ( ) ;
}
registerParticipant ( participant ) {
if ( ! this . dialogueSettings . participants . has ( participant ) ) {
this . dialogueSettings . participants . set ( participant , this . dialogueSettings . participants . size + 1 ) ;
}
}
getEnforcedId ( pattern , line ) {
let enforcedId = null ;
const result = pattern . exec ( line ) ;
if ( result != null && result . length > 1 ) {
enforcedId = result [ 1 ] ;
}
return enforcedId ;
}
renderDialogue ( ) {
const lines = this . src . split ( /\r?\n/ ) . map ( ( line ) => line . trim ( ) ) . filter ( ( line ) => line . length > 0 ) ;
for ( const line of lines ) {
if ( KEYWORDS . LEFT _PATTERN . test ( line ) ) {
this . dialogueSettings . leftParticipant . title = line . split ( ":" ) . splice ( 1 ) . join ( ":" ) . trim ( ) ;
this . dialogueSettings . leftParticipant . renderedOnce = false ;
this . dialogueSettings . leftParticipant . enforcedId = this . getEnforcedId ( KEYWORDS . LEFT _PATTERN , line ) ;
} else if ( KEYWORDS . RIGHT _PATTERN . test ( line ) ) {
this . dialogueSettings . rightParticipant . title = line . split ( ":" ) . splice ( 1 ) . join ( ":" ) . trim ( ) ;
this . dialogueSettings . rightParticipant . renderedOnce = false ;
this . dialogueSettings . rightParticipant . enforcedId = this . getEnforcedId ( KEYWORDS . RIGHT _PATTERN , line ) ;
} else if ( line . startsWith ( KEYWORDS . TITLE _MODE ) ) {
const modeName = line . substr ( KEYWORDS . TITLE _MODE . length ) . trim ( ) . toLowerCase ( ) ;
if ( Object . values ( DialogueTitleMode ) . some ( ( mode ) => mode == modeName ) ) {
this . dialogueSettings . titleMode = modeName ;
}
} else if ( line . startsWith ( KEYWORDS . MESSAGE _MAX _WIDTH ) ) {
this . dialogueSettings . messageMaxWidth = line . substr ( KEYWORDS . MESSAGE _MAX _WIDTH . length ) . trim ( ) ;
} else if ( line . startsWith ( KEYWORDS . COMMENT _MAX _WIDTH ) ) {
this . dialogueSettings . commentMaxWidth = line . substr ( KEYWORDS . COMMENT _MAX _WIDTH . length ) . trim ( ) ;
} else if ( KEYWORDS . DELIMITER . test ( line ) ) {
new Delimiter ( this . dialogueSettings ) ;
} else if ( line . startsWith ( KEYWORDS . COMMENT ) ) {
const content = line . substr ( KEYWORDS . COMMENT . length ) ;
new Comment ( content , this . dialogueSettings ) ;
} else if ( line . startsWith ( KEYWORDS . MESSAGE _LEFT ) ) {
const content = line . substr ( KEYWORDS . MESSAGE _LEFT . length ) ;
this . registerParticipant ( this . dialogueSettings . leftParticipant . title ) ;
new Message ( content , SIDES . LEFT , this . dialogueSettings ) ;
} else if ( line . startsWith ( KEYWORDS . MESSAGE _RIGHT ) ) {
const content = line . substr ( KEYWORDS . MESSAGE _RIGHT . length ) ;
this . registerParticipant ( this . dialogueSettings . rightParticipant . title ) ;
new Message ( content , SIDES . RIGHT , this . dialogueSettings ) ;
}
}
}
} ;
// src/settings.ts
var import _obsidian = _ _toModule ( require ( "obsidian" ) ) ;
var DEFAULT _SETTINGS = {
defaultLeftTitle : "" ,
defaultRightTitle : "" ,
defaultTitleMode : DialogueTitleMode . First ,
defaultMessageMaxWidth : "60%" ,
defaultCommentMaxWidth : "60%"
} ;
var DialogueSettingTab = class extends import _obsidian . PluginSettingTab {
constructor ( app , plugin ) {
super ( app , plugin ) ;
this . plugin = plugin ;
}
display ( ) {
const { containerEl } = this ;
containerEl . empty ( ) ;
containerEl . createEl ( "h2" , { text : "Dialogue Settings" } ) ;
const coffeeEl = containerEl . createEl ( "div" , {
attr : {
style : "text-align: center; margin-bottom: 10px;"
}
} ) ;
const coffeeLinkEl = coffeeEl . createEl ( "a" , { href : "https://www.buymeacoffee.com/holubj" } ) ;
coffeeLinkEl . createEl ( "img" , {
attr : {
src : "https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" ,
alt : "Buy Me A Coffee" ,
style : "height: 60px; width: 217px;"
}
} ) ;
new import _obsidian . Setting ( containerEl ) . setName ( "Default left title" ) . setDesc ( "Default value for left title in all dialogues." ) . addText ( ( text ) => text . setPlaceholder ( "Enter default left title" ) . setValue ( this . plugin . settings . defaultLeftTitle ) . onChange ( ( value ) => _ _async ( this , null , function * ( ) {
this . plugin . settings . defaultLeftTitle = value ;
yield this . plugin . saveSettings ( ) ;
} ) ) ) ;
new import _obsidian . Setting ( containerEl ) . setName ( "Default right title" ) . setDesc ( "Default value for right title in all dialogues." ) . addText ( ( text ) => text . setPlaceholder ( "Enter default right title" ) . setValue ( this . plugin . settings . defaultRightTitle ) . onChange ( ( value ) => _ _async ( this , null , function * ( ) {
this . plugin . settings . defaultRightTitle = value ;
yield this . plugin . saveSettings ( ) ;
} ) ) ) ;
new import _obsidian . Setting ( containerEl ) . setName ( "Default title mode" ) . setDesc ( "Default title mode in all dialogues." ) . addDropdown ( ( cb ) => {
Object . values ( DialogueTitleMode ) . forEach ( ( titleMode ) => {
const mode = titleMode . toString ( ) ;
cb . addOption ( mode , mode . charAt ( 0 ) . toUpperCase ( ) + mode . slice ( 1 ) ) ;
} ) ;
cb . setValue ( this . plugin . settings . defaultTitleMode ) . onChange ( ( value ) => _ _async ( this , null , function * ( ) {
this . plugin . settings . defaultTitleMode = value ;
yield this . plugin . saveSettings ( ) ;
} ) ) ;
} ) ;
new import _obsidian . Setting ( containerEl ) . setName ( "Default max message width" ) . setDesc ( "Default max message width in all dialogues." ) . addText ( ( text ) => text . setPlaceholder ( "Enter default max message width" ) . setValue ( this . plugin . settings . defaultMessageMaxWidth ) . onChange ( ( value ) => _ _async ( this , null , function * ( ) {
this . plugin . settings . defaultMessageMaxWidth = value ;
yield this . plugin . saveSettings ( ) ;
} ) ) ) ;
new import _obsidian . Setting ( containerEl ) . setName ( "Default max comment width" ) . setDesc ( "Default max comment width in all dialogues." ) . addText ( ( text ) => text . setPlaceholder ( "Enter default max comment width" ) . setValue ( this . plugin . settings . defaultCommentMaxWidth ) . onChange ( ( value ) => _ _async ( this , null , function * ( ) {
this . plugin . settings . defaultCommentMaxWidth = value ;
yield this . plugin . saveSettings ( ) ;
} ) ) ) ;
}
} ;
// src/main.ts
var DialoguePlugin = class extends import _obsidian2 . Plugin {
onload ( ) {
return _ _async ( this , null , function * ( ) {
yield this . loadSettings ( ) ;
this . registerMarkdownCodeBlockProcessor ( ` dialogue ` , ( src , el , ctx ) => {
new DialogueRenderer ( src , el , this . settings ) ;
} ) ;
this . addSettingTab ( new DialogueSettingTab ( this . app , this ) ) ;
} ) ;
}
loadSettings ( ) {
return _ _async ( this , null , function * ( ) {
this . settings = Object . assign ( { } , DEFAULT _SETTINGS , yield this . loadData ( ) ) ;
} ) ;
}
saveSettings ( ) {
return _ _async ( this , null , function * ( ) {
yield this . saveData ( this . settings ) ;
} ) ;
}
} ;