dimcode-web 0.1.0-alpha.10 → 0.1.0-alpha.12

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 (70) hide show
  1. package/package.json +1 -1
  2. package/release-manifest.json +64 -64
  3. package/web/assets/{CodeBlockNode-BkKCYSZe.js → CodeBlockNode-60OgUwQ7.js} +2 -2
  4. package/web/assets/{PreCodeBlock-CQiTyDCM.js → PreCodeBlock-DVwonMrZ.js} +1 -1
  5. package/web/assets/{Tooltip-CU5QexXw.js → Tooltip-D_iQTc-v.js} +1 -1
  6. package/web/assets/{arc-8_yX_UH-.js → arc-BDSDdwDv.js} +1 -1
  7. package/web/assets/{architectureDiagram-3BPJPVTR-BcXLOfOI.js → architectureDiagram-3BPJPVTR-Bp-buFYT.js} +1 -1
  8. package/web/assets/{blockDiagram-GPEHLZMM-CEKtakPc.js → blockDiagram-GPEHLZMM-CGFXutYB.js} +1 -1
  9. package/web/assets/{c4Diagram-AAUBKEIU-zZcpoKmv.js → c4Diagram-AAUBKEIU-CK81MW6S.js} +1 -1
  10. package/web/assets/channel-vaJb6Uzh.js +1 -0
  11. package/web/assets/{chunk-2J33WTMH-dFnQn9hc.js → chunk-2J33WTMH-BoGFm_Ja.js} +1 -1
  12. package/web/assets/{chunk-4BX2VUAB-DjjPcYaV.js → chunk-4BX2VUAB-CbZzNwQg.js} +1 -1
  13. package/web/assets/{chunk-55IACEB6-D_6EcDqZ.js → chunk-55IACEB6-BZora9t3.js} +1 -1
  14. package/web/assets/{chunk-727SXJPM-CI-3chrs.js → chunk-727SXJPM-BW7PYkUF.js} +1 -1
  15. package/web/assets/{chunk-AQP2D5EJ-DRgiAbw2.js → chunk-AQP2D5EJ-jBr0F1L0.js} +1 -1
  16. package/web/assets/{chunk-FMBD7UC4-BqKrwDA_.js → chunk-FMBD7UC4-Ctw2_biG.js} +1 -1
  17. package/web/assets/{chunk-ND2GUHAM-B5cAPOB1.js → chunk-ND2GUHAM-CglIMpot.js} +1 -1
  18. package/web/assets/{chunk-QZHKN3VN-F4YC8_f_.js → chunk-QZHKN3VN-Dafu5qlJ.js} +1 -1
  19. package/web/assets/classDiagram-4FO5ZUOK-EjflPmAx.js +1 -0
  20. package/web/assets/classDiagram-v2-Q7XG4LA2-EjflPmAx.js +1 -0
  21. package/web/assets/{cose-bilkent-S5V4N54A-CajCdXuh.js → cose-bilkent-S5V4N54A-CU_bA9uN.js} +1 -1
  22. package/web/assets/{cynefin-OW5HDTMX-Dy6w1bhP.js → cynefin-OW5HDTMX-C4xDBkC-.js} +1 -1
  23. package/web/assets/{dagre-BM42HDAG-BymkC887.js → dagre-BM42HDAG-ByBoKdtM.js} +1 -1
  24. package/web/assets/{diagram-2AECGRRQ-CtfaySwH.js → diagram-2AECGRRQ-D069CPLb.js} +1 -1
  25. package/web/assets/{diagram-5GNKFQAL-Bl6KUMhr.js → diagram-5GNKFQAL-gV_KxSca.js} +1 -1
  26. package/web/assets/{diagram-KO2AKTUF-P5sfwN61.js → diagram-KO2AKTUF-B7puC9pY.js} +1 -1
  27. package/web/assets/{diagram-LMA3HP47-D9gD2CpB.js → diagram-LMA3HP47-C3skBDvs.js} +1 -1
  28. package/web/assets/{diagram-OG6HWLK6-CaCRrHGf.js → diagram-OG6HWLK6-CMHB2OJj.js} +1 -1
  29. package/web/assets/{erDiagram-TEJ5UH35-CNM4s1KX.js → erDiagram-TEJ5UH35-BiaN4dqV.js} +1 -1
  30. package/web/assets/{flowDiagram-I6XJVG4X-Bdb65Mja.js → flowDiagram-I6XJVG4X-BToOh9_1.js} +1 -1
  31. package/web/assets/{ganttDiagram-6RSMTGT7-D9faE2e8.js → ganttDiagram-6RSMTGT7-BvExJCp1.js} +1 -1
  32. package/web/assets/{gitGraphDiagram-PVQCEYII-4d4jIMfU.js → gitGraphDiagram-PVQCEYII-DDSemQ7P.js} +1 -1
  33. package/web/assets/{index-DejS3DXy.js → index-BeRBs4X9.js} +1 -1
  34. package/web/assets/index-BtvPmxLc.js +220 -0
  35. package/web/assets/{index-DR4aU0C0.js → index-DviuyFKA.js} +5 -5
  36. package/web/assets/{index-CRlNNu-y.css → index-QWsLY5HH.css} +1 -1
  37. package/web/assets/{index10-juJIi9I9.js → index10-dOy_vQD6.js} +1 -1
  38. package/web/assets/{index5-Bl0GOZhI.js → index5-BOU2nLE8.js} +1 -1
  39. package/web/assets/{index6-BHdMpBG5.js → index6-DR5XmdMu.js} +1 -1
  40. package/web/assets/{index8-AB_Nvz6R.js → index8-BvRgDa_J.js} +1 -1
  41. package/web/assets/{index9-DMukeGfx.js → index9-DbcgM9Nq.js} +1 -1
  42. package/web/assets/{infoDiagram-5YYISTIA-CdX5UJTa.js → infoDiagram-5YYISTIA-Cn4tOhRG.js} +1 -1
  43. package/web/assets/{ishikawaDiagram-YF4QCWOH-Dr_2Rp3Q.js → ishikawaDiagram-YF4QCWOH-rWzBXYON.js} +1 -1
  44. package/web/assets/{journeyDiagram-JHISSGLW-CCfHuw7c.js → journeyDiagram-JHISSGLW-Bxr_4EqR.js} +1 -1
  45. package/web/assets/{kanban-definition-UN3LZRKU-Dj3UcbF2.js → kanban-definition-UN3LZRKU-DsCcDt8-.js} +1 -1
  46. package/web/assets/{linear-CL3Z5odF.js → linear-BS3Zj0XR.js} +1 -1
  47. package/web/assets/{markstream-CoUaLNpp.js → markstream-BkeUOv85.js} +2 -2
  48. package/web/assets/{mermaid.core-BJxGOoVA.js → mermaid.core-Dx_GaOpJ.js} +4 -4
  49. package/web/assets/{mindmap-definition-RKZ34NQL-D00RLQRV.js → mindmap-definition-RKZ34NQL-DFpB8AIF.js} +1 -1
  50. package/web/assets/{pieDiagram-4H26LBE5-BGqQfehd.js → pieDiagram-4H26LBE5-BQwF2tkc.js} +1 -1
  51. package/web/assets/{quadrantDiagram-W4KKPZXB-C_tNe1Cp.js → quadrantDiagram-W4KKPZXB-D52eaKYL.js} +1 -1
  52. package/web/assets/{requirementDiagram-4Y6WPE33-DI3N4qEV.js → requirementDiagram-4Y6WPE33-D7jJIlEK.js} +1 -1
  53. package/web/assets/{sankeyDiagram-5OEKKPKP-B4HsHxOU.js → sankeyDiagram-5OEKKPKP-CIippr_x.js} +1 -1
  54. package/web/assets/{sequenceDiagram-3UESZ5HK-BwPltP8r.js → sequenceDiagram-3UESZ5HK-CFeGDWiC.js} +1 -1
  55. package/web/assets/{stateDiagram-AJRCARHV-CaXU_K9y.js → stateDiagram-AJRCARHV-CQ2cSqF2.js} +1 -1
  56. package/web/assets/stateDiagram-v2-BHNVJYJU-CAbFkRgA.js +1 -0
  57. package/web/assets/{timeline-definition-PNZ67QCA-CH2JsvOa.js → timeline-definition-PNZ67QCA-BFuzLqGU.js} +1 -1
  58. package/web/assets/{vendor-vue-CrmKjNvT.js → vendor-vue-9TAdpIVM.js} +1 -1
  59. package/web/assets/{vennDiagram-CIIHVFJN-CmXeNPt4.js → vennDiagram-CIIHVFJN-FjL7IGQe.js} +1 -1
  60. package/web/assets/{wardleyDiagram-YWT4CUSO-BjI-bjBh.js → wardleyDiagram-YWT4CUSO-Dfz0iI5u.js} +1 -1
  61. package/web/assets/{xychartDiagram-2RQKCTM6-DCM4Ln-n.js → xychartDiagram-2RQKCTM6-BDomIXQK.js} +1 -1
  62. package/web/assets/zh-CN-CSwtlg0N.js +1 -0
  63. package/web/dimcode-web.json +2 -2
  64. package/web/index.html +3 -3
  65. package/web/assets/channel-Bd1htsYX.js +0 -1
  66. package/web/assets/classDiagram-4FO5ZUOK-BIb2luMM.js +0 -1
  67. package/web/assets/classDiagram-v2-Q7XG4LA2-BIb2luMM.js +0 -1
  68. package/web/assets/index-BNyYcMrm.js +0 -191
  69. package/web/assets/stateDiagram-v2-BHNVJYJU-Bi9yoMtb.js +0 -1
  70. package/web/assets/zh-CN-D1J2z6LG.js +0 -1
