Skip to content

Instantly share code, notes, and snippets.

View jonathantneal's full-sized avatar

Jonathan Neal jonathantneal

View GitHub Profile
@jonathantneal
jonathantneal / esbuild-loader.js
Last active June 15, 2021 01:49
Node — Loads modules using esbuild. — `node --experimental-loader ./esbuild-loader.js`
import { existsSync } from 'fs'
import { readFile } from 'fs/promises'
import { transform } from 'esbuild'
/** @typedef {{ conditions: string[], parentURL: string }} Context */
/** @typedef {(specifier: string, context: Context, defaultResolve: ResolveHook) => { url: string }} ResolveHook */
/** @typedef {(url: string, context: Context, defaultGetFormat: GetFormatHook) => { format: string }} GetFormatHook */
/** @typedef {(url: string, context: Context, defaultGetSource: GetSourceHook) => Promise<{ source: string | SharedArrayBuffer | Uint8Array }>} GetSourceHook */
/** Matches any JavaScript/TypeScript module. */
@jonathantneal
jonathantneal / ConstructableStylesheetPolyfill.js
Last active January 25, 2023 04:12
Constructable Stylesheet Polyfill — 330 bytes / 235 bytes gzipped — https://wicg.github.io/construct-stylesheets/
try {
new CSSStyleSheet()
} catch {
CSSStyleSheet = ((
stylePtt = CSSStyleSheet.prototype,
styleDoc = new Document(),
styleDom = styleDoc.appendChild(document.createElement('style')),
sheet
) => Object.assign(stylePtt.constructor = function CSSStyleSheet() {
if (!new.target) {
@jonathantneal
jonathantneal / createStyleSheetObserver.js
Created May 10, 2021 02:26
Some, like, useful functions when building cqfill. This gist may be deleted later.
/** Observes stylesheet lists and runs a callback whenever it encounteres added or removed stylesheets. */
export const createStyleSheetObserver = (/** @type {(addedSheets?: CSSStyleSheet[], removedSheets?: CSSStyleSheet[]) => void} */ callback) => {
/** @type {Set<StyleSheetList>} Observed style sheet lists. */
const sheetLists = new Set
/** @type {Set<CSSStyleSheet>} Previously observed style sheets. */
let lastSheets = new Set
/** Observes style sheet on each animation frame. */
const onAnimationFrame = () => {
requestAnimationFrame(onAnimationFrame)
/** @type {CSSStyleSheet[]} Observed StyleSheets after this frame. */
@jonathantneal
jonathantneal / README.md
Last active April 25, 2021 00:23
CSS Container Queries Notes

CSS Container Queries Notes

Detecting a layout container

  1. If the target rule represents a style rule;
  2. If the target rule style contains a fallback contain property; 1. If the fallback contain property represents a layout container;
    1. For each element matching the selector of the target rule;
    2. Add the element to the list of layout containers, then;
  3. Add a fallback layout containment rule for that specific element.
@jonathantneal
jonathantneal / all-css-property-names.js
Created March 9, 2021 20:33
All CSS Property Names
[
"align-content",
"align-items",
"align-self",
"alignment-baseline",
"all",
"animation",
"animation-delay",
"animation-direction",
"animation-duration",
@jonathantneal
jonathantneal / deepAssign.js
Created March 8, 2021 23:54
Deep Assign - deeply copies all enumerable own properties from one source object to a target object
function deepAssign(objectA, objectB) {
for (var n in objectB) {
var objectBN = objectB[n]
if (objectBN === Object(objectBN)) {
var objectAN = objectA[n]
if (objectAN === Object(objectAN)) {
objectA[n] = deepAssign(objectAN, objectBN)
@jonathantneal
jonathantneal / color.js
Created February 19, 2021 18:33
color.js - a color utility useful in a NodeJS terminal, console, command prompt
export default new Proxy(
Object.entries({
reset: 0,
bold: 1,
dim: 2,
underline: 4,
blink: 5,
invert: 7,
hidden: 8,
black: 30,
@jonathantneal
jonathantneal / flex-gap-polyfill.js
Created December 20, 2020 22:04
Flex Gap Polyfill
(
(
d,
c = d.createElement('b').style,
a = c.gap = 0,
polyfillList = new WeakMap,
ungapful = /^(normal|0px)+$/,
polyfillNode = element => {
if (polyfillList.has(element)) return
polyfillList.set(element, true)
@jonathantneal
jonathantneal / README.md
Last active November 5, 2022 17:04
Installing Apps on M1

Before Starting

Install Command Line Tools for macOS:

xcode-select --install

Quick Installs

@jonathantneal
jonathantneal / createObjectUID.ts
Created November 5, 2020 13:24
Create a unique identifier from an Object URL
/** Returns a unique identifier tied to the document in the window on which it was created. */
const createObjectUID = (): string => URL.createObjectURL(new Blob()).slice(-5)