first commit

This commit is contained in:
2025-09-25 20:00:00 -04:00
commit 7697252ba3
4071 changed files with 1606306 additions and 0 deletions

267
node_modules/obsidian/CHANGELOG.md generated vendored Normal file
View File

@@ -0,0 +1,267 @@
# Changelog
This CHANGELOG details any breaking changes to the API or new additions that require additional context. The versions listed below correspond to the versions of the Obsidian app. There may not be a corresponding package version for the version listed below.
## [v1.7.2](<https://github.com/obsidianmd/obsidian-api/commit/6933c6227617897e031f30c734f61167cedafb7d>) (Insider)
### Workspace changes
- New function `Plugin#onUserEnable` gives you a place to performance one-time initialize after the user installs and enables your plugin. If your plugin has a custom view, this is a good place to initialize it rather than recreating the view in `Plugin#onload`.
- `Workspace#ensureSideLeaf` is now public. This function is a shorthand way to create a leaf in the sidebar if one does not already exist.
- Added `WorkspaceLeaf#isDeferred` and `WorkspaceLeaf#loadIfDeferred`. As of Obsidian v1.7.2, Obsidian will now defer tabs by default. We published [a guide on how to handle deferred views](<https://publish.obsidian.md/dev-docs-test/Plugins/Guides/Understanding+deferred+views>) in the developer docs.
### Housekeeping
We've updated the API to prefer `unknown` to `any`. Using `any` causes Typescript to disable typechecking entirely on the returned value, so this change could uncover some hidden typing issues.
We also removed `prepareQuery`, `fuzzySearch`, and `PreparedQuery` from the API. If your plugin is using one of these functions, you should migrate to `prepareFuzzySearch`.
```ts
// Old
let pq: PreparedQuery = prepareQuery(q);
...
fuzzySearch(pq, text);
// New
let fuzzy = prepareFuzzySearch(q);
...
fuzzy(text);
```
### Misc
- New `Plugin#removeCommand` is now available if your plugin needs to dynamically remove commands (for example, if your plugin allows for user-created commands).
- `SuggestModal#selectActiveSuggestion` is now public. This is useful to provide an alternative hotkey to your SuggestModal that still triggers the selected item.
## v1.7.0 (Insider)
- Fixed `FileSystemAdapter#rmdir(dirPath, false)` always throwing an error when attempting to delete an empty directory.
- Added a `data-type` to the Markdown embed container using subpath type.
## v1.5.11
- Fixed `revealLeaf` failing to focus the correct window.
- If you are using the `SliderComponent` in your app, be aware, the behavior of the component has changed in 1.5.9. Now, instead of updating the value when the slider is dragged, it will only update the value when the slider is released. If your plugin was relying on the old behavior, you will need to update your plugin code to call `.setInstant(true)` on the slider.
**Note:** Because `setInstant` is a new function, you'll also need to check to see if the function exists before calling it. This will ensure your plugin maintains backwards compatibility when being run on older versions of Obsidian.
## v1.5.7
### `Plugin#onExternalSettingsChange`
There's a new callback function for plugins to react to when plugin settings (`data.json`) get changed on disk. This callback can be used to reload settings when they are updated by an external application or when the settings get synced using a file syncing service like Obsidian Sync.
### New `Vault#getFileByPath` and `Vault#getFolderByPath` utility functions
The `getAbstractFileByPath` has long been a point of confusion with plugin developers. More often than not,
you are looking for either a file or a folder. And you know which you want at call-time. Instead of using
`getAbstractFileByPath` then checking if the result is an instance of `TFile` or `TFolder`, now you can just
use `getFileByPath` or `getFolderByPath` to automatically do this check.
### `View.scope` is now public
Finally `scope` is made public on the `View` class. This means you can assign hotkeys for when your view is
active and focused.
### New `getFrontMatterInfo` utility
There is now a canonical way to find the offsets of where the frontmatter ends and where the content starts in a file.
### `FileManager#getAvailablePathForAttachment`
If your plugin saves attachments to the vault, you should be using `getAvailablePathForAttachment`. It will generate a safe path for you to use that respects the user's settings for file attachments.
## v1.4.4
We've exposed our helper function for setting tooltips on elements (`setTooltip`) as well as added a new progress bar component.
The `FileManager#processFrontMatter` function now also exposes the DataWriteOptions argument to be consistent with the other `process` and `write` functions.
## v1.4.0
We've made some changes to `CachedMetadata` to support **Properties**. `FrontMatterCache` is now no longer a `CacheItem`—meaning that it doesn't have a position. Instead, is it a _Reference_.
Another big change in v.1.4 is that frontmatter now supports wikilinks. If a value in the frontmatter can be interpreted as a link, it will be cached inside `CachedMetadata.frontmatterLinks`.
## v1.1.3
- Updated the [Canvas spec](https://github.com/obsidianmd/obsidian-api/blob/master/canvas.d.ts) to indicate that colors can be stored in 1 or 2 formats:
- as a hex string (i.e. "#FFFFFF")
- as a number "1", "2", etc.
If it's a number, this refers to the palette position. It can be themed via CSS variables.
### Theme Changes
There are some new CSS variables related to canvas and callouts in 1.1.3+. All the extended palette colors now have an RGB variant that is used for callouts and canvas colors. The hex values are primarily used for syntax highlighting.
```css
body {
--callout-bug: var(--color-red-rgb);
--callout-default: var(--color-blue-rgb);
--callout-error: var(--color-red-rgb);
--callout-example: var(--color-purple-rgb);
--callout-fail: var(--color-red-rgb);
--callout-important: var(--color-cyan-rgb);
--callout-info: var(--color-blue-rgb);
--callout-question: var(--color-yellow-rgb);
--callout-success: var(--color-green-rgb);
--callout-summary: var(--color-cyan-rgb);
--callout-tip: var(--color-cyan-rgb);
--callout-todo: var(--color-blue-rgb);
--callout-warning: var(--color-orange-rgb);
--callout-quote: 158, 158, 158;
}
.theme-light {
--color-red-rgb: 228, 55, 75;
--color-red: #E4374B;
--color-orange-rgb: 217, 108, 0;
--color-orange: #d96c00;
--color-yellow-rgb: 189, 142, 55;
--color-yellow: #BD8E37;
--color-green-rgb: 12, 181, 79;
--color-green: #0cb54f;
--color-cyan-rgb: 45, 183, 181;
--color-cyan: #2db7b5;
--color-blue-rgb: 8, 109, 221;
--color-blue: #086DDD;
--color-purple-rgb: 135, 107, 224;
--color-purple: #876be0;
--color-pink-rgb: 195, 43, 116;
--color-pink: #C32B74;
}
.theme-dark {
--color-red-rgb: 251, 70, 76;
--color-red: #fb464c;
--color-orange-rgb: 233, 151, 63;
--color-orange: #E9973F;
--color-yellow-rgb: 224, 222, 113;
--color-yellow: #E0DE71;
--color-green-rgb: 68, 207, 110;
--color-green: #44CF6E;
--color-cyan-rgb: 83, 223, 221;
--color-cyan: #53DFDD;
--color-blue-rgb: 2, 122, 255;
--color-blue: #027aff;
--color-purple-rgb: 168, 130, 255;
--color-purple: #a882ff;
--color-pink-rgb: 250, 153, 205;
--color-pink: #FA99CD;
}
```
## v1.1.1 (2022-12-8 — Insider build)
_[Changes since v1.0](https://github.com/obsidianmd/obsidian-api/compare/32fe4c3f...6161bf59)_
- [`file-open`](https://github.com/obsidianmd/obsidian-api/blob/ec589e9762a1d7e2faad01f894cb34c41b10ecaf/obsidian.d.ts#L4189) event is now fired when focusing a Canvas file card.
- Exposed the `activeEditor` on the Workspace. When a markdown view is active, this will point to the underlying `MarkdownEditView`. If a canvas view is active, this will be an EmbeddedEditor component.
With these two changes, plugins should be able to adapt to the new Canvas view quite easily. Custom
views that react the the currently focused views will automatically respond to the user clicking
on file cards in the canvas. If a plugin is currently accessing the `Editor` using the following
approach:
```ts
let view = app.workspace.getActiveViewOfType(MarkdownView);
if (view) {
let editor = view.editor;
// or
let file = view.file;
}
```
Instead you can access the `editor` or `file` by looking under the `activeEditor`:
```ts
let { activeEditor } = app.workspace;
if (activeEditor) {
let editor = activeEditor.editor;
let file = activeEditor.file;
}
```
## v1.1.0 (2022-12-05 — Insider build)
_[Changes since v1.0](https://github.com/obsidianmd/obsidian-api/compare/1b4f6e2...32fe4c3f)_
### New Metadata API
In anticipation of bigger improvements to metadata and frontmatter in Obsidian, we have introduced a new metadata API.
It is currently defined as follows:
```ts
interface FileManager {
/**
* Atomically read, modify, and save the frontmatter of a note.
* The frontmatter is passed in as a JS object, and should be mutated directly to achieve the desired result.
* @param file - the file to be modified. Must be a markdown file.
* @param fn - a callback function which mutates the frontMatter object synchronously.
* @public
*/
processFrontMatter(file: TFile, fn: (frontMatter: any) => void): Promise<void>
}
```
To use it:
```ts
app.fileManager.processFrontMatter(file, (frontmatter) => {
frontmatter["key1"] = value;
delete frontmatter["key2"];
});
```
All changes made within the callback block will be applied at once.
### Improved
- `setTooltip` now accepts an optional tooltip position.
- The `size?: number` parameter has been removed from `setIcon`. This is now configurable via CSS. You can add override the CSS var `--icon-size` on the parent class of your element to override the sizing (e.g. `.parent-element { --icon-size: var(--icon-xs) } `) The following icon sizes are available out-of-the-box: `--icon-xs`, `--icon-s`, `--icon-m`, and `--icon-l`.
- `editorCallback` no longer passes the active `view: MarkdownView`. Instead, it now provides either the MarkdownView or a MarkdownFileInfo object. This change allows for editor commands to work within a Canvas.
- `registerHoverLinkSource` is now available in the API to register your plugin's view with the Page preview core plugin.
### No longer broken
- Fixed `Editor.replaceSelection` not working when run immediately after closing a modal.
### Notable Changes
- Added support for an optional `fundingUrl` field the plugin manifest This is a link for users that want to donate to show appreciation and support plugin development. It's displayed when your plugin is selected in the list of community plugins.
- Added macOS calendar entitlements. This allow scripts run from within Obsidian to request calendar access.
## v1.0 (2022-10-13)
_[Changes since v0.15.9](https://github.com/obsidianmd/obsidian-api/compare/ff121cd...1b4f6e2)_
### New
- Added standard [color picker component](https://github.com/obsidianmd/obsidian-api/blob/902badd38ba907689f0917d7b193f7e33d1284fe/obsidian.d.ts#L493).
### Improved
- `getLeaf` can now be used to create a leaf in a new tab, a new tab group, or a new window. The preferred usage of `getLeaf` would be `getLeaf(Keymap.isModEvent(evt))` where `evt` is the user's KeyboardEvent. This allows for a consistent user experience when opening files while a modifier key is pressed.
### Notable Changes
- Workspace information is no longer saved to the `.obsidian/workspace` file. It is now saved to `workspace.json`.
- Added `.has-active-menu` class to file explorer item that received the right-click.
- Added `.list-bullet` class to HTML markup for unordered list items.

7
node_modules/obsidian/LICENSE.md generated vendored Normal file
View File

@@ -0,0 +1,7 @@
Copyright 2022 Dynalist Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

69
node_modules/obsidian/README.md generated vendored Normal file
View File

@@ -0,0 +1,69 @@
## Obsidian API
Type definitions for the latest [Obsidian](https://obsidian.md) API.
### Documentation
You can browse our Plugin API documentation at https://docs.obsidian.md/
For an example on how to create Obsidian plugins, use the template at https://github.com/obsidianmd/obsidian-sample-plugin
### Issues and API requests
For issues with the API, or to make requests for new APIs, please go to our forum: https://forum.obsidian.md/c/developers-api/14
### Plugin structure
`manifest.json`
- `id` the ID of your plugin.
- `name` the display name of your plugin.
- `author` the plugin author's name.
- `version` the version of your plugin.
- `minAppVersion` the minimum required Obsidian version for your plugin.
- `description` the long description of your plugin.
- `isDesktopOnly` whether your plugin uses NodeJS or Electron APIs.
- `authorUrl` (optional) a URL to your own website.
- `fundingUrl` (optional) a link for users to donation to show appreciation and support plugin development.
`main.js`
- This is the main entry point of your plugin.
- Import any Obsidian API using `require('obsidian')`
- Import NodeJS or Electron API using `require('fs')` or `require('electron')`
- Must export a default class which extends `Plugin`
- Must bundle all external dependencies into this file, using Rollup, Webpack, or another javascript bundler.
### App Architecture
##### The app is organized into a few major modules:
- `App`, the global object that owns everything else. You can access this via `this.app` inside your plugin. The `App` interface provides accessors for the following interfaces.
- `Vault`, the interface that lets you interact with files and folders in the vault.
- `Workspace`, the interface that lets you interact with panes on the screen.
- `MetadataCache`, the interface that contains cached metadata about each markdown file, including headings, links, embeds, tags, and blocks.
##### Additionally, by inheriting `Plugin`, you can:
- Add a ribbon icon using `this.addRibbonIcon`.
- Add a status bar (bottom) element using `this.addStatusBarItem`.
- Add a global command, optionally with a default hotkey, using `this.addCommand`.
- Add a plugin settings tab using `this.addSettingTab`.
- Register a new kind of view using `this.registerView`.
- Save and load plugin data using `this.loadData` and `this.saveData`.
##### Registering events
For registering events from any event interfaces, such as `App` and `Workspace`, please use `this.registerEvent`, which will automatically detach your event handler when your plugin unloads:
```
this.registerEvent(app.on('event-name', callback));
```
If you register DOM events for elements that persist on the page after your plugin unloads, such as `window` or `document` events, please use `this.registerDomEvent`:
```
this.registerDomEvent(element, 'click', callback);
```
If you use `setInterval`, please use `this.registerInterval`:
```
this.registerInterval(setInterval(callback, 1000));
```

97
node_modules/obsidian/canvas.d.ts generated vendored Normal file
View File

@@ -0,0 +1,97 @@
/**
* A color used to encode color data for nodes and edges
* can be a number (like '1') representing one of the (currently 6) supported colors.
* or can be a custom color using the hex format '#FFFFFFF'.
*/
export type CanvasColor = string;
/** The overall canvas file's JSON */
export interface CanvasData {
nodes: AllCanvasNodeData[];
edges: CanvasEdgeData[];
/** Support arbitrary keys for forward compatibility */
[key: string]: any;
}
/** A node */
export interface CanvasNodeData {
/** The unique ID for this node */
id: string;
// The positional data
x: number;
y: number;
width: number;
height: number;
/** The color of this node */
color?: CanvasColor;
// Support arbitrary keys for forward compatibility
[key: string]: any;
}
export type AllCanvasNodeData = CanvasFileData | CanvasTextData | CanvasLinkData | CanvasGroupData;
/** A node that is a file, where the file is located somewhere in the vault. */
export interface CanvasFileData extends CanvasNodeData {
type: 'file';
file: string;
/** An optional subpath which links to a heading or a block. Always starts with a `#`. */
subpath?: string;
}
/** A node that is plaintext. */
export interface CanvasTextData extends CanvasNodeData {
type: 'text';
text: string;
}
/** A node that is an external resource. */
export interface CanvasLinkData extends CanvasNodeData {
type: 'link';
url: string;
}
/** The background image rendering style */
export type BackgroundStyle = 'cover' | 'ratio' | 'repeat';
/** A node that represents a group. */
export interface CanvasGroupData extends CanvasNodeData {
type: 'group';
/** Optional label to display on top of the group. */
label?: string;
/** Optional background image, stores the path to the image file in the vault. */
background?: string;
/** Optional background image rendering style; defaults to 'cover'. */
backgroundStyle?: BackgroundStyle;
}
/** The side of the node that a connection is connected to */
export type NodeSide = 'top' | 'right' | 'bottom' | 'left';
/** What to display at the end of an edge */
export type EdgeEnd = 'none' | 'arrow';
/** An edge */
export interface CanvasEdgeData {
/** The unique ID for this edge */
id: string;
/** The node ID and side where this edge starts */
fromNode: string;
fromSide?: NodeSide;
/** The starting edge end; defaults to 'none' */
fromEnd?: EdgeEnd;
/** The node ID and side where this edge ends */
toNode: string;
toSide?: NodeSide;
/** The ending edge end; defaults to 'arrow' */
toEnd?: EdgeEnd;
/** The color of this edge */
color?: CanvasColor;
/** The text label of this edge, if available */
label?: string;
// Support arbitrary keys for forward compatibility
[key: string]: any;
}

5320
node_modules/obsidian/obsidian.d.ts generated vendored Normal file

File diff suppressed because it is too large Load Diff

24
node_modules/obsidian/package.json generated vendored Normal file
View File

@@ -0,0 +1,24 @@
{
"name": "obsidian",
"version": "1.8.7",
"description": "Type definitions for the latest Obsidian API (https://obsidian.md)",
"keywords": [
"obsdmd"
],
"homepage": "https://obsidian.md",
"repository": {
"type": "git",
"url": "git+https://github.com/obsidianmd/obsidian-api.git"
},
"license": "MIT",
"main": "",
"types": "obsidian.d.ts",
"dependencies": {
"@types/codemirror": "5.60.8",
"moment": "2.29.4"
},
"peerDependencies": {
"@codemirror/state": "^6.0.0",
"@codemirror/view": "^6.0.0"
}
}

513
node_modules/obsidian/publish.d.ts generated vendored Normal file
View File

@@ -0,0 +1,513 @@
declare global {
interface ObjectConstructor {
isEmpty(object: Record<string, any>): boolean;
each<T>(object: {
[key: string]: T;
}, callback: (value: T, key?: string) => boolean | void, context?: any): boolean;
}
interface ArrayConstructor {
combine<T>(arrays: T[][]): T[];
}
interface Array<T> {
first(): T | undefined;
last(): T | undefined;
contains(target: T): boolean;
remove(target: T): void;
shuffle(): this;
unique(): T[];
}
interface Math {
clamp(value: number, min: number, max: number): number;
square(value: number): number;
}
interface StringConstructor {
isString(obj: any): obj is string;
}
interface String {
contains(target: string): boolean;
startsWith(searchString: string, position?: number): boolean;
endsWith(target: string, length?: number): boolean;
format(...args: string[]): string;
}
interface NumberConstructor {
isNumber(obj: any): obj is number;
}
interface Node {
detach(): void;
empty(): void;
insertAfter<T extends Node>(node: T, child: Node | null): T;
indexOf(other: Node): number;
setChildrenInPlace(children: Node[]): void;
appendText(val: string): void;
/**
* Cross-window capable instanceof check, a drop-in replacement
* for instanceof checks on DOM Nodes. Remember to also check
* for nulls when necessary.
* @param type
*/
instanceOf<T>(type: {
new (): T;
}): this is T;
/**
* The document this node belongs to, or the global document.
*/
doc: Document;
/**
* The window object this node belongs to, or the global window.
*/
win: Window;
constructorWin: Window;
}
interface Element extends Node {
getText(): string;
setText(val: string | DocumentFragment): void;
addClass(...classes: string[]): void;
addClasses(classes: string[]): void;
removeClass(...classes: string[]): void;
removeClasses(classes: string[]): void;
toggleClass(classes: string | string[], value: boolean): void;
hasClass(cls: string): boolean;
setAttr(qualifiedName: string, value: string | number | boolean | null): void;
setAttrs(obj: {
[key: string]: string | number | boolean | null;
}): void;
getAttr(qualifiedName: string): string | null;
matchParent(selector: string, lastParent?: Element): Element | null;
getCssPropertyValue(property: string, pseudoElement?: string): string;
isActiveElement(): boolean;
}
interface HTMLElement extends Element {
show(): void;
hide(): void;
toggle(show: boolean): void;
toggleVisibility(visible: boolean): void;
/**
* Returns whether this element is shown, when the element is attached to the DOM and
* none of the parent and ancestor elements are hidden with `display: none`.
*
* Exception: Does not work on <body> and <html>, or on elements with `position: fixed`.
*/
isShown(): boolean;
setCssStyles(styles: Partial<CSSStyleDeclaration>): void;
setCssProps(props: Record<string, string>): void;
/**
* Get the inner width of this element without padding.
*/
readonly innerWidth: number;
/**
* Get the inner height of this element without padding.
*/
readonly innerHeight: number;
}
interface SVGElement extends Element {
setCssStyles(styles: Partial<CSSStyleDeclaration>): void;
setCssProps(props: Record<string, string>): void;
}
function isBoolean(obj: any): obj is boolean;
function fish(selector: string): HTMLElement | null;
function fishAll(selector: string): HTMLElement[];
interface Element extends Node {
find(selector: string): Element | null;
findAll(selector: string): HTMLElement[];
findAllSelf(selector: string): HTMLElement[];
}
interface HTMLElement extends Element {
find(selector: string): HTMLElement;
findAll(selector: string): HTMLElement[];
findAllSelf(selector: string): HTMLElement[];
}
interface DocumentFragment extends Node, NonElementParentNode, ParentNode {
find(selector: string): HTMLElement;
findAll(selector: string): HTMLElement[];
}
interface DomElementInfo {
/**
* The class to be assigned. Can be a space-separated string or an array of strings.
*/
cls?: string | string[];
/**
* The textContent to be assigned.
*/
text?: string | DocumentFragment;
/**
* HTML attributes to be added.
*/
attr?: {
[key: string]: string | number | boolean | null;
};
/**
* HTML title (for hover tooltip).
*/
title?: string;
/**
* The parent element to be assigned to.
*/
parent?: Node;
value?: string;
type?: string;
prepend?: boolean;
placeholder?: string;
href?: string;
}
interface SvgElementInfo {
/**
* The class to be assigned. Can be a space-separated string or an array of strings.
*/
cls?: string | string[];
/**
* HTML attributes to be added.
*/
attr?: {
[key: string]: string | number | boolean | null;
};
/**
* The parent element to be assigned to.
*/
parent?: Node;
prepend?: boolean;
}
interface Node {
/**
* Create an element and append it to this node.
*/
createEl<K extends keyof HTMLElementTagNameMap>(tag: K, o?: DomElementInfo | string, callback?: (el: HTMLElementTagNameMap[K]) => void): HTMLElementTagNameMap[K];
createDiv(o?: DomElementInfo | string, callback?: (el: HTMLDivElement) => void): HTMLDivElement;
createSpan(o?: DomElementInfo | string, callback?: (el: HTMLSpanElement) => void): HTMLSpanElement;
createSvg<K extends keyof SVGElementTagNameMap>(tag: K, o?: SvgElementInfo | string, callback?: (el: SVGElementTagNameMap[K]) => void): SVGElementTagNameMap[K];
}
function createEl<K extends keyof HTMLElementTagNameMap>(tag: K, o?: DomElementInfo | string, callback?: (el: HTMLElementTagNameMap[K]) => void): HTMLElementTagNameMap[K];
function createDiv(o?: DomElementInfo | string, callback?: (el: HTMLDivElement) => void): HTMLDivElement;
function createSpan(o?: DomElementInfo | string, callback?: (el: HTMLSpanElement) => void): HTMLSpanElement;
function createSvg<K extends keyof SVGElementTagNameMap>(tag: K, o?: SvgElementInfo | string, callback?: (el: SVGElementTagNameMap[K]) => void): SVGElementTagNameMap[K];
function createFragment(callback?: (el: DocumentFragment) => void): DocumentFragment;
interface EventListenerInfo {
selector: string;
listener: Function;
options?: boolean | AddEventListenerOptions;
callback: Function;
}
interface HTMLElement extends Element {
_EVENTS?: {
[K in keyof HTMLElementEventMap]?: EventListenerInfo[];
};
on<K extends keyof HTMLElementEventMap>(this: HTMLElement, type: K, selector: string, listener: (this: HTMLElement, ev: HTMLElementEventMap[K], delegateTarget: HTMLElement) => any, options?: boolean | AddEventListenerOptions): void;
off<K extends keyof HTMLElementEventMap>(this: HTMLElement, type: K, selector: string, listener: (this: HTMLElement, ev: HTMLElementEventMap[K], delegateTarget: HTMLElement) => any, options?: boolean | AddEventListenerOptions): void;
onClickEvent(this: HTMLElement, listener: (this: HTMLElement, ev: MouseEvent) => any, options?: boolean | AddEventListenerOptions): void;
/**
* @param listener - the callback to call when this node is inserted into the DOM.
* @param once - if true, this will only fire once and then unhook itself.
* @returns destroy - a function to remove the event handler to avoid memory leaks.
*/
onNodeInserted(this: HTMLElement, listener: () => any, once?: boolean): () => void;
/**
* @param listener - the callback to call when this node has been migrated to another window.
* @returns destroy - a function to remove the event handler to avoid memory leaks.
*/
onWindowMigrated(this: HTMLElement, listener: (win: Window) => any): () => void;
trigger(eventType: string): void;
}
interface Document {
_EVENTS?: {
[K in keyof DocumentEventMap]?: EventListenerInfo[];
};
on<K extends keyof DocumentEventMap>(this: Document, type: K, selector: string, listener: (this: Document, ev: DocumentEventMap[K], delegateTarget: HTMLElement) => any, options?: boolean | AddEventListenerOptions): void;
off<K extends keyof DocumentEventMap>(this: Document, type: K, selector: string, listener: (this: Document, ev: DocumentEventMap[K], delegateTarget: HTMLElement) => any, options?: boolean | AddEventListenerOptions): void;
}
interface UIEvent extends Event {
targetNode: Node | null;
win: Window;
doc: Document;
/**
* Cross-window capable instanceof check, a drop-in replacement
* for instanceof checks on UIEvents.
* @param type
*/
instanceOf<T>(type: {
new (...data: any[]): T;
}): this is T;
}
interface AjaxOptions {
method?: 'GET' | 'POST';
url: string;
success?: (response: any, req: XMLHttpRequest) => any;
error?: (error: any, req: XMLHttpRequest) => any;
data?: object | string | ArrayBuffer;
headers?: Record<string, string>;
withCredentials?: boolean;
req?: XMLHttpRequest;
}
function ajax(options: AjaxOptions): void;
function ajaxPromise(options: AjaxOptions): Promise<any>;
function ready(fn: () => any): void;
function sleep(ms: number): Promise<void>;
function nextFrame(): Promise<void>;
/**
* The actively focused Window object. This is usually the same as `window` but
* it will be different when using popout windows.
*/
let activeWindow: Window;
/**
* The actively focused Document object. This is usually the same as `document` but
* it will be different when using popout windows.
*/
let activeDocument: Document;
interface Window extends EventTarget, AnimationFrameProvider, GlobalEventHandlers, WindowEventHandlers, WindowLocalStorage, WindowOrWorkerGlobalScope, WindowSessionStorage {
/**
* The actively focused Window object. This is usually the same as `window` but
* it will be different when using popout windows.
*/
activeWindow: Window;
/**
* The actively focused Document object. This is usually the same as `document` but
* it will be different when using popout windows.
*/
activeDocument: Document;
sleep(ms: number): Promise<void>;
nextFrame(): Promise<void>;
}
interface Touch {
touchType: 'stylus' | 'direct';
}
}
/**
* @public
*/
export class Component {
/**
* Load this component and its children
* @public
*/
load(): void;
/**
* Override this to load your component
* @public
* @virtual
*/
onload(): void;
/**
* Unload this component and its children
* @public
*/
unload(): void;
/**
* Override this to unload your component
* @public
* @virtual
*/
onunload(): void;
/**
* Adds a child component, loading it if this component is loaded
* @public
*/
addChild<T extends Component>(component: T): T;
/**
* Removes a child component, unloading it
* @public
*/
removeChild<T extends Component>(component: T): T;
/**
* Registers a callback to be called when unloading
* @public
*/
register(cb: () => any): void;
/**
* Registers an event to be detached when unloading
* @public
*/
registerEvent(eventRef: EventRef): void;
/**
* Registers an DOM event to be detached when unloading
* @public
*/
registerDomEvent<K extends keyof WindowEventMap>(el: Window, type: K, callback: (this: HTMLElement, ev: WindowEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
/**
* Registers an DOM event to be detached when unloading
* @public
*/
registerDomEvent<K extends keyof DocumentEventMap>(el: Document, type: K, callback: (this: HTMLElement, ev: DocumentEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
/**
* Registers an DOM event to be detached when unloading
* @public
*/
registerDomEvent<K extends keyof HTMLElementEventMap>(el: HTMLElement, type: K, callback: (this: HTMLElement, ev: HTMLElementEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
/**
* Registers an interval (from setInterval) to be cancelled when unloading
* Use {@link window#setInterval} instead of {@link setInterval} to avoid TypeScript confusing between NodeJS vs Browser API
* @public
*/
registerInterval(id: number): number;
}
/**
* @public
*/
export interface EventRef {
}
/**
* @public
*/
export class Events {
/**
* @public
*/
on(name: string, callback: (...data: unknown[]) => unknown, ctx?: any): EventRef;
/**
* @public
*/
off(name: string, callback: (...data: unknown[]) => unknown): void;
/**
* @public
*/
offref(ref: EventRef): void;
/**
* @public
*/
trigger(name: string, ...data: unknown[]): void;
/**
* @public
*/
tryTrigger(evt: EventRef, args: unknown[]): void;
}
/**
* A post processor receives an element which is a section of the preview.
*
* Post processors can mutate the DOM to render various things, such as mermaid graphs, latex equations, or custom controls.
*
* If your post processor requires lifecycle management, for example, to clear an interval, kill a subprocess, etc when this element is
* removed from the app, look into {@link MarkdownPostProcessorContext#addChild}
* @public
*/
export interface MarkdownPostProcessor {
/**
* The processor function itself.
* @public
*/
(el: HTMLElement, ctx: MarkdownPostProcessorContext): Promise<any> | void;
/**
* An optional integer sort order. Defaults to 0. Lower number runs before higher numbers.
* @public
*/
sortOrder?: number;
}
/**
* @public
*/
export interface MarkdownPostProcessorContext {
/**
* @public
*/
docId: string;
/**
* The path to the associated file. Any links are assumed to be relative to the `sourcePath`.
* @public
*/
sourcePath: string;
/** @public */
frontmatter: any | null | undefined;
/**
* Adds a child component that will have its lifecycle managed by the renderer.
*
* Use this to add a dependent child to the renderer such that if the containerEl
* of the child is ever removed, the component's unload will be called.
* @public
*/
addChild(child: MarkdownRenderChild): void;
/**
* Gets the section information of this element at this point in time.
* Only call this function right before you need this information to get the most up-to-date version.
* This function may also return null in many circumstances; if you use it, you must be prepared to deal with nulls.
* @public
*/
getSectionInfo(el: HTMLElement): MarkdownSectionInformation | null;
}
/**
* @public
*/
export class MarkdownPreviewRenderer {
/**
* @public
*/
static registerPostProcessor(postProcessor: MarkdownPostProcessor, sortOrder?: number): void;
/**
* @public
*/
static unregisterPostProcessor(postProcessor: MarkdownPostProcessor): void;
/**
* @public
*/
static createCodeBlockPostProcessor(language: string, handler: (source: string, el: HTMLElement, ctx: MarkdownPostProcessorContext) => Promise<any> | void): (el: HTMLElement, ctx: MarkdownPostProcessorContext) => void;
}
/**
* @public
*/
export class MarkdownRenderChild extends Component {
/** @public */
containerEl: HTMLElement;
/**
* @param containerEl - This HTMLElement will be used to test whether this component is still alive.
* It should be a child of the Markdown preview sections, and when it's no longer attached
* (for example, when it is replaced with a new version because the user edited the Markdown source code),
* this component will be unloaded.
* @public
*/
constructor(containerEl: HTMLElement);
}
/** @public */
export interface MarkdownSectionInformation {
/** @public */
text: string;
/** @public */
lineStart: number;
/** @public */
lineEnd: number;
}
/** @public */
export class Publish extends Events {
/** @public */
get currentFilepath(): string;
/**
* @public
*/
registerMarkdownPostProcessor(postProcessor: MarkdownPostProcessor, sortOrder?: number): MarkdownPostProcessor;
/**
* Register a special post processor that handles fenced code given a language and a handler.
* This special post processor takes care of removing the `<pre><code>` and create a `<div>` that
* will be passed to your handler, and is expected to be filled with your custom elements.
* @public
*/
registerMarkdownCodeBlockProcessor(language: string, handler: (source: string, el: HTMLElement, ctx: MarkdownPostProcessorContext) => Promise<any> | void, sortOrder?: number): MarkdownPostProcessor;
/** @public */
on(name: 'navigated', callback: () => any, ctx?: any): EventRef;
}
export { }
/** @public */
declare global {
/**
* Global reference to the publish instance.
* @public
*/
var publish: Publish;
}