solve-engine 2.38.16 → 2.38.17
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-C-3vPMKp.d.cts → PackageCompatibility-DFpkrlUp.d.cts} +1 -1
- package/dist/{PackageCompatibility-zdsKvwQI.d.ts → PackageCompatibility-DwZ8-NYu.d.ts} +1 -1
- package/dist/{PackageRegistry-CStmqgw_.d.ts → PackageRegistry-BF6WA6w6.d.ts} +97 -1
- package/dist/{PackageRegistry-DiHxyxrn.d.cts → PackageRegistry-bOwZZ3Co.d.cts} +97 -1
- package/dist/{VMBuiltins-BwqFO2TY.d.cts → VMBuiltins-8xIW2gTv.d.cts} +13 -2
- package/dist/{VMBuiltins-h09nijID.d.ts → VMBuiltins-ChJ7Joj0.d.ts} +13 -2
- package/dist/{chunk-44BWHZ5V.js → chunk-2YHOWQ43.js} +2 -2
- package/dist/chunk-2YHOWQ43.js.map +1 -0
- package/dist/{chunk-IUCUBHFW.js → chunk-3A3GT46U.js} +2 -2
- package/dist/{chunk-IUCUBHFW.js.map → chunk-3A3GT46U.js.map} +1 -1
- package/dist/chunk-3ZLMMX25.js +2 -0
- package/dist/{chunk-ZXNM355C.js.map → chunk-3ZLMMX25.js.map} +1 -1
- package/dist/chunk-4BNV5KTW.cjs +5 -0
- package/dist/chunk-4BNV5KTW.cjs.map +1 -0
- package/dist/{chunk-HFES6BF5.cjs → chunk-K2OUNZZG.cjs} +2 -2
- package/dist/chunk-K2OUNZZG.cjs.map +1 -0
- package/dist/chunk-KE6SELT2.js +3 -0
- package/dist/{chunk-4LMPCB2V.js.map → chunk-KE6SELT2.js.map} +1 -1
- package/dist/{chunk-KVONXXPJ.cjs → chunk-KEUEXSHE.cjs} +3 -3
- package/dist/{chunk-KVONXXPJ.cjs.map → chunk-KEUEXSHE.cjs.map} +1 -1
- package/dist/{chunk-ZOS4RCB7.js → chunk-KEZIXLRU.js} +2 -2
- package/dist/{chunk-ZOS4RCB7.js.map → chunk-KEZIXLRU.js.map} +1 -1
- package/dist/chunk-MLYKA4XG.js +3 -0
- package/dist/chunk-MLYKA4XG.js.map +1 -0
- package/dist/{chunk-DTOSRC6E.cjs → chunk-NEK3QTWY.cjs} +2 -2
- package/dist/{chunk-DTOSRC6E.cjs.map → chunk-NEK3QTWY.cjs.map} +1 -1
- package/dist/chunk-PXHGWBUG.js +5 -0
- package/dist/chunk-PXHGWBUG.js.map +1 -0
- package/dist/{chunk-U54BIYXO.cjs → chunk-RKNUCZ6P.cjs} +2 -2
- package/dist/{chunk-U54BIYXO.cjs.map → chunk-RKNUCZ6P.cjs.map} +1 -1
- package/dist/{chunk-TOCCIZVE.cjs → chunk-T65HJSSB.cjs} +2 -2
- package/dist/{chunk-TOCCIZVE.cjs.map → chunk-T65HJSSB.cjs.map} +1 -1
- package/dist/chunk-TWXUJJVP.cjs +3 -0
- package/dist/chunk-TWXUJJVP.cjs.map +1 -0
- package/dist/chunk-WRKDFQXE.cjs +2 -0
- package/dist/chunk-WRKDFQXE.cjs.map +1 -0
- package/dist/chunk-XKUYR2ZK.js +2 -0
- package/dist/chunk-XKUYR2ZK.js.map +1 -0
- package/dist/constants.cjs +1 -1
- package/dist/constants.js +1 -1
- package/dist/engine.cjs +1 -1
- package/dist/engine.d.cts +42 -4
- package/dist/engine.d.ts +42 -4
- package/dist/engine.js +1 -1
- package/dist/engine.worker.cjs +1 -1
- package/dist/engine.worker.js +1 -1
- package/dist/engine.worker.js.map +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-25JO4SYL.cjs +0 -5
- package/dist/chunk-25JO4SYL.cjs.map +0 -1
- package/dist/chunk-3TXVKQLL.js +0 -5
- package/dist/chunk-3TXVKQLL.js.map +0 -1
- package/dist/chunk-44BWHZ5V.js.map +0 -1
- package/dist/chunk-4LMPCB2V.js +0 -3
- package/dist/chunk-6ADFAXTZ.cjs +0 -2
- package/dist/chunk-6ADFAXTZ.cjs.map +0 -1
- package/dist/chunk-AFNK2LUO.js +0 -2
- package/dist/chunk-AFNK2LUO.js.map +0 -1
- package/dist/chunk-H4EJRCXT.js +0 -3
- package/dist/chunk-H4EJRCXT.js.map +0 -1
- package/dist/chunk-HFES6BF5.cjs.map +0 -1
- package/dist/chunk-OUMFZQ6N.cjs +0 -3
- package/dist/chunk-OUMFZQ6N.cjs.map +0 -1
- package/dist/chunk-ZXNM355C.js +0 -2
|
@@ -2,7 +2,7 @@ import { a as PrecedenceParser, b as PrefixParselet, I as InfixParselet } from '
|
|
|
2
2
|
import { M as MarkdownLineType, L as Lexer, e as TokenCategory, c as LexerVocabulary } from './Lexer-DPn5dfCH.js';
|
|
3
3
|
import { IAsyncResolver } from './resolvers.js';
|
|
4
4
|
import { T as TokenFusion, c as TokenNormalizer, a as NormalizerRule } from './TokenNormalizer-DAzPp-j1.js';
|
|
5
|
-
import { b as VMCheckpointer, D as DependencyGraph, V as VM, h as DagSnapshot, i as EngineContext, S as ScopeManager, P as PluginFunctionHandler, A as AsConverter } from './VMBuiltins-
|
|
5
|
+
import { b as VMCheckpointer, D as DependencyGraph, V as VM, h as DagSnapshot, i as EngineContext, S as ScopeManager, P as PluginFunctionHandler, A as AsConverter } from './VMBuiltins-ChJ7Joj0.js';
|
|
6
6
|
import { V as Value, b as ValueType, D as DatetimeGrain } from './Value-B55Hvn3e.js';
|
|
7
7
|
import { a as BytecodeProgram } from './BytecodeBuilder-DSWKZi4f.js';
|
|
8
8
|
import { C as CalendarBackend } from './CalendarBackend-MdS3Bb4P.js';
|
|
@@ -2241,6 +2241,13 @@ declare class ExpressionEngine {
|
|
|
2241
2241
|
* DAG walk + re-evaluation pass. Replaces the old single-callback pattern.
|
|
2242
2242
|
*/
|
|
2243
2243
|
private batcher;
|
|
2244
|
+
/**
|
|
2245
|
+
* Names that may no longer be defined, pending the end of the pass.
|
|
2246
|
+
*
|
|
2247
|
+
* Null rather than an empty set, because a document that never removes a
|
|
2248
|
+
* definition never allocates one. See {@link settleOrphanedNames}.
|
|
2249
|
+
*/
|
|
2250
|
+
private orphanCandidates;
|
|
2244
2251
|
/**
|
|
2245
2252
|
* Drives proactive background refresh of live values, or `null` when the
|
|
2246
2253
|
* host has not enabled it (the default). See {@link BackgroundRefreshManager}.
|
|
@@ -2386,6 +2393,27 @@ declare class ExpressionEngine {
|
|
|
2386
2393
|
* Tests use this to access `batcher._testCaptures` for synchronous
|
|
2387
2394
|
* event observation without async stream reader timing issues.
|
|
2388
2395
|
*/
|
|
2396
|
+
/** The names of every user-defined unit in scope, for detecting a removal. */
|
|
2397
|
+
userUnitNames(): string[];
|
|
2398
|
+
/**
|
|
2399
|
+
* Drop every user unit defined by `lineNumber`, for a line being removed.
|
|
2400
|
+
*
|
|
2401
|
+
* A line being recompiled clears its own definitions on the way through, so
|
|
2402
|
+
* this is for the line that will never be compiled again.
|
|
2403
|
+
*
|
|
2404
|
+
* @param lineId - The persistent id of the line being deleted.
|
|
2405
|
+
* @returns Whether the line had defined anything.
|
|
2406
|
+
*/
|
|
2407
|
+
undefineUserUnitsFrom(lineId: number): boolean;
|
|
2408
|
+
/**
|
|
2409
|
+
* Recompile everything, because a user unit is no longer in scope.
|
|
2410
|
+
*
|
|
2411
|
+
* A unit is expanded while a line is compiled, so a line that used one holds
|
|
2412
|
+
* bytecode built around it. Losing the definition has to reach that bytecode
|
|
2413
|
+
* or the conversion goes on working from a definition the document no longer
|
|
2414
|
+
* contains.
|
|
2415
|
+
*/
|
|
2416
|
+
invalidateForRemovedUserUnits(): void;
|
|
2389
2417
|
getBatcher(): AsyncResolutionBatcher;
|
|
2390
2418
|
/**
|
|
2391
2419
|
* Register a package with the engine's isolated registries.
|
|
@@ -2544,6 +2572,74 @@ declare class ExpressionEngine {
|
|
|
2544
2572
|
* @param reads - Variable keys the line reads.
|
|
2545
2573
|
* @param writes - Variable keys the line writes.
|
|
2546
2574
|
*/
|
|
2575
|
+
/**
|
|
2576
|
+
* Forget names that no line defines any more.
|
|
2577
|
+
*
|
|
2578
|
+
* The graph reports a key when the line that wrote it stops doing so and no
|
|
2579
|
+
* other line writes it. The VM's variable store only ever accumulated, so
|
|
2580
|
+
* the value outlived the line: deleting `:x = 12` left `x + 4` answering
|
|
2581
|
+
* `16` for the rest of the session.
|
|
2582
|
+
*
|
|
2583
|
+
* The checkpoint chain is told as well, since it records what each line
|
|
2584
|
+
* wrote and would otherwise put the name back on the next restore.
|
|
2585
|
+
*
|
|
2586
|
+
* Only variable names. The key space also holds category tags, globals,
|
|
2587
|
+
* data sources and line positions, and none of those is a VM binding; a
|
|
2588
|
+
* prefix is what tells them apart, and a variable's key is the bare name.
|
|
2589
|
+
*
|
|
2590
|
+
* @param orphaned - Keys the graph reports as no longer written by any line.
|
|
2591
|
+
*/
|
|
2592
|
+
/**
|
|
2593
|
+
* Forget a name the graph says no line writes any more.
|
|
2594
|
+
*
|
|
2595
|
+
* Reported by {@link DependencyGraph.registerLine} and its `removeLine` when
|
|
2596
|
+
* the line that wrote a key stops doing so and no other line writes it. The
|
|
2597
|
+
* VM's variable store only ever accumulated, so the value outlived the line:
|
|
2598
|
+
* deleting `:x = 12` left `x + 4` answering `16` for the rest of the
|
|
2599
|
+
* session.
|
|
2600
|
+
*
|
|
2601
|
+
* The graph is not the authority here, the document is, and for two
|
|
2602
|
+
* ordering reasons. A line holding several inline expressions registers once
|
|
2603
|
+
* per expression, so the one that defines a name is followed by one that
|
|
2604
|
+
* does not, and the graph would report an orphan mid-line; the document
|
|
2605
|
+
* holds the line's aggregate write set and does not. And a structural edit
|
|
2606
|
+
* clears the graph, so afterwards it would call every name undefined. A
|
|
2607
|
+
* line's recorded write set survives both, and is up to date for the line
|
|
2608
|
+
* being registered, because a pass stores the line's results before it
|
|
2609
|
+
* registers its edges.
|
|
2610
|
+
*
|
|
2611
|
+
* Answering here rather than at the end of the pass is what lets the lines
|
|
2612
|
+
* BELOW the edit see it on the same pass rather than the next one.
|
|
2613
|
+
*
|
|
2614
|
+
* The checkpoint chain is told as well, since it records what each line
|
|
2615
|
+
* wrote and would otherwise put the name back on the next restore.
|
|
2616
|
+
*
|
|
2617
|
+
* Only variable names: the key space also holds category tags, globals,
|
|
2618
|
+
* data sources and line positions, and none of those is a VM binding.
|
|
2619
|
+
*
|
|
2620
|
+
* @param orphaned - Keys that just lost their last writer in the graph.
|
|
2621
|
+
*/
|
|
2622
|
+
forgetOrphanedNames(orphaned: readonly string[]): void;
|
|
2623
|
+
/**
|
|
2624
|
+
* Decide the candidates: forget the ones no line defines any more.
|
|
2625
|
+
*
|
|
2626
|
+
* Asked once, at the end of a pass, because deciding as each line registers
|
|
2627
|
+
* cannot work. A line holding several inline expressions registers once per
|
|
2628
|
+
* expression, so the one that defines a name is followed by one that does
|
|
2629
|
+
* not; and the engine registers a line before the pass records that line's
|
|
2630
|
+
* results, so its recorded write set is a pass behind. Both would answer
|
|
2631
|
+
* wrongly mid-pass. At the end of one, every line has registered and the
|
|
2632
|
+
* document is current.
|
|
2633
|
+
*
|
|
2634
|
+
* The document is the authority, not the graph: a structural edit clears
|
|
2635
|
+
* the graph, and a viewport leaves the lines outside it unregistered, while
|
|
2636
|
+
* a line's recorded write set survives both.
|
|
2637
|
+
*
|
|
2638
|
+
* The reader of a forgotten name updates on the following pass, which an
|
|
2639
|
+
* editor makes anyway. It is not made to happen sooner because every way of
|
|
2640
|
+
* doing that answers the question before it can be answered correctly.
|
|
2641
|
+
*/
|
|
2642
|
+
settleOrphanedNames(): void;
|
|
2547
2643
|
private registerLineWithTags;
|
|
2548
2644
|
/**
|
|
2549
2645
|
* Execute bytecode and handle the result.
|
|
@@ -2,7 +2,7 @@ import { a as PrecedenceParser, b as PrefixParselet, I as InfixParselet } from '
|
|
|
2
2
|
import { M as MarkdownLineType, L as Lexer, e as TokenCategory, c as LexerVocabulary } from './Lexer-DaWkCu84.cjs';
|
|
3
3
|
import { IAsyncResolver } from './resolvers.cjs';
|
|
4
4
|
import { T as TokenFusion, c as TokenNormalizer, a as NormalizerRule } from './TokenNormalizer-D382VSYh.cjs';
|
|
5
|
-
import { b as VMCheckpointer, D as DependencyGraph, V as VM, h as DagSnapshot, i as EngineContext, S as ScopeManager, P as PluginFunctionHandler, A as AsConverter } from './VMBuiltins-
|
|
5
|
+
import { b as VMCheckpointer, D as DependencyGraph, V as VM, h as DagSnapshot, i as EngineContext, S as ScopeManager, P as PluginFunctionHandler, A as AsConverter } from './VMBuiltins-8xIW2gTv.cjs';
|
|
6
6
|
import { V as Value, b as ValueType, D as DatetimeGrain } from './Value-B55Hvn3e.cjs';
|
|
7
7
|
import { a as BytecodeProgram } from './BytecodeBuilder-DSWKZi4f.cjs';
|
|
8
8
|
import { C as CalendarBackend } from './CalendarBackend-MdS3Bb4P.cjs';
|
|
@@ -2241,6 +2241,13 @@ declare class ExpressionEngine {
|
|
|
2241
2241
|
* DAG walk + re-evaluation pass. Replaces the old single-callback pattern.
|
|
2242
2242
|
*/
|
|
2243
2243
|
private batcher;
|
|
2244
|
+
/**
|
|
2245
|
+
* Names that may no longer be defined, pending the end of the pass.
|
|
2246
|
+
*
|
|
2247
|
+
* Null rather than an empty set, because a document that never removes a
|
|
2248
|
+
* definition never allocates one. See {@link settleOrphanedNames}.
|
|
2249
|
+
*/
|
|
2250
|
+
private orphanCandidates;
|
|
2244
2251
|
/**
|
|
2245
2252
|
* Drives proactive background refresh of live values, or `null` when the
|
|
2246
2253
|
* host has not enabled it (the default). See {@link BackgroundRefreshManager}.
|
|
@@ -2386,6 +2393,27 @@ declare class ExpressionEngine {
|
|
|
2386
2393
|
* Tests use this to access `batcher._testCaptures` for synchronous
|
|
2387
2394
|
* event observation without async stream reader timing issues.
|
|
2388
2395
|
*/
|
|
2396
|
+
/** The names of every user-defined unit in scope, for detecting a removal. */
|
|
2397
|
+
userUnitNames(): string[];
|
|
2398
|
+
/**
|
|
2399
|
+
* Drop every user unit defined by `lineNumber`, for a line being removed.
|
|
2400
|
+
*
|
|
2401
|
+
* A line being recompiled clears its own definitions on the way through, so
|
|
2402
|
+
* this is for the line that will never be compiled again.
|
|
2403
|
+
*
|
|
2404
|
+
* @param lineId - The persistent id of the line being deleted.
|
|
2405
|
+
* @returns Whether the line had defined anything.
|
|
2406
|
+
*/
|
|
2407
|
+
undefineUserUnitsFrom(lineId: number): boolean;
|
|
2408
|
+
/**
|
|
2409
|
+
* Recompile everything, because a user unit is no longer in scope.
|
|
2410
|
+
*
|
|
2411
|
+
* A unit is expanded while a line is compiled, so a line that used one holds
|
|
2412
|
+
* bytecode built around it. Losing the definition has to reach that bytecode
|
|
2413
|
+
* or the conversion goes on working from a definition the document no longer
|
|
2414
|
+
* contains.
|
|
2415
|
+
*/
|
|
2416
|
+
invalidateForRemovedUserUnits(): void;
|
|
2389
2417
|
getBatcher(): AsyncResolutionBatcher;
|
|
2390
2418
|
/**
|
|
2391
2419
|
* Register a package with the engine's isolated registries.
|
|
@@ -2544,6 +2572,74 @@ declare class ExpressionEngine {
|
|
|
2544
2572
|
* @param reads - Variable keys the line reads.
|
|
2545
2573
|
* @param writes - Variable keys the line writes.
|
|
2546
2574
|
*/
|
|
2575
|
+
/**
|
|
2576
|
+
* Forget names that no line defines any more.
|
|
2577
|
+
*
|
|
2578
|
+
* The graph reports a key when the line that wrote it stops doing so and no
|
|
2579
|
+
* other line writes it. The VM's variable store only ever accumulated, so
|
|
2580
|
+
* the value outlived the line: deleting `:x = 12` left `x + 4` answering
|
|
2581
|
+
* `16` for the rest of the session.
|
|
2582
|
+
*
|
|
2583
|
+
* The checkpoint chain is told as well, since it records what each line
|
|
2584
|
+
* wrote and would otherwise put the name back on the next restore.
|
|
2585
|
+
*
|
|
2586
|
+
* Only variable names. The key space also holds category tags, globals,
|
|
2587
|
+
* data sources and line positions, and none of those is a VM binding; a
|
|
2588
|
+
* prefix is what tells them apart, and a variable's key is the bare name.
|
|
2589
|
+
*
|
|
2590
|
+
* @param orphaned - Keys the graph reports as no longer written by any line.
|
|
2591
|
+
*/
|
|
2592
|
+
/**
|
|
2593
|
+
* Forget a name the graph says no line writes any more.
|
|
2594
|
+
*
|
|
2595
|
+
* Reported by {@link DependencyGraph.registerLine} and its `removeLine` when
|
|
2596
|
+
* the line that wrote a key stops doing so and no other line writes it. The
|
|
2597
|
+
* VM's variable store only ever accumulated, so the value outlived the line:
|
|
2598
|
+
* deleting `:x = 12` left `x + 4` answering `16` for the rest of the
|
|
2599
|
+
* session.
|
|
2600
|
+
*
|
|
2601
|
+
* The graph is not the authority here, the document is, and for two
|
|
2602
|
+
* ordering reasons. A line holding several inline expressions registers once
|
|
2603
|
+
* per expression, so the one that defines a name is followed by one that
|
|
2604
|
+
* does not, and the graph would report an orphan mid-line; the document
|
|
2605
|
+
* holds the line's aggregate write set and does not. And a structural edit
|
|
2606
|
+
* clears the graph, so afterwards it would call every name undefined. A
|
|
2607
|
+
* line's recorded write set survives both, and is up to date for the line
|
|
2608
|
+
* being registered, because a pass stores the line's results before it
|
|
2609
|
+
* registers its edges.
|
|
2610
|
+
*
|
|
2611
|
+
* Answering here rather than at the end of the pass is what lets the lines
|
|
2612
|
+
* BELOW the edit see it on the same pass rather than the next one.
|
|
2613
|
+
*
|
|
2614
|
+
* The checkpoint chain is told as well, since it records what each line
|
|
2615
|
+
* wrote and would otherwise put the name back on the next restore.
|
|
2616
|
+
*
|
|
2617
|
+
* Only variable names: the key space also holds category tags, globals,
|
|
2618
|
+
* data sources and line positions, and none of those is a VM binding.
|
|
2619
|
+
*
|
|
2620
|
+
* @param orphaned - Keys that just lost their last writer in the graph.
|
|
2621
|
+
*/
|
|
2622
|
+
forgetOrphanedNames(orphaned: readonly string[]): void;
|
|
2623
|
+
/**
|
|
2624
|
+
* Decide the candidates: forget the ones no line defines any more.
|
|
2625
|
+
*
|
|
2626
|
+
* Asked once, at the end of a pass, because deciding as each line registers
|
|
2627
|
+
* cannot work. A line holding several inline expressions registers once per
|
|
2628
|
+
* expression, so the one that defines a name is followed by one that does
|
|
2629
|
+
* not; and the engine registers a line before the pass records that line's
|
|
2630
|
+
* results, so its recorded write set is a pass behind. Both would answer
|
|
2631
|
+
* wrongly mid-pass. At the end of one, every line has registered and the
|
|
2632
|
+
* document is current.
|
|
2633
|
+
*
|
|
2634
|
+
* The document is the authority, not the graph: a structural edit clears
|
|
2635
|
+
* the graph, and a viewport leaves the lines outside it unregistered, while
|
|
2636
|
+
* a line's recorded write set survives both.
|
|
2637
|
+
*
|
|
2638
|
+
* The reader of a forgotten name updates on the following pass, which an
|
|
2639
|
+
* editor makes anyway. It is not made to happen sooner because every way of
|
|
2640
|
+
* doing that answers the question before it can be answered correctly.
|
|
2641
|
+
*/
|
|
2642
|
+
settleOrphanedNames(): void;
|
|
2547
2643
|
private registerLineWithTags;
|
|
2548
2644
|
/**
|
|
2549
2645
|
* Execute bytecode and handle the result.
|
|
@@ -680,7 +680,7 @@ declare class DependencyGraph {
|
|
|
680
680
|
* @param reads - Variable names this line reads
|
|
681
681
|
* @param writes - Variable names this line writes (assigns to)
|
|
682
682
|
*/
|
|
683
|
-
registerLine(lineNumber: number, reads: string[], writes: string[]):
|
|
683
|
+
registerLine(lineNumber: number, reads: string[], writes: string[]): readonly string[];
|
|
684
684
|
/**
|
|
685
685
|
* Register a line's dependency on an external data source (e.g., currency rate, OSRS GE price).
|
|
686
686
|
*
|
|
@@ -758,7 +758,7 @@ declare class DependencyGraph {
|
|
|
758
758
|
*
|
|
759
759
|
* @param lineNumber - The line number being removed
|
|
760
760
|
*/
|
|
761
|
-
removeLine(lineNumber: number):
|
|
761
|
+
removeLine(lineNumber: number): readonly string[];
|
|
762
762
|
/**
|
|
763
763
|
* Get all line numbers that consume (read) a given variable.
|
|
764
764
|
*
|
|
@@ -1058,6 +1058,17 @@ declare class VMCheckpointer {
|
|
|
1058
1058
|
* @returns Whether a checkpoint existed at that line.
|
|
1059
1059
|
*/
|
|
1060
1060
|
applyCheckpointAt(lineNumber: number): boolean;
|
|
1061
|
+
/**
|
|
1062
|
+
* Drop `names` from every checkpoint, as though no line had ever set them.
|
|
1063
|
+
*
|
|
1064
|
+
* A checkpoint records what its line wrote, so a name whose defining line
|
|
1065
|
+
* has been deleted or edited into something else is still in the chain, and
|
|
1066
|
+
* the next restore would put it back into the VM after the VM had been told
|
|
1067
|
+
* to forget it. The two have to agree.
|
|
1068
|
+
*
|
|
1069
|
+
* @param names - The names no line defines any more.
|
|
1070
|
+
*/
|
|
1071
|
+
forget(names: readonly string[]): void;
|
|
1061
1072
|
/**
|
|
1062
1073
|
* Find the nearest checkpoint at or before the given line number.
|
|
1063
1074
|
*
|
|
@@ -680,7 +680,7 @@ declare class DependencyGraph {
|
|
|
680
680
|
* @param reads - Variable names this line reads
|
|
681
681
|
* @param writes - Variable names this line writes (assigns to)
|
|
682
682
|
*/
|
|
683
|
-
registerLine(lineNumber: number, reads: string[], writes: string[]):
|
|
683
|
+
registerLine(lineNumber: number, reads: string[], writes: string[]): readonly string[];
|
|
684
684
|
/**
|
|
685
685
|
* Register a line's dependency on an external data source (e.g., currency rate, OSRS GE price).
|
|
686
686
|
*
|
|
@@ -758,7 +758,7 @@ declare class DependencyGraph {
|
|
|
758
758
|
*
|
|
759
759
|
* @param lineNumber - The line number being removed
|
|
760
760
|
*/
|
|
761
|
-
removeLine(lineNumber: number):
|
|
761
|
+
removeLine(lineNumber: number): readonly string[];
|
|
762
762
|
/**
|
|
763
763
|
* Get all line numbers that consume (read) a given variable.
|
|
764
764
|
*
|
|
@@ -1058,6 +1058,17 @@ declare class VMCheckpointer {
|
|
|
1058
1058
|
* @returns Whether a checkpoint existed at that line.
|
|
1059
1059
|
*/
|
|
1060
1060
|
applyCheckpointAt(lineNumber: number): boolean;
|
|
1061
|
+
/**
|
|
1062
|
+
* Drop `names` from every checkpoint, as though no line had ever set them.
|
|
1063
|
+
*
|
|
1064
|
+
* A checkpoint records what its line wrote, so a name whose defining line
|
|
1065
|
+
* has been deleted or edited into something else is still in the chain, and
|
|
1066
|
+
* the next restore would put it back into the VM after the VM had been told
|
|
1067
|
+
* to forget it. The two have to agree.
|
|
1068
|
+
*
|
|
1069
|
+
* @param names - The names no line defines any more.
|
|
1070
|
+
*/
|
|
1071
|
+
forget(names: readonly string[]): void;
|
|
1061
1072
|
/**
|
|
1062
1073
|
* Find the nearest checkpoint at or before the given line number.
|
|
1063
1074
|
*
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
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}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}};export{f as a};//# sourceMappingURL=chunk-
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
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}};export{f as a};//# sourceMappingURL=chunk-2YHOWQ43.js.map
|
|
2
|
+
//# sourceMappingURL=chunk-2YHOWQ43.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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":"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","file":"chunk-2YHOWQ43.js","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"]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {a,d}from'./chunk-U5MESNRT.js';import {a as a$2}from'./chunk-AFNK2LUO.js';import {b as b$1}from'./chunk-EOO6M65F.js';import {f,b as b$2}from'./chunk-J4K72CQN.js';import {a as a$1}from'./chunk-APYRNAU2.js';import {c}from'./chunk-FAO6DQ74.js';import {c as c$1}from'./chunk-6G2NES2I.js';var M=class{constructor(){this.category="Symbolic";}parse(e,o,t){e.consume("LPAREN"),e.parseExpression(a.Lowest,t),e.consume("RPAREN"),t.emitOpcode(51),t.emitIndex(67),t.emitIndex(1);}};var S=class{constructor(){this.category="Symbolic";}parse(e,o,t){e.consume("LPAREN"),e.parseExpression(a.Lowest,t),e.consume("RPAREN"),t.emitOpcode(51),t.emitIndex(68),t.emitIndex(1);}};function B(r,e){let o=r.peek();if(!o||o.type!=="IDENT"&&o.type!=="UNIT")throw c$1.parsing("SYMBOLIC_REQUIRES_VARIABLE_NAME",`${e} needs the name of an unknown here, as in ${e}(x^2, x).`,{found:o?.type??"end of input"});return r.consume(),o.value}function A(r,e){r.emitOpcode(13),r.emitString(e);}function T(r,e,o){let t=new d(e.pluginIndexMap);r.parseExpression(a.Lowest,t),r.setBuilder(e);let n=t.build();if(n.hasAsync)throw c$1.parsing("SYMBOLIC_ARGUMENT_MUST_BE_SYNCHRONOUS",`${o}'s expression must be synchronous (no weather/stocks/currency calls).`);return n}function _(r,e,o){let t=r.emitAnonymousBody([o],e);r.emitOpcode(159),r.emitIndex(t);}var k=class{constructor(){this.category="Symbolic";}parse(e,o,t){e.consume("LPAREN");let n=T(e,t,"solve"),i=e.match("EQUALS")?T(e,t,"solve"):null;e.consume("COMMA");let a=e.peek();if(!a||a.type!=="IDENT"&&a.type!=="UNIT")throw c$1.parsing("SOLVE_REQUIRES_VARIABLE_NAME","solve's second argument must be the name of the unknown to solve for, as in solve(x^2-4=0, x).",{found:a?.type??"end of input"});e.consume(),_(t,n,a.value),i?_(t,i,a.value):(t.emitOpcode(10),t.emitNumber(0)),A(t,a.value),e.consume("RPAREN"),t.emitOpcode(51),t.emitIndex(69),t.emitIndex(3);}};var b=class{constructor(){this.category="Symbolic";}parse(e,o,t){e.consume("LPAREN");let n=T(e,t,"der");e.consume("COMMA");let i=B(e,"der");_(t,n,i),A(t,i),e.match("COMMA")?e.parseExpression(a.Lowest,t):(t.emitOpcode(10),t.emitNumber(1)),e.consume("RPAREN"),t.emitOpcode(51),t.emitIndex(70),t.emitIndex(3);}};var F=class{constructor(){this.category="Symbolic";}parse(e,o,t){e.consume("LPAREN");let n=T(e,t,"integral");e.consume("COMMA");let i=B(e,"integral");_(t,n,i),A(t,i),e.consume("RPAREN"),t.emitOpcode(51),t.emitIndex(71),t.emitIndex(2);}};var w=class{constructor(){this.category="Symbolic";}parse(e,o,t){e.consume("LPAREN");let n=T(e,t,"taylor");e.consume("COMMA");let i=B(e,"taylor");_(t,n,i),A(t,i),e.consume("EQUALS"),e.parseExpression(a.Lowest,t),e.consume("COMMA"),e.parseExpression(a.Lowest,t),e.consume("RPAREN"),t.emitOpcode(51),t.emitIndex(72),t.emitIndex(4);}};var Y=class{constructor(){this.category="Symbolic";}parse(e,o,t){e.consume("LPAREN");let n=0;do e.parseExpression(a.Lowest,t),n++;while(e.match("COMMA"));e.consume("RPAREN"),t.emitOpcode(51),t.emitIndex(73),t.emitIndex(n);}};var v=class{constructor(){this.category="Symbolic";}parse(e,o,t){t.emitOpcode(10),t.emitNumber(Number(o.value)),t.emitOpcode(51),t.emitIndex(74),t.emitIndex(1);}};var U=class{constructor(){this.category="Symbolic";}parse(e,o,t){e.consume("LPAREN"),e.parseExpression(a.Lowest,t),e.consume("RPAREN"),t.emitOpcode(51),t.emitIndex(75),t.emitIndex(1);}};var $=class{constructor(){this.category="Symbolic";}parse(e,o,t){e.consume("LPAREN"),e.parseExpression(a.Lowest,t),e.consume("RPAREN"),t.emitOpcode(51),t.emitIndex(76),t.emitIndex(1);}};var z=class{constructor(){this.category="Symbolic";}parse(e,o,t){e.consume("LPAREN"),e.parseExpression(a.Lowest,t),e.consume("RPAREN"),t.emitOpcode(51),t.emitIndex(77),t.emitIndex(1);}};var j=class{constructor(){this.category="Symbolic";}parse(e,o,t){e.consume("LPAREN"),e.parseExpression(a.Lowest,t),e.consume("RPAREN"),t.emitOpcode(51),t.emitIndex(78),t.emitIndex(1);}};var G=class{constructor(){this.category="Symbolic";}parse(e,o,t){e.consume("LPAREN"),e.parseExpression(a.Lowest,t),e.consume("RPAREN"),t.emitOpcode(51),t.emitIndex(79),t.emitIndex(1);}};function ae(r=75){return {name:"symbolic:imaginary-literal",priority:r,shape:[{types:["NUMBER"]},{types:["IDENT"],values:["i"]}],match(e,o){let t=e[o];if(!t||t.type!=="NUMBER")return null;let n=e[o+1];return !n||n.type!=="IDENT"||n.value!=="i"||n.offset!==t.offset+t.value.length||e[o+2]?.type==="LPAREN"?null:{consumed:2,replacement:[new a$1("IMAGINARY",c("IMAGINARY"),t.value,t.value,t.offset,0,t.line,t.col)],ruleName:"symbolic:imaginary-literal"}}}}var se={expand:"EXPAND_FN",factor:"FACTOR_FN",solve:"SOLVE_FN",der:"DER_FN",derivative:"DER_FN",integral:"INTEGRAL_FN",taylor:"TAYLOR_FN",jacobian:"JACOBIAN_FN",conj:"CONJ_FN",re:"RE_FN",im:"IM_FN",cancel:"CANCEL_FN",apart:"APART_FN"};function me(r=80){return {name:"symbolic:call",priority:r,shape:[{types:["IDENT"],values:Object.keys(se)},{types:["LPAREN"]}],match(e,o){let t=e[o];if(!t||t.type!=="IDENT")return null;let n=se[t.value.toLowerCase()];return !n||e[o+1]?.type!=="LPAREN"?null:{consumed:1,replacement:[new a$1(n,c(n),t.value,t.value,t.offset,0,t.line,t.col)],ruleName:"symbolic:call"}}}}var le=[{word:"expand",tokenType:"EXPAND_FN",builtinIndex:67,example:"expand((x+1)*(x+2))",expected:"x^2+3x+2",docPage:"expanding.md"},{word:"factor",tokenType:"FACTOR_FN",builtinIndex:68,example:"factor(x^2-4)",expected:"(x-2)*(x+2)",docPage:"factoring.md"},{word:"solve",tokenType:"SOLVE_FN",builtinIndex:69,example:"solve(x^2-4=0, x)",expected:"= [-2, 2]",docPage:"solving-equations.md"},{word:"der",tokenType:"DER_FN",builtinIndex:70,example:"der(x^3, x)",expected:"3x^2",docPage:"calculus.md"},{word:"integral",tokenType:"INTEGRAL_FN",builtinIndex:71,example:"integral(x^2, x)",expected:"1/3x^3",docPage:"calculus.md"},{word:"taylor",tokenType:"TAYLOR_FN",builtinIndex:72,example:"taylor(exp(x), x=0, 3)",expected:"1/6x^3+0.5x^2+x+1",docPage:"calculus.md"},{word:"jacobian",tokenType:"JACOBIAN_FN",builtinIndex:73,example:"jacobian(x*y, x+y)",expected:"= [y, x; 1, 1]",docPage:"calculus.md"},{word:"conj",tokenType:"CONJ_FN",builtinIndex:75,example:"conj(2+3i)",expected:"2-3i",docPage:"complex.md"},{word:"re",tokenType:"RE_FN",builtinIndex:76,example:"re(2+3i)",expected:"= 2",docPage:"complex.md"},{word:"im",tokenType:"IM_FN",builtinIndex:77,example:"im(2+3i)",expected:"= 3",docPage:"complex.md"},{word:"cancel",tokenType:"CANCEL_FN",builtinIndex:78,example:"cancel((x^2-1)/(x-1))",expected:"x+1",docPage:"cancelling-fractions.md"},{word:"apart",tokenType:"APART_FN",builtinIndex:79,example:"apart((3x+5)/(x^2-1))",expected:"4/(x-1)-1/(x+1)",docPage:"splitting-fractions.md"}],Ye={name:"solve-symbolic",normalizerRules:[me(),ae()],prefixParselets:{EXPAND_FN:new M,FACTOR_FN:new S,SOLVE_FN:new k,DER_FN:new b,INTEGRAL_FN:new F,TAYLOR_FN:new w,JACOBIAN_FN:new Y,IMAGINARY:new v,CONJ_FN:new U,RE_FN:new $,IM_FN:new z,CANCEL_FN:new j,APART_FN:new G},tokenCategories:{EXPAND_FN:"keyword",FACTOR_FN:"keyword",SOLVE_FN:"keyword",DER_FN:"keyword",INTEGRAL_FN:"keyword",TAYLOR_FN:"keyword",JACOBIAN_FN:"keyword",IMAGINARY:"number",CONJ_FN:"keyword",RE_FN:"keyword",IM_FN:"keyword",CANCEL_FN:"keyword",APART_FN:"keyword"}},ve=new Set(le.map(r=>r.tokenType));function Ue(r){return r.some(e=>ve.has(e.type))}var de=r=>a$2("tag",r.toLowerCase());function $e(r){return r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}var ce=/(?:total|sum|average|count)\s+of\s+$/i,ue=64,Z=/(?:^|[^0-9A-Za-z_])#([0-9A-Za-z_-]+)(?![0-9A-Za-z_-])/g;function yr(r,e,o){let t=pe(r);return t.members.length===0&&t.queries.length===0?{reads:e,writes:o}:{reads:t.queries.length===0?e:[...e,...t.queries.map(de)],writes:t.members.length===0?o:[...o,...t.members.map(de)]}}function Nr(r){let e=pe(r).members;for(let o=0;o<e.length;o++)e[o]=e[o].toLowerCase();return e}function pe(r){let e=[],o=[],t=r.search(/\S/);Z.lastIndex=0;for(let n=Z.exec(r);n!==null;n=Z.exec(r)){let i=n.index+n[0].indexOf("#");if(t===i)continue;let a=n[1];if(ce.test(r.slice(Math.max(0,i-ue),i))){o.push(a);continue}e.push(a);}return {members:e,queries:o}}function Ir(r,e){if(e==="")return false;let o=new RegExp(`(?:^|[^0-9A-Za-z_])#${$e(e)}(?![0-9A-Za-z_-])`,"gi"),t=r.search(/\S/);for(let n=o.exec(r);n!==null;n=o.exec(r)){let i=n.index+n[0].indexOf("#");if(t!==i&&!ce.test(r.slice(Math.max(0,i-ue),i)))return true}return false}var ze=/^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:?\d{2})?)?$/;function fe(r,e){let o=r.trim();if(o.length>=2&&o.startsWith('"')&&o.endsWith('"')&&(o=o.slice(1,-1)),!ze.test(o))return null;let t=e.parseIso8601(o);return Number.isNaN(t)?null:t}var je=/^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(Z|[+-]\d{2}:?\d{2})?)?$/;function Tr(r){let e=je.exec(r.trim());if(e===null||e[1]===void 0)return {grain:"date"};let o=e[2];if(o===void 0)return {grain:"datetime"};if(o==="Z")return {grain:"instant",zone:f(0)};let t=o[0]==="-"?-1:1,n=o.slice(1).replace(":",""),i=Number(n.slice(0,2))*60+Number(n.slice(2));return {grain:"instant",zone:f(t*i)}}function _r(r,e){let o=e.fields(r),t=N=>String(N).padStart(2,"0"),n=o.year,i=t(o.month0+1),a=t(o.day),m=t(o.hour),d=t(o.minute),f=t(o.second),l=e.utcOffsetMinutes(r),p=l>=0?"+":"-",y=Math.abs(l),u=t(Math.floor(y/60)),s=t(y%60);return `${n}-${i}-${a}T${m}:${d}:${f}${p}${u}:${s}`}var Ge=1e12;function Er(r){return Math.abs(r)>=Ge?r:r*1e3}var Ve=Date.UTC(2026,3,3),ye,R,K=new Map;function He(){return typeof Intl=="object"&&Intl!==null?Intl.DateTimeFormat:void 0}function Ne(){let r=He();r!==ye&&(ye=r,R=void 0,K.clear());}function Je(){if(Ne(),R!==void 0)return R;try{let r=new Intl.DateTimeFormat("ja-JP").resolvedOptions().locale;R=typeof r=="string"&&r.startsWith("ja");}catch{R=false;}return R}function Ie(){if(typeof Intl!="object"||Intl===null||typeof Intl.DateTimeFormat!="function")return null;try{let r=new Intl.DateTimeFormat().resolvedOptions().locale;return typeof r=="string"&&r.length>0?r:null}catch{return null}}function xe(r){Ne();let e=K.get(r);if(e!==void 0)return e;let o=We(r);return K.set(r,o),o}function We(r){if(typeof Intl!="object"||Intl===null||typeof Intl.DateTimeFormat!="function"||!Je())return null;try{if(typeof Intl.DateTimeFormat.supportedLocalesOf=="function"&&Intl.DateTimeFormat.supportedLocalesOf([r]).length===0)return null;let e=new Intl.DateTimeFormat(r,{calendar:"gregory",numberingSystem:"latn",timeZone:"UTC",year:"numeric",month:"numeric",day:"numeric"}).formatToParts(Ve);if(!Array.isArray(e))return null;let o=e.filter(t=>t.type==="year"||t.type==="month"||t.type==="day").map(t=>t.type[0].toUpperCase()).join("");return o==="DMY"||o==="MDY"||o==="YMD"?o:null}catch{return null}}var C={DATE_INPUT_LOCALE_INVALID:"DATE_INPUT_LOCALE_INVALID",DATE_ORDER_MISMATCH:"DATE_ORDER_MISMATCH",DATE_NOT_A_CALENDAR_DAY:"DATE_NOT_A_CALENDAR_DAY"};function Ze(r){if(typeof Intl!="object"||Intl===null||typeof Intl.getCanonicalLocales!="function")return true;try{return Intl.getCanonicalLocales(r),!0}catch{return false}}function Rr(r){let e=r.inputLocale;if(e!==void 0&&!Ze(e))throw c$1.config(C.DATE_INPUT_LOCALE_INVALID,`date.inputLocale "${e}" is not a BCP-47 locale tag. Use a tag Intl accepts, for example "en-US".`,{inputLocale:e});let o=r.onAmbiguous,t=r.inputOrder;if(t==="DMY"||t==="MDY"||t==="YMD")return Object.freeze({order:t,orderSource:"config",onAmbiguous:o});if(t==="locale"){let n=e??Ie();if(n!=null){let i=xe(n);if(i!==null)return Object.freeze({order:i,orderSource:e!==void 0?"locale":"host-locale",locale:n,onAmbiguous:o})}return Object.freeze({order:"auto",orderSource:"fallback",onAmbiguous:o})}return Object.freeze({order:"auto",orderSource:"separator",onAmbiguous:o})}var Te=["January","February","March","April","May","June","July","August","September","October","November","December"],q=/^\d{1,2}$/,X=/^\d{4}$/;function Ke(r,e,o,t){let n=q.test(r),i=q.test(e),a=q.test(o);return t==="hyphen"&&X.test(r)&&i&&a?"iso":n&&i&&X.test(o)?"year-last-4":t==="slash"&&X.test(r)&&i&&a?"year-first-4":n&&i&&a?"short":"none"}function qe(r){if(r.length===4)return Number(r);if(r.length===2){let e=Number(r);return e<=68?2e3+e:1900+e}return null}function O(r,e,o){return e<1||e>12||r<1?false:r<=b$2(o,e-1)}function _e(r,e,o){return e<1||e>12?`there is no month ${e}`:r<1?`there is no day ${r}`:`${Te[e-1]} ${o} has ${b$2(o,e-1)} days`}function P(r,e,o){return `${r} ${Te[e-1]} ${o}`}function Q(r,e,o){let t=n=>String(n).padStart(2,"0");return `${String(o).padStart(4,"0")}-${t(e)}-${t(r)}`}function V(r,e,o){return r==="DMY"?{day:Number(e),month:Number(o)}:{day:Number(o),month:Number(e)}}function D(r){return r==="DMY"?"day first":r==="MDY"?"month first":"year first"}function Xe(r){return r==="hyphen"?"MDY":"DMY"}function te(r,e,o,t){let[n,i,a]=r.groups,m=Ke(n,i,a,r.separator),d=r.separator!=="dot",f=o==="refuse"||!d;if(m==="none")return {kind:"arithmetic"};if(m==="iso"){let g=Number(n),x=Number(i),I=Number(a);return O(I,x,g)?{kind:"date",day:I,month:x,year:g,order:"ISO",shortYear:false}:f?ee(r.text,I,x,g):{kind:"arithmetic"}}if(m==="year-first-4"){if(e!=="YMD")return {kind:"arithmetic"};let g=Number(n),x=Number(i),I=Number(a);return O(I,x,g)?{kind:"date",day:I,month:x,year:g,order:"YMD",shortYear:false}:{kind:"arithmetic"}}let l=qe(a);if(l===null)return {kind:"arithmetic"};let p=a.length===2;if(e==="YMD")return !f||m==="short"&&d?{kind:"arithmetic"}:Qe(r.text,n,i,l);let y=e==="auto"?Xe(r.separator):e,u=y==="DMY"?"MDY":"DMY",s=V(y,n,i),N=V(u,n,i);if(O(s.day,s.month,l)){let x=(N.day!==s.day||N.month!==s.month)&&O(N.day,N.month,l)?Q(N.day,N.month,l):void 0;return {kind:"date",day:s.day,month:s.month,year:l,order:y,shortYear:p,alternative:x}}return !f||m==="short"&&d?{kind:"arithmetic"}:O(N.day,N.month,l)?{kind:"refuse",code:C.DATE_ORDER_MISMATCH,message:`"${r.text}" is not a date read ${D(y)}: ${_e(s.day,s.month,l)}. Read ${D(u)} it is ${P(N.day,N.month,l)}. Set date.inputOrder to "${u}" to read numeric dates ${D(u)}.`}:ee(r.text,s.day,s.month,l)}function ee(r,e,o,t){return {kind:"refuse",code:C.DATE_NOT_A_CALENDAR_DAY,message:`"${r}" is not a real date: ${_e(e,o,t)}.`}}function Qe(r,e,o,t,n){let i=V("DMY",e,o),a=V("MDY",e,o),m=O(i.day,i.month,t),d=O(a.day,a.month,t);if(!m&&!d)return ee(r,i.day,i.month,t);let f=`"${r}" is not a date read year first.`,l=i.day===a.day&&i.month===a.month;if(m&&d&&!l)return {kind:"refuse",code:C.DATE_ORDER_MISMATCH,message:`${f} Read day first it is ${P(i.day,i.month,t)} and month first ${P(a.day,a.month,t)}. Write it as ${Q(i.day,i.month,t)}, or set date.inputOrder to "DMY" or "MDY".`};let p=m?i:a,y=m?"DMY":"MDY";return {kind:"refuse",code:C.DATE_ORDER_MISMATCH,message:`${f} Read ${D(y)} it is ${P(p.day,p.month,t)}. Write it as ${Q(p.day,p.month,t)}, or set date.inputOrder to "${y}".`}}function et(r,e){if(r.orderSource==="iso")return "ISO";if(r.orderSource==="spelled")return "with the month spelled out";let o=r.order===null||r.order==="ISO"||r.order==="spelled"?"as written":D(r.order);switch(r.orderSource){case "config":return `${o}, from date.inputOrder`;case "locale":return `${o}, from the locale ${r.locale}`;case "host-locale":return `${o}, from the host locale ${r.locale}`;case "fallback":return `${o}, the default for a ${e} date, because the host locale could not be read`;default:return `${o}, the default for a ${e} date`}}function ge(r){let[e,o,t]=r.split("-").map(Number);return P(t,o,e)}function tt(r,e,o){if(r.iso===null)return o??`"${r.text}" is not a date this engine can read.`;let t=`${r.text} read as ${ge(r.iso)}, ${et(r,e)}.`;if(r.alternative!==void 0&&r.order!==null&&r.order!=="ISO"&&r.order!=="spelled"){let n=r.order==="DMY"?"Month first":"Day first";t+=` ${n} would be ${ge(r.alternative)}.`;}return r.shortYear&&(t+=` The two-digit year ${r.text.slice(-2)} was read as ${r.iso.slice(0,4)}.`),t}function Pr(r,e,o){return {...r,note:tt(r,e,o),needsNote:r.contested||r.shortYear||r.iso===null}}function Dr(r){let e=/^(\d+)([/-])(\d+)\2(\d+)$/.exec(r);if(e!==null)return {text:r,groups:[e[1],e[3],e[4]],separator:e[2]==="-"?"hyphen":"slash"};let o=/^(\d{1,2})\.(\d{1,2})\.(\d{2}|\d{4})$/.exec(r);return o!==null?{text:r,groups:[o[1],o[2],o[3]],separator:"dot"}:null}var re="DATETIME_LITERAL",Le=c(re),he="DATETIME_LITERAL_UNREADABLE",rt=c(he),H=/^\d+$/,ot=/^\d{1,2}\.\d{1,2}$/,nt=/^\.(\d{2}|\d{4})$/;function it(r){for(let e=0;e<r.length-1;e++){let o=r[e];if((o.sourceEnd??o.offset+o.text.length)!==r[e+1].offset)return false}return true}function Ee(r,e,o,t,n,i){if(e<1||e>12||r<1||r>31)return null;let a=i.localMidnight(o,e-1,r),m=i.fields(a);if(m.year!==o||m.month0!==e-1||m.day!==r)return null;let d=t[0],f=t.map(p=>p.value).join(""),l=new a$1(re,Le,String(a),f,d.offset,0,d.line,d.col);return {consumed:t.length,replacement:[l],ruleName:n}}function at(r){let e="",o=-1;for(let t of r){let n=t.text??t.value;o>=0&&t.offset>o&&(e+=" "),e+=n,o=t.sourceEnd??t.offset+n.length;}return e}function Ae(r,e,o,t){let n=o[0],i=at(o),a=new a$1(he,rt,i,i,n.offset,0,n.line,n.col);return a.fault={code:r,message:e},{consumed:o.length,replacement:[a],ruleName:t}}var st=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:?\d{2})?/,mt=new Set(["NUMBER","MINUS","PLUS","COLON","IDENT"]),lt=16;function dt(r,e,o,t){let n=r[e];if(n.sourceEnd!==void 0)return null;let i=n.text,a=n.offset+n.text.length,m=[n];for(let u=e+1;u<r.length&&m.length<lt;u++){let s=r[u];if(s.sourceEnd!==void 0||s.offset!==a||!mt.has(s.type))break;i+=s.text,a=s.offset+s.text.length,m.push(s);}let d=st.exec(i);if(d===null)return null;let f=0,l=0;for(let u of m)if(l+=u.text.length,f++,l>=d[0].length)break;if(l!==d[0].length)return null;let p=fe(d[0],t);if(p===null)return null;let y=new a$1(re,Le,String(p),d[0],n.offset,0,n.line,n.col,n.offset+d[0].length);return {consumed:f,replacement:[y],ruleName:o}}function wr(r=()=>"auto",e=()=>b$1,o=()=>"refuse"){return {name:"datetime:date-literal",priority:70,shape:[{types:["NUMBER"]}],match(t,n){let i=t[n];if(i.type!=="NUMBER")return null;let a=e();if(ot.test(i.value)){let s=t[n+1];if(s&&s.type==="NUMBER"&&nt.test(s.value)){let[N,g]=i.value.split("."),x={text:`${i.value}${s.value}`,groups:[N,g,s.value.slice(1)],separator:"dot"},I=te(x,r(),o());if(I.kind==="date")return Ee(I.day,I.month,I.year,[i,s],"datetime:date-literal:dot",a);if(I.kind==="refuse")return Ae(I.code,I.message,[i,s],"datetime:date-literal:dot:unreadable")}return null}if(i.value.length===4&&H.test(i.value)){let s=dt(t,n,"datetime:date-literal:iso-timestamp",a);if(s)return s}if(!H.test(i.value))return null;let m=t[n+1];if(!m||m.type!=="SLASH"&&m.type!=="MINUS")return null;let d=t[n+2],f=t[n+3],l=t[n+4];if(!d||d.type!=="NUMBER"||!H.test(d.value)||!f||f.type!==m.type||!l||l.type!=="NUMBER"||!H.test(l.value))return null;let p=[i,m,d,f,l];if(!it(p))return null;let y={text:p.map(s=>s.value).join(""),groups:[i.value,d.value,l.value],separator:m.type==="MINUS"?"hyphen":"slash"},u=te(y,r(),o());return u.kind==="arithmetic"?null:u.kind==="refuse"?Ae(u.code,u.message,p,"datetime:date-literal:unreadable"):Ee(u.day,u.month,u.year,p,`datetime:date-literal:${u.order.toLowerCase()}`,a)}}}export{yr as a,Nr as b,Ir as c,Ye as d,Ue as e,fe as f,Tr as g,_r as h,Er as i,C as j,Rr as k,Ke as l,_e as m,Q as n,te as o,Pr as p,Dr as q,re as r,he as s,Ee as t,at as u,Ae as v,wr as w};//# sourceMappingURL=chunk-IUCUBHFW.js.map
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import {a,d}from'./chunk-U5MESNRT.js';import {a as a$2}from'./chunk-XKUYR2ZK.js';import {b as b$1}from'./chunk-EOO6M65F.js';import {f,b as b$2}from'./chunk-J4K72CQN.js';import {a as a$1}from'./chunk-APYRNAU2.js';import {c}from'./chunk-FAO6DQ74.js';import {c as c$1}from'./chunk-6G2NES2I.js';var M=class{constructor(){this.category="Symbolic";}parse(e,o,t){e.consume("LPAREN"),e.parseExpression(a.Lowest,t),e.consume("RPAREN"),t.emitOpcode(51),t.emitIndex(67),t.emitIndex(1);}};var S=class{constructor(){this.category="Symbolic";}parse(e,o,t){e.consume("LPAREN"),e.parseExpression(a.Lowest,t),e.consume("RPAREN"),t.emitOpcode(51),t.emitIndex(68),t.emitIndex(1);}};function B(r,e){let o=r.peek();if(!o||o.type!=="IDENT"&&o.type!=="UNIT")throw c$1.parsing("SYMBOLIC_REQUIRES_VARIABLE_NAME",`${e} needs the name of an unknown here, as in ${e}(x^2, x).`,{found:o?.type??"end of input"});return r.consume(),o.value}function A(r,e){r.emitOpcode(13),r.emitString(e);}function T(r,e,o){let t=new d(e.pluginIndexMap);r.parseExpression(a.Lowest,t),r.setBuilder(e);let n=t.build();if(n.hasAsync)throw c$1.parsing("SYMBOLIC_ARGUMENT_MUST_BE_SYNCHRONOUS",`${o}'s expression must be synchronous (no weather/stocks/currency calls).`);return n}function _(r,e,o){let t=r.emitAnonymousBody([o],e);r.emitOpcode(159),r.emitIndex(t);}var k=class{constructor(){this.category="Symbolic";}parse(e,o,t){e.consume("LPAREN");let n=T(e,t,"solve"),i=e.match("EQUALS")?T(e,t,"solve"):null;e.consume("COMMA");let a=e.peek();if(!a||a.type!=="IDENT"&&a.type!=="UNIT")throw c$1.parsing("SOLVE_REQUIRES_VARIABLE_NAME","solve's second argument must be the name of the unknown to solve for, as in solve(x^2-4=0, x).",{found:a?.type??"end of input"});e.consume(),_(t,n,a.value),i?_(t,i,a.value):(t.emitOpcode(10),t.emitNumber(0)),A(t,a.value),e.consume("RPAREN"),t.emitOpcode(51),t.emitIndex(69),t.emitIndex(3);}};var b=class{constructor(){this.category="Symbolic";}parse(e,o,t){e.consume("LPAREN");let n=T(e,t,"der");e.consume("COMMA");let i=B(e,"der");_(t,n,i),A(t,i),e.match("COMMA")?e.parseExpression(a.Lowest,t):(t.emitOpcode(10),t.emitNumber(1)),e.consume("RPAREN"),t.emitOpcode(51),t.emitIndex(70),t.emitIndex(3);}};var F=class{constructor(){this.category="Symbolic";}parse(e,o,t){e.consume("LPAREN");let n=T(e,t,"integral");e.consume("COMMA");let i=B(e,"integral");_(t,n,i),A(t,i),e.consume("RPAREN"),t.emitOpcode(51),t.emitIndex(71),t.emitIndex(2);}};var w=class{constructor(){this.category="Symbolic";}parse(e,o,t){e.consume("LPAREN");let n=T(e,t,"taylor");e.consume("COMMA");let i=B(e,"taylor");_(t,n,i),A(t,i),e.consume("EQUALS"),e.parseExpression(a.Lowest,t),e.consume("COMMA"),e.parseExpression(a.Lowest,t),e.consume("RPAREN"),t.emitOpcode(51),t.emitIndex(72),t.emitIndex(4);}};var Y=class{constructor(){this.category="Symbolic";}parse(e,o,t){e.consume("LPAREN");let n=0;do e.parseExpression(a.Lowest,t),n++;while(e.match("COMMA"));e.consume("RPAREN"),t.emitOpcode(51),t.emitIndex(73),t.emitIndex(n);}};var v=class{constructor(){this.category="Symbolic";}parse(e,o,t){t.emitOpcode(10),t.emitNumber(Number(o.value)),t.emitOpcode(51),t.emitIndex(74),t.emitIndex(1);}};var U=class{constructor(){this.category="Symbolic";}parse(e,o,t){e.consume("LPAREN"),e.parseExpression(a.Lowest,t),e.consume("RPAREN"),t.emitOpcode(51),t.emitIndex(75),t.emitIndex(1);}};var $=class{constructor(){this.category="Symbolic";}parse(e,o,t){e.consume("LPAREN"),e.parseExpression(a.Lowest,t),e.consume("RPAREN"),t.emitOpcode(51),t.emitIndex(76),t.emitIndex(1);}};var z=class{constructor(){this.category="Symbolic";}parse(e,o,t){e.consume("LPAREN"),e.parseExpression(a.Lowest,t),e.consume("RPAREN"),t.emitOpcode(51),t.emitIndex(77),t.emitIndex(1);}};var j=class{constructor(){this.category="Symbolic";}parse(e,o,t){e.consume("LPAREN"),e.parseExpression(a.Lowest,t),e.consume("RPAREN"),t.emitOpcode(51),t.emitIndex(78),t.emitIndex(1);}};var G=class{constructor(){this.category="Symbolic";}parse(e,o,t){e.consume("LPAREN"),e.parseExpression(a.Lowest,t),e.consume("RPAREN"),t.emitOpcode(51),t.emitIndex(79),t.emitIndex(1);}};function ae(r=75){return {name:"symbolic:imaginary-literal",priority:r,shape:[{types:["NUMBER"]},{types:["IDENT"],values:["i"]}],match(e,o){let t=e[o];if(!t||t.type!=="NUMBER")return null;let n=e[o+1];return !n||n.type!=="IDENT"||n.value!=="i"||n.offset!==t.offset+t.value.length||e[o+2]?.type==="LPAREN"?null:{consumed:2,replacement:[new a$1("IMAGINARY",c("IMAGINARY"),t.value,t.value,t.offset,0,t.line,t.col)],ruleName:"symbolic:imaginary-literal"}}}}var se={expand:"EXPAND_FN",factor:"FACTOR_FN",solve:"SOLVE_FN",der:"DER_FN",derivative:"DER_FN",integral:"INTEGRAL_FN",taylor:"TAYLOR_FN",jacobian:"JACOBIAN_FN",conj:"CONJ_FN",re:"RE_FN",im:"IM_FN",cancel:"CANCEL_FN",apart:"APART_FN"};function me(r=80){return {name:"symbolic:call",priority:r,shape:[{types:["IDENT"],values:Object.keys(se)},{types:["LPAREN"]}],match(e,o){let t=e[o];if(!t||t.type!=="IDENT")return null;let n=se[t.value.toLowerCase()];return !n||e[o+1]?.type!=="LPAREN"?null:{consumed:1,replacement:[new a$1(n,c(n),t.value,t.value,t.offset,0,t.line,t.col)],ruleName:"symbolic:call"}}}}var le=[{word:"expand",tokenType:"EXPAND_FN",builtinIndex:67,example:"expand((x+1)*(x+2))",expected:"x^2+3x+2",docPage:"expanding.md"},{word:"factor",tokenType:"FACTOR_FN",builtinIndex:68,example:"factor(x^2-4)",expected:"(x-2)*(x+2)",docPage:"factoring.md"},{word:"solve",tokenType:"SOLVE_FN",builtinIndex:69,example:"solve(x^2-4=0, x)",expected:"= [-2, 2]",docPage:"solving-equations.md"},{word:"der",tokenType:"DER_FN",builtinIndex:70,example:"der(x^3, x)",expected:"3x^2",docPage:"calculus.md"},{word:"integral",tokenType:"INTEGRAL_FN",builtinIndex:71,example:"integral(x^2, x)",expected:"1/3x^3",docPage:"calculus.md"},{word:"taylor",tokenType:"TAYLOR_FN",builtinIndex:72,example:"taylor(exp(x), x=0, 3)",expected:"1/6x^3+0.5x^2+x+1",docPage:"calculus.md"},{word:"jacobian",tokenType:"JACOBIAN_FN",builtinIndex:73,example:"jacobian(x*y, x+y)",expected:"= [y, x; 1, 1]",docPage:"calculus.md"},{word:"conj",tokenType:"CONJ_FN",builtinIndex:75,example:"conj(2+3i)",expected:"2-3i",docPage:"complex.md"},{word:"re",tokenType:"RE_FN",builtinIndex:76,example:"re(2+3i)",expected:"= 2",docPage:"complex.md"},{word:"im",tokenType:"IM_FN",builtinIndex:77,example:"im(2+3i)",expected:"= 3",docPage:"complex.md"},{word:"cancel",tokenType:"CANCEL_FN",builtinIndex:78,example:"cancel((x^2-1)/(x-1))",expected:"x+1",docPage:"cancelling-fractions.md"},{word:"apart",tokenType:"APART_FN",builtinIndex:79,example:"apart((3x+5)/(x^2-1))",expected:"4/(x-1)-1/(x+1)",docPage:"splitting-fractions.md"}],Ye={name:"solve-symbolic",normalizerRules:[me(),ae()],prefixParselets:{EXPAND_FN:new M,FACTOR_FN:new S,SOLVE_FN:new k,DER_FN:new b,INTEGRAL_FN:new F,TAYLOR_FN:new w,JACOBIAN_FN:new Y,IMAGINARY:new v,CONJ_FN:new U,RE_FN:new $,IM_FN:new z,CANCEL_FN:new j,APART_FN:new G},tokenCategories:{EXPAND_FN:"keyword",FACTOR_FN:"keyword",SOLVE_FN:"keyword",DER_FN:"keyword",INTEGRAL_FN:"keyword",TAYLOR_FN:"keyword",JACOBIAN_FN:"keyword",IMAGINARY:"number",CONJ_FN:"keyword",RE_FN:"keyword",IM_FN:"keyword",CANCEL_FN:"keyword",APART_FN:"keyword"}},ve=new Set(le.map(r=>r.tokenType));function Ue(r){return r.some(e=>ve.has(e.type))}var de=r=>a$2("tag",r.toLowerCase());function $e(r){return r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}var ce=/(?:total|sum|average|count)\s+of\s+$/i,ue=64,Z=/(?:^|[^0-9A-Za-z_])#([0-9A-Za-z_-]+)(?![0-9A-Za-z_-])/g;function yr(r,e,o){let t=pe(r);return t.members.length===0&&t.queries.length===0?{reads:e,writes:o}:{reads:t.queries.length===0?e:[...e,...t.queries.map(de)],writes:t.members.length===0?o:[...o,...t.members.map(de)]}}function Nr(r){let e=pe(r).members;for(let o=0;o<e.length;o++)e[o]=e[o].toLowerCase();return e}function pe(r){let e=[],o=[],t=r.search(/\S/);Z.lastIndex=0;for(let n=Z.exec(r);n!==null;n=Z.exec(r)){let i=n.index+n[0].indexOf("#");if(t===i)continue;let a=n[1];if(ce.test(r.slice(Math.max(0,i-ue),i))){o.push(a);continue}e.push(a);}return {members:e,queries:o}}function Ir(r,e){if(e==="")return false;let o=new RegExp(`(?:^|[^0-9A-Za-z_])#${$e(e)}(?![0-9A-Za-z_-])`,"gi"),t=r.search(/\S/);for(let n=o.exec(r);n!==null;n=o.exec(r)){let i=n.index+n[0].indexOf("#");if(t!==i&&!ce.test(r.slice(Math.max(0,i-ue),i)))return true}return false}var ze=/^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:?\d{2})?)?$/;function fe(r,e){let o=r.trim();if(o.length>=2&&o.startsWith('"')&&o.endsWith('"')&&(o=o.slice(1,-1)),!ze.test(o))return null;let t=e.parseIso8601(o);return Number.isNaN(t)?null:t}var je=/^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(Z|[+-]\d{2}:?\d{2})?)?$/;function Tr(r){let e=je.exec(r.trim());if(e===null||e[1]===void 0)return {grain:"date"};let o=e[2];if(o===void 0)return {grain:"datetime"};if(o==="Z")return {grain:"instant",zone:f(0)};let t=o[0]==="-"?-1:1,n=o.slice(1).replace(":",""),i=Number(n.slice(0,2))*60+Number(n.slice(2));return {grain:"instant",zone:f(t*i)}}function _r(r,e){let o=e.fields(r),t=N=>String(N).padStart(2,"0"),n=o.year,i=t(o.month0+1),a=t(o.day),m=t(o.hour),d=t(o.minute),f=t(o.second),l=e.utcOffsetMinutes(r),p=l>=0?"+":"-",y=Math.abs(l),u=t(Math.floor(y/60)),s=t(y%60);return `${n}-${i}-${a}T${m}:${d}:${f}${p}${u}:${s}`}var Ge=1e12;function Er(r){return Math.abs(r)>=Ge?r:r*1e3}var Ve=Date.UTC(2026,3,3),ye,R,K=new Map;function He(){return typeof Intl=="object"&&Intl!==null?Intl.DateTimeFormat:void 0}function Ne(){let r=He();r!==ye&&(ye=r,R=void 0,K.clear());}function Je(){if(Ne(),R!==void 0)return R;try{let r=new Intl.DateTimeFormat("ja-JP").resolvedOptions().locale;R=typeof r=="string"&&r.startsWith("ja");}catch{R=false;}return R}function Ie(){if(typeof Intl!="object"||Intl===null||typeof Intl.DateTimeFormat!="function")return null;try{let r=new Intl.DateTimeFormat().resolvedOptions().locale;return typeof r=="string"&&r.length>0?r:null}catch{return null}}function xe(r){Ne();let e=K.get(r);if(e!==void 0)return e;let o=We(r);return K.set(r,o),o}function We(r){if(typeof Intl!="object"||Intl===null||typeof Intl.DateTimeFormat!="function"||!Je())return null;try{if(typeof Intl.DateTimeFormat.supportedLocalesOf=="function"&&Intl.DateTimeFormat.supportedLocalesOf([r]).length===0)return null;let e=new Intl.DateTimeFormat(r,{calendar:"gregory",numberingSystem:"latn",timeZone:"UTC",year:"numeric",month:"numeric",day:"numeric"}).formatToParts(Ve);if(!Array.isArray(e))return null;let o=e.filter(t=>t.type==="year"||t.type==="month"||t.type==="day").map(t=>t.type[0].toUpperCase()).join("");return o==="DMY"||o==="MDY"||o==="YMD"?o:null}catch{return null}}var C={DATE_INPUT_LOCALE_INVALID:"DATE_INPUT_LOCALE_INVALID",DATE_ORDER_MISMATCH:"DATE_ORDER_MISMATCH",DATE_NOT_A_CALENDAR_DAY:"DATE_NOT_A_CALENDAR_DAY"};function Ze(r){if(typeof Intl!="object"||Intl===null||typeof Intl.getCanonicalLocales!="function")return true;try{return Intl.getCanonicalLocales(r),!0}catch{return false}}function Rr(r){let e=r.inputLocale;if(e!==void 0&&!Ze(e))throw c$1.config(C.DATE_INPUT_LOCALE_INVALID,`date.inputLocale "${e}" is not a BCP-47 locale tag. Use a tag Intl accepts, for example "en-US".`,{inputLocale:e});let o=r.onAmbiguous,t=r.inputOrder;if(t==="DMY"||t==="MDY"||t==="YMD")return Object.freeze({order:t,orderSource:"config",onAmbiguous:o});if(t==="locale"){let n=e??Ie();if(n!=null){let i=xe(n);if(i!==null)return Object.freeze({order:i,orderSource:e!==void 0?"locale":"host-locale",locale:n,onAmbiguous:o})}return Object.freeze({order:"auto",orderSource:"fallback",onAmbiguous:o})}return Object.freeze({order:"auto",orderSource:"separator",onAmbiguous:o})}var Te=["January","February","March","April","May","June","July","August","September","October","November","December"],q=/^\d{1,2}$/,X=/^\d{4}$/;function Ke(r,e,o,t){let n=q.test(r),i=q.test(e),a=q.test(o);return t==="hyphen"&&X.test(r)&&i&&a?"iso":n&&i&&X.test(o)?"year-last-4":t==="slash"&&X.test(r)&&i&&a?"year-first-4":n&&i&&a?"short":"none"}function qe(r){if(r.length===4)return Number(r);if(r.length===2){let e=Number(r);return e<=68?2e3+e:1900+e}return null}function O(r,e,o){return e<1||e>12||r<1?false:r<=b$2(o,e-1)}function _e(r,e,o){return e<1||e>12?`there is no month ${e}`:r<1?`there is no day ${r}`:`${Te[e-1]} ${o} has ${b$2(o,e-1)} days`}function P(r,e,o){return `${r} ${Te[e-1]} ${o}`}function Q(r,e,o){let t=n=>String(n).padStart(2,"0");return `${String(o).padStart(4,"0")}-${t(e)}-${t(r)}`}function V(r,e,o){return r==="DMY"?{day:Number(e),month:Number(o)}:{day:Number(o),month:Number(e)}}function D(r){return r==="DMY"?"day first":r==="MDY"?"month first":"year first"}function Xe(r){return r==="hyphen"?"MDY":"DMY"}function te(r,e,o,t){let[n,i,a]=r.groups,m=Ke(n,i,a,r.separator),d=r.separator!=="dot",f=o==="refuse"||!d;if(m==="none")return {kind:"arithmetic"};if(m==="iso"){let g=Number(n),x=Number(i),I=Number(a);return O(I,x,g)?{kind:"date",day:I,month:x,year:g,order:"ISO",shortYear:false}:f?ee(r.text,I,x,g):{kind:"arithmetic"}}if(m==="year-first-4"){if(e!=="YMD")return {kind:"arithmetic"};let g=Number(n),x=Number(i),I=Number(a);return O(I,x,g)?{kind:"date",day:I,month:x,year:g,order:"YMD",shortYear:false}:{kind:"arithmetic"}}let l=qe(a);if(l===null)return {kind:"arithmetic"};let p=a.length===2;if(e==="YMD")return !f||m==="short"&&d?{kind:"arithmetic"}:Qe(r.text,n,i,l);let y=e==="auto"?Xe(r.separator):e,u=y==="DMY"?"MDY":"DMY",s=V(y,n,i),N=V(u,n,i);if(O(s.day,s.month,l)){let x=(N.day!==s.day||N.month!==s.month)&&O(N.day,N.month,l)?Q(N.day,N.month,l):void 0;return {kind:"date",day:s.day,month:s.month,year:l,order:y,shortYear:p,alternative:x}}return !f||m==="short"&&d?{kind:"arithmetic"}:O(N.day,N.month,l)?{kind:"refuse",code:C.DATE_ORDER_MISMATCH,message:`"${r.text}" is not a date read ${D(y)}: ${_e(s.day,s.month,l)}. Read ${D(u)} it is ${P(N.day,N.month,l)}. Set date.inputOrder to "${u}" to read numeric dates ${D(u)}.`}:ee(r.text,s.day,s.month,l)}function ee(r,e,o,t){return {kind:"refuse",code:C.DATE_NOT_A_CALENDAR_DAY,message:`"${r}" is not a real date: ${_e(e,o,t)}.`}}function Qe(r,e,o,t,n){let i=V("DMY",e,o),a=V("MDY",e,o),m=O(i.day,i.month,t),d=O(a.day,a.month,t);if(!m&&!d)return ee(r,i.day,i.month,t);let f=`"${r}" is not a date read year first.`,l=i.day===a.day&&i.month===a.month;if(m&&d&&!l)return {kind:"refuse",code:C.DATE_ORDER_MISMATCH,message:`${f} Read day first it is ${P(i.day,i.month,t)} and month first ${P(a.day,a.month,t)}. Write it as ${Q(i.day,i.month,t)}, or set date.inputOrder to "DMY" or "MDY".`};let p=m?i:a,y=m?"DMY":"MDY";return {kind:"refuse",code:C.DATE_ORDER_MISMATCH,message:`${f} Read ${D(y)} it is ${P(p.day,p.month,t)}. Write it as ${Q(p.day,p.month,t)}, or set date.inputOrder to "${y}".`}}function et(r,e){if(r.orderSource==="iso")return "ISO";if(r.orderSource==="spelled")return "with the month spelled out";let o=r.order===null||r.order==="ISO"||r.order==="spelled"?"as written":D(r.order);switch(r.orderSource){case "config":return `${o}, from date.inputOrder`;case "locale":return `${o}, from the locale ${r.locale}`;case "host-locale":return `${o}, from the host locale ${r.locale}`;case "fallback":return `${o}, the default for a ${e} date, because the host locale could not be read`;default:return `${o}, the default for a ${e} date`}}function ge(r){let[e,o,t]=r.split("-").map(Number);return P(t,o,e)}function tt(r,e,o){if(r.iso===null)return o??`"${r.text}" is not a date this engine can read.`;let t=`${r.text} read as ${ge(r.iso)}, ${et(r,e)}.`;if(r.alternative!==void 0&&r.order!==null&&r.order!=="ISO"&&r.order!=="spelled"){let n=r.order==="DMY"?"Month first":"Day first";t+=` ${n} would be ${ge(r.alternative)}.`;}return r.shortYear&&(t+=` The two-digit year ${r.text.slice(-2)} was read as ${r.iso.slice(0,4)}.`),t}function Pr(r,e,o){return {...r,note:tt(r,e,o),needsNote:r.contested||r.shortYear||r.iso===null}}function Dr(r){let e=/^(\d+)([/-])(\d+)\2(\d+)$/.exec(r);if(e!==null)return {text:r,groups:[e[1],e[3],e[4]],separator:e[2]==="-"?"hyphen":"slash"};let o=/^(\d{1,2})\.(\d{1,2})\.(\d{2}|\d{4})$/.exec(r);return o!==null?{text:r,groups:[o[1],o[2],o[3]],separator:"dot"}:null}var re="DATETIME_LITERAL",Le=c(re),he="DATETIME_LITERAL_UNREADABLE",rt=c(he),H=/^\d+$/,ot=/^\d{1,2}\.\d{1,2}$/,nt=/^\.(\d{2}|\d{4})$/;function it(r){for(let e=0;e<r.length-1;e++){let o=r[e];if((o.sourceEnd??o.offset+o.text.length)!==r[e+1].offset)return false}return true}function Ee(r,e,o,t,n,i){if(e<1||e>12||r<1||r>31)return null;let a=i.localMidnight(o,e-1,r),m=i.fields(a);if(m.year!==o||m.month0!==e-1||m.day!==r)return null;let d=t[0],f=t.map(p=>p.value).join(""),l=new a$1(re,Le,String(a),f,d.offset,0,d.line,d.col);return {consumed:t.length,replacement:[l],ruleName:n}}function at(r){let e="",o=-1;for(let t of r){let n=t.text??t.value;o>=0&&t.offset>o&&(e+=" "),e+=n,o=t.sourceEnd??t.offset+n.length;}return e}function Ae(r,e,o,t){let n=o[0],i=at(o),a=new a$1(he,rt,i,i,n.offset,0,n.line,n.col);return a.fault={code:r,message:e},{consumed:o.length,replacement:[a],ruleName:t}}var st=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:?\d{2})?/,mt=new Set(["NUMBER","MINUS","PLUS","COLON","IDENT"]),lt=16;function dt(r,e,o,t){let n=r[e];if(n.sourceEnd!==void 0)return null;let i=n.text,a=n.offset+n.text.length,m=[n];for(let u=e+1;u<r.length&&m.length<lt;u++){let s=r[u];if(s.sourceEnd!==void 0||s.offset!==a||!mt.has(s.type))break;i+=s.text,a=s.offset+s.text.length,m.push(s);}let d=st.exec(i);if(d===null)return null;let f=0,l=0;for(let u of m)if(l+=u.text.length,f++,l>=d[0].length)break;if(l!==d[0].length)return null;let p=fe(d[0],t);if(p===null)return null;let y=new a$1(re,Le,String(p),d[0],n.offset,0,n.line,n.col,n.offset+d[0].length);return {consumed:f,replacement:[y],ruleName:o}}function wr(r=()=>"auto",e=()=>b$1,o=()=>"refuse"){return {name:"datetime:date-literal",priority:70,shape:[{types:["NUMBER"]}],match(t,n){let i=t[n];if(i.type!=="NUMBER")return null;let a=e();if(ot.test(i.value)){let s=t[n+1];if(s&&s.type==="NUMBER"&&nt.test(s.value)){let[N,g]=i.value.split("."),x={text:`${i.value}${s.value}`,groups:[N,g,s.value.slice(1)],separator:"dot"},I=te(x,r(),o());if(I.kind==="date")return Ee(I.day,I.month,I.year,[i,s],"datetime:date-literal:dot",a);if(I.kind==="refuse")return Ae(I.code,I.message,[i,s],"datetime:date-literal:dot:unreadable")}return null}if(i.value.length===4&&H.test(i.value)){let s=dt(t,n,"datetime:date-literal:iso-timestamp",a);if(s)return s}if(!H.test(i.value))return null;let m=t[n+1];if(!m||m.type!=="SLASH"&&m.type!=="MINUS")return null;let d=t[n+2],f=t[n+3],l=t[n+4];if(!d||d.type!=="NUMBER"||!H.test(d.value)||!f||f.type!==m.type||!l||l.type!=="NUMBER"||!H.test(l.value))return null;let p=[i,m,d,f,l];if(!it(p))return null;let y={text:p.map(s=>s.value).join(""),groups:[i.value,d.value,l.value],separator:m.type==="MINUS"?"hyphen":"slash"},u=te(y,r(),o());return u.kind==="arithmetic"?null:u.kind==="refuse"?Ae(u.code,u.message,p,"datetime:date-literal:unreadable"):Ee(u.day,u.month,u.year,p,`datetime:date-literal:${u.order.toLowerCase()}`,a)}}}export{yr as a,Nr as b,Ir as c,Ye as d,Ue as e,fe as f,Tr as g,_r as h,Er as i,C as j,Rr as k,Ke as l,_e as m,Q as n,te as o,Pr as p,Dr as q,re as r,he as s,Ee as t,at as u,Ae as v,wr as w};//# sourceMappingURL=chunk-3A3GT46U.js.map
|
|
2
|
+
//# sourceMappingURL=chunk-3A3GT46U.js.map
|