Skip to content

Commit 92410ea

Browse files
Merge pull request #243 from SenteraLLC/fix/type-hints
fix/type-hints
2 parents 144a6e8 + 50f1f3e commit 92410ea

34 files changed

Lines changed: 1006 additions & 333 deletions

.github/tasks.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
## Tasks
2-
-
2+

.github/workflows/test.yml

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,40 @@ jobs:
5959
with:
6060
name: playwright-report
6161
path: playwright-report/
62-
retention-days: 30
62+
retention-days: 30
63+
64+
type-tests:
65+
runs-on: ubuntu-latest
66+
67+
steps:
68+
- uses: actions/checkout@v4
69+
70+
- name: Setup Node.js
71+
uses: actions/setup-node@v4
72+
with:
73+
node-version: '20'
74+
cache: 'npm'
75+
76+
- name: Install dependencies
77+
run: npm install
78+
79+
- name: Build project
80+
run: npm run build
81+
82+
- name: Pack tarball
83+
run: npm pack
84+
85+
- name: Install tarball in temp consumer project
86+
run: |
87+
mkdir /tmp/type-test-consumer
88+
cp tests/types/index.test-d.ts /tmp/type-test-consumer/
89+
cp tests/types/tsconfig.json /tmp/type-test-consumer/
90+
cd /tmp/type-test-consumer
91+
npm init -y
92+
npm install $GITHUB_WORKSPACE/ulabel-*.tgz
93+
npm install --save-dev typescript @types/jquery
94+
95+
- name: Verify type declarations compile
96+
run: |
97+
cd /tmp/type-test-consumer
98+
npx tsc --noEmit

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ All notable changes to this project will be documented here.
44

55
## [unreleased]
66

7+
## [0.23.4] - May 5th, 2026
8+
- Fix type declarations for npm consumers
9+
- Add `"files"` field to `package.json` to explicitly control published package contents.
10+
- Add CI type-test job that validates type declarations against a packed tarball.
11+
712
## [0.23.3] - Mar 18th, 2026
813
- Add `get_keypoint_slider_value()` public API method to get the current keypoint slider value (0-1).
914
- Add `get_distance_filter_value()` public API method to get the current distance filter slider values.

index.d.ts

Lines changed: 53 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { FilterDistanceOverlay } from "./src/overlays";
44
import { ULabelSubtask } from "./src/subtask";
55
import { Toolbox, AnnotationResizeItem } from "./src/toolbox";
66

