@reuse-sh/lightbox 0.0.6 → 0.2.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 (53) hide show
  1. package/README.md +65 -16
  2. package/dist/audio.d.ts +2 -0
  3. package/dist/audio.js +17 -0
  4. package/dist/base.css +602 -0
  5. package/dist/browser/audio.js +3 -0
  6. package/dist/browser/audio.js.map +1 -0
  7. package/dist/browser/carousel-link.js +3 -0
  8. package/dist/browser/carousel-link.js.map +1 -0
  9. package/dist/browser/embed.js +3 -0
  10. package/dist/browser/embed.js.map +1 -0
  11. package/dist/browser/html.js +3 -0
  12. package/dist/browser/html.js.map +1 -0
  13. package/dist/browser/iframe.js +3 -0
  14. package/dist/browser/iframe.js.map +1 -0
  15. package/dist/browser/lightbox.js +3 -0
  16. package/dist/browser/lightbox.js.map +1 -0
  17. package/dist/browser/video.js +3 -0
  18. package/dist/browser/video.js.map +1 -0
  19. package/dist/carousel.d.ts +6 -0
  20. package/dist/carousel.js +17 -0
  21. package/dist/chrome.d.ts +35 -0
  22. package/dist/chrome.js +53 -0
  23. package/dist/embed.d.ts +14 -0
  24. package/dist/embed.js +173 -0
  25. package/dist/geometry.d.ts +37 -1
  26. package/dist/geometry.js +75 -5
  27. package/dist/html.d.ts +2 -0
  28. package/dist/html.js +15 -0
  29. package/dist/icons.d.ts +15 -0
  30. package/dist/icons.js +40 -0
  31. package/dist/iframe.d.ts +8 -0
  32. package/dist/iframe.js +43 -0
  33. package/dist/index.d.ts +180 -47
  34. package/dist/index.js +3817 -398
  35. package/dist/react.d.ts +18 -9
  36. package/dist/react.js +71 -46
  37. package/dist/sources.d.ts +28 -0
  38. package/dist/sources.js +179 -0
  39. package/dist/theme.css +236 -0
  40. package/dist/themes/dark.css +12 -0
  41. package/dist/themes/light.css +12 -0
  42. package/dist/themes/page.css +28 -0
  43. package/dist/themes/photos.css +17 -0
  44. package/dist/unlayered/base.css +599 -0
  45. package/dist/unlayered/theme.css +233 -0
  46. package/dist/unlayered/themes/dark.css +9 -0
  47. package/dist/unlayered/themes/light.css +9 -0
  48. package/dist/unlayered/themes/page.css +25 -0
  49. package/dist/unlayered/themes/photos.css +14 -0
  50. package/dist/video.d.ts +3 -0
  51. package/dist/video.js +55 -0
  52. package/package.json +33 -4
  53. package/dist/styles.css +0 -218
package/dist/index.d.ts CHANGED
@@ -1,75 +1,208 @@
1
1
  import { type Point, type Zoom } from "./geometry.js";
2
2
  export type { Point, Rect, Size, Zoom } from "./geometry.js";
