@moriajs/renderer 0.1.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/.turbo/turbo-build.log +4 -0
- package/.turbo/turbo-typecheck.log +10 -0
- package/LICENSE +21 -0
- package/dist/index.d.ts +55 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +85 -0
- package/dist/index.js.map +1 -0
- package/package.json +47 -0
- package/src/index.ts +110 -0
- package/tsconfig.json +14 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
|
|
2
|
+
> @moriajs/renderer@0.0.1 typecheck C:\Codes\node\2026\github\moriajs\packages\renderer
|
|
3
|
+
> tsc --noEmit
|
|
4
|
+
|
|
5
|
+
src/index.ts(46,34): error TS7016: Could not find a declaration file for module 'mithril-node-render'. 'C:/Codes/node/2026/github/moriajs/node_modules/.pnpm/mithril-node-render@3.0.2_mithril@2.3.8/node_modules/mithril-node-render/index.js' implicitly has an 'any' type.
|
|
6
|
+
Try `npm i --save-dev @types/mithril-node-render` if it exists or add a new declaration (.d.ts) file containing `declare module 'mithril-node-render';`
|
|
7
|
+
src/index.ts(89,58): error TS2304: Cannot find name 'Element'.
|
|
8
|
+
src/index.ts(99,16): error TS2304: Cannot find name 'window'.
|
|
9
|
+
src/index.ts(100,17): error TS2304: Cannot find name 'window'.
|
|
10
|
+
ELIFECYCLE Command failed with exit code 2.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Guntur D
|
|
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.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @moriajs/renderer
|
|
3
|
+
*
|
|
4
|
+
* Hybrid SSR/CSR rendering engine for Mithril.js.
|
|
5
|
+
* Provides server-side rendering with mithril-node-render
|
|
6
|
+
* and client-side hydration.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Options for rendering a page.
|
|
10
|
+
*/
|
|
11
|
+
export interface RenderOptions {
|
|
12
|
+
/** Page title */
|
|
13
|
+
title?: string;
|
|
14
|
+
/** Meta tags for the page head */
|
|
15
|
+
meta?: Record<string, string>;
|
|
16
|
+
/** Initial data to hydrate on the client */
|
|
17
|
+
initialData?: Record<string, unknown>;
|
|
18
|
+
/** HTML lang attribute */
|
|
19
|
+
lang?: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Render a Mithril component to an HTML string (server-side).
|
|
23
|
+
*
|
|
24
|
+
* Uses mithril-node-render to produce static HTML from Mithril vnodes.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* import { renderToString } from '@moriajs/renderer';
|
|
29
|
+
* import MyPage from './pages/Home.js';
|
|
30
|
+
*
|
|
31
|
+
* const html = await renderToString(MyPage, {
|
|
32
|
+
* title: 'Home — My App',
|
|
33
|
+
* initialData: { user: { name: 'Guntur' } },
|
|
34
|
+
* });
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export declare function renderToString(component: any, options?: RenderOptions): Promise<string>;
|
|
38
|
+
/**
|
|
39
|
+
* Hydrate a server-rendered Mithril component on the client.
|
|
40
|
+
* Call this in your entry-client.ts.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* import { hydrate } from '@moriajs/renderer';
|
|
45
|
+
* import App from './App.js';
|
|
46
|
+
*
|
|
47
|
+
* hydrate(App, document.getElementById('app')!);
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export declare function hydrate(component: any, container: Element): Promise<void>;
|
|
51
|
+
/**
|
|
52
|
+
* Get hydration data injected by the server.
|
|
53
|
+
*/
|
|
54
|
+
export declare function getHydrationData<T = Record<string, unknown>>(): T | undefined;
|
|
55
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;GAEG;AACH,MAAM,WAAW,aAAa;IAC1B,iBAAiB;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,kCAAkC;IAClC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9B,4CAA4C;IAC5C,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACtC,0BAA0B;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,cAAc,CAEhC,SAAS,EAAE,GAAG,EACd,OAAO,GAAE,aAAkB,GAC5B,OAAO,CAAC,MAAM,CAAC,CAkCjB;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,OAAO,CAEzB,SAAS,EAAE,GAAG,EACd,SAAS,EAAE,OAAO,GACnB,OAAO,CAAC,IAAI,CAAC,CAIf;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,CAAC,GAAG,SAAS,CAM7E"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @moriajs/renderer
|
|
3
|
+
*
|
|
4
|
+
* Hybrid SSR/CSR rendering engine for Mithril.js.
|
|
5
|
+
* Provides server-side rendering with mithril-node-render
|
|
6
|
+
* and client-side hydration.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Render a Mithril component to an HTML string (server-side).
|
|
10
|
+
*
|
|
11
|
+
* Uses mithril-node-render to produce static HTML from Mithril vnodes.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* import { renderToString } from '@moriajs/renderer';
|
|
16
|
+
* import MyPage from './pages/Home.js';
|
|
17
|
+
*
|
|
18
|
+
* const html = await renderToString(MyPage, {
|
|
19
|
+
* title: 'Home — My App',
|
|
20
|
+
* initialData: { user: { name: 'Guntur' } },
|
|
21
|
+
* });
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export async function renderToString(
|
|
25
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
26
|
+
component, options = {}) {
|
|
27
|
+
// mithril-node-render has no type declarations — use string import
|
|
28
|
+
const renderModule = await Function('return import("mithril-node-render")')();
|
|
29
|
+
const mModule = await Function('return import("mithril")')();
|
|
30
|
+
const render = renderModule.default;
|
|
31
|
+
const m = mModule.default;
|
|
32
|
+
const componentHtml = await render(m(component));
|
|
33
|
+
const metaTags = options.meta
|
|
34
|
+
? Object.entries(options.meta)
|
|
35
|
+
.map(([name, content]) => `<meta name="${name}" content="${content}">`)
|
|
36
|
+
.join('\n ')
|
|
37
|
+
: '';
|
|
38
|
+
const hydrationScript = options.initialData
|
|
39
|
+
? `<script>window.__MORIA_DATA__ = ${JSON.stringify(options.initialData)};</script>`
|
|
40
|
+
: '';
|
|
41
|
+
return `<!DOCTYPE html>
|
|
42
|
+
<html lang="${options.lang ?? 'en'}">
|
|
43
|
+
<head>
|
|
44
|
+
<meta charset="UTF-8">
|
|
45
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
46
|
+
${metaTags}
|
|
47
|
+
<title>${options.title ?? 'MoriaJS App'}</title>
|
|
48
|
+
</head>
|
|
49
|
+
<body>
|
|
50
|
+
<div id="app">${componentHtml}</div>
|
|
51
|
+
${hydrationScript}
|
|
52
|
+
<script type="module" src="/src/entry-client.ts"></script>
|
|
53
|
+
</body>
|
|
54
|
+
</html>`;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Hydrate a server-rendered Mithril component on the client.
|
|
58
|
+
* Call this in your entry-client.ts.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```ts
|
|
62
|
+
* import { hydrate } from '@moriajs/renderer';
|
|
63
|
+
* import App from './App.js';
|
|
64
|
+
*
|
|
65
|
+
* hydrate(App, document.getElementById('app')!);
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export async function hydrate(
|
|
69
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
70
|
+
component, container) {
|
|
71
|
+
const mModule = await import('mithril');
|
|
72
|
+
const m = mModule.default;
|
|
73
|
+
m.mount(container, component);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Get hydration data injected by the server.
|
|
77
|
+
*/
|
|
78
|
+
export function getHydrationData() {
|
|
79
|
+
if (typeof window !== 'undefined') {
|
|
80
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
81
|
+
return window.__MORIA_DATA__;
|
|
82
|
+
}
|
|
83
|
+
return undefined;
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAgBH;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc;AAChC,8DAA8D;AAC9D,SAAc,EACd,UAAyB,EAAE;IAE3B,mEAAmE;IACnE,MAAM,YAAY,GAAG,MAAO,QAAQ,CAAC,sCAAsC,CAAC,EAAgE,CAAC;IAC7I,MAAM,OAAO,GAAG,MAAO,QAAQ,CAAC,0BAA0B,CAAC,EAAsD,CAAC;IAElH,MAAM,MAAM,GAAG,YAAY,CAAC,OAAO,CAAC;IACpC,MAAM,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC;IAE1B,MAAM,aAAa,GAAG,MAAM,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;IAEjD,MAAM,QAAQ,GAAG,OAAO,CAAC,IAAI;QACzB,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC;aACzB,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,OAAO,CAAC,EAAE,EAAE,CAAC,eAAe,IAAI,cAAc,OAAO,IAAI,CAAC;aACtE,IAAI,CAAC,QAAQ,CAAC;QACnB,CAAC,CAAC,EAAE,CAAC;IAET,MAAM,eAAe,GAAG,OAAO,CAAC,WAAW;QACvC,CAAC,CAAC,mCAAmC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,WAAW,CAAC,YAAY;QACpF,CAAC,CAAC,EAAE,CAAC;IAET,OAAO;cACG,OAAO,CAAC,IAAI,IAAI,IAAI;;;;MAI5B,QAAQ;aACD,OAAO,CAAC,KAAK,IAAI,aAAa;;;oBAGvB,aAAa;MAC3B,eAAe;;;QAGb,CAAC;AACT,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,KAAK,UAAU,OAAO;AACzB,8DAA8D;AAC9D,SAAc,EACd,SAAkB;IAElB,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,SAAS,CAAC,CAAC;IACxC,MAAM,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC;IAC1B,CAAC,CAAC,KAAK,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;AAClC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB;IAC5B,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;QAChC,8DAA8D;QAC9D,OAAQ,MAAc,CAAC,cAA+B,CAAC;IAC3D,CAAC;IACD,OAAO,SAAS,CAAC;AACrB,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@moriajs/renderer",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "MoriaJS renderer — Mithril.js SSR/CSR hybrid rendering engine",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"mithril": "^2.2.0",
|
|
16
|
+
"mithril-node-render": "^3.0.0"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"typescript": "^5.7.0",
|
|
20
|
+
"rimraf": "^6.0.0",
|
|
21
|
+
"@types/mithril": "^2.2.0",
|
|
22
|
+
"@types/node": "^22.0.0"
|
|
23
|
+
},
|
|
24
|
+
"peerDependencies": {
|
|
25
|
+
"@moriajs/core": "0.1.1"
|
|
26
|
+
},
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"author": "Guntur-D <guntur.d.npm@gmail.com>",
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "git+https://github.com/guntur-d/moriajs.git",
|
|
32
|
+
"directory": "packages/renderer"
|
|
33
|
+
},
|
|
34
|
+
"homepage": "https://github.com/guntur-d/moriajs/tree/main/packages/renderer#readme",
|
|
35
|
+
"bugs": {
|
|
36
|
+
"url": "https://github.com/guntur-d/moriajs/issues"
|
|
37
|
+
},
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build": "tsc",
|
|
43
|
+
"dev": "tsc --watch",
|
|
44
|
+
"typecheck": "tsc --noEmit",
|
|
45
|
+
"clean": "rimraf dist .turbo"
|
|
46
|
+
}
|
|
47
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @moriajs/renderer
|
|
3
|
+
*
|
|
4
|
+
* Hybrid SSR/CSR rendering engine for Mithril.js.
|
|
5
|
+
* Provides server-side rendering with mithril-node-render
|
|
6
|
+
* and client-side hydration.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Options for rendering a page.
|
|
11
|
+
*/
|
|
12
|
+
export interface RenderOptions {
|
|
13
|
+
/** Page title */
|
|
14
|
+
title?: string;
|
|
15
|
+
/** Meta tags for the page head */
|
|
16
|
+
meta?: Record<string, string>;
|
|
17
|
+
/** Initial data to hydrate on the client */
|
|
18
|
+
initialData?: Record<string, unknown>;
|
|
19
|
+
/** HTML lang attribute */
|
|
20
|
+
lang?: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Render a Mithril component to an HTML string (server-side).
|
|
25
|
+
*
|
|
26
|
+
* Uses mithril-node-render to produce static HTML from Mithril vnodes.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* import { renderToString } from '@moriajs/renderer';
|
|
31
|
+
* import MyPage from './pages/Home.js';
|
|
32
|
+
*
|
|
33
|
+
* const html = await renderToString(MyPage, {
|
|
34
|
+
* title: 'Home — My App',
|
|
35
|
+
* initialData: { user: { name: 'Guntur' } },
|
|
36
|
+
* });
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export async function renderToString(
|
|
40
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
41
|
+
component: any,
|
|
42
|
+
options: RenderOptions = {}
|
|
43
|
+
): Promise<string> {
|
|
44
|
+
// mithril-node-render has no type declarations — use string import
|
|
45
|
+
const renderModule = await (Function('return import("mithril-node-render")')() as Promise<{ default: (vnode: unknown) => Promise<string> }>);
|
|
46
|
+
const mModule = await (Function('return import("mithril")')() as Promise<{ default: (tag: unknown) => unknown }>);
|
|
47
|
+
|
|
48
|
+
const render = renderModule.default;
|
|
49
|
+
const m = mModule.default;
|
|
50
|
+
|
|
51
|
+
const componentHtml = await render(m(component));
|
|
52
|
+
|
|
53
|
+
const metaTags = options.meta
|
|
54
|
+
? Object.entries(options.meta)
|
|
55
|
+
.map(([name, content]) => `<meta name="${name}" content="${content}">`)
|
|
56
|
+
.join('\n ')
|
|
57
|
+
: '';
|
|
58
|
+
|
|
59
|
+
const hydrationScript = options.initialData
|
|
60
|
+
? `<script>window.__MORIA_DATA__ = ${JSON.stringify(options.initialData)};</script>`
|
|
61
|
+
: '';
|
|
62
|
+
|
|
63
|
+
return `<!DOCTYPE html>
|
|
64
|
+
<html lang="${options.lang ?? 'en'}">
|
|
65
|
+
<head>
|
|
66
|
+
<meta charset="UTF-8">
|
|
67
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
68
|
+
${metaTags}
|
|
69
|
+
<title>${options.title ?? 'MoriaJS App'}</title>
|
|
70
|
+
</head>
|
|
71
|
+
<body>
|
|
72
|
+
<div id="app">${componentHtml}</div>
|
|
73
|
+
${hydrationScript}
|
|
74
|
+
<script type="module" src="/src/entry-client.ts"></script>
|
|
75
|
+
</body>
|
|
76
|
+
</html>`;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Hydrate a server-rendered Mithril component on the client.
|
|
81
|
+
* Call this in your entry-client.ts.
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```ts
|
|
85
|
+
* import { hydrate } from '@moriajs/renderer';
|
|
86
|
+
* import App from './App.js';
|
|
87
|
+
*
|
|
88
|
+
* hydrate(App, document.getElementById('app')!);
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
export async function hydrate(
|
|
92
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
93
|
+
component: any,
|
|
94
|
+
container: Element
|
|
95
|
+
): Promise<void> {
|
|
96
|
+
const mModule = await import('mithril');
|
|
97
|
+
const m = mModule.default;
|
|
98
|
+
m.mount(container, component);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Get hydration data injected by the server.
|
|
103
|
+
*/
|
|
104
|
+
export function getHydrationData<T = Record<string, unknown>>(): T | undefined {
|
|
105
|
+
if (typeof window !== 'undefined') {
|
|
106
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
107
|
+
return (window as any).__MORIA_DATA__ as T | undefined;
|
|
108
|
+
}
|
|
109
|
+
return undefined;
|
|
110
|
+
}
|