solve-engine 2.2.0 → 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/dist/{Configuration-B6W0-T67.d.cts → Configuration-BGQn-cJ8.d.cts} +38 -0
  2. package/dist/{Configuration-B6W0-T67.d.ts → Configuration-BGQn-cJ8.d.ts} +38 -0
  3. package/dist/FormattingSettings-bRKjU7wI.d.cts +47 -0
  4. package/dist/FormattingSettings-bRKjU7wI.d.ts +47 -0
  5. package/dist/{PackageCompatibility-DBsZ0l2a.d.ts → PackageCompatibility-UsSZIfHs.d.ts} +1 -1
  6. package/dist/{PackageCompatibility-Cv7zjqSV.d.cts → PackageCompatibility-cEClSSkz.d.cts} +1 -1
  7. package/dist/{PackageRegistry-DRbqNJfI.d.ts → PackageRegistry-B3yJHSxX.d.ts} +24 -1
  8. package/dist/{PackageRegistry-BSGQ6saH.d.cts → PackageRegistry-BsLmAVZJ.d.cts} +24 -1
  9. package/dist/{chunk-7NXAZJDB.js → chunk-5R7S5KJJ.js} +3 -3
  10. package/dist/{chunk-7NXAZJDB.js.map → chunk-5R7S5KJJ.js.map} +1 -1
  11. package/dist/chunk-6ZNNPXXE.cjs +3 -0
  12. package/dist/chunk-6ZNNPXXE.cjs.map +1 -0
  13. package/dist/{chunk-7GK3XEZF.js → chunk-7E7NXKQ5.js} +2 -2
  14. package/dist/chunk-7E7NXKQ5.js.map +1 -0
  15. package/dist/chunk-AR7L5OJ2.js +2 -0
  16. package/dist/chunk-AR7L5OJ2.js.map +1 -0
  17. package/dist/chunk-B5NBFGNP.js +3 -0
  18. package/dist/chunk-B5NBFGNP.js.map +1 -0
  19. package/dist/{chunk-6C6IPUBH.cjs → chunk-E2ZSMJEL.cjs} +3 -3
  20. package/dist/{chunk-6C6IPUBH.cjs.map → chunk-E2ZSMJEL.cjs.map} +1 -1
  21. package/dist/chunk-GALZNKW7.js +3 -0
  22. package/dist/chunk-GALZNKW7.js.map +1 -0
  23. package/dist/{chunk-ZCNBT44X.cjs → chunk-LNZNJSRW.cjs} +2 -2
  24. package/dist/chunk-LNZNJSRW.cjs.map +1 -0
  25. package/dist/chunk-MMT2LS5I.cjs +2 -0
  26. package/dist/chunk-MMT2LS5I.cjs.map +1 -0
  27. package/dist/chunk-NAMMTJBE.cjs +3 -0
  28. package/dist/chunk-NAMMTJBE.cjs.map +1 -0
  29. package/dist/chunk-NXIMGB4S.cjs +2 -0
  30. package/dist/chunk-NXIMGB4S.cjs.map +1 -0
  31. package/dist/chunk-UA3BGOYT.js +5 -0
  32. package/dist/chunk-UA3BGOYT.js.map +1 -0
  33. package/dist/chunk-UGQM6ZXU.js +2 -0
  34. package/dist/chunk-UGQM6ZXU.js.map +1 -0
  35. package/dist/chunk-WYAY6WPQ.cjs +5 -0
  36. package/dist/chunk-WYAY6WPQ.cjs.map +1 -0
  37. package/dist/constants.cjs +1 -1
  38. package/dist/constants.d.cts +1 -1
  39. package/dist/constants.d.ts +1 -1
  40. package/dist/constants.js +1 -1
  41. package/dist/engine.cjs +1 -1
  42. package/dist/engine.d.cts +5 -5
  43. package/dist/engine.d.ts +5 -5
  44. package/dist/engine.js +1 -1
  45. package/dist/format.cjs +1 -1
  46. package/dist/format.d.cts +2 -2
  47. package/dist/format.d.ts +2 -2
  48. package/dist/format.js +1 -1
  49. package/dist/index.cjs +1 -1
  50. package/dist/index.d.cts +4 -4
  51. package/dist/index.d.ts +4 -4
  52. package/dist/index.js +1 -1
  53. package/dist/language.d.cts +3 -3
  54. package/dist/language.d.ts +3 -3
  55. package/dist/packages.cjs +1 -1
  56. package/dist/packages.d.cts +11 -2
  57. package/dist/packages.d.ts +11 -2
  58. package/dist/packages.js +1 -1
  59. package/dist/resolvers.cjs +1 -1
  60. package/dist/resolvers.d.cts +14 -0
  61. package/dist/resolvers.d.ts +14 -0
  62. package/dist/resolvers.js +1 -1
  63. package/dist/testing.cjs +2 -2
  64. package/dist/testing.d.cts +3 -3
  65. package/dist/testing.d.ts +3 -3
  66. package/dist/testing.js +1 -1
  67. package/dist/worker.cjs +2 -2
  68. package/dist/worker.d.cts +3 -3
  69. package/dist/worker.d.ts +3 -3
  70. package/dist/worker.js +1 -1
  71. package/package.json +1 -1
  72. package/dist/FormattingSettings-CJHyxcYu.d.cts +0 -27
  73. package/dist/FormattingSettings-CJHyxcYu.d.ts +0 -27
  74. package/dist/chunk-7BXPCWKM.cjs +0 -2
  75. package/dist/chunk-7BXPCWKM.cjs.map +0 -1
  76. package/dist/chunk-7GK3XEZF.js.map +0 -1
  77. package/dist/chunk-E2Q3PQ2G.js +0 -3
  78. package/dist/chunk-E2Q3PQ2G.js.map +0 -1
  79. package/dist/chunk-HLBYHXQD.cjs +0 -3
  80. package/dist/chunk-HLBYHXQD.cjs.map +0 -1
  81. package/dist/chunk-J4LZD4ZY.js +0 -3
  82. package/dist/chunk-J4LZD4ZY.js.map +0 -1
  83. package/dist/chunk-KVTOV3TZ.js +0 -2
  84. package/dist/chunk-KVTOV3TZ.js.map +0 -1
  85. package/dist/chunk-OVKDDTXO.cjs +0 -3
  86. package/dist/chunk-OVKDDTXO.cjs.map +0 -1
  87. package/dist/chunk-TN5E6JU6.js +0 -2
  88. package/dist/chunk-TN5E6JU6.js.map +0 -1
  89. package/dist/chunk-U2UZJX5W.cjs +0 -5
  90. package/dist/chunk-U2UZJX5W.cjs.map +0 -1
  91. package/dist/chunk-X3R7B7XM.cjs +0 -2
  92. package/dist/chunk-X3R7B7XM.cjs.map +0 -1
  93. package/dist/chunk-YU3PACLE.js +0 -5
  94. package/dist/chunk-YU3PACLE.js.map +0 -1
  95. package/dist/chunk-ZCNBT44X.cjs.map +0 -1
@@ -48,7 +48,28 @@ type HolidayCalendar = HolidayPredicate | Iterable<string | number | Date>;
48
48
  * Controls the bounds and formatting for date/time expression evaluation
49
49
  * (e.g., `today + 20 days`, `last monday`).
50
50
  */
51
+ /**
52
+ * How an ambiguous all-numeric date literal is read.
53
+ *
54
+ * - `'auto'`: by separator, the historic behaviour. A slash date is
55
+ * day-first (`25/12/2023`), a hyphen date is month-first (`12-25-2023`)
56
+ * unless its first group is four digits, which makes it ISO (`2023-12-25`).
57
+ * - `'DMY'` / `'MDY'` / `'YMD'`: a fixed order for every numeric separator, so
58
+ * a host can match its readers' locale. `'MDY'` is what lets a US reader's
59
+ * `12/25/2023` parse, which `'auto'` refuses because the slash defaults to
60
+ * day-first.
61
+ *
62
+ * Only the all-numeric literals are affected. A spelled-out month (`March 9,
63
+ * 2024`) is never ambiguous, and an ISO timestamp is always read as ISO.
64
+ */
65
+ type DateInputOrder = 'auto' | 'DMY' | 'MDY' | 'YMD';
66
+ /** Date-related engine configuration: offset limits, input order, holidays. */
51
67
  interface DateConfig {
68
+ /**
69
+ * The order an ambiguous all-numeric date literal is read in. Defaults to
70
+ * `'auto'` (by separator, the historic behaviour). See {@link DateInputOrder}.
71
+ */
72
+ readonly inputOrder: DateInputOrder;
52
73
  /**
53
74
  * How far forward a date offset whose COST grows with the offset may reach,
54
75
  * in years. Enforced by `vm/VM.ts`'s `addBusinessDays()`.
@@ -171,6 +192,21 @@ interface DiagnosticConfig {
171
192
  /** Enable VM trace mode, emits per-opcode execution events (very verbose; disables some optimizations) */
172
193
  readonly vmTraceEnabled: boolean;
173
194
  }
195
+ /**
196
+ * Proactive background refresh of live async values.
197
+ *
198
+ * Off by default. When a live value (a stock quote, an FX rate) has gone
199
+ * stale, today it only refetches on the next re-evaluation (a keystroke), so a
200
+ * note left open silently ages. With this enabled, the engine drives a refetch
201
+ * on each such value's own cadence (the resolver's `refetchIntervalMs`) for the
202
+ * values currently on screen, and pushes the fresh result to the host through
203
+ * the same event stream the pull path uses. It needs timers and a live editor
204
+ * consuming that stream, so a headless or batch host leaves it off.
205
+ */
206
+ interface BackgroundRefreshConfig {
207
+ /** Master switch. When false, no timers run and every value refreshes only on re-evaluation. */
208
+ readonly enabled: boolean;
209
+ }
174
210
  /**
175
211
  * Virtual Machine configuration.
176
212
  * Controls the internal bytecode VM that executes compiled expressions.
@@ -283,6 +319,8 @@ interface EngineConfig {
283
319
  readonly worker: WorkerConfig;
284
320
  /** Diagnostic pipeline configuration */
