Skip to content

Commit

Permalink
update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
edsilv committed Apr 15, 2018
2 parents 43cfb0a + 175de74 commit 725f693
Show file tree
Hide file tree
Showing 12 changed files with 125 additions and 94 deletions.
25 changes: 10 additions & 15 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,15 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Mocha Tests",
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
"args": [
"-u",
"tdd",
"--timeout",
"999999",
"--colors",
"${workspaceFolder}/test"
],
"internalConsoleOptions": "openOnSessionStart"
}
{
"type": "node",
"request": "launch",
"name": "Debug Tests",
"program": "${workspaceRoot}/node_modules/jest/bin/jest.js",
"cwd": "${workspaceRoot}",
"args": [

]
}
]
}
2 changes: 1 addition & 1 deletion examples
27 changes: 23 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
},
"homepage": "https://github.com/universalviewer/universalviewer",
"devDependencies": {
"@types/jest": "^22.2.2",
"@types/puppeteer": "^1.2.0",
"async": "0.9.0",
"chai": "4.1.2",
"chalk": "0.5.1",
Expand All @@ -54,6 +56,7 @@
"lodash": "4.17.4",
"ncp": "2.0.0",
"puppeteer": "^1.2.0",
"ts-jest": "^22.4.2",
"typescript": "2.7.2"
},
"dependencies": {
Expand All @@ -75,29 +78,45 @@
"jsviews": "0.9.83",
"key-codes": "edsilv/key-codes#v0.0.7",
"manifesto.js": "2.2.16",
"@iiif/manifold": "1.2.22",
"@iiif/manifold": "1.2.24",
"mediaelement": "4.0.2",
"opencollective": "1.0.3",
"openseadragon": "2.2.1",
"pdfjs-dist": "2.0.161",
"requirejs": "2.2.0",
"three": "0.87.1",
"three": "0.91.0",
"utils": "edsilv/utils#v0.2.1",
"uv-cy-gb-theme": "UniversalViewer/uv-cy-gb-theme#v1.1.1",
"uv-en-gb-theme": "UniversalViewer/uv-en-gb-theme#v1.1.1",
"virtex3d": "0.3.9"
"virtex3d": "0.3.10"
},
"collective": {
"type": "opencollective",
"url": "https://opencollective.com/universalviewer",
"logo": "https://opencollective.com/opencollective/logo.txt"
},
"jest": {
"globals": {
"ts-jest": {
"enableTsDiagnostics": true
}
},
"preset": "jest-puppeteer",
"testRegex": "test.*test.js",
"transform": {
"^.+\\.tsx?$": "ts-jest"
},
"testPathIgnorePatterns": [
"/node_modules/",
"/examples"
],
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json",
"node"
]
}
}
6 changes: 5 additions & 1 deletion src/URLDataProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ export default class URLDataProvider extends UVDataProvider {

public set(key: string, value: string): void {
if (!this.readonly) {
Utils.Urls.setHashParameter(key, value.toString(), document);
if (value) {
Utils.Urls.setHashParameter(key, value.toString(), document);
} else {
Utils.Urls.setHashParameter(key, '', document);
}
}
}
}
24 changes: 24 additions & 0 deletions src/extensions/uv-seadragon-extension/Bounds.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { } from 'Jest';

import { Bounds } from './Bounds';

