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 speak( | |
text = '', | |
options = { | |
volume: 1, // 0-1 | |
rate: 1.25, // 0.1-10 | |
pitch: 1, // 0-2 | |
lang: 'en-US', | |
// voice: 'Catherine' | |
voice: 'Karen' | |
} |
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> | |
<title>CSS Shadow Root styling</title> | |
<script type=module> | |
class CustomElement extends HTMLElement { | |
connectedCallback() { | |
const shadow = this.attachShadow({mode: 'closed'}) | |
shadow.innerHTML = ` | |
<style> |
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 processSelfClosingTags(string = '') { | |
const dom = document.implementation.createHTMLDocument().createRange().createContextualFragment(string) | |
function consumeNode(node = document.createElement('span')) { | |
if ( | |
node.nodeType === 8 | |
&& node.textContent.match(/^\?.+\?$/) | |
) { | |
node.replaceWith( | |
document.createElement( |
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 XPath search */ (await import('https://unpkg.com/espath')).default(window.dataLayer, '//string') | |
/* cookie to object */ Object.fromEntries(document.cookie.split('; ').map(entry => entry.split('='))) | |
/* cookie to object */ (await import('https://v2.crocdn.com/_plugins/cookie-to-object.js')).default() | |
/* css elements search */ document.querySelectorAll ('*') | |
/* xpath element search */ (await import('https://unpkg.com/queryxpath/queryxpath.es.js')).queryXPathAll ('//*') |
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
css clamp function usage at work { | |
font-size: clamp(12pt, 5vw, 15pt); | |
font-size: clamp(22pt, 2.5vw, 28pt); | |
font-size: clamp(20pt, 2.5vw, 28pt); | |
font-size: clamp(8pt, 6--ew, 10pt); | |
font-size: clamp(7pt, 6--ew, 9pt); | |
font-size: clamp(24px, 6vw, 36px); | |
font-size: clamp(var(--min), 4vw, var(--max)); | |
font-size: clamp(var(--min), 5vw, var(--max)); | |
font-size: clamp(var(--min), 3vw, var(--max)); |
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
class InactivityCountdown { | |
constructor( | |
callback = () => {}, | |
duration = 10 | |
) { | |
this.timer // to hold setTimeout ID | |
this.active = false // remember timer state | |
this.callback = callback // function to run when countdown completes | |
this.duration = duration // time in seconds to wait | |
} |
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
// Wait for React | |
function hasReactProperty(tag = document.documentElement) { | |
return Object.keys(tag).some(key => | |
key.includes('__react') | |
) | |
} | |
function isReactRoot(tag) { | |
return hasReactProperty(tag) |
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 src="data:text/javascript, | |
import {demo} from 'data:text/javascript,export const demo = `Howdy`'; | |
console.log(demo); | |
"></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
Sass (and Less and Stylus and other custom languages that compile to CSS) have some design flaws that end up limiting what you can do with CSS. If you have a codebase that still depends on them it would be a good time to isolate and minimize the code you have that uses them and strategize how you'll migrate away from them. If your project doesn't have have them, or you haven't yet learned them - it might be a good idea, thinking ahead, to just skip that and get into a pure CSS workflow. Don't worry, you can still preprocess CSS, the secret is writing and handling valid CSS at every step in your workflow so all the tools work together | |
Some flaws Sass has that get in the way: | |
- It's not actually compatible with CSS syntax. It's not a super-set, it's an entirely different syntax and because it's incompatible with real CSS, there's an infinite variety of things you might have or want in CSS that can't even be present in any stylesheet Sass looks at | |
- Some of the things Sass adds to its custom syntax are things |
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(strings, ...expressions) { | |
return document.createRange().createContextualFragment( | |
strings.reduce((output, string, index) => | |
output + expressions[index - 1] + string | |
) | |
) | |
} | |
document.body.append( | |
html` |
NewerOlder