@meursyphus/flitter 0.0.6 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -351,7 +351,7 @@ var lerp_default = lerp;
351
351
  // src/utils/getTextSize.ts
352
352
  var OFFSET = 20;
353
353
  var SCALE = 100;
354
- var defaultWidthMapStr = `007LLmW'55;N0500LLLLLLLLLL00NNNLzWW\\\\WQb\\0FWLg\\bWb\\WQ\\WrWWQ000CL5LLFLL0LL**F*gLLLL5F0LF\\FFF5.5N`;
354
+ var defaultWidthMapStr = "007LLmW'55;N0500LLLLLLLLLL00NNNLzWW\\\\WQb\\0FWLg\\bWb\\WQ\\WrWWQ000CL5LLFLL0LL**F*gLLLL5F0LF\\FFF5.5N";
355
355
  var DEFAULT_FONT_SIZE = 12;
356
356
  var DEFAULT_FONT_FAMILY = "sans-serif";
357
357
  var DEFAULT_FONT = `${DEFAULT_FONT_SIZE}px ${DEFAULT_FONT_FAMILY}`;
@@ -414,18 +414,6 @@ function createUniqueId() {
414
414
  return (id++).toString();
415
415
  }
416
416
 
417
- // src/utils/TypedObject.ts
418
- function entries(obj) {
419
- return Object.entries(obj);
420
- }
421
- function keys(obj) {
422
- return Object.keys(obj);
423
- }
424
- var TypedObject_default = {
425
- entries,
426
- keys
427
- };
428
-
429
417
  // src/utils/index.ts
