UNPKG

astro

Version:

Astro is a modern site builder with web best practices, performance, and DX front-of-mind.

65 lines (64 loc) • 2.73 kB
// NOTE: Although this entrypoint is exported, it is internal API and may change at any time. 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, chunkToString, createHeadAndContent, defineScriptVars, Fragment, maybeRenderHead, Renderer, renderComponent, renderHead, renderHTMLElement, renderPage, renderScript, renderScriptElement, renderSlot, renderSlotToString, renderStreaming, renderTemplate as render, renderTemplate, renderToString, renderUniqueStylesheet, voidElementNames } from "./render/index.js"; export { templateEnter, templateExit } from "./render/template-depth.js"; export { createTransitionScope, renderTransition } from "./transition.js"; import { markHTMLString } from "./escape.js"; import { addAttribute, Renderer } from "./render/index.js"; export 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; } /** @internal Associate JSX components with a specific renderer (see /packages/integrations/mdx/src/vite-plugin-mdx-postprocess.ts) */ export function __astro_tag_component__(Component, rendererName) { if (!Component) return; if (typeof Component !== "function") return; Object.defineProperty(Component, Renderer, { value: rendererName, enumerable: false, writable: false }); } // Adds support for `<Component {...value} /> export function spreadAttributes(values = {}, _name, { class: scopedClassName } = {}) { let output = ""; // If the compiler passes along a scoped class, merge with existing props or inject it 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 of Object.keys(values)) { output += addAttribute(values[key], key, true, _name); } return markHTMLString(output); } // Adds CSS variables to an inline style tag export 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 markHTMLString(output); }