{"version":3,"file":"osc52.d.ts","sourceRoot":"","sources":["../src/osc52.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,iFAAiF;AACjF,eAAO,MAAM,eAAe,QAAS,CAAC;AAEtC,wEAAwE;AACxE,wBAAgB,WAAW,CAC1B,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE;IAAE,OAAO,CAAC,EAAE,OAAO,CAAA;CAAO,GACjC;IACF,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,OAAO,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;CACd,CA+BA;AAED,4EAA4E;AAC5E,wBAAgB,UAAU,CACzB,KAAK,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,IAAI,EAC1B,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE;IAAE,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,GAC7B;IACF,SAAS,EAAE,OAAO,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;CACd,CAIA","sourcesContent":["/**\n * OSC-52 clipboard write primitive.\n *\n * The terminal-native \"set clipboard\" sequence: `\\e]52;c;<base64>\\x07`.\n * Works over SSH because it lives in the byte stream, not in any local\n * clipboard daemon. Limit comes from terminal buffer caps — most modern\n * terminals accept ~75k base64 bytes (a few MB rendered, but base64 is the\n * wire format). We truncate at 74_994 to leave headroom for the framing\n * bytes (`\\e]52;c;` + `\\x07`).\n */\n\n/** Maximum decoded character count we accept before truncation, conservative. */\nexport const OSC52_MAX_BYTES = 74_994;\n\n/** Buffers the input and returns the OSC-52 sequence ready to write. */\nexport function encodeOsc52(\n\ttext: string,\n\toptions: { primary?: boolean } = {},\n): {\n\tsequence: string;\n\ttruncated: boolean;\n\tbytes: number;\n} {\n\tconst target = options.primary ? \"p\" : \"c\";\n\tlet truncated = false;\n\tlet payload = text;\n\t// Conservative byte budget: encode and check length; if over limit, slice\n\t// the source string and re-encode. We bias toward source-character count\n\t// because most terminals advertise a base64 limit, not a character limit.\n\tlet encoded = Buffer.from(payload, \"utf8\").toString(\"base64\");\n\tif (encoded.length > OSC52_MAX_BYTES) {\n\t\ttruncated = true;\n\t\t// Find a safe character boundary that fits.\n\t\tlet lo = 0;\n\t\tlet hi = payload.length;\n\t\twhile (lo < hi) {\n\t\t\tconst mid = Math.floor((lo + hi + 1) / 2);\n\t\t\tconst candidate = payload.slice(0, mid);\n\t\t\tconst cb = Buffer.from(candidate, \"utf8\").toString(\"base64\");\n\t\t\tif (cb.length <= OSC52_MAX_BYTES) {\n\t\t\t\tlo = mid;\n\t\t\t} else {\n\t\t\t\thi = mid - 1;\n\t\t\t}\n\t\t}\n\t\tpayload = payload.slice(0, lo);\n\t\tencoded = Buffer.from(payload, \"utf8\").toString(\"base64\");\n\t}\n\treturn {\n\t\tsequence: `\\x1b]52;${target};${encoded}\\x07`,\n\t\ttruncated,\n\t\tbytes: encoded.length,\n\t};\n}\n\n/** Convenience: write the sequence with a caller-provided emit function. */\nexport function writeOsc52(\n\twrite: (s: string) => void,\n\ttext: string,\n\toptions?: { primary?: boolean },\n): {\n\ttruncated: boolean;\n\tbytes: number;\n} {\n\tconst { sequence, truncated, bytes } = encodeOsc52(text, options);\n\twrite(sequence);\n\treturn { truncated, bytes };\n}\n"]}