diff --git a/deno.lock b/deno.lock index ed1484f..5be9f89 100644 --- a/deno.lock +++ b/deno.lock @@ -227,6 +227,10 @@ "https://deno.land/x/canvas@v1.4.1/src/wasm.js": "449d72cc14fc4142a5853f944df49a744d852981d09c5515528ede8aebb0afda", "https://deno.land/x/copy_paste@v1.1.3/deps.ts": "89bfebe10979530b38b3be2ace3b24a7b83dbecb2a6cca7cd7b05b9a86fb1e61", "https://deno.land/x/copy_paste@v1.1.3/mod.ts": "3b82d6c620749acb86398bbec1f2c1f472cc39921c22ca7d7a98ab682b170f20", + "https://deno.land/x/css@0.3.0/core/lexer/lexer.ts": "4260365331a970526566e773e3399a0a90420c5fc18eb76664a5d9d36fe36c63", + "https://deno.land/x/css@0.3.0/core/parser/parser.ts": "c9fc6db27f346e7a34b66ea19232e1540e9c88f477da3246f6b3a3efae11c0a9", + "https://deno.land/x/css@0.3.0/debug/debug.js": "fb6774490c1c6236453837d8507a1df32270eabff568ec991355cfcb7ca47f2b", + "https://deno.land/x/css@0.3.0/mod.ts": "e9f5f17cfeb7843732291c263e0a912c31861465680b2234079e9a7dfd7de178", "https://deno.land/x/deno_dom@v0.1.38/build/deno-wasm/deno-wasm.js": "98b1ad24a1c13284557917659402202e5c5258ab1431b3f3a82434ad36ffa05a", "https://deno.land/x/deno_dom@v0.1.38/deno-dom-wasm.ts": "bfd999a493a6974e9fca4d331bee03bfb68cfc600c662cd0b48b21d67a2a8ba0", "https://deno.land/x/deno_dom@v0.1.38/src/api.ts": "0ff5790f0a3eeecb4e00b7d8fbfa319b165962cf6d0182a65ba90f158d74f7d7", @@ -307,6 +311,7 @@ "https://deno.land/x/imagescript@1.2.9/utils/wasm/jpeg.js": "da660e827fa45a85ee63aafa38dceb031dbd8988162bf730ace8d6135d842413", "https://deno.land/x/imagescript@1.2.9/utils/wasm/svg.js": "f7d8827fa8dc4aa9b1027374a87ae658da4bdd46048c66c01d909291d1cf132a", "https://deno.land/x/imagescript@1.2.9/utils/wasm/zlib.js": "63060a9aabee087929eb01d9e8b75b3ddc94a846a929a81d4456ed9b54d72671", + "https://esm.sh/css@3.0.0": "a54982657613e96ebf2bc9487629a96a6e57bd33aaa04943c543b6cfc94962b3", "https://esm.sh/preact-render-to-string@5.2.0?external=preact": "d68df08425ff945f8b2872d784d587c6588f9f6369e553758d254477bfc95818", "https://esm.sh/preact@10.16.0": "5229650cdac537f87cae81d5001e88d4e7a38cc7e77be978961d2897a733117d", "https://esm.sh/preact@10.16.0/jsx-runtime?dts": "9e67b64a5b48299c77d30bffc213735fdcf4b3b5d4ad8ff8d4136f246de5fa34", @@ -314,6 +319,12 @@ "https://esm.sh/stable/preact@10.16.0/denonext/preact.mjs": "01dc8bdf124926c611c0711081b9c162cf2735cccad7c2bc9914766f633ddb1d", "https://esm.sh/stable/preact@10.16.0/denonext/src.js": "a95281269ac2665427e647cde8628d5cd6eef13bb6bea381c3167a78fa922316", "https://esm.sh/v128/preact@10.16.0/src/index.js": "3bafc9400950c38b80163dcbcd4538a54ef158a83f448517f34324c5685f1569", - "https://esm.sh/v134/preact-render-to-string@5.2.0/X-ZS9wcmVhY3Q/denonext/preact-render-to-string.mjs": "b2b771d82125460bd3e5cdf20ebd662a08c4c61e34b174cd11db929dd5883966" + "https://esm.sh/v134/preact-render-to-string@5.2.0/X-ZS9wcmVhY3Q/denonext/preact-render-to-string.mjs": "b2b771d82125460bd3e5cdf20ebd662a08c4c61e34b174cd11db929dd5883966", + "https://esm.sh/v135/atob@2.1.2/denonext/atob.mjs": "dd534c006761ac47d482333cb9cf131034faa878878d1206ac30372eac803701", + "https://esm.sh/v135/css@3.0.0/denonext/css.mjs": "56fbc2f42803ff9ed37086bf761df8ae6a0ad705c1b163030d9cf0ed284abe34", + "https://esm.sh/v135/decode-uri-component@0.2.2/denonext/decode-uri-component.mjs": "ff66ea8f8e09fab0ef177e73e5d1287a6a50685cb463b071ade77b23cd71024b", + "https://esm.sh/v135/inherits@2.0.4/denonext/inherits.mjs": "8095f3d6aea060c904fb24ae50f2882779c0acbe5d56814514c8b5153f3b4b3b", + "https://esm.sh/v135/source-map-resolve@0.6.0/denonext/source-map-resolve.mjs": "2c593f3194066ca13039c2aed83aed326c8cbfa5526221b1fd14f9e16460dd74", + "https://esm.sh/v135/source-map@0.6.1/denonext/source-map.mjs": "ccff3bb06dea7c01a2c83cf12113697592e418fd06b55ae2bb4cb0a4e51a98b8" } } diff --git a/serverside/name-color.ts b/serverside/name-color.ts index 215b23b..b6ca79e 100644 --- a/serverside/name-color.ts +++ b/serverside/name-color.ts @@ -1,13 +1,25 @@ import { DOMParser, } from "https://deno.land/x/deno_dom@v0.1.38/deno-dom-wasm.ts"; +import * as css from "https://deno.land/x/css@0.3.0/mod.ts"; + +// so, so brittle +function is_valid_color(color: string): boolean { + try { + const { stylesheet } = css.parse(`*{color:${color};}`); + return stylesheet.rules.length == 1 && + stylesheet.rules[0].declarations.length == 1; + } catch { + return false; + } +} // maybe a bit high, maybe a bit low const MAX_AGE_MS = 10 * 60 * 1000; // > "light-dark(oklab(000, 000, 000), oklab(255, 255, 255))".length // 54 -const MAX_COLOR_LEN = 64; +const MAX_COLOR_LEN = 256; const colors: Record< string, @@ -31,9 +43,14 @@ async function get_name_color(name: string): Promise { for (const p of dom.querySelectorAll("p")) { const text = p.textContent; if (text.startsWith("name-color: ")) { - return text.split("name-color: ")[1] + const color = text.split("name-color: ")[1] .slice(0, MAX_COLOR_LEN) .replaceAll(";", ""); + if (is_valid_color(color)) { + return color; + } else { + console.log(`invalid color!!!! ${color}`); + } } } } @@ -73,7 +90,6 @@ function cssify({ requester }: { requester?: string }): string { return preamble + vars + classes; } -// TODO: ONE BIG REQUEST/RESPONSE DUHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHh Deno.serve({ port: 61266 }, async (req) => { const url = new URL(req.url); const names = url.searchParams.getAll("name").filter((name) =>