MCPcopy Create free account
hub / github.com/DavidHDev/react-bits / setup

Function setup

src/tailwind/TextAnimations/ASCIIText/ASCIIText.jsx:429–468  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

427 };
428
429 const setup = async () => {
430 const { width, height } = containerRef.current.getBoundingClientRect();
431
432 if (width === 0 || height === 0) {
433 observer = new IntersectionObserver(
434 async ([entry]) => {
435 if (cancelled) return;
436 if (entry.isIntersecting && entry.boundingClientRect.width > 0 && entry.boundingClientRect.height > 0) {
437 const { width: w, height: h } = entry.boundingClientRect;
438 observer.disconnect();
439 observer = null;
440
441 if (!cancelled) {
442 asciiRef.current = await createAndInit(containerRef.current, w, h);
443 if (!cancelled && asciiRef.current) {
444 asciiRef.current.load();
445 }
446 }
447 }
448 },
449 { threshold: 0.1 }
450 );
451 observer.observe(containerRef.current);
452 return;
453 }
454
455 asciiRef.current = await createAndInit(containerRef.current, width, height);
456 if (!cancelled && asciiRef.current) {
457 asciiRef.current.load();
458
459 ro = new ResizeObserver(entries => {
460 if (!entries[0] || !asciiRef.current) return;
461 const { width: w, height: h } = entries[0].contentRect;
462 if (w > 0 && h > 0) {
463 asciiRef.current.setSize(w, h);
464 }
465 });
466 ro.observe(containerRef.current);
467 }
468 };
469
470 setup();
471

Callers 1

ASCIITextFunction · 0.70

Calls 3

createAndInitFunction · 0.70
loadMethod · 0.45
setSizeMethod · 0.45

Tested by

no test coverage detected