describe('Bounds', () => {
const bounds = new Bounds(0, 5, 100, 95);

it('has accessors available', () => {
expect(bounds.x).toEqual(0);
expect(bounds.y).toEqual(5);
expect(bounds.w).toEqual(100);
expect(bounds.h).toEqual(95);
});
describe('toString', () => {
it('is in format x,y,w,h', () => {
expect(bounds.toString()).toEqual('0,5,100,95');
});
});
describe('fromString', () => {
it('creates with arguments in correct order', () => {
expect(Bounds.fromString(bounds.toString()).toString()).toEqual(bounds.toString());
});
});
});
2 changes: 1 addition & 1 deletion src/extensions/uv-seadragon-extension/Bounds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ export class Bounds {
var boundsArr: string[] = bounds.split(',');
return new Bounds(Number(boundsArr[0]), Number(boundsArr[1]), Number(boundsArr[2]), Number(boundsArr[3]));
}
}
}
37 changes: 17 additions & 20 deletions src/extensions/uv-virtex-extension/lib/virtex.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// virtex v0.3.9 https://github.com/edsilv/virtex#readme
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.virtex = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
// virtex v0.3.10 https://github.com/edsilv/virtex#readme
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.virtex = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
(function (global){

var Virtex;
Expand Down Expand Up @@ -142,22 +142,15 @@ var Virtex;
var glTFFileTypeHandler = /** @class */ (function () {
function glTFFileTypeHandler() {
}
glTFFileTypeHandler.setup = function (viewport, obj) {
glTFFileTypeHandler.setup = function (viewport, gltf) {
return new Promise(function (resolve) {
viewport.objectGroup.add(obj.scene);
if (obj.animations) {
var animations = obj.animations;
for (var i = 0, l = animations.length; i < l; i++) {
//const animation = animations[i];
//animation.loop = true;
//animation.play();
}
}
viewport.scene = obj.scene;
if (obj.cameras && obj.cameras.length) {
viewport.camera = obj.cameras[0];
}
resolve(obj);
// todo: add animation, gltf camera support e.g.
// https://github.com/donmccurdy/three-gltf-viewer/blob/master/src/viewer.js#L183
// allow specifying envmap? https://github.com/mrdoob/three.js/blob/dev/examples/webgl_loader_gltf.html#L92
var scene = gltf.scene || gltf.scenes[0];
viewport.objectGroup.add(scene);
viewport.createCamera();
resolve(gltf);
});
};
return glTFFileTypeHandler;
Expand Down Expand Up @@ -587,10 +580,14 @@ var Virtex;
return new THREE.Box3().setFromObject(this.objectGroup);
};
Viewport.prototype._getBoundingWidth = function () {
return this._getBoundingBox().getSize().x;
var target = new THREE.Vector3();
this._getBoundingBox().getSize(target);
return target.x;
};
Viewport.prototype._getBoundingHeight = function () {
return this._getBoundingBox().getSize().y;
var target = new THREE.Vector3();
this._getBoundingBox().getSize(target);
return target.y;
};
// private _getDistanceToObject(): number {
// return this.camera.position.distanceTo(this.objectGroup.position);
Expand Down Expand Up @@ -958,4 +955,4 @@ var Virtex;

}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{}]},{},[1])(1)
});
});
79 changes: 33 additions & 46 deletions src/lib/manifold.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @iiif/manifold v1.2.22 https://github.com/iiif-commons/manifold#readme
// @iiif/manifold v1.2.24 https://github.com/iiif-commons/manifold#readme
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.iiifmanifold = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
(function (global){

Expand Down Expand Up @@ -237,6 +237,7 @@ var Manifold;
canvas.externalResource = this;
this.dataUri = this._getDataUri(canvas);
this.index = canvas.index;
this.authAPIVersion = options.authApiVersion;
this._parseAuthServices(canvas);
// get the height and width of the image resource if available
this._parseDimensions(canvas);
Expand Down Expand Up @@ -284,21 +285,28 @@ var Manifold;
}
};
ExternalResource.prototype._parseAuthServices = function (resource) {
var auth1_clickThroughService = manifesto.Utils.getService(resource, manifesto.ServiceProfile.auth1Clickthrough().toString());
var auth1_loginService = manifesto.Utils.getService(resource, manifesto.ServiceProfile.auth1Login().toString());
var auth1_externalService = manifesto.Utils.getService(resource, manifesto.ServiceProfile.auth1External().toString());
var auth1_kioskService = manifesto.Utils.getService(resource, manifesto.ServiceProfile.auth1Kiosk().toString());
if (auth1_clickThroughService || auth1_loginService || auth1_externalService || auth1_kioskService) {
this.authAPIVersion = 1;
if (this.authAPIVersion === 0.9) {
this.clickThroughService = manifesto.Utils.getService(resource, manifesto.ServiceProfile.clickThrough().toString());
this.loginService = manifesto.Utils.getService(resource, manifesto.ServiceProfile.login().toString());
this.restrictedService = manifesto.Utils.getService(resource, manifesto.ServiceProfile.restricted().toString());
if (this.clickThroughService) {
this.logoutService = this.clickThroughService.getService(manifesto.ServiceProfile.logout().toString());
this.tokenService = this.clickThroughService.getService(manifesto.ServiceProfile.token().toString());
}
else if (this.loginService) {
this.logoutService = this.loginService.getService(manifesto.ServiceProfile.logout().toString());
this.tokenService = this.loginService.getService(manifesto.ServiceProfile.token().toString());
}
else if (this.restrictedService) {
this.logoutService = this.restrictedService.getService(manifesto.ServiceProfile.logout().toString());
this.tokenService = this.restrictedService.getService(manifesto.ServiceProfile.token().toString());
}
}
else {
this.authAPIVersion = 0.9;
}
if (this.authAPIVersion === 1) {
this.clickThroughService = auth1_clickThroughService;
this.loginService = auth1_loginService;
this.externalService = auth1_externalService;
this.kioskService = auth1_kioskService;
this.clickThroughService = manifesto.Utils.getService(resource, manifesto.ServiceProfile.auth1Clickthrough().toString());
this.loginService = manifesto.Utils.getService(resource, manifesto.ServiceProfile.auth1Login().toString());
this.externalService = manifesto.Utils.getService(resource, manifesto.ServiceProfile.auth1External().toString());
this.kioskService = manifesto.Utils.getService(resource, manifesto.ServiceProfile.auth1Kiosk().toString());
if (this.clickThroughService) {
this.logoutService = this.clickThroughService.getService(manifesto.ServiceProfile.auth1Logout().toString());
this.tokenService = this.clickThroughService.getService(manifesto.ServiceProfile.auth1Token().toString());
Expand All @@ -316,23 +324,6 @@ var Manifold;
this.tokenService = this.kioskService.getService(manifesto.ServiceProfile.auth1Token().toString());
}
}
else {
this.clickThroughService = manifesto.Utils.getService(resource, manifesto.ServiceProfile.clickThrough().toString());
this.loginService = manifesto.Utils.getService(resource, manifesto.ServiceProfile.login().toString());
this.restrictedService = manifesto.Utils.getService(resource, manifesto.ServiceProfile.restricted().toString());
if (this.clickThroughService) {
this.logoutService = this.clickThroughService.getService(manifesto.ServiceProfile.logout().toString());
this.tokenService = this.clickThroughService.getService(manifesto.ServiceProfile.token().toString());
}
else if (this.loginService) {
this.logoutService = this.loginService.getService(manifesto.ServiceProfile.logout().toString());
this.tokenService = this.loginService.getService(manifesto.ServiceProfile.token().toString());
}
else if (this.restrictedService) {
this.logoutService = this.restrictedService.getService(manifesto.ServiceProfile.logout().toString());
this.tokenService = this.restrictedService.getService(manifesto.ServiceProfile.token().toString());
}
}
};
ExternalResource.prototype._parseDimensions = function (canvas) {
var images = canvas.getImages();
Expand Down Expand Up @@ -432,14 +423,6 @@ var Manifold;
Manifold.ExternalResource = ExternalResource;
})(Manifold || (Manifold = {}));

