import{visit as u}from"unist-util-visit";import D from"cross-fetch";import{fromDom as F}from"hast-util-from-dom";function A(){A=function(u,D){return new F(u,void 0,D)};var u=RegExp.prototype,D=new WeakMap;function F(u,A,C){var B=new RegExp(u,A);return D.set(B,C||D.get(u)),E(B,F.prototype)}function C(u,F){var A=D.get(F);return Object.keys(A).reduce(function(D,F){var C=A[F];if("number"==typeof C)D[F]=u[C];else{for(var E=0;void 0===u[C[E]]&&E+1]+)>/g,function(u,D){var F=E[D];return"$"+(Array.isArray(F)?F.join("$"):F)}))}if("function"==typeof A){var B=this;return u[Symbol.replace].call(this,F,function(){var u=arguments;return"object"!=typeof u[u.length-1]&&(u=[].slice.call(u)).push(C(u,B)),A.apply(this,u)})}return u[Symbol.replace].call(this,F,A)},A.apply(this,arguments)}function C(){return C=Object.assign?Object.assign.bind():function(u){for(var D=1;D{if(o(u))return D(u).then(u=>u.text()).then(u=>u);throw new Error("Cannot read non valid URL in node env.")},o=u=>{let D;try{D=new URL(u)}catch(u){return!1}return"http:"===D.protocol||"https:"===D.protocol},s=(u,D)=>[u.slice(0,D),u.slice(D)],l=(u,D)=>{const F=u.ref.author,A=D.ref.author;if(F.length!==A.length)return!1;for(let u=0;u{const D=document.createRange().createContextualFragment(u);return F(D).children[0]},c=["div","p","span","li","td","th"],p="CITATION",f=F=>(A={})=>async(E,t)=>{var n,f;let d=[];const h=A.csl||(null==t||null==(n=t.data)||null==(n=n.frontmatter)?void 0:n.csl)||"apa",g=A.lang||"en-US",x=F.plugins.config.get("@csl"),b=await(async(u,D,F="")=>{const A=u.plugins.config.get("@csl");if(Object.keys(A.templates.data).includes(D))return D;{const u=`customCSL-${Math.random().toString(36).slice(2,7)}`;let F="";o(D)&&(F=D);try{A.templates.add(u,await i(F))}catch(u){throw new Error(`Input CSL option, ${D}, is invalid or is an unknown file.`)}return u}})(F,h,A.path),m=await(async(u,D,F="")=>{const A=u.plugins.config.get("@csl");if(Object.keys(A.locales.data).includes(D))return D;{let u="";o(D)&&(u=D);try{const D=await i(u),F=D.match(/xml:lang="(.+)"/)[1];return A.locales.add(F,D),F}catch(u){throw new Error(`Input locale option, ${D}, is invalid or is an unknown file.`)}}})(F,g,A.path);let v=await(async(u,D)=>{var F;let A=[];if(u.bibliography)A="string"==typeof u.bibliography?[u.bibliography]:u.bibliography;else if(null!=D&&null!=(F=D.data)&&null!=(F=F.frontmatter)&&F.bibliography){A="string"==typeof D.data.frontmatter.bibliography?[D.data.frontmatter.bibliography]:D.data.frontmatter.bibliography;for(let u=0;uu.id),w=[],N={};let j=1;const O=x.engine(y.data,b,m,"html"),S=O.opt.xclass,k=(u=>u.cslXml.dataObj.children[0].children.find(u=>u.attrs&&u.attrs["citation-format"]).attrs["citation-format"])(O);if(u(E,"text",(u,D,F)=>{const E=u.value.match(B);if(!E||"tagName"in F&&!c.includes(F.tagName))return;let t=E.index,n=E.index+E[0].length;void 0!==E[2]&&t--;const i=[];0!==t&&i.push({type:"text",value:u.value.slice(0,t)});const[o,f]=(u=>{let D=[],F=!1;const A=u[1],E=u[2],B=u[3],t=u[4];if(void 0!==A)for(const u of A.split(";")){const F=e.exec(u.trim());if(null===F)continue;const A={id:F.groups.citekey.replace(/{(.+)}/,"$1"),prefix:void 0,locator:void 0,label:"page","suppress-author":!1,suffix:void 0},C=F.groups.prefix;void 0!==C&&(A["suppress-author"]=C.trim().endsWith("-"),A.prefix=A["suppress-author"]?C.substring(0,C.trim().length-1).trim():C.trim());const E=F.groups.explicitLocator,B=F.groups.explicitLocatorInSuffix,t=F.groups.suffix;let n,i=!0;void 0===E&&void 0===B?(n=t,i=!1):void 0===B&&void 0===E||(n=void 0!==E?E:B,A.suffix=null==t?void 0:t.trim());const{label:o,locator:s,suffix:l}=r(n,i);A.locator=s,void 0!==o&&(A.label=o),void 0===E&&void 0===B?A.suffix=l:void 0!==l&&void 0!==A.locator&&(A.locator+=l),D.push(A)}else F=!0,D.push(C({prefix:void 0,id:B.replace(/{(.+)}/,"$1"),"suppress-author":void 0!==E},r(t,!1)));return[D,F]})(E);for(const u of o)if(!$.includes(u.id))return;const[d,h]=((u,D,F,A,C,E,B,e,t)=>{const{inlineClass:n,linkCitations:r}=B,i=`${A}-${C}`,o=u.processCitationCluster({citationID:i,citationItems:F,properties:"in-text"===D?{noteIndex:0,mode:e?"composite":""}:{noteIndex:C,mode:e?"composite":""}},E.length>0?E:[],[])[1].find(u=>u[2]===i)[1],c=`citation--${F.map(u=>u.id.toLowerCase()).join("--")}--${C}`;if("note"===D)return[o,a(`${C}`)];if(r&&"numeric"===t){let u=0;const D=F.map(u=>u.id),A=o.replace(/\d+/g,function(F){const A=`${F}`;return u++,A});return[o,a(`${A}`)]}if(r&&"author-date"===t){if(1===F.length){const u=e?`${o}`:`${o.slice(0,1)}${o.slice(1,-1)}${o.slice(-1)}`;return[o,a(`${u}`)]}{const D=((u,D,F)=>{const A=[];if(F)for(const F of u.registry.reflist)D.includes(F.id)&&A.push(F);else for(const F of D)A.push(u.registry.reflist.find(u=>u.id===F));return A})(u,F.map(u=>u.id),u.opt.sort_citations),A=[];let C=o;for(const[u,F]of D.entries()){const E=F.id;let B=F.ambig;u>0&&l(D[u-1],F)&&-1===C.indexOf(B)&&(B=F.ref.issued.year.toString());const e=C.indexOf(B),[t,n]=s(C,e);A.push(t);const r=`${n.substring(0,B.length)}`;A.push(r),C=n.substr(B.length)}return A.push(C),[o,a(`${A.join("")}`)]}}return[o,a(`${o}`)]})(O,S,o,p,j,w,A,f,k);N[j]=d,w.push([`${p}-${j}`,0]),j+=1,i.push(h),nu.replace("@",""))),O.registry.mylist.length>=1&&(!A.suppressBibliography||(null==(f=A.inlineBibClass)?void 0:f.length)>0)){const D=(u=>{const[D,F]=u.makeBibliography(),A='
\n'+F.join("")+"
",C=a(A);return C.children.filter(u=>{var D;return null==(D=u.properties)||null==(D=D.className)?void 0:D.includes("csl-entry")}).forEach((u,F)=>{const A=D.entry_ids[F][0].toLowerCase();u.properties=u.properties||{},u.properties.id="bib-"+A}),C})(O);let F=!1;const B={};D.children.filter(u=>{var D;return null==(D=u.properties)||null==(D=D.className)?void 0:D.includes("csl-entry")}).forEach(u=>{const D=u.properties.id.split("-").slice(1).join("-");B[D]=C({},u),B[D].properties={id:"inlinebib-"+D}}),u(E,"element",(u,C,E)=>{var e,t;if((null==(e=A.inlineBibClass)?void 0:e.length)>0&&null!=(t=u.properties)&&null!=(t=t.id)&&t.toString().startsWith("citation-")){const[,...D]=u.properties.id.toString().split("--"),F=D.pop(),C={type:"element",tagName:"div",properties:{className:A.inlineBibClass,id:`inlineBib--${D.join("--")}--${F}`},children:D.map(u=>{const D=B[u];return D.properties={class:"inline-entry",id:`inline--${u}--${F}`},D})};E.children.push(C)}!A.suppressBibliography&&("p"===u.tagName||"div"===u.tagName)&&u.children.length>=1&&"text"===u.children[0].type&&"[^ref]"===u.children[0].value&&(E.children[C]=D,F=!0)}),A.suppressBibliography||F||E.children.push(D)}let L;if(u(E,"element",(u,D,F)=>{"section"===u.tagName&&u.properties.dataFootnotes&&(L=u,F.children.splice(D,1))}),"note"===S&&Object.keys(N).length>0){let D=[],F=1;u(E,"element",u=>{if("sup"===u.tagName&&"element"===u.children[0].type){let A=u.children[0];if("a"===A.tagName){const{href:u,id:C}=A.properties;if(u.includes("fn")&&C.includes("fnref")){const C=u.split("-").pop();D.push({type:u.includes("cite")?"citation":"existing",oldId:C}),A.properties.href=`#user-content-fn-${F}`,A.properties.id=`user-content-fnref-${F}`,A.children[0].value=F.toString(),F+=1}}}});const A=((u,D,F)=>{const A={type:"element",tagName:"ol",properties:{},children:[{type:"text",value:"\n"}]};let C;F&&(C=F.children.filter(u=>"element"==u.type).find(u=>"ol"===u.tagName));for(const[F,E]of D.entries()){const{type:D,oldId:B}=E;if("citation"===D)A.children.push({type:"element",tagName:"li",properties:{id:`user-content-fn-${F+1}`},children:[{type:"element",tagName:"p",properties:{},children:[a(`${u[B]}`),{type:"element",tagName:"a",properties:{href:`#user-content-fnref-${F+1}`,dataFootnoteBackref:!0,className:["data-footnote-backref"],ariaLabel:"Back to content"},children:[{type:"text",value:"↩"}]}]},{type:"text",value:"\n"}]});else if("existing"===D){const u=C.children.find(u=>"li"===u.tagName&&u.properties.id===`user-content-fn-${B}`);u.properties.id=`user-content-fn-${F+1}`,u.children[1].children.find(u=>"a"===u.tagName).properties.href=`#user-content-fnref-${F+1}`,A.children.push(u)}}return{type:"element",tagName:"section",properties:{dataFootnotes:!0,className:["footnotes"]},children:[{type:"element",tagName:"h2",properties:{className:["sr-only"],id:"footnote-label"},children:[{type:"text",value:"Footnotes"}]},{type:"text",value:"\n"},A]}})(N,D,L);E.children.push(A)}else L&&E.children.push(L)};export{f as default}; //# sourceMappingURL=generator.mjs.map