@moriajs/renderer 0.1.1 → 0.3.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/.turbo/turbo-build.log +1 -1
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +21 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -4
- package/src/index.ts +29 -1
package/.turbo/turbo-build.log
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -17,6 +17,12 @@ export interface RenderOptions {
|
|
|
17
17
|
initialData?: Record<string, unknown>;
|
|
18
18
|
/** HTML lang attribute */
|
|
19
19
|
lang?: string;
|
|
20
|
+
/** Application mode — affects script injection */
|
|
21
|
+
mode?: 'development' | 'production';
|
|
22
|
+
/** Client entry point for dev mode (default: '/src/entry-client.ts') */
|
|
23
|
+
clientEntry?: string;
|
|
24
|
+
/** CSS stylesheet links to inject in the head */
|
|
25
|
+
cssLinks?: string[];
|
|
20
26
|
}
|
|
21
27
|
/**
|
|
22
28
|
* Render a Mithril component to an HTML string (server-side).
|
|
@@ -30,6 +36,7 @@ export interface RenderOptions {
|
|
|
30
36
|
*
|
|
31
37
|
* const html = await renderToString(MyPage, {
|
|
32
38
|
* title: 'Home — My App',
|
|
39
|
+
* mode: 'development',
|
|
33
40
|
* initialData: { user: { name: 'Guntur' } },
|
|
34
41
|
* });
|
|
35
42
|
* ```
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +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;
|
|
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;IACd,kDAAkD;IAClD,IAAI,CAAC,EAAE,aAAa,GAAG,YAAY,CAAC;IACpC,wEAAwE;IACxE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,iDAAiD;IACjD,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACvB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,cAAc,CAEhC,SAAS,EAAE,GAAG,EACd,OAAO,GAAE,aAAkB,GAC5B,OAAO,CAAC,MAAM,CAAC,CAuDjB;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
CHANGED
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
*
|
|
18
18
|
* const html = await renderToString(MyPage, {
|
|
19
19
|
* title: 'Home — My App',
|
|
20
|
+
* mode: 'development',
|
|
20
21
|
* initialData: { user: { name: 'Guntur' } },
|
|
21
22
|
* });
|
|
22
23
|
* ```
|
|
@@ -35,21 +36,40 @@ component, options = {}) {
|
|
|
35
36
|
.map(([name, content]) => `<meta name="${name}" content="${content}">`)
|
|
36
37
|
.join('\n ')
|
|
37
38
|
: '';
|
|
39
|
+
const cssLinkTags = options.cssLinks
|
|
40
|
+
? options.cssLinks
|
|
41
|
+
.map((href) => `<link rel="stylesheet" href="${href}">`)
|
|
42
|
+
.join('\n ')
|
|
43
|
+
: '';
|
|
38
44
|
const hydrationScript = options.initialData
|
|
39
45
|
? `<script>window.__MORIA_DATA__ = ${JSON.stringify(options.initialData)};</script>`
|
|
40
46
|
: '';
|
|
47
|
+
// Dev vs production script tags
|
|
48
|
+
const mode = options.mode ?? 'production';
|
|
49
|
+
const clientEntry = options.clientEntry ?? '/src/entry-client.ts';
|
|
50
|
+
let scriptTags;
|
|
51
|
+
if (mode === 'development') {
|
|
52
|
+
scriptTags = [
|
|
53
|
+
`<script type="module" src="/@vite/client"></script>`,
|
|
54
|
+
`<script type="module" src="${clientEntry}"></script>`,
|
|
55
|
+
].join('\n ');
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
scriptTags = `<script type="module" src="/assets/entry-client.js"></script>`;
|
|
59
|
+
}
|
|
41
60
|
return `<!DOCTYPE html>
|
|
42
61
|
<html lang="${options.lang ?? 'en'}">
|
|
43
62
|
<head>
|
|
44
63
|
<meta charset="UTF-8">
|
|
45
64
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
46
65
|
${metaTags}
|
|
66
|
+
${cssLinkTags}
|
|
47
67
|
<title>${options.title ?? 'MoriaJS App'}</title>
|
|
48
68
|
</head>
|
|
49
69
|
<body>
|
|
50
70
|
<div id="app">${componentHtml}</div>
|
|
51
71
|
${hydrationScript}
|
|
52
|
-
|
|
72
|
+
${scriptTags}
|
|
53
73
|
</body>
|
|
54
74
|
</html>`;
|
|
55
75
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAsBH;;;;;;;;;;;;;;;;GAgBG;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,WAAW,GAAG,OAAO,CAAC,QAAQ;QAChC,CAAC,CAAC,OAAO,CAAC,QAAQ;aACb,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,gCAAgC,IAAI,IAAI,CAAC;aACvD,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,gCAAgC;IAChC,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,YAAY,CAAC;IAC1C,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,IAAI,sBAAsB,CAAC;IAElE,IAAI,UAAkB,CAAC;IACvB,IAAI,IAAI,KAAK,aAAa,EAAE,CAAC;QACzB,UAAU,GAAG;YACT,qDAAqD;YACrD,8BAA8B,WAAW,aAAa;SACzD,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACrB,CAAC;SAAM,CAAC;QACJ,UAAU,GAAG,+DAA+D,CAAC;IACjF,CAAC;IAED,OAAO;cACG,OAAO,CAAC,IAAI,IAAI,IAAI;;;;MAI5B,QAAQ;MACR,WAAW;aACJ,OAAO,CAAC,KAAK,IAAI,aAAa;;;oBAGvB,aAAa;MAC3B,eAAe;MACf,UAAU;;QAER,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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moriajs/renderer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "MoriaJS renderer — Mithril.js SSR/CSR hybrid rendering engine",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -21,9 +21,6 @@
|
|
|
21
21
|
"@types/mithril": "^2.2.0",
|
|
22
22
|
"@types/node": "^22.0.0"
|
|
23
23
|
},
|
|
24
|
-
"peerDependencies": {
|
|
25
|
-
"@moriajs/core": "0.1.1"
|
|
26
|
-
},
|
|
27
24
|
"license": "MIT",
|
|
28
25
|
"author": "Guntur-D <guntur.d.npm@gmail.com>",
|
|
29
26
|
"repository": {
|
package/src/index.ts
CHANGED
|
@@ -18,6 +18,12 @@ export interface RenderOptions {
|
|
|
18
18
|
initialData?: Record<string, unknown>;
|
|
19
19
|
/** HTML lang attribute */
|
|
20
20
|
lang?: string;
|
|
21
|
+
/** Application mode — affects script injection */
|
|
22
|
+
mode?: 'development' | 'production';
|
|
23
|
+
/** Client entry point for dev mode (default: '/src/entry-client.ts') */
|
|
24
|
+
clientEntry?: string;
|
|
25
|
+
/** CSS stylesheet links to inject in the head */
|
|
26
|
+
cssLinks?: string[];
|
|
21
27
|
}
|
|
22
28
|
|
|
23
29
|
/**
|
|
@@ -32,6 +38,7 @@ export interface RenderOptions {
|
|
|
32
38
|
*
|
|
33
39
|
* const html = await renderToString(MyPage, {
|
|
34
40
|
* title: 'Home — My App',
|
|
41
|
+
* mode: 'development',
|
|
35
42
|
* initialData: { user: { name: 'Guntur' } },
|
|
36
43
|
* });
|
|
37
44
|
* ```
|
|
@@ -56,22 +63,43 @@ export async function renderToString(
|
|
|
56
63
|
.join('\n ')
|
|
57
64
|
: '';
|
|
58
65
|
|
|
66
|
+
const cssLinkTags = options.cssLinks
|
|
67
|
+
? options.cssLinks
|
|
68
|
+
.map((href) => `<link rel="stylesheet" href="${href}">`)
|
|
69
|
+
.join('\n ')
|
|
70
|
+
: '';
|
|
71
|
+
|
|
59
72
|
const hydrationScript = options.initialData
|
|
60
73
|
? `<script>window.__MORIA_DATA__ = ${JSON.stringify(options.initialData)};</script>`
|
|
61
74
|
: '';
|
|
62
75
|
|
|
76
|
+
// Dev vs production script tags
|
|
77
|
+
const mode = options.mode ?? 'production';
|
|
78
|
+
const clientEntry = options.clientEntry ?? '/src/entry-client.ts';
|
|
79
|
+
|
|
80
|
+
let scriptTags: string;
|
|
81
|
+
if (mode === 'development') {
|
|
82
|
+
scriptTags = [
|
|
83
|
+
`<script type="module" src="/@vite/client"></script>`,
|
|
84
|
+
`<script type="module" src="${clientEntry}"></script>`,
|
|
85
|
+
].join('\n ');
|
|
86
|
+
} else {
|
|
87
|
+
scriptTags = `<script type="module" src="/assets/entry-client.js"></script>`;
|
|
88
|
+
}
|
|
89
|
+
|
|
63
90
|
return `<!DOCTYPE html>
|
|
64
91
|
<html lang="${options.lang ?? 'en'}">
|
|
65
92
|
<head>
|
|
66
93
|
<meta charset="UTF-8">
|
|
67
94
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
68
95
|
${metaTags}
|
|
96
|
+
${cssLinkTags}
|
|
69
97
|
<title>${options.title ?? 'MoriaJS App'}</title>
|
|
70
98
|
</head>
|
|
71
99
|
<body>
|
|
72
100
|
<div id="app">${componentHtml}</div>
|
|
73
101
|
${hydrationScript}
|
|
74
|
-
|
|
102
|
+
${scriptTags}
|
|
75
103
|
</body>
|
|
76
104
|
</html>`;
|
|
77
105
|
}
|