### Install SmartPhoto via Package Manager
Source: https://github.com/appleple/smartphoto/blob/master/README.md
Commands to install the library using npm or yarn.
```shell
npm install smartphoto --save
```
```shell
yarn add smartphoto
```
--------------------------------
### Initialize SmartPhoto
Source: https://github.com/appleple/smartphoto/blob/master/README.md
Basic initialization for standard and jQuery environments.
```js
const SmartPhoto = require('smartphoto');
```
```js
document.addEventListener('DOMContentLoaded',function(){
new SmartPhoto(".js-smartphoto");
});
```
```js
$(function(){
$(".js-smartphoto").SmartPhoto();
});
```
--------------------------------
### SmartPhoto Constructor
Source: https://github.com/appleple/smartphoto/blob/master/README.md
Initializes the SmartPhoto viewer with custom configuration options.
```APIDOC
## new SmartPhoto(selector, options)
### Description
Initializes a new SmartPhoto instance on the elements matching the provided selector.
### Parameters
- **selector** (string) - Required - CSS selector for the target elements.
- **options** (object) - Optional - Configuration object containing settings like arrows, nav, resizeStyle, etc.
```
--------------------------------
### SmartPhoto Instance Methods
Source: https://github.com/appleple/smartphoto/blob/master/README.md
Methods available on the SmartPhoto instance to control the viewer, navigation, and lifecycle.
```APIDOC
## SmartPhoto Methods
### on(event, listener)
Subscribe to viewer events.
### destroy()
Remove the viewer and all associated event listeners.
### [Symbol.dispose]()
Destroys the instance automatically when used with a `using` declaration.
### gotoSlide(index)
Navigate to the slide at the specified index within the current group.
### hidePhoto(dir?)
Close the viewer. `dir` can be 'bottom' (default) or 'top' to control animation direction.
### zoomPhoto() / zoomOutPhoto()
Programmatically zoom the current image in or out.
### addNewItem(element)
Register a new thumbnail element (HTML mode).
### show(indexOrId?, options?)
Open the viewer. `options.group` selects the group, and `options.trigger` sets the source element.
### hide()
Alias for `hidePhoto()`.
### next() / prev()
Navigate to the next or previous slide.
### addItem(slideOrElement)
Add a new item, accepting either a slide object or an HTML Element.
### currentIndex
Getter returning the index of the currently displayed slide.
```
--------------------------------
### new SmartPhoto(selectorOrData)
Source: https://github.com/appleple/smartphoto/blob/master/README.md
Initializes the SmartPhoto viewer. Can be initialized using a CSS selector for HTML elements or an array of slide objects for programmatic data source mode.
```APIDOC
## new SmartPhoto(selectorOrData)
### Description
Initializes the SmartPhoto instance. In HTML mode, pass a CSS selector string. In data source mode, pass an array of slide objects.
### Parameters
- **selectorOrData** (string|Array) - Required - A CSS selector string (e.g., ".js-smartphoto") or an array of objects containing image metadata (src, thumb, caption, alt, id, group, width, height).
```
--------------------------------
### Programmatic Data Source Usage
Source: https://github.com/appleple/smartphoto/blob/master/README.md
Initialize SmartPhoto using an array of objects instead of scanning DOM elements.
```js
const photo = new SmartPhoto([
{ src: "/img/bear-large.jpg", thumb: "/img/bear.jpg", caption: "bear", id: "bear" },
{ src: "/img/camel-large.jpg", thumb: "/img/camel.jpg", caption: "camel", id: "camel", width: 1200, height: 800 },
]);
photo.show(0); // open by index
photo.show("camel"); // or by id
photo.next();
photo.prev();
photo.hide();
photo.on("change", () => { /* ... */ }); // same event contract as HTML mode
```
--------------------------------
### photo.next() / photo.prev() / photo.hide()
Source: https://github.com/appleple/smartphoto/blob/master/README.md
Navigation and control methods for the SmartPhoto instance.
```APIDOC
## Navigation Methods
### Description
Methods to control the viewer state programmatically.
- **next()**: Advances to the next image.
- **prev()**: Returns to the previous image.
- **hide()**: Closes the image viewer.
```
--------------------------------
### Basic HTML Usage
Source: https://github.com/appleple/smartphoto/blob/master/README.md
Standard implementation using anchor tags with data attributes for captions, IDs, and grouping.
```html
```
--------------------------------
### Configure image resizing style
Source: https://github.com/appleple/smartphoto/blob/master/README.md
Sets the resizeStyle option to control whether images fit or fill the screen.
```js
document.addEventListener('DOMContentLoaded',function(){
new SmartPhoto(".js-smartphoto",{
resizeStyle: 'fit'
});
});
```
--------------------------------
### photo.on(event, callback)
Source: https://github.com/appleple/smartphoto/blob/master/README.md
Registers event listeners for the SmartPhoto instance.
```APIDOC
## photo.on(event, callback)
### Description
Attaches an event listener to the SmartPhoto instance to handle lifecycle events like 'change'.
### Parameters
- **event** (string) - Required - The name of the event (e.g., 'change').
- **callback** (function) - Required - The function to execute when the event is triggered.
```
--------------------------------
### photo.show(indexOrId, options)
Source: https://github.com/appleple/smartphoto/blob/master/README.md
Opens the image viewer at a specific index or by ID.
```APIDOC
## photo.show(indexOrId, options)
### Description
Displays the image viewer. You can specify the target image by its index (integer) or its ID (string).
### Parameters
- **indexOrId** (number|string) - Required - The index or ID of the image to display.
- **options** (object) - Optional - Configuration object containing `group` (string) to specify the group and `trigger` (element) to specify the origin element for animations.
```
--------------------------------
### SmartPhoto Events
Source: https://github.com/appleple/smartphoto/blob/master/README.md
List of events that can be subscribed to using the .on() method.
```APIDOC
## photo.on(event, callback)
### Description
Registers a callback function for a specific event triggered by the SmartPhoto instance.
### Supported Events
- **open**: Triggered when the modal opens.
- **close**: Triggered when the modal closes.
- **loadall**: Triggered when all images are loaded.
- **change**: Triggered when the photo is changed.
- **swipestart**: Triggered when a swipe gesture starts.
- **swipeend**: Triggered when a swipe gesture ends.
- **zoomin**: Triggered when the image is zoomed in.
- **zoomout**: Triggered when the image is zoomed out.
```
--------------------------------
### Handle SmartPhoto events
Source: https://github.com/appleple/smartphoto/blob/master/README.md
Registers listeners for various viewer events such as opening, closing, changing images, and zooming.
```js
// when the modal opened
photo.on('open',function(){
console.log('open');
});
// when the modal closed
photo.on('close',function(){
console.log('close');
});
// when all images are loaded
photo.on('loadall',function(){
console.log('loadall');
});
// when photo is changed
photo.on('change',function(){
console.log('change');
});
// when swipe started
photo.on('swipestart',function(){
console.log('swipestart');
});
// when swipe ended
photo.on('swipeend',function(){
console.log('swipeend');
});
// when zoomed in
photo.on('zoomin',function(){
console.log('zoomin');
});
// when zoomed out
photo.on('zoomout',function(){
console.log('zoomout');
});
```
--------------------------------
### CSS Custom Properties
Source: https://github.com/appleple/smartphoto/blob/master/README.md
CSS variables used to customize the appearance and animation of the SmartPhoto viewer.
```APIDOC
## CSS Custom Properties
- **--smartphoto-animation-speed**: Animation speed (default: 300ms).
- **--smartphoto-animation-function**: Easing function (default: ease-out).
- **--smartphoto-backdrop-color**: Backdrop color (default: rgba(0, 0, 0, 1)).
- **--smartphoto-header-color**: Header color (default: rgba(0, 0, 0, .2)).
```
--------------------------------
### Override SmartPhoto CSS Custom Properties
Source: https://github.com/appleple/smartphoto/blob/master/README.md
Apply these variables to the .smartphoto class or :root to customize animation and color settings without rebuilding.
```css
.smartphoto {
--smartphoto-animation-speed: 500ms;
--smartphoto-animation-function: ease-in-out;
--smartphoto-backdrop-color: rgba(0, 0, 0, 0.9);
--smartphoto-header-color: rgba(0, 0, 0, 0.4);
}
```
--------------------------------
### Hide UI elements in SmartPhoto
Source: https://github.com/appleple/smartphoto/blob/master/README.md
Disables navigation arrows and thumbnails by passing configuration options to the constructor.
```js
document.addEventListener('DOMContentLoaded',function(){
new SmartPhoto(".js-smartphoto",{
arrows: false,
nav: false
});
});
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.