@oddbird/popover-polyfill
Advanced tools
Comparing version 0.4.3 to 0.4.4
@@ -16,4 +16,3 @@ // src/events.ts | ||
setTimeout(() => { | ||
if (!popoverToggleTaskQueue.has(element)) | ||
return; | ||
if (!popoverToggleTaskQueue.has(element)) return; | ||
element.dispatchEvent( | ||
@@ -51,4 +50,3 @@ new ToggleEvent("toggle", { | ||
} | ||
if (element.popoverTargetAction === "hide" && visibility === "hidden") | ||
return; | ||
if (element.popoverTargetAction === "hide" && visibility === "hidden") return; | ||
if (visibility === "showing") { | ||
@@ -65,4 +63,3 @@ hidePopover(popover, true, true); | ||
} | ||
if (!element.isConnected) | ||
return false; | ||
if (!element.isConnected) return false; | ||
if (expectedToBeShowing && getPopoverVisibilityState(element) !== "showing") { | ||
@@ -77,9 +74,7 @@ return false; | ||
} | ||
if (document.fullscreenElement === element) | ||
return false; | ||
if (document.fullscreenElement === element) return false; | ||
return true; | ||
} | ||
function getStackPosition(popover) { | ||
if (!popover) | ||
return 0; | ||
if (!popover) return 0; | ||
return Array.from(autoPopoverList.get(popover.ownerDocument) || []).indexOf( | ||
@@ -112,4 +107,3 @@ popover | ||
} | ||
if (node.parentNode) | ||
return getRootNode(node.parentNode); | ||
if (node.parentNode) return getRootNode(node.parentNode); | ||
return node; | ||
@@ -122,7 +116,5 @@ } | ||
} | ||
node = node.parentElement || getRootNode(node); | ||
if (node instanceof ShadowRoot) | ||
node = node.host; | ||
if (node instanceof Document) | ||
return; | ||
node = node instanceof Element && node.assignedSlot || node.parentElement || getRootNode(node); | ||
if (node instanceof ShadowRoot) node = node.host; | ||
if (node instanceof Document) return; | ||
} | ||
@@ -133,9 +125,6 @@ } | ||
const nodePopover = node.popoverTargetElement; | ||
if (nodePopover instanceof HTMLElement) | ||
return nodePopover; | ||
if (nodePopover instanceof HTMLElement) return nodePopover; | ||
node = node.parentElement || getRootNode(node); | ||
if (node instanceof ShadowRoot) | ||
node = node.host; | ||
if (node instanceof Document) | ||
return; | ||
if (node instanceof ShadowRoot) node = node.host; | ||
if (node instanceof Document) return; | ||
} | ||
@@ -155,4 +144,3 @@ } | ||
const candidateAncestor = nearestInclusiveOpenPopover(candidate); | ||
if (candidateAncestor === null) | ||
return null; | ||
if (candidateAncestor === null) return null; | ||
const candidatePosition = popoverPositions.get(candidateAncestor); | ||
@@ -167,7 +155,5 @@ if (topMostPopoverAncestor2 === null || popoverPositions.get(topMostPopoverAncestor2) < candidatePosition) { | ||
function isFocusable(focusTarget) { | ||
if (focusTarget.hidden || focusTarget instanceof ShadowRoot) | ||
return false; | ||
if (focusTarget.hidden || focusTarget instanceof ShadowRoot) return false; | ||
if (focusTarget instanceof HTMLButtonElement || focusTarget instanceof HTMLInputElement || focusTarget instanceof HTMLSelectElement || focusTarget instanceof HTMLTextAreaElement || focusTarget instanceof HTMLOptGroupElement || focusTarget instanceof HTMLOptionElement || focusTarget instanceof HTMLFieldSetElement) { | ||
if (focusTarget.disabled) | ||
return false; | ||
if (focusTarget.disabled) return false; | ||
} | ||
@@ -345,11 +331,8 @@ if (focusTarget instanceof HTMLInputElement && focusTarget.type === "hidden") { | ||
function lightDismissOpenPopovers(event) { | ||
if (!event.isTrusted) | ||
return; | ||
if (!event.isTrusted) return; | ||
const target = event.composedPath()[0]; | ||
if (!target) | ||
return; | ||
if (!target) return; | ||
const document2 = target.ownerDocument; | ||
const topMostPopover = topMostAutoPopover(document2); | ||
if (!topMostPopover) | ||
return; | ||
if (!topMostPopover) return; | ||
const ancestor = topMostClickedPopover(target); | ||
@@ -368,4 +351,3 @@ if (ancestor && event.type === "pointerdown") { | ||
function setInvokerAriaExpanded(el, force = false) { | ||
if (!el) | ||
return; | ||
if (!el) return; | ||
if (!initialAriaExpandedValue.has(el)) { | ||
@@ -500,4 +482,3 @@ initialAriaExpandedValue.set(el, el.getAttribute("aria-expanded")); | ||
function apply() { | ||
if (typeof window === "undefined") | ||
return; | ||
if (typeof window === "undefined") return; | ||
window.ToggleEvent = window.ToggleEvent || ToggleEvent; | ||
@@ -524,7 +505,2 @@ function rewriteSelector(selector) { | ||
); | ||
patchSelectorFn( | ||
DocumentFragment.prototype, | ||
"querySelectorAll", | ||
rewriteSelector | ||
); | ||
Object.defineProperties(HTMLElement.prototype, { | ||
@@ -535,7 +511,5 @@ popover: { | ||
get() { | ||
if (!this.hasAttribute("popover")) | ||
return null; | ||
if (!this.hasAttribute("popover")) return null; | ||
const value = (this.getAttribute("popover") || "").toLowerCase(); | ||
if (value === "" || value == "auto") | ||
return "auto"; | ||
if (value === "" || value == "auto") return "auto"; | ||
return "manual"; | ||
@@ -657,4 +631,3 @@ }, | ||
const value = (this.getAttribute("popovertargetaction") || "").toLowerCase(); | ||
if (value === "show" || value === "hide") | ||
return value; | ||
if (value === "show" || value === "hide") return value; | ||
return "toggle"; | ||
@@ -661,0 +634,0 @@ }, |
@@ -1,2 +0,2 @@ | ||
"use strict";(()=>{var c=class extends Event{oldState;newState;constructor(t,{oldState:o="",newState:r="",...i}={}){super(t,i),this.oldState=String(o||""),this.newState=String(r||"")}},N=new WeakMap;function P(e,t,o){N.set(e,setTimeout(()=>{N.has(e)&&e.dispatchEvent(new c("toggle",{cancelable:!1,oldState:t,newState:o}))},0))}var x=globalThis.ShadowRoot||function(){},V=globalThis.HTMLDialogElement||function(){},y=new WeakMap,p=new WeakMap,h=new WeakMap;function b(e){return h.get(e)||"hidden"}var L=new WeakMap;function O(e){let t=e.popoverTargetElement;if(!(t instanceof HTMLElement))return;let o=b(t);e.popoverTargetAction==="show"&&o==="showing"||e.popoverTargetAction==="hide"&&o==="hidden"||(o==="showing"?v(t,!0,!0):d(t,!1)&&(L.set(t,e),H(t)))}function d(e,t){return!(e.popover!=="auto"&&e.popover!=="manual"||!e.isConnected||t&&b(e)!=="showing"||!t&&b(e)!=="hidden"||e instanceof V&&e.hasAttribute("open")||document.fullscreenElement===e)}function F(e){return e?Array.from(p.get(e.ownerDocument)||[]).indexOf(e)+1:0}function $(e){let t=W(e),o=U(e);return F(t)>F(o)?t:o}function M(e){let t=p.get(e);for(let o of t||[])if(!o.isConnected)t.delete(o);else return o;return null}function g(e){return typeof e.getRootNode=="function"?e.getRootNode():e.parentNode?g(e.parentNode):e}function W(e){for(;e;){if(e instanceof HTMLElement&&e.popover==="auto"&&h.get(e)==="showing")return e;if(e=e.parentElement||g(e),e instanceof x&&(e=e.host),e instanceof Document)return}}function U(e){for(;e;){let t=e.popoverTargetElement;if(t instanceof HTMLElement)return t;if(e=e.parentElement||g(e),e instanceof x&&(e=e.host),e instanceof Document)return}}function G(e){let t=new Map,o=0;for(let l of p.get(e.ownerDocument)||[])t.set(l,o),o+=1;t.set(e,o),o+=1;let r=null;function i(l){let a=W(l);if(a===null)return null;let T=t.get(a);(r===null||t.get(r)<T)&&(r=a)}return i(e.parentElement||g(e)),r}function Q(e){return e.hidden||e instanceof x||(e instanceof HTMLButtonElement||e instanceof HTMLInputElement||e instanceof HTMLSelectElement||e instanceof HTMLTextAreaElement||e instanceof HTMLOptGroupElement||e instanceof HTMLOptionElement||e instanceof HTMLFieldSetElement)&&e.disabled||e instanceof HTMLInputElement&&e.type==="hidden"||e instanceof HTMLAnchorElement&&e.href===""?!1:typeof e.tabIndex=="number"&&e.tabIndex!==-1}function _(e){if(e.shadowRoot&&e.shadowRoot.delegatesFocus!==!0)return null;let t=e;t.shadowRoot&&(t=t.shadowRoot);let o=t.querySelector("[autofocus]");if(o)return o;{let l=t.querySelectorAll("slot");for(let a of l){let T=a.assignedElements({flatten:!0});for(let n of T){if(n.hasAttribute("autofocus"))return n;if(o=n.querySelector("[autofocus]"),o)return o}}}let r=e.ownerDocument.createTreeWalker(t,NodeFilter.SHOW_ELEMENT),i=r.currentNode;for(;i;){if(Q(i))return i;i=r.nextNode()}}function J(e){_(e)?.focus()}var S=new WeakMap;function H(e){if(!d(e,!1))return;let t=e.ownerDocument;if(!e.dispatchEvent(new c("beforetoggle",{cancelable:!0,oldState:"closed",newState:"open"}))||!d(e,!1))return;let o=!1;if(e.popover==="auto"){let i=e.getAttribute("popover"),l=G(e)||t;if(w(l,!1,!0),i!==e.getAttribute("popover")||!d(e,!1))return}M(t)||(o=!0),S.delete(e);let r=t.activeElement;e.classList.add(":popover-open"),h.set(e,"showing"),y.has(t)||y.set(t,new Set),y.get(t).add(e),J(e),e.popover==="auto"&&(p.has(t)||p.set(t,new Set),p.get(t).add(e),q(L.get(e),!0)),o&&r&&e.popover==="auto"&&S.set(e,r),P(e,"closed","open")}function v(e,t=!1,o=!1){if(!d(e,!0))return;let r=e.ownerDocument;if(e.popover==="auto"&&(w(e,t,o),!d(e,!0))||(q(L.get(e),!1),L.delete(e),o&&(e.dispatchEvent(new c("beforetoggle",{oldState:"open",newState:"closed"})),!d(e,!0))))return;y.get(r)?.delete(e),p.get(r)?.delete(e),e.classList.remove(":popover-open"),h.set(e,"hidden"),o&&P(e,"open","closed");let i=S.get(e);i&&(S.delete(e),t&&i.focus())}function B(e,t=!1,o=!1){let r=M(e);for(;r;)v(r,t,o),r=M(e)}function w(e,t,o){let r=e.ownerDocument||e;if(e instanceof Document)return B(r,t,o);let i=null,l=!1;for(let a of p.get(r)||[])if(a===e)l=!0;else if(l){i=a;break}if(!l)return B(r,t,o);for(;i&&b(i)==="showing"&&p.get(r)?.size;)v(i,t,o)}var A=new WeakMap;function D(e){if(!e.isTrusted)return;let t=e.composedPath()[0];if(!t)return;let o=t.ownerDocument;if(!M(o))return;let i=$(t);if(i&&e.type==="pointerdown")A.set(o,i);else if(e.type==="pointerup"){let l=A.get(o)===i;A.delete(o),l&&w(i||o,!1,!0)}}var k=new WeakMap;function q(e,t=!1){if(!e)return;k.has(e)||k.set(e,e.getAttribute("aria-expanded"));let o=e.popoverTargetElement;if(o instanceof HTMLElement&&o.popover==="auto")e.setAttribute("aria-expanded",String(t));else{let r=k.get(e);r?e.setAttribute("aria-expanded",r):e.removeAttribute("aria-expanded")}}var C=globalThis.ShadowRoot||function(){};function j(){return typeof HTMLElement<"u"&&typeof HTMLElement.prototype=="object"&&"popover"in HTMLElement.prototype}function f(e,t,o){let r=e[t];Object.defineProperty(e,t,{value(i){return r.call(this,o(i))}})}var X=/(^|[^\\]):popover-open\b/g;function Y(){return typeof globalThis.CSSLayerBlockRule=="function"}function Z(){let e=Y();return` | ||
"use strict";(()=>{var c=class extends Event{oldState;newState;constructor(t,{oldState:o="",newState:r="",...i}={}){super(t,i),this.oldState=String(o||""),this.newState=String(r||"")}},N=new WeakMap;function P(e,t,o){N.set(e,setTimeout(()=>{N.has(e)&&e.dispatchEvent(new c("toggle",{cancelable:!1,oldState:t,newState:o}))},0))}var x=globalThis.ShadowRoot||function(){},V=globalThis.HTMLDialogElement||function(){},b=new WeakMap,p=new WeakMap,h=new WeakMap;function y(e){return h.get(e)||"hidden"}var L=new WeakMap;function O(e){let t=e.popoverTargetElement;if(!(t instanceof HTMLElement))return;let o=y(t);e.popoverTargetAction==="show"&&o==="showing"||e.popoverTargetAction==="hide"&&o==="hidden"||(o==="showing"?v(t,!0,!0):f(t,!1)&&(L.set(t,e),H(t)))}function f(e,t){return!(e.popover!=="auto"&&e.popover!=="manual"||!e.isConnected||t&&y(e)!=="showing"||!t&&y(e)!=="hidden"||e instanceof V&&e.hasAttribute("open")||document.fullscreenElement===e)}function F(e){return e?Array.from(p.get(e.ownerDocument)||[]).indexOf(e)+1:0}function $(e){let t=W(e),o=U(e);return F(t)>F(o)?t:o}function M(e){let t=p.get(e);for(let o of t||[])if(!o.isConnected)t.delete(o);else return o;return null}function d(e){return typeof e.getRootNode=="function"?e.getRootNode():e.parentNode?d(e.parentNode):e}function W(e){for(;e;){if(e instanceof HTMLElement&&e.popover==="auto"&&h.get(e)==="showing")return e;if(e=e instanceof Element&&e.assignedSlot||e.parentElement||d(e),e instanceof x&&(e=e.host),e instanceof Document)return}}function U(e){for(;e;){let t=e.popoverTargetElement;if(t instanceof HTMLElement)return t;if(e=e.parentElement||d(e),e instanceof x&&(e=e.host),e instanceof Document)return}}function G(e){let t=new Map,o=0;for(let l of p.get(e.ownerDocument)||[])t.set(l,o),o+=1;t.set(e,o),o+=1;let r=null;function i(l){let a=W(l);if(a===null)return null;let T=t.get(a);(r===null||t.get(r)<T)&&(r=a)}return i(e.parentElement||d(e)),r}function Q(e){return e.hidden||e instanceof x||(e instanceof HTMLButtonElement||e instanceof HTMLInputElement||e instanceof HTMLSelectElement||e instanceof HTMLTextAreaElement||e instanceof HTMLOptGroupElement||e instanceof HTMLOptionElement||e instanceof HTMLFieldSetElement)&&e.disabled||e instanceof HTMLInputElement&&e.type==="hidden"||e instanceof HTMLAnchorElement&&e.href===""?!1:typeof e.tabIndex=="number"&&e.tabIndex!==-1}function _(e){if(e.shadowRoot&&e.shadowRoot.delegatesFocus!==!0)return null;let t=e;t.shadowRoot&&(t=t.shadowRoot);let o=t.querySelector("[autofocus]");if(o)return o;{let l=t.querySelectorAll("slot");for(let a of l){let T=a.assignedElements({flatten:!0});for(let n of T){if(n.hasAttribute("autofocus"))return n;if(o=n.querySelector("[autofocus]"),o)return o}}}let r=e.ownerDocument.createTreeWalker(t,NodeFilter.SHOW_ELEMENT),i=r.currentNode;for(;i;){if(Q(i))return i;i=r.nextNode()}}function J(e){_(e)?.focus()}var S=new WeakMap;function H(e){if(!f(e,!1))return;let t=e.ownerDocument;if(!e.dispatchEvent(new c("beforetoggle",{cancelable:!0,oldState:"closed",newState:"open"}))||!f(e,!1))return;let o=!1;if(e.popover==="auto"){let i=e.getAttribute("popover"),l=G(e)||t;if(w(l,!1,!0),i!==e.getAttribute("popover")||!f(e,!1))return}M(t)||(o=!0),S.delete(e);let r=t.activeElement;e.classList.add(":popover-open"),h.set(e,"showing"),b.has(t)||b.set(t,new Set),b.get(t).add(e),J(e),e.popover==="auto"&&(p.has(t)||p.set(t,new Set),p.get(t).add(e),C(L.get(e),!0)),o&&r&&e.popover==="auto"&&S.set(e,r),P(e,"closed","open")}function v(e,t=!1,o=!1){if(!f(e,!0))return;let r=e.ownerDocument;if(e.popover==="auto"&&(w(e,t,o),!f(e,!0))||(C(L.get(e),!1),L.delete(e),o&&(e.dispatchEvent(new c("beforetoggle",{oldState:"open",newState:"closed"})),!f(e,!0))))return;b.get(r)?.delete(e),p.get(r)?.delete(e),e.classList.remove(":popover-open"),h.set(e,"hidden"),o&&P(e,"open","closed");let i=S.get(e);i&&(S.delete(e),t&&i.focus())}function B(e,t=!1,o=!1){let r=M(e);for(;r;)v(r,t,o),r=M(e)}function w(e,t,o){let r=e.ownerDocument||e;if(e instanceof Document)return B(r,t,o);let i=null,l=!1;for(let a of p.get(r)||[])if(a===e)l=!0;else if(l){i=a;break}if(!l)return B(r,t,o);for(;i&&y(i)==="showing"&&p.get(r)?.size;)v(i,t,o)}var A=new WeakMap;function D(e){if(!e.isTrusted)return;let t=e.composedPath()[0];if(!t)return;let o=t.ownerDocument;if(!M(o))return;let i=$(t);if(i&&e.type==="pointerdown")A.set(o,i);else if(e.type==="pointerup"){let l=A.get(o)===i;A.delete(o),l&&w(i||o,!1,!0)}}var k=new WeakMap;function C(e,t=!1){if(!e)return;k.has(e)||k.set(e,e.getAttribute("aria-expanded"));let o=e.popoverTargetElement;if(o instanceof HTMLElement&&o.popover==="auto")e.setAttribute("aria-expanded",String(t));else{let r=k.get(e);r?e.setAttribute("aria-expanded",r):e.removeAttribute("aria-expanded")}}var q=globalThis.ShadowRoot||function(){};function j(){return typeof HTMLElement<"u"&&typeof HTMLElement.prototype=="object"&&"popover"in HTMLElement.prototype}function g(e,t,o){let r=e[t];Object.defineProperty(e,t,{value(i){return r.call(this,o(i))}})}var X=/(^|[^\\]):popover-open\b/g;function Y(){return typeof globalThis.CSSLayerBlockRule=="function"}function Z(){let e=Y();return` | ||
${e?"@layer popover-polyfill {":""} | ||
@@ -63,3 +63,3 @@ :where([popover]) { | ||
${e?"}":""} | ||
`}var m=null;function I(e){let t=Z();if(m===null)try{m=new CSSStyleSheet,m.replaceSync(t)}catch{m=!1}if(m===!1){let o=document.createElement("style");o.textContent=t,e instanceof Document?e.head.prepend(o):e.prepend(o)}else e.adoptedStyleSheets=[m,...e.adoptedStyleSheets]}function K(){if(typeof window>"u")return;window.ToggleEvent=window.ToggleEvent||c;function e(n){return n?.includes(":popover-open")&&(n=n.replace(X,"$1.\\:popover-open")),n}f(Document.prototype,"querySelector",e),f(Document.prototype,"querySelectorAll",e),f(Element.prototype,"querySelector",e),f(Element.prototype,"querySelectorAll",e),f(Element.prototype,"matches",e),f(Element.prototype,"closest",e),f(DocumentFragment.prototype,"querySelectorAll",e),f(DocumentFragment.prototype,"querySelectorAll",e),Object.defineProperties(HTMLElement.prototype,{popover:{enumerable:!0,configurable:!0,get(){if(!this.hasAttribute("popover"))return null;let n=(this.getAttribute("popover")||"").toLowerCase();return n===""||n=="auto"?"auto":"manual"},set(n){this.setAttribute("popover",n)}},showPopover:{enumerable:!0,configurable:!0,value(){H(this)}},hidePopover:{enumerable:!0,configurable:!0,value(){v(this,!0,!0)}},togglePopover:{enumerable:!0,configurable:!0,value(n){h.get(this)==="showing"&&n===void 0||n===!1?v(this,!0,!0):(n===void 0||n===!0)&&H(this)}}});let t=Element.prototype.attachShadow;t&&Object.defineProperties(Element.prototype,{attachShadow:{enumerable:!0,configurable:!0,writable:!0,value(n){let s=t.call(this,n);return I(s),s}}});let o=HTMLElement.prototype.attachInternals;o&&Object.defineProperties(HTMLElement.prototype,{attachInternals:{enumerable:!0,configurable:!0,writable:!0,value(){let n=o.call(this);return n.shadowRoot&&I(n.shadowRoot),n}}});let r=new WeakMap;function i(n){Object.defineProperties(n.prototype,{popoverTargetElement:{enumerable:!0,configurable:!0,set(s){if(s===null)this.removeAttribute("popovertarget"),r.delete(this);else if(s instanceof Element)this.setAttribute("popovertarget",""),r.set(this,s);else throw new TypeError("popoverTargetElement must be an element or null")},get(){if(this.localName!=="button"&&this.localName!=="input"||this.localName==="input"&&this.type!=="reset"&&this.type!=="image"&&this.type!=="button"||this.disabled||this.form&&this.type==="submit")return null;let s=r.get(this);if(s&&s.isConnected)return s;if(s&&!s.isConnected)return r.delete(this),null;let u=g(this),E=this.getAttribute("popovertarget");return(u instanceof Document||u instanceof C)&&E&&u.getElementById(E)||null}},popoverTargetAction:{enumerable:!0,configurable:!0,get(){let s=(this.getAttribute("popovertargetaction")||"").toLowerCase();return s==="show"||s==="hide"?s:"toggle"},set(s){this.setAttribute("popovertargetaction",s)}}})}i(HTMLButtonElement),i(HTMLInputElement);let l=n=>{let s=n.composedPath(),u=s[0];if(!(u instanceof Element)||u?.shadowRoot)return;let E=g(u);if(!(E instanceof C||E instanceof Document))return;let R=s.find(z=>z.matches?.("[popovertargetaction],[popovertarget]"));if(R){O(R),n.preventDefault();return}},a=n=>{let s=n.key,u=n.target;!n.defaultPrevented&&u&&(s==="Escape"||s==="Esc")&&w(u.ownerDocument,!0,!0)};(n=>{n.addEventListener("click",l),n.addEventListener("keydown",a),n.addEventListener("pointerdown",D),n.addEventListener("pointerup",D)})(document),I(document)}j()||K();})(); | ||
`}var m=null;function I(e){let t=Z();if(m===null)try{m=new CSSStyleSheet,m.replaceSync(t)}catch{m=!1}if(m===!1){let o=document.createElement("style");o.textContent=t,e instanceof Document?e.head.prepend(o):e.prepend(o)}else e.adoptedStyleSheets=[m,...e.adoptedStyleSheets]}function K(){if(typeof window>"u")return;window.ToggleEvent=window.ToggleEvent||c;function e(n){return n?.includes(":popover-open")&&(n=n.replace(X,"$1.\\:popover-open")),n}g(Document.prototype,"querySelector",e),g(Document.prototype,"querySelectorAll",e),g(Element.prototype,"querySelector",e),g(Element.prototype,"querySelectorAll",e),g(Element.prototype,"matches",e),g(Element.prototype,"closest",e),g(DocumentFragment.prototype,"querySelectorAll",e),Object.defineProperties(HTMLElement.prototype,{popover:{enumerable:!0,configurable:!0,get(){if(!this.hasAttribute("popover"))return null;let n=(this.getAttribute("popover")||"").toLowerCase();return n===""||n=="auto"?"auto":"manual"},set(n){this.setAttribute("popover",n)}},showPopover:{enumerable:!0,configurable:!0,value(){H(this)}},hidePopover:{enumerable:!0,configurable:!0,value(){v(this,!0,!0)}},togglePopover:{enumerable:!0,configurable:!0,value(n){h.get(this)==="showing"&&n===void 0||n===!1?v(this,!0,!0):(n===void 0||n===!0)&&H(this)}}});let t=Element.prototype.attachShadow;t&&Object.defineProperties(Element.prototype,{attachShadow:{enumerable:!0,configurable:!0,writable:!0,value(n){let s=t.call(this,n);return I(s),s}}});let o=HTMLElement.prototype.attachInternals;o&&Object.defineProperties(HTMLElement.prototype,{attachInternals:{enumerable:!0,configurable:!0,writable:!0,value(){let n=o.call(this);return n.shadowRoot&&I(n.shadowRoot),n}}});let r=new WeakMap;function i(n){Object.defineProperties(n.prototype,{popoverTargetElement:{enumerable:!0,configurable:!0,set(s){if(s===null)this.removeAttribute("popovertarget"),r.delete(this);else if(s instanceof Element)this.setAttribute("popovertarget",""),r.set(this,s);else throw new TypeError("popoverTargetElement must be an element or null")},get(){if(this.localName!=="button"&&this.localName!=="input"||this.localName==="input"&&this.type!=="reset"&&this.type!=="image"&&this.type!=="button"||this.disabled||this.form&&this.type==="submit")return null;let s=r.get(this);if(s&&s.isConnected)return s;if(s&&!s.isConnected)return r.delete(this),null;let u=d(this),E=this.getAttribute("popovertarget");return(u instanceof Document||u instanceof q)&&E&&u.getElementById(E)||null}},popoverTargetAction:{enumerable:!0,configurable:!0,get(){let s=(this.getAttribute("popovertargetaction")||"").toLowerCase();return s==="show"||s==="hide"?s:"toggle"},set(s){this.setAttribute("popovertargetaction",s)}}})}i(HTMLButtonElement),i(HTMLInputElement);let l=n=>{let s=n.composedPath(),u=s[0];if(!(u instanceof Element)||u?.shadowRoot)return;let E=d(u);if(!(E instanceof q||E instanceof Document))return;let R=s.find(z=>z.matches?.("[popovertargetaction],[popovertarget]"));if(R){O(R),n.preventDefault();return}},a=n=>{let s=n.key,u=n.target;!n.defaultPrevented&&u&&(s==="Escape"||s==="Esc")&&w(u.ownerDocument,!0,!0)};(n=>{n.addEventListener("click",l),n.addEventListener("keydown",a),n.addEventListener("pointerdown",D),n.addEventListener("pointerup",D)})(document),I(document)}j()||K();})(); | ||
//# sourceMappingURL=popover.iife.min.js.map |
@@ -16,4 +16,3 @@ // src/events.ts | ||
setTimeout(() => { | ||
if (!popoverToggleTaskQueue.has(element)) | ||
return; | ||
if (!popoverToggleTaskQueue.has(element)) return; | ||
element.dispatchEvent( | ||
@@ -51,4 +50,3 @@ new ToggleEvent("toggle", { | ||
} | ||
if (element.popoverTargetAction === "hide" && visibility === "hidden") | ||
return; | ||
if (element.popoverTargetAction === "hide" && visibility === "hidden") return; | ||
if (visibility === "showing") { | ||
@@ -65,4 +63,3 @@ hidePopover(popover, true, true); | ||
} | ||
if (!element.isConnected) | ||
return false; | ||
if (!element.isConnected) return false; | ||
if (expectedToBeShowing && getPopoverVisibilityState(element) !== "showing") { | ||
@@ -77,9 +74,7 @@ return false; | ||
} | ||
if (document.fullscreenElement === element) | ||
return false; | ||
if (document.fullscreenElement === element) return false; | ||
return true; | ||
} | ||
function getStackPosition(popover) { | ||
if (!popover) | ||
return 0; | ||
if (!popover) return 0; | ||
return Array.from(autoPopoverList.get(popover.ownerDocument) || []).indexOf( | ||
@@ -112,4 +107,3 @@ popover | ||
} | ||
if (node.parentNode) | ||
return getRootNode(node.parentNode); | ||
if (node.parentNode) return getRootNode(node.parentNode); | ||
return node; | ||
@@ -122,7 +116,5 @@ } | ||
} | ||
node = node.parentElement || getRootNode(node); | ||
if (node instanceof ShadowRoot) | ||
node = node.host; | ||
if (node instanceof Document) | ||
return; | ||
node = node instanceof Element && node.assignedSlot || node.parentElement || getRootNode(node); | ||
if (node instanceof ShadowRoot) node = node.host; | ||
if (node instanceof Document) return; | ||
} | ||
@@ -133,9 +125,6 @@ } | ||
const nodePopover = node.popoverTargetElement; | ||
if (nodePopover instanceof HTMLElement) | ||
return nodePopover; | ||
if (nodePopover instanceof HTMLElement) return nodePopover; | ||
node = node.parentElement || getRootNode(node); | ||
if (node instanceof ShadowRoot) | ||
node = node.host; | ||
if (node instanceof Document) | ||
return; | ||
if (node instanceof ShadowRoot) node = node.host; | ||
if (node instanceof Document) return; | ||
} | ||
@@ -155,4 +144,3 @@ } | ||
const candidateAncestor = nearestInclusiveOpenPopover(candidate); | ||
if (candidateAncestor === null) | ||
return null; | ||
if (candidateAncestor === null) return null; | ||
const candidatePosition = popoverPositions.get(candidateAncestor); | ||
@@ -167,7 +155,5 @@ if (topMostPopoverAncestor2 === null || popoverPositions.get(topMostPopoverAncestor2) < candidatePosition) { | ||
function isFocusable(focusTarget) { | ||
if (focusTarget.hidden || focusTarget instanceof ShadowRoot) | ||
return false; | ||
if (focusTarget.hidden || focusTarget instanceof ShadowRoot) return false; | ||
if (focusTarget instanceof HTMLButtonElement || focusTarget instanceof HTMLInputElement || focusTarget instanceof HTMLSelectElement || focusTarget instanceof HTMLTextAreaElement || focusTarget instanceof HTMLOptGroupElement || focusTarget instanceof HTMLOptionElement || focusTarget instanceof HTMLFieldSetElement) { | ||
if (focusTarget.disabled) | ||
return false; | ||
if (focusTarget.disabled) return false; | ||
} | ||
@@ -345,11 +331,8 @@ if (focusTarget instanceof HTMLInputElement && focusTarget.type === "hidden") { | ||
function lightDismissOpenPopovers(event) { | ||
if (!event.isTrusted) | ||
return; | ||
if (!event.isTrusted) return; | ||
const target = event.composedPath()[0]; | ||
if (!target) | ||
return; | ||
if (!target) return; | ||
const document2 = target.ownerDocument; | ||
const topMostPopover = topMostAutoPopover(document2); | ||
if (!topMostPopover) | ||
return; | ||
if (!topMostPopover) return; | ||
const ancestor = topMostClickedPopover(target); | ||
@@ -368,4 +351,3 @@ if (ancestor && event.type === "pointerdown") { | ||
function setInvokerAriaExpanded(el, force = false) { | ||
if (!el) | ||
return; | ||
if (!el) return; | ||
if (!initialAriaExpandedValue.has(el)) { | ||
@@ -495,4 +477,3 @@ initialAriaExpandedValue.set(el, el.getAttribute("aria-expanded")); | ||
function apply() { | ||
if (typeof window === "undefined") | ||
return; | ||
if (typeof window === "undefined") return; | ||
window.ToggleEvent = window.ToggleEvent || ToggleEvent; | ||
@@ -519,7 +500,2 @@ function rewriteSelector(selector) { | ||
); | ||
patchSelectorFn( | ||
DocumentFragment.prototype, | ||
"querySelectorAll", | ||
rewriteSelector | ||
); | ||
Object.defineProperties(HTMLElement.prototype, { | ||
@@ -530,7 +506,5 @@ popover: { | ||
get() { | ||
if (!this.hasAttribute("popover")) | ||
return null; | ||
if (!this.hasAttribute("popover")) return null; | ||
const value = (this.getAttribute("popover") || "").toLowerCase(); | ||
if (value === "" || value == "auto") | ||
return "auto"; | ||
if (value === "" || value == "auto") return "auto"; | ||
return "manual"; | ||
@@ -652,4 +626,3 @@ }, | ||
const value = (this.getAttribute("popovertargetaction") || "").toLowerCase(); | ||
if (value === "show" || value === "hide") | ||
return value; | ||
if (value === "show" || value === "hide") return value; | ||
return "toggle"; | ||
@@ -702,4 +675,3 @@ }, | ||
// src/index.ts | ||
if (!isSupported()) | ||
apply(); | ||
if (!isSupported()) apply(); | ||
//# sourceMappingURL=popover.js.map |
@@ -1,2 +0,2 @@ | ||
var c=class extends Event{oldState;newState;constructor(t,{oldState:o="",newState:r="",...i}={}){super(t,i),this.oldState=String(o||""),this.newState=String(r||"")}},N=new WeakMap;function P(e,t,o){N.set(e,setTimeout(()=>{N.has(e)&&e.dispatchEvent(new c("toggle",{cancelable:!1,oldState:t,newState:o}))},0))}var x=globalThis.ShadowRoot||function(){},V=globalThis.HTMLDialogElement||function(){},y=new WeakMap,p=new WeakMap,h=new WeakMap;function b(e){return h.get(e)||"hidden"}var L=new WeakMap;function O(e){let t=e.popoverTargetElement;if(!(t instanceof HTMLElement))return;let o=b(t);e.popoverTargetAction==="show"&&o==="showing"||e.popoverTargetAction==="hide"&&o==="hidden"||(o==="showing"?v(t,!0,!0):d(t,!1)&&(L.set(t,e),H(t)))}function d(e,t){return!(e.popover!=="auto"&&e.popover!=="manual"||!e.isConnected||t&&b(e)!=="showing"||!t&&b(e)!=="hidden"||e instanceof V&&e.hasAttribute("open")||document.fullscreenElement===e)}function F(e){return e?Array.from(p.get(e.ownerDocument)||[]).indexOf(e)+1:0}function $(e){let t=W(e),o=U(e);return F(t)>F(o)?t:o}function M(e){let t=p.get(e);for(let o of t||[])if(!o.isConnected)t.delete(o);else return o;return null}function g(e){return typeof e.getRootNode=="function"?e.getRootNode():e.parentNode?g(e.parentNode):e}function W(e){for(;e;){if(e instanceof HTMLElement&&e.popover==="auto"&&h.get(e)==="showing")return e;if(e=e.parentElement||g(e),e instanceof x&&(e=e.host),e instanceof Document)return}}function U(e){for(;e;){let t=e.popoverTargetElement;if(t instanceof HTMLElement)return t;if(e=e.parentElement||g(e),e instanceof x&&(e=e.host),e instanceof Document)return}}function G(e){let t=new Map,o=0;for(let l of p.get(e.ownerDocument)||[])t.set(l,o),o+=1;t.set(e,o),o+=1;let r=null;function i(l){let a=W(l);if(a===null)return null;let T=t.get(a);(r===null||t.get(r)<T)&&(r=a)}return i(e.parentElement||g(e)),r}function Q(e){return e.hidden||e instanceof x||(e instanceof HTMLButtonElement||e instanceof HTMLInputElement||e instanceof HTMLSelectElement||e instanceof HTMLTextAreaElement||e instanceof HTMLOptGroupElement||e instanceof HTMLOptionElement||e instanceof HTMLFieldSetElement)&&e.disabled||e instanceof HTMLInputElement&&e.type==="hidden"||e instanceof HTMLAnchorElement&&e.href===""?!1:typeof e.tabIndex=="number"&&e.tabIndex!==-1}function _(e){if(e.shadowRoot&&e.shadowRoot.delegatesFocus!==!0)return null;let t=e;t.shadowRoot&&(t=t.shadowRoot);let o=t.querySelector("[autofocus]");if(o)return o;{let l=t.querySelectorAll("slot");for(let a of l){let T=a.assignedElements({flatten:!0});for(let n of T){if(n.hasAttribute("autofocus"))return n;if(o=n.querySelector("[autofocus]"),o)return o}}}let r=e.ownerDocument.createTreeWalker(t,NodeFilter.SHOW_ELEMENT),i=r.currentNode;for(;i;){if(Q(i))return i;i=r.nextNode()}}function J(e){_(e)?.focus()}var S=new WeakMap;function H(e){if(!d(e,!1))return;let t=e.ownerDocument;if(!e.dispatchEvent(new c("beforetoggle",{cancelable:!0,oldState:"closed",newState:"open"}))||!d(e,!1))return;let o=!1;if(e.popover==="auto"){let i=e.getAttribute("popover"),l=G(e)||t;if(w(l,!1,!0),i!==e.getAttribute("popover")||!d(e,!1))return}M(t)||(o=!0),S.delete(e);let r=t.activeElement;e.classList.add(":popover-open"),h.set(e,"showing"),y.has(t)||y.set(t,new Set),y.get(t).add(e),J(e),e.popover==="auto"&&(p.has(t)||p.set(t,new Set),p.get(t).add(e),q(L.get(e),!0)),o&&r&&e.popover==="auto"&&S.set(e,r),P(e,"closed","open")}function v(e,t=!1,o=!1){if(!d(e,!0))return;let r=e.ownerDocument;if(e.popover==="auto"&&(w(e,t,o),!d(e,!0))||(q(L.get(e),!1),L.delete(e),o&&(e.dispatchEvent(new c("beforetoggle",{oldState:"open",newState:"closed"})),!d(e,!0))))return;y.get(r)?.delete(e),p.get(r)?.delete(e),e.classList.remove(":popover-open"),h.set(e,"hidden"),o&&P(e,"open","closed");let i=S.get(e);i&&(S.delete(e),t&&i.focus())}function B(e,t=!1,o=!1){let r=M(e);for(;r;)v(r,t,o),r=M(e)}function w(e,t,o){let r=e.ownerDocument||e;if(e instanceof Document)return B(r,t,o);let i=null,l=!1;for(let a of p.get(r)||[])if(a===e)l=!0;else if(l){i=a;break}if(!l)return B(r,t,o);for(;i&&b(i)==="showing"&&p.get(r)?.size;)v(i,t,o)}var A=new WeakMap;function D(e){if(!e.isTrusted)return;let t=e.composedPath()[0];if(!t)return;let o=t.ownerDocument;if(!M(o))return;let i=$(t);if(i&&e.type==="pointerdown")A.set(o,i);else if(e.type==="pointerup"){let l=A.get(o)===i;A.delete(o),l&&w(i||o,!1,!0)}}var k=new WeakMap;function q(e,t=!1){if(!e)return;k.has(e)||k.set(e,e.getAttribute("aria-expanded"));let o=e.popoverTargetElement;if(o instanceof HTMLElement&&o.popover==="auto")e.setAttribute("aria-expanded",String(t));else{let r=k.get(e);r?e.setAttribute("aria-expanded",r):e.removeAttribute("aria-expanded")}}var C=globalThis.ShadowRoot||function(){};function j(){return typeof HTMLElement<"u"&&typeof HTMLElement.prototype=="object"&&"popover"in HTMLElement.prototype}function f(e,t,o){let r=e[t];Object.defineProperty(e,t,{value(i){return r.call(this,o(i))}})}var X=/(^|[^\\]):popover-open\b/g;function Y(){return typeof globalThis.CSSLayerBlockRule=="function"}function Z(){let e=Y();return` | ||
var c=class extends Event{oldState;newState;constructor(t,{oldState:o="",newState:r="",...i}={}){super(t,i),this.oldState=String(o||""),this.newState=String(r||"")}},N=new WeakMap;function P(e,t,o){N.set(e,setTimeout(()=>{N.has(e)&&e.dispatchEvent(new c("toggle",{cancelable:!1,oldState:t,newState:o}))},0))}var x=globalThis.ShadowRoot||function(){},V=globalThis.HTMLDialogElement||function(){},b=new WeakMap,p=new WeakMap,h=new WeakMap;function y(e){return h.get(e)||"hidden"}var L=new WeakMap;function O(e){let t=e.popoverTargetElement;if(!(t instanceof HTMLElement))return;let o=y(t);e.popoverTargetAction==="show"&&o==="showing"||e.popoverTargetAction==="hide"&&o==="hidden"||(o==="showing"?v(t,!0,!0):f(t,!1)&&(L.set(t,e),H(t)))}function f(e,t){return!(e.popover!=="auto"&&e.popover!=="manual"||!e.isConnected||t&&y(e)!=="showing"||!t&&y(e)!=="hidden"||e instanceof V&&e.hasAttribute("open")||document.fullscreenElement===e)}function F(e){return e?Array.from(p.get(e.ownerDocument)||[]).indexOf(e)+1:0}function $(e){let t=W(e),o=U(e);return F(t)>F(o)?t:o}function M(e){let t=p.get(e);for(let o of t||[])if(!o.isConnected)t.delete(o);else return o;return null}function d(e){return typeof e.getRootNode=="function"?e.getRootNode():e.parentNode?d(e.parentNode):e}function W(e){for(;e;){if(e instanceof HTMLElement&&e.popover==="auto"&&h.get(e)==="showing")return e;if(e=e instanceof Element&&e.assignedSlot||e.parentElement||d(e),e instanceof x&&(e=e.host),e instanceof Document)return}}function U(e){for(;e;){let t=e.popoverTargetElement;if(t instanceof HTMLElement)return t;if(e=e.parentElement||d(e),e instanceof x&&(e=e.host),e instanceof Document)return}}function G(e){let t=new Map,o=0;for(let l of p.get(e.ownerDocument)||[])t.set(l,o),o+=1;t.set(e,o),o+=1;let r=null;function i(l){let a=W(l);if(a===null)return null;let T=t.get(a);(r===null||t.get(r)<T)&&(r=a)}return i(e.parentElement||d(e)),r}function Q(e){return e.hidden||e instanceof x||(e instanceof HTMLButtonElement||e instanceof HTMLInputElement||e instanceof HTMLSelectElement||e instanceof HTMLTextAreaElement||e instanceof HTMLOptGroupElement||e instanceof HTMLOptionElement||e instanceof HTMLFieldSetElement)&&e.disabled||e instanceof HTMLInputElement&&e.type==="hidden"||e instanceof HTMLAnchorElement&&e.href===""?!1:typeof e.tabIndex=="number"&&e.tabIndex!==-1}function _(e){if(e.shadowRoot&&e.shadowRoot.delegatesFocus!==!0)return null;let t=e;t.shadowRoot&&(t=t.shadowRoot);let o=t.querySelector("[autofocus]");if(o)return o;{let l=t.querySelectorAll("slot");for(let a of l){let T=a.assignedElements({flatten:!0});for(let n of T){if(n.hasAttribute("autofocus"))return n;if(o=n.querySelector("[autofocus]"),o)return o}}}let r=e.ownerDocument.createTreeWalker(t,NodeFilter.SHOW_ELEMENT),i=r.currentNode;for(;i;){if(Q(i))return i;i=r.nextNode()}}function J(e){_(e)?.focus()}var S=new WeakMap;function H(e){if(!f(e,!1))return;let t=e.ownerDocument;if(!e.dispatchEvent(new c("beforetoggle",{cancelable:!0,oldState:"closed",newState:"open"}))||!f(e,!1))return;let o=!1;if(e.popover==="auto"){let i=e.getAttribute("popover"),l=G(e)||t;if(w(l,!1,!0),i!==e.getAttribute("popover")||!f(e,!1))return}M(t)||(o=!0),S.delete(e);let r=t.activeElement;e.classList.add(":popover-open"),h.set(e,"showing"),b.has(t)||b.set(t,new Set),b.get(t).add(e),J(e),e.popover==="auto"&&(p.has(t)||p.set(t,new Set),p.get(t).add(e),C(L.get(e),!0)),o&&r&&e.popover==="auto"&&S.set(e,r),P(e,"closed","open")}function v(e,t=!1,o=!1){if(!f(e,!0))return;let r=e.ownerDocument;if(e.popover==="auto"&&(w(e,t,o),!f(e,!0))||(C(L.get(e),!1),L.delete(e),o&&(e.dispatchEvent(new c("beforetoggle",{oldState:"open",newState:"closed"})),!f(e,!0))))return;b.get(r)?.delete(e),p.get(r)?.delete(e),e.classList.remove(":popover-open"),h.set(e,"hidden"),o&&P(e,"open","closed");let i=S.get(e);i&&(S.delete(e),t&&i.focus())}function B(e,t=!1,o=!1){let r=M(e);for(;r;)v(r,t,o),r=M(e)}function w(e,t,o){let r=e.ownerDocument||e;if(e instanceof Document)return B(r,t,o);let i=null,l=!1;for(let a of p.get(r)||[])if(a===e)l=!0;else if(l){i=a;break}if(!l)return B(r,t,o);for(;i&&y(i)==="showing"&&p.get(r)?.size;)v(i,t,o)}var A=new WeakMap;function D(e){if(!e.isTrusted)return;let t=e.composedPath()[0];if(!t)return;let o=t.ownerDocument;if(!M(o))return;let i=$(t);if(i&&e.type==="pointerdown")A.set(o,i);else if(e.type==="pointerup"){let l=A.get(o)===i;A.delete(o),l&&w(i||o,!1,!0)}}var k=new WeakMap;function C(e,t=!1){if(!e)return;k.has(e)||k.set(e,e.getAttribute("aria-expanded"));let o=e.popoverTargetElement;if(o instanceof HTMLElement&&o.popover==="auto")e.setAttribute("aria-expanded",String(t));else{let r=k.get(e);r?e.setAttribute("aria-expanded",r):e.removeAttribute("aria-expanded")}}var q=globalThis.ShadowRoot||function(){};function j(){return typeof HTMLElement<"u"&&typeof HTMLElement.prototype=="object"&&"popover"in HTMLElement.prototype}function g(e,t,o){let r=e[t];Object.defineProperty(e,t,{value(i){return r.call(this,o(i))}})}var X=/(^|[^\\]):popover-open\b/g;function Y(){return typeof globalThis.CSSLayerBlockRule=="function"}function Z(){let e=Y();return` | ||
${e?"@layer popover-polyfill {":""} | ||
@@ -63,3 +63,3 @@ :where([popover]) { | ||
${e?"}":""} | ||
`}var m=null;function I(e){let t=Z();if(m===null)try{m=new CSSStyleSheet,m.replaceSync(t)}catch{m=!1}if(m===!1){let o=document.createElement("style");o.textContent=t,e instanceof Document?e.head.prepend(o):e.prepend(o)}else e.adoptedStyleSheets=[m,...e.adoptedStyleSheets]}function K(){if(typeof window>"u")return;window.ToggleEvent=window.ToggleEvent||c;function e(n){return n?.includes(":popover-open")&&(n=n.replace(X,"$1.\\:popover-open")),n}f(Document.prototype,"querySelector",e),f(Document.prototype,"querySelectorAll",e),f(Element.prototype,"querySelector",e),f(Element.prototype,"querySelectorAll",e),f(Element.prototype,"matches",e),f(Element.prototype,"closest",e),f(DocumentFragment.prototype,"querySelectorAll",e),f(DocumentFragment.prototype,"querySelectorAll",e),Object.defineProperties(HTMLElement.prototype,{popover:{enumerable:!0,configurable:!0,get(){if(!this.hasAttribute("popover"))return null;let n=(this.getAttribute("popover")||"").toLowerCase();return n===""||n=="auto"?"auto":"manual"},set(n){this.setAttribute("popover",n)}},showPopover:{enumerable:!0,configurable:!0,value(){H(this)}},hidePopover:{enumerable:!0,configurable:!0,value(){v(this,!0,!0)}},togglePopover:{enumerable:!0,configurable:!0,value(n){h.get(this)==="showing"&&n===void 0||n===!1?v(this,!0,!0):(n===void 0||n===!0)&&H(this)}}});let t=Element.prototype.attachShadow;t&&Object.defineProperties(Element.prototype,{attachShadow:{enumerable:!0,configurable:!0,writable:!0,value(n){let s=t.call(this,n);return I(s),s}}});let o=HTMLElement.prototype.attachInternals;o&&Object.defineProperties(HTMLElement.prototype,{attachInternals:{enumerable:!0,configurable:!0,writable:!0,value(){let n=o.call(this);return n.shadowRoot&&I(n.shadowRoot),n}}});let r=new WeakMap;function i(n){Object.defineProperties(n.prototype,{popoverTargetElement:{enumerable:!0,configurable:!0,set(s){if(s===null)this.removeAttribute("popovertarget"),r.delete(this);else if(s instanceof Element)this.setAttribute("popovertarget",""),r.set(this,s);else throw new TypeError("popoverTargetElement must be an element or null")},get(){if(this.localName!=="button"&&this.localName!=="input"||this.localName==="input"&&this.type!=="reset"&&this.type!=="image"&&this.type!=="button"||this.disabled||this.form&&this.type==="submit")return null;let s=r.get(this);if(s&&s.isConnected)return s;if(s&&!s.isConnected)return r.delete(this),null;let u=g(this),E=this.getAttribute("popovertarget");return(u instanceof Document||u instanceof C)&&E&&u.getElementById(E)||null}},popoverTargetAction:{enumerable:!0,configurable:!0,get(){let s=(this.getAttribute("popovertargetaction")||"").toLowerCase();return s==="show"||s==="hide"?s:"toggle"},set(s){this.setAttribute("popovertargetaction",s)}}})}i(HTMLButtonElement),i(HTMLInputElement);let l=n=>{let s=n.composedPath(),u=s[0];if(!(u instanceof Element)||u?.shadowRoot)return;let E=g(u);if(!(E instanceof C||E instanceof Document))return;let R=s.find(z=>z.matches?.("[popovertargetaction],[popovertarget]"));if(R){O(R),n.preventDefault();return}},a=n=>{let s=n.key,u=n.target;!n.defaultPrevented&&u&&(s==="Escape"||s==="Esc")&&w(u.ownerDocument,!0,!0)};(n=>{n.addEventListener("click",l),n.addEventListener("keydown",a),n.addEventListener("pointerdown",D),n.addEventListener("pointerup",D)})(document),I(document)}j()||K(); | ||
`}var m=null;function I(e){let t=Z();if(m===null)try{m=new CSSStyleSheet,m.replaceSync(t)}catch{m=!1}if(m===!1){let o=document.createElement("style");o.textContent=t,e instanceof Document?e.head.prepend(o):e.prepend(o)}else e.adoptedStyleSheets=[m,...e.adoptedStyleSheets]}function K(){if(typeof window>"u")return;window.ToggleEvent=window.ToggleEvent||c;function e(n){return n?.includes(":popover-open")&&(n=n.replace(X,"$1.\\:popover-open")),n}g(Document.prototype,"querySelector",e),g(Document.prototype,"querySelectorAll",e),g(Element.prototype,"querySelector",e),g(Element.prototype,"querySelectorAll",e),g(Element.prototype,"matches",e),g(Element.prototype,"closest",e),g(DocumentFragment.prototype,"querySelectorAll",e),Object.defineProperties(HTMLElement.prototype,{popover:{enumerable:!0,configurable:!0,get(){if(!this.hasAttribute("popover"))return null;let n=(this.getAttribute("popover")||"").toLowerCase();return n===""||n=="auto"?"auto":"manual"},set(n){this.setAttribute("popover",n)}},showPopover:{enumerable:!0,configurable:!0,value(){H(this)}},hidePopover:{enumerable:!0,configurable:!0,value(){v(this,!0,!0)}},togglePopover:{enumerable:!0,configurable:!0,value(n){h.get(this)==="showing"&&n===void 0||n===!1?v(this,!0,!0):(n===void 0||n===!0)&&H(this)}}});let t=Element.prototype.attachShadow;t&&Object.defineProperties(Element.prototype,{attachShadow:{enumerable:!0,configurable:!0,writable:!0,value(n){let s=t.call(this,n);return I(s),s}}});let o=HTMLElement.prototype.attachInternals;o&&Object.defineProperties(HTMLElement.prototype,{attachInternals:{enumerable:!0,configurable:!0,writable:!0,value(){let n=o.call(this);return n.shadowRoot&&I(n.shadowRoot),n}}});let r=new WeakMap;function i(n){Object.defineProperties(n.prototype,{popoverTargetElement:{enumerable:!0,configurable:!0,set(s){if(s===null)this.removeAttribute("popovertarget"),r.delete(this);else if(s instanceof Element)this.setAttribute("popovertarget",""),r.set(this,s);else throw new TypeError("popoverTargetElement must be an element or null")},get(){if(this.localName!=="button"&&this.localName!=="input"||this.localName==="input"&&this.type!=="reset"&&this.type!=="image"&&this.type!=="button"||this.disabled||this.form&&this.type==="submit")return null;let s=r.get(this);if(s&&s.isConnected)return s;if(s&&!s.isConnected)return r.delete(this),null;let u=d(this),E=this.getAttribute("popovertarget");return(u instanceof Document||u instanceof q)&&E&&u.getElementById(E)||null}},popoverTargetAction:{enumerable:!0,configurable:!0,get(){let s=(this.getAttribute("popovertargetaction")||"").toLowerCase();return s==="show"||s==="hide"?s:"toggle"},set(s){this.setAttribute("popovertargetaction",s)}}})}i(HTMLButtonElement),i(HTMLInputElement);let l=n=>{let s=n.composedPath(),u=s[0];if(!(u instanceof Element)||u?.shadowRoot)return;let E=d(u);if(!(E instanceof q||E instanceof Document))return;let R=s.find(z=>z.matches?.("[popovertargetaction],[popovertarget]"));if(R){O(R),n.preventDefault();return}},a=n=>{let s=n.key,u=n.target;!n.defaultPrevented&&u&&(s==="Escape"||s==="Esc")&&w(u.ownerDocument,!0,!0)};(n=>{n.addEventListener("click",l),n.addEventListener("keydown",a),n.addEventListener("pointerdown",D),n.addEventListener("pointerup",D)})(document),I(document)}j()||K(); | ||
//# sourceMappingURL=popover.min.js.map |
{ | ||
"name": "@oddbird/popover-polyfill", | ||
"version": "0.4.3", | ||
"version": "0.4.4", | ||
"description": "Popover Attribute Polyfill", | ||
@@ -82,2 +82,3 @@ "license": "BSD-3-Clause", | ||
"test:ci": "run-p test:unit test:e2e:ci", | ||
"test:ui": "npm run test:e2e -- --ui", | ||
"prepare": "husky", | ||
@@ -89,5 +90,5 @@ "prepack": "npm run build" | ||
"@types/node": "*", | ||
"@typescript-eslint/eslint-plugin": "^7.7.1", | ||
"@typescript-eslint/parser": "^7.7.1", | ||
"esbuild": "^0.20.2", | ||
"@typescript-eslint/eslint-plugin": "^7.17.0", | ||
"@typescript-eslint/parser": "^7.17.0", | ||
"esbuild": "^0.23.0", | ||
"eslint": "^8.57.0", | ||
@@ -97,9 +98,9 @@ "eslint-config-prettier": "^9.1.0", | ||
"eslint-plugin-import": "^2.29.1", | ||
"eslint-plugin-simple-import-sort": "^12.1.0", | ||
"husky": "^9.0.11", | ||
"lint-staged": "^15.2.2", | ||
"eslint-plugin-simple-import-sort": "^12.1.1", | ||
"husky": "^9.1.1", | ||
"lint-staged": "^15.2.7", | ||
"npm-run-all": "^4.1.5", | ||
"prettier": "3.2.5", | ||
"prettier": "3.3.3", | ||
"ts-node": "^10.9.2", | ||
"typescript": "^5.4.5" | ||
"typescript": "^5.5.3" | ||
}, | ||
@@ -106,0 +107,0 @@ "lint-staged": { |
@@ -168,2 +168,5 @@ # Popover Attribute Polyfill | ||
- The polyfill will not work in browsers with partial popover support enabled, | ||
and will also not attempt to make experimental support match the final spec. | ||
## Contributing | ||
@@ -170,0 +173,0 @@ |
@@ -116,3 +116,6 @@ import { queuePopoverToggleEventTask, ToggleEvent } from './events.js'; | ||
} | ||
node = node.parentElement || getRootNode(node); | ||
node = | ||
(node instanceof Element && node.assignedSlot) || | ||
node.parentElement || | ||
getRootNode(node); | ||
if (node instanceof ShadowRoot) node = node.host; | ||
@@ -119,0 +122,0 @@ if (node instanceof Document) return; |
@@ -170,7 +170,2 @@ import { ToggleEvent } from './events.js'; | ||
); | ||
patchSelectorFn( | ||
DocumentFragment.prototype, | ||
'querySelectorAll', | ||
rewriteSelector, | ||
); | ||
@@ -177,0 +172,0 @@ Object.defineProperties(HTMLElement.prototype, { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
187
268781
2434