second commit

This commit is contained in:
2024-12-27 22:31:23 +09:00
parent 2353324570
commit 10a0f110ca
8819 changed files with 1307198 additions and 28 deletions

View File

@ -0,0 +1,64 @@
import type { CarouselOptions, CarouselItem, IndicatorItem, RotationItems } from './types';
import type { InstanceOptions } from '../../dom/types';
import { CarouselInterface } from './interface';
declare class Carousel implements CarouselInterface {
_instanceId: string;
_carouselEl: HTMLElement;
_items: CarouselItem[];
_indicators: IndicatorItem[];
_activeItem: CarouselItem;
_intervalDuration: number;
_intervalInstance: number;
_options: CarouselOptions;
_initialized: boolean;
constructor(carouselEl?: HTMLElement | null, items?: CarouselItem[], options?: CarouselOptions, instanceOptions?: InstanceOptions);
/**
* initialize carousel and items based on active one
*/
init(): void;
destroy(): void;
removeInstance(): void;
destroyAndRemoveInstance(): void;
getItem(position: number): CarouselItem;
/**
* Slide to the element based on id
* @param {*} position
*/
slideTo(position: number): void;
/**
* Based on the currently active item it will go to the next position
*/
next(): void;
/**
* Based on the currently active item it will go to the previous position
*/
prev(): void;
/**
* This method applies the transform classes based on the left, middle, and right rotation carousel items
* @param {*} rotationItems
*/
_rotate(rotationItems: RotationItems): void;
/**
* Set an interval to cycle through the carousel items
*/
cycle(): void;
/**
* Clears the cycling interval
*/
pause(): void;
/**
* Get the currently active item
*/
getActiveItem(): CarouselItem;
/**
* Set the currently active item and data attribute
* @param {*} position
*/
_setActiveItem(item: CarouselItem): void;
updateOnNext(callback: () => void): void;
updateOnPrev(callback: () => void): void;
updateOnChange(callback: () => void): void;
}
export declare function initCarousels(): void;
export default Carousel;
//# sourceMappingURL=index.d.ts.map

View File

@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/carousel/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACR,eAAe,EACf,YAAY,EACZ,aAAa,EACb,aAAa,EAChB,MAAM,SAAS,CAAC;AACjB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAsBhD,cAAM,QAAS,YAAW,iBAAiB;IACvC,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,WAAW,CAAC;IACzB,MAAM,EAAE,YAAY,EAAE,CAAC;IACvB,WAAW,EAAE,aAAa,EAAE,CAAC;IAC7B,WAAW,EAAE,YAAY,CAAC;IAC1B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,QAAQ,EAAE,eAAe,CAAC;IAC1B,YAAY,EAAE,OAAO,CAAC;gBAGlB,UAAU,GAAE,WAAW,GAAG,IAAW,EACrC,KAAK,GAAE,YAAY,EAAO,EAC1B,OAAO,GAAE,eAAyB,EAClC,eAAe,GAAE,eAAwC;IA0B7D;;OAEG;IACH,IAAI;IA4BJ,OAAO;IAMP,cAAc;IAId,wBAAwB;IAKxB,OAAO,CAAC,QAAQ,EAAE,MAAM;IAIxB;;;OAGG;IACH,OAAO,CAAC,QAAQ,EAAE,MAAM;IAuBxB;;OAEG;IACH,IAAI;IAiBJ;;OAEG;IACH,IAAI;IAiBJ;;;OAGG;IACH,OAAO,CAAC,aAAa,EAAE,aAAa;IAmDpC;;OAEG;IACH,KAAK;IAQL;;OAEG;IACH,KAAK;IAIL;;OAEG;IACH,aAAa;IAIb;;;OAGG;IACH,cAAc,CAAC,IAAI,EAAE,YAAY;IAyBjC,YAAY,CAAC,QAAQ,EAAE,MAAM,IAAI;IAIjC,YAAY,CAAC,QAAQ,EAAE,MAAM,IAAI;IAIjC,cAAc,CAAC,QAAQ,EAAE,MAAM,IAAI;CAGtC;AAED,wBAAgB,aAAa,SA0E5B;AAOD,eAAe,QAAQ,CAAC"}

View File

