@redot-src/glare 1.0.0 → 1.1.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 (63) hide show
  1. package/README.md +40 -8
  2. package/dist/core/animation.d.ts +7 -0
  3. package/dist/core/bind.d.ts +8 -0
  4. package/dist/core/dom.d.ts +18 -0
  5. package/dist/core/glare.d.ts +65 -0
  6. package/dist/core/idle.d.ts +9 -0
  7. package/dist/core/interactions.d.ts +3 -0
  8. package/dist/core/loaders.d.ts +5 -0
  9. package/dist/core/options.d.ts +5 -0
  10. package/dist/core/registry.d.ts +9 -0
  11. package/dist/core/zoom.d.ts +36 -0
  12. package/dist/defaults.d.ts +5 -5
  13. package/dist/esm.d.ts +3 -0
  14. package/dist/glare.css +1 -1
  15. package/dist/glare.esm.js +1038 -1171
  16. package/dist/glare.esm.js.map +1 -1
  17. package/dist/glare.js +25 -23
  18. package/dist/glare.js.map +1 -1
  19. package/dist/i18n.d.ts +4 -0
  20. package/dist/icons.d.ts +12 -13
  21. package/dist/index.d.ts +5 -7
  22. package/dist/media/detect.d.ts +4 -0
  23. package/dist/media/items.d.ts +6 -0
  24. package/dist/media/providers.d.ts +6 -0
  25. package/dist/modules/fullscreen.d.ts +15 -0
  26. package/dist/modules/gestures.d.ts +45 -0
  27. package/dist/modules/hash.d.ts +22 -0
  28. package/dist/modules/share.d.ts +17 -0
  29. package/dist/modules/slideshow.d.ts +25 -0
  30. package/dist/modules/thumbs.d.ts +22 -0
  31. package/dist/modules/wheel.d.ts +19 -0
  32. package/dist/templates.d.ts +7 -0
  33. package/dist/types.d.ts +117 -131
  34. package/dist/umd.d.ts +3 -0
  35. package/dist/utils/dom.d.ts +20 -0
  36. package/dist/utils/env.d.ts +5 -0
  37. package/dist/utils/object.d.ts +3 -0
  38. package/dist/utils/template.d.ts +5 -0
  39. package/package.json +18 -24
  40. package/dist/defaults.d.ts.map +0 -1
  41. package/dist/fullscreen.d.ts +0 -14
  42. package/dist/fullscreen.d.ts.map +0 -1
  43. package/dist/gestures.d.ts +0 -24
  44. package/dist/gestures.d.ts.map +0 -1
  45. package/dist/hash.d.ts +0 -20
  46. package/dist/hash.d.ts.map +0 -1
  47. package/dist/icons.d.ts.map +0 -1
  48. package/dist/index.d.ts.map +0 -1
  49. package/dist/instance.d.ts +0 -103
  50. package/dist/instance.d.ts.map +0 -1
  51. package/dist/media.d.ts +0 -5
  52. package/dist/media.d.ts.map +0 -1
  53. package/dist/share.d.ts +0 -13
  54. package/dist/share.d.ts.map +0 -1
  55. package/dist/slideshow.d.ts +0 -19
  56. package/dist/slideshow.d.ts.map +0 -1
  57. package/dist/thumbs.d.ts +0 -17
  58. package/dist/thumbs.d.ts.map +0 -1
  59. package/dist/types.d.ts.map +0 -1
  60. package/dist/utils.d.ts +0 -31
  61. package/dist/utils.d.ts.map +0 -1
  62. package/dist/wheel.d.ts +0 -11
  63. package/dist/wheel.d.ts.map +0 -1