285
321
  readonly diagnostic: DiagnosticConfig;
322
+ /** Proactive background refresh of live async values */
323
+ readonly backgroundRefresh: BackgroundRefreshConfig;
286
324
  }
287
325
  /**
288
326
  * A partial {@link EngineConfig} override, one section at a time.
@@ -48,7 +48,28 @@ type HolidayCalendar = HolidayPredicate | Iterable<string | number | Date>;
48
48
  * Controls the bounds and formatting for date/time expression evaluation
49
49
  * (e.g., `today + 20 days`, `last monday`).
50
50
  */
51
+ /**
52
+ * How an ambiguous all-numeric date literal is read.
53
+ *
54
+ * - `'auto'`: by separator, the historic behaviour. A slash date is
55
+ * day-first (`25/12/2023`), a hyphen date is month-first (`12-25-2023`)
56
+ * unless its first group is four digits, which makes it ISO (`2023-12-25`).
57
+ * - `'DMY'` / `'MDY'` / `'YMD'`: a fixed order for every numeric separator, so
58
+ * a host can match its readers' locale. `'MDY'` is what lets a US reader's
59
+ * `12/25/2023` parse, which `'auto'` refuses because the slash defaults to
60
+ * day-first.
61
+ *
62
+ * Only the all-numeric literals are affected. A spelled-out month (`March 9,
63
+ * 2024`) is never ambiguous, and an ISO timestamp is always read as ISO.
64
+ */
65
+ type DateInputOrder = 'auto' | 'DMY' | 'MDY' | 'YMD';
66
+ /** Date-related engine configuration: offset limits, input order, holidays. */
51
67
  interface DateConfig {
68
+ /**
69
+ * The order an ambiguous all-numeric date literal is read in. Defaults to
70
+ * `'auto'` (by separator, the historic behaviour). See {@link DateInputOrder}.
71
+ */
72
+ readonly inputOrder: DateInputOrder;
52
73
  /**
53
74
  * How far forward a date offset whose COST grows with the offset may reach,
54
75
  * in years. Enforced by `vm/VM.ts`'s `addBusinessDays()`.
@@ -171,6 +192,21 @@ interface DiagnosticConfig {
171
192
  /** Enable VM trace mode, emits per-opcode execution events (very verbose; disables some optimizations) */
172
193
  readonly vmTraceEnabled: boolean;
173
194
  }
195
+ /**
196
+ * Proactive background refresh of live async values.
197
+ *
198
+ * Off by default. When a live value (a stock quote, an FX rate) has gone
199
+ * stale, today it only refetches on the next re-evaluation (a keystroke), so a
200
+ * note left open silently ages. With this enabled, the engine drives a refetch
201
+ * on each such value's own cadence (the resolver's `refetchIntervalMs`) for the
202
+ * values currently on screen, and pushes the fresh result to the host through
203
+ * the same event stream the pull path uses. It needs timers and a live editor
204
+ * consuming that stream, so a headless or batch host leaves it off.
205
+ */
206
+ interface BackgroundRefreshConfig {
207
+ /** Master switch. When false, no timers run and every value refreshes only on re-evaluation. */
208
+ readonly enabled: boolean;
209
+ }
174
210
  /**
175
211
  * Virtual Machine configuration.
176
212
  * Controls the internal bytecode VM that executes compiled expressions.
@@ -283,6 +319,8 @@ interface EngineConfig {
283
319
  readonly worker: WorkerConfig;
284
320
  /** Diagnostic pipeline configuration */
285
321
  readonly diagnostic: DiagnosticConfig;
322
+ /** Proactive background refresh of live async values */
323
+ readonly backgroundRefresh: BackgroundRefreshConfig;
286
324
  }
287
325
  /**
288
326
  * A partial {@link EngineConfig} override, one section at a time.
@@ -0,0 +1,47 @@
1
+ /**
2
+ * How a Datetime value is rendered.
3
+ *
4
+ * - `'long'`: the spelled-out form, "Tuesday, March 10, 2026" (the default).
5
+ * - `'iso'`: "2026-03-10" (ISO 8601, with a `T`-separated time when present).
6
+ * - `'dmy'`: "10/03/2026" (day first).
7
+ * - `'mdy'`: "03/10/2026" (month first).
8
+ *
9
+ * The weekday and long month name in `'long'` are localised through the same
10
+ * locale the number separators come from; the numeric forms are locale-neutral.
11
+ */
12
+ type DateOutputFormat = "long" | "iso" | "dmy" | "mdy";
13
+ /**
14
+ * Minimal formatting settings interface for the engine
15
+ * This allows the engine to format values without depending on app-specific settings
16
+ */
17
+ interface FormattingSettings {
18
+ floatResult: {
19
+ decimalPlaces: number;
20
+ enableSeperator: boolean;
21
+ };
22
+ numberResult: {
23
+ decimalSeparatorLocale: string;
24
+ };
25
+ hexResult: {
26
+ enablePadding: boolean;
27
+ paddingZeros: number;
28
+ };
29
+ unitOfMeasurementResult: {
30
+ decimalPlaces: number;
31
+ };
32
+ percentageResult: {
33
+ decimalPlaces: number;
34
+ };
35
+ /**
36
+ * Optional so a host that built a `FormattingSettings` before this field
37
+ * existed still compiles; a missing `dateResult` reads as `'long'`, the
38
+ * historic output.
39
+ */
40
+ dateResult?: {
41
+ format: DateOutputFormat;
42
+ };
43
+ }
44
+ /** Formatting used when a host supplies none. */
45
+ declare const DEFAULT_FORMATTING_SETTINGS: FormattingSettings;
46
+
47
+ export { DEFAULT_FORMATTING_SETTINGS as D, type FormattingSettings as F };
@@ -0,0 +1,47 @@
1
+ /**
2
+ * How a Datetime value is rendered.
3
+ *
4
+ * - `'long'`: the spelled-out form, "Tuesday, March 10, 2026" (the default).
5
+ * - `'iso'`: "2026-03-10" (ISO 8601, with a `T`-separated time when present).
6
+ * - `'dmy'`: "10/03/2026" (day first).
7
+ * - `'mdy'`: "03/10/2026" (month first).
8
+ *
9
+ * The weekday and long month name in `'long'` are localised through the same
10
+ * locale the number separators come from; the numeric forms are locale-neutral.
11
+ */
12
+ type DateOutputFormat = "long" | "iso" | "dmy" | "mdy";
13
+ /**
14
+ * Minimal formatting settings interface for the engine
15
+ * This allows the engine to format values without depending on app-specific settings
16
+ */
17
+ interface FormattingSettings {
18
+ floatResult: {
19
+ decimalPlaces: number;
20
+ enableSeperator: boolean;
21
+ };
22
+ numberResult: {
23
+ decimalSeparatorLocale: string;
24
+ };
25
+ hexResult: {
26
+ enablePadding: boolean;
27
+ paddingZeros: number;
28
+ };
29
+ unitOfMeasurementResult: {
30
+ decimalPlaces: number;
31
+ };
32
+ percentageResult: {
33
+ decimalPlaces: number;
34
+ };
35
+ /**
36
+ * Optional so a host that built a `FormattingSettings` before this field
37
+ * existed still compiles; a missing `dateResult` reads as `'long'`, the
38
+ * historic output.
39
+ */
40
+ dateResult?: {
41
+ format: DateOutputFormat;
42
+ };
43
+ }
44
+ /** Formatting used when a host supplies none. */
45
+ declare const DEFAULT_FORMATTING_SETTINGS: FormattingSettings;
46
+
47
+ export { DEFAULT_FORMATTING_SETTINGS as D, type FormattingSettings as F };
@@ -1,4 +1,4 @@
1
- import { I as IEnginePackage } from './PackageRegistry-DRbqNJfI.js';
1
+ import { I as IEnginePackage } from './PackageRegistry-B3yJHSxX.js';
2
2
 
3
3
  /**
4
4
  * Package load-time compatibility checking, the "detect overlapping
@@ -1,4 +1,4 @@
1
- import { I as IEnginePackage } from './PackageRegistry-BSGQ6saH.cjs';
1
+ import { I as IEnginePackage } from './PackageRegistry-BsLmAVZJ.cjs';
2
2
 
3
3
  /**
4
4
  * Package load-time compatibility checking, the "detect overlapping
@@ -9,7 +9,7 @@ import { QueryClient } from '@tanstack/query-core';
9
9
  import { E as EngineError } from './EngineError-Ce1lPkjZ.js';
10
10
  import { a as DiagnosticReportJSON, D as DiagnosticPipeline } from './pipeline-72QmQlGx.js';
11
11
  import { T as Token } from './Token-CbP_OutD.js';
12
- import { E as EngineConfigOverride, a as EngineConfig } from './Configuration-B6W0-T67.js';
12
+ import { E as EngineConfigOverride, a as EngineConfig } from './Configuration-BGQn-cJ8.js';
13
13
 
14
14
  /**
15
15
  * One line's compiled bytecode, plus the variables it reads and writes.
@@ -1690,6 +1690,17 @@ declare class ExpressionEngine {
1690
1690
  * DAG walk + re-evaluation pass. Replaces the old single-callback pattern.
1691
1691
  */
1692
1692
  private batcher;
