@triiiceratops/plugin-annotation-editor 1.0.0-rc.7 → 1.0.0

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.
@@ -1,260 +0,0 @@
1
- import type { AnnotationEditorConfig, AnnotationPersistenceOp, DrawingTool } from './types';
2
- import { AnnotationStore } from './AnnotationStore.svelte';
3
- import type { ViewerState } from 'triiiceratops';
4
- /** Every tool the plugin knows how to draw, in default button order. */
5
- export declare const ALL_TOOLS: DrawingTool[];
6
- /**
7
- * Resolve the effective tool set and default tool from config so the manager
8
- * and controller share one source of truth (F8). An empty/absent `tools` list
9
- * means "all tools"; `defaultTool` is honored only when it's within `tools`,
10
- * otherwise the first available tool wins.
11
- */
12
- export declare function resolveTools(config: {
13
- tools?: DrawingTool[];
14
- defaultTool?: DrawingTool;
15
- }): {
16
- tools: DrawingTool[];
17
- defaultTool: DrawingTool;
18
- };
19
- /**
20
- * Manages the Annotorious instance and annotation CRUD operations.
21
- * Instantiated within the controller component.
22
- */
23
- export declare class AnnotationManager {
24
- private static readonly ACTIVE_EDIT_ID_EVENT;
25
- private static readonly DEFAULT_POINT_FILL;
26
- private static readonly DEFAULT_POINT_STROKE;
27
- private static readonly DEFAULT_POINT_STROKE_WIDTH;
28
- private static readonly DEFAULT_DRAWING_STYLE;
29
- private config;
30
- private store;
31
- private readonly ownsStore;
32
- private readonly viewerState;
33
- private annotorious;
34
- private osdViewer;
35
- private openHandler;
36
- private canvasClickHandler;
37
- private createOSDAnnotator;
38
- private W3CImageFormat;
39
- private OSD;
40
- private editingPointOrigin;
41
- private get currentManifestId();
42
- private get currentCanvasId();
43
- private activeEditingAnnotationId;
44
- private lastHandledCanvasKey;
45
- private suppressedEchoIds;
46
- private isDrawingEnabled;
47
- private activeTool;
48
- private selectedAnnotation;
49
- private readonly resolvedTools;
50
- readonly resolvedDefaultTool: DrawingTool;
51
- onSelectionChange?: (annotation: any | null) => void;
52
- onAnnotationCreated?: (annotation: any) => void;
53
- onAnnotationHydrationChange?: (isHydrating: boolean) => void;
54
- onActiveEditingAnnotationChange?: (annotationId: string | null) => void;
55
- constructor(config: AnnotationEditorConfig, store?: AnnotationStore, viewerState?: ViewerState);
56
- init(viewer: any, canvasId: string | null): void;
57
- private initAnnotorious;
58
- /**
59
- * Create a true IIIF `PointSelector` annotation at the exact click point
60
- * (F17). The click is converted click → viewport → image coords → canvas
61
- * coords and rounded once to integer canvas pixels (D2) — no synthetic
62
- * fragment rectangle, no zoom-dependent geometry, no `point-` id heuristic.
63
- * The annotation goes through the same store create path as drawn shapes
64
- * (prepareDraft, stamping, display sync); it is already canvas-space, so the
65
- * image→canvas transform is skipped. It is then opened for body editing.
66
- */
67
- private handlePointClick;
68
- setEditing(enabled: boolean): void;
69
- private updateDrawingMode;
70
- /**
71
- * A point annotation is one whose target carries a `PointSelector` (F17).
72
- * Recurses one level into `selector.item` for wrapped selectors, matching
73
- * `annotationAdapter.ts`. No `point-` id heuristic — geometry, not id, is
74
- * authoritative.
75
- */
76
- private isPointAnnotation;
77
- private getPointCoordinates;
78
- private toPointSelectorTarget;
79
- /**
80
- * Convert a cached (canvas-space) annotation into the image-space shape
81
- * Annotorious edits. Non-points scale straight to image space. A point has
82
- * no Annotorious tool, so it becomes a small fragment rectangle centred on
83
- * the point and sized in **screen pixels at selection time** (§3.2): the
84
- * marker keeps a constant visual size regardless of image resolution or
85
- * zoom. The exact point is recorded separately (`editingPointOrigin`) so the
86
- * reverse conversion never re-derives it from the rect centre.
87
- */
88
- private toAnnotoriousTarget;
89
- /**
90
- * Reverse of {@link toAnnotoriousTarget} for a point being edited: turn the
91
- * image-space fragment rect Annotorious holds back into a canvas-space
92
- * `PointSelector`. If the rect's centre still maps to the recorded origin
93
- * (integer canvas px, D2), the point wasn't dragged and the origin is emitted
94
- * verbatim — a bit-identical round-trip. If it moved, the new rect centre is
95
- * used (§3.2).
96
- */
97
- private pointFromEditingRect;
98
- private parseFragmentRect;
99
- /**
100
- * The point editing rectangle's side length in **image units**, derived from
101
- * the configured marker diameter (screen px) and the current
102
- * image-units-per-screen-pixel. Falls back to treating the diameter as
103
- * canvas units (scaled to image space) when the viewport can't be measured
104
- * yet — e.g. before the viewer's first render.
105
- */
106
- private pointEditRectImageSize;
107
- /**
108
- * Image units spanned by one screen pixel at the current zoom, measured the
109
- * way the old point-authoring code did: convert two 1px-apart screen points
110
- * to image coordinates and take the delta. Returns null when the viewport
111
- * isn't available.
112
- */
113
- private imageUnitsPerScreenPixel;
114
- /**
115
- * Annotorious `style` callback: points get the configured marker colours,
116
- * every other shape gets the host's drawing style (F9). A point is
117
- * identified by having an editing origin recorded for its id.
118
- */
119
- private styleForAnnotation;
120
- private getCurrentCanvasImageDimensions;
121
- setTool(tool: DrawingTool): void;
122
- get availableTools(): DrawingTool[];
123
- /**
124
- * The store's current unhandled persistence error for the panel's default
125
- * error line, or `null` when there's nothing to show (F20).
126
- */
127
- get persistenceError(): {
128
- op: AnnotationPersistenceOp;
129
- annotationId?: string;
130
- } | null;
131
- /** Dismiss the panel's persistence error line. */
132
- dismissPersistenceError(): void;
133
- /** Whether an undo is available (reactive; drives the panel button — F6). */
134
- get canUndo(): boolean;
135
- /** Whether a redo is available (reactive; drives the panel button — F6). */
136
- get canRedo(): boolean;
137
- /**
138
- * Reverse the most recent persisted operation through the store's op stack,
139
- * replaying its inverse against the adapter so storage and display stay in
140
- * agreement (F6).
141
- */
142
- undo(): Promise<void>;
143
- /** Re-apply the most recently undone operation (F6). */
144
- redo(): Promise<void>;
145
- private setupEvents;
146
- private setActiveEditingAnnotationId;
147
- /**
148
- * Reset the manager's Annotorious-facing selection fields. Shared by the two
149
- * teardown paths: `clearSelectionState()` (also notifies the host, leaves
150
- * Annotorious untouched) and `clearAnnotoriousEditingAnnotation()` (also
151
- * clears Annotorious's annotation set).
152
- */
153
- private resetSelectionFields;
154
- /**
155
- * Tear down the current selection and tell the host it's gone, without
156
- * touching Annotorious's own annotation set. Used on the create/delete/
157
- * rollback paths where Annotorious's shape is managed separately.
158
- */
159
- private clearSelectionState;
160
- private clearAnnotoriousEditingAnnotation;
161
- /**
162
- * Clear all annotations from Annotorious, marking each so the resulting
163
- * (async) `deleteAnnotation` echo is consumed by handleDeleteAnnotation and
164
- * never mistaken for a user-originated deletion (F27). Only ids actually
165
- * present are marked, so no stale marks accrue.
166
- */
167
- private clearAnnotationsSuppressed;
168
- handleCanvasChange(manifestId: string | null, canvasId: string | null): Promise<void>;
169
- private loadAnnotations;
170
- /**
171
- * Handles Annotorious's (async) `createAnnotation` lifecycle event. Persists
172
- * exactly what the host's prepareDraft/prepareAnnotation produced — not the
173
- * raw event payload — so draft enrichment survives create (F2).
174
- */
175
- private handleCreateAnnotation;
176
- /**
177
- * Handles Annotorious's (async) `updateAnnotation` lifecycle event. Echoes
178
- * we triggered ourselves (e.g. pushing edited bodies back into Annotorious)
179
- * are consumed here so they don't double-persist (F3).
180
- */
181
- private handleUpdateAnnotation;
182
- /**
183
- * Handles Annotorious's (async) `deleteAnnotation` lifecycle event. Echoes
184
- * from our own `clearAnnotations()` teardown are marked and consumed here so
185
- * they never reach the adapter. A genuine Annotorious-originated deletion of
186
- * a persisted annotation syncs the adapter, cache, and selection state (F27).
187
- */
188
- private handleDeleteAnnotation;
189
- /**
190
- * Persist an annotation that arrived in **image space** (Annotorious event
191
- * payloads, geometry edits). Transforms to canvas space, forces the target
192
- * source, applies beforeSave, then persists.
193
- */
194
- saveAnnotation(annotation: any): Promise<boolean>;
195
- /**
196
- * Convert an image-space annotation from Annotorious into canvas space for
197
- * the cache/panel/store. An actively-edited point takes the lossless
198
- * origin-aware path (§3.2); everything else scales normally, with legacy
199
- * fragment-centre read-compat via `toPointSelectorTarget` (D3).
200
- */
201
- private annotationToCanvasSpace;
202
- /**
203
- * Persist a freshly created annotation that is already in **canvas space**
204
- * (the output of prepareAnnotation). Skips the image→canvas re-transform;
205
- * beforeSave still runs last. Returns whether the write succeeded.
206
- */
207
- private persistCreate;
208
- /**
209
- * Run a store mutation whose resulting (asynchronous) Annotorious lifecycle
210
- * echo for `annotationId` must not be re-persisted.
211
- *
212
- * NOTE: Annotorious v3 dispatches lifecycle events via `setTimeout(…, 1)`
213
- * (verified in @annotorious/core@3.7.19), so a synchronous boolean guard as
214
- * originally planned would already be reset by the time the echo fires. We
215
- * mark the id and let the echo consume the mark instead. A body-change
216
- * update emits exactly one echo, so one mark == one consumed echo.
217
- */
218
- private withSuppressedEcho;
219
- /** Record one more expected self-triggered echo for this id. */
220
- private markSuppressedEcho;
221
- /**
222
- * Consume one expected echo for this id. Returns true (and decrements the
223
- * count, deleting the entry at zero) while echoes remain outstanding, so two
224
- * concurrent echoes — e.g. a body-save update echo and a teardown delete echo
225
- * for the same id — are each matched and neither leaks (F3/F27).
226
- */
227
- private consumeSuppressedEcho;
228
- /**
229
- * Always overwrite `target.source` with the current canvas id. Within this
230
- * plugin the target is by definition the canvas the user is annotating, so
231
- * overwriting is safe regardless of what the Annotorious W3C serializer
232
- * stamped at init time (see F1). All other target fields are preserved.
233
- */
234
- private forceTargetSource;
235
- private prepareAnnotation;
236
- private applyBeforeSave;
237
- private getRuntimeContext;
238
- private notifyExtensionSelectionChange;
239
- private hydrateAnnotation;
240
- deleteAnnotation(annotationId: string): Promise<boolean>;
241
- updateAnnotationBodies(annotationId: string, bodies: unknown[] | unknown): Promise<boolean>;
242
- /**
243
- * React to the store swapping a freshly-created annotation onto its
244
- * server-assigned id (F5). If that annotation is the one currently open for
245
- * editing, re-open it under the canonical id: this re-adds it to Annotorious,
246
- * reselects it, and re-emits the active-edit-id signal with the new id.
247
- */
248
- private handleIdReconciled;
249
- /**
250
- * Reconcile the open Annotorious editing session with an undo/redo replay
251
- * (F6). Only the annotation currently open is affected: if the replay left
252
- * it in storage, re-open it so its geometry and body reflect the restored
253
- * state; if the replay removed it (e.g. undoing the create of the annotation
254
- * being edited), tear the editing session down.
255
- */
256
- private handleReplay;
257
- selectAnnotationById(annotationId: string): Promise<void>;
258
- cancelSelection(): void;
259
- destroy(): void;
260
- }
package/dist/styles.d.ts DELETED
@@ -1,11 +0,0 @@
1
- /**
2
- * The combined stylesheet (base Annotorious sheet + layer fixes) installed under
3
- * the `annotorious` id at activation, shaped by {@link definePluginStyles} into
4
- * the `STYLES` / `STYLE_ID` exports.
5
- *
6
- * No plugin chrome CSS lives here anymore: core owns the toolbar button and the
7
- * docked-panel / anchored-flyout surface (epic restore-plugin-toolbar-chrome),
8
- * so the plugin ships only the Annotorious annotation-layer styles. The panel's
9
- * own presentation is scoped component CSS rendered inside `view.mount`.
10
- */
11
- export declare const STYLES: string, STYLE_ID: string;