Use the new plugin access API from embla7.
This commit is contained in:
@@ -18,7 +18,6 @@ export class FrigateCardCarousel extends LitElement {
|
|||||||
public direction: 'vertical' | 'horizontal' = 'horizontal';
|
public direction: 'vertical' | 'horizontal' = 'horizontal';
|
||||||
|
|
||||||
protected _carousel?: EmblaCarouselType;
|
protected _carousel?: EmblaCarouselType;
|
||||||
protected _plugins: Record<string, EmblaPluginType> = {};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Scroll to a particular slide.
|
* Scroll to a particular slide.
|
||||||
@@ -81,7 +80,6 @@ export class FrigateCardCarousel extends LitElement {
|
|||||||
if (this._carousel) {
|
if (this._carousel) {
|
||||||
this._carousel.destroy();
|
this._carousel.destroy();
|
||||||
}
|
}
|
||||||
this._plugins = {};
|
|
||||||
this._carousel = undefined;
|
this._carousel = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,19 +92,13 @@ export class FrigateCardCarousel extends LitElement {
|
|||||||
) as HTMLElement;
|
) as HTMLElement;
|
||||||
|
|
||||||
if (carouselNode) {
|
if (carouselNode) {
|
||||||
const plugins = this._getPlugins() ?? [];
|
|
||||||
this._plugins = plugins.reduce((acc, cur) => {
|
|
||||||
acc[cur.name] = cur;
|
|
||||||
return acc;
|
|
||||||
}, {});
|
|
||||||
|
|
||||||
this._carousel = EmblaCarousel(
|
this._carousel = EmblaCarousel(
|
||||||
carouselNode,
|
carouselNode,
|
||||||
{
|
{
|
||||||
axis: this.direction == 'horizontal' ? 'x' : 'y',
|
axis: this.direction == 'horizontal' ? 'x' : 'y',
|
||||||
...this._getOptions(),
|
...this._getOptions(),
|
||||||
},
|
},
|
||||||
plugins,
|
this._getPlugins() ?? [],
|
||||||
);
|
);
|
||||||
this._carousel.on('init', () => dispatchFrigateCardEvent(this, 'carousel:init'));
|
this._carousel.on('init', () => dispatchFrigateCardEvent(this, 'carousel:init'));
|
||||||
this._carousel.on('select', () => {
|
this._carousel.on('select', () => {
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import {
|
|||||||
FrigateCardMediaPlayer,
|
FrigateCardMediaPlayer,
|
||||||
} from '../../types.js';
|
} from '../../types.js';
|
||||||
|
|
||||||
export type AutoMediaPluginOptionsType = CreateOptionsType<{
|
type OptionsType = CreateOptionsType<{
|
||||||
playerSelector?: string;
|
playerSelector?: string;
|
||||||
|
|
||||||
// Note: Neither play nor unmute will activate on selection. The caller is
|
// Note: Neither play nor unmute will activate on selection. The caller is
|
||||||
@@ -22,19 +22,21 @@ export type AutoMediaPluginOptionsType = CreateOptionsType<{
|
|||||||
autoMuteCondition?: AutoMuteCondition;
|
autoMuteCondition?: AutoMuteCondition;
|
||||||
}>;
|
}>;
|
||||||
|
|
||||||
export const defaultOptions: AutoMediaPluginOptionsType = {
|
const defaultOptions: OptionsType = {
|
||||||
active: true,
|
active: true,
|
||||||
breakpoints: {},
|
breakpoints: {},
|
||||||
};
|
};
|
||||||
|
|
||||||
export type AutoMediaPluginType = CreatePluginType<
|
export type AutoMediaOptionsType = Partial<OptionsType>
|
||||||
|
|
||||||
|
export type AutoMediaType = CreatePluginType<
|
||||||
{
|
{
|
||||||
play: () => void;
|
play: () => void;
|
||||||
pause: () => void;
|
pause: () => void;
|
||||||
mute: () => void;
|
mute: () => void;
|
||||||
unmute: () => void;
|
unmute: () => void;
|
||||||
},
|
},
|
||||||
AutoMediaPluginOptionsType
|
AutoMediaOptionsType
|
||||||
>;
|
>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -43,15 +45,15 @@ export type AutoMediaPluginType = CreatePluginType<
|
|||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
export function AutoMediaPlugin(
|
export function AutoMediaPlugin(
|
||||||
userOptions?: AutoMediaPluginOptionsType,
|
userOptions?: AutoMediaOptionsType,
|
||||||
): AutoMediaPluginType {
|
): AutoMediaType {
|
||||||
const optionsHandler = EmblaCarousel.optionsHandler();
|
const optionsHandler = EmblaCarousel.optionsHandler();
|
||||||
const optionsBase = optionsHandler.merge(
|
const optionsBase = optionsHandler.merge(
|
||||||
defaultOptions,
|
defaultOptions,
|
||||||
AutoMediaPlugin.globalOptions,
|
AutoMediaPlugin.globalOptions,
|
||||||
);
|
);
|
||||||
|
|
||||||
let options: AutoMediaPluginType['options'];
|
let options: AutoMediaType['options'];
|
||||||
let carousel: EmblaCarouselType;
|
let carousel: EmblaCarouselType;
|
||||||
let slides: HTMLElement[];
|
let slides: HTMLElement[];
|
||||||
|
|
||||||
@@ -210,8 +212,8 @@ export function AutoMediaPlugin(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const self: AutoMediaPluginType = {
|
const self: AutoMediaType = {
|
||||||
name: 'AutoMediaPlugin',
|
name: 'autoMedia',
|
||||||
options: optionsHandler.merge(optionsBase, userOptions),
|
options: optionsHandler.merge(optionsBase, userOptions),
|
||||||
init,
|
init,
|
||||||
destroy,
|
destroy,
|
||||||
@@ -223,4 +225,4 @@ export function AutoMediaPlugin(
|
|||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
AutoMediaPlugin.globalOptions = <AutoMediaPluginOptionsType | undefined>undefined;
|
AutoMediaPlugin.globalOptions = <AutoMediaOptionsType | undefined>undefined;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { CreatePluginType } from 'embla-carousel/components/Plugins';
|
|||||||
import EmblaCarousel, { EmblaCarouselType, EmblaEventType } from 'embla-carousel';
|
import EmblaCarousel, { EmblaCarouselType, EmblaEventType } from 'embla-carousel';
|
||||||
import { LazyUnloadCondition } from '../../types';
|
import { LazyUnloadCondition } from '../../types';
|
||||||
|
|
||||||
export type LazyloadOptionsType = CreateOptionsType<{
|
export type OptionsType = CreateOptionsType<{
|
||||||
// Number of slides to lazyload left/right of selected (0 == only selected
|
// Number of slides to lazyload left/right of selected (0 == only selected
|
||||||
// slide).
|
// slide).
|
||||||
lazyLoadCount?: number;
|
lazyLoadCount?: number;
|
||||||
@@ -13,12 +13,14 @@ export type LazyloadOptionsType = CreateOptionsType<{
|
|||||||
lazyUnloadCallback?: (index: number, slide: HTMLElement) => void;
|
lazyUnloadCallback?: (index: number, slide: HTMLElement) => void;
|
||||||
}>;
|
}>;
|
||||||
|
|
||||||
export const defaultOptions: LazyloadOptionsType = {
|
export const defaultOptions: OptionsType = {
|
||||||
active: true,
|
active: true,
|
||||||
breakpoints: {},
|
breakpoints: {},
|
||||||
lazyLoadCount: 0,
|
lazyLoadCount: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type LazyloadOptionsType = Partial<OptionsType>
|
||||||
|
|
||||||
export type LazyloadType = CreatePluginType<
|
export type LazyloadType = CreatePluginType<
|
||||||
{
|
{
|
||||||
hasLazyloaded(index: number): boolean;
|
hasLazyloaded(index: number): boolean;
|
||||||
@@ -147,7 +149,7 @@ export function Lazyload(userOptions?: LazyloadOptionsType): LazyloadType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const self: LazyloadType = {
|
const self: LazyloadType = {
|
||||||
name: 'Lazyload',
|
name: 'lazyload',
|
||||||
options: optionsHandler.merge(optionsBase, userOptions),
|
options: optionsHandler.merge(optionsBase, userOptions),
|
||||||
init,
|
init,
|
||||||
destroy,
|
destroy,
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ import {
|
|||||||
dispatchMediaShowEvent,
|
dispatchMediaShowEvent,
|
||||||
} from '../utils/media-info.js';
|
} from '../utils/media-info.js';
|
||||||
import { View } from '../view.js';
|
import { View } from '../view.js';
|
||||||
import { AutoMediaPlugin, AutoMediaPluginType } from './embla-plugins/automedia.js';
|
import { AutoMediaPlugin } from './embla-plugins/automedia.js';
|
||||||
import { Lazyload } from './embla-plugins/lazyload.js';
|
import { Lazyload } from './embla-plugins/lazyload.js';
|
||||||
import { FrigateCardMediaCarousel } from './media-carousel.js';
|
import { FrigateCardMediaCarousel } from './media-carousel.js';
|
||||||
import { dispatchErrorMessageEvent } from './message.js';
|
import { dispatchErrorMessageEvent } from './message.js';
|
||||||
@@ -239,9 +239,7 @@ export class FrigateCardLiveCarousel extends FrigateCardMediaCarousel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (changedProperties.has('preloaded')) {
|
if (changedProperties.has('preloaded')) {
|
||||||
const automedia = this._plugins['AutoMediaPlugin'] as
|
const automedia = this._getAutoMediaPlugin();
|
||||||
| AutoMediaPluginType
|
|
||||||
| undefined;
|
|
||||||
if (automedia) {
|
if (automedia) {
|
||||||
// If this has changed to preloaded (i.e. is now loaded but in the
|
// If this has changed to preloaded (i.e. is now loaded but in the
|
||||||
// background) take the appropriate play/pause/mute/unmute actions.
|
// background) take the appropriate play/pause/mute/unmute actions.
|
||||||
|
|||||||
@@ -9,7 +9,8 @@ import {
|
|||||||
isValidMediaShowInfo
|
isValidMediaShowInfo
|
||||||
} from '../utils/media-info.js';
|
} from '../utils/media-info.js';
|
||||||
import { FrigateCardCarousel } from './carousel.js';
|
import { FrigateCardCarousel } from './carousel.js';
|
||||||
import { AutoMediaPluginType } from './embla-plugins/automedia.js';
|
import { AutoMediaType } from './embla-plugins/automedia.js';
|
||||||
|
import { LazyloadType } from './embla-plugins/lazyload';
|
||||||
import './next-prev-control.js';
|
import './next-prev-control.js';
|
||||||
import { FrigateCardNextPreviousControl } from './next-prev-control.js';
|
import { FrigateCardNextPreviousControl } from './next-prev-control.js';
|
||||||
import { FrigateCardTitleControl } from './title-control.js';
|
import { FrigateCardTitleControl } from './title-control.js';
|
||||||
@@ -41,12 +42,28 @@ export class FrigateCardMediaCarousel extends FrigateCardCarousel {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the AutoMedia plugin (if any).
|
||||||
|
* @returns The plugin or `null`.
|
||||||
|
*/
|
||||||
|
protected _getAutoMediaPlugin(): AutoMediaType | null {
|
||||||
|
return this._carousel?.plugins()['autoMedia'] ?? null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the LazyLoad plugin (if any).
|
||||||
|
* @returns The plugin or `null`.
|
||||||
|
*/
|
||||||
|
protected _getLazyLoadPlugin(): LazyloadType | null {
|
||||||
|
return this._carousel?.plugins()['lazyload'] ?? null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Play the media on the selected slide. May be overridden to control when
|
* Play the media on the selected slide. May be overridden to control when
|
||||||
* autoplay should happen.
|
* autoplay should happen.
|
||||||
*/
|
*/
|
||||||
protected _autoPlayHandler(): void {
|
protected _autoPlayHandler(): void {
|
||||||
(this._plugins['AutoMediaPlugin'] as AutoMediaPluginType | undefined)?.play();
|
this._getAutoMediaPlugin()?.play();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -54,7 +71,7 @@ export class FrigateCardMediaCarousel extends FrigateCardCarousel {
|
|||||||
* autoplay should happen.
|
* autoplay should happen.
|
||||||
*/
|
*/
|
||||||
protected _autoUnmuteHandler(): void {
|
protected _autoUnmuteHandler(): void {
|
||||||
(this._plugins['AutoMediaPlugin'] as AutoMediaPluginType | undefined)?.unmute();
|
this._getAutoMediaPlugin()?.unmute();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+10
-12
@@ -7,14 +7,14 @@ import {
|
|||||||
LitElement,
|
LitElement,
|
||||||
PropertyValues,
|
PropertyValues,
|
||||||
TemplateResult,
|
TemplateResult,
|
||||||
unsafeCSS
|
unsafeCSS,
|
||||||
} from 'lit';
|
} from 'lit';
|
||||||
import { customElement, property } from 'lit/decorators.js';
|
import { customElement, property } from 'lit/decorators.js';
|
||||||
import { ifDefined } from 'lit/directives/if-defined.js';
|
import { ifDefined } from 'lit/directives/if-defined.js';
|
||||||
import { ref } from 'lit/directives/ref.js';
|
import { ref } from 'lit/directives/ref.js';
|
||||||
import {
|
import {
|
||||||
dispatchFrigateCardErrorEvent,
|
dispatchFrigateCardErrorEvent,
|
||||||
renderProgressIndicator
|
renderProgressIndicator,
|
||||||
} from '../components/message.js';
|
} from '../components/message.js';
|
||||||
import viewerStyle from '../scss/viewer.scss';
|
import viewerStyle from '../scss/viewer.scss';
|
||||||
import type {
|
import type {
|
||||||
@@ -26,7 +26,7 @@ import type {
|
|||||||
FrigateCardMediaPlayer,
|
FrigateCardMediaPlayer,
|
||||||
MediaShowInfo,
|
MediaShowInfo,
|
||||||
TransitionEffect,
|
TransitionEffect,
|
||||||
ViewerConfig
|
ViewerConfig,
|
||||||
} from '../types.js';
|
} from '../types.js';
|
||||||
import { stopEventFromActivatingCardWideActions } from '../utils/action.js';
|
import { stopEventFromActivatingCardWideActions } from '../utils/action.js';
|
||||||
import { contentsChanged } from '../utils/basic.js';
|
import { contentsChanged } from '../utils/basic.js';
|
||||||
@@ -36,19 +36,19 @@ import {
|
|||||||
getFullDependentBrowseMediaQueryParametersOrDispatchError,
|
getFullDependentBrowseMediaQueryParametersOrDispatchError,
|
||||||
isTrueMedia,
|
isTrueMedia,
|
||||||
multipleBrowseMediaQueryMerged,
|
multipleBrowseMediaQueryMerged,
|
||||||
overrideMultiBrowseMediaQueryParameters
|
overrideMultiBrowseMediaQueryParameters,
|
||||||
} from '../utils/ha/browse-media.js';
|
} from '../utils/ha/browse-media.js';
|
||||||
import { ResolvedMediaCache, resolveMedia } from '../utils/ha/resolved-media.js';
|
import { ResolvedMediaCache, resolveMedia } from '../utils/ha/resolved-media.js';
|
||||||
import { createMediaShowInfo } from '../utils/media-info.js';
|
import { createMediaShowInfo } from '../utils/media-info.js';
|
||||||
import { View } from '../view.js';
|
import { View } from '../view.js';
|
||||||
import { AutoMediaPlugin } from './embla-plugins/automedia.js';
|
import { AutoMediaPlugin } from './embla-plugins/automedia.js';
|
||||||
import { Lazyload, LazyloadType } from './embla-plugins/lazyload.js';
|
import { Lazyload } from './embla-plugins/lazyload.js';
|
||||||
import { FrigateCardMediaCarousel, IMG_EMPTY } from './media-carousel.js';
|
import { FrigateCardMediaCarousel, IMG_EMPTY } from './media-carousel.js';
|
||||||
import './next-prev-control.js';
|
import './next-prev-control.js';
|
||||||
import { FrigateCardNextPreviousControl } from './next-prev-control.js';
|
import { FrigateCardNextPreviousControl } from './next-prev-control.js';
|
||||||
import './title-control.js';
|
import './title-control.js';
|
||||||
import "../patches/ha-hls-player";
|
import '../patches/ha-hls-player';
|
||||||
import "./surround-thumbnails";
|
import './surround-thumbnails';
|
||||||
|
|
||||||
@customElement('frigate-card-viewer')
|
@customElement('frigate-card-viewer')
|
||||||
export class FrigateCardViewer extends LitElement {
|
export class FrigateCardViewer extends LitElement {
|
||||||
@@ -778,9 +778,7 @@ export class FrigateCardViewerCarousel extends FrigateCardMediaCarousel {
|
|||||||
// images in media-carousel.ts). Here we need to only call the
|
// images in media-carousel.ts). Here we need to only call the
|
||||||
// media load handler on a 'real' load.
|
// media load handler on a 'real' load.
|
||||||
!lazyLoad ||
|
!lazyLoad ||
|
||||||
(this._plugins['Lazyload'] as LazyloadType | undefined)?.hasLazyloaded(
|
this._getLazyLoadPlugin()?.hasLazyloaded(slideIndex)
|
||||||
slideIndex,
|
|
||||||
)
|
|
||||||
) {
|
) {
|
||||||
this._mediaLoadedHandler(slideIndex, createMediaShowInfo(e));
|
this._mediaLoadedHandler(slideIndex, createMediaShowInfo(e));
|
||||||
}
|
}
|
||||||
@@ -793,7 +791,7 @@ export class FrigateCardViewerCarousel extends FrigateCardMediaCarousel {
|
|||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
interface HTMLElementTagNameMap {
|
interface HTMLElementTagNameMap {
|
||||||
"frigate-card-viewer-carousel": FrigateCardViewerCarousel
|
'frigate-card-viewer-carousel': FrigateCardViewerCarousel;
|
||||||
"frigate-card-viewer": FrigateCardViewer
|
'frigate-card-viewer': FrigateCardViewer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user