@yuneta/gobj-ui 7.26.50 → 7.26.52

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.
@@ -1295,6 +1295,8 @@ var PRIVATE_DATA$22 = {
1295
1295
  expected_pop_ids: [],
1296
1296
  given_up: null,
1297
1297
  own_entries: [],
1298
+ traverse_from: -1,
1299
+ entry_change_handler: null,
1298
1300
  popstate_handler: null,
1299
1301
  avatar_provider: null,
1300
1302
  avatar_nodes: [],
@@ -1370,7 +1372,13 @@ function mt_start$21(gobj) {
1370
1372
  let p = gobj.priv;
1371
1373
  if (!p) return;
1372
1374
  note_late_landing(gobj, ev);
1375
+ let from = p.traverse_from;
1376
+ p.traverse_from = -1;
1373
1377
  let hash_moved = window.location.hash !== p.last_hash;
1378
+ if (p.expected_pops === 0 && from >= 0 && retire_dead_entries(gobj, from, hash_moved)) {
1379
+ if (!p.skip_hash) p.last_hash = window.location.hash;
1380
+ return;
1381
+ }
1374
1382
  if (p.expected_pops > 0 && window.location.hash !== p.expected_pop_hash) {
1375
1383
  drop_expected_pops(gobj);
1376
1384
  on_traversal(ev);
@@ -1421,6 +1429,15 @@ function mt_start$21(gobj) {
1421
1429
  }
1422
1430
  };
1423
1431
  window.addEventListener("popstate", priv.popstate_handler);
1432
+ let nav = window.navigation;
1433
+ if (nav && typeof nav.addEventListener === "function") {
1434
+ priv.entry_change_handler = (ev) => {
1435
+ let p = gobj.priv;
1436
+ if (!p) return;
1437
+ p.traverse_from = ev && ev.navigationType === "traverse" && ev.from && typeof ev.from.index === "number" ? ev.from.index : -1;
1438
+ };
1439
+ nav.addEventListener("currententrychange", priv.entry_change_handler);
1440
+ }
1424
1441
  keep_dead_entries_across_reload();
1425
1442
  adopt_orphan_back(gobj);
1426
1443
  }
@@ -1463,6 +1480,12 @@ function mt_stop$20(gobj) {
1463
1480
  window.removeEventListener("popstate", priv.popstate_handler);
1464
1481
  priv.popstate_handler = null;
1465
1482
  }
1483
+ if (priv.entry_change_handler) {
1484
+ let nav = window.navigation;
1485
+ if (nav && typeof nav.removeEventListener === "function") nav.removeEventListener("currententrychange", priv.entry_change_handler);
1486
+ priv.entry_change_handler = null;
1487
+ }
1488
+ priv.traverse_from = -1;
1466
1489
  for (let entry of priv.pending_markers) {
1467
1490
  entry.marker_pending = false;
1468
1491
  entry.no_marker = true;
@@ -2860,7 +2883,9 @@ function retire_overlays(gobj) {
2860
2883
  *
2861
2884
  * A page with no next shell keeps them: with no router on the
2862
2885
  * page, a Back over the app's own entries changes nothing on
2863
- * screen anyway, and the next shell retires them all the same.
2886
+ * screen anyway, and the next shell retires them all the same --
2887
+ * at its start, or when a traversal of the reader's lands on them
2888
+ * if the reader moved meanwhile.
2864
2889
  ************************************************************/
2865
2890
  function hand_over_history(gobj) {
2866
2891
  let priv = gobj.priv;
@@ -2980,6 +3005,7 @@ function note_own_entry(gobj) {
2980
3005
  let priv = gobj.priv;
2981
3006
  let key = current_entry_key();
2982
3007
  if (!key || priv.own_entries.includes(key)) return;
3008
+ __dead_entries__.delete(key);
2983
3009
  priv.own_entries.push(key);
2984
3010
  if (priv.own_entries.length > OWN_ENTRIES_PRUNE_AT) {
2985
3011
  let alive = new Set(window.navigation.entries().map((e) => e.key));
@@ -2990,42 +3016,70 @@ function note_own_entry(gobj) {
2990
3016
  * Take off, with ONE history.go(-n), the dead entries a
2991
3017
  * stopped shell left under the current one (hand_over_history).
2992
3018
  * The walk stops at the first entry that is not dead, so it
2993
- * never goes past an entry of the reader's. The traversal is
2994
- * this shell's own (expected_pops): its overlays' markers and
2995
- * the routes it pushes wait for the landing, and a position
2996
- * the URL holds is put back on the entry it lands on, as for
2997
- * any back() of ours (restore_hash). Returns true when it
2998
- * went.
2999
- ************************************************************/
3000
- function retire_dead_entries(gobj) {
3001
- let priv = gobj.priv;
3019
+ * never goes past an entry of the reader's, and at the first
3020
+ * entry of the current document: a navigation to another page
3021
+ * with replace keeps the entry's key, so a later document can
3022
+ * sit on the key of a dead marker, over the entries of the one
3023
+ * before it (up to gobj-ui 7.26.50 the walk went into them and
3024
+ * that document was loaded again). After a reload every entry
3025
+ * is the new document's, and its dead ones go.
3026
+ *
3027
+ * With `from` (the index a traversal of the reader's came
3028
+ * from), it goes on over the dead entries that traversal landed
3029
+ * on, the way it was going: down to the first live one under
3030
+ * them, or up to the first live one over them -- there is none
3031
+ * when they are the newest, and nothing moves. Dead entries
3032
+ * under an entry of the reader's are taken off that way: the
3033
+ * start of a shell never goes past one.
3034
+ *
3035
+ * The traversal is this shell's own (expected_pops): its
3036
+ * overlays' markers and the routes it pushes wait for the
3037
+ * landing. At the start, a position the URL holds is put back
3038
+ * on the entry it lands on, as for any back() of ours
3039
+ * (restore_hash). The keys stay dead while their entries
3040
+ * exist: a later Back or Forward onto them goes over them too.
3041
+ * Returns true when it went.
3042
+ ************************************************************/
3043
+ function retire_dead_entries(gobj, from, hash_moved) {
3044
+ let priv = gobj.priv;
3045
+ let reader = typeof from === "number";
3002
3046
  if (__dead_entries__.size === 0 || priv.expected_pops > 0 || !priv.popstate_handler || !current_entry_key()) return false;
3003
3047
  let nav = window.navigation;
3004
3048
  let entries = nav.entries();
3005
3049
  let index = nav.currentEntry.index;
3006
3050
  let alive = new Set(entries.map((e) => e.key));
3007
3051
  for (let key of __dead_entries__) if (!alive.has(key)) __dead_entries__.delete(key);
3052
+ if (reader && (from === index || !__dead_entries__.has(entries[index].key))) return false;
3053
+ let step = reader && from < index ? 1 : -1;
3008
3054
  let landing = index;
3009
- while (landing > 0 && __dead_entries__.has(entries[landing].key)) landing--;
3010
- let steps = index - landing;
3055
+ while (__dead_entries__.has(entries[landing].key)) {
3056
+ let next = landing + step;
3057
+ if (next < 0 || next >= entries.length || !entries[next].sameDocument) break;
3058
+ landing = next;
3059
+ }
3060
+ if (step > 0 && __dead_entries__.has(entries[landing].key)) return false;
3061
+ let steps = landing - index;
3011
3062
  if (steps === 0) return false;
3012
3063
  let landing_hash = "";
3013
3064
  try {
3014
3065
  landing_hash = new URL(entries[landing].url).hash;
3015
3066
  } catch (e) {
3016
- (0, _yuneta_gobj_js.log_warning)(`C_YUI_SHELL: the entry under the dead ones has no url: ${e}`);
3067
+ (0, _yuneta_gobj_js.log_warning)(`C_YUI_SHELL: the entry past the dead ones has no url: ${e}`);
3017
3068
  return false;
3018
3069
  }
3019
- for (let i = landing + 1; i <= index; i++) __dead_entries__.delete(entries[i].key);
3020
3070
  priv.expected_pops++;
3021
3071
  priv.expected_pop_hash = landing_hash;
3022
- priv.restore_hash = window.location.hash !== landing_hash ? window.location.hash : "";
3072
+ if (reader) {
3073
+ priv.restore_hash = "";
3074
+ if (hash_moved && window.location.hash !== landing_hash) priv.skip_hash = window.location.hash;
3075
+ } else priv.restore_hash = window.location.hash !== landing_hash ? window.location.hash : "";
3023
3076
  try {
3024
- window.history.go(-steps);
3077
+ window.history.go(steps);
3025
3078
  } catch (e) {
3026
3079
  priv.expected_pops--;
3027
3080
  priv.restore_hash = "";
3028
- (0, _yuneta_gobj_js.log_warning)(`C_YUI_SHELL: retiring ${steps} dead history entries failed: ${e}`);
3081
+ priv.skip_hash = "";
3082
+ (0, _yuneta_gobj_js.log_warning)(`C_YUI_SHELL: going over ${Math.abs(steps)} dead history entries failed: ${e}`);
3029
3083
  return false;
3030
3084
  }
3031
3085
  clear_deferred_timer(gobj);
@@ -3133,6 +3187,8 @@ function push_overlay_marker(gobj, entry) {
3133
3187
  if (below === null || plain) try {
3134
3188
  window.history.replaceState(Object.assign({}, below, { __yui_below__: entry.id }), "");
3135
3189
  stamped = true;
3190
+ let key = current_entry_key();
3191
+ if (key) __dead_entries__.delete(key);
3136
3192
  } catch (e) {
3137
3193
  (0, _yuneta_gobj_js.log_warning)(`C_YUI_SHELL: stamping the entry under an overlay failed: ${e}`);
3138
3194
  }
@@ -6801,7 +6857,7 @@ function ac_shell_changed(gobj, event, kw, src) {
6801
6857
  * language the window was opened in (a reader took the
6802
6858
  * aria-labelledby, which changed; the tooltip did not).
6803
6859
  ************************************************************/
6804
- function ac_language_changed$11(gobj, event, kw, src) {
6860
+ function ac_language_changed$12(gobj, event, kw, src) {
6805
6861
  let priv = gobj.priv;
6806
6862
  for (let entry of priv.windows) {
6807
6863
  if (!entry.title_prefix || !entry.$chip) continue;
@@ -6872,7 +6928,7 @@ function create_gclass$20(gclass_name) {
6872
6928
  ],
6873
6929
  [
6874
6930
  "EV_LANGUAGE_CHANGED",
6875
- ac_language_changed$11,
6931
+ ac_language_changed$12,
6876
6932
  null
6877
6933
  ]
6878
6934
  ]]], gmt$20, 0, attrs_table$20, PRIVATE_DATA$20, 0, 0, 0, 0);
@@ -9625,220 +9681,842 @@ function yui_icons_list() {
9625
9681
  });
9626
9682
  return list;
9627
9683
  }
9628
- /************************************************************
9629
- * JSON type discriminator (viewer vocabulary)
9630
- ************************************************************/
9631
- function json_type(value) {
9632
- if (value === null) return "null";
9633
- if (Array.isArray(value)) return "array";
9634
- switch (typeof value) {
9635
- case "string": return "string";
9636
- case "number": return "number";
9637
- case "boolean": return "boolean";
9638
- case "object": return "object";
9639
- default: return "unknown";
9640
- }
9641
- }
9642
- /************************************************************
9643
- * Detect a kw_collapse() sentinel.
9684
+ //#endregion
9685
+ //#region src/yui_time.js
9686
+ /***********************************************************************
9687
+ * yui_time.js
9644
9688
  *
9645
- * The kernel replaces an over-limit dict with:
9646
- * { "__collapsed__": { "path": ..., "size": N } }
9647
- * and an over-limit array with:
9648
- * [ { "__collapsed__": { "path": ..., "size": N } } ]
9689
+ * Time, without a DOM: epochs, and the algebra of PERIODS.
9649
9690
  *
9650
- * Returns { size, path, is_array } or null.
9651
- ************************************************************/
9652
- function is_collapsed(value) {
9653
- if (value && typeof value === "object" && !Array.isArray(value)) {
9654
- let keys = Object.keys(value);
9655
- if (keys.length === 1 && keys[0] === "__collapsed__") {
9656
- let c = value.__collapsed__ || {};
9657
- return {
9658
- size: c.size,
9659
- path: c.path,
9660
- is_array: false
9661
- };
9662
- }
9663
- return null;
9691
+ * Two things live here, and they are the two halves of every date
9692
+ * UI the projects keep rewriting:
9693
+ *
9694
+ * 1) EPOCH <-> the local wall clock. A timestamp travels in the
9695
+ * producer's own unit — seconds, or milliseconds when a topic
9696
+ * says so — and every conversion crosses that `ms` flag. Getting
9697
+ * it wrong puts the same instant on two different clocks in one
9698
+ * screen (it did: a picker asking "from 18:55" local returned
9699
+ * rows a table labelled 16:55).
9700
+ *
9701
+ * 2) The PERIOD. A period is not an enum of five names: it is a
9702
+ * BUCKET, and a bucket is `count` of a `unit`:
9703
+ *
9704
+ * {id: "day", unit: "day", count: 1}
9705
+ * {id: "week", unit: "week", count: 1} ISO, Mon-first
9706
+ * {id: "bimester", unit: "month", count: 2}
9707
+ * {id: "quarter", unit: "month", count: 3}
9708
+ * {id: "semester", unit: "month", count: 6}
9709
+ * {id: "decade", unit: "year", count: 10}
9710
+ * {id: "15min", unit: "minute", count: 15}
9711
+ *
9712
+ * Given that pair, ONE implementation answers every question a
9713
+ * date navigator asks — where does the bucket holding this
9714
+ * instant start and end, what is the previous/next one, what do
9715
+ * I call it — so an app that wants quarters declares a quarter
9716
+ * instead of asking for a new component.
9717
+ *
9718
+ * Buckets are ALIGNED, never "count back from now": months align to
9719
+ * the year (which is why 2, 3, 4, 6 and 12 fall on clean calendar
9720
+ * boundaries), weeks to Monday, hours to local midnight. "Last 7
9721
+ * days" is a different animal — a rolling window — and it is not a
9722
+ * period: see `rolling_bounds()`.
9723
+ *
9724
+ * Everything here is LOCAL time (the user reads a local clock) and
9725
+ * DST-safe: it never adds 86400000 ms to cross a day, it builds the
9726
+ * next date from calendar fields and lets the platform do it.
9727
+ *
9728
+ * Copyright (c) 2026, ArtGins.
9729
+ * All Rights Reserved.
9730
+ ***********************************************************************/
9731
+ /***************************************************************
9732
+ * Constants
9733
+ ***************************************************************/
9734
+ var MS_DAY = 864e5;
9735
+ var PERIOD_UNITS = [
9736
+ "minute",
9737
+ "hour",
9738
+ "day",
9739
+ "week",
9740
+ "month",
9741
+ "year"
9742
+ ];
9743
+ var YUI_PERIODS = {
9744
+ minute: {
9745
+ id: "minute",
9746
+ unit: "minute",
9747
+ count: 1
9748
+ },
9749
+ "5min": {
9750
+ id: "5min",
9751
+ unit: "minute",
9752
+ count: 5
9753
+ },
9754
+ "15min": {
9755
+ id: "15min",
9756
+ unit: "minute",
9757
+ count: 15
9758
+ },
9759
+ hour: {
9760
+ id: "hour",
9761
+ unit: "hour",
9762
+ count: 1
9763
+ },
9764
+ day: {
9765
+ id: "day",
9766
+ unit: "day",
9767
+ count: 1
9768
+ },
9769
+ week: {
9770
+ id: "week",
9771
+ unit: "week",
9772
+ count: 1
9773
+ },
9774
+ fortnight: {
9775
+ id: "fortnight",
9776
+ unit: "week",
9777
+ count: 2
9778
+ },
9779
+ month: {
9780
+ id: "month",
9781
+ unit: "month",
9782
+ count: 1
9783
+ },
9784
+ bimester: {
9785
+ id: "bimester",
9786
+ unit: "month",
9787
+ count: 2
9788
+ },
9789
+ quarter: {
9790
+ id: "quarter",
9791
+ unit: "month",
9792
+ count: 3
9793
+ },
9794
+ semester: {
9795
+ id: "semester",
9796
+ unit: "month",
9797
+ count: 6
9798
+ },
9799
+ year: {
9800
+ id: "year",
9801
+ unit: "year",
9802
+ count: 1
9803
+ },
9804
+ decade: {
9805
+ id: "decade",
9806
+ unit: "year",
9807
+ count: 10
9664
9808
  }
9665
- if (Array.isArray(value) && value.length === 1) {
9666
- let e = value[0];
9667
- if (e && typeof e === "object" && !Array.isArray(e) && Object.keys(e).length === 1 && e.__collapsed__) {
9668
- let c = e.__collapsed__ || {};
9669
- return {
9670
- size: c.size,
9671
- path: c.path,
9672
- is_array: true
9673
- };
9674
- }
9809
+ };
9810
+ var YUI_PERIODS_DEFAULT = [
9811
+ "hour",
9812
+ "day",
9813
+ "week",
9814
+ "month",
9815
+ "year"
9816
+ ];
9817
+ var YUI_ROLLING = {
9818
+ "1h": {
9819
+ id: "1h",
9820
+ secs: 3600,
9821
+ label: "last hour"
9822
+ },
9823
+ "6h": {
9824
+ id: "6h",
9825
+ secs: 21600,
9826
+ label: "last 6h"
9827
+ },
9828
+ "24h": {
9829
+ id: "24h",
9830
+ secs: 86400,
9831
+ label: "last 24h"
9832
+ },
9833
+ "7d": {
9834
+ id: "7d",
9835
+ secs: 604800,
9836
+ label: "last 7 days"
9837
+ },
9838
+ "30d": {
9839
+ id: "30d",
9840
+ secs: 2592e3,
9841
+ label: "last 30 days"
9675
9842
  }
9676
- return null;
9677
- }
9678
- /************************************************************
9679
- * Join / split absolute path segments (kernel convention)
9680
- ************************************************************/
9681
- function seg_join(segments) {
9682
- return segments.map(function(s) {
9683
- return String(s);
9684
- }).join("`");
9843
+ };
9844
+ /***************************
9845
+ * Locale / i18n
9846
+ ***************************/
9847
+ /***************************************************************
9848
+ * The locale to format with.
9849
+ *
9850
+ * NEVER at module top level, and never `navigator.language` raw:
9851
+ * Firefox can report the literal STRING "undefined", and every Intl
9852
+ * constructor throws RangeError on it — a module that built its
9853
+ * formatter on import took the whole bundle down with it (that is why
9854
+ * gui_agent refuses to import the gobj-ui barrel).
9855
+ ***************************************************************/
9856
+ function safe_locale(locale) {
9857
+ if (typeof locale === "string" && locale && locale !== "undefined") return locale;
9858
+ let nav = typeof navigator !== "undefined" ? navigator.language : null;
9859
+ if (typeof nav === "string" && nav && nav !== "undefined") return nav;
9860
+ return "en";
9685
9861
  }
9686
- function seg_split(path) {
9687
- if (path === "" || path === null || path === void 0) return [];
9688
- return path.split("`");
9862
+ /***************************************************************
9863
+ * Translate through the APP's translator when it gave us one, and
9864
+ * degrade to the key itself otherwise — interpolating `{{x}}` by hand,
9865
+ * so a label never renders raw mustaches at a caller that has no i18n.
9866
+ ***************************************************************/
9867
+ function tr(t, key, params) {
9868
+ if (typeof t === "function") return t(key, params);
9869
+ let s = key;
9870
+ for (let k in params || {}) s = s.replaceAll(`{{${k}}}`, String(params[k]));
9871
+ return s;
9689
9872
  }
9690
- /************************************************************
9691
- * Walk a JSON tree by absolute segments; undefined if the
9692
- * path does not resolve.
9693
- ************************************************************/
9694
- function get_by_segments(root, segments) {
9695
- let v = root;
9696
- for (let seg of segments) {
9697
- if (v === null || v === void 0) return;
9698
- if (Array.isArray(v)) v = v[Number(seg)];
9699
- else if (typeof v === "object") v = v[seg];
9700
- else return;
9873
+ /***************************************************************
9874
+ * Intl formatters, built PER CALL (see safe_locale). They are cheap
9875
+ * next to a repaint, and caching them would need a locale-change hook
9876
+ * the library has no business owning.
9877
+ ***************************************************************/
9878
+ function fmt_intl(date, locale, opts) {
9879
+ try {
9880
+ return new Intl.DateTimeFormat(safe_locale(locale), opts).format(date);
9881
+ } catch (e) {
9882
+ return date.toDateString();
9701
9883
  }
9702
- return v;
9703
9884
  }
9704
- /************************************************************
9705
- * Set a value at absolute segments (mutates root).
9706
- *
9707
- * segments == [] means "replace the whole root" — the caller
9708
- * must use the RETURNED value in that case (a primitive/array
9709
- * root cannot be mutated in place).
9710
- ************************************************************/
9711
- function set_by_segments(root, segments, new_value) {
9712
- if (segments.length === 0) return new_value;
9713
- let parent = get_by_segments(root, segments.slice(0, -1));
9714
- if (parent === null || parent === void 0 || typeof parent !== "object") return root;
9715
- let last = segments[segments.length - 1];
9716
- if (Array.isArray(parent)) parent[Number(last)] = new_value;
9717
- else parent[last] = new_value;
9718
- return root;
9885
+ /***************************
9886
+ * Epoch <-> clock
9887
+ ***************************/
9888
+ /***************************************************************
9889
+ * Epoch in the producer's unit -> milliseconds, and back.
9890
+ * `ms` true means the value already IS milliseconds.
9891
+ ***************************************************************/
9892
+ function epoch_to_ms(value, ms) {
9893
+ if (!value) return 0;
9894
+ return ms ? value : value * 1e3;
9719
9895
  }
9720
- /************************************************************
9721
- * Does `value` (or any loaded descendant / its own key)
9722
- * contain the lower-cased search term?
9723
- *
9724
- * Collapsed (not-yet-loaded) subtrees can't be searched, so
9725
- * they never match on content — only their key can match,
9726
- * which the renderer checks separately.
9727
- ************************************************************/
9728
- function subtree_matches(value, term) {
9729
- if (!term) return true;
9730
- if (is_collapsed(value)) return false;
9731
- let type = json_type(value);
9732
- if (type === "object") {
9733
- for (let [k, v] of Object.entries(value)) {
9734
- if (String(k).toLowerCase().includes(term)) return true;
9735
- if (subtree_matches(v, term)) return true;
9736
- }
9737
- return false;
9738
- }
9739
- if (type === "array") {
9740
- for (let v of value) if (subtree_matches(v, term)) return true;
9741
- return false;
9896
+ function ms_to_epoch(value_ms, ms) {
9897
+ if (!value_ms) return 0;
9898
+ return ms ? value_ms : Math.floor(value_ms / 1e3);
9899
+ }
9900
+ /***************************************************************
9901
+ * The LOCAL wall-clock string an `<input type="datetime-local">` takes
9902
+ * ("YYYY-MM-DDTHH:MM:SS", which needs step=1 to keep the seconds), and
9903
+ * the parse back. Empty / unparseable -> 0, which is exactly how a
9904
+ * match condition reads an absent bound.
9905
+ ***************************************************************/
9906
+ function epoch_to_local_input(value, ms) {
9907
+ if (!value) return "";
9908
+ let d = new Date(epoch_to_ms(value, ms));
9909
+ let pad = (n) => String(n).padStart(2, "0");
9910
+ return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}T${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}`;
9911
+ }
9912
+ function local_input_to_epoch(v, ms) {
9913
+ if (!v) return 0;
9914
+ let parsed = Date.parse(v);
9915
+ if (Number.isNaN(parsed)) return 0;
9916
+ return ms_to_epoch(parsed, ms);
9917
+ }
9918
+ /***************************************************************
9919
+ * A timestamp for a table cell: the local wall clock, space-separated,
9920
+ * keeping the milliseconds when the producer bothered to send them (a
9921
+ * topic that sets sf_t_ms usually appends several records inside the
9922
+ * same second, and a column that hides that shows a column of ties).
9923
+ ***************************************************************/
9924
+ function fmt_epoch(value, ms) {
9925
+ if (!value) return "";
9926
+ try {
9927
+ let s = epoch_to_local_input(value, ms).replace("T", " ");
9928
+ if (ms) s += `.${String(value % 1e3).padStart(3, "0")}`;
9929
+ return s;
9930
+ } catch (e) {
9931
+ return String(value);
9742
9932
  }
9743
- return String(value).toLowerCase().includes(term);
9744
9933
  }
9745
- /************************************************************
9746
- * Fields whose numeric value is an epoch timestamp.
9934
+ var DATE_TIME_OPTIONS = {
9935
+ day: "numeric",
9936
+ month: "short",
9937
+ year: "numeric",
9938
+ hour: "2-digit",
9939
+ minute: "2-digit",
9940
+ second: "2-digit",
9941
+ hourCycle: "h23"
9942
+ };
9943
+ /***************************************************************
9944
+ * A moment as a VIEW shows it as text: the day, the month and the
9945
+ * year, then the clock of 24 hours with its seconds, in the APP's
9946
+ * language -- `locale` is the language t() answers in (the views
9947
+ * pass `i18next.language`), never the browser's:
9747
9948
  *
9748
- * THE ONE LIST. C_YUI_FORM's jsoneditor takes its
9749
- * `timestampTag` from here: it used to carry its own copy,
9750
- * and a copy is how the two stopped agreeing.
9949
+ * fmt_date_time(d, "es") -> "14 oct 2026, 15:05:09"
9950
+ * fmt_date_time(d, "en") -> "Oct 14, 2026, 15:05:09"
9751
9951
  *
9752
- * TWO SPELLINGS, AND LAS DOS SON DEL BACKEND. timeranger2
9753
- * writes `from_t`/`from_tm` in the match_cond of a query and
9754
- * `fr_t`/`fr_tm` in the metadata of a topic and of a file --
9755
- * which is what a Raw JSON of a treedb actually shows. With
9756
- * only the long pair listed, `to_t` got its date and the
9757
- * `fr_t` right above it did not, which reads as a broken
9758
- * annotator rather than a missing name.
9759
- ************************************************************/
9760
- var TIME_FIELDS = [
9761
- "__t__",
9762
- "__tm__",
9763
- "t",
9764
- "tm",
9765
- "time",
9766
- "from_t",
9767
- "to_t",
9768
- "from_tm",
9769
- "to_tm",
9770
- "fr_t",
9771
- "fr_tm",
9772
- "t_input",
9773
- "t_output"
9774
- ];
9775
- function is_time_field(field) {
9776
- return TIME_FIELDS.indexOf(field) >= 0;
9777
- }
9778
- /************************************************************
9779
- * Format an epoch value as a local wall-clock string.
9780
- * Accepts seconds or milliseconds; returns null when the
9781
- * value is not a usable positive timestamp (0 == "unset").
9782
- ************************************************************/
9783
- function format_epoch(value) {
9784
- if (typeof value !== "number" || !isFinite(value) || value <= 0) return null;
9785
- let ms = Math.abs(value) < 0xe8d4a51000 ? value * 1e3 : value;
9786
- let d = new Date(ms);
9787
- if (isNaN(d.getTime())) return null;
9788
- return d.toLocaleString();
9789
- }
9790
- /************************************************************
9791
- * The text view's payload: the document as text, indented
9792
- * four characters, cut at `max_chars`.
9952
+ * "" for anything that is not a valid Date. A locale Intl refuses
9953
+ * gives the language-free "2026-10-14 15:05:09".
9793
9954
  *
9794
- * Returns {text, capped}. `capped` is what the caller
9795
- * announces under the dump — a cut that is not announced
9796
- * reads as a document that ends there.
9797
- ************************************************************/
9798
- function json_text_dump(root, max_chars) {
9799
- let text;
9955
+ * The time cells of C_YUI_FORM and C_YUI_TREEDB_TOPIC_WITH_FORM and
9956
+ * the reading C_YUI_JSON writes beside a time field all come from
9957
+ * here, so the same moment reads the same in the three.
9958
+ ***************************************************************/
9959
+ function fmt_date_time(date, locale) {
9960
+ if (!(date instanceof Date) || isNaN(date.getTime())) return "";
9800
9961
  try {
9801
- text = JSON.stringify(root, null, 4);
9962
+ return new Intl.DateTimeFormat(safe_locale(locale), DATE_TIME_OPTIONS).format(date);
9802
9963
  } catch (e) {
9803
- return {
9804
- text: "",
9805
- capped: false,
9806
- error: String(e)
9807
- };
9964
+ return epoch_to_local_input(date.getTime(), true).replace("T", " ");
9808
9965
  }
9809
- if (text === void 0) return {
9810
- text: "",
9811
- capped: false,
9812
- error: "not representable as JSON"
9813
- };
9814
- if (typeof max_chars === "number" && max_chars > 0 && text.length > max_chars) return {
9815
- text: text.slice(0, max_chars),
9816
- capped: true
9966
+ }
9967
+ /***************************
9968
+ * Calendar atoms
9969
+ ***************************/
9970
+ /***************************************************************
9971
+ * The day number of a date, counting local calendar days from
9972
+ * 1970-01-01. Built from the FIELDS (Date.UTC of y/m/d), never from
9973
+ * the timestamp: a DST day is 23 or 25 hours long, so dividing a local
9974
+ * epoch by 86400000 drifts a day twice a year.
9975
+ ***************************************************************/
9976
+ function day_number(d) {
9977
+ return Math.floor(Date.UTC(d.getFullYear(), d.getMonth(), d.getDate()) / MS_DAY);
9978
+ }
9979
+ function date_from_day_number(n) {
9980
+ let d = /* @__PURE__ */ new Date(n * MS_DAY);
9981
+ return new Date(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate());
9982
+ }
9983
+ /***************************************************************
9984
+ * The Monday of the week a date falls in (ISO: the week starts on
9985
+ * Monday, and Sunday closes it).
9986
+ ***************************************************************/
9987
+ function start_of_iso_week(d) {
9988
+ let day = d.getDay();
9989
+ let back = day === 0 ? 6 : day - 1;
9990
+ return new Date(d.getFullYear(), d.getMonth(), d.getDate() - back);
9991
+ }
9992
+ /***************************************************************
9993
+ * The ISO week a date belongs to: {week, year}. The YEAR is the ISO
9994
+ * week-year, not the calendar year — 2026-12-31 lives in week 1 of
9995
+ * 2027, and a label that said "week 1 2026" would name a week six
9996
+ * months away.
9997
+ ***************************************************************/
9998
+ function iso_week(d) {
9999
+ let monday = start_of_iso_week(d);
10000
+ let thursday = new Date(monday.getFullYear(), monday.getMonth(), monday.getDate() + 3);
10001
+ let jan1 = new Date(thursday.getFullYear(), 0, 1);
10002
+ return {
10003
+ week: Math.floor((day_number(thursday) - day_number(jan1)) / 7) + 1,
10004
+ year: thursday.getFullYear()
9817
10005
  };
10006
+ }
10007
+ /***************************************************************
10008
+ * The index of the ISO week a date falls in, counting weeks from the
10009
+ * Monday of the epoch week. It is what aligns a MULTI-week bucket (a
10010
+ * fortnight) to a Monday instead of to whatever day 1970-01-01 was.
10011
+ ***************************************************************/
10012
+ function week_index(d) {
10013
+ return Math.floor((day_number(start_of_iso_week(d)) + 3) / 7);
10014
+ }
10015
+ /***************************
10016
+ * Period algebra
10017
+ ***************************/
10018
+ /***************************************************************
10019
+ * Normalize whatever a caller hands us into a spec: an id of the
10020
+ * catalog, or a spec of its own. Returns null for anything that is not
10021
+ * a bucket (a "span" / "custom" mode of a navigator has no algebra).
10022
+ ***************************************************************/
10023
+ function period_spec(period) {
10024
+ if (!period) return null;
10025
+ let spec = typeof period === "string" ? YUI_PERIODS[period] : period;
10026
+ if (!spec || !spec.unit) return null;
10027
+ if (PERIOD_UNITS.indexOf(spec.unit) < 0) return null;
10028
+ let count = parseInt(spec.count, 10);
10029
+ if (!(count > 0)) count = 1;
9818
10030
  return {
9819
- text,
9820
- capped: false
10031
+ id: spec.id || spec.unit,
10032
+ unit: spec.unit,
10033
+ count
9821
10034
  };
9822
10035
  }
9823
- /************************************************************
9824
- * Which view a freshly mounted viewer opens on.
9825
- *
9826
- * Three answers, in order of authority: what the HOST asked
9827
- * for, what the READER chose last time, and `fallback`.
10036
+ /***************************************************************
10037
+ * The START of the bucket that holds `anchor_ms`, as a local Date.
9828
10038
  *
9829
- * The host wins because a viewer mounted to show a graph has
9830
- * to show one. The memory comes next, because reopening a
9831
- * document in the view you just left is the whole point of
9832
- * remembering it. `fallback` is the floor.
10039
+ * Alignment is what makes a bucket a bucket. Each unit floors against
10040
+ * the natural origin of the unit above it, so the boundaries are the
10041
+ * ones a human already has in their head:
9833
10042
  *
9834
- * Anything not in `modes` is treated as unsaid, which covers
9835
- * an absent value, an empty one, and a stored string from an
9836
- * older release that named a view no longer offered.
9837
- ************************************************************/
9838
- function pick_view_mode(asked, remembered, modes, fallback) {
9839
- let known = (m) => Array.isArray(modes) && modes.indexOf(m) >= 0;
9840
- if (known(asked)) return asked;
9841
- if (known(remembered)) return remembered;
10043
+ * minute -> the hour (a 15min bucket starts at :00/:15/:30/:45)
10044
+ * hour -> local midnight (a 6h bucket starts at 00/06/12/18)
10045
+ * day -> 1970-01-01 (count=1 is the plain day; a 10-day
10046
+ * bucket has no calendar origin to
10047
+ * align to, so it aligns to the epoch)
10048
+ * week -> the epoch week, Monday-first (ISO)
10049
+ * month -> January (which is why 2/3/4/6/12 give calendar
10050
+ * bimesters, quarters and semesters)
10051
+ * year -> year 0 (a decade starts at 2020, not 2021)
10052
+ ***************************************************************/
10053
+ function period_start(period, anchor_ms) {
10054
+ let spec = period_spec(period);
10055
+ if (!spec) return null;
10056
+ let d = new Date(anchor_ms);
10057
+ let n = spec.count;
10058
+ switch (spec.unit) {
10059
+ case "minute": {
10060
+ let m = Math.floor(d.getMinutes() / n) * n;
10061
+ return new Date(d.getFullYear(), d.getMonth(), d.getDate(), d.getHours(), m);
10062
+ }
10063
+ case "hour": {
10064
+ let h = Math.floor(d.getHours() / n) * n;
10065
+ return new Date(d.getFullYear(), d.getMonth(), d.getDate(), h);
10066
+ }
10067
+ case "day": return date_from_day_number(Math.floor(day_number(d) / n) * n);
10068
+ case "week": return date_from_day_number(Math.floor(week_index(d) / n) * n * 7 - 3);
10069
+ case "month": {
10070
+ let mi = d.getFullYear() * 12 + d.getMonth();
10071
+ let s = Math.floor(mi / n) * n;
10072
+ return new Date(Math.floor(s / 12), s % 12, 1);
10073
+ }
10074
+ case "year": {
10075
+ let y = Math.floor(d.getFullYear() / n) * n;
10076
+ return new Date(y, 0, 1);
10077
+ }
10078
+ default: return null;
10079
+ }
10080
+ }
10081
+ /***************************************************************
10082
+ * The start of the bucket `delta` buckets away (delta may be negative).
10083
+ * Calendar arithmetic, never millisecond arithmetic: `new Date(y, m+3, 1)`
10084
+ * overflows the year by itself, and stepping a day across a DST change
10085
+ * keeps landing on midnight.
10086
+ ***************************************************************/
10087
+ function period_shift(period, anchor_ms, delta) {
10088
+ let spec = period_spec(period);
10089
+ if (!spec) return anchor_ms;
10090
+ let s = period_start(spec, anchor_ms);
10091
+ let step = spec.count * (delta || 0);
10092
+ switch (spec.unit) {
10093
+ case "minute": return new Date(s.getFullYear(), s.getMonth(), s.getDate(), s.getHours(), s.getMinutes() + step).getTime();
10094
+ case "hour": return new Date(s.getFullYear(), s.getMonth(), s.getDate(), s.getHours() + step).getTime();
10095
+ case "day": return new Date(s.getFullYear(), s.getMonth(), s.getDate() + step).getTime();
10096
+ case "week": return new Date(s.getFullYear(), s.getMonth(), s.getDate() + step * 7).getTime();
10097
+ case "month": return new Date(s.getFullYear(), s.getMonth() + step, 1).getTime();
10098
+ case "year": return new Date(s.getFullYear() + step, 0, 1).getTime();
10099
+ default: return anchor_ms;
10100
+ }
10101
+ }
10102
+ /***************************************************************
10103
+ * The bucket holding `anchor_ms`, as {from, to} in MILLISECONDS.
10104
+ *
10105
+ * `to` is INCLUSIVE — the last millisecond of the bucket, not the first
10106
+ * of the next one. Both ends of a match condition are inclusive, and an
10107
+ * exclusive end handed to one silently swallows the record that landed
10108
+ * exactly on the boundary.
10109
+ ***************************************************************/
10110
+ function period_bounds(period, anchor_ms) {
10111
+ let spec = period_spec(period);
10112
+ if (!spec) return {
10113
+ from: 0,
10114
+ to: 0
10115
+ };
10116
+ return {
10117
+ from: period_start(spec, anchor_ms).getTime(),
10118
+ to: period_shift(spec, anchor_ms, 1) - 1
10119
+ };
10120
+ }
10121
+ /***************************************************************
10122
+ * The same bucket, in the unit the CONSUMER speaks (a tranger topic
10123
+ * keeps its timestamps in seconds, unless its system_flag says
10124
+ * milliseconds). This is the function a query builder calls.
10125
+ ***************************************************************/
10126
+ function period_bounds_epoch(period, anchor_ms, ms) {
10127
+ let b = period_bounds(period, anchor_ms);
10128
+ if (!b.from) return {
10129
+ from: 0,
10130
+ to: 0
10131
+ };
10132
+ return {
10133
+ from: ms_to_epoch(b.from, ms),
10134
+ to: ms_to_epoch(b.to, ms)
10135
+ };
10136
+ }
10137
+ /***************************************************************
10138
+ * A ROLLING window: `secs` back from now. Not a bucket — it has no
10139
+ * previous and no next, it just ends at `now`.
10140
+ *
10141
+ * The `to` end is left OPEN (0). An iterator with no upper bound keeps
10142
+ * matching the records that land while the card is on screen; pinning
10143
+ * it to "now" would freeze the window at the instant the user clicked.
10144
+ ***************************************************************/
10145
+ function rolling_bounds(rolling, ms, now_ms) {
10146
+ let r = typeof rolling === "string" ? YUI_ROLLING[rolling] : rolling;
10147
+ if (!r || !r.secs) return {
10148
+ from: 0,
10149
+ to: 0
10150
+ };
10151
+ return {
10152
+ from: ms_to_epoch((now_ms === void 0 ? Date.now() : now_ms) - r.secs * 1e3, ms),
10153
+ to: 0
10154
+ };
10155
+ }
10156
+ /***************************************************************
10157
+ * Is this the LAST bucket — the one `now` falls in? It is what greys
10158
+ * out the "next" arrow, and what tells the navigator it is already home.
10159
+ ***************************************************************/
10160
+ function is_current_period(period, anchor_ms, now_ms) {
10161
+ let spec = period_spec(period);
10162
+ if (!spec) return false;
10163
+ let now = now_ms === void 0 ? Date.now() : now_ms;
10164
+ let a = period_start(spec, anchor_ms);
10165
+ let b = period_start(spec, now);
10166
+ return !!a && !!b && a.getTime() === b.getTime();
10167
+ }
10168
+ /***************************************************************
10169
+ * Recognize the bucket a {from, to} pair came from, so a range that
10170
+ * travelled through a URL, a saved view or a backend answer comes back
10171
+ * as the period the user picked instead of as a hand-typed range.
10172
+ *
10173
+ * `from`/`to` are in the CONSUMER's unit (`ms`), and so is the
10174
+ * comparison — that is the whole trap: a bucket ends on the last
10175
+ * MILLISECOND (…23:59:59.999), and a consumer that keeps seconds stored
10176
+ * it truncated (…23:59:59). Comparing in milliseconds, a week saved by a
10177
+ * seconds-based topic came back as "no bucket at all", every time.
10178
+ *
10179
+ * Only an EXACT match counts: both ends must land on the bucket's own
10180
+ * boundaries, as that consumer would have written them. `candidates` are
10181
+ * ids/specs, tried in order. Returns {period, anchor} (anchor in ms) or
10182
+ * null.
10183
+ ***************************************************************/
10184
+ function infer_period(from, to, candidates, ms) {
10185
+ if (!from || !to || to <= from) return null;
10186
+ let from_ms = epoch_to_ms(from, ms);
10187
+ for (let candidate of candidates || Object.keys(YUI_PERIODS)) {
10188
+ let spec = period_spec(candidate);
10189
+ if (!spec) continue;
10190
+ let b = period_bounds_epoch(spec, from_ms, ms);
10191
+ if (b.from === from && b.to === to) return {
10192
+ period: spec,
10193
+ anchor: from_ms
10194
+ };
10195
+ }
10196
+ return null;
10197
+ }
10198
+ /***************************
10199
+ * Period labels
10200
+ ***************************/
10201
+ /***************************************************************
10202
+ * The name of a GRANULARITY (what the segmented control shows):
10203
+ * the spec's own id as an i18n key, so an app that declares
10204
+ * {id: "quarter"} gets "Trimestre" the moment it adds the key.
10205
+ ***************************************************************/
10206
+ function period_name(period, t) {
10207
+ let spec = period_spec(period);
10208
+ if (!spec) return tr(t, String(period && period.id || period || ""));
10209
+ return tr(t, spec.id);
10210
+ }
10211
+ /***************************************************************
10212
+ * The name of the bucket a navigator is PARKED on: what goes between
10213
+ * the two arrows.
10214
+ *
10215
+ * day -> "Today" / "Yesterday" / "13 jul 2026"
10216
+ * week -> "Week 27" (+ year when it is not this one)
10217
+ * month -> "July" (+ year when it is not this one)
10218
+ * quarter -> "Q3 2026" (unit month, count 3)
10219
+ * semester -> "H2 2026" (unit month, count 6)
10220
+ * year -> "2026"
10221
+ * decade -> "2020 – 2029"
10222
+ * any other -> the bucket's own edges: "1 jul – 31 aug 2026"
10223
+ *
10224
+ * The named ones are named because a range reads worse than a name;
10225
+ * everything an app invents falls back to the range, which is always
10226
+ * true and never wrong.
10227
+ ***************************************************************/
10228
+ function period_label(period, anchor_ms, t, locale) {
10229
+ let spec = period_spec(period);
10230
+ if (!spec) return "";
10231
+ let loc = safe_locale(locale);
10232
+ let start = period_start(spec, anchor_ms);
10233
+ let end = new Date(period_bounds(spec, anchor_ms).to);
10234
+ let now = /* @__PURE__ */ new Date();
10235
+ let this_year = start.getFullYear() === now.getFullYear();
10236
+ if (spec.unit === "day" && spec.count === 1) {
10237
+ let diff = day_number(start) - day_number(now);
10238
+ if (diff === 0) return tr(t, "today");
10239
+ if (diff === -1) return tr(t, "yesterday");
10240
+ if (diff === 1) return tr(t, "tomorrow");
10241
+ return fmt_intl(start, loc, this_year ? {
10242
+ day: "numeric",
10243
+ month: "short"
10244
+ } : {
10245
+ day: "numeric",
10246
+ month: "short",
10247
+ year: "numeric"
10248
+ });
10249
+ }
10250
+ if (spec.unit === "hour" && spec.count === 1) {
10251
+ let hh = fmt_intl(start, loc, {
10252
+ hour: "2-digit",
10253
+ minute: "2-digit"
10254
+ });
10255
+ if (day_number(start) === day_number(now)) return hh;
10256
+ return `${hh} · ${fmt_intl(start, loc, {
10257
+ day: "numeric",
10258
+ month: "short"
10259
+ })}`;
10260
+ }
10261
+ if (spec.unit === "week" && spec.count === 1) {
10262
+ let away = week_index(start) - week_index(now);
10263
+ if (away === 0) return tr(t, "this week");
10264
+ if (away === -1) return tr(t, "last week");
10265
+ let w = iso_week(start);
10266
+ return w.year === now.getFullYear() ? tr(t, "week {{n}}", { n: w.week }) : tr(t, "week {{n}} {{y}}", {
10267
+ n: w.week,
10268
+ y: w.year
10269
+ });
10270
+ }
10271
+ if (spec.unit === "month" && spec.count === 1) return fmt_intl(start, loc, this_year ? { month: "long" } : {
10272
+ month: "long",
10273
+ year: "numeric"
10274
+ });
10275
+ if (spec.unit === "month" && (spec.count === 3 || spec.count === 6)) {
10276
+ let n = Math.floor(start.getMonth() / spec.count) + 1;
10277
+ return tr(t, spec.count === 3 ? "quarter {{n}} {{y}}" : "semester {{n}} {{y}}", {
10278
+ n,
10279
+ y: start.getFullYear()
10280
+ });
10281
+ }
10282
+ if (spec.unit === "year") {
10283
+ if (spec.count === 1) return String(start.getFullYear());
10284
+ return `${start.getFullYear()} – ${end.getFullYear()}`;
10285
+ }
10286
+ let opts = spec.unit === "minute" || spec.unit === "hour" ? {
10287
+ day: "numeric",
10288
+ month: "short",
10289
+ hour: "2-digit",
10290
+ minute: "2-digit"
10291
+ } : {
10292
+ day: "numeric",
10293
+ month: "short"
10294
+ };
10295
+ if (start.getFullYear() !== end.getFullYear()) {
10296
+ let y_opts = Object.assign({ year: "numeric" }, opts);
10297
+ return `${fmt_intl(start, loc, y_opts)} – ${fmt_intl(end, loc, y_opts)}`;
10298
+ }
10299
+ let span = `${fmt_intl(start, loc, opts)} – ${fmt_intl(end, loc, opts)}`;
10300
+ return this_year ? span : `${span} ${start.getFullYear()}`;
10301
+ }
10302
+ /************************************************************
10303
+ * JSON type discriminator (viewer vocabulary)
10304
+ ************************************************************/
10305
+ function json_type(value) {
10306
+ if (value === null) return "null";
10307
+ if (Array.isArray(value)) return "array";
10308
+ switch (typeof value) {
10309
+ case "string": return "string";
10310
+ case "number": return "number";
10311
+ case "boolean": return "boolean";
10312
+ case "object": return "object";
10313
+ default: return "unknown";
10314
+ }
10315
+ }
10316
+ /************************************************************
10317
+ * Detect a kw_collapse() sentinel.
10318
+ *
10319
+ * The kernel replaces an over-limit dict with:
10320
+ * { "__collapsed__": { "path": ..., "size": N } }
10321
+ * and an over-limit array with:
10322
+ * [ { "__collapsed__": { "path": ..., "size": N } } ]
10323
+ *
10324
+ * Returns { size, path, is_array } or null.
10325
+ ************************************************************/
10326
+ function is_collapsed(value) {
10327
+ if (value && typeof value === "object" && !Array.isArray(value)) {
10328
+ let keys = Object.keys(value);
10329
+ if (keys.length === 1 && keys[0] === "__collapsed__") {
10330
+ let c = value.__collapsed__ || {};
10331
+ return {
10332
+ size: c.size,
10333
+ path: c.path,
10334
+ is_array: false
10335
+ };
10336
+ }
10337
+ return null;
10338
+ }
10339
+ if (Array.isArray(value) && value.length === 1) {
10340
+ let e = value[0];
10341
+ if (e && typeof e === "object" && !Array.isArray(e) && Object.keys(e).length === 1 && e.__collapsed__) {
10342
+ let c = e.__collapsed__ || {};
10343
+ return {
10344
+ size: c.size,
10345
+ path: c.path,
10346
+ is_array: true
10347
+ };
10348
+ }
10349
+ }
10350
+ return null;
10351
+ }
10352
+ /************************************************************
10353
+ * Join / split absolute path segments (kernel convention)
10354
+ ************************************************************/
10355
+ function seg_join(segments) {
10356
+ return segments.map(function(s) {
10357
+ return String(s);
10358
+ }).join("`");
10359
+ }
10360
+ function seg_split(path) {
10361
+ if (path === "" || path === null || path === void 0) return [];
10362
+ return path.split("`");
10363
+ }
10364
+ /************************************************************
10365
+ * Walk a JSON tree by absolute segments; undefined if the
10366
+ * path does not resolve.
10367
+ ************************************************************/
10368
+ function get_by_segments(root, segments) {
10369
+ let v = root;
10370
+ for (let seg of segments) {
10371
+ if (v === null || v === void 0) return;
10372
+ if (Array.isArray(v)) v = v[Number(seg)];
10373
+ else if (typeof v === "object") v = v[seg];
10374
+ else return;
10375
+ }
10376
+ return v;
10377
+ }
10378
+ /************************************************************
10379
+ * Set a value at absolute segments (mutates root).
10380
+ *
10381
+ * segments == [] means "replace the whole root" — the caller
10382
+ * must use the RETURNED value in that case (a primitive/array
10383
+ * root cannot be mutated in place).
10384
+ ************************************************************/
10385
+ function set_by_segments(root, segments, new_value) {
10386
+ if (segments.length === 0) return new_value;
10387
+ let parent = get_by_segments(root, segments.slice(0, -1));
10388
+ if (parent === null || parent === void 0 || typeof parent !== "object") return root;
10389
+ let last = segments[segments.length - 1];
10390
+ if (Array.isArray(parent)) parent[Number(last)] = new_value;
10391
+ else parent[last] = new_value;
10392
+ return root;
10393
+ }
10394
+ /************************************************************
10395
+ * Does `value` (or any loaded descendant / its own key)
10396
+ * contain the lower-cased search term?
10397
+ *
10398
+ * Collapsed (not-yet-loaded) subtrees can't be searched, so
10399
+ * they never match on content — only their key can match,
10400
+ * which the renderer checks separately.
10401
+ ************************************************************/
10402
+ function subtree_matches(value, term) {
10403
+ if (!term) return true;
10404
+ if (is_collapsed(value)) return false;
10405
+ let type = json_type(value);
10406
+ if (type === "object") {
10407
+ for (let [k, v] of Object.entries(value)) {
10408
+ if (String(k).toLowerCase().includes(term)) return true;
10409
+ if (subtree_matches(v, term)) return true;
10410
+ }
10411
+ return false;
10412
+ }
10413
+ if (type === "array") {
10414
+ for (let v of value) if (subtree_matches(v, term)) return true;
10415
+ return false;
10416
+ }
10417
+ return String(value).toLowerCase().includes(term);
10418
+ }
10419
+ /************************************************************
10420
+ * Fields whose numeric value is an epoch timestamp.
10421
+ *
10422
+ * THE ONE LIST. C_YUI_FORM's jsoneditor takes its
10423
+ * `timestampTag` from here: it used to carry its own copy,
10424
+ * and a copy is how the two stopped agreeing.
10425
+ *
10426
+ * TWO SPELLINGS, AND LAS DOS SON DEL BACKEND. timeranger2
10427
+ * writes `from_t`/`from_tm` in the match_cond of a query and
10428
+ * `fr_t`/`fr_tm` in the metadata of a topic and of a file --
10429
+ * which is what a Raw JSON of a treedb actually shows. With
10430
+ * only the long pair listed, `to_t` got its date and the
10431
+ * `fr_t` right above it did not, which reads as a broken
10432
+ * annotator rather than a missing name.
10433
+ ************************************************************/
10434
+ var TIME_FIELDS = [
10435
+ "__t__",
10436
+ "__tm__",
10437
+ "t",
10438
+ "tm",
10439
+ "time",
10440
+ "from_t",
10441
+ "to_t",
10442
+ "from_tm",
10443
+ "to_tm",
10444
+ "fr_t",
10445
+ "fr_tm",
10446
+ "t_input",
10447
+ "t_output"
10448
+ ];
10449
+ function is_time_field(field) {
10450
+ return TIME_FIELDS.indexOf(field) >= 0;
10451
+ }
10452
+ /************************************************************
10453
+ * Format an epoch value as a local wall-clock string, 24
10454
+ * hours, in the APP's language `locale` (fmt_date_time() of
10455
+ * yui_time.js, as the time cells of the forms and tables;
10456
+ * up to gobj-ui 7.26.51 it was toLocaleString(): the
10457
+ * browser's language, and 12 hours in English).
10458
+ * Accepts seconds or milliseconds; returns null when the
10459
+ * value is not a usable positive timestamp (0 == "unset").
10460
+ ************************************************************/
10461
+ function format_epoch(value, locale) {
10462
+ if (typeof value !== "number" || !isFinite(value) || value <= 0) return null;
10463
+ let ms = Math.abs(value) < 0xe8d4a51000 ? value * 1e3 : value;
10464
+ let d = new Date(ms);
10465
+ if (isNaN(d.getTime())) return null;
10466
+ return fmt_date_time(d, locale);
10467
+ }
10468
+ /************************************************************
10469
+ * The text view's payload: the document as text, indented
10470
+ * four characters, cut at `max_chars`.
10471
+ *
10472
+ * Returns {text, capped}. `capped` is what the caller
10473
+ * announces under the dump — a cut that is not announced
10474
+ * reads as a document that ends there.
10475
+ ************************************************************/
10476
+ function json_text_dump(root, max_chars) {
10477
+ let text;
10478
+ try {
10479
+ text = JSON.stringify(root, null, 4);
10480
+ } catch (e) {
10481
+ return {
10482
+ text: "",
10483
+ capped: false,
10484
+ error: String(e)
10485
+ };
10486
+ }
10487
+ if (text === void 0) return {
10488
+ text: "",
10489
+ capped: false,
10490
+ error: "not representable as JSON"
10491
+ };
10492
+ if (typeof max_chars === "number" && max_chars > 0 && text.length > max_chars) return {
10493
+ text: text.slice(0, max_chars),
10494
+ capped: true
10495
+ };
10496
+ return {
10497
+ text,
10498
+ capped: false
10499
+ };
10500
+ }
10501
+ /************************************************************
10502
+ * Which view a freshly mounted viewer opens on.
10503
+ *
10504
+ * Three answers, in order of authority: what the HOST asked
10505
+ * for, what the READER chose last time, and `fallback`.
10506
+ *
10507
+ * The host wins because a viewer mounted to show a graph has
10508
+ * to show one. The memory comes next, because reopening a
10509
+ * document in the view you just left is the whole point of
10510
+ * remembering it. `fallback` is the floor.
10511
+ *
10512
+ * Anything not in `modes` is treated as unsaid, which covers
10513
+ * an absent value, an empty one, and a stored string from an
10514
+ * older release that named a view no longer offered.
10515
+ ************************************************************/
10516
+ function pick_view_mode(asked, remembered, modes, fallback) {
10517
+ let known = (m) => Array.isArray(modes) && modes.indexOf(m) >= 0;
10518
+ if (known(asked)) return asked;
10519
+ if (known(remembered)) return remembered;
9842
10520
  return fallback;
9843
10521
  }
9844
10522
  /************************************************************
@@ -9985,8 +10663,11 @@ function json_diff_rows(doc_a, doc_b) {
9985
10663
  * `new Date("YYYY-MM-DDT02:30:00")` answers the EARLIER one
9986
10664
  * (ECMAScript's "compatible" disambiguation). An epoch in the
9987
10665
  * SECOND pass of that hour is shown as 02:30 and comes back
9988
- * one hour earlier: saving the record -- any field of it --
9989
- * moves a writable time column that holds it by -3600 s.
10666
+ * one hour earlier. So neither the form's field nor the cell
10667
+ * editor reads a box that still shows what it was filled
10668
+ * with: they give back the value it was filled from (up to
10669
+ * gobj-ui 7.26.48 the cell, and 7.26.50 the field, wrote
10670
+ * -3600 s on a save of any field of the record).
9990
10671
  * - the night the clocks go forward (spring), one hour does not
9991
10672
  * exist. No epoch is shown in it, so nothing read comes back
9992
10673
  * wrong; a wall time TYPED in it is moved forward by the
@@ -9996,8 +10677,8 @@ function json_diff_rows(doc_a, doc_b) {
9996
10677
  * carry. What is safe: a read-only time column never goes back
9997
10678
  * (treedb_write_plan.js, col_goes_back_to_treedb), and a time
9998
10679
  * pkey2 goes back as the record had it, never through this
9999
- * widget (instance_keys_of). A writable time column edited or
10000
- * merely saved inside the repeated hour is the exposed case.
10680
+ * widget (instance_keys_of). A wall time TYPED inside the
10681
+ * repeated hour is the exposed case: it is the first pass.
10001
10682
  *
10002
10683
  * Copyright (c) 2026, ArtGins.
10003
10684
  * All Rights Reserved.
@@ -10050,15 +10731,17 @@ function epoch_to_time_value(epoch, real_type) {
10050
10731
  }
10051
10732
  /************************************************************
10052
10733
  * The value of a time column as a table cell shows it: the
10053
- * local clock the editor opens on, "YYYY-MM-DD HH:mm:ss", as
10054
- * fmt_epoch() of yui_time.js writes a timestamp in a table. ""
10055
- * for no time; a value that is not one is shown as it is, so the
10056
- * reader sees what the column holds.
10057
- ************************************************************/
10058
- function time_value_to_text(value, real_type) {
10734
+ * local clock, 24 hours, in the APP's language `locale`
10735
+ * (fmt_date_time() of yui_time.js: es "14 oct 2026, 15:05:09").
10736
+ * Up to gobj-ui 7.26.51 the form wrote "2026-10-14 15:05:09" and
10737
+ * the treedb table "14 oct 2026, 03:05:09 p. m.", in the
10738
+ * browser's language. "" for no time; a value that is not one is
10739
+ * shown as it is, so the reader sees what the column holds.
10740
+ ************************************************************/
10741
+ function time_value_to_text(value, real_type, locale) {
10059
10742
  let date = time_value_to_date(value, real_type);
10060
10743
  if (!date) return value === null || value === void 0 ? "" : String(value);
10061
- return date_to_datetime_local(date).replace("T", " ");
10744
+ return fmt_date_time(date, locale);
10062
10745
  }
10063
10746
  //#endregion
10064
10747
  //#region src/form_time_cell_editor.js
@@ -12563,6 +13246,36 @@ function table_column_titles(template) {
12563
13246
  });
12564
13247
  return titles;
12565
13248
  }
13249
+ var TIME_CELL_FORMATTERS = /* @__PURE__ */ new WeakSet();
13250
+ /******************************************************************
13251
+ * The formatter of a time cell: the local clock, 24 hours, in the
13252
+ * APP's language (fmt_date_time of yui_time.js, as the cells of
13253
+ * C_YUI_TREEDB_TOPIC_WITH_FORM): es "14 oct 2026, 15:05:09".
13254
+ ******************************************************************/
13255
+ function time_cell_formatter(real_type) {
13256
+ let formatter = function(cell) {
13257
+ return text_node(time_value_to_text(cell.getValue(), real_type, safe_locale(i18next.default.language)));
13258
+ };
13259
+ TIME_CELL_FORMATTERS.add(formatter);
13260
+ return formatter;
13261
+ }
13262
+ /******************************************************************
13263
+ * Draw the time cells of a table again, in the current language.
13264
+ * Cell by cell, never a redraw of the rows: a row's formatter
13265
+ * builds its nested tables anew -- empty. A cell being edited is
13266
+ * its editor's; Tabulator formats it again when the editor closes.
13267
+ ******************************************************************/
13268
+ function reformat_time_cells(tabulator) {
13269
+ for (let column of tabulator.getColumns()) {
13270
+ let formatter = column.getDefinition().formatter;
13271
+ if (!TIME_CELL_FORMATTERS.has(formatter)) continue;
13272
+ for (let cell of column.getCells()) {
13273
+ let $cell = cell.getElement();
13274
+ if ($cell.classList.contains("tabulator-editing")) continue;
13275
+ $cell.replaceChildren(formatter(cell));
13276
+ }
13277
+ }
13278
+ }
12566
13279
  /******************************************************************
12567
13280
  * Convert a template's items in tabulator columns
12568
13281
  ******************************************************************/
@@ -12675,9 +13388,7 @@ function template2columns(gobj, columns, template, sub_elements) {
12675
13388
  case "time":
12676
13389
  column.editor = form_time_cell_editor(field_desc.real_type);
12677
13390
  column.editorParams = { verticalNavigation: "table" };
12678
- column.formatter = function(cell) {
12679
- return text_node(time_value_to_text(cell.getValue(), field_desc.real_type));
12680
- };
13391
+ column.formatter = time_cell_formatter(field_desc.real_type);
12681
13392
  break;
12682
13393
  case "color":
12683
13394
  column.editor = "input";
@@ -12903,7 +13614,8 @@ function get_form_values(gobj, $form) {
12903
13614
  case "input":
12904
13615
  switch (input_type) {
12905
13616
  case "datetime-local":
12906
- value = datetime_local_to_epoch($input.value);
13617
+ if ($input.yui_time_kept && $input.value === $input.yui_time_kept.shown) value = $input.yui_time_kept.value;
13618
+ else value = datetime_local_to_epoch($input.value);
12907
13619
  break;
12908
13620
  default: value = getInputValue($input);
12909
13621
  }
@@ -12971,8 +13683,10 @@ function clear_data(gobj, $form) {
12971
13683
  if (jsoneditor) jsoneditor.set({ text: "" });
12972
13684
  } else if ($input.type === "checkbox") $input.checked = false;
12973
13685
  else if ($input.type === "radio") $input.checked = false;
12974
- else if ($input.type === "datetime-local") $input.value = null;
12975
- else if ($input.type === "color") {
13686
+ else if ($input.type === "datetime-local") {
13687
+ $input.value = null;
13688
+ $input.yui_time_kept = null;
13689
+ } else if ($input.type === "color") {
12976
13690
  $input.value = "#000000";
12977
13691
  if ($input.yui_color_value) {
12978
13692
  $input.yui_color_value.textContent = $input.value;
@@ -13062,6 +13776,7 @@ function set_form_values(gobj, template, $form, record) {
13062
13776
  value = field_desc.default_value;
13063
13777
  modified = true;
13064
13778
  }
13779
+ let stored = value === void 0 ? null : value;
13065
13780
  value = treedb_value_2_form_value(gobj, field_desc, value);
13066
13781
  if (value === void 0) value = null;
13067
13782
  switch (tag) {
@@ -13074,6 +13789,10 @@ function set_form_values(gobj, template, $form, record) {
13074
13789
  switch (input_type) {
13075
13790
  case "datetime-local":
13076
13791
  $input.value = date_to_datetime_local(value);
13792
+ $input.yui_time_kept = {
13793
+ value: stored,
13794
+ shown: $input.value
13795
+ };
13077
13796
  break;
13078
13797
  case "color":
13079
13798
  $input.value = convertColor(value);
@@ -13650,7 +14369,7 @@ function ac_name_json_editors(gobj, event, kw, src) {
13650
14369
  * in the old language until it draws it again, so each is told to
13651
14370
  * (a new onRenderMenu), and the render names it again.
13652
14371
  ************************************************************/
13653
- function ac_language_changed$10(gobj, event, kw, src) {
14372
+ function ac_language_changed$11(gobj, event, kw, src) {
13654
14373
  let $container = (0, _yuneta_gobj_js.gobj_read_attr)(gobj, "$container");
13655
14374
  if (!$container) return 0;
13656
14375
  for (let $editor of $container.querySelectorAll(".jsoneditor")) {
@@ -13659,7 +14378,10 @@ function ac_language_changed$10(gobj, event, kw, src) {
13659
14378
  }
13660
14379
  for (let $table of $container.querySelectorAll(".yui-tabulator-table, .yui-tabulator-table-nested")) {
13661
14380
  let tabulator = $table.tabulator;
13662
- if (tabulator && tabulator.initialized && $table.template) yui_tabulator_relocalize(tabulator, i18next.t, table_column_titles($table.template));
14381
+ if (tabulator && tabulator.initialized && $table.template) {
14382
+ yui_tabulator_relocalize(tabulator, i18next.t, table_column_titles($table.template));
14383
+ reformat_time_cells(tabulator);
14384
+ }
13663
14385
  }
13664
14386
  return 0;
13665
14387
  }
@@ -13836,7 +14558,7 @@ function create_gclass$17(gclass_name) {
13836
14558
  ],
13837
14559
  [
13838
14560
  "EV_LANGUAGE_CHANGED",
13839
- ac_language_changed$10,
14561
+ ac_language_changed$11,
13840
14562
  null
13841
14563
  ]
13842
14564
  ]]];
@@ -14232,7 +14954,7 @@ function mt_create$16(gobj) {
14232
14954
  * rewritten in place, and the map's locale with them so a
14233
14955
  * control or a popup built later is right too.
14234
14956
  ***************************************************************/
14235
- function ac_language_changed$9(gobj, event, kw, src) {
14957
+ function ac_language_changed$10(gobj, event, kw, src) {
14236
14958
  let priv = gobj.priv;
14237
14959
  if (priv.xmap) yui_maplibre_relocalize(priv.xmap, i18next.t);
14238
14960
  return 0;
@@ -14800,7 +15522,7 @@ function create_gclass$16(gclass_name) {
14800
15522
  ], [["ST_IDLE", [
14801
15523
  [
14802
15524
  "EV_LANGUAGE_CHANGED",
14803
- ac_language_changed$9,
15525
+ ac_language_changed$10,
14804
15526
  null
14805
15527
  ],
14806
15528
  [
@@ -14949,12 +15671,145 @@ function yui_uplot_axes(axes) {
14949
15671
  });
14950
15672
  }
14951
15673
  //#endregion
15674
+ //#region src/yui_uplot_time.js
15675
+ /***********************************************************************
15676
+ * yui_uplot_time.js
15677
+ *
15678
+ * The texts uPlot writes for a moment -- the ticks of a time axis
15679
+ * and the reading of the legend -- in the APP's language, with a
15680
+ * clock of 24 hours, as every other time a gobj-ui view shows
15681
+ * (fmt_date_time of yui_time.js).
15682
+ *
15683
+ * uPlot writes them from templates of its own, in English and
15684
+ * 12 hours: "3pm", "3:05pm", "10/14" (month first), "Oct", and
15685
+ * "2026-10-14 3:05pm" in the legend. Its `fmtDate` option takes
15686
+ * the template and returns the function that writes a Date with
15687
+ * it; this one is given to it:
15688
+ *
15689
+ * legend "{YYYY}-{MM}-{DD} {h}:{mm}{aa}" -> fmt_date_time()
15690
+ * "14 oct 2026, 15:05:09"
15691
+ * "{h}{aa}" "3pm" -> "15:00"
15692
+ * "{h}:{mm}{aa}" "3:05pm" -> "15:05"
15693
+ * "{M}/{D}" "10/14" -> es "14/10", en "10/14"
15694
+ * "{M}/{D}/{YY}" "10/14/26"-> es "14/10/26", en "10/14/26"
15695
+ * "{MMM}" "Oct" -> es "oct", en "Oct"
15696
+ *
15697
+ * The language is asked for on every call, so a redraw after a
15698
+ * language change writes the new one (C_YUI_UPLOT redraws its
15699
+ * axes on EV_LANGUAGE_CHANGED).
15700
+ *
15701
+ * Copyright (c) 2026, ArtGins.
15702
+ * All Rights Reserved.
15703
+ ***********************************************************************/
15704
+ var LEGEND_STAMP = "{YYYY}-{MM}-{DD} {h}:{mm}{aa}";
15705
+ var pad2 = (n) => String(n).padStart(2, "0");
15706
+ var __formatters__ = /* @__PURE__ */ new Map();
15707
+ function intl(locale, opts) {
15708
+ let key = locale + "|" + JSON.stringify(opts);
15709
+ let f = __formatters__.get(key);
15710
+ if (!f) {
15711
+ try {
15712
+ f = new Intl.DateTimeFormat(locale, opts);
15713
+ } catch (e) {
15714
+ f = new Intl.DateTimeFormat("en", opts);
15715
+ }
15716
+ __formatters__.set(key, f);
15717
+ }
15718
+ return f;
15719
+ }
15720
+ var WHOLE = [
15721
+ ["{M}/{D}/{YY}", (d, loc) => intl(loc, {
15722
+ day: "numeric",
15723
+ month: "numeric",
15724
+ year: "2-digit"
15725
+ }).format(d)],
15726
+ ["{M}/{D}", (d, loc) => intl(loc, {
15727
+ day: "numeric",
15728
+ month: "numeric"
15729
+ }).format(d)],
15730
+ ["{h}{aa}", (d) => `${pad2(d.getHours())}:00`]
15731
+ ];
15732
+ var TOKENS = {
15733
+ YYYY: (d) => String(d.getFullYear()),
15734
+ YY: (d) => String(d.getFullYear()).slice(2),
15735
+ MMMM: (d, loc) => intl(loc, { month: "long" }).format(d),
15736
+ MMM: (d, loc) => intl(loc, { month: "short" }).format(d),
15737
+ MM: (d) => pad2(d.getMonth() + 1),
15738
+ M: (d) => String(d.getMonth() + 1),
15739
+ DD: (d) => pad2(d.getDate()),
15740
+ D: (d) => String(d.getDate()),
15741
+ WWWW: (d, loc) => intl(loc, { weekday: "long" }).format(d),
15742
+ WWW: (d, loc) => intl(loc, { weekday: "short" }).format(d),
15743
+ HH: (d) => pad2(d.getHours()),
15744
+ H: (d) => String(d.getHours()),
15745
+ hh: (d) => pad2(d.getHours()),
15746
+ h: (d) => pad2(d.getHours()),
15747
+ AA: () => "",
15748
+ aa: () => "",
15749
+ a: () => "",
15750
+ mm: (d) => pad2(d.getMinutes()),
15751
+ m: (d) => String(d.getMinutes()),
15752
+ ss: (d) => pad2(d.getSeconds()),
15753
+ s: (d) => String(d.getSeconds()),
15754
+ fff: (d) => String(d.getMilliseconds()).padStart(3, "0")
15755
+ };
15756
+ /***************************************************************
15757
+ * A template -> its parts: literal text, or a function of
15758
+ * (date, locale).
15759
+ ***************************************************************/
15760
+ function template_parts(tpl) {
15761
+ let parts = [];
15762
+ let rest = String(tpl);
15763
+ while (rest.length > 0) {
15764
+ let whole = WHOLE.find(([frag]) => rest.startsWith(frag));
15765
+ if (whole) {
15766
+ parts.push(whole[1]);
15767
+ rest = rest.slice(whole[0].length);
15768
+ continue;
15769
+ }
15770
+ let m = /^\{([a-z]+)\}/i.exec(rest);
15771
+ if (m && TOKENS[m[1]]) {
15772
+ parts.push(TOKENS[m[1]]);
15773
+ rest = rest.slice(m[0].length);
15774
+ continue;
15775
+ }
15776
+ let next = rest.indexOf("{", 1);
15777
+ let text = next < 0 ? rest : rest.slice(0, next);
15778
+ parts.push(text);
15779
+ rest = rest.slice(text.length);
15780
+ }
15781
+ return parts;
15782
+ }
15783
+ /***************************************************************
15784
+ * uPlot's `fmtDate` option. `get_locale` answers the app's
15785
+ * language at the moment of the call (the views pass
15786
+ * `() => i18next.language`).
15787
+ ***************************************************************/
15788
+ function yui_uplot_fmt_date(get_locale) {
15789
+ let locale = () => safe_locale(typeof get_locale === "function" ? get_locale() : null);
15790
+ return function(tpl) {
15791
+ if (tpl === LEGEND_STAMP) return (date) => fmt_date_time(date, locale());
15792
+ let parts = template_parts(tpl);
15793
+ return function(date) {
15794
+ let loc = locale();
15795
+ let out = "";
15796
+ for (let part of parts) out += typeof part === "string" ? part : part(date, loc);
15797
+ return out;
15798
+ };
15799
+ };
15800
+ }
15801
+ //#endregion
14952
15802
  //#region src/c_yui_uplot.js
14953
15803
  /***********************************************************************
14954
15804
  * c_yui_uplot.js
14955
15805
  *
14956
15806
  * Graphics, Charts with uPlot
14957
15807
  *
15808
+ * A moment uPlot writes -- a tick of a time axis, the reading of
15809
+ * the legend -- is in the app's language with a clock of 24 hours
15810
+ * (yui_uplot_time.js), and is written again on the shell's
15811
+ * EV_LANGUAGE_CHANGED.
15812
+ *
14958
15813
  * Copyright (c) 2025-2026, ArtGins.
14959
15814
  * All Rights Reserved.
14960
15815
  ***********************************************************************/
@@ -14983,7 +15838,10 @@ var attrs_table$15 = [
14983
15838
  (0, _yuneta_gobj_js.SDATA)(_yuneta_gobj_js.data_type_t.DTP_INTEGER, "timeout_idle", 0, 5, "Idle timeout (seconds)"),
14984
15839
  (0, _yuneta_gobj_js.SDATA_END)()
14985
15840
  ];
14986
- var PRIVATE_DATA$15 = { theme_observer: null };
15841
+ var PRIVATE_DATA$15 = {
15842
+ theme_observer: null,
15843
+ lang_shell: null
15844
+ };
14987
15845
  var __gclass__$15 = null;
14988
15846
  /******************************
14989
15847
  * Framework Methods
@@ -15001,11 +15859,22 @@ function mt_create$15(gobj) {
15001
15859
  /***************************************************************
15002
15860
  * Framework Method: Start
15003
15861
  ***************************************************************/
15004
- function mt_start$15(gobj) {}
15862
+ function mt_start$15(gobj) {
15863
+ let priv = gobj.priv;
15864
+ let shell = yui_shell_of(gobj);
15865
+ if (shell) {
15866
+ (0, _yuneta_gobj_js.gobj_subscribe_event)(shell, "EV_LANGUAGE_CHANGED", {}, gobj);
15867
+ priv.lang_shell = shell;
15868
+ }
15869
+ }
15005
15870
  /***************************************************************
15006
15871
  * Framework Method: Stop
15007
15872
  ***************************************************************/
15008
- function mt_stop$15(gobj) {}
15873
+ function mt_stop$15(gobj) {
15874
+ let priv = gobj.priv;
15875
+ if (priv.lang_shell && !(0, _yuneta_gobj_js.gobj_is_destroying)(priv.lang_shell)) (0, _yuneta_gobj_js.gobj_unsubscribe_event)(priv.lang_shell, "EV_LANGUAGE_CHANGED", {}, gobj);
15876
+ priv.lang_shell = null;
15877
+ }
15009
15878
  /***************************************************************
15010
15879
  * Framework Method: Destroy
15011
15880
  ***************************************************************/
@@ -15043,7 +15912,8 @@ function build_ui$14(gobj) {
15043
15912
  height: (0, _yuneta_gobj_js.gobj_read_attr)(gobj, "height"),
15044
15913
  series: (0, _yuneta_gobj_js.gobj_read_attr)(gobj, "series"),
15045
15914
  axes: yui_uplot_axes((0, _yuneta_gobj_js.gobj_read_attr)(gobj, "axes")),
15046
- scales: (0, _yuneta_gobj_js.gobj_read_attr)(gobj, "scales")
15915
+ scales: (0, _yuneta_gobj_js.gobj_read_attr)(gobj, "scales"),
15916
+ fmtDate: yui_uplot_fmt_date(() => i18next.default.language)
15047
15917
  };
15048
15918
  let uplot$2 = new uplot.default(uPlot_options, (0, _yuneta_gobj_js.gobj_read_attr)(gobj, "data"), $container);
15049
15919
  (0, _yuneta_gobj_js.gobj_write_attr)(gobj, "uplot", uplot$2);
@@ -15165,17 +16035,33 @@ function ac_theme$4(gobj, event, kw, src) {
15165
16035
  return 0;
15166
16036
  }
15167
16037
  /******************************************************
16038
+ * The language changed: the ticks of a time axis and the
16039
+ * reading of the legend ask for it when they are written,
16040
+ * so they are written again.
16041
+ ******************************************************/
16042
+ function ac_language_changed$9(gobj, event, kw, src) {
16043
+ let uplot$6 = (0, _yuneta_gobj_js.gobj_read_attr)(gobj, "uplot");
16044
+ if (!uplot$6) return 0;
16045
+ try {
16046
+ uplot$6.redraw(true, true);
16047
+ uplot$6.setLegend(null, false);
16048
+ } catch (e) {
16049
+ (0, _yuneta_gobj_js.log_error)(`${(0, _yuneta_gobj_js.gobj_short_name)(gobj)}: cannot redraw the chart: ${e}`);
16050
+ }
16051
+ return 0;
16052
+ }
16053
+ /******************************************************
15168
16054
  *
15169
16055
  ******************************************************/
15170
16056
  function ac_del_serie(gobj, event, kw, src) {
15171
- let uplot$6 = (0, _yuneta_gobj_js.gobj_read_attr)(gobj, "uplot");
15172
- for (let idx = 1; idx < uplot$6.series.length; idx++) {
15173
- let serie = uplot$6.series[idx];
16057
+ let uplot$7 = (0, _yuneta_gobj_js.gobj_read_attr)(gobj, "uplot");
16058
+ for (let idx = 1; idx < uplot$7.series.length; idx++) {
16059
+ let serie = uplot$7.series[idx];
15174
16060
  if (serie.id && serie.id === kw.id) {
15175
- uplot$6.delSeries(idx);
15176
- let data = uplot$6.data.splice(idx, 1);
16061
+ uplot$7.delSeries(idx);
16062
+ let data = uplot$7.data.splice(idx, 1);
15177
16063
  if (data.length === 1) data = [[]];
15178
- uplot$6.setData(data);
16064
+ uplot$7.setData(data);
15179
16065
  return 0;
15180
16066
  }
15181
16067
  }
@@ -15185,9 +16071,9 @@ function ac_del_serie(gobj, event, kw, src) {
15185
16071
  *
15186
16072
  ******************************************************/
15187
16073
  function ac_clear$1(gobj, event, kw, src) {
15188
- let uplot$7 = (0, _yuneta_gobj_js.gobj_read_attr)(gobj, "uplot");
15189
- uplot$7.setData([[]]);
15190
- for (let idx = uplot$7.series.length - 1; idx > 0; idx--) uplot$7.delSeries(idx);
16074
+ let uplot$8 = (0, _yuneta_gobj_js.gobj_read_attr)(gobj, "uplot");
16075
+ uplot$8.setData([[]]);
16076
+ for (let idx = uplot$8.series.length - 1; idx > 0; idx--) uplot$8.delSeries(idx);
15191
16077
  return 0;
15192
16078
  }
15193
16079
  /***************************
@@ -15212,7 +16098,8 @@ function create_gclass$15(gclass_name) {
15212
16098
  ["EV_ADD_SERIE", 0],
15213
16099
  ["EV_DEL_SERIE", 0],
15214
16100
  ["EV_CLEAR", 0],
15215
- ["EV_THEME", 0]
16101
+ ["EV_THEME", 0],
16102
+ ["EV_LANGUAGE_CHANGED", 0]
15216
16103
  ], [["ST_IDLE", [
15217
16104
  [
15218
16105
  "EV_LOAD_DATA",
@@ -15238,6 +16125,11 @@ function create_gclass$15(gclass_name) {
15238
16125
  "EV_THEME",
15239
16126
  ac_theme$4,
15240
16127
  null
16128
+ ],
16129
+ [
16130
+ "EV_LANGUAGE_CHANGED",
16131
+ ac_language_changed$9,
16132
+ null
15241
16133
  ]
15242
16134
  ]]], gmt$15, 0, attrs_table$15, PRIVATE_DATA$15, 0, 0, 0, 0);
15243
16135
  if (!__gclass__$15) return -1;
@@ -18304,7 +19196,8 @@ var PRIVATE_DATA$13 = {
18304
19196
  $search_ctl: null,
18305
19197
  $expand_btn: null,
18306
19198
  $collapse_btn: null,
18307
- $mode_btns: null
19199
+ $mode_btns: null,
19200
+ lang_shell: null
18308
19201
  };
18309
19202
  var __gclass__$13 = null;
18310
19203
  /******************************
@@ -18332,13 +19225,22 @@ function mt_create$13(gobj) {
18332
19225
  * Framework Method: Start
18333
19226
  ***************************************************************/
18334
19227
  function mt_start$13(gobj) {
18335
- if (gobj.priv.root !== null) (0, _yuneta_gobj_js.gobj_change_state)(gobj, "ST_READY");
19228
+ let priv = gobj.priv;
19229
+ if (priv.root !== null) (0, _yuneta_gobj_js.gobj_change_state)(gobj, "ST_READY");
19230
+ let shell = yui_shell_of(gobj);
19231
+ if (shell) {
19232
+ (0, _yuneta_gobj_js.gobj_subscribe_event)(shell, "EV_LANGUAGE_CHANGED", {}, gobj);
19233
+ priv.lang_shell = shell;
19234
+ }
18336
19235
  render_view$1(gobj);
18337
19236
  }
18338
19237
  /***************************************************************
18339
19238
  * Framework Method: Stop
18340
19239
  ***************************************************************/
18341
19240
  function mt_stop$13(gobj) {
19241
+ let priv = gobj.priv;
19242
+ if (priv.lang_shell && !(0, _yuneta_gobj_js.gobj_is_destroying)(priv.lang_shell)) (0, _yuneta_gobj_js.gobj_unsubscribe_event)(priv.lang_shell, "EV_LANGUAGE_CHANGED", {}, gobj);
19243
+ priv.lang_shell = null;
18342
19244
  teardown_graph_child$1(gobj);
18343
19245
  }
18344
19246
  /***************************************************************
@@ -19037,7 +19939,7 @@ function leaf_row(key, value, depth) {
19037
19939
  text_node(text)
19038
19940
  ]);
19039
19941
  if (key !== null && is_time_field(String(key))) {
19040
- let wall = format_epoch(value);
19942
+ let wall = format_epoch(value, safe_locale(i18next.default.language));
19041
19943
  if (wall) body.push([
19042
19944
  "span",
19043
19945
  { class: "JSON_TIME is-size-7 yui-text-quiet ml-2" },
@@ -19288,6 +20190,12 @@ function ac_json_item_clicked(gobj, event, kw, src) {
19288
20190
  }
19289
20191
  /************************************************************
19290
20192
  * EV_LANGUAGE_CHANGED — re-translate chrome + re-render
20193
+ *
20194
+ * Only the TREE is drawn again: it writes the reading of a
20195
+ * time field in the language of the moment it was drawn. The
20196
+ * text view carries its keys (refresh_language reaches them),
20197
+ * and loading the graph again would throw away the reader's
20198
+ * camera for nothing.
19291
20199
  ************************************************************/
19292
20200
  function ac_language_changed$8(gobj, event, kw, src) {
19293
20201
  let priv = gobj.priv;
@@ -19297,7 +20205,7 @@ function ac_language_changed$8(gobj, event, kw, src) {
19297
20205
  if (priv.$search) priv.$search.setAttribute("placeholder", (0, i18next.t)("search"));
19298
20206
  apply_view_mode$1(gobj);
19299
20207
  }
19300
- render_view$1(gobj);
20208
+ if (current_view_mode$1(gobj) === "tree") render_tree(gobj);
19301
20209
  return 0;
19302
20210
  }
19303
20211
  /************************************************************
@@ -32978,26 +33886,11 @@ function transform__treedb_value_2_table_value(gobj, col, value, row, field) {
32978
33886
  switch (field_desc.real_type) {
32979
33887
  case "string":
32980
33888
  case "integer":
32981
- value = time_value_to_date(value, field_desc.real_type);
32982
- if (!value) {
32983
- value = "";
32984
- break;
32985
- }
32986
- const rawLocale = navigator.language;
32987
- const userLocale = typeof rawLocale === "string" && rawLocale && rawLocale !== "undefined" ? rawLocale : void 0;
32988
- const formatter = new Intl.DateTimeFormat(userLocale, {
32989
- day: "numeric",
32990
- month: "short",
32991
- year: "numeric",
32992
- hour: "2-digit",
32993
- minute: "2-digit",
32994
- second: "2-digit",
32995
- hour12: true
32996
- });
32997
- value = (0, _yuneta_gobj_js.createElement2)([
33889
+ value = time_value_to_text(value, field_desc.real_type, safe_locale(i18next.default.language));
33890
+ if (value) value = (0, _yuneta_gobj_js.createElement2)([
32998
33891
  "span",
32999
33892
  { class: "is-size-7" },
33000
- formatter.format(value)
33893
+ text_node(value)
33001
33894
  ]);
33002
33895
  }
33003
33896
  break;
@@ -82652,591 +83545,6 @@ function register_c_yui_schema_editor() {
82652
83545
  return create_gclass$1(GCLASS_NAME$1);
82653
83546
  }
82654
83547
  //#endregion
82655
- //#region src/yui_time.js
82656
- /***********************************************************************
82657
- * yui_time.js
82658
- *
82659
- * Time, without a DOM: epochs, and the algebra of PERIODS.
82660
- *
82661
- * Two things live here, and they are the two halves of every date
82662
- * UI the projects keep rewriting:
82663
- *
82664
- * 1) EPOCH <-> the local wall clock. A timestamp travels in the
82665
- * producer's own unit — seconds, or milliseconds when a topic
82666
- * says so — and every conversion crosses that `ms` flag. Getting
82667
- * it wrong puts the same instant on two different clocks in one
82668
- * screen (it did: a picker asking "from 18:55" local returned
82669
- * rows a table labelled 16:55).
82670
- *
82671
- * 2) The PERIOD. A period is not an enum of five names: it is a
82672
- * BUCKET, and a bucket is `count` of a `unit`:
82673
- *
82674
- * {id: "day", unit: "day", count: 1}
82675
- * {id: "week", unit: "week", count: 1} ISO, Mon-first
82676
- * {id: "bimester", unit: "month", count: 2}
82677
- * {id: "quarter", unit: "month", count: 3}
82678
- * {id: "semester", unit: "month", count: 6}
82679
- * {id: "decade", unit: "year", count: 10}
82680
- * {id: "15min", unit: "minute", count: 15}
82681
- *
82682
- * Given that pair, ONE implementation answers every question a
82683
- * date navigator asks — where does the bucket holding this
82684
- * instant start and end, what is the previous/next one, what do
82685
- * I call it — so an app that wants quarters declares a quarter
82686
- * instead of asking for a new component.
82687
- *
82688
- * Buckets are ALIGNED, never "count back from now": months align to
82689
- * the year (which is why 2, 3, 4, 6 and 12 fall on clean calendar
82690
- * boundaries), weeks to Monday, hours to local midnight. "Last 7
82691
- * days" is a different animal — a rolling window — and it is not a
82692
- * period: see `rolling_bounds()`.
82693
- *
82694
- * Everything here is LOCAL time (the user reads a local clock) and
82695
- * DST-safe: it never adds 86400000 ms to cross a day, it builds the
82696
- * next date from calendar fields and lets the platform do it.
82697
- *
82698
- * Copyright (c) 2026, ArtGins.
82699
- * All Rights Reserved.
82700
- ***********************************************************************/
82701
- /***************************************************************
82702
- * Constants
82703
- ***************************************************************/
82704
- var MS_DAY = 864e5;
82705
- var PERIOD_UNITS = [
82706
- "minute",
82707
- "hour",
82708
- "day",
82709
- "week",
82710
- "month",
82711
- "year"
82712
- ];
82713
- var YUI_PERIODS = {
82714
- minute: {
82715
- id: "minute",
82716
- unit: "minute",
82717
- count: 1
82718
- },
82719
- "5min": {
82720
- id: "5min",
82721
- unit: "minute",
82722
- count: 5
82723
- },
82724
- "15min": {
82725
- id: "15min",
82726
- unit: "minute",
82727
- count: 15
82728
- },
82729
- hour: {
82730
- id: "hour",
82731
- unit: "hour",
82732
- count: 1
82733
- },
82734
- day: {
82735
- id: "day",
82736
- unit: "day",
82737
- count: 1
82738
- },
82739
- week: {
82740
- id: "week",
82741
- unit: "week",
82742
- count: 1
82743
- },
82744
- fortnight: {
82745
- id: "fortnight",
82746
- unit: "week",
82747
- count: 2
82748
- },
82749
- month: {
82750
- id: "month",
82751
- unit: "month",
82752
- count: 1
82753
- },
82754
- bimester: {
82755
- id: "bimester",
82756
- unit: "month",
82757
- count: 2
82758
- },
82759
- quarter: {
82760
- id: "quarter",
82761
- unit: "month",
82762
- count: 3
82763
- },
82764
- semester: {
82765
- id: "semester",
82766
- unit: "month",
82767
- count: 6
82768
- },
82769
- year: {
82770
- id: "year",
82771
- unit: "year",
82772
- count: 1
82773
- },
82774
- decade: {
82775
- id: "decade",
82776
- unit: "year",
82777
- count: 10
82778
- }
82779
- };
82780
- var YUI_PERIODS_DEFAULT = [
82781
- "hour",
82782
- "day",
82783
- "week",
82784
- "month",
82785
- "year"
82786
- ];
82787
- var YUI_ROLLING = {
82788
- "1h": {
82789
- id: "1h",
82790
- secs: 3600,
82791
- label: "last hour"
82792
- },
82793
- "6h": {
82794
- id: "6h",
82795
- secs: 21600,
82796
- label: "last 6h"
82797
- },
82798
- "24h": {
82799
- id: "24h",
82800
- secs: 86400,
82801
- label: "last 24h"
82802
- },
82803
- "7d": {
82804
- id: "7d",
82805
- secs: 604800,
82806
- label: "last 7 days"
82807
- },
82808
- "30d": {
82809
- id: "30d",
82810
- secs: 2592e3,
82811
- label: "last 30 days"
82812
- }
82813
- };
82814
- /***************************
82815
- * Locale / i18n
82816
- ***************************/
82817
- /***************************************************************
82818
- * The locale to format with.
82819
- *
82820
- * NEVER at module top level, and never `navigator.language` raw:
82821
- * Firefox can report the literal STRING "undefined", and every Intl
82822
- * constructor throws RangeError on it — a module that built its
82823
- * formatter on import took the whole bundle down with it (that is why
82824
- * gui_agent refuses to import the gobj-ui barrel).
82825
- ***************************************************************/
82826
- function safe_locale(locale) {
82827
- if (typeof locale === "string" && locale && locale !== "undefined") return locale;
82828
- let nav = typeof navigator !== "undefined" ? navigator.language : null;
82829
- if (typeof nav === "string" && nav && nav !== "undefined") return nav;
82830
- return "en";
82831
- }
82832
- /***************************************************************
82833
- * Translate through the APP's translator when it gave us one, and
82834
- * degrade to the key itself otherwise — interpolating `{{x}}` by hand,
82835
- * so a label never renders raw mustaches at a caller that has no i18n.
82836
- ***************************************************************/
82837
- function tr(t, key, params) {
82838
- if (typeof t === "function") return t(key, params);
82839
- let s = key;
82840
- for (let k in params || {}) s = s.replaceAll(`{{${k}}}`, String(params[k]));
82841
- return s;
82842
- }
82843
- /***************************************************************
82844
- * Intl formatters, built PER CALL (see safe_locale). They are cheap
82845
- * next to a repaint, and caching them would need a locale-change hook
82846
- * the library has no business owning.
82847
- ***************************************************************/
82848
- function fmt_intl(date, locale, opts) {
82849
- try {
82850
- return new Intl.DateTimeFormat(safe_locale(locale), opts).format(date);
82851
- } catch (e) {
82852
- return date.toDateString();
82853
- }
82854
- }
82855
- /***************************
82856
- * Epoch <-> clock
82857
- ***************************/
82858
- /***************************************************************
82859
- * Epoch in the producer's unit -> milliseconds, and back.
82860
- * `ms` true means the value already IS milliseconds.
82861
- ***************************************************************/
82862
- function epoch_to_ms(value, ms) {
82863
- if (!value) return 0;
82864
- return ms ? value : value * 1e3;
82865
- }
82866
- function ms_to_epoch(value_ms, ms) {
82867
- if (!value_ms) return 0;
82868
- return ms ? value_ms : Math.floor(value_ms / 1e3);
82869
- }
82870
- /***************************************************************
82871
- * The LOCAL wall-clock string an `<input type="datetime-local">` takes
82872
- * ("YYYY-MM-DDTHH:MM:SS", which needs step=1 to keep the seconds), and
82873
- * the parse back. Empty / unparseable -> 0, which is exactly how a
82874
- * match condition reads an absent bound.
82875
- ***************************************************************/
82876
- function epoch_to_local_input(value, ms) {
82877
- if (!value) return "";
82878
- let d = new Date(epoch_to_ms(value, ms));
82879
- let pad = (n) => String(n).padStart(2, "0");
82880
- return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}T${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}`;
82881
- }
82882
- function local_input_to_epoch(v, ms) {
82883
- if (!v) return 0;
82884
- let parsed = Date.parse(v);
82885
- if (Number.isNaN(parsed)) return 0;
82886
- return ms_to_epoch(parsed, ms);
82887
- }
82888
- /***************************************************************
82889
- * A timestamp for a table cell: the local wall clock, space-separated,
82890
- * keeping the milliseconds when the producer bothered to send them (a
82891
- * topic that sets sf_t_ms usually appends several records inside the
82892
- * same second, and a column that hides that shows a column of ties).
82893
- ***************************************************************/
82894
- function fmt_epoch(value, ms) {
82895
- if (!value) return "";
82896
- try {
82897
- let s = epoch_to_local_input(value, ms).replace("T", " ");
82898
- if (ms) s += `.${String(value % 1e3).padStart(3, "0")}`;
82899
- return s;
82900
- } catch (e) {
82901
- return String(value);
82902
- }
82903
- }
82904
- /***************************
82905
- * Calendar atoms
82906
- ***************************/
82907
- /***************************************************************
82908
- * The day number of a date, counting local calendar days from
82909
- * 1970-01-01. Built from the FIELDS (Date.UTC of y/m/d), never from
82910
- * the timestamp: a DST day is 23 or 25 hours long, so dividing a local
82911
- * epoch by 86400000 drifts a day twice a year.
82912
- ***************************************************************/
82913
- function day_number(d) {
82914
- return Math.floor(Date.UTC(d.getFullYear(), d.getMonth(), d.getDate()) / MS_DAY);
82915
- }
82916
- function date_from_day_number(n) {
82917
- let d = /* @__PURE__ */ new Date(n * MS_DAY);
82918
- return new Date(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate());
82919
- }
82920
- /***************************************************************
82921
- * The Monday of the week a date falls in (ISO: the week starts on
82922
- * Monday, and Sunday closes it).
82923
- ***************************************************************/
82924
- function start_of_iso_week(d) {
82925
- let day = d.getDay();
82926
- let back = day === 0 ? 6 : day - 1;
82927
- return new Date(d.getFullYear(), d.getMonth(), d.getDate() - back);
82928
- }
82929
- /***************************************************************
82930
- * The ISO week a date belongs to: {week, year}. The YEAR is the ISO
82931
- * week-year, not the calendar year — 2026-12-31 lives in week 1 of
82932
- * 2027, and a label that said "week 1 2026" would name a week six
82933
- * months away.
82934
- ***************************************************************/
82935
- function iso_week(d) {
82936
- let monday = start_of_iso_week(d);
82937
- let thursday = new Date(monday.getFullYear(), monday.getMonth(), monday.getDate() + 3);
82938
- let jan1 = new Date(thursday.getFullYear(), 0, 1);
82939
- return {
82940
- week: Math.floor((day_number(thursday) - day_number(jan1)) / 7) + 1,
82941
- year: thursday.getFullYear()
82942
- };
82943
- }
82944
- /***************************************************************
82945
- * The index of the ISO week a date falls in, counting weeks from the
82946
- * Monday of the epoch week. It is what aligns a MULTI-week bucket (a
82947
- * fortnight) to a Monday instead of to whatever day 1970-01-01 was.
82948
- ***************************************************************/
82949
- function week_index(d) {
82950
- return Math.floor((day_number(start_of_iso_week(d)) + 3) / 7);
82951
- }
82952
- /***************************
82953
- * Period algebra
82954
- ***************************/
82955
- /***************************************************************
82956
- * Normalize whatever a caller hands us into a spec: an id of the
82957
- * catalog, or a spec of its own. Returns null for anything that is not
82958
- * a bucket (a "span" / "custom" mode of a navigator has no algebra).
82959
- ***************************************************************/
82960
- function period_spec(period) {
82961
- if (!period) return null;
82962
- let spec = typeof period === "string" ? YUI_PERIODS[period] : period;
82963
- if (!spec || !spec.unit) return null;
82964
- if (PERIOD_UNITS.indexOf(spec.unit) < 0) return null;
82965
- let count = parseInt(spec.count, 10);
82966
- if (!(count > 0)) count = 1;
82967
- return {
82968
- id: spec.id || spec.unit,
82969
- unit: spec.unit,
82970
- count
82971
- };
82972
- }
82973
- /***************************************************************
82974
- * The START of the bucket that holds `anchor_ms`, as a local Date.
82975
- *
82976
- * Alignment is what makes a bucket a bucket. Each unit floors against
82977
- * the natural origin of the unit above it, so the boundaries are the
82978
- * ones a human already has in their head:
82979
- *
82980
- * minute -> the hour (a 15min bucket starts at :00/:15/:30/:45)
82981
- * hour -> local midnight (a 6h bucket starts at 00/06/12/18)
82982
- * day -> 1970-01-01 (count=1 is the plain day; a 10-day
82983
- * bucket has no calendar origin to
82984
- * align to, so it aligns to the epoch)
82985
- * week -> the epoch week, Monday-first (ISO)
82986
- * month -> January (which is why 2/3/4/6/12 give calendar
82987
- * bimesters, quarters and semesters)
82988
- * year -> year 0 (a decade starts at 2020, not 2021)
82989
- ***************************************************************/
82990
- function period_start(period, anchor_ms) {
82991
- let spec = period_spec(period);
82992
- if (!spec) return null;
82993
- let d = new Date(anchor_ms);
82994
- let n = spec.count;
82995
- switch (spec.unit) {
82996
- case "minute": {
82997
- let m = Math.floor(d.getMinutes() / n) * n;
82998
- return new Date(d.getFullYear(), d.getMonth(), d.getDate(), d.getHours(), m);
82999
- }
83000
- case "hour": {
83001
- let h = Math.floor(d.getHours() / n) * n;
83002
- return new Date(d.getFullYear(), d.getMonth(), d.getDate(), h);
83003
- }
83004
- case "day": return date_from_day_number(Math.floor(day_number(d) / n) * n);
83005
- case "week": return date_from_day_number(Math.floor(week_index(d) / n) * n * 7 - 3);
83006
- case "month": {
83007
- let mi = d.getFullYear() * 12 + d.getMonth();
83008
- let s = Math.floor(mi / n) * n;
83009
- return new Date(Math.floor(s / 12), s % 12, 1);
83010
- }
83011
- case "year": {
83012
- let y = Math.floor(d.getFullYear() / n) * n;
83013
- return new Date(y, 0, 1);
83014
- }
83015
- default: return null;
83016
- }
83017
- }
83018
- /***************************************************************
83019
- * The start of the bucket `delta` buckets away (delta may be negative).
83020
- * Calendar arithmetic, never millisecond arithmetic: `new Date(y, m+3, 1)`
83021
- * overflows the year by itself, and stepping a day across a DST change
83022
- * keeps landing on midnight.
83023
- ***************************************************************/
83024
- function period_shift(period, anchor_ms, delta) {
83025
- let spec = period_spec(period);
83026
- if (!spec) return anchor_ms;
83027
- let s = period_start(spec, anchor_ms);
83028
- let step = spec.count * (delta || 0);
83029
- switch (spec.unit) {
83030
- case "minute": return new Date(s.getFullYear(), s.getMonth(), s.getDate(), s.getHours(), s.getMinutes() + step).getTime();
83031
- case "hour": return new Date(s.getFullYear(), s.getMonth(), s.getDate(), s.getHours() + step).getTime();
83032
- case "day": return new Date(s.getFullYear(), s.getMonth(), s.getDate() + step).getTime();
83033
- case "week": return new Date(s.getFullYear(), s.getMonth(), s.getDate() + step * 7).getTime();
83034
- case "month": return new Date(s.getFullYear(), s.getMonth() + step, 1).getTime();
83035
- case "year": return new Date(s.getFullYear() + step, 0, 1).getTime();
83036
- default: return anchor_ms;
83037
- }
83038
- }
83039
- /***************************************************************
83040
- * The bucket holding `anchor_ms`, as {from, to} in MILLISECONDS.
83041
- *
83042
- * `to` is INCLUSIVE — the last millisecond of the bucket, not the first
83043
- * of the next one. Both ends of a match condition are inclusive, and an
83044
- * exclusive end handed to one silently swallows the record that landed
83045
- * exactly on the boundary.
83046
- ***************************************************************/
83047
- function period_bounds(period, anchor_ms) {
83048
- let spec = period_spec(period);
83049
- if (!spec) return {
83050
- from: 0,
83051
- to: 0
83052
- };
83053
- return {
83054
- from: period_start(spec, anchor_ms).getTime(),
83055
- to: period_shift(spec, anchor_ms, 1) - 1
83056
- };
83057
- }
83058
- /***************************************************************
83059
- * The same bucket, in the unit the CONSUMER speaks (a tranger topic
83060
- * keeps its timestamps in seconds, unless its system_flag says
83061
- * milliseconds). This is the function a query builder calls.
83062
- ***************************************************************/
83063
- function period_bounds_epoch(period, anchor_ms, ms) {
83064
- let b = period_bounds(period, anchor_ms);
83065
- if (!b.from) return {
83066
- from: 0,
83067
- to: 0
83068
- };
83069
- return {
83070
- from: ms_to_epoch(b.from, ms),
83071
- to: ms_to_epoch(b.to, ms)
83072
- };
83073
- }
83074
- /***************************************************************
83075
- * A ROLLING window: `secs` back from now. Not a bucket — it has no
83076
- * previous and no next, it just ends at `now`.
83077
- *
83078
- * The `to` end is left OPEN (0). An iterator with no upper bound keeps
83079
- * matching the records that land while the card is on screen; pinning
83080
- * it to "now" would freeze the window at the instant the user clicked.
83081
- ***************************************************************/
83082
- function rolling_bounds(rolling, ms, now_ms) {
83083
- let r = typeof rolling === "string" ? YUI_ROLLING[rolling] : rolling;
83084
- if (!r || !r.secs) return {
83085
- from: 0,
83086
- to: 0
83087
- };
83088
- return {
83089
- from: ms_to_epoch((now_ms === void 0 ? Date.now() : now_ms) - r.secs * 1e3, ms),
83090
- to: 0
83091
- };
83092
- }
83093
- /***************************************************************
83094
- * Is this the LAST bucket — the one `now` falls in? It is what greys
83095
- * out the "next" arrow, and what tells the navigator it is already home.
83096
- ***************************************************************/
83097
- function is_current_period(period, anchor_ms, now_ms) {
83098
- let spec = period_spec(period);
83099
- if (!spec) return false;
83100
- let now = now_ms === void 0 ? Date.now() : now_ms;
83101
- let a = period_start(spec, anchor_ms);
83102
- let b = period_start(spec, now);
83103
- return !!a && !!b && a.getTime() === b.getTime();
83104
- }
83105
- /***************************************************************
83106
- * Recognize the bucket a {from, to} pair came from, so a range that
83107
- * travelled through a URL, a saved view or a backend answer comes back
83108
- * as the period the user picked instead of as a hand-typed range.
83109
- *
83110
- * `from`/`to` are in the CONSUMER's unit (`ms`), and so is the
83111
- * comparison — that is the whole trap: a bucket ends on the last
83112
- * MILLISECOND (…23:59:59.999), and a consumer that keeps seconds stored
83113
- * it truncated (…23:59:59). Comparing in milliseconds, a week saved by a
83114
- * seconds-based topic came back as "no bucket at all", every time.
83115
- *
83116
- * Only an EXACT match counts: both ends must land on the bucket's own
83117
- * boundaries, as that consumer would have written them. `candidates` are
83118
- * ids/specs, tried in order. Returns {period, anchor} (anchor in ms) or
83119
- * null.
83120
- ***************************************************************/
83121
- function infer_period(from, to, candidates, ms) {
83122
- if (!from || !to || to <= from) return null;
83123
- let from_ms = epoch_to_ms(from, ms);
83124
- for (let candidate of candidates || Object.keys(YUI_PERIODS)) {
83125
- let spec = period_spec(candidate);
83126
- if (!spec) continue;
83127
- let b = period_bounds_epoch(spec, from_ms, ms);
83128
- if (b.from === from && b.to === to) return {
83129
- period: spec,
83130
- anchor: from_ms
83131
- };
83132
- }
83133
- return null;
83134
- }
83135
- /***************************
83136
- * Period labels
83137
- ***************************/
83138
- /***************************************************************
83139
- * The name of a GRANULARITY (what the segmented control shows):
83140
- * the spec's own id as an i18n key, so an app that declares
83141
- * {id: "quarter"} gets "Trimestre" the moment it adds the key.
83142
- ***************************************************************/
83143
- function period_name(period, t) {
83144
- let spec = period_spec(period);
83145
- if (!spec) return tr(t, String(period && period.id || period || ""));
83146
- return tr(t, spec.id);
83147
- }
83148
- /***************************************************************
83149
- * The name of the bucket a navigator is PARKED on: what goes between
83150
- * the two arrows.
83151
- *
83152
- * day -> "Today" / "Yesterday" / "13 jul 2026"
83153
- * week -> "Week 27" (+ year when it is not this one)
83154
- * month -> "July" (+ year when it is not this one)
83155
- * quarter -> "Q3 2026" (unit month, count 3)
83156
- * semester -> "H2 2026" (unit month, count 6)
83157
- * year -> "2026"
83158
- * decade -> "2020 – 2029"
83159
- * any other -> the bucket's own edges: "1 jul – 31 aug 2026"
83160
- *
83161
- * The named ones are named because a range reads worse than a name;
83162
- * everything an app invents falls back to the range, which is always
83163
- * true and never wrong.
83164
- ***************************************************************/
83165
- function period_label(period, anchor_ms, t, locale) {
83166
- let spec = period_spec(period);
83167
- if (!spec) return "";
83168
- let loc = safe_locale(locale);
83169
- let start = period_start(spec, anchor_ms);
83170
- let end = new Date(period_bounds(spec, anchor_ms).to);
83171
- let now = /* @__PURE__ */ new Date();
83172
- let this_year = start.getFullYear() === now.getFullYear();
83173
- if (spec.unit === "day" && spec.count === 1) {
83174
- let diff = day_number(start) - day_number(now);
83175
- if (diff === 0) return tr(t, "today");
83176
- if (diff === -1) return tr(t, "yesterday");
83177
- if (diff === 1) return tr(t, "tomorrow");
83178
- return fmt_intl(start, loc, this_year ? {
83179
- day: "numeric",
83180
- month: "short"
83181
- } : {
83182
- day: "numeric",
83183
- month: "short",
83184
- year: "numeric"
83185
- });
83186
- }
83187
- if (spec.unit === "hour" && spec.count === 1) {
83188
- let hh = fmt_intl(start, loc, {
83189
- hour: "2-digit",
83190
- minute: "2-digit"
83191
- });
83192
- if (day_number(start) === day_number(now)) return hh;
83193
- return `${hh} · ${fmt_intl(start, loc, {
83194
- day: "numeric",
83195
- month: "short"
83196
- })}`;
83197
- }
83198
- if (spec.unit === "week" && spec.count === 1) {
83199
- let away = week_index(start) - week_index(now);
83200
- if (away === 0) return tr(t, "this week");
83201
- if (away === -1) return tr(t, "last week");
83202
- let w = iso_week(start);
83203
- return w.year === now.getFullYear() ? tr(t, "week {{n}}", { n: w.week }) : tr(t, "week {{n}} {{y}}", {
83204
- n: w.week,
83205
- y: w.year
83206
- });
83207
- }
83208
- if (spec.unit === "month" && spec.count === 1) return fmt_intl(start, loc, this_year ? { month: "long" } : {
83209
- month: "long",
83210
- year: "numeric"
83211
- });
83212
- if (spec.unit === "month" && (spec.count === 3 || spec.count === 6)) {
83213
- let n = Math.floor(start.getMonth() / spec.count) + 1;
83214
- return tr(t, spec.count === 3 ? "quarter {{n}} {{y}}" : "semester {{n}} {{y}}", {
83215
- n,
83216
- y: start.getFullYear()
83217
- });
83218
- }
83219
- if (spec.unit === "year") {
83220
- if (spec.count === 1) return String(start.getFullYear());
83221
- return `${start.getFullYear()} – ${end.getFullYear()}`;
83222
- }
83223
- let opts = spec.unit === "minute" || spec.unit === "hour" ? {
83224
- day: "numeric",
83225
- month: "short",
83226
- hour: "2-digit",
83227
- minute: "2-digit"
83228
- } : {
83229
- day: "numeric",
83230
- month: "short"
83231
- };
83232
- if (start.getFullYear() !== end.getFullYear()) {
83233
- let y_opts = Object.assign({ year: "numeric" }, opts);
83234
- return `${fmt_intl(start, loc, y_opts)} – ${fmt_intl(end, loc, y_opts)}`;
83235
- }
83236
- let span = `${fmt_intl(start, loc, opts)} – ${fmt_intl(end, loc, opts)}`;
83237
- return this_year ? span : `${span} ${start.getFullYear()}`;
83238
- }
83239
- //#endregion
83240
83548
  //#region src/c_yui_period.js
83241
83549
  /***********************************************************************
83242
83550
  * c_yui_period.js
@@ -86191,6 +86499,7 @@ exports.enableElements = enableElements;
86191
86499
  exports.epoch_to_local_input = epoch_to_local_input;
86192
86500
  exports.epoch_to_ms = epoch_to_ms;
86193
86501
  exports.expose_view_container = expose_view_container;
86502
+ exports.fmt_date_time = fmt_date_time;
86194
86503
  exports.fmt_epoch = fmt_epoch;
86195
86504
  exports.getStrokeColor = getStrokeColor;
86196
86505
  exports.infer_period = infer_period;