MCPcopy Create free account
hub / github.com/Noumena-Network/code / applyPaddingToText

Function applyPaddingToText

src/ink/render-node-to-output.ts:368–387  ·  view source on GitHub ↗
(
  node: DOMElement,
  text: string,
  softWrap?: boolean[],
)

Source from the content-addressed store, hash-verified

366// Only first node is taken into account, because other text nodes can't have margin or padding,
367// so their coordinates will be relative to the first node anyway
368function applyPaddingToText(
369 node: DOMElement,
370 text: string,
371 softWrap?: boolean[],
372): string {
373 const yogaNode = node.childNodes[0]?.yogaNode
374
375 if (yogaNode) {
376 const offsetX = yogaNode.getComputedLeft()
377 const offsetY = yogaNode.getComputedTop()
378 text = '\n'.repeat(offsetY) + indentString(text, offsetX)
379 if (softWrap && offsetY > 0) {
380 // Prepend `false` for each padding line so indices stay aligned
381 // with text.split('\n'). Mutate in place — caller owns the array.
382 softWrap.unshift(...Array<boolean>(offsetY).fill(false))
383 }
384 }
385
386 return text
387}
388
389// After nodes are laid out, render each to output object, which later gets rendered to terminal
390function renderNodeToOutput(

Callers 1

renderNodeToOutputFunction · 0.85

Calls 2

getComputedLeftMethod · 0.45
getComputedTopMethod · 0.45

Tested by

no test coverage detected