/* THIS IS A GENERATED/BUNDLED FILE BY ESBUILD if you want to view the source, please visit the github repository of this plugin */ "use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var __accessCheck = (obj, member, msg) => { if (!member.has(obj)) throw TypeError("Cannot " + msg); }; var __privateGet = (obj, member, getter) => { __accessCheck(obj, member, "read from private field"); return getter ? getter.call(obj) : member.get(obj); }; var __privateAdd = (obj, member, value) => { if (member.has(obj)) throw TypeError("Cannot add the same private member more than once"); member instanceof WeakSet ? member.add(obj) : member.set(obj, value); }; var __privateSet = (obj, member, value, setter) => { __accessCheck(obj, member, "write to private field"); setter ? setter.call(obj, value) : member.set(obj, value); return value; }; // src/main.ts var main_exports = {}; __export(main_exports, { default: () => CalloutManagerPlugin }); module.exports = __toCommonJS(main_exports); var import_obsidian18 = require("obsidian"); // node_modules/obsidian-extra/dist/esm/functions/getFloatingWindows.js function getFloatingWindows(app2) { var _a, _b, _c, _d; return (_d = (_c = (_b = (_a = app2 === null || app2 === void 0 ? void 0 : app2.workspace) === null || _a === void 0 ? void 0 : _a.floatingSplit) === null || _b === void 0 ? void 0 : _b.children) === null || _c === void 0 ? void 0 : _c.map((split) => split.win)) !== null && _d !== void 0 ? _d : []; } // node_modules/obsidian-extra/dist/esm/functions/getCurrentThemeID.js function getCurrentThemeID(app2) { const theme = app2.customCss.theme; return theme === "" ? null : theme; } // node_modules/obsidian-extra/dist/esm/functions/getCurrentColorScheme.js function getCurrentThemeID2(app2) { const { body } = app2.workspace.containerEl.doc; return body.classList.contains("theme-dark") ? "dark" : "light"; } // node_modules/obsidian-extra/dist/esm/functions/getThemeManifest.js function getThemeManifest(app2, themeID) { const manifests = app2.customCss.themes; if (!Object.prototype.hasOwnProperty.call(manifests, themeID)) { return null; } return manifests[themeID]; } // node_modules/obsidian-extra/dist/esm/functions/isThemeInstalled.js function isThemeInstalled(app2, themeID) { return getThemeManifest(app2, themeID) !== null; } // node_modules/obsidian-extra/dist/esm/functions/getThemeStyleElement.js function getThemeStyleElement(app2) { const currentTheme = getCurrentThemeID(app2); if (currentTheme == null || !isThemeInstalled(app2, currentTheme)) { return null; } return app2.customCss.styleEl; } // node_modules/obsidian-extra/dist/esm/functions/isSnippetEnabled.js function isSnippetEnabled(app2, snippetID) { return app2.customCss.enabledSnippets.has(snippetID); } // node_modules/obsidian-extra/dist/esm/functions/fetchObsidianStyles.js var import_obsidian = require("obsidian"); // node_modules/obsidian-extra/dist/esm/internal/utils/versionCompare.js function versionCompare(a, b) { const aParts = a.split(".").map((n) => parseInt(n, 10)); const bParts = b.split(".").map((n) => parseInt(n, 10)); const partsSize = Math.max(aParts.length, bParts.length); arrayPadEnd(aParts, partsSize, 0); arrayPadEnd(bParts, partsSize, 0); for (let i = 0; i < partsSize; i++) { if (aParts[i] < bParts[i]) return -1; if (aParts[i] > bParts[i]) return 1; } return 0; } function arrayPadEnd(arr, length, fill) { const missing = length - arr.length; if (missing > 0) { arr.push(...new Array(missing).fill(fill)); } } // node_modules/obsidian-extra/dist/esm/functions/fetchObsidianStyles.js var __awaiter = function(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 fetchObsidianStyles(app2) { var _a; return __awaiter(this, void 0, void 0, function* () { if (versionCompare(import_obsidian.apiVersion, "1.1.15") > 0) { throw new Error(`[obsidian-extra]: Obsidian ${import_obsidian.apiVersion} has not been tested with this function`); } try { const electron = (_a = globalThis.electron) !== null && _a !== void 0 ? _a : require("electron"); if (electron == null) { throw new Error("Unable to get electron module from web renderer process"); } const fs = require("fs/promises"); if ((fs === null || fs === void 0 ? void 0 : fs.readFile) == null) { throw new Error("Unable to get fs module from web renderer process"); } const resources = electron.ipcRenderer.sendSync("resources"); return yield fs.readFile(`${resources}/app.css`, "utf8"); } catch (ex) { throw new Error(`[obsidian-extra]: Could not get Obsidian styles: ${ex}`); } }); } // node_modules/obsidian-extra/dist/esm/functions/getInstalledSnippetIDs.js function getInstalledSnippetIDs(app2) { return app2.customCss.snippets; } // node_modules/obsidian-extra/dist/esm/functions/getSnippetStyleElements.js function getSnippetStyleElements(app2) { const styleManager = app2.customCss; const snippets = getInstalledSnippetIDs(app2); const map = /* @__PURE__ */ new Map(); for (let i = 0, elI = 0; i < snippets.length; i++) { const snippetID = styleManager.snippets[i]; if (isSnippetEnabled(app2, snippetID)) { map.set(snippetID, styleManager.extraStyleEls[elI]); elI++; } } return map; } // node_modules/obsidian-extra/dist/esm/functions/openPluginSettings.js function openPluginSettings(app2, plugin) { var _a, _b; const settingManager = app2.setting; const pluginId = typeof plugin === "string" ? plugin : plugin.manifest.id; if (((_a = settingManager.activeTab) === null || _a === void 0 ? void 0 : _a.id) !== pluginId) { settingManager.openTabById(""); } settingManager.open(); if (((_b = settingManager.activeTab) === null || _b === void 0 ? void 0 : _b.id) !== pluginId) { settingManager.openTabById(pluginId); } } // node_modules/obsidian-extra/dist/esm/functions/createCustomStyleSheet.js var Counter = Symbol("CustomStylesheet count"); function foreachWindow(app2, fn) { fn(app2.workspace.containerEl.doc, true); for (const float of getFloatingWindows(app2)) { fn(float.document, false); } } function createCustomStyleSheet(app2, plugin) { var _a; let result; const pl = plugin; const plId = plugin.manifest.id; const ssId = ((_a = pl[Counter]) !== null && _a !== void 0 ? _a : pl[Counter] = 0).toString(); pl[Counter]++; const styleEl = app2.workspace.containerEl.doc.createElement("style"); const styleElInFloats = []; styleEl.setAttribute("data-source-plugin", plId); styleEl.setAttribute("data-source-id", ssId); function unapply() { styleElInFloats.splice(0, styleElInFloats.length).forEach((el) => el.remove()); styleEl.detach(); foreachWindow(app2, (doc) => { for (const styleEl2 of Array.from(doc.head.querySelectorAll("style"))) { if (result.is(styleEl2)) { styleEl2.remove(); } } }); } function reapply() { unapply(); foreachWindow(app2, (doc, isFloating) => { let lastEl = doc.head.lastElementChild; for (let el = lastEl; el != null; el = el.previousElementSibling) { lastEl = el; if (lastEl.tagName === "STYLE") { break; } } if (!isFloating) { lastEl === null || lastEl === void 0 ? void 0 : lastEl.insertAdjacentElement("afterend", styleEl); return; } const styleElClone = styleEl.cloneNode(true); styleElInFloats.push(styleElClone); lastEl === null || lastEl === void 0 ? void 0 : lastEl.insertAdjacentElement("afterend", styleElClone); }); } app2.workspace.on("css-change", reapply); app2.workspace.on("layout-change", reapply); result = Object.freeze(Object.defineProperties(() => { unapply(); app2.workspace.off("css-change", reapply); app2.workspace.off("layout-change", reapply); }, { css: { enumerable: true, configurable: false, get() { return styleEl.textContent; }, set(v) { styleEl.textContent = v; for (const styleEl2 of styleElInFloats) { styleEl2.textContent = v; } } }, is: { enumerable: false, configurable: false, value: (el) => { return el.getAttribute("data-source-plugin") === plId && el.getAttribute("data-source-id") === ssId; } }, setAttribute: { enumerable: false, configurable: false, value: (attr, value) => { if (attr === "data-source-id" || attr === "data-source-plugin") { throw new Error(`Cannot change attribute '${attr}' on custom style sheet.`); } styleEl.setAttribute(attr, value); for (const styleEl2 of styleElInFloats) { styleEl2.setAttribute(attr, value); } } }, removeAttribute: { enumerable: false, configurable: false, value: (attr) => { if (attr === "data-source-id" || attr === "data-source-plugin") { throw new Error(`Cannot remove attribute '${attr}' from custom style sheet.`); } styleEl.removeAttribute(attr); for (const styleEl2 of styleElInFloats) { styleEl2.removeAttribute(attr); } } } })); reapply(); return result; } // src/ui/paned-setting-tab.ts var import_obsidian3 = require("obsidian"); // node_modules/obsidian-extra/dist/esm/functions/closeSettings.js function closeSettings(app2) { const settingManager = app2.setting; settingManager.close(); } // src/ui/pane-layers.ts var import_obsidian2 = require("obsidian"); var UIPaneLayers = class { constructor(options) { this.layers = []; this.closeParent = options.close; this.navInstance = { open: (pane) => this.push(pane), close: () => this.pop(), replace: (pane) => this.top = pane }; } /** * Pushes a new pane on top of the stack. * The active pane will be suspended. * * @param pane The pane to push. */ push(pane) { const { activePane: oldPane } = this; if (oldPane !== void 0) { const title = oldPane.title; this.layers.push({ scroll: { top: this.scrollEl.scrollTop, left: this.scrollEl.scrollLeft }, state: oldPane.suspendState(), pane: oldPane, title: typeof title === "string" ? title : title.subtitle }); this.setPaneVariables(oldPane, false); this.containerEl.empty(); } const newPane = this.activePane = pane; this.setPaneVariables(newPane, true); newPane.onReady(); this.doDisplay(true); this.scrollEl.scrollTo({ top: 0, left: 0 }); } /** * Pops the active pane off the stack. * The active pane will be destroyed, and the one underneath it will be restored. * * @param pane The pane to push. */ pop(options) { var _a, _b; if (this.activePane === void 0) { this.closeParent(); return void 0; } const noDisplay = (_a = options == null ? void 0 : options.noDisplay) != null ? _a : false; const oldPane = this.activePane; const newPane = this.layers.pop(); this.activePane = void 0; this.setPaneVariables(oldPane, false); oldPane.onClose((_b = options == null ? void 0 : options.cancelled) != null ? _b : false); if (!noDisplay) { this.containerEl.empty(); } if (newPane !== void 0) { this.activePane = newPane.pane; this.setPaneVariables(newPane.pane, true); newPane.pane.restoreState(newPane.state); if (!noDisplay) { this.doDisplay(true); this.scrollEl.scrollTo(newPane.scroll); } } return oldPane; } /** * Removes all panes off the stack. * All panes will be destroyed. * * @param pane The pane to push. */ clear(options) { const removed = []; const opts = { noDisplay: true, ...options != null ? options : {} }; while (this.activePane !== void 0) { removed.push(this.pop(opts)); } return removed; } /** * The top-most (i.e. currently active) pane in the layers. */ get top() { return this.activePane; } set top(pane) { const { activePane: oldTop } = this; if (oldTop !== void 0) { this.setPaneVariables(oldTop, false); oldTop.onClose(false); } const newPane = this.activePane = pane; this.setPaneVariables(newPane, true); newPane.onReady(); this.doDisplay(true); } doDisplay(renderControls) { const { activePane, titleEl, navEl, containerEl } = this; if (activePane === void 0) { return; } navEl.empty(); if (this.layers.length > 0) { new import_obsidian2.ButtonComponent(this.navEl).setIcon("lucide-arrow-left-circle").setClass("clickable-icon").setTooltip(`Back to ${this.layers[this.layers.length - 1].title}`).onClick(() => this.navInstance.close()); } titleEl.empty(); const { title } = activePane; if (typeof title === "string") { titleEl.createEl("h2", { text: title }); } else { titleEl.createEl("h2", { text: title.title }); titleEl.createEl("h3", { text: title.subtitle }); } if (renderControls) { this.controlsEl.empty(); activePane.displayControls(); } containerEl.empty(); activePane.display(); } setPaneVariables(pane, attached) { const notAttachedError = () => { throw new Error("Not attached"); }; Object.defineProperties(pane, { nav: { configurable: true, enumerable: true, get: attached ? () => this.navInstance : notAttachedError }, containerEl: { configurable: true, enumerable: true, get: attached ? () => this.containerEl : notAttachedError }, controlsEl: { configurable: true, enumerable: true, get: attached ? () => this.controlsEl : notAttachedError } }); } }; // src/ui/paned-setting-tab.ts var UISettingTab = class extends import_obsidian3.PluginSettingTab { constructor(plugin, createDefault) { super(plugin.app, plugin); this.plugin = plugin; this.createDefault = createDefault; this.initLayer = null; this.layers = new UIPaneLayers({ close: () => closeSettings(this.app) }); } openWithPane(pane) { this.initLayer = pane; openPluginSettings(this.plugin.app, this.plugin); } /** @override */ hide() { this.initLayer = null; this.layers.clear(); super.hide(); } display() { var _a; const { containerEl, layers } = this; containerEl.empty(); containerEl.classList.add("calloutmanager-setting-tab", "calloutmanager-pane"); const headerEl = containerEl.createDiv({ cls: "calloutmanager-setting-tab-header" }); layers.navEl = headerEl.createDiv({ cls: "calloutmanager-setting-tab-nav" }); layers.titleEl = headerEl.createDiv({ cls: "calloutmanager-setting-tab-title" }); const controlsEl = headerEl.createDiv({ cls: "calloutmanager-setting-tab-controls" }); layers.controlsEl = controlsEl.createDiv(); layers.scrollEl = containerEl.createDiv({ cls: "calloutmanager-setting-tab-viewport vertical-tab-content" }); layers.containerEl = layers.scrollEl.createDiv({ cls: "calloutmanager-setting-tab-content" }); controlsEl.createDiv({ cls: "modal-close-button" }, (closeButtonEl) => { closeButtonEl.addEventListener("click", (ev) => { if (!ev.isTrusted) return; closeSettings(this.app); }); }); layers.clear(); const initLayer = (_a = this.initLayer) != null ? _a : this.createDefault(); this.initLayer = null; layers.top = initLayer; } }; // src/api-v1.ts var import_obsidian5 = require("obsidian"); // src/util/color.ts function toHSV(color) { if ("h" in color && "s" in color && "v" in color) return color; const rFloat = color.r / 255; const gFloat = color.g / 255; const bFloat = color.b / 255; const cmax = Math.max(rFloat, gFloat, bFloat); const cmin = Math.min(rFloat, gFloat, bFloat); const delta = cmax - cmin; let h = 0; if (cmax !== cmin) { switch (cmax) { case rFloat: h = (60 * ((gFloat - bFloat) / delta) + 360) % 360; break; case gFloat: h = (60 * ((bFloat - rFloat) / delta) + 120) % 360; break; case bFloat: h = (60 * ((rFloat - gFloat) / delta) + 240) % 360; break; } } const s = cmax === 0 ? 0 : delta / cmax * 100; const v = cmax * 100; const hsv = { h, s, v }; if ("a" in color) { hsv.a = color.a / 255 * 100; } return hsv; } function toHexRGB(color) { const parts = [color.r, color.g, color.b, ..."a" in color ? [color.a] : []]; return parts.map((c) => c.toString(16).padStart(2, "0")).join(""); } var REGEX_RGB = /^\s*rgba?\(\s*([\d.]+%?)\s*[, ]\s*([\d.]+%?)\s*[, ]\s*([\d.]+%?\s*)\)\s*$/i; function parseColorRGB(rgb) { const matches = REGEX_RGB.exec(rgb); if (matches === null) return null; const components = matches.slice(1).map((v) => v.trim()); const rgbComponents = rgbComponentStringsToNumber(components); if (rgbComponents === null) { return null; } if (void 0 !== rgbComponents.find((v) => isNaN(v) || v < 0 || v > 255)) { return null; } return { r: rgbComponents[0], g: rgbComponents[1], b: rgbComponents[2] }; } function rgbComponentStringsToNumber(components) { if (components[0].endsWith("%")) { if (void 0 !== components.slice(1, 3).find((c) => !c.endsWith("%"))) { return null; } return components.map((v) => parseFloat(v.substring(0, v.length - 1))).map((v) => Math.floor(v * 255 / 100)); } if (void 0 !== components.slice(1, 3).find((c) => c.endsWith("%"))) { return null; } return components.map((v) => parseInt(v, 10)); } // src/ui/component/callout-preview.ts var import_obsidian4 = require("obsidian"); var NO_ATTACH = Symbol(); var CalloutPreviewComponent = class extends import_obsidian4.Component { constructor(containerEl, options) { super(); const { color, icon, id, title, content } = options; const frag = document.createDocumentFragment(); const calloutEl = this.calloutEl = frag.createDiv({ cls: ["callout", "calloutmanager-preview"] }); const titleElContainer = calloutEl.createDiv({ cls: "callout-title" }); this.iconEl = titleElContainer.createDiv({ cls: "callout-icon" }); const titleEl = this.titleEl = titleElContainer.createDiv({ cls: "callout-title-inner" }); const contentEl = this.contentEl = content === void 0 ? void 0 : calloutEl.createDiv({ cls: "callout-content" }); this.setIcon(icon); this.setColor(color); this.setCalloutID(id); if (title == null) titleEl.textContent = id; else if (typeof title === "function") title(titleEl); else if (typeof title === "string") titleEl.textContent = title; else titleEl.appendChild(title); if (contentEl != null) { if (typeof content === "function") content(contentEl); else if (typeof content === "string") contentEl.textContent = content; else contentEl.appendChild(content); } if (containerEl != NO_ATTACH) { CalloutPreviewComponent.prototype.attachTo.call(this, containerEl); } } /** * Changes the callout ID. * This will *not* change the appearance of the preview. * * @param id The new ID to use. */ setCalloutID(id) { const { calloutEl } = this; calloutEl.setAttribute("data-callout", id); return this; } /** * Changes the callout icon. * * @param icon The ID of the new icon to use. */ setIcon(icon) { const { iconEl, calloutEl } = this; calloutEl.style.setProperty("--callout-icon", icon); iconEl.empty(); const iconSvg = (0, import_obsidian4.getIcon)(icon); if (iconSvg != null) { this.iconEl.appendChild(iconSvg); } return this; } /** * Changes the callout color. * * @param color The color to use. */ setColor(color) { const { calloutEl } = this; if (color == null) { calloutEl.style.removeProperty("--callout-color"); return this; } calloutEl.style.setProperty("--callout-color", `${color.r}, ${color.g}, ${color.b}`); return this; } /** * Attaches the callout preview to a DOM element. * This places it at the end of the element. * * @param containerEl The container to attach to. */ attachTo(containerEl) { containerEl.appendChild(this.calloutEl); return this; } /** * Resets the `--callout-color` and `--callout-icon` CSS properties added to the callout element. */ resetStylePropertyOverrides() { const { calloutEl } = this; calloutEl.style.removeProperty("--callout-color"); calloutEl.style.removeProperty("--callout-icon"); } }; var IsolatedCalloutPreviewComponent = class extends CalloutPreviewComponent { constructor(containerEl, options) { var _a, _b, _c; super(NO_ATTACH, options); const frag = document.createDocumentFragment(); const focused = (_a = options.focused) != null ? _a : false; const colorScheme = options.colorScheme; const readingView = ((_b = options.viewType) != null ? _b : "reading") === "reading"; const cssEls = (_c = options == null ? void 0 : options.cssEls) != null ? _c : getCurrentStyles(containerEl == null ? void 0 : containerEl.doc); const shadowHostEl = this.shadowHostEl = frag.createDiv(); const shadowRoot = this.shadowRoot = shadowHostEl.attachShadow({ delegatesFocus: false, mode: "closed" }); const shadowHead = this.shadowHead = shadowRoot.createEl("head"); const shadowBody = this.shadowBody = shadowRoot.createEl("body"); const styleEls = this.styleEls = []; for (const cssEl of cssEls) { const cssElClone = cssEl.cloneNode(true); if (cssEl.tagName === "STYLE") { styleEls.push(cssElClone); } shadowHead.appendChild(cssElClone); } shadowHead.createEl("style", { text: SHADOW_DOM_RESET_STYLES }); this.customStyleEl = shadowHead.createEl("style", { attr: { "data-custom-styles": "true" } }); shadowBody.classList.add(`theme-${colorScheme}`, "obsidian-app"); const viewContentEl = shadowBody.createDiv({ cls: "app-container" }).createDiv({ cls: "horizontal-main-container" }).createDiv({ cls: "workspace" }).createDiv({ cls: "workspace-split mod-root" }).createDiv({ cls: `workspace-tabs ${focused ? "mod-active" : ""}` }).createDiv({ cls: "workspace-tab-container" }).createDiv({ cls: `workspace-leaf ${focused ? "mod-active" : ""}` }).createDiv({ cls: "workspace-leaf-content" }).createDiv({ cls: "view-content" }); const calloutParentEl = readingView ? createReadingViewContainer(viewContentEl) : createLiveViewContainer(viewContentEl); calloutParentEl.appendChild(this.calloutEl); if (containerEl != null) { IsolatedCalloutPreviewComponent.prototype.attachTo.call(this, containerEl); } } /** * Replaces the `