@annotorious/annotorious 3.0.0-rc.21 → 3.0.0-rc.4
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 +2 -5
- package/dist/Annotorious.d.ts.map +1 -1
- package/dist/AnnotoriousOpts.d.ts +3 -2
- package/dist/AnnotoriousOpts.d.ts.map +1 -1
- package/dist/annotation/SVGAnnotationLayerPointerEvent.d.ts.map +1 -1
- package/dist/annotation/editors/Handle.d.ts +14 -0
- package/dist/annotation/editors/Handle.d.ts.map +1 -0
- package/dist/annotation/editors/editorsRegistry.d.ts +1 -1
- 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/drawingToolsRegistry.d.ts +4 -4
- package/dist/annotation/tools/drawingToolsRegistry.d.ts.map +1 -1
- package/dist/annotation/utils/responsive.d.ts +1 -2
- package/dist/annotation/utils/responsive.d.ts.map +1 -1
- package/dist/annotation/utils/styling.d.ts +1 -1
- 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 +2046 -2300
- 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 +7 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/keyboardCommands.d.ts.map +1 -1
- package/dist/model/w3c/W3CImageFormatAdapter.d.ts +2 -3
- package/dist/model/w3c/W3CImageFormatAdapter.d.ts.map +1 -1
- package/dist/model/w3c/fragment/FragmentSelector.d.ts +2 -1
- package/dist/model/w3c/fragment/FragmentSelector.d.ts.map +1 -1
- package/dist/model/w3c/index.d.ts +0 -1
- 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 +2 -1
- package/dist/model/w3c/svg/SVGSelector.d.ts.map +1 -1
- package/dist/state/ImageAnnotatorState.d.ts.map +1 -1
- package/dist/state/spatialTree.d.ts +1 -1
- package/dist/state/spatialTree.d.ts.map +1 -1
- package/package.json +16 -13
- package/src/Annotorious.css +5 -5
- package/src/Annotorious.ts +12 -21
- package/src/AnnotoriousOpts.ts +7 -7
- package/src/annotation/SVGAnnotationLayer.svelte +15 -21
- package/src/annotation/SVGAnnotationLayerPointerEvent.ts +2 -1
- package/src/annotation/Transform.ts +1 -1
- package/src/annotation/editors/Editor.svelte +11 -10
- package/src/annotation/editors/EditorMount.svelte +2 -2
- package/src/annotation/editors/Handle.ts +21 -0
- package/src/annotation/editors/index.ts +2 -2
- package/src/annotation/editors/polygon/PolygonEditor.svelte +16 -16
- package/src/annotation/editors/rectangle/RectangleEditor.svelte +43 -46
- package/src/annotation/shapes/Ellipse.svelte +2 -2
- package/src/annotation/shapes/Polygon.svelte +2 -2
- package/src/annotation/shapes/Rectangle.svelte +2 -2
- package/src/annotation/tools/ToolMount.svelte +3 -3
- package/src/annotation/tools/drawingToolsRegistry.ts +1 -2
- package/src/annotation/tools/polygon/RubberbandPolygon.svelte +11 -36
- package/src/annotation/tools/rectangle/RubberbandRectangle.svelte +10 -16
- package/src/annotation/utils/responsive.ts +1 -1
- package/src/annotation/utils/touch.ts +1 -4
- package/src/index.ts +16 -23
- package/src/keyboardCommands.ts +4 -8
- package/src/model/w3c/W3CImageFormatAdapter.ts +22 -53
- package/src/model/w3c/fragment/FragmentSelector.ts +6 -5
- package/src/model/w3c/index.ts +0 -1
- package/src/model/w3c/svg/SVG.ts +2 -1
- package/src/model/w3c/svg/SVGSelector.ts +13 -11
- package/src/state/ImageAnnotatorState.ts +3 -3
- package/src/state/spatialTree.ts +2 -3
- package/src/themes/dark/index.css +2 -2
- package/src/themes/light/index.css +2 -2
- package/src/themes/smart/setTheme.ts +2 -2
- package/dist/annotation/editors/Handle.svelte.d.ts +0 -1
- package/dist/model/w3c/W3CImageAnnotation.d.ts +0 -11
- package/dist/model/w3c/W3CImageAnnotation.d.ts.map +0 -1
- package/src/annotation/editors/Handle.svelte +0 -66
- package/src/model/w3c/W3CImageAnnotation.ts +0 -17
package/src/model/w3c/svg/SVG.ts
CHANGED
|
@@ -13,7 +13,8 @@ export const sanitize = (doc: Element | Document) => {
|
|
|
13
13
|
// Remove script tags
|
|
14
14
|
const scripts = doc.getElementsByTagName('script');
|
|
15
15
|
|
|
16
|
-
Array.from(scripts).reverse().forEach(el =>
|
|
16
|
+
Array.from(scripts).reverse().forEach(el =>
|
|
17
|
+
el.parentNode.removeChild(el));
|
|
17
18
|
|
|
18
19
|
Array.from(doc.querySelectorAll('*')).forEach(cleanEl);
|
|
19
20
|
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { W3CSelector } from '@annotorious/core';
|
|
2
2
|
import { boundsFromPoints, ShapeType } from '../../core';
|
|
3
|
-
import {
|
|
3
|
+
import type { Ellipse, EllipseGeometry, Polygon, PolygonGeometry, Shape } from '../../core';
|
|
4
|
+
import { SVG_NAMESPACE, insertSVGNamespace, sanitize } from './SVG';
|
|
4
5
|
|
|
5
|
-
export interface SVGSelector {
|
|
6
|
+
export interface SVGSelector extends W3CSelector {
|
|
6
7
|
|
|
7
8
|
type: 'SvgSelector';
|
|
8
9
|
|
|
9
10
|
value: string;
|
|
10
|
-
|
|
11
|
+
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
const parseSVGXML = (value: string): Element => {
|
|
@@ -28,6 +29,9 @@ const parseSVGXML = (value: string): Element => {
|
|
|
28
29
|
|
|
29
30
|
const parseSVGPolygon = (value: string): Polygon => {
|
|
30
31
|
const [a, b, str] = value.match(/(<polygon points=["|'])([^("|')]*)/) || [];
|
|
32
|
+
|
|
33
|
+
if (!str) return;
|
|
34
|
+
|
|
31
35
|
const points = str.split(' ').map((p) => p.split(',').map(parseFloat));
|
|
32
36
|
|
|
33
37
|
return {
|
|
@@ -42,10 +46,10 @@ const parseSVGPolygon = (value: string): Polygon => {
|
|
|
42
46
|
const parseSVGEllipse = (value: string): Ellipse => {
|
|
43
47
|
const doc = parseSVGXML(value);
|
|
44
48
|
|
|
45
|
-
const cx = parseFloat(doc.getAttribute('cx')
|
|
46
|
-
const cy = parseFloat(doc.getAttribute('cy')
|
|
47
|
-
const rx = parseFloat(doc.getAttribute('rx')
|
|
48
|
-
const ry = parseFloat(doc.getAttribute('ry')
|
|
49
|
+
const cx = parseFloat(doc.getAttribute('cx'));
|
|
50
|
+
const cy = parseFloat(doc.getAttribute('cy'));
|
|
51
|
+
const rx = parseFloat(doc.getAttribute('rx'));
|
|
52
|
+
const ry = parseFloat(doc.getAttribute('ry'));
|
|
49
53
|
|
|
50
54
|
const bounds = {
|
|
51
55
|
minX: cx - rx,
|
|
@@ -73,12 +77,10 @@ export const parseSVGSelector = <T extends Shape>(valueOrSelector: SVGSelector |
|
|
|
73
77
|
return parseSVGPolygon(value) as unknown as T;
|
|
74
78
|
else if (value.includes('<ellipse '))
|
|
75
79
|
return parseSVGEllipse(value) as unknown as T;
|
|
76
|
-
else
|
|
77
|
-
throw 'Unsupported SVG shape: ' + value;
|
|
78
80
|
}
|
|
79
81
|
|
|
80
82
|
export const serializeSVGSelector = (shape: Shape): SVGSelector => {
|
|
81
|
-
let value: string
|
|
83
|
+
let value: string;
|
|
82
84
|
|
|
83
85
|
if (shape.type === ShapeType.POLYGON) {
|
|
84
86
|
const geom = shape.geometry as PolygonGeometry;
|
|
@@ -44,11 +44,11 @@ export const createImageAnnotatorState = <E extends unknown>(
|
|
|
44
44
|
const viewport = createViewportState();
|
|
45
45
|
|
|
46
46
|
store.observe(({ changes }) => {
|
|
47
|
-
tree.set(
|
|
47
|
+
tree.set(changes.created.map(a => a.target as ImageAnnotationTarget), false);
|
|
48
48
|
|
|
49
|
-
|
|
49
|
+
changes.deleted.forEach(a => tree.remove(a.target as ImageAnnotationTarget));
|
|
50
50
|
|
|
51
|
-
|
|
51
|
+
changes.updated.forEach(({ oldValue, newValue }) =>
|
|
52
52
|
tree.update(oldValue.target, newValue.target));
|
|
53
53
|
});
|
|
54
54
|
|
package/src/state/spatialTree.ts
CHANGED
|
@@ -40,8 +40,7 @@ export const createSpatialTree = () => {
|
|
|
40
40
|
|
|
41
41
|
const remove = (target: ImageAnnotationTarget) => {
|
|
42
42
|
const item = index.get(target.annotation);
|
|
43
|
-
|
|
44
|
-
tree.remove(item);
|
|
43
|
+
tree.remove(item);
|
|
45
44
|
index.delete(target.annotation);
|
|
46
45
|
};
|
|
47
46
|
|
|
@@ -63,7 +62,7 @@ export const createSpatialTree = () => {
|
|
|
63
62
|
tree.load(indexedTargets);
|
|
64
63
|
};
|
|
65
64
|
|
|
66
|
-
const getAt = (x: number, y: number): ImageAnnotationTarget |
|
|
65
|
+
const getAt = (x: number, y: number): ImageAnnotationTarget | null => {
|
|
67
66
|
const idxHits = tree.search({
|
|
68
67
|
minX: x,
|
|
69
68
|
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-handle,
|
|
15
|
-
div[data-theme="dark"] rect.a9s-handle {
|
|
14
|
+
rect.a9s-corner-handle,
|
|
15
|
+
div[data-theme="dark"] rect.a9s-corner-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-handle,
|
|
17
|
-
div[data-theme="light"] rect.a9s-handle {
|
|
16
|
+
rect.a9s-corner-handle,
|
|
17
|
+
div[data-theme="light"] rect.a9s-corner-handle {
|
|
18
18
|
fill: #fff;
|
|
19
19
|
rx: 1px;
|
|
20
20
|
stroke: rgba(0, 0, 0, 0.45);
|
|
@@ -8,7 +8,7 @@ export const sampleBrightness = (imageOrCanvas: HTMLElement) => {
|
|
|
8
8
|
|
|
9
9
|
if (imageOrCanvas.nodeName === 'CANVAS') {
|
|
10
10
|
canvas = imageOrCanvas as HTMLCanvasElement;
|
|
11
|
-
context = canvas.getContext('2d', { willReadFrequently: true })
|
|
11
|
+
context = canvas.getContext('2d', { willReadFrequently: true });
|
|
12
12
|
} else {
|
|
13
13
|
const img = imageOrCanvas as HTMLImageElement;
|
|
14
14
|
// Copy image to in-memory canvas for processing
|
|
@@ -16,7 +16,7 @@ export const sampleBrightness = (imageOrCanvas: HTMLElement) => {
|
|
|
16
16
|
canvas.width = img.width;
|
|
17
17
|
canvas.height = img.height;
|
|
18
18
|
|
|
19
|
-
context = canvas.getContext('2d', { willReadFrequently: true })
|
|
19
|
+
context = canvas.getContext('2d', { willReadFrequently: true });
|
|
20
20
|
context.drawImage(img, 0, 0, img.width, img.height);
|
|
21
21
|
}
|
|
22
22
|
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { SvelteComponentTyped as default } from 'svelte';
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { W3CAnnotation, W3CAnnotationTarget } from '@annotorious/core';
|
|
2
|
-
import type { FragmentSelector } from './fragment';
|
|
3
|
-
import type { SVGSelector } from './svg';
|
|
4
|
-
export interface W3CImageAnnotation extends W3CAnnotation {
|
|
5
|
-
target: W3CImageAnnotationTarget | W3CImageAnnotationTarget[];
|
|
6
|
-
}
|
|
7
|
-
export interface W3CImageAnnotationTarget extends W3CAnnotationTarget {
|
|
8
|
-
selector: W3CImageSelector | W3CImageSelector[];
|
|
9
|
-
}
|
|
10
|
-
export type W3CImageSelector = FragmentSelector | SVGSelector;
|
|
11
|
-
//# sourceMappingURL=W3CImageAnnotation.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"W3CImageAnnotation.d.ts","sourceRoot":"","sources":["../../../src/model/w3c/W3CImageAnnotation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAC5E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAEzC,MAAM,WAAW,kBAAmB,SAAQ,aAAa;IAEvD,MAAM,EAAE,wBAAwB,GAAG,wBAAwB,EAAE,CAAC;CAE/D;AAED,MAAM,WAAW,wBAAyB,SAAQ,mBAAmB;IAEnE,QAAQ,EAAE,gBAAgB,GAAG,gBAAgB,EAAE,CAAC;CAEjD;AAED,MAAM,MAAM,gBAAgB,GAAG,gBAAgB,GAAG,WAAW,CAAC"}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import { isTouch } from '../utils';
|
|
3
|
-
|
|
4
|
-
/** props **/
|
|
5
|
-
export let x: number;
|
|
6
|
-
export let y: number;
|
|
7
|
-
export let scale: number;
|
|
8
|
-
export let radius: number = 30;
|
|
9
|
-
|
|
10
|
-
let touched = false;
|
|
11
|
-
|
|
12
|
-
const onPointerDown = (event: PointerEvent) => {
|
|
13
|
-
if (event.pointerType === 'touch')
|
|
14
|
-
touched = true;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const onPointerUp = () =>
|
|
18
|
-
touched = false;
|
|
19
|
-
|
|
20
|
-
$: handleSize = 10 / scale;
|
|
21
|
-
</script>
|
|
22
|
-
|
|
23
|
-
{#if isTouch}
|
|
24
|
-
<g class="a9s-touch-handle">
|
|
25
|
-
<circle
|
|
26
|
-
cx={x}
|
|
27
|
-
cy={y}
|
|
28
|
-
r={radius / scale}
|
|
29
|
-
class="a9s-touch-halo"
|
|
30
|
-
class:touched={touched}
|
|
31
|
-
on:pointerdown
|
|
32
|
-
on:pointerdown={onPointerDown}
|
|
33
|
-
on:pointerup={onPointerUp} />
|
|
34
|
-
|
|
35
|
-
<rect
|
|
36
|
-
class={`a9s-handle ${$$props.class || ''}`.trim()}
|
|
37
|
-
x={x - handleSize / 2}
|
|
38
|
-
y={y - handleSize / 2}
|
|
39
|
-
width={handleSize}
|
|
40
|
-
height={handleSize}
|
|
41
|
-
on:pointerdown
|
|
42
|
-
on:pointerdown={onPointerDown}
|
|
43
|
-
on:pointerup={onPointerUp} />
|
|
44
|
-
</g>
|
|
45
|
-
{:else}
|
|
46
|
-
<rect
|
|
47
|
-
class={`a9s-handle ${$$props.class || ''}`.trim()}
|
|
48
|
-
x={x - handleSize / 2}
|
|
49
|
-
y={y - handleSize / 2}
|
|
50
|
-
width={handleSize}
|
|
51
|
-
height={handleSize}
|
|
52
|
-
on:pointerdown />
|
|
53
|
-
{/if}
|
|
54
|
-
|
|
55
|
-
<style>
|
|
56
|
-
.a9s-touch-halo {
|
|
57
|
-
fill: transparent;
|
|
58
|
-
stroke-width: 0;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
.a9s-touch-halo.touched {
|
|
62
|
-
fill: rgba(255, 255, 255, 0.25);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
</style>
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { W3CAnnotation, W3CAnnotationTarget } from '@annotorious/core';
|
|
2
|
-
import type { FragmentSelector } from './fragment';
|
|
3
|
-
import type { SVGSelector } from './svg';
|
|
4
|
-
|
|
5
|
-
export interface W3CImageAnnotation extends W3CAnnotation {
|
|
6
|
-
|
|
7
|
-
target: W3CImageAnnotationTarget | W3CImageAnnotationTarget[];
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export interface W3CImageAnnotationTarget extends W3CAnnotationTarget {
|
|
12
|
-
|
|
13
|
-
selector: W3CImageSelector | W3CImageSelector[];
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export type W3CImageSelector = FragmentSelector | SVGSelector;
|