|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| export class SlideRenderer {
|
| constructor(container, options = {}) {
|
| this.container = container;
|
| this.options = {
|
| transition: options.transition || 'fade',
|
| transitionDuration: options.transitionDuration || 600,
|
| autoAnimate: options.autoAnimate !== false,
|
| ...options
|
| };
|
|
|
| this.slides = [];
|
| this.currentIndex = 0;
|
| this.isAnimating = false;
|
| }
|
|
|
| |
| |
|
|
| loadSlides(slides) {
|
| this.slides = slides;
|
| this.currentIndex = 0;
|
| this.renderAllSlides();
|
| }
|
|
|
| |
| |
|
|
| renderAllSlides() {
|
| this.container.innerHTML = '';
|
|
|
| this.slides.forEach((slide, index) => {
|
| const slideElement = this.createSlideElement(slide, index);
|
| this.container.appendChild(slideElement);
|
| });
|
|
|
|
|
| if (this.slides.length > 0) {
|
| this.showSlide(0);
|
| }
|
| }
|
|
|
| |
| |
|
|
| createSlideElement(slide, index) {
|
| const slideDiv = document.createElement('div');
|
| slideDiv.className = 'slide';
|
| slideDiv.dataset.index = index;
|
| slideDiv.style.display = 'none';
|
|
|
|
|
| const contentDiv = document.createElement('div');
|
| contentDiv.className = 'slide-content';
|
|
|
|
|
| slide.content.forEach((item, itemIndex) => {
|
| const element = this.renderContentItem(item, itemIndex);
|
| if (element) {
|
| contentDiv.appendChild(element);
|
| }
|
| });
|
|
|
| slideDiv.appendChild(contentDiv);
|
|
|
|
|
| const slideNumber = document.createElement('div');
|
| slideNumber.className = 'slide-number';
|
| slideNumber.textContent = `${index + 1} / ${this.slides.length}`;
|
| slideDiv.appendChild(slideNumber);
|
|
|
| return slideDiv;
|
| }
|
|
|
| |
| |
|
|
| renderContentItem(item, index) {
|
| const element = document.createElement('div');
|
| element.className = `content-item content-${item.type}`;
|
|
|
| if (this.options.autoAnimate) {
|
| element.style.opacity = '0';
|
| element.style.transform = 'translateY(20px)';
|
| element.dataset.animationDelay = index * 150;
|
| }
|
|
|
| switch (item.type) {
|
| case 'h1':
|
| element.innerHTML = `<h1>${this.parseInline(item.content)}</h1>`;
|
| break;
|
|
|
| case 'h2':
|
| element.innerHTML = `<h2>${this.parseInline(item.content)}</h2>`;
|
| break;
|
|
|
| case 'h3':
|
| element.innerHTML = `<h3>${this.parseInline(item.content)}</h3>`;
|
| break;
|
|
|
| case 'h4':
|
| element.innerHTML = `<h4>${this.parseInline(item.content)}</h4>`;
|
| break;
|
|
|
| case 'text':
|
| element.innerHTML = `<p>${this.parseInline(item.content)}</p>`;
|
| break;
|
|
|
| case 'list-item':
|
| const li = document.createElement('li');
|
| li.innerHTML = this.parseInline(item.content);
|
| const ul = document.createElement('ul');
|
| ul.appendChild(li);
|
| element.appendChild(ul);
|
| break;
|
|
|
| case 'numbered-item':
|
| const nli = document.createElement('li');
|
| nli.innerHTML = this.parseInline(item.content);
|
| const ol = document.createElement('ol');
|
| ol.appendChild(nli);
|
| element.appendChild(ol);
|
| break;
|
|
|
| case 'code':
|
| const pre = document.createElement('pre');
|
| const code = document.createElement('code');
|
| code.className = `language-${item.language}`;
|
| code.textContent = item.content;
|
| pre.appendChild(code);
|
| element.appendChild(pre);
|
| break;
|
|
|
| case 'blockquote':
|
| element.innerHTML = `<blockquote>${this.parseInline(item.content)}</blockquote>`;
|
| break;
|
|
|
| case 'image':
|
| element.innerHTML = `<img src="${item.src}" alt="${item.alt || ''}" />`;
|
| break;
|
|
|
| case 'link':
|
| element.innerHTML = `<a href="${item.url}" target="_blank">${item.text}</a>`;
|
| break;
|
|
|
| default:
|
| return null;
|
| }
|
|
|
| return element;
|
| }
|
|
|
| |
| |
|
|
| parseInline(text) {
|
| if (!text) return '';
|
|
|
|
|
| text = text.replace(/\*\*([^*]+)\*\*/g, '<strong>$1</strong>');
|
| text = text.replace(/__([^_]+)__/g, '<strong>$1</strong>');
|
|
|
|
|
| text = text.replace(/\*([^*]+)\*/g, '<em>$1</em>');
|
| text = text.replace(/_([^_]+)_/g, '<em>$1</em>');
|
|
|
|
|
| text = text.replace(/`([^`]+)`/g, '<code>$1</code>');
|
|
|
| return text;
|
| }
|
|
|
| |
| |
|
|
| async showSlide(index, direction = 'next') {
|
| if (this.isAnimating || index < 0 || index >= this.slides.length) {
|
| return;
|
| }
|
|
|
| this.isAnimating = true;
|
|
|
| const currentSlide = this.container.querySelector(`[data-index="${this.currentIndex}"]`);
|
| const nextSlide = this.container.querySelector(`[data-index="${index}"]`);
|
|
|
| if (!nextSlide) {
|
| this.isAnimating = false;
|
| return;
|
| }
|
|
|
|
|
| await this.applyTransition(currentSlide, nextSlide, direction);
|
|
|
| this.currentIndex = index;
|
| this.isAnimating = false;
|
|
|
|
|
| if (this.options.autoAnimate) {
|
| this.animateSlideContent(nextSlide);
|
| }
|
| }
|
|
|
| |
| |
|
|
| async applyTransition(currentSlide, nextSlide, direction) {
|
| const duration = this.options.transitionDuration;
|
|
|
| switch (this.options.transition) {
|
| case 'fade':
|
| await this.fadeTransition(currentSlide, nextSlide, duration);
|
| break;
|
|
|
| case 'slide':
|
| await this.slideTransition(currentSlide, nextSlide, direction, duration);
|
| break;
|
|
|
| case 'zoom':
|
| await this.zoomTransition(currentSlide, nextSlide, duration);
|
| break;
|
|
|
| case 'glitch':
|
| await this.glitchTransition(currentSlide, nextSlide, duration);
|
| break;
|
|
|
| case 'matrix':
|
| await this.matrixTransition(currentSlide, nextSlide, duration);
|
| break;
|
|
|
| case 'cube':
|
| await this.cubeTransition(currentSlide, nextSlide, direction, duration);
|
| break;
|
|
|
| case 'pixelate':
|
| await this.pixelateTransition(currentSlide, nextSlide, duration);
|
| break;
|
|
|
| default:
|
|
|
| if (currentSlide) currentSlide.style.display = 'none';
|
| nextSlide.style.display = 'flex';
|
| }
|
| }
|
|
|
| |
| |
|
|
| async fadeTransition(currentSlide, nextSlide, duration) {
|
| nextSlide.style.display = 'flex';
|
| nextSlide.style.opacity = '0';
|
|
|
| await this.wait(50);
|
|
|
| if (currentSlide) {
|
| currentSlide.style.transition = `opacity ${duration}ms ease`;
|
| currentSlide.style.opacity = '0';
|
| }
|
|
|
| nextSlide.style.transition = `opacity ${duration}ms ease`;
|
| nextSlide.style.opacity = '1';
|
|
|
| await this.wait(duration);
|
|
|
| if (currentSlide) {
|
| currentSlide.style.display = 'none';
|
| currentSlide.style.opacity = '1';
|
| }
|
| }
|
|
|
| |
| |
|
|
| async slideTransition(currentSlide, nextSlide, direction, duration) {
|
| const offset = direction === 'next' ? '100%' : '-100%';
|
|
|
| nextSlide.style.display = 'flex';
|
| nextSlide.style.transform = `translateX(${offset})`;
|
|
|
| await this.wait(50);
|
|
|
| if (currentSlide) {
|
| currentSlide.style.transition = `transform ${duration}ms ease`;
|
| currentSlide.style.transform = `translateX(${direction === 'next' ? '-100%' : '100%'})`;
|
| }
|
|
|
| nextSlide.style.transition = `transform ${duration}ms ease`;
|
| nextSlide.style.transform = 'translateX(0)';
|
|
|
| await this.wait(duration);
|
|
|
| if (currentSlide) {
|
| currentSlide.style.display = 'none';
|
| currentSlide.style.transform = 'translateX(0)';
|
| }
|
| }
|
|
|
| |
| |
|
|
| async zoomTransition(currentSlide, nextSlide, duration) {
|
| nextSlide.style.display = 'flex';
|
| nextSlide.style.transform = 'scale(0.8)';
|
| nextSlide.style.opacity = '0';
|
|
|
| await this.wait(50);
|
|
|
| if (currentSlide) {
|
| currentSlide.style.transition = `all ${duration}ms ease`;
|
| currentSlide.style.transform = 'scale(1.2)';
|
| currentSlide.style.opacity = '0';
|
| }
|
|
|
| nextSlide.style.transition = `all ${duration}ms ease`;
|
| nextSlide.style.transform = 'scale(1)';
|
| nextSlide.style.opacity = '1';
|
|
|
| await this.wait(duration);
|
|
|
| if (currentSlide) {
|
| currentSlide.style.display = 'none';
|
| currentSlide.style.transform = 'scale(1)';
|
| currentSlide.style.opacity = '1';
|
| }
|
| }
|
|
|
| |
| |
|
|
| animateSlideContent(slideElement) {
|
| const items = slideElement.querySelectorAll('.content-item');
|
|
|
| items.forEach((item, index) => {
|
| const delay = parseInt(item.dataset.animationDelay) || 0;
|
|
|
| setTimeout(() => {
|
| item.style.transition = 'all 400ms ease';
|
| item.style.opacity = '1';
|
| item.style.transform = 'translateY(0)';
|
| }, delay);
|
| });
|
| }
|
|
|
| |
| |
|
|
| async next() {
|
| if (this.currentIndex < this.slides.length - 1) {
|
| await this.showSlide(this.currentIndex + 1, 'next');
|
| }
|
| }
|
|
|
| |
| |
|
|
| async previous() {
|
| if (this.currentIndex > 0) {
|
| await this.showSlide(this.currentIndex - 1, 'prev');
|
| }
|
| }
|
|
|
| |
| |
|
|
| async goToFirst() {
|
| await this.showSlide(0, 'next');
|
| }
|
|
|
| |
| |
|
|
| async goToLast() {
|
| await this.showSlide(this.slides.length - 1, 'prev');
|
| }
|
|
|
| |
| |
|
|
| async glitchTransition(currentSlide, nextSlide, duration) {
|
| nextSlide.style.display = 'flex';
|
| nextSlide.style.opacity = '0';
|
|
|
| const glitchSteps = 8;
|
| const stepDuration = duration / glitchSteps;
|
|
|
| for (let i = 0; i < glitchSteps; i++) {
|
| const offset = Math.random() * 20 - 10;
|
| const opacity = i / glitchSteps;
|
|
|
| if (currentSlide) {
|
| currentSlide.style.transform = `translateX(${offset}px)`;
|
| currentSlide.style.opacity = String(1 - opacity);
|
| currentSlide.style.filter = `hue-rotate(${Math.random() * 360}deg)`;
|
| }
|
|
|
| nextSlide.style.transform = `translateX(${-offset}px)`;
|
| nextSlide.style.opacity = String(opacity);
|
| nextSlide.style.filter = `hue-rotate(${Math.random() * 360}deg)`;
|
|
|
| await this.wait(stepDuration);
|
| }
|
|
|
| if (currentSlide) {
|
| currentSlide.style.display = 'none';
|
| currentSlide.style.transform = '';
|
| currentSlide.style.filter = '';
|
| }
|
| nextSlide.style.transform = '';
|
| nextSlide.style.filter = '';
|
| nextSlide.style.opacity = '1';
|
| }
|
|
|
| |
| |
|
|
| async matrixTransition(currentSlide, nextSlide, duration) {
|
| nextSlide.style.display = 'flex';
|
|
|
|
|
| const matrix = document.createElement('div');
|
| matrix.style.position = 'absolute';
|
| matrix.style.inset = '0';
|
| matrix.style.background = 'linear-gradient(0deg, transparent 0%, rgba(0, 255, 0, 0.8) 50%, transparent 100%)';
|
| matrix.style.backgroundSize = '100% 200%';
|
| matrix.style.animation = `matrixScroll ${duration}ms linear`;
|
| matrix.style.zIndex = '1000';
|
| matrix.style.pointerEvents = 'none';
|
|
|
| this.container.appendChild(matrix);
|
|
|
|
|
| if (currentSlide) {
|
| currentSlide.style.transition = `opacity ${duration * 0.7}ms ease`;
|
| currentSlide.style.opacity = '0';
|
| }
|
|
|
| await this.wait(duration * 0.3);
|
|
|
| nextSlide.style.opacity = '0';
|
| nextSlide.style.transition = `opacity ${duration * 0.7}ms ease`;
|
| nextSlide.style.opacity = '1';
|
|
|
| await this.wait(duration * 0.7);
|
|
|
| if (currentSlide) {
|
| currentSlide.style.display = 'none';
|
| currentSlide.style.opacity = '1';
|
| }
|
|
|
| matrix.remove();
|
| }
|
|
|
| |
| |
|
|
| async cubeTransition(currentSlide, nextSlide, direction, duration) {
|
| const perspective = '1200px';
|
| const rotateY = direction === 'next' ? '-90deg' : '90deg';
|
|
|
| this.container.style.perspective = perspective;
|
| this.container.style.perspectiveOrigin = 'center center';
|
|
|
| nextSlide.style.display = 'flex';
|
| nextSlide.style.transform = `rotateY(${direction === 'next' ? '90deg' : '-90deg'})`;
|
| nextSlide.style.transformOrigin = direction === 'next' ? 'right center' : 'left center';
|
|
|
| if (currentSlide) {
|
| currentSlide.style.transformOrigin = direction === 'next' ? 'left center' : 'right center';
|
| }
|
|
|
| await this.wait(50);
|
|
|
| if (currentSlide) {
|
| currentSlide.style.transition = `transform ${duration}ms cubic-bezier(0.645, 0.045, 0.355, 1)`;
|
| currentSlide.style.transform = `rotateY(${rotateY})`;
|
| }
|
|
|
| nextSlide.style.transition = `transform ${duration}ms cubic-bezier(0.645, 0.045, 0.355, 1)`;
|
| nextSlide.style.transform = 'rotateY(0deg)';
|
|
|
| await this.wait(duration);
|
|
|
| if (currentSlide) {
|
| currentSlide.style.display = 'none';
|
| currentSlide.style.transform = '';
|
| }
|
| nextSlide.style.transform = '';
|
| this.container.style.perspective = '';
|
| }
|
|
|
| |
| |
|
|
| async pixelateTransition(currentSlide, nextSlide, duration) {
|
| nextSlide.style.display = 'flex';
|
| nextSlide.style.opacity = '0';
|
|
|
| const steps = 10;
|
| const stepDuration = duration / steps;
|
|
|
|
|
| for (let i = 0; i <= steps / 2; i++) {
|
| const pixelSize = i * 2;
|
| if (currentSlide) {
|
| currentSlide.style.filter = `blur(${pixelSize}px)`;
|
| currentSlide.style.opacity = String(1 - (i / (steps / 2)));
|
| }
|
| await this.wait(stepDuration);
|
| }
|
|
|
| if (currentSlide) {
|
| currentSlide.style.display = 'none';
|
| }
|
|
|
|
|
| for (let i = steps / 2; i >= 0; i--) {
|
| const pixelSize = i * 2;
|
| nextSlide.style.filter = `blur(${pixelSize}px)`;
|
| nextSlide.style.opacity = String(1 - (i / (steps / 2)));
|
| await this.wait(stepDuration);
|
| }
|
|
|
| if (currentSlide) {
|
| currentSlide.style.filter = '';
|
| currentSlide.style.opacity = '1';
|
| }
|
| nextSlide.style.filter = '';
|
| nextSlide.style.opacity = '1';
|
| }
|
|
|
| |
| |
|
|
| wait(ms) {
|
| return new Promise(resolve => setTimeout(resolve, ms));
|
| }
|
|
|
| |
| |
|
|
| getCurrentSlide() {
|
| return this.slides[this.currentIndex];
|
| }
|
|
|
| |
| |
|
|
| getSlideCount() {
|
| return this.slides.length;
|
| }
|
| }
|
|
|
|
|
| export function createSlideRenderer(container, options = {}) {
|
| return new SlideRenderer(container, options);
|
| }
|
|
|