@purestack/ts-render 1.1.12 → 1.1.14
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/dist/ts-render.d.mts +3 -1
- package/dist/ts-render.d.mts.map +1 -1
- package/dist/ts-render.mjs +2 -2
- package/dist/ts-render.mjs.map +1 -1
- package/package.json +5 -5
package/dist/ts-render.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! @purestack/ts-render v1.1.
|
|
1
|
+
/*! @purestack/ts-render v1.1.14 | (c) 2026 Ahmed Yasin Koculu | MIT License */
|
|
2
2
|
|
|
3
3
|
import { Component } from "regor";
|
|
4
4
|
import { PageContext } from "@purestack/ts-common";
|
|
@@ -15,6 +15,8 @@ export declare const componentRegistry: {
|
|
|
15
15
|
interface RenderAppOptions<TContext extends PageContext> {
|
|
16
16
|
/** Components for this render, on top of the registered ones. */
|
|
17
17
|
components: unknown;
|
|
18
|
+
/** Whether this render also inherits the shared component registry. */
|
|
19
|
+
inheritComponents?: boolean;
|
|
18
20
|
context: TContext;
|
|
19
21
|
/**
|
|
20
22
|
* Runs on the rendered document, before it becomes HTML. It may be async:
|
package/dist/ts-render.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ts-render.d.mts","names":[],"sources":["../src/componentRegistry.ts","../src/renderApp.ts"],"mappings":";;;qBAKa;EACX,SAAQ,cAAa,WAAa;EAGlC,aAAa,gBAAW,aAAkB;EAQ1C,UAAU,eAAe;EAGzB,iBAAgB;EAGhB;;;;UChBe,iBAAiB,iBAAiB;;EAEjD;EACA,SAAS;;;;;EAKT,cAAc,UAAU,oBAAoB;;;;;;qBAOjC,YAAa,iBAAiB,aAAW,cACxC,SACH,iBAAiB,cACzB"}
|
|
1
|
+
{"version":3,"file":"ts-render.d.mts","names":[],"sources":["../src/componentRegistry.ts","../src/renderApp.ts"],"mappings":";;;qBAKa;EACX,SAAQ,cAAa,WAAa;EAGlC,aAAa,gBAAW,aAAkB;EAQ1C,UAAU,eAAe;EAGzB,iBAAgB;EAGhB;;;;UChBe,iBAAiB,iBAAiB;;EAEjD;;EAEA;EACA,SAAS;;;;;EAKT,cAAc,UAAU,oBAAoB;;;;;;qBAOjC,YAAa,iBAAiB,aAAW,cACxC,SACH,iBAAiB,cACzB"}
|
package/dist/ts-render.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! @purestack/ts-render v1.1.
|
|
1
|
+
/*! @purestack/ts-render v1.1.14 | (c) 2026 Ahmed Yasin Koculu | MIT License */
|
|
2
2
|
|
|
3
3
|
import { isPlainObject } from "@purestack/ts-util";
|
|
4
4
|
import { runInDom } from "@purestack/ts-minidom";
|
|
@@ -66,7 +66,7 @@ const renderApp = (html, options) => {
|
|
|
66
66
|
};
|
|
67
67
|
createApp({
|
|
68
68
|
components: {
|
|
69
|
-
...componentRegistry.getAll(),
|
|
69
|
+
...options.inheritComponents === false ? {} : componentRegistry.getAll(),
|
|
70
70
|
...isPlainObject(options.components) ? options.components : {}
|
|
71
71
|
},
|
|
72
72
|
pageContext
|
package/dist/ts-render.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ts-render.mjs","names":[],"sources":["../src/componentRegistry.ts","../src/renderApp.ts"],"sourcesContent":["import { isPlainObject } from '@purestack/ts-util'\nimport type { Component } from 'regor'\n\nconst registry = new Map<string, Component<never>>()\n\nexport const componentRegistry = {\n register(name: string, component: Component<never>) {\n registry.set(name, component)\n },\n registerMany<TComponents>(...components: (TComponents | object)[]) {\n for (const compSet of components) {\n if (!isPlainObject(compSet)) continue\n for (const [name, component] of Object.entries(compSet)) {\n registry.set(name, component as Component<never>)\n }\n }\n },\n getAll(): Record<string, Component> {\n return Object.fromEntries(registry.entries())\n },\n hasComponentName(name: string) {\n return hasComponentName(name, registry)\n },\n clear() {\n registry.clear()\n },\n}\n\nfunction hasComponentName(\n input: string,\n source: Map<string, Component<never>>,\n) {\n const normalizedInput = normalizeComponentName(input)\n if (!normalizedInput) return false\n for (const key of source.keys()) {\n const normalizedKey = normalizeComponentName(key)\n if (!normalizedKey) continue\n if (normalizedKey === normalizedInput) return true\n }\n return false\n}\n\nfunction normalizeComponentName(value: string) {\n const trimmed = value.trim()\n if (!trimmed) return ''\n return trimmed.toLowerCase().replace(/[^a-z0-9]/g, '')\n}\n","import type { PageContext } from '@purestack/ts-common'\nimport { runInDom } from '@purestack/ts-minidom'\nimport { buildModalScript, buildTabsScript } from '@purestack/ts-page-scripts'\nimport { isPlainObject } from '@purestack/ts-util'\nimport { createApp } from 'regor'\nimport { componentRegistry } from './componentRegistry'\n\nexport interface RenderAppOptions<TContext extends PageContext> {\n /** Components for this render, on top of the registered ones. */\n components: unknown\n context: TContext\n /**\n * Runs on the rendered document, before it becomes HTML. It may be async:\n * the document stays this render's own until it finishes.\n */\n onRendered?: (document: Document) => void | Promise<void>\n}\n\n/**\n * Renders Regor markup to HTML in a document of its own, so renders can\n * overlap, and `onRendered` can await, without seeing each other's pages.\n */\nexport const renderApp = <TContext extends PageContext>(\n html: string,\n options: RenderAppOptions<TContext>,\n): Promise<string> => {\n const normalizedHtml = html.trimStart()\n const isDocument =\n normalizedHtml.startsWith('<!DOCTYPE html>') ||\n normalizedHtml.startsWith('<!doctype html>') ||\n normalizedHtml.startsWith('<html')\n const htmlToParse = isDocument\n ? normalizedHtml\n : `<!DOCTYPE html><html><body>${html}</body></html>`\n return runInDom(htmlToParse, async (document) => {\n const runtimeEmbeds = new Map<string, 'body' | 'head'>()\n const baseContext = options.context\n const pageContext = {\n ...baseContext,\n recordRuntimeEmbed: (name: string, position: 'body' | 'head') => {\n const normalized = name.trim().toLowerCase()\n if (normalized.length > 0) {\n runtimeEmbeds.set(normalized, position)\n }\n baseContext.recordRuntimeEmbed(name, position)\n },\n }\n createApp(\n {\n components: {\n ...componentRegistry.getAll(),\n ...(isPlainObject(options.components) ? options.components : {}),\n },\n pageContext,\n },\n {\n element: document.body,\n },\n )\n appendEmbeddedScriptsToDom(runtimeEmbeds, pageContext)\n await options.onRendered?.(document)\n if (isDocument) {\n return `<!DOCTYPE html>${document.documentElement?.outerHTML ?? ''}`\n }\n return document.body?.innerHTML ?? ''\n })\n}\n\nfunction appendEmbeddedScriptsToDom(\n runtimeEmbeds: Map<string, 'body' | 'head'>,\n context: PageContext,\n) {\n appendRuntimeScript(\n resolveTabsEmbedPosition(runtimeEmbeds, context),\n buildTabsScript,\n )\n appendRuntimeScript(\n resolveModalEmbedPosition(runtimeEmbeds, context),\n buildModalScript,\n )\n}\n\nfunction appendRuntimeScript(\n position: 'body' | 'head' | undefined,\n scriptBuilder: () => string,\n) {\n if (!position) return\n const targetParent = ensureScriptParent(position)\n if (!targetParent) return\n const script = document.createElement('script')\n script.textContent = scriptBuilder()\n targetParent.appendChild(script)\n}\n\nfunction ensureScriptParent(position: 'body' | 'head') {\n if (position === 'body') {\n return document.body\n }\n return document.head\n}\n\nfunction resolveTabsEmbedPosition(\n runtimeEmbeds: Map<string, 'body' | 'head'>,\n context: PageContext,\n) {\n const runtimePosition = runtimeEmbeds.get('tabs')\n if (runtimePosition) return runtimePosition\n return context?.pageInfo?.frontmatter?.embed?.tabs\n}\n\nfunction resolveModalEmbedPosition(\n runtimeEmbeds: Map<string, 'body' | 'head'>,\n context: PageContext,\n) {\n const runtimePosition = runtimeEmbeds.get('modal')\n if (runtimePosition) return runtimePosition\n return context?.pageInfo?.frontmatter?.embed?.modal\n}\n"],"mappings":";;;;;;AAGA,MAAM,2BAAW,IAAI,IAA8B;AAEnD,MAAa,oBAAoB;CAC/B,SAAS,MAAc,WAA6B;EAClD,SAAS,IAAI,MAAM,SAAS;CAC9B;CACA,aAA0B,GAAG,YAAsC;EACjE,KAAK,MAAM,WAAW,YAAY;GAChC,IAAI,CAAC,cAAc,OAAO,GAAG;GAC7B,KAAK,MAAM,CAAC,MAAM,cAAc,OAAO,QAAQ,OAAO,GACpD,SAAS,IAAI,MAAM,SAA6B;EAEpD;CACF;CACA,SAAoC;EAClC,OAAO,OAAO,YAAY,SAAS,QAAQ,CAAC;CAC9C;CACA,iBAAiB,MAAc;EAC7B,OAAO,iBAAiB,MAAM,QAAQ;CACxC;CACA,QAAQ;EACN,SAAS,MAAM;CACjB;AACF;AAEA,SAAS,iBACP,OACA,QACA;CACA,MAAM,kBAAkB,uBAAuB,KAAK;CACpD,IAAI,CAAC,iBAAiB,OAAO;CAC7B,KAAK,MAAM,OAAO,OAAO,KAAK,GAAG;EAC/B,MAAM,gBAAgB,uBAAuB,GAAG;EAChD,IAAI,CAAC,eAAe;EACpB,IAAI,kBAAkB,iBAAiB,OAAO;CAChD;CACA,OAAO;AACT;AAEA,SAAS,uBAAuB,OAAe;CAC7C,MAAM,UAAU,MAAM,KAAK;CAC3B,IAAI,CAAC,SAAS,OAAO;CACrB,OAAO,QAAQ,YAAY,CAAC,CAAC,QAAQ,cAAc,EAAE;AACvD;;;;;;;;
|
|
1
|
+
{"version":3,"file":"ts-render.mjs","names":[],"sources":["../src/componentRegistry.ts","../src/renderApp.ts"],"sourcesContent":["import { isPlainObject } from '@purestack/ts-util'\nimport type { Component } from 'regor'\n\nconst registry = new Map<string, Component<never>>()\n\nexport const componentRegistry = {\n register(name: string, component: Component<never>) {\n registry.set(name, component)\n },\n registerMany<TComponents>(...components: (TComponents | object)[]) {\n for (const compSet of components) {\n if (!isPlainObject(compSet)) continue\n for (const [name, component] of Object.entries(compSet)) {\n registry.set(name, component as Component<never>)\n }\n }\n },\n getAll(): Record<string, Component> {\n return Object.fromEntries(registry.entries())\n },\n hasComponentName(name: string) {\n return hasComponentName(name, registry)\n },\n clear() {\n registry.clear()\n },\n}\n\nfunction hasComponentName(\n input: string,\n source: Map<string, Component<never>>,\n) {\n const normalizedInput = normalizeComponentName(input)\n if (!normalizedInput) return false\n for (const key of source.keys()) {\n const normalizedKey = normalizeComponentName(key)\n if (!normalizedKey) continue\n if (normalizedKey === normalizedInput) return true\n }\n return false\n}\n\nfunction normalizeComponentName(value: string) {\n const trimmed = value.trim()\n if (!trimmed) return ''\n return trimmed.toLowerCase().replace(/[^a-z0-9]/g, '')\n}\n","import type { PageContext } from '@purestack/ts-common'\nimport { runInDom } from '@purestack/ts-minidom'\nimport { buildModalScript, buildTabsScript } from '@purestack/ts-page-scripts'\nimport { isPlainObject } from '@purestack/ts-util'\nimport { createApp } from 'regor'\nimport { componentRegistry } from './componentRegistry'\n\nexport interface RenderAppOptions<TContext extends PageContext> {\n /** Components for this render, on top of the registered ones. */\n components: unknown\n /** Whether this render also inherits the shared component registry. */\n inheritComponents?: boolean\n context: TContext\n /**\n * Runs on the rendered document, before it becomes HTML. It may be async:\n * the document stays this render's own until it finishes.\n */\n onRendered?: (document: Document) => void | Promise<void>\n}\n\n/**\n * Renders Regor markup to HTML in a document of its own, so renders can\n * overlap, and `onRendered` can await, without seeing each other's pages.\n */\nexport const renderApp = <TContext extends PageContext>(\n html: string,\n options: RenderAppOptions<TContext>,\n): Promise<string> => {\n const normalizedHtml = html.trimStart()\n const isDocument =\n normalizedHtml.startsWith('<!DOCTYPE html>') ||\n normalizedHtml.startsWith('<!doctype html>') ||\n normalizedHtml.startsWith('<html')\n const htmlToParse = isDocument\n ? normalizedHtml\n : `<!DOCTYPE html><html><body>${html}</body></html>`\n return runInDom(htmlToParse, async (document) => {\n const runtimeEmbeds = new Map<string, 'body' | 'head'>()\n const baseContext = options.context\n const pageContext = {\n ...baseContext,\n recordRuntimeEmbed: (name: string, position: 'body' | 'head') => {\n const normalized = name.trim().toLowerCase()\n if (normalized.length > 0) {\n runtimeEmbeds.set(normalized, position)\n }\n baseContext.recordRuntimeEmbed(name, position)\n },\n }\n createApp(\n {\n components: {\n ...(options.inheritComponents === false\n ? {}\n : componentRegistry.getAll()),\n ...(isPlainObject(options.components) ? options.components : {}),\n },\n pageContext,\n },\n {\n element: document.body,\n },\n )\n appendEmbeddedScriptsToDom(runtimeEmbeds, pageContext)\n await options.onRendered?.(document)\n if (isDocument) {\n return `<!DOCTYPE html>${document.documentElement?.outerHTML ?? ''}`\n }\n return document.body?.innerHTML ?? ''\n })\n}\n\nfunction appendEmbeddedScriptsToDom(\n runtimeEmbeds: Map<string, 'body' | 'head'>,\n context: PageContext,\n) {\n appendRuntimeScript(\n resolveTabsEmbedPosition(runtimeEmbeds, context),\n buildTabsScript,\n )\n appendRuntimeScript(\n resolveModalEmbedPosition(runtimeEmbeds, context),\n buildModalScript,\n )\n}\n\nfunction appendRuntimeScript(\n position: 'body' | 'head' | undefined,\n scriptBuilder: () => string,\n) {\n if (!position) return\n const targetParent = ensureScriptParent(position)\n if (!targetParent) return\n const script = document.createElement('script')\n script.textContent = scriptBuilder()\n targetParent.appendChild(script)\n}\n\nfunction ensureScriptParent(position: 'body' | 'head') {\n if (position === 'body') {\n return document.body\n }\n return document.head\n}\n\nfunction resolveTabsEmbedPosition(\n runtimeEmbeds: Map<string, 'body' | 'head'>,\n context: PageContext,\n) {\n const runtimePosition = runtimeEmbeds.get('tabs')\n if (runtimePosition) return runtimePosition\n return context?.pageInfo?.frontmatter?.embed?.tabs\n}\n\nfunction resolveModalEmbedPosition(\n runtimeEmbeds: Map<string, 'body' | 'head'>,\n context: PageContext,\n) {\n const runtimePosition = runtimeEmbeds.get('modal')\n if (runtimePosition) return runtimePosition\n return context?.pageInfo?.frontmatter?.embed?.modal\n}\n"],"mappings":";;;;;;AAGA,MAAM,2BAAW,IAAI,IAA8B;AAEnD,MAAa,oBAAoB;CAC/B,SAAS,MAAc,WAA6B;EAClD,SAAS,IAAI,MAAM,SAAS;CAC9B;CACA,aAA0B,GAAG,YAAsC;EACjE,KAAK,MAAM,WAAW,YAAY;GAChC,IAAI,CAAC,cAAc,OAAO,GAAG;GAC7B,KAAK,MAAM,CAAC,MAAM,cAAc,OAAO,QAAQ,OAAO,GACpD,SAAS,IAAI,MAAM,SAA6B;EAEpD;CACF;CACA,SAAoC;EAClC,OAAO,OAAO,YAAY,SAAS,QAAQ,CAAC;CAC9C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D,MAAM,QAAQ,aAAa,QAAQ;EACnC,IAAI,YACF,OAAO,kBAAkB,SAAS,iBAAiB,aAAa;EAElE,OAAO,SAAS,MAAM,aAAa;CACrC,CAAC;AACH;AAEA,SAAS,2BACP,eACA,SACA;CACA,oBACE,yBAAyB,eAAe,OAAO,GAC/C,eACF;CACA,oBACE,0BAA0B,eAAe,OAAO,GAChD,gBACF;AACF;AAEA,SAAS,oBACP,UACA,eACA;CACA,IAAI,CAAC,UAAU;CACf,MAAM,eAAe,mBAAmB,QAAQ;CAChD,IAAI,CAAC,cAAc;CACnB,MAAM,SAAS,SAAS,cAAc,QAAQ;CAC9C,OAAO,cAAc,cAAc;CACnC,aAAa,YAAY,MAAM;AACjC;AAEA,SAAS,mBAAmB,UAA2B;CACrD,IAAI,aAAa,QACf,OAAO,SAAS;CAElB,OAAO,SAAS;AAClB;AAEA,SAAS,yBACP,eACA,SACA;CACA,MAAM,kBAAkB,cAAc,IAAI,MAAM;CAChD,IAAI,iBAAiB,OAAO;CAC5B,OAAO,SAAS,UAAU,aAAa,OAAO;AAChD;AAEA,SAAS,0BACP,eACA,SACA;CACA,MAAM,kBAAkB,cAAc,IAAI,OAAO;CACjD,IAAI,iBAAiB,OAAO;CAC5B,OAAO,SAAS,UAAU,aAAa,OAAO;AAChD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@purestack/ts-render",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.14",
|
|
4
4
|
"packageManager": "yarn@4.9.2",
|
|
5
5
|
"module": "./dist/ts-render.mjs",
|
|
6
6
|
"types": "./dist/ts-render.d.mts",
|
|
@@ -39,10 +39,10 @@
|
|
|
39
39
|
"test": "vitest"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@purestack/ts-common": "^1.1.
|
|
43
|
-
"@purestack/ts-minidom": "^1.1.
|
|
44
|
-
"@purestack/ts-page-scripts": "^1.1.
|
|
45
|
-
"@purestack/ts-util": "^1.1.
|
|
42
|
+
"@purestack/ts-common": "^1.1.14",
|
|
43
|
+
"@purestack/ts-minidom": "^1.1.14",
|
|
44
|
+
"@purestack/ts-page-scripts": "^1.1.14",
|
|
45
|
+
"@purestack/ts-util": "^1.1.14",
|
|
46
46
|
"regor": "^1.7.5"
|
|
47
47
|
}
|
|
48
48
|
}
|