triiiceratops 0.8.2 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/dist/components/AnnotationOverlay.svelte +288 -0
  2. package/dist/components/AnnotationOverlay.svelte.d.ts +3 -0
  3. package/dist/components/CanvasNavigation.svelte +32 -0
  4. package/dist/components/CanvasNavigation.svelte.d.ts +11 -0
  5. package/dist/components/DemoHeader.svelte +703 -0
  6. package/dist/components/DemoHeader.svelte.d.ts +9 -0
  7. package/dist/components/FloatingMenu.svelte +208 -0
  8. package/dist/components/FloatingMenu.svelte.d.ts +3 -0
  9. package/dist/components/LeftFab.svelte +69 -0
  10. package/dist/components/LeftFab.svelte.d.ts +3 -0
  11. package/dist/components/MetadataDialog.svelte +151 -0
  12. package/dist/components/MetadataDialog.svelte.d.ts +3 -0
  13. package/dist/components/OSDViewer.svelte +260 -0
  14. package/dist/components/OSDViewer.svelte.d.ts +8 -0
  15. package/dist/components/SearchPanel.svelte +150 -0
  16. package/dist/components/SearchPanel.svelte.d.ts +3 -0
  17. package/dist/components/ThemeToggle.svelte +118 -0
  18. package/dist/components/ThemeToggle.svelte.d.ts +3 -0
  19. package/dist/components/ThumbnailGallery.svelte +601 -0
  20. package/dist/components/ThumbnailGallery.svelte.d.ts +36 -0
  21. package/dist/components/TriiiceratopsViewer.svelte +434 -0
  22. package/dist/components/TriiiceratopsViewer.svelte.d.ts +20 -0
  23. package/dist/components/TriiiceratopsViewerElement.svelte +139 -0
  24. package/dist/components/TriiiceratopsViewerElement.svelte.d.ts +27 -0
  25. package/dist/components/TriiiceratopsViewerElementImage.svelte +143 -0
  26. package/dist/components/TriiiceratopsViewerElementImage.svelte.d.ts +27 -0
  27. package/dist/custom-element-image.d.ts +1 -0
  28. package/dist/custom-element-image.js +2 -0
  29. package/dist/custom-element.d.ts +1 -0
  30. package/dist/custom-element.js +3 -0
  31. package/dist/index.js +9 -4153
  32. package/dist/plugins/image-manipulation/ImageManipulationPanel.svelte +134 -0
  33. package/dist/plugins/image-manipulation/ImageManipulationPanel.svelte.d.ts +10 -0
  34. package/dist/{src/lib/plugins → plugins}/image-manipulation/ImageManipulationPlugin.svelte.d.ts +2 -2
  35. package/dist/plugins/image-manipulation/ImageManipulationPlugin.svelte.js +122 -0
  36. package/dist/{src/lib/plugins → plugins}/image-manipulation/filters.d.ts +1 -1
  37. package/dist/plugins/image-manipulation/filters.js +48 -0
  38. package/dist/plugins/image-manipulation/index.js +2 -0
  39. package/dist/plugins/image-manipulation/types.js +7 -0
  40. package/dist/state/i18n.svelte.d.ts +4 -0
  41. package/dist/state/i18n.svelte.js +18 -0
  42. package/dist/state/manifests.svelte.js +210 -0
  43. package/dist/state/manifests.test.d.ts +1 -0
  44. package/dist/state/manifests.test.js +242 -0
  45. package/dist/{src/lib/state → state}/viewer.svelte.d.ts +4 -4
  46. package/dist/state/viewer.svelte.js +693 -0
  47. package/dist/theme/colorUtils.js +196 -0
  48. package/dist/theme/colorUtils.test.d.ts +1 -0
  49. package/dist/theme/colorUtils.test.js +90 -0
  50. package/dist/theme/index.js +52 -0
  51. package/dist/{src/lib/theme → theme}/themeManager.d.ts +4 -1
  52. package/dist/theme/themeManager.js +177 -0
  53. package/dist/theme/types.js +40 -0
  54. package/dist/triiiceratops-bundle.js +4676 -0
  55. package/dist/types/config.js +1 -0
  56. package/dist/{src/lib/types → types}/plugin.d.ts +3 -3
  57. package/dist/types/plugin.js +36 -0
  58. package/dist/utils/annotationAdapter.js +354 -0
  59. package/dist/utils/annotationAdapter.test.d.ts +1 -0
  60. package/dist/utils/annotationAdapter.test.js +91 -0
  61. package/package.json +6 -5
  62. package/dist/plugin-CHYleMsW.js +0 -538
  63. package/dist/plugins/image-manipulation.js +0 -411
  64. package/dist/src/lib/components/AnnotationOverlay.svelte.d.ts +0 -1
  65. package/dist/src/lib/components/CanvasNavigation.svelte.d.ts +0 -1
  66. package/dist/src/lib/components/FloatingMenu.svelte.d.ts +0 -1
  67. package/dist/src/lib/components/LeftFab.svelte.d.ts +0 -1
  68. package/dist/src/lib/components/MetadataDialog.svelte.d.ts +0 -1
  69. package/dist/src/lib/components/OSDViewer.svelte.d.ts +0 -1
  70. package/dist/src/lib/components/SearchPanel.svelte.d.ts +0 -1
  71. package/dist/src/lib/components/ThumbnailGallery.svelte.d.ts +0 -1
  72. package/dist/src/lib/components/TriiiceratopsViewer.svelte.d.ts +0 -1
  73. package/dist/src/lib/custom-element-image.d.ts +0 -0
  74. package/dist/src/lib/custom-element.d.ts +0 -0
  75. package/dist/src/lib/paraglide/messages/de.d.ts +0 -96
  76. package/dist/src/lib/paraglide/messages/en.d.ts +0 -96
  77. package/dist/src/lib/paraglide/messages.d.ts +0 -272
  78. package/dist/src/lib/paraglide/runtime.d.ts +0 -52
  79. package/dist/src/lib/plugins/image-manipulation/ImageManipulationPanel.svelte.d.ts +0 -1
  80. package/dist/src/lib/state/i18n.svelte.d.ts +0 -5
  81. package/dist/triiiceratops.css +0 -1
  82. /package/dist/{src/lib/index.d.ts → index.d.ts} +0 -0
  83. /package/dist/{src/lib/plugins → plugins}/image-manipulation/index.d.ts +0 -0
  84. /package/dist/{src/lib/plugins → plugins}/image-manipulation/types.d.ts +0 -0
  85. /package/dist/{src/lib/state → state}/manifests.svelte.d.ts +0 -0
  86. /package/dist/{src/lib/theme → theme}/colorUtils.d.ts +0 -0
  87. /package/dist/{src/lib/theme → theme}/index.d.ts +0 -0
  88. /package/dist/{src/lib/theme → theme}/types.d.ts +0 -0
  89. /package/dist/{src/lib/types → types}/config.d.ts +0 -0
  90. /package/dist/{src/lib/utils → utils}/annotationAdapter.d.ts +0 -0
