├── .eslintrc.cjs ├── .gitignore ├── .prettierrc.json ├── README.en.md ├── README.md ├── app ├── components │ ├── CopyButton.tsx │ ├── ImageShow.tsx │ ├── LanguageMenu.tsx │ ├── LinkWithLang.tsx │ └── ui │ │ ├── alert.tsx │ │ ├── badge.tsx │ │ ├── button.tsx │ │ ├── dropdown-menu.tsx │ │ └── input.tsx ├── cookies.server.ts ├── entry.client.tsx ├── entry.server.tsx ├── hooks │ └── useDebouncedValue.tsx ├── lib │ ├── color-schema.tsx │ ├── extract.ts │ ├── file.ts │ └── utils.ts ├── locales │ ├── en.json │ ├── locale.ts │ └── zh.json ├── root.tsx ├── routes │ ├── ($lang)._index.tsx │ └── api.userLang.ts ├── sessions.server.ts ├── tailwind.css ├── types.ts └── ui │ └── primitives │ └── utils.tsx ├── components.json ├── functions └── [[path]].ts ├── load-context.ts ├── package.json ├── pnpm-lock.yaml ├── postcss.config.js ├── public ├── _headers ├── _routes.json ├── android-chrome-192x192.png ├── android-chrome-512x512.png ├── apple-touch-icon.png ├── favicon-16x16.png ├── favicon-32x32.png ├── favicon.ico └── remix.ico ├── tailwind.config.ts ├── tsconfig.json ├── vite.config.ts ├── worker-configuration.d.ts └── wrangler.example.toml /.eslintrc.cjs: -------------------------------------------------------------------------------- 1 | /** 2 | * This is intended to be a basic starting point for linting in your app. 3 | * It relies on recommended configs out of the box for simplicity, but you can 4 | * and should modify this configuration to best suit your team's needs. 5 | */ 6 | 7 | /** @type {import('eslint').Linter.Config} */ 8 | module.exports = { 9 | root: true, 10 | parserOptions: { 11 | ecmaVersion: "latest", 12 | sourceType: "module", 13 | ecmaFeatures: { 14 | jsx: true, 15 | }, 16 | }, 17 | env: { 18 | browser: true, 19 | commonjs: true, 20 | es6: true, 21 | }, 22 | ignorePatterns: ["!**/.server", "!**/.client"], 23 | 24 | // Base config 25 | extends: ["eslint:recommended"], 26 | 27 | overrides: [ 28 | // React 29 | { 30 | files: ["**/*.{js,jsx,ts,tsx}"], 31 | plugins: ["react", "jsx-a11y"], 32 | extends: [ 33 | "plugin:react/recommended", 34 | "plugin:react/jsx-runtime", 35 | "plugin:react-hooks/recommended", 36 | "plugin:jsx-a11y/recommended", 37 | ], 38 | settings: { 39 | react: { 40 | version: "detect", 41 | }, 42 | formComponents: ["Form"], 43 | linkComponents: [ 44 | { name: "Link", linkAttribute: "to" }, 45 | { name: "NavLink", linkAttribute: "to" }, 46 | ], 47 | "import/resolver": { 48 | typescript: {}, 49 | }, 50 | }, 51 | }, 52 | 53 | // Typescript 54 | { 55 | files: ["**/*.{ts,tsx}"], 56 | plugins: ["@typescript-eslint", "import"], 57 | parser: "@typescript-eslint/parser", 58 | settings: { 59 | "import/internal-regex": "^~/", 60 | "import/resolver": { 61 | node: { 62 | extensions: [".ts", ".tsx"], 63 | }, 64 | typescript: { 65 | alwaysTryTypes: true, 66 | }, 67 | }, 68 | }, 69 | extends: [ 70 | "plugin:@typescript-eslint/recommended", 71 | "plugin:import/recommended", 72 | "plugin:import/typescript", 73 | ], 74 | }, 75 | 76 | // Node 77 | { 78 | files: [".eslintrc.cjs"], 79 | env: { 80 | node: true, 81 | }, 82 | }, 83 | ], 84 | }; 85 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | 3 | /.cache 4 | /build 5 | .env 6 | .dev.vars 7 | 8 | .wrangler 9 | wrangler.toml -------------------------------------------------------------------------------- /.prettierrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "plugins": ["prettier-plugin-tailwindcss"] 3 | } 4 | -------------------------------------------------------------------------------- /README.en.md: -------------------------------------------------------------------------------- 1 | # Extract.fun - Web Image Extractor 2 | 3 | [中文](./README.md) | English 4 | 5 | A modern web application that helps you extract images from any website using Cloudflare's browser rendering capabilities. Built with Remix and deployed on Cloudflare Pages. 6 | 7 | 🌐 **Live Site**: [https://extract.fun](https://extract.fun) 8 | 9 | ## Features 10 | 11 | - 🖼️ Extract images from any website 12 | - 🚀 Fast and efficient using Cloudflare's edge network 13 | - 🌐 Browser-based rendering for accurate results 14 | - 💻 Modern UI built with React and TailwindCSS 15 | - 🔒 Secure and reliable 16 | 17 | ## Tech Stack 18 | 19 | - [Remix](https://remix.run/) - Full stack web framework 20 | - [Cloudflare Pages](https://pages.cloudflare.com/) - Hosting and deployment 21 | - [Cloudflare Browser Rendering](https://developers.cloudflare.com/browser-rendering/) - Browser rendering 22 | - [React](https://reactjs.org/) - UI framework 23 | - [TailwindCSS](https://tailwindcss.com/) - Styling 24 | - [TypeScript](https://www.typescriptlang.org/) - Type safety 25 | 26 | ## Development 27 | 28 | ### Prerequisites 29 | 30 | - Node.js (Latest LTS version recommended) 31 | - pnpm package manager 32 | - Cloudflare account 33 | - Wrangler CLI 34 | 35 | ### Local Setup 36 | 37 | 1. Clone the repository 38 | ```bash 39 | git clone https://github.com/yourusername/extract 40 | cd extract 41 | ``` 42 | 43 | 2. Install dependencies 44 | ```bash 45 | pnpm install 46 | ``` 47 | 48 | 3. Copy wrangler example config 49 | ```bash 50 | cp wrangler.example.toml wrangler.toml 51 | ``` 52 | 53 | 4. Start the development server 54 | ```bash 55 | pnpm dev 56 | ``` 57 | 58 | ### Deployment 59 | 60 | Deploy to Cloudflare Pages: 61 | 62 | ```bash 63 | pnpm run deploy 64 | ``` 65 | 66 | ## Contributing 67 | 68 | Contributions are welcome! Please feel free to submit a Pull Request. 69 | 70 | ## License 71 | 72 | MIT License - feel free to use this project for your own purposes. 73 | 74 | --- 75 | 76 | Made with ❤️ using Remix and Cloudflare 77 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Extract.fun - 网站图片提取工具 2 | 3 | 中文 | [English](./README.en.md) 4 | 5 | 一个使用 Cloudflare 浏览器渲染功能从任何网站提取图片的现代 Web 应用。基于 Remix 构建并部署在 Cloudflare Pages 上。 6 | 7 | 🌐 **在线地址**: [https://extract.fun](https://extract.fun) 8 | 9 | ## 功能特点 10 | 11 | - 🖼️ 从任意网站提取图片 12 | - 🚀 使用 Cloudflare 边缘网络,快速高效 13 | - 🌐 基于浏览器渲染,确保准确的结果 14 | - 💻 使用 React 和 TailwindCSS 构建的现代界面 15 | - 🔒 安全可靠 16 | 17 | ## 技术栈 18 | 19 | - [Remix](https://remix.run/) - 全栈 Web 框架 20 | - [Cloudflare Pages](https://pages.cloudflare.com/) - 托管和部署 21 | - [Cloudflare Browser Rendering](https://developers.cloudflare.com/browser-rendering/) - 浏览器渲染 22 | - [React](https://reactjs.org/) - UI 框架 23 | - [TailwindCSS](https://tailwindcss.com/) - 样式设计 24 | - [TypeScript](https://www.typescriptlang.org/) - 类型安全 25 | 26 | ## 开发指南 27 | 28 | ### 环境要求 29 | 30 | - Node.js(推荐最新的 LTS 版本) 31 | - pnpm 包管理器 32 | - Cloudflare 账号 33 | - Wrangler CLI 34 | 35 | ### 本地设置 36 | 37 | 1. 克隆仓库 38 | ```bash 39 | git clone https://github.com/yourusername/extract 40 | cd extract 41 | ``` 42 | 43 | 2. 安装依赖 44 | ```bash 45 | pnpm install 46 | ``` 47 | 48 | 3. 复制 wrangler 配置示例 49 | ```bash 50 | cp wrangler.example.toml wrangler.toml 51 | ``` 52 | 53 | 4. 启动开发服务器 54 | ```bash 55 | pnpm dev 56 | ``` 57 | 58 | ### 部署 59 | 60 | 部署到 Cloudflare Pages: 61 | 62 | ```bash 63 | pnpm run deploy 64 | ``` 65 | 66 | ## 贡献 67 | 68 | 欢迎提交 Pull Request 来帮助改进这个项目! 69 | 70 | ## 许可证 71 | 72 | MIT 许可证 - 您可以自由使用这个项目。 73 | 74 | --- 75 | 76 | 使用 Remix 和 Cloudflare 用 ❤️ 构建 77 | -------------------------------------------------------------------------------- /app/components/CopyButton.tsx: -------------------------------------------------------------------------------- 1 | import { ExclamationTriangleIcon } from "@radix-ui/react-icons"; 2 | import { CheckIcon, CopyIcon } from "lucide-react"; 3 | import { useState } from "react"; 4 | import { Button, ButtonProps } from "~/components/ui/button"; 5 | 6 | interface CopyButtonProps extends ButtonProps { 7 | content: string; 8 | deplay?: number; 9 | } 10 | 11 | export type CopyStatus = "idle" | "success" | "error"; 12 | 13 | const copyStatusIcons = { 14 | idle: , 15 | success: , 16 | error: , 17 | }; 18 | 19 | export function CopyButton(props: CopyButtonProps) { 20 | const [status, setStatus] = useState("idle"); 21 | 22 | async function copyToClipboard(content: string) { 23 | try { 24 | await navigator.clipboard.writeText(content); 25 | setStatus("success"); 26 | } catch (error) { 27 | setStatus("error"); 28 | } finally { 29 | setTimeout(() => { 30 | setStatus("idle"); 31 | }, props.deplay || 1000); 32 | } 33 | } 34 | 35 | return ( 36 | 45 | ); 46 | } 47 | -------------------------------------------------------------------------------- /app/components/ImageShow.tsx: -------------------------------------------------------------------------------- 1 | import { DownloadIcon, EyeOffIcon } from "lucide-react"; 2 | import clsx from "clsx"; 3 | import { useState } from "react"; 4 | import { ExtractImageData } from "~/types"; 5 | import { CopyButton } from "~/components/CopyButton"; 6 | import { Button } from "~/components/ui/button"; 7 | import { downloadImage, readablizeBytes } from "~/lib/file"; 8 | import { Badge } from "~/components/ui/badge"; 9 | 10 | export function ImageShow({ 11 | src, 12 | size, 13 | mimeType, 14 | width, 15 | height, 16 | decoded, 17 | previewNotAvailable, 18 | }: ExtractImageData & { 19 | previewNotAvailable: string; 20 | }) { 21 | const [notAvailable, setNotAvailable] = useState(!decoded); 22 | 23 | let ext = mimeType.split("/")[1]; 24 | if (ext === "svg+xml") { 25 | ext = "svg"; 26 | } 27 | let name = src.split("/").pop() || "image"; 28 | 29 | const img = new Image(); 30 | img.src = src; 31 | img.onerror = () => { 32 | setNotAvailable(true); 33 | }; 34 | 35 | return ( 36 |
37 |
38 | 42 | {width} x {height} 43 | 44 | {notAvailable ? ( 45 |
46 | 47 | {previewNotAvailable} 48 |
49 | ) : ( 50 | 54 | )} 55 |
56 | 57 | {name.length > 20 ? name.slice(0, 20) + "..." : name} 58 | 59 |
60 | 70 | {ext} 71 | 72 | 73 | {readablizeBytes(size)} 74 | 75 |
76 | 77 | 80 |
81 |
82 | ); 83 | } 84 | -------------------------------------------------------------------------------- /app/components/LanguageMenu.tsx: -------------------------------------------------------------------------------- 1 | import { LanguagesIcon, LoaderIcon } from "lucide-react"; 2 | import { useFetcher, useNavigation, useParams } from "@remix-run/react"; 3 | import { 4 | DropdownMenu, 5 | DropdownMenuContent, 6 | DropdownMenuTrigger, 7 | DropdownMenuCheckboxItem, 8 | } from "~/components/ui/dropdown-menu"; 9 | import { Button } from "~/components/ui/button"; 10 | import { useDebouncedValue } from "~/hooks/useDebouncedValue"; 11 | 12 | export function LanguageMenu() { 13 | const params = useParams(); 14 | const lang = params.lang || "en"; 15 | const fetcher = useFetcher({ key: "userLang" }); 16 | 17 | const navigation = useNavigation(); 18 | let isLoading = 19 | navigation.state === "loading" || navigation.formAction === "/api/userLang"; 20 | 21 | function setLang(lang: string) { 22 | fetcher.submit( 23 | { 24 | lang, 25 | }, 26 | { 27 | action: "/api/userLang", 28 | method: "POST", 29 | }, 30 | ); 31 | } 32 | 33 | return ( 34 | 35 | 36 | 47 | 48 | 49 | setLang("en")} 51 | checked={lang === "en"} 52 | > 53 | English 54 | 55 | setLang("zh")} 57 | checked={lang === "zh"} 58 | > 59 | 简体中文 60 | 61 | 62 | 63 | ); 64 | } 65 | -------------------------------------------------------------------------------- /app/components/LinkWithLang.tsx: -------------------------------------------------------------------------------- 1 | import { LinkProps, Link } from "@remix-run/react"; 2 | 3 | interface LinkWithLangProps extends LinkProps { 4 | lang?: string; 5 | } 6 | 7 | export default function LinkWithLang(props: LinkWithLangProps) { 8 | let { lang, to } = props; 9 | switch (lang) { 10 | case "zh": 11 | to = `/zh${to}`; 12 | if (to.endsWith("/")) { 13 | to = to.slice(0, -1); 14 | } 15 | break; 16 | } 17 | return ; 18 | } 19 | -------------------------------------------------------------------------------- /app/components/ui/alert.tsx: -------------------------------------------------------------------------------- 1 | import * as React from "react"; 2 | import { cva, type VariantProps } from "class-variance-authority"; 3 | 4 | import { cn } from "~/lib/utils"; 5 | 6 | const alertVariants = cva( 7 | "relative w-full rounded-lg border px-4 py-3 text-sm [&>svg+div]:translate-y-[-3px] [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:text-foreground [&>svg~*]:pl-7", 8 | { 9 | variants: { 10 | variant: { 11 | default: "bg-background text-foreground", 12 | destructive: 13 | "border-destructive/50 text-destructive dark:border-destructive [&>svg]:text-destructive", 14 | }, 15 | }, 16 | defaultVariants: { 17 | variant: "default", 18 | }, 19 | }, 20 | ); 21 | 22 | const Alert = React.forwardRef< 23 | HTMLDivElement, 24 | React.HTMLAttributes & VariantProps 25 | >(({ className, variant, ...props }, ref) => ( 26 |
32 | )); 33 | Alert.displayName = "Alert"; 34 | 35 | const AlertTitle = React.forwardRef< 36 | HTMLParagraphElement, 37 | React.HTMLAttributes 38 | >(({ className, ...props }, ref) => ( 39 |
44 | )); 45 | AlertTitle.displayName = "AlertTitle"; 46 | 47 | const AlertDescription = React.forwardRef< 48 | HTMLParagraphElement, 49 | React.HTMLAttributes 50 | >(({ className, ...props }, ref) => ( 51 |
56 | )); 57 | AlertDescription.displayName = "AlertDescription"; 58 | 59 | export { Alert, AlertTitle, AlertDescription }; 60 | -------------------------------------------------------------------------------- /app/components/ui/badge.tsx: -------------------------------------------------------------------------------- 1 | import * as React from "react"; 2 | import { cva, type VariantProps } from "class-variance-authority"; 3 | 4 | import { cn } from "~/lib/utils"; 5 | 6 | const badgeVariants = cva( 7 | "inline-flex items-center rounded-md border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2", 8 | { 9 | variants: { 10 | variant: { 11 | default: 12 | "border-transparent bg-primary text-primary-foreground shadow hover:bg-primary/80", 13 | secondary: 14 | "border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80", 15 | destructive: 16 | "border-transparent bg-destructive text-destructive-foreground shadow hover:bg-destructive/80", 17 | outline: "text-foreground", 18 | }, 19 | }, 20 | defaultVariants: { 21 | variant: "default", 22 | }, 23 | }, 24 | ); 25 | 26 | export interface BadgeProps 27 | extends React.HTMLAttributes, 28 | VariantProps {} 29 | 30 | function Badge({ className, variant, ...props }: BadgeProps) { 31 | return ( 32 |
33 | ); 34 | } 35 | 36 | export { Badge, badgeVariants }; 37 | -------------------------------------------------------------------------------- /app/components/ui/button.tsx: -------------------------------------------------------------------------------- 1 | import * as React from "react"; 2 | import { Slot } from "@radix-ui/react-slot"; 3 | import { cva, type VariantProps } from "class-variance-authority"; 4 | 5 | import { cn } from "~/lib/utils"; 6 | 7 | const buttonVariants = cva( 8 | "inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50", 9 | { 10 | variants: { 11 | variant: { 12 | default: 13 | "bg-primary text-primary-foreground shadow hover:bg-primary/90", 14 | destructive: 15 | "bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90", 16 | outline: 17 | "border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground", 18 | secondary: 19 | "bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80", 20 | ghost: "hover:bg-accent hover:text-accent-foreground", 21 | link: "text-primary underline-offset-4 hover:underline", 22 | }, 23 | size: { 24 | default: "h-9 px-4 py-2", 25 | sm: "h-8 rounded-md px-3 text-xs", 26 | lg: "h-10 rounded-md px-8", 27 | icon: "h-9 w-9", 28 | }, 29 | }, 30 | defaultVariants: { 31 | variant: "default", 32 | size: "default", 33 | }, 34 | }, 35 | ); 36 | 37 | export interface ButtonProps 38 | extends React.ButtonHTMLAttributes, 39 | VariantProps { 40 | asChild?: boolean; 41 | } 42 | 43 | const Button = React.forwardRef( 44 | ({ className, variant, size, asChild = false, ...props }, ref) => { 45 | const Comp = asChild ? Slot : "button"; 46 | return ( 47 | 52 | ); 53 | }, 54 | ); 55 | Button.displayName = "Button"; 56 | 57 | export { Button, buttonVariants }; 58 | -------------------------------------------------------------------------------- /app/components/ui/dropdown-menu.tsx: -------------------------------------------------------------------------------- 1 | import * as React from "react"; 2 | import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu"; 3 | import { 4 | CheckIcon, 5 | ChevronRightIcon, 6 | DotFilledIcon, 7 | } from "@radix-ui/react-icons"; 8 | 9 | import { cn } from "~/lib/utils"; 10 | 11 | const DropdownMenu = DropdownMenuPrimitive.Root; 12 | 13 | const DropdownMenuTrigger = DropdownMenuPrimitive.Trigger; 14 | 15 | const DropdownMenuGroup = DropdownMenuPrimitive.Group; 16 | 17 | const DropdownMenuPortal = DropdownMenuPrimitive.Portal; 18 | 19 | const DropdownMenuSub = DropdownMenuPrimitive.Sub; 20 | 21 | const DropdownMenuRadioGroup = DropdownMenuPrimitive.RadioGroup; 22 | 23 | const DropdownMenuSubTrigger = React.forwardRef< 24 | React.ElementRef, 25 | React.ComponentPropsWithoutRef & { 26 | inset?: boolean; 27 | } 28 | >(({ className, inset, children, ...props }, ref) => ( 29 | 38 | {children} 39 | 40 | 41 | )); 42 | DropdownMenuSubTrigger.displayName = 43 | DropdownMenuPrimitive.SubTrigger.displayName; 44 | 45 | const DropdownMenuSubContent = React.forwardRef< 46 | React.ElementRef, 47 | React.ComponentPropsWithoutRef 48 | >(({ className, ...props }, ref) => ( 49 | 57 | )); 58 | DropdownMenuSubContent.displayName = 59 | DropdownMenuPrimitive.SubContent.displayName; 60 | 61 | const DropdownMenuContent = React.forwardRef< 62 | React.ElementRef, 63 | React.ComponentPropsWithoutRef 64 | >(({ className, sideOffset = 4, ...props }, ref) => ( 65 | 66 | 76 | 77 | )); 78 | DropdownMenuContent.displayName = DropdownMenuPrimitive.Content.displayName; 79 | 80 | const DropdownMenuItem = React.forwardRef< 81 | React.ElementRef, 82 | React.ComponentPropsWithoutRef & { 83 | inset?: boolean; 84 | } 85 | >(({ className, inset, ...props }, ref) => ( 86 | 95 | )); 96 | DropdownMenuItem.displayName = DropdownMenuPrimitive.Item.displayName; 97 | 98 | const DropdownMenuCheckboxItem = React.forwardRef< 99 | React.ElementRef, 100 | React.ComponentPropsWithoutRef 101 | >(({ className, children, checked, ...props }, ref) => ( 102 | 111 | 112 | 113 | 114 | 115 | 116 | {children} 117 | 118 | )); 119 | DropdownMenuCheckboxItem.displayName = 120 | DropdownMenuPrimitive.CheckboxItem.displayName; 121 | 122 | const DropdownMenuRadioItem = React.forwardRef< 123 | React.ElementRef, 124 | React.ComponentPropsWithoutRef 125 | >(({ className, children, ...props }, ref) => ( 126 | 134 | 135 | 136 | 137 | 138 | 139 | {children} 140 | 141 | )); 142 | DropdownMenuRadioItem.displayName = DropdownMenuPrimitive.RadioItem.displayName; 143 | 144 | const DropdownMenuLabel = React.forwardRef< 145 | React.ElementRef, 146 | React.ComponentPropsWithoutRef & { 147 | inset?: boolean; 148 | } 149 | >(({ className, inset, ...props }, ref) => ( 150 | 159 | )); 160 | DropdownMenuLabel.displayName = DropdownMenuPrimitive.Label.displayName; 161 | 162 | const DropdownMenuSeparator = React.forwardRef< 163 | React.ElementRef, 164 | React.ComponentPropsWithoutRef 165 | >(({ className, ...props }, ref) => ( 166 | 171 | )); 172 | DropdownMenuSeparator.displayName = DropdownMenuPrimitive.Separator.displayName; 173 | 174 | const DropdownMenuShortcut = ({ 175 | className, 176 | ...props 177 | }: React.HTMLAttributes) => { 178 | return ( 179 | 183 | ); 184 | }; 185 | DropdownMenuShortcut.displayName = "DropdownMenuShortcut"; 186 | 187 | export { 188 | DropdownMenu, 189 | DropdownMenuTrigger, 190 | DropdownMenuContent, 191 | DropdownMenuItem, 192 | DropdownMenuCheckboxItem, 193 | DropdownMenuRadioItem, 194 | DropdownMenuLabel, 195 | DropdownMenuSeparator, 196 | DropdownMenuShortcut, 197 | DropdownMenuGroup, 198 | DropdownMenuPortal, 199 | DropdownMenuSub, 200 | DropdownMenuSubContent, 201 | DropdownMenuSubTrigger, 202 | DropdownMenuRadioGroup, 203 | }; 204 | -------------------------------------------------------------------------------- /app/components/ui/input.tsx: -------------------------------------------------------------------------------- 1 | import * as React from "react"; 2 | 3 | import { cn } from "~/lib/utils"; 4 | 5 | export interface InputProps 6 | extends React.InputHTMLAttributes {} 7 | 8 | const Input = React.forwardRef( 9 | ({ className, type, ...props }, ref) => { 10 | return ( 11 | 20 | ); 21 | }, 22 | ); 23 | Input.displayName = "Input"; 24 | 25 | export { Input }; 26 | -------------------------------------------------------------------------------- /app/cookies.server.ts: -------------------------------------------------------------------------------- 1 | import { createCookie } from "@remix-run/cloudflare"; 2 | 3 | export const userPrefs = createCookie("user-prefs", { 4 | maxAge: 604_800, 5 | }); 6 | 7 | export const userLang = createCookie("user-lang", { 8 | maxAge: 604_800, 9 | }); 10 | -------------------------------------------------------------------------------- /app/entry.client.tsx: -------------------------------------------------------------------------------- 1 | /** 2 | * By default, Remix will handle hydrating your app on the client for you. 3 | * You are free to delete this file if you'd like to, but if you ever want it revealed again, you can run `npx remix reveal` ✨ 4 | * For more information, see https://remix.run/file-conventions/entry.client 5 | */ 6 | 7 | import { RemixBrowser } from "@remix-run/react"; 8 | import { startTransition, StrictMode } from "react"; 9 | import { hydrateRoot } from "react-dom/client"; 10 | 11 | startTransition(() => { 12 | hydrateRoot( 13 | document, 14 | 15 | 16 | , 17 | ); 18 | }); 19 | -------------------------------------------------------------------------------- /app/entry.server.tsx: -------------------------------------------------------------------------------- 1 | /** 2 | * By default, Remix will handle generating the HTTP Response for you. 3 | * You are free to delete this file if you'd like to, but if you ever want it revealed again, you can run `npx remix reveal` ✨ 4 | * For more information, see https://remix.run/file-conventions/entry.server 5 | */ 6 | 7 | import type { AppLoadContext, EntryContext } from "@remix-run/cloudflare"; 8 | import { RemixServer } from "@remix-run/react"; 9 | import { isbot } from "isbot"; 10 | import { renderToReadableStream } from "react-dom/server"; 11 | 12 | export default async function handleRequest( 13 | request: Request, 14 | responseStatusCode: number, 15 | responseHeaders: Headers, 16 | remixContext: EntryContext, 17 | // This is ignored so we can keep it in the template for visibility. Feel 18 | // free to delete this parameter in your app if you're not using it! 19 | // eslint-disable-next-line @typescript-eslint/no-unused-vars 20 | loadContext: AppLoadContext, 21 | ) { 22 | const body = await renderToReadableStream( 23 | , 24 | { 25 | signal: request.signal, 26 | onError(error: unknown) { 27 | // Log streaming rendering errors from inside the shell 28 | console.error(error); 29 | responseStatusCode = 500; 30 | }, 31 | }, 32 | ); 33 | 34 | if (isbot(request.headers.get("user-agent") || "")) { 35 | await body.allReady; 36 | } 37 | 38 | responseHeaders.set("Content-Type", "text/html"); 39 | return new Response(body, { 40 | headers: responseHeaders, 41 | status: responseStatusCode, 42 | }); 43 | } 44 | -------------------------------------------------------------------------------- /app/hooks/useDebouncedValue.tsx: -------------------------------------------------------------------------------- 1 | import { useEffect, useState } from "react"; 2 | 3 | // Define a generic type parameter T 4 | export const useDebouncedValue = (inputValue: T, delay: number): T => { 5 | const [debouncedValue, setDebouncedValue] = useState(inputValue); 6 | 7 | useEffect(() => { 8 | const handler = setTimeout(() => { 9 | setDebouncedValue(inputValue); 10 | }, delay); 11 | 12 | return () => { 13 | clearTimeout(handler); 14 | }; 15 | }, [inputValue, delay]); 16 | 17 | return debouncedValue; 18 | }; 19 | -------------------------------------------------------------------------------- /app/lib/color-schema.tsx: -------------------------------------------------------------------------------- 1 | import { useMemo } from "react"; 2 | import { useNavigation, useRouteLoaderData } from "@remix-run/react"; 3 | import type { loader as rootLoader } from "~/root"; 4 | import { useLayoutEffect } from "~/ui/primitives/utils"; 5 | 6 | export type ColorScheme = "dark" | "light" | "system"; 7 | 8 | export function useColorScheme(): ColorScheme { 9 | let rootLoaderData = useRouteLoaderData("root"); 10 | let rootColorScheme = rootLoaderData?.colorScheme ?? "system"; 11 | 12 | let { formData } = useNavigation(); 13 | let optimisticColorScheme = formData?.has("colorScheme") 14 | ? (formData.get("colorScheme") as ColorScheme) 15 | : null; 16 | return optimisticColorScheme || rootColorScheme; 17 | } 18 | 19 | function syncColorScheme(media: MediaQueryList | MediaQueryListEvent) { 20 | if (media.matches) { 21 | document.documentElement.classList.add("dark"); 22 | } else { 23 | document.documentElement.classList.remove("dark"); 24 | } 25 | } 26 | 27 | function ColorSchemeScriptImpl() { 28 | let colorScheme = useColorScheme(); 29 | // This script automatically adds the dark class to the document element if 30 | // colorScheme is "system" and prefers-color-scheme: dark is true. 31 | let script = useMemo( 32 | () => ` 33 | let colorScheme = ${JSON.stringify(colorScheme)}; 34 | if (colorScheme === "system") { 35 | let media = window.matchMedia("(prefers-color-scheme: dark)") 36 | if (media.matches) document.documentElement.classList.add("dark"); 37 | } 38 | `, 39 | [], // eslint-disable-line -- we don't want this script to ever change 40 | ); 41 | 42 | // Set 43 | useLayoutEffect(() => { 44 | switch (colorScheme) { 45 | case "light": 46 | document.documentElement.classList.remove("dark"); 47 | break; 48 | case "dark": 49 | document.documentElement.classList.add("dark"); 50 | break; 51 | case "system": 52 | let media = window.matchMedia("(prefers-color-scheme: dark)"); 53 | syncColorScheme(media); 54 | media.addEventListener("change", syncColorScheme); 55 | return () => media.removeEventListener("change", syncColorScheme); 56 | default: 57 | console.error("Impossible color scheme state:", colorScheme); 58 | } 59 | }, [colorScheme]); 60 | 61 | // always sync the color scheme if "system" is used 62 | // this accounts for the docs pages adding some classnames to documentElement in root 63 | useLayoutEffect(() => { 64 | if (colorScheme === "system") { 65 | let media = window.matchMedia("(prefers-color-scheme: dark)"); 66 | syncColorScheme(media); 67 | } 68 | }); 69 | 70 | return