Download wp-calypso/packages/block-renderer/src/utils/load-styles.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 958 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/packages/block-renderer/src/utils/load-styles.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/packages/block-renderer/src/utils/load-styles.ts
-
curl -L -o load-styles.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/packages/block-renderer/src/utils/load-styles.ts
958 Bytes
| const loadStyle = async ( | |
| element: HTMLElement, | |
| { tagName, id, href, rel, media, textContent }: HTMLLinkElement | |
| ) => { | |
| return new Promise( ( resolve ) => { | |
| const style = element.ownerDocument.createElement( tagName ) as HTMLLinkElement; | |
| style.id = id; | |
| if ( href ) { | |
| style.href = href; | |
| style.rel = rel; | |
| style.media = media; | |
| style.onload = () => resolve( style ); | |
| style.onerror = () => { | |
| // eslint-disable-next-line no-console | |
| console.warn( `Error while loading the CSS: ${ href }` ); | |
| // Resolve the promise to ignore the error. | |
| resolve( style ); | |
| }; | |
| } else { | |
| style.textContent = textContent; | |
| resolve( style ); | |
| } | |
| element.appendChild( style ); | |
| } ); | |
| }; | |
| const loadStyles = async ( element: HTMLElement, styles: HTMLLinkElement[] ) => { | |
| return styles.reduce( | |
| ( promise, style ): Promise< any > => promise.then( () => loadStyle( element, style ) ), | |
| Promise.resolve() | |
| ); | |
| }; | |
| export default loadStyles; | |