@readium/shared
Version:
Shared models to be used across other Readium projects and implementations in Typescript
132 lines (131 loc) • 5.05 kB
TypeScript
import { MediaType } from '../util/mediatype/MediaType';
import { Properties } from './Properties';
import { Locator } from './Locator';
/**
* Link Object for the Readium Web Publication Manifest.
* https://readium.org/webpub-manifest/schema/link.schema.json
*/
export declare class Link {
/** URI or URI template of the linked resource. */
readonly href: string;
/** Indicates that a URI template is used in href. */
readonly templated?: boolean;
/** MIME type of the linked resource. */
readonly type?: string;
/** Title of the linked resource. */
readonly title?: string;
/** Relation between the linked resource and its containing collection. */
readonly rels?: Set<string>;
/** Properties associated to the linked resource. */
properties?: Properties;
/** Height of the linked resource in pixels. */
readonly height?: number;
/** Width of the linked resource in pixels. */
readonly width?: number;
/** Size of the linked resource in bytes. */
readonly size?: number;
/** Length of the linked resource in seconds. */
readonly duration?: number;
/** Bitrate of the linked resource in kbps. */
readonly bitrate?: number;
/** Expected language of the linked resource. */
readonly languages?: Array<string>;
/** Alternate resources for the linked resource. */
readonly alternates?: Links;
/** Resources that are children of the linked resource, in the context of a given collection role. */
readonly children?: Links;
/**
* Creates a [Link].
*/
constructor(values: {
href: string;
templated?: boolean;
type?: string;
title?: string;
rels?: Set<string>;
properties?: Properties;
height?: number;
width?: number;
size?: number;
duration?: number;
bitrate?: number;
languages?: Array<string>;
alternates?: Links;
children?: Links;
});
/**
* Parses a [Link] from its RWPM JSON representation.
*/
static deserialize(json: any): Link | undefined;
/**
* Serializes a [Link] to its RWPM JSON representation.
*/
serialize(): any;
/** MediaType of the linked resource. */
get mediaType(): MediaType;
/** Computes an absolute URL to the link, relative to the given `baseURL`.
* If the link's `href` is already absolute, the `baseURL` is ignored.
*/
toURL(baseUrl?: string): string | undefined;
/** List of URI template parameter keys, if the `Link` is templated. */
get templateParameters(): Set<string>;
/** Expands the `Link`'s HREF by replacing URI template variables by the given parameters.
* See RFC 6570 on URI template: https://tools.ietf.org/html/rfc6570
*/
expandTemplate(parameters: {
[param: string]: string;
}): Link;
/**
* Makes a copy of this [Link] after merging in the given additional other [properties].
*/
addProperties(properties: {
[key: string]: any;
}): Link;
/**
* Creates a [Locator] from a reading order [Link].
*/
get locator(): Locator;
}
/**
* Parses multiple JSON links into an array of Link.
*/
export declare class Links {
items: Array<Link>;
/**
* Creates a [Links].
*/
constructor(items: Array<Link>);
/**
* Creates a list of [Link] from its RWPM JSON representation.
*/
static deserialize(json: any): Links | undefined;
/**
* Serializes an array of [Link] to its RWPM JSON representation.
*/
serialize(): any;
/** Finds the first link with the given relation. */
findWithRel(rel: string): Link | undefined;
/** Finds all the links with the given relation. */
filterByRel(rel: string): Array<Link>;
/** Finds the first link matching the given HREF. */
findWithHref(href: string): Link | undefined;
/** Finds the index of the first link matching the given HREF. */
findIndexWithHref(href: string): number;
/** Finds the first link matching the given media type. */
findWithMediaType(mediaType: string): Link | undefined;
/** Finds all the links matching the given media type. */
filterByMediaType(mediaType: string): Array<Link>;
/** Finds all the links matching any of the given media types. */
filterByMediaTypes(mediaTypes: Array<string>): Array<Link>;
/** Returns whether all the resources in the collection are audio clips. */
everyIsAudio(): boolean;
/** Returns whether all the resources in the collection are bitmaps. */
everyIsBitmap(): boolean;
/** Returns whether all the resources in the collection are HTML documents. */
everyIsHTML(): boolean;
/** Returns whether all the resources in the collection are video clips. */
everyIsVideo(): boolean;
/** Returns whether all the resources in the collection are matching any of the given media types. */
everyMatchesMediaType(mediaTypes: string | Array<string>): boolean;
filterLinksHasType(): Array<Link>;
}