@tuwaio/docs-ui 0.0.29 → 0.0.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/dist/components/CodeBlock.cjs +61 -0
  2. package/dist/components/CodeBlock.d.cts +20 -0
  3. package/dist/components/CodeBlock.d.ts +20 -0
  4. package/dist/components/CodeBlock.js +37 -0
  5. package/dist/components/CodeHighlighter.cjs +52 -0
  6. package/dist/components/CodeHighlighter.d.cts +10 -0
  7. package/dist/components/CodeHighlighter.d.ts +10 -0
  8. package/dist/components/CodeHighlighter.js +18 -0
  9. package/dist/components/CopyIconButton.cjs +44 -0
  10. package/dist/components/CopyIconButton.d.cts +9 -0
  11. package/dist/components/CopyIconButton.d.ts +9 -0
  12. package/dist/components/CopyIconButton.js +20 -0
  13. package/dist/components/Features.cjs +42 -0
  14. package/dist/components/Features.d.cts +11 -0
  15. package/dist/components/Features.d.ts +11 -0
  16. package/dist/components/Features.js +18 -0
  17. package/dist/components/Footer.cjs +66 -0
  18. package/dist/components/Footer.d.cts +9 -0
  19. package/dist/components/Footer.d.ts +9 -0
  20. package/dist/components/Footer.js +42 -0
  21. package/dist/components/Logo.cjs +75 -0
  22. package/dist/components/Logo.d.cts +12 -0
  23. package/dist/components/Logo.d.ts +12 -0
  24. package/dist/components/Logo.js +41 -0
  25. package/dist/components/NavBar.cjs +50 -0
  26. package/dist/components/NavBar.d.cts +16 -0
  27. package/dist/components/NavBar.d.ts +16 -0
  28. package/dist/components/NavBar.js +26 -0
  29. package/dist/components/NoSSR.cjs +36 -0
  30. package/dist/components/NoSSR.d.cts +16 -0
  31. package/dist/components/NoSSR.d.ts +16 -0
  32. package/dist/components/NoSSR.js +16 -0
  33. package/dist/components/PackageInstallationTabs.cjs +64 -0
  34. package/dist/components/PackageInstallationTabs.d.cts +8 -0
  35. package/dist/components/PackageInstallationTabs.d.ts +8 -0
  36. package/dist/components/PackageInstallationTabs.js +40 -0
  37. package/dist/components/StarryBackground.cjs +162 -0
  38. package/dist/components/StarryBackground.d.cts +5 -0
  39. package/dist/components/StarryBackground.d.ts +5 -0
  40. package/dist/components/StarryBackground.js +142 -0
  41. package/dist/components/StyledLink.cjs +44 -0
  42. package/dist/components/StyledLink.d.cts +9 -0
  43. package/dist/components/StyledLink.d.ts +9 -0
  44. package/dist/components/StyledLink.js +20 -0
  45. package/dist/components/ThemeSwitcher.cjs +96 -0
  46. package/dist/components/ThemeSwitcher.d.cts +9 -0
  47. package/dist/components/ThemeSwitcher.d.ts +9 -0
  48. package/dist/components/ThemeSwitcher.js +72 -0
  49. package/dist/components/VideoPlayer.cjs +103 -0
  50. package/dist/components/VideoPlayer.d.cts +34 -0
  51. package/dist/components/VideoPlayer.d.ts +34 -0
  52. package/dist/components/VideoPlayer.js +79 -0
  53. package/dist/index.cjs +68 -2
  54. package/dist/index.css +3 -3
  55. package/dist/index.d.cts +15 -139
  56. package/dist/index.d.ts +15 -139
  57. package/dist/index.js +19 -2
  58. package/dist/utils.cjs +52 -0
  59. package/dist/utils.d.cts +16 -0
  60. package/dist/utils.d.ts +16 -0
  61. package/dist/utils.js +27 -0
  62. package/package.json +11 -10
