diff --git a/src/IUVData.ts b/src/IUVData.ts index acec02715..ae1dbe00b 100644 --- a/src/IUVData.ts +++ b/src/IUVData.ts @@ -4,8 +4,11 @@ import { YouTubeData } from "./content-handlers/youtube/YouTubeData"; import { ILocale } from "./content-handlers/iiif/modules/uv-shared-module/ILocale"; import { BaseConfig } from "./content-handlers/iiif/BaseConfig"; -export interface IUVData extends IIIFData, EPubData, YouTubeData { - config?: BaseConfig; // do not pass this on initialisation, internal use only +export interface IUVData + extends IIIFData, + EPubData, + YouTubeData { + config?: T; // do not pass this on initialisation, internal use only debug?: boolean; embedded?: boolean; isReload?: boolean; diff --git a/src/UniversalViewer.ts b/src/UniversalViewer.ts index 190a75216..8b563eeb6 100644 --- a/src/UniversalViewer.ts +++ b/src/UniversalViewer.ts @@ -4,7 +4,7 @@ import BaseContentHandler, { EventListener } from "./BaseContentHandler"; export interface IUVOptions { target: HTMLElement; - data: IUVData; + data: IUVData; } enum ContentType { @@ -29,9 +29,9 @@ const ContentHandler: IContentHandlerRegistry = { ), }; -export class UniversalViewer extends BaseContentHandler { +export class UniversalViewer extends BaseContentHandler> { private _contentType: ContentType = ContentType.UNKNOWN; - private _assignedContentHandler: IContentHandler; + private _assignedContentHandler: IContentHandler>; private _externalEventListeners: EventListener[] = []; constructor(public options: IUVOptions) { @@ -51,7 +51,7 @@ export class UniversalViewer extends BaseContentHandler { }); } - private async _assignContentHandler(data: IUVData): Promise { + private async _assignContentHandler(data: IUVData): Promise { let contentType: ContentType; if (data[ContentType.IIIFLEGACY]) { @@ -91,7 +91,7 @@ export class UniversalViewer extends BaseContentHandler { return handlerChanged; } - public set(data: IUVData, initial?: boolean): void { + public set(data: IUVData, initial?: boolean): void { // content type may have changed this._assignContentHandler(data).then((handlerChanged: boolean) => { if (handlerChanged) { diff --git a/src/Utils.ts b/src/Utils.ts index de5619660..2e2190554 100644 --- a/src/Utils.ts +++ b/src/Utils.ts @@ -36,8 +36,8 @@ export const debounce = (callback: (args: any) => void, wait: number) => { }; export const propertiesChanged = ( - newData: IUVData, - currentData: IUVData, + newData: IUVData, + currentData: IUVData, properties: string[] ): boolean => { let propChanged: boolean = false; @@ -53,8 +53,8 @@ export const propertiesChanged = ( }; export const propertyChanged = ( - newData: IUVData, - currentData: IUVData, + newData: IUVData, + currentData: IUVData, propertyName: string ): boolean => { return currentData[propertyName] !== newData[propertyName]; diff --git a/src/content-handlers/iiif/BaseConfig.ts b/src/content-handlers/iiif/BaseConfig.ts index 3140292c4..edf1af59c 100644 --- a/src/content-handlers/iiif/BaseConfig.ts +++ b/src/content-handlers/iiif/BaseConfig.ts @@ -93,9 +93,6 @@ export type Options = { /** Determines if arrow keys can be used to navigate */ useArrowKeysToNavigate?: boolean; - /** Determines if PDF.js should be used for PDF rendering */ - usePdfJs?: boolean; - /** Determines if zoom to search result is enabled */ zoomToSearchResultEnabled?: boolean; diff --git a/src/content-handlers/iiif/IIIFContentHandler.ts b/src/content-handlers/iiif/IIIFContentHandler.ts index cad538ba5..9cf0fe373 100644 --- a/src/content-handlers/iiif/IIIFContentHandler.ts +++ b/src/content-handlers/iiif/IIIFContentHandler.ts @@ -36,64 +36,64 @@ const Extension: IExtensionRegistry = { name: "uv-av-extension", loader: () => /* webpackMode: "lazy" */ import( - "./extensions/uv-av-extension/Extension" - ), + "./extensions/uv-av-extension/Extension" + ), }, ALEPH: { name: "uv-aleph-extension", loader: () => /* webpackMode: "lazy" */ import( - "./extensions/uv-aleph-extension/Extension" - ), + "./extensions/uv-aleph-extension/Extension" + ), }, DEFAULT: { name: "uv-default-extension", loader: () => /* webpackMode: "lazy" */ import( - "./extensions/uv-default-extension/Extension" - ), + "./extensions/uv-default-extension/Extension" + ), }, EBOOK: { name: "uv-ebook-extension", loader: () => /* webpackMode: "lazy" */ import( - "./extensions/uv-ebook-extension/Extension" - ), + "./extensions/uv-ebook-extension/Extension" + ), }, MEDIAELEMENT: { name: "uv-mediaelement-extension", loader: () => /* webpackMode: "lazy" */ import( - "./extensions/uv-mediaelement-extension/Extension" - ), + "./extensions/uv-mediaelement-extension/Extension" + ), }, MODELVIEWER: { name: "uv-model-viewer-extension", loader: () => /* webpackMode: "lazy" */ import( - "./extensions/uv-model-viewer-extension/Extension" - ), + "./extensions/uv-model-viewer-extension/Extension" + ), }, OSD: { name: "uv-openseadragon-extension", loader: () => /* webpackMode: "lazy" */ import( - "./extensions/uv-openseadragon-extension/Extension" - ), + "./extensions/uv-openseadragon-extension/Extension" + ), }, PDF: { name: "uv-pdf-extension", loader: () => /* webpackMode: "lazy" */ import( - "./extensions/uv-pdf-extension/Extension" - ), + "./extensions/uv-pdf-extension/Extension" + ), }, SLIDEATLAS: { name: "uv-openseadragon-extension", loader: () => /* webpackMode: "lazy" */ import( - "./extensions/uv-openseadragon-extension/Extension" - ), + "./extensions/uv-openseadragon-extension/Extension" + ), }, }; @@ -196,7 +196,7 @@ export default class IIIFContentHandler extends BaseContentHandler return this._getExtensionByType(this._extensionRegistry[format], format); } - public set(data: IUVData, initial?: boolean): void { + public set(data: IUVData, initial?: boolean): void { if (initial) { this.extra.initial = true; } @@ -210,7 +210,11 @@ export default class IIIFContentHandler extends BaseContentHandler this._reload(data); } else { // changing any of these data properties forces the UV to reload. - const newData: IUVData = Object.assign({}, this.extension.data, data); + const newData: IUVData = Object.assign( + {}, + this.extension.data, + data + ); if ( newData.isReload || newData.iiifManifestId !== this.extension.data.iiifManifestId || @@ -269,12 +273,12 @@ export default class IIIFContentHandler extends BaseContentHandler // $elem.attr("class", ""); } - private async _reload(data: IUVData): Promise { + private async _reload(data: IUVData): Promise { this._pubsub.dispose(); // remove any existing event listeners data.target = ""; // clear target - this.subscribe(Events.RELOAD, (data?: IUVData) => { + this.subscribe(Events.RELOAD, (data?: IUVData) => { this.fire(Events.RELOAD, data); }); @@ -384,7 +388,10 @@ export default class IIIFContentHandler extends BaseContentHandler } // import the config file - let config = await (extension as any).loadConfig(data.locales[0].name, extension?.type.name); + let config = await (extension as any).loadConfig( + data.locales[0].name, + extension?.type.name + ); data.config = await that.configure(config); @@ -401,7 +408,7 @@ export default class IIIFContentHandler extends BaseContentHandler private _createExtension( extension: any, - data: IUVData, + data: IUVData, helper: Helper ): void { this.extension = extension; diff --git a/src/content-handlers/iiif/URLAdapter.ts b/src/content-handlers/iiif/URLAdapter.ts index 33cf11a05..f66bd43c9 100644 --- a/src/content-handlers/iiif/URLAdapter.ts +++ b/src/content-handlers/iiif/URLAdapter.ts @@ -40,7 +40,7 @@ export class URLAdapter extends UVAdapter { } } - public getInitialData(overrides?: IUVData): IUVData { + public getInitialData(overrides?: IUVData): IUVData { const formattedLocales: Array<{ label?: string; name: string }> = []; const locales = this.get("locales", ""); if (locales) { @@ -189,7 +189,7 @@ export class URLAdapter extends UVAdapter { uv.on( IIIFEvents.RANGE_CHANGE, (range) => { - const rangeId = !range || typeof range === 'string' ? range : range.id; + const rangeId = !range || typeof range === "string" ? range : range.id; this.set("rid", rangeId); }, false diff --git a/src/content-handlers/iiif/extensions/uv-aleph-extension/Extension.ts b/src/content-handlers/iiif/extensions/uv-aleph-extension/Extension.ts index ca07524c6..536d13d9d 100644 --- a/src/content-handlers/iiif/extensions/uv-aleph-extension/Extension.ts +++ b/src/content-handlers/iiif/extensions/uv-aleph-extension/Extension.ts @@ -15,7 +15,7 @@ import "./theme/theme.less"; import defaultConfig from "./config/config.json"; import { Config } from "./config/Config"; -export default class Extension extends BaseExtension +export default class Extension extends BaseExtension implements IAlephExtension { $downloadDialogue: JQuery; $multiSelectDialogue: JQuery; diff --git a/src/content-handlers/iiif/extensions/uv-aleph-extension/IAlephExtensionData.ts b/src/content-handlers/iiif/extensions/uv-aleph-extension/IAlephExtensionData.ts index 4e70277b9..172116023 100644 --- a/src/content-handlers/iiif/extensions/uv-aleph-extension/IAlephExtensionData.ts +++ b/src/content-handlers/iiif/extensions/uv-aleph-extension/IAlephExtensionData.ts @@ -1,3 +1,4 @@ import { IUVData } from "../../../../IUVData"; +import { Config } from "./config/Config"; -export interface IAlephExtensionData extends IUVData {} +export interface IAlephExtensionData extends IUVData {} diff --git a/src/content-handlers/iiif/extensions/uv-av-extension/Extension.ts b/src/content-handlers/iiif/extensions/uv-av-extension/Extension.ts index fad5a67c2..fb583aa20 100644 --- a/src/content-handlers/iiif/extensions/uv-av-extension/Extension.ts +++ b/src/content-handlers/iiif/extensions/uv-av-extension/Extension.ts @@ -17,7 +17,8 @@ import "./theme/theme.less"; import defaultConfig from "./config/config.json"; import { Config } from "./config/Config"; -export default class Extension extends BaseExtension implements IAVExtension { +export default class Extension extends BaseExtension + implements IAVExtension { $downloadDialogue: JQuery; $multiSelectDialogue: JQuery; $settingsDialogue: JQuery; diff --git a/src/content-handlers/iiif/extensions/uv-av-extension/IAVExtensionData.ts b/src/content-handlers/iiif/extensions/uv-av-extension/IAVExtensionData.ts index 94f4851a2..7a22fa7d9 100644 --- a/src/content-handlers/iiif/extensions/uv-av-extension/IAVExtensionData.ts +++ b/src/content-handlers/iiif/extensions/uv-av-extension/IAVExtensionData.ts @@ -1,3 +1,4 @@ import { IUVData } from "../../../../IUVData"; +import { Config } from "./config/Config"; -export interface IAVExtensionData extends IUVData {} +export interface IAVExtensionData extends IUVData {} diff --git a/src/content-handlers/iiif/extensions/uv-default-extension/Extension.ts b/src/content-handlers/iiif/extensions/uv-default-extension/Extension.ts index 434c9b681..119dc3181 100644 --- a/src/content-handlers/iiif/extensions/uv-default-extension/Extension.ts +++ b/src/content-handlers/iiif/extensions/uv-default-extension/Extension.ts @@ -14,7 +14,7 @@ import "./theme/theme.less"; import defaultConfig from "./config/config.json"; import { Config } from "./config/Config"; -export default class Extension extends BaseExtension +export default class Extension extends BaseExtension implements IDefaultExtension { $downloadDialogue: JQuery; $shareDialogue: JQuery; diff --git a/src/content-handlers/iiif/extensions/uv-ebook-extension/Extension.ts b/src/content-handlers/iiif/extensions/uv-ebook-extension/Extension.ts index 7ed357bff..7b4d32c80 100644 --- a/src/content-handlers/iiif/extensions/uv-ebook-extension/Extension.ts +++ b/src/content-handlers/iiif/extensions/uv-ebook-extension/Extension.ts @@ -18,7 +18,7 @@ import "./theme/theme.less"; import defaultConfig from "./config/config.json"; import { Config } from "./config/Config"; -export default class Extension extends BaseExtension +export default class Extension extends BaseExtension implements IEbookExtension { $downloadDialogue: JQuery; $moreInfoDialogue: JQuery; diff --git a/src/content-handlers/iiif/extensions/uv-ebook-extension/IEbookExtensionData.ts b/src/content-handlers/iiif/extensions/uv-ebook-extension/IEbookExtensionData.ts index 8044bcb2e..a9071d9a7 100644 --- a/src/content-handlers/iiif/extensions/uv-ebook-extension/IEbookExtensionData.ts +++ b/src/content-handlers/iiif/extensions/uv-ebook-extension/IEbookExtensionData.ts @@ -1,5 +1,6 @@ import { IUVData } from "../../../../IUVData"; +import { Config } from "./config/Config"; -export interface IEbookExtensionData extends IUVData { +export interface IEbookExtensionData extends IUVData { cfi: string; } diff --git a/src/content-handlers/iiif/extensions/uv-mediaelement-extension/Extension.ts b/src/content-handlers/iiif/extensions/uv-mediaelement-extension/Extension.ts index d260d85ca..96c5a83c6 100644 --- a/src/content-handlers/iiif/extensions/uv-mediaelement-extension/Extension.ts +++ b/src/content-handlers/iiif/extensions/uv-mediaelement-extension/Extension.ts @@ -30,7 +30,7 @@ import defaultConfig from "./config/config.json"; import { Events } from "../../../../Events"; import { Config } from "./config/Config"; -export default class Extension extends BaseExtension +export default class Extension extends BaseExtension implements IMediaElementExtension { $downloadDialogue: JQuery; $shareDialogue: JQuery; diff --git a/src/content-handlers/iiif/extensions/uv-model-viewer-extension/Extension.ts b/src/content-handlers/iiif/extensions/uv-model-viewer-extension/Extension.ts index 5daf2f91b..0d202eb6f 100644 --- a/src/content-handlers/iiif/extensions/uv-model-viewer-extension/Extension.ts +++ b/src/content-handlers/iiif/extensions/uv-model-viewer-extension/Extension.ts @@ -23,7 +23,7 @@ import { AnnotationGroup } from "@iiif/manifold"; import { AnnotationResults } from "../../modules/uv-shared-module/AnnotationResults"; import { Config } from "./config/Config"; -export default class ModelViewerExtension extends BaseExtension { +export default class ModelViewerExtension extends BaseExtension { $downloadDialogue: JQuery; $shareDialogue: JQuery; $helpDialogue: JQuery; diff --git a/src/content-handlers/iiif/extensions/uv-openseadragon-extension/Extension.ts b/src/content-handlers/iiif/extensions/uv-openseadragon-extension/Extension.ts index 699e87a16..a24c6bc1e 100644 --- a/src/content-handlers/iiif/extensions/uv-openseadragon-extension/Extension.ts +++ b/src/content-handlers/iiif/extensions/uv-openseadragon-extension/Extension.ts @@ -55,7 +55,7 @@ import { merge } from "../../../../Utils"; import defaultConfig from "./config/config.json"; import { Config } from "./config/Config"; -export default class OpenSeadragonExtension extends BaseExtension { +export default class OpenSeadragonExtension extends BaseExtension { $downloadDialogue: JQuery; $externalContentDialogue: JQuery; $helpDialogue: JQuery; diff --git a/src/content-handlers/iiif/extensions/uv-pdf-extension/Extension.ts b/src/content-handlers/iiif/extensions/uv-pdf-extension/Extension.ts index ad08c1871..845ff57f6 100644 --- a/src/content-handlers/iiif/extensions/uv-pdf-extension/Extension.ts +++ b/src/content-handlers/iiif/extensions/uv-pdf-extension/Extension.ts @@ -18,7 +18,8 @@ import defaultConfig from "./config/config.json"; import { Events } from "../../../../Events"; import { Config } from "./config/Config"; -export default class Extension extends BaseExtension implements IPDFExtension { +export default class Extension extends BaseExtension + implements IPDFExtension { $downloadDialogue: JQuery; $shareDialogue: JQuery; $helpDialogue: JQuery; diff --git a/src/content-handlers/iiif/extensions/uv-pdf-extension/IPDFExtensionData.ts b/src/content-handlers/iiif/extensions/uv-pdf-extension/IPDFExtensionData.ts index cf1c4b12a..4ecc425c8 100644 --- a/src/content-handlers/iiif/extensions/uv-pdf-extension/IPDFExtensionData.ts +++ b/src/content-handlers/iiif/extensions/uv-pdf-extension/IPDFExtensionData.ts @@ -1,5 +1,6 @@ import { IUVData } from "../../../../IUVData"; +import { Config } from "./config/Config"; -export interface IPDFExtensionData extends IUVData { +export interface IPDFExtensionData extends IUVData { anchor: string | null; } diff --git a/src/content-handlers/iiif/extensions/uv-pdf-extension/config/Config.ts b/src/content-handlers/iiif/extensions/uv-pdf-extension/config/Config.ts index 30f142a17..e3aeb9a30 100644 --- a/src/content-handlers/iiif/extensions/uv-pdf-extension/config/Config.ts +++ b/src/content-handlers/iiif/extensions/uv-pdf-extension/config/Config.ts @@ -1,7 +1,13 @@ -import { BaseConfig } from "@/content-handlers/iiif/BaseConfig"; +import { BaseConfig, Options } from "@/content-handlers/iiif/BaseConfig"; type Modules = {}; +type PDFOptions = Options & { + /** Determines if PDF.js should be used for PDF rendering */ + usePdfJs?: boolean; +}; + export type Config = BaseConfig & { + options: PDFOptions; modules: Modules; }; diff --git a/src/content-handlers/iiif/modules/uv-pdfcenterpanel-module/PDFCenterPanel.ts b/src/content-handlers/iiif/modules/uv-pdfcenterpanel-module/PDFCenterPanel.ts index b62e55c0d..1e30700ab 100644 --- a/src/content-handlers/iiif/modules/uv-pdfcenterpanel-module/PDFCenterPanel.ts +++ b/src/content-handlers/iiif/modules/uv-pdfcenterpanel-module/PDFCenterPanel.ts @@ -6,6 +6,7 @@ import { Bools } from "@edsilv/utils"; import { AnnotationBody, Canvas, IExternalResource } from "manifesto.js"; import { Events } from "../../../../Events"; import { loadScripts } from "../../../../Utils"; +import { Config } from "../../extensions/uv-pdf-extension/config/Config"; // declare var PDFJS: any; @@ -57,7 +58,12 @@ export class PDFCenterPanel extends CenterPanel { // Only attach PDF controls if we're using PDF.js; they have no meaning in // PDFObject. However, we still create the objects above so that references // to them do not cause errors (simpler than putting usePdfJs checks all over): - if (Bools.getBool(this.extension.data.config!.options.usePdfJs, false)) { + if ( + Bools.getBool( + (this.extension.data.config! as Config).options.usePdfJs, + false + ) + ) { // this.$content.append(this._$spinner); this.$content.append(this._$progress); this.$content.append(this._$prevButton); @@ -265,7 +271,12 @@ export class PDFCenterPanel extends CenterPanel { this._lastMediaUri = mediaUri; - if (!Bools.getBool(this.extension.data.config!.options.usePdfJs, false)) { + if ( + !Bools.getBool( + (this.extension.data.config! as Config).options.usePdfJs, + false + ) + ) { window.PDFObject = await import( /* webpackChunkName: "pdfobject" */ /* webpackMode: "lazy" */ "pdfobject" ); @@ -317,7 +328,12 @@ export class PDFCenterPanel extends CenterPanel { } private _render(num: number): void { - if (!Bools.getBool(this.extension.data.config!.options.usePdfJs, false)) { + if ( + !Bools.getBool( + (this.extension.data.config! as Config).options.usePdfJs, + false + ) + ) { return; } diff --git a/src/content-handlers/iiif/modules/uv-shared-module/BaseExtension.ts b/src/content-handlers/iiif/modules/uv-shared-module/BaseExtension.ts index bab84dce9..38f77b818 100644 --- a/src/content-handlers/iiif/modules/uv-shared-module/BaseExtension.ts +++ b/src/content-handlers/iiif/modules/uv-shared-module/BaseExtension.ts @@ -49,7 +49,7 @@ import { StoreApi } from "zustand/vanilla"; import { ExtensionState } from "./ExtensionState"; import { BaseConfig, Metric, MetricType } from "../../BaseConfig"; -export class BaseExtension implements IExtension { +export class BaseExtension implements IExtension { $authDialogue: JQuery; $clickThroughDialogue: JQuery; $element: JQuery; @@ -59,7 +59,7 @@ export class BaseExtension implements IExtension { annotations: AnnotationGroup[] = []; clickThroughDialogue: ClickThroughDialogue; extensionHost: IIIFExtensionHost; - data: IUVData; + data: IUVData; extensions: any; helper: Helper; isCreated: boolean = false; @@ -79,7 +79,7 @@ export class BaseExtension implements IExtension { tabbing: boolean = false; browserDetect: BrowserDetect; locales = {}; - defaultConfig: BaseConfig; + defaultConfig: T; public create(): void { const that = this; @@ -181,7 +181,7 @@ export class BaseExtension implements IExtension { if (manifestUri) { this.fire(Events.DROP, manifestUri); - const data: IUVData = {}; + const data: IUVData = >{}; data.iiifManifestId = manifestUri; this.reload(data); } @@ -714,7 +714,7 @@ export class BaseExtension implements IExtension { } // re-bootstraps the application with new querystring params - reload(data?: IUVData): void { + reload(data?: IUVData): void { this.extensionHost.publish(Events.RELOAD, data); } @@ -1039,7 +1039,7 @@ export class BaseExtension implements IExtension { // todo: use redux in manifold to get reset state viewManifest(manifest: Manifest): void { - const data: IUVData = {}; + const data: IUVData = >{}; data.iiifManifestId = this.helper.manifestUri; data.collectionIndex = this.helper.getCollectionIndex(manifest); data.manifestIndex = manifest.index; @@ -1050,7 +1050,7 @@ export class BaseExtension implements IExtension { // todo: use redux in manifold to get reset state viewCollection(collection: Collection): void { - const data: IUVData = {}; + const data: IUVData = >{}; //data.manifestUri = this.helper.manifestUri; data.iiifManifestId = collection.parentCollection ? collection.parentCollection.id @@ -1168,7 +1168,7 @@ export class BaseExtension implements IExtension { changeLocale(locale: string): void { // re-order locales so the passed locale is first - const data: IUVData = {}; + const data: IUVData = >{}; if (this.data.locales) { data.locales = this.data.locales.slice(0); diff --git a/src/content-handlers/iiif/modules/uv-shared-module/IExtension.ts b/src/content-handlers/iiif/modules/uv-shared-module/IExtension.ts index 219c68cf5..0812ae480 100644 --- a/src/content-handlers/iiif/modules/uv-shared-module/IExtension.ts +++ b/src/content-handlers/iiif/modules/uv-shared-module/IExtension.ts @@ -27,7 +27,7 @@ export interface IExtension { extensionHost: IIIFExtensionHost; create(): void; createModules(): void; - data: IUVData; + data: IUVData; defaultConfig: BaseConfig; dispose(): void; exitFullScreen(): void; @@ -71,7 +71,7 @@ export interface IExtension { type: ExtensionLoader; redirect(uri: string): void; refresh(): void; - reload(data?: IUVData): void; + reload(data?: IUVData): void; resize(): void; resources: IExternalResourceData[] | null; shifted: boolean;