### Install bigger-picture with npm Source: https://github.com/henrygd/bigger-picture/blob/main/readme.md Install the bigger-picture package via npm. ```bash npm install bigger-picture ``` -------------------------------- ### onOpen option example Source: https://github.com/henrygd/bigger-picture/blob/main/readme.md Adds a custom class to the gallery container just before the intro animation starts. The callback receives the container element and the active item object. ```javascript bp.open({ onOpen: (container) => container.classList.add('custom-class'), }) ``` -------------------------------- ### Responsive Image Example: srcset via data-img attribute Source: https://github.com/henrygd/bigger-picture/blob/main/public/index.html HTML anchor for a responsive image using a srcset value passed as data-img. The sizes attribute is automatically updated when image dimensions change; you can also set your own sizes. The example uses three sizes (1300, 2500, 6000 pixels) with the 1300px image as the starting image on small screens, 2500px on most laptops/desktops, and 6000px on very high resolution monitors or when zooming past the 2500px size. ```html map of critical role's exandria ``` -------------------------------- ### next() example Source: https://github.com/henrygd/bigger-picture Shows opening a gallery and calling bp.next() to move to the next item. ```javascript bp.open({ items: nodes }) bp.next() // third item if starting position was 2 ``` -------------------------------- ### open() options Source: https://github.com/henrygd/bigger-picture Configuration options for the open() function in Bigger Picture. These options control the gallery's data source, starting position, scaling, callbacks, and more. ```APIDOC ## open() options ### Description Configuration options for the `open()` function in Bigger Picture. These options control the gallery's data source, starting position, scaling, callbacks, and more. ### Parameters #### Options Object - **items** (HTMLElement | HTMLCollection | NodeList | item[]) - Required - Data source. DOM nodes/collections read item properties from `data-*` attributes; arrays use object items. - **el** (HTMLElement | EventTarget) - Optional - Start the gallery at the item matching this node (or an item's `element`). Typical usage: `event.currentTarget` in a click handler. Overrides `position`. - **position** (number) - Optional - Zero-indexed starting position. Ignored when `el` matches. Default: `0`. - **scale** (number) - Optional - Controls displayed item size; `1` fills to screen edges. Default: `0.99`. - **intro** (string) - Optional - Overrides default scale intro. Only `'fadeup'` (a vertical `fly` transition) is currently supported. - **inline** (boolean) - Optional - Inline mode. Disables the `keydown` listener and `bp-lock` scroll-lock. Default: `false`. - **noClose** (boolean) - Optional - Hides the close button (`.bp-noclose .bp-x { display: none }`) and blocks Escape/overlay close; only `close()` closes. Default: `false`. - **noPinch** (() => any) - Optional - Called at pinch time with `container` (wrapper element); truthy return disables pinch zoom. - **focusWrap** (HTMLElement | EventTarget) - Optional - Element to trap Tab focus within. Default: gallery wrapper (`container.el`). - **maxZoom** (number) - Optional - Global image maximum zoom multiplier. Effective per-item value: `activeItem.maxZoom || opts.maxZoom || 10`. `1` disables zoom. Default: `10`. - **sizes** (string) - Optional - Global `sizes` attribute override for `srcset` images. Without it, sizes are computed from rendered dimensions (and grow on zoom). - **onOpen** ((container: HTMLElement, activeItem: activeItem) => void) - Optional - Runs just before intro animation. - **onUpdate** ((container?: HTMLElement, activeItem?: activeItem) => void) - Optional - Runs after active item updates. - **onClose** ((container?: HTMLElement, activeItem?: activeItem) => void) - Optional - Runs just before outro animation. - **onClosed** (() => void) - Optional - Runs after removal from the page. - **onResize** ((container?: HTMLElement, activeItem?: activeItem) => void) - Optional - Runs when gallery dimensions change via `ResizeObserver`. - **onImageClick** ((container?: HTMLElement, activeItem?: activeItem) => any) - Optional - Runs on image click; truthy return prevents zoom toggling. - **onError** ((container?: HTMLElement, activeItem?: activeItem, error?: Error) => void) - Optional - Runs when an item errors while loading. ### Callback defaults and argument semantics - `container` is the gallery's wrapper element (`.bp-wrap`) for all callbacks except `onError`, which receives the internal `container` object (`{ el, w, h }`). - Callbacks are invoked with optional chaining (`opts.onOpen?.`, etc.), so omitting them is always safe. ``` -------------------------------- ### Example: opening with NodeList and array of objects Source: https://github.com/henrygd/bigger-picture Shows two ways to call open: passing a NodeList (data attributes supply item data) and passing an array of objects with optional el, maxZoom, and element for animation origin. ```javascript let bp = BiggerPicture({ target: document.body }) // passing items as a NodeList (data attributes supply item data) bp.open({ items: document.querySelectorAll('#images a'), }) // passing items as an array of objects bp.open({ el: event.currentTarget, // start at the clicked node maxZoom: 3, items: [ { img: 'example.jpg', thumb: 'example_thumb.jpg', alt: 'Example', height: 2500, width: 1667, element: document.querySelector('#thumb-1'), // animation origin }, ], }) ``` -------------------------------- ### Example usage of setPosition Source: https://github.com/henrygd/bigger-picture Example showing how to open a gallery and jump to the fourth item using setPosition(3). ```javascript bp.open({ items: nodes }) // jump to the fourth item bp.setPosition(3) ``` -------------------------------- ### onUpdate option example Source: https://github.com/henrygd/bigger-picture/blob/main/readme.md Logs the container and active item data whenever the active item is updated. The callback is executed just after the update and receives the container and activeItem. ```javascript bp.open({ onUpdate(container, activeItem) { console.log('container', container) console.log('activeItem', activeItem) }, }) ``` -------------------------------- ### addAttributes usage example with object Source: https://github.com/henrygd/bigger-picture Example of importing addAttributes from 'bigger-picture/svelte/stores' and applying an object of attributes to an image element. ```javascript import { addAttributes } from 'bigger-picture/svelte/stores' addAttributes(img, { loading: 'lazy', decoding: 'async' }) ``` -------------------------------- ### close() example with event listener Source: https://github.com/henrygd/bigger-picture Shows opening a gallery and attaching a click listener to a close button to call bp.close(). ```javascript let bp = BiggerPicture({ target: document.body }) bp.open({ items: nodes }) // imperative close (also reachable via Esc, close button, or overlay click unless noClose is set) document.querySelector('#close-btn').addEventListener('click', () => bp.close()) ``` -------------------------------- ### getThumbBackground usage example Source: https://github.com/henrygd/bigger-picture Example of using getThumbBackground to set a node's backgroundImage. The comment shows the resulting value. ```javascript import { getThumbBackground } from 'bigger-picture/svelte/stores' node.style.backgroundImage = getThumbBackground({ thumb: 'thumbs/1.jpg' }) // => "url(thumbs/1.jpg)" ``` -------------------------------- ### closing store usage example Source: https://github.com/henrygd/bigger-picture Subscribe to the closing store to react to gallery closing state. Unsubscribe when done. ```js import { closing } from 'bigger-picture/svelte/stores' const unsubscribe = closing.subscribe((value) => { console.log('is closing', value) }) // ...later unsubscribe() ``` -------------------------------- ### JavaScript initialization and click handling for BiggerPicture Source: https://github.com/henrygd/bigger-picture/blob/main/public/index.html Initializes BiggerPicture with a target of document.body, selects image links, and adds a click listener that opens the gallery with the clicked element as the starting point. The openGallery function prevents default link behavior and calls bp.open with the image links and current target. ```javascript // initialize let bp = BiggerPicture({ target: document.body, }) // grab image links let imageLinks = document.querySelectorAll('#images > a') // add click listener to open BiggerPicture for (let link of imageLinks) { link.addEventListener("click", openGallery); } // function to open BiggerPicture function openGallery(e) { e.preventDefault() bp.open({ items: imageLinks, el: e.currentTarget, }) } ``` -------------------------------- ### prev() and next() custom buttons example Source: https://github.com/henrygd/bigger-picture Shows wiring custom prev and next buttons to call bp.prev() and bp.next(). ```javascript // wiring custom prev/next buttons on top of the gallery prevBtn.addEventListener('click', () => bp.prev()) nextBtn.addEventListener('click', () => bp.next()) ``` -------------------------------- ### prefersReducedMotion usage example Source: https://github.com/henrygd/bigger-picture Use the constant to skip animations in your own integration code when the user prefers reduced motion. ```js import { prefersReducedMotion } from 'bigger-picture/svelte/stores' if (prefersReducedMotion) { // skip animations in your own integration code } ``` -------------------------------- ### HTML markup for basic gallery with data-* attributes Source: https://github.com/henrygd/bigger-picture/blob/main/public/index.html Defines a container with an anchor and image element. The anchor uses data-* attributes (data-img, data-thumb, data-alt, data-height, data-width) to supply image data to BiggerPicture. This is the HTML structure used in the basic gallery example. ```html
image description
``` -------------------------------- ### Video and Embed Example: HTML data attributes and JavaScript initialization Source: https://github.com/henrygd/bigger-picture/blob/main/public/index.html HTML markup for video and iframe embed links using data attributes (data-sources, data-tracks, data-iframe) to pass data to BiggerPicture. The JavaScript initializes BiggerPicture, attaches click listeners to all links, and opens the media on click. For native video/audio, provide a sources array with src and type (mime); a JSON-parsable string is also accepted. Tracks option adds captions. Width/height default to 1920/1080. ```html video description Uebok youtube embed ``` ```javascript // initialize BiggerPicture let bp = BiggerPicture({ target: document.body }); // grab image links let links = document.querySelectorAll("a"); // add click listener on links to open BiggerPicture for (let link of links) { link.addEventListener("click", openBiggerPicture); } // function to open BiggerPicture function openBiggerPicture(e) { e.preventDefault(); bp.open({ items: e.currentTarget, el: e.currentTarget }); } ``` -------------------------------- ### defaultTweenOptions usage example Source: https://github.com/henrygd/bigger-picture Example of using defaultTweenOptions with a tweened store from svelte/motion. Imports the function from 'bigger-picture/svelte/stores'. ```javascript import { defaultTweenOptions } from 'bigger-picture/svelte/stores' import { tweened } from 'svelte/motion' const size = tweened([100, 100], defaultTweenOptions(400)) ``` -------------------------------- ### Mount component in onOpen for html item Source: https://github.com/henrygd/bigger-picture/blob/main/readme.md Mount a component inside the container when the item opens. Pass an empty string to the html property and use the onOpen method to target the .bp-html element. This example mounts a Svelte component named Firewatch. ```js // mounting svelte component (firewatch example from demo site) onOpen(container) { new Firewatch({ target: container.querySelector('.bp-html'), }) }, ``` -------------------------------- ### noPinch option example Source: https://github.com/henrygd/bigger-picture/blob/main/readme.md Disables pinch zoom when the gallery container width is less than 800 pixels. The function receives the gallery's wrapper element and must return a truthy value to disable pinch zoom. ```javascript bp.open({ noPinch: (container) => container.clientWidth < 800, }) ``` -------------------------------- ### Example: error handling via onError option Source: https://github.com/henrygd/bigger-picture Shows how to use the onError callback to handle load failures, logging the error with the active item's index. ```javascript // error handling via the onError option bp.open({ items: galleryItems, onError: (container, activeItem, error) => { console.error(`Failed to load item at index ${activeItem.i}`, error) }, }) ``` -------------------------------- ### options Source: https://github.com/henrygd/bigger-picture Configuration object for opening a Bigger Picture lightbox. It defines the items to display, optional starting position, scale, callbacks, and other behavior modifiers. ```APIDOC ## options ### Description Configuration object for opening a Bigger Picture lightbox. It defines the items to display, optional starting position, scale, callbacks, and other behavior modifiers. ### Fields - **items** (HTMLElement | HTMLCollection | NodeList | item[]) - Required - Data source for displayed items. `HTMLElement`/`HTMLCollection`/`NodeList` items read properties from `data-*` attributes; array items are plain objects (see `item`). - **el** (HTMLElement | EventTarget) - Optional - If it matches an item node (or an item's `element` value), the gallery starts at that position. E.g. `event.target` in a click handler. - **position** (number) - Optional - Zero-indexed start position. Ignored when `el` is used. - **scale** (number) - Optional - Size of displayed item; `1` fills to screen edges. - **intro** (string) - Optional - Overrides default intro animation. Only `'fadeup'` is currently supported. - **inline** (boolean) - Optional - Marks the lightbox inline; interaction events are modified to avoid hijacking scroll and tab. - **noClose** (boolean) - Optional - Hides the close button (`.bp-noclose .bp-x { display: none }`) and prevents closing except via the `close()` method. - **noPinch** (() => any) - Optional - Executed at pinch time; return a truthy value to disable pinch zoom. Receives `container` (the wrapper `HTMLElement`). - **focusWrap** (HTMLElement | EventTarget) - Optional - Wrapper element to trap focus within on Tab. Defaults to the gallery's own wrapper. - **maxZoom** (number) - Optional - Cap for image zoom as a multiple of the starting size. Item-level `maxZoom` overrides. - **onOpen** ((container: HTMLElement, activeItem: activeItem) => void) - Optional - Runs just before the intro animation. - **onUpdate** ((container?: HTMLElement, activeItem?: activeItem) => void) - Optional - Runs just after the active item updates. - **onClose** ((container?: HTMLElement, activeItem?: activeItem) => void) - Optional - Runs just before the outro animation. - **onClosed** (() => void) - Optional - Runs just after the lightbox is closed and removed. - **onResize** ((container?: HTMLElement, activeItem?: activeItem) => void) - Optional - Runs when gallery (not window) dimensions change, via `ResizeObserver`. - **onImageClick** ((container?: HTMLElement, activeItem?: activeItem) => any) - Optional - Runs on image click. A truthy return prevents zooming. - **onError** ((container?: HTMLElement, activeItem?: activeItem, error?: Error) => void) - Optional - Runs when loading an item (image, audio, video, iframe) errors. ### Note > **Note on `container` in `onError`:** the declared type is `HTMLElement`, but the image and video components pass their internal `container` prop object (`{ el, w, h }`, where `el` is the wrapper element) — see `src/components/image.svelte:388` and `src/components/video.svelte:51`. All other callbacks receive `container.el` (the wrapper `HTMLElement`). ### Used by - `BiggerPictureInstance.open(options: options)` — the parameter type. ``` -------------------------------- ### addAttributes usage example with JSON string Source: https://github.com/henrygd/bigger-picture Example of using addAttributes with a JSON string, which is parsed with JSON.parse. The string form matches a data-attr HTML attribute value. ```javascript // JSON string form — same shape as a data-attr HTML attribute value addAttributes(img, '{"crossorigin": "anonymous", "referrerpolicy": "no-referrer"}') ``` -------------------------------- ### Inline Gallery Example: HTML container and JavaScript object data Source: https://github.com/henrygd/bigger-picture/blob/main/public/index.html HTML container for an inline gallery and JavaScript that supplies data via a JavaScript object. Use the inline option with scale, intro, and noClose settings as shown. The items array contains image objects with img, thumb, height, width, and alt properties. ```html ``` ```javascript // example data let items = [ { img: "https://assets.henrygd.me/bp/images/janko-ferlic-SDivo1PTBDs-unsplash.jpg", thumb: "https://assets.henrygd.me/bp/images/janko-ferlic-SDivo1PTBDs-unsplash_thumb.jpg", height: "2000", width: "3000", alt: "wildlife photography of brown bear cub" }, { img: "https://assets.henrygd.me/bp/images/corey-agopian-5y4ljzRrDFA-unsplash.jpg", thumb: "https://assets.henrygd.me/bp/images/corey-agopian-5y4ljzRrDFA-unsplash_thumb.jpg", height: "2000", width: "3000", alt: "palm trees under clear blue sky" }, ]; // initialize BiggerPicture let bp = BiggerPicture({ target: document.getElementById("inline") }); // open inline gallery bp.open({ items, inline: true, scale: 1, intro: "fadeup", noClose: true, }); ``` -------------------------------- ### data-tracks attribute for video captions Source: https://github.com/henrygd/bigger-picture/blob/main/readme.md Use the data-tracks attribute to add text tracks (e.g., captions) to videos. The value is a JSON array of track objects; each object creates a track element. This example passes English and Spanish captions. ```html
``` -------------------------------- ### instance.open(options) Source: https://github.com/henrygd/bigger-picture Opens the lightbox with the given options. Accepts an options object that defines the items to display and other settings. ```APIDOC ## instance.open(options) ### Description Opens the lightbox with the given options. Accepts an options object that defines the items to display and other settings. ### Method Method ### Parameters #### Options - **options** (object) - Required - Options for opening the lightbox (see `options` type). ### Returns - **void** - No return value. ``` -------------------------------- ### Initialize and open bigger-picture lightbox Source: https://github.com/henrygd/bigger-picture/blob/main/readme.md Initialize the lightbox and open it with items from the DOM. The target element is document.body, and the items are selected via querySelectorAll. ```javascript import BiggerPicture from 'bigger-picture' // initialize let bp = BiggerPicture({ target: document.body, }) // open (will be a child of the target element above) bp.open({ items: document.querySelectorAll('#images a'), }) ``` -------------------------------- ### open(options) Source: https://github.com/henrygd/bigger-picture Opens the lightbox with the given options. Renders the gallery as a child of the instance's target. Accepts a full options object and returns void. ```APIDOC ## open(options) ### Description Opens the lightbox with the given options. Renders the gallery as a child of the instance's target. ### Method open ### Signature Source (`src/bigger-picture.svelte:72`): ```js export const open = (options) => { opts = options inline = opts.inline // add class to hide scroll if not inline gallery if (!inline && html.scrollHeight > html.clientHeight) { html.classList.add('bp-lock') } // update trigger element to restore focus focusTrigger = document.activeElement container.w = target.offsetWidth container.h = target === document.body ? window.innerHeight : target.clientHeight smallScreen = container.w < 769 position = opts.position || 0 // set items items = [] for (let i = 0; i < (opts.items.length || 1); i++) { let item = opts.items[i] || opts.items if ('dataset' in item) { items.push({ element: item, i, ...item.dataset }) } else { item.i = i items.push(item) // set item to element for position check below item = item.element } // override gallery position if needed if (opts.el && opts.el === item) { position = i } } } ``` TypeScript declaration (`index.d.ts:108`): ```ts open: (options: options) => void ``` ### Parameters | Parameter | Type | Required | Default | Description | |-----------|------|----------|---------|-------------| | `options` | [`options`](../types.md#options) | yes | — | Full options object; see [configuration.md](../configuration.md). | ### Behavior details (from source) - `position` defaults to `opts.position || 0`; ignored when `opts.el` matches an item (the matched index wins). - `items` normalization: a DOM node / `NodeList` item is converted to `{ element: item, i, ...item.dataset }` (data attributes become item properties, e.g. `data-img` → `img`). Plain objects are pushed as-is (mutated with `i = `), and matched against `opts.el` via their `element` property. - Passing a single node as `items` works: `opts.items.length` is `undefined`, so the loop runs once with `item = opts.items[i] || opts.items`. - Adds the `bp-lock` class to `` when the page scrolls and the gallery is not inline (removed on destroy). - `smallScreen` = `container.w < 769` (drives swipe/drag behaviors and the `bp-small` class). ### Return type `void`. ### Throws None. Errors are internal and reported through the `onError` option callback (see below). ### Request Example ```js let bp = BiggerPicture({ target: document.body }) // passing items as a NodeList (data attributes supply item data) bp.open({ items: document.querySelectorAll('#images a'), }) // passing items as an array of objects bp.open({ el: event.currentTarget, // start at the clicked node maxZoom: 3, items: [ { img: 'example.jpg', thumb: 'example_thumb.jpg', alt: 'Example', height: 2500, width: 1667, element: document.querySelector('#thumb-1'), // animation origin }, ], }) ``` ```js // error handling via the onError option bp.open({ items: galleryItems, onError: (container, activeItem, error) => { console.error(`Failed to load item at index ${activeItem.i}`, error) }, }) ``` ``` -------------------------------- ### instance.prev() Source: https://github.com/henrygd/bigger-picture Navigates to the previous item in the gallery. ```APIDOC ## instance.prev() ### Description Navigates to the previous item in the gallery. ### Method Method ### Parameters None ### Returns - **void** - No return value. ``` -------------------------------- ### instance.next() Source: https://github.com/henrygd/bigger-picture Navigates to the next item in the gallery. ```APIDOC ## instance.next() ### Description Navigates to the next item in the gallery. ### Method Method ### Parameters None ### Returns - **void** - No return value. ``` -------------------------------- ### instance.next() / instance.prev() Source: https://github.com/henrygd/bigger-picture Changes to the next or previous item in the gallery, wrapping around at the ends. These methods are used to navigate through the gallery items imperatively. ```APIDOC ## instance.next() / instance.prev() ### Description Changes to the next or previous item in the gallery, wrapping around at the ends. These methods are used to navigate through the gallery items imperatively. ### Method next / prev ### Endpoint instance.next() / instance.prev() ### Parameters None. ### Response #### Success Response - **Return type**: `void` ### Request Example ```js bp.open({ items: nodes }) bp.next() // third item if starting position was 2 ``` ```js // wiring custom prev/next buttons on top of the gallery prevBtn.addEventListener('click', () => bp.prev()) nextBtn.addEventListener('click', () => bp.next()) ``` ``` -------------------------------- ### Bigger Picture Options Source: https://github.com/henrygd/bigger-picture/blob/main/readme.md Documentation for the options object passed to the Bigger Picture open method. ```APIDOC ## [OPTIONS] Bigger Picture Options ### Description Configuration options for the Bigger Picture lightbox gallery. These options are passed to the `open` method to customize behavior. ### Options #### items - **Type**: `NodeList` or `Node` or `Array` - **Required**: Yes - **Description**: The data source for the displayed items. See Item Properties for details. If using NodeList or Node, the information is passed via data attributes. If using Array, the information is passed via object. #### el - **Type**: `Node` - **Default**: `undefined` - **Description**: If the specified node matches a node in `items` (or matches the `element` value on an item if using an array), the gallery will start at that position. For example, you could use this inside a click handler by passing `event.target`. #### position - **Type**: `number` - **Default**: `0` - **Description**: Start position of gallery. If using `el` this will be ignored. This number is zero-indexed. The third item would be position 2. #### scale - **Type**: `number` - **Default**: `0.99` - **Description**: Controls the size of the displayed item. Use `1` to fill item to screen edges. #### intro - **Type**: `string` - **Default**: `undefined` - **Description**: Overrides the default intro animation. Currently `fadeup` is the only alternative. #### inline - **Type**: `boolean` - **Default**: `false` - **Description**: Specifies that the lightbox is inline. Interaction events are modified to avoid hijacking scroll and tab press. The container element for an inline gallery should be set to position: relative. #### noClose - **Type**: `boolean` - **Default**: `false` - **Description**: Hides the close button and prevents the lightbox from closing unless the `close` method is called. Recommended to use in combination with an inline gallery. #### noPinch - **Type**: `function` - **Description**: Return a truthy value to disable pinch zoom. Function is executed at the time of the pinch. Supplies `container` - the gallery's wrapper element. #### focusWrap - **Type**: `node` - **Description**: Specify wrapper element to trap focus within on tab press. Useful when mounting a gallery inside a custom layout. #### maxZoom - **Type**: `number` - **Default**: `10` - **Description**: Restricts an image's maximum zoom to `maxZoom` times the starting size, even if the item's `width` / `height` is larger. For example, a `maxZoom` of 2 on an image that starts at 800px width would limit the image to a maximum zoom of 1600px width. A `maxZoom` of 1 would prevent zooming entirely. If `maxZoom` is set on an individual item it will override the value set in options. #### onOpen - **Type**: `function` - **Description**: Executes just before intro animation. Supplies `container` - the gallery's wrapper element, and `activeItem` - an object containing the currently displayed item's data. #### onUpdate - **Type**: `function` - **Description**: Executes just after the active item is updated. Supplies `container` and `activeItem`. #### onClose - **Type**: `function` - **Description**: Executes just before outro animation. Supplies `container` and `activeItem`. #### onClosed - **Type**: `function` - **Description**: Executes just after the lightbox has been closed and removed from the page. #### onResize - **Type**: `function` - **Description**: Executes when the dimensions of the gallery (not the window) are changed. Supplies `container` and `activeItem`. #### onImageClick - **Type**: `function` - **Description**: Executes when an image is clicked. Return a truthy value to prevent zooming. Supplies `container` and `activeItem`. This method was added to make it easier to open a full screen instance when an image is clicked within an inline gallery, but could be used for other purposes. #### onError - **Type**: `function` - **Description**: Executes if an error is thrown when loading an image, audio, or video item. Supplies `container`, `activeItem` and `error`. ### Example Usage ```js bp.open({ noPinch: (container) => container.clientWidth < 800, }) ``` ```js bp.open({ onOpen: (container) => container.classList.add('custom-class'), }) ``` ```js bp.open({ onUpdate(container, activeItem) { console.log('container', container) console.log('activeItem', activeItem) }, }) ``` ``` -------------------------------- ### instance.target Source: https://github.com/henrygd/bigger-picture Property that holds the target element that triggered the lightbox. ```APIDOC ## instance.target ### Description Property that holds the target element that triggered the lightbox. ### Type - **Element** - The DOM element that opened the lightbox. ``` -------------------------------- ### open function source (src/bigger-picture.svelte:72) Source: https://github.com/henrygd/bigger-picture Core implementation of the open method. Initializes options, adds 'bp-lock' class to html when not inline and page scrolls, sets container dimensions, normalizes items (DOM nodes/NodeList to objects with dataset, plain objects mutated with index), and overrides position if opts.el matches an item. ```javascript export const open = (options) => { opts = options inline = opts.inline // add class to hide scroll if not inline gallery if (!inline && html.scrollHeight > html.clientHeight) { html.classList.add('bp-lock') } // update trigger element to restore focus focusTrigger = document.activeElement container.w = target.offsetWidth container.h = target === document.body ? window.innerHeight : target.clientHeight smallScreen = container.w < 769 position = opts.position || 0 // set items items = [] for (let i = 0; i < (opts.items.length || 1); i++) { let item = opts.items[i] || opts.items if ('dataset' in item) { items.push({ element: item, i, ...item.dataset }) } else { item.i = i items.push(item) // set item to element for position check below item = item.element } // override gallery position if needed if (opts.el && opts.el === item) { position = i } } } ``` -------------------------------- ### BiggerPictureInstance.open Source: https://github.com/henrygd/bigger-picture Opens the gallery with the given options. This method is part of the BiggerPictureInstance interface returned by the default export. ```APIDOC ## BiggerPictureInstance.open ### Description Opens the gallery with the given options. ### Method open ### Parameters - **options** (options) - Required - Options for opening the gallery. ### Response Returns void. ``` -------------------------------- ### target Source: https://github.com/henrygd/bigger-picture The parent element the gallery is mounted within (the `target` passed to the factory). ```APIDOC ## target ### Description The parent element the gallery is mounted within (the `target` passed to the factory). ### Type `HTMLElement` ``` -------------------------------- ### Initialize BiggerPicture with a single target Source: https://github.com/henrygd/bigger-picture Creates one instance per target, mounting the gallery at document.body. The instance is then used to open a gallery with items. ```javascript import BiggerPicture from 'bigger-picture' // initialize one instance per target; mounts at document.body let bp = BiggerPicture({ target: document.body, }) ``` -------------------------------- ### instance.close() Source: https://github.com/henrygd/bigger-picture Closes the lightbox if it is open. ```APIDOC ## instance.close() ### Description Closes the lightbox if it is open. ### Method Method ### Parameters None ### Returns - **void** - No return value. ``` -------------------------------- ### Open Bigger Picture with item data and element for animation Source: https://github.com/henrygd/bigger-picture/blob/main/readme.md Use this snippet to open Bigger Picture with custom item data. Add an `element` property to each item to control the default open/close animation; the active item's element is where the animation opens from and closes to. This property is not needed if you're not using the default scale animation. ```js bp.open({ items: [ { img: 'example.jpg', thumb: 'example_thumb.jpg', alt: 'Example', height: 2500, width: 1667, // if you're using the default intro animation element: node, }, ], }) ``` -------------------------------- ### items Source: https://github.com/henrygd/bigger-picture Array of all items in the currently active gallery (normalized `item` objects, each given an `i` index during `open()`). `null`/`undefined` while closed. ```APIDOC ## items ### Description Array of all items in the currently active gallery (normalized `item` objects, each given an `i` index during `open()`). `null`/`undefined` while closed. ### Type `item[]` ``` -------------------------------- ### data-sources attribute for video/audio sources Source: https://github.com/henrygd/bigger-picture/blob/main/readme.md Use the data-sources attribute to define multiple video or audio sources for a media item. Each object in the array requires a src and may include a type; all key/value pairs become attributes on the generated source element. The value can also be a JSON-parsable string. ```html
``` -------------------------------- ### TypeScript declaration for open (index.d.ts:108) Source: https://github.com/henrygd/bigger-picture Type signature for the open method, accepting an options object and returning void. ```typescript open: (options: options) => void ``` -------------------------------- ### instance.close() Source: https://github.com/henrygd/bigger-picture Closes the lightbox. It runs the onClose callback before the outro animation, sets the closing store to true, tears down the gallery markup, and restores focus to the trigger element. ```APIDOC ## instance.close() ### Description Closes the lightbox. It runs the onClose callback before the outro animation, sets the closing store to true, tears down the gallery markup, and restores focus to the trigger element. ### Method close ### Endpoint instance.close() ### Parameters None. ### Response #### Success Response - **Return type**: `void` ### Request Example ```js let bp = BiggerPicture({ target: document.body }) bp.open({ items: nodes }) // imperative close (also reachable via Esc, close button, or overlay click unless noClose is set) document.querySelector('#close-btn').addEventListener('click', () => bp.close()) ``` Can be used with `noClose: true` — the only documented way to close such a gallery: ```js bp.open({ items: nodes, noClose: true, inline: true, }) // close from app code setTimeout(() => bp.close(), 5000) ``` ``` -------------------------------- ### closing Source: https://github.com/henrygd/bigger-picture Svelte store that indicates whether the lightbox is closing. ```APIDOC ## closing ### Description Svelte store that indicates whether the lightbox is closing. ### Type - **Writable** - A writable store with a numeric value. ``` -------------------------------- ### Basic gallery HTML markup Source: https://github.com/henrygd/bigger-picture/blob/main/readme.md HTML markup for a basic gallery. Each anchor element provides the image data via data attributes and contains a thumbnail image. ```html ``` -------------------------------- ### instance.items Source: https://github.com/henrygd/bigger-picture Property that holds the current items array. ```APIDOC ## instance.items ### Description Property that holds the current items array. ### Type - **Array** - The items currently displayed in the lightbox. ``` -------------------------------- ### closing Source: https://github.com/henrygd/bigger-picture A Svelte writable store that tracks whether the gallery is closing. Subscribe to it to react to closing state changes. ```APIDOC ## closing ### Description Svelte writable store tracking whether the gallery is in the process of closing. ### Type `Writable` (from `svelte/store`). Value is `0` (idle) or `1`/truthy — the parent component sets it with `closing.set(true)` during `close()` and `closing.set(false)` when the gallery is destroyed. ### Behavior Set to `true` when `instance.close()` runs; reset to `false` in the wrapper's `destroy()` hook. The image component reacts to it to zoom the image back out while closing. ### Request Example ```js import { closing } from 'bigger-picture/svelte/stores' const unsubscribe = closing.subscribe((value) => { console.log('is closing', value) }) // ...later unsubscribe() ``` ``` -------------------------------- ### close() with noClose: true Source: https://github.com/henrygd/bigger-picture Shows opening a gallery with noClose and inline options, then closing it from app code after a timeout. ```javascript bp.open({ items: nodes, noClose: true, inline: true, }) // close from app code setTimeout(() => bp.close(), 5000) ``` -------------------------------- ### BiggerPicture(options) Source: https://github.com/henrygd/bigger-picture Factory function that initializes a BiggerPicture instance. It accepts an options object with a target element and returns an instance with methods like open, close, next, prev, and setPosition. ```APIDOC ## BiggerPicture(options) ### Description Initializes a BiggerPicture instance. The options object must contain a `target` element where the gallery will be mounted. ### Method Factory function (default export) ### Parameters - `options` (initObject) - Required - Must contain `target` (HTMLElement) - the parent element inside which the gallery will be mounted. Any extra keys are spread into the Svelte component instance. ### Return Type BiggerPictureInstance - an object with methods `open`, `close`, `next`, `prev`, `setPosition` and properties `items`, `target`. ### Request Example ```js import BiggerPicture from 'bigger-picture' // initialize one instance per target; mounts at document.body let bp = BiggerPicture({ target: document.body, }) ``` ```js // multiple targets = multiple instances with independent state import BiggerPicture from 'bigger-picture' let bodyBp = BiggerPicture({ target: document.body }) let inlineBp = BiggerPicture({ target: document.getElementById('inline_gallery') }) bodyBp.open({ items: document.querySelectorAll('#images a') }) inlineBp.open({ items: inlineNodes, inline: true }) ``` ``` -------------------------------- ### TypeScript declarations for items and target Source: https://github.com/henrygd/bigger-picture TypeScript declarations for the items and target instance properties, including their types and comments. ```typescript /** Array of all items in currently active gallery */ items: item[] /** Gallery target */ target: HTMLElement ``` -------------------------------- ### BiggerPicture(options) Source: https://github.com/henrygd/bigger-picture Factory function that creates a new Bigger Picture instance. Accepts an initialization object and returns an instance with methods to control the lightbox. ```APIDOC ## BiggerPicture(options) ### Description Creates a new Bigger Picture instance. Accepts an initialization object and returns an instance with methods to control the lightbox. ### Method Factory function ### Parameters #### Options - **options** (object) - Required - Initialization object (see `initObject` type). ### Returns - **BiggerPictureInstance** - The created instance. ``` -------------------------------- ### prefersReducedMotion constant signature Source: https://github.com/henrygd/bigger-picture Boolean constant indicating user preference for reduced motion. Evaluated once at module load; undefined if matchMedia is unavailable. ```js // src/stores.js:8-9 export const prefersReducedMotion = globalThis.matchMedia?.( '(prefers-reduced-motion: reduce)' ).matches ``` -------------------------------- ### BiggerPictureInstance.target Source: https://github.com/henrygd/bigger-picture The mounting parent element of the gallery. This property is part of the BiggerPictureInstance interface returned by the default export. ```APIDOC ## BiggerPictureInstance.target ### Description Gallery target. ### Type HTMLElement ### Response Returns the target HTMLElement. ``` -------------------------------- ### close() source implementation Source: https://github.com/henrygd/bigger-picture Source code for the close() method from src/bigger-picture.svelte:106. It calls onClose, sets closing store, clears items, and restores focus. ```javascript export const close = () => { opts.onClose?.(container.el, activeItem) closing.set(true) items = null // restore focus to trigger element focusTrigger?.focus({ preventScroll: true }) } ``` -------------------------------- ### defaultTweenOptions(duration) Source: https://github.com/henrygd/bigger-picture Builds the options object used for internal Svelte tweens and transitions. It returns an object with easing and duration, where duration is set to 0 if the user prefers reduced motion. ```APIDOC ## defaultTweenOptions(duration) ### Description Builds the options object used for internal Svelte tweens and transitions. ### Signature ```js export const defaultTweenOptions = (duration) => ({ easing: cubicOut, duration: prefersReducedMotion ? 0 : duration, }) ``` ### Parameters | Parameter | Type | Required | Default | Description | |-----------|------|----------|---------|-------------| | `duration` | number | yes | — | Desired tween duration in milliseconds. Replaced by `0` when `prefersReducedMotion` is `true`. | ### Return type `{ easing: typeof cubicOut; duration: number }` — passed to `svelte/motion` tweens (`imageDimensions`, `zoomDragTranslate` in `src/components/image.svelte`) and Svelte transitions. ### Example ```js import { defaultTweenOptions } from 'bigger-picture/svelte/stores' import { tweened } from 'svelte/motion' const size = tweened([100, 100], defaultTweenOptions(400)) ``` ``` -------------------------------- ### getNextPosition helper Source: https://github.com/henrygd/bigger-picture Helper function used by setPosition to compute the wrapped position using modulo items.length. ```javascript const getNextPosition = (index) => (index + items.length) % items.length ``` -------------------------------- ### BiggerPictureInstance.prev Source: https://github.com/henrygd/bigger-picture Changes to the previous item in the gallery, wrapping around. This method is part of the BiggerPictureInstance interface returned by the default export. ```APIDOC ## BiggerPictureInstance.prev ### Description Changes to previous item in gallery. ### Method prev ### Parameters None. ### Response Returns void. ``` -------------------------------- ### TypeScript declaration for setPosition Source: https://github.com/henrygd/bigger-picture TypeScript declaration for the setPosition method, showing its signature as a function taking a number and returning void. ```typescript setPosition: (position: number) => void ```