package/dist/i18n.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ import type { GlareOptions, I18nDict } from './types';
2
+ export declare const i18nEn: I18nDict;
3
+ /** Resolves the active dictionary: built-in English, then `i18n.en`, then `i18n[lang]`. */
4
+ export declare function getDict(opts: GlareOptions): I18nDict;
package/dist/icons.d.ts CHANGED
@@ -1,15 +1,14 @@
1
1
  export declare const icons: {
2
- readonly close: "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\"><path d=\"M18 6 6 18\"/><path d=\"m6 6 12 12\"/></svg>";
3
- readonly next: "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\"><path d=\"m9 18 6-6-6-6\"/></svg>";
4
- readonly prev: "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\"><path d=\"m15 18-6-6 6-6\"/></svg>";
5
- readonly zoomIn: "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\"><circle cx=\"11\" cy=\"11\" r=\"8\"/><path d=\"m21 21-4.3-4.3\"/><path d=\"M11 8v6\"/><path d=\"M8 11h6\"/></svg>";
6
- readonly zoomOut: "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\"><circle cx=\"11\" cy=\"11\" r=\"8\"/><path d=\"m21 21-4.3-4.3\"/><path d=\"M8 11h6\"/></svg>";
7
- readonly download: "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\"><path d=\"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4\"/><polyline points=\"7 10 12 15 17 10\"/><line x1=\"12\" x2=\"12\" y1=\"15\" y2=\"3\"/></svg>";
8
- readonly share: "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\"><circle cx=\"18\" cy=\"5\" r=\"3\"/><circle cx=\"6\" cy=\"12\" r=\"3\"/><circle cx=\"18\" cy=\"19\" r=\"3\"/><line x1=\"8.59\" x2=\"15.42\" y1=\"13.51\" y2=\"17.49\"/><line x1=\"15.41\" x2=\"8.59\" y1=\"6.51\" y2=\"10.49\"/></svg>";
9
- readonly thumbs: "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\"><rect width=\"18\" height=\"18\" x=\"3\" y=\"3\" rx=\"2\"/><path d=\"M3 9h18\"/><path d=\"M9 21V9\"/></svg>";
10
- readonly play: "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\"><polygon points=\"6 3 20 12 6 21 6 3\"/></svg>";
11
- readonly pause: "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\"><rect width=\"4\" height=\"16\" x=\"6\" y=\"4\"/><rect width=\"4\" height=\"16\" x=\"14\" y=\"4\"/></svg>";
12
- readonly fullscreen: "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\"><path d=\"M8 3H5a2 2 0 0 0-2 2v3\"/><path d=\"M21 8V5a2 2 0 0 0-2-2h-3\"/><path d=\"M3 16v3a2 2 0 0 0 2 2h3\"/><path d=\"M16 21h3a2 2 0 0 0 2-2v-3\"/></svg>";
13
- readonly fullscreenExit: "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\"><path d=\"M8 3v3a2 2 0 0 1-2 2H3\"/><path d=\"M21 8h-3a2 2 0 0 1-2-2V3\"/><path d=\"M3 16h3a2 2 0 0 1 2 2v3\"/><path d=\"M16 21v-3a2 2 0 0 1 2-2h3\"/></svg>";
2
+ readonly close: string;
3
+ readonly next: string;
4
+ readonly prev: string;
5
+ readonly zoomIn: string;
6
+ readonly zoomOut: string;
7
+ readonly download: string;
8
+ readonly share: string;
9
+ readonly thumbs: string;
10
+ readonly play: string;
11
+ readonly pause: string;
12
+ readonly fullscreen: string;
13
+ readonly fullscreenExit: string;
14
14
  };
15
- //# sourceMappingURL=icons.d.ts.map
package/dist/index.d.ts CHANGED
@@ -1,8 +1,6 @@
1
- import './styles/glare.css';
2
- export type { AnimationEffect, AjaxOptions, BoundGroup, ClickAction, ContentType, EventHandler, EventName, FullscreenOptions, HashOptions, I18nDict, IframeOptions, ImageOptions, MediaProvider, GlareInstance, GlareOptions, ShareOptions, SlideItem, SlideSource, SlideshowOptions, ThumbsOptions, ToolbarButton, TouchOptions, TransitionEffect, VideoOptions, } from './types';
3
- export { defaults, defaultMedia, i18nEn } from './defaults';
4
- export { Glare, autoBind } from './instance';
5
- export { detectType, normalizeItem, itemsFromElements } from './media';
6
- import { Glare } from './instance';
1
+ import { Glare } from './core/glare';
2
+ export type { AjaxOptions, AnimationEffect, BoundGroup, ClickAction, ClickActionName, ContentType, EventHandler, EventName, FullscreenOptions, GlareInstance, GlareOptions, GlareRefs, I18nDict, IframeOptions, ImageOptions, LifecycleEvent, LifecycleHandler, MediaProvider, ResolvedOptions, ShareOptions, SlideEvent, SlideItem, SlideSource, SlideshowOptions, ThumbsOptions, ToolbarButton, TouchOptions, TransitionEffect, VideoOptions, } from './types';
3
+ export type { Point, Zoom, ZoomState } from './core/zoom';
4
+ export { Glare };
5
+ export declare const autoBind: typeof Glare.autoBind;
7
6
  export default Glare;
