@iiif/3d-manifesto-dev
Version:
IIIF Presentation API utility library for client and server with 3D extension
96 lines • 3.96 kB
JavaScript
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
import { Annotation, AnnotationPage, ManifestResource, Color, } from "./internal";
// @ts-ignore
import flattenDeep from "lodash/flattenDeep";
var Scene = /** @class */ (function (_super) {
__extends(Scene, _super);
function Scene(jsonld, options) {
return _super.call(this, jsonld, options) || this;
}
// Presentation API 3.0
Scene.prototype.getContent = function () {
var content = [];
var items = this.__jsonld.items || this.__jsonld.content;
if (!items)
return content;
// should be contained in an AnnotationPage
var annotationPage = null;
if (items.length) {
annotationPage = new AnnotationPage(items[0], this.options);
}
if (!annotationPage) {
return content;
}
var annotations = annotationPage.getItems();
for (var i = 0; i < annotations.length; i++) {
var a = annotations[i];
var annotation = new Annotation(a, this.options);
content.push(annotation);
}
return content;
};
Object.defineProperty(Scene.prototype, "Content", {
// 3D extension
get: function () {
return this.getContent();
},
enumerable: false,
configurable: true
});
Scene.prototype.getAnnotationById = function (searchId) {
for (var _i = 0, _a = this.Content; _i < _a.length; _i++) {
var anno = _a[_i];
if (anno.id === searchId)
return anno;
}
return null;
};
Scene.prototype.getBackgroundColor = function () {
// regular expression intended to match strings like
// "#FF00FF" -- interpreted as three hexadecimal values
// in range 0-255 . Not that the \w escape matches digits,
// upper and lower case latin characters, and underscore
// currently only supports the form for CSS
// https://www.w3.org/wiki/CSS/Properties/color/RGB
// with 6 hexadecimal digits
var bgc = this.getProperty("backgroundColor");
if (bgc)
return Color.fromCSS(bgc);
else
return null;
};
// Annotations not rendered as part of the Canvas
// Have non-painting motivations and are listed in Canvas annotations property, not items property
Scene.prototype.getNonContentAnnotations = function () {
var _this = this;
var annotationPages = (this.__jsonld.annotations || [])
.filter(function (annotationPage) {
return annotationPage && annotationPage.type === "AnnotationPage";
})
.map(function (annotationPage) { return new AnnotationPage(annotationPage, _this.options); });
if (!annotationPages.length)
return [];
var annotationsNested = annotationPages.map(function (page) {
return page.getItems();
});
var annotationsFlat = flattenDeep(annotationsNested);
return annotationsFlat.map(function (annotation) { return new Annotation(annotation, _this.options); });
};
return Scene;
}(ManifestResource));
export { Scene };
//# sourceMappingURL=Scene.js.map