@yamatozhen/design_system 1.0.0

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 (87) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +101 -0
  3. package/package.json +49 -0
  4. package/scripts/postinstall.js +105 -0
  5. package/template/app/ClientNav.tsx +310 -0
  6. package/template/app/globals.css +167 -0
  7. package/template/app/layout.tsx +128 -0
  8. package/template/app/themes/dark-mc.css +51 -0
  9. package/template/app/themes/dark.css +51 -0
  10. package/template/app/themes/light-mc.css +51 -0
  11. package/template/app/themes/light.css +51 -0
  12. package/template/app/themes/theme.css +82 -0
  13. package/template/components/layout/Lightbox/LightboxCard.tsx +100 -0
  14. package/template/components/layout/Lightbox/LightboxGallery.module.css +249 -0
  15. package/template/components/layout/Lightbox/LightboxGallery.tsx +72 -0
  16. package/template/components/layout/Lightbox/LightboxGrid.tsx +186 -0
  17. package/template/components/layout/Lightbox/LightboxModal.module.css +395 -0
  18. package/template/components/layout/Lightbox/LightboxModal.tsx +500 -0
  19. package/template/components/layout/Lightbox/demo.tsx +412 -0
  20. package/template/components/layout/Lightbox/index.ts +30 -0
  21. package/template/components/layout/Lightbox/types.ts +113 -0
  22. package/template/components/layout/Lightbox/useLightboxFilters.ts +140 -0
  23. package/template/components/layout/accordion/Accordion.module.css +149 -0
  24. package/template/components/layout/accordion/Accordion.tsx +114 -0
  25. package/template/components/layout/button/Button.module.css +305 -0
  26. package/template/components/layout/button/ButtonGroup.tsx +503 -0
  27. package/template/components/layout/button/FAB.tsx +118 -0
  28. package/template/components/layout/button/button.tsx +128 -0
  29. package/template/components/layout/button/drop.module.css +229 -0
  30. package/template/components/layout/button/drop.tsx +516 -0
  31. package/template/components/layout/hero/v1/heroSlideshow.module.css +107 -0
  32. package/template/components/layout/hero/v1/heroSlideshow.tsx +233 -0
  33. package/template/components/layout/modals/accessibilityModal/AccessibilityModal.module.css +126 -0
  34. package/template/components/layout/modals/accessibilityModal/AccessibilityModal.tsx +290 -0
  35. package/template/components/layout/modals/alert/Alert.tsx +188 -0
  36. package/template/components/layout/navigation/MioCard.module.css +88 -0
  37. package/template/components/layout/navigation/MioCard.tsx +266 -0
  38. package/template/components/layout/navigation/Wrap.tsx +41 -0
  39. package/template/components/layout/navigation/nav/Nav.module.css +508 -0
  40. package/template/components/layout/navigation/nav/Nav.tsx +167 -0
  41. package/template/components/layout/navigation/nav/NavBar.tsx +419 -0
  42. package/template/components/layout/navigation/nav/NavContext.tsx +259 -0
  43. package/template/components/layout/navigation/nav/NavItem.tsx +173 -0
  44. package/template/components/layout/navigation/nav/NavNew.module.css +373 -0
  45. package/template/components/layout/navigation/nav/NavRail.tsx +315 -0
  46. package/template/components/layout/navigation/nav/NavSection.tsx +102 -0
  47. package/template/components/layout/navigation/nav/NavTab.tsx +25 -0
  48. package/template/components/layout/navigation/nav/navftb/NavFTB.module.css +252 -0
  49. package/template/components/layout/navigation/nav/navftb/NavFTB.tsx +399 -0
  50. package/template/components/layout/navigation/nav/navftb/useTabIndicator.ts +484 -0
  51. package/template/components/layout/navigation/nav/navheader/NavHeader.module.css +59 -0
  52. package/template/components/layout/navigation/nav/navheader/NavHeader.tsx +478 -0
  53. package/template/components/layout/pages/loadingScreen.tsx +102 -0
  54. package/template/components/layout/pages/maintenance/Maintenance.tsx +53 -0
  55. package/template/components/layout/pages/maintenance/maintenance.module.css +163 -0
  56. package/template/components/layout/switch/Switch.module.css +102 -0
  57. package/template/components/layout/switch/Switch.tsx +48 -0
  58. package/template/components/tools/Divider.tsx +11 -0
  59. package/template/components/tools/ProgressiveBlur.tsx +73 -0
  60. package/template/components/tools/ReduceMotionContext.tsx +5 -0
  61. package/template/components/tools/Sinewave.tsx +199 -0
  62. package/template/components/tools/SinewaveProgress.tsx +135 -0
  63. package/template/components/tools/badge/Badge.tsx +28 -0
  64. package/template/components/tools/flubber.d.ts +7 -0
  65. package/template/components/tools/icon/SocialIcons.tsx +88 -0
  66. package/template/components/tools/icon/icon.module.css +0 -0
  67. package/template/components/tools/icon/icon.tsx +125 -0
  68. package/template/components/tools/mobileViewProvider.tsx +58 -0
  69. package/template/components/tools/react-bits/ClickSpark.tsx +177 -0
  70. package/template/components/tools/react-bits/FadeContent.tsx +90 -0
  71. package/template/components/tools/react-bits/GlareHover.tsx +73 -0
  72. package/template/components/tools/react-bits/GradientText/GradientText.css +70 -0
  73. package/template/components/tools/react-bits/GradientText/GradientText.tsx +44 -0
  74. package/template/components/tools/react-bits/Magnet.tsx +118 -0
  75. package/template/components/tools/react-bits/Stepper/Stepper.css +134 -0
  76. package/template/components/tools/react-bits/Stepper/Stepper.tsx +412 -0
  77. package/template/components/tools/ripple/ripple.css +41 -0
  78. package/template/components/tools/ripple/ripple.tsx +53 -0
  79. package/template/components/tools/shape/ShapeLoader.tsx +101 -0
  80. package/template/components/tools/shape/ShapeMorph.tsx +190 -0
  81. package/template/components/tools/shape/ShapePaths.ts +116 -0
  82. package/template/components/tools/switch/Switch.module.css +102 -0
  83. package/template/components/tools/switch/Switch.tsx +48 -0
  84. package/template/components/tools/useBodyScrollLock.tsx +27 -0
  85. package/template/components/tools/useImageColor.ts +47 -0
  86. package/template/components/tools/useNavSheetDrag.tsx +196 -0
  87. package/template/public/fonts/material-symbols/MaterialSymbolsRounded-VariableFont_FILL,GRAD,opsz,wght.woff2 +0 -0