8
- //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,4 @@
1
+ import type { ContentType } from '../types';
2
+ /** Guesses the content type from a URL; falls back to `fallback` for unknown URLs. */
3
+ export declare function detectType(src: string, fallback?: ContentType): ContentType;
4
+ export declare function videoMime(src: string): string;
@@ -0,0 +1,6 @@
1
+ import type { GlareOptions, SlideItem, SlideSource } from '../types';
2
+ /** Turns a user-provided slide into a normalized `SlideItem`. */
3
+ export declare function normalizeItem(source: SlideSource | string, index: number, opts: GlareOptions): SlideItem;
4
+ /** Reads slide data from trigger elements (`href`, `data-*` attributes, nested `<img>`). */
5
+ export declare function itemsFromElements(elements: HTMLElement[], opts: GlareOptions): SlideItem[];
6
+ export declare function createItems(items: Array<SlideSource | string> | HTMLElement[], opts: GlareOptions): SlideItem[];
@@ -0,0 +1,6 @@
1
+ import type { ContentType, MediaProvider, SlideSource } from '../types';
2
+ export declare const providers: Record<string, MediaProvider>;
3
+ /** Rewrites `src` through the first matching provider, or returns null. */
4
+ export declare function applyProvider(src: string, media: Record<string, MediaProvider> | undefined): Pick<SlideSource, 'src' | 'thumb'> & {
5
+ type: ContentType;
6
+ } | null;
@@ -0,0 +1,15 @@
1
+ import type { FullscreenOptions } from '../types';
2
+ import type { Glare } from '../core/glare';
3
+ /** Fullscreen API wrapper with the WebKit fallback still needed by Safari. */
4
+ export declare class Fullscreen {
5
+ private readonly glare;
6
+ private readonly container;
7
+ private readonly offs;
8
+ constructor(glare: Glare, container: HTMLElement, opts: FullscreenOptions);
9
+ isFullscreen(): boolean;
10
+ request(): void;
11
+ exit(): void;
12
+ toggle(): void;
13
+ destroy(): void;
14
+ private sync;
15
+ }
@@ -0,0 +1,45 @@
1
+ import type { TouchOptions } from '../types';
2
+ import type { Zoom } from '../core/zoom';
3
+ export interface GestureHost {
4
+ zoom: Zoom;
5
+ touch: TouchOptions;
6
+ /** The backdrop, dimmed while the stage is dragged vertically. */
7
+ bg: HTMLElement | null;
8
+ /** Whether the current slide can be panned when zoomed. */
9
+ canPan(): boolean;
10
+ close(): void;
11
+ next(): void;
12
+ prev(): void;
13
+ }
14
+ /** Swipe, pan and pinch handling on top of Pointer Events. */
15
+ export declare class Gestures {
16
+ private readonly stage;
17
+ private readonly host;
18
+ private readonly pointers;
19
+ private readonly offs;
20
+ private mode;
21
+ private moved;
22
+ private start;
23
+ private startTime;
24
+ private startZoom;
25
+ private startMid;
26
+ private startDistance;
27
+ constructor(stage: HTMLElement, host: GestureHost);
28
+ destroy(): void;
29
+ /** Returns whether the last gesture moved, then clears the flag. */
30
+ consumeMoved(): boolean;
31
+ private onDown;
32
+ private onMove;
33
+ private onUp;
34
+ /** Anchors a new gesture on the currently pressed pointers. */
35
+ private begin;
36
+ private move;
37
+ /** Scales around the pinch midpoint so the content under the fingers stays put. */
38
+ private pinch;
39
+ private end;
40
+ /** Moves the whole stage with the finger and dims the backdrop on vertical drags. */
41
+ private dragStage;
42
+ private releaseStage;
43
+ /** A long or fast vertical swipe closes; a horizontal one navigates. */
44
+ private finishSwipe;
45
+ }
@@ -0,0 +1,22 @@
1
+ import type { Glare } from '../core/glare';
2
+ /** Parses `#gallery-3` into `{ gallery: 'gallery', index: 2 }`. */
3
+ export declare function parseHash(hash?: string): {
4
+ gallery: string;
5
+ index: number;
6
+ } | null;
7
+ /**
8
+ * Keeps the URL hash in sync with the current slide of a named gallery.
9
+ * Opening pushes one history entry so the browser's Back button closes the lightbox;
10
+ * slide changes replace it so Back never walks through every slide.
11
+ */
12
+ export declare class Hash {
13
+ private readonly glare;
14
+ private readonly gallery;
15
+ private readonly off;
16
+ private pushed;
17
+ constructor(glare: Glare, gallery: string);
18
+ update(index?: number): void;
19
+ destroy(): void;
20
+ private onHashChange;
21
+ private replace;
22
+ }
@@ -0,0 +1,17 @@
1
+ import type { ShareOptions } from '../types';
2
+ import type { Glare } from '../core/glare';
3
+ /** Overlay with social share links and a copyable URL. */
4
+ export declare class Share {
5
+ private readonly glare;
6
+ private readonly container;
7
+ private readonly opts;
8
+ private overlay;
9
+ private off;
10
+ constructor(glare: Glare, container: HTMLElement, opts: ShareOptions);
11
+ get isOpen(): boolean;
12
+ open(): void;
13
+ close(): void;
14
+ destroy(): void;
15
+ private copy;
16
+ private resolveUrl;
17
+ }
@@ -0,0 +1,25 @@
1
+ import type { SlideshowOptions } from '../types';
2
+ import type { Glare } from '../core/glare';
3
+ /** Advances slides on a timer and animates the top progress bar. */
4
+ export declare class Slideshow {
5
+ private readonly glare;
6
+ private readonly container;
7
+ private readonly opts;
8
+ private readonly bar;
9
+ private readonly button;
10
+ private timer;
11
+ private active;
12
+ constructor(glare: Glare, container: HTMLElement, opts: SlideshowOptions);
13
+ isActive(): boolean;
14
+ start(): void;
15
+ stop(): void;
16
+ toggle(): void;
17
+ onIndexChange(): void;
18
+ destroy(): void;
19
+ private get speed();
20
+ private get atEnd();
21
+ private schedule;
22
+ private clearTimer;
23
+ private setProgress;
24
+ private syncButton;
25
+ }
@@ -0,0 +1,22 @@
1
+ import type { ThumbsOptions } from '../types';
2
+ import type { Glare } from '../core/glare';
3
+ /** Clickable thumbnail strip, horizontal (`x`) or vertical (`y`). */
4
+ export declare class Thumbs {
5
+ private readonly glare;
6
+ private readonly container;
7
+ private readonly opts;
8
+ isActive: boolean;
9
+ private readonly axis;
10
+ private readonly strip;
11
+ private readonly list;
12
+ private offs;
13
+ constructor(glare: Glare, container: HTMLElement, opts: ThumbsOptions);
14
+ show(): void;
15
+ hide(): void;
16
+ toggle(): void;
17
+ /** Highlights the thumbnail for `index` and scrolls it into view. */
18
+ focus(index?: number): void;
19
+ destroy(): void;
20
+ private setActive;
21
+ private build;
22
+ }
@@ -0,0 +1,19 @@
1
+ import type { SlideItem } from '../types';
2
+ export interface WheelHost {
3
+ /** `'auto'` only navigates on image slides; `true` on every slide. */
4
+ mode: boolean | 'auto';
5
+ current(): SlideItem | null;
6
+ isZoomed(): boolean;
7
+ next(): void;
8
+ prev(): void;
9
+ }
10
+ /** Mouse-wheel navigation between slides: one gesture moves one slide. */
11
+ export declare class WheelNav {
12
+ private readonly off;
13
+ private distance;
14
+ private fired;
15
+ private settle;
16
+ constructor(stage: HTMLElement, host: WheelHost);
17
+ destroy(): void;
18
+ private restartSettle;
19
+ }
@@ -0,0 +1,7 @@
1
+ export declare const baseTemplate: string;
2
+ export declare const buttonTemplates: Record<string, string>;
3
+ export declare const spinnerTemplate = "<div class=\"glare-spinner\" role=\"status\" aria-label=\"{{LOADING}}\"></div>";
4
+ export declare const errorTemplate = "<div class=\"glare-error\"><p>{{ERROR}}</p></div>";
5
+ export declare const videoTemplate: string;
6
+ export declare const iframeTemplate = "<iframe class=\"glare-iframe\"></iframe>";
7
+ export declare const shareTemplate: string;
package/dist/types.d.ts CHANGED
@@ -1,57 +1,58 @@
1
+ import type { Point, Zoom } from './core/zoom';
2
+ import type { Fullscreen } from './modules/fullscreen';
3
+ import type { Share } from './modules/share';
4
+ import type { Slideshow } from './modules/slideshow';
5
+ import type { Thumbs } from './modules/thumbs';
1
6
  export type ContentType = 'image' | 'video' | 'iframe' | 'inline' | 'ajax' | 'html';
