Skip to content

Instantly share code, notes, and snippets.

View franktopel's full-sized avatar
🏠
Working from home

Frank Topel franktopel

🏠
Working from home
View GitHub Profile
@franktopel
franktopel / separateHtmlAndCss.js
Last active September 17, 2020 11:39
Javascript function to extract 'unsafe-inline' styles from a HTML string
export function separateHtmlAndCss(str) {
const parser = new DOMParser();
let parsedHtml = parser.parseFromString(str, 'text/html');
const CLASS_NAME_PREFIX = 'generated-class-name-';
let html, css = '';
// handle <style>-Tags
const styleTags = parsedHtml.querySelectorAll('style');
if (styleTags.length > 0) {
for (let i = 0; i < styleTags.length; i++) {
@franktopel
franktopel / input.scss
Created September 15, 2020 09:28
Generated by SassMeister.com.
div {
color: lighten(#a00, 10%);
background-color: darken(#a00, 20%);
}
@franktopel
franktopel / HTMLBaseElement.md
Last active August 25, 2023 12:03
HTMLBaseElement class solving the problem of connectedCallback being called before children are parsed

There is a huge practical problem with web components spec v1:

In certain cases connectedCallback is being called when the element's child nodes are not yet available.

This makes web components dysfunctional in those cases where they rely on their children for setup.

See WICG/webcomponents#551 for reference.

To solve this, we have created a HTMLBaseElement class in our team which serves as the new class to extend autonomous custom elements from.

@franktopel
franktopel / Frontend Architecture for Single Page Applications in 2018.md
Last active May 14, 2018 08:24
Frontend Architecture for Single Page Applications in 2018