@tyndall/webcomponents 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/README.md ADDED
@@ -0,0 +1,26 @@
1
+ # @tyndall/webcomponents
2
+
3
+ ## Overview
4
+ Web Components adapter package implementing framework UIAdapter contracts without React dependencies.
5
+
6
+ ## Responsibilities
7
+ - Provide Web Components adapter, factory, and registry
8
+ - Keep renderer behavior deterministic and contract-compliant
9
+
10
+ ## Public API Highlights
11
+ - createWebComponentsAdapter
12
+ - createWebComponentsAdapterRegistry
13
+
14
+ ## Development
15
+ - Build: bun run --filter @tyndall/webcomponents build
16
+ - Test (from workspace root): bun test
17
+
18
+ ## Documentation
19
+ - Package specification: [spec.md](./spec.md)
20
+ - Package architecture: [architecture.md](./architecture.md)
21
+ - Package changes: [CHANGELOG.md](./CHANGELOG.md)
22
+
23
+ ## Maintenance Rules
24
+ - Keep this document aligned with implemented package behavior.
25
+ - Update spec.md and architecture.md whenever package contracts or design boundaries change.
26
+ - Record user-visible package changes in CHANGELOG.md.
@@ -0,0 +1,12 @@
1
+ import type { HeadDescriptor, HmrIntegration, UIAdapter, UIAdapterEntryContext, UIAdapterRenderContext, UIAdapterRenderResult } from "@tyndall/core";
2
+ export interface WebComponentsAdapterOptions {
3
+ name?: string;
4
+ createClientEntry?: (ctx: UIAdapterEntryContext) => string;
5
+ createServerEntry?: (ctx: UIAdapterEntryContext) => string;
6
+ renderToHtml?: (ctx: UIAdapterRenderContext) => Promise<UIAdapterRenderResult> | UIAdapterRenderResult;
7
+ render?: (ctx: UIAdapterRenderContext) => Promise<unknown> | unknown;
8
+ getHead?: (ctx: UIAdapterRenderContext) => HeadDescriptor;
9
+ hmrIntegration?: HmrIntegration;
10
+ }
11
+ export declare const createWebComponentsAdapter: (options?: WebComponentsAdapterOptions) => UIAdapter;
12
+ //# sourceMappingURL=adapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,cAAc,EACd,SAAS,EACT,qBAAqB,EACrB,sBAAsB,EACtB,qBAAqB,EACtB,MAAM,eAAe,CAAC;AAGvB,MAAM,WAAW,2BAA2B;IAC1C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,iBAAiB,CAAC,EAAE,CAAC,GAAG,EAAE,qBAAqB,KAAK,MAAM,CAAC;IAC3D,iBAAiB,CAAC,EAAE,CAAC,GAAG,EAAE,qBAAqB,KAAK,MAAM,CAAC;IAC3D,YAAY,CAAC,EAAE,CACb,GAAG,EAAE,sBAAsB,KACxB,OAAO,CAAC,qBAAqB,CAAC,GAAG,qBAAqB,CAAC;IAC5D,MAAM,CAAC,EAAE,CAAC,GAAG,EAAE,sBAAsB,KAAK,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC;IACrE,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,sBAAsB,KAAK,cAAc,CAAC;IAC1D,cAAc,CAAC,EAAE,cAAc,CAAC;CACjC;AAyED,eAAO,MAAM,0BAA0B,GACrC,UAAS,2BAAgC,KACxC,SAQD,CAAC"}
@@ -0,0 +1,69 @@
1
+ import { mergeHeadDescriptors, serializeProps } from "@tyndall/core";
2
+ const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
3
+ const resolvePageImport = (ctx) => {
4
+ const options = ctx.uiOptions ?? ctx.adapterOptions;
5
+ const pageModule = options?.pageModule;
6
+ const specifier = typeof pageModule === "string" ? pageModule : "./page";
7
+ return JSON.stringify(specifier);
8
+ };
9
+ const normalizeRenderResult = (value) => {
10
+ if (typeof value === "string") {
11
+ return { html: value };
12
+ }
13
+ if (isRecord(value) && typeof value.html === "string") {
14
+ return {
15
+ html: value.html,
16
+ head: isRecord(value.head) ? value.head : undefined,
17
+ status: typeof value.status === "number" ? value.status : undefined,
18
+ headers: isRecord(value.headers)
19
+ ? Object.fromEntries(Object.entries(value.headers).map(([key, header]) => [key, String(header)]))
20
+ : undefined,
21
+ };
22
+ }
23
+ return { html: String(value ?? "") };
24
+ };
25
+ const defaultClientEntry = (ctx) => {
26
+ const pageImport = resolvePageImport(ctx);
27
+ return [
28
+ `import Page from ${pageImport};`,
29
+ "if (Page && typeof Page.register === \"function\") {",
30
+ " Page.register();",
31
+ "}",
32
+ ].join("\n");
33
+ };
34
+ const defaultServerEntry = (ctx) => {
35
+ const pageImport = resolvePageImport(ctx);
36
+ return [
37
+ `import Page from ${pageImport};`,
38
+ "export const renderToHtml = async (ctx) => {",
39
+ " if (Page && typeof Page.render === \"function\") {",
40
+ " const html = await Page.render(ctx.props ?? {});",
41
+ " return { html: typeof html === \"string\" ? html : String(html ?? \"\") };",
42
+ " }",
43
+ " return { html: `<div data-hyper-webcomponents=\\\"true\\\">${ctx.routeId}</div>` };",
44
+ "};",
45
+ ].join("\n");
46
+ };
47
+ const defaultRenderToHtml = async (ctx, options) => {
48
+ if (!options.render) {
49
+ return { html: `<div data-hyper-webcomponents=\"true\">${ctx.routeId}</div>` };
50
+ }
51
+ const rendered = await options.render(ctx);
52
+ const normalized = normalizeRenderResult(rendered);
53
+ const providedHead = options.getHead?.(ctx);
54
+ // Adapter-level getHead should be able to override route-level defaults.
55
+ const head = mergeHeadDescriptors(normalized.head ?? {}, providedHead ?? {});
56
+ return {
57
+ ...normalized,
58
+ head,
59
+ };
60
+ };
61
+ export const createWebComponentsAdapter = (options = {}) => ({
62
+ name: options.name ?? "webcomponents",
63
+ createClientEntry: options.createClientEntry ?? defaultClientEntry,
64
+ createServerEntry: options.createServerEntry ?? defaultServerEntry,
65
+ renderToHtml: options.renderToHtml ?? ((ctx) => defaultRenderToHtml(ctx, options)),
66
+ serializeProps,
67
+ getHead: options.getHead,
68
+ hmrIntegration: options.hmrIntegration,
69
+ });
@@ -0,0 +1,4 @@
1
+ export { createWebComponentsAdapter } from "./adapter.js";
2
+ export type { WebComponentsAdapterOptions } from "./adapter.js";
3
+ export { createWebComponentsAdapterRegistry, createWebComponentsUiAdapterFactory, } from "./registry.js";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAC;AAC1D,YAAY,EAAE,2BAA2B,EAAE,MAAM,cAAc,CAAC;AAChE,OAAO,EACL,kCAAkC,EAClC,mCAAmC,GACpC,MAAM,eAAe,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { createWebComponentsAdapter } from "./adapter.js";
2
+ export { createWebComponentsAdapterRegistry, createWebComponentsUiAdapterFactory, } from "./registry.js";
@@ -0,0 +1,4 @@
1
+ import type { UIAdapterFactory, UIAdapterRegistry } from "@tyndall/core";
2
+ export declare const createWebComponentsUiAdapterFactory: () => UIAdapterFactory;
3
+ export declare const createWebComponentsAdapterRegistry: () => UIAdapterRegistry;
4
+ //# sourceMappingURL=registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkB,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAWzF,eAAO,MAAM,mCAAmC,QAAO,gBAiBtD,CAAC;AAEF,eAAO,MAAM,kCAAkC,QAAO,iBAEpD,CAAC"}
@@ -0,0 +1,18 @@
1
+ import { createWebComponentsAdapter } from "./adapter.js";
2
+ const isFunction = (value) => typeof value === "function";
3
+ export const createWebComponentsUiAdapterFactory = () => (options) => {
4
+ const normalized = options;
5
+ const routeRender = isFunction(normalized.routeRender)
6
+ ? normalized.routeRender
7
+ : undefined;
8
+ const routeHead = isFunction(normalized.routeHead)
9
+ ? normalized.routeHead
10
+ : undefined;
11
+ return createWebComponentsAdapter({
12
+ render: routeRender ? ({ props }) => routeRender(props) : undefined,
13
+ getHead: routeHead ? ({ props }) => routeHead(props) : undefined,
14
+ });
15
+ };
16
+ export const createWebComponentsAdapterRegistry = () => ({
17
+ webcomponents: createWebComponentsUiAdapterFactory(),
18
+ });
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "@tyndall/webcomponents",
3
+ "version": "0.0.1",
4
+ "publishConfig": {
5
+ "access": "public"
6
+ },
7
+ "type": "module",
8
+ "main": "dist/index.js",
9
+ "types": "dist/index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "bun": "./src/index.ts",
14
+ "default": "./dist/index.js"
15
+ }
16
+ },
17
+ "files": [
18
+ "dist"
19
+ ],
20
+ "scripts": {
21
+ "build": "tsc -p tsconfig.json"
22
+ },
23
+ "dependencies": {
24
+ "@tyndall/core": "workspace:*",
25
+ "@tyndall/shared": "workspace:*"
26
+ }
27
+ }