diff --git a/.gitignore b/.gitignore index ef00a112..92ae9621 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ _fresh/ tmp/ vendor/ +node_modules/ diff --git a/.vscode/import_map.json b/.vscode/import_map.json index 328391a2..7d586475 100644 --- a/.vscode/import_map.json +++ b/.vscode/import_map.json @@ -17,6 +17,8 @@ "$marked-mangle": "https://esm.sh/marked-mangle@1.0.1", "$fresh-testing-library": "https://deno.land/x/fresh_testing_library@0.11.1/mod.ts", "$fresh-testing-library/": "https://deno.land/x/fresh_testing_library@0.11.1/", - "tailwindcss": "npm:tailwindcss@3.3.5" + "tailwindcss": "npm:tailwindcss@3.3.5", + "tailwindcss/": "npm:/tailwindcss@3.3.5/", + "tailwindcss/plugin": "npm:/tailwindcss@3.3.5/plugin.js" } } diff --git a/plugins/tailwind.ts b/plugins/tailwind.ts index b800c221..2ab3657a 100644 --- a/plugins/tailwind.ts +++ b/plugins/tailwind.ts @@ -5,60 +5,65 @@ import cssnano from "npm:cssnano@6.0.1"; import * as path from "https://deno.land/std@0.207.0/path/mod.ts"; import { walk } from "https://deno.land/std@0.207.0/fs/walk.ts"; +const CONFIG_EXTENSIONS = ["ts", "js", "mjs"]; + +async function findTailwindConfigFile(directory: string): Promise { + let dir = directory; + while (true) { + for (let i = 0; i < CONFIG_EXTENSIONS.length; i++) { + const ext = CONFIG_EXTENSIONS[i]; + const filePath = path.join(dir, `tailwind.config.${ext}`); + try { + const stat = await Deno.stat(filePath); + if (stat.isFile) { + return filePath; + } + } catch (err) { + if (!(err instanceof Deno.errors.NotFound)) { + throw err; + } + } + } + + const parent = path.dirname(dir); + if (parent === dir) { + throw new Error( + `Could not find a tailwind config file in the current directory or any parent directory.`, + ); + } + + dir = parent; + } +} + async function initTailwind( config: ResolvedFreshConfig, ): Promise { const root = path.dirname(config.staticDir); - let tailwindConfig: Config | null = null; + const configPath = await findTailwindConfigFile(root); + console.log({ configPath, cwd: Deno.cwd() }); + const url = path.toFileUrl(configPath).href; + const tailwindConfig = (await import(url)).default as Config; - const configFilePaths = [ - path.join(Deno.cwd(), "tailwind.config.ts"), - path.join(Deno.cwd(), "tailwind.config.js"), - path.join(Deno.cwd(), "tailwind.config.mjs"), - path.join(root, "tailwind.config.ts"), - path.join(root, "tailwind.config.js"), - path.join(root, "tailwind.config.mjs"), - ]; - for (const configFile of configFilePaths) { - let importedConfig: Config | null = null; - try { - const url = path.toFileUrl(configFile).href; - importedConfig = (await import(url)).default as Config; - } catch (_err) { - // ignore - } + if (!Array.isArray(tailwindConfig.content)) { + throw new Error(`Expected tailwind "content" option to be an array`); + } - if (importedConfig !== null) { - if (!Array.isArray(importedConfig.content)) { - throw new Error(`Expected tailwind "content" option to be an array`); + tailwindConfig.content = tailwindConfig.content.map((pattern) => { + if (typeof pattern === "string") { + const relative = path.relative(Deno.cwd(), path.dirname(configPath)); + + if (!relative.startsWith("..")) { + return path.join(relative, pattern); } - - importedConfig.content = importedConfig.content.map((pattern) => { - if (typeof pattern === "string") { - return path.join( - path.relative(Deno.cwd(), path.dirname(configFile)), - pattern, - ); - } - return pattern; - }); - - tailwindConfig = importedConfig; - - break; } - } + return pattern; + }); - if (tailwindConfig === null) { - throw new Error( - `Could not find tailwind config file. Searched the following locations:\n\n${ - configFilePaths.map((p) => `- ${p}`).join("\n") - }`, - ); - } - - const plugins: postcss.AcceptedPlugin[] = [ + // PostCSS types cause deep recursion + // deno-lint-ignore no-explicit-any + const plugins: any[] = [ tailwindCss(tailwindConfig), ]; diff --git a/tests/test_utils.ts b/tests/test_utils.ts index cf4da271..104f9adf 100644 --- a/tests/test_utils.ts +++ b/tests/test_utils.ts @@ -207,7 +207,6 @@ export async function withPageName( }); try { - await delay(100); const browser = await puppeteer.launch({ args: ["--no-sandbox"] }); try { diff --git a/tests/www/navigate_test.ts b/tests/www/navigate_test.ts index e2852094..7747112a 100644 --- a/tests/www/navigate_test.ts +++ b/tests/www/navigate_test.ts @@ -1,8 +1,10 @@ -import { waitForText, withPageName } from "$fresh/tests/test_utils.ts"; +import { runBuild, waitForText, withPageName } from "../test_utils.ts"; Deno.test("www - docs navigation", async () => { + await runBuild("./www/dev.ts"); await withPageName("./www/main.ts", async (page, address) => { - await page.goto(`${address}`, { waitUntil: "networkidle2" }); + await page.goto(`${address}`); + await page.click(`a[href="/docs"]`); await waitForText(page, "h1", "Introduction"); diff --git a/www/components/Button.tsx b/www/components/Button.tsx index 32414f5e..df97a7f6 100644 --- a/www/components/Button.tsx +++ b/www/components/Button.tsx @@ -7,7 +7,7 @@ export function RoundedButton(props: JSX.HTMLAttributes) { touchAction: "manipulation", }} {...props} - class="p-3 border border-transparent rounded-full text-white bg-green(500 hover:600) focus:(outline-none ring(2 offset-2 green-500)) disabled:(bg-green-200 cursor-default)}" + class="p-3 border border-transparent rounded-full text-white bg-green-500 hover:bg-green-600 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-green-500 disabled:bg-green-200 disabled:cursor-default" /> ); } diff --git a/www/components/DocsSidebar.tsx b/www/components/DocsSidebar.tsx index 1b401a80..39e99b12 100644 --- a/www/components/DocsSidebar.tsx +++ b/www/components/DocsSidebar.tsx @@ -54,7 +54,7 @@ export function SidebarCategory(props: {
  • {title} @@ -78,7 +78,7 @@ export function SidebarEntry(props: {
  • {title} diff --git a/www/components/DocsTitle.tsx b/www/components/DocsTitle.tsx index e99ebbc4..d2a8928a 100644 --- a/www/components/DocsTitle.tsx +++ b/www/components/DocsTitle.tsx @@ -3,7 +3,7 @@ export default function DocsTitle() { <> -
    -
    +
    +
    © {new Date().getFullYear()} the Fresh authors
    diff --git a/www/components/NavigationBar.tsx b/www/components/NavigationBar.tsx index 9567dcf5..0c403401 100644 --- a/www/components/NavigationBar.tsx +++ b/www/components/NavigationBar.tsx @@ -31,7 +31,7 @@ export default function NavigationBar( href={item.href} class={`p-1 sm:p-2 ${ isHome ? "text-green-900" : "text-gray-600" - } hover:underline [data-current]:font-bold [data-ancestor]:font-bold`} + } hover:underline data-[current]:font-bold data-[ancestor]:font-bold`} > {item.name}
    diff --git a/www/components/Projects.tsx b/www/components/Projects.tsx index 0b6f19a2..e2470713 100644 --- a/www/components/Projects.tsx +++ b/www/components/Projects.tsx @@ -29,11 +29,11 @@ export default function Projects(props: ProjectProps) { width={600} height={337} style={{ aspectRatio: "16/9" }} - class="object-cover shadow-lg group-hover:(shadow-xl opacity-70) rounded-lg" + class="object-cover shadow-lg group-hover:shadow-xl group-hover:opacity-70 rounded-lg" />
    -
    + {project.github && ( diff --git a/www/components/gallery/Carousel.tsx b/www/components/gallery/Carousel.tsx index 9f334147..4d271db3 100644 --- a/www/components/gallery/Carousel.tsx +++ b/www/components/gallery/Carousel.tsx @@ -1,4 +1,3 @@ -import { tw } from "twind"; import { asset } from "$fresh/runtime.ts"; import { useSignal } from "@preact/signals"; import { useEffect, useRef } from "preact/hooks"; @@ -83,7 +82,7 @@ const Carousel = (props: CarouselProps) => { if (outgoingSlide === idx) return "-translate-x-full z-10"; return "translate-x-full"; }; - return tw`slide absolute top-0 left-0 transition-all ease-in-out duration-700 transform ${TRANSITION_CLASS}`; + return `slide absolute top-0 left-0 transition-all ease-in-out duration-700 transform ${TRANSITION_CLASS}`; }; const nextSlide = () => { diff --git a/www/deno.json b/www/deno.json index 63308c12..998436aa 100644 --- a/www/deno.json +++ b/www/deno.json @@ -1,5 +1,6 @@ { "lock": false, + "nodeModulesDir": true, "tasks": { "start": "deno run -A --watch=static/,routes/,../src dev.ts", "build": "deno run -A dev.ts build", @@ -7,8 +8,6 @@ }, "imports": { "$fresh/": "../", - "twind": "https://esm.sh/twind@0.16.19", - "twind/": "https://esm.sh/twind@0.16.19/", "preact": "https://esm.sh/preact@10.15.1", "preact/": "https://esm.sh/preact@10.15.1/", "@preact/signals": "https://esm.sh/*@preact/signals@1.1.3", @@ -17,7 +16,10 @@ "$ga4": "https://raw.githubusercontent.com/denoland/ga4/main/mod.ts", "$marked-mangle": "https://esm.sh/marked-mangle@1.0.1", "$fresh-testing-library": "https://deno.land/x/fresh_testing_library@0.8.0/mod.ts", - "$fresh-testing-library/": "https://deno.land/x/fresh_testing_library@0.8.0/" + "$fresh-testing-library/": "https://deno.land/x/fresh_testing_library@0.8.0/", + "tailwindcss": "npm:tailwindcss@3.3.5", + "tailwindcss/": "npm:/tailwindcss@3.3.5/", + "tailwindcss/plugin": "npm:/tailwindcss@3.3.5/plugin.js" }, "compilerOptions": { "jsx": "react-jsx", diff --git a/www/fresh.config.ts b/www/fresh.config.ts index 67aa3598..9e40362a 100644 --- a/www/fresh.config.ts +++ b/www/fresh.config.ts @@ -1,10 +1,9 @@ -import twindPlugin from "$fresh/plugins/twind.ts"; -import twindConfig from "./twind.config.ts"; import { defineConfig } from "$fresh/server.ts"; +import tailwind from "$fresh/plugins/tailwind.ts"; export default defineConfig({ build: { target: "safari12", }, - plugins: [twindPlugin(twindConfig)], + plugins: [tailwind()], }); diff --git a/www/fresh.gen.ts b/www/fresh.gen.ts index b973a01b..d2c34ad6 100644 --- a/www/fresh.gen.ts +++ b/www/fresh.gen.ts @@ -4,6 +4,7 @@ import * as $_404 from "./routes/_404.tsx"; import * as $_500 from "./routes/_500.tsx"; +import * as $_app from "./routes/_app.tsx"; import * as $_middleware from "./routes/_middleware.ts"; import * as $components from "./routes/components.tsx"; import * as $docs_slug_ from "./routes/docs/[...slug].tsx"; @@ -24,6 +25,7 @@ const manifest = { routes: { "./routes/_404.tsx": $_404, "./routes/_500.tsx": $_500, + "./routes/_app.tsx": $_app, "./routes/_middleware.ts": $_middleware, "./routes/components.tsx": $components, "./routes/docs/[...slug].tsx": $docs_slug_, diff --git a/www/islands/CopyArea.tsx b/www/islands/CopyArea.tsx index e1cf04f5..c2f28c20 100644 --- a/www/islands/CopyArea.tsx +++ b/www/islands/CopyArea.tsx @@ -31,14 +31,14 @@ export default function CopyArea(props: { code: string }) { }, [copied.value]); return ( -
    +
             {props.code}
           
    diff --git a/www/islands/LemonDrop.tsx b/www/islands/LemonDrop.tsx index 1aae7c0d..456f0ea7 100644 --- a/www/islands/LemonDrop.tsx +++ b/www/islands/LemonDrop.tsx @@ -99,7 +99,7 @@ function LemonDrop() { viewBox="0 0 100 300" fill="none" xmlns="http://www.w3.org/2000/svg" - class="mt-36" + class="mt-32" role="img" aria-label="Fresh logo" > diff --git a/www/routes/_404.tsx b/www/routes/_404.tsx index addce283..596c5550 100644 --- a/www/routes/_404.tsx +++ b/www/routes/_404.tsx @@ -10,11 +10,11 @@ export function ServerCodePage(
    -

    +

    {props.serverCode}

    -

    +

    {props.codeDescription}

    diff --git a/www/routes/_app.tsx b/www/routes/_app.tsx new file mode 100644 index 00000000..a06e3770 --- /dev/null +++ b/www/routes/_app.tsx @@ -0,0 +1,17 @@ +import { AppProps } from "$fresh/server.ts"; + +export default function App({ Component }: AppProps) { + return ( + + + + + My Fresh app + + + + + + + ); +} diff --git a/www/routes/components.tsx b/www/routes/components.tsx index 4037a995..8ec394d8 100644 --- a/www/routes/components.tsx +++ b/www/routes/components.tsx @@ -57,8 +57,8 @@ export default function Home(props: PageProps) {
    -
    -

    +
    +

    Fresh Components

    @@ -71,7 +71,7 @@ export default function Home(props: PageProps) {

    @@ -80,7 +80,7 @@ export default function Home(props: PageProps) {

    Charts

    diff --git a/www/routes/docs/[...slug].tsx b/www/routes/docs/[...slug].tsx index 5e61e368..8d1e70c6 100644 --- a/www/routes/docs/[...slug].tsx +++ b/www/routes/docs/[...slug].tsx @@ -190,7 +190,7 @@ function MobileSidebar(props: { page: Page }) { class="absolute inset-0 bg-gray-600 opacity-75" for="docs_sidebar" /> -
    +
    -

    +

    {props.page.title}

    +
    {prev && ( {"←"} Previous diff --git a/www/routes/index.tsx b/www/routes/index.tsx index d76c260b..5d6ed97b 100644 --- a/www/routes/index.tsx +++ b/www/routes/index.tsx @@ -76,7 +76,7 @@ export default function MainPage(props: PageProps) { function HelloBar() { return ( Fresh v1.5 has been released with Partials,{" "} @@ -151,11 +151,11 @@ function Features() { function Intro(props: { origin: string }) { return ( -
    +
    -

    +

    The next-gen web framework.

    @@ -166,7 +166,7 @@ function Intro(props: { origin: string }) {
    Get started @@ -198,10 +198,10 @@ function Intro(props: { origin: string }) { function Example() { return ( -
    +
    -

    +

    Interactive islands @@ -223,8 +223,8 @@ function Example() { function Showcase() { return ( -
    -

    +
    +

    Showcase @@ -245,18 +245,18 @@ function Showcase() { function StartJourney() { return ( -
    -

    +
    +

    Start your Fresh journey

    -

    +

    Jump right in and build your website with Fresh. Learn everything you need to know in seconds.

    Get started diff --git a/www/routes/showcase.tsx b/www/routes/showcase.tsx index d6c5bd26..bae94980 100644 --- a/www/routes/showcase.tsx +++ b/www/routes/showcase.tsx @@ -28,8 +28,8 @@ export default function ShowcasePage(props: PageProps) {
    -
    -

    +
    +

    Badge

    @@ -77,8 +77,8 @@ export default function ShowcasePage(props: PageProps) { function Showcase({ items }: { items: Project[] }) { return ( -
    -

    +
    +

    Showcase

    diff --git a/www/static/styles.css b/www/static/styles.css new file mode 100644 index 00000000..b5c61c95 --- /dev/null +++ b/www/static/styles.css @@ -0,0 +1,3 @@ +@tailwind base; +@tailwind components; +@tailwind utilities; diff --git a/www/tailwind.config.ts b/www/tailwind.config.ts new file mode 100644 index 00000000..c993fe51 --- /dev/null +++ b/www/tailwind.config.ts @@ -0,0 +1,21 @@ +import { type Config } from "tailwindcss"; +import plugin from "tailwindcss/plugin"; + +export default { + content: [ + "{routes,islands,components}/**/*.{ts,tsx}", + ], + plugins: [ + plugin((api) => { + api.addUtilities({ + ".form-select-bg": { + "background-image": + `url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='none'%3e%3cpath d='M7 7l3-3 3 3m0 6l-3 3-3-3' stroke='%239fa6b2' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3e%3c/svg%3e")`, + "background-position": "right 0.5rem center", + "background-size": "1.5em 1.5em", + "background-repeat": "no-repeat", + }, + }); + }), + ], +} as Config; diff --git a/www/twind.config.ts b/www/twind.config.ts deleted file mode 100644 index bb4387e2..00000000 --- a/www/twind.config.ts +++ /dev/null @@ -1,52 +0,0 @@ -import { Options } from "$fresh/plugins/twind.ts"; -import * as colors from "twind/colors"; - -export default { - selfURL: import.meta.url, - theme: { - colors: { - blue: colors.blue, - black: colors.black, - gray: colors.gray, - green: colors.green, - white: colors.white, - yellow: colors.yellow, - transparent: "transparent", - }, - }, - plugins: { - // Basic workaround for old twind version not supporting - // the `basis-*` keyword - basis: (parts) => { - let value; - const arr = parts[0].split("/"); - if (arr.length === 2) { - value = `${(+arr[0] / +arr[1]) * 100}%`; - } else if (parts.length === 1) { - value = parts[0]; - } - return { - "flex-basis": value, - }; - }, - "rounded-full": () => { - return { - "border-radius": "9999px", - }; - }, - "form-select-bg": () => { - return { - "background-image": - `url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='none'%3e%3cpath d='M7 7l3-3 3 3m0 6l-3 3-3-3' stroke='%239fa6b2' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3e%3c/svg%3e")`, - "background-position": "right 0.5rem center", - "background-size": "1.5em 1.5em", - "background-repeat": "no-repeat", - }; - }, - "grow": () => { - return { - "flex-grow": "1", - }; - }, - }, -} as Options;