poon-choi 0.0.3 → 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 +8 -0
- package/README.zh.md +8 -0
- package/bin/{index.ts → cli.ts} +6 -2
- package/package.json +12 -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/src/routes/index.tsx
DELETED
|
@@ -1,511 +0,0 @@
|
|
|
1
|
-
/** biome-ignore-all lint/a11y/noSvgWithoutTitle: <explanation> */
|
|
2
|
-
/** biome-ignore-all lint/suspicious/useIterableCallbackReturn: <explanation> */
|
|
3
|
-
/** biome-ignore-all lint/a11y/noStaticElementInteractions: <explanation> */
|
|
4
|
-
/** biome-ignore-all lint/a11y/useKeyWithClickEvents: <explanation> */
|
|
5
|
-
/** biome-ignore-all lint/complexity/useOptionalChain: <explanation> */
|
|
6
|
-
/** biome-ignore-all lint/a11y/useButtonType: <explanation> */
|
|
7
|
-
import { createFileRoute } from '@tanstack/react-router'
|
|
8
|
-
import { useCallback, useEffect, useRef, useState } from 'react'
|
|
9
|
-
import { DropStage } from '#/components/DropStage'
|
|
10
|
-
import { FitModeToggle } from '#/components/FitModeToggle'
|
|
11
|
-
import { GapColorPicker } from '#/components/GapColorPicker'
|
|
12
|
-
import { ThumbnailStrip } from '#/components/ThumbnailStrip'
|
|
13
|
-
import { useToast } from '#/hooks/useToast'
|
|
14
|
-
import { type Cell, drawImageToCell, type FitMode } from '#/lib/draw'
|
|
15
|
-
import { type ImageItem, isImageFile, loadImageFromFile } from '#/lib/file'
|
|
16
|
-
|
|
17
|
-
import './index.css'
|
|
18
|
-
import { VerticalSeparator } from '#/components/VerticalSeparator'
|
|
19
|
-
import { config } from '#/lib/config'
|
|
20
|
-
|
|
21
|
-
export const Route = createFileRoute('/')({
|
|
22
|
-
component: App,
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
const { COVER_W, COVER_H, GAP, GAP_COLOR: BG_COLOR, JPEG_QUALITY } = config
|
|
26
|
-
|
|
27
|
-
function App() {
|
|
28
|
-
// ---------- Constants ----------
|
|
29
|
-
|
|
30
|
-
const THUMB_SIZE = 383
|
|
31
|
-
const MAX_IMAGES = 6
|
|
32
|
-
// const BG_COLOR = '#ffffff'
|
|
33
|
-
|
|
34
|
-
// console.log('I am here!')
|
|
35
|
-
|
|
36
|
-
// ---------- State ----------
|
|
37
|
-
const [items, setItems] = useState<ImageItem[]>([])
|
|
38
|
-
const [gapColor, setGapColor] = useState<string>(BG_COLOR)
|
|
39
|
-
const [fitMode, setFitMode] = useState<FitMode>('cover')
|
|
40
|
-
|
|
41
|
-
// let dragSrcIndex = -1
|
|
42
|
-
|
|
43
|
-
// ---------- DOM ----------
|
|
44
|
-
// const stage = document.getElementById('stage')
|
|
45
|
-
// const canvas = document.getElementById('preview')
|
|
46
|
-
const previewRef = useRef<HTMLCanvasElement>(null)
|
|
47
|
-
|
|
48
|
-
// const dropzone = document.getElementById('dropzone')
|
|
49
|
-
// const strip = document.getElementById('strip')
|
|
50
|
-
// const fileInput = document.getElementById('fileInput')
|
|
51
|
-
const fileInputRef = useRef<HTMLInputElement>(null)
|
|
52
|
-
// const fileInput = fileInputRef.current
|
|
53
|
-
|
|
54
|
-
// const dlCover = document.getElementById('dlCover')
|
|
55
|
-
// const dlThumb = document.getElementById('dlThumb')
|
|
56
|
-
// const clearAll = document.getElementById('clearAll')
|
|
57
|
-
// const toasts = document.getElementById('toasts')
|
|
58
|
-
|
|
59
|
-
// canvas.addEventListener('click', () => {
|
|
60
|
-
// if (items.length > 0 && items.length < MAX_IMAGES) fileInput.click()
|
|
61
|
-
// })
|
|
62
|
-
|
|
63
|
-
// ---------- Toast ----------
|
|
64
|
-
const { containerRef, toast } = useToast()
|
|
65
|
-
|
|
66
|
-
// ---------- Preview canvas sizing (DPR-aware) ----------
|
|
67
|
-
// function sizePreviewCanvas() {
|
|
68
|
-
// const dpr = window.devicePixelRatio || 1
|
|
69
|
-
// const rect = canvas.getBoundingClientRect()
|
|
70
|
-
// const cssW = rect.width || COVER_W
|
|
71
|
-
// const cssH = rect.height || COVER_H
|
|
72
|
-
// canvas.width = Math.round(cssW * dpr)
|
|
73
|
-
// canvas.height = Math.round(cssH * dpr)
|
|
74
|
-
// }
|
|
75
|
-
|
|
76
|
-
// ---------- Render the composed cover onto a given ctx at a given size ----------
|
|
77
|
-
const composeOnto = useCallback(
|
|
78
|
-
(targetCtx: CanvasRenderingContext2D, targetW: number, targetH: number) => {
|
|
79
|
-
const scale = targetW / COVER_W
|
|
80
|
-
// console.log('COVER_W:', COVER_W)
|
|
81
|
-
targetCtx.fillStyle = gapColor
|
|
82
|
-
targetCtx.fillRect(0, 0, targetW, targetH)
|
|
83
|
-
|
|
84
|
-
if (items.length === 0) return
|
|
85
|
-
|
|
86
|
-
const cells = getCells(items.length)
|
|
87
|
-
for (let i = 0; i < items.length; i++) {
|
|
88
|
-
drawImageToCell(targetCtx, items[i].img, cells[i], scale, fitMode)
|
|
89
|
-
}
|
|
90
|
-
},
|
|
91
|
-
[items, gapColor, fitMode],
|
|
92
|
-
)
|
|
93
|
-
|
|
94
|
-
// ---------- Mutations ----------
|
|
95
|
-
const handleMove = (from: number, to: number) => {
|
|
96
|
-
setItems((prev) => {
|
|
97
|
-
if (to < 0 || to >= prev.length) return prev // 边界直接忽略
|
|
98
|
-
const next = [...prev]
|
|
99
|
-
const [moved] = next.splice(from, 1)
|
|
100
|
-
next.splice(to, 0, moved)
|
|
101
|
-
return next
|
|
102
|
-
})
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
const handleRemove = (id: string) => {
|
|
106
|
-
setItems((prev) => {
|
|
107
|
-
const target = prev.find((x) => x.id === id)
|
|
108
|
-
if (target) URL.revokeObjectURL(target.url)
|
|
109
|
-
return prev.filter((x) => x.id !== id)
|
|
110
|
-
})
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
function handleClearAllClick() {
|
|
114
|
-
items.forEach((it) => {
|
|
115
|
-
URL.revokeObjectURL(it.url)
|
|
116
|
-
})
|
|
117
|
-
setItems([])
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
const addFiles = useCallback(
|
|
121
|
-
async (files: File[] | null) => {
|
|
122
|
-
// const files = Array.from(fileList || [])
|
|
123
|
-
if (!files || files.length === 0) return
|
|
124
|
-
|
|
125
|
-
// Determine capacity
|
|
126
|
-
const room = MAX_IMAGES - items.length
|
|
127
|
-
if (room <= 0) {
|
|
128
|
-
toast(`最多 ${MAX_IMAGES} 张,已忽略 ${files.length} 张`)
|
|
129
|
-
return
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// Filter to images first
|
|
133
|
-
const imageFiles = files.filter(isImageFile)
|
|
134
|
-
const nonImageCount = files.length - imageFiles.length
|
|
135
|
-
if (nonImageCount > 0) {
|
|
136
|
-
toast(`已跳过 ${nonImageCount} 个非图片文件`)
|
|
137
|
-
}
|
|
138
|
-
if (imageFiles.length === 0) return
|
|
139
|
-
|
|
140
|
-
// Enforce cap
|
|
141
|
-
let toLoad = imageFiles
|
|
142
|
-
let overflow = 0
|
|
143
|
-
if (imageFiles.length > room) {
|
|
144
|
-
toLoad = imageFiles.slice(0, room)
|
|
145
|
-
overflow = imageFiles.length - room
|
|
146
|
-
}
|
|
147
|
-
if (overflow > 0) {
|
|
148
|
-
toast(`最多 ${MAX_IMAGES} 张,已忽略 ${overflow} 张`)
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
// Show spinner-ish state via toast? Keep it simple: load with brief cursor wait.
|
|
152
|
-
const prevCursor = document.body.style.cursor
|
|
153
|
-
document.body.style.cursor = 'progress'
|
|
154
|
-
|
|
155
|
-
// Decode sequentially to preserve drop order and avoid blocking
|
|
156
|
-
const loaded: ImageItem[] = []
|
|
157
|
-
for (const f of toLoad) {
|
|
158
|
-
try {
|
|
159
|
-
loaded.push(await loadImageFromFile(f))
|
|
160
|
-
} catch (_) {
|
|
161
|
-
toast(`无法读取图片:${f.name || '未命名'}`)
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
document.body.style.cursor = prevCursor
|
|
165
|
-
|
|
166
|
-
if (loaded.length === 0) return
|
|
167
|
-
setItems((items) => items.concat(loaded))
|
|
168
|
-
},
|
|
169
|
-
[toast, items.length],
|
|
170
|
-
)
|
|
171
|
-
|
|
172
|
-
// ---------- Export helpers ----------
|
|
173
|
-
function makeExportCanvas() {
|
|
174
|
-
const c = document.createElement('canvas')
|
|
175
|
-
c.width = COVER_W
|
|
176
|
-
c.height = COVER_H
|
|
177
|
-
const cx = c.getContext('2d')
|
|
178
|
-
|
|
179
|
-
if (!cx) throw new Error('no canvas context')
|
|
180
|
-
|
|
181
|
-
composeOnto(cx, COVER_W, COVER_H)
|
|
182
|
-
return c
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
function makeThumbCanvas() {
|
|
186
|
-
const cover = makeExportCanvas()
|
|
187
|
-
const c = document.createElement('canvas')
|
|
188
|
-
c.width = THUMB_SIZE
|
|
189
|
-
c.height = THUMB_SIZE
|
|
190
|
-
const cx = c.getContext('2d')
|
|
191
|
-
if (!cx) throw new Error('no canvas context')
|
|
192
|
-
cx.fillStyle = gapColor
|
|
193
|
-
cx.fillRect(0, 0, THUMB_SIZE, THUMB_SIZE)
|
|
194
|
-
// Center-crop the cover: take THUMB_SIZE x THUMB_SIZE window centered.
|
|
195
|
-
const sx = (COVER_W - THUMB_SIZE) / 2
|
|
196
|
-
const sy = (COVER_H - THUMB_SIZE) / 2
|
|
197
|
-
cx.drawImage(
|
|
198
|
-
cover,
|
|
199
|
-
sx,
|
|
200
|
-
sy,
|
|
201
|
-
THUMB_SIZE,
|
|
202
|
-
THUMB_SIZE,
|
|
203
|
-
0,
|
|
204
|
-
0,
|
|
205
|
-
THUMB_SIZE,
|
|
206
|
-
THUMB_SIZE,
|
|
207
|
-
)
|
|
208
|
-
return c
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
function downloadCanvas(c: HTMLCanvasElement, filename: string) {
|
|
212
|
-
console.log('JPEG_QUALITY:', JPEG_QUALITY)
|
|
213
|
-
c.toBlob(
|
|
214
|
-
(blob) => {
|
|
215
|
-
if (!blob) {
|
|
216
|
-
toast('导出失败')
|
|
217
|
-
return
|
|
218
|
-
}
|
|
219
|
-
const a = document.createElement('a')
|
|
220
|
-
a.href = URL.createObjectURL(blob)
|
|
221
|
-
a.download = filename
|
|
222
|
-
document.body.appendChild(a)
|
|
223
|
-
a.click()
|
|
224
|
-
a.remove()
|
|
225
|
-
setTimeout(() => URL.revokeObjectURL(a.href), 2000)
|
|
226
|
-
},
|
|
227
|
-
'image/jpeg',
|
|
228
|
-
JPEG_QUALITY,
|
|
229
|
-
)
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
// ---------- Event wiring ----------
|
|
233
|
-
const [fileInputValue, setFileInputValue] = useState('')
|
|
234
|
-
// @ts-expect-error
|
|
235
|
-
const handleDropzoneClick = () => fileInputRef.current.click()
|
|
236
|
-
const onFileInputChange = (
|
|
237
|
-
e: React.ChangeEvent<HTMLInputElement, HTMLInputElement>,
|
|
238
|
-
) => {
|
|
239
|
-
addFiles(Array.from(e.target.files || []))
|
|
240
|
-
// fileInput.value = '' // allow re-selecting same file
|
|
241
|
-
setFileInputValue('')
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
// Whole-page drag & drop (so dropping anywhere in the stage works)
|
|
245
|
-
// let dragDepth = 0
|
|
246
|
-
|
|
247
|
-
useEffect(() => {
|
|
248
|
-
const handler = (e: DragEvent) => {
|
|
249
|
-
if (
|
|
250
|
-
e.dataTransfer &&
|
|
251
|
-
Array.from(e.dataTransfer.types).includes('Files')
|
|
252
|
-
) {
|
|
253
|
-
e.preventDefault()
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
const events = ['dragenter', 'dragover'] as const
|
|
258
|
-
events.forEach((ev) => window.addEventListener(ev, handler))
|
|
259
|
-
|
|
260
|
-
return () => {
|
|
261
|
-
events.forEach((ev) => window.removeEventListener(ev, handler))
|
|
262
|
-
}
|
|
263
|
-
}, [])
|
|
264
|
-
|
|
265
|
-
// Paste
|
|
266
|
-
useEffect(() => {
|
|
267
|
-
const handlePaste = (e: ClipboardEvent) => {
|
|
268
|
-
const itemsInClip = e.clipboardData && e.clipboardData.items
|
|
269
|
-
if (!itemsInClip) return
|
|
270
|
-
|
|
271
|
-
const files: File[] = []
|
|
272
|
-
for (const it of itemsInClip) {
|
|
273
|
-
if (it.kind === 'file') {
|
|
274
|
-
const f = it.getAsFile()
|
|
275
|
-
if (f) files.push(f)
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
if (files.length) {
|
|
280
|
-
e.preventDefault()
|
|
281
|
-
addFiles(files)
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
// console.log('window:', window)
|
|
286
|
-
|
|
287
|
-
window.addEventListener('paste', handlePaste)
|
|
288
|
-
return () => window.removeEventListener('paste', handlePaste)
|
|
289
|
-
}, [addFiles])
|
|
290
|
-
|
|
291
|
-
/**
|
|
292
|
-
*
|
|
293
|
-
* @returns {string}
|
|
294
|
-
* @example wechat_cover_yyyy_MM_dd_HH_mm_ss_ms.jpg'
|
|
295
|
-
*/
|
|
296
|
-
const genFilename = () => {
|
|
297
|
-
// wechat_cover_2026_10_30_10_21_15_678.jpg
|
|
298
|
-
const date = new Date()
|
|
299
|
-
return `wechat_cover_${date.getFullYear()}_${date.getMonth() + 1}_${date.getDate()}_${date.getHours()}_${date.getMinutes()}_${date.getSeconds()}_${date.getMilliseconds()}.jpg`
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
// Buttons
|
|
303
|
-
const handleDlCoverClick = () => {
|
|
304
|
-
if (!items.length) return
|
|
305
|
-
downloadCanvas(makeExportCanvas(), 'wechat-cover-900x383.jpg')
|
|
306
|
-
}
|
|
307
|
-
const handleDlThumbClick = () => {
|
|
308
|
-
if (!items.length) return
|
|
309
|
-
downloadCanvas(makeThumbCanvas(), 'wechat-cover-thumbnail-383x383.jpg')
|
|
310
|
-
}
|
|
311
|
-
// clearAll.addEventListener('click', clearAllItems)
|
|
312
|
-
|
|
313
|
-
// Resize → re-render at new DPR/size
|
|
314
|
-
// window.addEventListener('resize', () => {
|
|
315
|
-
// // Only re-render if we have images (or even empty state to keep crisp)
|
|
316
|
-
// render()
|
|
317
|
-
// })
|
|
318
|
-
|
|
319
|
-
// ---------- Init ----------
|
|
320
|
-
useEffect(() => {
|
|
321
|
-
const canvas = previewRef.current
|
|
322
|
-
if (!canvas) return
|
|
323
|
-
|
|
324
|
-
// console.log('canvas:', canvas)
|
|
325
|
-
const ctx = canvas.getContext('2d')
|
|
326
|
-
// 某些上下文如 webgl 未创建成功时也是 null
|
|
327
|
-
if (!ctx) return
|
|
328
|
-
|
|
329
|
-
// Ensure canvas has proper CSS size for DPR calc
|
|
330
|
-
const dpr = window.devicePixelRatio || 1
|
|
331
|
-
const cssW = canvas.clientWidth || COVER_W
|
|
332
|
-
const cssH = canvas.clientHeight || COVER_H
|
|
333
|
-
canvas.width = Math.round(cssW * dpr)
|
|
334
|
-
canvas.height = Math.round(cssH * dpr)
|
|
335
|
-
|
|
336
|
-
ctx.setTransform(1, 0, 0, 1, 0, 0)
|
|
337
|
-
ctx.clearRect(0, 0, canvas.width, canvas.height)
|
|
338
|
-
composeOnto(ctx, canvas.width, canvas.height)
|
|
339
|
-
|
|
340
|
-
// Toggle state classes
|
|
341
|
-
// stage.classList.toggle('has-image', items.length > 0)
|
|
342
|
-
// dlCover.disabled =
|
|
343
|
-
// dlThumb.disabled = items.length === 0
|
|
344
|
-
// clearAll.disabled = items.length === 0
|
|
345
|
-
}, [composeOnto]) // composeOnto 为何加入依赖数组,这其实是想要的行为:items 变了就该重绘
|
|
346
|
-
|
|
347
|
-
return (
|
|
348
|
-
<main className="page-wrap px-4 pb-8 pt-14 1">
|
|
349
|
-
<div className="wrap">
|
|
350
|
-
<h1>封面拼接工具</h1>
|
|
351
|
-
{/* <h1>微信公众号封面拼接工具</h1> */}
|
|
352
|
-
<p className="sub">
|
|
353
|
-
{/* 拖入 1–6 张图片,自动拼接为 2.35:1 公众号封面(900×383),并生成 1:1 */}
|
|
354
|
-
拖入 1–6 张图片,自动拼接为 <code>2.35:1</code> 封面(
|
|
355
|
-
<code>
|
|
356
|
-
{COVER_W}×{COVER_H}
|
|
357
|
-
</code>
|
|
358
|
-
),并生成 <code>1:1</code> 缩略图
|
|
359
|
-
</p>
|
|
360
|
-
|
|
361
|
-
<DropStage
|
|
362
|
-
items={items}
|
|
363
|
-
id="stage"
|
|
364
|
-
onFiles={(xs) => addFiles(Array.from(xs))}
|
|
365
|
-
>
|
|
366
|
-
<canvas ref={previewRef} id="preview"></canvas>
|
|
367
|
-
<div
|
|
368
|
-
className="dropzone"
|
|
369
|
-
id="dropzone"
|
|
370
|
-
onClick={() => handleDropzoneClick()}
|
|
371
|
-
>
|
|
372
|
-
<svg
|
|
373
|
-
viewBox="0 0 24 24"
|
|
374
|
-
fill="none"
|
|
375
|
-
stroke="currentColor"
|
|
376
|
-
strokeWidth="1.6"
|
|
377
|
-
>
|
|
378
|
-
<path
|
|
379
|
-
d="M12 16V4m0 0L8 8m4-4l4 4"
|
|
380
|
-
strokeLinecap="round"
|
|
381
|
-
strokeLinejoin="round"
|
|
382
|
-
/>
|
|
383
|
-
<path
|
|
384
|
-
d="M4 16v2a2 2 0 002 2h12a2 2 0 002-2v-2"
|
|
385
|
-
strokeLinecap="round"
|
|
386
|
-
/>
|
|
387
|
-
</svg>
|
|
388
|
-
<span className="hint">拖入图片</span>
|
|
389
|
-
<span className="subhint">或点击选择 · 支持粘贴 · 最多 6 张</span>
|
|
390
|
-
</div>
|
|
391
|
-
</DropStage>
|
|
392
|
-
|
|
393
|
-
<input
|
|
394
|
-
type="file"
|
|
395
|
-
id="fileInput"
|
|
396
|
-
ref={fileInputRef}
|
|
397
|
-
onChange={(event) => onFileInputChange(event)}
|
|
398
|
-
value={fileInputValue}
|
|
399
|
-
accept="image/*"
|
|
400
|
-
multiple
|
|
401
|
-
/>
|
|
402
|
-
|
|
403
|
-
<ThumbnailStrip
|
|
404
|
-
items={items}
|
|
405
|
-
maxImages={MAX_IMAGES}
|
|
406
|
-
onRemove={handleRemove}
|
|
407
|
-
onMove={handleMove}
|
|
408
|
-
onAddMore={() => fileInputRef.current?.click()}
|
|
409
|
-
/>
|
|
410
|
-
|
|
411
|
-
<div className="actions items-center">
|
|
412
|
-
<FitModeToggle value={fitMode} onChange={setFitMode} />
|
|
413
|
-
|
|
414
|
-
<VerticalSeparator />
|
|
415
|
-
|
|
416
|
-
<GapColorPicker
|
|
417
|
-
presetColors={config.PRESETS}
|
|
418
|
-
initialColor={BG_COLOR}
|
|
419
|
-
onChange={setGapColor}
|
|
420
|
-
/>
|
|
421
|
-
|
|
422
|
-
<VerticalSeparator />
|
|
423
|
-
|
|
424
|
-
<button
|
|
425
|
-
className="btn btn-primary"
|
|
426
|
-
id="dlCover"
|
|
427
|
-
disabled={items.length === 0}
|
|
428
|
-
onClick={handleDlCoverClick}
|
|
429
|
-
>
|
|
430
|
-
下载封面
|
|
431
|
-
</button>
|
|
432
|
-
<button
|
|
433
|
-
className="btn btn-secondary"
|
|
434
|
-
id="dlThumb"
|
|
435
|
-
disabled={items.length === 0}
|
|
436
|
-
onClick={handleDlThumbClick}
|
|
437
|
-
>
|
|
438
|
-
下载缩略图
|
|
439
|
-
</button>
|
|
440
|
-
<div className="spacer"></div>
|
|
441
|
-
<button
|
|
442
|
-
className="btn btn-secondary"
|
|
443
|
-
id="clearAll"
|
|
444
|
-
disabled={items.length === 0}
|
|
445
|
-
onClick={handleClearAllClick}
|
|
446
|
-
>
|
|
447
|
-
清空
|
|
448
|
-
</button>
|
|
449
|
-
</div>
|
|
450
|
-
</div>
|
|
451
|
-
|
|
452
|
-
<div id="toasts" ref={containerRef}></div>
|
|
453
|
-
</main>
|
|
454
|
-
)
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
// ---------- Layout: cell rects for n images ----------
|
|
458
|
-
// Returns array of {x,y,w,h} in cover coordinates, one per image (may be fewer
|
|
459
|
-
// than total cells when n is odd on a grid — e.g. 5 in 3×2 leaves one blank).
|
|
460
|
-
function getCells(n: number) {
|
|
461
|
-
const W = COVER_W,
|
|
462
|
-
H = COVER_H
|
|
463
|
-
|
|
464
|
-
// Build raw grid cells, then inset each by G/2 on shared edges.
|
|
465
|
-
// Outer edges are not inset (no outer margin).
|
|
466
|
-
let cols: number
|
|
467
|
-
let rows: number
|
|
468
|
-
let raw: (Cell & { col: number; row: number })[] = []
|
|
469
|
-
|
|
470
|
-
if (n <= 1) {
|
|
471
|
-
return [{ x: 0, y: 0, w: W, h: H }]
|
|
472
|
-
} else if (n === 2) {
|
|
473
|
-
cols = 2
|
|
474
|
-
rows = 1
|
|
475
|
-
} else if (n === 3) {
|
|
476
|
-
cols = 3
|
|
477
|
-
rows = 1
|
|
478
|
-
} else if (n === 4) {
|
|
479
|
-
cols = 2
|
|
480
|
-
rows = 2
|
|
481
|
-
} else {
|
|
482
|
-
cols = 3
|
|
483
|
-
rows = 2 // 5 or 6
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
// Raw equal cells
|
|
487
|
-
const cw = W / cols
|
|
488
|
-
const ch = H / rows
|
|
489
|
-
for (let r = 0; r < rows; r++) {
|
|
490
|
-
for (let c = 0; c < cols; c++) {
|
|
491
|
-
raw.push({ x: c * cw, y: r * ch, w: cw, h: ch, col: c, row: r })
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
// For 5 images, drop the last cell (bottom-right) — leave blank.
|
|
496
|
-
if (n === 5) raw = raw.slice(0, 5)
|
|
497
|
-
|
|
498
|
-
// Inset each cell by G/2 on edges shared with a neighbor.
|
|
499
|
-
return raw.map((cell) => {
|
|
500
|
-
const left = cell.col > 0 ? GAP / 2 : 0
|
|
501
|
-
const right = cell.col < cols - 1 ? GAP / 2 : 0
|
|
502
|
-
const top = cell.row > 0 ? GAP / 2 : 0
|
|
503
|
-
const bottom = cell.row < rows - 1 ? GAP / 2 : 0
|
|
504
|
-
return {
|
|
505
|
-
x: cell.x + left,
|
|
506
|
-
y: cell.y + top,
|
|
507
|
-
w: cell.w - left - right,
|
|
508
|
-
h: cell.h - top - bottom,
|
|
509
|
-
}
|
|
510
|
-
})
|
|
511
|
-
}
|