diva.js 6.0.1 → 7.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (133) hide show
  1. package/.clang-format +7 -0
  2. package/.github/workflows/npm-publish.yml +45 -0
  3. package/LICENSE +55 -0
  4. package/Makefile +75 -0
  5. package/README.md +15 -108
  6. package/elm.json +32 -0
  7. package/package.json +12 -59
  8. package/review/elm.json +52 -0
  9. package/review/src/ReviewConfig.elm +87 -0
  10. package/scripts/elm-esm.sh +40 -0
  11. package/scripts/minify-css.mjs +31 -0
  12. package/src/Filters.elm +1044 -0
  13. package/src/Main.elm +1217 -0
  14. package/src/Model.elm +213 -0
  15. package/src/Msg.elm +59 -0
  16. package/src/Utilities.elm +46 -0
  17. package/src/View/CollectionExplorer.elm +172 -0
  18. package/src/View/Helpers.elm +86 -0
  19. package/src/View/HtmlRenderer.elm +136 -0
  20. package/src/View/Icons.elm +159 -0
  21. package/src/View/ManifestInfoModal.elm +363 -0
  22. package/src/View/PageViewModal.elm +1046 -0
  23. package/src/View/Sidebar.elm +786 -0
  24. package/src/View/Toolbar.elm +189 -0
  25. package/src/View.elm +244 -0
  26. package/src/diva.ts +802 -0
  27. package/src/filters.ts +1843 -0
  28. package/src/styles/app.css +328 -0
  29. package/src/styles/collection.css +75 -0
  30. package/src/styles/modal.css +388 -0
  31. package/src/styles/sidebar.css +215 -0
  32. package/src/styles/theme.css +39 -0
  33. package/src/styles/toolbar.css +154 -0
  34. package/src/viewer-element.ts +1307 -0
  35. package/testing/index.html +52 -0
  36. package/testing/testing.html +231 -0
  37. package/tsconfig.json +12 -0
  38. package/AUTHORS +0 -22
  39. package/_site/diva.iml +0 -11
  40. package/build/diva.css +0 -554
  41. package/build/diva.css.map +0 -1
  42. package/build/diva.js +0 -9
  43. package/build/diva.js.map +0 -1
  44. package/build/plugins/download.js +0 -2
  45. package/build/plugins/download.js.map +0 -1
  46. package/build/plugins/manipulation.js +0 -2
  47. package/build/plugins/manipulation.js.map +0 -1
  48. package/build/plugins/metadata.js +0 -2
  49. package/build/plugins/metadata.js.map +0 -1
  50. package/diva.iml +0 -11
  51. package/index.html +0 -28
  52. package/karma.conf.js +0 -87
  53. package/source/css/_mixins.scss +0 -43
  54. package/source/css/_variables.scss +0 -50
  55. package/source/css/_viewer.scss +0 -462
  56. package/source/css/diva.scss +0 -15
  57. package/source/css/plugins/_manipulation.scss +0 -228
  58. package/source/css/plugins/_metadata.scss +0 -31
  59. package/source/img/adjust.svg +0 -11
  60. package/source/img/book-view.svg +0 -6
  61. package/source/img/close.svg +0 -6
  62. package/source/img/download.svg +0 -6
  63. package/source/img/from-fullscreen.svg +0 -8
  64. package/source/img/grid-fewer.svg +0 -6
  65. package/source/img/grid-more.svg +0 -6
  66. package/source/img/grid-view.svg +0 -6
  67. package/source/img/link.svg +0 -6
  68. package/source/img/metadata.svg +0 -9
  69. package/source/img/page-view.svg +0 -6
  70. package/source/img/to-fullscreen.svg +0 -11
  71. package/source/img/zoom-in.svg +0 -6
  72. package/source/img/zoom-out.svg +0 -7
  73. package/source/js/composite-image.js +0 -174
  74. package/source/js/diva-global.js +0 -7
  75. package/source/js/diva.js +0 -1543
  76. package/source/js/document-handler.js +0 -180
  77. package/source/js/document-layout.js +0 -286
  78. package/source/js/exceptions.js +0 -26
  79. package/source/js/gesture-events.js +0 -190
  80. package/source/js/grid-handler.js +0 -122
  81. package/source/js/iiif-source-adapter.js +0 -63
  82. package/source/js/image-cache.js +0 -113
  83. package/source/js/image-manifest.js +0 -157
  84. package/source/js/image-request-handler.js +0 -76
  85. package/source/js/interpolate-animation.js +0 -122
  86. package/source/js/page-layouts/book-layout.js +0 -161
  87. package/source/js/page-layouts/grid-layout.js +0 -97
  88. package/source/js/page-layouts/index.js +0 -38
  89. package/source/js/page-layouts/page-dimensions.js +0 -9
  90. package/source/js/page-layouts/singles-layout.js +0 -27
  91. package/source/js/page-overlay-manager.js +0 -102
  92. package/source/js/page-tools-overlay.js +0 -95
  93. package/source/js/parse-iiif-manifest.js +0 -302
  94. package/source/js/plugins/_filters.js +0 -679
  95. package/source/js/plugins/download.js +0 -83
  96. package/source/js/plugins/manipulation.js +0 -837
  97. package/source/js/plugins/metadata.js +0 -190
  98. package/source/js/renderer.js +0 -584
  99. package/source/js/settings-view.js +0 -30
  100. package/source/js/tile-coverage-map.js +0 -25
  101. package/source/js/toolbar.js +0 -572
  102. package/source/js/utils/dragscroll.js +0 -106
  103. package/source/js/utils/elt.js +0 -94
  104. package/source/js/utils/events.js +0 -190
  105. package/source/js/utils/get-scrollbar-width.js +0 -29
  106. package/source/js/utils/hash-params.js +0 -86
  107. package/source/js/utils/parse-label-value.js +0 -34
  108. package/source/js/utils/vanilla.kinetic.js +0 -527
  109. package/source/js/validation-runner.js +0 -177
  110. package/source/js/viewer-core.js +0 -1505
  111. package/source/js/viewport.js +0 -143
  112. package/test/_setup.js +0 -13
  113. package/test/composite-image_test.js +0 -94
  114. package/test/diva_test.js +0 -43
  115. package/test/hash-params_test.js +0 -221
  116. package/test/image-cache_test.js +0 -106
  117. package/test/main.js +0 -6
  118. package/test/manifests/beromunsterManifest.json +0 -15514
  119. package/test/manifests/iiifv2.json +0 -11032
  120. package/test/manifests/iiifv2pages.json +0 -30437
  121. package/test/manifests/iiifv3.json +0 -10965
  122. package/test/navigation_test.js +0 -355
  123. package/test/parse-iiif-manifest_test.js +0 -68
  124. package/test/public_test.js +0 -881
  125. package/test/settings_test.js +0 -487
  126. package/test/utils/book-layout_test.js +0 -148
  127. package/test/utils/elt_test.js +0 -102
  128. package/test/utils/events_test.js +0 -245
  129. package/test/utils/hash-params_test.js +0 -79
  130. package/test/utils/parse-label-value_test.js +0 -45
  131. package/test/z_plugins_test.js +0 -180
  132. package/webpack.config.js +0 -58
  133. package/webpack.config.test.js +0 -45