2
- export type AnimationEffect = false | 'fade' | 'zoom' | 'zoom-in-out' | 'slide' | 'circular' | 'tube' | 'rotate';
7
+ /** Effect played when the lightbox opens. */
8
+ export type AnimationEffect = false | 'fade' | 'zoom';
9
+ /** Effect played when moving between slides. */
3
10
  export type TransitionEffect = false | 'fade' | 'slide' | 'circular' | 'tube' | 'zoom-in-out' | 'rotate';
4
- export type ClickAction = false | 'close' | 'next' | 'nextOrClose' | 'toggleControls' | 'zoom' | ((current: SlideItem, event: Event) => ClickAction | void);
5
- export type ToolbarButton = 'zoom' | 'slideshow' | 'thumbs' | 'close' | 'download' | 'share' | 'fullscreen' | string;
11
+ export type ClickActionName = 'close' | 'next' | 'nextOrClose' | 'toggleControls' | 'zoom';
12
+ export type ClickAction = false | ClickActionName | ((current: SlideItem, event: Event) => ClickActionName | false | void);
13
+ export type ToolbarButton = 'zoom' | 'slideshow' | 'thumbs' | 'share' | 'download' | 'fullscreen' | 'close' | (string & {});
6
14
  export interface MediaProvider {
7
15
  matcher: RegExp;
8
- type?: ContentType | 'iframe' | 'image';
16
+ type?: ContentType;
17
+ /** Embed URL; a string may reference capture groups as `$1`. */
9
18
  url?: string | ((match: RegExpMatchArray, url: string) => string);
10
19
  thumb?: string | ((match: RegExpMatchArray, url: string) => string);
11
20
  params?: Record<string, string | number | boolean>;
12
- paramPlace?: number;
13
21
  }
