@annotorious/annotorious 3.0.0-rc.3 → 3.0.0-rc.31
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.d.ts +10 -7
- package/dist/Annotorious.d.ts.map +1 -1
- package/dist/AnnotoriousOpts.d.ts +8 -6
- package/dist/AnnotoriousOpts.d.ts.map +1 -1
- package/dist/annotation/SVGAnnotationLayerPointerEvent.d.ts +4 -2
- package/dist/annotation/SVGAnnotationLayerPointerEvent.d.ts.map +1 -1
- package/dist/annotation/editors/Handle.svelte.d.ts +1 -0
- package/dist/annotation/editors/editorsRegistry.d.ts +4 -3
- package/dist/annotation/editors/editorsRegistry.d.ts.map +1 -1
- package/dist/annotation/editors/index.d.ts +1 -1
- package/dist/annotation/editors/index.d.ts.map +1 -1
- package/dist/annotation/tools/DrawingToolConfig.d.ts +2 -1
- package/dist/annotation/tools/drawingToolsRegistry.d.ts +5 -4
- package/dist/annotation/tools/drawingToolsRegistry.d.ts.map +1 -1
- package/dist/annotation/utils/responsive.d.ts +1 -1
- package/dist/annotation/utils/styling.d.ts +4 -3
- package/dist/annotation/utils/styling.d.ts.map +1 -1
- package/dist/annotation/utils/touch.d.ts.map +1 -1
- package/dist/annotorious.css +1 -1
- package/dist/annotorious.es.js +2540 -2178
- package/dist/annotorious.es.js.map +1 -1
- package/dist/annotorious.js +1 -1
- package/dist/annotorious.js.map +1 -1
- package/dist/index.d.ts +1 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/keyboardCommands.d.ts +3 -2
- package/dist/keyboardCommands.d.ts.map +1 -1
- package/dist/model/core/ImageAnnotation.d.ts +3 -2
- package/dist/model/core/Shape.d.ts +2 -1
- package/dist/model/core/ellipse/Ellipse.d.ts +2 -1
- package/dist/model/core/polygon/Polygon.d.ts +2 -1
- package/dist/model/core/rectangle/Rectangle.d.ts +2 -1
- package/dist/model/core/rectangle/rectangleUtils.d.ts +3 -2
- package/dist/model/core/shapeUtils.d.ts +3 -5
- package/dist/model/core/shapeUtils.d.ts.map +1 -1
- package/dist/model/w3c/W3CImageAnnotation.d.ts +12 -0
- package/dist/model/w3c/W3CImageAnnotation.d.ts.map +1 -0
- package/dist/model/w3c/W3CImageFormatAdapter.d.ts +12 -6
- package/dist/model/w3c/W3CImageFormatAdapter.d.ts.map +1 -1
- package/dist/model/w3c/fragment/FragmentSelector.d.ts +3 -3
- package/dist/model/w3c/fragment/FragmentSelector.d.ts.map +1 -1
- package/dist/model/w3c/index.d.ts +1 -0
- package/dist/model/w3c/index.d.ts.map +1 -1
- package/dist/model/w3c/svg/SVG.d.ts.map +1 -1
- package/dist/model/w3c/svg/SVGSelector.d.ts +3 -3
- package/dist/model/w3c/svg/SVGSelector.d.ts.map +1 -1
- package/dist/state/ImageAnnotationStore.d.ts +3 -2
- package/dist/state/ImageAnnotatorState.d.ts +5 -4
- package/dist/state/ImageAnnotatorState.d.ts.map +1 -1
- package/dist/state/spatialTree.d.ts +3 -2
- package/dist/state/spatialTree.d.ts.map +1 -1
- package/dist/themes/smart/setTheme.d.ts +4 -1
- package/dist/themes/smart/setTheme.d.ts.map +1 -1
- package/package.json +16 -16
- package/src/Annotorious.css +9 -5
- package/src/Annotorious.ts +52 -36
- package/src/AnnotoriousOpts.ts +16 -15
- package/src/annotation/SVGAnnotationLayer.svelte +71 -36
- package/src/annotation/SVGAnnotationLayerPointerEvent.ts +2 -3
- package/src/annotation/Transform.ts +1 -1
- package/src/annotation/editors/Editor.svelte +10 -11
- package/src/annotation/editors/EditorMount.svelte +3 -3
- package/src/annotation/editors/Handle.svelte +66 -0
- package/src/annotation/editors/editorsRegistry.ts +2 -2
- package/src/annotation/editors/index.ts +2 -2
- package/src/annotation/editors/polygon/PolygonEditor.svelte +16 -16
- package/src/annotation/editors/rectangle/RectangleEditor.svelte +46 -43
- package/src/annotation/shapes/Ellipse.svelte +3 -3
- package/src/annotation/shapes/Polygon.svelte +3 -3
- package/src/annotation/shapes/Rectangle.svelte +3 -3
- package/src/annotation/tools/ToolMount.svelte +3 -3
- package/src/annotation/tools/drawingToolsRegistry.ts +2 -1
- package/src/annotation/tools/polygon/RubberbandPolygon.svelte +40 -13
- package/src/annotation/tools/rectangle/RubberbandRectangle.svelte +27 -11
- package/src/annotation/utils/responsive.ts +1 -1
- package/src/annotation/utils/styling.ts +5 -2
- package/src/annotation/utils/touch.ts +4 -1
- package/src/index.ts +22 -16
- package/src/keyboardCommands.ts +11 -7
- package/src/model/w3c/W3CImageAnnotation.ts +17 -0
- package/src/model/w3c/W3CImageFormatAdapter.ts +79 -31
- package/src/model/w3c/fragment/FragmentSelector.ts +5 -6
- package/src/model/w3c/index.ts +1 -0
- package/src/model/w3c/svg/SVG.ts +1 -2
- package/src/model/w3c/svg/SVGSelector.ts +11 -13
- package/src/state/ImageAnnotatorState.ts +4 -5
- package/src/state/spatialTree.ts +13 -6
- package/src/themes/dark/index.css +2 -2
- package/src/themes/light/index.css +2 -2
- package/src/themes/smart/setTheme.ts +10 -6
- package/dist/annotation/editors/Handle.d.ts +0 -14
- package/dist/annotation/editors/Handle.d.ts.map +0 -1
- package/src/annotation/editors/Handle.ts +0 -21
|
@@ -37,18 +37,18 @@ export const createImageAnnotatorState = <E extends unknown>(
|
|
|
37
37
|
|
|
38
38
|
const tree = createSpatialTree();
|
|
39
39
|
|
|
40
|
-
const selection = createSelectionState(store, opts.
|
|
40
|
+
const selection = createSelectionState(store, opts.userSelectAction);
|
|
41
41
|
|
|
42
42
|
const hover = createHoverState(store);
|
|
43
43
|
|
|
44
44
|
const viewport = createViewportState();
|
|
45
45
|
|
|
46
46
|
store.observe(({ changes }) => {
|
|
47
|
-
tree.set(changes.created.map(a => a.target as ImageAnnotationTarget), false);
|
|
47
|
+
tree.set((changes.created || []).map(a => a.target as ImageAnnotationTarget), false);
|
|
48
48
|
|
|
49
|
-
changes.deleted.forEach(a => tree.remove(a.target as ImageAnnotationTarget));
|
|
49
|
+
(changes.deleted || []).forEach(a => tree.remove(a.target as ImageAnnotationTarget));
|
|
50
50
|
|
|
51
|
-
changes.updated.forEach(({ oldValue, newValue }) =>
|
|
51
|
+
(changes.updated || []).forEach(({ oldValue, newValue }) =>
|
|
52
52
|
tree.update(oldValue.target, newValue.target));
|
|
53
53
|
});
|
|
54
54
|
|
|
@@ -85,4 +85,3 @@ export const createSvelteImageAnnotatorState = <E extends unknown>(
|
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
}
|
|
88
|
-
|
package/src/state/spatialTree.ts
CHANGED
|
@@ -40,7 +40,8 @@ export const createSpatialTree = () => {
|
|
|
40
40
|
|
|
41
41
|
const remove = (target: ImageAnnotationTarget) => {
|
|
42
42
|
const item = index.get(target.annotation);
|
|
43
|
-
|
|
43
|
+
if (item)
|
|
44
|
+
tree.remove(item);
|
|
44
45
|
index.delete(target.annotation);
|
|
45
46
|
};
|
|
46
47
|
|
|
@@ -53,16 +54,22 @@ export const createSpatialTree = () => {
|
|
|
53
54
|
if (replace)
|
|
54
55
|
clear();
|
|
55
56
|
|
|
56
|
-
const indexedTargets = targets.
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
57
|
+
const indexedTargets = targets.reduce<IndexedTarget[]>((all, target) => {
|
|
58
|
+
if (target.selector?.geometry?.bounds) {
|
|
59
|
+
// In case the host app injects any custom annotations, the
|
|
60
|
+
// spatial index should simply ignore them.
|
|
61
|
+
const { minX, minY, maxX, maxY } = target.selector.geometry.bounds;
|
|
62
|
+
return [...all, { minX, minY, maxX, maxY, target }];
|
|
63
|
+
} else {
|
|
64
|
+
return all;
|
|
65
|
+
}
|
|
66
|
+
}, []);
|
|
60
67
|
|
|
61
68
|
indexedTargets.forEach(t => index.set(t.target.annotation, t));
|
|
62
69
|
tree.load(indexedTargets);
|
|
63
70
|
};
|
|
64
71
|
|
|
65
|
-
const getAt = (x: number, y: number): ImageAnnotationTarget |
|
|
72
|
+
const getAt = (x: number, y: number): ImageAnnotationTarget | undefined => {
|
|
66
73
|
const idxHits = tree.search({
|
|
67
74
|
minX: x,
|
|
68
75
|
minY: y,
|
|
@@ -11,8 +11,8 @@ div[data-theme="dark"] .a9s-annotationlayer .a9s-inner {
|
|
|
11
11
|
stroke-width: 1px;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
rect.a9s-
|
|
15
|
-
div[data-theme="dark"] rect.a9s-
|
|
14
|
+
rect.a9s-handle,
|
|
15
|
+
div[data-theme="dark"] rect.a9s-handle {
|
|
16
16
|
fill: #000;
|
|
17
17
|
rx: 2px;
|
|
18
18
|
}
|
|
@@ -13,8 +13,8 @@ div[data-theme="light"] .a9s-annotationlayer .a9s-inner {
|
|
|
13
13
|
stroke-width: 1.5px;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
rect.a9s-
|
|
17
|
-
div[data-theme="light"] rect.a9s-
|
|
16
|
+
rect.a9s-handle,
|
|
17
|
+
div[data-theme="light"] rect.a9s-handle {
|
|
18
18
|
fill: #fff;
|
|
19
19
|
rx: 1px;
|
|
20
20
|
stroke: rgba(0, 0, 0, 0.45);
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { Theme } from '../../AnnotoriousOpts';
|
|
2
|
+
|
|
1
3
|
export const sampleBrightness = (imageOrCanvas: HTMLElement) => {
|
|
2
4
|
|
|
3
5
|
let canvas: HTMLCanvasElement;
|
|
@@ -6,7 +8,7 @@ export const sampleBrightness = (imageOrCanvas: HTMLElement) => {
|
|
|
6
8
|
|
|
7
9
|
if (imageOrCanvas.nodeName === 'CANVAS') {
|
|
8
10
|
canvas = imageOrCanvas as HTMLCanvasElement;
|
|
9
|
-
context = canvas.getContext('2d', { willReadFrequently: true })
|
|
11
|
+
context = canvas.getContext('2d', { willReadFrequently: true })!;
|
|
10
12
|
} else {
|
|
11
13
|
const img = imageOrCanvas as HTMLImageElement;
|
|
12
14
|
// Copy image to in-memory canvas for processing
|
|
@@ -14,7 +16,7 @@ export const sampleBrightness = (imageOrCanvas: HTMLElement) => {
|
|
|
14
16
|
canvas.width = img.width;
|
|
15
17
|
canvas.height = img.height;
|
|
16
18
|
|
|
17
|
-
context = canvas.getContext('2d', { willReadFrequently: true })
|
|
19
|
+
context = canvas.getContext('2d', { willReadFrequently: true })!;
|
|
18
20
|
context.drawImage(img, 0, 0, img.width, img.height);
|
|
19
21
|
}
|
|
20
22
|
|
|
@@ -35,12 +37,14 @@ export const sampleBrightness = (imageOrCanvas: HTMLElement) => {
|
|
|
35
37
|
return totalBrightness / 81;
|
|
36
38
|
}
|
|
37
39
|
|
|
38
|
-
export const
|
|
40
|
+
export const detectTheme = (imageOrCanvas: HTMLElement) => {
|
|
39
41
|
const brightness = sampleBrightness(imageOrCanvas);
|
|
40
|
-
|
|
41
42
|
const theme = brightness > 0.6 ? 'dark' : 'light'
|
|
42
43
|
|
|
43
44
|
console.log(`[Annotorious] Image brightness: ${brightness.toFixed(1)}. Setting ${theme} theme.`);
|
|
44
45
|
|
|
45
|
-
|
|
46
|
-
}
|
|
46
|
+
return theme;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export const setTheme = (imageOrCanvas: HTMLElement, container: HTMLElement, theme: Theme) =>
|
|
50
|
+
container.setAttribute('data-theme', theme === 'auto' ? detectTheme(imageOrCanvas) : theme);
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export type Handle = string;
|
|
2
|
-
export declare const Handle: {
|
|
3
|
-
(value: string | number): string;
|
|
4
|
-
SHAPE: string;
|
|
5
|
-
TOP: string;
|
|
6
|
-
RIGHT: string;
|
|
7
|
-
BOTTOM: string;
|
|
8
|
-
LEFT: string;
|
|
9
|
-
TOP_LEFT: string;
|
|
10
|
-
TOP_RIGHT: string;
|
|
11
|
-
BOTTOM_RIGHT: string;
|
|
12
|
-
BOTTOM_LEFT: string;
|
|
13
|
-
};
|
|
14
|
-
//# sourceMappingURL=Handle.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Handle.d.ts","sourceRoot":"","sources":["../../../src/annotation/editors/Handle.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,MAAM,GAAG,MAAM,CAAC;AAE5B,eAAO,MAAM,MAAM;YAAW,MAAM,GAAG,MAAM;;;;;;;;;;CAAsB,CAAC"}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
export type Handle = string;
|
|
2
|
-
|
|
3
|
-
export const Handle = (value: string | number) => `HANDLE-${value}`;
|
|
4
|
-
|
|
5
|
-
Handle.SHAPE = 'SHAPE';
|
|
6
|
-
|
|
7
|
-
Handle.TOP = 'TOP';
|
|
8
|
-
|
|
9
|
-
Handle.RIGHT = 'RIGHT';
|
|
10
|
-
|
|
11
|
-
Handle.BOTTOM = 'BOTTOM';
|
|
12
|
-
|
|
13
|
-
Handle.LEFT = 'LEFT';
|
|
14
|
-
|
|
15
|
-
Handle.TOP_LEFT = 'TOP_LEFT';
|
|
16
|
-
|
|
17
|
-
Handle.TOP_RIGHT = 'TOP_RIGHT';
|
|
18
|
-
|
|
19
|
-
Handle.BOTTOM_RIGHT = 'BOTTOM_RIGHT';
|
|
20
|
-
|
|
21
|
-
Handle.BOTTOM_LEFT = 'BOTTOM_LEFT';
|