poon-choi 0.0.2 → 0.0.4
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.
- package/.output/nitro.json +17 -0
- package/.output/public/assets/about-D4e6L2RX.js +1 -0
- package/.output/public/assets/index-B6P0kA2f.css +1 -0
- package/.output/public/assets/index-CdiJXXIG.js +11 -0
- package/.output/public/assets/routes-BgrRSMVP.js +7 -0
- package/.output/public/assets/styles-DqQrEVt_.css +1 -0
- package/.output/server/_chunks/ssr-renderer.mjs +23 -0
- package/.output/server/_libs/@tanstack/react-router+[...].mjs +15021 -0
- package/.output/server/_libs/clsx.mjs +15 -0
- package/.output/server/_libs/h3+rou3+srvx.mjs +1352 -0
- package/.output/server/_libs/tailwind-merge.mjs +3459 -0
- package/.output/server/_libs/tanstack__history.mjs +363 -0
- package/.output/server/_libs/ufo.mjs +63 -0
- package/.output/server/_runtime.mjs +34 -0
- package/.output/server/_ssr/about-C106R88A.mjs +26 -0
- package/.output/server/_ssr/empty-plugin-adapters-BiGySXWX.mjs +4 -0
- package/.output/server/_ssr/router-B7lhQtFL.mjs +258 -0
- package/.output/server/_ssr/routes-Cutxg__h.mjs +769 -0
- package/.output/server/_ssr/ssr.mjs +7304 -0
- package/.output/server/_ssr/start-CwhArFJN.mjs +3 -0
- package/.output/server/_tanstack-start-manifest_v-Dh5m4VsW.mjs +25 -0
- package/.output/server/index.mjs +311 -0
- package/LICENSE +21 -0
- package/README.md +10 -3
- package/README.zh.md +10 -3
- package/bin/{index.ts → cli.ts} +17 -2
- package/package.json +17 -49
- package/README.tanstack-start.md +0 -224
- package/src/components/DropStage.tsx +0 -64
- package/src/components/FitModeToggle.tsx +0 -34
- package/src/components/Footer.tsx +0 -44
- package/src/components/GapColorPicker.tsx +0 -53
- package/src/components/Header.tsx +0 -78
- package/src/components/PresetColorDropdown.tsx +0 -166
- package/src/components/ThemeToggle.tsx +0 -81
- package/src/components/ThumbnailStrip.tsx +0 -147
- package/src/components/VerticalSeparator.tsx +0 -5
- package/src/hooks/useToast.tsx +0 -23
- package/src/lib/config.ts +0 -48
- package/src/lib/draw.ts +0 -78
- package/src/lib/file.ts +0 -23
- package/src/lib/utils.ts +0 -7
- package/src/routeTree.gen.ts +0 -86
- package/src/router.tsx +0 -19
- package/src/routes/__root.tsx +0 -68
- package/src/routes/about.tsx +0 -23
- package/src/routes/index.css +0 -300
- package/src/routes/index.tsx +0 -511
- package/src/styles.css +0 -375
package/README.tanstack-start.md
DELETED
|
@@ -1,224 +0,0 @@
|
|
|
1
|
-
Welcome to your new TanStack Start app!
|
|
2
|
-
|
|
3
|
-
# Getting Started
|
|
4
|
-
|
|
5
|
-
To run this application:
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
pnpm install
|
|
9
|
-
pnpm dev
|
|
10
|
-
```
|
|
11
|
-
|
|
12
|
-
# Building For Production
|
|
13
|
-
|
|
14
|
-
To build this application for production:
|
|
15
|
-
|
|
16
|
-
```bash
|
|
17
|
-
pnpm build
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
## Styling
|
|
21
|
-
|
|
22
|
-
This project uses [Tailwind CSS](https://tailwindcss.com/) for styling.
|
|
23
|
-
|
|
24
|
-
### Removing Tailwind CSS
|
|
25
|
-
|
|
26
|
-
If you prefer not to use Tailwind CSS:
|
|
27
|
-
|
|
28
|
-
1. Remove the demo pages in `src/routes/demo/`
|
|
29
|
-
2. Replace the Tailwind import in `src/styles.css` with your own styles
|
|
30
|
-
3. Remove `tailwindcss()` from the plugins array in `vite.config.ts`
|
|
31
|
-
4. Remove `@tailwindcss/vite` and `tailwindcss` from `package.json`
|
|
32
|
-
|
|
33
|
-
## Linting & Formatting
|
|
34
|
-
|
|
35
|
-
This project uses [Biome](https://biomejs.dev/) for linting and formatting. The following scripts are available:
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
```bash
|
|
39
|
-
pnpm lint
|
|
40
|
-
pnpm format
|
|
41
|
-
pnpm check
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
## Deploy to Render
|
|
46
|
-
|
|
47
|
-
This project includes a Render Blueprint:
|
|
48
|
-
|
|
49
|
-
1. Push this repo to GitHub, GitLab, or Bitbucket
|
|
50
|
-
2. In Render, choose **New > Blueprint** and connect this repo
|
|
51
|
-
3. Render reads `render.yaml` and creates the web service
|
|
52
|
-
4. In the Render Dashboard, add any secrets from `.env.example` under **Environment**
|
|
53
|
-
5. Deploy
|
|
54
|
-
|
|
55
|
-
The Nitro server handles SSR, server functions, API routes, and static assets.
|
|
56
|
-
Render provides `PORT` automatically; Nitro reads it at runtime.
|
|
57
|
-
|
|
58
|
-
Need a database? Add one from the Render Dashboard, then connect it via
|
|
59
|
-
environment variables. See https://render.com/docs/databases for options.
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
## Shadcn
|
|
63
|
-
|
|
64
|
-
Add components using the latest version of [Shadcn](https://ui.shadcn.com/).
|
|
65
|
-
|
|
66
|
-
```bash
|
|
67
|
-
pnpm dlx shadcn@latest add button
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
## Routing
|
|
73
|
-
|
|
74
|
-
This project uses [TanStack Router](https://tanstack.com/router) with file-based routing. Routes are managed as files in `src/routes`.
|
|
75
|
-
|
|
76
|
-
### Adding A Route
|
|
77
|
-
|
|
78
|
-
To add a new route to your application just add a new file in the `./src/routes` directory.
|
|
79
|
-
|
|
80
|
-
TanStack will automatically generate the content of the route file for you.
|
|
81
|
-
|
|
82
|
-
Now that you have two routes you can use a `Link` component to navigate between them.
|
|
83
|
-
|
|
84
|
-
### Adding Links
|
|
85
|
-
|
|
86
|
-
To use SPA (Single Page Application) navigation you will need to import the `Link` component from `@tanstack/react-router`.
|
|
87
|
-
|
|
88
|
-
```tsx
|
|
89
|
-
import { Link } from "@tanstack/react-router";
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
Then anywhere in your JSX you can use it like so:
|
|
93
|
-
|
|
94
|
-
```tsx
|
|
95
|
-
<Link to="/about">About</Link>
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
This will create a link that will navigate to the `/about` route.
|
|
99
|
-
|
|
100
|
-
More information on the `Link` component can be found in the [Link documentation](https://tanstack.com/router/v1/docs/framework/react/api/router/linkComponent).
|
|
101
|
-
|
|
102
|
-
### Using A Layout
|
|
103
|
-
|
|
104
|
-
In the File Based Routing setup the layout is located in `src/routes/__root.tsx`. Anything you add to the root route will appear in all the routes. The route content will appear in the JSX where you render `{children}` in the `shellComponent`.
|
|
105
|
-
|
|
106
|
-
Here is an example layout that includes a header:
|
|
107
|
-
|
|
108
|
-
```tsx
|
|
109
|
-
import { HeadContent, Scripts, createRootRoute } from '@tanstack/react-router'
|
|
110
|
-
|
|
111
|
-
export const Route = createRootRoute({
|
|
112
|
-
head: () => ({
|
|
113
|
-
meta: [
|
|
114
|
-
{ charSet: 'utf-8' },
|
|
115
|
-
{ name: 'viewport', content: 'width=device-width, initial-scale=1' },
|
|
116
|
-
{ title: 'My App' },
|
|
117
|
-
],
|
|
118
|
-
}),
|
|
119
|
-
shellComponent: ({ children }) => (
|
|
120
|
-
<html lang="en">
|
|
121
|
-
<head>
|
|
122
|
-
<HeadContent />
|
|
123
|
-
</head>
|
|
124
|
-
<body>
|
|
125
|
-
<header>
|
|
126
|
-
<nav>
|
|
127
|
-
<Link to="/">Home</Link>
|
|
128
|
-
<Link to="/about">About</Link>
|
|
129
|
-
</nav>
|
|
130
|
-
</header>
|
|
131
|
-
{children}
|
|
132
|
-
<Scripts />
|
|
133
|
-
</body>
|
|
134
|
-
</html>
|
|
135
|
-
),
|
|
136
|
-
})
|
|
137
|
-
```
|
|
138
|
-
|
|
139
|
-
More information on layouts can be found in the [Layouts documentation](https://tanstack.com/router/latest/docs/framework/react/guide/routing-concepts#layouts).
|
|
140
|
-
|
|
141
|
-
## Server Functions
|
|
142
|
-
|
|
143
|
-
TanStack Start provides server functions that allow you to write server-side code that seamlessly integrates with your client components.
|
|
144
|
-
|
|
145
|
-
```tsx
|
|
146
|
-
import { createServerFn } from '@tanstack/react-start'
|
|
147
|
-
|
|
148
|
-
const getServerTime = createServerFn({
|
|
149
|
-
method: 'GET',
|
|
150
|
-
}).handler(async () => {
|
|
151
|
-
return new Date().toISOString()
|
|
152
|
-
})
|
|
153
|
-
|
|
154
|
-
// Use in a component
|
|
155
|
-
function MyComponent() {
|
|
156
|
-
const [time, setTime] = useState('')
|
|
157
|
-
|
|
158
|
-
useEffect(() => {
|
|
159
|
-
getServerTime().then(setTime)
|
|
160
|
-
}, [])
|
|
161
|
-
|
|
162
|
-
return <div>Server time: {time}</div>
|
|
163
|
-
}
|
|
164
|
-
```
|
|
165
|
-
|
|
166
|
-
## API Routes
|
|
167
|
-
|
|
168
|
-
You can create API routes by using the `server` property in your route definitions:
|
|
169
|
-
|
|
170
|
-
```tsx
|
|
171
|
-
import { createFileRoute } from '@tanstack/react-router'
|
|
172
|
-
import { json } from '@tanstack/react-start'
|
|
173
|
-
|
|
174
|
-
export const Route = createFileRoute('/api/hello')({
|
|
175
|
-
server: {
|
|
176
|
-
handlers: {
|
|
177
|
-
GET: () => json({ message: 'Hello, World!' }),
|
|
178
|
-
},
|
|
179
|
-
},
|
|
180
|
-
})
|
|
181
|
-
```
|
|
182
|
-
|
|
183
|
-
## Data Fetching
|
|
184
|
-
|
|
185
|
-
There are multiple ways to fetch data in your application. You can use TanStack Query to fetch data from a server. But you can also use the `loader` functionality built into TanStack Router to load the data for a route before it's rendered.
|
|
186
|
-
|
|
187
|
-
For example:
|
|
188
|
-
|
|
189
|
-
```tsx
|
|
190
|
-
import { createFileRoute } from '@tanstack/react-router'
|
|
191
|
-
|
|
192
|
-
export const Route = createFileRoute('/people')({
|
|
193
|
-
loader: async () => {
|
|
194
|
-
const response = await fetch('https://swapi.dev/api/people')
|
|
195
|
-
return response.json()
|
|
196
|
-
},
|
|
197
|
-
component: PeopleComponent,
|
|
198
|
-
})
|
|
199
|
-
|
|
200
|
-
function PeopleComponent() {
|
|
201
|
-
const data = Route.useLoaderData()
|
|
202
|
-
return (
|
|
203
|
-
<ul>
|
|
204
|
-
{data.results.map((person) => (
|
|
205
|
-
<li key={person.name}>{person.name}</li>
|
|
206
|
-
))}
|
|
207
|
-
</ul>
|
|
208
|
-
)
|
|
209
|
-
}
|
|
210
|
-
```
|
|
211
|
-
|
|
212
|
-
Loaders simplify your data fetching logic dramatically. Check out more information in the [Loader documentation](https://tanstack.com/router/latest/docs/framework/react/guide/data-loading#loader-parameters).
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
# Demo files
|
|
216
|
-
|
|
217
|
-
Files prefixed with `demo` can be safely deleted. They are there to provide a starting point for you to play around with the features you've installed.
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
# Learn More
|
|
221
|
-
|
|
222
|
-
You can learn more about all of the offerings from TanStack in the [TanStack documentation](https://tanstack.com).
|
|
223
|
-
|
|
224
|
-
For TanStack Start specific documentation, visit [TanStack Start](https://tanstack.com/start).
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
/** biome-ignore-all lint/a11y/noStaticElementInteractions: <explanation> */
|
|
2
|
-
/** biome-ignore-all lint/a11y/useKeyWithClickEvents: <explanation> */
|
|
3
|
-
|
|
4
|
-
import { useRef, useState } from 'react'
|
|
5
|
-
|
|
6
|
-
type Props = {
|
|
7
|
-
items: unknown[]
|
|
8
|
-
children: React.ReactNode
|
|
9
|
-
onFiles: (files: FileList) => void // ⬅️ 对应 addFiles
|
|
10
|
-
id?: string
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function DropStage({ items, children, onFiles }: Props) {
|
|
14
|
-
const dragDepth = useRef(0)
|
|
15
|
-
const [isDragOver, setIsDragOver] = useState(false)
|
|
16
|
-
|
|
17
|
-
const handleDragEnter = (e: React.DragEvent) => {
|
|
18
|
-
if (e.dataTransfer && Array.from(e.dataTransfer.types).includes('Files')) {
|
|
19
|
-
e.preventDefault()
|
|
20
|
-
dragDepth.current += 1
|
|
21
|
-
setIsDragOver(true)
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const handleDragover = (e: React.DragEvent) => {
|
|
26
|
-
if (e.dataTransfer && Array.from(e.dataTransfer.types).includes('Files')) {
|
|
27
|
-
e.preventDefault()
|
|
28
|
-
e.dataTransfer.dropEffect = 'copy'
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
const handleDragLeave = (_e: React.DragEvent) => {
|
|
32
|
-
dragDepth.current = Math.max(0, dragDepth.current - 1)
|
|
33
|
-
if (dragDepth.current === 0) setIsDragOver(false)
|
|
34
|
-
}
|
|
35
|
-
const handleDrop = (e: React.DragEvent) => {
|
|
36
|
-
if (e.dataTransfer && Array.from(e.dataTransfer.types).includes('Files')) {
|
|
37
|
-
e.preventDefault()
|
|
38
|
-
dragDepth.current = 0
|
|
39
|
-
setIsDragOver(false)
|
|
40
|
-
onFiles(e.dataTransfer.files)
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const className = [
|
|
45
|
-
'stage',
|
|
46
|
-
items.length > 0 && 'has-image',
|
|
47
|
-
isDragOver && 'dragover',
|
|
48
|
-
]
|
|
49
|
-
.filter(Boolean)
|
|
50
|
-
.join(' ')
|
|
51
|
-
|
|
52
|
-
return (
|
|
53
|
-
<div
|
|
54
|
-
className={className}
|
|
55
|
-
id="stage"
|
|
56
|
-
onDragEnter={(event) => handleDragEnter(event)}
|
|
57
|
-
onDragLeave={handleDragLeave}
|
|
58
|
-
onDragOver={handleDragover}
|
|
59
|
-
onDrop={handleDrop}
|
|
60
|
-
>
|
|
61
|
-
{children}
|
|
62
|
-
</div>
|
|
63
|
-
)
|
|
64
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import type { FitMode } from '#/lib/draw'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* 受控的模式切换按钮。
|
|
5
|
-
* value: 'cover' | 'contain'
|
|
6
|
-
* onChange: (next: 'cover' | 'contain') => void
|
|
7
|
-
*/
|
|
8
|
-
export function FitModeToggle({
|
|
9
|
-
value,
|
|
10
|
-
onChange,
|
|
11
|
-
className = '',
|
|
12
|
-
}: {
|
|
13
|
-
value: FitMode
|
|
14
|
-
onChange: (next: FitMode) => void
|
|
15
|
-
className?: string
|
|
16
|
-
}) {
|
|
17
|
-
const next = value === 'cover' ? 'contain' : 'cover'
|
|
18
|
-
const label = value === 'cover' ? 'Cover' : 'Contain'
|
|
19
|
-
return (
|
|
20
|
-
<button
|
|
21
|
-
type="button"
|
|
22
|
-
onClick={() => onChange(next)}
|
|
23
|
-
aria-pressed={value === 'contain'}
|
|
24
|
-
className={
|
|
25
|
-
'cursor-pointer ' +
|
|
26
|
-
'px-4 py-2.5 rounded-lg text-sm font-medium bg-white text-slate-700 ' +
|
|
27
|
-
'border border-slate-200 transition hover:bg-slate-50 ' +
|
|
28
|
-
className
|
|
29
|
-
}
|
|
30
|
-
>
|
|
31
|
-
裁剪模式:{label}
|
|
32
|
-
</button>
|
|
33
|
-
)
|
|
34
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
export default function Footer() {
|
|
2
|
-
const year = new Date().getFullYear()
|
|
3
|
-
|
|
4
|
-
return (
|
|
5
|
-
<footer className="mt-20 border-t border-[var(--line)] px-4 pb-14 pt-10 text-[var(--sea-ink-soft)]">
|
|
6
|
-
<div className="page-wrap flex flex-col items-center justify-between gap-4 text-center sm:flex-row sm:text-left">
|
|
7
|
-
<p className="m-0 text-sm">
|
|
8
|
-
© {year} Your name here. All rights reserved.
|
|
9
|
-
</p>
|
|
10
|
-
<p className="island-kicker m-0">Built with TanStack Start</p>
|
|
11
|
-
</div>
|
|
12
|
-
<div className="mt-4 flex justify-center gap-4">
|
|
13
|
-
<a
|
|
14
|
-
href="https://x.com/tan_stack"
|
|
15
|
-
target="_blank"
|
|
16
|
-
rel="noreferrer"
|
|
17
|
-
className="rounded-xl p-2 text-[var(--sea-ink-soft)] transition hover:bg-[var(--link-bg-hover)] hover:text-[var(--sea-ink)]"
|
|
18
|
-
>
|
|
19
|
-
<span className="sr-only">Follow TanStack on X</span>
|
|
20
|
-
<svg viewBox="0 0 16 16" aria-hidden="true" width="32" height="32">
|
|
21
|
-
<path
|
|
22
|
-
fill="currentColor"
|
|
23
|
-
d="M12.6 1h2.2L10 6.48 15.64 15h-4.41L7.78 9.82 3.23 15H1l5.14-5.84L.72 1h4.52l3.12 4.73L12.6 1zm-.77 12.67h1.22L4.57 2.26H3.26l8.57 11.41z"
|
|
24
|
-
/>
|
|
25
|
-
</svg>
|
|
26
|
-
</a>
|
|
27
|
-
<a
|
|
28
|
-
href="https://github.com/TanStack"
|
|
29
|
-
target="_blank"
|
|
30
|
-
rel="noreferrer"
|
|
31
|
-
className="rounded-xl p-2 text-[var(--sea-ink-soft)] transition hover:bg-[var(--link-bg-hover)] hover:text-[var(--sea-ink)]"
|
|
32
|
-
>
|
|
33
|
-
<span className="sr-only">Go to TanStack GitHub</span>
|
|
34
|
-
<svg viewBox="0 0 16 16" aria-hidden="true" width="32" height="32">
|
|
35
|
-
<path
|
|
36
|
-
fill="currentColor"
|
|
37
|
-
d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.012 8.012 0 0 0 16 8c0-4.42-3.58-8-8-8z"
|
|
38
|
-
/>
|
|
39
|
-
</svg>
|
|
40
|
-
</a>
|
|
41
|
-
</div>
|
|
42
|
-
</footer>
|
|
43
|
-
)
|
|
44
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { useState } from 'react'
|
|
2
|
-
import { PresetColorDropdown } from './PresetColorDropdown'
|
|
3
|
-
|
|
4
|
-
export function GapColorPicker({
|
|
5
|
-
onChange,
|
|
6
|
-
initialColor,
|
|
7
|
-
presetColors,
|
|
8
|
-
}: {
|
|
9
|
-
onChange: (color: string) => void
|
|
10
|
-
initialColor: string
|
|
11
|
-
presetColors: string[]
|
|
12
|
-
}) {
|
|
13
|
-
const [value, setValue] = useState(initialColor)
|
|
14
|
-
|
|
15
|
-
return (
|
|
16
|
-
// to tailwind css "display: flex; align-items: center; gap: 8px; font-size: 13px; color: #555;"
|
|
17
|
-
<div className="gap-color-wrap flex items-center gap-2 text-sm text-slate-600">
|
|
18
|
-
<label htmlFor="gapColor" className="cursor-pointer">
|
|
19
|
-
间隙颜色
|
|
20
|
-
</label>
|
|
21
|
-
<PresetColorDropdown
|
|
22
|
-
presets={presetColors}
|
|
23
|
-
curColor={value}
|
|
24
|
-
onPick={(color) => {
|
|
25
|
-
setValue(color)
|
|
26
|
-
onChange(color)
|
|
27
|
-
}}
|
|
28
|
-
/>
|
|
29
|
-
|
|
30
|
-
<div
|
|
31
|
-
className="flex items-center gap-2 ps-2 border border-gray-300 rounded-md"
|
|
32
|
-
style={{ outline: `1px solid ${value}`, outlineOffset: '-2px' }}
|
|
33
|
-
>
|
|
34
|
-
🎨
|
|
35
|
-
<input
|
|
36
|
-
type="color"
|
|
37
|
-
id="gapColor"
|
|
38
|
-
value={value}
|
|
39
|
-
onChange={(e) => {
|
|
40
|
-
const gapColor = e.target.value
|
|
41
|
-
setValue(gapColor)
|
|
42
|
-
onChange(gapColor)
|
|
43
|
-
}}
|
|
44
|
-
// width: 34px; height: 34px; padding: 0; border: 1px solid #d5dae2; border-radius: 8px; background: none; cursor: pointer;
|
|
45
|
-
className="h-8 w-8 aspect-square bg-transparent cursor-pointer
|
|
46
|
-
[&::-webkit-color-swatch-wrapper]:p-0
|
|
47
|
-
[&::-webkit-color-swatch]:rounded-md [&::-webkit-color-swatch]:border-0
|
|
48
|
-
"
|
|
49
|
-
/>
|
|
50
|
-
</div>
|
|
51
|
-
</div>
|
|
52
|
-
)
|
|
53
|
-
}
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { Link } from '@tanstack/react-router'
|
|
2
|
-
import ThemeToggle from './ThemeToggle'
|
|
3
|
-
|
|
4
|
-
export default function Header() {
|
|
5
|
-
return (
|
|
6
|
-
<header className="sticky top-0 z-50 border-b border-[var(--line)] bg-[var(--header-bg)] px-4 backdrop-blur-lg">
|
|
7
|
-
<nav className="page-wrap flex flex-wrap items-center gap-x-3 gap-y-2 py-3 sm:py-4">
|
|
8
|
-
<h2 className="m-0 flex-shrink-0 text-base font-semibold tracking-tight">
|
|
9
|
-
<Link
|
|
10
|
-
to="/"
|
|
11
|
-
className="inline-flex items-center gap-2 rounded-full border border-[var(--chip-line)] bg-[var(--chip-bg)] px-3 py-1.5 text-sm text-[var(--sea-ink)] no-underline shadow-[0_8px_24px_rgba(30,90,72,0.08)] sm:px-4 sm:py-2"
|
|
12
|
-
>
|
|
13
|
-
<span className="h-2 w-2 rounded-full bg-[linear-gradient(90deg,#56c6be,#7ed3bf)]" />
|
|
14
|
-
TanStack Start
|
|
15
|
-
</Link>
|
|
16
|
-
</h2>
|
|
17
|
-
|
|
18
|
-
<div className="order-3 flex w-full flex-wrap items-center gap-x-4 gap-y-1 pb-1 text-sm font-semibold sm:order-none sm:w-auto sm:flex-nowrap sm:pb-0">
|
|
19
|
-
<Link
|
|
20
|
-
to="/"
|
|
21
|
-
className="nav-link"
|
|
22
|
-
activeProps={{ className: 'nav-link is-active' }}
|
|
23
|
-
>
|
|
24
|
-
Home
|
|
25
|
-
</Link>
|
|
26
|
-
<Link
|
|
27
|
-
to="/about"
|
|
28
|
-
className="nav-link"
|
|
29
|
-
activeProps={{ className: 'nav-link is-active' }}
|
|
30
|
-
>
|
|
31
|
-
About
|
|
32
|
-
</Link>
|
|
33
|
-
<a
|
|
34
|
-
href="https://tanstack.com/start/latest/docs/framework/react/overview"
|
|
35
|
-
className="nav-link"
|
|
36
|
-
target="_blank"
|
|
37
|
-
rel="noreferrer"
|
|
38
|
-
>
|
|
39
|
-
Docs
|
|
40
|
-
</a>
|
|
41
|
-
</div>
|
|
42
|
-
|
|
43
|
-
<div className="ml-auto flex items-center gap-1.5 sm:gap-2">
|
|
44
|
-
<a
|
|
45
|
-
href="https://x.com/tan_stack"
|
|
46
|
-
target="_blank"
|
|
47
|
-
rel="noreferrer"
|
|
48
|
-
className="hidden rounded-xl p-2 text-[var(--sea-ink-soft)] transition hover:bg-[var(--link-bg-hover)] hover:text-[var(--sea-ink)] sm:block"
|
|
49
|
-
>
|
|
50
|
-
<span className="sr-only">Follow TanStack on X</span>
|
|
51
|
-
<svg viewBox="0 0 16 16" aria-hidden="true" width="24" height="24">
|
|
52
|
-
<path
|
|
53
|
-
fill="currentColor"
|
|
54
|
-
d="M12.6 1h2.2L10 6.48 15.64 15h-4.41L7.78 9.82 3.23 15H1l5.14-5.84L.72 1h4.52l3.12 4.73L12.6 1zm-.77 12.67h1.22L4.57 2.26H3.26l8.57 11.41z"
|
|
55
|
-
/>
|
|
56
|
-
</svg>
|
|
57
|
-
</a>
|
|
58
|
-
<a
|
|
59
|
-
href="https://github.com/TanStack"
|
|
60
|
-
target="_blank"
|
|
61
|
-
rel="noreferrer"
|
|
62
|
-
className="hidden rounded-xl p-2 text-[var(--sea-ink-soft)] transition hover:bg-[var(--link-bg-hover)] hover:text-[var(--sea-ink)] sm:block"
|
|
63
|
-
>
|
|
64
|
-
<span className="sr-only">Go to TanStack GitHub</span>
|
|
65
|
-
<svg viewBox="0 0 16 16" aria-hidden="true" width="24" height="24">
|
|
66
|
-
<path
|
|
67
|
-
fill="currentColor"
|
|
68
|
-
d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.012 8.012 0 0 0 16 8c0-4.42-3.58-8-8-8z"
|
|
69
|
-
/>
|
|
70
|
-
</svg>
|
|
71
|
-
</a>
|
|
72
|
-
|
|
73
|
-
<ThemeToggle />
|
|
74
|
-
</div>
|
|
75
|
-
</nav>
|
|
76
|
-
</header>
|
|
77
|
-
)
|
|
78
|
-
}
|
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
// GapColorPicker.jsx 内
|
|
2
|
-
|
|
3
|
-
import { useEffect, useRef, useState } from 'react'
|
|
4
|
-
import { cn } from '#/lib/utils'
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* color keyword to color value converter (eg. `'white'` -> `'#ffffff'`)
|
|
8
|
-
* @param c
|
|
9
|
-
* @returns
|
|
10
|
-
*/
|
|
11
|
-
const toColorValue = (c: string): string => {
|
|
12
|
-
// return c
|
|
13
|
-
const ctx = document.createElement('canvas').getContext('2d')
|
|
14
|
-
if (!ctx) return c
|
|
15
|
-
ctx.fillStyle = c
|
|
16
|
-
|
|
17
|
-
return ctx.fillStyle
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
interface PresetDropdownProps {
|
|
21
|
-
onPick: (hex: string) => void
|
|
22
|
-
presets: string[]
|
|
23
|
-
curColor: string
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export function PresetColorDropdown({
|
|
27
|
-
onPick,
|
|
28
|
-
presets: PRESETS,
|
|
29
|
-
curColor,
|
|
30
|
-
}: PresetDropdownProps) {
|
|
31
|
-
const [open, setOpen] = useState<boolean>(false)
|
|
32
|
-
const ref = useRef<HTMLDivElement | null>(null)
|
|
33
|
-
const [cycleIndex, setCycleIndex] = useState(0)
|
|
34
|
-
// const [curColor, setCurColor] = useState<string>(PRESETS[0])
|
|
35
|
-
|
|
36
|
-
useEffect(() => {
|
|
37
|
-
if (!open) return
|
|
38
|
-
const onDown = (e: MouseEvent) => {
|
|
39
|
-
if (ref.current && !ref.current.contains(e.target as Node)) setOpen(false)
|
|
40
|
-
}
|
|
41
|
-
document.addEventListener('mousedown', onDown)
|
|
42
|
-
return () => document.removeEventListener('mousedown', onDown)
|
|
43
|
-
}, [open])
|
|
44
|
-
|
|
45
|
-
const handleCycle = (): void => {
|
|
46
|
-
const next = PRESETS[cycleIndex % PRESETS.length]
|
|
47
|
-
// setCurColor(next)
|
|
48
|
-
// onChange(toColorValue(next))
|
|
49
|
-
onPick(next)
|
|
50
|
-
setCycleIndex((i) => (i + 1) % PRESETS.length)
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return (
|
|
54
|
-
<div ref={ref} className="relative flex gap-1">
|
|
55
|
-
<button
|
|
56
|
-
type="button"
|
|
57
|
-
onClick={() => setOpen((o) => !o)}
|
|
58
|
-
className="h-9 w-57 px-3 rounded-lg border border-slate-200 bg-white text-[13px]
|
|
59
|
-
text-slate-600 flex justify-between items-center gap-2 hover:bg-slate-50"
|
|
60
|
-
>
|
|
61
|
-
预设颜色 <code className={'border-0!'}>{curColor}</code>
|
|
62
|
-
<div className="flex items-center gap-2 xms-auto">
|
|
63
|
-
<ColorPreviewerCube color={curColor} />
|
|
64
|
-
<span className="text-slate-400">▾</span>
|
|
65
|
-
</div>
|
|
66
|
-
</button>
|
|
67
|
-
|
|
68
|
-
{open && (
|
|
69
|
-
<div
|
|
70
|
-
className="absolute z-20 mt-10 min-w-[calc(100%-5rem)] max-h-64 overflow-auto rounded-lg border
|
|
71
|
-
border-slate-200 bg-white shadow-lg p-1"
|
|
72
|
-
>
|
|
73
|
-
{/* color not presets */}
|
|
74
|
-
{!PRESETS.find((x) => isSameColor(x, curColor)) && (
|
|
75
|
-
<Option
|
|
76
|
-
className="cursor-not-allowed"
|
|
77
|
-
color={curColor}
|
|
78
|
-
curColor={curColor}
|
|
79
|
-
renderColor={() => `${curColor} not in presets`}
|
|
80
|
-
></Option>
|
|
81
|
-
)}
|
|
82
|
-
|
|
83
|
-
{PRESETS.map((c) => {
|
|
84
|
-
const hex = toColorValue(c)
|
|
85
|
-
return (
|
|
86
|
-
<Option
|
|
87
|
-
key={hex}
|
|
88
|
-
curColor={curColor}
|
|
89
|
-
color={c}
|
|
90
|
-
onClick={(color) => {
|
|
91
|
-
onPick(color)
|
|
92
|
-
setOpen(false)
|
|
93
|
-
}}
|
|
94
|
-
></Option>
|
|
95
|
-
)
|
|
96
|
-
})}
|
|
97
|
-
</div>
|
|
98
|
-
)}
|
|
99
|
-
|
|
100
|
-
<button
|
|
101
|
-
type="button"
|
|
102
|
-
onClick={handleCycle}
|
|
103
|
-
className="h-9 px-3 rounded-lg text-[13px] font-medium bg-white text-slate-700
|
|
104
|
-
border border-slate-200 transition hover:bg-slate-50"
|
|
105
|
-
>
|
|
106
|
-
逐个设置
|
|
107
|
-
</button>
|
|
108
|
-
</div>
|
|
109
|
-
)
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
function ColorPreviewerCube({ color }: { color: string }) {
|
|
113
|
-
return (
|
|
114
|
-
<span
|
|
115
|
-
className="inline-block w-4 h-4 rounded border border-slate-300 shrink-0"
|
|
116
|
-
style={{ background: color }}
|
|
117
|
-
/>
|
|
118
|
-
)
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
function Option({
|
|
122
|
-
color: c,
|
|
123
|
-
onClick,
|
|
124
|
-
curColor,
|
|
125
|
-
renderColor = identity,
|
|
126
|
-
className,
|
|
127
|
-
}: {
|
|
128
|
-
curColor: string
|
|
129
|
-
color: string
|
|
130
|
-
onClick?: (hex: string) => void
|
|
131
|
-
renderColor?: (color: string) => Text
|
|
132
|
-
className?: string
|
|
133
|
-
}) {
|
|
134
|
-
return (
|
|
135
|
-
<button
|
|
136
|
-
key={c}
|
|
137
|
-
type="button"
|
|
138
|
-
onClick={() => {
|
|
139
|
-
onClick?.(c)
|
|
140
|
-
// onPick(hex)
|
|
141
|
-
// setCurColor(hex)
|
|
142
|
-
// setOpen(false)
|
|
143
|
-
}}
|
|
144
|
-
className={cn(
|
|
145
|
-
`cursor-pointer w-full flex items-center gap-2 px-2 py-1.5 rounded-md`,
|
|
146
|
-
`text-[13px] text-slate-700 hover:bg-slate-100`,
|
|
147
|
-
isSameColor(curColor, c) && 'bg-slate-100',
|
|
148
|
-
className,
|
|
149
|
-
)}
|
|
150
|
-
>
|
|
151
|
-
<ColorPreviewerCube color={c} />
|
|
152
|
-
<code className="font-mono border-0! whitespace-nowrap">
|
|
153
|
-
{renderColor(c)}
|
|
154
|
-
</code>
|
|
155
|
-
</button>
|
|
156
|
-
)
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
const isSameColor = (a: string, b: string) => {
|
|
160
|
-
return a === b || toColorValue(a) === toColorValue(b)
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
type Text = string
|
|
164
|
-
function identity<T>(value: T) {
|
|
165
|
-
return value
|
|
166
|
-
}
|