const EMPTY_LINE={text:``,cursor:0};function lineOf(e){return{text:e,cursor:e.length}}function insert(e,t){return t.length===0?e:{text:e.text.slice(0,e.cursor)+t+e.text.slice(e.cursor),cursor:e.cursor+t.length}}function backspace(e){return e.cursor===0?e:{text:e.text.slice(0,e.cursor-1)+e.text.slice(e.cursor),cursor:e.cursor-1}}function deleteForward(e){return e.cursor>=e.text.length?e:{text:e.text.slice(0,e.cursor)+e.text.slice(e.cursor+1),cursor:e.cursor}}function moveLeft(e){return e.cursor===0?e:{text:e.text,cursor:e.cursor-1}}function moveRight(e){return e.cursor>=e.text.length?e:{text:e.text,cursor:e.cursor+1}}function moveHome(e){return e.cursor===0?e:{text:e.text,cursor:0}}function moveEnd(e){return e.cursor===e.text.length?e:{text:e.text,cursor:e.text.length}}function killToEnd(e){return e.cursor>=e.text.length?e:{text:e.text.slice(0,e.cursor),cursor:e.cursor}}function killToStart(e){return e.cursor===0?e:{text:e.text.slice(e.cursor),cursor:0}}function deleteWord(e){if(e.cursor===0)return e;let t=e.cursor;for(;t>0&&isWhitespace(e.text[t-1]);)--t;for(;t>0&&!isWhitespace(e.text[t-1]);)--t;return{text:e.text.slice(0,t)+e.text.slice(e.cursor),cursor:t}}function isWhitespace(e){return e!==void 0&&/\s/u.test(e)}function visibleLine(e,t,n=`…`){let r=Math.max(1,t),{text:i,cursor:a}=e;if(i.length<=r)return{before:i.slice(0,a),after:i.slice(a)};let o=a<r?0:a-r+1;o=Math.min(o,i.length-r),o=Math.max(0,o);let s=o+r,c=i.slice(o,s),l=a-o;return o>0&&l>0&&(c=n+c.slice(n.length)),s<i.length&&l<c.length&&(c=c.slice(0,c.length-n.length)+n),{before:c.slice(0,l),after:c.slice(l)}}var PromptHistory=class{#e=[];#t=0;#n=``;add(e){if(e.trim().length!==0){if(this.#e.at(-1)===e){this.#r();return}this.#e.push(e),this.#r()}}begin(e){this.#t=this.#e.length,this.#n=e}previous(e){if(this.#e.length!==0&&(this.#t===this.#e.length&&(this.#n=e),this.#t!==0))return--this.#t,this.#e[this.#t]}next(){if(!(this.#t>=this.#e.length))return this.#t+=1,this.#t===this.#e.length?this.#n:this.#e[this.#t]}#r(){this.#t=this.#e.length,this.#n=``}};export{EMPTY_LINE,PromptHistory,backspace,deleteForward,deleteWord,insert,killToEnd,killToStart,lineOf,moveEnd,moveHome,moveLeft,moveRight,visibleLine};