Skip to content

Instantly share code, notes, and snippets.

View LeaVerou's full-sized avatar

Lea Verou LeaVerou

View GitHub Profile
@LeaVerou
LeaVerou / dabblet.css
Created June 23, 2022 11:17
Never use circle size to convey information
/**
* Never use circle size to convey information
*/
div {
display: inline-flex; align-items: center; justify-content: center;
width: 200px;
aspect-ratio: 1 / 1;
padding: 1em;
background: radial-gradient(closest-side, hsl(220 10% 70%) calc(var(--p)), transparent 0) hsl(220 10% 90%);
@LeaVerou
LeaVerou / dabblet.css
Created June 9, 2022 12:13
Invalid custom property values
/**
* Invalid custom property values
*/
@property --foo {
syntax: "red | orange";
initial-value: red;
inherits: false;
}
html { --foo: green }
@LeaVerou
LeaVerou / dabblet.css
Created June 6, 2022 14:58
Division by <length> test
/**
* Division by <length> test
*/
div {
background: green;
width: 100px;
height: calc(100px * (100vw / 100vh));
}
@LeaVerou
LeaVerou / detect_custom_elements.js
Last active April 21, 2022 21:02 — forked from ebidel/highlight_custom_elements.js
Get a list of custom elements used on a page
// Highlights all custom elements on the page.
// 7/31/2016: updated to work with both shadow dom v0 and v1.
// To create a bookmarklet, use http://ted.mielczarek.org/code/mozilla/bookmarklet.html
var allCustomElements = [];
function isCustomElement(el) {
const isAttr = el.getAttribute('is');
// Check for <super-button> and <button is="super-button">.
return el.localName.includes('-') || isAttr && isAttr.includes('-');
@LeaVerou
LeaVerou / dabblet.css
Created February 28, 2022 18:16
Overriding presentational HTML
/**
* Overriding presentational HTML
*/
div {
background: pink;
}
@LeaVerou
LeaVerou / dabblet.css
Created December 13, 2021 14:00
Negative opacity
/**
* Negative opacity
*/
body { background: red }
@supports (opacity: -3.1415926535) {
body { background: green }
}
@LeaVerou
LeaVerou / tape-to-mocha.js
Last active November 2, 2021 23:04
Shim to migrate Tape tests to Mocha tests
// Migrate Tape tests to Chai tets (used by Mocha)
// This will not get you 100% of the way, but it will get you most of the way there (depending on your tests).
// I mainly only had to rewrite tests that used subtests (`t.test()`): For those, I used `describe` for the outer test, and converted `t.test()` to `test()`
import { assert } from '@esm-bundle/chai';
assert.ok = assert.isOk.bind(assert);
assert.pass = assert.isOk.bind(assert, true);
assert.end = () => {}; // no-op
assert.plan = () => {}; // no-op, doesn't seem to be needed with WTR
@LeaVerou
LeaVerou / settings.json
Created August 3, 2021 11:24
VS Code Solarized Light that looks like Atom’s Solarized Light (WIP)
{
"workbench.colorTheme": "Solarized Light",
"editor.fontFamily": "Consolas, Menlo, Monaco, 'Courier New', monospace",
"editor.insertSpaces": false,
"editor.inlineSuggest.enabled": true,
"editor.fontSize": 14.5,
"editor.renderWhitespace": "boundary",
"editor.codeLens": false,
"editor.inlayHints.fontFamily": "Consolas, Menlo, Monaco, 'Courier New', monospace",
"diffEditor.codeLens": true,

Test

let color = new Color("p3", [0, 1, 0]);
let redgreen = color.range("red", {
	space: "lch", // interpolation space
	outputSpace: "srgb"
});
redgreen(.5); // midpoint

Tab's example

let middleRed = new Color("rgb(100 0 0)");
let middleGreen = new Color("rgb(0 100 0)");
let mixed = middleRed.mix(middleGreen, -.2, {space: "srgb"});

middleRed.hue;
mixed.hue;