@microsoft/webui 0.0.1 → 0.0.2
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/README.md +116 -0
- package/dist/index.d.ts +12 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -7
- package/package.json +8 -8
package/README.md
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# @microsoft/webui
|
|
2
|
+
|
|
3
|
+
High-performance server-side rendering framework. Compiles HTML templates into a binary protocol at build time and renders them with native speed at runtime — no JavaScript runtime overhead.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @microsoft/webui
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
The package automatically installs the correct platform-specific native binary for your OS and architecture (Windows, macOS, Linux — x64 and arm64).
|
|
12
|
+
|
|
13
|
+
## Quick start
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
import { build, render } from "@microsoft/webui";
|
|
17
|
+
|
|
18
|
+
// Build templates into a protocol
|
|
19
|
+
const result = build({ appDir: "./src" });
|
|
20
|
+
|
|
21
|
+
// Render with state data
|
|
22
|
+
const html = render(result.protocol, { name: "World", items: ["a", "b"] });
|
|
23
|
+
console.log(html);
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## API
|
|
27
|
+
|
|
28
|
+
### `build(options: BuildOptions): BuildResult`
|
|
29
|
+
|
|
30
|
+
Compiles an application directory of HTML templates into a binary protocol.
|
|
31
|
+
|
|
32
|
+
```js
|
|
33
|
+
const result = build({
|
|
34
|
+
appDir: "./src", // Path to the template directory
|
|
35
|
+
entry: "index.html", // Entry file (default: "index.html")
|
|
36
|
+
css: "link", // CSS strategy: "link" or "style"
|
|
37
|
+
plugin: "fast", // Parser plugin (e.g., "fast" for FAST-HTML)
|
|
38
|
+
components: [], // Additional component sources
|
|
39
|
+
outDir: "./dist", // Output directory for CLI fallback
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
// result.protocol — Buffer containing the compiled protocol
|
|
43
|
+
// result.cssFiles — Array of [filename, content, ...] pairs
|
|
44
|
+
// result.stats — { durationMs, fragmentCount, componentCount, cssFileCount, protocolSizeBytes, tokenCount }
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### `render(protocol: Buffer, state: object | string): string`
|
|
48
|
+
|
|
49
|
+
Renders a compiled protocol with state data and returns the full HTML string.
|
|
50
|
+
|
|
51
|
+
```js
|
|
52
|
+
const html = render(protocol, { title: "Hello", show: true });
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### `renderStream(protocol: Buffer, state: object | string, onChunk: (html: string) => void): void`
|
|
56
|
+
|
|
57
|
+
Renders with streaming output — each HTML fragment is passed to the callback as it is produced.
|
|
58
|
+
|
|
59
|
+
```js
|
|
60
|
+
renderStream(protocol, state, (chunk) => {
|
|
61
|
+
response.write(chunk);
|
|
62
|
+
});
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### `buildAndRender(options: BuildOptions, state: object | string): string`
|
|
66
|
+
|
|
67
|
+
Convenience function that builds and renders in a single call.
|
|
68
|
+
|
|
69
|
+
```js
|
|
70
|
+
const html = buildAndRender({ appDir: "./src" }, { name: "WebUI" });
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### `inspect(protocol: Buffer): string`
|
|
74
|
+
|
|
75
|
+
Returns a JSON representation of the protocol for debugging.
|
|
76
|
+
|
|
77
|
+
```js
|
|
78
|
+
const json = inspect(protocol);
|
|
79
|
+
console.log(JSON.parse(json));
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### `renderPartial(protocol: Buffer, stateJson: string, entryId: string, requestPath: string, inventoryHex: string): string`
|
|
83
|
+
|
|
84
|
+
Produces a JSON partial response for client-side navigation, including state, templates, and route chain.
|
|
85
|
+
|
|
86
|
+
## CLI
|
|
87
|
+
|
|
88
|
+
The package also includes the `webui` CLI binary:
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
# Build templates to disk
|
|
92
|
+
npx webui build ./src --out ./dist
|
|
93
|
+
|
|
94
|
+
# Start a dev server
|
|
95
|
+
npx webui serve ./src --state ./data/state.json --port 3000
|
|
96
|
+
|
|
97
|
+
# Inspect a compiled protocol
|
|
98
|
+
npx webui inspect ./dist/protocol.bin
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Platform support
|
|
102
|
+
|
|
103
|
+
| OS | Architecture | Package |
|
|
104
|
+
|---|---|---|
|
|
105
|
+
| Windows | x64 | `@microsoft/webui-win32-x64` |
|
|
106
|
+
| Windows | arm64 | `@microsoft/webui-win32-arm64` |
|
|
107
|
+
| macOS | arm64 | `@microsoft/webui-darwin-arm64` |
|
|
108
|
+
| macOS | x64 | `@microsoft/webui-darwin-x64` |
|
|
109
|
+
| Linux | x64 | `@microsoft/webui-linux-x64` |
|
|
110
|
+
| Linux | arm64 | `@microsoft/webui-linux-arm64` |
|
|
111
|
+
|
|
112
|
+
Platform-specific packages are installed automatically as optional dependencies.
|
|
113
|
+
|
|
114
|
+
## License
|
|
115
|
+
|
|
116
|
+
[MIT](https://github.com/microsoft/webui/blob/main/LICENSE)
|
package/dist/index.d.ts
CHANGED
|
@@ -37,6 +37,15 @@ export interface BuildResult {
|
|
|
37
37
|
/** Build statistics. */
|
|
38
38
|
stats: BuildStats;
|
|
39
39
|
}
|
|
40
|
+
/** Options for rendering a protocol. */
|
|
41
|
+
export interface RenderOptions {
|
|
42
|
+
/** Fragment ID to start rendering from (default: "index.html"). */
|
|
43
|
+
entry?: string;
|
|
44
|
+
/** URL path to match routes against (default: "/"). */
|
|
45
|
+
requestPath?: string;
|
|
46
|
+
/** Parser plugin name (e.g., "fast" for FAST-HTML hydration). */
|
|
47
|
+
plugin?: string;
|
|
48
|
+
}
|
|
40
49
|
/** Complete JSON partial response from the server for client-side navigation. */
|
|
41
50
|
export interface PartialResponse {
|
|
42
51
|
/** Application state for the matched route. */
|
|
@@ -61,14 +70,14 @@ export declare function build(options: BuildOptions): BuildResult;
|
|
|
61
70
|
* Render a pre-compiled protocol with state data.
|
|
62
71
|
* Uses native addon when available, WASM fallback otherwise.
|
|
63
72
|
*/
|
|
64
|
-
export declare function render(protocol: Buffer, state: object | string): string;
|
|
73
|
+
export declare function render(protocol: Buffer, state: object | string, options?: RenderOptions): string;
|
|
65
74
|
/**
|
|
66
75
|
* Render a protocol with streaming output.
|
|
67
76
|
* Each HTML fragment is passed to the onChunk callback as it is produced.
|
|
68
77
|
*/
|
|
69
|
-
export declare function renderStream(protocol: Buffer, state: object | string, onChunk: (html: string) => void): void;
|
|
78
|
+
export declare function renderStream(protocol: Buffer, state: object | string, onChunk: (html: string) => void, options?: RenderOptions): void;
|
|
70
79
|
/** Build and render in a single call. */
|
|
71
|
-
export declare function buildAndRender(options: BuildOptions, state: object | string): string;
|
|
80
|
+
export declare function buildAndRender(options: BuildOptions, state: object | string, renderOpts?: RenderOptions): string;
|
|
72
81
|
/** Inspect protocol bytes and return JSON representation. */
|
|
73
82
|
export declare function inspect(protocolData: Buffer): string;
|
|
74
83
|
/**
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,gDAAgD;AAChD,MAAM,WAAW,YAAY;IAC3B,2DAA2D;IAC3D,MAAM,EAAE,MAAM,CAAC;IACf,oDAAoD;IACpD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,0DAA0D;IAC1D,GAAG,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IACvB,4DAA4D;IAC5D,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,kEAAkE;IAClE,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,iEAAiE;IACjE,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,wBAAwB;AACxB,MAAM,WAAW,UAAU;IACzB,sCAAsC;IACtC,UAAU,EAAE,MAA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AAC,CAAC;QAChC,KAAK,CAAC,EAAE,OAAO,CAAC;KACjB,CAAC,CAAC;CACJ;AA6DD,uDAAuD;AACvD,wBAAgB,KAAK,CAAC,OAAO,EAAE,YAAY,GAAG,WAAW,CAkCxD;AAID;;;GAGG;AACH,wBAAgB,MAAM,CACpB,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,GAAG,MAAM,EACtB,OAAO,CAAC,EAAE,aAAa,GACtB,MAAM,CAiBR;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAC1B,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,GAAG,MAAM,EACtB,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,EAC/B,OAAO,CAAC,EAAE,aAAa,GACtB,IAAI,CAcN;AAID,yCAAyC;AACzC,wBAAgB,cAAc,CAC5B,OAAO,EAAE,YAAY,EACrB,KAAK,EAAE,MAAM,GAAG,MAAM,EACtB,UAAU,CAAC,EAAE,aAAa,GACzB,MAAM,CAMR;AAED,6DAA6D;AAC7D,wBAAgB,OAAO,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAMpD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAC3B,YAAY,EAAE,MAAM,EACpB,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,MAAM,EACnB,YAAY,EAAE,MAAM,GACnB,MAAM,CAMR"}
|
package/dist/index.js
CHANGED
|
@@ -60,14 +60,16 @@ function build(options) {
|
|
|
60
60
|
}
|
|
61
61
|
return { protocol: Buffer.alloc(0), cssFiles: [], stats: emptyStats() };
|
|
62
62
|
}
|
|
63
|
-
function render(protocol, state) {
|
|
63
|
+
function render(protocol, state, options) {
|
|
64
64
|
const native = loadAddon();
|
|
65
65
|
if (native) {
|
|
66
66
|
let result = "";
|
|
67
67
|
const stateStr = typeof state === "string" ? state : JSON.stringify(state);
|
|
68
|
-
|
|
68
|
+
const entry = options?.entry ?? "index.html";
|
|
69
|
+
const requestPath = options?.requestPath ?? "/";
|
|
70
|
+
native.render(protocol, stateStr, entry, requestPath, (chunk) => {
|
|
69
71
|
result += chunk;
|
|
70
|
-
});
|
|
72
|
+
}, options?.plugin);
|
|
71
73
|
return result;
|
|
72
74
|
}
|
|
73
75
|
warnFallback();
|
|
@@ -75,11 +77,13 @@ function render(protocol, state) {
|
|
|
75
77
|
"[webui] render() requires the native addon. WASM render fallback not yet wired."
|
|
76
78
|
);
|
|
77
79
|
}
|
|
78
|
-
function renderStream(protocol, state, onChunk) {
|
|
80
|
+
function renderStream(protocol, state, onChunk, options) {
|
|
79
81
|
const native = loadAddon();
|
|
80
82
|
if (native) {
|
|
81
83
|
const stateStr = typeof state === "string" ? state : JSON.stringify(state);
|
|
82
|
-
|
|
84
|
+
const entry = options?.entry ?? "index.html";
|
|
85
|
+
const requestPath = options?.requestPath ?? "/";
|
|
86
|
+
native.render(protocol, stateStr, entry, requestPath, onChunk, options?.plugin);
|
|
83
87
|
return;
|
|
84
88
|
}
|
|
85
89
|
warnFallback();
|
|
@@ -87,12 +91,12 @@ function renderStream(protocol, state, onChunk) {
|
|
|
87
91
|
"[webui] renderStream() requires the native addon. WASM render fallback not yet wired."
|
|
88
92
|
);
|
|
89
93
|
}
|
|
90
|
-
function buildAndRender(options, state) {
|
|
94
|
+
function buildAndRender(options, state, renderOpts) {
|
|
91
95
|
const result = build(options);
|
|
92
96
|
if (!result.protocol || result.protocol.length === 0) {
|
|
93
97
|
throw new Error("[webui] Build did not return protocol data.");
|
|
94
98
|
}
|
|
95
|
-
return render(result.protocol, state);
|
|
99
|
+
return render(result.protocol, state, renderOpts);
|
|
96
100
|
}
|
|
97
101
|
function inspect(protocolData) {
|
|
98
102
|
const native = loadAddon();
|
package/package.json
CHANGED
|
@@ -27,19 +27,19 @@
|
|
|
27
27
|
"license": "MIT",
|
|
28
28
|
"name": "@microsoft/webui",
|
|
29
29
|
"optionalDependencies": {
|
|
30
|
-
"@microsoft/webui-darwin-arm64": "0.0.
|
|
31
|
-
"@microsoft/webui-
|
|
32
|
-
"@microsoft/webui-
|
|
33
|
-
"@microsoft/webui-linux-x64": "0.0.
|
|
34
|
-
"@microsoft/webui-win32-arm64": "0.0.
|
|
35
|
-
"@microsoft/webui-win32-x64": "0.0.
|
|
30
|
+
"@microsoft/webui-darwin-arm64": "0.0.2",
|
|
31
|
+
"@microsoft/webui-linux-arm64": "0.0.2",
|
|
32
|
+
"@microsoft/webui-darwin-x64": "0.0.2",
|
|
33
|
+
"@microsoft/webui-linux-x64": "0.0.2",
|
|
34
|
+
"@microsoft/webui-win32-arm64": "0.0.2",
|
|
35
|
+
"@microsoft/webui-win32-x64": "0.0.2"
|
|
36
36
|
},
|
|
37
37
|
"repository": {
|
|
38
38
|
"type": "git",
|
|
39
|
-
"url": "https://github.com/
|
|
39
|
+
"url": "https://github.com/microsoft/webui.git"
|
|
40
40
|
},
|
|
41
41
|
"type": "module",
|
|
42
|
-
"version": "0.0.
|
|
42
|
+
"version": "0.0.2",
|
|
43
43
|
"scripts": {
|
|
44
44
|
"build": "esbuild src/index.ts src/platform.ts src/install.ts --outdir=dist --format=esm --platform=node && tsc --emitDeclarationOnly",
|
|
45
45
|
"postinstall": "node --input-type=module -e \"try{await import('./dist/install.js')}catch{}\"",
|