export type NativeSdkJson = | null | boolean | number | string | NativeSdkJson[] | { [key: string]: NativeSdkJson }; export type NativeSdkErrorCode = | "invalid_request" | "unknown_command" | "permission_denied" | "handler_failed" | "payload_too_large" | "internal_error" | string; export interface NativeSdkInvokeError extends Error { code: NativeSdkErrorCode; } export interface NativeSdkWindowInfo { id: number; label: string; title: string; open: boolean; focused: boolean; x: number; y: number; width: number; height: number; scale: number; } export interface NativeSdkCreateWindowOptions { label?: string; title?: string; width?: number; height?: number; x?: number; y?: number; restoreState?: boolean; url?: string; } export interface NativeSdkRect { x?: number; y?: number; width: number; height: number; } export interface NativeSdkWebViewInfo { label: string; windowId: number; url: string; x: number; y: number; width: number; height: number; layer: number; zoom: number; transparent: boolean; bridge: boolean; focused: boolean; open: boolean; } export interface NativeSdkCreateWebViewOptions { /** Stable label for this child WebView. Defaults to "webview". Unique per native window. "main" is reserved for the startup WebView. */ label?: string; /** Parent native window id. Defaults to the caller and must match the window that calls the command when provided. */ windowId?: number; /** Target URL. Its origin must be listed in the runtime navigation policy. */ url: string; /** Logical content coordinates relative to the parent window. */ frame: NativeSdkRect; /** Native z-order within the parent window. Higher layers appear above lower layers. */ layer?: number; /** Best-effort transparent WebView background support for chrome/menu surfaces. */ transparent?: boolean; /** Inject `window.zero` into this WebView when it is trusted app chrome. Defaults to false. */ bridge?: boolean; } export interface NativeSdkSetWebViewFrameOptions { /** Defaults to "webview". Use "main" to resize the startup WebView. */ label?: string; /** Defaults to the caller and must match the window that calls the command when provided. */ windowId?: number; frame: NativeSdkRect; } export interface NativeSdkNavigateWebViewOptions { /** Defaults to "webview". Child WebViews only. */ label?: string; /** Defaults to the caller and must match the window that calls the command when provided. */ windowId?: number; url: string; } export interface NativeSdkSetWebViewZoomOptions { /** Defaults to "webview". Use "main" to zoom the startup WebView. */ label?: string; /** Defaults to the caller and must match the window that calls the command when provided. */ windowId?: number; /** Page zoom factor. Valid range: 0.25 to 5.0. */ zoom: number; } export interface NativeSdkSetWebViewLayerOptions { /** Defaults to "webview". "main" support depends on the native backend. */ label?: string; /** Defaults to the caller and must match the window that calls the command when provided. */ windowId?: number; layer: number; } export interface NativeSdkCloseWebViewOptions { /** Defaults to "webview". The reserved "main" WebView cannot be closed. */ label?: string; /** Defaults to the caller and must match the window that calls the command when provided. */ windowId?: number; } export interface NativeSdkWebViewHandle extends NativeSdkWebViewInfo { setFrame(frame: NativeSdkRect): Promise; navigate(url: string): Promise; setZoom(zoom: number): Promise; setLayer(layer: number): Promise; close(): Promise; } export type NativeSdkViewKind = | "webview" | "toolbar" | "titlebar_accessory" | "titlebarAccessory" | "sidebar" | "statusbar" | "split" | "stack" | "button" | "icon_button" | "iconButton" | "list_item" | "listItem" | "checkbox" | "toggle" | "segmented_control" | "segmentedControl" | "text_field" | "textField" | "search_field" | "searchField" | "label" | "spacer" | "gpu_surface" | "gpuSurface" | "progress_indicator" | "progressIndicator"; export type NativeSdkGpuSurfaceBackend = "none" | "metal"; export type NativeSdkGpuSurfacePixelFormat = "none" | "bgra8_unorm"; export type NativeSdkGpuSurfacePresentMode = "none" | "timer"; export type NativeSdkGpuSurfaceAlphaMode = "none" | "opaque" | "premultiplied"; export type NativeSdkGpuSurfaceColorSpace = "none" | "srgb" | "display_p3"; export type NativeSdkGpuSurfaceStatus = "unavailable" | "initializing" | "ready" | "lost"; export type NativeSdkCursor = "arrow" | "pointing_hand" | "text" | "resize_horizontal"; export type NativeSdkCanvasFrameProfileRisk = "idle" | "low" | "moderate" | "high"; export interface NativeSdkViewInfo { /** Stable runtime view id for this window/view lifetime. */ id: number; label: string; windowId: number; kind: NativeSdkViewKind; parent: string | null; role: string; accessibilityLabel: string; text: string; url: string; x: number; y: number; width: number; height: number; layer: number; visible: boolean; enabled: boolean; transparent: boolean; bridge: boolean; gpuWidth: number; gpuHeight: number; gpuScale: number; gpuFrame: number; gpuTimestampNs: number; gpuFrameIntervalNs: number; gpuInputTimestampNs: number; gpuInputLatencyNs: number; gpuInputLatencyBudgetNs: number; gpuInputLatencyBudgetExceededCount: number; gpuInputLatencyBudgetOk: boolean; gpuFirstFrameLatencyNs: number; gpuFirstFrameLatencyBudgetNs: number; gpuFirstFrameLatencyBudgetExceededCount: number; gpuFirstFrameLatencyBudgetOk: boolean; gpuNonblank: boolean; gpuSampleColor: number; gpuBackend: NativeSdkGpuSurfaceBackend; gpuPixelFormat: NativeSdkGpuSurfacePixelFormat; gpuPresentMode: NativeSdkGpuSurfacePresentMode; gpuAlphaMode: NativeSdkGpuSurfaceAlphaMode; gpuColorSpace: NativeSdkGpuSurfaceColorSpace; gpuVsync: boolean; gpuStatus: NativeSdkGpuSurfaceStatus; canvasRevision: number; canvasCommandCount: number; canvasFrameRequiresRender: boolean; canvasFrameFullRepaint: boolean; canvasFrameBatchCount: number; canvasFrameEncoderCommandCount: number; canvasFrameEncoderCacheActionCount: number; canvasFrameEncoderBindPipelineCount: number; canvasFrameEncoderDrawBatchCount: number; canvasFramePipelineCount: number; canvasFramePipelineUploadCount: number; canvasFramePipelineRetainCount: number; canvasFramePipelineEvictCount: number; canvasFramePathGeometryCount: number; canvasFramePathGeometryVertexCount: number; canvasFramePathGeometryIndexCount: number; canvasFramePathGeometryUploadCount: number; canvasFramePathGeometryRetainCount: number; canvasFramePathGeometryEvictCount: number; canvasFrameImageCount: number; canvasFrameImageUploadCount: number; canvasFrameImageRetainCount: number; canvasFrameImageEvictCount: number; canvasFrameLayerCount: number; canvasFrameLayerOpacityCount: number; canvasFrameLayerClipCount: number; canvasFrameLayerTransformCount: number; canvasFrameLayerUploadCount: number; canvasFrameLayerRetainCount: number; canvasFrameLayerEvictCount: number; canvasFrameResourceCount: number; canvasFrameResourceUploadCount: number; canvasFrameResourceRetainCount: number; canvasFrameResourceEvictCount: number; canvasFrameVisualEffectCount: number; canvasFrameVisualEffectShadowCount: number; canvasFrameVisualEffectBlurCount: number; canvasFrameVisualEffectUploadCount: number; canvasFrameVisualEffectRetainCount: number; canvasFrameVisualEffectEvictCount: number; canvasFrameGlyphAtlasEntryCount: number; canvasFrameGlyphAtlasUploadCount: number; canvasFrameGlyphAtlasRetainCount: number; canvasFrameGlyphAtlasEvictCount: number; canvasFrameTextLayoutCount: number; canvasFrameTextLayoutLineCount: number; canvasFrameTextLayoutUploadCount: number; canvasFrameTextLayoutRetainCount: number; canvasFrameTextLayoutEvictCount: number; canvasFrameGpuPacketCommandCount: number; canvasFrameGpuPacketCacheActionCount: number; canvasFrameGpuPacketCachedResourceCommandCount: number; canvasFrameGpuPacketUnsupportedCommandCount: number; canvasFrameGpuPacketRepresentable: boolean; canvasFrameChangeCount: number; canvasFrameBudgetExceededCount: number; canvasFrameBudgetOk: boolean; canvasFrameDirtyBounds: NativeSdkRect | null; canvasFrameProfileWorkUnits: number; canvasFrameProfileRisk: NativeSdkCanvasFrameProfileRisk; canvasFrameProfileSurfaceArea: number; canvasFrameProfileDirtyArea: number; canvasFrameProfileDirtyRatio: number; widgetRevision: number; widgetNodeCount: number; widgetSemanticsCount: number; cursor: NativeSdkCursor; focused: boolean; command: string; open: boolean; } export type NativeSdkNativeViewKind = Exclude; export interface NativeSdkCreateViewBaseOptions { label: string; windowId?: number; parent?: string; layer?: number; visible?: boolean; enabled?: boolean; /** Semantic role or fallback accessibility text. Use text for visible titles and placeholders. */ role?: string; /** Accessibility label announced for the native control without changing visible text. */ accessibilityLabel?: string; /** Visible native control label, button title, or text/search placeholder. */ text?: string; command?: string; transparent?: boolean; bridge?: boolean; } export interface NativeSdkCreateNativeViewOptions extends NativeSdkCreateViewBaseOptions { kind: NativeSdkNativeViewKind; frame?: NativeSdkRect; url?: never; /** Only valid for gpu_surface views. Defaults to the first supported backend. */ gpuBackend?: NativeSdkGpuSurfaceBackend; /** Only valid for gpu_surface views. */ gpuPixelFormat?: NativeSdkGpuSurfacePixelFormat; /** Only valid for gpu_surface views. */ gpuPresentMode?: NativeSdkGpuSurfacePresentMode; /** Only valid for gpu_surface views. */ gpuAlphaMode?: NativeSdkGpuSurfaceAlphaMode; /** Only valid for gpu_surface views. */ gpuColorSpace?: NativeSdkGpuSurfaceColorSpace; /** Only valid for gpu_surface views. */ gpuVsync?: boolean; } export interface NativeSdkCreateWebViewViewOptions extends NativeSdkCreateViewBaseOptions { kind: "webview"; frame: NativeSdkRect; url: string; } export type NativeSdkCreateViewOptions = | NativeSdkCreateNativeViewOptions | NativeSdkCreateWebViewViewOptions; export interface NativeSdkUpdateViewOptions { label: string; windowId?: number; frame?: NativeSdkRect; layer?: number; visible?: boolean; enabled?: boolean; /** Semantic role or fallback accessibility text. Use text for visible titles and placeholders. */ role?: string; /** Accessibility label announced for the native control without changing visible text. */ accessibilityLabel?: string; /** Visible native control label, button title, or text/search placeholder. */ text?: string; command?: string; /** Only valid for WebView-backed views. */ url?: string; } export interface NativeSdkSetViewFrameOptions { label: string; windowId?: number; frame: NativeSdkRect; } export interface NativeSdkSetViewVisibleOptions { label: string; windowId?: number; visible: boolean; } export interface NativeSdkViewSelector { label: string; windowId?: number; } export interface NativeSdkViewTraversalOptions { windowId?: number; } export interface NativeSdkViewHandle extends NativeSdkViewInfo { update(patch: Omit): Promise; setFrame(frame: NativeSdkRect): Promise; setVisible(visible: boolean): Promise; focus(): Promise; close(): Promise; } export type NativeSdkCommandSource = | "runtime" | "menu" | "shortcut" | "toolbar" | "tray" | "native_view" | "bridge"; export type NativeSdkPlatformFeature = | "main_webview" | "mainWebView" | "child_webviews" | "childWebViews" | "native_views" | "nativeViews" | "native_control_commands" | "nativeControlCommands" | "menus" | "tray" | "shortcuts" | "dialogs" | "clipboard_text" | "clipboardText" | "clipboard_rich_data" | "clipboardRichData" | "open_url" | "openUrl" | "reveal_path" | "revealPath" | "notifications" | "recent_documents" | "recentDocuments" | "credentials" | "file_drops" | "fileDrops" | "app_activation_events" | "appActivationEvents" | "gpu_surfaces" | "gpuSurfaces"; export type NativeSdkPlatformFeatureSelector = | { feature: NativeSdkPlatformFeature; name?: never } | { feature?: never; name: NativeSdkPlatformFeature }; export interface NativeSdkCommandEvent { name: string; source: NativeSdkCommandSource; windowId: number; viewLabel: string; /** Native tray item id for tray-sourced commands, otherwise 0. */ trayItemId: number; } export interface NativeSdkCommandInfo { id: string; title: string; enabled: boolean; checked: boolean; } export interface NativeSdkCommandSelector { name?: string; id?: string; } export interface NativeSdkShortcutModifiers { primary: boolean; command: boolean; control: boolean; option: boolean; shift: boolean; } export interface NativeSdkShortcutDetail { id: string; /** Alias for `id`, kept for compatibility with older built-in shortcut events. */ command: string; key: string; windowId: number; modifiers: NativeSdkShortcutModifiers; } export type NativeSdkAppLifecycleDetail = Record; export interface NativeSdkFileDropDetail { windowId: number; paths: string[]; } export interface NativeSdkOpenFileOptions { title?: string; defaultPath?: string; allowDirectories?: boolean; allowMultiple?: boolean; } export interface NativeSdkSaveFileOptions { title?: string; defaultPath?: string; defaultName?: string; } export interface NativeSdkMessageDialogOptions { style?: "info" | "warning" | "critical"; title?: string; message?: string; informativeText?: string; primaryButton?: string; secondaryButton?: string; tertiaryButton?: string; } export interface NativeSdkOpenUrlOptions { url: string; } export interface NativeSdkRevealPathOptions { path: string; } export interface NativeSdkRecentDocumentOptions { path: string; } export interface NativeSdkNotificationOptions { title: string; subtitle?: string; body?: string; } export interface NativeSdkClipboardReadOptions { mimeType?: string; } export interface NativeSdkClipboardWriteOptions { mimeType?: string; data: string; } export interface NativeSdkClipboardData { mimeType: string; data: string; } export interface NativeSdkCredentialKey { service: string; account: string; } export interface NativeSdkSetCredentialOptions extends NativeSdkCredentialKey { secret: string; } export interface NativeSdkApi { invoke(command: string, payload?: NativeSdkJson): Promise; on(name: "shortcut", callback: (detail: NativeSdkShortcutDetail) => void): () => void; on(name: "app:activate" | "app:deactivate", callback: (detail: NativeSdkAppLifecycleDetail) => void): () => void; on(name: "drop:files", callback: (detail: NativeSdkFileDropDetail) => void): () => void; on(name: string, callback: (detail: T) => void): () => void; off(name: "shortcut", callback: (detail: NativeSdkShortcutDetail) => void): void; off(name: "app:activate" | "app:deactivate", callback: (detail: NativeSdkAppLifecycleDetail) => void): void; off(name: "drop:files", callback: (detail: NativeSdkFileDropDetail) => void): void; off(name: string, callback: (detail: T) => void): void; /** Dispatch an app command through the runtime command path. */ commands: { invoke(command: string | NativeSdkCommandSelector): Promise; list(): Promise; }; windows: { create(options?: NativeSdkCreateWindowOptions): Promise; list(): Promise; focus(value: number | string): Promise; close(value: number | string): Promise; }; /** Manage the named native WebViews layered inside the calling native window. */ webviews: { create(options: NativeSdkCreateWebViewOptions): Promise; list(): Promise; setFrame(options: NativeSdkSetWebViewFrameOptions): Promise; navigate(options: NativeSdkNavigateWebViewOptions): Promise; setZoom(options: NativeSdkSetWebViewZoomOptions): Promise; setLayer(options: NativeSdkSetWebViewLayerOptions): Promise; close(options?: NativeSdkCloseWebViewOptions): Promise; }; /** Manage generic native views and WebView-backed views inside the calling native window. */ views: { create(options: NativeSdkCreateViewOptions): Promise; list(): Promise; update(label: string, patch: Omit): Promise; update(options: NativeSdkUpdateViewOptions): Promise; setFrame(options: NativeSdkSetViewFrameOptions): Promise; setVisible(options: NativeSdkSetViewVisibleOptions): Promise; focus(options: string | NativeSdkViewSelector): Promise; focusNext(options?: NativeSdkViewTraversalOptions): Promise; focusPrevious(options?: NativeSdkViewTraversalOptions): Promise; close(options: string | NativeSdkViewSelector): Promise; }; dialogs: { openFile(options?: NativeSdkOpenFileOptions): Promise; saveFile(options?: NativeSdkSaveFileOptions): Promise; showMessage(options?: NativeSdkMessageDialogOptions): Promise<"primary" | "secondary" | "tertiary">; }; clipboard: { readText(): Promise; writeText(value: string | { text: string }): Promise; read(options?: NativeSdkClipboardReadOptions): Promise; write(options: string | NativeSdkClipboardWriteOptions): Promise; }; os: { openUrl(value: string | NativeSdkOpenUrlOptions): Promise; showNotification(value: string | NativeSdkNotificationOptions): Promise; revealPath(value: string | NativeSdkRevealPathOptions): Promise; addRecentDocument(value: string | NativeSdkRecentDocumentOptions): Promise; clearRecentDocuments(): Promise; }; credentials: { set(options: NativeSdkSetCredentialOptions): Promise; get(options: NativeSdkCredentialKey): Promise; delete(options: NativeSdkCredentialKey): Promise; }; platform: { supports(value: NativeSdkPlatformFeature | NativeSdkPlatformFeatureSelector): Promise; }; } declare global { interface Window { zero: NativeSdkApi; } } export {};