citeproc-plus
Version:
Citeproc-js + citation styles bundled
3 lines (2 loc) • 2.18 kB
JavaScript
;function e(t){if(t.name)return t;const s={};return s.name=t.n,t.a?s.attrs=t.a:s.attrs={},s.children=[],t.c?t.c.forEach((t=>{"string"==typeof t?s.children.push(t):s.children.push(e(t))})):"term"===t.n&&s.children.push(""),s}exports.CSL=class{constructor(){this.styles={},this.locales={},this.citeproc=!1}getStyles(){return Promise.resolve().then((function(){return require("./styles-fae41266.js")})).then((({styles:e})=>e))}getEngine(e,t,s,r){let n,i;return Promise.all([this.getCiteproc(),this.getStyle(t).then((e=>i=e))]).then((()=>this.getLocale(i,s,r).then((e=>n=e)))).then((()=>{const t=Object.assign(Object.create(e),e);return t.retrieveLocale=()=>n,new this.citeproc.Engine(t,i,s,r)}))}getEngineSync(e,t,s,r){if(!this.citeproc||!this.styles[t])return!1;const n=this.styles[t];let i=r||(n.attrs["default-locale"]?n.attrs["default-locale"]:s||"en-US");if(this.locales[i]||(i="en-US"),!this.locales[i])return!1;const l=this.locales[i],o=Object.assign(Object.create(e),e);return o.retrieveLocale=()=>l,new this.citeproc.Engine(o,n,s,r)}getCiteproc(){return this.citeproc?Promise.resolve():Promise.resolve().then((function(){return require("./citeproc_commonjs-7ada0779.js")})).then((function(e){return e.citeproc_commonjs})).then((e=>this.citeproc=e.default))}getStyle(t){return"object"==typeof t?Promise.resolve(t):Promise.resolve().then((function(){return require("./styles-fae41266.js")})).then((({styleLocations:s})=>{let r;return s[t]||(t=Object.keys(s).find((()=>!0))),this.styles[s[t]]?(this.styles[s[t]][t]=e(this.styles[s[t]][t]),r=Promise.resolve(this.styles[s[t]][t])):r=fetch(s[t],{method:"GET"}).then((e=>e.json())).then((r=>(this.styles[s[t]]=r,this.styles[s[t]][t]=e(this.styles[s[t]][t]),Promise.resolve(this.styles[s[t]][t])))),r}))}getLocale(t,s,r){let n=r||(t.attrs["default-locale"]?t.attrs["default-locale"]:s||"en-US");return this.locales[n]?Promise.resolve(this.locales[n]):Promise.resolve().then((function(){return require("./locales-90ac4a04.js")})).then((({locales:e})=>(e[n]||(n="en-US"),fetch(e[n],{method:"GET"})))).then((e=>e.json())).then((t=>(this.locales[n]=e(t),Promise.resolve(this.locales[n]))))}};
//# sourceMappingURL=index.js.map