@hedystia/astro 2.2.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/dist/client.cjs +44 -0
- package/dist/client.cjs.map +1 -0
- package/dist/client.d.cts +8 -0
- package/dist/client.d.mts +9 -0
- package/dist/client.mjs +40 -0
- package/dist/client.mjs.map +1 -0
- package/dist/context.cjs +23 -0
- package/dist/context.cjs.map +1 -0
- package/dist/context.mjs +22 -0
- package/dist/context.mjs.map +1 -0
- package/dist/index.cjs +54 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +12 -0
- package/dist/index.d.mts +12 -0
- package/dist/index.mjs +49 -0
- package/dist/index.mjs.map +1 -0
- package/dist/server.cjs +49 -0
- package/dist/server.cjs.map +1 -0
- package/dist/server.d.cts +6 -0
- package/dist/server.d.mts +7 -0
- package/dist/server.mjs +45 -0
- package/dist/server.mjs.map +1 -0
- package/package.json +60 -0
- package/readme.md +128 -0
package/dist/client.cjs
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
4
|
+
});
|
|
5
|
+
let _hedystia_view = require("@hedystia/view");
|
|
6
|
+
//#region src/client.ts
|
|
7
|
+
var client_default = (element) => (Component, props, slotted, { client }) => {
|
|
8
|
+
if (!element.hasAttribute("ssr")) return;
|
|
9
|
+
const _slots = {};
|
|
10
|
+
if (Object.keys(slotted).length > 0) {
|
|
11
|
+
if (client !== "only") {
|
|
12
|
+
const iterator = document.createTreeWalker(element, NodeFilter.SHOW_ELEMENT, (node) => {
|
|
13
|
+
if (node === element) return NodeFilter.FILTER_SKIP;
|
|
14
|
+
if (node.nodeName === "ASTRO-SLOT") return NodeFilter.FILTER_ACCEPT;
|
|
15
|
+
if (node.nodeName === "ASTRO-ISLAND") return NodeFilter.FILTER_REJECT;
|
|
16
|
+
return NodeFilter.FILTER_SKIP;
|
|
17
|
+
});
|
|
18
|
+
let slot;
|
|
19
|
+
while (true) {
|
|
20
|
+
slot = iterator.nextNode();
|
|
21
|
+
if (!slot) break;
|
|
22
|
+
_slots[slot.getAttribute("name") || "default"] = slot;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
for (const [key, value] of Object.entries(slotted)) {
|
|
26
|
+
if (_slots[key]) continue;
|
|
27
|
+
_slots[key] = document.createElement("astro-slot");
|
|
28
|
+
if (key !== "default") _slots[key].setAttribute("name", key);
|
|
29
|
+
_slots[key].innerHTML = value;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
const { default: children, ...slots } = _slots;
|
|
33
|
+
element.innerHTML = "";
|
|
34
|
+
const app = (0, _hedystia_view.mount)(() => Component({
|
|
35
|
+
...props,
|
|
36
|
+
...slots,
|
|
37
|
+
children
|
|
38
|
+
}), element);
|
|
39
|
+
element.addEventListener("astro:unmount", () => app.dispose(), { once: true });
|
|
40
|
+
};
|
|
41
|
+
//#endregion
|
|
42
|
+
exports.default = client_default;
|
|
43
|
+
|
|
44
|
+
//# sourceMappingURL=client.cjs.map
|
|
@@ -0,0 +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":";;;;;;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/client.mjs
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { mount } from "@hedystia/view";
|
|
2
|
+
//#region src/client.ts
|
|
3
|
+
var client_default = (element) => (Component, props, slotted, { client }) => {
|
|
4
|
+
if (!element.hasAttribute("ssr")) return;
|
|
5
|
+
const _slots = {};
|
|
6
|
+
if (Object.keys(slotted).length > 0) {
|
|
7
|
+
if (client !== "only") {
|
|
8
|
+
const iterator = document.createTreeWalker(element, NodeFilter.SHOW_ELEMENT, (node) => {
|
|
9
|
+
if (node === element) return NodeFilter.FILTER_SKIP;
|
|
10
|
+
if (node.nodeName === "ASTRO-SLOT") return NodeFilter.FILTER_ACCEPT;
|
|
11
|
+
if (node.nodeName === "ASTRO-ISLAND") return NodeFilter.FILTER_REJECT;
|
|
12
|
+
return NodeFilter.FILTER_SKIP;
|
|
13
|
+
});
|
|
14
|
+
let slot;
|
|
15
|
+
while (true) {
|
|
16
|
+
slot = iterator.nextNode();
|
|
17
|
+
if (!slot) break;
|
|
18
|
+
_slots[slot.getAttribute("name") || "default"] = slot;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
for (const [key, value] of Object.entries(slotted)) {
|
|
22
|
+
if (_slots[key]) continue;
|
|
23
|
+
_slots[key] = document.createElement("astro-slot");
|
|
24
|
+
if (key !== "default") _slots[key].setAttribute("name", key);
|
|
25
|
+
_slots[key].innerHTML = value;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
const { default: children, ...slots } = _slots;
|
|
29
|
+
element.innerHTML = "";
|
|
30
|
+
const app = mount(() => Component({
|
|
31
|
+
...props,
|
|
32
|
+
...slots,
|
|
33
|
+
children
|
|
34
|
+
}), element);
|
|
35
|
+
element.addEventListener("astro:unmount", () => app.dispose(), { once: true });
|
|
36
|
+
};
|
|
37
|
+
//#endregion
|
|
38
|
+
export { client_default as default };
|
|
39
|
+
|
|
40
|
+
//# sourceMappingURL=client.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.mjs","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,MAAM,YAAY,UAAU;EAAE,GAAG;EAAO,GAAG;EAAO;EAAU,CAAC,EAAE,QAAQ;AAE7E,SAAQ,iBAAiB,uBAAuB,IAAI,SAAS,EAAE,EAAE,MAAM,MAAM,CAAC"}
|
package/dist/context.cjs
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
//#region src/context.ts
|
|
2
|
+
const contexts = /* @__PURE__ */ new WeakMap();
|
|
3
|
+
function getContext(result) {
|
|
4
|
+
if (contexts.has(result)) return contexts.get(result);
|
|
5
|
+
const ctx = {
|
|
6
|
+
c: 0,
|
|
7
|
+
get id() {
|
|
8
|
+
return `v${this.c.toString()}`;
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
contexts.set(result, ctx);
|
|
12
|
+
return ctx;
|
|
13
|
+
}
|
|
14
|
+
function incrementId(ctx) {
|
|
15
|
+
const id = ctx.id;
|
|
16
|
+
ctx.c++;
|
|
17
|
+
return id;
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
20
|
+
exports.getContext = getContext;
|
|
21
|
+
exports.incrementId = incrementId;
|
|
22
|
+
|
|
23
|
+
//# sourceMappingURL=context.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.cjs","names":[],"sources":["../src/context.ts"],"sourcesContent":["import type { RendererContext } from \"./types\";\n\ntype Context = {\n id: string;\n c: number;\n};\n\nconst contexts = new WeakMap<RendererContext[\"result\"], Context>();\n\nexport function getContext(result: RendererContext[\"result\"]): Context {\n if (contexts.has(result)) {\n return contexts.get(result)!;\n }\n const ctx: Context = {\n c: 0,\n get id() {\n return `v${this.c.toString()}`;\n },\n };\n contexts.set(result, ctx);\n return ctx;\n}\n\nexport function incrementId(ctx: Context): string {\n const id = ctx.id;\n ctx.c++;\n return id;\n}\n"],"mappings":";AAOA,MAAM,2BAAW,IAAI,SAA6C;AAElE,SAAgB,WAAW,QAA4C;AACrE,KAAI,SAAS,IAAI,OAAO,CACtB,QAAO,SAAS,IAAI,OAAO;CAE7B,MAAM,MAAe;EACnB,GAAG;EACH,IAAI,KAAK;AACP,UAAO,IAAI,KAAK,EAAE,UAAU;;EAE/B;AACD,UAAS,IAAI,QAAQ,IAAI;AACzB,QAAO;;AAGT,SAAgB,YAAY,KAAsB;CAChD,MAAM,KAAK,IAAI;AACf,KAAI;AACJ,QAAO"}
|
package/dist/context.mjs
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
//#region src/context.ts
|
|
2
|
+
const contexts = /* @__PURE__ */ new WeakMap();
|
|
3
|
+
function getContext(result) {
|
|
4
|
+
if (contexts.has(result)) return contexts.get(result);
|
|
5
|
+
const ctx = {
|
|
6
|
+
c: 0,
|
|
7
|
+
get id() {
|
|
8
|
+
return `v${this.c.toString()}`;
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
contexts.set(result, ctx);
|
|
12
|
+
return ctx;
|
|
13
|
+
}
|
|
14
|
+
function incrementId(ctx) {
|
|
15
|
+
const id = ctx.id;
|
|
16
|
+
ctx.c++;
|
|
17
|
+
return id;
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
20
|
+
export { getContext, incrementId };
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=context.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.mjs","names":[],"sources":["../src/context.ts"],"sourcesContent":["import type { RendererContext } from \"./types\";\n\ntype Context = {\n id: string;\n c: number;\n};\n\nconst contexts = new WeakMap<RendererContext[\"result\"], Context>();\n\nexport function getContext(result: RendererContext[\"result\"]): Context {\n if (contexts.has(result)) {\n return contexts.get(result)!;\n }\n const ctx: Context = {\n c: 0,\n get id() {\n return `v${this.c.toString()}`;\n },\n };\n contexts.set(result, ctx);\n return ctx;\n}\n\nexport function incrementId(ctx: Context): string {\n const id = ctx.id;\n ctx.c++;\n return id;\n}\n"],"mappings":";AAOA,MAAM,2BAAW,IAAI,SAA6C;AAElE,SAAgB,WAAW,QAA4C;AACrE,KAAI,SAAS,IAAI,OAAO,CACtB,QAAO,SAAS,IAAI,OAAO;CAE7B,MAAM,MAAe;EACnB,GAAG;EACH,IAAI,KAAK;AACP,UAAO,IAAI,KAAK,EAAE,UAAU;;EAE/B;AACD,UAAS,IAAI,QAAQ,IAAI;AACzB,QAAO;;AAGT,SAAgB,YAAY,KAAsB;CAChD,MAAM,KAAK,IAAI;AACf,KAAI;AACJ,QAAO"}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
4
|
+
});
|
|
5
|
+
//#region src/index.ts
|
|
6
|
+
function getRenderer() {
|
|
7
|
+
return {
|
|
8
|
+
name: "@hedystia/astro",
|
|
9
|
+
clientEntrypoint: "@hedystia/astro/client.js",
|
|
10
|
+
serverEntrypoint: "@hedystia/astro/server.js"
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
function src_default(options = {}) {
|
|
14
|
+
return {
|
|
15
|
+
name: "@hedystia/astro",
|
|
16
|
+
hooks: { "astro:config:setup": async ({ addRenderer, updateConfig }) => {
|
|
17
|
+
addRenderer(getRenderer());
|
|
18
|
+
updateConfig({ vite: getViteConfiguration(options) });
|
|
19
|
+
} }
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
function getViteConfiguration({ include, exclude }) {
|
|
23
|
+
return { plugins: [hedystiaViewPlugin({
|
|
24
|
+
include,
|
|
25
|
+
exclude
|
|
26
|
+
}), configEnvironmentPlugin()] };
|
|
27
|
+
}
|
|
28
|
+
function hedystiaViewPlugin(_options) {
|
|
29
|
+
return {
|
|
30
|
+
name: "@hedystia/astro:view",
|
|
31
|
+
config() {
|
|
32
|
+
return { esbuild: {
|
|
33
|
+
jsx: "automatic",
|
|
34
|
+
jsxImportSource: "@hedystia/view"
|
|
35
|
+
} };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function configEnvironmentPlugin() {
|
|
40
|
+
return {
|
|
41
|
+
name: "@hedystia/astro:config-environment",
|
|
42
|
+
configEnvironment(environmentName) {
|
|
43
|
+
return { optimizeDeps: {
|
|
44
|
+
include: environmentName === "client" ? ["@hedystia/astro/client.js"] : [],
|
|
45
|
+
exclude: ["@hedystia/astro/server.js"]
|
|
46
|
+
} };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
//#endregion
|
|
51
|
+
exports.default = src_default;
|
|
52
|
+
exports.getContainerRenderer = getRenderer;
|
|
53
|
+
|
|
54
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +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: getViteConfiguration(options),\n });\n },\n },\n };\n}\n\nfunction getViteConfiguration({ include, exclude }: Options) {\n return {\n plugins: [hedystiaViewPlugin({ include, exclude }), configEnvironmentPlugin()],\n };\n}\n\nfunction hedystiaViewPlugin(_options: Options): Plugin {\n return {\n name: \"@hedystia/astro:view\",\n config() {\n return {\n esbuild: {\n jsx: \"automatic\",\n jsxImportSource: \"@hedystia/view\",\n },\n };\n },\n };\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":";;;;;AAGA,SAAS,cAA6B;AACpC,QAAO;EACL,MAAM;EACN,kBAAkB;EAClB,kBAAkB;EACnB;;AAUH,SAAA,YAAyB,UAAmB,EAAE,EAAoB;AAChE,QAAO;EACL,MAAM;EACN,OAAO,EACL,sBAAsB,OAAO,EAAE,aAAa,mBAAmB;AAC7D,eAAY,aAAa,CAAC;AAC1B,gBAAa,EACX,MAAM,qBAAqB,QAAQ,EACpC,CAAC;KAEL;EACF;;AAGH,SAAS,qBAAqB,EAAE,SAAS,WAAoB;AAC3D,QAAO,EACL,SAAS,CAAC,mBAAmB;EAAE;EAAS;EAAS,CAAC,EAAE,yBAAyB,CAAC,EAC/E;;AAGH,SAAS,mBAAmB,UAA2B;AACrD,QAAO;EACL,MAAM;EACN,SAAS;AACP,UAAO,EACL,SAAS;IACP,KAAK;IACL,iBAAiB;IAClB,EACF;;EAEJ;;AAGH,SAAS,0BAAkC;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/index.d.cts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { AstroIntegration, AstroRenderer } from "astro";
|
|
2
|
+
|
|
3
|
+
//#region src/index.d.ts
|
|
4
|
+
declare function getRenderer(): AstroRenderer;
|
|
5
|
+
interface Options {
|
|
6
|
+
include?: string[];
|
|
7
|
+
exclude?: string[];
|
|
8
|
+
}
|
|
9
|
+
declare function export_default(options?: Options): AstroIntegration;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { Options, export_default as default, getRenderer as getContainerRenderer };
|
|
12
|
+
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { AstroIntegration, AstroRenderer } from "astro";
|
|
2
|
+
|
|
3
|
+
//#region src/index.d.ts
|
|
4
|
+
declare function getRenderer(): AstroRenderer;
|
|
5
|
+
interface Options {
|
|
6
|
+
include?: string[];
|
|
7
|
+
exclude?: string[];
|
|
8
|
+
}
|
|
9
|
+
declare function export_default(options?: Options): AstroIntegration;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { Options, export_default as default, getRenderer as getContainerRenderer };
|
|
12
|
+
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
//#region src/index.ts
|
|
2
|
+
function getRenderer() {
|
|
3
|
+
return {
|
|
4
|
+
name: "@hedystia/astro",
|
|
5
|
+
clientEntrypoint: "@hedystia/astro/client.js",
|
|
6
|
+
serverEntrypoint: "@hedystia/astro/server.js"
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
function src_default(options = {}) {
|
|
10
|
+
return {
|
|
11
|
+
name: "@hedystia/astro",
|
|
12
|
+
hooks: { "astro:config:setup": async ({ addRenderer, updateConfig }) => {
|
|
13
|
+
addRenderer(getRenderer());
|
|
14
|
+
updateConfig({ vite: getViteConfiguration(options) });
|
|
15
|
+
} }
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function getViteConfiguration({ include, exclude }) {
|
|
19
|
+
return { plugins: [hedystiaViewPlugin({
|
|
20
|
+
include,
|
|
21
|
+
exclude
|
|
22
|
+
}), configEnvironmentPlugin()] };
|
|
23
|
+
}
|
|
24
|
+
function hedystiaViewPlugin(_options) {
|
|
25
|
+
return {
|
|
26
|
+
name: "@hedystia/astro:view",
|
|
27
|
+
config() {
|
|
28
|
+
return { esbuild: {
|
|
29
|
+
jsx: "automatic",
|
|
30
|
+
jsxImportSource: "@hedystia/view"
|
|
31
|
+
} };
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function configEnvironmentPlugin() {
|
|
36
|
+
return {
|
|
37
|
+
name: "@hedystia/astro:config-environment",
|
|
38
|
+
configEnvironment(environmentName) {
|
|
39
|
+
return { optimizeDeps: {
|
|
40
|
+
include: environmentName === "client" ? ["@hedystia/astro/client.js"] : [],
|
|
41
|
+
exclude: ["@hedystia/astro/server.js"]
|
|
42
|
+
} };
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
//#endregion
|
|
47
|
+
export { src_default as default, getRenderer as getContainerRenderer };
|
|
48
|
+
|
|
49
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +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: getViteConfiguration(options),\n });\n },\n },\n };\n}\n\nfunction getViteConfiguration({ include, exclude }: Options) {\n return {\n plugins: [hedystiaViewPlugin({ include, exclude }), configEnvironmentPlugin()],\n };\n}\n\nfunction hedystiaViewPlugin(_options: Options): Plugin {\n return {\n name: \"@hedystia/astro:view\",\n config() {\n return {\n esbuild: {\n jsx: \"automatic\",\n jsxImportSource: \"@hedystia/view\",\n },\n };\n },\n };\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":";AAGA,SAAS,cAA6B;AACpC,QAAO;EACL,MAAM;EACN,kBAAkB;EAClB,kBAAkB;EACnB;;AAUH,SAAA,YAAyB,UAAmB,EAAE,EAAoB;AAChE,QAAO;EACL,MAAM;EACN,OAAO,EACL,sBAAsB,OAAO,EAAE,aAAa,mBAAmB;AAC7D,eAAY,aAAa,CAAC;AAC1B,gBAAa,EACX,MAAM,qBAAqB,QAAQ,EACpC,CAAC;KAEL;EACF;;AAGH,SAAS,qBAAqB,EAAE,SAAS,WAAoB;AAC3D,QAAO,EACL,SAAS,CAAC,mBAAmB;EAAE;EAAS;EAAS,CAAC,EAAE,yBAAyB,CAAC,EAC/E;;AAGH,SAAS,mBAAmB,UAA2B;AACrD,QAAO;EACL,MAAM;EACN,SAAS;AACP,UAAO,EACL,SAAS;IACP,KAAK;IACL,iBAAiB;IAClB,EACF;;EAEJ;;AAGH,SAAS,0BAAkC;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
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
4
|
+
});
|
|
5
|
+
const require_context = require("./context.cjs");
|
|
6
|
+
let _hedystia_view = require("@hedystia/view");
|
|
7
|
+
//#region src/server.ts
|
|
8
|
+
const slotName = (str) => str.trim().replace(/[-_]([a-z])/g, (_, w) => w.toUpperCase());
|
|
9
|
+
async function check(Component, _props, _children) {
|
|
10
|
+
if (typeof Component !== "function") return false;
|
|
11
|
+
if (Component.name === "QwikComponent") return false;
|
|
12
|
+
if (Component.toString().includes("$$payload")) return false;
|
|
13
|
+
try {
|
|
14
|
+
return typeof (0, _hedystia_view.renderToString)(() => Component(_props)) === "string";
|
|
15
|
+
} catch {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
async function renderToStaticMarkup(Component, props, { default: children, ...slotted }, metadata) {
|
|
20
|
+
const ctx = require_context.getContext(this.result);
|
|
21
|
+
const renderId = metadata?.hydrate ? require_context.incrementId(ctx) : "";
|
|
22
|
+
const tagName = (metadata?.astroStaticSlot ? !!metadata.hydrate : true) ? "astro-slot" : "astro-static-slot";
|
|
23
|
+
const slots = {};
|
|
24
|
+
for (const [key, value] of Object.entries(slotted)) {
|
|
25
|
+
const name = slotName(key);
|
|
26
|
+
slots[name] = `<${tagName} name="${name}">${value}</${tagName}>`;
|
|
27
|
+
}
|
|
28
|
+
const childrenHtml = children != null ? `<${tagName}>${children}</${tagName}>` : void 0;
|
|
29
|
+
const newProps = {
|
|
30
|
+
...props,
|
|
31
|
+
...slots,
|
|
32
|
+
children: childrenHtml
|
|
33
|
+
};
|
|
34
|
+
const componentHtml = (0, _hedystia_view.renderToString)(() => Component(newProps));
|
|
35
|
+
return {
|
|
36
|
+
attrs: { "data-view-render-id": renderId },
|
|
37
|
+
html: componentHtml
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
const renderer = {
|
|
41
|
+
name: "@hedystia/astro",
|
|
42
|
+
check,
|
|
43
|
+
renderToStaticMarkup,
|
|
44
|
+
supportsAstroStaticSlot: true
|
|
45
|
+
};
|
|
46
|
+
//#endregion
|
|
47
|
+
exports.default = renderer;
|
|
48
|
+
|
|
49
|
+
//# sourceMappingURL=server.cjs.map
|
|
@@ -0,0 +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 html = renderToString(() => Component(_props));\n return typeof html === \"string\";\n } catch {\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;AAEF,SAAO,QAAA,GAAA,eAAA,sBAD2B,UAAU,OAAO,CAAC,KAC7B;SACjB;AACN,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;;CAGhE,MAAM,eAAe,YAAY,OAAO,IAAI,QAAQ,GAAG,SAAS,IAAI,QAAQ,KAAK,KAAA;CAEjF,MAAM,WAAW;EACf,GAAG;EACH,GAAG;EACH,UAAU;EACX;CAED,MAAM,iBAAA,GAAA,eAAA,sBAAqC,UAAU,SAAS,CAAC;AAE/D,QAAO;EACL,OAAO,EACL,uBAAuB,UACxB;EACD,MAAM;EACP;;AAGH,MAAM,WAAwC;CAC5C,MAAM;CACN;CACA;CACA,yBAAyB;CAC1B"}
|
package/dist/server.mjs
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { getContext, incrementId } from "./context.mjs";
|
|
2
|
+
import { renderToString } from "@hedystia/view";
|
|
3
|
+
//#region src/server.ts
|
|
4
|
+
const slotName = (str) => str.trim().replace(/[-_]([a-z])/g, (_, w) => w.toUpperCase());
|
|
5
|
+
async function check(Component, _props, _children) {
|
|
6
|
+
if (typeof Component !== "function") return false;
|
|
7
|
+
if (Component.name === "QwikComponent") return false;
|
|
8
|
+
if (Component.toString().includes("$$payload")) return false;
|
|
9
|
+
try {
|
|
10
|
+
return typeof renderToString(() => Component(_props)) === "string";
|
|
11
|
+
} catch {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
async function renderToStaticMarkup(Component, props, { default: children, ...slotted }, metadata) {
|
|
16
|
+
const ctx = getContext(this.result);
|
|
17
|
+
const renderId = metadata?.hydrate ? incrementId(ctx) : "";
|
|
18
|
+
const tagName = (metadata?.astroStaticSlot ? !!metadata.hydrate : true) ? "astro-slot" : "astro-static-slot";
|
|
19
|
+
const slots = {};
|
|
20
|
+
for (const [key, value] of Object.entries(slotted)) {
|
|
21
|
+
const name = slotName(key);
|
|
22
|
+
slots[name] = `<${tagName} name="${name}">${value}</${tagName}>`;
|
|
23
|
+
}
|
|
24
|
+
const childrenHtml = children != null ? `<${tagName}>${children}</${tagName}>` : void 0;
|
|
25
|
+
const newProps = {
|
|
26
|
+
...props,
|
|
27
|
+
...slots,
|
|
28
|
+
children: childrenHtml
|
|
29
|
+
};
|
|
30
|
+
const componentHtml = renderToString(() => Component(newProps));
|
|
31
|
+
return {
|
|
32
|
+
attrs: { "data-view-render-id": renderId },
|
|
33
|
+
html: componentHtml
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
const renderer = {
|
|
37
|
+
name: "@hedystia/astro",
|
|
38
|
+
check,
|
|
39
|
+
renderToStaticMarkup,
|
|
40
|
+
supportsAstroStaticSlot: true
|
|
41
|
+
};
|
|
42
|
+
//#endregion
|
|
43
|
+
export { renderer as default };
|
|
44
|
+
|
|
45
|
+
//# sourceMappingURL=server.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.mjs","names":[],"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 html = renderToString(() => Component(_props));\n return typeof html === \"string\";\n } catch {\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;AAEF,SAAO,OADM,qBAAqB,UAAU,OAAO,CAAC,KAC7B;SACjB;AACN,SAAO;;;AAIX,eAAe,qBAEb,WACA,OACA,EAAE,SAAS,UAAU,GAAG,WACxB,UACA;CACA,MAAM,MAAM,WAAW,KAAK,OAAO;CACnC,MAAM,WAAW,UAAU,UAAU,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;;CAGhE,MAAM,eAAe,YAAY,OAAO,IAAI,QAAQ,GAAG,SAAS,IAAI,QAAQ,KAAK,KAAA;CAEjF,MAAM,WAAW;EACf,GAAG;EACH,GAAG;EACH,UAAU;EACX;CAED,MAAM,gBAAgB,qBAAqB,UAAU,SAAS,CAAC;AAE/D,QAAO;EACL,OAAO,EACL,uBAAuB,UACxB;EACD,MAAM;EACP;;AAGH,MAAM,WAAwC;CAC5C,MAAM;CACN;CACA;CACA,yBAAyB;CAC1B"}
|
package/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hedystia/astro",
|
|
3
|
+
"version": "2.2.0",
|
|
4
|
+
"description": "Use @hedystia/view components within Astro",
|
|
5
|
+
"homepage": "https://docs.hedystia.com",
|
|
6
|
+
"private": false,
|
|
7
|
+
"keywords": [
|
|
8
|
+
"hedystia",
|
|
9
|
+
"astro-integration",
|
|
10
|
+
"astro-component",
|
|
11
|
+
"renderer",
|
|
12
|
+
"view"
|
|
13
|
+
],
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"type": "commonjs",
|
|
16
|
+
"types": "./dist/index.d.cts",
|
|
17
|
+
"main": "./dist/index.cjs",
|
|
18
|
+
"module": "./dist/index.mjs",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./dist/index.d.cts",
|
|
22
|
+
"import": "./dist/index.mjs",
|
|
23
|
+
"require": "./dist/index.cjs"
|
|
24
|
+
},
|
|
25
|
+
"./client.js": {
|
|
26
|
+
"types": "./dist/client.d.cts",
|
|
27
|
+
"import": "./dist/client.mjs",
|
|
28
|
+
"require": "./dist/client.cjs"
|
|
29
|
+
},
|
|
30
|
+
"./server.js": {
|
|
31
|
+
"types": "./dist/server.d.cts",
|
|
32
|
+
"import": "./dist/server.mjs",
|
|
33
|
+
"require": "./dist/server.cjs"
|
|
34
|
+
},
|
|
35
|
+
"./package.json": "./package.json"
|
|
36
|
+
},
|
|
37
|
+
"scripts": {
|
|
38
|
+
"build": "tsdown --config-loader unrun",
|
|
39
|
+
"release:pkg": "bun publish --provenance --access public",
|
|
40
|
+
"dev": "tsdown --watch"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@types/bun": "^1.3.11",
|
|
44
|
+
"typescript": "6.0.2"
|
|
45
|
+
},
|
|
46
|
+
"peerDependencies": {
|
|
47
|
+
"@hedystia/view": ">= 2.0.0",
|
|
48
|
+
"astro": ">= 5.0.0",
|
|
49
|
+
"vite": ">= 7.3.1"
|
|
50
|
+
},
|
|
51
|
+
"repository": {
|
|
52
|
+
"type": "git",
|
|
53
|
+
"url": "https://github.com/Hedystia/Hedystia"
|
|
54
|
+
},
|
|
55
|
+
"author": {
|
|
56
|
+
"name": "Zastinian",
|
|
57
|
+
"email": "contact@zastinian.com",
|
|
58
|
+
"url": "https://github.com/Zastinian"
|
|
59
|
+
}
|
|
60
|
+
}
|
package/readme.md
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# @hedystia/astro
|
|
2
|
+
|
|
3
|
+
Astro integration for [@hedystia/view](https://www.npmjs.com/package/@hedystia/view) — use reactive View components within Astro.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
bun add @hedystia/astro @hedystia/view
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Setup
|
|
12
|
+
|
|
13
|
+
Add the integration to your `astro.config.mjs`:
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
import { defineConfig } from "astro/config";
|
|
17
|
+
import hedystiaView from "@hedystia/astro";
|
|
18
|
+
|
|
19
|
+
export default defineConfig({
|
|
20
|
+
integrations: [hedystiaView()],
|
|
21
|
+
});
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Quick Start
|
|
25
|
+
|
|
26
|
+
Create a View component:
|
|
27
|
+
|
|
28
|
+
```tsx
|
|
29
|
+
// src/components/Counter.tsx
|
|
30
|
+
import { sig, val, set } from "@hedystia/view";
|
|
31
|
+
|
|
32
|
+
export default function Counter() {
|
|
33
|
+
const count = sig(0);
|
|
34
|
+
|
|
35
|
+
return (
|
|
36
|
+
<div style={{ padding: "16px" }}>
|
|
37
|
+
<h1>Counter: {() => val(count)}</h1>
|
|
38
|
+
<button onClick={() => set(count, val(count) + 1)}>+</button>
|
|
39
|
+
</div>
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Use it in an Astro page with client directives:
|
|
45
|
+
|
|
46
|
+
```astro
|
|
47
|
+
---
|
|
48
|
+
// src/pages/index.astro
|
|
49
|
+
import Counter from "../components/Counter";
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
<html>
|
|
53
|
+
<body>
|
|
54
|
+
<h1>My Astro Site</h1>
|
|
55
|
+
<Counter client:load />
|
|
56
|
+
</body>
|
|
57
|
+
</html>
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Client Directives
|
|
61
|
+
|
|
62
|
+
| Directive | Description |
|
|
63
|
+
|-----------|-------------|
|
|
64
|
+
| `client:load` | Hydrate on page load |
|
|
65
|
+
| `client:idle` | Hydrate when browser is idle |
|
|
66
|
+
| `client:visible` | Hydrate when element enters viewport |
|
|
67
|
+
| `client:only="@hedystia/astro"` | Client-only rendering (no SSR) |
|
|
68
|
+
|
|
69
|
+
## Signals & Reactivity
|
|
70
|
+
|
|
71
|
+
All `@hedystia/view` reactivity features work inside Astro:
|
|
72
|
+
|
|
73
|
+
```tsx
|
|
74
|
+
import { sig, val, set, memo, batch } from "@hedystia/view";
|
|
75
|
+
|
|
76
|
+
export default function App() {
|
|
77
|
+
const count = sig(0);
|
|
78
|
+
const doubled = memo(() => val(count) * 2);
|
|
79
|
+
|
|
80
|
+
return (
|
|
81
|
+
<div>
|
|
82
|
+
<span>{() => val(count)}</span>
|
|
83
|
+
<span>Doubled: {() => val(doubled)}</span>
|
|
84
|
+
<button onClick={() => set(count, val(count) + 1)}>+</button>
|
|
85
|
+
</div>
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Flow Components
|
|
91
|
+
|
|
92
|
+
```tsx
|
|
93
|
+
import { sig, val, set, Show, For } from "@hedystia/view";
|
|
94
|
+
|
|
95
|
+
export default function TodoList() {
|
|
96
|
+
const items = sig([
|
|
97
|
+
{ id: 1, text: "Learn Astro" },
|
|
98
|
+
{ id: 2, text: "Use @hedystia/view" },
|
|
99
|
+
]);
|
|
100
|
+
|
|
101
|
+
return (
|
|
102
|
+
<div>
|
|
103
|
+
<ul>
|
|
104
|
+
{For({
|
|
105
|
+
each: () => val(items),
|
|
106
|
+
key: (item) => item.id,
|
|
107
|
+
children: (item) => <li>{val(item).text}</li>,
|
|
108
|
+
})}
|
|
109
|
+
</ul>
|
|
110
|
+
</div>
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## SSR
|
|
116
|
+
|
|
117
|
+
Components render to static HTML on the server. The `renderToString` function from `@hedystia/view` is used automatically for server-side rendering.
|
|
118
|
+
|
|
119
|
+
## API Reference
|
|
120
|
+
|
|
121
|
+
| Export | Description |
|
|
122
|
+
|--------|-------------|
|
|
123
|
+
| `default` | Astro integration function |
|
|
124
|
+
| `getContainerRenderer` | Container renderer for Astro Container API |
|
|
125
|
+
|
|
126
|
+
## License
|
|
127
|
+
|
|
128
|
+
MIT
|