renderTo
Stack-safe renderer that writes this element's compact (pretty = false) or indented (pretty = true) string form as UTF-8 into out, stopping after limit characters (appending a truncation marker). Expressed with DeepRecursiveFunction so deep nesting cannot overflow the call stack; reuses the per-node prettyPrintHeader/prettyPrintTrailer/contentToString so output is unchanged for ordinary elements.
The character limit is required because in-memory String/StringBuilder are Int-bounded: the in-memory toString/prettyPrint pass MAX_RENDER_CHARS, while streaming to a kotlinx.io.Sink (the kxs-io extensions) can pass a larger value. Per-leaf content is rendered bounded (and clamped to Int) so a single huge primitive never materializes a giant transient. The limit also bounds the descent, since each header carries its own indentation and output therefore grows with depth.