@vvfx/sdk 0.2.2-beta.6 → 0.2.2-beta.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/dist/index.mjs CHANGED
@@ -3,7 +3,7 @@
3
3
  * Description: TODO
4
4
  * Author: Ant Group CO., Ltd.
5
5
  * Contributors: 赤芍,何即,不择,意绮
6
- * Version: v0.2.2-beta.6
6
+ * Version: v0.2.2-beta.8
7
7
  */
8
8
 
9
9
  'use strict';
@@ -91932,8 +91932,8 @@ function mountHTMLShell(container, content, shell) {
91932
91932
  var SHELL_INTERACTIVE_SELECTOR = '[data-vvfx-html-shell-interactive="true"]';
91933
91933
  var EDITING_INTERACTIVE_SELECTOR = '[data-vvfx-html-editing-interactive="true"]';
91934
91934
  var CONTENT_INTERACTIVE_SELECTOR = [
91935
- '[data-interaction-zone="self"]',
91936
91935
  '[data-vvfx-html-interaction-zone="self"]',
91936
+ '[data-vvfx-html-interaction-zone="subtree"]',
91937
91937
  'a[href]',
91938
91938
  'button:not([disabled])',
91939
91939
  'input:not([disabled])',
@@ -91949,7 +91949,6 @@ var CONTENT_INTERACTIVE_SELECTOR = [
91949
91949
  '[tabindex]:not([tabindex="-1"])'
91950
91950
  ].join(', ');
91951
91951
  var CONTENT_INTERACTION_NONE_SELECTOR = [
91952
- '[data-interaction-zone="none"]',
91953
91952
  '[data-vvfx-html-interaction-zone="none"]'
91954
91953
  ].join(', ');
91955
91954
  var EDITING_VIEWPORT_PADDING = 48;
@@ -92023,7 +92022,10 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
92023
92022
  _this.syncContentInteraction(hoverShellInteractiveId);
92024
92023
  }
92025
92024
  };