@ -0,0 +1,285 @@
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
import instances from '../../dom/instances';
var Default = {
defaultPosition: 0,
indicators: {
items: [],
activeClasses: 'bg-white dark:bg-gray-800',
inactiveClasses: 'bg-white/50 dark:bg-gray-800/50 hover:bg-white dark:hover:bg-gray-800',
},
interval: 3000,
onNext: function () { },
onPrev: function () { },
onChange: function () { },
};
var DefaultInstanceOptions = {
id: null,
override: true,
};
var Carousel = /** @class */ (function () {
function Carousel(carouselEl, items, options, instanceOptions) {
if (carouselEl === void 0) { carouselEl = null; }
if (items === void 0) { items = []; }
if (options === void 0) { options = Default; }
if (instanceOptions === void 0) { instanceOptions = DefaultInstanceOptions; }
this._instanceId = instanceOptions.id
? instanceOptions.id
: carouselEl.id;
this._carouselEl = carouselEl;
this._items = items;
this._options = __assign(__assign(__assign({}, Default), options), { indicators: __assign(__assign({}, Default.indicators), options.indicators) });
this._activeItem = this.getItem(this._options.defaultPosition);
this._indicators = this._options.indicators.items;
this._intervalDuration = this._options.interval;
this._intervalInstance = null;
this._initialized = false;
this.init();
instances.addInstance('Carousel', this, this._instanceId, instanceOptions.override);
}
/**
* initialize carousel and items based on active one
*/
Carousel.prototype.init = function () {
var _this = this;
if (this._items.length && !this._initialized) {
this._items.map(function (item) {
item.el.classList.add('absolute', 'inset-0', 'transition-transform', 'transform');
});
// if no active item is set then first position is default
if (this.getActiveItem()) {
this.slideTo(this.getActiveItem().position);
}
else {
this.slideTo(0);
}
this._indicators.map(function (indicator, position) {
indicator.el.addEventListener('click', function () {
_this.slideTo(position);
});
});
this._initialized = true;
}
};
Carousel.prototype.destroy = function () {
if (this._initialized) {
this._initialized = false;
}
};
Carousel.prototype.removeInstance = function () {
instances.removeInstance('Carousel', this._instanceId);
};
Carousel.prototype.destroyAndRemoveInstance = function () {
this.destroy();
this.removeInstance();
};
Carousel.prototype.getItem = function (position) {
return this._items[position];
};
/**
* Slide to the element based on id
* @param {*} position
*/
Carousel.prototype.slideTo = function (position) {
var nextItem = this._items[position];
var rotationItems = {
left: nextItem.position === 0
? this._items[this._items.length - 1]
: this._items[nextItem.position - 1],
middle: nextItem,
right: nextItem.position === this._items.length - 1
? this._items[0]
: this._items[nextItem.position + 1],
};
this._rotate(rotationItems);
this._setActiveItem(nextItem);
if (this._intervalInstance) {
this.pause();
this.cycle();
}
this._options.onChange(this);
};
/**
* Based on the currently active item it will go to the next position
*/
Carousel.prototype.next = function () {
var activeItem = this.getActiveItem();
var nextItem = null;
// check if last item
if (activeItem.position === this._items.length - 1) {
nextItem = this._items[0];
}
else {
nextItem = this._items[activeItem.position + 1];
}
this.slideTo(nextItem.position);
// callback function
this._options.onNext(this);
};
/**
* Based on the currently active item it will go to the previous position
*/
Carousel.prototype.prev = function () {
var activeItem = this.getActiveItem();
var prevItem = null;
// check if first item
if (activeItem.position === 0) {
prevItem = this._items[this._items.length - 1];
}
else {
prevItem = this._items[activeItem.position - 1];
}
this.slideTo(prevItem.position);
// callback function
this._options.onPrev(this);
};
/**
* This method applies the transform classes based on the left, middle, and right rotation carousel items
* @param {*} rotationItems
*/
Carousel.prototype._rotate = function (rotationItems) {
// reset
this._items.map(function (item) {
item.el.classList.add('hidden');
});
// Handling the case when there is only one item
if (this._items.length === 1) {
rotationItems.middle.el.classList.remove('-translate-x-full', 'translate-x-full', 'translate-x-0', 'hidden', 'z-10');
rotationItems.middle.el.classList.add('translate-x-0', 'z-20');
return;
}
// left item (previously active)
rotationItems.left.el.classList.remove('-translate-x-full', 'translate-x-full', 'translate-x-0', 'hidden', 'z-20');
rotationItems.left.el.classList.add('-translate-x-full', 'z-10');
// currently active item
rotationItems.middle.el.classList.remove('-translate-x-full', 'translate-x-full', 'translate-x-0', 'hidden', 'z-10');
rotationItems.middle.el.classList.add('translate-x-0', 'z-30');
// right item (upcoming active)
rotationItems.right.el.classList.remove('-translate-x-full', 'translate-x-full', 'translate-x-0', 'hidden', 'z-30');
rotationItems.right.el.classList.add('translate-x-full', 'z-20');
};
/**
* Set an interval to cycle through the carousel items
*/
Carousel.prototype.cycle = function () {
var _this = this;
if (typeof window !== 'undefined') {
this._intervalInstance = window.setInterval(function () {
_this.next();
}, this._intervalDuration);
}
};
/**
* Clears the cycling interval
*/
Carousel.prototype.pause = function () {
clearInterval(this._intervalInstance);
};
/**
* Get the currently active item
*/
Carousel.prototype.getActiveItem = function () {
return this._activeItem;
};
/**
* Set the currently active item and data attribute
* @param {*} position
*/
Carousel.prototype._setActiveItem = function (item) {
var _a, _b;
var _this = this;
this._activeItem = item;
var position = item.position;
// update the indicators if available
if (this._indicators.length) {
this._indicators.map(function (indicator) {
var _a, _b;
indicator.el.setAttribute('aria-current', 'false');
(_a = indicator.el.classList).remove.apply(_a, _this._options.indicators.activeClasses.split(' '));
(_b = indicator.el.classList).add.apply(_b, _this._options.indicators.inactiveClasses.split(' '));
});
(_a = this._indicators[position].el.classList).add.apply(_a, this._options.indicators.activeClasses.split(' '));
(_b = this._indicators[position].el.classList).remove.apply(_b, this._options.indicators.inactiveClasses.split(' '));
this._indicators[position].el.setAttribute('aria-current', 'true');
}
};
Carousel.prototype.updateOnNext = function (callback) {
this._options.onNext = callback;
};
Carousel.prototype.updateOnPrev = function (callback) {
this._options.onPrev = callback;
};
Carousel.prototype.updateOnChange = function (callback) {
this._options.onChange = callback;
};
return Carousel;
}());
export function initCarousels() {
document.querySelectorAll('[data-carousel]').forEach(function ($carouselEl) {
var interval = $carouselEl.getAttribute('data-carousel-interval');
var slide = $carouselEl.getAttribute('data-carousel') === 'slide'
? true
: false;
var items = [];
var defaultPosition = 0;
if ($carouselEl.querySelectorAll('[data-carousel-item]').length) {
Array.from($carouselEl.querySelectorAll('[data-carousel-item]')).map(function ($carouselItemEl, position) {
items.push({
position: position,
el: $carouselItemEl,
});
if ($carouselItemEl.getAttribute('data-carousel-item') ===
'active') {
defaultPosition = position;
}
});
}
var indicators = [];
if ($carouselEl.querySelectorAll('[data-carousel-slide-to]').length) {
Array.from($carouselEl.querySelectorAll('[data-carousel-slide-to]')).map(function ($indicatorEl) {
indicators.push({
position: parseInt($indicatorEl.getAttribute('data-carousel-slide-to')),
el: $indicatorEl,
});
});
}
var carousel = new Carousel($carouselEl, items, {
defaultPosition: defaultPosition,
indicators: {
items: indicators,
},
interval: interval ? interval : Default.interval,
});
if (slide) {
carousel.cycle();
}
// check for controls
var carouselNextEl = $carouselEl.querySelector('[data-carousel-next]');
var carouselPrevEl = $carouselEl.querySelector('[data-carousel-prev]');
if (carouselNextEl) {
carouselNextEl.addEventListener('click', function () {
carousel.next();
});
}
if (carouselPrevEl) {
carouselPrevEl.addEventListener('click', function () {
carousel.prev();
});
}
});
}
if (typeof window !== 'undefined') {
window.Carousel = Carousel;
window.initCarousels = initCarousels;
}
export default Carousel;
//# sourceMappingURL=index.js.map

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,23 @@
import { CarouselOptions, CarouselItem, IndicatorItem, RotationItems } from './types';
export declare interface CarouselInterface {
_items: CarouselItem[];
_indicators: IndicatorItem[];
_activeItem: CarouselItem;
_intervalDuration: number;
_intervalInstance: number;
_options: CarouselOptions;
init(): void;
getItem(position: number): CarouselItem;
getActiveItem(): CarouselItem;
_setActiveItem(item: CarouselItem): void;
slideTo(position: number): void;
next(): void;
prev(): void;
_rotate(rotationItems: RotationItems): void;
cycle(): void;
pause(): void;
destroy(): void;
removeInstance(): void;
destroyAndRemoveInstance(): void;
}
//# sourceMappingURL=interface.d.ts.map

