@reuse-sh/lightbox 0.0.0-stage → 0.0.1

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.
@@ -0,0 +1,9 @@
1
+ import { type ReactNode } from "react";
2
+ import { type Lightbox as LightboxController, type LightboxOptions, type LightboxState } from "./index.js";
3
+ export interface LightboxHandle extends LightboxController {
4
+ state: LightboxState;
5
+ }
6
+ export declare function useLightbox(options?: LightboxOptions): LightboxHandle;
7
+ export declare function Lightbox({ children, ...options }: LightboxOptions & {
8
+ children: (lightbox: LightboxHandle) => ReactNode;
9
+ }): ReactNode;
package/dist/react.js ADDED
@@ -0,0 +1,52 @@
1
+ "use client";
2
+ import { useEffect, useMemo, useRef, useState } from "react";
3
+ import { createLightbox, } from "./index.js";
4
+ export function useLightbox(options = {}) {
5
+ const optionsRef = useRef(options);
6
+ optionsRef.current = options;
7
+ const controller = useRef(null);
8
+ const [state, setState] = useState({
9
+ isOpen: false,
10
+ isClosing: false,
11
+ index: 0,
12
+ count: 0,
13
+ zoom: { scale: 1, x: 0, y: 0 },
14
+ });
15
+ const handle = useMemo(() => {
16
+ const ensure = () => {
17
+ if (!controller.current) {
18
+ controller.current = createLightbox({
19
+ ...optionsRef.current,
20
+ onChange: (next) => {
21
+ setState(next);
22
+ optionsRef.current.onChange?.(next);
23
+ },
24
+ });
25
+ }
26
+ return controller.current;
27
+ };
28
+ return {
29
+ open: (items, index) => ensure().open(items, index),
30
+ close: () => controller.current?.close() ?? Promise.resolve(),
31
+ next: () => controller.current?.next(),
32
+ prev: () => controller.current?.prev(),
33
+ goTo: (index) => controller.current?.goTo(index),
34
+ zoomTo: (scale, focus) => controller.current?.zoomTo(scale, focus),
35
+ toggleZoom: (focus) => controller.current?.toggleZoom(focus),
36
+ getState: () => ensure().getState(),
37
+ subscribe: (listener) => ensure().subscribe(listener),
38
+ destroy: () => {
39
+ controller.current?.destroy();
40
+ controller.current = null;
41
+ },
42
+ };
43
+ }, []);
44
+ useEffect(() => () => {
45
+ controller.current?.destroy();
46
+ controller.current = null;
47
+ }, []);
48
+ return { ...handle, state };
49
+ }
50
+ export function Lightbox({ children, ...options }) {
51
+ return children(useLightbox(options));
52
+ }
@@ -0,0 +1,218 @@
1
+ .reuse-lightbox {
2
+ --reuse-lightbox-background: rgb(15 15 17 / 96%);
3
+ --reuse-lightbox-foreground: #fff;
4
+ --reuse-lightbox-control: rgb(35 35 38 / 96%);
5
+ position: fixed;
6
+ inset: 0;
7
+ width: 100%;
8
+ max-width: none;
9
+ height: 100%;
10
+ max-height: none;
11
+ margin: 0;
12
+ padding: 0;
13
+ overflow: hidden;
14
+ border: 0;
15
+ background: transparent;
16
+ color: var(--reuse-lightbox-foreground);
17
+ overscroll-behavior: contain;
18
+ font-family: inherit;
19
+ }
20
+ .reuse-lightbox::backdrop {
21
+ background: transparent;
22
+ }
23
+ .reuse-lightbox-backdrop {
24
+ position: absolute;
25
+ inset: 0;
26
+ background: var(--reuse-lightbox-background);
27
+ pointer-events: none;
28
+ }
29
+ .reuse-lightbox-viewport {
30
+ position: relative;
31
+ display: flex;
32
+ width: 100%;
33
+ height: 100%;
34
+ overflow-x: auto;
35
+ overflow-y: hidden;
36
+ scroll-snap-type: x mandatory;
37
+ overscroll-behavior: contain;
38
+ scrollbar-width: none;
39
+ touch-action: pan-x;
40
+ outline-offset: -4px;
41
+ }
42
+ .reuse-lightbox-viewport::-webkit-scrollbar {
43
+ display: none;
44
+ }
45
+ .reuse-lightbox-slide {
46
+ position: relative;
47
+ display: grid;
48
+ flex: 0 0 100%;
49
+ width: 100%;
50
+ height: 100%;
51
+ place-items: center;
52
+ scroll-snap-align: start;
53
+ scroll-snap-stop: always;
54
+ overflow: hidden;
55
+ }
56
+ .reuse-lightbox-frame {
57
+ position: relative;
58
+ flex: none;
59
+ transform-origin: center;
60
+ cursor: zoom-in;
61
+ }
62
+ .reuse-lightbox[data-zoomed="true"] .reuse-lightbox-frame {
63
+ cursor: grab;
64
+ }
65
+ .reuse-lightbox[data-zoomed="true"] .reuse-lightbox-frame:active {
66
+ cursor: grabbing;
67
+ }
68
+ .reuse-lightbox-image {
69
+ display: block;
70
+ width: 100%;
71
+ height: 100%;
72
+ max-width: none;
73
+ object-fit: contain;
74
+ user-select: none;
75
+ -webkit-user-drag: none;
76
+ }
77
+ .reuse-lightbox-button {
78
+ position: absolute;
79
+ z-index: 2;
80
+ display: grid;
81
+ width: 44px;
82
+ height: 44px;
83
+ padding: 10px;
84
+ place-items: center;
85
+ border: 0;
86
+ border-radius: 50%;
87
+ background: var(--reuse-lightbox-control);
88
+ color: inherit;
89
+ font: inherit;
90
+ font-size: 26px;
91
+ line-height: 1;
92
+ cursor: pointer;
93
+ touch-action: manipulation;
94
+ backdrop-filter: blur(16px);
95
+ }
96
+ .reuse-lightbox-button svg {
97
+ width: 24px;
98
+ height: 24px;
99
+ }
100
+ .reuse-lightbox-button:hover {
101
+ background: rgb(58 58 62 / 98%);
102
+ }
103
+ .reuse-lightbox-button:disabled {
104
+ opacity: 0.3;
105
+ cursor: default;
106
+ }
107
+ .reuse-lightbox-button:focus-visible,
108
+ .reuse-lightbox-thumbnails button:focus-visible {
109
+ outline: 2px solid currentColor;
110
+ outline-offset: 3px;
111
+ }
112
+ .reuse-lightbox-close {
113
+ top: max(16px, env(safe-area-inset-top));
114
+ right: max(16px, env(safe-area-inset-right));
115
+ }
116
+ .reuse-lightbox-zoom {
117
+ top: max(16px, env(safe-area-inset-top));
118
+ right: calc(max(16px, env(safe-area-inset-right)) + 54px);
119
+ }
120
+ .reuse-lightbox-prev {
121
+ top: calc(50% - 22px);
122
+ left: max(16px, env(safe-area-inset-left));
123
+ }
124
+ .reuse-lightbox-next {
125
+ top: calc(50% - 22px);
126
+ right: max(16px, env(safe-area-inset-right));
127
+ }
128
+ .reuse-lightbox-footer {
129
+ position: absolute;
130
+ z-index: 2;
131
+ right: 72px;
132
+ bottom: max(16px, env(safe-area-inset-bottom));
133
+ left: 72px;
134
+ display: grid;
135
+ justify-items: center;
136
+ gap: 10px;
137
+ pointer-events: none;
138
+ }
139
+ .reuse-lightbox-counter {
140
+ padding: 6px 12px;
141
+ border-radius: 20px;
142
+ background: var(--reuse-lightbox-control);
143
+ font-size: 13px;
144
+ font-variant-numeric: tabular-nums;
145
+ backdrop-filter: blur(16px);
146
+ }
147
+ .reuse-lightbox-caption {
148
+ max-width: 60ch;
149
+ max-height: 20vh;
150
+ margin: 0;
151
+ overflow: auto;
152
+ padding: 4px 10px;
153
+ border-radius: 4px;
154
+ background: var(--reuse-lightbox-background);
155
+ font-size: 14px;
156
+ line-height: 1.5;
157
+ text-align: center;
158
+ overflow-wrap: anywhere;
159
+ pointer-events: auto;
160
+ }
161
+ .reuse-lightbox-caption:empty {
162
+ display: none;
163
+ }
164
+ .reuse-lightbox-thumbnails {
165
+ display: flex;
166
+ max-width: 100%;
167
+ gap: 8px;
168
+ overflow-x: auto;
169
+ padding: 4px;
170
+ pointer-events: auto;
171
+ }
172
+ .reuse-lightbox-thumbnails button {
173
+ flex: 0 0 44px;
174
+ width: 44px;
175
+ height: 44px;
176
+ padding: 0;
177
+ overflow: hidden;
178
+ border: 2px solid transparent;
179
+ border-radius: 5px;
180
+ background: none;
181
+ opacity: 0.6;
182
+ cursor: pointer;
183
+ }
184
+ .reuse-lightbox-thumbnails button[aria-current="true"] {
185
+ border-color: var(--reuse-lightbox-foreground);
186
+ opacity: 1;
187
+ }
188
+ .reuse-lightbox-thumbnails img {
189
+ width: 100%;
190
+ height: 100%;
191
+ object-fit: cover;
192
+ }
193
+
194
+ .reuse-lightbox-error {
195
+ position: absolute;
196
+ inset: 0;
197
+ display: grid;
198
+ padding: 24px;
199
+ place-items: center;
200
+ text-align: center;
201
+ }
202
+ @media (max-width: 480px) {
203
+ .reuse-lightbox-prev {
204
+ left: 8px;
205
+ }
206
+ .reuse-lightbox-next {
207
+ right: 8px;
208
+ }
209
+ .reuse-lightbox-footer {
210
+ right: 16px;
211
+ left: 16px;
212
+ }
213
+ }
214
+ @media (prefers-reduced-motion: reduce) {
215
+ .reuse-lightbox-viewport {
216
+ scroll-behavior: auto;
217
+ }
218
+ }
package/package.json CHANGED
@@ -1,6 +1,64 @@
1
1
  {
2
2
  "name": "@reuse-sh/lightbox",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.0.1",
4
+ "description": "An image lightbox on native scrolling, with thumbnail transitions, zoom, pan, and pinch.",
5
+ "keywords": [
6
+ "reuse",
7
+ "lightbox",
8
+ "gallery",
9
+ "zoom",
10
+ "image-viewer"
11
+ ],
12
+ "homepage": "https://reuse.sh/lightbox",
13
+ "bugs": "https://github.com/reuse-sh/reuse/issues",
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/reuse-sh/reuse.git",
17
+ "directory": "packages/lightbox"
18
+ },
19
+ "license": "MIT",
20
+ "author": "nK <https://nkdev.info>",
21
+ "type": "module",
22
+ "sideEffects": [
23
+ "**/*.css"
24
+ ],
25
+ "files": [
26
+ "dist",
27
+ "README.md",
28
+ "LICENSE"
29
+ ],
30
+ "exports": {
31
+ ".": {
32
+ "types": "./dist/index.d.ts",
33
+ "import": "./dist/index.js"
34
+ },
35
+ "./styles.css": "./dist/styles.css",
36
+ "./react": {
37
+ "types": "./dist/react.d.ts",
38
+ "import": "./dist/react.js"
39
+ }
40
+ },
41
+ "peerDependencies": {
42
+ "react": ">=19"
43
+ },
44
+ "peerDependenciesMeta": {
45
+ "react": {
46
+ "optional": true
47
+ }
48
+ },
49
+ "devDependencies": {
50
+ "react": "19.3.0",
51
+ "@types/react": "19.3.0"
52
+ },
53
+ "dependencies": {
54
+ "@reuse-sh/carousel": "0.0.1"
55
+ },
56
+ "publishConfig": {
57
+ "access": "public"
58
+ },
59
+ "scripts": {
60
+ "build": "node ../../scripts/clean-dist.mjs && tsc -p tsconfig.json && node ../../scripts/copy-styles.mjs",
61
+ "type-check": "tsc -p tsconfig.json --noEmit",
62
+ "test": "vitest run"
63
+ }
6
64
  }