Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@oddbird/popover-polyfill

Package Overview
Dependencies
Maintainers
3
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@oddbird/popover-polyfill - npm Package Compare versions

Comparing version 0.2.0 to 0.2.1

10

dist/popover-fn.js

@@ -88,3 +88,11 @@ // src/events.ts

function topMostAutoPopover(document2) {
return Array.from(autoPopoverList.get(document2) || []).pop() || null;
const documentPopovers = autoPopoverList.get(document2);
for (const popover of documentPopovers || []) {
if (!popover.isConnected) {
documentPopovers.delete(popover);
} else {
return popover;
}
}
return null;
}

@@ -91,0 +99,0 @@ function nearestInclusiveOpenPopover(node) {

2

dist/popover.iife.min.js

@@ -1,2 +0,2 @@

"use strict";(()=>{var p=class extends Event{constructor(o,{oldState:i="",newState:r="",...l}={}){super(o,l);this.oldState=String(i||""),this.newState=String(r||"")}},S=new WeakMap;function H(e,t,o){S.set(e,setTimeout(()=>{S.has(e)&&e.dispatchEvent(new p("toggle",{cancelable:!1,oldState:t,newState:o}))},0))}var m=new WeakMap,a=new WeakMap,d=new WeakMap;function h(e){return d.get(e)||"hidden"}var T=new WeakMap;function D(e){let t=e.popoverTargetElement;if(!t)return;let o=h(t);e.popoverTargetAction==="show"&&o==="showing"||e.popoverTargetAction==="hide"&&o==="hidden"||(o==="showing"?g(t,!0,!0):f(t,!1)&&(T.set(t,e),w(t)))}function f(e,t){return!(e.popover!=="auto"&&e.popover!=="manual"||!e.isConnected||t&&h(e)!=="showing"||!t&&h(e)!=="hidden"||e instanceof HTMLDialogElement&&e.hasAttribute("open")||document.fullscreenElement===e)}function P(e){return e?Array.from(a.get(e.ownerDocument)||[]).indexOf(e)+1:0}function N(e){let t=x(e),o=W(e);return P(t)>P(o)?t:o}function M(e){return Array.from(a.get(e)||[]).pop()||null}function x(e){for(;e;){if(e instanceof HTMLElement&&e.popover==="auto"&&d.get(e)==="showing")return e;if(e=e.parentElement||e.getRootNode(),e instanceof ShadowRoot&&(e=e.host),e instanceof Document)return}}function W(e){for(;e;){let t=e.popoverTargetElement;if(t)return t;if(e=e.parentElement||e.getRootNode(),e instanceof ShadowRoot&&(e=e.host),e instanceof Document)return}}function B(e){let t=new Map,o=0,i=e.ownerDocument;for(let n of a.get(i)||[])t.set(n,o),o+=1;t.set(e,o),o+=1;let r=null;function l(n){let s=x(n);if(s===null)return null;let u=t.get(s);(r===null||t.get(r)<u)&&(r=s)}return l(e?.parentElement),r}function O(e){return e.hidden||(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:e.tabIndex!==-1}function q(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 i=e.ownerDocument.createTreeWalker(t,NodeFilter.SHOW_ELEMENT),r=i.currentNode;for(;r;){if(O(r))return r;r=i.nextNode()}}function C(e){q(e)?.focus()}var L=new WeakMap;function w(e){if(!f(e,!1))return;let t=e.ownerDocument;if(!e.dispatchEvent(new p("beforetoggle",{cancelable:!0,oldState:"closed",newState:"open"}))||!f(e,!1))return;let o=!1;if(e.popover==="auto"){let r=e.getAttribute("popover"),l=B(e)||t;if(E(l,!1,!0),r!==e.getAttribute("popover")||!f(e,!1))return}M(t)||(o=!0),L.delete(e);let i=t.activeElement;e.classList.add(":popover-open"),d.set(e,"showing"),m.has(t)||m.set(t,new Set),m.get(t).add(e),C(e),e.popover==="auto"&&(a.has(t)||a.set(t,new Set),a.get(t).add(e),I(T.get(e),!0)),o&&i&&e.popover==="auto"&&L.set(e,i),H(e,"closed","open")}function g(e,t=!1,o=!1){if(!f(e,!0))return;let i=e.ownerDocument;if(e.popover==="auto"&&(E(e,t,o),!f(e,!0))||(I(T.get(e),!1),T.delete(e),o&&(e.dispatchEvent(new p("beforetoggle",{oldState:"open",newState:"closed"})),!f(e,!0))))return;m.get(i)?.delete(e),a.get(i)?.delete(e),e.classList.remove(":popover-open"),d.set(e,"hidden"),o&&H(e,"open","closed");let r=L.get(e);r&&(L.delete(e),t&&r.focus())}function k(e,t=!1,o=!1){let i=M(e);for(;i;)g(i,t,o),i=M(e)}function E(e,t,o){let i=e.ownerDocument||e;if(e instanceof Document)return k(i,t,o);let r=null,l=!1;for(let n of a.get(i)||[])if(n===e)l=!0;else if(l){r=n;break}if(!l)return k(i,t,o);for(;r&&h(r)==="showing"&&a.get(i)?.size;)g(r,t,o)}var b=new WeakMap;function A(e){if(!e.isTrusted)return;let t=e.composedPath()[0];if(!t)return;let o=t.ownerDocument;if(!M(o))return;let r=N(t);if(r&&e.type==="pointerdown")b.set(o,r);else if(e.type==="pointerup"){let l=b.get(o)===r;b.delete(o),l&&E(r||o,!1,!0)}}var y=new WeakMap;function I(e,t=!1){if(!e)return;y.has(e)||y.set(e,e.getAttribute("aria-expanded"));let o=e.popoverTargetElement;if(o&&o.popover==="auto")e.setAttribute("aria-expanded",String(t));else{let i=y.get(e);i?e.setAttribute("aria-expanded",i):e.removeAttribute("aria-expanded")}}function R(){return typeof HTMLElement<"u"&&typeof HTMLElement.prototype=="object"&&"popover"in HTMLElement.prototype}function c(e,t,o){let i=e[t];Object.defineProperty(e,t,{value(r){return i.call(this,o(r))}})}var K=/(^|[^\\]):popover-open\b/g;function F(){window.ToggleEvent=window.ToggleEvent||p;function e(n){return n.includes(":popover-open")&&(n=n.replace(K,"$1.\\:popover-open")),n}c(Document.prototype,"querySelector",e),c(Document.prototype,"querySelectorAll",e),c(Element.prototype,"querySelector",e),c(Element.prototype,"querySelectorAll",e),c(Element.prototype,"matches",e),c(Element.prototype,"closest",e),c(DocumentFragment.prototype,"querySelectorAll",e),c(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(){w(this)}},hidePopover:{enumerable:!0,configurable:!0,value(){g(this,!0,!0)}},togglePopover:{enumerable:!0,configurable:!0,value(n){d.get(this)==="showing"&&n===void 0||n===!1?g(this,!0,!0):(n===void 0||n===!0)&&w(this)}}});let t=new WeakMap;function o(n){Object.defineProperties(n.prototype,{popoverTargetElement:{enumerable:!0,configurable:!0,set(s){if(s===null)this.removeAttribute("popovertarget"),t.delete(this);else if(s instanceof Element)this.setAttribute("popovertarget",""),t.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=t.get(this);if(s&&s.isConnected)return s;if(s&&!s.isConnected)return t.delete(this),null;let u=this.getRootNode(),v=this.getAttribute("popovertarget");return(u instanceof Document||u instanceof ShadowRoot)&&v&&u.getElementById(v)||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)}}})}o(HTMLButtonElement),o(HTMLInputElement);let i=n=>{if(!n.isTrusted)return;let s=n.composedPath()[0];if(!(s instanceof Element)||s?.shadowRoot)return;let u=s.getRootNode();if(!(u instanceof ShadowRoot||u instanceof Document))return;let v=s.closest("[popovertargetaction],[popovertarget]");if(v){D(v);return}},r=n=>{let s=n.key,u=n.target;u&&(s==="Escape"||s==="Esc")&&E(u.ownerDocument,!0,!0)};(n=>{n.addEventListener("click",i),n.addEventListener("keydown",r),n.addEventListener("pointerdown",A),n.addEventListener("pointerup",A)})(document)}R()||F();})();
"use strict";(()=>{var p=class extends Event{constructor(o,{oldState:i="",newState:r="",...l}={}){super(o,l);this.oldState=String(i||""),this.newState=String(r||"")}},S=new WeakMap;function H(e,t,o){S.set(e,setTimeout(()=>{S.has(e)&&e.dispatchEvent(new p("toggle",{cancelable:!1,oldState:t,newState:o}))},0))}var m=new WeakMap,a=new WeakMap,d=new WeakMap;function h(e){return d.get(e)||"hidden"}var T=new WeakMap;function D(e){let t=e.popoverTargetElement;if(!t)return;let o=h(t);e.popoverTargetAction==="show"&&o==="showing"||e.popoverTargetAction==="hide"&&o==="hidden"||(o==="showing"?g(t,!0,!0):f(t,!1)&&(T.set(t,e),w(t)))}function f(e,t){return!(e.popover!=="auto"&&e.popover!=="manual"||!e.isConnected||t&&h(e)!=="showing"||!t&&h(e)!=="hidden"||e instanceof HTMLDialogElement&&e.hasAttribute("open")||document.fullscreenElement===e)}function A(e){return e?Array.from(a.get(e.ownerDocument)||[]).indexOf(e)+1:0}function N(e){let t=x(e),o=W(e);return A(t)>A(o)?t:o}function M(e){let t=a.get(e);for(let o of t||[])if(!o.isConnected)t.delete(o);else return o;return null}function x(e){for(;e;){if(e instanceof HTMLElement&&e.popover==="auto"&&d.get(e)==="showing")return e;if(e=e.parentElement||e.getRootNode(),e instanceof ShadowRoot&&(e=e.host),e instanceof Document)return}}function W(e){for(;e;){let t=e.popoverTargetElement;if(t)return t;if(e=e.parentElement||e.getRootNode(),e instanceof ShadowRoot&&(e=e.host),e instanceof Document)return}}function B(e){let t=new Map,o=0,i=e.ownerDocument;for(let n of a.get(i)||[])t.set(n,o),o+=1;t.set(e,o),o+=1;let r=null;function l(n){let s=x(n);if(s===null)return null;let u=t.get(s);(r===null||t.get(r)<u)&&(r=s)}return l(e?.parentElement),r}function O(e){return e.hidden||(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:e.tabIndex!==-1}function q(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 i=e.ownerDocument.createTreeWalker(t,NodeFilter.SHOW_ELEMENT),r=i.currentNode;for(;r;){if(O(r))return r;r=i.nextNode()}}function C(e){q(e)?.focus()}var L=new WeakMap;function w(e){if(!f(e,!1))return;let t=e.ownerDocument;if(!e.dispatchEvent(new p("beforetoggle",{cancelable:!0,oldState:"closed",newState:"open"}))||!f(e,!1))return;let o=!1;if(e.popover==="auto"){let r=e.getAttribute("popover"),l=B(e)||t;if(E(l,!1,!0),r!==e.getAttribute("popover")||!f(e,!1))return}M(t)||(o=!0),L.delete(e);let i=t.activeElement;e.classList.add(":popover-open"),d.set(e,"showing"),m.has(t)||m.set(t,new Set),m.get(t).add(e),C(e),e.popover==="auto"&&(a.has(t)||a.set(t,new Set),a.get(t).add(e),I(T.get(e),!0)),o&&i&&e.popover==="auto"&&L.set(e,i),H(e,"closed","open")}function g(e,t=!1,o=!1){if(!f(e,!0))return;let i=e.ownerDocument;if(e.popover==="auto"&&(E(e,t,o),!f(e,!0))||(I(T.get(e),!1),T.delete(e),o&&(e.dispatchEvent(new p("beforetoggle",{oldState:"open",newState:"closed"})),!f(e,!0))))return;m.get(i)?.delete(e),a.get(i)?.delete(e),e.classList.remove(":popover-open"),d.set(e,"hidden"),o&&H(e,"open","closed");let r=L.get(e);r&&(L.delete(e),t&&r.focus())}function k(e,t=!1,o=!1){let i=M(e);for(;i;)g(i,t,o),i=M(e)}function E(e,t,o){let i=e.ownerDocument||e;if(e instanceof Document)return k(i,t,o);let r=null,l=!1;for(let n of a.get(i)||[])if(n===e)l=!0;else if(l){r=n;break}if(!l)return k(i,t,o);for(;r&&h(r)==="showing"&&a.get(i)?.size;)g(r,t,o)}var b=new WeakMap;function P(e){if(!e.isTrusted)return;let t=e.composedPath()[0];if(!t)return;let o=t.ownerDocument;if(!M(o))return;let r=N(t);if(r&&e.type==="pointerdown")b.set(o,r);else if(e.type==="pointerup"){let l=b.get(o)===r;b.delete(o),l&&E(r||o,!1,!0)}}var y=new WeakMap;function I(e,t=!1){if(!e)return;y.has(e)||y.set(e,e.getAttribute("aria-expanded"));let o=e.popoverTargetElement;if(o&&o.popover==="auto")e.setAttribute("aria-expanded",String(t));else{let i=y.get(e);i?e.setAttribute("aria-expanded",i):e.removeAttribute("aria-expanded")}}function R(){return typeof HTMLElement<"u"&&typeof HTMLElement.prototype=="object"&&"popover"in HTMLElement.prototype}function c(e,t,o){let i=e[t];Object.defineProperty(e,t,{value(r){return i.call(this,o(r))}})}var K=/(^|[^\\]):popover-open\b/g;function F(){window.ToggleEvent=window.ToggleEvent||p;function e(n){return n.includes(":popover-open")&&(n=n.replace(K,"$1.\\:popover-open")),n}c(Document.prototype,"querySelector",e),c(Document.prototype,"querySelectorAll",e),c(Element.prototype,"querySelector",e),c(Element.prototype,"querySelectorAll",e),c(Element.prototype,"matches",e),c(Element.prototype,"closest",e),c(DocumentFragment.prototype,"querySelectorAll",e),c(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(){w(this)}},hidePopover:{enumerable:!0,configurable:!0,value(){g(this,!0,!0)}},togglePopover:{enumerable:!0,configurable:!0,value(n){d.get(this)==="showing"&&n===void 0||n===!1?g(this,!0,!0):(n===void 0||n===!0)&&w(this)}}});let t=new WeakMap;function o(n){Object.defineProperties(n.prototype,{popoverTargetElement:{enumerable:!0,configurable:!0,set(s){if(s===null)this.removeAttribute("popovertarget"),t.delete(this);else if(s instanceof Element)this.setAttribute("popovertarget",""),t.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=t.get(this);if(s&&s.isConnected)return s;if(s&&!s.isConnected)return t.delete(this),null;let u=this.getRootNode(),v=this.getAttribute("popovertarget");return(u instanceof Document||u instanceof ShadowRoot)&&v&&u.getElementById(v)||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)}}})}o(HTMLButtonElement),o(HTMLInputElement);let i=n=>{if(!n.isTrusted)return;let s=n.composedPath()[0];if(!(s instanceof Element)||s?.shadowRoot)return;let u=s.getRootNode();if(!(u instanceof ShadowRoot||u instanceof Document))return;let v=s.closest("[popovertargetaction],[popovertarget]");if(v){D(v);return}},r=n=>{let s=n.key,u=n.target;u&&(s==="Escape"||s==="Esc")&&E(u.ownerDocument,!0,!0)};(n=>{n.addEventListener("click",i),n.addEventListener("keydown",r),n.addEventListener("pointerdown",P),n.addEventListener("pointerup",P)})(document)}R()||F();})();
//# sourceMappingURL=popover.iife.min.js.map