View File

@ -0,0 +1 @@
{"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../../../../src/components/carousel/interface.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,eAAe,EACf,YAAY,EACZ,aAAa,EACb,aAAa,EAChB,MAAM,SAAS,CAAC;AAEjB,MAAM,CAAC,OAAO,WAAW,iBAAiB;IACtC,MAAM,EAAE,YAAY,EAAE,CAAC;IACvB,WAAW,EAAE,aAAa,EAAE,CAAC;IAC7B,WAAW,EAAE,YAAY,CAAC;IAC1B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,QAAQ,EAAE,eAAe,CAAC;IAE1B,IAAI,IAAI,IAAI,CAAC;IAEb,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG,YAAY,CAAC;IACxC,aAAa,IAAI,YAAY,CAAC;IAE9B,cAAc,CAAC,IAAI,EAAE,YAAY,GAAG,IAAI,CAAC;IAEzC,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IAEhC,IAAI,IAAI,IAAI,CAAC;IACb,IAAI,IAAI,IAAI,CAAC;IAEb,OAAO,CAAC,aAAa,EAAE,aAAa,GAAG,IAAI,CAAC;IAC5C,KAAK,IAAI,IAAI,CAAC;IACd,KAAK,IAAI,IAAI,CAAC;IAEd,OAAO,IAAI,IAAI,CAAC;IAChB,cAAc,IAAI,IAAI,CAAC;IACvB,wBAAwB,IAAI,IAAI,CAAC;CACpC"}

