Spaces:
Running

spingenius-pro / components /loader-preview.js
dazman72's picture
ad more customisation options, use cutting edge libraries for a rich user experience and the ability to create totally unique and custom loaders
1a52121 verified
Raw History Blame Contribute Delete
1.93 kB
class LoaderPreview extends HTMLElement {
connectedCallback() {
this.attachShadow({ mode: 'open' });
this.shadowRoot.innerHTML = `
<style>
:host {
display: block;
width: 100%;
height: 100%;
position: relative;
}
.preview-container {
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
background: white;
border-radius: 0.5rem;
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
overflow: hidden;
}
canvas {
max-width: 100%;
max-height: 100%;
}
</style>
<div class="preview-container">
<canvas id="loader-canvas"></canvas>
</div>
`;
this.canvas = this.shadowRoot.getElementById('loader-canvas');
this.ctx = this.canvas.getContext('2d');
this.setupCanvas();
this.startAnimation();
}
setupCanvas() {
const container = this.shadowRoot.querySelector('.preview-container');
this.canvas.width = container.clientWidth;
this.canvas.height = container.clientHeight;
}
startAnimation() {
const animate = () => {
this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
// Draw custom loader animation using canvas API
const time = Date.now() * 0.001;
const centerX = this.canvas.width / 2;
const centerY = this.canvas.height / 2;
const radius = Math.min(this.canvas.width, this.canvas.height) * 0.3;
this.ctx.beginPath();
this.ctx.arc(centerX, centerY, radius, time % (Math.PI * 2), (time + Math.PI) % (Math.PI * 2));
this.ctx.lineWidth = 8;
this.ctx.strokeStyle = '#3b82f6';
this.ctx.stroke();
requestAnimationFrame(animate);
};
animate();
}
}
customElements.define('loader-preview', LoaderPreview);