|
// Polyfill so we can run this in Node.js as well |
|
if (typeof atob !== 'function') { |
|
var atob = a => Buffer.from(a, 'base64').toString('binary') |
|
var btoa = b => Buffer.from(b).toString('base64'); |
|
} |
|
|
|
// 511 bytes after minify |
|
var a=[ |
|
["#1b6f3f", "#10c5b4", "#ade4cd", "#29ec19"], |
|
["#96bde8", "#246a85", "#3483e4", "#b168f6"], |
|
["#b623b1", "#6e18f9", "#49cbc1", "#5ad67d"], |
|
["#73267b", "#c29c5b", "#6086de"], |
|
["#e79f9b", "#772140", "#cb8c96"], |
|
["#a45cd7", "#3d0709", "#9778c4", "#5893b6", "#40a399"], |
|
["#6df6d1", "#5ea534", "#88bc86"], |
|
["#6f4895", "#d5a6fc", "#3951c3", "#4e2816", "#7fd50c"], |
|
["#58498e", "#596a5c", "#9d53ee", "#c30935", "#3a0480"], |
|
["#67aef5", "#2eae76", "#6e2376", "#e05d7d"], |
|
["#ca15c8", "#a98acd", "#0293c3", "#856e0d"], |
|
["#b65cd2", "#fc2bba", "#59a669", "#2f2c99"], |
|
]; |
|
|
|
// turn into base64 encoded strings |
|
var txt = a.map(palette => { |
|
const uint8 = new Uint8Array(palette.map(n => hexToRGB(n)).flat()) |
|
return btoa(uint8) |
|
}).join(`:`) |
|
|
|
// decompress without # prefix (313 bytes) |
|
var k=`G28/EMW0reTNKewZ:lr3oJGqFNIPksWj2:tiOxbhj5ScvBWtZ9:cyZ7wpxbYIbe:55+bdyFAy4yW:pFzXPQcJl3jEWJO2QKOZ:bfbRXqU0iLyG:b0iV1ab8OVHDTigWf9UM:WEmOWWpcnVPuwwk1OgSA:Z671Lq52biN24F19:yhXIqYrNApPDhW4N:tlzS/Cu6WaZpLyyZ`.split`:`.map(b=>[...atob(b)].map(c=>c.charCodeAt().toString(16).padStart(2,0)).join``.match(/.{6}/g)) |
|
|
|
console.log(k); |
|
|
|
function hexToRGB(str) { |
|
var hex = str.replace(/^#/, ""); |
|
if (hex.length === 3) hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2]; |
|
var num = parseInt(hex, 16); |
|
var red = num >> 16; |
|
var green = (num >> 8) & 255; |
|
var blue = num & 255; |
|
return [red, green, blue]; |
|
} |
TODO idea: use rgb444 or rgb565 to further reduce the base64 payload, and/or use a custom ASCII encoder such as a variant of uuencoding.
The difficulty with 444 is decoding as it may require a sort of bit stream reader. Below is an option with rgb565 using Uint16Array to wrap a single color (2 bytes) into a single 16bit decimal.