@@ -0,0 +1,412 @@
1
+ "use client";
2
+ import { useState } from "react";
3
+ import {
4
+ LightboxGrid,
5
+ LightboxModal,
6
+ orientationFromRatio,
7
+ useLightboxFilters,
8
+ type LightboxItem,
9
+ type LightboxSlide,
10
+ } from "./index";
11
+ import Button from "../button/button";
12
+ import Drop from "../button/drop";
13
+ import Divider from "@/components/tools/Divider";
14
+
15
+ /* -----------------------------------------------------------
16
+ Sample data — 24 items mirroring the HTML prototype
17
+ ----------------------------------------------------------- */
18
+
19
+ const slide = (
20
+ title?: string,
21
+ comment?: string,
22
+ isDefault?: boolean,
23
+ ): LightboxSlide => ({ title, comment, default: isDefault });
24
+
25
+ const item = (
26
+ id: string,
27
+ span: LightboxItem["span"],
28
+ ratio: string,
29
+ tags: string[],
30
+ date: string,
31
+ views: number,
32
+ relevance: number,
33
+ favorite: boolean,
34
+ title: string,
35
+ description: string,
36
+ author: string,
37
+ slides: LightboxSlide[],
38
+ ): LightboxItem => ({
39
+ id,
40
+ span,
41
+ ratio,
42
+ orient: orientationFromRatio(ratio),
43
+ tags,
44
+ date,
45
+ views,
46
+ relevance,
47
+ favorite,
48
+ title,
49
+ description,
50
+ author,
51
+ slides,
52
+ });
53
+
54
+ export const sampleItems: LightboxItem[] = [
55
+ // 01: Multi-slide Frog Project Test
56
+ item(
57
+ "01",
58
+ "2x2",
59
+ "1/1",
60
+ ["Animation", "Concept"],
61
+ "2026-06-23",
62
+ 5400,
63
+ 120,
64
+ true,
65
+ "The Frog Project",
66
+ "Multi-slide workflow test documenting style, composition changes, and animation cycles.",
67
+ "Yamato Zhen",
68
+ [
69
+ {
70
+ src: "/frog_final.jpg",
71
+ alt: "Final Render Illustration",
72
+ title: "Final Rendering",
73
+ comment: "Polished final piece with full material shading.",
74
+ default: true,
75
+ },
76
+ {
77
+ src: "/frog_sketch.jpg",
78
+ alt: "Initial Sketch Pass",
79
+ title: "Rough Concept Sketch",
80
+ comment: "Exploring basic silhouette weight and anatomy.",
81
+ },
82
+ {
83
+ src: "/frog.gif",
84
+ alt: "Motion Test GIF",
85
+ title: "Animation Loop Pass",
86
+ comment: "Checking bounce timing and secondary motion frames.",
87
+ },
88
+ ],
89
+ ),
90
+
91
+ // 02: Foreseen Yasuo
92
+ item(
93
+ "02",
94
+ "2x1",
95
+ "16/9",
96
+ ["Splash Art", "Digital"],
97
+ "2026-01-15",
98
+ 15000,
99
+ 340,
100
+ false,
101
+ "Foreseen Yasuo",
102
+ "Official promotional artwork exploration highlighting cinematic depth perspective.",
103
+ "Kudos Productions",
104
+ [
105
+ {
106
+ src: "/kudos-productions-foreseen-yasuo-02-susu.jpg",
107
+ alt: "Foreseen Yasuo Splash Cut",
108
+ title: "Official Cut",
109
+ default: true,
110
+ },
111
+ ],
112
+ ),
113
+
114
+ // 03: Prestige Pandemonium Shaco
115
+ item(
116
+ "03",
117
+ "1x2",
118
+ "9/16",
119
+ ["Splash Art", "Digital"],
120
+ "2026-04-12",
121
+ 12400,
122
+ 94,
123
+ true,
124
+ "Prestige Pandemonium Shaco",
125
+ "Character splash color exploration showcasing lighting rendering.",
126
+ "Kudos Productions",
127
+ [
128
+ {
129
+ src: "/kudos-productions-prestige-pandemonium-shaco-02-yuyu.jpg",
130
+ alt: "Prestige Shaco Cut",
131
+ title: "Published Cut",
132
+ default: true,
133
+ },
134
+ ],
135
+ ),
136
+
137
+ // 04: Terence Cantal Study 3
138
+ item(
139
+ "04",
140
+ "1x1",
141
+ "1/1",
142
+ ["Study", "Texture"],
143
+ "2026-03-22",
144
+ 3200,
145
+ 45,
146
+ false,
147
+ "Terence Cantal Study 3",
148
+ "Material rendering values and texture mapping research overlay.",
149
+ "Terence Cantal",
150
+ [
151
+ {
152
+ src: "/terence-cantal-3.jpg",
153
+ alt: "Material Surface Study",
154
+ title: "Surface Pass",
155
+ default: true,
156
+ },
157
+ ],
158
+ ),
159
+
160
+ // 05: Diana Composition
161
+ item(
162
+ "05",
163
+ "2x1",
164
+ "16/9",
165
+ ["Illustration", "Value Study"],
166
+ "2026-05-02",
167
+ 8900,
168
+ 112,
169
+ false,
170
+ "Diana Composition",
171
+ "Keyframe structural focus painting, manipulating ambient light conditions.",
172
+ "Terence Cantal",
173
+ [
174
+ {
175
+ src: "/terence-cantal-diana-final.jpg",
176
+ alt: "Diana Final Illustration",
177
+ title: "Master Production Render",
178
+ default: true,
179
+ },
180
+ ],
181
+ ),
182
+
183
+ // 06: Terence Cantal Final Composition
184
+ item(
185
+ "06",
186
+ "1x1",
187
+ "1/1",
188
+ ["Illustration", "Final"],
189
+ "2026-05-10",
190
+ 4100,
191
+ 78,
192
+ false,
193
+ "Terence Cantal Final Composition",
194
+ "WebP format asset delivery verification pipeline test.",
195
+ "Terence Cantal",
196
+ [
197
+ {
198
+ src: "/terence-cantal-final-copy.webp",
199
+ alt: "Optimized Final Presentation WebP",
200
+ title: "Compressed WebP Presentation",
201
+ default: true,
202
+ },
203
+ ],
204
+ ),
205
+ ];
206
+ const ALL_TAGS = [
207
+ "Splash Art",
208
+ "Sketch",
209
+ "Digital",
210
+ "Traditional",
211
+ "Concept",
212
+ "Study",
213
+ "Fan Art",
214
+ ];
215
+
216
+ /* -----------------------------------------------------------
217
+ Demo page — quick & dirty controls, throw away when done
218
+ ----------------------------------------------------------- */
219
+
220
+ export default function LightboxGalleryDemo() {
221
+ const [items, setItems] = useState<LightboxItem[]>(sampleItems);
222
+ const [openItem, setOpenItem] = useState<LightboxItem | null>(null);
223
+
224
+ const { state, actions, filteredItems } = useLightboxFilters(items);
225
+
226
+ const toggleFavorite = (target: LightboxItem) => {
227
+ setItems((prev) =>
228
+ prev.map((it) =>
229
+ it.id === target.id ? { ...it, favorite: !it.favorite } : it,
230
+ ),
231
+ );
232
+ setOpenItem((current) =>
233
+ current && current.id === target.id
234
+ ? { ...current, favorite: !current.favorite }
235
+ : current,
236
+ );
237
+ };
238
+
239
+ return (
240
+ <>
241
+ {/*<div style={controlsStyle}>
242
+ <span style={labelStyle}>Mode</span>
243
+ <button style={btn(state.mode === "bento")}>Bento</button>
244
+ <button style={btn(state.mode === "square")}>Square</button>
245
+ <button style={btn(state.mode === "aspect")}>Aspect</button>
246
+
247
+ <span style={{ ...labelStyle, marginLeft: 12 }}>Sort</span>
248
+ <select
249
+ value={state.sort}
250
+ onChange={(e) => actions.setSort(e.target.value as SortOption)}
251
+ style={selectStyle}
252
+ >
253
+ <option value="relevant">Most relevant</option>
254
+ <option value="recent">Most recent</option>
255
+ <option value="oldest">Oldest</option>
256
+ <option value="views">Most viewed</option>
257
+ </select>
258
+
259
+ <span style={{ ...labelStyle, marginLeft: 12 }}>Tags</span>
260
+ {ALL_TAGS.map((tag) => (
261
+ <button
262
+ key={tag}
263
+ onClick={() => actions.toggleTag(tag)}
264
+ style={btn(state.tags.has(tag))}
265
+ >
266
+ {tag}
267
+ </button>
268
+ ))}
269
+
270
+ <div style={{ flex: 1 }} />
271
+
272
+ <button onClick={actions.zoomOut} style={btn(false)} title="Zoom out">
273
+ −
274
+ </button>
275
+ <button onClick={actions.zoomIn} style={btn(false)} title="Zoom in">
276
+ +
277
+ </button>
278
+ <button style={btn(state.favoritesOnly)} title="Favorites only">
279
+ ♥
280
+ </button>
281
+ <button onClick={actions.resetFilters} style={btn(false)}>
282
+ Reset
283
+ </button>
284
+ <Button primary>
285
+ <Icon systemName="browse" label="Bento" />
286
+ </Button>
287
+ </div>*/}
288
+ <div
289
+ style={{
290
+ width: "100%",
291
+ maxWidth: 1080,
292
+ marginInline: "auto",
293
+ display: "flex",
294
+ flexWrap: "wrap",
295
+ justifyContent: "space-between",
296
+ alignItems: "center",
297
+ gap: 6,
298
+ }}
299
+ >
300
+ <div style={{ display: "flex", gap: 8 }}>
301
+ <Button.group exclusive secondary width={210}>
302
+ <Button.group.Tab
303
+ systemName="browse"
304
+ label={{ text: "Bento", hideWhenInactive: true }}
305
+ onClick={() => actions.setMode("bento")}
306
+ toggle
307
+ default
308
+ />
309
+ <Button.group.Tab
310
+ systemName="grid_view"
311
+ label={{ text: "Grid", hideWhenInactive: true }}
312
+ onClick={() => actions.setMode("square")}
313
+ toggle
314
+ />
315
+ <Button.group.Tab
316
+ systemName="fit_screen"
317
+ label={{ text: "Ratio", hideWhenInactive: true }}
318
+ onClick={() => actions.setMode("aspect")}
319
+ toggle
320
+ />
321
+ </Button.group>
322
+ <Drop.Menu
323
+ multiSelect
324
+ primary
325
+ systemName="filter_alt"
326
+ label="Filter by"
327
+ >
328
+ <Drop.Item
329
+ systemName="owl"
330
+ label="Study"
331
+ toggle
332
+ onClick={() => actions.toggleTag("Study")}
333
+ />
334
+ <Drop.Item
335
+ systemName="draw_abstract"
336
+ label="Concept"
337
+ onClick={() => actions.toggleTag("Concept")}
338
+ toggle
339
+ />
340
+ <Drop.Item
341
+ systemName="draw_collage"
342
+ label="Fan art"
343
+ onClick={() => actions.toggleTag("Fan Art")}
344
+ toggle
345
+ />
346
+ <Divider />
347
+ <Drop.Item systemName="style" label="Artwork Style">
348
+ <Divider />
349
+ <Drop.Item
350
+ label="Splash Art"
351
+ onClick={() => actions.toggleTag("Splash Art")}
352
+ toggle
353
+ />
354
+ <Drop.Item
355
+ label="Sketch"
356
+ onClick={() => actions.toggleTag("Sketch")}
357
+ toggle
358
+ />
359
+ <Drop.Item
360
+ label="Traditional"
361
+ onClick={() => actions.toggleTag("Traditonal")}
362
+ toggle
363
+ />
364
+ <Drop.Item
365
+ label="Digital"
366
+ onClick={() => actions.toggleTag("Digital")}
367
+ toggle
368
+ />
369
+ </Drop.Item>
370
+ <Divider />
371
+ <Drop.Item
372
+ label="Favorites"
373
+ systemName="favorite"
374
+ onClick={actions.toggleFavoritesOnly}
375
+ toggle
376
+ />
377
+ </Drop.Menu>
378
+ </div>
379
+ <Button.group
380
+ multiSelect
381
+ outlined
382
+ width={178}
383
+ cta={{
384
+ label: "Reset",
385
+ onClick: actions.resetFilters,
386
+ outlined: true,
387
+ circle: true,
388
+ }}
389
+ >
390
+ <Button.group.Tab
391
+ onClick={actions.zoomOut}
392
+ systemName="remove"
393
+ circle
394
+ />
395
+ <Button.group.Tab onClick={actions.zoomIn} systemName="add" circle />
396
+ </Button.group>
397
+ </div>
398
+
399
+ <LightboxGrid
400
+ items={filteredItems}
401
+ mode={state.mode}
402
+ zoom={state.zoom}
403
+ onCardClick={(it) => setOpenItem(it)}
404
+ />
405
+ <LightboxModal
406
+ item={openItem}
407
+ onClose={() => setOpenItem(null)}
408
+ onToggleFavorite={toggleFavorite}
409
+ />
410
+ </>
411
+ );
412
+ }
@@ -0,0 +1,30 @@
1
+ export { LightboxGallery } from "./LightboxGallery";
2
+ export type { LightboxGalleryProps } from "./LightboxGallery";
3
+
4
+ export { LightboxGrid } from "./LightboxGrid";
5
+ export type { LightboxGridProps } from "./LightboxGrid";
6
+
7
+ export { LightboxCard } from "./LightboxCard";
8
+ export type { LightboxCardProps } from "./LightboxCard";
9
+
10
+ export { LightboxModal } from "./LightboxModal";
11
+ export type { LightboxModalProps } from "./LightboxModal";
12
+
13
+ export {
14
+ useLightboxFilters,
15
+ type UseLightboxFiltersOptions,
16
+ } from "./useLightboxFilters";
17
+
18
+ export {
19
+ orientationFromRatio,
20
+ getDefaultSlide,
21
+ type ViewMode,
22
+ type SortOption,
23
+ type GridSpan,
24
+ type Orientation,
25
+ type LightboxSlide,
26
+ type LightboxItem,
27
+ type LightboxFilters,
28
+ type LightboxFiltersState,
29
+ type LightboxFiltersActions,
30
+ } from "./types";
@@ -0,0 +1,113 @@
1
+ export type ViewMode = "bento" | "square" | "aspect";
2
+
3
+ export type SortOption = "relevant" | "recent" | "oldest" | "views";
4
+
5
+ export type GridSpan = "1x1" | "2x1" | "1x2" | "2x2";
6
+
7
+ export type Orientation = "landscape" | "portrait" | "square";
8
+
9
+ /**
10
+ * A single image (or slide) inside a multi-image artwork. Shown stacked
11
+ * vertically in the LightboxModal.
12
+ */
13
+ export interface LightboxSlide {
14
+ /** Image source. Optional — when missing, a gray placeholder is rendered. */
15
+ src?: string;
16
+ alt?: string;
17
+ /** Per-slide title shown inline below the image and in the side panel. */
18
+ title?: string;
19
+ /** Per-slide comment shown inline below the image and in the side panel. */
20
+ comment?: string;
21
+ /** Marks this slide as the gallery thumbnail. The first match wins. */
22
+ default?: boolean;
23
+ }
24
+
25
+ export interface LightboxItem {
26
+ /** Stable unique id — used as React key and for FLIP rect tracking. */
27
+ id: string;
28
+ /** Grid span used in `bento` mode. */
29
+ span: GridSpan;
30
+ /** CSS aspect-ratio string used in `aspect` mode, e.g. `"16/9"`. */
31
+ ratio: string;
32
+ /** Derived from `ratio`. Drives layout in `aspect` mode. */
33
+ orient: Orientation;
34
+ tags: string[];
35
+ /** ISO date string. */
36
+ date: string;
37
+ views: number;
38
+ /** Optional sort weight (0–100). Used by the `"relevant"` sort. */
39
+ relevance: number;
40
+ favorite: boolean;
41
+ /** Optional image source; if omitted, the card renders as a gray placeholder. */
42
+ src?: string;
43
+ alt?: string;
44
+ title?: string;
45
+ /** Item-level description shown in the modal's side panel. */
46
+ description?: string;
47
+ /** Optional author / artist name shown in the modal. */
48
+ author?: string;
49
+ /** All images for this artwork. Gallery thumbnail uses the `default` slide. */
50
+ slides?: LightboxSlide[];
51
+ }
52
+
53
+ export interface LightboxFiltersState {
54
+ mode: ViewMode;
55
+ sort: SortOption;
56
+ tags: Set<string>;
57
+ favoritesOnly: boolean;
58
+ zoom: number;
59
+ }
60
+
61
+ export interface LightboxFiltersActions {
62
+ setMode: (mode: ViewMode) => void;
63
+ setSort: (sort: SortOption) => void;
64
+ toggleTag: (tag: string) => void;
65
+ setTags: (tags: Iterable<string>) => void;
66
+ toggleFavoritesOnly: () => void;
67
+ setFavoritesOnly: (v: boolean) => void;
68
+ zoomIn: () => void;
69
+ zoomOut: () => void;
70
+ setZoom: (z: number) => void;
71
+ resetFilters: () => void;
72
+ }
73
+
74
+ export interface LightboxFilters {
75
+ state: LightboxFiltersState;
76
+ actions: LightboxFiltersActions;
77
+ filteredItems: LightboxItem[];
78
+ /** Increments on every `resetFilters()` call. Use as a React `key` on
79
+ * controlled UI (e.g. a toggle group) to force it to remount and clear
80
+ * its internal state when filters are reset. */
81
+ resetKey: number;
82
+ }
83
+
84
+ /**
85
+ * Pick the slide that should represent the item in the gallery.
86
+ * Returns the first slide flagged `default: true`, falling back to the
87
+ * first slide, or `undefined` when there are no slides.
88
+ */
89
+ export function getDefaultSlide(item: LightboxItem): LightboxSlide | undefined {
90
+ if (!item.slides?.length) return undefined;
91
+ return item.slides.find((s) => s.default) ?? item.slides[0];
92
+ }
93
+
94
+ /** Derive orientation from an aspect-ratio string like `"16/9"`. */
95
+ export function orientationFromRatio(ratio: string): Orientation {
96
+ const [a, b] = ratio.split("/").map(Number);
97
+ if (!a || !b) return "square";
98
+ if (a > b) return "landscape";
99
+ if (a < b) return "portrait";
100
+ return "square";
101
+ }
102
+
103
+ const ALL_TAGS = [
104
+ "Relevance",
105
+
106
+ "Splash Art",
107
+ "Sketch",
108
+ "Traditional",
109
+ "Digital",
110
+ "Concept",
111
+ "Study",
112
+ "Fan Art",
113
+ ];
@@ -0,0 +1,140 @@
1
+ "use client";
2
+
3
+ import { useCallback, useMemo, useState } from "react";
4
+ import type {
5
+ LightboxFilters,
6
+ LightboxFiltersActions,
7
+ LightboxFiltersState,
8
+ LightboxItem,
9
+ SortOption,
10
+ ViewMode,
11
+ } from "./types";
12
+
13
+ export interface UseLightboxFiltersOptions {
14
+ initialMode?: ViewMode;
15
+ initialSort?: SortOption;
16
+ initialTags?: Iterable<string>;
17
+ initialFavoritesOnly?: boolean;
18
+ initialZoom?: number;
19
+ zoomStep?: number;
20
+ zoomMin?: number;
21
+ zoomMax?: number;
22
+ /**
23
+ * Tag matching mode. `"any"` (default) shows items matching at least one
24
+ * selected tag. `"all"` requires items to match every selected tag.
25
+ */
26
+ tagMatch?: "any" | "all";
27
+ }
28
+
29
+ /**
30
+ * Filter/sort logic for the Lightbox gallery. Returns state, actions, and
31
+ * the items derived from applying the filters & sort.
32
+ *
33
+ * Wire the returned `actions` to your own buttons/tabs. Pass `filteredItems`
34
+ * + the relevant pieces of `state` to <LightboxGrid />.
35
+ */
36
+ export function useLightboxFilters(
37
+ items: LightboxItem[],
38
+ options: UseLightboxFiltersOptions = {},
39
+ ): LightboxFilters {
40
+ const {
41
+ initialMode = "bento",
42
+ initialSort = "relevant",
43
+ initialTags,
44
+ initialFavoritesOnly = false,
45
+ initialZoom = 160,
46
+ zoomStep = 30,
47
+ zoomMin = 100,
48
+ zoomMax = 320,
49
+ tagMatch = "any",
50
+ } = options;
51
+
52
+ const [mode, setMode] = useState<ViewMode>(initialMode);
53
+ const [sort, setSort] = useState<SortOption>(initialSort);
54
+ const [tags, setTagsInternal] = useState<Set<string>>(
55
+ () => new Set(initialTags ?? []),
56
+ );
57
+ const [favoritesOnly, setFavoritesOnly] = useState(initialFavoritesOnly);
58
+ const [zoom, setZoom] = useState(initialZoom);
59
+ const [resetKey, setResetKey] = useState(0);
60
+
61
+ const toggleTag = useCallback((tag: string) => {
62
+ setTagsInternal((prev) => {
63
+ const next = new Set(prev);
64
+ if (next.has(tag)) next.delete(tag);
65
+ else next.add(tag);
66
+ return next;
67
+ });
68
+ }, []);
69
+
70
+ const setTags = useCallback((next: Iterable<string>) => {
71
+ setTagsInternal(new Set(next));
72
+ }, []);
73
+
74
+ const toggleFavoritesOnly = useCallback(() => {
75
+ setFavoritesOnly((prev) => !prev);
76
+ }, []);
77
+
78
+ const zoomIn = useCallback(() => {
79
+ setZoom((z) => Math.min(z + zoomStep, zoomMax));
80
+ }, [zoomStep, zoomMax]);
81
+
82
+ const zoomOut = useCallback(() => {
83
+ setZoom((z) => Math.max(z - zoomStep, zoomMin));
84
+ }, [zoomStep, zoomMin]);
85
+
86
+ const resetFilters = useCallback(() => {
87
+ setTagsInternal(new Set());
88
+ setFavoritesOnly(false);
89
+ setResetKey((k) => k + 1);
90
+ }, []);
91
+
92
+ const filteredItems = useMemo(() => {
93
+ const filtered = items.filter((item) => {
94
+ const tagMatchOk =
95
+ tags.size === 0 ||
96
+ (tagMatch === "all"
97
+ ? Array.from(tags).every((t) => item.tags.includes(t))
98
+ : item.tags.some((t) => tags.has(t)));
99
+ const favOk = !favoritesOnly || item.favorite;
100
+ return tagMatchOk && favOk;
101
+ });
102
+
103
+ return filtered.sort((a, b) => {
104
+ switch (sort) {
105
+ case "recent":
106
+ return new Date(b.date).getTime() - new Date(a.date).getTime();
107
+ case "oldest":
108
+ return new Date(a.date).getTime() - new Date(b.date).getTime();
109
+ case "views":
110
+ return b.views - a.views;
111
+ case "relevant":
112
+ default:
113
+ return b.relevance - a.relevance;
114
+ }
115
+ });
116
+ }, [items, tags, favoritesOnly, sort, tagMatch]);
117
+
118
+ const state: LightboxFiltersState = {
119
+ mode,
120
+ sort,
121
+ tags,
122
+ favoritesOnly,
123
+ zoom,
124
+ };
125
+
126
+ const actions: LightboxFiltersActions = {
127
+ setMode,
128
+ setSort,
129
+ toggleTag,
130
+ setTags,
131
+ toggleFavoritesOnly,
132
+ setFavoritesOnly,
133
+ zoomIn,
134
+ zoomOut,
135
+ setZoom,
136
+ resetFilters,
137
+ };
138
+
139
+ return { state, actions, filteredItems, resetKey };
140
+ }