@@ -0,0 +1,41 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import parse, { domToReact, Element } from "html-react-parser";
3
+ import React from "react";
4
+ const LOGO_URL = "https://cdn.jsdelivr.net/gh/TuwaIO/workflows@main/preview/logo_v2.svg";
5
+ async function RemoteLogo({ url = LOGO_URL, className, style, ...props }) {
6
+ let rawSvg;
7
+ try {
8
+ const response = await fetch(url, {
9
+ next: { revalidate: 86400 }
10
+ // Cache for 24 hours
11
+ });
12
+ if (!response.ok) {
13
+ throw new Error(`Failed to fetch SVG: ${response.status}`);
14
+ }
15
+ rawSvg = await response.text();
16
+ } catch (error) {
17
+ console.error("RemoteLogo: Failed to fetch SVG from remote source:", error);
18
+ return /* @__PURE__ */ jsx("svg", { className, style, ...props });
19
+ }
20
+ const cleanSvg = rawSvg.replace(/<\?xml[\s\S]*?\?>/g, "").replace(/<!DOCTYPE[\s\S]*?>/gi, "").replace(/\sxml:space=/g, " xmlSpace=").trim();
21
+ const parsed = parse(cleanSvg, {
22
+ replace(domNode) {
23
+ if (domNode instanceof Element && domNode.name === "svg") {
24
+ const children = domToReact(domNode.children);
25
+ const attribs = { ...domNode.attribs };
26
+ if ("xmlspace" in attribs) {
27
+ attribs.xmlSpace = attribs.xmlspace;
28
+ delete attribs.xmlspace;
29
+ }
30
+ const svgClassName = [className, "remote-logo"].filter(Boolean).join(" ");
31
+ return /* @__PURE__ */ jsx("svg", { ...attribs, className: svgClassName, style, ...props, children });
32
+ }
33
+ }
34
+ });
35
+ const elements = Array.isArray(parsed) ? parsed : [parsed];
36
+ const svgElement = elements.find((el) => React.isValidElement(el) && el.type === "svg");
37
+ return svgElement ? svgElement : /* @__PURE__ */ jsx("svg", { className, style, ...props });
38
+ }
39
+ export {
40
+ RemoteLogo
41
+ };
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var NavBar_exports = {};
20
+ __export(NavBar_exports, {
21
+ Navbar: () => Navbar
22
+ });
23
+ module.exports = __toCommonJS(NavBar_exports);
24
+ var import_jsx_runtime = require("react/jsx-runtime");
25
+ var import_nova_core = require("@tuwaio/nova-core");
26
+ var import_nextra_theme_docs = require("nextra-theme-docs");
27
+ var import_utils = require("../utils");
28
+ function Navbar({ links, logo }) {
29
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_nextra_theme_docs.Navbar, { logo, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "tuwadocs:flex tuwadocs:items-center tuwadocs:gap-3", children: (links ?? import_utils.baseNavLinks).map(({ title, href, image, className }) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
30
+ "a",
31
+ {
32
+ href,
33
+ target: "_blank",
34
+ rel: "noopener noreferrer",
35
+ className: (0, import_nova_core.cn)(
36
+ "tuwadocs:hidden tuwadocs:sm:flex tuwadocs:items-center tuwadocs:gap-1 tuwadocs:px-3 tuwadocs:py-1.5 tuwadocs:text-sm tuwadocs:font-medium tuwadocs:transition-colors tuwadocs:text-[var(--tuwa-text-primary)]",
37
+ className
38
+ ),
39
+ children: [
40
+ image,
41
+ title
42
+ ]
43
+ },
44
+ title
45
+ )) }) });
46
+ }
47
+ // Annotate the CommonJS export names for ESM import in node:
48
+ 0 && (module.exports = {
49
+ Navbar
50
+ });
@@ -0,0 +1,16 @@
1
+ import * as react from 'react';
2
+ import { ReactNode } from 'react';
3
+
4
+ type SocialLink = {
5
+ title: string;
6
+ href: string;
7
+ image: ReactNode;
8
+ className?: string;
9
+ };
10
+ interface NavProps {
11
+ links?: SocialLink[];
12
+ logo?: ReactNode;
13
+ }
14
+ declare function Navbar({ links, logo }: NavProps): react.JSX.Element;
15
+
16
+ export { type NavProps, Navbar, type SocialLink };
@@ -0,0 +1,16 @@
1
+ import * as react from 'react';
2
+ import { ReactNode } from 'react';
3
+
4
+ type SocialLink = {
5
+ title: string;
6
+ href: string;
7
+ image: ReactNode;
8
+ className?: string;
9
+ };
10
+ interface NavProps {
11
+ links?: SocialLink[];
12
+ logo?: ReactNode;
13
+ }
14
+ declare function Navbar({ links, logo }: NavProps): react.JSX.Element;
15
+
16
+ export { type NavProps, Navbar, type SocialLink };
@@ -0,0 +1,26 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { cn } from "@tuwaio/nova-core";
3
+ import { Navbar as NextraNavbar } from "nextra-theme-docs";
4
+ import { baseNavLinks } from "../utils";
5
+ function Navbar({ links, logo }) {
6
+ return /* @__PURE__ */ jsx(NextraNavbar, { logo, children: /* @__PURE__ */ jsx("div", { className: "tuwadocs:flex tuwadocs:items-center tuwadocs:gap-3", children: (links ?? baseNavLinks).map(({ title, href, image, className }) => /* @__PURE__ */ jsxs(
7
+ "a",
8
+ {
9
+ href,
10
+ target: "_blank",
11
+ rel: "noopener noreferrer",
12
+ className: cn(
13
+ "tuwadocs:hidden tuwadocs:sm:flex tuwadocs:items-center tuwadocs:gap-1 tuwadocs:px-3 tuwadocs:py-1.5 tuwadocs:text-sm tuwadocs:font-medium tuwadocs:transition-colors tuwadocs:text-[var(--tuwa-text-primary)]",
14
+ className
15
+ ),
16
+ children: [
17
+ image,
18
+ title
19
+ ]
20
+ },
21
+ title
22
+ )) }) });
23
+ }
24
+ export {
25
+ Navbar
26
+ };
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ "use client";
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+ var NoSSR_exports = {};
21
+ __export(NoSSR_exports, {
22
+ default: () => NoSSR
23
+ });
24
+ module.exports = __toCommonJS(NoSSR_exports);
25
+ var import_jsx_runtime = require("react/jsx-runtime");
26
+ var import_react = require("react");
27
+ function NoSSR({ children }) {
28
+ const [mounted, setMounted] = (0, import_react.useState)(false);
29
+ (0, import_react.useEffect)(() => {
30
+ setMounted(true);
31
+ }, []);
32
+ if (!mounted) {
33
+ return null;
34
+ }
35
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children });
36
+ }
@@ -0,0 +1,16 @@
1
+ import * as react from 'react';
2
+ import { ReactNode } from 'react';
3
+
4
+ /**
5
+ * A wrapper component that prevents its children from rendering on the server (SSR).
6
+ * It waits until the component is mounted on the client before rendering them.
7
+ *
8
+ * @param props - The component props.
9
+ * @param props.children - The children components to render on the client.
10
+ * @returns The children components on the client, or null on the server.
11
+ */
12
+ declare function NoSSR({ children }: {
13
+ children: ReactNode;
14
+ }): react.JSX.Element | null;
15
+
16
+ export { NoSSR as default };
@@ -0,0 +1,16 @@
1
+ import * as react from 'react';
2
+ import { ReactNode } from 'react';
3
+
4
+ /**
5
+ * A wrapper component that prevents its children from rendering on the server (SSR).
6
+ * It waits until the component is mounted on the client before rendering them.
7
+ *
8
+ * @param props - The component props.
9
+ * @param props.children - The children components to render on the client.
10
+ * @returns The children components on the client, or null on the server.
11
+ */
12
+ declare function NoSSR({ children }: {
13
+ children: ReactNode;
14
+ }): react.JSX.Element | null;
15
+
16
+ export { NoSSR as default };
@@ -0,0 +1,16 @@
1
+ "use client";
2
+ import { Fragment, jsx } from "react/jsx-runtime";
3
+ import { useEffect, useState } from "react";
4
+ function NoSSR({ children }) {
5
+ const [mounted, setMounted] = useState(false);
6
+ useEffect(() => {
7
+ setMounted(true);
8
+ }, []);
9
+ if (!mounted) {
10
+ return null;
11
+ }
12
+ return /* @__PURE__ */ jsx(Fragment, { children });
13
+ }
14
+ export {
15
+ NoSSR as default
16
+ };
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ "use client";
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+ var PackageInstallationTabs_exports = {};
21
+ __export(PackageInstallationTabs_exports, {
22
+ PackageInstallationTabs: () => PackageInstallationTabs
23
+ });
24
+ module.exports = __toCommonJS(PackageInstallationTabs_exports);
25
+ var import_jsx_runtime = require("react/jsx-runtime");
26
+ var import_outline = require("@heroicons/react/24/outline");
27
+ var import_components = require("nextra/components");
28
+ var import_CodeBlock = require("./CodeBlock");
29
+ var import_CodeHighlighter = require("./CodeHighlighter");
30
+ const tabsItems = [
31
+ {
32
+ title: "pnpm",
33
+ command: "pnpm add"
34
+ },
35
+ {
36
+ title: "bun",
37
+ command: "bun add"
38
+ },
39
+ {
40
+ title: "npm",
41
+ command: "npm install"
42
+ },
43
+ {
44
+ title: "yarn",
45
+ command: "yarn add"
46
+ }
47
+ ];
48
+ function PackageInstallationTabs({
49
+ packagesList,
50
+ resolvedTheme
51
+ }) {
52
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "tuwadocs:my-4", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.Tabs, { items: tabsItems.map((tab) => tab.title), children: tabsItems.map((tab) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.Tabs.Tab, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_CodeBlock.CodeBlock, { title: "Terminal", titleIcons: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_outline.CommandLineIcon, {}), textToCopy: `${tab.command} ${packagesList}`, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
53
+ import_CodeHighlighter.CodeHighlighter,
54
+ {
55
+ resolvedTheme,
56
+ language: "bash",
57
+ children: `${tab.command} ${packagesList}`
58
+ }
59
+ ) }) }, tab.title)) }) });
60
+ }
61
+ // Annotate the CommonJS export names for ESM import in node:
62
+ 0 && (module.exports = {
63
+ PackageInstallationTabs
64
+ });
@@ -0,0 +1,8 @@
1
+ import * as react from 'react';
2
+ import { CodeHighlighterProps } from './CodeHighlighter.cjs';
3
+
4
+ declare function PackageInstallationTabs({ packagesList, resolvedTheme, }: {
5
+ packagesList: string;
6
+ } & Pick<CodeHighlighterProps, 'resolvedTheme'>): react.JSX.Element;
7
+
8
+ export { PackageInstallationTabs };
@@ -0,0 +1,8 @@
1
+ import * as react from 'react';
2
+ import { CodeHighlighterProps } from './CodeHighlighter.js';
3
+
4
+ declare function PackageInstallationTabs({ packagesList, resolvedTheme, }: {
5
+ packagesList: string;
6
+ } & Pick<CodeHighlighterProps, 'resolvedTheme'>): react.JSX.Element;
7
+
8
+ export { PackageInstallationTabs };
@@ -0,0 +1,40 @@
1
+ "use client";
2
+ import { jsx } from "react/jsx-runtime";
3
+ import { CommandLineIcon } from "@heroicons/react/24/outline";
4
+ import { Tabs } from "nextra/components";
5
+ import { CodeBlock } from "./CodeBlock";
6
+ import { CodeHighlighter } from "./CodeHighlighter";
7
+ const tabsItems = [
8
+ {
9
+ title: "pnpm",
10
+ command: "pnpm add"
11
+ },
12
+ {
13
+ title: "bun",
14
+ command: "bun add"
15
+ },
16
+ {
17
+ title: "npm",
18
+ command: "npm install"
19
+ },
20
+ {
21
+ title: "yarn",
22
+ command: "yarn add"
23
+ }
24
+ ];
25
+ function PackageInstallationTabs({
26
+ packagesList,
27
+ resolvedTheme
28
+ }) {
29
+ return /* @__PURE__ */ jsx("div", { className: "tuwadocs:my-4", children: /* @__PURE__ */ jsx(Tabs, { items: tabsItems.map((tab) => tab.title), children: tabsItems.map((tab) => /* @__PURE__ */ jsx(Tabs.Tab, { children: /* @__PURE__ */ jsx(CodeBlock, { title: "Terminal", titleIcons: /* @__PURE__ */ jsx(CommandLineIcon, {}), textToCopy: `${tab.command} ${packagesList}`, children: /* @__PURE__ */ jsx(
30
+ CodeHighlighter,
31
+ {
32
+ resolvedTheme,
33
+ language: "bash",
34
+ children: `${tab.command} ${packagesList}`
35
+ }
36
+ ) }) }, tab.title)) }) });
37
+ }
38
+ export {
39
+ PackageInstallationTabs
40
+ };
@@ -0,0 +1,162 @@
1
+ "use strict";
2
+ "use client";
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+ var StarryBackground_exports = {};
21
+ __export(StarryBackground_exports, {
22
+ default: () => StarryBackground
23
+ });
24
+ module.exports = __toCommonJS(StarryBackground_exports);
25
+ var import_jsx_runtime = require("react/jsx-runtime");
26
+ var import_react = require("react");
27
+ const NUM_STARS = 100;
28
+ const STAR_RADIUS_MIN = 0.9;
29
+ const STAR_RADIUS_MAX = 2.7;
30
+ const STAR_VELOCITY_FACTOR = 0.3;
31
+ const STAR_INITIAL_OPACITY_MIN = 0.5;
32
+ const STAR_INITIAL_OPACITY_RANGE = 0.5;
33
+ const MOUSE_REPEL_DISTANCE = 150;
34
+ const MOUSE_REPEL_DISTANCE_SQ = MOUSE_REPEL_DISTANCE * MOUSE_REPEL_DISTANCE;
35
+ const MOUSE_REPEL_FORCE = 2;
36
+ const LINE_MAX_DISTANCE = 120;
37
+ const LINE_MAX_DISTANCE_SQ = LINE_MAX_DISTANCE * LINE_MAX_DISTANCE;
38
+ const LINE_WIDTH = 0.75;
39
+ const TWINKLE_SPEED = 1e-3;
40
+ function StarryBackground() {
41
+ const canvasRef = (0, import_react.useRef)(null);
42
+ const mouseRef = (0, import_react.useRef)({ x: 0, y: 0 });
43
+ const starsRef = (0, import_react.useRef)([]);
44
+ const animationIdRef = (0, import_react.useRef)(null);
45
+ (0, import_react.useEffect)(() => {
46
+ const canvas = canvasRef.current;
47
+ if (!canvas) return;
48
+ const ctx = canvas.getContext("2d");
49
+ if (!ctx) return;
50
+ const setCanvasSize = () => {
51
+ canvas.width = window.innerWidth;
52
+ canvas.height = window.innerHeight;
53
+ };
54
+ const createStars = () => {
55
+ const stars = [];
56
+ for (let i = 0; i < NUM_STARS; i++) {
57
+ stars.push({
58
+ x: Math.random() * canvas.width,
59
+ y: Math.random() * canvas.height,
60
+ radius: Math.random() * (STAR_RADIUS_MAX - STAR_RADIUS_MIN) + STAR_RADIUS_MIN,
61
+ vx: (Math.random() - 0.5) * STAR_VELOCITY_FACTOR,
62
+ vy: (Math.random() - 0.5) * STAR_VELOCITY_FACTOR,
63
+ opacity: Math.random() * STAR_INITIAL_OPACITY_RANGE + STAR_INITIAL_OPACITY_MIN
64
+ });
65
+ }
66
+ return stars;
67
+ };
68
+ const handleMouseMove = (e) => {
69
+ mouseRef.current.x = e.clientX;
70
+ mouseRef.current.y = e.clientY;
71
+ };
72
+ const handleResize = () => {
73
+ setCanvasSize();
74
+ starsRef.current = createStars();
75
+ };
76
+ const updateAndDrawScene = (timestamp) => {
77
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
78
+ const stars = starsRef.current;
79
+ const mouse = mouseRef.current;
80
+ const isDark = document.documentElement.classList.contains("dark");
81
+ for (const star of stars) {
82
+ star.x += star.vx;
83
+ star.y += star.vy;
84
+ if (star.x < 0 || star.x > canvas.width) star.vx = -star.vx;
85
+ if (star.y < 0 || star.y > canvas.height) star.vy = -star.vy;
86
+ const dxMouse = mouse.x - star.x;
87
+ const dyMouse = mouse.y - star.y;
88
+ const distMouseSq = dxMouse * dxMouse + dyMouse * dyMouse;
89
+ if (distMouseSq < MOUSE_REPEL_DISTANCE_SQ) {
90
+ const distance = Math.sqrt(distMouseSq);
91
+ const force = (MOUSE_REPEL_DISTANCE - distance) / MOUSE_REPEL_DISTANCE;
92
+ const forceX = dxMouse / distance * force * MOUSE_REPEL_FORCE;
93
+ const forceY = dyMouse / distance * force * MOUSE_REPEL_FORCE;
94
+ star.x -= forceX;
95
+ star.y -= forceY;
96
+ }
97
+ star.opacity = 0.3 + Math.sin(timestamp * TWINKLE_SPEED + star.x) * 0.5 + 0.5;
98
+ const clampedOpacity = Math.min(star.opacity, 1);
99
+ const gradient = ctx.createRadialGradient(star.x, star.y, 0, star.x, star.y, star.radius);
100
+ if (isDark) {
101
+ gradient.addColorStop(0, `rgba(255, 255, 255, ${clampedOpacity})`);
102
+ gradient.addColorStop(0.5, `rgba(147, 197, 253, ${clampedOpacity * 0.6})`);
103
+ gradient.addColorStop(1, "rgba(59, 130, 246, 0)");
104
+ } else {
105
+ gradient.addColorStop(0, `rgba(15, 23, 42, ${clampedOpacity})`);
106
+ gradient.addColorStop(0.5, `rgba(71, 85, 105, ${clampedOpacity * 0.6})`);
107
+ gradient.addColorStop(1, "rgba(148, 163, 184, 0)");
108
+ }
109
+ ctx.beginPath();
110
+ ctx.arc(star.x, star.y, star.radius, 0, Math.PI * 2);
111
+ ctx.fillStyle = gradient;
112
+ ctx.fill();
113
+ }
114
+ ctx.lineWidth = LINE_WIDTH;
115
+ for (let i = 0; i < stars.length; i++) {
116
+ const star1 = stars[i];
117
+ for (let j = i + 1; j < stars.length; j++) {
118
+ const star2 = stars[j];
119
+ const dx = star1.x - star2.x;
120
+ const dy = star1.y - star2.y;
121
+ const distanceSq = dx * dx + dy * dy;
122
+ if (distanceSq < LINE_MAX_DISTANCE_SQ) {
123
+ const opacity = 0.2 * (1 - distanceSq / LINE_MAX_DISTANCE_SQ);
124
+ if (isDark) {
125
+ ctx.strokeStyle = `rgba(147, 197, 253, ${opacity})`;
126
+ } else {
127
+ ctx.strokeStyle = `rgba(71, 85, 105, ${opacity * 1.5})`;
128
+ }
129
+ ctx.beginPath();
130
+ ctx.moveTo(star1.x, star1.y);
131
+ ctx.lineTo(star2.x, star2.y);
132
+ ctx.stroke();
133
+ }
134
+ }
135
+ }
136
+ };
137
+ const animate = () => {
138
+ const timestamp = Date.now();
139
+ updateAndDrawScene(timestamp);
140
+ animationIdRef.current = requestAnimationFrame(animate);
141
+ };
142
+ setCanvasSize();
143
+ starsRef.current = createStars();
144
+ animate();
145
+ window.addEventListener("mousemove", handleMouseMove);
146
+ window.addEventListener("resize", handleResize);
147
+ return () => {
148
+ if (animationIdRef.current) {
149
+ cancelAnimationFrame(animationIdRef.current);
150
+ }
151
+ window.removeEventListener("mousemove", handleMouseMove);
152
+ window.removeEventListener("resize", handleResize);
153
+ };
154
+ }, []);
155
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
156
+ "canvas",
157
+ {
158
+ ref: canvasRef,
159
+ className: "tuwadocs:absolute tuwadocs:inset-0 tuwadocs:w-full tuwadocs:h-full tuwadocs:bg-gradient-to-b tuwadocs:from-slate-200 tuwadocs:to-slate-350 tuwadocs:dark:from-[#0a0e27] tuwadocs:dark:to-[#1a1f3a]"
160
+ }
161
+ );
162
+ }
@@ -0,0 +1,5 @@
1
+ import * as react from 'react';
2
+
3
+ declare function StarryBackground(): react.JSX.Element;
4
+
5
+ export { StarryBackground as default };
@@ -0,0 +1,5 @@
1
+ import * as react from 'react';
2
+
3
+ declare function StarryBackground(): react.JSX.Element;
4
+
5
+ export { StarryBackground as default };