@tellegen/svelte 0.2.0 → 0.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 (88) hide show
  1. package/README.md +269 -5
  2. package/dist/Sparkline.svelte +2 -2
  3. package/dist/TellegenMap.svelte +518 -202
  4. package/dist/TellegenMap.svelte.d.ts +45 -0
  5. package/dist/TellegenProvider.svelte +40 -4
  6. package/dist/TellegenShell.svelte +24 -46
  7. package/dist/TellegenViewer.svelte +12 -2
  8. package/dist/api.d.ts +18 -3
  9. package/dist/api.js +8 -2
  10. package/dist/basemap.d.ts +192 -0
  11. package/dist/basemap.js +259 -0
  12. package/dist/colors.d.ts +25 -7
  13. package/dist/colors.js +39 -13
  14. package/dist/components/AppFooter.svelte +3 -2
  15. package/dist/components/AppHeader.svelte +44 -19
  16. package/dist/components/BindingLines.svelte +4 -7
  17. package/dist/components/BusPicker.svelte +11 -5
  18. package/dist/components/ControlPanel.svelte +106 -343
  19. package/dist/components/DemandSlider.svelte +36 -29
  20. package/dist/components/DiagramCanvas.svelte +486 -0
  21. package/dist/components/DiagramCanvas.svelte.d.ts +13 -0
  22. package/dist/components/DisplayControls.svelte +8 -2
  23. package/dist/components/DropZone.svelte +1 -1
  24. package/dist/components/FormulationSelector.svelte +9 -4
  25. package/dist/components/LocalCaseDetails.svelte +61 -48
  26. package/dist/components/McResults.svelte +428 -0
  27. package/dist/components/McResults.svelte.d.ts +17 -0
  28. package/dist/components/ModelDetails.svelte +230 -0
  29. package/dist/components/ModelDetails.svelte.d.ts +7 -0
  30. package/dist/components/MulticonductorDetails.svelte +232 -83
  31. package/dist/components/NetworkStats.svelte +20 -18
  32. package/dist/components/NotificationCenter.svelte +245 -0
  33. package/dist/components/NotificationCenter.svelte.d.ts +3 -0
  34. package/dist/components/PanelCard.svelte +384 -0
  35. package/dist/components/PanelCard.svelte.d.ts +9 -0
  36. package/dist/components/PanelFrame.svelte +46 -0
  37. package/dist/components/PanelFrame.svelte.d.ts +16 -0
  38. package/dist/components/PanelHost.svelte +237 -0
  39. package/dist/components/PanelHost.svelte.d.ts +6 -0
  40. package/dist/components/PlacementCue.svelte +1 -1
  41. package/dist/components/PowerFlowDetails.svelte +99 -0
  42. package/dist/components/PowerFlowDetails.svelte.d.ts +3 -0
  43. package/dist/components/RatingSlider.svelte +19 -14
  44. package/dist/components/RestoreDefaultsButton.svelte +1 -1
  45. package/dist/components/SavedNetworkDetails.svelte +214 -0
  46. package/dist/components/SavedNetworkDetails.svelte.d.ts +3 -0
  47. package/dist/components/SensitivityReadout.svelte +26 -18
  48. package/dist/components/ShellEnvironment.svelte +51 -0
  49. package/dist/components/ShellEnvironment.svelte.d.ts +18 -0
  50. package/dist/components/SizeLegend.svelte +2 -2
  51. package/dist/components/SolveCard.svelte +48 -51
  52. package/dist/components/TopMovers.svelte +9 -4
  53. package/dist/components/TopMovers.svelte.d.ts +2 -17
  54. package/dist/components.d.ts +5 -0
  55. package/dist/components.js +5 -0
  56. package/dist/context.svelte.d.ts +8 -1
  57. package/dist/context.svelte.js +8 -3
  58. package/dist/controller.svelte.d.ts +117 -36
  59. package/dist/controller.svelte.js +1133 -253
  60. package/dist/diagram-labels.d.ts +9 -0
  61. package/dist/diagram-labels.js +40 -0
  62. package/dist/display.d.ts +3 -7
  63. package/dist/display.js +31 -27
  64. package/dist/format.d.ts +9 -0
  65. package/dist/format.js +17 -4
  66. package/dist/index.d.ts +15 -5
  67. package/dist/index.js +9 -2
  68. package/dist/map.d.ts +4 -2
  69. package/dist/map.js +2 -1
  70. package/dist/maplibre-worker.d.ts +5 -0
  71. package/dist/maplibre-worker.dev.d.ts +11 -0
  72. package/dist/maplibre-worker.dev.js +15 -0
  73. package/dist/maplibre-worker.js +8 -0
  74. package/dist/multiconductor.d.ts +11 -2
  75. package/dist/multiconductor.js +107 -14
  76. package/dist/notices.svelte.d.ts +29 -0
  77. package/dist/notices.svelte.js +86 -0
  78. package/dist/panels.svelte.d.ts +71 -0
  79. package/dist/panels.svelte.js +245 -0
  80. package/dist/slider.d.ts +12 -0
  81. package/dist/slider.js +31 -0
  82. package/dist/state.svelte.d.ts +107 -23
  83. package/dist/state.svelte.js +106 -20
  84. package/dist/styles.css +59 -6
  85. package/dist/synthetic-layout.js +1 -0
  86. package/package.json +29 -11
  87. package/dist/study-package.d.ts +0 -8
  88. package/dist/study-package.js +0 -17
