diva.js 6.0.2 → 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 (131) 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 -114
  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/build/diva.css +0 -554
  40. package/build/diva.css.map +0 -1
  41. package/build/diva.js +0 -9
  42. package/build/diva.js.map +0 -1
  43. package/build/plugins/download.js +0 -2
  44. package/build/plugins/download.js.map +0 -1
  45. package/build/plugins/manipulation.js +0 -2
  46. package/build/plugins/manipulation.js.map +0 -1
  47. package/build/plugins/metadata.js +0 -2
  48. package/build/plugins/metadata.js.map +0 -1
  49. package/index.html +0 -28
  50. package/karma.conf.js +0 -87
  51. package/source/css/_mixins.scss +0 -43
  52. package/source/css/_variables.scss +0 -50
  53. package/source/css/_viewer.scss +0 -462
  54. package/source/css/diva.scss +0 -15
  55. package/source/css/plugins/_manipulation.scss +0 -228
  56. package/source/css/plugins/_metadata.scss +0 -31
  57. package/source/img/adjust.svg +0 -11
  58. package/source/img/book-view.svg +0 -6
  59. package/source/img/close.svg +0 -6
  60. package/source/img/download.svg +0 -6
  61. package/source/img/from-fullscreen.svg +0 -8
  62. package/source/img/grid-fewer.svg +0 -6
  63. package/source/img/grid-more.svg +0 -6
  64. package/source/img/grid-view.svg +0 -6
  65. package/source/img/link.svg +0 -6
  66. package/source/img/metadata.svg +0 -9
  67. package/source/img/page-view.svg +0 -6
  68. package/source/img/to-fullscreen.svg +0 -11
  69. package/source/img/zoom-in.svg +0 -6
  70. package/source/img/zoom-out.svg +0 -7
  71. package/source/js/composite-image.js +0 -174
  72. package/source/js/diva-global.js +0 -7
  73. package/source/js/diva.js +0 -1543
  74. package/source/js/document-handler.js +0 -180
  75. package/source/js/document-layout.js +0 -286
  76. package/source/js/exceptions.js +0 -26
  77. package/source/js/gesture-events.js +0 -190
  78. package/source/js/grid-handler.js +0 -122
  79. package/source/js/iiif-source-adapter.js +0 -63
  80. package/source/js/image-cache.js +0 -113
  81. package/source/js/image-manifest.js +0 -157
  82. package/source/js/image-request-handler.js +0 -76
  83. package/source/js/interpolate-animation.js +0 -122
  84. package/source/js/page-layouts/book-layout.js +0 -161
  85. package/source/js/page-layouts/grid-layout.js +0 -97
  86. package/source/js/page-layouts/index.js +0 -38
  87. package/source/js/page-layouts/page-dimensions.js +0 -9
  88. package/source/js/page-layouts/singles-layout.js +0 -27
  89. package/source/js/page-overlay-manager.js +0 -102
  90. package/source/js/page-tools-overlay.js +0 -95
  91. package/source/js/parse-iiif-manifest.js +0 -302
  92. package/source/js/plugins/_filters.js +0 -679
  93. package/source/js/plugins/download.js +0 -83
  94. package/source/js/plugins/manipulation.js +0 -837
  95. package/source/js/plugins/metadata.js +0 -190
  96. package/source/js/renderer.js +0 -584
  97. package/source/js/settings-view.js +0 -30
  98. package/source/js/tile-coverage-map.js +0 -25
  99. package/source/js/toolbar.js +0 -573
  100. package/source/js/utils/dragscroll.js +0 -106
  101. package/source/js/utils/elt.js +0 -94
  102. package/source/js/utils/events.js +0 -190
  103. package/source/js/utils/get-scrollbar-width.js +0 -29
  104. package/source/js/utils/hash-params.js +0 -86
  105. package/source/js/utils/parse-label-value.js +0 -34
  106. package/source/js/utils/vanilla.kinetic.js +0 -527
  107. package/source/js/validation-runner.js +0 -177
  108. package/source/js/viewer-core.js +0 -1514
  109. package/source/js/viewport.js +0 -143
  110. package/test/_setup.js +0 -13
  111. package/test/composite-image_test.js +0 -94
  112. package/test/diva_test.js +0 -43
  113. package/test/hash-params_test.js +0 -221
  114. package/test/image-cache_test.js +0 -106
  115. package/test/main.js +0 -6
  116. package/test/manifests/beromunsterManifest.json +0 -15514
  117. package/test/manifests/iiifv2.json +0 -11032
  118. package/test/manifests/iiifv2pages.json +0 -30437
  119. package/test/manifests/iiifv3.json +0 -10965
  120. package/test/navigation_test.js +0 -355
  121. package/test/parse-iiif-manifest_test.js +0 -68
  122. package/test/public_test.js +0 -881
  123. package/test/settings_test.js +0 -487
  124. package/test/utils/book-layout_test.js +0 -148
  125. package/test/utils/elt_test.js +0 -102
  126. package/test/utils/events_test.js +0 -245
  127. package/test/utils/hash-params_test.js +0 -79
  128. package/test/utils/parse-label-value_test.js +0 -45
  129. package/test/z_plugins_test.js +0 -180
  130. package/webpack.config.js +0 -58
  131. package/webpack.config.test.js +0 -45
