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.
Files changed (49) hide show
  1. package/.output/nitro.json +17 -0
  2. package/.output/public/assets/about-D4e6L2RX.js +1 -0
  3. package/.output/public/assets/index-B6P0kA2f.css +1 -0
  4. package/.output/public/assets/index-CdiJXXIG.js +11 -0
  5. package/.output/public/assets/routes-BgrRSMVP.js +7 -0
  6. package/.output/public/assets/styles-DqQrEVt_.css +1 -0
  7. package/.output/server/_chunks/ssr-renderer.mjs +23 -0
  8. package/.output/server/_libs/@tanstack/react-router+[...].mjs +15021 -0
  9. package/.output/server/_libs/clsx.mjs +15 -0
  10. package/.output/server/_libs/h3+rou3+srvx.mjs +1352 -0
  11. package/.output/server/_libs/tailwind-merge.mjs +3459 -0
  12. package/.output/server/_libs/tanstack__history.mjs +363 -0
  13. package/.output/server/_libs/ufo.mjs +63 -0
  14. package/.output/server/_runtime.mjs +34 -0
  15. package/.output/server/_ssr/about-C106R88A.mjs +26 -0
  16. package/.output/server/_ssr/empty-plugin-adapters-BiGySXWX.mjs +4 -0
  17. package/.output/server/_ssr/router-B7lhQtFL.mjs +258 -0
  18. package/.output/server/_ssr/routes-Cutxg__h.mjs +769 -0
  19. package/.output/server/_ssr/ssr.mjs +7304 -0
  20. package/.output/server/_ssr/start-CwhArFJN.mjs +3 -0
  21. package/.output/server/_tanstack-start-manifest_v-Dh5m4VsW.mjs +25 -0
  22. package/.output/server/index.mjs +311 -0
  23. package/LICENSE +21 -0
  24. package/README.md +10 -3
  25. package/README.zh.md +10 -3
  26. package/bin/{index.ts → cli.ts} +17 -2
  27. package/package.json +17 -49
  28. package/README.tanstack-start.md +0 -224
  29. package/src/components/DropStage.tsx +0 -64
  30. package/src/components/FitModeToggle.tsx +0 -34
  31. package/src/components/Footer.tsx +0 -44
  32. package/src/components/GapColorPicker.tsx +0 -53
  33. package/src/components/Header.tsx +0 -78
  34. package/src/components/PresetColorDropdown.tsx +0 -166
  35. package/src/components/ThemeToggle.tsx +0 -81
  36. package/src/components/ThumbnailStrip.tsx +0 -147
  37. package/src/components/VerticalSeparator.tsx +0 -5
  38. package/src/hooks/useToast.tsx +0 -23
  39. package/src/lib/config.ts +0 -48
  40. package/src/lib/draw.ts +0 -78
  41. package/src/lib/file.ts +0 -23
  42. package/src/lib/utils.ts +0 -7
  43. package/src/routeTree.gen.ts +0 -86
  44. package/src/router.tsx +0 -19
  45. package/src/routes/__root.tsx +0 -68
  46. package/src/routes/about.tsx +0 -23
  47. package/src/routes/index.css +0 -300
  48. package/src/routes/index.tsx +0 -511
  49. package/src/styles.css +0 -375
