@annotorious/annotorious 3.0.0-rc.16 → 3.0.0-rc.18

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.
Files changed (72) hide show
  1. package/dist/Annotorious.d.ts.map +1 -1
  2. package/dist/annotation/SVGAnnotationLayerPointerEvent.d.ts.map +1 -1
  3. package/dist/annotation/editors/Handle.svelte.d.ts +1 -0
  4. package/dist/annotation/editors/editorsRegistry.d.ts +1 -1
  5. package/dist/annotation/editors/editorsRegistry.d.ts.map +1 -1
  6. package/dist/annotation/editors/index.d.ts +1 -1
  7. package/dist/annotation/editors/index.d.ts.map +1 -1
  8. package/dist/annotation/tools/drawingToolsRegistry.d.ts +4 -4
  9. package/dist/annotation/tools/drawingToolsRegistry.d.ts.map +1 -1
  10. package/dist/annotation/utils/responsive.d.ts +2 -1
  11. package/dist/annotation/utils/responsive.d.ts.map +1 -1
  12. package/dist/annotation/utils/styling.d.ts +1 -1
  13. package/dist/annotation/utils/styling.d.ts.map +1 -1
  14. package/dist/annotation/utils/touch.d.ts.map +1 -1
  15. package/dist/annotorious.css +1 -1
  16. package/dist/annotorious.es.js +2373 -2072
  17. package/dist/annotorious.es.js.map +1 -1
  18. package/dist/annotorious.js +1 -1
  19. package/dist/annotorious.js.map +1 -1
  20. package/dist/index.d.ts +1 -1
  21. package/dist/index.d.ts.map +1 -1
  22. package/dist/keyboardCommands.d.ts.map +1 -1
  23. package/dist/model/w3c/W3CImageAnnotation.d.ts +11 -0
  24. package/dist/model/w3c/W3CImageAnnotation.d.ts.map +1 -0
  25. package/dist/model/w3c/W3CImageFormatAdapter.d.ts +3 -2
  26. package/dist/model/w3c/W3CImageFormatAdapter.d.ts.map +1 -1
  27. package/dist/model/w3c/fragment/FragmentSelector.d.ts +1 -2
  28. package/dist/model/w3c/fragment/FragmentSelector.d.ts.map +1 -1
  29. package/dist/model/w3c/index.d.ts +1 -0
  30. package/dist/model/w3c/index.d.ts.map +1 -1
  31. package/dist/model/w3c/svg/SVG.d.ts.map +1 -1
  32. package/dist/model/w3c/svg/SVGSelector.d.ts +1 -2
  33. package/dist/model/w3c/svg/SVGSelector.d.ts.map +1 -1
  34. package/dist/state/spatialTree.d.ts +1 -1
  35. package/dist/state/spatialTree.d.ts.map +1 -1
  36. package/package.json +10 -10
  37. package/src/Annotorious.css +5 -5
  38. package/src/Annotorious.ts +7 -6
  39. package/src/annotation/SVGAnnotationLayer.svelte +18 -14
  40. package/src/annotation/SVGAnnotationLayerPointerEvent.ts +1 -2
  41. package/src/annotation/Transform.ts +1 -1
  42. package/src/annotation/editors/Editor.svelte +10 -11
  43. package/src/annotation/editors/EditorMount.svelte +2 -2
  44. package/src/annotation/editors/Handle.svelte +66 -0
  45. package/src/annotation/editors/index.ts +2 -2
  46. package/src/annotation/editors/polygon/PolygonEditor.svelte +16 -16
  47. package/src/annotation/editors/rectangle/RectangleEditor.svelte +46 -43
  48. package/src/annotation/shapes/Ellipse.svelte +2 -2
  49. package/src/annotation/shapes/Polygon.svelte +2 -2
  50. package/src/annotation/shapes/Rectangle.svelte +2 -2
  51. package/src/annotation/tools/ToolMount.svelte +3 -3
  52. package/src/annotation/tools/drawingToolsRegistry.ts +2 -1
  53. package/src/annotation/tools/polygon/RubberbandPolygon.svelte +34 -11
  54. package/src/annotation/tools/rectangle/RubberbandRectangle.svelte +16 -10
  55. package/src/annotation/utils/responsive.ts +1 -1
  56. package/src/annotation/utils/touch.ts +4 -1
  57. package/src/index.ts +1 -2
  58. package/src/keyboardCommands.ts +8 -4
  59. package/src/model/w3c/W3CImageAnnotation.ts +17 -0
  60. package/src/model/w3c/W3CImageFormatAdapter.ts +19 -15
  61. package/src/model/w3c/fragment/FragmentSelector.ts +5 -6
  62. package/src/model/w3c/index.ts +1 -0
  63. package/src/model/w3c/svg/SVG.ts +1 -2
  64. package/src/model/w3c/svg/SVGSelector.ts +11 -13
  65. package/src/state/ImageAnnotatorState.ts +3 -3
  66. package/src/state/spatialTree.ts +3 -2
  67. package/src/themes/dark/index.css +2 -2
  68. package/src/themes/light/index.css +2 -2
  69. package/src/themes/smart/setTheme.ts +2 -2
  70. package/dist/annotation/editors/Handle.d.ts +0 -14
  71. package/dist/annotation/editors/Handle.d.ts.map +0 -1
  72. package/src/annotation/editors/Handle.ts +0 -21
