/ *
THIS IS A GENERATED / BUNDLED FILE BY ROLLUP
if you want to view the source visit the plugins github repository
* /
'use strict' ;
var obsidian = require ( 'obsidian' ) ;
/ * ! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Copyright ( c ) Microsoft Corporation .
Permission to use , copy , modify , and / or distribute this software for any
purpose with or without fee is hereby granted .
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS . IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL , DIRECT ,
INDIRECT , OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE , DATA OR PROFITS , WHETHER IN AN ACTION OF CONTRACT , NEGLIGENCE OR
OTHER TORTIOUS ACTION , ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /
function _ _awaiter ( thisArg , _arguments , P , generator ) {
function adopt ( value ) { return value instanceof P ? value : new P ( function ( resolve ) { resolve ( value ) ; } ) ; }
return new ( P || ( P = Promise ) ) ( function ( resolve , reject ) {
function fulfilled ( value ) { try { step ( generator . next ( value ) ) ; } catch ( e ) { reject ( e ) ; } }
function rejected ( value ) { try { step ( generator [ "throw" ] ( value ) ) ; } catch ( e ) { reject ( e ) ; } }
function step ( result ) { result . done ? resolve ( result . value ) : adopt ( result . value ) . then ( fulfilled , rejected ) ; }
step ( ( generator = generator . apply ( thisArg , _arguments || [ ] ) ) . next ( ) ) ;
} ) ;
}
function _ _classPrivateFieldGet ( receiver , state , kind , f ) {
if ( kind === "a" && ! f ) throw new TypeError ( "Private accessor was defined without a getter" ) ;
if ( typeof state === "function" ? receiver !== state || ! f : ! state . has ( receiver ) ) throw new TypeError ( "Cannot read private member from an object whose class did not declare it" ) ;
return kind === "m" ? f : kind === "a" ? f . call ( receiver ) : f ? f . value : state . get ( receiver ) ;
}
function _ _classPrivateFieldSet ( receiver , state , value , kind , f ) {
if ( kind === "m" ) throw new TypeError ( "Private method is not writable" ) ;
if ( kind === "a" && ! f ) throw new TypeError ( "Private accessor was defined without a setter" ) ;
if ( typeof state === "function" ? receiver !== state || ! f : ! state . has ( receiver ) ) throw new TypeError ( "Cannot write private member to an object whose class did not declare it" ) ;
return ( kind === "a" ? f . call ( receiver , value ) : f ? f . value = value : state . set ( receiver , value ) ) , value ;
}
const labeledRegex = / ^ [ \ t ] * ( ? : d a t e : ) ( . + ? ) ( ? : ^ [ \ t ] * ( ? : t i t l e : ) ( . + ? ) ) ? ( ? : ^ [ \ t ] * ( ? : c o n t e n t : ) ( . + ? ) ) ? ( ? = ^ [ \ t ] * d a t e : ) / g i m s u ;
//it uses the EventFactory provided to parse the source into Events
const timelineLabeledHandler = ( source , eventFactory ) => {
source += "\ndate: " ;
let sourceMatch ;
while ( ( sourceMatch = labeledRegex . exec ( source ) ) !== null ) {
eventFactory . create ( sourceMatch [ 1 ] , sourceMatch [ 2 ] , sourceMatch [ 3 ] ) ;
}
} ;
const timelineHandler = ( source , eventFactory ) => {
//source to events
const sourceSplitted = source . split ( /^\s*\+ ?/gm ) . slice ( 1 ) ;
//this is code is not readable
//sourceSplitted.push(...new Array(3 - (sourceSplitted.length % 3)).fill(""));
//adding 2 empty stings and 2 to sourceSplitted.length is safe and readble
sourceSplitted . push ( "" , "" ) ;
const counter = sourceSplitted . length - ( sourceSplitted . length % 3 ) ;
for ( let i = 0 ; i < counter ; i += 3 ) {
eventFactory . create ( sourceSplitted [ i ] , sourceSplitted [ i + 1 ] , sourceSplitted [ i + 2 ] ) ;
}
} ;
const toExport = [
{ tag : "timeline" , handler : timelineHandler } ,
{ tag : "timeline-labeled" , handler : timelineLabeledHandler } ,
] ;
var _EventFactory _root , _EventFactory _sourcePath , _EventFactory _eventCounter ;
//remove first child's top margin and last child's bottom margin
const trim = ( s ) => {
if ( s == null ) {
s = "" ;
return ;
}
s = s . trim ( ) ;
if ( s . length === 0 )
s = "\u200B" ;
} ;
class EventFactory {
constructor ( root , sourcePath ) {
_EventFactory _root . set ( this , void 0 ) ;
_EventFactory _sourcePath . set ( this , void 0 ) ;
//#markdownRenderChild: MarkdownRenderChild;
_EventFactory _eventCounter . set ( this , void 0 ) ;
this . create = ( time , title , description ) => {
trim ( time ) ;
trim ( title ) ;
trim ( description ) ;
let timeContainerEl = _ _classPrivateFieldGet ( this , _EventFactory _root , "f" ) . createDiv ( { cls : "time-container" } ) , timeEl = timeContainerEl . createDiv ( { cls : "time" } ) , infoEl = _ _classPrivateFieldGet ( this , _EventFactory _root , "f" ) . createDiv ( { cls : "info" } ) , titleEl = infoEl . createDiv ( { cls : "title" } ) , descriptionEl = infoEl . createDiv ( { cls : "description" } ) ;
obsidian . MarkdownRenderer . renderMarkdown ( time , timeEl , _ _classPrivateFieldGet ( this , _EventFactory _sourcePath , "f" ) , null //this.#markdownRenderChild
) ;
obsidian . MarkdownRenderer . renderMarkdown ( title , titleEl , _ _classPrivateFieldGet ( this , _EventFactory _sourcePath , "f" ) , null //this.#markdownRenderChild
) ;
obsidian . MarkdownRenderer . renderMarkdown ( description , descriptionEl , _ _classPrivateFieldGet ( this , _EventFactory _sourcePath , "f" ) , null //this.#markdownRenderChild
) ;
// regulate(descriptionEl);
// regulate(timeEl);
// regulate(titleEl);
_ _classPrivateFieldSet ( this , _EventFactory _eventCounter , + _ _classPrivateFieldGet ( this , _EventFactory _eventCounter , "f" ) + 1 , "f" ) ;
} ;
this . getEventCounter = ( ) => _ _classPrivateFieldGet ( this , _EventFactory _eventCounter , "f" ) ;
_ _classPrivateFieldSet ( this , _EventFactory _root , root , "f" ) ;
_ _classPrivateFieldSet ( this , _EventFactory _sourcePath , sourcePath , "f" ) ;
//this.#markdownRenderChild = new MarkdownRenderChild(root);
//this.markdownRenderChild.containerEl = root;
_ _classPrivateFieldSet ( this , _EventFactory _eventCounter , 0 , "f" ) ;
}
}
_EventFactory _root = new WeakMap ( ) , _EventFactory _sourcePath = new WeakMap ( ) , _EventFactory _eventCounter = new WeakMap ( ) ;
const classRegex = / ( ? < = ^ \ s * ) \ [ . + ? \ ] / g s ;
const stringToClassArray = ( input ) => {
input = input . trim ( ) ;
if ( input [ 0 ] != "[" || input [ input . length - 1 ] != "]" )
return [ ] ;
return input
. substring ( 1 , input . length - 1 )
. trim ( )
. split ( /\s*,\s*/ ) ;
} ;
class MyPlugin extends obsidian . Plugin {
constructor ( ) {
super ( ... arguments ) ;
this . onload = ( ) => _ _awaiter ( this , void 0 , void 0 , function * ( ) {
toExport . forEach ( ( { tag , handler } ) => {
this . registerMarkdownCodeBlockProcessor ( tag , ( source , el , ctx ) => {
let mainLine = el . createDiv ( {
cls : "main-line" ,
} ) ;
el . addClass ( "timeline" ) ;
let classMatch = source . match ( classRegex ) ;
if ( classMatch !== null ) {
let classes = stringToClassArray ( classMatch [ 0 ] ) ;
el . addClasses ( classes ) ;
}
let eventFactory = new EventFactory ( el , ctx . sourcePath ) ;
handler ( source , eventFactory ) ;
mainLine . style . gridRowEnd = ` ${ eventFactory . getEventCounter ( ) + 1 } ` ;
const links = el . querySelectorAll ( "a.internal-link" ) ;
this . addLinksToCache ( links , ctx . sourcePath ) ;
} ) ;
this . registerEvent ( this . app . metadataCache . on ( "resolve" , ( file ) => {
if ( this . app . workspace . getActiveFile ( ) != file )
return ;
const view = this . app . workspace . getActiveViewOfType ( obsidian . MarkdownView ) ;
if ( ! view || ! ( view instanceof obsidian . MarkdownView ) )
return ;
const admonitionLinks = view . contentEl . querySelectorAll ( "a.internal-link" ) ;
this . addLinksToCache ( admonitionLinks , file . path ) ;
} ) ) ;
} ) ;
} ) ;
}
addLinksToCache ( links , sourcePath ) {
/* / / @ ts - expect - error
this . app . metadataCache . resolveLinks ( sourcePath ) ; * /
for ( let i = 0 ; i < links . length ; i ++ ) {
const a = links [ i ] ;
if ( a . dataset . href ) {
let file = this . app . metadataCache . getFirstLinkpathDest ( a . dataset . href , "" ) ;
let cache , path ;
if ( file && file instanceof obsidian . TFile ) {
cache = this . app . metadataCache . resolvedLinks ;
path = file . path ;
}
else {
cache = this . app . metadataCache . unresolvedLinks ;
path = a . dataset . href ;
}
if ( ! cache [ sourcePath ] ) {
cache [ sourcePath ] = {
[ path ] : 0 ,
} ;
}
let resolved = cache [ sourcePath ] ;
if ( ! resolved [ path ] ) {
resolved [ path ] = 0 ;
}
resolved [ path ] += 1 ;
cache [ sourcePath ] = resolved ;
}
}
}
}
module . exports = MyPlugin ;
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWFpbi5qcyIsInNvdXJjZXMiOlsibm9kZV9tb2R1bGVzL3RzbGliL3RzbGliLmVzNi5qcyIsInNyYy9jb2RlQmxvY2tIYW5kbGVyLnRzIiwic3JjL0V2ZW50RmFjdG9yeS50cyIsIm1haW4udHMiXSwic291cmNlc0NvbnRlbnQiOlsiLyohICoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqXHJcbkNvcHlyaWdodCAoYykgTWljcm9zb2Z0IENvcnBvcmF0aW9uLlxyXG5cclxuUGVybWlzc2lvbiB0byB1c2UsIGNvcHksIG1vZGlmeSwgYW5kL29yIGRpc3RyaWJ1dGUgdGhpcyBzb2Z0d2FyZSBmb3IgYW55XHJcbnB1cnBvc2Ugd2l0aCBvciB3aXRob3V0IGZlZSBpcyBoZXJlYnkgZ3JhbnRlZC5cclxuXHJcblRIRSBTT0ZUV0FSRSBJUyBQUk9WSURFRCBcIkFTIElTXCIgQU5EIFRIRSBBVVRIT1IgRElTQ0xBSU1TIEFMTCBXQVJSQU5USUVTIFdJV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