@readium/shared
Version:
Shared models to be used across other Readium projects and implementations in Typescript
55 lines (47 loc) • 1.43 kB
text/typescript
/* Copyright 2021 Readium Foundation. All rights reserved.
* Use of this source code is governed by a BSD-style license,
* available in the LICENSE file present in the Github repository of the project.
*/
export enum Page {
left = 'left',
right = 'right',
center = 'center'
}
/**
* Properties associated to the linked resource.
*
* This is opened for extensions.
* https://readium.org/webpub-manifest/schema/link.schema.json
*/
export class Properties {
public otherProperties: { [key: string]: any };
constructor(values: { [key: string]: any }) {
this.otherProperties = values;
}
get page(): Page | undefined {
return this.otherProperties['page'] as Page | undefined;
}
/**
* Creates a [Properties] from its RWPM JSON representation.
*/
public static deserialize(json: any): Properties | undefined {
if (!json) return;
return new Properties(json);
}
/**
* Serializes a [Properties] to its RWPM JSON representation.
*/
public serialize(): any {
return this.otherProperties;
}
/**
* Makes a copy of this [Properties] after merging in the given additional other [properties].
*/
public add(properties: { [key: string]: any }): Properties {
const _properties = Object.assign({}, this.otherProperties);
for (const property in properties) {
_properties[property] = properties[property];
}
return new Properties(_properties);
}
}