Refactor routing in App component to enhance navigation and improve error handling by integrating dynamic routes and updating the NotFound route.
This commit is contained in:
9
node_modules/astro/dist/runtime/server/astro-component.d.ts
generated
vendored
Normal file
9
node_modules/astro/dist/runtime/server/astro-component.d.ts
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
import type { PropagationHint } from '../../@types/astro.js';
|
||||
import type { AstroComponentFactory } from './render/index.js';
|
||||
interface CreateComponentOptions {
|
||||
factory: AstroComponentFactory;
|
||||
moduleId?: string;
|
||||
propagation?: PropagationHint;
|
||||
}
|
||||
export declare function createComponent(arg1: AstroComponentFactory | CreateComponentOptions, moduleId?: string, propagation?: PropagationHint): AstroComponentFactory;
|
||||
export {};
|
37
node_modules/astro/dist/runtime/server/astro-component.js
generated
vendored
Normal file
37
node_modules/astro/dist/runtime/server/astro-component.js
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
import { AstroError, AstroErrorData } from "../../core/errors/index.js";
|
||||
function validateArgs(args) {
|
||||
if (args.length !== 3) return false;
|
||||
if (!args[0] || typeof args[0] !== "object") return false;
|
||||
return true;
|
||||
}
|
||||
function baseCreateComponent(cb, moduleId, propagation) {
|
||||
const name = moduleId?.split("/").pop()?.replace(".astro", "") ?? "";
|
||||
const fn = (...args) => {
|
||||
if (!validateArgs(args)) {
|
||||
throw new AstroError({
|
||||
...AstroErrorData.InvalidComponentArgs,
|
||||
message: AstroErrorData.InvalidComponentArgs.message(name)
|
||||
});
|
||||
}
|
||||
return cb(...args);
|
||||
};
|
||||
Object.defineProperty(fn, "name", { value: name, writable: false });
|
||||
fn.isAstroComponentFactory = true;
|
||||
fn.moduleId = moduleId;
|
||||
fn.propagation = propagation;
|
||||
return fn;
|
||||
}
|
||||
function createComponentWithOptions(opts) {
|
||||
const cb = baseCreateComponent(opts.factory, opts.moduleId, opts.propagation);
|
||||
return cb;
|
||||
}
|
||||
function createComponent(arg1, moduleId, propagation) {
|
||||
if (typeof arg1 === "function") {
|
||||
return baseCreateComponent(arg1, moduleId, propagation);
|
||||
} else {
|
||||
return createComponentWithOptions(arg1);
|
||||
}
|
||||
}
|
||||
export {
|
||||
createComponent
|
||||
};
|
2
node_modules/astro/dist/runtime/server/astro-global.d.ts
generated
vendored
Normal file
2
node_modules/astro/dist/runtime/server/astro-global.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import type { AstroGlobalPartial } from '../../@types/astro.js';
|
||||
export declare function createAstro(site: string | undefined): AstroGlobalPartial;
|
33
node_modules/astro/dist/runtime/server/astro-global.js
generated
vendored
Normal file
33
node_modules/astro/dist/runtime/server/astro-global.js
generated
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
import { ASTRO_VERSION } from "../../core/constants.js";
|
||||
import { AstroError, AstroErrorData } from "../../core/errors/index.js";
|
||||
function createAstroGlobFn() {
|
||||
const globHandler = (importMetaGlobResult) => {
|
||||
if (typeof importMetaGlobResult === "string") {
|
||||
throw new AstroError({
|
||||
...AstroErrorData.AstroGlobUsedOutside,
|
||||
message: AstroErrorData.AstroGlobUsedOutside.message(JSON.stringify(importMetaGlobResult))
|
||||
});
|
||||
}
|
||||
let allEntries = [...Object.values(importMetaGlobResult)];
|
||||
if (allEntries.length === 0) {
|
||||
throw new AstroError({
|
||||
...AstroErrorData.AstroGlobNoMatch,
|
||||
message: AstroErrorData.AstroGlobNoMatch.message(JSON.stringify(importMetaGlobResult))
|
||||
});
|
||||
}
|
||||
return Promise.all(allEntries.map((fn) => fn()));
|
||||
};
|
||||
return globHandler;
|
||||
}
|
||||
function createAstro(site) {
|
||||
return {
|
||||
// TODO: this is no longer necessary for `Astro.site`
|
||||
// but it somehow allows working around caching issues in content collections for some tests
|
||||
site: site ? new URL(site) : void 0,
|
||||
generator: `Astro v${ASTRO_VERSION}`,
|
||||
glob: createAstroGlobFn()
|
||||
};
|
||||
}
|
||||
export {
|
||||
createAstro
|
||||
};
|
1
node_modules/astro/dist/runtime/server/astro-island.d.ts
generated
vendored
Normal file
1
node_modules/astro/dist/runtime/server/astro-island.d.ts
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export {};
|
156
node_modules/astro/dist/runtime/server/astro-island.js
generated
vendored
Normal file
156
node_modules/astro/dist/runtime/server/astro-island.js
generated
vendored
Normal file
@@ -0,0 +1,156 @@
|
||||
{
|
||||
const propTypes = {
|
||||
0: (value) => reviveObject(value),
|
||||
1: (value) => reviveArray(value),
|
||||
2: (value) => new RegExp(value),
|
||||
3: (value) => new Date(value),
|
||||
4: (value) => new Map(reviveArray(value)),
|
||||
5: (value) => new Set(reviveArray(value)),
|
||||
6: (value) => BigInt(value),
|
||||
7: (value) => new URL(value),
|
||||
8: (value) => new Uint8Array(value),
|
||||
9: (value) => new Uint16Array(value),
|
||||
10: (value) => new Uint32Array(value),
|
||||
11: (value) => Infinity * value
|
||||
};
|
||||
const reviveTuple = (raw) => {
|
||||
const [type, value] = raw;
|
||||
return type in propTypes ? propTypes[type](value) : void 0;
|
||||
};
|
||||
const reviveArray = (raw) => raw.map(reviveTuple);
|
||||
const reviveObject = (raw) => {
|
||||
if (typeof raw !== "object" || raw === null) return raw;
|
||||
return Object.fromEntries(Object.entries(raw).map(([key, value]) => [key, reviveTuple(value)]));
|
||||
};
|
||||
class AstroIsland extends HTMLElement {
|
||||
Component;
|
||||
hydrator;
|
||||
static observedAttributes = ["props"];
|
||||
disconnectedCallback() {
|
||||
document.removeEventListener("astro:after-swap", this.unmount);
|
||||
document.addEventListener("astro:after-swap", this.unmount, { once: true });
|
||||
}
|
||||
connectedCallback() {
|
||||
if (!this.hasAttribute("await-children") || document.readyState === "interactive" || document.readyState === "complete") {
|
||||
this.childrenConnectedCallback();
|
||||
} else {
|
||||
const onConnected = () => {
|
||||
document.removeEventListener("DOMContentLoaded", onConnected);
|
||||
mo.disconnect();
|
||||
this.childrenConnectedCallback();
|
||||
};
|
||||
const mo = new MutationObserver(() => {
|
||||
if (this.lastChild?.nodeType === Node.COMMENT_NODE && this.lastChild.nodeValue === "astro:end") {
|
||||
this.lastChild.remove();
|
||||
onConnected();
|
||||
}
|
||||
});
|
||||
mo.observe(this, { childList: true });
|
||||
document.addEventListener("DOMContentLoaded", onConnected);
|
||||
}
|
||||
}
|
||||
async childrenConnectedCallback() {
|
||||
let beforeHydrationUrl = this.getAttribute("before-hydration-url");
|
||||
if (beforeHydrationUrl) {
|
||||
await import(beforeHydrationUrl);
|
||||
}
|
||||
this.start();
|
||||
}
|
||||
async start() {
|
||||
const opts = JSON.parse(this.getAttribute("opts"));
|
||||
const directive = this.getAttribute("client");
|
||||
if (Astro[directive] === void 0) {
|
||||
window.addEventListener(`astro:${directive}`, () => this.start(), { once: true });
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await Astro[directive](
|
||||
async () => {
|
||||
const rendererUrl = this.getAttribute("renderer-url");
|
||||
const [componentModule, { default: hydrator }] = await Promise.all([
|
||||
import(this.getAttribute("component-url")),
|
||||
rendererUrl ? import(rendererUrl) : () => () => {
|
||||
}
|
||||
]);
|
||||
const componentExport = this.getAttribute("component-export") || "default";
|
||||
if (!componentExport.includes(".")) {
|
||||
this.Component = componentModule[componentExport];
|
||||
} else {
|
||||
this.Component = componentModule;
|
||||
for (const part of componentExport.split(".")) {
|
||||
this.Component = this.Component[part];
|
||||
}
|
||||
}
|
||||
this.hydrator = hydrator;
|
||||
return this.hydrate;
|
||||
},
|
||||
opts,
|
||||
this
|
||||
);
|
||||
} catch (e) {
|
||||
console.error(`[astro-island] Error hydrating ${this.getAttribute("component-url")}`, e);
|
||||
}
|
||||
}
|
||||
hydrate = async () => {
|
||||
if (!this.hydrator) return;
|
||||
if (!this.isConnected) return;
|
||||
const parentSsrIsland = this.parentElement?.closest("astro-island[ssr]");
|
||||
if (parentSsrIsland) {
|
||||
parentSsrIsland.addEventListener("astro:hydrate", this.hydrate, { once: true });
|
||||
return;
|
||||
}
|
||||
const slotted = this.querySelectorAll("astro-slot");
|
||||
const slots = {};
|
||||
const templates = this.querySelectorAll("template[data-astro-template]");
|
||||
for (const template of templates) {
|
||||
const closest = template.closest(this.tagName);
|
||||
if (!closest?.isSameNode(this)) continue;
|
||||
slots[template.getAttribute("data-astro-template") || "default"] = template.innerHTML;
|
||||
template.remove();
|
||||
}
|
||||
for (const slot of slotted) {
|
||||
const closest = slot.closest(this.tagName);
|
||||
if (!closest?.isSameNode(this)) continue;
|
||||
slots[slot.getAttribute("name") || "default"] = slot.innerHTML;
|
||||
}
|
||||
let props;
|
||||
try {
|
||||
props = this.hasAttribute("props") ? reviveObject(JSON.parse(this.getAttribute("props"))) : {};
|
||||
} catch (e) {
|
||||
let componentName = this.getAttribute("component-url") || "<unknown>";
|
||||
const componentExport = this.getAttribute("component-export");
|
||||
if (componentExport) {
|
||||
componentName += ` (export ${componentExport})`;
|
||||
}
|
||||
console.error(
|
||||
`[hydrate] Error parsing props for component ${componentName}`,
|
||||
this.getAttribute("props"),
|
||||
e
|
||||
);
|
||||
throw e;
|
||||
}
|
||||
let hydrationTimeStart;
|
||||
const hydrator = this.hydrator(this);
|
||||
if (process.env.NODE_ENV === "development") hydrationTimeStart = performance.now();
|
||||
await hydrator(this.Component, props, slots, {
|
||||
client: this.getAttribute("client")
|
||||
});
|
||||
if (process.env.NODE_ENV === "development" && hydrationTimeStart)
|
||||
this.setAttribute(
|
||||
"client-render-time",
|
||||
(performance.now() - hydrationTimeStart).toString()
|
||||
);
|
||||
this.removeAttribute("ssr");
|
||||
this.dispatchEvent(new CustomEvent("astro:hydrate"));
|
||||
};
|
||||
attributeChangedCallback() {
|
||||
this.hydrate();
|
||||
}
|
||||
unmount = () => {
|
||||
if (!this.isConnected) this.dispatchEvent(new CustomEvent("astro:unmount"));
|
||||
};
|
||||
}
|
||||
if (!customElements.get("astro-island")) {
|
||||
customElements.define("astro-island", AstroIsland);
|
||||
}
|
||||
}
|
7
node_modules/astro/dist/runtime/server/astro-island.prebuilt-dev.d.ts
generated
vendored
Normal file
7
node_modules/astro/dist/runtime/server/astro-island.prebuilt-dev.d.ts
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
/**
|
||||
* This file is prebuilt from packages/astro/src/runtime/server/astro-island.ts
|
||||
* Do not edit this directly, but instead edit that file and rerun the prebuild
|
||||
* to generate this file.
|
||||
*/
|
||||
declare const _default: "(()=>{var A=Object.defineProperty;var g=(i,o,a)=>o in i?A(i,o,{enumerable:!0,configurable:!0,writable:!0,value:a}):i[o]=a;var l=(i,o,a)=>g(i,typeof o!=\"symbol\"?o+\"\":o,a);{let i={0:t=>y(t),1:t=>a(t),2:t=>new RegExp(t),3:t=>new Date(t),4:t=>new Map(a(t)),5:t=>new Set(a(t)),6:t=>BigInt(t),7:t=>new URL(t),8:t=>new Uint8Array(t),9:t=>new Uint16Array(t),10:t=>new Uint32Array(t),11:t=>1/0*t},o=t=>{let[h,e]=t;return h in i?i[h](e):void 0},a=t=>t.map(o),y=t=>typeof t!=\"object\"||t===null?t:Object.fromEntries(Object.entries(t).map(([h,e])=>[h,o(e)]));class f extends HTMLElement{constructor(){super(...arguments);l(this,\"Component\");l(this,\"hydrator\");l(this,\"hydrate\",async()=>{var b;if(!this.hydrator||!this.isConnected)return;let e=(b=this.parentElement)==null?void 0:b.closest(\"astro-island[ssr]\");if(e){e.addEventListener(\"astro:hydrate\",this.hydrate,{once:!0});return}let c=this.querySelectorAll(\"astro-slot\"),n={},p=this.querySelectorAll(\"template[data-astro-template]\");for(let r of p){let s=r.closest(this.tagName);s!=null&&s.isSameNode(this)&&(n[r.getAttribute(\"data-astro-template\")||\"default\"]=r.innerHTML,r.remove())}for(let r of c){let s=r.closest(this.tagName);s!=null&&s.isSameNode(this)&&(n[r.getAttribute(\"name\")||\"default\"]=r.innerHTML)}let u;try{u=this.hasAttribute(\"props\")?y(JSON.parse(this.getAttribute(\"props\"))):{}}catch(r){let s=this.getAttribute(\"component-url\")||\"<unknown>\",v=this.getAttribute(\"component-export\");throw v&&(s+=` (export ${v})`),console.error(`[hydrate] Error parsing props for component ${s}`,this.getAttribute(\"props\"),r),r}let d,m=this.hydrator(this);d=performance.now(),await m(this.Component,u,n,{client:this.getAttribute(\"client\")}),d&&this.setAttribute(\"client-render-time\",(performance.now()-d).toString()),this.removeAttribute(\"ssr\"),this.dispatchEvent(new CustomEvent(\"astro:hydrate\"))});l(this,\"unmount\",()=>{this.isConnected||this.dispatchEvent(new CustomEvent(\"astro:unmount\"))})}disconnectedCallback(){document.removeEventListener(\"astro:after-swap\",this.unmount),document.addEventListener(\"astro:after-swap\",this.unmount,{once:!0})}connectedCallback(){if(!this.hasAttribute(\"await-children\")||document.readyState===\"interactive\"||document.readyState===\"complete\")this.childrenConnectedCallback();else{let e=()=>{document.removeEventListener(\"DOMContentLoaded\",e),c.disconnect(),this.childrenConnectedCallback()},c=new MutationObserver(()=>{var n;((n=this.lastChild)==null?void 0:n.nodeType)===Node.COMMENT_NODE&&this.lastChild.nodeValue===\"astro:end\"&&(this.lastChild.remove(),e())});c.observe(this,{childList:!0}),document.addEventListener(\"DOMContentLoaded\",e)}}async childrenConnectedCallback(){let e=this.getAttribute(\"before-hydration-url\");e&&await import(e),this.start()}async start(){let e=JSON.parse(this.getAttribute(\"opts\")),c=this.getAttribute(\"client\");if(Astro[c]===void 0){window.addEventListener(`astro:${c}`,()=>this.start(),{once:!0});return}try{await Astro[c](async()=>{let n=this.getAttribute(\"renderer-url\"),[p,{default:u}]=await Promise.all([import(this.getAttribute(\"component-url\")),n?import(n):()=>()=>{}]),d=this.getAttribute(\"component-export\")||\"default\";if(!d.includes(\".\"))this.Component=p[d];else{this.Component=p;for(let m of d.split(\".\"))this.Component=this.Component[m]}return this.hydrator=u,this.hydrate},e,this)}catch(n){console.error(`[astro-island] Error hydrating ${this.getAttribute(\"component-url\")}`,n)}}attributeChangedCallback(){this.hydrate()}}l(f,\"observedAttributes\",[\"props\"]),customElements.get(\"astro-island\")||customElements.define(\"astro-island\",f)}})();";
|
||||
export default _default;
|
4
node_modules/astro/dist/runtime/server/astro-island.prebuilt-dev.js
generated
vendored
Normal file
4
node_modules/astro/dist/runtime/server/astro-island.prebuilt-dev.js
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
var astro_island_prebuilt_dev_default = `(()=>{var A=Object.defineProperty;var g=(i,o,a)=>o in i?A(i,o,{enumerable:!0,configurable:!0,writable:!0,value:a}):i[o]=a;var l=(i,o,a)=>g(i,typeof o!="symbol"?o+"":o,a);{let i={0:t=>y(t),1:t=>a(t),2:t=>new RegExp(t),3:t=>new Date(t),4:t=>new Map(a(t)),5:t=>new Set(a(t)),6:t=>BigInt(t),7:t=>new URL(t),8:t=>new Uint8Array(t),9:t=>new Uint16Array(t),10:t=>new Uint32Array(t),11:t=>1/0*t},o=t=>{let[h,e]=t;return h in i?i[h](e):void 0},a=t=>t.map(o),y=t=>typeof t!="object"||t===null?t:Object.fromEntries(Object.entries(t).map(([h,e])=>[h,o(e)]));class f extends HTMLElement{constructor(){super(...arguments);l(this,"Component");l(this,"hydrator");l(this,"hydrate",async()=>{var b;if(!this.hydrator||!this.isConnected)return;let e=(b=this.parentElement)==null?void 0:b.closest("astro-island[ssr]");if(e){e.addEventListener("astro:hydrate",this.hydrate,{once:!0});return}let c=this.querySelectorAll("astro-slot"),n={},p=this.querySelectorAll("template[data-astro-template]");for(let r of p){let s=r.closest(this.tagName);s!=null&&s.isSameNode(this)&&(n[r.getAttribute("data-astro-template")||"default"]=r.innerHTML,r.remove())}for(let r of c){let s=r.closest(this.tagName);s!=null&&s.isSameNode(this)&&(n[r.getAttribute("name")||"default"]=r.innerHTML)}let u;try{u=this.hasAttribute("props")?y(JSON.parse(this.getAttribute("props"))):{}}catch(r){let s=this.getAttribute("component-url")||"<unknown>",v=this.getAttribute("component-export");throw v&&(s+=\` (export \${v})\`),console.error(\`[hydrate] Error parsing props for component \${s}\`,this.getAttribute("props"),r),r}let d,m=this.hydrator(this);d=performance.now(),await m(this.Component,u,n,{client:this.getAttribute("client")}),d&&this.setAttribute("client-render-time",(performance.now()-d).toString()),this.removeAttribute("ssr"),this.dispatchEvent(new CustomEvent("astro:hydrate"))});l(this,"unmount",()=>{this.isConnected||this.dispatchEvent(new CustomEvent("astro:unmount"))})}disconnectedCallback(){document.removeEventListener("astro:after-swap",this.unmount),document.addEventListener("astro:after-swap",this.unmount,{once:!0})}connectedCallback(){if(!this.hasAttribute("await-children")||document.readyState==="interactive"||document.readyState==="complete")this.childrenConnectedCallback();else{let e=()=>{document.removeEventListener("DOMContentLoaded",e),c.disconnect(),this.childrenConnectedCallback()},c=new MutationObserver(()=>{var n;((n=this.lastChild)==null?void 0:n.nodeType)===Node.COMMENT_NODE&&this.lastChild.nodeValue==="astro:end"&&(this.lastChild.remove(),e())});c.observe(this,{childList:!0}),document.addEventListener("DOMContentLoaded",e)}}async childrenConnectedCallback(){let e=this.getAttribute("before-hydration-url");e&&await import(e),this.start()}async start(){let e=JSON.parse(this.getAttribute("opts")),c=this.getAttribute("client");if(Astro[c]===void 0){window.addEventListener(\`astro:\${c}\`,()=>this.start(),{once:!0});return}try{await Astro[c](async()=>{let n=this.getAttribute("renderer-url"),[p,{default:u}]=await Promise.all([import(this.getAttribute("component-url")),n?import(n):()=>()=>{}]),d=this.getAttribute("component-export")||"default";if(!d.includes("."))this.Component=p[d];else{this.Component=p;for(let m of d.split("."))this.Component=this.Component[m]}return this.hydrator=u,this.hydrate},e,this)}catch(n){console.error(\`[astro-island] Error hydrating \${this.getAttribute("component-url")}\`,n)}}attributeChangedCallback(){this.hydrate()}}l(f,"observedAttributes",["props"]),customElements.get("astro-island")||customElements.define("astro-island",f)}})();`;
|
||||
export {
|
||||
astro_island_prebuilt_dev_default as default
|
||||
};
|
7
node_modules/astro/dist/runtime/server/astro-island.prebuilt.d.ts
generated
vendored
Normal file
7
node_modules/astro/dist/runtime/server/astro-island.prebuilt.d.ts
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
/**
|
||||
* This file is prebuilt from packages/astro/src/runtime/server/astro-island.ts
|
||||
* Do not edit this directly, but instead edit that file and rerun the prebuild
|
||||
* to generate this file.
|
||||
*/
|
||||
declare const _default: "(()=>{var A=Object.defineProperty;var g=(i,o,a)=>o in i?A(i,o,{enumerable:!0,configurable:!0,writable:!0,value:a}):i[o]=a;var d=(i,o,a)=>g(i,typeof o!=\"symbol\"?o+\"\":o,a);{let i={0:t=>m(t),1:t=>a(t),2:t=>new RegExp(t),3:t=>new Date(t),4:t=>new Map(a(t)),5:t=>new Set(a(t)),6:t=>BigInt(t),7:t=>new URL(t),8:t=>new Uint8Array(t),9:t=>new Uint16Array(t),10:t=>new Uint32Array(t),11:t=>1/0*t},o=t=>{let[l,e]=t;return l in i?i[l](e):void 0},a=t=>t.map(o),m=t=>typeof t!=\"object\"||t===null?t:Object.fromEntries(Object.entries(t).map(([l,e])=>[l,o(e)]));class y extends HTMLElement{constructor(){super(...arguments);d(this,\"Component\");d(this,\"hydrator\");d(this,\"hydrate\",async()=>{var b;if(!this.hydrator||!this.isConnected)return;let e=(b=this.parentElement)==null?void 0:b.closest(\"astro-island[ssr]\");if(e){e.addEventListener(\"astro:hydrate\",this.hydrate,{once:!0});return}let c=this.querySelectorAll(\"astro-slot\"),n={},h=this.querySelectorAll(\"template[data-astro-template]\");for(let r of h){let s=r.closest(this.tagName);s!=null&&s.isSameNode(this)&&(n[r.getAttribute(\"data-astro-template\")||\"default\"]=r.innerHTML,r.remove())}for(let r of c){let s=r.closest(this.tagName);s!=null&&s.isSameNode(this)&&(n[r.getAttribute(\"name\")||\"default\"]=r.innerHTML)}let p;try{p=this.hasAttribute(\"props\")?m(JSON.parse(this.getAttribute(\"props\"))):{}}catch(r){let s=this.getAttribute(\"component-url\")||\"<unknown>\",v=this.getAttribute(\"component-export\");throw v&&(s+=` (export ${v})`),console.error(`[hydrate] Error parsing props for component ${s}`,this.getAttribute(\"props\"),r),r}let u;await this.hydrator(this)(this.Component,p,n,{client:this.getAttribute(\"client\")}),this.removeAttribute(\"ssr\"),this.dispatchEvent(new CustomEvent(\"astro:hydrate\"))});d(this,\"unmount\",()=>{this.isConnected||this.dispatchEvent(new CustomEvent(\"astro:unmount\"))})}disconnectedCallback(){document.removeEventListener(\"astro:after-swap\",this.unmount),document.addEventListener(\"astro:after-swap\",this.unmount,{once:!0})}connectedCallback(){if(!this.hasAttribute(\"await-children\")||document.readyState===\"interactive\"||document.readyState===\"complete\")this.childrenConnectedCallback();else{let e=()=>{document.removeEventListener(\"DOMContentLoaded\",e),c.disconnect(),this.childrenConnectedCallback()},c=new MutationObserver(()=>{var n;((n=this.lastChild)==null?void 0:n.nodeType)===Node.COMMENT_NODE&&this.lastChild.nodeValue===\"astro:end\"&&(this.lastChild.remove(),e())});c.observe(this,{childList:!0}),document.addEventListener(\"DOMContentLoaded\",e)}}async childrenConnectedCallback(){let e=this.getAttribute(\"before-hydration-url\");e&&await import(e),this.start()}async start(){let e=JSON.parse(this.getAttribute(\"opts\")),c=this.getAttribute(\"client\");if(Astro[c]===void 0){window.addEventListener(`astro:${c}`,()=>this.start(),{once:!0});return}try{await Astro[c](async()=>{let n=this.getAttribute(\"renderer-url\"),[h,{default:p}]=await Promise.all([import(this.getAttribute(\"component-url\")),n?import(n):()=>()=>{}]),u=this.getAttribute(\"component-export\")||\"default\";if(!u.includes(\".\"))this.Component=h[u];else{this.Component=h;for(let f of u.split(\".\"))this.Component=this.Component[f]}return this.hydrator=p,this.hydrate},e,this)}catch(n){console.error(`[astro-island] Error hydrating ${this.getAttribute(\"component-url\")}`,n)}}attributeChangedCallback(){this.hydrate()}}d(y,\"observedAttributes\",[\"props\"]),customElements.get(\"astro-island\")||customElements.define(\"astro-island\",y)}})();";
|
||||
export default _default;
|
4
node_modules/astro/dist/runtime/server/astro-island.prebuilt.js
generated
vendored
Normal file
4
node_modules/astro/dist/runtime/server/astro-island.prebuilt.js
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
var astro_island_prebuilt_default = `(()=>{var A=Object.defineProperty;var g=(i,o,a)=>o in i?A(i,o,{enumerable:!0,configurable:!0,writable:!0,value:a}):i[o]=a;var d=(i,o,a)=>g(i,typeof o!="symbol"?o+"":o,a);{let i={0:t=>m(t),1:t=>a(t),2:t=>new RegExp(t),3:t=>new Date(t),4:t=>new Map(a(t)),5:t=>new Set(a(t)),6:t=>BigInt(t),7:t=>new URL(t),8:t=>new Uint8Array(t),9:t=>new Uint16Array(t),10:t=>new Uint32Array(t),11:t=>1/0*t},o=t=>{let[l,e]=t;return l in i?i[l](e):void 0},a=t=>t.map(o),m=t=>typeof t!="object"||t===null?t:Object.fromEntries(Object.entries(t).map(([l,e])=>[l,o(e)]));class y extends HTMLElement{constructor(){super(...arguments);d(this,"Component");d(this,"hydrator");d(this,"hydrate",async()=>{var b;if(!this.hydrator||!this.isConnected)return;let e=(b=this.parentElement)==null?void 0:b.closest("astro-island[ssr]");if(e){e.addEventListener("astro:hydrate",this.hydrate,{once:!0});return}let c=this.querySelectorAll("astro-slot"),n={},h=this.querySelectorAll("template[data-astro-template]");for(let r of h){let s=r.closest(this.tagName);s!=null&&s.isSameNode(this)&&(n[r.getAttribute("data-astro-template")||"default"]=r.innerHTML,r.remove())}for(let r of c){let s=r.closest(this.tagName);s!=null&&s.isSameNode(this)&&(n[r.getAttribute("name")||"default"]=r.innerHTML)}let p;try{p=this.hasAttribute("props")?m(JSON.parse(this.getAttribute("props"))):{}}catch(r){let s=this.getAttribute("component-url")||"<unknown>",v=this.getAttribute("component-export");throw v&&(s+=\` (export \${v})\`),console.error(\`[hydrate] Error parsing props for component \${s}\`,this.getAttribute("props"),r),r}let u;await this.hydrator(this)(this.Component,p,n,{client:this.getAttribute("client")}),this.removeAttribute("ssr"),this.dispatchEvent(new CustomEvent("astro:hydrate"))});d(this,"unmount",()=>{this.isConnected||this.dispatchEvent(new CustomEvent("astro:unmount"))})}disconnectedCallback(){document.removeEventListener("astro:after-swap",this.unmount),document.addEventListener("astro:after-swap",this.unmount,{once:!0})}connectedCallback(){if(!this.hasAttribute("await-children")||document.readyState==="interactive"||document.readyState==="complete")this.childrenConnectedCallback();else{let e=()=>{document.removeEventListener("DOMContentLoaded",e),c.disconnect(),this.childrenConnectedCallback()},c=new MutationObserver(()=>{var n;((n=this.lastChild)==null?void 0:n.nodeType)===Node.COMMENT_NODE&&this.lastChild.nodeValue==="astro:end"&&(this.lastChild.remove(),e())});c.observe(this,{childList:!0}),document.addEventListener("DOMContentLoaded",e)}}async childrenConnectedCallback(){let e=this.getAttribute("before-hydration-url");e&&await import(e),this.start()}async start(){let e=JSON.parse(this.getAttribute("opts")),c=this.getAttribute("client");if(Astro[c]===void 0){window.addEventListener(\`astro:\${c}\`,()=>this.start(),{once:!0});return}try{await Astro[c](async()=>{let n=this.getAttribute("renderer-url"),[h,{default:p}]=await Promise.all([import(this.getAttribute("component-url")),n?import(n):()=>()=>{}]),u=this.getAttribute("component-export")||"default";if(!u.includes("."))this.Component=h[u];else{this.Component=h;for(let f of u.split("."))this.Component=this.Component[f]}return this.hydrator=p,this.hydrate},e,this)}catch(n){console.error(\`[astro-island] Error hydrating \${this.getAttribute("component-url")}\`,n)}}attributeChangedCallback(){this.hydrate()}}d(y,"observedAttributes",["props"]),customElements.get("astro-island")||customElements.define("astro-island",y)}})();`;
|
||||
export {
|
||||
astro_island_prebuilt_default as default
|
||||
};
|
4
node_modules/astro/dist/runtime/server/endpoint.d.ts
generated
vendored
Normal file
4
node_modules/astro/dist/runtime/server/endpoint.d.ts
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
import type { APIContext, EndpointHandler } from '../../@types/astro.js';
|
||||
import type { Logger } from '../../core/logger/core.js';
|
||||
/** Renders an endpoint request to completion, returning the body. */
|
||||
export declare function renderEndpoint(mod: EndpointHandler, context: APIContext, ssr: boolean, logger: Logger): Promise<Response>;
|
54
node_modules/astro/dist/runtime/server/endpoint.js
generated
vendored
Normal file
54
node_modules/astro/dist/runtime/server/endpoint.js
generated
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
import { bold } from "kleur/colors";
|
||||
import { REROUTABLE_STATUS_CODES, REROUTE_DIRECTIVE_HEADER } from "../../core/constants.js";
|
||||
import { EndpointDidNotReturnAResponse } from "../../core/errors/errors-data.js";
|
||||
import { AstroError } from "../../core/errors/errors.js";
|
||||
async function renderEndpoint(mod, context, ssr, logger) {
|
||||
const { request, url } = context;
|
||||
const method = request.method.toUpperCase();
|
||||
const handler = mod[method] ?? mod["ALL"];
|
||||
if (!ssr && ssr === false && method !== "GET") {
|
||||
logger.warn(
|
||||
"router",
|
||||
`${url.pathname} ${bold(
|
||||
method
|
||||
)} requests are not available for a static site. Update your config to \`output: 'server'\` or \`output: 'hybrid'\` to enable.`
|
||||
);
|
||||
}
|
||||
if (handler === void 0) {
|
||||
logger.warn(
|
||||
"router",
|
||||
`No API Route handler exists for the method "${method}" for the route "${url.pathname}".
|
||||
Found handlers: ${Object.keys(mod).map((exp) => JSON.stringify(exp)).join(", ")}
|
||||
` + ("all" in mod ? `One of the exported handlers is "all" (lowercase), did you mean to export 'ALL'?
|
||||
` : "")
|
||||
);
|
||||
return new Response(null, { status: 404 });
|
||||
}
|
||||
if (typeof handler !== "function") {
|
||||
logger.error(
|
||||
"router",
|
||||
`The route "${url.pathname}" exports a value for the method "${method}", but it is of the type ${typeof handler} instead of a function.`
|
||||
);
|
||||
return new Response(null, { status: 500 });
|
||||
}
|
||||
let response = await handler.call(mod, context);
|
||||
if (!response || response instanceof Response === false) {
|
||||
throw new AstroError(EndpointDidNotReturnAResponse);
|
||||
}
|
||||
if (REROUTABLE_STATUS_CODES.includes(response.status)) {
|
||||
try {
|
||||
response.headers.set(REROUTE_DIRECTIVE_HEADER, "no");
|
||||
} catch (err) {
|
||||
if (err.message?.includes("immutable")) {
|
||||
response = new Response(response.body, response);
|
||||
response.headers.set(REROUTE_DIRECTIVE_HEADER, "no");
|
||||
} else {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
}
|
||||
return response;
|
||||
}
|
||||
export {
|
||||
renderEndpoint
|
||||
};
|
22
node_modules/astro/dist/runtime/server/escape.d.ts
generated
vendored
Normal file
22
node_modules/astro/dist/runtime/server/escape.d.ts
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
import { escape } from 'html-escaper';
|
||||
export declare const escapeHTML: typeof escape;
|
||||
export declare class HTMLBytes extends Uint8Array {
|
||||
}
|
||||
/**
|
||||
* A "blessed" extension of String that tells Astro that the string
|
||||
* has already been escaped. This helps prevent double-escaping of HTML.
|
||||
*/
|
||||
export declare class HTMLString extends String {
|
||||
get [Symbol.toStringTag](): string;
|
||||
}
|
||||
type BlessedType = string | HTMLBytes;
|
||||
/**
|
||||
* markHTMLString marks a string as raw or "already escaped" by returning
|
||||
* a `HTMLString` instance. This is meant for internal use, and should not
|
||||
* be returned through any public JS API.
|
||||
*/
|
||||
export declare const markHTMLString: (value: any) => any;
|
||||
export declare function isHTMLString(value: any): value is HTMLString;
|
||||
export declare function isHTMLBytes(value: any): value is HTMLBytes;
|
||||
export declare function unescapeHTML(str: any): BlessedType | Promise<BlessedType | AsyncGenerator<BlessedType, void, unknown>> | AsyncGenerator<BlessedType, void, unknown>;
|
||||
export {};
|
82
node_modules/astro/dist/runtime/server/escape.js
generated
vendored
Normal file
82
node_modules/astro/dist/runtime/server/escape.js
generated
vendored
Normal file
@@ -0,0 +1,82 @@
|
||||
import { escape } from "html-escaper";
|
||||
import { streamAsyncIterator } from "./util.js";
|
||||
const escapeHTML = escape;
|
||||
class HTMLBytes extends Uint8Array {
|
||||
}
|
||||
Object.defineProperty(HTMLBytes.prototype, Symbol.toStringTag, {
|
||||
get() {
|
||||
return "HTMLBytes";
|
||||
}
|
||||
});
|
||||
class HTMLString extends String {
|
||||
get [Symbol.toStringTag]() {
|
||||
return "HTMLString";
|
||||
}
|
||||
}
|
||||
const markHTMLString = (value) => {
|
||||
if (value instanceof HTMLString) {
|
||||
return value;
|
||||
}
|
||||
if (typeof value === "string") {
|
||||
return new HTMLString(value);
|
||||
}
|
||||
return value;
|
||||
};
|
||||
function isHTMLString(value) {
|
||||
return Object.prototype.toString.call(value) === "[object HTMLString]";
|
||||
}
|
||||
function markHTMLBytes(bytes) {
|
||||
return new HTMLBytes(bytes);
|
||||
}
|
||||
function isHTMLBytes(value) {
|
||||
return Object.prototype.toString.call(value) === "[object HTMLBytes]";
|
||||
}
|
||||
function hasGetReader(obj) {
|
||||
return typeof obj.getReader === "function";
|
||||
}
|
||||
async function* unescapeChunksAsync(iterable) {
|
||||
if (hasGetReader(iterable)) {
|
||||
for await (const chunk of streamAsyncIterator(iterable)) {
|
||||
yield unescapeHTML(chunk);
|
||||
}
|
||||
} else {
|
||||
for await (const chunk of iterable) {
|
||||
yield unescapeHTML(chunk);
|
||||
}
|
||||
}
|
||||
}
|
||||
function* unescapeChunks(iterable) {
|
||||
for (const chunk of iterable) {
|
||||
yield unescapeHTML(chunk);
|
||||
}
|
||||
}
|
||||
function unescapeHTML(str) {
|
||||
if (!!str && typeof str === "object") {
|
||||
if (str instanceof Uint8Array) {
|
||||
return markHTMLBytes(str);
|
||||
} else if (str instanceof Response && str.body) {
|
||||
const body = str.body;
|
||||
return unescapeChunksAsync(body);
|
||||
} else if (typeof str.then === "function") {
|
||||
return Promise.resolve(str).then((value) => {
|
||||
return unescapeHTML(value);
|
||||
});
|
||||
} else if (str[Symbol.for("astro:slot-string")]) {
|
||||
return str;
|
||||
} else if (Symbol.iterator in str) {
|
||||
return unescapeChunks(str);
|
||||
} else if (Symbol.asyncIterator in str || hasGetReader(str)) {
|
||||
return unescapeChunksAsync(str);
|
||||
}
|
||||
}
|
||||
return markHTMLString(str);
|
||||
}
|
||||
export {
|
||||
HTMLBytes,
|
||||
HTMLString,
|
||||
escapeHTML,
|
||||
isHTMLBytes,
|
||||
isHTMLString,
|
||||
markHTMLString,
|
||||
unescapeHTML
|
||||
};
|
27
node_modules/astro/dist/runtime/server/hydration.d.ts
generated
vendored
Normal file
27
node_modules/astro/dist/runtime/server/hydration.d.ts
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
import type { AstroComponentMetadata, SSRElement, SSRLoadedRenderer, SSRResult } from '../../@types/astro.js';
|
||||
export interface HydrationMetadata {
|
||||
directive: string;
|
||||
value: string;
|
||||
componentUrl: string;
|
||||
componentExport: {
|
||||
value: string;
|
||||
};
|
||||
}
|
||||
type Props = Record<string | number | symbol, any>;
|
||||
interface ExtractedProps {
|
||||
isPage: boolean;
|
||||
hydration: HydrationMetadata | null;
|
||||
props: Props;
|
||||
propsWithoutTransitionAttributes: Props;
|
||||
}
|
||||
export declare function extractDirectives(inputProps: Props, clientDirectives: SSRResult['clientDirectives']): ExtractedProps;
|
||||
interface HydrateScriptOptions {
|
||||
renderer: SSRLoadedRenderer;
|
||||
result: SSRResult;
|
||||
astroId: string;
|
||||
props: Record<string | number, any>;
|
||||
attrs: Record<string, string> | undefined;
|
||||
}
|
||||
/** For hydrated components, generate a <script type="module"> to load the component */
|
||||
export declare function generateHydrateScript(scriptOptions: HydrateScriptOptions, metadata: Required<AstroComponentMetadata>): Promise<SSRElement>;
|
||||
export {};
|
123
node_modules/astro/dist/runtime/server/hydration.js
generated
vendored
Normal file
123
node_modules/astro/dist/runtime/server/hydration.js
generated
vendored
Normal file
@@ -0,0 +1,123 @@
|
||||
import { AstroError, AstroErrorData } from "../../core/errors/index.js";
|
||||
import { escapeHTML } from "./escape.js";
|
||||
import { serializeProps } from "./serialize.js";
|
||||
const transitionDirectivesToCopyOnIsland = Object.freeze([
|
||||
"data-astro-transition-scope",
|
||||
"data-astro-transition-persist",
|
||||
"data-astro-transition-persist-props"
|
||||
]);
|
||||
function extractDirectives(inputProps, clientDirectives) {
|
||||
let extracted = {
|
||||
isPage: false,
|
||||
hydration: null,
|
||||
props: {},
|
||||
propsWithoutTransitionAttributes: {}
|
||||
};
|
||||
for (const [key, value] of Object.entries(inputProps)) {
|
||||
if (key.startsWith("server:")) {
|
||||
if (key === "server:root") {
|
||||
extracted.isPage = true;
|
||||
}
|
||||
}
|
||||
if (key.startsWith("client:")) {
|
||||
if (!extracted.hydration) {
|
||||
extracted.hydration = {
|
||||
directive: "",
|
||||
value: "",
|
||||
componentUrl: "",
|
||||
componentExport: { value: "" }
|
||||
};
|
||||
}
|
||||
switch (key) {
|
||||
case "client:component-path": {
|
||||
extracted.hydration.componentUrl = value;
|
||||
break;
|
||||
}
|
||||
case "client:component-export": {
|
||||
extracted.hydration.componentExport.value = value;
|
||||
break;
|
||||
}
|
||||
case "client:component-hydration": {
|
||||
break;
|
||||
}
|
||||
case "client:display-name": {
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
extracted.hydration.directive = key.split(":")[1];
|
||||
extracted.hydration.value = value;
|
||||
if (!clientDirectives.has(extracted.hydration.directive)) {
|
||||
const hydrationMethods = Array.from(clientDirectives.keys()).map((d) => `client:${d}`).join(", ");
|
||||
throw new Error(
|
||||
`Error: invalid hydration directive "${key}". Supported hydration methods: ${hydrationMethods}`
|
||||
);
|
||||
}
|
||||
if (extracted.hydration.directive === "media" && typeof extracted.hydration.value !== "string") {
|
||||
throw new AstroError(AstroErrorData.MissingMediaQueryDirective);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
extracted.props[key] = value;
|
||||
if (!transitionDirectivesToCopyOnIsland.includes(key)) {
|
||||
extracted.propsWithoutTransitionAttributes[key] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const sym of Object.getOwnPropertySymbols(inputProps)) {
|
||||
extracted.props[sym] = inputProps[sym];
|
||||
extracted.propsWithoutTransitionAttributes[sym] = inputProps[sym];
|
||||
}
|
||||
return extracted;
|
||||
}
|
||||
async function generateHydrateScript(scriptOptions, metadata) {
|
||||
const { renderer, result, astroId, props, attrs } = scriptOptions;
|
||||
const { hydrate, componentUrl, componentExport } = metadata;
|
||||
if (!componentExport.value) {
|
||||
throw new AstroError({
|
||||
...AstroErrorData.NoMatchingImport,
|
||||
message: AstroErrorData.NoMatchingImport.message(metadata.displayName)
|
||||
});
|
||||
}
|
||||
const island = {
|
||||
children: "",
|
||||
props: {
|
||||
// This is for HMR, probably can avoid it in prod
|
||||
uid: astroId
|
||||
}
|
||||
};
|
||||
if (attrs) {
|
||||
for (const [key, value] of Object.entries(attrs)) {
|
||||
island.props[key] = escapeHTML(value);
|
||||
}
|
||||
}
|
||||
island.props["component-url"] = await result.resolve(decodeURI(componentUrl));
|
||||
if (renderer.clientEntrypoint) {
|
||||
island.props["component-export"] = componentExport.value;
|
||||
island.props["renderer-url"] = await result.resolve(decodeURI(renderer.clientEntrypoint));
|
||||
island.props["props"] = escapeHTML(serializeProps(props, metadata));
|
||||
}
|
||||
island.props["ssr"] = "";
|
||||
island.props["client"] = hydrate;
|
||||
let beforeHydrationUrl = await result.resolve("astro:scripts/before-hydration.js");
|
||||
if (beforeHydrationUrl.length) {
|
||||
island.props["before-hydration-url"] = beforeHydrationUrl;
|
||||
}
|
||||
island.props["opts"] = escapeHTML(
|
||||
JSON.stringify({
|
||||
name: metadata.displayName,
|
||||
value: metadata.hydrateArgs || ""
|
||||
})
|
||||
);
|
||||
transitionDirectivesToCopyOnIsland.forEach((name) => {
|
||||
if (typeof props[name] !== "undefined") {
|
||||
island.props[name] = props[name];
|
||||
}
|
||||
});
|
||||
return island;
|
||||
}
|
||||
export {
|
||||
extractDirectives,
|
||||
generateHydrateScript
|
||||
};
|
13
node_modules/astro/dist/runtime/server/index.d.ts
generated
vendored
Normal file
13
node_modules/astro/dist/runtime/server/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
export { createComponent } from './astro-component.js';
|
||||
export { createAstro } from './astro-global.js';
|
||||
export { renderEndpoint } from './endpoint.js';
|
||||
export { escapeHTML, HTMLBytes, HTMLString, isHTMLString, markHTMLString, unescapeHTML, } from './escape.js';
|
||||
export { renderJSX } from './jsx.js';
|
||||
export { addAttribute, createHeadAndContent, defineScriptVars, Fragment, maybeRenderHead, renderTemplate as render, renderComponent, Renderer as Renderer, renderHead, renderHTMLElement, renderPage, renderScript, renderScriptElement, renderSlot, renderSlotToString, renderTemplate, renderToString, renderUniqueStylesheet, voidElementNames, } from './render/index.js';
|
||||
export type { AstroComponentFactory, AstroComponentInstance, ComponentSlots, RenderInstruction, } from './render/index.js';
|
||||
export { createTransitionScope, renderTransition } from './transition.js';
|
||||
export declare function mergeSlots(...slotted: unknown[]): Record<string, () => any>;
|
||||
export declare function spreadAttributes(values?: Record<any, any>, _name?: string, { class: scopedClassName }?: {
|
||||
class?: string;
|
||||
}): any;
|
||||
export declare function defineStyleVars(defs: Record<any, any> | Record<any, any>[]): any;
|
122
node_modules/astro/dist/runtime/server/index.js
generated
vendored
Normal file
122
node_modules/astro/dist/runtime/server/index.js
generated
vendored
Normal file
@@ -0,0 +1,122 @@
|
||||
import { createComponent } from "./astro-component.js";
|
||||
import { createAstro } from "./astro-global.js";
|
||||
import { renderEndpoint } from "./endpoint.js";
|
||||
import {
|
||||
escapeHTML,
|
||||
HTMLBytes,
|
||||
HTMLString,
|
||||
isHTMLString,
|
||||
markHTMLString,
|
||||
unescapeHTML
|
||||
} from "./escape.js";
|
||||
import { renderJSX } from "./jsx.js";
|
||||
import {
|
||||
addAttribute,
|
||||
createHeadAndContent,
|
||||
defineScriptVars,
|
||||
Fragment,
|
||||
maybeRenderHead,
|
||||
renderTemplate,
|
||||
renderComponent,
|
||||
Renderer,
|
||||
renderHead,
|
||||
renderHTMLElement,
|
||||
renderPage,
|
||||
renderScript,
|
||||
renderScriptElement,
|
||||
renderSlot,
|
||||
renderSlotToString,
|
||||
renderTemplate as renderTemplate2,
|
||||
renderToString,
|
||||
renderUniqueStylesheet,
|
||||
voidElementNames
|
||||
} from "./render/index.js";
|
||||
import { createTransitionScope, renderTransition } from "./transition.js";
|
||||
import { markHTMLString as markHTMLString2 } from "./escape.js";
|
||||
import { Renderer as Renderer2, addAttribute as addAttribute2 } from "./render/index.js";
|
||||
function mergeSlots(...slotted) {
|
||||
const slots = {};
|
||||
for (const slot of slotted) {
|
||||
if (!slot) continue;
|
||||
if (typeof slot === "object") {
|
||||
Object.assign(slots, slot);
|
||||
} else if (typeof slot === "function") {
|
||||
Object.assign(slots, mergeSlots(slot()));
|
||||
}
|
||||
}
|
||||
return slots;
|
||||
}
|
||||
function __astro_tag_component__(Component, rendererName) {
|
||||
if (!Component) return;
|
||||
if (typeof Component !== "function") return;
|
||||
Object.defineProperty(Component, Renderer2, {
|
||||
value: rendererName,
|
||||
enumerable: false,
|
||||
writable: false
|
||||
});
|
||||
}
|
||||
function spreadAttributes(values = {}, _name, { class: scopedClassName } = {}) {
|
||||
let output = "";
|
||||
if (scopedClassName) {
|
||||
if (typeof values.class !== "undefined") {
|
||||
values.class += ` ${scopedClassName}`;
|
||||
} else if (typeof values["class:list"] !== "undefined") {
|
||||
values["class:list"] = [values["class:list"], scopedClassName];
|
||||
} else {
|
||||
values.class = scopedClassName;
|
||||
}
|
||||
}
|
||||
for (const [key, value] of Object.entries(values)) {
|
||||
output += addAttribute2(value, key, true);
|
||||
}
|
||||
return markHTMLString2(output);
|
||||
}
|
||||
function defineStyleVars(defs) {
|
||||
let output = "";
|
||||
let arr = !Array.isArray(defs) ? [defs] : defs;
|
||||
for (const vars of arr) {
|
||||
for (const [key, value] of Object.entries(vars)) {
|
||||
if (value || value === 0) {
|
||||
output += `--${key}: ${value};`;
|
||||
}
|
||||
}
|
||||
}
|
||||
return markHTMLString2(output);
|
||||
}
|
||||
export {
|
||||
Fragment,
|
||||
HTMLBytes,
|
||||
HTMLString,
|
||||
Renderer,
|
||||
__astro_tag_component__,
|
||||
addAttribute,
|
||||
createAstro,
|
||||
createComponent,
|
||||
createHeadAndContent,
|
||||
createTransitionScope,
|
||||
defineScriptVars,
|
||||
defineStyleVars,
|
||||
escapeHTML,
|
||||
isHTMLString,
|
||||
markHTMLString,
|
||||
maybeRenderHead,
|
||||
mergeSlots,
|
||||
renderTemplate as render,
|
||||
renderComponent,
|
||||
renderEndpoint,
|
||||
renderHTMLElement,
|
||||
renderHead,
|
||||
renderJSX,
|
||||
renderPage,
|
||||
renderScript,
|
||||
renderScriptElement,
|
||||
renderSlot,
|
||||
renderSlotToString,
|
||||
renderTemplate2 as renderTemplate,
|
||||
renderToString,
|
||||
renderTransition,
|
||||
renderUniqueStylesheet,
|
||||
spreadAttributes,
|
||||
unescapeHTML,
|
||||
voidElementNames
|
||||
};
|
2
node_modules/astro/dist/runtime/server/jsx.d.ts
generated
vendored
Normal file
2
node_modules/astro/dist/runtime/server/jsx.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import type { SSRResult } from '../../@types/astro.js';
|
||||
export declare function renderJSX(result: SSRResult, vnode: any): Promise<any>;
|
159
node_modules/astro/dist/runtime/server/jsx.js
generated
vendored
Normal file
159
node_modules/astro/dist/runtime/server/jsx.js
generated
vendored
Normal file
@@ -0,0 +1,159 @@
|
||||
import { AstroJSX, isVNode } from "../../jsx-runtime/index.js";
|
||||
import {
|
||||
HTMLString,
|
||||
escapeHTML,
|
||||
markHTMLString,
|
||||
renderToString,
|
||||
spreadAttributes,
|
||||
voidElementNames
|
||||
} from "./index.js";
|
||||
import { renderComponentToString } from "./render/component.js";
|
||||
const ClientOnlyPlaceholder = "astro-client-only";
|
||||
const hasTriedRenderComponentSymbol = Symbol("hasTriedRenderComponent");
|
||||
async function renderJSX(result, vnode) {
|
||||
switch (true) {
|
||||
case vnode instanceof HTMLString:
|
||||
if (vnode.toString().trim() === "") {
|
||||
return "";
|
||||
}
|
||||
return vnode;
|
||||
case typeof vnode === "string":
|
||||
return markHTMLString(escapeHTML(vnode));
|
||||
case typeof vnode === "function":
|
||||
return vnode;
|
||||
case (!vnode && vnode !== 0):
|
||||
return "";
|
||||
case Array.isArray(vnode):
|
||||
return markHTMLString(
|
||||
(await Promise.all(vnode.map((v) => renderJSX(result, v)))).join("")
|
||||
);
|
||||
}
|
||||
return renderJSXVNode(result, vnode);
|
||||
}
|
||||
async function renderJSXVNode(result, vnode) {
|
||||
if (isVNode(vnode)) {
|
||||
switch (true) {
|
||||
case !vnode.type: {
|
||||
throw new Error(`Unable to render ${result.pathname} because it contains an undefined Component!
|
||||
Did you forget to import the component or is it possible there is a typo?`);
|
||||
}
|
||||
case vnode.type === Symbol.for("astro:fragment"):
|
||||
return renderJSX(result, vnode.props.children);
|
||||
case vnode.type.isAstroComponentFactory: {
|
||||
let props = {};
|
||||
let slots = {};
|
||||
for (const [key, value] of Object.entries(vnode.props ?? {})) {
|
||||
if (key === "children" || value && typeof value === "object" && value["$$slot"]) {
|
||||
slots[key === "children" ? "default" : key] = () => renderJSX(result, value);
|
||||
} else {
|
||||
props[key] = value;
|
||||
}
|
||||
}
|
||||
const str = await renderToString(result, vnode.type, props, slots);
|
||||
if (str instanceof Response) {
|
||||
throw str;
|
||||
}
|
||||
const html = markHTMLString(str);
|
||||
return html;
|
||||
}
|
||||
case (!vnode.type && vnode.type !== 0):
|
||||
return "";
|
||||
case (typeof vnode.type === "string" && vnode.type !== ClientOnlyPlaceholder):
|
||||
return markHTMLString(await renderElement(result, vnode.type, vnode.props ?? {}));
|
||||
}
|
||||
if (vnode.type) {
|
||||
let extractSlots2 = function(child) {
|
||||
if (Array.isArray(child)) {
|
||||
return child.map((c) => extractSlots2(c));
|
||||
}
|
||||
if (!isVNode(child)) {
|
||||
_slots.default.push(child);
|
||||
return;
|
||||
}
|
||||
if ("slot" in child.props) {
|
||||
_slots[child.props.slot] = [..._slots[child.props.slot] ?? [], child];
|
||||
delete child.props.slot;
|
||||
return;
|
||||
}
|
||||
_slots.default.push(child);
|
||||
};
|
||||
var extractSlots = extractSlots2;
|
||||
if (typeof vnode.type === "function" && vnode.props["server:root"]) {
|
||||
const output2 = await vnode.type(vnode.props ?? {});
|
||||
return await renderJSX(result, output2);
|
||||
}
|
||||
if (typeof vnode.type === "function") {
|
||||
if (vnode.props[hasTriedRenderComponentSymbol]) {
|
||||
delete vnode.props[hasTriedRenderComponentSymbol];
|
||||
const output2 = await vnode.type(vnode.props ?? {});
|
||||
if (output2?.[AstroJSX] || !output2) {
|
||||
return await renderJSXVNode(result, output2);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
vnode.props[hasTriedRenderComponentSymbol] = true;
|
||||
}
|
||||
}
|
||||
const { children = null, ...props } = vnode.props ?? {};
|
||||
const _slots = {
|
||||
default: []
|
||||
};
|
||||
extractSlots2(children);
|
||||
for (const [key, value] of Object.entries(props)) {
|
||||
if (value?.["$$slot"]) {
|
||||
_slots[key] = value;
|
||||
delete props[key];
|
||||
}
|
||||
}
|
||||
const slotPromises = [];
|
||||
const slots = {};
|
||||
for (const [key, value] of Object.entries(_slots)) {
|
||||
slotPromises.push(
|
||||
renderJSX(result, value).then((output2) => {
|
||||
if (output2.toString().trim().length === 0) return;
|
||||
slots[key] = () => output2;
|
||||
})
|
||||
);
|
||||
}
|
||||
await Promise.all(slotPromises);
|
||||
let output;
|
||||
if (vnode.type === ClientOnlyPlaceholder && vnode.props["client:only"]) {
|
||||
output = await renderComponentToString(
|
||||
result,
|
||||
vnode.props["client:display-name"] ?? "",
|
||||
null,
|
||||
props,
|
||||
slots
|
||||
);
|
||||
} else {
|
||||
output = await renderComponentToString(
|
||||
result,
|
||||
typeof vnode.type === "function" ? vnode.type.name : vnode.type,
|
||||
vnode.type,
|
||||
props,
|
||||
slots
|
||||
);
|
||||
}
|
||||
return markHTMLString(output);
|
||||
}
|
||||
}
|
||||
return markHTMLString(`${vnode}`);
|
||||
}
|
||||
async function renderElement(result, tag, { children, ...props }) {
|
||||
return markHTMLString(
|
||||
`<${tag}${spreadAttributes(props)}${markHTMLString(
|
||||
(children == null || children == "") && voidElementNames.test(tag) ? `/>` : `>${children == null ? "" : await renderJSX(result, prerenderElementChildren(tag, children))}</${tag}>`
|
||||
)}`
|
||||
);
|
||||
}
|
||||
function prerenderElementChildren(tag, children) {
|
||||
if (typeof children === "string" && (tag === "style" || tag === "script")) {
|
||||
return markHTMLString(children);
|
||||
} else {
|
||||
return children;
|
||||
}
|
||||
}
|
||||
export {
|
||||
renderJSX
|
||||
};
|
2
node_modules/astro/dist/runtime/server/render/any.d.ts
generated
vendored
Normal file
2
node_modules/astro/dist/runtime/server/render/any.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import { type RenderDestination } from './common.js';
|
||||
export declare function renderChild(destination: RenderDestination, child: any): Promise<void>;
|
48
node_modules/astro/dist/runtime/server/render/any.js
generated
vendored
Normal file
48
node_modules/astro/dist/runtime/server/render/any.js
generated
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
import { escapeHTML, isHTMLString, markHTMLString } from "../escape.js";
|
||||
import { isPromise } from "../util.js";
|
||||
import { isAstroComponentInstance, isRenderTemplateResult } from "./astro/index.js";
|
||||
import { isRenderInstance } from "./common.js";
|
||||
import { SlotString } from "./slot.js";
|
||||
import { renderToBufferDestination } from "./util.js";
|
||||
async function renderChild(destination, child) {
|
||||
if (isPromise(child)) {
|
||||
child = await child;
|
||||
}
|
||||
if (child instanceof SlotString) {
|
||||
destination.write(child);
|
||||
} else if (isHTMLString(child)) {
|
||||
destination.write(child);
|
||||
} else if (Array.isArray(child)) {
|
||||
const childRenders = child.map((c) => {
|
||||
return renderToBufferDestination((bufferDestination) => {
|
||||
return renderChild(bufferDestination, c);
|
||||
});
|
||||
});
|
||||
for (const childRender of childRenders) {
|
||||
if (!childRender) continue;
|
||||
await childRender.renderToFinalDestination(destination);
|
||||
}
|
||||
} else if (typeof child === "function") {
|
||||
await renderChild(destination, child());
|
||||
} else if (typeof child === "string") {
|
||||
destination.write(markHTMLString(escapeHTML(child)));
|
||||
} else if (!child && child !== 0) {
|
||||
} else if (isRenderInstance(child)) {
|
||||
await child.render(destination);
|
||||
} else if (isRenderTemplateResult(child)) {
|
||||
await child.render(destination);
|
||||
} else if (isAstroComponentInstance(child)) {
|
||||
await child.render(destination);
|
||||
} else if (ArrayBuffer.isView(child)) {
|
||||
destination.write(child);
|
||||
} else if (typeof child === "object" && (Symbol.asyncIterator in child || Symbol.iterator in child)) {
|
||||
for await (const value of child) {
|
||||
await renderChild(destination, value);
|
||||
}
|
||||
} else {
|
||||
destination.write(child);
|
||||
}
|
||||
}
|
||||
export {
|
||||
renderChild
|
||||
};
|
12
node_modules/astro/dist/runtime/server/render/astro/factory.d.ts
generated
vendored
Normal file
12
node_modules/astro/dist/runtime/server/render/astro/factory.d.ts
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
import type { PropagationHint, SSRResult } from '../../../../@types/astro.js';
|
||||
import type { HeadAndContent } from './head-and-content.js';
|
||||
import type { RenderTemplateResult } from './render-template.js';
|
||||
export type AstroFactoryReturnValue = RenderTemplateResult | Response | HeadAndContent;
|
||||
export interface AstroComponentFactory {
|
||||
(result: any, props: any, slots: any): AstroFactoryReturnValue | Promise<AstroFactoryReturnValue>;
|
||||
isAstroComponentFactory?: boolean;
|
||||
moduleId?: string | undefined;
|
||||
propagation?: PropagationHint;
|
||||
}
|
||||
export declare function isAstroComponentFactory(obj: any): obj is AstroComponentFactory;
|
||||
export declare function isAPropagatingComponent(result: SSRResult, factory: AstroComponentFactory): boolean;
|
14
node_modules/astro/dist/runtime/server/render/astro/factory.js
generated
vendored
Normal file
14
node_modules/astro/dist/runtime/server/render/astro/factory.js
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
function isAstroComponentFactory(obj) {
|
||||
return obj == null ? false : obj.isAstroComponentFactory === true;
|
||||
}
|
||||
function isAPropagatingComponent(result, factory) {
|
||||
let hint = factory.propagation || "none";
|
||||
if (factory.moduleId && result.componentMetadata.has(factory.moduleId) && hint === "none") {
|
||||
hint = result.componentMetadata.get(factory.moduleId).propagation;
|
||||
}
|
||||
return hint === "in-tree" || hint === "self";
|
||||
}
|
||||
export {
|
||||
isAPropagatingComponent,
|
||||
isAstroComponentFactory
|
||||
};
|
10
node_modules/astro/dist/runtime/server/render/astro/head-and-content.d.ts
generated
vendored
Normal file
10
node_modules/astro/dist/runtime/server/render/astro/head-and-content.d.ts
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
import type { RenderTemplateResult } from './render-template.js';
|
||||
declare const headAndContentSym: unique symbol;
|
||||
export type HeadAndContent = {
|
||||
[headAndContentSym]: true;
|
||||
head: string;
|
||||
content: RenderTemplateResult;
|
||||
};
|
||||
export declare function isHeadAndContent(obj: unknown): obj is HeadAndContent;
|
||||
export declare function createHeadAndContent(head: string, content: RenderTemplateResult): HeadAndContent;
|
||||
export {};
|
15
node_modules/astro/dist/runtime/server/render/astro/head-and-content.js
generated
vendored
Normal file
15
node_modules/astro/dist/runtime/server/render/astro/head-and-content.js
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
const headAndContentSym = Symbol.for("astro.headAndContent");
|
||||
function isHeadAndContent(obj) {
|
||||
return typeof obj === "object" && obj !== null && !!obj[headAndContentSym];
|
||||
}
|
||||
function createHeadAndContent(head, content) {
|
||||
return {
|
||||
[headAndContentSym]: true,
|
||||
head,
|
||||
content
|
||||
};
|
||||
}
|
||||
export {
|
||||
createHeadAndContent,
|
||||
isHeadAndContent
|
||||
};
|
7
node_modules/astro/dist/runtime/server/render/astro/index.d.ts
generated
vendored
Normal file
7
node_modules/astro/dist/runtime/server/render/astro/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
export { isAstroComponentFactory } from './factory.js';
|
||||
export type { AstroComponentFactory } from './factory.js';
|
||||
export { createHeadAndContent, isHeadAndContent } from './head-and-content.js';
|
||||
export { createAstroComponentInstance, isAstroComponentInstance } from './instance.js';
|
||||
export type { AstroComponentInstance } from './instance.js';
|
||||
export { isRenderTemplateResult, renderTemplate } from './render-template.js';
|
||||
export { renderToReadableStream, renderToString } from './render.js';
|
16
node_modules/astro/dist/runtime/server/render/astro/index.js
generated
vendored
Normal file
16
node_modules/astro/dist/runtime/server/render/astro/index.js
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
import { isAstroComponentFactory } from "./factory.js";
|
||||
import { createHeadAndContent, isHeadAndContent } from "./head-and-content.js";
|
||||
import { createAstroComponentInstance, isAstroComponentInstance } from "./instance.js";
|
||||
import { isRenderTemplateResult, renderTemplate } from "./render-template.js";
|
||||
import { renderToReadableStream, renderToString } from "./render.js";
|
||||
export {
|
||||
createAstroComponentInstance,
|
||||
createHeadAndContent,
|
||||
isAstroComponentFactory,
|
||||
isAstroComponentInstance,
|
||||
isHeadAndContent,
|
||||
isRenderTemplateResult,
|
||||
renderTemplate,
|
||||
renderToReadableStream,
|
||||
renderToString
|
||||
};
|
20
node_modules/astro/dist/runtime/server/render/astro/instance.d.ts
generated
vendored
Normal file
20
node_modules/astro/dist/runtime/server/render/astro/instance.d.ts
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
import type { SSRResult } from '../../../../@types/astro.js';
|
||||
import type { ComponentSlots } from '../slot.js';
|
||||
import type { AstroComponentFactory } from './factory.js';
|
||||
import type { RenderDestination } from '../common.js';
|
||||
type ComponentProps = Record<string | number, any>;
|
||||
declare const astroComponentInstanceSym: unique symbol;
|
||||
export declare class AstroComponentInstance {
|
||||
[astroComponentInstanceSym]: boolean;
|
||||
private readonly result;
|
||||
private readonly props;
|
||||
private readonly slotValues;
|
||||
private readonly factory;
|
||||
private returnValue;
|
||||
constructor(result: SSRResult, props: ComponentProps, slots: ComponentSlots, factory: AstroComponentFactory);
|
||||
init(result: SSRResult): Promise<import("./factory.js").AstroFactoryReturnValue>;
|
||||
render(destination: RenderDestination): Promise<void>;
|
||||
}
|
||||
export declare function createAstroComponentInstance(result: SSRResult, displayName: string, factory: AstroComponentFactory, props: ComponentProps, slots?: any): AstroComponentInstance;
|
||||
export declare function isAstroComponentInstance(obj: unknown): obj is AstroComponentInstance;
|
||||
export {};
|
76
node_modules/astro/dist/runtime/server/render/astro/instance.js
generated
vendored
Normal file
76
node_modules/astro/dist/runtime/server/render/astro/instance.js
generated
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
import { isPromise } from "../../util.js";
|
||||
import { renderChild } from "../any.js";
|
||||
import { isAPropagatingComponent } from "./factory.js";
|
||||
import { isHeadAndContent } from "./head-and-content.js";
|
||||
const astroComponentInstanceSym = Symbol.for("astro.componentInstance");
|
||||
class AstroComponentInstance {
|
||||
[astroComponentInstanceSym] = true;
|
||||
result;
|
||||
props;
|
||||
slotValues;
|
||||
factory;
|
||||
returnValue;
|
||||
constructor(result, props, slots, factory) {
|
||||
this.result = result;
|
||||
this.props = props;
|
||||
this.factory = factory;
|
||||
this.slotValues = {};
|
||||
for (const name in slots) {
|
||||
let didRender = false;
|
||||
let value = slots[name](result);
|
||||
this.slotValues[name] = () => {
|
||||
if (!didRender) {
|
||||
didRender = true;
|
||||
return value;
|
||||
}
|
||||
return slots[name](result);
|
||||
};
|
||||
}
|
||||
}
|
||||
async init(result) {
|
||||
if (this.returnValue !== void 0) return this.returnValue;
|
||||
this.returnValue = this.factory(result, this.props, this.slotValues);
|
||||
if (isPromise(this.returnValue)) {
|
||||
this.returnValue.then((resolved) => {
|
||||
this.returnValue = resolved;
|
||||
}).catch(() => {
|
||||
});
|
||||
}
|
||||
return this.returnValue;
|
||||
}
|
||||
async render(destination) {
|
||||
const returnValue = await this.init(this.result);
|
||||
if (isHeadAndContent(returnValue)) {
|
||||
await returnValue.content.render(destination);
|
||||
} else {
|
||||
await renderChild(destination, returnValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
function validateComponentProps(props, displayName) {
|
||||
if (props != null) {
|
||||
for (const prop of Object.keys(props)) {
|
||||
if (prop.startsWith("client:")) {
|
||||
console.warn(
|
||||
`You are attempting to render <${displayName} ${prop} />, but ${displayName} is an Astro component. Astro components do not render in the client and should not have a hydration directive. Please use a framework component for client rendering.`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
function createAstroComponentInstance(result, displayName, factory, props, slots = {}) {
|
||||
validateComponentProps(props, displayName);
|
||||
const instance = new AstroComponentInstance(result, props, slots, factory);
|
||||
if (isAPropagatingComponent(result, factory)) {
|
||||
result._metadata.propagators.add(instance);
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
function isAstroComponentInstance(obj) {
|
||||
return typeof obj === "object" && obj !== null && !!obj[astroComponentInstanceSym];
|
||||
}
|
||||
export {
|
||||
AstroComponentInstance,
|
||||
createAstroComponentInstance,
|
||||
isAstroComponentInstance
|
||||
};
|
13
node_modules/astro/dist/runtime/server/render/astro/render-template.d.ts
generated
vendored
Normal file
13
node_modules/astro/dist/runtime/server/render/astro/render-template.d.ts
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
import type { RenderDestination } from '../common.js';
|
||||
declare const renderTemplateResultSym: unique symbol;
|
||||
export declare class RenderTemplateResult {
|
||||
[renderTemplateResultSym]: boolean;
|
||||
private htmlParts;
|
||||
expressions: any[];
|
||||
private error;
|
||||
constructor(htmlParts: TemplateStringsArray, expressions: unknown[]);
|
||||
render(destination: RenderDestination): Promise<void>;
|
||||
}
|
||||
export declare function isRenderTemplateResult(obj: unknown): obj is RenderTemplateResult;
|
||||
export declare function renderTemplate(htmlParts: TemplateStringsArray, ...expressions: any[]): RenderTemplateResult;
|
||||
export {};
|
54
node_modules/astro/dist/runtime/server/render/astro/render-template.js
generated
vendored
Normal file
54
node_modules/astro/dist/runtime/server/render/astro/render-template.js
generated
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
import { markHTMLString } from "../../escape.js";
|
||||
import { isPromise } from "../../util.js";
|
||||
import { renderChild } from "../any.js";
|
||||
import { renderToBufferDestination } from "../util.js";
|
||||
const renderTemplateResultSym = Symbol.for("astro.renderTemplateResult");
|
||||
class RenderTemplateResult {
|
||||
[renderTemplateResultSym] = true;
|
||||
htmlParts;
|
||||
expressions;
|
||||
error;
|
||||
constructor(htmlParts, expressions) {
|
||||
this.htmlParts = htmlParts;
|
||||
this.error = void 0;
|
||||
this.expressions = expressions.map((expression) => {
|
||||
if (isPromise(expression)) {
|
||||
return Promise.resolve(expression).catch((err) => {
|
||||
if (!this.error) {
|
||||
this.error = err;
|
||||
throw err;
|
||||
}
|
||||
});
|
||||
}
|
||||
return expression;
|
||||
});
|
||||
}
|
||||
async render(destination) {
|
||||
const expRenders = this.expressions.map((exp) => {
|
||||
return renderToBufferDestination((bufferDestination) => {
|
||||
if (exp || exp === 0) {
|
||||
return renderChild(bufferDestination, exp);
|
||||
}
|
||||
});
|
||||
});
|
||||
for (let i = 0; i < this.htmlParts.length; i++) {
|
||||
const html = this.htmlParts[i];
|
||||
const expRender = expRenders[i];
|
||||
destination.write(markHTMLString(html));
|
||||
if (expRender) {
|
||||
await expRender.renderToFinalDestination(destination);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
function isRenderTemplateResult(obj) {
|
||||
return typeof obj === "object" && obj !== null && !!obj[renderTemplateResultSym];
|
||||
}
|
||||
function renderTemplate(htmlParts, ...expressions) {
|
||||
return new RenderTemplateResult(htmlParts, expressions);
|
||||
}
|
||||
export {
|
||||
RenderTemplateResult,
|
||||
isRenderTemplateResult,
|
||||
renderTemplate
|
||||
};
|
5
node_modules/astro/dist/runtime/server/render/astro/render.d.ts
generated
vendored
Normal file
5
node_modules/astro/dist/runtime/server/render/astro/render.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
import type { RouteData, SSRResult } from '../../../../@types/astro.js';
|
||||
import type { AstroComponentFactory } from './factory.js';
|
||||
export declare function renderToString(result: SSRResult, componentFactory: AstroComponentFactory, props: any, children: any, isPage?: boolean, route?: RouteData): Promise<string | Response>;
|
||||
export declare function renderToReadableStream(result: SSRResult, componentFactory: AstroComponentFactory, props: any, children: any, isPage?: boolean, route?: RouteData): Promise<ReadableStream | Response>;
|
||||
export declare function renderToAsyncIterable(result: SSRResult, componentFactory: AstroComponentFactory, props: any, children: any, isPage?: boolean, route?: RouteData): Promise<AsyncIterable<Uint8Array> | Response>;
|
228
node_modules/astro/dist/runtime/server/render/astro/render.js
generated
vendored
Normal file
228
node_modules/astro/dist/runtime/server/render/astro/render.js
generated
vendored
Normal file
@@ -0,0 +1,228 @@
|
||||
import { AstroError, AstroErrorData } from "../../../../core/errors/index.js";
|
||||
import { chunkToByteArray, chunkToString, encoder } from "../common.js";
|
||||
import { promiseWithResolvers } from "../util.js";
|
||||
import { isHeadAndContent } from "./head-and-content.js";
|
||||
import { isRenderTemplateResult } from "./render-template.js";
|
||||
const DOCTYPE_EXP = /<!doctype html/i;
|
||||
async function renderToString(result, componentFactory, props, children, isPage = false, route) {
|
||||
const templateResult = await callComponentAsTemplateResultOrResponse(
|
||||
result,
|
||||
componentFactory,
|
||||
props,
|
||||
children,
|
||||
route
|
||||
);
|
||||
if (templateResult instanceof Response) return templateResult;
|
||||
let str = "";
|
||||
let renderedFirstPageChunk = false;
|
||||
if (isPage) {
|
||||
await bufferHeadContent(result);
|
||||
}
|
||||
const destination = {
|
||||
write(chunk) {
|
||||
if (isPage && !renderedFirstPageChunk) {
|
||||
renderedFirstPageChunk = true;
|
||||
if (!result.partial && !DOCTYPE_EXP.test(String(chunk))) {
|
||||
const doctype = result.compressHTML ? "<!DOCTYPE html>" : "<!DOCTYPE html>\n";
|
||||
str += doctype;
|
||||
}
|
||||
}
|
||||
if (chunk instanceof Response) return;
|
||||
str += chunkToString(result, chunk);
|
||||
}
|
||||
};
|
||||
await templateResult.render(destination);
|
||||
return str;
|
||||
}
|
||||
async function renderToReadableStream(result, componentFactory, props, children, isPage = false, route) {
|
||||
const templateResult = await callComponentAsTemplateResultOrResponse(
|
||||
result,
|
||||
componentFactory,
|
||||
props,
|
||||
children,
|
||||
route
|
||||
);
|
||||
if (templateResult instanceof Response) return templateResult;
|
||||
let renderedFirstPageChunk = false;
|
||||
if (isPage) {
|
||||
await bufferHeadContent(result);
|
||||
}
|
||||
return new ReadableStream({
|
||||
start(controller) {
|
||||
const destination = {
|
||||
write(chunk) {
|
||||
if (isPage && !renderedFirstPageChunk) {
|
||||
renderedFirstPageChunk = true;
|
||||
if (!result.partial && !DOCTYPE_EXP.test(String(chunk))) {
|
||||
const doctype = result.compressHTML ? "<!DOCTYPE html>" : "<!DOCTYPE html>\n";
|
||||
controller.enqueue(encoder.encode(doctype));
|
||||
}
|
||||
}
|
||||
if (chunk instanceof Response) {
|
||||
throw new AstroError({
|
||||
...AstroErrorData.ResponseSentError
|
||||
});
|
||||
}
|
||||
const bytes = chunkToByteArray(result, chunk);
|
||||
controller.enqueue(bytes);
|
||||
}
|
||||
};
|
||||
(async () => {
|
||||
try {
|
||||
await templateResult.render(destination);
|
||||
controller.close();
|
||||
} catch (e) {
|
||||
if (AstroError.is(e) && !e.loc) {
|
||||
e.setLocation({
|
||||
file: route?.component
|
||||
});
|
||||
}
|
||||
setTimeout(() => controller.error(e), 0);
|
||||
}
|
||||
})();
|
||||
},
|
||||
cancel() {
|
||||
result.cancelled = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
async function callComponentAsTemplateResultOrResponse(result, componentFactory, props, children, route) {
|
||||
const factoryResult = await componentFactory(result, props, children);
|
||||
if (factoryResult instanceof Response) {
|
||||
return factoryResult;
|
||||
} else if (isHeadAndContent(factoryResult)) {
|
||||
if (!isRenderTemplateResult(factoryResult.content)) {
|
||||
throw new AstroError({
|
||||
...AstroErrorData.OnlyResponseCanBeReturned,
|
||||
message: AstroErrorData.OnlyResponseCanBeReturned.message(
|
||||
route?.route,
|
||||
typeof factoryResult
|
||||
),
|
||||
location: {
|
||||
file: route?.component
|
||||
}
|
||||
});
|
||||
}
|
||||
return factoryResult.content;
|
||||
} else if (!isRenderTemplateResult(factoryResult)) {
|
||||
throw new AstroError({
|
||||
...AstroErrorData.OnlyResponseCanBeReturned,
|
||||
message: AstroErrorData.OnlyResponseCanBeReturned.message(route?.route, typeof factoryResult),
|
||||
location: {
|
||||
file: route?.component
|
||||
}
|
||||
});
|
||||
}
|
||||
return factoryResult;
|
||||
}
|
||||
async function bufferHeadContent(result) {
|
||||
const iterator = result._metadata.propagators.values();
|
||||
while (true) {
|
||||
const { value, done } = iterator.next();
|
||||
if (done) {
|
||||
break;
|
||||
}
|
||||
const returnValue = await value.init(result);
|
||||
if (isHeadAndContent(returnValue)) {
|
||||
result._metadata.extraHead.push(returnValue.head);
|
||||
}
|
||||
}
|
||||
}
|
||||
async function renderToAsyncIterable(result, componentFactory, props, children, isPage = false, route) {
|
||||
const templateResult = await callComponentAsTemplateResultOrResponse(
|
||||
result,
|
||||
componentFactory,
|
||||
props,
|
||||
children,
|
||||
route
|
||||
);
|
||||
if (templateResult instanceof Response) return templateResult;
|
||||
let renderedFirstPageChunk = false;
|
||||
if (isPage) {
|
||||
await bufferHeadContent(result);
|
||||
}
|
||||
let error = null;
|
||||
let next = null;
|
||||
const buffer = [];
|
||||
let renderingComplete = false;
|
||||
const iterator = {
|
||||
async next() {
|
||||
if (result.cancelled) return { done: true, value: void 0 };
|
||||
if (next !== null) {
|
||||
await next.promise;
|
||||
} else if (!renderingComplete && !buffer.length) {
|
||||
next = promiseWithResolvers();
|
||||
await next.promise;
|
||||
}
|
||||
if (!renderingComplete) {
|
||||
next = promiseWithResolvers();
|
||||
}
|
||||
if (error) {
|
||||
throw error;
|
||||
}
|
||||
let length = 0;
|
||||
for (let i = 0, len = buffer.length; i < len; i++) {
|
||||
length += buffer[i].length;
|
||||
}
|
||||
let mergedArray = new Uint8Array(length);
|
||||
let offset = 0;
|
||||
for (let i = 0, len = buffer.length; i < len; i++) {
|
||||
const item = buffer[i];
|
||||
mergedArray.set(item, offset);
|
||||
offset += item.length;
|
||||
}
|
||||
buffer.length = 0;
|
||||
const returnValue = {
|
||||
// The iterator is done when rendering has finished
|
||||
// and there are no more chunks to return.
|
||||
done: length === 0 && renderingComplete,
|
||||
value: mergedArray
|
||||
};
|
||||
return returnValue;
|
||||
},
|
||||
async return() {
|
||||
result.cancelled = true;
|
||||
return { done: true, value: void 0 };
|
||||
}
|
||||
};
|
||||
const destination = {
|
||||
write(chunk) {
|
||||
if (isPage && !renderedFirstPageChunk) {
|
||||
renderedFirstPageChunk = true;
|
||||
if (!result.partial && !DOCTYPE_EXP.test(String(chunk))) {
|
||||
const doctype = result.compressHTML ? "<!DOCTYPE html>" : "<!DOCTYPE html>\n";
|
||||
buffer.push(encoder.encode(doctype));
|
||||
}
|
||||
}
|
||||
if (chunk instanceof Response) {
|
||||
throw new AstroError(AstroErrorData.ResponseSentError);
|
||||
}
|
||||
const bytes = chunkToByteArray(result, chunk);
|
||||
if (bytes.length > 0) {
|
||||
buffer.push(bytes);
|
||||
next?.resolve();
|
||||
} else if (buffer.length > 0) {
|
||||
next?.resolve();
|
||||
}
|
||||
}
|
||||
};
|
||||
const renderPromise = templateResult.render(destination);
|
||||
renderPromise.then(() => {
|
||||
renderingComplete = true;
|
||||
next?.resolve();
|
||||
}).catch((err) => {
|
||||
error = err;
|
||||
renderingComplete = true;
|
||||
next?.resolve();
|
||||
});
|
||||
return {
|
||||
[Symbol.asyncIterator]() {
|
||||
return iterator;
|
||||
}
|
||||
};
|
||||
}
|
||||
export {
|
||||
renderToAsyncIterable,
|
||||
renderToReadableStream,
|
||||
renderToString
|
||||
};
|
30
node_modules/astro/dist/runtime/server/render/common.d.ts
generated
vendored
Normal file
30
node_modules/astro/dist/runtime/server/render/common.d.ts
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
import type { SSRResult } from '../../../@types/astro.js';
|
||||
import type { RenderInstruction } from './instruction.js';
|
||||
import type { HTMLBytes, HTMLString } from '../escape.js';
|
||||
import { type SlotString } from './slot.js';
|
||||
/**
|
||||
* Possible chunk types to be written to the destination, and it'll
|
||||
* handle stringifying them at the end.
|
||||
*
|
||||
* NOTE: Try to reduce adding new types here. If possible, serialize
|
||||
* the custom types to a string in `renderChild` in `any.ts`.
|
||||
*/
|
||||
export type RenderDestinationChunk = string | HTMLBytes | HTMLString | SlotString | ArrayBufferView | RenderInstruction | Response;
|
||||
export interface RenderDestination {
|
||||
/**
|
||||
* Any rendering logic should call this to construct the HTML output.
|
||||
* See the `chunk` parameter for possible writable values.
|
||||
*/
|
||||
write(chunk: RenderDestinationChunk): void;
|
||||
}
|
||||
export interface RenderInstance {
|
||||
render: RenderFunction;
|
||||
}
|
||||
export type RenderFunction = (destination: RenderDestination) => Promise<void> | void;
|
||||
export declare const Fragment: unique symbol;
|
||||
export declare const Renderer: unique symbol;
|
||||
export declare const encoder: TextEncoder;
|
||||
export declare const decoder: TextDecoder;
|
||||
export declare function chunkToString(result: SSRResult, chunk: Exclude<RenderDestinationChunk, Response>): string;
|
||||
export declare function chunkToByteArray(result: SSRResult, chunk: Exclude<RenderDestinationChunk, Response>): Uint8Array;
|
||||
export declare function isRenderInstance(obj: unknown): obj is RenderInstance;
|
96
node_modules/astro/dist/runtime/server/render/common.js
generated
vendored
Normal file
96
node_modules/astro/dist/runtime/server/render/common.js
generated
vendored
Normal file
@@ -0,0 +1,96 @@
|
||||
import { markHTMLString } from "../escape.js";
|
||||
import {
|
||||
determineIfNeedsHydrationScript,
|
||||
determinesIfNeedsDirectiveScript,
|
||||
getPrescripts
|
||||
} from "../scripts.js";
|
||||
import { renderAllHeadContent } from "./head.js";
|
||||
import { isRenderInstruction } from "./instruction.js";
|
||||
import { isSlotString } from "./slot.js";
|
||||
const Fragment = Symbol.for("astro:fragment");
|
||||
const Renderer = Symbol.for("astro:renderer");
|
||||
const encoder = new TextEncoder();
|
||||
const decoder = new TextDecoder();
|
||||
function stringifyChunk(result, chunk) {
|
||||
if (isRenderInstruction(chunk)) {
|
||||
const instruction = chunk;
|
||||
switch (instruction.type) {
|
||||
case "directive": {
|
||||
const { hydration } = instruction;
|
||||
let needsHydrationScript = hydration && determineIfNeedsHydrationScript(result);
|
||||
let needsDirectiveScript = hydration && determinesIfNeedsDirectiveScript(result, hydration.directive);
|
||||
let prescriptType = needsHydrationScript ? "both" : needsDirectiveScript ? "directive" : null;
|
||||
if (prescriptType) {
|
||||
let prescripts = getPrescripts(result, prescriptType, hydration.directive);
|
||||
return markHTMLString(prescripts);
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
case "head": {
|
||||
if (result._metadata.hasRenderedHead || result.partial) {
|
||||
return "";
|
||||
}
|
||||
return renderAllHeadContent(result);
|
||||
}
|
||||
case "maybe-head": {
|
||||
if (result._metadata.hasRenderedHead || result._metadata.headInTree || result.partial) {
|
||||
return "";
|
||||
}
|
||||
return renderAllHeadContent(result);
|
||||
}
|
||||
case "renderer-hydration-script": {
|
||||
const { rendererSpecificHydrationScripts } = result._metadata;
|
||||
const { rendererName } = instruction;
|
||||
if (!rendererSpecificHydrationScripts.has(rendererName)) {
|
||||
rendererSpecificHydrationScripts.add(rendererName);
|
||||
return instruction.render();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
default: {
|
||||
throw new Error(`Unknown chunk type: ${chunk.type}`);
|
||||
}
|
||||
}
|
||||
} else if (chunk instanceof Response) {
|
||||
return "";
|
||||
} else if (isSlotString(chunk)) {
|
||||
let out = "";
|
||||
const c = chunk;
|
||||
if (c.instructions) {
|
||||
for (const instr of c.instructions) {
|
||||
out += stringifyChunk(result, instr);
|
||||
}
|
||||
}
|
||||
out += chunk.toString();
|
||||
return out;
|
||||
}
|
||||
return chunk.toString();
|
||||
}
|
||||
function chunkToString(result, chunk) {
|
||||
if (ArrayBuffer.isView(chunk)) {
|
||||
return decoder.decode(chunk);
|
||||
} else {
|
||||
return stringifyChunk(result, chunk);
|
||||
}
|
||||
}
|
||||
function chunkToByteArray(result, chunk) {
|
||||
if (ArrayBuffer.isView(chunk)) {
|
||||
return chunk;
|
||||
} else {
|
||||
const stringified = stringifyChunk(result, chunk);
|
||||
return encoder.encode(stringified.toString());
|
||||
}
|
||||
}
|
||||
function isRenderInstance(obj) {
|
||||
return !!obj && typeof obj === "object" && "render" in obj && typeof obj.render === "function";
|
||||
}
|
||||
export {
|
||||
Fragment,
|
||||
Renderer,
|
||||
chunkToByteArray,
|
||||
chunkToString,
|
||||
decoder,
|
||||
encoder,
|
||||
isRenderInstance
|
||||
};
|
11
node_modules/astro/dist/runtime/server/render/component.d.ts
generated
vendored
Normal file
11
node_modules/astro/dist/runtime/server/render/component.d.ts
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
import type { RouteData, SSRResult } from '../../../@types/astro.js';
|
||||
import { type RenderInstance } from './common.js';
|
||||
import { type ComponentSlots } from './slot.js';
|
||||
declare const needsHeadRenderingSymbol: unique symbol;
|
||||
export declare function renderComponent(result: SSRResult, displayName: string, Component: unknown, props: Record<string | number, any>, slots?: ComponentSlots): Promise<RenderInstance>;
|
||||
export declare function renderComponentToString(result: SSRResult, displayName: string, Component: unknown, props: Record<string | number, any>, slots?: any, isPage?: boolean, route?: RouteData): Promise<string>;
|
||||
export type NonAstroPageComponent = {
|
||||
name: string;
|
||||
[needsHeadRenderingSymbol]: boolean;
|
||||
};
|
||||
export {};
|
447
node_modules/astro/dist/runtime/server/render/component.js
generated
vendored
Normal file
447
node_modules/astro/dist/runtime/server/render/component.js
generated
vendored
Normal file
@@ -0,0 +1,447 @@
|
||||
import { createRenderInstruction } from "./instruction.js";
|
||||
import { clsx } from "clsx";
|
||||
import { AstroError, AstroErrorData } from "../../../core/errors/index.js";
|
||||
import { markHTMLString } from "../escape.js";
|
||||
import { extractDirectives, generateHydrateScript } from "../hydration.js";
|
||||
import { serializeProps } from "../serialize.js";
|
||||
import { shorthash } from "../shorthash.js";
|
||||
import { isPromise } from "../util.js";
|
||||
import { isAstroComponentFactory } from "./astro/factory.js";
|
||||
import { renderTemplate } from "./astro/index.js";
|
||||
import { createAstroComponentInstance } from "./astro/instance.js";
|
||||
import {
|
||||
Fragment,
|
||||
Renderer,
|
||||
chunkToString
|
||||
} from "./common.js";
|
||||
import { componentIsHTMLElement, renderHTMLElement } from "./dom.js";
|
||||
import { maybeRenderHead } from "./head.js";
|
||||
import { containsServerDirective, renderServerIsland } from "./server-islands.js";
|
||||
import { renderSlotToString, renderSlots } from "./slot.js";
|
||||
import { formatList, internalSpreadAttributes, renderElement, voidElementNames } from "./util.js";
|
||||
const needsHeadRenderingSymbol = Symbol.for("astro.needsHeadRendering");
|
||||
const rendererAliases = /* @__PURE__ */ new Map([["solid", "solid-js"]]);
|
||||
const clientOnlyValues = /* @__PURE__ */ new Set(["solid-js", "react", "preact", "vue", "svelte", "lit"]);
|
||||
function guessRenderers(componentUrl) {
|
||||
const extname = componentUrl?.split(".").pop();
|
||||
switch (extname) {
|
||||
case "svelte":
|
||||
return ["@astrojs/svelte"];
|
||||
case "vue":
|
||||
return ["@astrojs/vue"];
|
||||
case "jsx":
|
||||
case "tsx":
|
||||
return ["@astrojs/react", "@astrojs/preact", "@astrojs/solid-js", "@astrojs/vue (jsx)"];
|
||||
case void 0:
|
||||
default:
|
||||
return [
|
||||
"@astrojs/react",
|
||||
"@astrojs/preact",
|
||||
"@astrojs/solid-js",
|
||||
"@astrojs/vue",
|
||||
"@astrojs/svelte",
|
||||
"@astrojs/lit"
|
||||
];
|
||||
}
|
||||
}
|
||||
function isFragmentComponent(Component) {
|
||||
return Component === Fragment;
|
||||
}
|
||||
function isHTMLComponent(Component) {
|
||||
return Component && Component["astro:html"] === true;
|
||||
}
|
||||
const ASTRO_SLOT_EXP = /<\/?astro-slot\b[^>]*>/g;
|
||||
const ASTRO_STATIC_SLOT_EXP = /<\/?astro-static-slot\b[^>]*>/g;
|
||||
function removeStaticAstroSlot(html, supportsAstroStaticSlot = true) {
|
||||
const exp = supportsAstroStaticSlot ? ASTRO_STATIC_SLOT_EXP : ASTRO_SLOT_EXP;
|
||||
return html.replace(exp, "");
|
||||
}
|
||||
async function renderFrameworkComponent(result, displayName, Component, _props, slots = {}) {
|
||||
if (!Component && "client:only" in _props === false) {
|
||||
throw new Error(
|
||||
`Unable to render ${displayName} because it is ${Component}!
|
||||
Did you forget to import the component or is it possible there is a typo?`
|
||||
);
|
||||
}
|
||||
const { renderers, clientDirectives } = result;
|
||||
const metadata = {
|
||||
astroStaticSlot: true,
|
||||
displayName
|
||||
};
|
||||
const { hydration, isPage, props, propsWithoutTransitionAttributes } = extractDirectives(
|
||||
_props,
|
||||
clientDirectives
|
||||
);
|
||||
let html = "";
|
||||
let attrs = void 0;
|
||||
if (hydration) {
|
||||
metadata.hydrate = hydration.directive;
|
||||
metadata.hydrateArgs = hydration.value;
|
||||
metadata.componentExport = hydration.componentExport;
|
||||
metadata.componentUrl = hydration.componentUrl;
|
||||
}
|
||||
const probableRendererNames = guessRenderers(metadata.componentUrl);
|
||||
const validRenderers = renderers.filter((r) => r.name !== "astro:jsx");
|
||||
const { children, slotInstructions } = await renderSlots(result, slots);
|
||||
let renderer;
|
||||
if (metadata.hydrate !== "only") {
|
||||
let isTagged = false;
|
||||
try {
|
||||
isTagged = Component && Component[Renderer];
|
||||
} catch {
|
||||
}
|
||||
if (isTagged) {
|
||||
const rendererName = Component[Renderer];
|
||||
renderer = renderers.find(({ name }) => name === rendererName);
|
||||
}
|
||||
if (!renderer) {
|
||||
let error;
|
||||
for (const r of renderers) {
|
||||
try {
|
||||
if (await r.ssr.check.call({ result }, Component, props, children)) {
|
||||
renderer = r;
|
||||
break;
|
||||
}
|
||||
} catch (e) {
|
||||
error ??= e;
|
||||
}
|
||||
}
|
||||
if (!renderer && error) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
if (!renderer && typeof HTMLElement === "function" && componentIsHTMLElement(Component)) {
|
||||
const output = await renderHTMLElement(
|
||||
result,
|
||||
Component,
|
||||
_props,
|
||||
slots
|
||||
);
|
||||
return {
|
||||
render(destination) {
|
||||
destination.write(output);
|
||||
}
|
||||
};
|
||||
}
|
||||
} else {
|
||||
if (metadata.hydrateArgs) {
|
||||
const rendererName = rendererAliases.has(metadata.hydrateArgs) ? rendererAliases.get(metadata.hydrateArgs) : metadata.hydrateArgs;
|
||||
if (clientOnlyValues.has(rendererName)) {
|
||||
renderer = renderers.find(
|
||||
({ name }) => name === `@astrojs/${rendererName}` || name === rendererName
|
||||
);
|
||||
}
|
||||
}
|
||||
if (!renderer && validRenderers.length === 1) {
|
||||
renderer = validRenderers[0];
|
||||
}
|
||||
if (!renderer) {
|
||||
const extname = metadata.componentUrl?.split(".").pop();
|
||||
renderer = renderers.find(({ name }) => name === `@astrojs/${extname}` || name === extname);
|
||||
}
|
||||
}
|
||||
let componentServerRenderEndTime;
|
||||
if (!renderer) {
|
||||
if (metadata.hydrate === "only") {
|
||||
const rendererName = rendererAliases.has(metadata.hydrateArgs) ? rendererAliases.get(metadata.hydrateArgs) : metadata.hydrateArgs;
|
||||
if (clientOnlyValues.has(rendererName)) {
|
||||
const plural = validRenderers.length > 1;
|
||||
throw new AstroError({
|
||||
...AstroErrorData.NoMatchingRenderer,
|
||||
message: AstroErrorData.NoMatchingRenderer.message(
|
||||
metadata.displayName,
|
||||
metadata?.componentUrl?.split(".").pop(),
|
||||
plural,
|
||||
validRenderers.length
|
||||
),
|
||||
hint: AstroErrorData.NoMatchingRenderer.hint(
|
||||
formatList(probableRendererNames.map((r) => "`" + r + "`"))
|
||||
)
|
||||
});
|
||||
} else {
|
||||
throw new AstroError({
|
||||
...AstroErrorData.NoClientOnlyHint,
|
||||
message: AstroErrorData.NoClientOnlyHint.message(metadata.displayName),
|
||||
hint: AstroErrorData.NoClientOnlyHint.hint(
|
||||
probableRendererNames.map((r) => r.replace("@astrojs/", "")).join("|")
|
||||
)
|
||||
});
|
||||
}
|
||||
} else if (typeof Component !== "string") {
|
||||
const matchingRenderers = validRenderers.filter(
|
||||
(r) => probableRendererNames.includes(r.name)
|
||||
);
|
||||
const plural = validRenderers.length > 1;
|
||||
if (matchingRenderers.length === 0) {
|
||||
throw new AstroError({
|
||||
...AstroErrorData.NoMatchingRenderer,
|
||||
message: AstroErrorData.NoMatchingRenderer.message(
|
||||
metadata.displayName,
|
||||
metadata?.componentUrl?.split(".").pop(),
|
||||
plural,
|
||||
validRenderers.length
|
||||
),
|
||||
hint: AstroErrorData.NoMatchingRenderer.hint(
|
||||
formatList(probableRendererNames.map((r) => "`" + r + "`"))
|
||||
)
|
||||
});
|
||||
} else if (matchingRenderers.length === 1) {
|
||||
renderer = matchingRenderers[0];
|
||||
({ html, attrs } = await renderer.ssr.renderToStaticMarkup.call(
|
||||
{ result },
|
||||
Component,
|
||||
propsWithoutTransitionAttributes,
|
||||
children,
|
||||
metadata
|
||||
));
|
||||
} else {
|
||||
throw new Error(`Unable to render ${metadata.displayName}!
|
||||
|
||||
This component likely uses ${formatList(probableRendererNames)},
|
||||
but Astro encountered an error during server-side rendering.
|
||||
|
||||
Please ensure that ${metadata.displayName}:
|
||||
1. Does not unconditionally access browser-specific globals like \`window\` or \`document\`.
|
||||
If this is unavoidable, use the \`client:only\` hydration directive.
|
||||
2. Does not conditionally return \`null\` or \`undefined\` when rendered on the server.
|
||||
|
||||
If you're still stuck, please open an issue on GitHub or join us at https://astro.build/chat.`);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (metadata.hydrate === "only") {
|
||||
const rendererName = rendererAliases.has(metadata.hydrateArgs) ? rendererAliases.get(metadata.hydrateArgs) : metadata.hydrateArgs;
|
||||
if (!clientOnlyValues.has(rendererName)) {
|
||||
console.warn(
|
||||
`The client:only directive for ${metadata.displayName} is not recognized. The renderer ${renderer.name} will be used. If you intended to use a different renderer, please provide a valid client:only directive.`
|
||||
);
|
||||
}
|
||||
html = await renderSlotToString(result, slots?.fallback);
|
||||
} else {
|
||||
const componentRenderStartTime = performance.now();
|
||||
({ html, attrs } = await renderer.ssr.renderToStaticMarkup.call(
|
||||
{ result },
|
||||
Component,
|
||||
propsWithoutTransitionAttributes,
|
||||
children,
|
||||
metadata
|
||||
));
|
||||
if (process.env.NODE_ENV === "development")
|
||||
componentServerRenderEndTime = performance.now() - componentRenderStartTime;
|
||||
}
|
||||
}
|
||||
if (renderer && !renderer.clientEntrypoint && renderer.name !== "@astrojs/lit" && metadata.hydrate) {
|
||||
throw new AstroError({
|
||||
...AstroErrorData.NoClientEntrypoint,
|
||||
message: AstroErrorData.NoClientEntrypoint.message(
|
||||
displayName,
|
||||
metadata.hydrate,
|
||||
renderer.name
|
||||
)
|
||||
});
|
||||
}
|
||||
if (!html && typeof Component === "string") {
|
||||
const Tag = sanitizeElementName(Component);
|
||||
const childSlots = Object.values(children).join("");
|
||||
const renderTemplateResult = renderTemplate`<${Tag}${internalSpreadAttributes(
|
||||
props
|
||||
)}${markHTMLString(
|
||||
childSlots === "" && voidElementNames.test(Tag) ? `/>` : `>${childSlots}</${Tag}>`
|
||||
)}`;
|
||||
html = "";
|
||||
const destination = {
|
||||
write(chunk) {
|
||||
if (chunk instanceof Response) return;
|
||||
html += chunkToString(result, chunk);
|
||||
}
|
||||
};
|
||||
await renderTemplateResult.render(destination);
|
||||
}
|
||||
if (!hydration) {
|
||||
return {
|
||||
render(destination) {
|
||||
if (slotInstructions) {
|
||||
for (const instruction of slotInstructions) {
|
||||
destination.write(instruction);
|
||||
}
|
||||
}
|
||||
if (isPage || renderer?.name === "astro:jsx") {
|
||||
destination.write(html);
|
||||
} else if (html && html.length > 0) {
|
||||
destination.write(
|
||||
markHTMLString(removeStaticAstroSlot(html, renderer?.ssr?.supportsAstroStaticSlot))
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
const astroId = shorthash(
|
||||
`<!--${metadata.componentExport.value}:${metadata.componentUrl}-->
|
||||
${html}
|
||||
${serializeProps(
|
||||
props,
|
||||
metadata
|
||||
)}`
|
||||
);
|
||||
const island = await generateHydrateScript(
|
||||
{ renderer, result, astroId, props, attrs },
|
||||
metadata
|
||||
);
|
||||
if (componentServerRenderEndTime && process.env.NODE_ENV === "development")
|
||||
island.props["server-render-time"] = componentServerRenderEndTime;
|
||||
let unrenderedSlots = [];
|
||||
if (html) {
|
||||
if (Object.keys(children).length > 0) {
|
||||
for (const key of Object.keys(children)) {
|
||||
let tagName = renderer?.ssr?.supportsAstroStaticSlot ? !!metadata.hydrate ? "astro-slot" : "astro-static-slot" : "astro-slot";
|
||||
let expectedHTML = key === "default" ? `<${tagName}>` : `<${tagName} name="${key}">`;
|
||||
if (!html.includes(expectedHTML)) {
|
||||
unrenderedSlots.push(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
unrenderedSlots = Object.keys(children);
|
||||
}
|
||||
const template = unrenderedSlots.length > 0 ? unrenderedSlots.map(
|
||||
(key) => `<template data-astro-template${key !== "default" ? `="${key}"` : ""}>${children[key]}</template>`
|
||||
).join("") : "";
|
||||
island.children = `${html ?? ""}${template}`;
|
||||
if (island.children) {
|
||||
island.props["await-children"] = "";
|
||||
island.children += `<!--astro:end-->`;
|
||||
}
|
||||
return {
|
||||
render(destination) {
|
||||
if (slotInstructions) {
|
||||
for (const instruction of slotInstructions) {
|
||||
destination.write(instruction);
|
||||
}
|
||||
}
|
||||
destination.write(createRenderInstruction({ type: "directive", hydration }));
|
||||
if (hydration.directive !== "only" && renderer?.ssr.renderHydrationScript) {
|
||||
destination.write(
|
||||
createRenderInstruction({
|
||||
type: "renderer-hydration-script",
|
||||
rendererName: renderer.name,
|
||||
render: renderer.ssr.renderHydrationScript
|
||||
})
|
||||
);
|
||||
}
|
||||
const renderedElement = renderElement("astro-island", island, false);
|
||||
destination.write(markHTMLString(renderedElement));
|
||||
}
|
||||
};
|
||||
}
|
||||
function sanitizeElementName(tag) {
|
||||
const unsafe = /[&<>'"\s]+/;
|
||||
if (!unsafe.test(tag)) return tag;
|
||||
return tag.trim().split(unsafe)[0].trim();
|
||||
}
|
||||
async function renderFragmentComponent(result, slots = {}) {
|
||||
const children = await renderSlotToString(result, slots?.default);
|
||||
return {
|
||||
render(destination) {
|
||||
if (children == null) return;
|
||||
destination.write(children);
|
||||
}
|
||||
};
|
||||
}
|
||||
async function renderHTMLComponent(result, Component, _props, slots = {}) {
|
||||
const { slotInstructions, children } = await renderSlots(result, slots);
|
||||
const html = Component({ slots: children });
|
||||
const hydrationHtml = slotInstructions ? slotInstructions.map((instr) => chunkToString(result, instr)).join("") : "";
|
||||
return {
|
||||
render(destination) {
|
||||
destination.write(markHTMLString(hydrationHtml + html));
|
||||
}
|
||||
};
|
||||
}
|
||||
function renderAstroComponent(result, displayName, Component, props, slots = {}) {
|
||||
if (containsServerDirective(props)) {
|
||||
return renderServerIsland(result, displayName, props, slots);
|
||||
}
|
||||
const instance = createAstroComponentInstance(result, displayName, Component, props, slots);
|
||||
return {
|
||||
async render(destination) {
|
||||
await instance.render(destination);
|
||||
}
|
||||
};
|
||||
}
|
||||
async function renderComponent(result, displayName, Component, props, slots = {}) {
|
||||
if (isPromise(Component)) {
|
||||
Component = await Component.catch(handleCancellation);
|
||||
}
|
||||
if (isFragmentComponent(Component)) {
|
||||
return await renderFragmentComponent(result, slots).catch(handleCancellation);
|
||||
}
|
||||
props = normalizeProps(props);
|
||||
if (isHTMLComponent(Component)) {
|
||||
return await renderHTMLComponent(result, Component, props, slots).catch(handleCancellation);
|
||||
}
|
||||
if (isAstroComponentFactory(Component)) {
|
||||
return renderAstroComponent(result, displayName, Component, props, slots);
|
||||
}
|
||||
return await renderFrameworkComponent(result, displayName, Component, props, slots).catch(
|
||||
handleCancellation
|
||||
);
|
||||
function handleCancellation(e) {
|
||||
if (result.cancelled)
|
||||
return {
|
||||
render() {
|
||||
}
|
||||
};
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
function normalizeProps(props) {
|
||||
if (props["class:list"] !== void 0) {
|
||||
const value = props["class:list"];
|
||||
delete props["class:list"];
|
||||
props["class"] = clsx(props["class"], value);
|
||||
if (props["class"] === "") {
|
||||
delete props["class"];
|
||||
}
|
||||
}
|
||||
return props;
|
||||
}
|
||||
async function renderComponentToString(result, displayName, Component, props, slots = {}, isPage = false, route) {
|
||||
let str = "";
|
||||
let renderedFirstPageChunk = false;
|
||||
let head = "";
|
||||
if (isPage && !result.partial && nonAstroPageNeedsHeadInjection(Component)) {
|
||||
head += chunkToString(result, maybeRenderHead());
|
||||
}
|
||||
try {
|
||||
const destination = {
|
||||
write(chunk) {
|
||||
if (isPage && !result.partial && !renderedFirstPageChunk) {
|
||||
renderedFirstPageChunk = true;
|
||||
if (!/<!doctype html/i.test(String(chunk))) {
|
||||
const doctype = result.compressHTML ? "<!DOCTYPE html>" : "<!DOCTYPE html>\n";
|
||||
str += doctype + head;
|
||||
}
|
||||
}
|
||||
if (chunk instanceof Response) return;
|
||||
str += chunkToString(result, chunk);
|
||||
}
|
||||
};
|
||||
const renderInstance = await renderComponent(result, displayName, Component, props, slots);
|
||||
await renderInstance.render(destination);
|
||||
} catch (e) {
|
||||
if (AstroError.is(e) && !e.loc) {
|
||||
e.setLocation({
|
||||
file: route?.component
|
||||
});
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
function nonAstroPageNeedsHeadInjection(pageComponent) {
|
||||
return !!pageComponent?.[needsHeadRenderingSymbol];
|
||||
}
|
||||
export {
|
||||
renderComponent,
|
||||
renderComponentToString
|
||||
};
|
3
node_modules/astro/dist/runtime/server/render/dom.d.ts
generated
vendored
Normal file
3
node_modules/astro/dist/runtime/server/render/dom.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import type { SSRResult } from '../../../@types/astro.js';
|
||||
export declare function componentIsHTMLElement(Component: unknown): boolean;
|
||||
export declare function renderHTMLElement(result: SSRResult, constructor: typeof HTMLElement, props: any, slots: any): Promise<string>;
|
26
node_modules/astro/dist/runtime/server/render/dom.js
generated
vendored
Normal file
26
node_modules/astro/dist/runtime/server/render/dom.js
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
import { markHTMLString } from "../escape.js";
|
||||
import { renderSlotToString } from "./slot.js";
|
||||
import { toAttributeString } from "./util.js";
|
||||
function componentIsHTMLElement(Component) {
|
||||
return typeof HTMLElement !== "undefined" && HTMLElement.isPrototypeOf(Component);
|
||||
}
|
||||
async function renderHTMLElement(result, constructor, props, slots) {
|
||||
const name = getHTMLElementName(constructor);
|
||||
let attrHTML = "";
|
||||
for (const attr in props) {
|
||||
attrHTML += ` ${attr}="${toAttributeString(await props[attr])}"`;
|
||||
}
|
||||
return markHTMLString(
|
||||
`<${name}${attrHTML}>${await renderSlotToString(result, slots?.default)}</${name}>`
|
||||
);
|
||||
}
|
||||
function getHTMLElementName(constructor) {
|
||||
const definedName = customElements.getName(constructor);
|
||||
if (definedName) return definedName;
|
||||
const assignedName = constructor.name.replace(/^HTML|Element$/g, "").replace(/[A-Z]/g, "-$&").toLowerCase().replace(/^-/, "html-");
|
||||
return assignedName;
|
||||
}
|
||||
export {
|
||||
componentIsHTMLElement,
|
||||
renderHTMLElement
|
||||
};
|
5
node_modules/astro/dist/runtime/server/render/head.d.ts
generated
vendored
Normal file
5
node_modules/astro/dist/runtime/server/render/head.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
import type { SSRResult } from '../../../@types/astro.js';
|
||||
import type { MaybeRenderHeadInstruction, RenderHeadInstruction } from './instruction.js';
|
||||
export declare function renderAllHeadContent(result: SSRResult): any;
|
||||
export declare function renderHead(): RenderHeadInstruction;
|
||||
export declare function maybeRenderHead(): MaybeRenderHeadInstruction;
|
37
node_modules/astro/dist/runtime/server/render/head.js
generated
vendored
Normal file
37
node_modules/astro/dist/runtime/server/render/head.js
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
import { markHTMLString } from "../escape.js";
|
||||
import { createRenderInstruction } from "./instruction.js";
|
||||
import { renderElement } from "./util.js";
|
||||
const uniqueElements = (item, index, all) => {
|
||||
const props = JSON.stringify(item.props);
|
||||
const children = item.children;
|
||||
return index === all.findIndex((i) => JSON.stringify(i.props) === props && i.children == children);
|
||||
};
|
||||
function renderAllHeadContent(result) {
|
||||
result._metadata.hasRenderedHead = true;
|
||||
const styles = Array.from(result.styles).filter(uniqueElements).map(
|
||||
(style) => style.props.rel === "stylesheet" ? renderElement("link", style) : renderElement("style", style)
|
||||
);
|
||||
result.styles.clear();
|
||||
const scripts = Array.from(result.scripts).filter(uniqueElements).map((script) => {
|
||||
return renderElement("script", script, false);
|
||||
});
|
||||
const links = Array.from(result.links).filter(uniqueElements).map((link) => renderElement("link", link, false));
|
||||
let content = styles.join("\n") + links.join("\n") + scripts.join("\n");
|
||||
if (result._metadata.extraHead.length > 0) {
|
||||
for (const part of result._metadata.extraHead) {
|
||||
content += part;
|
||||
}
|
||||
}
|
||||
return markHTMLString(content);
|
||||
}
|
||||
function renderHead() {
|
||||
return createRenderInstruction({ type: "head" });
|
||||
}
|
||||
function maybeRenderHead() {
|
||||
return createRenderInstruction({ type: "maybe-head" });
|
||||
}
|
||||
export {
|
||||
maybeRenderHead,
|
||||
renderAllHeadContent,
|
||||
renderHead
|
||||
};
|
12
node_modules/astro/dist/runtime/server/render/index.d.ts
generated
vendored
Normal file
12
node_modules/astro/dist/runtime/server/render/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
export { createHeadAndContent, renderTemplate, renderToString } from './astro/index.js';
|
||||
export type { AstroComponentFactory, AstroComponentInstance } from './astro/index.js';
|
||||
export { Fragment, Renderer, chunkToByteArray, chunkToString } from './common.js';
|
||||
export { renderComponent, renderComponentToString } from './component.js';
|
||||
export { renderScript } from './script.js';
|
||||
export { renderHTMLElement } from './dom.js';
|
||||
export { maybeRenderHead, renderHead } from './head.js';
|
||||
export type { RenderInstruction } from './instruction.js';
|
||||
export { renderPage } from './page.js';
|
||||
export { renderSlot, renderSlotToString, type ComponentSlots } from './slot.js';
|
||||
export { renderScriptElement, renderUniqueStylesheet } from './tags.js';
|
||||
export { addAttribute, defineScriptVars, voidElementNames } from './util.js';
|
33
node_modules/astro/dist/runtime/server/render/index.js
generated
vendored
Normal file
33
node_modules/astro/dist/runtime/server/render/index.js
generated
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
import { createHeadAndContent, renderTemplate, renderToString } from "./astro/index.js";
|
||||
import { Fragment, Renderer, chunkToByteArray, chunkToString } from "./common.js";
|
||||
import { renderComponent, renderComponentToString } from "./component.js";
|
||||
import { renderScript } from "./script.js";
|
||||
import { renderHTMLElement } from "./dom.js";
|
||||
import { maybeRenderHead, renderHead } from "./head.js";
|
||||
import { renderPage } from "./page.js";
|
||||
import { renderSlot, renderSlotToString } from "./slot.js";
|
||||
import { renderScriptElement, renderUniqueStylesheet } from "./tags.js";
|
||||
import { addAttribute, defineScriptVars, voidElementNames } from "./util.js";
|
||||
export {
|
||||
Fragment,
|
||||
Renderer,
|
||||
addAttribute,
|
||||
chunkToByteArray,
|
||||
chunkToString,
|
||||
createHeadAndContent,
|
||||
defineScriptVars,
|
||||
maybeRenderHead,
|
||||
renderComponent,
|
||||
renderComponentToString,
|
||||
renderHTMLElement,
|
||||
renderHead,
|
||||
renderPage,
|
||||
renderScript,
|
||||
renderScriptElement,
|
||||
renderSlot,
|
||||
renderSlotToString,
|
||||
renderTemplate,
|
||||
renderToString,
|
||||
renderUniqueStylesheet,
|
||||
voidElementNames
|
||||
};
|
26
node_modules/astro/dist/runtime/server/render/instruction.d.ts
generated
vendored
Normal file
26
node_modules/astro/dist/runtime/server/render/instruction.d.ts
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
import type { HydrationMetadata } from '../hydration.js';
|
||||
export type RenderDirectiveInstruction = {
|
||||
type: 'directive';
|
||||
hydration: HydrationMetadata;
|
||||
};
|
||||
export type RenderHeadInstruction = {
|
||||
type: 'head';
|
||||
};
|
||||
/**
|
||||
* Render a renderer-specific hydration script before the first component of that
|
||||
* framework
|
||||
*/
|
||||
export type RendererHydrationScriptInstruction = {
|
||||
type: 'renderer-hydration-script';
|
||||
rendererName: string;
|
||||
render: () => string;
|
||||
};
|
||||
export type MaybeRenderHeadInstruction = {
|
||||
type: 'maybe-head';
|
||||
};
|
||||
export type RenderInstruction = RenderDirectiveInstruction | RenderHeadInstruction | MaybeRenderHeadInstruction | RendererHydrationScriptInstruction;
|
||||
export declare function createRenderInstruction(instruction: RenderDirectiveInstruction): RenderDirectiveInstruction;
|
||||
export declare function createRenderInstruction(instruction: RendererHydrationScriptInstruction): RendererHydrationScriptInstruction;
|
||||
export declare function createRenderInstruction(instruction: RenderHeadInstruction): RenderHeadInstruction;
|
||||
export declare function createRenderInstruction(instruction: MaybeRenderHeadInstruction): MaybeRenderHeadInstruction;
|
||||
export declare function isRenderInstruction(chunk: any): chunk is RenderInstruction;
|
13
node_modules/astro/dist/runtime/server/render/instruction.js
generated
vendored
Normal file
13
node_modules/astro/dist/runtime/server/render/instruction.js
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
const RenderInstructionSymbol = Symbol.for("astro:render");
|
||||
function createRenderInstruction(instruction) {
|
||||
return Object.defineProperty(instruction, RenderInstructionSymbol, {
|
||||
value: true
|
||||
});
|
||||
}
|
||||
function isRenderInstruction(chunk) {
|
||||
return chunk && typeof chunk === "object" && chunk[RenderInstructionSymbol];
|
||||
}
|
||||
export {
|
||||
createRenderInstruction,
|
||||
isRenderInstruction
|
||||
};
|
4
node_modules/astro/dist/runtime/server/render/page.d.ts
generated
vendored
Normal file
4
node_modules/astro/dist/runtime/server/render/page.d.ts
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
import type { RouteData, SSRResult } from '../../../@types/astro.js';
|
||||
import { type NonAstroPageComponent } from './component.js';
|
||||
import type { AstroComponentFactory } from './index.js';
|
||||
export declare function renderPage(result: SSRResult, componentFactory: AstroComponentFactory | NonAstroPageComponent, props: any, children: any, streaming: boolean, route?: RouteData): Promise<Response>;
|
70
node_modules/astro/dist/runtime/server/render/page.js
generated
vendored
Normal file
70
node_modules/astro/dist/runtime/server/render/page.js
generated
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
import { renderComponentToString } from "./component.js";
|
||||
import { isAstroComponentFactory } from "./astro/index.js";
|
||||
import { renderToAsyncIterable, renderToReadableStream, renderToString } from "./astro/render.js";
|
||||
import { encoder } from "./common.js";
|
||||
import { isDeno, isNode } from "./util.js";
|
||||
async function renderPage(result, componentFactory, props, children, streaming, route) {
|
||||
if (!isAstroComponentFactory(componentFactory)) {
|
||||
result._metadata.headInTree = result.componentMetadata.get(componentFactory.moduleId)?.containsHead ?? false;
|
||||
const pageProps = { ...props ?? {}, "server:root": true };
|
||||
const str = await renderComponentToString(
|
||||
result,
|
||||
componentFactory.name,
|
||||
componentFactory,
|
||||
pageProps,
|
||||
{},
|
||||
true,
|
||||
route
|
||||
);
|
||||
const bytes = encoder.encode(str);
|
||||
return new Response(bytes, {
|
||||
headers: new Headers([
|
||||
["Content-Type", "text/html; charset=utf-8"],
|
||||
["Content-Length", bytes.byteLength.toString()]
|
||||
])
|
||||
});
|
||||
}
|
||||
result._metadata.headInTree = result.componentMetadata.get(componentFactory.moduleId)?.containsHead ?? false;
|
||||
let body;
|
||||
if (streaming) {
|
||||
if (isNode && !isDeno) {
|
||||
const nodeBody = await renderToAsyncIterable(
|
||||
result,
|
||||
componentFactory,
|
||||
props,
|
||||
children,
|
||||
true,
|
||||
route
|
||||
);
|
||||
body = nodeBody;
|
||||
} else {
|
||||
body = await renderToReadableStream(result, componentFactory, props, children, true, route);
|
||||
}
|
||||
} else {
|
||||
body = await renderToString(result, componentFactory, props, children, true, route);
|
||||
}
|
||||
if (body instanceof Response) return body;
|
||||
const init = result.response;
|
||||
const headers = new Headers(init.headers);
|
||||
if (!streaming && typeof body === "string") {
|
||||
body = encoder.encode(body);
|
||||
headers.set("Content-Length", body.byteLength.toString());
|
||||
}
|
||||
if (route?.component.endsWith(".md")) {
|
||||
headers.set("Content-Type", "text/html; charset=utf-8");
|
||||
}
|
||||
let status = init.status;
|
||||
if (route?.route === "/404") {
|
||||
status = 404;
|
||||
} else if (route?.route === "/500") {
|
||||
status = 500;
|
||||
}
|
||||
if (status) {
|
||||
return new Response(body, { ...init, headers, status });
|
||||
} else {
|
||||
return new Response(body, { ...init, headers });
|
||||
}
|
||||
}
|
||||
export {
|
||||
renderPage
|
||||
};
|
6
node_modules/astro/dist/runtime/server/render/script.d.ts
generated
vendored
Normal file
6
node_modules/astro/dist/runtime/server/render/script.d.ts
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
import type { SSRResult } from '../../../@types/astro.js';
|
||||
/**
|
||||
* Relies on the `renderScript: true` compiler option
|
||||
* @experimental
|
||||
*/
|
||||
export declare function renderScript(result: SSRResult, id: string): Promise<any>;
|
18
node_modules/astro/dist/runtime/server/render/script.js
generated
vendored
Normal file
18
node_modules/astro/dist/runtime/server/render/script.js
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
import { markHTMLString } from "../escape.js";
|
||||
async function renderScript(result, id) {
|
||||
if (result._metadata.renderedScripts.has(id)) return;
|
||||
result._metadata.renderedScripts.add(id);
|
||||
const inlined = result.inlinedScripts.get(id);
|
||||
if (inlined != null) {
|
||||
if (inlined) {
|
||||
return markHTMLString(`<script type="module">${inlined}</script>`);
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
const resolved = await result.resolve(id);
|
||||
return markHTMLString(`<script type="module" src="${resolved}"></script>`);
|
||||
}
|
||||
export {
|
||||
renderScript
|
||||
};
|
5
node_modules/astro/dist/runtime/server/render/server-islands.d.ts
generated
vendored
Normal file
5
node_modules/astro/dist/runtime/server/render/server-islands.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
import type { SSRResult } from '../../../@types/astro.js';
|
||||
import type { RenderInstance } from './common.js';
|
||||
import { type ComponentSlots } from './slot.js';
|
||||
export declare function containsServerDirective(props: Record<string | number, any>): boolean;
|
||||
export declare function renderServerIsland(result: SSRResult, _displayName: string, props: Record<string | number, any>, slots: ComponentSlots): RenderInstance;
|
83
node_modules/astro/dist/runtime/server/render/server-islands.js
generated
vendored
Normal file
83
node_modules/astro/dist/runtime/server/render/server-islands.js
generated
vendored
Normal file
@@ -0,0 +1,83 @@
|
||||
import { encryptString } from "../../../core/encryption.js";
|
||||
import { renderChild } from "./any.js";
|
||||
import { renderSlotToString } from "./slot.js";
|
||||
const internalProps = /* @__PURE__ */ new Set([
|
||||
"server:component-path",
|
||||
"server:component-export",
|
||||
"server:component-directive",
|
||||
"server:defer"
|
||||
]);
|
||||
function containsServerDirective(props) {
|
||||
return "server:component-directive" in props;
|
||||
}
|
||||
function safeJsonStringify(obj) {
|
||||
return JSON.stringify(obj).replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029").replace(/</g, "\\u003c").replace(/>/g, "\\u003e").replace(/\//g, "\\u002f");
|
||||
}
|
||||
function renderServerIsland(result, _displayName, props, slots) {
|
||||
return {
|
||||
async render(destination) {
|
||||
const componentPath = props["server:component-path"];
|
||||
const componentExport = props["server:component-export"];
|
||||
const componentId = result.serverIslandNameMap.get(componentPath);
|
||||
if (!componentId) {
|
||||
throw new Error(`Could not find server component name`);
|
||||
}
|
||||
for (const key2 of Object.keys(props)) {
|
||||
if (internalProps.has(key2)) {
|
||||
delete props[key2];
|
||||
}
|
||||
}
|
||||
destination.write("<!--[if astro]>server-island-start<![endif]-->");
|
||||
const renderedSlots = {};
|
||||
for (const name in slots) {
|
||||
if (name !== "fallback") {
|
||||
const content = await renderSlotToString(result, slots[name]);
|
||||
renderedSlots[name] = content.toString();
|
||||
} else {
|
||||
await renderChild(destination, slots.fallback(result));
|
||||
}
|
||||
}
|
||||
const key = await result.key;
|
||||
const propsEncrypted = await encryptString(key, JSON.stringify(props));
|
||||
const hostId = crypto.randomUUID();
|
||||
const slash = result.base.endsWith("/") ? "" : "/";
|
||||
const serverIslandUrl = `${result.base}${slash}_server-islands/${componentId}${result.trailingSlash === "always" ? "/" : ""}`;
|
||||
destination.write(`<script async type="module" data-island-id="${hostId}">
|
||||
let componentId = ${safeJsonStringify(componentId)};
|
||||
let componentExport = ${safeJsonStringify(componentExport)};
|
||||
let script = document.querySelector('script[data-island-id="${hostId}"]');
|
||||
let data = {
|
||||
componentExport,
|
||||
encryptedProps: ${safeJsonStringify(propsEncrypted)},
|
||||
slots: ${safeJsonStringify(renderedSlots)},
|
||||
};
|
||||
|
||||
let response = await fetch('${serverIslandUrl}', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
if (script) {
|
||||
if(response.status === 200 && response.headers.get('content-type') === 'text/html') {
|
||||
let html = await response.text();
|
||||
|
||||
// Swap!
|
||||
while(script.previousSibling &&
|
||||
script.previousSibling.nodeType !== 8 &&
|
||||
script.previousSibling.data !== '[if astro]>server-island-start<![endif]') {
|
||||
script.previousSibling.remove();
|
||||
}
|
||||
script.previousSibling?.remove();
|
||||
|
||||
let frag = document.createRange().createContextualFragment(html);
|
||||
script.before(frag);
|
||||
}
|
||||
script.remove();
|
||||
}
|
||||
</script>`);
|
||||
}
|
||||
};
|
||||
}
|
||||
export {
|
||||
containsServerDirective,
|
||||
renderServerIsland
|
||||
};
|
24
node_modules/astro/dist/runtime/server/render/slot.d.ts
generated
vendored
Normal file
24
node_modules/astro/dist/runtime/server/render/slot.d.ts
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
import type { SSRResult } from '../../../@types/astro.js';
|
||||
import { renderTemplate } from './astro/render-template.js';
|
||||
import type { RenderInstruction } from './instruction.js';
|
||||
import { HTMLString } from '../escape.js';
|
||||
import { type RenderInstance } from './common.js';
|
||||
type RenderTemplateResult = ReturnType<typeof renderTemplate>;
|
||||
export type ComponentSlots = Record<string, ComponentSlotValue>;
|
||||
export type ComponentSlotValue = (result: SSRResult) => RenderTemplateResult | Promise<RenderTemplateResult>;
|
||||
declare const slotString: unique symbol;
|
||||
export declare class SlotString extends HTMLString {
|
||||
instructions: null | RenderInstruction[];
|
||||
[slotString]: boolean;
|
||||
constructor(content: string, instructions: null | RenderInstruction[]);
|
||||
}
|
||||
export declare function isSlotString(str: string): str is any;
|
||||
export declare function renderSlot(result: SSRResult, slotted: ComponentSlotValue | RenderTemplateResult, fallback?: ComponentSlotValue | RenderTemplateResult): RenderInstance;
|
||||
export declare function renderSlotToString(result: SSRResult, slotted: ComponentSlotValue | RenderTemplateResult, fallback?: ComponentSlotValue | RenderTemplateResult): Promise<string>;
|
||||
interface RenderSlotsResult {
|
||||
slotInstructions: null | RenderInstruction[];
|
||||
children: Record<string, string>;
|
||||
}
|
||||
export declare function renderSlots(result: SSRResult, slots?: ComponentSlots): Promise<RenderSlotsResult>;
|
||||
export declare function createSlotValueFromString(content: string): ComponentSlotValue;
|
||||
export {};
|
86
node_modules/astro/dist/runtime/server/render/slot.js
generated
vendored
Normal file
86
node_modules/astro/dist/runtime/server/render/slot.js
generated
vendored
Normal file
@@ -0,0 +1,86 @@
|
||||
import { renderTemplate } from "./astro/render-template.js";
|
||||
import { HTMLString, markHTMLString, unescapeHTML } from "../escape.js";
|
||||
import { renderChild } from "./any.js";
|
||||
import { chunkToString } from "./common.js";
|
||||
const slotString = Symbol.for("astro:slot-string");
|
||||
class SlotString extends HTMLString {
|
||||
instructions;
|
||||
[slotString];
|
||||
constructor(content, instructions) {
|
||||
super(content);
|
||||
this.instructions = instructions;
|
||||
this[slotString] = true;
|
||||
}
|
||||
}
|
||||
function isSlotString(str) {
|
||||
return !!str[slotString];
|
||||
}
|
||||
function renderSlot(result, slotted, fallback) {
|
||||
if (!slotted && fallback) {
|
||||
return renderSlot(result, fallback);
|
||||
}
|
||||
return {
|
||||
async render(destination) {
|
||||
await renderChild(destination, typeof slotted === "function" ? slotted(result) : slotted);
|
||||
}
|
||||
};
|
||||
}
|
||||
async function renderSlotToString(result, slotted, fallback) {
|
||||
let content = "";
|
||||
let instructions = null;
|
||||
const temporaryDestination = {
|
||||
write(chunk) {
|
||||
if (chunk instanceof SlotString) {
|
||||
content += chunk;
|
||||
if (chunk.instructions) {
|
||||
instructions ??= [];
|
||||
instructions.push(...chunk.instructions);
|
||||
}
|
||||
} else if (chunk instanceof Response) return;
|
||||
else if (typeof chunk === "object" && "type" in chunk && typeof chunk.type === "string") {
|
||||
if (instructions === null) {
|
||||
instructions = [];
|
||||
}
|
||||
instructions.push(chunk);
|
||||
} else {
|
||||
content += chunkToString(result, chunk);
|
||||
}
|
||||
}
|
||||
};
|
||||
const renderInstance = renderSlot(result, slotted, fallback);
|
||||
await renderInstance.render(temporaryDestination);
|
||||
return markHTMLString(new SlotString(content, instructions));
|
||||
}
|
||||
async function renderSlots(result, slots = {}) {
|
||||
let slotInstructions = null;
|
||||
let children = {};
|
||||
if (slots) {
|
||||
await Promise.all(
|
||||
Object.entries(slots).map(
|
||||
([key, value]) => renderSlotToString(result, value).then((output) => {
|
||||
if (output.instructions) {
|
||||
if (slotInstructions === null) {
|
||||
slotInstructions = [];
|
||||
}
|
||||
slotInstructions.push(...output.instructions);
|
||||
}
|
||||
children[key] = output;
|
||||
})
|
||||
)
|
||||
);
|
||||
}
|
||||
return { slotInstructions, children };
|
||||
}
|
||||
function createSlotValueFromString(content) {
|
||||
return function() {
|
||||
return renderTemplate`${unescapeHTML(content)}`;
|
||||
};
|
||||
}
|
||||
export {
|
||||
SlotString,
|
||||
createSlotValueFromString,
|
||||
isSlotString,
|
||||
renderSlot,
|
||||
renderSlotToString,
|
||||
renderSlots
|
||||
};
|
4
node_modules/astro/dist/runtime/server/render/tags.d.ts
generated
vendored
Normal file
4
node_modules/astro/dist/runtime/server/render/tags.d.ts
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
import type { SSRElement, SSRResult } from '../../../@types/astro.js';
|
||||
import type { StylesheetAsset } from '../../../core/app/types.js';
|
||||
export declare function renderScriptElement({ props, children }: SSRElement): string;
|
||||
export declare function renderUniqueStylesheet(result: SSRResult, sheet: StylesheetAsset): string | undefined;
|
21
node_modules/astro/dist/runtime/server/render/tags.js
generated
vendored
Normal file
21
node_modules/astro/dist/runtime/server/render/tags.js
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
import { renderElement } from "./util.js";
|
||||
function renderScriptElement({ props, children }) {
|
||||
return renderElement("script", {
|
||||
props,
|
||||
children
|
||||
});
|
||||
}
|
||||
function renderUniqueStylesheet(result, sheet) {
|
||||
if (sheet.type === "external") {
|
||||
if (Array.from(result.styles).some((s) => s.props.href === sheet.src)) return "";
|
||||
return renderElement("link", { props: { rel: "stylesheet", href: sheet.src }, children: "" });
|
||||
}
|
||||
if (sheet.type === "inline") {
|
||||
if (Array.from(result.styles).some((s) => s.children.includes(sheet.content))) return "";
|
||||
return renderElement("style", { props: {}, children: sheet.content });
|
||||
}
|
||||
}
|
||||
export {
|
||||
renderScriptElement,
|
||||
renderUniqueStylesheet
|
||||
};
|
39
node_modules/astro/dist/runtime/server/render/util.d.ts
generated
vendored
Normal file
39
node_modules/astro/dist/runtime/server/render/util.d.ts
generated
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
import type { SSRElement } from '../../../@types/astro.js';
|
||||
import type { RenderFunction } from './common.js';
|
||||
export declare const voidElementNames: RegExp;
|
||||
export declare const toAttributeString: (value: any, shouldEscape?: boolean) => any;
|
||||
export declare function defineScriptVars(vars: Record<any, any>): any;
|
||||
export declare function formatList(values: string[]): string;
|
||||
export declare function addAttribute(value: any, key: string, shouldEscape?: boolean): any;
|
||||
export declare function internalSpreadAttributes(values: Record<any, any>, shouldEscape?: boolean): any;
|
||||
export declare function renderElement(name: string, { props: _props, children }: SSRElement, shouldEscape?: boolean): string;
|
||||
/**
|
||||
* Executes the `bufferRenderFunction` to prerender it into a buffer destination, and return a promise
|
||||
* with an object containing the `renderToFinalDestination` function to flush the buffer to the final
|
||||
* destination.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* // Render components in parallel ahead of time
|
||||
* const finalRenders = [ComponentA, ComponentB].map((comp) => {
|
||||
* return renderToBufferDestination(async (bufferDestination) => {
|
||||
* await renderComponentToDestination(bufferDestination);
|
||||
* });
|
||||
* });
|
||||
* // Render array of components serially
|
||||
* for (const finalRender of finalRenders) {
|
||||
* await finalRender.renderToFinalDestination(finalDestination);
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
export declare function renderToBufferDestination(bufferRenderFunction: RenderFunction): {
|
||||
renderToFinalDestination: RenderFunction;
|
||||
};
|
||||
export declare const isNode: boolean;
|
||||
export declare const isDeno: boolean;
|
||||
export type PromiseWithResolvers<T> = {
|
||||
promise: Promise<T>;
|
||||
resolve: (value: T) => void;
|
||||
reject: (reason?: any) => void;
|
||||
};
|
||||
export declare function promiseWithResolvers<T = any>(): PromiseWithResolvers<T>;
|
170
node_modules/astro/dist/runtime/server/render/util.js
generated
vendored
Normal file
170
node_modules/astro/dist/runtime/server/render/util.js
generated
vendored
Normal file
@@ -0,0 +1,170 @@
|
||||
import { clsx } from "clsx";
|
||||
import { HTMLString, markHTMLString } from "../escape.js";
|
||||
const voidElementNames = /^(area|base|br|col|command|embed|hr|img|input|keygen|link|meta|param|source|track|wbr)$/i;
|
||||
const htmlBooleanAttributes = /^(?:allowfullscreen|async|autofocus|autoplay|checked|controls|default|defer|disabled|disablepictureinpicture|disableremoteplayback|formnovalidate|hidden|loop|nomodule|novalidate|open|playsinline|readonly|required|reversed|scoped|seamless|selected|itemscope)$/i;
|
||||
const htmlEnumAttributes = /^(?:contenteditable|draggable|spellcheck|value)$/i;
|
||||
const svgEnumAttributes = /^(?:autoReverse|externalResourcesRequired|focusable|preserveAlpha)$/i;
|
||||
const AMPERSAND_REGEX = /&/g;
|
||||
const DOUBLE_QUOTE_REGEX = /"/g;
|
||||
const STATIC_DIRECTIVES = /* @__PURE__ */ new Set(["set:html", "set:text"]);
|
||||
const toIdent = (k) => k.trim().replace(/(?!^)\b\w|\s+|\W+/g, (match, index) => {
|
||||
if (/\W/.test(match)) return "";
|
||||
return index === 0 ? match : match.toUpperCase();
|
||||
});
|
||||
const toAttributeString = (value, shouldEscape = true) => shouldEscape ? String(value).replace(AMPERSAND_REGEX, "&").replace(DOUBLE_QUOTE_REGEX, """) : value;
|
||||
const kebab = (k) => k.toLowerCase() === k ? k : k.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`);
|
||||
const toStyleString = (obj) => Object.entries(obj).filter(([_, v]) => typeof v === "string" && v.trim() || typeof v === "number").map(([k, v]) => {
|
||||
if (k[0] !== "-" && k[1] !== "-") return `${kebab(k)}:${v}`;
|
||||
return `${k}:${v}`;
|
||||
}).join(";");
|
||||
function defineScriptVars(vars) {
|
||||
let output = "";
|
||||
for (const [key, value] of Object.entries(vars)) {
|
||||
output += `const ${toIdent(key)} = ${JSON.stringify(value)?.replace(
|
||||
/<\/script>/g,
|
||||
"\\x3C/script>"
|
||||
)};
|
||||
`;
|
||||
}
|
||||
return markHTMLString(output);
|
||||
}
|
||||
function formatList(values) {
|
||||
if (values.length === 1) {
|
||||
return values[0];
|
||||
}
|
||||
return `${values.slice(0, -1).join(", ")} or ${values[values.length - 1]}`;
|
||||
}
|
||||
function addAttribute(value, key, shouldEscape = true) {
|
||||
if (value == null) {
|
||||
return "";
|
||||
}
|
||||
if (value === false) {
|
||||
if (htmlEnumAttributes.test(key) || svgEnumAttributes.test(key)) {
|
||||
return markHTMLString(` ${key}="false"`);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
if (STATIC_DIRECTIVES.has(key)) {
|
||||
console.warn(`[astro] The "${key}" directive cannot be applied dynamically at runtime. It will not be rendered as an attribute.
|
||||
|
||||
Make sure to use the static attribute syntax (\`${key}={value}\`) instead of the dynamic spread syntax (\`{...{ "${key}": value }}\`).`);
|
||||
return "";
|
||||
}
|
||||
if (key === "class:list") {
|
||||
const listValue = toAttributeString(clsx(value), shouldEscape);
|
||||
if (listValue === "") {
|
||||
return "";
|
||||
}
|
||||
return markHTMLString(` ${key.slice(0, -5)}="${listValue}"`);
|
||||
}
|
||||
if (key === "style" && !(value instanceof HTMLString)) {
|
||||
if (Array.isArray(value) && value.length === 2) {
|
||||
return markHTMLString(
|
||||
` ${key}="${toAttributeString(`${toStyleString(value[0])};${value[1]}`, shouldEscape)}"`
|
||||
);
|
||||
}
|
||||
if (typeof value === "object") {
|
||||
return markHTMLString(` ${key}="${toAttributeString(toStyleString(value), shouldEscape)}"`);
|
||||
}
|
||||
}
|
||||
if (key === "className") {
|
||||
return markHTMLString(` class="${toAttributeString(value, shouldEscape)}"`);
|
||||
}
|
||||
if (typeof value === "string" && value.includes("&") && isHttpUrl(value)) {
|
||||
return markHTMLString(` ${key}="${toAttributeString(value, false)}"`);
|
||||
}
|
||||
if (value === true && (key.startsWith("data-") || htmlBooleanAttributes.test(key))) {
|
||||
return markHTMLString(` ${key}`);
|
||||
} else {
|
||||
return markHTMLString(` ${key}="${toAttributeString(value, shouldEscape)}"`);
|
||||
}
|
||||
}
|
||||
function internalSpreadAttributes(values, shouldEscape = true) {
|
||||
let output = "";
|
||||
for (const [key, value] of Object.entries(values)) {
|
||||
output += addAttribute(value, key, shouldEscape);
|
||||
}
|
||||
return markHTMLString(output);
|
||||
}
|
||||
function renderElement(name, { props: _props, children = "" }, shouldEscape = true) {
|
||||
const { lang: _, "data-astro-id": astroId, "define:vars": defineVars, ...props } = _props;
|
||||
if (defineVars) {
|
||||
if (name === "style") {
|
||||
delete props["is:global"];
|
||||
delete props["is:scoped"];
|
||||
}
|
||||
if (name === "script") {
|
||||
delete props.hoist;
|
||||
children = defineScriptVars(defineVars) + "\n" + children;
|
||||
}
|
||||
}
|
||||
if ((children == null || children == "") && voidElementNames.test(name)) {
|
||||
return `<${name}${internalSpreadAttributes(props, shouldEscape)}>`;
|
||||
}
|
||||
return `<${name}${internalSpreadAttributes(props, shouldEscape)}>${children}</${name}>`;
|
||||
}
|
||||
const noop = () => {
|
||||
};
|
||||
class BufferedRenderer {
|
||||
chunks = [];
|
||||
renderPromise;
|
||||
destination;
|
||||
constructor(bufferRenderFunction) {
|
||||
this.renderPromise = bufferRenderFunction(this);
|
||||
Promise.resolve(this.renderPromise).catch(noop);
|
||||
}
|
||||
write(chunk) {
|
||||
if (this.destination) {
|
||||
this.destination.write(chunk);
|
||||
} else {
|
||||
this.chunks.push(chunk);
|
||||
}
|
||||
}
|
||||
async renderToFinalDestination(destination) {
|
||||
for (const chunk of this.chunks) {
|
||||
destination.write(chunk);
|
||||
}
|
||||
this.destination = destination;
|
||||
await this.renderPromise;
|
||||
}
|
||||
}
|
||||
function renderToBufferDestination(bufferRenderFunction) {
|
||||
const renderer = new BufferedRenderer(bufferRenderFunction);
|
||||
return renderer;
|
||||
}
|
||||
const isNode = typeof process !== "undefined" && Object.prototype.toString.call(process) === "[object process]";
|
||||
const isDeno = typeof Deno !== "undefined";
|
||||
function promiseWithResolvers() {
|
||||
let resolve, reject;
|
||||
const promise = new Promise((_resolve, _reject) => {
|
||||
resolve = _resolve;
|
||||
reject = _reject;
|
||||
});
|
||||
return {
|
||||
promise,
|
||||
resolve,
|
||||
reject
|
||||
};
|
||||
}
|
||||
const VALID_PROTOCOLS = ["http:", "https:"];
|
||||
function isHttpUrl(url) {
|
||||
try {
|
||||
const parsedUrl = new URL(url);
|
||||
return VALID_PROTOCOLS.includes(parsedUrl.protocol);
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
export {
|
||||
addAttribute,
|
||||
defineScriptVars,
|
||||
formatList,
|
||||
internalSpreadAttributes,
|
||||
isDeno,
|
||||
isNode,
|
||||
promiseWithResolvers,
|
||||
renderElement,
|
||||
renderToBufferDestination,
|
||||
toAttributeString,
|
||||
voidElementNames
|
||||
};
|
5
node_modules/astro/dist/runtime/server/scripts.d.ts
generated
vendored
Normal file
5
node_modules/astro/dist/runtime/server/scripts.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
import type { SSRResult } from '../../@types/astro.js';
|
||||
export declare function determineIfNeedsHydrationScript(result: SSRResult): boolean;
|
||||
export declare function determinesIfNeedsDirectiveScript(result: SSRResult, directive: string): boolean;
|
||||
export type PrescriptType = null | 'both' | 'directive';
|
||||
export declare function getPrescripts(result: SSRResult, type: PrescriptType, directive: string): string;
|
40
node_modules/astro/dist/runtime/server/scripts.js
generated
vendored
Normal file
40
node_modules/astro/dist/runtime/server/scripts.js
generated
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
import islandScriptDev from "./astro-island.prebuilt-dev.js";
|
||||
import islandScript from "./astro-island.prebuilt.js";
|
||||
const ISLAND_STYLES = `<style>astro-island,astro-slot,astro-static-slot{display:contents}</style>`;
|
||||
function determineIfNeedsHydrationScript(result) {
|
||||
if (result._metadata.hasHydrationScript) {
|
||||
return false;
|
||||
}
|
||||
return result._metadata.hasHydrationScript = true;
|
||||
}
|
||||
function determinesIfNeedsDirectiveScript(result, directive) {
|
||||
if (result._metadata.hasDirectives.has(directive)) {
|
||||
return false;
|
||||
}
|
||||
result._metadata.hasDirectives.add(directive);
|
||||
return true;
|
||||
}
|
||||
function getDirectiveScriptText(result, directive) {
|
||||
const clientDirectives = result.clientDirectives;
|
||||
const clientDirective = clientDirectives.get(directive);
|
||||
if (!clientDirective) {
|
||||
throw new Error(`Unknown directive: ${directive}`);
|
||||
}
|
||||
return clientDirective;
|
||||
}
|
||||
function getPrescripts(result, type, directive) {
|
||||
switch (type) {
|
||||
case "both":
|
||||
return `${ISLAND_STYLES}<script>${getDirectiveScriptText(result, directive)};${process.env.NODE_ENV === "development" ? islandScriptDev : islandScript}</script>`;
|
||||
case "directive":
|
||||
return `<script>${getDirectiveScriptText(result, directive)}</script>`;
|
||||
case null:
|
||||
break;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
export {
|
||||
determineIfNeedsHydrationScript,
|
||||
determinesIfNeedsDirectiveScript,
|
||||
getPrescripts
|
||||
};
|
2
node_modules/astro/dist/runtime/server/serialize.d.ts
generated
vendored
Normal file
2
node_modules/astro/dist/runtime/server/serialize.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import type { AstroComponentMetadata } from '../../@types/astro.js';
|
||||
export declare function serializeProps(props: any, metadata: AstroComponentMetadata): string;
|
100
node_modules/astro/dist/runtime/server/serialize.js
generated
vendored
Normal file
100
node_modules/astro/dist/runtime/server/serialize.js
generated
vendored
Normal file
@@ -0,0 +1,100 @@
|
||||
const PROP_TYPE = {
|
||||
Value: 0,
|
||||
JSON: 1,
|
||||
// Actually means Array
|
||||
RegExp: 2,
|
||||
Date: 3,
|
||||
Map: 4,
|
||||
Set: 5,
|
||||
BigInt: 6,
|
||||
URL: 7,
|
||||
Uint8Array: 8,
|
||||
Uint16Array: 9,
|
||||
Uint32Array: 10,
|
||||
Infinity: 11
|
||||
};
|
||||
function serializeArray(value, metadata = {}, parents = /* @__PURE__ */ new WeakSet()) {
|
||||
if (parents.has(value)) {
|
||||
throw new Error(`Cyclic reference detected while serializing props for <${metadata.displayName} client:${metadata.hydrate}>!
|
||||
|
||||
Cyclic references cannot be safely serialized for client-side usage. Please remove the cyclic reference.`);
|
||||
}
|
||||
parents.add(value);
|
||||
const serialized = value.map((v) => {
|
||||
return convertToSerializedForm(v, metadata, parents);
|
||||
});
|
||||
parents.delete(value);
|
||||
return serialized;
|
||||
}
|
||||
function serializeObject(value, metadata = {}, parents = /* @__PURE__ */ new WeakSet()) {
|
||||
if (parents.has(value)) {
|
||||
throw new Error(`Cyclic reference detected while serializing props for <${metadata.displayName} client:${metadata.hydrate}>!
|
||||
|
||||
Cyclic references cannot be safely serialized for client-side usage. Please remove the cyclic reference.`);
|
||||
}
|
||||
parents.add(value);
|
||||
const serialized = Object.fromEntries(
|
||||
Object.entries(value).map(([k, v]) => {
|
||||
return [k, convertToSerializedForm(v, metadata, parents)];
|
||||
})
|
||||
);
|
||||
parents.delete(value);
|
||||
return serialized;
|
||||
}
|
||||
function convertToSerializedForm(value, metadata = {}, parents = /* @__PURE__ */ new WeakSet()) {
|
||||
const tag = Object.prototype.toString.call(value);
|
||||
switch (tag) {
|
||||
case "[object Date]": {
|
||||
return [PROP_TYPE.Date, value.toISOString()];
|
||||
}
|
||||
case "[object RegExp]": {
|
||||
return [PROP_TYPE.RegExp, value.source];
|
||||
}
|
||||
case "[object Map]": {
|
||||
return [PROP_TYPE.Map, serializeArray(Array.from(value), metadata, parents)];
|
||||
}
|
||||
case "[object Set]": {
|
||||
return [PROP_TYPE.Set, serializeArray(Array.from(value), metadata, parents)];
|
||||
}
|
||||
case "[object BigInt]": {
|
||||
return [PROP_TYPE.BigInt, value.toString()];
|
||||
}
|
||||
case "[object URL]": {
|
||||
return [PROP_TYPE.URL, value.toString()];
|
||||
}
|
||||
case "[object Array]": {
|
||||
return [PROP_TYPE.JSON, serializeArray(value, metadata, parents)];
|
||||
}
|
||||
case "[object Uint8Array]": {
|
||||
return [PROP_TYPE.Uint8Array, Array.from(value)];
|
||||
}
|
||||
case "[object Uint16Array]": {
|
||||
return [PROP_TYPE.Uint16Array, Array.from(value)];
|
||||
}
|
||||
case "[object Uint32Array]": {
|
||||
return [PROP_TYPE.Uint32Array, Array.from(value)];
|
||||
}
|
||||
default: {
|
||||
if (value !== null && typeof value === "object") {
|
||||
return [PROP_TYPE.Value, serializeObject(value, metadata, parents)];
|
||||
}
|
||||
if (value === Infinity) {
|
||||
return [PROP_TYPE.Infinity, 1];
|
||||
}
|
||||
if (value === -Infinity) {
|
||||
return [PROP_TYPE.Infinity, -1];
|
||||
}
|
||||
if (value === void 0) {
|
||||
return [PROP_TYPE.Value];
|
||||
}
|
||||
return [PROP_TYPE.Value, value];
|
||||
}
|
||||
}
|
||||
}
|
||||
function serializeProps(props, metadata) {
|
||||
const serialized = JSON.stringify(serializeObject(props, metadata));
|
||||
return serialized;
|
||||
}
|
||||
export {
|
||||
serializeProps
|
||||
};
|
31
node_modules/astro/dist/runtime/server/shorthash.d.ts
generated
vendored
Normal file
31
node_modules/astro/dist/runtime/server/shorthash.d.ts
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* shortdash - https://github.com/bibig/node-shorthash
|
||||
*
|
||||
* @license
|
||||
*
|
||||
* (The MIT License)
|
||||
*
|
||||
* Copyright (c) 2013 Bibig <bibig@me.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person
|
||||
* obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without
|
||||
* restriction, including without limitation the rights to use,
|
||||
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following
|
||||
* conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
export declare function shorthash(text: string): string;
|
61
node_modules/astro/dist/runtime/server/shorthash.js
generated
vendored
Normal file
61
node_modules/astro/dist/runtime/server/shorthash.js
generated
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
/**
|
||||
* shortdash - https://github.com/bibig/node-shorthash
|
||||
*
|
||||
* @license
|
||||
*
|
||||
* (The MIT License)
|
||||
*
|
||||
* Copyright (c) 2013 Bibig <bibig@me.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person
|
||||
* obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without
|
||||
* restriction, including without limitation the rights to use,
|
||||
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following
|
||||
* conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
const dictionary = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXY";
|
||||
const binary = dictionary.length;
|
||||
function bitwise(str) {
|
||||
let hash = 0;
|
||||
if (str.length === 0) return hash;
|
||||
for (let i = 0; i < str.length; i++) {
|
||||
const ch = str.charCodeAt(i);
|
||||
hash = (hash << 5) - hash + ch;
|
||||
hash = hash & hash;
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
function shorthash(text) {
|
||||
let num;
|
||||
let result = "";
|
||||
let integer = bitwise(text);
|
||||
const sign = integer < 0 ? "Z" : "";
|
||||
integer = Math.abs(integer);
|
||||
while (integer >= binary) {
|
||||
num = integer % binary;
|
||||
integer = Math.floor(integer / binary);
|
||||
result = dictionary[num] + result;
|
||||
}
|
||||
if (integer > 0) {
|
||||
result = dictionary[integer] + result;
|
||||
}
|
||||
return sign + result;
|
||||
}
|
||||
export {
|
||||
shorthash
|
||||
};
|
7
node_modules/astro/dist/runtime/server/transition.d.ts
generated
vendored
Normal file
7
node_modules/astro/dist/runtime/server/transition.d.ts
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
import type { SSRResult, TransitionAnimationPair, TransitionAnimationValue } from '../../@types/astro.js';
|
||||
export declare function createTransitionScope(result: SSRResult, hash: string): string;
|
||||
export declare function renderTransition(result: SSRResult, hash: string, animationName: TransitionAnimationValue | undefined, transitionName: string): string;
|
||||
export declare function createAnimationScope(transitionName: string, animations: Record<string, TransitionAnimationPair>): {
|
||||
scope: string;
|
||||
styles: string;
|
||||
};
|
179
node_modules/astro/dist/runtime/server/transition.js
generated
vendored
Normal file
179
node_modules/astro/dist/runtime/server/transition.js
generated
vendored
Normal file
@@ -0,0 +1,179 @@
|
||||
import cssesc from "cssesc";
|
||||
import { fade, slide } from "../../transitions/index.js";
|
||||
import { markHTMLString } from "./escape.js";
|
||||
const transitionNameMap = /* @__PURE__ */ new WeakMap();
|
||||
function incrementTransitionNumber(result) {
|
||||
let num = 1;
|
||||
if (transitionNameMap.has(result)) {
|
||||
num = transitionNameMap.get(result) + 1;
|
||||
}
|
||||
transitionNameMap.set(result, num);
|
||||
return num;
|
||||
}
|
||||
function createTransitionScope(result, hash) {
|
||||
const num = incrementTransitionNumber(result);
|
||||
return `astro-${hash}-${num}`;
|
||||
}
|
||||
const getAnimations = (name) => {
|
||||
if (name === "fade") return fade();
|
||||
if (name === "slide") return slide();
|
||||
if (typeof name === "object") return name;
|
||||
};
|
||||
const addPairs = (animations, stylesheet) => {
|
||||
for (const [direction, images] of Object.entries(animations)) {
|
||||
for (const [image, rules] of Object.entries(images)) {
|
||||
stylesheet.addAnimationPair(direction, image, rules);
|
||||
}
|
||||
}
|
||||
};
|
||||
const reEncodeValidChars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_".split("").reduce((v, c) => (v[c.charCodeAt(0)] = c, v), []);
|
||||
const reEncodeInValidStart = "-0123456789_".split("").reduce((v, c) => (v[c.charCodeAt(0)] = c, v), []);
|
||||
function reEncode(s) {
|
||||
let result = "";
|
||||
let codepoint;
|
||||
for (let i = 0; i < s.length; i += (codepoint ?? 0) > 65535 ? 2 : 1) {
|
||||
codepoint = s.codePointAt(i);
|
||||
if (codepoint !== void 0) {
|
||||
result += codepoint < 128 ? codepoint === 95 ? "__" : reEncodeValidChars[codepoint] ?? "_" + codepoint.toString(16).padStart(2, "0") : String.fromCodePoint(codepoint);
|
||||
}
|
||||
}
|
||||
return reEncodeInValidStart[result.codePointAt(0) ?? 0] ? "_" + result : result;
|
||||
}
|
||||
function renderTransition(result, hash, animationName, transitionName) {
|
||||
if (typeof (transitionName ?? "") !== "string") {
|
||||
throw new Error(`Invalid transition name {${transitionName}}`);
|
||||
}
|
||||
if (!animationName) animationName = "fade";
|
||||
const scope = createTransitionScope(result, hash);
|
||||
const name = transitionName ? cssesc(reEncode(transitionName), { isIdentifier: true }) : scope;
|
||||
const sheet = new ViewTransitionStyleSheet(scope, name);
|
||||
const animations = getAnimations(animationName);
|
||||
if (animations) {
|
||||
addPairs(animations, sheet);
|
||||
} else if (animationName === "none") {
|
||||
sheet.addFallback("old", "animation: none; mix-blend-mode: normal;");
|
||||
sheet.addModern("old", "animation: none; opacity: 0; mix-blend-mode: normal;");
|
||||
sheet.addAnimationRaw("new", "animation: none; mix-blend-mode: normal;");
|
||||
sheet.addModern("group", "animation: none");
|
||||
}
|
||||
result._metadata.extraHead.push(markHTMLString(`<style>${sheet.toString()}</style>`));
|
||||
return scope;
|
||||
}
|
||||
function createAnimationScope(transitionName, animations) {
|
||||
const hash = Math.random().toString(36).slice(2, 8);
|
||||
const scope = `astro-${hash}`;
|
||||
const sheet = new ViewTransitionStyleSheet(scope, transitionName);
|
||||
addPairs(animations, sheet);
|
||||
return { scope, styles: sheet.toString().replaceAll('"', "") };
|
||||
}
|
||||
class ViewTransitionStyleSheet {
|
||||
constructor(scope, name) {
|
||||
this.scope = scope;
|
||||
this.name = name;
|
||||
}
|
||||
modern = [];
|
||||
fallback = [];
|
||||
toString() {
|
||||
const { scope, name } = this;
|
||||
const [modern, fallback] = [this.modern, this.fallback].map((rules) => rules.join(""));
|
||||
return [
|
||||
`[data-astro-transition-scope="${scope}"] { view-transition-name: ${name}; }`,
|
||||
this.layer(modern),
|
||||
fallback
|
||||
].join("");
|
||||
}
|
||||
layer(cssText) {
|
||||
return cssText ? `@layer astro { ${cssText} }` : "";
|
||||
}
|
||||
addRule(target, cssText) {
|
||||
this[target].push(cssText);
|
||||
}
|
||||
addAnimationRaw(image, animation) {
|
||||
this.addModern(image, animation);
|
||||
this.addFallback(image, animation);
|
||||
}
|
||||
addModern(image, animation) {
|
||||
const { name } = this;
|
||||
this.addRule("modern", `::view-transition-${image}(${name}) { ${animation} }`);
|
||||
}
|
||||
addFallback(image, animation) {
|
||||
const { scope } = this;
|
||||
this.addRule(
|
||||
"fallback",
|
||||
// Two selectors here, the second in case there is an animation on the root.
|
||||
`[data-astro-transition-fallback="${image}"] [data-astro-transition-scope="${scope}"],
|
||||
[data-astro-transition-fallback="${image}"][data-astro-transition-scope="${scope}"] { ${animation} }`
|
||||
);
|
||||
}
|
||||
addAnimationPair(direction, image, rules) {
|
||||
const { scope, name } = this;
|
||||
const animation = stringifyAnimation(rules);
|
||||
const prefix = direction === "backwards" ? `[data-astro-transition=back]` : direction === "forwards" ? "" : `[data-astro-transition=${direction}]`;
|
||||
this.addRule("modern", `${prefix}::view-transition-${image}(${name}) { ${animation} }`);
|
||||
this.addRule(
|
||||
"fallback",
|
||||
`${prefix}[data-astro-transition-fallback="${image}"] [data-astro-transition-scope="${scope}"],
|
||||
${prefix}[data-astro-transition-fallback="${image}"][data-astro-transition-scope="${scope}"] { ${animation} }`
|
||||
);
|
||||
}
|
||||
}
|
||||
function addAnimationProperty(builder, prop, value) {
|
||||
let arr = builder[prop];
|
||||
if (Array.isArray(arr)) {
|
||||
arr.push(value.toString());
|
||||
} else {
|
||||
builder[prop] = [value.toString()];
|
||||
}
|
||||
}
|
||||
function animationBuilder() {
|
||||
return {
|
||||
toString() {
|
||||
let out = "";
|
||||
for (let k in this) {
|
||||
let value = this[k];
|
||||
if (Array.isArray(value)) {
|
||||
out += `
|
||||
${k}: ${value.join(", ")};`;
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
};
|
||||
}
|
||||
function stringifyAnimation(anim) {
|
||||
if (Array.isArray(anim)) {
|
||||
return stringifyAnimations(anim);
|
||||
} else {
|
||||
return stringifyAnimations([anim]);
|
||||
}
|
||||
}
|
||||
function stringifyAnimations(anims) {
|
||||
const builder = animationBuilder();
|
||||
for (const anim of anims) {
|
||||
if (anim.duration) {
|
||||
addAnimationProperty(builder, "animation-duration", toTimeValue(anim.duration));
|
||||
}
|
||||
if (anim.easing) {
|
||||
addAnimationProperty(builder, "animation-timing-function", anim.easing);
|
||||
}
|
||||
if (anim.direction) {
|
||||
addAnimationProperty(builder, "animation-direction", anim.direction);
|
||||
}
|
||||
if (anim.delay) {
|
||||
addAnimationProperty(builder, "animation-delay", anim.delay);
|
||||
}
|
||||
if (anim.fillMode) {
|
||||
addAnimationProperty(builder, "animation-fill-mode", anim.fillMode);
|
||||
}
|
||||
addAnimationProperty(builder, "animation-name", anim.name);
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
function toTimeValue(num) {
|
||||
return typeof num === "number" ? num + "ms" : num;
|
||||
}
|
||||
export {
|
||||
createAnimationScope,
|
||||
createTransitionScope,
|
||||
renderTransition
|
||||
};
|
2
node_modules/astro/dist/runtime/server/util.d.ts
generated
vendored
Normal file
2
node_modules/astro/dist/runtime/server/util.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
export declare function isPromise<T = any>(value: any): value is Promise<T>;
|
||||
export declare function streamAsyncIterator(stream: ReadableStream): AsyncGenerator<any, void, unknown>;
|
19
node_modules/astro/dist/runtime/server/util.js
generated
vendored
Normal file
19
node_modules/astro/dist/runtime/server/util.js
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
function isPromise(value) {
|
||||
return !!value && typeof value === "object" && "then" in value && typeof value.then === "function";
|
||||
}
|
||||
async function* streamAsyncIterator(stream) {
|
||||
const reader = stream.getReader();
|
||||
try {
|
||||
while (true) {
|
||||
const { done, value } = await reader.read();
|
||||
if (done) return;
|
||||
yield value;
|
||||
}
|
||||
} finally {
|
||||
reader.releaseLock();
|
||||
}
|
||||
}
|
||||
export {
|
||||
isPromise,
|
||||
streamAsyncIterator
|
||||
};
|
Reference in New Issue
Block a user