Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@citeproc-rs/wasm

Package Overview
Dependencies
Maintainers
1
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@citeproc-rs/wasm - npm Package Compare versions

Comparing version 0.0.0-canary-197979f to 0.0.0-canary-26ac18a

_cjs/snippets/wasm-1883a0b9dcad429e/src/js/include.js

31

_cjs/citeproc_rs_wasm_bg.d.ts
/* tslint:disable */
/* eslint-disable */
export const memory: WebAssembly.Memory;
export function parseStyleMetadata(a: number, b: number): number;
export function __wbg_driver_free(a: number): void;
export function driver_new(a: number, b: number, c: number, d: number, e: number): number;
export function driver_new(a: number): number;
export function driver_setStyle(a: number, b: number, c: number): number;
export function driver_setReferences(a: number, b: number, c: number): void;
export function driver_insertReference(a: number, b: number): void;
export function driver_resetReferences(a: number, b: number, c: number): number;
export function driver_insertReferences(a: number, b: number, c: number): number;
export function driver_insertReference(a: number, b: number): number;
export function driver_removeReference(a: number, b: number, c: number): number;
export function driver_includeUncited(a: number, b: number): number;
export function driver_toFetch(a: number): number;
export function driver_insertCluster(a: number, b: number): void;
export function driver_removeCluster(a: number, b: number): void;
export function driver_initClusters(a: number, b: number, c: number): void;
export function driver_builtCluster(a: number, b: number): number;
export function driver_randomClusterId(a: number, b: number): void;
export function driver_insertCluster(a: number, b: number): number;
export function driver_removeCluster(a: number, b: number, c: number): number;
export function driver_initClusters(a: number, b: number, c: number): number;
export function driver_builtCluster(a: number, b: number, c: number): number;
export function driver_previewCitationCluster(a: number, b: number, c: number, d: number, e: number, f: number, g: number): number;
export function driver_makeBibliography(a: number): number;
export function driver_bibliographyMeta(a: number): number;
export function driver_renumberClusters(a: number, b: number, c: number): void;
export function driver_setClusterOrder(a: number, b: number, c: number): void;
export function driver_setClusterOrder(a: number, b: number, c: number): number;
export function driver_batchedUpdates(a: number): number;
export function driver_fullRender(a: number): number;
export function driver_drain(a: number): void;
export function driver_fetchAll(a: number): number;
export function driver_fetchLocales(a: number): number;
export function __wbindgen_malloc(a: number): number;
export function __wbindgen_realloc(a: number, b: number, c: number): number;
export const __wbindgen_export_2: WebAssembly.Table;
export function _dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h18b461775fab0812(a: number, b: number, c: number): void;
export function _dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__ha382542df1b652c5(a: number, b: number, c: number): void;
export function __wbindgen_free(a: number, b: number): void;
export function __wbindgen_exn_store(a: number): void;
export function wasm_bindgen__convert__closures__invoke2_mut__h442d48e1eb0f8a8d(a: number, b: number, c: number, d: number): void;
export function wasm_bindgen__convert__closures__invoke2_mut__h5b58866e158bfea3(a: number, b: number, c: number, d: number): void;
/* tslint:disable */
/* eslint-disable */
/**
* Parses a CSL style, either independent or dependent, and returns its metadata.
* @param {string} style
* @returns {WasmResult<StyleMeta>}
*/
export function parseStyleMetadata(style: string): WasmResult<StyleMeta>;
interface InitOptions {
/** A CSL style as an XML string */
style: string,
/** A Fetcher implementation for fetching locales.
*
* If not provided, then no locales can be fetched, and default-locale and localeOverride will
* not be respected; the only locale used will be the bundled en-US. */
fetcher?: Fetcher,
/** The output format for this driver instance */
format: "html" | "rtf" | "plain",
/** A locale to use instead of the style's default-locale.
*
* For dependent styles, use parseStyleMetadata to find out which locale it prefers, and pass
* in the parent style with a localeOverride set to that value.
*/
localeOverride?: string,
/** Disables sorting in the bibliography; items appear in cited order. */
bibliographyNoSort?: bool,
}
/** This interface lets citeproc retrieve locales or modules asynchronously,
according to which ones are needed. */
export interface Lifecycle {
export interface Fetcher {
/** Return locale XML for a particular locale. */

@@ -12,2 +41,4 @@ fetchLocale(lang: string): Promise<string>;

export type DateLiteral = { "literal": string; };

@@ -21,2 +52,4 @@ export type DateRaw = { "raw": string; };

/** Locator type, and a locator string */

@@ -36,3 +69,3 @@ export type Locator = {

suppression?: "InText" | "Rest" | null;
} & CiteLocator;
} & Partial<CiteLocator>;

@@ -46,3 +79,3 @@ export type ClusterNumber = {

export type Cluster = {
id: number;
id: string;
cites: Cite[];

@@ -52,3 +85,3 @@ };

export type ClusterPosition = {
id: number;
id: string;
/** Leaving off this field means this cluster is in-text. */

@@ -58,2 +91,4 @@ note?: number;

export type Reference = {

@@ -67,4 +102,6 @@ id: string;

export interface BibliographyUpdate {
updatedEntries: { [key: string]: string };
updatedEntries: Map<string, string>;
entryIds?: string[];

@@ -74,26 +111,158 @@ }

export type UpdateSummary<Output = string> = {
clusters: [number, Output][];
clusters: [string, Output][];
bibliography?: BibliographyUpdate;
};
type InvalidCsl = {
severity: "Error" | "Warning";
type IncludeUncited = "None" | "All" | { Specific: string[] };
type BibEntry = {
id: string;
value: string;
};
type BibEntries = BibEntry[];
type FullRender = {
allClusters: Map<string, string>,
bibEntries: BibEntries,
};
type BibliographyMeta = {
maxOffset: number;
entrySpacing: number;
lineSpacing: number;
hangingIndent: boolean;
/** the second-field-align value of the CSL style */
secondFieldAlign: null | "flush" | "margin";
/** Format-specific metadata */
formatMeta: any,
};
type Severity = "Error" | "Warning";
interface InvalidCsl {
severity: Severity;
/** Relevant bytes in the provided XML */
range: {
start: number;
end: number;
start: number,
end: number,
};
message: string;
hint: string;
hint: string | undefined;
};
type ParseError = {
ParseError: string;
type StyleError = {
tag: "Invalid",
content: InvalidCsl[],
} | {
tag: "ParseError",
content: string,
} | {
/** Cannot use a dependent style to format citations, pass the parent style instead. */
tag: "DependentStyle",
content: {
requiredParent: string,
}
};
type Invalid = {
Invalid: InvalidCsl[];
type DriverError = {
tag: "UnknownOutputFormat",
content: string,
} | {
tag: "JsonError",
} | {
tag: "GetFetcherError",
} | {
tag: "NonExistentCluster",
content: string,
} | {
tag: "ReorderingError"
} | {
tag: "ReorderingErrorNumericId"
};
type StyleError = Partial<ParseError & Invalid>;
declare global {
/** Catch-all citeproc-rs Error subclass. */
declare class CiteprocRsError extends Error {
constructor(message: string);
}
declare class CiteprocRsDriverError extends CiteprocRsError {
data: DriverError;
constructor(message: string, data: DriverError);
}
declare class CslStyleError extends CiteprocRsError {
data: StyleError;
constructor(message: string, data: StyleError);
}
}
interface WasmResult<T> {
/** If this is an error, throws the error. */
unwrap(): T;
/** If this is an error, returns it, else throws. */
unwrap_err(): Error;
is_ok(): boolean;
is_err(): boolean;
/** If this is an error, returns the default value. */
unwrap_or(default: T): T;
/** If this is Ok, returns f(ok_val), else returns Err unmodified. */
map<R>(f: (t: T) => R): WasmResult<T>;
/** If this is Ok, returns f(ok_val), else returns the default value. */
map_or<R>(default: R, f: (t: T) => R): R;
}
type CitationFormat = "author-date" | "author" | "numeric" | "label" | "note";
interface LocalizedString {
value: string,
lang?: string,
}
interface ParentLink {
href: string,
lang?: string,
}
interface Link {
href: string,
rel: "self" | "documentation" | "template",
lang?: string,
}
interface Rights {
value: string,
lang?: string,
license?: string,
}
interface StyleInfo {
id: string,
updated: string,
title: LocalizedString,
titleShort?: LocalizedString,
parent?: ParentLink,
links: Link[],
rights?: Rights,
citationFormat?: CitationFormat,
categories: string[],
issn?: string,
eissn?: string,
issnl?: string,
}
interface IndependentMeta {
/** A list of languages for which a locale override was specified.
* Does not include the language-less final override. */
localeOverrides: string[],
hasBibliography: bool,
}
interface StyleMeta {
info: StyleInfo,
features: { [feature: string]: bool },
defaultLocale: string,
/** May be absent on a dependent style */
class?: "in-text" | "note",
cslVersionRequired: string,
/** May be absent on a dependent style */
independentMeta?: IndependentMeta,
};
/**

@@ -107,30 +276,53 @@ */

* * `style` is a CSL style as a string. Independent styles only.
* * `lifecycle` must implement the `Lifecycle` interface
* * `fetcher` must implement the `Fetcher` interface
* * `format` is one of { "html", "rtf" }
*
* Throws an error if it cannot parse the style you gave it.
* @param {string} style
* @param {any} lifecycle
* @param {string} format
* @returns {Driver}
* @param {InitOptions} options
* @returns {WasmResult<Driver>}
*/
static new(style: string, lifecycle: any, format: string): Driver;
static new(options: InitOptions): WasmResult<Driver>;
/**
* Sets the style (which will also cause everything to be recomputed)
* @param {string} style_text
* @returns {any}
* @param {string} style_text
* @returns {WasmResult<undefined>}
*/
setStyle(style_text: string): any;
setStyle(style_text: string): WasmResult<undefined>;
/**
* Completely overwrites the references library.
* This **will** delete references that are not in the provided list.
* @param {any[]} refs
* @returns {WasmResult<undefined>}
*/
resetReferences(refs: any[]): WasmResult<undefined>;
/**
* Inserts or overwrites references as a batch operation.
* @param {any[]} refs
* This **will not** delete references that are not in the provided list.
* @param {any[]} refs
* @returns {WasmResult<undefined>}
*/
setReferences(refs: any[]): void;
insertReferences(refs: any[]): WasmResult<undefined>;
/**
* Inserts or overwrites a reference.
*
* * `refr` is a Reference object.
* @param {Reference} refr
* @returns {WasmResult<undefined>}
*/
insertReference(refr: Reference): WasmResult<undefined>;
/**
* Removes a reference by id. If it is cited, any cites will be dangling. It will also
* disappear from the bibliography.
* @param {string} id
* @returns {WasmResult<undefined>}
*/
removeReference(id: string): WasmResult<undefined>;
/**
* Sets the references to be included in the bibliography despite not being directly cited.
*
* * `refr` is a
* @param {any} refr
* @param {IncludeUncited} uncited
* @returns {WasmResult<undefined>}
*/
insertReference(refr: any): void;
includeUncited(uncited: IncludeUncited): WasmResult<undefined>;
/**

@@ -140,15 +332,22 @@ * Gets a list of locales in use by the references currently loaded.

* Note that Driver comes pre-loaded with the `en-US` locale.
* @returns {any}
* @returns {WasmResult<string[]>}
*/
toFetch(): any;
toFetch(): WasmResult<string[]>;
/**
* Returns a random cluster id, with an extra guarantee that it isn't already in use.
* @returns {string}
*/
randomClusterId(): string;
/**
* Inserts or replaces a cluster with a matching `id`.
* @param {any} cluster_id
* @param {any} cluster
* @returns {WasmResult<undefined>}
*/
insertCluster(cluster_id: any): void;
insertCluster(cluster: any): WasmResult<undefined>;
/**
* Removes a cluster with a matching `id`
* @param {number} cluster_id
* @param {string} cluster_id
* @returns {WasmResult<undefined>}
*/
removeCluster(cluster_id: number): void;
removeCluster(cluster_id: string): WasmResult<undefined>;
/**

@@ -158,5 +357,6 @@ * Resets all the clusters in the processor to a new list.

* * `clusters` is a Cluster[]
* @param {any[]} clusters
* @param {any[]} clusters
* @returns {WasmResult<undefined>}
*/
initClusters(clusters: any[]): void;
initClusters(clusters: any[]): WasmResult<undefined>;
/**

@@ -167,37 +367,28 @@ * Returns the formatted citation cluster for `cluster_id`.

* still useful for initialization.
* @param {number} id
* @returns {any}
* @param {string} id
* @returns {WasmResult<string>}
*/
builtCluster(id: number): any;
builtCluster(id: string): WasmResult<string>;
/**
* @returns {any}
* Previews a formatted citation cluster, in a particular position.
*
* - `cites`: The cites to go in the cluster
* - `positions`: An array of `ClusterPosition`s as in set_cluster_order, but with a single
* cluster's id set to zero. The cluster with id=0 is the position to preview the cite. It
* can replace another cluster, or be inserted before/after/between existing clusters, in
* any location you can think of.
* @param {any[]} cites
* @param {any[]} positions
* @param {string} format
* @returns {WasmResult<string>}
*/
makeBibliography(): any;
previewCitationCluster(cites: any[], positions: any[], format: string): WasmResult<string>;
/**
* @returns {any}
* @returns {WasmResult<BibEntries>}
*/
bibliographyMeta(): any;
makeBibliography(): WasmResult<BibEntries>;
/**
* Replaces cluster numberings in one go.
*
* * `mappings` is an `Array<[ ClusterId, ClusterNumber ]>` where `ClusterNumber`
* is, e.g. `{ note: 1 }`, `{ note: [3, 1] }` or `{ inText: 5 }` in the same way a
* Cluster must contain one of those three numberings.
*
* Not every ClusterId must appear in the array, just the ones you wish to renumber.
*
* The library consumer is responsible for ensuring that clusters are well-ordered. Clusters
* are sorted for determining cite positions (ibid, subsequent, etc). If a footnote is
* deleted, you will likely need to shift all cluster numbers after it back by one.
*
* The second note numbering, `{note: [3, 1]}`, is for having multiple clusters in a single
* footnote. This is possible in many editors. The second number acts as a second sorting
* key.
*
* The third note numbering, `{ inText: 5 }`, is for ordering in-text references that appear
* within the body of a document. These will be sorted but won't cause
* `first-reference-note-number` to become available.
* @param {any[]} mappings
* @returns {WasmResult<BibliographyMeta>}
*/
renumberClusters(mappings: any[]): void;
bibliographyMeta(): WasmResult<BibliographyMeta>;
/**

@@ -227,5 +418,6 @@ * Specifies which clusters are actually considered to be in the document, and sets their

* May error without having set_cluster_ids, but with some set_cluster_note_number-s executed.
* @param {any[]} pieces
* @param {any[]} positions
* @returns {WasmResult<undefined>}
*/
setClusterOrder(pieces: any[]): void;
setClusterOrder(positions: any[]): WasmResult<undefined>;
/**

@@ -239,16 +431,22 @@ * Retrieve any clusters that have been touched since last time `batchedUpdates` was

* * returns an `UpdateSummary`
* @returns {any}
* @returns {WasmResult<UpdateSummary>}
*/
batchedUpdates(): any;
batchedUpdates(): WasmResult<UpdateSummary>;
/**
* Drains the `batchedUpdates` queue manually. Use it to avoid serializing an unneeded
* `UpdateSummary`.
* Returns all the clusters and bibliography entries in the document.
* Also drains the queue, just like batchedUpdates().
* Use this to rehydrate a document or run non-interactively.
* @returns {WasmResult<FullRender>}
*/
fullRender(): WasmResult<FullRender>;
/**
* Drains the `batchedUpdates` queue manually.
*/
drain(): void;
/**
* Asynchronously fetches all the locales that may be required, and saves them into the
* engine. Uses your provided `Lifecycle.fetchLocale` function.
* @returns {Promise<any>}
* engine. Uses your provided `Fetcher.fetchLocale` function.
* @returns {Promise<any>}
*/
fetchAll(): Promise<any>;
fetchLocales(): Promise<any>;
}
let imports = {};
imports['__wbindgen_placeholder__'] = module.exports;
let wasm;
const { WasmResult, CiteprocRsError, CiteprocRsDriverError, CslStyleError } = require(String.raw`./snippets/wasm-1883a0b9dcad429e/src/js/include.js`);
const { TextDecoder } = require(String.raw`util`);

@@ -12,16 +13,2 @@

let heap_next = heap.length;
function dropObject(idx) {
if (idx < 36) return;
heap[idx] = heap_next;
heap_next = idx;
}
function takeObject(idx) {
const ret = getObject(idx);
dropObject(idx);
return ret;
}
let WASM_VECTOR_LEN = 0;

@@ -54,11 +41,16 @@

function addHeapObject(obj) {
if (heap_next === heap.length) heap.push(heap.length + 1);
const idx = heap_next;
heap_next = heap[idx];
let heap_next = heap.length;
heap[idx] = obj;
return idx;
function dropObject(idx) {
if (idx < 36) return;
heap[idx] = heap_next;
heap_next = idx;
}
function takeObject(idx) {
const ret = getObject(idx);
dropObject(idx);
return ret;
}
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });

@@ -80,2 +72,11 @@

function addHeapObject(obj) {
if (heap_next === heap.length) heap.push(heap.length + 1);
const idx = heap_next;
heap_next = heap[idx];
heap[idx] = obj;
return idx;
}
function isLikeNone(x) {

@@ -86,3 +87,3 @@ return x === undefined || x === null;

function makeMutClosure(arg0, arg1, dtor, f) {
const state = { a: arg0, b: arg1, cnt: 1, dtor };
const state = { a: arg0, b: arg1, cnt: 1 };
const real = (...args) => {

@@ -98,18 +99,25 @@ // First up with a closure we increment the internal reference

} finally {
if (--state.cnt === 0) {
wasm.__wbindgen_export_2.get(state.dtor)(a, state.b);
} else {
state.a = a;
}
if (--state.cnt === 0) wasm.__wbindgen_export_2.get(dtor)(a, state.b);
else state.a = a;
}
};
real.original = state;
return real;
}
function __wbg_adapter_18(arg0, arg1, arg2) {
wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h18b461775fab0812(arg0, arg1, addHeapObject(arg2));
function __wbg_adapter_24(arg0, arg1, arg2) {
wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__ha382542df1b652c5(arg0, arg1, addHeapObject(arg2));
}
/**
* Parses a CSL style, either independent or dependent, and returns its metadata.
* @param {string} style
* @returns {WasmResult<StyleMeta>}
*/
module.exports.parseStyleMetadata = function(style) {
var ptr0 = passStringToWasm0(style, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
var len0 = WASM_VECTOR_LEN;
var ret = wasm.parseStyleMetadata(ptr0, len0);
return takeObject(ret);
};
let cachegetUint32Memory0 = null;

@@ -143,6 +151,9 @@ function getUint32Memory0() {

}
function __wbg_adapter_43(arg0, arg1, arg2, arg3) {
wasm.wasm_bindgen__convert__closures__invoke2_mut__h442d48e1eb0f8a8d(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
function __wbg_adapter_81(arg0, arg1, arg2, arg3) {
wasm.wasm_bindgen__convert__closures__invoke2_mut__h5b58866e158bfea3(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
}
function getArrayU8FromWasm0(ptr, len) {
return getUint8Memory0().subarray(ptr / 1, ptr / 1 + len);
}
/**

@@ -169,18 +180,12 @@ */

* * `style` is a CSL style as a string. Independent styles only.
* * `lifecycle` must implement the `Lifecycle` interface
* * `fetcher` must implement the `Fetcher` interface
* * `format` is one of { "html", "rtf" }
*
* Throws an error if it cannot parse the style you gave it.
* @param {string} style
* @param {any} lifecycle
* @param {string} format
* @returns {Driver}
* @param {InitOptions} options
* @returns {WasmResult<Driver>}
*/
static new(style, lifecycle, format) {
var ptr0 = passStringToWasm0(style, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
var len0 = WASM_VECTOR_LEN;
var ptr1 = passStringToWasm0(format, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
var len1 = WASM_VECTOR_LEN;
var ret = wasm.driver_new(ptr0, len0, addHeapObject(lifecycle), ptr1, len1);
return Driver.__wrap(ret);
static new(options) {
var ret = wasm.driver_new(addHeapObject(options));
return takeObject(ret);
}

@@ -190,3 +195,3 @@ /**

* @param {string} style_text
* @returns {any}
* @returns {WasmResult<undefined>}
*/

@@ -200,9 +205,24 @@ setStyle(style_text) {

/**
* Completely overwrites the references library.
* This **will** delete references that are not in the provided list.
* @param {any[]} refs
* @returns {WasmResult<undefined>}
*/
resetReferences(refs) {
var ptr0 = passArrayJsValueToWasm0(refs, wasm.__wbindgen_malloc);
var len0 = WASM_VECTOR_LEN;
var ret = wasm.driver_resetReferences(this.ptr, ptr0, len0);
return takeObject(ret);
}
/**
* Inserts or overwrites references as a batch operation.
* This **will not** delete references that are not in the provided list.
* @param {any[]} refs
* @returns {WasmResult<undefined>}
*/
setReferences(refs) {
insertReferences(refs) {
var ptr0 = passArrayJsValueToWasm0(refs, wasm.__wbindgen_malloc);
var len0 = WASM_VECTOR_LEN;
wasm.driver_setReferences(this.ptr, ptr0, len0);
var ret = wasm.driver_insertReferences(this.ptr, ptr0, len0);
return takeObject(ret);
}

@@ -212,13 +232,38 @@ /**

*
* * `refr` is a
* @param {any} refr
* * `refr` is a Reference object.
* @param {Reference} refr
* @returns {WasmResult<undefined>}
*/
insertReference(refr) {
wasm.driver_insertReference(this.ptr, addHeapObject(refr));
var ret = wasm.driver_insertReference(this.ptr, addHeapObject(refr));
return takeObject(ret);
}
/**
* Removes a reference by id. If it is cited, any cites will be dangling. It will also
* disappear from the bibliography.
* @param {string} id
* @returns {WasmResult<undefined>}
*/
removeReference(id) {
var ptr0 = passStringToWasm0(id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
var len0 = WASM_VECTOR_LEN;
var ret = wasm.driver_removeReference(this.ptr, ptr0, len0);
return takeObject(ret);
}
/**
* Sets the references to be included in the bibliography despite not being directly cited.
*
* * `refr` is a
* @param {IncludeUncited} uncited
* @returns {WasmResult<undefined>}
*/
includeUncited(uncited) {
var ret = wasm.driver_includeUncited(this.ptr, addHeapObject(uncited));
return takeObject(ret);
}
/**
* Gets a list of locales in use by the references currently loaded.
*
* Note that Driver comes pre-loaded with the `en-US` locale.
* @returns {any}
* @returns {WasmResult<string[]>}
*/

@@ -230,14 +275,34 @@ toFetch() {

/**
* Returns a random cluster id, with an extra guarantee that it isn't already in use.
* @returns {string}
*/
randomClusterId() {
try {
wasm.driver_randomClusterId(8, this.ptr);
var r0 = getInt32Memory0()[8 / 4 + 0];
var r1 = getInt32Memory0()[8 / 4 + 1];
return getStringFromWasm0(r0, r1);
} finally {
wasm.__wbindgen_free(r0, r1);
}
}
/**
* Inserts or replaces a cluster with a matching `id`.
* @param {any} cluster_id
* @param {any} cluster
* @returns {WasmResult<undefined>}
*/
insertCluster(cluster_id) {
wasm.driver_insertCluster(this.ptr, addHeapObject(cluster_id));
insertCluster(cluster) {
var ret = wasm.driver_insertCluster(this.ptr, addHeapObject(cluster));
return takeObject(ret);
}
/**
* Removes a cluster with a matching `id`
* @param {number} cluster_id
* @param {string} cluster_id
* @returns {WasmResult<undefined>}
*/
removeCluster(cluster_id) {
wasm.driver_removeCluster(this.ptr, cluster_id);
var ptr0 = passStringToWasm0(cluster_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
var len0 = WASM_VECTOR_LEN;
var ret = wasm.driver_removeCluster(this.ptr, ptr0, len0);
return takeObject(ret);
}

@@ -249,2 +314,3 @@ /**

* @param {any[]} clusters
* @returns {WasmResult<undefined>}
*/

@@ -254,3 +320,4 @@ initClusters(clusters) {

var len0 = WASM_VECTOR_LEN;
wasm.driver_initClusters(this.ptr, ptr0, len0);
var ret = wasm.driver_initClusters(this.ptr, ptr0, len0);
return takeObject(ret);
}

@@ -262,12 +329,37 @@ /**

* still useful for initialization.
* @param {number} id
* @returns {any}
* @param {string} id
* @returns {WasmResult<string>}
*/
builtCluster(id) {
var ret = wasm.driver_builtCluster(this.ptr, id);
var ptr0 = passStringToWasm0(id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
var len0 = WASM_VECTOR_LEN;
var ret = wasm.driver_builtCluster(this.ptr, ptr0, len0);
return takeObject(ret);
}
/**
* @returns {any}
* Previews a formatted citation cluster, in a particular position.
*
* - `cites`: The cites to go in the cluster
* - `positions`: An array of `ClusterPosition`s as in set_cluster_order, but with a single
* cluster's id set to zero. The cluster with id=0 is the position to preview the cite. It
* can replace another cluster, or be inserted before/after/between existing clusters, in
* any location you can think of.
* @param {any[]} cites
* @param {any[]} positions
* @param {string} format
* @returns {WasmResult<string>}
*/
previewCitationCluster(cites, positions, format) {
var ptr0 = passArrayJsValueToWasm0(cites, wasm.__wbindgen_malloc);
var len0 = WASM_VECTOR_LEN;
var ptr1 = passArrayJsValueToWasm0(positions, wasm.__wbindgen_malloc);
var len1 = WASM_VECTOR_LEN;
var ptr2 = passStringToWasm0(format, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
var len2 = WASM_VECTOR_LEN;
var ret = wasm.driver_previewCitationCluster(this.ptr, ptr0, len0, ptr1, len1, ptr2, len2);
return takeObject(ret);
}
/**
* @returns {WasmResult<BibEntries>}
*/
makeBibliography() {

@@ -278,3 +370,3 @@ var ret = wasm.driver_makeBibliography(this.ptr);

/**
* @returns {any}
* @returns {WasmResult<BibliographyMeta>}
*/

@@ -286,29 +378,2 @@ bibliographyMeta() {

/**
* Replaces cluster numberings in one go.
*
* * `mappings` is an `Array<[ ClusterId, ClusterNumber ]>` where `ClusterNumber`
* is, e.g. `{ note: 1 }`, `{ note: [3, 1] }` or `{ inText: 5 }` in the same way a
* Cluster must contain one of those three numberings.
*
* Not every ClusterId must appear in the array, just the ones you wish to renumber.
*
* The library consumer is responsible for ensuring that clusters are well-ordered. Clusters
* are sorted for determining cite positions (ibid, subsequent, etc). If a footnote is
* deleted, you will likely need to shift all cluster numbers after it back by one.
*
* The second note numbering, `{note: [3, 1]}`, is for having multiple clusters in a single
* footnote. This is possible in many editors. The second number acts as a second sorting
* key.
*
* The third note numbering, `{ inText: 5 }`, is for ordering in-text references that appear
* within the body of a document. These will be sorted but won't cause
* `first-reference-note-number` to become available.
* @param {any[]} mappings
*/
renumberClusters(mappings) {
var ptr0 = passArrayJsValueToWasm0(mappings, wasm.__wbindgen_malloc);
var len0 = WASM_VECTOR_LEN;
wasm.driver_renumberClusters(this.ptr, ptr0, len0);
}
/**
* Specifies which clusters are actually considered to be in the document, and sets their

@@ -337,8 +402,10 @@ * order. You may insert as many clusters as you like, but the ones provided here are the only

* May error without having set_cluster_ids, but with some set_cluster_note_number-s executed.
* @param {any[]} pieces
* @param {any[]} positions
* @returns {WasmResult<undefined>}
*/
setClusterOrder(pieces) {
var ptr0 = passArrayJsValueToWasm0(pieces, wasm.__wbindgen_malloc);
setClusterOrder(positions) {
var ptr0 = passArrayJsValueToWasm0(positions, wasm.__wbindgen_malloc);
var len0 = WASM_VECTOR_LEN;
wasm.driver_setClusterOrder(this.ptr, ptr0, len0);
var ret = wasm.driver_setClusterOrder(this.ptr, ptr0, len0);
return takeObject(ret);
}

@@ -353,3 +420,3 @@ /**

* * returns an `UpdateSummary`
* @returns {any}
* @returns {WasmResult<UpdateSummary>}
*/

@@ -361,5 +428,14 @@ batchedUpdates() {

/**
* Drains the `batchedUpdates` queue manually. Use it to avoid serializing an unneeded
* `UpdateSummary`.
* Returns all the clusters and bibliography entries in the document.
* Also drains the queue, just like batchedUpdates().
* Use this to rehydrate a document or run non-interactively.
* @returns {WasmResult<FullRender>}
*/
fullRender() {
var ret = wasm.driver_fullRender(this.ptr);
return takeObject(ret);
}
/**
* Drains the `batchedUpdates` queue manually.
*/
drain() {

@@ -370,7 +446,7 @@ wasm.driver_drain(this.ptr);

* Asynchronously fetches all the locales that may be required, and saves them into the
* engine. Uses your provided `Lifecycle.fetchLocale` function.
* engine. Uses your provided `Fetcher.fetchLocale` function.
* @returns {Promise<any>}
*/
fetchAll() {
var ret = wasm.driver_fetchAll(this.ptr);
fetchLocales() {
var ret = wasm.driver_fetchLocales(this.ptr);
return takeObject(ret);

@@ -381,10 +457,2 @@ }

module.exports.__wbindgen_object_drop_ref = function(arg0) {
takeObject(arg0);
};
module.exports.__wbg_error_e549f7fed6d655aa = function(arg0) {
console.error(takeObject(arg0));
};
module.exports.__wbindgen_json_serialize = function(arg0, arg1) {

@@ -399,12 +467,46 @@ const obj = getObject(arg1);

module.exports.__wbindgen_object_clone_ref = function(arg0) {
var ret = getObject(arg0);
module.exports.__wbg_fetchLocale_d644d4ae2ca50f81 = function(arg0, arg1, arg2) {
var ret = getObject(arg0).fetchLocale(getStringFromWasm0(arg1, arg2));
return addHeapObject(ret);
};
module.exports.__wbg_fetchLocale_8f52b973b0739a6c = function(arg0, arg1, arg2) {
var ret = getObject(arg0).fetchLocale(getStringFromWasm0(arg1, arg2));
module.exports.__wbindgen_object_drop_ref = function(arg0) {
takeObject(arg0);
};
module.exports.__wbg_debug_4885c3f7d6f044a3 = function(arg0, arg1) {
console.debug(getStringFromWasm0(arg0, arg1));
};
module.exports.__wbg_log_bee3ea1a89f334d8 = function(arg0, arg1) {
console.log(getStringFromWasm0(arg0, arg1));
};
module.exports.__wbg_info_0547ff9513f2019b = function(arg0, arg1) {
console.info(getStringFromWasm0(arg0, arg1));
};
module.exports.__wbg_warn_a478dea6e6e05394 = function(arg0, arg1) {
console.warn(getStringFromWasm0(arg0, arg1));
};
module.exports.__wbg_error_72e88ba6901b6eee = function(arg0, arg1) {
console.error(getStringFromWasm0(arg0, arg1));
};
module.exports.__wbg_get_1edc26456ed84f9b = function(arg0, arg1) {
var ret = getObject(arg0)[takeObject(arg1)];
return addHeapObject(ret);
};
module.exports.__wbindgen_string_new = function(arg0, arg1) {
var ret = getStringFromWasm0(arg0, arg1);
return addHeapObject(ret);
};
module.exports.__wbindgen_json_parse = function(arg0, arg1) {
var ret = JSON.parse(getStringFromWasm0(arg0, arg1));
return addHeapObject(ret);
};
module.exports.__wbindgen_cb_drop = function(arg0) {

@@ -420,13 +522,74 @@ const obj = takeObject(arg0).original;

module.exports.__wbindgen_json_parse = function(arg0, arg1) {
var ret = JSON.parse(getStringFromWasm0(arg0, arg1));
module.exports.__wbg_driver_new = function(arg0) {
var ret = Driver.__wrap(arg0);
return addHeapObject(ret);
};
module.exports.__wbg_new_4896ab6bba55e0d9 = function(arg0, arg1) {
var ret = new Error(getStringFromWasm0(arg0, arg1));
module.exports.__wbindgen_object_clone_ref = function(arg0) {
var ret = getObject(arg0);
return addHeapObject(ret);
};
module.exports.__wbg_call_0dad7db75ec90ae7 = handleError(function(arg0, arg1, arg2) {
module.exports.__wbg_new_f12987d5c30f0ab7 = function(arg0) {
var ret = new CiteprocRsError(takeObject(arg0));
return addHeapObject(ret);
};
module.exports.__wbg_new_c5e56e6577bc2b6a = function(arg0, arg1) {
var ret = new CslStyleError(takeObject(arg0), takeObject(arg1));
return addHeapObject(ret);
};
module.exports.__wbg_new_6edca5ab9ee61764 = function(arg0) {
var ret = new WasmResult(takeObject(arg0));
return addHeapObject(ret);
};
module.exports.__wbg_new_8d5f3cd64eaaa8b5 = function(arg0, arg1) {
var ret = new CiteprocRsDriverError(takeObject(arg0), takeObject(arg1));
return addHeapObject(ret);
};
module.exports.__wbindgen_is_undefined = function(arg0) {
var ret = getObject(arg0) === undefined;
return ret;
};
module.exports.__wbindgen_is_object = function(arg0) {
const val = getObject(arg0);
var ret = typeof(val) === 'object' && val !== null;
return ret;
};
module.exports.__wbindgen_is_function = function(arg0) {
var ret = typeof(getObject(arg0)) === 'function';
return ret;
};
module.exports.__wbg_error_e549f7fed6d655aa = function(arg0) {
console.error(takeObject(arg0));
};
module.exports.__wbg_new_59cb74e423758ede = function() {
var ret = new Error();
return addHeapObject(ret);
};
module.exports.__wbg_stack_558ba5917b466edd = function(arg0, arg1) {
var ret = getObject(arg1).stack;
var ptr0 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
var len0 = WASM_VECTOR_LEN;
getInt32Memory0()[arg0 / 4 + 1] = len0;
getInt32Memory0()[arg0 / 4 + 0] = ptr0;
};
module.exports.__wbg_error_4bb6c2a97407129a = function(arg0, arg1) {
try {
console.error(getStringFromWasm0(arg0, arg1));
} finally {
wasm.__wbindgen_free(arg0, arg1);
}
};
module.exports.__wbg_call_0246f1c8ff252fb6 = handleError(function(arg0, arg1, arg2) {
var ret = getObject(arg0).call(getObject(arg1), getObject(arg2));

@@ -436,3 +599,3 @@ return addHeapObject(ret);

module.exports.__wbg_new_7039bf8b99f049e1 = function(arg0, arg1) {
module.exports.__wbg_new_09f2ad087112acf0 = function(arg0, arg1) {
try {

@@ -444,3 +607,3 @@ var state0 = {a: arg0, b: arg1};

try {
return __wbg_adapter_43(a, state0.b, arg0, arg1);
return __wbg_adapter_81(a, state0.b, arg0, arg1);
} finally {

@@ -457,3 +620,3 @@ state0.a = a;

module.exports.__wbg_resolve_4df26938859b92e3 = function(arg0) {
module.exports.__wbg_resolve_708df7651c8929b8 = function(arg0) {
var ret = Promise.resolve(getObject(arg0));

@@ -463,3 +626,3 @@ return addHeapObject(ret);

module.exports.__wbg_then_ffb6e71f7a6735ad = function(arg0, arg1) {
module.exports.__wbg_then_8c23dce80c84c8fb = function(arg0, arg1) {
var ret = getObject(arg0).then(getObject(arg1));

@@ -469,3 +632,3 @@ return addHeapObject(ret);

module.exports.__wbg_then_021fcdc7f0350b58 = function(arg0, arg1, arg2) {
module.exports.__wbg_then_300153bb889a5b4b = function(arg0, arg1, arg2) {
var ret = getObject(arg0).then(getObject(arg1), getObject(arg2));

@@ -475,2 +638,40 @@ return addHeapObject(ret);

module.exports.__wbg_getRandomValues_3ac1b33c90b52596 = function(arg0, arg1, arg2) {
getObject(arg0).getRandomValues(getArrayU8FromWasm0(arg1, arg2));
};
module.exports.__wbg_randomFillSync_6f956029658662ec = function(arg0, arg1, arg2) {
getObject(arg0).randomFillSync(getArrayU8FromWasm0(arg1, arg2));
};
module.exports.__wbg_self_1c83eb4471d9eb9b = handleError(function() {
var ret = self.self;
return addHeapObject(ret);
});
module.exports.__wbg_static_accessor_MODULE_abf5ae284bffdf45 = function() {
var ret = module;
return addHeapObject(ret);
};
module.exports.__wbg_require_5b2b5b594d809d9f = function(arg0, arg1, arg2) {
var ret = getObject(arg0).require(getStringFromWasm0(arg1, arg2));
return addHeapObject(ret);
};
module.exports.__wbg_crypto_c12f14e810edcaa2 = function(arg0) {
var ret = getObject(arg0).crypto;
return addHeapObject(ret);
};
module.exports.__wbg_msCrypto_679be765111ba775 = function(arg0) {
var ret = getObject(arg0).msCrypto;
return addHeapObject(ret);
};
module.exports.__wbg_getRandomValues_05a60bf171bfc2be = function(arg0) {
var ret = getObject(arg0).getRandomValues;
return addHeapObject(ret);
};
module.exports.__wbindgen_string_get = function(arg0, arg1) {

@@ -489,8 +690,4 @@ const obj = getObject(arg1);

module.exports.__wbindgen_rethrow = function(arg0) {
throw takeObject(arg0);
};
module.exports.__wbindgen_closure_wrapper847 = function(arg0, arg1, arg2) {
var ret = makeMutClosure(arg0, arg1, 88, __wbg_adapter_18);
module.exports.__wbindgen_closure_wrapper928 = function(arg0, arg1, arg2) {
var ret = makeMutClosure(arg0, arg1, 210, __wbg_adapter_24);
return addHeapObject(ret);

@@ -497,0 +694,0 @@ };

/* tslint:disable */
/* eslint-disable */
export const memory: WebAssembly.Memory;
export function parseStyleMetadata(a: number, b: number): number;
export function __wbg_driver_free(a: number): void;
export function driver_new(a: number, b: number, c: number, d: number, e: number): number;
export function driver_new(a: number): number;
export function driver_setStyle(a: number, b: number, c: number): number;
export function driver_setReferences(a: number, b: number, c: number): void;
export function driver_insertReference(a: number, b: number): void;
export function driver_resetReferences(a: number, b: number, c: number): number;
export function driver_insertReferences(a: number, b: number, c: number): number;
export function driver_insertReference(a: number, b: number): number;
export function driver_removeReference(a: number, b: number, c: number): number;
export function driver_includeUncited(a: number, b: number): number;
export function driver_toFetch(a: number): number;
export function driver_insertCluster(a: number, b: number): void;
export function driver_removeCluster(a: number, b: number): void;
export function driver_initClusters(a: number, b: number, c: number): void;
export function driver_builtCluster(a: number, b: number): number;
export function driver_randomClusterId(a: number, b: number): void;
export function driver_insertCluster(a: number, b: number): number;
export function driver_removeCluster(a: number, b: number, c: number): number;
export function driver_initClusters(a: number, b: number, c: number): number;
export function driver_builtCluster(a: number, b: number, c: number): number;
export function driver_previewCitationCluster(a: number, b: number, c: number, d: number, e: number, f: number, g: number): number;
export function driver_makeBibliography(a: number): number;
export function driver_bibliographyMeta(a: number): number;
export function driver_renumberClusters(a: number, b: number, c: number): void;
export function driver_setClusterOrder(a: number, b: number, c: number): void;
export function driver_setClusterOrder(a: number, b: number, c: number): number;
export function driver_batchedUpdates(a: number): number;
export function driver_fullRender(a: number): number;
export function driver_drain(a: number): void;
export function driver_fetchAll(a: number): number;
export function driver_fetchLocales(a: number): number;
export function __wbindgen_malloc(a: number): number;
export function __wbindgen_realloc(a: number, b: number, c: number): number;
export const __wbindgen_export_2: WebAssembly.Table;
export function _dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h18b461775fab0812(a: number, b: number, c: number): void;
export function _dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__ha382542df1b652c5(a: number, b: number, c: number): void;
export function __wbindgen_free(a: number, b: number): void;
export function __wbindgen_exn_store(a: number): void;
export function wasm_bindgen__convert__closures__invoke2_mut__h442d48e1eb0f8a8d(a: number, b: number, c: number, d: number): void;
export function wasm_bindgen__convert__closures__invoke2_mut__h5b58866e158bfea3(a: number, b: number, c: number, d: number): void;

@@ -0,1 +1,2 @@

import { WasmResult, CiteprocRsError, CiteprocRsDriverError, CslStyleError } from './snippets/wasm-1883a0b9dcad429e/src/js/include.js';
import * as wasm from './citeproc_rs_wasm_bg.wasm';

@@ -9,16 +10,2 @@

let heap_next = heap.length;
function dropObject(idx) {
if (idx < 36) return;
heap[idx] = heap_next;
heap_next = idx;
}
function takeObject(idx) {
const ret = getObject(idx);
dropObject(idx);
return ret;
}
let WASM_VECTOR_LEN = 0;

@@ -97,11 +84,16 @@

function addHeapObject(obj) {
if (heap_next === heap.length) heap.push(heap.length + 1);
const idx = heap_next;
heap_next = heap[idx];
let heap_next = heap.length;
heap[idx] = obj;
return idx;
function dropObject(idx) {
if (idx < 36) return;
heap[idx] = heap_next;
heap_next = idx;
}
function takeObject(idx) {
const ret = getObject(idx);
dropObject(idx);
return ret;
}
const lTextDecoder = typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder;

@@ -117,2 +109,11 @@

function addHeapObject(obj) {
if (heap_next === heap.length) heap.push(heap.length + 1);
const idx = heap_next;
heap_next = heap[idx];
heap[idx] = obj;
return idx;
}
function isLikeNone(x) {

@@ -123,3 +124,3 @@ return x === undefined || x === null;

function makeMutClosure(arg0, arg1, dtor, f) {
const state = { a: arg0, b: arg1, cnt: 1, dtor };
const state = { a: arg0, b: arg1, cnt: 1 };
const real = (...args) => {

@@ -135,18 +136,25 @@ // First up with a closure we increment the internal reference

} finally {
if (--state.cnt === 0) {
wasm.__wbindgen_export_2.get(state.dtor)(a, state.b);
} else {
state.a = a;
}
if (--state.cnt === 0) wasm.__wbindgen_export_2.get(dtor)(a, state.b);
else state.a = a;
}
};
real.original = state;
return real;
}
function __wbg_adapter_18(arg0, arg1, arg2) {
wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h18b461775fab0812(arg0, arg1, addHeapObject(arg2));
function __wbg_adapter_24(arg0, arg1, arg2) {
wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__ha382542df1b652c5(arg0, arg1, addHeapObject(arg2));
}
/**
* Parses a CSL style, either independent or dependent, and returns its metadata.
* @param {string} style
* @returns {WasmResult<StyleMeta>}
*/
export function parseStyleMetadata(style) {
var ptr0 = passStringToWasm0(style, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
var len0 = WASM_VECTOR_LEN;
var ret = wasm.parseStyleMetadata(ptr0, len0);
return takeObject(ret);
}
let cachegetUint32Memory0 = null;

@@ -180,6 +188,9 @@ function getUint32Memory0() {

}
function __wbg_adapter_43(arg0, arg1, arg2, arg3) {
wasm.wasm_bindgen__convert__closures__invoke2_mut__h442d48e1eb0f8a8d(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
function __wbg_adapter_81(arg0, arg1, arg2, arg3) {
wasm.wasm_bindgen__convert__closures__invoke2_mut__h5b58866e158bfea3(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
}
function getArrayU8FromWasm0(ptr, len) {
return getUint8Memory0().subarray(ptr / 1, ptr / 1 + len);
}
/**

@@ -206,18 +217,12 @@ */

* * `style` is a CSL style as a string. Independent styles only.
* * `lifecycle` must implement the `Lifecycle` interface
* * `fetcher` must implement the `Fetcher` interface
* * `format` is one of { "html", "rtf" }
*
* Throws an error if it cannot parse the style you gave it.
* @param {string} style
* @param {any} lifecycle
* @param {string} format
* @returns {Driver}
* @param {InitOptions} options
* @returns {WasmResult<Driver>}
*/
static new(style, lifecycle, format) {
var ptr0 = passStringToWasm0(style, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
var len0 = WASM_VECTOR_LEN;
var ptr1 = passStringToWasm0(format, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
var len1 = WASM_VECTOR_LEN;
var ret = wasm.driver_new(ptr0, len0, addHeapObject(lifecycle), ptr1, len1);
return Driver.__wrap(ret);
static new(options) {
var ret = wasm.driver_new(addHeapObject(options));
return takeObject(ret);
}

@@ -227,3 +232,3 @@ /**

* @param {string} style_text
* @returns {any}
* @returns {WasmResult<undefined>}
*/

@@ -237,9 +242,24 @@ setStyle(style_text) {

/**
* Completely overwrites the references library.
* This **will** delete references that are not in the provided list.
* @param {any[]} refs
* @returns {WasmResult<undefined>}
*/
resetReferences(refs) {
var ptr0 = passArrayJsValueToWasm0(refs, wasm.__wbindgen_malloc);
var len0 = WASM_VECTOR_LEN;
var ret = wasm.driver_resetReferences(this.ptr, ptr0, len0);
return takeObject(ret);
}
/**
* Inserts or overwrites references as a batch operation.
* This **will not** delete references that are not in the provided list.
* @param {any[]} refs
* @returns {WasmResult<undefined>}
*/
setReferences(refs) {
insertReferences(refs) {
var ptr0 = passArrayJsValueToWasm0(refs, wasm.__wbindgen_malloc);
var len0 = WASM_VECTOR_LEN;
wasm.driver_setReferences(this.ptr, ptr0, len0);
var ret = wasm.driver_insertReferences(this.ptr, ptr0, len0);
return takeObject(ret);
}

@@ -249,13 +269,38 @@ /**

*
* * `refr` is a
* @param {any} refr
* * `refr` is a Reference object.
* @param {Reference} refr
* @returns {WasmResult<undefined>}
*/
insertReference(refr) {
wasm.driver_insertReference(this.ptr, addHeapObject(refr));
var ret = wasm.driver_insertReference(this.ptr, addHeapObject(refr));
return takeObject(ret);
}
/**
* Removes a reference by id. If it is cited, any cites will be dangling. It will also
* disappear from the bibliography.
* @param {string} id
* @returns {WasmResult<undefined>}
*/
removeReference(id) {
var ptr0 = passStringToWasm0(id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
var len0 = WASM_VECTOR_LEN;
var ret = wasm.driver_removeReference(this.ptr, ptr0, len0);
return takeObject(ret);
}
/**
* Sets the references to be included in the bibliography despite not being directly cited.
*
* * `refr` is a
* @param {IncludeUncited} uncited
* @returns {WasmResult<undefined>}
*/
includeUncited(uncited) {
var ret = wasm.driver_includeUncited(this.ptr, addHeapObject(uncited));
return takeObject(ret);
}
/**
* Gets a list of locales in use by the references currently loaded.
*
* Note that Driver comes pre-loaded with the `en-US` locale.
* @returns {any}
* @returns {WasmResult<string[]>}
*/

@@ -267,14 +312,34 @@ toFetch() {

/**
* Returns a random cluster id, with an extra guarantee that it isn't already in use.
* @returns {string}
*/
randomClusterId() {
try {
wasm.driver_randomClusterId(8, this.ptr);
var r0 = getInt32Memory0()[8 / 4 + 0];
var r1 = getInt32Memory0()[8 / 4 + 1];
return getStringFromWasm0(r0, r1);
} finally {
wasm.__wbindgen_free(r0, r1);
}
}
/**
* Inserts or replaces a cluster with a matching `id`.
* @param {any} cluster_id
* @param {any} cluster
* @returns {WasmResult<undefined>}
*/
insertCluster(cluster_id) {
wasm.driver_insertCluster(this.ptr, addHeapObject(cluster_id));
insertCluster(cluster) {
var ret = wasm.driver_insertCluster(this.ptr, addHeapObject(cluster));
return takeObject(ret);
}
/**
* Removes a cluster with a matching `id`
* @param {number} cluster_id
* @param {string} cluster_id
* @returns {WasmResult<undefined>}
*/
removeCluster(cluster_id) {
wasm.driver_removeCluster(this.ptr, cluster_id);
var ptr0 = passStringToWasm0(cluster_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
var len0 = WASM_VECTOR_LEN;
var ret = wasm.driver_removeCluster(this.ptr, ptr0, len0);
return takeObject(ret);
}

@@ -286,2 +351,3 @@ /**

* @param {any[]} clusters
* @returns {WasmResult<undefined>}
*/

@@ -291,3 +357,4 @@ initClusters(clusters) {

var len0 = WASM_VECTOR_LEN;
wasm.driver_initClusters(this.ptr, ptr0, len0);
var ret = wasm.driver_initClusters(this.ptr, ptr0, len0);
return takeObject(ret);
}

@@ -299,12 +366,37 @@ /**

* still useful for initialization.
* @param {number} id
* @returns {any}
* @param {string} id
* @returns {WasmResult<string>}
*/
builtCluster(id) {
var ret = wasm.driver_builtCluster(this.ptr, id);
var ptr0 = passStringToWasm0(id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
var len0 = WASM_VECTOR_LEN;
var ret = wasm.driver_builtCluster(this.ptr, ptr0, len0);
return takeObject(ret);
}
/**
* @returns {any}
* Previews a formatted citation cluster, in a particular position.
*
* - `cites`: The cites to go in the cluster
* - `positions`: An array of `ClusterPosition`s as in set_cluster_order, but with a single
* cluster's id set to zero. The cluster with id=0 is the position to preview the cite. It
* can replace another cluster, or be inserted before/after/between existing clusters, in
* any location you can think of.
* @param {any[]} cites
* @param {any[]} positions
* @param {string} format
* @returns {WasmResult<string>}
*/
previewCitationCluster(cites, positions, format) {
var ptr0 = passArrayJsValueToWasm0(cites, wasm.__wbindgen_malloc);
var len0 = WASM_VECTOR_LEN;
var ptr1 = passArrayJsValueToWasm0(positions, wasm.__wbindgen_malloc);
var len1 = WASM_VECTOR_LEN;
var ptr2 = passStringToWasm0(format, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
var len2 = WASM_VECTOR_LEN;
var ret = wasm.driver_previewCitationCluster(this.ptr, ptr0, len0, ptr1, len1, ptr2, len2);
return takeObject(ret);
}
/**
* @returns {WasmResult<BibEntries>}
*/
makeBibliography() {

@@ -315,3 +407,3 @@ var ret = wasm.driver_makeBibliography(this.ptr);

/**
* @returns {any}
* @returns {WasmResult<BibliographyMeta>}
*/

@@ -323,29 +415,2 @@ bibliographyMeta() {

/**
* Replaces cluster numberings in one go.
*
* * `mappings` is an `Array<[ ClusterId, ClusterNumber ]>` where `ClusterNumber`
* is, e.g. `{ note: 1 }`, `{ note: [3, 1] }` or `{ inText: 5 }` in the same way a
* Cluster must contain one of those three numberings.
*
* Not every ClusterId must appear in the array, just the ones you wish to renumber.
*
* The library consumer is responsible for ensuring that clusters are well-ordered. Clusters
* are sorted for determining cite positions (ibid, subsequent, etc). If a footnote is
* deleted, you will likely need to shift all cluster numbers after it back by one.
*
* The second note numbering, `{note: [3, 1]}`, is for having multiple clusters in a single
* footnote. This is possible in many editors. The second number acts as a second sorting
* key.
*
* The third note numbering, `{ inText: 5 }`, is for ordering in-text references that appear
* within the body of a document. These will be sorted but won't cause
* `first-reference-note-number` to become available.
* @param {any[]} mappings
*/
renumberClusters(mappings) {
var ptr0 = passArrayJsValueToWasm0(mappings, wasm.__wbindgen_malloc);
var len0 = WASM_VECTOR_LEN;
wasm.driver_renumberClusters(this.ptr, ptr0, len0);
}
/**
* Specifies which clusters are actually considered to be in the document, and sets their

@@ -374,8 +439,10 @@ * order. You may insert as many clusters as you like, but the ones provided here are the only

* May error without having set_cluster_ids, but with some set_cluster_note_number-s executed.
* @param {any[]} pieces
* @param {any[]} positions
* @returns {WasmResult<undefined>}
*/
setClusterOrder(pieces) {
var ptr0 = passArrayJsValueToWasm0(pieces, wasm.__wbindgen_malloc);
setClusterOrder(positions) {
var ptr0 = passArrayJsValueToWasm0(positions, wasm.__wbindgen_malloc);
var len0 = WASM_VECTOR_LEN;
wasm.driver_setClusterOrder(this.ptr, ptr0, len0);
var ret = wasm.driver_setClusterOrder(this.ptr, ptr0, len0);
return takeObject(ret);
}

@@ -390,3 +457,3 @@ /**

* * returns an `UpdateSummary`
* @returns {any}
* @returns {WasmResult<UpdateSummary>}
*/

@@ -398,5 +465,14 @@ batchedUpdates() {

/**
* Drains the `batchedUpdates` queue manually. Use it to avoid serializing an unneeded
* `UpdateSummary`.
* Returns all the clusters and bibliography entries in the document.
* Also drains the queue, just like batchedUpdates().
* Use this to rehydrate a document or run non-interactively.
* @returns {WasmResult<FullRender>}
*/
fullRender() {
var ret = wasm.driver_fullRender(this.ptr);
return takeObject(ret);
}
/**
* Drains the `batchedUpdates` queue manually.
*/
drain() {

@@ -407,7 +483,7 @@ wasm.driver_drain(this.ptr);

* Asynchronously fetches all the locales that may be required, and saves them into the
* engine. Uses your provided `Lifecycle.fetchLocale` function.
* engine. Uses your provided `Fetcher.fetchLocale` function.
* @returns {Promise<any>}
*/
fetchAll() {
var ret = wasm.driver_fetchAll(this.ptr);
fetchLocales() {
var ret = wasm.driver_fetchLocales(this.ptr);
return takeObject(ret);

@@ -417,10 +493,2 @@ }

export const __wbindgen_object_drop_ref = function(arg0) {
takeObject(arg0);
};
export const __wbg_error_e549f7fed6d655aa = function(arg0) {
console.error(takeObject(arg0));
};
export const __wbindgen_json_serialize = function(arg0, arg1) {

@@ -435,12 +503,46 @@ const obj = getObject(arg1);

export const __wbindgen_object_clone_ref = function(arg0) {
var ret = getObject(arg0);
export const __wbg_fetchLocale_d644d4ae2ca50f81 = function(arg0, arg1, arg2) {
var ret = getObject(arg0).fetchLocale(getStringFromWasm0(arg1, arg2));
return addHeapObject(ret);
};
export const __wbg_fetchLocale_8f52b973b0739a6c = function(arg0, arg1, arg2) {
var ret = getObject(arg0).fetchLocale(getStringFromWasm0(arg1, arg2));
export const __wbindgen_object_drop_ref = function(arg0) {
takeObject(arg0);
};
export const __wbg_debug_4885c3f7d6f044a3 = function(arg0, arg1) {
console.debug(getStringFromWasm0(arg0, arg1));
};
export const __wbg_log_bee3ea1a89f334d8 = function(arg0, arg1) {
console.log(getStringFromWasm0(arg0, arg1));
};
export const __wbg_info_0547ff9513f2019b = function(arg0, arg1) {
console.info(getStringFromWasm0(arg0, arg1));
};
export const __wbg_warn_a478dea6e6e05394 = function(arg0, arg1) {
console.warn(getStringFromWasm0(arg0, arg1));
};
export const __wbg_error_72e88ba6901b6eee = function(arg0, arg1) {
console.error(getStringFromWasm0(arg0, arg1));
};
export const __wbg_get_1edc26456ed84f9b = function(arg0, arg1) {
var ret = getObject(arg0)[takeObject(arg1)];
return addHeapObject(ret);
};
export const __wbindgen_string_new = function(arg0, arg1) {
var ret = getStringFromWasm0(arg0, arg1);
return addHeapObject(ret);
};
export const __wbindgen_json_parse = function(arg0, arg1) {
var ret = JSON.parse(getStringFromWasm0(arg0, arg1));
return addHeapObject(ret);
};
export const __wbindgen_cb_drop = function(arg0) {

@@ -456,13 +558,74 @@ const obj = takeObject(arg0).original;

export const __wbindgen_json_parse = function(arg0, arg1) {
var ret = JSON.parse(getStringFromWasm0(arg0, arg1));
export const __wbg_driver_new = function(arg0) {
var ret = Driver.__wrap(arg0);
return addHeapObject(ret);
};
export const __wbg_new_4896ab6bba55e0d9 = function(arg0, arg1) {
var ret = new Error(getStringFromWasm0(arg0, arg1));
export const __wbindgen_object_clone_ref = function(arg0) {
var ret = getObject(arg0);
return addHeapObject(ret);
};
export const __wbg_call_0dad7db75ec90ae7 = handleError(function(arg0, arg1, arg2) {
export const __wbg_new_f12987d5c30f0ab7 = function(arg0) {
var ret = new CiteprocRsError(takeObject(arg0));
return addHeapObject(ret);
};
export const __wbg_new_c5e56e6577bc2b6a = function(arg0, arg1) {
var ret = new CslStyleError(takeObject(arg0), takeObject(arg1));
return addHeapObject(ret);
};
export const __wbg_new_6edca5ab9ee61764 = function(arg0) {
var ret = new WasmResult(takeObject(arg0));
return addHeapObject(ret);
};
export const __wbg_new_8d5f3cd64eaaa8b5 = function(arg0, arg1) {
var ret = new CiteprocRsDriverError(takeObject(arg0), takeObject(arg1));
return addHeapObject(ret);
};
export const __wbindgen_is_undefined = function(arg0) {
var ret = getObject(arg0) === undefined;
return ret;
};
export const __wbindgen_is_object = function(arg0) {
const val = getObject(arg0);
var ret = typeof(val) === 'object' && val !== null;
return ret;
};
export const __wbindgen_is_function = function(arg0) {
var ret = typeof(getObject(arg0)) === 'function';
return ret;
};
export const __wbg_error_e549f7fed6d655aa = function(arg0) {
console.error(takeObject(arg0));
};
export const __wbg_new_59cb74e423758ede = function() {
var ret = new Error();
return addHeapObject(ret);
};
export const __wbg_stack_558ba5917b466edd = function(arg0, arg1) {
var ret = getObject(arg1).stack;
var ptr0 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
var len0 = WASM_VECTOR_LEN;
getInt32Memory0()[arg0 / 4 + 1] = len0;
getInt32Memory0()[arg0 / 4 + 0] = ptr0;
};
export const __wbg_error_4bb6c2a97407129a = function(arg0, arg1) {
try {
console.error(getStringFromWasm0(arg0, arg1));
} finally {
wasm.__wbindgen_free(arg0, arg1);
}
};
export const __wbg_call_0246f1c8ff252fb6 = handleError(function(arg0, arg1, arg2) {
var ret = getObject(arg0).call(getObject(arg1), getObject(arg2));

@@ -472,3 +635,3 @@ return addHeapObject(ret);

export const __wbg_new_7039bf8b99f049e1 = function(arg0, arg1) {
export const __wbg_new_09f2ad087112acf0 = function(arg0, arg1) {
try {

@@ -480,3 +643,3 @@ var state0 = {a: arg0, b: arg1};

try {
return __wbg_adapter_43(a, state0.b, arg0, arg1);
return __wbg_adapter_81(a, state0.b, arg0, arg1);
} finally {

@@ -493,3 +656,3 @@ state0.a = a;

export const __wbg_resolve_4df26938859b92e3 = function(arg0) {
export const __wbg_resolve_708df7651c8929b8 = function(arg0) {
var ret = Promise.resolve(getObject(arg0));

@@ -499,3 +662,3 @@ return addHeapObject(ret);

export const __wbg_then_ffb6e71f7a6735ad = function(arg0, arg1) {
export const __wbg_then_8c23dce80c84c8fb = function(arg0, arg1) {
var ret = getObject(arg0).then(getObject(arg1));

@@ -505,3 +668,3 @@ return addHeapObject(ret);

export const __wbg_then_021fcdc7f0350b58 = function(arg0, arg1, arg2) {
export const __wbg_then_300153bb889a5b4b = function(arg0, arg1, arg2) {
var ret = getObject(arg0).then(getObject(arg1), getObject(arg2));

@@ -511,2 +674,40 @@ return addHeapObject(ret);

export const __wbg_getRandomValues_3ac1b33c90b52596 = function(arg0, arg1, arg2) {
getObject(arg0).getRandomValues(getArrayU8FromWasm0(arg1, arg2));
};
export const __wbg_randomFillSync_6f956029658662ec = function(arg0, arg1, arg2) {
getObject(arg0).randomFillSync(getArrayU8FromWasm0(arg1, arg2));
};
export const __wbg_self_1c83eb4471d9eb9b = handleError(function() {
var ret = self.self;
return addHeapObject(ret);
});
export const __wbg_static_accessor_MODULE_abf5ae284bffdf45 = function() {
var ret = module;
return addHeapObject(ret);
};
export const __wbg_require_5b2b5b594d809d9f = function(arg0, arg1, arg2) {
var ret = getObject(arg0).require(getStringFromWasm0(arg1, arg2));
return addHeapObject(ret);
};
export const __wbg_crypto_c12f14e810edcaa2 = function(arg0) {
var ret = getObject(arg0).crypto;
return addHeapObject(ret);
};
export const __wbg_msCrypto_679be765111ba775 = function(arg0) {
var ret = getObject(arg0).msCrypto;
return addHeapObject(ret);
};
export const __wbg_getRandomValues_05a60bf171bfc2be = function(arg0) {
var ret = getObject(arg0).getRandomValues;
return addHeapObject(ret);
};
export const __wbindgen_string_get = function(arg0, arg1) {

@@ -525,10 +726,6 @@ const obj = getObject(arg1);

export const __wbindgen_rethrow = function(arg0) {
throw takeObject(arg0);
};
export const __wbindgen_closure_wrapper847 = function(arg0, arg1, arg2) {
var ret = makeMutClosure(arg0, arg1, 88, __wbg_adapter_18);
export const __wbindgen_closure_wrapper928 = function(arg0, arg1, arg2) {
var ret = makeMutClosure(arg0, arg1, 210, __wbg_adapter_24);
return addHeapObject(ret);
};
/* tslint:disable */
/* eslint-disable */
/**
* Parses a CSL style, either independent or dependent, and returns its metadata.
* @param {string} style
* @returns {WasmResult<StyleMeta>}
*/
export function parseStyleMetadata(style: string): WasmResult<StyleMeta>;
interface InitOptions {
/** A CSL style as an XML string */
style: string,
/** A Fetcher implementation for fetching locales.
*
* If not provided, then no locales can be fetched, and default-locale and localeOverride will
* not be respected; the only locale used will be the bundled en-US. */
fetcher?: Fetcher,
/** The output format for this driver instance */
format: "html" | "rtf" | "plain",
/** A locale to use instead of the style's default-locale.
*
* For dependent styles, use parseStyleMetadata to find out which locale it prefers, and pass
* in the parent style with a localeOverride set to that value.
*/
localeOverride?: string,
/** Disables sorting in the bibliography; items appear in cited order. */
bibliographyNoSort?: bool,
}
/** This interface lets citeproc retrieve locales or modules asynchronously,
according to which ones are needed. */
export interface Lifecycle {
export interface Fetcher {
/** Return locale XML for a particular locale. */

@@ -12,2 +41,4 @@ fetchLocale(lang: string): Promise<string>;

export type DateLiteral = { "literal": string; };

@@ -21,2 +52,4 @@ export type DateRaw = { "raw": string; };

/** Locator type, and a locator string */

@@ -36,3 +69,3 @@ export type Locator = {

suppression?: "InText" | "Rest" | null;
} & CiteLocator;
} & Partial<CiteLocator>;

@@ -46,3 +79,3 @@ export type ClusterNumber = {

export type Cluster = {
id: number;
id: string;
cites: Cite[];

@@ -52,3 +85,3 @@ };

export type ClusterPosition = {
id: number;
id: string;
/** Leaving off this field means this cluster is in-text. */

@@ -58,2 +91,4 @@ note?: number;

export type Reference = {

@@ -67,4 +102,6 @@ id: string;

export interface BibliographyUpdate {
updatedEntries: { [key: string]: string };
updatedEntries: Map<string, string>;
entryIds?: string[];

@@ -74,26 +111,158 @@ }

export type UpdateSummary<Output = string> = {
clusters: [number, Output][];
clusters: [string, Output][];
bibliography?: BibliographyUpdate;
};
type InvalidCsl = {
severity: "Error" | "Warning";
type IncludeUncited = "None" | "All" | { Specific: string[] };
type BibEntry = {
id: string;
value: string;
};
type BibEntries = BibEntry[];
type FullRender = {
allClusters: Map<string, string>,
bibEntries: BibEntries,
};
type BibliographyMeta = {
maxOffset: number;
entrySpacing: number;
lineSpacing: number;
hangingIndent: boolean;
/** the second-field-align value of the CSL style */
secondFieldAlign: null | "flush" | "margin";
/** Format-specific metadata */
formatMeta: any,
};
type Severity = "Error" | "Warning";
interface InvalidCsl {
severity: Severity;
/** Relevant bytes in the provided XML */
range: {
start: number;
end: number;
start: number,
end: number,
};
message: string;
hint: string;
hint: string | undefined;
};
type ParseError = {
ParseError: string;
type StyleError = {
tag: "Invalid",
content: InvalidCsl[],
} | {
tag: "ParseError",
content: string,
} | {
/** Cannot use a dependent style to format citations, pass the parent style instead. */
tag: "DependentStyle",
content: {
requiredParent: string,
}
};
type Invalid = {
Invalid: InvalidCsl[];
type DriverError = {
tag: "UnknownOutputFormat",
content: string,
} | {
tag: "JsonError",
} | {
tag: "GetFetcherError",
} | {
tag: "NonExistentCluster",
content: string,
} | {
tag: "ReorderingError"
} | {
tag: "ReorderingErrorNumericId"
};
type StyleError = Partial<ParseError & Invalid>;
declare global {
/** Catch-all citeproc-rs Error subclass. */
declare class CiteprocRsError extends Error {
constructor(message: string);
}
declare class CiteprocRsDriverError extends CiteprocRsError {
data: DriverError;
constructor(message: string, data: DriverError);
}
declare class CslStyleError extends CiteprocRsError {
data: StyleError;
constructor(message: string, data: StyleError);
}
}
interface WasmResult<T> {
/** If this is an error, throws the error. */
unwrap(): T;
/** If this is an error, returns it, else throws. */
unwrap_err(): Error;
is_ok(): boolean;
is_err(): boolean;
/** If this is an error, returns the default value. */
unwrap_or(default: T): T;
/** If this is Ok, returns f(ok_val), else returns Err unmodified. */
map<R>(f: (t: T) => R): WasmResult<T>;
/** If this is Ok, returns f(ok_val), else returns the default value. */
map_or<R>(default: R, f: (t: T) => R): R;
}
type CitationFormat = "author-date" | "author" | "numeric" | "label" | "note";
interface LocalizedString {
value: string,
lang?: string,
}
interface ParentLink {
href: string,
lang?: string,
}
interface Link {
href: string,
rel: "self" | "documentation" | "template",
lang?: string,
}
interface Rights {
value: string,
lang?: string,
license?: string,
}
interface StyleInfo {
id: string,
updated: string,
title: LocalizedString,
titleShort?: LocalizedString,
parent?: ParentLink,
links: Link[],
rights?: Rights,
citationFormat?: CitationFormat,
categories: string[],
issn?: string,
eissn?: string,
issnl?: string,
}
interface IndependentMeta {
/** A list of languages for which a locale override was specified.
* Does not include the language-less final override. */
localeOverrides: string[],
hasBibliography: bool,
}
interface StyleMeta {
info: StyleInfo,
features: { [feature: string]: bool },
defaultLocale: string,
/** May be absent on a dependent style */
class?: "in-text" | "note",
cslVersionRequired: string,
/** May be absent on a dependent style */
independentMeta?: IndependentMeta,
};
/**

@@ -107,30 +276,53 @@ */

* * `style` is a CSL style as a string. Independent styles only.
* * `lifecycle` must implement the `Lifecycle` interface
* * `fetcher` must implement the `Fetcher` interface
* * `format` is one of { "html", "rtf" }
*
* Throws an error if it cannot parse the style you gave it.
* @param {string} style
* @param {any} lifecycle
* @param {string} format
* @returns {Driver}
* @param {InitOptions} options
* @returns {WasmResult<Driver>}
*/
static new(style: string, lifecycle: any, format: string): Driver;
static new(options: InitOptions): WasmResult<Driver>;
/**
* Sets the style (which will also cause everything to be recomputed)
* @param {string} style_text
* @returns {any}
* @param {string} style_text
* @returns {WasmResult<undefined>}
*/
setStyle(style_text: string): any;
setStyle(style_text: string): WasmResult<undefined>;
/**
* Completely overwrites the references library.
* This **will** delete references that are not in the provided list.
* @param {any[]} refs
* @returns {WasmResult<undefined>}
*/
resetReferences(refs: any[]): WasmResult<undefined>;
/**
* Inserts or overwrites references as a batch operation.
* @param {any[]} refs
* This **will not** delete references that are not in the provided list.
* @param {any[]} refs
* @returns {WasmResult<undefined>}
*/
setReferences(refs: any[]): void;
insertReferences(refs: any[]): WasmResult<undefined>;
/**
* Inserts or overwrites a reference.
*
* * `refr` is a Reference object.
* @param {Reference} refr
* @returns {WasmResult<undefined>}
*/
insertReference(refr: Reference): WasmResult<undefined>;
/**
* Removes a reference by id. If it is cited, any cites will be dangling. It will also
* disappear from the bibliography.
* @param {string} id
* @returns {WasmResult<undefined>}
*/
removeReference(id: string): WasmResult<undefined>;
/**
* Sets the references to be included in the bibliography despite not being directly cited.
*
* * `refr` is a
* @param {any} refr
* @param {IncludeUncited} uncited
* @returns {WasmResult<undefined>}
*/
insertReference(refr: any): void;
includeUncited(uncited: IncludeUncited): WasmResult<undefined>;
/**

@@ -140,15 +332,22 @@ * Gets a list of locales in use by the references currently loaded.

* Note that Driver comes pre-loaded with the `en-US` locale.
* @returns {any}
* @returns {WasmResult<string[]>}
*/
toFetch(): any;
toFetch(): WasmResult<string[]>;
/**
* Returns a random cluster id, with an extra guarantee that it isn't already in use.
* @returns {string}
*/
randomClusterId(): string;
/**
* Inserts or replaces a cluster with a matching `id`.
* @param {any} cluster_id
* @param {any} cluster
* @returns {WasmResult<undefined>}
*/
insertCluster(cluster_id: any): void;
insertCluster(cluster: any): WasmResult<undefined>;
/**
* Removes a cluster with a matching `id`
* @param {number} cluster_id
* @param {string} cluster_id
* @returns {WasmResult<undefined>}
*/
removeCluster(cluster_id: number): void;
removeCluster(cluster_id: string): WasmResult<undefined>;
/**

@@ -158,5 +357,6 @@ * Resets all the clusters in the processor to a new list.

* * `clusters` is a Cluster[]
* @param {any[]} clusters
* @param {any[]} clusters
* @returns {WasmResult<undefined>}
*/
initClusters(clusters: any[]): void;
initClusters(clusters: any[]): WasmResult<undefined>;
/**

@@ -167,37 +367,28 @@ * Returns the formatted citation cluster for `cluster_id`.

* still useful for initialization.
* @param {number} id
* @returns {any}
* @param {string} id
* @returns {WasmResult<string>}
*/
builtCluster(id: number): any;
builtCluster(id: string): WasmResult<string>;
/**
* @returns {any}
* Previews a formatted citation cluster, in a particular position.
*
* - `cites`: The cites to go in the cluster
* - `positions`: An array of `ClusterPosition`s as in set_cluster_order, but with a single
* cluster's id set to zero. The cluster with id=0 is the position to preview the cite. It
* can replace another cluster, or be inserted before/after/between existing clusters, in
* any location you can think of.
* @param {any[]} cites
* @param {any[]} positions
* @param {string} format
* @returns {WasmResult<string>}
*/
makeBibliography(): any;
previewCitationCluster(cites: any[], positions: any[], format: string): WasmResult<string>;
/**
* @returns {any}
* @returns {WasmResult<BibEntries>}
*/
bibliographyMeta(): any;
makeBibliography(): WasmResult<BibEntries>;
/**
* Replaces cluster numberings in one go.
*
* * `mappings` is an `Array<[ ClusterId, ClusterNumber ]>` where `ClusterNumber`
* is, e.g. `{ note: 1 }`, `{ note: [3, 1] }` or `{ inText: 5 }` in the same way a
* Cluster must contain one of those three numberings.
*
* Not every ClusterId must appear in the array, just the ones you wish to renumber.
*
* The library consumer is responsible for ensuring that clusters are well-ordered. Clusters
* are sorted for determining cite positions (ibid, subsequent, etc). If a footnote is
* deleted, you will likely need to shift all cluster numbers after it back by one.
*
* The second note numbering, `{note: [3, 1]}`, is for having multiple clusters in a single
* footnote. This is possible in many editors. The second number acts as a second sorting
* key.
*
* The third note numbering, `{ inText: 5 }`, is for ordering in-text references that appear
* within the body of a document. These will be sorted but won't cause
* `first-reference-note-number` to become available.
* @param {any[]} mappings
* @returns {WasmResult<BibliographyMeta>}
*/
renumberClusters(mappings: any[]): void;
bibliographyMeta(): WasmResult<BibliographyMeta>;
/**

@@ -227,5 +418,6 @@ * Specifies which clusters are actually considered to be in the document, and sets their

* May error without having set_cluster_ids, but with some set_cluster_note_number-s executed.
* @param {any[]} pieces
* @param {any[]} positions
* @returns {WasmResult<undefined>}
*/
setClusterOrder(pieces: any[]): void;
setClusterOrder(positions: any[]): WasmResult<undefined>;
/**

@@ -239,16 +431,22 @@ * Retrieve any clusters that have been touched since last time `batchedUpdates` was

* * returns an `UpdateSummary`
* @returns {any}
* @returns {WasmResult<UpdateSummary>}
*/
batchedUpdates(): any;
batchedUpdates(): WasmResult<UpdateSummary>;
/**
* Drains the `batchedUpdates` queue manually. Use it to avoid serializing an unneeded
* `UpdateSummary`.
* Returns all the clusters and bibliography entries in the document.
* Also drains the queue, just like batchedUpdates().
* Use this to rehydrate a document or run non-interactively.
* @returns {WasmResult<FullRender>}
*/
fullRender(): WasmResult<FullRender>;
/**
* Drains the `batchedUpdates` queue manually.
*/
drain(): void;
/**
* Asynchronously fetches all the locales that may be required, and saves them into the
* engine. Uses your provided `Lifecycle.fetchLocale` function.
* @returns {Promise<any>}
* engine. Uses your provided `Fetcher.fetchLocale` function.
* @returns {Promise<any>}
*/
fetchAll(): Promise<any>;
fetchLocales(): Promise<any>;
}
/* tslint:disable */
/* eslint-disable */
export const memory: WebAssembly.Memory;
export function parseStyleMetadata(a: number, b: number): number;
export function __wbg_driver_free(a: number): void;
export function driver_new(a: number, b: number, c: number, d: number, e: number): number;
export function driver_new(a: number): number;
export function driver_setStyle(a: number, b: number, c: number): number;
export function driver_setReferences(a: number, b: number, c: number): void;
export function driver_insertReference(a: number, b: number): void;
export function driver_resetReferences(a: number, b: number, c: number): number;
export function driver_insertReferences(a: number, b: number, c: number): number;
export function driver_insertReference(a: number, b: number): number;
export function driver_removeReference(a: number, b: number, c: number): number;
export function driver_includeUncited(a: number, b: number): number;
export function driver_toFetch(a: number): number;
export function driver_insertCluster(a: number, b: number): void;
export function driver_removeCluster(a: number, b: number): void;
export function driver_initClusters(a: number, b: number, c: number): void;
export function driver_builtCluster(a: number, b: number): number;
export function driver_randomClusterId(a: number, b: number): void;
export function driver_insertCluster(a: number, b: number): number;
export function driver_removeCluster(a: number, b: number, c: number): number;
export function driver_initClusters(a: number, b: number, c: number): number;
export function driver_builtCluster(a: number, b: number, c: number): number;
export function driver_previewCitationCluster(a: number, b: number, c: number, d: number, e: number, f: number, g: number): number;
export function driver_makeBibliography(a: number): number;
export function driver_bibliographyMeta(a: number): number;
export function driver_renumberClusters(a: number, b: number, c: number): void;
export function driver_setClusterOrder(a: number, b: number, c: number): void;
export function driver_setClusterOrder(a: number, b: number, c: number): number;
export function driver_batchedUpdates(a: number): number;
export function driver_fullRender(a: number): number;
export function driver_drain(a: number): void;
export function driver_fetchAll(a: number): number;
export function driver_fetchLocales(a: number): number;
export function __wbindgen_malloc(a: number): number;
export function __wbindgen_realloc(a: number, b: number, c: number): number;
export const __wbindgen_export_2: WebAssembly.Table;
export function _dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h18b461775fab0812(a: number, b: number, c: number): void;
export function _dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__ha382542df1b652c5(a: number, b: number, c: number): void;
export function __wbindgen_free(a: number, b: number): void;
export function __wbindgen_exn_store(a: number): void;
export function wasm_bindgen__convert__closures__invoke2_mut__h442d48e1eb0f8a8d(a: number, b: number, c: number, d: number): void;
export function wasm_bindgen__convert__closures__invoke2_mut__h5b58866e158bfea3(a: number, b: number, c: number, d: number): void;
/* tslint:disable */
/* eslint-disable */
/**
* Parses a CSL style, either independent or dependent, and returns its metadata.
* @param {string} style
* @returns {WasmResult<StyleMeta>}
*/
export function parseStyleMetadata(style: string): WasmResult<StyleMeta>;
interface InitOptions {
/** A CSL style as an XML string */
style: string,
/** A Fetcher implementation for fetching locales.
*
* If not provided, then no locales can be fetched, and default-locale and localeOverride will
* not be respected; the only locale used will be the bundled en-US. */
fetcher?: Fetcher,
/** The output format for this driver instance */
format: "html" | "rtf" | "plain",
/** A locale to use instead of the style's default-locale.
*
* For dependent styles, use parseStyleMetadata to find out which locale it prefers, and pass
* in the parent style with a localeOverride set to that value.
*/
localeOverride?: string,
/** Disables sorting in the bibliography; items appear in cited order. */
bibliographyNoSort?: bool,
}
/** This interface lets citeproc retrieve locales or modules asynchronously,
according to which ones are needed. */
export interface Lifecycle {
export interface Fetcher {
/** Return locale XML for a particular locale. */

@@ -12,2 +41,4 @@ fetchLocale(lang: string): Promise<string>;

export type DateLiteral = { "literal": string; };

@@ -21,2 +52,4 @@ export type DateRaw = { "raw": string; };

/** Locator type, and a locator string */

@@ -36,3 +69,3 @@ export type Locator = {

suppression?: "InText" | "Rest" | null;
} & CiteLocator;
} & Partial<CiteLocator>;

@@ -46,3 +79,3 @@ export type ClusterNumber = {

export type Cluster = {
id: number;
id: string;
cites: Cite[];

@@ -52,3 +85,3 @@ };

export type ClusterPosition = {
id: number;
id: string;
/** Leaving off this field means this cluster is in-text. */

@@ -58,2 +91,4 @@ note?: number;

export type Reference = {

@@ -67,4 +102,6 @@ id: string;

export interface BibliographyUpdate {
updatedEntries: { [key: string]: string };
updatedEntries: Map<string, string>;
entryIds?: string[];

@@ -74,26 +111,158 @@ }

export type UpdateSummary<Output = string> = {
clusters: [number, Output][];
clusters: [string, Output][];
bibliography?: BibliographyUpdate;
};
type InvalidCsl = {
severity: "Error" | "Warning";
type IncludeUncited = "None" | "All" | { Specific: string[] };
type BibEntry = {
id: string;
value: string;
};
type BibEntries = BibEntry[];
type FullRender = {
allClusters: Map<string, string>,
bibEntries: BibEntries,
};
type BibliographyMeta = {
maxOffset: number;
entrySpacing: number;
lineSpacing: number;
hangingIndent: boolean;
/** the second-field-align value of the CSL style */
secondFieldAlign: null | "flush" | "margin";
/** Format-specific metadata */
formatMeta: any,
};
type Severity = "Error" | "Warning";
interface InvalidCsl {
severity: Severity;
/** Relevant bytes in the provided XML */
range: {
start: number;
end: number;
start: number,
end: number,
};
message: string;
hint: string;
hint: string | undefined;
};
type ParseError = {
ParseError: string;
type StyleError = {
tag: "Invalid",
content: InvalidCsl[],
} | {
tag: "ParseError",
content: string,
} | {
/** Cannot use a dependent style to format citations, pass the parent style instead. */
tag: "DependentStyle",
content: {
requiredParent: string,
}
};
type Invalid = {
Invalid: InvalidCsl[];
type DriverError = {
tag: "UnknownOutputFormat",
content: string,
} | {
tag: "JsonError",
} | {
tag: "GetFetcherError",
} | {
tag: "NonExistentCluster",
content: string,
} | {
tag: "ReorderingError"
} | {
tag: "ReorderingErrorNumericId"
};
type StyleError = Partial<ParseError & Invalid>;
declare global {
/** Catch-all citeproc-rs Error subclass. */
declare class CiteprocRsError extends Error {
constructor(message: string);
}
declare class CiteprocRsDriverError extends CiteprocRsError {
data: DriverError;
constructor(message: string, data: DriverError);
}
declare class CslStyleError extends CiteprocRsError {
data: StyleError;
constructor(message: string, data: StyleError);
}
}
interface WasmResult<T> {
/** If this is an error, throws the error. */
unwrap(): T;
/** If this is an error, returns it, else throws. */
unwrap_err(): Error;
is_ok(): boolean;
is_err(): boolean;
/** If this is an error, returns the default value. */
unwrap_or(default: T): T;
/** If this is Ok, returns f(ok_val), else returns Err unmodified. */
map<R>(f: (t: T) => R): WasmResult<T>;
/** If this is Ok, returns f(ok_val), else returns the default value. */
map_or<R>(default: R, f: (t: T) => R): R;
}
type CitationFormat = "author-date" | "author" | "numeric" | "label" | "note";
interface LocalizedString {
value: string,
lang?: string,
}
interface ParentLink {
href: string,
lang?: string,
}
interface Link {
href: string,
rel: "self" | "documentation" | "template",
lang?: string,
}
interface Rights {
value: string,
lang?: string,
license?: string,
}
interface StyleInfo {
id: string,
updated: string,
title: LocalizedString,
titleShort?: LocalizedString,
parent?: ParentLink,
links: Link[],
rights?: Rights,
citationFormat?: CitationFormat,
categories: string[],
issn?: string,
eissn?: string,
issnl?: string,
}
interface IndependentMeta {
/** A list of languages for which a locale override was specified.
* Does not include the language-less final override. */
localeOverrides: string[],
hasBibliography: bool,
}
interface StyleMeta {
info: StyleInfo,
features: { [feature: string]: bool },
defaultLocale: string,
/** May be absent on a dependent style */
class?: "in-text" | "note",
cslVersionRequired: string,
/** May be absent on a dependent style */
independentMeta?: IndependentMeta,
};
/**

@@ -107,30 +276,53 @@ */

* * `style` is a CSL style as a string. Independent styles only.
* * `lifecycle` must implement the `Lifecycle` interface
* * `fetcher` must implement the `Fetcher` interface
* * `format` is one of { "html", "rtf" }
*
* Throws an error if it cannot parse the style you gave it.
* @param {string} style
* @param {any} lifecycle
* @param {string} format
* @returns {Driver}
* @param {InitOptions} options
* @returns {WasmResult<Driver>}
*/
static new(style: string, lifecycle: any, format: string): Driver;
static new(options: InitOptions): WasmResult<Driver>;
/**
* Sets the style (which will also cause everything to be recomputed)
* @param {string} style_text
* @returns {any}
* @param {string} style_text
* @returns {WasmResult<undefined>}
*/
setStyle(style_text: string): any;
setStyle(style_text: string): WasmResult<undefined>;
/**
* Completely overwrites the references library.
* This **will** delete references that are not in the provided list.
* @param {any[]} refs
* @returns {WasmResult<undefined>}
*/
resetReferences(refs: any[]): WasmResult<undefined>;
/**
* Inserts or overwrites references as a batch operation.
* @param {any[]} refs
* This **will not** delete references that are not in the provided list.
* @param {any[]} refs
* @returns {WasmResult<undefined>}
*/
setReferences(refs: any[]): void;
insertReferences(refs: any[]): WasmResult<undefined>;
/**
* Inserts or overwrites a reference.
*
* * `refr` is a Reference object.
* @param {Reference} refr
* @returns {WasmResult<undefined>}
*/
insertReference(refr: Reference): WasmResult<undefined>;
/**
* Removes a reference by id. If it is cited, any cites will be dangling. It will also
* disappear from the bibliography.
* @param {string} id
* @returns {WasmResult<undefined>}
*/
removeReference(id: string): WasmResult<undefined>;
/**
* Sets the references to be included in the bibliography despite not being directly cited.
*
* * `refr` is a
* @param {any} refr
* @param {IncludeUncited} uncited
* @returns {WasmResult<undefined>}
*/
insertReference(refr: any): void;
includeUncited(uncited: IncludeUncited): WasmResult<undefined>;
/**

@@ -140,15 +332,22 @@ * Gets a list of locales in use by the references currently loaded.

* Note that Driver comes pre-loaded with the `en-US` locale.
* @returns {any}
* @returns {WasmResult<string[]>}
*/
toFetch(): any;
toFetch(): WasmResult<string[]>;
/**
* Returns a random cluster id, with an extra guarantee that it isn't already in use.
* @returns {string}
*/
randomClusterId(): string;
/**
* Inserts or replaces a cluster with a matching `id`.
* @param {any} cluster_id
* @param {any} cluster
* @returns {WasmResult<undefined>}
*/
insertCluster(cluster_id: any): void;
insertCluster(cluster: any): WasmResult<undefined>;
/**
* Removes a cluster with a matching `id`
* @param {number} cluster_id
* @param {string} cluster_id
* @returns {WasmResult<undefined>}
*/
removeCluster(cluster_id: number): void;
removeCluster(cluster_id: string): WasmResult<undefined>;
/**

@@ -158,5 +357,6 @@ * Resets all the clusters in the processor to a new list.

* * `clusters` is a Cluster[]
* @param {any[]} clusters
* @param {any[]} clusters
* @returns {WasmResult<undefined>}
*/
initClusters(clusters: any[]): void;
initClusters(clusters: any[]): WasmResult<undefined>;
/**

@@ -167,37 +367,28 @@ * Returns the formatted citation cluster for `cluster_id`.

* still useful for initialization.
* @param {number} id
* @returns {any}
* @param {string} id
* @returns {WasmResult<string>}
*/
builtCluster(id: number): any;
builtCluster(id: string): WasmResult<string>;
/**
* @returns {any}
* Previews a formatted citation cluster, in a particular position.
*
* - `cites`: The cites to go in the cluster
* - `positions`: An array of `ClusterPosition`s as in set_cluster_order, but with a single
* cluster's id set to zero. The cluster with id=0 is the position to preview the cite. It
* can replace another cluster, or be inserted before/after/between existing clusters, in
* any location you can think of.
* @param {any[]} cites
* @param {any[]} positions
* @param {string} format
* @returns {WasmResult<string>}
*/
makeBibliography(): any;
previewCitationCluster(cites: any[], positions: any[], format: string): WasmResult<string>;
/**
* @returns {any}
* @returns {WasmResult<BibEntries>}
*/
bibliographyMeta(): any;
makeBibliography(): WasmResult<BibEntries>;
/**
* Replaces cluster numberings in one go.
*
* * `mappings` is an `Array<[ ClusterId, ClusterNumber ]>` where `ClusterNumber`
* is, e.g. `{ note: 1 }`, `{ note: [3, 1] }` or `{ inText: 5 }` in the same way a
* Cluster must contain one of those three numberings.
*
* Not every ClusterId must appear in the array, just the ones you wish to renumber.
*
* The library consumer is responsible for ensuring that clusters are well-ordered. Clusters
* are sorted for determining cite positions (ibid, subsequent, etc). If a footnote is
* deleted, you will likely need to shift all cluster numbers after it back by one.
*
* The second note numbering, `{note: [3, 1]}`, is for having multiple clusters in a single
* footnote. This is possible in many editors. The second number acts as a second sorting
* key.
*
* The third note numbering, `{ inText: 5 }`, is for ordering in-text references that appear
* within the body of a document. These will be sorted but won't cause
* `first-reference-note-number` to become available.
* @param {any[]} mappings
* @returns {WasmResult<BibliographyMeta>}
*/
renumberClusters(mappings: any[]): void;
bibliographyMeta(): WasmResult<BibliographyMeta>;
/**

@@ -227,5 +418,6 @@ * Specifies which clusters are actually considered to be in the document, and sets their

* May error without having set_cluster_ids, but with some set_cluster_note_number-s executed.
* @param {any[]} pieces
* @param {any[]} positions
* @returns {WasmResult<undefined>}
*/
setClusterOrder(pieces: any[]): void;
setClusterOrder(positions: any[]): WasmResult<undefined>;
/**

@@ -239,16 +431,22 @@ * Retrieve any clusters that have been touched since last time `batchedUpdates` was

* * returns an `UpdateSummary`
* @returns {any}
* @returns {WasmResult<UpdateSummary>}
*/
batchedUpdates(): any;
batchedUpdates(): WasmResult<UpdateSummary>;
/**
* Drains the `batchedUpdates` queue manually. Use it to avoid serializing an unneeded
* `UpdateSummary`.
* Returns all the clusters and bibliography entries in the document.
* Also drains the queue, just like batchedUpdates().
* Use this to rehydrate a document or run non-interactively.
* @returns {WasmResult<FullRender>}
*/
fullRender(): WasmResult<FullRender>;
/**
* Drains the `batchedUpdates` queue manually.
*/
drain(): void;
/**
* Asynchronously fetches all the locales that may be required, and saves them into the
* engine. Uses your provided `Lifecycle.fetchLocale` function.
* @returns {Promise<any>}
* engine. Uses your provided `Fetcher.fetchLocale` function.
* @returns {Promise<any>}
*/
fetchAll(): Promise<any>;
fetchLocales(): Promise<any>;
}

@@ -260,25 +458,32 @@

readonly memory: WebAssembly.Memory;
readonly parseStyleMetadata: (a: number, b: number) => number;
readonly __wbg_driver_free: (a: number) => void;
readonly driver_new: (a: number, b: number, c: number, d: number, e: number) => number;
readonly driver_new: (a: number) => number;
readonly driver_setStyle: (a: number, b: number, c: number) => number;
readonly driver_setReferences: (a: number, b: number, c: number) => void;
readonly driver_insertReference: (a: number, b: number) => void;
readonly driver_resetReferences: (a: number, b: number, c: number) => number;
readonly driver_insertReferences: (a: number, b: number, c: number) => number;
readonly driver_insertReference: (a: number, b: number) => number;
readonly driver_removeReference: (a: number, b: number, c: number) => number;
readonly driver_includeUncited: (a: number, b: number) => number;
readonly driver_toFetch: (a: number) => number;
readonly driver_insertCluster: (a: number, b: number) => void;
readonly driver_removeCluster: (a: number, b: number) => void;
readonly driver_initClusters: (a: number, b: number, c: number) => void;
readonly driver_builtCluster: (a: number, b: number) => number;
readonly driver_randomClusterId: (a: number, b: number) => void;
readonly driver_insertCluster: (a: number, b: number) => number;
readonly driver_removeCluster: (a: number, b: number, c: number) => number;
readonly driver_initClusters: (a: number, b: number, c: number) => number;
readonly driver_builtCluster: (a: number, b: number, c: number) => number;
readonly driver_previewCitationCluster: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => number;
readonly driver_makeBibliography: (a: number) => number;
readonly driver_bibliographyMeta: (a: number) => number;
readonly driver_renumberClusters: (a: number, b: number, c: number) => void;
readonly driver_setClusterOrder: (a: number, b: number, c: number) => void;
readonly driver_setClusterOrder: (a: number, b: number, c: number) => number;
readonly driver_batchedUpdates: (a: number) => number;
readonly driver_fullRender: (a: number) => number;
readonly driver_drain: (a: number) => void;
readonly driver_fetchAll: (a: number) => number;
readonly driver_fetchLocales: (a: number) => number;
readonly __wbindgen_malloc: (a: number) => number;
readonly __wbindgen_realloc: (a: number, b: number, c: number) => number;
readonly __wbindgen_export_2: WebAssembly.Table;
readonly _dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h18b461775fab0812: (a: number, b: number, c: number) => void;
readonly _dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__ha382542df1b652c5: (a: number, b: number, c: number) => void;
readonly __wbindgen_free: (a: number, b: number) => void;
readonly __wbindgen_exn_store: (a: number) => void;
readonly wasm_bindgen__convert__closures__invoke2_mut__h442d48e1eb0f8a8d: (a: number, b: number, c: number, d: number) => void;
readonly wasm_bindgen__convert__closures__invoke2_mut__h5b58866e158bfea3: (a: number, b: number, c: number, d: number) => void;
}

@@ -285,0 +490,0 @@

@@ -0,1 +1,2 @@

import { WasmResult, CiteprocRsError, CiteprocRsDriverError, CslStyleError } from './snippets/wasm-1883a0b9dcad429e/src/js/include.js';

@@ -10,16 +11,2 @@ let wasm;

let heap_next = heap.length;
function dropObject(idx) {
if (idx < 36) return;
heap[idx] = heap_next;
heap_next = idx;
}
function takeObject(idx) {
const ret = getObject(idx);
dropObject(idx);
return ret;
}
let WASM_VECTOR_LEN = 0;

@@ -96,11 +83,16 @@

function addHeapObject(obj) {
if (heap_next === heap.length) heap.push(heap.length + 1);
const idx = heap_next;
heap_next = heap[idx];
let heap_next = heap.length;
heap[idx] = obj;
return idx;
function dropObject(idx) {
if (idx < 36) return;
heap[idx] = heap_next;
heap_next = idx;
}
function takeObject(idx) {
const ret = getObject(idx);
dropObject(idx);
return ret;
}
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });

@@ -114,2 +106,11 @@

function addHeapObject(obj) {
if (heap_next === heap.length) heap.push(heap.length + 1);
const idx = heap_next;
heap_next = heap[idx];
heap[idx] = obj;
return idx;
}
function isLikeNone(x) {

@@ -120,3 +121,3 @@ return x === undefined || x === null;

function makeMutClosure(arg0, arg1, dtor, f) {
const state = { a: arg0, b: arg1, cnt: 1, dtor };
const state = { a: arg0, b: arg1, cnt: 1 };
const real = (...args) => {

@@ -132,18 +133,25 @@ // First up with a closure we increment the internal reference

} finally {
if (--state.cnt === 0) {
wasm.__wbindgen_export_2.get(state.dtor)(a, state.b);
} else {
state.a = a;
}
if (--state.cnt === 0) wasm.__wbindgen_export_2.get(dtor)(a, state.b);
else state.a = a;
}
};
real.original = state;
return real;
}
function __wbg_adapter_18(arg0, arg1, arg2) {
wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h18b461775fab0812(arg0, arg1, addHeapObject(arg2));
function __wbg_adapter_24(arg0, arg1, arg2) {
wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__ha382542df1b652c5(arg0, arg1, addHeapObject(arg2));
}
/**
* Parses a CSL style, either independent or dependent, and returns its metadata.
* @param {string} style
* @returns {WasmResult<StyleMeta>}
*/
export function parseStyleMetadata(style) {
var ptr0 = passStringToWasm0(style, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
var len0 = WASM_VECTOR_LEN;
var ret = wasm.parseStyleMetadata(ptr0, len0);
return takeObject(ret);
}
let cachegetUint32Memory0 = null;

@@ -177,6 +185,9 @@ function getUint32Memory0() {

}
function __wbg_adapter_43(arg0, arg1, arg2, arg3) {
wasm.wasm_bindgen__convert__closures__invoke2_mut__h442d48e1eb0f8a8d(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
function __wbg_adapter_81(arg0, arg1, arg2, arg3) {
wasm.wasm_bindgen__convert__closures__invoke2_mut__h5b58866e158bfea3(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
}
function getArrayU8FromWasm0(ptr, len) {
return getUint8Memory0().subarray(ptr / 1, ptr / 1 + len);
}
/**

@@ -203,18 +214,12 @@ */

* * `style` is a CSL style as a string. Independent styles only.
* * `lifecycle` must implement the `Lifecycle` interface
* * `fetcher` must implement the `Fetcher` interface
* * `format` is one of { "html", "rtf" }
*
* Throws an error if it cannot parse the style you gave it.
* @param {string} style
* @param {any} lifecycle
* @param {string} format
* @returns {Driver}
* @param {InitOptions} options
* @returns {WasmResult<Driver>}
*/
static new(style, lifecycle, format) {
var ptr0 = passStringToWasm0(style, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
var len0 = WASM_VECTOR_LEN;
var ptr1 = passStringToWasm0(format, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
var len1 = WASM_VECTOR_LEN;
var ret = wasm.driver_new(ptr0, len0, addHeapObject(lifecycle), ptr1, len1);
return Driver.__wrap(ret);
static new(options) {
var ret = wasm.driver_new(addHeapObject(options));
return takeObject(ret);
}

@@ -224,3 +229,3 @@ /**

* @param {string} style_text
* @returns {any}
* @returns {WasmResult<undefined>}
*/

@@ -234,9 +239,24 @@ setStyle(style_text) {

/**
* Completely overwrites the references library.
* This **will** delete references that are not in the provided list.
* @param {any[]} refs
* @returns {WasmResult<undefined>}
*/
resetReferences(refs) {
var ptr0 = passArrayJsValueToWasm0(refs, wasm.__wbindgen_malloc);
var len0 = WASM_VECTOR_LEN;
var ret = wasm.driver_resetReferences(this.ptr, ptr0, len0);
return takeObject(ret);
}
/**
* Inserts or overwrites references as a batch operation.
* This **will not** delete references that are not in the provided list.
* @param {any[]} refs
* @returns {WasmResult<undefined>}
*/
setReferences(refs) {
insertReferences(refs) {
var ptr0 = passArrayJsValueToWasm0(refs, wasm.__wbindgen_malloc);
var len0 = WASM_VECTOR_LEN;
wasm.driver_setReferences(this.ptr, ptr0, len0);
var ret = wasm.driver_insertReferences(this.ptr, ptr0, len0);
return takeObject(ret);
}

@@ -246,13 +266,38 @@ /**

*
* * `refr` is a
* @param {any} refr
* * `refr` is a Reference object.
* @param {Reference} refr
* @returns {WasmResult<undefined>}
*/
insertReference(refr) {
wasm.driver_insertReference(this.ptr, addHeapObject(refr));
var ret = wasm.driver_insertReference(this.ptr, addHeapObject(refr));
return takeObject(ret);
}
/**
* Removes a reference by id. If it is cited, any cites will be dangling. It will also
* disappear from the bibliography.
* @param {string} id
* @returns {WasmResult<undefined>}
*/
removeReference(id) {
var ptr0 = passStringToWasm0(id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
var len0 = WASM_VECTOR_LEN;
var ret = wasm.driver_removeReference(this.ptr, ptr0, len0);
return takeObject(ret);
}
/**
* Sets the references to be included in the bibliography despite not being directly cited.
*
* * `refr` is a
* @param {IncludeUncited} uncited
* @returns {WasmResult<undefined>}
*/
includeUncited(uncited) {
var ret = wasm.driver_includeUncited(this.ptr, addHeapObject(uncited));
return takeObject(ret);
}
/**
* Gets a list of locales in use by the references currently loaded.
*
* Note that Driver comes pre-loaded with the `en-US` locale.
* @returns {any}
* @returns {WasmResult<string[]>}
*/

@@ -264,14 +309,34 @@ toFetch() {

/**
* Returns a random cluster id, with an extra guarantee that it isn't already in use.
* @returns {string}
*/
randomClusterId() {
try {
wasm.driver_randomClusterId(8, this.ptr);
var r0 = getInt32Memory0()[8 / 4 + 0];
var r1 = getInt32Memory0()[8 / 4 + 1];
return getStringFromWasm0(r0, r1);
} finally {
wasm.__wbindgen_free(r0, r1);
}
}
/**
* Inserts or replaces a cluster with a matching `id`.
* @param {any} cluster_id
* @param {any} cluster
* @returns {WasmResult<undefined>}
*/
insertCluster(cluster_id) {
wasm.driver_insertCluster(this.ptr, addHeapObject(cluster_id));
insertCluster(cluster) {
var ret = wasm.driver_insertCluster(this.ptr, addHeapObject(cluster));
return takeObject(ret);
}
/**
* Removes a cluster with a matching `id`
* @param {number} cluster_id
* @param {string} cluster_id
* @returns {WasmResult<undefined>}
*/
removeCluster(cluster_id) {
wasm.driver_removeCluster(this.ptr, cluster_id);
var ptr0 = passStringToWasm0(cluster_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
var len0 = WASM_VECTOR_LEN;
var ret = wasm.driver_removeCluster(this.ptr, ptr0, len0);
return takeObject(ret);
}

@@ -283,2 +348,3 @@ /**

* @param {any[]} clusters
* @returns {WasmResult<undefined>}
*/

@@ -288,3 +354,4 @@ initClusters(clusters) {

var len0 = WASM_VECTOR_LEN;
wasm.driver_initClusters(this.ptr, ptr0, len0);
var ret = wasm.driver_initClusters(this.ptr, ptr0, len0);
return takeObject(ret);
}

@@ -296,12 +363,37 @@ /**

* still useful for initialization.
* @param {number} id
* @returns {any}
* @param {string} id
* @returns {WasmResult<string>}
*/
builtCluster(id) {
var ret = wasm.driver_builtCluster(this.ptr, id);
var ptr0 = passStringToWasm0(id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
var len0 = WASM_VECTOR_LEN;
var ret = wasm.driver_builtCluster(this.ptr, ptr0, len0);
return takeObject(ret);
}
/**
* @returns {any}
* Previews a formatted citation cluster, in a particular position.
*
* - `cites`: The cites to go in the cluster
* - `positions`: An array of `ClusterPosition`s as in set_cluster_order, but with a single
* cluster's id set to zero. The cluster with id=0 is the position to preview the cite. It
* can replace another cluster, or be inserted before/after/between existing clusters, in
* any location you can think of.
* @param {any[]} cites
* @param {any[]} positions
* @param {string} format
* @returns {WasmResult<string>}
*/
previewCitationCluster(cites, positions, format) {
var ptr0 = passArrayJsValueToWasm0(cites, wasm.__wbindgen_malloc);
var len0 = WASM_VECTOR_LEN;
var ptr1 = passArrayJsValueToWasm0(positions, wasm.__wbindgen_malloc);
var len1 = WASM_VECTOR_LEN;
var ptr2 = passStringToWasm0(format, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
var len2 = WASM_VECTOR_LEN;
var ret = wasm.driver_previewCitationCluster(this.ptr, ptr0, len0, ptr1, len1, ptr2, len2);
return takeObject(ret);
}
/**
* @returns {WasmResult<BibEntries>}
*/
makeBibliography() {

@@ -312,3 +404,3 @@ var ret = wasm.driver_makeBibliography(this.ptr);

/**
* @returns {any}
* @returns {WasmResult<BibliographyMeta>}
*/

@@ -320,29 +412,2 @@ bibliographyMeta() {

/**
* Replaces cluster numberings in one go.
*
* * `mappings` is an `Array<[ ClusterId, ClusterNumber ]>` where `ClusterNumber`
* is, e.g. `{ note: 1 }`, `{ note: [3, 1] }` or `{ inText: 5 }` in the same way a
* Cluster must contain one of those three numberings.
*
* Not every ClusterId must appear in the array, just the ones you wish to renumber.
*
* The library consumer is responsible for ensuring that clusters are well-ordered. Clusters
* are sorted for determining cite positions (ibid, subsequent, etc). If a footnote is
* deleted, you will likely need to shift all cluster numbers after it back by one.
*
* The second note numbering, `{note: [3, 1]}`, is for having multiple clusters in a single
* footnote. This is possible in many editors. The second number acts as a second sorting
* key.
*
* The third note numbering, `{ inText: 5 }`, is for ordering in-text references that appear
* within the body of a document. These will be sorted but won't cause
* `first-reference-note-number` to become available.
* @param {any[]} mappings
*/
renumberClusters(mappings) {
var ptr0 = passArrayJsValueToWasm0(mappings, wasm.__wbindgen_malloc);
var len0 = WASM_VECTOR_LEN;
wasm.driver_renumberClusters(this.ptr, ptr0, len0);
}
/**
* Specifies which clusters are actually considered to be in the document, and sets their

@@ -371,8 +436,10 @@ * order. You may insert as many clusters as you like, but the ones provided here are the only

* May error without having set_cluster_ids, but with some set_cluster_note_number-s executed.
* @param {any[]} pieces
* @param {any[]} positions
* @returns {WasmResult<undefined>}
*/
setClusterOrder(pieces) {
var ptr0 = passArrayJsValueToWasm0(pieces, wasm.__wbindgen_malloc);
setClusterOrder(positions) {
var ptr0 = passArrayJsValueToWasm0(positions, wasm.__wbindgen_malloc);
var len0 = WASM_VECTOR_LEN;
wasm.driver_setClusterOrder(this.ptr, ptr0, len0);
var ret = wasm.driver_setClusterOrder(this.ptr, ptr0, len0);
return takeObject(ret);
}

@@ -387,3 +454,3 @@ /**

* * returns an `UpdateSummary`
* @returns {any}
* @returns {WasmResult<UpdateSummary>}
*/

@@ -395,5 +462,14 @@ batchedUpdates() {

/**
* Drains the `batchedUpdates` queue manually. Use it to avoid serializing an unneeded
* `UpdateSummary`.
* Returns all the clusters and bibliography entries in the document.
* Also drains the queue, just like batchedUpdates().
* Use this to rehydrate a document or run non-interactively.
* @returns {WasmResult<FullRender>}
*/
fullRender() {
var ret = wasm.driver_fullRender(this.ptr);
return takeObject(ret);
}
/**
* Drains the `batchedUpdates` queue manually.
*/
drain() {

@@ -404,7 +480,7 @@ wasm.driver_drain(this.ptr);

* Asynchronously fetches all the locales that may be required, and saves them into the
* engine. Uses your provided `Lifecycle.fetchLocale` function.
* engine. Uses your provided `Fetcher.fetchLocale` function.
* @returns {Promise<any>}
*/
fetchAll() {
var ret = wasm.driver_fetchAll(this.ptr);
fetchLocales() {
var ret = wasm.driver_fetchLocales(this.ptr);
return takeObject(ret);

@@ -453,8 +529,2 @@ }

imports.wbg = {};
imports.wbg.__wbindgen_object_drop_ref = function(arg0) {
takeObject(arg0);
};
imports.wbg.__wbg_error_e549f7fed6d655aa = function(arg0) {
console.error(takeObject(arg0));
};
imports.wbg.__wbindgen_json_serialize = function(arg0, arg1) {

@@ -468,10 +538,36 @@ const obj = getObject(arg1);

};
imports.wbg.__wbindgen_object_clone_ref = function(arg0) {
var ret = getObject(arg0);
imports.wbg.__wbg_fetchLocale_d644d4ae2ca50f81 = function(arg0, arg1, arg2) {
var ret = getObject(arg0).fetchLocale(getStringFromWasm0(arg1, arg2));
return addHeapObject(ret);
};
imports.wbg.__wbg_fetchLocale_8f52b973b0739a6c = function(arg0, arg1, arg2) {
var ret = getObject(arg0).fetchLocale(getStringFromWasm0(arg1, arg2));
imports.wbg.__wbindgen_object_drop_ref = function(arg0) {
takeObject(arg0);
};
imports.wbg.__wbg_debug_4885c3f7d6f044a3 = function(arg0, arg1) {
console.debug(getStringFromWasm0(arg0, arg1));
};
imports.wbg.__wbg_log_bee3ea1a89f334d8 = function(arg0, arg1) {
console.log(getStringFromWasm0(arg0, arg1));
};
imports.wbg.__wbg_info_0547ff9513f2019b = function(arg0, arg1) {
console.info(getStringFromWasm0(arg0, arg1));
};
imports.wbg.__wbg_warn_a478dea6e6e05394 = function(arg0, arg1) {
console.warn(getStringFromWasm0(arg0, arg1));
};
imports.wbg.__wbg_error_72e88ba6901b6eee = function(arg0, arg1) {
console.error(getStringFromWasm0(arg0, arg1));
};
imports.wbg.__wbg_get_1edc26456ed84f9b = function(arg0, arg1) {
var ret = getObject(arg0)[takeObject(arg1)];
return addHeapObject(ret);
};
imports.wbg.__wbindgen_string_new = function(arg0, arg1) {
var ret = getStringFromWasm0(arg0, arg1);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_json_parse = function(arg0, arg1) {
var ret = JSON.parse(getStringFromWasm0(arg0, arg1));
return addHeapObject(ret);
};
imports.wbg.__wbindgen_cb_drop = function(arg0) {

@@ -486,15 +582,65 @@ const obj = takeObject(arg0).original;

};
imports.wbg.__wbindgen_json_parse = function(arg0, arg1) {
var ret = JSON.parse(getStringFromWasm0(arg0, arg1));
imports.wbg.__wbg_driver_new = function(arg0) {
var ret = Driver.__wrap(arg0);
return addHeapObject(ret);
};
imports.wbg.__wbg_new_4896ab6bba55e0d9 = function(arg0, arg1) {
var ret = new Error(getStringFromWasm0(arg0, arg1));
imports.wbg.__wbindgen_object_clone_ref = function(arg0) {
var ret = getObject(arg0);
return addHeapObject(ret);
};
imports.wbg.__wbg_call_0dad7db75ec90ae7 = handleError(function(arg0, arg1, arg2) {
imports.wbg.__wbg_new_f12987d5c30f0ab7 = function(arg0) {
var ret = new CiteprocRsError(takeObject(arg0));
return addHeapObject(ret);
};
imports.wbg.__wbg_new_c5e56e6577bc2b6a = function(arg0, arg1) {
var ret = new CslStyleError(takeObject(arg0), takeObject(arg1));
return addHeapObject(ret);
};
imports.wbg.__wbg_new_6edca5ab9ee61764 = function(arg0) {
var ret = new WasmResult(takeObject(arg0));
return addHeapObject(ret);
};
imports.wbg.__wbg_new_8d5f3cd64eaaa8b5 = function(arg0, arg1) {
var ret = new CiteprocRsDriverError(takeObject(arg0), takeObject(arg1));
return addHeapObject(ret);
};
imports.wbg.__wbindgen_is_undefined = function(arg0) {
var ret = getObject(arg0) === undefined;
return ret;
};
imports.wbg.__wbindgen_is_object = function(arg0) {
const val = getObject(arg0);
var ret = typeof(val) === 'object' && val !== null;
return ret;
};
imports.wbg.__wbindgen_is_function = function(arg0) {
var ret = typeof(getObject(arg0)) === 'function';
return ret;
};
imports.wbg.__wbg_error_e549f7fed6d655aa = function(arg0) {
console.error(takeObject(arg0));
};
imports.wbg.__wbg_new_59cb74e423758ede = function() {
var ret = new Error();
return addHeapObject(ret);
};
imports.wbg.__wbg_stack_558ba5917b466edd = function(arg0, arg1) {
var ret = getObject(arg1).stack;
var ptr0 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
var len0 = WASM_VECTOR_LEN;
getInt32Memory0()[arg0 / 4 + 1] = len0;
getInt32Memory0()[arg0 / 4 + 0] = ptr0;
};
imports.wbg.__wbg_error_4bb6c2a97407129a = function(arg0, arg1) {
try {
console.error(getStringFromWasm0(arg0, arg1));
} finally {
wasm.__wbindgen_free(arg0, arg1);
}
};
imports.wbg.__wbg_call_0246f1c8ff252fb6 = handleError(function(arg0, arg1, arg2) {
var ret = getObject(arg0).call(getObject(arg1), getObject(arg2));
return addHeapObject(ret);
});
imports.wbg.__wbg_new_7039bf8b99f049e1 = function(arg0, arg1) {
imports.wbg.__wbg_new_09f2ad087112acf0 = function(arg0, arg1) {
try {

@@ -506,3 +652,3 @@ var state0 = {a: arg0, b: arg1};

try {
return __wbg_adapter_43(a, state0.b, arg0, arg1);
return __wbg_adapter_81(a, state0.b, arg0, arg1);
} finally {

@@ -518,14 +664,44 @@ state0.a = a;

};
imports.wbg.__wbg_resolve_4df26938859b92e3 = function(arg0) {
imports.wbg.__wbg_resolve_708df7651c8929b8 = function(arg0) {
var ret = Promise.resolve(getObject(arg0));
return addHeapObject(ret);
};
imports.wbg.__wbg_then_ffb6e71f7a6735ad = function(arg0, arg1) {
imports.wbg.__wbg_then_8c23dce80c84c8fb = function(arg0, arg1) {
var ret = getObject(arg0).then(getObject(arg1));
return addHeapObject(ret);
};
imports.wbg.__wbg_then_021fcdc7f0350b58 = function(arg0, arg1, arg2) {
imports.wbg.__wbg_then_300153bb889a5b4b = function(arg0, arg1, arg2) {
var ret = getObject(arg0).then(getObject(arg1), getObject(arg2));
return addHeapObject(ret);
};
imports.wbg.__wbg_getRandomValues_3ac1b33c90b52596 = function(arg0, arg1, arg2) {
getObject(arg0).getRandomValues(getArrayU8FromWasm0(arg1, arg2));
};
imports.wbg.__wbg_randomFillSync_6f956029658662ec = function(arg0, arg1, arg2) {
getObject(arg0).randomFillSync(getArrayU8FromWasm0(arg1, arg2));
};
imports.wbg.__wbg_self_1c83eb4471d9eb9b = handleError(function() {
var ret = self.self;
return addHeapObject(ret);
});
imports.wbg.__wbg_static_accessor_MODULE_abf5ae284bffdf45 = function() {
var ret = module;
return addHeapObject(ret);
};
imports.wbg.__wbg_require_5b2b5b594d809d9f = function(arg0, arg1, arg2) {
var ret = getObject(arg0).require(getStringFromWasm0(arg1, arg2));
return addHeapObject(ret);
};
imports.wbg.__wbg_crypto_c12f14e810edcaa2 = function(arg0) {
var ret = getObject(arg0).crypto;
return addHeapObject(ret);
};
imports.wbg.__wbg_msCrypto_679be765111ba775 = function(arg0) {
var ret = getObject(arg0).msCrypto;
return addHeapObject(ret);
};
imports.wbg.__wbg_getRandomValues_05a60bf171bfc2be = function(arg0) {
var ret = getObject(arg0).getRandomValues;
return addHeapObject(ret);
};
imports.wbg.__wbindgen_string_get = function(arg0, arg1) {

@@ -542,7 +718,4 @@ const obj = getObject(arg1);

};
imports.wbg.__wbindgen_rethrow = function(arg0) {
throw takeObject(arg0);
};
imports.wbg.__wbindgen_closure_wrapper847 = function(arg0, arg1, arg2) {
var ret = makeMutClosure(arg0, arg1, 88, __wbg_adapter_18);
imports.wbg.__wbindgen_closure_wrapper928 = function(arg0, arg1, arg2) {
var ret = makeMutClosure(arg0, arg1, 210, __wbg_adapter_24);
return addHeapObject(ret);

@@ -549,0 +722,0 @@ };

@@ -7,3 +7,3 @@ {

"description": "citeproc-rs, compiled to WebAssembly",
"version": "0.0.0-canary-197979f",
"version": "0.0.0-canary-26ac18a",
"license": "MPL-2.0",

@@ -18,2 +18,3 @@ "repository": {

"_web/*",
"_no_modules/*",
"README.md"

@@ -20,0 +21,0 @@ ],

# `@citeproc-rs/wasm`
This is a build of `citeproc` that is suitable for use in Node.js, a browser or
a Firefox/Chromium-based application like Zotero. It consists of a WebAssembly
(WASM) binary, and a fairly lightweight JavaScript wrapper for that binary.
This is a front-end to
[`citeproc-rs`](https://github.com/cormacrelf/citeproc-rs), a citation
processor written in Rust and compiled to WebAssembly.
README for newer version of the API forthcoming.
It contains builds appropriate for:
- Node.js
- Browsers, using a bundler like Webpack.js
- Browsers directly importing an ES Module from a webserver
## Installation / Release channels
There are two release channels:
**Stable** is each versioned release. (*At the time of writing, there are no
versioned releases.*) Install with:
```sh
yarn add @citeproc-rs/wasm
```
**Canary** tracks the master branch [on
GitHub](https://github.com/cormacrelf/citeproc-rs). Its version numbers follow
the format `0.0.0-canary-GIT_COMMIT_SHA`, so version ranges in your
`package.json` are not meaningful. But you can install the latest one with:
```sh
yarn add @citeproc-rs/wasm@canary
# alternatively, a specific commit
yarn add @citeproc-rs/wasm@0.0.0-canary-COMMIT_SHA
```
If you use NPM, replace `yarn add` with `npm install`.
### Including in your project
For Node.js, simply import the package as normal. Typescript definitions are
provided, though parts of the API that cannot have auto-generated type
definitions are alluded to in doc comments with an accompanying type you can
import.
```
// Node.js
const { Driver } = require("@citeproc-rs/wasm");
```
##### Microsoft Edge
Note the caveats in around Microsoft Edge's TextEncoder/TextDecoder support in
[the wasm-bindgen
tutorial](https://rustwasm.github.io/docs/wasm-bindgen/examples/hello-world.html).
#### Using Webpack
When loading on the web, for technical reasons and because the compiled
WebAssembly is large, you must load the package asynchronously. Webpack comes
with the ability to import packages asynchronously like so:
```javascript
// Webpack
import("@citeproc-rs/wasm")
.then(go)
.catch(console.error);
function go(wasm) {
const { Driver } = wasm;
// use Driver
}
```
When you do this, your code will trigger a download (and streaming parse) of
the binary, and when that is complete, your `go` function will be called. The
download can of course be cached if your web server is set up correctly, making
the whole process very quick.
You can use the regular-import Driver as a TypeScript type anywhere, just don't
use it to call `.new()`.
##### React
If you're writing a React app, you may wish to use `React.lazy` like so:
```typescript
// App.tsx
import React, { Suspense } from "react";
const AsyncCiteprocEnabledComponent = React.lazy(async () => {
await import("@citeproc-rs/wasm");
return await import("./CiteprocEnabledComponent");
});
const App = () => (
<Suspense
fallback={<div>Loading citation formatting engine...</div>}>
<AsyncCiteprocEnabledComponent />
</Suspense>
);
// CiteprocEnabledComponent
import { Driver } from "@citeproc-rs/wasm";
// ...
```
#### Importing it in a script tag (`web` target)
To directly import it without a bundler in a (modern) web browser with ES
modules support, the procedure is different. You must:
1. Make the `_web` subdirectory of the published NPM package available in a
content directory on your webserver, or use a CDN like [unpkg](unpkg.com).
2. Include a `<script type="module">` tag in your page's `<body>`, like so:
```html
<script type="module">
import init, { Driver } from './path/to/_web/citeproc_rs_wasm.js';
async function run() {
await init();
// use Driver
}
run()
</script>
```
**Careful**: This method does not ensure the package is loaded only once. If
you call init again, it will invalidate any previous Drivers you created.
#### Importing it in a script tag (`no-modules` target)
This is *based on* the [wasm-bindgen guide
entry](https://rustwasm.github.io/docs/wasm-bindgen/examples/without-a-bundler.html?highlight=no-modules#using-the-older---target-no-modules),
noting the caveats. You will, similarly to the `web` target, need to make the
contents of the `_no_modules` subdirectory of the published NPM package
available on a webserver or via a CDN. But it has **ONE ADDITIONAL FILE** to
import via a script tag.
**Careful**: This method does not ensure the package is loaded only once. If
you call init again, it will invalidate any previous Drivers you created.
```
<html>
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type"/>
</head>
<body>
<!-- Include these TWO JS files -->
<script src='path/to/@citeproc-rs/wasm/_no_modules/citeproc_rs_wasm_include.js'></script>
<script src='path/to/@citeproc-rs/wasm/_no_modules/citeproc_rs_wasm.js'></script>
<script>
// Like with the `--target web` output the exports are immediately
// available but they won't work until we initialize the module. Unlike
// `--target web`, however, the globals are all stored on a
// `wasm_bindgen` global. The global itself is the initialization
// function and then the properties of the global are all the exported
// functions.
//
// Note that the name `wasm_bindgen` will at some point be configurable with the
// `--no-modules-global` CLI flag (https://github.com/rustwasm/wasm-pack/issues/729)
const { Driver } = wasm_bindgen;
async function run() {
// Note the _bg.wasm ending
await wasm_bindgen('path/to/@citeproc-rs/wasm/_no_modules/citeproc_rs_wasm_bg.wasm');
// Use Driver
}
run();
</script>
</body>
</html>
```
#### Usage in Zotero
There is a special build for Zotero and the legacy Firefox ESR extensions API,
which wants a CommonJS module format but without the Node.js `fs` APIs, and
`no-modules`' loading mechanisms but without the use of `window` as a global as
it doesn't exist. The files are in the `_zotero` directory of the NPM package.
Usage is essentially the same as no-modules; you'll need all three files:
* `@citeproc-rs/wasm/_zotero/citeproc_rs_wasm_include.js`
* `@citeproc-rs/wasm/_zotero/citeproc_rs_wasm.js`
* `@citeproc-rs/wasm/_zotero/citeproc_rs_wasm_bg.wasm`
Apart from the CommonJS shims, the main difference is that the API will be
loaded onto the `Zotero.CiteprocRs` object, in order for it all to be linked
together.
**Careful**: This method does not ensure the package is loaded only once. If
you call `initWasmModule` again, it will invalidate any previous Drivers you
created.
```javascript
require("citeproc_rs_wasm_include");
const initWasmModule = require("citeproc_rs_wasm");
const wasmBinaryPromise = Zotero.HTTP
.request('GET',
'resource://zotero/citeproc_rs_wasm_bg.wasm',
{ responseType: "arraybuffer" })
.then(xhr => xhr.response);
await initWasmModule(wasmBinaryPromise);
let driver;
try {
driver = Zotero.CiteprocRs.Driver.new({...}).unwrap();
} catch (e) {
if (e instanceof Zotero.CiteprocRs.CslStyleError) {
// ...
}
}
```
## Usage
### Overview
The basic pattern of interactive use is:
1. Create a driver instance with your style
2. Edit the references or the citation clusters as you please
3. **Call `driver.batchedUpdates()`**
4. Apply the updates to your document (e.g. GUI)
5. Go to step 2 when a user makes a change
Step three is the important one. Each time you edit a cluster or a reference,
it is common for only one or two visible modifications to result. Therefore,
the driver only gives you those clusters or bibliography entries that have
changed, or have been caused to change by an edit elsewhere. You can submit any
number of edits between each call.
The API also allows for non-interactive use. See below.
### Error handling
To avoid [this issue][1963], almost every API wraps its return value in a
JavaScript object that contains either a successful result or an error, which
is a JavaScript Error object. This is called `WasmResult`, and it is modelled
on the Rust [`Result` type][rust-result]. If you just want your errors thrown,
simply tack `.unwrap()` onto nearly every API call. If you want to handle them
manually, you can, and this is mainly useful for showing style parse or
validation errors. Some error types have structured data attached to them.
```typescript
let result = Driver.new({ ... });
if (result.is_err()) {
let error = result.unwrap_err();
if (error instanceof CslStyleError) {
console.warn("Could not parse CSL, error:", error);
// You can also
// throw error;
}
} else {
let driver = result.unwrap();
}
// ...
driver.free(); // No unwrap.
```
The error types must unfortunately be global exports, on window/global/self.
In this document, `.unwrap()` used after an example means it returns a
WasmResult.
[1963]: https://github.com/rustwasm/wasm-bindgen/issues/1963
[rust-result]: https://doc.rust-lang.org/stable/std/result/enum.Result.html
### 1. Creating a driver instance
First, create a driver. Note that for now, you must also call `.free()` on the
Driver when you are finished with it to deallocate its memory, but [there is a TC39
proposal](https://rustwasm.github.io/docs/wasm-bindgen/reference/weak-references.html)
in the implementation phase that will make this unnecessary.
A driver needs at least an XML style string, a fetcher (below), and an output
format (one of `"html"`, `"rtf"` or `"plain"`).
```javascript
let fetcher = ...; // see below
let driverResult = Driver.new({
style: "<style version=\"1.0\" class=\"note\" ... > ... </style>",
format: "html", // optional, html is the default
localeOverride: "de-DE", // optional, like setting default-locale on the style
// bibliographyNoSort: true // disables sorting on the bibliography
fetcher,
});
// Throw any errors, get the inner Driver
let driver = driverResult.unwrap();
// Fetch the chain of locale files required to use the specified locale
await driver.fetchLocales();
// ... use the driver ...
driver.free()
```
The library parses and validates the CSL style input. Any validation errors are
reported, with byte offsets to find the CSL fragment responsible, a descriptive
and useful message (in English) and sometimes even a hint for how to fix it.
See [Error Handling](#error-handling) for how to access this.
#### Fetcher
There are hundreds of locales, and the locales you need depend on the style
default, any overrides and any fallback locales defined, so the procedure for
retrieving one is asynchronous to allow for fetching one over HTTP. There's not
much more to it than this:
```javascript
class Fetcher {
async fetchLocale(lang) {
return await fetch("https://some-cdn-with-locales.com/locales-${lang}.xml")
.then(res => res.text());
// or just
// return "<locale> ... </locale>";
// return LOCALES_PRELOADED[lang];
// or if you don't support locales other than the bundled en-US!
// return null;
}
}
let fetcher = new Fetcher();
let driver = Driver.new({ ..., fetcher }).unwrap();
// Make sure you actually fetch them!
await driver.fetchLocales();
```
Unless you don't have `async` syntax, in which case, return a `Promise`
directly, e.g. `return Promise.resolve("<locale> ... </locale>")`.
Declining to provide a locale fetcher in `Driver.new` or forgetting to call
`await driver.fetchLocales()` results in use of the bundled `en-US` locale. You
should also never attempt to use the driver instance while it is fetching locales.
### 2. Edit the references or the citation clusters
#### References
You can insert a reference like so. This is a [CSL-JSON][schema] object.
[schema]: https://github.com/citation-style-language/schema
```javascript
driver.insertReference({ id: "citekey", type: "book", title: "Title" }).unwrap();
driver.insertReferences([ ... many references ... ]).unwrap();
driver.resetReferences([ ... deletes any others ... ]).unwrap();
driver.removeReference("citekey").unwrap();
```
#### Citation Clusters and their Cites
A document consists of a series of clusters, each with a series of cites. Each
cluster has an `id`, which is any old string.
```javascript
// initClusters is like booting up an existing document and getting up to speed
driver.initClusters([
{ id: "one", cites: [ {id: "citekey"} ] },
{ id: "two", cites: [ {id: "citekey", locator: "56", label: "page" } ] },
]).unwrap();
// Update or insert any one of them like so
driver.insertCluster({ id: "one", cites: [ { id: "updated_citekey" } ] }).unwrap();
// (You can use `driver.randomClusterId()` to generate a new one at random.)
let three = driver.randomClusterId();
driver.insertCluster({ id: three, cites: [ { id: "new_cluster_here" } ] }).unwrap();
```
These clusters do not contain position information, so reordering is a separate
procedure. **Without calling setClusterOrder, the driver considers the document
to be empty.**
So, `setClusterOrder` expresses the ordering of the clusters within the
document. Each one in the document should appear in this list. You can skip
note numbers, which means there were non-citing footnotes in between. Omitting
`note` means it's an in-text reference. Note numbers must be monotonic, but you
can have more than one cluster in the same footnote.
```javascript
driver.setClusterOrder([ { id: "one", note: 1 }, { id: "two", note: 4 } ]).unwrap();
```
You will notice that if an interactive user cuts and pastes a paragraph
containing citation clusters, the whole reordering operation can be expressed
in two calls, one after the cut (with some clusters omitted) and one after the
paste (with those same clusters placed somewhere else). No calls to
`insertCluster` need be made.
#### Uncited items
Sometimes a user wishes to include references in the bibliography even though
they are not mentioned in a citation anywhere in the document.
```javascript
driver.includeUncited("None").unwrap(); // Default
driver.includeUncited("All").unwrap();
driver.includeUncited({ Specific: ["citekeyA", "citekeyB"] }).unwrap();
```
The "All" is based on which references your driver knows about. If you have
this set to "All", simply calling `driver.insertReference()` with a new
reference ID will result in an entry being added to the bibliography. Entries
in Specific mode do not have to exist when they are provided here; they can be,
for instance, the citekeys of collection of references in a reference library
which are subsequently provided in full to the driver, at which point they
appear in the bibliography, but not items from elsewhere in the library.
### 3. Call `driver.batchedUpdates()` and apply the diff
This gets you a diff to apply to your document UI. It includes both clusters
that have changed, and bibliography entries that have changed.
```javascript
// Get the diff since last time batchedUpdates, fullRender or drain was called.
let diff = driver.batchedUpdates().unwrap();
// apply cluster changes to the UI.
// ("myDocument" is an imaginary API.)
for (let changedCluster of diff.clusters) {
let [id, html] = changedCluster;
myDocument.updateCluster(id, html);
}
// Null? No change to the bibliography.
if (diff.bibliography != null) {
let bib = diff.bibliography;
// Save the entries that have actually changed
for (let key of Object.keys(bib.updatedEntries)) {
let rendered = bib.updatedEntries[key];
myDocument.updateBibEntry(key, rendered);
}
// entryIds is the full list of entries in the bibliography.
// If a citekey isn't in there, it should be removed.
// It is non-null when it has changed.
if (bib.entryIds != null) {
myDocument.setBibliographyOrder(bib.entryIds);
}
}
```
Note, for some intuition, if you call `batchedUpdates()` again immediately, the
diff will be empty.
### Bibliographies
Beyond the interactive batchedUpdates method, there are two functions for
producing a bibliography statically.
```javascript
// returns BibliographyMeta, with information about how a library consumer should
// lay out the bibliography. There is a similar API in citeproc-js.
let meta = driver.bibliographyMeta().unwrap();
// This is an array of BibEntry
let bibliography = driver.makeBibliography().unwrap();
for (let entry of bibliography) {
console.log(entry.id, entry.value);
}
```
### Preview citation clusters
Sometimes, a user wants to see how a cluster will look while they are editing
it, before confirming the change.
```javascript
let cites = [ { id: "citekey", locator: "45" }, { ... } ];
let positions = [ ... before, { note: 34 }, ... after ];
let preview = driver.previewCitationCluster(cites, positions, "html").unwrap();
```
The positions array is exactly like a call to `setClusterOrder`, except exactly
one of the positions omits the id field. This could either:
- Replace an existing cluster's position, and preview a cluster replacement; or
- Represent the position a cluster is hypothetically inserted.
If you passed only one position, it would be like previewing an operation like
"delete the entire document and replace it with this one cluster". **That would
mean you would never see "ibid" in a preview.** So for maximum utility,
assemble the positions array as you would a call to `setClusterOrder` with
exactly the operation you're previewing applied.
### Non-Interactive use, or re-hydrating a previously created document
If you are working non-interactively, or re-hydrating a previously created
document for interactive use, you may want to do one pass over all the clusters
in the document, so that each cluster and bibliography entry reflects the
correct value.
```javascript
// Get the clusters from your document (example)
let allNotes = myDocument.footnotes.map(fn => {
return { cluster: getCluster(fn), number: fn.number }
});
// Re-hydrate the entire document based on the reference library and your
// document's clusters
driver.resetReferences(myDocument.allReferences).unwrap();
driver.initClusters(allNotes.map(fn => fn.cluster)).unwrap();
driver.setClusterOrder(allNotes.map(fn => { id: fn.cluster.id, note: fn.number })).unwrap();
// Render every cluster and bibliography item.
// It then drains the update queue, leaving the diff empty for the next edit.
// see the FullRender typescript type
let render = driver.fullRender().unwrap();
// Write out the rendered clusters into the doc
for (let fn of allNotes) {
fn.renderedHtml = render.allClusters[fn.cluster.id];
}
// Write out the bibliography entries as well
let allBibKeys = render.bibEntries.map(entry => entry.id);
for (let bibEntry of render.bibEntries) {
myDocument.bibliographyMap[entry.id] = entry.value;
}
// Update your (example) UI
updateUserInterface(allNotes, myDocument, whatever);
```
### `parseStyleMetadata`
Sometimes you want information about a CSL style without actually booting up a
whole driver. One important use case is a dependent style, which can't be used
with `Driver.new()` because it doesn't have the ability to render citations on
its own, and is essentially just a container for three pieces of information:
- A journal name
- An independent parent style
- A possible default-locale override
`@citeproc-rs/wasm` provides an API for finding out what's in a CSL style file.
```typescript
let result = parseStyleMetadata("<style ...> ... </style>").unwrap();
```
The result could be a `CslStyleError`, but this is less likely than with
Driver.new() as it will not actually attempt to parse and validate all the
parts of a style.
Here's how to use `parseStyleMetadata` to parse and use a dependent style.
```typescript
let dependentStyle = "<style ...> ... </style>";
let meta = parseStyleMetadata(dependentStyle).unwrap();
let isDependent = meta.info.parent != null;
let parentStyleId = isDependent && meta.info.parent.href;
let localeOverride = meta.defaultLocale;
// ...
let parentStyle = await downloadStyleWithId(parentStyleId);
let driver = Driver.new({
style: parentStyle,
localeOverride,
...
}).unwrap();
await driver.fetchLocales();
// Here you might also want to know if the style can render a bibliography or not
let parentMeta = parseStyleMetadata(parentStyle).unwrap();
if (parentMeta.independentMeta.hasBibliography) {
let bib = driver.makeBibliography().unwrap();
// ...
}
// ...
driver.free();
```

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc