@annotorious/core 3.0.0-rc.5 → 3.0.0-rc.7
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-core.es.js.map +1 -1
- package/dist/model/Annotator.d.ts +2 -2
- package/dist/model/Annotator.d.ts.map +1 -1
- package/dist/presence/AppearanceProvider.d.ts +1 -1
- package/dist/presence/AppearanceProvider.d.ts.map +1 -1
- package/dist/presence/PresenceState.d.ts +1 -1
- package/dist/presence/PresenceState.d.ts.map +1 -1
- package/dist/presence/PresentUser.d.ts +1 -1
- package/dist/presence/PresentUser.d.ts.map +1 -1
- package/dist/state/StoreObserver.d.ts +1 -1
- package/dist/state/StoreObserver.d.ts.map +1 -1
- package/dist/utils/annotationUtils.d.ts +2 -1
- package/dist/utils/annotationUtils.d.ts.map +1 -1
- package/dist/utils/diffAnnotations.d.ts +2 -2
- package/dist/utils/diffAnnotations.d.ts.map +1 -1
- package/package.json +3 -15
- package/src/index.ts +0 -5
- package/src/lifecycle/Lifecycle.ts +0 -211
- package/src/lifecycle/LifecycleEvents.ts +0 -21
- package/src/lifecycle/index.ts +0 -2
- package/src/model/Annotation.ts +0 -73
- package/src/model/Annotator.ts +0 -199
- package/src/model/DrawingStyle.ts +0 -19
- package/src/model/Filter.ts +0 -3
- package/src/model/FormatAdapter.ts +0 -36
- package/src/model/User.ts +0 -19
- package/src/model/W3CAnnotation.ts +0 -118
- package/src/model/index.ts +0 -7
- package/src/presence/Appearance.ts +0 -9
- package/src/presence/AppearanceProvider.ts +0 -53
- package/src/presence/ColorPalette.ts +0 -14
- package/src/presence/PresenceEvents.ts +0 -9
- package/src/presence/PresenceProvider.ts +0 -7
- package/src/presence/PresenceState.ts +0 -145
- package/src/presence/PresentUser.ts +0 -10
- package/src/presence/index.ts +0 -6
- package/src/state/Hover.ts +0 -34
- package/src/state/Selection.ts +0 -113
- package/src/state/Store.ts +0 -344
- package/src/state/StoreObserver.ts +0 -194
- package/src/state/SvelteStore.ts +0 -54
- package/src/state/UndoStack.ts +0 -143
- package/src/state/Viewport.ts +0 -14
- package/src/state/index.ts +0 -7
- package/src/utils/annotationUtils.ts +0 -33
- package/src/utils/diffAnnotations.ts +0 -39
- package/src/utils/index.ts +0 -3
- package/src/vite-env.d.ts +0 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { Annotation } from './Annotation';
|
|
2
2
|
import type { User } from './User';
|
|
3
|
-
import type { PresenceProvider } from '../presence';
|
|
3
|
+
import type { PresenceProvider } from '../presence/PresenceProvider';
|
|
4
4
|
import { type HoverState, type SelectionState, type Store, type UndoStack, type ViewportState } from '../state';
|
|
5
|
-
import type { LifecycleEvents } from '../lifecycle';
|
|
5
|
+
import type { LifecycleEvents } from '../lifecycle/LifecycleEvents';
|
|
6
6
|
import { type FormatAdapter } from './FormatAdapter';
|
|
7
7
|
import type { DrawingStyle } from './DrawingStyle';
|
|
8
8
|
import type { Filter } from './Filter';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Annotator.d.ts","sourceRoot":"","sources":["../../src/model/Annotator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"Annotator.d.ts","sourceRoot":"","sources":["../../src/model/Annotator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAU,KAAK,UAAU,EAAE,KAAK,cAAc,EAAE,KAAK,KAAK,EAAE,KAAK,SAAS,EAAE,KAAK,aAAa,EAAE,MAAM,UAAU,CAAC;AACxH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,EAAY,KAAK,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC/D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAEvC;;;;GAIG;AACH,MAAM,WAAW,SAAS,CAAC,CAAC,SAAS,UAAU,GAAG,UAAU,EAAE,CAAC,SAAS,OAAO,GAAG,UAAU;IAE1F,aAAa,CAAC,UAAU,EAAE,CAAC,GAAG,IAAI,CAAC;IAEnC,cAAc,IAAI,IAAI,CAAC;IAEvB,OAAO,IAAI,OAAO,CAAC;IAEnB,OAAO,IAAI,OAAO,CAAC;IAEnB,gBAAgB,IAAI,IAAI,CAAC;IAEzB,OAAO,IAAI,IAAI,CAAC;IAEhB,iBAAiB,CAAC,EAAE,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS,CAAC;IAE7C,cAAc,IAAI,CAAC,EAAE,CAAC;IAEtB,WAAW,IAAI,CAAC,EAAE,CAAC;IAEnB,OAAO,IAAI,IAAI,CAAC;IAEhB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC;IAE3C,IAAI,IAAI,IAAI,CAAC;IAEb,gBAAgB,CAAC,GAAG,EAAE,CAAC,GAAG,MAAM,GAAG,CAAC,CAAC;IAErC,cAAc,CAAC,WAAW,EAAE,CAAC,EAAE,GAAG,IAAI,CAAC;IAEvC,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAEhC,mBAAmB,CAAC,CAAC,QAAQ,EAAE,gBAAgB,GAAG,IAAI,CAAC;IAEvD,WAAW,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,IAAI,CAAC;IAE3C,QAAQ,CAAC,GAAG,EAAE,YAAY,GAAG,CAAC,CAAC,UAAU,EAAE,CAAC,KAAK,YAAY,CAAC,GAAG,SAAS,GAAG,IAAI,CAAC;IAElF,OAAO,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC;IAE1B,IAAI,IAAI,IAAI,CAAC;IAEb,gBAAgB,CAAC,UAAU,EAAE,CAAC,GAAG,CAAC,CAAC;IAEnC,EAAE,CAAC,CAAC,SAAS,MAAM,eAAe,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IAExF,GAAG,CAAC,CAAC,SAAS,MAAM,eAAe,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IAEzF,KAAK,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC;CAE1B;AAED,MAAM,WAAW,cAAc,CAAC,CAAC,SAAS,UAAU;IAElD,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;IAEhB,SAAS,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC;IAE7B,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC;IAErB,QAAQ,EAAE,aAAa,CAAC;CAEzB;AAED,eAAO,MAAM,mBAAmB;;;;;;4BAyBC,MAAM;;;2BAmBP,MAAM;;;;wBAkCT,MAAM,GAAG,MAAM,EAAE;;;CA0C7C,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AppearanceProvider.d.ts","sourceRoot":"","sources":["../../src/presence/AppearanceProvider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"AppearanceProvider.d.ts","sourceRoot":"","sources":["../../src/presence/AppearanceProvider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAGjD,MAAM,WAAW,kBAAkB;IAEjC,OAAO,CAAC,WAAW,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,GAAG,UAAU,CAAC;IAErD,UAAU,CAAC,IAAI,EAAE,WAAW,GAAG,IAAI,CAAC;CAErC;AAED,eAAO,MAAM,oBAAoB;;0BAaF,MAAM;CAKpC,CAAA;AAED,eAAO,MAAM,+BAA+B;2BAIZ,MAAM,QAAQ,IAAI,KAAG,UAAU;uBAUnC,WAAW;CAKtC,CAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Unsubscribe } from 'nanoevents';
|
|
2
|
-
import type { User } from '../model';
|
|
2
|
+
import type { User } from '../model/User';
|
|
3
3
|
import type { PresentUser } from './PresentUser';
|
|
4
4
|
import type { PresenceEvents } from './PresenceEvents';
|
|
5
5
|
import type { AppearanceProvider } from './AppearanceProvider';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PresenceState.d.ts","sourceRoot":"","sources":["../../src/presence/PresenceState.ts"],"names":[],"mappings":"AACA,OAAO,EAAoB,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AAChE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"PresenceState.d.ts","sourceRoot":"","sources":["../../src/presence/PresenceState.ts"],"names":[],"mappings":"AACA,OAAO,EAAoB,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AAChE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAEvD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE/D,MAAM,WAAW,aAAa;IAG5B,eAAe,IAAI,WAAW,EAAE,CAAC;IAGjC,cAAc,CAAC,WAAW,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;IAGnE,EAAE,CAAC,CAAC,SAAS,MAAM,cAAc,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,cAAc,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC;IAGvF,SAAS,CAAC,KAAK,EAAE;QAAE,WAAW,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,IAAI,CAAA;KAAE,EAAE,GAAG,IAAI,CAAC;IAG9D,eAAe,CAAC,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;CAExE;AAMD,eAAO,MAAM,YAAY,QAAW,CAAC;AAErC,eAAO,MAAM,mBAAmB,wBACV,kBAAkB,KACrC,aA6GF,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PresentUser.d.ts","sourceRoot":"","sources":["../../src/presence/PresentUser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"PresentUser.d.ts","sourceRoot":"","sources":["../../src/presence/PresentUser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE/C,MAAM,WAAW,WAAY,SAAQ,IAAI;IAEvC,WAAW,EAAE,MAAM,CAAC;IAEpB,UAAU,EAAE,UAAU,CAAA;CAEvB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Annotation, AnnotationBody, AnnotationTarget } from '../model';
|
|
1
|
+
import type { Annotation, AnnotationBody, AnnotationTarget } from '../model/Annotation';
|
|
2
2
|
/** Interface for listening to changes in the annotation store **/
|
|
3
3
|
export interface StoreObserver<T extends Annotation> {
|
|
4
4
|
onChange: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StoreObserver.d.ts","sourceRoot":"","sources":["../../src/state/StoreObserver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"StoreObserver.d.ts","sourceRoot":"","sources":["../../src/state/StoreObserver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAGxF,kEAAkE;AAClE,MAAM,WAAW,aAAa,CAAC,CAAC,SAAS,UAAU;IAEjD,QAAQ,EAAE;QAAE,CAAC,KAAK,EAAE,gBAAgB,CAAC,CAAC,CAAC,GAAG,IAAI,CAAA;KAAE,CAAC;IAEjD,OAAO,EAAE,mBAAmB,CAAC;CAE9B;AAED,yDAAyD;AACzD,MAAM,WAAW,gBAAgB,CAAC,CAAC,SAAS,UAAU;IAEpD,MAAM,EAAE,MAAM,CAAC;IAEf,OAAO,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;IAEtB,KAAK,EAAE,CAAC,EAAE,CAAC;CAEZ;AAED,MAAM,WAAW,SAAS,CAAC,CAAC,SAAS,UAAU;IAE7C,OAAO,CAAC,EAAE,CAAC,EAAE,CAAC;IAEd,OAAO,CAAC,EAAE,CAAC,EAAE,CAAC;IAEd,OAAO,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;CAEvB;AAED,MAAM,WAAW,MAAM,CAAC,CAAC,SAAS,UAAU;IAE1C,QAAQ,EAAE,CAAC,CAAC;IAEZ,QAAQ,EAAE,CAAC,CAAC;IAEZ,aAAa,CAAC,EAAE,cAAc,EAAE,CAAC;IAEjC,aAAa,CAAC,EAAE,cAAc,EAAE,CAAC;IAEjC,aAAa,CAAC,EAAE,KAAK,CAAC;QAAE,OAAO,EAAE,cAAc,CAAC;QAAC,OAAO,EAAE,cAAc,CAAA;KAAE,CAAC,CAAC;IAE5E,aAAa,CAAC,EAAE;QAAE,SAAS,EAAE,gBAAgB,CAAC;QAAC,SAAS,EAAE,gBAAgB,CAAA;KAAC,CAAC;CAE7E;AAED,gFAAgF;AAChF,MAAM,WAAW,mBAAmB;IAGlC,MAAM,CAAC,EAAE,MAAM,CAAC;IAGhB,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAGhC,MAAM,CAAC,EAAE,MAAM,CAAA;CAEhB;AAED,yDAAyD;AACzD,oBAAY,MAAM;IAGhB,SAAS,cAAc;IAGvB,WAAW,gBAAgB;CAE5B;AAED,qGAAqG;AACrG,oBAAY,MAAM;IAEhB,KAAK,UAAU;IAEf,MAAM,WAAW;CAElB;AAED,kEAAkE;AAClE,eAAO,MAAM,YAAY,2FAiDxB,CAAA;AAED,eAAO,MAAM,YAAY;;;;CA0DxB,CAAA"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { Annotation, AnnotationBody
|
|
1
|
+
import type { Annotation, AnnotationBody } from '../model/Annotation';
|
|
2
|
+
import type { User } from '../model/User';
|
|
2
3
|
/**
|
|
3
4
|
* Returns all users listed as creators or updaters in any parts of this
|
|
4
5
|
* annotation.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"annotationUtils.d.ts","sourceRoot":"","sources":["../../src/utils/annotationUtils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"annotationUtils.d.ts","sourceRoot":"","sources":["../../src/utils/annotationUtils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACtE,OAAO,KAAK,EAAG,IAAI,EAAE,MAAM,eAAe,CAAC;AAC3C;;;GAGG;AACH,eAAO,MAAM,eAAe,eAAgB,UAAU,KAAG,IAAI,EAY5D,CAAA;AAED,eAAO,MAAM,UAAU,eACT,UAAU;;aAEZ,IAAI,YACJ,IAAI,KACb,cAMD,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Update } from '../state';
|
|
2
|
-
import type { Annotation } from '../model';
|
|
1
|
+
import type { Update } from '../state/StoreObserver';
|
|
2
|
+
import type { Annotation } from '../model/Annotation';
|
|
3
3
|
export declare const diffAnnotations: <T extends Annotation = Annotation>(oldValue: T, newValue: T) => Update<T>;
|
|
4
4
|
//# sourceMappingURL=diffAnnotations.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"diffAnnotations.d.ts","sourceRoot":"","sources":["../../src/utils/diffAnnotations.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"diffAnnotations.d.ts","sourceRoot":"","sources":["../../src/utils/diffAnnotations.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAuBtD,eAAO,MAAM,eAAe,4EAa3B,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@annotorious/core",
|
|
3
|
-
"version": "3.0.0-rc.
|
|
3
|
+
"version": "3.0.0-rc.7",
|
|
4
4
|
"description": "Annotorious core types and functions",
|
|
5
5
|
"author": "Rainer Simon",
|
|
6
6
|
"license": "BSD-3-Clause",
|
|
@@ -18,24 +18,12 @@
|
|
|
18
18
|
"test": "vitest",
|
|
19
19
|
"coverage": "vitest run --coverage"
|
|
20
20
|
},
|
|
21
|
+
"main": "./dist/annotorious-core.es.js",
|
|
21
22
|
"module": "./dist/annotorious-core.es.js",
|
|
22
23
|
"types": "./dist/index.d.ts",
|
|
23
24
|
"files": [
|
|
24
|
-
"dist"
|
|
25
|
-
"src"
|
|
25
|
+
"dist"
|
|
26
26
|
],
|
|
27
|
-
"exports": {
|
|
28
|
-
".": {
|
|
29
|
-
"types": "./dist/index.d.ts",
|
|
30
|
-
"import": "./dist/annotorious-core.es.js"
|
|
31
|
-
},
|
|
32
|
-
"./src": "./src/index.ts",
|
|
33
|
-
"./src/lifecycle": "./src/lifecycle/index.ts",
|
|
34
|
-
"./src/model": "./src/model/index.ts",
|
|
35
|
-
"./src/presence": "./src/presence/index.ts",
|
|
36
|
-
"./src/state": "./src/state/index.ts",
|
|
37
|
-
"./src/utils": "./src/utils/index.ts"
|
|
38
|
-
},
|
|
39
27
|
"devDependencies": {
|
|
40
28
|
"@tsconfig/svelte": "^3.0.0",
|
|
41
29
|
"@types/deep-equal": "^1.0.2",
|
package/src/index.ts
DELETED
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
import { dequal } from 'dequal/lite';
|
|
2
|
-
import type { Annotation, AnnotatorState, FormatAdapter } from '../model';
|
|
3
|
-
import { Origin, type ChangeSet, type UndoStack } from '../state';
|
|
4
|
-
import type { ViewportState } from '../state';
|
|
5
|
-
import type { LifecycleEvents } from './LifecycleEvents';
|
|
6
|
-
|
|
7
|
-
export type Lifecycle<I extends Annotation, E extends unknown> =
|
|
8
|
-
ReturnType<typeof createLifecyleObserver<I, E>>;
|
|
9
|
-
|
|
10
|
-
export const createLifecyleObserver = <I extends Annotation, E extends unknown>(
|
|
11
|
-
state: AnnotatorState<I>,
|
|
12
|
-
undoStack: UndoStack<I>,
|
|
13
|
-
adapter?: FormatAdapter<I, E>,
|
|
14
|
-
autoSave?: boolean
|
|
15
|
-
) => {
|
|
16
|
-
const { store, selection, hover, viewport } = state;
|
|
17
|
-
|
|
18
|
-
const observers: Map<keyof LifecycleEvents, Function[]> = new Map();
|
|
19
|
-
|
|
20
|
-
// The currently selected annotations, in the state when they were selected
|
|
21
|
-
let initialSelection: I[] = [];
|
|
22
|
-
|
|
23
|
-
let currentHover: string | undefined;
|
|
24
|
-
|
|
25
|
-
let idleTimeout: ReturnType<typeof setTimeout>;
|
|
26
|
-
|
|
27
|
-
const on = <T extends keyof LifecycleEvents>(event: T, callback: LifecycleEvents<E>[T]) => {
|
|
28
|
-
if (observers.has(event)) {
|
|
29
|
-
observers.get(event).push(callback);
|
|
30
|
-
} else {
|
|
31
|
-
observers.set(event, [callback]);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const off = <T extends keyof LifecycleEvents<E>>(event: T, callback: LifecycleEvents<E>[T]) => {
|
|
36
|
-
const callbacks = observers.get(event);
|
|
37
|
-
if (callbacks) {
|
|
38
|
-
const idx = callbacks.indexOf(callback);
|
|
39
|
-
if (idx > 0)
|
|
40
|
-
callbacks.splice(callbacks.indexOf(callback), 1);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const emit = (event: keyof LifecycleEvents<E>, arg0: I | I[], arg1?: I | PointerEvent) => {
|
|
45
|
-
if (observers.has(event)) {
|
|
46
|
-
setTimeout(() => {
|
|
47
|
-
observers.get(event).forEach(callback => {
|
|
48
|
-
if (adapter) {
|
|
49
|
-
const serialized0 = Array.isArray(arg0) ?
|
|
50
|
-
arg0.map(a => adapter.serialize(a)) : adapter.serialize(arg0);
|
|
51
|
-
|
|
52
|
-
const serialized1: E | PointerEvent | undefined =
|
|
53
|
-
arg1 ? arg1 instanceof PointerEvent ? arg1 : adapter.serialize(arg1) : undefined;
|
|
54
|
-
|
|
55
|
-
callback(serialized0 as E & E[], serialized1);
|
|
56
|
-
} else {
|
|
57
|
-
callback(arg0 as E & E[], arg1 as unknown as E);
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
}, 1);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const onIdleUpdate = () => {
|
|
65
|
-
const { selected } = selection;
|
|
66
|
-
|
|
67
|
-
// User idle after activity - fire update events for selected
|
|
68
|
-
// annotations that changed
|
|
69
|
-
const updatedSelected = selected.map(({ id }) => store.getAnnotation(id));
|
|
70
|
-
|
|
71
|
-
updatedSelected.forEach(updated => {
|
|
72
|
-
const initial = initialSelection.find(a => a.id === updated.id);
|
|
73
|
-
if (!initial || !dequal(initial, updated)) {
|
|
74
|
-
emit('updateAnnotation', updated, initial);
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
initialSelection = initialSelection.map(initial => {
|
|
79
|
-
const updated = updatedSelected.find(({ id }) => id === initial.id);
|
|
80
|
-
return updated ? updated : initial
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
selection.subscribe(({ selected })=> {
|
|
85
|
-
if (initialSelection.length === 0 && selected.length === 0)
|
|
86
|
-
return;
|
|
87
|
-
|
|
88
|
-
if (initialSelection.length === 0 && selected.length > 0) {
|
|
89
|
-
// A new selection was made - store the editable annotation as initial state
|
|
90
|
-
initialSelection = selected.map(({ id }) => store.getAnnotation(id));
|
|
91
|
-
} else if (initialSelection.length > 0 && selected.length === 0) {
|
|
92
|
-
// Deselect!
|
|
93
|
-
initialSelection.forEach(initial => {
|
|
94
|
-
const updatedState = store.getAnnotation(initial.id);
|
|
95
|
-
|
|
96
|
-
if (updatedState && !dequal(updatedState, initial)) {
|
|
97
|
-
emit('updateAnnotation', updatedState, initial);
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
initialSelection = [];
|
|
102
|
-
} else {
|
|
103
|
-
// Changed selection
|
|
104
|
-
const initialIds = new Set(initialSelection.map(a => a.id));
|
|
105
|
-
const selectedIds = new Set(selected.map(({ id }) => id));
|
|
106
|
-
|
|
107
|
-
// Fire update events for deselected annotations that have changed
|
|
108
|
-
const deselected = initialSelection.filter(a => !selectedIds.has(a.id));
|
|
109
|
-
deselected.forEach(initial => {
|
|
110
|
-
const updatedState = store.getAnnotation(initial.id);
|
|
111
|
-
|
|
112
|
-
if (updatedState && !dequal(updatedState, initial))
|
|
113
|
-
emit('updateAnnotation', updatedState, initial);
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
initialSelection = [
|
|
117
|
-
// Remove annotations that were deselected
|
|
118
|
-
...initialSelection.filter(a => selectedIds.has(a.id)),
|
|
119
|
-
// Add editable annotations that were selected
|
|
120
|
-
...selected.filter(({ id }) => !initialIds.has(id))
|
|
121
|
-
.map(({ id }) => store.getAnnotation(id))
|
|
122
|
-
];
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
emit('selectionChanged', initialSelection);
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
hover.subscribe(id => {
|
|
129
|
-
if (!currentHover && id) {
|
|
130
|
-
emit('mouseEnterAnnotation', store.getAnnotation(id));
|
|
131
|
-
} else if (currentHover && !id) {
|
|
132
|
-
emit('mouseLeaveAnnotation', store.getAnnotation(currentHover));
|
|
133
|
-
} else if (currentHover && id) {
|
|
134
|
-
emit('mouseLeaveAnnotation', store.getAnnotation(currentHover));
|
|
135
|
-
emit('mouseEnterAnnotation', store.getAnnotation(id));
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
currentHover = id;
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
viewport?.subscribe(ids =>
|
|
142
|
-
emit('viewportIntersect', ids.map(store.getAnnotation)));
|
|
143
|
-
|
|
144
|
-
store.observe(event => {
|
|
145
|
-
// autoSave option triggers update events on idleness
|
|
146
|
-
if (autoSave) {
|
|
147
|
-
if (idleTimeout)
|
|
148
|
-
clearTimeout(idleTimeout);
|
|
149
|
-
|
|
150
|
-
idleTimeout = setTimeout(onIdleUpdate, 1000);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// Local CREATE and DELETE events are applied immediately
|
|
154
|
-
const { created, deleted } = event.changes;
|
|
155
|
-
created.forEach(a => emit('createAnnotation', a));
|
|
156
|
-
deleted.forEach(a => emit('deleteAnnotation', a));
|
|
157
|
-
|
|
158
|
-
// Updates are only applied immediately if they involve body changes
|
|
159
|
-
const updatesWithBody = event.changes.updated.filter(u => [
|
|
160
|
-
...(u.bodiesCreated || []),
|
|
161
|
-
...(u.bodiesDeleted || []),
|
|
162
|
-
...(u.bodiesUpdated || [])
|
|
163
|
-
].length > 0);
|
|
164
|
-
|
|
165
|
-
// Emit an update with the new annototation and the stored initial state
|
|
166
|
-
updatesWithBody.forEach(({ oldValue, newValue }) => {
|
|
167
|
-
const initial = initialSelection.find(a => a.id === oldValue.id) || oldValue;
|
|
168
|
-
|
|
169
|
-
// Record the update as the new last known state
|
|
170
|
-
initialSelection = initialSelection
|
|
171
|
-
.map(a => a.id === oldValue.id ? newValue : a);
|
|
172
|
-
|
|
173
|
-
emit('updateAnnotation', newValue, initial);
|
|
174
|
-
});
|
|
175
|
-
}, { origin: Origin.LOCAL });
|
|
176
|
-
|
|
177
|
-
// Track remote changes - these should update the initial state
|
|
178
|
-
store.observe(event => {
|
|
179
|
-
if (initialSelection) {
|
|
180
|
-
const selectedIds = new Set(initialSelection.map(a => a.id));
|
|
181
|
-
|
|
182
|
-
const relevantUpdates = event.changes.updated
|
|
183
|
-
.filter(({ newValue }) => selectedIds.has(newValue.id))
|
|
184
|
-
.map(({ newValue }) => newValue);
|
|
185
|
-
|
|
186
|
-
if (relevantUpdates.length > 0) {
|
|
187
|
-
initialSelection = initialSelection.map(selected => {
|
|
188
|
-
const updated = relevantUpdates.find(updated => updated.id === selected.id);
|
|
189
|
-
return updated ? updated : selected;
|
|
190
|
-
})
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
}, { origin: Origin.REMOTE });
|
|
194
|
-
|
|
195
|
-
const onUndoOrRedo = (undo: boolean) => (changes: ChangeSet<I>) => {
|
|
196
|
-
const { created, deleted, updated } = changes;
|
|
197
|
-
created.forEach(a => emit('createAnnotation', a));
|
|
198
|
-
deleted.forEach(a => emit('deleteAnnotation', a));
|
|
199
|
-
|
|
200
|
-
if (undo)
|
|
201
|
-
updated.forEach(t => emit('updateAnnotation', t.oldValue, t.newValue));
|
|
202
|
-
else
|
|
203
|
-
updated.forEach(t => emit('updateAnnotation', t.newValue, t.oldValue));
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
undoStack.on('undo', onUndoOrRedo(true));
|
|
207
|
-
undoStack.on('redo', onUndoOrRedo(false));
|
|
208
|
-
|
|
209
|
-
return { on, off, emit }
|
|
210
|
-
|
|
211
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { Annotation } from '../model';
|
|
2
|
-
|
|
3
|
-
export interface LifecycleEvents<T extends unknown = Annotation> {
|
|
4
|
-
|
|
5
|
-
clickAnnotation: (annotation: T, originalEvent: PointerEvent) => void;
|
|
6
|
-
|
|
7
|
-
createAnnotation: (annotation: T) => void;
|
|
8
|
-
|
|
9
|
-
deleteAnnotation: (annotation: T) => void;
|
|
10
|
-
|
|
11
|
-
mouseEnterAnnotation: (annotation: T) => void;
|
|
12
|
-
|
|
13
|
-
mouseLeaveAnnotation: (annotation: T) => void;
|
|
14
|
-
|
|
15
|
-
selectionChanged: (annotation: T[]) => void;
|
|
16
|
-
|
|
17
|
-
updateAnnotation: (annotation: T, previous: T) => void;
|
|
18
|
-
|
|
19
|
-
viewportIntersect: (visible: T[]) => void;
|
|
20
|
-
|
|
21
|
-
}
|
package/src/lifecycle/index.ts
DELETED
package/src/model/Annotation.ts
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import type { User } from './User';
|
|
2
|
-
|
|
3
|
-
export interface Annotation {
|
|
4
|
-
|
|
5
|
-
id: string;
|
|
6
|
-
|
|
7
|
-
target: AnnotationTarget;
|
|
8
|
-
|
|
9
|
-
bodies: AnnotationBody[];
|
|
10
|
-
|
|
11
|
-
properties?: {
|
|
12
|
-
|
|
13
|
-
[key: string]: any;
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export interface AnnotationTarget {
|
|
20
|
-
|
|
21
|
-
annotation: string;
|
|
22
|
-
|
|
23
|
-
selector: AbstractSelector;
|
|
24
|
-
|
|
25
|
-
creator?: User;
|
|
26
|
-
|
|
27
|
-
created?: Date;
|
|
28
|
-
|
|
29
|
-
updatedBy?: User;
|
|
30
|
-
|
|
31
|
-
updated?: Date;
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export interface AbstractSelector { }
|
|
36
|
-
|
|
37
|
-
export interface AnnotationBody {
|
|
38
|
-
|
|
39
|
-
id: string;
|
|
40
|
-
|
|
41
|
-
annotation: string;
|
|
42
|
-
|
|
43
|
-
type?: string;
|
|
44
|
-
|
|
45
|
-
purpose?: Purpose | string;
|
|
46
|
-
|
|
47
|
-
value?: string;
|
|
48
|
-
|
|
49
|
-
creator?: User;
|
|
50
|
-
|
|
51
|
-
created?: Date;
|
|
52
|
-
|
|
53
|
-
updatedBy?: User;
|
|
54
|
-
|
|
55
|
-
updated?: Date;
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// Pre-defined purposes from https://www.w3.org/TR/annotation-model/#motivation-and-purpose
|
|
60
|
-
export type Purpose =
|
|
61
|
-
'assessing' |
|
|
62
|
-
'bookmarking' |
|
|
63
|
-
'classifying' |
|
|
64
|
-
'commenting' |
|
|
65
|
-
'describing' |
|
|
66
|
-
'editing' |
|
|
67
|
-
'highlighting' |
|
|
68
|
-
'identifying' |
|
|
69
|
-
'linking' |
|
|
70
|
-
'moderating' |
|
|
71
|
-
'questioning' |
|
|
72
|
-
'replying' |
|
|
73
|
-
'tagging';
|
package/src/model/Annotator.ts
DELETED
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
import type { Annotation } from './Annotation';
|
|
2
|
-
import type { User } from './User';
|
|
3
|
-
import type { PresenceProvider } from '../presence';
|
|
4
|
-
import { Origin, type HoverState, type SelectionState, type Store, type UndoStack, type ViewportState } from '../state';
|
|
5
|
-
import type { LifecycleEvents } from '../lifecycle';
|
|
6
|
-
import { parseAll, type FormatAdapter } from './FormatAdapter';
|
|
7
|
-
import type { DrawingStyle } from './DrawingStyle';
|
|
8
|
-
import type { Filter } from './Filter';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Base annotator interface.
|
|
12
|
-
* I ... internal core data model
|
|
13
|
-
* E ... external adapted representation
|
|
14
|
-
*/
|
|
15
|
-
export interface Annotator<I extends Annotation = Annotation, E extends unknown = Annotation> {
|
|
16
|
-
|
|
17
|
-
addAnnotation(annotation: E): void;
|
|
18
|
-
|
|
19
|
-
cancelSelected(): void;
|
|
20
|
-
|
|
21
|
-
canRedo(): boolean;
|
|
22
|
-
|
|
23
|
-
canUndo(): boolean;
|
|
24
|
-
|
|
25
|
-
clearAnnotations(): void;
|
|
26
|
-
|
|
27
|
-
destroy(): void;
|
|
28
|
-
|
|
29
|
-
getAnnotationById(id: string): E | undefined;
|
|
30
|
-
|
|
31
|
-
getAnnotations(): E[];
|
|
32
|
-
|
|
33
|
-
getSelected(): E[];
|
|
34
|
-
|
|
35
|
-
getUser(): User;
|
|
36
|
-
|
|
37
|
-
loadAnnotations(url: string): Promise<E[]>;
|
|
38
|
-
|
|
39
|
-
redo(): void;
|
|
40
|
-
|
|
41
|
-
removeAnnotation(arg: E | string): E;
|
|
42
|
-
|
|
43
|
-
setAnnotations(annotations: E[]): void;
|
|
44
|
-
|
|
45
|
-
setFilter(filter: Filter): void;
|
|
46
|
-
|
|
47
|
-
setPresenceProvider?(provider: PresenceProvider): void;
|
|
48
|
-
|
|
49
|
-
setSelected(arg?: string | string[]): void;
|
|
50
|
-
|
|
51
|
-
setStyle(arg: DrawingStyle | ((annotation: I) => DrawingStyle) | undefined): void;
|
|
52
|
-
|
|
53
|
-
setUser(user: User): void;
|
|
54
|
-
|
|
55
|
-
undo(): void;
|
|
56
|
-
|
|
57
|
-
updateAnnotation(annotation: E): E;
|
|
58
|
-
|
|
59
|
-
on<T extends keyof LifecycleEvents<E>>(event: T, callback: LifecycleEvents<E>[T]): void;
|
|
60
|
-
|
|
61
|
-
off<T extends keyof LifecycleEvents<E>>(event: T, callback: LifecycleEvents<E>[T]): void;
|
|
62
|
-
|
|
63
|
-
state: AnnotatorState<I>;
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export interface AnnotatorState<A extends Annotation> {
|
|
68
|
-
|
|
69
|
-
store: Store<A>;
|
|
70
|
-
|
|
71
|
-
selection: SelectionState<A>;
|
|
72
|
-
|
|
73
|
-
hover: HoverState<A>;
|
|
74
|
-
|
|
75
|
-
viewport: ViewportState;
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export const createBaseAnnotator = <I extends Annotation, E extends unknown>(
|
|
80
|
-
state: AnnotatorState<I>,
|
|
81
|
-
undoStack: UndoStack<I>,
|
|
82
|
-
adapter?: FormatAdapter<I, E>
|
|
83
|
-
) => {
|
|
84
|
-
|
|
85
|
-
const { store, selection } = state;
|
|
86
|
-
|
|
87
|
-
const addAnnotation = (annotation: E) => {
|
|
88
|
-
if (adapter) {
|
|
89
|
-
const { parsed, error } = adapter.parse(annotation);
|
|
90
|
-
if (parsed) {
|
|
91
|
-
store.addAnnotation(parsed, Origin.REMOTE);
|
|
92
|
-
} else {
|
|
93
|
-
console.error(error);
|
|
94
|
-
}
|
|
95
|
-
} else {
|
|
96
|
-
store.addAnnotation(annotation as unknown as I, Origin.REMOTE);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
const cancelSelected = () => selection.clear();
|
|
101
|
-
|
|
102
|
-
const clearAnnotations = () => store.clear();
|
|
103
|
-
|
|
104
|
-
const getAnnotationById = (id: string): E | undefined => {
|
|
105
|
-
const annotation = store.getAnnotation(id);
|
|
106
|
-
return (adapter && annotation) ?
|
|
107
|
-
adapter.serialize(annotation) as E : annotation as unknown as E;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
const getAnnotations = () =>
|
|
111
|
-
(adapter ? store.all().map(adapter.serialize) : store.all()) as E[];
|
|
112
|
-
|
|
113
|
-
const getSelected = () => {
|
|
114
|
-
const selectedIds = selection.selected?.map(s => s.id) || [];
|
|
115
|
-
|
|
116
|
-
const selected = selectedIds.map(id => store.getAnnotation(id));
|
|
117
|
-
|
|
118
|
-
return adapter
|
|
119
|
-
? selected.map(adapter.serialize)
|
|
120
|
-
: selected as unknown as E[];
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
const loadAnnotations = (url: string) =>
|
|
124
|
-
fetch(url)
|
|
125
|
-
.then((response) => response.json())
|
|
126
|
-
.then((annotations) => {
|
|
127
|
-
setAnnotations(annotations);
|
|
128
|
-
return annotations;
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
const removeAnnotation = (arg: E | string): E => {
|
|
132
|
-
if (typeof arg === 'string') {
|
|
133
|
-
const annotation = store.getAnnotation(arg);
|
|
134
|
-
store.deleteAnnotation(arg);
|
|
135
|
-
|
|
136
|
-
return adapter ? adapter.serialize(annotation) : annotation as unknown as E;
|
|
137
|
-
} else {
|
|
138
|
-
const annotation = adapter ? adapter.parse(arg).parsed : (arg as unknown as I);
|
|
139
|
-
store.deleteAnnotation(annotation);
|
|
140
|
-
return arg;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
const setAnnotations = (annotations: E[]) => {
|
|
145
|
-
if (adapter) {
|
|
146
|
-
const { parsed, failed } = parseAll(adapter)(annotations);
|
|
147
|
-
|
|
148
|
-
if (failed.length > 0)
|
|
149
|
-
console.warn(`Discarded ${failed.length} invalid annotations`, failed);
|
|
150
|
-
|
|
151
|
-
store.bulkAddAnnotation(parsed, true, Origin.REMOTE);
|
|
152
|
-
} else {
|
|
153
|
-
store.bulkAddAnnotation(annotations as unknown as I[], true, Origin.REMOTE);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
const setSelected = (arg?: string | string[]) => {
|
|
158
|
-
if (arg) {
|
|
159
|
-
selection.setSelected(arg);
|
|
160
|
-
} else {
|
|
161
|
-
selection.clear();
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
const updateAnnotation = (updated: E): E => {
|
|
166
|
-
if (adapter) {
|
|
167
|
-
const crosswalked = adapter.parse(updated).parsed;
|
|
168
|
-
const previous = adapter.serialize(store.getAnnotation(crosswalked.id));
|
|
169
|
-
store.updateAnnotation(crosswalked);
|
|
170
|
-
return previous;
|
|
171
|
-
} else {
|
|
172
|
-
const previous = store.getAnnotation((updated as unknown as I).id);
|
|
173
|
-
store.updateAnnotation(updated as unknown as I);
|
|
174
|
-
return previous as unknown as E;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
// Note that we don't spread the undoStack - it has a .destroy()
|
|
179
|
-
// method that would likely get overwritten by other Annotator implementations
|
|
180
|
-
// if people are not careful.
|
|
181
|
-
return {
|
|
182
|
-
addAnnotation,
|
|
183
|
-
cancelSelected,
|
|
184
|
-
canRedo: undoStack.canRedo,
|
|
185
|
-
canUndo: undoStack.canUndo,
|
|
186
|
-
clearAnnotations,
|
|
187
|
-
getAnnotationById,
|
|
188
|
-
getAnnotations,
|
|
189
|
-
getSelected,
|
|
190
|
-
loadAnnotations,
|
|
191
|
-
redo: undoStack.redo,
|
|
192
|
-
removeAnnotation,
|
|
193
|
-
setAnnotations,
|
|
194
|
-
setSelected,
|
|
195
|
-
undo: undoStack.undo,
|
|
196
|
-
updateAnnotation
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
}
|