r){if(!t.final_argument_whitespace)throw new At(`maximum ${r} argument(s) allowed, ${i.length} supplied`);{const t=e.split(/\s+/);i=t.splice(0,r-1),i.push(t.join(" "))}}return i}(n,t):n&&(o=0,r=[n].concat(r)),r.length&&!r[0].trim()&&(r.shift(),o++),r.length&&!t.has_content)throw new At("Has content but content not allowed");return{map:e.map?e.map:[0,0],args:a,options:s,body:r.join("\n"),bodyMap:e.map?[r.length>0?e.map[0]+o:e.map[1],r.length>0?e.map[1]-1:e.map[1]]:[0,0]}}function Tt(e,t){let n=1,i={},r=null;if(e.length&&e[0].startsWith("---")){n++;const t=[];r=[];let i=!1;for(const o of e.slice(1))o.startsWith("---")?(n++,i=!0):i?t.push(o):(n++,r.push(o));e=t}else if(e.length&&e[0].startsWith(":")){const t=[];r=[];let i=!1;for(const o of e)i||o.startsWith(":")?i?t.push(o):(n++,r.push(o.slice(1))):(i=!0,t.push(o));e=t}if(null!==r)try{const e=yt.load(r.join("\n"));if(null===e||"object"!=typeof e)throw new At(`not dict: ${e}`);i=e}catch(e){throw new At(`Invalid options YAML: ${e}`)}if(t.rawOptions)return[e,i,n];for(const[e,n]of Object.entries(i)){const r=t.option_spec?t.option_spec[e]:null;if(!r)throw new At(`Unknown option: ${e}`);let o=n;null!==n&&!1!==n||(o="");try{o=r(`${o||""}`)}catch(t){throw new At(`Invalid option value: (option: '${e}'; value: ${n})\n${t}`)}i[e]=o}return[e,i,n]}function Ct(e,t){var n;let i=t.directivesAfter||"block";(null===(n=t.replaceFences)||void 0===n||n)&&(e.core.ruler.after(i,"fence_to_directive",jt),i="fence_to_directive"),e.core.ruler.after(i,"run_directives",function(e){function t(t){const n=[];for(const i of t.tokens)if("directive"===i.type&&i.info in e)try{const r=new e[i.info](t),o=xt(i,r),[s,a]=Tt(i.content.trim()?i.content.split(/\r?\n/):[],r),l=new t.Token("parsed_directive_open","",1);l.info=i.info,l.hidden=!0,l.content=s.join("\n").trim(),l.meta={arg:i.meta.arg,opts:a};const c=[l];c.push(...r.run(o));const u=new t.Token("parsed_directive_close","",-1);u.hidden=!0,c.push(u),c[1].meta=Object.assign(Object.assign({directive:!0},o.options),c[1].meta),n.push(...c)}catch(e){const r=new t.Token("directive_error","",0);r.content=i.content,r.info=i.info,r.meta=i.meta,r.map=i.map,r.meta.error_message=e.message,r.meta.error_name=e.name,n.push(r)}else n.push(i);return t.tokens=n,!0}return t}(t.directives||{})),e.renderer.rules.directive=(e,t)=>{const n=e[t];return`\n`},e.renderer.rules.directive_error=(e,t)=>{const n=e[t];let i="";return n.content&&(i=`\n---\n${n.content}`),`\n`}}function jt(e){for(const t of e.tokens)if("fence"===t.type||"colon_fence"===t.type){const e=t.info.match(/^\{([^\s}]+)\}\s*(.*)$/);e&&(t.type="directive",t.info=e[1],t.meta={arg:e[2]})}return!0}function Ot(e){return e.toLowerCase().split(/\s+/).join("-").replace(/[^a-z0-9]+/,"-").replace(/^[-0-9]+|-+$/,"")}class It extends Error{constructor(){super(...arguments),this.name="OptionSpecError"}}const St=e=>e,Et=e=>{if(!e)throw new It("Argument required but none supplied");return e},$t=e=>{if(e.trim())throw new It(`No argument is allowed: "${e}" supplied`);return null},Nt=e=>`${e||""}`.split(/\s+/).map((e=>Ot(e)));function Mt(e){if(!e)throw new It("Value is not set");const t=Number.parseFloat(e);if(Number.isNaN(t)||!Number.isInteger(t))throw new It(`Value "${e}" is not an integer`);return t}function Ft(e){const t=Mt(e);if(t<0)throw new It(`Value "${e}" must be positive or zero`);return t}const Lt=e=>e?Ft(e):null,qt=e=>Ft(e=`${e||""}`.replace(/\s+%$/,""));function Dt(e,t){const n=new RegExp(`^(?[0-9.]+)\\s*(?${t.join("|")})$`).exec(e);if(!n||!n.groups)throw new It(`not a positive measure of one of the following units: ${t.join("|")}`);return n.groups.number+n.groups.units}const Ut=["em","ex","px","in","cm","mm","pt","pc"],Yt=e=>Dt(e,[...Ut,""]),Rt=(e,t="")=>{try{return Dt(e,[...Ut,"%"])}catch(n){return Yt(e)+t}},Pt=(e,t="")=>"image"===e.toLowerCase()?"image":Rt(e,t);function Wt(e){return t=>{if(t=t.toLowerCase().trim(),e.includes(t))return t;throw new It(`must be in: ${e.join("|")}`)}}const Jt=e=>e;var Bt=Object.freeze({__proto__:null,make_id:Ot,OptionSpecError:It,unchanged:St,unchanged_required:Et,flag:$t,class_option:Nt,int:Mt,nonnegative_int:Ft,optional_int:Lt,percentage:qt,length_or_unitless:Yt,length_or_percentage_or_unitless:Rt,length_or_percentage_or_unitless_figure:Pt,create_choice:Wt,uri:Jt});class Kt extends wt{constructor(){super(...arguments),this.final_argument_whitespace=!0,this.has_content=!0,this.option_spec={class:Nt,name:St},this.title="",this.kind=""}run(e){var t;const n=[],i=this.createToken("admonition_open","aside",1,{map:e.map,block:!0,meta:{kind:this.kind}});(null===(t=e.options.class)||void 0===t?void 0:t.length)>=1?(i.attrSet("class",e.options.class.join(" ")),i.attrJoin("class","admonition")):i.attrSet("class","admonition"),this.kind&&i.attrJoin("class",this.kind),n.push(i);const r=this.createToken("admonition_title_open","header",1);r.attrSet("class","admonition-title"),n.push(r);const o=e.args[0]||this.title;n.push(this.createToken("inline","",0,{map:[e.map[0],e.map[0]],content:o,children:[]})),n.push(this.createToken("admonition_title_close","header",-1,{block:!0}));const s=this.nestedParse(e.body,e.bodyMap[0]);return n.push(...s),n.push(this.createToken("admonition_close","aside",-1,{block:!0})),n}}const zt={admonition:class extends Kt{constructor(){super(...arguments),this.required_arguments=1}},attention:class extends Kt{constructor(){super(...arguments),this.title="Attention",this.kind="attention"}},caution:class extends Kt{constructor(){super(...arguments),this.title="Caution",this.kind="caution"}},danger:class extends Kt{constructor(){super(...arguments),this.title="Danger",this.kind="danger"}},error:class extends Kt{constructor(){super(...arguments),this.title="Error",this.kind="error"}},important:class extends Kt{constructor(){super(...arguments),this.title="Important",this.kind="important"}},hint:class extends Kt{constructor(){super(...arguments),this.title="Hint",this.kind="hint"}},note:class extends Kt{constructor(){super(...arguments),this.title="Note",this.kind="note"}},seealso:class extends Kt{constructor(){super(...arguments),this.title="See Also",this.kind="seealso"}},tip:class extends Kt{constructor(){super(...arguments),this.title="Tip",this.kind="tip"}},warning:class extends Kt{constructor(){super(...arguments),this.title="Warning",this.kind="warning"}}};const Gt={code:class extends wt{constructor(){super(...arguments),this.required_arguments=0,this.optional_arguments=1,this.final_argument_whitespace=!1,this.has_content=!0,this.option_spec={"number-lines":Lt,force:$t,name:St,class:Nt}}run(e){this.assert_has_content(e);return[this.createToken("fence","code",0,{info:e.args?e.args[0]:"",content:e.body,map:e.bodyMap})]}},"code-block":class extends wt{constructor(){super(...arguments),this.required_arguments=0,this.optional_arguments=1,this.final_argument_whitespace=!1,this.has_content=!0,this.option_spec={linenos:$t,"lineno-start":Mt,dedent:Lt,"emphasize-lines":Et,caption:Et,force:$t,name:St,class:Nt}}run(e){this.assert_has_content(e);return[this.createToken("fence","code",0,{info:e.args?e.args[0]:"",content:e.body,map:e.bodyMap})]}},"code-cell":class extends wt{constructor(){super(...arguments),this.required_arguments=0,this.optional_arguments=1,this.final_argument_whitespace=!1,this.has_content=!0,this.rawOptions=!0}run(e){return[this.createToken("fence","code",0,{info:e.args?e.args[0]:"",content:e.body,map:e.bodyMap})]}}},Vt={alt:St,height:Yt,width:Rt,scale:qt,target:Et,class:Nt,name:St};class Ht extends wt{constructor(){super(...arguments),this.required_arguments=1,this.optional_arguments=0,this.final_argument_whitespace=!0,this.option_spec=Object.assign(Object.assign({},Vt),{align:Wt(["left","center","right","top","middle","bottom"])})}create_image(e){const t=e.args[0]||"",n=this.createToken("image","img",0,{map:e.map,block:!0});n.attrSet("src",t),n.attrSet("alt",e.options.alt||"");const i=[];return e.options.alt&&this.state.md.inline.parse(e.options.alt,this.state.md,this.state.env,i),n.children=i,e.options.height&&n.attrSet("height",e.options.height),e.options.width&&n.attrSet("width",e.options.width),e.options.align&&n.attrJoin("class",`align-${e.options.align}`),e.options.class&&n.attrJoin("class",e.options.class.join(" ")),n}run(e){return[this.create_image(e)]}}const Zt={image:Ht,figure:class extends Ht{constructor(){super(...arguments),this.option_spec=Object.assign(Object.assign({},Vt),{align:Wt(["left","center","right"]),figwidth:Pt,figclass:Nt}),this.has_content=!0}run(e){const t=this.createToken("figure_open","figure",1,{map:e.map,block:!0});let n;e.options.figclass&&t.attrJoin("class",e.options.figclass.join(" ")),e.options.align&&t.attrJoin("class",`align-${e.options.align}`),e.options.figwidth&&"image"!==e.options.figwidth&&t.attrSet("width",e.options.figwidth),e.options.name&&(n=g(this.state,t,f.figure,e.options.name,e.body.trim()),t.attrJoin("class","numbered"));const i=this.create_image(e);i.map=[e.map[0],e.map[0]];let r=[],o=[];if(e.body){const[t,...i]=e.body.split("\n\n"),s=i.join("\n\n"),a=e.bodyMap[0],l=this.createToken("figure_caption_open","figcaption",1,{block:!0});n&&l.attrSet("number",`${n.number}`);if(r=[l,...this.nestedParse(t,a),this.createToken("figure_caption_close","figcaption",-1,{block:!0})],s){const e=a+t.split("\n").length+1;o=[this.createToken("figure_legend_open","",1,{block:!0}),...this.nestedParse(s,e),this.createToken("figure_legend_close","",-1,{block:!0})]}}const s=this.createToken("figure_close","figure",-1,{block:!0});return[t,i,...r,...o,s]}}};class Qt{constructor(e,t=!0){if(this.children=[],this.children=[],t)this._set_children_from_tokens(e);else{if(0===e.length)throw new Error("Tree creation: Can only create root from empty token sequence.");if(1===e.length){const t=e[0];if(t.nesting)throw new Error("Unequal nesting level at the start and end of token stream.");this.token=t,null!==t.children&&t.children.length>0&&this._set_children_from_tokens(t.children)}else this.nester_tokens={opening:e[0],closing:e[e.length-1]},this._set_children_from_tokens(e.slice(1,-1))}}_set_children_from_tokens(e){const t=[...e].reverse();let n;for(;t.length>0&&(n=t.pop(),n);){if(!n.nesting){this._add_child([n]);continue}if(1!==n.nesting)throw new Error("Invalid token nesting");const e=[n];let i=1;for(;t.length>0&&0!==i;)n=t.pop(),n&&(e.push(n),i+=n.nesting);if(i)throw new Error(`unclosed tokens starting: ${e[0]}`);this._add_child(e)}}_add_child(e){const t=new Qt(e,!1);t.parent=this,this.children.push(t)}to_tokens(){const e=[];return function e(t,n){if("root"===t.type)for(const i of t.children)e(i,n);else if(t.token)n.push(t.token);else{if(!t.nester_tokens)throw new Error("No nested token available");n.push(t.nester_tokens.opening);for(const i of t.children)e(i,n);n.push(t.nester_tokens.closing)}}(this,e),e}get is_root(){return!(this.token||this.nester_tokens)}get is_nested(){return!!this.nester_tokens}get siblings(){return this.parent?this.parent.children:[this]}*walk(e=!0){e&&(yield this);for(const e of this.children)yield*e.walk(!0)}get type(){var e,t,n;if(this.is_root)return"root";if(this.token)return this.token.type;if(null===(e=this.nester_tokens)||void 0===e?void 0:e.opening.type.endsWith("_open"))return null===(t=this.nester_tokens)||void 0===t?void 0:t.opening.type.slice(0,-5);if(this.nester_tokens)return null===(n=this.nester_tokens)||void 0===n?void 0:n.opening.type;throw new Error("no internal token")}attribute_token(){if(this.token)return this.token;if(this.nester_tokens)return this.nester_tokens.opening;throw new Error("Tree node does not have the accessed attribute")}get tag(){return this.attribute_token().tag}get level(){return this.attribute_token().level}get content(){return this.attribute_token().content}get markup(){return this.attribute_token().markup}get info(){return this.attribute_token().info}get meta(){return this.attribute_token().meta}get block(){return this.attribute_token().block}get hidden(){return this.attribute_token().hidden}get map(){return this.attribute_token().map}get attrs(){return this.attribute_token().attrs}}const Xt={"list-table":class extends wt{constructor(){super(...arguments),this.required_arguments=0,this.optional_arguments=1,this.final_argument_whitespace=!0,this.has_content=!0,this.option_spec={"header-rows":Ft,"stub-columns":Ft,width:Rt,widths:St,class:Nt,name:St,align:Wt(["left","center","right"])}}run(e){this.assert_has_content(e);const t=e.options["header-rows"]||0,n=this.nestedParse(e.body,e.bodyMap[0]);if(n.length<2||"bullet_list_open"!==n[0].type||"bullet_list_close"!==n[n.length-1].type)throw new At("Content is not a single bullet list");const i=[],r=this.createToken("table_open","table",1,{map:e.bodyMap});e.options.align&&r.attrJoin("class",`align-${e.options.align}`),e.options.class&&r.attrJoin("class",e.options.class.join(" ")),i.push(r),e.args.length&&e.args[0]&&(i.push(this.createToken("table_caption_open","caption",1)),i.push(this.createToken("inline","",0,{map:[e.map[0],e.map[0]],content:e.args[0],children:[]})),i.push(this.createToken("table_caption_close","caption",-1)));let o,s="th";t?(i.push(this.createToken("thead_open","thead",1,{level:1})),s="th"):(i.push(this.createToken("tbody_open","tbody",1,{level:1})),s="td");let a=0;for(const e of new Qt(n.slice(1,-1)).children){a+=1,this.assert("list_item"===e.type,`list item ${a} not of type 'list_item': ${e.type}`),this.assert(1===e.children.length&&"bullet_list"===e.children[0].type,`list item ${a} content not a nested bullet list`);const n=e.children[0].children;void 0===o?o=n.length:this.assert(n.length===o,`list item ${a} does not contain the same number of columns as previous items`),t&&a===t+1&&(i.push(this.createToken("thead_close","thead",-1,{level:1})),i.push(this.createToken("tbody_open","tbody",1,{level:1})),s="td"),i.push(this.createToken("tr_open","tr",1,{map:e.map,level:2}));for(const e of n)i.push(this.createToken(`${s}_open`,s,1,{map:e.map,level:3})),i.push(...e.to_tokens().slice(1,-1)),i.push(this.createToken(`${s}_close`,s,-1,{level:3}));i.push(this.createToken("tr_close","tr",-1,{level:2}))}if(t&&a{const t=m(e);return t.references.forEach((e=>{const{label:n,tokens:i,contentFromTarget:r}=e,o=(e,t)=>(i.open.attrJoin("class","error"),i.open.tag=i.close.tag="code",i.content.content=r&&t?r(t):e,!0),s=t.targets[n];return s?e.kind&&s.kind!==e.kind?o(`Reference "${n}" does not match kind "${e.kind}"`):(i.open.attrSet("href",`#${s.label}`),s.title&&i.open.attrSet("title",s.title),void(r&&(i.content.content=r(s).trim()))):o(n,{kind:e.kind||"",label:n,title:n,number:`"${n}"`})})),!0}))}const rn={parseRoles:!0,replaceFences:!0,rolesAfter:"inline",directivesAfter:"block",directives:tn,roles:_};function on(e,t){const n=Object.assign(Object.assign({},rn),t);e.use(o,n),e.use(Ct,n),e.use(nn,n)}e.Directive=wt,e.Role=t,e.default=on,e.directiveOptions=Bt,e.directivePlugin=Ct,e.directivesDefault=tn,e.docutilsPlugin=on,e.rolePlugin=o,e.rolesDefault=_,Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=index.umd.min.js.map