-
Notifications
You must be signed in to change notification settings - Fork 4
feat(home): add the first screen on the current architecture #91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
huyanxius
wants to merge
9
commits into
1024XEngineer:main
Choose a base branch
from
huyanxius:feat/home-first-screen
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a167cb2
feat(home): add dotted brand mark backdrop
huyanxius 4b85b0c
feat(home): replace placeholder root route with first screen
huyanxius e6a1175
feat(app): move the shell boundary into the route table
huyanxius 135ac1a
test(home): cover first screen entries and choice card
huyanxius 6f17988
feat(layout): remove the centered content container
huyanxius 8f9fd49
fix(layout): make the site name a link back home
huyanxius 557417e
docs(frontend): sync the docs with the landed first screen
huyanxius 0c88dc7
feat(shared): add an opt-in page container
huyanxius 15a975a
refactor(pages): wrap the placeholder pages in the page container
huyanxius File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,13 @@ | ||
| import { PageContainer } from '@/shared/ui' | ||
|
|
||
| /** 资产库。 */ | ||
| export function AssetLibraryPage() { | ||
| return ( | ||
| <section className="border border-dashed border-slate-300 p-6"> | ||
| <h1 className="font-medium">资产库</h1> | ||
| <p className="mt-2 text-sm text-slate-500">本次只提交模块划分与接口,页面实现进后续 PR。</p> | ||
| </section> | ||
| <PageContainer> | ||
| <section className="border border-dashed border-slate-300 p-6"> | ||
| <h1 className="font-medium">资产库</h1> | ||
| <p className="mt-2 text-sm text-slate-500">本次只提交模块划分与接口,页面实现进后续 PR。</p> | ||
| </section> | ||
| </PageContainer> | ||
| ) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,154 @@ | ||
| import { useEffect, useRef } from 'react' | ||
|
|
||
| const SAMPLE_SIZE = 48 | ||
| const MAX_DPR = 2 | ||
| const WAVE_DURATION = 7200 | ||
|
|
||
| interface BrandPoint { | ||
| accent: boolean | ||
| luminance: number | ||
| x: number | ||
| y: number | ||
| } | ||
|
|
||
| function smoothStep(value: number) { | ||
| return value * value * (3 - 2 * value) | ||
| } | ||
|
|
||
| function sampleMark(image: HTMLImageElement): BrandPoint[] { | ||
| const sample = document.createElement('canvas') | ||
| sample.width = SAMPLE_SIZE | ||
| sample.height = SAMPLE_SIZE | ||
| const context = sample.getContext('2d', { willReadFrequently: true }) | ||
| if (!context) return [] | ||
|
|
||
| context.drawImage(image, 0, 0, SAMPLE_SIZE, SAMPLE_SIZE) | ||
| const pixels = context.getImageData(0, 0, SAMPLE_SIZE, SAMPLE_SIZE).data | ||
| const points: BrandPoint[] = [] | ||
|
|
||
| for (let y = 0; y < SAMPLE_SIZE; y += 1) { | ||
| for (let x = 0; x < SAMPLE_SIZE; x += 1) { | ||
| if (pixels[(y * SAMPLE_SIZE + x) * 4 + 3] < 80) continue | ||
| const centerLight = Math.max( | ||
| 0, | ||
| 1 - Math.hypot(x / SAMPLE_SIZE - 0.5, y / SAMPLE_SIZE - 0.5) / 0.7, | ||
| ) | ||
| points.push({ | ||
| accent: Math.hypot(x - SAMPLE_SIZE * 0.44, y - SAMPLE_SIZE * 0.5) < SAMPLE_SIZE * 0.055, | ||
| luminance: 0.34 + centerLight * 0.3, | ||
| x: x / (SAMPLE_SIZE - 1), | ||
| y: y / (SAMPLE_SIZE - 1), | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| return points | ||
| } | ||
|
|
||
| /** livedemo 主屏点阵小鸟;仅作为主页背景,不接入页面业务。 */ | ||
| export function HomeBrandBird() { | ||
| const canvasRef = useRef<HTMLCanvasElement>(null) | ||
|
|
||
| useEffect(() => { | ||
| const canvas = canvasRef.current | ||
| if (!canvas || typeof ResizeObserver === 'undefined') return | ||
| const context = canvas.getContext('2d') | ||
| if (!context) return | ||
|
|
||
| const reduceMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches | ||
| const image = new Image() | ||
| image.decoding = 'async' | ||
| image.src = '/windup-mark.svg' | ||
|
|
||
| let animationFrame = 0 | ||
| let points: BrandPoint[] = [] | ||
| let width = 1 | ||
| let height = 1 | ||
|
|
||
| function draw(time = 0) { | ||
| context!.clearRect(0, 0, width, height) | ||
| if (!points.length) return | ||
|
|
||
| const markSize = Math.min(width * 0.36, height * 0.66, 576) | ||
| const originX = Math.max(18, width * 0.02) | ||
| const originY = height - markSize * 0.9 | ||
| const dotRadius = Math.max(1.15, Math.min(3.6, markSize / 155)) | ||
| const waveProgress = reduceMotion ? 0.5 : (time % WAVE_DURATION) / WAVE_DURATION | ||
| const primaryCenter = originX + (waveProgress * 1.42 - 0.2) * markSize | ||
| const echoProgress = (waveProgress + 0.52) % 1 | ||
| const echoCenter = originX + (echoProgress * 1.42 - 0.2) * markSize | ||
| const spread = markSize * 0.15 | ||
|
|
||
| for (const point of points) { | ||
| const baseX = originX + point.x * markSize | ||
| const baseY = originY + point.y * markSize | ||
| const primaryDistance = baseX - primaryCenter | ||
| const echoDistance = baseX - echoCenter | ||
| const primaryWave = reduceMotion | ||
| ? 0 | ||
| : Math.sin(primaryDistance / 14) * Math.exp(-((primaryDistance / spread) ** 2)) | ||
| const echoWave = reduceMotion | ||
| ? 0 | ||
| : Math.sin(echoDistance / 17) * Math.exp(-((echoDistance / spread) ** 2)) * 0.42 | ||
| const displacement = (primaryWave + echoWave) * 4.2 * (0.38 + smoothStep(point.x) * 0.62) | ||
| const lightBand = primaryWave * 0.2 + echoWave * 0.1 | ||
| const opacity = Math.max(0.16, Math.min(0.92, point.luminance + lightBand)) | ||
|
|
||
| context!.beginPath() | ||
| context!.arc( | ||
| baseX + displacement * 0.18, | ||
| baseY + displacement, | ||
| dotRadius + Math.max(0, lightBand) * 1.35, | ||
| 0, | ||
| Math.PI * 2, | ||
| ) | ||
| context!.fillStyle = point.accent | ||
| ? `rgba(176, 119, 47, ${Math.min(0.76, opacity + 0.12)})` | ||
| : `rgba(38, 63, 45, ${opacity * 0.38})` | ||
| context!.fill() | ||
| } | ||
| } | ||
|
|
||
| function resize() { | ||
| const bounds = canvas!.getBoundingClientRect() | ||
| const dpr = Math.min(window.devicePixelRatio || 1, MAX_DPR) | ||
| width = Math.max(1, bounds.width) | ||
| height = Math.max(1, bounds.height) | ||
| canvas!.width = Math.round(width * dpr) | ||
| canvas!.height = Math.round(height * dpr) | ||
| context!.setTransform(dpr, 0, 0, dpr, 0, 0) | ||
| draw() | ||
| } | ||
|
|
||
| function animate(time: number) { | ||
| draw(time) | ||
| animationFrame = window.requestAnimationFrame(animate) | ||
| } | ||
|
|
||
| function load() { | ||
| points = sampleMark(image) | ||
| draw() | ||
| if (!reduceMotion) animationFrame = window.requestAnimationFrame(animate) | ||
| } | ||
|
|
||
| const observer = new ResizeObserver(resize) | ||
| observer.observe(canvas) | ||
| image.addEventListener('load', load, { once: true }) | ||
| resize() | ||
|
|
||
| return () => { | ||
| window.cancelAnimationFrame(animationFrame) | ||
| observer.disconnect() | ||
| image.removeEventListener('load', load) | ||
| } | ||
| }, []) | ||
|
|
||
| return ( | ||
| <canvas | ||
| ref={canvasRef} | ||
| data-testid="home-brand-bird" | ||
| aria-hidden="true" | ||
| className="pointer-events-none absolute inset-0 h-full w-full opacity-75" | ||
| /> | ||
| ) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| // @vitest-environment jsdom | ||
| import { cleanup, render, screen } from '@testing-library/react' | ||
| import { afterEach, describe, expect, it } from 'vitest' | ||
| import { MemoryRouter } from 'react-router' | ||
|
|
||
| import { HomeChoiceCard } from './choice-card' | ||
|
|
||
| afterEach(cleanup) | ||
|
|
||
| describe('HomeChoiceCard', () => { | ||
| it('只根据输入渲染一个可导航入口', () => { | ||
| render( | ||
| <MemoryRouter> | ||
| <HomeChoiceCard | ||
| to="/quick-start" | ||
| eyebrow="ONE COMMAND" | ||
| index="01" | ||
| title="快速开始" | ||
| description="用一句话描述角色。" | ||
| actionLabel="写下角色设定" | ||
| tone="dark" | ||
| /> | ||
| </MemoryRouter>, | ||
| ) | ||
|
|
||
| expect(screen.getByRole('link', { name: /快速开始/ }).getAttribute('href')).toBe('/quick-start') | ||
| }) | ||
| }) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.