@yodaos-pkg/ink-env
v0.20.1
Published
TypeScript definitions for Ink framework
Readme
@yodaos-pkg/ink-env
@yodaos-pkg/ink-env provides TypeScript ambient type definitions for the Ink JavaScript runtime environment.
It is intended for JavaScript and TypeScript application code that runs inside Ink. The package focuses on the API surface available to app code and intentionally does not document runtime implementation details.
What This Package Provides
- global environment types such as
console, timers,fetch,WebSocket,EventSource,navigator, andperformance - DOM-style event and event target types used by the Ink runtime
- app-facing framework globals such as
getApp(),App,Page, andComponent - the
wxnamespace for mini-program style APIs - media, speech, sensor, networking, and AI-related API typings exposed to business logic
- asset module declarations for common image and audio file types
Install
npm install -D @yodaos-pkg/ink-envThis package exposes global declarations. In most cases you do not need to import anything from it.
TypeScript Setup
Add the package to your tsconfig.json so TypeScript can load the ambient declarations explicitly:
{
"compilerOptions": {
"types": ["@yodaos-pkg/ink-env"]
}
}If your project already loads all installed type packages automatically, this step may not be necessary.
API Overview
Core Globals
The environment includes commonly used global APIs such as:
consolesetTimeout,setInterval,clearTimeout,clearIntervalrequestAnimationFrame,cancelAnimationFrameatob,btoafetch,Headers,Request,RequestInit,Response,FormDataReadableStream,WritableStream,TransformStream, and queueing strategiesBlob,File,ImageBitmap,ImageData,createImageBitmapwindow,self,global,performance
Example:
setTimeout(() => {
console.log('hello from Ink');
}, 16);App And Page APIs
The package includes framework-facing globals and instance types used by application code:
getApp()AppPageComponent
These types are useful for page logic, component logic, and app-level state access.
DOM-Style Events
Ink application code can use DOM-like event primitives and typed event objects, including:
EventTargetEventMessageEventKeyboardEventPointerEventWheelEventFocusEventInputEvent
These declarations are designed for app code that listens to runtime-dispatched events or interacts with event-driven APIs.
Networking APIs
The environment includes typed networking surfaces for both promise-based and streaming use cases:
fetch()WebSocketEventSourceAbortControllerandAbortSignal
Example:
const response = await fetch('https://example.com/data');
const data = await response.json();
console.log(data);Navigator And Runtime Information
The navigator typing includes runtime and device-facing information such as:
navigator.userAgentnavigator.languagenavigator.languagesnavigator.regionnavigator.versionsnavigator.bluetoothnavigator.geolocation
Media And Audio APIs
The package includes types for media-related capabilities exposed to app code, such as:
AudioPlayerSoundcreateImageBitmap- recorder and camera APIs under
wx.media - image and audio library access through
navigator.mediaLibrary(list,get, and create-onlysave)
Sensors And Speech APIs
The environment also includes typed interfaces for selected device capabilities:
AccelerometerGyroscopeMagnetometerAbsoluteOrientationSensorSpeechRecognitionwx.speech
navigator.geolocation is also available with standard callback signatures and
position/error shapes. This API is host-capability driven: the Ink runtime only
normalizes the JavaScript surface, permission gate, and IPC payloads, while the
actual location provider must be supplied by the host environment.
Availability may depend on the current host environment. The type package describes the supported JavaScript API surface, not host-by-host runtime guarantees.
Payment APIs
The package also includes first-release typings for the standard payment entry points exposed to Ink app code:
PaymentRequestPaymentResponsePaymentMethodDataPaymentDetailsInitPaymentOptions
Example:
const request = new PaymentRequest(
[{ supportedMethods: 'basic-card' }],
{
total: {
label: 'Total',
amount: { currency: 'USD', value: '12.34' },
},
},
{
requestPayerEmail: true,
},
);
const canPay = await request.canMakePayment();
if (canPay) {
const response = await request.show();
console.log(response.payerEmail, response.shippingOption, response.shippingAddress);
await response.complete('success');
}Payment typing notes:
- these types describe the JavaScript-standard surface available inside the Ink app runtime
- the actual payment backend is host-capability driven; the host must provide a
paymentcapability bridge PaymentResponseincludes top-levelpayerName,payerEmail,payerPhone,shippingOption, andshippingAddressin addition todetails- first-release typing and runtime support exclude dynamic update events such as
shippingaddresschange,shippingoptionchange,paymentmethodchange,merchantvalidation, andPaymentResponse.retry()
AI APIs
The package includes AI-related types exposed to application code:
LanguageModelLanguageModelSessionLanguageModelMessageLanguageModelTool
These types are intended for application code that interacts with the host-provided language model capability.
wx Namespace
Mini-program style APIs are exposed under the global wx namespace. Current type coverage includes areas such as:
- base utilities like
wx.canIUse() - window and system information such as
wx.getWindowInfo() - app control such as
wx.exitMiniProgram() - UI helpers such as
wx.setBackgroundColor() - networking APIs such as
wx.request(),wx.connectSocket(), andwx.createEventSource() - media APIs such as recorder and camera helpers under
wx.media - speech helpers under
wx.speech
Example:
const info = wx.getWindowInfo();
console.log(info.windowWidth, info.windowHeight);What This Package Does Not Cover
This README is intentionally focused on the JavaScript and TypeScript API surface available to application code.
It does not document:
- runtime internals
- renderer or engine architecture
- native bridge details
- package implementation structure
- host-specific implementation notes that are not part of the exposed API contract
Files
The published package contains:
index.d.tsglobals.d.tsmodules.d.tswx.d.tsREADME.md
