@microsoft/webui-framework 0.0.4 → 0.0.5

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.
@@ -0,0 +1,24 @@
1
+ /**
2
+ * @microsoft/webui-framework — lightweight Web Component runtime with SSR hydration.
3
+ *
4
+ * Provides a reactive base class, decorators, and hydration utilities for
5
+ * building Web Components that work with WebUI's server-side rendering pipeline.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * import { WebUIElement, observable, attr } from '@microsoft/webui-framework';
10
+ *
11
+ * class MyCounter extends WebUIElement {
12
+ * @attr count = 0;
13
+ * @observable label = 'Count';
14
+ * }
15
+ * MyCounter.define('my-counter');
16
+ * ```
17
+ *
18
+ * @packageDocumentation
19
+ */
20
+ export { WebUIElement } from './element.js';
21
+ export { observable, attr } from './decorators.js';
22
+ export { getTemplate } from './template.js';
23
+ export type { TemplateMeta } from './template.js';
24
+ export { hydrationStart, hydrationEnd } from './lifecycle.js';
package/dist/index.js ADDED
@@ -0,0 +1,12 @@
1
+ import { WebUIElement } from "./element.js";
2
+ import { observable, attr } from "./decorators.js";
3
+ import { getTemplate } from "./template.js";
4
+ import { hydrationStart, hydrationEnd } from "./lifecycle.js";
5
+ export {
6
+ WebUIElement,
7
+ attr,
8
+ getTemplate,
9
+ hydrationEnd,
10
+ hydrationStart,
11
+ observable
12
+ };
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Call before a component begins hydration.
3
+ * Increments the pending counter and (once) places the global start mark.
4
+ */
5
+ export declare function hydrationStart(): void;
6
+ /**
7
+ * Call after a component has finished hydration.
8
+ * When the last component finishes, fires the global event + measure.
9
+ */
10
+ export declare function hydrationEnd(): void;
@@ -0,0 +1,27 @@
1
+ let pendingCount = 0;
2
+ let started = false;
3
+ let completed = false;
4
+ function hydrationStart() {
5
+ if (!started) {
6
+ performance.mark("webui:hydrate:total:start");
7
+ started = true;
8
+ }
9
+ pendingCount++;
10
+ }
11
+ function hydrationEnd() {
12
+ pendingCount--;
13
+ if (pendingCount <= 0 && !completed) {
14
+ completed = true;
15
+ performance.mark("webui:hydrate:total:end");
16
+ performance.measure(
17
+ "webui:hydrate:total",
18
+ "webui:hydrate:total:start",
19
+ "webui:hydrate:total:end"
20
+ );
21
+ window.dispatchEvent(new Event("webui:hydration-complete"));
22
+ }
23
+ }
24
+ export {
25
+ hydrationEnd,
26
+ hydrationStart
27
+ };
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Template type definitions — shared across packages without pulling in
3
+ * the global `Window` augmentation from `template.ts`.
4
+ */
5
+ export type CompiledAttrPart = string | [path: string];
6
+ export type TemplateNodePath = number[];
7
+ export type TemplateSlotPath = [
8
+ parentPath: TemplateNodePath,
9
+ beforeIndex: number,
10
+ order?: number
11
+ ];
12
+ export type CompiledTextRunMeta = [slot: TemplateSlotPath, parts: CompiledAttrPart[], raw?: 1];
13
+ export type CompiledAttrGroupMeta = [
14
+ target: TemplateNodePath,
15
+ start: number,
16
+ count: number
17
+ ];
18
+ /**
19
+ * Compiled condition — a pre-compiled JS function plus the paths it references.
20
+ * The Rust compiler emits the function body at build time so the runtime
21
+ * doesn't need a condition AST interpreter.
22
+ *
23
+ * - `[0]` — evaluator function: `(resolve, scope) => boolean`
24
+ * - `[1]` — referenced paths for the reactive path index
25
+ */
26
+ export type CompiledCondition = [
27
+ fn: (v: (path: string, s?: unknown) => unknown, s?: unknown) => boolean,
28
+ paths: string[]
29
+ ];
30
+ export type CompiledConditionalMeta = [condition: CompiledCondition, blockIndex: number, slot: TemplateSlotPath];
31
+ export type CompiledAttrMeta = [name: string, kind: 0, value: string] | [name: string, kind: 1, value: string] | [name: string, kind: 2, condition: CompiledCondition] | [name: string, kind: 3, parts: CompiledAttrPart[]];
32
+ export type CompiledRepeatMeta = [collection: string, itemVar: string, blockIndex: number, slot: TemplateSlotPath];
33
+ export type CompiledEventMeta = [name: string, handler: string, needsEvent: number, target: TemplateNodePath];
34
+ export interface TemplateBlockMeta {
35
+ h: string;
36
+ tx?: CompiledTextRunMeta[];
37
+ a?: CompiledAttrMeta[];
38
+ ag?: CompiledAttrGroupMeta[];
39
+ c?: CompiledConditionalMeta[];
40
+ r?: CompiledRepeatMeta[];
41
+ e?: CompiledEventMeta[];
42
+ }
43
+ export interface TemplateMeta extends TemplateBlockMeta {
44
+ b?: TemplateBlockMeta[];
45
+ sa?: string;
46
+ re?: [string, string, number][];
47
+ /** Shadow DOM flag — when true, client-created components use shadow root. */
48
+ sd?: boolean;
49
+ }
File without changes
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Template registry — stores compiled metadata objects from the Rust compiler.
3
+ *
4
+ * Each entry is a metadata object with:
5
+ * - `h` — static HTML for the component template
6
+ * - `tx` — text runs `[slot, parts]` for text binding positions
7
+ * - `a` — attribute binding metadata
8
+ * - `ag` — attribute target groups `[path, startIndex, count]`
9
+ * - `c` — conditional blocks `[conditionAst, blockIndex]`
10
+ * - `cl` — conditional anchor slots
11
+ * - `r` — repeat/for blocks `[collection, itemVar, blockIndex]`
12
+ * - `rl` — repeat anchor slots
13
+ * - `e` — element events `[eventName, handlerName, needsEvent]`
14
+ * - `el` — event target element paths
15
+ * - `b` — nested compiled block metadata
16
+ * - `sa` — adopted stylesheet specifier for CSS module strategy
17
+ * - `sd` — shadow DOM flag for client-created components
18
+ * - `re` — root events on the host element
19
+ */
20
+ export type { CompiledAttrGroupMeta, CompiledAttrMeta, CompiledAttrPart, CompiledCondition, CompiledConditionalMeta, CompiledTextRunMeta, TemplateBlockMeta, TemplateMeta, TemplateNodePath, TemplateSlotPath, } from './template-types.js';
21
+ import type { TemplateMeta } from './template-types.js';
22
+ declare global {
23
+ interface Window {
24
+ __webui_templates?: Record<string, TemplateMeta>;
25
+ __webui_state?: Record<string, unknown>;
26
+ /** When true, all client-created components use shadow DOM. */
27
+ __webui_shadow?: boolean;
28
+ }
29
+ }
30
+ export declare function getTemplate(name: string): TemplateMeta | undefined;
@@ -0,0 +1,6 @@
1
+ function getTemplate(name) {
2
+ return window.__webui_templates?.[name];
3
+ }
4
+ export {
5
+ getTemplate
6
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@microsoft/webui-framework",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "type": "module",
5
5
  "description": "WebUI Framework Next — Preact-inspired lightweight Web Component runtime with SSR hydration. 15KB minified, compiled-template path mapping, no hydration markers.",
6
6
  "license": "MIT",
@@ -20,7 +20,7 @@
20
20
  "@types/node": "^25.3.5",
21
21
  "esbuild": "^0.27.3",
22
22
  "typescript": "^5.9.3",
23
- "@microsoft/webui-test-support": "0.0.4"
23
+ "@microsoft/webui-test-support": "0.0.5"
24
24
  },
25
25
  "scripts": {
26
26
  "build": "find src -name '*.ts' ! -name '*.test.ts' | xargs esbuild --outdir=dist --outbase=src --format=esm --platform=browser && tsc --emitDeclarationOnly",