@@ -1,14 +1,19 @@
1
1
  import { type TellegenApiClient } from './api.js';
2
2
  import type { BranchRatingDeltas, Network, NetworkBus, SensitivityColumn, Solution } from './api.js';
3
3
  import { CaseState, LocalCase, MulticonductorCase, type AppState, type DemandRangeMode, type SolvableCase } from './state.svelte.js';
4
- import { type BrowserStudy, type Formulation, type SensTarget } from '@tellegen/engine';
4
+ import { type EngineTransport, type McPfDetail, type McPfDetailQuery, type McPfOptions, type McPfSummary, type McStudySnapshot, type BrowserStudy, type Formulation, type IngestedCase, type PowerIoDiagnostic, type SensTarget } from '@tellegen/engine';
5
5
  /** A parsed geographic sidecar awaiting application: the canonical `.geo.json`
6
6
  * layer document from the engine's tolerant reader, its source file name, and
7
7
  * the reader's notes on records it could not use. */
8
8
  type GeoLayerFile = {
9
9
  name: string;
10
10
  layer: string;
11
- warnings: string[];
11
+ diagnostics: PowerIoDiagnostic[];
12
+ };
13
+ type SavedCaseCapture = {
14
+ input: string;
15
+ solution?: string;
16
+ view?: import('@tellegen/engine').StudyView;
12
17
  };
13
18
  /** A lowered analysis row is view-only only when a current producer says so;
14
19
  * absence keeps payloads from older compatible engine/server versions editable. */
@@ -23,23 +28,54 @@ type DemandRangeAnchor = {
23
28
  };
