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

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 (58) 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/editorsRegistry.d.ts +1 -1
  4. package/dist/annotation/editors/editorsRegistry.d.ts.map +1 -1
  5. package/dist/annotation/tools/drawingToolsRegistry.d.ts +4 -4
  6. package/dist/annotation/tools/drawingToolsRegistry.d.ts.map +1 -1
  7. package/dist/annotation/utils/responsive.d.ts +2 -1
  8. package/dist/annotation/utils/responsive.d.ts.map +1 -1
  9. package/dist/annotation/utils/styling.d.ts +1 -1
  10. package/dist/annotation/utils/styling.d.ts.map +1 -1
  11. package/dist/annotorious.es.js +1799 -1728
  12. package/dist/annotorious.es.js.map +1 -1
  13. package/dist/annotorious.js +1 -1
  14. package/dist/annotorious.js.map +1 -1
  15. package/dist/index.d.ts +1 -1
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/keyboardCommands.d.ts.map +1 -1
  18. package/dist/model/w3c/W3CImageAnnotation.d.ts +11 -0
  19. package/dist/model/w3c/W3CImageAnnotation.d.ts.map +1 -0
  20. package/dist/model/w3c/W3CImageFormatAdapter.d.ts +3 -2
  21. package/dist/model/w3c/W3CImageFormatAdapter.d.ts.map +1 -1
  22. package/dist/model/w3c/fragment/FragmentSelector.d.ts +1 -2
  23. package/dist/model/w3c/fragment/FragmentSelector.d.ts.map +1 -1
  24. package/dist/model/w3c/index.d.ts +1 -0
  25. package/dist/model/w3c/index.d.ts.map +1 -1
  26. package/dist/model/w3c/svg/SVG.d.ts.map +1 -1
  27. package/dist/model/w3c/svg/SVGSelector.d.ts +1 -2
  28. package/dist/model/w3c/svg/SVGSelector.d.ts.map +1 -1
  29. package/dist/state/spatialTree.d.ts +1 -1
  30. package/dist/state/spatialTree.d.ts.map +1 -1
  31. package/package.json +10 -10
  32. package/src/Annotorious.ts +7 -6
  33. package/src/annotation/SVGAnnotationLayer.svelte +18 -14
  34. package/src/annotation/SVGAnnotationLayerPointerEvent.ts +1 -2
  35. package/src/annotation/Transform.ts +1 -1
  36. package/src/annotation/editors/Editor.svelte +5 -5
  37. package/src/annotation/editors/EditorMount.svelte +1 -1
  38. package/src/annotation/editors/polygon/PolygonEditor.svelte +8 -6
  39. package/src/annotation/editors/rectangle/RectangleEditor.svelte +4 -4
  40. package/src/annotation/shapes/Ellipse.svelte +2 -2
  41. package/src/annotation/shapes/Polygon.svelte +2 -2
  42. package/src/annotation/shapes/Rectangle.svelte +2 -2
  43. package/src/annotation/tools/ToolMount.svelte +3 -3
  44. package/src/annotation/tools/drawingToolsRegistry.ts +2 -1
  45. package/src/annotation/tools/polygon/RubberbandPolygon.svelte +18 -12
  46. package/src/annotation/tools/rectangle/RubberbandRectangle.svelte +16 -10
  47. package/src/annotation/utils/responsive.ts +1 -1
  48. package/src/index.ts +1 -2
  49. package/src/keyboardCommands.ts +6 -2
  50. package/src/model/w3c/W3CImageAnnotation.ts +17 -0
  51. package/src/model/w3c/W3CImageFormatAdapter.ts +19 -15
  52. package/src/model/w3c/fragment/FragmentSelector.ts +5 -6
  53. package/src/model/w3c/index.ts +1 -0
  54. package/src/model/w3c/svg/SVG.ts +1 -2
  55. package/src/model/w3c/svg/SVGSelector.ts +11 -13
  56. package/src/state/ImageAnnotatorState.ts +3 -3
  57. package/src/state/spatialTree.ts +3 -2
  58. package/src/themes/smart/setTheme.ts +2 -2
package/dist/index.d.ts CHANGED
@@ -6,5 +6,5 @@ export * from './annotation/tools';
6
6
  export * from './Annotorious';
7
7
  export * from './AnnotoriousOpts';
8
8
  export * from './keyboardCommands';