@@ -88,3 +88,11 @@ // src/events.ts

function topMostAutoPopover(document2) {
return Array.from(autoPopoverList.get(document2) || []).pop() || null;
const documentPopovers = autoPopoverList.get(document2);
for (const popover of documentPopovers || []) {
if (!popover.isConnected) {
documentPopovers.delete(popover);
} else {
return popover;
}
}
return null;
}

@@ -91,0 +99,0 @@ function nearestInclusiveOpenPopover(node) {

@@ -1,2 +0,2 @@

var p=class extends Event{constructor(o,{oldState:i="",newState:r="",...l}={}){super(o,l);this.oldState=String(i||""),this.newState=String(r||"")}},S=new WeakMap;function H(e,t,o){S.set(e,setTimeout(()=>{S.has(e)&&e.dispatchEvent(new p("toggle",{cancelable:!1,oldState:t,newState:o}))},0))}var m=new WeakMap,a=new WeakMap,d=new WeakMap;function h(e){return d.get(e)||"hidden"}var T=new WeakMap;function D(e){let t=e.popoverTargetElement;if(!t)return;let o=h(t);e.popoverTargetAction==="show"&&o==="showing"||e.popoverTargetAction==="hide"&&o==="hidden"||(o==="showing"?g(t,!0,!0):f(t,!1)&&(T.set(t,e),w(t)))}function f(e,t){return!(e.popover!=="auto"&&e.popover!=="manual"||!e.isConnected||t&&h(e)!=="showing"||!t&&h(e)!=="hidden"||e instanceof HTMLDialogElement&&e.hasAttribute("open")||document.fullscreenElement===e)}function P(e){return e?Array.from(a.get(e.ownerDocument)||[]).indexOf(e)+1:0}function N(e){let t=x(e),o=W(e);return P(t)>P(o)?t:o}function M(e){return Array.from(a.get(e)||[]).pop()||null}function x(e){for(;e;){if(e instanceof HTMLElement&&e.popover==="auto"&&d.get(e)==="showing")return e;if(e=e.parentElement||e.getRootNode(),e instanceof ShadowRoot&&(e=e.host),e instanceof Document)return}}function W(e){for(;e;){let t=e.popoverTargetElement;if(t)return t;if(e=e.parentElement||e.getRootNode(),e instanceof ShadowRoot&&(e=e.host),e instanceof Document)return}}function B(e){let t=new Map,o=0,i=e.ownerDocument;for(let n of a.get(i)||[])t.set(n,o),o+=1;t.set(e,o),o+=1;let r=null;function l(n){let s=x(n);if(s===null)return null;let u=t.get(s);(r===null||t.get(r)<u)&&(r=s)}return l(e?.parentElement),r}function O(e){return e.hidden||(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:e.tabIndex!==-1}function q(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 i=e.ownerDocument.createTreeWalker(t,NodeFilter.SHOW_ELEMENT),r=i.currentNode;for(;r;){if(O(r))return r;r=i.nextNode()}}function C(e){q(e)?.focus()}var L=new WeakMap;function w(e){if(!f(e,!1))return;let t=e.ownerDocument;if(!e.dispatchEvent(new p("beforetoggle",{cancelable:!0,oldState:"closed",newState:"open"}))||!f(e,!1))return;let o=!1;if(e.popover==="auto"){let r=e.getAttribute("popover"),l=B(e)||t;if(E(l,!1,!0),r!==e.getAttribute("popover")||!f(e,!1))return}M(t)||(o=!0),L.delete(e);let i=t.activeElement;e.classList.add(":popover-open"),d.set(e,"showing"),m.has(t)||m.set(t,new Set),m.get(t).add(e),C(e),e.popover==="auto"&&(a.has(t)||a.set(t,new Set),a.get(t).add(e),I(T.get(e),!0)),o&&i&&e.popover==="auto"&&L.set(e,i),H(e,"closed","open")}function g(e,t=!1,o=!1){if(!f(e,!0))return;let i=e.ownerDocument;if(e.popover==="auto"&&(E(e,t,o),!f(e,!0))||(I(T.get(e),!1),T.delete(e),o&&(e.dispatchEvent(new p("beforetoggle",{oldState:"open",newState:"closed"})),!f(e,!0))))return;m.get(i)?.delete(e),a.get(i)?.delete(e),e.classList.remove(":popover-open"),d.set(e,"hidden"),o&&H(e,"open","closed");let r=L.get(e);r&&(L.delete(e),t&&r.focus())}function k(e,t=!1,o=!1){let i=M(e);for(;i;)g(i,t,o),i=M(e)}function E(e,t,o){let i=e.ownerDocument||e;if(e instanceof Document)return k(i,t,o);let r=null,l=!1;for(let n of a.get(i)||[])if(n===e)l=!0;else if(l){r=n;break}if(!l)return k(i,t,o);for(;r&&h(r)==="showing"&&a.get(i)?.size;)g(r,t,o)}var b=new WeakMap;function A(e){if(!e.isTrusted)return;let t=e.composedPath()[0];if(!t)return;let o=t.ownerDocument;if(!M(o))return;let r=N(t);if(r&&e.type==="pointerdown")b.set(o,r);else if(e.type==="pointerup"){let l=b.get(o)===r;b.delete(o),l&&E(r||o,!1,!0)}}var y=new WeakMap;function I(e,t=!1){if(!e)return;y.has(e)||y.set(e,e.getAttribute("aria-expanded"));let o=e.popoverTargetElement;if(o&&o.popover==="auto")e.setAttribute("aria-expanded",String(t));else{let i=y.get(e);i?e.setAttribute("aria-expanded",i):e.removeAttribute("aria-expanded")}}function R(){return typeof HTMLElement<"u"&&typeof HTMLElement.prototype=="object"&&"popover"in HTMLElement.prototype}function c(e,t,o){let i=e[t];Object.defineProperty(e,t,{value(r){return i.call(this,o(r))}})}var K=/(^|[^\\]):popover-open\b/g;function F(){window.ToggleEvent=window.ToggleEvent||p;function e(n){return n.includes(":popover-open")&&(n=n.replace(K,"$1.\\:popover-open")),n}c(Document.prototype,"querySelector",e),c(Document.prototype,"querySelectorAll",e),c(Element.prototype,"querySelector",e),c(Element.prototype,"querySelectorAll",e),c(Element.prototype,"matches",e),c(Element.prototype,"closest",e),c(DocumentFragment.prototype,"querySelectorAll",e),c(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(){w(this)}},hidePopover:{enumerable:!0,configurable:!0,value(){g(this,!0,!0)}},togglePopover:{enumerable:!0,configurable:!0,value(n){d.get(this)==="showing"&&n===void 0||n===!1?g(this,!0,!0):(n===void 0||n===!0)&&w(this)}}});let t=new WeakMap;function o(n){Object.defineProperties(n.prototype,{popoverTargetElement:{enumerable:!0,configurable:!0,set(s){if(s===null)this.removeAttribute("popovertarget"),t.delete(this);else if(s instanceof Element)this.setAttribute("popovertarget",""),t.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=t.get(this);if(s&&s.isConnected)return s;if(s&&!s.isConnected)return t.delete(this),null;let u=this.getRootNode(),v=this.getAttribute("popovertarget");return(u instanceof Document||u instanceof ShadowRoot)&&v&&u.getElementById(v)||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)}}})}o(HTMLButtonElement),o(HTMLInputElement);let i=n=>{if(!n.isTrusted)return;let s=n.composedPath()[0];if(!(s instanceof Element)||s?.shadowRoot)return;let u=s.getRootNode();if(!(u instanceof ShadowRoot||u instanceof Document))return;let v=s.closest("[popovertargetaction],[popovertarget]");if(v){D(v);return}},r=n=>{let s=n.key,u=n.target;u&&(s==="Escape"||s==="Esc")&&E(u.ownerDocument,!0,!0)};(n=>{n.addEventListener("click",i),n.addEventListener("keydown",r),n.addEventListener("pointerdown",A),n.addEventListener("pointerup",A)})(document)}R()||F();
var p=class extends Event{constructor(o,{oldState:i="",newState:r="",...l}={}){super(o,l);this.oldState=String(i||""),this.newState=String(r||"")}},S=new WeakMap;function H(e,t,o){S.set(e,setTimeout(()=>{S.has(e)&&e.dispatchEvent(new p("toggle",{cancelable:!1,oldState:t,newState:o}))},0))}var m=new WeakMap,a=new WeakMap,d=new WeakMap;function h(e){return d.get(e)||"hidden"}var T=new WeakMap;function D(e){let t=e.popoverTargetElement;if(!t)return;let o=h(t);e.popoverTargetAction==="show"&&o==="showing"||e.popoverTargetAction==="hide"&&o==="hidden"||(o==="showing"?g(t,!0,!0):f(t,!1)&&(T.set(t,e),w(t)))}function f(e,t){return!(e.popover!=="auto"&&e.popover!=="manual"||!e.isConnected||t&&h(e)!=="showing"||!t&&h(e)!=="hidden"||e instanceof HTMLDialogElement&&e.hasAttribute("open")||document.fullscreenElement===e)}function A(e){return e?Array.from(a.get(e.ownerDocument)||[]).indexOf(e)+1:0}function N(e){let t=x(e),o=W(e);return A(t)>A(o)?t:o}function M(e){let t=a.get(e);for(let o of t||[])if(!o.isConnected)t.delete(o);else return o;return null}function x(e){for(;e;){if(e instanceof HTMLElement&&e.popover==="auto"&&d.get(e)==="showing")return e;if(e=e.parentElement||e.getRootNode(),e instanceof ShadowRoot&&(e=e.host),e instanceof Document)return}}function W(e){for(;e;){let t=e.popoverTargetElement;if(t)return t;if(e=e.parentElement||e.getRootNode(),e instanceof ShadowRoot&&(e=e.host),e instanceof Document)return}}function B(e){let t=new Map,o=0,i=e.ownerDocument;for(let n of a.get(i)||[])t.set(n,o),o+=1;t.set(e,o),o+=1;let r=null;function l(n){let s=x(n);if(s===null)return null;let u=t.get(s);(r===null||t.get(r)<u)&&(r=s)}return l(e?.parentElement),r}function O(e){return e.hidden||(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:e.tabIndex!==-1}function q(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 i=e.ownerDocument.createTreeWalker(t,NodeFilter.SHOW_ELEMENT),r=i.currentNode;for(;r;){if(O(r))return r;r=i.nextNode()}}function C(e){q(e)?.focus()}var L=new WeakMap;function w(e){if(!f(e,!1))return;let t=e.ownerDocument;if(!e.dispatchEvent(new p("beforetoggle",{cancelable:!0,oldState:"closed",newState:"open"}))||!f(e,!1))return;let o=!1;if(e.popover==="auto"){let r=e.getAttribute("popover"),l=B(e)||t;if(E(l,!1,!0),r!==e.getAttribute("popover")||!f(e,!1))return}M(t)||(o=!0),L.delete(e);let i=t.activeElement;e.classList.add(":popover-open"),d.set(e,"showing"),m.has(t)||m.set(t,new Set),m.get(t).add(e),C(e),e.popover==="auto"&&(a.has(t)||a.set(t,new Set),a.get(t).add(e),I(T.get(e),!0)),o&&i&&e.popover==="auto"&&L.set(e,i),H(e,"closed","open")}function g(e,t=!1,o=!1){if(!f(e,!0))return;let i=e.ownerDocument;if(e.popover==="auto"&&(E(e,t,o),!f(e,!0))||(I(T.get(e),!1),T.delete(e),o&&(e.dispatchEvent(new p("beforetoggle",{oldState:"open",newState:"closed"})),!f(e,!0))))return;m.get(i)?.delete(e),a.get(i)?.delete(e),e.classList.remove(":popover-open"),d.set(e,"hidden"),o&&H(e,"open","closed");let r=L.get(e);r&&(L.delete(e),t&&r.focus())}function k(e,t=!1,o=!1){let i=M(e);for(;i;)g(i,t,o),i=M(e)}function E(e,t,o){let i=e.ownerDocument||e;if(e instanceof Document)return k(i,t,o);let r=null,l=!1;for(let n of a.get(i)||[])if(n===e)l=!0;else if(l){r=n;break}if(!l)return k(i,t,o);for(;r&&h(r)==="showing"&&a.get(i)?.size;)g(r,t,o)}var b=new WeakMap;function P(e){if(!e.isTrusted)return;let t=e.composedPath()[0];if(!t)return;let o=t.ownerDocument;if(!M(o))return;let r=N(t);if(r&&e.type==="pointerdown")b.set(o,r);else if(e.type==="pointerup"){let l=b.get(o)===r;b.delete(o),l&&E(r||o,!1,!0)}}var y=new WeakMap;function I(e,t=!1){if(!e)return;y.has(e)||y.set(e,e.getAttribute("aria-expanded"));let o=e.popoverTargetElement;if(o&&o.popover==="auto")e.setAttribute("aria-expanded",String(t));else{let i=y.get(e);i?e.setAttribute("aria-expanded",i):e.removeAttribute("aria-expanded")}}function R(){return typeof HTMLElement<"u"&&typeof HTMLElement.prototype=="object"&&"popover"in HTMLElement.prototype}function c(e,t,o){let i=e[t];Object.defineProperty(e,t,{value(r){return i.call(this,o(r))}})}var K=/(^|[^\\]):popover-open\b/g;function F(){window.ToggleEvent=window.ToggleEvent||p;function e(n){return n.includes(":popover-open")&&(n=n.replace(K,"$1.\\:popover-open")),n}c(Document.prototype,"querySelector",e),c(Document.prototype,"querySelectorAll",e),c(Element.prototype,"querySelector",e),c(Element.prototype,"querySelectorAll",e),c(Element.prototype,"matches",e),c(Element.prototype,"closest",e),c(DocumentFragment.prototype,"querySelectorAll",e),c(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(){w(this)}},hidePopover:{enumerable:!0,configurable:!0,value(){g(this,!0,!0)}},togglePopover:{enumerable:!0,configurable:!0,value(n){d.get(this)==="showing"&&n===void 0||n===!1?g(this,!0,!0):(n===void 0||n===!0)&&w(this)}}});let t=new WeakMap;function o(n){Object.defineProperties(n.prototype,{popoverTargetElement:{enumerable:!0,configurable:!0,set(s){if(s===null)this.removeAttribute("popovertarget"),t.delete(this);else if(s instanceof Element)this.setAttribute("popovertarget",""),t.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=t.get(this);if(s&&s.isConnected)return s;if(s&&!s.isConnected)return t.delete(this),null;let u=this.getRootNode(),v=this.getAttribute("popovertarget");return(u instanceof Document||u instanceof ShadowRoot)&&v&&u.getElementById(v)||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)}}})}o(HTMLButtonElement),o(HTMLInputElement);let i=n=>{if(!n.isTrusted)return;let s=n.composedPath()[0];if(!(s instanceof Element)||s?.shadowRoot)return;let u=s.getRootNode();if(!(u instanceof ShadowRoot||u instanceof Document))return;let v=s.closest("[popovertargetaction],[popovertarget]");if(v){D(v);return}},r=n=>{let s=n.key,u=n.target;u&&(s==="Escape"||s==="Esc")&&E(u.ownerDocument,!0,!0)};(n=>{n.addEventListener("click",i),n.addEventListener("keydown",r),n.addEventListener("pointerdown",P),n.addEventListener("pointerup",P)})(document)}R()||F();
//# sourceMappingURL=popover.min.js.map
{
"name": "@oddbird/popover-polyfill",
"version": "0.2.0",
"version": "0.2.1",
"description": "Popover Attribute Polyfill",

@@ -37,3 +37,5 @@ "license": "BSD-3-Clause",

"import": "./dist/popover-fn.js"
}
},
"./css": "./dist/popover.css",
"./dist/popover.css": "./dist/popover.css"
},

