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
#!/usr/bin/env node | |
var fs = require('fs'); | |
var http = require('http'); | |
var path = require('path'); | |
var rollup = require('rollup'); | |
var rollupConfig = require('../rollup.config'); | |
var CONTENT_TYPES = { | |
'.html': 'text/html', |
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
/* makes sizing simpler */ | |
*, | |
*::before, | |
*::after { | |
box-sizing: border-box; | |
} | |
/* remove default spacing */ | |
/* force styling of type through styling, rather than elements */ |
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
import imagemin from 'imagemin'; | |
import imageminWebp from 'imagemin-webp'; | |
import imageminPngquant from 'imagemin-pngquant'; | |
const produceWebP = async () => { | |
const outputFolder = './images/webp'; | |
await imagemin(['images/*.png'], { | |
destination: outputFolder, | |
plugins: [ |
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 isTranferable(obj) { | |
try { | |
return ( | |
obj instanceof ArrayBuffer || | |
obj instanceof MessagePort || | |
obj instanceof ImageBitmap || // safari 15+ ios 15+ | |
obj instanceof OffscreenCanvas // safari 16.4+ ios 16.4+ | |
); | |
} catch { | |
return false; |
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
const isFn = (a) => typeof a === 'function'; | |
export function addObjectPool(objtype, resetFunction, maxSize = Number.MAX_SAFE_INTEGER) { | |
const pool = []; | |
function newObject() { | |
return new objtype(); | |
} | |
if (isFn(resetFunction)) { |
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
const isRunningInBrowser = typeof window !== 'undefined'; | |
function runWhenBrowserEnvReady(fn) { | |
if (isRunningInBrowser) { | |
const doc = document; | |
doc.readyState[0] === 'l' ? doc.addEventListener('DOMContentLoaded', fn) : fn(); | |
} else { | |
fn(); | |
} | |
} |
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
/* | |
* Based on example code by Stefan Gustavson (stegu@itn.liu.se). | |
* Optimisations by Peter Eastman (peastman@drizzle.stanford.edu). | |
* Better rank ordering method by Stefan Gustavson in 2012. | |
* | |
* This code was placed in the public domain by its original author, | |
* Stefan Gustavson. You may use it as you see fit, but | |
* attribution is appreciated. | |
*/ |
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
// returns a number with the fractional part of the given number | |
function fract(num) { | |
return num - Math.floor(num); | |
} | |
// hash2d - not repeatable or stable between platforms | |
function hash2d(x, y) { | |
return fract(43758.5453 * Math.sin(x * 78.233 - 12.9898 * y)); | |
} | |
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 Semaphore() { | |
// controllable promise | |
let _resolve; | |
let _reject; | |
const promiseSemaphore = new Promise((resolve, reject) => { | |
_resolve = resolve; | |
_reject = reject; | |
}); |
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 resolveAfter(ms) { | |
// intoduces a delay | |
return new Promise((resolve) => setTimeout(resolve, ms)); | |
} |
NewerOlder