/* THIS IS A GENERATED/BUNDLED FILE BY ESBUILD if you want to view the source, please visit the github repository of this plugin */ var Z=Object.defineProperty;var Ke=Object.getOwnPropertyDescriptor;var Ve=Object.getOwnPropertyNames;var Je=Object.prototype.hasOwnProperty;var Ye=(t,e)=>{for(var n in e)Z(t,n,{get:e[n],enumerable:!0})},et=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of Ve(e))!Je.call(t,s)&&s!==n&&Z(t,s,{get:()=>e[s],enumerable:!(r=Ke(e,s))||r.enumerable});return t};var tt=t=>et(Z({},"__esModule",{value:!0}),t);var Mt={};Ye(Mt,{default:()=>_});module.exports=tt(Mt);var F=require("obsidian"),M=require("@codemirror/view"),Ze=require("@codemirror/language"),B=require("@codemirror/state");var L=require("@lezer/common"),p=require("@lezer/highlight"),z=class t{static create(e,n,r,s,i){let o=s+(s<<8)+e+(n<<4)|0;return new t(e,n,r,o,i,[],[])}constructor(e,n,r,s,i,o,a){this.type=e,this.value=n,this.from=r,this.hash=s,this.end=i,this.children=o,this.positions=a,this.hashProp=[[L.NodeProp.contextHash,s]]}addChild(e,n){e.prop(L.NodeProp.contextHash)!=this.hash&&(e=new L.Tree(e.type,e.children,e.positions,e.length,this.hashProp)),this.children.push(e),this.positions.push(n)}toTree(e,n=this.end){let r=this.children.length-1;return r>=0&&(n=Math.max(n,this.positions[r]+this.children[r].length+this.from)),new L.Tree(e.types[this.type],this.children,this.positions,n-this.from).balance({makeTree:(s,i,o)=>new L.Tree(L.NodeType.none,s,i,o,this.hashProp)})}},h;(function(t){t[t.Document=1]="Document",t[t.CodeBlock=2]="CodeBlock",t[t.FencedCode=3]="FencedCode",t[t.Blockquote=4]="Blockquote",t[t.HorizontalRule=5]="HorizontalRule",t[t.BulletList=6]="BulletList",t[t.OrderedList=7]="OrderedList",t[t.ListItem=8]="ListItem",t[t.ATXHeading1=9]="ATXHeading1",t[t.ATXHeading2=10]="ATXHeading2",t[t.ATXHeading3=11]="ATXHeading3",t[t.ATXHeading4=12]="ATXHeading4",t[t.ATXHeading5=13]="ATXHeading5",t[t.ATXHeading6=14]="ATXHeading6",t[t.SetextHeading1=15]="SetextHeading1",t[t.SetextHeading2=16]="SetextHeading2",t[t.HTMLBlock=17]="HTMLBlock",t[t.LinkReference=18]="LinkReference",t[t.Paragraph=19]="Paragraph",t[t.CommentBlock=20]="CommentBlock",t[t.ProcessingInstructionBlock=21]="ProcessingInstructionBlock",t[t.Escape=22]="Escape",t[t.Entity=23]="Entity",t[t.HardBreak=24]="HardBreak",t[t.Emphasis=25]="Emphasis",t[t.StrongEmphasis=26]="StrongEmphasis",t[t.Link=27]="Link",t[t.Image=28]="Image",t[t.InlineCode=29]="InlineCode",t[t.HTMLTag=30]="HTMLTag",t[t.Comment=31]="Comment",t[t.ProcessingInstruction=32]="ProcessingInstruction",t[t.Autolink=33]="Autolink",t[t.HeaderMark=34]="HeaderMark",t[t.QuoteMark=35]="QuoteMark",t[t.ListMark=36]="ListMark",t[t.LinkMark=37]="LinkMark",t[t.EmphasisMark=38]="EmphasisMark",t[t.CodeMark=39]="CodeMark",t[t.CodeText=40]="CodeText",t[t.CodeInfo=41]="CodeInfo",t[t.LinkTitle=42]="LinkTitle",t[t.LinkLabel=43]="LinkLabel",t[t.URL=44]="URL"})(h||(h={}));var W=class{constructor(e,n){this.start=e,this.content=n,this.marks=[],this.parsers=[]}},K=class{constructor(){this.text="",this.baseIndent=0,this.basePos=0,this.depth=0,this.markers=[],this.pos=0,this.indent=0,this.next=-1}forward(){this.basePos>this.pos&&this.forwardInner()}forwardInner(){let e=this.skipSpace(this.basePos);this.indent=this.countIndent(e,this.pos,this.indent),this.pos=e,this.next=e==this.text.length?-1:this.text.charCodeAt(e)}skipSpace(e){return N(this.text,e)}reset(e){for(this.text=e,this.baseIndent=this.basePos=this.pos=this.indent=0,this.forwardInner(),this.depth=1;this.markers.length;)this.markers.pop()}moveBase(e){this.basePos=e,this.baseIndent=this.countIndent(e,this.pos,this.indent)}moveBaseColumn(e){this.baseIndent=e,this.basePos=this.findColumn(e)}addMarker(e){this.markers.push(e)}countIndent(e,n=0,r=0){for(let s=n;s=e.stack[n.depth+1].value+n.baseIndent)return!0;if(n.indent>=n.baseIndent+4)return!1;let r=(t.type==h.OrderedList?ue:he)(n,e,!1);return r>0&&(t.type!=h.BulletList||le(n,e,!1)<0)&&n.text.charCodeAt(n.pos+r-1)==t.value}var Ee={[h.Blockquote](t,e,n){return n.next!=62?!1:(n.markers.push(k(h.QuoteMark,e.lineStart+n.pos,e.lineStart+n.pos+1)),n.moveBase(n.pos+(E(n.text.charCodeAt(n.pos+1))?2:1)),t.end=e.lineStart+n.text.length,!0)},[h.ListItem](t,e,n){return n.indent-1?!1:(n.moveBaseColumn(n.baseIndent+t.value),!0)},[h.OrderedList]:ke,[h.BulletList]:ke,[h.Document](){return!0}};function E(t){return t==32||t==9||t==10||t==13}function N(t,e=0){for(;en&&E(t.charCodeAt(e-1));)e--;return e}function Me(t){if(t.next!=96&&t.next!=126)return-1;let e=t.pos+1;for(;e-1&&t.depth==e.stack.length||r<3?-1:1}function xe(t,e){for(let n=t.stack.length-1;n>=0;n--)if(t.stack[n].type==e)return!0;return!1}function he(t,e,n){return(t.next==45||t.next==43||t.next==42)&&(t.pos==t.text.length-1||E(t.text.charCodeAt(t.pos+1)))&&(!n||xe(e,h.BulletList)||t.skipSpace(t.pos+2)=48&&s<=57;){r++;if(r==t.text.length)return-1;s=t.text.charCodeAt(r)}return r==t.pos||r>t.pos+9||s!=46&&s!=41||rt.pos+1||t.next!=49)?-1:r+1-t.pos}function Ae(t){if(t.next!=35)return-1;let e=t.pos+1;for(;e6?-1:n}function He(t){if(t.next!=45&&t.next!=61||t.indent>=t.baseIndent+4)return-1;let e=t.pos+1;for(;e/,ye=/\?>/,J=[[/^<(?:script|pre|style)(?:\s|>|$)/i,/<\/(?:script|pre|style)>/i],[/^\s*/i.exec(r);if(i)return t.append(k(h.Comment,n,n+1+i[0].length));let o=/^\?[^]*?\?>/.exec(r);if(o)return t.append(k(h.ProcessingInstruction,n,n+1+o[0].length));let a=/^(?:![A-Z][^]*?>|!\[CDATA\[[^]*?\]\]>|\/\s*[a-zA-Z][\w-]*\s*>|\s*[a-zA-Z][\w-]*(\s+[a-zA-Z:_][\w-.:]*(?:\s*=\s*(?:[^\s"'=<>`]+|'[^']*'|"[^"]*"))?)*\s*(\/\s*)?>)/.exec(r);return a?t.append(k(h.HTMLTag,n,n+1+a[0].length)):-1},Emphasis(t,e,n){if(e!=95&&e!=42)return-1;let r=n+1;for(;t.char(r)==e;)r++;let s=t.slice(n-1,n),i=t.slice(r,r+1),o=T.test(s),a=T.test(i),l=/\s|^$/.test(s),u=/\s|^$/.test(i),f=!u&&(!a||l||o),c=!l&&(!o||u||a),d=f&&(e==42||!c||o),g=c&&(e==42||!f||a);return t.append(new C(e==95?Te:De,n,r,(d?1:0)|(g?2:0)))},HardBreak(t,e,n){if(e==92&&t.char(n+1)==10)return t.append(k(h.HardBreak,n,n+2));if(e==32){let r=n+1;for(;t.char(r)==32;)r++;if(t.char(r)==10&&r>=n+2)return t.append(k(h.HardBreak,n,r+1))}return-1},Link(t,e,n){return e==91?t.append(new C(v,n,n+1,1)):-1},Image(t,e,n){return e==33&&t.char(n+1)==91?t.append(new C(we,n,n+2,1)):-1},LinkEnd(t,e,n){if(e!=93)return-1;for(let r=t.parts.length-1;r>=0;r--){let s=t.parts[r];if(s instanceof C&&(s.type==v||s.type==we)){if(!s.side||t.skipSpace(s.to)==n&&!/[(\[]/.test(t.slice(n+1,n+2)))return t.parts[r]=null,-1;let i=t.takeContent(r),o=t.parts[r]=it(t,i,s.type==v?h.Link:h.Image,s.from,n+1);if(s.type==v)for(let a=0;ae?k(h.URL,e+n,i+n):i==t.length?null:!1}}function ze(t,e,n){let r=t.charCodeAt(e);if(r!=39&&r!=34&&r!=40)return!1;let s=r==40?41:r;for(let i=e+1,o=!1;i=this.end?-1:this.text.charCodeAt(e-this.offset)}get end(){return this.offset+this.text.length}slice(e,n){return this.text.slice(e-this.offset,n-this.offset)}append(e){return this.parts.push(e),e.to}addDelimiter(e,n,r,s,i){return this.append(new C(e,n,r,(s?1:0)|(i?2:0)))}addElement(e){return this.append(e)}resolveMarkers(e){for(let r=e;r=e;l--){let m=this.parts[l];if(m instanceof C&&m.side&1&&m.type==s.type&&!(i&&(s.side&1||m.side&2)&&(m.to-m.from+o)%3==0&&((m.to-m.from)%3||o%3))){a=m;break}}if(!a)continue;let u=s.type.resolve,f=[],c=a.from,d=s.to;if(i){let m=Math.min(2,a.to-a.from,o);c=a.to-m,d=s.from+m,u=m==1?"Emphasis":"StrongEmphasis"}a.type.mark&&f.push(this.elt(a.type.mark,c,a.to));for(let m=l+1;m=0;n--){let r=this.parts[n];if(r instanceof C&&r.type==e)return n}return null}takeContent(e){let n=this.resolveMarkers(e);return this.parts.length=e,n}skipSpace(e){return N(this.text,e-this.offset)+this.offset}elt(e,n,r,s){return typeof e=="string"?k(this.parser.getNodeType(e),n,r,s):new $(e,n)}};function ie(t,e){if(!e.length)return t;if(!t.length)return e;let n=t.slice(),r=0;for(let s of e){for(;r(e?e-1:0))return!1;if(this.fragmentEnd<0){let i=this.fragment.to;for(;i>0&&this.input.read(i-1,i)!=` `;)i--;this.fragmentEnd=i?i-1:0}let r=this.cursor;r||(r=this.cursor=this.fragment.tree.cursor(),r.firstChild());let s=e+this.fragment.offset;for(;r.to<=s;)if(!r.parent())return!1;for(;;){if(r.from>=s)return this.fragment.from<=n;if(!r.childAfter(s))return!1}}matches(e){let n=this.cursor.tree;return n&&n.prop(L.NodeProp.contextHash)==e}takeNodes(e){let n=this.cursor,r=this.fragment.offset,s=this.fragmentEnd-(this.fragment.openEnd?1:0),i=e.absoluteLineStart,o=i,a=e.block.children.length,l=o,u=a;for(;;){if(n.to-r>s){if(n.type.isAnonymous&&n.firstChild())continue;break}let f=$e(n.from-r,e.ranges);if(n.to-r<=e.ranges[e.rangeI].to)e.addNode(n.tree,f);else{let c=new L.Tree(e.parser.nodeSet.types[h.Paragraph],[],[],0,e.block.hashProp);e.reusePlaceholders.set(c,n.tree),e.addNode(c,f)}if(n.type.is("Block")&&(at.indexOf(n.type.id)<0?(o=n.to-r,a=e.block.children.length):(o=l,a=u,l=n.to-r,u=e.block.children.length)),!n.nextSibling())break}for(;e.block.children.length>a;)e.block.children.pop(),e.block.positions.pop();return o-i}};function $e(t,e){let n=t;for(let r=1;rD[t]),Object.keys(D).map(t=>nt[t]),Object.keys(D),rt,Ee,Object.keys(Q).map(t=>Q[t]),Object.keys(Q),[]);var lt={resolve:"Strikethrough",mark:"StrikethroughMark"},xt={defineNodes:[{name:"Strikethrough",style:{"Strikethrough/...":p.tags.strikethrough}},{name:"StrikethroughMark",style:p.tags.processingInstruction}],parseInline:[{name:"Strikethrough",parse(t,e,n){if(e!=126||t.char(n+1)!=126||t.char(n+2)==126)return-1;let r=t.slice(n-1,n),s=t.slice(n+2,n+3),i=/\s|^$/.test(r),o=/\s|^$/.test(s),a=T.test(r),l=T.test(s);return t.addDelimiter(lt,n,n+2,!o&&(!l||i||a),!i&&(!a||o||l))},after:"Emphasis"}]};function P(t,e,n=0,r,s=0){let i=0,o=!0,a=-1,l=-1,u=!1,f=()=>{r.push(t.elt("TableCell",s+a,s+l,t.parser.parseInline(e.slice(a,l),s+a)))};for(let c=n;c-1)&&i++,o=!1,r&&(a>-1&&f(),r.push(t.elt("TableDelimiter",c+s,c+s+1))),a=l=-1):(u||d!=32&&d!=9)&&(a<0&&(a=c),l=c+1),u=!u&&d==92}return a>-1&&(i++,r&&f()),i}function Ce(t,e){for(let n=e;ns instanceof X)||!Ce(e.text,e.basePos))return!1;let r=t.scanLine(t.absoluteLineEnd+1).text;return qe.test(r)&&P(t,e.text,e.basePos)==P(t,r,e.basePos)},before:"SetextHeading"}]},oe=class{nextLine(){return!1}finish(e,n){return e.addLeafElement(n,e.elt("Task",n.start,n.start+n.content.length,[e.elt("TaskMarker",n.start,n.start+3),...e.parser.parseInline(n.content.slice(3),n.start+3)])),!0}},Ht={defineNodes:[{name:"Task",block:!0,style:p.tags.list},{name:"TaskMarker",style:p.tags.atom}],parseBlock:[{name:"TaskList",leaf(t,e){return/^\[[ xX]\][ \t]/.test(e.content)&&t.parentType().name=="ListItem"?new oe:null},after:"SetextHeading"}]};function _e(t,e,n){return(r,s,i)=>{if(s!=t||r.char(i+1)==t)return-1;let o=[r.elt(n,i,i+1)];for(let a=i+1;a0){l!==null?de(l)!==g&&(l=a.createEl("ul",{cls:`pf2e-statblock-indent-${g}`}),l.appendChild(u)):u.classList.add(`pf2e-statblock-indent-${g}`),f+=g-1;continue}if((u.className.includes("pf2e-statblock-indent")||l!==null&&l.className.includes("pf2e-statblock-indent"))&&c.nodeName==="#text"&&d.textContent.startsWith("- ")){u.tagName!=="LI"&&(l===null&&(l=a.createEl("ul",{cls:u.className}),u.replaceWith(l)),u=l.createEl("li"));let b=u.appendChild(c.cloneNode(!1));b.textContent=b.textContent.substring(2);continue}else if(u.tagName==="LI"){let b=a.createEl("p");l.removeChild(u),u=b,l.hasChildNodes()||a.removeChild(l),l=null;let m=0;for(let w=f-1;w>=0;w--){let S=o[w];if(o[w]instanceof Element&&S.classList.contains("pf2e-statblock-tab"))m++;else break}m>0&&u.classList.add(`pf2e-statblock-indent-${m}`)}u.tagName==="P"&&(c instanceof Element&&d.tagName==="STRONG"?u.classList.add("pf2e-statblock-subentry"):u.previousElementSibling!=null&&u.previousElementSibling.tagName==="P"&&!u.previousElementSibling.classList.contains("pf2e-statblock-subentry")&&de(u)===de(u.previousElementSibling)&&u.classList.add("pf2e-statblock-2nd-paragraph"))}else if(c instanceof Element&&d.tagName==="BR"){l===null?u=a.createEl("p"):u=l.createEl("li");continue}u.appendChild(c.cloneNode(!0))}}r.push(a)}for(let s=n.length-1;s>=0;s--)n[s].replaceWith(r[s])}var ce=class{constructor(){this.codeText="";this.locationInDoc=-1}},q=class{constructor(e,n,r){this.decor=r,this.start=e,this.end=n}},pe=/[!"#$%&'()*+,\-.\/:;<=>?@\[\\\]^_`{|}~\xA1\u2010-\u2027]/;try{pe=new RegExp("[\\p{Pc}|\\p{Pd}|\\p{Pe}|\\p{Pf}|\\p{Pi}|\\p{Po}|\\p{Ps}]\\p{Sm}","u")}catch{}var wt={resolve:"Highlight",mark:"HighlightMark"},St={defineNodes:[{name:"Highlight",style:{"Highlight/...":fe.tags.heading3}},{name:"HighlightMark",style:fe.tags.processingInstruction}],parseInline:[{name:"Highlight",parse(t,e,n){if(e!=61||t.char(n+1)!=61||t.char(n+2)==61)return-1;let r=t.slice(n-1,n),s=t.slice(n+2,n+3),i=/\s|^$/.test(r),o=/\s|^$/.test(s),a=pe.test(r),l=pe.test(s);return t.addDelimiter(wt,n,n+2,!o&&(!l||i||a),!i&&(!a||o||l))},before:"Emphasis"}]},Ct=Xe.configure(St),ge=class extends M.WidgetType{constructor(e){super(),this.actionText=e}toDOM(e){let n=document.createElement("span");return this.actionText==="[reaction]"||this.actionText==="[free-action]"||this.actionText=="[one-action]"||this.actionText==="[two-actions]"||this.actionText==="[three-actions]"?(n.innerText=this.actionText,n.className="pf2e-statblock-live-action"):(n.innerText="???",n.className="pf2e-statblock-live-error"),n}},Et=B.StateField.define({create(t){return M.Decoration.none},update(t,e){let n=!1,r=-1,s=new Array;(0,Ze.syntaxTree)(e.state).iterate({enter(a){if(a.type.name==="Document")return!0;let l=e.newDoc.sliceString(a.from,a.to);if(a.type.name.startsWith("HyperMD-codeblock_HyperMD-codeblock-begin_HyperMD-codeblock-begin-bg_HyperMD-codeblock-bg")){if(n)return!1;if(l==="```pf2e-stats"){n=!0,r=-1;let u=new ce;return s.push(u),!1}}if(!n)return!1;if(a.type.name.startsWith("HyperMD-codeblock_HyperMD-codeblock-bg_HyperMD-codeblock-end_HyperMD-codeblock-end-bg"))n=!1;else if(a.type.name.startsWith("hmd-codeblock")){let u="";s[s.length-1].locationInDoc<0?s[s.length-1].locationInDoc=a.from:r!==-1&&(u=` `.repeat(a.from-r)),s[s.length-1].codeText+=u+l,r=a.to}return n}});let i=new Array;for(let a of s){let l=a.locationInDoc,u=l+a.codeText.length;Ct.parse(a.codeText).iterate({enter(c){let d=l+c.from,g=l+c.to,b=!0,m=0,w="pf2e-statblock-live";switch(c.type.name){case"Document":return!0;case"ATXHeading1":{w+="-h1";break}case"ATXHeading2":{w+="-h2",b=!1;break}case"ATXHeading3":{w+="-h3",b=!1;break}case"Paragraph":{w+="-p",m=-1;break}case"Emphasis":{w+="-i",m=1;break}case"StrongEmphasis":{w+="-b",m=1;break}case"InlineCode":{if(w+="-actionSource",m=2,b=!1,c.to-c.from<4)return!1;let S=a.codeText.slice(c.from+1,c.to-1);i.push(new q(g,g,M.Decoration.widget({widget:new ge(S)})));break}case"Highlight":{w+="-mark",m=1,b=!1;let S=a.codeText.slice(c.from+2,c.to-2),I=Ge(S);w+=" "+I;break}case"ListItem":{w+="-li",m=-1;break}case"BulletList":{w+="-ul";break}case"OrderedList":{w+="-ol";break}default:return!1}try{let S=M.Decoration.mark({inclusiveStart:!0,class:w});S.startSide=m,i.push(new q(d,g,S))}catch{}return b}})}i.sort((a,l)=>a.startl.start?1:a.decor.startSide<=l.decor.startSide?-1:1);let o=new B.RangeSetBuilder;for(let a of i)o.add(a.start,a.end,a.decor);return o.finish()},provide(t){return M.EditorView.decorations.from(t)}}),_=class extends F.Plugin{async onload(){this.registerMarkdownCodeBlockProcessor("pf2e-stats",(e,n,r)=>{e=e.replaceAll(" ",'INDENTATION PROCESSING ERROR');let s=n.createEl("div",{cls:"pf2e-statblock"});F.MarkdownRenderer.render(this.app,e,s,r.sourcePath,this);let i=s.getElementsByTagName("mark");for(let o=0;o