Home / File/ visible.ts — astro Source File

visible.ts — astro Source File

Architecture documentation for visible.ts, a typescript file in the astro codebase. 2 imports, 0 dependents.

File typescript CoreAstro RenderingEngine 2 imports 1 functions

Entity Profile

Dependency Diagram

graph LR
  37aa8300_5daa_9e08_6eed_8c19ecdbf4a1["visible.ts"]
  fba0fdb8_7fc8_4a17_2cab_d6a89c55b288["./elements.js"]
  37aa8300_5daa_9e08_6eed_8c19ecdbf4a1 --> fba0fdb8_7fc8_4a17_2cab_d6a89c55b288
  4c453c0b_17bb_ebc3_f7de_e2a632e42c1e["../types/public/integrations.js"]
  37aa8300_5daa_9e08_6eed_8c19ecdbf4a1 --> 4c453c0b_17bb_ebc3_f7de_e2a632e42c1e
  style 37aa8300_5daa_9e08_6eed_8c19ecdbf4a1 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import type { ClientVisibleOptions } from '../../types/public/elements.js';
import type { ClientDirective } from '../../types/public/integrations.js';

/**
 * Hydrate this component when one of it's children becomes visible
 * We target the children because `astro-island` is set to `display: contents`
 * which doesn't work with IntersectionObserver
 */
const visibleDirective: ClientDirective = (load, options, el) => {
	const cb = async () => {
		const hydrate = await load();
		await hydrate();
	};

	const rawOptions =
		typeof options.value === 'object' ? (options.value as ClientVisibleOptions) : undefined;

	const ioOptions: IntersectionObserverInit = {
		rootMargin: rawOptions?.rootMargin,
	};

	const io = new IntersectionObserver((entries) => {
		for (const entry of entries) {
			if (!entry.isIntersecting) continue;
			// As soon as we hydrate, disconnect this IntersectionObserver for every `astro-island`
			io.disconnect();
			cb();
			break; // break loop on first match
		}
	}, ioOptions);

	for (const child of el.children) {
		io.observe(child);
	}
};

export default visibleDirective;

Domain

Subdomains

Functions

Dependencies

  • ../types/public/integrations.js
  • ./elements.js

Frequently Asked Questions

What does visible.ts do?
visible.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 visible.ts?
visible.ts defines 1 function(s): visibleDirective.
What does visible.ts depend on?
visible.ts imports 2 module(s): ../types/public/integrations.js, ./elements.js.
Where is visible.ts in the architecture?
visible.ts is located at packages/astro/src/runtime/client/visible.ts (domain: CoreAstro, subdomain: RenderingEngine, directory: packages/astro/src/runtime/client).

Analyze Your Own Codebase

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

Try Supermodel Free