triiiceratops 0.9.1 → 0.9.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2 @@
1
+ import '../app.css';
2
+ export * from './index';
@@ -0,0 +1,2 @@
1
+ import '../app.css';
2
+ export * from './index';
@@ -1,103 +1,70 @@
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
1
  import Sliders from 'phosphor-svelte/lib/Sliders';
28
2
  import { BasePlugin } from '../../types/plugin';
29
3
  import { applyFilters, clearFilters, hasActiveFilters } from './filters';
30
4
  import { DEFAULT_FILTERS } from './types';
31
5
  import ImageManipulationPanel from './ImageManipulationPanel.svelte';
32
6
  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);
7
+ export class ImageManipulationPlugin extends BasePlugin {
8
+ id = 'image-manipulation';
9
+ name = 'Image Manipulation';
10
+ version = '1.0.0';
11
+ // Reactive state using Svelte 5 runes
12
+ _panelOpen = $state(false);
13
+ _filters = $state({ ...DEFAULT_FILTERS });
14
+ osd = null;
15
+ onRegister(context) {
16
+ super.onRegister(context);
49
17
  // Register menu button
50
18
  context.registerMenuButton({
51
- id: "".concat(this.id, ":toggle"),
19
+ id: `${this.id}:toggle`,
52
20
  icon: Sliders,
53
21
  get tooltip() {
54
22
  return m.image_adjustments();
55
23
  },
56
- onClick: function () { return _this.togglePanel(); },
57
- isActive: function () { return _this._panelOpen; },
24
+ onClick: () => this.togglePanel(),
25
+ isActive: () => this._panelOpen,
58
26
  activeClass: 'btn-secondary',
59
27
  order: 50,
60
28
  });
61
29
  // Register panel
62
30
  context.registerPanel({
63
- id: "".concat(this.id, ":panel"),
31
+ id: `${this.id}:panel`,
64
32
  component: ImageManipulationPanel,
65
33
  position: 'left',
66
- isVisible: function () { return _this._panelOpen; },
34
+ isVisible: () => this._panelOpen,
67
35
  props: {
68
36
  filters: this._filters,
69
- onFilterChange: function (f) { return _this.setFilters(f); },
70
- onReset: function () { return _this.resetFilters(); },
71
- onClose: function () { return _this.togglePanel(); },
37
+ onFilterChange: (f) => this.setFilters(f),
38
+ onReset: () => this.resetFilters(),
39
+ onClose: () => this.togglePanel(),
72
40
  },
73
41
  });
74
- };
75
- ImageManipulationPlugin.prototype.onViewerReady = function (viewer) {
76
- var _this = this;
42
+ }
43
+ onViewerReady(viewer) {
77
44
  this.osd = viewer;
78
45
  // Apply existing filters if any
79
46
  if (hasActiveFilters(this._filters)) {
80
47
  applyFilters(viewer, this._filters);
81
48
  }
82
49
  // 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);
50
+ this.osd.addHandler('open', () => {
51
+ if (this.osd && hasActiveFilters(this._filters)) {
52
+ applyFilters(this.osd, this._filters);
86
53
  }
87
54
  });
88
- };
89
- ImageManipulationPlugin.prototype.onDestroy = function () {
55
+ }
56
+ onDestroy() {
90
57
  if (this.osd) {
91
58
  clearFilters(this.osd);
92
59
  }
93
60
  this.osd = null;
94
- _super.prototype.onDestroy.call(this);
95
- };
61
+ super.onDestroy();
62
+ }
96
63
  // Public API
97
- ImageManipulationPlugin.prototype.togglePanel = function () {
64
+ togglePanel() {
98
65
  this._panelOpen = !this._panelOpen;
99
- };
100
- ImageManipulationPlugin.prototype.setFilters = function (filters) {
66
+ }
67
+ setFilters(filters) {
101
68
  // Mutate properties to maintain reference for bound props
102
69
  this._filters.brightness = filters.brightness;
103
70
  this._filters.contrast = filters.contrast;
@@ -107,16 +74,14 @@ var ImageManipulationPlugin = /** @class */ (function (_super) {
107
74
  if (this.osd) {
108
75
  applyFilters(this.osd, filters);
109
76
  }
110
- };
111
- ImageManipulationPlugin.prototype.resetFilters = function () {
77
+ }
78
+ resetFilters() {
112
79
  Object.assign(this._filters, DEFAULT_FILTERS);
113
80
  if (this.osd) {
114
81
  clearFilters(this.osd);
115
82
  }
116
- };
117
- ImageManipulationPlugin.prototype.getFilters = function () {
118
- return __assign({}, this._filters);
119
- };
120
- return ImageManipulationPlugin;
121
- }(BasePlugin));
122
- export { ImageManipulationPlugin };
83
+ }
84
+ getFilters() {
85
+ return { ...this._filters };
86
+ }
87
+ }
@@ -3,20 +3,19 @@
3
3
  * CSS filters are GPU-accelerated and work without modifying OSD internals.
