@designos/renderer-html 0.0.0-stage → 0.1.0

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 CHANGED
@@ -1,3 +1,5 @@
1
- # Temporary Holding Version
1
+ # @designos/renderer-html
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Deterministic HTML artifact serializer for DesignOS `PageDocument`. Call `renderHtmlPage(data, { components })`, where each authored component maps to a tag name or `{ tag, textProp }` definition. An explicit map makes the output independent of framework compiler packages.
4
+
5
+ The serializer escapes text and attributes, omits event-handler props and dangerous URL schemes, and maps named slot children to the HTML `slot` attribute. Missing component mappings become a `div` marked with `data-designos-missing`. The optional core registry applies the shared legacy single-slot projection rule.
@@ -0,0 +1,21 @@
1
+ import { PageDocument } from '@designos/core';
2
+ import { RendererOptions } from '@designos/renderer-core';
3
+ export { NodeComposition, RenderNodeView, RendererAdapter, RendererOptions, resolveNodeComposition } from '@designos/renderer-core';
4
+
5
+ declare const rendererTarget: {
6
+ readonly id: "html";
7
+ readonly kind: "artifact";
8
+ };
9
+ interface HtmlComponentDefinition {
10
+ tag: string;
11
+ /** Optional prop to emit as escaped text content instead of an attribute. */
12
+ textProp?: string;
13
+ }
14
+ type HtmlComponentMap = Record<string, string | HtmlComponentDefinition>;
15
+ interface HtmlRenderOptions extends RendererOptions {
16
+ components: HtmlComponentMap;
17
+ }
18
+ /** Serialize a canonical PageDocument to escaped HTML using an explicit component-to-tag map. */
19
+ declare function renderHtmlPage(data: PageDocument, options: HtmlRenderOptions): string;
20
+
21
+ export { type HtmlComponentDefinition, type HtmlComponentMap, type HtmlRenderOptions, renderHtmlPage, rendererTarget };
package/dist/index.js ADDED
@@ -0,0 +1,73 @@
1
+ // src/index.ts
2
+ import { renderPageDocument as traversePageDocument } from "@designos/renderer-core";
3
+ import { resolveNodeComposition } from "@designos/renderer-core";
4
+ var rendererTarget = { id: "html", kind: "artifact" };
5
+ var VOID_TAGS = /* @__PURE__ */ new Set(["area", "base", "br", "col", "embed", "hr", "img", "input", "link", "meta", "param", "source", "track", "wbr"]);
6
+ var BOOLEAN_ATTRIBUTES = /* @__PURE__ */ new Set(["allowfullscreen", "async", "autofocus", "autoplay", "checked", "controls", "defer", "disabled", "hidden", "loop", "multiple", "muted", "open", "readonly", "required", "selected"]);
7
+ var escapeHtml = (value) => value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&#39;");
8
+ var validName = /^[A-Za-z][A-Za-z0-9:_-]*$/;
9
+ function serializeStyle(value) {
10
+ if (!value || typeof value !== "object" || Array.isArray(value)) return typeof value === "string" ? value : void 0;
11
+ const declarations = Object.entries(value).flatMap(([key, item]) => {
12
+ if (item === null || item === void 0 || typeof item === "object") return [];
13
+ const cssName = key.startsWith("--") ? key : key.replace(/[A-Z]/g, (char) => `-${char.toLowerCase()}`);
14
+ return [`${cssName}:${String(item)}`];
15
+ });
16
+ return declarations.join(";");
17
+ }
18
+ function serializeAttributes(props, textProp) {
19
+ const attributes = [];
20
+ for (const [rawName, value] of Object.entries(props)) {
21
+ if (rawName === textProp || rawName === "children" || rawName === "slots" || rawName === "key" || rawName === "ref") continue;
22
+ if (/^on[a-z]/i.test(rawName) || !validName.test(rawName)) continue;
23
+ const name = rawName === "className" ? "class" : rawName;
24
+ if (name === "style") {
25
+ const style = serializeStyle(value);
26
+ if (style) attributes.push(`style="${escapeHtml(style)}"`);
27
+ continue;
28
+ }
29
+ if (value === null || value === void 0 || typeof value === "object") continue;
30
+ if (["href", "src", "action", "formaction", "xlink:href"].includes(name.toLowerCase()) && /^\s*(?:javascript|vbscript|data):/i.test(String(value))) continue;
31
+ if (typeof value === "boolean") {
32
+ if (BOOLEAN_ATTRIBUTES.has(name.toLowerCase())) {
33
+ if (value) attributes.push(`${name}=""`);
34
+ } else if (name.startsWith("aria-") || name.startsWith("data-")) {
35
+ attributes.push(`${name}="${String(value)}"`);
36
+ }
37
+ continue;
38
+ }
39
+ attributes.push(`${name}="${escapeHtml(String(value))}"`);
40
+ }
41
+ return attributes.length ? ` ${attributes.join(" ")}` : "";
42
+ }
43
+ function definitionFor(type, components) {
44
+ const found = components[type];
45
+ const definition = typeof found === "string" ? { tag: found } : found;
46
+ return definition && validName.test(definition.tag) ? definition : { tag: "div" };
47
+ }
48
+ function renderHtmlPage(data, options) {
49
+ return traversePageDocument(data, {
50
+ renderNode(view) {
51
+ const definition = definitionFor(view.node.type, options.components);
52
+ const tag = definition.tag;
53
+ const text = definition.textProp ? view.node.props[definition.textProp] : void 0;
54
+ const textContent = typeof text === "string" || typeof text === "number" ? escapeHtml(String(text)) : "";
55
+ const descendants = [
56
+ ...view.children,
57
+ ...Object.values(view.slots).flat()
58
+ ].join("");
59
+ const children = `${textContent}${descendants}`;
60
+ const slotAttribute = view.slotName ? ` slot="${escapeHtml(view.slotName)}"` : "";
61
+ const attributes = serializeAttributes(view.node.props, definition.textProp);
62
+ const missingAttribute = options.components[view.node.type] ? "" : ` data-designos-missing="${escapeHtml(view.node.type)}"`;
63
+ if (VOID_TAGS.has(tag.toLowerCase())) return `<${tag}${attributes}${slotAttribute}${missingAttribute}>`;
64
+ return `<${tag}${attributes}${slotAttribute}${missingAttribute}>${children}</${tag}>`;
65
+ }
66
+ }, { registry: options.registry });
67
+ }
68
+ export {
69
+ renderHtmlPage,
70
+ rendererTarget,
71
+ resolveNodeComposition
72
+ };
73
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { ComponentRegistryContract, PageDocument } from \"@designos/core\";\nimport { renderPageDocument as traversePageDocument } from \"@designos/renderer-core\";\nimport type { RendererOptions } from \"@designos/renderer-core\";\n\nexport const rendererTarget = { id: \"html\", kind: \"artifact\" } as const;\n\nexport interface HtmlComponentDefinition {\n tag: string;\n /** Optional prop to emit as escaped text content instead of an attribute. */\n textProp?: string;\n}\nexport type HtmlComponentMap = Record<string, string | HtmlComponentDefinition>;\nexport interface HtmlRenderOptions extends RendererOptions {\n components: HtmlComponentMap;\n}\n\nconst VOID_TAGS = new Set([\"area\", \"base\", \"br\", \"col\", \"embed\", \"hr\", \"img\", \"input\", \"link\", \"meta\", \"param\", \"source\", \"track\", \"wbr\"]);\nconst BOOLEAN_ATTRIBUTES = new Set([\"allowfullscreen\", \"async\", \"autofocus\", \"autoplay\", \"checked\", \"controls\", \"defer\", \"disabled\", \"hidden\", \"loop\", \"multiple\", \"muted\", \"open\", \"readonly\", \"required\", \"selected\"]);\nconst escapeHtml = (value: string) => value.replaceAll(\"&\", \"&amp;\").replaceAll(\"<\", \"&lt;\").replaceAll(\">\", \"&gt;\").replaceAll('\"', \"&quot;\").replaceAll(\"'\", \"&#39;\");\nconst validName = /^[A-Za-z][A-Za-z0-9:_-]*$/;\n\nfunction serializeStyle(value: unknown): string | undefined {\n if (!value || typeof value !== \"object\" || Array.isArray(value)) return typeof value === \"string\" ? value : undefined;\n const declarations = Object.entries(value as Record<string, unknown>).flatMap(([key, item]) => {\n if (item === null || item === undefined || typeof item === \"object\") return [];\n const cssName = key.startsWith(\"--\") ? key : key.replace(/[A-Z]/g, (char) => `-${char.toLowerCase()}`);\n return [`${cssName}:${String(item)}`];\n });\n return declarations.join(\";\");\n}\n\nfunction serializeAttributes(props: Record<string, unknown>, textProp?: string): string {\n const attributes: string[] = [];\n for (const [rawName, value] of Object.entries(props)) {\n if (rawName === textProp || rawName === \"children\" || rawName === \"slots\" || rawName === \"key\" || rawName === \"ref\") continue;\n if (/^on[a-z]/i.test(rawName) || !validName.test(rawName)) continue;\n const name = rawName === \"className\" ? \"class\" : rawName;\n if (name === \"style\") {\n const style = serializeStyle(value);\n if (style) attributes.push(`style=\"${escapeHtml(style)}\"`);\n continue;\n }\n if (value === null || value === undefined || typeof value === \"object\") continue;\n if ([\"href\", \"src\", \"action\", \"formaction\", \"xlink:href\"].includes(name.toLowerCase()) && /^\\s*(?:javascript|vbscript|data):/i.test(String(value))) continue;\n if (typeof value === \"boolean\") {\n if (BOOLEAN_ATTRIBUTES.has(name.toLowerCase())) {\n if (value) attributes.push(`${name}=\"\"`);\n } else if (name.startsWith(\"aria-\") || name.startsWith(\"data-\")) {\n attributes.push(`${name}=\"${String(value)}\"`);\n }\n continue;\n }\n attributes.push(`${name}=\"${escapeHtml(String(value))}\"`);\n }\n return attributes.length ? ` ${attributes.join(\" \")}` : \"\";\n}\n\nfunction definitionFor(type: string, components: HtmlComponentMap): HtmlComponentDefinition {\n const found = components[type];\n const definition = typeof found === \"string\" ? { tag: found } : found;\n return definition && validName.test(definition.tag) ? definition : { tag: \"div\" };\n}\n\n/** Serialize a canonical PageDocument to escaped HTML using an explicit component-to-tag map. */\nexport function renderHtmlPage(data: PageDocument, options: HtmlRenderOptions): string {\n return traversePageDocument<string>(data, {\n renderNode(view) {\n const definition = definitionFor(view.node.type, options.components);\n const tag = definition.tag;\n const text = definition.textProp ? view.node.props[definition.textProp] : undefined;\n const textContent = typeof text === \"string\" || typeof text === \"number\" ? escapeHtml(String(text)) : \"\";\n const descendants = [\n ...view.children,\n ...Object.values(view.slots).flat(),\n ].join(\"\");\n const children = `${textContent}${descendants}`;\n const slotAttribute = view.slotName ? ` slot=\"${escapeHtml(view.slotName)}\"` : \"\";\n const attributes = serializeAttributes(view.node.props, definition.textProp);\n const missingAttribute = options.components[view.node.type] ? \"\" : ` data-designos-missing=\"${escapeHtml(view.node.type)}\"`;\n if (VOID_TAGS.has(tag.toLowerCase())) return `<${tag}${attributes}${slotAttribute}${missingAttribute}>`;\n return `<${tag}${attributes}${slotAttribute}${missingAttribute}>${children}</${tag}>`;\n },\n }, { registry: options.registry });\n}\n\nexport type { RendererAdapter, RendererOptions, RenderNodeView, NodeComposition } from \"@designos/renderer-core\";\nexport { resolveNodeComposition } from \"@designos/renderer-core\";\n"],"mappings":";AACA,SAAS,sBAAsB,4BAA4B;AAqF3D,SAAS,8BAA8B;AA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M,WAAW,QAAQ,IAAI;AAC1E,YAAM,cAAc,OAAO,SAAS,YAAY,OAAO,SAAS,WAAW,WAAW,OAAO,IAAI,CAAC,IAAI;AACtG,YAAM,cAAc;AAAA,QAClB,GAAG,KAAK;AAAA,QACR,GAAG,OAAO,OAAO,KAAK,KAAK,EAAE,KAAK;AAAA,MACpC,EAAE,KAAK,EAAE;AACT,YAAM,WAAW,GAAG,WAAW,GAAG,WAAW;AAC7C,YAAM,gBAAgB,KAAK,WAAW,UAAU,WAAW,KAAK,QAAQ,CAAC,MAAM;AAC/E,YAAM,aAAa,oBAAoB,KAAK,KAAK,OAAO,WAAW,QAAQ;AAC3E,YAAM,mBAAmB,QAAQ,WAAW,KAAK,KAAK,IAAI,IAAI,KAAK,2BAA2B,WAAW,KAAK,KAAK,IAAI,CAAC;AACxH,UAAI,UAAU,IAAI,IAAI,YAAY,CAAC,EAAG,QAAO,IAAI,GAAG,GAAG,UAAU,GAAG,aAAa,GAAG,gBAAgB;AACpG,aAAO,IAAI,GAAG,GAAG,UAAU,GAAG,aAAa,GAAG,gBAAgB,IAAI,QAAQ,KAAK,GAAG;AAAA,IACpF;AAAA,EACF,GAAG,EAAE,UAAU,QAAQ,SAAS,CAAC;AACnC;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,40 @@
1
1
  {
2
2
  "name": "@designos/renderer-html",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "private": false,
5
+ "type": "module",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./dist/index.d.ts",
9
+ "import": "./dist/index.js"
10
+ }
11
+ },
12
+ "dependencies": {
13
+ "@designos/core": "0.1.0",
14
+ "@designos/renderer-core": "0.1.0"
15
+ },
16
+ "devDependencies": {
17
+ "tsup": "^8.5.0",
18
+ "typescript": "^5.9.2",
19
+ "vitest": "^3.2.4"
20
+ },
21
+ "files": [
22
+ "dist",
23
+ "README.md"
24
+ ],
25
+ "main": "./dist/index.js",
26
+ "types": "./dist/index.d.ts",
27
+ "publishConfig": {
28
+ "access": "public"
29
+ },
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "git+https://github.com/relacloud/design-os.git",
33
+ "directory": "packages/renderer-html"
34
+ },
35
+ "scripts": {
36
+ "typecheck": "tsc --noEmit",
37
+ "build": "tsup",
38
+ "test": "vitest"
39
+ }
6
40
  }