Example
Create a new Font object
const fetcher = name =>
fetch(`https://example.com/${name}`).then(r => {
if (r.status === 200) {
return r.blob();
} else {
throw new Error();
}
});
const customFonts = ["arial.ttf", "helvetica.ttf", "tahoma.ttf"]
.map(font => new NutrientViewer.Font({ name: font, callback: fetcher }));
NutrientViewer.load({
customFonts,
document: 'https://example.com/document.pdf'
}).then(instance => {});
Hierarchy
Constructors
Parameters
args{ callback?: FontCallback; name: string }
Properties
Methods
Returns the record's
[key, value]pairs, in the order its fields were defined.Returns
IterableIterator<[string, unknown]>An iterator over the record's fields.
Immutable Record API
27
- "[iterator]"(): IterableIterator<
[
keyof { callback: FontCallback
| null; name: string | null },
string | FontCallback | null,
],
>Iterates the
[key, value]pairs, in the order the fields were defined.Returns
IterableIterator<
[
keyof { callback: FontCallback
| null; name: string | null },
string | FontCallback | null
]
>
Returns a record with every key reset to the default it was defined with.
Returns
thisA new record holding only default values.
- delete<K extends keyof { callback: FontCallback | null; name: string | null }>(
key: K & ("name" | "callback"),
): thisReturns a record with
keyreset to the default it was defined with.Type Parameters
Kextends keyof { callback: FontCallback | null; name: string | null }Parameters
keyK & ("name" | "callback")One of the keys this record was defined with.
Returns
thisA new record, or this one when the value already equals the default.
Returns a record with the value at
keyPathremoved. A field of this record is reset to its default; a key of a nested collection or plain object is deleted.Parameters
keyPathIterable<unknown>The keys to follow, outermost first.
Returns
thisA new record, or this one when nothing was removed.
equals
Reports whether
otheris a record holding the same keys with equal values, whatever its class.Parameters
otherunknownThe value to compare against.
Returns
booleantruewhen both hold the same keys and every value matches.Deprecated
Records of different classes with identical values compare equal. Use
isEqual(), which also requires both records to be of the same class.
- get<
K extends keyof { callback: FontCallback
| null; name: string | null },
N = never,
>(
key: K & ("name" | "callback"),
notSetValue?: N,
): N | { callback: FontCallback | null; name: string | null }[K]Returns the value stored under
key.Type Parameters
Kextends keyof { callback: FontCallback | null; name: string | null }N = neverParameters
Returns
N | { callback: FontCallback | null; name: string | null }[K]The current value for that key.
Returns the value at
keyPath, walking nested records and collections.A literal key path is checked against the record's fields and gives the value's type; a computed one gives
unknown.Parameters
keyPathIterable<unknown>The keys to follow, outermost first.
Returns
unknownThe value at that path, or
undefinedwhen it does not resolve.Returns the value at
keyPath, walking nested records and collections.A literal key path is checked against the record's fields and gives the value's type; a computed one gives
unknown.
Reports whether
keyis one of the keys this record was defined with.A literal key must name a field; a key typed as
stringis narrowed to the field names.Parameters
keystringThe key to look for.
Returns
key is "name" | "callback"truewhen the record defines that key, even if its value isnull.
Computes a hash of this record from its contents, the same way Immutable.js does. Equal records have equal hashes; records with equal hashes are not necessarily equal. Plain objects, functions and symbols hash by identity, so a hash is only meaningful within the page that computed it.
Returns
numberAn integer hash.
Reports whether
keyPathresolves, walking nested records and collections.Parameters
keyPathIterable<unknown>The keys to follow, outermost first.
Returns
booleantruewhen every key along the path is present.
Reports whether
otheris a record of the same class holding equal values. Only the two records' own classes are compared; nested records compare asequals()does.Parameters
otherunknownThe value to compare against.
Returns
booleantruewhen both are the same class and every value matches.
- merge(
...collections: (
| Partial<{ callback: FontCallback | null; name: string | null }>
| Iterable<readonly [string, unknown]>
)[],
): thisReturns a record with the entries of each collection applied in order.
Keys the record was not defined with are ignored.
Parameters
...collections(
| Partial<{ callback: FontCallback | null; name: string | null }>
| Iterable<readonly [string, unknown]>
)[]Plain objects or key/value iterables to apply.
Returns
thisA new record, or this one when no value changed.
- mergeDeep(
...collections: (
| Partial<{ name: string | null; callback: FontCallback | null }>
| Iterable<readonly [string, unknown]>
)[],
): thisReturns a record with the entries of each collection merged in, recursing into nested collections and plain objects instead of replacing them.
Keys the record was not defined with are ignored.
Parameters
...collections(
| Partial<{ name: string | null; callback: FontCallback | null }>
| Iterable<readonly [string, unknown]>
)[]Plain objects or key/value iterables to merge in.
Returns
thisA new record, or this one when no value changed.
Returns a record with each collection merged deeply into the value at
keyPath.Parameters
keyPathIterable<unknown>The keys to follow, outermost first.
...collectionsunknown[]Collections or plain objects to merge into the value there.
Returns
thisA new record, or this one when the value is unchanged.
- mergeDeepWith(
merger: (previous: unknown, next: unknown, key: unknown) => unknown,
...collections: (
| Partial<{ name: string | null; callback: FontCallback | null }>
| Iterable<readonly [string, unknown]>
)[],
): thisReturns a record with the entries of each collection merged in deeply, calling
mergerwhere a nested value is not a collection to decide the value that is kept.Keys the record was not defined with are ignored.
Parameters
merger(previous: unknown, next: unknown, key: unknown) => unknownReceives the current value, the incoming value and the key.
...collections(
| Partial<{ name: string | null; callback: FontCallback | null }>
| Iterable<readonly [string, unknown]>
)[]Plain objects or key/value iterables to merge in.
Returns
thisA new record, or this one when no value changed.
Returns a record with each collection merged into the value at
keyPath, one level at a time.Parameters
keyPathIterable<unknown>The keys to follow, outermost first.
...collectionsunknown[]Collections or plain objects to merge into the value there.
Returns
thisA new record, or this one when the value is unchanged.
- mergeWith(
merger: <K extends string | number | symbol>(
previous: { callback: FontCallback | null; name: string | null }[K],
next: { callback: FontCallback | null; name: string | null }[K],
key: K,
) => { callback: FontCallback | null; name: string | null }[K],
...collections: (
| Partial<{ callback: FontCallback | null; name: string | null }>
| Iterable<readonly [string, unknown]>
)[],
): thisReturns a record with the entries of each collection merged in, calling
mergerfor each key the record already holds to decide the value that is kept.Keys the record was not defined with are ignored.
Parameters
merger<K extends string | number | symbol>(
previous: { callback: FontCallback | null; name: string | null }[K],
next: { callback: FontCallback | null; name: string | null }[K],
key: K
) => { callback: FontCallback | null; name: string | null }[K]Receives the current value, the incoming value and the key.
...collections(
| Partial<{ callback: FontCallback | null; name: string | null }>
| Iterable<readonly [string, unknown]>
)[]Plain objects or key/value iterables to merge in.
Returns
thisA new record, or this one when no value changed.
- remove<K extends keyof { callback: FontCallback | null; name: string | null }>(
key: K & ("name" | "callback"),
): thisAn alias for delete.
Type Parameters
Kextends keyof { callback: FontCallback | null; name: string | null }Parameters
keyK & ("name" | "callback")One of the keys this record was defined with.
Returns
thisA new record, or this one when the value already equals the default.
- set<K extends keyof { callback: FontCallback | null; name: string | null }>(
key: K & ("name" | "callback"),
value: { callback: FontCallback | null; name: string | null }[K],
): thisReturns a record with
keyset tovalue.Setting a key to the value it already holds returns the same instance, so a record can be compared by reference to detect a change.
Type Parameters
Kextends keyof { callback: FontCallback | null; name: string | null }Parameters
keyK & ("name" | "callback")One of the keys this record was defined with.
value{ callback: FontCallback | null; name: string | null }[K]The value to store.
Returns
thisA new record, or this one when the value is unchanged or the key is not defined.
Returns a record with
valuewritten atkeyPath.Parameters
keyPathIterable<unknown>The keys to follow, outermost first.
valueunknownThe value to store.
Returns
thisA new record, or this one when the value is unchanged.
Converts this record and everything nested inside it to plain JavaScript values.
Returns
{ name: string | null; callback: FontCallback | null }A plain object holding this record's values, converted all the way down.
An alias for toObject, called by
JSON.stringify.Returns
{ callback: FontCallback | null; name: string | null }A plain object holding this record's values.
Converts this record to a plain object, one level deep. Nested records are left as they are.
Returns
{ callback: FontCallback | null; name: string | null }A plain object holding this record's values.
- update<K extends keyof { callback: FontCallback | null; name: string | null }>(
key: K & ("name" | "callback"),
updater: (
value: { callback: FontCallback | null; name: string | null }[K],
) => { callback: FontCallback | null; name: string | null }[K],
): thisReturns a record with
keyreplaced by the result of applyingupdaterto its current value.Type Parameters
Kextends keyof { callback: FontCallback | null; name: string | null }Parameters
keyK & ("name" | "callback")One of the keys this record was defined with.
updater(
value: { callback: FontCallback | null; name: string | null }[K]
) => { callback: FontCallback | null; name: string | null }[K]Receives the current value and returns the new one.
Returns
thisA new record, or this one when the value is unchanged.
- updateIn<N>(
keyPath: Iterable<unknown>,
notSetValue: N,
updater: (value: unknown) => unknown,
): thisReturns a record with the value at
keyPathreplaced by the result ofupdater. Returns a record with the value at
keyPathreplaced by the result ofupdater.Parameters
keyPathIterable<unknown>The keys to follow, outermost first.
updater(value: unknown) => unknownReceives the current value and returns the new one.
Returns
thisA new record, or this one when the value is unchanged.
Applies several changes as one, so only a single new record is allocated.
The record handed to
mutatormay be written to withset; it is frozen again oncemutatorreturns.Parameters
mutator(mutable: this) => unknownReceives a temporarily writable copy of this record.
Returns
thisA new record holding the applied changes, or this one when nothing changed.
This record is used to persist information related to custom fonts on Standalone deployments. Custom fonts need to be specified during the instance load and correctly fetched. They will be used while rendering the document contents and exporting its annotations.