@microsoft/webui 0.0.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Microsoft Corporation.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,86 @@
1
+ /** Options for building a WebUI application. */
2
+ export interface BuildOptions {
3
+ /** Path to the application folder containing templates. */
4
+ appDir: string;
5
+ /** Entry HTML file name (default: "index.html"). */
6
+ entry?: string;
7
+ /** CSS delivery strategy: "link" (default) or "style". */
8
+ css?: "link" | "style";
9
+ /** Parser plugin (e.g., "fast" for FAST-HTML hydration). */
10
+ plugin?: string;
11
+ /** Additional component sources (npm packages or local paths). */
12
+ components?: string[];
13
+ /** Output directory (used by CLI fallback for build-to-disk). */
14
+ outDir?: string;
15
+ }
16
+ /** Build statistics. */
17
+ export interface BuildStats {
18
+ /** Build duration in milliseconds. */
19
+ durationMs: number;
20
+ /** Total number of protocol fragments. */
21
+ fragmentCount: number;
22
+ /** Number of registered components. */
23
+ componentCount: number;
24
+ /** Number of CSS files produced. */
25
+ cssFileCount: number;
26
+ /** Size of the serialized protocol in bytes. */
27
+ protocolSizeBytes: number;
28
+ /** Number of unique CSS tokens discovered. */
29
+ tokenCount: number;
30
+ }
31
+ /** Result of a successful build operation. */
32
+ export interface BuildResult {
33
+ /** Serialized protocol (protobuf binary). */
34
+ protocol: Buffer;
35
+ /** CSS files as alternating [filename, content, ...]. */
36
+ cssFiles: string[];
37
+ /** Build statistics. */
38
+ stats: BuildStats;
39
+ }
40
+ /** Complete JSON partial response from the server for client-side navigation. */
41
+ export interface PartialResponse {
42
+ /** Application state for the matched route. */
43
+ state: Record<string, unknown>;
44
+ /** f-template HTML strings the client doesn't already have. */
45
+ templates: string[];
46
+ /** Updated hex bitmask of loaded component templates. */
47
+ inventory: string;
48
+ /** The request path. */
49
+ path: string;
50
+ /** Matched route chain — one entry per nesting level. */
51
+ chain: Array<{
52
+ component: string;
53
+ path: string;
54
+ params?: Record<string, string>;
55
+ exact?: boolean;
56
+ }>;
57
+ }
58
+ /** Build a WebUI application from an app directory. */
59
+ export declare function build(options: BuildOptions): BuildResult;
60
+ /**
61
+ * Render a pre-compiled protocol with state data.
62
+ * Uses native addon when available, WASM fallback otherwise.
63
+ */
64
+ export declare function render(protocol: Buffer, state: object | string): string;
65
+ /**
66
+ * Render a protocol with streaming output.
67
+ * Each HTML fragment is passed to the onChunk callback as it is produced.
68
+ */
69
+ export declare function renderStream(protocol: Buffer, state: object | string, onChunk: (html: string) => void): void;
70
+ /** Build and render in a single call. */
71
+ export declare function buildAndRender(options: BuildOptions, state: object | string): string;
72
+ /** Inspect protocol bytes and return JSON representation. */
73
+ export declare function inspect(protocolData: Buffer): string;
74
+ /**
75
+ * Produce a complete JSON partial response for client-side navigation.
76
+ *
77
+ * Returns a JSON string with `state`, `templates`, `inventory`, `path`, and `chain`.
78
+ * Pipe directly to the HTTP response — no post-processing needed.
79
+ *
80
+ * If you need to inspect the response, parse it with the exported `PartialResponse` type:
81
+ * ```ts
82
+ * const partial: PartialResponse = JSON.parse(renderPartial(...));
83
+ * ```
84
+ */
85
+ export declare function renderPartial(protocolData: Buffer, stateJson: string, entryId: string, requestPath: string, inventoryHex: string): string;
86
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +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,MAAM,CAAC;IACnB,0CAA0C;IAC1C,aAAa,EAAE,MAAM,CAAC;IACtB,uCAAuC;IACvC,cAAc,EAAE,MAAM,CAAC;IACvB,oCAAoC;IACpC,YAAY,EAAE,MAAM,CAAC;IACrB,gDAAgD;IAChD,iBAAiB,EAAE,MAAM,CAAC;IAC1B,8CAA8C;IAC9C,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,8CAA8C;AAC9C,MAAM,WAAW,WAAW;IAC1B,6CAA6C;IAC7C,QAAQ,EAAE,MAAM,CAAC;IACjB,yDAAyD;IACzD,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,wBAAwB;IACxB,KAAK,EAAE,UAAU,CAAC;CACnB;AAED,iFAAiF;AACjF,MAAM,W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{ createRequire } from "node:module";
2
+ import { execFileSync } from "node:child_process";
3
+ import fs from "node:fs";
4
+ import nodePath from "node:path";
5
+ import { resolve, platformKey } from "./platform.js";
6
+ const require2 = createRequire(import.meta.url);
7
+ let addon = null;
8
+ let fallbackWarned = false;
9
+ function loadAddon() {
10
+ if (addon) return addon;
11
+ const addonPath = resolve("addon");
12
+ if (addonPath) {
13
+ try {
14
+ if (addonPath.endsWith(".node")) {
15
+ addon = require2(addonPath);
16
+ } else {
17
+ const m = { exports: {} };
18
+ process.dlopen(m, addonPath);
19
+ addon = m.exports;
20
+ }
21
+ return addon;
22
+ } catch {
23
+ }
24
+ }
25
+ return null;
26
+ }
27
+ function warnFallback() {
28
+ if (fallbackWarned) return;
29
+ fallbackWarned = true;
30
+ console.warn(
31
+ `[webui] Native addon not available for ${platformKey()}. Using WASM fallback \u2014 performance may be degraded.
32
+ Install the platform-specific package for optimal performance.`
33
+ );
34
+ }
35
+ function build(options) {
36
+ const native = loadAddon();
37
+ if (native?.build) {
38
+ return native.build(options);
39
+ }
40
+ const binPath = resolve("bin");
41
+ if (!binPath) {
42
+ throw new Error(
43
+ "[webui] Cannot build: no native addon or CLI binary available."
44
+ );
45
+ }
46
+ const args = ["build", options.appDir ?? "."];
47
+ if (options.entry) args.push("--entry", options.entry);
48
+ if (options.css) args.push("--css", options.css);
49
+ if (options.plugin) args.push("--plugin", options.plugin);
50
+ if (options.components) {
51
+ for (const c of options.components) {
52
+ args.push("--components", c);
53
+ }
54
+ }
55
+ if (options.outDir) args.push("--out", options.outDir);
56
+ execFileSync(binPath, args, { stdio: "inherit" });
57
+ if (options.outDir) {
58
+ const protocol = fs.readFileSync(nodePath.join(options.outDir, "protocol.bin"));
59
+ return { protocol, cssFiles: [], stats: emptyStats() };
60
+ }
61
+ return { protocol: Buffer.alloc(0), cssFiles: [], stats: emptyStats() };
62
+ }
63
+ function render(protocol, state) {
64
+ const native = loadAddon();
65
+ if (native) {
66
+ let result = "";
67
+ const stateStr = typeof state === "string" ? state : JSON.stringify(state);
68
+ native.render(protocol, stateStr, (chunk) => {
69
+ result += chunk;
70
+ });
71
+ return result;
72
+ }
73
+ warnFallback();
74
+ throw new Error(
75
+ "[webui] render() requires the native addon. WASM render fallback not yet wired."
76
+ );
77
+ }
78
+ function renderStream(protocol, state, onChunk) {
79
+ const native = loadAddon();
80
+ if (native) {
81
+ const stateStr = typeof state === "string" ? state : JSON.stringify(state);
82
+ native.render(protocol, stateStr, onChunk);
83
+ return;
84
+ }
85
+ warnFallback();
86
+ throw new Error(
87
+ "[webui] renderStream() requires the native addon. WASM render fallback not yet wired."
88
+ );
89
+ }
90
+ function buildAndRender(options, state) {
91
+ const result = build(options);
92
+ if (!result.protocol || result.protocol.length === 0) {
93
+ throw new Error("[webui] Build did not return protocol data.");
94
+ }
95
+ return render(result.protocol, state);
96
+ }
97
+ function inspect(protocolData) {
98
+ const native = loadAddon();
99
+ if (native?.inspect) {
100
+ return native.inspect(protocolData);
101
+ }
102
+ throw new Error("[webui] inspect() requires the native addon.");
103
+ }
104
+ function renderPartial(protocolData, stateJson, entryId, requestPath, inventoryHex) {
105
+ const native = loadAddon();
106
+ if (native?.renderPartial) {
107
+ return native.renderPartial(protocolData, stateJson, entryId, requestPath, inventoryHex);
108
+ }
109
+ throw new Error("[webui] renderPartial() requires the native addon.");
110
+ }
111
+ function emptyStats() {
112
+ return {
113
+ durationMs: 0,
114
+ fragmentCount: 0,
115
+ componentCount: 0,
116
+ cssFileCount: 0,
117
+ protocolSizeBytes: 0,
118
+ tokenCount: 0
119
+ };
120
+ }
121
+ export {
122
+ build,
123
+ buildAndRender,
124
+ inspect,
125
+ render,
126
+ renderPartial,
127
+ renderStream
128
+ };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=install.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"install.d.ts","sourceRoot":"","sources":["../src/install.ts"],"names":[],"mappings":""}
@@ -0,0 +1,23 @@
1
+ import fs from "node:fs";
2
+ import { resolve, platformKey, packageName } from "./platform.js";
3
+ try {
4
+ const binPath = resolve("bin");
5
+ if (binPath && fs.existsSync(binPath)) {
6
+ process.exit(0);
7
+ }
8
+ } catch {
9
+ }
10
+ const key = platformKey();
11
+ let pkg;
12
+ try {
13
+ pkg = packageName();
14
+ } catch {
15
+ console.warn(
16
+ `[webui] Warning: Unsupported platform ${key}. The webui CLI will not be available. Set WEBUI_BINARY_PATH to use a custom binary.`
17
+ );
18
+ process.exit(0);
19
+ }
20
+ console.warn(
21
+ `[webui] Warning: Platform package ${pkg} was not installed. This usually means your package manager was run with --no-optional. The webui CLI and native addon will not be available.
22
+ To fix: reinstall without --no-optional, or set WEBUI_BINARY_PATH.`
23
+ );
@@ -0,0 +1,11 @@
1
+ export declare function platformKey(): string;
2
+ export declare function packageName(): string;
3
+ /**
4
+ * Resolve a file from the platform-specific package, with fallback to
5
+ * local cargo build output for workspace development.
6
+ *
7
+ * @param kind — "bin" for CLI binary, "addon" for .node file
8
+ * @returns Absolute path, or null if not found.
9
+ */
10
+ export declare function resolve(kind: "bin" | "addon"): string | null;
11
+ //# sourceMappingURL=platform.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"platform.d.ts","sourceRoot":"","sources":["../src/platform.ts"],"names":[],"mappings":"AA2BA,wBAAgB,WAAW,IAAI,MAAM,CAEpC;AAED,wBAAgB,WAAW,IAAI,MAAM,CAUpC;AAED;;;;;;GAMG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,KAAK,GAAG,OAAO,GAAG,MAAM,GAAG,IAAI,CA+C5D"}
@@ -0,0 +1,75 @@
1
+ import { createRequire } from "node:module";
2
+ import { existsSync } from "node:fs";
3
+ import os from "node:os";
4
+ import path from "node:path";
5
+ import { fileURLToPath } from "node:url";
6
+ const require2 = createRequire(import.meta.url);
7
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
8
+ const PLATFORMS = {
9
+ "darwin-arm64": "@microsoft/webui-darwin-arm64",
10
+ "darwin-x64": "@microsoft/webui-darwin-x64",
11
+ "linux-x64": "@microsoft/webui-linux-x64",
12
+ "linux-arm64": "@microsoft/webui-linux-arm64",
13
+ "win32-x64": "@microsoft/webui-win32-x64",
14
+ "win32-arm64": "@microsoft/webui-win32-arm64"
15
+ };
16
+ const ADDON_NAMES = {
17
+ darwin: "libwebui_node.dylib",
18
+ linux: "libwebui_node.so",
19
+ win32: "webui_node.dll"
20
+ };
21
+ function platformKey() {
22
+ return `${process.platform}-${os.arch()}`;
23
+ }
24
+ function packageName() {
25
+ const key = platformKey();
26
+ const name = PLATFORMS[key];
27
+ if (!name) {
28
+ throw new Error(
29
+ `[webui] Unsupported platform: ${key}. Supported: ${Object.keys(PLATFORMS).join(", ")}`
30
+ );
31
+ }
32
+ return name;
33
+ }
34
+ function resolve(kind) {
35
+ if (kind === "bin" && process.env["WEBUI_BINARY_PATH"]) {
36
+ return process.env["WEBUI_BINARY_PATH"];
37
+ }
38
+ if (kind === "addon" && process.env["WEBUI_ADDON_PATH"]) {
39
+ return process.env["WEBUI_ADDON_PATH"];
40
+ }
41
+ try {
42
+ const pkg = packageName();
43
+ const pkgDir = path.dirname(require2.resolve(`${pkg}/package.json`));
44
+ if (kind === "bin") {
45
+ const binName = process.platform === "win32" ? "webui.exe" : "webui";
46
+ const binPath = path.join(pkgDir, "bin", binName);
47
+ if (existsSync(binPath)) return binPath;
48
+ } else {
49
+ const addonPath = path.join(pkgDir, "webui.node");
50
+ if (existsSync(addonPath)) return addonPath;
51
+ }
52
+ } catch {
53
+ }
54
+ const workspaceRoot = path.resolve(__dirname, "..", "..", "..");
55
+ const releasePath = path.join(workspaceRoot, "target", "release");
56
+ if (kind === "bin") {
57
+ const binName = process.platform === "win32" ? "webui.exe" : "webui";
58
+ const binPath = path.join(releasePath, binName);
59
+ if (existsSync(binPath)) return binPath;
60
+ const debugPath = path.join(workspaceRoot, "target", "debug", binName);
61
+ if (existsSync(debugPath)) return debugPath;
62
+ } else {
63
+ const addonName = ADDON_NAMES[process.platform] ?? "libwebui_node.so";
64
+ const addonPath = path.join(releasePath, addonName);
65
+ if (existsSync(addonPath)) return addonPath;
66
+ const debugPath = path.join(workspaceRoot, "target", "debug", addonName);
67
+ if (existsSync(debugPath)) return debugPath;
68
+ }
69
+ return null;
70
+ }
71
+ export {
72
+ packageName,
73
+ platformKey,
74
+ resolve
75
+ };
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "bin": {
3
+ "webui": "bin/webui"
4
+ },
5
+ "description": "WebUI — high-performance server-side rendering framework. Build-time protocol compiler and streaming renderer.",
6
+ "devDependencies": {
7
+ "@types/node": "^25.3.5",
8
+ "esbuild": "^0.27.3",
9
+ "typescript": "^5.9.3"
10
+ },
11
+ "engines": {
12
+ "node": ">=18"
13
+ },
14
+ "exports": {
15
+ ".": {
16
+ "import": {
17
+ "default": "./dist/index.js",
18
+ "types": "./dist/index.d.ts"
19
+ }
20
+ }
21
+ },
22
+ "files": [
23
+ "bin/",
24
+ "dist/",
25
+ "wasm/"
26
+ ],
27
+ "license": "MIT",
28
+ "name": "@microsoft/webui",
29
+ "optionalDependencies": {
30
+ "@microsoft/webui-darwin-arm64": "0.0.1",
31
+ "@microsoft/webui-darwin-x64": "0.0.1",
32
+ "@microsoft/webui-linux-arm64": "0.0.1",
33
+ "@microsoft/webui-linux-x64": "0.0.1",
34
+ "@microsoft/webui-win32-arm64": "0.0.1",
35
+ "@microsoft/webui-win32-x64": "0.0.1"
36
+ },
37
+ "repository": {
38
+ "type": "git",
39
+ "url": "https://github.com/nicolo-ribaudo/nicolo-nicolo.git"
40
+ },
41
+ "type": "module",
42
+ "version": "0.0.1",
43
+ "scripts": {
44
+ "build": "esbuild src/index.ts src/platform.ts src/install.ts --outdir=dist --format=esm --platform=node && tsc --emitDeclarationOnly",
45
+ "postinstall": "node --input-type=module -e \"try{await import('./dist/install.js')}catch{}\"",
46
+ "test": "esbuild test/integration.test.ts --outfile=test/integration.test.js --format=esm --platform=node && node --test test/integration.test.js"
47
+ }
48
+ }
package/wasm/.gitkeep ADDED
File without changes