/** * manage loading of content like svg files. * allow to manage the loading only if the container is visible (lazy mode). * put data into cache. * allow validators on the received content (if sanitize mode enabled). * * @example * ```typescript * const lazy = true; * const svgLoadContent = new OdsLoadContent([ * (content) => {return content !== 'forbiddenText' ? content : 'filtered' } * ]); * * this.svgLoadContent.waitUntilVisible(yourHTMLElement, '50px', () => { * svgLoadContent.load('my/file/path.svg', true, true); * }, lazy); * ``` * * --- * * Code inspired by ionic-icons (version 6.0.3) from Ionic team * https://github.com/ionic-team/ionicons * * The MIT License (MIT) * * Copyright (c) 2015-present Ionic (http://ionic.io/) * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ export declare class OdsLoadContent { private contentCache; private contentValidators; private io?; private readonly logger; private requestCache; constructor(contentValidators?: Array<(content: string) => string>); /** * load a given url only in case of element is visible in browser. * check first the cache and if not yet cached, make the call and cache it. * the cached content can be sanitized with the validators. * @param url - url of the content to load * @param isVisible - is the element to display is visible in browser * @param sanitize - clean content with your own validators * @param isBrowser - browser context or not */ load(url: string, isVisible: boolean, sanitize?: boolean, isBrowser?: boolean): Promise; onDestroy(): void; /** * wait for calling a callback only when the element is visible in the browser, for lazy mode. * if lazy not enabled, it calls directly the callback. * an intersection observer is used in order to allow the detection. * if the browser does not support it, the lazy mode is not applied. * @param el - html element to check visibility * @param rootMargin - margin trigger on the viewport border used to detect visibility * @param cb - callback to call when visible * @param lazy - enable or not the lazy mode * @param isBrowser - is browser context or not */ waitUntilVisible(el: HTMLElement, rootMargin: string, cb: () => void, lazy: boolean, isBrowser?: boolean): void; /** * get the cached content of url or fetch it. * requests are also cached in order to not doing multiple times the same. * @param url - url to fetch if needed * @param sanitize - apply validators on the retrieved content or not */ private getContent; private sanitize; }