@xterm/addon-webgl 0.20.0-beta.196 → 0.20.0-beta.198

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -71,5 +71,5 @@ out vec4 outColor;
71
71
 
72
72
  void main() {
73
73
  outColor = v_color;
74
- }`,u0=8,Re=u0*Float32Array.BYTES_PER_ELEMENT,n1=20*u0,Le=class{constructor(){this.attributes=new Float32Array(n1),this.count=0}},c0=0,ut=0,pt=0,Qt=0,Ct=0,mt=0,ft=0,he=class extends W{constructor(t,r,n,a){super();this._terminal=t;this._gl=r;this._dimensions=n;this._themeService=a;this._vertices=new Le;this._verticesCursor=new Le;let s=this._gl;this._program=y(ae(s,r1,s1)),this._register(g(()=>s.deleteProgram(this._program))),this._projectionLocation=y(s.getUniformLocation(this._program,"u_projection")),this._vertexArrayObject=s.createVertexArray(),s.bindVertexArray(this._vertexArrayObject);let o=new Float32Array([0,0,1,0,0,1,1,1]),l=s.createBuffer();this._register(g(()=>s.deleteBuffer(l))),s.bindBuffer(s.ARRAY_BUFFER,l),s.bufferData(s.ARRAY_BUFFER,o,s.STATIC_DRAW),s.enableVertexAttribArray(3),s.vertexAttribPointer(3,2,this._gl.FLOAT,!1,0,0);let T=new Uint8Array([0,1,2,3]),h=s.createBuffer();this._register(g(()=>s.deleteBuffer(h))),s.bindBuffer(s.ELEMENT_ARRAY_BUFFER,h),s.bufferData(s.ELEMENT_ARRAY_BUFFER,T,s.STATIC_DRAW),this._attributesBuffer=y(s.createBuffer()),this._register(g(()=>s.deleteBuffer(this._attributesBuffer))),s.bindBuffer(s.ARRAY_BUFFER,this._attributesBuffer),s.enableVertexAttribArray(0),s.vertexAttribPointer(0,2,s.FLOAT,!1,Re,0),s.vertexAttribDivisor(0,1),s.enableVertexAttribArray(1),s.vertexAttribPointer(1,2,s.FLOAT,!1,Re,2*Float32Array.BYTES_PER_ELEMENT),s.vertexAttribDivisor(1,1),s.enableVertexAttribArray(2),s.vertexAttribPointer(2,4,s.FLOAT,!1,Re,4*Float32Array.BYTES_PER_ELEMENT),s.vertexAttribDivisor(2,1),this._updateCachedColors(a.colors),this._register(this._themeService.onChangeColors(d=>{this._updateCachedColors(d),this._updateViewportRectangle()}))}renderBackgrounds(){this._renderVertices(this._vertices)}renderCursor(){this._renderVertices(this._verticesCursor)}_renderVertices(t){let r=this._gl;r.useProgram(this._program),r.bindVertexArray(this._vertexArrayObject),r.uniformMatrix4fv(this._projectionLocation,!1,ne),r.bindBuffer(r.ARRAY_BUFFER,this._attributesBuffer),r.bufferData(r.ARRAY_BUFFER,t.attributes,r.DYNAMIC_DRAW),r.drawElementsInstanced(this._gl.TRIANGLE_STRIP,4,r.UNSIGNED_BYTE,0,t.count)}handleResize(){this._updateViewportRectangle()}setDimensions(t){this._dimensions=t}_updateCachedColors(t){this._bgFloat=this._colorToFloat32Array(t.background),this._cursorFloat=this._colorToFloat32Array(t.cursor)}_updateViewportRectangle(){this._addRectangleFloat(this._vertices.attributes,0,0,0,this._terminal.cols*this._dimensions.device.cell.width,this._terminal.rows*this._dimensions.device.cell.height,this._bgFloat)}updateBackgrounds(t){let r=this._terminal,n=this._vertices,a=1,s,o,l,T,h,d,_,c,u,p,C;for(s=0;s<r.rows;s++){for(l=-1,T=0,h=0,d=!1,o=0;o<r.cols;o++)_=(s*r.cols+o)*y0,c=t.cells[_+S0],u=t.cells[_+R0],p=!!(u&67108864),(c!==T||u!==h&&(d||p))&&((T!==0||d&&h!==0)&&(C=a++*u0,this._updateRectangle(n,C,h,T,l,o,s)),l=o,T=c,h=u,d=p);(T!==0||d&&h!==0)&&(C=a++*u0,this._updateRectangle(n,C,h,T,l,r.cols,s))}n.count=a}updateCursor(t){let r=this._verticesCursor,n=t.cursor;if(!n||n.style==="block"){r.count=0;return}let a,s=0;(n.style==="bar"||n.style==="outline")&&(a=s++*u0,this._addRectangleFloat(r.attributes,a,n.x*this._dimensions.device.cell.width,n.y*this._dimensions.device.cell.height,n.style==="bar"?n.dpr*n.cursorWidth:n.dpr,this._dimensions.device.cell.height,this._cursorFloat)),(n.style==="underline"||n.style==="outline")&&(a=s++*u0,this._addRectangleFloat(r.attributes,a,n.x*this._dimensions.device.cell.width,(n.y+1)*this._dimensions.device.cell.height-n.dpr,n.width*this._dimensions.device.cell.width,n.dpr,this._cursorFloat)),n.style==="outline"&&(a=s++*u0,this._addRectangleFloat(r.attributes,a,n.x*this._dimensions.device.cell.width,n.y*this._dimensions.device.cell.height,n.width*this._dimensions.device.cell.width,n.dpr,this._cursorFloat),a=s++*u0,this._addRectangleFloat(r.attributes,a,(n.x+n.width)*this._dimensions.device.cell.width-n.dpr,n.y*this._dimensions.device.cell.height,n.dpr,this._dimensions.device.cell.height,this._cursorFloat)),r.count=s}_updateRectangle(t,r,n,a,s,o,l){if(n&67108864)switch(n&50331648){case 16777216:case 33554432:c0=this._themeService.colors.ansi[n&255].rgba;break;case 50331648:c0=(n&16777215)<<8;break;case 0:default:c0=this._themeService.colors.foreground.rgba}else switch(a&50331648){case 16777216:case 33554432:c0=this._themeService.colors.ansi[a&255].rgba;break;case 50331648:c0=(a&16777215)<<8;break;case 0:default:c0=this._themeService.colors.background.rgba}t.attributes.length<r+4&&(t.attributes=dt(t.attributes,this._terminal.rows*this._terminal.cols*u0)),ut=s*this._dimensions.device.cell.width,pt=l*this._dimensions.device.cell.height,Qt=(c0>>24&255)/255,Ct=(c0>>16&255)/255,mt=(c0>>8&255)/255,ft=1,this._addRectangle(t.attributes,r,ut,pt,(o-s)*this._dimensions.device.cell.width,this._dimensions.device.cell.height,Qt,Ct,mt,ft)}_addRectangle(t,r,n,a,s,o,l,T,h,d){t[r]=n/this._dimensions.device.canvas.width,t[r+1]=a/this._dimensions.device.canvas.height,t[r+2]=s/this._dimensions.device.canvas.width,t[r+3]=o/this._dimensions.device.canvas.height,t[r+4]=l,t[r+5]=T,t[r+6]=h,t[r+7]=d}_addRectangleFloat(t,r,n,a,s,o,l){t[r]=n/this._dimensions.device.canvas.width,t[r+1]=a/this._dimensions.device.canvas.height,t[r+2]=s/this._dimensions.device.canvas.width,t[r+3]=o/this._dimensions.device.canvas.height,t[r+4]=l[0],t[r+5]=l[1],t[r+6]=l[2],t[r+7]=l[3]}_colorToFloat32Array(t){return new Float32Array([(t.rgba>>24&255)/255,(t.rgba>>16&255)/255,(t.rgba>>8&255)/255,(t.rgba&255)/255])}};var de=class extends W{constructor(t,r,n,a,s,o,l,T){super();this._container=r;this._alpha=s;this._coreBrowserService=o;this._optionsService=l;this._themeService=T;this._deviceCharWidth=0;this._deviceCharHeight=0;this._deviceCellWidth=0;this._deviceCellHeight=0;this._deviceCharLeft=0;this._deviceCharTop=0;this._canvas=this._coreBrowserService.mainDocument.createElement("canvas"),this._canvas.classList.add(`xterm-${n}-layer`),this._canvas.style.zIndex=a.toString(),this._initCanvas(),this._container.appendChild(this._canvas),this._register(this._themeService.onChangeColors(h=>{this._refreshCharAtlas(t,h),this.reset(t)})),this._register(g(()=>{this._canvas.remove()}))}_initCanvas(){this._ctx=y(this._canvas.getContext("2d",{alpha:this._alpha})),this._alpha||this._clearAll()}handleBlur(t){}handleFocus(t){}handleCursorMove(t){}handleGridChanged(t,r,n){}handleSelectionChanged(t,r,n,a=!1){}_setTransparency(t,r){if(r===this._alpha)return;let n=this._canvas;this._alpha=r,this._canvas=this._canvas.cloneNode(),this._initCanvas(),this._container.replaceChild(this._canvas,n),this._refreshCharAtlas(t,this._themeService.colors),this.handleGridChanged(t,0,t.rows-1)}_refreshCharAtlas(t,r){this._deviceCharWidth<=0&&this._deviceCharHeight<=0||(this._charAtlas=ee(t,this._optionsService.rawOptions,r,this._deviceCellWidth,this._deviceCellHeight,this._deviceCharWidth,this._deviceCharHeight,this._coreBrowserService.dpr,2048),this._charAtlas.warmUp())}resize(t,r){this._deviceCellWidth=r.device.cell.width,this._deviceCellHeight=r.device.cell.height,this._deviceCharWidth=r.device.char.width,this._deviceCharHeight=r.device.char.height,this._deviceCharLeft=r.device.char.left,this._deviceCharTop=r.device.char.top,this._canvas.width=r.device.canvas.width,this._canvas.height=r.device.canvas.height,this._canvas.style.width=`${r.css.canvas.width}px`,this._canvas.style.height=`${r.css.canvas.height}px`,this._alpha||this._clearAll(),this._refreshCharAtlas(t,this._themeService.colors)}_fillBottomLineAtCells(t,r,n=1){this._ctx.fillRect(t*this._deviceCellWidth,(r+1)*this._deviceCellHeight-this._coreBrowserService.dpr-1,n*this._deviceCellWidth,this._coreBrowserService.dpr)}_clearAll(){this._alpha?this._ctx.clearRect(0,0,this._canvas.width,this._canvas.height):(this._ctx.fillStyle=this._themeService.colors.background.css,this._ctx.fillRect(0,0,this._canvas.width,this._canvas.height))}_clearCells(t,r,n,a){this._alpha?this._ctx.clearRect(t*this._deviceCellWidth,r*this._deviceCellHeight,n*this._deviceCellWidth,a*this._deviceCellHeight):(this._ctx.fillStyle=this._themeService.colors.background.css,this._ctx.fillRect(t*this._deviceCellWidth,r*this._deviceCellHeight,n*this._deviceCellWidth,a*this._deviceCellHeight))}_fillCharTrueColor(t,r,n,a){this._ctx.font=this._getFont(t,!1,!1),this._ctx.textBaseline=q0,this._clipCell(n,a,r.getWidth()),this._ctx.fillText(r.getChars(),n*this._deviceCellWidth+this._deviceCharLeft,a*this._deviceCellHeight+this._deviceCharTop+this._deviceCharHeight)}_clipCell(t,r,n){this._ctx.beginPath(),this._ctx.rect(t*this._deviceCellWidth,r*this._deviceCellHeight,n*this._deviceCellWidth,this._deviceCellHeight),this._ctx.clip()}_getFont(t,r,n){let a=r?t.options.fontWeightBold:t.options.fontWeight;return`${n?"italic":""} ${a} ${t.options.fontSize*this._coreBrowserService.dpr}px ${t.options.fontFamily}`}};var _e=class extends de{constructor(e,t,r,n,a,s,o){super(r,e,"link",t,!0,a,s,o),this._register(n.onShowLinkUnderline(l=>this._handleShowLinkUnderline(l))),this._register(n.onHideLinkUnderline(l=>this._handleHideLinkUnderline(l)))}resize(e,t){super.resize(e,t),this._state=void 0}reset(e){this._clearCurrentLink()}_clearCurrentLink(){if(this._state){this._clearCells(this._state.x1,this._state.y1,this._state.cols-this._state.x1,1);let e=this._state.y2-this._state.y1-1;e>0&&this._clearCells(0,this._state.y1+1,this._state.cols,e),this._clearCells(0,this._state.y2,this._state.x2,1),this._state=void 0}}_handleShowLinkUnderline(e){if(e.fg===257?this._ctx.fillStyle=this._themeService.colors.background.css:e.fg!==void 0&&lt(e.fg)?this._ctx.fillStyle=this._themeService.colors.ansi[e.fg].css:this._ctx.fillStyle=this._themeService.colors.foreground.css,e.y1===e.y2)this._fillBottomLineAtCells(e.x1,e.y1,e.x2-e.x1);else{this._fillBottomLineAtCells(e.x1,e.y1,e.cols-e.x1);for(let t=e.y1+1;t<e.y2;t++)this._fillBottomLineAtCells(0,t,e.cols);this._fillBottomLineAtCells(0,e.y2,e.x2)}this._state=e}_handleHideLinkUnderline(e){this._clearCurrentLink()}};var xe=class{constructor(e,t,r,n){this._node=e,this._type=t,this._handler=r,this._options=n,e.addEventListener(t,r,n)}dispose(){!this._node||!this._handler||(this._node.removeEventListener(this._type,this._handler,this._options),this._node=null,this._handler=null)}};function ce(i,e,t,r){return new xe(i,e,t,r)}var ue=class extends W{constructor(t,r,n,a,s,o,l,T,h=!0,d){super();this._terminal=t;this._characterJoinerService=r;this._charSizeService=n;this._coreBrowserService=a;this._coreService=s;this._decorationService=o;this._optionsService=l;this._themeService=T;this._customGlyphs=h;this._cursorBlinkStateManager=new C0;this._charAtlasDisposable=this._register(new C0);this._observerDisposable=this._register(new C0);this._model=new Te;this._rowHasBlinkingCells=[];this._rowHasBlinkingCellsCount=0;this._workCell=new ie;this._rectangleRenderer=this._register(new C0);this._glyphRenderer=this._register(new C0);this._onChangeTextureAtlas=this._register(new U);this.onChangeTextureAtlas=this._onChangeTextureAtlas.event;this._onAddTextureAtlasCanvas=this._register(new U);this.onAddTextureAtlasCanvas=this._onAddTextureAtlasCanvas.event;this._onRemoveTextureAtlasCanvas=this._register(new U);this.onRemoveTextureAtlasCanvas=this._onRemoveTextureAtlasCanvas.event;this._onRequestRedraw=this._register(new U);this.onRequestRedraw=this._onRequestRedraw.event;this._onContextLoss=this._register(new U);this.onContextLoss=this._onContextLoss.event;this._canvas=this._coreBrowserService.mainDocument.createElement("canvas");let _={antialias:!1,depth:!1,preserveDrawingBuffer:d};if(this._gl=this._canvas.getContext("webgl2",_),!this._gl)throw new Error("WebGL2 not supported "+this._gl);this._register(this._themeService.onChangeColors(()=>this._handleColorChange())),this._cellColorResolver=new Y0(this._terminal,this._optionsService,this._model.selection,this._decorationService,this._coreBrowserService,this._themeService),this._core=this._terminal._core,this._renderLayers=[new _e(this._core.screenElement,2,this._terminal,this._core.linkifier,this._coreBrowserService,l,this._themeService)],this.dimensions=Ke(),this._devicePixelRatio=this._coreBrowserService.dpr,this._updateDimensions(),this._updateCursorBlink(),this._register(l.onOptionChange(()=>this._handleOptionsChanged())),this._textBlinkStateManager=this._register(new re(()=>this._requestRedrawViewport(),this._coreBrowserService,this._optionsService)),this._resetBlinkingRowState(),this._deviceMaxTextureSize=this._gl.getParameter(this._gl.MAX_TEXTURE_SIZE),this._register(ce(this._canvas,"webglcontextlost",c=>{console.log("webglcontextlost event received"),c.preventDefault(),this._contextRestorationTimeout=setTimeout(()=>{this._contextRestorationTimeout=void 0,console.warn("webgl context not restored; firing onContextLoss"),this._onContextLoss.fire(c)},3e3)})),this._register(ce(this._canvas,"webglcontextrestored",c=>{console.warn("webglcontextrestored event received"),clearTimeout(this._contextRestorationTimeout),this._contextRestorationTimeout=void 0,Me(this._terminal),this._initializeWebGLState(),this._requestRedrawViewport()})),this._observerDisposable.value=Ae(this._canvas,this._coreBrowserService.window,(c,u)=>this._setCanvasDevicePixelDimensions(c,u)),this._register(this._coreBrowserService.onWindowChange(c=>{this._observerDisposable.value=Ae(this._canvas,c,(u,p)=>this._setCanvasDevicePixelDimensions(u,p))})),this._register(ce(this._coreBrowserService.mainDocument,"mousedown",()=>this._cursorBlinkStateManager.value?.restartBlinkAnimation())),this._core.screenElement.appendChild(this._canvas),[this._rectangleRenderer.value,this._glyphRenderer.value]=this._initializeWebGLState(),this._isAttached=this._core.screenElement.isConnected,this._register(g(()=>{for(let c of this._renderLayers)c.dispose();this._canvas.parentElement?.removeChild(this._canvas),Me(this._terminal)}))}get textureAtlas(){return this._charAtlas?.pages[0].canvas}_handleColorChange(){this._refreshCharAtlas(),this._clearModel(!0)}handleDevicePixelRatioChange(){this._devicePixelRatio!==this._coreBrowserService.dpr&&(this._devicePixelRatio=this._coreBrowserService.dpr,this.handleResize(this._terminal.cols,this._terminal.rows))}handleResize(t,r){this._updateDimensions(),this._model.resize(this._terminal.cols,this._terminal.rows),this._resetBlinkingRowState();for(let n of this._renderLayers)n.resize(this._terminal,this.dimensions);this._canvas.width=this.dimensions.device.canvas.width,this._canvas.height=this.dimensions.device.canvas.height,this._canvas.style.width=`${this.dimensions.css.canvas.width}px`,this._canvas.style.height=`${this.dimensions.css.canvas.height}px`,this._core.screenElement.style.width=`${this.dimensions.css.canvas.width}px`,this._core.screenElement.style.height=`${this.dimensions.css.canvas.height}px`,this._rectangleRenderer.value?.setDimensions(this.dimensions),this._rectangleRenderer.value?.handleResize(),this._glyphRenderer.value?.setDimensions(this.dimensions),this._glyphRenderer.value?.handleResize(),this._refreshCharAtlas(),this._clearModel(!1),this._onRequestRedraw.fire({start:0,end:this._terminal.rows-1,sync:!0})}handleCharSizeChanged(){this.handleResize(this._terminal.cols,this._terminal.rows)}handleBlur(){for(let t of this._renderLayers)t.handleBlur(this._terminal);this._cursorBlinkStateManager.value?.pause(),this._requestRedrawViewport()}handleFocus(){for(let t of this._renderLayers)t.handleFocus(this._terminal);this._cursorBlinkStateManager.value?.resume(),this._requestRedrawViewport()}handleViewportVisibilityChange(t){this._textBlinkStateManager.setViewportVisible(t)}handleSelectionChanged(t,r,n){for(let a of this._renderLayers)a.handleSelectionChanged(this._terminal,t,r,n);this._model.selection.update(this._core,t,r,n),this._requestRedrawViewport()}handleCursorMove(){for(let t of this._renderLayers)t.handleCursorMove(this._terminal);this._cursorBlinkStateManager.value?.restartBlinkAnimation()}_handleOptionsChanged(){this._updateDimensions(),this._refreshCharAtlas(),this._updateCursorBlink()}_initializeWebGLState(){return this._rectangleRenderer.value=new he(this._terminal,this._gl,this.dimensions,this._themeService),this._glyphRenderer.value=new oe(this._terminal,this._gl,this.dimensions,this._optionsService),this.handleCharSizeChanged(),[this._rectangleRenderer.value,this._glyphRenderer.value]}_refreshCharAtlas(){if(this.dimensions.device.char.width<=0&&this.dimensions.device.char.height<=0){this._isAttached=!1;return}let t=ee(this._terminal,this._optionsService.rawOptions,this._themeService.colors,this.dimensions.device.cell.width,this.dimensions.device.cell.height,this.dimensions.device.char.width,this.dimensions.device.char.height,this._coreBrowserService.dpr,this._deviceMaxTextureSize,this._customGlyphs);this._charAtlas!==t&&(this._onChangeTextureAtlas.fire(t.pages[0].canvas),this._charAtlasDisposable.value=ke(_0.forward(t.onAddTextureAtlasCanvas,this._onAddTextureAtlasCanvas),_0.forward(t.onRemoveTextureAtlasCanvas,this._onRemoveTextureAtlasCanvas))),this._charAtlas=t,this._charAtlas.warmUp(),this._glyphRenderer.value?.setAtlas(this._charAtlas)}_clearModel(t){this._model.clear(),t&&this._glyphRenderer.value?.clear()}clearTextureAtlas(){this._charAtlas?.clearTexture(),this._clearModel(!0),this._requestRedrawViewport()}clear(){this._clearModel(!0);for(let t of this._renderLayers)t.reset(this._terminal);this._resetBlinkingRowState(),this._textBlinkStateManager.setNeedsBlinkInViewport(!1),this._cursorBlinkStateManager.value?.restartBlinkAnimation(),this._updateCursorBlink()}renderRows(t,r){if(!this._isAttached)if(this._core.screenElement?.isConnected&&this._charSizeService.width&&this._charSizeService.height)this._updateDimensions(),this._refreshCharAtlas(),this._isAttached=!0;else return;for(let n of this._renderLayers)n.handleGridChanged(this._terminal,t,r);!this._glyphRenderer.value||!this._rectangleRenderer.value||(this._glyphRenderer.value.beginFrame()?(this._clearModel(!0),this._updateModel(0,this._terminal.rows-1)):this._updateModel(t,r),this._rectangleRenderer.value.renderBackgrounds(),this._glyphRenderer.value.render(this._model),(!this._cursorBlinkStateManager.value||this._cursorBlinkStateManager.value.isCursorVisible)&&this._rectangleRenderer.value.renderCursor())}_updateCursorBlink(){this._coreService.decPrivateModes.cursorBlink??this._terminal.options.cursorBlink?this._cursorBlinkStateManager.value=new te(()=>{this._requestRedrawCursor()},this._coreBrowserService):this._cursorBlinkStateManager.clear(),this._requestRedrawCursor()}_updateModel(t,r){let n=this._core,a=this._workCell,s,o,l,T,h,d,_=0,c=!0,u,p,C,Q,m,R,F,b,A;t=Et(t,n.rows-1,0),r=Et(r,n.rows-1,0);let X=this._coreService.decPrivateModes.cursorStyle??n.options.cursorStyle??"block",z=this._terminal.buffer.active.baseY+this._terminal.buffer.active.cursorY,x0=z-n.buffer.ydisp,e0=Math.min(this._terminal.buffer.active.cursorX,n.cols-1),T0=-1,M=this._coreService.isCursorInitialized&&!this._coreService.isCursorHidden&&(!this._cursorBlinkStateManager.value||this._cursorBlinkStateManager.value.isCursorVisible);this._model.cursor=void 0;let l0=!1;for(o=t;o<=r;o++){l=o+n.buffer.ydisp,T=n.buffer.lines.get(l);let t0=!1;for(this._model.lineLengths[o]=0,C=z===l,_=0,h=this._characterJoinerService.getJoinedCharacters(l),b=0;b<n.cols;b++){if(s=this._cellColorResolver.result.bg,T.loadCell(b,a),b===0&&(s=this._cellColorResolver.result.bg),d=!1,c=b>=_,u=b,h.length>0&&b===h[0][0]&&c){p=h.shift();let Y=this._model.selection.isCellSelected(this._terminal,p[0],l);for(F=p[0]+1;F<p[1];F++)c&&=Y===this._model.selection.isCellSelected(this._terminal,F,l);c&&=!C||e0<p[0]||e0>=p[1],c?(d=!0,a=new De(a,T.translateToString(!0,p[0],p[1]),p[1]-p[0]),u=p[1]-1):_=p[1]}if(Q=a.getChars(),m=a.getCode(),F=(o*n.cols+b)*y0,!t0&&a.isBlink()&&(t0=!0),this._cellColorResolver.resolve(a,b,l,this.dimensions.device.cell.width,this.dimensions.device.cell.height),M&&l===z&&(b===e0&&(this._model.cursor={x:e0,y:x0,width:a.getWidth(),style:this._coreBrowserService.isFocused?X:n.options.cursorInactiveStyle,cursorWidth:n.options.cursorWidth,dpr:this._devicePixelRatio},T0=e0+a.getWidth()-1),b>=e0&&b<=T0&&(this._coreBrowserService.isFocused&&X==="block"||this._coreBrowserService.isFocused===!1&&n.options.cursorInactiveStyle==="block")&&(this._cellColorResolver.result.fg=50331648|this._themeService.colors.cursorAccent.rgba>>8&16777215,this._cellColorResolver.result.bg=50331648|this._themeService.colors.cursor.rgba>>8&16777215)),this._textBlinkStateManager.isEnabled&&!this._textBlinkStateManager.isBlinkOn&&a.isBlink()&&(this._cellColorResolver.result.fg|=1073741824),m!==0&&(this._model.lineLengths[o]=b+1),!(this._model.cells[F]===m&&this._model.cells[F+S0]===this._cellColorResolver.result.bg&&this._model.cells[F+R0]===this._cellColorResolver.result.fg&&this._model.cells[F+le]===this._cellColorResolver.result.ext)&&(l0=!0,Q.length>1&&(m|=ct),this._model.cells[F]=m,this._model.cells[F+S0]=this._cellColorResolver.result.bg,this._model.cells[F+R0]=this._cellColorResolver.result.fg,this._model.cells[F+le]=this._cellColorResolver.result.ext,R=a.getWidth(),this._glyphRenderer.value.updateCell(b,o,m,this._cellColorResolver.result.bg,this._cellColorResolver.result.fg,this._cellColorResolver.result.ext,Q,R,s),d)){for(a=this._workCell,b++;b<=u;b++)A=(o*n.cols+b)*y0,this._glyphRenderer.value.updateCell(b,o,0,0,0,0,"",0,0),this._model.cells[A]=0,this._model.cells[A+S0]=this._cellColorResolver.result.bg,this._model.cells[A+R0]=this._cellColorResolver.result.fg,this._model.cells[A+le]=this._cellColorResolver.result.ext;b--}}this._setRowBlinkState(o,t0)}l0&&this._rectangleRenderer.value.updateBackgrounds(this._model),this._rectangleRenderer.value.updateCursor(this._model),this._updateTextBlinkState()}_resetBlinkingRowState(){this._rowHasBlinkingCells=new Array(this._terminal.rows).fill(!1),this._rowHasBlinkingCellsCount=0}_setRowBlinkState(t,r){this._rowHasBlinkingCells[t]!==r&&(this._rowHasBlinkingCells[t]=r,this._rowHasBlinkingCellsCount+=r?1:-1)}_updateTextBlinkState(){this._textBlinkStateManager.setNeedsBlinkInViewport(this._rowHasBlinkingCellsCount>0)}_updateDimensions(){!this._charSizeService.width||!this._charSizeService.height||(this.dimensions.device.char.width=Math.floor(this._charSizeService.width*this._devicePixelRatio),this.dimensions.device.char.height=Math.ceil(this._charSizeService.height*this._devicePixelRatio),this.dimensions.device.cell.height=Math.floor(this.dimensions.device.char.height*this._optionsService.rawOptions.lineHeight),this.dimensions.device.char.top=this._optionsService.rawOptions.lineHeight===1?0:Math.round((this.dimensions.device.cell.height-this.dimensions.device.char.height)/2),this.dimensions.device.cell.width=this.dimensions.device.char.width+Math.round(this._optionsService.rawOptions.letterSpacing),this.dimensions.device.char.left=Math.floor(this._optionsService.rawOptions.letterSpacing/2),this.dimensions.device.canvas.height=this._terminal.rows*this.dimensions.device.cell.height,this.dimensions.device.canvas.width=this._terminal.cols*this.dimensions.device.cell.width,this.dimensions.css.canvas.height=Math.round(this.dimensions.device.canvas.height/this._devicePixelRatio),this.dimensions.css.canvas.width=Math.round(this.dimensions.device.canvas.width/this._devicePixelRatio),this.dimensions.css.cell.height=this.dimensions.device.cell.height/this._devicePixelRatio,this.dimensions.css.cell.width=this.dimensions.device.cell.width/this._devicePixelRatio)}_setCanvasDevicePixelDimensions(t,r){this._canvas.width===t&&this._canvas.height===r||(this._canvas.width=t,this._canvas.height=r,this._onRequestRedraw.fire({start:0,end:this._terminal.rows-1,sync:!0}))}_requestRedrawViewport(){this._onRequestRedraw.fire({start:0,end:this._terminal.rows-1})}_requestRedrawCursor(){let t=this._terminal.buffer.active.cursorY;this._onRequestRedraw.fire({start:t,end:t})}},De=class extends s0{constructor(t,r,n){super();this.content=0;this.combinedData="";this.fg=t.fg,this.bg=t.bg,this.combinedData=r,this._width=n}isCombined(){return 2097152}getWidth(){return this._width}getChars(){return this.combinedData}getCode(){return 2097151}setFromCharData(t){throw new Error("not implemented")}getAsCharData(){return[this.fg,this.getChars(),this.getWidth(),this.getCode()]}};function Et(i,e,t=0){return Math.max(Math.min(i,e),t)}var bt=class extends W{constructor(t){if(fe&&Ve()<16){let r={antialias:!1,depth:!1,preserveDrawingBuffer:!0};if(!document.createElement("canvas").getContext("webgl2",r))throw new Error("Webgl2 is only supported on Safari 16 and above")}super();this._onChangeTextureAtlas=this._register(new U);this.onChangeTextureAtlas=this._onChangeTextureAtlas.event;this._onAddTextureAtlasCanvas=this._register(new U);this.onAddTextureAtlasCanvas=this._onAddTextureAtlasCanvas.event;this._onRemoveTextureAtlasCanvas=this._register(new U);this.onRemoveTextureAtlasCanvas=this._onRemoveTextureAtlasCanvas.event;this._onContextLoss=this._register(new U);this.onContextLoss=this._onContextLoss.event;this._customGlyphs=t?.customGlyphs??!0,this._preserveDrawingBuffer=t?.preserveDrawingBuffer}activate(t){let r=t._core;if(!t.element){this._register(r.onWillOpen(()=>this.activate(t)));return}this._terminal=t;let n=r.coreService,a=r.optionsService,s=r,o=s._renderService,l=s._characterJoinerService,T=s._charSizeService,h=s._coreBrowserService,d=s._decorationService,_=s._themeService;this._renderer=this._register(new ue(t,l,T,h,n,d,a,_,this._customGlyphs,this._preserveDrawingBuffer)),this._register(_0.forward(this._renderer.onContextLoss,this._onContextLoss)),this._register(_0.forward(this._renderer.onChangeTextureAtlas,this._onChangeTextureAtlas)),this._register(_0.forward(this._renderer.onAddTextureAtlasCanvas,this._onAddTextureAtlasCanvas)),this._register(_0.forward(this._renderer.onRemoveTextureAtlasCanvas,this._onRemoveTextureAtlasCanvas)),o.setRenderer(this._renderer),this._register(g(()=>{if(this._terminal._core._store._isDisposed)return;let c=this._terminal._core._renderService;c.setRenderer(this._terminal._core._createRenderer()),c.handleResize(t.cols,t.rows)}))}get textureAtlas(){return this._renderer?.textureAtlas}clearTextureAtlas(){this._renderer?.clearTextureAtlas()}};export{bt as WebglAddon};
74
+ }`,u0=8,Re=u0*Float32Array.BYTES_PER_ELEMENT,n1=20*u0,Le=class{constructor(){this.attributes=new Float32Array(n1),this.count=0}},c0=0,ut=0,pt=0,Qt=0,Ct=0,mt=0,ft=0,he=class extends W{constructor(t,r,n,a){super();this._terminal=t;this._gl=r;this._dimensions=n;this._themeService=a;this._vertices=new Le;this._verticesCursor=new Le;let s=this._gl;this._program=y(ae(s,r1,s1)),this._register(g(()=>s.deleteProgram(this._program))),this._projectionLocation=y(s.getUniformLocation(this._program,"u_projection")),this._vertexArrayObject=s.createVertexArray(),s.bindVertexArray(this._vertexArrayObject);let o=new Float32Array([0,0,1,0,0,1,1,1]),l=s.createBuffer();this._register(g(()=>s.deleteBuffer(l))),s.bindBuffer(s.ARRAY_BUFFER,l),s.bufferData(s.ARRAY_BUFFER,o,s.STATIC_DRAW),s.enableVertexAttribArray(3),s.vertexAttribPointer(3,2,this._gl.FLOAT,!1,0,0);let T=new Uint8Array([0,1,2,3]),h=s.createBuffer();this._register(g(()=>s.deleteBuffer(h))),s.bindBuffer(s.ELEMENT_ARRAY_BUFFER,h),s.bufferData(s.ELEMENT_ARRAY_BUFFER,T,s.STATIC_DRAW),this._attributesBuffer=y(s.createBuffer()),this._register(g(()=>s.deleteBuffer(this._attributesBuffer))),s.bindBuffer(s.ARRAY_BUFFER,this._attributesBuffer),s.enableVertexAttribArray(0),s.vertexAttribPointer(0,2,s.FLOAT,!1,Re,0),s.vertexAttribDivisor(0,1),s.enableVertexAttribArray(1),s.vertexAttribPointer(1,2,s.FLOAT,!1,Re,2*Float32Array.BYTES_PER_ELEMENT),s.vertexAttribDivisor(1,1),s.enableVertexAttribArray(2),s.vertexAttribPointer(2,4,s.FLOAT,!1,Re,4*Float32Array.BYTES_PER_ELEMENT),s.vertexAttribDivisor(2,1),this._updateCachedColors(a.colors),this._register(this._themeService.onChangeColors(d=>{this._updateCachedColors(d),this._updateViewportRectangle()}))}renderBackgrounds(){this._renderVertices(this._vertices)}renderCursor(){this._renderVertices(this._verticesCursor)}_renderVertices(t){let r=this._gl;r.useProgram(this._program),r.bindVertexArray(this._vertexArrayObject),r.uniformMatrix4fv(this._projectionLocation,!1,ne),r.bindBuffer(r.ARRAY_BUFFER,this._attributesBuffer),r.bufferData(r.ARRAY_BUFFER,t.attributes,r.DYNAMIC_DRAW),r.drawElementsInstanced(this._gl.TRIANGLE_STRIP,4,r.UNSIGNED_BYTE,0,t.count)}handleResize(){this._updateViewportRectangle()}setDimensions(t){this._dimensions=t}_updateCachedColors(t){this._bgFloat=this._colorToFloat32Array(t.background),this._cursorFloat=this._colorToFloat32Array(t.cursor)}_updateViewportRectangle(){this._addRectangleFloat(this._vertices.attributes,0,0,0,this._terminal.cols*this._dimensions.device.cell.width,this._terminal.rows*this._dimensions.device.cell.height,this._bgFloat)}updateBackgrounds(t){let r=this._terminal,n=this._vertices,a=1,s,o,l,T,h,d,_,c,u,p,C;for(s=0;s<r.rows;s++){for(l=-1,T=0,h=0,d=!1,o=0;o<r.cols;o++)_=(s*r.cols+o)*y0,c=t.cells[_+S0],u=t.cells[_+R0],p=!!(u&67108864),(c!==T||u!==h&&(d||p))&&((T!==0||d&&h!==0)&&(C=a++*u0,this._updateRectangle(n,C,h,T,l,o,s)),l=o,T=c,h=u,d=p);(T!==0||d&&h!==0)&&(C=a++*u0,this._updateRectangle(n,C,h,T,l,r.cols,s))}n.count=a}updateCursor(t){let r=this._verticesCursor,n=t.cursor;if(!n||n.style==="block"){r.count=0;return}let a,s=0;(n.style==="bar"||n.style==="outline")&&(a=s++*u0,this._addRectangleFloat(r.attributes,a,n.x*this._dimensions.device.cell.width,n.y*this._dimensions.device.cell.height,n.style==="bar"?n.dpr*n.cursorWidth:n.dpr,this._dimensions.device.cell.height,this._cursorFloat)),(n.style==="underline"||n.style==="outline")&&(a=s++*u0,this._addRectangleFloat(r.attributes,a,n.x*this._dimensions.device.cell.width,(n.y+1)*this._dimensions.device.cell.height-n.dpr,n.width*this._dimensions.device.cell.width,n.dpr,this._cursorFloat)),n.style==="outline"&&(a=s++*u0,this._addRectangleFloat(r.attributes,a,n.x*this._dimensions.device.cell.width,n.y*this._dimensions.device.cell.height,n.width*this._dimensions.device.cell.width,n.dpr,this._cursorFloat),a=s++*u0,this._addRectangleFloat(r.attributes,a,(n.x+n.width)*this._dimensions.device.cell.width-n.dpr,n.y*this._dimensions.device.cell.height,n.dpr,this._dimensions.device.cell.height,this._cursorFloat)),r.count=s}_updateRectangle(t,r,n,a,s,o,l){if(n&67108864)switch(n&50331648){case 16777216:case 33554432:c0=this._themeService.colors.ansi[n&255].rgba;break;case 50331648:c0=(n&16777215)<<8;break;case 0:default:c0=this._themeService.colors.foreground.rgba}else switch(a&50331648){case 16777216:case 33554432:c0=this._themeService.colors.ansi[a&255].rgba;break;case 50331648:c0=(a&16777215)<<8;break;case 0:default:c0=this._themeService.colors.background.rgba}t.attributes.length<r+4&&(t.attributes=dt(t.attributes,this._terminal.rows*this._terminal.cols*u0)),ut=s*this._dimensions.device.cell.width,pt=l*this._dimensions.device.cell.height,Qt=(c0>>24&255)/255,Ct=(c0>>16&255)/255,mt=(c0>>8&255)/255,ft=1,this._addRectangle(t.attributes,r,ut,pt,(o-s)*this._dimensions.device.cell.width,this._dimensions.device.cell.height,Qt,Ct,mt,ft)}_addRectangle(t,r,n,a,s,o,l,T,h,d){t[r]=n/this._dimensions.device.canvas.width,t[r+1]=a/this._dimensions.device.canvas.height,t[r+2]=s/this._dimensions.device.canvas.width,t[r+3]=o/this._dimensions.device.canvas.height,t[r+4]=l,t[r+5]=T,t[r+6]=h,t[r+7]=d}_addRectangleFloat(t,r,n,a,s,o,l){t[r]=n/this._dimensions.device.canvas.width,t[r+1]=a/this._dimensions.device.canvas.height,t[r+2]=s/this._dimensions.device.canvas.width,t[r+3]=o/this._dimensions.device.canvas.height,t[r+4]=l[0],t[r+5]=l[1],t[r+6]=l[2],t[r+7]=l[3]}_colorToFloat32Array(t){return new Float32Array([(t.rgba>>24&255)/255,(t.rgba>>16&255)/255,(t.rgba>>8&255)/255,(t.rgba&255)/255])}};var de=class extends W{constructor(t,r,n,a,s,o,l,T){super();this._container=r;this._alpha=s;this._coreBrowserService=o;this._optionsService=l;this._themeService=T;this._deviceCharWidth=0;this._deviceCharHeight=0;this._deviceCellWidth=0;this._deviceCellHeight=0;this._deviceCharLeft=0;this._deviceCharTop=0;this._canvas=this._coreBrowserService.mainDocument.createElement("canvas"),this._canvas.classList.add(`xterm-${n}-layer`),this._canvas.style.zIndex=a.toString(),this._initCanvas(),this._container.appendChild(this._canvas),this._register(this._themeService.onChangeColors(h=>{this._refreshCharAtlas(t,h),this.reset(t)})),this._register(g(()=>{this._canvas.remove()}))}_initCanvas(){this._ctx=y(this._canvas.getContext("2d",{alpha:this._alpha})),this._alpha||this._clearAll()}handleBlur(t){}handleFocus(t){}handleCursorMove(t){}handleGridChanged(t,r,n){}handleSelectionChanged(t,r,n,a=!1){}_setTransparency(t,r){if(r===this._alpha)return;let n=this._canvas;this._alpha=r,this._canvas=this._canvas.cloneNode(),this._initCanvas(),this._container.replaceChild(this._canvas,n),this._refreshCharAtlas(t,this._themeService.colors),this.handleGridChanged(t,0,t.rows-1)}_refreshCharAtlas(t,r){this._deviceCharWidth<=0&&this._deviceCharHeight<=0||(this._charAtlas=ee(t,this._optionsService.rawOptions,r,this._deviceCellWidth,this._deviceCellHeight,this._deviceCharWidth,this._deviceCharHeight,this._coreBrowserService.dpr,2048),this._charAtlas.warmUp())}resize(t,r){this._deviceCellWidth=r.device.cell.width,this._deviceCellHeight=r.device.cell.height,this._deviceCharWidth=r.device.char.width,this._deviceCharHeight=r.device.char.height,this._deviceCharLeft=r.device.char.left,this._deviceCharTop=r.device.char.top,this._canvas.width=r.device.canvas.width,this._canvas.height=r.device.canvas.height,this._canvas.style.width=`${r.css.canvas.width}px`,this._canvas.style.height=`${r.css.canvas.height}px`,this._alpha||this._clearAll(),this._refreshCharAtlas(t,this._themeService.colors)}_fillBottomLineAtCells(t,r,n=1){this._ctx.fillRect(t*this._deviceCellWidth,(r+1)*this._deviceCellHeight-this._coreBrowserService.dpr-1,n*this._deviceCellWidth,this._coreBrowserService.dpr)}_clearAll(){this._alpha?this._ctx.clearRect(0,0,this._canvas.width,this._canvas.height):(this._ctx.fillStyle=this._themeService.colors.background.css,this._ctx.fillRect(0,0,this._canvas.width,this._canvas.height))}_clearCells(t,r,n,a){this._alpha?this._ctx.clearRect(t*this._deviceCellWidth,r*this._deviceCellHeight,n*this._deviceCellWidth,a*this._deviceCellHeight):(this._ctx.fillStyle=this._themeService.colors.background.css,this._ctx.fillRect(t*this._deviceCellWidth,r*this._deviceCellHeight,n*this._deviceCellWidth,a*this._deviceCellHeight))}_fillCharTrueColor(t,r,n,a){this._ctx.font=this._getFont(t,!1,!1),this._ctx.textBaseline=q0,this._clipCell(n,a,r.getWidth()),this._ctx.fillText(r.getChars(),n*this._deviceCellWidth+this._deviceCharLeft,a*this._deviceCellHeight+this._deviceCharTop+this._deviceCharHeight)}_clipCell(t,r,n){this._ctx.beginPath(),this._ctx.rect(t*this._deviceCellWidth,r*this._deviceCellHeight,n*this._deviceCellWidth,this._deviceCellHeight),this._ctx.clip()}_getFont(t,r,n){let a=r?t.options.fontWeightBold:t.options.fontWeight;return`${n?"italic":""} ${a} ${t.options.fontSize*this._coreBrowserService.dpr}px ${t.options.fontFamily}`}};var _e=class extends de{constructor(e,t,r,n,a,s,o){super(r,e,"link",t,!0,a,s,o),this._register(n.onShowLinkUnderline(l=>this._handleShowLinkUnderline(l))),this._register(n.onHideLinkUnderline(l=>this._handleHideLinkUnderline(l)))}resize(e,t){super.resize(e,t),this._state=void 0}reset(e){this._clearCurrentLink()}_clearCurrentLink(){if(this._state){this._clearCells(this._state.x1,this._state.y1,this._state.cols-this._state.x1,1);let e=this._state.y2-this._state.y1-1;e>0&&this._clearCells(0,this._state.y1+1,this._state.cols,e),this._clearCells(0,this._state.y2,this._state.x2,1),this._state=void 0}}_handleShowLinkUnderline(e){if(e.fg===257?this._ctx.fillStyle=this._themeService.colors.background.css:e.fg!==void 0&&lt(e.fg)?this._ctx.fillStyle=this._themeService.colors.ansi[e.fg].css:this._ctx.fillStyle=this._themeService.colors.foreground.css,e.y1===e.y2)this._fillBottomLineAtCells(e.x1,e.y1,e.x2-e.x1);else{this._fillBottomLineAtCells(e.x1,e.y1,e.cols-e.x1);for(let t=e.y1+1;t<e.y2;t++)this._fillBottomLineAtCells(0,t,e.cols);this._fillBottomLineAtCells(0,e.y2,e.x2)}this._state=e}_handleHideLinkUnderline(e){this._clearCurrentLink()}};var xe=class{constructor(e,t,r,n){this._node=e,this._type=t,this._handler=r,this._options=n,e.addEventListener(t,r,n)}dispose(){!this._node||!this._handler||(this._node.removeEventListener(this._type,this._handler,this._options),this._node=null,this._handler=null)}};function ce(i,e,t,r){return new xe(i,e,t,r)}var ue=class extends W{constructor(t,r,n,a,s,o,l,T,h=!0,d){super();this._terminal=t;this._characterJoinerService=r;this._charSizeService=n;this._coreBrowserService=a;this._coreService=s;this._decorationService=o;this._optionsService=l;this._themeService=T;this._customGlyphs=h;this._cursorBlinkStateManager=this._register(new C0);this._charAtlasDisposable=this._register(new C0);this._observerDisposable=this._register(new C0);this._model=new Te;this._rowHasBlinkingCells=[];this._rowHasBlinkingCellsCount=0;this._workCell=new ie;this._rectangleRenderer=this._register(new C0);this._glyphRenderer=this._register(new C0);this._onChangeTextureAtlas=this._register(new U);this.onChangeTextureAtlas=this._onChangeTextureAtlas.event;this._onAddTextureAtlasCanvas=this._register(new U);this.onAddTextureAtlasCanvas=this._onAddTextureAtlasCanvas.event;this._onRemoveTextureAtlasCanvas=this._register(new U);this.onRemoveTextureAtlasCanvas=this._onRemoveTextureAtlasCanvas.event;this._onRequestRedraw=this._register(new U);this.onRequestRedraw=this._onRequestRedraw.event;this._onContextLoss=this._register(new U);this.onContextLoss=this._onContextLoss.event;this._canvas=this._coreBrowserService.mainDocument.createElement("canvas");let _={antialias:!1,depth:!1,preserveDrawingBuffer:d};if(this._gl=this._canvas.getContext("webgl2",_),!this._gl)throw new Error("WebGL2 not supported "+this._gl);this._register(this._themeService.onChangeColors(()=>this._handleColorChange())),this._cellColorResolver=new Y0(this._terminal,this._optionsService,this._model.selection,this._decorationService,this._coreBrowserService,this._themeService),this._core=this._terminal._core,this._renderLayers=[new _e(this._core.screenElement,2,this._terminal,this._core.linkifier,this._coreBrowserService,l,this._themeService)],this.dimensions=Ke(),this._devicePixelRatio=this._coreBrowserService.dpr,this._updateDimensions(),this._updateCursorBlink(),this._register(l.onOptionChange(()=>this._handleOptionsChanged())),this._textBlinkStateManager=this._register(new re(()=>this._requestRedrawViewport(),this._coreBrowserService,this._optionsService)),this._resetBlinkingRowState(),this._deviceMaxTextureSize=this._gl.getParameter(this._gl.MAX_TEXTURE_SIZE),this._register(ce(this._canvas,"webglcontextlost",c=>{console.log("webglcontextlost event received"),c.preventDefault(),this._contextRestorationTimeout=setTimeout(()=>{this._contextRestorationTimeout=void 0,console.warn("webgl context not restored; firing onContextLoss"),this._onContextLoss.fire(c)},3e3)})),this._register(ce(this._canvas,"webglcontextrestored",c=>{console.warn("webglcontextrestored event received"),clearTimeout(this._contextRestorationTimeout),this._contextRestorationTimeout=void 0,Me(this._terminal),this._initializeWebGLState(),this._requestRedrawViewport()})),this._observerDisposable.value=Ae(this._canvas,this._coreBrowserService.window,(c,u)=>this._setCanvasDevicePixelDimensions(c,u)),this._register(this._coreBrowserService.onWindowChange(c=>{this._observerDisposable.value=Ae(this._canvas,c,(u,p)=>this._setCanvasDevicePixelDimensions(u,p))})),this._register(ce(this._coreBrowserService.mainDocument,"mousedown",()=>this._cursorBlinkStateManager.value?.restartBlinkAnimation())),this._core.screenElement.appendChild(this._canvas),[this._rectangleRenderer.value,this._glyphRenderer.value]=this._initializeWebGLState(),this._isAttached=this._core.screenElement.isConnected,this._register(g(()=>{for(let c of this._renderLayers)c.dispose();this._canvas.parentElement?.removeChild(this._canvas),Me(this._terminal)}))}get textureAtlas(){return this._charAtlas?.pages[0].canvas}_handleColorChange(){this._refreshCharAtlas(),this._clearModel(!0)}handleDevicePixelRatioChange(){this._devicePixelRatio!==this._coreBrowserService.dpr&&(this._devicePixelRatio=this._coreBrowserService.dpr,this.handleResize(this._terminal.cols,this._terminal.rows))}handleResize(t,r){this._updateDimensions(),this._model.resize(this._terminal.cols,this._terminal.rows),this._resetBlinkingRowState();for(let n of this._renderLayers)n.resize(this._terminal,this.dimensions);this._canvas.width=this.dimensions.device.canvas.width,this._canvas.height=this.dimensions.device.canvas.height,this._canvas.style.width=`${this.dimensions.css.canvas.width}px`,this._canvas.style.height=`${this.dimensions.css.canvas.height}px`,this._core.screenElement.style.width=`${this.dimensions.css.canvas.width}px`,this._core.screenElement.style.height=`${this.dimensions.css.canvas.height}px`,this._rectangleRenderer.value?.setDimensions(this.dimensions),this._rectangleRenderer.value?.handleResize(),this._glyphRenderer.value?.setDimensions(this.dimensions),this._glyphRenderer.value?.handleResize(),this._refreshCharAtlas(),this._clearModel(!1),this._onRequestRedraw.fire({start:0,end:this._terminal.rows-1,sync:!0})}handleCharSizeChanged(){this.handleResize(this._terminal.cols,this._terminal.rows)}handleBlur(){for(let t of this._renderLayers)t.handleBlur(this._terminal);this._cursorBlinkStateManager.value?.pause(),this._requestRedrawViewport()}handleFocus(){for(let t of this._renderLayers)t.handleFocus(this._terminal);this._cursorBlinkStateManager.value?.resume(),this._requestRedrawViewport()}handleViewportVisibilityChange(t){this._textBlinkStateManager.setViewportVisible(t)}handleSelectionChanged(t,r,n){for(let a of this._renderLayers)a.handleSelectionChanged(this._terminal,t,r,n);this._model.selection.update(this._core,t,r,n),this._requestRedrawViewport()}handleCursorMove(){for(let t of this._renderLayers)t.handleCursorMove(this._terminal);this._cursorBlinkStateManager.value?.restartBlinkAnimation()}_handleOptionsChanged(){this._updateDimensions(),this._refreshCharAtlas(),this._updateCursorBlink()}_initializeWebGLState(){return this._rectangleRenderer.value=new he(this._terminal,this._gl,this.dimensions,this._themeService),this._glyphRenderer.value=new oe(this._terminal,this._gl,this.dimensions,this._optionsService),this.handleCharSizeChanged(),[this._rectangleRenderer.value,this._glyphRenderer.value]}_refreshCharAtlas(){if(this.dimensions.device.char.width<=0&&this.dimensions.device.char.height<=0){this._isAttached=!1;return}let t=ee(this._terminal,this._optionsService.rawOptions,this._themeService.colors,this.dimensions.device.cell.width,this.dimensions.device.cell.height,this.dimensions.device.char.width,this.dimensions.device.char.height,this._coreBrowserService.dpr,this._deviceMaxTextureSize,this._customGlyphs);this._charAtlas!==t&&(this._onChangeTextureAtlas.fire(t.pages[0].canvas),this._charAtlasDisposable.value=ke(_0.forward(t.onAddTextureAtlasCanvas,this._onAddTextureAtlasCanvas),_0.forward(t.onRemoveTextureAtlasCanvas,this._onRemoveTextureAtlasCanvas))),this._charAtlas=t,this._charAtlas.warmUp(),this._glyphRenderer.value?.setAtlas(this._charAtlas)}_clearModel(t){this._model.clear(),t&&this._glyphRenderer.value?.clear()}clearTextureAtlas(){this._charAtlas?.clearTexture(),this._clearModel(!0),this._requestRedrawViewport()}clear(){this._clearModel(!0);for(let t of this._renderLayers)t.reset(this._terminal);this._resetBlinkingRowState(),this._textBlinkStateManager.setNeedsBlinkInViewport(!1),this._cursorBlinkStateManager.value?.restartBlinkAnimation(),this._updateCursorBlink()}renderRows(t,r){if(!this._isAttached)if(this._core.screenElement?.isConnected&&this._charSizeService.width&&this._charSizeService.height)this._updateDimensions(),this._refreshCharAtlas(),this._isAttached=!0;else return;for(let n of this._renderLayers)n.handleGridChanged(this._terminal,t,r);!this._glyphRenderer.value||!this._rectangleRenderer.value||(this._glyphRenderer.value.beginFrame()?(this._clearModel(!0),this._updateModel(0,this._terminal.rows-1)):this._updateModel(t,r),this._rectangleRenderer.value.renderBackgrounds(),this._glyphRenderer.value.render(this._model),(!this._cursorBlinkStateManager.value||this._cursorBlinkStateManager.value.isCursorVisible)&&this._rectangleRenderer.value.renderCursor())}_updateCursorBlink(){this._coreService.decPrivateModes.cursorBlink??this._terminal.options.cursorBlink?this._cursorBlinkStateManager.value=new te(()=>{this._requestRedrawCursor()},this._coreBrowserService):this._cursorBlinkStateManager.clear(),this._requestRedrawCursor()}_updateModel(t,r){let n=this._core,a=this._workCell,s,o,l,T,h,d,_=0,c=!0,u,p,C,Q,m,R,F,b,A;t=Et(t,n.rows-1,0),r=Et(r,n.rows-1,0);let X=this._coreService.decPrivateModes.cursorStyle??n.options.cursorStyle??"block",z=this._terminal.buffer.active.baseY+this._terminal.buffer.active.cursorY,x0=z-n.buffer.ydisp,e0=Math.min(this._terminal.buffer.active.cursorX,n.cols-1),T0=-1,M=this._coreService.isCursorInitialized&&!this._coreService.isCursorHidden&&(!this._cursorBlinkStateManager.value||this._cursorBlinkStateManager.value.isCursorVisible);this._model.cursor=void 0;let l0=!1;for(o=t;o<=r;o++){l=o+n.buffer.ydisp,T=n.buffer.lines.get(l);let t0=!1;for(this._model.lineLengths[o]=0,C=z===l,_=0,h=this._characterJoinerService.getJoinedCharacters(l),b=0;b<n.cols;b++){if(s=this._cellColorResolver.result.bg,T.loadCell(b,a),b===0&&(s=this._cellColorResolver.result.bg),d=!1,c=b>=_,u=b,h.length>0&&b===h[0][0]&&c){p=h.shift();let Y=this._model.selection.isCellSelected(this._terminal,p[0],l);for(F=p[0]+1;F<p[1];F++)c&&=Y===this._model.selection.isCellSelected(this._terminal,F,l);c&&=!C||e0<p[0]||e0>=p[1],c?(d=!0,a=new De(a,T.translateToString(!0,p[0],p[1]),p[1]-p[0]),u=p[1]-1):_=p[1]}if(Q=a.getChars(),m=a.getCode(),F=(o*n.cols+b)*y0,!t0&&a.isBlink()&&(t0=!0),this._cellColorResolver.resolve(a,b,l,this.dimensions.device.cell.width,this.dimensions.device.cell.height),M&&l===z&&(b===e0&&(this._model.cursor={x:e0,y:x0,width:a.getWidth(),style:this._coreBrowserService.isFocused?X:n.options.cursorInactiveStyle,cursorWidth:n.options.cursorWidth,dpr:this._devicePixelRatio},T0=e0+a.getWidth()-1),b>=e0&&b<=T0&&(this._coreBrowserService.isFocused&&X==="block"||this._coreBrowserService.isFocused===!1&&n.options.cursorInactiveStyle==="block")&&(this._cellColorResolver.result.fg=50331648|this._themeService.colors.cursorAccent.rgba>>8&16777215,this._cellColorResolver.result.bg=50331648|this._themeService.colors.cursor.rgba>>8&16777215)),this._textBlinkStateManager.isEnabled&&!this._textBlinkStateManager.isBlinkOn&&a.isBlink()&&(this._cellColorResolver.result.fg|=1073741824),m!==0&&(this._model.lineLengths[o]=b+1),!(this._model.cells[F]===m&&this._model.cells[F+S0]===this._cellColorResolver.result.bg&&this._model.cells[F+R0]===this._cellColorResolver.result.fg&&this._model.cells[F+le]===this._cellColorResolver.result.ext)&&(l0=!0,Q.length>1&&(m|=ct),this._model.cells[F]=m,this._model.cells[F+S0]=this._cellColorResolver.result.bg,this._model.cells[F+R0]=this._cellColorResolver.result.fg,this._model.cells[F+le]=this._cellColorResolver.result.ext,R=a.getWidth(),this._glyphRenderer.value.updateCell(b,o,m,this._cellColorResolver.result.bg,this._cellColorResolver.result.fg,this._cellColorResolver.result.ext,Q,R,s),d)){for(a=this._workCell,b++;b<=u;b++)A=(o*n.cols+b)*y0,this._glyphRenderer.value.updateCell(b,o,0,0,0,0,"",0,0),this._model.cells[A]=0,this._model.cells[A+S0]=this._cellColorResolver.result.bg,this._model.cells[A+R0]=this._cellColorResolver.result.fg,this._model.cells[A+le]=this._cellColorResolver.result.ext;b--}}this._setRowBlinkState(o,t0)}l0&&this._rectangleRenderer.value.updateBackgrounds(this._model),this._rectangleRenderer.value.updateCursor(this._model),this._updateTextBlinkState()}_resetBlinkingRowState(){this._rowHasBlinkingCells=new Array(this._terminal.rows).fill(!1),this._rowHasBlinkingCellsCount=0}_setRowBlinkState(t,r){this._rowHasBlinkingCells[t]!==r&&(this._rowHasBlinkingCells[t]=r,this._rowHasBlinkingCellsCount+=r?1:-1)}_updateTextBlinkState(){this._textBlinkStateManager.setNeedsBlinkInViewport(this._rowHasBlinkingCellsCount>0)}_updateDimensions(){!this._charSizeService.width||!this._charSizeService.height||(this.dimensions.device.char.width=Math.floor(this._charSizeService.width*this._devicePixelRatio),this.dimensions.device.char.height=Math.ceil(this._charSizeService.height*this._devicePixelRatio),this.dimensions.device.cell.height=Math.floor(this.dimensions.device.char.height*this._optionsService.rawOptions.lineHeight),this.dimensions.device.char.top=this._optionsService.rawOptions.lineHeight===1?0:Math.round((this.dimensions.device.cell.height-this.dimensions.device.char.height)/2),this.dimensions.device.cell.width=this.dimensions.device.char.width+Math.round(this._optionsService.rawOptions.letterSpacing),this.dimensions.device.char.left=Math.floor(this._optionsService.rawOptions.letterSpacing/2),this.dimensions.device.canvas.height=this._terminal.rows*this.dimensions.device.cell.height,this.dimensions.device.canvas.width=this._terminal.cols*this.dimensions.device.cell.width,this.dimensions.css.canvas.height=Math.round(this.dimensions.device.canvas.height/this._devicePixelRatio),this.dimensions.css.canvas.width=Math.round(this.dimensions.device.canvas.width/this._devicePixelRatio),this.dimensions.css.cell.height=this.dimensions.device.cell.height/this._devicePixelRatio,this.dimensions.css.cell.width=this.dimensions.device.cell.width/this._devicePixelRatio)}_setCanvasDevicePixelDimensions(t,r){this._canvas.width===t&&this._canvas.height===r||(this._canvas.width=t,this._canvas.height=r,this._onRequestRedraw.fire({start:0,end:this._terminal.rows-1,sync:!0}))}_requestRedrawViewport(){this._onRequestRedraw.fire({start:0,end:this._terminal.rows-1})}_requestRedrawCursor(){let t=this._terminal.buffer.active.cursorY;this._onRequestRedraw.fire({start:t,end:t})}},De=class extends s0{constructor(t,r,n){super();this.content=0;this.combinedData="";this.fg=t.fg,this.bg=t.bg,this.combinedData=r,this._width=n}isCombined(){return 2097152}getWidth(){return this._width}getChars(){return this.combinedData}getCode(){return 2097151}setFromCharData(t){throw new Error("not implemented")}getAsCharData(){return[this.fg,this.getChars(),this.getWidth(),this.getCode()]}};function Et(i,e,t=0){return Math.max(Math.min(i,e),t)}var bt=class extends W{constructor(t){if(fe&&Ve()<16){let r={antialias:!1,depth:!1,preserveDrawingBuffer:!0};if(!document.createElement("canvas").getContext("webgl2",r))throw new Error("Webgl2 is only supported on Safari 16 and above")}super();this._onChangeTextureAtlas=this._register(new U);this.onChangeTextureAtlas=this._onChangeTextureAtlas.event;this._onAddTextureAtlasCanvas=this._register(new U);this.onAddTextureAtlasCanvas=this._onAddTextureAtlasCanvas.event;this._onRemoveTextureAtlasCanvas=this._register(new U);this.onRemoveTextureAtlasCanvas=this._onRemoveTextureAtlasCanvas.event;this._onContextLoss=this._register(new U);this.onContextLoss=this._onContextLoss.event;this._customGlyphs=t?.customGlyphs??!0,this._preserveDrawingBuffer=t?.preserveDrawingBuffer}activate(t){let r=t._core;if(!t.element){this._register(r.onWillOpen(()=>this.activate(t)));return}this._terminal=t;let n=r.coreService,a=r.optionsService,s=r,o=s._renderService,l=s._characterJoinerService,T=s._charSizeService,h=s._coreBrowserService,d=s._decorationService,_=s._themeService;this._renderer=this._register(new ue(t,l,T,h,n,d,a,_,this._customGlyphs,this._preserveDrawingBuffer)),this._register(_0.forward(this._renderer.onContextLoss,this._onContextLoss)),this._register(_0.forward(this._renderer.onChangeTextureAtlas,this._onChangeTextureAtlas)),this._register(_0.forward(this._renderer.onAddTextureAtlasCanvas,this._onAddTextureAtlasCanvas)),this._register(_0.forward(this._renderer.onRemoveTextureAtlasCanvas,this._onRemoveTextureAtlasCanvas)),o.setRenderer(this._renderer),this._register(g(()=>{if(this._terminal._core._store._isDisposed)return;let c=this._terminal._core._renderService;c.setRenderer(this._terminal._core._createRenderer()),c.handleResize(t.cols,t.rows)}))}get textureAtlas(){return this._renderer?.textureAtlas}clearTextureAtlas(){this._renderer?.clearTextureAtlas()}};export{bt as WebglAddon};
75
75
  //# sourceMappingURL=addon-webgl.mjs.map