View File

@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=interface.js.map

View File

@ -0,0 +1 @@
{"version":3,"file":"interface.js","sourceRoot":"","sources":["../../../../src/components/carousel/interface.ts"],"names":[],"mappings":""}

View File

@ -0,0 +1,27 @@
import { CarouselInterface } from './interface';
export declare type CarouselItem = {
position: number;
el: HTMLElement;
};
export declare type IndicatorItem = {
position: number;
el: HTMLElement;
};
export declare type RotationItems = {
left: CarouselItem;
middle: CarouselItem;
right: CarouselItem;
};
export declare type CarouselOptions = {
defaultPosition?: number;
indicators?: {
items?: IndicatorItem[];
activeClasses?: string;
inactiveClasses?: string;
};
interval?: number;
onNext?: (carousel: CarouselInterface) => void;
onPrev?: (carousel: CarouselInterface) => void;
onChange?: (carousel: CarouselInterface) => void;
};
//# sourceMappingURL=types.d.ts.map

View File

@ -0,0 +1 @@
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/components/carousel/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEhD,MAAM,CAAC,OAAO,MAAM,YAAY,GAAG;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,EAAE,EAAE,WAAW,CAAC;CACnB,CAAC;AAEF,MAAM,CAAC,OAAO,MAAM,aAAa,GAAG;IAChC,QAAQ,EAAE,MAAM,CAAC;IACjB,EAAE,EAAE,WAAW,CAAC;CACnB,CAAC;AAEF,MAAM,CAAC,OAAO,MAAM,aAAa,GAAG;IAChC,IAAI,EAAE,YAAY,CAAC;IACnB,MAAM,EAAE,YAAY,CAAC;IACrB,KAAK,EAAE,YAAY,CAAC;CACvB,CAAC;AAEF,MAAM,CAAC,OAAO,MAAM,eAAe,GAAG;IAClC,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,UAAU,CAAC,EAAE;QACT,KAAK,CAAC,EAAE,aAAa,EAAE,CAAC;QACxB,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,eAAe,CAAC,EAAE,MAAM,CAAC;KAC5B,CAAC;IACF,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,iBAAiB,KAAK,IAAI,CAAC;IAC/C,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,iBAAiB,KAAK,IAAI,CAAC;IAC/C,QAAQ,CAAC,EAAE,CAAC,QAAQ,EAAE,iBAAiB,KAAK,IAAI,CAAC;CACpD,CAAC"}

View File

@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=types.js.map

View File

@ -0,0 +1 @@
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/components/carousel/types.ts"],"names":[],"mappings":""}