1693
+ /**
1694
+ * Drives proactive background refresh of live values, or `null` when the
1695
+ * host has not enabled it (the default). See {@link BackgroundRefreshManager}.
1696
+ */
1697
+ private readonly backgroundRefresh;
1698
+ /**
1699
+ * The signal a background re-evaluation is dispatched under. Never aborted
1700
+ * (a background refetch is not tied to a keystroke), so the batcher treats
1701
+ * its results as current; the manager's own timers are what stop the work.
1702
+ */
1703
+ private readonly backgroundRefreshSignal;
1693
1704
  /** Post-lexer token normalizer for phrase fusion, implicit multiply, etc. */
1694
1705
  private normalizer;
1695
1706
  /**
@@ -1848,6 +1859,18 @@ declare class ExpressionEngine {
1848
1859
  * and fires typed events to all listeners.
1849
1860
  */
1850
1861
  private resolveAsync;
1862
+ /**
1863
+ * Start refreshing a value in the background if it declared a cadence and the
1864
+ * host enabled background refresh. A no-op otherwise, so the pull path is
1865
+ * unchanged for a headless host or a value that never wants it.
1866
+ */
1867
+ private registerBackgroundRefresh;
1868
+ /**
1869
+ * How many live values are currently being refreshed in the background.
1870
+ * Zero when the host has not enabled background refresh. For hosts that want
1871
+ * to surface it, and for tests.
1872
+ */
1873
+ getBackgroundRefreshCount(): number;
1851
1874
  /**
1852
1875
  * Unified parsing method that handles different input types and returns comprehensive results
1853
1876
  * with precise coordinate mapping for inline solves.
@@ -9,7 +9,7 @@ import { QueryClient } from '@tanstack/query-core';
9
9
  import { E as EngineError } from './EngineError-Ce1lPkjZ.cjs';
10
10
  import { a as DiagnosticReportJSON, D as DiagnosticPipeline } from './pipeline-DCQicwWX.cjs';
11
11
  import { T as Token } from './Token-CbP_OutD.cjs';
12
- import { E as EngineConfigOverride, a as EngineConfig } from './Configuration-B6W0-T67.cjs';
12
+ import { E as EngineConfigOverride, a as EngineConfig } from './Configuration-BGQn-cJ8.cjs';
13
13
 
14
14
  /**
15
15
  * One line's compiled bytecode, plus the variables it reads and writes.
@@ -1690,6 +1690,17 @@ declare class ExpressionEngine {
1690
1690
  * DAG walk + re-evaluation pass. Replaces the old single-callback pattern.
1691
1691
  */
1692
1692
  private batcher;
1693
+ /**
1694
+ * Drives proactive background refresh of live values, or `null` when the
1695
+ * host has not enabled it (the default). See {@link BackgroundRefreshManager}.
1696
+ */
1697
+ private readonly backgroundRefresh;
1698
+ /**
1699
+ * The signal a background re-evaluation is dispatched under. Never aborted
1700
+ * (a background refetch is not tied to a keystroke), so the batcher treats
1701
+ * its results as current; the manager's own timers are what stop the work.
1702
+ */
1703
+ private readonly backgroundRefreshSignal;
1693
1704
  /** Post-lexer token normalizer for phrase fusion, implicit multiply, etc. */
1694
1705
  private normalizer;
1695
1706
  /**
@@ -1848,6 +1859,18 @@ declare class ExpressionEngine {
1848
1859
  * and fires typed events to all listeners.
1849
1860
  */
1850
1861
  private resolveAsync;
