-
Notifications
You must be signed in to change notification settings - Fork 31
/
webceph.d.ts
953 lines (859 loc) · 23.7 KB
/
webceph.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
declare const __DEBUG__: boolean;
declare const __VERSION__: string;
declare const __BUILD_TIMESTAMP__: number;
type AngularUnit = 'degree' | 'radian';
type LinearUnit = 'mm' | 'cm' | 'in';
type LandmarkType = 'angle' | 'point' | 'line' | 'distance' | 'sum' | 'ratio';
type Categories = {
skeletalPattern: 'class1' | 'class2' | 'tendency_for_class3' | 'class3',
maxilla: 'normal' | 'prognathic' | 'retrognathic',
mandible: 'normal' | 'prognathic' | 'retrognathic',
skeletalProfile: 'normal' | 'concave' | 'convex',
mandibularRotation: 'normal' | 'clockwise' | 'counterclockwise',
growthPattern: 'normal' | 'horizontal' | 'vertical',
upperIncisorInclination: 'normal' | 'labial' | 'palatal',
lowerIncisorInclination: 'normal' | 'labial' | 'lingual',
skeletalBite: 'normal' | 'open' | 'closed',
chin: 'normal' | 'recessive' | 'prominent',
overbite: 'normal' | 'negative' | 'decreased' | 'increased',
overjet: 'normal' | 'negative' | 'decreased' | 'increased',
lowerLipProminence: 'normal' | 'resessive' | 'prominent',
upperLipProminence: 'normal' | 'resessive' | 'prominent',
};
type Category = keyof Categories;
type Indication<C extends Category> = Categories[C];
type Severity = 'none' | 'low' | 'medium' | 'high';
interface LandmarkInterpretation<T extends Category> {
category: T;
indication: Indication<T>;
severity?: Severity;
value: number;
max: number;
min: number;
mean: number;
}
interface AnalysisInterpretation<T extends Category> extends LandmarkInterpretation<T> {
/** A list of symbol that were used to calculate this result */
relevantComponents: string[];
}
type CalculateLandmark<Calculated extends (number | undefined), MappedComponent, Mapped> = (
/** The calculated values of this landmark's components
* in the same order they were defined
*/
...calculated: Array<Calculated | undefined>,
) => (
/**
* The geometrical representation of this landmark's components
* in the same order they were defined.
*/
...mapped: Array<MappedComponent | undefined>,
) => (
/**
* The geometrical representation of this landmark itself.
* Should be the result of calling map on this landmark if it is defined.
*/
mappedComponent: Mapped | undefined,
) => number;
type MapLandmark<Mapped, Result> = (
/** The geometrical representation of this landmark's components
* in the same order they were defined
*/
...mapped: Array<Mapped | undefined>,
) => Result;
type InterpretLandmark<C extends Category> = (
value: number, min: number, max: number, mean: number,
) => Array<LandmarkInterpretation<C>>;
type InterpretAnalysis<C extends Category> = (
values: Record<string, number | undefined>,
objects: Record<string, GeoObject | undefined>,
) => Array<CategorizedAnalysisResult<C>>;
/**
* A generic interface that represents any cephalometric landmark, including
* angles, lines and points.
* Landmarks may also have names and units.
*/
interface CephLandmark {
name?: string;
/**
* Each landmark must have a symbol which acts as the unique identifier for that landmark.
*/
symbol: string;
/** The type of radiograph or photograph on which this landmark can be set. */
imageType: ImageType;
description?: string;
type: LandmarkType;
unit?: AngularUnit | LinearUnit;
/**
* Some landmarks are composed of more basic components; for example, a line is
* composed of two points.
*/
components: CephLandmark[];
/** An optional custom calculation method.
* It is a curried function that is first passed the calculated values of this
* landmark's components (if applicable) and then geometrical representation of
* those components in the same order they were defined.
*/
calculate?: CalculateLandmark<number, GeoObject, GeoObject>;
/** An optional custom mapping method.
* It is a curried function that is first passed the calculated values of this
* landmark's components (if applicable) and then geometrical representation of
* those components in the same order they were defined.
*/
map?: MapLandmark<GeoObject, GeoObject>;
/** An optional interpretation method.
* It is passed the calculated value of this landmark.
* If a custom calculation method is provied, it is called before
* this method and the calculated value is passed as the first argument.
*/
interpret?: InterpretLandmark<Category>;
}
interface CephPoint extends CephLandmark {
type: 'point';
}
interface CephLine extends CephLandmark {
type: 'line';
components: CephPoint[];
}
interface CephDistance extends CephLandmark {
type: 'distance';
unit: LinearUnit;
components: [CephPoint, CephLine];
}
interface CephAngle extends CephLandmark {
type: 'angle';
unit: AngularUnit;
components: CephPoint[] | CephLine[] | CephAngle[];
}
interface CephAngularSum extends CephLandmark {
type: 'sum';
unit: AngularUnit ;
components: CephAngle[];
}
type AnalysisComponent = {
landmark: CephLandmark;
mean: number;
max: number;
min: number;
};
type CategorizedAnalysisResult<T extends Category> = {
category: T;
indication: Indication<T>;
severity?: Severity;
relevantComponents: Array<Pick<LandmarkInterpretation<T>, 'mean' | 'max' | 'min' | 'value'> & { symbol: string }>;
};
type IndexedAnalysisInterpretation = Partial<{
[C in Category]: CategorizedAnalysisResult<C>;
}>;
interface Analyses {
ceph_lateral: (
'downs' | 'ricketts_lateral' |
'common' | 'basic' | 'bjork' |
'tweed' | 'steiner' | 'basic' |
'soft_tissues_lateral'
);
ceph_pa: (
'ricketts_frontal'
);
photo_lateral: (
'soft_tissues_photo_lateral'
);
photo_frontal: (
'soft_tissues_photo_frontal' |
'frontal_face_proportions'
);
panoramic: (
'panoramic_analysis'
);
}
type ImageType = keyof Analyses;
type AnalysisId<T extends ImageType> = Analyses[T];
/**
* Describes a cephalometric analysis, composed of a list of
* landmarks and their respective mean values and an interpretation
* method.
*/
interface Analysis<T extends ImageType> {
id: AnalysisId<T>;
components: AnalysisComponent[];
/**
* Given a map of the evaluated values of this analysis components,
* this function should return an array of interpreted results grouped
* by category.
*/
interpret: InterpretAnalysis<Category>;
}
type Rotation = {
type: 'rotation';
value: number;
axis: 'x' | 'y' | 'z';
};
type Scale = {
type: 'scale';
value: number;
};
type FlipX = Rotation & {
value: 180;
axis: 'y';
};
type FlipY = Rotation & {
value: 180;
axis: 'x';
};
type Transformation = Rotation | Scale;
/**
* Describes a geometrical point in a 2D-plane
*/
interface GeoPoint {
x: number;
y: number;
}
/**
* Describes a geometrical angle in a 2D-plane
*/
interface GeoAngle {
vectors: [GeoVector, GeoVector];
}
/**
* Describes a geometrical line in a 2D-plane
*/
interface GeoVector {
x1: number;
y1: number;
x2: number;
y2: number;
}
type SingleGeoObject = GeoPoint | GeoVector | GeoAngle;
type CompositeGeoObject = SingleGeoObject[];
type GeoObject = SingleGeoObject | CompositeGeoObject;
type StepState = 'done' | 'current' | 'pending' | 'skipped';
type GenericError = { message: string, code?: number };
type WorkerDetails = {
id: string;
type: 'image_worker' | 'tracing_worker';
isBusy: boolean;
error: null | GenericError;
};
type ContentRect = {
top: number;
left: number;
width: number;
height: number;
};
type TracingMode = 'auto' | 'manual' | 'assisted';
type WorkspaceMode = 'tracing' | 'superimposition';
type SuperimpositionMode = 'auto' | 'manual';
type WorkspaceSettings = {
isImporting: boolean;
isExporting: boolean;
importError: GenericError | null;
exportError: GenericError | null;
mode: WorkspaceMode;
contectRect: ContentRect | null;
images: string[];
tracing: {
imageId: string | null;
},
superimposition: {
mode: SuperimpositionMode;
};
};
type TreatmentStage = {
/**
* Display name for this treatment stage
*/
name: string;
/** An ordered list of images assigned to this treatment stage */
imageIds: string[];
};
type ExportFileFormat = 'wceph_v1' | 'jpeg';
type ExportFileOptions = any; // @TODO
interface UndoableState<T> {
past: T[];
present: T;
future: T[];
}
type FetchStatus = {
isLoading: true;
error: null;
} | {
isLoading: false;
error: GenericError;
} | {
isLoading: false;
error: null;
};
type Locale = Record<string, string>;
interface StoreState {
'app.init.isInitialized': boolean;
'app.status.isUpdating': boolean;
'app.status.isInstalling': boolean;
'app.status.isInstalled': boolean;
'app.status.isUpdated': boolean;
'app.persistence.isSupported': boolean;
'app.persistence.isSaving': boolean;
'app.persistence.isLoading': boolean;
'app.persistence.isUpgrading': boolean;
'app.persistence.isReady': boolean;
'app.persistence.save.error': GenericError | null;
'app.persistence.load.error': GenericError | null;
/** Languages available for the app */
'app.locale.supportedLocales': string[];
'app.locale.fetchStatus': {
[locale: string]: FetchStatus;
};
'app.locale.data': {
[locale: string]: Locale | undefined;
};
/** Default languages provided by the browser (navigator.language or navigator.languages) */
'env.locale.requestedLocales': string[];
'env.userAgent': string | null;
'env.connection.isOffline': boolean;
'env.compat.check.ignored': {
[userAgent: string]: boolean;
};
'env.compat.check.status': {
[userAgent: string]: {
isChecking: boolean;
error: GenericError | null;
};
};
'env.compat.check.results': {
[userAgent: string]: {
missingFeatures: {
[featureId: string]: MissingBrowserFeature;
};
};
};
/** Language preference explicitly set by user */
'user.preferences.preferredLocale': string | null;
'workspace.canvas.mouse.position': null | {
x: number;
y: number;
};
'workspace.canvas.tools.activeToolId': ToolId;
'workspace.canvas.scale.value': number;
'workspace.canvas.scale.offset': null | {
top: number;
left: number;
};
'workspace.canvas.highlightedStep': string | null;
/** Data indexed by image ID */
'images.props': {
[imageId: string]: ImageBlobData & CephImageData<ImageType>;
};
'images.tracing': {
[imageId: string]: CephImageTracingData;
};
'images.status': {
[imageId: string]: {
isLoading: true;
error: null;
} | {
isLoading: false;
error: GenericError;
} | {
isLoading: false;
error: null;
};
};
'analyses.status': Partial<{
[T in ImageType]: {
[analysisId: string]: FetchStatus;
};
}>;
'analyses.lastUsedId': {
[T in ImageType]: AnalysisId<T>;
};
'analyses.summary.isShown': boolean;
'workspaces.order': string[];
'workspaces.activeWorkspaceId': string | null;
'workspaces.settings': {
[id: string]: WorkspaceSettings;
};
'treatment.stages.order': string[];
/** User-specified order of treatment stages */
'treatment.stages.data': {
[stageId: string]: TreatmentStage;
};
'workers': {
[workerId: string]: WorkerDetails;
};
}
type ToolId = (
'ADD_POINT' |
'ERASER' |
'ZOOM_WITH_WHEEL' |
'SELECT' |
'ZOOM_WITH_CLICK'
);
type ImageBlobData = {
name: string | null;
data: string;
width: number;
height: number;
};
type CephImageData<T extends ImageType> = {
/** A null value indicates that the image type is not set or is unknown */
type: T | null;
scaleFactor: number | null;
flipX: boolean;
flipY: boolean;
/** A value between 0 and 1, defaults to 0.5 */
brightness: number;
/** A value between 0 and 1, defaults to 0.5 */
contrast: number;
/** Wether the image colors should be inverted */
invertColors: boolean;
analysis: {
/** Last used analysis for this image */
activeId: AnalysisId<T> | null;
};
};
type CephImageTracingData = {
mode: 'auto' | 'assisted' | 'manual';
manualLandmarks: {
[symbol: string]: GeoObject;
};
/** Steps to skip in non-manual tracing modes */
skippedSteps: {
[symbol: string]: true;
};
};
type ProgressStatus = Partial<{
/**
* A null value indicates unknown progress,
* undefined indicates no change in value
*/
progress: number | null;
complete: boolean;
error: GenericError;
}>;
interface Events {
CONNECTION_STATUS_CHANGED: Partial<{
isOffline: boolean;
isSlow: boolean;
isMetered: boolean;
}>;
APP_INSTALL_STATUS_CHANGED: ProgressStatus;
APP_UPDATE_STATUS_CHANGED: ProgressStatus;
WORKER_CREATED: WorkerDetails;
WORKER_TERMINATED: string;
WORKER_STATUS_CHANGED: Pick<WorkerDetails, 'id'> & Pick<WorkerDetails, 'isBusy' | 'error'>;
APP_IS_READY: void;
LOAD_IMAGE_FROM_URL_REQUESTED: {
url: string;
workspaceId: string;
};
EXPORT_FILE_REQUESTED: {
format: ExportFileFormat;
options?: ExportFileOptions;
};
EXPORT_FILE_SUCCEEDED: void;
EXPORT_FILE_FAILED: GenericError;
EXPORT_PROGRESS_CHANGED: {
value: number;
data?: any; // @TODO;
};
IMPORT_FILE_REQUESTED: {
file: File;
workspaceId: string;
};
IMPORT_FILE_SUCCEEDED: {
workspaceId: string;
};
IMPORT_FILE_FAILED: {
workspaceId: string;
error: GenericError;
};
IMPORT_PROGRESS_CHANGED: {
value: number;
data?: any; // @TODO;
};
LOAD_IMAGE_STARTED: {
imageId: string;
workspaceId: string;
};
LOAD_IMAGE_SUCCEEDED: (
{ id: string } & ImageBlobData
);
LOAD_IMAGE_FAILED: {
id: string;
error: GenericError;
};
CLOSE_IMAGE_REQUESTED: {
imageId: string;
workspaceId: string;
};
CANVAS_RESIZED: {
workspaceId: string;
contentRect: {
top: number;
left: number;
width: number;
height: number;
};
};
SET_WORKSPACE_MODE_REQUESTED: {
workspaceId: string;
mode: WorkspaceMode;
};
SET_ACTIVE_WORKSPACE: {
id: string;
};
ADD_NEW_WORKSPACE: {
id: string;
settings?: Partial<WorkspaceSettings>;
};
REMOVE_WORKSPACE: {
id: string;
removeUnreferencedImages: boolean;
};
SET_ACTIVE_IMAGE_ID: {
imageId: string;
workspaceId: string;
};
SET_IMAGE_PROPS: (
{ id: string } &
Partial<CephImageData<ImageType>> &
Partial<{
tracing: CephImageTracingData;
}>
);
TRACE_IMAGE_REQUESTED: {
imageId: string;
workspaceId: string;
};
ADD_MANUAL_LANDMARK_REQUESTED: {
imageId: string;
symbol: string;
value: GeoObject;
};
ADD_UNKOWN_MANUAL_LANDMARK_REQUESTED: {
imageId: string;
value: GeoObject;
};
REMOVE_MANUAL_LANDMARK_REQUESTED: {
imageId: string;
symbol: string;
};
FLIP_IMAGE_X_REQUESTED: {
imageId: string;
};
FLIP_IMAGE_Y_REQUESTED: {
imageId: string;
};
SET_IMAGE_BRIGHTNESS_REQUESTED: {
imageId: string;
/** A value between 0 and 1 */
value: number;
};
SET_IMAGE_CONTRAST_REQUESTED: {
imageId: string;
/** A value between 0 and 1 */
value: number;
};
INVERT_IMAGE_REQUESTED: {
imageId: string;
};
RESET_WORKSPACE_REQUESTED: void;
IGNORE_WORKSPACE_ERROR_REQUESTED: void;
MOUSE_POSITION_CHANGED: {
x: number;
y: number;
};
REDO_REQUESTED: void;
UNDO_REQUESTED: void;
SET_SCALE_REQUESTED: {
imageId: string;
scale: number;
};
SET_SCALE_OFFSET_REQUESTED: {
imageId: string;
top: number;
left: number;
};
HIGHLIGHT_STEP_ON_CANVAS_REQUESTED: {
symbol: string;
};
UNHIGHLIGHT_STEP_ON_CANVAS_REQUESTED: void;
SET_ACTIVE_TOOL_REQUESTED: ToolId;
SET_ANALYSIS_REQUESTED: {
imageType: ImageType;
analysisId: AnalysisId<ImageType>;
};
FETCH_ANALYSIS_SUCCEEDED: {
imageType: ImageType;
analysisId: AnalysisId<ImageType>;
};
FETCH_ANALYSIS_FAILED: {
imageType: ImageType;
analysisId: AnalysisId<ImageType>;
error: GenericError;
};
SET_TRACING_MODE_REQUESTED: {
imageId: string;
mode: TracingMode;
};
SKIP_MANUAL_STEP_REQUESTED: {
imageId: string;
step: string;
};
UNSKIP_MANUAL_STEP_REQUESTED: {
imageId: string;
step: string;
};
SET_SCALE_FACTOR_REQUESTED: {
imageId: string;
value: number;
};
UNSET_SCALE_FACTOR_REQUESTED: {
imageId: string;
};
SUPERIMPOSE_IMAGES_REQUESTED: {
workspaceId: string;
order: string[];
};
SET_SUPERIMPOSITION_MODE_REQUESTED: {
workspaceId: string;
mode: SuperimpositionMode;
};
ADD_TREATMENT_STAGE: {
id: string;
data: TreatmentStage;
};
REMOVE_TREATMENT_STAGE: {
id: string;
};
UPDATE_TREATMENT_STAGE: {
id: string;
update: Partial<TreatmentStage>;
};
TOGGLE_ANALYSIS_RESULTS_REQUESTED: void;
BROWSER_COMPATIBLITY_CHECK_REQUESTED: {
userAgent: string;
};
BROWSER_COMPATIBLITY_CHECK_SUCCEEDED: {
userAgent: string;
};
BROWSER_COMPATIBLITY_CHECK_FAILED: {
userAgent: string;
error: GenericError;
};
IGNORE_BROWSER_COMPATIBLITY_REQUESTED: {
userAgent: string;
};
ENFORCE_BROWSER_COMPATIBLITY_REQUESTED: {
userAgent: string;
};
MISSING_BROWSER_FEATURE_DETECTED: {
userAgent: string;
feature: MissingBrowserFeature;
};
LOAD_PERSISTED_STATE_REQUESTED: void;
LOAD_PERSISTED_STATE_SUCCEEDED: Partial<StoreState>;
LOAD_PERSISTED_STATE_FAILED: GenericError;
PERSIST_STATE_UPGRADE_STARTED: void;
PERSIST_STATE_STARTED: void;
PERSIST_STATE_SUCCEEDED: void;
PERSIST_STATE_FAILED: GenericError;
CLEAR_PRESISTED_STATE_REQUESTED: void;
CLEAR_PRESISTED_STATE_SUCCEEDED: void;
CLEAR_PERSISTED_STATE_FAILED: GenericError;
SET_USER_PREFERRED_LOCALE: string;
UNSET_USER_PREFERRED_LOCALE: void;
ENV_LOCALES_CHANGED: string[];
FETCH_LOCALE_STARTED: string;
FETCH_LOCALE_SUCCEEDED: {
locale: string;
messages: Locale;
};
FETCH_LOCALE_FAILED: {
locale: string,
error: GenericError;
};
}
type GenericDispatch = (action: GenericAction) => any;
type ActionType = keyof Events;
type StoreKey = keyof StoreState;
type ActionCreator<T extends ActionType> = (payload: Events[T]) => Action<T>;
type GenericActionCreator = ActionCreator<ActionType>;
type GenericAction = {
type: ActionType;
payload?: any;
};
type Action<T extends ActionType> = {
type: T;
payload: Events[T];
};
type Reducer<S, A extends ActionType> = (state: S, action: Action<A>) => S;
type ReducerMap = {
[Key in StoreKey]: Reducer<StoreState[Key], ActionType>;
};
type ActionToReducerMap<Key extends StoreKey> = Partial<{
[A in ActionType]: Reducer<StoreState[Key], A>;
}>;
/* Tools */
/** An Editor Tool is just a collection of functions that consume state and dispatch actions.
* The functions are collected to simplify the canvas logic and make it easier to switch
* the behavior of mouse actions on the canvas.
*/
interface EditorTool {
/** Indicates whether the lens should be shown when this tool is active.
* `null` indicates no preference.
*/
shouldShowLens: boolean | null;
/**
* Triggered when mouse enters the canvas.
*/
onCanvasMouseEnter?(dispatch: GenericDispatch): void;
/**
* Triggered when mouse leaves the canvas.
*/
onCanvasMouseLeave?(dispatch: GenericDispatch): void;
/**
* Triggered when the left mouse button is clicked.
*/
onCanvasLeftClick?(dispatch: GenericDispatch, x: number, y: number): void;
/**
* Triggered when the right mouse button is clicked.
*/
onCanvasRightClick?(dispatch: GenericDispatch, x: number, y: number): void;
/**
* Triggered when the mouse scrolls over the canvas.
* Useful for implementing zoom functionality.
*/
onCanvasMouseWheel?(dispatch: GenericDispatch, x: number, y: number, delta: number): void;
/**
* Triggered when the mouse moves over the canvas.
* Useful for implementing lens functionality.
*/
onCanvasMouseMove?(dispatch: GenericDispatch, x: number, y: number): void;
/**
* Triggered when the mouse enters a landmark.
*/
onLandmarkMouseEnter?(dispatch: GenericDispatch, symbol: string): void;
/**
* Triggered when the mouse enters a landmark.
*/
onLandmarkMouseLeave?(dispatch: GenericDispatch, symbol: string): void;
/**
* Triggered when a landmark is clicked.
* Useful for manipulating previously added landmarks.
*/
onLandmarkClick?(dispatch: GenericDispatch, symbol: string, e: MouseEvent): void;
/**
* Called every time the mouse enters a landmark.
* Useful for implementing tool-specific cursors.
*/
getCursorForLandmark?(symbol: string): string | undefined;
getCursorForCanvas?(): string | undefined;
getPropsForLandmark?(symbol: string): { [id: string]: any } | undefined;
}
/** An EditorToolCreator is a function that is used to create editor tools.
* It recieves the store state as the first argument.
*/
type EditorToolCreator = (state: StoreState) => EditorTool;
type ValidationError = GenericError & {
type: number;
data?: any;
};
type ExportProgressCallback = (
value: number,
data?: any, // @TODO
) => void;
type ImportOptions = Partial<{
/** IDs to assign for imported images */
ids: string[];
loadTracingData: boolean;
loadWorkspaceSettings: boolean;
loadSuperimpositionState: boolean;
treatmentStagesToLoad: string[];
}> & {
workspaceId: string;
};
/**
* A file importer recieves the file to be imported along with any import options and
* returns an array of actions to be dispatched in order.
*/
type Importer = (file: File, options: ImportOptions) => Promise<GenericAction[]>;
type ExportOptions = Partial<{
imagesToSave: string[];
saveTracingData: boolean;
saveWorkspaceSettings: boolean;
saveSuperimpositionState: boolean;
/* Whether to include the reference image */
includeRasterImage: boolean;
/* Tracing objects to export per image */
objectsToExport: Record<string, Record<string, boolean>>;
treatmentStagesToSave: string[];
thumbs: Partial<{
'64x64': boolean;
'128x128': boolean;
'256x256': boolean;
'512x512': boolean;
}>;
}>;
type ValidateOptions = {
};
/**
* A file exporter recieves the application state along with any export options and
* returns an File blob to be saved.
*/
type Exporter = (
state: StoreState,
options: ExportOptions,
progressCallback?: ExportProgressCallback,
) => Promise<File>;
/**
* A validator recieves the file to validate and returns zero, one or more validation errors.
* A return value with a length of 0 means that the files is valid.
*/
type Validator = (
fileToValidate: File,
options: ValidateOptions,
) => Promise<ValidationError[]>;
/**
* A file saver allows a persistent file to be updated on disk or remotely by
* listening to state changes and doing some work asynchronously.
* It allows the concept of opening and closing files instead of requiring the user
* to manually export a file after every change.
*/
type Saver = (state: StoreState) => IterableIterator<GenericAction>;
type KeyboardCommand = (
'ADD_NEW_WORKSPACE'
);
type KeyboardActionCreators = Record<KeyboardCommand, () => GenericAction>;
type KeyboardHandlers = Record<KeyboardCommand, (event: KeyboardEvent) => any>;
type KeyboardMap = Record<KeyboardCommand, string>;
/* Browser compatiblity checking */
type BrowserId = 'Chrome' | 'Firefox' | 'Opera' | 'Microsoft Edge' | 'Safari';
type OsId = 'mac' | 'windows' | 'linux' | 'chromeos' | 'ios' | 'android';
interface BrowserFeature {
id: string;
available: boolean;
optional: boolean;
}
type MissingBrowserFeature = BrowserFeature & { available: false };
interface Browser {
id: BrowserId | string;
/**
* The current version of the browser
*/
version: string;
/**
* URL to the download page of the browser
*/
downloadUrl: string;
}
declare module 'lodash/zipObject' {
const zipObject: <K extends string, V>(keys: K[], values: V[]) => Record<K, V>;
export = zipObject;
}
declare module 'lodash/pick' {
const pick: <T extends Record<string, any>, K extends keyof T>(obj: T, ...args: K[]) => Pick<T, K>;
export = pick;
}
declare module 'lodash/countBy' {
const countBy: <T>(array: T[], el: T) => Record<'true' | 'false', number>;
export = countBy;
}