{"draft":null,"from":4,"to":318,"files":[{"path":"worker/project/unseen.ts","added":42,"removed":0,"diff":"--- /dev/null\n+++ b/worker/project/unseen.ts\n@@ -0,0 +1,42 @@\n+// Characters a reader can't see, refused in text the engine keeps and prints:\n+// version messages, starting notes, line notes and\n+// announcements. In a terminal, ESC and C1 start escape sequences that can\n+// set the clipboard or draw a fake link, so `abso log` and news must never\n+// carry them. The same list as the website's announcements and Issues.\n+\n+const UNSEEN: [number, number, string][] = [\n+\t[0x00, 0x08, \"a control character\"],\n+\t[0x0b, 0x1f, \"a control character\"],\n+\t[0x7f, 0x9f, \"a control character\"],\n+\t[0x180e, 0x180e, \"the Mongolian vowel separator (U+180E)\"],\n+\t[0x200b, 0x200f, \"a zero-width or direction mark (U+200B-200F)\"],\n+\t[0x2028, 0x2029, \"a line or paragraph separator (U+2028-2029)\"],\n+\t[0x202a, 0x202e, \"a bidirectional embedding or override (U+202A-202E)\"],\n+\t[0x2060, 0x2064, \"an invisible joiner or operator (U+2060-2064)\"],\n+\t[0x2066, 0x2069, \"a bidirectional isolate (U+2066-2069)\"],\n+\t[0xfe00, 0xfe0f, \"a variation selector (U+FE00-FE0F)\"],\n+\t[0xfeff, 0xfeff, \"a byte order mark (U+FEFF)\"],\n+\t[0xe0000, 0xe007f, \"a tag character (U+E0000-E007F)\"],\n+\t[0xe0100, 0xe01ef, \"a variation selector (U+E0100-E01EF)\"],\n+];\n+\n+/**\n+ * The first character in `text` a reader can't see, as \"<what> at character N\", or null.\n+ * \\n and \\t pass, and so does \\r before \\n, since a message file written on Windows ends its lines that way.\n+ */\n+export function unseenIn(text: string): string | null {\n+\tconst chars = [...text];\n+\tfor (const [i, ch] of chars.entries()) {\n+\t\tconst c = ch.codePointAt(0)!;\n+\t\tif (c === 0x0d && chars[i + 1] === \"\\n\") continue;\n+\t\tconst hit = UNSEEN.find(([lo, hi]) => c >= lo && c <= hi);\n+\t\tif (hit) return `${hit[2]} at character ${i + 1}`;\n+\t}\n+\treturn null;\n+}\n+\n+/** Why `text`, named `what` (\"the message\"), can't be kept, or null. */\n+export function unseenError(what: string, text: unknown): string | null {\n+\tconst hit = typeof text === \"string\" ? unseenIn(text) : null;\n+\treturn hit === null ? null : `${what} holds ${hit}, which a reader can't see; take it out`;\n+}"}],"unmatched":[]}