@@ -1,14 +1,13 @@
1
- import type { W3CSelector } from '@annotorious/core';
2
- import { boundsFromPoints, ShapeType } from '../../core';
3
1
  import type { Ellipse, EllipseGeometry, Polygon, PolygonGeometry, Shape } from '../../core';
4
- import { SVG_NAMESPACE, insertSVGNamespace, sanitize } from './SVG';
2
+ import { boundsFromPoints, ShapeType } from '../../core';
3
+ import { insertSVGNamespace, sanitize, SVG_NAMESPACE } from './SVG';
5
4
 
6
- export interface SVGSelector extends W3CSelector {
5
+ export interface SVGSelector {
7
6
 
8
7
  type: 'SvgSelector';
9
8
 
10
9
  value: string;
11
-
10
+
12
11
  }
13
12
 
14
13
  const parseSVGXML = (value: string): Element => {
@@ -29,9 +28,6 @@ const parseSVGXML = (value: string): Element => {
29
28
 
30
29
  const parseSVGPolygon = (value: string): Polygon => {
31
30
  const [a, b, str] = value.match(/(<polygon points=["|'])([^("|')]*)/) || [];
32
-
33
- if (!str) return;
34
-
35
31
  const points = str.split(' ').map((p) => p.split(',').map(parseFloat));
36
32
 
37
33
  return {
@@ -46,10 +42,10 @@ const parseSVGPolygon = (value: string): Polygon => {
46
42
  const parseSVGEllipse = (value: string): Ellipse => {
47
43
  const doc = parseSVGXML(value);
48
44
 
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'));
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')!);
53
49
 
54
50
  const bounds = {
55
51
  minX: cx - rx,
@@ -77,10 +73,12 @@ export const parseSVGSelector = <T extends Shape>(valueOrSelector: SVGSelector |
77
73
  return parseSVGPolygon(value) as unknown as T;
78
74
  else if (value.includes('<ellipse '))
79
75
  return parseSVGEllipse(value) as unknown as T;
76
+ else
77
+ throw 'Unsupported SVG shape: ' + value;
80
78
  }
81
79
 
82
80
  export const serializeSVGSelector = (shape: Shape): SVGSelector => {
83
- let value: string;
81
+ let value: string | undefined;
84
82
 
85
83
  if (shape.type === ShapeType.POLYGON) {
86
84
  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(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
 
@@ -40,7 +40,8 @@ export const createSpatialTree = () => {
40
40
 
41
41
  const remove = (target: ImageAnnotationTarget) => {
42
42
  const item = index.get(target.annotation);
43
- tree.remove(item);
43
+ if (item)
44
+ tree.remove(item);
44
45
  index.delete(target.annotation);
45
46
  };
46
47
 
@@ -62,7 +63,7 @@ export const createSpatialTree = () => {
62
63
  tree.load(indexedTargets);
63
64
  };
64
65
 
65
- const getAt = (x: number, y: number): ImageAnnotationTarget | null => {
66
+ const getAt = (x: number, y: number): ImageAnnotationTarget | undefined => {
66
67
  const idxHits = tree.search({
67
68
  minX: x,
68
69
  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-corner-handle,
15
- div[data-theme="dark"] rect.a9s-corner-handle {
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-corner-handle,
17
- div[data-theme="light"] rect.a9s-corner-handle {
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);
@@ -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,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';