9
- export type { Annotation, AnnotationBody, AnnotationTarget, Annotator, AnnotatorState, Appearance, AppearanceProvider, Color, DrawingStyle, Filter, FormatAdapter, HoverState, LifecycleEvents, ParseResult, PresentUser, Purpose, Selection, SelectionState, Store, StoreChangeEvent, StoreObserver, User, W3CAnnotation, W3CAnnotationBody, W3CAnnotationTarget, W3CSelector } from '@annotorious/core';
9
+ export type { Annotation, AnnotationBody, AnnotationTarget, Annotator, AnnotatorState, Appearance, AppearanceProvider, Color, DrawingStyle, Filter, FormatAdapter, HoverState, LifecycleEvents, ParseResult, PresentUser, Purpose, Selection, SelectionState, Store, StoreChangeEvent, StoreObserver, User, W3CAnnotation, W3CAnnotationBody, W3CAnnotationTarget } from '@annotorious/core';
10
10
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,oBAAoB,CAAC;AACnC,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AAGnC,YAAY,EACV,UAAU,EACV,cAAc,EACd,gBAAgB,EAChB,SAAS,EACT,cAAc,EACd,UAAU,EACV,kBAAkB,EAClB,KAAK,EACL,YAAY,EACZ,MAAM,EACN,aAAa,EACb,UAAU,EACV,eAAe,EACf,WAAW,EACX,WAAW,EACX,OAAO,EACP,SAAS,EACT,cAAc,EACd,KAAK,EACL,gBAAgB,EAChB,aAAa,EACb,IAAI,EACJ,aAAa,EACb,iBAAiB,EACjB,mBAAmB,EACnB,WAAW,EACZ,MAAM,mBAAmB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,oBAAoB,CAAC;AACnC,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AAGnC,YAAY,EACV,UAAU,EACV,cAAc,EACd,gBAAgB,EAChB,SAAS,EACT,cAAc,EACd,UAAU,EACV,kBAAkB,EAClB,KAAK,EACL,YAAY,EACZ,MAAM,EACN,aAAa,EACb,UAAU,EACV,eAAe,EACf,WAAW,EACX,WAAW,EACX,OAAO,EACP,SAAS,EACT,cAAc,EACd,KAAK,EACL,gBAAgB,EAChB,aAAa,EACb,IAAI,EACJ,aAAa,EACb,iBAAiB,EACjB,mBAAmB,EACpB,MAAM,mBAAmB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"keyboardCommands.d.ts","sourceRoot":"","sources":["../src/keyboardCommands.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAI/D,eAAO,MAAM,oBAAoB,8DAEnB,OAAO;;CAuCpB,CAAA"}
1
+ {"version":3,"file":"keyboardCommands.d.ts","sourceRoot":"","sources":["../src/keyboardCommands.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAI/D,eAAO,MAAM,oBAAoB,8DAEnB,OAAO;;CA2CpB,CAAA"}
@@ -0,0 +1,11 @@
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
@@ -0,0 +1 @@
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,7 +1,8 @@
1
1
  import type { FormatAdapter, ParseResult, W3CAnnotation } from '@annotorious/core';
2
2
  import type { ImageAnnotation } from '../core';
3
- export type W3CImageFormatAdapter = FormatAdapter<ImageAnnotation, W3CAnnotation>;
3
+ import type { W3CImageAnnotation } from './W3CImageAnnotation';
4
+ export type W3CImageFormatAdapter = FormatAdapter<ImageAnnotation, W3CImageAnnotation>;
4
5
  export declare const W3CImageFormat: (source: string, invertY?: boolean) => W3CImageFormatAdapter;
5
6
  export declare const parseW3CImageAnnotation: (annotation: W3CAnnotation, invertY?: boolean) => ParseResult<ImageAnnotation>;
6
- export declare const serializeW3CImageAnnotation: (annotation: ImageAnnotation, source: string) => W3CAnnotation;
7
+ export declare const serializeW3CImageAnnotation: (annotation: ImageAnnotation, source: string) => W3CImageAnnotation;
7
8
  //# sourceMappingURL=W3CImageFormatAdapter.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"W3CImageFormatAdapter.d.ts","sourceRoot":"","sources":["../../../src/model/w3c/W3CImageFormatAdapter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAEnF,OAAO,KAAK,EAAE,eAAe,EAAqB,MAAM,SAAS,CAAC;AAMlE,MAAM,MAAM,qBAAqB,GAAG,aAAa,CAAC,eAAe,EAAE,aAAa,CAAC,CAAC;AAElF,eAAO,MAAM,cAAc,WACjB,MAAM,YACL,OAAO,0BAUjB,CAAA;AAED,eAAO,MAAM,uBAAuB,eACtB,aAAa,YAChB,OAAO,KACf,YAAY,eAAe,CAyC7B,CAAA;AAED,eAAO,MAAM,2BAA2B,eAC1B,eAAe,UACnB,MAAM,KACb,aA6BF,CAAC"}
1
+ {"version":3,"file":"W3CImageFormatAdapter.d.ts","sourceRoot":"","sources":["../../../src/model/w3c/W3CImageFormatAdapter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAEnF,OAAO,KAAK,EAAE,eAAe,EAAqB,MAAM,SAAS,CAAC;AAKlE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE/D,MAAM,MAAM,qBAAqB,GAAG,aAAa,CAAC,eAAe,EAAE,kBAAkB,CAAC,CAAC;AAEvF,eAAO,MAAM,cAAc,WACjB,MAAM,YACL,OAAO,0BAUjB,CAAA;AAED,eAAO,MAAM,uBAAuB,eACtB,aAAa,YAChB,OAAO,KACf,YAAY,eAAe,CA2C7B,CAAA;AAED,eAAO,MAAM,2BAA2B,eAC1B,eAAe,UACnB,MAAM,KACb,kBA8BF,CAAA"}
@@ -1,6 +1,5 @@
1
- import type { W3CSelector } from '@annotorious/core';
2
1
  import type { Rectangle, RectangleGeometry } from '../../core';
3
- export interface FragmentSelector extends W3CSelector {
2
+ export interface FragmentSelector {
4
3
  type: 'FragmentSelector';
5
4
  conformsTo: 'http://www.w3.org/TR/media-frags/';
6
5
  value: string;
@@ -1 +1 @@
1
- {"version":3,"file":"FragmentSelector.d.ts","sourceRoot":"","sources":["../../../../src/model/w3c/fragment/FragmentSelector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD,OAAO,KAAK,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAE/D,MAAM,WAAW,gBAAiB,SAAQ,WAAW;IAEnD,IAAI,EAAE,kBAAkB,CAAC;IAEzB,UAAU,EAAE,mCAAmC,CAAC;IAEhD,KAAK,EAAE,MAAM,CAAC;CAEf;AAED,eAAO,MAAM,qBAAqB,uBACZ,gBAAgB,GAAG,MAAM,wBAE5C,SA+BF,CAAC;AAEF,eAAO,MAAM,yBAAyB,aAAc,iBAAiB,KAAG,gBAQvE,CAAC"}
1
+ {"version":3,"file":"FragmentSelector.d.ts","sourceRoot":"","sources":["../../../../src/model/w3c/fragment/FragmentSelector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAG/D,MAAM,WAAW,gBAAgB;IAE/B,IAAI,EAAE,kBAAkB,CAAC;IAEzB,UAAU,EAAE,mCAAmC,CAAC;IAEhD,KAAK,EAAE,MAAM,CAAC;CAEf;AAED,eAAO,MAAM,qBAAqB,uBACZ,gBAAgB,GAAG,MAAM,wBAE5C,SA+BF,CAAA;AAED,eAAO,MAAM,yBAAyB,aAAc,iBAAiB,KAAG,gBAQvE,CAAA"}
@@ -1,4 +1,5 @@
1
1
  export * from './fragment';
2
2
  export * from './svg';
3
+ export * from './W3CImageAnnotation';
3
4
  export * from './W3CImageFormatAdapter';
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/model/w3c/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,OAAO,CAAC;AACtB,cAAc,yBAAyB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/model/w3c/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,OAAO,CAAC;AACtB,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"SVG.d.ts","sourceRoot":"","sources":["../../../../src/model/w3c/svg/SVG.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,+BAA+B,CAAC;AAE1D,eAAO,MAAM,QAAQ,QAAS,OAAO,GAAG,QAAQ,uBAmB/C,CAAA;AAED,uDAAuD;AACvD,eAAO,MAAM,kBAAkB,gBAAiB,QAAQ,KAAG,OAW1D,CAAA"}
1
+ {"version":3,"file":"SVG.d.ts","sourceRoot":"","sources":["../../../../src/model/w3c/svg/SVG.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,+BAA+B,CAAC;AAE1D,eAAO,MAAM,QAAQ,QAAS,OAAO,GAAG,QAAQ,uBAkB/C,CAAA;AAED,uDAAuD;AACvD,eAAO,MAAM,kBAAkB,gBAAiB,QAAQ,KAAG,OAW1D,CAAA"}
@@ -1,6 +1,5 @@
1
- import type { W3CSelector } from '@annotorious/core';
2
1
  import type { Shape } from '../../core';
3
- export interface SVGSelector extends W3CSelector {
2
+ export interface SVGSelector {
4
3
  type: 'SvgSelector';
5
4
  value: string;
6
5
  }
@@ -1 +1 @@
1
- {"version":3,"file":"SVGSelector.d.ts","sourceRoot":"","sources":["../../../../src/model/w3c/svg/SVGSelector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD,OAAO,KAAK,EAAsD,KAAK,EAAE,MAAM,YAAY,CAAC;AAG5F,MAAM,WAAW,WAAY,SAAQ,WAAW;IAE9C,IAAI,EAAE,aAAa,CAAC;IAEpB,KAAK,EAAE,MAAM,CAAC;CAEf;AA6DD,eAAO,MAAM,gBAAgB,qCAAsC,WAAW,GAAG,MAAM,MAOtF,CAAA;AAED,eAAO,MAAM,oBAAoB,UAAW,KAAK,KAAG,WAiBnD,CAAA"}
1
+ {"version":3,"file":"SVGSelector.d.ts","sourceRoot":"","sources":["../../../../src/model/w3c/svg/SVGSelector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAsD,KAAK,EAAE,MAAM,YAAY,CAAC;AAI5F,MAAM,WAAW,WAAW;IAE1B,IAAI,EAAE,aAAa,CAAC;IAEpB,KAAK,EAAE,MAAM,CAAC;CAEf;AA0DD,eAAO,MAAM,gBAAgB,qCAAsC,WAAW,GAAG,MAAM,MAStF,CAAA;AAED,eAAO,MAAM,oBAAoB,UAAW,KAAK,KAAG,WAiBnD,CAAA"}
@@ -9,7 +9,7 @@ interface IndexedTarget {
9
9
  export declare const createSpatialTree: () => {
10
10
  all: () => IndexedTarget[];
11
11
  clear: () => void;
12
- getAt: (x: number, y: number) => ImageAnnotationTarget | null;
12
+ getAt: (x: number, y: number) => ImageAnnotationTarget | undefined;
13
13
  getIntersecting: (x: number, y: number, width: number, height: number) => ImageAnnotationTarget[];
14
14
  insert: (target: ImageAnnotationTarget) => void;
15
15
  remove: (target: ImageAnnotationTarget) => void;
@@ -1 +1 @@
1
- {"version":3,"file":"spatialTree.d.ts","sourceRoot":"","sources":["../../src/state/spatialTree.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAEtD,UAAU,aAAa;IAErB,IAAI,EAAE,MAAM,CAAC;IAEb,IAAI,EAAE,MAAM,CAAC;IAEb,IAAI,EAAE,MAAM,CAAC;IAEb,IAAI,EAAE,MAAM,CAAC;IAEb,MAAM,EAAE,qBAAqB,CAAC;CAE/B;AAED,eAAO,MAAM,iBAAiB;;;eA8CV,MAAM,KAAK,MAAM,KAAG,qBAAqB,GAAG,IAAI;yBAqBtC,MAAM,KAAK,MAAM,SAAS,MAAM,UAAU,MAAM;qBAtDpD,qBAAqB;qBASrB,qBAAqB;mBAWvB,qBAAqB,EAAE,YAAW,OAAO;;uBALrC,qBAAqB,WAAW,qBAAqB;CA6DhF,CAAA"}
1
+ {"version":3,"file":"spatialTree.d.ts","sourceRoot":"","sources":["../../src/state/spatialTree.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAEtD,UAAU,aAAa;IAErB,IAAI,EAAE,MAAM,CAAC;IAEb,IAAI,EAAE,MAAM,CAAC;IAEb,IAAI,EAAE,MAAM,CAAC;IAEb,IAAI,EAAE,MAAM,CAAC;IAEb,MAAM,EAAE,qBAAqB,CAAC;CAE/B;AAED,eAAO,MAAM,iBAAiB;;;eA+CV,MAAM,KAAK,MAAM,KAAG,qBAAqB,GAAG,SAAS;yBAqB3C,MAAM,KAAK,MAAM,SAAS,MAAM,UAAU,MAAM;qBAvDpD,qBAAqB;qBASrB,qBAAqB;mBAYvB,qBAAqB,EAAE,YAAW,OAAO;;uBALrC,qBAAqB,WAAW,qBAAqB;CA6DhF,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@annotorious/annotorious",
3
- "version": "3.0.0-rc.16",
3
+ "version": "3.0.0-rc.17",
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",
@@ -36,15 +36,15 @@
36
36
  "./src": "./src/index.ts"
37
37
  },
38
38
  "devDependencies": {
39
- "@sveltejs/vite-plugin-svelte": "^2.4.6",
40
- "@tsconfig/svelte": "^3.0.0",
41
- "@types/rbush": "^3.0.2",
42
- "jsdom": "^22.1.0",
43
- "svelte": "^3.59.2",
44
- "typescript": "^4.9.5",
45
- "vite": "^4.4.9",
46
- "vite-plugin-dts": "^3.6.0",
47
- "vitest": "^0.34.6"
39
+ "@sveltejs/vite-plugin-svelte": "^3.0.1",
40
+ "@tsconfig/svelte": "^5.0.2",
41
+ "@types/rbush": "^3.0.3",
42
+ "jsdom": "^23.0.1",
43
+ "svelte": "^4.2.8",
44
+ "typescript": "^5.3.3",
45
+ "vite": "^5.0.10",
46
+ "vite-plugin-dts": "^3.7.0",
47
+ "vitest": "^1.1.1"
48
48
  },
49
49
  "peerDependencies": {
50
50
  "@annotorious/core": "*"
@@ -68,21 +68,21 @@ export const createImageAnnotator = <E extends unknown = ImageAnnotation>(
68
68
  // Wrapper div has unwanted margin at the bottom otherwise!
69
69
  img.style.display = 'block';
70
70
 
71
- img.parentNode.insertBefore(container, img);
71
+ img.parentNode!.insertBefore(container, img);
72
72
  container.appendChild(img);
73
73
 
74
74
  const keyboardCommands = initKeyboardCommands(undoStack);
75
75
 
76
76
  let currentUser: User = createAnonymousGuest();
77
77
 
78
- _setTheme(img, container, opts.theme);
78
+ _setTheme(img, container, opts.theme!);
79
79
 
80
80
  const annotationLayer = new SVGAnnotationLayer({
81
81
  target: container,
82
82
  props: {
83
- drawingEnabled: opts.drawingEnabled,
83
+ drawingEnabled: Boolean(opts.drawingEnabled),
84
84
  image: img,
85
- preferredDrawingMode: opts.drawingMode,
85
+ preferredDrawingMode: opts.drawingMode!,
86
86
  state,
87
87
  style: opts.style,
88
88
  user: currentUser
@@ -109,8 +109,8 @@ export const createImageAnnotator = <E extends unknown = ImageAnnotation>(
109
109
  annotationLayer.$destroy();
110
110
 
111
111
  // Unwrap the image
112
- container.parentNode.insertBefore(img, container);
113
- container.parentNode.removeChild(container);
112
+ container.parentNode!.insertBefore(img, container);
113
+ container.parentNode!.removeChild(container);
114
114
 
115
115
  // Other cleanup actions
116
116
  keyboardCommands.destroy();
@@ -131,6 +131,7 @@ export const createImageAnnotator = <E extends unknown = ImageAnnotation>(
131
131
  if (!toolSpec)
132
132
  throw `No drawing tool named ${name}`;
133
133
 
134
+ // @ts-ignore
134
135
  annotationLayer.$set({ toolName: name })
135
136
  }
136
137
 
@@ -1,10 +1,10 @@
1
- <script type="ts">
2
- import { onMount, type SvelteComponent } from 'svelte';
1
+ <script lang="ts">
2
+ import { SvelteComponent, onMount } from 'svelte';
3
3
  import { v4 as uuidv4 } from 'uuid';
4
4
  import type { DrawingStyle, StoreChangeEvent, User } from '@annotorious/core';
5
5
  import { ShapeType } from '../model';
6
6
  import type { ImageAnnotation, Shape} from '../model';
7
- import { getEditor, EditorMount } from './editors';
7
+ import { getEditor as _getEditor, EditorMount } from './editors';
8
8
  import { Ellipse, Polygon, Rectangle} from './shapes';
9
9
  import { getTool, listDrawingTools, ToolMount } from './tools';
10
10
  import { enableResponsive } from './utils';
@@ -18,11 +18,11 @@
18
18
  export let image: HTMLImageElement | HTMLCanvasElement;
19
19
  export let preferredDrawingMode: DrawingMode;
20
20
  export let state: SvelteImageAnnotatorState;
21
- export let style: DrawingStyle | ((annotation: ImageAnnotation) => DrawingStyle) = undefined;
22
- export let toolName: string = listDrawingTools().length > 0 ? listDrawingTools()[0] : undefined;
21
+ export let style: DrawingStyle | ((annotation: ImageAnnotation) => DrawingStyle) | undefined = undefined;
22
+ export let toolName: string = listDrawingTools()[0];
23
23
  export let user: User;
24
24
 
25
- $: ({ tool, opts } = getTool(toolName));
25
+ $: ({ tool, opts } = getTool(toolName) || { tool: undefined, opts: undefined });
26
26
 
27
27
  $: drawingMode = opts?.drawingMode || preferredDrawingMode;
28
28
 
@@ -43,16 +43,17 @@
43
43
 
44
44
  $: ({ onPointerDown, onPointerUp } = addEventListeners(svgEl, store));
45
45
 
46
- let storeObserver = null;
46
+ let storeObserver: (event: StoreChangeEvent<ImageAnnotation>) => void | undefined;
47
47
 
48
- let editableAnnotations: ImageAnnotation[] = null;
48
+ let editableAnnotations: ImageAnnotation[] | undefined;
49
49
 
50
50
  $: isEditable = (a: ImageAnnotation) => $selection.selected.find(s => s.id === a.id && s.editable);
51
51
 
52
52
  $: trackSelection($selection.selected);
53
53
 
54
54
  const trackSelection = (selected: { id: string, editable?: boolean }[]) => {
55
- store.unobserve(storeObserver);
55
+ if (storeObserver)
56
+ store.unobserve(storeObserver);
56
57
 
57
58
  // Track only editable annotations
58
59
  const editableIds =
@@ -60,17 +61,17 @@
60
61
 
61
62
  if (editableIds.length > 0) {
62
63
  // Resolve selected IDs from the store
63
- editableAnnotations = editableIds.map(id => store.getAnnotation(id));
64
+ editableAnnotations = editableIds.map(id => store.getAnnotation(id)!).filter(Boolean);
64
65
 
65
66
  // Track updates on the editable annotations
66
67
  storeObserver = (event: StoreChangeEvent<ImageAnnotation>) => {
67
68
  const { updated } = event.changes;
68
- editableAnnotations = updated.map(change => change.newValue);
69
+ editableAnnotations = updated?.map(change => change.newValue);
69
70
  }
70
71
 
71
72
  store.observe(storeObserver, { annotations: editableIds });
72
73
  } else {
73
- editableAnnotations = null;
74
+ editableAnnotations = undefined;
74
75
  }
75
76
  }
76
77
 
@@ -108,10 +109,13 @@
108
109
  ...target,
109
110
  selector: event.detail,
110
111
  created: isUpdate ? target.created : new Date(),
111
- updated: isUpdate ? new Date() : null,
112
- updatedBy: isUpdate ? user : null
112
+ updated: isUpdate ? new Date() : undefined,
113
+ updatedBy: isUpdate ? user : undefined
113
114
  });
114
115
  }
116
+
117
+ // To get around lack of TypeScript support in Svelte markup
118
+ const getEditor = (shape: Shape): typeof SvelteComponent => _getEditor(shape)!;
115
119
  </script>
116
120
 
117
121
  <svg
@@ -1,7 +1,6 @@
1
1
  import { createEventDispatcher } from 'svelte';
2
2
  import type { SvelteImageAnnotationStore } from '../state';
3
3
  import type { ImageAnnotation } from '../model';
4
- import { isTouch } from './utils';
5
4
 
6
5
  export interface SVGAnnotationLayerPointerEvent {
7
6
 
@@ -51,5 +50,5 @@ const getSVGPoint = (evt: PointerEvent, svg: SVGSVGElement) => {
51
50
  pt.x = x + left;
52
51
  pt.y = y + top;
53
52
 
54
- return pt.matrixTransform(svg.getScreenCTM().inverse());
53
+ return pt.matrixTransform(svg.getScreenCTM()!.inverse());
55
54
  }
@@ -19,7 +19,7 @@ export const createSVGTransform = (svg: SVGSVGElement): Transform => ({
19
19
  pt.x = offsetX + bbox.x;
20
20
  pt.y = offsetY + bbox.y;
21
21
 
22
- const { x, y } = pt.matrixTransform(svg.getScreenCTM().inverse());
22
+ const { x, y } = pt.matrixTransform(svg.getScreenCTM()!.inverse());
23
23
  return [x, y];
24
24
  }
25
25
 
@@ -1,4 +1,4 @@
1
- <script type="ts">
1
+ <script lang="ts">
2
2
  import { createEventDispatcher } from 'svelte';
3
3
  import type { Shape } from '../../model';
4
4
  import type { Handle } from './Handle';
@@ -11,11 +11,11 @@
11
11
  export let editor: (shape: Shape, handle: Handle, delta: [number, number]) => Shape;
12
12
  export let transform: Transform;
13
13
 
14
- let grabbedHandle: Handle = null;
14
+ let grabbedHandle: Handle | undefined;
15
15
 
16
16
  let origin: [number, number];
17
17
 
18
- let initialShape: Shape = null;
18
+ let initialShape: Shape | undefined;
19
19
 
20
20
  const onGrab = (handle: Handle) => (evt: PointerEvent) => {
21
21
  grabbedHandle = handle;
@@ -34,7 +34,7 @@
34
34
 
35
35
  const delta: [number, number] = [x - origin[0], y - origin[1]];
36
36
 
37
- shape = editor(initialShape, grabbedHandle, delta);
37
+ shape = editor(initialShape!, grabbedHandle, delta);
38
38
 
39
39
  dispatch('change', shape);
40
40
  }
@@ -44,7 +44,7 @@
44
44
  const target = evt.target as Element;
45
45
  target.releasePointerCapture(evt.pointerId);
46
46
 
47
- grabbedHandle = null;
47
+ grabbedHandle = undefined;
48
48
 
49
49
  initialShape = shape;
50
50
 
@@ -10,7 +10,7 @@
10
10
  /** Props */
11
11
  export let annotation: ImageAnnotation;
12
12
  export let editor: typeof SvelteComponent;
13
- export let style: DrawingStyle | ((annotation: ImageAnnotation) => DrawingStyle) = undefined;
13
+ export let style: DrawingStyle | ((annotation: ImageAnnotation) => DrawingStyle) | undefined;
14
14
  export let target: SVGGElement;
15
15
  export let transform: Transform;
16
16
  export let viewportScale: number;
@@ -1,12 +1,12 @@
1
- <script type="ts">
1
+ <script lang="ts">
2
2
  import { boundsFromPoints } from '../../../model';
3
- import type { Polygon } from '../../../model';
3
+ import type { Polygon, PolygonGeometry, Shape } from '../../../model';
4
4
  import type { Transform } from '../../Transform';
5
5
  import { Editor, Handle } from '..';
6
6
 
7
7
  /** Props */
8
8
  export let shape: Polygon;
9
- export let computedStyle: string = undefined;
9
+ export let computedStyle: string | undefined;
10
10
  export let transform: Transform;
11
11
  export let viewportScale: number = 1;
12
12
 
@@ -14,13 +14,15 @@
14
14
 
15
15
  $: handleSize = 10 / viewportScale;
16
16
 
17
- const editor = (polygon: Polygon, handle: Handle, delta: [number, number]) => {
17
+ const editor = (polygon: Shape, handle: Handle, delta: [number, number]) => {
18
18
  let points: [number, number][];
19
19
 
20
+ const geom = (polygon.geometry) as PolygonGeometry;
21
+
20
22
  if (handle === Handle.SHAPE) {
21
- points = polygon.geometry.points.map(([x, y]) => [x + delta[0], y + delta[1]]);
23
+ points = geom.points.map(([x, y]) => [x + delta[0], y + delta[1]]);
22
24
  } else {
23
- points = polygon.geometry.points.map(([x, y], idx) =>
25
+ points = geom.points.map(([x, y], idx) =>
24
26
  handle === Handle(idx) ? [x + delta[0], y + delta[1]] : [x, y]
25
27
  );
26
28
  }
@@ -1,11 +1,11 @@
1
- <script type="ts">
2
- import type { Rectangle } from '../../../model';
1
+ <script lang="ts">
2
+ import type { Rectangle, Shape } from '../../../model';
3
3
  import type { Transform } from '../../Transform';
4
4
  import { Editor, Handle } from '..';
5
5
 
6
6
  /** Props */
7
7
  export let shape: Rectangle;
8
- export let computedStyle: string = undefined;
8
+ export let computedStyle: string | undefined;
9
9
  export let transform: Transform;
10
10
  export let viewportScale: number = 1;
11
11
 
@@ -13,7 +13,7 @@
13
13
 
14
14
  $: handleSize = 10 / viewportScale;
15
15
 
16
- const editor = (rectangle: Rectangle, handle: Handle, delta: [number, number]) => {
16
+ const editor = (rectangle: Shape, handle: Handle, delta: [number, number]) => {
17
17
  const initialBounds = rectangle.geometry.bounds;
18
18
 
19
19
  let [x0, y0] = [initialBounds.minX, initialBounds.minY];
@@ -1,4 +1,4 @@
1
- <script type="ts">
1
+ <script lang="ts">
2
2
  import type { DrawingStyle } from '@annotorious/core';
3
3
  import type { Geometry, EllipseGeometry, ImageAnnotation } from '../../model';
4
4
  import { computeStyle } from '../utils/styling';
@@ -6,7 +6,7 @@
6
6
  /** Props */
7
7
  export let annotation: ImageAnnotation;
8
8
  export let geom: Geometry;
9
- export let style: DrawingStyle | ((annotation: ImageAnnotation) => DrawingStyle) = undefined;
9
+ export let style: DrawingStyle | ((annotation: ImageAnnotation) => DrawingStyle) | undefined;
10
10
 
11
11
  $: computedStyle = computeStyle(annotation, style);
12
12
 
@@ -1,4 +1,4 @@
1
- <script type="ts">
1
+ <script lang="ts">
2
2
  import type { DrawingStyle } from '@annotorious/core';
3
3
  import type { Geometry, ImageAnnotation, PolygonGeometry } from '../../model';
4
4
  import { computeStyle } from '../utils/styling';
@@ -6,7 +6,7 @@
6
6
  /** Props **/
7
7
  export let annotation: ImageAnnotation;
8
8
  export let geom: Geometry;
9
- export let style: DrawingStyle | ((annotation: ImageAnnotation) => DrawingStyle) = undefined;
9
+ export let style: DrawingStyle | ((annotation: ImageAnnotation) => DrawingStyle) | undefined;
10
10
 
11
11
  $: computedStyle = computeStyle(annotation, style);
12
12
 
@@ -1,4 +1,4 @@
1
- <script type="ts">
1
+ <script lang="ts">
2
2
  import type { DrawingStyle } from '@annotorious/core';
3
3
  import type { Geometry, ImageAnnotation, RectangleGeometry } from '../../model';
4
4
  import { computeStyle } from '../utils/styling';
@@ -6,7 +6,7 @@
6
6
  /** Props **/
7
7
  export let annotation: ImageAnnotation;
8
8
  export let geom: Geometry;
9
- export let style: DrawingStyle | ((annotation: ImageAnnotation) => DrawingStyle) = undefined;
9
+ export let style: DrawingStyle | ((annotation: ImageAnnotation) => DrawingStyle) | undefined;
10
10
 
11
11
  $: computedStyle = computeStyle(annotation, style);
12
12
 
@@ -23,9 +23,9 @@
23
23
 
24
24
  const cleanup: Function[] = [];
25
25
 
26
- const addEventListener = (name: string, handler: (evt: PointerEvent) => void, capture?: boolean) => {
27
- svg.addEventListener(name, handler, capture);
28
- cleanup.push(() => svg.removeEventListener(name, handler, capture));
26
+ const addEventListener = (name: keyof SVGSVGElementEventMap, handler: EventListenerOrEventListenerObject, capture?: boolean) => {
27
+ svg?.addEventListener(name, handler, capture);
28
+ cleanup.push(() => svg?.removeEventListener(name, handler, capture));
29
29
  }
30
30
 
31
31
  toolComponent = new tool({
@@ -9,10 +9,11 @@ export type DrawingToolOpts = {
9
9
 
10
10
  drawingMode?: DrawingMode;
11
11
 
12
- [key: string]: string;
12
+ [key: string]: any;
13
13
 
14
14
  }
15
15
 
16
+ // @ts-ignore
16
17
  const REGISTERED = new Map<DrawingTool, { tool: typeof SvelteComponent, opts?: DrawingToolOpts }>([
17
18
  ['rectangle', { tool: RubberbandRectangle }],
18
19
  ['polygon', { tool: RubberbandPolygon }]
@@ -1,4 +1,4 @@
1
- <script type="ts">
1
+ <script lang="ts">
2
2
  import { onMount, createEventDispatcher } from 'svelte';
3
3
  import type { DrawingMode } from '../../../AnnotoriousOpts';
4
4
  import { boundsFromPoints, computeArea, ShapeType, type Polygon } from '../../../model';
@@ -17,7 +17,7 @@
17
17
 
18
18
  let points: [number, number][] = [];
19
19
 
20
- let cursor: [number, number] = null;
20
+ let cursor: [number, number] | undefined;
21
21
 
22
22
  let isClosable: boolean = false;
23
23
 
@@ -25,7 +25,9 @@
25
25
 
26
26
  $: handleSize = 10 / viewportScale;
27
27
 
28
- const onPointerDown = (evt: PointerEvent) => {
28
+ const onPointerDown = (event: Event) => {
29
+ const evt = event as PointerEvent;
30
+
29
31
  // Note that the event itself is ephemeral!
30
32
  const { timeStamp, offsetX, offsetY } = evt;
31
33
  lastPointerDown = { timeStamp, offsetX, offsetY };
@@ -40,7 +42,9 @@
40
42
  }
41
43
  }
42
44
 
43
- const onPointerMove = (evt: PointerEvent) => {
45
+ const onPointerMove = (event: Event) => {
46
+ const evt = event as PointerEvent;
47
+
44
48
  if (points.length > 0) {
45
49
  cursor = transform.elementToImage(evt.offsetX, evt.offsetY);
46
50
 
@@ -51,7 +55,9 @@
51
55
  }
52
56
  }
53
57
 
54
- const onPointerUp = (evt: PointerEvent) => {
58
+ const onPointerUp = (event: Event) => {
59
+ const evt = event as PointerEvent;
60
+
55
61
  if (drawingMode === 'click') {
56
62
  const timeDifference = evt.timeStamp - lastPointerDown.timeStamp;
57
63
 
@@ -71,17 +77,17 @@
71
77
 
72
78
  cursor = point;
73
79
  } else {
74
- points.push(cursor);
80
+ points.push(cursor!);
75
81
  }
76
82
  } else {
77
83
  // Require minimum drag of 4px
78
84
  if (points.length === 1) {
79
- const dist = distance(points[0], cursor);
85
+ const dist = distance(points[0], cursor!);
80
86
 
81
87
  if (dist <= 4) {
82
88
  // Cancel
83
89
  points = [];
84
- cursor = null;
90
+ cursor = undefined;
85
91
 
86
92
  return;
87
93
  }
@@ -93,7 +99,7 @@
93
99
  if (isClosable) {
94
100
  stopDrawing();
95
101
  } else {
96
- points.push(cursor);
102
+ points.push(cursor!);
97
103
  }
98
104
  }
99
105
  }
@@ -101,7 +107,7 @@
101
107
  const onDblClick = () => {
102
108
  // Require min 3 points (incl. cursor) and minimum
103
109
  // polygon area
104
- const p = [...points, cursor];
110
+ const p = [...points, cursor!];
105
111
 
106
112
  const shape: Polygon = {
107
113
  type: ShapeType.POLYGON,
@@ -114,7 +120,7 @@
114
120
  const area = computeArea(shape);
115
121
  if (area > 4) {
116
122
  points = [];
117
- cursor = null;
123
+ cursor = undefined;
118
124
 
119
125
  dispatch('create', shape);
120
126
  }
@@ -130,7 +136,7 @@
130
136
  }
131
137
 
132
138
  points = [];
133
- cursor = null;
139
+ cursor = undefined;
134
140
 
135
141
  dispatch('create', shape);
136
142
  }