@@ -0,0 +1,134 @@
1
+ <script lang="ts">
2
+ import X from 'phosphor-svelte/lib/X';
3
+ import ArrowCounterClockwise from 'phosphor-svelte/lib/ArrowCounterClockwise';
4
+ import type { ImageFilters } from './types';
5
+
6
+ let {
7
+ filters,
8
+ onFilterChange,
9
+ onReset,
10
+ onClose,
11
+ }: {
12
+ filters: ImageFilters;
13
+ onFilterChange: (filters: ImageFilters) => void;
14
+ onReset: () => void;
15
+ onClose: () => void;
16
+ } = $props();
17
+
18
+ function updateFilter<K extends keyof ImageFilters>(
19
+ key: K,
20
+ value: ImageFilters[K],
21
+ ) {
22
+ onFilterChange({ ...filters, [key]: value });
23
+ }
24
+ </script>
25
+
26
+ <div
27
+ class="w-72 h-full bg-base-200 border-l border-base-300 shadow-xl flex flex-col"
28
+ >
29
+ <!-- Header -->
30
+ <div class="flex items-center justify-between p-4 border-b border-base-300">
31
+ <h2 class="text-lg font-semibold">Image Adjustments</h2>
32
+ <button
33
+ class="btn btn-sm btn-ghost btn-circle"
34
+ onclick={onClose}
35
+ aria-label="Close panel"
36
+ >
37
+ <X size={20} />
38
+ </button>
39
+ </div>
40
+
41
+ <!-- Sliders -->
42
+ <div class="flex-1 overflow-y-auto p-4 space-y-6">
43
+ <!-- Brightness -->
44
+ <div class="form-control">
45
+ <label class="label" for="brightness-slider">
46
+ <span class="label-text">Brightness</span>
47
+ <span class="label-text-alt">{filters.brightness}%</span>
48
+ </label>
49
+ <input
50
+ id="brightness-slider"
51
+ type="range"
52
+ min="0"
53
+ max="200"
54
+ value={filters.brightness}
55
+ oninput={(e) =>
56
+ updateFilter('brightness', +e.currentTarget.value)}
57
+ class="range range-sm range-primary"
58
+ />
59
+ </div>
60
+
61
+ <!-- Contrast -->
62
+ <div class="form-control">
63
+ <label class="label" for="contrast-slider">
64
+ <span class="label-text">Contrast</span>
65
+ <span class="label-text-alt">{filters.contrast}%</span>
66
+ </label>
67
+ <input
68
+ id="contrast-slider"
69
+ type="range"
70
+ min="0"
71
+ max="200"
72
+ value={filters.contrast}
73
+ oninput={(e) =>
74
+ updateFilter('contrast', +e.currentTarget.value)}
75
+ class="range range-sm range-secondary"
76
+ />
77
+ </div>
78
+
79
+ <!-- Saturation -->
80
+ <div class="form-control">
81
+ <label class="label" for="saturation-slider">
82
+ <span class="label-text">Saturation</span>
83
+ <span class="label-text-alt">{filters.saturation}%</span>
84
+ </label>
85
+ <input
86
+ id="saturation-slider"
87
+ type="range"
88
+ min="0"
89
+ max="200"
90
+ value={filters.saturation}
91
+ oninput={(e) =>
92
+ updateFilter('saturation', +e.currentTarget.value)}
93
+ class="range range-sm range-accent"
94
+ />
95
+ </div>
96
+
97
+ <!-- Effects -->
98
+ <div class="divider">Effects</div>
99
+
100
+ <div class="form-control">
101
+ <label class="label cursor-pointer">
102
+ <span class="label-text">Invert Colors</span>
103
+ <input
104
+ type="checkbox"
105
+ checked={filters.invert}
106
+ onchange={(e) =>
107
+ updateFilter('invert', e.currentTarget.checked)}
108
+ class="toggle toggle-primary"
109
+ />
110
+ </label>
111
+ </div>
112
+
113
+ <div class="form-control">
114
+ <label class="label cursor-pointer">
115
+ <span class="label-text">Grayscale</span>
116
+ <input
117
+ type="checkbox"
118
+ checked={filters.grayscale}
119
+ onchange={(e) =>
120
+ updateFilter('grayscale', e.currentTarget.checked)}
121
+ class="toggle toggle-secondary"
122
+ />
123
+ </label>
124
+ </div>
125
+ </div>
126
+
127
+ <!-- Footer -->
128
+ <div class="p-4 border-t border-base-300">
129
+ <button class="btn btn-outline btn-block" onclick={onReset}>
130
+ <ArrowCounterClockwise size={20} />
131
+ Reset to Default
132
+ </button>
133
+ </div>
134
+ </div>
@@ -0,0 +1,10 @@
1
+ import type { ImageFilters } from './types';
2
+ type $$ComponentProps = {
3
+ filters: ImageFilters;
4
+ onFilterChange: (filters: ImageFilters) => void;
5
+ onReset: () => void;
6
+ onClose: () => void;
7
+ };
8
+ declare const ImageManipulationPanel: import("svelte").Component<$$ComponentProps, {}, "">;
9
+ type ImageManipulationPanel = ReturnType<typeof ImageManipulationPanel>;
10
+ export default ImageManipulationPanel;
@@ -1,6 +1,6 @@
1
- import { BasePlugin, PluginContext } from '../../types/plugin';
2
- import { ImageFilters } from './types';
3
1
  type OSDViewer = import('openseadragon').OpenSeadragon.Viewer;