var __assign = (this && this.__assign) || Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
var Manifold;
(function (Manifold) {
var Helper = /** @class */ (function () {
Expand Down Expand Up @@ -697,7 +680,7 @@ var Manifold;
currentRange = this.getCurrentRange();
}
if (currentRange) {
var flatTree = this._getFlattenedTree(this._extractChildren(this.getTree()), this._extractChildren).map(function (x) { return delete x.children && x; });
var flatTree = this.getFlattenedTree();
for (var i = 0; i < flatTree.length; i++) {
var node = flatTree[i];
// find current range in flattened tree
Expand Down Expand Up @@ -746,14 +729,18 @@ var Manifold;
return null;
};
Helper.prototype.getFlattenedTree = function () {
return this._getFlattenedTree(this._extractChildren(this.getTree()), this._extractChildren).map(function (x) { return delete x.children && x; });
return this._flattenTree(this.getTree(), 'nodes');
};
Helper.prototype._getFlattenedTree = function (children, extractChildren, level, parent) {
Helper.prototype._flattenTree = function (root, key) {
var _this = this;
return Array.prototype.concat.apply(children.map(function (x) { return (__assign({}, x, { level: level || 1, parent: parent || null })); }), children.map(function (x) { return _this._getFlattenedTree(extractChildren(x) || [], extractChildren, (level || 1) + 1, x.id); }));
};
Helper.prototype._extractChildren = function (treeNode) {
return treeNode.nodes;
var flatten = [Object.assign({}, root)];
delete flatten[0][key];
if (root[key] && root[key].length > 0) {
return flatten.concat(root[key]
.map(function (child) { return _this._flattenTree(child, key); })
.reduce(function (a, b) { return a.concat(b); }, []));
}
return flatten;
};
Helper.prototype.getRanges = function () {
return this.manifest.getAllRanges();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class MediaElementCenterPanel extends CenterPanel {
const renderings: Manifesto.IRendering[] = canvas.getRenderings();

if (renderings && renderings.length) {
$.each(canvas.getRenderings(), (index: number, rendering: Manifesto.IRendering) => {
canvas.getRenderings().forEach((rendering: Manifesto.IRendering) => {
sources.push({
type: rendering.getFormat().toString(),
src: rendering.id
Expand All @@ -80,7 +80,7 @@ export class MediaElementCenterPanel extends CenterPanel {
const formats: Manifesto.IAnnotationBody[] | null = this.extension.getMediaFormats(this.extension.helper.getCurrentCanvas());

if (formats && formats.length) {
$.each(formats, (index: number, format: Manifesto.IAnnotationBody) => {
formats.forEach((format: Manifesto.IAnnotationBody) => {

const type: Manifesto.MediaType | null = format.getFormat();

Expand Down
6 changes: 3 additions & 3 deletions src/modules/uv-shared-module/BaseExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ export class BaseExtension implements IExtension {
// if limitLocales is disabled,
// loop through remaining availableLocales and add to finalLocales.

$.each(configuredLocales, (index: number, configuredLocale: ILocale) => {
configuredLocales.forEach((configuredLocale: ILocale) => {
const match: any[] = availableLocales.filter((item: any) => { return item.name === configuredLocale.name; });
if (match.length) {
var m: any = match[0];
Expand All @@ -735,7 +735,7 @@ export class BaseExtension implements IExtension {
const limitLocales: boolean = Utils.Bools.getBool(this.data.config.options.limitLocales, false);

if (!limitLocales) {
$.each(availableLocales, (index: number, availableLocale: any) => {
availableLocales.forEach((availableLocale: any) => {
if (!availableLocale.added) {
finalLocales.push(availableLocale);
}
Expand Down Expand Up @@ -980,7 +980,7 @@ export class BaseExtension implements IExtension {
const indices: number[] = this.getPagedIndices();
const resourcesToLoad: Manifesto.IExternalResource[] = [];

$.each(indices, (i: number, index: number) => {
indices.forEach((index: number) => {
const canvas: Manifesto.ICanvas = this.helper.getCanvasByIndex(index);
let r: Manifesto.IExternalResource;

Expand Down
Loading

0 comments on commit 725f693

Please sign in to comment.