@limetech/lime-elements 40.5.4 → 40.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/cjs/{index-ETPz91V5.js → index-zZvs6xK-.js} +9382 -9504
  3. package/dist/cjs/lime-elements.cjs.js +1 -1
  4. package/dist/cjs/limel-file-viewer.cjs.entry.js +1 -1
  5. package/dist/cjs/limel-markdown.cjs.entry.js +28 -4
  6. package/dist/cjs/limel-prosemirror-adapter.cjs.entry.js +2 -2
  7. package/dist/cjs/loader.cjs.js +1 -1
  8. package/dist/cjs/markdown-exporter-9p7d3Q76.js +6210 -0
  9. package/dist/cjs/{markdown-parser-YH5HSSgF.js → markdown-parser-Cgv5Y9Z4.js} +579 -848
  10. package/dist/collection/components/markdown/markdown-exporter.js +186 -0
  11. package/dist/collection/components/markdown/markdown-parser.js +2 -3
  12. package/dist/collection/components/markdown/markdown.js +54 -2
  13. package/dist/esm/{index-CbciMfiU.js → index-BN64nlbO.js} +9369 -9505
  14. package/dist/esm/lime-elements.js +1 -1
  15. package/dist/esm/limel-file-viewer.entry.js +1 -1
  16. package/dist/esm/limel-markdown.entry.js +28 -4
  17. package/dist/esm/limel-prosemirror-adapter.entry.js +2 -2
  18. package/dist/esm/loader.js +1 -1
  19. package/dist/esm/markdown-exporter--3_MaqwD.js +6208 -0
  20. package/dist/esm/{markdown-parser-DrxxGLF5.js → markdown-parser-DCf-3dKZ.js} +506 -791
  21. package/dist/lime-elements/lime-elements.esm.js +1 -1
  22. package/dist/lime-elements/{p-05afb316.entry.js → p-20658306.entry.js} +1 -1
  23. package/dist/lime-elements/p-BPzhuHcl.js +1 -0
  24. package/dist/lime-elements/p-CC4Usa-Q.js +7 -0
  25. package/dist/lime-elements/p-_UXAljNc.js +1 -0
  26. package/dist/lime-elements/p-dc9cd793.entry.js +1 -0
  27. package/dist/lime-elements/{p-10594468.entry.js → p-dd62042a.entry.js} +1 -1
  28. package/dist/types/components/markdown/markdown-exporter.d.ts +15 -0
  29. package/dist/types/components/markdown/markdown.d.ts +19 -0
  30. package/dist/types/components.d.ts +10 -0
  31. package/dist/types/global/shared-types/custom-element.types.d.ts +25 -0
  32. package/package.json +7 -1
  33. package/dist/lime-elements/p-6d5b23ad.entry.js +0 -1
  34. package/dist/lime-elements/p-C9xHOCE_.js +0 -7
  35. package/dist/lime-elements/p-DMNtoJ8I.js +0 -1
