@nectary/components 5.45.2 → 5.45.4

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/bundle.js CHANGED
@@ -211,9 +211,7 @@ const isTransformedElement = (element) => {
211
211
  }
212
212
  const style = getComputedStyle(element);
213
213
  const backdropFilter = style.getPropertyValue("backdrop-filter");
214
- const hasTransform = style.transform !== "none" || style.perspective !== "none" || style.filter !== "none" || backdropFilter !== "" && backdropFilter !== "none";
215
- const hasWillChange = style.willChange.split(",").map((value) => value.trim().toLowerCase()).some((value) => value === "transform" || value === "perspective" || value === "filter" || value === "backdrop-filter");
216
- return hasTransform || hasWillChange;
214
+ return style.transform !== "none" || style.perspective !== "none" || style.filter !== "none" || backdropFilter !== "" && backdropFilter !== "none";
217
215
  };
218
216
  const getTransformedAncestor = (node) => {
219
217
  let current = node;
@@ -3501,14 +3499,15 @@ const getPlacementContext = (node, ancestorHint) => {
3501
3499
  };
3502
3500
  };
3503
3501
  const toLocalRect = (rect, placementContext) => {
3504
- if (placementContext.transformedAncestor == null) {
3502
+ const { transformedAncestor, boundsLeft, boundsTop, scaleX, scaleY } = placementContext;
3503
+ if (transformedAncestor == null) {
3505
3504
  return rect;
3506
3505
  }
3507
3506
  return {
3508
- x: (rect.x - placementContext.boundsLeft) / placementContext.scaleX,
3509
- y: (rect.y - placementContext.boundsTop) / placementContext.scaleY,
3510
- width: rect.width / placementContext.scaleX,
3511
- height: rect.height / placementContext.scaleY
3507
+ x: (rect.x - boundsLeft) / scaleX + transformedAncestor.scrollLeft,
3508
+ y: (rect.y - boundsTop) / scaleY + transformedAncestor.scrollTop,
3509
+ width: rect.width / scaleX,
3510
+ height: rect.height / scaleY
3512
3511
  };
3513
3512
  };
3514
3513
  const orientationValues$2 = [
@@ -3582,13 +3581,14 @@ const enableOverscroll = () => {
3582
3581
  document.documentElement.style.removeProperty("overscroll-behavior");
3583
3582
  }
3584
3583
  };
3585
- const templateHTML$Z = '<style>:host{display:contents;position:relative}dialog{position:fixed;left:0;top:0;transform:translate(var(--sinch-pop-offset-x),var(--sinch-pop-offset-y));margin:0;outline:0;padding:0;border:none;box-sizing:border-box;max-width:unset;max-height:unset;z-index:var(--sinch-comp-pop-z-index,1);background:0 0;overflow:visible}dialog:not([open]){display:none}dialog::backdrop{background-color:transparent}#content{position:relative;z-index:var(--sinch-comp-pop-z-index,1)}#target-open{display:flex;flex-direction:column;position:absolute;left:0;top:0}#focus{display:none;position:absolute;width:0;height:0}</style><slot id="target" name="target" aria-haspopup="dialog" aria-expanded="false"></slot><div id="focus"></div><dialog id="dialog"><div id="target-open"><slot name="target-open"></slot></div><div id="content"><slot name="content"></slot></div></dialog>';
3584
+ const templateHTML$Z = '<style>:host{display:contents;position:relative}dialog{position:fixed;left:0;top:0;transform:translate(var(--sinch-pop-offset-x),var(--sinch-pop-offset-y));margin:0;outline:0;padding:0;border:none;box-sizing:border-box;max-width:unset;max-height:unset;z-index:var(--sinch-comp-pop-z-index,1);background:0 0;overflow:visible}dialog:not([open]){display:none}dialog::backdrop{background-color:transparent}#backdrop{display:none;position:fixed;inset:0;margin:0;border:none;padding:0;background:0 0;pointer-events:auto;z-index:0}dialog[data-modal-backdrop] #backdrop{display:block}#content{position:relative;z-index:var(--sinch-comp-pop-z-index,1)}#target-open{display:flex;flex-direction:column;position:absolute;left:0;top:0;z-index:var(--sinch-comp-pop-z-index,1)}#focus{display:none;position:absolute;width:0;height:0}</style><slot id="target" name="target" aria-haspopup="dialog" aria-expanded="false"></slot><div id="focus"></div><dialog id="dialog"><div id="backdrop"></div><div id="target-open"><slot name="target-open"></slot></div><div id="content"><slot name="content"></slot></div></dialog>';
3586
3585
  const template$Z = document.createElement("template");
3587
3586
  template$Z.innerHTML = templateHTML$Z;
3588
3587
  class Pop extends NectaryElement {
3589
3588
  #$targetWrapper;
3590
3589
  #$focus;
3591
3590
  #$dialog;
3591
+ #$backdrop;
3592
3592
  #resizeThrottle;
3593
3593
  #scrollPositionThrottle;
3594
3594
  #resizeObserver;
@@ -3603,9 +3603,11 @@ class Pop extends NectaryElement {
3603
3603
  #modalWidth = 0;
3604
3604
  #modalHeight = 0;
3605
3605
  #scrollableParents = [];
3606
+ #documentDismissController = null;
3606
3607
  #openSession = {
3607
3608
  effectiveAllowScroll: false,
3608
3609
  modalSemantics: false,
3610
+ openAsModal: true,
3609
3611
  targetStyleValue: null,
3610
3612
  transformedAncestor: null
3611
3613
  };
@@ -3623,6 +3625,7 @@ class Pop extends NectaryElement {
3623
3625
  this.#$targetWrapper = shadowRoot.querySelector("#target");
3624
3626
  this.#$focus = shadowRoot.querySelector("#focus");
3625
3627
  this.#$dialog = shadowRoot.querySelector("#dialog");
3628
+ this.#$backdrop = shadowRoot.querySelector("#backdrop");
3626
3629
  this.#$targetSlot = shadowRoot.querySelector('slot[name="target"]');
3627
3630
  this.#$targetOpenSlot = shadowRoot.querySelector('slot[name="target-open"]');
3628
3631
  this.#$contentSlot = shadowRoot.querySelector('slot[name="content"]');
@@ -3649,6 +3652,7 @@ class Pop extends NectaryElement {
3649
3652
  this.#syncDialogA11yAttrs();
3650
3653
  this.#$dialog.addEventListener("cancel", this.#onCancel, { signal });
3651
3654
  this.#$dialog.addEventListener("mousedown", this.#onBackdropMouseDown, { signal });
3655
+ this.#$backdrop.addEventListener("pointerdown", this.#onModalBackdropPointerDown, { signal });
3652
3656
  this.addEventListener("-close", this.#onCloseReactHandler, { signal });
3653
3657
  subscribeContext(this, "visibility", this.#onContextVisibility, signal);
3654
3658
  if (getBooleanAttribute(this, "open")) {
@@ -3744,7 +3748,9 @@ class Pop extends NectaryElement {
3744
3748
  }
3745
3749
  case "modal": {
3746
3750
  if (this.#$dialog.open) {
3747
- this.#syncDialogSemantics(this.#shouldUseModalSemantics());
3751
+ this.#openSession.modalSemantics = this.modal;
3752
+ this.#syncDialogSemantics(this.modal);
3753
+ this.#syncModalBackdrop(this.#needsModalBackdrop());
3748
3754
  }
3749
3755
  break;
3750
3756
  }
@@ -3783,8 +3789,19 @@ class Pop extends NectaryElement {
3783
3789
  this.#hasManagedHostRole = false;
3784
3790
  this.#$dialog.removeAttribute("aria-modal");
3785
3791
  }
3786
- #shouldUseModalSemantics(transformedAncestor = this.#openSession.transformedAncestor) {
3787
- return this.modal && transformedAncestor === null;
3792
+ #needsModalBackdrop(openSession = this.#openSession) {
3793
+ return openSession.modalSemantics && !openSession.openAsModal;
3794
+ }
3795
+ #syncModalBackdrop(shouldShow) {
3796
+ if (shouldShow) {
3797
+ this.#$dialog.setAttribute("data-modal-backdrop", "");
3798
+ } else {
3799
+ this.#$dialog.removeAttribute("data-modal-backdrop");
3800
+ }
3801
+ }
3802
+ #usesShowModal(transformedAncestor) {
3803
+ const effectiveAllowScroll = this.allowScroll || transformedAncestor != null;
3804
+ return !effectiveAllowScroll || this.modal && transformedAncestor === null;
3788
3805
  }
3789
3806
  #getTargetRect() {
3790
3807
  let item = getFirstSlotElement(this.#$targetSlot, true);
@@ -3854,22 +3871,56 @@ class Pop extends NectaryElement {
3854
3871
  el.removeEventListener("scroll", this.#onScrollableParentScroll, { capture: true });
3855
3872
  });
3856
3873
  }
3874
+ #subscribeDocumentDismiss() {
3875
+ this.#documentDismissController = new AbortController();
3876
+ const { signal } = this.#documentDismissController;
3877
+ requestAnimationFrame(() => {
3878
+ requestAnimationFrame(() => {
3879
+ if (!signal.aborted && this.isDomConnected && this.#$dialog.open) {
3880
+ document.addEventListener("pointerdown", this.#onDocumentPointerDown, { capture: true, signal });
3881
+ }
3882
+ });
3883
+ });
3884
+ }
3885
+ #unsubscribeDocumentDismiss() {
3886
+ this.#documentDismissController?.abort();
3887
+ this.#documentDismissController = null;
3888
+ }
3889
+ #isPointerEventInsidePop(e) {
3890
+ for (const node of e.composedPath()) {
3891
+ if (node === this || node === this.#$dialog) {
3892
+ return true;
3893
+ }
3894
+ if (node instanceof Node && composedContains(this.#$dialog, node)) {
3895
+ return true;
3896
+ }
3897
+ for (const targetEl of [
3898
+ ...this.#$targetSlot.assignedElements({ flatten: true }),
3899
+ ...this.#$targetOpenSlot.assignedElements({ flatten: true })
3900
+ ]) {
3901
+ if (node === targetEl || node instanceof Node && composedContains(targetEl, node)) {
3902
+ return true;
3903
+ }
3904
+ }
3905
+ }
3906
+ return false;
3907
+ }
3857
3908
  #onExpand() {
3858
3909
  if (!this.isDomConnected || this.#$dialog.open) {
3859
3910
  return;
3860
3911
  }
3861
3912
  const transformedAncestor = getTransformedAncestor(this);
3862
3913
  const effectiveAllowScroll = this.allowScroll || transformedAncestor != null;
3863
- const shouldUseModal = this.#shouldUseModalSemantics(transformedAncestor);
3864
- const openAsModal = shouldUseModal || !effectiveAllowScroll;
3914
+ const openAsModal = this.#usesShowModal(transformedAncestor);
3865
3915
  this.#openSession = {
3866
3916
  effectiveAllowScroll,
3867
- modalSemantics: shouldUseModal,
3917
+ modalSemantics: this.modal,
3918
+ openAsModal,
3868
3919
  targetStyleValue: null,
3869
3920
  transformedAncestor
3870
3921
  };
3871
3922
  this.#syncDialogA11yAttrs();
3872
- this.#syncDialogSemantics(shouldUseModal);
3923
+ this.#syncDialogSemantics(this.modal);
3873
3924
  this.#$targetSlot.addEventListener("blur", this.#stopEventPropagation, true);
3874
3925
  this.#$focus.setAttribute("tabindex", "-1");
3875
3926
  this.#$focus.style.display = "block";
@@ -3884,10 +3935,11 @@ class Pop extends NectaryElement {
3884
3935
  } else {
3885
3936
  this.#$dialog.show();
3886
3937
  }
3938
+ this.#syncModalBackdrop(this.#needsModalBackdrop());
3887
3939
  this.#$targetWrapper.setAttribute("aria-expanded", "true");
3888
3940
  this.#updateOrientation();
3889
3941
  this.#resizeObserver.observe(this.#$dialog);
3890
- if (shouldUseModal) {
3942
+ if (this.modal) {
3891
3943
  getFirstFocusableElement(this.#$contentSlot)?.focus();
3892
3944
  } else {
3893
3945
  if (!effectiveAllowScroll) {
@@ -3915,6 +3967,9 @@ class Pop extends NectaryElement {
3915
3967
  } else {
3916
3968
  this.#subscribeScrollTracking();
3917
3969
  }
3970
+ if (!openAsModal) {
3971
+ this.#subscribeDocumentDismiss();
3972
+ }
3918
3973
  window.addEventListener("resize", this.#onResize);
3919
3974
  requestAnimationFrame(() => {
3920
3975
  if (this.isDomConnected && this.#$dialog.open) {
@@ -3931,19 +3986,21 @@ class Pop extends NectaryElement {
3931
3986
  const openSession = this.#openSession;
3932
3987
  const effectiveAllowScroll = openSession.effectiveAllowScroll;
3933
3988
  this.#resizeObserver.disconnect();
3934
- const isNonModal = !openSession.modalSemantics;
3989
+ const usesShowClosePath = !openSession.openAsModal;
3990
+ const hasTransferredTarget = !openSession.modalSemantics && !effectiveAllowScroll;
3935
3991
  const activeSlot = effectiveAllowScroll ? this.#$targetSlot : this.#$targetOpenSlot;
3936
3992
  this.#dispatchContentVisibility(false);
3937
3993
  activeSlot.removeEventListener("keydown", this.#onTargetKeydown);
3938
- if (isNonModal) {
3994
+ if (usesShowClosePath) {
3939
3995
  activeSlot.addEventListener("blur", this.#captureActiveElement, true);
3940
3996
  }
3997
+ this.#syncModalBackdrop(false);
3941
3998
  this.#$dialog.close();
3942
3999
  this.#$targetWrapper.setAttribute("aria-expanded", "false");
3943
- if (isNonModal) {
4000
+ if (usesShowClosePath) {
3944
4001
  activeSlot.removeEventListener("blur", this.#captureActiveElement, true);
3945
4002
  }
3946
- if (isNonModal && !effectiveAllowScroll) {
4003
+ if (hasTransferredTarget) {
3947
4004
  this.#restoreTransferredTarget();
3948
4005
  }
3949
4006
  if (this.shouldRestoreFocusOnClose && this.#targetActiveElement !== null) {
@@ -3964,6 +4021,7 @@ class Pop extends NectaryElement {
3964
4021
  }
3965
4022
  }
3966
4023
  this.#targetActiveElement = null;
4024
+ this.#unsubscribeDocumentDismiss();
3967
4025
  if (!effectiveAllowScroll) {
3968
4026
  enableOverscroll();
3969
4027
  } else {
@@ -3977,6 +4035,7 @@ class Pop extends NectaryElement {
3977
4035
  this.#openSession = {
3978
4036
  effectiveAllowScroll: false,
3979
4037
  modalSemantics: false,
4038
+ openAsModal: true,
3980
4039
  targetStyleValue: null,
3981
4040
  transformedAncestor: null
3982
4041
  };
@@ -3985,7 +4044,17 @@ class Pop extends NectaryElement {
3985
4044
  #onResize = () => {
3986
4045
  this.#resizeThrottle.fn();
3987
4046
  };
3988
- #onScrollableParentScroll = () => {
4047
+ #shouldRepositionForScroll(scrollingElement) {
4048
+ const { transformedAncestor } = this.#openSession;
4049
+ if (transformedAncestor == null || !(scrollingElement instanceof HTMLElement)) {
4050
+ return true;
4051
+ }
4052
+ return scrollingElement !== transformedAncestor;
4053
+ }
4054
+ #onScrollableParentScroll = (e) => {
4055
+ if (!this.#shouldRepositionForScroll(e.target)) {
4056
+ return;
4057
+ }
3989
4058
  this.#scrollPositionThrottle.fn();
3990
4059
  };
3991
4060
  #updatePosition = (updateWidth) => {
@@ -4051,6 +4120,27 @@ class Pop extends NectaryElement {
4051
4120
  }
4052
4121
  }
4053
4122
  };
4123
+ #onModalBackdropPointerDown = (e) => {
4124
+ if (!this.shouldCloseOnBackdropClick || e.button !== 0) {
4125
+ return;
4126
+ }
4127
+ e.preventDefault();
4128
+ e.stopPropagation();
4129
+ this.#dispatchCloseEvent();
4130
+ };
4131
+ #onDocumentPointerDown = (e) => {
4132
+ if (!this.shouldCloseOnBackdropClick || this.#$dialog.open === false) {
4133
+ return;
4134
+ }
4135
+ if (e.button !== 0) {
4136
+ return;
4137
+ }
4138
+ if (this.#isPointerEventInsidePop(e)) {
4139
+ return;
4140
+ }
4141
+ e.preventDefault();
4142
+ this.#dispatchCloseEvent();
4143
+ };
4054
4144
  #onCancel = (e) => {
4055
4145
  e.preventDefault();
4056
4146
  e.stopPropagation();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nectary/components",
3
- "version": "5.45.2",
3
+ "version": "5.45.4",
4
4
  "files": [
5
5
  "**/*/*.css",
6
6
  "**/*/*.json",
package/pop/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Context, subscribeContext } from "../utils/context.js";
2
- import { getBooleanAttribute, updateBooleanAttribute, getLiteralAttribute, updateLiteralAttribute, updateIntegerAttribute, getIntegerAttribute, isAttrEqual, getScrollableParents, getTransformedAncestor, isAttrTrue } from "../utils/dom.js";
2
+ import { getBooleanAttribute, updateBooleanAttribute, getLiteralAttribute, updateLiteralAttribute, updateIntegerAttribute, getIntegerAttribute, isAttrEqual, getScrollableParents, composedContains, getTransformedAncestor, isAttrTrue } from "../utils/dom.js";
3
3
  import { defineCustomElement, NectaryElement } from "../utils/element.js";
4
4
  import { getRect } from "../utils/rect.js";
5
5
  import { getFirstSlotElement, getFirstFocusableElement, isElementFocused } from "../utils/slot.js";
@@ -8,13 +8,14 @@ import { getReactEventHandler } from "../utils/get-react-event-handler.js";
8
8
  import { isTargetEqual } from "../utils/event-target.js";
9
9
  import { getPlacementContext, toLocalRect } from "../utils/placement.js";
10
10
  import { orientationValues, disableOverscroll, enableOverscroll, getAnchorPosition, clampPosition } from "./utils.js";
11
- const templateHTML = '<style>:host{display:contents;position:relative}dialog{position:fixed;left:0;top:0;transform:translate(var(--sinch-pop-offset-x),var(--sinch-pop-offset-y));margin:0;outline:0;padding:0;border:none;box-sizing:border-box;max-width:unset;max-height:unset;z-index:var(--sinch-comp-pop-z-index,1);background:0 0;overflow:visible}dialog:not([open]){display:none}dialog::backdrop{background-color:transparent}#content{position:relative;z-index:var(--sinch-comp-pop-z-index,1)}#target-open{display:flex;flex-direction:column;position:absolute;left:0;top:0}#focus{display:none;position:absolute;width:0;height:0}</style><slot id="target" name="target" aria-haspopup="dialog" aria-expanded="false"></slot><div id="focus"></div><dialog id="dialog"><div id="target-open"><slot name="target-open"></slot></div><div id="content"><slot name="content"></slot></div></dialog>';
11
+ const templateHTML = '<style>:host{display:contents;position:relative}dialog{position:fixed;left:0;top:0;transform:translate(var(--sinch-pop-offset-x),var(--sinch-pop-offset-y));margin:0;outline:0;padding:0;border:none;box-sizing:border-box;max-width:unset;max-height:unset;z-index:var(--sinch-comp-pop-z-index,1);background:0 0;overflow:visible}dialog:not([open]){display:none}dialog::backdrop{background-color:transparent}#backdrop{display:none;position:fixed;inset:0;margin:0;border:none;padding:0;background:0 0;pointer-events:auto;z-index:0}dialog[data-modal-backdrop] #backdrop{display:block}#content{position:relative;z-index:var(--sinch-comp-pop-z-index,1)}#target-open{display:flex;flex-direction:column;position:absolute;left:0;top:0;z-index:var(--sinch-comp-pop-z-index,1)}#focus{display:none;position:absolute;width:0;height:0}</style><slot id="target" name="target" aria-haspopup="dialog" aria-expanded="false"></slot><div id="focus"></div><dialog id="dialog"><div id="backdrop"></div><div id="target-open"><slot name="target-open"></slot></div><div id="content"><slot name="content"></slot></div></dialog>';
12
12
  const template = document.createElement("template");
13
13
  template.innerHTML = templateHTML;
14
14
  class Pop extends NectaryElement {
15
15
  #$targetWrapper;
16
16
  #$focus;
17
17
  #$dialog;
18
+ #$backdrop;
18
19
  #resizeThrottle;
19
20
  #scrollPositionThrottle;
20
21
  #resizeObserver;
@@ -29,9 +30,11 @@ class Pop extends NectaryElement {
29
30
  #modalWidth = 0;
30
31
  #modalHeight = 0;
31
32
  #scrollableParents = [];
33
+ #documentDismissController = null;
32
34
  #openSession = {
33
35
  effectiveAllowScroll: false,
34
36
  modalSemantics: false,
37
+ openAsModal: true,
35
38
  targetStyleValue: null,
36
39
  transformedAncestor: null
37
40
  };
@@ -49,6 +52,7 @@ class Pop extends NectaryElement {
49
52
  this.#$targetWrapper = shadowRoot.querySelector("#target");
50
53
  this.#$focus = shadowRoot.querySelector("#focus");
51
54
  this.#$dialog = shadowRoot.querySelector("#dialog");
55
+ this.#$backdrop = shadowRoot.querySelector("#backdrop");
52
56
  this.#$targetSlot = shadowRoot.querySelector('slot[name="target"]');
53
57
  this.#$targetOpenSlot = shadowRoot.querySelector('slot[name="target-open"]');
54
58
  this.#$contentSlot = shadowRoot.querySelector('slot[name="content"]');
@@ -75,6 +79,7 @@ class Pop extends NectaryElement {
75
79
  this.#syncDialogA11yAttrs();
76
80
  this.#$dialog.addEventListener("cancel", this.#onCancel, { signal });
77
81
  this.#$dialog.addEventListener("mousedown", this.#onBackdropMouseDown, { signal });
82
+ this.#$backdrop.addEventListener("pointerdown", this.#onModalBackdropPointerDown, { signal });
78
83
  this.addEventListener("-close", this.#onCloseReactHandler, { signal });
79
84
  subscribeContext(this, "visibility", this.#onContextVisibility, signal);
80
85
  if (getBooleanAttribute(this, "open")) {
@@ -170,7 +175,9 @@ class Pop extends NectaryElement {
170
175
  }
171
176
  case "modal": {
172
177
  if (this.#$dialog.open) {
173
- this.#syncDialogSemantics(this.#shouldUseModalSemantics());
178
+ this.#openSession.modalSemantics = this.modal;
179
+ this.#syncDialogSemantics(this.modal);
180
+ this.#syncModalBackdrop(this.#needsModalBackdrop());
174
181
  }
175
182
  break;
176
183
  }
@@ -209,8 +216,19 @@ class Pop extends NectaryElement {
209
216
  this.#hasManagedHostRole = false;
210
217
  this.#$dialog.removeAttribute("aria-modal");
211
218
  }
212
- #shouldUseModalSemantics(transformedAncestor = this.#openSession.transformedAncestor) {
213
- return this.modal && transformedAncestor === null;
219
+ #needsModalBackdrop(openSession = this.#openSession) {
220
+ return openSession.modalSemantics && !openSession.openAsModal;
221
+ }
222
+ #syncModalBackdrop(shouldShow) {
223
+ if (shouldShow) {
224
+ this.#$dialog.setAttribute("data-modal-backdrop", "");
225
+ } else {
226
+ this.#$dialog.removeAttribute("data-modal-backdrop");
227
+ }
228
+ }
229
+ #usesShowModal(transformedAncestor) {
230
+ const effectiveAllowScroll = this.allowScroll || transformedAncestor != null;
231
+ return !effectiveAllowScroll || this.modal && transformedAncestor === null;
214
232
  }
215
233
  #getTargetRect() {
216
234
  let item = getFirstSlotElement(this.#$targetSlot, true);
@@ -280,22 +298,56 @@ class Pop extends NectaryElement {
280
298
  el.removeEventListener("scroll", this.#onScrollableParentScroll, { capture: true });
281
299
  });
282
300
  }
301
+ #subscribeDocumentDismiss() {
302
+ this.#documentDismissController = new AbortController();
303
+ const { signal } = this.#documentDismissController;
304
+ requestAnimationFrame(() => {
305
+ requestAnimationFrame(() => {
306
+ if (!signal.aborted && this.isDomConnected && this.#$dialog.open) {
307
+ document.addEventListener("pointerdown", this.#onDocumentPointerDown, { capture: true, signal });
308
+ }
309
+ });
310
+ });
311
+ }
312
+ #unsubscribeDocumentDismiss() {
313
+ this.#documentDismissController?.abort();
314
+ this.#documentDismissController = null;
315
+ }
316
+ #isPointerEventInsidePop(e) {
317
+ for (const node of e.composedPath()) {
318
+ if (node === this || node === this.#$dialog) {
319
+ return true;
320
+ }
321
+ if (node instanceof Node && composedContains(this.#$dialog, node)) {
322
+ return true;
323
+ }
324
+ for (const targetEl of [
325
+ ...this.#$targetSlot.assignedElements({ flatten: true }),
326
+ ...this.#$targetOpenSlot.assignedElements({ flatten: true })
327
+ ]) {
328
+ if (node === targetEl || node instanceof Node && composedContains(targetEl, node)) {
329
+ return true;
330
+ }
331
+ }
332
+ }
333
+ return false;
334
+ }
283
335
  #onExpand() {
284
336
  if (!this.isDomConnected || this.#$dialog.open) {
285
337
  return;
286
338
  }
287
339
  const transformedAncestor = getTransformedAncestor(this);
288
340
  const effectiveAllowScroll = this.allowScroll || transformedAncestor != null;
289
- const shouldUseModal = this.#shouldUseModalSemantics(transformedAncestor);
290
- const openAsModal = shouldUseModal || !effectiveAllowScroll;
341
+ const openAsModal = this.#usesShowModal(transformedAncestor);
291
342
  this.#openSession = {
292
343
  effectiveAllowScroll,
293
- modalSemantics: shouldUseModal,
344
+ modalSemantics: this.modal,
345
+ openAsModal,
294
346
  targetStyleValue: null,
295
347
  transformedAncestor
296
348
  };
297
349
  this.#syncDialogA11yAttrs();
298
- this.#syncDialogSemantics(shouldUseModal);
350
+ this.#syncDialogSemantics(this.modal);
299
351
  this.#$targetSlot.addEventListener("blur", this.#stopEventPropagation, true);
300
352
  this.#$focus.setAttribute("tabindex", "-1");
301
353
  this.#$focus.style.display = "block";
@@ -310,10 +362,11 @@ class Pop extends NectaryElement {
310
362
  } else {
311
363
  this.#$dialog.show();
312
364
  }
365
+ this.#syncModalBackdrop(this.#needsModalBackdrop());
313
366
  this.#$targetWrapper.setAttribute("aria-expanded", "true");
314
367
  this.#updateOrientation();
315
368
  this.#resizeObserver.observe(this.#$dialog);
316
- if (shouldUseModal) {
369
+ if (this.modal) {
317
370
  getFirstFocusableElement(this.#$contentSlot)?.focus();
318
371
  } else {
319
372
  if (!effectiveAllowScroll) {
@@ -341,6 +394,9 @@ class Pop extends NectaryElement {
341
394
  } else {
342
395
  this.#subscribeScrollTracking();
343
396
  }
397
+ if (!openAsModal) {
398
+ this.#subscribeDocumentDismiss();
399
+ }
344
400
  window.addEventListener("resize", this.#onResize);
345
401
  requestAnimationFrame(() => {
346
402
  if (this.isDomConnected && this.#$dialog.open) {
@@ -357,19 +413,21 @@ class Pop extends NectaryElement {
357
413
  const openSession = this.#openSession;
358
414
  const effectiveAllowScroll = openSession.effectiveAllowScroll;
359
415
  this.#resizeObserver.disconnect();
360
- const isNonModal = !openSession.modalSemantics;
416
+ const usesShowClosePath = !openSession.openAsModal;
417
+ const hasTransferredTarget = !openSession.modalSemantics && !effectiveAllowScroll;
361
418
  const activeSlot = effectiveAllowScroll ? this.#$targetSlot : this.#$targetOpenSlot;
362
419
  this.#dispatchContentVisibility(false);
363
420
  activeSlot.removeEventListener("keydown", this.#onTargetKeydown);
364
- if (isNonModal) {
421
+ if (usesShowClosePath) {
365
422
  activeSlot.addEventListener("blur", this.#captureActiveElement, true);
366
423
  }
424
+ this.#syncModalBackdrop(false);
367
425
  this.#$dialog.close();
368
426
  this.#$targetWrapper.setAttribute("aria-expanded", "false");
369
- if (isNonModal) {
427
+ if (usesShowClosePath) {
370
428
  activeSlot.removeEventListener("blur", this.#captureActiveElement, true);
371
429
  }
372
- if (isNonModal && !effectiveAllowScroll) {
430
+ if (hasTransferredTarget) {
373
431
  this.#restoreTransferredTarget();
374
432
  }
375
433
  if (this.shouldRestoreFocusOnClose && this.#targetActiveElement !== null) {
@@ -390,6 +448,7 @@ class Pop extends NectaryElement {
390
448
  }
391
449
  }
392
450
  this.#targetActiveElement = null;
451
+ this.#unsubscribeDocumentDismiss();
393
452
  if (!effectiveAllowScroll) {
394
453
  enableOverscroll();
395
454
  } else {
@@ -403,6 +462,7 @@ class Pop extends NectaryElement {
403
462
  this.#openSession = {
404
463
  effectiveAllowScroll: false,
405
464
  modalSemantics: false,
465
+ openAsModal: true,
406
466
  targetStyleValue: null,
407
467
  transformedAncestor: null
408
468
  };
@@ -411,7 +471,17 @@ class Pop extends NectaryElement {
411
471
  #onResize = () => {
412
472
  this.#resizeThrottle.fn();
413
473
  };
414
- #onScrollableParentScroll = () => {
474
+ #shouldRepositionForScroll(scrollingElement) {
475
+ const { transformedAncestor } = this.#openSession;
476
+ if (transformedAncestor == null || !(scrollingElement instanceof HTMLElement)) {
477
+ return true;
478
+ }
479
+ return scrollingElement !== transformedAncestor;
480
+ }
481
+ #onScrollableParentScroll = (e) => {
482
+ if (!this.#shouldRepositionForScroll(e.target)) {
483
+ return;
484
+ }
415
485
  this.#scrollPositionThrottle.fn();
416
486
  };
417
487
  #updatePosition = (updateWidth) => {
@@ -477,6 +547,27 @@ class Pop extends NectaryElement {
477
547
  }
478
548
  }
479
549
  };
550
+ #onModalBackdropPointerDown = (e) => {
551
+ if (!this.shouldCloseOnBackdropClick || e.button !== 0) {
552
+ return;
553
+ }
554
+ e.preventDefault();
555
+ e.stopPropagation();
556
+ this.#dispatchCloseEvent();
557
+ };
558
+ #onDocumentPointerDown = (e) => {
559
+ if (!this.shouldCloseOnBackdropClick || this.#$dialog.open === false) {
560
+ return;
561
+ }
562
+ if (e.button !== 0) {
563
+ return;
564
+ }
565
+ if (this.#isPointerEventInsidePop(e)) {
566
+ return;
567
+ }
568
+ e.preventDefault();
569
+ this.#dispatchCloseEvent();
570
+ };
480
571
  #onCancel = (e) => {
481
572
  e.preventDefault();
482
573
  e.stopPropagation();
package/utils/dom.js CHANGED
@@ -221,9 +221,7 @@ const isTransformedElement = (element) => {
221
221
  }
222
222
  const style = getComputedStyle(element);
223
223
  const backdropFilter = style.getPropertyValue("backdrop-filter");
224
- const hasTransform = style.transform !== "none" || style.perspective !== "none" || style.filter !== "none" || backdropFilter !== "" && backdropFilter !== "none";
225
- const hasWillChange = style.willChange.split(",").map((value) => value.trim().toLowerCase()).some((value) => value === "transform" || value === "perspective" || value === "filter" || value === "backdrop-filter");
226
- return hasTransform || hasWillChange;
224
+ return style.transform !== "none" || style.perspective !== "none" || style.filter !== "none" || backdropFilter !== "" && backdropFilter !== "none";
227
225
  };
228
226
  const getTransformedAncestor = (node) => {
229
227
  let current = node;
@@ -62,14 +62,15 @@ const getPlacementContext = (node, ancestorHint) => {
62
62
  };
63
63
  };
64
64
  const toLocalRect = (rect, placementContext) => {
65
- if (placementContext.transformedAncestor == null) {
65
+ const { transformedAncestor, boundsLeft, boundsTop, scaleX, scaleY } = placementContext;
66
+ if (transformedAncestor == null) {
66
67
  return rect;
67
68
  }
68
69
  return {
69
- x: (rect.x - placementContext.boundsLeft) / placementContext.scaleX,
70
- y: (rect.y - placementContext.boundsTop) / placementContext.scaleY,
71
- width: rect.width / placementContext.scaleX,
72
- height: rect.height / placementContext.scaleY
70
+ x: (rect.x - boundsLeft) / scaleX + transformedAncestor.scrollLeft,
71
+ y: (rect.y - boundsTop) / scaleY + transformedAncestor.scrollTop,
72
+ width: rect.width / scaleX,
73
+ height: rect.height / scaleY
73
74
  };
74
75
  };
75
76
  export {