Frameworks

@lightgallery/headless

Framework-free lightGallery core: state machine, gesture math and plugin logic shared by every v3 binding.

@lightgallery/headless is the framework-free core of lightGallery 3: everything a gallery needs to decide, with none of the rendering. It holds the state machine, settings resolution, gesture verdicts, spring physics, zoom and thumbnail math, the justified layout, responsive image selection, video URL builders, share links and URL drivers. It has no DOM and no framework; its TypeScript config excludes the DOM library, so window and document do not even type-check inside it.

The vanilla lightgallery package, @lightgallery/react, @lightgallery/vue and @lightgallery/angular are all renderers over this core. That is why a swipe threshold, a zoom clamp or a setting behaves the same in every package: it is the same code.

Who it is for

If you use one of the four packages you never install this one; each depends on it. Install it directly to build a binding for another framework, a web component, or a custom gallery UI on the same foundation.

npm install @lightgallery/headless

What it exports

AreaExportsNotes
StatecreateGalleryState, galleryReducer, clampIndexPure reducer over OPEN, CLOSE, NEXT, PREV, GO_TO and the load and transition actions
SettingsresolveSettings, coreSettingsDefaultsMerges user settings, mobile settings and strings over the defaults
ItemsgetSlideTypeImage, video, iframe or inline, from an item’s fields
Slide windowinggetSlideIndexesInDom, getPreloadIndexes, getSlidePoolIndexesWhich slides to mount and preload, including virtualization
GesturesgetSwipeAxis, getSwipeReleaseVerdict, getHorizontalDragTransforms, getVerticalDragEffects, shouldCloseOnVerticalDrag, getEdgeFrictionedDelta, upsertPointer, removePointerAxis lock, flick detection, boundary friction, drag to close
PhysicsstepSpring, isSpringSettled, project, getWindowedVelocity, pushVelocitySampleDamped spring, momentum projection, windowed release velocity
ZoomgetPinchScale, getPinchPan, getPointZoomPan, clampScale, clampPan, getPanBounds, shouldCloseOnPinch, getActualSizeScaleFocal-point pinch, pan bounds with friction, pinch to close
ThumbnailsgetThumbWindow, getThumbCorridorWindow, getActiveThumbTranslate, clampThumbTranslate, getElasticThumbTranslate, getScrubThumbIndex, getScrubThumbTranslateStrip windowing, centering, elastic edges, scrubbing
LayoutgetJustifiedLayout, getJustifiedRowsRow-justified box layout for trigger grids
ResponsiveparseSrcset, resolveImageSource, resolveSizes, matchesMedia, awaitDecodesrcset and sizes selection, decode gating
Origin animationgetOriginTransform, fitImageSize, parseImageSizeOpen-from-trigger transforms
Origin cropgetOriginWindow, getOriginCropFlight, parseObjectFit, parseBackgroundFit, parseCssPositionThe origin crop plugin’s flight from a cropped thumbnail
ToolbargetToolbarOverflow, getToolbarItemPriorityWhich buttons move into the overflow menu
VideogetVideoInfo, getYouTubeEmbedUrl, getVimeoEmbedUrl, getWistiaEmbedUrl, getYouTubePosterUrl, getFacadePosterProvider detection, embed URLs, facade posters
SharegetSharePayload, canNativeShare, getXShareLink, getFacebookShareLink, getPinterestShareLinkWeb Share payload and social fallbacks
URL driverscreateHashDriver, createHistoryHashDriver, createNavigationHashDriverOne interface over hash, history and the Navigation API
Plugin slicesinitialZoomSlice, applyZoom, initialRotateSlice, rotateLeft, rotateRight, flipHorizontal, flipVertical, initialAutoplaySlicePer-plugin state reducers
AccessibilityformatSlideAnnouncementLive-region text from a template string
IconscoreDefaultIcons, zoomDefaultIcons, …, LgIconNameThe built-in inline SVG icon sets, grouped by feature
LicensesetLicenseKey, checkLicenseKeyThe license check every package shares
EventscreateEmitterA typed emitter for renderers

Each module is independent and the package has no side effects; import only what your renderer needs.

Example

import {
    createGalleryState,
    galleryReducer,
    getSlideIndexesInDom,
    resolveSettings,
} from '@lightgallery/headless';

const settings = resolveSettings({ loop: true, speed: 400 });

let state = createGalleryState({ slidesCount: 5, loop: settings.loop });
state = galleryReducer(state, { type: 'OPEN', index: 2 });
state = galleryReducer(state, { type: 'NEXT' });

// Which slides to keep mounted right now: the current slide, its
// neighbours, and the previous slide so an outgoing transition can finish.
const mounted = getSlideIndexesInDom(
    state.currentIndex,
    state.previousIndex,
    state.slidesCount,
    settings.numberOfSlideItemsInDom,
    settings.loop,
);

Every function is pure. A renderer wraps the reducer in its own reactivity, a reducer hook in React, a store in Vue, a signal in Angular, and owns every DOM concern: measuring, painting, pointer events and focus.

License

Free and open source under the GPLv3, like every lightGallery package. If your project keeps its source proprietary, a commercial license covers it: same code, nothing gated.

Edit this page on GitHub