site/node_modules/rehype-citation/dist/browser/cite.mjs

3 lines
188 KiB
JavaScript
Raw Normal View History

2024-10-14 06:09:33 +00:00
import{parse as e,format as t}from"@citation-js/name";import{parse as r,format as i}from"@citation-js/date";import o from"citeproc";import a from"js-yaml";var n={__proto__:null,currentVersion:function(){return this.log.length},retrieveVersion:function(e=1){if(e<=0||e>this.currentVersion())return null;{const[t,r]=this.log[e-1],i=new this.constructor(JSON.parse(t),JSON.parse(r));return i.log=this.log.slice(0,e),i}},retrieveLastVersion:function(){return this.retrieveVersion(this.currentVersion())},undo:function(e=1){return this.retrieveVersion(this.currentVersion()-e)},save:function(){return this.log.push([JSON.stringify(this.data),JSON.stringify(this._options)]),this}};const s=["real","string"],l=["json","html","string","rtf"],c=["csl","bibtex","bibtxt","citation-*","ris","ndjson"],m=["string","function"];function u(e){if("object"!=typeof e)throw new TypeError("Options not an object!");const{format:t,type:r,style:i,lang:o,append:a,prepend:n}=e;if(t&&!s.includes(t))throw new TypeError(`Option format ("${t}") should be one of: ${s}`);if(r&&!l.includes(r))throw new TypeError(`Option type ("${r}") should be one of: ${l}`);if(i&&!c.includes(i)&&!/^citation/.test(i))throw new TypeError(`Option style ("${i}") should be one of: ${c}`);if(o&&"string"!=typeof o)throw new TypeError("Option lang should be a string, but is a "+typeof o);if(n&&!m.includes(typeof n))throw new TypeError("Option prepend should be a string or a function, but is a "+typeof n);if(a&&!m.includes(typeof a))throw new TypeError("Option append should be a string or a function, but is a "+typeof a);if(/^citation/.test(i)&&"json"===r)throw new Error(`Combination type/style of json/citation-* is not valid: ${r}/${i}`);return!0}var p={__proto__:null,options:function(e,t){return u(e),t&&this.save(),Object.assign(this._options,e),this},defaultOptions:{format:"real",type:"json",style:"csl",lang:"en-US"}};function h(e){switch(e){case void 0:return"Undefined";case null:return"Null";default:return e.constructor.name}}function f(e){switch(typeof e){case"string":return"String";case"object":if(Array.isArray(e))return"Array";if("Object"===h(e))return"SimpleObject";if("Null"!==h(e))return"ComplexObject";default:return"Primitive"}}var d={__proto__:null,typeOf:h,dataTypeOf:f};function g(e,t){if(e._graph){const r=t.findIndex(({type:e})=>"@else/list+object"===e);-1!==r&&t.splice(r+1,0,...e._graph.slice(0,-1))}return e._graph=t,e}function b(e){return delete e._graph,e}var y={__proto__:null,applyGraph:g,removeGraph:b};const v={_output(e,t,r){this._log.push(t,r),this._levels.indexOf(e)<this._levels.indexOf(this.level)||this._console.log(t,...r)},_console:null,_log:[],_levels:["http","debug","unmapped","info","warn","error","silent"],level:"silent"};for(const e of v._levels)v[e]=(t,...r)=>v._output(e,t,r);v._console="function"==typeof console.Console?new console.Console(process.stderr):console;const x={},w={},k={};function T(e,t){switch(t){case"Array":return 0===e.length||e.every(e=>"@csl/object"===j(e))?"@csl/list+object":"@else/list+object";case"SimpleObject":case"ComplexObject":return"@csl/object";default:return"@invalid"}}function E(e=[],t){for(const r of e)if(x[r].predicate(t))return E(x[r].extensions,t)||r}function j(e){const t=f(e);return"Array"===t&&0===e.length?T(e,t):E(w[t],e)||T(e,t)}function S(e,{dataType:t,predicate:r,extends:i}){let o=[];if(e in k&&(o=k[e],delete k[e],v.debug("[core]",`Subclasses "${o}" finally registered to parent type "${e}"`)),x[e]={predicate:r,extensions:o},i){const t=x[i];t?t.extensions.push(e):(k[i]||(k[i]=[]),k[i].push(e),v.debug("[core]",`Subclass "${e}" is waiting on parent type "${i}"`))}else(w[t]||(w[t]=[])).push(e)}function O(e){delete x[e];const t=[...Object.keys(w).map(e=>w[e]),...Object.keys(x).map(e=>x[e].extensions).filter(e=>e.length>0)];t.forEach(t=>{const r=t.indexOf(e);r>-1&&t.splice(r,1)})}const _=/^(?:@(.+?))(?:\/(?:(.+?)\+)?(?:(.+)))?$/;class A{constructor(e){this.validDataTypes=["String","Array","SimpleObject","ComplexObject","Primitive"],this.data=e}validateDataType(){const e=this.data.dataType;if(e&&!this.validDataTypes.includes
//# sourceMappingURL=cite.mjs.map