@@ -90,10 +92,10 @@ "typesVersions": {

"devDependencies": {
"@playwright/test": "^1.32.2",
"@playwright/test": "^1.33.0",
"@types/node": "*",
"@typescript-eslint/eslint-plugin": "^5.57.1",
"@typescript-eslint/parser": "^5.57.1",
"esbuild": "^0.17.15",
"eslint": "^8.37.0",
"@typescript-eslint/eslint-plugin": "^5.59.5",
"@typescript-eslint/parser": "^5.59.5",
"esbuild": "^0.17.19",
"eslint": "^8.40.0",
"eslint-config-prettier": "^8.8.0",
"eslint-import-resolver-typescript": "^3.5.4",
"eslint-import-resolver-typescript": "^3.5.5",
"eslint-plugin-import": "^2.27.5",

@@ -103,10 +105,10 @@ "eslint-plugin-prettier": "^4.2.1",

"husky": "^8.0.3",
"lint-staged": "^13.2.0",
"lint-staged": "^13.2.2",
"npm-run-all": "^4.1.5",
"prettier": "^2.8.7",
"stylelint": "^15.4.0",
"stylelint-config-standard": "^32.0.0",
"stylis": "^4.1.3",
"prettier": "^2.8.8",
"stylelint": "^15.6.1",
"stylelint-config-standard": "^33.0.0",
"stylis": "^4.2.0",
"ts-node": "^10.9.1",
"typescript": "^5.0.3"
"typescript": "^5.0.4"
},

@@ -113,0 +115,0 @@ "lint-staged": {

@@ -78,3 +78,12 @@ import { queuePopoverToggleEventTask, ToggleEvent } from './events.js';

function topMostAutoPopover(document: Document): HTMLElement | null {
return Array.from(autoPopoverList.get(document) || []).pop() || null;
const documentPopovers = autoPopoverList.get(document);
for (const popover of documentPopovers || []) {
if (!popover.isConnected) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
documentPopovers!.delete(popover);
} else {
return popover;
}
}
return null;
}

@@ -81,0 +90,0 @@

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc