@innovatorved/code-lab 0.6.1 → 0.7.1

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.
Files changed (131) hide show
  1. package/ARCHITECTURE.md +2 -2
  2. package/CHANGELOG.md +35 -0
  3. package/README.md +38 -1
  4. package/dist/apps/web/src/index.d.ts +0 -9
  5. package/dist/code-lab-sql.esm.js +19 -19
  6. package/dist/code-lab-sql.umd.js +20 -20
  7. package/dist/code-lab.css +1 -1
  8. package/dist/code-lab.d.ts +19 -1
  9. package/dist/code-lab.esm.js +933 -1685
  10. package/dist/code-lab.js +932 -1684
  11. package/dist/extensions/cpp.esm.js +132 -8751
  12. package/dist/extensions/cpp.js +124 -8761
  13. package/dist/extensions/guided-lab.esm.js +33 -6827
  14. package/dist/extensions/guided-lab.js +33 -6845
  15. package/dist/extensions/javascript.esm.js +1 -36
  16. package/dist/extensions/javascript.js +1 -58
  17. package/dist/extensions/python.esm.js +79 -8109
  18. package/dist/extensions/python.js +79 -8127
  19. package/dist/extensions/typescript.esm.js +1 -55
  20. package/dist/extensions/typescript.js +1 -77
  21. package/dist/index.d.ts +1 -1
  22. package/dist/modular-kernel.d.ts +0 -4
  23. package/dist/preview-sw.js +1 -1
  24. package/dist/runtime.esm.js +79 -79
  25. package/dist/runtime.js +79 -79
  26. package/dist/schemas.d.ts +22 -1
  27. package/dist/schemas.esm.js +33 -6806
  28. package/dist/schemas.js +33 -6822
  29. package/dist/shell.esm.js +248 -242
  30. package/dist/shell.js +248 -242
  31. package/dist/terminal.esm.js +8 -6
  32. package/dist/terminal.js +6 -6
  33. package/dist/workbench/command-palette.d.ts +0 -4
  34. package/dist/workbench/index.d.ts +0 -20
  35. package/dist/workbench/intellisense.d.ts +1 -7
  36. package/package.json +3 -10
  37. package/src/code-lab.css +11 -503
  38. package/src/extensions/cpp.ts +11 -29
  39. package/src/extensions/guided-lab.ts +6 -2
  40. package/src/extensions/python.ts +9 -3
  41. package/src/index.ts +1 -1
  42. package/src/modular-kernel.ts +0 -4
  43. package/src/runtime.ts +153 -42
  44. package/src/schemas.ts +12 -3
  45. package/src/shell.ts +109 -16
  46. package/src/terminal.ts +4 -2
  47. package/src/workbench/command-palette.ts +22 -302
  48. package/src/workbench/diff-editor.ts +2 -0
  49. package/src/workbench/icons.ts +1 -1
  50. package/src/workbench/index.ts +0 -15
  51. package/src/workbench/intellisense.ts +17 -4
  52. package/src/workbench.ts +432 -456
  53. package/dist/code-lab.umd.js +0 -6109
  54. package/dist/packages/editor/src/index.d.ts +0 -118
  55. package/dist/packages/preview/src/index.d.ts +0 -34
  56. package/dist/packages/runtime/src/index.d.ts +0 -47
  57. package/dist/packages/terminal/src/index.d.ts +0 -54
  58. package/dist/workbench/drawer.d.ts +0 -18
  59. package/dist/workbench/file-tree.d.ts +0 -11
  60. package/dist/workbench/guided-pane.d.ts +0 -11
  61. package/dist/workbench/styles.d.ts +0 -4
  62. package/dist/workbench/toolbar.d.ts +0 -17
  63. package/packages/commands/README.md +0 -7
  64. package/packages/commands/package.json +0 -16
  65. package/packages/commands/src/index.ts +0 -467
  66. package/packages/commands/tsconfig.json +0 -22
  67. package/packages/core/README.md +0 -12
  68. package/packages/core/package.json +0 -13
  69. package/packages/core/src/di.ts +0 -147
  70. package/packages/core/src/disposable.ts +0 -112
  71. package/packages/core/src/errors.ts +0 -205
  72. package/packages/core/src/events.ts +0 -157
  73. package/packages/core/src/index.ts +0 -49
  74. package/packages/core/src/path.ts +0 -118
  75. package/packages/core/src/registry.ts +0 -61
  76. package/packages/core/tsconfig.json +0 -19
  77. package/packages/editor/README.md +0 -9
  78. package/packages/editor/package.json +0 -18
  79. package/packages/editor/src/index.ts +0 -344
  80. package/packages/editor/tsconfig.json +0 -24
  81. package/packages/fs/README.md +0 -7
  82. package/packages/fs/package.json +0 -16
  83. package/packages/fs/src/backends.ts +0 -301
  84. package/packages/fs/src/index.ts +0 -18
  85. package/packages/fs/src/types.ts +0 -44
  86. package/packages/fs/src/vfs-service.ts +0 -257
  87. package/packages/fs/tsconfig.json +0 -22
  88. package/packages/preview/README.md +0 -3
  89. package/packages/preview/package.json +0 -16
  90. package/packages/preview/src/index.ts +0 -125
  91. package/packages/preview/tsconfig.json +0 -22
  92. package/packages/runtime/README.md +0 -3
  93. package/packages/runtime/package.json +0 -17
  94. package/packages/runtime/src/index.ts +0 -134
  95. package/packages/runtime/tsconfig.json +0 -23
  96. package/packages/settings/README.md +0 -7
  97. package/packages/settings/package.json +0 -16
  98. package/packages/settings/src/builtin-schemas.ts +0 -246
  99. package/packages/settings/src/configuration-service.ts +0 -609
  100. package/packages/settings/src/index.ts +0 -38
  101. package/packages/settings/src/jsonc.ts +0 -189
  102. package/packages/settings/src/schema.ts +0 -164
  103. package/packages/settings/tsconfig.json +0 -22
  104. package/packages/sql/README.md +0 -12
  105. package/packages/sql/package.json +0 -13
  106. package/packages/sql/src/completions.ts +0 -359
  107. package/packages/sql/src/diagnostics.ts +0 -200
  108. package/packages/sql/src/formatter.ts +0 -271
  109. package/packages/sql/src/index.ts +0 -54
  110. package/packages/sql/src/sql-editor.ts +0 -802
  111. package/packages/sql/src/styles.ts +0 -524
  112. package/packages/sql/src/tokenizer.ts +0 -457
  113. package/packages/sql/src/types.ts +0 -148
  114. package/packages/sql/tsconfig.json +0 -19
  115. package/packages/terminal/README.md +0 -3
  116. package/packages/terminal/package.json +0 -16
  117. package/packages/terminal/src/index.ts +0 -183
  118. package/packages/terminal/tsconfig.json +0 -22
  119. package/packages/ui/README.md +0 -8
  120. package/packages/ui/package.json +0 -18
  121. package/packages/ui/src/index.ts +0 -40
  122. package/packages/ui/src/observability.ts +0 -173
  123. package/packages/ui/src/plugin-registry.ts +0 -289
  124. package/packages/ui/src/settings-dialog.ts +0 -911
  125. package/packages/ui/src/themes.ts +0 -333
  126. package/packages/ui/tsconfig.json +0 -24
  127. package/src/workbench/drawer.ts +0 -157
  128. package/src/workbench/file-tree.ts +0 -51
  129. package/src/workbench/guided-pane.ts +0 -43
  130. package/src/workbench/styles.ts +0 -211
  131. package/src/workbench/toolbar.ts +0 -182
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * ============================================================
3
- * @innovatorved/code-lab v0.6.1 — Standalone Browser Code IDE & Virtual Runtime
3
+ * @innovatorved/code-lab v0.7.1 — Standalone Browser Code IDE & Virtual Runtime
4
4
  * ============================================================
5
5
  * Features:
6
6
  * - Sandboxed Web Worker Execution Engine with Multi-Instance Isolation & Watchdog Timer
@@ -18,18 +18,18 @@ const _root = typeof globalThis !== 'undefined' ? globalThis : typeof window !==
18
18
  var CodeLabLogger=(()=>{var s=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var y=(o,n)=>{for(var a in n)s(o,a,{get:n[a],enumerable:!0})},v=(o,n,a,t)=>{if(n&&typeof n=="object"||typeof n=="function")for(let e of C(n))!x.call(o,e)&&e!==a&&s(o,e,{get:()=>n[e],enumerable:!(t=p(n,e))||t.enumerable});return o};var O=o=>v(s({},"__esModule",{value:!0}),o);var h={};y(h,{CodeLabError:()=>d,DEFAULT_LOGGER:()=>w,LOG_PREFIX:()=>c,createLogger:()=>g,default:()=>_,isCodeLabError:()=>f});var c="[code-lab]",d=class extends Error{code;options;cause;recoverable;details;context;constructor(n,a,t={}){super(a),this.name="CodeLabError",this.code=n,this.options=t,this.cause=t.cause,this.recoverable=t.recoverable!==!1;let e=t.details??t.context;e!==void 0&&(this.details=e,this.context=e),Object.setPrototypeOf(this,new.target.prototype)}};function f(o){return!!(o&&typeof o=="object"&&(o instanceof d||o.name==="CodeLabError"&&typeof o.code=="string"))}function g(o={}){let n=o.logger??null,a=o.debug===!0,t=o.prefix||c,e=(r,b)=>{if(r==="debug"&&!a)return;if(n&&typeof n[r]=="function"){let L=null;try{n[r](...b);return}catch(k){L=k}}let i=typeof console<"u"?console:null,l=i?i[r]:null;typeof l=="function"&&l.call(i,t,...b)};return{debug:(...r)=>e("debug",r),info:(...r)=>e("info",r),warn:(...r)=>e("warn",r),error:(...r)=>e("error",r)}}var w=g(),E={LOG_PREFIX:c,CodeLabError:d,isCodeLabError:f,createLogger:g,DEFAULT_LOGGER:w},u=typeof globalThis<"u"?globalThis:null;u&&!u.CodeLabLogger&&(u.CodeLabLogger=E);var _=E;return O(h);})();
19
19
 
20
20
  (function () {
21
- (function(g,b){const m=b();g&&(g.CodeLabTerminal=m,g.PTYTerminalEngine=m.PTYTerminalEngine,g.createPTYTerminalEngine=m.createPTYTerminalEngine,g.createTerminal=m.createTerminal,g.ansiToHtml=m.ansiToHtml,g.parseAnsiToHtml=m.parseAnsiToHtml),typeof module<"u"&&module.exports?module.exports=m:typeof define=="function"&&define.amd&&define([],function(){return m})})(typeof globalThis<"u"?globalThis:typeof window<"u"?window:this,function(){"use strict";const g=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{},b=g&&g.CodeLabLogger&&typeof g.CodeLabLogger.createLogger=="function"?g.CodeLabLogger.createLogger():{debug(){},info(...u){typeof console<"u"&&console.info&&console.info("[code-lab]",...u)},warn(...u){typeof console<"u"&&console.warn&&console.warn("[code-lab]",...u)},error(...u){typeof console<"u"&&console.error&&console.error("[code-lab]",...u)}},m={1:"cl-ansi-bold",2:"cl-ansi-dim",3:"cl-ansi-italic",4:"cl-ansi-underline",7:"cl-ansi-inverse",9:"cl-ansi-strike",30:"cl-ansi-black",31:"cl-ansi-red",32:"cl-ansi-green",33:"cl-ansi-yellow",34:"cl-ansi-blue",35:"cl-ansi-magenta",36:"cl-ansi-cyan",37:"cl-ansi-white",90:"cl-ansi-gray",91:"cl-ansi-bright-red",92:"cl-ansi-bright-green",93:"cl-ansi-bright-yellow",94:"cl-ansi-bright-blue",95:"cl-ansi-bright-magenta",96:"cl-ansi-bright-cyan",97:"cl-ansi-bright-white",40:"cl-ansi-bg-black",41:"cl-ansi-bg-red",42:"cl-ansi-bg-green",43:"cl-ansi-bg-yellow",44:"cl-ansi-bg-blue",45:"cl-ansi-bg-magenta",46:"cl-ansi-bg-cyan",47:"cl-ansi-bg-white",100:"cl-ansi-bg-bright-black",101:"cl-ansi-bg-bright-red",102:"cl-ansi-bg-bright-green",103:"cl-ansi-bg-bright-yellow",104:"cl-ansi-bg-bright-blue",105:"cl-ansi-bg-bright-magenta",106:"cl-ansi-bg-bright-cyan",107:"cl-ansi-bg-bright-white"},S=["#000000","#cd3131","#0dbc79","#e5e510","#2472c8","#bc3fbc","#11a8cd","#e5e5e5","#666666","#f14c4c","#23d18b","#f5f543","#3b8eea","#d670d6","#29b8db","#ffffff"];function I(u){const e=Number(u);if(!Number.isFinite(e)||e<0||e>255)return null;if(e<16)return S[e];if(e<232){const n=e-16,i=Math.floor(n/36),l=Math.floor(n%36/6),r=n%6,s=f=>f===0?0:55+f*40;return`rgb(${s(i)}, ${s(l)}, ${s(r)})`}const t=8+(e-232)*10;return`rgb(${t}, ${t}, ${t})`}function y(u){return u==null?"":String(u).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}function C(u){if(!u)return"";const e=String(u);if(!e.includes("\x1B")&&!e.includes("\r"))return e;let t=e;t=t.replace(/\x1b\]8;[^;]*;[^\x07\x1b]*(?:\x07|\x1b\\)([\s\S]*?)\x1b\]8;;(?:\x07|\x1b\\)/g,"$1"),t=t.replace(/\x1b\][^\x07\x1b]*(?:\x07|\x1b\\)/g,"");const n=t.lastIndexOf("\x1B[2J"),i=t.lastIndexOf("\x1B[3J"),l=t.lastIndexOf("\x1Bc"),r=Math.max(n,i,l);if(r!==-1){const p=r===l?2:4;t=t.slice(r+p),t=t.replace(/^(?:\x1b\[[23]J|\x1b\[(?:\d+;\d+)?H)+/,"")}t=t.replace(/\r\n/g,`
21
+ (function(g,b){const m=b();g&&(g.CodeLabTerminal=m,g.PTYTerminalEngine=m.PTYTerminalEngine,g.createPTYTerminalEngine=m.createPTYTerminalEngine,g.createTerminal=m.createTerminal,g.ansiToHtml=m.ansiToHtml,g.parseAnsiToHtml=m.parseAnsiToHtml),typeof module<"u"&&module.exports?module.exports=m:typeof define=="function"&&define.amd&&define([],function(){return m})})(typeof globalThis<"u"?globalThis:typeof window<"u"?window:this,function(){"use strict";const g=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{},b=g&&g.CodeLabLogger&&typeof g.CodeLabLogger.createLogger=="function"?g.CodeLabLogger.createLogger():{debug(){},info(...u){typeof console<"u"&&console.info&&console.info("[code-lab]",...u)},warn(...u){typeof console<"u"&&console.warn&&console.warn("[code-lab]",...u)},error(...u){typeof console<"u"&&console.error&&console.error("[code-lab]",...u)}},m={1:"cl-ansi-bold",2:"cl-ansi-dim",3:"cl-ansi-italic",4:"cl-ansi-underline",7:"cl-ansi-inverse",9:"cl-ansi-strike",30:"cl-ansi-black",31:"cl-ansi-red",32:"cl-ansi-green",33:"cl-ansi-yellow",34:"cl-ansi-blue",35:"cl-ansi-magenta",36:"cl-ansi-cyan",37:"cl-ansi-white",90:"cl-ansi-gray",91:"cl-ansi-bright-red",92:"cl-ansi-bright-green",93:"cl-ansi-bright-yellow",94:"cl-ansi-bright-blue",95:"cl-ansi-bright-magenta",96:"cl-ansi-bright-cyan",97:"cl-ansi-bright-white",40:"cl-ansi-bg-black",41:"cl-ansi-bg-red",42:"cl-ansi-bg-green",43:"cl-ansi-bg-yellow",44:"cl-ansi-bg-blue",45:"cl-ansi-bg-magenta",46:"cl-ansi-bg-cyan",47:"cl-ansi-bg-white",100:"cl-ansi-bg-bright-black",101:"cl-ansi-bg-bright-red",102:"cl-ansi-bg-bright-green",103:"cl-ansi-bg-bright-yellow",104:"cl-ansi-bg-bright-blue",105:"cl-ansi-bg-bright-magenta",106:"cl-ansi-bg-bright-cyan",107:"cl-ansi-bg-bright-white"},I=["#000000","#cd3131","#0dbc79","#e5e510","#2472c8","#bc3fbc","#11a8cd","#e5e5e5","#666666","#f14c4c","#23d18b","#f5f543","#3b8eea","#d670d6","#29b8db","#ffffff"];function C(u){const e=Number(u);if(!Number.isFinite(e)||e<0||e>255)return null;if(e<16)return I[e];if(e<232){const n=e-16,i=Math.floor(n/36),l=Math.floor(n%36/6),r=n%6,s=f=>f===0?0:55+f*40;return`rgb(${s(i)}, ${s(l)}, ${s(r)})`}const t=8+(e-232)*10;return`rgb(${t}, ${t}, ${t})`}function y(u){return u==null?"":String(u).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}function w(u){if(!u)return"";const e=String(u);if(!e.includes("\x1B")&&!e.includes("\r"))return e;let t=e;t=t.replace(/\x1b\]8;[^;]*;[^\x07\x1b]*(?:\x07|\x1b\\)([\s\S]*?)\x1b\]8;;(?:\x07|\x1b\\)/g,"$1"),t=t.replace(/\x1b\][^\x07\x1b]*(?:\x07|\x1b\\)/g,"");const n=t.lastIndexOf("\x1B[2J"),i=t.lastIndexOf("\x1B[3J"),l=t.lastIndexOf("\x1Bc"),r=Math.max(n,i,l);if(r!==-1){const p=r===l?2:4;t=t.slice(r+p),t=t.replace(/^(?:\x1b\[[23]J|\x1b\[(?:\d+;\d+)?H)+/,"")}t=t.replace(/\r\n/g,`
22
22
  `);const s=t.split(`
23
23
  `),f=[];for(let p=0;p<s.length;p++){let c=s[p];for(;/\x1b\[(?:1)?A/.test(c);){const a=/\x1b\[(?:1)?A/.exec(c),d=c.slice(0,a.index);let h=c.slice(a.index+a[0].length);if(f.length>0){if(h.includes("\x1B[2K"))h=h.slice(h.lastIndexOf("\x1B[2K")+4),f[f.length-1]=h;else if(h.includes("\r")){const o=h.split("\r");f[f.length-1]=o[o.length-1]}else f[f.length-1]=h;c=d}else c=d+h}if(c.includes("\x1B[2K")){const a=c.lastIndexOf("\x1B[2K");c=c.slice(a+4)}if(c.includes("\r")){const a=c.split("\r");c=a[a.length-1]}c=c.replace(/\x1b\[[0]?K/g,""),c=c.replace(/\x1b\[(?:1)?G/g,""),f.push(c)}return f.join(`
24
- `)}function _(u){if(!u)return"";const e=C(String(u));if(!e.includes("\x1B["))return y(e);const t=e.replace(/\x1b\[[0-9;?]*(?!m)[A-Za-z]/g,""),n=/\x1b\[([0-9;]*)m/g;let i="",l=0,r;const s={bold:!1,dim:!1,italic:!1,underline:!1,inverse:!1,strike:!1,fgClass:null,bgClass:null,fgColor:null,bgColor:null},f=()=>{s.bold=!1,s.dim=!1,s.italic=!1,s.underline=!1,s.inverse=!1,s.strike=!1,s.fgClass=null,s.bgClass=null,s.fgColor=null,s.bgColor=null},p=a=>{if(!a)return"";const d=y(a),h=[];s.bold&&h.push("cl-ansi-bold"),s.dim&&h.push("cl-ansi-dim"),s.italic&&h.push("cl-ansi-italic"),s.underline&&h.push("cl-ansi-underline"),s.inverse&&h.push("cl-ansi-inverse"),s.strike&&h.push("cl-ansi-strike"),s.fgClass&&h.push(s.fgClass),s.bgClass&&h.push(s.bgClass);const o=[];if(s.fgColor&&o.push(`color:${s.fgColor}`),s.bgColor&&o.push(`background-color:${s.bgColor}`),s.inverse&&!s.fgClass&&!s.bgClass&&o.push("filter:invert(1)"),s.strike&&o.push("text-decoration:line-through"),h.length===0&&o.length===0)return d;const v=h.length>0?` class="${h.join(" ")}"`:"",x=o.length>0?` style="${o.join(";")}"`:"";return`<span${v}${x}>${d}</span>`};for(;(r=n.exec(t))!==null;){const a=t.slice(l,r.index);a&&(i+=p(a)),l=n.lastIndex;const d=r[1]?r[1].split(";").map(Number):[0];for(let h=0;h<d.length;h++){const o=d[h];if(o===0||Number.isNaN(o))f();else if(o===1)s.bold=!0;else if(o===2)s.dim=!0;else if(o===3)s.italic=!0;else if(o===4)s.underline=!0;else if(o===7)s.inverse=!0;else if(o===9)s.strike=!0;else if(o===22)s.bold=!1,s.dim=!1;else if(o===23)s.italic=!1;else if(o===24)s.underline=!1;else if(o===27)s.inverse=!1;else if(o===29)s.strike=!1;else if(o===39)s.fgClass=null,s.fgColor=null;else if(o===49)s.bgClass=null,s.bgColor=null;else if((o===38||o===48)&&d[h+1]===5&&h+2<d.length){const v=I(d[h+2]);v&&(o===38?(s.fgClass=null,s.fgColor=v):(s.bgClass=null,s.bgColor=v)),h+=2}else if((o===38||o===48)&&d[h+1]===2&&h+4<d.length){const v=Math.max(0,Math.min(255,Number(d[h+2])||0)),x=Math.max(0,Math.min(255,Number(d[h+3])||0)),E=Math.max(0,Math.min(255,Number(d[h+4])||0)),D=`rgb(${v}, ${x}, ${E})`;o===38?(s.fgClass=null,s.fgColor=D):(s.bgClass=null,s.bgColor=D),h+=4}else o>=30&&o<=37||o>=90&&o<=97?(s.fgClass=m[o]||null,s.fgColor=null):(o>=40&&o<=47||o>=100&&o<=107)&&(s.bgClass=m[o]||null,s.bgColor=null)}}const c=t.slice(l);return c&&(i+=p(c)),i}const M=_,T=2e3,k=new Set(["stdout","stderr","system","info","warn","error","success"]);function L(u){const e=String(u||"stdout").trim();return k.has(e)?e:"stdout"}class w{constructor(e,t={}){e&&typeof e=="object"&&typeof e.querySelector!="function"&&typeof e.appendChild!="function"&&arguments.length===1&&(t=e,e=t.container||null),this.container=e||null,this.options=t||{},this.maxScrollback=typeof this.options.maxScrollback=="number"&&this.options.maxScrollback>0?this.options.maxScrollback:T,this.maxHistory=typeof this.options.maxHistory=="number"&&this.options.maxHistory>0?this.options.maxHistory:1e3,this.logs=Array.isArray(this.options.logs)?this.options.logs:[],this.cwd=this.options.cwd||"/workspace",this.replMode=!!this.options.replMode,this.promptOverride=this.options.prompt||null,this.history=Array.isArray(this.options.history)?this.options.history:[],this.historyIdx=-1,this.savedBuffer="",this.buffer="",this.cursor=0,this.searchMode=!1,this.searchQuery="",this.searchMatchIdx=-1,this._readLineQueue=[],this.isBusy=!1,this.onCommand=typeof this.options.onCommand=="function"?this.options.onCommand:null,this.getCompletions=typeof this.options.getCompletions=="function"?this.options.getCompletions:null,this.onKey=typeof this.options.onKey=="function"?this.options.onKey:null,this.onInterrupt=typeof this.options.onInterrupt=="function"?this.options.onInterrupt:null,this._activeLineCommitted=!0,this._cursorCol=0,this._pendingEscape="",this._targetLineIdx=-1,this._needsRewrite=!1,this._activeLineEl=null,this._mounted=!1,this._listeners=[],this.container&&this.mount(this.container)}getPrompt(){return this.promptOverride?this.promptOverride:this.replMode?"> ":`codelab:${this.cwd||"/workspace"}$ `}setPrompt(e){this.promptOverride=e,this.updateActiveLine()}setCwd(e){this.cwd=e,this.updateActiveLine()}setReplMode(e){this.replMode=!!e,this.updateActiveLine()}writeStreamChunk(e,t="stdout"){let n=String(e??"");if(!n)return;this._pendingEscape&&(n=this._pendingEscape+n,this._pendingEscape="");let i=!1,l=0;for(;l<n.length;){if(n[l]==="\x1B"){const s=n.slice(l);if(s==="\x1B"||/^\x1b\[[0-9;?]*$/.test(s)||/^\x1b\][^\x07]*(?:\x1b)?$/.test(s)){this._pendingEscape=s;break}if(s.startsWith("\x1Bc")){l+=2,this.clear(),i=!1;continue}const f=/^\x1b\]([^\x07\x1b]*)(?:\x07|\x1b\\)/.exec(s);if(f){l+=f[0].length;continue}const p=/^\x1b\[([0-9;?]*)([A-Za-z])/.exec(s);if(p){const c=p[1],a=p[2],d=p[0];if(l+=d.length,a==="K"){const h=this._getActiveLine(t);c==="2"?(h.text="",this._cursorCol=0,this._needsRewrite=!1):(h.text=h.text.slice(0,this._cursorCol),this._needsRewrite=!1),i=!0}else if(a==="A"){const h=parseInt(c,10)||1;if(this.logs.length>0){const o=this._activeLineCommitted?this.logs.length:this.logs.length-1;this._targetLineIdx=Math.max(0,o-h),this._activeLineCommitted=!1,this._cursorCol=0,this._needsRewrite=!1;const v=this.logs[this._targetLineIdx];v&&(v.text=""),this._activeLineEl=null}}else if(a==="G"||a==="H"||a==="f")this._cursorCol=0,a==="G"&&(this._needsRewrite=!0);else if(a==="J"&&(c==="2"||c==="3"))this.clear(),i=!1;else if(a==="m"){const h=this._getActiveLine(t);h.text+=d,i=!0}continue}}const r=n[l];if(r==="\r")this._cursorCol=0,this._needsRewrite=!0,l++;else if(r===`
24
+ `)}function _(u){if(!u)return"";const e=w(String(u));if(!e.includes("\x1B["))return y(e);const t=e.replace(/\x1b\[[0-9;?]*(?!m)[A-Za-z]/g,""),n=/\x1b\[([0-9;]*)m/g;let i="",l=0,r;const s={bold:!1,dim:!1,italic:!1,underline:!1,inverse:!1,strike:!1,fgClass:null,bgClass:null,fgColor:null,bgColor:null},f=()=>{s.bold=!1,s.dim=!1,s.italic=!1,s.underline=!1,s.inverse=!1,s.strike=!1,s.fgClass=null,s.bgClass=null,s.fgColor=null,s.bgColor=null},p=a=>{if(!a)return"";const d=y(a),h=[];s.bold&&h.push("cl-ansi-bold"),s.dim&&h.push("cl-ansi-dim"),s.italic&&h.push("cl-ansi-italic"),s.underline&&h.push("cl-ansi-underline"),s.inverse&&h.push("cl-ansi-inverse"),s.strike&&h.push("cl-ansi-strike"),s.fgClass&&h.push(s.fgClass),s.bgClass&&h.push(s.bgClass);const o=[];if(s.fgColor&&o.push(`color:${s.fgColor}`),s.bgColor&&o.push(`background-color:${s.bgColor}`),s.inverse&&!s.fgClass&&!s.bgClass&&o.push("filter:invert(1)"),s.strike&&o.push("text-decoration:line-through"),h.length===0&&o.length===0)return d;const v=h.length>0?` class="${h.join(" ")}"`:"",x=o.length>0?` style="${o.join(";")}"`:"";return`<span${v}${x}>${d}</span>`};for(;(r=n.exec(t))!==null;){const a=t.slice(l,r.index);a&&(i+=p(a)),l=n.lastIndex;const d=r[1]?r[1].split(";").map(Number):[0];for(let h=0;h<d.length;h++){const o=d[h];if(o===0||Number.isNaN(o))f();else if(o===1)s.bold=!0;else if(o===2)s.dim=!0;else if(o===3)s.italic=!0;else if(o===4)s.underline=!0;else if(o===7)s.inverse=!0;else if(o===9)s.strike=!0;else if(o===22)s.bold=!1,s.dim=!1;else if(o===23)s.italic=!1;else if(o===24)s.underline=!1;else if(o===27)s.inverse=!1;else if(o===29)s.strike=!1;else if(o===39)s.fgClass=null,s.fgColor=null;else if(o===49)s.bgClass=null,s.bgColor=null;else if((o===38||o===48)&&d[h+1]===5&&h+2<d.length){const v=C(d[h+2]);v&&(o===38?(s.fgClass=null,s.fgColor=v):(s.bgClass=null,s.bgColor=v)),h+=2}else if((o===38||o===48)&&d[h+1]===2&&h+4<d.length){const v=Math.max(0,Math.min(255,Number(d[h+2])||0)),x=Math.max(0,Math.min(255,Number(d[h+3])||0)),E=Math.max(0,Math.min(255,Number(d[h+4])||0)),S=`rgb(${v}, ${x}, ${E})`;o===38?(s.fgClass=null,s.fgColor=S):(s.bgClass=null,s.bgColor=S),h+=4}else o>=30&&o<=37||o>=90&&o<=97?(s.fgClass=m[o]||null,s.fgColor=null):(o>=40&&o<=47||o>=100&&o<=107)&&(s.bgClass=m[o]||null,s.bgColor=null)}}const c=t.slice(l);return c&&(i+=p(c)),i}const M=_,T=2e3,k=new Set(["stdout","stderr","system","info","warn","error","success"]);function L(u){const e=String(u||"stdout").trim();return k.has(e)?e:"stdout"}class A{constructor(e,t={}){e&&typeof e=="object"&&typeof e.querySelector!="function"&&typeof e.appendChild!="function"&&arguments.length===1&&(t=e,e=t.container||null),this.container=e||null,this.options=t||{},this.maxScrollback=typeof this.options.maxScrollback=="number"&&this.options.maxScrollback>0?this.options.maxScrollback:T,this.maxHistory=typeof this.options.maxHistory=="number"&&this.options.maxHistory>0?this.options.maxHistory:1e3,this.logs=Array.isArray(this.options.logs)?this.options.logs:[],this.cwd=this.options.cwd||"/workspace",this.replMode=!!this.options.replMode,this.promptOverride=this.options.prompt||null,this.history=Array.isArray(this.options.history)?this.options.history:[],this.historyIdx=-1,this.savedBuffer="",this.buffer="",this.cursor=0,this.searchMode=!1,this.searchQuery="",this.searchMatchIdx=-1,this._readLineQueue=[],this.isBusy=!1,this.onCommand=typeof this.options.onCommand=="function"?this.options.onCommand:null,this.getCompletions=typeof this.options.getCompletions=="function"?this.options.getCompletions:null,this.onKey=typeof this.options.onKey=="function"?this.options.onKey:null,this.onInterrupt=typeof this.options.onInterrupt=="function"?this.options.onInterrupt:null,this._activeLineCommitted=!0,this._cursorCol=0,this._pendingEscape="",this._targetLineIdx=-1,this._needsRewrite=!1,this._activeLineEl=null,this._mounted=!1,this._listeners=[],this.container&&this.mount(this.container)}getPrompt(){return this.promptOverride?this.promptOverride:this.replMode?"> ":`codelab:${this.cwd||"/workspace"}$ `}setPrompt(e){this.promptOverride=e,this.updateActiveLine()}setCwd(e){this.cwd=e,this.updateActiveLine()}setReplMode(e){this.replMode=!!e,this.updateActiveLine()}writeStreamChunk(e,t="stdout"){let n=String(e??"");if(!n)return;this._pendingEscape&&(n=this._pendingEscape+n,this._pendingEscape="");let i=!1,l=0;for(;l<n.length;){if(n[l]==="\x1B"){const s=n.slice(l);if(s==="\x1B"||/^\x1b\[[0-9;?]*$/.test(s)||/^\x1b\][^\x07]*(?:\x1b)?$/.test(s)){this._pendingEscape=s;break}if(s.startsWith("\x1Bc")){l+=2,this.clear(),i=!1;continue}const f=/^\x1b\]([^\x07\x1b]*)(?:\x07|\x1b\\)/.exec(s);if(f){l+=f[0].length;continue}const p=/^\x1b\[([0-9;?]*)([A-Za-z])/.exec(s);if(p){const c=p[1],a=p[2],d=p[0];if(l+=d.length,a==="K"){const h=this._getActiveLine(t);c==="2"?(h.text="",this._cursorCol=0,this._needsRewrite=!1):(h.text=h.text.slice(0,this._cursorCol),this._needsRewrite=!1),i=!0}else if(a==="A"){const h=parseInt(c,10)||1;if(this.logs.length>0){const o=this._activeLineCommitted?this.logs.length:this.logs.length-1;this._targetLineIdx=Math.max(0,o-h),this._activeLineCommitted=!1,this._cursorCol=0,this._needsRewrite=!1;const v=this.logs[this._targetLineIdx];v&&(v.text=""),this._activeLineEl=null}}else if(a==="G"||a==="H"||a==="f")this._cursorCol=0,a==="G"&&(this._needsRewrite=!0);else if(a==="J"&&(c==="2"||c==="3"))this.clear(),i=!1;else if(a==="m"){const h=this._getActiveLine(t);h.text+=d,i=!0}continue}}const r=n[l];if(r==="\r")this._cursorCol=0,this._needsRewrite=!0,l++;else if(r===`
25
25
  `){const s=this._getActiveLine(t);s.text+=`
26
26
  `,this._activeLineCommitted=!0,this._cursorCol=0,this._targetLineIdx=-1,this._needsRewrite=!1,this._activeLineEl=null,i=!0,l++}else{const s=this._getActiveLine(t);this._needsRewrite&&this._cursorCol===0&&s.text.length>0&&!s.text.endsWith(`
27
27
  `)?(s.text=r,this._needsRewrite=!1):s.text+=r,this._cursorCol++,i=!0,l++}}i&&this._updateActiveDomLine(),this._scrollToBottom()}write(e,t="stdout"){this.writeStreamChunk(e,t)}writeln(e,t="stdout"){this.writeStreamChunk(String(e)+`
28
- `,t)}isCommandRunning(){return!!(this.isBusy&&(!this._readLineQueue||this._readLineQueue.length===0))}_pushLog(e){const t={type:L(e&&e.type),text:String(e&&e.text!=null?e.text:"")};if(this.logs.push(t),this.logs.length>this.maxScrollback){const n=this.logs.length-this.maxScrollback;if(this.logs.splice(0,n),this._targetLineIdx>=0&&(this._targetLineIdx=Math.max(0,this._targetLineIdx-n)),this.container&&typeof this.container.querySelector=="function"){const i=this.container.querySelector("#cl-terminal-log");if(i&&i.children&&i.children.length>this.maxScrollback)for(;i.children.length>this.maxScrollback&&typeof i.removeChild=="function"&&i.firstChild;)i.removeChild(i.firstChild)}}return t}_getActiveLine(e){if(this._targetLineIdx>=0&&this._targetLineIdx<this.logs.length)return this.logs[this._targetLineIdx];if(this._activeLineCommitted||this.logs.length===0){const t=this._pushLog({text:"",type:e});return this._activeLineCommitted=!1,this._cursorCol=0,this._targetLineIdx=this.logs.length-1,this._needsRewrite=!1,this._appendDomLine(t),t}return this._targetLineIdx=this.logs.length-1,this.logs[this.logs.length-1]}_appendDomLine(e){if(!this.container||typeof document>"u")return;const t=this.container.querySelector("#cl-terminal-log");if(!t)return;const n=document.createElement("div");n.className="codelab-log-line "+L(e.type),n.innerHTML=_(e.text),t.appendChild(n),this._activeLineEl=n}_updateActiveDomLine(){if(!this.container||typeof document>"u")return;const e=this._getActiveLineSync();if(!e)return;let t=this._activeLineEl;if(!t||!t.parentNode){const n=this.container.querySelector("#cl-terminal-log");n&&(this._targetLineIdx>=0&&this._targetLineIdx<n.children.length?t=n.children[this._targetLineIdx]:t=n.children[n.children.length-1],this._activeLineEl=t)}t&&(t.className="codelab-log-line "+L(e.type),t.innerHTML=_(e.text))}_getActiveLineSync(){return this._targetLineIdx>=0&&this._targetLineIdx<this.logs.length?this.logs[this._targetLineIdx]:this.logs[this.logs.length-1]||null}_scrollToBottom(){if(!this.container)return;const e=this.container.querySelector("#cl-terminal-surface")||this.container;e&&typeof e.scrollTop=="number"&&typeof e.scrollHeight=="number"&&(e.scrollTop=e.scrollHeight)}clear(){if(this.logs.length=0,this._activeLineCommitted=!0,this._cursorCol=0,this._targetLineIdx=-1,this._needsRewrite=!1,this._activeLineEl=null,this.container&&typeof this.container.querySelector=="function"){const e=this.container.querySelector("#cl-terminal-log");e&&(e.innerHTML="")}}getHistory(){return[...this.history]}_activateNextReadLine(){if(!this._readLineQueue||this._readLineQueue.length===0)return;const e=this._readLineQueue[0];e&&typeof e=="object"&&!e._activated&&(e._activated=!0,e.prevPrompt=this.promptOverride,e.promptText&&(this.promptOverride=e.promptText))}_drainReadLineQueue(e=null){if(!Array.isArray(this._readLineQueue)||this._readLineQueue.length===0)return;const t=this._readLineQueue.splice(0,this._readLineQueue.length);let n;for(const i of t)i&&typeof i=="object"&&i._activated&&n===void 0&&(n=i.prevPrompt),i&&typeof i.cleanup=="function"&&i.cleanup();n!==void 0&&(this.promptOverride=n);for(const i of t)if(typeof i=="function")try{i(e)}catch(l){b.debug("readLine callback threw during drain.",l)}else if(i&&typeof i.resolve=="function")try{i.resolve(e)}catch(l){b.debug("readLine resolve threw during drain.",l)}}readLine(e="",t={}){return t&&t.signal&&t.signal.aborted?Promise.resolve(null):new Promise(n=>{const i={promptText:String(e||""),prevPrompt:null,_activated:!1,cleanup:null,resolve:n};if(t&&t.signal&&typeof t.signal.addEventListener=="function"){const l=()=>{const r=this._readLineQueue.indexOf(i);r!==-1&&(this._readLineQueue.splice(r,1),i._activated&&(this.promptOverride=i.prevPrompt,this._activateNextReadLine()),this.updateActiveLine(),n(null))};t.signal.addEventListener("abort",l,{once:!0}),i.cleanup=()=>{try{t.signal.removeEventListener("abort",l)}catch(r){b.debug("readLine abort listener cleanup failed.",r)}}}this._readLineQueue.push(i),this._activateNextReadLine(),this.updateActiveLine()})}focus(){if(!this.container||typeof this.container.querySelector!="function")return;const e=this.container.querySelector("#cl-repl-input");if(e&&typeof e.focus=="function")try{e.focus()}catch(t){b.debug("Terminal input focus skipped.",t)}}mount(e){if(typeof e=="string"&&typeof document<"u"&&(e=document.querySelector(e)),this.container=e||null,!this.container||typeof this.container.querySelector!="function"){this._mounted=!1;return}this._mounted=!0,this.render()}_cleanupListeners(){if(!Array.isArray(this._listeners)){this._listeners=[];return}for(const e of this._listeners)if(typeof e=="function")try{e()}catch(t){b.debug("Terminal listener cleanup callback failed.",t)}else if(e&&e.target&&typeof e.target.removeEventListener=="function")try{e.target.removeEventListener(e.type,e.handler)}catch(t){b.debug("Terminal removeEventListener failed.",t)}this._listeners=[]}destroy(){this._drainReadLineQueue(null),this._cleanupListeners(),this._mounted=!1}_addListener(e,t,n){e&&typeof e.addEventListener=="function"&&(e.addEventListener(t,n),this._listeners.push({target:e,type:t,handler:n}))}_bindEvents(){if(this._cleanupListeners(),!this.container||typeof this.container.querySelector!="function")return;const e=this.container.querySelector("#cl-terminal-surface")||this.container,t=this.container.querySelector("#cl-repl-input"),n=this.container.querySelector("#cl-repl-form");e&&this._addListener(e,"click",i=>{if(i&&i.target===t)return;typeof window<"u"&&window.getSelection&&String(window.getSelection())||this.focus()}),t&&(this._addListener(t,"keydown",i=>this.handleKeyDown(i)),this._addListener(t,"paste",i=>{const l=i&&i.clipboardData&&typeof i.clipboardData.getData=="function"?i.clipboardData.getData("text/plain"):"";l&&(i.preventDefault&&i.preventDefault(),this.pasteText(l))}),this._addListener(t,"input",()=>{if(this.isCommandRunning()){t.value="";return}t.value!==this.buffer&&(this.buffer=t.value,this.cursor=typeof t.selectionStart=="number"?t.selectionStart:this.buffer.length,this.updateActiveLine())})),n&&this._addListener(n,"submit",i=>{i&&typeof i.preventDefault=="function"&&i.preventDefault(),this.submitLine()})}_findReverseSearchMatch(e,t){if(!e||!this.history.length)return-1;const n=typeof t=="number"?Math.min(t,this.history.length-1):this.history.length-1;for(let i=n;i>=0;i--)if(this.history[i]&&this.history[i].includes(e))return i;return-1}handleKeyDown(e){if(!e)return;if(this.onKey)try{if(this.onKey(e)===!1)return}catch(r){b.warn("Terminal onKey callback threw.",r)}const t=e.key,n=!!(e.ctrlKey&&!e.metaKey),i=!!(e.metaKey&&!e.ctrlKey),l=!!(e.ctrlKey||e.metaKey);if(l&&(t==="l"||t==="L")||i&&(t==="k"||t==="K")){e.preventDefault&&e.preventDefault(),this.clear();return}if(!(i&&(t==="c"||t==="C"))&&!(i&&(t==="v"||t==="V"))){if(n&&(t==="c"||t==="C")){if(e.shiftKey||!this.isBusy&&typeof window<"u"&&typeof window.getSelection=="function"&&String(window.getSelection()).length>0)return;e.preventDefault&&e.preventDefault();const s=this.isBusy||this._readLineQueue&&this._readLineQueue.length>0;this.isBusy=!1;const f=this._pushLog({type:"system",text:s?"^C":`${this.getPrompt()}${this.buffer}^C`});if(this._appendDomLine(f),this._activeLineCommitted=!0,this._activeLineEl=null,this.buffer="",this.cursor=0,this.historyIdx=-1,this._drainReadLineQueue(null),this.replMode&&(this.replMode=!1),this.onInterrupt)try{this.onInterrupt()}catch(p){b.warn("Terminal onInterrupt callback threw.",p)}this.updateActiveLine(),this._scrollToBottom();return}if(this.isCommandRunning()){e.preventDefault&&e.preventDefault();return}if(l&&(t==="r"||t==="R")){if(e.preventDefault&&e.preventDefault(),!this.searchMode)this.searchMode=!0,this.searchQuery="",this.searchMatchIdx=-1;else if(this.searchQuery){const r=this.searchMatchIdx>0?this.searchMatchIdx-1:this.history.length-1,s=this._findReverseSearchMatch(this.searchQuery,r);s!==-1&&(this.searchMatchIdx=s,this.buffer=this.history[s],this.cursor=this.buffer.length)}this.updateActiveLine();return}if(this.searchMode){if(t==="Escape"||l&&(t==="g"||t==="G")){e.preventDefault&&e.preventDefault(),this.searchMode=!1,this.searchQuery="",this.searchMatchIdx=-1,this.updateActiveLine();return}if(t==="Backspace"){e.preventDefault&&e.preventDefault(),this.searchQuery=this.searchQuery.slice(0,-1);const r=this._findReverseSearchMatch(this.searchQuery,this.history.length-1);this.searchMatchIdx=r,r!==-1&&(this.buffer=this.history[r],this.cursor=this.buffer.length),this.updateActiveLine();return}if(t==="Enter"){e.preventDefault&&e.preventDefault(),this.searchMode=!1,this.searchQuery="",this.searchMatchIdx=-1,this.submitLine();return}if(t&&t.length===1&&!l&&!e.altKey){e.preventDefault&&e.preventDefault(),this.searchQuery+=t;const r=this._findReverseSearchMatch(this.searchQuery,this.history.length-1);this.searchMatchIdx=r,r!==-1&&(this.buffer=this.history[r],this.cursor=this.buffer.length),this.updateActiveLine();return}this.searchMode=!1,this.searchQuery="",this.searchMatchIdx=-1}if(e.altKey&&(t==="b"||t==="B"||t==="ArrowLeft")||n&&t==="ArrowLeft"){e.preventDefault&&e.preventDefault();let r=this.cursor;for(;r>0&&/\s/.test(this.buffer[r-1]);)r--;for(;r>0&&!/\s/.test(this.buffer[r-1]);)r--;this.cursor=r,this.updateActiveLine();return}if(e.altKey&&(t==="f"||t==="F"||t==="ArrowRight")||n&&t==="ArrowRight"){e.preventDefault&&e.preventDefault();let r=this.cursor;for(;r<this.buffer.length&&/\s/.test(this.buffer[r]);)r++;for(;r<this.buffer.length&&!/\s/.test(this.buffer[r]);)r++;this.cursor=r,this.updateActiveLine();return}if(n&&(t==="w"||t==="W")||e.altKey&&t==="Backspace"){e.preventDefault&&e.preventDefault();let r=this.cursor;for(;r>0&&/\s/.test(this.buffer[r-1]);)r--;for(;r>0&&!/\s/.test(this.buffer[r-1]);)r--;this.buffer=this.buffer.slice(0,r)+this.buffer.slice(this.cursor),this.cursor=r,this.updateActiveLine();return}if(t==="ArrowLeft"){e.preventDefault&&e.preventDefault(),this.cursor>0&&(this.cursor--,this.updateActiveLine());return}if(t==="ArrowRight"){e.preventDefault&&e.preventDefault(),this.cursor<this.buffer.length&&(this.cursor++,this.updateActiveLine());return}if(t==="Home"||l&&(t==="a"||t==="A")){e.preventDefault&&e.preventDefault(),this.cursor=0,this.updateActiveLine();return}if(t==="End"||l&&(t==="e"||t==="E")){e.preventDefault&&e.preventDefault(),this.cursor=this.buffer.length,this.updateActiveLine();return}if(l&&(t==="u"||t==="U")){e.preventDefault&&e.preventDefault(),this.buffer=this.buffer.slice(this.cursor),this.cursor=0,this.updateActiveLine();return}if(l&&(t==="k"||t==="K")){e.preventDefault&&e.preventDefault(),this.buffer=this.buffer.slice(0,this.cursor),this.updateActiveLine();return}if(t==="Backspace"){e.preventDefault&&e.preventDefault(),this.cursor>0&&(this.buffer=this.buffer.slice(0,this.cursor-1)+this.buffer.slice(this.cursor),this.cursor--,this.updateActiveLine());return}if(t==="Delete"){e.preventDefault&&e.preventDefault(),this.cursor<this.buffer.length&&(this.buffer=this.buffer.slice(0,this.cursor)+this.buffer.slice(this.cursor+1),this.updateActiveLine());return}if(l&&(t==="d"||t==="D")&&this.buffer===""){if(e.preventDefault&&e.preventDefault(),this._readLineQueue&&this._readLineQueue.length>0){this._drainReadLineQueue(null),this.updateActiveLine();return}if(this.replMode){this._pushLog({type:"system",text:`${this.getPrompt()}.exit`}),this.replMode=!1,this.render();return}}if(t==="ArrowUp"){if(e.preventDefault&&e.preventDefault(),!this.history.length)return;this.historyIdx===-1?(this.savedBuffer=this.buffer,this.historyIdx=this.history.length-1):this.historyIdx>0&&this.historyIdx--,this.buffer=this.history[this.historyIdx]||"",this.cursor=this.buffer.length,this.updateActiveLine();return}if(t==="ArrowDown"){e.preventDefault&&e.preventDefault(),this.historyIdx!==-1&&(this.historyIdx<this.history.length-1?(this.historyIdx++,this.buffer=this.history[this.historyIdx]||""):(this.historyIdx=-1,this.buffer=this.savedBuffer||""),this.cursor=this.buffer.length,this.updateActiveLine());return}if(t==="Tab"){e.preventDefault&&e.preventDefault(),this.autoComplete();return}if(t==="Enter"){e.preventDefault&&e.preventDefault(),this.submitLine();return}t&&t.length===1&&!l&&!e.altKey&&(e.preventDefault&&e.preventDefault(),this.buffer=this.buffer.slice(0,this.cursor)+t+this.buffer.slice(this.cursor),this.cursor++,this.updateActiveLine())}}async pasteText(e){if(!e||this.isCommandRunning())return;const t=String(e).replace(/\r\n/g,`
28
+ `,t)}isCommandRunning(){return!!(this.isBusy&&(!this._readLineQueue||this._readLineQueue.length===0))}_pushLog(e){const t={type:L(e&&e.type),text:String(e&&e.text!=null?e.text:"")};if(this.logs.push(t),this.logs.length>this.maxScrollback){const n=this.logs.length-this.maxScrollback;if(this.logs.splice(0,n),this._targetLineIdx>=0&&(this._targetLineIdx=Math.max(0,this._targetLineIdx-n)),this.container&&typeof this.container.querySelector=="function"){const i=this.container.querySelector("#cl-terminal-log");if(i&&i.children&&i.children.length>this.maxScrollback)for(;i.children.length>this.maxScrollback&&typeof i.removeChild=="function"&&i.firstChild;)i.removeChild(i.firstChild)}}return t}_getActiveLine(e){if(this._targetLineIdx>=0&&this._targetLineIdx<this.logs.length)return this.logs[this._targetLineIdx];if(this._activeLineCommitted||this.logs.length===0){const t=this._pushLog({text:"",type:e});return this._activeLineCommitted=!1,this._cursorCol=0,this._targetLineIdx=this.logs.length-1,this._needsRewrite=!1,this._appendDomLine(t),t}return this._targetLineIdx=this.logs.length-1,this.logs[this.logs.length-1]}_appendDomLine(e){if(!this.container||typeof document>"u")return;const t=this.container.querySelector("#cl-terminal-log");if(!t)return;const n=document.createElement("div");n.className="codelab-log-line "+L(e.type),n.innerHTML=_(e.text),t.appendChild(n),this._activeLineEl=n}_updateActiveDomLine(){if(!this.container||typeof document>"u")return;const e=this._getActiveLineSync();if(!e)return;let t=this._activeLineEl;if(!t||!t.parentNode){const n=this.container.querySelector("#cl-terminal-log");n&&(this._targetLineIdx>=0&&this._targetLineIdx<n.children.length?t=n.children[this._targetLineIdx]:t=n.children[n.children.length-1],this._activeLineEl=t)}t&&(t.className="codelab-log-line "+L(e.type),t.innerHTML=_(e.text))}_getActiveLineSync(){return this._targetLineIdx>=0&&this._targetLineIdx<this.logs.length?this.logs[this._targetLineIdx]:this.logs[this.logs.length-1]||null}_scrollToBottom(){if(!this.container)return;const e=this.container.querySelector("#cl-terminal-surface")||this.container;e&&typeof e.scrollTop=="number"&&typeof e.scrollHeight=="number"&&(e.scrollTop=e.scrollHeight)}clear(){if(this.logs.length=0,this._activeLineCommitted=!0,this._cursorCol=0,this._targetLineIdx=-1,this._needsRewrite=!1,this._activeLineEl=null,this.container&&typeof this.container.querySelector=="function"){const e=this.container.querySelector("#cl-terminal-log");e&&(e.innerHTML="")}}getHistory(){return[...this.history]}_activateNextReadLine(){if(!this._readLineQueue||this._readLineQueue.length===0)return;const e=this._readLineQueue[0];e&&typeof e=="object"&&!e._activated&&(e._activated=!0,e.prevPrompt=this.promptOverride,e.promptText&&(this.promptOverride=e.promptText))}_drainReadLineQueue(e=null){if(!Array.isArray(this._readLineQueue)||this._readLineQueue.length===0)return;const t=this._readLineQueue.splice(0,this._readLineQueue.length);let n;for(const i of t)i&&typeof i=="object"&&i._activated&&n===void 0&&(n=i.prevPrompt),i&&typeof i.cleanup=="function"&&i.cleanup();n!==void 0&&(this.promptOverride=n);for(const i of t)if(typeof i=="function")try{i(e)}catch(l){b.debug("readLine callback threw during drain.",l)}else if(i&&typeof i.resolve=="function")try{i.resolve(e)}catch(l){b.debug("readLine resolve threw during drain.",l)}}readLine(e="",t={}){return t&&t.signal&&t.signal.aborted?Promise.resolve(null):new Promise(n=>{const i={promptText:String(e||""),prevPrompt:null,_activated:!1,cleanup:null,resolve:n};if(t&&t.signal&&typeof t.signal.addEventListener=="function"){const l=()=>{const r=this._readLineQueue.indexOf(i);r!==-1&&(this._readLineQueue.splice(r,1),i._activated&&(this.promptOverride=i.prevPrompt,this._activateNextReadLine()),this.updateActiveLine(),n(null))};t.signal.addEventListener("abort",l,{once:!0}),i.cleanup=()=>{try{t.signal.removeEventListener("abort",l)}catch(r){b.debug("readLine abort listener cleanup failed.",r)}}}this._readLineQueue.push(i),this._activateNextReadLine(),this.updateActiveLine()})}focus(){if(!this.container||typeof this.container.querySelector!="function")return;const e=this.container.querySelector("#cl-repl-input");if(e&&typeof e.focus=="function")try{e.focus()}catch(t){b.debug("Terminal input focus skipped.",t)}}mount(e){if(typeof e=="string"&&typeof document<"u"&&(e=document.querySelector(e)),this.container=e||null,!this.container||typeof this.container.querySelector!="function"){this._mounted=!1;return}this._mounted=!0,this.render()}_cleanupListeners(){if(!Array.isArray(this._listeners)){this._listeners=[];return}for(const e of this._listeners)if(typeof e=="function")try{e()}catch(t){b.debug("Terminal listener cleanup callback failed.",t)}else if(e&&e.target&&typeof e.target.removeEventListener=="function")try{e.target.removeEventListener(e.type,e.handler)}catch(t){b.debug("Terminal removeEventListener failed.",t)}this._listeners=[]}destroy(){this._drainReadLineQueue(null),this._cleanupListeners(),this._mounted=!1}_addListener(e,t,n){e&&typeof e.addEventListener=="function"&&(e.addEventListener(t,n),this._listeners.push({target:e,type:t,handler:n}))}_bindEvents(){if(this._cleanupListeners(),!this.container||typeof this.container.querySelector!="function")return;const e=this.container.querySelector("#cl-terminal-surface")||this.container,t=this.container.querySelector("#cl-repl-input"),n=this.container.querySelector("#cl-repl-form");e&&this._addListener(e,"click",i=>{if(i&&i.target===t)return;typeof window<"u"&&window.getSelection&&String(window.getSelection())||this.focus()}),t&&(this._addListener(t,"keydown",i=>this.handleKeyDown(i)),this._addListener(t,"paste",i=>{const l=i&&i.clipboardData&&typeof i.clipboardData.getData=="function"?i.clipboardData.getData("text/plain"):"";l&&(i.preventDefault&&i.preventDefault(),this.pasteText(l))}),this._addListener(t,"input",()=>{if(this.isCommandRunning()){t.value="";return}t.value!==this.buffer&&(this.buffer=t.value,this.cursor=typeof t.selectionStart=="number"?t.selectionStart:this.buffer.length,this.updateActiveLine())})),n&&this._addListener(n,"submit",i=>{i&&typeof i.preventDefault=="function"&&i.preventDefault(),this.submitLine()})}_findReverseSearchMatch(e,t){if(!e||!this.history.length)return-1;const n=typeof t=="number"?Math.min(t,this.history.length-1):this.history.length-1;for(let i=n;i>=0;i--)if(this.history[i]&&this.history[i].includes(e))return i;return-1}handleKeyDown(e){if(!e)return;if(this.onKey)try{if(this.onKey(e)===!1)return}catch(r){b.warn("Terminal onKey callback threw.",r)}const t=e.key,n=!!(e.ctrlKey&&!e.metaKey),i=!!(e.metaKey&&!e.ctrlKey),l=!!(e.ctrlKey||e.metaKey);if(l&&(t==="l"||t==="L")||i&&(t==="k"||t==="K")){e.preventDefault&&e.preventDefault(),this.clear();return}if(!(i&&(t==="c"||t==="C"))&&!(i&&(t==="v"||t==="V"))){if(n&&(t==="c"||t==="C")){if(e.shiftKey||!this.isBusy&&typeof window<"u"&&typeof window.getSelection=="function"&&String(window.getSelection()).length>0)return;e.preventDefault&&e.preventDefault();const s=this.isBusy||this._readLineQueue&&this._readLineQueue.length>0;this.isBusy=!1;const f=this._pushLog({type:"system",text:s?"^C":`${this.getPrompt()}${this.buffer}^C`});if(this._appendDomLine(f),this._activeLineCommitted=!0,this._activeLineEl=null,this.buffer="",this.cursor=0,this.historyIdx=-1,this._drainReadLineQueue(null),this.replMode&&(this.replMode=!1),this.onInterrupt)try{this.onInterrupt()}catch(p){b.warn("Terminal onInterrupt callback threw.",p)}this.updateActiveLine(),this._scrollToBottom();return}if(this.isCommandRunning()){e.preventDefault&&e.preventDefault();return}if(l&&(t==="r"||t==="R")){if(e.preventDefault&&e.preventDefault(),!this.searchMode)this.searchMode=!0,this.searchQuery="",this.searchMatchIdx=-1;else if(this.searchQuery){const r=this.searchMatchIdx>0?this.searchMatchIdx-1:this.history.length-1,s=this._findReverseSearchMatch(this.searchQuery,r);s!==-1&&(this.searchMatchIdx=s,this.buffer=this.history[s],this.cursor=this.buffer.length)}this.updateActiveLine();return}if(this.searchMode){if(t==="Escape"||l&&(t==="g"||t==="G")){e.preventDefault&&e.preventDefault(),this.searchMode=!1,this.searchQuery="",this.searchMatchIdx=-1,this.updateActiveLine();return}if(t==="Backspace"){e.preventDefault&&e.preventDefault(),this.searchQuery=this.searchQuery.slice(0,-1);const r=this._findReverseSearchMatch(this.searchQuery,this.history.length-1);this.searchMatchIdx=r,r!==-1&&(this.buffer=this.history[r],this.cursor=this.buffer.length),this.updateActiveLine();return}if(t==="Enter"){e.preventDefault&&e.preventDefault(),this.searchMode=!1,this.searchQuery="",this.searchMatchIdx=-1,this.submitLine();return}if(t&&t.length===1&&!l&&!e.altKey){e.preventDefault&&e.preventDefault(),this.searchQuery+=t;const r=this._findReverseSearchMatch(this.searchQuery,this.history.length-1);this.searchMatchIdx=r,r!==-1&&(this.buffer=this.history[r],this.cursor=this.buffer.length),this.updateActiveLine();return}this.searchMode=!1,this.searchQuery="",this.searchMatchIdx=-1}if(e.altKey&&(t==="b"||t==="B"||t==="ArrowLeft")||n&&t==="ArrowLeft"){e.preventDefault&&e.preventDefault();let r=this.cursor;for(;r>0&&/\s/.test(this.buffer[r-1]);)r--;for(;r>0&&!/\s/.test(this.buffer[r-1]);)r--;this.cursor=r,this.updateActiveLine();return}if(e.altKey&&(t==="f"||t==="F"||t==="ArrowRight")||n&&t==="ArrowRight"){e.preventDefault&&e.preventDefault();let r=this.cursor;for(;r<this.buffer.length&&/\s/.test(this.buffer[r]);)r++;for(;r<this.buffer.length&&!/\s/.test(this.buffer[r]);)r++;this.cursor=r,this.updateActiveLine();return}if(n&&(t==="w"||t==="W")||e.altKey&&t==="Backspace"){e.preventDefault&&e.preventDefault();let r=this.cursor;for(;r>0&&/\s/.test(this.buffer[r-1]);)r--;for(;r>0&&!/\s/.test(this.buffer[r-1]);)r--;this.buffer=this.buffer.slice(0,r)+this.buffer.slice(this.cursor),this.cursor=r,this.updateActiveLine();return}if(t==="ArrowLeft"){e.preventDefault&&e.preventDefault(),this.cursor>0&&(this.cursor--,this.updateActiveLine());return}if(t==="ArrowRight"){e.preventDefault&&e.preventDefault(),this.cursor<this.buffer.length&&(this.cursor++,this.updateActiveLine());return}if(t==="Home"||e.ctrlKey&&!e.metaKey&&(t==="a"||t==="A")){e.preventDefault&&e.preventDefault(),this.cursor=0,this.updateActiveLine();return}if(t==="End"||l&&(t==="e"||t==="E")){e.preventDefault&&e.preventDefault(),this.cursor=this.buffer.length,this.updateActiveLine();return}if(l&&(t==="u"||t==="U")){e.preventDefault&&e.preventDefault(),this.buffer=this.buffer.slice(this.cursor),this.cursor=0,this.updateActiveLine();return}if(l&&(t==="k"||t==="K")){e.preventDefault&&e.preventDefault(),this.buffer=this.buffer.slice(0,this.cursor),this.updateActiveLine();return}if(t==="Backspace"){e.preventDefault&&e.preventDefault(),this.cursor>0&&(this.buffer=this.buffer.slice(0,this.cursor-1)+this.buffer.slice(this.cursor),this.cursor--,this.updateActiveLine());return}if(t==="Delete"){e.preventDefault&&e.preventDefault(),this.cursor<this.buffer.length&&(this.buffer=this.buffer.slice(0,this.cursor)+this.buffer.slice(this.cursor+1),this.updateActiveLine());return}if(l&&(t==="d"||t==="D")&&this.buffer===""){if(e.preventDefault&&e.preventDefault(),this._readLineQueue&&this._readLineQueue.length>0){this._drainReadLineQueue(null),this.updateActiveLine();return}if(this.replMode){this._pushLog({type:"system",text:`${this.getPrompt()}.exit`}),this.replMode=!1,this.render();return}}if(t==="ArrowUp"){if(e.preventDefault&&e.preventDefault(),!this.history.length)return;this.historyIdx===-1?(this.savedBuffer=this.buffer,this.historyIdx=this.history.length-1):this.historyIdx>0&&this.historyIdx--,this.buffer=this.history[this.historyIdx]||"",this.cursor=this.buffer.length,this.updateActiveLine();return}if(t==="ArrowDown"){e.preventDefault&&e.preventDefault(),this.historyIdx!==-1&&(this.historyIdx<this.history.length-1?(this.historyIdx++,this.buffer=this.history[this.historyIdx]||""):(this.historyIdx=-1,this.buffer=this.savedBuffer||""),this.cursor=this.buffer.length,this.updateActiveLine());return}if(t==="Tab"){e.preventDefault&&e.preventDefault(),this.autoComplete();return}if(t==="Enter"){e.preventDefault&&e.preventDefault(),this.submitLine();return}t&&t.length===1&&!l&&!e.altKey&&(e.preventDefault&&e.preventDefault(),this.buffer=this.buffer.slice(0,this.cursor)+t+this.buffer.slice(this.cursor),this.cursor++,this.updateActiveLine())}}async pasteText(e){if(!e||this.isCommandRunning())return;const t=String(e).replace(/\r\n/g,`
29
29
  `).replace(/\r/g,`
30
30
  `);if(!t.includes(`
31
31
  `)){this.buffer=this.buffer.slice(0,this.cursor)+t+this.buffer.slice(this.cursor),this.cursor+=t.length,this.updateActiveLine();return}const n=t.split(`
32
- `);for(let i=0;i<n.length;i++){const l=n[i];if(i<n.length-1)for(this.buffer=this.buffer.slice(0,this.cursor)+l+this.buffer.slice(this.cursor),this.cursor=this.buffer.length,this.submitLine();this.isCommandRunning();)await new Promise(r=>setTimeout(r,10));else l.length>0&&(this.buffer=l,this.cursor=l.length,this.updateActiveLine())}}autoComplete(){if(!this.getCompletions)return;const e=this.getCompletions(this.buffer,this.cursor);if(!e||!Array.isArray(e.matches)||e.matches.length===0)return;const t=e.matches;if(t.length===1){const n=t[0],l=n.endsWith("/")?"":" ",r=this.buffer.slice(0,e.tokenStart),s=this.buffer.slice(this.cursor);this.buffer=r+n+l+s,this.cursor=r.length+n.length+l.length,this.updateActiveLine()}else{let n=t[0];for(let i=1;i<t.length;i++){let l=0;for(;l<n.length&&l<t[i].length&&n[l]===t[i][l];)l++;n=n.slice(0,l)}if(n.length>e.token.length){const i=this.buffer.slice(0,e.tokenStart),l=this.buffer.slice(this.cursor);this.buffer=i+n+l,this.cursor=i.length+n.length}this._pushLog({type:"system",text:`${this.getPrompt()}${this.buffer}`}),this._pushLog({type:"stdout",text:t.join(" ")}),this.render()}}submitLine(){if(this._readLineQueue&&this._readLineQueue.length>0){const l=this.buffer;this.buffer="",this.cursor=0,this.historyIdx=-1,this.searchMode=!1,this.searchQuery="",this.searchMatchIdx=-1;const r=this._readLineQueue.shift();r&&typeof r.cleanup=="function"&&r.cleanup(),typeof r=="function"?(this.updateActiveLine(),r(l)):r&&typeof r.resolve=="function"&&(this.promptOverride=r.prevPrompt,this._activateNextReadLine(),this.updateActiveLine(),r.resolve(l));return}if(this.isBusy)return;const e=this.buffer,t=this.getPrompt();this.buffer="",this.cursor=0,this.historyIdx=-1,this.searchMode=!1,this.searchQuery="",this.searchMatchIdx=-1;const n=this._pushLog({type:"system",text:`${t}${e}`});if(this._activeLineCommitted=!0,this._cursorCol=0,this._targetLineIdx=-1,this._needsRewrite=!1,this._appendDomLine(n),this._activeLineEl=null,e.trim()&&this.history[this.history.length-1]!==e.trim()){this.history.push(e.trim());const l=typeof this.maxHistory=="number"&&this.maxHistory>0?this.maxHistory:1e3;this.history.length>l&&this.history.splice(0,this.history.length-l)}if(!this.onCommand){this.updateActiveLine();return}this.isBusy=!0,this.updateActiveLine();let i;try{i=this.onCommand(e)}catch(l){throw this.isBusy=!1,this.updateActiveLine(),l}i&&typeof i.then=="function"?Promise.resolve(i).catch(l=>{b.debug("Terminal onCommand promise rejected.",l)}).finally(()=>{this.isBusy=!1,this.updateActiveLine()}):(this.isBusy=!1,this.updateActiveLine())}updateActiveLine(){if(!this.container||typeof this.container.querySelector!="function")return;const e=this.container.querySelector("#cl-repl-input");e&&e.value!==this.buffer&&(e.value=this.buffer);const t=this.container.querySelector("#cl-pty-active-line");if(!t)return;if(this.isCommandRunning()){typeof t.setAttribute=="function"&&t.setAttribute("data-busy","true"),t.style&&(t.style.display="none"),t.innerHTML='<span class="codelab-pty__prompt"></span><span class="codelab-pty__before"></span><span class="codelab-pty__cursor"></span><span class="codelab-pty__after"></span>';return}typeof t.removeAttribute=="function"&&t.removeAttribute("data-busy"),t.style&&(t.style.display="");const n=this.searchMode?`(reverse-i-search)\`${this.searchQuery}\`: `:this.getPrompt(),i=this.buffer.slice(0,this.cursor),l=this.cursor<this.buffer.length?this.buffer[this.cursor]:" ",r=this.cursor<this.buffer.length?this.buffer.slice(this.cursor+1):"";t.innerHTML=`<span class="codelab-pty__prompt">${y(n)}</span><span class="codelab-pty__before">${y(i)}</span><span class="codelab-pty__cursor blink">${y(l)}</span><span class="codelab-pty__after">${y(r)}</span>`}render(){if(!this.container||typeof this.container.querySelector!="function")return;const e=this.container.querySelector("#cl-repl-input"),t=!!(e&&typeof document<"u"&&document.activeElement===e),n=this.logs.map(a=>`<div class="codelab-log-line ${L(a.type)}">${_(a.text)}</div>`).join(""),i=this.isCommandRunning(),l=i?"":this.searchMode?`(reverse-i-search)\`${this.searchQuery}\`: `:this.getPrompt(),r=i?"":this.buffer.slice(0,this.cursor),s=i?"":this.cursor<this.buffer.length?this.buffer[this.cursor]:" ",f=i?"":this.cursor<this.buffer.length?this.buffer.slice(this.cursor+1):"",p=i?' data-busy="true" style="display:none;"':"",c=i?"codelab-pty__cursor":"codelab-pty__cursor blink";if(this.container.innerHTML=`
32
+ `);for(let i=0;i<n.length;i++){const l=n[i];if(i<n.length-1){for(this.buffer=this.buffer.slice(0,this.cursor)+l+this.buffer.slice(this.cursor),this.cursor=this.buffer.length,this.submitLine();this._mounted&&this.isCommandRunning();)await new Promise(r=>setTimeout(r,10));if(!this._mounted)return}else l.length>0&&(this.buffer=l,this.cursor=l.length,this.updateActiveLine())}}autoComplete(){if(!this.getCompletions)return;const e=this.getCompletions(this.buffer,this.cursor);if(!e||!Array.isArray(e.matches)||e.matches.length===0)return;const t=e.matches;if(t.length===1){const n=t[0],l=n.endsWith("/")?"":" ",r=this.buffer.slice(0,e.tokenStart),s=this.buffer.slice(this.cursor);this.buffer=r+n+l+s,this.cursor=r.length+n.length+l.length,this.updateActiveLine()}else{let n=t[0];for(let i=1;i<t.length;i++){let l=0;for(;l<n.length&&l<t[i].length&&n[l]===t[i][l];)l++;n=n.slice(0,l)}if(n.length>e.token.length){const i=this.buffer.slice(0,e.tokenStart),l=this.buffer.slice(this.cursor);this.buffer=i+n+l,this.cursor=i.length+n.length}this._pushLog({type:"system",text:`${this.getPrompt()}${this.buffer}`}),this._pushLog({type:"stdout",text:t.join(" ")}),this.render()}}submitLine(){if(this._readLineQueue&&this._readLineQueue.length>0){const l=this.buffer;this.buffer="",this.cursor=0,this.historyIdx=-1,this.searchMode=!1,this.searchQuery="",this.searchMatchIdx=-1;const r=this._readLineQueue.shift();r&&typeof r.cleanup=="function"&&r.cleanup(),typeof r=="function"?(this.updateActiveLine(),r(l)):r&&typeof r.resolve=="function"&&(this.promptOverride=r.prevPrompt,this._activateNextReadLine(),this.updateActiveLine(),r.resolve(l));return}if(this.isBusy)return;const e=this.buffer,t=this.getPrompt();this.buffer="",this.cursor=0,this.historyIdx=-1,this.searchMode=!1,this.searchQuery="",this.searchMatchIdx=-1;const n=this._pushLog({type:"system",text:`${t}${e}`});if(this._activeLineCommitted=!0,this._cursorCol=0,this._targetLineIdx=-1,this._needsRewrite=!1,this._appendDomLine(n),this._activeLineEl=null,e.trim()&&this.history[this.history.length-1]!==e.trim()){this.history.push(e.trim());const l=typeof this.maxHistory=="number"&&this.maxHistory>0?this.maxHistory:1e3;this.history.length>l&&this.history.splice(0,this.history.length-l)}if(!this.onCommand){this.updateActiveLine();return}this.isBusy=!0,this.updateActiveLine();let i;try{i=this.onCommand(e)}catch(l){throw this.isBusy=!1,this.updateActiveLine(),l}i&&typeof i.then=="function"?Promise.resolve(i).catch(l=>{b.debug("Terminal onCommand promise rejected.",l)}).finally(()=>{this.isBusy=!1,this.updateActiveLine()}):(this.isBusy=!1,this.updateActiveLine())}updateActiveLine(){if(!this.container||typeof this.container.querySelector!="function")return;const e=this.container.querySelector("#cl-repl-input");e&&e.value!==this.buffer&&(e.value=this.buffer);const t=this.container.querySelector("#cl-pty-active-line");if(!t)return;if(this.isCommandRunning()){typeof t.setAttribute=="function"&&t.setAttribute("data-busy","true"),t.style&&(t.style.display="none"),t.innerHTML='<span class="codelab-pty__prompt"></span><span class="codelab-pty__before"></span><span class="codelab-pty__cursor"></span><span class="codelab-pty__after"></span>';return}typeof t.removeAttribute=="function"&&t.removeAttribute("data-busy"),t.style&&(t.style.display="");const n=this.searchMode?`(reverse-i-search)\`${this.searchQuery}\`: `:this.getPrompt(),i=this.buffer.slice(0,this.cursor),l=this.cursor<this.buffer.length?this.buffer[this.cursor]:" ",r=this.cursor<this.buffer.length?this.buffer.slice(this.cursor+1):"";t.innerHTML=`<span class="codelab-pty__prompt">${y(n)}</span><span class="codelab-pty__before">${y(i)}</span><span class="codelab-pty__cursor blink">${y(l)}</span><span class="codelab-pty__after">${y(r)}</span>`}render(){if(!this.container||typeof this.container.querySelector!="function")return;const e=this.container.querySelector("#cl-repl-input"),t=!!(e&&typeof document<"u"&&document.activeElement===e),n=this.logs.map(a=>`<div class="codelab-log-line ${L(a.type)}">${_(a.text)}</div>`).join(""),i=this.isCommandRunning(),l=i?"":this.searchMode?`(reverse-i-search)\`${this.searchQuery}\`: `:this.getPrompt(),r=i?"":this.buffer.slice(0,this.cursor),s=i?"":this.cursor<this.buffer.length?this.buffer[this.cursor]:" ",f=i?"":this.cursor<this.buffer.length?this.buffer.slice(this.cursor+1):"",p=i?' data-busy="true" style="display:none;"':"",c=i?"codelab-pty__cursor":"codelab-pty__cursor blink";if(this.container.innerHTML=`
33
33
  <div class="codelab-terminal" id="cl-terminal-surface" tabindex="0">
34
34
  <div class="codelab-terminal__log" id="cl-terminal-log">${n}</div>
35
35
  <div class="codelab-pty__active-line" id="cl-pty-active-line"${p}>
@@ -39,7 +39,7 @@ var CodeLabLogger=(()=>{var s=Object.defineProperty;var p=Object.getOwnPropertyD
39
39
  <input type="text" class="codelab-repl__input" id="cl-repl-input" autocomplete="off" spellcheck="false" aria-label="Terminal command input" value="${y(this.buffer)}">
40
40
  </form>
41
41
  </div>
42
- `,this._scrollToBottom(),this._bindEvents(),t){const a=this.container.querySelector("#cl-repl-input");if(a&&typeof a.focus=="function")try{a.focus(),typeof a.setSelectionRange=="function"&&a.setSelectionRange(this.cursor,this.cursor)}catch(d){b.debug("Terminal focus/selection restore skipped.",d)}}}}function A(u,e={}){return new w(u,e)}return{PTYTerminalEngine:w,createPTYTerminalEngine:A,createTerminal:A,ansiToHtml:_,parseAnsiToHtml:M,escapeHtml:y,ANSI_CODE_MAP:m,resolveAnsiControlCodes:C}});
42
+ `,this._scrollToBottom(),this._bindEvents(),t){const a=this.container.querySelector("#cl-repl-input");if(a&&typeof a.focus=="function")try{a.focus(),typeof a.setSelectionRange=="function"&&a.setSelectionRange(this.cursor,this.cursor)}catch(d){b.debug("Terminal focus/selection restore skipped.",d)}}}}function D(u,e={}){return new A(u,e)}return{PTYTerminalEngine:A,createPTYTerminalEngine:D,createTerminal:D,ansiToHtml:_,parseAnsiToHtml:M,escapeHtml:y,ANSI_CODE_MAP:m,ansi256ToColor:C,resolveAnsiControlCodes:w}});
43
43
 
44
44
  })();
45
45
 
@@ -51,6 +51,7 @@ const ansiToHtml = CodeLabTerminal.ansiToHtml;
51
51
  const parseAnsiToHtml = CodeLabTerminal.parseAnsiToHtml;
52
52
  const escapeHtml = CodeLabTerminal.escapeHtml;
53
53
  const ANSI_CODE_MAP = CodeLabTerminal.ANSI_CODE_MAP;
54
+ const ansi256ToColor = CodeLabTerminal.ansi256ToColor;
54
55
  const resolveAnsiControlCodes = CodeLabTerminal.resolveAnsiControlCodes;
55
56
 
56
57
  export {
@@ -62,6 +63,7 @@ export {
62
63
  parseAnsiToHtml,
63
64
  escapeHtml,
64
65
  ANSI_CODE_MAP,
66
+ ansi256ToColor,
65
67
  resolveAnsiControlCodes
66
68
  };
67
69
  export default CodeLabTerminal;
package/dist/terminal.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * ============================================================
3
- * @innovatorved/code-lab v0.6.1 — Standalone Browser Code IDE & Virtual Runtime
3
+ * @innovatorved/code-lab v0.7.1 — Standalone Browser Code IDE & Virtual Runtime
4
4
  * ============================================================
5
5
  * Features:
6
6
  * - Sandboxed Web Worker Execution Engine with Multi-Instance Isolation & Watchdog Timer
@@ -19,18 +19,18 @@
19
19
  var CodeLabLogger=(()=>{var s=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var y=(o,n)=>{for(var a in n)s(o,a,{get:n[a],enumerable:!0})},v=(o,n,a,t)=>{if(n&&typeof n=="object"||typeof n=="function")for(let e of C(n))!x.call(o,e)&&e!==a&&s(o,e,{get:()=>n[e],enumerable:!(t=p(n,e))||t.enumerable});return o};var O=o=>v(s({},"__esModule",{value:!0}),o);var h={};y(h,{CodeLabError:()=>d,DEFAULT_LOGGER:()=>w,LOG_PREFIX:()=>c,createLogger:()=>g,default:()=>_,isCodeLabError:()=>f});var c="[code-lab]",d=class extends Error{code;options;cause;recoverable;details;context;constructor(n,a,t={}){super(a),this.name="CodeLabError",this.code=n,this.options=t,this.cause=t.cause,this.recoverable=t.recoverable!==!1;let e=t.details??t.context;e!==void 0&&(this.details=e,this.context=e),Object.setPrototypeOf(this,new.target.prototype)}};function f(o){return!!(o&&typeof o=="object"&&(o instanceof d||o.name==="CodeLabError"&&typeof o.code=="string"))}function g(o={}){let n=o.logger??null,a=o.debug===!0,t=o.prefix||c,e=(r,b)=>{if(r==="debug"&&!a)return;if(n&&typeof n[r]=="function"){let L=null;try{n[r](...b);return}catch(k){L=k}}let i=typeof console<"u"?console:null,l=i?i[r]:null;typeof l=="function"&&l.call(i,t,...b)};return{debug:(...r)=>e("debug",r),info:(...r)=>e("info",r),warn:(...r)=>e("warn",r),error:(...r)=>e("error",r)}}var w=g(),E={LOG_PREFIX:c,CodeLabError:d,isCodeLabError:f,createLogger:g,DEFAULT_LOGGER:w},u=typeof globalThis<"u"?globalThis:null;u&&!u.CodeLabLogger&&(u.CodeLabLogger=E);var _=E;return O(h);})();
20
20
 
21
21
  (function () {
22
- (function(g,b){const m=b();g&&(g.CodeLabTerminal=m,g.PTYTerminalEngine=m.PTYTerminalEngine,g.createPTYTerminalEngine=m.createPTYTerminalEngine,g.createTerminal=m.createTerminal,g.ansiToHtml=m.ansiToHtml,g.parseAnsiToHtml=m.parseAnsiToHtml),typeof module<"u"&&module.exports?module.exports=m:typeof define=="function"&&define.amd&&define([],function(){return m})})(typeof globalThis<"u"?globalThis:typeof window<"u"?window:this,function(){"use strict";const g=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{},b=g&&g.CodeLabLogger&&typeof g.CodeLabLogger.createLogger=="function"?g.CodeLabLogger.createLogger():{debug(){},info(...u){typeof console<"u"&&console.info&&console.info("[code-lab]",...u)},warn(...u){typeof console<"u"&&console.warn&&console.warn("[code-lab]",...u)},error(...u){typeof console<"u"&&console.error&&console.error("[code-lab]",...u)}},m={1:"cl-ansi-bold",2:"cl-ansi-dim",3:"cl-ansi-italic",4:"cl-ansi-underline",7:"cl-ansi-inverse",9:"cl-ansi-strike",30:"cl-ansi-black",31:"cl-ansi-red",32:"cl-ansi-green",33:"cl-ansi-yellow",34:"cl-ansi-blue",35:"cl-ansi-magenta",36:"cl-ansi-cyan",37:"cl-ansi-white",90:"cl-ansi-gray",91:"cl-ansi-bright-red",92:"cl-ansi-bright-green",93:"cl-ansi-bright-yellow",94:"cl-ansi-bright-blue",95:"cl-ansi-bright-magenta",96:"cl-ansi-bright-cyan",97:"cl-ansi-bright-white",40:"cl-ansi-bg-black",41:"cl-ansi-bg-red",42:"cl-ansi-bg-green",43:"cl-ansi-bg-yellow",44:"cl-ansi-bg-blue",45:"cl-ansi-bg-magenta",46:"cl-ansi-bg-cyan",47:"cl-ansi-bg-white",100:"cl-ansi-bg-bright-black",101:"cl-ansi-bg-bright-red",102:"cl-ansi-bg-bright-green",103:"cl-ansi-bg-bright-yellow",104:"cl-ansi-bg-bright-blue",105:"cl-ansi-bg-bright-magenta",106:"cl-ansi-bg-bright-cyan",107:"cl-ansi-bg-bright-white"},S=["#000000","#cd3131","#0dbc79","#e5e510","#2472c8","#bc3fbc","#11a8cd","#e5e5e5","#666666","#f14c4c","#23d18b","#f5f543","#3b8eea","#d670d6","#29b8db","#ffffff"];function I(u){const e=Number(u);if(!Number.isFinite(e)||e<0||e>255)return null;if(e<16)return S[e];if(e<232){const n=e-16,i=Math.floor(n/36),l=Math.floor(n%36/6),r=n%6,s=f=>f===0?0:55+f*40;return`rgb(${s(i)}, ${s(l)}, ${s(r)})`}const t=8+(e-232)*10;return`rgb(${t}, ${t}, ${t})`}function y(u){return u==null?"":String(u).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}function C(u){if(!u)return"";const e=String(u);if(!e.includes("\x1B")&&!e.includes("\r"))return e;let t=e;t=t.replace(/\x1b\]8;[^;]*;[^\x07\x1b]*(?:\x07|\x1b\\)([\s\S]*?)\x1b\]8;;(?:\x07|\x1b\\)/g,"$1"),t=t.replace(/\x1b\][^\x07\x1b]*(?:\x07|\x1b\\)/g,"");const n=t.lastIndexOf("\x1B[2J"),i=t.lastIndexOf("\x1B[3J"),l=t.lastIndexOf("\x1Bc"),r=Math.max(n,i,l);if(r!==-1){const p=r===l?2:4;t=t.slice(r+p),t=t.replace(/^(?:\x1b\[[23]J|\x1b\[(?:\d+;\d+)?H)+/,"")}t=t.replace(/\r\n/g,`
22
+ (function(g,b){const m=b();g&&(g.CodeLabTerminal=m,g.PTYTerminalEngine=m.PTYTerminalEngine,g.createPTYTerminalEngine=m.createPTYTerminalEngine,g.createTerminal=m.createTerminal,g.ansiToHtml=m.ansiToHtml,g.parseAnsiToHtml=m.parseAnsiToHtml),typeof module<"u"&&module.exports?module.exports=m:typeof define=="function"&&define.amd&&define([],function(){return m})})(typeof globalThis<"u"?globalThis:typeof window<"u"?window:this,function(){"use strict";const g=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{},b=g&&g.CodeLabLogger&&typeof g.CodeLabLogger.createLogger=="function"?g.CodeLabLogger.createLogger():{debug(){},info(...u){typeof console<"u"&&console.info&&console.info("[code-lab]",...u)},warn(...u){typeof console<"u"&&console.warn&&console.warn("[code-lab]",...u)},error(...u){typeof console<"u"&&console.error&&console.error("[code-lab]",...u)}},m={1:"cl-ansi-bold",2:"cl-ansi-dim",3:"cl-ansi-italic",4:"cl-ansi-underline",7:"cl-ansi-inverse",9:"cl-ansi-strike",30:"cl-ansi-black",31:"cl-ansi-red",32:"cl-ansi-green",33:"cl-ansi-yellow",34:"cl-ansi-blue",35:"cl-ansi-magenta",36:"cl-ansi-cyan",37:"cl-ansi-white",90:"cl-ansi-gray",91:"cl-ansi-bright-red",92:"cl-ansi-bright-green",93:"cl-ansi-bright-yellow",94:"cl-ansi-bright-blue",95:"cl-ansi-bright-magenta",96:"cl-ansi-bright-cyan",97:"cl-ansi-bright-white",40:"cl-ansi-bg-black",41:"cl-ansi-bg-red",42:"cl-ansi-bg-green",43:"cl-ansi-bg-yellow",44:"cl-ansi-bg-blue",45:"cl-ansi-bg-magenta",46:"cl-ansi-bg-cyan",47:"cl-ansi-bg-white",100:"cl-ansi-bg-bright-black",101:"cl-ansi-bg-bright-red",102:"cl-ansi-bg-bright-green",103:"cl-ansi-bg-bright-yellow",104:"cl-ansi-bg-bright-blue",105:"cl-ansi-bg-bright-magenta",106:"cl-ansi-bg-bright-cyan",107:"cl-ansi-bg-bright-white"},I=["#000000","#cd3131","#0dbc79","#e5e510","#2472c8","#bc3fbc","#11a8cd","#e5e5e5","#666666","#f14c4c","#23d18b","#f5f543","#3b8eea","#d670d6","#29b8db","#ffffff"];function C(u){const e=Number(u);if(!Number.isFinite(e)||e<0||e>255)return null;if(e<16)return I[e];if(e<232){const n=e-16,i=Math.floor(n/36),l=Math.floor(n%36/6),r=n%6,s=f=>f===0?0:55+f*40;return`rgb(${s(i)}, ${s(l)}, ${s(r)})`}const t=8+(e-232)*10;return`rgb(${t}, ${t}, ${t})`}function y(u){return u==null?"":String(u).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}function w(u){if(!u)return"";const e=String(u);if(!e.includes("\x1B")&&!e.includes("\r"))return e;let t=e;t=t.replace(/\x1b\]8;[^;]*;[^\x07\x1b]*(?:\x07|\x1b\\)([\s\S]*?)\x1b\]8;;(?:\x07|\x1b\\)/g,"$1"),t=t.replace(/\x1b\][^\x07\x1b]*(?:\x07|\x1b\\)/g,"");const n=t.lastIndexOf("\x1B[2J"),i=t.lastIndexOf("\x1B[3J"),l=t.lastIndexOf("\x1Bc"),r=Math.max(n,i,l);if(r!==-1){const p=r===l?2:4;t=t.slice(r+p),t=t.replace(/^(?:\x1b\[[23]J|\x1b\[(?:\d+;\d+)?H)+/,"")}t=t.replace(/\r\n/g,`
23
23
  `);const s=t.split(`
24
24
  `),f=[];for(let p=0;p<s.length;p++){let c=s[p];for(;/\x1b\[(?:1)?A/.test(c);){const a=/\x1b\[(?:1)?A/.exec(c),d=c.slice(0,a.index);let h=c.slice(a.index+a[0].length);if(f.length>0){if(h.includes("\x1B[2K"))h=h.slice(h.lastIndexOf("\x1B[2K")+4),f[f.length-1]=h;else if(h.includes("\r")){const o=h.split("\r");f[f.length-1]=o[o.length-1]}else f[f.length-1]=h;c=d}else c=d+h}if(c.includes("\x1B[2K")){const a=c.lastIndexOf("\x1B[2K");c=c.slice(a+4)}if(c.includes("\r")){const a=c.split("\r");c=a[a.length-1]}c=c.replace(/\x1b\[[0]?K/g,""),c=c.replace(/\x1b\[(?:1)?G/g,""),f.push(c)}return f.join(`
25
- `)}function _(u){if(!u)return"";const e=C(String(u));if(!e.includes("\x1B["))return y(e);const t=e.replace(/\x1b\[[0-9;?]*(?!m)[A-Za-z]/g,""),n=/\x1b\[([0-9;]*)m/g;let i="",l=0,r;const s={bold:!1,dim:!1,italic:!1,underline:!1,inverse:!1,strike:!1,fgClass:null,bgClass:null,fgColor:null,bgColor:null},f=()=>{s.bold=!1,s.dim=!1,s.italic=!1,s.underline=!1,s.inverse=!1,s.strike=!1,s.fgClass=null,s.bgClass=null,s.fgColor=null,s.bgColor=null},p=a=>{if(!a)return"";const d=y(a),h=[];s.bold&&h.push("cl-ansi-bold"),s.dim&&h.push("cl-ansi-dim"),s.italic&&h.push("cl-ansi-italic"),s.underline&&h.push("cl-ansi-underline"),s.inverse&&h.push("cl-ansi-inverse"),s.strike&&h.push("cl-ansi-strike"),s.fgClass&&h.push(s.fgClass),s.bgClass&&h.push(s.bgClass);const o=[];if(s.fgColor&&o.push(`color:${s.fgColor}`),s.bgColor&&o.push(`background-color:${s.bgColor}`),s.inverse&&!s.fgClass&&!s.bgClass&&o.push("filter:invert(1)"),s.strike&&o.push("text-decoration:line-through"),h.length===0&&o.length===0)return d;const v=h.length>0?` class="${h.join(" ")}"`:"",x=o.length>0?` style="${o.join(";")}"`:"";return`<span${v}${x}>${d}</span>`};for(;(r=n.exec(t))!==null;){const a=t.slice(l,r.index);a&&(i+=p(a)),l=n.lastIndex;const d=r[1]?r[1].split(";").map(Number):[0];for(let h=0;h<d.length;h++){const o=d[h];if(o===0||Number.isNaN(o))f();else if(o===1)s.bold=!0;else if(o===2)s.dim=!0;else if(o===3)s.italic=!0;else if(o===4)s.underline=!0;else if(o===7)s.inverse=!0;else if(o===9)s.strike=!0;else if(o===22)s.bold=!1,s.dim=!1;else if(o===23)s.italic=!1;else if(o===24)s.underline=!1;else if(o===27)s.inverse=!1;else if(o===29)s.strike=!1;else if(o===39)s.fgClass=null,s.fgColor=null;else if(o===49)s.bgClass=null,s.bgColor=null;else if((o===38||o===48)&&d[h+1]===5&&h+2<d.length){const v=I(d[h+2]);v&&(o===38?(s.fgClass=null,s.fgColor=v):(s.bgClass=null,s.bgColor=v)),h+=2}else if((o===38||o===48)&&d[h+1]===2&&h+4<d.length){const v=Math.max(0,Math.min(255,Number(d[h+2])||0)),x=Math.max(0,Math.min(255,Number(d[h+3])||0)),E=Math.max(0,Math.min(255,Number(d[h+4])||0)),D=`rgb(${v}, ${x}, ${E})`;o===38?(s.fgClass=null,s.fgColor=D):(s.bgClass=null,s.bgColor=D),h+=4}else o>=30&&o<=37||o>=90&&o<=97?(s.fgClass=m[o]||null,s.fgColor=null):(o>=40&&o<=47||o>=100&&o<=107)&&(s.bgClass=m[o]||null,s.bgColor=null)}}const c=t.slice(l);return c&&(i+=p(c)),i}const M=_,T=2e3,k=new Set(["stdout","stderr","system","info","warn","error","success"]);function L(u){const e=String(u||"stdout").trim();return k.has(e)?e:"stdout"}class w{constructor(e,t={}){e&&typeof e=="object"&&typeof e.querySelector!="function"&&typeof e.appendChild!="function"&&arguments.length===1&&(t=e,e=t.container||null),this.container=e||null,this.options=t||{},this.maxScrollback=typeof this.options.maxScrollback=="number"&&this.options.maxScrollback>0?this.options.maxScrollback:T,this.maxHistory=typeof this.options.maxHistory=="number"&&this.options.maxHistory>0?this.options.maxHistory:1e3,this.logs=Array.isArray(this.options.logs)?this.options.logs:[],this.cwd=this.options.cwd||"/workspace",this.replMode=!!this.options.replMode,this.promptOverride=this.options.prompt||null,this.history=Array.isArray(this.options.history)?this.options.history:[],this.historyIdx=-1,this.savedBuffer="",this.buffer="",this.cursor=0,this.searchMode=!1,this.searchQuery="",this.searchMatchIdx=-1,this._readLineQueue=[],this.isBusy=!1,this.onCommand=typeof this.options.onCommand=="function"?this.options.onCommand:null,this.getCompletions=typeof this.options.getCompletions=="function"?this.options.getCompletions:null,this.onKey=typeof this.options.onKey=="function"?this.options.onKey:null,this.onInterrupt=typeof this.options.onInterrupt=="function"?this.options.onInterrupt:null,this._activeLineCommitted=!0,this._cursorCol=0,this._pendingEscape="",this._targetLineIdx=-1,this._needsRewrite=!1,this._activeLineEl=null,this._mounted=!1,this._listeners=[],this.container&&this.mount(this.container)}getPrompt(){return this.promptOverride?this.promptOverride:this.replMode?"> ":`codelab:${this.cwd||"/workspace"}$ `}setPrompt(e){this.promptOverride=e,this.updateActiveLine()}setCwd(e){this.cwd=e,this.updateActiveLine()}setReplMode(e){this.replMode=!!e,this.updateActiveLine()}writeStreamChunk(e,t="stdout"){let n=String(e??"");if(!n)return;this._pendingEscape&&(n=this._pendingEscape+n,this._pendingEscape="");let i=!1,l=0;for(;l<n.length;){if(n[l]==="\x1B"){const s=n.slice(l);if(s==="\x1B"||/^\x1b\[[0-9;?]*$/.test(s)||/^\x1b\][^\x07]*(?:\x1b)?$/.test(s)){this._pendingEscape=s;break}if(s.startsWith("\x1Bc")){l+=2,this.clear(),i=!1;continue}const f=/^\x1b\]([^\x07\x1b]*)(?:\x07|\x1b\\)/.exec(s);if(f){l+=f[0].length;continue}const p=/^\x1b\[([0-9;?]*)([A-Za-z])/.exec(s);if(p){const c=p[1],a=p[2],d=p[0];if(l+=d.length,a==="K"){const h=this._getActiveLine(t);c==="2"?(h.text="",this._cursorCol=0,this._needsRewrite=!1):(h.text=h.text.slice(0,this._cursorCol),this._needsRewrite=!1),i=!0}else if(a==="A"){const h=parseInt(c,10)||1;if(this.logs.length>0){const o=this._activeLineCommitted?this.logs.length:this.logs.length-1;this._targetLineIdx=Math.max(0,o-h),this._activeLineCommitted=!1,this._cursorCol=0,this._needsRewrite=!1;const v=this.logs[this._targetLineIdx];v&&(v.text=""),this._activeLineEl=null}}else if(a==="G"||a==="H"||a==="f")this._cursorCol=0,a==="G"&&(this._needsRewrite=!0);else if(a==="J"&&(c==="2"||c==="3"))this.clear(),i=!1;else if(a==="m"){const h=this._getActiveLine(t);h.text+=d,i=!0}continue}}const r=n[l];if(r==="\r")this._cursorCol=0,this._needsRewrite=!0,l++;else if(r===`
25
+ `)}function _(u){if(!u)return"";const e=w(String(u));if(!e.includes("\x1B["))return y(e);const t=e.replace(/\x1b\[[0-9;?]*(?!m)[A-Za-z]/g,""),n=/\x1b\[([0-9;]*)m/g;let i="",l=0,r;const s={bold:!1,dim:!1,italic:!1,underline:!1,inverse:!1,strike:!1,fgClass:null,bgClass:null,fgColor:null,bgColor:null},f=()=>{s.bold=!1,s.dim=!1,s.italic=!1,s.underline=!1,s.inverse=!1,s.strike=!1,s.fgClass=null,s.bgClass=null,s.fgColor=null,s.bgColor=null},p=a=>{if(!a)return"";const d=y(a),h=[];s.bold&&h.push("cl-ansi-bold"),s.dim&&h.push("cl-ansi-dim"),s.italic&&h.push("cl-ansi-italic"),s.underline&&h.push("cl-ansi-underline"),s.inverse&&h.push("cl-ansi-inverse"),s.strike&&h.push("cl-ansi-strike"),s.fgClass&&h.push(s.fgClass),s.bgClass&&h.push(s.bgClass);const o=[];if(s.fgColor&&o.push(`color:${s.fgColor}`),s.bgColor&&o.push(`background-color:${s.bgColor}`),s.inverse&&!s.fgClass&&!s.bgClass&&o.push("filter:invert(1)"),s.strike&&o.push("text-decoration:line-through"),h.length===0&&o.length===0)return d;const v=h.length>0?` class="${h.join(" ")}"`:"",x=o.length>0?` style="${o.join(";")}"`:"";return`<span${v}${x}>${d}</span>`};for(;(r=n.exec(t))!==null;){const a=t.slice(l,r.index);a&&(i+=p(a)),l=n.lastIndex;const d=r[1]?r[1].split(";").map(Number):[0];for(let h=0;h<d.length;h++){const o=d[h];if(o===0||Number.isNaN(o))f();else if(o===1)s.bold=!0;else if(o===2)s.dim=!0;else if(o===3)s.italic=!0;else if(o===4)s.underline=!0;else if(o===7)s.inverse=!0;else if(o===9)s.strike=!0;else if(o===22)s.bold=!1,s.dim=!1;else if(o===23)s.italic=!1;else if(o===24)s.underline=!1;else if(o===27)s.inverse=!1;else if(o===29)s.strike=!1;else if(o===39)s.fgClass=null,s.fgColor=null;else if(o===49)s.bgClass=null,s.bgColor=null;else if((o===38||o===48)&&d[h+1]===5&&h+2<d.length){const v=C(d[h+2]);v&&(o===38?(s.fgClass=null,s.fgColor=v):(s.bgClass=null,s.bgColor=v)),h+=2}else if((o===38||o===48)&&d[h+1]===2&&h+4<d.length){const v=Math.max(0,Math.min(255,Number(d[h+2])||0)),x=Math.max(0,Math.min(255,Number(d[h+3])||0)),E=Math.max(0,Math.min(255,Number(d[h+4])||0)),S=`rgb(${v}, ${x}, ${E})`;o===38?(s.fgClass=null,s.fgColor=S):(s.bgClass=null,s.bgColor=S),h+=4}else o>=30&&o<=37||o>=90&&o<=97?(s.fgClass=m[o]||null,s.fgColor=null):(o>=40&&o<=47||o>=100&&o<=107)&&(s.bgClass=m[o]||null,s.bgColor=null)}}const c=t.slice(l);return c&&(i+=p(c)),i}const M=_,T=2e3,k=new Set(["stdout","stderr","system","info","warn","error","success"]);function L(u){const e=String(u||"stdout").trim();return k.has(e)?e:"stdout"}class A{constructor(e,t={}){e&&typeof e=="object"&&typeof e.querySelector!="function"&&typeof e.appendChild!="function"&&arguments.length===1&&(t=e,e=t.container||null),this.container=e||null,this.options=t||{},this.maxScrollback=typeof this.options.maxScrollback=="number"&&this.options.maxScrollback>0?this.options.maxScrollback:T,this.maxHistory=typeof this.options.maxHistory=="number"&&this.options.maxHistory>0?this.options.maxHistory:1e3,this.logs=Array.isArray(this.options.logs)?this.options.logs:[],this.cwd=this.options.cwd||"/workspace",this.replMode=!!this.options.replMode,this.promptOverride=this.options.prompt||null,this.history=Array.isArray(this.options.history)?this.options.history:[],this.historyIdx=-1,this.savedBuffer="",this.buffer="",this.cursor=0,this.searchMode=!1,this.searchQuery="",this.searchMatchIdx=-1,this._readLineQueue=[],this.isBusy=!1,this.onCommand=typeof this.options.onCommand=="function"?this.options.onCommand:null,this.getCompletions=typeof this.options.getCompletions=="function"?this.options.getCompletions:null,this.onKey=typeof this.options.onKey=="function"?this.options.onKey:null,this.onInterrupt=typeof this.options.onInterrupt=="function"?this.options.onInterrupt:null,this._activeLineCommitted=!0,this._cursorCol=0,this._pendingEscape="",this._targetLineIdx=-1,this._needsRewrite=!1,this._activeLineEl=null,this._mounted=!1,this._listeners=[],this.container&&this.mount(this.container)}getPrompt(){return this.promptOverride?this.promptOverride:this.replMode?"> ":`codelab:${this.cwd||"/workspace"}$ `}setPrompt(e){this.promptOverride=e,this.updateActiveLine()}setCwd(e){this.cwd=e,this.updateActiveLine()}setReplMode(e){this.replMode=!!e,this.updateActiveLine()}writeStreamChunk(e,t="stdout"){let n=String(e??"");if(!n)return;this._pendingEscape&&(n=this._pendingEscape+n,this._pendingEscape="");let i=!1,l=0;for(;l<n.length;){if(n[l]==="\x1B"){const s=n.slice(l);if(s==="\x1B"||/^\x1b\[[0-9;?]*$/.test(s)||/^\x1b\][^\x07]*(?:\x1b)?$/.test(s)){this._pendingEscape=s;break}if(s.startsWith("\x1Bc")){l+=2,this.clear(),i=!1;continue}const f=/^\x1b\]([^\x07\x1b]*)(?:\x07|\x1b\\)/.exec(s);if(f){l+=f[0].length;continue}const p=/^\x1b\[([0-9;?]*)([A-Za-z])/.exec(s);if(p){const c=p[1],a=p[2],d=p[0];if(l+=d.length,a==="K"){const h=this._getActiveLine(t);c==="2"?(h.text="",this._cursorCol=0,this._needsRewrite=!1):(h.text=h.text.slice(0,this._cursorCol),this._needsRewrite=!1),i=!0}else if(a==="A"){const h=parseInt(c,10)||1;if(this.logs.length>0){const o=this._activeLineCommitted?this.logs.length:this.logs.length-1;this._targetLineIdx=Math.max(0,o-h),this._activeLineCommitted=!1,this._cursorCol=0,this._needsRewrite=!1;const v=this.logs[this._targetLineIdx];v&&(v.text=""),this._activeLineEl=null}}else if(a==="G"||a==="H"||a==="f")this._cursorCol=0,a==="G"&&(this._needsRewrite=!0);else if(a==="J"&&(c==="2"||c==="3"))this.clear(),i=!1;else if(a==="m"){const h=this._getActiveLine(t);h.text+=d,i=!0}continue}}const r=n[l];if(r==="\r")this._cursorCol=0,this._needsRewrite=!0,l++;else if(r===`
26
26
  `){const s=this._getActiveLine(t);s.text+=`
27
27
  `,this._activeLineCommitted=!0,this._cursorCol=0,this._targetLineIdx=-1,this._needsRewrite=!1,this._activeLineEl=null,i=!0,l++}else{const s=this._getActiveLine(t);this._needsRewrite&&this._cursorCol===0&&s.text.length>0&&!s.text.endsWith(`
28
28
  `)?(s.text=r,this._needsRewrite=!1):s.text+=r,this._cursorCol++,i=!0,l++}}i&&this._updateActiveDomLine(),this._scrollToBottom()}write(e,t="stdout"){this.writeStreamChunk(e,t)}writeln(e,t="stdout"){this.writeStreamChunk(String(e)+`
29
- `,t)}isCommandRunning(){return!!(this.isBusy&&(!this._readLineQueue||this._readLineQueue.length===0))}_pushLog(e){const t={type:L(e&&e.type),text:String(e&&e.text!=null?e.text:"")};if(this.logs.push(t),this.logs.length>this.maxScrollback){const n=this.logs.length-this.maxScrollback;if(this.logs.splice(0,n),this._targetLineIdx>=0&&(this._targetLineIdx=Math.max(0,this._targetLineIdx-n)),this.container&&typeof this.container.querySelector=="function"){const i=this.container.querySelector("#cl-terminal-log");if(i&&i.children&&i.children.length>this.maxScrollback)for(;i.children.length>this.maxScrollback&&typeof i.removeChild=="function"&&i.firstChild;)i.removeChild(i.firstChild)}}return t}_getActiveLine(e){if(this._targetLineIdx>=0&&this._targetLineIdx<this.logs.length)return this.logs[this._targetLineIdx];if(this._activeLineCommitted||this.logs.length===0){const t=this._pushLog({text:"",type:e});return this._activeLineCommitted=!1,this._cursorCol=0,this._targetLineIdx=this.logs.length-1,this._needsRewrite=!1,this._appendDomLine(t),t}return this._targetLineIdx=this.logs.length-1,this.logs[this.logs.length-1]}_appendDomLine(e){if(!this.container||typeof document>"u")return;const t=this.container.querySelector("#cl-terminal-log");if(!t)return;const n=document.createElement("div");n.className="codelab-log-line "+L(e.type),n.innerHTML=_(e.text),t.appendChild(n),this._activeLineEl=n}_updateActiveDomLine(){if(!this.container||typeof document>"u")return;const e=this._getActiveLineSync();if(!e)return;let t=this._activeLineEl;if(!t||!t.parentNode){const n=this.container.querySelector("#cl-terminal-log");n&&(this._targetLineIdx>=0&&this._targetLineIdx<n.children.length?t=n.children[this._targetLineIdx]:t=n.children[n.children.length-1],this._activeLineEl=t)}t&&(t.className="codelab-log-line "+L(e.type),t.innerHTML=_(e.text))}_getActiveLineSync(){return this._targetLineIdx>=0&&this._targetLineIdx<this.logs.length?this.logs[this._targetLineIdx]:this.logs[this.logs.length-1]||null}_scrollToBottom(){if(!this.container)return;const e=this.container.querySelector("#cl-terminal-surface")||this.container;e&&typeof e.scrollTop=="number"&&typeof e.scrollHeight=="number"&&(e.scrollTop=e.scrollHeight)}clear(){if(this.logs.length=0,this._activeLineCommitted=!0,this._cursorCol=0,this._targetLineIdx=-1,this._needsRewrite=!1,this._activeLineEl=null,this.container&&typeof this.container.querySelector=="function"){const e=this.container.querySelector("#cl-terminal-log");e&&(e.innerHTML="")}}getHistory(){return[...this.history]}_activateNextReadLine(){if(!this._readLineQueue||this._readLineQueue.length===0)return;const e=this._readLineQueue[0];e&&typeof e=="object"&&!e._activated&&(e._activated=!0,e.prevPrompt=this.promptOverride,e.promptText&&(this.promptOverride=e.promptText))}_drainReadLineQueue(e=null){if(!Array.isArray(this._readLineQueue)||this._readLineQueue.length===0)return;const t=this._readLineQueue.splice(0,this._readLineQueue.length);let n;for(const i of t)i&&typeof i=="object"&&i._activated&&n===void 0&&(n=i.prevPrompt),i&&typeof i.cleanup=="function"&&i.cleanup();n!==void 0&&(this.promptOverride=n);for(const i of t)if(typeof i=="function")try{i(e)}catch(l){b.debug("readLine callback threw during drain.",l)}else if(i&&typeof i.resolve=="function")try{i.resolve(e)}catch(l){b.debug("readLine resolve threw during drain.",l)}}readLine(e="",t={}){return t&&t.signal&&t.signal.aborted?Promise.resolve(null):new Promise(n=>{const i={promptText:String(e||""),prevPrompt:null,_activated:!1,cleanup:null,resolve:n};if(t&&t.signal&&typeof t.signal.addEventListener=="function"){const l=()=>{const r=this._readLineQueue.indexOf(i);r!==-1&&(this._readLineQueue.splice(r,1),i._activated&&(this.promptOverride=i.prevPrompt,this._activateNextReadLine()),this.updateActiveLine(),n(null))};t.signal.addEventListener("abort",l,{once:!0}),i.cleanup=()=>{try{t.signal.removeEventListener("abort",l)}catch(r){b.debug("readLine abort listener cleanup failed.",r)}}}this._readLineQueue.push(i),this._activateNextReadLine(),this.updateActiveLine()})}focus(){if(!this.container||typeof this.container.querySelector!="function")return;const e=this.container.querySelector("#cl-repl-input");if(e&&typeof e.focus=="function")try{e.focus()}catch(t){b.debug("Terminal input focus skipped.",t)}}mount(e){if(typeof e=="string"&&typeof document<"u"&&(e=document.querySelector(e)),this.container=e||null,!this.container||typeof this.container.querySelector!="function"){this._mounted=!1;return}this._mounted=!0,this.render()}_cleanupListeners(){if(!Array.isArray(this._listeners)){this._listeners=[];return}for(const e of this._listeners)if(typeof e=="function")try{e()}catch(t){b.debug("Terminal listener cleanup callback failed.",t)}else if(e&&e.target&&typeof e.target.removeEventListener=="function")try{e.target.removeEventListener(e.type,e.handler)}catch(t){b.debug("Terminal removeEventListener failed.",t)}this._listeners=[]}destroy(){this._drainReadLineQueue(null),this._cleanupListeners(),this._mounted=!1}_addListener(e,t,n){e&&typeof e.addEventListener=="function"&&(e.addEventListener(t,n),this._listeners.push({target:e,type:t,handler:n}))}_bindEvents(){if(this._cleanupListeners(),!this.container||typeof this.container.querySelector!="function")return;const e=this.container.querySelector("#cl-terminal-surface")||this.container,t=this.container.querySelector("#cl-repl-input"),n=this.container.querySelector("#cl-repl-form");e&&this._addListener(e,"click",i=>{if(i&&i.target===t)return;typeof window<"u"&&window.getSelection&&String(window.getSelection())||this.focus()}),t&&(this._addListener(t,"keydown",i=>this.handleKeyDown(i)),this._addListener(t,"paste",i=>{const l=i&&i.clipboardData&&typeof i.clipboardData.getData=="function"?i.clipboardData.getData("text/plain"):"";l&&(i.preventDefault&&i.preventDefault(),this.pasteText(l))}),this._addListener(t,"input",()=>{if(this.isCommandRunning()){t.value="";return}t.value!==this.buffer&&(this.buffer=t.value,this.cursor=typeof t.selectionStart=="number"?t.selectionStart:this.buffer.length,this.updateActiveLine())})),n&&this._addListener(n,"submit",i=>{i&&typeof i.preventDefault=="function"&&i.preventDefault(),this.submitLine()})}_findReverseSearchMatch(e,t){if(!e||!this.history.length)return-1;const n=typeof t=="number"?Math.min(t,this.history.length-1):this.history.length-1;for(let i=n;i>=0;i--)if(this.history[i]&&this.history[i].includes(e))return i;return-1}handleKeyDown(e){if(!e)return;if(this.onKey)try{if(this.onKey(e)===!1)return}catch(r){b.warn("Terminal onKey callback threw.",r)}const t=e.key,n=!!(e.ctrlKey&&!e.metaKey),i=!!(e.metaKey&&!e.ctrlKey),l=!!(e.ctrlKey||e.metaKey);if(l&&(t==="l"||t==="L")||i&&(t==="k"||t==="K")){e.preventDefault&&e.preventDefault(),this.clear();return}if(!(i&&(t==="c"||t==="C"))&&!(i&&(t==="v"||t==="V"))){if(n&&(t==="c"||t==="C")){if(e.shiftKey||!this.isBusy&&typeof window<"u"&&typeof window.getSelection=="function"&&String(window.getSelection()).length>0)return;e.preventDefault&&e.preventDefault();const s=this.isBusy||this._readLineQueue&&this._readLineQueue.length>0;this.isBusy=!1;const f=this._pushLog({type:"system",text:s?"^C":`${this.getPrompt()}${this.buffer}^C`});if(this._appendDomLine(f),this._activeLineCommitted=!0,this._activeLineEl=null,this.buffer="",this.cursor=0,this.historyIdx=-1,this._drainReadLineQueue(null),this.replMode&&(this.replMode=!1),this.onInterrupt)try{this.onInterrupt()}catch(p){b.warn("Terminal onInterrupt callback threw.",p)}this.updateActiveLine(),this._scrollToBottom();return}if(this.isCommandRunning()){e.preventDefault&&e.preventDefault();return}if(l&&(t==="r"||t==="R")){if(e.preventDefault&&e.preventDefault(),!this.searchMode)this.searchMode=!0,this.searchQuery="",this.searchMatchIdx=-1;else if(this.searchQuery){const r=this.searchMatchIdx>0?this.searchMatchIdx-1:this.history.length-1,s=this._findReverseSearchMatch(this.searchQuery,r);s!==-1&&(this.searchMatchIdx=s,this.buffer=this.history[s],this.cursor=this.buffer.length)}this.updateActiveLine();return}if(this.searchMode){if(t==="Escape"||l&&(t==="g"||t==="G")){e.preventDefault&&e.preventDefault(),this.searchMode=!1,this.searchQuery="",this.searchMatchIdx=-1,this.updateActiveLine();return}if(t==="Backspace"){e.preventDefault&&e.preventDefault(),this.searchQuery=this.searchQuery.slice(0,-1);const r=this._findReverseSearchMatch(this.searchQuery,this.history.length-1);this.searchMatchIdx=r,r!==-1&&(this.buffer=this.history[r],this.cursor=this.buffer.length),this.updateActiveLine();return}if(t==="Enter"){e.preventDefault&&e.preventDefault(),this.searchMode=!1,this.searchQuery="",this.searchMatchIdx=-1,this.submitLine();return}if(t&&t.length===1&&!l&&!e.altKey){e.preventDefault&&e.preventDefault(),this.searchQuery+=t;const r=this._findReverseSearchMatch(this.searchQuery,this.history.length-1);this.searchMatchIdx=r,r!==-1&&(this.buffer=this.history[r],this.cursor=this.buffer.length),this.updateActiveLine();return}this.searchMode=!1,this.searchQuery="",this.searchMatchIdx=-1}if(e.altKey&&(t==="b"||t==="B"||t==="ArrowLeft")||n&&t==="ArrowLeft"){e.preventDefault&&e.preventDefault();let r=this.cursor;for(;r>0&&/\s/.test(this.buffer[r-1]);)r--;for(;r>0&&!/\s/.test(this.buffer[r-1]);)r--;this.cursor=r,this.updateActiveLine();return}if(e.altKey&&(t==="f"||t==="F"||t==="ArrowRight")||n&&t==="ArrowRight"){e.preventDefault&&e.preventDefault();let r=this.cursor;for(;r<this.buffer.length&&/\s/.test(this.buffer[r]);)r++;for(;r<this.buffer.length&&!/\s/.test(this.buffer[r]);)r++;this.cursor=r,this.updateActiveLine();return}if(n&&(t==="w"||t==="W")||e.altKey&&t==="Backspace"){e.preventDefault&&e.preventDefault();let r=this.cursor;for(;r>0&&/\s/.test(this.buffer[r-1]);)r--;for(;r>0&&!/\s/.test(this.buffer[r-1]);)r--;this.buffer=this.buffer.slice(0,r)+this.buffer.slice(this.cursor),this.cursor=r,this.updateActiveLine();return}if(t==="ArrowLeft"){e.preventDefault&&e.preventDefault(),this.cursor>0&&(this.cursor--,this.updateActiveLine());return}if(t==="ArrowRight"){e.preventDefault&&e.preventDefault(),this.cursor<this.buffer.length&&(this.cursor++,this.updateActiveLine());return}if(t==="Home"||l&&(t==="a"||t==="A")){e.preventDefault&&e.preventDefault(),this.cursor=0,this.updateActiveLine();return}if(t==="End"||l&&(t==="e"||t==="E")){e.preventDefault&&e.preventDefault(),this.cursor=this.buffer.length,this.updateActiveLine();return}if(l&&(t==="u"||t==="U")){e.preventDefault&&e.preventDefault(),this.buffer=this.buffer.slice(this.cursor),this.cursor=0,this.updateActiveLine();return}if(l&&(t==="k"||t==="K")){e.preventDefault&&e.preventDefault(),this.buffer=this.buffer.slice(0,this.cursor),this.updateActiveLine();return}if(t==="Backspace"){e.preventDefault&&e.preventDefault(),this.cursor>0&&(this.buffer=this.buffer.slice(0,this.cursor-1)+this.buffer.slice(this.cursor),this.cursor--,this.updateActiveLine());return}if(t==="Delete"){e.preventDefault&&e.preventDefault(),this.cursor<this.buffer.length&&(this.buffer=this.buffer.slice(0,this.cursor)+this.buffer.slice(this.cursor+1),this.updateActiveLine());return}if(l&&(t==="d"||t==="D")&&this.buffer===""){if(e.preventDefault&&e.preventDefault(),this._readLineQueue&&this._readLineQueue.length>0){this._drainReadLineQueue(null),this.updateActiveLine();return}if(this.replMode){this._pushLog({type:"system",text:`${this.getPrompt()}.exit`}),this.replMode=!1,this.render();return}}if(t==="ArrowUp"){if(e.preventDefault&&e.preventDefault(),!this.history.length)return;this.historyIdx===-1?(this.savedBuffer=this.buffer,this.historyIdx=this.history.length-1):this.historyIdx>0&&this.historyIdx--,this.buffer=this.history[this.historyIdx]||"",this.cursor=this.buffer.length,this.updateActiveLine();return}if(t==="ArrowDown"){e.preventDefault&&e.preventDefault(),this.historyIdx!==-1&&(this.historyIdx<this.history.length-1?(this.historyIdx++,this.buffer=this.history[this.historyIdx]||""):(this.historyIdx=-1,this.buffer=this.savedBuffer||""),this.cursor=this.buffer.length,this.updateActiveLine());return}if(t==="Tab"){e.preventDefault&&e.preventDefault(),this.autoComplete();return}if(t==="Enter"){e.preventDefault&&e.preventDefault(),this.submitLine();return}t&&t.length===1&&!l&&!e.altKey&&(e.preventDefault&&e.preventDefault(),this.buffer=this.buffer.slice(0,this.cursor)+t+this.buffer.slice(this.cursor),this.cursor++,this.updateActiveLine())}}async pasteText(e){if(!e||this.isCommandRunning())return;const t=String(e).replace(/\r\n/g,`
29
+ `,t)}isCommandRunning(){return!!(this.isBusy&&(!this._readLineQueue||this._readLineQueue.length===0))}_pushLog(e){const t={type:L(e&&e.type),text:String(e&&e.text!=null?e.text:"")};if(this.logs.push(t),this.logs.length>this.maxScrollback){const n=this.logs.length-this.maxScrollback;if(this.logs.splice(0,n),this._targetLineIdx>=0&&(this._targetLineIdx=Math.max(0,this._targetLineIdx-n)),this.container&&typeof this.container.querySelector=="function"){const i=this.container.querySelector("#cl-terminal-log");if(i&&i.children&&i.children.length>this.maxScrollback)for(;i.children.length>this.maxScrollback&&typeof i.removeChild=="function"&&i.firstChild;)i.removeChild(i.firstChild)}}return t}_getActiveLine(e){if(this._targetLineIdx>=0&&this._targetLineIdx<this.logs.length)return this.logs[this._targetLineIdx];if(this._activeLineCommitted||this.logs.length===0){const t=this._pushLog({text:"",type:e});return this._activeLineCommitted=!1,this._cursorCol=0,this._targetLineIdx=this.logs.length-1,this._needsRewrite=!1,this._appendDomLine(t),t}return this._targetLineIdx=this.logs.length-1,this.logs[this.logs.length-1]}_appendDomLine(e){if(!this.container||typeof document>"u")return;const t=this.container.querySelector("#cl-terminal-log");if(!t)return;const n=document.createElement("div");n.className="codelab-log-line "+L(e.type),n.innerHTML=_(e.text),t.appendChild(n),this._activeLineEl=n}_updateActiveDomLine(){if(!this.container||typeof document>"u")return;const e=this._getActiveLineSync();if(!e)return;let t=this._activeLineEl;if(!t||!t.parentNode){const n=this.container.querySelector("#cl-terminal-log");n&&(this._targetLineIdx>=0&&this._targetLineIdx<n.children.length?t=n.children[this._targetLineIdx]:t=n.children[n.children.length-1],this._activeLineEl=t)}t&&(t.className="codelab-log-line "+L(e.type),t.innerHTML=_(e.text))}_getActiveLineSync(){return this._targetLineIdx>=0&&this._targetLineIdx<this.logs.length?this.logs[this._targetLineIdx]:this.logs[this.logs.length-1]||null}_scrollToBottom(){if(!this.container)return;const e=this.container.querySelector("#cl-terminal-surface")||this.container;e&&typeof e.scrollTop=="number"&&typeof e.scrollHeight=="number"&&(e.scrollTop=e.scrollHeight)}clear(){if(this.logs.length=0,this._activeLineCommitted=!0,this._cursorCol=0,this._targetLineIdx=-1,this._needsRewrite=!1,this._activeLineEl=null,this.container&&typeof this.container.querySelector=="function"){const e=this.container.querySelector("#cl-terminal-log");e&&(e.innerHTML="")}}getHistory(){return[...this.history]}_activateNextReadLine(){if(!this._readLineQueue||this._readLineQueue.length===0)return;const e=this._readLineQueue[0];e&&typeof e=="object"&&!e._activated&&(e._activated=!0,e.prevPrompt=this.promptOverride,e.promptText&&(this.promptOverride=e.promptText))}_drainReadLineQueue(e=null){if(!Array.isArray(this._readLineQueue)||this._readLineQueue.length===0)return;const t=this._readLineQueue.splice(0,this._readLineQueue.length);let n;for(const i of t)i&&typeof i=="object"&&i._activated&&n===void 0&&(n=i.prevPrompt),i&&typeof i.cleanup=="function"&&i.cleanup();n!==void 0&&(this.promptOverride=n);for(const i of t)if(typeof i=="function")try{i(e)}catch(l){b.debug("readLine callback threw during drain.",l)}else if(i&&typeof i.resolve=="function")try{i.resolve(e)}catch(l){b.debug("readLine resolve threw during drain.",l)}}readLine(e="",t={}){return t&&t.signal&&t.signal.aborted?Promise.resolve(null):new Promise(n=>{const i={promptText:String(e||""),prevPrompt:null,_activated:!1,cleanup:null,resolve:n};if(t&&t.signal&&typeof t.signal.addEventListener=="function"){const l=()=>{const r=this._readLineQueue.indexOf(i);r!==-1&&(this._readLineQueue.splice(r,1),i._activated&&(this.promptOverride=i.prevPrompt,this._activateNextReadLine()),this.updateActiveLine(),n(null))};t.signal.addEventListener("abort",l,{once:!0}),i.cleanup=()=>{try{t.signal.removeEventListener("abort",l)}catch(r){b.debug("readLine abort listener cleanup failed.",r)}}}this._readLineQueue.push(i),this._activateNextReadLine(),this.updateActiveLine()})}focus(){if(!this.container||typeof this.container.querySelector!="function")return;const e=this.container.querySelector("#cl-repl-input");if(e&&typeof e.focus=="function")try{e.focus()}catch(t){b.debug("Terminal input focus skipped.",t)}}mount(e){if(typeof e=="string"&&typeof document<"u"&&(e=document.querySelector(e)),this.container=e||null,!this.container||typeof this.container.querySelector!="function"){this._mounted=!1;return}this._mounted=!0,this.render()}_cleanupListeners(){if(!Array.isArray(this._listeners)){this._listeners=[];return}for(const e of this._listeners)if(typeof e=="function")try{e()}catch(t){b.debug("Terminal listener cleanup callback failed.",t)}else if(e&&e.target&&typeof e.target.removeEventListener=="function")try{e.target.removeEventListener(e.type,e.handler)}catch(t){b.debug("Terminal removeEventListener failed.",t)}this._listeners=[]}destroy(){this._drainReadLineQueue(null),this._cleanupListeners(),this._mounted=!1}_addListener(e,t,n){e&&typeof e.addEventListener=="function"&&(e.addEventListener(t,n),this._listeners.push({target:e,type:t,handler:n}))}_bindEvents(){if(this._cleanupListeners(),!this.container||typeof this.container.querySelector!="function")return;const e=this.container.querySelector("#cl-terminal-surface")||this.container,t=this.container.querySelector("#cl-repl-input"),n=this.container.querySelector("#cl-repl-form");e&&this._addListener(e,"click",i=>{if(i&&i.target===t)return;typeof window<"u"&&window.getSelection&&String(window.getSelection())||this.focus()}),t&&(this._addListener(t,"keydown",i=>this.handleKeyDown(i)),this._addListener(t,"paste",i=>{const l=i&&i.clipboardData&&typeof i.clipboardData.getData=="function"?i.clipboardData.getData("text/plain"):"";l&&(i.preventDefault&&i.preventDefault(),this.pasteText(l))}),this._addListener(t,"input",()=>{if(this.isCommandRunning()){t.value="";return}t.value!==this.buffer&&(this.buffer=t.value,this.cursor=typeof t.selectionStart=="number"?t.selectionStart:this.buffer.length,this.updateActiveLine())})),n&&this._addListener(n,"submit",i=>{i&&typeof i.preventDefault=="function"&&i.preventDefault(),this.submitLine()})}_findReverseSearchMatch(e,t){if(!e||!this.history.length)return-1;const n=typeof t=="number"?Math.min(t,this.history.length-1):this.history.length-1;for(let i=n;i>=0;i--)if(this.history[i]&&this.history[i].includes(e))return i;return-1}handleKeyDown(e){if(!e)return;if(this.onKey)try{if(this.onKey(e)===!1)return}catch(r){b.warn("Terminal onKey callback threw.",r)}const t=e.key,n=!!(e.ctrlKey&&!e.metaKey),i=!!(e.metaKey&&!e.ctrlKey),l=!!(e.ctrlKey||e.metaKey);if(l&&(t==="l"||t==="L")||i&&(t==="k"||t==="K")){e.preventDefault&&e.preventDefault(),this.clear();return}if(!(i&&(t==="c"||t==="C"))&&!(i&&(t==="v"||t==="V"))){if(n&&(t==="c"||t==="C")){if(e.shiftKey||!this.isBusy&&typeof window<"u"&&typeof window.getSelection=="function"&&String(window.getSelection()).length>0)return;e.preventDefault&&e.preventDefault();const s=this.isBusy||this._readLineQueue&&this._readLineQueue.length>0;this.isBusy=!1;const f=this._pushLog({type:"system",text:s?"^C":`${this.getPrompt()}${this.buffer}^C`});if(this._appendDomLine(f),this._activeLineCommitted=!0,this._activeLineEl=null,this.buffer="",this.cursor=0,this.historyIdx=-1,this._drainReadLineQueue(null),this.replMode&&(this.replMode=!1),this.onInterrupt)try{this.onInterrupt()}catch(p){b.warn("Terminal onInterrupt callback threw.",p)}this.updateActiveLine(),this._scrollToBottom();return}if(this.isCommandRunning()){e.preventDefault&&e.preventDefault();return}if(l&&(t==="r"||t==="R")){if(e.preventDefault&&e.preventDefault(),!this.searchMode)this.searchMode=!0,this.searchQuery="",this.searchMatchIdx=-1;else if(this.searchQuery){const r=this.searchMatchIdx>0?this.searchMatchIdx-1:this.history.length-1,s=this._findReverseSearchMatch(this.searchQuery,r);s!==-1&&(this.searchMatchIdx=s,this.buffer=this.history[s],this.cursor=this.buffer.length)}this.updateActiveLine();return}if(this.searchMode){if(t==="Escape"||l&&(t==="g"||t==="G")){e.preventDefault&&e.preventDefault(),this.searchMode=!1,this.searchQuery="",this.searchMatchIdx=-1,this.updateActiveLine();return}if(t==="Backspace"){e.preventDefault&&e.preventDefault(),this.searchQuery=this.searchQuery.slice(0,-1);const r=this._findReverseSearchMatch(this.searchQuery,this.history.length-1);this.searchMatchIdx=r,r!==-1&&(this.buffer=this.history[r],this.cursor=this.buffer.length),this.updateActiveLine();return}if(t==="Enter"){e.preventDefault&&e.preventDefault(),this.searchMode=!1,this.searchQuery="",this.searchMatchIdx=-1,this.submitLine();return}if(t&&t.length===1&&!l&&!e.altKey){e.preventDefault&&e.preventDefault(),this.searchQuery+=t;const r=this._findReverseSearchMatch(this.searchQuery,this.history.length-1);this.searchMatchIdx=r,r!==-1&&(this.buffer=this.history[r],this.cursor=this.buffer.length),this.updateActiveLine();return}this.searchMode=!1,this.searchQuery="",this.searchMatchIdx=-1}if(e.altKey&&(t==="b"||t==="B"||t==="ArrowLeft")||n&&t==="ArrowLeft"){e.preventDefault&&e.preventDefault();let r=this.cursor;for(;r>0&&/\s/.test(this.buffer[r-1]);)r--;for(;r>0&&!/\s/.test(this.buffer[r-1]);)r--;this.cursor=r,this.updateActiveLine();return}if(e.altKey&&(t==="f"||t==="F"||t==="ArrowRight")||n&&t==="ArrowRight"){e.preventDefault&&e.preventDefault();let r=this.cursor;for(;r<this.buffer.length&&/\s/.test(this.buffer[r]);)r++;for(;r<this.buffer.length&&!/\s/.test(this.buffer[r]);)r++;this.cursor=r,this.updateActiveLine();return}if(n&&(t==="w"||t==="W")||e.altKey&&t==="Backspace"){e.preventDefault&&e.preventDefault();let r=this.cursor;for(;r>0&&/\s/.test(this.buffer[r-1]);)r--;for(;r>0&&!/\s/.test(this.buffer[r-1]);)r--;this.buffer=this.buffer.slice(0,r)+this.buffer.slice(this.cursor),this.cursor=r,this.updateActiveLine();return}if(t==="ArrowLeft"){e.preventDefault&&e.preventDefault(),this.cursor>0&&(this.cursor--,this.updateActiveLine());return}if(t==="ArrowRight"){e.preventDefault&&e.preventDefault(),this.cursor<this.buffer.length&&(this.cursor++,this.updateActiveLine());return}if(t==="Home"||e.ctrlKey&&!e.metaKey&&(t==="a"||t==="A")){e.preventDefault&&e.preventDefault(),this.cursor=0,this.updateActiveLine();return}if(t==="End"||l&&(t==="e"||t==="E")){e.preventDefault&&e.preventDefault(),this.cursor=this.buffer.length,this.updateActiveLine();return}if(l&&(t==="u"||t==="U")){e.preventDefault&&e.preventDefault(),this.buffer=this.buffer.slice(this.cursor),this.cursor=0,this.updateActiveLine();return}if(l&&(t==="k"||t==="K")){e.preventDefault&&e.preventDefault(),this.buffer=this.buffer.slice(0,this.cursor),this.updateActiveLine();return}if(t==="Backspace"){e.preventDefault&&e.preventDefault(),this.cursor>0&&(this.buffer=this.buffer.slice(0,this.cursor-1)+this.buffer.slice(this.cursor),this.cursor--,this.updateActiveLine());return}if(t==="Delete"){e.preventDefault&&e.preventDefault(),this.cursor<this.buffer.length&&(this.buffer=this.buffer.slice(0,this.cursor)+this.buffer.slice(this.cursor+1),this.updateActiveLine());return}if(l&&(t==="d"||t==="D")&&this.buffer===""){if(e.preventDefault&&e.preventDefault(),this._readLineQueue&&this._readLineQueue.length>0){this._drainReadLineQueue(null),this.updateActiveLine();return}if(this.replMode){this._pushLog({type:"system",text:`${this.getPrompt()}.exit`}),this.replMode=!1,this.render();return}}if(t==="ArrowUp"){if(e.preventDefault&&e.preventDefault(),!this.history.length)return;this.historyIdx===-1?(this.savedBuffer=this.buffer,this.historyIdx=this.history.length-1):this.historyIdx>0&&this.historyIdx--,this.buffer=this.history[this.historyIdx]||"",this.cursor=this.buffer.length,this.updateActiveLine();return}if(t==="ArrowDown"){e.preventDefault&&e.preventDefault(),this.historyIdx!==-1&&(this.historyIdx<this.history.length-1?(this.historyIdx++,this.buffer=this.history[this.historyIdx]||""):(this.historyIdx=-1,this.buffer=this.savedBuffer||""),this.cursor=this.buffer.length,this.updateActiveLine());return}if(t==="Tab"){e.preventDefault&&e.preventDefault(),this.autoComplete();return}if(t==="Enter"){e.preventDefault&&e.preventDefault(),this.submitLine();return}t&&t.length===1&&!l&&!e.altKey&&(e.preventDefault&&e.preventDefault(),this.buffer=this.buffer.slice(0,this.cursor)+t+this.buffer.slice(this.cursor),this.cursor++,this.updateActiveLine())}}async pasteText(e){if(!e||this.isCommandRunning())return;const t=String(e).replace(/\r\n/g,`
30
30
  `).replace(/\r/g,`
31
31
  `);if(!t.includes(`
32
32
  `)){this.buffer=this.buffer.slice(0,this.cursor)+t+this.buffer.slice(this.cursor),this.cursor+=t.length,this.updateActiveLine();return}const n=t.split(`
33
- `);for(let i=0;i<n.length;i++){const l=n[i];if(i<n.length-1)for(this.buffer=this.buffer.slice(0,this.cursor)+l+this.buffer.slice(this.cursor),this.cursor=this.buffer.length,this.submitLine();this.isCommandRunning();)await new Promise(r=>setTimeout(r,10));else l.length>0&&(this.buffer=l,this.cursor=l.length,this.updateActiveLine())}}autoComplete(){if(!this.getCompletions)return;const e=this.getCompletions(this.buffer,this.cursor);if(!e||!Array.isArray(e.matches)||e.matches.length===0)return;const t=e.matches;if(t.length===1){const n=t[0],l=n.endsWith("/")?"":" ",r=this.buffer.slice(0,e.tokenStart),s=this.buffer.slice(this.cursor);this.buffer=r+n+l+s,this.cursor=r.length+n.length+l.length,this.updateActiveLine()}else{let n=t[0];for(let i=1;i<t.length;i++){let l=0;for(;l<n.length&&l<t[i].length&&n[l]===t[i][l];)l++;n=n.slice(0,l)}if(n.length>e.token.length){const i=this.buffer.slice(0,e.tokenStart),l=this.buffer.slice(this.cursor);this.buffer=i+n+l,this.cursor=i.length+n.length}this._pushLog({type:"system",text:`${this.getPrompt()}${this.buffer}`}),this._pushLog({type:"stdout",text:t.join(" ")}),this.render()}}submitLine(){if(this._readLineQueue&&this._readLineQueue.length>0){const l=this.buffer;this.buffer="",this.cursor=0,this.historyIdx=-1,this.searchMode=!1,this.searchQuery="",this.searchMatchIdx=-1;const r=this._readLineQueue.shift();r&&typeof r.cleanup=="function"&&r.cleanup(),typeof r=="function"?(this.updateActiveLine(),r(l)):r&&typeof r.resolve=="function"&&(this.promptOverride=r.prevPrompt,this._activateNextReadLine(),this.updateActiveLine(),r.resolve(l));return}if(this.isBusy)return;const e=this.buffer,t=this.getPrompt();this.buffer="",this.cursor=0,this.historyIdx=-1,this.searchMode=!1,this.searchQuery="",this.searchMatchIdx=-1;const n=this._pushLog({type:"system",text:`${t}${e}`});if(this._activeLineCommitted=!0,this._cursorCol=0,this._targetLineIdx=-1,this._needsRewrite=!1,this._appendDomLine(n),this._activeLineEl=null,e.trim()&&this.history[this.history.length-1]!==e.trim()){this.history.push(e.trim());const l=typeof this.maxHistory=="number"&&this.maxHistory>0?this.maxHistory:1e3;this.history.length>l&&this.history.splice(0,this.history.length-l)}if(!this.onCommand){this.updateActiveLine();return}this.isBusy=!0,this.updateActiveLine();let i;try{i=this.onCommand(e)}catch(l){throw this.isBusy=!1,this.updateActiveLine(),l}i&&typeof i.then=="function"?Promise.resolve(i).catch(l=>{b.debug("Terminal onCommand promise rejected.",l)}).finally(()=>{this.isBusy=!1,this.updateActiveLine()}):(this.isBusy=!1,this.updateActiveLine())}updateActiveLine(){if(!this.container||typeof this.container.querySelector!="function")return;const e=this.container.querySelector("#cl-repl-input");e&&e.value!==this.buffer&&(e.value=this.buffer);const t=this.container.querySelector("#cl-pty-active-line");if(!t)return;if(this.isCommandRunning()){typeof t.setAttribute=="function"&&t.setAttribute("data-busy","true"),t.style&&(t.style.display="none"),t.innerHTML='<span class="codelab-pty__prompt"></span><span class="codelab-pty__before"></span><span class="codelab-pty__cursor"></span><span class="codelab-pty__after"></span>';return}typeof t.removeAttribute=="function"&&t.removeAttribute("data-busy"),t.style&&(t.style.display="");const n=this.searchMode?`(reverse-i-search)\`${this.searchQuery}\`: `:this.getPrompt(),i=this.buffer.slice(0,this.cursor),l=this.cursor<this.buffer.length?this.buffer[this.cursor]:" ",r=this.cursor<this.buffer.length?this.buffer.slice(this.cursor+1):"";t.innerHTML=`<span class="codelab-pty__prompt">${y(n)}</span><span class="codelab-pty__before">${y(i)}</span><span class="codelab-pty__cursor blink">${y(l)}</span><span class="codelab-pty__after">${y(r)}</span>`}render(){if(!this.container||typeof this.container.querySelector!="function")return;const e=this.container.querySelector("#cl-repl-input"),t=!!(e&&typeof document<"u"&&document.activeElement===e),n=this.logs.map(a=>`<div class="codelab-log-line ${L(a.type)}">${_(a.text)}</div>`).join(""),i=this.isCommandRunning(),l=i?"":this.searchMode?`(reverse-i-search)\`${this.searchQuery}\`: `:this.getPrompt(),r=i?"":this.buffer.slice(0,this.cursor),s=i?"":this.cursor<this.buffer.length?this.buffer[this.cursor]:" ",f=i?"":this.cursor<this.buffer.length?this.buffer.slice(this.cursor+1):"",p=i?' data-busy="true" style="display:none;"':"",c=i?"codelab-pty__cursor":"codelab-pty__cursor blink";if(this.container.innerHTML=`
33
+ `);for(let i=0;i<n.length;i++){const l=n[i];if(i<n.length-1){for(this.buffer=this.buffer.slice(0,this.cursor)+l+this.buffer.slice(this.cursor),this.cursor=this.buffer.length,this.submitLine();this._mounted&&this.isCommandRunning();)await new Promise(r=>setTimeout(r,10));if(!this._mounted)return}else l.length>0&&(this.buffer=l,this.cursor=l.length,this.updateActiveLine())}}autoComplete(){if(!this.getCompletions)return;const e=this.getCompletions(this.buffer,this.cursor);if(!e||!Array.isArray(e.matches)||e.matches.length===0)return;const t=e.matches;if(t.length===1){const n=t[0],l=n.endsWith("/")?"":" ",r=this.buffer.slice(0,e.tokenStart),s=this.buffer.slice(this.cursor);this.buffer=r+n+l+s,this.cursor=r.length+n.length+l.length,this.updateActiveLine()}else{let n=t[0];for(let i=1;i<t.length;i++){let l=0;for(;l<n.length&&l<t[i].length&&n[l]===t[i][l];)l++;n=n.slice(0,l)}if(n.length>e.token.length){const i=this.buffer.slice(0,e.tokenStart),l=this.buffer.slice(this.cursor);this.buffer=i+n+l,this.cursor=i.length+n.length}this._pushLog({type:"system",text:`${this.getPrompt()}${this.buffer}`}),this._pushLog({type:"stdout",text:t.join(" ")}),this.render()}}submitLine(){if(this._readLineQueue&&this._readLineQueue.length>0){const l=this.buffer;this.buffer="",this.cursor=0,this.historyIdx=-1,this.searchMode=!1,this.searchQuery="",this.searchMatchIdx=-1;const r=this._readLineQueue.shift();r&&typeof r.cleanup=="function"&&r.cleanup(),typeof r=="function"?(this.updateActiveLine(),r(l)):r&&typeof r.resolve=="function"&&(this.promptOverride=r.prevPrompt,this._activateNextReadLine(),this.updateActiveLine(),r.resolve(l));return}if(this.isBusy)return;const e=this.buffer,t=this.getPrompt();this.buffer="",this.cursor=0,this.historyIdx=-1,this.searchMode=!1,this.searchQuery="",this.searchMatchIdx=-1;const n=this._pushLog({type:"system",text:`${t}${e}`});if(this._activeLineCommitted=!0,this._cursorCol=0,this._targetLineIdx=-1,this._needsRewrite=!1,this._appendDomLine(n),this._activeLineEl=null,e.trim()&&this.history[this.history.length-1]!==e.trim()){this.history.push(e.trim());const l=typeof this.maxHistory=="number"&&this.maxHistory>0?this.maxHistory:1e3;this.history.length>l&&this.history.splice(0,this.history.length-l)}if(!this.onCommand){this.updateActiveLine();return}this.isBusy=!0,this.updateActiveLine();let i;try{i=this.onCommand(e)}catch(l){throw this.isBusy=!1,this.updateActiveLine(),l}i&&typeof i.then=="function"?Promise.resolve(i).catch(l=>{b.debug("Terminal onCommand promise rejected.",l)}).finally(()=>{this.isBusy=!1,this.updateActiveLine()}):(this.isBusy=!1,this.updateActiveLine())}updateActiveLine(){if(!this.container||typeof this.container.querySelector!="function")return;const e=this.container.querySelector("#cl-repl-input");e&&e.value!==this.buffer&&(e.value=this.buffer);const t=this.container.querySelector("#cl-pty-active-line");if(!t)return;if(this.isCommandRunning()){typeof t.setAttribute=="function"&&t.setAttribute("data-busy","true"),t.style&&(t.style.display="none"),t.innerHTML='<span class="codelab-pty__prompt"></span><span class="codelab-pty__before"></span><span class="codelab-pty__cursor"></span><span class="codelab-pty__after"></span>';return}typeof t.removeAttribute=="function"&&t.removeAttribute("data-busy"),t.style&&(t.style.display="");const n=this.searchMode?`(reverse-i-search)\`${this.searchQuery}\`: `:this.getPrompt(),i=this.buffer.slice(0,this.cursor),l=this.cursor<this.buffer.length?this.buffer[this.cursor]:" ",r=this.cursor<this.buffer.length?this.buffer.slice(this.cursor+1):"";t.innerHTML=`<span class="codelab-pty__prompt">${y(n)}</span><span class="codelab-pty__before">${y(i)}</span><span class="codelab-pty__cursor blink">${y(l)}</span><span class="codelab-pty__after">${y(r)}</span>`}render(){if(!this.container||typeof this.container.querySelector!="function")return;const e=this.container.querySelector("#cl-repl-input"),t=!!(e&&typeof document<"u"&&document.activeElement===e),n=this.logs.map(a=>`<div class="codelab-log-line ${L(a.type)}">${_(a.text)}</div>`).join(""),i=this.isCommandRunning(),l=i?"":this.searchMode?`(reverse-i-search)\`${this.searchQuery}\`: `:this.getPrompt(),r=i?"":this.buffer.slice(0,this.cursor),s=i?"":this.cursor<this.buffer.length?this.buffer[this.cursor]:" ",f=i?"":this.cursor<this.buffer.length?this.buffer.slice(this.cursor+1):"",p=i?' data-busy="true" style="display:none;"':"",c=i?"codelab-pty__cursor":"codelab-pty__cursor blink";if(this.container.innerHTML=`
34
34
  <div class="codelab-terminal" id="cl-terminal-surface" tabindex="0">
35
35
  <div class="codelab-terminal__log" id="cl-terminal-log">${n}</div>
36
36
  <div class="codelab-pty__active-line" id="cl-pty-active-line"${p}>
@@ -40,7 +40,7 @@ var CodeLabLogger=(()=>{var s=Object.defineProperty;var p=Object.getOwnPropertyD
40
40
  <input type="text" class="codelab-repl__input" id="cl-repl-input" autocomplete="off" spellcheck="false" aria-label="Terminal command input" value="${y(this.buffer)}">
41
41
  </form>
42
42
  </div>
43
- `,this._scrollToBottom(),this._bindEvents(),t){const a=this.container.querySelector("#cl-repl-input");if(a&&typeof a.focus=="function")try{a.focus(),typeof a.setSelectionRange=="function"&&a.setSelectionRange(this.cursor,this.cursor)}catch(d){b.debug("Terminal focus/selection restore skipped.",d)}}}}function A(u,e={}){return new w(u,e)}return{PTYTerminalEngine:w,createPTYTerminalEngine:A,createTerminal:A,ansiToHtml:_,parseAnsiToHtml:M,escapeHtml:y,ANSI_CODE_MAP:m,resolveAnsiControlCodes:C}});
43
+ `,this._scrollToBottom(),this._bindEvents(),t){const a=this.container.querySelector("#cl-repl-input");if(a&&typeof a.focus=="function")try{a.focus(),typeof a.setSelectionRange=="function"&&a.setSelectionRange(this.cursor,this.cursor)}catch(d){b.debug("Terminal focus/selection restore skipped.",d)}}}}function D(u,e={}){return new A(u,e)}return{PTYTerminalEngine:A,createPTYTerminalEngine:D,createTerminal:D,ansiToHtml:_,parseAnsiToHtml:M,escapeHtml:y,ANSI_CODE_MAP:m,ansi256ToColor:C,resolveAnsiControlCodes:w}});
44
44
 
45
45
  })();
46
46
 
@@ -18,8 +18,4 @@ export interface FuzzyMatchResult {
18
18
  * word-boundary / camelCase transitions, and prefix alignment.
19
19
  */
20
20
  export declare function fuzzyScoreText(query: string, candidate: string): FuzzyMatchResult | null;
21
- /**
22
- * Renders HTML with `<mark class="codelab-palette-hl">` around matched subsequence characters.
23
- */
24
21
  export declare function renderHighlightedText(text: string, indices: number[]): string;
25
- export declare function getStandardWorkbenchCommands(workbench: any): CommandPaletteItem[];
@@ -2,24 +2,15 @@
2
2
  * @innovatorved/code-lab — Workbench Subsystem Entrypoint
3
3
  */
4
4
  export * from './icons';
5
- export * from './styles';
6
- export * from './toolbar';
7
- export * from './drawer';
8
5
  export * from './diff-editor';
9
6
  export * from './command-palette';
10
7
  export * from './share';
11
- export * from './file-tree';
12
8
  export * from './editor';
13
- export * from './guided-pane';
14
9
  export * from './xterm-adapter';
15
10
  export * from './intellisense';
16
- import * as toolbar from './toolbar';
17
- import * as drawer from './drawer';
18
11
  import * as diffEditor from './diff-editor';
19
12
  import * as commandPalette from './command-palette';
20
13
  import * as share from './share';
21
- import * as fileTree from './file-tree';
22
- import * as guidedPane from './guided-pane';
23
14
  import * as xtermAdapter from './xterm-adapter';
24
15
  import * as intellisense from './intellisense';
25
16
  export declare const CodeLabWorkbenchComponents: {
@@ -48,24 +39,13 @@ export declare const CodeLabWorkbenchComponents: {
48
39
  canUseXtermInEnvironment(container?: unknown): boolean;
49
40
  createXtermTerminalEngine(container: HTMLElement | null, options?: xtermAdapter.XtermAdapterOptions): xtermAdapter.XtermTerminalEngine;
50
41
  XtermTerminalEngine: typeof xtermAdapter.XtermTerminalEngine;
51
- renderStepPillsHtml(steps: guidedPane.GuidedStepData[], activeIndex: number, completedStepIds: Set<string>): string;
52
42
  formatCppSource(code: string): string;
53
- buildFileHierarchy(files: Record<string, string>, creatingItem?: any): fileTree.FileNode;
54
- getFileIcon(filename: string): string;
55
43
  compressWorkspaceSnapshot(payload: share.WorkspaceSharePayload): Promise<string>;
56
44
  decompressWorkspaceSnapshot(encoded: string): Promise<share.WorkspaceSharePayload | null>;
57
45
  fuzzyScoreText(query: string, candidate: string): commandPalette.FuzzyMatchResult | null;
58
46
  renderHighlightedText(text: string, indices: number[]): string;
59
- getStandardWorkbenchCommands(workbench: any): commandPalette.CommandPaletteItem[];
60
47
  computeSimpleDiff(oldText: string, newText: string): diffEditor.DiffComputeResult;
61
48
  CodeLabDiffEditorManager: typeof diffEditor.CodeLabDiffEditorManager;
62
- formatTelemetryHud(durationMs: number | null, memoryBytes: number | null, lang: string): string;
63
- renderDrawerTabsHtml(opts: drawer.DrawerTabOptions): string;
64
- renderProblemsPanelHtml(workbench: any): string;
65
- renderStdinPanelHtml(workbench: any): string;
66
- renderLanguageSwitcherHtml(workbench: any): string;
67
- renderToolbarHtml(opts: toolbar.ToolbarRenderOptions): string;
68
- WORKBENCH_STYLES: "\n/* \u2500\u2500 Split Run Button \u2500\u2500 */\n.codelab-btn-split {\n display: inline-flex;\n align-items: stretch;\n border-radius: var(--cl-radius-md, 6px);\n overflow: visible;\n position: relative;\n}\n.codelab-btn-split .codelab-btn-split__main {\n border-top-right-radius: 0;\n border-bottom-right-radius: 0;\n border-right: 1px solid rgba(0, 0, 0, 0.18);\n}\n.codelab-btn-split .codelab-btn-split__trigger {\n border-top-left-radius: 0;\n border-bottom-left-radius: 0;\n padding: 0 6px;\n min-width: 24px;\n}\n.codelab-split-menu {\n position: absolute;\n top: calc(100% + 4px);\n right: 0;\n background: var(--cl-bg-panel, #18181a);\n border: 1px solid var(--cl-border-strong, var(--cl-border, #27272a));\n border-radius: var(--cl-radius-md, 6px);\n box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);\n z-index: 1200;\n min-width: 220px;\n padding: 4px;\n display: none;\n}\n.codelab-split-menu.open,\n.codelab-split-menu.active {\n display: block;\n}\n.codelab-split-menu__item {\n display: flex;\n align-items: center;\n justify-content: space-between;\n width: 100%;\n padding: 6px 10px;\n border-radius: var(--cl-radius-sm, 4px);\n background: none;\n border: none;\n color: var(--cl-fg, #f4f4f5);\n font-family: var(--cl-font-sans);\n font-size: var(--cl-text-xs, 0.75rem);\n cursor: pointer;\n text-align: left;\n}\n.codelab-split-menu__item:hover,\n.codelab-split-menu__item:focus-visible {\n background: var(--cl-list-active, #28282b);\n color: var(--cl-list-active-fg, #f4f4f5);\n outline: none;\n}\n\n/* \u2500\u2500 Command Palette Trigger Pill \u2500\u2500 */\n.codelab-cmd-trigger {\n display: inline-flex;\n align-items: center;\n gap: 6px;\n padding: 3px 12px;\n min-width: 200px;\n justify-content: center;\n border-radius: var(--cl-radius-md, 6px);\n background: var(--cl-input-bg, #141415);\n border: 1px solid var(--cl-border, #27272a);\n color: var(--cl-fg-muted, #a1a1aa);\n font-family: var(--cl-font-sans);\n font-size: var(--cl-text-xs, 0.75rem);\n cursor: pointer;\n transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;\n}\n.codelab-cmd-trigger:hover,\n.codelab-cmd-trigger:focus-visible {\n background: var(--cl-bg-hover, #1f1f22);\n color: var(--cl-fg, #f4f4f5);\n border-color: var(--cl-border-strong, #3a3a3e);\n outline: none;\n}\n\n/* \u2500\u2500 HUD Telemetry Pill \u2500\u2500 */\n.codelab-hud-pill {\n display: inline-flex;\n align-items: center;\n gap: 8px;\n padding: 2px 10px;\n border-radius: 999px;\n background: var(--cl-bg-panel, #18181a);\n border: 1px solid var(--cl-border, #27272a);\n color: var(--cl-fg-muted, #a1a1aa);\n font-family: var(--cl-font-mono);\n font-size: var(--cl-text-2xs, 0.6875rem);\n font-variant-numeric: tabular-nums;\n font-weight: 500;\n margin-left: auto;\n user-select: none;\n}\n.codelab-hud-pill__metric {\n display: inline-flex;\n align-items: center;\n gap: 4px;\n}\n\n/* \u2500\u2500 Stdin / Custom Input Panel \u2500\u2500 */\n.codelab-stdin-panel {\n display: flex;\n flex-direction: column;\n height: 100%;\n padding: 8px 12px;\n background: var(--cl-bg-editor, #0f0f10);\n box-sizing: border-box;\n}\n.codelab-stdin-panel__header {\n display: flex;\n align-items: center;\n justify-content: space-between;\n margin-bottom: 6px;\n font-family: var(--cl-font-sans);\n font-size: var(--cl-text-xs, 0.75rem);\n color: var(--cl-fg-muted, #a1a1aa);\n font-weight: 500;\n}\n.codelab-stdin-panel__textarea {\n flex: 1;\n width: 100%;\n background: var(--cl-input-bg, #141415);\n border: 1px solid var(--cl-border, #27272a);\n border-radius: var(--cl-radius-md, 6px);\n color: var(--cl-fg, #f4f4f5);\n font-family: var(--cl-font-mono);\n font-size: var(--cl-text-xs, 0.75rem);\n line-height: 1.5;\n padding: 8px 10px;\n resize: none;\n outline: none;\n box-sizing: border-box;\n}\n.codelab-stdin-panel__textarea:focus {\n border-color: var(--cl-focus-border, #a1a1aa);\n}\n\n/* \u2500\u2500 Problems Drawer Tab \u2500\u2500 */\n.codelab-problems-list {\n display: flex;\n flex-direction: column;\n overflow-y: auto;\n height: 100%;\n padding: 4px 0;\n}\n.codelab-problem-item {\n display: flex;\n align-items: center;\n gap: 8px;\n padding: 5px 12px;\n font-size: var(--cl-text-xs, 0.75rem);\n font-family: var(--cl-font-mono);\n cursor: pointer;\n border-bottom: 1px solid var(--cl-border-subtle, #1d1d20);\n}\n.codelab-problem-item:hover {\n background: var(--cl-bg-hover, #1f1f22);\n}\n.codelab-problem-item--error {\n color: var(--cl-red, #f87171);\n}\n.codelab-problem-item--warning {\n color: var(--cl-amber, #fbbf24);\n}\n.codelab-problem-item--info {\n color: var(--cl-fg, #f4f4f5);\n}\n.codelab-problem-item__location {\n color: var(--cl-fg-muted, #a1a1aa);\n font-size: var(--cl-text-2xs, 0.6875rem);\n font-variant-numeric: tabular-nums;\n margin-left: auto;\n}\n\n/* \u2500\u2500 Monaco Side-by-Side Diff Editor \u2500\u2500 */\n.codelab-diff-container {\n display: flex;\n flex-direction: column;\n width: 100%;\n height: 100%;\n background: var(--cl-bg-editor, #0f0f10);\n}\n.codelab-diff-toolbar {\n display: flex;\n align-items: center;\n gap: 8px;\n padding: 6px 12px;\n background: var(--cl-bg-elevated, #141415);\n border-bottom: 1px solid var(--cl-border, #27272a);\n font-family: var(--cl-font-sans);\n font-size: var(--cl-text-xs, 0.75rem);\n}\n.codelab-diff-host {\n flex: 1;\n width: 100%;\n height: calc(100% - 36px);\n position: relative;\n}\n";
69
49
  getFileIconSvg(filename: string, isOpenFolder?: boolean): string;
70
50
  CL_ICONS: Record<string, string>;
71
51
  };
@@ -157,6 +157,7 @@ export declare class WorkspaceAtaController {
157
157
  private inFlight;
158
158
  private disposables;
159
159
  private debounceTimer;
160
+ private disposed;
160
161
  constructor(monaco: MonacoNamespaceLike | null | undefined);
161
162
  scheduleScan(files: Record<string, string>, delayMs?: number): void;
162
163
  scanNow(files: Record<string, string>): Promise<void>;
@@ -177,13 +178,6 @@ export declare function registerCrossFileEditorOpener(monaco: MonacoNamespaceLik
177
178
  export declare function attachAutoCloseTagBehavior(monaco: MonacoNamespaceLike | null | undefined, editor: MonacoEditorLike | null | undefined): {
178
179
  dispose: () => void;
179
180
  };
180
- /**
181
- * Configures Monaco language services once per `monaco` global instance:
182
- * - VS Code Modern themes
183
- * - Node.js ambient `.d.ts` + `tsconfig.json` compiler options
184
- * - JSON schemas (`package.json`, `tsconfig.json`, `jsconfig.json`)
185
- * - HTML Emmet completions, CSS cross-file variable completions/hovers, SQL schema completions/hovers
186
- */
187
181
  export declare function initializeMonacoIntelligence(monaco: MonacoNamespaceLike | null | undefined, getWorkspaceFiles: WorkspaceFilesGetter): void;
188
182
  /**
189
183
  * Extracts structured symbols from any workspace file for Explorer OUTLINE,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@innovatorved/code-lab",
3
- "version": "0.6.1",
3
+ "version": "0.7.1",
4
4
  "description": "Modular browser-native IDE Workbench, Lightweight SQL Playground & Inline Editor (@innovatorved/code-lab/sql), POSIX Shell & Coreutils, PTY Terminal, Web Worker Node.js/Bun Virtual Runtime, C++20 WASI, and Python 3.12 Extension.",
5
5
  "workspaces": [
6
6
  "packages/*",
@@ -8,7 +8,7 @@
8
8
  ],
9
9
  "main": "./dist/code-lab.js",
10
10
  "module": "./dist/code-lab.esm.js",
11
- "umd": "./dist/code-lab.umd.js",
11
+ "umd": "./dist/code-lab.js",
12
12
  "types": "./dist/code-lab.d.ts",
13
13
  "style": "./dist/code-lab.css",
14
14
  "exports": {
@@ -18,7 +18,7 @@
18
18
  "require": "./dist/code-lab.js",
19
19
  "default": "./dist/code-lab.js"
20
20
  },
21
- "./umd": "./dist/code-lab.umd.js",
21
+ "./umd": "./dist/code-lab.js",
22
22
  "./sql": {
23
23
  "types": "./dist/code-lab-sql.d.ts",
24
24
  "import": "./dist/code-lab-sql.esm.js",
@@ -95,7 +95,6 @@
95
95
  "files": [
96
96
  "dist",
97
97
  "src",
98
- "packages",
99
98
  "README.md",
100
99
  "ARCHITECTURE.md",
101
100
  "CHANGELOG.md",
@@ -127,12 +126,6 @@
127
126
  "pack:check": "bun pm pack --dry-run",
128
127
  "prepublishOnly": "bun run build && node tests/test-esm-exports.js && node tests/test-version-sync.js"
129
128
  },
130
- "lint-staged": {
131
- "*.{ts,js}": [
132
- "node tools/lint.js",
133
- "node tools/check-boundaries.js"
134
- ]
135
- },
136
129
  "dependencies": {
137
130
  "zod": "^4.6.7"
138
131
  },