92026
- this.handleContainerMouseLeave = function() {
92025
+ this.handleContainerMouseLeave = function(event) {
92026
+ if (_this.isMouseLeaveWithinContainer(event)) {
92027
+ return;
92028
+ }
92027
92029
  if (_this.contentInteractionFrame !== undefined) {
92028
92030
  cancelAnimationFrame(_this.contentInteractionFrame);
92029
92031
  _this.contentInteractionFrame = undefined;
@@ -92264,6 +92266,17 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
92264
92266
  this.options.container.addEventListener('mouseleave', this.handleContainerMouseLeave, true);
92265
92267
  this.options.container.addEventListener('contextmenu', this.handleContainerContextMenu, true);
92266
92268
  };
92269
+ _proto.isMouseLeaveWithinContainer = function isMouseLeaveWithinContainer(event) {
92270
+ var relatedTarget = event.relatedTarget;
92271
+ if (!relatedTarget) {
92272
+ return false;
92273
+ }
92274
+ try {
92275
+ return this.options.container.contains(relatedTarget);
92276
+ } catch (unused) {
92277
+ return false;
92278
+ }
92279
+ };
92267
92280
  _proto.isHTMLContextMenuEvent = function isHTMLContextMenuEvent(event) {
92268
92281
  if (typeof Element !== 'function' || !_instanceof(event.target, Element)) {
92269
92282
  return false;
@@ -92559,8 +92572,11 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
92559
92572
  return undefined;
92560
92573
  };
92561
92574
  _proto.syncActiveContentInteraction = function syncActiveContentInteraction(event) {
92562
- var zone = this.getContentInteractiveZoneByEvent(event);
92563
- this.setActiveContentInteraction(zone);
92575
+ var decision = this.resolveHTMLInteractionTarget(event);
92576
+ if (decision.kind === 'canvas' && this.shouldKeepActiveContentInteractionForFocusedElement()) {
92577
+ return;
92578
+ }
92579
+ this.setActiveContentInteraction(decision.kind === 'html' ? decision.interaction : undefined);
92564
92580
  };
92565
92581
  _proto.scheduleActiveContentInteractionSync = function scheduleActiveContentInteractionSync(event) {
92566
92582
  var _this = this;
@@ -92584,7 +92600,7 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
92584
92600
  _proto.setActiveContentInteraction = function setActiveContentInteraction(zone) {
92585
92601
  var _this = this;
92586
92602
  var previous = this.state.activeContentInteraction;
92587
- if ((previous == null ? void 0 : previous.id) === (zone == null ? void 0 : zone.id) && (previous == null ? void 0 : previous.element) === (zone == null ? void 0 : zone.element)) {
92603
+ if ((previous == null ? void 0 : previous.id) === (zone == null ? void 0 : zone.id) && (previous == null ? void 0 : previous.element) === (zone == null ? void 0 : zone.element) && (previous == null ? void 0 : previous.zone) === (zone == null ? void 0 : zone.zone)) {
92588
92604
  return;
92589
92605
  }
92590
92606
  this.state.activeContentInteraction = zone;
@@ -92599,22 +92615,77 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
92599
92615
  _this.syncContentInteraction(id);
92600
92616
  });
92601
92617
  };
92602
- _proto.getContentInteractiveZoneByEvent = function getContentInteractiveZoneByEvent(event) {
92618
+ _proto.shouldKeepActiveContentInteractionForFocusedElement = function shouldKeepActiveContentInteractionForFocusedElement() {
92619
+ var activeInteraction = this.state.activeContentInteraction;
92620
+ if (!activeInteraction || typeof document === 'undefined') {
92621
+ return false;
92622
+ }
92623
+ var activeElement = document.activeElement;
92624
+ if (!activeElement || activeElement === document.body) {
92625
+ return false;
92626
+ }
92627
+ var interactionElement = activeInteraction.element;
92628
+ return interactionElement === activeElement || typeof interactionElement.contains === 'function' && interactionElement.contains(activeElement);
92629
+ };
92630
+ _proto.resolveHTMLInteractionTarget = function resolveHTMLInteractionTarget(event) {
92603
92631
  var id = this.getHTMLCardIdByEvent(event);
92604
92632
  if (!id || this.isEditableCard(id)) {
92605
- return undefined;
92633
+ return {
92634
+ kind: 'canvas',
92635
+ id: id
92636
+ };
92606
92637
  }
92607
92638
  var contentOverlay = this.state.contentElements.get(id);
92608
92639
  if (!contentOverlay) {
92609
- return undefined;
92640
+ return {
92641
+ kind: 'canvas',
92642
+ id: id
92643
+ };
92644
+ }
92645
+ var activeSubtree = this.getActiveSubtreeInteractionAtEvent(id, event);
92646
+ if (activeSubtree) {
92647
+ return {
92648
+ kind: 'html',
92649
+ interaction: activeSubtree
92650
+ };
92610
92651
  }
92611
- var zone = this.getContentInteractionZones(id, contentOverlay).find(function(zone) {
92652
+ var matchedZones = this.getContentInteractionZones(id, contentOverlay).filter(function(zone) {
92612
92653
  return isMouseEventInsideRect(event, zone.rect);
92613
92654
  });
92614
- return zone ? {
92615
- id: id,
92616
- element: zone.element
92617
- } : undefined;
92655
+ var zone = this.resolveContentInteractionZone(matchedZones);
92656
+ if (zone) {
92657
+ return {
92658
+ kind: 'html',
92659
+ interaction: {
92660
+ id: id,
92661
+ element: zone.element,
92662
+ zone: zone.zone
92663
+ }
92664
+ };
92665
+ }
92666
+ return {
92667
+ kind: 'canvas',
92668
+ id: id
92669
+ };
92670
+ };
92671
+ _proto.getActiveSubtreeInteractionAtEvent = function getActiveSubtreeInteractionAtEvent(id, event) {
92672
+ var activeInteraction = this.state.activeContentInteraction;
92673
+ if ((activeInteraction == null ? void 0 : activeInteraction.id) !== id || activeInteraction.zone !== 'subtree') {
92674
+ return undefined;
92675
+ }
92676
+ var rect = activeInteraction.element.getBoundingClientRect();
92677
+ return isMouseEventInsideRect(event, rect) ? activeInteraction : undefined;
92678
+ };
92679
+ _proto.resolveContentInteractionZone = function resolveContentInteractionZone(zones) {
92680
+ if (zones.length <= 1) {
92681
+ return zones[0];
92682
+ }
92683
+ var subtreeRoot = zones.find(function(candidate) {
92684
+ return candidate.zone === 'subtree' && typeof candidate.element.contains === 'function' && zones.some(function(zone) {
92685
+ return zone.element !== candidate.element && candidate.element.contains(zone.element);
92686
+ });
92687
+ });
92688
+ return subtreeRoot != null ? subtreeRoot : zones[0];
92618
92689
  };
92619
92690
  _proto.getContentInteractionZones = function getContentInteractionZones(id, contentOverlay) {
92620
92691
  var _this = this;
@@ -92627,7 +92698,8 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
92627
92698
  }).map(function(element) {
92628
92699
  return {
92629
92700
  element: element,
92630
- rect: element.getBoundingClientRect()
92701
+ rect: element.getBoundingClientRect(),
92702
+ zone: _this.getContentInteractionZoneMode(element)
92631
92703
  };
92632
92704
  });
92633
92705
  this.state.contentInteractionZones.set(id, zones);
@@ -92657,6 +92729,10 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
92657
92729
  }
92658
92730
  return !!element.closest(CONTENT_INTERACTION_NONE_SELECTOR);
92659
92731
  };
92732
+ _proto.getContentInteractionZoneMode = function getContentInteractionZoneMode(element) {
92733
+ var zone = element.dataset.vvfxHtmlInteractionZone;
92734
+ return zone === 'subtree' ? 'subtree' : 'self';
92735
+ };
92660
92736
  _proto.invalidateContentInteractionZones = function invalidateContentInteractionZones(id) {
92661
92737
  if (id) {
92662
92738
  var _this_state_contentInteractionResizeCleanups_get;
@@ -92769,11 +92845,11 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
92769
92845
  var _this_state_editing, _this_state_activeContentInteraction;
92770
92846
  var isEditing = ((_this_state_editing = this.state.editing) == null ? void 0 : _this_state_editing.id) === id;
92771
92847
  var activeInteraction = ((_this_state_activeContentInteraction = this.state.activeContentInteraction) == null ? void 0 : _this_state_activeContentInteraction.id) === id ? this.state.activeContentInteraction : undefined;
92772
- var isInteractive = isEditing || !!activeInteraction;
92773
92848
  var overlay = this.state.elements.get(id);
92774
92849
  var scaleOverlay = this.state.contentScaleElements.get(id);
92775
92850
  var contentOverlay = this.state.contentElements.get(id);
92776
92851
  var contentMount = this.state.contentMountElements.get(id);
92852
+ var isInteractive = isEditing || !!activeInteraction;
92777
92853
  if (overlay) {
92778
92854
  overlay.dataset.editing = isEditing ? 'true' : 'false';
92779
92855
  overlay.style.pointerEvents = 'none';
@@ -92791,7 +92867,7 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
92791
92867
  iframe.tabIndex = isActiveIframe ? 0 : -1;
92792
92868
  });
92793
92869
  this.syncShellInteraction(id, contentOverlay, isInteractive);
92794
- this.syncContentInteractionZones(id, contentOverlay, activeInteraction == null ? void 0 : activeInteraction.element, isEditing, isInteractive);
92870
+ this.syncContentInteractionZones(id, contentOverlay, activeInteraction, isEditing, isInteractive);
92795
92871
  }
92796
92872
  if (contentMount) {
92797
92873
  contentMount.dataset.editing = isEditing ? 'true' : 'false';
@@ -92804,19 +92880,32 @@ var HTMLOverlayManager = /*#__PURE__*/ function() {
92804
92880
  }
92805
92881
  }
92806
92882
  };
92807
- _proto.syncContentInteractionZones = function syncContentInteractionZones(id, contentOverlay, activeElement, isEditing, isInteractive) {
92883
+ _proto.syncContentInteractionZones = function syncContentInteractionZones(id, contentOverlay, activeInteraction, isEditing, isInteractive) {
92808
92884
  var _this = this;
92885
+ var activeElement = activeInteraction == null ? void 0 : activeInteraction.element;
92809
92886
  contentOverlay.querySelectorAll(this.getContentInteractiveSelector(id)).forEach(function(element) {
92810
- if (!isInteractive || _this.isContentInteractionDisabled(element)) {
92887
+ if ((activeInteraction == null ? void 0 : activeInteraction.zone) === 'subtree' && activeElement && element !== activeElement && typeof activeElement.contains === 'function' && activeElement.contains(element)) {
92888
+ _this.clearContentInteractionState(element);
92889
+ return;
92890
+ }
92891
+ if (!isInteractive) {
92892
+ _this.clearContentInteractionState(element);
92893
+ return;
92894
+ }
92895
+ if (_this.isContentInteractionDisabled(element)) {
92811
92896
  element.dataset.vvfxHtmlInteractionActive = 'false';
92812
92897
  element.style.pointerEvents = 'none';
92813
92898
  return;
92814
92899
  }
92815
- var isElementInteractive = isEditing || activeElement === element;
92900
+ var isElementInteractive = isEditing || activeElement === element || (activeInteraction == null ? void 0 : activeInteraction.zone) === 'subtree' && typeof (activeElement == null ? void 0 : activeElement.contains) === 'function' && activeElement.contains(element);
92816
92901
  element.dataset.vvfxHtmlInteractionActive = isElementInteractive ? 'true' : 'false';
92817
92902
  element.style.pointerEvents = isElementInteractive ? 'auto' : 'none';
92818
92903
  });
92819
92904
  };
92905
+ _proto.clearContentInteractionState = function clearContentInteractionState(element) {
92906
+ delete element.dataset.vvfxHtmlInteractionActive;
92907
+ element.style.pointerEvents = '';
92908
+ };
92820
92909
  _proto.syncShellInteraction = function syncShellInteraction(id, contentOverlay, isInteractive) {
92821
92910
  var isHoveringShellInteractive = this.state.hoverShellInteractiveId === id;
92822
92911
  var isShellInteractiveActive = isInteractive || isHoveringShellInteractive;