@swifttui/web 0.1.8 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/src/wasi/BrowserWASIBridge.d.ts +8 -0
- package/dist/src/wasi/BrowserWASIBridge.js +2 -0
- package/dist/src/wasi/BrowserWASIBridge.js.map +1 -1
- package/dist/src/wasi/WasmEngineCapabilities.d.ts +35 -0
- package/dist/src/wasi/WasmEngineCapabilities.js +39 -0
- package/dist/src/wasi/WasmEngineCapabilities.js.map +1 -0
- package/dist/wasi.d.ts +2 -1
- package/dist/wasi.js +2 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -5,5 +5,6 @@ import { WebHostSceneBridge, WebHostSceneRuntime, WebHostSceneRuntimeOptions, Wh
|
|
|
5
5
|
import { WebSocketSceneBridge, WebSocketSceneBridgeFactory, WebSocketSceneBridgeOptions, WebSocketSceneSocket, webSocketSceneURL } from "./src/WebSocketSceneBridge.js";
|
|
6
6
|
import { WebHostAppController, WebHostAppOptions, WebHostBridgeFactory, WebHostBridgeFactoryOptions, WebHostEmbeddedHostConfig, createWebHostApp } from "./src/WebHostApp.js";
|
|
7
7
|
import { StdIOPipe } from "./src/wasi/StdIOPipe.js";
|
|
8
|
+
import { WasmEngineCapabilities, WasmEngineFamily, WasmEngineProbeSignals, classifyWasmEngineFamily, collectWasmEngineProbeSignals, resolveWasmEngineCapabilities, stackProfileEnvironmentDefaults } from "./src/wasi/WasmEngineCapabilities.js";
|
|
8
9
|
import { BrowserWASIBridge, BrowserWASIBridgeOptions, BrowserWASIOutputSink } from "./src/wasi/BrowserWASIBridge.js";
|
|
9
|
-
export { BrowserWASIBridge, BrowserWASIBridgeOptions, BrowserWASIOutputSink, ResolvedWebHostTerminalPalette, ResolvedWebHostTerminalStyle, SUPPORTED_SURFACE_VERSION, StdIOPipe, WebHostANSIColors, WebHostAccessibilityAnnouncement, WebHostAccessibilityLiveRegion, WebHostAccessibilityNode, WebHostAccessibilityPoint, WebHostAppController, WebHostAppOptions, WebHostBridgeFactory, WebHostBridgeFactoryOptions, WebHostEmbeddedHostConfig, WebHostFocusPresentation, WebHostFocusSemantics, WebHostFrameDiagnosticRecord, WebHostKeyInput, WebHostMouseInput, WebHostOutputDecoder, WebHostOutputRecord, WebHostOutputSink, WebHostRuntimeIssue, WebHostSceneBridge, WebHostSceneDescriptor, WebHostSceneManifest, WebHostSceneManifestSource, WebHostSceneRuntime, WebHostSceneRuntimeOptions, WebHostScrollRegion, WebHostSurfaceCell, WebHostSurfaceDamage, WebHostSurfaceDamageRange, WebHostSurfaceDamageTextRow, WebHostSurfaceDeltaFrame, WebHostSurfaceDeltaRow, WebHostSurfaceFrame, WebHostSurfaceImage, WebHostSurfaceImageFormat, WebHostSurfaceLineStyle, WebHostSurfaceLinkRow, WebHostSurfaceLinkRun, WebHostSurfaceRect, WebHostSurfaceSize, WebHostSurfaceStyle, WebHostTerminalAppearance, WebHostTerminalCursorStyle, WebHostTerminalPalette, WebHostTerminalRenderStyle, WebHostTerminalStyle, WebHostTerminalTheme, WebSocketSceneBridge, WebSocketSceneBridgeFactory, WebSocketSceneBridgeOptions, WebSocketSceneSocket, WheelMode, applyWebHostTerminalStyle, createWebHostApp, decodeWebHostTerminalRenderStyleBase64, encodeKeyInputMessage, encodeMouseInputMessage, encodePasteInputMessage, encodeRenderStyleControlMessage, encodeResizeControlMessage, encodeWebHostTerminalRenderStyleBase64, loadWebHostSceneManifest, mergeWebHostTerminalStyle, normalizeWebHostSceneManifest, normalizeWebHostTerminalStyle, resolveWebHostTerminalRenderStyle, webSocketSceneURL, webTUISceneManifestFromDescriptors, webTUISceneManifestToJSON, webTUITerminalBackgroundColor };
|
|
10
|
+
export { BrowserWASIBridge, BrowserWASIBridgeOptions, BrowserWASIOutputSink, ResolvedWebHostTerminalPalette, ResolvedWebHostTerminalStyle, SUPPORTED_SURFACE_VERSION, StdIOPipe, WasmEngineCapabilities, WasmEngineFamily, WasmEngineProbeSignals, WebHostANSIColors, WebHostAccessibilityAnnouncement, WebHostAccessibilityLiveRegion, WebHostAccessibilityNode, WebHostAccessibilityPoint, WebHostAppController, WebHostAppOptions, WebHostBridgeFactory, WebHostBridgeFactoryOptions, WebHostEmbeddedHostConfig, WebHostFocusPresentation, WebHostFocusSemantics, WebHostFrameDiagnosticRecord, WebHostKeyInput, WebHostMouseInput, WebHostOutputDecoder, WebHostOutputRecord, WebHostOutputSink, WebHostRuntimeIssue, WebHostSceneBridge, WebHostSceneDescriptor, WebHostSceneManifest, WebHostSceneManifestSource, WebHostSceneRuntime, WebHostSceneRuntimeOptions, WebHostScrollRegion, WebHostSurfaceCell, WebHostSurfaceDamage, WebHostSurfaceDamageRange, WebHostSurfaceDamageTextRow, WebHostSurfaceDeltaFrame, WebHostSurfaceDeltaRow, WebHostSurfaceFrame, WebHostSurfaceImage, WebHostSurfaceImageFormat, WebHostSurfaceLineStyle, WebHostSurfaceLinkRow, WebHostSurfaceLinkRun, WebHostSurfaceRect, WebHostSurfaceSize, WebHostSurfaceStyle, WebHostTerminalAppearance, WebHostTerminalCursorStyle, WebHostTerminalPalette, WebHostTerminalRenderStyle, WebHostTerminalStyle, WebHostTerminalTheme, WebSocketSceneBridge, WebSocketSceneBridgeFactory, WebSocketSceneBridgeOptions, WebSocketSceneSocket, WheelMode, applyWebHostTerminalStyle, classifyWasmEngineFamily, collectWasmEngineProbeSignals, createWebHostApp, decodeWebHostTerminalRenderStyleBase64, encodeKeyInputMessage, encodeMouseInputMessage, encodePasteInputMessage, encodeRenderStyleControlMessage, encodeResizeControlMessage, encodeWebHostTerminalRenderStyleBase64, loadWebHostSceneManifest, mergeWebHostTerminalStyle, normalizeWebHostSceneManifest, normalizeWebHostTerminalStyle, resolveWasmEngineCapabilities, resolveWebHostTerminalRenderStyle, stackProfileEnvironmentDefaults, webSocketSceneURL, webTUISceneManifestFromDescriptors, webTUISceneManifestToJSON, webTUITerminalBackgroundColor };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { StdIOPipe } from "./src/wasi/StdIOPipe.js";
|
|
2
|
+
import { classifyWasmEngineFamily, collectWasmEngineProbeSignals, resolveWasmEngineCapabilities, stackProfileEnvironmentDefaults } from "./src/wasi/WasmEngineCapabilities.js";
|
|
2
3
|
import { applyWebHostTerminalStyle, decodeWebHostTerminalRenderStyleBase64, encodeWebHostTerminalRenderStyleBase64, mergeWebHostTerminalStyle, normalizeWebHostTerminalStyle, resolveWebHostTerminalRenderStyle, webTUITerminalBackgroundColor } from "./src/WebHostTerminalStyle.js";
|
|
3
4
|
import { SUPPORTED_SURFACE_VERSION, WebHostOutputDecoder, encodeKeyInputMessage, encodeMouseInputMessage, encodePasteInputMessage, encodeRenderStyleControlMessage, encodeResizeControlMessage } from "./src/WebHostSurfaceTransport.js";
|
|
4
5
|
import { BrowserWASIBridge } from "./src/wasi/BrowserWASIBridge.js";
|
|
@@ -6,4 +7,4 @@ import { WebSocketSceneBridge, webSocketSceneURL } from "./src/WebSocketSceneBri
|
|
|
6
7
|
import { loadWebHostSceneManifest, normalizeWebHostSceneManifest, webTUISceneManifestFromDescriptors, webTUISceneManifestToJSON } from "./src/WebHostSceneManifest.js";
|
|
7
8
|
import { WebHostSceneRuntime } from "./src/WebHostSceneRuntime.js";
|
|
8
9
|
import { createWebHostApp } from "./src/WebHostApp.js";
|
|
9
|
-
export { BrowserWASIBridge, SUPPORTED_SURFACE_VERSION, StdIOPipe, WebHostOutputDecoder, WebHostSceneRuntime, WebSocketSceneBridge, applyWebHostTerminalStyle, createWebHostApp, decodeWebHostTerminalRenderStyleBase64, encodeKeyInputMessage, encodeMouseInputMessage, encodePasteInputMessage, encodeRenderStyleControlMessage, encodeResizeControlMessage, encodeWebHostTerminalRenderStyleBase64, loadWebHostSceneManifest, mergeWebHostTerminalStyle, normalizeWebHostSceneManifest, normalizeWebHostTerminalStyle, resolveWebHostTerminalRenderStyle, webSocketSceneURL, webTUISceneManifestFromDescriptors, webTUISceneManifestToJSON, webTUITerminalBackgroundColor };
|
|
10
|
+
export { BrowserWASIBridge, SUPPORTED_SURFACE_VERSION, StdIOPipe, WebHostOutputDecoder, WebHostSceneRuntime, WebSocketSceneBridge, applyWebHostTerminalStyle, classifyWasmEngineFamily, collectWasmEngineProbeSignals, createWebHostApp, decodeWebHostTerminalRenderStyleBase64, encodeKeyInputMessage, encodeMouseInputMessage, encodePasteInputMessage, encodeRenderStyleControlMessage, encodeResizeControlMessage, encodeWebHostTerminalRenderStyleBase64, loadWebHostSceneManifest, mergeWebHostTerminalStyle, normalizeWebHostSceneManifest, normalizeWebHostTerminalStyle, resolveWasmEngineCapabilities, resolveWebHostTerminalRenderStyle, stackProfileEnvironmentDefaults, webSocketSceneURL, webTUISceneManifestFromDescriptors, webTUISceneManifestToJSON, webTUITerminalBackgroundColor };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { WebHostTerminalStyle } from "../WebHostTerminalStyle.js";
|
|
2
2
|
import { WebHostOutputSink, encodeRenderStyleControlMessage, encodeResizeControlMessage } from "../WebHostSurfaceTransport.js";
|
|
3
3
|
import { StdIOPipe } from "./StdIOPipe.js";
|
|
4
|
+
import { WasmEngineCapabilities } from "./WasmEngineCapabilities.js";
|
|
4
5
|
//#region src/wasi/BrowserWASIBridge.d.ts
|
|
5
6
|
interface BrowserWASIBridgeOptions {
|
|
6
7
|
sceneId: string;
|
|
@@ -8,6 +9,13 @@ interface BrowserWASIBridgeOptions {
|
|
|
8
9
|
rows: number;
|
|
9
10
|
environment?: Record<string, string>;
|
|
10
11
|
renderStyle?: WebHostTerminalStyle;
|
|
12
|
+
/**
|
|
13
|
+
* Detected engine capabilities driving engine-conditional environment
|
|
14
|
+
* defaults (e.g. disabling the stack-lean resolve profile on V8). Defaults
|
|
15
|
+
* to probing the current engine; injectable for tests and embedders that
|
|
16
|
+
* want to force a profile.
|
|
17
|
+
*/
|
|
18
|
+
engineCapabilities?: WasmEngineCapabilities;
|
|
11
19
|
}
|
|
12
20
|
type BrowserWASIOutputSink = WebHostOutputSink;
|
|
13
21
|
declare class BrowserWASIBridge {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { StdIOPipe } from "./StdIOPipe.js";
|
|
2
|
+
import { resolveWasmEngineCapabilities, stackProfileEnvironmentDefaults } from "./WasmEngineCapabilities.js";
|
|
2
3
|
import { encodeWebHostTerminalRenderStyleBase64 } from "../WebHostTerminalStyle.js";
|
|
3
4
|
import { WebHostOutputDecoder, encodeRenderStyleControlMessage, encodeResizeControlMessage } from "../WebHostSurfaceTransport.js";
|
|
4
5
|
//#region src/wasi/BrowserWASIBridge.ts
|
|
@@ -19,6 +20,7 @@ var BrowserWASIBridge = class {
|
|
|
19
20
|
TUIGUI_SCENE: options.sceneId,
|
|
20
21
|
TUIGUI_COLUMNS: String(Math.max(1, options.columns)),
|
|
21
22
|
TUIGUI_ROWS: String(Math.max(1, options.rows)),
|
|
23
|
+
...stackProfileEnvironmentDefaults(options.engineCapabilities ?? resolveWasmEngineCapabilities()),
|
|
22
24
|
...options.environment,
|
|
23
25
|
...options.renderStyle ? { TUIGUI_RENDER_STYLE: encodeWebHostTerminalRenderStyleBase64(options.renderStyle) } : {}
|
|
24
26
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BrowserWASIBridge.js","names":[],"sources":["../../../src/wasi/BrowserWASIBridge.ts"],"sourcesContent":["import { StdIOPipe } from \"./StdIOPipe.ts\";\nimport {\n encodeWebHostTerminalRenderStyleBase64,\n type WebHostTerminalStyle,\n} from \"../WebHostTerminalStyle.ts\";\nimport {\n WebHostOutputDecoder,\n encodeRenderStyleControlMessage,\n encodeResizeControlMessage,\n type WebHostOutputSink,\n} from \"../WebHostSurfaceTransport.ts\";\n\nexport interface BrowserWASIBridgeOptions {\n sceneId: string;\n columns: number;\n rows: number;\n environment?: Record<string, string>;\n renderStyle?: WebHostTerminalStyle;\n}\n\nexport type BrowserWASIOutputSink = WebHostOutputSink;\n\nexport class BrowserWASIBridge {\n readonly stdin = new StdIOPipe();\n readonly stdout = new StdIOPipe();\n readonly stderr = new StdIOPipe();\n readonly environment: Record<string, string>;\n\n private detachStdout?: () => void;\n private detachStderr?: () => void;\n private readonly resizeListeners = new Set<(\n columns: number,\n rows: number,\n cellWidth?: number,\n cellHeight?: number\n ) => void>();\n private latestResize: {\n columns: number;\n rows: number;\n cellWidth?: number;\n cellHeight?: number;\n };\n\n constructor(options: BrowserWASIBridgeOptions) {\n this.environment = {\n TUIGUI_MODE: \"browser\",\n TUIGUI_TRANSPORT: \"surface\",\n TUIGUI_SURFACE_DELTA: \"1\",\n TUIGUI_SCENE: options.sceneId,\n TUIGUI_COLUMNS: String(Math.max(1, options.columns)),\n TUIGUI_ROWS: String(Math.max(1, options.rows)),\n ...options.environment,\n ...(options.renderStyle\n ? {\n TUIGUI_RENDER_STYLE: encodeWebHostTerminalRenderStyleBase64(\n options.renderStyle\n ),\n }\n : {}),\n };\n this.latestResize = {\n columns: Math.max(1, options.columns),\n rows: Math.max(1, options.rows),\n };\n }\n\n bindOutput(\n sink: BrowserWASIOutputSink\n ): void {\n this.detachStdout?.();\n this.detachStderr?.();\n const decoder = new WebHostOutputDecoder();\n this.detachStdout = this.stdout.subscribe((chunk) => {\n for (const record of decoder.feed(chunk)) {\n switch (record.type) {\n case \"surface\":\n sink.presentSurface(record.frame);\n break;\n case \"clipboard\":\n void sink.writeClipboard?.(record.text);\n break;\n case \"runtimeIssue\":\n sink.notifyRuntimeIssue?.(record.issue);\n break;\n case \"frameDiagnostic\":\n sink.recordFrameDiagnostic?.(record.diagnostic);\n break;\n case \"text\":\n sink.writeOutput?.(record.text);\n break;\n }\n }\n });\n this.detachStderr = this.stderr.subscribe((chunk) => {\n sink.writeError?.(new TextDecoder().decode(chunk));\n });\n }\n\n resize(\n columns: number,\n rows: number,\n cellWidth?: number,\n cellHeight?: number\n ): void {\n const normalizedColumns = Math.max(1, columns);\n const normalizedRows = Math.max(1, rows);\n this.environment.TUIGUI_COLUMNS = String(normalizedColumns);\n this.environment.TUIGUI_ROWS = String(normalizedRows);\n this.latestResize = {\n columns: normalizedColumns,\n rows: normalizedRows,\n cellWidth,\n cellHeight,\n };\n this.stdin.write(encodeResizeControlMessage(columns, rows, cellWidth, cellHeight));\n for (const listener of this.resizeListeners) {\n listener(normalizedColumns, normalizedRows, cellWidth, cellHeight);\n }\n }\n\n updateRenderStyle(\n style: WebHostTerminalStyle\n ): void {\n this.environment.TUIGUI_RENDER_STYLE = encodeWebHostTerminalRenderStyleBase64(style);\n this.stdin.write(encodeRenderStyleControlMessage(style));\n }\n\n sendInput(\n chunk: Uint8Array\n ): void {\n this.stdin.write(chunk);\n }\n\n subscribeResize(\n listener: (\n columns: number,\n rows: number,\n cellWidth?: number,\n cellHeight?: number\n ) => void\n ): () => void {\n this.resizeListeners.add(listener);\n listener(\n this.latestResize.columns,\n this.latestResize.rows,\n this.latestResize.cellWidth,\n this.latestResize.cellHeight\n );\n return () => {\n this.resizeListeners.delete(listener);\n };\n }\n\n dispose(): void {\n this.detachStdout?.();\n this.detachStderr?.();\n this.resizeListeners.clear();\n this.stdin.close();\n this.stdout.close();\n this.stderr.close();\n }\n}\n\nexport {\n encodeRenderStyleControlMessage,\n encodeResizeControlMessage,\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"BrowserWASIBridge.js","names":[],"sources":["../../../src/wasi/BrowserWASIBridge.ts"],"sourcesContent":["import { StdIOPipe } from \"./StdIOPipe.ts\";\nimport {\n resolveWasmEngineCapabilities,\n stackProfileEnvironmentDefaults,\n type WasmEngineCapabilities,\n} from \"./WasmEngineCapabilities.ts\";\nimport {\n encodeWebHostTerminalRenderStyleBase64,\n type WebHostTerminalStyle,\n} from \"../WebHostTerminalStyle.ts\";\nimport {\n WebHostOutputDecoder,\n encodeRenderStyleControlMessage,\n encodeResizeControlMessage,\n type WebHostOutputSink,\n} from \"../WebHostSurfaceTransport.ts\";\n\nexport interface BrowserWASIBridgeOptions {\n sceneId: string;\n columns: number;\n rows: number;\n environment?: Record<string, string>;\n renderStyle?: WebHostTerminalStyle;\n /**\n * Detected engine capabilities driving engine-conditional environment\n * defaults (e.g. disabling the stack-lean resolve profile on V8). Defaults\n * to probing the current engine; injectable for tests and embedders that\n * want to force a profile.\n */\n engineCapabilities?: WasmEngineCapabilities;\n}\n\nexport type BrowserWASIOutputSink = WebHostOutputSink;\n\nexport class BrowserWASIBridge {\n readonly stdin = new StdIOPipe();\n readonly stdout = new StdIOPipe();\n readonly stderr = new StdIOPipe();\n readonly environment: Record<string, string>;\n\n private detachStdout?: () => void;\n private detachStderr?: () => void;\n private readonly resizeListeners = new Set<(\n columns: number,\n rows: number,\n cellWidth?: number,\n cellHeight?: number\n ) => void>();\n private latestResize: {\n columns: number;\n rows: number;\n cellWidth?: number;\n cellHeight?: number;\n };\n\n constructor(options: BrowserWASIBridgeOptions) {\n this.environment = {\n TUIGUI_MODE: \"browser\",\n TUIGUI_TRANSPORT: \"surface\",\n TUIGUI_SURFACE_DELTA: \"1\",\n TUIGUI_SCENE: options.sceneId,\n TUIGUI_COLUMNS: String(Math.max(1, options.columns)),\n TUIGUI_ROWS: String(Math.max(1, options.rows)),\n ...stackProfileEnvironmentDefaults(\n options.engineCapabilities ?? resolveWasmEngineCapabilities()\n ),\n ...options.environment,\n ...(options.renderStyle\n ? {\n TUIGUI_RENDER_STYLE: encodeWebHostTerminalRenderStyleBase64(\n options.renderStyle\n ),\n }\n : {}),\n };\n this.latestResize = {\n columns: Math.max(1, options.columns),\n rows: Math.max(1, options.rows),\n };\n }\n\n bindOutput(\n sink: BrowserWASIOutputSink\n ): void {\n this.detachStdout?.();\n this.detachStderr?.();\n const decoder = new WebHostOutputDecoder();\n this.detachStdout = this.stdout.subscribe((chunk) => {\n for (const record of decoder.feed(chunk)) {\n switch (record.type) {\n case \"surface\":\n sink.presentSurface(record.frame);\n break;\n case \"clipboard\":\n void sink.writeClipboard?.(record.text);\n break;\n case \"runtimeIssue\":\n sink.notifyRuntimeIssue?.(record.issue);\n break;\n case \"frameDiagnostic\":\n sink.recordFrameDiagnostic?.(record.diagnostic);\n break;\n case \"text\":\n sink.writeOutput?.(record.text);\n break;\n }\n }\n });\n this.detachStderr = this.stderr.subscribe((chunk) => {\n sink.writeError?.(new TextDecoder().decode(chunk));\n });\n }\n\n resize(\n columns: number,\n rows: number,\n cellWidth?: number,\n cellHeight?: number\n ): void {\n const normalizedColumns = Math.max(1, columns);\n const normalizedRows = Math.max(1, rows);\n this.environment.TUIGUI_COLUMNS = String(normalizedColumns);\n this.environment.TUIGUI_ROWS = String(normalizedRows);\n this.latestResize = {\n columns: normalizedColumns,\n rows: normalizedRows,\n cellWidth,\n cellHeight,\n };\n this.stdin.write(encodeResizeControlMessage(columns, rows, cellWidth, cellHeight));\n for (const listener of this.resizeListeners) {\n listener(normalizedColumns, normalizedRows, cellWidth, cellHeight);\n }\n }\n\n updateRenderStyle(\n style: WebHostTerminalStyle\n ): void {\n this.environment.TUIGUI_RENDER_STYLE = encodeWebHostTerminalRenderStyleBase64(style);\n this.stdin.write(encodeRenderStyleControlMessage(style));\n }\n\n sendInput(\n chunk: Uint8Array\n ): void {\n this.stdin.write(chunk);\n }\n\n subscribeResize(\n listener: (\n columns: number,\n rows: number,\n cellWidth?: number,\n cellHeight?: number\n ) => void\n ): () => void {\n this.resizeListeners.add(listener);\n listener(\n this.latestResize.columns,\n this.latestResize.rows,\n this.latestResize.cellWidth,\n this.latestResize.cellHeight\n );\n return () => {\n this.resizeListeners.delete(listener);\n };\n }\n\n dispose(): void {\n this.detachStdout?.();\n this.detachStderr?.();\n this.resizeListeners.clear();\n this.stdin.close();\n this.stdout.close();\n this.stderr.close();\n }\n}\n\nexport {\n encodeRenderStyleControlMessage,\n encodeResizeControlMessage,\n};\n"],"mappings":";;;;;AAkCA,IAAa,oBAAb,MAA+B;CAC7B,QAAiB,IAAI,UAAU;CAC/B,SAAkB,IAAI,UAAU;CAChC,SAAkB,IAAI,UAAU;CAChC;CAEA;CACA;CACA,kCAAmC,IAAI,IAK5B;CACX;CAOA,YAAY,SAAmC;EAC7C,KAAK,cAAc;GACjB,aAAa;GACb,kBAAkB;GAClB,sBAAsB;GACtB,cAAc,QAAQ;GACtB,gBAAgB,OAAO,KAAK,IAAI,GAAG,QAAQ,OAAO,CAAC;GACnD,aAAa,OAAO,KAAK,IAAI,GAAG,QAAQ,IAAI,CAAC;GAC7C,GAAG,gCACD,QAAQ,sBAAsB,8BAA8B,CAC9D;GACA,GAAG,QAAQ;GACX,GAAI,QAAQ,cACR,EACE,qBAAqB,uCACnB,QAAQ,WACV,EACF,IACA,CAAC;EACP;EACA,KAAK,eAAe;GAClB,SAAS,KAAK,IAAI,GAAG,QAAQ,OAAO;GACpC,MAAM,KAAK,IAAI,GAAG,QAAQ,IAAI;EAChC;CACF;CAEA,WACE,MACM;EACN,KAAK,eAAe;EACpB,KAAK,eAAe;EACpB,MAAM,UAAU,IAAI,qBAAqB;EACzC,KAAK,eAAe,KAAK,OAAO,WAAW,UAAU;GACnD,KAAK,MAAM,UAAU,QAAQ,KAAK,KAAK,GACrC,QAAQ,OAAO,MAAf;IACA,KAAK;KACH,KAAK,eAAe,OAAO,KAAK;KAChC;IACF,KAAK;KACH,KAAU,iBAAiB,OAAO,IAAI;KACtC;IACF,KAAK;KACH,KAAK,qBAAqB,OAAO,KAAK;KACtC;IACF,KAAK;KACH,KAAK,wBAAwB,OAAO,UAAU;KAC9C;IACF,KAAK;KACH,KAAK,cAAc,OAAO,IAAI;KAC9B;GACF;EAEJ,CAAC;EACD,KAAK,eAAe,KAAK,OAAO,WAAW,UAAU;GACnD,KAAK,aAAa,IAAI,YAAY,CAAC,CAAC,OAAO,KAAK,CAAC;EACnD,CAAC;CACH;CAEA,OACE,SACA,MACA,WACA,YACM;EACN,MAAM,oBAAoB,KAAK,IAAI,GAAG,OAAO;EAC7C,MAAM,iBAAiB,KAAK,IAAI,GAAG,IAAI;EACvC,KAAK,YAAY,iBAAiB,OAAO,iBAAiB;EAC1D,KAAK,YAAY,cAAc,OAAO,cAAc;EACpD,KAAK,eAAe;GAClB,SAAS;GACT,MAAM;GACN;GACA;EACF;EACA,KAAK,MAAM,MAAM,2BAA2B,SAAS,MAAM,WAAW,UAAU,CAAC;EACjF,KAAK,MAAM,YAAY,KAAK,iBAC1B,SAAS,mBAAmB,gBAAgB,WAAW,UAAU;CAErE;CAEA,kBACE,OACM;EACN,KAAK,YAAY,sBAAsB,uCAAuC,KAAK;EACnF,KAAK,MAAM,MAAM,gCAAgC,KAAK,CAAC;CACzD;CAEA,UACE,OACM;EACN,KAAK,MAAM,MAAM,KAAK;CACxB;CAEA,gBACE,UAMY;EACZ,KAAK,gBAAgB,IAAI,QAAQ;EACjC,SACE,KAAK,aAAa,SAClB,KAAK,aAAa,MAClB,KAAK,aAAa,WAClB,KAAK,aAAa,UACpB;EACA,aAAa;GACX,KAAK,gBAAgB,OAAO,QAAQ;EACtC;CACF;CAEA,UAAgB;EACd,KAAK,eAAe;EACpB,KAAK,eAAe;EACpB,KAAK,gBAAgB,MAAM;EAC3B,KAAK,MAAM,MAAM;EACjB,KAAK,OAAO,MAAM;EAClB,KAAK,OAAO,MAAM;CACpB;AACF"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
//#region src/wasi/WasmEngineCapabilities.d.ts
|
|
2
|
+
type WasmEngineFamily = "v8" | "jsc" | "gecko" | "unknown";
|
|
3
|
+
interface WasmEngineProbeSignals {
|
|
4
|
+
errorStack: string;
|
|
5
|
+
errorHasGeckoFileName: boolean;
|
|
6
|
+
errorHasJSCSourceURL: boolean;
|
|
7
|
+
wasmSuspendingType: string;
|
|
8
|
+
wasmPromisingType: string;
|
|
9
|
+
}
|
|
10
|
+
interface WasmEngineCapabilities {
|
|
11
|
+
engine: WasmEngineFamily;
|
|
12
|
+
/**
|
|
13
|
+
* WebAssembly JavaScript Promise Integration (`WebAssembly.Suspending` +
|
|
14
|
+
* `WebAssembly.promising`). When true, a future main-thread execution path
|
|
15
|
+
* can suspend on stdin instead of blocking a worker on `Atomics.wait`.
|
|
16
|
+
*/
|
|
17
|
+
supportsJSPI: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Whether the SwiftTUI WASI build should keep its stack-lean resolve
|
|
20
|
+
* profile on this engine.
|
|
21
|
+
*/
|
|
22
|
+
stackLeanRecommended: boolean;
|
|
23
|
+
}
|
|
24
|
+
declare function collectWasmEngineProbeSignals(): WasmEngineProbeSignals;
|
|
25
|
+
declare function classifyWasmEngineFamily(signals: WasmEngineProbeSignals): WasmEngineFamily;
|
|
26
|
+
declare function resolveWasmEngineCapabilities(signals?: WasmEngineProbeSignals): WasmEngineCapabilities;
|
|
27
|
+
/**
|
|
28
|
+
* WASI environment defaults implied by the engine capabilities. Spread these
|
|
29
|
+
* *before* caller-provided environment entries so an explicit
|
|
30
|
+
* `SWIFTTUI_STACK_LEAN_PROFILE` (or a tuning override) always wins.
|
|
31
|
+
*/
|
|
32
|
+
declare function stackProfileEnvironmentDefaults(capabilities: WasmEngineCapabilities): Record<string, string>;
|
|
33
|
+
//#endregion
|
|
34
|
+
export { WasmEngineCapabilities, WasmEngineFamily, WasmEngineProbeSignals, classifyWasmEngineFamily, collectWasmEngineProbeSignals, resolveWasmEngineCapabilities, stackProfileEnvironmentDefaults };
|
|
35
|
+
//# sourceMappingURL=WasmEngineCapabilities.d.ts.map
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
//#region src/wasi/WasmEngineCapabilities.ts
|
|
2
|
+
function collectWasmEngineProbeSignals() {
|
|
3
|
+
const probe = /* @__PURE__ */ new Error("wasm-engine-probe");
|
|
4
|
+
const wasm = globalThis.WebAssembly;
|
|
5
|
+
return {
|
|
6
|
+
errorStack: typeof probe.stack === "string" ? probe.stack : "",
|
|
7
|
+
errorHasGeckoFileName: "fileName" in probe,
|
|
8
|
+
errorHasJSCSourceURL: "sourceURL" in probe,
|
|
9
|
+
wasmSuspendingType: typeof wasm?.Suspending,
|
|
10
|
+
wasmPromisingType: typeof wasm?.promising
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
function classifyWasmEngineFamily(signals) {
|
|
14
|
+
if (/^\s*at /m.test(signals.errorStack)) return "v8";
|
|
15
|
+
if (signals.errorHasGeckoFileName) return "gecko";
|
|
16
|
+
if (signals.errorHasJSCSourceURL || /^[^\n]*@/m.test(signals.errorStack)) return "jsc";
|
|
17
|
+
return "unknown";
|
|
18
|
+
}
|
|
19
|
+
function resolveWasmEngineCapabilities(signals = collectWasmEngineProbeSignals()) {
|
|
20
|
+
const engine = classifyWasmEngineFamily(signals);
|
|
21
|
+
return {
|
|
22
|
+
engine,
|
|
23
|
+
supportsJSPI: signals.wasmSuspendingType === "function" && signals.wasmPromisingType === "function",
|
|
24
|
+
stackLeanRecommended: engine !== "v8"
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* WASI environment defaults implied by the engine capabilities. Spread these
|
|
29
|
+
* *before* caller-provided environment entries so an explicit
|
|
30
|
+
* `SWIFTTUI_STACK_LEAN_PROFILE` (or a tuning override) always wins.
|
|
31
|
+
*/
|
|
32
|
+
function stackProfileEnvironmentDefaults(capabilities) {
|
|
33
|
+
if (capabilities.stackLeanRecommended) return {};
|
|
34
|
+
return { SWIFTTUI_STACK_LEAN_PROFILE: "0" };
|
|
35
|
+
}
|
|
36
|
+
//#endregion
|
|
37
|
+
export { classifyWasmEngineFamily, collectWasmEngineProbeSignals, resolveWasmEngineCapabilities, stackProfileEnvironmentDefaults };
|
|
38
|
+
|
|
39
|
+
//# sourceMappingURL=WasmEngineCapabilities.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WasmEngineCapabilities.js","names":[],"sources":["../../../src/wasi/WasmEngineCapabilities.ts"],"sourcesContent":["// Runtime detection of the browser's JS/wasm engine family and the wasm\n// capabilities that decide how the SwiftTUI WASI runtime should execute.\n//\n// JavaScriptCore runs wasm calls on the host thread's native stack, and\n// Darwin worker threads get ~1/16 of the main-thread stack budget, so\n// SwiftTUI's WASI build defaults to its stack-lean resolve profile\n// (`SWIFTTUI_STACK_LEAN_PROFILE`, depth-capped chunked resolve). That profile\n// costs steady-state pipeline time, and engines with roomy worker stacks\n// don't need it. Detection is deliberately asymmetric: a wrongly applied lean\n// profile only costs speed, while wrongly disabling it on JSC overflows the\n// wasm stack and kills the app — so lean stays recommended unless the engine\n// is confidently V8 (the only family with a measured, comfortable worker\n// budget). Gecko is kept on the lean profile until its worker wasm stack\n// budget is measured.\n//\n// Engine classification reads Error mechanics rather than user-agent\n// strings: V8 formats stack frames as ` at fn (url)`, JSC and Gecko as\n// `fn@url`, and the two are split by their engine-specific Error instance\n// properties (Gecko `fileName`, JSC `sourceURL`). Non-browser JSC hosts that\n// emulate V8 stack frames for Node compatibility (e.g. Bun) classify as\n// \"v8\"; the probe targets browser engines, where the formats don't cross.\n\nexport type WasmEngineFamily = \"v8\" | \"jsc\" | \"gecko\" | \"unknown\";\n\nexport interface WasmEngineProbeSignals {\n errorStack: string;\n errorHasGeckoFileName: boolean;\n errorHasJSCSourceURL: boolean;\n wasmSuspendingType: string;\n wasmPromisingType: string;\n}\n\nexport interface WasmEngineCapabilities {\n engine: WasmEngineFamily;\n /**\n * WebAssembly JavaScript Promise Integration (`WebAssembly.Suspending` +\n * `WebAssembly.promising`). When true, a future main-thread execution path\n * can suspend on stdin instead of blocking a worker on `Atomics.wait`.\n */\n supportsJSPI: boolean;\n /**\n * Whether the SwiftTUI WASI build should keep its stack-lean resolve\n * profile on this engine.\n */\n stackLeanRecommended: boolean;\n}\n\nexport function collectWasmEngineProbeSignals(): WasmEngineProbeSignals {\n const probe = new Error(\"wasm-engine-probe\");\n const wasm = (\n globalThis as {\n WebAssembly?: { Suspending?: unknown; promising?: unknown };\n }\n ).WebAssembly;\n return {\n errorStack: typeof probe.stack === \"string\" ? probe.stack : \"\",\n errorHasGeckoFileName: \"fileName\" in probe,\n errorHasJSCSourceURL: \"sourceURL\" in probe,\n wasmSuspendingType: typeof wasm?.Suspending,\n wasmPromisingType: typeof wasm?.promising,\n };\n}\n\nexport function classifyWasmEngineFamily(\n signals: WasmEngineProbeSignals\n): WasmEngineFamily {\n if (/^\\s*at /m.test(signals.errorStack)) {\n return \"v8\";\n }\n if (signals.errorHasGeckoFileName) {\n return \"gecko\";\n }\n if (signals.errorHasJSCSourceURL || /^[^\\n]*@/m.test(signals.errorStack)) {\n return \"jsc\";\n }\n return \"unknown\";\n}\n\nexport function resolveWasmEngineCapabilities(\n signals: WasmEngineProbeSignals = collectWasmEngineProbeSignals()\n): WasmEngineCapabilities {\n const engine = classifyWasmEngineFamily(signals);\n return {\n engine,\n supportsJSPI:\n signals.wasmSuspendingType === \"function\" &&\n signals.wasmPromisingType === \"function\",\n stackLeanRecommended: engine !== \"v8\",\n };\n}\n\n/**\n * WASI environment defaults implied by the engine capabilities. Spread these\n * *before* caller-provided environment entries so an explicit\n * `SWIFTTUI_STACK_LEAN_PROFILE` (or a tuning override) always wins.\n */\nexport function stackProfileEnvironmentDefaults(\n capabilities: WasmEngineCapabilities\n): Record<string, string> {\n if (capabilities.stackLeanRecommended) {\n return {};\n }\n return { SWIFTTUI_STACK_LEAN_PROFILE: \"0\" };\n}\n"],"mappings":";AA+CA,SAAgB,gCAAwD;CACtE,MAAM,wBAAQ,IAAI,MAAM,mBAAmB;CAC3C,MAAM,OACJ,WAGA;CACF,OAAO;EACL,YAAY,OAAO,MAAM,UAAU,WAAW,MAAM,QAAQ;EAC5D,uBAAuB,cAAc;EACrC,sBAAsB,eAAe;EACrC,oBAAoB,OAAO,MAAM;EACjC,mBAAmB,OAAO,MAAM;CAClC;AACF;AAEA,SAAgB,yBACd,SACkB;CAClB,IAAI,WAAW,KAAK,QAAQ,UAAU,GACpC,OAAO;CAET,IAAI,QAAQ,uBACV,OAAO;CAET,IAAI,QAAQ,wBAAwB,YAAY,KAAK,QAAQ,UAAU,GACrE,OAAO;CAET,OAAO;AACT;AAEA,SAAgB,8BACd,UAAkC,8BAA8B,GACxC;CACxB,MAAM,SAAS,yBAAyB,OAAO;CAC/C,OAAO;EACL;EACA,cACE,QAAQ,uBAAuB,cAC/B,QAAQ,sBAAsB;EAChC,sBAAsB,WAAW;CACnC;AACF;;;;;;AAOA,SAAgB,gCACd,cACwB;CACxB,IAAI,aAAa,sBACf,OAAO,CAAC;CAEV,OAAO,EAAE,6BAA6B,IAAI;AAC5C"}
|
package/dist/wasi.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { encodeRenderStyleControlMessage, encodeResizeControlMessage } from "./src/WebHostSurfaceTransport.js";
|
|
2
2
|
import { StdIOPipe } from "./src/wasi/StdIOPipe.js";
|
|
3
|
+
import { WasmEngineCapabilities, WasmEngineFamily, WasmEngineProbeSignals, classifyWasmEngineFamily, collectWasmEngineProbeSignals, resolveWasmEngineCapabilities, stackProfileEnvironmentDefaults } from "./src/wasi/WasmEngineCapabilities.js";
|
|
3
4
|
import { BrowserWASIBridge, BrowserWASIBridgeOptions, BrowserWASIOutputSink } from "./src/wasi/BrowserWASIBridge.js";
|
|
4
5
|
import { SharedInputQueueBuffers, SharedInputQueueReader, SharedInputQueueWriter, SharedInputReadiness, createSharedInputQueue, hydrateSharedInputQueue, sharedInputQueueDefaultCapacity } from "./src/wasi/SharedInputQueue.js";
|
|
5
6
|
import { WasmSceneResizeEvent, WasmSceneRuntimeFactoryOptions, WasmSceneRuntimeHandle, createWasmSceneRuntimeFactory } from "./src/wasi/WasmSceneRuntime.js";
|
|
6
|
-
export { BrowserWASIBridge, BrowserWASIBridgeOptions, BrowserWASIOutputSink, SharedInputQueueBuffers, SharedInputQueueReader, SharedInputQueueWriter, SharedInputReadiness, StdIOPipe, WasmSceneResizeEvent, WasmSceneRuntimeFactoryOptions, WasmSceneRuntimeHandle, createSharedInputQueue, createWasmSceneRuntimeFactory, encodeRenderStyleControlMessage, encodeResizeControlMessage, hydrateSharedInputQueue, sharedInputQueueDefaultCapacity };
|
|
7
|
+
export { BrowserWASIBridge, BrowserWASIBridgeOptions, BrowserWASIOutputSink, SharedInputQueueBuffers, SharedInputQueueReader, SharedInputQueueWriter, SharedInputReadiness, StdIOPipe, WasmEngineCapabilities, WasmEngineFamily, WasmEngineProbeSignals, WasmSceneResizeEvent, WasmSceneRuntimeFactoryOptions, WasmSceneRuntimeHandle, classifyWasmEngineFamily, collectWasmEngineProbeSignals, createSharedInputQueue, createWasmSceneRuntimeFactory, encodeRenderStyleControlMessage, encodeResizeControlMessage, hydrateSharedInputQueue, resolveWasmEngineCapabilities, sharedInputQueueDefaultCapacity, stackProfileEnvironmentDefaults };
|
package/dist/wasi.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { StdIOPipe } from "./src/wasi/StdIOPipe.js";
|
|
2
|
+
import { classifyWasmEngineFamily, collectWasmEngineProbeSignals, resolveWasmEngineCapabilities, stackProfileEnvironmentDefaults } from "./src/wasi/WasmEngineCapabilities.js";
|
|
2
3
|
import { encodeRenderStyleControlMessage, encodeResizeControlMessage } from "./src/WebHostSurfaceTransport.js";
|
|
3
4
|
import { BrowserWASIBridge } from "./src/wasi/BrowserWASIBridge.js";
|
|
4
5
|
import { SharedInputQueueReader, SharedInputQueueWriter, createSharedInputQueue, hydrateSharedInputQueue, sharedInputQueueDefaultCapacity } from "./src/wasi/SharedInputQueue.js";
|
|
5
6
|
import { createWasmSceneRuntimeFactory } from "./src/wasi/WasmSceneRuntime.js";
|
|
6
|
-
export { BrowserWASIBridge, SharedInputQueueReader, SharedInputQueueWriter, StdIOPipe, createSharedInputQueue, createWasmSceneRuntimeFactory, encodeRenderStyleControlMessage, encodeResizeControlMessage, hydrateSharedInputQueue, sharedInputQueueDefaultCapacity };
|
|
7
|
+
export { BrowserWASIBridge, SharedInputQueueReader, SharedInputQueueWriter, StdIOPipe, classifyWasmEngineFamily, collectWasmEngineProbeSignals, createSharedInputQueue, createWasmSceneRuntimeFactory, encodeRenderStyleControlMessage, encodeResizeControlMessage, hydrateSharedInputQueue, resolveWasmEngineCapabilities, sharedInputQueueDefaultCapacity, stackProfileEnvironmentDefaults };
|