@@ -1,81 +0,0 @@
1
- import { useEffect, useState } from 'react'
2
-
3
- type ThemeMode = 'light' | 'dark' | 'auto'
4
-
5
- function getInitialMode(): ThemeMode {
6
- if (typeof window === 'undefined') {
7
- return 'auto'
8
- }
9
-
10
- const stored = window.localStorage.getItem('theme')
11
- if (stored === 'light' || stored === 'dark' || stored === 'auto') {
12
- return stored
13
- }
14
-
15
- return 'auto'
16
- }
17
-
18
- function applyThemeMode(mode: ThemeMode) {
19
- const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches
20
- const resolved = mode === 'auto' ? (prefersDark ? 'dark' : 'light') : mode
21
-
22
- document.documentElement.classList.remove('light', 'dark')
23
- document.documentElement.classList.add(resolved)
24
-
25
- if (mode === 'auto') {
26
- document.documentElement.removeAttribute('data-theme')
27
- } else {
28
- document.documentElement.setAttribute('data-theme', mode)
29
- }
30
-
31
- document.documentElement.style.colorScheme = resolved
32
- }
33
-
34
- export default function ThemeToggle() {
35
- const [mode, setMode] = useState<ThemeMode>('auto')
36
-
37
- useEffect(() => {
38
- const initialMode = getInitialMode()
39
- setMode(initialMode)
40
- applyThemeMode(initialMode)
41
- }, [])
42
-
43
- useEffect(() => {
44
- if (mode !== 'auto') {
45
- return
46
- }
47
-
48
- const media = window.matchMedia('(prefers-color-scheme: dark)')
49
- const onChange = () => applyThemeMode('auto')
50
-
51
- media.addEventListener('change', onChange)
52
- return () => {
53
- media.removeEventListener('change', onChange)
54
- }
55
- }, [mode])
56
-
57
- function toggleMode() {
58
- const nextMode: ThemeMode =
59
- mode === 'light' ? 'dark' : mode === 'dark' ? 'auto' : 'light'
60
- setMode(nextMode)
61
- applyThemeMode(nextMode)
62
- window.localStorage.setItem('theme', nextMode)
63
- }
64
-
65
- const label =
66
- mode === 'auto'
67
- ? 'Theme mode: auto (system). Click to switch to light mode.'
68
- : `Theme mode: ${mode}. Click to switch mode.`
69
-
70
- return (
71
- <button
72
- type="button"
73
- onClick={toggleMode}
74
- aria-label={label}
75
- title={label}
76
- className="rounded-full border border-[var(--chip-line)] bg-[var(--chip-bg)] px-3 py-1.5 text-sm font-semibold text-[var(--sea-ink)] shadow-[0_8px_22px_rgba(30,90,72,0.08)] transition hover:-translate-y-0.5"
77
- >
78
- {mode === 'auto' ? 'Auto' : mode === 'dark' ? 'Dark' : 'Light'}
79
- </button>
80
- )
81
- }
@@ -1,147 +0,0 @@
1
- /** biome-ignore-all lint/a11y/noStaticElementInteractions: <explanation> */
2
- import { type DragEvent, useState } from 'react'
3
-
4
- export type StripItem = {
5
- id: string // 稳定唯一 id,用作 key
6
- url: string // 预览地址(blob URL / 远程地址)
7
- }
8
-
9
- type Props = {
10
- items: StripItem[]
11
- maxImages?: number
12
- onRemove: (id: string) => void
13
- onMove: (fromIndex: number, toIndex: number) => void
14
- onAddMore: () => void // 父组件负责触发 file input
15
- }
16
-
17
- export function ThumbnailStrip({
18
- items,
19
- maxImages = 9,
20
- onRemove,
21
- onMove,
22
- onAddMore,
23
- }: Props) {
24
- // 拖拽源索引;用 null 表示"无"
25
- const [dragSrc, setDragSrc] = useState<number | null>(null)
26
- // 当前悬停的目标索引,用于高亮
27
- const [dropTarget, setDropTarget] = useState<number | null>(null)
28
-
29
- const handleDragStart = (e: DragEvent<HTMLDivElement>, index: number) => {
30
- setDragSrc(index)
31
- e.dataTransfer.effectAllowed = 'move'
32
- try {
33
- e.dataTransfer.setData('text/plain', String(index))
34
- } catch {
35
- /* 某些浏览器/环境不支持,忽略 */
36
- }
37
- }
38
-
39
- const handleDragEnd = () => {
40
- setDragSrc(null)
41
- setDropTarget(null)
42
- }
43
-
44
- const handleDragOver = (e: DragEvent<HTMLDivElement>, index: number) => {
45
- e.preventDefault()
46
- e.dataTransfer.dropEffect = 'move'
47
- if (dragSrc !== null && dragSrc !== index) {
48
- setDropTarget(index)
49
- }
50
- }
51
-
52
- const handleDragLeave = (index: number) => {
53
- // 只在离开的是当前目标时清除,避免子元素冒泡误清
54
- setDropTarget((cur) => (cur === index ? null : cur))
55
- }
56
-
57
- const handleDrop = (e: DragEvent<HTMLDivElement>, index: number) => {
58
- e.preventDefault()
59
- setDropTarget(null)
60
- if (dragSrc === null || dragSrc === index) return
61
- onMove(dragSrc, index)
62
- setDragSrc(null)
63
- }
64
-
65
- const canAddMore = items.length > 0 && items.length < maxImages
66
-
67
- return (
68
- <div className="strip">
69
- {items.map((item, i) => {
70
- const isDragging = dragSrc === i
71
- const isDropTarget = dropTarget === i
72
-
73
- const className = [
74
- 'thumb',
75
- isDragging && 'dragging',
76
- isDropTarget && 'drop-target',
77
- ]
78
- .filter(Boolean)
79
- .join(' ')
80
-
81
- return (
82
- <div
83
- key={item.id}
84
- className={className}
85
- draggable
86
- data-index={i}
87
- onDragStart={(e) => handleDragStart(e, i)}
88
- onDragEnd={handleDragEnd}
89
- onDragOver={(e) => handleDragOver(e, i)}
90
- onDragLeave={() => handleDragLeave(i)}
91
- onDrop={(e) => handleDrop(e, i)}
92
- >
93
- <img src={item.url} alt={`图片 ${i + 1}`} />
94
-
95
- <span className="idx">{i + 1}</span>
96
-
97
- <button
98
- type="button"
99
- className="remove"
100
- title="移除"
101
- onClick={(e) => {
102
- e.stopPropagation()
103
- onRemove(item.id)
104
- }}
105
- >
106
- ×
107
- </button>
108
-
109
- <div className="move">
110
- <button
111
- type="button"
112
- title="左移"
113
- onClick={(e) => {
114
- e.stopPropagation()
115
- onMove(i, i - 1)
116
- }}
117
- >
118
- ←
119
- </button>
120
- <button
121
- type="button"
122
- title="右移"
123
- onClick={(e) => {
124
- e.stopPropagation()
125
- onMove(i, i + 1)
126
- }}
127
- >
128
- →
129
- </button>
130
- </div>
131
- </div>
132
- )
133
- })}
134
-
135
- {canAddMore && (
136
- <button
137
- type="button"
138
- className="thumb add-more"
139
- title="继续添加图片"
140
- onClick={onAddMore}
141
- >
142
- +
143
- </button>
144
- )}
145
- </div>
146
- )
147
- }
@@ -1,5 +0,0 @@
1
- export function VerticalSeparator() {
2
- return (
3
- <span className="vertical-separator w-0.5 bg-gray-300 inline-block h-[1.2em]"></span>
4
- )
5
- }
@@ -1,23 +0,0 @@
1
- import { useCallback, useRef } from 'react'
2
-
3
- export function useToast() {
4
- const containerRef = useRef<HTMLDivElement>(null)
5
-
6
- const toast = (msg: string, ms = 2600) => {
7
- const container = containerRef.current
8
- if (!container) return
9
-
10
- const el = document.createElement('div')
11
- el.className = 'toast'
12
- el.textContent = msg
13
- container.appendChild(el)
14
-
15
- setTimeout(() => {
16
- el.style.transition = 'opacity .25s'
17
- el.style.opacity = '0'
18
- setTimeout(() => el.remove(), 260)
19
- }, ms)
20
- }
21
-
22
- return { containerRef, toast: useCallback(toast, []) }
23
- }
package/src/lib/config.ts DELETED
@@ -1,48 +0,0 @@
1
- const SCALE = 2
2
-
3
- export const config = {
4
- COVER_W: 900 * SCALE,
5
- COVER_H: 383 * SCALE,
6
- JPEG_QUALITY: 0.92,
7
-
8
- // COVER_W : 1440,
9
- // COVER_H : 720,
10
- GAP: 5, // gap in px,
11
- // BG_COLOR : 'white' // 图片间隙底色(深灰,白图上也清晰可见),
12
- get GAP_COLOR() {
13
- return config.PRESETS[0]
14
- }, // 图片间隙底色(深灰,白图上也清晰可见),
15
-
16
- PRESETS: [
17
- 'white',
18
- 'yellowgreen',
19
- '#6ff1a3',
20
- '#7a7c88',
21
- '#bfbfbf',
22
- '#c1cbcc',
23
- '#c6c9d8',
24
- '#d6d5da',
25
- '#f7d24f',
26
- '#fda036',
27
- '#c28f74',
28
- '#a48157',
29
- '#fac29f',
30
- '#815f39',
31
- ],
32
-
33
- // GAP_COLOR: '', // 图片间隙底色(深灰,白图上也清晰可见),
34
- // white
35
- // yellowgreen
36
- // #6ff1a3
37
- // #7a7c88
38
- // #bfbfbf
39
- // #c1cbcc
40
- // #c6c9d8
41
- // #d6d5da
42
- // #f7d24f
43
- // #fda036
44
- // #c28f74
45
- // #a48157
46
- // #fac29f
47
- // #815f39
48
- }
package/src/lib/draw.ts DELETED
@@ -1,78 +0,0 @@
1
- export type FitMode = 'cover' | 'contain'
2
-
3
- export type Cell = {
4
- x: number
5
- y: number
6
- w: number
7
- h: number
8
- }
9
-
10
- export const drawImageToCell = (
11
- ctx: CanvasRenderingContext2D,
12
- img: HTMLImageElement,
13
- cell: Cell,
14
- scale: number,
15
- fitMode: FitMode,
16
- ) => {
17
- if (fitMode === 'contain') drawContain(ctx, img, cell, scale)
18
- else drawCover(ctx, img, cell, scale)
19
- }
20
-
21
- const drawContain: typeof drawCover = (ctx, img, cell, scale = 1) => {
22
- const cx = cell.x * scale,
23
- cy = cell.y * scale
24
- const cw = cell.w * scale,
25
- ch = cell.h * scale
26
- const iw = img.naturalWidth || img.width
27
- const ih = img.naturalHeight || img.height
28
- if (!iw || !ih) return
29
- const cellRatio = cw / ch,
30
- imgRatio = iw / ih
31
- let dw: number, dh: number
32
- if (imgRatio > cellRatio) {
33
- dw = cw
34
- dh = cw / imgRatio
35
- } else {
36
- dh = ch
37
- dw = ch * imgRatio
38
- }
39
- const dx = cx + (cw - dw) / 2
40
- const dy = cy + (ch - dh) / 2
41
- ctx.drawImage(img, 0, 0, iw, ih, dx, dy, dw, dh)
42
- }
43
-
44
- // ---------- Draw one image cover-cropped (center) into a rect on target ctx ----------
45
- function drawCover(
46
- targetCtx: CanvasRenderingContext2D,
47
- img: HTMLImageElement,
48
- cell: Cell,
49
- scale = 1,
50
- ): void {
51
- const cx = cell.x * scale,
52
- cy = cell.y * scale
53
- const cw = cell.w * scale,
54
- ch = cell.h * scale
55
-
56
- const iw = img.naturalWidth || img.width
57
- const ih = img.naturalHeight || img.height
58
- if (!iw || !ih) return
59
-
60
- const cellRatio = cw / ch
61
- const imgRatio = iw / ih
62
-
63
- let sx: number, sy: number, sw: number, sh: number
64
- if (imgRatio > cellRatio) {
65
- // image wider than cell → crop sides
66
- sh = ih
67
- sw = ih * cellRatio
68
- sx = (iw - sw) / 2
69
- sy = 0
70
- } else {
71
- // image taller than cell → crop top/bottom
72
- sw = iw
73
- sh = iw / cellRatio
74
- sx = 0
75
- sy = (ih - sh) / 2
76
- }
77
- targetCtx.drawImage(img, sx, sy, sw, sh, cx, cy, cw, ch)
78
- }
package/src/lib/file.ts DELETED
@@ -1,23 +0,0 @@
1
- export type ImageItem = { img: HTMLImageElement; url: string; id: string }
2
-
3
- // ---------- File intake ----------
4
- export function isImageFile(file: File) {
5
- // biome-ignore lint/complexity/useOptionalChain: <explanation>
6
- return file && file.type && file.type.startsWith('image/')
7
- }
8
-
9
- export async function loadImageFromFile(file: File): Promise<ImageItem> {
10
- return new Promise((resolve, reject) => {
11
- const url = URL.createObjectURL(file)
12
- const img = new Image()
13
-
14
- img.onload = () =>
15
- resolve({ img, url, id: `${file.name}_${Math.random()}` })
16
-
17
- img.onerror = () => {
18
- URL.revokeObjectURL(url)
19
- reject(new Error('decode failed'))
20
- }
21
- img.src = url
22
- })
23
- }
package/src/lib/utils.ts DELETED
@@ -1,7 +0,0 @@
1
- import type { ClassValue } from 'clsx'
2
- import { clsx } from 'clsx'
3
- import { twMerge } from 'tailwind-merge'
4
-
5
- export function cn(...inputs: ClassValue[]) {
6
- return twMerge(clsx(inputs))
7
- }
@@ -1,86 +0,0 @@
1
- /* eslint-disable */
2
-
3
- // @ts-nocheck
4
-
5
- // noinspection JSUnusedGlobalSymbols
6
-
7
- // This file was automatically generated by TanStack Router.
8
- // You should NOT make any changes in this file as it will be overwritten.
9
- // Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified.
10
-
11
- import { Route as rootRouteImport } from './routes/__root'
12
- import { Route as IndexRouteImport } from './routes/index'
13
- import { Route as AboutRouteImport } from './routes/about'
14
-
15
- const IndexRoute = IndexRouteImport.update({
16
- id: '/',
17
- path: '/',
18
- getParentRoute: () => rootRouteImport,
19
- } as any)
20
- const AboutRoute = AboutRouteImport.update({
21
- id: '/about',
22
- path: '/about',
23
- getParentRoute: () => rootRouteImport,
24
- } as any)
25
-
26
- export interface FileRoutesByFullPath {
27
- '/': typeof IndexRoute
28
- '/about': typeof AboutRoute
29
- }
30
- export interface FileRoutesByTo {
31
- '/': typeof IndexRoute
32
- '/about': typeof AboutRoute
33
- }
34
- export interface FileRoutesById {
35
- __root__: typeof rootRouteImport
36
- '/': typeof IndexRoute
37
- '/about': typeof AboutRoute
38
- }
39
- export interface FileRouteTypes {
40
- fileRoutesByFullPath: FileRoutesByFullPath
41
- fullPaths: '/' | '/about'
42
- fileRoutesByTo: FileRoutesByTo
43
- to: '/' | '/about'
44
- id: '__root__' | '/' | '/about'
45
- fileRoutesById: FileRoutesById
46
- }
47
- export interface RootRouteChildren {
48
- IndexRoute: typeof IndexRoute
49
- AboutRoute: typeof AboutRoute
50
- }
51
-
52
- declare module '@tanstack/react-router' {
53
- interface FileRoutesByPath {
54
- '/': {
55
- id: '/'
56
- path: '/'
57
- fullPath: '/'
58
- preLoaderRoute: typeof IndexRouteImport
59
- parentRoute: typeof rootRouteImport
60
- }
61
- '/about': {
62
- id: '/about'
63
- path: '/about'
64
- fullPath: '/about'
65
- preLoaderRoute: typeof AboutRouteImport
66
- parentRoute: typeof rootRouteImport
67
- }
68
- }
69
- }
70
-
71
- const rootRouteChildren: RootRouteChildren = {
72
- IndexRoute: IndexRoute,
73
- AboutRoute: AboutRoute,
74
- }
75
- export const routeTree = rootRouteImport
76
- ._addFileChildren(rootRouteChildren)
77
- ._addFileTypes<FileRouteTypes>()
78
-
79
- import type { getRouter } from './router.tsx'
80
- import type { createStart } from '@tanstack/react-start'
81
- declare module '@tanstack/react-start' {
82
- interface Register {
83
- ssr: true
84
- router: Awaited<ReturnType<typeof getRouter>>
85
- }
86
- }
package/src/router.tsx DELETED
@@ -1,19 +0,0 @@
1
- import { createRouter as createTanStackRouter } from '@tanstack/react-router'
2
- import { routeTree } from './routeTree.gen'
3
-
4
- export function getRouter() {
5
- const router = createTanStackRouter({
6
- routeTree,
7
- scrollRestoration: true,
8
- defaultPreload: 'intent',
9
- defaultPreloadStaleTime: 0,
10
- })
11
-
12
- return router
13
- }
14
-
15
- declare module '@tanstack/react-router' {
16
- interface Register {
17
- router: ReturnType<typeof getRouter>
18
- }
19
- }
@@ -1,68 +0,0 @@
1
- import { TanStackDevtools } from '@tanstack/react-devtools'
2
- import { createRootRoute, HeadContent, Scripts } from '@tanstack/react-router'
3
- import { TanStackRouterDevtoolsPanel } from '@tanstack/react-router-devtools'
4
- import Footer from '../components/Footer'
5
- import Header from '../components/Header'
6
-
7
- import appCss from '../styles.css?url'
8
-
9
- const THEME_INIT_SCRIPT = `(function(){try{var stored=window.localStorage.getItem('theme');var mode=(stored==='light'||stored==='dark'||stored==='auto')?stored:'auto';var prefersDark=window.matchMedia('(prefers-color-scheme: dark)').matches;var resolved=mode==='auto'?(prefersDark?'dark':'light'):mode;var root=document.documentElement;root.classList.remove('light','dark');root.classList.add(resolved);if(mode==='auto'){root.removeAttribute('data-theme')}else{root.setAttribute('data-theme',mode)}root.style.colorScheme=resolved;}catch(e){}})();`
10
-
11
- export const Route = createRootRoute({
12
- head: () => ({
13
- meta: [
14
- {
15
- charSet: 'utf-8',
16
- },
17
- {
18
- name: 'viewport',
19
- content: 'width=device-width, initial-scale=1',
20
- },
21
- {
22
- title: 'TanStack Start Starter',
23
- },
24
- ],
25
- // scripts: [
26
- // {
27
- // src: '/foo.js',
28
- // // defer: true, // optional
29
- // },
30
- // ],
31
- links: [
32
- {
33
- rel: 'stylesheet',
34
- href: appCss,
35
- },
36
- ],
37
- }),
38
- shellComponent: RootDocument,
39
- })
40
-
41
- function RootDocument({ children }: { children: React.ReactNode }) {
42
- return (
43
- <html lang="en" suppressHydrationWarning>
44
- <head>
45
- <script dangerouslySetInnerHTML={{ __html: THEME_INIT_SCRIPT }} />
46
- <HeadContent />
47
- </head>
48
- <body className="font-sans antialiased [overflow-wrap:anywhere] selection:bg-[rgba(79,184,178,0.24)]">
49
- <Header />
50
- {children}
51
- <Footer />
52
- <TanStackDevtools
53
- config={{
54
- inspectHotkey: ['Alt', 'CtrlOrMeta'],
55
- position: 'bottom-right',
56
- }}
57
- plugins={[
58
- {
59
- name: 'Tanstack Router',
60
- render: <TanStackRouterDevtoolsPanel />,
61
- },
62
- ]}
63
- />
64
- <Scripts />
65
- </body>
66
- </html>
67
- )
68
- }
@@ -1,23 +0,0 @@
1
- import { createFileRoute } from '@tanstack/react-router'
2
-
3
- export const Route = createFileRoute('/about')({
4
- component: About,
5
- })
6
-
7
- function About() {
8
- return (
9
- <main className="page-wrap px-4 py-12">
10
- <section className="island-shell rounded-2xl p-6 sm:p-8">
11
- <p className="island-kicker mb-2">About</p>
12
- <h1 className="display-title mb-3 text-4xl font-bold text-[var(--sea-ink)] sm:text-5xl">
13
- A small starter with room to grow.
14
- </h1>
15
- <p className="m-0 max-w-3xl text-base leading-8 text-[var(--sea-ink-soft)]">
16
- TanStack Start gives you type-safe routing, server functions, and
17
- modern SSR defaults. Use this as a clean foundation, then layer in
18
- your own routes, styling, and add-ons.
19
- </p>
20
- </section>
21
- </main>
22
- )
23
- }