solve-engine 2.5.0 → 2.7.0
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.
- package/dist/{BytecodeBuilder-DGGeByAP.d.cts → BytecodeBuilder-BGq9ZiO3.d.cts} +2 -1
- package/dist/{BytecodeBuilder-DGGeByAP.d.ts → BytecodeBuilder-BGq9ZiO3.d.ts} +2 -1
- package/dist/{PackageCompatibility-cEClSSkz.d.cts → PackageCompatibility-BG0iur4I.d.cts} +1 -1
- package/dist/{PackageCompatibility-UsSZIfHs.d.ts → PackageCompatibility-BlIcQg5v.d.ts} +1 -1
- package/dist/{PackageRegistry-B3yJHSxX.d.ts → PackageRegistry-BJ0QQd3k.d.ts} +5 -5
- package/dist/{PackageRegistry-BsLmAVZJ.d.cts → PackageRegistry-DeGDZkNt.d.cts} +5 -5
- package/dist/{Parselet-C4Wu055_.d.cts → Parselet-BSndkWEY.d.cts} +2 -2
- package/dist/{Parselet-B-zoPrTa.d.ts → Parselet-Blq8B0Gj.d.ts} +2 -2
- package/dist/{ScopeManager-DkpnlKuz.d.ts → ScopeManager-CF3cZUqW.d.ts} +3 -3
- package/dist/{ScopeManager-t6SnP6Ce.d.cts → ScopeManager-D8nLv--u.d.cts} +3 -3
- package/dist/{VMCheckpoints-CsHmQVaD.d.ts → VMCheckpoints-BsR5_auF.d.ts} +3 -3
- package/dist/{VMCheckpoints-C_jQvABf.d.cts → VMCheckpoints-Dy39SVHa.d.cts} +3 -3
- package/dist/{Value-CCi_Eecs.d.cts → Value-DCTqTSeP.d.cts} +57 -5
- package/dist/{Value-CCi_Eecs.d.ts → Value-DCTqTSeP.d.ts} +57 -5
- package/dist/chunk-5AMJNF7J.js +3 -0
- package/dist/chunk-5AMJNF7J.js.map +1 -0
- package/dist/chunk-5TCSFTZD.js +2 -0
- package/dist/chunk-5TCSFTZD.js.map +1 -0
- package/dist/chunk-5TVI2UPZ.cjs +2 -0
- package/dist/chunk-5TVI2UPZ.cjs.map +1 -0
- package/dist/{chunk-N7N7MPMK.cjs → chunk-75XDS65A.cjs} +2 -2
- package/dist/{chunk-N7N7MPMK.cjs.map → chunk-75XDS65A.cjs.map} +1 -1
- package/dist/chunk-A33K7NY4.js +2 -0
- package/dist/chunk-A33K7NY4.js.map +1 -0
- package/dist/chunk-AQWNEO7M.cjs +2 -0
- package/dist/{chunk-YFWAR766.cjs.map → chunk-AQWNEO7M.cjs.map} +1 -1
- package/dist/{chunk-YUJNMUKM.cjs → chunk-B7J24Q5T.cjs} +2 -2
- package/dist/{chunk-YUJNMUKM.cjs.map → chunk-B7J24Q5T.cjs.map} +1 -1
- package/dist/{chunk-7RTKJMYS.js → chunk-CVY2A3TP.js} +2 -2
- package/dist/{chunk-7RTKJMYS.js.map → chunk-CVY2A3TP.js.map} +1 -1
- package/dist/{chunk-FDE5HWDI.cjs → chunk-FNNIAJNY.cjs} +2 -2
- package/dist/{chunk-FDE5HWDI.cjs.map → chunk-FNNIAJNY.cjs.map} +1 -1
- package/dist/chunk-FUDVKPB7.cjs +2 -0
- package/dist/chunk-FUDVKPB7.cjs.map +1 -0
- package/dist/chunk-GYX6S6OS.cjs +3 -0
- package/dist/chunk-GYX6S6OS.cjs.map +1 -0
- package/dist/chunk-HAEOMJE3.cjs +2 -0
- package/dist/chunk-HAEOMJE3.cjs.map +1 -0
- package/dist/{chunk-LOM3H5ZD.js → chunk-HF4H7LYA.js} +4 -4
- package/dist/{chunk-LOM3H5ZD.js.map → chunk-HF4H7LYA.js.map} +1 -1
- package/dist/chunk-HTJPV42D.js +2 -0
- package/dist/{chunk-LBNX7TXI.js.map → chunk-HTJPV42D.js.map} +1 -1
- package/dist/chunk-IHZBKT7L.cjs +3 -0
- package/dist/chunk-IHZBKT7L.cjs.map +1 -0
- package/dist/chunk-JEFMG6CV.js +2 -0
- package/dist/chunk-JEFMG6CV.js.map +1 -0
- package/dist/{chunk-XNIWQHXY.js → chunk-JQBG3LX4.js} +2 -2
- package/dist/{chunk-XNIWQHXY.js.map → chunk-JQBG3LX4.js.map} +1 -1
- package/dist/{chunk-TWC7K3ZX.js → chunk-KHCNMNZZ.js} +2 -2
- package/dist/{chunk-TWC7K3ZX.js.map → chunk-KHCNMNZZ.js.map} +1 -1
- package/dist/{chunk-RDMJNRDO.js → chunk-KXM7EY27.js} +3 -3
- package/dist/{chunk-RDMJNRDO.js.map → chunk-KXM7EY27.js.map} +1 -1
- package/dist/{chunk-AXMQG5TS.cjs → chunk-MVP2YD4X.cjs} +2 -2
- package/dist/{chunk-AXMQG5TS.cjs.map → chunk-MVP2YD4X.cjs.map} +1 -1
- package/dist/chunk-N4HJTHZR.js +2 -0
- package/dist/chunk-N4HJTHZR.js.map +1 -0
- package/dist/chunk-P5EMTVMJ.js +3 -0
- package/dist/chunk-P5EMTVMJ.js.map +1 -0
- package/dist/chunk-PNDQRCRQ.cjs +2 -0
- package/dist/chunk-PNDQRCRQ.cjs.map +1 -0
- package/dist/{chunk-JFAJN3C2.cjs → chunk-VBSMA7WJ.cjs} +2 -2
- package/dist/chunk-VBSMA7WJ.cjs.map +1 -0
- package/dist/{chunk-NGJMCVH4.cjs → chunk-W7VOTR2J.cjs} +3 -3
- package/dist/{chunk-NGJMCVH4.cjs.map → chunk-W7VOTR2J.cjs.map} +1 -1
- package/dist/{chunk-RSF25YSJ.js → chunk-WTEXBPBR.js} +2 -2
- package/dist/{chunk-RSF25YSJ.js.map → chunk-WTEXBPBR.js.map} +1 -1
- package/dist/{chunk-E6Z4NQAS.js → chunk-YNMMRH44.js} +2 -2
- package/dist/chunk-YNMMRH44.js.map +1 -0
- package/dist/{chunk-D5MTMRHS.cjs → chunk-ZRFUD2LX.cjs} +4 -4
- package/dist/{chunk-D5MTMRHS.cjs.map → chunk-ZRFUD2LX.cjs.map} +1 -1
- package/dist/constants.cjs +1 -1
- package/dist/constants.js +1 -1
- package/dist/engine.cjs +1 -1
- package/dist/engine.d.cts +8 -8
- package/dist/engine.d.ts +8 -8
- package/dist/engine.js +1 -1
- package/dist/format.cjs +1 -1
- package/dist/format.d.cts +1 -1
- package/dist/format.d.ts +1 -1
- package/dist/format.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +8 -8
- package/dist/index.d.ts +8 -8
- package/dist/index.js +1 -1
- package/dist/language.d.cts +7 -7
- package/dist/language.d.ts +7 -7
- package/dist/packages.cjs +1 -1
- package/dist/packages.d.cts +7 -7
- package/dist/packages.d.ts +7 -7
- package/dist/packages.js +1 -1
- package/dist/parser.cjs +1 -1
- package/dist/parser.d.cts +4 -4
- package/dist/parser.d.ts +4 -4
- package/dist/parser.js +1 -1
- package/dist/{pipeline-DCQicwWX.d.cts → pipeline-BM8xc0CZ.d.cts} +3 -3
- package/dist/{pipeline-72QmQlGx.d.ts → pipeline-J2ehIm7t.d.ts} +3 -3
- package/dist/resolvers.d.cts +2 -2
- package/dist/resolvers.d.ts +2 -2
- package/dist/testing.cjs +2 -2
- package/dist/testing.d.cts +7 -7
- package/dist/testing.d.ts +7 -7
- package/dist/testing.js +1 -1
- package/dist/uom.cjs +1 -1
- package/dist/uom.d.cts +2 -2
- package/dist/uom.d.ts +2 -2
- package/dist/uom.js +1 -1
- package/dist/vm.cjs +1 -1
- package/dist/vm.d.cts +7 -7
- package/dist/vm.d.ts +7 -7
- package/dist/vm.js +1 -1
- package/dist/worker.cjs +2 -2
- package/dist/worker.cjs.map +1 -1
- package/dist/worker.d.cts +32 -6
- package/dist/worker.d.ts +32 -6
- package/dist/worker.js +2 -2
- package/dist/worker.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-2HQWM5OB.js +0 -3
- package/dist/chunk-2HQWM5OB.js.map +0 -1
- package/dist/chunk-6G3PMEPA.js +0 -2
- package/dist/chunk-6G3PMEPA.js.map +0 -1
- package/dist/chunk-6INX773F.cjs +0 -2
- package/dist/chunk-6INX773F.cjs.map +0 -1
- package/dist/chunk-6ZNNPXXE.cjs +0 -3
- package/dist/chunk-6ZNNPXXE.cjs.map +0 -1
- package/dist/chunk-ANJPS6FF.cjs +0 -2
- package/dist/chunk-ANJPS6FF.cjs.map +0 -1
- package/dist/chunk-B5NBFGNP.js +0 -3
- package/dist/chunk-B5NBFGNP.js.map +0 -1
- package/dist/chunk-CT5TC3JX.cjs +0 -3
- package/dist/chunk-CT5TC3JX.cjs.map +0 -1
- package/dist/chunk-E6Z4NQAS.js.map +0 -1
- package/dist/chunk-ESUN2THE.cjs +0 -2
- package/dist/chunk-ESUN2THE.cjs.map +0 -1
- package/dist/chunk-EVAOPEO4.js +0 -2
- package/dist/chunk-EVAOPEO4.js.map +0 -1
- package/dist/chunk-JFAJN3C2.cjs.map +0 -1
- package/dist/chunk-LBNX7TXI.js +0 -2
- package/dist/chunk-PS272DZJ.cjs +0 -2
- package/dist/chunk-PS272DZJ.cjs.map +0 -1
- package/dist/chunk-QEYTENAK.js +0 -2
- package/dist/chunk-QEYTENAK.js.map +0 -1
- package/dist/chunk-R2ENWQ76.js +0 -2
- package/dist/chunk-R2ENWQ76.js.map +0 -1
- package/dist/chunk-YFWAR766.cjs +0 -2
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var a=class{constructor(){this.collectors=[];}register(t){this.collectors.push(t);}unregister(t){let e=this.collectors.indexOf(t);e!==-1&&this.collectors.splice(e,1);}clear(){this.collectors=[];}get hasCollectors(){return this.collectors.length>0}get collectorCount(){return this.collectors.length}firePipelineStart(t){if(this.collectors.length!==0)for(let e of this.collectors)e.onPipelineStart?.(t);}fireTokenEmitted(t){if(this.collectors.length!==0)for(let e of this.collectors)e.onTokenEmitted?.(t);}fireNormalizerStart(t){if(this.collectors.length!==0)for(let e of this.collectors)e.onNormalizerStart?.(t);}fireTokenFused(t){if(this.collectors.length!==0)for(let e of this.collectors)e.onTokenFused?.(t);}fireNormalizerEnd(t){if(this.collectors.length!==0)for(let e of this.collectors)e.onNormalizerEnd?.(t);}fireParseletMatched(t){if(this.collectors.length!==0)for(let e of this.collectors)e.onParseletMatched?.(t);}fireBytecodeBuilt(t){if(this.collectors.length!==0)for(let e of this.collectors)e.onBytecodeBuilt?.(t);}fireVmStep(t){if(this.collectors.length!==0)for(let e of this.collectors)e.onVmStep?.(t);}fireVmHalt(t){if(this.collectors.length!==0)for(let e of this.collectors)e.onVmHalt?.(t);}fireCacheHit(t){if(this.collectors.length!==0)for(let e of this.collectors)e.onCacheHit?.(t);}fireCacheMiss(t){if(this.collectors.length!==0)for(let e of this.collectors)e.onCacheMiss?.(t);}firePipelineEnd(t){if(this.collectors.length!==0)for(let e of this.collectors)e.onPipelineEnd?.(t);}collectReports(){let t=[];for(let e of this.collectors){let n=e.getReport();n&&t.push(n);}return t}reset(){for(let t of this.collectors)t.reset();}};var s=class{onPipelineStart(t){}onTokenEmitted(t){}onNormalizerStart(t){}onTokenFused(t){}onNormalizerEnd(t){}onParseletMatched(t){}onBytecodeBuilt(t){}onVmStep(t){}onVmHalt(t){}onCacheHit(t){}onCacheMiss(t){}onPipelineEnd(t){}};var i=class extends s{constructor(){super(...arguments);this.events=[];this.startNs=0;this.parseletEntries=new Map;this.totalTokens=0;this.cacheHitSeen=false;this.vmStepSeen=false;this.hasBytecodeBuilt=false;this.firstBytecodeOpcodesLength=0;this.parseletMatches=[];this.lastExpression="";this.lastInputType="";}get parseletMatchCount(){return this.parseletMatches.length}reset(){this.events=[],this.parseletEntries.clear(),this.startNs=0,this.totalTokens=0,this.cacheHitSeen=false,this.vmStepSeen=false,this.hasBytecodeBuilt=false,this.firstBytecodeOpcodesLength=0,this.parseletMatches=[],this.lastExpression="",this.lastInputType="";}stamp(e){let n=this.startNs!==0?performance.now()*1e6-this.startNs:0;return {...e,elapsedNs:n}}onPipelineStart(e){this.startNs===0&&(this.startNs=performance.now()*1e6),this.lastExpression=e.expression,this.lastInputType=e.inputType,this.events.push(this.stamp(e));}onTokenEmitted(e){this.events.push(this.stamp(e)),this.totalTokens++;}onNormalizerStart(e){this.events.push(this.stamp(e));}onTokenFused(e){this.events.push(this.stamp(e));}onNormalizerEnd(e){this.events.push(this.stamp(e));}onParseletMatched(e){this.events.push(this.stamp(e));let n=this.parseletEntries.get(e.parseletCategory);n?n.count++:this.parseletEntries.set(e.parseletCategory,{category:e.parseletCategory,count:1}),this.parseletMatches.push({tokenType:e.tokenType,tokenValue:e.tokenValue,parseletCategory:e.parseletCategory,parseletType:e.parseletType,isPrefix:e.isPrefix,bindingPower:e.bindingPower,tokenOffset:e.tokenOffset});}onBytecodeBuilt(e){this.events.push(this.stamp(e)),this.hasBytecodeBuilt||(this.hasBytecodeBuilt=true,this.firstBytecodeOpcodesLength=e.opcodesLength);}onVmStep(e){this.events.push(this.stamp(e)),this.vmStepSeen=true;}onVmHalt(e){this.events.push(this.stamp(e));}onCacheHit(e){this.events.push(this.stamp(e)),this.cacheHitSeen=true;}onCacheMiss(e){this.events.push(this.stamp(e));}onPipelineEnd(e){this.events.push(this.stamp(e));}getReport(){if(this.events.length===0)return;let e=performance.now()*1e6-this.startNs,n=new Map;for(let[,r]of this.parseletEntries)n.set(r.category,r.count);let c=this.firstBytecodeOpcodesLength,p=this.cacheHitSeen,d=this.totalTokens,o={events:this.events,parselets:this.parseletMatches.map(r=>({...r})),summary:{totalTokens:d,totalParselets:n.size,totalOpcodes:c,cacheHit:p,elapsedNs:e,parseCategories:n},metadata:{expression:this.lastExpression,inputType:this.lastInputType,timestamp:Date.now(),vmTraceEnabled:this.vmStepSeen},toJSON(){return {events:o.events,parselets:o.parselets,summary:{totalTokens:o.summary.totalTokens,totalParselets:o.summary.totalParselets,totalOpcodes:o.summary.totalOpcodes,cacheHit:o.summary.cacheHit,elapsedNs:o.summary.elapsedNs,parseCategories:Object.fromEntries(o.summary.parseCategories)},metadata:{...o.metadata}}}};return o}};var y={TokenEmitted:"token_emitted",NormalizerStart:"normalizer_start",TokenFused:"token_fused",NormalizerEnd:"normalizer_end",ParseletMatched:"parselet_matched",BytecodeBuilt:"bytecode_built",VmStep:"vm_step",VmHalt:"vm_halt",CacheHit:"cache_hit",CacheMiss:"cache_miss",PipelineStart:"pipeline_start",PipelineEnd:"pipeline_end"};export{a,i as b,y as c};//# sourceMappingURL=chunk-
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
var a=class{constructor(){this.collectors=[];}register(t){this.collectors.push(t);}unregister(t){let e=this.collectors.indexOf(t);e!==-1&&this.collectors.splice(e,1);}clear(){this.collectors=[];}get hasCollectors(){return this.collectors.length>0}get collectorCount(){return this.collectors.length}firePipelineStart(t){if(this.collectors.length!==0)for(let e of this.collectors)e.onPipelineStart?.(t);}fireTokenEmitted(t){if(this.collectors.length!==0)for(let e of this.collectors)e.onTokenEmitted?.(t);}fireNormalizerStart(t){if(this.collectors.length!==0)for(let e of this.collectors)e.onNormalizerStart?.(t);}fireTokenFused(t){if(this.collectors.length!==0)for(let e of this.collectors)e.onTokenFused?.(t);}fireNormalizerEnd(t){if(this.collectors.length!==0)for(let e of this.collectors)e.onNormalizerEnd?.(t);}fireParseletMatched(t){if(this.collectors.length!==0)for(let e of this.collectors)e.onParseletMatched?.(t);}fireBytecodeBuilt(t){if(this.collectors.length!==0)for(let e of this.collectors)e.onBytecodeBuilt?.(t);}fireVmStep(t){if(this.collectors.length!==0)for(let e of this.collectors)e.onVmStep?.(t);}fireVmHalt(t){if(this.collectors.length!==0)for(let e of this.collectors)e.onVmHalt?.(t);}fireCacheHit(t){if(this.collectors.length!==0)for(let e of this.collectors)e.onCacheHit?.(t);}fireCacheMiss(t){if(this.collectors.length!==0)for(let e of this.collectors)e.onCacheMiss?.(t);}firePipelineEnd(t){if(this.collectors.length!==0)for(let e of this.collectors)e.onPipelineEnd?.(t);}collectReports(){let t=[];for(let e of this.collectors){let n=e.getReport();n&&t.push(n);}return t}reset(){for(let t of this.collectors)t.reset();}};var s=class{onPipelineStart(t){}onTokenEmitted(t){}onNormalizerStart(t){}onTokenFused(t){}onNormalizerEnd(t){}onParseletMatched(t){}onBytecodeBuilt(t){}onVmStep(t){}onVmHalt(t){}onCacheHit(t){}onCacheMiss(t){}onPipelineEnd(t){}};var i=class extends s{constructor(){super(...arguments);this.events=[];this.startNs=0;this.parseletEntries=new Map;this.totalTokens=0;this.cacheHitSeen=false;this.vmStepSeen=false;this.hasBytecodeBuilt=false;this.firstBytecodeOpcodesLength=0;this.parseletMatches=[];this.lastExpression="";this.lastInputType="";}get parseletMatchCount(){return this.parseletMatches.length}reset(){this.events=[],this.parseletEntries.clear(),this.startNs=0,this.totalTokens=0,this.cacheHitSeen=false,this.vmStepSeen=false,this.hasBytecodeBuilt=false,this.firstBytecodeOpcodesLength=0,this.parseletMatches=[],this.lastExpression="",this.lastInputType="";}stamp(e){let n=this.startNs!==0?performance.now()*1e6-this.startNs:0;return {...e,elapsedNs:n}}onPipelineStart(e){this.startNs===0&&(this.startNs=performance.now()*1e6),this.lastExpression=e.expression,this.lastInputType=e.inputType,this.events.push(this.stamp(e));}onTokenEmitted(e){this.events.push(this.stamp(e)),this.totalTokens++;}onNormalizerStart(e){this.events.push(this.stamp(e));}onTokenFused(e){this.events.push(this.stamp(e));}onNormalizerEnd(e){this.events.push(this.stamp(e));}onParseletMatched(e){this.events.push(this.stamp(e));let n=this.parseletEntries.get(e.parseletCategory);n?n.count++:this.parseletEntries.set(e.parseletCategory,{category:e.parseletCategory,count:1}),this.parseletMatches.push({tokenType:e.tokenType,tokenValue:e.tokenValue,parseletCategory:e.parseletCategory,parseletType:e.parseletType,isPrefix:e.isPrefix,bindingPower:e.bindingPower,tokenOffset:e.tokenOffset});}onBytecodeBuilt(e){this.events.push(this.stamp(e)),this.hasBytecodeBuilt||(this.hasBytecodeBuilt=true,this.firstBytecodeOpcodesLength=e.opcodesLength);}onVmStep(e){this.events.push(this.stamp(e)),this.vmStepSeen=true;}onVmHalt(e){this.events.push(this.stamp(e));}onCacheHit(e){this.events.push(this.stamp(e)),this.cacheHitSeen=true;}onCacheMiss(e){this.events.push(this.stamp(e));}onPipelineEnd(e){this.events.push(this.stamp(e));}getReport(){if(this.events.length===0)return;let e=performance.now()*1e6-this.startNs,n=new Map;for(let[,r]of this.parseletEntries)n.set(r.category,r.count);let c=this.firstBytecodeOpcodesLength,p=this.cacheHitSeen,d=this.totalTokens,o={events:this.events,parselets:this.parseletMatches.map(r=>({...r})),summary:{totalTokens:d,totalParselets:n.size,totalOpcodes:c,cacheHit:p,elapsedNs:e,parseCategories:n},metadata:{expression:this.lastExpression,inputType:this.lastInputType,timestamp:Date.now(),vmTraceEnabled:this.vmStepSeen},toJSON(){return {events:o.events,parselets:o.parselets,summary:{totalTokens:o.summary.totalTokens,totalParselets:o.summary.totalParselets,totalOpcodes:o.summary.totalOpcodes,cacheHit:o.summary.cacheHit,elapsedNs:o.summary.elapsedNs,parseCategories:Object.fromEntries(o.summary.parseCategories)},metadata:{...o.metadata}}}};return o}};var y={TokenEmitted:"token_emitted",NormalizerStart:"normalizer_start",TokenFused:"token_fused",NormalizerEnd:"normalizer_end",ParseletMatched:"parselet_matched",BytecodeBuilt:"bytecode_built",VmStep:"vm_step",VmHalt:"vm_halt",CacheHit:"cache_hit",CacheMiss:"cache_miss",PipelineStart:"pipeline_start",PipelineEnd:"pipeline_end"};export{a,i as b,y as c};//# sourceMappingURL=chunk-KHCNMNZZ.js.map
|
|
2
|
+
//# sourceMappingURL=chunk-KHCNMNZZ.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/diagnostics/pipeline.ts","../src/diagnostics/collector.ts","../src/diagnostics/timeline-collector.ts","../src/diagnostics/events.ts"],"names":["DiagnosticPipeline","collector","idx","event","c","reports","report","DiagnosticCollector","_event","TimelineDiagnosticCollector","elapsedNs","entry","parseCategories","totalOpcodes","cacheHit","totalTokens","e","DiagnosticEventType"],"mappings":"AAYO,IAAMA,CAAAA,CAAN,KAAyB,CAAzB,WAAA,EAAA,CACL,KAAQ,UAAA,CAAoC,GAAC,CAE7C,QAAA,CAASC,CAAAA,CAAsC,CAC7C,KAAK,UAAA,CAAW,IAAA,CAAKA,CAAS,EAChC,CAEA,UAAA,CAAWA,EAAs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,CACP,WAAA,CAAAD,CAAAA,CACA,eAAgBH,CAAAA,CAAgB,IAAA,CAChC,aAAAC,CAAAA,CACA,QAAA,CAAAC,EACA,SAAA,CAAAJ,CAAAA,CACA,eAAA,CAAAE,CACF,CAAA,CACA,QAAA,CAAU,CACR,UAAA,CAAY,IAAA,CAAK,cAAA,CACjB,SAAA,CAAW,IAAA,CAAK,aAAA,CAChB,UAAW,IAAA,CAAK,GAAA,EAAI,CACpB,cAAA,CAAgB,IAAA,CAAK,UACvB,EACA,MAAA,EAA+B,CAC7B,OAAO,CACL,MAAA,CAAQN,EAAO,MAAA,CACf,SAAA,CAAWA,CAAAA,CAAO,SAAA,CAClB,OAAA,CAAS,CACP,YAAaA,CAAAA,CAAO,OAAA,CAAQ,WAAA,CAC5B,cAAA,CAAgBA,CAAAA,CAAO,OAAA,CAAQ,eAC/B,YAAA,CAAcA,CAAAA,CAAO,OAAA,CAAQ,YAAA,CAC7B,QAAA,CAAUA,CAAAA,CAAO,QAAQ,QAAA,CACzB,SAAA,CAAWA,EAAO,OAAA,CAAQ,SAAA,CAC1B,gBAAiB,MAAA,CAAO,WAAA,CAAYA,CAAAA,CAAO,OAAA,CAAQ,eAAe,CACpE,EACA,QAAA,CAAU,CAAE,GAAGA,CAAAA,CAAO,QAAS,CACjC,CACF,CACF,CAAA,CAEA,OAAOA,CACT,CACH,MClOaW,CAAAA,CAAsB,CACjC,YAAA,CAAc,eAAA,CACd,eAAA,CAAiB,kBAAA,CACjB,WAAY,aAAA,CACZ,aAAA,CAAe,gBAAA,CACf,eAAA,CAAiB,kBAAA,CACjB,aAAA,CAAe,iBACf,MAAA,CAAQ,SAAA,CACR,MAAA,CAAQ,SAAA,CACR,QAAA,CAAU,WAAA,CACV,UAAW,YAAA,CACX,aAAA,CAAe,gBAAA,CACf,WAAA,CAAa,cACf","file":"chunk-TWC7K3ZX.js","sourcesContent":["import { DiagnosticCollector } from \"./collector\";\nimport { DiagnosticEvent } from \"./events\";\nimport { DiagnosticReport } from \"./events\";\n\n/**\n * Dispatches diagnostic events to all registered collectors.\n *\n * Performance guarantee: when no collectors are registered (production mode),\n * every dispatch method is a branch on `this.collectors.length === 0` which\n * modern JS engines will predict and eliminate. The overhead is a single\n * comparison per call, effectively zero.\n */\nexport class DiagnosticPipeline {\n private collectors: DiagnosticCollector[] = [];\n\n register(collector: DiagnosticCollector): void {\n this.collectors.push(collector);\n }\n\n unregister(collector: DiagnosticCollector): void {\n const idx = this.collectors.indexOf(collector);\n if (idx !== -1) this.collectors.splice(idx, 1);\n }\n\n clear(): void {\n this.collectors = [];\n }\n\n get hasCollectors(): boolean {\n return this.collectors.length > 0;\n }\n\n get collectorCount(): number {\n return this.collectors.length;\n }\n\n // Inline-optimized dispatchers, each checks length once then loops.\n // When collectors.length === 0, the JIT eliminates the entire method body.\n\n firePipelineStart(event: DiagnosticEvent & { type: \"pipeline_start\" }): void {\n if (this.collectors.length === 0) return;\n for (const c of this.collectors) c.onPipelineStart?.(event);\n }\n\n fireTokenEmitted(event: DiagnosticEvent & { type: \"token_emitted\" }): void {\n if (this.collectors.length === 0) return;\n for (const c of this.collectors) c.onTokenEmitted?.(event);\n }\n\n fireNormalizerStart(event: DiagnosticEvent & { type: \"normalizer_start\" }): void {\n if (this.collectors.length === 0) return;\n for (const c of this.collectors) c.onNormalizerStart?.(event);\n }\n\n fireTokenFused(event: DiagnosticEvent & { type: \"token_fused\" }): void {\n if (this.collectors.length === 0) return;\n for (const c of this.collectors) c.onTokenFused?.(event);\n }\n\n fireNormalizerEnd(event: DiagnosticEvent & { type: \"normalizer_end\" }): void {\n if (this.collectors.length === 0) return;\n for (const c of this.collectors) c.onNormalizerEnd?.(event);\n }\n\n fireParseletMatched(event: DiagnosticEvent & { type: \"parselet_matched\" }): void {\n if (this.collectors.length === 0) return;\n for (const c of this.collectors) c.onParseletMatched?.(event);\n }\n\n fireBytecodeBuilt(event: DiagnosticEvent & { type: \"bytecode_built\" }): void {\n if (this.collectors.length === 0) return;\n for (const c of this.collectors) c.onBytecodeBuilt?.(event);\n }\n\n fireVmStep(event: DiagnosticEvent & { type: \"vm_step\" }): void {\n if (this.collectors.length === 0) return;\n for (const c of this.collectors) c.onVmStep?.(event);\n }\n\n fireVmHalt(event: DiagnosticEvent & { type: \"vm_halt\" }): void {\n if (this.collectors.length === 0) return;\n for (const c of this.collectors) c.onVmHalt?.(event);\n }\n\n fireCacheHit(event: DiagnosticEvent & { type: \"cache_hit\" }): void {\n if (this.collectors.length === 0) return;\n for (const c of this.collectors) c.onCacheHit?.(event);\n }\n\n fireCacheMiss(event: DiagnosticEvent & { type: \"cache_miss\" }): void {\n if (this.collectors.length === 0) return;\n for (const c of this.collectors) c.onCacheMiss?.(event);\n }\n\n firePipelineEnd(event: DiagnosticEvent & { type: \"pipeline_end\" }): void {\n if (this.collectors.length === 0) return;\n for (const c of this.collectors) c.onPipelineEnd?.(event);\n }\n\n collectReports(): DiagnosticReport[] {\n const reports: DiagnosticReport[] = [];\n for (const c of this.collectors) {\n const report = c.getReport();\n if (report) reports.push(report);\n }\n return reports;\n }\n\n reset(): void {\n for (const c of this.collectors) c.reset();\n }\n}","import { DiagnosticEvent } from \"./events\";\nimport { DiagnosticReport } from \"./events\";\n\n/**\n * Interface for collecting diagnostic data during pipeline execution.\n *\n * All methods are implemented as concrete no-ops so subclasses only\n * need to override the ones they care about. This avoids optional\n * method issues with TypeScript's strict mode.\n *\n * The parameters are named `_event` because these base implementations\n * deliberately ignore them. Overrides are free to name theirs `event` and use\n * it; TypeScript does not match parameter names when checking overrides.\n */\nexport abstract class DiagnosticCollector {\n onPipelineStart(_event: DiagnosticEvent & { type: \"pipeline_start\" }): void {}\n onTokenEmitted(_event: DiagnosticEvent & { type: \"token_emitted\" }): void {}\n onNormalizerStart(_event: DiagnosticEvent & { type: \"normalizer_start\" }): void {}\n onTokenFused(_event: DiagnosticEvent & { type: \"token_fused\" }): void {}\n onNormalizerEnd(_event: DiagnosticEvent & { type: \"normalizer_end\" }): void {}\n onParseletMatched(_event: DiagnosticEvent & { type: \"parselet_matched\" }): void {}\n onBytecodeBuilt(_event: DiagnosticEvent & { type: \"bytecode_built\" }): void {}\n onVmStep(_event: DiagnosticEvent & { type: \"vm_step\" }): void {}\n onVmHalt(_event: DiagnosticEvent & { type: \"vm_halt\" }): void {}\n onCacheHit(_event: DiagnosticEvent & { type: \"cache_hit\" }): void {}\n onCacheMiss(_event: DiagnosticEvent & { type: \"cache_miss\" }): void {}\n onPipelineEnd(_event: DiagnosticEvent & { type: \"pipeline_end\" }): void {}\n\n abstract getReport(): DiagnosticReport | undefined;\n abstract reset(): void;\n}","import { DiagnosticCollector } from \"./collector\";\nimport { DiagnosticReport, DiagnosticReportJSON, DiagnosticEvent, CategorizedParselet } from \"./events\";\n\n/**\n * Collects all pipeline events with high-resolution timestamps.\n *\n * Overrides the zero-filled `elapsedNs` on every incoming event with a\n * real `performance.now()` delta from `onPipelineStart`. This enables\n * per-stage timing extraction from the event timeline (lexer/parser/\n * compiler/VM breakdown) rather than relying on a single total elapsed.\n *\n * Produces a complete DiagnosticReport at the end of evaluation.\n */\nexport class TimelineDiagnosticCollector extends DiagnosticCollector {\n private events: DiagnosticEvent[] = [];\n private startNs: number = 0;\n private parseletEntries: Map<string, { category: string; count: number }> = new Map();\n\n // Incrementally-maintained summary state. See getReport()'s doc comment\n // for why these exist. Each mirrors exactly what getReport() used to\n // recompute by rescanning the full `events` array on every call.\n private totalTokens = 0;\n private cacheHitSeen = false;\n private vmStepSeen = false;\n private hasBytecodeBuilt = false;\n private firstBytecodeOpcodesLength = 0;\n private parseletMatches: CategorizedParselet[] = [];\n private lastExpression = \"\";\n private lastInputType = \"\";\n\n /**\n * Current cumulative count of `parselet_matched` events seen since\n * construction (or the last `reset()`), a cheap peek that doesn't build\n * the full report (`getReport()` copies the whole `parseletMatches`\n * array). Used by `ExpressionEngine.evaluateExpressionWithDiagnostic()`\n * to capture a \"before\" baseline per line, since `parseletMatches` itself\n * is deliberately cumulative across an entire document pass (see\n * `onPipelineStart`'s doc comment) rather than reset per line.\n */\n get parseletMatchCount(): number {\n return this.parseletMatches.length;\n }\n\n reset(): void {\n this.events = [];\n this.parseletEntries.clear();\n this.startNs = 0;\n this.totalTokens = 0;\n this.cacheHitSeen = false;\n this.vmStepSeen = false;\n this.hasBytecodeBuilt = false;\n this.firstBytecodeOpcodesLength = 0;\n this.parseletMatches = [];\n this.lastExpression = \"\";\n this.lastInputType = \"\";\n }\n\n /** Stamp the real wall-clock `elapsedNs` onto an event before storing it. */\n private stamp<T extends DiagnosticEvent>(event: T): T {\n const elapsedNs = this.startNs !== 0\n ? performance.now() * 1e6 - this.startNs\n : 0;\n return { ...event, elapsedNs } as T;\n }\n\n onPipelineStart(event: DiagnosticEvent & { type: \"pipeline_start\" }): void {\n // Set once per collector lifetime (until an explicit reset()), not on\n // every pipeline, a multi-line evaluation pass fires pipeline_start\n // once per line, all appending to the SAME `events` array (see\n // buildLineStats() in the playground, which relies on that shared,\n // ever-growing array to slice out each line's own events via\n // cumulative-length diffing). Resetting the origin on every line meant\n // every individual line's own timestamps were self-consistent, but\n // nothing tied one line's clock to another's, any code trying to\n // compare or span timestamps ACROSS lines (e.g. \"how far into this\n // pass are we\") had no stable reference point to do it with.\n if (this.startNs === 0) {\n this.startNs = performance.now() * 1e6;\n }\n // Tracked incrementally (most-recent wins) so getReport()'s `metadata`\n // describes the line THIS report is actually about, reading\n // `events[0]` instead (the old code) froze `expression`/`inputType` on\n // the very first line ever evaluated in the session, forever, which is\n // wrong regardless of whether a field is meant to be cumulative or\n // per-line: nothing downstream ever wanted \"line 1's expression\" once\n // the document had moved on to line 50.\n this.lastExpression = event.expression;\n this.lastInputType = event.inputType;\n this.events.push(this.stamp(event));\n }\n\n onTokenEmitted(event: DiagnosticEvent & { type: \"token_emitted\" }): void {\n this.events.push(this.stamp(event));\n this.totalTokens++;\n }\n\n onNormalizerStart(event: DiagnosticEvent & { type: \"normalizer_start\" }): void {\n this.events.push(this.stamp(event));\n }\n\n onTokenFused(event: DiagnosticEvent & { type: \"token_fused\" }): void {\n this.events.push(this.stamp(event));\n }\n\n onNormalizerEnd(event: DiagnosticEvent & { type: \"normalizer_end\" }): void {\n this.events.push(this.stamp(event));\n }\n\n onParseletMatched(event: DiagnosticEvent & { type: \"parselet_matched\" }): void {\n this.events.push(this.stamp(event));\n\n const entry = this.parseletEntries.get(event.parseletCategory);\n if (entry) {\n entry.count++;\n } else {\n this.parseletEntries.set(event.parseletCategory, {\n category: event.parseletCategory,\n count: 1,\n });\n }\n\n this.parseletMatches.push({\n tokenType: event.tokenType,\n tokenValue: event.tokenValue,\n parseletCategory: event.parseletCategory,\n parseletType: event.parseletType,\n isPrefix: event.isPrefix,\n bindingPower: event.bindingPower,\n tokenOffset: event.tokenOffset,\n });\n }\n\n onBytecodeBuilt(event: DiagnosticEvent & { type: \"bytecode_built\" }): void {\n this.events.push(this.stamp(event));\n // Matches getReport()'s original behavior: the FIRST bytecode_built\n // event ever seen (not the most recent) wins, preserved as-is here\n // this rewrite only changes HOW that value is computed, not what it is.\n if (!this.hasBytecodeBuilt) {\n this.hasBytecodeBuilt = true;\n this.firstBytecodeOpcodesLength = event.opcodesLength;\n }\n }\n\n onVmStep(event: DiagnosticEvent & { type: \"vm_step\" }): void {\n this.events.push(this.stamp(event));\n this.vmStepSeen = true;\n }\n\n onVmHalt(event: DiagnosticEvent & { type: \"vm_halt\" }): void {\n this.events.push(this.stamp(event));\n }\n\n onCacheHit(event: DiagnosticEvent & { type: \"cache_hit\" }): void {\n this.events.push(this.stamp(event));\n this.cacheHitSeen = true;\n }\n\n onCacheMiss(event: DiagnosticEvent & { type: \"cache_miss\" }): void {\n this.events.push(this.stamp(event));\n }\n\n onPipelineEnd(event: DiagnosticEvent & { type: \"pipeline_end\" }): void {\n this.events.push(this.stamp(event));\n }\n\n/**\n * Build the summary/metadata/parselets report from this collector's\n * running state.\n *\n * These fields used to be recomputed by rescanning the FULL `events`\n * array on every single call (`.some()`/`.filter()`/a manual scan), since\n * `events` is never cleared except by an explicit `reset()` (which nothing\n * in `ExpressionEngine` currently calls, the cumulative-across-the-whole-\n * document design is deliberate, see `onPipelineStart`'s comment and the\n * playground's `buildLineStats()`, which slices per-line events out of\n * this ever-growing array via cumulative-length diffing), that meant\n * per-call cost grew linearly with total prior calls: O(n²) diagnostic-mode\n * evaluation over a document's lifetime. Fixed by maintaining each of these\n * incrementally as events arrive (see the `on*` handlers above), the same\n * pattern already used for `parseletEntries`. Every value produced here is\n * identical to what the old rescanning code produced, including its\n * existing \"first bytecode_built event wins\" quirk. This is a performance\n * fix, not a behavior change.\n */\ngetReport(): DiagnosticReport | undefined {\n if (this.events.length === 0) return undefined;\n\n const elapsedNs = performance.now() * 1e6 - this.startNs;\n\n const parseCategories = new Map<string, number>();\n for (const [, entry] of this.parseletEntries) {\n parseCategories.set(entry.category, entry.count);\n }\n\n const totalOpcodes = this.firstBytecodeOpcodesLength;\n const cacheHit = this.cacheHitSeen;\n const totalTokens = this.totalTokens;\n\n const report: DiagnosticReport = {\n events: this.events,\n parselets: this.parseletMatches.map((e) => ({ ...e })),\n summary: {\n totalTokens,\n totalParselets: parseCategories.size,\n totalOpcodes,\n cacheHit,\n elapsedNs,\n parseCategories,\n },\n metadata: {\n expression: this.lastExpression,\n inputType: this.lastInputType,\n timestamp: Date.now(),\n vmTraceEnabled: this.vmStepSeen,\n },\n toJSON(): DiagnosticReportJSON {\n return {\n events: report.events,\n parselets: report.parselets,\n summary: {\n totalTokens: report.summary.totalTokens,\n totalParselets: report.summary.totalParselets,\n totalOpcodes: report.summary.totalOpcodes,\n cacheHit: report.summary.cacheHit,\n elapsedNs: report.summary.elapsedNs,\n parseCategories: Object.fromEntries(report.summary.parseCategories),\n },\n metadata: { ...report.metadata },\n };\n },\n };\n\n return report;\n }\n}","\n\nimport type { MatrixData, RangeData, ColourData, SplitData } from \"@solve-js/vm/Value\";\nimport type { SymbolicNode } from \"@solve-js/symbolic\";\n\n/**\n * Diagnostic event types as string constants (not const enum, for cross-module compatibility with isolatedModules)\n */\nexport const DiagnosticEventType = {\n TokenEmitted: \"token_emitted\",\n NormalizerStart: \"normalizer_start\",\n TokenFused: \"token_fused\",\n NormalizerEnd: \"normalizer_end\",\n ParseletMatched: \"parselet_matched\",\n BytecodeBuilt: \"bytecode_built\",\n VmStep: \"vm_step\",\n VmHalt: \"vm_halt\",\n CacheHit: \"cache_hit\",\n CacheMiss: \"cache_miss\",\n PipelineStart: \"pipeline_start\",\n PipelineEnd: \"pipeline_end\",\n} as const;\n\n/** Discriminator naming which pipeline event a diagnostic record describes. */\nexport type EventType = (typeof DiagnosticEventType)[keyof typeof DiagnosticEventType];\n\n/** Base event, all events include a timestamp relative to pipeline start */\nexport interface BaseEvent {\n readonly type: string;\n readonly elapsedNs: number;\n readonly expression: string;\n}\n\n/** Emitted after each token is produced by the lexer */\nexport interface TokenEmittedEvent extends BaseEvent {\n readonly type: \"token_emitted\";\n readonly token: {\n readonly type: string;\n readonly value: string;\n readonly offset: number;\n readonly line: number;\n readonly col: number;\n };\n}\n\n/** Emitted when the parser resolves a parselet for a token */\nexport interface ParseletMatchedEvent extends BaseEvent {\n readonly type: \"parselet_matched\";\n readonly tokenType: string;\n readonly tokenValue: string;\n readonly parseletCategory: string;\n readonly parseletType: string;\n readonly isPrefix: boolean;\n readonly bindingPower?: number;\n readonly tokenOffset: number;\n}\n\n/** Emitted after bytecode is built */\nexport interface BytecodeBuiltEvent extends BaseEvent {\n readonly type: \"bytecode_built\";\n readonly opcodesLength: number;\n readonly numbersLength: number;\n readonly stringsLength: number;\n readonly isCached: boolean;\n}\n\n/** Emitted after each VM opcode execution (only when vmTrace is enabled) */\nexport interface VmStepEvent extends BaseEvent {\n readonly type: \"vm_step\";\n readonly opcode: number;\n readonly opcodeName: string;\n readonly ip: number;\n readonly stackDepth: number;\n readonly instructionNumber: number;\n readonly stack: ReadonlyArray<{\n readonly type: number;\n readonly value: number | bigint | string | boolean | MatrixData | RangeData | ColourData | SplitData | SymbolicNode;\n readonly unit?: string;\n }>;\n}\n\n/** Emitted when the VM halts with a result */\nexport interface VmHaltEvent extends BaseEvent {\n readonly type: \"vm_halt\";\n readonly result?: {\n readonly type: number;\n readonly value: number | bigint | string | boolean | MatrixData | RangeData | ColourData | SplitData | SymbolicNode;\n readonly unit?: string;\n };\n}\n\n/** Emitted on cache hit */\nexport interface CacheHitEvent extends BaseEvent {\n readonly type: \"cache_hit\";\n readonly cache: \"bytecode\" | \"line\";\n readonly key: string;\n}\n\n/** Emitted on cache miss */\nexport interface CacheMissEvent extends BaseEvent {\n readonly type: \"cache_miss\";\n readonly cache: \"bytecode\" | \"line\";\n readonly key: string;\n}\n\n/** Emitted when a pipeline evaluation begins */\nexport interface PipelineStartEvent extends BaseEvent {\n readonly type: \"pipeline_start\";\n readonly inputType: string;\n}\n\n/** Emitted when a pipeline evaluation completes */\nexport interface PipelineEndEvent extends BaseEvent {\n readonly type: \"pipeline_end\";\n readonly success: boolean;\n readonly error?: string;\n readonly totalTokens: number;\n readonly totalOpcodes: number;\n}\n\n/** Emitted when the normalizer begins its pass */\nexport interface NormalizerStartEvent extends BaseEvent {\n readonly type: \"normalizer_start\";\n readonly inputTokenCount: number;\n}\n\n/** Emitted when the normalizer fuses tokens */\nexport interface TokenFusedEvent extends BaseEvent {\n readonly type: \"token_fused\";\n readonly ruleName: string;\n readonly sourceTokenCount: number;\n readonly fusedTokenType: string;\n readonly fusedTokenValue: string;\n}\n\n/** Emitted when the normalizer completes its pass */\nexport interface NormalizerEndEvent extends BaseEvent {\n readonly type: \"normalizer_end\";\n readonly outputTokenCount: number;\n readonly fusionsCount: number;\n}\n\n/** Union of all event types */\nexport type DiagnosticEvent =\n | TokenEmittedEvent\n | NormalizerStartEvent\n | TokenFusedEvent\n | NormalizerEndEvent\n | ParseletMatchedEvent\n | BytecodeBuiltEvent\n | VmStepEvent\n | VmHaltEvent\n | CacheHitEvent\n | CacheMissEvent\n | PipelineStartEvent\n | PipelineEndEvent;\n\n/** Categorized parselet info */\nexport interface CategorizedParselet {\n readonly tokenType: string;\n readonly tokenValue: string;\n readonly parseletCategory: string;\n readonly parseletType: string;\n readonly isPrefix: boolean;\n readonly bindingPower?: number;\n readonly tokenOffset: number;\n}\n\n/** JSON-serializable representation of a DiagnosticReport */\nexport interface DiagnosticReportJSON {\n readonly events: readonly DiagnosticEvent[];\n readonly parselets: readonly CategorizedParselet[];\n readonly summary: {\n readonly totalTokens: number;\n readonly totalParselets: number;\n readonly totalOpcodes: number;\n readonly cacheHit: boolean;\n readonly elapsedNs: number;\n readonly parseCategories: Record<string, number>;\n };\n readonly metadata: {\n readonly expression: string;\n readonly inputType: string;\n readonly timestamp: number;\n readonly vmTraceEnabled: boolean;\n };\n}\n\n/** Structured diagnostic report */\nexport interface DiagnosticReport {\n readonly events: readonly DiagnosticEvent[];\n readonly parselets: readonly CategorizedParselet[];\n readonly summary: {\n readonly totalTokens: number;\n readonly totalParselets: number;\n readonly totalOpcodes: number;\n readonly cacheHit: boolean;\n readonly elapsedNs: number;\n readonly parseCategories: ReadonlyMap<string, number>;\n };\n readonly metadata: {\n readonly expression: string;\n readonly inputType: string;\n readonly timestamp: number;\n readonly vmTraceEnabled: boolean;\n };\n\n /** Serialize to a JSON-safe plain object */\n toJSON(): DiagnosticReportJSON;\n}\n\n/** JSON-serializable representation of a DiagnosticReport */\nexport interface DiagnosticReportJSON {\n readonly events: readonly DiagnosticEvent[];\n readonly parselets: readonly CategorizedParselet[];\n readonly summary: {\n readonly totalTokens: number;\n readonly totalParselets: number;\n readonly totalOpcodes: number;\n readonly cacheHit: boolean;\n readonly elapsedNs: number;\n readonly parseCategories: Record<string, number>;\n };\n readonly metadata: {\n readonly expression: string;\n readonly inputType: string;\n readonly timestamp: number;\n readonly vmTraceEnabled: boolean;\n };\n}"]}
|
|
1
|
+
{"version":3,"sources":["../src/diagnostics/pipeline.ts","../src/diagnostics/collector.ts","../src/diagnostics/timeline-collector.ts","../src/diagnostics/events.ts"],"names":["DiagnosticPipeline","collector","idx","event","c","reports","report","DiagnosticCollector","_event","TimelineDiagnosticCollector","elapsedNs","entry","parseCategories","totalOpcodes","cacheHit","totalTokens","e","DiagnosticEventType"],"mappings":"AAYO,IAAMA,CAAAA,CAAN,KAAyB,CAAzB,WAAA,EAAA,CACL,KAAQ,UAAA,CAAoC,GAAC,CAE7C,QAAA,CAASC,CAAAA,CAAsC,CAC7C,KAAK,UAAA,CAAW,IAAA,CAAKA,CAAS,EAChC,CAEA,UAAA,CAAWA,EAAsC,CAC/C,IAAMC,CAAAA,CAAM,IAAA,CAAK,UAAA,CAAW,OAAA,CAAQD,CAAS,CAAA,CACzCC,CAAAA,GAAQ,IAAI,IAAA,CAAK,UAAA,CAAW,OAAOA,CAAAA,CAAK,CAAC,EAC/C,CAEA,KAAA,EAAc,CACZ,KAAK,UAAA,CAAa,GACpB,CAEA,IAAI,aAAA,EAAyB,CAC3B,OAAO,IAAA,CAAK,UAAA,CAAW,MAAA,CAAS,CAClC,CAEA,IAAI,cAAA,EAAyB,CAC3B,OAAO,IAAA,CAAK,UAAA,CAAW,MACzB,CAKA,iBAAA,CAAkBC,CAAAA,CAA2D,CAC3E,GAAI,IAAA,CAAK,WAAW,MAAA,GAAW,CAAA,CAC/B,IAAA,IAAWC,CAAAA,IAAK,IAAA,CAAK,UAAA,CAAYA,EAAE,eAAA,GAAkBD,CAAK,EAC5D,CAEA,gBAAA,CAAiBA,CAAAA,CAA0D,CACzE,GAAI,IAAA,CAAK,WAAW,MAAA,GAAW,CAAA,CAC/B,QAAWC,CAAAA,IAAK,IAAA,CAAK,UAAA,CAAYA,CAAAA,CAAE,cAAA,GAAiBD,CAAK,EAC3D,CAEA,mBAAA,CAAoBA,CAAAA,CAA6D,CAC/E,GAAI,IAAA,CAAK,WAAW,MAAA,GAAW,CAAA,CAC/B,IAAA,IAAWC,CAAAA,IAAK,IAAA,CAAK,UAAA,CAAYA,EAAE,iBAAA,GAAoBD,CAAK,EAC9D,CAEA,cAAA,CAAeA,EAAwD,C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aAAA,CACZ,aAAA,CAAe,gBAAA,CACf,eAAA,CAAiB,kBAAA,CACjB,aAAA,CAAe,iBACf,MAAA,CAAQ,SAAA,CACR,MAAA,CAAQ,SAAA,CACR,QAAA,CAAU,WAAA,CACV,UAAW,YAAA,CACX,aAAA,CAAe,gBAAA,CACf,WAAA,CAAa,cACf","file":"chunk-KHCNMNZZ.js","sourcesContent":["import { DiagnosticCollector } from \"./collector\";\nimport { DiagnosticEvent } from \"./events\";\nimport { DiagnosticReport } from \"./events\";\n\n/**\n * Dispatches diagnostic events to all registered collectors.\n *\n * Performance guarantee: when no collectors are registered (production mode),\n * every dispatch method is a branch on `this.collectors.length === 0` which\n * modern JS engines will predict and eliminate. The overhead is a single\n * comparison per call, effectively zero.\n */\nexport class DiagnosticPipeline {\n private collectors: DiagnosticCollector[] = [];\n\n register(collector: DiagnosticCollector): void {\n this.collectors.push(collector);\n }\n\n unregister(collector: DiagnosticCollector): void {\n const idx = this.collectors.indexOf(collector);\n if (idx !== -1) this.collectors.splice(idx, 1);\n }\n\n clear(): void {\n this.collectors = [];\n }\n\n get hasCollectors(): boolean {\n return this.collectors.length > 0;\n }\n\n get collectorCount(): number {\n return this.collectors.length;\n }\n\n // Inline-optimized dispatchers, each checks length once then loops.\n // When collectors.length === 0, the JIT eliminates the entire method body.\n\n firePipelineStart(event: DiagnosticEvent & { type: \"pipeline_start\" }): void {\n if (this.collectors.length === 0) return;\n for (const c of this.collectors) c.onPipelineStart?.(event);\n }\n\n fireTokenEmitted(event: DiagnosticEvent & { type: \"token_emitted\" }): void {\n if (this.collectors.length === 0) return;\n for (const c of this.collectors) c.onTokenEmitted?.(event);\n }\n\n fireNormalizerStart(event: DiagnosticEvent & { type: \"normalizer_start\" }): void {\n if (this.collectors.length === 0) return;\n for (const c of this.collectors) c.onNormalizerStart?.(event);\n }\n\n fireTokenFused(event: DiagnosticEvent & { type: \"token_fused\" }): void {\n if (this.collectors.length === 0) return;\n for (const c of this.collectors) c.onTokenFused?.(event);\n }\n\n fireNormalizerEnd(event: DiagnosticEvent & { type: \"normalizer_end\" }): void {\n if (this.collectors.length === 0) return;\n for (const c of this.collectors) c.onNormalizerEnd?.(event);\n }\n\n fireParseletMatched(event: DiagnosticEvent & { type: \"parselet_matched\" }): void {\n if (this.collectors.length === 0) return;\n for (const c of this.collectors) c.onParseletMatched?.(event);\n }\n\n fireBytecodeBuilt(event: DiagnosticEvent & { type: \"bytecode_built\" }): void {\n if (this.collectors.length === 0) return;\n for (const c of this.collectors) c.onBytecodeBuilt?.(event);\n }\n\n fireVmStep(event: DiagnosticEvent & { type: \"vm_step\" }): void {\n if (this.collectors.length === 0) return;\n for (const c of this.collectors) c.onVmStep?.(event);\n }\n\n fireVmHalt(event: DiagnosticEvent & { type: \"vm_halt\" }): void {\n if (this.collectors.length === 0) return;\n for (const c of this.collectors) c.onVmHalt?.(event);\n }\n\n fireCacheHit(event: DiagnosticEvent & { type: \"cache_hit\" }): void {\n if (this.collectors.length === 0) return;\n for (const c of this.collectors) c.onCacheHit?.(event);\n }\n\n fireCacheMiss(event: DiagnosticEvent & { type: \"cache_miss\" }): void {\n if (this.collectors.length === 0) return;\n for (const c of this.collectors) c.onCacheMiss?.(event);\n }\n\n firePipelineEnd(event: DiagnosticEvent & { type: \"pipeline_end\" }): void {\n if (this.collectors.length === 0) return;\n for (const c of this.collectors) c.onPipelineEnd?.(event);\n }\n\n collectReports(): DiagnosticReport[] {\n const reports: DiagnosticReport[] = [];\n for (const c of this.collectors) {\n const report = c.getReport();\n if (report) reports.push(report);\n }\n return reports;\n }\n\n reset(): void {\n for (const c of this.collectors) c.reset();\n }\n}","import { DiagnosticEvent } from \"./events\";\nimport { DiagnosticReport } from \"./events\";\n\n/**\n * Interface for collecting diagnostic data during pipeline execution.\n *\n * All methods are implemented as concrete no-ops so subclasses only\n * need to override the ones they care about. This avoids optional\n * method issues with TypeScript's strict mode.\n *\n * The parameters are named `_event` because these base implementations\n * deliberately ignore them. Overrides are free to name theirs `event` and use\n * it; TypeScript does not match parameter names when checking overrides.\n */\nexport abstract class DiagnosticCollector {\n onPipelineStart(_event: DiagnosticEvent & { type: \"pipeline_start\" }): void {}\n onTokenEmitted(_event: DiagnosticEvent & { type: \"token_emitted\" }): void {}\n onNormalizerStart(_event: DiagnosticEvent & { type: \"normalizer_start\" }): void {}\n onTokenFused(_event: DiagnosticEvent & { type: \"token_fused\" }): void {}\n onNormalizerEnd(_event: DiagnosticEvent & { type: \"normalizer_end\" }): void {}\n onParseletMatched(_event: DiagnosticEvent & { type: \"parselet_matched\" }): void {}\n onBytecodeBuilt(_event: DiagnosticEvent & { type: \"bytecode_built\" }): void {}\n onVmStep(_event: DiagnosticEvent & { type: \"vm_step\" }): void {}\n onVmHalt(_event: DiagnosticEvent & { type: \"vm_halt\" }): void {}\n onCacheHit(_event: DiagnosticEvent & { type: \"cache_hit\" }): void {}\n onCacheMiss(_event: DiagnosticEvent & { type: \"cache_miss\" }): void {}\n onPipelineEnd(_event: DiagnosticEvent & { type: \"pipeline_end\" }): void {}\n\n abstract getReport(): DiagnosticReport | undefined;\n abstract reset(): void;\n}","import { DiagnosticCollector } from \"./collector\";\nimport { DiagnosticReport, DiagnosticReportJSON, DiagnosticEvent, CategorizedParselet } from \"./events\";\n\n/**\n * Collects all pipeline events with high-resolution timestamps.\n *\n * Overrides the zero-filled `elapsedNs` on every incoming event with a\n * real `performance.now()` delta from `onPipelineStart`. This enables\n * per-stage timing extraction from the event timeline (lexer/parser/\n * compiler/VM breakdown) rather than relying on a single total elapsed.\n *\n * Produces a complete DiagnosticReport at the end of evaluation.\n */\nexport class TimelineDiagnosticCollector extends DiagnosticCollector {\n private events: DiagnosticEvent[] = [];\n private startNs: number = 0;\n private parseletEntries: Map<string, { category: string; count: number }> = new Map();\n\n // Incrementally-maintained summary state. See getReport()'s doc comment\n // for why these exist. Each mirrors exactly what getReport() used to\n // recompute by rescanning the full `events` array on every call.\n private totalTokens = 0;\n private cacheHitSeen = false;\n private vmStepSeen = false;\n private hasBytecodeBuilt = false;\n private firstBytecodeOpcodesLength = 0;\n private parseletMatches: CategorizedParselet[] = [];\n private lastExpression = \"\";\n private lastInputType = \"\";\n\n /**\n * Current cumulative count of `parselet_matched` events seen since\n * construction (or the last `reset()`), a cheap peek that doesn't build\n * the full report (`getReport()` copies the whole `parseletMatches`\n * array). Used by `ExpressionEngine.evaluateExpressionWithDiagnostic()`\n * to capture a \"before\" baseline per line, since `parseletMatches` itself\n * is deliberately cumulative across an entire document pass (see\n * `onPipelineStart`'s doc comment) rather than reset per line.\n */\n get parseletMatchCount(): number {\n return this.parseletMatches.length;\n }\n\n reset(): void {\n this.events = [];\n this.parseletEntries.clear();\n this.startNs = 0;\n this.totalTokens = 0;\n this.cacheHitSeen = false;\n this.vmStepSeen = false;\n this.hasBytecodeBuilt = false;\n this.firstBytecodeOpcodesLength = 0;\n this.parseletMatches = [];\n this.lastExpression = \"\";\n this.lastInputType = \"\";\n }\n\n /** Stamp the real wall-clock `elapsedNs` onto an event before storing it. */\n private stamp<T extends DiagnosticEvent>(event: T): T {\n const elapsedNs = this.startNs !== 0\n ? performance.now() * 1e6 - this.startNs\n : 0;\n return { ...event, elapsedNs } as T;\n }\n\n onPipelineStart(event: DiagnosticEvent & { type: \"pipeline_start\" }): void {\n // Set once per collector lifetime (until an explicit reset()), not on\n // every pipeline, a multi-line evaluation pass fires pipeline_start\n // once per line, all appending to the SAME `events` array (see\n // buildLineStats() in the playground, which relies on that shared,\n // ever-growing array to slice out each line's own events via\n // cumulative-length diffing). Resetting the origin on every line meant\n // every individual line's own timestamps were self-consistent, but\n // nothing tied one line's clock to another's, any code trying to\n // compare or span timestamps ACROSS lines (e.g. \"how far into this\n // pass are we\") had no stable reference point to do it with.\n if (this.startNs === 0) {\n this.startNs = performance.now() * 1e6;\n }\n // Tracked incrementally (most-recent wins) so getReport()'s `metadata`\n // describes the line THIS report is actually about, reading\n // `events[0]` instead (the old code) froze `expression`/`inputType` on\n // the very first line ever evaluated in the session, forever, which is\n // wrong regardless of whether a field is meant to be cumulative or\n // per-line: nothing downstream ever wanted \"line 1's expression\" once\n // the document had moved on to line 50.\n this.lastExpression = event.expression;\n this.lastInputType = event.inputType;\n this.events.push(this.stamp(event));\n }\n\n onTokenEmitted(event: DiagnosticEvent & { type: \"token_emitted\" }): void {\n this.events.push(this.stamp(event));\n this.totalTokens++;\n }\n\n onNormalizerStart(event: DiagnosticEvent & { type: \"normalizer_start\" }): void {\n this.events.push(this.stamp(event));\n }\n\n onTokenFused(event: DiagnosticEvent & { type: \"token_fused\" }): void {\n this.events.push(this.stamp(event));\n }\n\n onNormalizerEnd(event: DiagnosticEvent & { type: \"normalizer_end\" }): void {\n this.events.push(this.stamp(event));\n }\n\n onParseletMatched(event: DiagnosticEvent & { type: \"parselet_matched\" }): void {\n this.events.push(this.stamp(event));\n\n const entry = this.parseletEntries.get(event.parseletCategory);\n if (entry) {\n entry.count++;\n } else {\n this.parseletEntries.set(event.parseletCategory, {\n category: event.parseletCategory,\n count: 1,\n });\n }\n\n this.parseletMatches.push({\n tokenType: event.tokenType,\n tokenValue: event.tokenValue,\n parseletCategory: event.parseletCategory,\n parseletType: event.parseletType,\n isPrefix: event.isPrefix,\n bindingPower: event.bindingPower,\n tokenOffset: event.tokenOffset,\n });\n }\n\n onBytecodeBuilt(event: DiagnosticEvent & { type: \"bytecode_built\" }): void {\n this.events.push(this.stamp(event));\n // Matches getReport()'s original behavior: the FIRST bytecode_built\n // event ever seen (not the most recent) wins, preserved as-is here\n // this rewrite only changes HOW that value is computed, not what it is.\n if (!this.hasBytecodeBuilt) {\n this.hasBytecodeBuilt = true;\n this.firstBytecodeOpcodesLength = event.opcodesLength;\n }\n }\n\n onVmStep(event: DiagnosticEvent & { type: \"vm_step\" }): void {\n this.events.push(this.stamp(event));\n this.vmStepSeen = true;\n }\n\n onVmHalt(event: DiagnosticEvent & { type: \"vm_halt\" }): void {\n this.events.push(this.stamp(event));\n }\n\n onCacheHit(event: DiagnosticEvent & { type: \"cache_hit\" }): void {\n this.events.push(this.stamp(event));\n this.cacheHitSeen = true;\n }\n\n onCacheMiss(event: DiagnosticEvent & { type: \"cache_miss\" }): void {\n this.events.push(this.stamp(event));\n }\n\n onPipelineEnd(event: DiagnosticEvent & { type: \"pipeline_end\" }): void {\n this.events.push(this.stamp(event));\n }\n\n/**\n * Build the summary/metadata/parselets report from this collector's\n * running state.\n *\n * These fields used to be recomputed by rescanning the FULL `events`\n * array on every single call (`.some()`/`.filter()`/a manual scan), since\n * `events` is never cleared except by an explicit `reset()` (which nothing\n * in `ExpressionEngine` currently calls, the cumulative-across-the-whole-\n * document design is deliberate, see `onPipelineStart`'s comment and the\n * playground's `buildLineStats()`, which slices per-line events out of\n * this ever-growing array via cumulative-length diffing), that meant\n * per-call cost grew linearly with total prior calls: O(n²) diagnostic-mode\n * evaluation over a document's lifetime. Fixed by maintaining each of these\n * incrementally as events arrive (see the `on*` handlers above), the same\n * pattern already used for `parseletEntries`. Every value produced here is\n * identical to what the old rescanning code produced, including its\n * existing \"first bytecode_built event wins\" quirk. This is a performance\n * fix, not a behavior change.\n */\ngetReport(): DiagnosticReport | undefined {\n if (this.events.length === 0) return undefined;\n\n const elapsedNs = performance.now() * 1e6 - this.startNs;\n\n const parseCategories = new Map<string, number>();\n for (const [, entry] of this.parseletEntries) {\n parseCategories.set(entry.category, entry.count);\n }\n\n const totalOpcodes = this.firstBytecodeOpcodesLength;\n const cacheHit = this.cacheHitSeen;\n const totalTokens = this.totalTokens;\n\n const report: DiagnosticReport = {\n events: this.events,\n parselets: this.parseletMatches.map((e) => ({ ...e })),\n summary: {\n totalTokens,\n totalParselets: parseCategories.size,\n totalOpcodes,\n cacheHit,\n elapsedNs,\n parseCategories,\n },\n metadata: {\n expression: this.lastExpression,\n inputType: this.lastInputType,\n timestamp: Date.now(),\n vmTraceEnabled: this.vmStepSeen,\n },\n toJSON(): DiagnosticReportJSON {\n return {\n events: report.events,\n parselets: report.parselets,\n summary: {\n totalTokens: report.summary.totalTokens,\n totalParselets: report.summary.totalParselets,\n totalOpcodes: report.summary.totalOpcodes,\n cacheHit: report.summary.cacheHit,\n elapsedNs: report.summary.elapsedNs,\n parseCategories: Object.fromEntries(report.summary.parseCategories),\n },\n metadata: { ...report.metadata },\n };\n },\n };\n\n return report;\n }\n}","\n\nimport type { MatrixData, RangeData, ColourData, SplitData, ChartData, IpCidrData } from \"@solve-js/vm/Value\";\nimport type { SymbolicNode } from \"@solve-js/symbolic\";\n\n/**\n * Diagnostic event types as string constants (not const enum, for cross-module compatibility with isolatedModules)\n */\nexport const DiagnosticEventType = {\n TokenEmitted: \"token_emitted\",\n NormalizerStart: \"normalizer_start\",\n TokenFused: \"token_fused\",\n NormalizerEnd: \"normalizer_end\",\n ParseletMatched: \"parselet_matched\",\n BytecodeBuilt: \"bytecode_built\",\n VmStep: \"vm_step\",\n VmHalt: \"vm_halt\",\n CacheHit: \"cache_hit\",\n CacheMiss: \"cache_miss\",\n PipelineStart: \"pipeline_start\",\n PipelineEnd: \"pipeline_end\",\n} as const;\n\n/** Discriminator naming which pipeline event a diagnostic record describes. */\nexport type EventType = (typeof DiagnosticEventType)[keyof typeof DiagnosticEventType];\n\n/** Base event, all events include a timestamp relative to pipeline start */\nexport interface BaseEvent {\n readonly type: string;\n readonly elapsedNs: number;\n readonly expression: string;\n}\n\n/** Emitted after each token is produced by the lexer */\nexport interface TokenEmittedEvent extends BaseEvent {\n readonly type: \"token_emitted\";\n readonly token: {\n readonly type: string;\n readonly value: string;\n readonly offset: number;\n readonly line: number;\n readonly col: number;\n };\n}\n\n/** Emitted when the parser resolves a parselet for a token */\nexport interface ParseletMatchedEvent extends BaseEvent {\n readonly type: \"parselet_matched\";\n readonly tokenType: string;\n readonly tokenValue: string;\n readonly parseletCategory: string;\n readonly parseletType: string;\n readonly isPrefix: boolean;\n readonly bindingPower?: number;\n readonly tokenOffset: number;\n}\n\n/** Emitted after bytecode is built */\nexport interface BytecodeBuiltEvent extends BaseEvent {\n readonly type: \"bytecode_built\";\n readonly opcodesLength: number;\n readonly numbersLength: number;\n readonly stringsLength: number;\n readonly isCached: boolean;\n}\n\n/** Emitted after each VM opcode execution (only when vmTrace is enabled) */\nexport interface VmStepEvent extends BaseEvent {\n readonly type: \"vm_step\";\n readonly opcode: number;\n readonly opcodeName: string;\n readonly ip: number;\n readonly stackDepth: number;\n readonly instructionNumber: number;\n readonly stack: ReadonlyArray<{\n readonly type: number;\n readonly value: number | bigint | string | boolean | MatrixData | RangeData | ColourData | SplitData | ChartData | IpCidrData | SymbolicNode;\n readonly unit?: string;\n }>;\n}\n\n/** Emitted when the VM halts with a result */\nexport interface VmHaltEvent extends BaseEvent {\n readonly type: \"vm_halt\";\n readonly result?: {\n readonly type: number;\n readonly value: number | bigint | string | boolean | MatrixData | RangeData | ColourData | SplitData | ChartData | IpCidrData | SymbolicNode;\n readonly unit?: string;\n };\n}\n\n/** Emitted on cache hit */\nexport interface CacheHitEvent extends BaseEvent {\n readonly type: \"cache_hit\";\n readonly cache: \"bytecode\" | \"line\";\n readonly key: string;\n}\n\n/** Emitted on cache miss */\nexport interface CacheMissEvent extends BaseEvent {\n readonly type: \"cache_miss\";\n readonly cache: \"bytecode\" | \"line\";\n readonly key: string;\n}\n\n/** Emitted when a pipeline evaluation begins */\nexport interface PipelineStartEvent extends BaseEvent {\n readonly type: \"pipeline_start\";\n readonly inputType: string;\n}\n\n/** Emitted when a pipeline evaluation completes */\nexport interface PipelineEndEvent extends BaseEvent {\n readonly type: \"pipeline_end\";\n readonly success: boolean;\n readonly error?: string;\n readonly totalTokens: number;\n readonly totalOpcodes: number;\n}\n\n/** Emitted when the normalizer begins its pass */\nexport interface NormalizerStartEvent extends BaseEvent {\n readonly type: \"normalizer_start\";\n readonly inputTokenCount: number;\n}\n\n/** Emitted when the normalizer fuses tokens */\nexport interface TokenFusedEvent extends BaseEvent {\n readonly type: \"token_fused\";\n readonly ruleName: string;\n readonly sourceTokenCount: number;\n readonly fusedTokenType: string;\n readonly fusedTokenValue: string;\n}\n\n/** Emitted when the normalizer completes its pass */\nexport interface NormalizerEndEvent extends BaseEvent {\n readonly type: \"normalizer_end\";\n readonly outputTokenCount: number;\n readonly fusionsCount: number;\n}\n\n/** Union of all event types */\nexport type DiagnosticEvent =\n | TokenEmittedEvent\n | NormalizerStartEvent\n | TokenFusedEvent\n | NormalizerEndEvent\n | ParseletMatchedEvent\n | BytecodeBuiltEvent\n | VmStepEvent\n | VmHaltEvent\n | CacheHitEvent\n | CacheMissEvent\n | PipelineStartEvent\n | PipelineEndEvent;\n\n/** Categorized parselet info */\nexport interface CategorizedParselet {\n readonly tokenType: string;\n readonly tokenValue: string;\n readonly parseletCategory: string;\n readonly parseletType: string;\n readonly isPrefix: boolean;\n readonly bindingPower?: number;\n readonly tokenOffset: number;\n}\n\n/** JSON-serializable representation of a DiagnosticReport */\nexport interface DiagnosticReportJSON {\n readonly events: readonly DiagnosticEvent[];\n readonly parselets: readonly CategorizedParselet[];\n readonly summary: {\n readonly totalTokens: number;\n readonly totalParselets: number;\n readonly totalOpcodes: number;\n readonly cacheHit: boolean;\n readonly elapsedNs: number;\n readonly parseCategories: Record<string, number>;\n };\n readonly metadata: {\n readonly expression: string;\n readonly inputType: string;\n readonly timestamp: number;\n readonly vmTraceEnabled: boolean;\n };\n}\n\n/** Structured diagnostic report */\nexport interface DiagnosticReport {\n readonly events: readonly DiagnosticEvent[];\n readonly parselets: readonly CategorizedParselet[];\n readonly summary: {\n readonly totalTokens: number;\n readonly totalParselets: number;\n readonly totalOpcodes: number;\n readonly cacheHit: boolean;\n readonly elapsedNs: number;\n readonly parseCategories: ReadonlyMap<string, number>;\n };\n readonly metadata: {\n readonly expression: string;\n readonly inputType: string;\n readonly timestamp: number;\n readonly vmTraceEnabled: boolean;\n };\n\n /** Serialize to a JSON-safe plain object */\n toJSON(): DiagnosticReportJSON;\n}\n\n/** JSON-serializable representation of a DiagnosticReport */\nexport interface DiagnosticReportJSON {\n readonly events: readonly DiagnosticEvent[];\n readonly parselets: readonly CategorizedParselet[];\n readonly summary: {\n readonly totalTokens: number;\n readonly totalParselets: number;\n readonly totalOpcodes: number;\n readonly cacheHit: boolean;\n readonly elapsedNs: number;\n readonly parseCategories: Record<string, number>;\n };\n readonly metadata: {\n readonly expression: string;\n readonly inputType: string;\n readonly timestamp: number;\n readonly vmTraceEnabled: boolean;\n };\n}"]}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {a}from'./chunk-RAF57WYO.js';import {l,m,g}from'./chunk-
|
|
2
|
-
`),r=new Array(n.length);for(let s=0;s<n.length;s++){let i=this.nextLineId++;r[s]=i,this.lines.set(i,{lineId:i,textHash:a(n[s]),text:n[s],expressions:[],bytecodes:[],reads:[],writes:[],results:[],result:null,dirty:true,isVariableDef:false,isEmpty:n[s].trim().length===0,inlineSolveCount:0});}this.orderTree.replaceAll(r);for(let s of r)this.dirtyLineIds.add(s);}applyChanges(e){let t=[],n=[],r=[...e].sort((s,i)=>i.startLine-s.startLine);for(let s of r){let i=s.startLine-1,a$1=[];for(let o of s.insertLines){let c=this.nextLineId++;a$1.push(c),t.push(c),this.lines.set(c,{lineId:c,textHash:a(o),text:o,expressions:[],bytecodes:[],reads:[],writes:[],results:[],result:null,dirty:true,isVariableDef:false,isEmpty:o.trim().length===0,inlineSolveCount:0});}for(let o of a$1)this.dirtyLineIds.add(o);let l=this.orderTree.spliceAt(i,s.deleteCount,a$1);for(let o of l)n.push(o),this.lines.delete(o),this.dirtyLineIds.delete(o);}return this._positionCache=null,{inserted:t,removed:n}}insertLines(e,t){let n={startLine:e,deleteCount:0,insertLines:t};return this.applyChanges([n]).inserted}deleteLines(e,t){let n={startLine:e,deleteCount:t-e+1,insertLines:[]};return this.applyChanges([n]).removed}editLine(e,t){let n=this.getLineAt(e);if(!n)return false;let r=a(t);return r===n.textHash?false:(n.text=t,n.textHash=r,n.expressions=[],n.bytecodes=[],n.results=[],n.result=null,n.inlineSolveCount=0,n.dirty=true,this.dirtyLineIds.add(n.lineId),n.isEmpty=t.trim().length===0,true)}getLineAt(e){let t=e-1,n=this.orderTree.getAt(t);if(n!==void 0)return this.lines.get(n)}getLinePosition(e){if(this._positionCache)return this._positionCache.get(e)??-1;this._positionCache=new Map;let t=1;for(let n of this.orderTree)this._positionCache.set(n,t++);return this._positionCache.get(e)??-1}getVisibleLines(e,t){let n=this.orderTree.getRange(e-1,t-1),r=[];for(let s of n){let i=this.lines.get(s);i&&r.push(i);}return r}getAllLines(){return this.getVisibleLines(1,this.lineCount)}getLineById(e){return this.lines.get(e)}getDirtyLines(){let e=[];for(let t of this.lines.values())t.dirty&&e.push(t);return e}hasAnyDirtyLineBefore(e){for(let t of this.dirtyLineIds){let n=this.getLinePosition(t);if(n>=1&&n<e)return true}return false}hasAnyDirtyVariableDefLineBefore(e){for(let t of this.dirtyLineIds){let n=this.lines.get(t);if(!n||!n.isVariableDef)continue;let r=this.getLinePosition(t);if(r>=1&&r<e)return true}return false}get dirtyCount(){return this.dirtyLineIds.size}isBytecodeValid(e,t){let n=this.lines.get(e);return n!==void 0&&n.textHash===t}markClean(e){let t=this.lines.get(e);t&&(t.dirty=false,this.dirtyLineIds.delete(e));}markDirtyByLineNumber(e){let t=this.getLineAt(e);t&&(t.dirty=true,this.dirtyLineIds.add(t.lineId));}markDirty(e){let t=this.lines.get(e);t&&(t.dirty=true,this.dirtyLineIds.add(e));}invalidateAll(){for(let e of this.lines.values())e.dirty=true;this.dirtyLineIds=new Set(this.lines.keys());}updateLineResult(e,t,n,r,s,i,a,l=0){let o=this.lines.get(e);o&&(o.results=t,o.result=t[0]?.[0]??null,o.bytecodes=n,o.expressions=r,o.reads=s,o.writes=i,o.isVariableDef=a,o.inlineSolveCount=l,o.dirty=false,this.dirtyLineIds.delete(e));}updateLineCompiled(e,t,n,r,s,i,a=0){let l=this.lines.get(e);l&&(l.expressions=t,l.bytecodes=n,l.reads=r,l.writes=s,l.isVariableDef=i,l.inlineSolveCount=a);}get lineCount(){return this.orderTree.length}get isEmpty(){return this.orderTree.isEmpty}*[Symbol.iterator](){for(let e of this.orderTree){let t=this.lines.get(e);t&&(yield t);}}clear(){this.lines.clear(),this.orderTree.clear(),this._positionCache=null,this.nextLineId=1;}toJSON(){return {lineCount:this.lineCount,lines:this.getAllLines().map(e=>({lineId:e.lineId,text:e.text.substring(0,80),textHash:e.textHash,dirty:e.dirty,isVariableDef:e.isVariableDef,isEmpty:e.isEmpty,hasBytecode:e.bytecodes.length>0,hasResult:e.results.length>0,inlineSolveCount:e.inlineSolveCount,reads:e.reads,writes:e.writes}))}}};var A=class{constructor(){this.worker=null;this.nextId=1;this.pending=new Map;}ensureWorker(){return this.worker?this.worker:(this.worker=g(),this.worker.onmessage=e=>{let t=e.data;if(!t||t.type!=="COMPILE_RESULT")return;let n=this.pending.get(t.id);if(!n)return;this.pending.delete(t.id);let r=[];for(let s of t.results)r.push(this.reconstructResult(s));n.resolve(r);},this.worker.onerror=e=>{for(let[t,n]of this.pending)n.reject(new Error(`Compilation worker error: ${e.message}`)),this.pending.delete(t);},this.worker)}async compileBatch(e){if(e.length===0)return [];let t=this.ensureWorker(),n=this.nextId++;return new Promise((r,s)=>{this.pending.set(n,{resolve:r,reject:s}),t.postMessage({type:"COMPILE_BATCH",id:n,items:e});})}storeResults(e,t){let n=new Map;for(let i of e){if(i.error)continue;let a=t.getLineById(i.lineId);if(!a||a.textHash!==i.compiledAgainstHash)continue;let l=n.get(i.lineId);l||(l={bytecodes:[],reads:new Set,writes:new Set,isVariableDef:false,expressions:a.expressions.length>0?[...a.expressions]:[],textHash:i.compiledAgainstHash},n.set(i.lineId,l)),l.bytecodes.push(i.program);for(let o of i.reads)l.reads.add(o);for(let o of i.writes)l.writes.add(o);i.isVariableDef&&(l.isVariableDef=true);}let s=0;for(let[i,a]of n){if(a.bytecodes.length===0)continue;let o=t.getLineById(i)?.inlineSolveCount??0;t.updateLineCompiled(i,a.expressions,a.bytecodes,[...a.reads],[...a.writes],a.isVariableDef,o),s+=a.bytecodes.length;}return s}terminate(){this.worker&&(this.worker.terminate(),this.worker=null,this.pending.clear());}get isActive(){return this.worker!==null}reconstructResult(e){if(e.error)return {lineId:e.lineId,compiledAgainstHash:e.compiledAgainstHash,program:{opcodes:new Uint8Array(0),numbers:new Float64Array(0),strings:[],hasAsync:false},reads:[],writes:[],isVariableDef:false,error:e.error};let t=e.opcodesLength>0?new Uint8Array(e.opcodesBuffer,0,e.opcodesLength):new Uint8Array(0),n=e.numbersLength>0?new Float64Array(e.numbersBuffer,0,e.numbersLength):new Float64Array(0),r={opcodes:t,numbers:n,strings:e.strings,hasAsync:false};return {lineId:e.lineId,compiledAgainstHash:e.compiledAgainstHash,program:r,reads:e.reads,writes:e.writes,isVariableDef:e.isVariableDef,error:null}}};var U=128,k=3,Z=6,Q=2,X=k,H=class u{constructor(){this.lastViewportStart=null;this.savedDirection=null;this.pageAccess=new Map;this.accessSeq=0;}static pageForLine(e){return Math.floor((e-1)/U)}static pageRange(e,t){return {startLine:e*U+1,endLine:Math.min((e+1)*U,t)}}detectDirection(e){return this.lastViewportStart===null?null:e.startLine>this.lastViewportStart?"down":e.startLine<this.lastViewportStart?"up":null}maintainAfterEval(e,t){this.savedDirection=this.detectDirection(e),this.lastViewportStart=e.startLine;let n=t.lineCount,r=u.pageForLine(e.startLine),s=u.pageForLine(e.endLine),i=u.pageForLine(n),a=Math.max(0,r-k),l=Math.min(i,s+k),o=Math.max(0,r-Z),c=Math.min(i,s+Z);for(let h=a;h<=l;h++)this.touchPage(h);for(let h=o;h<=c;h++)h>=a&&h<=l||this.evictPageResults(h,t,n);let d=o-1,p=Math.max(0,d-X+1);for(let h=p;h<=d;h++)this.evictPageBytecode(h,t,n);let f=c+1,g=Math.min(i,f+X-1);for(let h=f;h<=g;h++)this.evictPageBytecode(h,t,n);}getPreloadTargets(e,t){let n=this.savedDirection;if(!n)return [];let r=[],s=u.pageForLine(e.endLine),i=u.pageForLine(e.startLine),a=u.pageForLine(t.lineCount),l=[];if(n==="down"){let o=s+k+1,c=Math.min(o+Q-1,a);for(let d=o;d<=c&&d<=a;d++)l.push(d);}else {let o=i-k-1;for(let c=o;c>o-Q&&c>=0;c--)l.push(c);}for(let o of l){let c=u.pageRange(o,t.lineCount);for(let d=c.startLine;d<=c.endLine;d++){let p=t.getLineAt(d);if(p&&p.dirty&&!(p.bytecodes.length>0&&!p.isVariableDef)&&!p.isEmpty)if(p.expressions.length>0)for(let f of p.expressions)f.trim()&&r.push({lineId:p.lineId,expression:f,textHash:p.textHash});else {let f=c$1.findInlineSolves(p.text);if(f.length>0)for(let g of f)g.expression.trim()&&r.push({lineId:p.lineId,expression:g.expression,textHash:p.textHash});else {let g=p.text.trim();g&&r.push({lineId:p.lineId,expression:g,textHash:p.textHash});}}}}return r}clear(){this.pageAccess.clear(),this.accessSeq=0,this.lastViewportStart=null,this.savedDirection=null;}touchPage(e){this.pageAccess.set(e,++this.accessSeq);}evictPageResults(e,t,n){let r=u.pageRange(e,n);for(let s=r.startLine;s<=r.endLine;s++){let i=t.getLineAt(s);i&&!i.isVariableDef&&i.results.length>0&&(i.results=[],i.result=null);}}evictPageBytecode(e,t,n){let r=u.pageRange(e,n);for(let s=r.startLine;s<=r.endLine;s++){let i=t.getLineAt(s);!i||i.isVariableDef||(i.bytecodes.length>0||i.results.length>0)&&(i.bytecodes=[],i.results=[],i.result=null,t.markDirty(i.lineId));}}};var Y=(r=>(r[r.Tier1=1]="Tier1",r[r.Tier2=2]="Tier2",r[r.Tier3=3]="Tier3",r[r.Skipped=0]="Skipped",r))(Y||{}),w=class{constructor(e,t,n){this.compilationWorker=null;this.globalUnsubscribe=null;this.doc=e,this.engine=t,this.dag=t.getDag(),this.checkpointer=n??null,this.pageManager=new H,this.engine.setDocumentModel(this.doc),this.globalUnsubscribe=J.subscribe(r=>{for(let s of this.dag.getAffectedLines(K(r)))this.doc.markDirtyByLineNumber(s);});}evaluate(e,t){this.engine.setKeystrokeSignal(t??null),h();try{this.reseedAccumulators();let n=[],r=new Map,s={tier1:0,tier2:0,tier3:0,skipped:0},i=this.doc.lineCount,a=Math.min(e.endLine,i);for(let l=1;l<=a;l++){let o=this.doc.getLineAt(l);if(!o){s.skipped++;continue}let c=l>=e.startLine&&l<=e.endLine,d=this.evaluateSingleLine(o,l,c);n.push(d),d.tier===1?s.tier1++:d.tier===2?s.tier2++:d.tier===3?s.tier3++:s.skipped++,d.results&&c&&r.set(l,d.results.flat());}return this.pageManager.maintainAfterEval(e,this.doc),{lines:n,resultMap:r,tierCounts:s}}finally{this.engine.setKeystrokeSignal(null),i();}}backgroundCompile(e){let t=[],n=this.doc.lineCount,r=e.endLine+1;for(let s=r;s<=n;s++){let i=this.doc.getLineAt(s);if(!i||!i.dirty||i.bytecodes.length>0&&!i.isVariableDef)continue;let a=this.evaluateSingleLine(i,s,false);t.push(a);}return t}dispatchBackgroundCompiles(e){let t=this.collectInvisibleCompileTargets(e);t.length!==0&&(this.compilationWorker||(this.compilationWorker=new A),this.compilationWorker.compileBatch(t).then(n=>{this.compilationWorker.storeResults(n,this.doc);}).catch(n=>{}));}terminateWorker(){this.compilationWorker&&(this.compilationWorker.terminate(),this.compilationWorker=null),this.globalUnsubscribe&&(this.globalUnsubscribe(),this.globalUnsubscribe=null);}getDoc(){return this.doc}evaluateAll(e){let t={startLine:1,endLine:this.doc.lineCount};return this.evaluate(t,e)}setViewport(e,t){if(this.engine.setKeystrokeSignal(t??null),e.startLine>1&&this.hasDirtyLinesBefore(e.startLine))return this.checkpointer?.clear(),this.evaluate(e,t);this.pageManager.maintainAfterEval(e,this.doc),this.preloadNextPages(e),this.restoreTo(e.startLine-1),h();try{return this.collectEvalResults(e.startLine,e.endLine)}finally{this.engine.setKeystrokeSignal(null),i();}}applyTransaction(e){let t=new Set;for(let s of e)for(let i=0;i<s.deleteCount;i++){let a=s.startLine+i,l=this.dag.getWrites(a);for(let o of l)t.add(o);this.dag.removeLine(a),this.engine.getLineCache().removeAllForLine(a);}let n=new Set;for(let s of t){let i=this.dag.getAffectedLines(s);for(let a of i){let l=this.doc.getLineAt(a);l&&n.add(l.lineId);}}let r=this.doc.applyChanges(e);this.checkpointer?.clear();for(let s of n)this.doc.markDirty(s);return this.dag.clear(),{inserted:r.inserted,removed:r.removed}}reseedAccumulators(){let e=this.engine.resetAccumulators();if(e.size===0)return;let t=this.doc.lineCount;for(let n=1;n<=t;n++){let r=this.dag.getWrites(n);if(r.size!==0){for(let s of r)if(e.has(s)){this.doc.markDirtyByLineNumber(n);break}}}}collectEvalResults(e,t){let n=[],r=new Map,s={tier1:0,tier2:0,tier3:0,skipped:0},i=this.doc.lineCount,a=Math.min(t,i);for(let l=e;l<=a;l++){let o=this.doc.getLineAt(l);if(!o)continue;let c=this.evaluateSingleLine(o,l,true);n.push(c),c.tier===1?s.tier1++:c.tier===2?s.tier2++:c.tier===3?s.tier3++:s.skipped++,c.results&&r.set(l,c.results.flat());}return {lines:n,resultMap:r,tierCounts:s}}hasDirtyLinesBefore(e){return this.doc.hasAnyDirtyVariableDefLineBefore(e)}evaluateSingleLine(e,t,n){let r={lineId:e.lineId,lineNumber:t};if(e.isEmpty||l(e.text))return e.isEmpty=true,this.doc.markClean(e.lineId),{...r,tier:0,result:null,error:null};let{expressions:s,inlineSolveCount:i}=this.extractExpressions(e);return s.length===0?(e.isEmpty=true,this.doc.markClean(e.lineId),{...r,tier:0,result:null,error:null}):e.dirty?n?this.evaluateTier1(e,t,s,i,r):e.bytecodes.length>0&&e.bytecodes.length===s.length&&!e.isVariableDef?{...r,tier:0,result:null,error:null}:this.evaluateTier3(e,t,s,i,r):n&&e.bytecodes.length>0?this.evaluateTier2(e,t,r):{...r,tier:0,result:null,error:null}}evaluateTier1(e,t,n,r,s){let i=[],a=[],l=new Set,o=new Set,c=false,d=null,p=null,f=false,g=false;for(let y of n){if(!y.trim())continue;let b=null,L;try{let m=this.engine.evaluateLine(t,y);b=[m],d=m,L=this.engine.getLineCache().get(t,y);}catch(m){let x=m instanceof Error?m.message:String(m);p||(p=x),f=true,b=null;}if(b&&b.some(m=>m.type===12)&&(g=true),b?i.push(b):i.push([N("eval_failed",p??"unknown error")]),L){a.push(L.bytecode);for(let m of L.readVariables)l.add(m);L.writeVariable&&(o.add(L.writeVariable),c=true);}else try{let{program:m,reads:x,writes:E}=this.engine.compileExpression(y);a.push(m);for(let S of x)l.add(S);for(let S of E)o.add(S);E.length>0&&(c=!0);}catch(m){if(a.push({opcodes:new Uint8Array(0),numbers:new Float64Array(0),strings:[],hasAsync:false}),m instanceof b$2&&m.context){let x=m.context.reads,E=m.context.writes;if(Array.isArray(x))for(let S of x)l.add(S);if(Array.isArray(E))for(let S of E)o.add(S);}}}let h=[...l],v=[...o];return f||g?(this.doc.updateLineCompiled(e.lineId,n,a,h,v,c,r),e.results=i,e.result=i[0]?.[0]??null,e.inlineSolveCount=r,e.expressions=n):this.doc.updateLineResult(e.lineId,i,a,n,h,v,c,r),this.dag.registerLine(t,h,v),this.checkpointer&&v.length>0&&!f&&!g&&this.checkpointer.snapshot(t,e.lineId,v),{...s,tier:1,result:d,results:i,error:p}}evaluateTier2(e,t,n){if(e.bytecodes.length===0)return {...n,tier:0,result:null,error:null};let r=[],s=null,i=null,a=false;for(let l of e.bytecodes)if(l.opcodes.length!==0)try{let o=this.engine.executeCached(l,t);s=o,r.push([o]);}catch(o){let c=o instanceof Error?o.message:String(o);i||(i=c),a=true,r.push([N("exec_failed",c)]);}return this.dag.registerLine(t,e.reads,e.writes),e.results=r,e.result=r[0]?.[0]??null,a&&this.doc.markDirty(e.lineId),{...n,tier:2,result:s,results:r,error:i}}evaluateTier3(e,t,n,r,s){let i=[],a=new Set,l=new Set,o=false,c=null,d=null,p=false,f=false;for(let v of n)if(v.trim())try{let{program:y,reads:b,writes:L}=this.engine.compileExpression(v);i.push(y);for(let m of b)a.add(m);for(let m of L)l.add(m);L.length>0&&(o=!0),L.length>0&&y.opcodes.length>0&&(c=this.engine.executeCached(y,t),c&&c.type===12&&(f=!0));}catch(y){let b=y instanceof Error?y.message:String(y);d||(d=b),p=true,i.push({opcodes:new Uint8Array(0),numbers:new Float64Array(0),strings:[],hasAsync:false});}let g=[...a],h=[...l];return this.doc.updateLineCompiled(e.lineId,n,i,g,h,o,r),this.dag.registerLine(t,g,h),o&&c&&!p&&!f&&(e.results=[[c]],e.result=c,this.doc.markClean(e.lineId),this.checkpointer&&this.checkpointer.snapshot(t,e.lineId,h)),{...s,tier:3,result:c,results:o&&c&&!p&&!f?[[c]]:void 0,error:d}}restoreTo(e){this.checkpointer&&this.checkpointer.restoreTo(e);}getCheckpointer(){return this.checkpointer}getPageManager(){return this.pageManager}preloadNextPages(e){let t=this.pageManager.getPreloadTargets(e,this.doc);t.length!==0&&(this.compilationWorker||(this.compilationWorker=new A),this.compilationWorker.compileBatch(t).then(n=>{this.compilationWorker.storeResults(n,this.doc);}).catch(n=>{}));}collectInvisibleCompileTargets(e){let t=[],n=this.doc.lineCount,r=e.endLine+1;for(let s=r;s<=n;s++){let i=this.doc.getLineAt(s);if(!i||!i.dirty||i.bytecodes.length>0&&!i.isVariableDef||i.isEmpty||l(i.text))continue;let{expressions:a}=this.extractExpressions(i);if(a.length!==0)for(let l of a)l.trim()&&t.push({lineId:i.lineId,expression:l,textHash:i.textHash});}return t}extractExpressions(e){if(e.expressions.length>0)return {expressions:e.expressions,inlineSolveCount:e.inlineSolveCount};let t=e.text.trim();if(t.length===0)return {expressions:[],inlineSolveCount:0};let n=c$1.findInlineSolves(e.text);return n.length>0?{expressions:n.map(r=>r.expression),inlineSolveCount:n.length}:{expressions:[t],inlineSolveCount:0}}};function ee(u){return typeof u.unit=="string"?u.unit:String(u.value)}function ie(u,e,t={inputType:"markdown"}){let n=u.getDocumentModel(),r=new R;r.setDocument(e);let s=new w(r,u);try{let i=r.lineCount;s.evaluate({startLine:1,endLine:i});let a=[],l=[],o=0;for(let c=1;c<=i;c++){let d=r.getLineAt(c),p=d.text,f=o,g=o+p.length;o=g+1;let h=d.inlineSolveCount>0,v=[],y=null,b=null;d.isEmpty||(h?v=m(p,c).map((L,m)=>{let x=d.results[m]?.[0]??null;if(x&&x.type===13){let E=ee(x);return l.push(`Line ${c}: ${E}`),{...L,result:null,error:E}}return {...L,result:x,error:null}}):(y=d.expressions[0]??null,b=d.result??null,b&&b.type===13&&l.push(`Line ${c}: ${ee(b)}`))),a.push({lineNumber:c,text:p,startPosition:f,endPosition:g,isEmpty:d.isEmpty,hasInlineSolves:h,inlineSolves:v,expression:y,error:null,result:b});}return {lines:a,totalLines:i,errors:l}}finally{s.terminateWorker(),u.setDocumentModel(n);}}export{R as a,Y as b,w as c,ie as d};//# sourceMappingURL=chunk-RDMJNRDO.js.map
|
|
3
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import {a}from'./chunk-RAF57WYO.js';import {l,m,g}from'./chunk-HF4H7LYA.js';import {b as b$1}from'./chunk-76F3LCIL.js';import {J,K}from'./chunk-HTJPV42D.js';import {h,i,P as P$1}from'./chunk-A33K7NY4.js';import {b}from'./chunk-CVY2A3TP.js';import {c as c$1}from'./chunk-YAHGSBMC.js';import {c,b as b$2}from'./chunk-MPB7KUN5.js';var P=class{constructor(){this.root=null;}get length(){return this.root?this.root.size:0}get isEmpty(){return this.root===null}getAt(e){if(!(e<0||e>=(this.root?.size??0)))return this.nodeAt(this.root,e).lineId}insertAt(e,t){let[n,r]=I(this.root,e);this.root=C(C(n,te(t)),r);}deleteAt(e){if(e<0||e>=(this.root?.size??0))return;let[t,n]=I(this.root,e),[r,s]=I(n,1),i=r?r.lineId:void 0;return this.root=C(t,s),i}spliceAt(e,t,n){let r=Math.max(0,e),s=Math.min(Math.max(0,t),(this.root?.size??0)-r),[i,a]=I(this.root,r),[l,o]=I(a,s),c=ne(l),d=B(n,0,n.length);return this.root=C(C(i,d),o),c}replaceAll(e){this.root=B(e,0,e.length);}getRange(e,t){let n=Math.max(0,e),r=Math.min((this.root?.size??0)-1,t);if(n>r)return [];let s=[];return this.collectRange(this.root,n,r,0,s),s}clear(){this.root=null;}*[Symbol.iterator](){yield*this.inOrder(this.root);}*inOrder(e){e&&(yield*this.inOrder(e.left),yield e.lineId,yield*this.inOrder(e.right));}nodeAt(e,t){let n=e.left?e.left.size:0;return t<n?this.nodeAt(e.left,t):t===n?e:this.nodeAt(e.right,t-n-1)}collectRange(e,t,n,r,s){if(!e)return;let i=e.left?e.left.size:0,a=r+i;a>t&&e.left&&this.collectRange(e.left,t,n,r,s),a>=t&&a<=n&&s.push(e.lineId),a<n&&e.right&&this.collectRange(e.right,t,n,a+1,s);}};function te(u){return {lineId:u,size:1,priority:Math.random(),left:null,right:null}}function T(u){u.size=1+(u.left?u.left.size:0)+(u.right?u.right.size:0);}function C(u,e){return u?e?u.priority>e.priority?(u.right=C(u.right,e),T(u),u):(e.left=C(u,e.left),T(e),e):u:e}function I(u,e){if(!u)return [null,null];let t=u.left?u.left.size:0;if(e<=t){let[n,r]=I(u.left,e);return u.left=r,T(u),[n,u]}else {let[n,r]=I(u.right,e-t-1);return u.right=n,T(u),[u,r]}}function ne(u){let e=[];return F(u,e),e}function F(u,e){u&&(F(u.left,e),e.push(u.lineId),F(u.right,e));}function B(u,e,t){if(e>=t)return null;let n=Math.floor((e+t)/2),r=re(n);return {lineId:u[n],size:t-e,priority:r,left:B(u,e,n),right:B(u,n+1,t)}}function re(u){let e=u;return e=(e>>16^e)*73244475,e=(e>>16^e)*73244475,e=e>>16^e,e/4294967295}var R=class{constructor(e=b.performance.maxDocumentLines){this.lines=new Map;this.orderTree=new P;this.nextLineId=1;this._positionCache=null;this.dirtyLineIds=new Set;this.maxLines=e;}setDocument(e){if(b$1(e,this.maxLines)>this.maxLines)throw c.execution("DOCUMENT_TOO_LARGE",`This document has more than ${this.maxLines.toLocaleString("en-US")} lines, which is the most the engine will hold at once`,{maxLines:this.maxLines});this.lines.clear(),this.orderTree.clear(),this._positionCache=null,this.dirtyLineIds.clear(),this.nextLineId=1;let n=e.split(`
|
|
2
|
+
`),r=new Array(n.length);for(let s=0;s<n.length;s++){let i=this.nextLineId++;r[s]=i,this.lines.set(i,{lineId:i,textHash:a(n[s]),text:n[s],expressions:[],bytecodes:[],reads:[],writes:[],results:[],result:null,dirty:true,isVariableDef:false,isEmpty:n[s].trim().length===0,inlineSolveCount:0});}this.orderTree.replaceAll(r);for(let s of r)this.dirtyLineIds.add(s);}applyChanges(e){let t=[],n=[],r=[...e].sort((s,i)=>i.startLine-s.startLine);for(let s of r){let i=s.startLine-1,a$1=[];for(let o of s.insertLines){let c=this.nextLineId++;a$1.push(c),t.push(c),this.lines.set(c,{lineId:c,textHash:a(o),text:o,expressions:[],bytecodes:[],reads:[],writes:[],results:[],result:null,dirty:true,isVariableDef:false,isEmpty:o.trim().length===0,inlineSolveCount:0});}for(let o of a$1)this.dirtyLineIds.add(o);let l=this.orderTree.spliceAt(i,s.deleteCount,a$1);for(let o of l)n.push(o),this.lines.delete(o),this.dirtyLineIds.delete(o);}return this._positionCache=null,{inserted:t,removed:n}}insertLines(e,t){let n={startLine:e,deleteCount:0,insertLines:t};return this.applyChanges([n]).inserted}deleteLines(e,t){let n={startLine:e,deleteCount:t-e+1,insertLines:[]};return this.applyChanges([n]).removed}editLine(e,t){let n=this.getLineAt(e);if(!n)return false;let r=a(t);return r===n.textHash?false:(n.text=t,n.textHash=r,n.expressions=[],n.bytecodes=[],n.results=[],n.result=null,n.inlineSolveCount=0,n.dirty=true,this.dirtyLineIds.add(n.lineId),n.isEmpty=t.trim().length===0,true)}getLineAt(e){let t=e-1,n=this.orderTree.getAt(t);if(n!==void 0)return this.lines.get(n)}getLinePosition(e){if(this._positionCache)return this._positionCache.get(e)??-1;this._positionCache=new Map;let t=1;for(let n of this.orderTree)this._positionCache.set(n,t++);return this._positionCache.get(e)??-1}getVisibleLines(e,t){let n=this.orderTree.getRange(e-1,t-1),r=[];for(let s of n){let i=this.lines.get(s);i&&r.push(i);}return r}getAllLines(){return this.getVisibleLines(1,this.lineCount)}getLineById(e){return this.lines.get(e)}getDirtyLines(){let e=[];for(let t of this.lines.values())t.dirty&&e.push(t);return e}hasAnyDirtyLineBefore(e){for(let t of this.dirtyLineIds){let n=this.getLinePosition(t);if(n>=1&&n<e)return true}return false}hasAnyDirtyVariableDefLineBefore(e){for(let t of this.dirtyLineIds){let n=this.lines.get(t);if(!n||!n.isVariableDef)continue;let r=this.getLinePosition(t);if(r>=1&&r<e)return true}return false}get dirtyCount(){return this.dirtyLineIds.size}isBytecodeValid(e,t){let n=this.lines.get(e);return n!==void 0&&n.textHash===t}markClean(e){let t=this.lines.get(e);t&&(t.dirty=false,this.dirtyLineIds.delete(e));}markDirtyByLineNumber(e){let t=this.getLineAt(e);t&&(t.dirty=true,this.dirtyLineIds.add(t.lineId));}markDirty(e){let t=this.lines.get(e);t&&(t.dirty=true,this.dirtyLineIds.add(e));}invalidateAll(){for(let e of this.lines.values())e.dirty=true;this.dirtyLineIds=new Set(this.lines.keys());}updateLineResult(e,t,n,r,s,i,a,l=0){let o=this.lines.get(e);o&&(o.results=t,o.result=t[0]?.[0]??null,o.bytecodes=n,o.expressions=r,o.reads=s,o.writes=i,o.isVariableDef=a,o.inlineSolveCount=l,o.dirty=false,this.dirtyLineIds.delete(e));}updateLineCompiled(e,t,n,r,s,i,a=0){let l=this.lines.get(e);l&&(l.expressions=t,l.bytecodes=n,l.reads=r,l.writes=s,l.isVariableDef=i,l.inlineSolveCount=a);}get lineCount(){return this.orderTree.length}get isEmpty(){return this.orderTree.isEmpty}*[Symbol.iterator](){for(let e of this.orderTree){let t=this.lines.get(e);t&&(yield t);}}clear(){this.lines.clear(),this.orderTree.clear(),this._positionCache=null,this.nextLineId=1;}toJSON(){return {lineCount:this.lineCount,lines:this.getAllLines().map(e=>({lineId:e.lineId,text:e.text.substring(0,80),textHash:e.textHash,dirty:e.dirty,isVariableDef:e.isVariableDef,isEmpty:e.isEmpty,hasBytecode:e.bytecodes.length>0,hasResult:e.results.length>0,inlineSolveCount:e.inlineSolveCount,reads:e.reads,writes:e.writes}))}}};var A=class{constructor(){this.worker=null;this.nextId=1;this.pending=new Map;}ensureWorker(){return this.worker?this.worker:(this.worker=g(),this.worker.onmessage=e=>{let t=e.data;if(!t||t.type!=="COMPILE_RESULT")return;let n=this.pending.get(t.id);if(!n)return;this.pending.delete(t.id);let r=[];for(let s of t.results)r.push(this.reconstructResult(s));n.resolve(r);},this.worker.onerror=e=>{for(let[t,n]of this.pending)n.reject(new Error(`Compilation worker error: ${e.message}`)),this.pending.delete(t);},this.worker)}async compileBatch(e){if(e.length===0)return [];let t=this.ensureWorker(),n=this.nextId++;return new Promise((r,s)=>{this.pending.set(n,{resolve:r,reject:s}),t.postMessage({type:"COMPILE_BATCH",id:n,items:e});})}storeResults(e,t){let n=new Map;for(let i of e){if(i.error)continue;let a=t.getLineById(i.lineId);if(!a||a.textHash!==i.compiledAgainstHash)continue;let l=n.get(i.lineId);l||(l={bytecodes:[],reads:new Set,writes:new Set,isVariableDef:false,expressions:a.expressions.length>0?[...a.expressions]:[],textHash:i.compiledAgainstHash},n.set(i.lineId,l)),l.bytecodes.push(i.program);for(let o of i.reads)l.reads.add(o);for(let o of i.writes)l.writes.add(o);i.isVariableDef&&(l.isVariableDef=true);}let s=0;for(let[i,a]of n){if(a.bytecodes.length===0)continue;let o=t.getLineById(i)?.inlineSolveCount??0;t.updateLineCompiled(i,a.expressions,a.bytecodes,[...a.reads],[...a.writes],a.isVariableDef,o),s+=a.bytecodes.length;}return s}terminate(){this.worker&&(this.worker.terminate(),this.worker=null,this.pending.clear());}get isActive(){return this.worker!==null}reconstructResult(e){if(e.error)return {lineId:e.lineId,compiledAgainstHash:e.compiledAgainstHash,program:{opcodes:new Uint8Array(0),numbers:new Float64Array(0),strings:[],hasAsync:false},reads:[],writes:[],isVariableDef:false,error:e.error};let t=e.opcodesLength>0?new Uint8Array(e.opcodesBuffer,0,e.opcodesLength):new Uint8Array(0),n=e.numbersLength>0?new Float64Array(e.numbersBuffer,0,e.numbersLength):new Float64Array(0),r={opcodes:t,numbers:n,strings:e.strings,hasAsync:false};return {lineId:e.lineId,compiledAgainstHash:e.compiledAgainstHash,program:r,reads:e.reads,writes:e.writes,isVariableDef:e.isVariableDef,error:null}}};var U=128,k=3,Z=6,Q=2,X=k,H=class u{constructor(){this.lastViewportStart=null;this.savedDirection=null;this.pageAccess=new Map;this.accessSeq=0;}static pageForLine(e){return Math.floor((e-1)/U)}static pageRange(e,t){return {startLine:e*U+1,endLine:Math.min((e+1)*U,t)}}detectDirection(e){return this.lastViewportStart===null?null:e.startLine>this.lastViewportStart?"down":e.startLine<this.lastViewportStart?"up":null}maintainAfterEval(e,t){this.savedDirection=this.detectDirection(e),this.lastViewportStart=e.startLine;let n=t.lineCount,r=u.pageForLine(e.startLine),s=u.pageForLine(e.endLine),i=u.pageForLine(n),a=Math.max(0,r-k),l=Math.min(i,s+k),o=Math.max(0,r-Z),c=Math.min(i,s+Z);for(let h=a;h<=l;h++)this.touchPage(h);for(let h=o;h<=c;h++)h>=a&&h<=l||this.evictPageResults(h,t,n);let d=o-1,p=Math.max(0,d-X+1);for(let h=p;h<=d;h++)this.evictPageBytecode(h,t,n);let f=c+1,g=Math.min(i,f+X-1);for(let h=f;h<=g;h++)this.evictPageBytecode(h,t,n);}getPreloadTargets(e,t){let n=this.savedDirection;if(!n)return [];let r=[],s=u.pageForLine(e.endLine),i=u.pageForLine(e.startLine),a=u.pageForLine(t.lineCount),l=[];if(n==="down"){let o=s+k+1,c=Math.min(o+Q-1,a);for(let d=o;d<=c&&d<=a;d++)l.push(d);}else {let o=i-k-1;for(let c=o;c>o-Q&&c>=0;c--)l.push(c);}for(let o of l){let c=u.pageRange(o,t.lineCount);for(let d=c.startLine;d<=c.endLine;d++){let p=t.getLineAt(d);if(p&&p.dirty&&!(p.bytecodes.length>0&&!p.isVariableDef)&&!p.isEmpty)if(p.expressions.length>0)for(let f of p.expressions)f.trim()&&r.push({lineId:p.lineId,expression:f,textHash:p.textHash});else {let f=c$1.findInlineSolves(p.text);if(f.length>0)for(let g of f)g.expression.trim()&&r.push({lineId:p.lineId,expression:g.expression,textHash:p.textHash});else {let g=p.text.trim();g&&r.push({lineId:p.lineId,expression:g,textHash:p.textHash});}}}}return r}clear(){this.pageAccess.clear(),this.accessSeq=0,this.lastViewportStart=null,this.savedDirection=null;}touchPage(e){this.pageAccess.set(e,++this.accessSeq);}evictPageResults(e,t,n){let r=u.pageRange(e,n);for(let s=r.startLine;s<=r.endLine;s++){let i=t.getLineAt(s);i&&!i.isVariableDef&&i.results.length>0&&(i.results=[],i.result=null);}}evictPageBytecode(e,t,n){let r=u.pageRange(e,n);for(let s=r.startLine;s<=r.endLine;s++){let i=t.getLineAt(s);!i||i.isVariableDef||(i.bytecodes.length>0||i.results.length>0)&&(i.bytecodes=[],i.results=[],i.result=null,t.markDirty(i.lineId));}}};var Y=(r=>(r[r.Tier1=1]="Tier1",r[r.Tier2=2]="Tier2",r[r.Tier3=3]="Tier3",r[r.Skipped=0]="Skipped",r))(Y||{}),w=class{constructor(e,t,n){this.compilationWorker=null;this.globalUnsubscribe=null;this.doc=e,this.engine=t,this.dag=t.getDag(),this.checkpointer=n??null,this.pageManager=new H,this.engine.setDocumentModel(this.doc),this.globalUnsubscribe=J.subscribe(r=>{for(let s of this.dag.getAffectedLines(K(r)))this.doc.markDirtyByLineNumber(s);});}evaluate(e,t){this.engine.setKeystrokeSignal(t??null),h();try{this.reseedAccumulators();let n=[],r=new Map,s={tier1:0,tier2:0,tier3:0,skipped:0},i=this.doc.lineCount,a=Math.min(e.endLine,i);for(let l=1;l<=a;l++){let o=this.doc.getLineAt(l);if(!o){s.skipped++;continue}let c=l>=e.startLine&&l<=e.endLine,d=this.evaluateSingleLine(o,l,c);n.push(d),d.tier===1?s.tier1++:d.tier===2?s.tier2++:d.tier===3?s.tier3++:s.skipped++,d.results&&c&&r.set(l,d.results.flat());}return this.pageManager.maintainAfterEval(e,this.doc),{lines:n,resultMap:r,tierCounts:s}}finally{this.engine.setKeystrokeSignal(null),i();}}backgroundCompile(e){let t=[],n=this.doc.lineCount,r=e.endLine+1;for(let s=r;s<=n;s++){let i=this.doc.getLineAt(s);if(!i||!i.dirty||i.bytecodes.length>0&&!i.isVariableDef)continue;let a=this.evaluateSingleLine(i,s,false);t.push(a);}return t}dispatchBackgroundCompiles(e){let t=this.collectInvisibleCompileTargets(e);t.length!==0&&(this.compilationWorker||(this.compilationWorker=new A),this.compilationWorker.compileBatch(t).then(n=>{this.compilationWorker.storeResults(n,this.doc);}).catch(n=>{}));}terminateWorker(){this.compilationWorker&&(this.compilationWorker.terminate(),this.compilationWorker=null),this.globalUnsubscribe&&(this.globalUnsubscribe(),this.globalUnsubscribe=null);}getDoc(){return this.doc}evaluateAll(e){let t={startLine:1,endLine:this.doc.lineCount};return this.evaluate(t,e)}setViewport(e,t){if(this.engine.setKeystrokeSignal(t??null),e.startLine>1&&this.hasDirtyLinesBefore(e.startLine))return this.checkpointer?.clear(),this.evaluate(e,t);this.pageManager.maintainAfterEval(e,this.doc),this.preloadNextPages(e),this.restoreTo(e.startLine-1),h();try{return this.collectEvalResults(e.startLine,e.endLine)}finally{this.engine.setKeystrokeSignal(null),i();}}applyTransaction(e){let t=new Set;for(let s of e)for(let i=0;i<s.deleteCount;i++){let a=s.startLine+i,l=this.dag.getWrites(a);for(let o of l)t.add(o);this.dag.removeLine(a),this.engine.getLineCache().removeAllForLine(a);}let n=new Set;for(let s of t){let i=this.dag.getAffectedLines(s);for(let a of i){let l=this.doc.getLineAt(a);l&&n.add(l.lineId);}}let r=this.doc.applyChanges(e);this.checkpointer?.clear();for(let s of n)this.doc.markDirty(s);return this.dag.clear(),{inserted:r.inserted,removed:r.removed}}reseedAccumulators(){let e=this.engine.resetAccumulators();if(e.size===0)return;let t=this.doc.lineCount;for(let n=1;n<=t;n++){let r=this.dag.getWrites(n);if(r.size!==0){for(let s of r)if(e.has(s)){this.doc.markDirtyByLineNumber(n);break}}}}collectEvalResults(e,t){let n=[],r=new Map,s={tier1:0,tier2:0,tier3:0,skipped:0},i=this.doc.lineCount,a=Math.min(t,i);for(let l=e;l<=a;l++){let o=this.doc.getLineAt(l);if(!o)continue;let c=this.evaluateSingleLine(o,l,true);n.push(c),c.tier===1?s.tier1++:c.tier===2?s.tier2++:c.tier===3?s.tier3++:s.skipped++,c.results&&r.set(l,c.results.flat());}return {lines:n,resultMap:r,tierCounts:s}}hasDirtyLinesBefore(e){return this.doc.hasAnyDirtyVariableDefLineBefore(e)}evaluateSingleLine(e,t,n){let r={lineId:e.lineId,lineNumber:t};if(e.isEmpty||l(e.text))return e.isEmpty=true,this.doc.markClean(e.lineId),{...r,tier:0,result:null,error:null};let{expressions:s,inlineSolveCount:i}=this.extractExpressions(e);return s.length===0?(e.isEmpty=true,this.doc.markClean(e.lineId),{...r,tier:0,result:null,error:null}):e.dirty?n?this.evaluateTier1(e,t,s,i,r):e.bytecodes.length>0&&e.bytecodes.length===s.length&&!e.isVariableDef?{...r,tier:0,result:null,error:null}:this.evaluateTier3(e,t,s,i,r):n&&e.bytecodes.length>0?this.evaluateTier2(e,t,r):{...r,tier:0,result:null,error:null}}evaluateTier1(e,t,n,r,s){let i=[],a=[],l=new Set,o=new Set,c=false,d=null,p=null,f=false,g=false;for(let y of n){if(!y.trim())continue;let b=null,L;try{let m=this.engine.evaluateLine(t,y);b=[m],d=m,L=this.engine.getLineCache().get(t,y);}catch(m){let x=m instanceof Error?m.message:String(m);p||(p=x),f=true,b=null;}if(b&&b.some(m=>m.type===12)&&(g=true),b?i.push(b):i.push([P$1("eval_failed",p??"unknown error")]),L){a.push(L.bytecode);for(let m of L.readVariables)l.add(m);L.writeVariable&&(o.add(L.writeVariable),c=true);}else try{let{program:m,reads:x,writes:E}=this.engine.compileExpression(y);a.push(m);for(let S of x)l.add(S);for(let S of E)o.add(S);E.length>0&&(c=!0);}catch(m){if(a.push({opcodes:new Uint8Array(0),numbers:new Float64Array(0),strings:[],hasAsync:false}),m instanceof b$2&&m.context){let x=m.context.reads,E=m.context.writes;if(Array.isArray(x))for(let S of x)l.add(S);if(Array.isArray(E))for(let S of E)o.add(S);}}}let h=[...l],v=[...o];return f||g?(this.doc.updateLineCompiled(e.lineId,n,a,h,v,c,r),e.results=i,e.result=i[0]?.[0]??null,e.inlineSolveCount=r,e.expressions=n):this.doc.updateLineResult(e.lineId,i,a,n,h,v,c,r),this.dag.registerLine(t,h,v),this.checkpointer&&v.length>0&&!f&&!g&&this.checkpointer.snapshot(t,e.lineId,v),{...s,tier:1,result:d,results:i,error:p}}evaluateTier2(e,t,n){if(e.bytecodes.length===0)return {...n,tier:0,result:null,error:null};let r=[],s=null,i=null,a=false;for(let l of e.bytecodes)if(l.opcodes.length!==0)try{let o=this.engine.executeCached(l,t);s=o,r.push([o]);}catch(o){let c=o instanceof Error?o.message:String(o);i||(i=c),a=true,r.push([P$1("exec_failed",c)]);}return this.dag.registerLine(t,e.reads,e.writes),e.results=r,e.result=r[0]?.[0]??null,a&&this.doc.markDirty(e.lineId),{...n,tier:2,result:s,results:r,error:i}}evaluateTier3(e,t,n,r,s){let i=[],a=new Set,l=new Set,o=false,c=null,d=null,p=false,f=false;for(let v of n)if(v.trim())try{let{program:y,reads:b,writes:L}=this.engine.compileExpression(v);i.push(y);for(let m of b)a.add(m);for(let m of L)l.add(m);L.length>0&&(o=!0),L.length>0&&y.opcodes.length>0&&(c=this.engine.executeCached(y,t),c&&c.type===12&&(f=!0));}catch(y){let b=y instanceof Error?y.message:String(y);d||(d=b),p=true,i.push({opcodes:new Uint8Array(0),numbers:new Float64Array(0),strings:[],hasAsync:false});}let g=[...a],h=[...l];return this.doc.updateLineCompiled(e.lineId,n,i,g,h,o,r),this.dag.registerLine(t,g,h),o&&c&&!p&&!f&&(e.results=[[c]],e.result=c,this.doc.markClean(e.lineId),this.checkpointer&&this.checkpointer.snapshot(t,e.lineId,h)),{...s,tier:3,result:c,results:o&&c&&!p&&!f?[[c]]:void 0,error:d}}restoreTo(e){this.checkpointer&&this.checkpointer.restoreTo(e);}getCheckpointer(){return this.checkpointer}getPageManager(){return this.pageManager}preloadNextPages(e){let t=this.pageManager.getPreloadTargets(e,this.doc);t.length!==0&&(this.compilationWorker||(this.compilationWorker=new A),this.compilationWorker.compileBatch(t).then(n=>{this.compilationWorker.storeResults(n,this.doc);}).catch(n=>{}));}collectInvisibleCompileTargets(e){let t=[],n=this.doc.lineCount,r=e.endLine+1;for(let s=r;s<=n;s++){let i=this.doc.getLineAt(s);if(!i||!i.dirty||i.bytecodes.length>0&&!i.isVariableDef||i.isEmpty||l(i.text))continue;let{expressions:a}=this.extractExpressions(i);if(a.length!==0)for(let l of a)l.trim()&&t.push({lineId:i.lineId,expression:l,textHash:i.textHash});}return t}extractExpressions(e){if(e.expressions.length>0)return {expressions:e.expressions,inlineSolveCount:e.inlineSolveCount};let t=e.text.trim();if(t.length===0)return {expressions:[],inlineSolveCount:0};let n=c$1.findInlineSolves(e.text);return n.length>0?{expressions:n.map(r=>r.expression),inlineSolveCount:n.length}:{expressions:[t],inlineSolveCount:0}}};function ee(u){return typeof u.unit=="string"?u.unit:String(u.value)}function ie(u,e,t={inputType:"markdown"}){let n=u.getDocumentModel(),r=new R;r.setDocument(e);let s=new w(r,u);try{let i=r.lineCount;s.evaluate({startLine:1,endLine:i});let a=[],l=[],o=0;for(let c=1;c<=i;c++){let d=r.getLineAt(c),p=d.text,f=o,g=o+p.length;o=g+1;let h=d.inlineSolveCount>0,v=[],y=null,b=null;d.isEmpty||(h?v=m(p,c).map((L,m)=>{let x=d.results[m]?.[0]??null;if(x&&x.type===13){let E=ee(x);return l.push(`Line ${c}: ${E}`),{...L,result:null,error:E}}return {...L,result:x,error:null}}):(y=d.expressions[0]??null,b=d.result??null,b&&b.type===13&&l.push(`Line ${c}: ${ee(b)}`))),a.push({lineNumber:c,text:p,startPosition:f,endPosition:g,isEmpty:d.isEmpty,hasInlineSolves:h,inlineSolves:v,expression:y,error:null,result:b});}return {lines:a,totalLines:i,errors:l}}finally{s.terminateWorker(),u.setDocumentModel(n);}}export{R as a,Y as b,w as c,ie as d};//# sourceMappingURL=chunk-KXM7EY27.js.map
|
|
3
|
+
//# sourceMappingURL=chunk-KXM7EY27.js.map
|