@yuneta/gobj-ui 7.27.23 → 7.27.25

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.
@@ -17946,8 +17946,8 @@ function load_json(gobj) {
17946
17946
  yui_graph_update_zoom((0, _yuneta_gobj_js.gobj_read_attr)(gobj, "$container"), priv.graph);
17947
17947
  return;
17948
17948
  }
17949
- Promise.resolve(graph.zoomTo(1)).then(() => {
17950
- if (!yui_graph_center_on(graph, priv.anchor_id)) yui_graph_center_on(graph, root_id);
17949
+ Promise.resolve(graph.zoomTo(1)).then(async () => {
17950
+ if (!(priv.anchor_id ? await yui_graph_center_on(graph, priv.anchor_id) : false)) await yui_graph_center_on(graph, root_id);
17951
17951
  priv.last_zoom = 1;
17952
17952
  yui_graph_update_zoom((0, _yuneta_gobj_js.gobj_read_attr)(gobj, "$container"), priv.graph);
17953
17953
  });
@@ -24404,16 +24404,24 @@ function restore_view_state(gobj) {
24404
24404
  let graph = priv.graph;
24405
24405
  let state = load_view_state(gobj);
24406
24406
  if (!graph || !state) return false;
24407
+ let zoom = Number.isFinite(state.zoom) && state.zoom > 0 ? state.zoom : null;
24408
+ let position = Array.isArray(state.position) && state.position.length >= 2 && Number.isFinite(state.position[0]) && Number.isFinite(state.position[1]) ? [state.position[0], state.position[1]] : null;
24409
+ if ((zoom !== null || position !== null) && !camera_shows_a_card(gobj, zoom, position)) {
24410
+ (0, _yuneta_gobj_js.log_warning)(`${(0, _yuneta_gobj_js.gobj_short_name)(gobj)}: the saved view shows none of the ${Object.keys(priv.node_by_id || {}).length} gobjs, framed again`);
24411
+ zoom = null;
24412
+ position = null;
24413
+ priv.view_refused = true;
24414
+ }
24407
24415
  let done = false;
24408
24416
  priv.restoring = true;
24409
24417
  try {
24410
- if (Number.isFinite(state.zoom) && state.zoom > 0) {
24411
- graph.zoomTo(state.zoom);
24412
- priv.last_zoom = state.zoom;
24418
+ if (zoom !== null) {
24419
+ graph.zoomTo(zoom);
24420
+ priv.last_zoom = zoom;
24413
24421
  done = true;
24414
24422
  }
24415
- if (Array.isArray(state.position) && state.position.length >= 2 && Number.isFinite(state.position[0]) && Number.isFinite(state.position[1])) {
24416
- graph.translateTo([state.position[0], state.position[1]]);
24423
+ if (position !== null) {
24424
+ graph.translateTo(position);
24417
24425
  done = true;
24418
24426
  }
24419
24427
  if (state.anchor) {
@@ -24431,6 +24439,30 @@ function restore_view_state(gobj) {
24431
24439
  yui_graph_update_zoom((0, _yuneta_gobj_js.gobj_read_attr)(gobj, "$container"), priv.graph);
24432
24440
  return done;
24433
24441
  }
24442
+ function camera_shows_a_card(gobj, zoom, position) {
24443
+ let priv = gobj.priv;
24444
+ let graph = priv.graph;
24445
+ let ids = Object.keys(priv.node_by_id || {});
24446
+ if (!graph || !ids.length) return true;
24447
+ try {
24448
+ let size = graph.getSize();
24449
+ let c = graph.getCanvasCenter();
24450
+ let z = zoom !== null ? zoom : graph.getZoom();
24451
+ let t = position !== null ? position : graph.getPosition();
24452
+ let w = size[0];
24453
+ let h = size[1];
24454
+ if (!(w > 0 && h > 0) || !(z > 0)) return true;
24455
+ for (let id of ids) {
24456
+ let n = graph.getElementPosition(id);
24457
+ let vx = (n[0] - c[0]) * z + t[0] + c[0];
24458
+ let vy = (n[1] - c[1]) * z + t[1] + c[1];
24459
+ if (vx >= 0 && vx <= w && vy >= 0 && vy <= h) return true;
24460
+ }
24461
+ } catch (e) {
24462
+ return true;
24463
+ }
24464
+ return false;
24465
+ }
24434
24466
  function save_view_state(gobj) {
24435
24467
  let priv = gobj.priv;
24436
24468
  let graph = priv.graph;
@@ -24441,8 +24473,9 @@ function save_view_state(gobj) {
24441
24473
  anchor: priv.anchor_state === "on" ? priv.anchor_name : ""
24442
24474
  };
24443
24475
  let camera = null;
24476
+ let has_nodes = !!priv.node_by_id && Object.keys(priv.node_by_id).length > 0;
24444
24477
  try {
24445
- camera = camera_of(graph.getZoom(), graph.getPosition());
24478
+ camera = has_nodes ? camera_of(graph.getZoom(), graph.getPosition()) : null;
24446
24479
  } catch (e) {}
24447
24480
  if (!camera) {
24448
24481
  let old = load_view_state(gobj);
@@ -24500,7 +24533,8 @@ var PRIVATE_DATA$9 = {
24500
24533
  last_zoom: 1,
24501
24534
  remote_root: null,
24502
24535
  trace_info: {},
24503
- trace_pending: false
24536
+ trace_pending: false,
24537
+ view_refused: false
24504
24538
  };
24505
24539
  var __gclass__$9 = null;
24506
24540
  var __layout_registered__ = false;
@@ -25594,10 +25628,14 @@ function load_tree(gobj) {
25594
25628
  priv.restored = true;
25595
25629
  if (restore_view_state(gobj)) return;
25596
25630
  }
25597
- Promise.resolve(graph.zoomTo(1)).then(() => {
25598
- if (!yui_graph_center_on(graph, priv.anchor_id)) yui_graph_center_on(graph, root_id);
25631
+ Promise.resolve(graph.zoomTo(1)).then(async () => {
25632
+ if (!(priv.anchor_id ? await yui_graph_center_on(graph, priv.anchor_id) : false)) await yui_graph_center_on(graph, root_id);
25599
25633
  priv.last_zoom = 1;
25600
25634
  yui_graph_update_zoom((0, _yuneta_gobj_js.gobj_read_attr)(gobj, "$container"), priv.graph);
25635
+ if (priv.view_refused) {
25636
+ priv.view_refused = false;
25637
+ save_view_state(gobj);
25638
+ }
25601
25639
  });
25602
25640
  });
25603
25641
  }
@@ -43482,8 +43520,8 @@ function _objectWithoutProperties(e, t) {
43482
43520
  /*!
43483
43521
  * @antv/g-lite
43484
43522
  * @description A core module for rendering engine implements DOM API.
43485
- * @version 2.7.0
43486
- * @date 12/24/2025, 11:55:20 AM
43523
+ * @version 2.7.2
43524
+ * @date 10/16/2026, 2:34:22 AM
43487
43525
  * @author AntVis
43488
43526
  * @docs https://g.antv.antgroup.com/
43489
43527
  */
@@ -43954,12 +43992,13 @@ function getAngle(angle) {
43954
43992
  }
43955
43993
  var $vec3$3 = create$3();
43956
43994
  function createVec3(x) {
43995
+ var _x$, _x$2, _x$3, _x$4;
43957
43996
  var y = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 0;
43958
43997
  var z = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : 0;
43959
43998
  var clone$2 = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : true;
43960
43999
  if (Array.isArray(x) && x.length === 3) return clone$2 ? clone(x) : copy$3($vec3$3, x);
43961
44000
  if (isNumber(x)) return clone$2 ? fromValues$2(x, y, z) : set$3($vec3$3, x, y, z);
43962
- return clone$2 ? fromValues$2(x[0], x[1] || y, x[2] || z) : set$3($vec3$3, x[0], x[1] || y, x[2] || z);
44001
+ return clone$2 ? fromValues$2(x[0], (_x$ = x[1]) !== null && _x$ !== void 0 ? _x$ : y, (_x$2 = x[2]) !== null && _x$2 !== void 0 ? _x$2 : z) : set$3($vec3$3, x[0], (_x$3 = x[1]) !== null && _x$3 !== void 0 ? _x$3 : y, (_x$4 = x[2]) !== null && _x$4 !== void 0 ? _x$4 : z);
43963
44002
  }
43964
44003
  var DEG_RAD = Math.PI / 180;
43965
44004
  function deg2rad(deg) {
@@ -50218,7 +50257,7 @@ var FederatedEvent = /*#__PURE__*/ function() {
50218
50257
  }
50219
50258
  ]);
50220
50259
  }();
50221
- var FederatedMouseEvent = /*#__PURE__*/ function(_ref) {
50260
+ var FederatedMouseEvent = /*#__PURE__*/ function(_FederatedEvent) {
50222
50261
  function FederatedMouseEvent() {
50223
50262
  var _this;
50224
50263
  _classCallCheck(this, FederatedMouseEvent);
@@ -50254,7 +50293,7 @@ var FederatedMouseEvent = /*#__PURE__*/ function(_ref) {
50254
50293
  _this.screen = new Point();
50255
50294
  return _this;
50256
50295
  }
50257
- _inherits(FederatedMouseEvent, _ref);
50296
+ _inherits(FederatedMouseEvent, _FederatedEvent);
50258
50297
  return _createClass(FederatedMouseEvent, [
50259
50298
  {
50260
50299
  key: "clientX",
@@ -54907,9 +54946,18 @@ var PrepareRendererPlugin = /*#__PURE__*/ function() {
54907
54946
  renderingService.dirty();
54908
54947
  };
54909
54948
  var handleBoundsChanged = function handleBoundsChanged(e) {
54910
- var _this$mutationRecords;
54911
54949
  var records = e.detail;
54912
- (_this$mutationRecords = _this.mutationRecords).push.apply(_this$mutationRecords, _toConsumableArray(records));
54950
+ var _iterator = _createForOfIteratorHelper(records), _step;
54951
+ try {
54952
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
54953
+ var record = _step.value;
54954
+ _this.mutationRecords.push(record);
54955
+ }
54956
+ } catch (err) {
54957
+ _iterator.e(err);
54958
+ } finally {
54959
+ _iterator.f();
54960
+ }
54913
54961
  renderingService.dirty();
54914
54962
  };
54915
54963
  var handleMounted = function handleMounted(e) {
@@ -55910,8 +55958,8 @@ PERFORMANCE OF THIS SOFTWARE.
55910
55958
  /*!
55911
55959
  * @antv/g
55912
55960
  * @description A core module for rendering engine implements DOM API.
55913
- * @version 6.3.1
55914
- * @date 12/24/2025, 11:55:39 AM
55961
+ * @version 6.3.3
55962
+ * @date 10/16/2026, 2:34:40 AM
55915
55963
  * @author AntVis
55916
55964
  * @docs https://g.antv.antgroup.com/
55917
55965
  */
@@ -63073,74 +63121,43 @@ var Animation = /*#__PURE__*/ function() {
63073
63121
  /**
63074
63122
  * https://github.com/gre/bezier-easing
63075
63123
  * BezierEasing - use bezier curve for transition easing function
63076
- * by Gaëtan Renaudeau 2014 - 2015 – MIT License
63124
+ * by Gaëtan Renaudeau 2014 - 2026 – MIT License
63077
63125
  */
63078
- var NEWTON_ITERATIONS = 4;
63079
- var NEWTON_MIN_SLOPE = .001;
63080
- var SUBDIVISION_PRECISION = 1e-7;
63081
- var SUBDIVISION_MAX_ITERATIONS = 10;
63082
- var kSplineTableSize = 11;
63083
- var kSampleStepSize = 1 / (kSplineTableSize - 1);
63084
- var float32ArraySupported = typeof Float32Array === "function";
63085
- var A = function A(aA1, aA2) {
63086
- return 1 - 3 * aA2 + 3 * aA1;
63087
- };
63088
- var B = function B(aA1, aA2) {
63089
- return 3 * aA2 - 6 * aA1;
63090
- };
63091
- var C = function C(aA1) {
63092
- return 3 * aA1;
63093
- };
63094
- var calcBezier = function calcBezier(aT, aA1, aA2) {
63095
- return ((A(aA1, aA2) * aT + B(aA1, aA2)) * aT + C(aA1)) * aT;
63096
- };
63097
- var getSlope = function getSlope(aT, aA1, aA2) {
63098
- return 3 * A(aA1, aA2) * aT * aT + 2 * B(aA1, aA2) * aT + C(aA1);
63099
- };
63100
- var binarySubdivide = function binarySubdivide(aX, aA, aB, mX1, mX2) {
63101
- var currentX;
63102
- var currentT;
63103
- var i = 0;
63104
- do {
63105
- currentT = aA + (aB - aA) / 2;
63106
- currentX = calcBezier(currentT, mX1, mX2) - aX;
63107
- if (currentX > 0) aB = currentT;
63108
- else aA = currentT;
63109
- } while (Math.abs(currentX) > SUBDIVISION_PRECISION && ++i < SUBDIVISION_MAX_ITERATIONS);
63110
- return currentT;
63111
- };
63112
- var newtonRaphsonIterate = function newtonRaphsonIterate(aX, aGuessT, mX1, mX2) {
63113
- for (var i = 0; i < NEWTON_ITERATIONS; ++i) {
63114
- var currentSlope = getSlope(aGuessT, mX1, mX2);
63115
- if (currentSlope === 0) return aGuessT;
63116
- var currentX = calcBezier(aGuessT, mX1, mX2) - aX;
63117
- aGuessT -= currentX / currentSlope;
63118
- }
63119
- return aGuessT;
63126
+ var solveTForX = function solveTForX(x, a, b, c) {
63127
+ var j = 1 / Math.max(c, Math.sqrt(x));
63128
+ var k = x * j;
63129
+ var l = k * j;
63130
+ var s = c * j;
63131
+ var q = b * l;
63132
+ var m = s * s + q;
63133
+ var h = -s * (s * s + 1.5 * q) - a * k * l;
63134
+ var D = h * h - m * m * m;
63135
+ var v;
63136
+ if (m === 0 || D > 1e-12 * h * h) {
63137
+ var U = -Math.cbrt(h < 0 ? h - Math.sqrt(D) : h + Math.sqrt(D));
63138
+ v = U + m / U || 0;
63139
+ } else {
63140
+ var r = Math.sqrt(m);
63141
+ v = 2 * r * Math.cos(Math.acos(Math.max(-1, Math.min(1, -h / (m * r)))) / 3);
63142
+ }
63143
+ return Math.min(1, k / (v + s));
63120
63144
  };
63121
63145
  var bezier = function bezier(mX1, mY1, mX2, mY2) {
63122
63146
  if (!(mX1 >= 0 && mX1 <= 1 && mX2 >= 0 && mX2 <= 1)) throw new Error("bezier x values must be in [0, 1] range");
63123
63147
  if (mX1 === mY1 && mX2 === mY2) return function(t) {
63124
63148
  return t;
63125
63149
  };
63126
- var sampleValues = float32ArraySupported ? new Float32Array(kSplineTableSize) : new Array(kSplineTableSize);
63127
- for (var i = 0; i < kSplineTableSize; ++i) sampleValues[i] = calcBezier(i * kSampleStepSize, mX1, mX2);
63128
- var getTForX = function getTForX(aX) {
63129
- var intervalStart = 0;
63130
- var currentSample = 1;
63131
- var lastSample = kSplineTableSize - 1;
63132
- for (; currentSample !== lastSample && sampleValues[currentSample] <= aX; ++currentSample) intervalStart += kSampleStepSize;
63133
- --currentSample;
63134
- var dist = (aX - sampleValues[currentSample]) / (sampleValues[currentSample + 1] - sampleValues[currentSample]);
63135
- var guessForT = intervalStart + dist * kSampleStepSize;
63136
- var initialSlope = getSlope(guessForT, mX1, mX2);
63137
- if (initialSlope >= NEWTON_MIN_SLOPE) return newtonRaphsonIterate(aX, guessForT, mX1, mX2);
63138
- if (initialSlope === 0) return guessForT;
63139
- return binarySubdivide(aX, intervalStart, intervalStart + kSampleStepSize, mX1, mX2);
63140
- };
63150
+ var a = (3 * mX1 - 3 * mX2 + 1) / 2;
63151
+ var b = mX2 - 2 * mX1;
63152
+ var c = mX1;
63153
+ var ay = 3 * mY1 - 3 * mY2 + 1;
63154
+ var by = 3 * (mY2 - 2 * mY1);
63155
+ var cy = 3 * mY1;
63141
63156
  return function(t) {
63142
- if (t === 0 || t === 1) return t;
63143
- return calcBezier(getTForX(t), mY1, mY2);
63157
+ if (t <= 0) return 0;
63158
+ if (t >= 1) return 1;
63159
+ var u = solveTForX(t, a, b, c);
63160
+ return ((ay * u + by) * u + cy) * u;
63144
63161
  };
63145
63162
  };
63146
63163
  var convertToDash = function convertToDash(str) {
@@ -63882,9 +63899,11 @@ var AnimationTimeline = /*#__PURE__*/ function() {
63882
63899
  if (t < Number(_this.currentTime)) t = Number(_this.currentTime);
63883
63900
  _this.animations.sort(compareAnimations);
63884
63901
  _this.animations = _this.tick(t, true, _this.animations)[0];
63902
+ _this.updateAnimationsPromises();
63885
63903
  processing.forEach(function(entry) {
63886
63904
  entry[1](t);
63887
63905
  });
63906
+ _this.updateAnimationsPromises();
63888
63907
  _this.applyPendingEffects();
63889
63908
  };
63890
63909
  this.document = document;
@@ -63994,18 +64013,13 @@ var AnimationTimeline = /*#__PURE__*/ function() {
63994
64013
  {
63995
64014
  key: "requestAnimationFrame",
63996
64015
  value: function requestAnimationFrame(f) {
63997
- var _this3 = this;
63998
- return this.rAF(function(x) {
63999
- _this3.updateAnimationsPromises();
64000
- f(x);
64001
- _this3.updateAnimationsPromises();
64002
- });
64016
+ return this.rAF(f);
64003
64017
  }
64004
64018
  },
64005
64019
  {
64006
64020
  key: "tick",
64007
64021
  value: function tick(t, isAnimationFrame, updatingAnimations) {
64008
- var _this4 = this, _this$pendingEffects, _this$pendingEffects2;
64022
+ var _this3 = this, _this$pendingEffects, _this$pendingEffects2;
64009
64023
  this.inTick = true;
64010
64024
  this.hasRestartedThisFrame = false;
64011
64025
  this.currentTime = t;
@@ -64023,7 +64037,7 @@ var AnimationTimeline = /*#__PURE__*/ function() {
64023
64037
  newPendingEffects.push(animation.effect);
64024
64038
  animation.markTarget();
64025
64039
  }
64026
- if (animation._needsTick) _this4.ticking = true;
64040
+ if (animation._needsTick) _this3.ticking = true;
64027
64041
  var alive = animation._inEffect || animation._needsTick;
64028
64042
  animation._inTimeline = alive;
64029
64043
  if (alive) activeAnimations.push(animation);
@@ -17941,8 +17941,8 @@ function load_json(gobj) {
17941
17941
  yui_graph_update_zoom(gobj_read_attr(gobj, "$container"), priv.graph);
17942
17942
  return;
17943
17943
  }
17944
- Promise.resolve(graph.zoomTo(1)).then(() => {
17945
- if (!yui_graph_center_on(graph, priv.anchor_id)) yui_graph_center_on(graph, root_id);
17944
+ Promise.resolve(graph.zoomTo(1)).then(async () => {
17945
+ if (!(priv.anchor_id ? await yui_graph_center_on(graph, priv.anchor_id) : false)) await yui_graph_center_on(graph, root_id);
17946
17946
  priv.last_zoom = 1;
17947
17947
  yui_graph_update_zoom(gobj_read_attr(gobj, "$container"), priv.graph);
17948
17948
  });
@@ -24399,16 +24399,24 @@ function restore_view_state(gobj) {
24399
24399
  let graph = priv.graph;
24400
24400
  let state = load_view_state(gobj);
24401
24401
  if (!graph || !state) return false;
24402
+ let zoom = Number.isFinite(state.zoom) && state.zoom > 0 ? state.zoom : null;
24403
+ let position = Array.isArray(state.position) && state.position.length >= 2 && Number.isFinite(state.position[0]) && Number.isFinite(state.position[1]) ? [state.position[0], state.position[1]] : null;
24404
+ if ((zoom !== null || position !== null) && !camera_shows_a_card(gobj, zoom, position)) {
24405
+ log_warning(`${gobj_short_name(gobj)}: the saved view shows none of the ${Object.keys(priv.node_by_id || {}).length} gobjs, framed again`);
24406
+ zoom = null;
24407
+ position = null;
24408
+ priv.view_refused = true;
24409
+ }
24402
24410
  let done = false;
24403
24411
  priv.restoring = true;
24404
24412
  try {
24405
- if (Number.isFinite(state.zoom) && state.zoom > 0) {
24406
- graph.zoomTo(state.zoom);
24407
- priv.last_zoom = state.zoom;
24413
+ if (zoom !== null) {
24414
+ graph.zoomTo(zoom);
24415
+ priv.last_zoom = zoom;
24408
24416
  done = true;
24409
24417
  }
24410
- if (Array.isArray(state.position) && state.position.length >= 2 && Number.isFinite(state.position[0]) && Number.isFinite(state.position[1])) {
24411
- graph.translateTo([state.position[0], state.position[1]]);
24418
+ if (position !== null) {
24419
+ graph.translateTo(position);
24412
24420
  done = true;
24413
24421
  }
24414
24422
  if (state.anchor) {
@@ -24426,6 +24434,30 @@ function restore_view_state(gobj) {
24426
24434
  yui_graph_update_zoom(gobj_read_attr(gobj, "$container"), priv.graph);
24427
24435
  return done;
24428
24436
  }
24437
+ function camera_shows_a_card(gobj, zoom, position) {
24438
+ let priv = gobj.priv;
24439
+ let graph = priv.graph;
24440
+ let ids = Object.keys(priv.node_by_id || {});
24441
+ if (!graph || !ids.length) return true;
24442
+ try {
24443
+ let size = graph.getSize();
24444
+ let c = graph.getCanvasCenter();
24445
+ let z = zoom !== null ? zoom : graph.getZoom();
24446
+ let t = position !== null ? position : graph.getPosition();
24447
+ let w = size[0];
24448
+ let h = size[1];
24449
+ if (!(w > 0 && h > 0) || !(z > 0)) return true;
24450
+ for (let id of ids) {
24451
+ let n = graph.getElementPosition(id);
24452
+ let vx = (n[0] - c[0]) * z + t[0] + c[0];
24453
+ let vy = (n[1] - c[1]) * z + t[1] + c[1];
24454
+ if (vx >= 0 && vx <= w && vy >= 0 && vy <= h) return true;
24455
+ }
24456
+ } catch (e) {
24457
+ return true;
24458
+ }
24459
+ return false;
24460
+ }
24429
24461
  function save_view_state(gobj) {
24430
24462
  let priv = gobj.priv;
24431
24463
  let graph = priv.graph;
@@ -24436,8 +24468,9 @@ function save_view_state(gobj) {
24436
24468
  anchor: priv.anchor_state === "on" ? priv.anchor_name : ""
24437
24469
  };
24438
24470
  let camera = null;
24471
+ let has_nodes = !!priv.node_by_id && Object.keys(priv.node_by_id).length > 0;
24439
24472
  try {
24440
- camera = camera_of(graph.getZoom(), graph.getPosition());
24473
+ camera = has_nodes ? camera_of(graph.getZoom(), graph.getPosition()) : null;
24441
24474
  } catch (e) {}
24442
24475
  if (!camera) {
24443
24476
  let old = load_view_state(gobj);
@@ -24495,7 +24528,8 @@ var PRIVATE_DATA$9 = {
24495
24528
  last_zoom: 1,
24496
24529
  remote_root: null,
24497
24530
  trace_info: {},
24498
- trace_pending: false
24531
+ trace_pending: false,
24532
+ view_refused: false
24499
24533
  };
24500
24534
  var __gclass__$9 = null;
24501
24535
  var __layout_registered__ = false;
@@ -25589,10 +25623,14 @@ function load_tree(gobj) {
25589
25623
  priv.restored = true;
25590
25624
  if (restore_view_state(gobj)) return;
25591
25625
  }
25592
- Promise.resolve(graph.zoomTo(1)).then(() => {
25593
- if (!yui_graph_center_on(graph, priv.anchor_id)) yui_graph_center_on(graph, root_id);
25626
+ Promise.resolve(graph.zoomTo(1)).then(async () => {
25627
+ if (!(priv.anchor_id ? await yui_graph_center_on(graph, priv.anchor_id) : false)) await yui_graph_center_on(graph, root_id);
25594
25628
  priv.last_zoom = 1;
25595
25629
  yui_graph_update_zoom(gobj_read_attr(gobj, "$container"), priv.graph);
25630
+ if (priv.view_refused) {
25631
+ priv.view_refused = false;
25632
+ save_view_state(gobj);
25633
+ }
25596
25634
  });
25597
25635
  });
25598
25636
  }
@@ -43477,8 +43515,8 @@ function _objectWithoutProperties(e, t) {
43477
43515
  /*!
43478
43516
  * @antv/g-lite
43479
43517
  * @description A core module for rendering engine implements DOM API.
43480
- * @version 2.7.0
43481
- * @date 12/24/2025, 11:55:20 AM
43518
+ * @version 2.7.2
43519
+ * @date 10/16/2026, 2:34:22 AM
43482
43520
  * @author AntVis
43483
43521
  * @docs https://g.antv.antgroup.com/
43484
43522
  */
@@ -43949,12 +43987,13 @@ function getAngle(angle) {
43949
43987
  }
43950
43988
  var $vec3$3 = create$3();
43951
43989
  function createVec3(x) {
43990
+ var _x$, _x$2, _x$3, _x$4;
43952
43991
  var y = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 0;
43953
43992
  var z = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : 0;
43954
43993
  var clone$2 = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : true;
43955
43994
  if (Array.isArray(x) && x.length === 3) return clone$2 ? clone(x) : copy$3($vec3$3, x);
43956
43995
  if (isNumber(x)) return clone$2 ? fromValues$2(x, y, z) : set$3($vec3$3, x, y, z);
43957
- return clone$2 ? fromValues$2(x[0], x[1] || y, x[2] || z) : set$3($vec3$3, x[0], x[1] || y, x[2] || z);
43996
+ return clone$2 ? fromValues$2(x[0], (_x$ = x[1]) !== null && _x$ !== void 0 ? _x$ : y, (_x$2 = x[2]) !== null && _x$2 !== void 0 ? _x$2 : z) : set$3($vec3$3, x[0], (_x$3 = x[1]) !== null && _x$3 !== void 0 ? _x$3 : y, (_x$4 = x[2]) !== null && _x$4 !== void 0 ? _x$4 : z);
43958
43997
  }
43959
43998
  var DEG_RAD = Math.PI / 180;
43960
43999
  function deg2rad(deg) {
@@ -50213,7 +50252,7 @@ var FederatedEvent = /*#__PURE__*/ function() {
50213
50252
  }
50214
50253
  ]);
50215
50254
  }();
50216
- var FederatedMouseEvent = /*#__PURE__*/ function(_ref) {
50255
+ var FederatedMouseEvent = /*#__PURE__*/ function(_FederatedEvent) {
50217
50256
  function FederatedMouseEvent() {
50218
50257
  var _this;
50219
50258
  _classCallCheck(this, FederatedMouseEvent);
@@ -50249,7 +50288,7 @@ var FederatedMouseEvent = /*#__PURE__*/ function(_ref) {
50249
50288
  _this.screen = new Point();
50250
50289
  return _this;
50251
50290
  }
50252
- _inherits(FederatedMouseEvent, _ref);
50291
+ _inherits(FederatedMouseEvent, _FederatedEvent);
50253
50292
  return _createClass(FederatedMouseEvent, [
50254
50293
  {
50255
50294
  key: "clientX",
@@ -54902,9 +54941,18 @@ var PrepareRendererPlugin = /*#__PURE__*/ function() {
54902
54941
  renderingService.dirty();
54903
54942
  };
54904
54943
  var handleBoundsChanged = function handleBoundsChanged(e) {
54905
- var _this$mutationRecords;
54906
54944
  var records = e.detail;
54907
- (_this$mutationRecords = _this.mutationRecords).push.apply(_this$mutationRecords, _toConsumableArray(records));
54945
+ var _iterator = _createForOfIteratorHelper(records), _step;
54946
+ try {
54947
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
54948
+ var record = _step.value;
54949
+ _this.mutationRecords.push(record);
54950
+ }
54951
+ } catch (err) {
54952
+ _iterator.e(err);
54953
+ } finally {
54954
+ _iterator.f();
54955
+ }
54908
54956
  renderingService.dirty();
54909
54957
  };
54910
54958
  var handleMounted = function handleMounted(e) {
@@ -55905,8 +55953,8 @@ PERFORMANCE OF THIS SOFTWARE.
55905
55953
  /*!
55906
55954
  * @antv/g
55907
55955
  * @description A core module for rendering engine implements DOM API.
55908
- * @version 6.3.1
55909
- * @date 12/24/2025, 11:55:39 AM
55956
+ * @version 6.3.3
55957
+ * @date 10/16/2026, 2:34:40 AM
55910
55958
  * @author AntVis
55911
55959
  * @docs https://g.antv.antgroup.com/
55912
55960
  */
@@ -63068,74 +63116,43 @@ var Animation = /*#__PURE__*/ function() {
63068
63116
  /**
63069
63117
  * https://github.com/gre/bezier-easing
63070
63118
  * BezierEasing - use bezier curve for transition easing function
63071
- * by Gaëtan Renaudeau 2014 - 2015 – MIT License
63119
+ * by Gaëtan Renaudeau 2014 - 2026 – MIT License
63072
63120
  */
63073
- var NEWTON_ITERATIONS = 4;
63074
- var NEWTON_MIN_SLOPE = .001;
63075
- var SUBDIVISION_PRECISION = 1e-7;
63076
- var SUBDIVISION_MAX_ITERATIONS = 10;
63077
- var kSplineTableSize = 11;
63078
- var kSampleStepSize = 1 / (kSplineTableSize - 1);
63079
- var float32ArraySupported = typeof Float32Array === "function";
63080
- var A = function A(aA1, aA2) {
63081
- return 1 - 3 * aA2 + 3 * aA1;
63082
- };
63083
- var B = function B(aA1, aA2) {
63084
- return 3 * aA2 - 6 * aA1;
63085
- };
63086
- var C = function C(aA1) {
63087
- return 3 * aA1;
63088
- };
63089
- var calcBezier = function calcBezier(aT, aA1, aA2) {
63090
- return ((A(aA1, aA2) * aT + B(aA1, aA2)) * aT + C(aA1)) * aT;
63091
- };
63092
- var getSlope = function getSlope(aT, aA1, aA2) {
63093
- return 3 * A(aA1, aA2) * aT * aT + 2 * B(aA1, aA2) * aT + C(aA1);
63094
- };
63095
- var binarySubdivide = function binarySubdivide(aX, aA, aB, mX1, mX2) {
63096
- var currentX;
63097
- var currentT;
63098
- var i = 0;
63099
- do {
63100
- currentT = aA + (aB - aA) / 2;
63101
- currentX = calcBezier(currentT, mX1, mX2) - aX;
63102
- if (currentX > 0) aB = currentT;
63103
- else aA = currentT;
63104
- } while (Math.abs(currentX) > SUBDIVISION_PRECISION && ++i < SUBDIVISION_MAX_ITERATIONS);
63105
- return currentT;
63106
- };
63107
- var newtonRaphsonIterate = function newtonRaphsonIterate(aX, aGuessT, mX1, mX2) {
63108
- for (var i = 0; i < NEWTON_ITERATIONS; ++i) {
63109
- var currentSlope = getSlope(aGuessT, mX1, mX2);
63110
- if (currentSlope === 0) return aGuessT;
63111
- var currentX = calcBezier(aGuessT, mX1, mX2) - aX;
63112
- aGuessT -= currentX / currentSlope;
63113
- }
63114
- return aGuessT;
63121
+ var solveTForX = function solveTForX(x, a, b, c) {
63122
+ var j = 1 / Math.max(c, Math.sqrt(x));
63123
+ var k = x * j;
63124
+ var l = k * j;
63125
+ var s = c * j;
63126
+ var q = b * l;
63127
+ var m = s * s + q;
63128
+ var h = -s * (s * s + 1.5 * q) - a * k * l;
63129
+ var D = h * h - m * m * m;
63130
+ var v;
63131
+ if (m === 0 || D > 1e-12 * h * h) {
63132
+ var U = -Math.cbrt(h < 0 ? h - Math.sqrt(D) : h + Math.sqrt(D));
63133
+ v = U + m / U || 0;
63134
+ } else {
63135
+ var r = Math.sqrt(m);
63136
+ v = 2 * r * Math.cos(Math.acos(Math.max(-1, Math.min(1, -h / (m * r)))) / 3);
63137
+ }
63138
+ return Math.min(1, k / (v + s));
63115
63139
  };
63116
63140
  var bezier = function bezier(mX1, mY1, mX2, mY2) {
63117
63141
  if (!(mX1 >= 0 && mX1 <= 1 && mX2 >= 0 && mX2 <= 1)) throw new Error("bezier x values must be in [0, 1] range");
63118
63142
  if (mX1 === mY1 && mX2 === mY2) return function(t) {
63119
63143
  return t;
63120
63144
  };
63121
- var sampleValues = float32ArraySupported ? new Float32Array(kSplineTableSize) : new Array(kSplineTableSize);
63122
- for (var i = 0; i < kSplineTableSize; ++i) sampleValues[i] = calcBezier(i * kSampleStepSize, mX1, mX2);
63123
- var getTForX = function getTForX(aX) {
63124
- var intervalStart = 0;
63125
- var currentSample = 1;
63126
- var lastSample = kSplineTableSize - 1;
63127
- for (; currentSample !== lastSample && sampleValues[currentSample] <= aX; ++currentSample) intervalStart += kSampleStepSize;
63128
- --currentSample;
63129
- var dist = (aX - sampleValues[currentSample]) / (sampleValues[currentSample + 1] - sampleValues[currentSample]);
63130
- var guessForT = intervalStart + dist * kSampleStepSize;
63131
- var initialSlope = getSlope(guessForT, mX1, mX2);
63132
- if (initialSlope >= NEWTON_MIN_SLOPE) return newtonRaphsonIterate(aX, guessForT, mX1, mX2);
63133
- if (initialSlope === 0) return guessForT;
63134
- return binarySubdivide(aX, intervalStart, intervalStart + kSampleStepSize, mX1, mX2);
63135
- };
63145
+ var a = (3 * mX1 - 3 * mX2 + 1) / 2;
63146
+ var b = mX2 - 2 * mX1;
63147
+ var c = mX1;
63148
+ var ay = 3 * mY1 - 3 * mY2 + 1;
63149
+ var by = 3 * (mY2 - 2 * mY1);
63150
+ var cy = 3 * mY1;
63136
63151
  return function(t) {
63137
- if (t === 0 || t === 1) return t;
63138
- return calcBezier(getTForX(t), mY1, mY2);
63152
+ if (t <= 0) return 0;
63153
+ if (t >= 1) return 1;
63154
+ var u = solveTForX(t, a, b, c);
63155
+ return ((ay * u + by) * u + cy) * u;
63139
63156
  };
63140
63157
  };
63141
63158
  var convertToDash = function convertToDash(str) {
@@ -63877,9 +63894,11 @@ var AnimationTimeline = /*#__PURE__*/ function() {
63877
63894
  if (t < Number(_this.currentTime)) t = Number(_this.currentTime);
63878
63895
  _this.animations.sort(compareAnimations);
63879
63896
  _this.animations = _this.tick(t, true, _this.animations)[0];
63897
+ _this.updateAnimationsPromises();
63880
63898
  processing.forEach(function(entry) {
63881
63899
  entry[1](t);
63882
63900
  });
63901
+ _this.updateAnimationsPromises();
63883
63902
  _this.applyPendingEffects();
63884
63903
  };
63885
63904
  this.document = document;
@@ -63989,18 +64008,13 @@ var AnimationTimeline = /*#__PURE__*/ function() {
63989
64008
  {
63990
64009
  key: "requestAnimationFrame",
63991
64010
  value: function requestAnimationFrame(f) {
63992
- var _this3 = this;
63993
- return this.rAF(function(x) {
63994
- _this3.updateAnimationsPromises();
63995
- f(x);
63996
- _this3.updateAnimationsPromises();
63997
- });
64011
+ return this.rAF(f);
63998
64012
  }
63999
64013
  },
64000
64014
  {
64001
64015
  key: "tick",
64002
64016
  value: function tick(t, isAnimationFrame, updatingAnimations) {
64003
- var _this4 = this, _this$pendingEffects, _this$pendingEffects2;
64017
+ var _this3 = this, _this$pendingEffects, _this$pendingEffects2;
64004
64018
  this.inTick = true;
64005
64019
  this.hasRestartedThisFrame = false;
64006
64020
  this.currentTime = t;
@@ -64018,7 +64032,7 @@ var AnimationTimeline = /*#__PURE__*/ function() {
64018
64032
  newPendingEffects.push(animation.effect);
64019
64033
  animation.markTarget();
64020
64034
  }
64021
- if (animation._needsTick) _this4.ticking = true;
64035
+ if (animation._needsTick) _this3.ticking = true;
64022
64036
  var alive = animation._inEffect || animation._needsTick;
64023
64037
  animation._inTimeline = alive;
64024
64038
  if (alive) activeAnimations.push(animation);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yuneta/gobj-ui",
3
- "version": "7.27.23",
3
+ "version": "7.27.25",
4
4
  "type": "module",
5
5
  "main": "dist/gobj-ui.cjs.js",
6
6
  "module": "dist/gobj-ui.es.js",
@@ -35,6 +35,9 @@
35
35
  "prepublishOnly": "npm run build"
36
36
  },
37
37
  "dependencies": {
38
+ "@antv/g": "^6.3.3",
39
+ "@antv/g-canvas": "^2.2.2",
40
+ "@antv/g-plugin-dragndrop": "^2.1.3",
38
41
  "acorn": "^8.19.0"
39
42
  },
40
43
  "devDependencies": {
@@ -242,19 +242,38 @@ function restore_view_state(gobj)
242
242
  return false;
243
243
  }
244
244
 
245
+ /* A camera saved by an older version can hold nulls (a NaN written
246
+ * as json): what is not a number is not restored. */
247
+ let zoom = (Number.isFinite(state.zoom) && state.zoom > 0)? state.zoom: null;
248
+ let position = (Array.isArray(state.position) && state.position.length >= 2 &&
249
+ Number.isFinite(state.position[0]) && Number.isFinite(state.position[1]))?
250
+ [state.position[0], state.position[1]]: null;
251
+
252
+ /* Nor a camera that would show none of the tree. One was saved from
253
+ * an EMPTY graph -- a remote tree is empty until its host loads it,
254
+ * and a fit pressed then frames nothing -- and every opening after
255
+ * it went back to the same blank canvas. It is judged from the
256
+ * numbers BEFORE it is applied, so a refused camera never moves the
257
+ * graph: the opening frames the tree as a first one does, and the
258
+ * next move saves a good camera. */
259
+ if((zoom !== null || position !== null) && !camera_shows_a_card(gobj, zoom, position)) {
260
+ log_warning(`${gobj_short_name(gobj)}: the saved view shows none of the ` +
261
+ `${Object.keys(priv.node_by_id || {}).length} gobjs, framed again`);
262
+ zoom = null;
263
+ position = null;
264
+ priv.view_refused = true; /* the framing saves its camera over it */
265
+ }
266
+
245
267
  let done = false;
246
268
  priv.restoring = true;
247
269
  try {
248
- /* A camera saved by an older version can hold nulls (a NaN
249
- * written as json): what is not a number is not restored. */
250
- if(Number.isFinite(state.zoom) && state.zoom > 0) {
251
- graph.zoomTo(state.zoom);
252
- priv.last_zoom = state.zoom;
270
+ if(zoom !== null) {
271
+ graph.zoomTo(zoom);
272
+ priv.last_zoom = zoom;
253
273
  done = true;
254
274
  }
255
- if(Array.isArray(state.position) && state.position.length >= 2 &&
256
- Number.isFinite(state.position[0]) && Number.isFinite(state.position[1])) {
257
- graph.translateTo([state.position[0], state.position[1]]);
275
+ if(position !== null) {
276
+ graph.translateTo(position);
258
277
  done = true;
259
278
  }
260
279
  if(state.anchor) {
@@ -276,6 +295,46 @@ function restore_view_state(gobj)
276
295
  return done;
277
296
  }
278
297
 
298
+ /* Would the centre of at least one card land inside the canvas under
299
+ * this camera? `zoom` and `position` are what getZoom()/getPosition()
300
+ * answer (a null one: the current). A camera absolute-translated to T
301
+ * at zoom Z puts a point n of the graph at (n - C) * Z + T + C on the
302
+ * canvas, C its centre -- the closed form of G6's own
303
+ * getTranslateOptions(), the one yui_graph_center_on() relies on.
304
+ * True when there is nothing to show or it cannot be computed: only a
305
+ * camera KNOWN to show nothing is refused. */
306
+ function camera_shows_a_card(gobj, zoom, position)
307
+ {
308
+ let priv = gobj.priv;
309
+ let graph = priv.graph;
310
+ let ids = Object.keys(priv.node_by_id || {});
311
+ if(!graph || !ids.length) {
312
+ return true;
313
+ }
314
+ try {
315
+ let size = graph.getSize();
316
+ let c = graph.getCanvasCenter();
317
+ let z = (zoom !== null)? zoom: graph.getZoom();
318
+ let t = (position !== null)? position: graph.getPosition();
319
+ let w = size[0];
320
+ let h = size[1];
321
+ if(!(w > 0 && h > 0) || !(z > 0)) {
322
+ return true;
323
+ }
324
+ for(let id of ids) {
325
+ let n = graph.getElementPosition(id);
326
+ let vx = (n[0] - c[0]) * z + t[0] + c[0];
327
+ let vy = (n[1] - c[1]) * z + t[1] + c[1];
328
+ if(vx >= 0 && vx <= w && vy >= 0 && vy <= h) {
329
+ return true;
330
+ }
331
+ }
332
+ } catch(e) {
333
+ return true;
334
+ }
335
+ return false;
336
+ }
337
+
279
338
  function save_view_state(gobj)
280
339
  {
281
340
  let priv = gobj.priv;
@@ -291,8 +350,13 @@ function save_view_state(gobj)
291
350
  anchor: (priv.anchor_state === "on")? priv.anchor_name: "",
292
351
  };
293
352
  let camera = null;
353
+ /* The camera of an EMPTY graph frames nothing: a remote tree before
354
+ * its host loads it, where a fit or a zoom would save a view of no
355
+ * card that every later opening goes back to. Not saved; the one
356
+ * saved before stays (below). */
357
+ let has_nodes = !!priv.node_by_id && Object.keys(priv.node_by_id).length > 0;
294
358
  try {
295
- camera = camera_of(graph.getZoom(), graph.getPosition());
359
+ camera = has_nodes ? camera_of(graph.getZoom(), graph.getPosition()) : null;
296
360
  } catch(e) {
297
361
  /* between renders: keep the rest, the camera is not readable */
298
362
  }
@@ -383,6 +447,7 @@ let PRIVATE_DATA = {
383
447
  remote_root: null, // the descriptor of the backend tree, as last loaded
384
448
  trace_info: {}, // gclass -> {gclass_levels, global_levels, gclass_on, global_on, error}
385
449
  trace_pending: false, // a trace was set: the block is locked until the host answers
450
+ view_refused: false, // the saved camera showed no card: the opening's framing replaces it
386
451
  };
387
452
 
388
453
  let __gclass__ = null;
@@ -1815,12 +1880,28 @@ function load_tree(gobj)
1815
1880
  * -- never parked at the layout's origin, which is a
1816
1881
  * corner with nothing in it.
1817
1882
  */
1818
- Promise.resolve(graph.zoomTo(1)).then(() => {
1819
- if(!yui_graph_center_on(graph, priv.anchor_id)) {
1820
- yui_graph_center_on(graph, root_id);
1883
+ Promise.resolve(graph.zoomTo(1)).then(async () => {
1884
+ /* yui_graph_center_on() is ASYNC: unawaited, its answer
1885
+ * is a promise, always truthy, so `!` of it was always
1886
+ * false and the root was never centred -- the opening
1887
+ * stayed wherever the camera happened to be. (And the
1888
+ * root is at y = 0, a camera coordinate @antv/g-lite
1889
+ * below 2.7.2 could not reach: its createVec3() read
1890
+ * `x[1] || y`, so a 0 kept the old value. package.json
1891
+ * holds the antv floors that bring 2.7.2.) */
1892
+ let on_anchor = priv.anchor_id?
1893
+ await yui_graph_center_on(graph, priv.anchor_id): false;
1894
+ if(!on_anchor) {
1895
+ await yui_graph_center_on(graph, root_id);
1821
1896
  }
1822
1897
  priv.last_zoom = 1;
1823
1898
  yui_graph_update_zoom(gobj_read_attr(gobj, "$container"), priv.graph);
1899
+ /* A refused camera is replaced now, not at the reader's
1900
+ * next move: left saved, every opening refused it again. */
1901
+ if(priv.view_refused) {
1902
+ priv.view_refused = false;
1903
+ save_view_state(gobj);
1904
+ }
1824
1905
  });
1825
1906
  });
1826
1907
  }
@@ -1520,9 +1520,15 @@ function load_json(gobj)
1520
1520
  * -- never parked at the layout's origin, which is a corner
1521
1521
  * with nothing in it and is where `1:1` used to land.
1522
1522
  */
1523
- Promise.resolve(graph.zoomTo(1)).then(() => {
1524
- if(!yui_graph_center_on(graph, priv.anchor_id)) {
1525
- yui_graph_center_on(graph, root_id);
1523
+ Promise.resolve(graph.zoomTo(1)).then(async () => {
1524
+ /* yui_graph_center_on() is ASYNC: unawaited, its answer
1525
+ * is a promise, always truthy, so `!` of it was always
1526
+ * false and the root was never centred -- the opening
1527
+ * stayed wherever the camera happened to be. */
1528
+ let on_anchor = priv.anchor_id?
1529
+ await yui_graph_center_on(graph, priv.anchor_id): false;
1530
+ if(!on_anchor) {
1531
+ await yui_graph_center_on(graph, root_id);
1526
1532
  }
1527
1533
  priv.last_zoom = 1;
1528
1534
  yui_graph_update_zoom(gobj_read_attr(gobj, "$container"), priv.graph);
@@ -30,7 +30,8 @@ if(typeof globalThis.ResizeObserver === "undefined") {
30
30
  };
31
31
  }
32
32
 
33
- const camera = vi.hoisted(() => ({zoom: NaN, position: [NaN, NaN], zoomed: [], moved: []}));
33
+ const camera = vi.hoisted(() => ({zoom: NaN, position: [NaN, NaN], zoomed: [], moved: [],
34
+ size: null, viewport: null}));
34
35
  vi.mock("@antv/g6", async (importOriginal) => {
35
36
  const real = await importOriginal();
36
37
  class FakeGraph {
@@ -62,6 +63,27 @@ vi.mock("@antv/g6", async (importOriginal) => {
62
63
  camera.moved.push(p);
63
64
  return Promise.resolve();
64
65
  }
66
+ /* Where a card lands on screen: `camera.viewport` for every one
67
+ * of them, and the canvas `camera.size`. Unset, the camera cannot
68
+ * be read, which is what the older tests expect. */
69
+ getSize() {
70
+ if(!camera.size) {
71
+ throw new Error("no size");
72
+ }
73
+ return camera.size;
74
+ }
75
+ getElementPosition() {
76
+ return [0, 0];
77
+ }
78
+ getElementData() {
79
+ return {};
80
+ }
81
+ getCanvasCenter() {
82
+ return [400, 300];
83
+ }
84
+ getViewportByCanvas() {
85
+ return camera.viewport;
86
+ }
65
87
  getData() {
66
88
  return {nodes: [], edges: [], combos: []};
67
89
  }
@@ -122,6 +144,8 @@ beforeEach(() => {
122
144
  camera.position = [NaN, NaN];
123
145
  camera.zoomed = [];
124
146
  camera.moved = [];
147
+ camera.size = null;
148
+ camera.viewport = null;
125
149
  });
126
150
 
127
151
  function errors()
@@ -183,3 +207,55 @@ describe("C_YUI_GOBJ_TREE_JS saves only a camera of numbers", () => {
183
207
  expect(errors()).toEqual([]);
184
208
  });
185
209
  });
210
+
211
+ describe("C_YUI_GOBJ_TREE_JS does not restore a camera that shows nothing", () => {
212
+ test("a saved camera with every card off the canvas is framed again", async () => {
213
+ const name = `camera_${++seq}`;
214
+ window.localStorage.setItem(`yui_gobj_tree_view:${name}`,
215
+ JSON.stringify({layout: "", collapsed: {}, anchor: "", zoom: 0.18, position: [-20000, -20000]}));
216
+ camera.size = [800, 600];
217
+ camera.viewport = [-5000, -5000];
218
+ /* what G6 answers once the opening has framed the tree */
219
+ camera.zoom = 1;
220
+ camera.position = [5, 6];
221
+ await mount(name);
222
+ await new Promise((resolve) => setTimeout(resolve, 0));
223
+ /* judged before it is applied: only the opening's own framing */
224
+ expect(camera.zoomed).toEqual([1]);
225
+ /* and the refused camera is replaced by the framing's, so the
226
+ * next opening does not refuse it again */
227
+ expect(saved(name)).toMatchObject({zoom: 1, position: [5, 6]});
228
+ expect(logged.filter((l) => l.level === "warning").map((l) => l.msg).join(" "))
229
+ .toMatch(/the saved view shows none of the/);
230
+ expect(errors()).toEqual([]);
231
+ });
232
+
233
+ test("a saved camera that shows a card is kept", async () => {
234
+ const name = `camera_${++seq}`;
235
+ window.localStorage.setItem(`yui_gobj_tree_view:${name}`,
236
+ JSON.stringify({layout: "", collapsed: {}, anchor: "", zoom: 0.5, position: [10, 20]}));
237
+ camera.size = [800, 600];
238
+ camera.viewport = [400, 300];
239
+ await mount(name);
240
+ await new Promise((resolve) => setTimeout(resolve, 0));
241
+ expect(camera.zoomed).toEqual([0.5]);
242
+ expect(camera.moved).toEqual([[10, 20]]);
243
+ expect(errors()).toEqual([]);
244
+ });
245
+ });
246
+
247
+ describe("C_YUI_GOBJ_TREE_JS opens centred on its root", () => {
248
+ test("with nothing saved, the camera is moved onto the root", async () => {
249
+ /* yui_graph_center_on() is async, and its answer was read
250
+ * unawaited -- a promise, always truthy -- so the root was never
251
+ * centred and the opening stayed where the camera happened to be. */
252
+ const name = `camera_${++seq}`;
253
+ camera.viewport = [0, 0]; /* the root, 400x300 off the centre */
254
+ await mount(name);
255
+ await new Promise((resolve) => setTimeout(resolve, 0));
256
+ expect(camera.zoomed).toEqual([1]);
257
+ expect(camera.moved.length).toBeGreaterThan(0);
258
+ expect(camera.moved[0]).toEqual([400, 300]);
259
+ expect(errors()).toEqual([]);
260
+ });
261
+ });
@@ -295,4 +295,20 @@ describe("C_YUI_GOBJ_TREE_JS, source local", () => {
295
295
  expect(wanted).toEqual([]);
296
296
  expect(problems()).toEqual([]);
297
297
  });
298
+
299
+ test("an empty graph saves no camera: a fit before the tree loads frames nothing", async () => {
300
+ const view = await mount("remote", host);
301
+ const key = `yui_gobj_tree_view:tree_${seq}`;
302
+ gobj_send_event(view, "EV_REFRESH", {}, view);
303
+ const saved = JSON.parse(window.localStorage.getItem(key) || "null");
304
+ expect(saved).not.toBe(null);
305
+ expect("zoom" in saved).toBe(false);
306
+ expect("position" in saved).toBe(false);
307
+
308
+ gobj_send_event(view, "EV_LOAD_TREE", {tree: TREE}, host);
309
+ gobj_send_event(view, "EV_REFRESH", {}, view);
310
+ const after = JSON.parse(window.localStorage.getItem(key));
311
+ expect(after.zoom).toBe(1);
312
+ expect(problems()).toEqual([]);
313
+ });
298
314
  });