react-iiif-vault 0.9.10 → 0.9.13
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.
- package/.build/types/canvas-panel/Viewer.d.ts +13 -0
- package/.build/types/canvas-panel/index.d.ts +18 -0
- package/.build/types/canvas-panel/render/Annotation.d.ts +8 -0
- package/.build/types/canvas-panel/render/AnnotationPage.d.ts +6 -0
- package/.build/types/canvas-panel/render/Audio.d.ts +6 -0
- package/.build/types/canvas-panel/render/Canvas.d.ts +23 -0
- package/.build/types/canvas-panel/render/DefaultCanvasFallback.d.ts +5 -0
- package/.build/types/canvas-panel/render/Image.d.ts +13 -0
- package/.build/types/canvas-panel/render/Model.d.ts +3 -0
- package/.build/types/canvas-panel/render/Video.d.ts +6 -0
- package/.build/types/context/AnnotationContext.d.ts +5 -0
- package/.build/types/context/CanvasContext.d.ts +5 -0
- package/.build/types/context/CollectionContext.d.ts +5 -0
- package/.build/types/context/ContextBridge.d.ts +22 -0
- package/.build/types/context/ImageServiceLoaderContext.d.ts +4 -0
- package/.build/types/context/ManifestContext.d.ts +5 -0
- package/.build/types/context/MediaContext.d.ts +17 -0
- package/.build/types/context/PortalContext.d.ts +7 -0
- package/.build/types/context/RangeContext.d.ts +5 -0
- package/.build/types/context/ResourceContext.d.ts +14 -0
- package/.build/types/context/VaultContext.d.ts +14 -0
- package/.build/types/context/ViewerPresetContext.d.ts +3 -0
- package/.build/types/context/VisibleCanvasContext.d.ts +4 -0
- package/.build/types/demo/demo.d.ts +1 -0
- package/.build/types/demo/media-controls.d.ts +1 -0
- package/.build/types/demo/viewer-controls.d.ts +1 -0
- package/.build/types/features/rendering-strategy/3d-strategy.d.ts +13 -0
- package/.build/types/features/rendering-strategy/audio-strategy.d.ts +3 -0
- package/.build/types/features/rendering-strategy/choice-types.d.ts +15 -0
- package/.build/types/features/rendering-strategy/image-strategy.d.ts +13 -0
- package/.build/types/features/rendering-strategy/rendering-utils.d.ts +21 -0
- package/.build/types/features/rendering-strategy/resource-types.d.ts +42 -0
- package/.build/types/features/rendering-strategy/strategies.d.ts +22 -0
- package/.build/types/features/rendering-strategy/video-strategy.d.ts +3 -0
- package/.build/types/hooks/useAnnotation.d.ts +8 -0
- package/.build/types/hooks/useAnnotationPageManager.d.ts +10 -0
- package/.build/types/hooks/useAnnotationsAtTime.d.ts +4 -0
- package/.build/types/hooks/useCanvas.d.ts +8 -0
- package/.build/types/hooks/useCanvasClock.d.ts +1 -0
- package/.build/types/hooks/useCanvasSelector.d.ts +0 -0
- package/.build/types/hooks/useCanvasTimeline.d.ts +0 -0
- package/.build/types/hooks/useCollection.d.ts +8 -0
- package/.build/types/hooks/useDispatch.d.ts +2 -0
- package/.build/types/hooks/useEnabledAnnotationPageIds.d.ts +1 -0
- package/.build/types/hooks/useEventListener.d.ts +4 -0
- package/.build/types/hooks/useExistingVault.d.ts +1 -0
- package/.build/types/hooks/useExternalCollection.d.ts +13 -0
- package/.build/types/hooks/useExternalManifest.d.ts +13 -0
- package/.build/types/hooks/useExternalResource.d.ts +16 -0
- package/.build/types/hooks/useImageService.d.ts +9 -0
- package/.build/types/hooks/useImageTile.d.ts +11 -0
- package/.build/types/hooks/useLoadImageService.d.ts +6 -0
- package/.build/types/hooks/useManifest.d.ts +8 -0
- package/.build/types/hooks/usePaintables.d.ts +8 -0
- package/.build/types/hooks/usePaintingAnnotations.d.ts +4 -0
- package/.build/types/hooks/useRange.d.ts +8 -0
- package/.build/types/hooks/useRenderingStrategy.d.ts +14 -0
- package/.build/types/hooks/useResourceEvents.d.ts +3 -0
- package/.build/types/hooks/useResources.d.ts +1 -0
- package/.build/types/hooks/useSearchService.d.ts +2 -0
- package/.build/types/hooks/useSimpleMediaPlayer.d.ts +32 -0
- package/.build/types/hooks/useStyleHelper.d.ts +1 -0
- package/.build/types/hooks/useStyles.d.ts +3 -0
- package/.build/types/hooks/useThumbnail.d.ts +5 -0
- package/.build/types/hooks/useVault.d.ts +2 -0
- package/.build/types/hooks/useVaultEffect.d.ts +2 -0
- package/.build/types/hooks/useVaultSelector.d.ts +2 -0
- package/.build/types/hooks/useVirtualAnnotationPage.d.ts +13 -0
- package/.build/types/hooks/useVirtualAnnotationPageContext.d.ts +9 -0
- package/.build/types/hooks/useVirtualCanvas.d.ts +0 -0
- package/.build/types/index.d.ts +54 -0
- package/.build/types/utility/flatten-annotation-page-ids.d.ts +7 -0
- package/.build/types/viewers/SimpleViewerContext.d.ts +18 -0
- package/.build/types/viewers/SingleCanvasContext.d.ts +1 -0
- package/dist/bundle/cjs/index.js +36 -0
- package/dist/bundle/cjs/index.js.map +1 -0
- package/dist/{esm → bundle/esm}/index.mjs +740 -791
- package/dist/bundle/esm/index.mjs.map +1 -0
- package/dist/canvas-panel/cjs/canvas-panel.js +36 -0
- package/dist/canvas-panel/cjs/canvas-panel.js.map +1 -0
- package/dist/canvas-panel/esm/canvas-panel.mjs +2043 -0
- package/dist/canvas-panel/esm/canvas-panel.mjs.map +1 -0
- package/dist/index.umd.js +121 -31742
- package/dist/index.umd.js.map +1 -0
- package/package.json +38 -28
- package/dist/cjs/index.js +0 -2536
- package/dist/index.d.ts +0 -615
package/dist/cjs/index.js
DELETED
|
@@ -1,2536 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var React$1 = require('react');
|
|
6
|
-
var atlas = require('@atlas-viewer/atlas');
|
|
7
|
-
var vault = require('@iiif/vault');
|
|
8
|
-
var typesafeActions = require('typesafe-actions');
|
|
9
|
-
var require$$0 = require('react-dom');
|
|
10
|
-
var vaultHelpers = require('@iiif/vault-helpers');
|
|
11
|
-
var iiifImageApi = require('@atlas-viewer/iiif-image-api');
|
|
12
|
-
|
|
13
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
14
|
-
|
|
15
|
-
var React__default = /*#__PURE__*/_interopDefaultLegacy(React$1);
|
|
16
|
-
var require$$0__default = /*#__PURE__*/_interopDefaultLegacy(require$$0);
|
|
17
|
-
|
|
18
|
-
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
19
|
-
|
|
20
|
-
var reactErrorBoundary_umd = {exports: {}};
|
|
21
|
-
|
|
22
|
-
(function (module, exports) {
|
|
23
|
-
(function (global, factory) {
|
|
24
|
-
factory(exports, React__default["default"]) ;
|
|
25
|
-
})(commonjsGlobal, (function (exports, React) {
|
|
26
|
-
function _interopNamespace(e) {
|
|
27
|
-
if (e && e.__esModule) return e;
|
|
28
|
-
var n = Object.create(null);
|
|
29
|
-
if (e) {
|
|
30
|
-
Object.keys(e).forEach(function (k) {
|
|
31
|
-
if (k !== 'default') {
|
|
32
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
33
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
34
|
-
enumerable: true,
|
|
35
|
-
get: function () { return e[k]; }
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
n["default"] = e;
|
|
41
|
-
return Object.freeze(n);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
45
|
-
|
|
46
|
-
function _setPrototypeOf(o, p) {
|
|
47
|
-
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
|
|
48
|
-
o.__proto__ = p;
|
|
49
|
-
return o;
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
return _setPrototypeOf(o, p);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function _inheritsLoose(subClass, superClass) {
|
|
56
|
-
subClass.prototype = Object.create(superClass.prototype);
|
|
57
|
-
subClass.prototype.constructor = subClass;
|
|
58
|
-
_setPrototypeOf(subClass, superClass);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
var changedArray = function changedArray(a, b) {
|
|
62
|
-
if (a === void 0) {
|
|
63
|
-
a = [];
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
if (b === void 0) {
|
|
67
|
-
b = [];
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return a.length !== b.length || a.some(function (item, index) {
|
|
71
|
-
return !Object.is(item, b[index]);
|
|
72
|
-
});
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
var initialState = {
|
|
76
|
-
error: null
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
|
|
80
|
-
_inheritsLoose(ErrorBoundary, _React$Component);
|
|
81
|
-
|
|
82
|
-
function ErrorBoundary() {
|
|
83
|
-
var _this;
|
|
84
|
-
|
|
85
|
-
for (var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
86
|
-
_args[_key] = arguments[_key];
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
_this = _React$Component.call.apply(_React$Component, [this].concat(_args)) || this;
|
|
90
|
-
_this.state = initialState;
|
|
91
|
-
|
|
92
|
-
_this.resetErrorBoundary = function () {
|
|
93
|
-
var _this$props;
|
|
94
|
-
|
|
95
|
-
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
96
|
-
args[_key2] = arguments[_key2];
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
_this.props.onReset == null ? void 0 : (_this$props = _this.props).onReset.apply(_this$props, args);
|
|
100
|
-
|
|
101
|
-
_this.reset();
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
return _this;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
ErrorBoundary.getDerivedStateFromError = function getDerivedStateFromError(error) {
|
|
108
|
-
return {
|
|
109
|
-
error: error
|
|
110
|
-
};
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
var _proto = ErrorBoundary.prototype;
|
|
114
|
-
|
|
115
|
-
_proto.reset = function reset() {
|
|
116
|
-
this.setState(initialState);
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
_proto.componentDidCatch = function componentDidCatch(error, info) {
|
|
120
|
-
var _this$props$onError, _this$props2;
|
|
121
|
-
|
|
122
|
-
(_this$props$onError = (_this$props2 = this.props).onError) == null ? void 0 : _this$props$onError.call(_this$props2, error, info);
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
_proto.componentDidUpdate = function componentDidUpdate(prevProps, prevState) {
|
|
126
|
-
var error = this.state.error;
|
|
127
|
-
var resetKeys = this.props.resetKeys; // There's an edge case where if the thing that triggered the error
|
|
128
|
-
// happens to *also* be in the resetKeys array, we'd end up resetting
|
|
129
|
-
// the error boundary immediately. This would likely trigger a second
|
|
130
|
-
// error to be thrown.
|
|
131
|
-
// So we make sure that we don't check the resetKeys on the first call
|
|
132
|
-
// of cDU after the error is set
|
|
133
|
-
|
|
134
|
-
if (error !== null && prevState.error !== null && changedArray(prevProps.resetKeys, resetKeys)) {
|
|
135
|
-
var _this$props$onResetKe, _this$props3;
|
|
136
|
-
|
|
137
|
-
(_this$props$onResetKe = (_this$props3 = this.props).onResetKeysChange) == null ? void 0 : _this$props$onResetKe.call(_this$props3, prevProps.resetKeys, resetKeys);
|
|
138
|
-
this.reset();
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
_proto.render = function render() {
|
|
143
|
-
var error = this.state.error;
|
|
144
|
-
var _this$props4 = this.props,
|
|
145
|
-
fallbackRender = _this$props4.fallbackRender,
|
|
146
|
-
FallbackComponent = _this$props4.FallbackComponent,
|
|
147
|
-
fallback = _this$props4.fallback;
|
|
148
|
-
|
|
149
|
-
if (error !== null) {
|
|
150
|
-
var _props = {
|
|
151
|
-
error: error,
|
|
152
|
-
resetErrorBoundary: this.resetErrorBoundary
|
|
153
|
-
};
|
|
154
|
-
|
|
155
|
-
if ( /*#__PURE__*/React__namespace.isValidElement(fallback)) {
|
|
156
|
-
return fallback;
|
|
157
|
-
} else if (typeof fallbackRender === 'function') {
|
|
158
|
-
return fallbackRender(_props);
|
|
159
|
-
} else if (FallbackComponent) {
|
|
160
|
-
return /*#__PURE__*/React__namespace.createElement(FallbackComponent, _props);
|
|
161
|
-
} else {
|
|
162
|
-
throw new Error('react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop');
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
return this.props.children;
|
|
167
|
-
};
|
|
168
|
-
|
|
169
|
-
return ErrorBoundary;
|
|
170
|
-
}(React__namespace.Component);
|
|
171
|
-
|
|
172
|
-
function withErrorBoundary(Component, errorBoundaryProps) {
|
|
173
|
-
var Wrapped = function Wrapped(props) {
|
|
174
|
-
return /*#__PURE__*/React__namespace.createElement(ErrorBoundary, errorBoundaryProps, /*#__PURE__*/React__namespace.createElement(Component, props));
|
|
175
|
-
}; // Format for display in DevTools
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
var name = Component.displayName || Component.name || 'Unknown';
|
|
179
|
-
Wrapped.displayName = "withErrorBoundary(" + name + ")";
|
|
180
|
-
return Wrapped;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
function useErrorHandler(givenError) {
|
|
184
|
-
var _React$useState = React__namespace.useState(null),
|
|
185
|
-
error = _React$useState[0],
|
|
186
|
-
setError = _React$useState[1];
|
|
187
|
-
|
|
188
|
-
if (givenError != null) throw givenError;
|
|
189
|
-
if (error != null) throw error;
|
|
190
|
-
return setError;
|
|
191
|
-
}
|
|
192
|
-
/*
|
|
193
|
-
eslint
|
|
194
|
-
@typescript-eslint/sort-type-union-intersection-members: "off",
|
|
195
|
-
@typescript-eslint/no-throw-literal: "off",
|
|
196
|
-
@typescript-eslint/prefer-nullish-coalescing: "off"
|
|
197
|
-
*/
|
|
198
|
-
|
|
199
|
-
exports.ErrorBoundary = ErrorBoundary;
|
|
200
|
-
exports.useErrorHandler = useErrorHandler;
|
|
201
|
-
exports.withErrorBoundary = withErrorBoundary;
|
|
202
|
-
|
|
203
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
204
|
-
|
|
205
|
-
}));
|
|
206
|
-
|
|
207
|
-
}(reactErrorBoundary_umd, reactErrorBoundary_umd.exports));
|
|
208
|
-
|
|
209
|
-
var __defProp$a = Object.defineProperty;
|
|
210
|
-
var __getOwnPropSymbols$a = Object.getOwnPropertySymbols;
|
|
211
|
-
var __hasOwnProp$a = Object.prototype.hasOwnProperty;
|
|
212
|
-
var __propIsEnum$a = Object.prototype.propertyIsEnumerable;
|
|
213
|
-
var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
214
|
-
var __spreadValues$a = (a, b) => {
|
|
215
|
-
for (var prop in b || (b = {}))
|
|
216
|
-
if (__hasOwnProp$a.call(b, prop))
|
|
217
|
-
__defNormalProp$a(a, prop, b[prop]);
|
|
218
|
-
if (__getOwnPropSymbols$a)
|
|
219
|
-
for (var prop of __getOwnPropSymbols$a(b)) {
|
|
220
|
-
if (__propIsEnum$a.call(b, prop))
|
|
221
|
-
__defNormalProp$a(a, prop, b[prop]);
|
|
222
|
-
}
|
|
223
|
-
return a;
|
|
224
|
-
};
|
|
225
|
-
const defaultResourceContext = {
|
|
226
|
-
collection: void 0,
|
|
227
|
-
manifest: void 0,
|
|
228
|
-
range: void 0,
|
|
229
|
-
canvas: void 0,
|
|
230
|
-
annotation: void 0
|
|
231
|
-
};
|
|
232
|
-
const ResourceReactContext = React__default["default"].createContext(defaultResourceContext);
|
|
233
|
-
const useResourceContext = () => {
|
|
234
|
-
return React$1.useContext(ResourceReactContext);
|
|
235
|
-
};
|
|
236
|
-
function ResourceProvider({ value, children }) {
|
|
237
|
-
const parentContext = useResourceContext();
|
|
238
|
-
const newContext = React$1.useMemo(() => {
|
|
239
|
-
return __spreadValues$a(__spreadValues$a({}, parentContext), value);
|
|
240
|
-
}, [value, parentContext]);
|
|
241
|
-
return /* @__PURE__ */ React__default["default"].createElement(ResourceReactContext.Provider, {
|
|
242
|
-
value: newContext
|
|
243
|
-
}, children);
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
const ReactVaultContext = React__default["default"].createContext({
|
|
247
|
-
vault: null,
|
|
248
|
-
setVaultInstance: (vault) => {
|
|
249
|
-
}
|
|
250
|
-
});
|
|
251
|
-
function VaultProvider({
|
|
252
|
-
vault: vault$1,
|
|
253
|
-
vaultOptions,
|
|
254
|
-
useGlobal,
|
|
255
|
-
resources,
|
|
256
|
-
children
|
|
257
|
-
}) {
|
|
258
|
-
const [vaultInstance, setVaultInstance] = React$1.useState(() => {
|
|
259
|
-
if (vault$1) {
|
|
260
|
-
return vault$1;
|
|
261
|
-
}
|
|
262
|
-
if (useGlobal) {
|
|
263
|
-
return vault.globalVault(vaultOptions);
|
|
264
|
-
}
|
|
265
|
-
if (vaultOptions) {
|
|
266
|
-
return new vault.Vault(vaultOptions);
|
|
267
|
-
}
|
|
268
|
-
return new vault.Vault();
|
|
269
|
-
});
|
|
270
|
-
return /* @__PURE__ */ React__default["default"].createElement(ReactVaultContext.Provider, {
|
|
271
|
-
value: { vault: vaultInstance, setVaultInstance }
|
|
272
|
-
}, /* @__PURE__ */ React__default["default"].createElement(ResourceProvider, {
|
|
273
|
-
value: resources || {}
|
|
274
|
-
}, children));
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
const useVault = () => {
|
|
278
|
-
const { vault } = React$1.useContext(ReactVaultContext);
|
|
279
|
-
if (vault === null) {
|
|
280
|
-
throw new Error("Vault not found. Ensure you have your provider set up correctly.");
|
|
281
|
-
}
|
|
282
|
-
return vault;
|
|
283
|
-
};
|
|
284
|
-
|
|
285
|
-
var __async$1 = (__this, __arguments, generator) => {
|
|
286
|
-
return new Promise((resolve, reject) => {
|
|
287
|
-
var fulfilled = (value) => {
|
|
288
|
-
try {
|
|
289
|
-
step(generator.next(value));
|
|
290
|
-
} catch (e) {
|
|
291
|
-
reject(e);
|
|
292
|
-
}
|
|
293
|
-
};
|
|
294
|
-
var rejected = (value) => {
|
|
295
|
-
try {
|
|
296
|
-
step(generator.throw(value));
|
|
297
|
-
} catch (e) {
|
|
298
|
-
reject(e);
|
|
299
|
-
}
|
|
300
|
-
};
|
|
301
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
302
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
303
|
-
});
|
|
304
|
-
};
|
|
305
|
-
function useExternalResource(idOrRef, { noCache = false } = {}) {
|
|
306
|
-
const id = typeof idOrRef === "string" ? idOrRef : idOrRef.id;
|
|
307
|
-
const vault = useVault();
|
|
308
|
-
const [realId, setRealId] = React$1.useState(id);
|
|
309
|
-
const [error, setError] = React$1.useState(void 0);
|
|
310
|
-
const initialData = React$1.useMemo(() => {
|
|
311
|
-
return vault.get(id, { skipSelfReturn: true }) || void 0;
|
|
312
|
-
}, [id, vault]);
|
|
313
|
-
const [resource, setResource] = React$1.useState(initialData);
|
|
314
|
-
React$1.useEffect(() => {
|
|
315
|
-
(() => __async$1(this, null, function* () {
|
|
316
|
-
try {
|
|
317
|
-
const fetchedResource = initialData && !noCache ? initialData : yield vault.load(id);
|
|
318
|
-
const _realId = fetchedResource ? fetchedResource.id || fetchedResource["@id"] : null;
|
|
319
|
-
if (fetchedResource && realId !== _realId) {
|
|
320
|
-
setRealId(_realId);
|
|
321
|
-
}
|
|
322
|
-
setResource(fetchedResource);
|
|
323
|
-
} catch (err) {
|
|
324
|
-
setError(err);
|
|
325
|
-
}
|
|
326
|
-
}))();
|
|
327
|
-
}, [id, noCache]);
|
|
328
|
-
return {
|
|
329
|
-
isLoaded: !!resource,
|
|
330
|
-
id: realId,
|
|
331
|
-
requestId: id,
|
|
332
|
-
error,
|
|
333
|
-
resource,
|
|
334
|
-
cached: !!(resource && resource === initialData)
|
|
335
|
-
};
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
function useExternalManifest(idOrRef, options) {
|
|
339
|
-
const { id, isLoaded, error, resource, requestId, cached } = useExternalResource(idOrRef, options);
|
|
340
|
-
return { id, isLoaded, error, manifest: resource, requestId, cached };
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
function ManifestContext({ manifest, children }) {
|
|
344
|
-
return /* @__PURE__ */ React__default["default"].createElement(ResourceProvider, {
|
|
345
|
-
value: { manifest }
|
|
346
|
-
}, children);
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
function CanvasContext({ canvas, children }) {
|
|
350
|
-
return /* @__PURE__ */ React__default["default"].createElement(ResourceProvider, {
|
|
351
|
-
value: { canvas }
|
|
352
|
-
}, children);
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
function useVaultSelector(selector, deps = []) {
|
|
356
|
-
const vault = useVault();
|
|
357
|
-
const [selectedState, setSelectedState] = React$1.useState(() => selector(vault.getState(), vault));
|
|
358
|
-
React$1.useEffect(() => {
|
|
359
|
-
return vault.subscribe((s) => selector(s, vault), (s) => {
|
|
360
|
-
setSelectedState(s);
|
|
361
|
-
}, false);
|
|
362
|
-
}, deps);
|
|
363
|
-
return selectedState;
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
const VisibleCanvasReactContext = React__default["default"].createContext([]);
|
|
367
|
-
function useVisibleCanvases() {
|
|
368
|
-
const ids = React$1.useContext(VisibleCanvasReactContext);
|
|
369
|
-
return useVaultSelector((state) => {
|
|
370
|
-
return ids.map((id) => state.iiif.entities.Canvas[id]).filter(Boolean);
|
|
371
|
-
}, [ids]);
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
const noop = () => {
|
|
375
|
-
};
|
|
376
|
-
const SimpleViewerReactContext = React$1.createContext({
|
|
377
|
-
setCurrentCanvasId: noop,
|
|
378
|
-
setCurrentCanvasIndex: noop,
|
|
379
|
-
nextCanvas: noop,
|
|
380
|
-
previousCanvas: noop,
|
|
381
|
-
currentCanvasIndex: -1,
|
|
382
|
-
totalCanvases: 0,
|
|
383
|
-
pagingView: true
|
|
384
|
-
});
|
|
385
|
-
function SimpleViewerProvider(props) {
|
|
386
|
-
const manifest = useExternalManifest(props.manifest);
|
|
387
|
-
const [currentCanvasId, setCurrentCanvasId] = React$1.useState("");
|
|
388
|
-
const [visible, setVisible] = React$1.useState([]);
|
|
389
|
-
const pagingView = (typeof props.pagingEnabled === "undefined" || props.pagingEnabled) && manifest.manifest && manifest.manifest.behavior && manifest.manifest.behavior.includes("paged");
|
|
390
|
-
React$1.useEffect(() => {
|
|
391
|
-
var _a, _b;
|
|
392
|
-
if (manifest.manifest) {
|
|
393
|
-
setCurrentCanvasId((_a = manifest.manifest.items[0]) == null ? void 0 : _a.id);
|
|
394
|
-
setVisible([(_b = manifest.manifest.items[0]) == null ? void 0 : _b.id]);
|
|
395
|
-
}
|
|
396
|
-
}, [manifest.manifest, props.manifest]);
|
|
397
|
-
const canvasList = React$1.useMemo(() => {
|
|
398
|
-
var _a;
|
|
399
|
-
return ((_a = manifest.manifest) == null ? void 0 : _a.items.map((c) => c.id)) || [];
|
|
400
|
-
}, [manifest.manifest, props.manifest]);
|
|
401
|
-
const currentCanvasIndex = React$1.useMemo(() => canvasList.indexOf(currentCanvasId), [canvasList, currentCanvasId]);
|
|
402
|
-
const nextCanvas = React$1.useCallback(() => {
|
|
403
|
-
if (canvasList.length && currentCanvasId) {
|
|
404
|
-
if (currentCanvasIndex === -1) {
|
|
405
|
-
return;
|
|
406
|
-
}
|
|
407
|
-
if (canvasList[currentCanvasIndex + 2] ? currentCanvasIndex + 2 === canvasList.length : currentCanvasIndex === canvasList.length) {
|
|
408
|
-
return;
|
|
409
|
-
}
|
|
410
|
-
const newCanvas = pagingView && currentCanvasIndex !== 0 ? canvasList[currentCanvasIndex + 2] : canvasList[currentCanvasIndex + 1];
|
|
411
|
-
const pageCanvas = pagingView ? currentCanvasIndex !== 0 ? canvasList[currentCanvasIndex + 3] : canvasList[currentCanvasIndex + 2] : null;
|
|
412
|
-
if (newCanvas) {
|
|
413
|
-
setCurrentCanvasId(newCanvas);
|
|
414
|
-
setVisible(pageCanvas ? [newCanvas, pageCanvas] : [newCanvas]);
|
|
415
|
-
}
|
|
416
|
-
}
|
|
417
|
-
}, [pagingView, canvasList, currentCanvasId, currentCanvasIndex]);
|
|
418
|
-
const previousCanvas = React$1.useCallback(() => {
|
|
419
|
-
if (canvasList.length && currentCanvasId) {
|
|
420
|
-
if (currentCanvasIndex === 0 || currentCanvasIndex === -1) {
|
|
421
|
-
return;
|
|
422
|
-
}
|
|
423
|
-
const newCanvas = pagingView && currentCanvasIndex !== 1 ? canvasList[currentCanvasIndex - 2] : canvasList[currentCanvasIndex - 1];
|
|
424
|
-
const pageCanvas = pagingView && currentCanvasIndex !== 1 ? canvasList[currentCanvasIndex - 1] : null;
|
|
425
|
-
if (newCanvas) {
|
|
426
|
-
setCurrentCanvasId(newCanvas);
|
|
427
|
-
setVisible(pageCanvas ? [newCanvas, pageCanvas] : [newCanvas]);
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
}, [pagingView, canvasList, currentCanvasId, currentCanvasIndex]);
|
|
431
|
-
const setCurrentCanvasIndex = React$1.useCallback((idx) => {
|
|
432
|
-
const realIdx = pagingView && idx % 2 === 1 ? idx - 1 : idx;
|
|
433
|
-
const newId = canvasList[realIdx];
|
|
434
|
-
const newNextId = pagingView && realIdx !== 0 ? canvasList[realIdx + 1] : null;
|
|
435
|
-
if (newId) {
|
|
436
|
-
setCurrentCanvasId(newId);
|
|
437
|
-
setVisible((prevValue) => {
|
|
438
|
-
const newValue = newNextId ? [newId, newNextId] : [newId];
|
|
439
|
-
if (prevValue.length === prevValue.length) {
|
|
440
|
-
for (let i = 0; i < prevValue.length; i++) {
|
|
441
|
-
if (prevValue[i] !== newValue[i]) {
|
|
442
|
-
return newValue;
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
return prevValue;
|
|
446
|
-
}
|
|
447
|
-
return newValue;
|
|
448
|
-
});
|
|
449
|
-
}
|
|
450
|
-
}, [pagingView, canvasList]);
|
|
451
|
-
const internalSetCurrentCanvasId = React$1.useCallback((nextId) => {
|
|
452
|
-
const idx = canvasList.indexOf(nextId);
|
|
453
|
-
if (idx !== -1) {
|
|
454
|
-
setCurrentCanvasIndex(idx);
|
|
455
|
-
}
|
|
456
|
-
}, [canvasList, setCurrentCanvasIndex]);
|
|
457
|
-
const ctx = React$1.useMemo(() => ({
|
|
458
|
-
setCurrentCanvasId: internalSetCurrentCanvasId,
|
|
459
|
-
nextCanvas,
|
|
460
|
-
previousCanvas,
|
|
461
|
-
currentCanvasIndex,
|
|
462
|
-
totalCanvases: canvasList.length,
|
|
463
|
-
setCurrentCanvasIndex,
|
|
464
|
-
pagingView: true
|
|
465
|
-
}), [nextCanvas, previousCanvas, currentCanvasIndex, canvasList, setCurrentCanvasIndex, internalSetCurrentCanvasId]);
|
|
466
|
-
if (!manifest.manifest) {
|
|
467
|
-
console.warn("The manifest passed to the provider is not a valid IIIF manifest.");
|
|
468
|
-
return /* @__PURE__ */ React__default["default"].createElement("div", null, "Sorry, something went wrong.");
|
|
469
|
-
}
|
|
470
|
-
if (!manifest.isLoaded) {
|
|
471
|
-
return /* @__PURE__ */ React__default["default"].createElement("div", null, "Loading...");
|
|
472
|
-
}
|
|
473
|
-
return /* @__PURE__ */ React__default["default"].createElement(SimpleViewerReactContext.Provider, {
|
|
474
|
-
value: ctx
|
|
475
|
-
}, /* @__PURE__ */ React__default["default"].createElement(VisibleCanvasReactContext.Provider, {
|
|
476
|
-
value: visible
|
|
477
|
-
}, /* @__PURE__ */ React__default["default"].createElement(ManifestContext, {
|
|
478
|
-
manifest: manifest.manifest.id
|
|
479
|
-
}, /* @__PURE__ */ React__default["default"].createElement(CanvasContext, {
|
|
480
|
-
canvas: currentCanvasId
|
|
481
|
-
}, props.children))));
|
|
482
|
-
}
|
|
483
|
-
function useSimpleViewer() {
|
|
484
|
-
return React$1.useContext(SimpleViewerReactContext);
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
function useContextBridge() {
|
|
488
|
-
return {
|
|
489
|
-
VaultContext: React$1.useContext(ReactVaultContext),
|
|
490
|
-
ResourceContext: React$1.useContext(ResourceReactContext),
|
|
491
|
-
SimpleViewerReactContext: React$1.useContext(SimpleViewerReactContext),
|
|
492
|
-
VisibleCanvasReactContext: React$1.useContext(VisibleCanvasReactContext)
|
|
493
|
-
};
|
|
494
|
-
}
|
|
495
|
-
function ContextBridge(props) {
|
|
496
|
-
return /* @__PURE__ */ React__default["default"].createElement(VaultProvider, {
|
|
497
|
-
vault: props.bridge.VaultContext.vault || void 0,
|
|
498
|
-
resources: props.bridge.ResourceContext
|
|
499
|
-
}, /* @__PURE__ */ React__default["default"].createElement(VisibleCanvasReactContext.Provider, {
|
|
500
|
-
value: props.bridge.VisibleCanvasReactContext
|
|
501
|
-
}, /* @__PURE__ */ React__default["default"].createElement(SimpleViewerReactContext.Provider, {
|
|
502
|
-
value: props.bridge.SimpleViewerReactContext
|
|
503
|
-
}, props.children)));
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
const IMPORT_ENTITIES = "@iiif/IMPORT_ENTITIES";
|
|
507
|
-
const MODIFY_ENTITY_FIELD = "@iiif/MODIFY_ENTITY_FIELD";
|
|
508
|
-
const REORDER_ENTITY_FIELD = "@iiif/REORDER_ENTITY_FIELD";
|
|
509
|
-
const ADD_REFERENCE = "@iiif/ADD_REFERENCE";
|
|
510
|
-
const REMOVE_REFERENCE = "@iiif/REMOVE_REFERENCE";
|
|
511
|
-
const importEntities = typesafeActions.createAction(IMPORT_ENTITIES)();
|
|
512
|
-
const modifyEntityField = typesafeActions.createAction(MODIFY_ENTITY_FIELD)();
|
|
513
|
-
const reorderEntityField = typesafeActions.createAction(REORDER_ENTITY_FIELD)();
|
|
514
|
-
const addReference = typesafeActions.createAction(ADD_REFERENCE)();
|
|
515
|
-
const removeReference = typesafeActions.createAction(REMOVE_REFERENCE)();
|
|
516
|
-
const entityActions = { importEntities, modifyEntityField, reorderEntityField, addReference, removeReference };
|
|
517
|
-
|
|
518
|
-
const ADD_MAPPING = "@iiif/ADD_MAPPING";
|
|
519
|
-
const ADD_MAPPINGS = "@iiif/ADD_MAPPINGS";
|
|
520
|
-
typesafeActions.createAction(ADD_MAPPING)();
|
|
521
|
-
typesafeActions.createAction(ADD_MAPPINGS)();
|
|
522
|
-
|
|
523
|
-
const SET_META_VALUE = "@iiif/SET_META_VALUE";
|
|
524
|
-
const SET_META_VALUE_DYNAMIC = "@iiif/SET_META_VALUE_DYNAMIC";
|
|
525
|
-
const UNSET_META_VALUE = "@iiif/UNSET_META_VALUE";
|
|
526
|
-
typesafeActions.createAction(SET_META_VALUE)();
|
|
527
|
-
typesafeActions.createAction(SET_META_VALUE_DYNAMIC)();
|
|
528
|
-
typesafeActions.createAction(UNSET_META_VALUE)();
|
|
529
|
-
const REQUEST_RESOURCE = "@iiif/REQUEST_RESOURCE";
|
|
530
|
-
const REQUEST_ERROR = "@iiif/REQUEST_ERROR";
|
|
531
|
-
const REQUEST_MISMATCH = "@iiif/REQUEST_MISMATCH";
|
|
532
|
-
const REQUEST_COMPLETE = "@iiif/REQUEST_COMPLETE";
|
|
533
|
-
const REQUEST_OFFLINE_RESOURCE = "@iiif/REQUEST_OFFLINE_RESOURCE";
|
|
534
|
-
typesafeActions.createAction(REQUEST_RESOURCE)();
|
|
535
|
-
typesafeActions.createAction(REQUEST_ERROR)();
|
|
536
|
-
typesafeActions.createAction(REQUEST_MISMATCH)();
|
|
537
|
-
typesafeActions.createAction(REQUEST_COMPLETE)();
|
|
538
|
-
typesafeActions.createAction(REQUEST_OFFLINE_RESOURCE)();
|
|
539
|
-
|
|
540
|
-
const BATCH_ACTIONS = "@iiif/BATCH";
|
|
541
|
-
const BATCH_IMPORT = "@iiif/BATCH_IMPORT";
|
|
542
|
-
typesafeActions.createAction(BATCH_ACTIONS)();
|
|
543
|
-
typesafeActions.createAction(BATCH_IMPORT)();
|
|
544
|
-
|
|
545
|
-
function useDispatch() {
|
|
546
|
-
const vault = useVault();
|
|
547
|
-
const store = vault.getStore();
|
|
548
|
-
return React$1.useMemo(() => {
|
|
549
|
-
return (action) => store.dispatch(action);
|
|
550
|
-
}, [store]);
|
|
551
|
-
}
|
|
552
|
-
|
|
553
|
-
function isVaultActivated(obj) {
|
|
554
|
-
return typeof obj !== "string" && obj && obj.bindToVault;
|
|
555
|
-
}
|
|
556
|
-
function useVirtualAnnotationPage() {
|
|
557
|
-
const vault = useVault();
|
|
558
|
-
const sources = React$1.useRef([]);
|
|
559
|
-
const dispatch = useDispatch();
|
|
560
|
-
const virtualId = React$1.useMemo(() => {
|
|
561
|
-
return `vault://annotation-page/${new Date().getTime()}/${Math.round(Math.random() * 1e9).toString(16)}`;
|
|
562
|
-
}, []);
|
|
563
|
-
React$1.useLayoutEffect(() => {
|
|
564
|
-
const page = {
|
|
565
|
-
id: virtualId,
|
|
566
|
-
type: "AnnotationPage",
|
|
567
|
-
behavior: [],
|
|
568
|
-
motivation: null,
|
|
569
|
-
label: null,
|
|
570
|
-
thumbnail: [],
|
|
571
|
-
summary: null,
|
|
572
|
-
requiredStatement: null,
|
|
573
|
-
metadata: [],
|
|
574
|
-
rights: null,
|
|
575
|
-
provider: [],
|
|
576
|
-
items: [],
|
|
577
|
-
seeAlso: [],
|
|
578
|
-
homepage: [],
|
|
579
|
-
logo: [],
|
|
580
|
-
rendering: [],
|
|
581
|
-
service: []
|
|
582
|
-
};
|
|
583
|
-
dispatch(entityActions.importEntities({
|
|
584
|
-
entities: {
|
|
585
|
-
AnnotationPage: {
|
|
586
|
-
[page.id]: page
|
|
587
|
-
}
|
|
588
|
-
}
|
|
589
|
-
}));
|
|
590
|
-
}, [virtualId]);
|
|
591
|
-
const fullPage = useVaultSelector((state) => virtualId ? state.iiif.entities.AnnotationPage[virtualId] : null, [virtualId]);
|
|
592
|
-
const addAnnotation = React$1.useCallback((id, atIndex) => {
|
|
593
|
-
if (virtualId) {
|
|
594
|
-
if (isVaultActivated(id)) {
|
|
595
|
-
const display = id;
|
|
596
|
-
if (!display.__vault) {
|
|
597
|
-
display.bindToVault(vault);
|
|
598
|
-
}
|
|
599
|
-
id = typeof display.source === "string" ? display.source : display.source.id;
|
|
600
|
-
sources.current[id] = display;
|
|
601
|
-
} else if (typeof id !== "string") {
|
|
602
|
-
id = id.id;
|
|
603
|
-
}
|
|
604
|
-
const full = vault.get({ id: virtualId, type: "AnnotationPage" });
|
|
605
|
-
const annotation = vault.get({ id, type: "Annotation" });
|
|
606
|
-
if (full && annotation) {
|
|
607
|
-
if (!full.items.find((r) => r.id === annotation.id)) {
|
|
608
|
-
dispatch(entityActions.addReference({
|
|
609
|
-
id: virtualId,
|
|
610
|
-
type: "AnnotationPage",
|
|
611
|
-
key: "items",
|
|
612
|
-
reference: {
|
|
613
|
-
id,
|
|
614
|
-
type: "Annotation"
|
|
615
|
-
},
|
|
616
|
-
index: atIndex
|
|
617
|
-
}));
|
|
618
|
-
}
|
|
619
|
-
}
|
|
620
|
-
}
|
|
621
|
-
}, [virtualId]);
|
|
622
|
-
const removeAnnotation = React$1.useCallback((id) => {
|
|
623
|
-
if (virtualId) {
|
|
624
|
-
if (isVaultActivated(id)) {
|
|
625
|
-
id = typeof id.source === "string" ? id.source : id.source.id;
|
|
626
|
-
} else if (typeof id !== "string") {
|
|
627
|
-
id = id.id;
|
|
628
|
-
}
|
|
629
|
-
if (sources.current[id]) {
|
|
630
|
-
sources.current[id].beforeRemove();
|
|
631
|
-
}
|
|
632
|
-
const full = vault.get({ id: virtualId, type: "AnnotationPage" });
|
|
633
|
-
if (full) {
|
|
634
|
-
dispatch(entityActions.removeReference({
|
|
635
|
-
id: virtualId,
|
|
636
|
-
type: "AnnotationPage",
|
|
637
|
-
key: "items",
|
|
638
|
-
reference: {
|
|
639
|
-
id,
|
|
640
|
-
type: "Annotation"
|
|
641
|
-
}
|
|
642
|
-
}));
|
|
643
|
-
}
|
|
644
|
-
}
|
|
645
|
-
}, [virtualId]);
|
|
646
|
-
return [
|
|
647
|
-
fullPage,
|
|
648
|
-
{
|
|
649
|
-
addAnnotation,
|
|
650
|
-
removeAnnotation
|
|
651
|
-
}
|
|
652
|
-
];
|
|
653
|
-
}
|
|
654
|
-
|
|
655
|
-
const VirtualAnnotationPageContext = React$1.createContext(null);
|
|
656
|
-
function useVirtualAnnotationPageContext() {
|
|
657
|
-
const ctx = React$1.useContext(VirtualAnnotationPageContext);
|
|
658
|
-
return [
|
|
659
|
-
ctx.fullPage,
|
|
660
|
-
{
|
|
661
|
-
addAnnotation: ctx.addAnnotation,
|
|
662
|
-
removeAnnotation: ctx.removeAnnotation
|
|
663
|
-
}
|
|
664
|
-
];
|
|
665
|
-
}
|
|
666
|
-
function VirtualAnnotationProvider({ children }) {
|
|
667
|
-
const [fullPage, { addAnnotation, removeAnnotation }] = useVirtualAnnotationPage();
|
|
668
|
-
return /* @__PURE__ */ React__default["default"].createElement(VirtualAnnotationPageContext.Provider, {
|
|
669
|
-
value: React$1.useMemo(() => ({ fullPage, addAnnotation, removeAnnotation }), [fullPage])
|
|
670
|
-
}, children);
|
|
671
|
-
}
|
|
672
|
-
|
|
673
|
-
var __defProp$9 = Object.defineProperty;
|
|
674
|
-
var __defProps$7 = Object.defineProperties;
|
|
675
|
-
var __getOwnPropDescs$7 = Object.getOwnPropertyDescriptors;
|
|
676
|
-
var __getOwnPropSymbols$9 = Object.getOwnPropertySymbols;
|
|
677
|
-
var __hasOwnProp$9 = Object.prototype.hasOwnProperty;
|
|
678
|
-
var __propIsEnum$9 = Object.prototype.propertyIsEnumerable;
|
|
679
|
-
var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
680
|
-
var __spreadValues$9 = (a, b) => {
|
|
681
|
-
for (var prop in b || (b = {}))
|
|
682
|
-
if (__hasOwnProp$9.call(b, prop))
|
|
683
|
-
__defNormalProp$9(a, prop, b[prop]);
|
|
684
|
-
if (__getOwnPropSymbols$9)
|
|
685
|
-
for (var prop of __getOwnPropSymbols$9(b)) {
|
|
686
|
-
if (__propIsEnum$9.call(b, prop))
|
|
687
|
-
__defNormalProp$9(a, prop, b[prop]);
|
|
688
|
-
}
|
|
689
|
-
return a;
|
|
690
|
-
};
|
|
691
|
-
var __spreadProps$7 = (a, b) => __defProps$7(a, __getOwnPropDescs$7(b));
|
|
692
|
-
function DefaultCanvasFallback({ width, style, height }) {
|
|
693
|
-
return /* @__PURE__ */ React__default["default"].createElement("div", {
|
|
694
|
-
style: __spreadProps$7(__spreadValues$9({ width, height, minHeight: 500 }, style || {}), { background: "#f9f9f9" })
|
|
695
|
-
}, "Unknown error");
|
|
696
|
-
}
|
|
697
|
-
|
|
698
|
-
var createRoot;
|
|
699
|
-
|
|
700
|
-
var m = require$$0__default["default"];
|
|
701
|
-
{
|
|
702
|
-
var i = m.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
|
|
703
|
-
createRoot = function(c, o) {
|
|
704
|
-
i.usingClientEntryPoint = true;
|
|
705
|
-
try {
|
|
706
|
-
return m.createRoot(c, o);
|
|
707
|
-
} finally {
|
|
708
|
-
i.usingClientEntryPoint = false;
|
|
709
|
-
}
|
|
710
|
-
};
|
|
711
|
-
}
|
|
712
|
-
|
|
713
|
-
const ViewerPresetContext = React$1.createContext(null);
|
|
714
|
-
function useViewerPreset() {
|
|
715
|
-
return React$1.useContext(ViewerPresetContext);
|
|
716
|
-
}
|
|
717
|
-
|
|
718
|
-
const PortalContext = React__default["default"].createContext(null);
|
|
719
|
-
const OverlayPortalContext = React__default["default"].createContext(null);
|
|
720
|
-
function CanvasPortal({ children, overlay }) {
|
|
721
|
-
const htmlElement = React$1.useContext(overlay ? OverlayPortalContext : PortalContext);
|
|
722
|
-
const rootRef = React$1.useRef(null);
|
|
723
|
-
const preset = useViewerPreset();
|
|
724
|
-
React$1.useLayoutEffect(() => {
|
|
725
|
-
if (!rootRef.current) {
|
|
726
|
-
rootRef.current = htmlElement ? createRoot(htmlElement) : null;
|
|
727
|
-
}
|
|
728
|
-
}, []);
|
|
729
|
-
React$1.useLayoutEffect(() => {
|
|
730
|
-
return () => {
|
|
731
|
-
var _a;
|
|
732
|
-
(_a = rootRef.current) == null ? void 0 : _a.unmount();
|
|
733
|
-
rootRef.current = null;
|
|
734
|
-
};
|
|
735
|
-
}, []);
|
|
736
|
-
React$1.useLayoutEffect(() => {
|
|
737
|
-
if (rootRef.current) {
|
|
738
|
-
rootRef.current.render(/* @__PURE__ */ React__default["default"].createElement(ViewerPresetContext.Provider, {
|
|
739
|
-
value: preset
|
|
740
|
-
}, children));
|
|
741
|
-
}
|
|
742
|
-
}, [children, preset]);
|
|
743
|
-
return null;
|
|
744
|
-
}
|
|
745
|
-
|
|
746
|
-
var __defProp$8 = Object.defineProperty;
|
|
747
|
-
var __defProps$6 = Object.defineProperties;
|
|
748
|
-
var __getOwnPropDescs$6 = Object.getOwnPropertyDescriptors;
|
|
749
|
-
var __getOwnPropSymbols$8 = Object.getOwnPropertySymbols;
|
|
750
|
-
var __hasOwnProp$8 = Object.prototype.hasOwnProperty;
|
|
751
|
-
var __propIsEnum$8 = Object.prototype.propertyIsEnumerable;
|
|
752
|
-
var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
753
|
-
var __spreadValues$8 = (a, b) => {
|
|
754
|
-
for (var prop in b || (b = {}))
|
|
755
|
-
if (__hasOwnProp$8.call(b, prop))
|
|
756
|
-
__defNormalProp$8(a, prop, b[prop]);
|
|
757
|
-
if (__getOwnPropSymbols$8)
|
|
758
|
-
for (var prop of __getOwnPropSymbols$8(b)) {
|
|
759
|
-
if (__propIsEnum$8.call(b, prop))
|
|
760
|
-
__defNormalProp$8(a, prop, b[prop]);
|
|
761
|
-
}
|
|
762
|
-
return a;
|
|
763
|
-
};
|
|
764
|
-
var __spreadProps$6 = (a, b) => __defProps$6(a, __getOwnPropDescs$6(b));
|
|
765
|
-
var __objRest = (source, exclude) => {
|
|
766
|
-
var target = {};
|
|
767
|
-
for (var prop in source)
|
|
768
|
-
if (__hasOwnProp$8.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
769
|
-
target[prop] = source[prop];
|
|
770
|
-
if (source != null && __getOwnPropSymbols$8)
|
|
771
|
-
for (var prop of __getOwnPropSymbols$8(source)) {
|
|
772
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum$8.call(source, prop))
|
|
773
|
-
target[prop] = source[prop];
|
|
774
|
-
}
|
|
775
|
-
return target;
|
|
776
|
-
};
|
|
777
|
-
function Viewer(_a) {
|
|
778
|
-
var _b = _a, {
|
|
779
|
-
children,
|
|
780
|
-
errorFallback,
|
|
781
|
-
outerContainerProps = {}
|
|
782
|
-
} = _b, props = __objRest(_b, [
|
|
783
|
-
"children",
|
|
784
|
-
"errorFallback",
|
|
785
|
-
"outerContainerProps"
|
|
786
|
-
]);
|
|
787
|
-
const portal = React$1.useRef(null);
|
|
788
|
-
const [portalElement, setPortalElement] = React$1.useState();
|
|
789
|
-
const [viewerPreset, setViewerPreset] = React$1.useState();
|
|
790
|
-
const overlayPortal = React$1.useRef(null);
|
|
791
|
-
const [overlayPortalElement, setOverlayPortalElement] = React$1.useState();
|
|
792
|
-
const bridge = useContextBridge();
|
|
793
|
-
const ErrorFallback = errorFallback || DefaultCanvasFallback;
|
|
794
|
-
React$1.useLayoutEffect(() => {
|
|
795
|
-
setPortalElement(portal.current);
|
|
796
|
-
setOverlayPortalElement(overlayPortal.current);
|
|
797
|
-
}, []);
|
|
798
|
-
return /* @__PURE__ */ React__default["default"].createElement(reactErrorBoundary_umd.exports.ErrorBoundary, {
|
|
799
|
-
fallbackRender: () => /* @__PURE__ */ React__default["default"].createElement(ErrorFallback, __spreadValues$8({}, props))
|
|
800
|
-
}, /* @__PURE__ */ React__default["default"].createElement(atlas.AtlasAuto, __spreadProps$6(__spreadValues$8({}, props), {
|
|
801
|
-
containerProps: __spreadValues$8({ style: { position: "relative" } }, props.containerProps || {}),
|
|
802
|
-
htmlChildren: /* @__PURE__ */ React__default["default"].createElement("div", {
|
|
803
|
-
ref: overlayPortal
|
|
804
|
-
}),
|
|
805
|
-
onCreated: (preset) => {
|
|
806
|
-
setViewerPreset(preset);
|
|
807
|
-
if (props.onCreated) {
|
|
808
|
-
props.onCreated(preset);
|
|
809
|
-
}
|
|
810
|
-
}
|
|
811
|
-
}), /* @__PURE__ */ React__default["default"].createElement(ViewerPresetContext.Provider, {
|
|
812
|
-
value: viewerPreset
|
|
813
|
-
}, /* @__PURE__ */ React__default["default"].createElement(PortalContext.Provider, {
|
|
814
|
-
value: portalElement
|
|
815
|
-
}, /* @__PURE__ */ React__default["default"].createElement(OverlayPortalContext.Provider, {
|
|
816
|
-
value: overlayPortalElement
|
|
817
|
-
}, /* @__PURE__ */ React__default["default"].createElement(ContextBridge, {
|
|
818
|
-
bridge
|
|
819
|
-
}, /* @__PURE__ */ React__default["default"].createElement(VirtualAnnotationProvider, null, children)))))), /* @__PURE__ */ React__default["default"].createElement("div", {
|
|
820
|
-
ref: portal
|
|
821
|
-
}));
|
|
822
|
-
}
|
|
823
|
-
|
|
824
|
-
function useResourceEvents(resource, scope) {
|
|
825
|
-
const vault = useVault();
|
|
826
|
-
const helper = React$1.useMemo(() => vaultHelpers.createEventsHelper(vault), [vault]);
|
|
827
|
-
const hooks = useVaultSelector(() => {
|
|
828
|
-
if (resource && resource.id) {
|
|
829
|
-
return vault.getResourceMeta(resource.id, "eventManager");
|
|
830
|
-
}
|
|
831
|
-
return null;
|
|
832
|
-
}, [resource]);
|
|
833
|
-
return React$1.useMemo(() => {
|
|
834
|
-
return resource ? helper.getListenersAsProps(resource, scope) : {};
|
|
835
|
-
}, [hooks, resource, vault, scope]);
|
|
836
|
-
}
|
|
837
|
-
|
|
838
|
-
function useStyles(resource, scope) {
|
|
839
|
-
const vault = useVault();
|
|
840
|
-
const helper = React$1.useMemo(() => vaultHelpers.createStylesHelper(vault), [vault]);
|
|
841
|
-
return useVaultSelector(() => {
|
|
842
|
-
if (!resource) {
|
|
843
|
-
return null;
|
|
844
|
-
}
|
|
845
|
-
const styles = helper.getAppliedStyles(resource.id);
|
|
846
|
-
return styles ? scope ? styles[scope] : styles : void 0;
|
|
847
|
-
}, [resource, scope]);
|
|
848
|
-
}
|
|
849
|
-
|
|
850
|
-
const BOX_SELECTOR = /&?(xywh=)?(pixel:|percent:)?([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?),([0-9]+(?:\.[0-9]+)?)/;
|
|
851
|
-
const TEMPORAL_SELECTOR = /&?(t=)(npt:)?([0-9]+(.[0-9]+)?)?(,([0-9]+(.[0-9]+)?))?/;
|
|
852
|
-
function parseSelector(source) {
|
|
853
|
-
if (Array.isArray(source)) {
|
|
854
|
-
return source.reduce((data, nextSource) => {
|
|
855
|
-
const { selector, selectors } = parseSelector(nextSource);
|
|
856
|
-
if (selector) {
|
|
857
|
-
if (!data.selector) {
|
|
858
|
-
data.selector = selector;
|
|
859
|
-
}
|
|
860
|
-
data.selectors.push(...selectors);
|
|
861
|
-
}
|
|
862
|
-
return data;
|
|
863
|
-
}, {
|
|
864
|
-
selector: null,
|
|
865
|
-
selectors: []
|
|
866
|
-
});
|
|
867
|
-
}
|
|
868
|
-
if (!source) {
|
|
869
|
-
return {
|
|
870
|
-
selector: null,
|
|
871
|
-
selectors: []
|
|
872
|
-
};
|
|
873
|
-
}
|
|
874
|
-
if (typeof source === "string") {
|
|
875
|
-
const [id, fragment] = source.split("#");
|
|
876
|
-
if (!fragment) {
|
|
877
|
-
return {
|
|
878
|
-
selector: null,
|
|
879
|
-
selectors: []
|
|
880
|
-
};
|
|
881
|
-
}
|
|
882
|
-
return parseSelector({ type: "FragmentSelector", value: fragment });
|
|
883
|
-
}
|
|
884
|
-
if (source.type === "PointSelector" && (source.t || source.t === 0)) {
|
|
885
|
-
const selector = {
|
|
886
|
-
type: "TemporalSelector",
|
|
887
|
-
temporal: {
|
|
888
|
-
startTime: source.t
|
|
889
|
-
}
|
|
890
|
-
};
|
|
891
|
-
return {
|
|
892
|
-
selector,
|
|
893
|
-
selectors: [selector]
|
|
894
|
-
};
|
|
895
|
-
}
|
|
896
|
-
if (source.type === "FragmentSelector") {
|
|
897
|
-
const matchBoxSelector = BOX_SELECTOR.exec(source.value);
|
|
898
|
-
if (matchBoxSelector) {
|
|
899
|
-
const selector = {
|
|
900
|
-
type: "BoxSelector",
|
|
901
|
-
spatial: {
|
|
902
|
-
unit: matchBoxSelector[2] === "percent:" ? "percent" : "pixel",
|
|
903
|
-
x: parseFloat(matchBoxSelector[3]),
|
|
904
|
-
y: parseFloat(matchBoxSelector[4]),
|
|
905
|
-
width: parseFloat(matchBoxSelector[5]),
|
|
906
|
-
height: parseFloat(matchBoxSelector[6])
|
|
907
|
-
}
|
|
908
|
-
};
|
|
909
|
-
return {
|
|
910
|
-
selector,
|
|
911
|
-
selectors: [selector]
|
|
912
|
-
};
|
|
913
|
-
}
|
|
914
|
-
const matchTimeSelector = source.value.match(TEMPORAL_SELECTOR);
|
|
915
|
-
if (matchTimeSelector) {
|
|
916
|
-
const selector = {
|
|
917
|
-
type: "TemporalSelector",
|
|
918
|
-
temporal: {
|
|
919
|
-
startTime: matchTimeSelector[4] ? parseFloat(matchTimeSelector[4]) : 0,
|
|
920
|
-
endTime: matchTimeSelector[7] ? parseFloat(matchTimeSelector[7]) : void 0
|
|
921
|
-
}
|
|
922
|
-
};
|
|
923
|
-
return {
|
|
924
|
-
selector,
|
|
925
|
-
selectors: [selector]
|
|
926
|
-
};
|
|
927
|
-
}
|
|
928
|
-
return {
|
|
929
|
-
selector: null,
|
|
930
|
-
selectors: []
|
|
931
|
-
};
|
|
932
|
-
}
|
|
933
|
-
return {
|
|
934
|
-
selector: null,
|
|
935
|
-
selectors: []
|
|
936
|
-
};
|
|
937
|
-
}
|
|
938
|
-
|
|
939
|
-
var __defProp$7 = Object.defineProperty;
|
|
940
|
-
var __defProps$5 = Object.defineProperties;
|
|
941
|
-
var __getOwnPropDescs$5 = Object.getOwnPropertyDescriptors;
|
|
942
|
-
var __getOwnPropSymbols$7 = Object.getOwnPropertySymbols;
|
|
943
|
-
var __hasOwnProp$7 = Object.prototype.hasOwnProperty;
|
|
944
|
-
var __propIsEnum$7 = Object.prototype.propertyIsEnumerable;
|
|
945
|
-
var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
946
|
-
var __spreadValues$7 = (a, b) => {
|
|
947
|
-
for (var prop in b || (b = {}))
|
|
948
|
-
if (__hasOwnProp$7.call(b, prop))
|
|
949
|
-
__defNormalProp$7(a, prop, b[prop]);
|
|
950
|
-
if (__getOwnPropSymbols$7)
|
|
951
|
-
for (var prop of __getOwnPropSymbols$7(b)) {
|
|
952
|
-
if (__propIsEnum$7.call(b, prop))
|
|
953
|
-
__defNormalProp$7(a, prop, b[prop]);
|
|
954
|
-
}
|
|
955
|
-
return a;
|
|
956
|
-
};
|
|
957
|
-
var __spreadProps$5 = (a, b) => __defProps$5(a, __getOwnPropDescs$5(b));
|
|
958
|
-
function expandTarget(target, options = {}) {
|
|
959
|
-
if (Array.isArray(target)) {
|
|
960
|
-
return expandTarget(target[0]);
|
|
961
|
-
}
|
|
962
|
-
if (typeof target === "string") {
|
|
963
|
-
const [id, fragment] = target.split("#");
|
|
964
|
-
if (!fragment) {
|
|
965
|
-
return {
|
|
966
|
-
type: "SpecificResource",
|
|
967
|
-
source: { id, type: options.typeMap && options.typeMap[id] || "Unknown" },
|
|
968
|
-
selector: null,
|
|
969
|
-
selectors: []
|
|
970
|
-
};
|
|
971
|
-
}
|
|
972
|
-
return expandTarget({
|
|
973
|
-
type: "SpecificResource",
|
|
974
|
-
source: { id, type: "Unknown" },
|
|
975
|
-
selector: {
|
|
976
|
-
type: "FragmentSelector",
|
|
977
|
-
value: fragment
|
|
978
|
-
}
|
|
979
|
-
});
|
|
980
|
-
}
|
|
981
|
-
if (target.type === "Choice" || target.type === "List" || target.type === "Composite" || target.type === "Independents") {
|
|
982
|
-
return expandTarget(target.items[0]);
|
|
983
|
-
}
|
|
984
|
-
if (target.type === "SpecificResource") {
|
|
985
|
-
if (target.source.type === "Canvas" && target.source.partOf && typeof target.source.partOf === "string") {
|
|
986
|
-
target.source.partOf = [
|
|
987
|
-
{
|
|
988
|
-
id: target.source.partOf,
|
|
989
|
-
type: "Manifest"
|
|
990
|
-
}
|
|
991
|
-
];
|
|
992
|
-
}
|
|
993
|
-
const { selector, selectors } = target.selector ? parseSelector(target.selector) : { selector: null, selectors: [] };
|
|
994
|
-
return {
|
|
995
|
-
type: "SpecificResource",
|
|
996
|
-
source: target.source,
|
|
997
|
-
selector,
|
|
998
|
-
selectors
|
|
999
|
-
};
|
|
1000
|
-
}
|
|
1001
|
-
if (target.id) {
|
|
1002
|
-
if (target.type === "Canvas" && target.partOf && typeof target.partOf === "string") {
|
|
1003
|
-
target.partOf = [
|
|
1004
|
-
{
|
|
1005
|
-
id: target.partOf,
|
|
1006
|
-
type: "Manifest"
|
|
1007
|
-
}
|
|
1008
|
-
];
|
|
1009
|
-
}
|
|
1010
|
-
const [id, fragment] = target.id.split("#");
|
|
1011
|
-
if (!fragment) {
|
|
1012
|
-
return {
|
|
1013
|
-
type: "SpecificResource",
|
|
1014
|
-
source: __spreadProps$5(__spreadValues$7({}, target), {
|
|
1015
|
-
id
|
|
1016
|
-
}),
|
|
1017
|
-
selector: null,
|
|
1018
|
-
selectors: []
|
|
1019
|
-
};
|
|
1020
|
-
}
|
|
1021
|
-
return expandTarget({
|
|
1022
|
-
type: "SpecificResource",
|
|
1023
|
-
source: __spreadProps$5(__spreadValues$7({}, target), {
|
|
1024
|
-
id
|
|
1025
|
-
}),
|
|
1026
|
-
selector: {
|
|
1027
|
-
type: "FragmentSelector",
|
|
1028
|
-
value: fragment
|
|
1029
|
-
}
|
|
1030
|
-
});
|
|
1031
|
-
}
|
|
1032
|
-
return {
|
|
1033
|
-
type: "SpecificResource",
|
|
1034
|
-
source: target,
|
|
1035
|
-
selector: null,
|
|
1036
|
-
selectors: []
|
|
1037
|
-
};
|
|
1038
|
-
}
|
|
1039
|
-
|
|
1040
|
-
var __defProp$6 = Object.defineProperty;
|
|
1041
|
-
var __defProps$4 = Object.defineProperties;
|
|
1042
|
-
var __getOwnPropDescs$4 = Object.getOwnPropertyDescriptors;
|
|
1043
|
-
var __getOwnPropSymbols$6 = Object.getOwnPropertySymbols;
|
|
1044
|
-
var __hasOwnProp$6 = Object.prototype.hasOwnProperty;
|
|
1045
|
-
var __propIsEnum$6 = Object.prototype.propertyIsEnumerable;
|
|
1046
|
-
var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1047
|
-
var __spreadValues$6 = (a, b) => {
|
|
1048
|
-
for (var prop in b || (b = {}))
|
|
1049
|
-
if (__hasOwnProp$6.call(b, prop))
|
|
1050
|
-
__defNormalProp$6(a, prop, b[prop]);
|
|
1051
|
-
if (__getOwnPropSymbols$6)
|
|
1052
|
-
for (var prop of __getOwnPropSymbols$6(b)) {
|
|
1053
|
-
if (__propIsEnum$6.call(b, prop))
|
|
1054
|
-
__defNormalProp$6(a, prop, b[prop]);
|
|
1055
|
-
}
|
|
1056
|
-
return a;
|
|
1057
|
-
};
|
|
1058
|
-
var __spreadProps$4 = (a, b) => __defProps$4(a, __getOwnPropDescs$4(b));
|
|
1059
|
-
function useAnnotation(options = {}, deps = []) {
|
|
1060
|
-
const { id, selector } = options;
|
|
1061
|
-
const ctx = useResourceContext();
|
|
1062
|
-
const vault = useVault();
|
|
1063
|
-
const annotationId = id ? id : ctx.annotation;
|
|
1064
|
-
const annotation = useVaultSelector((s) => annotationId ? s.iiif.entities.Annotation[annotationId] : void 0, [annotationId]);
|
|
1065
|
-
const body = useVaultSelector((s) => annotation && annotation.body ? annotation.body.map((singleBody) => singleBody ? s.iiif.entities[singleBody.type][singleBody.id] : null).filter(Boolean) : [], [annotation]);
|
|
1066
|
-
return React$1.useMemo(() => {
|
|
1067
|
-
if (!annotation) {
|
|
1068
|
-
return void 0;
|
|
1069
|
-
}
|
|
1070
|
-
const newAnnotation = __spreadProps$4(__spreadValues$6({}, annotation), {
|
|
1071
|
-
body,
|
|
1072
|
-
target: expandTarget(annotation.target, { typeMap: vault.getState().iiif.mapping })
|
|
1073
|
-
});
|
|
1074
|
-
if (selector) {
|
|
1075
|
-
return selector(newAnnotation);
|
|
1076
|
-
}
|
|
1077
|
-
return newAnnotation;
|
|
1078
|
-
}, [annotation, selector, body, ...deps]);
|
|
1079
|
-
}
|
|
1080
|
-
|
|
1081
|
-
function useCanvas(options = {}, deps = []) {
|
|
1082
|
-
const { id, selector } = options;
|
|
1083
|
-
const ctx = useResourceContext();
|
|
1084
|
-
const canvasId = id ? id : ctx.canvas;
|
|
1085
|
-
const canvas = useVaultSelector((s) => canvasId ? s.iiif.entities.Canvas[canvasId] : void 0, [canvasId]);
|
|
1086
|
-
return React$1.useMemo(() => {
|
|
1087
|
-
if (!canvas) {
|
|
1088
|
-
return void 0;
|
|
1089
|
-
}
|
|
1090
|
-
if (selector) {
|
|
1091
|
-
return selector(canvas);
|
|
1092
|
-
}
|
|
1093
|
-
return canvas;
|
|
1094
|
-
}, [canvas, selector, ...deps]);
|
|
1095
|
-
}
|
|
1096
|
-
|
|
1097
|
-
var __defProp$5 = Object.defineProperty;
|
|
1098
|
-
var __getOwnPropSymbols$5 = Object.getOwnPropertySymbols;
|
|
1099
|
-
var __hasOwnProp$5 = Object.prototype.hasOwnProperty;
|
|
1100
|
-
var __propIsEnum$5 = Object.prototype.propertyIsEnumerable;
|
|
1101
|
-
var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1102
|
-
var __spreadValues$5 = (a, b) => {
|
|
1103
|
-
for (var prop in b || (b = {}))
|
|
1104
|
-
if (__hasOwnProp$5.call(b, prop))
|
|
1105
|
-
__defNormalProp$5(a, prop, b[prop]);
|
|
1106
|
-
if (__getOwnPropSymbols$5)
|
|
1107
|
-
for (var prop of __getOwnPropSymbols$5(b)) {
|
|
1108
|
-
if (__propIsEnum$5.call(b, prop))
|
|
1109
|
-
__defNormalProp$5(a, prop, b[prop]);
|
|
1110
|
-
}
|
|
1111
|
-
return a;
|
|
1112
|
-
};
|
|
1113
|
-
const RenderAnnotation = ({
|
|
1114
|
-
id,
|
|
1115
|
-
style: defaultStyle,
|
|
1116
|
-
className,
|
|
1117
|
-
interactive
|
|
1118
|
-
}) => {
|
|
1119
|
-
const annotation = useAnnotation({ id });
|
|
1120
|
-
const style = useStyles(annotation, "atlas");
|
|
1121
|
-
const html = useStyles(annotation, "html");
|
|
1122
|
-
const events = useResourceEvents(annotation, ["atlas"]);
|
|
1123
|
-
const canvas = useCanvas();
|
|
1124
|
-
const allStyles = React$1.useMemo(() => {
|
|
1125
|
-
return atlas.mergeStyles(defaultStyle, style);
|
|
1126
|
-
}, [defaultStyle, style]);
|
|
1127
|
-
const isValid = canvas && annotation && annotation.target && annotation.target.selector && annotation.target.selector.type === "BoxSelector" && annotation.target.source && annotation.target.source.id === canvas.id;
|
|
1128
|
-
if (!isValid) {
|
|
1129
|
-
return null;
|
|
1130
|
-
}
|
|
1131
|
-
return /* @__PURE__ */ React__default["default"].createElement(atlas.RegionHighlight, __spreadValues$5({
|
|
1132
|
-
id: annotation.id,
|
|
1133
|
-
isEditing: true,
|
|
1134
|
-
region: annotation.target.selector.spatial,
|
|
1135
|
-
style: allStyles,
|
|
1136
|
-
className: (html == null ? void 0 : html.className) || className,
|
|
1137
|
-
interactive: !!((html == null ? void 0 : html.href) || interactive),
|
|
1138
|
-
href: (html == null ? void 0 : html.href) || null,
|
|
1139
|
-
title: (html == null ? void 0 : html.title) || null,
|
|
1140
|
-
hrefTarget: (html == null ? void 0 : html.target) || null
|
|
1141
|
-
}, events));
|
|
1142
|
-
};
|
|
1143
|
-
|
|
1144
|
-
const RenderAnnotationPage = ({
|
|
1145
|
-
className,
|
|
1146
|
-
page
|
|
1147
|
-
}) => {
|
|
1148
|
-
var _a;
|
|
1149
|
-
const style = useStyles(page, "atlas");
|
|
1150
|
-
const html = useStyles(page, "html");
|
|
1151
|
-
useVaultSelector((state) => page.id ? state.iiif.entities.AnnotationPage[page.id] : null, []);
|
|
1152
|
-
return /* @__PURE__ */ React__default["default"].createElement(React$1.Fragment, null, (_a = page.items) == null ? void 0 : _a.map((annotation) => {
|
|
1153
|
-
return /* @__PURE__ */ React__default["default"].createElement(RenderAnnotation, {
|
|
1154
|
-
key: annotation.id,
|
|
1155
|
-
id: annotation.id,
|
|
1156
|
-
style,
|
|
1157
|
-
className: (html == null ? void 0 : html.className) || className
|
|
1158
|
-
});
|
|
1159
|
-
}));
|
|
1160
|
-
};
|
|
1161
|
-
|
|
1162
|
-
const TileSet = atlas.TileSet;
|
|
1163
|
-
function RenderImage({
|
|
1164
|
-
id,
|
|
1165
|
-
image,
|
|
1166
|
-
thumbnail,
|
|
1167
|
-
isStatic,
|
|
1168
|
-
x = 0,
|
|
1169
|
-
y = 0,
|
|
1170
|
-
annotations,
|
|
1171
|
-
children
|
|
1172
|
-
}) {
|
|
1173
|
-
var _a, _b, _c, _d;
|
|
1174
|
-
return /* @__PURE__ */ React__default["default"].createElement(React$1.Fragment, {
|
|
1175
|
-
key: id
|
|
1176
|
-
}, !image.service ? /* @__PURE__ */ React__default["default"].createElement(React$1.Fragment, {
|
|
1177
|
-
key: "no-service"
|
|
1178
|
-
}, /* @__PURE__ */ React__default["default"].createElement("world-image", {
|
|
1179
|
-
uri: image.id,
|
|
1180
|
-
target: image.target.spatial,
|
|
1181
|
-
display: image.width && image.height ? {
|
|
1182
|
-
width: image.width,
|
|
1183
|
-
height: image.height
|
|
1184
|
-
} : void 0
|
|
1185
|
-
}), annotations, children) : /* @__PURE__ */ React__default["default"].createElement(React$1.Fragment, {
|
|
1186
|
-
key: "service"
|
|
1187
|
-
}, /* @__PURE__ */ React__default["default"].createElement(TileSet, {
|
|
1188
|
-
viewport: isStatic,
|
|
1189
|
-
tiles: {
|
|
1190
|
-
id: image.service.id || image.service["@id"],
|
|
1191
|
-
height: image.height,
|
|
1192
|
-
width: image.width,
|
|
1193
|
-
imageService: image.service,
|
|
1194
|
-
thumbnail: thumbnail && thumbnail.type === "fixed" ? thumbnail : void 0
|
|
1195
|
-
},
|
|
1196
|
-
x: ((_a = image.target) == null ? void 0 : _a.spatial.x) + x,
|
|
1197
|
-
y: ((_b = image.target) == null ? void 0 : _b.spatial.y) + y,
|
|
1198
|
-
width: (_c = image.target) == null ? void 0 : _c.spatial.width,
|
|
1199
|
-
height: (_d = image.target) == null ? void 0 : _d.spatial.height
|
|
1200
|
-
}), annotations, children));
|
|
1201
|
-
}
|
|
1202
|
-
|
|
1203
|
-
function parseSpecificResource(resource) {
|
|
1204
|
-
if (resource.type === "SpecificResource") {
|
|
1205
|
-
return [resource.source, { selector: resource.selector }];
|
|
1206
|
-
}
|
|
1207
|
-
return [resource, { selector: null }];
|
|
1208
|
-
}
|
|
1209
|
-
function getPaintables(vault, paintingAnnotations, enabledChoices) {
|
|
1210
|
-
const types = [];
|
|
1211
|
-
let choice = null;
|
|
1212
|
-
const items = [];
|
|
1213
|
-
for (const annotation of paintingAnnotations) {
|
|
1214
|
-
const bodies = vault.get(annotation.body);
|
|
1215
|
-
for (const unknownBody of bodies) {
|
|
1216
|
-
const [body, { selector }] = parseSpecificResource(unknownBody);
|
|
1217
|
-
const type = (body.type || "unknown").toLowerCase();
|
|
1218
|
-
if (type === "choice") {
|
|
1219
|
-
const nestedBodies = vault.get(body.items);
|
|
1220
|
-
const selected = enabledChoices.length ? enabledChoices.map((cid) => nestedBodies.find((b) => b.id === cid)).filter(Boolean) : [nestedBodies[0]];
|
|
1221
|
-
if (selected.length === 0) {
|
|
1222
|
-
selected.push(nestedBodies[0]);
|
|
1223
|
-
}
|
|
1224
|
-
choice = {
|
|
1225
|
-
type: "single-choice",
|
|
1226
|
-
items: nestedBodies.map((b) => ({
|
|
1227
|
-
id: b.id,
|
|
1228
|
-
label: b.label,
|
|
1229
|
-
selected: selected.indexOf(b) !== -1
|
|
1230
|
-
})),
|
|
1231
|
-
label: unknownBody.label
|
|
1232
|
-
};
|
|
1233
|
-
bodies.push(...selected);
|
|
1234
|
-
continue;
|
|
1235
|
-
}
|
|
1236
|
-
if (types.indexOf(type) === -1) {
|
|
1237
|
-
types.push(type);
|
|
1238
|
-
}
|
|
1239
|
-
items.push({
|
|
1240
|
-
type,
|
|
1241
|
-
resource: body,
|
|
1242
|
-
target: annotation.target,
|
|
1243
|
-
selector
|
|
1244
|
-
});
|
|
1245
|
-
}
|
|
1246
|
-
}
|
|
1247
|
-
return {
|
|
1248
|
-
types,
|
|
1249
|
-
items,
|
|
1250
|
-
choice
|
|
1251
|
-
};
|
|
1252
|
-
}
|
|
1253
|
-
const emptyActions = {
|
|
1254
|
-
makeChoice: () => {
|
|
1255
|
-
}
|
|
1256
|
-
};
|
|
1257
|
-
const unknownResponse = { type: "unknown" };
|
|
1258
|
-
const unsupportedStrategy = (reason) => {
|
|
1259
|
-
return { type: "unknown", reason, annotations: { pages: [] } };
|
|
1260
|
-
};
|
|
1261
|
-
|
|
1262
|
-
function useManifest(options = {}, deps = []) {
|
|
1263
|
-
const { id, selector } = options;
|
|
1264
|
-
const ctx = useResourceContext();
|
|
1265
|
-
useVault();
|
|
1266
|
-
const manifestId = id ? id : ctx.manifest;
|
|
1267
|
-
const manifest = useVaultSelector((s) => manifestId ? s.iiif.entities.Manifest[manifestId] : void 0, [manifestId]);
|
|
1268
|
-
return React$1.useMemo(() => {
|
|
1269
|
-
if (!manifest) {
|
|
1270
|
-
return void 0;
|
|
1271
|
-
}
|
|
1272
|
-
if (selector) {
|
|
1273
|
-
return selector(manifest);
|
|
1274
|
-
}
|
|
1275
|
-
return manifest;
|
|
1276
|
-
}, [manifest, selector, ...deps]);
|
|
1277
|
-
}
|
|
1278
|
-
|
|
1279
|
-
function getMeta$1(state, resourceId) {
|
|
1280
|
-
var _a;
|
|
1281
|
-
const resourceMeta = (_a = state == null ? void 0 : state.iiif) == null ? void 0 : _a.meta[resourceId];
|
|
1282
|
-
if (!resourceMeta) {
|
|
1283
|
-
return null;
|
|
1284
|
-
}
|
|
1285
|
-
return resourceMeta.annotationPageManager;
|
|
1286
|
-
}
|
|
1287
|
-
function useEnabledAnnotationPageIds(resourceId, availablePageIds) {
|
|
1288
|
-
return useVaultSelector((state) => {
|
|
1289
|
-
const pageIds = [];
|
|
1290
|
-
if (!resourceId) {
|
|
1291
|
-
return pageIds;
|
|
1292
|
-
}
|
|
1293
|
-
const allAnnotationListIds = Object.keys(state.iiif.entities.AnnotationPage);
|
|
1294
|
-
for (const annotationListId of allAnnotationListIds) {
|
|
1295
|
-
if (!availablePageIds || availablePageIds.indexOf(annotationListId) !== -1) {
|
|
1296
|
-
const annotationListMeta = getMeta$1(state, annotationListId);
|
|
1297
|
-
if (annotationListMeta && annotationListMeta.views && annotationListMeta.views[resourceId]) {
|
|
1298
|
-
pageIds.push(annotationListId);
|
|
1299
|
-
}
|
|
1300
|
-
}
|
|
1301
|
-
}
|
|
1302
|
-
return pageIds;
|
|
1303
|
-
}, [resourceId, availablePageIds]);
|
|
1304
|
-
}
|
|
1305
|
-
|
|
1306
|
-
function flattenAnnotationPageIds({
|
|
1307
|
-
canvas,
|
|
1308
|
-
manifest,
|
|
1309
|
-
all,
|
|
1310
|
-
canvases
|
|
1311
|
-
}) {
|
|
1312
|
-
const foundIds = [];
|
|
1313
|
-
if (manifest) {
|
|
1314
|
-
for (const page of manifest.annotations) {
|
|
1315
|
-
if (foundIds.indexOf(page.id) === -1) {
|
|
1316
|
-
foundIds.push(page.id);
|
|
1317
|
-
}
|
|
1318
|
-
}
|
|
1319
|
-
}
|
|
1320
|
-
if (all) {
|
|
1321
|
-
if (canvases && canvases.length) {
|
|
1322
|
-
for (const canvas_ of canvases) {
|
|
1323
|
-
for (const page of canvas_.annotations) {
|
|
1324
|
-
if (foundIds.indexOf(page.id) === -1) {
|
|
1325
|
-
foundIds.push(page.id);
|
|
1326
|
-
}
|
|
1327
|
-
}
|
|
1328
|
-
}
|
|
1329
|
-
}
|
|
1330
|
-
} else if (canvas) {
|
|
1331
|
-
for (const page of canvas.annotations) {
|
|
1332
|
-
if (foundIds.indexOf(page.id) === -1) {
|
|
1333
|
-
foundIds.push(page.id);
|
|
1334
|
-
}
|
|
1335
|
-
}
|
|
1336
|
-
}
|
|
1337
|
-
return foundIds;
|
|
1338
|
-
}
|
|
1339
|
-
|
|
1340
|
-
var __defProp$4 = Object.defineProperty;
|
|
1341
|
-
var __defProps$3 = Object.defineProperties;
|
|
1342
|
-
var __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors;
|
|
1343
|
-
var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
|
|
1344
|
-
var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
|
|
1345
|
-
var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
|
|
1346
|
-
var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1347
|
-
var __spreadValues$4 = (a, b) => {
|
|
1348
|
-
for (var prop in b || (b = {}))
|
|
1349
|
-
if (__hasOwnProp$4.call(b, prop))
|
|
1350
|
-
__defNormalProp$4(a, prop, b[prop]);
|
|
1351
|
-
if (__getOwnPropSymbols$4)
|
|
1352
|
-
for (var prop of __getOwnPropSymbols$4(b)) {
|
|
1353
|
-
if (__propIsEnum$4.call(b, prop))
|
|
1354
|
-
__defNormalProp$4(a, prop, b[prop]);
|
|
1355
|
-
}
|
|
1356
|
-
return a;
|
|
1357
|
-
};
|
|
1358
|
-
var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b));
|
|
1359
|
-
function getMeta(state, resourceId) {
|
|
1360
|
-
var _a;
|
|
1361
|
-
const resourceMeta = (_a = state == null ? void 0 : state.iiif) == null ? void 0 : _a.meta[resourceId];
|
|
1362
|
-
if (!resourceMeta) {
|
|
1363
|
-
return null;
|
|
1364
|
-
}
|
|
1365
|
-
return resourceMeta.annotationPageManager;
|
|
1366
|
-
}
|
|
1367
|
-
function useAnnotationPageManager(resourceId, options = {}) {
|
|
1368
|
-
const vault = useVault();
|
|
1369
|
-
const manifest = useManifest();
|
|
1370
|
-
const canvas = useCanvas();
|
|
1371
|
-
const canvases = useVisibleCanvases();
|
|
1372
|
-
const availablePageIds = React$1.useMemo(() => {
|
|
1373
|
-
return flattenAnnotationPageIds({
|
|
1374
|
-
all: options.all,
|
|
1375
|
-
manifest,
|
|
1376
|
-
canvas,
|
|
1377
|
-
canvases
|
|
1378
|
-
});
|
|
1379
|
-
}, [options.all, canvas, canvases, manifest]);
|
|
1380
|
-
const enabledPageIds = useEnabledAnnotationPageIds(resourceId, options.all ? void 0 : availablePageIds);
|
|
1381
|
-
const setPageDisabled = React$1.useCallback((deselectId) => {
|
|
1382
|
-
if (!resourceId) {
|
|
1383
|
-
return;
|
|
1384
|
-
}
|
|
1385
|
-
vault.setMetaValue([deselectId, "annotationPageManager", "views"], (existingResources) => {
|
|
1386
|
-
if (existingResources && !existingResources[resourceId]) {
|
|
1387
|
-
return existingResources;
|
|
1388
|
-
}
|
|
1389
|
-
return __spreadProps$3(__spreadValues$4({}, existingResources || {}), {
|
|
1390
|
-
[resourceId]: false
|
|
1391
|
-
});
|
|
1392
|
-
});
|
|
1393
|
-
}, [resourceId, vault]);
|
|
1394
|
-
const setPageEnabled = React$1.useCallback((id, opt = {}) => {
|
|
1395
|
-
if (!resourceId) {
|
|
1396
|
-
return;
|
|
1397
|
-
}
|
|
1398
|
-
const state = vault.getState();
|
|
1399
|
-
const toDeselect = [];
|
|
1400
|
-
if (opt == null ? void 0 : opt.deselectOthers) {
|
|
1401
|
-
const allAnnotationListIds = Object.keys(state.iiif.entities.AnnotationPage);
|
|
1402
|
-
for (const annotationPageId of allAnnotationListIds) {
|
|
1403
|
-
const annotationListMeta = getMeta(state, annotationPageId);
|
|
1404
|
-
if (annotationListMeta && annotationListMeta.views && annotationListMeta.views[resourceId]) {
|
|
1405
|
-
toDeselect.push(annotationPageId);
|
|
1406
|
-
}
|
|
1407
|
-
}
|
|
1408
|
-
}
|
|
1409
|
-
for (const deselectId of toDeselect) {
|
|
1410
|
-
setPageDisabled(deselectId);
|
|
1411
|
-
}
|
|
1412
|
-
vault.setMetaValue([id, "annotationPageManager", "views"], (existingResources) => {
|
|
1413
|
-
if (existingResources && existingResources[resourceId]) {
|
|
1414
|
-
return existingResources;
|
|
1415
|
-
}
|
|
1416
|
-
return __spreadProps$3(__spreadValues$4({}, existingResources || {}), {
|
|
1417
|
-
[resourceId]: true
|
|
1418
|
-
});
|
|
1419
|
-
});
|
|
1420
|
-
}, [resourceId, setPageDisabled, vault]);
|
|
1421
|
-
return {
|
|
1422
|
-
availablePageIds,
|
|
1423
|
-
enabledPageIds,
|
|
1424
|
-
setPageEnabled,
|
|
1425
|
-
setPageDisabled
|
|
1426
|
-
};
|
|
1427
|
-
}
|
|
1428
|
-
|
|
1429
|
-
function useResources(ids, type) {
|
|
1430
|
-
return useVaultSelector((state, vault) => vault.get(ids.map((id) => ({ id, type }))), [ids, type]);
|
|
1431
|
-
}
|
|
1432
|
-
|
|
1433
|
-
const ImageServiceLoaderContext = React__default["default"].createContext(new iiifImageApi.ImageServiceLoader());
|
|
1434
|
-
function useImageServiceLoader() {
|
|
1435
|
-
return React$1.useContext(ImageServiceLoaderContext);
|
|
1436
|
-
}
|
|
1437
|
-
|
|
1438
|
-
var __defProp$3 = Object.defineProperty;
|
|
1439
|
-
var __defProps$2 = Object.defineProperties;
|
|
1440
|
-
var __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors;
|
|
1441
|
-
var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
|
|
1442
|
-
var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
|
|
1443
|
-
var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
|
|
1444
|
-
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1445
|
-
var __spreadValues$3 = (a, b) => {
|
|
1446
|
-
for (var prop in b || (b = {}))
|
|
1447
|
-
if (__hasOwnProp$3.call(b, prop))
|
|
1448
|
-
__defNormalProp$3(a, prop, b[prop]);
|
|
1449
|
-
if (__getOwnPropSymbols$3)
|
|
1450
|
-
for (var prop of __getOwnPropSymbols$3(b)) {
|
|
1451
|
-
if (__propIsEnum$3.call(b, prop))
|
|
1452
|
-
__defNormalProp$3(a, prop, b[prop]);
|
|
1453
|
-
}
|
|
1454
|
-
return a;
|
|
1455
|
-
};
|
|
1456
|
-
var __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
|
|
1457
|
-
function useLoadImageService() {
|
|
1458
|
-
const loader = useImageServiceLoader();
|
|
1459
|
-
const [imageServiceStatus, setImageServiceStatus] = React$1.useState({});
|
|
1460
|
-
const didUnmount = React$1.useRef(false);
|
|
1461
|
-
React$1.useEffect(() => {
|
|
1462
|
-
return () => {
|
|
1463
|
-
didUnmount.current = true;
|
|
1464
|
-
};
|
|
1465
|
-
}, []);
|
|
1466
|
-
const loadImageService = React$1.useCallback((imageService, { height, width }) => {
|
|
1467
|
-
if (imageService) {
|
|
1468
|
-
const imageServiceId = imageService.id || imageService["@id"];
|
|
1469
|
-
const syncLoaded = loader.loadServiceSync({
|
|
1470
|
-
id: imageServiceId,
|
|
1471
|
-
width: imageService.width || width,
|
|
1472
|
-
height: imageService.height || height,
|
|
1473
|
-
source: imageService
|
|
1474
|
-
});
|
|
1475
|
-
if (syncLoaded) {
|
|
1476
|
-
imageService = syncLoaded;
|
|
1477
|
-
} else if (!imageServiceStatus[imageServiceId]) {
|
|
1478
|
-
if (!didUnmount.current) {
|
|
1479
|
-
setImageServiceStatus((r) => {
|
|
1480
|
-
return __spreadProps$2(__spreadValues$3({}, r), {
|
|
1481
|
-
[imageServiceId]: "loading"
|
|
1482
|
-
});
|
|
1483
|
-
});
|
|
1484
|
-
}
|
|
1485
|
-
loader.loadService({
|
|
1486
|
-
id: imageServiceId,
|
|
1487
|
-
width: imageService.width || width,
|
|
1488
|
-
height: imageService.height || height
|
|
1489
|
-
}).then(() => {
|
|
1490
|
-
if (!didUnmount.current) {
|
|
1491
|
-
setImageServiceStatus((r) => {
|
|
1492
|
-
return __spreadProps$2(__spreadValues$3({}, r), {
|
|
1493
|
-
[imageServiceId]: "done"
|
|
1494
|
-
});
|
|
1495
|
-
});
|
|
1496
|
-
}
|
|
1497
|
-
});
|
|
1498
|
-
}
|
|
1499
|
-
}
|
|
1500
|
-
return imageService;
|
|
1501
|
-
}, [loader, imageServiceStatus]);
|
|
1502
|
-
return [loadImageService, imageServiceStatus];
|
|
1503
|
-
}
|
|
1504
|
-
|
|
1505
|
-
function usePaintingAnnotations(options = {}) {
|
|
1506
|
-
const canvas = useCanvas(options.canvasId ? { id: options.canvasId } : void 0);
|
|
1507
|
-
return useVaultSelector((state, vault) => {
|
|
1508
|
-
if (!canvas) {
|
|
1509
|
-
return [];
|
|
1510
|
-
}
|
|
1511
|
-
const annotationPages = vault.get(canvas.items);
|
|
1512
|
-
const flatAnnotations = [];
|
|
1513
|
-
for (const page of annotationPages) {
|
|
1514
|
-
flatAnnotations.push(...vault.get(page.items));
|
|
1515
|
-
}
|
|
1516
|
-
return flatAnnotations;
|
|
1517
|
-
}, [canvas]);
|
|
1518
|
-
}
|
|
1519
|
-
|
|
1520
|
-
function usePaintables(options, deps = []) {
|
|
1521
|
-
const vault = useVault();
|
|
1522
|
-
const paintingAnnotations = usePaintingAnnotations();
|
|
1523
|
-
const [enabledChoices, setEnabledChoices] = React$1.useState((options == null ? void 0 : options.defaultChoices) || []);
|
|
1524
|
-
const paintables = React$1.useMemo(() => getPaintables(vault, paintingAnnotations, enabledChoices), [vault, paintingAnnotations, enabledChoices, ...deps]);
|
|
1525
|
-
const makeChoice = React$1.useCallback((id, { deselectOthers = true, deselect = false } = {}) => {
|
|
1526
|
-
if (paintables.choice) {
|
|
1527
|
-
if (paintables.choice.type !== "single-choice") {
|
|
1528
|
-
throw new Error("Complex choice not supported yet");
|
|
1529
|
-
}
|
|
1530
|
-
setEnabledChoices((prevChoices) => {
|
|
1531
|
-
if (deselect) {
|
|
1532
|
-
const without = prevChoices.filter((e) => e !== id);
|
|
1533
|
-
if (without.length === 0) {
|
|
1534
|
-
const defaultId = paintables.items[0].resource.id;
|
|
1535
|
-
if (defaultId) {
|
|
1536
|
-
return [defaultId];
|
|
1537
|
-
} else {
|
|
1538
|
-
return [];
|
|
1539
|
-
}
|
|
1540
|
-
}
|
|
1541
|
-
return without;
|
|
1542
|
-
}
|
|
1543
|
-
if (deselectOthers) {
|
|
1544
|
-
return [id];
|
|
1545
|
-
}
|
|
1546
|
-
const newChoices = [...prevChoices];
|
|
1547
|
-
if (newChoices.length === 0 && paintables.items.length) {
|
|
1548
|
-
const defaultId = paintables.items[0].resource.id;
|
|
1549
|
-
if (defaultId) {
|
|
1550
|
-
newChoices.push(defaultId);
|
|
1551
|
-
}
|
|
1552
|
-
}
|
|
1553
|
-
if (prevChoices.indexOf(id) !== -1) {
|
|
1554
|
-
return prevChoices;
|
|
1555
|
-
}
|
|
1556
|
-
return [...prevChoices, id];
|
|
1557
|
-
});
|
|
1558
|
-
}
|
|
1559
|
-
}, [paintables.choice]);
|
|
1560
|
-
const actions = { makeChoice };
|
|
1561
|
-
return [paintables, actions];
|
|
1562
|
-
}
|
|
1563
|
-
|
|
1564
|
-
function getImageStrategy(canvas, paintables, loadImageService) {
|
|
1565
|
-
const imageTypes = [];
|
|
1566
|
-
for (const singleImage of paintables.items) {
|
|
1567
|
-
const resource = singleImage.resource && singleImage.resource.type === "SpecificResource" ? singleImage.resource.source : singleImage.resource;
|
|
1568
|
-
if (!resource.id) {
|
|
1569
|
-
return unsupportedStrategy("No resource Identifier");
|
|
1570
|
-
}
|
|
1571
|
-
let imageService = void 0;
|
|
1572
|
-
if (resource.service) {
|
|
1573
|
-
const imageServices = iiifImageApi.getImageServices(resource);
|
|
1574
|
-
if (imageServices[0]) {
|
|
1575
|
-
imageService = loadImageService(imageServices[0], canvas);
|
|
1576
|
-
}
|
|
1577
|
-
}
|
|
1578
|
-
const { selector: imageTarget, source } = expandTarget(singleImage.target);
|
|
1579
|
-
if (source.id !== canvas.id) {
|
|
1580
|
-
continue;
|
|
1581
|
-
}
|
|
1582
|
-
const defaultTarget = {
|
|
1583
|
-
type: "BoxSelector",
|
|
1584
|
-
spatial: {
|
|
1585
|
-
x: 0,
|
|
1586
|
-
y: 0,
|
|
1587
|
-
width: canvas.width,
|
|
1588
|
-
height: canvas.height
|
|
1589
|
-
}
|
|
1590
|
-
};
|
|
1591
|
-
const target = imageTarget ? imageTarget.type === "TemporalSelector" ? {
|
|
1592
|
-
type: "TemporalBoxSelector",
|
|
1593
|
-
temporal: imageTarget.temporal,
|
|
1594
|
-
spatial: defaultTarget.spatial
|
|
1595
|
-
} : imageTarget : null;
|
|
1596
|
-
const defaultImageSelector = {
|
|
1597
|
-
type: "BoxSelector",
|
|
1598
|
-
spatial: {
|
|
1599
|
-
x: 0,
|
|
1600
|
-
y: 0,
|
|
1601
|
-
width: canvas.width,
|
|
1602
|
-
height: canvas.height
|
|
1603
|
-
}
|
|
1604
|
-
};
|
|
1605
|
-
const imageSelector = singleImage.resource.type === "SpecificResource" ? expandTarget(singleImage.resource) : null;
|
|
1606
|
-
const selector = imageSelector && imageSelector.selector && (imageSelector.selector.type === "BoxSelector" || imageSelector.selector.type === "TemporalBoxSelector") ? {
|
|
1607
|
-
type: "BoxSelector",
|
|
1608
|
-
spatial: {
|
|
1609
|
-
x: imageSelector.selector.spatial.x,
|
|
1610
|
-
y: imageSelector.selector.spatial.y,
|
|
1611
|
-
width: imageSelector.selector.spatial.width,
|
|
1612
|
-
height: imageSelector.selector.spatial.height
|
|
1613
|
-
}
|
|
1614
|
-
} : defaultImageSelector;
|
|
1615
|
-
if (imageService && !imageService.id) {
|
|
1616
|
-
imageService.id = imageService["@id"];
|
|
1617
|
-
}
|
|
1618
|
-
const imageType = {
|
|
1619
|
-
id: resource.id,
|
|
1620
|
-
type: "Image",
|
|
1621
|
-
width: target ? resource.width : canvas.width,
|
|
1622
|
-
height: target ? resource.height : canvas.height,
|
|
1623
|
-
service: imageService,
|
|
1624
|
-
sizes: imageService && imageService.sizes ? imageService.sizes : resource.width && resource.height ? [{ width: resource.width, height: resource.height }] : [],
|
|
1625
|
-
target: target && target.type !== "PointSelector" ? target : defaultTarget,
|
|
1626
|
-
selector
|
|
1627
|
-
};
|
|
1628
|
-
imageTypes.push(imageType);
|
|
1629
|
-
}
|
|
1630
|
-
return {
|
|
1631
|
-
type: "images",
|
|
1632
|
-
image: imageTypes[0],
|
|
1633
|
-
images: imageTypes,
|
|
1634
|
-
choice: paintables.choice
|
|
1635
|
-
};
|
|
1636
|
-
}
|
|
1637
|
-
|
|
1638
|
-
const supportedFormats = ["model/gltf-binary"];
|
|
1639
|
-
function get3dStrategy(canvas, paintables) {
|
|
1640
|
-
const first = paintables.items[0];
|
|
1641
|
-
const resource = first.resource;
|
|
1642
|
-
if (!resource.format) {
|
|
1643
|
-
return unsupportedStrategy("Unknown format");
|
|
1644
|
-
}
|
|
1645
|
-
if (supportedFormats.indexOf(resource.format) === -1) {
|
|
1646
|
-
return unsupportedStrategy(`3D format: ${resource.format} is unsupported`);
|
|
1647
|
-
}
|
|
1648
|
-
return {
|
|
1649
|
-
type: "3d-model",
|
|
1650
|
-
model: resource
|
|
1651
|
-
};
|
|
1652
|
-
}
|
|
1653
|
-
|
|
1654
|
-
function getAudioStrategy(canvas, paintables) {
|
|
1655
|
-
var _a;
|
|
1656
|
-
if (!canvas.duration) {
|
|
1657
|
-
return unsupportedStrategy("No duration on canvas");
|
|
1658
|
-
}
|
|
1659
|
-
if (paintables.items.length > 1) {
|
|
1660
|
-
return unsupportedStrategy("Only one audio source supported");
|
|
1661
|
-
}
|
|
1662
|
-
const audioResource = (_a = paintables.items[0]) == null ? void 0 : _a.resource;
|
|
1663
|
-
if (!audioResource) {
|
|
1664
|
-
return unsupportedStrategy("Unknown audio");
|
|
1665
|
-
}
|
|
1666
|
-
if (!audioResource.format) {
|
|
1667
|
-
return unsupportedStrategy("Audio does not have format");
|
|
1668
|
-
}
|
|
1669
|
-
return {
|
|
1670
|
-
type: "media",
|
|
1671
|
-
media: {
|
|
1672
|
-
duration: canvas.duration,
|
|
1673
|
-
url: audioResource.id,
|
|
1674
|
-
type: "Sound",
|
|
1675
|
-
target: {
|
|
1676
|
-
type: "TemporalSelector",
|
|
1677
|
-
temporal: {
|
|
1678
|
-
startTime: 0,
|
|
1679
|
-
endTime: canvas.duration
|
|
1680
|
-
}
|
|
1681
|
-
},
|
|
1682
|
-
format: audioResource.format,
|
|
1683
|
-
selector: {
|
|
1684
|
-
type: "TemporalSelector",
|
|
1685
|
-
temporal: {
|
|
1686
|
-
startTime: 0,
|
|
1687
|
-
endTime: canvas.duration
|
|
1688
|
-
}
|
|
1689
|
-
}
|
|
1690
|
-
},
|
|
1691
|
-
annotations: {
|
|
1692
|
-
pages: []
|
|
1693
|
-
}
|
|
1694
|
-
};
|
|
1695
|
-
}
|
|
1696
|
-
|
|
1697
|
-
function getVideoStrategy(canvas, paintables) {
|
|
1698
|
-
var _a;
|
|
1699
|
-
const videoPaintables = paintables.items.filter((t) => t.type === "video");
|
|
1700
|
-
if (!canvas.duration) {
|
|
1701
|
-
return unsupportedStrategy("No duration on canvas");
|
|
1702
|
-
}
|
|
1703
|
-
if (videoPaintables.length > 1) {
|
|
1704
|
-
return unsupportedStrategy("Only one video source supported");
|
|
1705
|
-
}
|
|
1706
|
-
const audioResource = (_a = videoPaintables[0]) == null ? void 0 : _a.resource;
|
|
1707
|
-
if (!audioResource) {
|
|
1708
|
-
return unsupportedStrategy("Unknown video");
|
|
1709
|
-
}
|
|
1710
|
-
if (!audioResource.format) {
|
|
1711
|
-
return unsupportedStrategy("Video does not have format");
|
|
1712
|
-
}
|
|
1713
|
-
return {
|
|
1714
|
-
type: "media",
|
|
1715
|
-
media: {
|
|
1716
|
-
duration: canvas.duration,
|
|
1717
|
-
url: audioResource.id,
|
|
1718
|
-
type: "Video",
|
|
1719
|
-
items: [],
|
|
1720
|
-
target: {
|
|
1721
|
-
type: "TemporalSelector",
|
|
1722
|
-
temporal: {
|
|
1723
|
-
startTime: 0,
|
|
1724
|
-
endTime: canvas.duration
|
|
1725
|
-
}
|
|
1726
|
-
},
|
|
1727
|
-
format: audioResource.format,
|
|
1728
|
-
selector: {
|
|
1729
|
-
type: "TemporalSelector",
|
|
1730
|
-
temporal: {
|
|
1731
|
-
startTime: 0,
|
|
1732
|
-
endTime: canvas.duration
|
|
1733
|
-
}
|
|
1734
|
-
}
|
|
1735
|
-
},
|
|
1736
|
-
annotations: {
|
|
1737
|
-
pages: []
|
|
1738
|
-
}
|
|
1739
|
-
};
|
|
1740
|
-
}
|
|
1741
|
-
|
|
1742
|
-
var __defProp$2 = Object.defineProperty;
|
|
1743
|
-
var __defProps$1 = Object.defineProperties;
|
|
1744
|
-
var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
|
|
1745
|
-
var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
|
|
1746
|
-
var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
|
|
1747
|
-
var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
|
|
1748
|
-
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1749
|
-
var __spreadValues$2 = (a, b) => {
|
|
1750
|
-
for (var prop in b || (b = {}))
|
|
1751
|
-
if (__hasOwnProp$2.call(b, prop))
|
|
1752
|
-
__defNormalProp$2(a, prop, b[prop]);
|
|
1753
|
-
if (__getOwnPropSymbols$2)
|
|
1754
|
-
for (var prop of __getOwnPropSymbols$2(b)) {
|
|
1755
|
-
if (__propIsEnum$2.call(b, prop))
|
|
1756
|
-
__defNormalProp$2(a, prop, b[prop]);
|
|
1757
|
-
}
|
|
1758
|
-
return a;
|
|
1759
|
-
};
|
|
1760
|
-
var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
|
|
1761
|
-
function useRenderingStrategy(options) {
|
|
1762
|
-
const manifest = useManifest();
|
|
1763
|
-
const canvas = useCanvas();
|
|
1764
|
-
const vault = useVault();
|
|
1765
|
-
const [loadImageService, imageServiceStatus] = useLoadImageService();
|
|
1766
|
-
const { enabledPageIds } = useAnnotationPageManager((options == null ? void 0 : options.annotationPageManagerId) || (manifest == null ? void 0 : manifest.id) || (canvas == null ? void 0 : canvas.id), {
|
|
1767
|
-
all: false
|
|
1768
|
-
});
|
|
1769
|
-
const enabledPages = useResources(enabledPageIds, "AnnotationPage");
|
|
1770
|
-
const supports = (options == null ? void 0 : options.strategies) || ["images", "media", "complex-timeline"];
|
|
1771
|
-
const [paintables, actions] = usePaintables(options, [imageServiceStatus]);
|
|
1772
|
-
const strategy = React$1.useMemo(() => {
|
|
1773
|
-
if (!canvas || paintables.types.length === 0) {
|
|
1774
|
-
return unknownResponse;
|
|
1775
|
-
}
|
|
1776
|
-
if (paintables.types.length !== 1) {
|
|
1777
|
-
if (paintables.types.length === 2 && paintables.types.indexOf("text") !== -1) {
|
|
1778
|
-
paintables.types = paintables.types.filter((t) => t !== "text");
|
|
1779
|
-
} else {
|
|
1780
|
-
if (supports.indexOf("complex-timeline") === -1) {
|
|
1781
|
-
return unsupportedStrategy("Complex timeline not supported");
|
|
1782
|
-
}
|
|
1783
|
-
return unsupportedStrategy("ComplexTimelineStrategy not yet supported");
|
|
1784
|
-
}
|
|
1785
|
-
}
|
|
1786
|
-
const mainType = paintables.types[0];
|
|
1787
|
-
if (mainType === "image") {
|
|
1788
|
-
if (supports.indexOf("images") === -1) {
|
|
1789
|
-
return unsupportedStrategy("Image not supported");
|
|
1790
|
-
}
|
|
1791
|
-
return getImageStrategy(canvas, paintables, loadImageService);
|
|
1792
|
-
}
|
|
1793
|
-
if (mainType === "Model" || mainType === "model") {
|
|
1794
|
-
if (supports.indexOf("3d-model") === -1) {
|
|
1795
|
-
return unsupportedStrategy("3D not supported");
|
|
1796
|
-
}
|
|
1797
|
-
return get3dStrategy(canvas, paintables);
|
|
1798
|
-
}
|
|
1799
|
-
if (mainType === "sound" || mainType === "audio") {
|
|
1800
|
-
if (supports.indexOf("media") === -1) {
|
|
1801
|
-
return unsupportedStrategy("Media not supported");
|
|
1802
|
-
}
|
|
1803
|
-
return getAudioStrategy(canvas, paintables);
|
|
1804
|
-
}
|
|
1805
|
-
if (mainType === "video") {
|
|
1806
|
-
if (supports.indexOf("media") === -1) {
|
|
1807
|
-
return unsupportedStrategy("Media not supported");
|
|
1808
|
-
}
|
|
1809
|
-
return getVideoStrategy(canvas, paintables);
|
|
1810
|
-
}
|
|
1811
|
-
return unknownResponse;
|
|
1812
|
-
}, [canvas, paintables, vault, actions.makeChoice]);
|
|
1813
|
-
return React$1.useMemo(() => {
|
|
1814
|
-
if (strategy.type === "unknown") {
|
|
1815
|
-
return [strategy, emptyActions];
|
|
1816
|
-
}
|
|
1817
|
-
return [
|
|
1818
|
-
__spreadProps$1(__spreadValues$2({}, strategy), {
|
|
1819
|
-
annotations: { pages: enabledPages }
|
|
1820
|
-
}),
|
|
1821
|
-
actions
|
|
1822
|
-
];
|
|
1823
|
-
}, [strategy, enabledPages]);
|
|
1824
|
-
}
|
|
1825
|
-
|
|
1826
|
-
const useVaultEffect = (callback, deps = []) => {
|
|
1827
|
-
const vault = useVault();
|
|
1828
|
-
React$1.useEffect(() => {
|
|
1829
|
-
callback(vault);
|
|
1830
|
-
}, [vault, ...deps]);
|
|
1831
|
-
};
|
|
1832
|
-
|
|
1833
|
-
function useThumbnail(request, dereference, { canvasId, manifestId } = {}) {
|
|
1834
|
-
const vault = useVault();
|
|
1835
|
-
const loader = useImageServiceLoader();
|
|
1836
|
-
const helper = React$1.useMemo(() => vaultHelpers.createThumbnailHelper(vault, { imageServiceLoader: loader }), [vault, loader]);
|
|
1837
|
-
const [thumbnail, setThumbnail] = React$1.useState();
|
|
1838
|
-
const manifest = useManifest(manifestId ? { id: manifestId } : void 0);
|
|
1839
|
-
const canvas = useCanvas(canvasId ? { id: canvasId } : void 0);
|
|
1840
|
-
const subject = canvas ? canvas : manifest;
|
|
1841
|
-
const didUnmount = React$1.useRef(false);
|
|
1842
|
-
React$1.useEffect(() => {
|
|
1843
|
-
return () => {
|
|
1844
|
-
didUnmount.current = true;
|
|
1845
|
-
};
|
|
1846
|
-
}, []);
|
|
1847
|
-
if (!subject) {
|
|
1848
|
-
throw new Error("Must be called under a manifest or canvas context.");
|
|
1849
|
-
}
|
|
1850
|
-
useVaultEffect((v) => {
|
|
1851
|
-
helper.getBestThumbnailAtSize(subject, request, dereference).then((thumb) => {
|
|
1852
|
-
if (thumb.best && !didUnmount.current) {
|
|
1853
|
-
setThumbnail(thumb.best);
|
|
1854
|
-
}
|
|
1855
|
-
});
|
|
1856
|
-
}, [subject]);
|
|
1857
|
-
return thumbnail;
|
|
1858
|
-
}
|
|
1859
|
-
|
|
1860
|
-
var __defProp$1 = Object.defineProperty;
|
|
1861
|
-
var __defProps = Object.defineProperties;
|
|
1862
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
1863
|
-
var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
|
|
1864
|
-
var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
|
|
1865
|
-
var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
|
|
1866
|
-
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1867
|
-
var __spreadValues$1 = (a, b) => {
|
|
1868
|
-
for (var prop in b || (b = {}))
|
|
1869
|
-
if (__hasOwnProp$1.call(b, prop))
|
|
1870
|
-
__defNormalProp$1(a, prop, b[prop]);
|
|
1871
|
-
if (__getOwnPropSymbols$1)
|
|
1872
|
-
for (var prop of __getOwnPropSymbols$1(b)) {
|
|
1873
|
-
if (__propIsEnum$1.call(b, prop))
|
|
1874
|
-
__defNormalProp$1(a, prop, b[prop]);
|
|
1875
|
-
}
|
|
1876
|
-
return a;
|
|
1877
|
-
};
|
|
1878
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
1879
|
-
function getDefaultState(duration) {
|
|
1880
|
-
return { isMuted: false, playRequested: false, isPlaying: false, isFinished: false, volume: 100, duration };
|
|
1881
|
-
}
|
|
1882
|
-
function reducer(state, action) {
|
|
1883
|
-
switch (action.type) {
|
|
1884
|
-
case "FINISHED":
|
|
1885
|
-
return __spreadProps(__spreadValues$1({}, state), { isFinished: true, isPlaying: false, playRequested: false });
|
|
1886
|
-
case "PLAY_PAUSE":
|
|
1887
|
-
return __spreadProps(__spreadValues$1({}, state), { isFinished: false, isPlaying: !state.isPlaying });
|
|
1888
|
-
case "PLAY_REQUESTED":
|
|
1889
|
-
return __spreadProps(__spreadValues$1({}, state), { isFinished: false, playRequested: true });
|
|
1890
|
-
case "PAUSE":
|
|
1891
|
-
return __spreadProps(__spreadValues$1({}, state), { isPlaying: false });
|
|
1892
|
-
case "PLAY":
|
|
1893
|
-
return __spreadProps(__spreadValues$1({}, state), { isFinished: false, playRequested: false, isPlaying: true });
|
|
1894
|
-
case "MUTE":
|
|
1895
|
-
return __spreadProps(__spreadValues$1({}, state), { isMuted: true });
|
|
1896
|
-
case "SET_VOLUME":
|
|
1897
|
-
return __spreadProps(__spreadValues$1({}, state), { volume: action.volume, isMuted: action.volume === 0 });
|
|
1898
|
-
case "TOGGLE_MUTE":
|
|
1899
|
-
return __spreadProps(__spreadValues$1({}, state), { isMuted: !state.isMuted });
|
|
1900
|
-
case "UNMUTE":
|
|
1901
|
-
return __spreadProps(__spreadValues$1({}, state), { isMuted: false });
|
|
1902
|
-
}
|
|
1903
|
-
return state;
|
|
1904
|
-
}
|
|
1905
|
-
function formatTime(time) {
|
|
1906
|
-
const seconds = Math.round(time);
|
|
1907
|
-
return `${Math.floor(seconds / 60)}:${`${seconds % 60}`.padStart(2, "0")}`;
|
|
1908
|
-
}
|
|
1909
|
-
function useSimpleMediaPlayer(props) {
|
|
1910
|
-
const [state, dispatch] = React$1.useReducer(reducer, getDefaultState(props.duration));
|
|
1911
|
-
const media = React$1.useRef(null);
|
|
1912
|
-
const currentTime = React$1.useRef(null);
|
|
1913
|
-
const progress = React$1.useRef(null);
|
|
1914
|
-
const _isMuted = React$1.useRef(false);
|
|
1915
|
-
const _updateCurrentTime = React$1.useCallback(() => {
|
|
1916
|
-
if (currentTime.current && media.current) {
|
|
1917
|
-
currentTime.current.innerHTML = formatTime(media.current.currentTime);
|
|
1918
|
-
if (progress.current) {
|
|
1919
|
-
progress.current.style.width = `${media.current.currentTime / props.duration * 100}%`;
|
|
1920
|
-
}
|
|
1921
|
-
if (_isMuted.current !== media.current.muted) {
|
|
1922
|
-
_isMuted.current = media.current.muted;
|
|
1923
|
-
dispatch(media.current.muted ? { type: "MUTE" } : { type: "UNMUTE" });
|
|
1924
|
-
}
|
|
1925
|
-
}
|
|
1926
|
-
}, [props.duration]);
|
|
1927
|
-
const play = React$1.useCallback(() => {
|
|
1928
|
-
if (media.current) {
|
|
1929
|
-
dispatch({ type: "PLAY_REQUESTED" });
|
|
1930
|
-
media.current.play().then(() => {
|
|
1931
|
-
dispatch({ type: "PLAY" });
|
|
1932
|
-
});
|
|
1933
|
-
_updateCurrentTime();
|
|
1934
|
-
}
|
|
1935
|
-
}, [_updateCurrentTime]);
|
|
1936
|
-
const playPause = React$1.useCallback(() => {
|
|
1937
|
-
if (media.current) {
|
|
1938
|
-
if (media.current.duration > 0 && media.current.paused) {
|
|
1939
|
-
play();
|
|
1940
|
-
} else {
|
|
1941
|
-
pause();
|
|
1942
|
-
}
|
|
1943
|
-
}
|
|
1944
|
-
}, [_updateCurrentTime]);
|
|
1945
|
-
const pause = React$1.useCallback(() => {
|
|
1946
|
-
if (media.current) {
|
|
1947
|
-
media.current.pause();
|
|
1948
|
-
dispatch({ type: "PAUSE" });
|
|
1949
|
-
_updateCurrentTime();
|
|
1950
|
-
}
|
|
1951
|
-
}, [_updateCurrentTime]);
|
|
1952
|
-
const toggleMute = React$1.useCallback(() => {
|
|
1953
|
-
if (media.current) {
|
|
1954
|
-
media.current.muted = !media.current.muted;
|
|
1955
|
-
dispatch(media.current.muted ? { type: "MUTE" } : { type: "UNMUTE" });
|
|
1956
|
-
}
|
|
1957
|
-
}, []);
|
|
1958
|
-
const mute = React$1.useCallback(() => {
|
|
1959
|
-
if (media.current) {
|
|
1960
|
-
media.current.muted = true;
|
|
1961
|
-
dispatch({ type: "MUTE" });
|
|
1962
|
-
}
|
|
1963
|
-
}, []);
|
|
1964
|
-
const unmute = React$1.useCallback(() => {
|
|
1965
|
-
if (media.current) {
|
|
1966
|
-
media.current.muted = false;
|
|
1967
|
-
dispatch({ type: "UNMUTE" });
|
|
1968
|
-
}
|
|
1969
|
-
}, []);
|
|
1970
|
-
const setVolume = React$1.useCallback((newVolume) => {
|
|
1971
|
-
if (media.current) {
|
|
1972
|
-
media.current.muted = false;
|
|
1973
|
-
media.current.volume = newVolume / 100;
|
|
1974
|
-
dispatch({ type: "SET_VOLUME", volume: newVolume });
|
|
1975
|
-
}
|
|
1976
|
-
}, []);
|
|
1977
|
-
const setDurationPercent = React$1.useCallback((percent) => {
|
|
1978
|
-
if (media.current) {
|
|
1979
|
-
media.current.currentTime = Math.max(0, Math.min(percent * props.duration, props.duration));
|
|
1980
|
-
_updateCurrentTime();
|
|
1981
|
-
}
|
|
1982
|
-
}, []);
|
|
1983
|
-
const setTime = React$1.useCallback((time) => {
|
|
1984
|
-
if (media.current) {
|
|
1985
|
-
media.current.currentTime = Math.max(0, Math.min(time, props.duration));
|
|
1986
|
-
_updateCurrentTime();
|
|
1987
|
-
}
|
|
1988
|
-
}, []);
|
|
1989
|
-
React$1.useEffect(() => {
|
|
1990
|
-
const interval = setInterval(() => {
|
|
1991
|
-
_updateCurrentTime();
|
|
1992
|
-
}, 350);
|
|
1993
|
-
return () => clearInterval(interval);
|
|
1994
|
-
}, [_updateCurrentTime, props.duration]);
|
|
1995
|
-
React$1.useEffect(() => {
|
|
1996
|
-
const ended = () => {
|
|
1997
|
-
dispatch({ type: "FINISHED" });
|
|
1998
|
-
};
|
|
1999
|
-
const _media = media.current;
|
|
2000
|
-
_media == null ? void 0 : _media.addEventListener("ended", ended);
|
|
2001
|
-
return () => _media == null ? void 0 : _media.removeEventListener("ended", ended);
|
|
2002
|
-
}, []);
|
|
2003
|
-
return [
|
|
2004
|
-
{ element: media, currentTime, progress },
|
|
2005
|
-
state,
|
|
2006
|
-
{
|
|
2007
|
-
play,
|
|
2008
|
-
pause,
|
|
2009
|
-
playPause,
|
|
2010
|
-
mute,
|
|
2011
|
-
unmute,
|
|
2012
|
-
toggleMute,
|
|
2013
|
-
setVolume,
|
|
2014
|
-
setDurationPercent,
|
|
2015
|
-
setTime
|
|
2016
|
-
}
|
|
2017
|
-
];
|
|
2018
|
-
}
|
|
2019
|
-
|
|
2020
|
-
const MediaReactContextState = React$1.createContext(null);
|
|
2021
|
-
const MediaReactContextActions = React$1.createContext(null);
|
|
2022
|
-
const MediaReactContextElements = React$1.createContext(null);
|
|
2023
|
-
function useMediaState() {
|
|
2024
|
-
const ctx = React$1.useContext(MediaReactContextState);
|
|
2025
|
-
if (!ctx) {
|
|
2026
|
-
throw new Error("Ctx not found");
|
|
2027
|
-
}
|
|
2028
|
-
return ctx;
|
|
2029
|
-
}
|
|
2030
|
-
function useMediaActions() {
|
|
2031
|
-
const ctx = React$1.useContext(MediaReactContextActions);
|
|
2032
|
-
if (!ctx) {
|
|
2033
|
-
throw new Error("Ctx not found");
|
|
2034
|
-
}
|
|
2035
|
-
return ctx;
|
|
2036
|
-
}
|
|
2037
|
-
function useMediaElements() {
|
|
2038
|
-
const ctx = React$1.useContext(MediaReactContextElements);
|
|
2039
|
-
if (!ctx) {
|
|
2040
|
-
throw new Error("Ctx not found");
|
|
2041
|
-
}
|
|
2042
|
-
return ctx;
|
|
2043
|
-
}
|
|
2044
|
-
function MediaPlayerProvider({
|
|
2045
|
-
actions,
|
|
2046
|
-
state,
|
|
2047
|
-
children,
|
|
2048
|
-
currentTime,
|
|
2049
|
-
progress,
|
|
2050
|
-
element
|
|
2051
|
-
}) {
|
|
2052
|
-
return /* @__PURE__ */ React.createElement(MediaReactContextElements.Provider, {
|
|
2053
|
-
value: { currentTime, progress, element }
|
|
2054
|
-
}, /* @__PURE__ */ React.createElement(MediaReactContextActions.Provider, {
|
|
2055
|
-
value: actions
|
|
2056
|
-
}, /* @__PURE__ */ React.createElement(MediaReactContextState.Provider, {
|
|
2057
|
-
value: state
|
|
2058
|
-
}, children)));
|
|
2059
|
-
}
|
|
2060
|
-
|
|
2061
|
-
function Audio({ media, children }) {
|
|
2062
|
-
const [{ element, currentTime, progress }, state, actions] = useSimpleMediaPlayer({ duration: media.duration });
|
|
2063
|
-
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(CanvasPortal, null, /* @__PURE__ */ React.createElement(MediaPlayerProvider, {
|
|
2064
|
-
state,
|
|
2065
|
-
actions,
|
|
2066
|
-
currentTime,
|
|
2067
|
-
progress,
|
|
2068
|
-
element
|
|
2069
|
-
}, /* @__PURE__ */ React.createElement("audio", {
|
|
2070
|
-
ref: element,
|
|
2071
|
-
src: media.url
|
|
2072
|
-
}), children)));
|
|
2073
|
-
}
|
|
2074
|
-
|
|
2075
|
-
function Video({ media, children }) {
|
|
2076
|
-
const [{ element, currentTime, progress }, state, actions] = useSimpleMediaPlayer({ duration: media.duration });
|
|
2077
|
-
const Component = "div";
|
|
2078
|
-
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(CanvasPortal, {
|
|
2079
|
-
overlay: true
|
|
2080
|
-
}, /* @__PURE__ */ React.createElement("style", null, `
|
|
2081
|
-
.video-container {
|
|
2082
|
-
position: absolute;
|
|
2083
|
-
top: 0;
|
|
2084
|
-
bottom: 0;
|
|
2085
|
-
left: 0;
|
|
2086
|
-
right: 0;
|
|
2087
|
-
background: #000;
|
|
2088
|
-
z-index: 13;
|
|
2089
|
-
display: flex;
|
|
2090
|
-
justify-content: center;
|
|
2091
|
-
pointer-events: visible;
|
|
2092
|
-
}
|
|
2093
|
-
`), /* @__PURE__ */ React.createElement(Component, {
|
|
2094
|
-
className: "video-container",
|
|
2095
|
-
part: "video-container",
|
|
2096
|
-
onClick: () => actions.playPause()
|
|
2097
|
-
}, /* @__PURE__ */ React.createElement("video", {
|
|
2098
|
-
ref: element,
|
|
2099
|
-
src: media.url,
|
|
2100
|
-
style: { width: "100%", objectFit: "contain" }
|
|
2101
|
-
}))), /* @__PURE__ */ React.createElement(CanvasPortal, null, /* @__PURE__ */ React.createElement(MediaPlayerProvider, {
|
|
2102
|
-
state,
|
|
2103
|
-
actions,
|
|
2104
|
-
currentTime,
|
|
2105
|
-
progress,
|
|
2106
|
-
element
|
|
2107
|
-
}, children)));
|
|
2108
|
-
}
|
|
2109
|
-
|
|
2110
|
-
function Model({ model }) {
|
|
2111
|
-
return /* @__PURE__ */ React.createElement(CanvasPortal, {
|
|
2112
|
-
overlay: true
|
|
2113
|
-
}, /* @__PURE__ */ React.createElement("style", null, `
|
|
2114
|
-
.model-container {
|
|
2115
|
-
position: absolute;
|
|
2116
|
-
top: 0;
|
|
2117
|
-
bottom: 0;
|
|
2118
|
-
left: 0;
|
|
2119
|
-
right: 0;
|
|
2120
|
-
background: #000;
|
|
2121
|
-
z-index: 13;
|
|
2122
|
-
display: flex;
|
|
2123
|
-
justify-content: center;
|
|
2124
|
-
pointer-events: visible;
|
|
2125
|
-
}
|
|
2126
|
-
`), /* @__PURE__ */ React.createElement("div", {
|
|
2127
|
-
className: "model-container"
|
|
2128
|
-
}, /* @__PURE__ */ React.createElement("model-viewer", {
|
|
2129
|
-
"interaction-prompt": "none",
|
|
2130
|
-
style: { width: "100%", height: "100%" },
|
|
2131
|
-
"camera-controls": "",
|
|
2132
|
-
"ar-status": "not-presenting",
|
|
2133
|
-
src: model.id
|
|
2134
|
-
})));
|
|
2135
|
-
}
|
|
2136
|
-
|
|
2137
|
-
var __defProp = Object.defineProperty;
|
|
2138
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
2139
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
2140
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
2141
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
2142
|
-
var __spreadValues = (a, b) => {
|
|
2143
|
-
for (var prop in b || (b = {}))
|
|
2144
|
-
if (__hasOwnProp.call(b, prop))
|
|
2145
|
-
__defNormalProp(a, prop, b[prop]);
|
|
2146
|
-
if (__getOwnPropSymbols)
|
|
2147
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
2148
|
-
if (__propIsEnum.call(b, prop))
|
|
2149
|
-
__defNormalProp(a, prop, b[prop]);
|
|
2150
|
-
}
|
|
2151
|
-
return a;
|
|
2152
|
-
};
|
|
2153
|
-
function RenderCanvas({
|
|
2154
|
-
x,
|
|
2155
|
-
y,
|
|
2156
|
-
onChoiceChange,
|
|
2157
|
-
registerActions,
|
|
2158
|
-
defaultChoices,
|
|
2159
|
-
isStatic,
|
|
2160
|
-
renderViewerControls,
|
|
2161
|
-
renderMediaControls,
|
|
2162
|
-
strategies,
|
|
2163
|
-
children
|
|
2164
|
-
}) {
|
|
2165
|
-
const canvas = useCanvas();
|
|
2166
|
-
const elementProps = useResourceEvents(canvas, ["deep-zoom"]);
|
|
2167
|
-
const [virtualPage] = useVirtualAnnotationPageContext();
|
|
2168
|
-
const vault = useVault();
|
|
2169
|
-
const helper = React$1.useMemo(() => vaultHelpers.createStylesHelper(vault), [vault]);
|
|
2170
|
-
const [strategy, actions] = useRenderingStrategy({
|
|
2171
|
-
strategies: strategies || ["images"],
|
|
2172
|
-
defaultChoices: defaultChoices == null ? void 0 : defaultChoices.map(({ id }) => id)
|
|
2173
|
-
});
|
|
2174
|
-
const choice = strategy.type === "images" ? strategy.choice : void 0;
|
|
2175
|
-
React$1.useEffect(() => {
|
|
2176
|
-
if (registerActions) {
|
|
2177
|
-
registerActions(actions);
|
|
2178
|
-
}
|
|
2179
|
-
}, [strategy.annotations]);
|
|
2180
|
-
React$1.useEffect(() => {
|
|
2181
|
-
if (defaultChoices) {
|
|
2182
|
-
for (const choice2 of defaultChoices) {
|
|
2183
|
-
if (typeof choice2.opacity !== "undefined") {
|
|
2184
|
-
helper.applyStyles({ id: choice2.id }, "atlas", {
|
|
2185
|
-
opacity: choice2.opacity
|
|
2186
|
-
});
|
|
2187
|
-
}
|
|
2188
|
-
}
|
|
2189
|
-
}
|
|
2190
|
-
}, [defaultChoices]);
|
|
2191
|
-
React$1.useLayoutEffect(() => {
|
|
2192
|
-
if (onChoiceChange) {
|
|
2193
|
-
onChoiceChange(choice);
|
|
2194
|
-
}
|
|
2195
|
-
}, [choice]);
|
|
2196
|
-
const thumbnail = useThumbnail({ maxWidth: 256, maxHeight: 256 });
|
|
2197
|
-
if (!canvas) {
|
|
2198
|
-
return null;
|
|
2199
|
-
}
|
|
2200
|
-
const accompanyingCanvas = canvas.accompanyingCanvas;
|
|
2201
|
-
const thumbnailFallbackImage = thumbnail && thumbnail.type === "fixed" ? /* @__PURE__ */ React__default["default"].createElement("world-object", {
|
|
2202
|
-
height: canvas.height,
|
|
2203
|
-
width: canvas.width,
|
|
2204
|
-
x,
|
|
2205
|
-
y
|
|
2206
|
-
}, /* @__PURE__ */ React__default["default"].createElement("world-image", {
|
|
2207
|
-
uri: thumbnail.id,
|
|
2208
|
-
target: { x: 0, y: 0, width: canvas.width, height: canvas.height },
|
|
2209
|
-
display: thumbnail.width && thumbnail.height ? {
|
|
2210
|
-
width: thumbnail.width,
|
|
2211
|
-
height: thumbnail.height
|
|
2212
|
-
} : void 0
|
|
2213
|
-
})) : null;
|
|
2214
|
-
if (strategy.type === "unknown") {
|
|
2215
|
-
if (thumbnailFallbackImage) {
|
|
2216
|
-
return thumbnailFallbackImage;
|
|
2217
|
-
}
|
|
2218
|
-
throw new Error(strategy.reason || "Unknown image strategy");
|
|
2219
|
-
}
|
|
2220
|
-
const annotations = /* @__PURE__ */ React__default["default"].createElement(React$1.Fragment, null, virtualPage ? /* @__PURE__ */ React__default["default"].createElement(RenderAnnotationPage, {
|
|
2221
|
-
page: virtualPage
|
|
2222
|
-
}) : null, strategy.annotations && strategy.annotations.pages ? strategy.annotations.pages.map((page) => {
|
|
2223
|
-
return /* @__PURE__ */ React__default["default"].createElement(RenderAnnotationPage, {
|
|
2224
|
-
key: page.id,
|
|
2225
|
-
page
|
|
2226
|
-
});
|
|
2227
|
-
}) : null, children);
|
|
2228
|
-
return /* @__PURE__ */ React__default["default"].createElement(React__default["default"].Fragment, null, /* @__PURE__ */ React__default["default"].createElement("world-object", __spreadValues({
|
|
2229
|
-
key: strategy.type,
|
|
2230
|
-
height: canvas.height,
|
|
2231
|
-
width: canvas.width,
|
|
2232
|
-
x,
|
|
2233
|
-
y
|
|
2234
|
-
}, elementProps), strategy.type === "images" ? /* @__PURE__ */ React__default["default"].createElement(React__default["default"].Fragment, null, strategy.images.map((image, idx) => {
|
|
2235
|
-
return /* @__PURE__ */ React__default["default"].createElement(RenderImage, {
|
|
2236
|
-
isStatic,
|
|
2237
|
-
key: image.id,
|
|
2238
|
-
image,
|
|
2239
|
-
id: image.id,
|
|
2240
|
-
thumbnail: idx === 0 ? thumbnail : void 0,
|
|
2241
|
-
annotations
|
|
2242
|
-
});
|
|
2243
|
-
}), renderViewerControls ? /* @__PURE__ */ React__default["default"].createElement(CanvasPortal, {
|
|
2244
|
-
overlay: true
|
|
2245
|
-
}, renderViewerControls(strategy)) : null) : null, strategy.type === "3d-model" ? /* @__PURE__ */ React__default["default"].createElement(Model, {
|
|
2246
|
-
model: strategy.model
|
|
2247
|
-
}) : null, strategy.type === "media" ? /* @__PURE__ */ React__default["default"].createElement(React__default["default"].Fragment, null, strategy.media.type === "Sound" ? /* @__PURE__ */ React__default["default"].createElement(Audio, {
|
|
2248
|
-
media: strategy.media
|
|
2249
|
-
}, thumbnailFallbackImage, renderMediaControls ? renderMediaControls(strategy) : null) : strategy.media.type === "Video" ? /* @__PURE__ */ React__default["default"].createElement(Video, {
|
|
2250
|
-
media: strategy.media
|
|
2251
|
-
}, thumbnailFallbackImage, renderMediaControls ? renderMediaControls(strategy) : null) : null) : null), strategy.type === "media" && strategy.media.type === "Sound" && accompanyingCanvas ? /* @__PURE__ */ React__default["default"].createElement(CanvasContext, {
|
|
2252
|
-
canvas: accompanyingCanvas.id
|
|
2253
|
-
}, /* @__PURE__ */ React__default["default"].createElement(RenderCanvas, null)) : null);
|
|
2254
|
-
}
|
|
2255
|
-
|
|
2256
|
-
const CanvasPanel = {
|
|
2257
|
-
RenderImage,
|
|
2258
|
-
RenderCanvas,
|
|
2259
|
-
RenderAnnotationPage,
|
|
2260
|
-
RenderAnnotation,
|
|
2261
|
-
Viewer
|
|
2262
|
-
};
|
|
2263
|
-
|
|
2264
|
-
function AnnotationContext({ annotation, children }) {
|
|
2265
|
-
return /* @__PURE__ */ React__default["default"].createElement(ResourceProvider, {
|
|
2266
|
-
value: { annotation }
|
|
2267
|
-
}, children);
|
|
2268
|
-
}
|
|
2269
|
-
|
|
2270
|
-
function CollectionContext({ collection, children }) {
|
|
2271
|
-
return /* @__PURE__ */ React__default["default"].createElement(ResourceProvider, {
|
|
2272
|
-
value: { collection }
|
|
2273
|
-
}, children);
|
|
2274
|
-
}
|
|
2275
|
-
|
|
2276
|
-
function RangeContext({ range, children }) {
|
|
2277
|
-
return /* @__PURE__ */ React__default["default"].createElement(ResourceProvider, {
|
|
2278
|
-
value: { range }
|
|
2279
|
-
}, children);
|
|
2280
|
-
}
|
|
2281
|
-
|
|
2282
|
-
function useAnnotationsAtTime(time, options = {}) {
|
|
2283
|
-
const allAnnotations = usePaintingAnnotations(options);
|
|
2284
|
-
return allAnnotations;
|
|
2285
|
-
}
|
|
2286
|
-
|
|
2287
|
-
function useCanvasClock(canvasId, autoplay = false) {
|
|
2288
|
-
}
|
|
2289
|
-
|
|
2290
|
-
function useCollection(options, deps = []) {
|
|
2291
|
-
const { id, selector } = options;
|
|
2292
|
-
const ctx = useResourceContext();
|
|
2293
|
-
const collectionId = id ? id : ctx.collection;
|
|
2294
|
-
const collection = useVaultSelector((s) => collectionId ? s.iiif.entities.Collection[collectionId] : void 0, [collectionId]);
|
|
2295
|
-
return React$1.useMemo(() => {
|
|
2296
|
-
if (!collection) {
|
|
2297
|
-
return void 0;
|
|
2298
|
-
}
|
|
2299
|
-
if (selector) {
|
|
2300
|
-
return selector(collection);
|
|
2301
|
-
}
|
|
2302
|
-
return collection;
|
|
2303
|
-
}, [collection, selector, ...deps]);
|
|
2304
|
-
}
|
|
2305
|
-
|
|
2306
|
-
function useEventListener(resource, name, listener, scope, deps = []) {
|
|
2307
|
-
const vault = useVault();
|
|
2308
|
-
const helper = React$1.useMemo(() => vaultHelpers.createEventsHelper(vault), [vault]);
|
|
2309
|
-
React$1.useEffect(() => {
|
|
2310
|
-
const currentResource = resource;
|
|
2311
|
-
if (!currentResource) {
|
|
2312
|
-
return () => {
|
|
2313
|
-
};
|
|
2314
|
-
}
|
|
2315
|
-
helper.addEventListener(currentResource, name, listener, scope);
|
|
2316
|
-
return () => {
|
|
2317
|
-
helper.removeEventListener(currentResource, name, listener);
|
|
2318
|
-
};
|
|
2319
|
-
}, [helper, resource, name, ...deps]);
|
|
2320
|
-
}
|
|
2321
|
-
|
|
2322
|
-
function useExistingVault() {
|
|
2323
|
-
const oldContext = React$1.useContext(ReactVaultContext);
|
|
2324
|
-
return oldContext && oldContext.vault ? oldContext.vault : vault.globalVault();
|
|
2325
|
-
}
|
|
2326
|
-
|
|
2327
|
-
function useExternalCollection(idOrRef, options) {
|
|
2328
|
-
const { id, isLoaded, error, resource, requestId, cached } = useExternalResource(idOrRef, options);
|
|
2329
|
-
return { id, isLoaded, error, manifest: resource, requestId, cached };
|
|
2330
|
-
}
|
|
2331
|
-
|
|
2332
|
-
var __async = (__this, __arguments, generator) => {
|
|
2333
|
-
return new Promise((resolve, reject) => {
|
|
2334
|
-
var fulfilled = (value) => {
|
|
2335
|
-
try {
|
|
2336
|
-
step(generator.next(value));
|
|
2337
|
-
} catch (e) {
|
|
2338
|
-
reject(e);
|
|
2339
|
-
}
|
|
2340
|
-
};
|
|
2341
|
-
var rejected = (value) => {
|
|
2342
|
-
try {
|
|
2343
|
-
step(generator.throw(value));
|
|
2344
|
-
} catch (e) {
|
|
2345
|
-
reject(e);
|
|
2346
|
-
}
|
|
2347
|
-
};
|
|
2348
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
2349
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
2350
|
-
});
|
|
2351
|
-
};
|
|
2352
|
-
function useImageService({ cacheKey } = {}) {
|
|
2353
|
-
const canvas = useCanvas();
|
|
2354
|
-
const annotations = usePaintingAnnotations();
|
|
2355
|
-
const vault = useVault();
|
|
2356
|
-
const imageService = useImageServiceLoader();
|
|
2357
|
-
const [_data, setData] = React$1.useState(void 0);
|
|
2358
|
-
const [isFetching, setIsFetching] = React$1.useState(false);
|
|
2359
|
-
const [status, setStatus] = React$1.useState("idle");
|
|
2360
|
-
const [error, setError] = React$1.useState(void 0);
|
|
2361
|
-
const key = canvas ? canvas.id : "undefined";
|
|
2362
|
-
const initialData = React$1.useMemo(() => {
|
|
2363
|
-
try {
|
|
2364
|
-
if (canvas && annotations.length) {
|
|
2365
|
-
const annotation = annotations[0];
|
|
2366
|
-
const resource = vault.get(annotation.body[0]);
|
|
2367
|
-
const imageServices = iiifImageApi.getImageServices(resource);
|
|
2368
|
-
const firstImageService = imageServices[0];
|
|
2369
|
-
if (!firstImageService) {
|
|
2370
|
-
return void 0;
|
|
2371
|
-
}
|
|
2372
|
-
return imageService.loadServiceSync({
|
|
2373
|
-
id: firstImageService.id || firstImageService["@id"],
|
|
2374
|
-
width: firstImageService.width || canvas.width,
|
|
2375
|
-
height: firstImageService.height || canvas.height
|
|
2376
|
-
}) || void 0;
|
|
2377
|
-
}
|
|
2378
|
-
} catch (e) {
|
|
2379
|
-
console.error(e);
|
|
2380
|
-
}
|
|
2381
|
-
return void 0;
|
|
2382
|
-
}, [key, cacheKey, canvas]);
|
|
2383
|
-
const data = status === "success" && _data ? _data : initialData;
|
|
2384
|
-
React$1.useEffect(() => {
|
|
2385
|
-
(() => __async(this, null, function* () {
|
|
2386
|
-
try {
|
|
2387
|
-
if (canvas && annotations.length) {
|
|
2388
|
-
const annotation = annotations[0];
|
|
2389
|
-
const resource = vault.get(annotation.body[0]);
|
|
2390
|
-
const imageServices = iiifImageApi.getImageServices(resource);
|
|
2391
|
-
const firstImageService = imageServices[0];
|
|
2392
|
-
if (!firstImageService) {
|
|
2393
|
-
return;
|
|
2394
|
-
}
|
|
2395
|
-
setIsFetching(true);
|
|
2396
|
-
setStatus("loading");
|
|
2397
|
-
try {
|
|
2398
|
-
const loadedService = (yield imageService.loadService({
|
|
2399
|
-
id: firstImageService.id || firstImageService["@id"],
|
|
2400
|
-
width: firstImageService.width || canvas.width,
|
|
2401
|
-
height: firstImageService.height || canvas.height
|
|
2402
|
-
})) || void 0;
|
|
2403
|
-
setData(loadedService);
|
|
2404
|
-
setStatus("success");
|
|
2405
|
-
setIsFetching(false);
|
|
2406
|
-
} catch (err) {
|
|
2407
|
-
setStatus("error");
|
|
2408
|
-
setError(err);
|
|
2409
|
-
}
|
|
2410
|
-
}
|
|
2411
|
-
} catch (err) {
|
|
2412
|
-
setStatus("error");
|
|
2413
|
-
setError(err);
|
|
2414
|
-
}
|
|
2415
|
-
}))();
|
|
2416
|
-
}, [key, cacheKey]);
|
|
2417
|
-
return React$1.useMemo(() => {
|
|
2418
|
-
return {
|
|
2419
|
-
data,
|
|
2420
|
-
isFetching,
|
|
2421
|
-
status,
|
|
2422
|
-
error
|
|
2423
|
-
};
|
|
2424
|
-
}, [data, isFetching, status, error]);
|
|
2425
|
-
}
|
|
2426
|
-
|
|
2427
|
-
function useImageTile() {
|
|
2428
|
-
const imageService = useImageService();
|
|
2429
|
-
return {
|
|
2430
|
-
isLoading: imageService.isFetching,
|
|
2431
|
-
tile: imageService.data ? {
|
|
2432
|
-
id: imageService.data.id || imageService.data["@id"],
|
|
2433
|
-
width: imageService.data.width,
|
|
2434
|
-
height: imageService.data.height,
|
|
2435
|
-
imageService: imageService.data,
|
|
2436
|
-
thumbnail: void 0
|
|
2437
|
-
} : null
|
|
2438
|
-
};
|
|
2439
|
-
}
|
|
2440
|
-
|
|
2441
|
-
function useRange(options = {}, deps = []) {
|
|
2442
|
-
const { id, selector } = options;
|
|
2443
|
-
const ctx = useResourceContext();
|
|
2444
|
-
const rangeId = id ? id : ctx.range;
|
|
2445
|
-
const range = useVaultSelector((s) => rangeId ? s.iiif.entities.Range[rangeId] : void 0, [rangeId]);
|
|
2446
|
-
return React$1.useMemo(() => {
|
|
2447
|
-
if (!range) {
|
|
2448
|
-
return void 0;
|
|
2449
|
-
}
|
|
2450
|
-
if (selector) {
|
|
2451
|
-
return selector(range);
|
|
2452
|
-
}
|
|
2453
|
-
return range;
|
|
2454
|
-
}, [range, selector, ...deps]);
|
|
2455
|
-
}
|
|
2456
|
-
|
|
2457
|
-
function useSearchService() {
|
|
2458
|
-
const manifest = useManifest();
|
|
2459
|
-
return manifest ? manifest.service.find((service) => service.profile === "SearchService1" || service.profile === "http://iiif.io/api/search/1/search") : void 0;
|
|
2460
|
-
}
|
|
2461
|
-
|
|
2462
|
-
function useStyleHelper() {
|
|
2463
|
-
const vault = useVault();
|
|
2464
|
-
return React$1.useMemo(() => vaultHelpers.createStylesHelper(vault), [vault]);
|
|
2465
|
-
}
|
|
2466
|
-
|
|
2467
|
-
exports.AnnotationContext = AnnotationContext;
|
|
2468
|
-
exports.CanvasContext = CanvasContext;
|
|
2469
|
-
exports.CanvasPanel = CanvasPanel;
|
|
2470
|
-
exports.CanvasPortal = CanvasPortal;
|
|
2471
|
-
exports.CollectionContext = CollectionContext;
|
|
2472
|
-
exports.ContextBridge = ContextBridge;
|
|
2473
|
-
exports.ImageServiceLoaderContext = ImageServiceLoaderContext;
|
|
2474
|
-
exports.ManifestContext = ManifestContext;
|
|
2475
|
-
exports.MediaPlayerProvider = MediaPlayerProvider;
|
|
2476
|
-
exports.OverlayPortalContext = OverlayPortalContext;
|
|
2477
|
-
exports.PortalContext = PortalContext;
|
|
2478
|
-
exports.RangeContext = RangeContext;
|
|
2479
|
-
exports.ReactVaultContext = ReactVaultContext;
|
|
2480
|
-
exports.ResourceProvider = ResourceProvider;
|
|
2481
|
-
exports.ResourceReactContext = ResourceReactContext;
|
|
2482
|
-
exports.SimpleViewerProvider = SimpleViewerProvider;
|
|
2483
|
-
exports.SimpleViewerReactContext = SimpleViewerReactContext;
|
|
2484
|
-
exports.VaultProvider = VaultProvider;
|
|
2485
|
-
exports.VirtualAnnotationProvider = VirtualAnnotationProvider;
|
|
2486
|
-
exports.VisibleCanvasReactContext = VisibleCanvasReactContext;
|
|
2487
|
-
exports.emptyActions = emptyActions;
|
|
2488
|
-
exports.expandTarget = expandTarget;
|
|
2489
|
-
exports.flattenAnnotationPageIds = flattenAnnotationPageIds;
|
|
2490
|
-
exports.formatTime = formatTime;
|
|
2491
|
-
exports.getImageStrategy = getImageStrategy;
|
|
2492
|
-
exports.getPaintables = getPaintables;
|
|
2493
|
-
exports.parseSelector = parseSelector;
|
|
2494
|
-
exports.parseSpecificResource = parseSpecificResource;
|
|
2495
|
-
exports.unknownResponse = unknownResponse;
|
|
2496
|
-
exports.unsupportedStrategy = unsupportedStrategy;
|
|
2497
|
-
exports.useAnnotation = useAnnotation;
|
|
2498
|
-
exports.useAnnotationPageManager = useAnnotationPageManager;
|
|
2499
|
-
exports.useAnnotationsAtTime = useAnnotationsAtTime;
|
|
2500
|
-
exports.useCanvas = useCanvas;
|
|
2501
|
-
exports.useCanvasClock = useCanvasClock;
|
|
2502
|
-
exports.useCollection = useCollection;
|
|
2503
|
-
exports.useContextBridge = useContextBridge;
|
|
2504
|
-
exports.useDispatch = useDispatch;
|
|
2505
|
-
exports.useEventListener = useEventListener;
|
|
2506
|
-
exports.useExistingVault = useExistingVault;
|
|
2507
|
-
exports.useExternalCollection = useExternalCollection;
|
|
2508
|
-
exports.useExternalManifest = useExternalManifest;
|
|
2509
|
-
exports.useExternalResource = useExternalResource;
|
|
2510
|
-
exports.useImageService = useImageService;
|
|
2511
|
-
exports.useImageServiceLoader = useImageServiceLoader;
|
|
2512
|
-
exports.useImageTile = useImageTile;
|
|
2513
|
-
exports.useLoadImageService = useLoadImageService;
|
|
2514
|
-
exports.useManifest = useManifest;
|
|
2515
|
-
exports.useMediaActions = useMediaActions;
|
|
2516
|
-
exports.useMediaElements = useMediaElements;
|
|
2517
|
-
exports.useMediaState = useMediaState;
|
|
2518
|
-
exports.usePaintables = usePaintables;
|
|
2519
|
-
exports.usePaintingAnnotations = usePaintingAnnotations;
|
|
2520
|
-
exports.useRange = useRange;
|
|
2521
|
-
exports.useRenderingStrategy = useRenderingStrategy;
|
|
2522
|
-
exports.useResourceContext = useResourceContext;
|
|
2523
|
-
exports.useResourceEvents = useResourceEvents;
|
|
2524
|
-
exports.useResources = useResources;
|
|
2525
|
-
exports.useSearchService = useSearchService;
|
|
2526
|
-
exports.useSimpleMediaPlayer = useSimpleMediaPlayer;
|
|
2527
|
-
exports.useSimpleViewer = useSimpleViewer;
|
|
2528
|
-
exports.useStyleHelper = useStyleHelper;
|
|
2529
|
-
exports.useStyles = useStyles;
|
|
2530
|
-
exports.useThumbnail = useThumbnail;
|
|
2531
|
-
exports.useVault = useVault;
|
|
2532
|
-
exports.useVaultEffect = useVaultEffect;
|
|
2533
|
-
exports.useVaultSelector = useVaultSelector;
|
|
2534
|
-
exports.useVirtualAnnotationPage = useVirtualAnnotationPage;
|
|
2535
|
-
exports.useVirtualAnnotationPageContext = useVirtualAnnotationPageContext;
|
|
2536
|
-
exports.useVisibleCanvases = useVisibleCanvases;
|