@vehicle-sil/gui-client 0.5.0 → 0.6.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.
package/dist/elements.js CHANGED
@@ -88,12 +88,26 @@ async function quietly(operation) {
88
88
  } catch {
89
89
  }
90
90
  }
91
- var QUIET = /* @__PURE__ */ new Set(["not-running", "offline"]);
91
+ var QUIET = /* @__PURE__ */ new Set([
92
+ "not-running",
93
+ "offline",
94
+ "connecting",
95
+ "already-running",
96
+ "paused",
97
+ "not-paused",
98
+ "not-stopping",
99
+ "already-stopping",
100
+ "starting"
101
+ ]);
102
+ function isQuietReason(code) {
103
+ return QUIET.has(code);
104
+ }
92
105
  var Part = class extends HTMLElement {
93
106
  static observedAttributes = [];
94
107
  #stops = [];
95
108
  #client = null;
96
109
  #bindings = 0;
110
+ #bindScheduled = false;
97
111
  #root = null;
98
112
  #sentence = null;
99
113
  /** Another connection than the page's (`connect()`). Setting it while the part is in the document binds it again. */
@@ -101,9 +115,10 @@ var Part = class extends HTMLElement {
101
115
  return this.#client;
102
116
  }
103
117
  set client(value) {
104
- if (value === this.#client) return;
105
- this.#client = value;
106
- if (this.isConnected) void this.#bind();
118
+ const next = value ?? null;
119
+ if (next === this.#client) return;
120
+ this.#client = next;
121
+ if (this.isConnected) this.#scheduleBind();
107
122
  }
108
123
  constructor() {
109
124
  super();
@@ -113,11 +128,23 @@ var Part = class extends HTMLElement {
113
128
  * A property that the page set before this class was defined sits on the object itself and hides the accessor:
114
129
  * take it off and set it again.
115
130
  */
116
- upgrade(name) {
117
- if (!Object.hasOwn(this, name)) return;
118
- const value = Reflect.get(this, name);
119
- Reflect.deleteProperty(this, name);
120
- Reflect.set(this, name, value);
131
+ upgrade(...names) {
132
+ for (const name of names) {
133
+ if (!Object.hasOwn(this, name)) continue;
134
+ const value = Reflect.get(this, name);
135
+ Reflect.deleteProperty(this, name);
136
+ Reflect.set(this, name, value);
137
+ }
138
+ }
139
+ /** Reflects a string attribute; `null` or `undefined` removes it while empty string is kept. */
140
+ reflectString(name, value) {
141
+ if (value === null || value === void 0) this.removeAttribute(name);
142
+ else this.setAttribute(name, String(value));
143
+ }
144
+ /** Reflects a non-empty string attribute; `null`, `undefined` or `""` removes it. */
145
+ reflectNonEmpty(name, value) {
146
+ if (value === null || value === void 0 || value === "") this.removeAttribute(name);
147
+ else this.setAttribute(name, String(value));
121
148
  }
122
149
  /** Stops `stop` when the part is unbound. */
123
150
  own(stop) {
@@ -128,14 +155,26 @@ var Part = class extends HTMLElement {
128
155
  return this.getAttribute(name) ?? fallback;
129
156
  }
130
157
  connectedCallback() {
131
- void this.#bind();
158
+ this.#scheduleBind();
132
159
  }
133
160
  disconnectedCallback() {
134
161
  this.#bindings++;
162
+ this.#bindScheduled = false;
135
163
  this.#clear();
136
164
  }
137
165
  attributeChangedCallback(_name, before, after) {
138
- if (before !== after && this.isConnected) void this.#bind();
166
+ if (before !== after && this.isConnected) this.#scheduleBind();
167
+ }
168
+ #scheduleBind() {
169
+ if (this.#bindScheduled || !this.isConnected) return;
170
+ this.#bindScheduled = true;
171
+ const generation = this.#bindings;
172
+ queueMicrotask(() => {
173
+ if (this.#bindings !== generation) return;
174
+ this.#bindScheduled = false;
175
+ if (!this.isConnected) return;
176
+ void this.#bind();
177
+ });
139
178
  }
140
179
  /** Shows the sentence of the failed connection (`speaking`) or not; the mark `data-error` stays either way. */
141
180
  #speak = (speaking) => {
@@ -173,7 +212,7 @@ var Part = class extends HTMLElement {
173
212
  async #bind() {
174
213
  this.#clear();
175
214
  const binding = ++this.#bindings;
176
- const alive = () => binding === this.#bindings && this.isConnected;
215
+ const alive = () => binding === this.#bindings && !this.#bindScheduled && this.isConnected;
177
216
  let shared = false;
178
217
  try {
179
218
  let client = this.#client;
@@ -193,8 +232,9 @@ var Part = class extends HTMLElement {
193
232
  /**
194
233
  * Binds `element` to one control of `client.controls`: `aria-disabled` (the caller ignores input while it is true),
195
234
  * `data-reason` and `data-caution` (the codes), and a sentence in an element that describes it (`aria-describedby`;
196
- * returned, to be put next to `element`). A reason that only says there is nothing to do (`not-running`, `offline`)
197
- * is in that element too, but hidden: a screen reader reads it, the page does not show it seven times.
235
+ * returned, to be put next to `element`). Empty descriptions and self-evident `QUIET` reasons (`not-running`,
236
+ * `offline`, `connecting`, `already-running`, `paused`, `not-paused`, `not-stopping`, `already-stopping`, `starting`)
237
+ * stay hidden visually while remaining accessible to screen readers.
198
238
  */
199
239
  describe(client, control, element) {
200
240
  const why = h("small", { id: `vsil-why-${++ids}`, class: "vsil-why" });
@@ -206,8 +246,9 @@ var Part = class extends HTMLElement {
206
246
  setData(element, "reason", reason?.code ?? null);
207
247
  setData(element, "caution", caution?.code ?? null);
208
248
  const shown = reason ?? caution;
209
- why.textContent = shown ? reasonText(shown) : "";
210
- why.hidden = shown !== null && QUIET.has(shown.code);
249
+ const text = shown ? reasonText(shown) : "";
250
+ why.textContent = text;
251
+ why.hidden = text === "" || shown !== null && QUIET.has(shown.code);
211
252
  })
212
253
  );
213
254
  return why;
@@ -263,6 +304,22 @@ function targetText(target2) {
263
304
  }
264
305
  var VsilConnectElement = class extends Part {
265
306
  static observedAttributes = ["network", "file"];
307
+ get network() {
308
+ return this.getAttribute("network") ?? "";
309
+ }
310
+ set network(value) {
311
+ this.reflectNonEmpty("network", value);
312
+ }
313
+ get file() {
314
+ return this.getAttribute("file") ?? "";
315
+ }
316
+ set file(value) {
317
+ this.reflectNonEmpty("file", value);
318
+ }
319
+ constructor() {
320
+ super();
321
+ this.upgrade("network", "file");
322
+ }
266
323
  draw(client, root, alive) {
267
324
  const network = this.getAttribute("network");
268
325
  if (!network) {
@@ -513,12 +570,30 @@ var VsilRunControlsElement = class extends Part {
513
570
  return this.#intent;
514
571
  }
515
572
  set intent(value) {
516
- this.#intent = value;
573
+ this.#intent = value ?? null;
517
574
  }
518
575
  #intent = null;
576
+ get labelStart() {
577
+ return this.getAttribute("label-start") ?? "";
578
+ }
579
+ set labelStart(value) {
580
+ this.reflectString("label-start", value);
581
+ }
582
+ get labelStop() {
583
+ return this.getAttribute("label-stop") ?? "";
584
+ }
585
+ set labelStop(value) {
586
+ this.reflectString("label-stop", value);
587
+ }
588
+ get labelForceStop() {
589
+ return this.getAttribute("label-force-stop") ?? "";
590
+ }
591
+ set labelForceStop(value) {
592
+ this.reflectString("label-force-stop", value);
593
+ }
519
594
  constructor() {
520
595
  super();
521
- this.upgrade("intent");
596
+ this.upgrade("intent", "labelStart", "labelStop", "labelForceStop");
522
597
  }
523
598
  draw(client, root) {
524
599
  const force = h(
@@ -568,6 +643,47 @@ var VsilTimeControlsElement = class extends Part {
568
643
  "label-step",
569
644
  "label-run-until"
570
645
  ];
646
+ get speeds() {
647
+ return this.getAttribute("speeds") ?? "";
648
+ }
649
+ set speeds(value) {
650
+ this.reflectNonEmpty("speeds", value);
651
+ }
652
+ get stepMs() {
653
+ return this.getAttribute("step-ms") ?? "";
654
+ }
655
+ set stepMs(value) {
656
+ if (value === null || value === void 0 || value === "") this.removeAttribute("step-ms");
657
+ else this.setAttribute("step-ms", String(value));
658
+ }
659
+ get labelPause() {
660
+ return this.getAttribute("label-pause") ?? "";
661
+ }
662
+ set labelPause(value) {
663
+ this.reflectString("label-pause", value);
664
+ }
665
+ get labelResume() {
666
+ return this.getAttribute("label-resume") ?? "";
667
+ }
668
+ set labelResume(value) {
669
+ this.reflectString("label-resume", value);
670
+ }
671
+ get labelStep() {
672
+ return this.getAttribute("label-step") ?? "";
673
+ }
674
+ set labelStep(value) {
675
+ this.reflectString("label-step", value);
676
+ }
677
+ get labelRunUntil() {
678
+ return this.getAttribute("label-run-until") ?? "";
679
+ }
680
+ set labelRunUntil(value) {
681
+ this.reflectString("label-run-until", value);
682
+ }
683
+ constructor() {
684
+ super();
685
+ this.upgrade("speeds", "stepMs", "labelPause", "labelResume", "labelStep", "labelRunUntil");
686
+ }
571
687
  draw(client, root) {
572
688
  const stepMs = h("input", { type: "number", min: "1", value: this.text("step-ms", "10") });
573
689
  const untilMs = h("input", { type: "number", min: "0", value: "1000" });
@@ -642,11 +758,17 @@ var VsilTimeControlsElement = class extends Part {
642
758
 
643
759
  // ../client/src/elements/scenario-parts.ts
644
760
  import { watch as watch4 } from "./index.js";
761
+ function formatParamValue(value) {
762
+ return typeof value === "string" ? value : String(value);
763
+ }
645
764
  var VsilScenarioSelectElement = class extends Part {
646
765
  draw(client, root, alive) {
647
766
  const select = h("select", {}, new Option("(no scenario)", ""));
648
767
  root.append(select);
649
- select.addEventListener("change", () => pageIntent.update({ scenario: select.value }));
768
+ select.addEventListener(
769
+ "change",
770
+ () => pageIntent.update({ scenario: select.value, case: "" })
771
+ );
650
772
  this.own(pageIntent.subscribe((intent2) => select.value = intent2.scenario ?? ""));
651
773
  let file;
652
774
  this.own(
@@ -662,7 +784,7 @@ var VsilScenarioSelectElement = class extends Part {
662
784
  for (const scenario of scenarios) select.add(new Option(scenario.name, scenario.path));
663
785
  select.value = pageIntent.get().scenario ?? "";
664
786
  if (select.value !== (pageIntent.get().scenario ?? ""))
665
- pageIntent.update({ scenario: "" });
787
+ pageIntent.update({ scenario: "", case: "" });
666
788
  },
667
789
  () => void 0
668
790
  // no list: the select keeps what it has
@@ -671,28 +793,150 @@ var VsilScenarioSelectElement = class extends Part {
671
793
  );
672
794
  }
673
795
  };
796
+ var VsilCaseSelectElement = class extends Part {
797
+ draw(client, root, alive) {
798
+ const select = h("select", { disabled: "" }, new Option("(no cases)", ""));
799
+ root.append(select);
800
+ setData(this, "cases", "none");
801
+ select.addEventListener("change", () => pageIntent.update({ case: select.value }));
802
+ let key = null;
803
+ let controller = null;
804
+ const abort = () => {
805
+ controller?.abort();
806
+ controller = null;
807
+ };
808
+ const resetDom = () => {
809
+ select.replaceChildren(new Option("(no cases)", ""));
810
+ select.disabled = true;
811
+ setData(this, "cases", "none");
812
+ };
813
+ const clear = () => {
814
+ resetDom();
815
+ if (pageIntent.get().case) pageIntent.update({ case: "" });
816
+ };
817
+ const refresh = () => {
818
+ const file = client.status.get().file;
819
+ const intent2 = pageIntent.get();
820
+ const scenario = intent2.scenario ?? "";
821
+ const variant = intent2.variant ?? "";
822
+ const nextKey = `${file ?? ""}\0${scenario}\0${variant}`;
823
+ if (nextKey === key) {
824
+ const wanted = intent2.case ?? "";
825
+ if ([...select.options].some((o) => o.value === wanted && !o.disabled)) {
826
+ select.value = wanted;
827
+ }
828
+ return;
829
+ }
830
+ key = nextKey;
831
+ abort();
832
+ if (!file || !scenario) {
833
+ clear();
834
+ return;
835
+ }
836
+ resetDom();
837
+ const nextController = new AbortController();
838
+ controller = nextController;
839
+ const checkIntent = variant ? { scenario, variant } : { scenario };
840
+ client.check(checkIntent, { file, signal: nextController.signal }).then(
841
+ (checked) => {
842
+ if (!alive() || key !== nextKey || nextController.signal.aborted) return;
843
+ const cases = checked.scenario?.cases ?? [];
844
+ if (cases.length === 0) {
845
+ clear();
846
+ return;
847
+ }
848
+ const details = new Map(
849
+ (checked.scenario?.case_details ?? []).map((detail) => [detail.name, detail])
850
+ );
851
+ const activeVariant = variant || (checked.variant ?? "");
852
+ select.replaceChildren(new Option("(choose a case)", ""));
853
+ for (const name of cases) {
854
+ const option = new Option(name, name);
855
+ const only = details.get(name)?.only ?? null;
856
+ if (activeVariant && only && !only.includes(activeVariant)) {
857
+ option.disabled = true;
858
+ option.title = `Only for variants: ${only.join(", ")}`;
859
+ }
860
+ select.add(option);
861
+ }
862
+ select.disabled = false;
863
+ setData(this, "cases", "available");
864
+ const wanted = pageIntent.get().case ?? "";
865
+ const valid = [...select.options].some((o) => o.value === wanted && !o.disabled);
866
+ select.value = valid ? wanted : "";
867
+ if (!valid && wanted !== "") pageIntent.update({ case: "" });
868
+ },
869
+ () => {
870
+ if (!alive() || key !== nextKey || nextController.signal.aborted) return;
871
+ clear();
872
+ key = null;
873
+ }
874
+ );
875
+ };
876
+ this.own(pageIntent.subscribe(refresh));
877
+ this.own(watch4(client.status, refresh));
878
+ this.own(() => {
879
+ abort();
880
+ setData(this, "cases", null);
881
+ });
882
+ }
883
+ };
674
884
  var VsilScenarioResultElement = class extends Part {
675
885
  draw(client, root) {
676
886
  const result = h("output");
887
+ const meta = h("div", { class: "vsil-scenario-meta" });
888
+ meta.hidden = true;
677
889
  const steps = h("ol");
678
- root.append(result, steps);
890
+ root.append(result, meta, steps);
679
891
  this.own(
680
892
  watch4(client.scenario, (scenario) => {
681
893
  result.textContent = scenario?.status ?? "-";
682
894
  setData(this, "status", scenario?.status ?? null);
895
+ setData(this, "case", scenario?.case ?? null);
896
+ const metaNodes = [];
897
+ if (scenario?.case) {
898
+ metaNodes.push(h("span", { "data-part": "case" }, `case: ${scenario.case}`));
899
+ }
900
+ if (scenario?.params && scenario.params.length > 0) {
901
+ const text = scenario.params.map((param) => `${param.name}=${formatParamValue(param.value)}`).join(", ");
902
+ metaNodes.push(h("span", { "data-part": "params" }, `params: ${text}`));
903
+ }
904
+ meta.replaceChildren(...metaNodes);
905
+ meta.hidden = metaNodes.length === 0;
683
906
  steps.replaceChildren(
684
907
  ...(scenario?.steps ?? []).map((step) => {
685
- const item = h(
686
- "li",
687
- {},
688
- `${step.text} \u2014 ${step.status}${step.at_ms !== null ? ` at ${step.at_ms} ms` : ""}${step.message ? `: ${step.message}` : ""}`
689
- );
908
+ const label = `${step.name ? `${step.name}: ` : ""}${step.text} \u2014 ${step.status}${step.at_ms !== null ? ` at ${step.at_ms} ms` : ""}${step.message ? `: ${step.message}` : ""}`;
909
+ const item = h("li", {}, label);
910
+ if (step.status === "failed") {
911
+ const hasLine = typeof step.line === "number" && step.line > 0;
912
+ if (step.file || hasLine) {
913
+ const src = step.file ?? scenario?.file ?? "";
914
+ const loc = hasLine ? src ? `${src}:${step.line}` : `line ${step.line}` : src;
915
+ item.append(h("small", { "data-part": "source" }, ` (${loc})`));
916
+ }
917
+ if (step.call_stack && step.call_stack.length > 0) {
918
+ item.append(
919
+ h(
920
+ "ul",
921
+ { "data-part": "call-stack" },
922
+ ...step.call_stack.map((frame) => {
923
+ const where = frame.file && frame.line !== null ? `${frame.file}:${frame.line}` : frame.file ?? (frame.line !== null ? `line ${frame.line}` : "");
924
+ const namePart = frame.name ? where ? ` (${frame.name})` : frame.name : "";
925
+ const entries = Object.entries(frame.params);
926
+ const paramPart = entries.length > 0 ? ` [${entries.map(([k, v]) => `${k}=${formatParamValue(v)}`).join(", ")}]` : "";
927
+ return h("li", {}, `${where}${namePart}${paramPart}`);
928
+ })
929
+ )
930
+ );
931
+ }
932
+ }
690
933
  setData(item, "status", step.status);
691
934
  return item;
692
935
  })
693
936
  );
694
937
  })
695
938
  );
939
+ this.own(() => setData(this, "case", null));
696
940
  }
697
941
  };
698
942
  var VsilTimelineElement = class extends Part {
@@ -718,18 +962,57 @@ var VsilTimelineElement = class extends Part {
718
962
  };
719
963
 
720
964
  // ../client/src/elements/variable-parts.ts
721
- import { watch as watch5 } from "./index.js";
965
+ import { ActionError, DROPPED_MESSAGE, watch as watch5 } from "./index.js";
722
966
  var noteIds = 0;
723
967
  var writeNote = (v) => {
724
968
  if (v.problem) return reasonText(v.problem);
725
969
  if (!v.can_write && v.why) return reasonText(v.why);
726
970
  return v.writing ? "writing\u2026" : "";
727
971
  };
972
+ function parseFallbackRef(raw) {
973
+ const dot = raw.indexOf(".");
974
+ return dot > 0 ? { peer: raw.slice(0, dot), name: raw.slice(dot + 1) } : { peer: raw, name: raw };
975
+ }
976
+ function toActionError(error) {
977
+ if (error instanceof ActionError) return error;
978
+ const message = error instanceof Error ? error.message : String(error);
979
+ const obj = error !== null && typeof error === "object" ? error : null;
980
+ const code = obj ? Reflect.get(obj, "code") : void 0;
981
+ const kind = obj ? Reflect.get(obj, "kind") : void 0;
982
+ const outcome = obj ? Reflect.get(obj, "outcome") : void 0;
983
+ const resolvedCode = typeof code === "string" && code !== "" ? code : typeof kind === "string" && kind !== "" ? kind : "error";
984
+ const resolvedOutcome = outcome === "unknown" || kind === "no-answer" || kind === "closed" ? "unknown" : "refused";
985
+ return new ActionError(resolvedCode, message, resolvedOutcome);
986
+ }
987
+ function writeStatusKind(status) {
988
+ if (typeof status === "string") return status;
989
+ if (status && typeof status === "object" && typeof status.kind === "string") return status.kind;
990
+ return "idle";
991
+ }
992
+ function conditionKindOf(condition) {
993
+ if (typeof condition === "string") return condition;
994
+ if (condition && typeof condition === "object" && typeof condition.kind === "string")
995
+ return condition.kind;
996
+ return "live";
997
+ }
998
+ var RUN_BOUNDARY_STATES = /* @__PURE__ */ new Set(["none", "starting", "ended", "crashed"]);
999
+ var RUN_BOUNDARY_CONDITIONS = /* @__PURE__ */ new Set(["unavailable", "missing", "waiting", "ended"]);
1000
+ var RUN_BOUNDARY_REASONS = /* @__PURE__ */ new Set(["ended", "not-ready", "not-running"]);
728
1001
  var VariablePart = class extends Part {
729
1002
  static observedAttributes = ["variable"];
730
- /** Whether the part writes (so that it says why it cannot). */
1003
+ /** Whether the part writes (so that it says why it cannot and tracks `data-write-status`). */
731
1004
  writes = false;
732
- draw(client, root) {
1005
+ get variable() {
1006
+ return this.getAttribute("variable") ?? "";
1007
+ }
1008
+ set variable(value) {
1009
+ this.reflectNonEmpty("variable", value);
1010
+ }
1011
+ constructor() {
1012
+ super();
1013
+ this.upgrade("variable");
1014
+ }
1015
+ draw(client, root, alive) {
733
1016
  const name = this.getAttribute("variable");
734
1017
  if (!name) {
735
1018
  throw new Error(
@@ -738,23 +1021,198 @@ var VariablePart = class extends Part {
738
1021
  }
739
1022
  const variable = client.variable(name);
740
1023
  const note = h("small", { id: `vsil-note-${++noteIds}`, class: "vsil-note" });
741
- const show = this.build(variable, root, note);
1024
+ let lastView = null;
1025
+ let nextToken = 0;
1026
+ let shownToken = 0;
1027
+ let shownStatus = "idle";
1028
+ let queuedCount = 0;
1029
+ const syncWriteStatus = () => {
1030
+ if (!this.writes || !alive()) return;
1031
+ let status;
1032
+ if (shownToken > 0) {
1033
+ status = shownStatus;
1034
+ } else {
1035
+ const viewKind = lastView ? writeStatusKind(lastView.write_status) : "idle";
1036
+ if (viewKind !== "idle") status = viewKind;
1037
+ else if (lastView?.writing) status = "sending";
1038
+ else if (lastView?.problem) status = "failed";
1039
+ else status = "idle";
1040
+ }
1041
+ setData(this, "writeStatus", status);
1042
+ };
1043
+ const resetLocalStatus = () => {
1044
+ shownToken = 0;
1045
+ shownStatus = "idle";
1046
+ queuedCount = 0;
1047
+ syncWriteStatus();
1048
+ };
1049
+ const show = this.build({
1050
+ variable,
1051
+ root,
1052
+ note,
1053
+ alive,
1054
+ fallbackRef: parseFallbackRef(name),
1055
+ trackLifecycle: {
1056
+ enqueueStarted: () => {
1057
+ const token = ++nextToken;
1058
+ shownToken = token;
1059
+ shownStatus = "sending";
1060
+ syncWriteStatus();
1061
+ return token;
1062
+ },
1063
+ enqueueQueued: (token) => {
1064
+ queuedCount++;
1065
+ if (token === shownToken) shownStatus = "queued";
1066
+ syncWriteStatus();
1067
+ },
1068
+ enqueueFailed: (token) => {
1069
+ if (token === shownToken) shownStatus = "failed";
1070
+ syncWriteStatus();
1071
+ },
1072
+ appliedSucceeded: (token) => {
1073
+ queuedCount = Math.max(0, queuedCount - 1);
1074
+ if (token === shownToken) shownStatus = "applied";
1075
+ syncWriteStatus();
1076
+ },
1077
+ appliedFailed: (token) => {
1078
+ queuedCount = Math.max(0, queuedCount - 1);
1079
+ if (token === shownToken) shownStatus = "failed";
1080
+ syncWriteStatus();
1081
+ },
1082
+ dropped: () => {
1083
+ shownToken = ++nextToken;
1084
+ shownStatus = "failed";
1085
+ syncWriteStatus();
1086
+ },
1087
+ hasQueued: () => queuedCount > 0
1088
+ }
1089
+ });
742
1090
  root.append(" ", note);
1091
+ this.own(() => {
1092
+ setData(this, "stale", null);
1093
+ setData(this, "canWrite", null);
1094
+ setData(this, "availability", null);
1095
+ setData(this, "reason", null);
1096
+ setData(this, "writeStatus", null);
1097
+ });
1098
+ if (this.writes && client.status) {
1099
+ let prevRun = null;
1100
+ let prevFile;
1101
+ this.own(
1102
+ watch5(client.status, (s) => {
1103
+ if (prevRun !== null) {
1104
+ const runChanged = s.run !== prevRun && (RUN_BOUNDARY_STATES.has(s.run) || RUN_BOUNDARY_STATES.has(prevRun));
1105
+ const fileChanged = s.file !== prevFile;
1106
+ if (runChanged || fileChanged) resetLocalStatus();
1107
+ }
1108
+ prevRun = s.run;
1109
+ prevFile = s.file;
1110
+ })
1111
+ );
1112
+ }
1113
+ let prevConditionKind = null;
1114
+ let prevWhyCode = null;
1115
+ let prevCanWrite = null;
1116
+ let prevHasProblem = false;
743
1117
  this.own(
744
1118
  watch5(variable, (v) => {
1119
+ const condKind = conditionKindOf(v.condition);
1120
+ const whyCode = v.why?.code ?? null;
1121
+ if (this.writes && lastView !== null) {
1122
+ const enteredBoundary = condKind !== prevConditionKind && RUN_BOUNDARY_CONDITIONS.has(condKind);
1123
+ const leftBoundary = prevConditionKind !== null && RUN_BOUNDARY_CONDITIONS.has(prevConditionKind) && !RUN_BOUNDARY_CONDITIONS.has(condKind);
1124
+ const reopenedFromEnded = prevCanWrite === false && v.can_write && prevWhyCode !== null && RUN_BOUNDARY_REASONS.has(prevWhyCode);
1125
+ const problemClearedExternally = prevHasProblem && v.problem === null && shownStatus === "failed";
1126
+ if (enteredBoundary || leftBoundary || reopenedFromEnded || problemClearedExternally) {
1127
+ shownToken = 0;
1128
+ shownStatus = "idle";
1129
+ if (enteredBoundary || leftBoundary || reopenedFromEnded) queuedCount = 0;
1130
+ }
1131
+ }
1132
+ lastView = v;
1133
+ prevConditionKind = condKind;
1134
+ prevWhyCode = whyCode;
1135
+ prevCanWrite = v.can_write;
1136
+ prevHasProblem = v.problem !== null;
745
1137
  setData(this, "stale", String(v.stale));
746
1138
  setData(this, "canWrite", String(v.can_write));
747
1139
  setData(this, "availability", v.availability);
748
- if (this.writes) note.textContent = writeNote(v);
749
- note.hidden = false;
1140
+ if (this.writes) {
1141
+ const text = writeNote(v);
1142
+ note.textContent = text;
1143
+ setData(this, "reason", !v.can_write && v.why ? v.why.code : null);
1144
+ note.hidden = text === "" || !v.problem && !v.can_write && v.why !== null && isQuietReason(v.why.code);
1145
+ syncWriteStatus();
1146
+ }
750
1147
  show(v);
751
1148
  })
752
1149
  );
753
1150
  }
754
1151
  };
1152
+ var WritingVariablePart = class extends VariablePart {
1153
+ writes = true;
1154
+ addEventListener(type, listener, options) {
1155
+ super.addEventListener(type, listener, options);
1156
+ }
1157
+ removeEventListener(type, listener, options) {
1158
+ super.removeEventListener(type, listener, options);
1159
+ }
1160
+ /** Dispatches a bubbling, composed write lifecycle event only while this binding is still alive and connected. */
1161
+ emitWriteEvent(type, detail, alive) {
1162
+ if (!alive() || !this.isConnected) return;
1163
+ this.dispatchEvent(new CustomEvent(type, { detail, bubbles: true, composed: true }));
1164
+ }
1165
+ /** Awaits stage 3+4 (`queued.applied()`) and emits `vsil-write-result` without ever leaking unhandled rejections. */
1166
+ async awaitApplied(queued, token, ctx, onSettled) {
1167
+ try {
1168
+ const result = await queued.applied();
1169
+ if (!ctx.alive()) return;
1170
+ ctx.trackLifecycle.appliedSucceeded(token);
1171
+ onSettled?.();
1172
+ const detail = { ok: true, ...result };
1173
+ this.emitWriteEvent("vsil-write-result", detail, ctx.alive);
1174
+ } catch (error) {
1175
+ if (!ctx.alive()) return;
1176
+ ctx.trackLifecycle.appliedFailed(token);
1177
+ onSettled?.();
1178
+ const detail = {
1179
+ ok: false,
1180
+ peer: queued.peer,
1181
+ name: queued.name,
1182
+ value: queued.value,
1183
+ error: toActionError(error),
1184
+ seq: queued.seq
1185
+ };
1186
+ this.emitWriteEvent("vsil-write-result", detail, ctx.alive);
1187
+ }
1188
+ }
1189
+ };
755
1190
  var VsilValueElement = class extends VariablePart {
756
1191
  static observedAttributes = ["variable", "on", "off", "no-unit"];
757
- build(_variable, root, note) {
1192
+ get on() {
1193
+ return this.getAttribute("on") ?? "";
1194
+ }
1195
+ set on(value) {
1196
+ this.reflectString("on", value);
1197
+ }
1198
+ get off() {
1199
+ return this.getAttribute("off") ?? "";
1200
+ }
1201
+ set off(value) {
1202
+ this.reflectString("off", value);
1203
+ }
1204
+ get noUnit() {
1205
+ const raw = this.getAttribute("no-unit");
1206
+ return raw !== null && raw.toLowerCase() !== "false";
1207
+ }
1208
+ set noUnit(value) {
1209
+ this.toggleAttribute("no-unit", Boolean(value));
1210
+ }
1211
+ constructor() {
1212
+ super();
1213
+ this.upgrade("on", "off", "noUnit");
1214
+ }
1215
+ build({ root, note }) {
758
1216
  const output = root.appendChild(h("output"));
759
1217
  return (v) => {
760
1218
  if (typeof v.value === "boolean") {
@@ -762,27 +1220,124 @@ var VsilValueElement = class extends VariablePart {
762
1220
  output.textContent = v.value ? this.text("on", "on") : this.text("off", "off");
763
1221
  } else {
764
1222
  setData(this, "on", null);
765
- const unit = this.hasAttribute("no-unit") || !v.unit ? "" : ` ${v.unit}`;
1223
+ const unit = this.noUnit || !v.unit ? "" : ` ${v.unit}`;
766
1224
  output.textContent = v.value === null ? "-" : `${v.text}${unit}`;
767
1225
  }
768
- note.textContent = v.note ?? "";
1226
+ const text = v.note ?? "";
1227
+ note.textContent = text;
1228
+ note.hidden = text === "";
769
1229
  };
770
1230
  }
771
1231
  };
772
- var VsilSliderElement = class extends VariablePart {
773
- writes = true;
774
- build(variable, root, note) {
1232
+ var VsilSliderElement = class extends WritingVariablePart {
1233
+ build(ctx) {
1234
+ const { variable, root, note, alive, fallbackRef, trackLifecycle } = ctx;
775
1235
  const input = h("input", { type: "range", "aria-describedby": note.id });
776
1236
  const output = h("output", { "aria-hidden": "true" });
777
1237
  note.setAttribute("aria-hidden", "true");
778
1238
  let dragging = false;
1239
+ let sending = false;
1240
+ let pending = null;
1241
+ const syncKnob = (v) => {
1242
+ const busy = v.writing || sending || pending !== null || trackLifecycle.hasQueued();
1243
+ if (!dragging && !busy && typeof v.value === "number") input.value = String(v.value);
1244
+ if (v.value === null || dragging || busy) input.removeAttribute("aria-valuetext");
1245
+ else input.setAttribute("aria-valuetext", output.textContent ?? "");
1246
+ };
1247
+ const send = (value) => {
1248
+ if (!alive()) return;
1249
+ sending = true;
1250
+ const token = trackLifecycle.enqueueStarted();
1251
+ void (async () => {
1252
+ let queued;
1253
+ try {
1254
+ queued = await variable.enqueue(value);
1255
+ } catch (error) {
1256
+ sending = false;
1257
+ pending = null;
1258
+ if (!alive()) return;
1259
+ trackLifecycle.enqueueFailed(token);
1260
+ syncKnob(variable.get());
1261
+ this.emitWriteEvent(
1262
+ "vsil-write-result",
1263
+ {
1264
+ ok: false,
1265
+ peer: fallbackRef.peer,
1266
+ name: fallbackRef.name,
1267
+ value,
1268
+ error: toActionError(error)
1269
+ },
1270
+ alive
1271
+ );
1272
+ return;
1273
+ }
1274
+ if (!alive()) {
1275
+ sending = false;
1276
+ pending = null;
1277
+ return;
1278
+ }
1279
+ trackLifecycle.enqueueQueued(token);
1280
+ const info = {
1281
+ session: queued.session,
1282
+ seq: queued.seq,
1283
+ peer: queued.peer,
1284
+ name: queued.name,
1285
+ value: queued.value
1286
+ };
1287
+ this.emitWriteEvent("vsil-write-queued", info, alive);
1288
+ if (!alive()) {
1289
+ sending = false;
1290
+ pending = null;
1291
+ return;
1292
+ }
1293
+ void this.awaitApplied(queued, token, ctx, () => syncKnob(variable.get()));
1294
+ sending = false;
1295
+ const next = pending;
1296
+ pending = null;
1297
+ if (next !== null) {
1298
+ const current = variable.get();
1299
+ const currentRanged = current.min !== null && current.max !== null;
1300
+ if (!input.disabled && current.can_write && currentRanged) {
1301
+ send(next.value);
1302
+ } else {
1303
+ trackLifecycle.dropped();
1304
+ syncKnob(current);
1305
+ const why = current.why;
1306
+ this.emitWriteEvent(
1307
+ "vsil-write-result",
1308
+ {
1309
+ ok: false,
1310
+ peer: fallbackRef.peer,
1311
+ name: fallbackRef.name,
1312
+ value: next.value,
1313
+ error: new ActionError(
1314
+ why?.code ?? "dropped",
1315
+ why?.message ?? DROPPED_MESSAGE,
1316
+ "refused"
1317
+ )
1318
+ },
1319
+ alive
1320
+ );
1321
+ }
1322
+ } else {
1323
+ syncKnob(variable.get());
1324
+ }
1325
+ })();
1326
+ };
779
1327
  input.addEventListener("input", () => {
780
1328
  dragging = true;
781
1329
  input.removeAttribute("aria-valuetext");
782
1330
  });
783
1331
  input.addEventListener("change", () => {
784
1332
  dragging = false;
785
- void quietly(() => variable.write(Number(input.value)));
1333
+ if (!alive() || input.disabled || !variable.get().can_write) return;
1334
+ const nextValue = Number(input.value);
1335
+ if (!Number.isFinite(nextValue)) return;
1336
+ if (sending) {
1337
+ pending = { value: nextValue };
1338
+ return;
1339
+ }
1340
+ send(nextValue);
786
1341
  });
787
1342
  for (const name of ["pointerup", "pointercancel", "keyup", "blur"])
788
1343
  input.addEventListener(name, () => dragging = false);
@@ -797,11 +1352,11 @@ var VsilSliderElement = class extends VariablePart {
797
1352
  input.step = v.step === null ? "any" : String(v.step);
798
1353
  } else if (v.can_write && !v.problem) {
799
1354
  note.textContent = "this variable has no range to set";
1355
+ note.hidden = false;
1356
+ setData(this, "reason", "no-range");
800
1357
  }
801
- if (!dragging && !v.writing && typeof v.value === "number") input.value = String(v.value);
802
1358
  output.textContent = v.value === null ? "-" : `${v.text}${v.unit ? ` ${v.unit}` : ""}`;
803
- if (v.value === null || dragging || v.writing) input.removeAttribute("aria-valuetext");
804
- else input.setAttribute("aria-valuetext", output.textContent);
1359
+ syncKnob(v);
805
1360
  };
806
1361
  }
807
1362
  };
@@ -814,10 +1369,28 @@ var target = (text) => {
814
1369
  }
815
1370
  return text;
816
1371
  };
817
- var VsilWriteElement = class extends VariablePart {
1372
+ var VsilWriteElement = class extends WritingVariablePart {
818
1373
  static observedAttributes = ["variable", "value", "label"];
819
- writes = true;
820
- build(variable, root, note) {
1374
+ get value() {
1375
+ const raw = this.getAttribute("value");
1376
+ return raw === null ? null : target(raw);
1377
+ }
1378
+ set value(value) {
1379
+ if (value === null || value === void 0) this.removeAttribute("value");
1380
+ else this.setAttribute("value", String(value));
1381
+ }
1382
+ get label() {
1383
+ return this.getAttribute("label") ?? "";
1384
+ }
1385
+ set label(value) {
1386
+ this.reflectString("label", value);
1387
+ }
1388
+ constructor() {
1389
+ super();
1390
+ this.upgrade("value", "label");
1391
+ }
1392
+ build(ctx) {
1393
+ const { variable, root, note, alive, fallbackRef, trackLifecycle } = ctx;
821
1394
  const value = target(this.getAttribute("value"));
822
1395
  const button = h(
823
1396
  "button",
@@ -825,8 +1398,41 @@ var VsilWriteElement = class extends VariablePart {
825
1398
  this.text("label", `${this.getAttribute("variable")} = ${String(value)}`)
826
1399
  );
827
1400
  button.addEventListener("click", () => {
828
- if (button.getAttribute("aria-disabled") !== "true")
829
- void quietly(() => variable.write(value));
1401
+ if (button.getAttribute("aria-disabled") === "true" || !alive()) return;
1402
+ const token = trackLifecycle.enqueueStarted();
1403
+ void (async () => {
1404
+ let queued;
1405
+ try {
1406
+ queued = await variable.enqueue(value);
1407
+ } catch (error) {
1408
+ if (!alive()) return;
1409
+ trackLifecycle.enqueueFailed(token);
1410
+ this.emitWriteEvent(
1411
+ "vsil-write-result",
1412
+ {
1413
+ ok: false,
1414
+ peer: fallbackRef.peer,
1415
+ name: fallbackRef.name,
1416
+ value,
1417
+ error: toActionError(error)
1418
+ },
1419
+ alive
1420
+ );
1421
+ return;
1422
+ }
1423
+ if (!alive()) return;
1424
+ trackLifecycle.enqueueQueued(token);
1425
+ const info = {
1426
+ session: queued.session,
1427
+ seq: queued.seq,
1428
+ peer: queued.peer,
1429
+ name: queued.name,
1430
+ value: queued.value
1431
+ };
1432
+ this.emitWriteEvent("vsil-write-queued", info, alive);
1433
+ if (!alive()) return;
1434
+ await this.awaitApplied(queued, token, ctx);
1435
+ })();
830
1436
  });
831
1437
  root.append(button);
832
1438
  return (v) => {
@@ -835,6 +1441,7 @@ var VsilWriteElement = class extends VariablePart {
835
1441
  if (already && !v.problem) {
836
1442
  note.textContent = `already ${String(value)}`;
837
1443
  note.hidden = true;
1444
+ setData(this, "reason", "already");
838
1445
  }
839
1446
  };
840
1447
  }
@@ -849,6 +1456,7 @@ var PARTS = [
849
1456
  ["vsil-slider", VsilSliderElement],
850
1457
  ["vsil-write", VsilWriteElement],
851
1458
  ["vsil-scenario-select", VsilScenarioSelectElement],
1459
+ ["vsil-case-select", VsilCaseSelectElement],
852
1460
  ["vsil-scenario-result", VsilScenarioResultElement],
853
1461
  ["vsil-timeline", VsilTimelineElement],
854
1462
  ["vsil-connect", VsilConnectElement],
@@ -856,6 +1464,7 @@ var PARTS = [
856
1464
  ];
857
1465
  for (const [name, part] of PARTS) if (!customElements.get(name)) customElements.define(name, part);
858
1466
  export {
1467
+ VsilCaseSelectElement,
859
1468
  VsilConnectElement,
860
1469
  VsilOutsideElement,
861
1470
  VsilRunControlsElement,