4
4
  */
5
5
  export function applyFilters(viewer, filters) {
6
- var _a;
7
6
  // OSD uses either canvas or webgl drawer
8
- var canvas = (_a = viewer.drawer) === null || _a === void 0 ? void 0 : _a.canvas;
7
+ const canvas = viewer.drawer?.canvas;
9
8
  if (!canvas)
10
9
  return;
11
- var parts = [];
10
+ const parts = [];
12
11
  if (filters.brightness !== 100) {
13
- parts.push("brightness(".concat(filters.brightness / 100, ")"));
12
+ parts.push(`brightness(${filters.brightness / 100})`);
14
13
  }
15
14
  if (filters.contrast !== 100) {
16
- parts.push("contrast(".concat(filters.contrast / 100, ")"));
15
+ parts.push(`contrast(${filters.contrast / 100})`);
17
16
  }
18
17
  if (filters.saturation !== 100) {
19
- parts.push("saturate(".concat(filters.saturation / 100, ")"));
18
+ parts.push(`saturate(${filters.saturation / 100})`);
20
19
  }
21
20
  if (filters.invert) {
22
21
  parts.push('invert(1)');
@@ -30,8 +29,7 @@ export function applyFilters(viewer, filters) {
30
29
  * Remove all filters from the canvas.
31
30
  */
32
31
  export function clearFilters(viewer) {
33
- var _a;
34
- var canvas = (_a = viewer.drawer) === null || _a === void 0 ? void 0 : _a.canvas;
32
+ const canvas = viewer.drawer?.canvas;
35
33
  if (canvas) {
36
34
  canvas.style.filter = 'none';
37
35
  }
@@ -1,4 +1,4 @@
1
- export var DEFAULT_FILTERS = {
1
+ export const DEFAULT_FILTERS = {
2
2
  brightness: 100,
3
3
  contrast: 100,
4
4
  saturation: 100,
@@ -1,4 +1,5 @@
1
+ import * as messages from "../paraglide/messages.js";
1
2
  export declare const language: {
2
- readonly current: any;
3
+ readonly current: "en" | "de";
3
4
  };
4
- export declare const m: any;
5
+ export declare const m: typeof messages;
@@ -1,16 +1,16 @@
1
1
  import * as messages from "../paraglide/messages.js";
2
2
  import { languageTag, onSetLanguageTag } from "../paraglide/runtime.js";
3
- var tag = $state(languageTag());
4
- onSetLanguageTag(function (newTag) {
3
+ let tag = $state(languageTag());
4
+ onSetLanguageTag((newTag) => {
5
5
  tag = newTag;
6
6
  });
7
- export var language = {
7
+ export const language = {
8
8
  get current() {
9
9
  return tag;
10
10
  }
11
11
  };
12
- export var m = new Proxy(messages, {
13
- get: function (target, prop, receiver) {
12
+ export const m = new Proxy(messages, {
13
+ get(target, prop, receiver) {
14
14
  // Register dependency by accessing the signal
15
15
  tag;
16
16
  return Reflect.get(target, prop, receiver);
@@ -1,173 +1,103 @@
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;
1
+ import * as manifesto from "manifesto.js";
2
+ export class ManifestsState {
3
+ manifests = $state({});
4
+ constructor() { }
5
+ async fetchManifest(manifestId) {
6
+ if (this.manifests[manifestId]) {
7
+ return; // Already fetched or fetching
8
+ }
9
+ this.manifests[manifestId] = { isFetching: true };
10
+ try {
11
+ const response = await fetch(manifestId);
12
+ if (!response.ok) {
13
+ throw new Error(`HTTP error! status: ${response.status}`);
31
14
  }
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 };
15
+ const json = await response.json();
16
+ const manifestoObject = manifesto.parseManifest(json);
17
+ this.manifests[manifestId] = {
18
+ json,
19
+ manifesto: manifestoObject,
20
+ isFetching: false,
21
+ };
22
+ }
23
+ catch (error) {
24
+ this.manifests[manifestId] = { error: error.message, isFetching: false };
25
+ }
35
26
  }
36
- };
37
- import * as manifesto from "manifesto.js";
38
- var ManifestsState = /** @class */ (function () {
39
- function ManifestsState() {
40
- this.manifests = $state({});
27
+ getManifest(manifestId) {
28
+ const entry = this.manifests[manifestId];
29
+ return entry?.manifesto;
41
30
  }
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);
31
+ async fetchAnnotationList(url) {
32
+ if (this.manifests[url])
33
+ return; // Already fetched or fetching
34
+ try {
35
+ const response = await fetch(url);
36
+ if (response.ok) {
37
+ const data = await response.json();
38
+ this.manifests[url] = { json: data };
39
+ }
40
+ else {
41
+ console.error(`Failed to fetch annotation list: ${url}`);
42
+ }
43
+ }
44
+ catch (e) {
45
+ console.error(`Error fetching annotation list: ${url}`, e);
46
+ }
47
+ }
48
+ getCanvases(manifestId) {
49
+ const m = this.getManifest(manifestId);
119
50
  if (!m) {
120
51
  return [];
121
52
  }
122
- var sequences = m.getSequences();
53
+ const sequences = m.getSequences();
123
54
  if (!sequences || !sequences.length)
124
55
  return [];
125
- var canvases = sequences[0].getCanvases();
56
+ const canvases = sequences[0].getCanvases();
126
57
  return canvases;
127
- };
128
- ManifestsState.prototype.getAnnotations = function (manifestId, canvasId) {
129
- var m = this.getManifest(manifestId);
58
+ }
59
+ getAnnotations(manifestId, canvasId) {
60
+ const m = this.getManifest(manifestId);
130
61
  if (!m)
131
62
  return [];
132
- var canvas = m.getSequences()[0].getCanvasById(canvasId);
63
+ const canvas = m.getSequences()[0].getCanvasById(canvasId);
133
64
  if (!canvas)
134
65
  return [];
135
- var annos = this.manualGetAnnotations(manifestId, canvasId);
66
+ const annos = this.manualGetAnnotations(manifestId, canvasId);
136
67
  return annos;
137
- };
68
+ }
138
69
  // 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);
70
+ manualGetAnnotations(manifestId, canvasId) {
71
+ const manifestoObject = this.getManifest(manifestId);
142
72
  if (!manifestoObject)
143
73
  return [];
144
- var canvas = manifestoObject.getSequences()[0].getCanvasById(canvasId);
74
+ const canvas = manifestoObject.getSequences()[0].getCanvasById(canvasId);
145
75
  if (!canvas)
146
76
  return [];
147
77
  // Manifesto wraps the JSON. We can access the underlying JSON via canvas.__jsonld
148
78
  // Or better, use canvas.getContent() if it works, but for external lists manual fetch is robust.
149
- var canvasJson = canvas.__jsonld;
150
- var annotations = [];
79
+ const canvasJson = canvas.__jsonld;
80
+ let annotations = [];
151
81
  // Helper to parse list using Manifesto
152
- var parseList = function (listJson) {
82
+ const parseList = (listJson) => {
153
83
  // manifesto.create is not available in 4.3.0 or not exported nicely?
154
84
  // Just return raw resources.
155
85
  return listJson.resources || listJson.items || [];
156
86
  };
157
87
  // IIIF v2 otherContent
158
88
  if (canvasJson.otherContent) {
159
- canvasJson.otherContent.forEach(function (content) {
160
- var id = content["@id"] || content.id;
89
+ canvasJson.otherContent.forEach((content) => {
90
+ const id = content["@id"] || content.id;
161
91
  if (id && !content.resources) {
162
- var externalList = _this.manifests[id];
92
+ const externalList = this.manifests[id];
163
93
  if (externalList) {
164
94
  if (externalList.json) {
165
- var parsed = parseList(externalList.json);
166
- annotations.push.apply(annotations, parsed);
95
+ const parsed = parseList(externalList.json);
96
+ annotations.push(...parsed);
167
97
  }
168
98
  }
169
99
  else {
170
- _this.fetchAnnotationList(id);
100
+ this.fetchAnnotationList(id);
171
101
  }
172
102
  }
173
103
  else if (content.resources) {
@@ -177,34 +107,32 @@ var ManifestsState = /** @class */ (function () {
177
107
  // Let's rely on the robust parsing I added to Overlay for raw/mixed.
178
108
  // But the user wants library usage.
179
109
  // const r = manifesto.create(content); // might work?
180
- annotations.push.apply(annotations, content.resources);
110
+ annotations.push(...content.resources);
181
111
  }
182
112
  });
183
113
  }
184
114
  // IIIF v3 annotations
185
115
  if (canvasJson.annotations) {
186
- canvasJson.annotations.forEach(function (content) {
187
- var id = content.id || content["@id"];
116
+ canvasJson.annotations.forEach((content) => {
117
+ const id = content.id || content["@id"];
188
118
  if (id && !content.items) {
189
- var externalList = _this.manifests[id];
119
+ const externalList = this.manifests[id];
190
120
  if (externalList) {
191
121
  if (externalList.json) {
192
- var parsed = parseList(externalList.json);
193
- annotations.push.apply(annotations, parsed);
122
+ const parsed = parseList(externalList.json);
123
+ annotations.push(...parsed);
194
124
  }
195
125
  }
196
126
  else {
197
- _this.fetchAnnotationList(id);
127
+ this.fetchAnnotationList(id);
198
128
  }
199
129
  }
200
130
  else if (content.items) {
201
- annotations.push.apply(annotations, content.items);
131
+ annotations.push(...content.items);
202
132
  }
203
133
  });
204
134
  }
205
135
  return annotations;
206
- };
207
- return ManifestsState;
208
- }());
209
- export { ManifestsState };
210
- export var manifestsState = new ManifestsState();
136
+ }
137
+ }
138
+ export const manifestsState = new ManifestsState();