diff --git a/dist/caroucssel.d.ts b/dist/carousel.d.ts similarity index 92% rename from dist/caroucssel.d.ts rename to dist/carousel.d.ts index 68581251..6b63a760 100644 --- a/dist/caroucssel.d.ts +++ b/dist/carousel.d.ts @@ -1,11 +1,10 @@ -import { Index, Options, Pages, ScrollBehavior } from './types'; -export * from './types'; +import { ICarousel, Index, Options, Pages, ScrollBehavior } from './types'; /** * The carousel javascript instance. */ -export declare class Carousel { +export declare class Carousel implements ICarousel { /** - * This can be used for testing purposes to reset the instance count which is + * This will be used for testing purposes to reset the instance count which is * used to create unique id's. * @internal */ diff --git a/dist/caroucssel.js b/dist/carousel.js similarity index 81% rename from dist/caroucssel.js rename to dist/carousel.js index bf7a2be0..d8874241 100644 --- a/dist/caroucssel.js +++ b/dist/carousel.js @@ -1,12 +1,12 @@ -import { Mask } from './plugins/mask'; +import { Mask } from './features/mask'; +import { Proxy } from './proxy'; import { ScrollBehavior, UpdateReason } from './types'; import { clearCache, clearFullCache, fromCache, writeCache } from './utils/cache'; import { debounce } from './utils/debounce'; -// Export all types -// (is required to expose all types in dist/caroucssel.d.ts) -export * from './types'; const ID_NAME = (count) => `caroucssel-${count}`; const ID_MATCH = /^caroucssel-[0-9]*$/; +const EVENT_SCROLL = 'scroll'; +const EVENT_RESIZE = 'resize'; const CACHE_KEY_ELEMENT = 'element'; const CACHE_KEY_ID = 'id'; const CACHE_KEY_CONFIGURATION = 'config'; @@ -16,66 +16,18 @@ const CACHE_KEY_PAGES = 'pages'; const CACHE_KEY_PAGE_INDEX = 'page-index'; const CACHE_KEY_MASK = 'mask'; const CACHE_KEY_PROXY = 'proxy'; -const CACHE_KEY_PLUGINS = 'plugins'; -const CACHE_KEY_PROXY_INSTANCE = 'proxy:instance'; -const CACHE_KEY_PROXY_PLUGIN = 'proxy:plugins'; +const CACHE_KEY_FEATURES = 'feautres'; const VISIBILITY_OFFSET = 0.25; const INVISIBLE_ELEMENTS = /^(link|meta|noscript|script|style|title)$/i; -const EVENT_SCROLL = 'scroll'; -const EVENT_RESIZE = 'resize'; const DEFAULTS = { - // Plugins: - plugins: [], - // filter + features: [], filterItem: () => true, - // Hooks: onScroll: () => undefined, }; /* * Internal counter for created instances. Will be used to create unique IDs. */ let __instanceCount = 0; -/** - * A proxy instance between carousel and each plugin. - */ -class Proxy { - constructor(instance, plugins) { - writeCache(this, CACHE_KEY_PROXY_INSTANCE, instance); - writeCache(this, CACHE_KEY_PROXY_PLUGIN, plugins); - } - get el() { - const instance = fromCache(this, CACHE_KEY_PROXY_INSTANCE); - return instance.el; - } - get mask() { - const instance = fromCache(this, CACHE_KEY_PROXY_INSTANCE); - return instance.mask; - } - get index() { - const instance = fromCache(this, CACHE_KEY_PROXY_INSTANCE); - return instance.index; - } - set index(value) { - const instance = fromCache(this, CACHE_KEY_PROXY_INSTANCE); - instance.index = value; - } - get items() { - const instance = fromCache(this, CACHE_KEY_PROXY_INSTANCE); - return instance.items; - } - get pages() { - const instance = fromCache(this, CACHE_KEY_PROXY_INSTANCE); - return instance.pages; - } - get pageIndex() { - const instance = fromCache(this, CACHE_KEY_PROXY_INSTANCE); - return instance.pageIndex; - } - update(plugin) { - // @TODO: Trigger update in instance and all other plugins except the source - // plugin that triggered the event. - } -} /** * The carousel javascript instance. */ @@ -105,22 +57,26 @@ export class Carousel { // Extend options and defaults into configuration: const configuration = Object.assign(Object.assign({}, DEFAULTS), options); writeCache(this, CACHE_KEY_CONFIGURATION, configuration); - // Detect if there is a "Mask" plugin passed as option. Then use this one, - // otherwise add a mandatory instance by default: - const plugins = [...configuration.plugins]; - const index = configuration.plugins.findIndex((plugin) => plugin instanceof Mask); - let mask = new Mask(); + // Detect if there is a "Mask" feature passed as option. Then use this one, + // otherwise add a mandatory instance by default. Also ensure that only one + // feature of type "Mask" is in the features list. + let mask = null; + let features = [...configuration.features]; + const index = configuration.features.findIndex((feature) => feature instanceof Mask); if (index > -1) { - [mask] = plugins.splice(index, 1); + // Extract first found instance of "Mask": + [mask] = features.splice(index, 1); } - plugins.unshift(mask); + mask !== null && mask !== void 0 ? mask : (mask = new Mask()); + features = features.filter((feature) => !(feature instanceof Mask)); + features = [mask, ...features]; writeCache(this, CACHE_KEY_MASK, mask); - // Plugins: - const proxy = new Proxy(this, plugins); + // Features: Initialize all features with a single proxy instance inbetween. + const proxy = new Proxy(this, features); writeCache(this, CACHE_KEY_PROXY, proxy); - writeCache(this, CACHE_KEY_PLUGINS, plugins); - plugins.forEach((plugin) => plugin.init(proxy)); - // Set initial index and set smooth scrolling: + writeCache(this, CACHE_KEY_FEATURES, features); + features.forEach((feature) => feature.init(proxy)); + // Set initial index and finally set smooth scrolling to enabled: switch (true) { // When index is a list: case Array.isArray(options.index): @@ -147,11 +103,13 @@ export class Carousel { /* eslint-enable @typescript-eslint/unbound-method */ } /** - * This can be used for testing purposes to reset the instance count which is + * This will be used for testing purposes to reset the instance count which is * used to create unique id's. * @internal */ static resetInstanceCount() { + /* This should not be part of the coverage report: test util */ + /* istanbul ignore next */ if (process.env.NODE_ENV === 'test') { __instanceCount = 0; } @@ -230,9 +188,6 @@ export class Carousel { if (!Array.isArray(values) || !values.length) { return; } - if (length === 0) { - return; - } let value = values[0] || 0; value = Math.max(Math.min(value, length - 1), 0); const { scrollLeft } = el; @@ -389,9 +344,9 @@ export class Carousel { const { el } = this; // Remove created id if it was created by carousel: ID_MATCH.test(el.id) && el.removeAttribute('id'); - // Destroy attached plugins: - const plugins = fromCache(this, CACHE_KEY_PLUGINS); - plugins === null || plugins === void 0 ? void 0 : plugins.forEach((plugin) => plugin.destroy()); + // Destroy attached features: + const features = fromCache(this, CACHE_KEY_FEATURES); + features.forEach((feature) => feature.destroy()); // Remove events: // // We need to work the the function reference. Using .bind() would create a @@ -415,23 +370,23 @@ export class Carousel { clearCache(this, CACHE_KEY_ITEMS); clearCache(this, CACHE_KEY_PAGES); clearCache(this, CACHE_KEY_PAGE_INDEX); - const plugins = fromCache(this, CACHE_KEY_PLUGINS); - plugins === null || plugins === void 0 ? void 0 : plugins.forEach((plugin) => plugin.update({ reason: UpdateReason.FORCED })); + const features = fromCache(this, CACHE_KEY_FEATURES); + features.forEach((feature) => feature.update({ reason: UpdateReason.FORCED })); } _onScroll(event) { clearCache(this, CACHE_KEY_INDEX); clearCache(this, CACHE_KEY_PAGE_INDEX); - const plugins = fromCache(this, CACHE_KEY_PLUGINS); - plugins === null || plugins === void 0 ? void 0 : plugins.forEach((plugin) => plugin.update({ reason: UpdateReason.SCROLL })); + const features = fromCache(this, CACHE_KEY_FEATURES); + features.forEach((feature) => feature.update({ reason: UpdateReason.SCROLL })); const { index } = this; const configuration = fromCache(this, CACHE_KEY_CONFIGURATION); - configuration === null || configuration === void 0 ? void 0 : configuration.onScroll({ index, type: EVENT_SCROLL, target: this, originalEvent: event }); + configuration.onScroll({ index, type: EVENT_SCROLL, target: this, originalEvent: event }); } _onResize() { clearCache(this, CACHE_KEY_PAGES); clearCache(this, CACHE_KEY_INDEX); clearCache(this, CACHE_KEY_PAGE_INDEX); - const plugins = fromCache(this, CACHE_KEY_PLUGINS); - plugins === null || plugins === void 0 ? void 0 : plugins.forEach((plugin) => plugin.update({ reason: UpdateReason.RESIZE })); + const features = fromCache(this, CACHE_KEY_FEATURES); + features.forEach((feature) => feature.update({ reason: UpdateReason.RESIZE })); } } diff --git a/dist/plugins/buttons/index.d.ts b/dist/features/buttons/index.d.ts similarity index 78% rename from dist/plugins/buttons/index.d.ts rename to dist/features/buttons/index.d.ts index c5c5b763..37a5640a 100644 --- a/dist/plugins/buttons/index.d.ts +++ b/dist/features/buttons/index.d.ts @@ -1,4 +1,4 @@ -import { Plugin, PluginProxy } from '../../types'; +import { IFeature, IProxy } from '../../types'; export declare type Params = { controls: string; className: string; @@ -17,12 +17,12 @@ export declare type Configuration = { previousTitle: string; }; /** - * The plugin to enable button controls. + * The feature to enable button controls. */ -export declare class Buttons implements Plugin { +export declare class Buttons implements IFeature { constructor(options?: Partial); get name(): string; - init(proxy: PluginProxy): void; + init(proxy: IProxy): void; destroy(): void; update(): void; private _render; diff --git a/dist/plugins/buttons/index.js b/dist/features/buttons/index.js similarity index 92% rename from dist/plugins/buttons/index.js rename to dist/features/buttons/index.js index 0556027d..9f3e2222 100644 --- a/dist/plugins/buttons/index.js +++ b/dist/features/buttons/index.js @@ -29,7 +29,7 @@ const CACHE_KEY_PROXY = 'proxy'; const CACHE_KEY_CONFIGURATION = 'config'; const CACHE_KEY_BUTTONS = 'buttons'; /** - * The plugin to enable button controls. + * The feature to enable button controls. */ export class Buttons { constructor(options = {}) { @@ -64,6 +64,8 @@ export class Buttons { label: nextLabel, title: nextTitle, className: [className, nextClassName].join(' '), + // The onClick listener was already bound in the constructor. + // // eslint-disable-next-line @typescript-eslint/unbound-method handler: this._onNext, }, @@ -72,6 +74,8 @@ export class Buttons { label: previousLabel, title: previousTitle, className: [className, previousClassName].join(' '), + // The onClick listener was already bound in the constructor. + // // eslint-disable-next-line @typescript-eslint/unbound-method handler: this._onPrevious, }, @@ -100,13 +104,14 @@ export class Buttons { } _remove() { const buttons = fromCache(this, CACHE_KEY_BUTTONS); - if (!buttons) { - return; - } buttons.forEach((button) => { var _a; + // The onClick listener was already bound in the constructor. + // // eslint-disable-next-line @typescript-eslint/unbound-method button === null || button === void 0 ? void 0 : button.removeEventListener('click', this._onPrevious); + // The onClick listener was already bound in the constructor. + // // eslint-disable-next-line @typescript-eslint/unbound-method button === null || button === void 0 ? void 0 : button.removeEventListener('click', this._onNext); (_a = button === null || button === void 0 ? void 0 : button.parentNode) === null || _a === void 0 ? void 0 : _a.removeChild(button); diff --git a/dist/features/mask/index.d.ts b/dist/features/mask/index.d.ts new file mode 100644 index 00000000..2388955e --- /dev/null +++ b/dist/features/mask/index.d.ts @@ -0,0 +1,20 @@ +import { IFeature, IProxy, UpdateData } from '../../types'; +export declare type Configuration = { + enabled: boolean; + className: string; + tagName: string; +}; +/** + * The feature to enable/disabled mask and scrollbar features. This feature will + * be added by default to each carousel. Use this feature to customize the default behaviour. + */ +export declare class Mask implements IFeature { + constructor(options?: Partial); + get name(): string; + get el(): Element | null; + init(proxy: IProxy): void; + destroy(): void; + update(data: UpdateData): void; + private _render; + private _remove; +} diff --git a/dist/plugins/mask/index.js b/dist/features/mask/index.js similarity index 83% rename from dist/plugins/mask/index.js rename to dist/features/mask/index.js index da23489f..5c2ebed1 100644 --- a/dist/plugins/mask/index.js +++ b/dist/features/mask/index.js @@ -1,6 +1,6 @@ import { UpdateReason } from '../../types'; import { clearCache, clearFullCache, fromCache, writeCache } from '../../utils/cache'; -import { Scrollbar } from '../../utils/scrollbar'; +import { Scrollbar } from './scrollbar'; /* * Singleton of scrollbar util. Is shared across all instances of carousel to * reduce redundant calculations. @@ -8,19 +8,16 @@ import { Scrollbar } from '../../utils/scrollbar'; let __scrollbar; const DEFAULTS = { enabled: true, - // @TODO: customize class name - // className: 'caroucssel-mask', - // @TODO: customize tag name - // tagName: 'div', + className: 'caroucssel-mask', + tagName: 'div', }; -const CLASSNAME = 'caroucssel-mask'; const CACHE_KEY_PROXY = 'proxy'; const CACHE_KEY_CONFIGURATION = 'config'; const CACHE_KEY_MASK = 'mask'; const CACHE_KEY_HEIGHT = 'scrollbar'; /** - * The plugin to enable/disabled mask and scrollbar features. This plugin will - * be added by default to each carousel. Use this plugin to customize the default behaviour. + * The feature to enable/disabled mask and scrollbar features. This feature will + * be added by default to each carousel. Use this feature to customize the default behaviour. */ export class Mask { constructor(options = {}) { @@ -56,7 +53,7 @@ export class Mask { } } _render() { - const { enabled } = fromCache(this, CACHE_KEY_CONFIGURATION); + const { enabled, className, tagName } = fromCache(this, CACHE_KEY_CONFIGURATION); if (!enabled) { return; } @@ -69,11 +66,11 @@ export class Mask { // case, the scrollbar height is 0: height = 0; } - // Use from cache factory to render mask element only once: + // Use fromCache factory to render mask element only once: fromCache(this, CACHE_KEY_MASK, () => { var _a; - const mask = document.createElement('div'); - mask.className = CLASSNAME; + const mask = document.createElement(tagName); + mask.className = className; mask.style.overflow = 'hidden'; mask.style.height = '100%'; (_a = element.parentNode) === null || _a === void 0 ? void 0 : _a.insertBefore(mask, element); diff --git a/dist/utils/scrollbar.d.ts b/dist/features/mask/scrollbar.d.ts similarity index 96% rename from dist/utils/scrollbar.d.ts rename to dist/features/mask/scrollbar.d.ts index c9b1befb..98dc59dd 100644 --- a/dist/utils/scrollbar.d.ts +++ b/dist/features/mask/scrollbar.d.ts @@ -7,6 +7,7 @@ export declare type ScrollbarDimensions = { export declare class Scrollbar { /** * Creates an instance. + * @internal */ constructor(); /** diff --git a/dist/utils/scrollbar.js b/dist/features/mask/scrollbar.js similarity index 96% rename from dist/utils/scrollbar.js rename to dist/features/mask/scrollbar.js index 5c965be5..01e58a4f 100644 --- a/dist/utils/scrollbar.js +++ b/dist/features/mask/scrollbar.js @@ -1,10 +1,11 @@ -import { clearCache, fromCache } from './cache'; +import { clearCache, fromCache } from '../../utils/cache'; /** * Helper class for scrollbar features. */ export class Scrollbar { /** * Creates an instance. + * @internal */ constructor() { window.addEventListener('resize', () => { diff --git a/dist/features/mouse/index.d.ts b/dist/features/mouse/index.d.ts new file mode 100644 index 00000000..de9aec04 --- /dev/null +++ b/dist/features/mouse/index.d.ts @@ -0,0 +1,11 @@ +import { IFeature, IProxy, UpdateData } from '../../types'; +/** + * Feature to enable mouse controls + * @hidden + */ +export declare class Mouse implements IFeature { + get name(): string; + init(proxy: IProxy): void; + destroy(): void; + update(data: UpdateData): void; +} diff --git a/dist/plugins/mouse/index.js b/dist/features/mouse/index.js similarity index 90% rename from dist/plugins/mouse/index.js rename to dist/features/mouse/index.js index efbe145b..633954c4 100644 --- a/dist/plugins/mouse/index.js +++ b/dist/features/mouse/index.js @@ -1,6 +1,6 @@ import { writeCache } from '../../utils/cache'; /** - * Plugin to enable mouse controls + * Feature to enable mouse controls * @hidden */ export class Mouse { diff --git a/dist/plugins/pagination/index.d.ts b/dist/features/pagination/index.d.ts similarity index 79% rename from dist/plugins/pagination/index.d.ts rename to dist/features/pagination/index.d.ts index 8b51b96b..3faa4272 100644 --- a/dist/plugins/pagination/index.d.ts +++ b/dist/features/pagination/index.d.ts @@ -1,4 +1,4 @@ -import { Plugin, PluginProxy, UpdateData } from '../../types'; +import { IFeature, IProxy, UpdateData } from '../../types'; export declare type Params = { controls: string; className: string; @@ -20,12 +20,12 @@ export declare type Configuration = { title: TextTemplate; }; /** - * The plugin to enable pagination controls. + * The feature to enable pagination controls. */ -export declare class Pagination implements Plugin { +export declare class Pagination implements IFeature { constructor(options?: Partial); get name(): string; - init(proxy: PluginProxy): void; + init(proxy: IProxy): void; destroy(): void; update(data: UpdateData): void; private _add; diff --git a/dist/plugins/pagination/index.js b/dist/features/pagination/index.js similarity index 91% rename from dist/plugins/pagination/index.js rename to dist/features/pagination/index.js index 3600ac0a..672316de 100644 --- a/dist/plugins/pagination/index.js +++ b/dist/features/pagination/index.js @@ -25,7 +25,7 @@ const CACHE_KEY_CONFIGURATION = 'config'; const CACHE_KEY_PAGINATION = 'pagination'; const CACHE_KEY_BUTTONS = 'buttons'; /** - * The plugin to enable pagination controls. + * The feature to enable pagination controls. */ export class Pagination { constructor(options = {}) { @@ -71,6 +71,8 @@ export class Pagination { // @TODO: Add template for buttons: const buttons = Array.from(pagination.querySelectorAll('button')) .map((button) => { + // The onClick listener was already bound in the constructor. + // // eslint-disable-next-line @typescript-eslint/unbound-method button.addEventListener('click', this._onClick, true); return button; @@ -84,7 +86,7 @@ export class Pagination { const proxy = fromCache(this, CACHE_KEY_PROXY); const buttons = fromCache(this, CACHE_KEY_BUTTONS); const { pageIndex } = proxy; - buttons === null || buttons === void 0 ? void 0 : buttons.forEach((button, at) => button.disabled = (at === pageIndex)); + buttons.forEach((button, at) => button.disabled = (at === pageIndex)); } _remove() { var _a; @@ -92,6 +94,8 @@ export class Pagination { const buttons = fromCache(this, CACHE_KEY_BUTTONS); buttons === null || buttons === void 0 ? void 0 : buttons.forEach((button) => { var _a; + // The onClick listener was already bound in the constructor. + // // eslint-disable-next-line @typescript-eslint/unbound-method button.removeEventListener('click', this._onClick); (_a = button.parentNode) === null || _a === void 0 ? void 0 : _a.removeChild(button); @@ -101,11 +105,10 @@ export class Pagination { clearCache(this, CACHE_KEY_PAGINATION); } _onClick(event) { - var _a; const proxy = fromCache(this, CACHE_KEY_PROXY); const buttons = fromCache(this, CACHE_KEY_BUTTONS); const target = event.currentTarget; - const index = (_a = buttons === null || buttons === void 0 ? void 0 : buttons.indexOf(target)) !== null && _a !== void 0 ? _a : 0; + const index = buttons.indexOf(target); proxy.index = proxy.pages[index]; } } diff --git a/dist/formats/cjs/caroucssel.js b/dist/formats/cjs/caroucssel.js index f7f3155b..736a67cc 100644 --- a/dist/formats/cjs/caroucssel.js +++ b/dist/formats/cjs/caroucssel.js @@ -138,9 +138,6 @@ class Buttons { } _remove() { const buttons = fromCache(this, CACHE_KEY_BUTTONS$1); - if (!buttons) { - return; - } buttons.forEach((button) => { var _a; button === null || button === void 0 ? void 0 : button.removeEventListener('click', this._onPrevious); @@ -162,18 +159,18 @@ class Buttons { } } -exports.UpdateReason = void 0; +var UpdateReason; (function (UpdateReason) { UpdateReason["SCROLL"] = "scroll"; UpdateReason["RESIZE"] = "resize"; UpdateReason["FORCED"] = "forced"; - UpdateReason["PLUGIN"] = "plugin"; -})(exports.UpdateReason || (exports.UpdateReason = {})); -exports.ScrollBehavior = void 0; + UpdateReason["FEATURE"] = "feature"; +})(UpdateReason || (UpdateReason = {})); +var ScrollBehavior; (function (ScrollBehavior) { ScrollBehavior["AUTO"] = "auto"; ScrollBehavior["SMOOTH"] = "smooth"; -})(exports.ScrollBehavior || (exports.ScrollBehavior = {})); +})(ScrollBehavior || (ScrollBehavior = {})); class Scrollbar { constructor() { @@ -212,8 +209,9 @@ class Scrollbar { let __scrollbar; const DEFAULTS$2 = { enabled: true, + className: 'caroucssel-mask', + tagName: 'div', }; -const CLASSNAME = 'caroucssel-mask'; const CACHE_KEY_PROXY$2 = 'proxy'; const CACHE_KEY_CONFIGURATION$2 = 'config'; const CACHE_KEY_MASK$1 = 'mask'; @@ -240,8 +238,8 @@ class Mask { } update(data) { switch (data.reason) { - case exports.UpdateReason.RESIZE: - case exports.UpdateReason.FORCED: + case UpdateReason.RESIZE: + case UpdateReason.FORCED: clearCache(this, CACHE_KEY_HEIGHT); this._render(); break; @@ -251,7 +249,7 @@ class Mask { } } _render() { - const { enabled } = fromCache(this, CACHE_KEY_CONFIGURATION$2); + const { enabled, className, tagName } = fromCache(this, CACHE_KEY_CONFIGURATION$2); if (!enabled) { return; } @@ -263,8 +261,8 @@ class Mask { } fromCache(this, CACHE_KEY_MASK$1, () => { var _a; - const mask = document.createElement('div'); - mask.className = CLASSNAME; + const mask = document.createElement(tagName); + mask.className = className; mask.style.overflow = 'hidden'; mask.style.height = '100%'; (_a = element.parentNode) === null || _a === void 0 ? void 0 : _a.insertBefore(mask, element); @@ -345,7 +343,7 @@ class Pagination { } update(data) { switch (data.reason) { - case exports.UpdateReason.SCROLL: + case UpdateReason.SCROLL: this._update(); break; default: @@ -382,7 +380,7 @@ class Pagination { const proxy = fromCache(this, CACHE_KEY_PROXY$1); const buttons = fromCache(this, CACHE_KEY_BUTTONS); const { pageIndex } = proxy; - buttons === null || buttons === void 0 ? void 0 : buttons.forEach((button, at) => button.disabled = (at === pageIndex)); + buttons.forEach((button, at) => button.disabled = (at === pageIndex)); } _remove() { var _a; @@ -398,15 +396,62 @@ class Pagination { clearCache(this, CACHE_KEY_PAGINATION); } _onClick(event) { - var _a; const proxy = fromCache(this, CACHE_KEY_PROXY$1); const buttons = fromCache(this, CACHE_KEY_BUTTONS); const target = event.currentTarget; - const index = (_a = buttons === null || buttons === void 0 ? void 0 : buttons.indexOf(target)) !== null && _a !== void 0 ? _a : 0; + const index = buttons.indexOf(target); proxy.index = proxy.pages[index]; } } +const CACHE_KEY_INSTANCE = 'instance'; +const CACHE_KEY_FEATURES$1 = 'features'; +function __getInstance(ref) { + return fromCache(ref, CACHE_KEY_INSTANCE); +} +function __getFeatures(ref) { + return fromCache(ref, CACHE_KEY_FEATURES$1); +} +class Proxy { + constructor(instance, features) { + writeCache(this, CACHE_KEY_INSTANCE, instance); + writeCache(this, CACHE_KEY_FEATURES$1, features); + } + get id() { + return __getInstance(this).id; + } + get el() { + return __getInstance(this).el; + } + get mask() { + return __getInstance(this).mask; + } + get index() { + return __getInstance(this).index; + } + set index(value) { + __getInstance(this).index = value; + } + get items() { + return __getInstance(this).items; + } + get pages() { + return __getInstance(this).pages; + } + get pageIndex() { + return __getInstance(this).pageIndex; + } + update(sender) { + __getInstance(this).update(); + __getFeatures(this).forEach((feature) => { + if (feature === sender) { + return; + } + feature.update({ reason: UpdateReason.FEATURE }); + }); + } +} + function debounce(func, delay) { let timeout = null; const debounced = (...args) => { @@ -420,6 +465,8 @@ function debounce(func, delay) { const ID_NAME = (count) => `caroucssel-${count}`; const ID_MATCH = /^caroucssel-[0-9]*$/; +const EVENT_SCROLL = 'scroll'; +const EVENT_RESIZE = 'resize'; const CACHE_KEY_ELEMENT = 'element'; const CACHE_KEY_ID = 'id'; const CACHE_KEY_CONFIGURATION = 'config'; @@ -429,58 +476,18 @@ const CACHE_KEY_PAGES = 'pages'; const CACHE_KEY_PAGE_INDEX = 'page-index'; const CACHE_KEY_MASK = 'mask'; const CACHE_KEY_PROXY = 'proxy'; -const CACHE_KEY_PLUGINS = 'plugins'; -const CACHE_KEY_PROXY_INSTANCE = 'proxy:instance'; -const CACHE_KEY_PROXY_PLUGIN = 'proxy:plugins'; +const CACHE_KEY_FEATURES = 'feautres'; const VISIBILITY_OFFSET = 0.25; const INVISIBLE_ELEMENTS = /^(link|meta|noscript|script|style|title)$/i; -const EVENT_SCROLL = 'scroll'; -const EVENT_RESIZE = 'resize'; const DEFAULTS = { - plugins: [], + features: [], filterItem: () => true, onScroll: () => undefined, }; let __instanceCount = 0; -class Proxy { - constructor(instance, plugins) { - writeCache(this, CACHE_KEY_PROXY_INSTANCE, instance); - writeCache(this, CACHE_KEY_PROXY_PLUGIN, plugins); - } - get el() { - const instance = fromCache(this, CACHE_KEY_PROXY_INSTANCE); - return instance.el; - } - get mask() { - const instance = fromCache(this, CACHE_KEY_PROXY_INSTANCE); - return instance.mask; - } - get index() { - const instance = fromCache(this, CACHE_KEY_PROXY_INSTANCE); - return instance.index; - } - set index(value) { - const instance = fromCache(this, CACHE_KEY_PROXY_INSTANCE); - instance.index = value; - } - get items() { - const instance = fromCache(this, CACHE_KEY_PROXY_INSTANCE); - return instance.items; - } - get pages() { - const instance = fromCache(this, CACHE_KEY_PROXY_INSTANCE); - return instance.pages; - } - get pageIndex() { - const instance = fromCache(this, CACHE_KEY_PROXY_INSTANCE); - return instance.pageIndex; - } - update(plugin) { - } -} class Carousel { constructor(el, options = {}) { - this.behavior = exports.ScrollBehavior.AUTO; + this.behavior = ScrollBehavior.AUTO; if (!el || !(el instanceof Element)) { throw new Error(`Carousel needs a dom element but "${(typeof el)}" was passed.`); } @@ -490,18 +497,20 @@ class Carousel { writeCache(this, CACHE_KEY_ID, el.id); const configuration = Object.assign(Object.assign({}, DEFAULTS), options); writeCache(this, CACHE_KEY_CONFIGURATION, configuration); - const plugins = [...configuration.plugins]; - const index = configuration.plugins.findIndex((plugin) => plugin instanceof Mask); - let mask = new Mask(); + let mask = null; + let features = [...configuration.features]; + const index = configuration.features.findIndex((feature) => feature instanceof Mask); if (index > -1) { - [mask] = plugins.splice(index, 1); + [mask] = features.splice(index, 1); } - plugins.unshift(mask); + mask !== null && mask !== void 0 ? mask : (mask = new Mask()); + features = features.filter((feature) => !(feature instanceof Mask)); + features = [mask, ...features]; writeCache(this, CACHE_KEY_MASK, mask); - const proxy = new Proxy(this, plugins); + const proxy = new Proxy(this, features); writeCache(this, CACHE_KEY_PROXY, proxy); - writeCache(this, CACHE_KEY_PLUGINS, plugins); - plugins.forEach((plugin) => plugin.init(proxy)); + writeCache(this, CACHE_KEY_FEATURES, features); + features.forEach((feature) => feature.init(proxy)); switch (true) { case Array.isArray(options.index): this.index = options.index; @@ -510,7 +519,7 @@ class Carousel { this.index = [options.index]; break; } - this.behavior = exports.ScrollBehavior.SMOOTH; + this.behavior = ScrollBehavior.SMOOTH; this._onScroll = debounce(this._onScroll.bind(this), 25); this._onResize = debounce(this._onResize.bind(this), 25); el.addEventListener(EVENT_SCROLL, this._onScroll); @@ -560,9 +569,6 @@ class Carousel { if (!Array.isArray(values) || !values.length) { return; } - if (length === 0) { - return; - } let value = values[0] || 0; value = Math.max(Math.min(value, length - 1), 0); const { scrollLeft } = el; @@ -654,8 +660,8 @@ class Carousel { destroy() { const { el } = this; ID_MATCH.test(el.id) && el.removeAttribute('id'); - const plugins = fromCache(this, CACHE_KEY_PLUGINS); - plugins === null || plugins === void 0 ? void 0 : plugins.forEach((plugin) => plugin.destroy()); + const features = fromCache(this, CACHE_KEY_FEATURES); + features.forEach((feature) => feature.destroy()); el.removeEventListener(EVENT_SCROLL, this._onScroll); window.removeEventListener(EVENT_RESIZE, this._onResize); clearFullCache(this); @@ -665,29 +671,32 @@ class Carousel { clearCache(this, CACHE_KEY_ITEMS); clearCache(this, CACHE_KEY_PAGES); clearCache(this, CACHE_KEY_PAGE_INDEX); - const plugins = fromCache(this, CACHE_KEY_PLUGINS); - plugins === null || plugins === void 0 ? void 0 : plugins.forEach((plugin) => plugin.update({ reason: exports.UpdateReason.FORCED })); + const features = fromCache(this, CACHE_KEY_FEATURES); + features.forEach((feature) => feature.update({ reason: UpdateReason.FORCED })); } _onScroll(event) { clearCache(this, CACHE_KEY_INDEX); clearCache(this, CACHE_KEY_PAGE_INDEX); - const plugins = fromCache(this, CACHE_KEY_PLUGINS); - plugins === null || plugins === void 0 ? void 0 : plugins.forEach((plugin) => plugin.update({ reason: exports.UpdateReason.SCROLL })); + const features = fromCache(this, CACHE_KEY_FEATURES); + features.forEach((feature) => feature.update({ reason: UpdateReason.SCROLL })); const { index } = this; const configuration = fromCache(this, CACHE_KEY_CONFIGURATION); - configuration === null || configuration === void 0 ? void 0 : configuration.onScroll({ index, type: EVENT_SCROLL, target: this, originalEvent: event }); + configuration.onScroll({ index, type: EVENT_SCROLL, target: this, originalEvent: event }); } _onResize() { clearCache(this, CACHE_KEY_PAGES); clearCache(this, CACHE_KEY_INDEX); clearCache(this, CACHE_KEY_PAGE_INDEX); - const plugins = fromCache(this, CACHE_KEY_PLUGINS); - plugins === null || plugins === void 0 ? void 0 : plugins.forEach((plugin) => plugin.update({ reason: exports.UpdateReason.RESIZE })); + const features = fromCache(this, CACHE_KEY_FEATURES); + features.forEach((feature) => feature.update({ reason: UpdateReason.RESIZE })); } } +const version = '0.12.0-2'; + exports.Buttons = Buttons; exports.Carousel = Carousel; exports.Mask = Mask; exports.Mouse = Mouse; exports.Pagination = Pagination; +exports.version = version; diff --git a/dist/formats/cjs/caroucssel.min.js b/dist/formats/cjs/caroucssel.min.js index b5237ee9..5503fdd9 100644 --- a/dist/formats/cjs/caroucssel.min.js +++ b/dist/formats/cjs/caroucssel.min.js @@ -1 +1 @@ -"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const t=new WeakMap;function e(e,n,s){const i=t.get(e)||{};if(n in i)return i[n];if(!s)return;const o=s();return i[n]=o,t.set(e,i),o}function n(e,n,s){const i=t.get(e)||{};i[n]=s,t.set(e,i)}function s(e,n){const s=t.get(e);s&&(s[n]=void 0,delete s[n])}function i(e){t.delete(e)}function o(t,e){const n=document.createElement("div");n.innerHTML=t(e);const s=n.firstElementChild;return s||null}const r={template:({className:t,controls:e,label:n,title:s})=>`\n\t\t\n\t`,className:"button",nextClassName:"is-next",nextLabel:"Next",nextTitle:"Go to next",previousClassName:"is-previous",previousLabel:"Previous",previousTitle:"Go to previous"};var l,a;exports.UpdateReason=void 0,(l=exports.UpdateReason||(exports.UpdateReason={})).SCROLL="scroll",l.RESIZE="resize",l.FORCED="forced",l.PLUGIN="plugin",exports.ScrollBehavior=void 0,(a=exports.ScrollBehavior||(exports.ScrollBehavior={})).AUTO="auto",a.SMOOTH="smooth";class c{constructor(){window.addEventListener("resize",(()=>{s(this,"dimensions")}))}get dimensions(){return e(this,"dimensions",(()=>{const t=document.createElement("div"),e=document.createElement("div");document.body.appendChild(e),e.style.position="absolute",e.style.top="0px",e.style.left="0px",e.style.visibility="hidden",e.appendChild(t),t.style.width="200px",t.style.height="100%",e.style.width="150px",e.style.height="200px",e.style.overflow="hidden";const n=t.offsetHeight;e.style.overflow="scroll";let s=t.offsetHeight;s=n===s?e.clientHeight:s;const i=n-s;return document.body.removeChild(e),{height:i}}))}}let d;const h={enabled:!0};class u{constructor(t={}){n(this,"config",Object.assign(Object.assign({},h),t))}get name(){return"buildin:mask"}get el(){var t;return null!==(t=e(this,"mask"))&&void 0!==t?t:null}init(t){n(this,"proxy",t),d=d||new c,this._render()}destroy(){this._remove(),i(this)}update(t){switch(t.reason){case exports.UpdateReason.RESIZE:case exports.UpdateReason.FORCED:s(this,"scrollbar"),this._render();break;default:this._render()}}_render(){const{enabled:t}=e(this,"config");if(!t)return;const s=e(this,"proxy").el;let{height:i}=d.dimensions;s.scrollWidth<=s.clientWidth&&(i=0),e(this,"mask",(()=>{var t;const e=document.createElement("div");return e.className="caroucssel-mask",e.style.overflow="hidden",e.style.height="100%",null===(t=s.parentNode)||void 0===t||t.insertBefore(e,s),e.appendChild(s),e}));i!==e(this,"scrollbar")&&(n(this,"scrollbar",i),s.style.height=`calc(100% + ${i}px)`,s.style.marginBottom=-1*i+"px")}_remove(){var t,n;const{el:s}=e(this,"proxy"),i=e(this,"mask");null===(t=null==i?void 0:i.parentNode)||void 0===t||t.insertBefore(s,i),null===(n=null==i?void 0:i.parentNode)||void 0===n||n.removeChild(i),s.removeAttribute("style")}}const p={template:({className:t,controls:e,pages:n,label:s,title:i})=>`\n\t\t
    \n\t\t\t${n.map(((t,o)=>{const r={index:o,page:t,pages:n},l=s(r),a=i(r);return`
  • \n\t\t\t\t\t\n\t\t\t\t
  • `})).join("")}\n\t\t
\n\t`,className:"pagination",label:({index:t})=>`${t+1}`,title:({index:t})=>`Go to ${t+1}. page`};function g(t,e){let n=null;return(...s)=>{null!==n&&clearTimeout(n),n=setTimeout((()=>t(...s)),e)}}const m=/^caroucssel-[0-9]*$/,x=/^(link|meta|noscript|script|style|title)$/i,v={plugins:[],filterItem:()=>!0,onScroll:()=>{}};let f=0;class b{constructor(t,e){n(this,"proxy:instance",t),n(this,"proxy:plugins",e)}get el(){return e(this,"proxy:instance").el}get mask(){return e(this,"proxy:instance").mask}get index(){return e(this,"proxy:instance").index}set index(t){e(this,"proxy:instance").index=t}get items(){return e(this,"proxy:instance").items}get pages(){return e(this,"proxy:instance").pages}get pageIndex(){return e(this,"proxy:instance").pageIndex}update(t){}}exports.Buttons=class{constructor(t={}){n(this,"config",Object.assign(Object.assign({},r),t)),this._onPrevious=this._onPrevious.bind(this),this._onNext=this._onNext.bind(this)}get name(){return"buildin:buttons"}init(t){n(this,"proxy",t),this._render()}destroy(){this._remove(),i(this)}update(){this._render()}_render(){const t=e(this,"proxy"),n=e(this,"config"),{el:s,mask:i,pages:r,pageIndex:l}=t,a=null!=i?i:s,{template:c,className:d,previousClassName:h,previousLabel:u,previousTitle:p,nextClassName:g,nextLabel:m,nextTitle:x}=n,v=[{controls:s.id,label:m,title:x,className:[d,g].join(" "),handler:this._onNext},{controls:s.id,label:u,title:p,className:[d,h].join(" "),handler:this._onPrevious}],[f,b]=e(this,"buttons",(()=>v.map((t=>{var e,{handler:n}=t,s=function(t,e){var n={};for(var s in t)Object.prototype.hasOwnProperty.call(t,s)&&e.indexOf(s)<0&&(n[s]=t[s]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(s=Object.getOwnPropertySymbols(t);i{var e;null==t||t.removeEventListener("click",this._onPrevious),null==t||t.removeEventListener("click",this._onNext),null===(e=null==t?void 0:t.parentNode)||void 0===e||e.removeChild(t)}))}_onPrevious(){const t=e(this,"proxy"),{pages:n,pageIndex:s}=t,i=n[s-1]||n[0];t.index=i}_onNext(){const t=e(this,"proxy"),{pages:n,pageIndex:s}=t,i=n[s+1]||n[n.length-1];t.index=i}},exports.Carousel=class{constructor(t,e={}){if(this.behavior=exports.ScrollBehavior.AUTO,!(t&&t instanceof Element))throw new Error(`Carousel needs a dom element but "${typeof t}" was passed.`);n(this,"element",t),f++,t.id=t.id||`caroucssel-${f}`,n(this,"id",t.id);const s=Object.assign(Object.assign({},v),e);n(this,"config",s);const i=[...s.plugins],o=s.plugins.findIndex((t=>t instanceof u));let r=new u;o>-1&&([r]=i.splice(o,1)),i.unshift(r),n(this,"mask",r);const l=new b(this,i);switch(n(this,"proxy",l),n(this,"plugins",i),i.forEach((t=>t.init(l))),!0){case Array.isArray(e.index):this.index=e.index;break;case!isNaN(e.index):this.index=[e.index]}this.behavior=exports.ScrollBehavior.SMOOTH,this._onScroll=g(this._onScroll.bind(this),25),this._onResize=g(this._onResize.bind(this),25),t.addEventListener("scroll",this._onScroll),window.addEventListener("resize",this._onResize)}static resetInstanceCount(){}get el(){return e(this,"element")}get mask(){var t;return null!==(t=e(this,"mask").el)&&void 0!==t?t:null}get id(){return e(this,"id")}get index(){return e(this,"index",(()=>{const{el:t,items:e}=this,{length:n}=e,{clientWidth:s}=t,i=t.getBoundingClientRect().left,o=[];let r=0;for(;r=0&&l+.75*n<=s&&o.push(r)}return 0===o.length?[0]:o}))}set index(t){const{behavior:e,el:n,items:i}=this,{length:o}=i;if(!Array.isArray(t)||!t.length)return;if(0===o)return;let r=t[0]||0;r=Math.max(Math.min(r,o-1),0);const{scrollLeft:l}=n,a=l,c={left:i[r].offsetLeft};r===this.pages[0][0]&&(c.left=0),a!==c.left&&(s(this,"index"),n.scrollTo(Object.assign(Object.assign({},c),{behavior:e})))}get items(){return e(this,"items",(()=>{const{filterItem:t}=e(this,"config"),{el:n}=this;return Array.from(n.children).filter((t=>!x.test(t.tagName)&&!t.hidden)).filter(t)}))}get pages(){return e(this,"pages",(()=>{const{el:t,items:e}=this,{clientWidth:n}=t;if(0===n)return e.map(((t,e)=>[e]));let s=[[]];return e.map(((t,e)=>{const{offsetLeft:n,clientWidth:s}=t;return{left:n,width:s,item:t,index:e}})).sort(((t,e)=>t.left-e.left)).forEach((t=>{const{left:e,width:i}=t,o=s[s.length-1],r=o[0];let l=(null==r?void 0:r.left)||0;o===s[0]&&(l=0);let a=Math.floor((e-l+.75*i)/n);for(;a>0;)s.push([]),a--;s[s.length-1].push(t)})),s=s.filter((t=>0!==t.length)),s.map((t=>t.map((({index:t})=>t))))}))}get pageIndex(){return e(this,"page-index",(()=>{const{el:t,items:e,index:n,pages:s}=this,i=t.getBoundingClientRect().left,{clientWidth:o}=t;let r=n.reduce(((t,n)=>{if(!e[n])return t;let{left:s,right:r}=e[n].getBoundingClientRect();return s=Math.round(s-i),r=Math.round(r-i),s<0||o{const s=e[t].getBoundingClientRect().right;return e[n].getBoundingClientRect().right-s}))[0];return s.findIndex((t=>t.includes(l)))}))}destroy(){const{el:t}=this;m.test(t.id)&&t.removeAttribute("id");const n=e(this,"plugins");null==n||n.forEach((t=>t.destroy())),t.removeEventListener("scroll",this._onScroll),window.removeEventListener("resize",this._onResize),i(this)}update(){s(this,"index"),s(this,"items"),s(this,"pages"),s(this,"page-index");const t=e(this,"plugins");null==t||t.forEach((t=>t.update({reason:exports.UpdateReason.FORCED})))}_onScroll(t){s(this,"index"),s(this,"page-index");const n=e(this,"plugins");null==n||n.forEach((t=>t.update({reason:exports.UpdateReason.SCROLL})));const{index:i}=this,o=e(this,"config");null==o||o.onScroll({index:i,type:"scroll",target:this,originalEvent:t})}_onResize(){s(this,"pages"),s(this,"index"),s(this,"page-index");const t=e(this,"plugins");null==t||t.forEach((t=>t.update({reason:exports.UpdateReason.RESIZE})))}},exports.Mask=u,exports.Mouse=class{get name(){return"buildin:mouse"}init(t){n(this,"proxy",t)}destroy(){console.log("Destroy mouse")}update(t){console.log("Update mouse:",t.reason)}},exports.Pagination=class{constructor(t={}){n(this,"config",Object.assign(Object.assign({},p),t)),this._onClick=this._onClick.bind(this)}get name(){return"buildin:pagination"}init(t){n(this,"proxy",t),this._add()}destroy(){this._remove(),i(this)}update(t){switch(t.reason){case exports.UpdateReason.SCROLL:this._update();break;default:this._remove(),this._add()}}_add(){var t;const s=e(this,"proxy"),i=e(this,"config"),{el:r,mask:l,pages:a}=s,c=null!=l?l:r;if(a.length<2)return;const{template:d,className:h,label:u,title:p}=i,g=o(d,{label:u,title:p,pages:a,className:h,controls:r.id});if(!g)return;const m=Array.from(g.querySelectorAll("button")).map((t=>(t.addEventListener("click",this._onClick,!0),t)));null===(t=c.parentNode)||void 0===t||t.appendChild(g),n(this,"pagination",g),n(this,"buttons",m),this._update()}_update(){const t=e(this,"proxy"),n=e(this,"buttons"),{pageIndex:s}=t;null==n||n.forEach(((t,e)=>t.disabled=e===s))}_remove(){var t;const n=e(this,"pagination"),i=e(this,"buttons");null==i||i.forEach((t=>{var e;t.removeEventListener("click",this._onClick),null===(e=t.parentNode)||void 0===e||e.removeChild(t)})),null===(t=null==n?void 0:n.parentNode)||void 0===t||t.removeChild(n),s(this,"buttons"),s(this,"pagination")}_onClick(t){var n;const s=e(this,"proxy"),i=e(this,"buttons"),o=t.currentTarget,r=null!==(n=null==i?void 0:i.indexOf(o))&&void 0!==n?n:0;s.index=s.pages[r]}}; +"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const t=new WeakMap;function e(e,s,n){const i=t.get(e)||{};if(s in i)return i[s];if(!n)return;const o=n();return i[s]=o,t.set(e,i),o}function s(e,s,n){const i=t.get(e)||{};i[s]=n,t.set(e,i)}function n(e,s){const n=t.get(e);n&&(n[s]=void 0,delete n[s])}function i(e){t.delete(e)}function o(t,e){const s=document.createElement("div");s.innerHTML=t(e);const n=s.firstElementChild;return n||null}const r={template:({className:t,controls:e,label:s,title:n})=>`\n\t\t\n\t`,className:"button",nextClassName:"is-next",nextLabel:"Next",nextTitle:"Go to next",previousClassName:"is-previous",previousLabel:"Previous",previousTitle:"Go to previous"};var l,a;!function(t){t.SCROLL="scroll",t.RESIZE="resize",t.FORCED="forced",t.FEATURE="feature"}(l||(l={})),function(t){t.AUTO="auto",t.SMOOTH="smooth"}(a||(a={}));class c{constructor(){window.addEventListener("resize",(()=>{n(this,"dimensions")}))}get dimensions(){return e(this,"dimensions",(()=>{const t=document.createElement("div"),e=document.createElement("div");document.body.appendChild(e),e.style.position="absolute",e.style.top="0px",e.style.left="0px",e.style.visibility="hidden",e.appendChild(t),t.style.width="200px",t.style.height="100%",e.style.width="150px",e.style.height="200px",e.style.overflow="hidden";const s=t.offsetHeight;e.style.overflow="scroll";let n=t.offsetHeight;n=s===n?e.clientHeight:n;const i=s-n;return document.body.removeChild(e),{height:i}}))}}let d;const h={enabled:!0,className:"caroucssel-mask",tagName:"div"};class u{constructor(t={}){s(this,"config",Object.assign(Object.assign({},h),t))}get name(){return"buildin:mask"}get el(){var t;return null!==(t=e(this,"mask"))&&void 0!==t?t:null}init(t){s(this,"proxy",t),d=d||new c,this._render()}destroy(){this._remove(),i(this)}update(t){switch(t.reason){case l.RESIZE:case l.FORCED:n(this,"scrollbar"),this._render();break;default:this._render()}}_render(){const{enabled:t,className:n,tagName:i}=e(this,"config");if(!t)return;const o=e(this,"proxy").el;let{height:r}=d.dimensions;o.scrollWidth<=o.clientWidth&&(r=0),e(this,"mask",(()=>{var t;const e=document.createElement(i);return e.className=n,e.style.overflow="hidden",e.style.height="100%",null===(t=o.parentNode)||void 0===t||t.insertBefore(e,o),e.appendChild(o),e}));r!==e(this,"scrollbar")&&(s(this,"scrollbar",r),o.style.height=`calc(100% + ${r}px)`,o.style.marginBottom=-1*r+"px")}_remove(){var t,s;const{el:n}=e(this,"proxy"),i=e(this,"mask");null===(t=null==i?void 0:i.parentNode)||void 0===t||t.insertBefore(n,i),null===(s=null==i?void 0:i.parentNode)||void 0===s||s.removeChild(i),n.removeAttribute("style")}}const p={template:({className:t,controls:e,pages:s,label:n,title:i})=>`\n\t\t
    \n\t\t\t${s.map(((t,o)=>{const r={index:o,page:t,pages:s},l=n(r),a=i(r);return`
  • \n\t\t\t\t\t\n\t\t\t\t
  • `})).join("")}\n\t\t
\n\t`,className:"pagination",label:({index:t})=>`${t+1}`,title:({index:t})=>`Go to ${t+1}. page`};function g(t){return e(t,"instance")}class m{constructor(t,e){s(this,"instance",t),s(this,"features",e)}get id(){return g(this).id}get el(){return g(this).el}get mask(){return g(this).mask}get index(){return g(this).index}set index(t){g(this).index=t}get items(){return g(this).items}get pages(){return g(this).pages}get pageIndex(){return g(this).pageIndex}update(t){var s;g(this).update(),(s=this,e(s,"features")).forEach((e=>{e!==t&&e.update({reason:l.FEATURE})}))}}function f(t,e){let s=null;return(...n)=>{null!==s&&clearTimeout(s),s=setTimeout((()=>t(...n)),e)}}const v=/^caroucssel-[0-9]*$/,x=/^(link|meta|noscript|script|style|title)$/i,b={features:[],filterItem:()=>!0,onScroll:()=>{}};let y=0;exports.Buttons=class{constructor(t={}){s(this,"config",Object.assign(Object.assign({},r),t)),this._onPrevious=this._onPrevious.bind(this),this._onNext=this._onNext.bind(this)}get name(){return"buildin:buttons"}init(t){s(this,"proxy",t),this._render()}destroy(){this._remove(),i(this)}update(){this._render()}_render(){const t=e(this,"proxy"),s=e(this,"config"),{el:n,mask:i,pages:r,pageIndex:l}=t,a=null!=i?i:n,{template:c,className:d,previousClassName:h,previousLabel:u,previousTitle:p,nextClassName:g,nextLabel:m,nextTitle:f}=s,v=[{controls:n.id,label:m,title:f,className:[d,g].join(" "),handler:this._onNext},{controls:n.id,label:u,title:p,className:[d,h].join(" "),handler:this._onPrevious}],[x,b]=e(this,"buttons",(()=>v.map((t=>{var e,{handler:s}=t,n=function(t,e){var s={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(s[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(n=Object.getOwnPropertySymbols(t);i{var e;null==t||t.removeEventListener("click",this._onPrevious),null==t||t.removeEventListener("click",this._onNext),null===(e=null==t?void 0:t.parentNode)||void 0===e||e.removeChild(t)}))}_onPrevious(){const t=e(this,"proxy"),{pages:s,pageIndex:n}=t,i=s[n-1]||s[0];t.index=i}_onNext(){const t=e(this,"proxy"),{pages:s,pageIndex:n}=t,i=s[n+1]||s[s.length-1];t.index=i}},exports.Carousel=class{constructor(t,e={}){if(this.behavior=a.AUTO,!(t&&t instanceof Element))throw new Error(`Carousel needs a dom element but "${typeof t}" was passed.`);s(this,"element",t),y++,t.id=t.id||`caroucssel-${y}`,s(this,"id",t.id);const n=Object.assign(Object.assign({},b),e);s(this,"config",n);let i=null,o=[...n.features];const r=n.features.findIndex((t=>t instanceof u));r>-1&&([i]=o.splice(r,1)),null!=i||(i=new u),o=o.filter((t=>!(t instanceof u))),o=[i,...o],s(this,"mask",i);const l=new m(this,o);switch(s(this,"proxy",l),s(this,"feautres",o),o.forEach((t=>t.init(l))),!0){case Array.isArray(e.index):this.index=e.index;break;case!isNaN(e.index):this.index=[e.index]}this.behavior=a.SMOOTH,this._onScroll=f(this._onScroll.bind(this),25),this._onResize=f(this._onResize.bind(this),25),t.addEventListener("scroll",this._onScroll),window.addEventListener("resize",this._onResize)}static resetInstanceCount(){}get el(){return e(this,"element")}get mask(){var t;return null!==(t=e(this,"mask").el)&&void 0!==t?t:null}get id(){return e(this,"id")}get index(){return e(this,"index",(()=>{const{el:t,items:e}=this,{length:s}=e,{clientWidth:n}=t,i=t.getBoundingClientRect().left,o=[];let r=0;for(;r=0&&l+.75*s<=n&&o.push(r)}return 0===o.length?[0]:o}))}set index(t){const{behavior:e,el:s,items:i}=this,{length:o}=i;if(!Array.isArray(t)||!t.length)return;let r=t[0]||0;r=Math.max(Math.min(r,o-1),0);const{scrollLeft:l}=s,a=l,c={left:i[r].offsetLeft};r===this.pages[0][0]&&(c.left=0),a!==c.left&&(n(this,"index"),s.scrollTo(Object.assign(Object.assign({},c),{behavior:e})))}get items(){return e(this,"items",(()=>{const{filterItem:t}=e(this,"config"),{el:s}=this;return Array.from(s.children).filter((t=>!x.test(t.tagName)&&!t.hidden)).filter(t)}))}get pages(){return e(this,"pages",(()=>{const{el:t,items:e}=this,{clientWidth:s}=t;if(0===s)return e.map(((t,e)=>[e]));let n=[[]];return e.map(((t,e)=>{const{offsetLeft:s,clientWidth:n}=t;return{left:s,width:n,item:t,index:e}})).sort(((t,e)=>t.left-e.left)).forEach((t=>{const{left:e,width:i}=t,o=n[n.length-1],r=o[0];let l=(null==r?void 0:r.left)||0;o===n[0]&&(l=0);let a=Math.floor((e-l+.75*i)/s);for(;a>0;)n.push([]),a--;n[n.length-1].push(t)})),n=n.filter((t=>0!==t.length)),n.map((t=>t.map((({index:t})=>t))))}))}get pageIndex(){return e(this,"page-index",(()=>{const{el:t,items:e,index:s,pages:n}=this,i=t.getBoundingClientRect().left,{clientWidth:o}=t;let r=s.reduce(((t,s)=>{if(!e[s])return t;let{left:n,right:r}=e[s].getBoundingClientRect();return n=Math.round(n-i),r=Math.round(r-i),n<0||o{const n=e[t].getBoundingClientRect().right;return e[s].getBoundingClientRect().right-n}))[0];return n.findIndex((t=>t.includes(l)))}))}destroy(){const{el:t}=this;v.test(t.id)&&t.removeAttribute("id");e(this,"feautres").forEach((t=>t.destroy())),t.removeEventListener("scroll",this._onScroll),window.removeEventListener("resize",this._onResize),i(this)}update(){n(this,"index"),n(this,"items"),n(this,"pages"),n(this,"page-index");e(this,"feautres").forEach((t=>t.update({reason:l.FORCED})))}_onScroll(t){n(this,"index"),n(this,"page-index");e(this,"feautres").forEach((t=>t.update({reason:l.SCROLL})));const{index:s}=this;e(this,"config").onScroll({index:s,type:"scroll",target:this,originalEvent:t})}_onResize(){n(this,"pages"),n(this,"index"),n(this,"page-index");e(this,"feautres").forEach((t=>t.update({reason:l.RESIZE})))}},exports.Mask=u,exports.Mouse=class{get name(){return"buildin:mouse"}init(t){s(this,"proxy",t)}destroy(){console.log("Destroy mouse")}update(t){console.log("Update mouse:",t.reason)}},exports.Pagination=class{constructor(t={}){s(this,"config",Object.assign(Object.assign({},p),t)),this._onClick=this._onClick.bind(this)}get name(){return"buildin:pagination"}init(t){s(this,"proxy",t),this._add()}destroy(){this._remove(),i(this)}update(t){switch(t.reason){case l.SCROLL:this._update();break;default:this._remove(),this._add()}}_add(){var t;const n=e(this,"proxy"),i=e(this,"config"),{el:r,mask:l,pages:a}=n,c=null!=l?l:r;if(a.length<2)return;const{template:d,className:h,label:u,title:p}=i,g=o(d,{label:u,title:p,pages:a,className:h,controls:r.id});if(!g)return;const m=Array.from(g.querySelectorAll("button")).map((t=>(t.addEventListener("click",this._onClick,!0),t)));null===(t=c.parentNode)||void 0===t||t.appendChild(g),s(this,"pagination",g),s(this,"buttons",m),this._update()}_update(){const t=e(this,"proxy"),s=e(this,"buttons"),{pageIndex:n}=t;s.forEach(((t,e)=>t.disabled=e===n))}_remove(){var t;const s=e(this,"pagination"),i=e(this,"buttons");null==i||i.forEach((t=>{var e;t.removeEventListener("click",this._onClick),null===(e=t.parentNode)||void 0===e||e.removeChild(t)})),null===(t=null==s?void 0:s.parentNode)||void 0===t||t.removeChild(s),n(this,"buttons"),n(this,"pagination")}_onClick(t){const s=e(this,"proxy"),n=e(this,"buttons"),i=t.currentTarget,o=n.indexOf(i);s.index=s.pages[o]}},exports.version="0.12.0-2"; diff --git a/dist/formats/umd/caroucssel.js b/dist/formats/umd/caroucssel.js index 54c2d02b..14130d7b 100644 --- a/dist/formats/umd/caroucssel.js +++ b/dist/formats/umd/caroucssel.js @@ -16,7 +16,7 @@ Object.defineProperty(_exports, "__esModule", { value: true }); - _exports.UpdateReason = _exports.ScrollBehavior = _exports.Pagination = _exports.Mouse = _exports.Mask = _exports.Carousel = _exports.Buttons = void 0; + _exports.version = _exports.Pagination = _exports.Mouse = _exports.Mask = _exports.Carousel = _exports.Buttons = void 0; function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } @@ -241,11 +241,6 @@ var _this = this; var buttons = fromCache(this, CACHE_KEY_BUTTONS$1); - - if (!buttons) { - return; - } - buttons.forEach(function (button) { var _a; @@ -279,22 +274,20 @@ _exports.Buttons = Buttons; var UpdateReason; - _exports.UpdateReason = UpdateReason; (function (UpdateReason) { UpdateReason["SCROLL"] = "scroll"; UpdateReason["RESIZE"] = "resize"; UpdateReason["FORCED"] = "forced"; - UpdateReason["PLUGIN"] = "plugin"; - })(UpdateReason || (_exports.UpdateReason = UpdateReason = {})); + UpdateReason["FEATURE"] = "feature"; + })(UpdateReason || (UpdateReason = {})); var ScrollBehavior; - _exports.ScrollBehavior = ScrollBehavior; (function (ScrollBehavior) { ScrollBehavior["AUTO"] = "auto"; ScrollBehavior["SMOOTH"] = "smooth"; - })(ScrollBehavior || (_exports.ScrollBehavior = ScrollBehavior = {})); + })(ScrollBehavior || (ScrollBehavior = {})); var Scrollbar = /*#__PURE__*/function () { function Scrollbar() { @@ -343,9 +336,10 @@ var __scrollbar; var DEFAULTS$2 = { - enabled: true + enabled: true, + className: 'caroucssel-mask', + tagName: 'div' }; - var CLASSNAME = 'caroucssel-mask'; var CACHE_KEY_PROXY$2 = 'proxy'; var CACHE_KEY_CONFIGURATION$2 = 'config'; var CACHE_KEY_MASK$1 = 'mask'; @@ -409,7 +403,9 @@ key: "_render", value: function _render() { var _fromCache3 = fromCache(this, CACHE_KEY_CONFIGURATION$2), - enabled = _fromCache3.enabled; + enabled = _fromCache3.enabled, + className = _fromCache3.className, + tagName = _fromCache3.tagName; if (!enabled) { return; @@ -426,8 +422,8 @@ fromCache(this, CACHE_KEY_MASK$1, function () { var _a; - var mask = document.createElement('div'); - mask.className = CLASSNAME; + var mask = document.createElement(tagName); + mask.className = className; mask.style.overflow = 'hidden'; mask.style.height = '100%'; (_a = element.parentNode) === null || _a === void 0 ? void 0 : _a.insertBefore(mask, element); @@ -624,7 +620,7 @@ var proxy = fromCache(this, CACHE_KEY_PROXY$1); var buttons = fromCache(this, CACHE_KEY_BUTTONS); var pageIndex = proxy.pageIndex; - buttons === null || buttons === void 0 ? void 0 : buttons.forEach(function (button, at) { + buttons.forEach(function (button, at) { return button.disabled = at === pageIndex; }); } @@ -650,12 +646,10 @@ }, { key: "_onClick", value: function _onClick(event) { - var _a; - var proxy = fromCache(this, CACHE_KEY_PROXY$1); var buttons = fromCache(this, CACHE_KEY_BUTTONS); var target = event.currentTarget; - var index = (_a = buttons === null || buttons === void 0 ? void 0 : buttons.indexOf(target)) !== null && _a !== void 0 ? _a : 0; + var index = buttons.indexOf(target); proxy.index = proxy.pages[index]; } }]); @@ -664,6 +658,82 @@ }(); _exports.Pagination = Pagination; + var CACHE_KEY_INSTANCE = 'instance'; + var CACHE_KEY_FEATURES$1 = 'features'; + + function __getInstance(ref) { + return fromCache(ref, CACHE_KEY_INSTANCE); + } + + function __getFeatures(ref) { + return fromCache(ref, CACHE_KEY_FEATURES$1); + } + + var Proxy = /*#__PURE__*/function () { + function Proxy(instance, features) { + _classCallCheck(this, Proxy); + + writeCache(this, CACHE_KEY_INSTANCE, instance); + writeCache(this, CACHE_KEY_FEATURES$1, features); + } + + _createClass(Proxy, [{ + key: "id", + get: function get() { + return __getInstance(this).id; + } + }, { + key: "el", + get: function get() { + return __getInstance(this).el; + } + }, { + key: "mask", + get: function get() { + return __getInstance(this).mask; + } + }, { + key: "index", + get: function get() { + return __getInstance(this).index; + }, + set: function set(value) { + __getInstance(this).index = value; + } + }, { + key: "items", + get: function get() { + return __getInstance(this).items; + } + }, { + key: "pages", + get: function get() { + return __getInstance(this).pages; + } + }, { + key: "pageIndex", + get: function get() { + return __getInstance(this).pageIndex; + } + }, { + key: "update", + value: function update(sender) { + __getInstance(this).update(); + + __getFeatures(this).forEach(function (feature) { + if (feature === sender) { + return; + } + + feature.update({ + reason: UpdateReason.FEATURE + }); + }); + } + }]); + + return Proxy; + }(); function debounce(func, delay) { var timeout = null; @@ -690,6 +760,8 @@ }; var ID_MATCH = /^caroucssel-[0-9]*$/; + var EVENT_SCROLL = 'scroll'; + var EVENT_RESIZE = 'resize'; var CACHE_KEY_ELEMENT = 'element'; var CACHE_KEY_ID = 'id'; var CACHE_KEY_CONFIGURATION = 'config'; @@ -699,15 +771,11 @@ var CACHE_KEY_PAGE_INDEX = 'page-index'; var CACHE_KEY_MASK = 'mask'; var CACHE_KEY_PROXY = 'proxy'; - var CACHE_KEY_PLUGINS = 'plugins'; - var CACHE_KEY_PROXY_INSTANCE = 'proxy:instance'; - var CACHE_KEY_PROXY_PLUGIN = 'proxy:plugins'; + var CACHE_KEY_FEATURES = 'feautres'; var VISIBILITY_OFFSET = 0.25; var INVISIBLE_ELEMENTS = /^(link|meta|noscript|script|style|title)$/i; - var EVENT_SCROLL = 'scroll'; - var EVENT_RESIZE = 'resize'; var DEFAULTS = { - plugins: [], + features: [], filterItem: function filterItem() { return true; }, @@ -717,62 +785,6 @@ }; var __instanceCount = 0; - var Proxy = /*#__PURE__*/function () { - function Proxy(instance, plugins) { - _classCallCheck(this, Proxy); - - writeCache(this, CACHE_KEY_PROXY_INSTANCE, instance); - writeCache(this, CACHE_KEY_PROXY_PLUGIN, plugins); - } - - _createClass(Proxy, [{ - key: "el", - get: function get() { - var instance = fromCache(this, CACHE_KEY_PROXY_INSTANCE); - return instance.el; - } - }, { - key: "mask", - get: function get() { - var instance = fromCache(this, CACHE_KEY_PROXY_INSTANCE); - return instance.mask; - } - }, { - key: "index", - get: function get() { - var instance = fromCache(this, CACHE_KEY_PROXY_INSTANCE); - return instance.index; - }, - set: function set(value) { - var instance = fromCache(this, CACHE_KEY_PROXY_INSTANCE); - instance.index = value; - } - }, { - key: "items", - get: function get() { - var instance = fromCache(this, CACHE_KEY_PROXY_INSTANCE); - return instance.items; - } - }, { - key: "pages", - get: function get() { - var instance = fromCache(this, CACHE_KEY_PROXY_INSTANCE); - return instance.pages; - } - }, { - key: "pageIndex", - get: function get() { - var instance = fromCache(this, CACHE_KEY_PROXY_INSTANCE); - return instance.pageIndex; - } - }, { - key: "update", - value: function update(plugin) {} - }]); - - return Proxy; - }(); - var Carousel = /*#__PURE__*/function () { function Carousel(el) { var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; @@ -791,29 +803,33 @@ writeCache(this, CACHE_KEY_ID, el.id); var configuration = Object.assign(Object.assign({}, DEFAULTS), options); writeCache(this, CACHE_KEY_CONFIGURATION, configuration); + var mask = null; - var plugins = _toConsumableArray(configuration.plugins); + var features = _toConsumableArray(configuration.features); - var index = configuration.plugins.findIndex(function (plugin) { - return plugin instanceof Mask; + var index = configuration.features.findIndex(function (feature) { + return feature instanceof Mask; }); - var mask = new Mask(); if (index > -1) { - var _plugins$splice = plugins.splice(index, 1); + var _features$splice = features.splice(index, 1); - var _plugins$splice2 = _slicedToArray(_plugins$splice, 1); + var _features$splice2 = _slicedToArray(_features$splice, 1); - mask = _plugins$splice2[0]; + mask = _features$splice2[0]; } - plugins.unshift(mask); + mask !== null && mask !== void 0 ? mask : mask = new Mask(); + features = features.filter(function (feature) { + return !(feature instanceof Mask); + }); + features = [mask].concat(_toConsumableArray(features)); writeCache(this, CACHE_KEY_MASK, mask); - var proxy = new Proxy(this, plugins); + var proxy = new Proxy(this, features); writeCache(this, CACHE_KEY_PROXY, proxy); - writeCache(this, CACHE_KEY_PLUGINS, plugins); - plugins.forEach(function (plugin) { - return plugin.init(proxy); + writeCache(this, CACHE_KEY_FEATURES, features); + features.forEach(function (feature) { + return feature.init(proxy); }); switch (true) { @@ -894,10 +910,6 @@ return; } - if (length === 0) { - return; - } - var value = values[0] || 0; value = Math.max(Math.min(value, length - 1), 0); var scrollLeft = el.scrollLeft; @@ -1047,9 +1059,9 @@ value: function destroy() { var el = this.el; ID_MATCH.test(el.id) && el.removeAttribute('id'); - var plugins = fromCache(this, CACHE_KEY_PLUGINS); - plugins === null || plugins === void 0 ? void 0 : plugins.forEach(function (plugin) { - return plugin.destroy(); + var features = fromCache(this, CACHE_KEY_FEATURES); + features.forEach(function (feature) { + return feature.destroy(); }); el.removeEventListener(EVENT_SCROLL, this._onScroll); window.removeEventListener(EVENT_RESIZE, this._onResize); @@ -1062,9 +1074,9 @@ clearCache(this, CACHE_KEY_ITEMS); clearCache(this, CACHE_KEY_PAGES); clearCache(this, CACHE_KEY_PAGE_INDEX); - var plugins = fromCache(this, CACHE_KEY_PLUGINS); - plugins === null || plugins === void 0 ? void 0 : plugins.forEach(function (plugin) { - return plugin.update({ + var features = fromCache(this, CACHE_KEY_FEATURES); + features.forEach(function (feature) { + return feature.update({ reason: UpdateReason.FORCED }); }); @@ -1074,15 +1086,15 @@ value: function _onScroll(event) { clearCache(this, CACHE_KEY_INDEX); clearCache(this, CACHE_KEY_PAGE_INDEX); - var plugins = fromCache(this, CACHE_KEY_PLUGINS); - plugins === null || plugins === void 0 ? void 0 : plugins.forEach(function (plugin) { - return plugin.update({ + var features = fromCache(this, CACHE_KEY_FEATURES); + features.forEach(function (feature) { + return feature.update({ reason: UpdateReason.SCROLL }); }); var index = this.index; var configuration = fromCache(this, CACHE_KEY_CONFIGURATION); - configuration === null || configuration === void 0 ? void 0 : configuration.onScroll({ + configuration.onScroll({ index: index, type: EVENT_SCROLL, target: this, @@ -1095,9 +1107,9 @@ clearCache(this, CACHE_KEY_PAGES); clearCache(this, CACHE_KEY_INDEX); clearCache(this, CACHE_KEY_PAGE_INDEX); - var plugins = fromCache(this, CACHE_KEY_PLUGINS); - plugins === null || plugins === void 0 ? void 0 : plugins.forEach(function (plugin) { - return plugin.update({ + var features = fromCache(this, CACHE_KEY_FEATURES); + features.forEach(function (feature) { + return feature.update({ reason: UpdateReason.RESIZE }); }); @@ -1111,4 +1123,6 @@ }(); _exports.Carousel = Carousel; + var version = '0.12.0-2'; + _exports.version = version; }); diff --git a/dist/formats/umd/caroucssel.min.js b/dist/formats/umd/caroucssel.min.js index 94390963..7ec1872b 100644 --- a/dist/formats/umd/caroucssel.min.js +++ b/dist/formats/umd/caroucssel.min.js @@ -1 +1 @@ -!function(t,e){if("function"==typeof define&&define.amd)define("caroucssel",["exports"],e);else if("undefined"!=typeof exports)e(exports);else{var n={exports:{}};e(n.exports),t.caroucssel=n.exports}}("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:this,(function(t){function e(t){return function(t){if(Array.isArray(t))return o(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||r(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function n(t){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function i(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var n=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null==n)return;var i,r,o=[],a=!0,s=!1;try{for(n=n.call(t);!(a=(i=n.next()).done)&&(o.push(i.value),!e||o.length!==e);a=!0);}catch(t){s=!0,r=t}finally{try{a||null==n.return||n.return()}finally{if(s)throw r}}return o}(t,e)||r(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function r(t,e){if(t){if("string"==typeof t)return o(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?o(t,e):void 0}}function o(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,i=new Array(e);n\n\t\t\t').concat(i,"\n\t\t\n\t")},className:"button",nextClassName:"is-next",nextLabel:"Next",nextTitle:"Go to next",previousClassName:"is-previous",previousLabel:"Previous",previousTitle:"Go to previous"},m="proxy",b="config",k=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};a(this,t),f(this,b,Object.assign(Object.assign({},g),e)),this._onPrevious=this._onPrevious.bind(this),this._onNext=this._onNext.bind(this)}return l(t,[{key:"name",get:function(){return"buildin:buttons"}},{key:"init",value:function(t){f(this,m,t),this._render()}},{key:"destroy",value:function(){this._remove(),d(this)}},{key:"update",value:function(){this._render()}},{key:"_render",value:function(){var t=c(this,m),e=c(this,b),n=t.el,r=t.mask,o=t.pages,a=t.pageIndex,s=null!=r?r:n,l=e.template,u=e.className,f=e.previousClassName,h=e.previousLabel,d=e.previousTitle,p=e.nextClassName,y=e.nextLabel,g=e.nextTitle,k=[{controls:n.id,label:y,title:g,className:[u,p].join(" "),handler:this._onNext},{controls:n.id,label:h,title:d,className:[u,f].join(" "),handler:this._onPrevious}],x=i(c(this,"buttons",(function(){return k.map((function(t){var e,n=t.handler,i=function(t,e){var n={};for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&e.indexOf(i)<0&&(n[i]=t[i]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(t);r0&&void 0!==arguments[0]?arguments[0]:{};a(this,t),f(this,C,Object.assign(Object.assign({},E),e))}return l(t,[{key:"name",get:function(){return"buildin:mask"}},{key:"el",get:function(){var t;return null!==(t=c(this,O))&&void 0!==t?t:null}},{key:"init",value:function(t){f(this,w,t),x=x||new _,this._render()}},{key:"destroy",value:function(){this._remove(),d(this)}},{key:"update",value:function(t){switch(t.reason){case p.RESIZE:case p.FORCED:h(this,S),this._render();break;default:this._render()}}},{key:"_render",value:function(){if(c(this,C).enabled){var t=c(this,w).el,e=x.dimensions.height;t.scrollWidth<=t.clientWidth&&(e=0),c(this,O,(function(){var e,n=document.createElement("div");return n.className="caroucssel-mask",n.style.overflow="hidden",n.style.height="100%",null===(e=t.parentNode)||void 0===e||e.insertBefore(n,t),n.appendChild(t),n})),e!==c(this,S)&&(f(this,S,e),t.style.height="calc(100% + ".concat(e,"px)"),t.style.marginBottom="".concat(-1*e,"px"))}}},{key:"_remove",value:function(){var t,e,n=c(this,w).el,i=c(this,O);null===(t=null==i?void 0:i.parentNode)||void 0===t||t.insertBefore(n,i),null===(e=null==i?void 0:i.parentNode)||void 0===e||e.removeChild(i),n.removeAttribute("style")}}]),t}();t.Mask=N;var L=function(){function t(){a(this,t)}return l(t,[{key:"name",get:function(){return"buildin:mouse"}},{key:"init",value:function(t){f(this,"proxy",t)}},{key:"destroy",value:function(){console.log("Destroy mouse")}},{key:"update",value:function(t){console.log("Update mouse:",t.reason)}}]),t}();t.Mouse=L;var j={template:function(t){var e=t.className,n=t.controls,i=t.pages,r=t.label,o=t.title;return'\n\t\t
    \n\t\t\t').concat(i.map((function(t,e){var a={index:e,page:t,pages:i},s=r(a),l=o(a);return'
  • \n\t\t\t\t\t\n\t\t\t\t
  • ")})).join(""),"\n\t\t
\n\t")},className:"pagination",label:function(t){var e=t.index;return"".concat(e+1)},title:function(t){var e=t.index;return"Go to ".concat(e+1,". page")}},R="proxy",I="config",A="pagination",T="buttons",B=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};a(this,t),f(this,I,Object.assign(Object.assign({},j),e)),this._onClick=this._onClick.bind(this)}return l(t,[{key:"name",get:function(){return"buildin:pagination"}},{key:"init",value:function(t){f(this,R,t),this._add()}},{key:"destroy",value:function(){this._remove(),d(this)}},{key:"update",value:function(t){switch(t.reason){case p.SCROLL:this._update();break;default:this._remove(),this._add()}}},{key:"_add",value:function(){var t,e=this,n=c(this,R),i=c(this,I),r=n.el,o=n.mask,a=n.pages,s=null!=o?o:r;if(!(a.length<2)){var l=i.template,u=i.className,h=v(l,{label:i.label,title:i.title,pages:a,className:u,controls:r.id});if(h){var d=Array.from(h.querySelectorAll("button")).map((function(t){return t.addEventListener("click",e._onClick,!0),t}));null===(t=s.parentNode)||void 0===t||t.appendChild(h),f(this,A,h),f(this,T,d),this._update()}}}},{key:"_update",value:function(){var t=c(this,R),e=c(this,T),n=t.pageIndex;null==e||e.forEach((function(t,e){return t.disabled=e===n}))}},{key:"_remove",value:function(){var t,e=this,n=c(this,A),i=c(this,T);null==i||i.forEach((function(t){var n;t.removeEventListener("click",e._onClick),null===(n=t.parentNode)||void 0===n||n.removeChild(t)})),null===(t=null==n?void 0:n.parentNode)||void 0===t||t.removeChild(n),h(this,T),h(this,A)}},{key:"_onClick",value:function(t){var e,n=c(this,R),i=c(this,T),r=t.currentTarget,o=null!==(e=null==i?void 0:i.indexOf(r))&&void 0!==e?e:0;n.index=n.pages[o]}}]),t}();function M(t,e){var n=null;return function(){for(var i=arguments.length,r=new Array(i),o=0;o1&&void 0!==arguments[1]?arguments[1]:{};if(a(this,t),this.behavior=y.AUTO,!(r&&r instanceof Element))throw new Error('Carousel needs a dom element but "'.concat(n(r),'" was passed.'));f(this,U,r),et++,r.id=r.id||P(et),f(this,W,r.id);var s=Object.assign(Object.assign({},tt),o);f(this,H,s);var l=e(s.plugins),u=s.plugins.findIndex((function(t){return t instanceof N})),c=new N;if(u>-1){var h=l.splice(u,1),d=i(h,1);c=d[0]}l.unshift(c),f(this,$,c);var v=new nt(this,l);switch(f(this,q,v),f(this,J,l),l.forEach((function(t){return t.init(v)})),!0){case Array.isArray(o.index):this.index=o.index;break;case!isNaN(o.index):this.index=[o.index]}this.behavior=y.SMOOTH,this._onScroll=M(this._onScroll.bind(this),25),this._onResize=M(this._onResize.bind(this),25),r.addEventListener(X,this._onScroll),window.addEventListener(Y,this._onResize)}return l(t,[{key:"el",get:function(){return c(this,U)}},{key:"mask",get:function(){var t;return null!==(t=c(this,$).el)&&void 0!==t?t:null}},{key:"id",get:function(){return c(this,W)}},{key:"index",get:function(){var t=this;return c(this,D,(function(){for(var e=t.el,n=t.items,i=n.length,r=e.clientWidth,o=e.getBoundingClientRect().left,a=[],s=0;s=0&&c+.75*u<=r&&a.push(s)}return 0===a.length?[0]:a}))},set:function(t){var e=this.behavior,n=this.el,i=this.items,r=i.length;if(Array.isArray(t)&&t.length&&0!==r){var o=t[0]||0;o=Math.max(Math.min(o,r-1),0);var a=n.scrollLeft,s={left:i[o].offsetLeft};o===this.pages[0][0]&&(s.left=0),a!==s.left&&(h(this,D),n.scrollTo(Object.assign(Object.assign({},s),{behavior:e})))}}},{key:"items",get:function(){var t=this;return c(this,G,(function(){var e=c(t,H).filterItem,n=t.el;return Array.from(n.children).filter((function(t){return!V.test(t.tagName)&&!t.hidden})).filter(e)}))}},{key:"pages",get:function(){var t=this;return c(this,F,(function(){var e=t.el,n=t.items,i=e.clientWidth;if(0===i)return n.map((function(t,e){return[e]}));var r=[[]];return n.map((function(t,e){return{left:t.offsetLeft,width:t.clientWidth,item:t,index:e}})).sort((function(t,e){return t.left-e.left})).forEach((function(t){var e=t.left,n=t.width,o=r[r.length-1],a=o[0],s=(null==a?void 0:a.left)||0;o===r[0]&&(s=0);for(var l=Math.floor((e-s+.75*n)/i);l>0;)r.push([]),l--;r[r.length-1].push(t)})),(r=r.filter((function(t){return 0!==t.length}))).map((function(t){return t.map((function(t){return t.index}))}))}))}},{key:"pageIndex",get:function(){var t=this;return c(this,Z,(function(){var e=t.el,n=t.items,i=t.index,r=t.pages,o=e.getBoundingClientRect().left,a=e.clientWidth,s=i.reduce((function(t,e){if(!n[e])return t;var i=n[e].getBoundingClientRect(),r=i.left,s=i.right;return r=Math.round(r-o),s=Math.round(s-o),r<0||at.length)&&(e=t.length);for(var n=0,i=new Array(e);n\n\t\t\t').concat(i,"\n\t\t\n\t")},className:"button",nextClassName:"is-next",nextLabel:"Next",nextTitle:"Go to next",previousClassName:"is-previous",previousLabel:"Previous",previousTitle:"Go to previous"},g="proxy",b="config",k=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};a(this,t),f(this,b,Object.assign(Object.assign({},m),e)),this._onPrevious=this._onPrevious.bind(this),this._onNext=this._onNext.bind(this)}return l(t,[{key:"name",get:function(){return"buildin:buttons"}},{key:"init",value:function(t){f(this,g,t),this._render()}},{key:"destroy",value:function(){this._remove(),d(this)}},{key:"update",value:function(){this._render()}},{key:"_render",value:function(){var t=c(this,g),e=c(this,b),n=t.el,r=t.mask,o=t.pages,a=t.pageIndex,s=null!=r?r:n,l=e.template,u=e.className,f=e.previousClassName,h=e.previousLabel,d=e.previousTitle,p=e.nextClassName,y=e.nextLabel,m=e.nextTitle,k=[{controls:n.id,label:y,title:m,className:[u,p].join(" "),handler:this._onNext},{controls:n.id,label:h,title:d,className:[u,f].join(" "),handler:this._onPrevious}],x=i(c(this,"buttons",(function(){return k.map((function(t){var e,n=t.handler,i=function(t,e){var n={};for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&e.indexOf(i)<0&&(n[i]=t[i]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(t);r0&&void 0!==arguments[0]?arguments[0]:{};a(this,t),f(this,C,Object.assign(Object.assign({},E),e))}return l(t,[{key:"name",get:function(){return"buildin:mask"}},{key:"el",get:function(){var t;return null!==(t=c(this,O))&&void 0!==t?t:null}},{key:"init",value:function(t){f(this,w,t),x=x||new _,this._render()}},{key:"destroy",value:function(){this._remove(),d(this)}},{key:"update",value:function(t){switch(t.reason){case p.RESIZE:case p.FORCED:h(this,N),this._render();break;default:this._render()}}},{key:"_render",value:function(){var t=c(this,C),e=t.enabled,n=t.className,i=t.tagName;if(e){var r=c(this,w).el,o=x.dimensions.height;r.scrollWidth<=r.clientWidth&&(o=0),c(this,O,(function(){var t,e=document.createElement(i);return e.className=n,e.style.overflow="hidden",e.style.height="100%",null===(t=r.parentNode)||void 0===t||t.insertBefore(e,r),e.appendChild(r),e})),o!==c(this,N)&&(f(this,N,o),r.style.height="calc(100% + ".concat(o,"px)"),r.style.marginBottom="".concat(-1*o,"px"))}}},{key:"_remove",value:function(){var t,e,n=c(this,w).el,i=c(this,O);null===(t=null==i?void 0:i.parentNode)||void 0===t||t.insertBefore(n,i),null===(e=null==i?void 0:i.parentNode)||void 0===e||e.removeChild(i),n.removeAttribute("style")}}]),t}();t.Mask=S;var L=function(){function t(){a(this,t)}return l(t,[{key:"name",get:function(){return"buildin:mouse"}},{key:"init",value:function(t){f(this,"proxy",t)}},{key:"destroy",value:function(){console.log("Destroy mouse")}},{key:"update",value:function(t){console.log("Update mouse:",t.reason)}}]),t}();t.Mouse=L;var j={template:function(t){var e=t.className,n=t.controls,i=t.pages,r=t.label,o=t.title;return'\n\t\t
    \n\t\t\t').concat(i.map((function(t,e){var a={index:e,page:t,pages:i},s=r(a),l=o(a);return'
  • \n\t\t\t\t\t\n\t\t\t\t
  • ")})).join(""),"\n\t\t
\n\t")},className:"pagination",label:function(t){var e=t.index;return"".concat(e+1)},title:function(t){var e=t.index;return"Go to ".concat(e+1,". page")}},A="proxy",R="config",I="pagination",T="buttons",M=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};a(this,t),f(this,R,Object.assign(Object.assign({},j),e)),this._onClick=this._onClick.bind(this)}return l(t,[{key:"name",get:function(){return"buildin:pagination"}},{key:"init",value:function(t){f(this,A,t),this._add()}},{key:"destroy",value:function(){this._remove(),d(this)}},{key:"update",value:function(t){switch(t.reason){case p.SCROLL:this._update();break;default:this._remove(),this._add()}}},{key:"_add",value:function(){var t,e=this,n=c(this,A),i=c(this,R),r=n.el,o=n.mask,a=n.pages,s=null!=o?o:r;if(!(a.length<2)){var l=i.template,u=i.className,h=v(l,{label:i.label,title:i.title,pages:a,className:u,controls:r.id});if(h){var d=Array.from(h.querySelectorAll("button")).map((function(t){return t.addEventListener("click",e._onClick,!0),t}));null===(t=s.parentNode)||void 0===t||t.appendChild(h),f(this,I,h),f(this,T,d),this._update()}}}},{key:"_update",value:function(){var t=c(this,A),e=c(this,T),n=t.pageIndex;e.forEach((function(t,e){return t.disabled=e===n}))}},{key:"_remove",value:function(){var t,e=this,n=c(this,I),i=c(this,T);null==i||i.forEach((function(t){var n;t.removeEventListener("click",e._onClick),null===(n=t.parentNode)||void 0===n||n.removeChild(t)})),null===(t=null==n?void 0:n.parentNode)||void 0===t||t.removeChild(n),h(this,T),h(this,I)}},{key:"_onClick",value:function(t){var e=c(this,A),n=c(this,T),i=t.currentTarget,r=n.indexOf(i);e.index=e.pages[r]}}]),t}();t.Pagination=M;var P="instance",B="features";function z(t){return c(t,P)}var W=function(){function t(e,n){a(this,t),f(this,P,e),f(this,B,n)}return l(t,[{key:"id",get:function(){return z(this).id}},{key:"el",get:function(){return z(this).el}},{key:"mask",get:function(){return z(this).mask}},{key:"index",get:function(){return z(this).index},set:function(t){z(this).index=t}},{key:"items",get:function(){return z(this).items}},{key:"pages",get:function(){return z(this).pages}},{key:"pageIndex",get:function(){return z(this).pageIndex}},{key:"update",value:function(t){var e;z(this).update(),(e=this,c(e,B)).forEach((function(e){e!==t&&e.update({reason:p.FEATURE})}))}}]),t}();function H(t,e){var n=null;return function(){for(var i=arguments.length,r=new Array(i),o=0;o1&&void 0!==arguments[1]?arguments[1]:{};if(a(this,t),this.behavior=y.AUTO,!(r&&r instanceof Element))throw new Error('Carousel needs a dom element but "'.concat(n(r),'" was passed.'));f(this,Z,r),rt++,r.id=r.id||U(rt),f(this,$,r.id);var s=Object.assign(Object.assign({},it),o);f(this,q,s);var l=null,u=e(s.features),c=s.features.findIndex((function(t){return t instanceof S}));if(c>-1){var h=u.splice(c,1),d=i(h,1);l=d[0]}null!=l||(l=new S),u=u.filter((function(t){return!(t instanceof S)})),u=[l].concat(e(u)),f(this,X,l);var v=new W(this,u);switch(f(this,Y,v),f(this,tt,u),u.forEach((function(t){return t.init(v)})),!0){case Array.isArray(o.index):this.index=o.index;break;case!isNaN(o.index):this.index=[o.index]}this.behavior=y.SMOOTH,this._onScroll=H(this._onScroll.bind(this),25),this._onResize=H(this._onResize.bind(this),25),r.addEventListener(D,this._onScroll),window.addEventListener(G,this._onResize)}return l(t,[{key:"el",get:function(){return c(this,Z)}},{key:"mask",get:function(){var t;return null!==(t=c(this,X).el)&&void 0!==t?t:null}},{key:"id",get:function(){return c(this,$)}},{key:"index",get:function(){var t=this;return c(this,V,(function(){for(var e=t.el,n=t.items,i=n.length,r=e.clientWidth,o=e.getBoundingClientRect().left,a=[],s=0;s=0&&c+.75*u<=r&&a.push(s)}return 0===a.length?[0]:a}))},set:function(t){var e=this.behavior,n=this.el,i=this.items,r=i.length;if(Array.isArray(t)&&t.length){var o=t[0]||0;o=Math.max(Math.min(o,r-1),0);var a=n.scrollLeft,s={left:i[o].offsetLeft};o===this.pages[0][0]&&(s.left=0),a!==s.left&&(h(this,V),n.scrollTo(Object.assign(Object.assign({},s),{behavior:e})))}}},{key:"items",get:function(){var t=this;return c(this,J,(function(){var e=c(t,q).filterItem,n=t.el;return Array.from(n.children).filter((function(t){return!nt.test(t.tagName)&&!t.hidden})).filter(e)}))}},{key:"pages",get:function(){var t=this;return c(this,K,(function(){var e=t.el,n=t.items,i=e.clientWidth;if(0===i)return n.map((function(t,e){return[e]}));var r=[[]];return n.map((function(t,e){return{left:t.offsetLeft,width:t.clientWidth,item:t,index:e}})).sort((function(t,e){return t.left-e.left})).forEach((function(t){var e=t.left,n=t.width,o=r[r.length-1],a=o[0],s=(null==a?void 0:a.left)||0;o===r[0]&&(s=0);for(var l=Math.floor((e-s+.75*n)/i);l>0;)r.push([]),l--;r[r.length-1].push(t)})),(r=r.filter((function(t){return 0!==t.length}))).map((function(t){return t.map((function(t){return t.index}))}))}))}},{key:"pageIndex",get:function(){var t=this;return c(this,Q,(function(){var e=t.el,n=t.items,i=t.index,r=t.pages,o=e.getBoundingClientRect().left,a=e.clientWidth,s=i.reduce((function(t,e){if(!n[e])return t;var i=n[e].getBoundingClientRect(),r=i.left,s=i.right;return r=Math.round(r-o),s=Math.round(s-o),r<0||a); - get name(): string; - get el(): Element | null; - init(proxy: PluginProxy): void; - destroy(): void; - update(data: UpdateData): void; - private _render; - private _remove; -} diff --git a/dist/plugins/mouse/index.d.ts b/dist/plugins/mouse/index.d.ts deleted file mode 100644 index d9116104..00000000 --- a/dist/plugins/mouse/index.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { Plugin, PluginProxy, UpdateData } from '../../types'; -/** - * Plugin to enable mouse controls - * @hidden - */ -export declare class Mouse implements Plugin { - get name(): string; - init(proxy: PluginProxy): void; - destroy(): void; - update(data: UpdateData): void; -} diff --git a/dist/proxy.d.ts b/dist/proxy.d.ts new file mode 100644 index 00000000..34d92001 --- /dev/null +++ b/dist/proxy.d.ts @@ -0,0 +1,17 @@ +import { ICarousel, IFeature, Index, IProxy, Pages } from "./types"; +/** + * A proxy instance between carousel and each feature. + * @internal + */ +export declare class Proxy implements IProxy { + constructor(instance: ICarousel, features: IFeature[]); + get id(): string; + get el(): Element; + get mask(): Element | null; + get index(): Index; + set index(value: Index); + get items(): HTMLElement[]; + get pages(): Pages; + get pageIndex(): number; + update(sender: IFeature): void; +} diff --git a/dist/proxy.js b/dist/proxy.js new file mode 100644 index 00000000..312d238a --- /dev/null +++ b/dist/proxy.js @@ -0,0 +1,55 @@ +import { UpdateReason } from "./types"; +import { fromCache, writeCache } from './utils/cache'; +const CACHE_KEY_INSTANCE = 'instance'; +const CACHE_KEY_FEATURES = 'features'; +function __getInstance(ref) { + return fromCache(ref, CACHE_KEY_INSTANCE); +} +function __getFeatures(ref) { + return fromCache(ref, CACHE_KEY_FEATURES); +} +/** + * A proxy instance between carousel and each feature. + * @internal + */ +export class Proxy { + constructor(instance, features) { + writeCache(this, CACHE_KEY_INSTANCE, instance); + writeCache(this, CACHE_KEY_FEATURES, features); + } + get id() { + return __getInstance(this).id; + } + get el() { + return __getInstance(this).el; + } + get mask() { + return __getInstance(this).mask; + } + get index() { + return __getInstance(this).index; + } + set index(value) { + __getInstance(this).index = value; + } + get items() { + return __getInstance(this).items; + } + get pages() { + return __getInstance(this).pages; + } + get pageIndex() { + return __getInstance(this).pageIndex; + } + update(sender) { + __getInstance(this).update(); + // Trigger update in all other features except the source feature that + // triggered the event: + __getFeatures(this).forEach((feature) => { + if (feature === sender) { + return; + } + feature.update({ reason: UpdateReason.FEATURE }); + }); + } +} diff --git a/dist/types/index.d.ts b/dist/types.d.ts similarity index 71% rename from dist/types/index.d.ts rename to dist/types.d.ts index b862c66e..06bab063 100644 --- a/dist/types/index.d.ts +++ b/dist/types.d.ts @@ -1,15 +1,7 @@ export declare type Index = [number, ...number[]]; export declare type Pages = [Index, ...Index[]]; -export declare enum UpdateReason { - SCROLL = "scroll", - RESIZE = "resize", - FORCED = "forced", - PLUGIN = "plugin" -} -export declare type UpdateData = { - reason: UpdateReason; -}; -export interface PluginProxy { +interface ICore { + get id(): string; get el(): Element; get mask(): Element | null; get index(): Index; @@ -17,29 +9,47 @@ export interface PluginProxy { get items(): HTMLElement[]; get pages(): Pages; get pageIndex(): number; - update(plugin: Plugin): void; } -export interface Plugin { +export interface ICarousel extends ICore { + behavior: ScrollBehavior; + destroy(): void; + update(): void; +} +export interface IProxy extends ICore { + update(sender: IFeature): void; +} +export interface IFeature { get name(): string; - init(proxy: PluginProxy): void; + init(proxy: IProxy): void; destroy(): void; update(data: UpdateData): void; } +export declare enum UpdateReason { + SCROLL = "scroll", + RESIZE = "resize", + FORCED = "forced", + FEATURE = "feature" +} +export declare type UpdateData = { + reason: UpdateReason; +}; export declare enum ScrollBehavior { AUTO = "auto", SMOOTH = "smooth" } export declare type ScrollHook = (event: { - index: number[]; + index: Index; type: 'scroll'; target: T; originalEvent: Event; }) => void; export declare type FilterItemFn = ((item: HTMLElement) => boolean) | ((item: HTMLElement, index: number) => boolean) | ((item: HTMLElement, index: number, array: HTMLElement[]) => boolean); export declare type Configuration = { - index?: Index | number; - plugins: Plugin[]; + features: IFeature[]; filterItem: FilterItemFn; onScroll: ScrollHook; }; -export declare type Options = Partial; +export declare type Options = Partial & { + index?: Index | number; +}; +export {}; diff --git a/dist/types/index.js b/dist/types.js similarity index 90% rename from dist/types/index.js rename to dist/types.js index de020a9a..dc7ee781 100644 --- a/dist/types/index.js +++ b/dist/types.js @@ -3,7 +3,7 @@ export var UpdateReason; UpdateReason["SCROLL"] = "scroll"; UpdateReason["RESIZE"] = "resize"; UpdateReason["FORCED"] = "forced"; - UpdateReason["PLUGIN"] = "plugin"; + UpdateReason["FEATURE"] = "feature"; })(UpdateReason || (UpdateReason = {})); export var ScrollBehavior; (function (ScrollBehavior) { diff --git a/dist/utils/cache.js b/dist/utils/cache.js index 17969d65..1b229eb1 100644 --- a/dist/utils/cache.js +++ b/dist/utils/cache.js @@ -46,4 +46,6 @@ export function clearFullCache(ref) { /** * This exposes the cache instance for test environments. Otherwise it will be null. */ +/* This should not be part of the coverage report: test util */ +/* istanbul ignore next */ export const cacheInstance = (process.env.NODE_ENV === 'test') ? __CACHE : null; diff --git a/package-lock.json b/package-lock.json index 03698576..4c070994 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "caroucssel", - "version": "0.12.0-1", + "version": "0.12.0-2", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 1ae39d50..6108f9b7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "caroucssel", - "version": "0.12.0-1", + "version": "0.12.0-2", "description": "A lightweight dependency-free css carousel.", "module": "dist/index.js", "main": "dist/formats/cjs/caroucssel.js",