24
29
  export interface ControllerOptions {
25
30
  api?: TellegenApiClient;
26
- apiBase?: string;
31
+ /** Backend base path. `null` means there is no backend: no client is
32
+ * created and nothing is ever fetched. */
33
+ apiBase?: string | null;
34
+ /** Whether `load()` fetches the bundled cases. Default `true`. With
35
+ * `false`, `load()` only marks the shell loaded and frames the map. */
36
+ loadDefaultCases?: boolean;
37
+ mcTransport?: Pick<EngineTransport, 'solveMcModule' | 'applyMcGeo'> & Partial<Pick<EngineTransport, 'solveMcStudy' | 'applyMcStudyGeo' | 'createMcPfSession'>>;
38
+ }
39
+ /** Input to `Controller.openBalancedModule` and `replaceLocalCase`: a
40
+ * balanced (transmission) powerio module, either as its JSON text or as the
41
+ * payload the engine's `ingestCase` already produced for it. */
42
+ export interface OpenBalancedModuleInput {
43
+ /** Case label; also the stem of the `.pio.json` file name the shell shows. */
44
+ name: string;
45
+ /** Module JSON, ingested through the engine. Ignored when `payload` is set. */
46
+ moduleJson?: string;
47
+ /** An already ingested balanced payload; skips the engine round trip. */
48
+ payload?: IngestedCase;
49
+ /** A `.geo.json` layer document, for a module that carries no coordinates. */
50
+ geoLayer?: string;
51
+ /** Overrides the formulation the module declares. */
52
+ formulation?: Formulation;
53
+ /** Default `true`: add the case, make it active, and start its browser
54
+ * solve. With `false` the prepared case is returned and not added. */
55
+ activate?: boolean;
56
+ /** Default `true`: fly the map to the case when it is activated. */
57
+ frame?: boolean;
27
58
  }