@@ -1,5 +1,5 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-DejS3DXy.js","assets/index-BNyYcMrm.js","assets/vendor-vue-CrmKjNvT.js","assets/index-CRlNNu-y.css"])))=>i.map(i=>d[i]);
2
- var Y=Object.defineProperty;var Z=(e,i,t)=>i in e?Y(e,i,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[i]=t;var f=(e,i,t)=>Z(e,typeof i!="symbol"?i+"":i,t);import{_ as ee}from"./index-BNyYcMrm.js";import"./vendor-vue-CrmKjNvT.js";var ie=class{constructor(){f(this,"chunks",[]);f(this,"cached","");f(this,"dirty",!1);f(this,"length",0)}append(e){e&&(this.chunks.push(e),this.length+=e.length,this.dirty=!0,this.chunks.length>256&&this.compact())}clear(e=""){this.chunks=e?[e]:[],this.cached=e,this.dirty=!1,this.length=e.length}toString(){return this.dirty&&(this.cached=this.chunks.join(""),this.dirty=!1),this.cached}compact(){this.chunks=[this.chunks.join("")]}};function H(e,i){e.replaceChildren();const t=document.createElement("div");t.className="stream-diffs-shell",t.style.overflow="auto",t.style.maxHeight=typeof i=="number"?`${i}px`:i??"none";const n=document.createElement("div");return n.className="stream-diffs-surface",t.appendChild(n),e.appendChild(t),{shell:t,surface:n}}function L(e,i,t){return{name:e,contents:i,lang:t}}var te=class{constructor(e){f(this,"input");f(this,"container");f(this,"surface");f(this,"instance");f(this,"diff");f(this,"selectedLines",null);f(this,"disposed",!1);f(this,"renderListeners",new Set);f(this,"visualRevision",0);f(this,"visualReadyPromise",Promise.resolve(!1));f(this,"resolveVisualReady");f(this,"module");this.input=e}async mount(e){this.disposed=!1,this.container=e,this.surface=H(e).surface,await this.render()}async update(e){this.input=e,this.surface&&await this.render(!0)}updateFile(e,i){return this.update({kind:"file",file:e,annotations:i,options:this.input.kind==="file"?this.input.options:void 0,workerManager:this.input.kind==="file"?this.input.workerManager:void 0})}updateDiff(e,i,t){return this.update({kind:"diff",oldFile:e,newFile:i,annotations:t,options:k(this.input)?this.input.options:void 0,workerManager:k(this.input)?this.input.workerManager:void 0})}updateParsedDiff(e,i){return this.update({kind:"diff",fileDiff:e,annotations:i,options:k(this.input)?this.input.options:void 0,workerManager:k(this.input)?this.input.workerManager:void 0})}updatePatch(e,i=0,t,n=0){return this.update({kind:"patch",patch:e,patchIndex:n,fileIndex:i,annotations:t,options:this.input.kind==="patch"?this.input.options:void 0,workerManager:this.input.kind==="patch"?this.input.workerManager:void 0})}updateMergeConflict(e,i){return this.update({kind:"merge-conflict",file:e,annotations:i,options:this.input.kind==="merge-conflict"?this.input.options:void 0,workerManager:this.input.kind==="merge-conflict"?this.input.workerManager:void 0})}setSelectedLines(e){var i;this.selectedLines=e,(i=this.instance)==null||i.setSelectedLines(e)}setAnnotations(e){this.instance&&(this.input.kind==="file"?(this.input.annotations=e,this.instance.setLineAnnotations(this.input.annotations)):(this.input.annotations=e,this.instance.setLineAnnotations(this.input.annotations)),this.emitRender())}setThemeType(e){var i;this.input.options?this.input.options={...this.input.options,themeType:e}:this.input.options={themeType:e},(i=this.instance)==null||i.setThemeType(e)}async setTheme(e){this.input.options?this.input.options={...this.input.options,theme:e}:this.input.options={theme:e},this.surface&&await this.render(!1)}async setOptions(e){this.input.options=e,this.surface&&await this.render(!1)}acceptReject(e,i){if(!k(this.input)||!this.diff)throw new Error("acceptReject() requires a diff view");const{diffAcceptRejectHunk:t}=this.module;return this.diff=t(this.diff,e,i),this.instance.render({fileDiff:this.diff,containerWrapper:this.surface,lineAnnotations:this.input.annotations}),this.diff}resolveConflict(e,i){if(this.input.kind!=="merge-conflict")throw new Error("resolveConflict() requires a merge-conflict view");const t=this.instance.resolveConflict(e,i);return t&&(this.input.file=t.file,this.diff=t.fileDiff),t==null?void 0:t.file}getResolvedFile(){if(!k(this.input)||!this.diff||this.diff.isPartial)return;const e="newFile"in this.input?this.input.newFile:void 0;return{name:(e==null?void 0:e.name)??this.diff.name,contents:this.diff.additionLines.join(""),lang:(e==null?void 0:e.lang)??this.diff.lang}}getDiff(){return this.diff}getInput(){return this.input}getNativeInstance(){return this.instance}onDidRender(e){return this.renderListeners.add(e),{dispose:()=>this.renderListeners.delete(e)}}async whenVisualReady(){let e=this.visualReadyPromise;for(;;){const i=await e;if(e===this.visualReadyPromise)return i;e=this.visualReadyPromise}}dispose(){var e,i;this.disposed=!0,this.invalidateVisualReady(),(e=this.instance)==null||e.cleanUp(),this.instance=void 0,this.surface=void 0,(i=this.container)==null||i.replaceChildren(),this.container=void 0,this.renderListeners.clear()}async render(e=!0){var a,r;const i=this.surface;if(!i||this.disposed)return;const t=this.beginVisualRender(),n=this.module??(this.module=await ee(()=>import("./index-DejS3DXy.js"),__vite__mapDeps([0,1,2,3])));if(this.disposed||i!==this.surface)return;if((a=this.instance)==null||a.cleanUp(),i.replaceChildren(),this.input.kind==="file"){const d=new n.File(b(this.input.options,()=>this.markVisualReady(t)),this.input.workerManager);d.render({file:this.input.file,containerWrapper:i,lineAnnotations:this.input.annotations}),this.instance=d,d.setSelectedLines(this.selectedLines),this.diff=void 0;return}if(k(this.input)){if(e||!this.diff)if(this.input.kind==="patch"){const g=n.parsePatchFiles(this.input.patch)[this.input.patchIndex??0];if(!g)throw new Error(`Patch does not contain patch index ${this.input.patchIndex??0}`);const h=g.files[this.input.fileIndex??0];if(!h)throw new Error(`Patch does not contain file index ${this.input.fileIndex??0}`);this.diff=h}else"fileDiff"in this.input?this.diff=this.input.fileDiff:this.diff=n.parseDiffFromFile(this.input.oldFile,this.input.newFile,(r=this.input.options)==null?void 0:r.parseDiffOptions);const d=new n.FileDiff(b(this.input.options,()=>this.markVisualReady(t)),this.input.workerManager);d.render({fileDiff:this.diff,containerWrapper:i,lineAnnotations:this.input.annotations}),this.instance=d,d.setSelectedLines(this.selectedLines);return}const o=new n.UnresolvedFile(b(this.input.options,()=>this.markVisualReady(t)),this.input.workerManager);o.render({file:this.input.file,containerWrapper:i,lineAnnotations:this.input.annotations}),this.instance=o,o.setSelectedLines(this.selectedLines),this.diff=o.fileDiff}emitRender(){for(const e of this.renderListeners)e()}beginVisualRender(){var i;(i=this.resolveVisualReady)==null||i.call(this,!1);const e=++this.visualRevision;return this.visualReadyPromise=new Promise(t=>{this.resolveVisualReady=t}),e}markVisualReady(e){var i;this.disposed||e!==this.visualRevision||((i=this.resolveVisualReady)==null||i.call(this,!0),this.resolveVisualReady=void 0,this.emitRender())}invalidateVisualReady(){var e;this.visualRevision++,(e=this.resolveVisualReady)==null||e.call(this,!1),this.resolveVisualReady=void 0}};function M(e){return new te(e)}function ne(e){return!e||e.useTokenTransformer===!0||!e.onTokenClick&&!e.onTokenEnter&&!e.onTokenLeave?e:{...e,useTokenTransformer:!0}}function b(e,i){const t=ne(e),n=t==null?void 0:t.onPostRender;return{...t,onPostRender(...o){n==null||n(...o),i()}}}function k(e){return e.kind==="diff"||e.kind==="patch"}var se=class{constructor(e={}){f(this,"options");f(this,"state","idle");f(this,"stats",{characters:0,lines:0,writes:0,resets:0,renderMode:"plain-text",overflowed:!1});f(this,"text",new ie);f(this,"pending",[]);f(this,"scheduled");f(this,"generation",0);f(this,"container");f(this,"shell");f(this,"surface");f(this,"finalizedSurface");f(this,"plainText");f(this,"finalizePromise");f(this,"renderListeners",new Set);f(this,"finalizedRenderSubscription");this.options=e}async mount(e){var n,o,a,r;if(this.state==="disposed")throw new Error("Cannot mount a disposed code stream. Create a new controller instead.");++this.generation,this.cancelScheduledFlush(),(n=this.finalizedSurface)==null||n.dispose(),(o=this.finalizedRenderSubscription)==null||o.dispose(),(a=this.container)==null||a.replaceChildren(),this.finalizedSurface=void 0,this.finalizedRenderSubscription=void 0,this.plainText=void 0,this.pending=[],this.setState("mounting"),this.container=e;const{shell:i,surface:t}=H(e,this.options.maxHeight);this.shell=i,this.surface=t,this.mountPlainText(t),(r=this.stats).startedAt??(r.startedAt=performance.now()),this.setState("streaming")}append(e){if(e){if(this.state==="finalized"||this.state==="finalizing"||this.state==="disposed")throw new Error(`Cannot append while stream is ${this.state}`);this.text.append(e),this.stats.characters=this.text.length,this.stats.lines+=re(e)+(this.stats.lines===0?1:0),this.pending.push(e),this.scheduleFlush()}}updateSnapshot(e){const i=this.text.toString();if(e.startsWith(i)){this.append(e.slice(i.length));return}const t=this.options.nonAppendBehavior??"reset";if(t!=="ignore"){if(t==="throw")throw new Error("Snapshot violates the append-only stream contract");return this.reset(e)}}async consume(e){try{if(Symbol.asyncIterator in e)for await(const i of e)this.append(i);else{const i=e.getReader();try{for(;;){const{done:t,value:n}=await i.read();if(t)break;this.append(n)}}finally{i.releaseLock()}}}catch(i){throw this.fail(i),i}}async flush(){var t;if(this.cancelScheduledFlush(),!this.pending.length)return;const e=this.shouldFollowViewport(),i=this.pending.join("");this.pending.length=0,(t=this.plainText)==null||t.append(i),this.stats.writes++,this.followViewport(e),this.emitRender()}finalize(e={view:"stream"}){if(this.state==="finalized")return Promise.resolve();if(this.finalizePromise)return this.finalizePromise;const i=this.performFinalize(e).finally(()=>{this.finalizePromise===i&&(this.finalizePromise=void 0)});return this.finalizePromise=i,i}async performFinalize(e){if(this.state==="disposed")throw new Error("Cannot finalize a disposed code stream");const i=this.generation;if(this.setState("finalizing"),await this.flush(),i!==this.generation)return;if(this.stats.finalizedAt=performance.now(),!e.view||e.view==="stream"){this.setState("finalized");return}const t=this.surface;if(!t)throw new Error("Mount the stream before finalizing to a file or diff view");const n=this.options.fileName??`code.${this.options.language??"txt"}`,o=L(n,this.getText(),this.options.language);let a;if(e.view==="file"){const{annotations:c,workerManager:y,view:S,...z}=e;a=M({kind:"file",file:o,annotations:c,options:{theme:this.options.theme,themeType:this.options.themeType,...z},workerManager:y??this.options.workerManager})}else{const{annotations:c,original:y,workerManager:S,view:z,...D}=e;a=M({kind:"diff",oldFile:L(n,y,this.options.language),newFile:o,annotations:c,options:{theme:this.options.theme,themeType:this.options.themeType,...D},workerManager:S??this.options.workerManager})}const r=document.createElement("div");if(r.className="stream-diffs-finalized",await a.mount(r),i!==this.generation){a.dispose();return}const d=this.shell,g=(d==null?void 0:d.scrollTop)??0,h=d?d.scrollHeight-d.scrollTop-d.clientHeight:0;t.replaceWith(r),this.surface=r,this.plainText=void 0,this.finalizedSurface=a,this.finalizedRenderSubscription=a.onDidRender(()=>this.emitRender()),d&&(this.options.autoScroll==="always"||this.options.autoScroll!=="never"&&h<=(this.options.autoScrollThresholdPx??32)?d.scrollTop=d.scrollHeight:d.scrollTop=g),this.setState("finalized"),this.emitRender()}async reset(e=""){var t,n;const i=this.container;++this.generation,this.cancelScheduledFlush(),(t=this.finalizedSurface)==null||t.dispose(),(n=this.finalizedRenderSubscription)==null||n.dispose(),this.finalizedSurface=void 0,this.finalizedRenderSubscription=void 0,this.plainText=void 0,this.pending=[],this.finalizePromise=void 0,this.text.clear(),this.stats.resets++,this.stats.characters=0,this.stats.lines=0,this.stats.renderMode="plain-text",this.stats.overflowed=!1,this.setState("idle"),e&&this.append(e),i&&await this.mount(i)}setThemeType(e){var i;this.options.themeType=e,(i=this.finalizedSurface)==null||i.setThemeType(e)}async setTheme(e){this.options.theme=e,this.finalizedSurface&&await this.finalizedSurface.setTheme(e)}async setLanguage(e){if(e===this.options.language||(this.options.language=e,!this.finalizedSurface))return;const i=this.finalizedSurface.getInput();i.kind==="file"?await this.finalizedSurface.updateFile({...i.file,lang:e},i.annotations):i.kind==="diff"&&"oldFile"in i&&await this.finalizedSurface.updateDiff({...i.oldFile,lang:e},{...i.newFile,lang:e},i.annotations)}getText(){return this.text.toString()}getState(){return this.state}getStats(){return{...this.stats}}getElement(){return this.shell}getFinalizedSurface(){return this.finalizedSurface}onDidRender(e){return this.renderListeners.add(e),{dispose:()=>this.renderListeners.delete(e)}}dispose(){var e,i,t;++this.generation,this.cancelScheduledFlush(),(e=this.finalizedSurface)==null||e.dispose(),(i=this.finalizedRenderSubscription)==null||i.dispose(),(t=this.container)==null||t.replaceChildren(),this.plainText=void 0,this.container=void 0,this.surface=void 0,this.shell=void 0,this.finalizedSurface=void 0,this.finalizedRenderSubscription=void 0,this.finalizePromise=void 0,this.renderListeners.clear(),this.setState("disposed")}scheduleFlush(){if(this.scheduled!=null||!this.plainText)return;const e=this.options.flushStrategy??"raf";e==="raf"&&typeof requestAnimationFrame=="function"?this.scheduled=requestAnimationFrame(()=>void this.flush()):this.scheduled=globalThis.setTimeout(()=>void this.flush(),e==="raf"?0:e.intervalMs)}cancelScheduledFlush(){this.scheduled!=null&&(typeof cancelAnimationFrame=="function"&&cancelAnimationFrame(this.scheduled),clearTimeout(this.scheduled),this.scheduled=void 0)}shouldFollowViewport(){const e=this.shell;return!e||this.options.autoScroll==="never"?!1:this.options.autoScroll==="always"?!0:e.scrollHeight-e.scrollTop-e.clientHeight<=(this.options.autoScrollThresholdPx??32)}followViewport(e=this.shouldFollowViewport()){this.shell&&e&&(this.shell.scrollTop=this.shell.scrollHeight)}mountPlainText(e){const i=document.createElement("pre");i.className="stream-diffs-plain-text",i.dataset.streamDiffsState="streaming",i.style.margin="0",i.style.whiteSpace=this.options.wrap?"pre-wrap":"pre",i.style.overflowWrap=this.options.wrap?"anywhere":"normal",i.textContent=this.getText(),e.replaceChildren(i),this.plainText=i}setState(e){var i,t;this.state=e,(t=(i=this.options).onStateChange)==null||t.call(i,e)}emitRender(){for(const e of this.renderListeners)e()}fail(e){var i,t;this.state!=="disposed"&&(this.setState("error"),(t=(i=this.options).onError)==null||t.call(i,e))}};function re(e){let i=0;for(let t=0;t<e.length;t++)e.charCodeAt(t)===10&&i++;return i}var ae=class{constructor(e={}){f(this,"options");f(this,"state","idle");f(this,"generation",0);f(this,"original","");f(this,"modified","");f(this,"container");f(this,"shell");f(this,"surface");f(this,"finalizedSurface");f(this,"finalizePromise");f(this,"renderListeners",new Set);f(this,"finalizedRenderSubscription");this.options=e}async mount(e,i=this.original,t=this.modified){var a,r,d;if(this.state==="disposed")throw new Error("Cannot mount a disposed diff stream. Create a new controller instead.");++this.generation,this.original=i,this.modified=t,(a=this.finalizedSurface)==null||a.dispose(),(r=this.finalizedRenderSubscription)==null||r.dispose(),(d=this.container)==null||d.replaceChildren(),this.finalizedSurface=void 0,this.finalizedRenderSubscription=void 0,this.setState("mounting"),this.container=e;const{shell:n,surface:o}=H(e,this.options.maxHeight);this.shell=n,this.surface=o,this.renderPre(),this.setState("streaming")}update(e,i){if(this.state==="disposed")throw new Error("Cannot update a disposed diff stream");return this.original=e,this.modified=i,this.finalizedSurface?this.finalizedSurface.updateDiff(this.asFile(e),this.asFile(i)):(this.renderPre(),this.emitRender(),Promise.resolve())}finalize(e){if(this.state==="finalized")return Promise.resolve(this.finalizedSurface);if(this.finalizePromise)return this.finalizePromise;const i=this.performFinalize(e).finally(()=>{this.finalizePromise===i&&(this.finalizePromise=void 0)});return this.finalizePromise=i,i}async performFinalize(e){if(this.state==="disposed")throw new Error("Cannot finalize a disposed diff stream");const i=this.surface;if(!i)throw new Error("Mount the diff stream before finalizing it");const t=this.generation;this.setState("finalizing");const n=M({kind:"diff",oldFile:this.asFile(this.original),newFile:this.asFile(this.modified),annotations:e,options:{...this.options,diffStyle:this.options.diffStyle??"unified"},workerManager:this.options.workerManager}),o=document.createElement("div");if(o.className="stream-diffs-finalized",await n.mount(o),t!==this.generation){n.dispose();return}const a=this.shell,r=(a==null?void 0:a.scrollTop)??0;return i.replaceWith(o),this.surface=o,this.finalizedSurface=n,this.finalizedRenderSubscription=n.onDidRender(()=>this.emitRender()),a&&(a.scrollTop=r),this.setState("finalized"),this.emitRender(),n}setThemeType(e){var i;this.options.themeType=e,(i=this.finalizedSurface)==null||i.setThemeType(e)}async setTheme(e){this.options.theme=e,this.finalizedSurface&&await this.finalizedSurface.setTheme(e)}async setLanguage(e){if(e!==this.options.language){if(this.options.language=e,this.finalizedSurface){const i=this.finalizedSurface.getInput();i.kind==="diff"&&"oldFile"in i&&await this.finalizedSurface.updateDiff({...i.oldFile,lang:e},{...i.newFile,lang:e},i.annotations);return}this.renderPre()}}getOriginal(){return this.original}getModified(){return this.modified}getState(){return this.state}getElement(){return this.shell}getFinalizedSurface(){return this.finalizedSurface}onDidRender(e){return this.renderListeners.add(e),{dispose:()=>this.renderListeners.delete(e)}}dispose(){var e,i,t;++this.generation,(e=this.finalizedSurface)==null||e.dispose(),(i=this.finalizedRenderSubscription)==null||i.dispose(),(t=this.container)==null||t.replaceChildren(),this.container=void 0,this.shell=void 0,this.surface=void 0,this.finalizedSurface=void 0,this.finalizedRenderSubscription=void 0,this.finalizePromise=void 0,this.renderListeners.clear(),this.setState("disposed")}renderPre(){const e=this.surface;if(!e||this.finalizedSurface)return;const i=document.createElement("div");i.className=`stream-diffs-diff-pre stream-diffs-diff-pre--${this.options.diffStyle??"unified"}`,i.dataset.streamDiffsState="streaming",i.style.minWidth="max-content",(this.options.diffStyle??"unified")==="split"?(i.style.display="grid",i.style.gridTemplateColumns="minmax(0, 1fr) minmax(0, 1fr)",i.append(this.createPre(this.original,"deletions"),this.createPre(this.modified,"additions"))):i.append(this.createPre(oe(this.original,this.modified),"unified")),e.replaceChildren(i)}createPre(e,i){const t=document.createElement("pre");return t.className=`stream-diffs-diff-pre__pane stream-diffs-diff-pre__pane--${i}`,t.dataset.side=i,t.style.margin="0",t.style.whiteSpace=this.options.wrap?"pre-wrap":"pre",t.style.overflowWrap=this.options.wrap?"anywhere":"normal",t.textContent=e,t}asFile(e){return L(this.options.fileName??`code.${this.options.language??"txt"}`,e,this.options.language)}setState(e){var i,t;this.state=e,(t=(i=this.options).onStateChange)==null||t.call(i,e)}emitRender(){for(const e of this.renderListeners)e()}};function oe(e,i){const t=e.split(`
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-BeRBs4X9.js","assets/index-BtvPmxLc.js","assets/vendor-vue-9TAdpIVM.js","assets/index-QWsLY5HH.css"])))=>i.map(i=>d[i]);
2
+ var Y=Object.defineProperty;var Z=(e,i,t)=>i in e?Y(e,i,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[i]=t;var f=(e,i,t)=>Z(e,typeof i!="symbol"?i+"":i,t);import{_ as ee}from"./index-BtvPmxLc.js";import"./vendor-vue-9TAdpIVM.js";var ie=class{constructor(){f(this,"chunks",[]);f(this,"cached","");f(this,"dirty",!1);f(this,"length",0)}append(e){e&&(this.chunks.push(e),this.length+=e.length,this.dirty=!0,this.chunks.length>256&&this.compact())}clear(e=""){this.chunks=e?[e]:[],this.cached=e,this.dirty=!1,this.length=e.length}toString(){return this.dirty&&(this.cached=this.chunks.join(""),this.dirty=!1),this.cached}compact(){this.chunks=[this.chunks.join("")]}};function H(e,i){e.replaceChildren();const t=document.createElement("div");t.className="stream-diffs-shell",t.style.overflow="auto",t.style.maxHeight=typeof i=="number"?`${i}px`:i??"none";const n=document.createElement("div");return n.className="stream-diffs-surface",t.appendChild(n),e.appendChild(t),{shell:t,surface:n}}function L(e,i,t){return{name:e,contents:i,lang:t}}var te=class{constructor(e){f(this,"input");f(this,"container");f(this,"surface");f(this,"instance");f(this,"diff");f(this,"selectedLines",null);f(this,"disposed",!1);f(this,"renderListeners",new Set);f(this,"visualRevision",0);f(this,"visualReadyPromise",Promise.resolve(!1));f(this,"resolveVisualReady");f(this,"module");this.input=e}async mount(e){this.disposed=!1,this.container=e,this.surface=H(e).surface,await this.render()}async update(e){this.input=e,this.surface&&await this.render(!0)}updateFile(e,i){return this.update({kind:"file",file:e,annotations:i,options:this.input.kind==="file"?this.input.options:void 0,workerManager:this.input.kind==="file"?this.input.workerManager:void 0})}updateDiff(e,i,t){return this.update({kind:"diff",oldFile:e,newFile:i,annotations:t,options:k(this.input)?this.input.options:void 0,workerManager:k(this.input)?this.input.workerManager:void 0})}updateParsedDiff(e,i){return this.update({kind:"diff",fileDiff:e,annotations:i,options:k(this.input)?this.input.options:void 0,workerManager:k(this.input)?this.input.workerManager:void 0})}updatePatch(e,i=0,t,n=0){return this.update({kind:"patch",patch:e,patchIndex:n,fileIndex:i,annotations:t,options:this.input.kind==="patch"?this.input.options:void 0,workerManager:this.input.kind==="patch"?this.input.workerManager:void 0})}updateMergeConflict(e,i){return this.update({kind:"merge-conflict",file:e,annotations:i,options:this.input.kind==="merge-conflict"?this.input.options:void 0,workerManager:this.input.kind==="merge-conflict"?this.input.workerManager:void 0})}setSelectedLines(e){var i;this.selectedLines=e,(i=this.instance)==null||i.setSelectedLines(e)}setAnnotations(e){this.instance&&(this.input.kind==="file"?(this.input.annotations=e,this.instance.setLineAnnotations(this.input.annotations)):(this.input.annotations=e,this.instance.setLineAnnotations(this.input.annotations)),this.emitRender())}setThemeType(e){var i;this.input.options?this.input.options={...this.input.options,themeType:e}:this.input.options={themeType:e},(i=this.instance)==null||i.setThemeType(e)}async setTheme(e){this.input.options?this.input.options={...this.input.options,theme:e}:this.input.options={theme:e},this.surface&&await this.render(!1)}async setOptions(e){this.input.options=e,this.surface&&await this.render(!1)}acceptReject(e,i){if(!k(this.input)||!this.diff)throw new Error("acceptReject() requires a diff view");const{diffAcceptRejectHunk:t}=this.module;return this.diff=t(this.diff,e,i),this.instance.render({fileDiff:this.diff,containerWrapper:this.surface,lineAnnotations:this.input.annotations}),this.diff}resolveConflict(e,i){if(this.input.kind!=="merge-conflict")throw new Error("resolveConflict() requires a merge-conflict view");const t=this.instance.resolveConflict(e,i);return t&&(this.input.file=t.file,this.diff=t.fileDiff),t==null?void 0:t.file}getResolvedFile(){if(!k(this.input)||!this.diff||this.diff.isPartial)return;const e="newFile"in this.input?this.input.newFile:void 0;return{name:(e==null?void 0:e.name)??this.diff.name,contents:this.diff.additionLines.join(""),lang:(e==null?void 0:e.lang)??this.diff.lang}}getDiff(){return this.diff}getInput(){return this.input}getNativeInstance(){return this.instance}onDidRender(e){return this.renderListeners.add(e),{dispose:()=>this.renderListeners.delete(e)}}async whenVisualReady(){let e=this.visualReadyPromise;for(;;){const i=await e;if(e===this.visualReadyPromise)return i;e=this.visualReadyPromise}}dispose(){var e,i;this.disposed=!0,this.invalidateVisualReady(),(e=this.instance)==null||e.cleanUp(),this.instance=void 0,this.surface=void 0,(i=this.container)==null||i.replaceChildren(),this.container=void 0,this.renderListeners.clear()}async render(e=!0){var a,r;const i=this.surface;if(!i||this.disposed)return;const t=this.beginVisualRender(),n=this.module??(this.module=await ee(()=>import("./index-BeRBs4X9.js"),__vite__mapDeps([0,1,2,3])));if(this.disposed||i!==this.surface)return;if((a=this.instance)==null||a.cleanUp(),i.replaceChildren(),this.input.kind==="file"){const d=new n.File(b(this.input.options,()=>this.markVisualReady(t)),this.input.workerManager);d.render({file:this.input.file,containerWrapper:i,lineAnnotations:this.input.annotations}),this.instance=d,d.setSelectedLines(this.selectedLines),this.diff=void 0;return}if(k(this.input)){if(e||!this.diff)if(this.input.kind==="patch"){const g=n.parsePatchFiles(this.input.patch)[this.input.patchIndex??0];if(!g)throw new Error(`Patch does not contain patch index ${this.input.patchIndex??0}`);const h=g.files[this.input.fileIndex??0];if(!h)throw new Error(`Patch does not contain file index ${this.input.fileIndex??0}`);this.diff=h}else"fileDiff"in this.input?this.diff=this.input.fileDiff:this.diff=n.parseDiffFromFile(this.input.oldFile,this.input.newFile,(r=this.input.options)==null?void 0:r.parseDiffOptions);const d=new n.FileDiff(b(this.input.options,()=>this.markVisualReady(t)),this.input.workerManager);d.render({fileDiff:this.diff,containerWrapper:i,lineAnnotations:this.input.annotations}),this.instance=d,d.setSelectedLines(this.selectedLines);return}const o=new n.UnresolvedFile(b(this.input.options,()=>this.markVisualReady(t)),this.input.workerManager);o.render({file:this.input.file,containerWrapper:i,lineAnnotations:this.input.annotations}),this.instance=o,o.setSelectedLines(this.selectedLines),this.diff=o.fileDiff}emitRender(){for(const e of this.renderListeners)e()}beginVisualRender(){var i;(i=this.resolveVisualReady)==null||i.call(this,!1);const e=++this.visualRevision;return this.visualReadyPromise=new Promise(t=>{this.resolveVisualReady=t}),e}markVisualReady(e){var i;this.disposed||e!==this.visualRevision||((i=this.resolveVisualReady)==null||i.call(this,!0),this.resolveVisualReady=void 0,this.emitRender())}invalidateVisualReady(){var e;this.visualRevision++,(e=this.resolveVisualReady)==null||e.call(this,!1),this.resolveVisualReady=void 0}};function M(e){return new te(e)}function ne(e){return!e||e.useTokenTransformer===!0||!e.onTokenClick&&!e.onTokenEnter&&!e.onTokenLeave?e:{...e,useTokenTransformer:!0}}function b(e,i){const t=ne(e),n=t==null?void 0:t.onPostRender;return{...t,onPostRender(...o){n==null||n(...o),i()}}}function k(e){return e.kind==="diff"||e.kind==="patch"}var se=class{constructor(e={}){f(this,"options");f(this,"state","idle");f(this,"stats",{characters:0,lines:0,writes:0,resets:0,renderMode:"plain-text",overflowed:!1});f(this,"text",new ie);f(this,"pending",[]);f(this,"scheduled");f(this,"generation",0);f(this,"container");f(this,"shell");f(this,"surface");f(this,"finalizedSurface");f(this,"plainText");f(this,"finalizePromise");f(this,"renderListeners",new Set);f(this,"finalizedRenderSubscription");this.options=e}async mount(e){var n,o,a,r;if(this.state==="disposed")throw new Error("Cannot mount a disposed code stream. Create a new controller instead.");++this.generation,this.cancelScheduledFlush(),(n=this.finalizedSurface)==null||n.dispose(),(o=this.finalizedRenderSubscription)==null||o.dispose(),(a=this.container)==null||a.replaceChildren(),this.finalizedSurface=void 0,this.finalizedRenderSubscription=void 0,this.plainText=void 0,this.pending=[],this.setState("mounting"),this.container=e;const{shell:i,surface:t}=H(e,this.options.maxHeight);this.shell=i,this.surface=t,this.mountPlainText(t),(r=this.stats).startedAt??(r.startedAt=performance.now()),this.setState("streaming")}append(e){if(e){if(this.state==="finalized"||this.state==="finalizing"||this.state==="disposed")throw new Error(`Cannot append while stream is ${this.state}`);this.text.append(e),this.stats.characters=this.text.length,this.stats.lines+=re(e)+(this.stats.lines===0?1:0),this.pending.push(e),this.scheduleFlush()}}updateSnapshot(e){const i=this.text.toString();if(e.startsWith(i)){this.append(e.slice(i.length));return}const t=this.options.nonAppendBehavior??"reset";if(t!=="ignore"){if(t==="throw")throw new Error("Snapshot violates the append-only stream contract");return this.reset(e)}}async consume(e){try{if(Symbol.asyncIterator in e)for await(const i of e)this.append(i);else{const i=e.getReader();try{for(;;){const{done:t,value:n}=await i.read();if(t)break;this.append(n)}}finally{i.releaseLock()}}}catch(i){throw this.fail(i),i}}async flush(){var t;if(this.cancelScheduledFlush(),!this.pending.length)return;const e=this.shouldFollowViewport(),i=this.pending.join("");this.pending.length=0,(t=this.plainText)==null||t.append(i),this.stats.writes++,this.followViewport(e),this.emitRender()}finalize(e={view:"stream"}){if(this.state==="finalized")return Promise.resolve();if(this.finalizePromise)return this.finalizePromise;const i=this.performFinalize(e).finally(()=>{this.finalizePromise===i&&(this.finalizePromise=void 0)});return this.finalizePromise=i,i}async performFinalize(e){if(this.state==="disposed")throw new Error("Cannot finalize a disposed code stream");const i=this.generation;if(this.setState("finalizing"),await this.flush(),i!==this.generation)return;if(this.stats.finalizedAt=performance.now(),!e.view||e.view==="stream"){this.setState("finalized");return}const t=this.surface;if(!t)throw new Error("Mount the stream before finalizing to a file or diff view");const n=this.options.fileName??`code.${this.options.language??"txt"}`,o=L(n,this.getText(),this.options.language);let a;if(e.view==="file"){const{annotations:c,workerManager:y,view:S,...z}=e;a=M({kind:"file",file:o,annotations:c,options:{theme:this.options.theme,themeType:this.options.themeType,...z},workerManager:y??this.options.workerManager})}else{const{annotations:c,original:y,workerManager:S,view:z,...D}=e;a=M({kind:"diff",oldFile:L(n,y,this.options.language),newFile:o,annotations:c,options:{theme:this.options.theme,themeType:this.options.themeType,...D},workerManager:S??this.options.workerManager})}const r=document.createElement("div");if(r.className="stream-diffs-finalized",await a.mount(r),i!==this.generation){a.dispose();return}const d=this.shell,g=(d==null?void 0:d.scrollTop)??0,h=d?d.scrollHeight-d.scrollTop-d.clientHeight:0;t.replaceWith(r),this.surface=r,this.plainText=void 0,this.finalizedSurface=a,this.finalizedRenderSubscription=a.onDidRender(()=>this.emitRender()),d&&(this.options.autoScroll==="always"||this.options.autoScroll!=="never"&&h<=(this.options.autoScrollThresholdPx??32)?d.scrollTop=d.scrollHeight:d.scrollTop=g),this.setState("finalized"),this.emitRender()}async reset(e=""){var t,n;const i=this.container;++this.generation,this.cancelScheduledFlush(),(t=this.finalizedSurface)==null||t.dispose(),(n=this.finalizedRenderSubscription)==null||n.dispose(),this.finalizedSurface=void 0,this.finalizedRenderSubscription=void 0,this.plainText=void 0,this.pending=[],this.finalizePromise=void 0,this.text.clear(),this.stats.resets++,this.stats.characters=0,this.stats.lines=0,this.stats.renderMode="plain-text",this.stats.overflowed=!1,this.setState("idle"),e&&this.append(e),i&&await this.mount(i)}setThemeType(e){var i;this.options.themeType=e,(i=this.finalizedSurface)==null||i.setThemeType(e)}async setTheme(e){this.options.theme=e,this.finalizedSurface&&await this.finalizedSurface.setTheme(e)}async setLanguage(e){if(e===this.options.language||(this.options.language=e,!this.finalizedSurface))return;const i=this.finalizedSurface.getInput();i.kind==="file"?await this.finalizedSurface.updateFile({...i.file,lang:e},i.annotations):i.kind==="diff"&&"oldFile"in i&&await this.finalizedSurface.updateDiff({...i.oldFile,lang:e},{...i.newFile,lang:e},i.annotations)}getText(){return this.text.toString()}getState(){return this.state}getStats(){return{...this.stats}}getElement(){return this.shell}getFinalizedSurface(){return this.finalizedSurface}onDidRender(e){return this.renderListeners.add(e),{dispose:()=>this.renderListeners.delete(e)}}dispose(){var e,i,t;++this.generation,this.cancelScheduledFlush(),(e=this.finalizedSurface)==null||e.dispose(),(i=this.finalizedRenderSubscription)==null||i.dispose(),(t=this.container)==null||t.replaceChildren(),this.plainText=void 0,this.container=void 0,this.surface=void 0,this.shell=void 0,this.finalizedSurface=void 0,this.finalizedRenderSubscription=void 0,this.finalizePromise=void 0,this.renderListeners.clear(),this.setState("disposed")}scheduleFlush(){if(this.scheduled!=null||!this.plainText)return;const e=this.options.flushStrategy??"raf";e==="raf"&&typeof requestAnimationFrame=="function"?this.scheduled=requestAnimationFrame(()=>void this.flush()):this.scheduled=globalThis.setTimeout(()=>void this.flush(),e==="raf"?0:e.intervalMs)}cancelScheduledFlush(){this.scheduled!=null&&(typeof cancelAnimationFrame=="function"&&cancelAnimationFrame(this.scheduled),clearTimeout(this.scheduled),this.scheduled=void 0)}shouldFollowViewport(){const e=this.shell;return!e||this.options.autoScroll==="never"?!1:this.options.autoScroll==="always"?!0:e.scrollHeight-e.scrollTop-e.clientHeight<=(this.options.autoScrollThresholdPx??32)}followViewport(e=this.shouldFollowViewport()){this.shell&&e&&(this.shell.scrollTop=this.shell.scrollHeight)}mountPlainText(e){const i=document.createElement("pre");i.className="stream-diffs-plain-text",i.dataset.streamDiffsState="streaming",i.style.margin="0",i.style.whiteSpace=this.options.wrap?"pre-wrap":"pre",i.style.overflowWrap=this.options.wrap?"anywhere":"normal",i.textContent=this.getText(),e.replaceChildren(i),this.plainText=i}setState(e){var i,t;this.state=e,(t=(i=this.options).onStateChange)==null||t.call(i,e)}emitRender(){for(const e of this.renderListeners)e()}fail(e){var i,t;this.state!=="disposed"&&(this.setState("error"),(t=(i=this.options).onError)==null||t.call(i,e))}};function re(e){let i=0;for(let t=0;t<e.length;t++)e.charCodeAt(t)===10&&i++;return i}var ae=class{constructor(e={}){f(this,"options");f(this,"state","idle");f(this,"generation",0);f(this,"original","");f(this,"modified","");f(this,"container");f(this,"shell");f(this,"surface");f(this,"finalizedSurface");f(this,"finalizePromise");f(this,"renderListeners",new Set);f(this,"finalizedRenderSubscription");this.options=e}async mount(e,i=this.original,t=this.modified){var a,r,d;if(this.state==="disposed")throw new Error("Cannot mount a disposed diff stream. Create a new controller instead.");++this.generation,this.original=i,this.modified=t,(a=this.finalizedSurface)==null||a.dispose(),(r=this.finalizedRenderSubscription)==null||r.dispose(),(d=this.container)==null||d.replaceChildren(),this.finalizedSurface=void 0,this.finalizedRenderSubscription=void 0,this.setState("mounting"),this.container=e;const{shell:n,surface:o}=H(e,this.options.maxHeight);this.shell=n,this.surface=o,this.renderPre(),this.setState("streaming")}update(e,i){if(this.state==="disposed")throw new Error("Cannot update a disposed diff stream");return this.original=e,this.modified=i,this.finalizedSurface?this.finalizedSurface.updateDiff(this.asFile(e),this.asFile(i)):(this.renderPre(),this.emitRender(),Promise.resolve())}finalize(e){if(this.state==="finalized")return Promise.resolve(this.finalizedSurface);if(this.finalizePromise)return this.finalizePromise;const i=this.performFinalize(e).finally(()=>{this.finalizePromise===i&&(this.finalizePromise=void 0)});return this.finalizePromise=i,i}async performFinalize(e){if(this.state==="disposed")throw new Error("Cannot finalize a disposed diff stream");const i=this.surface;if(!i)throw new Error("Mount the diff stream before finalizing it");const t=this.generation;this.setState("finalizing");const n=M({kind:"diff",oldFile:this.asFile(this.original),newFile:this.asFile(this.modified),annotations:e,options:{...this.options,diffStyle:this.options.diffStyle??"unified"},workerManager:this.options.workerManager}),o=document.createElement("div");if(o.className="stream-diffs-finalized",await n.mount(o),t!==this.generation){n.dispose();return}const a=this.shell,r=(a==null?void 0:a.scrollTop)??0;return i.replaceWith(o),this.surface=o,this.finalizedSurface=n,this.finalizedRenderSubscription=n.onDidRender(()=>this.emitRender()),a&&(a.scrollTop=r),this.setState("finalized"),this.emitRender(),n}setThemeType(e){var i;this.options.themeType=e,(i=this.finalizedSurface)==null||i.setThemeType(e)}async setTheme(e){this.options.theme=e,this.finalizedSurface&&await this.finalizedSurface.setTheme(e)}async setLanguage(e){if(e!==this.options.language){if(this.options.language=e,this.finalizedSurface){const i=this.finalizedSurface.getInput();i.kind==="diff"&&"oldFile"in i&&await this.finalizedSurface.updateDiff({...i.oldFile,lang:e},{...i.newFile,lang:e},i.annotations);return}this.renderPre()}}getOriginal(){return this.original}getModified(){return this.modified}getState(){return this.state}getElement(){return this.shell}getFinalizedSurface(){return this.finalizedSurface}onDidRender(e){return this.renderListeners.add(e),{dispose:()=>this.renderListeners.delete(e)}}dispose(){var e,i,t;++this.generation,(e=this.finalizedSurface)==null||e.dispose(),(i=this.finalizedRenderSubscription)==null||i.dispose(),(t=this.container)==null||t.replaceChildren(),this.container=void 0,this.shell=void 0,this.surface=void 0,this.finalizedSurface=void 0,this.finalizedRenderSubscription=void 0,this.finalizePromise=void 0,this.renderListeners.clear(),this.setState("disposed")}renderPre(){const e=this.surface;if(!e||this.finalizedSurface)return;const i=document.createElement("div");i.className=`stream-diffs-diff-pre stream-diffs-diff-pre--${this.options.diffStyle??"unified"}`,i.dataset.streamDiffsState="streaming",i.style.minWidth="max-content",(this.options.diffStyle??"unified")==="split"?(i.style.display="grid",i.style.gridTemplateColumns="minmax(0, 1fr) minmax(0, 1fr)",i.append(this.createPre(this.original,"deletions"),this.createPre(this.modified,"additions"))):i.append(this.createPre(oe(this.original,this.modified),"unified")),e.replaceChildren(i)}createPre(e,i){const t=document.createElement("pre");return t.className=`stream-diffs-diff-pre__pane stream-diffs-diff-pre__pane--${i}`,t.dataset.side=i,t.style.margin="0",t.style.whiteSpace=this.options.wrap?"pre-wrap":"pre",t.style.overflowWrap=this.options.wrap?"anywhere":"normal",t.textContent=e,t}asFile(e){return L(this.options.fileName??`code.${this.options.language??"txt"}`,e,this.options.language)}setState(e){var i,t;this.state=e,(t=(i=this.options).onStateChange)==null||t.call(i,e)}emitRender(){for(const e of this.renderListeners)e()}};function oe(e,i){const t=e.split(`
3
3
  `),n=i.split(`
4
4
  `);let o=0;for(;o<t.length&&o<n.length&&t[o]===n[o];)o++;let a=0;for(;a<t.length-o&&a<n.length-o&&t[t.length-a-1]===n[n.length-a-1];)a++;return[...t.slice(0,o).map(r=>` ${r}`),...t.slice(o,t.length-a).map(r=>`- ${r}`),...n.slice(o,n.length-a).map(r=>`+ ${r}`),...t.slice(t.length-a).map(r=>` ${r}`)].join(`
5
5
  `)}function we(e={}){let i,t,n,o,a,r="text",d="",g="",h,c=0,y="system",S=K(e),z=G(e);const D={disableLineNumbers:e.lineNumbers===!1,overflow:e.wordWrap==="on"?"wrap":"scroll",enableLineSelection:e.enableLineSelection},P=()=>({...D,theme:S,themeType:y});async function I(s,l,p){var m;F();const v=c;if($(s,e),h=s,r=x(p),W(l))return _(s,l,r);if(e.stream===!1)return O(s,l,r);const u=new se({...P(),...R(e),fileName:`code.${r}`,language:r,maxHeight:e.MAX_HEIGHT,autoScroll:e.autoScrollOnUpdate===!1?"never":"near-bottom",autoScrollThresholdPx:e.autoScrollThresholdPx,workerManager:e.workerManager});if(i=u,u.append(l),await u.mount(s),v!==c||i!==u||h!==s)throw u.dispose(),new Error("Editor creation was cancelled");return(m=e.onController)==null||m.call(e,u),o=C(()=>u.getText(),s,()=>u.getFinalizedSurface(),w=>u.onDidRender(w)),o}async function V(s,l,p,v){var q,B;F();const u=c;$(s,e),h=s,r=x(v),d=l,g=p;let m,w;if(e.stream===!1){if(m=M({kind:"diff",oldFile:T(l),newFile:T(p),annotations:e.lineAnnotations,workerManager:e.workerManager,options:{...P(),diffStyle:e.diffStyle??(e.renderSideBySide===!1?"unified":"split"),...R(e)}}),n=m,await m.mount(s),u!==c||n!==m||h!==s)throw m.dispose(),new Error("Editor creation was cancelled");(q=e.onController)==null||q.call(e,m)}else{if(w=new ae({...P(),...R(e),fileName:`code.${r}`,language:r,diffStyle:e.diffStyle??(e.renderSideBySide===!1?"unified":"split"),maxHeight:e.MAX_HEIGHT,wrap:e.wordWrap==="on",workerManager:e.workerManager}),t=w,await w.mount(s,l,p),u!==c||t!==w||h!==s)throw w.dispose(),new Error("Editor creation was cancelled");(B=e.onController)==null||B.call(e,w)}return a=ue(()=>d,()=>g,s,()=>m??(w==null?void 0:w.getFinalizedSurface())),a}async function J(s,l=r){const p=x(l);if(W(s)){(n==null?void 0:n.getInput().kind)==="merge-conflict"?(r=p,await n.updateMergeConflict(T(s),e.lineAnnotations)):h&&await _(h,s,p);return}if(e.stream===!1){(n==null?void 0:n.getInput().kind)==="file"?(r=p,await n.updateFile(T(s),e.lineAnnotations)):h&&await O(h,s,p);return}if(!i){h&&await I(h,s,p);return}if(i.getState()==="finalized"){s!==i.getText()&&await i.reset(s);return}if(p!==r){r=p,await i.setLanguage(p),s!==i.getText()&&await i.reset(s);return}const v=i.getText();s.startsWith(v)?i.append(s.slice(v.length)):await i.reset(s)}async function E(s,l,p=r){if(d=s,g=l,r=x(p),t){await t.update(s,l);return}if(!n){h&&await V(h,s,l,p);return}await n.updateDiff(T(s),T(l))}function F(){c++,i==null||i.dispose(),t==null||t.dispose(),t||n==null||n.dispose(),i=void 0,t=void 0,n=void 0,o=void 0,a=void 0,h=void 0}async function O(s,l,p){var m;F();const v=c;h=s,r=p;const u=M({kind:"file",file:T(l),annotations:e.lineAnnotations,workerManager:e.workerManager,options:{...P(),...R(e)}});if(n=u,await u.mount(s),v!==c||n!==u||h!==s)throw u.dispose(),new Error("Editor creation was cancelled");return(m=e.onController)==null||m.call(e,u),o=C(()=>X(u)??l,s,()=>u,w=>u.onDidRender(w)),o}async function _(s,l,p){var m;F();const v=c;h=s,r=p;const u=M({kind:"merge-conflict",file:T(l),annotations:e.lineAnnotations,workerManager:e.workerManager,options:{...P(),...R(e)}});if(n=u,await u.mount(s),v!==c||n!==u||h!==s)throw u.dispose(),new Error("Editor creation was cancelled");return(m=e.onController)==null||m.call(e,u),o=C(()=>X(u)??l,s,()=>u,w=>u.onDidRender(w)),o}function W(s){return e.mergeConflict===!1?!1:/^<<<<<<< .+$/m.test(s)&&/^=======$/m.test(s)&&/^>>>>>>> .+$/m.test(s)}async function Q(s){if(s){if(typeof s=="string"){const l=e.themes;if((l==null?void 0:l[0])===s){await j(),y="dark",i==null||i.setThemeType("dark"),t==null||t.setThemeType("dark"),n==null||n.setThemeType("dark");return}if((l==null?void 0:l[1])===s){await j(),y="light",i==null||i.setThemeType("light"),t==null||t.setThemeType("light"),n==null||n.setThemeType("light");return}}z=void 0,S=s,await U(s)}}async function j(){const s=G(e);!s||s===z||(z=s,S=K(e),await U(S))}async function U(s){await(i==null?void 0:i.setTheme(s)),await(t==null?void 0:t.setTheme(s)),await(n==null?void 0:n.setTheme(s))}function T(s){return L(`code.${r||"txt"}`,s,r)}return{runtimeKind:"stream-diffs",createEditor:I,createDiffEditor:V,updateCode:J,appendCode(s){i==null||i.append(s)},async finalizeCode(){if(!i||i.getState()==="finalized")return i==null?void 0:i.getFinalizedSurface();const s=R(e);return delete s.lineAnnotations,await i.finalize({view:"file",...s,theme:S,themeType:y,annotations:e.lineAnnotations,workerManager:e.workerManager}),i.getFinalizedSurface()},async finalizeDiff(){return t&&(n=await t.finalize(e.lineAnnotations)),n},updateDiff:E,updateOriginal(s,l=r){return E(s,g,l)},updateModified(s,l=r){return E(d,s,l)},appendOriginal(s,l=r){return E(d+s,g,l)},appendModified(s,l=r){return E(d,g+s,l)},cleanupEditor:F,safeClean:F,setTheme:Q,async setLanguage(s){if(r=x(s),await(i==null?void 0:i.setLanguage(r)),await(t==null?void 0:t.setLanguage(r)),n&&!t){const l=n.getInput();l.kind==="file"||l.kind==="merge-conflict"?await n.update({...l,file:{...l.file,lang:r}}):l.kind==="diff"&&"oldFile"in l&&await n.update({...l,oldFile:{...l.oldFile,lang:r},newFile:{...l.newFile,lang:r}})}},getCurrentTheme:()=>S,getEditor:()=>ce,getEditorView:()=>o??null,getDiffEditorView:()=>a??null,getDiffModels:()=>({original:A(()=>d),modified:A(()=>{var s;return((s=n==null?void 0:n.getResolvedFile())==null?void 0:s.contents)??(t==null?void 0:t.getModified())??g})}),getCode:()=>{var l;const s=n==null?void 0:n.getInput();return(s==null?void 0:s.kind)==="diff"||(s==null?void 0:s.kind)==="patch"?{original:d,modified:((l=n==null?void 0:n.getResolvedFile())==null?void 0:l.contents)??g}:(s==null?void 0:s.kind)==="file"||(s==null?void 0:s.kind)==="merge-conflict"?s.file.contents:t?{original:t.getOriginal(),modified:t.getModified()}:(i==null?void 0:i.getText())??null},refreshDiffPresentation:()=>n==null?void 0:n.update(n.getInput()),whenVisualReady:async()=>{const s=h,l=c,p=n??(i==null?void 0:i.getFinalizedSurface())??(t==null?void 0:t.getFinalizedSurface());return!p||!await p.whenVisualReady()?!1:le(s,()=>l===c&&s===h&&p===(n??(i==null?void 0:i.getFinalizedSurface())??(t==null?void 0:t.getFinalizedSurface())),()=>de(n??(i==null?void 0:i.getFinalizedSurface())??(t==null?void 0:t.getFinalizedSurface())))}}}async function le(e,i,t){var r,d;if(!e||typeof window>"u")return!1;let n="",o,a=0;for(let g=0;g<120;g+=1){if(!i())return!1;const h=e.querySelector(".stream-diffs-shell"),c=(d=(r=h==null?void 0:h.querySelector("diffs-container"))==null?void 0:r.shadowRoot)==null?void 0:d.querySelector("pre"),y=h==null?void 0:h.getBoundingClientRect(),S=(c==null?void 0:c.textContent)??"";if(y&&y.width>0&&y.height>0&&c&&t()){const z=`${Math.round(y.width)}:${Math.round(y.height)}:${c.scrollWidth}:${c.scrollHeight}:${S.length}`;if(a=c===o&&z===n?a+1:1,o=c,n=z,a>=2)return!0}else n="",o=void 0,a=0;await he()}return!1}function de(e){var d,g;if(!e)return!0;const i=e.getNativeInstance(),t=(i==null?void 0:i.fileRenderer)??(i==null?void 0:i.hunksRenderer);if(!t)return!0;const n=t.renderCache;if(!(n!=null&&n.result))return!1;if(n.highlighted===!0)return!0;const o=e.getInput();if(x(o.kind==="file"||o.kind==="merge-conflict"?o.file.lang:"oldFile"in o?o.oldFile.lang??o.newFile.lang:(d=e.getDiff())==null?void 0:d.lang)==="text")return!0;const a=Number(((g=t.getTokenizeMaxLength)==null?void 0:g.call(t))??1e5);if(o.kind==="file"||o.kind==="merge-conflict")return fe(o.file.contents)>a;const r=e.getDiff();return!!r&&Math.max(r.additionLines.length,r.deletionLines.length)>a}function x(e){return!e||/^(?:text|txt|plain|plaintext)$/i.test(e)?"text":e}function fe(e){if(!e)return 0;let i=1;for(let t=0;t<e.length;t+=1)e.charCodeAt(t)===10&&(i+=1);return i}function he(){return new Promise(e=>{let i=!1;const t=()=>{i||(i=!0,window.clearTimeout(o),window.cancelAnimationFrame(n),e())},n=window.requestAnimationFrame(t),o=window.setTimeout(t,50)})}function K(e){var i;return(i=e.themes)!=null&&i.length&&typeof e.themes[0]=="string"&&typeof e.themes[1]=="string"?{dark:e.themes[0],light:e.themes[1]}:e.theme??void 0}function G(e){var i,t;if(!(typeof((i=e.themes)==null?void 0:i[0])!="string"||typeof((t=e.themes)==null?void 0:t[1])!="string"))return`${e.themes[0]}