tairitsu-web 0.5.21

Tairitsu Web Framework - Modular WebAssembly-first framework with SSR, CSR, SSG support
/// Handwritten framework interfaces for tairitsu-browser:full package.
///
/// AUTO-GENERATED by: scripts/generate_browser_wit.py
/// DO NOT EDIT MANUALLY — changes will be overwritten.
///
/// Source: wit/handwritten/*.wit
/// Regenerate with: just wit-gen

interface event-callbacks {
    type listener-id = u64;
    type event-handle = u64;

    record mouse-event-data {
        client-x: f64,
        client-y: f64,
        offset-x: f64,
        offset-y: f64,
        button: u8,
        buttons: u8,
        ctrl-key: bool,
        shift-key: bool,
        alt-key: bool,
        meta-key: bool,
    }

    record keyboard-event-data {
        key: string,
        code: string,
        key-code: u32,
        ctrl-key: bool,
        shift-key: bool,
        alt-key: bool,
        meta-key: bool,
        repeat: bool,
    }

    record focus-event-data {
        related-target: option<u64>,
    }

    record input-event-data {
        data: option<string>,
        input-type: string,
    }

    on-mouse-event: func(listener-id: listener-id, event: event-handle, data: mouse-event-data);
    on-keyboard-event: func(listener-id: listener-id, event: event-handle, data: keyboard-event-data);
    on-focus-event: func(listener-id: listener-id, event: event-handle, data: focus-event-data);
    on-input-event: func(listener-id: listener-id, event: event-handle, data: input-event-data);
    on-generic-event: func(listener-id: listener-id, event: event-handle, event-type: string);
}

interface timer-callbacks {
    on-timeout: func(callback-id: u64);
    on-interval: func(callback-id: u64);
}

interface animation-callbacks {
    on-frame: func(callback-id: u64, timestamp: f64);
}

interface resize-observer-callbacks {
    use types.{dom-rect};

    record resize-entry {
        target: u64,
        content-rect: dom-rect,
    }

    on-resize: func(callback-id: u64, entries: list<resize-entry>);
}

interface mutation-observer-callbacks {
    record mutation-entry {
        mutation-type: string,
        target: u64,
        added-nodes: option<u64>,
        removed-nodes: option<u64>,
        previous-sibling: option<u64>,
        next-sibling: option<u64>,
        attribute-name: option<string>,
        attribute-namespace: option<string>,
        old-value: option<string>,
    }

    on-mutate: func(callback-id: u64, entries: list<mutation-entry>);
}

interface media-query-list-callbacks {
    on-change: func(callback-id: u64, matches: bool);
}

interface scroll-callbacks {
    on-scroll-event: func(callback-id: u64, scroll-x: f64, scroll-y: f64);
}

interface window-resize-callbacks {
    on-window-resize: func(callback-id: u64, width: s32, height: s32);
}

interface video-frame-callbacks {
    on-video-frame: func(callback-id: u64, event: string);
}

interface promise-callbacks {
    on-promise-resolved: func(promise-id: u64, value: string);
    on-promise-rejected: func(promise-id: u64, error: string);
}

interface geolocation-callbacks {
    record geo-position {
        latitude: f64,
        longitude: f64,
        altitude: option<f64>,
        accuracy: f64,
        altitude-accuracy: option<f64>,
        heading: option<f64>,
        speed: option<f64>,
    }

    record geo-position-error {
        code: u8,
        message: string,
    }

    on-position-success: func(callback-id: u64, position: geo-position);
    on-position-error: func(callback-id: u64, error: geo-position-error);
}

interface idb-callbacks {
    on-idb-request-success: func(callback-id: u64, %result: option<string>);
    on-idb-request-error: func(callback-id: u64, error: string);
}

interface file-reader-callbacks {
    on-file-reader-load: func(callback-id: u64, %result: string);
    on-file-reader-error: func(callback-id: u64, error: string);
}

interface web-socket-callbacks {
    on-web-socket-open: func(callback-id: u64);
    on-web-socket-message: func(callback-id: u64, data: string);
    on-web-socket-close: func(callback-id: u64, code: u16, reason: string);
    on-web-socket-error: func(callback-id: u64);
}

interface lifecycle {
    start: func() -> result<_, string>;
}

interface console {
    log: func(message: string);
    warn: func(message: string);
    error: func(message: string);
}

interface event-target {
    add-event-listener: func(target: u64, event-type: string, use-capture: bool) -> result<u64, string>;
    remove-event-listener: func(target: u64, listener-id: u64) -> result<_, string>;
    prevent-default: func(event: u64);
    stop-propagation: func(event: u64);
}

interface platform-helpers {
    use component-types.{content-editable-state};
    use types.{dom-rect};

    // -- Constructors skipped by auto-generator --

    create-resize-observer: func(callback-id: u64) -> u64;
    create-mutation-observer: func(callback-id: u64) -> u64;
    create-audio-context: func() -> u64;