28
59
  export declare class Controller {
29
60
  app: AppState;
30
- api: TellegenApiClient;
61
+ /** `null` when the controller was created with `apiBase: null`; every
62
+ * server path then reports "compute off" instead of fetching. */
63
+ api: TellegenApiClient | null;
64
+ readonly loadDefaultCases: boolean;
65
+ mcTransport: Pick<EngineTransport, 'solveMcModule' | 'applyMcGeo'> & Partial<Pick<EngineTransport, 'solveMcStudy' | 'applyMcStudyGeo' | 'createMcPfSession'>>;
31
66
  abort: AbortController | null;
32
67
  sensitivity429Until: number;
33
68
  serverComputeOff: boolean;
34
69
  caseStudies: WeakMap<SolvableCase, {
35
70
  study: BrowserStudy;
36
- networkJson: string;
71
+ studyInputJson: string;
37
72
  formulation: Formulation;
38
73
  baseSolution: Solution;
39
74
  }>;
75
+ private detachedCaseCaptures;
40
76
  studyUnavailable: WeakMap<SolvableCase, string>;
41
77
  studyBuilds: WeakMap<SolvableCase, {
42
- networkJson: string;
78
+ studyInputJson: string;
43
79
  formulation: Formulation;
44
80
  token: object;
45
81
  promise: Promise<BrowserStudy | null>;
@@ -74,6 +110,7 @@ export declare class Controller {
74
110
  /** True when two selection targets name the same bus or branch. */
75
111
  sameTarget(a: SensTarget, b: SensTarget): boolean;
76
112
  isPerturbed(c: SolvableCase | null): boolean;
113
+ bumpRevision(c: SolvableCase): void;
77
114
  setNearbyRangeAnchor(c: SolvableCase, bus: number, delta?: number): void;
78
115
  beginBusSelection(c: SolvableCase, busId: number): {
79
116
  ac: AbortController;
@@ -90,12 +127,12 @@ export declare class Controller {
90
127
  rememberHiddenDefaultCase(id: string): void;
91
128
  localNetwork(c: LocalCase): Network | null;
92
129
  maybeStartLocalSolve(id: string): void;
93
- getStudy(c: SolvableCase, networkJson: string): Promise<BrowserStudy | null>;
94
- browserSensitivity(c: SolvableCase, networkJson: string, target: SensTarget): Promise<SensitivityColumn | null>;
130
+ getStudy(c: SolvableCase, studyInputJson: string): Promise<BrowserStudy | null>;
131
+ browserSensitivity(c: SolvableCase, studyInputJson: string, target: SensTarget): Promise<SensitivityColumn | null>;
95
132
  disposeStudy(c: SolvableCase): void;
96
133
  acceptSensitivity(c: SolvableCase, col: SensitivityColumn | null, target: SensTarget | null, sensitivitySeq?: number): void;
97
134
  finishSolve(c: SolvableCase, seq: number, target: SensTarget | null): void;
98
- ensureNetworkJson(c: SolvableCase): Promise<string | null>;
135
+ ensureStudyInputJson(c: SolvableCase): Promise<string | null>;
99
136
  previewDeltas(c: SolvableCase, bus: number, value: number): {
100
137
  [x: string]: number;
101
138
  [x: number]: number;
@@ -187,11 +224,15 @@ export declare class Controller {
187
224
  removeBackendCase: (c: CaseState, event?: MouseEvent) => Promise<void>;
188
225
  activateLocal: (c: LocalCase) => void;
189
226
  removeLocalCase: (c: LocalCase, event?: MouseEvent) => Promise<void>;
190
- addAndActivateLocal: (c: LocalCase) => void;
227
+ /** Add a prepared local case, make it active, frame it (unless `frame` is
228
+ * false) and start its browser solve. */
229
+ addAndActivateLocal: (c: LocalCase, options?: {
230
+ frame?: boolean;
231
+ }) => void;
191
232
  placeLocalCase: (lon: number, lat: number) => Promise<void>;
192
233
  /** Write the case's on-screen layout into its network payload
193
234
  * (`Bus.location` with `synthetic` provenance — the engine also accepts
194
- * `manual`, which round trips through restored packages), so saves,
235
+ * `manual`, which round trips through saved PowerIO modules), so saves,
195
236
  * exports, and the `.geo.json` download carry it. Best effort: on an
196
237
  * engine failure the view still renders, only the layout's persistence is
197
238
  * lost. */
@@ -205,7 +246,7 @@ export declare class Controller {
205
246
  * wins on shared elements). The engine owns matching and the network becomes
206
247
  * the single owner of the coordinates: matched points land in
207
248
  * `Bus.location`, routes in `Branch.route`, and the refreshed
208
- * `network_json` replaces the case payload — so a saved package or export
249
+ * `module_json` replaces the case IR — so a saved module or export
209
250
  * carries exactly what is on screen. A live Study is synced the same way.
210
251
  * Throws when a layer matches nothing. */
211
252
  applyGeoLayers: (c: LocalCase, layers: GeoLayerFile[]) => Promise<void>;
@@ -213,10 +254,12 @@ export declare class Controller {
213
254
  * the case's network and view, provenance flips to the geographic source,
214
255
  * and the warnings panel gets the placement summary. */
215
256
  private adoptGeoPayload;
216
- /** Keep a live Study's base network in step with a geo change (locations
217
- * are metadata the model never reads, so nothing re-solves), and re-key its
218
- * cache entry so the next solve reuses it instead of rebuilding. */
219
- private syncCachedStudy;
257
+ /** Update an existing numerical Study after the base input receives geographic data. */
258
+ private syncStudyGeo;
259
+ private caseEditKey;
260
+ private localSidecarCopy;
261
+ private stageLocalSidecars;
262
+ private attachSidecarsToSelected;
220
263
  applyGeoLayersToExisting: (layers: GeoLayerFile[]) => Promise<void>;
221
264
  /** Ask the map to frame the selected branch and wait for the camera to land,
222
265
  * capped by FOCUS_SETTLE_CAP_MS and cut short by the selection's abort. */
@@ -232,7 +275,7 @@ export declare class Controller {
232
275
  * transient (a wasm chunk or case JSON fetch), so say what is known and keep
233
276
  * the retry meaningful. */
234
277
  private computeOffNotice;
235
- /** The one server ∂LMP/∂parameter request a selection may make: the
278
+ /** The one server nodal-value/parameter request a selection may make: the
236
279
  * reconciliation path when the browser Study produced no column for a DC OPF
237
280
  * case. Never retries on its own: a second request inside the same rate limit
238
281
  * window is a guaranteed rejection, and the retry button covers the user
@@ -267,6 +310,7 @@ export declare class Controller {
267
310
  commitDelta: (value: number) => void;
268
311
  finishDemandInput: (value: number) => void;
269
312
  resetCase: (c: SolvableCase) => void;
313
+ /** Rebuild the numerical Study for a selected calculation at the current demand. */
270
314
  changeFormulation: (c: SolvableCase, next: Formulation) => void;
271
315
  /** Parse dropped files in the browser via the powerio wasm module. Case
272
316
  * files (.m, .raw, .aux, .epc, .pwb) become local networks; geographic files can
@@ -279,12 +323,12 @@ export declare class Controller {
279
323
  * the first matching PowerWorld display. A failed geographic join keeps the
280
324
  * parsed case and returns the user-facing placement error. */
281
325
  private prepareDroppedLocal;
282
- /** Fill a coordinate-less case's positions from a co-dropped PowerWorld
283
- * `.pwd`: the display's substation points project to approximate
284
- * longitude/latitude and join onto buses through the `SubNum` extras key.
285
- * The first display that joins wins; one that matches nothing stays
286
- * available as its own preview entry, and the case stays placeable. */
326
+ /** A case that still has no geometry gets a connectivity layout as its
327
+ * diagram, so it can render and solve without a placement step. */
328
+ private placeTopologyAsDiagram;
329
+ /** Retain diagram geometry separately from the electrical case's geographic data. */
287
330
  private fillFromDisplaySibling;
331
+ setCaseDisplayMode: (c: LocalCase, mode: "geographic" | "diagram") => void;
288
332
  /** Route a dropped `.json` by its content. Recognized payloads return without
289
333
  * mutating case state so co-dropped sidecars can be applied first; unrouted
290
334
  * content returns the bytes already read for the geographic fallback. */
@@ -292,10 +336,30 @@ export declare class Controller {
292
336
  /** Parse a dropped OpenDSS `.dss` file into a multiconductor viewing case.
293
337
  * Returns true when a case landed; a parse failure sets the panel error. */
294
338
  private ingestDistFile;
295
- /** Build a `MulticonductorCase` from an ingest payload and make it active.
296
- * Geographic cases place immediately; planar/synthetic cases enter placement
297
- * (a map click or "place on map") so the user picks their center. */
339
+ /** Retain parsed electrical inputs and draw each declared coordinate space directly. */
298
340
  private addMultiCase;
341
+ /** Compute terminal quantities only for the retained input and current case revision. */
342
+ solveMultiCase: (c: MulticonductorCase, options?: McPfOptions, signal?: AbortSignal) => Promise<McPfSummary>;
343
+ /** Materialize the current retained operating point only when a portable
344
+ * snapshot is actually needed (save/export/geography). */
345
+ snapshotMultiCase: (c: MulticonductorCase) => Promise<McStudySnapshot>;
346
+ /** One bus's terminals and a page of equipment ports for the displayed
347
+ * operating point, from the live session or the stored full result. Null
348
+ * when the operating point changed before the page arrived. */
349
+ multiResultDetail: (c: MulticonductorCase, query: McPfDetailQuery) => Promise<McPfDetail | null>;
350
+ /** Every terminal's identity, voltage, and injected current, as numeric
351
+ * arrays of interleaved `[re, im]` values. */
352
+ multiTerminalTable: (c: MulticonductorCase) => Promise<{
353
+ ids: Array<[string, string]>;
354
+ voltages: Float64Array;
355
+ currents: Float64Array;
356
+ } | null>;
357
+ /** Apply coordinates atomically to the explicitly selected conductor-resolved case. */
358
+ applyMultiGeoLayers: (c: MulticonductorCase, layers: GeoLayerFile[]) => Promise<void>;
359
+ /** Stage an absolute load-branch P/Q edit and coalesce rapid UI changes into
360
+ * one retained-factor warm solve. */
361
+ queueMultiLoadPower: (c: MulticonductorCase, load: string, branch: number, p_w: number, q_var: number) => void;
362
+ private flushMultiLoadPowers;
299
363
  /** Make a multiconductor case active, framing it when it is placed. */
300
364
  activateMulti: (c: MulticonductorCase) => void;
301
365
  /** Select a bus in a multiconductor case: its terminal stack and incident
@@ -313,21 +377,38 @@ export declare class Controller {
313
377
  /** The unified map click-to-place: a pending multiconductor case takes the
314
378
  * click first, otherwise a pending local case does. */
315
379
  placeCase: (lon: number, lat: number) => void;
316
- /** Build a local case from a bare balanced ingest payload without activating
380
+ projectStudyInput(input: string, layer?: string): Promise<Network>;
381
+ caseGeographyLayers(c: LocalCase): Promise<string[]>;
382
+ /** Capture a matching cached result without constructing or solving a model. */
383
+ captureSavedCase(c: SolvableCase): Promise<SavedCaseCapture>;
384
+ /** Build a local case from a balanced PowerIO ingest payload without activating
317
385
  * it yet; co-dropped placement data is applied before the first solve. */
318
386
  private localFromBalancedPayload;
319
- /** Build a local case from a saved package, including its edit state and
320
- * formulation, without activating it until sidecars have been applied. */
321
- private localFromPackage;
387
+ /** Ingest module text through the engine and require a balanced network. */
388
+ private ingestBalancedModule;
389
+ /** Open a balanced powerio module from memory, the programmatic twin of
390
+ * dropping a `.pio.json` file: ingest (unless `payload` is given), apply an
391
+ * optional geographic layer, lay out a module without coordinates as a
392
+ * diagram, then add and activate it. Resolves to the new case; throws when
393
+ * the module is not a balanced network or the geographic layer matches
394
+ * nothing. */
395
+ openBalancedModule: (input: OpenBalancedModuleInput) => Promise<LocalCase>;
396
+ /** Swap a local case for a new module in place: same slot in the case list,
397
+ * same formulation unless `input.formulation` says otherwise, same display
398
+ * mode when the new case supports it, and the selected bus kept when the
399
+ * new case has it. The previous case's Study is freed. */
400
+ replaceLocalCase: (previous: LocalCase, input: OpenBalancedModuleInput) => Promise<LocalCase>;
322
401
  /** Build (or reuse) the case's Study and commit it at the current edit state, so a
323
402
  * save or export captures exactly what is on screen. Null (with an error set) when no
324
- * network or Study is available. */
325
- private syncedStudy;
326
- /** Save the active study as a `.pio.json` package and download it. */
327
- saveStudyPackage: (c: SolvableCase) => Promise<void>;
328
- /** Export the active study's committed state to `format` and download it. Returns the
329
- * writer's fidelity warnings so the caller can surface them. */
330
- exportStudyAs: (c: SolvableCase, format: string) => Promise<string[]>;
403
+ * PowerIO module or Study is available. */
404
+ syncedStudy: (c: SolvableCase) => Promise<BrowserStudy | null>;
405
+ /** Save the materialized case as a retained PowerIO module. */
406
+ saveCaseModule: (c: SolvableCase) => Promise<void>;
407
+ /** Save the exact DC OPF result with the materialized problem instance it solved. */
408
+ saveSolutionModule: (c: SolvableCase) => Promise<void>;
409
+ /** Export the active study's committed state to `format` and download it.
410
+ * Returns this output operation's structured diagnostics. */
411
+ exportCaseAs: (c: SolvableCase, format: string) => Promise<PowerIoDiagnostic[]>;
331
412
  /** A filesystem-safe base name for a downloaded case file. */
332
413
  private caseFileStem;
333
414
  setDemandRangeMode: (mode: DemandRangeMode) => void;