import * as sfw from 'sfw'; const { Div, Img } = sfw.element.native; import Image from '../../widgets/image/index.js'; const css = await sfw.css(import.meta.url, './index.css') export default class ImageViewer extends sfw.element.Container { #container #subtitle #images constructor() { super({ css }); this.#images = []; this.onnewer = () => {} this.onolder = () => {} this.body.append( this.#container = Div.new({ id: 'container', onscroll: () => this.#images.forEach(image => this.#preload(image)), children: [ this.#subtitle = Div.new({ id: 'subtitle', innerHTML: 'Powered by Memora' }) ], }) ); } add(id) { const image = Image.new({ id }); this.#images.push(image); this.#container.insertBefore(image, this.#subtitle); this.#preload(image); } clear() { this.#container.innerHTML = ''; this.#container.append(this.#subtitle); } #preload(image) { const loading_zone = (this.#container.scrollTop + this.#container.offsetHeight) * 2; if (image.offsetTop < loading_zone) { image.load(); } } }