Path: blob/main/extensions/markdown-language-features/preview-src/loading.ts
3292 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/4import { MessagePoster } from './messaging';56export class StyleLoadingMonitor {7private readonly _unloadedStyles: string[] = [];8private _finishedLoading: boolean = false;910private _poster?: MessagePoster;1112constructor() {13const onStyleLoadError = (event: any) => {14const source = event.target.dataset.source;15this._unloadedStyles.push(source);16};1718window.addEventListener('DOMContentLoaded', () => {19for (const link of document.getElementsByClassName('code-user-style') as HTMLCollectionOf<HTMLElement>) {20if (link.dataset.source) {21link.onerror = onStyleLoadError;22}23}24});2526window.addEventListener('load', () => {27if (!this._unloadedStyles.length) {28return;29}30this._finishedLoading = true;31this._poster?.postMessage('previewStyleLoadError', { unloadedStyles: this._unloadedStyles });32});33}3435public setPoster(poster: MessagePoster): void {36this._poster = poster;37if (this._finishedLoading) {38poster.postMessage('previewStyleLoadError', { unloadedStyles: this._unloadedStyles });39}40}41}424344