solve-engine 2.38.20 → 2.38.22
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/{PackageCompatibility-ZCZVGHws.d.ts → PackageCompatibility-C7ILySsH.d.ts} +1 -1
- package/dist/{PackageCompatibility-Bv42nEm2.d.cts → PackageCompatibility-CzDzOIg9.d.cts} +1 -1
- package/dist/{PackageRegistry-7dFbaAZp.d.cts → PackageRegistry-Bd8ErpwZ.d.cts} +78 -1
- package/dist/{PackageRegistry-B6s8LGCu.d.ts → PackageRegistry-D7_B0mxv.d.ts} +78 -1
- package/dist/{VMBuiltins-0C4z3yDS.d.cts → VMBuiltins-Baa90D2v.d.cts} +232 -1
- package/dist/{VMBuiltins-Bu6qaKi0.d.ts → VMBuiltins-BqkoJtHt.d.ts} +232 -1
- package/dist/chunk-54QMY2VL.cjs +2 -0
- package/dist/chunk-54QMY2VL.cjs.map +1 -0
- package/dist/{chunk-UOLCBH37.cjs → chunk-5GJUECKG.cjs} +5 -5
- package/dist/chunk-5GJUECKG.cjs.map +1 -0
- package/dist/chunk-CR7IHPA2.cjs +2 -0
- package/dist/chunk-CR7IHPA2.cjs.map +1 -0
- package/dist/{chunk-I4PKEUMZ.cjs → chunk-FJBWZW45.cjs} +2 -2
- package/dist/{chunk-I4PKEUMZ.cjs.map → chunk-FJBWZW45.cjs.map} +1 -1
- package/dist/chunk-NYJTBXSI.js +3 -0
- package/dist/chunk-NYJTBXSI.js.map +1 -0
- package/dist/{chunk-H4G3UXJV.js → chunk-NZUFFOB3.js} +3 -3
- package/dist/chunk-NZUFFOB3.js.map +1 -0
- package/dist/chunk-OBQC7KDY.cjs +2 -0
- package/dist/chunk-OBQC7KDY.cjs.map +1 -0
- package/dist/{chunk-3JSXJSMT.js → chunk-OC65AGRR.js} +2 -2
- package/dist/{chunk-3JSXJSMT.js.map → chunk-OC65AGRR.js.map} +1 -1
- package/dist/{chunk-EPLOL7WC.cjs → chunk-OQHRKHP7.cjs} +2 -2
- package/dist/{chunk-EPLOL7WC.cjs.map → chunk-OQHRKHP7.cjs.map} +1 -1
- package/dist/chunk-QP4VIEXZ.js +2 -0
- package/dist/chunk-QP4VIEXZ.js.map +1 -0
- package/dist/chunk-RAZ6IYUQ.js +5 -0
- package/dist/chunk-RAZ6IYUQ.js.map +1 -0
- package/dist/chunk-RMBUP4XA.js +2 -0
- package/dist/chunk-RMBUP4XA.js.map +1 -0
- package/dist/{chunk-BHHTXIUL.js → chunk-TVM5VYCM.js} +2 -2
- package/dist/{chunk-BHHTXIUL.js.map → chunk-TVM5VYCM.js.map} +1 -1
- package/dist/chunk-VNNRAHDE.cjs +3 -0
- package/dist/chunk-VNNRAHDE.cjs.map +1 -0
- package/dist/chunk-X2QJE3SV.js +2 -0
- package/dist/chunk-X2QJE3SV.js.map +1 -0
- package/dist/{chunk-7PUNL5CJ.cjs → chunk-ZJJ54J4L.cjs} +3 -3
- package/dist/{chunk-H4G3UXJV.js.map → chunk-ZJJ54J4L.cjs.map} +1 -1
- package/dist/constants.cjs +1 -1
- package/dist/constants.js +1 -1
- package/dist/engine.cjs +1 -1
- package/dist/engine.d.cts +128 -5
- package/dist/engine.d.ts +128 -5
- 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.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +1 -1
- package/dist/language.d.cts +3 -3
- package/dist/language.d.ts +3 -3
- package/dist/packages.cjs +1 -1
- package/dist/packages.d.cts +2 -2
- package/dist/packages.d.ts +2 -2
- package/dist/packages.js +1 -1
- package/dist/testing.cjs +2 -2
- package/dist/testing.d.cts +3 -3
- package/dist/testing.d.ts +3 -3
- package/dist/testing.js +1 -1
- package/dist/vm.cjs +1 -1
- package/dist/vm.d.cts +1 -1
- package/dist/vm.d.ts +1 -1
- package/dist/vm.js +1 -1
- package/dist/worker.cjs +2 -2
- package/dist/worker.d.cts +2 -2
- package/dist/worker.d.ts +2 -2
- package/dist/worker.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-2YHOWQ43.js +0 -2
- package/dist/chunk-2YHOWQ43.js.map +0 -1
- package/dist/chunk-6W3JFXPQ.cjs +0 -2
- package/dist/chunk-6W3JFXPQ.cjs.map +0 -1
- package/dist/chunk-7PUNL5CJ.cjs.map +0 -1
- package/dist/chunk-HNXV35Q2.cjs +0 -2
- package/dist/chunk-HNXV35Q2.cjs.map +0 -1
- package/dist/chunk-JZQRUOO6.js +0 -2
- package/dist/chunk-JZQRUOO6.js.map +0 -1
- package/dist/chunk-K2OUNZZG.cjs +0 -2
- package/dist/chunk-K2OUNZZG.cjs.map +0 -1
- package/dist/chunk-KZPA4DUF.cjs +0 -3
- package/dist/chunk-KZPA4DUF.cjs.map +0 -1
- package/dist/chunk-MXMMDSX4.js +0 -3
- package/dist/chunk-MXMMDSX4.js.map +0 -1
- package/dist/chunk-RTEWTZ6I.js +0 -5
- package/dist/chunk-RTEWTZ6I.js.map +0 -1
- package/dist/chunk-SIUHB77U.js +0 -2
- package/dist/chunk-SIUHB77U.js.map +0 -1
- package/dist/chunk-UOLCBH37.cjs.map +0 -1
package/dist/chunk-K2OUNZZG.cjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
'use strict';var f=class{constructor(t){this.checkpoints=[];this.vm=t;}snapshot(t,e,n){if(n.length===0)return null;let i=this.indexOfCheckpointAt(t),s=i>=0?i:this.insertionIndexFor(t),r=s>0?this.checkpoints[s-1]:null,h=Object.create(null),u=Object.create(null);for(let o of n){if(this.vm.hasUserFunction(o)){let l=this.vm.getUserFunction(o);l&&(u[o]=l);continue}let p=this.vm.getVar(o);p!==void 0&&(h[o]=p);}let c={lineNumber:t,lineId:e,variables:h,functions:u,parent:r};i>=0?this.checkpoints[i]=c:this.checkpoints.splice(s,0,c);let a=this.checkpoints[s+1];return a!==void 0&&(a.parent=c),c}restoreTo(t){let e=this.nearestCheckpointIndex(t);this.vm.reset();for(let n=0;n<=e;n++){let i=this.checkpoints[n];for(let s of Object.keys(i.variables))this.vm.setVar(s,i.variables[s]);for(let s of Object.keys(i.functions)){let r=i.functions[s];this.vm.defineUserFunction(r.name,r.params,r.program);}}}indexOfCheckpointAt(t){let e=this.nearestCheckpointIndex(t);return e>=0&&this.checkpoints[e].lineNumber===t?e:-1}insertionIndexFor(t){return this.nearestCheckpointIndex(t)+1}nearestCheckpointIndex(t){let e=0,n=this.checkpoints.length-1,i=-1;for(;e<=n;){let s=e+n>>1;this.checkpoints[s].lineNumber<=t?(i=s,e=s+1):n=s-1;}return i}updateCheckpointAt(t,e){let n=this.getCheckpointAt(t);if(!n)return false;for(let i of e){if(this.vm.hasUserFunction(i)){let r=this.vm.getUserFunction(i);r&&(n.functions[i]=r);continue}let s=this.vm.getVar(i);s!==void 0&&(n.variables[i]=s);}return true}applyCheckpointAt(t){let e=this.getCheckpointAt(t);if(!e)return false;for(let n of Object.keys(e.variables))this.vm.setVar(n,e.variables[n]);for(let n of Object.keys(e.functions)){let i=e.functions[n];this.vm.defineUserFunction(i.name,i.params,i.program);}return true}forget(t){if(t.length!==0)for(let e of this.checkpoints)for(let n of t)delete e.variables[n],delete e.functions[n];}getNearestCheckpoint(t){let e=this.nearestCheckpointIndex(t);return e<0?null:this.checkpoints[e]}getCheckpointAt(t){let e=this.nearestCheckpointIndex(t);if(e<0)return;let n=this.checkpoints[e];return n.lineNumber===t?n:void 0}getAllCheckpoints(){return this.checkpoints}lookupVariable(t){if(this.checkpoints.length===0)return;let e=this.checkpoints[this.checkpoints.length-1];for(;e;){if(Object.prototype.hasOwnProperty.call(e.variables,t))return e.variables[t];e=e.parent;}}clear(){this.checkpoints=[];}get count(){return this.checkpoints.length}get isEmpty(){return this.checkpoints.length===0}get vmInstance(){return this.vm}};exports.a=f;//# sourceMappingURL=chunk-K2OUNZZG.cjs.map
|
|
2
|
-
//# sourceMappingURL=chunk-K2OUNZZG.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/vm/VMCheckpoints.ts"],"names":["VMCheckpointer","vm","lineNumber","lineId","variableNames","existing","insertAt","parent","variables","functions","name","fn","val","checkpoint","next","targetIndex","i","cp","key","index","low","high","result","mid","value","names","candidate"],"mappings":"aAuFO,IAAMA,CAAAA,CAAN,KAAqB,CAM3B,WAAA,CAAYC,CAAAA,CAAQ,CAJpB,IAAA,CAAQ,WAAA,CAA8B,EAAC,CAKtC,IAAA,CAAK,EAAA,CAAKA,EACX,CAqBA,QAAA,CACCC,CAAAA,CACAC,CAAAA,CACAC,CAAAA,CACsB,CACtB,GAAIA,CAAAA,CAAc,MAAA,GAAW,CAAA,CAAG,OAAO,IAAA,CAqBvC,IAAMC,CAAAA,CAAW,IAAA,CAAK,mBAAA,CAAoBH,CAAU,CAAA,CAC9CI,CAAAA,CAAWD,CAAAA,EAAY,CAAA,CAAIA,CAAAA,CAAW,IAAA,CAAK,iBAAA,CAAkBH,CAAU,CAAA,CACvEK,CAAAA,CAASD,CAAAA,CAAW,CAAA,CAAI,IAAA,CAAK,WAAA,CAAYA,CAAAA,CAAW,CAAC,EAAI,IAAA,CAgBzDE,CAAAA,CAAmC,MAAA,CAAO,MAAA,CAAO,IAAI,CAAA,CACrDC,CAAAA,CAA6C,MAAA,CAAO,MAAA,CAAO,IAAI,CAAA,CAMrE,IAAA,IAAWC,CAAAA,IAAQN,CAAAA,CAAe,CACjC,GAAI,KAAK,EAAA,CAAG,eAAA,CAAgBM,CAAI,CAAA,CAAG,CAClC,IAAMC,CAAAA,CAAK,IAAA,CAAK,EAAA,CAAG,eAAA,CAAgBD,CAAI,CAAA,CACnCC,CAAAA,GAAIF,CAAAA,CAAUC,CAAI,CAAA,CAAIC,GAC1B,QACD,CACA,IAAMC,CAAAA,CAAM,IAAA,CAAK,EAAA,CAAG,MAAA,CAAOF,CAAI,CAAA,CAC3BE,CAAAA,GAAQ,MAAA,GACXJ,CAAAA,CAAUE,CA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AAA,CAAI,IAAA,CAAO,IAAA,CAAK,WAAA,CAAYA,CAAK,CACjD,CAMA,eAAA,CAAgBjB,CAAAA,CAA8C,CAG7D,IAAMiB,CAAAA,CAAQ,IAAA,CAAK,sBAAA,CAAuBjB,CAAU,CAAA,CACpD,GAAIiB,CAAAA,CAAQ,CAAA,CAAG,OACf,IAAMO,CAAAA,CAAY,KAAK,WAAA,CAAYP,CAAK,CAAA,CACxC,OAAOO,CAAAA,CAAU,UAAA,GAAexB,CAAAA,CAAawB,CAAAA,CAAY,MAC1D,CAMA,iBAAA,EAA6C,CAC5C,OAAO,IAAA,CAAK,WACb,CAgBA,eAAehB,CAAAA,CAAiC,CAC/C,GAAI,IAAA,CAAK,WAAA,CAAY,MAAA,GAAW,CAAA,CAAG,OAEnC,IAAIG,CAAAA,CAAkC,IAAA,CAAK,WAAA,CAAY,IAAA,CAAK,WAAA,CAAY,MAAA,CAAS,CAAC,EAClF,KAAOA,CAAAA,EAAY,CAClB,GAAI,MAAA,CAAO,SAAA,CAAU,cAAA,CAAe,IAAA,CAAKA,CAAAA,CAAW,SAAA,CAAWH,CAAI,CAAA,CAClE,OAAOG,CAAAA,CAAW,SAAA,CAAUH,CAAI,EAEjCG,CAAAA,CAAaA,CAAAA,CAAW,OACzB,CAED,CAQA,KAAA,EAAc,CACb,IAAA,CAAK,WAAA,CAAc,GACpB,CAGA,IAAI,KAAA,EAAgB,CACnB,OAAO,KAAK,WAAA,CAAY,MACzB,CAGA,IAAI,OAAA,EAAmB,CACtB,OAAO,IAAA,CAAK,YAAY,MAAA,GAAW,CACpC,CAGA,IAAI,UAAA,EAAiB,CACpB,OAAO,IAAA,CAAK,EACb,CACD","file":"chunk-K2OUNZZG.cjs","sourcesContent":["import { Value } from \"@solve-js/vm/Value\";\nimport type { VM } from \"@solve-js/vm/OpRegistry\";\nimport type { UserFunctionDef } from \"@solve-js/parser/BytecodeBuilder\";\n\n// ── VMCheckpoint ────────────────────────────────────────────────────────\n\n/**\n * A point-in-time snapshot of VM variable state.\n *\n * Each checkpoint holds only the variables that CHANGED at its line, and\n * reaches the rest through its `parent` link. A lookup walks that chain until\n * it finds the name; a restore walks it from the root applying each link's own\n * bindings in turn, so a later line's value naturally overwrites an earlier\n * one's.\n *\n * ```text\n * Checkpoint 0 (root): {} // empty scope\n * Checkpoint 1 (:x=5): { x: 5 } parent → 0\n * Checkpoint 2 (:y=8): { y: 8 } parent → 1\n * Checkpoint 3 (:x=3): { x: 3 } parent → 2 // shadows x=5\n * ```\n *\n * To look up `x` at checkpoint 3: find own `x=3` → done.\n * To look up `y` at checkpoint 3: not own → walk parent to checkpoint 2 → `y=8`.\n * To look up `z` at checkpoint 3: not found anywhere → undefined.\n *\n * **Memory:** O(number of variable definitions) heap, independent of\n * document length. Typical Obsidian documents have < 100 variable defs,\n * so total checkpoint heap is < 10 KB.\n */\nexport interface VMCheckpoint {\n\t/** 1-based line number where this checkpoint was created. */\n\tlineNumber: number;\n\t/** Persistent line ID from DocumentModel. */\n\tlineId: number;\n\t/**\n\t * Variable name → Value at this checkpoint.\n\t * Only the variables set or updated at this line; the rest are reached\n\t * through {@link VMCheckpoint.parent}.\n\t */\n\tvariables: Record<string, Value>;\n\t/**\n\t * User-defined-function name → definition at this checkpoint. SEPARATE\n\t * from `variables` above (not prototypally chained the same way\n\t * `restoreTo()` replays every checkpoint in the chain in order, so a\n\t * later redefinition of the same function name naturally overwrites an\n\t * earlier one during replay, without needing its own prototype walk).\n\t *\n\t * Without this field, a function definition's checkpoint entry would be\n\t * SILENTLY LOST: `snapshot()` used to call `vm.getVar(name)` for every\n\t * written name, which returns `undefined` for a function name (function\n\t * defs live in `vm.userFunctions`, not the flat variable store), and a\n\t * `val !== undefined` guard silently skipped it. A scroll-triggered\n\t * `restoreTo()` would then reset the VM and replay only `variables`,\n\t * making a function defined above the new viewport vanish (calling it\n\t * would throw `UNDEFINED_FUNCTION`) even though the document still\n\t * shows its definition line as clean/cached.\n\t */\n\tfunctions: Record<string, UserFunctionDef>;\n\t/** Parent checkpoint (closer to document start), or null for root. */\n\tparent: VMCheckpoint | null;\n}\n\n// ── VMCheckpointer ──────────────────────────────────────────────────────\n\n/**\n * Manages VM state checkpoints for the three-tier evaluation strategy.\n *\n * **Checkpoint creation:** After a variable-definition line executes\n * (Tier 1 or Tier 3), `snapshot()` records the current values of the\n * written variables. The checkpoint is linked via prototypal inheritance\n * to the previous checkpoint, so only changed variables consume memory.\n *\n * **Checkpoint restoration:** Before evaluating a viewport whose start line\n * is not line 1, `restoreTo(lineNumber)` resets the VM and replays all\n * variable definitions up to and including that line. This avoids\n * re-evaluating the entire document from line 1 on every scroll.\n *\n * **Thread safety:** Checkpoints are created synchronously on the main\n * thread during evaluation. They are immutable after creation (Value is\n * an immutable type), so no synchronization is needed.\n *\n * **Integration with Phase 5.2e:** `setViewport()` will use `getNearestCheckpoint()`\n * to find the checkpoint just before the new viewport start, then call\n * `restoreTo()` to set up the VM before evaluating only the visible lines.\n * This is the key to O(visible lines) scrolling instead of O(document).\n */\nexport class VMCheckpointer {\n\t/** Ordered array of checkpoints (ascending lineNumber). */\n\tprivate checkpoints: VMCheckpoint[] = [];\n\t/** The VM instance whose variables are snapshotted/restored. */\n\tprivate vm: VM;\n\n\tconstructor(vm: VM) {\n\t\tthis.vm = vm;\n\t}\n\n\t// ── Snapshot ─────────────────────────────────────────────────────\n\n\t/**\n\t * Create a checkpoint at the current line, recording the VM values of\n\t * the specified variables.\n\t *\n\t * Records only what this line wrote; the rest is reached through the\n\t * parent link rather than copied.\n\t *\n\t * A line that is snapshotted again drops every checkpoint at or after it\n\t * first, so the list stays in document order and the new checkpoint\n\t * inherits from the line before it rather than from one after it. See the\n\t * body for what went wrong without that.\n\t *\n\t * @param lineNumber 1-based line position.\n\t * @param lineId Persistent line ID from DocumentModel.\n\t * @param variableNames Names of variables that were written at this line.\n\t * @returns The new checkpoint, or null if no variable names provided.\n\t */\n\tsnapshot(\n\t\tlineNumber: number,\n\t\tlineId: number,\n\t\tvariableNames: string[]\n\t): VMCheckpoint | null {\n\t\tif (variableNames.length === 0) return null;\n\n\t\t// This line's own entry is replaced, and nothing else is touched.\n\t\t//\n\t\t// The list is a sequence of document positions and `restoreTo` reads it\n\t\t// as one, so a re-run must not append after entries that come later in\n\t\t// the document: editing line 2 of a document whose lines 1, 2 and 3 each\n\t\t// define something left the list as [1, 2, 3, 2], and a restore to line\n\t\t// 2 then found the stale entry.\n\t\t//\n\t\t// Replacing rather than truncating is the part that took a second go.\n\t\t// Dropping every entry at or after the line is sound only for a pass\n\t\t// running from line 1, which re-takes them as it continues. A pass\n\t\t// limited to a viewport does not: it re-snapshots the top of the\n\t\t// document and never reaches the definitions below its end line, so the\n\t\t// chain lost them, and `restoreTo` then RESET the VM and replayed a\n\t\t// prefix that no longer mentioned them. A line further down reading one\n\t\t// answered `Undefined variable` where it had answered a number. Absent\n\t\t// is worse than stale here: a stale entry is what the document is\n\t\t// currently showing anyway, and the pass corrects it when it reaches\n\t\t// that line.\n\t\tconst existing = this.indexOfCheckpointAt(lineNumber);\n\t\tconst insertAt = existing >= 0 ? existing : this.insertionIndexFor(lineNumber);\n\t\tconst parent = insertAt > 0 ? this.checkpoints[insertAt - 1] : null;\n\n\t\t// Each checkpoint holds only what its line wrote, and reaches the rest\n\t\t// through `parent`. It used to reach it through the prototype chain\n\t\t// instead, which held the same entries and cost the same memory, and\n\t\t// made the chain as deep as the document has definitions: a null\n\t\t// prototype is a flat object, and one per definition is a chain two\n\t\t// thousand deep on a document of two thousand definitions. Creating and\n\t\t// reading those took a pass over such a document from 6.0 ms to 23.1 ms.\n\t\t//\n\t\t// Nothing needed the inheritance. `restoreTo` walks `parent` and applies\n\t\t// each checkpoint's OWN keys, which is the same set either way, and the\n\t\t// one reader that did walk the prototype now walks `parent` too.\n\t\t//\n\t\t// Null-prototyped rather than `{}`, so a variable named `constructor` or\n\t\t// `toString` is a key like any other.\n\t\tconst variables: Record<string, Value> = Object.create(null) as Record<string, Value>;\n\t\tconst functions: Record<string, UserFunctionDef> = Object.create(null) as Record<string, UserFunctionDef>;\n\n\t\t// Record current VM values for the written names, routing each into\n\t\t// the right bag (a name is either a variable or a user-defined\n\t\t// function, never both; see VMCheckpoint.functions's doc comment for\n\t\t// why this dispatch is required, not optional).\n\t\tfor (const name of variableNames) {\n\t\t\tif (this.vm.hasUserFunction(name)) {\n\t\t\t\tconst fn = this.vm.getUserFunction(name);\n\t\t\t\tif (fn) functions[name] = fn;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst val = this.vm.getVar(name);\n\t\t\tif (val !== undefined) {\n\t\t\t\tvariables[name] = val;\n\t\t\t}\n\t\t}\n\n\t\tconst checkpoint: VMCheckpoint = {\n\t\t\tlineNumber,\n\t\t\tlineId,\n\t\t\tvariables,\n\t\t\tfunctions,\n\t\t\tparent,\n\t\t};\n\t\tif (existing >= 0) this.checkpoints[existing] = checkpoint;\n\t\telse this.checkpoints.splice(insertAt, 0, checkpoint);\n\t\t// The entry after this one now follows a different object.\n\t\tconst next = this.checkpoints[insertAt + 1];\n\t\tif (next !== undefined) next.parent = checkpoint;\n\t\treturn checkpoint;\n\t}\n\n\t// ── Restore ──────────────────────────────────────────────────────\n\n\t/**\n\t * Restore the VM to the state at or just after the given line number.\n\t *\n\t * Finds the nearest checkpoint whose `lineNumber <= targetLineNumber`,\n\t * then replays all variable definitions from root → that checkpoint\n\t * into the VM via `setVar()`. The VM's stack is also reset.\n\t *\n\t * If no checkpoint exists at or before the target line, the VM is\n\t * fully reset (empty scope, empty stack).\n\t *\n\t * **Performance:** O(total variable definitions before the line), since\n\t * each checkpoint in the chain contributes only the names its own line\n\t * wrote.\n\t *\n\t * @param lineNumber Target 1-based line number. The VM will have the\n\t * state that existed AFTER evaluating lines up to `lineNumber`.\n\t */\n\trestoreTo(lineNumber: number): void {\n\t\t// The chain from the root to the target IS the array up to that index.\n\t\t//\n\t\t// Every checkpoint is created with the one before it in the array as its\n\t\t// parent (see {@link snapshot}), and the array is kept in document\n\t\t// order, so walking parent links would visit exactly these entries in\n\t\t// exactly this order. Reading the array instead of the links costs no\n\t\t// allocation, and it was the links that made this quadratic: the walk\n\t\t// runs target-to-root, so the chain was assembled by `unshift`ing each\n\t\t// entry onto the front, which shifts every entry already there. A\n\t\t// document with two thousand definitions did four million shifts per\n\t\t// restore, and a scroll restores.\n\t\t//\n\t\t// `CheckpointsStayInDocumentOrder.spec.ts` asserts the invariant this\n\t\t// relies on, so a change that broke it would fail there rather than\n\t\t// quietly restoring the wrong state here.\n\t\tconst targetIndex = this.nearestCheckpointIndex(lineNumber);\n\n\t\tthis.vm.reset();\n\t\tfor (let i = 0; i <= targetIndex; i++) {\n\t\t\tconst cp = this.checkpoints[i];\n\t\t\t// Only the names this checkpoint's own line wrote; the ones before\n\t\t\t// it are applied by their own entries earlier in this same walk.\n\t\t\tfor (const key of Object.keys(cp.variables)) {\n\t\t\t\tthis.vm.setVar(key, cp.variables[key]);\n\t\t\t}\n\t\t\t// Replay function definitions the same way, a later checkpoint's\n\t\t\t// redefinition of the same name naturally overwrites an earlier\n\t\t\t// one since the walk runs root-to-target.\n\t\t\tfor (const key of Object.keys(cp.functions)) {\n\t\t\t\tconst fn = cp.functions[key];\n\t\t\t\tthis.vm.defineUserFunction(fn.name, fn.params, fn.program);\n\t\t\t}\n\t\t}\n\t}\n\n\t/** The index of the checkpoint recorded exactly at `lineNumber`, or -1. */\n\tprivate indexOfCheckpointAt(lineNumber: number): number {\n\t\tconst index = this.nearestCheckpointIndex(lineNumber);\n\t\treturn index >= 0 && this.checkpoints[index].lineNumber === lineNumber ? index : -1;\n\t}\n\n\t/** Where a checkpoint for `lineNumber` belongs, keeping the list in order. */\n\tprivate insertionIndexFor(lineNumber: number): number {\n\t\treturn this.nearestCheckpointIndex(lineNumber) + 1;\n\t}\n\n\t/**\n\t * The index of the last checkpoint at or before `lineNumber`, or -1.\n\t *\n\t * A binary search rather than a scan. The array is in document order, and\n\t * this is asked once per scroll and once per async batch, on a document\n\t * that can hold a checkpoint per definition.\n\t */\n\tprivate nearestCheckpointIndex(lineNumber: number): number {\n\t\tlet low = 0;\n\t\tlet high = this.checkpoints.length - 1;\n\t\tlet result = -1;\n\t\twhile (low <= high) {\n\t\t\tconst mid = (low + high) >> 1;\n\t\t\tif (this.checkpoints[mid].lineNumber <= lineNumber) {\n\t\t\t\tresult = mid;\n\t\t\t\tlow = mid + 1;\n\t\t\t} else {\n\t\t\t\thigh = mid - 1;\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t}\n\n\t/**\n\t * Record what `lineNumber` has just written, without disturbing the chain\n\t * after it.\n\t *\n\t * {@link snapshot} drops every checkpoint at or after the line, which is\n\t * right for a pass running forward in document order: it re-takes them as it\n\t * goes. A caller re-running a few lines out of a document does not, and\n\t * dropping the entries for lines it will never visit would lose the very\n\t * bindings it is sweeping through them to collect. So this overwrites in\n\t * place instead.\n\t *\n\t * Safe against the prototype chain, because it replaces only the\n\t * checkpoint's OWN bindings: a later checkpoint that also writes the name\n\t * holds its own copy and goes on shadowing this one.\n\t *\n\t * @param lineNumber 1-based line whose recorded bindings are refreshed.\n\t * @param variableNames The names it wrote.\n\t * @returns Whether a checkpoint existed at that line to update.\n\t */\n\tupdateCheckpointAt(lineNumber: number, variableNames: string[]): boolean {\n\t\tconst checkpoint = this.getCheckpointAt(lineNumber);\n\t\tif (!checkpoint) return false;\n\t\tfor (const name of variableNames) {\n\t\t\tif (this.vm.hasUserFunction(name)) {\n\t\t\t\tconst fn = this.vm.getUserFunction(name);\n\t\t\t\tif (fn) checkpoint.functions[name] = fn;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst value = this.vm.getVar(name);\n\t\t\tif (value !== undefined) checkpoint.variables[name] = value;\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t * Apply the bindings recorded AT `lineNumber`, leaving the rest of the VM\n\t * alone.\n\t *\n\t * {@link restoreTo} rebuilds the whole prefix, which costs the chain every\n\t * time it is called. A caller moving forward through the document already\n\t * holds the prefix up to the line before, and needs only what this line\n\t * added: restoring once and then applying each line in turn as it is passed\n\t * costs the chain once rather than once per line.\n\t *\n\t * @param lineNumber 1-based line whose own bindings are applied.\n\t * @returns Whether a checkpoint existed at that line.\n\t */\n\tapplyCheckpointAt(lineNumber: number): boolean {\n\t\tconst checkpoint = this.getCheckpointAt(lineNumber);\n\t\tif (!checkpoint) return false;\n\t\tfor (const key of Object.keys(checkpoint.variables)) {\n\t\t\tthis.vm.setVar(key, checkpoint.variables[key]);\n\t\t}\n\t\tfor (const key of Object.keys(checkpoint.functions)) {\n\t\t\tconst fn = checkpoint.functions[key];\n\t\t\tthis.vm.defineUserFunction(fn.name, fn.params, fn.program);\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t * Drop `names` from every checkpoint, as though no line had ever set them.\n\t *\n\t * A checkpoint records what its line wrote, so a name whose defining line\n\t * has been deleted or edited into something else is still in the chain, and\n\t * the next restore would put it back into the VM after the VM had been told\n\t * to forget it. The two have to agree.\n\t *\n\t * @param names - The names no line defines any more.\n\t */\n\tforget(names: readonly string[]): void {\n\t\tif (names.length === 0) return;\n\t\tfor (const checkpoint of this.checkpoints) {\n\t\t\tfor (const name of names) {\n\t\t\t\tdelete checkpoint.variables[name];\n\t\t\t\tdelete checkpoint.functions[name];\n\t\t\t}\n\t\t}\n\t}\n\n\t// ── Queries ──────────────────────────────────────────────────────\n\n\t/**\n\t * Find the nearest checkpoint at or before the given line number.\n\t *\n\t * Uses linear scan (checkpoints are sorted by lineNumber and the list\n\t * is short, typically < 20 for Obsidian documents). Can be upgraded\n\t * to binary search if needed for documents with 1000+ variable defs.\n\t *\n\t * @returns The nearest checkpoint, or null if none exists before the line.\n\t */\n\tgetNearestCheckpoint(lineNumber: number): VMCheckpoint | null {\n\t\tconst index = this.nearestCheckpointIndex(lineNumber);\n\t\treturn index < 0 ? null : this.checkpoints[index];\n\t}\n\n\t/**\n\t * Get a specific checkpoint by its line number.\n\t * @returns The checkpoint, or undefined if not found.\n\t */\n\tgetCheckpointAt(lineNumber: number): VMCheckpoint | undefined {\n\t\t// Searched, not scanned: the async sweep asks this once for every line\n\t\t// it walks past, and a scan would make that walk quadratic.\n\t\tconst index = this.nearestCheckpointIndex(lineNumber);\n\t\tif (index < 0) return undefined;\n\t\tconst candidate = this.checkpoints[index];\n\t\treturn candidate.lineNumber === lineNumber ? candidate : undefined;\n\t}\n\n\t/**\n\t * Get the entire checkpoint chain from root to the last checkpoint.\n\t * Useful for debugging and serialization.\n\t */\n\tgetAllCheckpoints(): readonly VMCheckpoint[] {\n\t\treturn this.checkpoints;\n\t}\n\n\t/**\n\t * Look up a variable's value through the checkpoint chain.\n\t *\n\t * Walks the prototype chain starting from the most recent checkpoint,\n\t * looking for the variable name as an own property. This is O(depth)\n\t * where depth is the number of checkpoints since the variable was\n\t * last set.\n\t *\n\t * **Note:** This queries the checkpointer's snapshot, not the VM.\n\t * The VM may have been modified since the last snapshot (e.g., by\n\t * Tier 2 execution of non-variable-def lines that don't create checkpoints).\n\t *\n\t * @returns The Value, or undefined if the variable was never set.\n\t */\n\tlookupVariable(name: string): Value | undefined {\n\t\tif (this.checkpoints.length === 0) return undefined;\n\n\t\tlet checkpoint: VMCheckpoint | null = this.checkpoints[this.checkpoints.length - 1];\n\t\twhile (checkpoint) {\n\t\t\tif (Object.prototype.hasOwnProperty.call(checkpoint.variables, name)) {\n\t\t\t\treturn checkpoint.variables[name];\n\t\t\t}\n\t\t\tcheckpoint = checkpoint.parent;\n\t\t}\n\t\treturn undefined;\n\t}\n\n\t// ── Lifecycle ────────────────────────────────────────────────────\n\n\t/**\n\t * Clear all checkpoints. The underlying VM is NOT reset, call\n\t * `vm.reset()` separately if needed.\n\t */\n\tclear(): void {\n\t\tthis.checkpoints = [];\n\t}\n\n\t/** Number of checkpoints stored. */\n\tget count(): number {\n\t\treturn this.checkpoints.length;\n\t}\n\n\t/** Returns true if no checkpoints have been created. */\n\tget isEmpty(): boolean {\n\t\treturn this.checkpoints.length === 0;\n\t}\n\n\t/** The associated VM instance. */\n\tget vmInstance(): VM {\n\t\treturn this.vm;\n\t}\n}\n"]}
|
package/dist/chunk-KZPA4DUF.cjs
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
'use strict';var chunkEFJCC6FJ_cjs=require('./chunk-EFJCC6FJ.cjs'),chunkUOLCBH37_cjs=require('./chunk-UOLCBH37.cjs'),chunkK2OUNZZG_cjs=require('./chunk-K2OUNZZG.cjs'),chunkEPLOL7WC_cjs=require('./chunk-EPLOL7WC.cjs'),chunkUURM7P3P_cjs=require('./chunk-UURM7P3P.cjs'),chunkHNXV35Q2_cjs=require('./chunk-HNXV35Q2.cjs'),chunkNH74IT7B_cjs=require('./chunk-NH74IT7B.cjs'),chunkI4PKEUMZ_cjs=require('./chunk-I4PKEUMZ.cjs'),chunk3MG7VIPL_cjs=require('./chunk-3MG7VIPL.cjs'),chunk6SYU4MH7_cjs=require('./chunk-6SYU4MH7.cjs');var P=class{constructor(){this.root=null;}get length(){return this.root?this.root.size:0}get isEmpty(){return this.root===null}getAt(e){if(!(e<0||e>=(this.root?.size??0)))return this.nodeAt(this.root,e).lineId}insertAt(e,t){let[n,i]=C(this.root,e);this.root=S(S(n,oe(t)),i);}deleteAt(e){if(e<0||e>=(this.root?.size??0))return;let[t,n]=C(this.root,e),[i,s]=C(n,1),r=i?i.lineId:void 0;return this.root=S(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,l]=C(this.root,i),[u,o]=C(l,s),c=le(u),d=O(n,0,n.length);return this.root=S(S(r,d),o),c}replaceAll(e){this.root=O(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,l=i+r;l>t&&e.left&&this.collectRange(e.left,t,n,i,s),l>=t&&l<=n&&s.push(e.lineId),l<n&&e.right&&this.collectRange(e.right,t,n,l+1,s);}};function oe(a){return {lineId:a,size:1,priority:Math.random(),left:null,right:null}}function B(a){a.size=1+(a.left?a.left.size:0)+(a.right?a.right.size:0);}function S(a,e){return a?e?a.priority>e.priority?(a.right=S(a.right,e),B(a),a):(e.left=S(a,e.left),B(e),e):a:e}function C(a,e){if(!a)return [null,null];let t=a.left?a.left.size:0;if(e<=t){let[n,i]=C(a.left,e);return a.left=i,B(a),[n,a]}else {let[n,i]=C(a.right,e-t-1);return a.right=n,B(a),[a,i]}}function le(a){let e=[];return j(a,e),e}function j(a,e){a&&(j(a.left,e),e.push(a.lineId),j(a.right,e));}function O(a,e,t){if(e>=t)return null;let n=Math.floor((e+t)/2),i=ae(a[n]);return {lineId:a[n],size:t-e,priority:i,left:O(a,e,n),right:O(a,n+1,t)}}function ae(a){let e=a+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 R=class{constructor(e=chunkI4PKEUMZ_cjs.b.performance.maxDocumentLines){this.lines=new Map;this.orderTree=new P;this.nextLineId=1;this._positionCache=null;this.dirtyLineIds=new Set;this.tagIndex=null;this.maxLines=e;}setDocument(e){if(chunkUURM7P3P_cjs.b(e,this.maxLines)>this.maxLines)throw chunk6SYU4MH7_cjs.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:chunkEFJCC6FJ_cjs.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,l=[];for(let o of s.insertLines){let c=this.nextLineId++;l.push(c),t.push(c),this.lines.set(c,{lineId:c,textHash:chunkEFJCC6FJ_cjs.a(o),text:o,expressions:[],bytecodes:[],reads:[],writes:[],results:[],result:null,dirty:true,isVariableDef:false,isEmpty:o.trim().length===0,inlineSolveCount:0});}for(let o of l)this.dirtyLineIds.add(o);if(this.tagIndex!==null)for(let o of l)this.indexTags(o,this.lines.get(o).text);let u=this.orderTree.spliceAt(r,s.deleteCount,l);for(let o of u)n.push(o),this.tagIndex!==null&&this.unindexTags(o,this.lines.get(o)?.text??""),this.lines.delete(o),this.dirtyLineIds.delete(o);}return this._positionCache=null,{inserted:t,removed:n}}insertLines(e,t){let n={startLine:e,deleteCount:0,insertLines:t};return this.applyChanges([n]).inserted}deleteLines(e,t){let n={startLine:e,deleteCount:t-e+1,insertLines:[]};return this.applyChanges([n]).removed}editLine(e,t){let n=this.getLineAt(e);if(!n)return false;let i=chunkEFJCC6FJ_cjs.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 chunkEPLOL7WC_cjs.b(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 chunkEPLOL7WC_cjs.b(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,l,u=0){let o=this.lines.get(e);o&&(o.results=t,o.result=t[0]?.[0]??null,o.bytecodes=n,o.expressions=i,o.reads=s,o.writes=r,o.isVariableDef=l,o.inlineSolveCount=u,o.dirty=false,this.dirtyLineIds.delete(e));}updateLineCompiled(e,t,n,i,s,r,l=0){let u=this.lines.get(e);u&&(u.expressions=t,u.bytecodes=n,u.reads=i,u.writes=s,u.isVariableDef=r,u.inlineSolveCount=l);}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 A=class{constructor(){this.worker=null;this.nextId=1;this.pending=new Map;}ensureWorker(){if(this.worker)return this.worker;let e=chunkUOLCBH37_cjs.h();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 l=t.getLineById(r.lineId);if(!l||l.textHash!==r.compiledAgainstHash)continue;let u=n.get(r.lineId);u||(u={bytecodes:[],reads:new Set,writes:new Set,isVariableDef:false,expressions:l.expressions.length>0?[...l.expressions]:[],textHash:r.compiledAgainstHash},n.set(r.lineId,u)),u.bytecodes.push(r.program);for(let o of r.reads)u.reads.add(o);for(let o of r.writes)u.writes.add(o);r.isVariableDef&&(u.isVariableDef=true);}let s=0;for(let[r,l]of n){if(l.bytecodes.length===0)continue;let o=t.getLineById(r)?.inlineSolveCount??0;t.updateLineCompiled(r,l.expressions,l.bytecodes,[...l.reads],[...l.writes],l.isVariableDef,o),s+=l.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 G=128,k=3,te=6,ne=2,ie=k,W=class a{constructor(){this.lastViewportStart=null;this.savedDirection=null;this.pageAccess=new Map;this.accessSeq=0;}static pageForLine(e){return Math.floor((e-1)/G)}static pageRange(e,t){return {startLine:e*G+1,endLine:Math.min((e+1)*G,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=a.pageForLine(e.startLine),s=a.pageForLine(e.endLine),r=a.pageForLine(n),l=Math.max(0,i-k),u=Math.min(r,s+k),o=Math.max(0,i-te),c=Math.min(r,s+te);for(let p=l;p<=u;p++)this.touchPage(p);for(let p=o;p<=c;p++)p>=l&&p<=u||this.evictPageResults(p,t,n);let d=o-1,h=Math.max(0,d-ie+1);for(let p=h;p<=d;p++)this.evictPageBytecode(p,t,n);let g=c+1,f=Math.min(r,g+ie-1);for(let p=g;p<=f;p++)this.evictPageBytecode(p,t,n);}getPreloadTargets(e,t){let n=this.savedDirection;if(!n)return [];let i=[],s=a.pageForLine(e.endLine),r=a.pageForLine(e.startLine),l=a.pageForLine(t.lineCount),u=[];if(n==="down"){let o=s+k+1,c=Math.min(o+ne-1,l);for(let d=o;d<=c&&d<=l;d++)u.push(d);}else {let o=r-k-1;for(let c=o;c>o-ne&&c>=0;c--)u.push(c);}for(let o of u){let c=a.pageRange(o,t.lineCount);for(let d=c.startLine;d<=c.endLine;d++){let h=t.getLineAt(d);if(h&&h.dirty&&!(h.bytecodes.length>0&&!h.isVariableDef)&&!h.isEmpty)if(h.expressions.length>0)for(let g of h.expressions)g.trim()&&i.push({lineId:h.lineId,expression:g,textHash:h.textHash});else {let g=chunk3MG7VIPL_cjs.c.findInlineSolves(h.text);if(g.length>0)for(let f of g)f.expression.trim()&&i.push({lineId:h.lineId,expression:f.expression,textHash:h.textHash});else {let f=h.text.trim();f&&i.push({lineId:h.lineId,expression:f,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=a.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=a.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 re=(i=>(i[i.Tier1=1]="Tier1",i[i.Tier2=2]="Tier2",i[i.Tier3=3]="Tier3",i[i.Skipped=0]="Skipped",i))(re||{}),w=class{constructor(e,t,n){this.compilationWorker=null;this.globalUnsubscribe=null;this.doc=e,this.engine=t,this.dag=t.getDag(),this.checkpointer=n??new chunkK2OUNZZG_cjs.a(t.getVM()),this.pageManager=new W,this.engine.getBatcher().checkpointer=this.checkpointer,this.engine.setDocumentModel(this.doc),this.globalUnsubscribe=chunkHNXV35Q2_cjs.N.subscribe(i=>{for(let s of this.dag.getAffectedLines(chunkHNXV35Q2_cjs.O(i)))this.doc.markDirtyByLineNumber(s);});}evaluate(e,t){this.engine.setKeystrokeSignal(t??null),chunkNH74IT7B_cjs.h();try{this.reseedAccumulators();let n=this.engine.userUnitNames(),i=[],s=new Map,r={tier1:0,tier2:0,tier3:0,skipped:0},l=this.doc.lineCount,u=Math.min(e.endLine,l),o=this.doc.getLineStatesInRange(1,u);for(let d=1;d<=u;d++){let h=o[d-1];if(!h){r.skipped++;continue}let g=d>=e.startLine&&d<=e.endLine,f=this.evaluateSingleLine(h,d,g);i.push(f),f.tier===1?r.tier1++:f.tier===2?r.tier2++:f.tier===3?r.tier3++:r.skipped++,f.results&&g&&s.set(d,f.results.flat());}this.pageManager.maintainAfterEval(e,this.doc),this.engine.settleOrphanedNames();let c=new Set(this.engine.userUnitNames());return n.some(d=>!c.has(d))&&this.engine.invalidateForRemovedUserUnits(),{lines:i,resultMap:s,tierCounts:r}}finally{this.engine.setKeystrokeSignal(null),chunkNH74IT7B_cjs.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 l=this.evaluateSingleLine(r,s,false);t.push(l);}return t}dispatchBackgroundCompiles(e){let t=this.collectInvisibleCompileTargets(e);t.length!==0&&(this.compilationWorker||(this.compilationWorker=new A),this.compilationWorker.compileBatch(t).then(n=>{this.compilationWorker.storeResults(n,this.doc);}).catch(n=>{}));}terminateWorker(){this.compilationWorker&&(this.compilationWorker.terminate(),this.compilationWorker=null),this.globalUnsubscribe&&(this.globalUnsubscribe(),this.globalUnsubscribe=null);}getDoc(){return this.doc}evaluateAll(e){let t={startLine:1,endLine:this.doc.lineCount};return this.evaluate(t,e)}setViewport(e,t){if(this.engine.setKeystrokeSignal(t??null),e.startLine>1&&this.hasDirtyLinesBefore(e.startLine))return this.checkpointer?.clear(),this.evaluate(e,t);this.reseedAccumulators(),this.pageManager.maintainAfterEval(e,this.doc),this.preloadNextPages(e),this.restoreTo(e.startLine-1),chunkNH74IT7B_cjs.h();try{return this.collectEvalResults(e.startLine,e.endLine)}finally{this.engine.setKeystrokeSignal(null),chunkNH74IT7B_cjs.i();}}applyTransaction(e){let t=new Set;for(let r of e)for(let l=0;l<r.deleteCount;l++){let u=r.startLine+l,o=this.dag.getWrites(u);for(let c of o)t.add(c);this.undefineOrphans(this.dag.removeLine(u)),this.engine.undefineUserUnitsFrom(this.doc.getLineAt(u)?.lineId??-1)&&this.engine.invalidateForRemovedUserUnits(),this.engine.getLineCache().removeAllForLine(u);}let n=new Set,i=new Set;for(let r of this.dag.linesReadingAPosition()){let l=this.doc.getLineAt(r);l&&(n.add(l.lineId),i.add(l.lineId));}for(let r of t){let l=this.dag.getAffectedLines(r);for(let u of l){let o=this.doc.getLineAt(u);o&&n.add(o.lineId);}}let s=this.doc.applyChanges(e);this.checkpointer?.clear();for(let r of n)this.doc.markDirty(r);for(let r of i)this.doc.forgetResult(r);return this.dag.clear(),{inserted:s.inserted,removed:s.removed}}reseedAccumulators(){let e=this.engine.resetAccumulators();if(e.size===0)return;let t=this.doc.lineCount;for(let n=1;n<=t;n++){let 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,l=Math.min(t,r);for(let u=e;u<=l;u++){let o=this.doc.getLineAt(u);if(!o)continue;let c=this.evaluateSingleLine(o,u,true);n.push(c),c.tier===1?s.tier1++:c.tier===2?s.tier2++:c.tier===3?s.tier3++:s.skipped++,c.results&&i.set(u,c.results.flat());}return {lines:n,resultMap:i,tierCounts:s}}hasDirtyLinesBefore(e){return this.doc.hasAnyDirtyVariableDefLineBefore(e)}evaluateSingleLine(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||chunkUOLCBH37_cjs.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){e.dirty&&(e.reads=[],e.writes=[],this.registerWithTags(t,[],[]),this.engine.undefineUserUnitsFrom(e.lineId));}registerWithTags(e,t,n){let i=this.doc.getLineAt(e)?.text??"",s=chunkEPLOL7WC_cjs.a(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=[],l=[],u=new Set,o=new Set,c=false,d=null,h=null,g=false,f=false;for(let y of n){if(!y.trim())continue;let b=null,L;try{let m=this.engine.evaluateLine(t,y);b=[m],d=m,L=this.engine.getLineCache().get(t,y);}catch(m){let x=m instanceof Error?m.message:String(m);h||(h=x),g=true,b=null;}if(b&&b.some(m=>m.type===12)&&(f=true),b?r.push(b):r.push([chunkNH74IT7B_cjs.P("eval_failed",h??"unknown error")]),L){l.push(L.bytecode);for(let m of L.readVariables)u.add(m);L.writeVariable&&(o.add(L.writeVariable),c=true);}else try{let{program:m,reads:x,writes:I}=this.engine.compileExpression(y);l.push(m);for(let E of x)u.add(E);for(let E of I)o.add(E);I.length>0&&(c=!0);}catch(m){if(l.push({opcodes:new Uint8Array(0),numbers:new Float64Array(0),strings:[],hasAsync:false}),m instanceof chunk6SYU4MH7_cjs.b&&m.context){let x=m.context.reads,I=m.context.writes;if(Array.isArray(x))for(let E of x)u.add(E);if(Array.isArray(I))for(let E of I)o.add(E);}}}let p=[...u],v=[...o];return g||f?(this.doc.updateLineCompiled(e.lineId,n,l,p,v,c,i),e.results=r,e.result=r[0]?.[0]??null,e.inlineSolveCount=i,e.expressions=n):this.doc.updateLineResult(e.lineId,r,l,n,p,v,c,i),this.registerWithTags(t,p,v),this.checkpointer&&v.length>0&&!g&&!f&&this.checkpointer.snapshot(t,e.lineId,v),{...s,tier:1,result:d,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,l=false;for(let u of e.bytecodes)if(u.opcodes.length!==0)try{let o=this.engine.executeCached(u,t);s=o,i.push([o]);}catch(o){let c=o instanceof Error?o.message:String(o);r||(r=c),l=true,i.push([chunkNH74IT7B_cjs.P("exec_failed",c)]);}return this.registerWithTags(t,e.reads,e.writes),i.length>0?(e.results=i,e.result=i[0][0]??null):e.result!==null&&chunkNH74IT7B_cjs.j()&&(e.results=e.results.map(u=>u.map(chunkNH74IT7B_cjs.k)),e.result=e.results[0]?.[0]??chunkNH74IT7B_cjs.k(e.result)),l&&this.doc.markDirty(e.lineId),this.checkpointer&&e.writes.length>0&&!l&&this.checkpointer.snapshot(t,e.lineId,e.writes),{...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=[],l=new Set,u=new Set,o=false,c=null,d=null,h=false,g=false;for(let v of n)if(v.trim())try{let{program:y,reads:b,writes:L}=this.engine.compileExpression(v);r.push(y);for(let m of b)l.add(m);for(let m of L)u.add(m);L.length>0&&(o=!0),L.length>0&&y.opcodes.length>0&&(c=this.engine.executeCached(y,t),c&&c.type===12&&(g=!0));}catch(y){let b=y instanceof Error?y.message:String(y);d||(d=b),h=true,r.push({opcodes:new Uint8Array(0),numbers:new Float64Array(0),strings:[],hasAsync:false});}let f=[...l],p=[...u];return this.doc.updateLineCompiled(e.lineId,n,r,f,p,o,i),this.registerWithTags(t,f,p),o&&c&&!h&&!g&&(e.results=[[c]],e.result=c,this.doc.markClean(e.lineId),this.checkpointer&&this.checkpointer.snapshot(t,e.lineId,p)),{...s,tier:3,result:c,results:o&&c&&!h&&!g?[[c]]:void 0,error:d}}restoreTo(e){this.checkpointer&&this.checkpointer.restoreTo(e);}getCheckpointer(){return this.checkpointer}getPageManager(){return this.pageManager}preloadNextPages(e){let t=this.pageManager.getPreloadTargets(e,this.doc);t.length!==0&&(this.compilationWorker||(this.compilationWorker=new A),this.compilationWorker.compileBatch(t).then(n=>{this.compilationWorker.storeResults(n,this.doc);}).catch(n=>{}));}collectInvisibleCompileTargets(e){let t=[],n=this.doc.lineCount,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||chunkUOLCBH37_cjs.m(r.text))continue;let{expressions:l}=this.extractExpressions(r);if(l.length!==0)for(let u of l)u.trim()&&t.push({lineId:r.lineId,expression:u,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=chunk3MG7VIPL_cjs.c.findInlineSolves(e.text);return n.length>0?{expressions:n.map(i=>i.expression),inlineSolveCount:n.length}:{expressions:[t],inlineSolveCount:0}}};function se(a){return typeof a.unit=="string"?a.unit:String(a.value)}function ue(a,e,t={inputType:"markdown"}){let n=a.getDocumentModel(),i=new R;i.setDocument(e);let s=new w(i,a,new chunkK2OUNZZG_cjs.a(a.getVM()));try{let r=i.lineCount;s.evaluate({startLine:1,endLine:r});let l=[],u=[],o=0;for(let c=1;c<=r;c++){let d=i.getLineAt(c),h=d.text,g=o,f=o+h.length;o=f+1;let p=d.inlineSolveCount>0,v=[],y=null,b=null;d.isEmpty||(p?v=chunkUOLCBH37_cjs.n(h,c).map((L,m)=>{let x=d.results[m]?.[0]??null;if(x&&x.type===13){let I=se(x);return u.push(`Line ${c}: ${I}`),{...L,result:null,error:I}}return {...L,result:x,error:null}}):(y=d.expressions[0]??null,b=d.result??null,b&&b.type===13&&u.push(`Line ${c}: ${se(b)}`))),l.push({lineNumber:c,text:h,startPosition:g,endPosition:f,isEmpty:d.isEmpty,hasInlineSolves:p,inlineSolves:v,expression:y,error:null,result:b});}return {lines:l,totalLines:r,errors:u}}finally{s.terminateWorker(),a.setDocumentModel(n);}}exports.a=R;exports.b=re;exports.c=w;exports.d=ue;//# sourceMappingURL=chunk-KZPA4DUF.cjs.map
|
|
3
|
-
//# sourceMappingURL=chunk-KZPA4DUF.cjs.map
|