/*!
 * Inline Spoilers for Obsidian
 * https://github.com/logonoff/obsidian-inline-spoilers
 * SPDX-License-Identifier: GPL-3.0-or-later
 */
"use strict";var u=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var N=Object.getOwnPropertyNames;var A=Object.prototype.hasOwnProperty;var C=(t,e)=>{for(var i in e)u(t,i,{get:e[i],enumerable:!0})},v=(t,e,i,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of N(e))!A.call(t,o)&&o!==i&&u(t,o,{get:()=>e[o],enumerable:!(s=y(e,o))||s.enumerable});return t};var _=t=>v(u({},"__esModule",{value:!0}),t);var H={};C(H,{default:()=>g});module.exports=_(H);var D=require("@codemirror/language"),x=require("@codemirror/state"),c=require("@codemirror/view"),n=require("obsidian"),P=/\|\|(.+?)\|\|/g,M="p, li, h1, h2, h3, h4, h5, h6, blockquote, em, strong, b, i, a, th, td",T=t=>{if(t.nodeType===Node.TEXT_NODE){if(!t.textContent||!t.parentNode)return;let e=t.textContent.split(/(\|\|[^|]+\|\|)/g),i=createFragment();for(let s of e)if(P.test(s)){let o=s.slice(2,-2),l=createSpan({cls:"inline_spoilers-spoiler",text:o});i.appendChild(l)}else{let o=activeDocument.createTextNode(s);i.appendChild(o)}t.parentNode.replaceChild(i,t)}else t.nodeType===Node.ELEMENT_NODE&&Array.from(t.childNodes).forEach(T)},w=(t,e)=>{let i=t.findAll(M);for(let o of i)Array.from(o.childNodes).forEach(T);let s=t.findAll(".inline_spoilers-spoiler");for(let o of s)e.registerDomEvent(o,"click",()=>{o.classList.toggle("inline_spoilers-revealed")})},V=t=>{let e=Array.from(t.containerEl.querySelectorAll(".inline_spoilers-spoiler"));for(let i of e){let s=i.parentNode,o=activeDocument.createTextNode(`||${i.innerText}||`);s&&s.replaceChild(o,i)}},L=c.Decoration.mark({class:"inline_spoilers-editor-spoiler",tagName:"span"}),R=c.Decoration.mark({class:"inline_spoilers-editor-spoiler-delimiter",tagName:"span"}),m=class{constructor(e){this.decorations=this.buildDecorations(e)}update(e){(e.docChanged||e.viewportChanged)&&(this.decorations=this.buildDecorations(e.view))}destroy(){}buildDecorations(e){let i=new x.RangeSetBuilder,s=[];for(let{from:o,to:l}of e.visibleRanges)(0,D.syntaxTree)(e.state).iterate({from:o,to:l,enter(E){let k=e.state.sliceDoc(E.from,E.to),h;for(;(h=P.exec(k))!==null;){let a=h.index,p=a+h[0].length,S=e.state.sliceDoc(a,p);!S.startsWith("||")&&!S.endsWith("||")||(s.push({from:a,to:a+2,isDelimiter:!0}),s.push({from:a+2,to:p-2,isDelimiter:!1}),s.push({from:p-2,to:p,isDelimiter:!0}))}}});s.sort((o,l)=>o.from-l.from);for(let o of s)i.add(o.from,o.to,o.isDelimiter?R:L);return i.finish()}},I={decorations:t=>t.decorations},d=c.ViewPlugin.fromClass(m,I),r=[],O=t=>{r.includes(d)||r.push(d),t.updateOptions()},b=t=>{let e=r.indexOf(d);e!==-1&&r.splice(e,1),t.updateOptions()},W={showAllSpoilers:!1,enableEditorMode:!1},f=class extends n.PluginSettingTab{constructor(e,i){super(e,i),this.plugin=i}display(){let{containerEl:e}=this;e.empty(),new n.Setting(e).setName("Reveal all spoilers").setDesc("Always show all inline spoilers, regardless of whether they are clicked or not.").addToggle(i=>i.setValue(this.plugin.settings.showAllSpoilers).onChange(async s=>{this.plugin.settings.showAllSpoilers=s,this.app.workspace.containerEl.toggleClass("inline_spoilers-revealed",s),await this.plugin.saveSettings()})),new n.Setting(e).setName("Hide spoilers in editor view (experimental)").setDesc("Hide spoilers in the editor until your cursor is on the same line as the spoiler.").addToggle(i=>i.setValue(this.plugin.settings.enableEditorMode).onChange(async s=>{this.plugin.settings.enableEditorMode=s,s?O(this.app.workspace):b(this.app.workspace),await this.plugin.saveSettings()}))}},g=class extends n.Plugin{async onload(){await this.loadSettings();let e=this.app.workspace.containerEl.querySelector(".markdown-reading-view");e&&w(e,this),this.registerMarkdownPostProcessor(i=>{w(i,this)}),this.addCommand({id:"create-spoiler",name:"Create spoiler",editorCallback:i=>{let s=i.getSelection();i.replaceSelection(`||${s}||`)}}),this.registerEditorExtension(r),this.addSettingTab(new f(this.app,this))}onunload(){this.app.workspace.containerEl.classList.remove("inline_spoilers-revealed"),V(this.app.workspace),b(this.app.workspace)}async loadSettings(){this.settings=Object.assign({},W,await this.loadData()),this.app.workspace.containerEl.toggleClass("inline_spoilers-revealed",this.settings.showAllSpoilers),this.settings.enableEditorMode&&r.push(d)}async saveSettings(){await this.saveData(this.settings)}};

/* nosourcemap */