Some implementation in classes; add JSDOC

This commit is contained in:
2023-10-02 17:17:36 +02:00
parent 4bbcf63940
commit 076dd1a717
9 changed files with 357 additions and 22 deletions

View File

@@ -1,9 +1,60 @@
import IIIFResource from './IIIFResource.js';
/**
* @class
* @implements IIIFResource
*/
class Canvas {
id = '';
type = 'sc:Canvas';
label = '';
images = [];
thumbnail = {};
/**
*
* @param {string} label
*/
constructor(IIIFApiVersion, baseURL) {
this.context = `http://iiif.io/api/presentation/${IIIFApiVersion}/context.json`;
this.BASE_URL = baseURL;
}
/**
* @param {string} idParam From the request
* @param {int|string} name A unique name for this canvas
*/
generateID(idParam, name) {
this.id = `${this.BASE_URL}/iiif/${idParam}/canvas/${name}`;
}
/**
* @param {string} label A label for this canvas
*/
setLabel(label) {
this.label = label;
}
/**
* Add a thumbnail object
* @todo Support multiple thumbs?
* @param {int} [height=300]
* @param {int} [width=300]
*/
setThumbnail(height = 300, width = 300) {
this.thumbnail = {
"@id" : '',
"@type" : 'dctypes:Image',
height,
width
}
}
/**
* Object representation
*/
toObject() {
return {
"@context" : this.context,
"@id" : this.id,
"@type" : this.type,
"label" : this.label,
"thumbnail" : this.thumbnail
}
}
}
export default Canvas;

View File

@@ -1,10 +1,7 @@
import IIIFResource from './IIIFResource.js';
import Sequence from "./Sequence.js";
import Canvas from "./Canvas.js";
/**
* @implements IIIFResource
* @class
*/
class Manifest {
id = '';
@@ -22,14 +19,7 @@ class Manifest {
* @param {Sequence} sequence The Sequence object
*/
addSequence(sequence) {
this.sequences.push(sequence);
}
/**
* @todo Implement
* @param {Canvas} canvas The Canvas object
*/
addCanvas(canvas) {
this.sequences.push(sequence.toObject());
}
/**
* @param {string} idParam From the request
@@ -46,6 +36,7 @@ class Manifest {
"@context" : this.context,
"@id" : this.id,
"@type" : this.type,
sequences: this.sequences,
}
}
}

View File

@@ -3,9 +3,27 @@ import IIIFResource from './IIIFResource.js';
* @todo Not needed in IIIF API v3,
* replaced by items
* @implements IIIFResource
* @class
*/
class Sequence {
canvases = [];
id = '';
type = 'sc:Sequence';
/**
* @todo Implement
* @param {Canvas} canvas The Canvas object
*/
addCanvas(canvas) {
this.canvases.push(canvas.toObject());
}
/**
* @todo Implement
*/
toObject() {
return {
"@id" : this.id,
"@type" : this.type,
canvases : this.canvases
}
}
}
export default Sequence;