solve-engine 2.38.23 → 2.38.25
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/{chunk-FBXQUQCY.js → chunk-A5OVVFJE.js} +2 -2
- package/dist/{chunk-FBXQUQCY.js.map → chunk-A5OVVFJE.js.map} +1 -1
- package/dist/chunk-ABOVDTHN.cjs +3 -0
- package/dist/chunk-ABOVDTHN.cjs.map +1 -0
- package/dist/{chunk-JVHRND2N.js → chunk-MY3UW5CC.js} +4 -4
- package/dist/chunk-MY3UW5CC.js.map +1 -0
- package/dist/{chunk-GITRBCSD.cjs → chunk-OVC4LAQ4.cjs} +4 -4
- package/dist/chunk-OVC4LAQ4.cjs.map +1 -0
- package/dist/{chunk-OGBLSNQE.cjs → chunk-QKNXCIM3.cjs} +2 -2
- package/dist/{chunk-OGBLSNQE.cjs.map → chunk-QKNXCIM3.cjs.map} +1 -1
- package/dist/chunk-UPQDEN72.js +3 -0
- package/dist/chunk-UPQDEN72.js.map +1 -0
- package/dist/constants.cjs +1 -1
- package/dist/constants.js +1 -1
- package/dist/engine.cjs +1 -1
- package/dist/engine.d.cts +30 -0
- package/dist/engine.d.ts +30 -0
- package/dist/engine.js +1 -1
- package/dist/engine.worker.cjs +1 -1
- package/dist/engine.worker.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/testing.cjs +2 -2
- package/dist/testing.js +1 -1
- package/dist/worker.cjs +2 -2
- package/dist/worker.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-AEGR3GFA.js +0 -3
- package/dist/chunk-AEGR3GFA.js.map +0 -1
- package/dist/chunk-GITRBCSD.cjs.map +0 -1
- package/dist/chunk-JVHRND2N.js.map +0 -1
- package/dist/chunk-UITBYTCD.cjs +0 -3
- package/dist/chunk-UITBYTCD.cjs.map +0 -1
package/dist/engine.d.cts
CHANGED
|
@@ -236,6 +236,18 @@ declare class ThreeTierEvaluator {
|
|
|
236
236
|
* The lines that sit on a cycle, by line id. See {@link settleCycles}.
|
|
237
237
|
*/
|
|
238
238
|
private cycleMemberIds;
|
|
239
|
+
/**
|
|
240
|
+
* The lowest position a structural edit moved, awaiting the next pass, or
|
|
241
|
+
* `MAX_SAFE_INTEGER` when nothing is pending.
|
|
242
|
+
*
|
|
243
|
+
* A structural edit shifts every line from here down to a new position, and
|
|
244
|
+
* the answer such a line still holds was computed for where it used to be.
|
|
245
|
+
* The next pass knows the viewport, so it can clear exactly the stale ones,
|
|
246
|
+
* the moved lines below the range it runs; see
|
|
247
|
+
* {@link forgetMovedBelowViewport}. Recorded rather than acted on at edit
|
|
248
|
+
* time because a moved line ABOVE the range is one a fresh pass still shows.
|
|
249
|
+
*/
|
|
250
|
+
private movedFloor;
|
|
239
251
|
/**
|
|
240
252
|
* Unsubscribe from sharedGlobalVariableStore, set in the constructor
|
|
241
253
|
* called from terminateWorker(). See the subscription itself below for
|
|
@@ -471,6 +483,24 @@ declare class ThreeTierEvaluator {
|
|
|
471
483
|
* @param startLine First line to evaluate (1-based, inclusive).
|
|
472
484
|
* @param endLine Last line to evaluate (1-based, inclusive). Clamped to docEnd.
|
|
473
485
|
*/
|
|
486
|
+
/**
|
|
487
|
+
* Clear the stale answers a structural edit left below the viewport.
|
|
488
|
+
*
|
|
489
|
+
* An insert or a delete moves every line from {@link movedFloor} down to a
|
|
490
|
+
* new position; the answer each still holds was computed for its old one. A
|
|
491
|
+
* moved line inside the range about to run is re-run and gets a fresh answer,
|
|
492
|
+
* and a moved line above it is one a fresh pass driven to this viewport still
|
|
493
|
+
* shows, so both are left alone. A moved line BELOW the range is neither: the
|
|
494
|
+
* pass never reaches it, nothing re-runs it, and a fresh pass shows nothing
|
|
495
|
+
* there, yet the incremental path kept its old answer, which a line reading
|
|
496
|
+
* that position then read back as a real one (#458). Those are cleared here,
|
|
497
|
+
* from just past `evalEnd` (or the earliest move, whichever is lower down) to
|
|
498
|
+
* the end of the document. Consumed once: a later pass over a wider viewport
|
|
499
|
+
* re-runs whichever of them it now covers.
|
|
500
|
+
*
|
|
501
|
+
* @param evalEnd - The last line this pass will run.
|
|
502
|
+
*/
|
|
503
|
+
private forgetMovedBelowViewport;
|
|
474
504
|
private collectEvalResults;
|
|
475
505
|
/**
|
|
476
506
|
* Check whether any **variable-definition** line before `position`
|
package/dist/engine.d.ts
CHANGED
|
@@ -236,6 +236,18 @@ declare class ThreeTierEvaluator {
|
|
|
236
236
|
* The lines that sit on a cycle, by line id. See {@link settleCycles}.
|
|
237
237
|
*/
|
|
238
238
|
private cycleMemberIds;
|
|
239
|
+
/**
|
|
240
|
+
* The lowest position a structural edit moved, awaiting the next pass, or
|
|
241
|
+
* `MAX_SAFE_INTEGER` when nothing is pending.
|
|
242
|
+
*
|
|
243
|
+
* A structural edit shifts every line from here down to a new position, and
|
|
244
|
+
* the answer such a line still holds was computed for where it used to be.
|
|
245
|
+
* The next pass knows the viewport, so it can clear exactly the stale ones,
|
|
246
|
+
* the moved lines below the range it runs; see
|
|
247
|
+
* {@link forgetMovedBelowViewport}. Recorded rather than acted on at edit
|
|
248
|
+
* time because a moved line ABOVE the range is one a fresh pass still shows.
|
|
249
|
+
*/
|
|
250
|
+
private movedFloor;
|
|
239
251
|
/**
|
|
240
252
|
* Unsubscribe from sharedGlobalVariableStore, set in the constructor
|
|
241
253
|
* called from terminateWorker(). See the subscription itself below for
|
|
@@ -471,6 +483,24 @@ declare class ThreeTierEvaluator {
|
|
|
471
483
|
* @param startLine First line to evaluate (1-based, inclusive).
|
|
472
484
|
* @param endLine Last line to evaluate (1-based, inclusive). Clamped to docEnd.
|
|
473
485
|
*/
|
|
486
|
+
/**
|
|
487
|
+
* Clear the stale answers a structural edit left below the viewport.
|
|
488
|
+
*
|
|
489
|
+
* An insert or a delete moves every line from {@link movedFloor} down to a
|
|
490
|
+
* new position; the answer each still holds was computed for its old one. A
|
|
491
|
+
* moved line inside the range about to run is re-run and gets a fresh answer,
|
|
492
|
+
* and a moved line above it is one a fresh pass driven to this viewport still
|
|
493
|
+
* shows, so both are left alone. A moved line BELOW the range is neither: the
|
|
494
|
+
* pass never reaches it, nothing re-runs it, and a fresh pass shows nothing
|
|
495
|
+
* there, yet the incremental path kept its old answer, which a line reading
|
|
496
|
+
* that position then read back as a real one (#458). Those are cleared here,
|
|
497
|
+
* from just past `evalEnd` (or the earliest move, whichever is lower down) to
|
|
498
|
+
* the end of the document. Consumed once: a later pass over a wider viewport
|
|
499
|
+
* re-runs whichever of them it now covers.
|
|
500
|
+
*
|
|
501
|
+
* @param evalEnd - The last line this pass will run.
|
|
502
|
+
*/
|
|
503
|
+
private forgetMovedBelowViewport;
|
|
474
504
|
private collectEvalResults;
|
|
475
505
|
/**
|
|
476
506
|
* Check whether any **variable-definition** line before `position`
|
package/dist/engine.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export{a as DocumentModel,b as EvalTier,c as ThreeTierEvaluator,d as evaluateDocument}from'./chunk-
|
|
1
|
+
export{a as DocumentModel,b as EvalTier,c as ThreeTierEvaluator,d as evaluateDocument}from'./chunk-UPQDEN72.js';import'./chunk-RAF57WYO.js';export{i as AsyncResolutionBatcher,o as ExpressionEngine,d as SNAPSHOT_FORMAT,e as SNAPSHOT_VERSION,f as SnapshotErrorCodes,k as checkExpressionComplexity,j as checkExpressionLength,l as extractReadsAndWrites,n as findInlineSolvesInLine,m as isEmptyLine,g as setEngineWorkerFactory}from'./chunk-MY3UW5CC.js';import'./chunk-RU3KGJRA.js';import'./chunk-2RWAXT6O.js';import'./chunk-RMDCGYZM.js';import'./chunk-MIQBJGGR.js';import'./chunk-X2QJE3SV.js';import'./chunk-RMBUP4XA.js';import'./chunk-JP4JMQOG.js';import'./chunk-TFZNEEJR.js';import'./chunk-HLZRNZEU.js';import'./chunk-ZISAN7NW.js';import'./chunk-U5MESNRT.js';import'./chunk-DB5ISONG.js';import'./chunk-76F3LCIL.js';import'./chunk-EOKHRS2T.js';import'./chunk-TCZSPH4A.js';import'./chunk-QP4VIEXZ.js';import'./chunk-X2GQAKL2.js';import'./chunk-PICFFFJV.js';import'./chunk-TZYMXNIB.js';import'./chunk-HFKDWQUL.js';import'./chunk-5TCSFTZD.js';import'./chunk-ZSFOIBIH.js';export{b as DATE_CALENDAR,a as DateCalendar,c as calendarOf,d as dateCalendarInZone}from'./chunk-EOO6M65F.js';import'./chunk-J4K72CQN.js';import'./chunk-A34R65WT.js';import'./chunk-BWTVJD5L.js';import'./chunk-A5OVVFJE.js';import'./chunk-6NL7RBAG.js';import'./chunk-JPFCXLJV.js';import'./chunk-APYRNAU2.js';import'./chunk-FAO6DQ74.js';import'./chunk-LHLW7JLS.js';import'./chunk-CHVGFTO3.js';import'./chunk-PRSXXDTA.js';import'./chunk-6G2NES2I.js';//# sourceMappingURL=engine.js.map
|
|
2
2
|
//# sourceMappingURL=engine.js.map
|
package/dist/engine.worker.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var chunkOVC4LAQ4_cjs=require('./chunk-OVC4LAQ4.cjs');require('./chunk-P5YWBIIU.cjs'),require('./chunk-NGBBNL4K.cjs'),require('./chunk-R3W53ZMP.cjs'),require('./chunk-TTFO4YDP.cjs');var chunkOBQC7KDY_cjs=require('./chunk-OBQC7KDY.cjs');require('./chunk-HG4NPDN5.cjs'),require('./chunk-EZ7R3ZHM.cjs'),require('./chunk-W4XLVZ6R.cjs');var chunk6FBXJYWO_cjs=require('./chunk-6FBXJYWO.cjs');require('./chunk-NMZRAJLJ.cjs'),require('./chunk-Y5ZY6DPX.cjs'),require('./chunk-K3PZ66XR.cjs'),require('./chunk-YV4GDW5A.cjs'),require('./chunk-UURM7P3P.cjs'),require('./chunk-GDLYXRMA.cjs'),require('./chunk-ZLRJ7TDP.cjs');var chunk54QMY2VL_cjs=require('./chunk-54QMY2VL.cjs');require('./chunk-OBZJKZ2F.cjs'),require('./chunk-SF5QVUEI.cjs'),require('./chunk-ABVDKMNF.cjs'),require('./chunk-TLG7VZRX.cjs'),require('./chunk-5TVI2UPZ.cjs'),require('./chunk-Z4MIX43O.cjs'),require('./chunk-EQNKDTMX.cjs'),require('./chunk-E4HAKNBQ.cjs'),require('./chunk-NH74IT7B.cjs'),require('./chunk-PHWIO4P3.cjs'),require('./chunk-QKNXCIM3.cjs'),require('./chunk-3MG7VIPL.cjs'),require('./chunk-Y7O4D3BJ.cjs'),require('./chunk-72J5V7SN.cjs'),require('./chunk-YBQOQTVL.cjs'),require('./chunk-S3DFU33X.cjs'),require('./chunk-J4LSAHCY.cjs'),require('./chunk-EZKR44MA.cjs'),require('./chunk-6SYU4MH7.cjs');var i=null;function E(){return i||(i=new chunkOVC4LAQ4_cjs.o({packages:chunk6FBXJYWO_cjs.z})),i}var f=null;function h(){return f||(f=chunkOBQC7KDY_cjs.b(chunk54QMY2VL_cjs.A,200,5e4)),f}function B(e){let r={lineId:e.lineId,expression:e.expression,compiledAgainstHash:e.textHash,strings:[],reads:[],writes:[],isVariableDef:false,error:null};try{let n=E(),{program:u,reads:s,writes:t}=n.compileExpression(e.expression),o=t.length>0,a=u.opcodes,l=u.numbers,y=a.buffer.slice(a.byteOffset,a.byteOffset+a.byteLength),d=l.buffer.slice(l.byteOffset,l.byteOffset+l.byteLength);return {...r,opcodesBuffer:y,numbersBuffer:d,opcodesLength:a.length,numbersLength:l.length,strings:[...u.strings],reads:s,writes:t,isVariableDef:o}}catch(n){return {...r,opcodesBuffer:new ArrayBuffer(0),numbersBuffer:new ArrayBuffer(0),opcodesLength:0,numbersLength:0,error:n instanceof Error?n.message:String(n)}}}function L(e){let r=[],n=[];for(let u of e.items){let s=B(u);r.push(s),s.opcodesBuffer.byteLength>0&&n.push(s.opcodesBuffer),s.numbersBuffer.byteLength>0&&n.push(s.numbersBuffer);}self.postMessage({id:e.id,type:"COMPILE_RESULT",results:r},n);}function M(e){let r=h();r.reset();let n=new Uint8Array(e.opcodesBuffer,0,e.opcodesLength),u=new Float64Array(e.numbersBuffer,0,e.numbersLength),s={opcodes:n,numbers:u,strings:e.strings};try{let t=chunkOBQC7KDY_cjs.c(s,r);if(t.type==="pending")return {lineNumber:e.lineNumber,valueType:12,value:0,isPending:!0,queryKey:t.queryKey};if(t.type==="error")return {lineNumber:e.lineNumber,valueType:13,value:0,isPending:!1,unit:t.error.message};let o=t.value;return {lineNumber:e.lineNumber,valueType:o.type,value:typeof o.value=="number"?o.value:typeof o.value=="bigint"?Number(o.value):0,unit:o.unit,isPending:!1}}catch{return {lineNumber:e.lineNumber,valueType:13,value:0,isPending:false,unit:"Worker execution failed"}}}function T(e){let r=[];for(let n of e.items)r.push(M(n));self.postMessage({id:e.id,type:"EXECUTE_RESULT",results:r});}var x=typeof self<"u"&&typeof window>"u",C=e=>{if(e.origin&&self.location&&e.origin!==self.location.origin)return;let r=e.data;switch(r.type){case "COMPILE_BATCH":L(r);break;case "EXECUTE_BATCH":T(r);break;case "TERMINATE":{i&&(i.clear(),i=null),f&&(f.reset(),f=null),self.postMessage({id:r.id,type:"COMPILE_RESULT",results:[]});break}default:self.postMessage({id:-1,type:"COMPILE_RESULT",results:[],error:`Unknown message type: ${r.type}`});}};x&&(self.onmessage=C);//# sourceMappingURL=engine.worker.cjs.map
|
|
2
2
|
//# sourceMappingURL=engine.worker.cjs.map
|
package/dist/engine.worker.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {o}from'./chunk-
|
|
1
|
+
import {o}from'./chunk-MY3UW5CC.js';import'./chunk-RU3KGJRA.js';import'./chunk-2RWAXT6O.js';import'./chunk-RMDCGYZM.js';import'./chunk-MIQBJGGR.js';import {c,b}from'./chunk-RMBUP4XA.js';import'./chunk-JP4JMQOG.js';import'./chunk-TFZNEEJR.js';import'./chunk-HLZRNZEU.js';import {z}from'./chunk-KSOB5FCI.js';import'./chunk-AWGSR2GZ.js';import'./chunk-ZISAN7NW.js';import'./chunk-U5MESNRT.js';import'./chunk-DB5ISONG.js';import'./chunk-76F3LCIL.js';import'./chunk-EOKHRS2T.js';import'./chunk-TCZSPH4A.js';import {A}from'./chunk-QP4VIEXZ.js';import'./chunk-X2GQAKL2.js';import'./chunk-PICFFFJV.js';import'./chunk-TZYMXNIB.js';import'./chunk-HFKDWQUL.js';import'./chunk-5TCSFTZD.js';import'./chunk-ZSFOIBIH.js';import'./chunk-EOO6M65F.js';import'./chunk-J4K72CQN.js';import'./chunk-A34R65WT.js';import'./chunk-BWTVJD5L.js';import'./chunk-A5OVVFJE.js';import'./chunk-6NL7RBAG.js';import'./chunk-JPFCXLJV.js';import'./chunk-APYRNAU2.js';import'./chunk-FAO6DQ74.js';import'./chunk-LHLW7JLS.js';import'./chunk-CHVGFTO3.js';import'./chunk-PRSXXDTA.js';import'./chunk-6G2NES2I.js';var i=null;function E(){return i||(i=new o({packages:z})),i}var f=null;function h(){return f||(f=b(A,200,5e4)),f}function B(e){let r={lineId:e.lineId,expression:e.expression,compiledAgainstHash:e.textHash,strings:[],reads:[],writes:[],isVariableDef:false,error:null};try{let n=E(),{program:u,reads:s,writes:t}=n.compileExpression(e.expression),o=t.length>0,a=u.opcodes,l=u.numbers,y=a.buffer.slice(a.byteOffset,a.byteOffset+a.byteLength),d=l.buffer.slice(l.byteOffset,l.byteOffset+l.byteLength);return {...r,opcodesBuffer:y,numbersBuffer:d,opcodesLength:a.length,numbersLength:l.length,strings:[...u.strings],reads:s,writes:t,isVariableDef:o}}catch(n){return {...r,opcodesBuffer:new ArrayBuffer(0),numbersBuffer:new ArrayBuffer(0),opcodesLength:0,numbersLength:0,error:n instanceof Error?n.message:String(n)}}}function L(e){let r=[],n=[];for(let u of e.items){let s=B(u);r.push(s),s.opcodesBuffer.byteLength>0&&n.push(s.opcodesBuffer),s.numbersBuffer.byteLength>0&&n.push(s.numbersBuffer);}self.postMessage({id:e.id,type:"COMPILE_RESULT",results:r},n);}function M(e){let r=h();r.reset();let n=new Uint8Array(e.opcodesBuffer,0,e.opcodesLength),u=new Float64Array(e.numbersBuffer,0,e.numbersLength),s={opcodes:n,numbers:u,strings:e.strings};try{let t=c(s,r);if(t.type==="pending")return {lineNumber:e.lineNumber,valueType:12,value:0,isPending:!0,queryKey:t.queryKey};if(t.type==="error")return {lineNumber:e.lineNumber,valueType:13,value:0,isPending:!1,unit:t.error.message};let o=t.value;return {lineNumber:e.lineNumber,valueType:o.type,value:typeof o.value=="number"?o.value:typeof o.value=="bigint"?Number(o.value):0,unit:o.unit,isPending:!1}}catch{return {lineNumber:e.lineNumber,valueType:13,value:0,isPending:false,unit:"Worker execution failed"}}}function T(e){let r=[];for(let n of e.items)r.push(M(n));self.postMessage({id:e.id,type:"EXECUTE_RESULT",results:r});}var x=typeof self<"u"&&typeof window>"u",C=e=>{if(e.origin&&self.location&&e.origin!==self.location.origin)return;let r=e.data;switch(r.type){case "COMPILE_BATCH":L(r);break;case "EXECUTE_BATCH":T(r);break;case "TERMINATE":{i&&(i.clear(),i=null),f&&(f.reset(),f=null),self.postMessage({id:r.id,type:"COMPILE_RESULT",results:[]});break}default:self.postMessage({id:-1,type:"COMPILE_RESULT",results:[],error:`Unknown message type: ${r.type}`});}};x&&(self.onmessage=C);//# sourceMappingURL=engine.worker.js.map
|
|
2
2
|
//# sourceMappingURL=engine.worker.js.map
|
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';require('./chunk-
|
|
1
|
+
'use strict';require('./chunk-ABOVDTHN.cjs'),require('./chunk-EFJCC6FJ.cjs');var chunkOVC4LAQ4_cjs=require('./chunk-OVC4LAQ4.cjs');require('./chunk-P5YWBIIU.cjs'),require('./chunk-NGBBNL4K.cjs'),require('./chunk-R3W53ZMP.cjs'),require('./chunk-TTFO4YDP.cjs'),require('./chunk-CR7IHPA2.cjs'),require('./chunk-OBQC7KDY.cjs'),require('./chunk-HG4NPDN5.cjs');var chunkEZ7R3ZHM_cjs=require('./chunk-EZ7R3ZHM.cjs');require('./chunk-W4XLVZ6R.cjs');var chunk6FBXJYWO_cjs=require('./chunk-6FBXJYWO.cjs');require('./chunk-NMZRAJLJ.cjs'),require('./chunk-Y5ZY6DPX.cjs');var chunkK3PZ66XR_cjs=require('./chunk-K3PZ66XR.cjs');require('./chunk-YV4GDW5A.cjs'),require('./chunk-UURM7P3P.cjs'),require('./chunk-GDLYXRMA.cjs'),require('./chunk-ZLRJ7TDP.cjs'),require('./chunk-54QMY2VL.cjs'),require('./chunk-OBZJKZ2F.cjs'),require('./chunk-SF5QVUEI.cjs'),require('./chunk-ABVDKMNF.cjs'),require('./chunk-TLG7VZRX.cjs'),require('./chunk-5TVI2UPZ.cjs'),require('./chunk-Z4MIX43O.cjs');var chunkEQNKDTMX_cjs=require('./chunk-EQNKDTMX.cjs');require('./chunk-E4HAKNBQ.cjs');var chunkNH74IT7B_cjs=require('./chunk-NH74IT7B.cjs');require('./chunk-PHWIO4P3.cjs');var chunkQKNXCIM3_cjs=require('./chunk-QKNXCIM3.cjs');require('./chunk-3MG7VIPL.cjs'),require('./chunk-Y7O4D3BJ.cjs'),require('./chunk-72J5V7SN.cjs'),require('./chunk-YBQOQTVL.cjs'),require('./chunk-S3DFU33X.cjs'),require('./chunk-J4LSAHCY.cjs'),require('./chunk-EZKR44MA.cjs');var chunk6SYU4MH7_cjs=require('./chunk-6SYU4MH7.cjs');var r={DEFINE_FUNCTION_INVALID_NAME:"DEFINE_FUNCTION_INVALID_NAME",DEFINE_FUNCTION_INVALID_SPEC:"DEFINE_FUNCTION_INVALID_SPEC",DEFINE_FUNCTION_ARITY_MISMATCH:"DEFINE_FUNCTION_ARITY_MISMATCH",DEFINE_FUNCTION_ARGUMENT_TYPE:"DEFINE_FUNCTION_ARGUMENT_TYPE",DEFINE_FUNCTION_RETURN_TYPE:"DEFINE_FUNCTION_RETURN_TYPE"},O=/^[a-z_][a-z0-9_]*$/i,N=new Set(["number","string","boolean"]);function u(e){return e===1?"1 argument":`${e} arguments`}function d(e){switch(e.type){case 0:case 1:return "a number";case 3:return "a string";case 10:return "a boolean";case 2:return "a big integer";case 5:return "a percentage";case 6:return "a value with a unit";case 4:return "a date";case 7:return "a matrix";case 8:return "a range";case 9:return "a symbolic expression";default:return "an unsupported value"}}function k(e,n,t){switch(n.type){case "number":if(e.type===0||e.type===1)return e.toNumber();break;case "string":if(e.type===3)return e.value;break;case "boolean":if(e.type===10)return e.value;break}throw chunk6SYU4MH7_cjs.c.execution({code:r.DEFINE_FUNCTION_ARGUMENT_TYPE,message:`${t}() expects "${n.name}" to be a ${n.type}, but was given ${d(e)}`,expected:`a ${n.type}`,found:d(e),context:{functionName:t,argName:n.name,expectedType:n.type}})}function R(e,n,t){switch(n){case "number":if(typeof e=="number")return chunkNH74IT7B_cjs.n(e);break;case "string":if(typeof e=="string")return chunkNH74IT7B_cjs.t(e);break;case "boolean":if(typeof e=="boolean")return chunkNH74IT7B_cjs.L(e);break}throw chunk6SYU4MH7_cjs.c.internal({code:r.DEFINE_FUNCTION_RETURN_TYPE,message:`${t}() is declared to return a ${n}, but its implementation returned ${typeof e}`,expected:`a ${n}`,found:typeof e,context:{functionName:t,expectedType:n}})}var p=class{constructor(n){this.fnName=n;this.category="Function";}parse(n,t,a){n.consume("LPAREN");let i=0;if(n.peek()?.type!=="RPAREN")for(n.parseExpression(chunkK3PZ66XR_cjs.a.Lowest,a),i++;n.match("COMMA");)n.parseExpression(chunkK3PZ66XR_cjs.a.Lowest,a),i++;n.consume("RPAREN"),a.emitPluginCall(this.fnName,i);}};function D(e){let n=e.args.length;return t=>{if(t.length!==n)throw chunk6SYU4MH7_cjs.c.execution({code:r.DEFINE_FUNCTION_ARITY_MISMATCH,message:`${e.name}() takes ${u(n)}, but was given ${t.length===0?"none":u(t.length)}`,expected:u(n),found:t.length===0?"none":u(t.length),context:{functionName:e.name,expected:n,actual:t.length}});let a=new Array(n);for(let s=0;s<n;s++)a[s]=k(t[s],e.args[s],e.name);let i=e.call(...a);return R(i,e.returns,e.name)}}function h(e){if(typeof e?.name!="string"||!O.test(e.name))throw chunk6SYU4MH7_cjs.c.config({code:r.DEFINE_FUNCTION_INVALID_NAME,message:`defineFunction: name must be a single identifier, got ${JSON.stringify(e?.name)}`,suggestion:'e.g. "vat" or "net_price"',context:{name:e?.name}});if(!Array.isArray(e.args))throw chunk6SYU4MH7_cjs.c.config({code:r.DEFINE_FUNCTION_INVALID_SPEC,message:`defineFunction: "${e.name}" args must be an array`,context:{name:e.name}});for(let n of e.args){if(typeof n?.name!="string"||n.name.length===0)throw chunk6SYU4MH7_cjs.c.config({code:r.DEFINE_FUNCTION_INVALID_SPEC,message:`defineFunction: "${e.name}" has an argument with no name`,context:{name:e.name}});if(!N.has(n.type))throw chunk6SYU4MH7_cjs.c.config({code:r.DEFINE_FUNCTION_INVALID_SPEC,message:`defineFunction: "${e.name}" argument "${n.name}" has unsupported type ${JSON.stringify(n.type)}`,suggestion:"supported argument types are number, string, boolean",context:{name:e.name,argName:n.name,type:n.type}})}if(!N.has(e.returns))throw chunk6SYU4MH7_cjs.c.config({code:r.DEFINE_FUNCTION_INVALID_SPEC,message:`defineFunction: "${e.name}" has unsupported return type ${JSON.stringify(e.returns)}`,suggestion:"supported return types are number, string, boolean",context:{name:e.name,returns:e.returns}});if(typeof e.call!="function")throw chunk6SYU4MH7_cjs.c.config({code:r.DEFINE_FUNCTION_INVALID_SPEC,message:`defineFunction: "${e.name}" is missing a call implementation`,context:{name:e.name}})}function w(e){h(e);let n=e.name,t=`DEFINE_FN_${n.toUpperCase()}`;return {name:`solve-fn-${n}`,lexerVocabulary:{keywords:{[n.toLowerCase()]:t}},prefixParselets:{[t]:new p(n)},pluginFunctions:{[n]:D(e)}}}function U(e={}){let{extraPackages:n=[],...t}=e;return new chunkOVC4LAQ4_cjs.o({...t,packages:n.length>0?[...chunk6FBXJYWO_cjs.z,...n]:chunk6FBXJYWO_cjs.z})}Object.defineProperty(exports,"ExpressionEngine",{enumerable:true,get:function(){return chunkOVC4LAQ4_cjs.o}});Object.defineProperty(exports,"SNAPSHOT_FORMAT",{enumerable:true,get:function(){return chunkOVC4LAQ4_cjs.d}});Object.defineProperty(exports,"SNAPSHOT_VERSION",{enumerable:true,get:function(){return chunkOVC4LAQ4_cjs.e}});Object.defineProperty(exports,"SnapshotErrorCodes",{enumerable:true,get:function(){return chunkOVC4LAQ4_cjs.f}});Object.defineProperty(exports,"assertEngineVersionCompatible",{enumerable:true,get:function(){return chunkOVC4LAQ4_cjs.c}});Object.defineProperty(exports,"checkEngineVersionCompatibility",{enumerable:true,get:function(){return chunkOVC4LAQ4_cjs.b}});Object.defineProperty(exports,"checkPackageCompatibility",{enumerable:true,get:function(){return chunkOVC4LAQ4_cjs.a}});Object.defineProperty(exports,"setEngineWorkerFactory",{enumerable:true,get:function(){return chunkOVC4LAQ4_cjs.g}});Object.defineProperty(exports,"formatValue",{enumerable:true,get:function(){return chunkEZ7R3ZHM_cjs.c}});Object.defineProperty(exports,"dateCalendarInZone",{enumerable:true,get:function(){return chunkEQNKDTMX_cjs.d}});Object.defineProperty(exports,"Value",{enumerable:true,get:function(){return chunkNH74IT7B_cjs.m}});Object.defineProperty(exports,"ValueType",{enumerable:true,get:function(){return chunkNH74IT7B_cjs.g}});Object.defineProperty(exports,"ENGINE_VERSION",{enumerable:true,get:function(){return chunkQKNXCIM3_cjs.a}});exports.DefineFunctionErrorCodes=r;exports.createEngine=U;exports.defineFunction=w;//# sourceMappingURL=index.cjs.map
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import'./chunk-
|
|
1
|
+
import'./chunk-UPQDEN72.js';import'./chunk-RAF57WYO.js';import {o}from'./chunk-MY3UW5CC.js';export{o as ExpressionEngine,d as SNAPSHOT_FORMAT,e as SNAPSHOT_VERSION,f as SnapshotErrorCodes,c as assertEngineVersionCompatible,b as checkEngineVersionCompatibility,a as checkPackageCompatibility,g as setEngineWorkerFactory}from'./chunk-MY3UW5CC.js';import'./chunk-RU3KGJRA.js';import'./chunk-2RWAXT6O.js';import'./chunk-RMDCGYZM.js';import'./chunk-MIQBJGGR.js';import'./chunk-X2QJE3SV.js';import'./chunk-RMBUP4XA.js';import'./chunk-JP4JMQOG.js';export{c as formatValue}from'./chunk-TFZNEEJR.js';import'./chunk-HLZRNZEU.js';import {z}from'./chunk-KSOB5FCI.js';import'./chunk-AWGSR2GZ.js';import'./chunk-ZISAN7NW.js';import {a}from'./chunk-U5MESNRT.js';import'./chunk-DB5ISONG.js';import'./chunk-76F3LCIL.js';import'./chunk-EOKHRS2T.js';import'./chunk-TCZSPH4A.js';import'./chunk-QP4VIEXZ.js';import'./chunk-X2GQAKL2.js';import'./chunk-PICFFFJV.js';import'./chunk-TZYMXNIB.js';import'./chunk-HFKDWQUL.js';import'./chunk-5TCSFTZD.js';import'./chunk-ZSFOIBIH.js';export{d as dateCalendarInZone}from'./chunk-EOO6M65F.js';import'./chunk-J4K72CQN.js';import {L,t,n}from'./chunk-A34R65WT.js';export{m as Value,g as ValueType}from'./chunk-A34R65WT.js';import'./chunk-BWTVJD5L.js';export{a as ENGINE_VERSION}from'./chunk-A5OVVFJE.js';import'./chunk-6NL7RBAG.js';import'./chunk-JPFCXLJV.js';import'./chunk-APYRNAU2.js';import'./chunk-FAO6DQ74.js';import'./chunk-LHLW7JLS.js';import'./chunk-CHVGFTO3.js';import'./chunk-PRSXXDTA.js';import {c}from'./chunk-6G2NES2I.js';var r={DEFINE_FUNCTION_INVALID_NAME:"DEFINE_FUNCTION_INVALID_NAME",DEFINE_FUNCTION_INVALID_SPEC:"DEFINE_FUNCTION_INVALID_SPEC",DEFINE_FUNCTION_ARITY_MISMATCH:"DEFINE_FUNCTION_ARITY_MISMATCH",DEFINE_FUNCTION_ARGUMENT_TYPE:"DEFINE_FUNCTION_ARGUMENT_TYPE",DEFINE_FUNCTION_RETURN_TYPE:"DEFINE_FUNCTION_RETURN_TYPE"},O=/^[a-z_][a-z0-9_]*$/i,N=new Set(["number","string","boolean"]);function u(e){return e===1?"1 argument":`${e} arguments`}function d(e){switch(e.type){case 0:case 1:return "a number";case 3:return "a string";case 10:return "a boolean";case 2:return "a big integer";case 5:return "a percentage";case 6:return "a value with a unit";case 4:return "a date";case 7:return "a matrix";case 8:return "a range";case 9:return "a symbolic expression";default:return "an unsupported value"}}function k(e,n,t){switch(n.type){case "number":if(e.type===0||e.type===1)return e.toNumber();break;case "string":if(e.type===3)return e.value;break;case "boolean":if(e.type===10)return e.value;break}throw c.execution({code:r.DEFINE_FUNCTION_ARGUMENT_TYPE,message:`${t}() expects "${n.name}" to be a ${n.type}, but was given ${d(e)}`,expected:`a ${n.type}`,found:d(e),context:{functionName:t,argName:n.name,expectedType:n.type}})}function R(e,n$1,t$1){switch(n$1){case "number":if(typeof e=="number")return n(e);break;case "string":if(typeof e=="string")return t(e);break;case "boolean":if(typeof e=="boolean")return L(e);break}throw c.internal({code:r.DEFINE_FUNCTION_RETURN_TYPE,message:`${t$1}() is declared to return a ${n$1}, but its implementation returned ${typeof e}`,expected:`a ${n$1}`,found:typeof e,context:{functionName:t$1,expectedType:n$1}})}var p=class{constructor(n){this.fnName=n;this.category="Function";}parse(n,t,a$1){n.consume("LPAREN");let i=0;if(n.peek()?.type!=="RPAREN")for(n.parseExpression(a.Lowest,a$1),i++;n.match("COMMA");)n.parseExpression(a.Lowest,a$1),i++;n.consume("RPAREN"),a$1.emitPluginCall(this.fnName,i);}};function D(e){let n=e.args.length;return t=>{if(t.length!==n)throw c.execution({code:r.DEFINE_FUNCTION_ARITY_MISMATCH,message:`${e.name}() takes ${u(n)}, but was given ${t.length===0?"none":u(t.length)}`,expected:u(n),found:t.length===0?"none":u(t.length),context:{functionName:e.name,expected:n,actual:t.length}});let a=new Array(n);for(let s=0;s<n;s++)a[s]=k(t[s],e.args[s],e.name);let i=e.call(...a);return R(i,e.returns,e.name)}}function h(e){if(typeof e?.name!="string"||!O.test(e.name))throw c.config({code:r.DEFINE_FUNCTION_INVALID_NAME,message:`defineFunction: name must be a single identifier, got ${JSON.stringify(e?.name)}`,suggestion:'e.g. "vat" or "net_price"',context:{name:e?.name}});if(!Array.isArray(e.args))throw c.config({code:r.DEFINE_FUNCTION_INVALID_SPEC,message:`defineFunction: "${e.name}" args must be an array`,context:{name:e.name}});for(let n of e.args){if(typeof n?.name!="string"||n.name.length===0)throw c.config({code:r.DEFINE_FUNCTION_INVALID_SPEC,message:`defineFunction: "${e.name}" has an argument with no name`,context:{name:e.name}});if(!N.has(n.type))throw c.config({code:r.DEFINE_FUNCTION_INVALID_SPEC,message:`defineFunction: "${e.name}" argument "${n.name}" has unsupported type ${JSON.stringify(n.type)}`,suggestion:"supported argument types are number, string, boolean",context:{name:e.name,argName:n.name,type:n.type}})}if(!N.has(e.returns))throw c.config({code:r.DEFINE_FUNCTION_INVALID_SPEC,message:`defineFunction: "${e.name}" has unsupported return type ${JSON.stringify(e.returns)}`,suggestion:"supported return types are number, string, boolean",context:{name:e.name,returns:e.returns}});if(typeof e.call!="function")throw c.config({code:r.DEFINE_FUNCTION_INVALID_SPEC,message:`defineFunction: "${e.name}" is missing a call implementation`,context:{name:e.name}})}function w(e){h(e);let n=e.name,t=`DEFINE_FN_${n.toUpperCase()}`;return {name:`solve-fn-${n}`,lexerVocabulary:{keywords:{[n.toLowerCase()]:t}},prefixParselets:{[t]:new p(n)},pluginFunctions:{[n]:D(e)}}}function U(e={}){let{extraPackages:n=[],...t}=e;return new o({...t,packages:n.length>0?[...z,...n]:z})}export{r as DefineFunctionErrorCodes,U as createEngine,w as defineFunction};//# sourceMappingURL=index.js.map
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/testing.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var chunkOVC4LAQ4_cjs=require('./chunk-OVC4LAQ4.cjs');require('./chunk-P5YWBIIU.cjs'),require('./chunk-NGBBNL4K.cjs'),require('./chunk-R3W53ZMP.cjs'),require('./chunk-TTFO4YDP.cjs'),require('./chunk-OBQC7KDY.cjs'),require('./chunk-HG4NPDN5.cjs'),require('./chunk-EZ7R3ZHM.cjs'),require('./chunk-W4XLVZ6R.cjs');var chunk6FBXJYWO_cjs=require('./chunk-6FBXJYWO.cjs');require('./chunk-NMZRAJLJ.cjs'),require('./chunk-Y5ZY6DPX.cjs'),require('./chunk-K3PZ66XR.cjs'),require('./chunk-YV4GDW5A.cjs'),require('./chunk-UURM7P3P.cjs'),require('./chunk-GDLYXRMA.cjs'),require('./chunk-ZLRJ7TDP.cjs'),require('./chunk-54QMY2VL.cjs'),require('./chunk-OBZJKZ2F.cjs'),require('./chunk-SF5QVUEI.cjs'),require('./chunk-ABVDKMNF.cjs'),require('./chunk-TLG7VZRX.cjs'),require('./chunk-5TVI2UPZ.cjs'),require('./chunk-Z4MIX43O.cjs'),require('./chunk-EQNKDTMX.cjs'),require('./chunk-E4HAKNBQ.cjs');var chunkNH74IT7B_cjs=require('./chunk-NH74IT7B.cjs');require('./chunk-PHWIO4P3.cjs');var chunkQKNXCIM3_cjs=require('./chunk-QKNXCIM3.cjs');require('./chunk-3MG7VIPL.cjs'),require('./chunk-Y7O4D3BJ.cjs'),require('./chunk-72J5V7SN.cjs'),require('./chunk-YBQOQTVL.cjs'),require('./chunk-S3DFU33X.cjs'),require('./chunk-J4LSAHCY.cjs'),require('./chunk-EZKR44MA.cjs');var chunk6SYU4MH7_cjs=require('./chunk-6SYU4MH7.cjs');var i=class o extends Error{constructor(t){super(t.message),this.name="ExpectationError",this.code=t.code,this.expected=t.expected,this.actual=t.actual,Object.setPrototypeOf(this,o.prototype);}};function V(o=[],t={}){let{locale:e="en",includeBuiltins:r=true}=t,s=new chunkOVC4LAQ4_cjs.o({locale:e,packages:r?chunk6FBXJYWO_cjs.z:[]});for(let a of o)s.registerPackage(a);return s}function v(o,t){try{let e=o.evaluateExpression(t);return e.isError()?{status:"error",code:e.errorCode??"",message:e.errorMessage??"",source:e}:e.isPending()?{status:"pending",value:e}:{status:"value",value:e}}catch(e){if(e instanceof chunk6SYU4MH7_cjs.b)return {status:"error",code:e.code,message:e.message,source:e};let r=e instanceof Error?e.message:String(e);return {status:"error",code:"UNKNOWN_ERROR",message:r,source:new chunkNH74IT7B_cjs.m(13,"UNKNOWN_ERROR",r)}}}function x(o,t){if(Object.is(o,t))return true;if(!Number.isFinite(o)||!Number.isFinite(t))return false;let e=1e-9*Math.max(1,Math.abs(o),Math.abs(t));return Math.abs(o-t)<=e}function l(o){return o.type===3?JSON.stringify(o.value):o.type===6&&typeof o.unit=="string"?`${String(o.value)} ${o.unit}`:String(o.value)}function n(o){switch(o.status){case "value":return l(o.value);case "pending":return "a pending async value";case "error":return `an error (${o.code}: ${o.message})`}}var d=class{constructor(t,e){this.expression=t;this.outcome=e;}get value(){if(this.outcome.status==="error")throw new i({code:"EXPECTED_VALUE",message:`Expected "${this.expression}" to evaluate, but it failed with ${n(this.outcome)}.`,expected:"a resolved value",actual:n(this.outcome)});return this.outcome.value}toEvaluate(){if(this.outcome.status!=="value")throw new i({code:"EXPECTED_EVALUATE",message:`Expected "${this.expression}" to evaluate to a value, but got ${n(this.outcome)}.`,expected:"a resolved value",actual:n(this.outcome)});return this}toEqual(t,e){if(this.outcome.status!=="value")throw new i({code:"EXPECTED_EQUAL",message:`Expected "${this.expression}" to equal ${c(t,e)}, but got ${n(this.outcome)}.`,expected:c(t,e),actual:n(this.outcome)});let r=this.outcome.value,s;if(typeof t=="number"?s=x(r.toNumber(),t):typeof t=="boolean"?s=r.type===10&&r.value===t:s=C(r)===t,!s)throw new i({code:"EXPECTED_EQUAL",message:`Expected "${this.expression}" to equal ${c(t,e)}, but it was ${l(r)}.`,expected:c(t,e),actual:l(r)});if(e!==void 0&&r.unit!==e)throw new i({code:"EXPECTED_UNIT",message:`Expected "${this.expression}" to carry the unit "${e}", but it was ${r.unit===void 0?"unitless":`"${r.unit}"`}.`,expected:`unit "${e}"`,actual:r.unit===void 0?"no unit":`unit "${r.unit}"`});return this}toBeError(){if(this.outcome.status!=="error")throw new i({code:"EXPECTED_ERROR",message:`Expected "${this.expression}" to fail, but it produced ${n(this.outcome)}.`,expected:"an error",actual:n(this.outcome)});return this}toFailWith(t){if(this.outcome.status!=="error")throw new i({code:"EXPECTED_FAIL_WITH",message:`Expected "${this.expression}" to fail with "${t}", but it produced ${n(this.outcome)}.`,expected:`error code "${t}"`,actual:n(this.outcome)});if(this.outcome.code!==t)throw new i({code:"EXPECTED_FAIL_WITH",message:`Expected "${this.expression}" to fail with "${t}", but it failed with "${this.outcome.code}" (${this.outcome.message}).`,expected:`error code "${t}"`,actual:`error code "${this.outcome.code}"`});return this}toBePending(){if(this.outcome.status!=="pending")throw new i({code:"EXPECTED_PENDING",message:`Expected "${this.expression}" to be pending, but got ${n(this.outcome)}.`,expected:"a pending async value",actual:n(this.outcome)});return this}};function c(o,t){let e=typeof o=="string"?JSON.stringify(o):String(o);return t===void 0?e:`${e} ${t}`}function C(o){return String(o.value)}function D(o,t){return new d(t,v(o,t))}var O=["a","an","and","or","but","if","then","the","this","that","these","those","in","on","at","to","of","for","from","with","by","as","per","into","over","is","are","was","were","be","been","being","do","does","did","have","has","had","will","would","can","could","should","may","might","must","price","cost","value","total","sum","count","rate","amount","number","time","date","day","week","month","year","hour","minute","second","add","buy","sell","hold","make","take","give","get","set","run","up","down","out","off","all","some","any","no","not","more","less","one","two","three","first","last","next","each","every","here","there"],$=["error","warning","info"];function k(o){let t=[],e=o.lexerVocabulary;if(e?.keywords)for(let[r,s]of Object.entries(e.keywords))t.push({word:r,via:"keyword",tokenType:s});if(e?.units)for(let r of e.units)t.push({word:r,via:"unit"});if(e?.operators)for(let[r,s]of Object.entries(e.operators))t.push({word:r,via:"operator",tokenType:s});if(o.phrases)for(let[r,s]of Object.entries(o.phrases))r.includes(" ")||t.push({word:r,via:"phrase",tokenType:s});return t}var p=class{constructor(t){this.pkg=t;}notToShadow(t=O){let e=new Set(t.map(s=>s.toLowerCase())),r=k(this.pkg).filter(s=>e.has(s.word.toLowerCase()));if(r.length>0){let s=r.map(a=>`"${a.word}" (${a.via})`).join(", ");throw new i({code:"PACKAGE_SHADOWS_PROSE",message:`Package "${this.pkg.name}" claims prose word(s) as syntax: ${s}. A word that is also ordinary English turns prose into arithmetic; prefer a multi-word phrase or a form that requires a parenthesis.`,expected:"no prose words claimed as syntax",actual:s})}return r}notToCollideWith(t,e="error"){let r=chunkOVC4LAQ4_cjs.a(this.pkg,t),s=$.indexOf(e),a=r.conflicts.filter(u=>$.indexOf(u.severity)<=s);if(a.length>0){let u=a.map(g=>`[${g.severity}] ${g.detail}`).join(`
|
|
2
2
|
`);throw new i({code:"PACKAGE_VOCABULARY_COLLISION",message:`Package "${this.pkg.name}" collides with another package:
|
|
3
|
-
${u}`,expected:`no conflicts at or above "${e}" severity`,actual:`${a.length} conflict(s)`})}return r}toDeclareCompatibleEngineVersion(t=
|
|
3
|
+
${u}`,expected:`no conflicts at or above "${e}" severity`,actual:`${a.length} conflict(s)`})}return r}toDeclareCompatibleEngineVersion(t=chunkQKNXCIM3_cjs.a){let e=chunkOVC4LAQ4_cjs.b(this.pkg,t);if(!e.compatible){let r=e.reason==="invalid-range"?`its range "${e.declaredRange}" is not valid semver`:`its range "${e.declaredRange}" is not satisfied by engine version "${e.engineVersion}"`;throw new i({code:"PACKAGE_ENGINE_VERSION_INCOMPATIBLE",message:`Package "${this.pkg.name}" declares an engineVersion that will be rejected at registration: ${r}.`,expected:`an engineVersion satisfied by "${t}"`,actual:`"${e.declaredRange}"`})}return this}};function L(o){return new p(o)}exports.COMMON_PROSE_WORDS=O;exports.ExpectationError=i;exports.ExpressionAssertion=d;exports.PackageAssertion=p;exports.createTestEngine=V;exports.expectExpression=D;exports.expectPackage=L;//# sourceMappingURL=testing.cjs.map
|
|
4
4
|
//# sourceMappingURL=testing.cjs.map
|
package/dist/testing.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {o,a,b}from'./chunk-
|
|
1
|
+
import {o,a,b}from'./chunk-MY3UW5CC.js';import'./chunk-RU3KGJRA.js';import'./chunk-2RWAXT6O.js';import'./chunk-RMDCGYZM.js';import'./chunk-MIQBJGGR.js';import'./chunk-RMBUP4XA.js';import'./chunk-JP4JMQOG.js';import'./chunk-TFZNEEJR.js';import'./chunk-HLZRNZEU.js';import {z}from'./chunk-KSOB5FCI.js';import'./chunk-AWGSR2GZ.js';import'./chunk-ZISAN7NW.js';import'./chunk-U5MESNRT.js';import'./chunk-DB5ISONG.js';import'./chunk-76F3LCIL.js';import'./chunk-EOKHRS2T.js';import'./chunk-TCZSPH4A.js';import'./chunk-QP4VIEXZ.js';import'./chunk-X2GQAKL2.js';import'./chunk-PICFFFJV.js';import'./chunk-TZYMXNIB.js';import'./chunk-HFKDWQUL.js';import'./chunk-5TCSFTZD.js';import'./chunk-ZSFOIBIH.js';import'./chunk-EOO6M65F.js';import'./chunk-J4K72CQN.js';import {m}from'./chunk-A34R65WT.js';import'./chunk-BWTVJD5L.js';import {a as a$1}from'./chunk-A5OVVFJE.js';import'./chunk-6NL7RBAG.js';import'./chunk-JPFCXLJV.js';import'./chunk-APYRNAU2.js';import'./chunk-FAO6DQ74.js';import'./chunk-LHLW7JLS.js';import'./chunk-CHVGFTO3.js';import'./chunk-PRSXXDTA.js';import {b as b$1}from'./chunk-6G2NES2I.js';var i=class o extends Error{constructor(t){super(t.message),this.name="ExpectationError",this.code=t.code,this.expected=t.expected,this.actual=t.actual,Object.setPrototypeOf(this,o.prototype);}};function V(o$1=[],t={}){let{locale:e="en",includeBuiltins:r=true}=t,s=new o({locale:e,packages:r?z:[]});for(let a of o$1)s.registerPackage(a);return s}function v(o,t){try{let e=o.evaluateExpression(t);return e.isError()?{status:"error",code:e.errorCode??"",message:e.errorMessage??"",source:e}:e.isPending()?{status:"pending",value:e}:{status:"value",value:e}}catch(e){if(e instanceof b$1)return {status:"error",code:e.code,message:e.message,source:e};let r=e instanceof Error?e.message:String(e);return {status:"error",code:"UNKNOWN_ERROR",message:r,source:new m(13,"UNKNOWN_ERROR",r)}}}function x(o,t){if(Object.is(o,t))return true;if(!Number.isFinite(o)||!Number.isFinite(t))return false;let e=1e-9*Math.max(1,Math.abs(o),Math.abs(t));return Math.abs(o-t)<=e}function l(o){return o.type===3?JSON.stringify(o.value):o.type===6&&typeof o.unit=="string"?`${String(o.value)} ${o.unit}`:String(o.value)}function n(o){switch(o.status){case "value":return l(o.value);case "pending":return "a pending async value";case "error":return `an error (${o.code}: ${o.message})`}}var d=class{constructor(t,e){this.expression=t;this.outcome=e;}get value(){if(this.outcome.status==="error")throw new i({code:"EXPECTED_VALUE",message:`Expected "${this.expression}" to evaluate, but it failed with ${n(this.outcome)}.`,expected:"a resolved value",actual:n(this.outcome)});return this.outcome.value}toEvaluate(){if(this.outcome.status!=="value")throw new i({code:"EXPECTED_EVALUATE",message:`Expected "${this.expression}" to evaluate to a value, but got ${n(this.outcome)}.`,expected:"a resolved value",actual:n(this.outcome)});return this}toEqual(t,e){if(this.outcome.status!=="value")throw new i({code:"EXPECTED_EQUAL",message:`Expected "${this.expression}" to equal ${c(t,e)}, but got ${n(this.outcome)}.`,expected:c(t,e),actual:n(this.outcome)});let r=this.outcome.value,s;if(typeof t=="number"?s=x(r.toNumber(),t):typeof t=="boolean"?s=r.type===10&&r.value===t:s=C(r)===t,!s)throw new i({code:"EXPECTED_EQUAL",message:`Expected "${this.expression}" to equal ${c(t,e)}, but it was ${l(r)}.`,expected:c(t,e),actual:l(r)});if(e!==void 0&&r.unit!==e)throw new i({code:"EXPECTED_UNIT",message:`Expected "${this.expression}" to carry the unit "${e}", but it was ${r.unit===void 0?"unitless":`"${r.unit}"`}.`,expected:`unit "${e}"`,actual:r.unit===void 0?"no unit":`unit "${r.unit}"`});return this}toBeError(){if(this.outcome.status!=="error")throw new i({code:"EXPECTED_ERROR",message:`Expected "${this.expression}" to fail, but it produced ${n(this.outcome)}.`,expected:"an error",actual:n(this.outcome)});return this}toFailWith(t){if(this.outcome.status!=="error")throw new i({code:"EXPECTED_FAIL_WITH",message:`Expected "${this.expression}" to fail with "${t}", but it produced ${n(this.outcome)}.`,expected:`error code "${t}"`,actual:n(this.outcome)});if(this.outcome.code!==t)throw new i({code:"EXPECTED_FAIL_WITH",message:`Expected "${this.expression}" to fail with "${t}", but it failed with "${this.outcome.code}" (${this.outcome.message}).`,expected:`error code "${t}"`,actual:`error code "${this.outcome.code}"`});return this}toBePending(){if(this.outcome.status!=="pending")throw new i({code:"EXPECTED_PENDING",message:`Expected "${this.expression}" to be pending, but got ${n(this.outcome)}.`,expected:"a pending async value",actual:n(this.outcome)});return this}};function c(o,t){let e=typeof o=="string"?JSON.stringify(o):String(o);return t===void 0?e:`${e} ${t}`}function C(o){return String(o.value)}function D(o,t){return new d(t,v(o,t))}var O=["a","an","and","or","but","if","then","the","this","that","these","those","in","on","at","to","of","for","from","with","by","as","per","into","over","is","are","was","were","be","been","being","do","does","did","have","has","had","will","would","can","could","should","may","might","must","price","cost","value","total","sum","count","rate","amount","number","time","date","day","week","month","year","hour","minute","second","add","buy","sell","hold","make","take","give","get","set","run","up","down","out","off","all","some","any","no","not","more","less","one","two","three","first","last","next","each","every","here","there"],$=["error","warning","info"];function k(o){let t=[],e=o.lexerVocabulary;if(e?.keywords)for(let[r,s]of Object.entries(e.keywords))t.push({word:r,via:"keyword",tokenType:s});if(e?.units)for(let r of e.units)t.push({word:r,via:"unit"});if(e?.operators)for(let[r,s]of Object.entries(e.operators))t.push({word:r,via:"operator",tokenType:s});if(o.phrases)for(let[r,s]of Object.entries(o.phrases))r.includes(" ")||t.push({word:r,via:"phrase",tokenType:s});return t}var p=class{constructor(t){this.pkg=t;}notToShadow(t=O){let e=new Set(t.map(s=>s.toLowerCase())),r=k(this.pkg).filter(s=>e.has(s.word.toLowerCase()));if(r.length>0){let s=r.map(a=>`"${a.word}" (${a.via})`).join(", ");throw new i({code:"PACKAGE_SHADOWS_PROSE",message:`Package "${this.pkg.name}" claims prose word(s) as syntax: ${s}. A word that is also ordinary English turns prose into arithmetic; prefer a multi-word phrase or a form that requires a parenthesis.`,expected:"no prose words claimed as syntax",actual:s})}return r}notToCollideWith(t,e="error"){let r=a(this.pkg,t),s=$.indexOf(e),a$1=r.conflicts.filter(u=>$.indexOf(u.severity)<=s);if(a$1.length>0){let u=a$1.map(g=>`[${g.severity}] ${g.detail}`).join(`
|
|
2
2
|
`);throw new i({code:"PACKAGE_VOCABULARY_COLLISION",message:`Package "${this.pkg.name}" collides with another package:
|
|
3
3
|
${u}`,expected:`no conflicts at or above "${e}" severity`,actual:`${a$1.length} conflict(s)`})}return r}toDeclareCompatibleEngineVersion(t=a$1){let e=b(this.pkg,t);if(!e.compatible){let r=e.reason==="invalid-range"?`its range "${e.declaredRange}" is not valid semver`:`its range "${e.declaredRange}" is not satisfied by engine version "${e.engineVersion}"`;throw new i({code:"PACKAGE_ENGINE_VERSION_INCOMPATIBLE",message:`Package "${this.pkg.name}" declares an engineVersion that will be rejected at registration: ${r}.`,expected:`an engineVersion satisfied by "${t}"`,actual:`"${e.declaredRange}"`})}return this}};function L(o){return new p(o)}export{O as COMMON_PROSE_WORDS,i as ExpectationError,d as ExpressionAssertion,p as PackageAssertion,V as createTestEngine,D as expectExpression,L as expectPackage};//# sourceMappingURL=testing.js.map
|
|
4
4
|
//# sourceMappingURL=testing.js.map
|
package/dist/worker.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
'use strict';var chunkHSTGWWU2_cjs=require('./chunk-HSTGWWU2.cjs'),
|
|
2
|
-
`).forEach((u,d)=>a.set(d+1,u)):o.method==="evaluateLines"?o.args[0].forEach((u,d)=>a.set(d+1,u)):a.set(-1,o.args[0]),a},V=(o,a)=>{if(a.type==="error"){g({kind:"async-error",queryKey:a.queryKey,packageId:a.packageId,error:chunkHSTGWWU2_cjs.b(chunk6SYU4MH7_cjs.d(a.error))});return}let u=[];for(let d of a.lineNumbers){let f=l.get(d);if(f!==void 0)try{let T=o.evaluateLine(d,f);T&&u.push({lineNumber:d,value:m(T,s)});}catch{}}u.length>0&&g({kind:"async-update",lines:u});},U=o=>{p?.();let a=o.getEventStream().getReader();p=()=>{a.cancel();},(async()=>{try{for(;;){let{done:u,value:d}=await a.read();if(u)return;V(o,d);}}catch{}})();},j=o=>{try{let a=$(n,o.packages);t=new
|
|
1
|
+
'use strict';var chunkHSTGWWU2_cjs=require('./chunk-HSTGWWU2.cjs'),chunkOVC4LAQ4_cjs=require('./chunk-OVC4LAQ4.cjs');require('./chunk-P5YWBIIU.cjs'),require('./chunk-NGBBNL4K.cjs'),require('./chunk-R3W53ZMP.cjs'),require('./chunk-TTFO4YDP.cjs'),require('./chunk-OBQC7KDY.cjs'),require('./chunk-HG4NPDN5.cjs');var chunkEZ7R3ZHM_cjs=require('./chunk-EZ7R3ZHM.cjs');require('./chunk-W4XLVZ6R.cjs');var chunk6FBXJYWO_cjs=require('./chunk-6FBXJYWO.cjs');require('./chunk-NMZRAJLJ.cjs');var chunkY5ZY6DPX_cjs=require('./chunk-Y5ZY6DPX.cjs');require('./chunk-K3PZ66XR.cjs'),require('./chunk-YV4GDW5A.cjs'),require('./chunk-UURM7P3P.cjs'),require('./chunk-GDLYXRMA.cjs'),require('./chunk-ZLRJ7TDP.cjs'),require('./chunk-54QMY2VL.cjs'),require('./chunk-OBZJKZ2F.cjs'),require('./chunk-SF5QVUEI.cjs'),require('./chunk-ABVDKMNF.cjs'),require('./chunk-TLG7VZRX.cjs');var chunk5TVI2UPZ_cjs=require('./chunk-5TVI2UPZ.cjs'),chunkZ4MIX43O_cjs=require('./chunk-Z4MIX43O.cjs');require('./chunk-EQNKDTMX.cjs'),require('./chunk-E4HAKNBQ.cjs'),require('./chunk-NH74IT7B.cjs'),require('./chunk-PHWIO4P3.cjs');var chunkQKNXCIM3_cjs=require('./chunk-QKNXCIM3.cjs');require('./chunk-3MG7VIPL.cjs'),require('./chunk-Y7O4D3BJ.cjs'),require('./chunk-72J5V7SN.cjs'),require('./chunk-YBQOQTVL.cjs'),require('./chunk-S3DFU33X.cjs'),require('./chunk-J4LSAHCY.cjs'),require('./chunk-EZKR44MA.cjs');var chunk6SYU4MH7_cjs=require('./chunk-6SYU4MH7.cjs');function B(e){if(e?.date?.inputOrder!=="locale")return e;let r={...e.date,inputOrder:chunkY5ZY6DPX_cjs.k({...chunkQKNXCIM3_cjs.b.date,...e.date}).order};return delete r.inputLocale,{...e,date:r}}var x=class{constructor(r){this.nextId=1;this.pending=new Map;this.resolvedListeners=new Set;this.asyncErrorListeners=new Set;this.terminated=false;this.transport=r,this.transport.onMessage(n=>this.onMessage(n));}init(r){let n=this.nextId++;return new Promise((t,s)=>{this.pending.set(n,{resolve:()=>t(),reject:s}),this.transport.postMessage({kind:"init",id:n,localeCode:r.localeCode,diagnostics:r.diagnostics,config:B(r.config),packages:r.packages,formatting:r.formatting});})}parseDocument(r,n){let{signal:t,...s}=n??{},i=Object.keys(s).length>0?s:void 0;return this.call("parseDocument",[r,i],t)}evaluateLines(r,n){return this.call("evaluateLines",[r],n?.signal)}evaluateExpression(r,n){return this.call("evaluateExpression",[r],n?.signal)}onResolved(r){return this.resolvedListeners.add(r),()=>this.resolvedListeners.delete(r)}onAsyncError(r){return this.asyncErrorListeners.add(r),()=>this.asyncErrorListeners.delete(r)}terminate(){if(this.terminated)return;this.terminated=true;let r=chunkHSTGWWU2_cjs.e();for(let n of this.pending.values())this.unhook(n),n.reject(r);this.pending.clear(),this.resolvedListeners.clear(),this.asyncErrorListeners.clear(),this.transport.terminate();}call(r,n,t){if(this.terminated)return Promise.reject(chunkHSTGWWU2_cjs.e());if(t?.aborted)return Promise.reject(chunkHSTGWWU2_cjs.d(r));let s=this.nextId++;return new Promise((i,l)=>{let c={resolve:i,reject:l};if(t){let p=()=>{this.pending.has(s)&&(this.pending.delete(s),this.transport.postMessage({kind:"cancel",id:s}),l(chunkHSTGWWU2_cjs.d(r)));};c.signal=t,c.onAbort=p,t.addEventListener("abort",p,{once:true});}this.pending.set(s,c),this.transport.postMessage({kind:"request",id:s,method:r,args:n});})}onMessage(r){let n=r;switch(n.kind){case "ready":case "result":{let t=n.kind==="result"?n.value:void 0;this.settle(n.id,s=>s.resolve(t));break}case "error":this.settle(n.id,t=>t.reject(chunkHSTGWWU2_cjs.c(n.error)));break;case "async-update":for(let t of [...this.resolvedListeners])t(n.lines);break;case "async-error":for(let t of [...this.asyncErrorListeners])t({queryKey:n.queryKey,packageId:n.packageId,error:chunkHSTGWWU2_cjs.c(n.error)});break}}settle(r,n){let t=this.pending.get(r);t&&(this.pending.delete(r),this.unhook(t),n(t));}unhook(r){r.signal&&r.onAbort&&r.signal.removeEventListener("abort",r.onAbort);}};async function G(e){let r=new x(e.transport);return await r.init(e),r}function F(e){return e>0?"Infinity":e<0?"-Infinity":"NaN"}function H(e){let r=e.data.map(n=>typeof n=="object"&&n!==null?chunkZ4MIX43O_cjs.R(n):typeof n=="number"&&!Number.isFinite(n)?F(n):n);return {rows:e.rows,cols:e.cols,cells:r,hasSymbolic:e.hasSymbolic}}function m(e,r){let n=e.toNumber(),t={type:e.type,text:chunkEZ7R3ZHM_cjs.c(e,r),number:Number.isFinite(n)?n:0};Number.isFinite(n)||(t.nonFinite=F(n)),e.unit!==void 0&&(t.unit=e.unit),e.timedOut!==void 0&&(t.timedOut=e.timedOut),e.grain!==void 0&&(t.grain=e.grain),e.zone!==void 0&&(t.zone=e.zone);let s=e.value;if(typeof s=="bigint")t.bigint=s.toString();else if(e.type===7)t.matrix=H(s);else if(e.type===8){let i=s;t.range={min:i.min,max:i.max};}else if(e.type===14){let i=s;t.colour={hex:chunk5TVI2UPZ_cjs.f(i),r:i.r,g:i.g,b:i.b,a:i.a,format:i.format,css:chunk5TVI2UPZ_cjs.g(i)};}else if(e.type===16){let i=s;t.chart={kind:i.kind,points:i.points.map(l=>[l[0],l[1]]),label:i.label,domain:[i.domain[0],i.domain[1]],range:[i.range[0],i.range[1]],...i.expr!==void 0?{expr:i.expr}:{}};}else if(e.type===17){let i=s;t.ipCidr={...i.addr!==void 0?{addr:i.addr}:{},...i.prefix!==void 0?{prefix:i.prefix}:{},text:chunkEZ7R3ZHM_cjs.c(e).replace(/^=\s*/,"")};}return t}function q(e,r){return e?m(e,r):null}function J(e,r){return {start:e.start,end:e.end,expression:e.expression,lineNumber:e.lineNumber,columnNumber:e.columnNumber,result:q(e.result,r),error:e.error??null}}function y(e,r){return {lineNumber:e.lineNumber,text:e.text,startPosition:e.startPosition,endPosition:e.endPosition,isEmpty:e.isEmpty,hasInlineSolves:e.hasInlineSolves,inlineSolves:e.inlineSolves.map(n=>J(n,r)),expression:e.expression,result:q(e.result,r),error:e.error}}function R(e,r){let n={lines:e.lines.map(t=>y(t,r)),totalLines:e.totalLines,errors:[...e.errors]};return e.diagnostics!==void 0&&(n.diagnostics=e.diagnostics),n}function $(e,r){if(r===void 0)return e;let n=new Map(e.map(s=>[s.name,s])),t=[];for(let s of r){let i=n.get(s);if(!i)throw chunk6SYU4MH7_cjs.c.config(chunkHSTGWWU2_cjs.a.WORKER_UNKNOWN_PACKAGE,`No package named "${s}" is available in this worker runtime`,{name:s,available:[...n.keys()]});t.push(i);}return t}function Q(e,r={}){let n=r.packages??chunk6FBXJYWO_cjs.z,t=null,s,i=new Map,l=new Map,c=null,p=null,g=o=>e.postMessage(o),E=(o,a)=>{g({kind:"error",id:o,error:chunkHSTGWWU2_cjs.b(chunk6SYU4MH7_cjs.d(a))});},D=o=>{let a=new Map;return o.method==="parseDocument"?o.args[0].split(`
|
|
2
|
+
`).forEach((u,d)=>a.set(d+1,u)):o.method==="evaluateLines"?o.args[0].forEach((u,d)=>a.set(d+1,u)):a.set(-1,o.args[0]),a},V=(o,a)=>{if(a.type==="error"){g({kind:"async-error",queryKey:a.queryKey,packageId:a.packageId,error:chunkHSTGWWU2_cjs.b(chunk6SYU4MH7_cjs.d(a.error))});return}let u=[];for(let d of a.lineNumbers){let f=l.get(d);if(f!==void 0)try{let T=o.evaluateLine(d,f);T&&u.push({lineNumber:d,value:m(T,s)});}catch{}}u.length>0&&g({kind:"async-update",lines:u});},U=o=>{p?.();let a=o.getEventStream().getReader();p=()=>{a.cancel();},(async()=>{try{for(;;){let{done:u,value:d}=await a.read();if(u)return;V(o,d);}}catch{}})();},j=o=>{try{let a=$(n,o.packages);t=new chunkOVC4LAQ4_cjs.o({locale:o.localeCode??"en",diagnostics:o.diagnostics??!1,config:o.config,packages:a,calendar:r.calendar}),s=r.calendar?{...o.formatting??chunkEZ7R3ZHM_cjs.a,calendar:r.calendar}:o.formatting,U(t),g({kind:"ready",id:o.id});}catch(a){E(o.id,a);}},K=(o,a)=>{let{method:u,args:d}=a;switch(u){case "parseDocument":return R(o.parseDocument(d[0],d[1]),s);case "evaluateLines":return o.evaluateLines(d[0]).map(f=>y(f,s));case "evaluateExpression":return m(o.evaluateExpression(d[0]),s);default:throw chunk6SYU4MH7_cjs.c.execution(chunkHSTGWWU2_cjs.a.WORKER_UNKNOWN_METHOD,`The worker runtime has no method named "${String(u)}"`,{method:u})}},_=o=>{let a=t;if(!a){E(o.id,chunk6SYU4MH7_cjs.c.execution(chunkHSTGWWU2_cjs.a.WORKER_NOT_INITIALISED,"The worker received a request before its engine finished initialising"));return}c?.abort();let u=new AbortController;c=u,l=D(o),i.set(o.id,u),a.setKeystrokeSignal(u.signal);try{let d=K(a,o);g({kind:"result",id:o.id,value:d});}catch(d){E(o.id,d);}finally{i.delete(o.id),a.setKeystrokeSignal(null);}};return e.onMessage(o=>{let a=o;switch(a.kind){case "init":j(a);break;case "request":_(a);break;case "cancel":i.get(a.id)?.abort();break}}),()=>{p?.(),p=null,c?.abort(),c=null,l=new Map;for(let o of i.values())o.abort();i.clear(),t?.clear(),t=null,e.terminate();}}function X(e){return typeof globalThis.structuredClone=="function"?globalThis.structuredClone(e):JSON.parse(JSON.stringify(e))}function Y(){let e=null,r=null,n=true,t=(l,c)=>{let p=X(c);queueMicrotask(()=>{n&&l()?.(p);});};return {client:{postMessage:l=>t(()=>r,l),onMessage:l=>{e=l;},terminate:()=>{n=false;}},host:{postMessage:l=>t(()=>e,l),onMessage:l=>{r=l;},terminate:()=>{n=false;}}}}function Z(e){return {postMessage:r=>e.postMessage(r),onMessage:r=>{let n=t=>r(t.data);typeof e.addEventListener=="function"?e.addEventListener("message",n):e.onmessage=n,e.start?.();},terminate:()=>{e.terminate?.(),e.close?.();}}}function ee(e){return {postMessage:r=>e.postMessage(r),onMessage:r=>{e.on("message",n=>r(n));},terminate:()=>{e.terminate?.(),e.close?.();}}}exports.createLinkedTransports=Y;exports.createWorkerEngine=G;exports.eventTargetTransport=Z;exports.messagePortTransport=ee;exports.serializeParsedLine=y;exports.serializeParsingResult=R;exports.serializeValue=m;exports.startWorkerRuntime=Q;//# sourceMappingURL=worker.cjs.map
|
|
3
3
|
//# sourceMappingURL=worker.cjs.map
|
package/dist/worker.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {a as a$1,e,d,c as c$2,b}from'./chunk-YID47OPR.js';import {o}from'./chunk-
|
|
1
|
+
import {a as a$1,e,d,c as c$2,b}from'./chunk-YID47OPR.js';import {o}from'./chunk-MY3UW5CC.js';import'./chunk-RU3KGJRA.js';import'./chunk-2RWAXT6O.js';import'./chunk-RMDCGYZM.js';import'./chunk-MIQBJGGR.js';import'./chunk-RMBUP4XA.js';import'./chunk-JP4JMQOG.js';import {c,a}from'./chunk-TFZNEEJR.js';import'./chunk-HLZRNZEU.js';import {z}from'./chunk-KSOB5FCI.js';import'./chunk-AWGSR2GZ.js';import {k}from'./chunk-ZISAN7NW.js';import'./chunk-U5MESNRT.js';import'./chunk-DB5ISONG.js';import'./chunk-76F3LCIL.js';import'./chunk-EOKHRS2T.js';import'./chunk-TCZSPH4A.js';import'./chunk-QP4VIEXZ.js';import'./chunk-X2GQAKL2.js';import'./chunk-PICFFFJV.js';import'./chunk-TZYMXNIB.js';import'./chunk-HFKDWQUL.js';import {g,f}from'./chunk-5TCSFTZD.js';import {R as R$1}from'./chunk-ZSFOIBIH.js';import'./chunk-EOO6M65F.js';import'./chunk-J4K72CQN.js';import'./chunk-A34R65WT.js';import'./chunk-BWTVJD5L.js';import {b as b$1}from'./chunk-A5OVVFJE.js';import'./chunk-6NL7RBAG.js';import'./chunk-JPFCXLJV.js';import'./chunk-APYRNAU2.js';import'./chunk-FAO6DQ74.js';import'./chunk-LHLW7JLS.js';import'./chunk-CHVGFTO3.js';import'./chunk-PRSXXDTA.js';import {c as c$1,d as d$1}from'./chunk-6G2NES2I.js';function B(e){if(e?.date?.inputOrder!=="locale")return e;let r={...e.date,inputOrder:k({...b$1.date,...e.date}).order};return delete r.inputLocale,{...e,date:r}}var x=class{constructor(r){this.nextId=1;this.pending=new Map;this.resolvedListeners=new Set;this.asyncErrorListeners=new Set;this.terminated=false;this.transport=r,this.transport.onMessage(n=>this.onMessage(n));}init(r){let n=this.nextId++;return new Promise((t,s)=>{this.pending.set(n,{resolve:()=>t(),reject:s}),this.transport.postMessage({kind:"init",id:n,localeCode:r.localeCode,diagnostics:r.diagnostics,config:B(r.config),packages:r.packages,formatting:r.formatting});})}parseDocument(r,n){let{signal:t,...s}=n??{},i=Object.keys(s).length>0?s:void 0;return this.call("parseDocument",[r,i],t)}evaluateLines(r,n){return this.call("evaluateLines",[r],n?.signal)}evaluateExpression(r,n){return this.call("evaluateExpression",[r],n?.signal)}onResolved(r){return this.resolvedListeners.add(r),()=>this.resolvedListeners.delete(r)}onAsyncError(r){return this.asyncErrorListeners.add(r),()=>this.asyncErrorListeners.delete(r)}terminate(){if(this.terminated)return;this.terminated=true;let r=e();for(let n of this.pending.values())this.unhook(n),n.reject(r);this.pending.clear(),this.resolvedListeners.clear(),this.asyncErrorListeners.clear(),this.transport.terminate();}call(r,n,t){if(this.terminated)return Promise.reject(e());if(t?.aborted)return Promise.reject(d(r));let s=this.nextId++;return new Promise((i,l)=>{let c={resolve:i,reject:l};if(t){let p=()=>{this.pending.has(s)&&(this.pending.delete(s),this.transport.postMessage({kind:"cancel",id:s}),l(d(r)));};c.signal=t,c.onAbort=p,t.addEventListener("abort",p,{once:true});}this.pending.set(s,c),this.transport.postMessage({kind:"request",id:s,method:r,args:n});})}onMessage(r){let n=r;switch(n.kind){case "ready":case "result":{let t=n.kind==="result"?n.value:void 0;this.settle(n.id,s=>s.resolve(t));break}case "error":this.settle(n.id,t=>t.reject(c$2(n.error)));break;case "async-update":for(let t of [...this.resolvedListeners])t(n.lines);break;case "async-error":for(let t of [...this.asyncErrorListeners])t({queryKey:n.queryKey,packageId:n.packageId,error:c$2(n.error)});break}}settle(r,n){let t=this.pending.get(r);t&&(this.pending.delete(r),this.unhook(t),n(t));}unhook(r){r.signal&&r.onAbort&&r.signal.removeEventListener("abort",r.onAbort);}};async function G(e){let r=new x(e.transport);return await r.init(e),r}function F(e){return e>0?"Infinity":e<0?"-Infinity":"NaN"}function H(e){let r=e.data.map(n=>typeof n=="object"&&n!==null?R$1(n):typeof n=="number"&&!Number.isFinite(n)?F(n):n);return {rows:e.rows,cols:e.cols,cells:r,hasSymbolic:e.hasSymbolic}}function m(e,r){let n=e.toNumber(),t={type:e.type,text:c(e,r),number:Number.isFinite(n)?n:0};Number.isFinite(n)||(t.nonFinite=F(n)),e.unit!==void 0&&(t.unit=e.unit),e.timedOut!==void 0&&(t.timedOut=e.timedOut),e.grain!==void 0&&(t.grain=e.grain),e.zone!==void 0&&(t.zone=e.zone);let s=e.value;if(typeof s=="bigint")t.bigint=s.toString();else if(e.type===7)t.matrix=H(s);else if(e.type===8){let i=s;t.range={min:i.min,max:i.max};}else if(e.type===14){let i=s;t.colour={hex:f(i),r:i.r,g:i.g,b:i.b,a:i.a,format:i.format,css:g(i)};}else if(e.type===16){let i=s;t.chart={kind:i.kind,points:i.points.map(l=>[l[0],l[1]]),label:i.label,domain:[i.domain[0],i.domain[1]],range:[i.range[0],i.range[1]],...i.expr!==void 0?{expr:i.expr}:{}};}else if(e.type===17){let i=s;t.ipCidr={...i.addr!==void 0?{addr:i.addr}:{},...i.prefix!==void 0?{prefix:i.prefix}:{},text:c(e).replace(/^=\s*/,"")};}return t}function q(e,r){return e?m(e,r):null}function J(e,r){return {start:e.start,end:e.end,expression:e.expression,lineNumber:e.lineNumber,columnNumber:e.columnNumber,result:q(e.result,r),error:e.error??null}}function y(e,r){return {lineNumber:e.lineNumber,text:e.text,startPosition:e.startPosition,endPosition:e.endPosition,isEmpty:e.isEmpty,hasInlineSolves:e.hasInlineSolves,inlineSolves:e.inlineSolves.map(n=>J(n,r)),expression:e.expression,result:q(e.result,r),error:e.error}}function R(e,r){let n={lines:e.lines.map(t=>y(t,r)),totalLines:e.totalLines,errors:[...e.errors]};return e.diagnostics!==void 0&&(n.diagnostics=e.diagnostics),n}function $(e,r){if(r===void 0)return e;let n=new Map(e.map(s=>[s.name,s])),t=[];for(let s of r){let i=n.get(s);if(!i)throw c$1.config(a$1.WORKER_UNKNOWN_PACKAGE,`No package named "${s}" is available in this worker runtime`,{name:s,available:[...n.keys()]});t.push(i);}return t}function Q(e,r={}){let n=r.packages??z,t=null,s,i=new Map,l=new Map,c=null,p=null,g=o=>e.postMessage(o),E=(o,a)=>{g({kind:"error",id:o,error:b(d$1(a))});},D=o=>{let a=new Map;return o.method==="parseDocument"?o.args[0].split(`
|
|
2
2
|
`).forEach((u,d)=>a.set(d+1,u)):o.method==="evaluateLines"?o.args[0].forEach((u,d)=>a.set(d+1,u)):a.set(-1,o.args[0]),a},V=(o,a)=>{if(a.type==="error"){g({kind:"async-error",queryKey:a.queryKey,packageId:a.packageId,error:b(d$1(a.error))});return}let u=[];for(let d of a.lineNumbers){let f=l.get(d);if(f!==void 0)try{let T=o.evaluateLine(d,f);T&&u.push({lineNumber:d,value:m(T,s)});}catch{}}u.length>0&&g({kind:"async-update",lines:u});},U=o=>{p?.();let a=o.getEventStream().getReader();p=()=>{a.cancel();},(async()=>{try{for(;;){let{done:u,value:d}=await a.read();if(u)return;V(o,d);}}catch{}})();},j=o$1=>{try{let a$1=$(n,o$1.packages);t=new o({locale:o$1.localeCode??"en",diagnostics:o$1.diagnostics??!1,config:o$1.config,packages:a$1,calendar:r.calendar}),s=r.calendar?{...o$1.formatting??a,calendar:r.calendar}:o$1.formatting,U(t),g({kind:"ready",id:o$1.id});}catch(a){E(o$1.id,a);}},K=(o,a)=>{let{method:u,args:d}=a;switch(u){case "parseDocument":return R(o.parseDocument(d[0],d[1]),s);case "evaluateLines":return o.evaluateLines(d[0]).map(f=>y(f,s));case "evaluateExpression":return m(o.evaluateExpression(d[0]),s);default:throw c$1.execution(a$1.WORKER_UNKNOWN_METHOD,`The worker runtime has no method named "${String(u)}"`,{method:u})}},_=o=>{let a=t;if(!a){E(o.id,c$1.execution(a$1.WORKER_NOT_INITIALISED,"The worker received a request before its engine finished initialising"));return}c?.abort();let u=new AbortController;c=u,l=D(o),i.set(o.id,u),a.setKeystrokeSignal(u.signal);try{let d=K(a,o);g({kind:"result",id:o.id,value:d});}catch(d){E(o.id,d);}finally{i.delete(o.id),a.setKeystrokeSignal(null);}};return e.onMessage(o=>{let a=o;switch(a.kind){case "init":j(a);break;case "request":_(a);break;case "cancel":i.get(a.id)?.abort();break}}),()=>{p?.(),p=null,c?.abort(),c=null,l=new Map;for(let o of i.values())o.abort();i.clear(),t?.clear(),t=null,e.terminate();}}function X(e){return typeof globalThis.structuredClone=="function"?globalThis.structuredClone(e):JSON.parse(JSON.stringify(e))}function Y(){let e=null,r=null,n=true,t=(l,c)=>{let p=X(c);queueMicrotask(()=>{n&&l()?.(p);});};return {client:{postMessage:l=>t(()=>r,l),onMessage:l=>{e=l;},terminate:()=>{n=false;}},host:{postMessage:l=>t(()=>e,l),onMessage:l=>{r=l;},terminate:()=>{n=false;}}}}function Z(e){return {postMessage:r=>e.postMessage(r),onMessage:r=>{let n=t=>r(t.data);typeof e.addEventListener=="function"?e.addEventListener("message",n):e.onmessage=n,e.start?.();},terminate:()=>{e.terminate?.(),e.close?.();}}}function ee(e){return {postMessage:r=>e.postMessage(r),onMessage:r=>{e.on("message",n=>r(n));},terminate:()=>{e.terminate?.(),e.close?.();}}}export{Y as createLinkedTransports,G as createWorkerEngine,Z as eventTargetTransport,ee as messagePortTransport,y as serializeParsedLine,R as serializeParsingResult,m as serializeValue,Q as startWorkerRuntime};//# sourceMappingURL=worker.js.map
|
|
3
3
|
//# sourceMappingURL=worker.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "solve-engine",
|
|
3
|
-
"version": "2.38.
|
|
3
|
+
"version": "2.38.25",
|
|
4
4
|
"description": "An embeddable expression engine for natural-language calculations: units, currencies, percentages, dates and matrices, with the parsing and evaluation plumbing already built.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"expression-evaluator",
|
package/dist/chunk-AEGR3GFA.js
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import {a}from'./chunk-RAF57WYO.js';import {m,n,h as h$1}from'./chunk-JVHRND2N.js';import {a as a$1}from'./chunk-X2QJE3SV.js';import {b as b$2,a as a$2}from'./chunk-ZISAN7NW.js';import {b as b$1}from'./chunk-76F3LCIL.js';import {N,O,b as b$3}from'./chunk-QP4VIEXZ.js';import {h,i,P as P$1,j,k}from'./chunk-A34R65WT.js';import {b}from'./chunk-FBXQUQCY.js';import {c as c$1}from'./chunk-6NL7RBAG.js';import {c,b as b$4}from'./chunk-6G2NES2I.js';var F=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,i]=A(this.root,e);this.root=R(R(n,fe(t)),i);}deleteAt(e){if(e<0||e>=(this.root?.size??0))return;let[t,n]=A(this.root,e),[i,s]=A(n,1),r=i?i.lineId:void 0;return this.root=R(t,s),r}spliceAt(e,t,n){let i=Math.max(0,e),s=Math.min(Math.max(0,t),(this.root?.size??0)-i),[r,o]=A(this.root,i),[d,a]=A(o,s),l=ge(d),c=z(n,0,n.length);return this.root=R(R(r,c),a),l}replaceAll(e){this.root=z(e,0,e.length);}getRange(e,t){let n=Math.max(0,e),i=Math.min((this.root?.size??0)-1,t);if(n>i)return [];let s=[];return this.collectRange(this.root,n,i,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,i,s){if(!e)return;let r=e.left?e.left.size:0,o=i+r;o>t&&e.left&&this.collectRange(e.left,t,n,i,s),o>=t&&o<=n&&s.push(e.lineId),o<n&&e.right&&this.collectRange(e.right,t,n,o+1,s);}};function fe(u){return {lineId:u,size:1,priority:Math.random(),left:null,right:null}}function U(u){u.size=1+(u.left?u.left.size:0)+(u.right?u.right.size:0);}function R(u,e){return u?e?u.priority>e.priority?(u.right=R(u.right,e),U(u),u):(e.left=R(u,e.left),U(e),e):u:e}function A(u,e){if(!u)return [null,null];let t=u.left?u.left.size:0;if(e<=t){let[n,i]=A(u.left,e);return u.left=i,U(u),[n,u]}else {let[n,i]=A(u.right,e-t-1);return u.right=n,U(u),[u,i]}}function ge(u){let e=[];return J(u,e),e}function J(u,e){u&&(J(u.left,e),e.push(u.lineId),J(u.right,e));}function z(u,e,t){if(e>=t)return null;let n=Math.floor((e+t)/2),i=pe(u[n]);return {lineId:u[n],size:t-e,priority:i,left:z(u,e,n),right:z(u,n+1,t)}}function pe(u){let e=u+2654435769|0;return e=Math.imul(e>>>16^e,73244475),e=Math.imul(e>>>16^e,73244475),e=(e>>>16^e)>>>0,e/4294967296}var T=class{constructor(e=b.performance.maxDocumentLines){this.lines=new Map;this.orderTree=new F;this.nextLineId=1;this._positionCache=null;this.dirtyLineIds=new Set;this.tagIndex=null;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,this.tagIndex=null;let n=e.split(`
|
|
2
|
-
`),i=new Array(n.length);for(let s=0;s<n.length;s++){let r=this.nextLineId++;i[s]=r,this.lines.set(r,{lineId:r,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(i);for(let s of i)this.dirtyLineIds.add(s);}applyChanges(e){let t=[],n=[],i=[...e].sort((s,r)=>r.startLine-s.startLine);for(let s of i){let r=s.startLine-1,o=[];for(let a$1 of s.insertLines){let l=this.nextLineId++;o.push(l),t.push(l),this.lines.set(l,{lineId:l,textHash:a(a$1),text:a$1,expressions:[],bytecodes:[],reads:[],writes:[],results:[],result:null,dirty:true,isVariableDef:false,isEmpty:a$1.trim().length===0,inlineSolveCount:0});}for(let a of o)this.dirtyLineIds.add(a);if(this.tagIndex!==null)for(let a of o)this.indexTags(a,this.lines.get(a).text);let d=this.orderTree.spliceAt(r,s.deleteCount,o);for(let a of d)n.push(a),this.tagIndex!==null&&this.unindexTags(a,this.lines.get(a)?.text??""),this.lines.delete(a),this.dirtyLineIds.delete(a);}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 i=a(t);return i===n.textHash?false:(this.tagIndex!==null&&(this.unindexTags(n.lineId,n.text),this.indexTags(n.lineId,t)),n.text=t,n.textHash=i,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)}linesCarryingTag(e){let t=this.ensureTagIndex().get(e.toLowerCase());if(t===void 0||t.size===0)return [];let n=[];for(let i of t){let s=this.getLinePosition(i);s>0&&n.push(s);}return n.sort((i,s)=>i-s),n}ensureTagIndex(){if(this.tagIndex!==null)return this.tagIndex;this.tagIndex=new Map;for(let e of this.lines.values())this.indexTags(e.lineId,e.text);return this.tagIndex}indexTags(e,t){if(!(t.indexOf("#")<0))for(let n of b$2(t)){let i=this.tagIndex.get(n);i===void 0?this.tagIndex.set(n,new Set([e])):i.add(e);}}unindexTags(e,t){if(!(t.indexOf("#")<0))for(let n of b$2(t)){let i=this.tagIndex.get(n);i!==void 0&&(i.delete(e),i.size===0&&this.tagIndex.delete(n));}}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),i=[];for(let s of n){let r=this.lines.get(s);r&&i.push(r);}return i}getLineStatesInRange(e,t){let n=this.orderTree.getRange(e-1,t-1),i=new Array(n.length);for(let s=0;s<n.length;s++)i[s]=this.lines.get(n[s]);return i}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 i=this.getLinePosition(t);if(i>=1&&i<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}forgetResult(e){let t=this.lines.get(e);t&&(t.result=null,t.results=[]);}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,i,s,r,o,d=0){let a=this.lines.get(e);a&&(a.results=t,a.result=t[0]?.[0]??null,a.bytecodes=n,a.expressions=i,a.reads=s,a.writes=r,a.isVariableDef=o,a.inlineSolveCount=d,a.dirty=false,this.dirtyLineIds.delete(e));}updateLineCompiled(e,t,n,i,s,r,o=0){let d=this.lines.get(e);d&&(d.expressions=t,d.bytecodes=n,d.reads=i,d.writes=s,d.isVariableDef=r,d.inlineSolveCount=o);}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,this.tagIndex=null;}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 M=class{constructor(){this.worker=null;this.nextId=1;this.pending=new Map;}ensureWorker(){if(this.worker)return this.worker;let e=h$1();if(e===null)throw new Error("no engine worker factory registered, so compilation stays on the main thread");return this.worker=e(),this.worker.onmessage=t=>{let n=t.data;if(!n||n.type!=="COMPILE_RESULT")return;let i=this.pending.get(n.id);if(!i)return;this.pending.delete(n.id);let s=[];for(let r of n.results)s.push(this.reconstructResult(r));i.resolve(s);},this.worker.onerror=t=>{for(let[n,i]of this.pending)i.reject(new Error(`Compilation worker error: ${t.message}`)),this.pending.delete(n);},this.worker}async compileBatch(e){if(e.length===0)return [];let t=this.ensureWorker(),n=this.nextId++;return new Promise((i,s)=>{this.pending.set(n,{resolve:i,reject:s}),t.postMessage({type:"COMPILE_BATCH",id:n,items:e});})}storeResults(e,t){let n=new Map;for(let r of e){if(r.error)continue;let o=t.getLineById(r.lineId);if(!o||o.textHash!==r.compiledAgainstHash)continue;let d=n.get(r.lineId);d||(d={bytecodes:[],reads:new Set,writes:new Set,isVariableDef:false,expressions:o.expressions.length>0?[...o.expressions]:[],textHash:r.compiledAgainstHash},n.set(r.lineId,d)),d.bytecodes.push(r.program);for(let a of r.reads)d.reads.add(a);for(let a of r.writes)d.writes.add(a);r.isVariableDef&&(d.isVariableDef=true);}let s=0;for(let[r,o]of n){if(o.bytecodes.length===0)continue;let a=t.getLineById(r)?.inlineSolveCount??0;t.updateLineCompiled(r,o.expressions,o.bytecodes,[...o.reads],[...o.writes],o.isVariableDef,a),s+=o.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),i={opcodes:t,numbers:n,strings:e.strings,hasAsync:false};return {lineId:e.lineId,compiledAgainstHash:e.compiledAgainstHash,program:i,reads:e.reads,writes:e.writes,isVariableDef:e.isVariableDef,error:null}}};var X=128,P=3,ae=6,ue=2,de=P,_=class u{constructor(){this.lastViewportStart=null;this.savedDirection=null;this.pageAccess=new Map;this.accessSeq=0;}static pageForLine(e){return Math.floor((e-1)/X)}static pageRange(e,t){return {startLine:e*X+1,endLine:Math.min((e+1)*X,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,i=u.pageForLine(e.startLine),s=u.pageForLine(e.endLine),r=u.pageForLine(n),o=Math.max(0,i-P),d=Math.min(r,s+P),a=Math.max(0,i-ae),l=Math.min(r,s+ae);for(let f=o;f<=d;f++)this.touchPage(f);for(let f=a;f<=l;f++)f>=o&&f<=d||this.evictPageResults(f,t,n);let c=a-1,h=Math.max(0,c-de+1);for(let f=h;f<=c;f++)this.evictPageBytecode(f,t,n);let m=l+1,g=Math.min(r,m+de-1);for(let f=m;f<=g;f++)this.evictPageBytecode(f,t,n);}getPreloadTargets(e,t){let n=this.savedDirection;if(!n)return [];let i=[],s=u.pageForLine(e.endLine),r=u.pageForLine(e.startLine),o=u.pageForLine(t.lineCount),d=[];if(n==="down"){let a=s+P+1,l=Math.min(a+ue-1,o);for(let c=a;c<=l&&c<=o;c++)d.push(c);}else {let a=r-P-1;for(let l=a;l>a-ue&&l>=0;l--)d.push(l);}for(let a of d){let l=u.pageRange(a,t.lineCount);for(let c=l.startLine;c<=l.endLine;c++){let h=t.getLineAt(c);if(h&&h.dirty&&!(h.bytecodes.length>0&&!h.isVariableDef)&&!h.isEmpty)if(h.expressions.length>0)for(let m of h.expressions)m.trim()&&i.push({lineId:h.lineId,expression:m,textHash:h.textHash});else {let m=c$1.findInlineSolves(h.text);if(m.length>0)for(let g of m)g.expression.trim()&&i.push({lineId:h.lineId,expression:g.expression,textHash:h.textHash});else {let g=h.text.trim();g&&i.push({lineId:h.lineId,expression:g,textHash:h.textHash});}}}}return i}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 i=u.pageRange(e,n);for(let s=i.startLine;s<=i.endLine;s++){let r=t.getLineAt(s);r&&!r.isVariableDef&&r.results.length>0&&(r.results=[],r.result=null);}}evictPageBytecode(e,t,n){let i=u.pageRange(e,n);for(let s=i.startLine;s<=i.endLine;s++){let r=t.getLineAt(s);!r||r.isVariableDef||(r.bytecodes.length>0||r.results.length>0)&&(r.bytecodes=[],r.results=[],r.result=null,t.markDirty(r.lineId));}}};var ce=(i=>(i[i.Tier1=1]="Tier1",i[i.Tier2=2]="Tier2",i[i.Tier3=3]="Tier3",i[i.Skipped=0]="Skipped",i))(ce||{});function Q(u){let e=new Set;for(let t of u)if(t.userFunctionBodies!==void 0)for(let n of t.userFunctionBodies)e.add(n.name);return e}function Y(u,e){let t=0;for(let n of u)if(n===e&&++t===2)return true;return false}var V=class{constructor(e,t,n){this.compilationWorker=null;this.textHashOfRecordedEdges=new Map;this.selfReadingWrites=new Map;this.cycleMemberIds=new Set;this.globalUnsubscribe=null;this.doc=e,this.engine=t,this.dag=t.getDag(),this.checkpointer=n??new a$1(t.getVM()),this.pageManager=new _,this.engine.getBatcher().checkpointer=this.checkpointer,this.engine.setDocumentModel(this.doc),this.globalUnsubscribe=N.subscribe(i=>{for(let s of this.dag.getAffectedLines(O(i)))this.doc.markDirtyByLineNumber(s);});}evaluate(e,t){this.engine.setKeystrokeSignal(t??null),h();try{this.reseedAccumulators();let n=this.engine.userUnitNames(),i=[],s=new Map,r={tier1:0,tier2:0,tier3:0,skipped:0},o=this.doc.lineCount,d=Math.min(e.endLine,o),a=this.doc.getLineStatesInRange(1,d);for(let c=1;c<=d;c++){let h=a[c-1];if(!h){r.skipped++;continue}let m=c>=e.startLine&&c<=e.endLine,g=this.evaluateSingleLine(h,c,m);i.push(g),g.tier===1?r.tier1++:g.tier===2?r.tier2++:g.tier===3?r.tier3++:r.skipped++,g.results&&m&&s.set(c,g.results.flat());}this.settleCycles(),this.pageManager.maintainAfterEval(e,this.doc),this.engine.settleOrphanedNames();let l=new Set(this.engine.userUnitNames());return n.some(c=>!l.has(c))&&this.engine.invalidateForRemovedUserUnits(),{lines:i,resultMap:s,tierCounts:r}}finally{this.engine.setKeystrokeSignal(null),i();}}backgroundCompile(e){let t=[],n=this.doc.lineCount,i=e.endLine+1;for(let s=i;s<=n;s++){let r=this.doc.getLineAt(s);if(!r||!r.dirty||r.bytecodes.length>0&&!r.isVariableDef)continue;let o=this.evaluateSingleLine(r,s,false);t.push(o);}return t}dispatchBackgroundCompiles(e){let t=this.collectInvisibleCompileTargets(e);t.length!==0&&(this.compilationWorker||(this.compilationWorker=new M),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.evaluate(e,t);this.reseedAccumulators(),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 r of e)for(let o=0;o<r.deleteCount;o++){let d=r.startLine+o,a=this.dag.getWrites(d);for(let l of a)t.add(l);this.undefineOrphans(this.dag.removeLine(d)),this.engine.undefineUserUnitsFrom(this.doc.getLineAt(d)?.lineId??-1)&&this.engine.invalidateForRemovedUserUnits(),this.engine.getLineCache().removeAllForLine(d);}let n=new Set,i=new Set;for(let r of this.dag.linesReadingAPosition()){let o=this.doc.getLineAt(r);o&&(n.add(o.lineId),i.add(o.lineId));}for(let r of t){let o=this.dag.getAffectedLines(r);for(let d of o){let a=this.doc.getLineAt(d);a&&n.add(a.lineId);}}let s=this.doc.applyChanges(e);this.checkpointer?.renumber(r=>this.doc.getLinePosition(r));for(let r of t)this.engine.restoreToPrefix(r,Number.MAX_SAFE_INTEGER);for(let r of n)this.doc.markDirty(r);for(let r of i)this.doc.forgetResult(r);this.dag.clear();for(let r of s.removed)this.textHashOfRecordedEdges.delete(r),this.selfReadingWrites.delete(r),this.cycleMemberIds.delete(r);return {inserted:s.inserted,removed:s.removed}}forgetPositionsOfEditedText(e,t){let n=this.textHashOfRecordedEdges.get(e.lineId);n!==e.textHash&&(n!==void 0&&this.dag.forgetPositionReads(t),this.textHashOfRecordedEdges.set(e.lineId,e.textHash));}settleCycles(){let e=this.dag.takeReadersThatGainedAPosition(),t=this.dag.takeEdgeChanges(),n=new Set(e);for(let i of t.lines)n.add(i);for(let i of t.keys)if(!b$3(i))for(let s of this.dag.directConsumersOf(i))n.add(s);if(n.size!==0){if(this.cycleMemberIds.size>0){let i=this.doc.lineCount;for(let s=1;s<=i;s++){let r=this.doc.getLineAt(s);r!==void 0&&this.cycleMemberIds.has(r.lineId)&&n.add(s);}}this.recomputeCycleMembership(n);}}recomputeCycleMembership(e){let t=new Map,n=new Map,i=new Set,s=[],r=[],o=0,d=l=>{t.set(l,o),n.set(l,o),o++,s.push(l),i.add(l),r.push({line:l,targets:this.dependantsOf(l),next:0});},a=(l,c)=>{let h=this.doc.getLineAt(l);h!==void 0&&c!==this.cycleMemberIds.has(h.lineId)&&(c?this.cycleMemberIds.add(h.lineId):this.cycleMemberIds.delete(h.lineId),this.doc.markDirty(h.lineId));};for(let l of e)if(!t.has(l))for(d(l);r.length>0;){let c=r[r.length-1];if(c.next<c.targets.length){let g=c.targets[c.next++];t.has(g)?i.has(g)&&n.set(c.line,Math.min(n.get(c.line),t.get(g))):d(g);continue}if(r.pop(),r.length>0){let g=r[r.length-1].line;n.set(g,Math.min(n.get(g),n.get(c.line)));}if(n.get(c.line)!==t.get(c.line))continue;let h=[],m;do m=s.pop(),i.delete(m),h.push(m);while(m!==c.line);for(let g of h)a(g,h.length>1);}}dependantsOf(e){let t=[...this.dag.getAffectedLinesByPosition(e)];for(let n of this.dag.getWrites(e))if(!b$3(n)){for(let i of this.dag.directConsumersOf(n))t.push(i);if(this.engine.isAccumulatorName(n))for(let i of this.dag.getProducers(n))i>e&&t.push(i);}return t}reseedAccumulators(){let e=this.engine.resetAccumulators();if(e.size===0)return;let t=this.doc.lineCount;for(let n=1;n<=t;n++){let i=this.doc.getLineAt(n);if(!(i===void 0||i.writes.length===0)){for(let s of i.writes)if(e.has(s)){this.doc.markDirtyByLineNumber(n);break}}}}collectEvalResults(e,t){let n=[],i=new Map,s={tier1:0,tier2:0,tier3:0,skipped:0},r=this.doc.lineCount,o=Math.min(t,r);for(let d=e;d<=o;d++){let a=this.doc.getLineAt(d);if(!a)continue;let l=this.evaluateSingleLine(a,d,true);n.push(l),l.tier===1?s.tier1++:l.tier===2?s.tier2++:l.tier===3?s.tier3++:s.skipped++,l.results&&i.set(d,l.results.flat());}return this.settleCycles(),{lines:n,resultMap:i,tierCounts:s}}hasDirtyLinesBefore(e){return this.doc.hasAnyDirtyVariableDefLineBefore(e)}evaluateSingleLine(e,t,n){e.dirty&&this.forgetPositionsOfEditedText(e,t);let i=this.cycleMemberIds.has(e.lineId);if(this.engine.setLineOnCycle(i),i)for(let r of e.reads)b$3(r)||this.engine.restoreToPrefix(r,t);let s=this.dispatchLine(e,t,n);return (s.tier===1||s.tier===2)&&this.dag.reconcilePositionReads(t),s}dispatchLine(e,t,n){let i={lineId:e.lineId,lineNumber:t};if(!e.dirty&&!n)return {...i,tier:0,result:null,error:null};if(e.isEmpty||m(e.text))return this.deregisterIfDirty(e,t),e.isEmpty=true,this.doc.markClean(e.lineId),{...i,tier:0,result:null,error:null};let{expressions:s,inlineSolveCount:r}=this.extractExpressions(e);return s.length===0?(this.deregisterIfDirty(e,t),e.isEmpty=true,this.doc.markClean(e.lineId),{...i,tier:0,result:null,error:null}):e.dirty?n?this.evaluateTier1(e,t,s,r,i):e.bytecodes.length>0&&e.bytecodes.length===s.length&&!e.isVariableDef?{...i,tier:0,result:null,error:null}:this.evaluateTier3(e,t,s,r,i):n&&e.bytecodes.length>0?this.evaluateTier2(e,t,i):{...i,tier:0,result:null,error:null}}deregisterIfDirty(e,t){if(e.dirty){for(let n of e.writes)this.engine.restoreToPrefix(n,t);e.reads=[],e.writes=[],this.registerWithTags(t,[],[]),this.engine.undefineUserUnitsFrom(e.lineId),this.checkpointer?.dropCheckpointAt(t);}}registerWithTags(e,t,n){let i=this.doc.getLineAt(e)?.text??"",s=a$2(i,t,n);this.undefineOrphans(this.dag.registerLine(e,s.reads,s.writes));}undefineOrphans(e){this.engine.forgetOrphanedNames(e);}evaluateTier1(e,t,n,i,s){this.engine.undefineUserUnitsFrom(e.lineId);let r=[],o=[],d=new Set,a=new Set,l=false,c=null,h=null,m=false,g=false;for(let C of e.writes)this.engine.restoreToPrefix(C,t);let f=new Set,x=[];for(let C of n){if(!C.trim())continue;let I=null,b;try{let p=this.engine.evaluateLine(t,C);I=[p],c=p,b=this.engine.getLineCache().get(t,C);}catch(p){let w=p instanceof Error?p.message:String(p);h||(h=w),m=true,I=null;}I&&I.some(p=>p.type===12)&&(g=true),I?r.push(I):r.push([P$1("eval_failed",h??"unknown error")]);let v=I===null;if(b){o.push(b.bytecode);for(let p of b.readVariables)d.add(p);b.writeVariable&&(a.add(b.writeVariable),l=true,Y(b.readVariables,b.writeVariable)&&x.push(b.writeVariable),v&&!f.has(b.writeVariable)?this.engine.restoreToPrefix(b.writeVariable,t):v||f.add(b.writeVariable));}else try{let{program:p,reads:w,writes:E}=this.engine.compileExpression(C);o.push(p);for(let y of w)d.add(y);for(let y of E)a.add(y);E.length>0&&(l=!0);for(let y of E)Y(w,y)&&x.push(y);for(let y of E)v&&!f.has(y)?this.engine.restoreToPrefix(y,t):v||f.add(y);}catch(p){if(o.push({opcodes:new Uint8Array(0),numbers:new Float64Array(0),strings:[],hasAsync:false}),p instanceof b$4&&p.context){let w=p.context.reads,E=p.context.writes;if(Array.isArray(w))for(let y of w)d.add(y);if(Array.isArray(E))for(let y of E)a.add(y),f.has(y)||this.engine.restoreToPrefix(y,t);}}}let S=[...d],L=[...a];return m||g?(this.doc.updateLineCompiled(e.lineId,n,o,S,L,l,i),e.results=r,e.result=r[0]?.[0]??null,e.inlineSolveCount=i,e.expressions=n):this.doc.updateLineResult(e.lineId,r,o,n,S,L,l,i),x.length>0?this.selfReadingWrites.set(e.lineId,x):this.selfReadingWrites.delete(e.lineId),this.registerWithTags(t,S,L),this.checkpointer&&L.length>0&&!g?this.checkpointer.snapshot(t,e.lineId,L,Q(o)):this.checkpointer&&L.length===0&&this.checkpointer.dropCheckpointAt(t),{...s,tier:1,result:c,results:r,error:h}}evaluateTier2(e,t,n){if(e.bytecodes.length===0)return {...n,tier:0,result:null,error:null};let i=[],s=null,r=null,o=false;for(let l of this.selfReadingWrites.get(e.lineId)??[])this.engine.restoreToPrefix(l,t);let d=this.engine.getLineCache(),a=new Set;for(let l=0;l<e.bytecodes.length;l++){let c=e.bytecodes[l];if(c.opcodes.length===0)continue;let h=d.get(t,e.expressions[l]??""),m=h!==void 0?h.writeVariable===null?[]:[h.writeVariable]:e.writes,g=false;try{let f=this.engine.executeCached(c,t);s=f,i.push([f]);}catch(f){let x=f instanceof Error?f.message:String(f);r||(r=x),o=true,g=true,i.push([P$1("exec_failed",x)]);}for(let f of m)g&&!a.has(f)?this.engine.restoreToPrefix(f,t):g||a.add(f);}return this.registerWithTags(t,e.reads,e.writes),i.length>0?(e.results=i,e.result=i[0][0]??null):e.result!==null&&j()&&(e.results=e.results.map(l=>l.map(k)),e.result=e.results[0]?.[0]??k(e.result)),o&&this.doc.markDirty(e.lineId),this.checkpointer&&e.writes.length>0&&!o&&this.checkpointer.snapshot(t,e.lineId,e.writes,Q(e.bytecodes)),{...n,tier:2,result:i.length>0?s:e.result,results:i.length>0?i:e.results,error:r}}evaluateTier3(e,t,n,i,s){let r=[],o=new Set,d=new Set,a=false,l=null,c=null,h=false,m=false;for(let L of e.writes)this.engine.restoreToPrefix(L,t);let g=new Set,f=[];for(let L of n){if(!L.trim())continue;let C;try{C=this.engine.compileExpression(L);}catch(p){let w=p instanceof Error?p.message:String(p);if(c||(c=w),h=true,r.push({opcodes:new Uint8Array(0),numbers:new Float64Array(0),strings:[],hasAsync:false}),p instanceof b$4&&p.context){let E=p.context.reads,y=p.context.writes;if(Array.isArray(E))for(let k of E)o.add(k);if(Array.isArray(y))for(let k of y)d.add(k),g.has(k)||this.engine.restoreToPrefix(k,t);}continue}let{program:I,reads:b,writes:v}=C;r.push(I);for(let p of b)o.add(p);for(let p of v)d.add(p);v.length>0&&(a=true);for(let p of v)Y(b,p)&&f.push(p);if(v.length>0&&I.opcodes.length>0)try{l=this.engine.executeCached(I,t),l&&l.type===12&&(m=!0);for(let p of v)g.add(p);}catch(p){let w=p instanceof Error?p.message:String(p);c||(c=w),h=true;for(let E of v)g.has(E)||this.engine.restoreToPrefix(E,t);}}let x=[...o],S=[...d];return this.doc.updateLineCompiled(e.lineId,n,r,x,S,a,i),this.registerWithTags(t,x,S),f.length>0?this.selfReadingWrites.set(e.lineId,f):this.selfReadingWrites.delete(e.lineId),a&&l&&!h&&!m&&(e.results=[[l]],e.result=l,this.doc.markClean(e.lineId)),this.checkpointer&&S.length>0&&!m?this.checkpointer.snapshot(t,e.lineId,S,Q(r)):this.checkpointer&&S.length===0&&this.checkpointer.dropCheckpointAt(t),{...s,tier:3,result:l,results:a&&l&&!h&&!m?[[l]]:void 0,error:c}}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 M),this.compilationWorker.compileBatch(t).then(n=>{this.compilationWorker.storeResults(n,this.doc);}).catch(n=>{}));}collectInvisibleCompileTargets(e){let t=[],n=this.doc.lineCount,i=e.endLine+1;for(let s=i;s<=n;s++){let r=this.doc.getLineAt(s);if(!r||!r.dirty||r.bytecodes.length>0&&!r.isVariableDef||r.isEmpty||m(r.text))continue;let{expressions:o}=this.extractExpressions(r);if(o.length!==0)for(let d of o)d.trim()&&t.push({lineId:r.lineId,expression:d,textHash:r.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(i=>i.expression),inlineSolveCount:n.length}:{expressions:[t],inlineSolveCount:0}}};function he(u){return typeof u.unit=="string"?u.unit:String(u.value)}function me(u,e,t={inputType:"markdown"}){let n$1=u.getDocumentModel(),i=new T;i.setDocument(e);let s=new V(i,u,new a$1(u.getVM()));try{let r=i.lineCount;s.evaluate({startLine:1,endLine:r});let o=[],d=[],a=0;for(let l=1;l<=r;l++){let c=i.getLineAt(l),h=c.text,m=a,g=a+h.length;a=g+1;let f=c.inlineSolveCount>0,x=[],S=null,L=null;c.isEmpty||(f?x=n(h,l).map((C,I)=>{let b=c.results[I]?.[0]??null;if(b&&b.type===13){let v=he(b);return d.push(`Line ${l}: ${v}`),{...C,result:null,error:v}}return {...C,result:b,error:null}}):(S=c.expressions[0]??null,L=c.result??null,L&&L.type===13&&d.push(`Line ${l}: ${he(L)}`))),o.push({lineNumber:l,text:h,startPosition:m,endPosition:g,isEmpty:c.isEmpty,hasInlineSolves:f,inlineSolves:x,expression:S,error:null,result:L});}return {lines:o,totalLines:r,errors:d}}finally{s.terminateWorker(),u.setDocumentModel(n$1);}}export{T as a,ce as b,V as c,me as d};//# sourceMappingURL=chunk-AEGR3GFA.js.map
|
|
3
|
-
//# sourceMappingURL=chunk-AEGR3GFA.js.map
|