Skip to content

Commit ae8a5e4

Browse files
authored
Merge pull request #200 from SenteraLLC/org/listeners
org/listeners
2 parents 9ca27d6 + c7d0915 commit ae8a5e4

6 files changed

Lines changed: 739 additions & 405 deletions

File tree

eslint.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export default [
2323
},
2424
stylistic.configs.customize(
2525
{
26+
arrowParens: true,
2627
braceStyle: "1tbs",
2728
commaDangle: "always-multiline",
2829
indent: 4,

index.d.ts

Lines changed: 105 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export type ClassDefinition = {
6363
name: string;
6464
id: number;
6565
color: string;
66+
keybind?: string;
6667
};
6768

6869
export type SliderInfo = {
@@ -194,6 +195,7 @@ export class ULabel {
194195
valid_class_ids: number[];
195196
toolbox_order?: number[];
196197
filter_distance_overlay?: FilterDistanceOverlay;
198+
resize_observers: ResizeObserver[];
197199
/**
198200
* @link https://github.com/SenteraLLC/ulabel/blob/main/api_spec.md#ulabel-constructor
199201
*/
@@ -221,8 +223,15 @@ export class ULabel {
221223
public show_whole_image(): void;
222224
public swap_frame_image(new_src: string, frame?: number): string;
223225
public swap_anno_bg_color(new_bg_color: string): string;
226+
227+
// Subtasks
224228
public get_current_subtask_key(): string;
225229
public get_current_subtask(): ULabelSubtask;
230+
public readjust_subtask_opacities(): void;
231+
public set_subtask(st_key: string): void;
232+
public switch_to_next_subtask(): void;
233+
234+
// Annotations
226235
public get_annotations(subtask: ULabelSubtask): ULabelAnnotation[];
227236
public set_annotations(annotations: ULabelAnnotation[], subtask: ULabelSubtask);
228237
public set_saved(saved: boolean);
@@ -245,14 +254,108 @@ export class ULabel {
245254
dist_prop: number;
246255
},
247256
): void;
248-
public toggle_erase_mode(mouse_event: JQuery.TriggeredEvent): void;
249-
public toggle_brush_mode(mouse_event: JQuery.TriggeredEvent): void;
257+
258+
// Brush
259+
// TODO (joshua-dean): should these actually be optional?
260+
public toggle_erase_mode(mouse_event?: JQuery.TriggeredEvent): void;
261+
public toggle_brush_mode(mouse_event?: JQuery.TriggeredEvent): void;
250262
public toggle_delete_class_id_in_toolbox(): void;
251263
public change_brush_size(scale_factor: number): void;
264+
public recolor_brush_circle(): void;
265+
public destroy_brush_circle(): void;
266+
267+
// Listeners
252268
public remove_listeners(): void;
253269
static get_allowed_toolbox_item_enum(): AllowedToolboxItem;
254270
static process_classes(ulabel_obj: ULabel, arg1: string, subtask_obj: ULabelSubtask);
255271
static build_id_dialogs(ulabel_obj: ULabel);
272+
273+
// Annotation lifecycle
274+
// TODO (joshua-dean): type for redo_payload
275+
public begin_annotation(mouse_event: JQuery.TriggeredEvent, redo_payload?: object): void;
276+
public create_annotation(
277+
spatial_type: ULabelSpatialType,
278+
spatial_payload: ULabelSpatialPayload,
279+
unique_id?: string,
280+
): void;
281+
public create_nonspatial_annotation(
282+
redo_payload?: object,
283+
): void;
284+
public delete_annotation(
285+
annotation_id: string,
286+
redo_payload?: object,
287+
record_action?: boolean,
288+
): void;
289+
public cancel_annotation(redo_payload?: object): void;
290+
public get_active_class_id(): number;
291+
public get_active_class_id_idx(): number;
292+
public undo(is_internal_undo?: boolean): void;
293+
public redo(): void;
294+
295+
// Mouse event handlers
296+
public handle_mouse_down(mouse_event: JQuery.TriggeredEvent): void;
297+
public handle_mouse_move(mouse_event: JQuery.TriggeredEvent): void;
298+
public handle_mouse_up(mouse_event: JQuery.TriggeredEvent): void;
299+
public handle_aux_click(mouse_event: JQuery.TriggeredEvent): void;
300+
public handle_wheel(wheel_event: WheelEvent): void;
301+
public start_drag(
302+
drag_key: string,
303+
release_button: string,
304+
mouse_event: JQuery.TriggeredEvent,
305+
): void;
306+
public end_drag(mouse_event: JQuery.TriggeredEvent): void;
307+
public drag_repan(mouse_event: JQuery.TriggeredEvent): void;
308+
public drag_rezoom(mouse_event: JQuery.TriggeredEvent): void;
309+
310+
// "Mouse event interpreters"
311+
public get_global_mouse_x(mouse_event: JQuery.TriggeredEvent): number;
312+
public get_global_mouse_y(mouse_event: JQuery.TriggeredEvent): number;
313+
314+
// Edit suggestions
315+
public suggest_edits(
316+
mouse_event?: JQuery.TriggeredEvent,
317+
nonspatial_id?: string,
318+
): void;
319+
public show_global_edit_suggestion(
320+
annid: string,
321+
offset?: {
322+
diffX: number;
323+
diffY: number;
324+
diffZ?: number;
325+
},
326+
nonspatial_id?: string,
327+
): void;
328+
public hide_global_edit_suggestion(): void;
329+
330+
// Drawing
331+
public rezoom(
332+
foc_x?: number,
333+
foc_y?: number,
334+
abs?: boolean,
335+
): void;
336+
public reposition_dialogs(): void;
337+
public handle_toolbox_overflow(): void;
338+
339+
// ID Dialog
340+
public set_id_dialog_payload_nopin(
341+
class_ind: number,
342+
dist_prop: number
343+
): void;
344+
public update_id_dialog_display(
345+
front?: boolean,
346+
): void;
347+
public handle_id_dialog_click(
348+
mouse_event: JQuery.TriggeredEvent,
349+
annotation_id?: string,
350+
new_class_idx?: number,
351+
): void;
352+
public show_id_dialog(
353+
gbx: number,
354+
gby: number,
355+
active_ann: string, // annotation id
356+
thumbnail?: boolean,
357+
nonspatial?: boolean,
358+
): void;
256359
}
257360

258361
declare global {

src/cookies.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
* ULabel cookie utilities.
3+
*/
4+
5+
export abstract class NightModeCookie {
6+
/**
7+
* The name of the cookie that stores the night mode preference.
8+
*/
9+
public static readonly COOKIE_NAME: string = "nightmode";
10+
11+
/**
12+
* Return whether the document has a night mode cookie.
13+
*/
14+
public static exists_in_document(): boolean {
15+
const cookie_components = document.cookie.split(";");
16+
const night_mode_comp = cookie_components.find(
17+
row => row.trim().startsWith(`${NightModeCookie.COOKIE_NAME}=true`),
18+
);
19+
return night_mode_comp !== undefined;
20+
}
21+
22+
/**
23+
* Set the night mode cookie.
24+
*/
25+
public static set_cookie(): void {
26+
const d = new Date();
27+
d.setTime(d.getTime() + (10000 * 24 * 60 * 60 * 1000));
28+
document.cookie = [
29+
NightModeCookie.COOKIE_NAME + "=true",
30+
"expires=" + d.toUTCString(),
31+
"path=/",
32+
].join(";");
33+
}
34+
35+
/**
36+
* Destroy the night mode cookie.
37+
*/
38+
public static destroy_cookie() {
39+
document.cookie = [
40+
NightModeCookie.COOKIE_NAME + "=true",
41+
"expires=Thu, 01 Jan 1970 00:00:00 UTC",
42+
"path=/",
43+
].join(";");
44+
}
45+
}

0 commit comments

Comments
 (0)