Home / File/ ssr-element.ts — astro Source File

ssr-element.ts — astro Source File

Architecture documentation for ssr-element.ts, a typescript file in the astro codebase. 4 imports, 0 dependents.

File typescript CoreAstro RenderingEngine 4 imports 5 functions

Entity Profile

Dependency Diagram

graph LR
  0bd2e8b9_eb60_d252_4865_5b65ac27a240["ssr-element.ts"]
  617c63d5_1302_acd7_3e75_06534fb7e782["../../assets/utils/getAssetsPrefix.js"]
  0bd2e8b9_eb60_d252_4865_5b65ac27a240 --> 617c63d5_1302_acd7_3e75_06534fb7e782
  7e4494c0_5563_4329_1bff_a84be66e1bc2["../core/path.js"]
  0bd2e8b9_eb60_d252_4865_5b65ac27a240 --> 7e4494c0_5563_4329_1bff_a84be66e1bc2
  10d4e39f_edb6_3e34_aa93_ae1211e7da05["../types/public/internal.js"]
  0bd2e8b9_eb60_d252_4865_5b65ac27a240 --> 10d4e39f_edb6_3e34_aa93_ae1211e7da05
  a4f2698c_5256_262a_ba7c_f72b51878d10["../core/app/types.js"]
  0bd2e8b9_eb60_d252_4865_5b65ac27a240 --> a4f2698c_5256_262a_ba7c_f72b51878d10
  style 0bd2e8b9_eb60_d252_4865_5b65ac27a240 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { getAssetsPrefix } from '../../assets/utils/getAssetsPrefix.js';
import { fileExtension, joinPaths, prependForwardSlash, slash } from '../../core/path.js';
import type { SSRElement } from '../../types/public/internal.js';
import type { AssetsPrefix, StylesheetAsset } from '../app/types.js';

export function createAssetLink(
	href: string,
	base?: string,
	assetsPrefix?: AssetsPrefix,
	queryParams?: URLSearchParams,
): string {
	let url = '';
	if (assetsPrefix) {
		const pf = getAssetsPrefix(fileExtension(href), assetsPrefix);
		url = joinPaths(pf, slash(href));
	} else if (base) {
		url = prependForwardSlash(joinPaths(base, slash(href)));
	} else {
		url = href;
	}
	if (queryParams) {
		url += '?' + queryParams.toString();
	}
	return url;
}

function createStylesheetElement(
	stylesheet: StylesheetAsset,
	base?: string,
	assetsPrefix?: AssetsPrefix,
	queryParams?: URLSearchParams,
): SSRElement {
	if (stylesheet.type === 'inline') {
		return {
			props: {},
			children: stylesheet.content,
		};
	} else {
		return {
			props: {
				rel: 'stylesheet',
				href: createAssetLink(stylesheet.src, base, assetsPrefix, queryParams),
			},
			children: '',
		};
	}
}

export function createStylesheetElementSet(
	stylesheets: StylesheetAsset[],
	base?: string,
	assetsPrefix?: AssetsPrefix,
	queryParams?: URLSearchParams,
): Set<SSRElement> {
	return new Set(
		stylesheets.map((s) => createStylesheetElement(s, base, assetsPrefix, queryParams)),
	);
}

export function createModuleScriptElement(
	script: { type: 'inline' | 'external'; value: string },
	base?: string,
	assetsPrefix?: AssetsPrefix,
	queryParams?: URLSearchParams,
): SSRElement {
	if (script.type === 'external') {
		return createModuleScriptElementWithSrc(script.value, base, assetsPrefix, queryParams);
	} else {
		return {
			props: {
				type: 'module',
			},
			children: script.value,
		};
	}
}

function createModuleScriptElementWithSrc(
	src: string,
	base?: string,
	assetsPrefix?: AssetsPrefix,
	queryParams?: URLSearchParams,
): SSRElement {
	return {
		props: {
			type: 'module',
			src: createAssetLink(src, base, assetsPrefix, queryParams),
		},
		children: '',
	};
}

Domain

Subdomains

Dependencies

  • ../../assets/utils/getAssetsPrefix.js
  • ../core/app/types.js
  • ../core/path.js
  • ../types/public/internal.js

Frequently Asked Questions

What does ssr-element.ts do?
ssr-element.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 ssr-element.ts?
ssr-element.ts defines 5 function(s): createAssetLink, createModuleScriptElement, createModuleScriptElementWithSrc, createStylesheetElement, createStylesheetElementSet.
What does ssr-element.ts depend on?
ssr-element.ts imports 4 module(s): ../../assets/utils/getAssetsPrefix.js, ../core/app/types.js, ../core/path.js, ../types/public/internal.js.
Where is ssr-element.ts in the architecture?
ssr-element.ts is located at packages/astro/src/core/render/ssr-element.ts (domain: CoreAstro, subdomain: RenderingEngine, directory: packages/astro/src/core/render).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free