/* THIS IS A GENERATED/BUNDLED FILE BY ESBUILD if you want to view the source, please visit the github repository of this plugin */ 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); // src/main.ts var main_exports = {}; __export(main_exports, { default: () => HTMLTabsPlugin }); module.exports = __toCommonJS(main_exports); var import_obsidian2 = require("obsidian"); // src/lines.ts var Line = class { constructor(text, line, offset) { this.text = text; this.loc = { col: 0, line, offset }; } }; // src/tabs.ts var Tabs = class { constructor() { this.tabs = []; this.active_id = 0; } hasTabs() { return this.tabs.length > 0; } }; // src/util/parsing.ts function getTabExtSource(el, ctx) { const sectionInfo = ctx.getSectionInfo(el); if (!sectionInfo) { return []; } const lines = []; const rawLines = sectionInfo.text.split("\n"); let offset = 0; let lineNumber = 0; rawLines.forEach((rawLine) => { if (lineNumber < sectionInfo.lineStart) { offset += rawLine.length + 1; lineNumber++; return; } if (lineNumber >= sectionInfo.lineStart && lineNumber <= sectionInfo.lineEnd) { lines.push(new Line(rawLine, lineNumber, offset)); offset += rawLine.length + 1; lineNumber++; return; } }); return lines; } function parseTabs(lines) { const tabs = new Tabs(); let newTab = null; let id = 0; for (const line of lines) { if (line.text.startsWith("---tab")) { if (newTab) { tabs.tabs.push(newTab); newTab = null; } const match = line.text.match(/---tab(\*)? (.+)/); if (match) { const [_, isStarred, label] = match; newTab = { id: id++, label: label.trim(), content: "" }; if (isStarred !== void 0) { tabs.active_id = newTab.id; } } } else if (newTab) { if (newTab.content === "") { newTab.content += line.text; } else { newTab.content += "\n" + line.text; } } } if (newTab) { tabs.tabs.push(newTab); } return tabs; } function parseLinesForCache(lines) { const tabCache = {}; for (const line of lines) { parseLineForEmbed(line, tabCache); parseLineForHeadings(line, tabCache); parseLineForLinks(line, tabCache); parseLineForListItems(line, tabCache); parseLineForSections(line, tabCache); parseLineForTags(line, tabCache); } return tabCache; } function parseLineForEmbed(line, tabCache) { } function parseLineForHeadings(line, tabCache) { } function parseLineForLinks(line, tabCache) { const linkRegex = /(?[^|\]]+)(\|(?[^\]]+))?\]\]/g; const matches = [...line.text.matchAll(linkRegex)]; if (matches.length > 0) { tabCache.links = []; matches.forEach(function(match) { var _a; const col = match.index ? match.index : 0; const start2 = { col, line: line.loc.line, offset: line.loc.offset + col }; const linkCache = { intabs: true, link: match.groups ? match.groups.link : match[1], original: match[0], position: { end: { col: start2.col + match[0].length, line: start2.line, offset: start2.offset + match[0].length }, start: start2 } }; if (match.groups && match.groups.display) { linkCache.displayText = match.groups.display; } (_a = tabCache.links) == null ? void 0 : _a.push(linkCache); }); } } function parseLineForListItems(line, tabCache) { } function parseLineForSections(line, tabCache) { } function parseLineForTags(line, tabCache) { } // src/util/cache.ts function updateCache(app2, tabLines) { rebuildCurrentPageCache(app2, tabLines); } function rebuildCurrentPageCache(app2, tabLines) { const current_file = app2.workspace.getActiveFile(); const pageCache = getPageCache(current_file); rebuildPageCache(pageCache, tabLines); app2.metadataCache.trigger("changed", current_file); app2.metadataCache.trigger("resolve", current_file); updateCacheLinks(app2.metadataCache, pageCache, current_file); } function updateCacheLinks(metadataCache, pageCache, current_file) { if (!pageCache || !pageCache.links || !current_file) { return; } const pageResolvedLinks = {}; const pageUnresolvedLinks = {}; pageCache.links.forEach((link) => { if (!link.intabs) { return; } let path = ""; let pageLinks = pageResolvedLinks; const file = metadataCache.getFirstLinkpathDest(link.link, ""); if (!file) { pageLinks = pageUnresolvedLinks; path = link.link; } else { path = file.path; } if (pageLinks[path] === void 0) { pageLinks[path] = 0; } pageLinks[path]++; }); metadataCache.resolvedLinks[current_file.path] = pageResolvedLinks; metadataCache.unresolvedLinks[current_file.path] = pageUnresolvedLinks; } function getPageCache(current_file) { if (!current_file) { return null; } return app.metadataCache.getFileCache(current_file); } function rebuildPageCache(pageCache, tabLines) { if (!pageCache) { return; } const tabCache = parseLinesForCache(tabLines); rebuildEmbedsCache(pageCache, tabCache); rebuildHeadingsCache(pageCache, tabCache); rebuildLinksCache(pageCache, tabCache); rebuildListItemsCache(pageCache, tabCache); rebuildSectionsCache(pageCache, tabCache); rebuildTagsCache(pageCache, tabCache); } function rebuildEmbedsCache(pageCache, tabCache) { if (!tabCache.embeds) { return; } if (!pageCache.embeds) { pageCache.embeds = []; } } function rebuildHeadingsCache(pageCache, tabCache) { } function rebuildLinksCache(pageCache, tabCache) { if (!tabCache.links) { return; } if (!pageCache.links) { pageCache.links = []; } const filteredLinks = pageCache.links.filter((link) => !link.intabs); const newLinks = filteredLinks.concat(tabCache.links).sort((a, b) => { return a.position.start.offset - b.position.start.offset; }); pageCache.links = newLinks; } function rebuildListItemsCache(pageCache, tabCache) { } function rebuildSectionsCache(pageCache, tabCache) { } function rebuildTagsCache(pageCache, tabCache) { } // src/ui/rendering.ts var import_obsidian = require("obsidian"); function render(tabs, source, container, ctx) { if (!tabs.hasTabs()) { renderCodeBlock(container, source, "html"); return; } const plugin2 = window.html_tabs_plugin; const mainAttributes = { "data-x-data": "{ tab: " + tabs.active_id + " }" }; const divMain = container.createEl("div", { attr: mainAttributes }); const divTabs = divMain.createEl("div", { cls: ["html-tabs"] }); for (let index = 0; index < tabs.tabs.length; index++) { const element = tabs.tabs[index]; const classes = ["html-tab"]; if (index > 0) { classes.push("html-tab-not-first"); } if (index === tabs.active_id) { classes.push("html-tab-active"); } const attributes = { "data-x-bind:class": "{ 'html-tab-active': tab == " + element.id + " }", "data-x-on:click": "tab = " + element.id }; const divTab = divTabs.createEl("div", { cls: classes, attr: attributes }); import_obsidian.MarkdownRenderer.render(plugin2.app, element.label, divTab, ctx.sourcePath, plugin2); } const divContent = divMain.createEl("div", { cls: ["html-tab-content"] }); for (let index = 0; index < tabs.tabs.length; index++) { const element = tabs.tabs[index]; const attributes = { "data-x-show": "tab == " + element.id }; const divTabContent = divContent.createEl("div", { attr: attributes }); import_obsidian.MarkdownRenderer.render(plugin2.app, element.content, divTabContent, ctx.sourcePath, plugin2).then(() => { const checks = divTabContent.findAll("input[type='checkbox']"); for (let i = 0; i < checks.length; i++) { checks[i].addEventListener("click", (event) => { event.preventDefault(); event.stopPropagation(); console.log("task has ben (un)checked"); }); } }); } } function renderCodeBlock(container, source, language) { const code = container.createEl("code", { cls: ["html-tabs"] }); if (language) { code.classList.add("language-" + language); } code.appendText(source); return code; } // node_modules/.pnpm/alpinejs@3.13.0/node_modules/alpinejs/dist/module.esm.js var flushPending = false; var flushing = false; var queue = []; var lastFlushedIndex = -1; function scheduler(callback) { queueJob(callback); } function queueJob(job) { if (!queue.includes(job)) queue.push(job); queueFlush(); } function dequeueJob(job) { let index = queue.indexOf(job); if (index !== -1 && index > lastFlushedIndex) queue.splice(index, 1); } function queueFlush() { if (!flushing && !flushPending) { flushPending = true; queueMicrotask(flushJobs); } } function flushJobs() { flushPending = false; flushing = true; for (let i = 0; i < queue.length; i++) { queue[i](); lastFlushedIndex = i; } queue.length = 0; lastFlushedIndex = -1; flushing = false; } var reactive; var effect; var release; var raw; var shouldSchedule = true; function disableEffectScheduling(callback) { shouldSchedule = false; callback(); shouldSchedule = true; } function setReactivityEngine(engine) { reactive = engine.reactive; release = engine.release; effect = (callback) => engine.effect(callback, { scheduler: (task) => { if (shouldSchedule) { scheduler(task); } else { task(); } } }); raw = engine.raw; } function overrideEffect(override) { effect = override; } function elementBoundEffect(el) { let cleanup2 = () => { }; let wrappedEffect = (callback) => { let effectReference = effect(callback); if (!el._x_effects) { el._x_effects = /* @__PURE__ */ new Set(); el._x_runEffects = () => { el._x_effects.forEach((i) => i()); }; } el._x_effects.add(effectReference); cleanup2 = () => { if (effectReference === void 0) return; el._x_effects.delete(effectReference); release(effectReference); }; return effectReference; }; return [wrappedEffect, () => { cleanup2(); }]; } function dispatch(el, name, detail = {}) { el.dispatchEvent( new CustomEvent(name, { detail, bubbles: true, // Allows events to pass the shadow DOM barrier. composed: true, cancelable: true }) ); } function walk(el, callback) { if (typeof ShadowRoot === "function" && el instanceof ShadowRoot) { Array.from(el.children).forEach((el2) => walk(el2, callback)); return; } let skip = false; callback(el, () => skip = true); if (skip) return; let node = el.firstElementChild; while (node) { walk(node, callback, false); node = node.nextElementSibling; } } function warn(message, ...args) { console.warn(`Alpine Warning: ${message}`, ...args); } var started = false; function start() { if (started) warn("Alpine has already been initialized on this page. Calling Alpine.start() more than once can cause problems."); started = true; if (!document.body) warn("Unable to initialize. Trying to load Alpine before `` is available. Did you forget to add `defer` in Alpine's `