@annotorious/core 3.0.0-pre-alpha-53 → 3.0.0-pre-alpha-55

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@annotorious/core",
3
- "version": "3.0.0-pre-alpha-53",
3
+ "version": "3.0.0-pre-alpha-55",
4
4
  "description": "Annotorious core types and functions",
5
5
  "author": "Rainer Simon",
6
6
  "license": "BSD-3-Clause",
@@ -3,8 +3,8 @@ import type { User } from './User';
3
3
  import type { PresenceProvider } from '../presence';
4
4
  import { Origin, type HoverState, type SelectionState, type Store, type ViewportState } from '../state';
5
5
  import type { LifecycleEvents } from '../lifecycle';
6
- import type { Formatter } from './Formatter';
7
6
  import { parseAll, type FormatAdapter } from './FormatAdapter';
7
+ import type { DrawingStyle } from './DrawingStyle';
8
8
 
9
9
  /**
10
10
  * Base annotator interface.
@@ -13,6 +13,8 @@ import { parseAll, type FormatAdapter } from './FormatAdapter';
13
13
  */
14
14
  export interface Annotator<I extends Annotation = Annotation, E extends unknown = Annotation> {
15
15
 
16
+ style: DrawingStyle | ((annotation: I) => DrawingStyle) | undefined;
17
+
16
18
  addAnnotation(annotation: E): void;
17
19
 
18
20
  clearAnnotations(): void;
@@ -31,8 +33,6 @@ export interface Annotator<I extends Annotation = Annotation, E extends unknown
31
33
 
32
34
  setAnnotations(annotations: E[]): void;
33
35
 
34
- setFormatter(formatter: Formatter): void;
35
-
36
36
  setPresenceProvider?(provider: PresenceProvider): void;
37
37
 
38
38
  setSelected(arg?: string | string[]): void;
@@ -1,5 +1,3 @@
1
- import type { Annotation } from './Annotation';
2
-
3
1
  type RGB = `rgb(${number}, ${number}, ${number})`;
4
2
 
5
3
  type RGBA = `rgba(${number}, ${number}, ${number}, ${number})`;
@@ -14,6 +12,8 @@ export interface DrawingStyle {
14
12
 
15
13
  fillOpacity?: number;
16
14
 
17
- }
15
+ stroke?: Color;
16
+
17
+ strokeOpacity?: number;
18
18
 
19
- export type Formatter = <T extends Annotation = Annotation>(annotation: T, isSelected?: boolean) => DrawingStyle;
19
+ }
@@ -83,7 +83,7 @@ export const parseW3CBodies = (
83
83
  ): AnnotationBody[] => (Array.isArray(body) ? body : [body]).map(body => {
84
84
 
85
85
  // Exctract properties that conform to the internal model, but keep custom props
86
- const { id, type, purpose, value, created, creator, ...rest} = body;
86
+ const { id, type, purpose, value, created, creator, ...rest } = body;
87
87
 
88
88
  // The internal model strictly requires IDs. (Because multi-user scenarios
89
89
  // will have problems without them.) In the W3C model, bodys *may* have IDs.
@@ -91,7 +91,7 @@ export const parseW3CBodies = (
91
91
  // generating the ID is idempotent: the same body should always get the same ID.
92
92
  // This will avoid unexpected results when checking for equality.
93
93
  return {
94
- id: id || hashCode(body),
94
+ id: id || `temp-${hashCode(body)}`,
95
95
  annotation: annotationId,
96
96
  type,
97
97
  purpose,
@@ -105,11 +105,14 @@ export const parseW3CBodies = (
105
105
 
106
106
  });
107
107
 
108
+ /** Serialization helper to remove core-specific fields from the annotation body **/
108
109
  export const serializeW3CBodies = (bodies: AnnotationBody[]): W3CAnnotationBody[] =>
109
110
  bodies.map(b => {
110
111
  const w3c = { ...b };
111
112
  delete w3c.annotation;
112
- delete w3c.id;
113
- return w3c;
114
- });
115
113
 
114
+ if (w3c.id?.startsWith('temp-'))
115
+ delete w3c.id;
116
+
117
+ return w3c;
118
+ });
@@ -1,6 +1,6 @@
1
1
  export * from './Annotation';
2
2
  export * from './Annotator';
3
+ export * from './DrawingStyle';
3
4
  export * from './FormatAdapter';
4
- export * from './Formatter';
5
5
  export * from './User';
6
6
  export * from './W3CAnnotation';
@@ -16,7 +16,7 @@ export enum PointerSelectAction {
16
16
 
17
17
  EDIT = 'EDIT', // Make annotation target(s) editable on pointer select
18
18
 
19
- HIGHLIGHT = 'HIGHLIGHT', // Just hightlight on select, but don't make editable
19
+ SELECT = 'SELECT', // Just select, but don't make editable
20
20
 
21
21
  NONE = 'NONE' // Click won't select - annotation is completely inert
22
22
 
@@ -53,7 +53,7 @@ export const createSelectionState = <T extends Annotation>(
53
53
  const action = onPointerSelect(annotation, selectAction);
54
54
  if (action === PointerSelectAction.EDIT)
55
55
  set({ selected: [{ id, editable: true }], pointerEvent });
56
- else if (action === PointerSelectAction.HIGHLIGHT)
56
+ else if (action === PointerSelectAction.SELECT)
57
57
  set({ selected: [{ id }], pointerEvent });
58
58
  else
59
59
  set({ selected: [], pointerEvent });