www: refresh home page (#2418)
Overhauls the Fresh homepage with a new design, new demos, and new sections highlighting Fresh's capabilities. --------- Co-authored-by: Marvin Hagemeister <marvin@deno.com>
This commit is contained in:
co-authored by
Marvin Hagemeister
parent
3b68a5d455
commit
e8d1a68b58
@@ -26,17 +26,17 @@ export default function CopyArea(props: { code: string }) {
|
||||
}
|
||||
const timer = setTimeout(() => {
|
||||
copied.value = false;
|
||||
}, 2000);
|
||||
}, 1000);
|
||||
return () => clearTimeout(timer);
|
||||
}, [copied.value]);
|
||||
|
||||
return (
|
||||
<div class="bg-gray-800 rounded text-white flex items-center min-w-0">
|
||||
<pre class="overflow-x-auto flex-1 py-2 px-4">
|
||||
<div class="bg-slate-800 rounded text-green-100 flex items-center min-w-0 overflow-x-auto">
|
||||
<pre class="overflow-x-auto w-full flex-1 px-6 py-4">
|
||||
{props.code}
|
||||
</pre>
|
||||
|
||||
<div class="relative my-2 mr-4">
|
||||
<div class="relative my-2 mr-4 sm:mr-6">
|
||||
<div
|
||||
class={`hidden transition ease-in-out absolute pointer-events-none bg-gray-900 text-white p-2 -top-1/3 left-1/2 transform -translate-x-1/2 -translate-y-full box-border rounded opacity-0 ${
|
||||
copied.value && "block opacity-100"
|
||||
|
||||
+17
-11
@@ -1,7 +1,6 @@
|
||||
import { useSignal } from "@preact/signals";
|
||||
import { IS_BROWSER } from "$fresh/runtime.ts";
|
||||
import { RoundedButton } from "../components/Button.tsx";
|
||||
import * as Icons from "../components/Icons.tsx";
|
||||
import { JSX } from "preact";
|
||||
|
||||
interface CounterProps {
|
||||
start: number;
|
||||
@@ -11,14 +10,11 @@ export default function Counter(props: CounterProps) {
|
||||
const count = useSignal(props.start);
|
||||
|
||||
return (
|
||||
<div
|
||||
class="bg-green-100 p-8 border-8 border-green-300 text-center"
|
||||
style="border-radius: 1rem"
|
||||
>
|
||||
<h3 class="green-300 text-2xl font-bold text-green-700">
|
||||
This area is interactive
|
||||
<div>
|
||||
<h3 class="text-2xl font-bold">
|
||||
Interactive island
|
||||
</h3>
|
||||
<p class="text-gray-600">
|
||||
<p>
|
||||
The server supplied the initial value of 3.
|
||||
</p>
|
||||
<div
|
||||
@@ -28,7 +24,6 @@ export default function Counter(props: CounterProps) {
|
||||
<RoundedButton
|
||||
title="Subtract 1"
|
||||
onClick={() => count.value -= 1}
|
||||
disabled={!IS_BROWSER || count.value <= 0}
|
||||
>
|
||||
<Icons.IconMinus />
|
||||
</RoundedButton>
|
||||
@@ -39,7 +34,6 @@ export default function Counter(props: CounterProps) {
|
||||
<RoundedButton
|
||||
title="Add 1"
|
||||
onClick={() => count.value += 1}
|
||||
disabled={!IS_BROWSER}
|
||||
>
|
||||
<Icons.IconPlus />
|
||||
</RoundedButton>
|
||||
@@ -47,3 +41,15 @@ export default function Counter(props: CounterProps) {
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function RoundedButton(props: JSX.HTMLAttributes<HTMLButtonElement>) {
|
||||
return (
|
||||
<button
|
||||
style={{
|
||||
touchAction: "manipulation",
|
||||
}}
|
||||
{...props}
|
||||
class="p-3 rounded-full border-2 border-current bg-white/20 hover:bg-white/50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-green-500 disabled:bg-green-200 disabled:cursor-default"
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
import { useEffect, useRef } from "preact/hooks";
|
||||
import { useSignal } from "@preact/signals";
|
||||
import { WaveTank } from "../components/WaveTank.ts";
|
||||
|
||||
function easeInCirc(x: number) {
|
||||
return 1 - Math.sqrt(1 - Math.pow(x, 2));
|
||||
}
|
||||
|
||||
const waveTank = new WaveTank();
|
||||
|
||||
function LemonBottom() {
|
||||
const SVG_WIDTH = 100;
|
||||
const counter = useSignal(0);
|
||||
const dropY = useSignal(60);
|
||||
const width = useSignal(SVG_WIDTH);
|
||||
const widthRef = useRef(width.value);
|
||||
const springs = useSignal(waveTank.springs);
|
||||
const requestIdRef = useRef<number>();
|
||||
const grid = SVG_WIDTH / waveTank.waveLength;
|
||||
let lemonTop: SVGElement | null;
|
||||
let lemonTopLeft: number;
|
||||
const points = [
|
||||
[0, 100],
|
||||
[0, 0],
|
||||
...springs.value.map((x, i) => [i * grid, x.p]),
|
||||
[width.value, 0],
|
||||
[width.value, 100],
|
||||
];
|
||||
const springsPath = `${points.map((x) => x.join(",")).join(" ")}`;
|
||||
|
||||
function updateJuice(timestamp: number) {
|
||||
const amp = 40;
|
||||
const x = timestamp / 2000;
|
||||
const saw = x - Math.floor(x);
|
||||
if (saw < 0.6) {
|
||||
counter.value = easeInCirc(saw) * amp;
|
||||
dropY.value = -100;
|
||||
} else {
|
||||
counter.value = easeInCirc(1 - saw) * amp * 0.1;
|
||||
dropY.value = 70 + Math.pow(saw - 0.6, 2) * 10000;
|
||||
}
|
||||
}
|
||||
|
||||
function update(timestamp: number) {
|
||||
updateJuice(timestamp);
|
||||
waveTank.update(waveTank.springs);
|
||||
springs.value = [...waveTank.springs];
|
||||
|
||||
const offset = 500;
|
||||
const saw = (timestamp + offset) / 2000 -
|
||||
Math.floor((timestamp + offset) / 2000);
|
||||
if (saw < 0.01) {
|
||||
drop();
|
||||
}
|
||||
requestIdRef.current = globalThis.requestAnimationFrame(update);
|
||||
}
|
||||
|
||||
function resize() {
|
||||
width.value = document.body.clientWidth;
|
||||
lemonTop = document.querySelector("#lemon-top");
|
||||
lemonTopLeft = lemonTop ? lemonTop.getBoundingClientRect().left + 25 : 50;
|
||||
}
|
||||
|
||||
function drop() {
|
||||
let dropPosition = 50;
|
||||
if (widthRef.current >= 768) {
|
||||
dropPosition = Math.round(100 / widthRef.current * lemonTopLeft);
|
||||
} else {
|
||||
dropPosition = Math.round(
|
||||
((widthRef.current / 2 - 30) / widthRef.current) * 100,
|
||||
);
|
||||
}
|
||||
waveTank.springs[dropPosition].p = -40;
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
widthRef.current = width.value;
|
||||
}, [width.value]);
|
||||
|
||||
useEffect(() => {
|
||||
const mediaQuery = globalThis.matchMedia(
|
||||
"(prefers-reduced-motion: reduce)",
|
||||
);
|
||||
if (mediaQuery.matches) {
|
||||
return;
|
||||
}
|
||||
|
||||
requestIdRef.current = requestAnimationFrame(update);
|
||||
globalThis.addEventListener("resize", resize);
|
||||
resize();
|
||||
|
||||
return () => {
|
||||
globalThis.removeEventListener("resize", resize);
|
||||
if (requestIdRef.current !== undefined) {
|
||||
cancelAnimationFrame(requestIdRef.current);
|
||||
}
|
||||
};
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<svg
|
||||
width="100%"
|
||||
height="100px"
|
||||
viewBox="0 0 100 100"
|
||||
preserveAspectRatio="none"
|
||||
style="margin-top: -60px"
|
||||
>
|
||||
<polygon
|
||||
points={springsPath}
|
||||
fill="white"
|
||||
transform="translate(0, 50)"
|
||||
>
|
||||
</polygon>
|
||||
</svg>
|
||||
);
|
||||
}
|
||||
|
||||
export default LemonBottom;
|
||||
+10
-10
@@ -11,7 +11,7 @@ const waveTank = new WaveTank();
|
||||
function LemonDrop() {
|
||||
const SVG_WIDTH = 100;
|
||||
const counter = useSignal(0);
|
||||
const dropy = useSignal(60);
|
||||
const dropY = useSignal(60);
|
||||
const width = useSignal(SVG_WIDTH);
|
||||
const widthRef = useRef(width.value);
|
||||
const springs = useSignal(waveTank.springs);
|
||||
@@ -37,10 +37,10 @@ function LemonDrop() {
|
||||
const saw = x - Math.floor(x);
|
||||
if (saw < 0.6) {
|
||||
counter.value = easeInCirc(saw) * amp;
|
||||
dropy.value = -100;
|
||||
dropY.value = -100;
|
||||
} else {
|
||||
counter.value = easeInCirc(1 - saw) * amp * 0.1;
|
||||
dropy.value = 70 + Math.pow(saw - 0.6, 2) * 10000;
|
||||
dropY.value = 70 + Math.pow(saw - 0.6, 2) * 10000;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ function LemonDrop() {
|
||||
const dropPosition = Math.round(
|
||||
((widthRef.current / 2 - 30) / widthRef.current) * 100,
|
||||
);
|
||||
waveTank.springs[dropPosition].p = -60;
|
||||
waveTank.springs[dropPosition].p = -40;
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
@@ -96,16 +96,16 @@ function LemonDrop() {
|
||||
return (
|
||||
<>
|
||||
<svg
|
||||
width="100"
|
||||
height="300"
|
||||
viewBox="0 0 100 300"
|
||||
width="120"
|
||||
height="240"
|
||||
viewBox="0 0 100 180"
|
||||
fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
class="mt-32"
|
||||
role="img"
|
||||
aria-label="Fresh logo"
|
||||
class="mt-8"
|
||||
alt="Fresh logo"
|
||||
>
|
||||
<circle cx="18" cy={dropy.value} r="4" fill="white"></circle>
|
||||
<circle cx="18" cy={dropY.value} r="4" fill="white"></circle>
|
||||
<path
|
||||
d="M11.9 96.3v24H7v-24h4.9Zm7.5 10.2v4h-8.8v-4h8.8Zm1-10.2v4h-9.8v-4h9.8ZM23.2 96.3H31c1.6 0 3 .3 4.1.9 1.1.5 2 1.3 2.6 2.4a8 8 0 0 1 1 4c0 1.3-.2 2.4-.6 3.3-.3 1-.8 1.7-1.5 2.3-.7.6-1.4 1-2.3 1.5l-1.5.8h-6.3v-4h4.3a3 3 0 0 0 1.7-.4c.4-.3.7-.7 1-1.2a5 5 0 0 0 .3-2c0-.7-.1-1.3-.3-1.9-.2-.5-.5-1-1-1.2-.3-.3-.9-.5-1.5-.5h-3v20h-4.8v-24Zm11 24-4.4-10.7h5l4.6 10.5v.2h-5.2ZM55.9 116.3v4H45.4v-4h10.5Zm-9-20v24H42v-24H47Zm7.6 9.8v3.8h-9.1v-3.8h9Zm1.4-9.8v4H45.4v-4h10.5ZM69 114c0-.4 0-.8-.2-1.1 0-.4-.2-.7-.5-1l-1-1-1.9-.8-2.6-1.2-2.2-1.5a6.5 6.5 0 0 1-1.7-2 6 6 0 0 1-.5-2.7c0-1 .1-2 .5-2.7a6 6 0 0 1 1.6-2.2c.7-.5 1.5-1 2.4-1.3a9.5 9.5 0 0 1 7.1.5c1.2.6 2 1.5 2.7 2.6.6 1 1 2.4 1 3.8h-5a5 5 0 0 0-.2-1.8c-.2-.5-.5-1-1-1.2-.4-.3-1-.5-1.6-.5-.6 0-1.1.2-1.5.4-.4.2-.7.6-1 1l-.2 1.4c0 .4.1.8.3 1.1l.8.8a21.3 21.3 0 0 0 2.8 1.4l2.9 1.4a9 9 0 0 1 2 1.8c.7.6 1 1.3 1.4 2a7.9 7.9 0 0 1-.1 5.5c-.4.8-.9 1.5-1.5 2.1a7 7 0 0 1-2.5 1.4c-2 .5-1 1.8-3 1.8s-1.3-1.5-3.2-1.8c-1-.3-2-.8-2.7-1.4a6.7 6.7 0 0 1-1.8-2.5c-.4-1-.6-2.2-.6-3.5h4.9c0 .7 0 1.3.2 1.8.1.5.3 1 .6 1.3.3.2.7.5 1.1.6.5.2 1 .2 1.5.2.7 0 1.2 0 1.6-.3.4-.3.6-.6.8-1 .2-.4.3-.9.3-1.4ZM90.5 106v4h-10v-4h10Zm-8.6-9.7v24h-4.8v-24h4.8Zm12.1 0v24h-4.8v-24H94Z"
|
||||
fill="#0A140C"
|
||||
|
||||
@@ -0,0 +1,124 @@
|
||||
import { useEffect, useRef } from "preact/hooks";
|
||||
import { useSignal } from "@preact/signals";
|
||||
import { WaveTank } from "../components/WaveTank.ts";
|
||||
|
||||
function easeInCirc(x: number) {
|
||||
return 1 - Math.sqrt(1 - Math.pow(x, 2));
|
||||
}
|
||||
|
||||
const waveTank = new WaveTank();
|
||||
|
||||
function LemonTop() {
|
||||
const SVG_WIDTH = 100;
|
||||
const counter = useSignal(0);
|
||||
const dropY = useSignal(60);
|
||||
const width = useSignal(SVG_WIDTH);
|
||||
const widthRef = useRef(width.value);
|
||||
const springs = useSignal(waveTank.springs);
|
||||
const requestIdRef = useRef<number>();
|
||||
|
||||
const juice = `M18 ${63 + counter.value} C15 ${63 + counter.value} 16 ${
|
||||
63 + counter.value
|
||||
} 12 61L9 56C2 33 62 -3 80 12C103 27 44 56 29 58C27 58 25 59 24 61C20 ${
|
||||
63 + counter.value
|
||||
} 21 ${63 + counter.value} 18 ${63 + counter.value}Z`;
|
||||
|
||||
function updateJuice(timestamp: number) {
|
||||
const amp = 40;
|
||||
const x = timestamp / 2000;
|
||||
const saw = x - Math.floor(x);
|
||||
if (saw < 0.6) {
|
||||
counter.value = easeInCirc(saw) * amp;
|
||||
dropY.value = -100;
|
||||
} else {
|
||||
counter.value = easeInCirc(1 - saw) * amp * 0.1;
|
||||
dropY.value = 70 + Math.pow(saw - 0.6, 2) * 10000;
|
||||
}
|
||||
}
|
||||
|
||||
function update(timestamp: number) {
|
||||
updateJuice(timestamp);
|
||||
waveTank.update(waveTank.springs);
|
||||
springs.value = [...waveTank.springs];
|
||||
|
||||
const offset = 500;
|
||||
const saw = (timestamp + offset) / 2000 -
|
||||
Math.floor((timestamp + offset) / 2000);
|
||||
if (saw < 0.01) {
|
||||
drop();
|
||||
}
|
||||
requestIdRef.current = globalThis.requestAnimationFrame(update);
|
||||
}
|
||||
|
||||
function resize() {
|
||||
width.value = document.body.clientWidth;
|
||||
}
|
||||
|
||||
function drop() {
|
||||
const dropPosition = Math.round(
|
||||
((widthRef.current / 2 - 30) / widthRef.current) * 100,
|
||||
);
|
||||
waveTank.springs[dropPosition].p = -40;
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
widthRef.current = width.value;
|
||||
}, [width.value]);
|
||||
|
||||
useEffect(() => {
|
||||
const mediaQuery = globalThis.matchMedia(
|
||||
"(prefers-reduced-motion: reduce)",
|
||||
);
|
||||
if (mediaQuery.matches) {
|
||||
return;
|
||||
}
|
||||
|
||||
requestIdRef.current = requestAnimationFrame(update);
|
||||
globalThis.addEventListener("resize", resize);
|
||||
resize();
|
||||
|
||||
return () => {
|
||||
globalThis.removeEventListener("resize", resize);
|
||||
if (requestIdRef.current !== undefined) {
|
||||
cancelAnimationFrame(requestIdRef.current);
|
||||
}
|
||||
};
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<>
|
||||
<svg
|
||||
width="150"
|
||||
height="500"
|
||||
viewBox="0 0 100 300"
|
||||
fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
role="img"
|
||||
class="mt-8 w-full h-auto max-w-32 lg:max-w-36"
|
||||
alt="Fresh logo"
|
||||
id="lemon-top"
|
||||
>
|
||||
<circle cx="18" cy={dropY.value} r="4" fill="#fff"></circle>
|
||||
<path
|
||||
d="M11.9 96.3v24H7v-24h4.9Zm7.5 10.2v4h-8.8v-4h8.8Zm1-10.2v4h-9.8v-4h9.8ZM23.2 96.3H31c1.6 0 3 .3 4.1.9 1.1.5 2 1.3 2.6 2.4a8 8 0 0 1 1 4c0 1.3-.2 2.4-.6 3.3-.3 1-.8 1.7-1.5 2.3-.7.6-1.4 1-2.3 1.5l-1.5.8h-6.3v-4h4.3a3 3 0 0 0 1.7-.4c.4-.3.7-.7 1-1.2a5 5 0 0 0 .3-2c0-.7-.1-1.3-.3-1.9-.2-.5-.5-1-1-1.2-.3-.3-.9-.5-1.5-.5h-3v20h-4.8v-24Zm11 24-4.4-10.7h5l4.6 10.5v.2h-5.2ZM55.9 116.3v4H45.4v-4h10.5Zm-9-20v24H42v-24H47Zm7.6 9.8v3.8h-9.1v-3.8h9Zm1.4-9.8v4H45.4v-4h10.5ZM69 114c0-.4 0-.8-.2-1.1 0-.4-.2-.7-.5-1l-1-1-1.9-.8-2.6-1.2-2.2-1.5a6.5 6.5 0 0 1-1.7-2 6 6 0 0 1-.5-2.7c0-1 .1-2 .5-2.7a6 6 0 0 1 1.6-2.2c.7-.5 1.5-1 2.4-1.3a9.5 9.5 0 0 1 7.1.5c1.2.6 2 1.5 2.7 2.6.6 1 1 2.4 1 3.8h-5a5 5 0 0 0-.2-1.8c-.2-.5-.5-1-1-1.2-.4-.3-1-.5-1.6-.5-.6 0-1.1.2-1.5.4-.4.2-.7.6-1 1l-.2 1.4c0 .4.1.8.3 1.1l.8.8a21.3 21.3 0 0 0 2.8 1.4l2.9 1.4a9 9 0 0 1 2 1.8c.7.6 1 1.3 1.4 2a7.9 7.9 0 0 1-.1 5.5c-.4.8-.9 1.5-1.5 2.1a7 7 0 0 1-2.5 1.4c-2 .5-1 1.8-3 1.8s-1.3-1.5-3.2-1.8c-1-.3-2-.8-2.7-1.4a6.7 6.7 0 0 1-1.8-2.5c-.4-1-.6-2.2-.6-3.5h4.9c0 .7 0 1.3.2 1.8.1.5.3 1 .6 1.3.3.2.7.5 1.1.6.5.2 1 .2 1.5.2.7 0 1.2 0 1.6-.3.4-.3.6-.6.8-1 .2-.4.3-.9.3-1.4ZM90.5 106v4h-10v-4h10Zm-8.6-9.7v24h-4.8v-24h4.8Zm12.1 0v24h-4.8v-24H94Z"
|
||||
fill="#0A140C"
|
||||
/>
|
||||
<path
|
||||
d="M84 16c13 27 1 52-7 59 0 4-9 9-12 7-12 5-38-2-53-21-6-7 1-21 21-36 13-10 33-17 51-9Z"
|
||||
fill="#FFD80B"
|
||||
/>
|
||||
<path d={juice} fill="#fff" />
|
||||
<path
|
||||
d="M69 15c15-1 9 10-6 19L44 44c-2 1-4-2-6 0l-3 6c-3 1-13 3-16 2-5-2-5-9 5-18l7-4c-1-2-1-2 2-5 3-2 19-10 29-11l1 2 6-1Z"
|
||||
fill="#FFED4E"
|
||||
/>
|
||||
<path
|
||||
d="M38 35c1-1 3-2 3-4l8-3c0 1-1 3 1 4-2 1-7 1-8 5-1-2-1-2-4-2Z"
|
||||
fill="#fff"
|
||||
/>
|
||||
</svg>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default LemonTop;
|
||||
Reference in New Issue
Block a user