diff --git a/CHANGELOG.md b/CHANGELOG.md index 9835a102..66c837b9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to this project will be documented here. +## [0.30.0] - Oct 20th, 2026 +#### Changed +- `init()` now returns the `ulabel_init`; typed `Promise` + ## [0.29.1] - Oct 12th, 2026 #### Fixed - `set_annotations()` / `set_annotations_batch()` could paint a frame with no annotations on heavy images. The outgoing annotations now stay on screen until the new ones are drawn. diff --git a/api_spec.md b/api_spec.md index 7a8df0b6..06889884 100644 --- a/api_spec.md +++ b/api_spec.md @@ -35,6 +35,14 @@ Note that in order to begin the session, you must thereafter call ulabel.init(() => {/* behavior on ready */}) ``` +`init()` returns a `Promise` that: + +- Resolves when initialization finishes (after the callback) +- Resolves early without calling the callback if [`destroy()`](#destroy) + runs mid-init; check `ulabel.is_destroyed` after awaiting +- Rejects if initialization fails (e.g. the image fails to decode) +- Rejects if the callback fails + `ULabel` is the only name that `ulabel.js` will add to the global namespace. > ULabel is designed for **a single instance per page**. Toolbox handlers, id dialogs, and global keybinds bind to shared DOM ids and delegated selectors on `document`, so mounting more than one `ULabel` simultaneously is not supported. diff --git a/index.d.ts b/index.d.ts index 2b5aacac..34041fd9 100644 --- a/index.d.ts +++ b/index.d.ts @@ -507,7 +507,7 @@ export class ULabel { * @link https://github.com/SenteraLLC/ulabel/blob/main/api_spec.md#display-utility-functions */ public version(): string; - public init(callback: () => void): void; + public init(callback: () => void): Promise; public after_init(): void; public show_initial_crop(): void; public show_whole_image(): void; diff --git a/package-lock.json b/package-lock.json index ffddee06..d85d8aff 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "ulabel", - "version": "0.29.1", + "version": "0.30.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "ulabel", - "version": "0.29.1", + "version": "0.30.0", "license": "MIT", "devDependencies": { "@eslint/config-inspector": "^1.3.0", diff --git a/package.json b/package.json index f00a9169..1c5b46d4 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "ulabel", "description": "An image annotation tool.", - "version": "0.29.1", + "version": "0.30.0", "main": "dist/ulabel.min.js", "module": "dist/ulabel.min.js", "types": "dist/index.d.ts", diff --git a/src/index.js b/src/index.js index 9736d6e7..ea6b8bb2 100644 --- a/src/index.js +++ b/src/index.js @@ -844,8 +844,14 @@ export class ULabel { this._owned_container = null; } + /** + * Initialize the session, then call the user callback. + * + * @param {() => void} callback User-provided callback to run after initialization. + * @returns {Promise} Resolves when initialization finishes; rejects if it fails. + */ init(callback) { - ulabel_init(this, callback); + return ulabel_init(this, callback); } /** diff --git a/src/version.js b/src/version.js index 7b8493b2..e1e7a4da 100644 --- a/src/version.js +++ b/src/version.js @@ -1 +1 @@ -export const ULABEL_VERSION = "0.29.1"; +export const ULABEL_VERSION = "0.30.0";