@@ -1,94 +0,0 @@
1
- export { setDOMAttributes as setAttributes };
2
-
3
- /**
4
- * Convenience function to create a DOM element, set attributes on it, and
5
- * append children. All arguments which are not of primitive type, are not
6
- * arrays, and are not DOM nodes are treated as attribute hashes and are
7
- * handled as described for setDOMAttributes. Children can either be a DOM
8
- * node or a primitive value, which is converted to a text node. Arrays are
9
- * handled recursively. Null and undefined values are ignored.
10
- *
11
- * Inspired by the ProseMirror helper of the same name.
12
- */
13
- export function elt (tag)
14
- {
15
- const el = document.createElement(tag);
16
- const args = Array.prototype.slice.call(arguments, 1);
17
-
18
- while (args.length)
19
- {
20
- const arg = args.shift();
21
- handleEltConstructorArg(el, arg);
22
- }
23
-
24
- return el;
25
- }
26
-
27
- function handleEltConstructorArg (el, arg)
28
- {
29
- if (arg == null) // NB: == is correct;
30
- return;
31
-
32
- if (typeof arg !== 'object' && typeof arg !== 'function')
33
- {
34
- // Coerce to string
35
- el.appendChild(document.createTextNode(arg));
36
- }
37
- else if (arg instanceof window.Node)
38
- {
39
- el.appendChild(arg);
40
- }
41
- else if (arg instanceof Array)
42
- {
43
- const childCount = arg.length;
44
- for (let i = 0; i < childCount; i++)
45
- handleEltConstructorArg(el, arg[i]);
46
- }
47
- else
48
- {
49
- setDOMAttributes(el, arg);
50
- }
51
- }
52
-
53
- /**
54
- * Set attributes of a DOM element. The `style` property is special-cased to
55
- * accept either a string or an object whose own attributes are assigned to
56
- * el.style.
57
- */
58
- function setDOMAttributes (el, attributes)
59
- {
60
- for (const prop in attributes)
61
- {
62
- if (!attributes.hasOwnProperty(prop))
63
- continue;
64
-
65
- if (prop === 'style')
66
- {
67
- setStyle(el, attributes.style);
68
- }
69
- else
70
- {
71
- el.setAttribute(prop, attributes[prop]);
72
- }
73
- }
74
- }
75
-
76
- function setStyle (el, style)
77
- {
78
- if (!style)
79
- return;
80
-
81
- if (typeof style !== 'object')
82
- {
83
- el.style.cssText = style;
84
- return;
85
- }
86
-
87
- for (const cssProp in style)
88
- {
89
- if (!style.hasOwnProperty(cssProp))
90
- continue;
91
-
92
- el.style[cssProp] = style[cssProp];
93
- }
94
- }
@@ -1,190 +0,0 @@
1
- /**
2
- * Events. Pub/Sub system for Loosely Coupled logic.
3
- * Based on Peter Higgins' port from Dojo to jQuery
4
- * https://github.com/phiggins42/bloody-jquery-plugins/blob/master/pubsub.js
5
- *
6
- * Re-adapted to vanilla Javascript
7
- *
8
- * @class Events
9
- */
10
-
11
- class DivaEvents
12
- {
13
- constructor()
14
- {
15
- this._cache = {};
16
- }
17
-
18
- /**
19
- * diva.Events.publish
20
- * e.g.: diva.Events.publish("PageDidLoad", [pageIndex, filename, pageSelector], this);
21
- *
22
- * @class Events
23
- * @method publish
24
- * @param topic {String}
25
- * @param args {Array}
26
- * @param scope {Object=} Optional - Subscribed functions will be executed with the supplied object as `this`.
27
- * It is necessary to supply this argument with the self variable when within a Diva instance.
28
- * The scope argument is matched with the instance ID of subscribers to determine whether they
29
- * should be executed. (See instanceID argument of subscribe.)
30
- */
31
- publish(topic, args, scope)
32
- {
33
- if (this._cache[topic])
34
- {
35
- const thisTopic = this._cache[topic];
36
-
37
- if (typeof thisTopic.global !== 'undefined')
38
- {
39
- const thisTopicGlobal = thisTopic.global;
40
- const globalCount = thisTopicGlobal.length;
41
-
42
- for (let i=0; i < globalCount; i++)
43
- {
44
- thisTopicGlobal[i].apply(scope || null, args || []);
45
- }
46
- }
47
-
48
- if (scope && typeof scope.getInstanceId !== 'undefined')
49
- {
50
- // get publisher instance ID from scope arg, compare, and execute if match
51
- const instanceID = scope.getInstanceId();
52
-
53
- if (this._cache[topic][instanceID])
54
- {
55
- const thisTopicInstance = this._cache[topic][instanceID];
56
- const scopedCount = thisTopicInstance.length;
57
-
58
- for (let j=0; j < scopedCount; j++)
59
- {
60
- thisTopicInstance[j].apply(scope, args || []);
61
- }
62
- }
63
- }
64
- }
65
- }
66
-
67
- /**
68
- * diva.Events.subscribe
69
- * e.g.: diva.Events.subscribe("PageDidLoad", highlight, settings.ID)
70
- *
71
- * @class Events
72
- * @method subscribe
73
- * @param {string} topic
74
- * @param {function} callback
75
- * @param {string=} instanceID Optional - String representing the ID of a Diva instance; if provided,
76
- * callback only fires for events published from that instance.
77
- * @return Event handler {Array}
78
- */
79
- subscribe(topic, callback, instanceID)
80
- {
81
- if (!this._cache[topic])
82
- {
83
- this._cache[topic] = {};
84
- }
85
-
86
- if (typeof instanceID === 'string')
87
- {
88
- if (!this._cache[topic][instanceID])
89
- {
90
- this._cache[topic][instanceID] = [];
91
- }
92
-
93
- this._cache[topic][instanceID].push(callback);
94
- }
95
- else
96
- {
97
- if (!this._cache[topic].global)
98
- {
99
- this._cache[topic].global = [];
100
- }
101
-
102
- this._cache[topic].global.push(callback);
103
- }
104
-
105
- return instanceID ? [topic, callback, instanceID] : [topic, callback];
106
- }
107
-
108
- /**
109
- * diva.Events.unsubscribe
110
- * e.g.: var handle = Events.subscribe("PageDidLoad", highlight);
111
- * Events.unsubscribe(handle);
112
- *
113
- * @class Events
114
- * @method unsubscribe
115
- * @param {array} handle
116
- * @param {boolean=} completely - Unsubscribe all events for a given topic.
117
- * @return {boolean} success
118
- */
119
- unsubscribe(handle, completely)
120
- {
121
- const t = handle[0];
122
-
123
- if (this._cache[t])
124
- {
125
- let topicArray;
126
- const instanceID = handle.length === 3 ? handle[2] : 'global';
127
-
128
- topicArray = this._cache[t][instanceID];
129
-
130
- if (!topicArray)
131
- {
132
- return false;
133
- }
134
-
135
- if (completely)
136
- {
137
- delete this._cache[t][instanceID];
138
- return topicArray.length > 0;
139
- }
140
-
141
- let i = topicArray.length;
142
-
143
- while (i--)
144
- {
145
- if (topicArray[i] === handle[1])
146
- {
147
- this._cache[t][instanceID].splice(i, 1);
148
- return true;
149
- }
150
- }
151
- }
152
-
153
- return false;
154
- }
155
-
156
- /**
157
- * diva.Events.unsubscribeAll
158
- * e.g.: diva.Events.unsubscribeAll('global');
159
- *
160
- * @class Events
161
- * @param {string=} instanceID Optional - instance ID to remove subscribers from or 'global' (if omitted,
162
- * subscribers in all scopes removed)
163
- * @method unsubscribeAll
164
- */
165
- unsubscribeAll(instanceID)
166
- {
167
- if (instanceID)
168
- {
169
- const topics = Object.keys(this._cache);
170
- let i = topics.length;
171
- let topic;
172
-
173
- while (i--)
174
- {
175
- topic = topics[i];
176
-
177
- if (typeof this._cache[topic][instanceID] !== 'undefined')
178
- {
179
- delete this._cache[topic][instanceID];
180
- }
181
- }
182
- }
183
- else
184
- {
185
- this._cache = {};
186
- }
187
- }
188
- }
189
-
190
- export let Events = new DivaEvents();
@@ -1,29 +0,0 @@
1
- // From http://www.alexandre-gomes.com/?p=115, modified slightly
2
- export default function getScrollbarWidth()
3
- {
4
- let inner = document.createElement('p');
5
- inner.style.width = '100%';
6
- inner.style.height = '200px';
7
-
8
- let outer = document.createElement('div');
9
- outer.style.position = 'absolute';
10
- outer.style.top = '0px';
11
- outer.style.left = '0px';
12
- outer.style.visibility = 'hidden';
13
- outer.style.width = '200px';
14
- outer.style.height = '150px';
15
- outer.style.overflow = 'hidden';
16
- outer.appendChild(inner);
17
-
18
- document.body.appendChild(outer);
19
-
20
- let w1 = inner.offsetWidth;
21
- outer.style.overflow = 'scroll';
22
- let w2 = inner.offsetWidth;
23
- if (w1 === w2) {
24
- w2 = outer.clientWidth; // for IE i think
25
- }
26
-
27
- document.body.removeChild(outer);
28
- return w1 - w2;
29
- }
@@ -1,86 +0,0 @@
1
- let HashParams = {
2
- get: getHashParam,
3
- update: updateHashParam
4
- };
5
-
6
- export default HashParams;
7
-
8
-
9
- // For getting the #key values from the URL. For specifying a page and zoom level
10
- // Look into caching, because we only need to get this during the initial load
11
- // Although for the tests I guess we would need to override caching somehow
12
- function getHashParam (key)
13
- {
14
- const hash = window.location.hash;
15
-
16
- if (hash !== '')
17
- {
18
- // Check if there is something that looks like either &key= or #key=
19
- let startIndex = (hash.indexOf('&' + key + '=') > 0) ? hash.indexOf('&' + key + '=') : hash.indexOf('#' + key + '=');
20
-
21
- // If startIndex is still -1, it means it can't find either
22
- if (startIndex >= 0)
23
- {
24
- // Add the length of the key plus the & and =
25
- startIndex += key.length + 2;
26
-
27
- // Either to the next ampersand or to the end of the string
28
- const endIndex = hash.indexOf('&', startIndex);
29
- if (endIndex > startIndex)
30
- {
31
- return decodeURIComponent(hash.substring(startIndex, endIndex));
32
- }
33
- else if (endIndex < 0)
34
- {
35
- // This means this hash param is the last one
36
- return decodeURIComponent(hash.substring(startIndex));
37
- }
38
- // If the key doesn't have a value I think
39
- return '';
40
- }
41
- else
42
- {
43
- // If it can't find the key
44
- return false;
45
- }
46
- }
47
- else
48
- {
49
- // If there are no hash params just return false
50
- return false;
51
- }
52
- }
53
-
54
- function updateHashParam (key, value)
55
- {
56
- // First make sure that we have to do any work at all
57
- const originalValue = getHashParam(key);
58
- const hash = window.location.hash;
59
-
60
- if (originalValue !== value)
61
- {
62
- // Is the key already in the URL?
63
- if (typeof originalValue === 'string')
64
- {
65
- // Already in the URL. Just get rid of the original value
66
- const startIndex = (hash.indexOf('&' + key + '=') > 0) ? hash.indexOf('&' + key + '=') : hash.indexOf('#' + key + '=');
67
- const endIndex = startIndex + key.length + 2 + originalValue.length;
68
- // # if it's the first, & otherwise
69
- const startThing = (startIndex === 0) ? '#' : '&';
70
- window.location.replace(hash.substring(0, startIndex) + startThing + key + '=' + value + hash.substring(endIndex));
71
- }
72
- else
73
- {
74
- // It's not present - add it
75
- if (hash.length === 0)
76
- {
77
- window.location.replace('#' + key + '=' + value);
78
- }
79
- else
80
- {
81
- // Append it
82
- window.location.replace(hash + '&' + key + '=' + value);
83
- }
84
- }
85
- }
86
- }
@@ -1,34 +0,0 @@
1
- /**
2
- * Parses a v3 manifest's label/value pair from an object & array to a string
3
- *
4
- * @public
5
- * @params {string} key - The key from which a label/value pair should be extracted.
6
- * @returns {object} - The label/value pair as strings.
7
- * */
8
-
9
- export default function parseLabelValue (key)
10
- {
11
- let l = key.label;
12
- let label = (typeof l === 'object') ? l[Object.keys(l)[0]][0] : l;
13
-
14
- let v = key.value;
15
- let value;
16
- if (Array.isArray(v))
17
- { // is array of objects
18
- value = v.map(e => e[Object.keys(e)[0]]);
19
- }
20
- else
21
- { // is object where value is possibly an array
22
- value = (typeof v === 'object') ? v[Object.keys(v)[0]] : v;
23
- }
24
-
25
- if (Array.isArray(value))
26
- {
27
- value = value.join(', ');
28
- }
29
-
30
- return {
31
- label: label,
32
- value: value
33
- };
34
- }