1862
+ /**
1863
+ * Start refreshing a value in the background if it declared a cadence and the
1864
+ * host enabled background refresh. A no-op otherwise, so the pull path is
1865
+ * unchanged for a headless host or a value that never wants it.
1866
+ */
1867
+ private registerBackgroundRefresh;
1868
+ /**
1869
+ * How many live values are currently being refreshed in the background.
1870
+ * Zero when the host has not enabled background refresh. For hosts that want
1871
+ * to surface it, and for tests.
1872
+ */
1873
+ getBackgroundRefreshCount(): number;
1851
1874
  /**
1852
1875
  * Unified parsing method that handles different input types and returns comprehensive results
1853
1876
  * with precise coordinate mapping for inline solves.
@@ -1,3 +1,3 @@
1
- import {a}from'./chunk-RAF57WYO.js';import {l,m,g}from'./chunk-YU3PACLE.js';import {b as b$1}from'./chunk-76F3LCIL.js';import {J,K}from'./chunk-W2JAR233.js';import {h,i,N}from'./chunk-EVAOPEO4.js';import {b}from'./chunk-KVTOV3TZ.js';import {c as c$1}from'./chunk-YAHGSBMC.js';import {c,b as b$2}from'./chunk-MPB7KUN5.js';var P=class{constructor(){this.root=null;}get length(){return this.root?this.root.size:0}get isEmpty(){return this.root===null}getAt(e){if(!(e<0||e>=(this.root?.size??0)))return this.nodeAt(this.root,e).lineId}insertAt(e,t){let[n,r]=I(this.root,e);this.root=C(C(n,te(t)),r);}deleteAt(e){if(e<0||e>=(this.root?.size??0))return;let[t,n]=I(this.root,e),[r,s]=I(n,1),i=r?r.lineId:void 0;return this.root=C(t,s),i}spliceAt(e,t,n){let r=Math.max(0,e),s=Math.min(Math.max(0,t),(this.root?.size??0)-r),[i,a]=I(this.root,r),[l,o]=I(a,s),c=ne(l),d=B(n,0,n.length);return this.root=C(C(i,d),o),c}replaceAll(e){this.root=B(e,0,e.length);}getRange(e,t){let n=Math.max(0,e),r=Math.min((this.root?.size??0)-1,t);if(n>r)return [];let s=[];return this.collectRange(this.root,n,r,0,s),s}clear(){this.root=null;}*[Symbol.iterator](){yield*this.inOrder(this.root);}*inOrder(e){e&&(yield*this.inOrder(e.left),yield e.lineId,yield*this.inOrder(e.right));}nodeAt(e,t){let n=e.left?e.left.size:0;return t<n?this.nodeAt(e.left,t):t===n?e:this.nodeAt(e.right,t-n-1)}collectRange(e,t,n,r,s){if(!e)return;let i=e.left?e.left.size:0,a=r+i;a>t&&e.left&&this.collectRange(e.left,t,n,r,s),a>=t&&a<=n&&s.push(e.lineId),a<n&&e.right&&this.collectRange(e.right,t,n,a+1,s);}};function te(u){return {lineId:u,size:1,priority:Math.random(),left:null,right:null}}function T(u){u.size=1+(u.left?u.left.size:0)+(u.right?u.right.size:0);}function C(u,e){return u?e?u.priority>e.priority?(u.right=C(u.right,e),T(u),u):(e.left=C(u,e.left),T(e),e):u:e}function I(u,e){if(!u)return [null,null];let t=u.left?u.left.size:0;if(e<=t){let[n,r]=I(u.left,e);return u.left=r,T(u),[n,u]}else {let[n,r]=I(u.right,e-t-1);return u.right=n,T(u),[u,r]}}function ne(u){let e=[];return F(u,e),e}function F(u,e){u&&(F(u.left,e),e.push(u.lineId),F(u.right,e));}function B(u,e,t){if(e>=t)return null;let n=Math.floor((e+t)/2),r=re(n);return {lineId:u[n],size:t-e,priority:r,left:B(u,e,n),right:B(u,n+1,t)}}function re(u){let e=u;return e=(e>>16^e)*73244475,e=(e>>16^e)*73244475,e=e>>16^e,e/4294967295}var R=class{constructor(e=b.performance.maxDocumentLines){this.lines=new Map;this.orderTree=new P;this.nextLineId=1;this._positionCache=null;this.dirtyLineIds=new Set;this.maxLines=e;}setDocument(e){if(b$1(e,this.maxLines)>this.maxLines)throw c.execution("DOCUMENT_TOO_LARGE",`This document has more than ${this.maxLines.toLocaleString("en-US")} lines, which is the most the engine will hold at once`,{maxLines:this.maxLines});this.lines.clear(),this.orderTree.clear(),this._positionCache=null,this.dirtyLineIds.clear(),this.nextLineId=1;let n=e.split(`
2
- `),r=new Array(n.length);for(let s=0;s<n.length;s++){let i=this.nextLineId++;r[s]=i,this.lines.set(i,{lineId:i,textHash:a(n[s]),text:n[s],expressions:[],bytecodes:[],reads:[],writes:[],results:[],result:null,dirty:true,isVariableDef:false,isEmpty:n[s].trim().length===0,inlineSolveCount:0});}this.orderTree.replaceAll(r);for(let s of r)this.dirtyLineIds.add(s);}applyChanges(e){let t=[],n=[],r=[...e].sort((s,i)=>i.startLine-s.startLine);for(let s of r){let i=s.startLine-1,a$1=[];for(let o of s.insertLines){let c=this.nextLineId++;a$1.push(c),t.push(c),this.lines.set(c,{lineId:c,textHash:a(o),text:o,expressions:[],bytecodes:[],reads:[],writes:[],results:[],result:null,dirty:true,isVariableDef:false,isEmpty:o.trim().length===0,inlineSolveCount:0});}for(let o of a$1)this.dirtyLineIds.add(o);let l=this.orderTree.spliceAt(i,s.deleteCount,a$1);for(let o of l)n.push(o),this.lines.delete(o),this.dirtyLineIds.delete(o);}return this._positionCache=null,{inserted:t,removed:n}}insertLines(e,t){let n={startLine:e,deleteCount:0,insertLines:t};return this.applyChanges([n]).inserted}deleteLines(e,t){let n={startLine:e,deleteCount:t-e+1,insertLines:[]};return this.applyChanges([n]).removed}editLine(e,t){let n=this.getLineAt(e);if(!n)return false;let r=a(t);return r===n.textHash?false:(n.text=t,n.textHash=r,n.expressions=[],n.bytecodes=[],n.results=[],n.result=null,n.inlineSolveCount=0,n.dirty=true,this.dirtyLineIds.add(n.lineId),n.isEmpty=t.trim().length===0,true)}getLineAt(e){let t=e-1,n=this.orderTree.getAt(t);if(n!==void 0)return this.lines.get(n)}getLinePosition(e){if(this._positionCache)return this._positionCache.get(e)??-1;this._positionCache=new Map;let t=1;for(let n of this.orderTree)this._positionCache.set(n,t++);return this._positionCache.get(e)??-1}getVisibleLines(e,t){let n=this.orderTree.getRange(e-1,t-1),r=[];for(let s of n){let i=this.lines.get(s);i&&r.push(i);}return r}getAllLines(){return this.getVisibleLines(1,this.lineCount)}getLineById(e){return this.lines.get(e)}getDirtyLines(){let e=[];for(let t of this.lines.values())t.dirty&&e.push(t);return e}hasAnyDirtyLineBefore(e){for(let t of this.dirtyLineIds){let n=this.getLinePosition(t);if(n>=1&&n<e)return true}return false}hasAnyDirtyVariableDefLineBefore(e){for(let t of this.dirtyLineIds){let n=this.lines.get(t);if(!n||!n.isVariableDef)continue;let r=this.getLinePosition(t);if(r>=1&&r<e)return true}return false}get dirtyCount(){return this.dirtyLineIds.size}isBytecodeValid(e,t){let n=this.lines.get(e);return n!==void 0&&n.textHash===t}markClean(e){let t=this.lines.get(e);t&&(t.dirty=false,this.dirtyLineIds.delete(e));}markDirtyByLineNumber(e){let t=this.getLineAt(e);t&&(t.dirty=true,this.dirtyLineIds.add(t.lineId));}markDirty(e){let t=this.lines.get(e);t&&(t.dirty=true,this.dirtyLineIds.add(e));}invalidateAll(){for(let e of this.lines.values())e.dirty=true;this.dirtyLineIds=new Set(this.lines.keys());}updateLineResult(e,t,n,r,s,i,a,l=0){let o=this.lines.get(e);o&&(o.results=t,o.result=t[0]?.[0]??null,o.bytecodes=n,o.expressions=r,o.reads=s,o.writes=i,o.isVariableDef=a,o.inlineSolveCount=l,o.dirty=false,this.dirtyLineIds.delete(e));}updateLineCompiled(e,t,n,r,s,i,a=0){let l=this.lines.get(e);l&&(l.expressions=t,l.bytecodes=n,l.reads=r,l.writes=s,l.isVariableDef=i,l.inlineSolveCount=a);}get lineCount(){return this.orderTree.length}get isEmpty(){return this.orderTree.isEmpty}*[Symbol.iterator](){for(let e of this.orderTree){let t=this.lines.get(e);t&&(yield t);}}clear(){this.lines.clear(),this.orderTree.clear(),this._positionCache=null,this.nextLineId=1;}toJSON(){return {lineCount:this.lineCount,lines:this.getAllLines().map(e=>({lineId:e.lineId,text:e.text.substring(0,80),textHash:e.textHash,dirty:e.dirty,isVariableDef:e.isVariableDef,isEmpty:e.isEmpty,hasBytecode:e.bytecodes.length>0,hasResult:e.results.length>0,inlineSolveCount:e.inlineSolveCount,reads:e.reads,writes:e.writes}))}}};var A=class{constructor(){this.worker=null;this.nextId=1;this.pending=new Map;}ensureWorker(){return this.worker?this.worker:(this.worker=g(),this.worker.onmessage=e=>{let t=e.data;if(!t||t.type!=="COMPILE_RESULT")return;let n=this.pending.get(t.id);if(!n)return;this.pending.delete(t.id);let r=[];for(let s of t.results)r.push(this.reconstructResult(s));n.resolve(r);},this.worker.onerror=e=>{for(let[t,n]of this.pending)n.reject(new Error(`Compilation worker error: ${e.message}`)),this.pending.delete(t);},this.worker)}async compileBatch(e){if(e.length===0)return [];let t=this.ensureWorker(),n=this.nextId++;return new Promise((r,s)=>{this.pending.set(n,{resolve:r,reject:s}),t.postMessage({type:"COMPILE_BATCH",id:n,items:e});})}storeResults(e,t){let n=new Map;for(let i of e){if(i.error)continue;let a=t.getLineById(i.lineId);if(!a||a.textHash!==i.compiledAgainstHash)continue;let l=n.get(i.lineId);l||(l={bytecodes:[],reads:new Set,writes:new Set,isVariableDef:false,expressions:a.expressions.length>0?[...a.expressions]:[],textHash:i.compiledAgainstHash},n.set(i.lineId,l)),l.bytecodes.push(i.program);for(let o of i.reads)l.reads.add(o);for(let o of i.writes)l.writes.add(o);i.isVariableDef&&(l.isVariableDef=true);}let s=0;for(let[i,a]of n){if(a.bytecodes.length===0)continue;let o=t.getLineById(i)?.inlineSolveCount??0;t.updateLineCompiled(i,a.expressions,a.bytecodes,[...a.reads],[...a.writes],a.isVariableDef,o),s+=a.bytecodes.length;}return s}terminate(){this.worker&&(this.worker.terminate(),this.worker=null,this.pending.clear());}get isActive(){return this.worker!==null}reconstructResult(e){if(e.error)return {lineId:e.lineId,compiledAgainstHash:e.compiledAgainstHash,program:{opcodes:new Uint8Array(0),numbers:new Float64Array(0),strings:[],hasAsync:false},reads:[],writes:[],isVariableDef:false,error:e.error};let t=e.opcodesLength>0?new Uint8Array(e.opcodesBuffer,0,e.opcodesLength):new Uint8Array(0),n=e.numbersLength>0?new Float64Array(e.numbersBuffer,0,e.numbersLength):new Float64Array(0),r={opcodes:t,numbers:n,strings:e.strings,hasAsync:false};return {lineId:e.lineId,compiledAgainstHash:e.compiledAgainstHash,program:r,reads:e.reads,writes:e.writes,isVariableDef:e.isVariableDef,error:null}}};var U=128,k=3,Z=6,Q=2,X=k,H=class u{constructor(){this.lastViewportStart=null;this.savedDirection=null;this.pageAccess=new Map;this.accessSeq=0;}static pageForLine(e){return Math.floor((e-1)/U)}static pageRange(e,t){return {startLine:e*U+1,endLine:Math.min((e+1)*U,t)}}detectDirection(e){return this.lastViewportStart===null?null:e.startLine>this.lastViewportStart?"down":e.startLine<this.lastViewportStart?"up":null}maintainAfterEval(e,t){this.savedDirection=this.detectDirection(e),this.lastViewportStart=e.startLine;let n=t.lineCount,r=u.pageForLine(e.startLine),s=u.pageForLine(e.endLine),i=u.pageForLine(n),a=Math.max(0,r-k),l=Math.min(i,s+k),o=Math.max(0,r-Z),c=Math.min(i,s+Z);for(let h=a;h<=l;h++)this.touchPage(h);for(let h=o;h<=c;h++)h>=a&&h<=l||this.evictPageResults(h,t,n);let d=o-1,p=Math.max(0,d-X+1);for(let h=p;h<=d;h++)this.evictPageBytecode(h,t,n);let f=c+1,g=Math.min(i,f+X-1);for(let h=f;h<=g;h++)this.evictPageBytecode(h,t,n);}getPreloadTargets(e,t){let n=this.savedDirection;if(!n)return [];let r=[],s=u.pageForLine(e.endLine),i=u.pageForLine(e.startLine),a=u.pageForLine(t.lineCount),l=[];if(n==="down"){let o=s+k+1,c=Math.min(o+Q-1,a);for(let d=o;d<=c&&d<=a;d++)l.push(d);}else {let o=i-k-1;for(let c=o;c>o-Q&&c>=0;c--)l.push(c);}for(let o of l){let c=u.pageRange(o,t.lineCount);for(let d=c.startLine;d<=c.endLine;d++){let p=t.getLineAt(d);if(p&&p.dirty&&!(p.bytecodes.length>0&&!p.isVariableDef)&&!p.isEmpty)if(p.expressions.length>0)for(let f of p.expressions)f.trim()&&r.push({lineId:p.lineId,expression:f,textHash:p.textHash});else {let f=c$1.findInlineSolves(p.text);if(f.length>0)for(let g of f)g.expression.trim()&&r.push({lineId:p.lineId,expression:g.expression,textHash:p.textHash});else {let g=p.text.trim();g&&r.push({lineId:p.lineId,expression:g,textHash:p.textHash});}}}}return r}clear(){this.pageAccess.clear(),this.accessSeq=0,this.lastViewportStart=null,this.savedDirection=null;}touchPage(e){this.pageAccess.set(e,++this.accessSeq);}evictPageResults(e,t,n){let r=u.pageRange(e,n);for(let s=r.startLine;s<=r.endLine;s++){let i=t.getLineAt(s);i&&!i.isVariableDef&&i.results.length>0&&(i.results=[],i.result=null);}}evictPageBytecode(e,t,n){let r=u.pageRange(e,n);for(let s=r.startLine;s<=r.endLine;s++){let i=t.getLineAt(s);!i||i.isVariableDef||(i.bytecodes.length>0||i.results.length>0)&&(i.bytecodes=[],i.results=[],i.result=null,t.markDirty(i.lineId));}}};var Y=(r=>(r[r.Tier1=1]="Tier1",r[r.Tier2=2]="Tier2",r[r.Tier3=3]="Tier3",r[r.Skipped=0]="Skipped",r))(Y||{}),w=class{constructor(e,t,n){this.compilationWorker=null;this.globalUnsubscribe=null;this.doc=e,this.engine=t,this.dag=t.getDag(),this.checkpointer=n??null,this.pageManager=new H,this.engine.setDocumentModel(this.doc),this.globalUnsubscribe=J.subscribe(r=>{for(let s of this.dag.getAffectedLines(K(r)))this.doc.markDirtyByLineNumber(s);});}evaluate(e,t){this.engine.setKeystrokeSignal(t??null),h();try{this.reseedAccumulators();let n=[],r=new Map,s={tier1:0,tier2:0,tier3:0,skipped:0},i=this.doc.lineCount,a=Math.min(e.endLine,i);for(let l=1;l<=a;l++){let o=this.doc.getLineAt(l);if(!o){s.skipped++;continue}let c=l>=e.startLine&&l<=e.endLine,d=this.evaluateSingleLine(o,l,c);n.push(d),d.tier===1?s.tier1++:d.tier===2?s.tier2++:d.tier===3?s.tier3++:s.skipped++,d.results&&c&&r.set(l,d.results.flat());}return this.pageManager.maintainAfterEval(e,this.doc),{lines:n,resultMap:r,tierCounts:s}}finally{this.engine.setKeystrokeSignal(null),i();}}backgroundCompile(e){let t=[],n=this.doc.lineCount,r=e.endLine+1;for(let s=r;s<=n;s++){let i=this.doc.getLineAt(s);if(!i||!i.dirty||i.bytecodes.length>0&&!i.isVariableDef)continue;let a=this.evaluateSingleLine(i,s,false);t.push(a);}return t}dispatchBackgroundCompiles(e){let t=this.collectInvisibleCompileTargets(e);t.length!==0&&(this.compilationWorker||(this.compilationWorker=new A),this.compilationWorker.compileBatch(t).then(n=>{this.compilationWorker.storeResults(n,this.doc);}).catch(n=>{}));}terminateWorker(){this.compilationWorker&&(this.compilationWorker.terminate(),this.compilationWorker=null),this.globalUnsubscribe&&(this.globalUnsubscribe(),this.globalUnsubscribe=null);}getDoc(){return this.doc}evaluateAll(e){let t={startLine:1,endLine:this.doc.lineCount};return this.evaluate(t,e)}setViewport(e,t){if(this.engine.setKeystrokeSignal(t??null),e.startLine>1&&this.hasDirtyLinesBefore(e.startLine))return this.checkpointer?.clear(),this.evaluate(e,t);this.pageManager.maintainAfterEval(e,this.doc),this.preloadNextPages(e),this.restoreTo(e.startLine-1),h();try{return this.collectEvalResults(e.startLine,e.endLine)}finally{this.engine.setKeystrokeSignal(null),i();}}applyTransaction(e){let t=new Set;for(let s of e)for(let i=0;i<s.deleteCount;i++){let a=s.startLine+i,l=this.dag.getWrites(a);for(let o of l)t.add(o);this.dag.removeLine(a),this.engine.getLineCache().removeAllForLine(a);}let n=new Set;for(let s of t){let i=this.dag.getAffectedLines(s);for(let a of i){let l=this.doc.getLineAt(a);l&&n.add(l.lineId);}}let r=this.doc.applyChanges(e);this.checkpointer?.clear();for(let s of n)this.doc.markDirty(s);return this.dag.clear(),{inserted:r.inserted,removed:r.removed}}reseedAccumulators(){let e=this.engine.resetAccumulators();if(e.size===0)return;let t=this.doc.lineCount;for(let n=1;n<=t;n++){let r=this.dag.getWrites(n);if(r.size!==0){for(let s of r)if(e.has(s)){this.doc.markDirtyByLineNumber(n);break}}}}collectEvalResults(e,t){let n=[],r=new Map,s={tier1:0,tier2:0,tier3:0,skipped:0},i=this.doc.lineCount,a=Math.min(t,i);for(let l=e;l<=a;l++){let o=this.doc.getLineAt(l);if(!o)continue;let c=this.evaluateSingleLine(o,l,true);n.push(c),c.tier===1?s.tier1++:c.tier===2?s.tier2++:c.tier===3?s.tier3++:s.skipped++,c.results&&r.set(l,c.results.flat());}return {lines:n,resultMap:r,tierCounts:s}}hasDirtyLinesBefore(e){return this.doc.hasAnyDirtyVariableDefLineBefore(e)}evaluateSingleLine(e,t,n){let r={lineId:e.lineId,lineNumber:t};if(e.isEmpty||l(e.text))return e.isEmpty=true,this.doc.markClean(e.lineId),{...r,tier:0,result:null,error:null};let{expressions:s,inlineSolveCount:i}=this.extractExpressions(e);return s.length===0?(e.isEmpty=true,this.doc.markClean(e.lineId),{...r,tier:0,result:null,error:null}):e.dirty?n?this.evaluateTier1(e,t,s,i,r):e.bytecodes.length>0&&e.bytecodes.length===s.length&&!e.isVariableDef?{...r,tier:0,result:null,error:null}:this.evaluateTier3(e,t,s,i,r):n&&e.bytecodes.length>0?this.evaluateTier2(e,t,r):{...r,tier:0,result:null,error:null}}evaluateTier1(e,t,n,r,s){let i=[],a=[],l=new Set,o=new Set,c=false,d=null,p=null,f=false,g=false;for(let y of n){if(!y.trim())continue;let b=null,L;try{let m=this.engine.evaluateLine(t,y);b=[m],d=m,L=this.engine.getLineCache().get(t,y);}catch(m){let x=m instanceof Error?m.message:String(m);p||(p=x),f=true,b=null;}if(b&&b.some(m=>m.type===12)&&(g=true),b?i.push(b):i.push([N("eval_failed",p??"unknown error")]),L){a.push(L.bytecode);for(let m of L.readVariables)l.add(m);L.writeVariable&&(o.add(L.writeVariable),c=true);}else try{let{program:m,reads:x,writes:E}=this.engine.compileExpression(y);a.push(m);for(let S of x)l.add(S);for(let S of E)o.add(S);E.length>0&&(c=!0);}catch(m){if(a.push({opcodes:new Uint8Array(0),numbers:new Float64Array(0),strings:[],hasAsync:false}),m instanceof b$2&&m.context){let x=m.context.reads,E=m.context.writes;if(Array.isArray(x))for(let S of x)l.add(S);if(Array.isArray(E))for(let S of E)o.add(S);}}}let h=[...l],v=[...o];return f||g?(this.doc.updateLineCompiled(e.lineId,n,a,h,v,c,r),e.results=i,e.result=i[0]?.[0]??null,e.inlineSolveCount=r,e.expressions=n):this.doc.updateLineResult(e.lineId,i,a,n,h,v,c,r),this.dag.registerLine(t,h,v),this.checkpointer&&v.length>0&&!f&&!g&&this.checkpointer.snapshot(t,e.lineId,v),{...s,tier:1,result:d,results:i,error:p}}evaluateTier2(e,t,n){if(e.bytecodes.length===0)return {...n,tier:0,result:null,error:null};let r=[],s=null,i=null,a=false;for(let l of e.bytecodes)if(l.opcodes.length!==0)try{let o=this.engine.executeCached(l,t);s=o,r.push([o]);}catch(o){let c=o instanceof Error?o.message:String(o);i||(i=c),a=true,r.push([N("exec_failed",c)]);}return this.dag.registerLine(t,e.reads,e.writes),e.results=r,e.result=r[0]?.[0]??null,a&&this.doc.markDirty(e.lineId),{...n,tier:2,result:s,results:r,error:i}}evaluateTier3(e,t,n,r,s){let i=[],a=new Set,l=new Set,o=false,c=null,d=null,p=false,f=false;for(let v of n)if(v.trim())try{let{program:y,reads:b,writes:L}=this.engine.compileExpression(v);i.push(y);for(let m of b)a.add(m);for(let m of L)l.add(m);L.length>0&&(o=!0),L.length>0&&y.opcodes.length>0&&(c=this.engine.executeCached(y,t),c&&c.type===12&&(f=!0));}catch(y){let b=y instanceof Error?y.message:String(y);d||(d=b),p=true,i.push({opcodes:new Uint8Array(0),numbers:new Float64Array(0),strings:[],hasAsync:false});}let g=[...a],h=[...l];return this.doc.updateLineCompiled(e.lineId,n,i,g,h,o,r),this.dag.registerLine(t,g,h),o&&c&&!p&&!f&&(e.results=[[c]],e.result=c,this.doc.markClean(e.lineId),this.checkpointer&&this.checkpointer.snapshot(t,e.lineId,h)),{...s,tier:3,result:c,results:o&&c&&!p&&!f?[[c]]:void 0,error:d}}restoreTo(e){this.checkpointer&&this.checkpointer.restoreTo(e);}getCheckpointer(){return this.checkpointer}getPageManager(){return this.pageManager}preloadNextPages(e){let t=this.pageManager.getPreloadTargets(e,this.doc);t.length!==0&&(this.compilationWorker||(this.compilationWorker=new A),this.compilationWorker.compileBatch(t).then(n=>{this.compilationWorker.storeResults(n,this.doc);}).catch(n=>{}));}collectInvisibleCompileTargets(e){let t=[],n=this.doc.lineCount,r=e.endLine+1;for(let s=r;s<=n;s++){let i=this.doc.getLineAt(s);if(!i||!i.dirty||i.bytecodes.length>0&&!i.isVariableDef||i.isEmpty||l(i.text))continue;let{expressions:a}=this.extractExpressions(i);if(a.length!==0)for(let l of a)l.trim()&&t.push({lineId:i.lineId,expression:l,textHash:i.textHash});}return t}extractExpressions(e){if(e.expressions.length>0)return {expressions:e.expressions,inlineSolveCount:e.inlineSolveCount};let t=e.text.trim();if(t.length===0)return {expressions:[],inlineSolveCount:0};let n=c$1.findInlineSolves(e.text);return n.length>0?{expressions:n.map(r=>r.expression),inlineSolveCount:n.length}:{expressions:[t],inlineSolveCount:0}}};function ee(u){return typeof u.unit=="string"?u.unit:String(u.value)}function ie(u,e,t={inputType:"markdown"}){let n=u.getDocumentModel(),r=new R;r.setDocument(e);let s=new w(r,u);try{let i=r.lineCount;s.evaluate({startLine:1,endLine:i});let a=[],l=[],o=0;for(let c=1;c<=i;c++){let d=r.getLineAt(c),p=d.text,f=o,g=o+p.length;o=g+1;let h=d.inlineSolveCount>0,v=[],y=null,b=null;d.isEmpty||(h?v=m(p,c).map((L,m)=>{let x=d.results[m]?.[0]??null;if(x&&x.type===13){let E=ee(x);return l.push(`Line ${c}: ${E}`),{...L,result:null,error:E}}return {...L,result:x,error:null}}):(y=d.expressions[0]??null,b=d.result??null,b&&b.type===13&&l.push(`Line ${c}: ${ee(b)}`))),a.push({lineNumber:c,text:p,startPosition:f,endPosition:g,isEmpty:d.isEmpty,hasInlineSolves:h,inlineSolves:v,expression:y,error:null,result:b});}return {lines:a,totalLines:i,errors:l}}finally{s.terminateWorker(),u.setDocumentModel(n);}}export{R as a,Y as b,w as c,ie as d};//# sourceMappingURL=chunk-7NXAZJDB.js.map
3
- //# sourceMappingURL=chunk-7NXAZJDB.js.map
1
+ import {a}from'./chunk-RAF57WYO.js';import {l,m,g}from'./chunk-UA3BGOYT.js';import {b as b$1}from'./chunk-76F3LCIL.js';import {J,K}from'./chunk-W2JAR233.js';import {h,i,N}from'./chunk-EVAOPEO4.js';import {b}from'./chunk-UGQM6ZXU.js';import {c as c$1}from'./chunk-YAHGSBMC.js';import {c,b as b$2}from'./chunk-MPB7KUN5.js';var P=class{constructor(){this.root=null;}get length(){return this.root?this.root.size:0}get isEmpty(){return this.root===null}getAt(e){if(!(e<0||e>=(this.root?.size??0)))return this.nodeAt(this.root,e).lineId}insertAt(e,t){let[n,r]=I(this.root,e);this.root=C(C(n,te(t)),r);}deleteAt(e){if(e<0||e>=(this.root?.size??0))return;let[t,n]=I(this.root,e),[r,s]=I(n,1),i=r?r.lineId:void 0;return this.root=C(t,s),i}spliceAt(e,t,n){let r=Math.max(0,e),s=Math.min(Math.max(0,t),(this.root?.size??0)-r),[i,a]=I(this.root,r),[l,o]=I(a,s),c=ne(l),d=B(n,0,n.length);return this.root=C(C(i,d),o),c}replaceAll(e){this.root=B(e,0,e.length);}getRange(e,t){let n=Math.max(0,e),r=Math.min((this.root?.size??0)-1,t);if(n>r)return [];let s=[];return this.collectRange(this.root,n,r,0,s),s}clear(){this.root=null;}*[Symbol.iterator](){yield*this.inOrder(this.root);}*inOrder(e){e&&(yield*this.inOrder(e.left),yield e.lineId,yield*this.inOrder(e.right));}nodeAt(e,t){let n=e.left?e.left.size:0;return t<n?this.nodeAt(e.left,t):t===n?e:this.nodeAt(e.right,t-n-1)}collectRange(e,t,n,r,s){if(!e)return;let i=e.left?e.left.size:0,a=r+i;a>t&&e.left&&this.collectRange(e.left,t,n,r,s),a>=t&&a<=n&&s.push(e.lineId),a<n&&e.right&&this.collectRange(e.right,t,n,a+1,s);}};function te(u){return {lineId:u,size:1,priority:Math.random(),left:null,right:null}}function T(u){u.size=1+(u.left?u.left.size:0)+(u.right?u.right.size:0);}function C(u,e){return u?e?u.priority>e.priority?(u.right=C(u.right,e),T(u),u):(e.left=C(u,e.left),T(e),e):u:e}function I(u,e){if(!u)return [null,null];let t=u.left?u.left.size:0;if(e<=t){let[n,r]=I(u.left,e);return u.left=r,T(u),[n,u]}else {let[n,r]=I(u.right,e-t-1);return u.right=n,T(u),[u,r]}}function ne(u){let e=[];return F(u,e),e}function F(u,e){u&&(F(u.left,e),e.push(u.lineId),F(u.right,e));}function B(u,e,t){if(e>=t)return null;let n=Math.floor((e+t)/2),r=re(n);return {lineId:u[n],size:t-e,priority:r,left:B(u,e,n),right:B(u,n+1,t)}}function re(u){let e=u;return e=(e>>16^e)*73244475,e=(e>>16^e)*73244475,e=e>>16^e,e/4294967295}var R=class{constructor(e=b.performance.maxDocumentLines){this.lines=new Map;this.orderTree=new P;this.nextLineId=1;this._positionCache=null;this.dirtyLineIds=new Set;this.maxLines=e;}setDocument(e){if(b$1(e,this.maxLines)>this.maxLines)throw c.execution("DOCUMENT_TOO_LARGE",`This document has more than ${this.maxLines.toLocaleString("en-US")} lines, which is the most the engine will hold at once`,{maxLines:this.maxLines});this.lines.clear(),this.orderTree.clear(),this._positionCache=null,this.dirtyLineIds.clear(),this.nextLineId=1;let n=e.split(`
2
+ `),r=new Array(n.length);for(let s=0;s<n.length;s++){let i=this.nextLineId++;r[s]=i,this.lines.set(i,{lineId:i,textHash:a(n[s]),text:n[s],expressions:[],bytecodes:[],reads:[],writes:[],results:[],result:null,dirty:true,isVariableDef:false,isEmpty:n[s].trim().length===0,inlineSolveCount:0});}this.orderTree.replaceAll(r);for(let s of r)this.dirtyLineIds.add(s);}applyChanges(e){let t=[],n=[],r=[...e].sort((s,i)=>i.startLine-s.startLine);for(let s of r){let i=s.startLine-1,a$1=[];for(let o of s.insertLines){let c=this.nextLineId++;a$1.push(c),t.push(c),this.lines.set(c,{lineId:c,textHash:a(o),text:o,expressions:[],bytecodes:[],reads:[],writes:[],results:[],result:null,dirty:true,isVariableDef:false,isEmpty:o.trim().length===0,inlineSolveCount:0});}for(let o of a$1)this.dirtyLineIds.add(o);let l=this.orderTree.spliceAt(i,s.deleteCount,a$1);for(let o of l)n.push(o),this.lines.delete(o),this.dirtyLineIds.delete(o);}return this._positionCache=null,{inserted:t,removed:n}}insertLines(e,t){let n={startLine:e,deleteCount:0,insertLines:t};return this.applyChanges([n]).inserted}deleteLines(e,t){let n={startLine:e,deleteCount:t-e+1,insertLines:[]};return this.applyChanges([n]).removed}editLine(e,t){let n=this.getLineAt(e);if(!n)return false;let r=a(t);return r===n.textHash?false:(n.text=t,n.textHash=r,n.expressions=[],n.bytecodes=[],n.results=[],n.result=null,n.inlineSolveCount=0,n.dirty=true,this.dirtyLineIds.add(n.lineId),n.isEmpty=t.trim().length===0,true)}getLineAt(e){let t=e-1,n=this.orderTree.getAt(t);if(n!==void 0)return this.lines.get(n)}getLinePosition(e){if(this._positionCache)return this._positionCache.get(e)??-1;this._positionCache=new Map;let t=1;for(let n of this.orderTree)this._positionCache.set(n,t++);return this._positionCache.get(e)??-1}getVisibleLines(e,t){let n=this.orderTree.getRange(e-1,t-1),r=[];for(let s of n){let i=this.lines.get(s);i&&r.push(i);}return r}getAllLines(){return this.getVisibleLines(1,this.lineCount)}getLineById(e){return this.lines.get(e)}getDirtyLines(){let e=[];for(let t of this.lines.values())t.dirty&&e.push(t);return e}hasAnyDirtyLineBefore(e){for(let t of this.dirtyLineIds){let n=this.getLinePosition(t);if(n>=1&&n<e)return true}return false}hasAnyDirtyVariableDefLineBefore(e){for(let t of this.dirtyLineIds){let n=this.lines.get(t);if(!n||!n.isVariableDef)continue;let r=this.getLinePosition(t);if(r>=1&&r<e)return true}return false}get dirtyCount(){return this.dirtyLineIds.size}isBytecodeValid(e,t){let n=this.lines.get(e);return n!==void 0&&n.textHash===t}markClean(e){let t=this.lines.get(e);t&&(t.dirty=false,this.dirtyLineIds.delete(e));}markDirtyByLineNumber(e){let t=this.getLineAt(e);t&&(t.dirty=true,this.dirtyLineIds.add(t.lineId));}markDirty(e){let t=this.lines.get(e);t&&(t.dirty=true,this.dirtyLineIds.add(e));}invalidateAll(){for(let e of this.lines.values())e.dirty=true;this.dirtyLineIds=new Set(this.lines.keys());}updateLineResult(e,t,n,r,s,i,a,l=0){let o=this.lines.get(e);o&&(o.results=t,o.result=t[0]?.[0]??null,o.bytecodes=n,o.expressions=r,o.reads=s,o.writes=i,o.isVariableDef=a,o.inlineSolveCount=l,o.dirty=false,this.dirtyLineIds.delete(e));}updateLineCompiled(e,t,n,r,s,i,a=0){let l=this.lines.get(e);l&&(l.expressions=t,l.bytecodes=n,l.reads=r,l.writes=s,l.isVariableDef=i,l.inlineSolveCount=a);}get lineCount(){return this.orderTree.length}get isEmpty(){return this.orderTree.isEmpty}*[Symbol.iterator](){for(let e of this.orderTree){let t=this.lines.get(e);t&&(yield t);}}clear(){this.lines.clear(),this.orderTree.clear(),this._positionCache=null,this.nextLineId=1;}toJSON(){return {lineCount:this.lineCount,lines:this.getAllLines().map(e=>({lineId:e.lineId,text:e.text.substring(0,80),textHash:e.textHash,dirty:e.dirty,isVariableDef:e.isVariableDef,isEmpty:e.isEmpty,hasBytecode:e.bytecodes.length>0,hasResult:e.results.length>0,inlineSolveCount:e.inlineSolveCount,reads:e.reads,writes:e.writes}))}}};var A=class{constructor(){this.worker=null;this.nextId=1;this.pending=new Map;}ensureWorker(){return this.worker?this.worker:(this.worker=g(),this.worker.onmessage=e=>{let t=e.data;if(!t||t.type!=="COMPILE_RESULT")return;let n=this.pending.get(t.id);if(!n)return;this.pending.delete(t.id);let r=[];for(let s of t.results)r.push(this.reconstructResult(s));n.resolve(r);},this.worker.onerror=e=>{for(let[t,n]of this.pending)n.reject(new Error(`Compilation worker error: ${e.message}`)),this.pending.delete(t);},this.worker)}async compileBatch(e){if(e.length===0)return [];let t=this.ensureWorker(),n=this.nextId++;return new Promise((r,s)=>{this.pending.set(n,{resolve:r,reject:s}),t.postMessage({type:"COMPILE_BATCH",id:n,items:e});})}storeResults(e,t){let n=new Map;for(let i of e){if(i.error)continue;let a=t.getLineById(i.lineId);if(!a||a.textHash!==i.compiledAgainstHash)continue;let l=n.get(i.lineId);l||(l={bytecodes:[],reads:new Set,writes:new Set,isVariableDef:false,expressions:a.expressions.length>0?[...a.expressions]:[],textHash:i.compiledAgainstHash},n.set(i.lineId,l)),l.bytecodes.push(i.program);for(let o of i.reads)l.reads.add(o);for(let o of i.writes)l.writes.add(o);i.isVariableDef&&(l.isVariableDef=true);}let s=0;for(let[i,a]of n){if(a.bytecodes.length===0)continue;let o=t.getLineById(i)?.inlineSolveCount??0;t.updateLineCompiled(i,a.expressions,a.bytecodes,[...a.reads],[...a.writes],a.isVariableDef,o),s+=a.bytecodes.length;}return s}terminate(){this.worker&&(this.worker.terminate(),this.worker=null,this.pending.clear());}get isActive(){return this.worker!==null}reconstructResult(e){if(e.error)return {lineId:e.lineId,compiledAgainstHash:e.compiledAgainstHash,program:{opcodes:new Uint8Array(0),numbers:new Float64Array(0),strings:[],hasAsync:false},reads:[],writes:[],isVariableDef:false,error:e.error};let t=e.opcodesLength>0?new Uint8Array(e.opcodesBuffer,0,e.opcodesLength):new Uint8Array(0),n=e.numbersLength>0?new Float64Array(e.numbersBuffer,0,e.numbersLength):new Float64Array(0),r={opcodes:t,numbers:n,strings:e.strings,hasAsync:false};return {lineId:e.lineId,compiledAgainstHash:e.compiledAgainstHash,program:r,reads:e.reads,writes:e.writes,isVariableDef:e.isVariableDef,error:null}}};var U=128,k=3,Z=6,Q=2,X=k,H=class u{constructor(){this.lastViewportStart=null;this.savedDirection=null;this.pageAccess=new Map;this.accessSeq=0;}static pageForLine(e){return Math.floor((e-1)/U)}static pageRange(e,t){return {startLine:e*U+1,endLine:Math.min((e+1)*U,t)}}detectDirection(e){return this.lastViewportStart===null?null:e.startLine>this.lastViewportStart?"down":e.startLine<this.lastViewportStart?"up":null}maintainAfterEval(e,t){this.savedDirection=this.detectDirection(e),this.lastViewportStart=e.startLine;let n=t.lineCount,r=u.pageForLine(e.startLine),s=u.pageForLine(e.endLine),i=u.pageForLine(n),a=Math.max(0,r-k),l=Math.min(i,s+k),o=Math.max(0,r-Z),c=Math.min(i,s+Z);for(let h=a;h<=l;h++)this.touchPage(h);for(let h=o;h<=c;h++)h>=a&&h<=l||this.evictPageResults(h,t,n);let d=o-1,p=Math.max(0,d-X+1);for(let h=p;h<=d;h++)this.evictPageBytecode(h,t,n);let f=c+1,g=Math.min(i,f+X-1);for(let h=f;h<=g;h++)this.evictPageBytecode(h,t,n);}getPreloadTargets(e,t){let n=this.savedDirection;if(!n)return [];let r=[],s=u.pageForLine(e.endLine),i=u.pageForLine(e.startLine),a=u.pageForLine(t.lineCount),l=[];if(n==="down"){let o=s+k+1,c=Math.min(o+Q-1,a);for(let d=o;d<=c&&d<=a;d++)l.push(d);}else {let o=i-k-1;for(let c=o;c>o-Q&&c>=0;c--)l.push(c);}for(let o of l){let c=u.pageRange(o,t.lineCount);for(let d=c.startLine;d<=c.endLine;d++){let p=t.getLineAt(d);if(p&&p.dirty&&!(p.bytecodes.length>0&&!p.isVariableDef)&&!p.isEmpty)if(p.expressions.length>0)for(let f of p.expressions)f.trim()&&r.push({lineId:p.lineId,expression:f,textHash:p.textHash});else {let f=c$1.findInlineSolves(p.text);if(f.length>0)for(let g of f)g.expression.trim()&&r.push({lineId:p.lineId,expression:g.expression,textHash:p.textHash});else {let g=p.text.trim();g&&r.push({lineId:p.lineId,expression:g,textHash:p.textHash});}}}}return r}clear(){this.pageAccess.clear(),this.accessSeq=0,this.lastViewportStart=null,this.savedDirection=null;}touchPage(e){this.pageAccess.set(e,++this.accessSeq);}evictPageResults(e,t,n){let r=u.pageRange(e,n);for(let s=r.startLine;s<=r.endLine;s++){let i=t.getLineAt(s);i&&!i.isVariableDef&&i.results.length>0&&(i.results=[],i.result=null);}}evictPageBytecode(e,t,n){let r=u.pageRange(e,n);for(let s=r.startLine;s<=r.endLine;s++){let i=t.getLineAt(s);!i||i.isVariableDef||(i.bytecodes.length>0||i.results.length>0)&&(i.bytecodes=[],i.results=[],i.result=null,t.markDirty(i.lineId));}}};var Y=(r=>(r[r.Tier1=1]="Tier1",r[r.Tier2=2]="Tier2",r[r.Tier3=3]="Tier3",r[r.Skipped=0]="Skipped",r))(Y||{}),w=class{constructor(e,t,n){this.compilationWorker=null;this.globalUnsubscribe=null;this.doc=e,this.engine=t,this.dag=t.getDag(),this.checkpointer=n??null,this.pageManager=new H,this.engine.setDocumentModel(this.doc),this.globalUnsubscribe=J.subscribe(r=>{for(let s of this.dag.getAffectedLines(K(r)))this.doc.markDirtyByLineNumber(s);});}evaluate(e,t){this.engine.setKeystrokeSignal(t??null),h();try{this.reseedAccumulators();let n=[],r=new Map,s={tier1:0,tier2:0,tier3:0,skipped:0},i=this.doc.lineCount,a=Math.min(e.endLine,i);for(let l=1;l<=a;l++){let o=this.doc.getLineAt(l);if(!o){s.skipped++;continue}let c=l>=e.startLine&&l<=e.endLine,d=this.evaluateSingleLine(o,l,c);n.push(d),d.tier===1?s.tier1++:d.tier===2?s.tier2++:d.tier===3?s.tier3++:s.skipped++,d.results&&c&&r.set(l,d.results.flat());}return this.pageManager.maintainAfterEval(e,this.doc),{lines:n,resultMap:r,tierCounts:s}}finally{this.engine.setKeystrokeSignal(null),i();}}backgroundCompile(e){let t=[],n=this.doc.lineCount,r=e.endLine+1;for(let s=r;s<=n;s++){let i=this.doc.getLineAt(s);if(!i||!i.dirty||i.bytecodes.length>0&&!i.isVariableDef)continue;let a=this.evaluateSingleLine(i,s,false);t.push(a);}return t}dispatchBackgroundCompiles(e){let t=this.collectInvisibleCompileTargets(e);t.length!==0&&(this.compilationWorker||(this.compilationWorker=new A),this.compilationWorker.compileBatch(t).then(n=>{this.compilationWorker.storeResults(n,this.doc);}).catch(n=>{}));}terminateWorker(){this.compilationWorker&&(this.compilationWorker.terminate(),this.compilationWorker=null),this.globalUnsubscribe&&(this.globalUnsubscribe(),this.globalUnsubscribe=null);}getDoc(){return this.doc}evaluateAll(e){let t={startLine:1,endLine:this.doc.lineCount};return this.evaluate(t,e)}setViewport(e,t){if(this.engine.setKeystrokeSignal(t??null),e.startLine>1&&this.hasDirtyLinesBefore(e.startLine))return this.checkpointer?.clear(),this.evaluate(e,t);this.pageManager.maintainAfterEval(e,this.doc),this.preloadNextPages(e),this.restoreTo(e.startLine-1),h();try{return this.collectEvalResults(e.startLine,e.endLine)}finally{this.engine.setKeystrokeSignal(null),i();}}applyTransaction(e){let t=new Set;for(let s of e)for(let i=0;i<s.deleteCount;i++){let a=s.startLine+i,l=this.dag.getWrites(a);for(let o of l)t.add(o);this.dag.removeLine(a),this.engine.getLineCache().removeAllForLine(a);}let n=new Set;for(let s of t){let i=this.dag.getAffectedLines(s);for(let a of i){let l=this.doc.getLineAt(a);l&&n.add(l.lineId);}}let r=this.doc.applyChanges(e);this.checkpointer?.clear();for(let s of n)this.doc.markDirty(s);return this.dag.clear(),{inserted:r.inserted,removed:r.removed}}reseedAccumulators(){let e=this.engine.resetAccumulators();if(e.size===0)return;let t=this.doc.lineCount;for(let n=1;n<=t;n++){let r=this.dag.getWrites(n);if(r.size!==0){for(let s of r)if(e.has(s)){this.doc.markDirtyByLineNumber(n);break}}}}collectEvalResults(e,t){let n=[],r=new Map,s={tier1:0,tier2:0,tier3:0,skipped:0},i=this.doc.lineCount,a=Math.min(t,i);for(let l=e;l<=a;l++){let o=this.doc.getLineAt(l);if(!o)continue;let c=this.evaluateSingleLine(o,l,true);n.push(c),c.tier===1?s.tier1++:c.tier===2?s.tier2++:c.tier===3?s.tier3++:s.skipped++,c.results&&r.set(l,c.results.flat());}return {lines:n,resultMap:r,tierCounts:s}}hasDirtyLinesBefore(e){return this.doc.hasAnyDirtyVariableDefLineBefore(e)}evaluateSingleLine(e,t,n){let r={lineId:e.lineId,lineNumber:t};if(e.isEmpty||l(e.text))return e.isEmpty=true,this.doc.markClean(e.lineId),{...r,tier:0,result:null,error:null};let{expressions:s,inlineSolveCount:i}=this.extractExpressions(e);return s.length===0?(e.isEmpty=true,this.doc.markClean(e.lineId),{...r,tier:0,result:null,error:null}):e.dirty?n?this.evaluateTier1(e,t,s,i,r):e.bytecodes.length>0&&e.bytecodes.length===s.length&&!e.isVariableDef?{...r,tier:0,result:null,error:null}:this.evaluateTier3(e,t,s,i,r):n&&e.bytecodes.length>0?this.evaluateTier2(e,t,r):{...r,tier:0,result:null,error:null}}evaluateTier1(e,t,n,r,s){let i=[],a=[],l=new Set,o=new Set,c=false,d=null,p=null,f=false,g=false;for(let y of n){if(!y.trim())continue;let b=null,L;try{let m=this.engine.evaluateLine(t,y);b=[m],d=m,L=this.engine.getLineCache().get(t,y);}catch(m){let x=m instanceof Error?m.message:String(m);p||(p=x),f=true,b=null;}if(b&&b.some(m=>m.type===12)&&(g=true),b?i.push(b):i.push([N("eval_failed",p??"unknown error")]),L){a.push(L.bytecode);for(let m of L.readVariables)l.add(m);L.writeVariable&&(o.add(L.writeVariable),c=true);}else try{let{program:m,reads:x,writes:E}=this.engine.compileExpression(y);a.push(m);for(let S of x)l.add(S);for(let S of E)o.add(S);E.length>0&&(c=!0);}catch(m){if(a.push({opcodes:new Uint8Array(0),numbers:new Float64Array(0),strings:[],hasAsync:false}),m instanceof b$2&&m.context){let x=m.context.reads,E=m.context.writes;if(Array.isArray(x))for(let S of x)l.add(S);if(Array.isArray(E))for(let S of E)o.add(S);}}}let h=[...l],v=[...o];return f||g?(this.doc.updateLineCompiled(e.lineId,n,a,h,v,c,r),e.results=i,e.result=i[0]?.[0]??null,e.inlineSolveCount=r,e.expressions=n):this.doc.updateLineResult(e.lineId,i,a,n,h,v,c,r),this.dag.registerLine(t,h,v),this.checkpointer&&v.length>0&&!f&&!g&&this.checkpointer.snapshot(t,e.lineId,v),{...s,tier:1,result:d,results:i,error:p}}evaluateTier2(e,t,n){if(e.bytecodes.length===0)return {...n,tier:0,result:null,error:null};let r=[],s=null,i=null,a=false;for(let l of e.bytecodes)if(l.opcodes.length!==0)try{let o=this.engine.executeCached(l,t);s=o,r.push([o]);}catch(o){let c=o instanceof Error?o.message:String(o);i||(i=c),a=true,r.push([N("exec_failed",c)]);}return this.dag.registerLine(t,e.reads,e.writes),e.results=r,e.result=r[0]?.[0]??null,a&&this.doc.markDirty(e.lineId),{...n,tier:2,result:s,results:r,error:i}}evaluateTier3(e,t,n,r,s){let i=[],a=new Set,l=new Set,o=false,c=null,d=null,p=false,f=false;for(let v of n)if(v.trim())try{let{program:y,reads:b,writes:L}=this.engine.compileExpression(v);i.push(y);for(let m of b)a.add(m);for(let m of L)l.add(m);L.length>0&&(o=!0),L.length>0&&y.opcodes.length>0&&(c=this.engine.executeCached(y,t),c&&c.type===12&&(f=!0));}catch(y){let b=y instanceof Error?y.message:String(y);d||(d=b),p=true,i.push({opcodes:new Uint8Array(0),numbers:new Float64Array(0),strings:[],hasAsync:false});}let g=[...a],h=[...l];return this.doc.updateLineCompiled(e.lineId,n,i,g,h,o,r),this.dag.registerLine(t,g,h),o&&c&&!p&&!f&&(e.results=[[c]],e.result=c,this.doc.markClean(e.lineId),this.checkpointer&&this.checkpointer.snapshot(t,e.lineId,h)),{...s,tier:3,result:c,results:o&&c&&!p&&!f?[[c]]:void 0,error:d}}restoreTo(e){this.checkpointer&&this.checkpointer.restoreTo(e);}getCheckpointer(){return this.checkpointer}getPageManager(){return this.pageManager}preloadNextPages(e){let t=this.pageManager.getPreloadTargets(e,this.doc);t.length!==0&&(this.compilationWorker||(this.compilationWorker=new A),this.compilationWorker.compileBatch(t).then(n=>{this.compilationWorker.storeResults(n,this.doc);}).catch(n=>{}));}collectInvisibleCompileTargets(e){let t=[],n=this.doc.lineCount,r=e.endLine+1;for(let s=r;s<=n;s++){let i=this.doc.getLineAt(s);if(!i||!i.dirty||i.bytecodes.length>0&&!i.isVariableDef||i.isEmpty||l(i.text))continue;let{expressions:a}=this.extractExpressions(i);if(a.length!==0)for(let l of a)l.trim()&&t.push({lineId:i.lineId,expression:l,textHash:i.textHash});}return t}extractExpressions(e){if(e.expressions.length>0)return {expressions:e.expressions,inlineSolveCount:e.inlineSolveCount};let t=e.text.trim();if(t.length===0)return {expressions:[],inlineSolveCount:0};let n=c$1.findInlineSolves(e.text);return n.length>0?{expressions:n.map(r=>r.expression),inlineSolveCount:n.length}:{expressions:[t],inlineSolveCount:0}}};function ee(u){return typeof u.unit=="string"?u.unit:String(u.value)}function ie(u,e,t={inputType:"markdown"}){let n=u.getDocumentModel(),r=new R;r.setDocument(e);let s=new w(r,u);try{let i=r.lineCount;s.evaluate({startLine:1,endLine:i});let a=[],l=[],o=0;for(let c=1;c<=i;c++){let d=r.getLineAt(c),p=d.text,f=o,g=o+p.length;o=g+1;let h=d.inlineSolveCount>0,v=[],y=null,b=null;d.isEmpty||(h?v=m(p,c).map((L,m)=>{let x=d.results[m]?.[0]??null;if(x&&x.type===13){let E=ee(x);return l.push(`Line ${c}: ${E}`),{...L,result:null,error:E}}return {...L,result:x,error:null}}):(y=d.expressions[0]??null,b=d.result??null,b&&b.type===13&&l.push(`Line ${c}: ${ee(b)}`))),a.push({lineNumber:c,text:p,startPosition:f,endPosition:g,isEmpty:d.isEmpty,hasInlineSolves:h,inlineSolves:v,expression:y,error:null,result:b});}return {lines:a,totalLines:i,errors:l}}finally{s.terminateWorker(),u.setDocumentModel(n);}}export{R as a,Y as b,w as c,ie as d};//# sourceMappingURL=chunk-5R7S5KJJ.js.map
3
+ //# sourceMappingURL=chunk-5R7S5KJJ.js.map