runtime.ts — astro Source File
Architecture documentation for runtime.ts, a typescript file in the astro codebase. 2 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 7fdc3f21_0a35_05d8_60c6_78c31cc2f5e3["runtime.ts"] 9e624f62_bcfa_4352_e9a0_dd454823f706["../../runtime/server/index.js"] 7fdc3f21_0a35_05d8_60c6_78c31cc2f5e3 --> 9e624f62_bcfa_4352_e9a0_dd454823f706 416eda3d_47e6_c298_102b_b7a37d86a44e["../../assets/types.js"] 7fdc3f21_0a35_05d8_60c6_78c31cc2f5e3 --> 416eda3d_47e6_c298_102b_b7a37d86a44e style 7fdc3f21_0a35_05d8_60c6_78c31cc2f5e3 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import {
createComponent,
render,
spreadAttributes,
unescapeHTML,
} from '../runtime/server/index.js';
import type { ImageMetadata } from './types.js';
export interface SvgComponentProps {
meta: ImageMetadata;
attributes: Record<string, string>;
children: string;
}
export function createSvgComponent({ meta, attributes, children }: SvgComponentProps) {
const Component = createComponent((_, props) => {
const normalizedProps = normalizeProps(attributes, props);
return render`<svg${spreadAttributes(normalizedProps)}>${unescapeHTML(children)}</svg>`;
});
if (import.meta.env.DEV) {
// Prevent revealing that this is a component
makeNonEnumerable(Component);
// Maintaining the current `console.log` output for SVG imports
Object.defineProperty(Component, Symbol.for('nodejs.util.inspect.custom'), {
value: (_: any, opts: any, inspect: any) => inspect(meta, opts),
});
}
Object.defineProperty(Component, 'toJSON', {
value: () => meta,
enumerable: false,
});
// Attaching the metadata to the component to maintain current functionality
return Object.assign(Component, meta);
}
type SvgAttributes = Record<string, any>;
/**
* Some attributes required for `image/svg+xml` are irrelevant when inlined in a `text/html` document. We can save a few bytes by dropping them.
*/
const ATTRS_TO_DROP = ['xmlns', 'xmlns:xlink', 'version'];
const DEFAULT_ATTRS: SvgAttributes = {};
export function dropAttributes(attributes: SvgAttributes) {
for (const attr of ATTRS_TO_DROP) {
delete attributes[attr];
}
return attributes;
}
function normalizeProps(attributes: SvgAttributes, props: SvgAttributes) {
return dropAttributes({ ...DEFAULT_ATTRS, ...attributes, ...props });
}
function makeNonEnumerable(object: Record<string, any>) {
for (const property in object) {
Object.defineProperty(object, property, { enumerable: false });
}
}
Domain
Subdomains
Dependencies
- ../../assets/types.js
- ../../runtime/server/index.js
Source
Frequently Asked Questions
What does runtime.ts do?
runtime.ts is a source file in the astro codebase, written in typescript. It belongs to the CoreAstro domain, RenderingEngine subdomain.
What functions are defined in runtime.ts?
runtime.ts defines 4 function(s): createSvgComponent, dropAttributes, makeNonEnumerable, normalizeProps.
What does runtime.ts depend on?
runtime.ts imports 2 module(s): ../../assets/types.js, ../../runtime/server/index.js.
Where is runtime.ts in the architecture?
runtime.ts is located at packages/astro/src/assets/runtime.ts (domain: CoreAstro, subdomain: RenderingEngine, directory: packages/astro/src/assets).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free