22
+ /** A slide as provided by the user. */
14
23
  export interface SlideSource {
15
24
  src?: string;
16
25
  type?: ContentType;
17
- width?: number | string;
18
- height?: number | string;
19
26
  caption?: string;
27
+ /** Fallback for `caption`. */
20
28
  title?: string;
21
- thumb?: string;
22
29
  alt?: string;
23
- downloadSrc?: string;
24
- html?: string;
25
- content?: string | HTMLElement;
30
+ thumb?: string;
31
+ width?: number | string;
32
+ height?: number | string;
26
33
  poster?: string;
27
34
  format?: string;
28
- preload?: boolean;
29
35
  autoStart?: boolean;
30
- opts?: Partial<GlareOptions>;
36
+ downloadSrc?: string;
37
+ html?: string;
38
+ content?: string | HTMLElement;
31
39
  $trigger?: HTMLElement | null;
32
- [key: string]: unknown;
33
40
  }
41
+ /** A normalized slide with runtime state. */
34
42
  export interface SlideItem extends SlideSource {
35
43
  index: number;
36
- type: ContentType;
37
44
  src: string;
38
- contentEl?: HTMLElement | null;
39
- $content?: HTMLElement | null;
40
- $slide?: HTMLElement | null;
41
- $image?: HTMLImageElement | null;
42
- isLoaded?: boolean;
43
- isComplete?: boolean;
44
- isError?: boolean;
45
- hasError?: boolean;
46
- pos?: number;
47
- width?: number | string;
48
- height?: number | string;
45
+ type: ContentType;
46
+ caption: string;
47
+ isLoaded: boolean;
48
+ hasError: boolean;
49
+ /** The reason the content failed to load, when `hasError` is set. */
50
+ error?: unknown;
49
51
  contentWidth?: number;
50
52
  contentHeight?: number;
51
- scaleX?: number;
52
- scaleY?: number;
53
- canZoomIn?: boolean;
54
- canZoomOut?: boolean;
53
+ $slide?: HTMLElement | null;
54
+ $content?: HTMLElement | null;
55
+ $image?: HTMLImageElement | null;
55
56
  }
