@thisiscrowd/crowdbox 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.
- package/README.md +348 -0
- package/dist/crowdbox.css +1 -0
- package/dist/crowdbox.css.map +1 -0
- package/dist/crowdbox.esm.js +1557 -0
- package/dist/crowdbox.esm.js.map +1 -0
- package/dist/crowdbox.umd.js +8 -0
- package/dist/crowdbox.umd.js.map +1 -0
- package/package.json +59 -0
- package/src/adapters/iframe.js +30 -0
- package/src/adapters/image.js +91 -0
- package/src/adapters/video.js +44 -0
- package/src/adapters/vimeo.js +52 -0
- package/src/adapters/youtube.js +54 -0
- package/src/browser.js +7 -0
- package/src/core/Crowdbox.js +739 -0
- package/src/core/EventEmitter.js +43 -0
- package/src/core/LightboxGallery.js +2 -0
- package/src/core/Registry.js +26 -0
- package/src/core/utils.js +115 -0
- package/src/index.js +61 -0
- package/src/plugins/download/download.js +50 -0
- package/src/plugins/fullscreen/fullscreen.js +65 -0
- package/src/plugins/share/share.js +63 -0
- package/src/plugins/thumbs/thumbs.js +108 -0
- package/src/plugins/zoom/zoom.js +51 -0
- package/src/react/GalleryGrid.jsx +75 -0
- package/src/react/Lightbox.jsx +36 -0
- package/src/react/useLightbox.js +34 -0
- package/src/styles/_animations.scss +62 -0
- package/src/styles/_mosaic.scss +46 -0
- package/src/styles/_responsive.scss +34 -0
- package/src/styles/_thumbnails.scss +66 -0
- package/src/styles/_toolbar.scss +150 -0
- package/src/styles/_variables.scss +23 -0
- package/src/styles/main.scss +164 -0
- package/types/index.d.ts +239 -0
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
// ─── Crowdbox — TypeScript definitions ─────────────────────────────────
|
|
2
|
+
|
|
3
|
+
export interface GalleryItem {
|
|
4
|
+
/** URL of the media. */
|
|
5
|
+
src: string;
|
|
6
|
+
/** Explicit media type. Auto-detected if omitted. */
|
|
7
|
+
type?: 'image' | 'video' | 'youtube' | 'vimeo' | 'iframe';
|
|
8
|
+
/** Thumbnail URL (falls back to src for images). */
|
|
9
|
+
thumb?: string;
|
|
10
|
+
/** Caption HTML string. */
|
|
11
|
+
caption?: string;
|
|
12
|
+
/** Alt text for images. */
|
|
13
|
+
alt?: string;
|
|
14
|
+
/** Poster image for video. */
|
|
15
|
+
poster?: string;
|
|
16
|
+
/** Override download URL. */
|
|
17
|
+
download?: string;
|
|
18
|
+
/** Custom filename for downloads. */
|
|
19
|
+
downloadName?: string;
|
|
20
|
+
/** URL used by the Share plugin. */
|
|
21
|
+
shareUrl?: string;
|
|
22
|
+
/** Start time in seconds (YouTube). */
|
|
23
|
+
start?: number;
|
|
24
|
+
/** Autoplay the media when opened. */
|
|
25
|
+
autoplay?: boolean;
|
|
26
|
+
/** Loop video. */
|
|
27
|
+
loop?: boolean;
|
|
28
|
+
/** Start muted. */
|
|
29
|
+
muted?: boolean;
|
|
30
|
+
/** For iframes: explicit width. */
|
|
31
|
+
iframeWidth?: string;
|
|
32
|
+
/** For iframes: explicit height. */
|
|
33
|
+
iframeHeight?: string;
|
|
34
|
+
/** Multiple sources for HTML5 video. */
|
|
35
|
+
sources?: Array<{ src: string; type?: string }>;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface I18nStrings {
|
|
39
|
+
close?: string;
|
|
40
|
+
prev?: string;
|
|
41
|
+
next?: string;
|
|
42
|
+
zoomIn?: string;
|
|
43
|
+
zoomOut?: string;
|
|
44
|
+
fullscreen?: string;
|
|
45
|
+
download?: string;
|
|
46
|
+
share?: string;
|
|
47
|
+
autoplayStart?: string;
|
|
48
|
+
autoplayStop?: string;
|
|
49
|
+
/** Template: "{current} of {total}" */
|
|
50
|
+
counter?: string;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface CrowdboxOptions {
|
|
54
|
+
/** CSS selector for trigger elements. Default: '[data-lgx]' */
|
|
55
|
+
selector?: string;
|
|
56
|
+
/** Loop gallery navigation. Default: true */
|
|
57
|
+
loop?: boolean;
|
|
58
|
+
/** Enable keyboard navigation. Default: true */
|
|
59
|
+
keyboard?: boolean;
|
|
60
|
+
/** Enable touch swipe. Default: true */
|
|
61
|
+
touch?: boolean;
|
|
62
|
+
/** Enable mouse drag. Default: true */
|
|
63
|
+
drag?: boolean;
|
|
64
|
+
/** Enable zoom controls. Default: true */
|
|
65
|
+
zoom?: boolean;
|
|
66
|
+
/** Show thumbnail strip. Default: true */
|
|
67
|
+
thumbnails?: boolean;
|
|
68
|
+
/** Show captions. Default: true */
|
|
69
|
+
captions?: boolean;
|
|
70
|
+
/** Show slide counter. Default: true */
|
|
71
|
+
counter?: boolean;
|
|
72
|
+
/** Show fullscreen button. Default: true */
|
|
73
|
+
fullscreen?: boolean;
|
|
74
|
+
/** Show download button. Default: false */
|
|
75
|
+
download?: boolean;
|
|
76
|
+
/** Show share button. Default: false */
|
|
77
|
+
share?: boolean;
|
|
78
|
+
/** Close when clicking the backdrop. Default: true */
|
|
79
|
+
closeOnBackdrop?: boolean;
|
|
80
|
+
/** Close on Escape key. Default: true */
|
|
81
|
+
closeOnEscape?: boolean;
|
|
82
|
+
/** Open/close animation duration in ms. Default: 300 */
|
|
83
|
+
animationDuration?: number;
|
|
84
|
+
/** Slide transition duration in ms. Default: 250 */
|
|
85
|
+
slideAnimationDuration?: number;
|
|
86
|
+
/** Zoom step per click. Default: 0.5 */
|
|
87
|
+
zoomStep?: number;
|
|
88
|
+
/** Maximum zoom level. Default: 4 */
|
|
89
|
+
zoomMax?: number;
|
|
90
|
+
/** Minimum zoom level. Default: 1 */
|
|
91
|
+
zoomMin?: number;
|
|
92
|
+
/** Lazy-load images. Default: true */
|
|
93
|
+
lazyLoad?: boolean;
|
|
94
|
+
/** Number of slides to preload ahead/behind. Default: 1 */
|
|
95
|
+
preload?: number;
|
|
96
|
+
/** Autoplay slideshow. Default: false */
|
|
97
|
+
autoplay?: boolean;
|
|
98
|
+
/** Autoplay interval in ms. Default: 4000 */
|
|
99
|
+
autoplayInterval?: number;
|
|
100
|
+
/** Localization strings. */
|
|
101
|
+
i18n?: I18nStrings;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export type LightboxGalleryOptions = CrowdboxOptions;
|
|
105
|
+
|
|
106
|
+
export type GalleryEventMap = {
|
|
107
|
+
open: { index: number; item: GalleryItem };
|
|
108
|
+
close: void;
|
|
109
|
+
slide: { index: number; item: GalleryItem };
|
|
110
|
+
zoom: { zoom: number };
|
|
111
|
+
download: { item: GalleryItem };
|
|
112
|
+
share: { item: GalleryItem; method: 'native' | 'clipboard' };
|
|
113
|
+
'autoplay:start': void;
|
|
114
|
+
'autoplay:stop': void;
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
export declare class EventEmitter {
|
|
118
|
+
on<K extends keyof GalleryEventMap>(event: K, listener: (data: GalleryEventMap[K]) => void): this;
|
|
119
|
+
once<K extends keyof GalleryEventMap>(event: K, listener: (data: GalleryEventMap[K]) => void): this;
|
|
120
|
+
off<K extends keyof GalleryEventMap>(event: K, listener: (data: GalleryEventMap[K]) => void): this;
|
|
121
|
+
emit<K extends keyof GalleryEventMap>(event: K, data?: GalleryEventMap[K]): boolean;
|
|
122
|
+
removeAllListeners(event?: string): this;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export declare class Crowdbox extends EventEmitter {
|
|
126
|
+
readonly opts: Required<CrowdboxOptions>;
|
|
127
|
+
|
|
128
|
+
constructor(options?: CrowdboxOptions);
|
|
129
|
+
|
|
130
|
+
/** Open the gallery with an array of items, starting at startIndex. */
|
|
131
|
+
open(items: GalleryItem | GalleryItem[], startIndex?: number): this;
|
|
132
|
+
|
|
133
|
+
/** Close the gallery. */
|
|
134
|
+
close(): this;
|
|
135
|
+
|
|
136
|
+
/** Go to the next item. */
|
|
137
|
+
next(): this;
|
|
138
|
+
|
|
139
|
+
/** Go to the previous item. */
|
|
140
|
+
prev(): this;
|
|
141
|
+
|
|
142
|
+
/** Jump to a specific index. */
|
|
143
|
+
goTo(index: number): this;
|
|
144
|
+
|
|
145
|
+
/** Zoom in by one step. */
|
|
146
|
+
zoomIn(): this;
|
|
147
|
+
|
|
148
|
+
/** Zoom out by one step. */
|
|
149
|
+
zoomOut(): this;
|
|
150
|
+
|
|
151
|
+
/** Reset zoom to 1×. */
|
|
152
|
+
resetZoom(): this;
|
|
153
|
+
|
|
154
|
+
/** Start the autoplay slideshow. */
|
|
155
|
+
startAutoplay(): this;
|
|
156
|
+
|
|
157
|
+
/** Stop the autoplay slideshow. */
|
|
158
|
+
stopAutoplay(): this;
|
|
159
|
+
|
|
160
|
+
/** Toggle the autoplay slideshow. */
|
|
161
|
+
toggleAutoplay(): this;
|
|
162
|
+
|
|
163
|
+
/** Remove all event listeners and DOM. */
|
|
164
|
+
destroy(): void;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export declare class LightboxGallery extends Crowdbox {}
|
|
168
|
+
|
|
169
|
+
// ─── Media Adapters ───────────────────────────────────────────────────────────
|
|
170
|
+
|
|
171
|
+
export interface MediaAdapter {
|
|
172
|
+
type: string;
|
|
173
|
+
canHandle(item: GalleryItem): boolean;
|
|
174
|
+
render(item: GalleryItem): HTMLElement;
|
|
175
|
+
getThumbnail(item: GalleryItem): string | null;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export declare const ImageAdapter: MediaAdapter;
|
|
179
|
+
export declare const VideoAdapter: MediaAdapter;
|
|
180
|
+
export declare const YouTubeAdapter: MediaAdapter;
|
|
181
|
+
export declare const VimeoAdapter: MediaAdapter;
|
|
182
|
+
export declare const IframeAdapter: MediaAdapter;
|
|
183
|
+
|
|
184
|
+
// ─── Plugins ──────────────────────────────────────────────────────────────────
|
|
185
|
+
|
|
186
|
+
export interface GalleryPlugin {
|
|
187
|
+
pluginName: string;
|
|
188
|
+
init?(gallery: Crowdbox): void;
|
|
189
|
+
afterOpen?(): void;
|
|
190
|
+
beforeClose?(): void;
|
|
191
|
+
afterClose?(): void;
|
|
192
|
+
afterBuildDOM?(): void;
|
|
193
|
+
buildToolbar?(toolbar: HTMLElement): void;
|
|
194
|
+
afterSlide?(index: number, item: GalleryItem): void;
|
|
195
|
+
updateUI?(): void;
|
|
196
|
+
afterZoom?(zoom: number): void;
|
|
197
|
+
toggleFullscreen?(): void;
|
|
198
|
+
destroy?(): void;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export declare class ZoomPlugin implements GalleryPlugin { static pluginName: 'zoom'; }
|
|
202
|
+
export declare class ThumbsPlugin implements GalleryPlugin { static pluginName: 'thumbnails'; }
|
|
203
|
+
export declare class FullscreenPlugin implements GalleryPlugin { static pluginName: 'fullscreen'; }
|
|
204
|
+
export declare class DownloadPlugin implements GalleryPlugin { static pluginName: 'download'; }
|
|
205
|
+
export declare class SharePlugin implements GalleryPlugin { static pluginName: 'share'; }
|
|
206
|
+
|
|
207
|
+
// ─── Registry ─────────────────────────────────────────────────────────────────
|
|
208
|
+
|
|
209
|
+
export declare const Registry: {
|
|
210
|
+
registerAdapter(type: string, adapter: MediaAdapter): void;
|
|
211
|
+
getAdapter(type: string): MediaAdapter | null;
|
|
212
|
+
registerPlugin(name: string, plugin: GalleryPlugin): void;
|
|
213
|
+
getPlugin(name: string): GalleryPlugin | null;
|
|
214
|
+
getPlugins(): GalleryPlugin[];
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
// ─── Factory ─────────────────────────────────────────────────────────────────
|
|
218
|
+
|
|
219
|
+
export declare function createGallery(options?: CrowdboxOptions): Crowdbox;
|
|
220
|
+
|
|
221
|
+
export default Crowdbox;
|
|
222
|
+
|
|
223
|
+
// ─── React types (optional peer dep) ─────────────────────────────────────────
|
|
224
|
+
|
|
225
|
+
export interface LightboxProps extends CrowdboxOptions {
|
|
226
|
+
items: GalleryItem[];
|
|
227
|
+
open: boolean;
|
|
228
|
+
startIndex?: number;
|
|
229
|
+
onClose: () => void;
|
|
230
|
+
className?: string;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
export interface GalleryGridProps {
|
|
234
|
+
items: GalleryItem[];
|
|
235
|
+
columns?: number;
|
|
236
|
+
gap?: number;
|
|
237
|
+
lightboxOptions?: CrowdboxOptions;
|
|
238
|
+
className?: string;
|
|
239
|
+
}
|