@@ -1,143 +0,0 @@
1
- export default class Viewport
2
- {
3
- constructor (outer, options)
4
- {
5
- options = options || {};
6
-
7
- this.intersectionTolerance = options.intersectionTolerance || 0;
8
- this.outer = outer;
9
- this._top = this._left = this._width = this._height = this._innerDimensions = null;
10
-
11
- this.invalidate();
12
- }
13
-
14
- intersectsRegion (region)
15
- {
16
- return this.hasHorizontalOverlap(region) && this.hasVerticalOverlap(region);
17
- }
18
-
19
- hasVerticalOverlap (region)
20
- {
21
- const top = this.top - this.intersectionTolerance;
22
- const bottom = this.bottom + this.intersectionTolerance;
23
-
24
- return (
25
- fallsBetween(region.top, top, bottom) ||
26
- fallsBetween(region.bottom, top, bottom) ||
27
- (region.top <= top && region.bottom >= bottom)
28
- );
29
- }
30
-
31
- hasHorizontalOverlap (region)
32
- {
33
- const left = this.left - this.intersectionTolerance;
34
- const right = this.right + this.intersectionTolerance;
35
-
36
- return (
37
- fallsBetween(region.left, left, right) ||
38
- fallsBetween(region.right, left, right) ||
39
- (region.left <= left && region.right >= right)
40
- );
41
- }
42
-
43
- invalidate ()
44
- {
45
- // FIXME: Should this check the inner dimensions as well?
46
- this._width = this.outer.clientWidth;
47
- this._height = this.outer.clientHeight;
48
-
49
- this._top = this.outer.scrollTop;
50
- this._left = this.outer.scrollLeft;
51
- }
52
-
53
- setInnerDimensions (dimensions)
54
- {
55
- this._innerDimensions = dimensions;
56
-
57
- if (dimensions)
58
- {
59
- this._top = clamp(this._top, 0, dimensions.height - this._height);
60
- this._left = clamp(this._left, 0, dimensions.width - this._width);
61
- }
62
- }
63
- }
64
-
65
- Object.defineProperties(Viewport.prototype, {
66
- top: getCoordinateDescriptor('top', 'height'),
67
- left: getCoordinateDescriptor('left', 'width'),
68
-
69
- width: getDimensionDescriptor('width'),
70
- height: getDimensionDescriptor('height'),
71
-
72
- bottom: {
73
- get: function ()
74
- {
75
- return this._top + this._height;
76
- }
77
- },
78
- right: {
79
- get: function ()
80
- {
81
- return this._left + this._width;
82
- }
83
- }
84
- });
85
-
86
- function getCoordinateDescriptor (coord, associatedDimension)
87
- {
88
- const privateProp = '_' + coord;
89
- const source = 'scroll' + coord.charAt(0).toUpperCase() + coord.slice(1);
90
-
91
- return {
92
- get: function ()
93
- {
94
- return this[privateProp];
95
- },
96
- set: function (newValue)
97
- {
98
- let normalized;
99
-
100
- if (this._innerDimensions)
101
- {
102
- const maxAllowed = this._innerDimensions[associatedDimension] - this[associatedDimension];
103
- normalized = clamp(newValue, 0, maxAllowed);
104
- }
105
- else
106
- {
107
- normalized = clampMin(newValue, 0);
108
- }
109
-
110
- this[privateProp] = this.outer[source] = normalized;
111
- }
112
- };
113
- }
114
-
115
- function getDimensionDescriptor (dimen)
116
- {
117
- return {
118
- get: function ()
119
- {
120
- return this['_' + dimen];
121
- }
122
- };
123
- }
124
-
125
- function fallsBetween (point, start, end)
126
- {
127
- return point >= start && point <= end;
128
- }
129
-
130
- function clamp (value, min, max)
131
- {
132
- return clampMin(clampMax(value, max), min);
133
- }
134
-
135
- function clampMin (value, min)
136
- {
137
- return Math.max(value, min);
138
- }
139
-
140
- function clampMax (value, max)
141
- {
142
- return Math.min(value, max);
143
- }
package/test/_setup.js DELETED
@@ -1,13 +0,0 @@
1
- let expect = require('chai').expect;
2
- global.expect = expect;
3
-
4
- let assert = require('chai').assert;
5
- global.assert = assert;
6
-
7
- let wrapper = document.createElement('div');
8
- wrapper.id = 'parent-wrapper';
9
- wrapper.setAttribute('style', 'width: 984px; height: 800px');
10
- let div = document.createElement('div');
11
- div.id = 'diva-wrapper';
12
- wrapper.appendChild(div);
13
- document.body.appendChild(wrapper);
@@ -1,94 +0,0 @@
1
- import CompositeImage from '../source/js/composite-image';
2
-
3
- describe('Composite Image', function ()
4
- {
5
- it('getTiles(zoomLevel) works properly', function ()
6
- {
7
- let tileLevels = [
8
- dummyTileLevel({ zoomLevel: 2, baseRows: 1, baseCols: 1 }),
9
- dummyTileLevel({ zoomLevel: 1, baseRows: 1, baseCols: 1 }),
10
- dummyTileLevel({ zoomLevel: 0, baseRows: 1, baseCols: 1 })
11
- ];
12
-
13
- let composite = new CompositeImage(tileLevels);
14
-
15
- // Load the really low-res tile
16
- composite.updateWithLoadedUrls(getUrls(tileLevels[2].tiles));
17
-
18
- assert.deepEqual(composite.getTiles(2), tileLevels[2].tiles, 'Should load available images');
19
-
20
- let mostOfLevel1 = tileLevels[1].tiles.slice(1);
21
- composite.updateWithLoadedUrls(getUrls(mostOfLevel1));
22
-
23
- assert.deepEqual(composite.getTiles(2), [tileLevels[2].tiles[0]].concat(mostOfLevel1),
24
- 'Should load lower-res tiles if not completely covered (with low-res first)');
25
-
26
- assert.deepEqual(composite.getTiles(0), tileLevels[2].tiles,
27
- 'Should prefer tiles at the specified zoomLevel, then higher levels, then lower');
28
-
29
- composite.clear();
30
- composite.updateWithLoadedUrls(getUrls(tileLevels[2].tiles));
31
- let mostOfLevel0 = tileLevels[0].tiles.slice(1);
32
- composite.updateWithLoadedUrls(getUrls(mostOfLevel0));
33
-
34
- assert.deepEqual(composite.getTiles(2), [tileLevels[2].tiles[0]].concat(mostOfLevel0),
35
- 'Should load lower-res tiles across multiple zoom levels if not completely covered');
36
- });
37
- });
38
-
39
- function dummyTileLevel(options)
40
- {
41
- let zoomLevel = options.zoomLevel,
42
- baseRows = options.baseRows,
43
- baseCols = options.baseCols;
44
-
45
- let tiles = [];
46
- let scaleRatio = Math.pow(2, zoomLevel);
47
-
48
- for (let baseRow=0; baseRow < baseRows; baseRow++) {
49
- for (let baseCol=0; baseCol < baseCols; baseCol++) {
50
- tiles.push.apply(tiles, dummyTiles(scaleRatio, baseRow, baseCol));
51
- }
52
- }
53
-
54
- return {
55
- zoomLevel: zoomLevel,
56
- rows: baseRows * scaleRatio,
57
- cols: baseCols * scaleRatio,
58
- tiles: tiles
59
- };
60
- }
61
-
62
- function dummyTiles(scaleRatio, baseRow, baseCol)
63
- {
64
- let tiles = [];
65
-
66
- for (let rowOffset=0; rowOffset < scaleRatio; rowOffset++)
67
- {
68
- for (let colOffset=0; colOffset < scaleRatio; colOffset++)
69
- {
70
- let row = baseRow * scaleRatio + rowOffset;
71
- let col = baseCol * scaleRatio + colOffset;
72
-
73
- let url = 'dummy://ratio/' + scaleRatio + '/' +
74
- baseRow + '[' + rowOffset + ']/' +
75
- baseCol + '[' + colOffset + ']';
76
-
77
- // FIXME: More fields
78
- tiles.push({
79
- url: url,
80
- row: row,
81
- col: col
82
- });
83
- }
84
- }
85
-
86
- return tiles;
87
- }
88
-
89
- function getUrls(tiles) {
90
- return tiles.map(function (tile)
91
- {
92
- return tile.url;
93
- });
94
- }
package/test/diva_test.js DELETED
@@ -1,43 +0,0 @@
1
- import Diva from "../source/js/diva";
2
- import {
3
- DivaParentElementNotFoundException,
4
- ObjectDataNotSuppliedException
5
- } from "../source/js/exceptions";
6
-
7
- describe('Viewer', function ()
8
- {
9
- it('should throw an exception if the parent is not found', function ()
10
- {
11
- let fcn = () => { new Diva('blah', {}); };
12
- expect(fcn).to.throw(DivaParentElementNotFoundException);
13
- });
14
-
15
- it('should not throw an exception if the parent div is found', () =>
16
- {
17
- let fcn = () => { new Diva('diva-wrapper', {}); };
18
- expect(fcn).to.not.throw(DivaParentElementNotFoundException);
19
- });
20
-
21
- it('should allow an element object to be passed in as a parent', () =>
22
- {
23
- let parent = document.createElement('div');
24
- let fcn = () => { new Diva(parent, {}); };
25
- expect(fcn).to.not.throw(DivaParentElementNotFoundException);
26
- });
27
-
28
- it('should throw an exception if objectData is not supplied', () =>
29
- {
30
- let parent = document.createElement('div');
31
- let fcn = () => { new Diva(parent, {}); };
32
- expect(fcn).to.throw(ObjectDataNotSuppliedException);
33
- });
34
-
35
- it('should not throw an exception if objectData is supplied', () =>
36
- {
37
- let parent = document.createElement('div');
38
- let fcn = () => { new Diva(parent, {
39
- objectData: 'https://example.com/iiif/manifest.json'
40
- }); };
41
- expect(fcn).to.not.throw(ObjectDataNotSuppliedException);
42
- });
43
- });
@@ -1,221 +0,0 @@
1
- import Diva from '../source/js/diva';
2
-
3
- // jQuery mimic
4
- let el = document.getElementById.bind(document);
5
-
6
- describe('Hash Params', function ()
7
- {
8
- beforeEach(function ()
9
- {
10
- // reset event subscription so only current test is subscribed
11
- Diva.Events.unsubscribeAll();
12
-
13
- // recreate diva instance
14
- let oldWrapper = document.getElementById('parent-wrapper');
15
- oldWrapper.parentNode.removeChild(oldWrapper);
16
- let newWrapper = document.createElement('div');
17
- newWrapper.id = 'parent-wrapper';
18
- newWrapper.setAttribute('style', 'width: 984px;');
19
- let div = document.createElement('div');
20
- div.id = 'diva-wrapper';
21
- newWrapper.appendChild(div);
22
- document.body.appendChild(newWrapper);
23
- });
24
-
25
- let testHashParams = function (testName, hashParams, onReadyCallback, config)
26
- {
27
- it(testName, function (done)
28
- {
29
- window.location.hash = Object.keys(hashParams).map(function (param)
30
- {
31
- return param + '=' + hashParams[param];
32
- }).join('&');
33
-
34
- let diva = new Diva('diva-wrapper', { // jshint ignore:line
35
- objectData: 'https://images.simssa.ca/iiif/manuscripts/cdn-hsmu-m2149l4/manifest.json',
36
- hashParamSuffix: config && config.hashParamSuffix ? config.hashParamSuffix : '',
37
- enableFilename: config && config.enableFilename ? config.enableFilename : ''
38
- });
39
-
40
- Diva.Events.subscribe('ViewerDidLoad', function (settings)
41
- {
42
- let scroll = {
43
- left: settings.viewportElement.scrollLeft,
44
- top: settings.viewportElement.scrollTop
45
- };
46
-
47
- onReadyCallback.call(this, settings, scroll);
48
- done();
49
- });
50
- });
51
- };
52
-
53
- testHashParams('works with hashParamSuffix', {vxyz: 'g', f: 'true'}, function (settings)
54
- {
55
- assert.isOk(settings.inGrid, 'Should read properties with the specified suffix');
56
- assert.isOk(!settings.inFullscreen, 'Should not read properties without it');
57
- }, {hashParamSuffix: 'xyz'});
58
-
59
- testHashParams("grid view (v)", {v: "g"}, function (settings)
60
- {
61
- assert.isOk(settings.inGrid, "inGrid setting should be true");
62
- assert.strictEqual(el(settings.selector + 'view-menu').children[0].classList[0], 'diva-grid-icon', "Current toolbar view icon should be the grid icon");
63
- });
64
-
65
- testHashParams("book view (v)", {v: "b"}, function (settings)
66
- {
67
- assert.isOk(settings.inBookLayout, "inBookLayout setting should be true");
68
- assert.strictEqual(el(settings.selector + 'view-menu').children[0].classList[0], 'diva-book-icon', "Current toolbar view icon should be the book icon");
69
- assert.isOk(this.isPageInViewport(0), 'There should be some book pages');
70
- });
71
-
72
- testHashParams("invalid view parameter (v) ", {v: "a"}, function (settings)
73
- {
74
- assert.isFalse(settings.inBookLayout, 'Should not be in book layout');
75
- assert.isFalse(settings.inGrid, 'Should also not be in grid layout');
76
- });
77
-
78
- testHashParams("fullscreen (f)", {f: "true"}, function (settings)
79
- {
80
- assert.isOk(settings.inFullscreen, "inFullscreen setting should be true");
81
- assert.isOk(document.body.classList.contains('diva-hide-scrollbar'), "The body element should have the hide-scrollbar class");
82
- });
83
-
84
- testHashParams("view (v) = 'g' and fullscreen (f)", {v: "g", f: "true"}, function (settings)
85
- {
86
- assert.isOk(settings.inFullscreen, "inFullscreen setting should be true");
87
- assert.isOk(settings.inGrid, "inGrid setting should be true");
88
- });
89
-
90
- testHashParams("zoom level (z) - valid value", {z: "3", f: "false"}, function (settings)
91
- {
92
- assert.strictEqual(settings.zoomLevel, 3, "Initial zoom level should be 3");
93
- });
94
-
95
- testHashParams("zoom level (z) - invalid value", {z: "6"}, function (settings)
96
- {
97
- assert.strictEqual(settings.zoomLevel, 0, "Initial zoom was invalid but >= 0, should be set to the min (0)");
98
- });
99
-
100
- testHashParams("zoom level (z) and view (v) = 'g' ", {z: "1", v: "g"}, function (settings)
101
- {
102
- assert.strictEqual(settings.zoomLevel, 1, "Initial zoom level should be 1");
103
- assert.isOk(settings.inGrid, "Should be in grid initially");
104
-
105
- // Now let's switch into document view and see if the zoom level is preserved
106
- document.getElementsByClassName('diva-document-icon')[0].click();
107
- assert.strictEqual(settings.zoomLevel, 1, "Zoom level setting should still be 1");
108
- // zoom level is 0 indexed internally, so setting to 1 should display 2.00
109
- assert.strictEqual(el(settings.selector + 'zoom-label').textContent, "Zoom level: 2", "Zoom buttons label should show a zoom level of 2");
110
- });
111
-
112
- testHashParams("zoom level (z) and fullscreen (f)", {z: "1", f: "true"}, function (settings)
113
- {
114
- assert.strictEqual(settings.zoomLevel, 1, "Initial zoom level should be 1");
115
- assert.isOk(settings.inFullscreen, "Should be in fullscreen initially");
116
-
117
- // Check that we're actually in fullscreen mode
118
- assert.isOk(document.body.classList.contains('diva-hide-scrollbar'), "The body element should have the hide-scrollbar class");
119
-
120
- // Check that the zoom level is actually 1 (second zoom)
121
- assert.strictEqual(el(settings.selector + 'zoom-label').textContent, "Zoom level: 2", "Zoom buttons label should show a zoom level of 2");
122
- });
123
-
124
- testHashParams("pagesPerRow (n) - valid value", {n: "3"}, function (settings)
125
- {
126
- assert.strictEqual(settings.pagesPerRow, 3, "Pages per row should be 3 initially");
127
- });
128
-
129
- testHashParams("pagesPerRow (n) - invalid value", {n: "1"}, function (settings)
130
- {
131
- assert.strictEqual(settings.pagesPerRow, 8, "Pages per row should default to the maximum");
132
- });
133
-
134
- testHashParams("pagesPerRow (n) and view (v) = 'g'", {n: "3", v: "g"}, function (settings)
135
- {
136
- assert.strictEqual(settings.pagesPerRow, 3, "Pages per row should be 3 initially");
137
- assert.isOk(settings.inGrid, "Should be in grid initially");
138
-
139
- // Check that the pages per row setting is actually 3
140
- assert.strictEqual(el(settings.selector + 'grid-label').textContent, "Pages per row: 3", "Grid buttons label should show 3 pages per row");
141
- });
142
-
143
- testHashParams("page filename (i) - valid value", {i: "https://images.simssa.ca/iiif/image/cdn-hsmu-m2149l4/cdn-hsmu-m2149l4_003r.jp2"}, function (settings)
144
- {
145
- assert.strictEqual(settings.activePageIndex, 4, "The initial page should be page 5 (index of 4)");
146
- }, {enableFilename: true});
147
-
148
- testHashParams("page filename (i) - invalid value", {i: "https://images.simssa.ca/iiif/image/cdn-hsmu-m2149l4/cdn-hsmu-m2149l4_000r.jp2"}, function (settings)
149
- {
150
- assert.strictEqual(settings.activePageIndex, 0, "The initial page should just be the first page");
151
- }, {enableFilename: true});
152
-
153
- testHashParams("page number (p) - valid value", {p: "6"}, function (settings)
154
- {
155
- assert.strictEqual(settings.activePageIndex, 5, "The initial page should be page 6 (index of 5)");
156
- }, {enableFilename: false});
157
-
158
- testHashParams("page number (p) - invalid value", {p: "600"}, function (settings)
159
- {
160
- assert.strictEqual(settings.activePageIndex, 0, "The initial page should just be the first page");
161
- }, {enableFilename: false});
162
-
163
- testHashParams("page number (p), view = 'g'", {p: "100", v: "g"}, function (settings)
164
- {
165
- assert.strictEqual(settings.activePageIndex, 99, "The initial page should be 100 (index of 99)");
166
- assert.ok(settings.inGrid, "Should be in grid");
167
- }, {enableFilename: false});
168
-
169
- testHashParams("horizontal and vertical offsets (x, y) without page specified", {x: 100, y: 200}, function (settings, scroll)
170
- {
171
- assert.strictEqual(scroll.top, 0, 'y position should not change');
172
- });
173
-
174
- testHashParams("vertical offset (y) on first page - positive value", {y: "600", p: "1"}, function (settings, scroll)
175
- {
176
- assert.strictEqual(scroll.top, 353, "Should have scrolled 353 (600 = top of page - viewport y-center) vertically");
177
- });
178
-
179
- testHashParams("vertical offset (y) on first page - negative value", {y: "-600", p: "1"}, function (settings, scroll)
180
- {
181
- assert.strictEqual(scroll.top, 0, "Should not have scrolled negatively because, well, you can't");
182
- });
183
- testHashParams("vertical offset (y) and page number (p)", {y: 500, p: "50"}, function (settings, scroll)
184
- {
185
- let expectedTopScroll = 44994;
186
- assert.strictEqual(settings.activePageIndex, 49, "Current page should be 50 (index of 49)");
187
- assert.strictEqual(scroll.top, expectedTopScroll, "Should be heightAbovePages + 500 pixels of scroll from the top + page y-center");
188
-
189
- // Check that the horizontal scroll hasn't been weirdly affected
190
- let expectedLeftScroll = 0; // no scrollbar at this zoom level
191
- assert.strictEqual(scroll.left, expectedLeftScroll, "Horizontal scroll should just center it");
192
- }, {enableFilename: false, zoomLevel: 2});
193
-
194
- testHashParams("horizontal offset (x) on first page - positive value", {x: "100", p: "1"}, function (settings, scroll)
195
- {
196
- // FIXME: https://github.com/DDMAL/diva.js/issues/331
197
- assert.strictEqual(scroll.left, 0, "Horizontal scroll should center it + 100 pixels to the right");
198
- });
199
-
200
- testHashParams("horizontal offset (x) on first page - negative value", {x: "-100", p: "1"}, function (settings, scroll)
201
- {
202
- // FIXME: https://github.com/DDMAL/diva.js/issues/331
203
- assert.strictEqual(scroll.left, 0, "Horizontal scroll should center it + 100 pixels to the left");
204
- });
205
-
206
- testHashParams("horizontal offset (x) and page number (p)", {x: 100, p: "50"}, function (settings, scroll)
207
- {
208
- // FIXME: https://github.com/DDMAL/diva.js/issues/331
209
- let expectedTopScroll = 44741;
210
- assert.strictEqual(scroll.top, expectedTopScroll, "vertical scroll should be just to page 50");
211
- assert.strictEqual(scroll.left, 0, "Horizontal scroll should center it + 100 pixels to the right");
212
- }, {enableFilename: false});
213
-
214
- testHashParams("horizontal offset (x), vertical offset (y), page number (p)", {x: 100, y: 200, p: "50"}, function (settings, scroll)
215
- {
216
- // FIXME: https://github.com/DDMAL/diva.js/issues/331
217
- let expectedTopScroll = 44694;
218
- assert.strictEqual(scroll.top, expectedTopScroll, "vertical scroll should be to page 50 + 200 + page y-center");
219
- assert.strictEqual(scroll.left, 0, "Horizontal scroll should center it + 100 pixels to the right");
220
- }, {enableFilename: false});
221
- });
@@ -1,106 +0,0 @@
1
- 'use strict';
2
-
3
- import ImageCache from '../source/js/image-cache';
4
-
5
- describe('Image Cache', function ()
6
- {
7
- it('Default max entries is 100', function ()
8
- {
9
- let cache = new ImageCache();
10
- assert.strictEqual(cache.maxKeys, 100);
11
- });
12
-
13
- it('Evicts the least recently used entry', function ()
14
- {
15
- let cache = new ImageCache({ maxKeys: 2 });
16
-
17
- let imgA = new Image();
18
- let imgB = new Image();
19
- let imgC = new Image();
20
-
21
- cache.put('A', imgA);
22
- cache.put('B', imgB);
23
- cache.put('C', imgC);
24
-
25
- assert.strictEqual(cache.has('A'), false, 'A evicted [has]');
26
- assert.strictEqual(cache.has('B'), true, 'B remains [has]');
27
- assert.strictEqual(cache.has('C'), true, 'C remains [has]');
28
-
29
- assert.strictEqual(cache.get('A'), null, 'A evicted [get]');
30
- assert.strictEqual(cache.get('B'), imgB, 'B remains [get]');
31
- assert.strictEqual(cache.get('C'), imgC, 'C remains [get]');
32
-
33
- cache.put('A', imgA);
34
- assert.strictEqual(cache.has('A'), true, 'A restored [has v2]');
35
- assert.strictEqual(cache.has('B'), false, 'B evicted [has v2]');
36
- assert.strictEqual(cache.has('C'), true, 'C remains [has v2]');
37
- });
38
-
39
- it('Put overwrites existing entries and bumps their LRU position', function ()
40
- {
41
- let cache = new ImageCache({ maxKeys: 2 });
42
-
43
- let imgA = new Image();
44
- let imgA2 = new Image();
45
- let imgB = new Image();
46
- let imgC = new Image();
47
-
48
- cache.put('A', imgA);
49
- cache.put('B', imgB);
50
- cache.put('A', imgA2);
51
- cache.put('C', imgC);
52
-
53
- assert.strictEqual(cache.get('A'), imgA2, 'A overwritten, still in cache');
54
- assert.strictEqual(cache.get('B'), null, 'B evicted');
55
- assert.strictEqual(cache.get('C'), imgC, 'C still in cache');
56
- });
57
-
58
- it("Entries which have been acquire()'d are promoted", function ()
59
- {
60
- let cache = new ImageCache({ maxKeys: 2 });
61
-
62
- let imgA = new Image();
63
- let imgB = new Image();
64
- let imgC = new Image();
65
-
66
- cache.put('A', imgA);
67
- cache.put('B', imgB);
68
-
69
- cache.acquire('A');
70
- cache.release('A');
71
-
72
- cache.put('C', imgC); // A would be evicted here if not promoted
73
-
74
- assert.strictEqual(cache.has('A'), true, 'A remains');
75
- assert.strictEqual(cache.has('B'), false, 'B evicted');
76
- assert.strictEqual(cache.has('C'), true, 'C remains');
77
- });
78
-
79
- it("Entries which have been acquire()'d are not evicted until released", function ()
80
- {
81
- let cache = new ImageCache({ maxKeys: 2 });
82
-
83
- let imgA = new Image();
84
- let imgB = new Image();
85
- let imgC = new Image();
86
-
87
- cache.put('A', imgA);
88
- cache.acquire('A');
89
-
90
- cache.put('B', imgB);
91
- cache.acquire('B');
92
-
93
- cache.put('C', imgC); // A would be evicted here if not held
94
-
95
- assert.strictEqual(cache.has('A'), true, 'A remains');
96
- assert.strictEqual(cache.has('B'), true, 'B remains');
97
- assert.strictEqual(cache.has('C'), true, 'C still entered');
98
-
99
- cache.release('B'); // B will be evicted even though it still has priority over A
100
-
101
- assert.strictEqual(cache.has('A'), true, 'A still remains (held)');
102
- assert.strictEqual(cache.has('B'), false, 'B evicted');
103
- assert.strictEqual(cache.has('C'), true, 'C still remains (by LRU policy)');
104
- });
105
-
106
- });
package/test/main.js DELETED
@@ -1,6 +0,0 @@
1
-
2
- const srcContext = require.context('../source/js', true, /\.js$/);
3
- srcContext.keys().forEach(srcContext);
4
-
5
- const testsContext = require.context('.', true, /\.js$/);
6
- testsContext.keys().forEach(testsContext);