@@ -0,0 +1 @@
1
+ import{z as t,w as n,y as e,A as r,i as o,C as i,g as c,v as a,E as s,S as u,h as l,u as f}from"./p-_UXAljNc.js";import{a as d,b as p,h,c as m,f as g,d as b,e as y,i as v,j as k,k as w,p as x,l as C,n as S,t as B,r as A,o as E}from"./p-CC4Usa-Q.js";import"./p-B85MJLTf.js";const F={}.hasOwnProperty;function L(t,n){let e,r=-1;if(n.extensions)for(;++r<n.extensions.length;)L(t,n.extensions[r]);for(e in n)if(F.call(n,e))switch(e){case"extensions":break;case"unsafe":case"join":o=t[e],(i=n[e])&&o.push(...i);break;case"handlers":M(t[e],n[e]);break;default:t.options[e]=n[e]}var o,i;return t}function M(t,n){n&&Object.assign(t,n)}function j(t){if(60!==t.charCodeAt(0))return;const n=t.charCodeAt(1);if(33===n){const n=t.charCodeAt(2);return 45===n?2:91===n?5:d(n)?4:void 0}if(63===n)return 3;const e=47===n,r=e?2:1;let o=r,i=t.charCodeAt(o);if(!d(i))return;for(;45===i||p(i);)i=t.charCodeAt(++o);const c=t.slice(r,o).toLowerCase();return!e&&47!==i&&h.includes(c)?1:m.includes(c)?6:7}const z=[function(t,n,e,r){if("code"===n.type&&g(n,r)&&("list"===t.type||t.type===n.type&&g(t,r)))return!1;if("spread"in e&&"boolean"==typeof e.spread){if("paragraph"===t.type&&(t.type===n.type||"definition"===n.type||"heading"===n.type&&b(n,r)))return;if("html"===t.type){const n=j(t.value);if(void 0===n||6===n||7===n)return 1}if("paragraph"===t.type&&"html"===n.type){const t=j(n.value);if(void 0===t||7===t)return 1}return e.spread?1:0}}],T=["autolink","destinationLiteral","destinationRaw","reference","titleQuote","titleApostrophe"],I=[{character:"\t",after:"[\\r\\n]",inConstruct:"phrasing"},{character:"\t",before:"[\\r\\n]",inConstruct:"phrasing"},{character:"\t",inConstruct:["codeFencedLangGraveAccent","codeFencedLangTilde"]},{character:"\r",inConstruct:["codeFencedLangGraveAccent","codeFencedLangTilde","codeFencedMetaGraveAccent","codeFencedMetaTilde","destinationLiteral","headingAtx"]},{character:"\n",inConstruct:["codeFencedLangGraveAccent","codeFencedLangTilde","codeFencedMetaGraveAccent","codeFencedMetaTilde","destinationLiteral","headingAtx"]},{character:"\r",before:"[\\r\\n]",inConstruct:"phrasing"},{character:"\r",after:"\\r",inConstruct:"phrasing"},{character:"\n",before:"\\n",inConstruct:"phrasing"},{character:"\n",after:"[\\r\\n]",inConstruct:"phrasing"},{character:" ",after:"[\\r\\n]",inConstruct:"phrasing"},{character:" ",before:"[\\r\\n]",inConstruct:"phrasing"},{character:" ",inConstruct:["codeFencedLangGraveAccent","codeFencedLangTilde"]},{character:"!",after:"\\[",inConstruct:"phrasing",notInConstruct:T},{character:'"',inConstruct:"titleQuote"},{atBreak:!0,character:"#"},{character:"#",inConstruct:"headingAtx",after:"(?:[\r\n]|$)"},{character:"&",after:"[#A-Za-z]",inConstruct:"phrasing"},{character:"'",inConstruct:"titleApostrophe"},{character:"(",inConstruct:"destinationRaw"},{before:"\\]",character:"(",inConstruct:"phrasing",notInConstruct:T},{atBreak:!0,before:"\\d+",character:")"},{character:")",inConstruct:"destinationRaw"},{atBreak:!0,character:"*",after:"(?:[ \t\r\n*])"},{character:"*",inConstruct:"phrasing",notInConstruct:T},{atBreak:!0,character:"+",after:"(?:[ \t\r\n])"},{atBreak:!0,character:"-",after:"(?:[ \t\r\n-])"},{atBreak:!0,before:"\\d+",character:".",after:"(?:[ \t\r\n]|$)"},{atBreak:!0,character:"<",after:"[!/?A-Za-z]"},{character:"<",after:"[!/?A-Za-z]",inConstruct:"phrasing",notInConstruct:T},{character:"<",inConstruct:"destinationLiteral"},{atBreak:!0,character:"="},{atBreak:!0,character:">"},{character:">",inConstruct:"destinationLiteral"},{atBreak:!0,character:"["},{character:"[",inConstruct:"phrasing",notInConstruct:T},{character:"[",inConstruct:["label","reference"]},{character:"\\",after:"[\\r\\n]",inConstruct:"phrasing"},{character:"]",inConstruct:["label","reference"]},{atBreak:!0,character:"_"},{character:"_",inConstruct:"phrasing",notInConstruct:T},{atBreak:!0,character:"`"},{character:"`",inConstruct:["codeFencedLangGraveAccent","codeFencedMetaGraveAccent"]},{character:"`",inConstruct:"phrasing",notInConstruct:T},{atBreak:!0,character:"~"},{character:"<",inConstruct:"autolink"},{character:">",inConstruct:"autolink"},{character:"",inConstruct:"autolink"}];let N=-1;for(;++N<33;)I.push({character:String.fromCharCode(N),inConstruct:"autolink"});function R(t){return t.label||!t.identifier?t.label||"":y(t.identifier)}function q(t){if(!t._compiled){const n=(t.atBreak?"[\\r\\n][\\t ]*":"")+(t.before?"(?:"+t.before+")":"");t._compiled=new RegExp((n?"("+n+")":"")+(/[$()*+\-.?[\\\]^{|}]/.test(t.character)?"\\":"")+t.character+(t.after?"(?:"+t.after+")":""),"g")}return t._compiled}function _(t){const n=t.codePointAt(0);return void 0===n?"":String.fromCodePoint(n)}function G(t){const n=t.codePointAt(t.length-2);return t.slice(void 0!==n&&n>65535?-2:-1)}function U(t,n,e){const r=v(t),o=v(n);return void 0===r?void 0===o?"_"===e?{inside:!0,outside:!0}:{inside:!1,outside:!1}:1===o?{inside:!0,outside:!0}:{inside:!1,outside:!0}:1===r?void 0===o?{inside:!1,outside:!1}:1===o?{inside:!0,outside:!0}:{inside:!1,outside:!1}:void 0===o?{inside:!1,outside:!1}:1===o?{inside:!0,outside:!1}:{inside:!1,outside:!1}}const $=new Map([["*",!1],["_",!0]]);function P(t,n,e){const r=new Set;for(const o of t){const t=e.get(o);if(t&&o.attention&&n.some((t=>t.attention===o.attention)))for(const n of t.tokens)r.add(n.attention)}const o=[];for(const n of t)n.attention&&r.delete(n.attention)&&o.push(n.attention);return o.reverse(),o}function Q(t,n,e){const r=[],o=new Map,i=new Map;let c=0;for(;c<t.length;){if(!t[c].attention){c++;continue}const a=t[c].value.charAt(0),s=$.get(a);let u=c+1;for(;u<t.length&&t[u].attention&&t[u].value.charAt(0)===a;)u++;const l=c?t[c-1].value:n,f=v(l.charCodeAt(l.length-1)),d=v((u<t.length?t[u].value:e).charCodeAt(0)),p=!d||2===d&&Boolean(f),h=!f||2===f&&Boolean(d),m={tokens:t.slice(c,u),markers:[],start:0,end:0,open:s?p&&(Boolean(f)||!h):p,close:s?h&&(Boolean(d)||!p):h,split:void 0!==s};for(const t of m.tokens){o.set(t,[...m.tokens]),i.set(t,m);let n=t.value.length;for(;n--;)m.markers.push(t)}m.end=m.markers.length,r.push(m),c=u}for(function(t,n){let e=0;for(;e<t.length;){const r=t[e],o=r.tokens[0].value.charAt(0),i=r.end-r.start;let c=r.close&&i?e:0;for(;c--;){const e=t[c],a=e.end-e.start;if(e.tokens[0].value.charAt(0)===o&&e.open&&a&&(r.split?!((e.close||r.open)&&i%3)||(a+i)%3:a===e.markers.length&&a===i)){const t=r.split?a>1&&i>1?2:1:i,o=e.markers.slice(e.end-t,e.end),c=r.markers.slice(r.start,r.start+t),s=o[0],u=c[0];if(s===o[t-1]&&s.value.length===t&&u===c[t-1]&&u.value.length===t&&s.attention===u.attention)n.delete(s),n.delete(u);else{const t=[...new Set([...o,...c])];for(const e of t){const r=n.get(e);r&&r.push(...t)}}e.end-=t,r.start+=t;break}}-1!==c&&r.start!==r.end||e++}}(r,o),c=-1;++c<t.length;){const n=o.get(t[c]);if(n)return{attention:P(t,n,i),index:c}}}function Z(t,n,e){return K(J(t,n,e),e.before,e.after)}function O(t,n){const e=t[n?0:t.length-1];if(!e||e.attention)return;const r=n?_(e.value):G(e.value),o=w(r.codePointAt(0));e.value=n?o+e.value.slice(r.length):e.value.slice(0,e.value.length-r.length)+o}function D(t,n,e,r,o){for(const i of e.attention){const c=n.get(i)||i.sequences[0];for(const a of i.sequences){if(a===c)continue;const s=new Map(n);s.set(i,a);const u=X(t,s,r,o),l=Q(u,r,o);if(!l||l.index>e.index)return{chosen:s,mistake:l,tokens:u}}}}function H(t,n,e){if(0===n.length)throw new Error("Cannot serialize `"+t+"` as attention without markers, expected one or more markers");if(0===e.length)throw new Error("Cannot serialize `"+t+"` as attention without sizes, expected one or more sizes");for(const n of e)if(!Number.isSafeInteger(n)||n<1)throw new Error("Cannot serialize `"+t+"` as attention with `"+n+"` as size, expected positive integer");const r=[];for(const o of n){if(1!==o.length)throw new Error("Cannot serialize `"+t+"` as attention with `"+o+"` as marker, expected a single ascii character");if(!k(o.charCodeAt(0)))throw new Error("Cannot serialize `"+t+"` as attention with `"+o+"` as marker, expected ascii punctuation");for(const t of e)r.push(o.repeat(t))}return r}function J(t,n,e){const r=n.indexStack,o=t.children||[],i=[];let c=-1,a=e.before;r.push(-1);let s=n.createTracker(e);for(;++c<o.length;){const u=o[c];let l;if(r[r.length-1]=c,c+1<o.length){let e=n.handle.handlers[o[c+1].type];e&&e.peek&&(e=e.peek),l=e?_(e(o[c+1],t,n,{before:"",after:"",...s.current()})):""}else l=e.after;const f=i[i.length-1];"string"!=typeof f||"\r"!==a&&"\n"!==a||"html"!==u.type||7===j(u.value)||(i[i.length-1]=f.replace(/(\r?\n|\r)$/," "),a=" ",s=n.createTracker(e),s.move(K(i,e.before,e.after)));const d=n.handle.handlers[u.type];if(d&&d.attention){const{construct:t,markers:e,sizes:r}=d.attention(u,n),o=H(u.type,e,r),c=o[0],l=n.enter(t);s.move(c);const f=J(u,n,{...s.current(),before:c,after:c});s.move(K(f,c,c)),s.move(c),l(),i.push({children:f,sequences:o}),a=c.charAt(c.length-1)}else{const e=n.handle(u,t,n,{...s.current(),after:l,before:a});if(!e)continue;s.move(e),i.push(e),a=G(e)}}return r.pop(),i}function X(t,n,e,r){const o=[];let i,c=G(e),a=-1;for(;++a<t.length;){const e=t[a];if("string"==typeof e){const t={value:e,attention:void 0};i&&i===_(e)&&O([t],!0),i=void 0,o.push(t),t.value&&(c=G(t.value));continue}const s=n.get(e)||e.sequences[0],u=s.charAt(0),l=t[a+1],f=c,d=_(void 0===l?r:"string"==typeof l?l:n.get(l)||l.sequences[0]),p=X(e.children,n,s,s),h=p.length>0?p[0].value:"",m=U(f.charCodeAt(f.length-1),h.charCodeAt(0),u);m.inside&&O(p,!0);const g=p.length>0?G(p[p.length-1].value):"",b=U(d.charCodeAt(0),g.charCodeAt(g.length-1),u);b.inside&&O(p,!1),m.outside&&"\n"!==f&&"\r"!==f&&O(o,!1),b.outside&&(i=d),o.push({value:s,attention:e},...p,{value:s,attention:e}),c=s.charAt(s.length-1)}return o}function K(t,n,e){let r=new Map;const o=X(t,r,n,e);let i=o,c=Q(i,n,e);for(;c;){const a=D(t,r,c,n,e);if(!a){i=o;break}r=a.chosen,i=a.tokens,c=a.mistake}let a="";for(const t of i)a+=t.value;return a}function V(t,n,e,r){let o=r.join.length;for(;o--;){const i=r.join[o](t,n,e,r);if(!0===i||1===i)break;if("number"==typeof i)return"\n".repeat(1+i);if(!1===i)return"\n\n\x3c!----\x3e\n\n"}return"\n\n"}const W=/\r?\n|\r/g;function Y(t,n){const e=[];let r,o=0,i=0;for(;r=W.exec(t);)c(t.slice(o,r.index)),e.push(r[0]),o=r.index+r[0].length,i++;return c(t.slice(o)),e.join("");function c(t){e.push(n(t,i,!t))}}const tt={}.hasOwnProperty;function nt(t,n){return t-n}function et(t,n){const e=/\\(?=[!-/:-@[-`{-~])/g,r=[],o=[],i=t+n;let c,a=-1,s=0;for(;c=e.exec(i);)r.push(c.index);for(;++a<r.length;)s!==r[a]&&o.push(t.slice(s,r[a])),o.push("\\"),s=r[a];return o.push(t.slice(s)),o.join("")}function rt(t){const n=t||{},e=n.now||{};let r=n.lineShift||0,o=e.line||1,i=e.column||1;return{move:function(t){const n=t||"",e=n.split(/\r?\n|\r/g),c=e[e.length-1];return o+=e.length-1,i=1===e.length?i+c.length:1+c.length+r,n},current:function(){return{now:{line:o,column:i},lineShift:r}},shift:function(t){r+=t}}}function ot(n,e){const r=e||{},o={associationId:R,bulletCurrent:void 0,bulletLastUsed:void 0,containerPhrasing:st,containerFlow:ut,createTracker:rt,compilePattern:q,enter:function(t){return o.stack.push(t),function(){o.stack.pop()}},handlers:{...C},handle:void 0,indentLines:Y,indexStack:[],join:[...z],options:{},safe:lt,stack:[],unsafe:[...I]};L(o,r),o.options.tightDefinitions&&o.join.push(at),o.handle=t("type",{invalid:it,unknown:ct,handlers:o.handlers});let i=o.handle(S(n)?{type:"root",children:[n]}:n,void 0,o,{before:"\n",after:"\n",now:{line:1,column:1},lineShift:0});return i&&10!==i.charCodeAt(i.length-1)&&13!==i.charCodeAt(i.length-1)&&(i+="\n"),i}function it(t){throw new Error("Cannot handle value `"+t+"`, expected node")}function ct(t){throw new Error("Cannot handle unknown node `"+t.type+"`")}function at(t,n){if("definition"===t.type&&t.type===n.type)return 0}function st(t,n){return Z(t,this,n)}function ut(t,n){return function(t,n,e){const r=n.indexStack,o=t.children||[],i=n.createTracker(e),c=[];let a=-1;for(r.push(-1);++a<o.length;){const e=o[a];r[r.length-1]=a,c.push(i.move(n.handle(e,t,n,{before:"\n",after:"\n",...i.current()}))),"list"!==e.type&&(n.bulletLastUsed=void 0),a<o.length-1&&c.push(i.move(V(e,o[a+1],t,n)))}return r.pop(),c.join("")}(t,this,n)}function lt(t,n){return function(t,n,e){const r=(e.before||"")+(n||"")+(e.after||""),o=[],i=[],c={},a=t.stack.includes("autolink");let s=-1;for(;++s<t.unsafe.length;){const n=t.unsafe[s];if(!x(t.stack,n))continue;const e=t.compilePattern(n);let i;for(;i=e.exec(r);){const t="before"in n||Boolean(n.atBreak),e="after"in n,r=i.index+(t?i[1].length:0);tt.call(c,r)?(c[r].before&&!t&&(c[r].before=!1),c[r].after&&!e&&(c[r].after=!1)):(o.push(r),c[r]={before:t,after:e})}}o.sort(nt);const u=e.before?e.before.length:0,l=r.length-(e.after?e.after.length:0);let f=u;for(s=-1;++s<o.length;){const t=o[s];if(!(t<f||t>=l)){if("_"===r.charAt(t)&&t>0&&void 0===v(r.charCodeAt(t-1))&&!tt.call(c,t-1)&&(t-1!==u||!/[*_]/.test(r.charAt(u-1)))){let n=t+1;for(;n<l&&"_"===r.charAt(n);)n++;const e=n-t-1;if(o[s+e]===n-1&&n<r.length&&void 0===v(r.charCodeAt(n))&&!tt.call(c,n)&&(n!==l-1||!/[*_]/.test(r.charAt(l)))){s+=e;continue}}if(!(t+1<l&&o[s+1]===t+1&&c[t].after&&!c[t+1].before&&!c[t+1].after||o[s-1]===t-1&&c[t].before&&!c[t-1].before&&!c[t-1].after)){if(f!==t){const n=r.slice(f,t);i.push(a?n:et(n,"\\"))}f=t,a?(i.push("%"+r.charCodeAt(t).toString(16).toUpperCase().padStart(2,"0")),f++):!/[!-/:-@[-`{-~]/.test(r.charAt(t))||e.encode&&e.encode.includes(r.charAt(t))?(i.push(w(r.charCodeAt(t))),f++):i.push("\\")}}}const d=r.slice(f,l);return i.push(a?d:et(d,e.after)),i.join("")}(this,t,n)}function ft(t,o){const i=function(t,o){switch(t.nodeType){case 1:return function(t,o){const i=t.namespaceURI,c=i===n.svg?e:r,a=i===n.html?t.tagName.toLowerCase():t.tagName,s=i===n.html&&"template"===a?t.content:t,u=t.getAttributeNames(),l={};let f=-1;for(;++f<u.length;)l[u[f]]=t.getAttribute(u[f])||"";return c(a,l,pt(s,o))}(t,o);case 3:return function(t){return{type:"text",value:t.nodeValue||""}}(t);case 8:return function(t){return{type:"comment",value:t.nodeValue||""}}(t);case 9:case 11:return dt(t,o);case 10:return{type:"doctype"};default:return}}(t,o);return i&&o.afterTransform&&o.afterTransform(t,i),i}function dt(t,n){return{type:"root",children:pt(t,n)}}function pt(t,n){const e=t.childNodes,r=[];let o=-1;for(;++o<e.length;){const t=ft(e[o],n);void 0!==t&&r.push(t)}return r}const ht=function(t,n,e,r,o){const i=mt(n);return!!yt(t)&&i.call(o,t,e,r)},mt=function(t){if(null==t)return bt;if("string"==typeof t)return function(t){return gt((function(n){return n.tagName===t}))}(t);if("object"==typeof t)return function(t){const n=[];let e=-1;for(;++e<t.length;)n[e]=mt(t[e]);return gt((function(...t){let e=-1;for(;++e<n.length;)if(n[e].apply(this,t))return!0;return!1}))}(t);if("function"==typeof t)return gt(t);throw new Error("Expected function, string, or array as `test`")};function gt(t){return function(n,e,r){return Boolean(yt(n)&&t.call(this,n,"number"==typeof e?e:void 0,r||void 0))}}function bt(t){return Boolean(t&&"object"==typeof t&&"type"in t&&"element"===t.type&&"tagName"in t&&"string"==typeof t.tagName)}function yt(t){return null!==t&&"object"==typeof t&&"type"in t&&"tagName"in t}const vt=mt((function(t){return"audio"===t.tagName||"canvas"===t.tagName||"embed"===t.tagName||"iframe"===t.tagName||"img"===t.tagName||"math"===t.tagName||"object"===t.tagName||"picture"===t.tagName||"svg"===t.tagName||"video"===t.tagName})),kt=["address","article","aside","blockquote","body","br","caption","center","col","colgroup","dd","dialog","dir","div","dl","dt","figcaption","figure","footer","form","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","legend","li","li","listing","main","menu","nav","ol","optgroup","option","p","plaintext","pre","section","summary","table","tbody","td","td","tfoot","th","th","thead","tr","ul","wbr","xmp"],wt=["button","input","select","textarea"],xt=["area","base","basefont","dialog","datalist","head","link","meta","noembed","noframes","param","rp","script","source","style","template","track","title"],Ct={},St=o(["comment","doctype"]);function Bt(t,n){if("children"in t){const e={...n};return("root"===t.type||Lt(t))&&(e.before=!0,e.after=!0),e.whitespace=function(t,n){if("tagName"in t&&t.properties)switch(t.tagName){case"listing":case"plaintext":case"script":case"style":case"xmp":return"pre";case"nobr":return"nowrap";case"pre":return t.properties.wrap?"pre-wrap":"pre";case"td":case"th":return t.properties.noWrap?"nowrap":n.whitespace;case"textarea":return"pre-wrap"}return n.whitespace}(t,n),function(t,n){let e=n.before;const r=n.after,o=t.children;let i=o.length,c=-1;for(;++c<i;){const t=Bt(o[c],{...n,after:At(o,c,r),before:e});t.remove?(o.splice(c,1),c--,i--):t.ignore||(e=t.stripAtStart),Ft(o[c])&&(e=!1)}return{ignore:!1,stripAtStart:Boolean(e||r),remove:!1}}(t,e)}if("text"===t.type){if("normal"===n.whitespace)return function(t,n){const e=n.collapse(t.value),r={ignore:!1,stripAtStart:!1,remove:!1};let o=0,i=e.length;return n.before&&jt(e.charAt(0))&&o++,o!==i&&jt(e.charAt(i-1))&&(n.after?i--:r.stripAtStart=!0),o===i?r.remove=!0:t.value=e.slice(o,i),r}(t,n);"nowrap"===n.whitespace&&(t.value=n.collapse(t.value))}return{ignore:St(t),stripAtStart:!1,remove:!1}}function At(t,n,e){for(;++n<t.length;){const e=t[n];let r=Et(e);if(void 0===r&&"children"in e&&!Mt(e)&&(r=At(e.children,-1)),"boolean"==typeof r)return r}return e}function Et(t){if("element"===t.type){if(Ft(t))return!1;if(Lt(t))return!0}else if("text"===t.type){if(!i(t))return!1}else if(!St(t))return!1}function Ft(t){return vt(t)||ht(t,wt)}function Lt(t){return ht(t,kt)}function Mt(t){return Boolean("element"===t.type&&t.properties.hidden)||St(t)||ht(t,xt)}function jt(t){return" "===t||"\n"===t}function zt(t){const n=/\r?\n|\r/.exec(t);return n?n[0]:" "}function Tt(){return" "}function It(t){return function(n){!function(t,n){var e;Bt(t,{collapse:(e=(n||Ct).newlines?zt:Tt,function(t){return String(t).replace(/[\t\n\v\f\r ]+/g,e)}),whitespace:"normal"})}(n,t)}}const Nt=function(t,n,e){const r=o(e);if(!t||!t.type||!t.children)throw new Error("Expected parent node");if("number"==typeof n){if(n<0||n===Number.POSITIVE_INFINITY)throw new Error("Expected positive finite number as index")}else if((n=t.children.indexOf(n))<0)throw new Error("Expected child node or index");for(;++n<t.children.length;)if(r(t.children[n],n,t))return t.children[n]},Rt=/\n/g,qt=/[\t ]+/g,_t=mt("br"),Gt=mt((function(t){return"td"===t.tagName||"th"===t.tagName})),Ut=mt("p"),$t=mt("tr"),Pt=mt(["datalist","head","noembed","noframes","noscript","rp","script","style","template","title",function(t){return Boolean((t.properties||{}).hidden)},function(t){return"dialog"===t.tagName&&!(t.properties||{}).open}]),Qt=mt(["address","article","aside","blockquote","body","caption","center","dd","dialog","dir","dl","dt","div","figure","figcaption","footer","form,","h1","h2","h3","h4","h5","h6","header","hgroup","hr","html","legend","li","listing","main","menu","nav","ol","p","plaintext","pre","section","ul","xmp"]);function Zt(t){const n="children"in t?t.children:[],e=Qt(t),r=Jt(t,{whitespace:{}.whitespace||"normal"}),o=[];"text"!==t.type&&"comment"!==t.type||o.push(...Dt(t,{breakBefore:!0,breakAfter:!0}));let i=-1;for(;++i<n.length;)o.push(...Ot(n[i],t,{whitespace:r,breakBefore:i?void 0:e,breakAfter:i<n.length-1?_t(n[i+1]):e}));const c=[];let a;for(i=-1;++i<o.length;){const t=o[i];"number"==typeof t?void 0!==a&&t>a&&(a=t):t&&(void 0!==a&&a>-1&&c.push("\n".repeat(a)||" "),a=-1,c.push(t))}return c.join("")}function Ot(t,n,e){return"element"===t.type?function(t,n,e){const r=Jt(t,e),o=t.children||[];let i,c,a=-1,s=[];if(Pt(t))return s;for(_t(t)||$t(t)&&Nt(n,t,$t)?c="\n":Ut(t)?(i=2,c=2):Qt(t)&&(i=1,c=1);++a<o.length;)s=s.concat(Ot(o[a],t,{whitespace:r,breakBefore:a?void 0:i,breakAfter:a<o.length-1?_t(o[a+1]):c}));return Gt(t)&&Nt(n,t,Gt)&&s.push("\t"),i&&s.unshift(i),c&&s.push(c),s}(t,n,e):"text"===t.type?"normal"===e.whitespace?Dt(t,e):function(t){return[String(t.value)]}(t):[]}function Dt(t,n){const e=String(t.value),r=[],o=[];let i=0;for(;i<=e.length;){Rt.lastIndex=i;const t=Rt.exec(e),o=t&&"index"in t?t.index:e.length;r.push(Ht(e.slice(i,o).replace(/[\u061C\u200E\u200F\u202A-\u202E\u2066-\u2069]/g,""),0!==i||n.breakBefore,o!==e.length||n.breakAfter)),i=o+1}let c,a=-1;for(;++a<r.length;)8203===r[a].charCodeAt(r[a].length-1)||a<r.length-1&&8203===r[a+1].charCodeAt(0)?(o.push(r[a]),c=void 0):r[a]?("number"==typeof c&&o.push(c),o.push(r[a]),c=0):0!==a&&a!==r.length-1||o.push(0);return o}function Ht(t,n,e){const r=[];let o,i=0;for(;i<t.length;){qt.lastIndex=i;const e=qt.exec(t);o=e?e.index:t.length,i||o||!e||n||r.push(""),i!==o&&r.push(t.slice(i,o)),i=e?o+e[0].length:o}return i===o||e||r.push(""),r.join(" ")}function Jt(t,n){if("element"===t.type){const e=t.properties||{};switch(t.tagName){case"listing":case"plaintext":case"xmp":return"pre";case"nobr":return"nowrap";case"pre":return e.wrap?"pre-wrap":"pre";case"td":case"th":return e.noWrap?"nowrap":n.whitespace;case"textarea":return"pre-wrap"}}return n.whitespace}function Xt(t){const n=String(t);let e=n.length;for(;e>0;){const t=n.codePointAt(e-1);if(void 0===t||10!==t&&13!==t)break;e--}return n.slice(0,e)}function Kt(t,n){const e=n.children;let r,o,i=-1;if("pre"===n.tagName)for(;++i<e.length;){const t=e[i];if("element"===t.type&&"code"===t.tagName&&t.properties&&t.properties.className&&Array.isArray(t.properties.className)){r=t.properties.className;break}}if(r)for(i=-1;++i<r.length;)if("language-"===String(r[i]).slice(0,9)){o=String(r[i]).slice(9);break}const c={type:"code",lang:o||null,meta:null,value:Xt(Zt(n))};return t.patch(n,c),c}function Vt(t,n){const e={type:"delete",children:t.all(n)};return t.patch(n,e),e}function Wt(t){let n=-1;if(t.length>1)for(;++n<t.length;)if(t[n].spread)return!0;return!1}function Yt(t,n){const e=t.all({type:"root",children:n}),r=t.toSpecificContent(e,tn);return 0===r.length?[]:1===r.length?r[0].children:[{type:"list",ordered:!1,start:null,spread:Wt(r),children:r}]}function tn(){return{type:"listItem",spread:!1,checked:null,children:[]}}function nn(t,n){const e={type:"emphasis",children:t.all(n)};return t.patch(n,e),e}function en(t){let n=0,e=t.length;for(;n<e&&"break"===t[n].type;)n++;for(;e>n&&"break"===t[e-1].type;)e--;return 0===n&&e===t.length?t:t.slice(n,e)}function rn(t,n){const e={type:"heading",depth:Number(n.tagName.charAt(1))||1,children:en(t.all(n))};return t.patch(n,e),e}function on(t,n){const e=n.properties||{},r={type:"image",url:t.resolve(String(e.src||"")||null),title:e.title?String(e.title):null,alt:e.alt?String(e.alt):""};return t.patch(n,r),r}function cn(t,n){const e={type:"inlineCode",value:Zt(n)};return t.patch(n,e),e}function an(t,n){const e=[],r=[],o=n||t.properties||{},i=sn(t),c=Math.min(Number.parseInt(String(o.size),10),0)||(o.multiple?4:1);let a=-1;for(;++a<i.length;){const t=i[a];t&&t.properties&&t.properties.selected&&e.push(t)}const s=e.length>0?e:i,u=Math.min(s.length,c);for(a=-1;++a<u;){const t=s[a],n=t.properties||{},e=Zt(t),o=e||String(n.label||""),i=String(n.value||"")||e;r.push([i,o===i?void 0:o])}return r}function sn(t){const n=[];let e=-1;for(;++e<t.children.length;){const r=t.children[e];"children"in r&&Array.isArray(r.children)&&n.push(...sn(r)),"element"!==r.type||"option"!==r.tagName||r.properties&&r.properties.disabled||n.push(r)}return n}const un={}.hasOwnProperty,ln=new Set(["pingback","prefetch","stylesheet"]),fn=mt(["a","abbr","area","b","bdi","bdo","br","button","cite","code","data","datalist","del","dfn","em","i","input","ins","kbd","keygen","label","map","mark","meter","noscript","output","progress","q","ruby","s","samp","script","select","small","span","strong","sub","sup","template","textarea","time","u","var","wbr"]),dn=mt("meta");function pn(t){return Boolean("text"===t.type||fn(t)||vt(t)||function(t){if("element"!==t.type||"link"!==t.tagName)return!1;if(t.properties.itemProp)return!0;const n=t.properties.rel;let e=-1;if(!Array.isArray(n)||0===n.length)return!1;for(;++e<n.length;)if(!ln.has(String(n[e])))return!1;return!0}(t)||dn(t)&&function(t,n){const e="element"===t.type&&un.call(t.properties,n)&&t.properties[n];return null!=e&&!1!==e}(t,"itemProp"))}function hn(t,n){const{rest:e,checkbox:r}=gn(n),o=r?Boolean(r.properties.checked):null,i={type:"listItem",spread:mn(e),checked:o,children:t.toFlow(t.all(e))};return t.patch(n,i),i}function mn(t){let n=-1,e=!1;for(;++n<t.children.length;){const r=t.children[n];if("element"===r.type){if(pn(r))continue;if("p"===r.tagName||e||mn(r))return!0;e=!0}}return!1}function gn(t){const n=t.children[0];if(n&&"element"===n.type&&"input"===n.tagName&&n.properties&&("checkbox"===n.properties.type||"radio"===n.properties.type))return{checkbox:n,rest:{...t,children:t.children.slice(1)}};if(n&&"element"===n.type&&"p"===n.tagName){const{checkbox:e,rest:r}=gn(n);if(e)return{checkbox:e,rest:{...t,children:[r,...t.children.slice(1)]}}}return{checkbox:void 0,rest:t}}function bn(t,n){const e="ol"===n.tagName,r=t.toSpecificContent(t.all(n),yn);let o=null;e&&(o=n.properties&&n.properties.start?Number.parseInt(String(n.properties.start),10):1);const i={type:"list",ordered:e,start:o,spread:Wt(r),children:r};return t.patch(n,i),i}function yn(){return{type:"listItem",spread:!1,checked:null,children:[]}}function vn(t){let n=-1;for(;++n<t.length;){const e=t[n];if(!Cn(e)||"children"in e&&vn(e.children))return!0}return!1}function kn(t){return xn(t,(function(t){return t.every((function(t){return"text"===t.type&&i(t.value)}))?[]:[{type:"paragraph",children:en(t)}]}),(function(t){return t}))}function wn(t){return xn(t.children,(function(n){const e=Sn(t);return e.children=n,[e]}),(function(n){if("children"in n&&"children"in t){const e=Sn(t),r=Sn(n);return e.children=n.children,r.children.push(e),r}return{...n}}))}function xn(t,n,e){const r=function(t){const n=[];let e=-1;for(;++e<t.length;){const r=t[e];"delete"!==r.type&&"link"!==r.type||!vn(r.children)?n.push(r):n.push(...wn(r))}return n}(t),o=[];let i=[],c=-1;for(;++c<r.length;){const t=r[c];Cn(t)?i.push(t):(i.length>0&&(o.push(...n(i)),i=[]),o.push(e(t)))}return i.length>0&&(o.push(...n(i)),i=[]),o}function Cn(t){const n=t.data&&t.data.hName;return n?pn({type:"element",tagName:n,properties:{},children:[]}):S(t)}function Sn(t){return c({...t,children:[]})}function Bn(t,n){const e=n.properties||{},r="video"===n.tagName?String(e.poster||""):"";let o=String(e.src||""),i=-1,c=!1,u=t.all(n);if(a({type:"root",children:u},(function(t){if("link"===t.type)return c=!0,s})),c||vn(u))return u;for(;!o&&++i<n.children.length;){const t=n.children[i];"element"===t.type&&"source"===t.tagName&&t.properties&&(o=String(t.properties.src||""))}if(r){const e={type:"image",title:null,url:t.resolve(r),alt:B(u)};t.patch(n,e),u=[e]}const l=u,f={type:"link",title:e.title?String(e.title):null,url:t.resolve(o),children:l};return t.patch(n,f),f}function An(t,n){const e=en(t.all(n));if(e.length>0){const r={type:"paragraph",children:e};return t.patch(n,r),r}}const En=['"'];function Fn(t,n){const e={type:"strong",children:t.all(n)};return t.patch(n,e),e}function Ln(t,n){const e={type:"tableCell",children:t.all(n)};if(t.patch(n,e),n.properties){const t=n.properties.rowSpan,r=n.properties.colSpan;if(t||r){const n=e.data||(e.data={});t&&(n.hastUtilToMdastTemporaryRowSpan=t),r&&(n.hastUtilToMdastTemporaryColSpan=r)}}return e}function Mn(){return{type:"tableCell",children:[]}}function jn(){return{type:"tableCell",children:[]}}function zn(){return{type:"tableRow",children:[]}}const Tn={comment:function(t,n){const e={type:"html",value:"\x3c!--"+n.value+"--\x3e"};return t.patch(n,e),e},doctype:qn,root:function(t,n){let e=t.all(n);(t.options.document||vn(e))&&(e=kn(e));const r={type:"root",children:e};return t.patch(n,r),r},text:function(t,n){const e={type:"text",value:n.value};return t.patch(n,e),e}},In={applet:qn,area:qn,basefont:qn,bgsound:qn,caption:qn,col:qn,colgroup:qn,command:qn,content:qn,datalist:qn,dialog:qn,element:qn,embed:qn,frame:qn,frameset:qn,isindex:qn,keygen:qn,link:qn,math:qn,menu:qn,menuitem:qn,meta:qn,nextid:qn,noembed:qn,noframes:qn,optgroup:qn,option:qn,param:qn,script:qn,shadow:qn,source:qn,spacer:qn,style:qn,svg:qn,template:qn,title:qn,track:qn,abbr:Nn,acronym:Nn,bdi:Nn,bdo:Nn,big:Nn,blink:Nn,button:Nn,canvas:Nn,cite:Nn,data:Nn,details:Nn,dfn:Nn,font:Nn,ins:Nn,label:Nn,map:Nn,marquee:Nn,meter:Nn,nobr:Nn,noscript:Nn,object:Nn,output:Nn,progress:Nn,rb:Nn,rbc:Nn,rp:Nn,rt:Nn,rtc:Nn,ruby:Nn,slot:Nn,small:Nn,span:Nn,sup:Nn,sub:Nn,tbody:Nn,tfoot:Nn,thead:Nn,time:Nn,address:Rn,article:Rn,aside:Rn,body:Rn,center:Rn,div:Rn,fieldset:Rn,figcaption:Rn,figure:Rn,form:Rn,footer:Rn,header:Rn,hgroup:Rn,html:Rn,legend:Rn,main:Rn,multicol:Rn,nav:Rn,picture:Rn,section:Rn,a:function(t,n){const e=n.properties||{},r=t.all(n),o={type:"link",url:t.resolve(String(e.href||"")||null),title:e.title?String(e.title):null,children:r};return t.patch(n,o),o},audio:Bn,b:Fn,base:function(t,n){t.baseFound||(t.frozenBaseUrl=String(n.properties&&n.properties.href||"")||void 0,t.baseFound=!0)},blockquote:function(t,n){const e={type:"blockquote",children:t.toFlow(t.all(n))};return t.patch(n,e),e},br:function(t,n){const e={type:"break"};return t.patch(n,e),e},code:cn,dir:bn,dl:function(t,n){const e=[],r=[];let o=-1;for(;++o<n.children.length;){const t=n.children[o];"element"===t.type&&"div"===t.tagName?e.push(...t.children):e.push(t)}let i={definitions:[],titles:[]};for(o=-1;++o<e.length;){const t=e[o];if("element"===t.type&&"dt"===t.tagName){const n=e[o-1];n&&"element"===n.type&&"dd"===n.tagName&&(r.push(i),i={definitions:[],titles:[]}),i.titles.push(t)}else i.definitions.push(t)}r.push(i),o=-1;const c=[];for(;++o<r.length;){const n=[...Yt(t,r[o].titles),...Yt(t,r[o].definitions)];n.length>0&&c.push({type:"listItem",spread:n.length>1,checked:null,children:n})}if(c.length>0){const e={type:"list",ordered:!1,start:null,spread:Wt(c),children:c};return t.patch(n,e),e}},dt:hn,dd:hn,del:Vt,em:nn,h1:rn,h2:rn,h3:rn,h4:rn,h5:rn,h6:rn,hr:function(t,n){const e={type:"thematicBreak"};return t.patch(n,e),e},i:nn,iframe:function(t,n){const e=n.properties||{},r=String(e.src||""),o=String(e.title||"");if(r&&o){const e={type:"link",title:null,url:t.resolve(r),children:[{type:"text",value:o}]};return t.patch(n,e),e}},img:on,image:on,input:function(t,n){const e=n.properties||{},r=String(e.value||e.placeholder||"");if(e.disabled||"hidden"===e.type||"file"===e.type)return;if("checkbox"===e.type||"radio"===e.type){const r={type:"text",value:e.checked?t.options.checked||"[x]":t.options.unchecked||"[ ]"};return t.patch(n,r),r}if("image"===e.type){const o=e.alt||r;if(o){const r={type:"image",url:t.resolve(String(e.src||"")||null),title:String(e.title||"")||null,alt:String(o)};return t.patch(n,r),r}return}let o=[];if(r)o=[[r,void 0]];else if("button"!==e.type&&"file"!==e.type&&"password"!==e.type&&"reset"!==e.type&&"submit"!==e.type&&e.list){const n=String(e.list),r=t.elementById.get(n);r&&"datalist"===r.tagName&&(o=an(r,e))}if(0===o.length)return;if("password"===e.type&&(o[0]=["•".repeat(o[0][0].length),void 0]),"email"===e.type||"url"===e.type){const n=[];let r=-1;for(;++r<o.length;){const i=t.resolve(o[r][0]);n.push({type:"link",title:null,url:"email"===e.type?"mailto:"+i:i,children:[{type:"text",value:o[r][1]||i}]}),r!==o.length-1&&n.push({type:"text",value:", "})}return n}const i=[];let c=-1;for(;++c<o.length;)i.push(o[c][1]?o[c][1]+" ("+o[c][0]+")":o[c][0]);const a={type:"text",value:i.join(", ")};return t.patch(n,a),a},kbd:cn,li:hn,listing:Kt,mark:nn,ol:bn,p:An,plaintext:Kt,pre:Kt,q:function(t,n){const e=t.options.quotes||En;t.qNesting++;const r=t.all(n);t.qNesting--;const o=e[t.qNesting%e.length],i=r[0],c=r[r.length-1],a=o.charAt(0),s=o.length>1?o.charAt(1):o;return i&&"text"===i.type?i.value=a+i.value:r.unshift({type:"text",value:a}),c&&"text"===c.type?c.value+=s:r.push({type:"text",value:s}),r},s:Vt,samp:cn,select:function(t,n){const e=an(n);let r=-1;const o=[];for(;++r<e.length;){const t=e[r];o.push(t[1]?t[1]+" ("+t[0]+")":t[0])}if(o.length>0){const e={type:"text",value:o.join(", ")};return t.patch(n,e),e}},strike:Vt,strong:Fn,summary:An,table:function(t,n){if(t.inTable){const e={type:"text",value:Zt(n)};return t.patch(n,e),e}t.inTable=!0;const{align:e,headless:r}=function(t){const n={align:[null],headless:!0};let e=0,r=0;return a(t,(function(o){if("element"===o.type){if("table"===o.tagName&&t!==o)return u;if("th"!==o.tagName&&"td"!==o.tagName||!o.properties)"thead"===o.tagName?n.headless=!1:"tr"===o.tagName&&(e++,r=0);else{if(!n.align[r]){const t=String(o.properties.align||"")||null;"center"!==t&&"left"!==t&&"right"!==t&&null!==t||(n.align[r]=t)}n.headless&&e<2&&"th"===o.tagName&&(n.headless=!1),r++}}})),n}(n),o=t.toSpecificContent(t.all(n),zn);r&&o.unshift({type:"tableRow",children:[]});let i=-1;for(;++i<o.length;){const n=o[i],e=t.toSpecificContent(n.children,jn);n.children=e}let c=1;for(i=-1;++i<o.length;){const t=o[i].children;let n=-1;for(;++n<t.length;){const e=t[n];if(e.data){const t=e.data,r=Number.parseInt(String(t.hastUtilToMdastTemporaryColSpan),10)||1,c=Number.parseInt(String(t.hastUtilToMdastTemporaryRowSpan),10)||1;if(r>1||c>1){let t=i-1;for(;++t<i+c;){let e=n-1;for(;++e<n+r&&o[t];){const r=[];t===i&&e===n||r.push({type:"tableCell",children:[]}),o[t].children.splice(e,0,...r)}}}"hastUtilToMdastTemporaryColSpan"in e.data&&delete e.data.hastUtilToMdastTemporaryColSpan,"hastUtilToMdastTemporaryRowSpan"in e.data&&delete e.data.hastUtilToMdastTemporaryRowSpan,0===Object.keys(e.data).length&&delete e.data}}t.length>c&&(c=t.length)}for(i=-1;++i<o.length;){const t=o[i].children;let n=t.length-1;for(;++n<c;)t.push({type:"tableCell",children:[]})}let s=e.length-1;for(;++s<c;)e.push(null);t.inTable=!1;const l={type:"table",align:e,children:o};return t.patch(n,l),l},td:Ln,textarea:function(t,n){const e={type:"text",value:Zt(n)};return t.patch(n,e),e},th:Ln,tr:function(t,n){const e={type:"tableRow",children:t.toSpecificContent(t.all(n),Mn)};return t.patch(n,e),e},tt:cn,u:nn,ul:bn,var:cn,video:Bn,wbr:function(t,n){const e={type:"text",value:"​"};return t.patch(n,e),e},xmp:Kt};function Nn(t,n){return t.all(n)}function Rn(t,n){return t.toFlow(t.all(n))}function qn(){}const _n={}.hasOwnProperty;function Gn(t){const n=t.children||[],e=[];let r=-1;for(;++r<n.length;){const o=this.one(n[r],t);Array.isArray(o)?e.push(...o):o&&e.push(o)}return e}function Un(t,n){if("element"===t.type){if(t.properties&&"ignore"===t.properties.dataMdast)return;if(_n.call(this.handlers,t.tagName))return this.handlers[t.tagName](this,t,n)||void 0}else if(_n.call(this.nodeHandlers,t.type))return this.nodeHandlers[t.type](this,t,n)||void 0;if("value"in t&&"string"==typeof t.value){const n={type:"text",value:t.value};return this.patch(t,n),n}if("children"in t)return this.all(t)}function $n(t,n){t.position&&(n.position=l(t))}function Pn(t){const n=this.frozenBaseUrl;return null==t?"":n?String(new URL(t,n)):t}function Qn(t){return kn(t)}function Zn(t,n){const e=n(),r=[];let o=[],i=-1;for(;++i<t.length;){const n=t[i];c(n)?(o.length>0&&(n.children.unshift(...o),o=[]),r.push(n)):o.push(n)}if(o.length>0){let t=r[r.length-1];t||(t=n(),r.push(t)),t.children.push(...o),o=[]}return r;function c(t){return t.type===e.type}}const On={};function Dn(t,n){const e=c(t),r=n||On,o=It({newlines:!0===r.newlines}),i=function(t){return{all:Gn,baseFound:!1,elementById:new Map,frozenBaseUrl:void 0,handlers:{...In,...t.handlers},inTable:!1,nodeHandlers:{...Tn,...t.nodeHandlers},one:Un,options:t,patch:$n,qNesting:0,resolve:Pn,toFlow:Qn,toSpecificContent:Zn}}(r);let s;o(e),a(e,(function(t){if(t&&"element"===t.type&&t.properties){const n=String(t.properties.id||"")||void 0;n&&!i.elementById.has(n)&&i.elementById.set(n,t)}}));const u=i.one(e,void 0);return s=u?Array.isArray(u)?{type:"root",children:u}:u:{type:"root",children:[]},a(s,(function(t,n,e){if("text"===t.type&&void 0!==n&&e){const r=e.children[n-1];if(r&&r.type===t.type)return r.value+=t.value,e.children.splice(n,1),r.position&&t.position&&(r.position.end=t.position.end),n-1;if(t.value=t.value.replace(/[\t ]*(\r?\n|\r)[\t ]*/,"$1"),!e||"heading"!==e.type&&"paragraph"!==e.type&&"root"!==e.type||(n||(t.value=t.value.replace(/^[\t ]+/,"")),n===e.children.length-1&&(t.value=t.value.replace(/[\t ]+$/,""))),!t.value)return e.children.splice(n,1),n}})),s}const Hn={document:!0};function Jn(t,n){return t&&"run"in t?async function(e,r){const o=Dn(e,{...Hn,...n});await t.run(o,r)}:function(n){return Dn(n,{...Hn,...t})}}function Xn(t){const n=this;n.compiler=function(e){return ot(e,{...n.data("settings"),...t,extensions:n.data("toMarkdownExtensions")||[]})}}async function Kn(t,n){const e=new Set(n.map((t=>t.tagName)).filter(ee)),r=new Map,o=function(t,n){return ft(t,n||{})||{type:"root",children:[]}}(t,{afterTransform:(t,n)=>{var o;"element"===n.type&&(function(t){const n=t.properties.dataSrc;"img"===t.tagName&&!t.properties.src&&n&&(t.properties.src=n)}(n),"a"===(o=n).tagName&&void 0!==o.properties.dataFootnoteBackref&&(o.properties.dataMdast="ignore"),t instanceof Element&&e.has(t.localName)&&r.set(n,t))}});await async function(t){await Promise.all([...t].map((async([t,n])=>{try{const e=await n.toMarkdown();t.properties.dataMarkdownDescription=e,t.children=[{type:"text",value:e}]}catch(t){console.error("Failed to describe element as markdown",t)}})))}(r);const i={sup:Yn,section:te};for(const t of e)i[t]=Vn;const c=f().use(Jn,{handlers:i}).use(A).use(Xn,{bullet:"-",handlers:{break:Wn}}),a=await c.run({type:"root",children:o.children});return c.stringify(a).trimEnd()}const Vn=(t,n)=>{const e=n.properties.dataMarkdownDescription;return"string"==typeof e?function(t){const{children:n}=f().use(E).use(A).parse(t);return 1===n.length&&"paragraph"===n[0].type?n[0].children:n}(e):t.all(n)},Wn=(...t)=>{const n=C.break(...t);return"\\\n"===n?" \n":n},Yn=(t,n)=>{const e=n.children.find((t=>ne(t,"a")&&void 0!==t.properties.dataFootnoteRef));if(!e)return In.sup(t,n);const r=e.children.map((t=>"text"===t.type?t.value:"")).join("");return{type:"footnoteReference",identifier:r,label:r}},te=(t,n)=>{if(void 0===n.properties.dataFootnotes)return In.section(t,n);const e=n.children.find((t=>ne(t,"ol"))),r=null==e?void 0:e.children.filter((t=>ne(t,"li")));return(null!=r?r:[]).map(((n,e)=>{const r=String(e+1);return{type:"footnoteDefinition",identifier:r,label:r,children:t.toFlow(t.all(n))}}))};function ne(t,n){return"element"===t.type&&t.tagName===n}function ee(t){var n;const e=null===(n=customElements.get(t))||void 0===n?void 0:n.prototype;return"function"==typeof(null==e?void 0:e.toMarkdown)}export{Kn as exportMarkdown}