/** * * The shadowDom / Intersection Observer version of Paul's concept: * https://github.com/paulirish/lite-youtube-embed * * A lightweight YouTube embed. Still should feel the same to the user, just * MUCH faster to initialize and paint. * * Thx to these as the inspiration * https://storage.googleapis.com/amp-vs-non-amp/youtube-lazy.html * https://autoplay-youtube-player.glitch.me/ * * Once built it, I also found these (👍👍): * https://github.com/ampproject/amphtml/blob/master/extensions/amp-youtube * https://github.com/Daugilas/lazyYT https://github.com/vb/lazyframe */ export declare class LiteYTEmbed extends HTMLElement { shadowRoot: ShadowRoot; private domRefFrame; private domRefImg; private domRefPlayButton; private static isPreconnected; private isIframeLoaded; constructor(); static get observedAttributes(): string[]; connectedCallback(): void; disconnectedCallback(): void; get videoId(): string; set videoId(id: string); get playlistId(): string; set playlistId(id: string); get videoTitle(): string; set videoTitle(title: string); get videoPlay(): string; set videoPlay(name: string); get videoStartAt(): string; get autoLoad(): boolean; get noCookie(): boolean; get posterQuality(): string; get posterLoading(): HTMLImageElement['loading']; get params(): string; set params(opts: string); private frameClickHandler; /** * Define our shadowDOM for the component */ private setupDom; /** * Parse our attributes and fire up some placeholders */ private setupComponent; /** * Lifecycle method that we use to listen for attribute changes to period */ attributeChangedCallback(_name: string, oldVal: unknown, newVal: unknown): void; /** * Inject the iframe into the component body * @param {boolean} isIntersectionObserver */ private addIframe; /** * Setup the placeholder image for the component */ private initImagePlaceholder; /** * Setup the Intersection Observer to load the iframe when scrolled into view */ private initIntersectionObserver; /** * This is a terrible hack to attempt to get YouTube Short-like autoplay on * mobile viewports. It's this way because: * 1. YouTube's Iframe embed does not offer determinism when loading * 2. Attempting to use onYouTubeIframeAPIReady() does not work in 99% of * cases * 3. You can _technically_ load the Frame API library and do more advanced * things, but I don't want to burn the thread of the wire with its * shenanigans since this an edge case. * @private */ private attemptShortAutoPlay; /** * A hacky attr check and viewport peek to see if we're going to try to enable * a more friendly YouTube Short style loading * @return boolean */ private isYouTubeShort; /** * Add a to the head * @param {string} kind * @param {string} url * @param {string} as */ private static addPrefetch; /** * Begin preconnecting to warm up the iframe load Since the embed's network * requests load within its iframe, preload/prefetch'ing them outside the * iframe will only cause double-downloads. So, the best we can do is warm up * a few connections to origins that are in the critical path. * * Maybe `` would work, but it's unsupported: * http://crbug.com/593267 But TBH, I don't think it'll happen soon with Site * Isolation and split caches adding serious complexity. */ private static warmConnections; } declare global { interface HTMLElementTagNameMap { 'lite-youtube': LiteYTEmbed; } interface Window { liteYouTubeNonce: string; liteYouTubeIsPreconnected: boolean; } }