obsidian-typings
Version:
Extended type definitions for the Obsidian API (https://obsidian.md)
1,675 lines (1,672 loc) • 736 kB
text/typescript
// Generated by dts-bundle-generator v9.5.1
import type { Capacitor, CapacitorPlatforms } from '@capacitor/core';
import type { ParseContext } from '@codemirror/language';
import type { SearchQuery } from '@codemirror/search';
import type { ChangeDesc, Extension, Facet, StateEffectType, StateField, Transaction } from '@codemirror/state';
import type { EditorView, ViewPlugin, ViewUpdate } from '@codemirror/view';
import type { NodeProp, Tree } from '@lezer/common';
import type { default as CodeMirror$1 } from 'codemirror';
import type { default as DOMPurify$1 } from 'dompurify';
import * as electron from 'electron';
import type { App as App$1, BrowserWindow, IpcRenderer } from 'electron';
import type { default as i18next } from 'i18next';
import type { Mermaid } from 'mermaid';
import type { default as moment$1 } from 'moment';
import * as fs from 'node:fs';
import type { FSWatcher, Stats } from 'node:fs';
import * as fsPromises from 'node:fs/promises';
import * as path from 'node:path';
import type { App, BlockCache, CacheItem, CachedMetadata, CloseableComponent, ColorComponent, Command, Component, Constructor, DataAdapter, Debouncer, EditableFileView, Editor, EditorPosition, EditorRange, EditorRangeOrCaret, EditorSuggest, EmbedCache, EventRef, Events, FileManager, FileStats, FileView, FrontmatterLinkCache, FuzzySuggestModal, HoverLinkSource, HoverPopover, IconName, ItemView, Keymap, KeymapInfo, LinkCache, MarkdownEditView, MarkdownFileInfo, MarkdownPostProcessorContext, MarkdownPreviewView, MarkdownView, Menu, Modal, Notice, ObsidianProtocolHandler, PaneType, Platform, Plugin as Plugin, PluginManifest, PluginSettingTab, Reference, ReferenceCache, Scope, SearchComponent, SearchResult, Setting, SettingTab, SplitDirection, TAbstractFile, TFile, TFolder, TextComponent, TextFileView, Vault, View, ViewCreator, ViewState, Workspace, WorkspaceLeaf, WorkspaceTabs, request, requestUrl } from 'obsidian';
import type { default as pdfjsLib } from 'pdfjs-dist';
import type { Application, Container, Graphics, ICanvas, Sprite, Text as Text$1, TextStyle, default as PIXI } from 'pixi.js';
import type { default as Prism$1 } from 'prismjs';
import type { default as scrypt$1 } from 'scrypt-js';
import type { default as TurndownService } from 'turndown';
declare global {
/**
* Augments the built-in {@link ArrayConstructor} interface.
*/
interface ArrayConstructor {
/**
* Combines an array of arrays into a single array.
*
* @typeParam T - The type of the elements in the arrays.
* @param arrays - The array of arrays to combine.
* @returns A single array containing all elements from the input arrays.
* @example
* ```ts
* console.log(Array.combine([[1, 2], [3, 4], [5, 6]])); // [1, 2, 3, 4, 5, 6]
* ```
* @official
*/
combine<T>(arrays: T[][]): T[];
}
}
declare global {
/**
* Augments the built-in {@link Array} interface.
*
* @typeParam T - The type of the elements in the array.
*/
interface Array<T> {
/**
* Checks if the array contains a specific element.
*
* @param target - The element to check for.
* @returns `true` if the element is found, `false` otherwise.
* @example
* ```ts
* console.log([1, 2, 3].contains(2)); // true
* console.log([1, 2, 3].contains(4)); // false
* ```
* @official
*/
contains(target: T): boolean;
/**
* Returns the index of the last element that satisfies the provided predicate.
*
* @param predicate - The predicate to test each element.
* @returns The index of the last element that satisfies the predicate, or `-1` if no such element is found.
* @example
* ```ts
* console.log([1, 2, 3, 2, 1].findLastIndex(x => x === 2)); // 3
* console.log([1, 2, 3, 2, 1].findLastIndex(x => x === 4)); // -1
* ```
* @official
*/
findLastIndex(predicate: (value: T) => boolean): number;
/**
* Returns the first element of the array.
*
* @returns The first element of the array, or `undefined` if the array is empty.
* @example
* ```ts
* console.log([1, 2, 3].first()); // 1
* console.log([].first()); // undefined
* ```
* @official
*/
first(): T | undefined;
/**
* Returns the last element of the array.
*
* @returns The last element of the array, or `undefined` if the array is empty.
* @example
* ```ts
* console.log([1, 2, 3].last()); // 3
* console.log([].last()); // undefined
* ```
* @official
*/
last(): T | undefined;
/**
* Removes an element from the array, if it exists, otherwise returns the array unchanged.
*
* @param target - The element to remove.
* @example
* ```ts
* let arr = [1, 2, 3];
* arr.remove(2);
* console.log(arr); // [1, 3]
* arr = [1, 2, 3];
* arr.remove(4);
* console.log(arr); // [1, 2, 3]
* ```
* @remarks The original version had return type `this`.
* See bug: {@link https://forum.obsidian.md/t/bug-array-remove-definition/98101}.
* @official
*/
remove(target: T): void;
/**
* Shuffles the array in place.
*
* @returns The array itself.
* @example
* ```ts
* const arr = [1, 2, 3];
* console.log(arr.shuffle()); // something like [2, 3, 1]
* console.log(arr); // same as above
* ```
* @official
*/
shuffle(): this;
/**
* Returns a new array with unique elements.
*
* @returns A new array with unique elements.
* @example
* ```ts
* console.log([1, 2, 3, 2, 1].unique()); // [1, 2, 3]
* ```
* @official
*/
unique(): T[];
}
}
declare global {
/**
* Augments the built-in {@link DocumentFragment} interface.
*/
interface DocumentFragment extends Node, NonElementParentNode, ParentNode {
/**
* Finds the first descendant element that matches the selector.
*
* @param selector - The selector to find the element with.
* @returns The first descendant element that matches the selector, or `null` if no match is found.
* @example
* ```ts
* const fragment = createFragment();
* fragment.createEl('strong', { cls: 'foo' });
* console.log(fragment.find('.foo')); // <strong class="foo"></strong>
* console.log(fragment.find('.bar')); // null
* ```
* @remarks See bug {@link https://forum.obsidian.md/t/bug-find-findall-findallself/98108}.
* @official
*/
find(selector: string): Element | null;
/**
* Finds all descendant elements that match the selector.
*
* @param selector - The selector to find the elements with.
* @returns An array of all descendant elements that match the selector.
* @example
* ```ts
* const fragment = createFragment();
* fragment.createEl('strong', { cls: 'foo' });
* fragment.createEl('strong', { cls: 'foo' });
* console.log(fragment.findAll('.foo')); // [<strong class="foo"></strong>, <strong class="foo"></strong>]
* console.log(fragment.findAll('.bar')); // []
* ```
* @remarks See bug {@link https://forum.obsidian.md/t/bug-find-findall-findallself/98108}.
* @official
*/
findAll(selector: string): Element[];
}
}
declare global {
/**
* Augments the built-in {@link Document} interface.
*/
interface Document {
/**
* The event listeners of the document.
* @official
*/
_EVENTS?: {
[K in keyof DocumentEventMap]?: EventListenerInfo[];
};
/**
* Removes an event listener from the document.
*
* @typeParam K - The type of the event to listen for.
* @param this - The document to remove the event listener from.
* @param type - The type of event to listen for.
* @param selector - The selector of the event target.
* @param listener - The listener to call when the event is triggered.
* @param options - The options of the event listener.
* @example
* ```ts
* document.off('click', 'div', document.body._EVENTS.click[0].listener);
* ```
* @official
*/
off<K extends keyof DocumentEventMap>(this: Document, type: K, selector: string, listener: (this: Document, ev: DocumentEventMap[K], delegateTarget: HTMLElement) => any, options?: boolean | AddEventListenerOptions): void;
/**
* Adds an event listener to the document.
*
* @typeParam K - The type of the event to listen for.
* @param this - The document to add the event listener to.
* @param type - The type of event to listen for.
* @param selector - The selector of the event target.
* @param listener - The listener to call when the event is triggered.
* @param options - The options of the event listener.
* @example
* ```ts
* document.on('click', 'div', (ev) => {
* console.log(ev);
* });
* ```
* @official
*/
on<K extends keyof DocumentEventMap>(this: Document, type: K, selector: string, listener: (this: Document, ev: DocumentEventMap[K], delegateTarget: HTMLElement) => any, options?: boolean | AddEventListenerOptions): void;
}
}
declare global {
/**
* Augments the built-in {@link Element} interface.
*/
interface Element extends Node {
/**
* Adds a class to the element.
*
* @param classes - The class to add.
* @example
* ```ts
* const element = createEl('p');
* element.addClass('foo', 'bar');
* console.log(element.className); // foo
* @official
*/
addClass(...classes: string[]): void;
/**
* Adds multiple classes to the element.
*
* @param classes - The classes to add.
* @example
* ```ts
* const element = createEl('p');
* element.addClasses(['foo', 'bar']);
* console.log(element.className); // foo bar
* ```
* @official
*/
addClasses(classes: string[]): void;
/**
* Finds the first descendant element that matches the selector.
*
* @param selector - The selector to find the element with.
* @returns The first descendant element that matches the selector, or `null` if no match is found.
* @example
* ```ts
* const element = createEl('p');
* element.createEl('strong', { cls: 'foo' });
* console.log(element.find('.foo')); // <strong class="foo"></strong>
* console.log(element.find('.bar')); // null
* ```
* @official
*/
find(selector: string): Element | null;
/**
* Finds all descendant elements that match the selector.
*
* @param selector - The selector to find the elements with.
* @returns An array of all descendant elements that match the selector.
* @example
* ```ts
* const element = createEl('p');
* element.createEl('strong', { cls: 'foo' });
* element.createEl('strong', { cls: 'foo' });
* console.log(element.findAll('.foo')); // [<strong class="foo"></strong>, <strong class="foo"></strong>]
* console.log(element.findAll('.bar')); // []
* ```
* @remarks See bug {@link https://forum.obsidian.md/t/bug-find-findall-findallself/98108}.
* @official
*/
findAll(selector: string): Element[];
/**
* Finds all descendant elements or self that match the selector.
*
* @param selector - The selector to find the elements with.
* @returns An array of all descendant elements or self that match the selector.
* @example
* ```ts
* const element = createEl('p', { cls: 'foo' });
* element.createEl('strong', { cls: 'foo' });
* console.log(element.findAllSelf('.foo')); // [<p class="foo"></p>, <strong class="foo"></strong>]
* console.log(element.findAllSelf('.bar')); // []
* ```
* @remarks See bug {@link https://forum.obsidian.md/t/bug-find-findall-findallself/98108}.
* @official
*/
findAllSelf(selector: string): Element[];
/**
* Gets an attribute from the element.
*
* @param qualifiedName - The name of the attribute to get.
* @returns The value of the attribute.
* @example
* ```ts
* const element = createEl('p');
* element.setAttr('data-foo', 'bar');
* console.log(element.getAttr('data-foo')); // bar
* ```
* @official
*/
getAttr(qualifiedName: string): string | null;
/**
* Gets the value of a CSS property of the element.
*
* @param property - The property to get the value of.
* @param pseudoElement - The pseudo-element to get the value of.
* @returns The value of the CSS property.
* @example
* ```ts
* const element = document.body.createEl('p');
* element.style.color = 'red';
* console.log(element.getCssPropertyValue('color')); // rgb(255, 0, 0)
* console.log(element.getCssPropertyValue('color', ':after')); // rgb(255, 0, 0)
* ```
* @official
*/
getCssPropertyValue(property: string, pseudoElement?: string): string;
/**
* Returns the text content of the element.
*
* @returns The text content of the element.
* @example
* ```ts
* const element = createEl('p');
* element.createEl('strong', { text: 'foo' });
* element.createEl('strong', { text: 'bar' });
* console.log(element.getText()); // foobar
* ```
* @official
*/
getText(): string;
/**
* Checks if the element has a class.
*
* @param cls - The class to check for.
* @returns `true` if the element has the class, `false` otherwise.
* @example
* ```ts
* const element = createEl('p');
* element.addClass('foo', 'bar');
* console.log(element.hasClass('foo')); // true
* console.log(element.hasClass('baz')); // false
* ```
* @official
*/
hasClass(cls: string): boolean;
/**
* Checks if the element is the active element.
*
* @returns `true` if the element is the active element, `false` otherwise.
* @example
* ```ts
* const element = document.body.createEl('p');
* console.log(element.isActiveElement()); // false
* console.log(document.activeElement.isActiveElement()); // true
* ```
* @official
*/
isActiveElement(): boolean;
/**
* Matches the selector recursively up the DOM tree.
*
* @param selector - The selector to match the parent with.
* @param lastParent - The last parent to stop matching against.
* @returns The matched element or `null` if no match is found.
* @example
* ```ts
* const element = createEl('p');
* console.log(element.matchParent('p')); // <p></p>
* console.log(element.matchParent('strong')); // null
* const child = element.createEl('strong');
* console.log(child.matchParent('strong')); // <strong></strong>
* console.log(child.matchParent('p')); // <p></p>
* const grandchild = child.createEl('em');
* console.log(grandchild.matchParent('p', child)); // null
* ```
* @official
*/
matchParent(selector: string, lastParent?: Element): Element | null;
/**
* Removes a class from the element.
*
* @param classes - The class to remove.
* @example
* ```ts
* const element = createEl('p');
* element.addClass('foo bar');
* element.removeClass('foo', 'baz');
* console.log(element.className); // bar
* ```
* @official
*/
removeClass(...classes: string[]): void;
/**
* Removes multiple classes from the element.
*
* @param classes - The classes to remove.
* @example
* ```ts
* const element = createEl('p');
* element.addClass('foo bar');
* element.removeClasses(['foo', 'baz']);
* console.log(element.className); // bar
* ```
* @official
*/
removeClasses(classes: string[]): void;
/**
* Sets an attribute on the element.
*
* @param qualifiedName - The name of the attribute to set.
* @param value - The value to set the attribute to.
* @example
* ```ts
* const element = createEl('p');
* element.setAttr('data-foo', 'bar');
* console.log(element.getAttr('data-foo')); // bar
* ```
* @official
*/
setAttr(qualifiedName: string, value: string | number | boolean | null): void;
/**
* Sets multiple attributes on the element.
*
* @param obj - The attributes to set.
* @example
* ```ts
* const element = createEl('p');
* element.setAttrs({
* 'data-foo': 'bar',
* 'data-baz': 'qux',
* });
* console.log(element.getAttr('data-foo')); // bar
* console.log(element.getAttr('data-baz')); // qux
* ```
* @official
*/
setAttrs(obj: {
[key: string]: string | number | boolean | null;
}): void;
/**
* Sets the text content of the element.
*
* @param val - The text content to set.
* @example
* ```ts
* const element = createEl('p');
* element.setText('foo');
* console.log(element); // <p>foo</p>
* const fragment = createFragment();
* fragment.createEl('strong', { text: 'bar' });
* element.setText(fragment);
* console.log(element); // <p><strong>bar</strong></p>
* ```
* @official
*/
setText(val: string | DocumentFragment): void;
/**
* Toggles a class on the element.
*
* @param classes - The class to toggle.
* @param value - If `true`, the class will be added, if `false`, the class will be removed.
* @example
* ```ts
* const element = createEl('p');
* element.addClass('foo', 'bar');
* element.toggleClass('foo', false);
* console.log(element.className); // bar
* element.toggleClass('foo', true);
* console.log(element.className); // bar foo
* element.toggleClass('baz', false);
* console.log(element.className); // bar foo
* element.toggleClass('baz', true);
* console.log(element.className); // bar foo baz
* ```
* @official
*/
toggleClass(classes: string | string[], value: boolean): void;
}
}
declare global {
/**
* Augments the built-in {@link HTMLElement} interface.
*/
interface HTMLElement extends Element {
/**
* The event listeners of the element.
* @official
*/
_EVENTS?: {
[K in keyof HTMLElementEventMap]?: EventListenerInfo[];
};
/**
* Get the inner height of this element without padding.
* @official
*/
readonly innerHeight: number;
/**
* Get the inner width of this element without padding.
* @official
*/
readonly innerWidth: number;
/**
* Hides the element using css `display` property.
*
* @example
* ```ts
* document.body.hide();
* ```
* @official
*/
hide(): 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`.
*
* @example
* ```ts
* const element = document.body.createEl('p');
* console.log(element.isShown()); // true
* element.hide();
* console.log(element.isShown()); // false
* ```
* @official
*/
isShown(): boolean;
/**
* Removes an event listener from the element.
*
* @typeParam K - The type of the event to listen for.
* @param this - The element to remove the event listener from.
* @param type - The type of event to listen for.
* @param selector - The selector of the event target.
* @param listener - The listener to call when the event is triggered.
* @param options - The options of the event listener.
* @example
* ```ts
* document.body.off('click', 'div', document.body._EVENTS.click[0].listener);
* ```
* @official
*/
off<K extends keyof HTMLElementEventMap>(this: HTMLElement, type: K, selector: string, listener: (this: HTMLElement, ev: HTMLElementEventMap[K], delegateTarget: HTMLElement) => any, options?: boolean | AddEventListenerOptions): void;
/**
* Adds an event listener to the element.
*
* @typeParam K - The type of the event to listen for.
* @param this - The element to add the event listener to.
* @param type - The type of event to listen for.
* @param selector - The selector of the event target.
* @param listener - The listener to call when the event is triggered.
* @param options - The options of the event listener.
* @example
* ```ts
* document.body.on('click', 'div', (ev) => {
* console.log(ev);
* });
* ```
* @official
*/
on<K extends keyof HTMLElementEventMap>(this: HTMLElement, type: K, selector: string, listener: (this: HTMLElement, ev: HTMLElementEventMap[K], delegateTarget: HTMLElement) => any, options?: boolean | AddEventListenerOptions): void;
/**
* Adds a click event listener to the element.
*
* @param this - The element to add the event listener to.
* @param listener - The listener to call when the click event is triggered.
* @param options - The options of the click event listener.
* @example
* ```ts
* document.body.onClickEvent((ev) => {
* console.log(ev);
* });
* ```
* @official
*/
onClickEvent(this: HTMLElement, listener: (this: HTMLElement, ev: MouseEvent) => any, options?: boolean | AddEventListenerOptions): void;
/**
* Adds an event listener to the element when it is inserted into the DOM.
*
* @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.
* @example
* ```ts
* document.body.onNodeInserted(() => {
* console.log('node inserted');
* });
* ```
* @official
*/
onNodeInserted(this: HTMLElement, listener: () => any, once?: boolean): () => void;
/**
* Adds an event listener to the element when it is migrated to another window.
*
* @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.
* @example
* ```ts
* document.body.onWindowMigrated((win) => {
* console.log('window migrated');
* });
* @official
*/
onWindowMigrated(this: HTMLElement, listener: (win: Window) => any): () => void;
/**
* Sets the CSS properties of the element.
*
* @param props - The properties to set.
* @example
* ```ts
* const element = document.body.createEl('p');
* element.setCssProps({ color: 'red', 'font-size': '16px' });
* ```
* @official
*/
setCssProps(props: Record<string, string>): void;
/**
* Sets the CSS styles of the element.
*
* @param styles - The styles to set.
* @example
* ```ts
* const element = document.body.createEl('p');
* element.setCssStyles({ color: 'red', fontSize: '16px' });
* ```
* @official
*/
setCssStyles(styles: Partial<CSSStyleDeclaration>): void;
/**
* Shows the element using css `display` property.
*
* @example
* ```ts
* document.body.show();
* ```
* @official
*/
show(): void;
/**
* Toggles the visibility of the element using css `display` property.
*
* @param show - Whether to show the element.
* @example
* ```ts
* document.body.toggle(true);
* document.body.toggle(false);
* ```
* @official
*/
toggle(show: boolean): void;
/**
* Toggles the visibility of the element using css `visibility` property.
*
* @param visible - Whether to show the element.
* @example
* ```ts
* document.body.toggleVisibility(true);
* document.body.toggleVisibility(false);
* ```
* @official
*/
toggleVisibility(visible: boolean): void;
/**
* Triggers an event on the element.
*
* @param eventType - the type of event to trigger.
* @example
* ```ts
* document.body.trigger('click');
* ```
* @official
*/
trigger(eventType: string): void;
}
}
declare global {
/**
* Augments the built-in {@link Math} interface.
*/
interface Math {
/**
* Clamps a value between a minimum and maximum.
*
* @param value - The value to clamp.
* @param min - The minimum value.
* @param max - The maximum value.
* @returns The clamped value.
* @example
* ```ts
* console.log(Math.clamp(10, 0, 5)); // 5
* console.log(Math.clamp(-10, 0, 5)); // 0
* console.log(Math.clamp(3, 0, 5)); // 3
* ```
* @official
*/
clamp(value: number, min: number, max: number): number;
/**
* Returns the square of a number.
*
* @param value - The number to square.
* @returns The square of the number.
* @example
* ```ts
* console.log(Math.square(2)); // 4
* console.log(Math.square(-2)); // 4
* ```
* @official
*/
square(value: number): number;
}
}
declare global {
/**
* Augments the built-in {@link Node} interface.
*/
interface Node {
/**
* Global window object.
* @official
*/
constructorWin: Window;
/**
* The document this node belongs to, or the global document.
* @official
*/
doc: Document;
/**
* The window object this node belongs to, or the global window.
* @official
*/
win: Window;
/**
* Appends a text node to the node.
*
* @param val - The text to append.
* @example
* ```ts
* const parent = createEl('p');
* parent.createEl('strong', { text: 'foo' });
* parent.appendText('bar');
* console.log(parent); // <p><strong>foo</strong>bar</p>
* ```
* @official
*/
appendText(val: string): void;
/**
* Creates a new `<div>` element.
*
* @param o - The options object.
* @param callback - A callback function to be called when the element is created.
* @returns The created element.
* @example
* ```ts
* document.body.createDiv({ text: 'foo' }, (div) => {
* div.createEl('strong', { text: 'bar' });
* });
* ```
* @official
*/
createDiv(o?: DomElementInfo | string, callback?: (el: HTMLDivElement) => void): HTMLDivElement;
/**
* Create an element and append it to this node.
*
* @typeParam K - The type of the element to create.
* @param tag - The tag name of the element to create.
* @param o - The options object.
* @param callback - A callback function to be called when the element is created.
* @returns The created element.
* @example
* ```ts
* document.body.createEl('p', { text: 'foo' }, (div) => {
* div.createEl('strong', { text: 'bar' });
* });
* ```
* @official
*/
createEl<K extends keyof HTMLElementTagNameMap>(tag: K, o?: DomElementInfo | string, callback?: (el: HTMLElementTagNameMap[K]) => void): HTMLElementTagNameMap[K];
/**
* Creates a new `<span>` element.
*
* @param o - The options object.
* @param callback - A callback function to be called when the element is created.
* @returns The created element.
* @example
* ```ts
* document.body.createSpan({ text: 'foo' }, (span) => {
* span.createEl('strong', { text: 'bar' });
* });
* ```
* @official
*/
createSpan(o?: DomElementInfo | string, callback?: (el: HTMLSpanElement) => void): HTMLSpanElement;
/**
* Creates a new svg element such as `<svg>`, `<circle>`, `<rect>`, etc.
*
* @typeParam K - The type of the element to create.
* @param tag - The tag name of the element to create.
* @param o - The options object.
* @param callback - A callback function to be called when the element is created.
* @returns The created element.
* @example
* ```ts
* document.body.createSvg('svg', { cls: 'foo bar' }, (svg) => {
* svg.createSvg('circle');
* });
* @official
*/
createSvg<K extends keyof SVGElementTagNameMap>(tag: K, o?: SvgElementInfo | string, callback?: (el: SVGElementTagNameMap[K]) => void): SVGElementTagNameMap[K];
/**
* Detaches the node from the DOM.
*
* @example
* ```ts
* const node = document.body.createEl('p');
* console.log(document.body.contains(node)); // true
* node.detach();
* console.log(document.body.contains(node)); // false
* ```
* @official
*/
detach(): void;
/**
* Empties the node.
*
* @example
* ```ts
* const parent = createEl('p');
* parent.createEl('strong');
* console.log(parent.childNodes.length); // 1
* parent.empty();
* console.log(parent.childNodes.length); // 0
* ```
* @official
*/
empty(): void;
/**
* Returns the index of the node or `-1` if the node is not found.
*
* @param other - The node to find.
* @returns The index of the node or `-1` if the node is not found.
* @official
*/
indexOf(other: Node): number;
/**
* Inserts a child node after the current node.
*
* @typeParam T - The type of the node to insert.
* @param node - The node to insert.
* @param child - The child node to insert after.
* @returns The inserted node.
* @example
* ```ts
* const parent = createEl('p');
* const child1 = parent.createEl('strong', { text: '1' });
* const child2 = parent.createEl('strong', { text: '2' });
* const child3 = parent.createEl('strong', { text: '3' });
* const newNode = createEl('em', { text: '4' });
* parent.insertAfter(newNode, child2);
* console.log(parent); // <p><strong>1</strong><strong>2</strong><em>4</em><strong>3</strong></p>
* ```
* @official
*/
insertAfter<T extends Node>(node: T, child: Node | null): T;
/**
* Cross-window capable instanceof check, a drop-in replacement.
* for instanceof checks on DOM Nodes. Remember to also check
* for nulls when necessary.
*
* @typeParam T - The type of the instance.
* @param type - The type to check.
* @returns `true` if the node is of the given type, `false` otherwise.
* @example
* ```ts
* const node = createEl('p');
* console.log(node.instanceOf(HTMLParagraphElement)); // true
* console.log(node.instanceOf(HTMLSpanElement)); // false
* ```
* @official
*/
instanceOf<T>(type: {
new (): T;
}): this is T;
/**
* Sets the children of the node.
*
* @param children - The children to set.
* @example
* ```ts
* const parent = createEl('p');
* const child1 = parent.createEl('strong', { text: '1' });
* const child2 = parent.createEl('strong', { text: '2' });
* const child3 = createEl('strong', { text: '3' });
* parent.setChildrenInPlace([child1, child3]);
* console.log(parent); // <p><strong>1</strong><strong>3</strong></p>
* ```
* @official
*/
setChildrenInPlace(children: Node[]): void;
}
}
declare global {
/**
* Augments the built-in {@link NumberConstructor} interface.
*/
interface NumberConstructor {
/**
* Type guard to check if a value is a number.
*
* @param obj - The value to check.
* @returns `true` if the value is a number, `false` otherwise.
* @example
* ```ts
* console.log(Number.isNumber(123)); // true
* console.log(Number.isNumber('123')); // false
* console.log(Number.isNumber(NaN)); // true
* console.log(Number.isNumber(Infinity)); // true
* console.log(Number.isNumber(-Infinity)); // true
* ```
* @remarks Regarding `NaN` see: {@link https://forum.obsidian.md/t/bug-number-isnumber-definition/98104}.
* @official
*/
isNumber(obj: any): obj is number;
}
}
declare global {
/**
* Augments the built-in {@link ObjectConstructor} interface.
*/
interface ObjectConstructor {
/**
* Check if all properties in an object satisfy a condition.
*
* @typeParam T - The type of the properties in the object.
* @param object - The object to check.
* @param callback - The condition to check.
* @param context - The context passed as `this` to the `callback`.
* @returns `true` if all properties satisfy the condition, `false` otherwise.
* @example
* ```ts
* console.log(Object.each({ a: 1, b: 2 }, function(value) { return value > this.min }, { min: 0 })); // true
* console.log(Object.each({ a: 1, b: 2 }, function(value) { return value > this.min }, { min: 1 }); // false
* ```
* @official
*/
each<T>(object: {
[key: string]: T;
}, callback: (value: T, key?: string) => boolean | void, context?: any): boolean;
/**
* Checks if an object is empty.
*
* @param object - The object to check.
* @returns `true` if the object is empty, `false` otherwise.
* @example
* ```ts
* console.log(Object.isEmpty({})); // true
* console.log(Object.isEmpty({ a: 1 })); // false
* ```
* @official
*/
isEmpty(object: Record<string, any>): boolean;
}
}
declare global {
/**
* Augments the built-in {@link SVGElement} interface.
*/
interface SVGElement extends Element {
/**
* Sets the CSS properties of the element.
*
* @param props - The properties to set.
* @example
* ```ts
* const element = document.body.createEl('svg');
* element.setCssProps({ color: 'red', 'font-size': '16px' });
* ```
* @official
*/
setCssProps(props: Record<string, string>): void;
/**
* Sets the CSS styles of the element.
*
* @param styles - The styles to set.
* @example
* ```ts
* const element = document.body.createEl('svg');
* element.setCssStyles({ color: 'red', fontSize: '16px' });
* ```
* @official
*/
setCssStyles(styles: Partial<CSSStyleDeclaration>): void;
}
}
declare global {
/**
* Augments the built-in {@link StringConstructor} interface.
*/
interface StringConstructor {
/**
* Type guard to check if a value is a string.
*
* @param obj - The value to check.
* @returns `true` if the value is a string, `false` otherwise.
* @example
* ```ts
* console.log(String.isString('foo')); // true
* console.log(String.isString(123)); // false
* ```
* @official
*/
isString(obj: any): obj is string;
}
}
declare global {
/**
* Augments the built-in {@link String} interface.
*/
interface String {
/**
* Checks if the string contains a specific substring.
*
* @param target - The substring to check for.
* @returns `true` if the string contains the substring, `false` otherwise.
* @example
* ```ts
* console.log('foo'.contains('oo')); // true
* console.log('foo'.contains('bar')); // false
* ```
* @official
*/
contains(target: string): boolean;
/**
* Checks if the string ends with a specific substring.
*
* @param searchString - The substring to check for.
* @param endPosition - The position to end checking at.
* @returns `true` if the string ends with the substring, `false` otherwise.
* @example
* ```ts
* console.log('foo'.endsWith('oo')); // true
* console.log('foo'.endsWith('fo')); // false
* console.log('foo'.endsWith('foo', 2)); // false
* console.log('foo'.endsWith('fo', 2)); // true
* ```
* @remarks The original version had different argument names.
* See bug: {@link https://forum.obsidian.md/t/bug-string-endwith-definition/98103}.
* @official
*/
endsWith(searchString: string, endPosition?: number): boolean;
/**
* Formats a string using the indexed placeholders.
*
* @param args - The arguments to format the string with.
* @returns The formatted string.
* @example
* ```ts
* console.log('foo {0} bar {1} baz {0}'.format('qux', 'quux')); // foo qux bar quux baz qux
* ```
* @official
*/
format(...args: string[]): string;
/**
* Checks if the string starts with a specific substring.
*
* @param searchString - The substring to check for.
* @param position - The position to start checking from.
* @returns `true` if the string starts with the substring, `false` otherwise.
* @example
* ```ts
* console.log('foo'.startsWith('fo')); // true
* console.log('foo'.startsWith('oo')); // false
* console.log('foo'.startsWith('foo', 1)); // false
* console.log('foo'.startsWith('oo', 1)); // true
* ```
* @official
*/
startsWith(searchString: string, position?: number): boolean;
}
}
declare global {
/**
* Augments the built-in {@link Touch} interface.
*/
interface Touch {
/**
* The type of touch.
* @official
*/
touchType: "stylus" | "direct";
}
}
declare global {
/**
* Augments the built-in {@link UIEvent} interface.
*/
interface UIEvent extends Event {
/**
* The document of the event.
* @official
*/
doc: Document;
/**
* The target node of the event.
* @official
*/
targetNode: Node | null;
/**
* The window of the event.
* @official
*/
win: Window;
/**
* Cross-window capable instanceof check, a drop-in replacement.
* for instanceof checks on UIEvents.
*
* @typeParam T - The type to check.
* @param type - The type to check.
* @returns Whether the event is an instance of the type.
* @example
* ```ts
* if (event.instanceOf(MouseEvent)) {
* console.log('event is a mouse event');
* }
* ```
* @official
*/
instanceOf<T>(type: {
new (...data: any[]): T;
}): this is T;
}
}
declare global {
/**
* Augments the built-in {@link Window} interface.
*/
interface Window extends EventTarget, AnimationFrameProvider, GlobalEventHandlers, WindowEventHandlers, WindowLocalStorage, WindowOrWorkerGlobalScope, WindowSessionStorage {
/**
* The actively focused Document object. This is usually the same as `document` but.
* it will be different when using popout windows.
*
* @official
*/
activeDocument: Document;
/**
* The actively focused Window object. This is usually the same as `window` but.
* it will be different when using popout windows.
*
* @official
*/
activeWindow: Window;
/**
* Global reference to the app.
*
* @unofficial
* @deprecated - Prefer not to use this value directly.
*/
app: App;
/**
* @todo Documentation incomplete.
* @unofficial
*/
bl: typeof Object.hasOwnProperty;
/**
* @todo Documentation incomplete.
* @unofficial
* @hidden
*/
blinkfetch: typeof fetch;
/**
* @todo Documentation incomplete.
* @unofficial
*/
blinkFormData: typeof FormData;
/**
* @todo Documentation incomplete.
* @unofficial
*/
blinkHeaders: typeof Headers;
/**
* @todo Documentation incomplete.
* @unofficial
*/
blinkRequest: typeof Request;
/**
* @todo Documentation incomplete.
* @unofficial
*/
blinkResponse: typeof Response;
/**
* @todo Documentation incomplete.
* @unofficial
*/
Capacitor: typeof Capacitor;
/**
* @todo Documentation incomplete.
* @unofficial
*/
CapacitorPlatforms: typeof CapacitorPlatforms;
/**
* @todo Documentation incomplete.
* @unofficial
*/
Cf: typeof Object.getOwnPropertyDescriptors;
/**
* @todo Documentation incomplete.
* @unofficial
*/
CodeMirror: typeof CodeMirror$1;
/**
* @todo Documentation incomplete.
* @unofficial
*/
CodeMirrorAdapter: CodeMirrorAdapterEx;
/**
* DOMPurify is a DOM-only, super-fast, uber-tolerant XSS sanitizer for HTML, MathML and SVG.
*
* @unofficial
*/
DOMPurify: typeof DOMPurify$1;
/**
* @todo Documentation incomplete.
* @unofficial
*/
El: typeof Object.propertyIsEnumerable;
/**
* @todo Documentation incomplete.
* @unofficial
*/
electron: typeof electron;
/**
* @todo Documentation incomplete.
* @unofficial
*/
electronWindow: ElectronWindow;
/**
* @todo Documentation incomplete.
* @unofficial
*/
frameDom: FrameDom;
/**
* Constructor for the Capacitor file system adapter.
*
* @unofficial
*/
FS: CapacitorAdapterFsConstructor;
/**
* @todo Documentation incomplete.
* @unofficial
*/
i18next: typeof i18next;
/**
* @todo Documentation incomplete.
* @unofficial
*/
MathJax?: MathJax;
/**
* @todo Documentation incomplete.
* @unofficial
*/
mermaid?: Mermaid;
/**
* Parse, validate, manipulate, and display dates in javascript.
*
* @unofficial
*
* Commented out because the global variable is already declared in the `moment` package.
*/
moment: typeof moment$1;
/**
* @todo Documentation incomplete.
* @unofficial
*/
mr: typeof Object.getOwnPropertySymbols;
/**
* Notification component. Use to present timely, high-value information.
*
* @unofficial
*/
Notice: typeof Notice;
/**
* Invoke obsidian protocol action.
*
* @unofficial
*/
OBS_ACT: ObsidianProtocolHandler;
/**
* @todo Documentation incomplete.
* @unofficial
*/
OBSIDIAN_DEFAULT_I18N: Localization;
/**
* @todo Documentation incomplete.
* @unofficial
*/
pdfjsLib: typeof pdfjsLib;
/**
* @todo Documentation incomplete.
* @unofficial
*/
pdfjsTestingUtils: PdfJsTestingUtils;
/**
* @todo Documentation incomplete.
* @unofficial
*/
PIXI: typeof PIXI;
/**
* @todo Documentation incomplete.
* @unofficial
*/
Prism?: typeof Prism$1;
/**
* Similar to `fetch()`, request a URL using HTTP/HTTPS, without any CORS restrictions.
*
* Returns the text value of the response.
* @unofficial
*/
request: typeof request;
/**
* Similar to `fetch()`, request a URL using HTTP/HTTPS, without any CORS restrictions.
*
* @unofficial
*/
requestUrl: typeof requestUrl;
/**
* @todo Documentation incomplete.
* @unofficial
*/
scrypt: typeof scrypt$1;
/**
* @todo Documentation incomplete.
* @unofficial
*/
Sf: typeof Object.defineProperties;
/**
* @todo Documentation incomplete.
* @unofficial
*/
temp1: Database["changeVersion"];
/**
* @todo Documentation incomplete.
* @unofficial
*/
titlebarStyle: string;
/**
* @todo Documentation incomplete.
* @unofficial
*/
TurndownService: typeof TurndownService;
/**
* @todo Documentation incomplete.
* @unofficial
*/
WebView: electron.WebviewTag;
/**
* @todo Documentation incomplete.
* @unofficial
*/
wf: typeof Object.defineProperty;
/**
* Sends an AJAX request.
*
* @param options - The options for the AJAX request.
* @example
* ```ts
* ajax({
* url: 'https://example.com',
* success: (response) => {
* console.log(response);
* },
* error: (error) => {
* console.error(error);
* }
* });
* ```
* @official
*/
ajax(options: AjaxOptions): void;
/**
* Sends an AJAX request and returns a promise.
*
* @param options - The options for the AJAX request.
* @returns A promise that resolves to the response.
* @example
* ```ts
* const response = await ajaxPromise({ url: 'https://example.com' });
* console.log(response);
* ```
* @official
*/
ajaxPromise(options: AjaxOptions): Promise<any>;
/**
* Creates a new `<div>` element.
*
* @param o - The options object.
* @param callback - A callback function to be called when the element is created.
* @returns The created element.
* @example
* ```ts
* createDiv({ text: 'foo' }, (div) => {
* div.createEl('strong', { text: 'bar' });
* });
* ```
* @official
*/
createDiv(o?: DomElementInfo | string, callback?: (el: HTMLDivElement) => void): HTMLDivElement;
/**
* Creates a new element.
*
* @typeParam K - The type of the element to create.
* @param tag - The tag name of the element to create.
* @param o - The options object.
* @param callback - A callback function to be called when the element is created.
* @returns The created element.
* @example
* ```ts
* createEl('p', { text: 'foo' }, (p) => {
* p.createEl('strong', { text: 'bar' });
* });
* ```
* @official
*/
createEl<K extends keyof HTMLElementTagNameMap>(tag: K, o?: DomElementInfo | string, callback?: (el: HTMLElementTagNameMap[K]) => void): HTMLElementTagNameMap[K];
/**
* Creates a new document fragment.
*
* @param callback - A callback function to be called when the element is created.
* @returns The created element.
* @example
* ```ts
* createFragment((fragment) => {
* fragment.createEl('p', { text: 'foo' });
* });
* ```
* @official
*/
createFragment(callback?: (el: DocumentFragment) => void): DocumentFragment;
/**
* Creates a new `<span>` element.
*
* @param o - The options object.
* @param callback - A callback function to be called when the element is created.
* @returns The created element.
* @example
* ```ts
* createSpan({ text: 'foo' }, (span) => {
* span.createEl('strong', { text: 'bar' });
* });
* ```
* @official
*/
createSpan(o?: DomElementInfo | string, callback?: (el: HTMLSpanElement) => void): HTMLSpanElement;
/**
* Creates a new svg element such as `<svg>`, `<circle>`, `<rect>`, etc.
*
* @param tag - The tag name of the element to create.
* @param o - The options object.
* @param callback - A callback function to be called when the element is created.
* @returns The created element.
* @example
* ```ts
* createSvg('svg', { cls: 'foo bar' }, (svg) => {
* svg.createSvg('circle');
* });
* ```
* @official
*/
createSvg<K extends keyof SVGElementTagNameMap>(tag: K, o?: SvgElementInfo | string, callback?: (el: SVGElementTagNameMap[K]) => void): SVGElementTagNameMap[K];
/**
* Finds the first element that matches the selector.
*
* @param selector - The selector to find the element with.
* @returns The first element that matches the selector, or `null` if no match is found.
* @example
* ```ts
* const element = document.body.createEl('p');
* element.createEl('strong', { cls: 'foo' });
* console.log(fish('.foo')); // <strong class="foo"></span>
* console.log(fish('.bar')); // null
* ```
* @official
*/
fish(selector: string): HTMLElement | null;
/**
* Finds all elements that match the selector.
*
* @param selector - The selector to find the elements with.
* @returns An array of all elements that match the selector.
* @example
* ```ts
* const element = document.body.createEl('p');
* element.createEl('strong', { cls: 'foo' });
* element.createEl('strong', { cls: 'foo' });
* console.log(fishAll('.foo')); // [<strong class="foo"></strong>, <strong class="foo"></strong>]
* console.log(fishAll('.bar')); // []
* ```
* @official
*/
fishAll(selector: string): HTMLElement[];
/**
* @todo Documentation incomplete.
* @unofficial
*/
globalEnhance(): void;
/**
* vim.js based on https://github.com/codemirror/CodeMirror/commit/793c9e65e09ec7fba3f4f5aaf366b3d36e1a709e (2021-12-04)
*
* Modified from https://github.com/nightwing/cm6-vim-mode-experiment/blob/master/src/vim.js 103a9b5 2021-12-03
*
* CodeMirror, copyright (c) by Marijn Haverbeke and others
*
* Distributed under an MIT license: https://codemirror.net/5/LICENSE
*
* Supported keybindings:
* Too many to list. Refer to defaultKeymap below.
*
* Supported Ex commands:
* Refer to defaultExCommandMap below.
*
* Registers: unnamed, -, ., :, /, _, a-z, A-Z, 0-9
* (Does not respect the special case for number registers when delete
* operator is made with these commands: %, (, ), , /, ?, n, N, {, } )
* TODO: Implement the remaining registers.
*
* Marks: a-z, A-Z, and 0-9
* TODO: Implement the remaining special marks. They have more complex
* behavior.
*
* Events:
* 'vim-mode-change' - raised on the editor anytime the current mode changes,
* Event object: {mode: "visual", subMode: "linewise"}
*
* Code structure:
* 1. Default keymap
* 2. Variable declarations and short basic helpers
* 3. Instance (External API) implementation
* 4. Internal state tracking objects (input state, counter) implementation
* and instantiation
* 5. Key handler (the main command dispatcher) implementation
* 6. Motion, operator, and action implementations
* 7. Helper functions for the key handler, motions, operators, and actions
* 8. Set up Vim to work as a keymap for CodeMirror.
* 9. Ex command implementations.
*
* @unofficial
*/
initVimMode(CodeMirror: CodeMirrorAdapterEx): VimApi;
/**
* Checks if the given object is a boolean.
*
* @param obj - The object to check.
* @returns `true` if the object is a boolean, `false` otherwise.
* @example
* ```ts
* console.log(isBoolean(false)); // true
* console.log(isBoolean('not a boolean')); // false
* ```
* @official
*/
isBoolean(obj: any): obj is boolean;
/**
* @todo Documentation incomplete.
* @unofficial
*/
li(target: object, source: object): object;
/**
* @todo Documentation incomplete.
* @unofficial
*/
mo(target: object, propertyNames: string[]): object;
/**
* Waits for the next frame.
*
* @returns A promise that resolves after the next frame.
* @example
* ```ts
* await nextFrame();
* ```
* @official
*/
nextFrame(): Promise<void>;
/**
* @todo Documentation incomplete.
* @unofficial
*/
openDatabase(name: string, version: string, displayName: string, estimatedSize: number, creationCallback?: (database: Database) => void): Database;
/**
* Executes a function when the DOM is ready.
*
* @param fn - The function to execute when the DOM is ready.
* @example
* ```ts
* ready(() => {
* console.log('DOM is ready');
* });
* @official
*/
ready(fn: () => any): void;
/**
* Select a language file location.
*
* @unofficial
*/
selectLanguageFileLocation(): void;
/**
* Sleeps for a given number of milliseconds.
*
* @param ms - The number of milliseconds to sleep.
* @returns A promise that resolves after the given number of milliseconds.
* @example
* ```ts
* await sleep(1000);
* ```
* @official
*/
sleep(ms: number): Promise<void>;
/**
* @todo Documentation incomplete.
* @unofficial
*/
St(target: object, source: object | undefined): object;
/**
* @todo Documentation incomplete.
* @unofficial
*/
Tl(target: object, propertyName: string, propertyValue: unknown): unknown;
}
}
declare global {
/**
* Global reference to the app.
*
* @unofficial
* @deprecated - Prefer not to use this value directly.
*/
var app: Window["app"];
}
declare global {
/**
* Information about HTMLElement event listener.
*/
interface EventListenerInfo {
/**
* Wrapper function of the event listener.
* @official
*/
callback: Function;
/**