56
57
  export interface TouchOptions {
57
58
  vertical?: boolean;
@@ -61,9 +62,7 @@ export interface ImageOptions {
61
62
  preload?: boolean;
62
63
  }
63
64
  export interface AjaxOptions {
64
- settings?: RequestInit & {
65
- data?: Record<string, string>;
66
- };
65
+ settings?: RequestInit;
67
66
  }
68
67
  export interface IframeOptions {
69
68
  preload?: boolean;
@@ -78,7 +77,6 @@ export interface VideoOptions {
78
77
  }
79
78
  export interface ThumbsOptions {
80
79
  autoStart?: boolean;
81
- hideOnClose?: boolean;
82
80
  parentEl?: string | HTMLElement;
83
81
  axis?: 'x' | 'y';
84
82
  }
@@ -93,145 +91,133 @@ export interface ShareOptions {
93
91
  url?: string | ((item: SlideItem) => string);
94
92
  tpl?: string;
95
93
  }
96
- export interface HashOptions {
97
- enabled?: boolean;
98
- }
99
- export interface I18nDict {
94
+ export type I18nDict = {
100
95
  CLOSE: string;
101
96
  NEXT: string;
102
97
  PREV: string;
103
98
  ERROR: string;
99
+ LOADING: string;
100
+ LIGHTBOX: string;
101
+ GO_TO_SLIDE: string;
102
+ VIDEO_UNSUPPORTED: string;
104
103
  PLAY_START: string;
105
104
  PLAY_STOP: string;
106
105
  FULL_SCREEN: string;
106
+ FULL_SCREEN_EXIT: string;
107
107
  THUMBS: string;
108
108
  DOWNLOAD: string;
109
109
  SHARE: string;
110
+ COPY: string;
110
111
  ZOOM: string;
111
- }
112
- export type EventName = 'onInit' | 'beforeLoad' | 'afterLoad' | 'beforeShow' | 'afterShow' | 'beforeClose' | 'afterClose' | 'onActivate' | 'onDeactivate' | 'onUpdate' | 'onReveal' | 'onDestroy';
113
- export type EventHandler = (instance: GlareInstance, current?: SlideItem, ...args: unknown[]) => unknown;
114
- export interface GlareOptions {
112
+ ZOOM_OUT: string;
113
+ };
114
+ /** Events that concern the instance as a whole. */
115
+ export type LifecycleEvent = 'onInit' | 'onActivate';
116
+ /** Events that concern one slide; the handler always receives it. */
117
+ export type SlideEvent = 'beforeLoad' | 'afterLoad' | 'onError' | 'beforeShow' | 'afterShow' | 'onUpdate' | 'beforeClose' | 'afterClose';
118
+ export type EventName = LifecycleEvent | SlideEvent;
119
+ export type LifecycleHandler = (instance: GlareInstance) => unknown;
120
+ export type EventHandler = (instance: GlareInstance, current: SlideItem) => unknown;
121
+ export type EventHandlers = Partial<Record<LifecycleEvent, LifecycleHandler> & Record<SlideEvent, EventHandler>>;
122
+ export interface GlareOptions extends EventHandlers {
115
123
  closeExisting?: boolean;
116
124
  loop?: boolean;
117
- gutter?: number;
118
125
  keyboard?: boolean;
119
- preventCaptionOverlap?: boolean;
126
+ protect?: boolean;
127
+ modal?: boolean;
128
+ idleTime?: number | false;
129
+ hideScrollbar?: boolean;
130
+ autoFocus?: boolean;
131
+ backFocus?: boolean;
132
+ trapFocus?: boolean;
133
+ defaultType?: ContentType;
134
+ parentEl?: string | HTMLElement;
135
+ baseClass?: string;
136
+ slideClass?: string;
120
137
  arrows?: boolean;
121
138
  infobar?: boolean;
122
- smallBtn?: boolean | 'auto';
123
139
  toolbar?: boolean | 'auto';
140
+ smallBtn?: boolean | 'auto';
124
141
  buttons?: ToolbarButton[];
125
- idleTime?: number | false;
126
- protect?: boolean;
127
- modal?: boolean;
128
- image?: ImageOptions;
129
- ajax?: AjaxOptions;
130
- iframe?: IframeOptions;
131
- video?: VideoOptions;
132
- defaultType?: ContentType;
142
+ caption?: string | ((instance: GlareInstance, current: SlideItem) => string);
133
143
  animationEffect?: AnimationEffect;
134
144
  animationDuration?: number;
135
- zoomOpacity?: boolean | 'auto';
145
+ zoomOpacity?: boolean;
136
146
  transitionEffect?: TransitionEffect;
137
147
  transitionDuration?: number;
138
- slideClass?: string;
139
- baseClass?: string;
140
- parentEl?: string | HTMLElement;
141
- hideScrollbar?: boolean;
142
- autoFocus?: boolean;
143
- backFocus?: boolean;
144
- trapFocus?: boolean;
145
- fullScreen?: FullscreenOptions | boolean;
146
- touch?: TouchOptions | false;
147
- hash?: HashOptions | boolean | null;
148
- media?: Record<string, MediaProvider>;
149
- slideShow?: SlideshowOptions | boolean;
150
- thumbs?: ThumbsOptions | boolean;
151
- share?: ShareOptions | boolean;
152
- wheel?: boolean | 'auto' | 'slide';
153
148
  clickContent?: ClickAction;
154
149
  clickSlide?: ClickAction;
155
- clickOutside?: ClickAction;
156
150
  dblclickContent?: ClickAction;
157
151
  dblclickSlide?: ClickAction;
158
- dblclickOutside?: ClickAction;
152
+ wheel?: boolean | 'auto';
153
+ touch?: TouchOptions | false;
154
+ /** Overrides applied on touch-first devices. */
159
155
  mobile?: Partial<GlareOptions>;
156
+ image?: ImageOptions;
157
+ video?: VideoOptions;
158
+ iframe?: IframeOptions;
159
+ ajax?: AjaxOptions;
160
+ media?: Record<string, MediaProvider>;
161
+ hash?: boolean;
162
+ slideshow?: SlideshowOptions | boolean;
163
+ thumbs?: ThumbsOptions | boolean;
164
+ fullscreen?: FullscreenOptions | boolean;
165
+ share?: ShareOptions | boolean;
160
166
  lang?: string;
161
167
  i18n?: Record<string, Partial<I18nDict>>;
162
- caption?: string | ((instance: GlareInstance, current: SlideItem) => string);
163
- onInit?: EventHandler;
164
- beforeLoad?: EventHandler;
165
- afterLoad?: EventHandler;
166
- beforeShow?: EventHandler;
167
- afterShow?: EventHandler;
168
- beforeClose?: EventHandler;
169
- afterClose?: EventHandler;
170
- onActivate?: EventHandler;
171
- onDeactivate?: EventHandler;
172
- onUpdate?: EventHandler;
168
+ baseTpl?: string;
173
169
  btnTpl?: Partial<Record<string, string>>;
174
170
  spinnerTpl?: string;
175
171
  errorTpl?: string;
176
- baseTpl?: string;
177
- [key: string]: unknown;
172
+ }
173
+ type DefaultedKey = Exclude<keyof GlareOptions, keyof EventHandlers | 'caption'>;
174
+ /** Options after the defaults have been merged in: everything but callbacks is present. */
175
+ export type ResolvedOptions = GlareOptions & Required<Pick<GlareOptions, DefaultedKey>> & {
176
+ image: Required<ImageOptions>;
177
+ video: Required<VideoOptions>;
178
+ iframe: Required<IframeOptions>;
179
+ ajax: Required<AjaxOptions>;
180
+ };
181
+ /** Elements of the mounted dialog. `container` and `stage` are required by the base template; the rest are optional chrome. */
182
+ export interface GlareRefs {
183
+ container: HTMLElement;
184
+ bg: HTMLElement | null;
185
+ inner: HTMLElement | null;
186
+ stage: HTMLElement;
187
+ caption: HTMLElement | null;
188
+ toolbar: HTMLElement | null;
189
+ infobar: HTMLElement | null;
190
+ navigation: HTMLElement | null;
178
191
  }
179
192
  export interface GlareInstance {
180
- id: number;
181
- group: SlideItem[];
182
- opts: GlareOptions;
193
+ readonly id: number;
194
+ readonly group: SlideItem[];
195
+ readonly opts: GlareOptions;
196
+ readonly zoom: Zoom;
183
197
  current: SlideItem | null;
184
198
  currIndex: number;
185
199
  prevIndex: number;
186
200
  isActive: boolean;
187
201
  isClosing: boolean;
188
- isAnimating: boolean;
189
- $refs: {
190
- container: HTMLElement | null;
191
- stage: HTMLElement | null;
192
- bg: HTMLElement | null;
193
- inner: HTMLElement | null;
194
- caption: HTMLElement | null;
195
- toolbar: HTMLElement | null;
196
- infobar: HTMLElement | null;
197
- navigation: HTMLElement | null;
198
- };
199
- open: (index?: number) => void;
200
- close: (event?: Event | null, duration?: number) => void;
201
- next: (duration?: number) => void;
202
- previous: (duration?: number) => void;
203
- prev: (duration?: number) => void;
204
- jumpTo: (index: number, duration?: number) => void;
205
- scaleToFit: (duration?: number) => void;
206
- scaleToActual: (x?: number, y?: number, duration?: number) => void;
207
- update: () => void;
208
- focus: () => void;
209
- toggleControls: (force?: boolean) => void;
210
202
  isIdle: boolean;
211
- SlideShow?: {
212
- start: () => void;
213
- stop: () => void;
214
- toggle: () => void;
215
- isActive: () => boolean;
216
- };
217
- Thumbs?: {
218
- show: () => void;
219
- hide: () => void;
220
- toggle: () => void;
221
- focus: (index?: number) => void;
222
- isActive: boolean;
223
- };
224
- FullScreen?: {
225
- request: () => void;
226
- exit: () => void;
227
- toggle: () => void;
228
- isFullscreen: () => boolean;
229
- };
203
+ /** Null while the lightbox is closed. */
204
+ $refs: GlareRefs | null;
205
+ slideshow?: Slideshow;
206
+ thumbs?: Thumbs;
207
+ fullscreen?: Fullscreen;
208
+ share?: Share;
209
+ open(index?: number): void;
210
+ close(): void;
211
+ next(): void;
212
+ prev(): void;
213
+ jumpTo(index: number): void;
214
+ toggleZoom(focus?: Point): void;
215
+ update(): void;
216
+ focus(): void;
217
+ toggleControls(force?: boolean): void;
230
218
  }
231
219
  export interface BoundGroup {
232
- selector: string;
233
- options: GlareOptions;
234
220
  elements: HTMLElement[];
235
221
  destroy: () => void;
236
222
  }
237
- //# sourceMappingURL=types.d.ts.map
223
+ export {};
package/dist/umd.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import './styles/index.css';
2
+ import { Glare } from './core/glare';
3
+ export default Glare;
@@ -0,0 +1,20 @@
1
+ export declare function $(selector: string, root?: ParentNode): HTMLElement | null;
2
+ export declare function $$(selector: string, root?: ParentNode): HTMLElement[];
3
+ export declare function createEl<K extends keyof HTMLElementTagNameMap>(tag: K, className?: string, html?: string): HTMLElementTagNameMap[K];
4
+ /** Parses an HTML string and returns its first element. */
5
+ export declare function fromHtml(html: string): HTMLElement;
6
+ /** Strips markup from an HTML string, for labels that must be plain text. */
7
+ export declare function toText(html: string): string;
8
+ /** Resolves a selector or element, searching `root` first and then the document. */
9
+ export declare function resolveElement(target: string | HTMLElement | null | undefined, root?: ParentNode): HTMLElement | null;
10
+ export declare function toCssSize(value: number | string): string;
11
+ /** Adds an event listener and returns a function that removes it. */
12
+ export declare function on<K extends keyof GlobalEventHandlersEventMap>(target: EventTarget, type: K, handler: (event: GlobalEventHandlersEventMap[K]) => void, options?: boolean | AddEventListenerOptions): () => void;
13
+ export declare function on(target: EventTarget, type: string, handler: EventListener, options?: boolean | AddEventListenerOptions): () => void;
14
+ /** Runs `callback` after the browser has painted the current frame. */
15
+ export declare function nextFrame(callback: () => void): void;
16
+ /**
17
+ * Runs `done` exactly once when a transition on `el` ends,
18
+ * or after `duration` as a fallback for transitions that never fire.
19
+ */
20
+ export declare function afterTransition(el: HTMLElement, duration: number, done: () => void): void;
@@ -0,0 +1,5 @@
1
+ export declare function isMobile(): boolean;
2
+ export declare function prefersReducedMotion(): boolean;
3
+ export declare function supportsFullscreen(): boolean;
4
+ /** Locks page scrolling while compensating for the scrollbar width. */
5
+ export declare function lockScroll(lock: boolean): void;
@@ -0,0 +1,3 @@
1
+ /** Recursively merges plain objects; other values (arrays, elements, RegExps) are replaced. */
2
+ export declare function deepMerge<T extends object>(...sources: Array<object | null | undefined | false>): T;
3
+ export declare function clamp(value: number, min: number, max: number): number;
@@ -0,0 +1,5 @@
1
+ /** Replaces `{{key}}` placeholders with values from `dict`. */
2
+ export declare function translate(template: string, dict: Record<string, string>): string;
3
+ export declare function buildQuery(params: Record<string, string | number | boolean>): string;
4
+ /** Expands `$1`-style capture references from a RegExp match. */
5
+ export declare function expandMatch(template: string, match: RegExpMatchArray): string;