This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function html(string = '') { | |
return document.implementation | |
.createHTMLDocument() | |
.createRange() | |
.createContextualFragment(string) | |
} | |
/* | |
A JavaScript function that takes a string of HTML syntax, parses it as HTML and returns a Document Fragment containing all parsed nodes. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function evaluateTemplate(template = '', html = '') { | |
const tag = Object.assign( | |
document.createElement('shadow-dom'), | |
{innerHTML: html} | |
) | |
tag.attachShadow({mode: 'open'}) | |
tag.shadowRoot.innerHTML = template | |
// Replace <slot> with contents (flatten) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@--custom-at-rule with prelude { | |
custom-type:--custom-pseudo-class(with args) /--custom-combinator/ ::--custom-pseudo-element { | |
--custom-property: --custom-ident --custom-function(1--custom-unit) !--custom-annotation; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
legal css custom property values { | |
--percentage: 25%; | |
--number: 37; | |
--length: 12em; | |
--time: 75ms; | |
--function: foo(); | |
--nested-function: foo(bar()); | |
--parentheses: ( ); | |
--braces: { }; | |
--brackets: [ ]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:root { | |
--palette: { | |
"blue": "#06f", | |
"font": ["Comic Sans MS", "Papyrus"] | |
}; | |
font-family: --json(var(--palette).font[1]); | |
color: --color(--json(var(--palette).blue)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<title>Star Rating Element</title> | |
<script type=module> | |
import StarRating from './star-rating-element.js' | |
customElements.define('star-rating', StarRating) | |
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type=module> | |
class WordCarousel extends HTMLElement { | |
constructor() { | |
super() | |
this.carousel | |
this.active = false | |
} | |
static get observedAttributes() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default function html(taggedTemplateString = [''], ...expressions) { | |
const nodes = [] | |
const functions = new Map | |
const strings = typeof taggedTemplateString === 'string' | |
? [taggedTemplateString] | |
: taggedTemplateString | |
function stringifyObject(object = '') { | |
// Null | |
if (object === null) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
json types in CSS syntax { | |
--string: "string"; | |
--number: 1; | |
--object: {"key": "value"}; | |
--array: [1, 2, 3]; | |
--boolean: true false; | |
--null: null; | |
--example: { | |
"json": ["data", true] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.matchMedia('(prefers-color-scheme: dark)').addListener(list => { | |
console.log( | |
event.matches === true | |
? 'Dark mode enabled' | |
: 'Light mode enabled' | |
) | |
}) |