2
+ import { BasePlugin, type PluginContext } from '../../types/plugin';
3
+ import { type ImageFilters } from './types';
4
4
  export declare class ImageManipulationPlugin extends BasePlugin {
5
5
  readonly id = "image-manipulation";
6
6
  readonly name = "Image Manipulation";
@@ -0,0 +1,122 @@
1
+ var __extends = (this && this.__extends) || (function () {
2
+ var extendStatics = function (d, b) {
3
+ extendStatics = Object.setPrototypeOf ||
4
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
+ return extendStatics(d, b);
7
+ };
8
+ return function (d, b) {
9
+ if (typeof b !== "function" && b !== null)
10
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
11
+ extendStatics(d, b);
12
+ function __() { this.constructor = d; }
13
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14
+ };
15
+ })();
16
+ var __assign = (this && this.__assign) || function () {
17
+ __assign = Object.assign || function(t) {
18
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
19
+ s = arguments[i];
20
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
21
+ t[p] = s[p];
22
+ }
23
+ return t;
24
+ };
25
+ return __assign.apply(this, arguments);
26
+ };
27
+ import Sliders from 'phosphor-svelte/lib/Sliders';
28
+ import { BasePlugin } from '../../types/plugin';
29
+ import { applyFilters, clearFilters, hasActiveFilters } from './filters';
30
+ import { DEFAULT_FILTERS } from './types';
31
+ import ImageManipulationPanel from './ImageManipulationPanel.svelte';
32
+ import { m } from '../../state/i18n.svelte';
33
+ var ImageManipulationPlugin = /** @class */ (function (_super) {
34
+ __extends(ImageManipulationPlugin, _super);
35
+ function ImageManipulationPlugin() {
36
+ var _this = _super !== null && _super.apply(this, arguments) || this;
37
+ _this.id = 'image-manipulation';
38
+ _this.name = 'Image Manipulation';
39
+ _this.version = '1.0.0';
40
+ // Reactive state using Svelte 5 runes
41
+ _this._panelOpen = $state(false);
42
+ _this._filters = $state(__assign({}, DEFAULT_FILTERS));
43
+ _this.osd = null;
44
+ return _this;
45
+ }
46
+ ImageManipulationPlugin.prototype.onRegister = function (context) {
47
+ var _this = this;
48
+ _super.prototype.onRegister.call(this, context);
49
+ // Register menu button
50
+ context.registerMenuButton({
51
+ id: "".concat(this.id, ":toggle"),
52
+ icon: Sliders,
53
+ get tooltip() {
54
+ return m.image_adjustments();
55
+ },
56
+ onClick: function () { return _this.togglePanel(); },
57
+ isActive: function () { return _this._panelOpen; },
58
+ activeClass: 'btn-secondary',
59
+ order: 50,
60
+ });
61
+ // Register panel
62
+ context.registerPanel({
63
+ id: "".concat(this.id, ":panel"),
64
+ component: ImageManipulationPanel,
65
+ position: 'left',
66
+ isVisible: function () { return _this._panelOpen; },
67
+ props: {
68
+ filters: this._filters,
69
+ onFilterChange: function (f) { return _this.setFilters(f); },
70
+ onReset: function () { return _this.resetFilters(); },
71
+ onClose: function () { return _this.togglePanel(); },
72
+ },
73
+ });
74
+ };
75
+ ImageManipulationPlugin.prototype.onViewerReady = function (viewer) {
76
+ var _this = this;
77
+ this.osd = viewer;
78
+ // Apply existing filters if any
79
+ if (hasActiveFilters(this._filters)) {
80
+ applyFilters(viewer, this._filters);
81
+ }
82
+ // Re-apply filters when new images unlock (canvas change)
83
+ this.osd.addHandler('open', function () {
84
+ if (_this.osd && hasActiveFilters(_this._filters)) {
85
+ applyFilters(_this.osd, _this._filters);
86
+ }
87
+ });
88
+ };
89
+ ImageManipulationPlugin.prototype.onDestroy = function () {
90
+ if (this.osd) {
91
+ clearFilters(this.osd);
92
+ }
93
+ this.osd = null;
94
+ _super.prototype.onDestroy.call(this);
95
+ };
96
+ // Public API
97
+ ImageManipulationPlugin.prototype.togglePanel = function () {
98
+ this._panelOpen = !this._panelOpen;
99
+ };
100
+ ImageManipulationPlugin.prototype.setFilters = function (filters) {
101
+ // Mutate properties to maintain reference for bound props
102
+ this._filters.brightness = filters.brightness;
103
+ this._filters.contrast = filters.contrast;
104
+ this._filters.saturation = filters.saturation;
105
+ this._filters.invert = filters.invert;
106
+ this._filters.grayscale = filters.grayscale;
107
+ if (this.osd) {
108
+ applyFilters(this.osd, filters);
109
+ }
110
+ };
111
+ ImageManipulationPlugin.prototype.resetFilters = function () {
112
+ Object.assign(this._filters, DEFAULT_FILTERS);
113
+ if (this.osd) {
114
+ clearFilters(this.osd);
115
+ }
116
+ };
117
+ ImageManipulationPlugin.prototype.getFilters = function () {
118
+ return __assign({}, this._filters);
119
+ };
120
+ return ImageManipulationPlugin;
121
+ }(BasePlugin));
122
+ export { ImageManipulationPlugin };
@@ -1,4 +1,4 @@
1
- import { ImageFilters } from './types';
1
+ import type { ImageFilters } from './types';
2
2
  type OSDViewer = {
3
3
  drawer?: {
4
4
  canvas?: HTMLCanvasElement;
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Apply CSS filters to the OpenSeadragon canvas element.
3
+ * CSS filters are GPU-accelerated and work without modifying OSD internals.
4
+ */
5
+ export function applyFilters(viewer, filters) {
6
+ var _a;
7
+ // OSD uses either canvas or webgl drawer
8
+ var canvas = (_a = viewer.drawer) === null || _a === void 0 ? void 0 : _a.canvas;
9
+ if (!canvas)
10
+ return;
11
+ var parts = [];
12
+ if (filters.brightness !== 100) {
13
+ parts.push("brightness(".concat(filters.brightness / 100, ")"));
14
+ }
15
+ if (filters.contrast !== 100) {
16
+ parts.push("contrast(".concat(filters.contrast / 100, ")"));
17
+ }
18
+ if (filters.saturation !== 100) {
19
+ parts.push("saturate(".concat(filters.saturation / 100, ")"));
20
+ }
21
+ if (filters.invert) {
22
+ parts.push('invert(1)');
23
+ }
24
+ if (filters.grayscale) {
25
+ parts.push('grayscale(1)');
26
+ }
27
+ canvas.style.filter = parts.length > 0 ? parts.join(' ') : 'none';
28
+ }
29
+ /**
30
+ * Remove all filters from the canvas.
31
+ */
32
+ export function clearFilters(viewer) {
33
+ var _a;
34
+ var canvas = (_a = viewer.drawer) === null || _a === void 0 ? void 0 : _a.canvas;
35
+ if (canvas) {
36
+ canvas.style.filter = 'none';
37
+ }
38
+ }
39
+ /**
40
+ * Check if any filters are active (not at default values).
41
+ */
42
+ export function hasActiveFilters(filters) {
43
+ return (filters.brightness !== 100 ||
44
+ filters.contrast !== 100 ||
45
+ filters.saturation !== 100 ||
46
+ filters.invert ||
47
+ filters.grayscale);
48
+ }
@@ -0,0 +1,2 @@
1
+ export { ImageManipulationPlugin } from './ImageManipulationPlugin.svelte';
2
+ export { DEFAULT_FILTERS } from './types';
@@ -0,0 +1,7 @@
1
+ export var DEFAULT_FILTERS = {
2
+ brightness: 100,
3
+ contrast: 100,
4
+ saturation: 100,
5
+ invert: false,
6
+ grayscale: false,
7
+ };
@@ -0,0 +1,4 @@
1
+ export declare const language: {
2
+ readonly current: any;
3
+ };
4
+ export declare const m: any;
@@ -0,0 +1,18 @@
1
+ import * as messages from "../paraglide/messages.js";
2
+ import { languageTag, onSetLanguageTag } from "../paraglide/runtime.js";
3
+ var tag = $state(languageTag());
4
+ onSetLanguageTag(function (newTag) {
5
+ tag = newTag;
6
+ });
7
+ export var language = {
8
+ get current() {
9
+ return tag;
10
+ }
11
+ };
12
+ export var m = new Proxy(messages, {
13
+ get: function (target, prop, receiver) {
14
+ // Register dependency by accessing the signal
15
+ tag;
16
+ return Reflect.get(target, prop, receiver);
17
+ }
18
+ });
@@ -0,0 +1,210 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
12
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
+ }
36
+ };
37
+ import * as manifesto from "manifesto.js";
38
+ var ManifestsState = /** @class */ (function () {
39
+ function ManifestsState() {
40
+ this.manifests = $state({});
41
+ }
42
+ ManifestsState.prototype.fetchManifest = function (manifestId) {
43
+ return __awaiter(this, void 0, void 0, function () {
44
+ var response, json, manifestoObject, error_1;
45
+ return __generator(this, function (_a) {
46
+ switch (_a.label) {
47
+ case 0:
48
+ if (this.manifests[manifestId]) {
49
+ return [2 /*return*/]; // Already fetched or fetching
50
+ }
51
+ this.manifests[manifestId] = { isFetching: true };
52
+ _a.label = 1;
53
+ case 1:
54
+ _a.trys.push([1, 4, , 5]);
55
+ return [4 /*yield*/, fetch(manifestId)];
56
+ case 2:
57
+ response = _a.sent();
58
+ if (!response.ok) {
59
+ throw new Error("HTTP error! status: ".concat(response.status));
60
+ }
61
+ return [4 /*yield*/, response.json()];
62
+ case 3:
63
+ json = _a.sent();
64
+ manifestoObject = manifesto.parseManifest(json);
65
+ this.manifests[manifestId] = {
66
+ json: json,
67
+ manifesto: manifestoObject,
68
+ isFetching: false,
69
+ };
70
+ return [3 /*break*/, 5];
71
+ case 4:
72
+ error_1 = _a.sent();
73
+ this.manifests[manifestId] = { error: error_1.message, isFetching: false };
74
+ return [3 /*break*/, 5];
75
+ case 5: return [2 /*return*/];
76
+ }
77
+ });
78
+ });
79
+ };
80
+ ManifestsState.prototype.getManifest = function (manifestId) {
81
+ var entry = this.manifests[manifestId];
82
+ return entry === null || entry === void 0 ? void 0 : entry.manifesto;
83
+ };
84
+ ManifestsState.prototype.fetchAnnotationList = function (url) {
85
+ return __awaiter(this, void 0, void 0, function () {
86
+ var response, data, e_1;
87
+ return __generator(this, function (_a) {
88
+ switch (_a.label) {
89
+ case 0:
90
+ if (this.manifests[url])
91
+ return [2 /*return*/]; // Already fetched or fetching
92
+ _a.label = 1;
93
+ case 1:
94
+ _a.trys.push([1, 6, , 7]);
95
+ return [4 /*yield*/, fetch(url)];
96
+ case 2:
97
+ response = _a.sent();
98
+ if (!response.ok) return [3 /*break*/, 4];
99
+ return [4 /*yield*/, response.json()];
100
+ case 3:
101
+ data = _a.sent();
102
+ this.manifests[url] = { json: data };
103
+ return [3 /*break*/, 5];
104
+ case 4:
105
+ console.error("Failed to fetch annotation list: ".concat(url));
106
+ _a.label = 5;
107
+ case 5: return [3 /*break*/, 7];
108
+ case 6:
109
+ e_1 = _a.sent();
110
+ console.error("Error fetching annotation list: ".concat(url), e_1);
111
+ return [3 /*break*/, 7];
112
+ case 7: return [2 /*return*/];
113
+ }
114
+ });
115
+ });
116
+ };
117
+ ManifestsState.prototype.getCanvases = function (manifestId) {
118
+ var m = this.getManifest(manifestId);
119
+ if (!m) {
120
+ return [];
121
+ }
122
+ var sequences = m.getSequences();
123
+ if (!sequences || !sequences.length)
124
+ return [];
125
+ var canvases = sequences[0].getCanvases();
126
+ return canvases;
127
+ };
128
+ ManifestsState.prototype.getAnnotations = function (manifestId, canvasId) {
129
+ var m = this.getManifest(manifestId);
130
+ if (!m)
131
+ return [];
132
+ var canvas = m.getSequences()[0].getCanvasById(canvasId);
133
+ if (!canvas)
134
+ return [];
135
+ var annos = this.manualGetAnnotations(manifestId, canvasId);
136
+ return annos;
137
+ };
138
+ // We can refactor this to use Manifesto's resource handling later if needed.
139
+ ManifestsState.prototype.manualGetAnnotations = function (manifestId, canvasId) {
140
+ var _this = this;
141
+ var manifestoObject = this.getManifest(manifestId);
142
+ if (!manifestoObject)
143
+ return [];
144
+ var canvas = manifestoObject.getSequences()[0].getCanvasById(canvasId);
145
+ if (!canvas)
146
+ return [];
147
+ // Manifesto wraps the JSON. We can access the underlying JSON via canvas.__jsonld
148
+ // Or better, use canvas.getContent() if it works, but for external lists manual fetch is robust.
149
+ var canvasJson = canvas.__jsonld;
150
+ var annotations = [];
151
+ // Helper to parse list using Manifesto
152
+ var parseList = function (listJson) {
153
+ // manifesto.create is not available in 4.3.0 or not exported nicely?
154
+ // Just return raw resources.
155
+ return listJson.resources || listJson.items || [];
156
+ };
157
+ // IIIF v2 otherContent
158
+ if (canvasJson.otherContent) {
159
+ canvasJson.otherContent.forEach(function (content) {
160
+ var id = content["@id"] || content.id;
161
+ if (id && !content.resources) {
162
+ var externalList = _this.manifests[id];
163
+ if (externalList) {
164
+ if (externalList.json) {
165
+ var parsed = parseList(externalList.json);
166
+ annotations.push.apply(annotations, parsed);
167
+ }
168
+ }
169
+ else {
170
+ _this.fetchAnnotationList(id);
171
+ }
172
+ }
173
+ else if (content.resources) {
174
+ // It's embedded
175
+ // We can wrap this in manifesto.create too if we wrap it in a list structure?
176
+ // Or just use raw for embedded for now, but mixed types might be annoying.
177
+ // Let's rely on the robust parsing I added to Overlay for raw/mixed.
178
+ // But the user wants library usage.
179
+ // const r = manifesto.create(content); // might work?
180
+ annotations.push.apply(annotations, content.resources);
181
+ }
182
+ });
183
+ }
184
+ // IIIF v3 annotations
185
+ if (canvasJson.annotations) {
186
+ canvasJson.annotations.forEach(function (content) {
187
+ var id = content.id || content["@id"];
188
+ if (id && !content.items) {
189
+ var externalList = _this.manifests[id];
190
+ if (externalList) {
191
+ if (externalList.json) {
192
+ var parsed = parseList(externalList.json);
193
+ annotations.push.apply(annotations, parsed);
194
+ }
195
+ }
196
+ else {
197
+ _this.fetchAnnotationList(id);
198
+ }
199
+ }
200
+ else if (content.items) {
201
+ annotations.push.apply(annotations, content.items);
202
+ }
203
+ });
204
+ }
205
+ return annotations;
206
+ };
207
+ return ManifestsState;
208
+ }());
209
+ export { ManifestsState };
210
+ export var manifestsState = new ManifestsState();
@@ -0,0 +1 @@
1
+ export {};