🎉 initiate project *astro_rewrite*
This commit is contained in:
parent
ffd4d5e86c
commit
2ba37bfbe3
8658 changed files with 2268794 additions and 2538 deletions
1
node_modules/astro/dist/runtime/server/render/any.d.ts
generated
vendored
Normal file
1
node_modules/astro/dist/runtime/server/render/any.d.ts
generated
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
export declare function renderChild(child: any): AsyncIterable<any>;
|
42
node_modules/astro/dist/runtime/server/render/any.js
generated
vendored
Normal file
42
node_modules/astro/dist/runtime/server/render/any.js
generated
vendored
Normal file
|
@ -0,0 +1,42 @@
|
|||
import { escapeHTML, isHTMLString, markHTMLString } from "../escape.js";
|
||||
import {
|
||||
isAstroComponentInstance,
|
||||
isRenderTemplateResult,
|
||||
renderAstroTemplateResult
|
||||
} from "./astro/index.js";
|
||||
import { SlotString } from "./slot.js";
|
||||
import { bufferIterators } from "./util.js";
|
||||
async function* renderChild(child) {
|
||||
child = await child;
|
||||
if (child instanceof SlotString) {
|
||||
if (child.instructions) {
|
||||
yield* child.instructions;
|
||||
}
|
||||
yield child;
|
||||
} else if (isHTMLString(child)) {
|
||||
yield child;
|
||||
} else if (Array.isArray(child)) {
|
||||
const bufferedIterators = bufferIterators(child.map((c) => renderChild(c)));
|
||||
for (const value of bufferedIterators) {
|
||||
yield markHTMLString(await value);
|
||||
}
|
||||
} else if (typeof child === "function") {
|
||||
yield* renderChild(child());
|
||||
} else if (typeof child === "string") {
|
||||
yield markHTMLString(escapeHTML(child));
|
||||
} else if (!child && child !== 0) {
|
||||
} else if (isRenderTemplateResult(child)) {
|
||||
yield* renderAstroTemplateResult(child);
|
||||
} else if (isAstroComponentInstance(child)) {
|
||||
yield* child.render();
|
||||
} else if (ArrayBuffer.isView(child)) {
|
||||
yield child;
|
||||
} else if (typeof child === "object" && (Symbol.asyncIterator in child || Symbol.iterator in child)) {
|
||||
yield* child;
|
||||
} else {
|
||||
yield child;
|
||||
}
|
||||
}
|
||||
export {
|
||||
renderChild
|
||||
};
|
13
node_modules/astro/dist/runtime/server/render/astro/factory.d.ts
generated
vendored
Normal file
13
node_modules/astro/dist/runtime/server/render/astro/factory.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,13 @@
|
|||
import type { PropagationHint, SSRResult } from '../../../../@types/astro';
|
||||
import type { HeadAndContent } from './head-and-content';
|
||||
import type { RenderTemplateResult } from './render-template';
|
||||
export type AstroFactoryReturnValue = RenderTemplateResult | Response | HeadAndContent;
|
||||
export interface AstroComponentFactory {
|
||||
(result: any, props: any, slots: any): AstroFactoryReturnValue;
|
||||
isAstroComponentFactory?: boolean;
|
||||
moduleId?: string | undefined;
|
||||
propagation?: PropagationHint;
|
||||
}
|
||||
export declare function isAstroComponentFactory(obj: any): obj is AstroComponentFactory;
|
||||
export declare function renderToString(result: SSRResult, componentFactory: AstroComponentFactory, props: any, children: any): Promise<string>;
|
||||
export declare function isAPropagatingComponent(result: SSRResult, factory: AstroComponentFactory): boolean;
|
31
node_modules/astro/dist/runtime/server/render/astro/factory.js
generated
vendored
Normal file
31
node_modules/astro/dist/runtime/server/render/astro/factory.js
generated
vendored
Normal file
|
@ -0,0 +1,31 @@
|
|||
import { HTMLParts } from "../common.js";
|
||||
import { isHeadAndContent } from "./head-and-content.js";
|
||||
import { renderAstroTemplateResult } from "./render-template.js";
|
||||
function isAstroComponentFactory(obj) {
|
||||
return obj == null ? false : obj.isAstroComponentFactory === true;
|
||||
}
|
||||
async function renderToString(result, componentFactory, props, children) {
|
||||
const factoryResult = await componentFactory(result, props, children);
|
||||
if (factoryResult instanceof Response) {
|
||||
const response = factoryResult;
|
||||
throw response;
|
||||
}
|
||||
let parts = new HTMLParts();
|
||||
const templateResult = isHeadAndContent(factoryResult) ? factoryResult.content : factoryResult;
|
||||
for await (const chunk of renderAstroTemplateResult(templateResult)) {
|
||||
parts.append(chunk, result);
|
||||
}
|
||||
return parts.toString();
|
||||
}
|
||||
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,
|
||||
renderToString
|
||||
};
|
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';
|
||||
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[headAndContentSym];
|
||||
}
|
||||
function createHeadAndContent(head, content) {
|
||||
return {
|
||||
[headAndContentSym]: true,
|
||||
head,
|
||||
content
|
||||
};
|
||||
}
|
||||
export {
|
||||
createHeadAndContent,
|
||||
isHeadAndContent
|
||||
};
|
6
node_modules/astro/dist/runtime/server/render/astro/index.d.ts
generated
vendored
Normal file
6
node_modules/astro/dist/runtime/server/render/astro/index.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
export type { AstroComponentFactory } from './factory';
|
||||
export { isAstroComponentFactory, renderToString } from './factory.js';
|
||||
export { createHeadAndContent, isHeadAndContent } from './head-and-content.js';
|
||||
export type { AstroComponentInstance } from './instance';
|
||||
export { createAstroComponentInstance, isAstroComponentInstance } from './instance.js';
|
||||
export { isRenderTemplateResult, renderAstroTemplateResult, renderTemplate, } from './render-template.js';
|
19
node_modules/astro/dist/runtime/server/render/astro/index.js
generated
vendored
Normal file
19
node_modules/astro/dist/runtime/server/render/astro/index.js
generated
vendored
Normal file
|
@ -0,0 +1,19 @@
|
|||
import { isAstroComponentFactory, renderToString } from "./factory.js";
|
||||
import { createHeadAndContent, isHeadAndContent } from "./head-and-content.js";
|
||||
import { createAstroComponentInstance, isAstroComponentInstance } from "./instance.js";
|
||||
import {
|
||||
isRenderTemplateResult,
|
||||
renderAstroTemplateResult,
|
||||
renderTemplate
|
||||
} from "./render-template.js";
|
||||
export {
|
||||
createAstroComponentInstance,
|
||||
createHeadAndContent,
|
||||
isAstroComponentFactory,
|
||||
isAstroComponentInstance,
|
||||
isHeadAndContent,
|
||||
isRenderTemplateResult,
|
||||
renderAstroTemplateResult,
|
||||
renderTemplate,
|
||||
renderToString
|
||||
};
|
19
node_modules/astro/dist/runtime/server/render/astro/instance.d.ts
generated
vendored
Normal file
19
node_modules/astro/dist/runtime/server/render/astro/instance.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,19 @@
|
|||
import type { SSRResult } from '../../../../@types/astro';
|
||||
import type { ComponentSlots } from '../slot.js';
|
||||
import type { AstroComponentFactory, AstroFactoryReturnValue } from './factory.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<AstroFactoryReturnValue>;
|
||||
render(): AsyncGenerator<any, void, undefined>;
|
||||
}
|
||||
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 {};
|
65
node_modules/astro/dist/runtime/server/render/astro/instance.js
generated
vendored
Normal file
65
node_modules/astro/dist/runtime/server/render/astro/instance.js
generated
vendored
Normal file
|
@ -0,0 +1,65 @@
|
|||
var _a;
|
||||
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 {
|
||||
constructor(result, props, slots, factory) {
|
||||
this[_a] = true;
|
||||
this.result = result;
|
||||
this.props = props;
|
||||
this.factory = factory;
|
||||
this.slotValues = {};
|
||||
for (const name in slots) {
|
||||
const value = slots[name](result);
|
||||
this.slotValues[name] = () => value;
|
||||
}
|
||||
}
|
||||
async init(result) {
|
||||
this.returnValue = this.factory(result, this.props, this.slotValues);
|
||||
return this.returnValue;
|
||||
}
|
||||
async *render() {
|
||||
if (this.returnValue === void 0) {
|
||||
await this.init(this.result);
|
||||
}
|
||||
let value = this.returnValue;
|
||||
if (isPromise(value)) {
|
||||
value = await value;
|
||||
}
|
||||
if (isHeadAndContent(value)) {
|
||||
yield* value.content;
|
||||
} else {
|
||||
yield* renderChild(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
_a = astroComponentInstanceSym;
|
||||
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.has(factory)) {
|
||||
result._metadata.propagators.set(factory, instance);
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
function isAstroComponentInstance(obj) {
|
||||
return typeof obj === "object" && !!obj[astroComponentInstanceSym];
|
||||
}
|
||||
export {
|
||||
AstroComponentInstance,
|
||||
createAstroComponentInstance,
|
||||
isAstroComponentInstance
|
||||
};
|
15
node_modules/astro/dist/runtime/server/render/astro/render-template.d.ts
generated
vendored
Normal file
15
node_modules/astro/dist/runtime/server/render/astro/render-template.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,15 @@
|
|||
import type { RenderInstruction } from '../types';
|
||||
import { HTMLBytes } from '../../escape.js';
|
||||
declare const renderTemplateResultSym: unique symbol;
|
||||
export declare class RenderTemplateResult {
|
||||
[renderTemplateResultSym]: boolean;
|
||||
private htmlParts;
|
||||
private expressions;
|
||||
private error;
|
||||
constructor(htmlParts: TemplateStringsArray, expressions: unknown[]);
|
||||
[Symbol.asyncIterator](): AsyncGenerator<any, void, undefined>;
|
||||
}
|
||||
export declare function isRenderTemplateResult(obj: unknown): obj is RenderTemplateResult;
|
||||
export declare function renderAstroTemplateResult(component: RenderTemplateResult): AsyncIterable<string | HTMLBytes | RenderInstruction>;
|
||||
export declare function renderTemplate(htmlParts: TemplateStringsArray, ...expressions: any[]): RenderTemplateResult;
|
||||
export {};
|
66
node_modules/astro/dist/runtime/server/render/astro/render-template.js
generated
vendored
Normal file
66
node_modules/astro/dist/runtime/server/render/astro/render-template.js
generated
vendored
Normal file
|
@ -0,0 +1,66 @@
|
|||
var _a;
|
||||
import { markHTMLString } from "../../escape.js";
|
||||
import { isPromise } from "../../util.js";
|
||||
import { renderChild } from "../any.js";
|
||||
import { bufferIterators } from "../util.js";
|
||||
const renderTemplateResultSym = Symbol.for("astro.renderTemplateResult");
|
||||
class RenderTemplateResult {
|
||||
constructor(htmlParts, expressions) {
|
||||
this[_a] = true;
|
||||
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 *[(_a = renderTemplateResultSym, Symbol.asyncIterator)]() {
|
||||
const { htmlParts, expressions } = this;
|
||||
let iterables = bufferIterators(expressions.map((e) => renderChild(e)));
|
||||
for (let i = 0; i < htmlParts.length; i++) {
|
||||
const html = htmlParts[i];
|
||||
const iterable = iterables[i];
|
||||
yield markHTMLString(html);
|
||||
if (iterable) {
|
||||
yield* iterable;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
function isRenderTemplateResult(obj) {
|
||||
return typeof obj === "object" && !!obj[renderTemplateResultSym];
|
||||
}
|
||||
async function* renderAstroTemplateResult(component) {
|
||||
for await (const value of component) {
|
||||
if (value || value === 0) {
|
||||
for await (const chunk of renderChild(value)) {
|
||||
switch (chunk.type) {
|
||||
case "directive": {
|
||||
yield chunk;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
yield markHTMLString(chunk);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
function renderTemplate(htmlParts, ...expressions) {
|
||||
return new RenderTemplateResult(htmlParts, expressions);
|
||||
}
|
||||
export {
|
||||
RenderTemplateResult,
|
||||
isRenderTemplateResult,
|
||||
renderAstroTemplateResult,
|
||||
renderTemplate
|
||||
};
|
17
node_modules/astro/dist/runtime/server/render/common.d.ts
generated
vendored
Normal file
17
node_modules/astro/dist/runtime/server/render/common.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,17 @@
|
|||
import type { SSRResult } from '../../../@types/astro';
|
||||
import type { RenderInstruction } from './types.js';
|
||||
import { HTMLBytes } from '../escape.js';
|
||||
import { type SlotString } from './slot.js';
|
||||
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 stringifyChunk(result: SSRResult, chunk: string | SlotString | RenderInstruction): string;
|
||||
export declare class HTMLParts {
|
||||
parts: string;
|
||||
constructor();
|
||||
append(part: string | HTMLBytes | RenderInstruction, result: SSRResult): void;
|
||||
toString(): string;
|
||||
toArrayBuffer(): Uint8Array;
|
||||
}
|
||||
export declare function chunkToByteArray(result: SSRResult, chunk: string | HTMLBytes | RenderInstruction): Uint8Array;
|
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 { 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 (typeof chunk.type === "string") {
|
||||
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) {
|
||||
return "";
|
||||
}
|
||||
return renderAllHeadContent(result);
|
||||
}
|
||||
case "maybe-head": {
|
||||
if (result._metadata.hasRenderedHead || result._metadata.headInTree) {
|
||||
return "";
|
||||
}
|
||||
return renderAllHeadContent(result);
|
||||
}
|
||||
default: {
|
||||
if (chunk instanceof Response) {
|
||||
return "";
|
||||
}
|
||||
throw new Error(`Unknown chunk type: ${chunk.type}`);
|
||||
}
|
||||
}
|
||||
} 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();
|
||||
}
|
||||
}
|
||||
class HTMLParts {
|
||||
constructor() {
|
||||
this.parts = "";
|
||||
}
|
||||
append(part, result) {
|
||||
if (ArrayBuffer.isView(part)) {
|
||||
this.parts += decoder.decode(part);
|
||||
} else {
|
||||
this.parts += stringifyChunk(result, part);
|
||||
}
|
||||
}
|
||||
toString() {
|
||||
return this.parts;
|
||||
}
|
||||
toArrayBuffer() {
|
||||
return encoder.encode(this.parts);
|
||||
}
|
||||
}
|
||||
function chunkToByteArray(result, chunk) {
|
||||
if (chunk instanceof Uint8Array) {
|
||||
return chunk;
|
||||
}
|
||||
let stringified = stringifyChunk(result, chunk);
|
||||
return encoder.encode(stringified.toString());
|
||||
}
|
||||
export {
|
||||
Fragment,
|
||||
HTMLParts,
|
||||
Renderer,
|
||||
chunkToByteArray,
|
||||
decoder,
|
||||
encoder,
|
||||
stringifyChunk
|
||||
};
|
7
node_modules/astro/dist/runtime/server/render/component.d.ts
generated
vendored
Normal file
7
node_modules/astro/dist/runtime/server/render/component.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
import type { SSRResult } from '../../../@types/astro';
|
||||
import type { RenderInstruction } from './types.js';
|
||||
import { HTMLBytes } from '../escape.js';
|
||||
import { type AstroComponentInstance } from './astro/index.js';
|
||||
export type ComponentIterable = AsyncIterable<string | HTMLBytes | RenderInstruction>;
|
||||
export declare function renderComponent(result: SSRResult, displayName: string, Component: unknown, props: Record<string | number, any>, slots?: any): Promise<ComponentIterable> | ComponentIterable | AstroComponentInstance;
|
||||
export declare function renderComponentToIterable(result: SSRResult, displayName: string, Component: unknown, props: Record<string | number, any>, slots?: any): Promise<ComponentIterable> | ComponentIterable;
|
317
node_modules/astro/dist/runtime/server/render/component.js
generated
vendored
Normal file
317
node_modules/astro/dist/runtime/server/render/component.js
generated
vendored
Normal file
|
@ -0,0 +1,317 @@
|
|||
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 {
|
||||
createAstroComponentInstance,
|
||||
isAstroComponentFactory,
|
||||
isAstroComponentInstance,
|
||||
renderAstroTemplateResult,
|
||||
renderTemplate
|
||||
} from "./astro/index.js";
|
||||
import { Fragment, Renderer, stringifyChunk } from "./common.js";
|
||||
import { componentIsHTMLElement, renderHTMLElement } from "./dom.js";
|
||||
import { renderSlots, renderSlotToString } from "./slot.js";
|
||||
import { formatList, internalSpreadAttributes, renderElement, voidElementNames } from "./util.js";
|
||||
const rendererAliases = /* @__PURE__ */ new Map([["solid", "solid-js"]]);
|
||||
function guessRenderers(componentUrl) {
|
||||
const extname = componentUrl == null ? void 0 : 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)"];
|
||||
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) {
|
||||
const exp = supportsAstroStaticSlot ? ASTRO_STATIC_SLOT_EXP : ASTRO_SLOT_EXP;
|
||||
return html.replace(exp, "");
|
||||
}
|
||||
async function renderFrameworkComponent(result, displayName, Component, _props, slots = {}) {
|
||||
var _a, _b, _c;
|
||||
if (!Component && !_props["client:only"]) {
|
||||
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 } = 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 = renderHTMLElement(result, Component, _props, slots);
|
||||
return output;
|
||||
}
|
||||
} else {
|
||||
if (metadata.hydrateArgs) {
|
||||
const passedName = metadata.hydrateArgs;
|
||||
const rendererName = rendererAliases.has(passedName) ? rendererAliases.get(passedName) : passedName;
|
||||
renderer = renderers.find(
|
||||
({ name }) => name === `@astrojs/${rendererName}` || name === rendererName
|
||||
);
|
||||
}
|
||||
if (!renderer && validRenderers.length === 1) {
|
||||
renderer = validRenderers[0];
|
||||
}
|
||||
if (!renderer) {
|
||||
const extname = (_a = metadata.componentUrl) == null ? void 0 : _a.split(".").pop();
|
||||
renderer = renderers.filter(
|
||||
({ name }) => name === `@astrojs/${extname}` || name === extname
|
||||
)[0];
|
||||
}
|
||||
}
|
||||
if (!renderer) {
|
||||
if (metadata.hydrate === "only") {
|
||||
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,
|
||||
(_b = metadata == null ? void 0 : metadata.componentUrl) == null ? void 0 : _b.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,
|
||||
props,
|
||||
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") {
|
||||
html = await renderSlotToString(result, slots == null ? void 0 : slots.fallback);
|
||||
} else {
|
||||
({ html, attrs } = await renderer.ssr.renderToStaticMarkup.call(
|
||||
{ result },
|
||||
Component,
|
||||
props,
|
||||
children,
|
||||
metadata
|
||||
));
|
||||
}
|
||||
}
|
||||
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 iterable = renderAstroTemplateResult(
|
||||
await renderTemplate`<${Tag}${internalSpreadAttributes(props)}${markHTMLString(
|
||||
childSlots === "" && voidElementNames.test(Tag) ? `/>` : `>${childSlots}</${Tag}>`
|
||||
)}`
|
||||
);
|
||||
html = "";
|
||||
for await (const chunk of iterable) {
|
||||
html += chunk;
|
||||
}
|
||||
}
|
||||
if (!hydration) {
|
||||
return async function* () {
|
||||
var _a2;
|
||||
if (slotInstructions) {
|
||||
yield* slotInstructions;
|
||||
}
|
||||
if (isPage || (renderer == null ? void 0 : renderer.name) === "astro:jsx") {
|
||||
yield html;
|
||||
} else if (html && html.length > 0) {
|
||||
yield markHTMLString(
|
||||
removeStaticAstroSlot(html, ((_a2 = renderer == null ? void 0 : renderer.ssr) == null ? void 0 : _a2.supportsAstroStaticSlot) ?? false)
|
||||
);
|
||||
} else {
|
||||
yield "";
|
||||
}
|
||||
}();
|
||||
}
|
||||
const astroId = shorthash(
|
||||
`<!--${metadata.componentExport.value}:${metadata.componentUrl}-->
|
||||
${html}
|
||||
${serializeProps(
|
||||
props,
|
||||
metadata
|
||||
)}`
|
||||
);
|
||||
const island = await generateHydrateScript(
|
||||
{ renderer, result, astroId, props, attrs },
|
||||
metadata
|
||||
);
|
||||
let unrenderedSlots = [];
|
||||
if (html) {
|
||||
if (Object.keys(children).length > 0) {
|
||||
for (const key of Object.keys(children)) {
|
||||
let tagName = ((_c = renderer == null ? void 0 : renderer.ssr) == null ? void 0 : _c.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"] = "";
|
||||
}
|
||||
async function* renderAll() {
|
||||
if (slotInstructions) {
|
||||
yield* slotInstructions;
|
||||
}
|
||||
yield { type: "directive", hydration, result };
|
||||
yield markHTMLString(renderElement("astro-island", island, false));
|
||||
}
|
||||
return renderAll();
|
||||
}
|
||||
function sanitizeElementName(tag) {
|
||||
const unsafe = /[&<>'"\s]+/g;
|
||||
if (!unsafe.test(tag))
|
||||
return tag;
|
||||
return tag.trim().split(unsafe)[0].trim();
|
||||
}
|
||||
async function renderFragmentComponent(result, slots = {}) {
|
||||
const children = await renderSlotToString(result, slots == null ? void 0 : slots.default);
|
||||
if (children == null) {
|
||||
return children;
|
||||
}
|
||||
return markHTMLString(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) => stringifyChunk(result, instr)).join("") : "";
|
||||
return markHTMLString(hydrationHtml + html);
|
||||
}
|
||||
function renderComponent(result, displayName, Component, props, slots = {}) {
|
||||
if (isPromise(Component)) {
|
||||
return Promise.resolve(Component).then((Unwrapped) => {
|
||||
return renderComponent(result, displayName, Unwrapped, props, slots);
|
||||
});
|
||||
}
|
||||
if (isFragmentComponent(Component)) {
|
||||
return renderFragmentComponent(result, slots);
|
||||
}
|
||||
if (isHTMLComponent(Component)) {
|
||||
return renderHTMLComponent(result, Component, props, slots);
|
||||
}
|
||||
if (isAstroComponentFactory(Component)) {
|
||||
return createAstroComponentInstance(result, displayName, Component, props, slots);
|
||||
}
|
||||
return renderFrameworkComponent(result, displayName, Component, props, slots);
|
||||
}
|
||||
function renderComponentToIterable(result, displayName, Component, props, slots = {}) {
|
||||
const renderResult = renderComponent(result, displayName, Component, props, slots);
|
||||
if (isAstroComponentInstance(renderResult)) {
|
||||
return renderResult.render();
|
||||
}
|
||||
return renderResult;
|
||||
}
|
||||
export {
|
||||
renderComponent,
|
||||
renderComponentToIterable
|
||||
};
|
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';
|
||||
export declare function componentIsHTMLElement(Component: unknown): boolean;
|
||||
export declare function renderHTMLElement(result: SSRResult, constructor: typeof HTMLElement, props: any, slots: any): Promise<any>;
|
27
node_modules/astro/dist/runtime/server/render/dom.js
generated
vendored
Normal file
27
node_modules/astro/dist/runtime/server/render/dom.js
generated
vendored
Normal file
|
@ -0,0 +1,27 @@
|
|||
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 == null ? void 0 : 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';
|
||||
import type { MaybeRenderHeadInstruction, RenderHeadInstruction } from './types';
|
||||
export declare function renderAllHeadContent(result: SSRResult): any;
|
||||
export declare function renderHead(): Generator<RenderHeadInstruction>;
|
||||
export declare function maybeRenderHead(): Generator<MaybeRenderHeadInstruction>;
|
36
node_modules/astro/dist/runtime/server/render/head.js
generated
vendored
Normal file
36
node_modules/astro/dist/runtime/server/render/head.js
generated
vendored
Normal file
|
@ -0,0 +1,36 @@
|
|||
import { markHTMLString } from "../escape.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 = links.join("\n") + styles.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() {
|
||||
yield { type: "head" };
|
||||
}
|
||||
function* maybeRenderHead() {
|
||||
yield { type: "maybe-head" };
|
||||
}
|
||||
export {
|
||||
maybeRenderHead,
|
||||
renderAllHeadContent,
|
||||
renderHead
|
||||
};
|
11
node_modules/astro/dist/runtime/server/render/index.d.ts
generated
vendored
Normal file
11
node_modules/astro/dist/runtime/server/render/index.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,11 @@
|
|||
export type { AstroComponentFactory, AstroComponentInstance } from './astro/index';
|
||||
export { createHeadAndContent, renderAstroTemplateResult, renderTemplate, renderToString, } from './astro/index.js';
|
||||
export { Fragment, Renderer, stringifyChunk } from './common.js';
|
||||
export { renderComponent, renderComponentToIterable } from './component.js';
|
||||
export { renderHTMLElement } from './dom.js';
|
||||
export { maybeRenderHead, renderHead } from './head.js';
|
||||
export { renderPage } from './page.js';
|
||||
export { renderSlot, renderSlotToString, type ComponentSlots } from './slot.js';
|
||||
export { renderScriptElement, renderUniqueStylesheet } from './tags.js';
|
||||
export type { RenderInstruction } from './types';
|
||||
export { addAttribute, defineScriptVars, voidElementNames } from './util.js';
|
36
node_modules/astro/dist/runtime/server/render/index.js
generated
vendored
Normal file
36
node_modules/astro/dist/runtime/server/render/index.js
generated
vendored
Normal file
|
@ -0,0 +1,36 @@
|
|||
import {
|
||||
createHeadAndContent,
|
||||
renderAstroTemplateResult,
|
||||
renderTemplate,
|
||||
renderToString
|
||||
} from "./astro/index.js";
|
||||
import { Fragment, Renderer, stringifyChunk } from "./common.js";
|
||||
import { renderComponent, renderComponentToIterable } from "./component.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,
|
||||
createHeadAndContent,
|
||||
defineScriptVars,
|
||||
maybeRenderHead,
|
||||
renderAstroTemplateResult,
|
||||
renderComponent,
|
||||
renderComponentToIterable,
|
||||
renderHTMLElement,
|
||||
renderHead,
|
||||
renderPage,
|
||||
renderScriptElement,
|
||||
renderSlot,
|
||||
renderSlotToString,
|
||||
renderTemplate,
|
||||
renderToString,
|
||||
renderUniqueStylesheet,
|
||||
stringifyChunk,
|
||||
voidElementNames
|
||||
};
|
9
node_modules/astro/dist/runtime/server/render/page.d.ts
generated
vendored
Normal file
9
node_modules/astro/dist/runtime/server/render/page.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
import type { RouteData, SSRResult } from '../../../@types/astro';
|
||||
import type { AstroComponentFactory } from './index';
|
||||
declare const needsHeadRenderingSymbol: unique symbol;
|
||||
type NonAstroPageComponent = {
|
||||
name: string;
|
||||
[needsHeadRenderingSymbol]: boolean;
|
||||
};
|
||||
export declare function renderPage(result: SSRResult, componentFactory: AstroComponentFactory | NonAstroPageComponent, props: any, children: any, streaming: boolean, route?: RouteData | undefined): Promise<Response>;
|
||||
export {};
|
168
node_modules/astro/dist/runtime/server/render/page.js
generated
vendored
Normal file
168
node_modules/astro/dist/runtime/server/render/page.js
generated
vendored
Normal file
|
@ -0,0 +1,168 @@
|
|||
import { AstroError, AstroErrorData } from "../../../core/errors/index.js";
|
||||
import { isHTMLString } from "../escape.js";
|
||||
import { createResponse } from "../response.js";
|
||||
import {
|
||||
isAstroComponentFactory,
|
||||
isAstroComponentInstance,
|
||||
isHeadAndContent,
|
||||
isRenderTemplateResult,
|
||||
renderAstroTemplateResult
|
||||
} from "./astro/index.js";
|
||||
import { chunkToByteArray, encoder, HTMLParts } from "./common.js";
|
||||
import { renderComponent } from "./component.js";
|
||||
import { maybeRenderHead } from "./head.js";
|
||||
const needsHeadRenderingSymbol = Symbol.for("astro.needsHeadRendering");
|
||||
function nonAstroPageNeedsHeadInjection(pageComponent) {
|
||||
return needsHeadRenderingSymbol in pageComponent && !!pageComponent[needsHeadRenderingSymbol];
|
||||
}
|
||||
async function iterableToHTMLBytes(result, iterable, onDocTypeInjection) {
|
||||
const parts = new HTMLParts();
|
||||
let i = 0;
|
||||
for await (const chunk of iterable) {
|
||||
if (isHTMLString(chunk)) {
|
||||
if (i === 0) {
|
||||
i++;
|
||||
if (!/<!doctype html/i.test(String(chunk))) {
|
||||
parts.append(`${result.compressHTML ? "<!DOCTYPE html>" : "<!DOCTYPE html>\n"}`, result);
|
||||
if (onDocTypeInjection) {
|
||||
await onDocTypeInjection(parts);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
parts.append(chunk, result);
|
||||
}
|
||||
return parts.toArrayBuffer();
|
||||
}
|
||||
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 renderPage(result, componentFactory, props, children, streaming, route) {
|
||||
var _a, _b;
|
||||
if (!isAstroComponentFactory(componentFactory)) {
|
||||
result._metadata.headInTree = ((_a = result.componentMetadata.get(componentFactory.moduleId)) == null ? void 0 : _a.containsHead) ?? false;
|
||||
const pageProps = { ...props ?? {}, "server:root": true };
|
||||
let output;
|
||||
let head = "";
|
||||
try {
|
||||
if (nonAstroPageNeedsHeadInjection(componentFactory)) {
|
||||
const parts = new HTMLParts();
|
||||
for await (const chunk of maybeRenderHead()) {
|
||||
parts.append(chunk, result);
|
||||
}
|
||||
head = parts.toString();
|
||||
}
|
||||
const renderResult = await renderComponent(
|
||||
result,
|
||||
componentFactory.name,
|
||||
componentFactory,
|
||||
pageProps,
|
||||
null
|
||||
);
|
||||
if (isAstroComponentInstance(renderResult)) {
|
||||
output = renderResult.render();
|
||||
} else {
|
||||
output = renderResult;
|
||||
}
|
||||
} catch (e) {
|
||||
if (AstroError.is(e) && !e.loc) {
|
||||
e.setLocation({
|
||||
file: route == null ? void 0 : route.component
|
||||
});
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
const bytes = await iterableToHTMLBytes(result, output, async (parts) => {
|
||||
parts.append(head, result);
|
||||
});
|
||||
return new Response(bytes, {
|
||||
headers: new Headers([
|
||||
["Content-Type", "text/html; charset=utf-8"],
|
||||
["Content-Length", bytes.byteLength.toString()]
|
||||
])
|
||||
});
|
||||
}
|
||||
result._metadata.headInTree = ((_b = result.componentMetadata.get(componentFactory.moduleId)) == null ? void 0 : _b.containsHead) ?? false;
|
||||
const factoryReturnValue = await componentFactory(result, props, children);
|
||||
const factoryIsHeadAndContent = isHeadAndContent(factoryReturnValue);
|
||||
if (isRenderTemplateResult(factoryReturnValue) || factoryIsHeadAndContent) {
|
||||
await bufferHeadContent(result);
|
||||
const templateResult = factoryIsHeadAndContent ? factoryReturnValue.content : factoryReturnValue;
|
||||
let iterable = renderAstroTemplateResult(templateResult);
|
||||
let init = result.response;
|
||||
let headers = new Headers(init.headers);
|
||||
let body;
|
||||
if (streaming) {
|
||||
body = new ReadableStream({
|
||||
start(controller) {
|
||||
async function read() {
|
||||
let i = 0;
|
||||
try {
|
||||
for await (const chunk of iterable) {
|
||||
if (isHTMLString(chunk)) {
|
||||
if (i === 0) {
|
||||
if (!/<!doctype html/i.test(String(chunk))) {
|
||||
controller.enqueue(
|
||||
encoder.encode(
|
||||
`${result.compressHTML ? "<!DOCTYPE html>" : "<!DOCTYPE html>\n"}`
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (chunk instanceof Response) {
|
||||
throw new AstroError({
|
||||
...AstroErrorData.ResponseSentError
|
||||
});
|
||||
}
|
||||
const bytes = chunkToByteArray(result, chunk);
|
||||
controller.enqueue(bytes);
|
||||
i++;
|
||||
}
|
||||
controller.close();
|
||||
} catch (e) {
|
||||
if (AstroError.is(e) && !e.loc) {
|
||||
e.setLocation({
|
||||
file: route == null ? void 0 : route.component
|
||||
});
|
||||
}
|
||||
controller.error(e);
|
||||
}
|
||||
}
|
||||
read();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
body = await iterableToHTMLBytes(result, iterable);
|
||||
headers.set("Content-Length", body.byteLength.toString());
|
||||
}
|
||||
let response = createResponse(body, { ...init, headers });
|
||||
return response;
|
||||
}
|
||||
if (!(factoryReturnValue instanceof Response)) {
|
||||
throw new AstroError({
|
||||
...AstroErrorData.OnlyResponseCanBeReturned,
|
||||
message: AstroErrorData.OnlyResponseCanBeReturned.message(
|
||||
route == null ? void 0 : route.route,
|
||||
typeof factoryReturnValue
|
||||
),
|
||||
location: {
|
||||
file: route == null ? void 0 : route.component
|
||||
}
|
||||
});
|
||||
}
|
||||
return factoryReturnValue;
|
||||
}
|
||||
export {
|
||||
renderPage
|
||||
};
|
22
node_modules/astro/dist/runtime/server/render/slot.d.ts
generated
vendored
Normal file
22
node_modules/astro/dist/runtime/server/render/slot.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,22 @@
|
|||
import type { SSRResult } from '../../../@types/astro.js';
|
||||
import type { renderTemplate } from './astro/render-template.js';
|
||||
import type { RenderInstruction } from './types.js';
|
||||
import { HTMLString } from '../escape.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): AsyncGenerator<any, void, undefined>;
|
||||
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 {};
|
66
node_modules/astro/dist/runtime/server/render/slot.js
generated
vendored
Normal file
66
node_modules/astro/dist/runtime/server/render/slot.js
generated
vendored
Normal file
|
@ -0,0 +1,66 @@
|
|||
import { HTMLString, markHTMLString } from "../escape.js";
|
||||
import { renderChild } from "./any.js";
|
||||
const slotString = Symbol.for("astro:slot-string");
|
||||
class SlotString extends HTMLString {
|
||||
constructor(content, instructions) {
|
||||
super(content);
|
||||
this.instructions = instructions;
|
||||
this[slotString] = true;
|
||||
}
|
||||
}
|
||||
slotString;
|
||||
function isSlotString(str) {
|
||||
return !!str[slotString];
|
||||
}
|
||||
async function* renderSlot(result, slotted, fallback) {
|
||||
if (slotted) {
|
||||
let iterator = renderChild(typeof slotted === "function" ? slotted(result) : slotted);
|
||||
yield* iterator;
|
||||
}
|
||||
if (fallback && !slotted) {
|
||||
yield* renderSlot(result, fallback);
|
||||
}
|
||||
}
|
||||
async function renderSlotToString(result, slotted, fallback) {
|
||||
let content = "";
|
||||
let instructions = null;
|
||||
let iterator = renderSlot(result, slotted, fallback);
|
||||
for await (const chunk of iterator) {
|
||||
if (typeof chunk.type === "string") {
|
||||
if (instructions === null) {
|
||||
instructions = [];
|
||||
}
|
||||
instructions.push(chunk);
|
||||
} else {
|
||||
content += chunk;
|
||||
}
|
||||
}
|
||||
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 };
|
||||
}
|
||||
export {
|
||||
SlotString,
|
||||
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';
|
||||
import type { StylesheetAsset } from '../../../core/app/types';
|
||||
export declare function renderScriptElement({ props, children }: SSRElement): string;
|
||||
export declare function renderUniqueStylesheet(result: SSRResult, sheet: StylesheetAsset): string | undefined;
|
23
node_modules/astro/dist/runtime/server/render/tags.js
generated
vendored
Normal file
23
node_modules/astro/dist/runtime/server/render/tags.js
generated
vendored
Normal file
|
@ -0,0 +1,23 @@
|
|||
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: { type: "text/css" }, children: sheet.content });
|
||||
}
|
||||
}
|
||||
export {
|
||||
renderScriptElement,
|
||||
renderUniqueStylesheet
|
||||
};
|
12
node_modules/astro/dist/runtime/server/render/types.d.ts
generated
vendored
Normal file
12
node_modules/astro/dist/runtime/server/render/types.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,12 @@
|
|||
import type { HydrationMetadata } from '../hydration.js';
|
||||
export type RenderDirectiveInstruction = {
|
||||
type: 'directive';
|
||||
hydration: HydrationMetadata;
|
||||
};
|
||||
export type RenderHeadInstruction = {
|
||||
type: 'head';
|
||||
};
|
||||
export type MaybeRenderHeadInstruction = {
|
||||
type: 'maybe-head';
|
||||
};
|
||||
export type RenderInstruction = RenderDirectiveInstruction | RenderHeadInstruction | MaybeRenderHeadInstruction;
|
0
node_modules/astro/dist/runtime/server/render/types.js
generated
vendored
Normal file
0
node_modules/astro/dist/runtime/server/render/types.js
generated
vendored
Normal file
26
node_modules/astro/dist/runtime/server/render/util.d.ts
generated
vendored
Normal file
26
node_modules/astro/dist/runtime/server/render/util.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,26 @@
|
|||
import type { SSRElement } from '../../../@types/astro';
|
||||
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;
|
||||
/**
|
||||
* This will take an array of async iterables and start buffering them eagerly.
|
||||
* To avoid useless buffering, it will only start buffering the next tick, so the
|
||||
* first sync iterables won't be buffered.
|
||||
*/
|
||||
export declare function bufferIterators<T>(iterators: AsyncIterable<T>[]): AsyncIterable<T>[];
|
||||
export declare class EagerAsyncIterableIterator {
|
||||
#private;
|
||||
constructor(iterable: AsyncIterable<any>);
|
||||
/**
|
||||
* Starts to eagerly fetch the inner iterator and cache the results.
|
||||
* Note: This might not be called after next() has been called once, e.g. the iterator is started
|
||||
*/
|
||||
buffer(): Promise<void>;
|
||||
next(): Promise<IteratorResult<any, any>>;
|
||||
isStarted(): boolean;
|
||||
[Symbol.asyncIterator](): this;
|
||||
}
|
215
node_modules/astro/dist/runtime/server/render/util.js
generated
vendored
Normal file
215
node_modules/astro/dist/runtime/server/render/util.js
generated
vendored
Normal file
|
@ -0,0 +1,215 @@
|
|||
import { HTMLString, markHTMLString } from "../escape.js";
|
||||
import { serializeListValue } from "../util.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|controls|default|defer|disabled|disablepictureinpicture|disableremoteplayback|formnovalidate|hidden|loop|nomodule|novalidate|open|playsinline|readonly|required|reversed|scoped|seamless|itemscope)$/i;
|
||||
const htmlEnumAttributes = /^(contenteditable|draggable|spellcheck|value)$/i;
|
||||
const svgEnumAttributes = /^(autoReverse|externalResourcesRequired|focusable|preserveAlpha)$/i;
|
||||
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]|\s/.test(match))
|
||||
return "";
|
||||
return index === 0 ? match : match.toUpperCase();
|
||||
});
|
||||
const toAttributeString = (value, shouldEscape = true) => shouldEscape ? String(value).replace(/&/g, "&").replace(/"/g, """) : value;
|
||||
const kebab = (k) => k.toLowerCase() === k ? k : k.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`);
|
||||
const toStyleString = (obj) => Object.entries(obj).map(([k, v]) => {
|
||||
if (k[0] !== "-" && k[1] !== "-")
|
||||
return `${kebab(k)}:${v}`;
|
||||
if (kebab(k) !== k)
|
||||
return `${kebab(k)}:var(${k});${k}:${v}`;
|
||||
return `${k}:${v}`;
|
||||
}).join(";");
|
||||
function defineScriptVars(vars) {
|
||||
var _a;
|
||||
let output = "";
|
||||
for (const [key, value] of Object.entries(vars)) {
|
||||
output += `const ${toIdent(key)} = ${(_a = JSON.stringify(value)) == null ? void 0 : _a.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(serializeListValue(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 (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 iteratorQueue = [];
|
||||
function queueIteratorBuffers(iterators) {
|
||||
if (iteratorQueue.length === 0) {
|
||||
setTimeout(() => {
|
||||
iteratorQueue.forEach((its) => its.forEach((it) => !it.isStarted() && it.buffer()));
|
||||
iteratorQueue.length = 0;
|
||||
});
|
||||
}
|
||||
iteratorQueue.push(iterators);
|
||||
}
|
||||
function bufferIterators(iterators) {
|
||||
const eagerIterators = iterators.map((it) => new EagerAsyncIterableIterator(it));
|
||||
queueIteratorBuffers(eagerIterators);
|
||||
return eagerIterators;
|
||||
}
|
||||
class EagerAsyncIterableIterator {
|
||||
#iterable;
|
||||
#queue = new Queue();
|
||||
#error = void 0;
|
||||
#next;
|
||||
/**
|
||||
* Whether the proxy is running in buffering or pass-through mode
|
||||
*/
|
||||
#isBuffering = false;
|
||||
#gen = void 0;
|
||||
#isStarted = false;
|
||||
constructor(iterable) {
|
||||
this.#iterable = iterable;
|
||||
}
|
||||
/**
|
||||
* Starts to eagerly fetch the inner iterator and cache the results.
|
||||
* Note: This might not be called after next() has been called once, e.g. the iterator is started
|
||||
*/
|
||||
async buffer() {
|
||||
if (this.#gen) {
|
||||
throw new Error("Cannot not switch from non-buffer to buffer mode");
|
||||
}
|
||||
this.#isBuffering = true;
|
||||
this.#isStarted = true;
|
||||
this.#gen = this.#iterable[Symbol.asyncIterator]();
|
||||
let value = void 0;
|
||||
do {
|
||||
this.#next = this.#gen.next();
|
||||
try {
|
||||
value = await this.#next;
|
||||
this.#queue.push(value);
|
||||
} catch (e) {
|
||||
this.#error = e;
|
||||
}
|
||||
} while (value && !value.done);
|
||||
}
|
||||
async next() {
|
||||
if (this.#error) {
|
||||
throw this.#error;
|
||||
}
|
||||
if (!this.#isBuffering) {
|
||||
if (!this.#gen) {
|
||||
this.#isStarted = true;
|
||||
this.#gen = this.#iterable[Symbol.asyncIterator]();
|
||||
}
|
||||
return await this.#gen.next();
|
||||
}
|
||||
if (!this.#queue.isEmpty()) {
|
||||
return this.#queue.shift();
|
||||
}
|
||||
await this.#next;
|
||||
return this.#queue.shift();
|
||||
}
|
||||
isStarted() {
|
||||
return this.#isStarted;
|
||||
}
|
||||
[Symbol.asyncIterator]() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
class Queue {
|
||||
constructor() {
|
||||
this.head = void 0;
|
||||
this.tail = void 0;
|
||||
}
|
||||
push(item) {
|
||||
if (this.head === void 0) {
|
||||
this.head = { item };
|
||||
this.tail = this.head;
|
||||
} else {
|
||||
this.tail.next = { item };
|
||||
this.tail = this.tail.next;
|
||||
}
|
||||
}
|
||||
isEmpty() {
|
||||
return this.head === void 0;
|
||||
}
|
||||
shift() {
|
||||
var _a, _b;
|
||||
const val = (_a = this.head) == null ? void 0 : _a.item;
|
||||
this.head = (_b = this.head) == null ? void 0 : _b.next;
|
||||
return val;
|
||||
}
|
||||
}
|
||||
export {
|
||||
EagerAsyncIterableIterator,
|
||||
addAttribute,
|
||||
bufferIterators,
|
||||
defineScriptVars,
|
||||
formatList,
|
||||
internalSpreadAttributes,
|
||||
renderElement,
|
||||
toAttributeString,
|
||||
voidElementNames
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue