triiiceratops 0.8.1 → 0.9.0
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/dist/chunks/TriiiceratopsViewer-BGtsfUPF.js +10298 -0
- package/dist/chunks/openseadragon-BTypULhm.js +12427 -0
- package/dist/components/AnnotationOverlay.svelte +288 -0
- package/dist/components/AnnotationOverlay.svelte.d.ts +3 -0
- package/dist/components/CanvasNavigation.svelte +32 -0
- package/dist/components/CanvasNavigation.svelte.d.ts +11 -0
- package/dist/components/DemoHeader.svelte +703 -0
- package/dist/components/DemoHeader.svelte.d.ts +9 -0
- package/dist/components/FloatingMenu.svelte +208 -0
- package/dist/components/FloatingMenu.svelte.d.ts +3 -0
- package/dist/components/LeftFab.svelte +69 -0
- package/dist/components/LeftFab.svelte.d.ts +3 -0
- package/dist/components/MetadataDialog.svelte +151 -0
- package/dist/components/MetadataDialog.svelte.d.ts +3 -0
- package/dist/components/OSDViewer.svelte +260 -0
- package/dist/components/OSDViewer.svelte.d.ts +8 -0
- package/dist/components/SearchPanel.svelte +150 -0
- package/dist/components/SearchPanel.svelte.d.ts +3 -0
- package/dist/components/ThemeToggle.svelte +118 -0
- package/dist/components/ThemeToggle.svelte.d.ts +3 -0
- package/dist/components/ThumbnailGallery.svelte +601 -0
- package/dist/components/ThumbnailGallery.svelte.d.ts +36 -0
- package/dist/components/TriiiceratopsViewer.svelte +434 -0
- package/dist/components/TriiiceratopsViewer.svelte.d.ts +20 -0
- package/dist/components/TriiiceratopsViewerElement.svelte +139 -0
- package/dist/components/TriiiceratopsViewerElement.svelte.d.ts +27 -0
- package/dist/components/TriiiceratopsViewerElementImage.svelte +143 -0
- package/dist/components/TriiiceratopsViewerElementImage.svelte.d.ts +27 -0
- package/dist/custom-element-image.d.ts +1 -0
- package/dist/custom-element-image.js +2 -0
- package/dist/custom-element.d.ts +1 -0
- package/dist/custom-element.js +3 -0
- package/dist/{src/lib/index.d.ts → index.d.ts} +1 -0
- package/dist/index.js +10 -4480
- package/dist/plugins/image-manipulation/ImageManipulationPanel.svelte +134 -0
- package/dist/plugins/image-manipulation/ImageManipulationPanel.svelte.d.ts +10 -0
- package/dist/{src/lib/plugins → plugins}/image-manipulation/ImageManipulationPlugin.svelte.d.ts +2 -2
- package/dist/plugins/image-manipulation/ImageManipulationPlugin.svelte.js +122 -0
- package/dist/{src/lib/plugins → plugins}/image-manipulation/filters.d.ts +1 -1
- package/dist/plugins/image-manipulation/filters.js +48 -0
- package/dist/plugins/image-manipulation/index.js +2 -0
- package/dist/plugins/image-manipulation/types.js +7 -0
- package/dist/state/i18n.svelte.d.ts +4 -0
- package/dist/state/i18n.svelte.js +18 -0
- package/dist/state/manifests.svelte.js +210 -0
- package/dist/state/manifests.test.d.ts +1 -0
- package/dist/state/manifests.test.js +242 -0
- package/dist/{src/lib/state → state}/viewer.svelte.d.ts +4 -4
- package/dist/state/viewer.svelte.js +693 -0
- package/dist/theme/colorUtils.js +196 -0
- package/dist/theme/colorUtils.test.d.ts +1 -0
- package/dist/theme/colorUtils.test.js +90 -0
- package/dist/theme/index.js +52 -0
- package/dist/{src/lib/theme → theme}/themeManager.d.ts +4 -1
- package/dist/theme/themeManager.js +177 -0
- package/dist/theme/types.js +40 -0
- package/dist/triiiceratops-bundle.js +4676 -0
- package/dist/triiiceratops-element-image.js +1 -1
- package/dist/triiiceratops-element.js +1 -1
- package/dist/types/config.js +1 -0
- package/dist/{src/lib/types → types}/plugin.d.ts +3 -3
- package/dist/types/plugin.js +36 -0
- package/dist/utils/annotationAdapter.js +354 -0
- package/dist/utils/annotationAdapter.test.d.ts +1 -0
- package/dist/utils/annotationAdapter.test.js +91 -0
- package/package.json +6 -5
- package/dist/chunks/TriiiceratopsViewer-CyamQrMe.js +0 -22698
- package/dist/plugin-De14WKQl.js +0 -546
- package/dist/plugins/image-manipulation.js +0 -454
- package/dist/src/lib/components/AnnotationOverlay.svelte.d.ts +0 -1
- package/dist/src/lib/components/CanvasNavigation.svelte.d.ts +0 -1
- package/dist/src/lib/components/FloatingMenu.svelte.d.ts +0 -1
- package/dist/src/lib/components/LeftFab.svelte.d.ts +0 -1
- package/dist/src/lib/components/MetadataDialog.svelte.d.ts +0 -1
- package/dist/src/lib/components/OSDViewer.svelte.d.ts +0 -1
- package/dist/src/lib/components/SearchPanel.svelte.d.ts +0 -1
- package/dist/src/lib/components/ThumbnailGallery.svelte.d.ts +0 -1
- package/dist/src/lib/components/TriiiceratopsViewer.svelte.d.ts +0 -1
- package/dist/src/lib/custom-element-image.d.ts +0 -0
- package/dist/src/lib/custom-element.d.ts +0 -0
- package/dist/src/lib/paraglide/messages/de.d.ts +0 -96
- package/dist/src/lib/paraglide/messages/en.d.ts +0 -96
- package/dist/src/lib/paraglide/messages.d.ts +0 -272
- package/dist/src/lib/paraglide/runtime.d.ts +0 -52
- package/dist/src/lib/plugins/image-manipulation/ImageManipulationPanel.svelte.d.ts +0 -1
- package/dist/src/lib/state/i18n.svelte.d.ts +0 -5
- /package/dist/{src/lib/plugins → plugins}/image-manipulation/index.d.ts +0 -0
- /package/dist/{src/lib/plugins → plugins}/image-manipulation/types.d.ts +0 -0
- /package/dist/{src/lib/state → state}/manifests.svelte.d.ts +0 -0
- /package/dist/{src/lib/theme → theme}/colorUtils.d.ts +0 -0
- /package/dist/{src/lib/theme → theme}/index.d.ts +0 -0
- /package/dist/{src/lib/theme → theme}/types.d.ts +0 -0
- /package/dist/{src/lib/types → types}/config.d.ts +0 -0
- /package/dist/{src/lib/utils → utils}/annotationAdapter.d.ts +0 -0
|
@@ -5,7 +5,7 @@ var he = (a) => {
|
|
|
5
5
|
var Ce = (a, e, t) => e in a ? Ie(a, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : a[e] = t;
|
|
6
6
|
var K = (a, e, t) => Ce(a, typeof e != "symbol" ? e + "" : e, t), Me = (a, e, t) => e.has(a) || he("Cannot " + t);
|
|
7
7
|
var W = (a, e, t) => (Me(a, e, "read from private field"), t ? t.call(a) : e.get(a)), le = (a, e, t) => e.has(a) ? he("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(a) : e.set(a, t);
|
|
8
|
-
import { p as te, v as Ve, w as Z, x as we, i as v, y as A, e as f, g as i, k as O, r as c, m as s, n as ae, z as S, b as C, A as ye, B as ue, C as Ae, D as Ze, E as Se, f as xe, X as He, F as Y, G as Te, H as oe, I as ve, J as fe, s as de, j as ge, K as ke, L as Fe, c as Le, a as X, u as Oe, h as ze, T as Ee, l as Pe, d as Re, o as Be, q as De, t as Q } from "./chunks/TriiiceratopsViewer-
|
|
8
|
+
import { p as te, v as Ve, w as Z, x as we, i as v, y as A, e as f, g as i, k as O, r as c, m as s, n as ae, z as S, b as C, A as ye, B as ue, C as Ae, D as Ze, E as Se, f as xe, X as He, F as Y, G as Te, H as oe, I as ve, J as fe, s as de, j as ge, K as ke, L as Fe, c as Le, a as X, u as Oe, h as ze, T as Ee, l as Pe, d as Re, o as Be, q as De, t as Q } from "./chunks/TriiiceratopsViewer-BGtsfUPF.js";
|
|
9
9
|
var je = Z('<path d="M68,102.06V40a12,12,0,0,0-24,0v62.06a36,36,0,0,0,0,67.88V216a12,12,0,0,0,24,0V169.94a36,36,0,0,0,0-67.88ZM56,148a12,12,0,1,1,12-12A12,12,0,0,1,56,148ZM164,88a36.07,36.07,0,0,0-24-33.94V40a12,12,0,0,0-24,0V54.06a36,36,0,0,0,0,67.88V216a12,12,0,0,0,24,0V121.94A36.07,36.07,0,0,0,164,88Zm-36,12a12,12,0,1,1,12-12A12,12,0,0,1,128,100Zm108,68a36.07,36.07,0,0,0-24-33.94V40a12,12,0,0,0-24,0v94.06a36,36,0,0,0,0,67.88V216a12,12,0,0,0,24,0V201.94A36.07,36.07,0,0,0,236,168Zm-36,12a12,12,0,1,1,12-12A12,12,0,0,1,200,180Z"></path>'), Je = Z('<path d="M80,136a24,24,0,1,1-24-24A24,24,0,0,1,80,136Zm48-72a24,24,0,1,0,24,24A24,24,0,0,0,128,64Zm72,80a24,24,0,1,0,24,24A24,24,0,0,0,200,144Z" opacity="0.2"></path><path d="M64,105V40a8,8,0,0,0-16,0v65a32,32,0,0,0,0,62v49a8,8,0,0,0,16,0V167a32,32,0,0,0,0-62Zm-8,47a16,16,0,1,1,16-16A16,16,0,0,1,56,152Zm80-95V40a8,8,0,0,0-16,0V57a32,32,0,0,0,0,62v97a8,8,0,0,0,16,0V119a32,32,0,0,0,0-62Zm-8,47a16,16,0,1,1,16-16A16,16,0,0,1,128,104Zm104,64a32.06,32.06,0,0,0-24-31V40a8,8,0,0,0-16,0v97a32,32,0,0,0,0,62v17a8,8,0,0,0,16,0V199A32.06,32.06,0,0,0,232,168Zm-32,16a16,16,0,1,1,16-16A16,16,0,0,1,200,184Z"></path>', 1), Ue = Z('<path d="M84,136a28,28,0,0,1-20,26.83V216a8,8,0,0,1-16,0V162.83a28,28,0,0,1,0-53.66V40a8,8,0,0,1,16,0v69.17A28,28,0,0,1,84,136Zm52-74.83V40a8,8,0,0,0-16,0V61.17a28,28,0,0,0,0,53.66V216a8,8,0,0,0,16,0V114.83a28,28,0,0,0,0-53.66Zm72,80V40a8,8,0,0,0-16,0V141.17a28,28,0,0,0,0,53.66V216a8,8,0,0,0,16,0V194.83a28,28,0,0,0,0-53.66Z"></path>'), Ne = Z('<path d="M62,106.6V40a6,6,0,0,0-12,0v66.6a30,30,0,0,0,0,58.8V216a6,6,0,0,0,12,0V165.4a30,30,0,0,0,0-58.8ZM56,154a18,18,0,1,1,18-18A18,18,0,0,1,56,154Zm78-95.4V40a6,6,0,0,0-12,0V58.6a30,30,0,0,0,0,58.8V216a6,6,0,0,0,12,0V117.4a30,30,0,0,0,0-58.8ZM128,106a18,18,0,1,1,18-18A18,18,0,0,1,128,106Zm102,62a30.05,30.05,0,0,0-24-29.4V40a6,6,0,0,0-12,0v98.6a30,30,0,0,0,0,58.8V216a6,6,0,0,0,12,0V197.4A30.05,30.05,0,0,0,230,168Zm-30,18a18,18,0,1,1,18-18A18,18,0,0,1,200,186Z"></path>'), Ge = Z('<path d="M64,105V40a8,8,0,0,0-16,0v65a32,32,0,0,0,0,62v49a8,8,0,0,0,16,0V167a32,32,0,0,0,0-62Zm-8,47a16,16,0,1,1,16-16A16,16,0,0,1,56,152Zm80-95V40a8,8,0,0,0-16,0V57a32,32,0,0,0,0,62v97a8,8,0,0,0,16,0V119a32,32,0,0,0,0-62Zm-8,47a16,16,0,1,1,16-16A16,16,0,0,1,128,104Zm104,64a32.06,32.06,0,0,0-24-31V40a8,8,0,0,0-16,0v97a32,32,0,0,0,0,62v17a8,8,0,0,0,16,0V199A32.06,32.06,0,0,0,232,168Zm-32,16a16,16,0,1,1,16-16A16,16,0,0,1,200,184Z"></path>'), qe = Z('<path d="M60,108.29V40a4,4,0,0,0-8,0v68.29a28,28,0,0,0,0,55.42V216a4,4,0,0,0,8,0V163.71a28,28,0,0,0,0-55.42ZM56,156a20,20,0,1,1,20-20A20,20,0,0,1,56,156Zm76-95.71V40a4,4,0,0,0-8,0V60.29a28,28,0,0,0,0,55.42V216a4,4,0,0,0,8,0V115.71a28,28,0,0,0,0-55.42ZM128,108a20,20,0,1,1,20-20A20,20,0,0,1,128,108Zm100,60a28,28,0,0,0-24-27.71V40a4,4,0,0,0-8,0V140.29a28,28,0,0,0,0,55.42V216a4,4,0,0,0,8,0V195.71A28,28,0,0,0,228,168Zm-28,20a20,20,0,1,1,20-20A20,20,0,0,1,200,188Z"></path>'), Ke = Z('<svg><!><rect width="256" height="256" fill="none"></rect><!></svg>');
|
|
10
10
|
function Xe(a, e) {
|
|
11
11
|
te(e, !0);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as b, p as _, a, u as E, g as s, s as J, f as N, b as O, h as V, d as j, e as k, i as q, T as x, j as B, k as c, r as U, l as z, m as A, n as D, o as F, q as G, t as u } from "./chunks/TriiiceratopsViewer-
|
|
1
|
+
import { c as b, p as _, a, u as E, g as s, s as J, f as N, b as O, h as V, d as j, e as k, i as q, T as x, j as B, k as c, r as U, l as z, m as A, n as D, o as F, q as G, t as u } from "./chunks/TriiiceratopsViewer-BGtsfUPF.js";
|
|
2
2
|
var H = N('<!> <div class="w-full h-full"><!></div>', 1);
|
|
3
3
|
function K(I, t) {
|
|
4
4
|
_(t, !0);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Component } from 'svelte';
|
|
2
|
-
import
|
|
3
|
-
import { ViewerState } from '../state/viewer.svelte';
|
|
1
|
+
import type { Component } from 'svelte';
|
|
2
|
+
import type OpenSeadragon from 'openseadragon';
|
|
3
|
+
import type { ViewerState } from '../state/viewer.svelte';
|
|
4
4
|
/**
|
|
5
5
|
* Context object passed to plugins during registration.
|
|
6
6
|
* This is the stable public API that plugins depend on.
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Optional base class providing common plugin functionality.
|
|
3
|
+
*/
|
|
4
|
+
var BasePlugin = /** @class */ (function () {
|
|
5
|
+
function BasePlugin() {
|
|
6
|
+
this.context = null;
|
|
7
|
+
}
|
|
8
|
+
BasePlugin.prototype.onRegister = function (context) {
|
|
9
|
+
this.context = context;
|
|
10
|
+
};
|
|
11
|
+
BasePlugin.prototype.onDestroy = function () {
|
|
12
|
+
this.context = null;
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(BasePlugin.prototype, "viewerState", {
|
|
15
|
+
/** Convenience getter for ViewerState */
|
|
16
|
+
get: function () {
|
|
17
|
+
if (!this.context) {
|
|
18
|
+
throw new Error("Plugin ".concat(this.id, " accessed viewerState before registration"));
|
|
19
|
+
}
|
|
20
|
+
return this.context.viewerState;
|
|
21
|
+
},
|
|
22
|
+
enumerable: false,
|
|
23
|
+
configurable: true
|
|
24
|
+
});
|
|
25
|
+
Object.defineProperty(BasePlugin.prototype, "osdViewer", {
|
|
26
|
+
/** Convenience getter for OSD viewer */
|
|
27
|
+
get: function () {
|
|
28
|
+
var _a, _b;
|
|
29
|
+
return (_b = (_a = this.context) === null || _a === void 0 ? void 0 : _a.getOSDViewer()) !== null && _b !== void 0 ? _b : null;
|
|
30
|
+
},
|
|
31
|
+
enumerable: false,
|
|
32
|
+
configurable: true
|
|
33
|
+
});
|
|
34
|
+
return BasePlugin;
|
|
35
|
+
}());
|
|
36
|
+
export { BasePlugin };
|
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helper to extract ID from annotation object
|
|
3
|
+
* Handles Manifesto objects and raw JSON
|
|
4
|
+
*/
|
|
5
|
+
function getAnnotationId(anno) {
|
|
6
|
+
return anno.id || anno['@id'] || (typeof anno.getId === 'function' ? anno.getId() : '');
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Parse xywh media fragment from target string
|
|
10
|
+
* Format: "canvas-id#xywh=x,y,w,h"
|
|
11
|
+
*/
|
|
12
|
+
function parseXywh(targetStr) {
|
|
13
|
+
if (!targetStr)
|
|
14
|
+
return null;
|
|
15
|
+
var match = targetStr.match(/xywh=(\d+),(\d+),(\d+),(\d+)/);
|
|
16
|
+
if (match) {
|
|
17
|
+
return {
|
|
18
|
+
x: parseInt(match[1], 10),
|
|
19
|
+
y: parseInt(match[2], 10),
|
|
20
|
+
w: parseInt(match[3], 10),
|
|
21
|
+
h: parseInt(match[4], 10),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Extract target geometry from various annotation formats
|
|
28
|
+
*/
|
|
29
|
+
function extractGeometry(annotation) {
|
|
30
|
+
// Try to find SVG selector first
|
|
31
|
+
var svgSelector = findSvgSelector(annotation);
|
|
32
|
+
if (svgSelector) {
|
|
33
|
+
return convertSvgToPolygon(svgSelector);
|
|
34
|
+
}
|
|
35
|
+
// Extract xywh from target
|
|
36
|
+
var xywh = extractXywhFromTarget(annotation);
|
|
37
|
+
if (xywh) {
|
|
38
|
+
return {
|
|
39
|
+
type: 'RECTANGLE',
|
|
40
|
+
x: xywh.x,
|
|
41
|
+
y: xywh.y,
|
|
42
|
+
w: xywh.w,
|
|
43
|
+
h: xywh.h,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Find SVG selector in annotation target
|
|
50
|
+
*/
|
|
51
|
+
function findSvgSelector(annotation) {
|
|
52
|
+
var _a, _b;
|
|
53
|
+
// Try Manifesto method
|
|
54
|
+
if (typeof annotation.getTarget === 'function') {
|
|
55
|
+
// For Manifesto, check raw JSON for SVG
|
|
56
|
+
var rawOn = ((_a = annotation.__jsonld) === null || _a === void 0 ? void 0 : _a.on) || ((_b = annotation.__jsonld) === null || _b === void 0 ? void 0 : _b.target);
|
|
57
|
+
if (rawOn) {
|
|
58
|
+
return extractSvgFromTarget(rawOn);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
// Check common locations in raw JSON
|
|
62
|
+
var target = annotation.target || annotation.on;
|
|
63
|
+
if (target) {
|
|
64
|
+
return extractSvgFromTarget(target);
|
|
65
|
+
}
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Extract SVG from target object/array
|
|
70
|
+
*/
|
|
71
|
+
function extractSvgFromTarget(target) {
|
|
72
|
+
if (!target)
|
|
73
|
+
return null;
|
|
74
|
+
// Handle array of targets
|
|
75
|
+
if (Array.isArray(target)) {
|
|
76
|
+
for (var _i = 0, target_1 = target; _i < target_1.length; _i++) {
|
|
77
|
+
var t = target_1[_i];
|
|
78
|
+
var svg = extractSvgValue(t);
|
|
79
|
+
if (svg)
|
|
80
|
+
return svg;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
return extractSvgValue(target);
|
|
85
|
+
}
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Extract SVG value from single target object
|
|
90
|
+
*/
|
|
91
|
+
function extractSvgValue(target) {
|
|
92
|
+
var _a;
|
|
93
|
+
if (!target)
|
|
94
|
+
return null;
|
|
95
|
+
// Check for SvgSelector
|
|
96
|
+
var selector = target.selector || target;
|
|
97
|
+
if ((selector === null || selector === void 0 ? void 0 : selector.type) === 'SvgSelector' && selector.value) {
|
|
98
|
+
return selector.value;
|
|
99
|
+
}
|
|
100
|
+
// Check item (sometimes nested)
|
|
101
|
+
if (((_a = selector === null || selector === void 0 ? void 0 : selector.item) === null || _a === void 0 ? void 0 : _a.type) === 'SvgSelector' && selector.item.value) {
|
|
102
|
+
return selector.item.value;
|
|
103
|
+
}
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Convert SVG string to POLYGON geometry
|
|
108
|
+
* Parses points from SVG path or polygon element
|
|
109
|
+
*/
|
|
110
|
+
function convertSvgToPolygon(svgString) {
|
|
111
|
+
try {
|
|
112
|
+
var parser = new DOMParser();
|
|
113
|
+
var doc = parser.parseFromString(svgString, 'image/svg+xml');
|
|
114
|
+
if (doc.documentElement.nodeName === 'parsererror') {
|
|
115
|
+
console.warn('Failed to parse SVG selector:', svgString);
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
var points = [];
|
|
119
|
+
// Extract points from polygon elements
|
|
120
|
+
var polygons = doc.querySelectorAll('polygon');
|
|
121
|
+
for (var _i = 0, polygons_1 = polygons; _i < polygons_1.length; _i++) {
|
|
122
|
+
var poly = polygons_1[_i];
|
|
123
|
+
var pointsAttr = poly.getAttribute('points');
|
|
124
|
+
if (pointsAttr) {
|
|
125
|
+
var polyPoints = parsePolygonPoints(pointsAttr);
|
|
126
|
+
points.push.apply(points, polyPoints);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
// Extract points from path elements (simple conversion, doesn't handle curves)
|
|
130
|
+
var paths = doc.querySelectorAll('path');
|
|
131
|
+
for (var _a = 0, paths_1 = paths; _a < paths_1.length; _a++) {
|
|
132
|
+
var path = paths_1[_a];
|
|
133
|
+
var d = path.getAttribute('d');
|
|
134
|
+
if (d) {
|
|
135
|
+
var pathPoints = parsePathData(d);
|
|
136
|
+
points.push.apply(points, pathPoints);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
// Extract points from circle/ellipse (approximate as polygon)
|
|
140
|
+
var circles = doc.querySelectorAll('circle');
|
|
141
|
+
for (var _b = 0, circles_1 = circles; _b < circles_1.length; _b++) {
|
|
142
|
+
var circle = circles_1[_b];
|
|
143
|
+
var cx = parseFloat(circle.getAttribute('cx') || '0');
|
|
144
|
+
var cy = parseFloat(circle.getAttribute('cy') || '0');
|
|
145
|
+
var r = parseFloat(circle.getAttribute('r') || '0');
|
|
146
|
+
var circlePoints = generateCirclePoints(cx, cy, r);
|
|
147
|
+
points.push.apply(points, circlePoints);
|
|
148
|
+
}
|
|
149
|
+
if (points.length === 0) {
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
return {
|
|
153
|
+
type: 'POLYGON',
|
|
154
|
+
points: points,
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
catch (e) {
|
|
158
|
+
console.warn('Failed to convert SVG to polygon:', e);
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Parse polygon points attribute
|
|
164
|
+
* Format: "x1,y1 x2,y2 x3,y3"
|
|
165
|
+
*/
|
|
166
|
+
function parsePolygonPoints(pointsStr) {
|
|
167
|
+
var points = [];
|
|
168
|
+
var pairs = pointsStr.trim().split(/\s+/);
|
|
169
|
+
for (var _i = 0, pairs_1 = pairs; _i < pairs_1.length; _i++) {
|
|
170
|
+
var pair = pairs_1[_i];
|
|
171
|
+
var _a = pair.split(',').map(function (v) { return parseFloat(v); }), x = _a[0], y = _a[1];
|
|
172
|
+
if (!isNaN(x) && !isNaN(y)) {
|
|
173
|
+
points.push([x, y]);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return points;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Parse SVG path data (simplified)
|
|
180
|
+
* Extracts M (moveto) and L (lineto) commands
|
|
181
|
+
*/
|
|
182
|
+
function parsePathData(d) {
|
|
183
|
+
var points = [];
|
|
184
|
+
// Simple regex: match M and L commands followed by coordinates
|
|
185
|
+
var commandRegex = /[ML]\s*([\d.]+)[,\s]+([\d.]+)/g;
|
|
186
|
+
var match;
|
|
187
|
+
while ((match = commandRegex.exec(d)) !== null) {
|
|
188
|
+
var x = parseFloat(match[1]);
|
|
189
|
+
var y = parseFloat(match[2]);
|
|
190
|
+
if (!isNaN(x) && !isNaN(y)) {
|
|
191
|
+
points.push([x, y]);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return points;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Generate polygon points approximating a circle
|
|
198
|
+
*/
|
|
199
|
+
function generateCirclePoints(cx, cy, r, numPoints) {
|
|
200
|
+
if (numPoints === void 0) { numPoints = 8; }
|
|
201
|
+
var points = [];
|
|
202
|
+
for (var i = 0; i < numPoints; i++) {
|
|
203
|
+
var angle = (i / numPoints) * Math.PI * 2;
|
|
204
|
+
var x = cx + r * Math.cos(angle);
|
|
205
|
+
var y = cy + r * Math.sin(angle);
|
|
206
|
+
points.push([x, y]);
|
|
207
|
+
}
|
|
208
|
+
return points;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Extract xywh from annotation target (multiple formats)
|
|
212
|
+
*/
|
|
213
|
+
function extractXywhFromTarget(annotation) {
|
|
214
|
+
var _a;
|
|
215
|
+
// Try Manifesto getTarget method
|
|
216
|
+
if (typeof annotation.getTarget === 'function') {
|
|
217
|
+
var target_2 = annotation.getTarget();
|
|
218
|
+
if (typeof target_2 === 'string' && target_2.includes('xywh=')) {
|
|
219
|
+
return parseXywh(target_2);
|
|
220
|
+
}
|
|
221
|
+
// Check raw JSON as fallback
|
|
222
|
+
var rawOn = (_a = annotation.__jsonld) === null || _a === void 0 ? void 0 : _a.on;
|
|
223
|
+
if (rawOn) {
|
|
224
|
+
var xywh = extractXywhFromRawTarget(rawOn);
|
|
225
|
+
if (xywh)
|
|
226
|
+
return xywh;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
// Check raw annotation formats (v2 and v3)
|
|
230
|
+
var target = annotation.target || annotation.on;
|
|
231
|
+
if (target) {
|
|
232
|
+
return extractXywhFromRawTarget(target);
|
|
233
|
+
}
|
|
234
|
+
return null;
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Extract xywh from raw target object/array
|
|
238
|
+
*/
|
|
239
|
+
function extractXywhFromRawTarget(target) {
|
|
240
|
+
if (!target)
|
|
241
|
+
return null;
|
|
242
|
+
// Handle arrays
|
|
243
|
+
if (Array.isArray(target)) {
|
|
244
|
+
for (var _i = 0, target_3 = target; _i < target_3.length; _i++) {
|
|
245
|
+
var t = target_3[_i];
|
|
246
|
+
var xywh = extractXywhFromRawTarget(t);
|
|
247
|
+
if (xywh)
|
|
248
|
+
return xywh;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
// Handle string targets with xywh
|
|
252
|
+
if (typeof target === 'string' && target.includes('xywh=')) {
|
|
253
|
+
return parseXywh(target);
|
|
254
|
+
}
|
|
255
|
+
// Handle object with selector
|
|
256
|
+
if (target.selector) {
|
|
257
|
+
var sel = target.selector;
|
|
258
|
+
var item = sel.item || sel;
|
|
259
|
+
if (item.value && typeof item.value === 'string' && item.value.includes('xywh=')) {
|
|
260
|
+
return parseXywh(item.value);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
return null;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Extract annotation body content (text, label, etc)
|
|
267
|
+
*/
|
|
268
|
+
function extractBody(annotation) {
|
|
269
|
+
var value = '';
|
|
270
|
+
var isHtml = false;
|
|
271
|
+
// Try Manifesto getBody method
|
|
272
|
+
if (typeof annotation.getBody === 'function') {
|
|
273
|
+
var body = annotation.getBody();
|
|
274
|
+
if (body && Array.isArray(body)) {
|
|
275
|
+
var values = [];
|
|
276
|
+
for (var _i = 0, body_1 = body; _i < body_1.length; _i++) {
|
|
277
|
+
var b = body_1[_i];
|
|
278
|
+
var val = b.getValue ? b.getValue() : '';
|
|
279
|
+
if (val) {
|
|
280
|
+
values.push(val);
|
|
281
|
+
var format = b.getFormat ? b.getFormat() : '';
|
|
282
|
+
if (format === 'text/html' || format === 'application/html') {
|
|
283
|
+
isHtml = true;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
value = values.join(' ');
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
else {
|
|
291
|
+
// Handle raw JSON body/resource
|
|
292
|
+
var getText = function (r) {
|
|
293
|
+
if (!r)
|
|
294
|
+
return '';
|
|
295
|
+
return r.chars || r.value || r['cnt:chars'] || '';
|
|
296
|
+
};
|
|
297
|
+
var checkHtml = function (r) {
|
|
298
|
+
if (!r)
|
|
299
|
+
return false;
|
|
300
|
+
return r.format === 'text/html' || r.type === 'TextualBody';
|
|
301
|
+
};
|
|
302
|
+
if (annotation.resource) {
|
|
303
|
+
var resources = Array.isArray(annotation.resource) ? annotation.resource : [annotation.resource];
|
|
304
|
+
value = resources.map(getText).filter(Boolean).join(' ');
|
|
305
|
+
isHtml = resources.some(checkHtml);
|
|
306
|
+
}
|
|
307
|
+
else if (annotation.body) {
|
|
308
|
+
var bodyArr = Array.isArray(annotation.body) ? annotation.body : [annotation.body];
|
|
309
|
+
value = bodyArr.map(getText).filter(Boolean).join(' ');
|
|
310
|
+
isHtml = bodyArr.some(checkHtml);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
// Try to extract label if no body content found
|
|
314
|
+
if (!value) {
|
|
315
|
+
if (typeof annotation.getLabel === 'function') {
|
|
316
|
+
value = annotation.getLabel() || '';
|
|
317
|
+
}
|
|
318
|
+
else if (annotation.label) {
|
|
319
|
+
value = Array.isArray(annotation.label) ? annotation.label.join(' ') : annotation.label;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
return { value: value || 'Annotation', isHtml: isHtml };
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Parse Manifesto/IIIF annotation to internal format
|
|
326
|
+
*/
|
|
327
|
+
export function parseAnnotation(annotation, index, isSearchHit) {
|
|
328
|
+
if (isSearchHit === void 0) { isSearchHit = false; }
|
|
329
|
+
var id = getAnnotationId(annotation) || "anno-".concat(index);
|
|
330
|
+
var geometry = extractGeometry(annotation);
|
|
331
|
+
// Skip annotations without geometry
|
|
332
|
+
if (!geometry) {
|
|
333
|
+
return null;
|
|
334
|
+
}
|
|
335
|
+
var body = extractBody(annotation);
|
|
336
|
+
return {
|
|
337
|
+
id: id,
|
|
338
|
+
geometry: geometry,
|
|
339
|
+
body: body,
|
|
340
|
+
isSearchHit: isSearchHit,
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* Batch parse annotations
|
|
345
|
+
*/
|
|
346
|
+
export function parseAnnotations(annotations, searchHitIds) {
|
|
347
|
+
if (searchHitIds === void 0) { searchHitIds = new Set(); }
|
|
348
|
+
return annotations
|
|
349
|
+
.map(function (anno, idx) {
|
|
350
|
+
var isSearchHit = searchHitIds.has(getAnnotationId(anno));
|
|
351
|
+
return parseAnnotation(anno, idx, isSearchHit);
|
|
352
|
+
})
|
|
353
|
+
.filter(function (anno) { return anno !== null; });
|
|
354
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { parseAnnotation } from "./annotationAdapter";
|
|
3
|
+
describe("annotationAdapter", function () {
|
|
4
|
+
describe("parseAnnotation", function () {
|
|
5
|
+
it("should correctly parse a simple xywh string target", function () {
|
|
6
|
+
var annotation = {
|
|
7
|
+
"@id": "http://example.org/anno1",
|
|
8
|
+
on: "http://example.org/image1#xywh=10,20,100,200",
|
|
9
|
+
label: "Test Annotation",
|
|
10
|
+
};
|
|
11
|
+
var result = parseAnnotation(annotation, 0);
|
|
12
|
+
expect(result).not.toBeNull();
|
|
13
|
+
if (!result)
|
|
14
|
+
return;
|
|
15
|
+
expect(result.geometry.type).toBe("RECTANGLE");
|
|
16
|
+
var geometry = result.geometry;
|
|
17
|
+
if ("x" in geometry) {
|
|
18
|
+
expect(geometry).toEqual({
|
|
19
|
+
type: "RECTANGLE",
|
|
20
|
+
x: 10,
|
|
21
|
+
y: 20,
|
|
22
|
+
w: 100,
|
|
23
|
+
h: 200,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
throw new Error("Geometry should be RECTANGLE type with x, y, w, h");
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
it("should extract SVG selector geometry", function () {
|
|
31
|
+
var annotation = {
|
|
32
|
+
"@id": "http://example.org/anno2",
|
|
33
|
+
on: {
|
|
34
|
+
selector: {
|
|
35
|
+
type: "SvgSelector",
|
|
36
|
+
value: '<svg><polygon points="10,10 50,10 50,50 10,50" /></svg>',
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
var result = parseAnnotation(annotation, 1);
|
|
41
|
+
expect(result).not.toBeNull();
|
|
42
|
+
if (!result)
|
|
43
|
+
return;
|
|
44
|
+
expect(result.geometry.type).toBe("POLYGON");
|
|
45
|
+
var geometry = result.geometry;
|
|
46
|
+
if ("points" in geometry) {
|
|
47
|
+
expect(geometry.points).toHaveLength(4);
|
|
48
|
+
expect(geometry.points).toEqual([
|
|
49
|
+
[10, 10],
|
|
50
|
+
[50, 10],
|
|
51
|
+
[50, 50],
|
|
52
|
+
[10, 50],
|
|
53
|
+
]);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
throw new Error("Geometry should be POLYGON type with points");
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
it("should handle Manifesto-style getTarget and getId methods", function () {
|
|
60
|
+
var mockManifestoAnno = {
|
|
61
|
+
getId: function () { return "http://example.org/manifesto-anno"; },
|
|
62
|
+
getTarget: function () { return "http://example.org/canvas1#xywh=5,5,50,50"; },
|
|
63
|
+
getBody: function () { return [
|
|
64
|
+
{ getValue: function () { return "Manifesto Body"; }, getFormat: function () { return "text/plain"; } },
|
|
65
|
+
]; },
|
|
66
|
+
};
|
|
67
|
+
// @ts-ignore - mocking complex object
|
|
68
|
+
var result = parseAnnotation(mockManifestoAnno, 2);
|
|
69
|
+
expect(result === null || result === void 0 ? void 0 : result.id).toBe("http://example.org/manifesto-anno");
|
|
70
|
+
var geometry = result === null || result === void 0 ? void 0 : result.geometry;
|
|
71
|
+
if (geometry && "x" in geometry) {
|
|
72
|
+
expect(geometry).toMatchObject({
|
|
73
|
+
type: "RECTANGLE",
|
|
74
|
+
x: 5,
|
|
75
|
+
y: 5,
|
|
76
|
+
w: 50,
|
|
77
|
+
h: 50,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
expect(result === null || result === void 0 ? void 0 : result.body.value).toBe("Manifesto Body");
|
|
81
|
+
});
|
|
82
|
+
it("should return null for invalid annotations with no geometry", function () {
|
|
83
|
+
var invalidAnno = {
|
|
84
|
+
"@id": "bad-anno",
|
|
85
|
+
on: "http://example.org/canvas1", // No media fragment or selector
|
|
86
|
+
};
|
|
87
|
+
var result = parseAnnotation(invalidAnno, 3);
|
|
88
|
+
expect(result).toBeNull();
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "triiiceratops",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -18,16 +18,16 @@
|
|
|
18
18
|
"module": "./dist/index.js",
|
|
19
19
|
"svelte": "./dist/index.js",
|
|
20
20
|
"style": "./dist/triiiceratops.css",
|
|
21
|
-
"types": "./dist/
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
22
|
"exports": {
|
|
23
23
|
".": {
|
|
24
|
-
"types": "./dist/
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
25
|
"style": "./dist/triiiceratops.css",
|
|
26
26
|
"svelte": "./dist/index.js",
|
|
27
27
|
"import": "./dist/index.js"
|
|
28
28
|
},
|
|
29
29
|
"./plugins/image-manipulation": {
|
|
30
|
-
"types": "./dist/
|
|
30
|
+
"types": "./dist/plugins/image-manipulation/index.d.ts",
|
|
31
31
|
"svelte": "./dist/plugins/image-manipulation.js",
|
|
32
32
|
"import": "./dist/plugins/image-manipulation.js"
|
|
33
33
|
},
|
|
@@ -52,6 +52,7 @@
|
|
|
52
52
|
"@inlang/paraglide-js": "^2.5.0",
|
|
53
53
|
"@inlang/paraglide-vite": "^1.4.0",
|
|
54
54
|
"@playwright/test": "^1.57.0",
|
|
55
|
+
"@sveltejs/package": "^2.5.7",
|
|
55
56
|
"@sveltejs/vite-plugin-svelte": "^6.2.1",
|
|
56
57
|
"@tsconfig/svelte": "^5.0.6",
|
|
57
58
|
"@types/node": "^24.10.1",
|
|
@@ -78,7 +79,7 @@
|
|
|
78
79
|
"scripts": {
|
|
79
80
|
"dev": "vite",
|
|
80
81
|
"build": "vite build",
|
|
81
|
-
"build:lib": "vite build --config vite.config.lib.ts",
|
|
82
|
+
"build:lib": "svelte-package && vite build --config vite.config.lib.ts",
|
|
82
83
|
"build:element": "vite build --config vite.config.element.ts",
|
|
83
84
|
"build:demo": "vite build --config vite.config.demo.ts",
|
|
84
85
|
"build:consumer": "vite build --config vite.config.demo-consumer.ts",
|