@annotorious/annotorious 3.3.5 → 3.3.6
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/annotorious.es.js +183 -179
- package/dist/annotorious.es.js.map +1 -1
- package/dist/annotorious.js +2 -2
- package/dist/annotorious.js.map +1 -1
- package/dist/state/ImageAnnotationStore.d.ts +3 -4
- package/dist/state/spatialTree.d.ts +2 -2
- package/package.json +2 -2
- package/src/state/ImageAnnotationStore.ts +3 -4
- package/src/state/ImageAnnotatorState.ts +16 -4
- package/src/state/spatialTree.ts +6 -3
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { Annotation, Store, SvelteAnnotatorState, SvelteStore } from '@annotorious/core';
|
|
2
|
-
import { ImageAnnotation } from '../model';
|
|
1
|
+
import { Annotation, Filter, Store, SvelteAnnotatorState, SvelteStore } from '@annotorious/core';
|
|
3
2
|
export type ImageAnnotationStore<I extends Annotation> = Store<I> & {
|
|
4
|
-
getAt(x: number, y: number):
|
|
5
|
-
getIntersecting(x: number, y: number, width: number, height: number):
|
|
3
|
+
getAt(x: number, y: number, filter?: Filter<I>): I | undefined;
|
|
4
|
+
getIntersecting(x: number, y: number, width: number, height: number): I[];
|
|
6
5
|
};
|
|
7
6
|
export type SvelteImageAnnotationStore<I extends Annotation = Annotation> = SvelteStore<I> & ImageAnnotationStore<I>;
|
|
8
7
|
export type SvelteImageAnnotatorState<I extends Annotation = Annotation, E extends unknown = Annotation> = SvelteAnnotatorState<I, E> & {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ImageAnnotationTarget } from '../model';
|
|
2
|
-
import { AnnotationTarget } from '@annotorious/core';
|
|
2
|
+
import { Annotation, AnnotationTarget, Filter } from '@annotorious/core';
|
|
3
3
|
interface IndexedTarget {
|
|
4
4
|
minX: number;
|
|
5
5
|
minY: number;
|
|
@@ -10,7 +10,7 @@ interface IndexedTarget {
|
|
|
10
10
|
export declare const createSpatialTree: () => {
|
|
11
11
|
all: () => IndexedTarget[];
|
|
12
12
|
clear: () => void;
|
|
13
|
-
getAt: (x: number, y: number) => ImageAnnotationTarget
|
|
13
|
+
getAt: (x: number, y: number, filter?: Filter<Annotation>) => ImageAnnotationTarget[];
|
|
14
14
|
getIntersecting: (x: number, y: number, width: number, height: number) => ImageAnnotationTarget[];
|
|
15
15
|
insert: (target: AnnotationTarget) => void;
|
|
16
16
|
remove: (target: AnnotationTarget) => void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@annotorious/annotorious",
|
|
3
|
-
"version": "3.3.
|
|
3
|
+
"version": "3.3.6",
|
|
4
4
|
"description": "Add image annotation functionality to any web page with a few lines of JavaScript",
|
|
5
5
|
"author": "Rainer Simon",
|
|
6
6
|
"license": "BSD-3-Clause",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"vitest": "^3.1.2"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@annotorious/core": "3.3.
|
|
52
|
+
"@annotorious/core": "3.3.6",
|
|
53
53
|
"rbush": "^4.0.1",
|
|
54
54
|
"svg-pathdata": "^7.2.0",
|
|
55
55
|
"uuid": "^11.1.0"
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import type { Annotation, Store, SvelteAnnotatorState, SvelteStore } from '@annotorious/core';
|
|
2
|
-
import type { ImageAnnotation } from '../model';
|
|
1
|
+
import type { Annotation, Filter, Store, SvelteAnnotatorState, SvelteStore } from '@annotorious/core';
|
|
3
2
|
|
|
4
3
|
export type ImageAnnotationStore<I extends Annotation> = Store<I> & {
|
|
5
4
|
|
|
6
|
-
getAt(x: number, y: number):
|
|
5
|
+
getAt(x: number, y: number, filter?: Filter<I>): I | undefined;
|
|
7
6
|
|
|
8
|
-
getIntersecting(x: number, y: number, width: number, height: number):
|
|
7
|
+
getIntersecting(x: number, y: number, width: number, height: number): I[];
|
|
9
8
|
|
|
10
9
|
}
|
|
11
10
|
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
toSvelteStore,
|
|
7
7
|
type Annotation,
|
|
8
8
|
type AnnotatorState,
|
|
9
|
+
type Filter,
|
|
9
10
|
type HoverState,
|
|
10
11
|
type SelectionState
|
|
11
12
|
} from '@annotorious/core';
|
|
@@ -53,13 +54,24 @@ export const createImageAnnotatorState = <I extends Annotation, E extends unknow
|
|
|
53
54
|
tree.update(oldValue.target, newValue.target));
|
|
54
55
|
});
|
|
55
56
|
|
|
56
|
-
const getAt = (x: number, y: number):
|
|
57
|
-
const
|
|
58
|
-
|
|
57
|
+
const getAt = (x: number, y: number, filter?: Filter<I>): I | undefined => {
|
|
58
|
+
const targets = tree.getAt(x, y, filter as Filter<Annotation>);
|
|
59
|
+
|
|
60
|
+
if (filter) {
|
|
61
|
+
// Resolve annotations first, so we can filter
|
|
62
|
+
const annotations = targets.map(t => store.getAnnotation(t.annotation)!)
|
|
63
|
+
.filter(Boolean)
|
|
64
|
+
.filter(filter);
|
|
65
|
+
|
|
66
|
+
return annotations[0];
|
|
67
|
+
} else {
|
|
68
|
+
const top = targets[0];
|
|
69
|
+
return top ? store.getAnnotation(top.annotation) : undefined;
|
|
70
|
+
}
|
|
59
71
|
}
|
|
60
72
|
|
|
61
73
|
const getIntersecting = (x: number, y: number, width: number, height: number) =>
|
|
62
|
-
tree.getIntersecting(x, y, width, height).map(target => store.getAnnotation(target.annotation) as
|
|
74
|
+
tree.getIntersecting(x, y, width, height).map(target => store.getAnnotation(target.annotation) as I);
|
|
63
75
|
|
|
64
76
|
return {
|
|
65
77
|
store: {
|
package/src/state/spatialTree.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import RBush from 'rbush';
|
|
2
2
|
import { ShapeType,computeArea, intersects, isImageAnnotationTarget } from '../model';
|
|
3
3
|
import type { ImageAnnotationTarget } from '../model';
|
|
4
|
-
import type { AnnotationTarget } from '@annotorious/core';
|
|
4
|
+
import type { Annotation, AnnotationTarget, Filter } from '@annotorious/core';
|
|
5
5
|
|
|
6
6
|
interface IndexedTarget {
|
|
7
7
|
|
|
@@ -74,7 +74,8 @@ export const createSpatialTree = () => {
|
|
|
74
74
|
tree.load(indexedTargets);
|
|
75
75
|
};
|
|
76
76
|
|
|
77
|
-
|
|
77
|
+
|
|
78
|
+
const getAt = (x: number, y: number, filter?: Filter<Annotation>): ImageAnnotationTarget[] => {
|
|
78
79
|
const idxHits = tree.search({
|
|
79
80
|
minX: x,
|
|
80
81
|
minY: y,
|
|
@@ -91,7 +92,9 @@ export const createSpatialTree = () => {
|
|
|
91
92
|
// Get smallest shape
|
|
92
93
|
if (exactHits.length > 0) {
|
|
93
94
|
exactHits.sort((a, b) => computeArea(a.selector) - computeArea(b.selector));
|
|
94
|
-
return exactHits
|
|
95
|
+
return exactHits;
|
|
96
|
+
} else {
|
|
97
|
+
return [];
|
|
95
98
|
}
|
|
96
99
|
};
|
|
97
100
|
|