3
- export interface LightboxItem {
4
- src: string;
5
- previewSrc?: string;
6
- width?: number;
7
- height?: number;
3
+ export interface LightboxStrings {
4
+ dialog: string;
5
+ slide: (index: number, count: number, caption?: string) => string;
6
+ counter: (index: number, count: number) => string;
7
+ close: string;
8
+ previous: string;
9
+ next: string;
10
+ zoomIn: string;
11
+ zoomOut: string;
12
+ fullscreenEnter: string;
13
+ fullscreenExit: string;
14
+ download: string;
15
+ thumbnails: string;
16
+ thumbnail: (index: number, count: number) => string;
17
+ slideshowStart: string;
18
+ slideshowStop: string;
19
+ loading: string;
20
+ error: string;
21
+ retry: string;
22
+ carouselRole: string;
23
+ }
24
+ export type LightboxSlotName = "toolbarStart" | "toolbarEnd" | "footer" | "aside";
25
+ export type LightboxSlot<Item extends LightboxItem = LightboxItem> = (context: {
26
+ lightbox: Lightbox<Item>;
27
+ document: Document;
28
+ /** The icon a built-in control shows: yours from the icons option, else the package's. */
29
+ icon: (name: LightboxIcon) => Node;
30
+ /** A new counter that shows the position and rolls its digits like the built-in one. */
31
+ counter: () => HTMLElement;
32
+ }) => {
33
+ node: Node;
34
+ update?: (state: LightboxState<Item>) => void;
35
+ destroy?: () => void;
36
+ };
37
+ export type LightboxControl = "close" | "arrows" | "counter" | "zoom" | "fullscreen" | "download" | "slideshow";
38
+ export type LightboxIcon = "close" | "previous" | "next" | "zoom" | "zoomOut" | "fullscreen" | "fullscreenExit" | "download" | "slideshow" | "slideshowPause";
39
+ export interface LightboxEvent {
40
+ readonly type: LightboxEventName;
41
+ readonly index: number;
42
+ readonly slide: HTMLElement | null;
43
+ }
44
+ export interface LightboxCancelableEvent extends LightboxEvent {
45
+ /** False for the close an emptied list starts, which preventDefault() cannot stop. */
46
+ readonly cancelable: boolean;
47
+ readonly defaultPrevented: boolean;
48
+ /** Keeps the viewer open. */
49
+ preventDefault(): void;
50
+ }
51
+ export interface LightboxBeforeChangeEvent extends LightboxEvent {
52
+ readonly nextIndex: number;
53
+ }
54
+ export interface LightboxEventMap {
55
+ open: LightboxEvent;
56
+ opened: LightboxEvent;
57
+ beforechange: LightboxBeforeChangeEvent;
58
+ change: LightboxEvent;
59
+ settle: LightboxEvent;
60
+ beforeclose: LightboxCancelableEvent;
61
+ closed: LightboxEvent;
62
+ }
63
+ export type LightboxEventName = keyof LightboxEventMap;
64
+ export interface LightboxListenOptions {
65
+ /** Removes the listener when it aborts. */
66
+ signal?: AbortSignal;
67
+ }
68
+ interface LightboxItemBase {
8
69
  alt?: string;
9
70
  caption?: string;
71
+ /** The file's own size; without it the viewer fits the preview's proportions until the file decodes. */
72
+ width?: number;
73
+ height?: number;
74
+ /** Shown while the file loads when the origin has no loaded image, and as a player's poster. */
75
+ previewSrc?: string;
10
76
  thumbnailSrc?: string;
11
- origin?: HTMLElement | null;
77
+ /** The tile the photo opens from and closes to, read again whenever the photo changes. */
78
+ origin?: HTMLElement | null | (() => HTMLElement | null);
12
79
  }
13
- export interface LightboxState {
14
- isOpen: boolean;
15
- isClosing: boolean;
16
- index: number;
17
- count: number;
18
- zoom: Zoom;
80
+ export interface LightboxImageItem extends LightboxItemBase {
81
+ type?: undefined;
82
+ src: string;
83
+ srcset?: string;
84
+ sizes?: string;
19
85
  }
20
- export interface LightboxContentContext {
21
- item: LightboxItem;
86
+ export interface LightboxMediaItem extends LightboxItemBase {
87
+ /** Picks the content module whose type matches, such as "video" for video(). */
88
+ type: string;
89
+ /** The media file, page or player link its module plays. */
90
+ src?: string;
91
+ /** Builds an HTML slide's content; HTML strings are never parsed. */
92
+ html?: () => Node;
93
+ }
94
+ export type LightboxItem = LightboxImageItem | LightboxMediaItem;
95
+ export interface LightboxState<Item extends LightboxItem = LightboxItem> {
96
+ readonly isOpen: boolean;
97
+ readonly isClosing: boolean;
98
+ readonly isAnimating: boolean;
99
+ readonly index: number;
100
+ readonly count: number;
101
+ /** The item at index, the object passed to open() or setItems(). */
102
+ readonly item: Item | undefined;
103
+ readonly canPrev: boolean;
104
+ readonly canNext: boolean;
105
+ /** The slideshow runs, also while it waits on a zoom, a player or a hover. */
106
+ readonly isPlaying: boolean;
107
+ readonly zoom: Readonly<Zoom>;
108
+ readonly chrome: "shown" | "hidden";
109
+ }
110
+ export interface LightboxContentContext<Item extends LightboxItem = LightboxItem> {
111
+ item: Extract<Item, LightboxImageItem>;
22
112
  index: number;
23
113
  container: HTMLElement;
24
114
  image: HTMLImageElement;
25
115
  }
26
- export interface LightboxOptions {
116
+ export interface LightboxMountContext {
117
+ item: LightboxMediaItem;
118
+ index: number;
119
+ /** Aborts when the slide unmounts. */
120
+ signal: AbortSignal;
121
+ /** True when the player should start once it is current: the autoplayMedia option and an open by a user action. */
122
+ autoplay: boolean;
123
+ }
124
+ export interface LightboxMounted {
125
+ unmount(): void;
126
+ /** Without pause the slide unmounts when another photo becomes current. */
127
+ pause?(): void;
128
+ /** Called when the slide becomes current; plays unless the person paused it. */
129
+ resume?(): void;
130
+ /** Width over height, 16 / 9 when missing. */
131
+ aspect?: number;
132
+ /** The slide takes pointer events, and the viewer's gestures leave it alone. */
133
+ interactive?: boolean;
134
+ /** Settles once the player can show itself; the poster and the spinner stay until then. */
135
+ ready?: Promise<unknown>;
136
+ }
137
+ export interface LightboxContent {
138
+ type: string;
139
+ mount(container: HTMLElement, context: LightboxMountContext): LightboxMounted;
140
+ }
141
+ export interface LightboxOptions<Item extends LightboxItem = LightboxItem> {
27
142
  container?: HTMLElement;
28
- label?: string;
29
143
  imageClick?: "zoom" | "close" | "none";
30
144
  doubleTapZoom?: boolean;
31
145
  maxZoom?: number;
32
146
  tapZoom?: number;
33
147
  preload?: number;
34
- thumbnails?: boolean;
35
- padding?: number;
36
- duration?: number;
148
+ controls?: Partial<Record<LightboxControl, boolean>>;
149
+ thumbnails?: false | "bottom" | "side";
150
+ thumbnailsVisible?: boolean;
151
+ caption?: "bottom" | "side";
152
+ slideshow?: {
153
+ interval?: number;
154
+ };
155
+ autoHide?: number | false;
37
156
  className?: string;
38
- icons?: Partial<Record<"close" | "prev" | "next" | "zoom", () => Node>>;
39
- renderContent?: (context: LightboxContentContext) => undefined | (() => void);
40
- /** Reports discrete actions, completed pointer gestures, and wheel input after 150ms idle. */
41
- onChange?: (state: LightboxState) => void;
157
+ icons?: Partial<Record<LightboxIcon, () => Node>>;
158
+ renderContent?: (context: LightboxContentContext<Item>) => undefined | (() => void);
159
+ /** Content modules for items with a type, such as video() from @reuse-sh/lightbox/video. */
160
+ content?: readonly LightboxContent[];
161
+ /** Starts the current player once it shows, when the viewer opened from a user action; default true. */
162
+ autoplayMedia?: boolean;
163
+ loop?: boolean;
164
+ history?: boolean;
165
+ strings?: Partial<LightboxStrings>;
166
+ slots?: Partial<Record<LightboxSlotName, LightboxSlot<Item>>>;
167
+ protect?: boolean;
42
168
  }
43
- export interface Lightbox {
44
- open(items: readonly LightboxItem[], index?: number): void;
169
+ export interface Lightbox<Item extends LightboxItem = LightboxItem> {
170
+ open(items: readonly Item[], index?: number): void;
45
171
  close(): Promise<void>;
46
172
  next(): void;
47
173
  prev(): void;
48
174
  goTo(index: number): void;
49
175
  zoomTo(scale: number, focus?: Point): void;
50
176
  toggleZoom(focus?: Point): void;
51
- /** Returns live geometry, including pointer and wheel samples before notification. */
52
- getState(): LightboxState;
53
- /** Subscribes to the settled changes reported by onChange. */
54
- subscribe(listener: (state: LightboxState) => void): () => void;
177
+ /** Starts the slideshow on the open viewer. */
178
+ play(): void;
179
+ pause(): void;
180
+ /** The last state subscribers received; a gesture or a wheel shows up once it settles. */
181
+ getState(): LightboxState<Item>;
182
+ /** Reports discrete actions, completed pointer gestures, and wheel input after 150ms idle. */
183
+ subscribe(listener: (state: LightboxState<Item>) => void, options?: LightboxListenOptions): () => void;
184
+ on<K extends LightboxEventName>(type: K, listener: (event: LightboxEventMap[K]) => void, options?: LightboxListenOptions): () => void;
185
+ append(items: readonly Item[]): void;
186
+ /** Keeps the current image when the new list still has it, otherwise shows index or the nearest image left. */
187
+ setItems(items: readonly Item[], index?: number): void;
188
+ /** Takes effect at the next open; loop and strings also change an open viewer at once. */
189
+ setOptions(options: Partial<Omit<LightboxOptions<Item>, "container">>): void;
190
+ getSlide(index: number): HTMLElement | null;
55
191
  destroy(): void;
56
192
  }
57
- export declare function createLightbox(options?: LightboxOptions): Lightbox;
58
- export declare function lightboxItemFromImage(image: HTMLImageElement, source?: string): LightboxItem;
59
- export declare function bindLightboxGallery(root: HTMLElement, options?: LightboxOptions & {
193
+ export declare function createLightbox<Item extends LightboxItem = LightboxItem>(options?: LightboxOptions<Item>): Lightbox<Item>;
194
+ /**
195
+ * The item a gallery trigger opens: a link, a button or an img, and the img inside it. Returns
196
+ * null when the trigger names no image file and no media type, so the page keeps its click.
197
+ */
198
+ export declare function lightboxItemFromElement(trigger: HTMLElement): LightboxItem | null;
199
+ export interface LightboxGalleryOptions<Item extends LightboxItem = LightboxItem> {
200
+ /** The triggers inside root; by default buttons, images and links that hold an img or carry data-lightbox-type or data-lightbox-src, never a[download]. A trigger inside another counts as the outer one. */
60
201
  selector?: string;
61
- getItem?: (image: HTMLImageElement) => LightboxItem;
62
- }): {
63
- open(items: readonly LightboxItem[], index?: number): void;
64
- close(): Promise<void>;
65
- next(): void;
66
- prev(): void;
67
- goTo(index: number): void;
68
- zoomTo(scale: number, focus?: Point): void;
69
- toggleZoom(focus?: Point): void;
70
- /** Returns live geometry, including pointer and wheel samples before notification. */
71
- getState(): LightboxState;
72
- /** Subscribes to the settled changes reported by onChange. */
73
- subscribe(listener: (state: LightboxState) => void): () => void;
74
- destroy: () => void;
75
- };
202
+ /** The item a trigger opens, lightboxItemFromElement by default; null leaves the trigger's click to the page. */
203
+ item?: (trigger: HTMLElement) => Item | null;
204
+ /** Triggers open only with the triggers of the same group, the closest data-lightbox-group by default. */
205
+ group?: (trigger: HTMLElement) => string;
206
+ }
207
+ /** Opens the triggers inside root in the lightbox on a plain click, and returns the function that unbinds. */
208
+ export declare function bindLightboxGallery<Item extends LightboxItem = LightboxItem>(root: HTMLElement, lightbox: Lightbox<Item>, options?: LightboxGalleryOptions<Item>): () => void;