Contents
Basic Usage
The module is based on the ECMAScript standard, so your project must use ES modules. Ensure that "type": "module" is set in your package.json or deno.json. CommonJS is not supported.
Import the module at the beginning of your main JavaScript file using import "swing-ui";. The module should be imported only once per project.
All classes, functions, and ui object variable are exposed globally and can be accessed throughout the project (except within worker threads).
The module is intended to run only in the main thread and must not be imported in a worker thread.
Global function alert(), confirm(), and prompt() are made to function just like in a web browser, but with additional parameters. We also added dialog() and error() for creating custom dialog windows and alerting error messages more conveniently. Function for file chooser, color chooser, and font chooser are method of a Window class.
Global ui Object
The module exposes the ui object globally, allowing it to be accessed from anywhere in the project except for worker threads. The ui variable is an instance of the SwingUI class, which serves as the main entry point and provides a wide range of utility functions. These include UI configuration, handling global events, clipboard access, synchronous file system operations (reading and writing files and directories), a sleep function, default menu bar configuration, and more.
UIComponent Base Class
All UI component classes extend this class and inherit some methods and properties from it, therefore all UI component objects are also instances of UIComponent class.
The following code outputs “true”:
let txt = new TextField();
if(txt instanceof UIComponent) console.log("true");UIComponent class is not intended to be instantiated, but only extended by other UI components included in this API.
TypeScript Compatibility
The module has been tested with TypeScript projects in Bun and Deno v2 and works as expected. The module directory includes a /types directory containing type definitions.
If you need improved compatibility, please contact us with a clear description of your requirements, and we will do our best to support them.