    // -- Global scope operations (need global handle, not readily available) --

    set-timeout: func(callback-id: u64, ms: s32) -> s32;
    clear-timeout: func(id: s32);
    set-interval: func(callback-id: u64, ms: s32) -> s32;
    clear-interval: func(id: s32);
    request-animation-frame: func(callback-id: u64) -> u32;
    cancel-animation-frame: func(id: u32);

    // -- Signature mismatch (auto-gen takes options handle, not simple params) --

    scroll-to: func(top: f64, behavior: string);

    // -- Promise polling (async/await bridge) --

    /// Create a promise from navigator.clipboard.writeText().
    /// Returns a promise-id that can be polled.
    clipboard-write-text-promise: func(text: string) -> u64;

    /// Create a promise from navigator.clipboard.readText().
    /// Returns a promise-id that can be polled.
    clipboard-read-text-promise: func() -> u64;

    /// Create a promise from fetch().
    /// Returns a promise-id that can be polled.
    fetch-promise: func(url: string, options: option<string>) -> u64;

    // -- Geolocation (callback-based, no promise needed) --

    get-geolocation-handle: func() -> u64;
    get-current-position: func(geo-handle: u64, success-callback-id: u64, error-callback-id: u64, enable-high-accuracy: bool, timeout: u32, maximum-age: u32);

    // -- Clipboard (needs clipboard handle + async navigation) --

    copy-to-clipboard: func(text: string) -> bool;
    read-clipboard: func() -> option<string>;

    // -- Content editable (bool→string conversion needed) --

    set-content-editable: func(element: u64, editable: bool);

    // -- DOM queries (auto-gen query_selector_all returns NodeList handle, not list) --

    get-element-by-id: func(id: string) -> option<u64>;
    query-selector: func(selector: string) -> option<u64>;
    query-selector-all: func(selector: string) -> list<u64>;

    on-scroll: func(callback-id: u64);
    on-resize-callback: func(callback-id: u64);

    // -- Custom convenience helpers (not W3C APIs) --

    get-scroll-top-from-point: func(x: s32, y: s32) -> f64;
    get-scroll-top-by-selector: func(selector: string) -> f64;
    get-element-rect-by-id: func(id: string) -> option<dom-rect>;
    get-bounding-rect-by-class: func(class-name: string, element: u64) -> option<dom-rect>;
    prefers-dark-mode: func() -> bool;

    // -- Rich text editing (custom composite type) --

    get-contenteditable-state: func(element: u64) -> option<content-editable-state>;
    get-selection-start: func(element: u64) -> option<u32>;
    get-selection-end: func(element: u64) -> option<u32>;

    // -- Audio convenience (auto-gen requires pre-allocated array) --

    analyser-get-frequency-data: func(analyser: u64) -> list<f32>;
    analyser-get-time-domain-data: func(analyser: u64) -> list<f32>;

    // -- Custom helpers (not W3C APIs) --

    draw-qrcode-on-canvas-by-id: func(canvas-id: string, matrix: list<list<bool>>, modules: u64, color: string, background: string) -> bool;

    // -- FileReader (sync convenience wrappers) --

    /// Read a blob/file as text synchronously (returns result directly).
    file-reader-sync-read-as-text: func(blob: u64, encoding: option<string>) -> result<string, string>;

    /// Read a blob/file as ArrayBuffer synchronously (returns bytes directly).
    file-reader-sync-read-as-array-buffer: func(blob: u64) -> result<list<u8>, string>;

    // -- FileReader async (callback-based) --

    /// Read a blob/file as text asynchronously.
    file-reader-read-as-text: func(blob: u64, encoding: option<string>, callback-id: u64);

    /// Read a blob/file as ArrayBuffer asynchronously.
    file-reader-read-as-array-buffer: func(blob: u64, callback-id: u64);

    // -- WebSocket (constructor not in auto-generated WIT) --

    /// Create a new WebSocket connection to the given URL.
    /// Returns a web-socket-handle (u64).
    /// Events are delivered via the web-socket-callbacks export interface.
    connect-web-socket: func(url: string) -> u64;

    // -- IndexedDB convenience (callback-based) --

    /// Open an IndexedDB database.
    idb-open: func(name: string, version: option<u64>, callback-id: u64) -> u64;

    /// Put a value into an object store.
    idb-put: func(db: u64, store-name: string, value: string, key: option<string>, callback-id: u64);

    /// Get a value from an object store.
    idb-get: func(db: u64, store-name: string, key: string, callback-id: u64);

    /// Delete a value from an object store.
    idb-delete: func(db: u64, store-name: string, key: string, callback-id: u64);

    /// Get all values from an object store.
    idb-get-all: func(db: u64, store-name: string, callback-id: u64);

    /// Delete an entire object store.
    idb-clear: func(db: u64, store-name: string, callback-id: u64);
}

interface component-types {
    record content-editable-state {
        editable: bool,
        focused: bool,
    }
}