7+
export { ULabelAnnotation, AllowedToolboxItem, Configuration, FilterDistanceOverlay, ULabelSubtask, Toolbox, AnnotationResizeItem };
8+
79
export type DistanceFromPolyline = {
810
distance: number;
911
polyline_id?: string;
@@ -15,7 +17,7 @@ export type DistanceFromPolyline = {
1517
*/
1618
export type DistanceFromPolylineClasses = {
1719
closest_row: DistanceFromPolyline;
18-
[key: number]: DistanceFromPolyline;
20+
[key: string]: DistanceFromPolyline;
1921
};
2022

2123
export type AbstractPoint = {
@@ -63,7 +65,7 @@ export type ClassDefinition = {
6365
name: string;
6466
id: number;
6567
color: string;
66-
keybind?: string;
68+
keybind: string | null;
6769
};
6870

6971
export type SliderInfo = {
@@ -133,7 +135,7 @@ export type ULabelAnnotations = { [key: string]: ULabelAnnotation[] };
133135

134136
export type ULabelSubmitData = {
135137
annotations: ULabelAnnotations;
136-
task_meta: object;
138+
task_meta: object | null;
137139
};
138140
export type ULabelSubmitHandler = (submitData: ULabelSubmitData) => void;
139141

@@ -239,6 +241,23 @@ export type ULabelActionCandidate = {
239241

240242
export type ULabelSubtasks = { [key: string]: ULabelSubtask };
241243

244+
export type ULabelConstructorArgs = {
245+
container_id: string;
246+
image_data: string | string[];
247+
username: string;
248+
submit_buttons: ULabelSubmitButton[];
249+
subtasks: ULabelSubtasks;
250+
task_meta?: object;
251+
annotation_meta?: object;
252+
px_per_px?: number;
253+
initial_crop?: InitialCrop;
254+
initial_line_size?: number;
255+
instructions_url?: string;
256+
toolbox_order?: AllowedToolboxItem[];
257+
/** @deprecated Use top-level properties instead. */
258+
config_data?: object;
259+
};
260+
242261
export class ULabel {
243262
subtasks: ULabelSubtasks;
244263
state: {
@@ -256,6 +275,9 @@ export class ULabel {
256275
anno_scaling_mode: AnnoScalingMode;
257276
// Keybind editing state
258277
is_editing_keybind: boolean;
278+
// Original keybind storage
279+
original_config_keybinds?: { [config_key: string]: string };
280+
original_class_keybinds?: { [class_id: number]: string | null };
259281
// Render state
260282
// TODO (joshua-dean): this is never assigned, is it used?
261283
demo_canvas_context: CanvasRenderingContext2D;
@@ -272,9 +294,13 @@ export class ULabel {
272294
begining_time: number;
273295
is_init: boolean;
274296
resize_observers: ResizeObserver[];
297+
275298
/**
276299
* @link https://github.com/SenteraLLC/ulabel/blob/main/api_spec.md#ulabel-constructor
277300
*/
301+
constructor(kwargs: ULabelConstructorArgs);
302+
303+
/** @deprecated Pass a single kwargs object instead of positional arguments. */
278304
constructor(
279305
container_id: string,
280306
image_data: string | string[],
@@ -294,6 +320,7 @@ export class ULabel {
294320
/**
295321
* @link https://github.com/SenteraLLC/ulabel/blob/main/api_spec.md#display-utility-functions
296322
*/
323+
public version(): string;
297324
public init(callback: () => void): void;
298325
public after_init(): void;
299326
public show_initial_crop(): void;
@@ -309,22 +336,22 @@ export class ULabel {
309336
public switch_to_next_subtask(): void;
310337

311338
// Annotations
312-
public get_annotations(subtask: ULabelSubtask): ULabelAnnotation[];
313-
public set_annotations(annotations: ULabelAnnotation[], subtask: ULabelSubtask);
314-
public set_saved(saved: boolean);
339+
public get_annotations(subtask: string): ULabelAnnotation[];
340+
public set_annotations(annotations: ULabelAnnotation[], subtask: string): void;
341+
public set_saved(saved: boolean): void;
315342
public draw_annotation_from_id(id: string, offset?: Offset, subtask?: string): void;
316343
public redraw_annotation(annotation_id: string, subtask?: string, offset?: Offset): void;
317344
public redraw_all_annotations(
318-
subtask?: string, // TODO (joshua-dean): THIS IS SUBTASK KEY, NAME PROPERLY
319-
offset?: number,
345+
subtask?: string,
346+
offset?: number | null,
320347
spatial_only?: boolean,
321-
);
322-
public redraw_multiple_spatial_annotations(annotation_ids: string[], subtask?: string, offset?: Offset);
348+
): void;
349+
public redraw_multiple_spatial_annotations(annotation_ids: string[], subtask?: string, offset?: Offset): void;
323350
public clear_nonspatial_annotation(annotation_id: string): void;
324351
public show_annotation_mode(
325-
target_jq?: JQuery<HTMLElement>, // TODO (joshua-dean): validate this type
326-
);
327-
public update_frame(delta?: number, new_frame?: number): void;
352+
target_jq?: JQuery<HTMLElement> | null, // TODO (joshua-dean): validate this type
353+
): void;
354+
public update_frame(delta?: number | null, new_frame?: number | null): void;
328355
public rebuild_containing_box(actid: string, ignore_final?: boolean, subtask?: string): void;
329356
public update_filter_distance_during_polyline_move(
330357
annotation_id: string,
@@ -341,7 +368,7 @@ export class ULabel {
341368
public get_keypoint_slider_value(): number | null;
342369
public get_distance_filter_value(): DistanceFromPolylineClasses | null;
343370
public fly_to_next_annotation(increment: number, max_zoom?: number): boolean;
344-
public fly_to_annotation_id(annotation_id: string, subtask_key?: string, max_zoom?: number): boolean;
371+
public fly_to_annotation_id(annotation_id: string, subtask_key?: string | null, max_zoom?: number): boolean;
345372
public fly_to_annotation(annotation: ULabelAnnotation, subtask_key?: string, max_zoom?: number): boolean;
346373

347374
// Brush
@@ -361,9 +388,10 @@ export class ULabel {
361388
public remove_listeners(): void;
362389

363390
// Static functions
391+
static version(): string;
364392
static get_time(): string;
365-
static get_allowed_toolbox_item_enum(): AllowedToolboxItem;
366-
static get_resize_toolbox_item(): AnnotationResizeItem;
393+
static get_allowed_toolbox_item_enum(): typeof AllowedToolboxItem;
394+
static get_resize_toolbox_item(): typeof AnnotationResizeItem;
367395
static process_classes(ulabel_obj: ULabel, arg1: string, subtask_obj: ULabelSubtask): void;
368396
static build_id_dialogs(ulabel_obj: ULabel): void;
369397

@@ -375,8 +403,8 @@ export class ULabel {
375403

376404
// Annotation lifecycle
377405
// TODO (joshua-dean): type for redo_payload
378-
public begin_annotation(mouse_event: JQuery.TriggeredEvent, annotation_id?: string, redo_payload?: object): void;
379-
public continue_annotation(mouse_event: JQuery.TriggeredEvent, is_click?: boolean, annotation_id?: string, redo_payload?: object): void;
406+
public begin_annotation(mouse_event: JQuery.TriggeredEvent | null | undefined, annotation_id?: string | null, redo_payload?: object | null): void;
407+
public continue_annotation(mouse_event: JQuery.TriggeredEvent | null | undefined, is_click?: boolean, annotation_id?: string | null, redo_payload?: object | null): void;
380408
public delete_annotation(
381409
annotation_id: string,
382410
redoing?: boolean,
@@ -468,14 +496,14 @@ export class ULabel {
468496

469497
// Edit suggestions
470498
public suggest_edits(
471-
mouse_event?: JQuery.TriggeredEvent,
472-
nonspatial_id?: string,
499+
mouse_event?: JQuery.TriggeredEvent | null,
500+
nonspatial_id?: string | null,
473501
force_refresh?: boolean,
474502
): void;
475503
public show_global_edit_suggestion(
476504
annid: string,
477-
offset?: Offset,
478-
nonspatial_id?: string,
505+
offset?: Offset | null,
506+
nonspatial_id?: string | null,
479507
): void;
480508
public hide_global_edit_suggestion(): void;
481509
public hide_edit_suggestion(): void;
@@ -485,7 +513,7 @@ export class ULabel {
485513
annid: string,
486514
access_str: string,
487515
as_though_pre_splice: boolean,
488-
);
516+
): unknown;
489517

490518
// Drawing
491519
public rezoom(
@@ -537,3 +565,5 @@ declare global {
537565
replaceLowerConcat(before: string, after: string, concat_string?: string): string;
538566
}
539567
}
568+
569+
export default ULabel;

package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
{
22
"name": "ulabel",
33
"description": "An image annotation tool.",
4-
"version": "0.23.3",
4+
"version": "0.23.4",
55
"main": "dist/ulabel.min.js",
66
"module": "dist/ulabel.min.js",
77
"types": "index.d.ts",
8+
"files": [
9+
"dist/",
10+
"src/",
11+
"index.d.ts"
12+
],
813
"exports": {
914
".": {
1015
"types": "./index.d.ts",
@@ -34,7 +39,7 @@
3439
"build-dev-and-demo": "npm run build-dev && npm run demo",
3540
"build-and-test": "npm run build && npm run test:both",
3641
"prepare": "husky",
37-
"lint": "eslint . --no-fix"
42+
"lint": "tsc --noEmit && eslint . --no-fix"
3843
},
3944
"lint-staged": {
4045
"**/*.{js,mjs,cjs,ts}": "eslint --fix"

0 commit comments

Comments
 (0)