Home / File/ rehype-images-to-component.ts — astro Source File

rehype-images-to-component.ts — astro Source File

Architecture documentation for rehype-images-to-component.ts, a typescript file in the astro codebase. 6 imports, 0 dependents.

File typescript CoreAstro RoutingSystem 6 imports 3 functions

Entity Profile

Dependency Diagram

graph LR
  315ab74a_5989_663f_988a_f9092ffec496["rehype-images-to-component.ts"]
  ab5f9b39_abc6_0697_d4ba_c51748add5b2["./utils.js"]
  315ab74a_5989_663f_988a_f9092ffec496 --> ab5f9b39_abc6_0697_d4ba_c51748add5b2
  f76e2597_e3e8_c502_d293_a666b44d49ce["hast"]
  315ab74a_5989_663f_988a_f9092ffec496 --> f76e2597_e3e8_c502_d293_a666b44d49ce
  350bf1c9_161e_6d98_d477_5ac7e492812d["mdast-util-mdx"]
  315ab74a_5989_663f_988a_f9092ffec496 --> 350bf1c9_161e_6d98_d477_5ac7e492812d
  03fa0bc9_b24b_2cf3_1b96_2104cbcd14a3["mdast-util-mdx-jsx"]
  315ab74a_5989_663f_988a_f9092ffec496 --> 03fa0bc9_b24b_2cf3_1b96_2104cbcd14a3
  d7b51bf7_4a46_1479_0cea_09e174fc7c48["unist-util-visit"]
  315ab74a_5989_663f_988a_f9092ffec496 --> d7b51bf7_4a46_1479_0cea_09e174fc7c48
  b909a1d2_5b96_acd8_d198_1f106f44e2c3["vfile"]
  315ab74a_5989_663f_988a_f9092ffec496 --> b909a1d2_5b96_acd8_d198_1f106f44e2c3
  style 315ab74a_5989_663f_988a_f9092ffec496 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import type { Properties, Root } from 'hast';
import type { MdxJsxAttribute, MdxjsEsm } from 'mdast-util-mdx';
import type { MdxJsxFlowElementHast } from 'mdast-util-mdx-jsx';
import { visit } from 'unist-util-visit';
import type { VFile } from 'vfile';
import { jsToTreeNode } from './utils.js';

export const ASTRO_IMAGE_ELEMENT = 'astro-image';
export const ASTRO_IMAGE_IMPORT = '__AstroImage__';
export const USES_ASTRO_IMAGE_FLAG = '__usesAstroImage';

function createArrayAttribute(name: string, values: (string | number)[]): MdxJsxAttribute {
	return {
		type: 'mdxJsxAttribute',
		name: name,
		value: {
			type: 'mdxJsxAttributeValueExpression',
			value: name,
			data: {
				estree: {
					type: 'Program',
					body: [
						{
							type: 'ExpressionStatement',
							expression: {
								type: 'ArrayExpression',
								elements: values.map((value) => ({
									type: 'Literal',
									value: value,
									raw: String(value),
								})),
							},
						},
					],
					sourceType: 'module',
					comments: [],
				},
			},
		},
	};
}

/**
 * Convert the <img /> element properties (except `src`) to MDX JSX attributes.
 *
 * @param {Properties} props - The element properties
 * @returns {MdxJsxAttribute[]} The MDX attributes
 */
function getImageComponentAttributes(props: Properties): MdxJsxAttribute[] {
	const attrs: MdxJsxAttribute[] = [];

	for (const [prop, value] of Object.entries(props)) {
		if (prop === 'src') continue;

		/*
		 * <Image /> component expects an array for those attributes but the
		 * received properties are sanitized as strings. So we need to convert them
		 * back to an array.
		 */
		if (prop === 'widths' || prop === 'densities') {
// ... (129 more lines)

Domain

Subdomains

Dependencies

  • ./utils.js
  • hast
  • mdast-util-mdx
  • mdast-util-mdx-jsx
  • unist-util-visit
  • vfile

Frequently Asked Questions

What does rehype-images-to-component.ts do?
rehype-images-to-component.ts is a source file in the astro codebase, written in typescript. It belongs to the CoreAstro domain, RoutingSystem subdomain.
What functions are defined in rehype-images-to-component.ts?
rehype-images-to-component.ts defines 3 function(s): createArrayAttribute, getImageComponentAttributes, rehypeImageToComponent.
What does rehype-images-to-component.ts depend on?
rehype-images-to-component.ts imports 6 module(s): ./utils.js, hast, mdast-util-mdx, mdast-util-mdx-jsx, unist-util-visit, vfile.
Where is rehype-images-to-component.ts in the architecture?
rehype-images-to-component.ts is located at packages/integrations/mdx/src/rehype-images-to-component.ts (domain: CoreAstro, subdomain: RoutingSystem, directory: packages/integrations/mdx/src).

Analyze Your Own Codebase

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

Try Supermodel Free