@hedystia/astro 2.2.6 → 2.2.8
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/_virtual/_rolldown/runtime.cjs +23 -0
- package/dist/client.cjs +1 -0
- package/dist/client.cjs.map +1 -1
- package/dist/index.cjs +40 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +37 -17
- package/dist/index.mjs.map +1 -1
- package/dist/server.cjs +1 -0
- package/dist/server.cjs.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
22
|
+
//#endregion
|
|
23
|
+
exports.__toESM = __toESM;
|
package/dist/client.cjs
CHANGED
|
@@ -2,6 +2,7 @@ Object.defineProperties(exports, {
|
|
|
2
2
|
__esModule: { value: true },
|
|
3
3
|
[Symbol.toStringTag]: { value: "Module" }
|
|
4
4
|
});
|
|
5
|
+
require("./_virtual/_rolldown/runtime.cjs");
|
|
5
6
|
let _hedystia_view = require("@hedystia/view");
|
|
6
7
|
//#region src/client.ts
|
|
7
8
|
var client_default = (element) => (Component, props, slotted, { client }) => {
|
package/dist/client.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.cjs","names":[],"sources":["../src/client.ts"],"sourcesContent":["import { mount } from \"@hedystia/view\";\n\nexport default (element: HTMLElement) =>\n (Component: any, props: any, slotted: any, { client }: { client: string }) => {\n if (!element.hasAttribute(\"ssr\")) {\n return;\n }\n\n const _slots: Record<string, any> = {};\n let _slot: HTMLElement | null;\n\n if (Object.keys(slotted).length > 0) {\n if (client !== \"only\") {\n const iterator = document.createTreeWalker(element, NodeFilter.SHOW_ELEMENT, (node) => {\n if (node === element) {\n return NodeFilter.FILTER_SKIP;\n }\n if (node.nodeName === \"ASTRO-SLOT\") {\n return NodeFilter.FILTER_ACCEPT;\n }\n if (node.nodeName === \"ASTRO-ISLAND\") {\n return NodeFilter.FILTER_REJECT;\n }\n return NodeFilter.FILTER_SKIP;\n });\n let slot: HTMLElement | null;\n\n while (true) {\n slot = iterator.nextNode() as HTMLElement | null;\n if (!slot) {\n break;\n }\n\n _slots[slot.getAttribute(\"name\") || \"default\"] = slot;\n }\n }\n for (const [key, value] of Object.entries(slotted)) {\n if (_slots[key]) {\n continue;\n }\n _slots[key] = document.createElement(\"astro-slot\");\n if (key !== \"default\") {\n _slots[key].setAttribute(\"name\", key);\n }\n _slots[key].innerHTML = value;\n }\n }\n\n const { default: children, ...slots } = _slots;\n\n element.innerHTML = \"\";\n\n const app = mount(() => Component({ ...props, ...slots, children }), element);\n\n element.addEventListener(\"astro:unmount\", () => app.dispose(), { once: true });\n };\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"client.cjs","names":[],"sources":["../src/client.ts"],"sourcesContent":["import { mount } from \"@hedystia/view\";\n\nexport default (element: HTMLElement) =>\n (Component: any, props: any, slotted: any, { client }: { client: string }) => {\n if (!element.hasAttribute(\"ssr\")) {\n return;\n }\n\n const _slots: Record<string, any> = {};\n let _slot: HTMLElement | null;\n\n if (Object.keys(slotted).length > 0) {\n if (client !== \"only\") {\n const iterator = document.createTreeWalker(element, NodeFilter.SHOW_ELEMENT, (node) => {\n if (node === element) {\n return NodeFilter.FILTER_SKIP;\n }\n if (node.nodeName === \"ASTRO-SLOT\") {\n return NodeFilter.FILTER_ACCEPT;\n }\n if (node.nodeName === \"ASTRO-ISLAND\") {\n return NodeFilter.FILTER_REJECT;\n }\n return NodeFilter.FILTER_SKIP;\n });\n let slot: HTMLElement | null;\n\n while (true) {\n slot = iterator.nextNode() as HTMLElement | null;\n if (!slot) {\n break;\n }\n\n _slots[slot.getAttribute(\"name\") || \"default\"] = slot;\n }\n }\n for (const [key, value] of Object.entries(slotted)) {\n if (_slots[key]) {\n continue;\n }\n _slots[key] = document.createElement(\"astro-slot\");\n if (key !== \"default\") {\n _slots[key].setAttribute(\"name\", key);\n }\n _slots[key].innerHTML = value;\n }\n }\n\n const { default: children, ...slots } = _slots;\n\n element.innerHTML = \"\";\n\n const app = mount(() => Component({ ...props, ...slots, children }), element);\n\n element.addEventListener(\"astro:unmount\", () => app.dispose(), { once: true });\n };\n"],"mappings":";;;;;;;AAEA,IAAA,kBAAgB,aACb,WAAgB,OAAY,SAAc,EAAE,aAAiC;AAC5E,KAAI,CAAC,QAAQ,aAAa,MAAM,CAC9B;CAGF,MAAM,SAA8B,EAAE;AAGtC,KAAI,OAAO,KAAK,QAAQ,CAAC,SAAS,GAAG;AACnC,MAAI,WAAW,QAAQ;GACrB,MAAM,WAAW,SAAS,iBAAiB,SAAS,WAAW,eAAe,SAAS;AACrF,QAAI,SAAS,QACX,QAAO,WAAW;AAEpB,QAAI,KAAK,aAAa,aACpB,QAAO,WAAW;AAEpB,QAAI,KAAK,aAAa,eACpB,QAAO,WAAW;AAEpB,WAAO,WAAW;KAClB;GACF,IAAI;AAEJ,UAAO,MAAM;AACX,WAAO,SAAS,UAAU;AAC1B,QAAI,CAAC,KACH;AAGF,WAAO,KAAK,aAAa,OAAO,IAAI,aAAa;;;AAGrD,OAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,QAAQ,EAAE;AAClD,OAAI,OAAO,KACT;AAEF,UAAO,OAAO,SAAS,cAAc,aAAa;AAClD,OAAI,QAAQ,UACV,QAAO,KAAK,aAAa,QAAQ,IAAI;AAEvC,UAAO,KAAK,YAAY;;;CAI5B,MAAM,EAAE,SAAS,UAAU,GAAG,UAAU;AAExC,SAAQ,YAAY;CAEpB,MAAM,OAAA,GAAA,eAAA,aAAkB,UAAU;EAAE,GAAG;EAAO,GAAG;EAAO;EAAU,CAAC,EAAE,QAAQ;AAE7E,SAAQ,iBAAiB,uBAAuB,IAAI,SAAS,EAAE,EAAE,MAAM,MAAM,CAAC"}
|
package/dist/index.cjs
CHANGED
|
@@ -2,6 +2,12 @@ Object.defineProperties(exports, {
|
|
|
2
2
|
__esModule: { value: true },
|
|
3
3
|
[Symbol.toStringTag]: { value: "Module" }
|
|
4
4
|
});
|
|
5
|
+
const require_runtime = require("./_virtual/_rolldown/runtime.cjs");
|
|
6
|
+
let node_fs = require("node:fs");
|
|
7
|
+
node_fs = require_runtime.__toESM(node_fs);
|
|
8
|
+
let node_path = require("node:path");
|
|
9
|
+
node_path = require_runtime.__toESM(node_path);
|
|
10
|
+
let _hedystia_view_vite = require("@hedystia/view/vite");
|
|
5
11
|
//#region src/index.ts
|
|
6
12
|
function getRenderer() {
|
|
7
13
|
return {
|
|
@@ -11,30 +17,47 @@ function getRenderer() {
|
|
|
11
17
|
};
|
|
12
18
|
}
|
|
13
19
|
function src_default(options = {}) {
|
|
20
|
+
const { plugins, collectedCSS } = (0, _hedystia_view_vite.viewPlugin)(options);
|
|
14
21
|
return {
|
|
15
22
|
name: "@hedystia/astro",
|
|
16
|
-
hooks: {
|
|
17
|
-
addRenderer
|
|
18
|
-
|
|
19
|
-
|
|
23
|
+
hooks: {
|
|
24
|
+
"astro:config:setup": async ({ addRenderer, updateConfig }) => {
|
|
25
|
+
addRenderer(getRenderer());
|
|
26
|
+
updateConfig({ vite: {
|
|
27
|
+
plugins: [...plugins, configEnvironmentPlugin()],
|
|
28
|
+
ssr: { noExternal: ["@hedystia/view"] }
|
|
29
|
+
} });
|
|
30
|
+
},
|
|
31
|
+
"astro:build:done": async ({ dir }) => {
|
|
32
|
+
if (collectedCSS.size > 0) {
|
|
33
|
+
const css = Array.from(collectedCSS.values()).join("\n");
|
|
34
|
+
injectCSSIntoHTML(dir.pathname, css);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
20
38
|
};
|
|
21
39
|
}
|
|
22
|
-
function
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
40
|
+
function injectCSSIntoHTML(dir, css) {
|
|
41
|
+
const styleTag = `<style data-hedystia-css>${css}</style>`;
|
|
42
|
+
for (const file of findHTMLFiles(dir)) {
|
|
43
|
+
let content = node_fs.default.readFileSync(file, "utf-8");
|
|
44
|
+
if (content.includes("data-hedystia-css")) continue;
|
|
45
|
+
if (content.includes("</head>")) content = content.replace("</head>", `${styleTag}</head>`);
|
|
46
|
+
else content = `${styleTag}${content}`;
|
|
47
|
+
node_fs.default.writeFileSync(file, content, "utf-8");
|
|
48
|
+
}
|
|
27
49
|
}
|
|
28
|
-
function
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
} };
|
|
50
|
+
function findHTMLFiles(dir) {
|
|
51
|
+
const files = [];
|
|
52
|
+
const walk = (d) => {
|
|
53
|
+
for (const entry of node_fs.default.readdirSync(d, { withFileTypes: true })) {
|
|
54
|
+
const full = node_path.default.join(d, entry.name);
|
|
55
|
+
if (entry.isDirectory()) walk(full);
|
|
56
|
+
else if (entry.name.endsWith(".html")) files.push(full);
|
|
36
57
|
}
|
|
37
58
|
};
|
|
59
|
+
walk(dir);
|
|
60
|
+
return files;
|
|
38
61
|
}
|
|
39
62
|
function configEnvironmentPlugin() {
|
|
40
63
|
return {
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type { AstroIntegration, AstroRenderer } from \"astro\";\nimport type { Plugin, UserConfig } from \"vite\";\n\nfunction getRenderer(): AstroRenderer {\n return {\n name: \"@hedystia/astro\",\n clientEntrypoint: \"@hedystia/astro/client.js\",\n serverEntrypoint: \"@hedystia/astro/server.js\",\n };\n}\n\nexport { getRenderer as getContainerRenderer };\n\nexport interface Options {\n include?: string[];\n exclude?: string[];\n}\n\nexport default function (options: Options = {}): AstroIntegration {\n return {\n name: \"@hedystia/astro\",\n hooks: {\n \"astro:config:setup\": async ({ addRenderer, updateConfig }) => {\n addRenderer(getRenderer());\n updateConfig({\n vite:
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["fs","path"],"sources":["../src/index.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport { viewPlugin } from \"@hedystia/view/vite\";\nimport type { AstroIntegration, AstroRenderer } from \"astro\";\nimport type { Plugin, UserConfig } from \"vite\";\n\nfunction getRenderer(): AstroRenderer {\n return {\n name: \"@hedystia/astro\",\n clientEntrypoint: \"@hedystia/astro/client.js\",\n serverEntrypoint: \"@hedystia/astro/server.js\",\n };\n}\n\nexport { getRenderer as getContainerRenderer };\n\nexport interface Options {\n include?: string[];\n exclude?: string[];\n}\n\nexport default function (options: Options = {}): AstroIntegration {\n const { plugins, collectedCSS } = viewPlugin(options);\n\n return {\n name: \"@hedystia/astro\",\n hooks: {\n \"astro:config:setup\": async ({ addRenderer, updateConfig }) => {\n addRenderer(getRenderer());\n updateConfig({\n vite: {\n plugins: [...plugins, configEnvironmentPlugin()],\n ssr: {\n noExternal: [\"@hedystia/view\"],\n },\n },\n });\n },\n \"astro:build:done\": async ({ dir }) => {\n if (collectedCSS.size > 0) {\n const css = Array.from(collectedCSS.values()).join(\"\\n\");\n injectCSSIntoHTML(dir.pathname, css);\n }\n },\n },\n };\n}\n\nfunction injectCSSIntoHTML(dir: string, css: string): void {\n const styleTag = `<style data-hedystia-css>${css}</style>`;\n\n for (const file of findHTMLFiles(dir)) {\n let content = fs.readFileSync(file, \"utf-8\");\n if (content.includes(\"data-hedystia-css\")) {\n continue;\n }\n if (content.includes(\"</head>\")) {\n content = content.replace(\"</head>\", `${styleTag}</head>`);\n } else {\n content = `${styleTag}${content}`;\n }\n fs.writeFileSync(file, content, \"utf-8\");\n }\n}\n\nfunction findHTMLFiles(dir: string): string[] {\n const files: string[] = [];\n const walk = (d: string) => {\n for (const entry of fs.readdirSync(d, { withFileTypes: true })) {\n const full = path.join(d, entry.name);\n if (entry.isDirectory()) {\n walk(full);\n } else if (entry.name.endsWith(\".html\")) {\n files.push(full);\n }\n }\n };\n walk(dir);\n return files;\n}\n\nfunction configEnvironmentPlugin(): Plugin {\n return {\n name: \"@hedystia/astro:config-environment\",\n configEnvironment(environmentName: string): UserConfig | Promise<UserConfig> | undefined {\n return {\n optimizeDeps: {\n include: environmentName === \"client\" ? [\"@hedystia/astro/client.js\"] : [],\n exclude: [\"@hedystia/astro/server.js\"],\n },\n };\n },\n };\n}\n"],"mappings":";;;;;;;;;;;AAMA,SAAS,cAA6B;AACpC,QAAO;EACL,MAAM;EACN,kBAAkB;EAClB,kBAAkB;EACnB;;AAUH,SAAA,YAAyB,UAAmB,EAAE,EAAoB;CAChE,MAAM,EAAE,SAAS,kBAAA,GAAA,oBAAA,YAA4B,QAAQ;AAErD,QAAO;EACL,MAAM;EACN,OAAO;GACL,sBAAsB,OAAO,EAAE,aAAa,mBAAmB;AAC7D,gBAAY,aAAa,CAAC;AAC1B,iBAAa,EAC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
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { viewPlugin } from "@hedystia/view/vite";
|
|
1
4
|
//#region src/index.ts
|
|
2
5
|
function getRenderer() {
|
|
3
6
|
return {
|
|
@@ -7,30 +10,47 @@ function getRenderer() {
|
|
|
7
10
|
};
|
|
8
11
|
}
|
|
9
12
|
function src_default(options = {}) {
|
|
13
|
+
const { plugins, collectedCSS } = viewPlugin(options);
|
|
10
14
|
return {
|
|
11
15
|
name: "@hedystia/astro",
|
|
12
|
-
hooks: {
|
|
13
|
-
addRenderer
|
|
14
|
-
|
|
15
|
-
|
|
16
|
+
hooks: {
|
|
17
|
+
"astro:config:setup": async ({ addRenderer, updateConfig }) => {
|
|
18
|
+
addRenderer(getRenderer());
|
|
19
|
+
updateConfig({ vite: {
|
|
20
|
+
plugins: [...plugins, configEnvironmentPlugin()],
|
|
21
|
+
ssr: { noExternal: ["@hedystia/view"] }
|
|
22
|
+
} });
|
|
23
|
+
},
|
|
24
|
+
"astro:build:done": async ({ dir }) => {
|
|
25
|
+
if (collectedCSS.size > 0) {
|
|
26
|
+
const css = Array.from(collectedCSS.values()).join("\n");
|
|
27
|
+
injectCSSIntoHTML(dir.pathname, css);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
16
31
|
};
|
|
17
32
|
}
|
|
18
|
-
function
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
33
|
+
function injectCSSIntoHTML(dir, css) {
|
|
34
|
+
const styleTag = `<style data-hedystia-css>${css}</style>`;
|
|
35
|
+
for (const file of findHTMLFiles(dir)) {
|
|
36
|
+
let content = fs.readFileSync(file, "utf-8");
|
|
37
|
+
if (content.includes("data-hedystia-css")) continue;
|
|
38
|
+
if (content.includes("</head>")) content = content.replace("</head>", `${styleTag}</head>`);
|
|
39
|
+
else content = `${styleTag}${content}`;
|
|
40
|
+
fs.writeFileSync(file, content, "utf-8");
|
|
41
|
+
}
|
|
23
42
|
}
|
|
24
|
-
function
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
} };
|
|
43
|
+
function findHTMLFiles(dir) {
|
|
44
|
+
const files = [];
|
|
45
|
+
const walk = (d) => {
|
|
46
|
+
for (const entry of fs.readdirSync(d, { withFileTypes: true })) {
|
|
47
|
+
const full = path.join(d, entry.name);
|
|
48
|
+
if (entry.isDirectory()) walk(full);
|
|
49
|
+
else if (entry.name.endsWith(".html")) files.push(full);
|
|
32
50
|
}
|
|
33
51
|
};
|
|
52
|
+
walk(dir);
|
|
53
|
+
return files;
|
|
34
54
|
}
|
|
35
55
|
function configEnvironmentPlugin() {
|
|
36
56
|
return {
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type { AstroIntegration, AstroRenderer } from \"astro\";\nimport type { Plugin, UserConfig } from \"vite\";\n\nfunction getRenderer(): AstroRenderer {\n return {\n name: \"@hedystia/astro\",\n clientEntrypoint: \"@hedystia/astro/client.js\",\n serverEntrypoint: \"@hedystia/astro/server.js\",\n };\n}\n\nexport { getRenderer as getContainerRenderer };\n\nexport interface Options {\n include?: string[];\n exclude?: string[];\n}\n\nexport default function (options: Options = {}): AstroIntegration {\n return {\n name: \"@hedystia/astro\",\n hooks: {\n \"astro:config:setup\": async ({ addRenderer, updateConfig }) => {\n addRenderer(getRenderer());\n updateConfig({\n vite:
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport { viewPlugin } from \"@hedystia/view/vite\";\nimport type { AstroIntegration, AstroRenderer } from \"astro\";\nimport type { Plugin, UserConfig } from \"vite\";\n\nfunction getRenderer(): AstroRenderer {\n return {\n name: \"@hedystia/astro\",\n clientEntrypoint: \"@hedystia/astro/client.js\",\n serverEntrypoint: \"@hedystia/astro/server.js\",\n };\n}\n\nexport { getRenderer as getContainerRenderer };\n\nexport interface Options {\n include?: string[];\n exclude?: string[];\n}\n\nexport default function (options: Options = {}): AstroIntegration {\n const { plugins, collectedCSS } = viewPlugin(options);\n\n return {\n name: \"@hedystia/astro\",\n hooks: {\n \"astro:config:setup\": async ({ addRenderer, updateConfig }) => {\n addRenderer(getRenderer());\n updateConfig({\n vite: {\n plugins: [...plugins, configEnvironmentPlugin()],\n ssr: {\n noExternal: [\"@hedystia/view\"],\n },\n },\n });\n },\n \"astro:build:done\": async ({ dir }) => {\n if (collectedCSS.size > 0) {\n const css = Array.from(collectedCSS.values()).join(\"\\n\");\n injectCSSIntoHTML(dir.pathname, css);\n }\n },\n },\n };\n}\n\nfunction injectCSSIntoHTML(dir: string, css: string): void {\n const styleTag = `<style data-hedystia-css>${css}</style>`;\n\n for (const file of findHTMLFiles(dir)) {\n let content = fs.readFileSync(file, \"utf-8\");\n if (content.includes(\"data-hedystia-css\")) {\n continue;\n }\n if (content.includes(\"</head>\")) {\n content = content.replace(\"</head>\", `${styleTag}</head>`);\n } else {\n content = `${styleTag}${content}`;\n }\n fs.writeFileSync(file, content, \"utf-8\");\n }\n}\n\nfunction findHTMLFiles(dir: string): string[] {\n const files: string[] = [];\n const walk = (d: string) => {\n for (const entry of fs.readdirSync(d, { withFileTypes: true })) {\n const full = path.join(d, entry.name);\n if (entry.isDirectory()) {\n walk(full);\n } else if (entry.name.endsWith(\".html\")) {\n files.push(full);\n }\n }\n };\n walk(dir);\n return files;\n}\n\nfunction configEnvironmentPlugin(): Plugin {\n return {\n name: \"@hedystia/astro:config-environment\",\n configEnvironment(environmentName: string): UserConfig | Promise<UserConfig> | undefined {\n return {\n optimizeDeps: {\n include: environmentName === \"client\" ? [\"@hedystia/astro/client.js\"] : [],\n exclude: [\"@hedystia/astro/server.js\"],\n },\n };\n },\n };\n}\n"],"mappings":";;;;AAMA,SAAS,cAA6B;AACpC,QAA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BAAkC;AACzC,QAAO;EACL,MAAM;EACN,kBAAkB,iBAAuE;AACvF,UAAO,EACL,cAAc;IACZ,SAAS,oBAAoB,WAAW,CAAC,4BAA4B,GAAG,EAAE;IAC1E,SAAS,CAAC,4BAA4B;IACvC,EACF;;EAEJ"}
|
package/dist/server.cjs
CHANGED
|
@@ -2,6 +2,7 @@ Object.defineProperties(exports, {
|
|
|
2
2
|
__esModule: { value: true },
|
|
3
3
|
[Symbol.toStringTag]: { value: "Module" }
|
|
4
4
|
});
|
|
5
|
+
require("./_virtual/_rolldown/runtime.cjs");
|
|
5
6
|
const require_context = require("./context.cjs");
|
|
6
7
|
let _hedystia_view = require("@hedystia/view");
|
|
7
8
|
//#region src/server.ts
|
package/dist/server.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.cjs","names":["getContext","incrementId"],"sources":["../src/server.ts"],"sourcesContent":["import { renderToString } from \"@hedystia/view\";\nimport type { NamedSSRLoadedRendererValue } from \"astro\";\nimport { getContext, incrementId } from \"./context\";\nimport type { RendererContext } from \"./types\";\n\nconst slotName = (str: string) => str.trim().replace(/[-_]([a-z])/g, (_, w) => w.toUpperCase());\n\nasync function check(\n this: RendererContext,\n Component: any,\n _props: Record<string, any>,\n _children: any,\n) {\n if (typeof Component !== \"function\") {\n return false;\n }\n if (Component.name === \"QwikComponent\") {\n return false;\n }\n if (Component.toString().includes(\"$$payload\")) {\n return false;\n }\n\n try {\n const result = Component(_props);\n const html = renderToString(result);\n return typeof html === \"string\" && html.length > 0;\n } catch (e) {\n console.error(\"[@hedystia/astro] check failed:\", e);\n return false;\n }\n}\n\nasync function renderToStaticMarkup(\n this: RendererContext,\n Component: any,\n props: Record<string, any>,\n { default: children, ...slotted }: any,\n metadata?: Record<string, any>,\n) {\n const ctx = getContext(this.result);\n const renderId = metadata?.hydrate ? incrementId(ctx) : \"\";\n const needsHydrate = metadata?.astroStaticSlot ? !!metadata.hydrate : true;\n const tagName = needsHydrate ? \"astro-slot\" : \"astro-static-slot\";\n\n const slots: Record<string, string> = {};\n for (const [key, value] of Object.entries(slotted)) {\n const name = slotName(key);\n slots[name] = `<${tagName} name=\"${name}\">${value}</${tagName}>`;\n }\n\n const childrenHtml = children != null ? `<${tagName}>${children}</${tagName}>` : undefined;\n\n const newProps = {\n ...props,\n ...slots,\n children: childrenHtml,\n };\n\n const componentHtml = renderToString(Component(newProps));\n\n return {\n attrs: {\n \"data-view-render-id\": renderId,\n },\n html: componentHtml,\n };\n}\n\nconst renderer: NamedSSRLoadedRendererValue = {\n name: \"@hedystia/astro\",\n check,\n renderToStaticMarkup,\n supportsAstroStaticSlot: true,\n};\n\nexport default renderer;\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"server.cjs","names":["getContext","incrementId"],"sources":["../src/server.ts"],"sourcesContent":["import { renderToString } from \"@hedystia/view\";\nimport type { NamedSSRLoadedRendererValue } from \"astro\";\nimport { getContext, incrementId } from \"./context\";\nimport type { RendererContext } from \"./types\";\n\nconst slotName = (str: string) => str.trim().replace(/[-_]([a-z])/g, (_, w) => w.toUpperCase());\n\nasync function check(\n this: RendererContext,\n Component: any,\n _props: Record<string, any>,\n _children: any,\n) {\n if (typeof Component !== \"function\") {\n return false;\n }\n if (Component.name === \"QwikComponent\") {\n return false;\n }\n if (Component.toString().includes(\"$$payload\")) {\n return false;\n }\n\n try {\n const result = Component(_props);\n const html = renderToString(result);\n return typeof html === \"string\" && html.length > 0;\n } catch (e) {\n console.error(\"[@hedystia/astro] check failed:\", e);\n return false;\n }\n}\n\nasync function renderToStaticMarkup(\n this: RendererContext,\n Component: any,\n props: Record<string, any>,\n { default: children, ...slotted }: any,\n metadata?: Record<string, any>,\n) {\n const ctx = getContext(this.result);\n const renderId = metadata?.hydrate ? incrementId(ctx) : \"\";\n const needsHydrate = metadata?.astroStaticSlot ? !!metadata.hydrate : true;\n const tagName = needsHydrate ? \"astro-slot\" : \"astro-static-slot\";\n\n const slots: Record<string, string> = {};\n for (const [key, value] of Object.entries(slotted)) {\n const name = slotName(key);\n slots[name] = `<${tagName} name=\"${name}\">${value}</${tagName}>`;\n }\n\n const childrenHtml = children != null ? `<${tagName}>${children}</${tagName}>` : undefined;\n\n const newProps = {\n ...props,\n ...slots,\n children: childrenHtml,\n };\n\n const componentHtml = renderToString(Component(newProps));\n\n return {\n attrs: {\n \"data-view-render-id\": renderId,\n },\n html: componentHtml,\n };\n}\n\nconst renderer: NamedSSRLoadedRendererValue = {\n name: \"@hedystia/astro\",\n check,\n renderToStaticMarkup,\n supportsAstroStaticSlot: true,\n};\n\nexport default renderer;\n"],"mappings":";;;;;;;;AAKA,MAAM,YAAY,QAAgB,IAAI,MAAM,CAAC,QAAQ,iBAAiB,GAAG,MAAM,EAAE,aAAa,CAAC;AAE/F,eAAe,MAEb,WACA,QACA,WACA;AACA,KAAI,OAAO,cAAc,WACvB,QAAO;AAET,KAAI,UAAU,SAAS,gBACrB,QAAO;AAET,KAAI,UAAU,UAAU,CAAC,SAAS,YAAY,CAC5C,QAAO;AAGT,KAAI;EAEF,MAAM,QAAA,GAAA,eAAA,gBADS,UAAU,OAAO,CACG;AACnC,SAAO,OAAO,SAAS,YAAY,KAAK,SAAS;UAC1C,GAAG;AACV,UAAQ,MAAM,mCAAmC,EAAE;AACnD,SAAO;;;AAIX,eAAe,qBAEb,WACA,OACA,EAAE,SAAS,UAAU,GAAG,WACxB,UACA;CACA,MAAM,MAAMA,gBAAAA,WAAW,KAAK,OAAO;CACnC,MAAM,WAAW,UAAU,UAAUC,gBAAAA,YAAY,IAAI,GAAG;CAExD,MAAM,WADe,UAAU,kBAAkB,CAAC,CAAC,SAAS,UAAU,QACvC,eAAe;CAE9C,MAAM,QAAgC,EAAE;AACxC,MAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,QAAQ,EAAE;EAClD,MAAM,OAAO,SAAS,IAAI;AAC1B,QAAM,QAAQ,IAAI,QAAQ,SAAS,KAAK,IAAI,MAAM,IAAI,QAAQ;;CA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