430
418
  var _Utils = class _Utils {
431
419
  static sum(values) {
@@ -11960,6 +11948,14 @@ var ToolTipPosition = /* @__PURE__ */ ((ToolTipPosition2) => {
11960
11948
  return ToolTipPosition2;
11961
11949
  })(ToolTipPosition || {});
11962
11950
 
11951
+ // src/exception/index.ts
11952
+ var NotImplementedError = class extends Error {
11953
+ constructor(method) {
11954
+ super(`${method} is not implemented`);
11955
+ this.name = "NotImplementedError";
11956
+ }
11957
+ };
11958
+
11963
11959
  // src/renderobject/RenderObject.ts
11964
11960
  var _domNode, _domOrder, _domOrderChanged;
11965
11961
  var RenderObject = class {
@@ -11996,8 +11992,11 @@ var RenderObject = class {
11996
11992
  set domOrder(newOrder) {
11997
11993
  if (newOrder === __privateGet(this, _domOrder))
11998
11994
  return;
11999
- __privateSet(this, _domOrderChanged, true);
12000
11995
  __privateSet(this, _domOrder, newOrder);
11996
+ this.didDomOrderChange();
11997
+ }
11998
+ didDomOrderChange() {
11999
+ __privateSet(this, _domOrderChanged, true);
12001
12000
  }
12002
12001
  get domNode() {
12003
12002
  assert(__privateGet(this, _domNode) != null, "domNode is not initialized");
@@ -12091,7 +12090,7 @@ var RenderObject = class {
12091
12090
  this.ownerElement = ownerElement;
12092
12091
  this.depth = ownerElement.depth;
12093
12092
  if (this.isPainter) {
12094
- this.mountSvgEl(this.renderOwner.paintContext);
12093
+ this.mountSvgEl(this.renderOwner.renderContext.paintContext);
12095
12094
  this.renderOwner.didDomOrderChange();
12096
12095
  }
12097
12096
  }
@@ -12125,8 +12124,8 @@ var RenderObject = class {
12125
12124
  resolveSvgEl() {
12126
12125
  const container = this.domNode;
12127
12126
  const svgEls = {};
12128
- for (let i = 0; i < container.children.length; i++) {
12129
- const child = container.children[i];
12127
+ for (const element of container.children) {
12128
+ const child = element;
12130
12129
  const name = child.getAttribute("data-render-name");
12131
12130
  svgEls[name] = child;
12132
12131
  }
@@ -12135,7 +12134,10 @@ var RenderObject = class {
12135
12134
  rearrangeDomOrder() {
12136
12135
  if (!__privateGet(this, _domOrderChanged))
12137
12136
  return;
12138
- this.isPainter && this.renderOwner.paintContext.insertSvgEl(this.domNode, this.domOrder);
12137
+ this.isPainter && this.renderOwner.renderContext.paintContext.insertSvgEl(
12138
+ this.domNode,
12139
+ this.domOrder
12140
+ );
12139
12141
  __privateSet(this, _domOrderChanged, false);
12140
12142
  }
12141
12143
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -12147,7 +12149,7 @@ var RenderObject = class {
12147
12149
  */
12148
12150
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
12149
12151
  preformLayout() {
12150
- throw { message: "not implemented performLayout" };
12152
+ throw new NotImplementedError("performLayout");
12151
12153
  }
12152
12154
  /*
12153
12155
  * Do not call this method directly. instead call paint
@@ -12196,12 +12198,22 @@ var RenderObject = class {
12196
12198
  });
12197
12199
  }
12198
12200
  /**
12199
- *
12200
12201
  * It is currently only used on ZIndexRenderObject
12201
12202
  */
12202
12203
  accept(visitor) {
12203
12204
  visitor.visitGeneral(this);
12204
12205
  }
12206
+ hitTest({ globalPoint }) {
12207
+ const viewPort = this.renderOwner.renderContext.viewPort;
12208
+ const { translation, scale } = viewPort;
12209
+ const bounds = {
12210
+ left: (this.matrix.storage[12] + translation.x) * scale,
12211
+ top: (this.matrix.storage[13] + translation.y) * scale,
12212
+ right: (this.matrix.storage[12] + translation.x + this.size.width) * scale,
12213
+ bottom: (this.matrix.storage[13] + translation.y + this.size.height) * scale
12214
+ };
12215
+ return globalPoint.x >= bounds.left && globalPoint.x <= bounds.right && globalPoint.y >= bounds.top && globalPoint.y <= bounds.bottom;
12216
+ }
12205
12217
  };
12206
12218
  _domNode = new WeakMap();
12207
12219
  _domOrder = new WeakMap();
@@ -12226,9 +12238,7 @@ var RenderView = class extends RenderObject_default {
12226
12238
  width: constraint.maxWidth,
12227
12239
  height: constraint.maxHeight
12228
12240
  });
12229
- this.children.forEach(
12230
- (child) => child.layout(constraints_default.loose(this.size))
12231
- );
12241
+ this.children.forEach((child) => child.layout(constraints_default.loose(this.size)));
12232
12242
  }
12233
12243
  paint(context, clipId, matrix4, opacity) {
12234
12244
  if (this.size.width === 0 || this.size.height === 0)
@@ -12429,7 +12439,7 @@ var RenderObjectElement = class extends Element_default {
12429
12439
  }
12430
12440
  findAncestorRenderObjectElement() {
12431
12441
  let ancestor = this.parent;
12432
- while (ancestor != null && !(ancestor.type === "render")) {
12442
+ while (ancestor != null && ancestor.type !== "render") {
12433
12443
  ancestor = ancestor.parent;
12434
12444
  }
12435
12445
  return ancestor;
@@ -12463,7 +12473,6 @@ var RenderObjectToWidgetAdapter = class extends RenderObjectWidget_default {
12463
12473
  app,
12464
12474
  renderOwner,
12465
12475
  buildOwner,
12466
- renderContext,
12467
12476
  scheduler
12468
12477
  }) {
12469
12478
  super({ children: [app] });
@@ -12473,7 +12482,7 @@ var RenderObjectToWidgetAdapter = class extends RenderObjectWidget_default {
12473
12482
  __publicField(this, "scheduler");
12474
12483
  this.renderOwner = renderOwner;
12475
12484
  this.buildOwner = buildOwner;
12476
- this.renderContext = renderContext;
12485
+ this.renderContext = renderOwner.renderContext;
12477
12486
  this.scheduler = scheduler;
12478
12487
  }
12479
12488
  createElement() {
@@ -12486,8 +12495,8 @@ var RenderObjectToWidgetAdapter = class extends RenderObjectWidget_default {
12486
12495
  createRenderObject() {
12487
12496
  return new RenderView_default({ renderOwner: this.renderOwner });
12488
12497
  }
12489
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
12490
12498
  updateRenderObject(renderObject) {
12499
+ renderObject.renderOwner = this.renderOwner;
12491
12500
  }
12492
12501
  };
12493
12502
  var RenderObjectToWidgetAdapter_default = RenderObjectToWidgetAdapter;
@@ -12531,9 +12540,11 @@ var BuildOwner_default = BuildOwner;
12531
12540
  var RenderOwner = class {
12532
12541
  constructor({
12533
12542
  onNeedVisualUpdate,
12534
- paintContext
12543
+ renderContext,
12544
+ hitTestDispatcher
12535
12545
  }) {
12536
- __publicField(this, "paintContext");
12546
+ __publicField(this, "hitTestDispatcher");
12547
+ __publicField(this, "renderContext");
12537
12548
  __publicField(this, "onNeedVisualUpdate");
12538
12549
  __publicField(this, "needsPaintRenderObjects", []);
12539
12550
  __publicField(this, "needsLayoutRenderObjects", []);
@@ -12543,7 +12554,9 @@ var RenderOwner = class {
12543
12554
  __publicField(this, "renderView");
12544
12555
  __publicField(this, "domOrderChanged", true);
12545
12556
  this.onNeedVisualUpdate = onNeedVisualUpdate;
12546
- this.paintContext = paintContext;
12557
+ this.renderContext = renderContext;
12558
+ this.hitTestDispatcher = hitTestDispatcher;
12559
+ this.hitTestDispatcher.init({ renderContext: this.renderContext });
12547
12560
  }
12548
12561
  requestVisualUpdate() {
12549
12562
  this.onNeedVisualUpdate();
@@ -12584,7 +12597,7 @@ var RenderOwner = class {
12584
12597
  dirties.sort((a, b) => a.depth - b.depth).forEach((renderObject) => {
12585
12598
  if (!renderObject.needsPaint)
12586
12599
  return;
12587
- renderObject.paintWithoutLayout(this.paintContext);
12600
+ renderObject.paintWithoutLayout(this.renderContext.paintContext);
12588
12601
  });
12589
12602
  }
12590
12603
  };
@@ -12670,6 +12683,12 @@ var Scheduler = class {
12670
12683
  this.persistenceCallbacks = [];
12671
12684
  this.postFrameCallbacks = [];
12672
12685
  }
12686
+ consumePostCallbacks() {
12687
+ this.postFrameCallbacks.forEach((callback) => {
12688
+ callback();
12689
+ });
12690
+ this.postFrameCallbacks = [];
12691
+ }
12673
12692
  schedule() {
12674
12693
  switch (this.phase) {
12675
12694
  case 0 /* idle */:
@@ -12686,9 +12705,7 @@ var Scheduler = class {
12686
12705
  callback();
12687
12706
  });
12688
12707
  this.phase = 2 /* postFrameCallbacks */;
12689
- this.postFrameCallbacks.forEach((callback) => {
12690
- callback();
12691
- });
12708
+ this.consumePostCallbacks();
12692
12709
  this.postFrameCallbacks = [];
12693
12710
  this.phase = 0 /* idle */;
12694
12711
  }
@@ -12705,25 +12722,25 @@ var Scheduler_default = Scheduler;
12705
12722
  var RenderFrameDispatcher = class {
12706
12723
  constructor({ onFrame } = {}) {
12707
12724
  __publicField(this, "onFrame");
12725
+ // Actually we don't need to invoke browser to render because browser automatically render its own state periodically
12726
+ // so Here we just call onFrame callback.
12727
+ __publicField(this, "idle", true);
12708
12728
  this.onFrame = onFrame;
12709
12729
  }
12710
12730
  setOnFrame(callback) {
12711
12731
  this.onFrame = () => callback();
12712
12732
  }
12713
- // Actually we dont need to invoke browser to render because browser automatically render its own state periodically
12714
- // so Here we just call onFrame callback.
12715
12733
  dispatch() {
12716
- if (typeof window === "undefined") {
12717
- setTimeout(() => {
12718
- var _a;
12719
- (_a = this.onFrame) == null ? void 0 : _a.call(this);
12720
- }, 0);
12721
- } else {
12722
- window.requestAnimationFrame(() => {
12723
- var _a;
12724
- (_a = this.onFrame) == null ? void 0 : _a.call(this);
12725
- });
12726
- }
12734
+ if (typeof window === "undefined")
12735
+ return;
12736
+ if (!this.idle)
12737
+ return;
12738
+ this.idle = false;
12739
+ window.requestAnimationFrame(() => {
12740
+ var _a;
12741
+ (_a = this.onFrame) == null ? void 0 : _a.call(this);
12742
+ this.idle = true;
12743
+ });
12727
12744
  }
12728
12745
  };
12729
12746
  var RenderFrameDispatcher_default = RenderFrameDispatcher;
@@ -12744,6 +12761,154 @@ var GlobalKey = class {
12744
12761
  };
12745
12762
  var Globalkey_default = GlobalKey;
12746
12763
 
12764
+ // src/hit-test/HitTestDispatcher.ts
12765
+ var _activated, _detectors, _rootPosition, _renderContext, _hitPosition, _handleMouseDown, _handleClick, _hitHistory, _handleMouseMove, _handleMouseUp, _handleMouseWheel, _handleMouseEnter, _handleMouseLeave, _wrapEvent, _didDomOrderChangeState;
12766
+ var HitTestDispatcher = class {
12767
+ constructor() {
12768
+ __privateAdd(this, _activated, typeof window !== "undefined");
12769
+ __privateAdd(this, _detectors, []);
12770
+ __privateAdd(this, _rootPosition, null);
12771
+ __privateAdd(this, _renderContext, void 0);
12772
+ __privateAdd(this, _hitPosition, new offset_default({ x: 0, y: 0 }));
12773
+ __privateAdd(this, _handleMouseDown, (e) => {
12774
+ this.hitTest(e, "onMouseDown");
12775
+ });
12776
+ __privateAdd(this, _handleClick, (e) => {
12777
+ this.hitTest(e, "onClick");
12778
+ });
12779
+ __privateAdd(this, _hitHistory, []);
12780
+ __privateAdd(this, _handleMouseMove, (e) => {
12781
+ this.traceHitPosition(e);
12782
+ this.hitTest(e, "onMouseMove");
12783
+ e.isPropagationStopped = false;
12784
+ for (const i in __privateGet(this, _detectors)) {
12785
+ const detector = __privateGet(this, _detectors)[i];
12786
+ if (e.isPropagationStopped)
12787
+ return;
12788
+ if (!__privateGet(this, _hitHistory)[i] && detector.hitTest({ globalPoint: __privateGet(this, _hitPosition) })) {
12789
+ detector.onMouseEnter(e);
12790
+ }
12791
+ }
12792
+ e.isPropagationStopped = false;
12793
+ for (const i in __privateGet(this, _detectors)) {
12794
+ const detector = __privateGet(this, _detectors)[i];
12795
+ if (e.isPropagationStopped)
12796
+ return;
12797
+ if (__privateGet(this, _hitHistory)[i] && !detector.hitTest({ globalPoint: __privateGet(this, _hitPosition) })) {
12798
+ detector.onMouseLeave(e);
12799
+ }
12800
+ }
12801
+ __privateGet(this, _detectors).forEach((detector, i) => {
12802
+ __privateGet(this, _hitHistory)[i] = detector.hitTest({
12803
+ globalPoint: __privateGet(this, _hitPosition)
12804
+ });
12805
+ });
12806
+ });
12807
+ __privateAdd(this, _handleMouseUp, (e) => {
12808
+ this.hitTest(e, "onMouseUp");
12809
+ });
12810
+ __privateAdd(this, _handleMouseWheel, (e) => {
12811
+ this.hitTest(e, "onMouseWheel");
12812
+ e.isPropagationStopped = false;
12813
+ for (const detector of __privateGet(this, _detectors)) {
12814
+ if (e.isPropagationStopped)
12815
+ return;
12816
+ if (!detector.hitTest({ globalPoint: __privateGet(this, _hitPosition) }))
12817
+ continue;
12818
+ detector.onMouseEnter(e);
12819
+ }
12820
+ e.isPropagationStopped = false;
12821
+ });
12822
+ __privateAdd(this, _handleMouseEnter, () => {
12823
+ const rect = __privateGet(this, _renderContext).view.getBoundingClientRect();
12824
+ __privateSet(this, _rootPosition, new offset_default({
12825
+ x: rect.left,
12826
+ y: rect.top
12827
+ }));
12828
+ });
12829
+ __privateAdd(this, _handleMouseLeave, () => {
12830
+ __privateSet(this, _rootPosition, null);
12831
+ });
12832
+ __publicField(this, "hitTest", (e, type) => {
12833
+ for (const detector of __privateGet(this, _detectors)) {
12834
+ if (e.isPropagationStopped)
12835
+ return;
12836
+ if (!detector.hitTest({ globalPoint: __privateGet(this, _hitPosition) }))
12837
+ continue;
12838
+ detector[type](e);
12839
+ }
12840
+ });
12841
+ __privateAdd(this, _wrapEvent, (callback) => (e) => {
12842
+ const stopPropagation = e.stopPropagation;
12843
+ e.stopPropagation = function() {
12844
+ e.isPropagationStopped = true;
12845
+ stopPropagation.call(e);
12846
+ };
12847
+ return callback(e);
12848
+ });
12849
+ /**
12850
+ * This code is for batch processing. The intention is not to perform the sorting operation every time this method is called,
12851
+ * but rather to ensure that the sorting happens only once in a batch manner. This is achieved by wrapping the sorting logic
12852
+ * inside a setTimeout, which defers the execution until the current call stack is clear, effectively coalescing multiple calls
12853
+ * into a single operation.
12854
+ */
12855
+ __privateAdd(this, _didDomOrderChangeState, "idle");
12856
+ }
12857
+ init({ renderContext }) {
12858
+ if (!__privateGet(this, _activated))
12859
+ return;
12860
+ __privateSet(this, _renderContext, renderContext);
12861
+ const { view } = __privateGet(this, _renderContext);
12862
+ view.addEventListener("mousedown", __privateGet(this, _wrapEvent).call(this, __privateGet(this, _handleMouseDown)));
12863
+ view.addEventListener("click", __privateGet(this, _wrapEvent).call(this, __privateGet(this, _handleClick)));
12864
+ view.addEventListener("mousemove", __privateGet(this, _wrapEvent).call(this, __privateGet(this, _handleMouseMove)));
12865
+ view.addEventListener("mouseup", __privateGet(this, _wrapEvent).call(this, __privateGet(this, _handleMouseUp)));
12866
+ view.addEventListener("wheel", __privateGet(this, _wrapEvent).call(this, __privateGet(this, _handleMouseWheel)));
12867
+ view.addEventListener("mouseenter", __privateGet(this, _handleMouseEnter));
12868
+ view.addEventListener("mouseleave", __privateGet(this, _handleMouseLeave));
12869
+ }
12870
+ traceHitPosition(e) {
12871
+ if (__privateGet(this, _rootPosition) == null)
12872
+ return;
12873
+ __privateGet(this, _hitPosition).x = e.clientX - __privateGet(this, _rootPosition).x;
12874
+ __privateGet(this, _hitPosition).y = e.clientY - __privateGet(this, _rootPosition).y;
12875
+ }
12876
+ didChangeDomOrder() {
12877
+ if (__privateGet(this, _didDomOrderChangeState) === "processing")
12878
+ return;
12879
+ __privateSet(this, _didDomOrderChangeState, "processing");
12880
+ setTimeout(() => {
12881
+ __privateSet(this, _detectors, __privateGet(this, _detectors).sort((a, b) => b.domOrder - a.domOrder));
12882
+ __privateSet(this, _didDomOrderChangeState, "idle");
12883
+ }, 0);
12884
+ }
12885
+ addDetector(detector) {
12886
+ if (!__privateGet(this, _activated))
12887
+ return;
12888
+ __privateGet(this, _detectors).push(detector);
12889
+ }
12890
+ removeDetector(detector) {
12891
+ if (!__privateGet(this, _activated))
12892
+ return;
12893
+ __privateSet(this, _detectors, __privateGet(this, _detectors).filter((d) => d !== detector));
12894
+ }
12895
+ };
12896
+ _activated = new WeakMap();
12897
+ _detectors = new WeakMap();
12898
+ _rootPosition = new WeakMap();
12899
+ _renderContext = new WeakMap();
12900
+ _hitPosition = new WeakMap();
12901
+ _handleMouseDown = new WeakMap();
12902
+ _handleClick = new WeakMap();
12903
+ _hitHistory = new WeakMap();
12904
+ _handleMouseMove = new WeakMap();
12905
+ _handleMouseUp = new WeakMap();
12906
+ _handleMouseWheel = new WeakMap();
12907
+ _handleMouseEnter = new WeakMap();
12908
+ _handleMouseLeave = new WeakMap();
12909
+ _wrapEvent = new WeakMap();
12910
+ _didDomOrderChangeState = new WeakMap();
12911
+
12747
12912
  // src/runApp.ts
12748
12913
  var AppRunner = class {
12749
12914
  constructor({
@@ -12758,14 +12923,22 @@ var AppRunner = class {
12758
12923
  __publicField(this, "buildOwner");
12759
12924
  __publicField(this, "renderOwner");
12760
12925
  __publicField(this, "scheduler");
12761
- __publicField(this, "renderDispatcher");
12762
12926
  __publicField(this, "didRun", false);
12763
12927
  __publicField(this, "widget");
12928
+ __publicField(this, "handleViewResize", (size) => {
12929
+ this.viewSize = size;
12930
+ if (this.didRun) {
12931
+ this.draw();
12932
+ } else {
12933
+ this.runApp(this.widget);
12934
+ }
12935
+ });
12764
12936
  this.viewSize = ssrSize;
12765
12937
  const renderContext = new RenderContext({
12766
12938
  view,
12767
12939
  document: _document,
12768
- window: _window
12940
+ window: _window,
12941
+ onResize: this.handleViewResize
12769
12942
  });
12770
12943
  const renderDispatcher = new RenderFrameDispatcher_default();
12771
12944
  const buildOwner = new BuildOwner_default({
@@ -12773,7 +12946,8 @@ var AppRunner = class {
12773
12946
  });
12774
12947
  const renderOwner = new RenderOwner_default({
12775
12948
  onNeedVisualUpdate: () => renderDispatcher.dispatch(),
12776
- paintContext: renderContext.paintContext
12949
+ renderContext,
12950
+ hitTestDispatcher: new HitTestDispatcher()
12777
12951
  });
12778
12952
  const scheduler = new Scheduler_default();
12779
12953
  scheduler.addPersistenceCallbacks(() => buildOwner.flushBuild());
@@ -12782,18 +12956,16 @@ var AppRunner = class {
12782
12956
  this.buildOwner = buildOwner;
12783
12957
  this.renderOwner = renderOwner;
12784
12958
  this.scheduler = scheduler;
12785
- this.renderDispatcher = renderDispatcher;
12786
12959
  this.renderContext = renderContext;
12787
12960
  }
12788
12961
  runApp(widget) {
12789
12962
  this.widget = widget;
12790
12963
  if (this.viewSize == null)
12791
- return ``;
12964
+ return "";
12792
12965
  this.root = new RenderObjectToWidgetAdapter_default({
12793
12966
  app: widget,
12794
12967
  buildOwner: this.buildOwner,
12795
12968
  renderOwner: this.renderOwner,
12796
- renderContext: this.renderContext,
12797
12969
  scheduler: this.scheduler
12798
12970
  }).createElement();
12799
12971
  this.root.mount(void 0);
@@ -12813,7 +12985,7 @@ var AppRunner = class {
12813
12985
  this.renderContext.window = window2;
12814
12986
  if (view)
12815
12987
  this.renderContext.view = view;
12816
- this.renderOwner.paintContext = this.renderContext.paintContext;
12988
+ this.renderOwner.renderContext = this.renderContext;
12817
12989
  }
12818
12990
  onMount({
12819
12991
  view,
@@ -12824,28 +12996,13 @@ var AppRunner = class {
12824
12996
  window,
12825
12997
  document
12826
12998
  });
12827
- resizeTarget && this.observeCanvasSize(resizeTarget);
12828
- }
12829
- observeCanvasSize(target) {
12830
- const resize = (child) => {
12831
- const { width, height } = child.target.getBoundingClientRect();
12832
- this.viewSize = new size_default({ width, height });
12833
- };
12834
- const resizeObserver = new ResizeObserver((entries2) => {
12835
- const child = entries2[0];
12836
- resize(child);
12837
- if (this.didRun) {
12838
- this.draw();
12839
- } else {
12840
- this.runApp(this.widget);
12841
- }
12842
- });
12843
- resizeObserver.observe(target);
12999
+ resizeTarget && this.renderContext.observeSize(resizeTarget);
12844
13000
  }
12845
13001
  draw() {
12846
13002
  this.layout();
12847
13003
  this.renderOwner.rearrangeDomOrder();
12848
13004
  this.paint();
13005
+ this.scheduler.consumePostCallbacks();
12849
13006
  }
12850
13007
  rebuild() {
12851
13008
  this.root.children[0].rebuild();
@@ -12858,19 +13015,42 @@ var AppRunner = class {
12858
13015
  const rootRenderObject = this.root.renderObject;
12859
13016
  rootRenderObject.paint(this.renderContext.paintContext);
12860
13017
  }
13018
+ dispose() {
13019
+ this.root.unmount();
13020
+ this.renderContext.dispose();
13021
+ }
12861
13022
  };
12862
13023
  var RenderContext = class {
12863
13024
  constructor({
12864
13025
  document: document2,
12865
13026
  window: window2,
12866
- view
13027
+ view,
13028
+ onResize
12867
13029
  }) {
12868
13030
  __publicField(this, "document");
12869
13031
  __publicField(this, "window");
12870
13032
  __publicField(this, "view");
13033
+ __publicField(this, "viewPort", {
13034
+ translation: { x: 0, y: 0 },
13035
+ scale: 1
13036
+ });
13037
+ __publicField(this, "viewSize", new size_default({ width: 0, height: 0 }));
13038
+ __publicField(this, "resizeObserver");
13039
+ __publicField(this, "onResize");
12871
13040
  this.document = document2;
12872
13041
  this.window = window2;
12873
13042
  this.view = view;
13043
+ this.onResize = onResize;
13044
+ }
13045
+ setViewport({
13046
+ translation,
13047
+ scale
13048
+ }) {
13049
+ this.viewPort = { translation, scale };
13050
+ this.view.setAttribute(
13051
+ "viewBox",
13052
+ `${-this.viewPort.translation.x} ${-this.viewPort.translation.y} ${this.viewSize.width / this.viewPort.scale} ${this.viewSize.height / this.viewPort.scale}`
13053
+ );
12874
13054
  }
12875
13055
  setConfig({
12876
13056
  document: document2,
@@ -12905,6 +13085,17 @@ var RenderContext = class {
12905
13085
  }
12906
13086
  };
12907
13087
  }
13088
+ dispose() {
13089
+ this.resizeObserver.disconnect();
13090
+ }
13091
+ observeSize(target) {
13092
+ this.resizeObserver = new ResizeObserver(([child]) => {
13093
+ const { width, height } = child.target.getBoundingClientRect();
13094
+ this.viewSize = new size_default({ width, height });
13095
+ this.onResize(this.viewSize);
13096
+ });
13097
+ this.resizeObserver.observe(target);
13098
+ }
12908
13099
  };
12909
13100
 
12910
13101
  // src/element/ComponentElement.ts
@@ -17256,7 +17447,6 @@ var BaseGestureDetector = class extends SingleChildRenderObjectWidget_default {
17256
17447
  onDragEnd,
17257
17448
  onDragMove,
17258
17449
  onDragStart,
17259
- bubble = {},
17260
17450
  onWheel
17261
17451
  }) {
17262
17452
  super({ child, key });
@@ -17272,7 +17462,6 @@ var BaseGestureDetector = class extends SingleChildRenderObjectWidget_default {
17272
17462
  __publicField(this, "onDragEnd");
17273
17463
  __publicField(this, "onWheel");
17274
17464
  __publicField(this, "cursor");
17275
- __publicField(this, "bubble");
17276
17465
  this.onClick = onClick != null ? onClick : emptyCallback;
17277
17466
  this.onMouseDown = onMouseDown != null ? onMouseDown : emptyCallback;
17278
17467
  this.onMouseMove = onMouseMove != null ? onMouseMove : emptyCallback;
@@ -17285,19 +17474,6 @@ var BaseGestureDetector = class extends SingleChildRenderObjectWidget_default {
17285
17474
  this.onDragEnd = onDragEnd != null ? onDragEnd : emptyCallback;
17286
17475
  this.onWheel = onWheel != null ? onWheel : emptyCallback;
17287
17476
  this.cursor = cursor != null ? cursor : "pointer";
17288
- this.bubble = __spreadValues({
17289
- mousedown: false,
17290
- mouseenter: false,
17291
- mouseleave: false,
17292
- mousemove: false,
17293
- mouseover: false,
17294
- mouseup: false,
17295
- click: false,
17296
- wheel: false,
17297
- dragstart: false,
17298
- dragend: false,
17299
- drag: false
17300
- }, bubble);
17301
17477
  }
17302
17478
  createRenderObject() {
17303
17479
  return new RenderGestureDetector({
@@ -17312,8 +17488,7 @@ var BaseGestureDetector = class extends SingleChildRenderObjectWidget_default {
17312
17488
  onDragMove: this.onDragMove,
17313
17489
  onDragEnd: this.onDragEnd,
17314
17490
  onWheel: this.onWheel,
17315
- cursor: this.cursor,
17316
- bubble: this.bubble
17491
+ cursor: this.cursor
17317
17492
  });
17318
17493
  }
17319
17494
  updateRenderObject(renderObject) {
@@ -17325,7 +17500,6 @@ var BaseGestureDetector = class extends SingleChildRenderObjectWidget_default {
17325
17500
  renderObject.onDragStart = this.onDragStart;
17326
17501
  renderObject.onDragMove = this.onDragMove;
17327
17502
  renderObject.onDragEnd = this.onDragEnd;
17328
- renderObject.bubble = this.bubble;
17329
17503
  renderObject.onWheel = this.onWheel;
17330
17504
  }
17331
17505
  };
@@ -17342,13 +17516,11 @@ var RenderGestureDetector = class extends SingleChildRenderObject_default {
17342
17516
  onDragMove,
17343
17517
  onDragStart,
17344
17518
  cursor,
17345
- bubble,
17346
17519
  onWheel
17347
17520
  }) {
17348
17521
  super({ isPainter: true });
17349
17522
  __publicField(this, "isRenderGestureDetector", true);
17350
17523
  __publicField(this, "id", createUniqueId());
17351
- __publicField(this, "_bubble");
17352
17524
  __publicField(this, "_cursor");
17353
17525
  __publicField(this, "_onClick");
17354
17526
  __publicField(this, "_onMouseDown");
@@ -17373,13 +17545,6 @@ var RenderGestureDetector = class extends SingleChildRenderObject_default {
17373
17545
  this._onDragStart = onDragStart;
17374
17546
  this._onWheel = onWheel;
17375
17547
  this._cursor = cursor;
17376
- this._bubble = bubble;
17377
- }
17378
- get bubble() {
17379
- return this._bubble;
17380
- }
17381
- set bubble(prop) {
17382
- this._bubble = prop;
17383
17548
  }
17384
17549
  get cursor() {
17385
17550
  return this._cursor;
@@ -17478,34 +17643,10 @@ var RenderGestureDetector = class extends SingleChildRenderObject_default {
17478
17643
  return;
17479
17644
  this._onWheel = prop;
17480
17645
  }
17481
- get listeners() {
17482
- const listeners = {
17483
- click: this.onClick,
17484
- mousedown: this.onMouseDown,
17485
- mousemove: this.onMouseMove,
17486
- mouseup: this.onMouseUp,
17487
- mouseover: this.onMouseOver,
17488
- mouseenter: this.onMouseEnter,
17489
- mouseleave: this.onMouseLeave,
17490
- wheel: this.onWheel,
17491
- dragstart: this.onDragStart,
17492
- drag: this.onDragMove,
17493
- dragend: this.onDragEnd
17494
- };
17495
- return TypedObject_default.keys(listeners).reduce((acc, key) => {
17496
- acc[key] = (e) => {
17497
- var _a;
17498
- if (this.bubble[key]) {
17499
- this.dispatchParent(e);
17500
- }
17501
- (_a = listeners[key]) == null ? void 0 : _a.call(listeners, e);
17502
- };
17503
- return acc;
17504
- }, {});
17505
- }
17506
17646
  attach(ownerElement) {
17507
17647
  super.attach(ownerElement);
17508
17648
  this.addEventListeners();
17649
+ this.renderOwner.hitTestDispatcher.addDetector(this);
17509
17650
  }
17510
17651
  dispose(context) {
17511
17652
  this.removeEventListeners();
@@ -17515,6 +17656,7 @@ var RenderGestureDetector = class extends SingleChildRenderObject_default {
17515
17656
  globalDragBackend = null;
17516
17657
  }
17517
17658
  super.dispose(context);
17659
+ this.renderOwner.hitTestDispatcher.removeDetector(this);
17518
17660
  }
17519
17661
  removeEventListeners() {
17520
17662
  getSingletonDragBackend().disconnectDragSource(this.id);
@@ -17523,22 +17665,13 @@ var RenderGestureDetector = class extends SingleChildRenderObject_default {
17523
17665
  const isBrowser = typeof window !== "undefined";
17524
17666
  if (!isBrowser)
17525
17667
  return;
17526
- const {
17527
- svgEls: { rect }
17528
- } = this.resolveSvgEl();
17529
17668
  const dragBackend = getSingletonDragBackend();
17530
17669
  dragBackend.isSetup || dragBackend.setup();
17531
17670
  backendRefCount++;
17532
- const _a = this.listeners, { drag, dragend, dragstart } = _a, restListeners = __objRest(_a, ["drag", "dragend", "dragstart"]);
17533
- dragBackend.connectDragSource(this.id, rect, {
17534
- onDragStart: dragstart,
17535
- onDragMove: drag,
17536
- onDragEnd: dragend
17537
- });
17538
- TypedObject_default.entries(restListeners).forEach(([type, listener]) => {
17539
- rect.addEventListener(type, (e) => {
17540
- listener(e);
17541
- });
17671
+ dragBackend.connectDragSource(this, {
17672
+ onDragStart: this.onDragStart,
17673
+ onDragMove: this.onDragMove,
17674
+ onDragEnd: this.onDragEnd
17542
17675
  });
17543
17676
  }
17544
17677
  performPaint({ rect }) {
@@ -17554,19 +17687,9 @@ var RenderGestureDetector = class extends SingleChildRenderObject_default {
17554
17687
  rect
17555
17688
  };
17556
17689
  }
17557
- dispatch(e) {
17558
- var _a, _b;
17559
- (_b = (_a = this.listeners)[e.type]) == null ? void 0 : _b.call(_a, e);
17560
- }
17561
- dispatchParent(e) {
17562
- let parent = this.parent;
17563
- while (parent != null) {
17564
- if (parent == null ? void 0 : parent.isRenderGestureDetector) {
17565
- parent.dispatch(e);
17566
- break;
17567
- }
17568
- parent = parent.parent;
17569
- }
17690
+ didChangeDomOrder() {
17691
+ super.didChangeDomOrder();
17692
+ this.renderOwner.hitTestDispatcher.didChangeDomOrder();
17570
17693
  }
17571
17694
  };
17572
17695
  function emptyCallback(_arg) {
@@ -17575,7 +17698,6 @@ var DragBackend = class {
17575
17698
  constructor() {
17576
17699
  __publicField(this, "isSetup", false);
17577
17700
  __publicField(this, "activeDragSourceId", null);
17578
- __publicField(this, "dragStartListener", {});
17579
17701
  __publicField(this, "dragMoveListener", {});
17580
17702
  __publicField(this, "dragEndListener", {});
17581
17703
  __publicField(this, "handleMouseMoveTop", (e) => {
@@ -17615,19 +17737,21 @@ var DragBackend = class {
17615
17737
  this.root.removeEventListener("mouseup", this.handleMouseUpTop);
17616
17738
  this.isSetup = false;
17617
17739
  }
17618
- connectDragSource(sourceId, node, {
17740
+ setActiveDragSourceId(sourceId) {
17741
+ this.activeDragSourceId = sourceId;
17742
+ }
17743
+ connectDragSource(detector, {
17619
17744
  onDragStart = emptyCallback,
17620
17745
  onDragMove = emptyCallback,
17621
17746
  onDragEnd = emptyCallback
17622
17747
  } = {}) {
17623
- this.dragStartListener[sourceId] = (e) => {
17624
- this.activeDragSourceId = sourceId;
17748
+ const sourceId = detector.id;
17749
+ const onMouseDown = detector.onMouseDown;
17750
+ detector.onMouseDown = (e) => {
17751
+ onMouseDown(e);
17752
+ this.setActiveDragSourceId(sourceId);
17625
17753
  onDragStart(e);
17626
17754
  };
17627
- node.addEventListener(
17628
- "mousedown",
17629
- this.dragStartListener[sourceId].bind(this)
17630
- );
17631
17755
  this.dragMoveListener[sourceId] = (e) => {
17632
17756
  onDragMove(e);
17633
17757
  };
@@ -18368,19 +18492,6 @@ var ToolTipState = class extends State {
18368
18492
  clipped: false,
18369
18493
  children: [
18370
18494
  GestureDetector_default({
18371
- bubble: {
18372
- mousedown: true,
18373
- mouseenter: true,
18374
- mouseleave: true,
18375
- mousemove: true,
18376
- mouseover: true,
18377
- mouseup: true,
18378
- click: true,
18379
- drag: true,
18380
- dragend: true,
18381
- dragstart: true,
18382
- wheel: true
18383
- },
18384
18495
  cursor: "default",
18385
18496
  child: this.widget.child,
18386
18497
  onMouseEnter: () => {