@oddbird/popover-polyfill
Advanced tools
Comparing version 0.3.1 to 0.3.2
interface PopoverToggleTargetElementInvoker { | ||
popoverTargetElement: HTMLElement | null; | ||
popoverTargetAction: 'toggle' | 'show' | 'hide'; | ||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLButtonElement/popoverTargetAction) */ | ||
popoverTargetAction: string; | ||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLButtonElement/popoverTargetElement) */ | ||
popoverTargetElement: Element | null; | ||
} | ||
declare global { | ||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/ToggleEvent) */ | ||
interface ToggleEvent extends Event { | ||
oldState: string; | ||
newState: string; | ||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/ToggleEvent/newState) */ | ||
readonly newState: string; | ||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/ToggleEvent/oldState) */ | ||
readonly oldState: string; | ||
} | ||
interface HTMLElement { | ||
popover: 'auto' | 'manual' | null; | ||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLElement/popover) */ | ||
popover: string | null; | ||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLElement/hidePopover) */ | ||
hidePopover(): void; | ||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLElement/showPopover) */ | ||
showPopover(): void; | ||
hidePopover(): void; | ||
togglePopover(): void; | ||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLElement/togglePopover) */ | ||
togglePopover(force?: boolean): void; | ||
} | ||
@@ -16,0 +25,0 @@ interface HTMLButtonElement extends PopoverToggleTargetElementInvoker { |
interface PopoverToggleTargetElementInvoker { | ||
popoverTargetElement: HTMLElement | null; | ||
popoverTargetAction: 'toggle' | 'show' | 'hide'; | ||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLButtonElement/popoverTargetAction) */ | ||
popoverTargetAction: string; | ||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLButtonElement/popoverTargetElement) */ | ||
popoverTargetElement: Element | null; | ||
} | ||
declare global { | ||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/ToggleEvent) */ | ||
interface ToggleEvent extends Event { | ||
oldState: string; | ||
newState: string; | ||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/ToggleEvent/newState) */ | ||
readonly newState: string; | ||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/ToggleEvent/oldState) */ | ||
readonly oldState: string; | ||
} | ||
interface HTMLElement { | ||
popover: 'auto' | 'manual' | null; | ||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLElement/popover) */ | ||
popover: string | null; | ||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLElement/hidePopover) */ | ||
hidePopover(): void; | ||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLElement/showPopover) */ | ||
showPopover(): void; | ||
hidePopover(): void; | ||
togglePopover(): void; | ||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLElement/togglePopover) */ | ||
togglePopover(force?: boolean): void; | ||
} | ||
@@ -16,0 +25,0 @@ interface HTMLButtonElement extends PopoverToggleTargetElementInvoker { |
@@ -43,3 +43,3 @@ // src/events.ts | ||
const popover = element.popoverTargetElement; | ||
if (!popover) { | ||
if (!(popover instanceof HTMLElement)) { | ||
return; | ||
@@ -128,3 +128,3 @@ } | ||
const nodePopover = node.popoverTargetElement; | ||
if (nodePopover) | ||
if (nodePopover instanceof HTMLElement) | ||
return nodePopover; | ||
@@ -352,3 +352,3 @@ node = node.parentElement || getRootNode(node); | ||
const popover = el.popoverTargetElement; | ||
if (popover && popover.popover === "auto") { | ||
if (popover instanceof HTMLElement && popover.popover === "auto") { | ||
el.setAttribute("aria-expanded", String(force)); | ||
@@ -355,0 +355,0 @@ } else { |
@@ -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||"")}},I=new WeakMap;function P(e,t,o){I.set(e,setTimeout(()=>{I.has(e)&&e.dispatchEvent(new c("toggle",{cancelable:!1,oldState:t,newState:o}))},0))}var F=globalThis.ShadowRoot||function(){},z=globalThis.HTMLDialogElement||function(){},M=new WeakMap,u=new WeakMap,g=new WeakMap;function L(e){return g.get(e)||"hidden"}var b=new WeakMap;function O(e){let t=e.popoverTargetElement;if(!t)return;let o=L(t);e.popoverTargetAction==="show"&&o==="showing"||e.popoverTargetAction==="hide"&&o==="hidden"||(o==="showing"?h(t,!0,!0):d(t,!1)&&(b.set(t,e),S(t)))}function d(e,t){return!(e.popover!=="auto"&&e.popover!=="manual"||!e.isConnected||t&&L(e)!=="showing"||!t&&L(e)!=="hidden"||e instanceof z&&e.hasAttribute("open")||document.fullscreenElement===e)}function R(e){return e?Array.from(u.get(e.ownerDocument)||[]).indexOf(e)+1:0}function V(e){let t=W(e),o=U(e);return R(t)>R(o)?t:o}function y(e){let t=u.get(e);for(let o of t||[])if(!o.isConnected)t.delete(o);else return o;return null}function v(e){return typeof e.getRootNode=="function"?e.getRootNode():e.parentNode?v(e.parentNode):e}function W(e){for(;e;){if(e instanceof HTMLElement&&e.popover==="auto"&&g.get(e)==="showing")return e;if(e=e.parentElement||v(e),e instanceof F&&(e=e.host),e instanceof Document)return}}function U(e){for(;e;){let t=e.popoverTargetElement;if(t)return t;if(e=e.parentElement||v(e),e instanceof F&&(e=e.host),e instanceof Document)return}}function G(e){let t=new Map,o=0,r=e.ownerDocument;for(let p of u.get(r)||[])t.set(p,o),o+=1;t.set(e,o),o+=1;let i=null;function l(p){let w=W(p);if(w===null)return null;let n=t.get(w);(i===null||t.get(i)<n)&&(i=w)}return l(e?.parentElement),i}function Q(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 _(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 r=e.ownerDocument.createTreeWalker(t,NodeFilter.SHOW_ELEMENT),i=r.currentNode;for(;i;){if(Q(i))return i;i=r.nextNode()}}function $(e){_(e)?.focus()}var H=new WeakMap;function S(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(T(l,!1,!0),i!==e.getAttribute("popover")||!d(e,!1))return}y(t)||(o=!0),H.delete(e);let r=t.activeElement;e.classList.add(":popover-open"),g.set(e,"showing"),M.has(t)||M.set(t,new Set),M.get(t).add(e),$(e),e.popover==="auto"&&(u.has(t)||u.set(t,new Set),u.get(t).add(e),B(b.get(e),!0)),o&&r&&e.popover==="auto"&&H.set(e,r),P(e,"closed","open")}function h(e,t=!1,o=!1){if(!d(e,!0))return;let r=e.ownerDocument;if(e.popover==="auto"&&(T(e,t,o),!d(e,!0))||(B(b.get(e),!1),b.delete(e),o&&(e.dispatchEvent(new c("beforetoggle",{oldState:"open",newState:"closed"})),!d(e,!0))))return;M.get(r)?.delete(e),u.get(r)?.delete(e),e.classList.remove(":popover-open"),g.set(e,"hidden"),o&&P(e,"open","closed");let i=H.get(e);i&&(H.delete(e),t&&i.focus())}function N(e,t=!1,o=!1){let r=y(e);for(;r;)h(r,t,o),r=y(e)}function T(e,t,o){let r=e.ownerDocument||e;if(e instanceof Document)return N(r,t,o);let i=null,l=!1;for(let p of u.get(r)||[])if(p===e)l=!0;else if(l){i=p;break}if(!l)return N(r,t,o);for(;i&&L(i)==="showing"&&u.get(r)?.size;)h(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(!y(o))return;let i=V(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&&T(i||o,!1,!0)}}var k=new WeakMap;function B(e,t=!1){if(!e)return;k.has(e)||k.set(e,e.getAttribute("aria-expanded"));let o=e.popoverTargetElement;if(o&&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 J=/(^|[^\\]):popover-open\b/g,q=` | ||
"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||"")}},I=new WeakMap;function P(e,t,o){I.set(e,setTimeout(()=>{I.has(e)&&e.dispatchEvent(new c("toggle",{cancelable:!1,oldState:t,newState:o}))},0))}var F=globalThis.ShadowRoot||function(){},z=globalThis.HTMLDialogElement||function(){},M=new WeakMap,p=new WeakMap,g=new WeakMap;function L(e){return g.get(e)||"hidden"}var b=new WeakMap;function O(e){let t=e.popoverTargetElement;if(!(t instanceof HTMLElement))return;let o=L(t);e.popoverTargetAction==="show"&&o==="showing"||e.popoverTargetAction==="hide"&&o==="hidden"||(o==="showing"?h(t,!0,!0):d(t,!1)&&(b.set(t,e),S(t)))}function d(e,t){return!(e.popover!=="auto"&&e.popover!=="manual"||!e.isConnected||t&&L(e)!=="showing"||!t&&L(e)!=="hidden"||e instanceof z&&e.hasAttribute("open")||document.fullscreenElement===e)}function R(e){return e?Array.from(p.get(e.ownerDocument)||[]).indexOf(e)+1:0}function V(e){let t=W(e),o=U(e);return R(t)>R(o)?t:o}function y(e){let t=p.get(e);for(let o of t||[])if(!o.isConnected)t.delete(o);else return o;return null}function v(e){return typeof e.getRootNode=="function"?e.getRootNode():e.parentNode?v(e.parentNode):e}function W(e){for(;e;){if(e instanceof HTMLElement&&e.popover==="auto"&&g.get(e)==="showing")return e;if(e=e.parentElement||v(e),e instanceof F&&(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||v(e),e instanceof F&&(e=e.host),e instanceof Document)return}}function G(e){let t=new Map,o=0,r=e.ownerDocument;for(let u of p.get(r)||[])t.set(u,o),o+=1;t.set(e,o),o+=1;let i=null;function l(u){let w=W(u);if(w===null)return null;let n=t.get(w);(i===null||t.get(i)<n)&&(i=w)}return l(e?.parentElement),i}function Q(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 _(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 r=e.ownerDocument.createTreeWalker(t,NodeFilter.SHOW_ELEMENT),i=r.currentNode;for(;i;){if(Q(i))return i;i=r.nextNode()}}function $(e){_(e)?.focus()}var H=new WeakMap;function S(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(T(l,!1,!0),i!==e.getAttribute("popover")||!d(e,!1))return}y(t)||(o=!0),H.delete(e);let r=t.activeElement;e.classList.add(":popover-open"),g.set(e,"showing"),M.has(t)||M.set(t,new Set),M.get(t).add(e),$(e),e.popover==="auto"&&(p.has(t)||p.set(t,new Set),p.get(t).add(e),B(b.get(e),!0)),o&&r&&e.popover==="auto"&&H.set(e,r),P(e,"closed","open")}function h(e,t=!1,o=!1){if(!d(e,!0))return;let r=e.ownerDocument;if(e.popover==="auto"&&(T(e,t,o),!d(e,!0))||(B(b.get(e),!1),b.delete(e),o&&(e.dispatchEvent(new c("beforetoggle",{oldState:"open",newState:"closed"})),!d(e,!0))))return;M.get(r)?.delete(e),p.get(r)?.delete(e),e.classList.remove(":popover-open"),g.set(e,"hidden"),o&&P(e,"open","closed");let i=H.get(e);i&&(H.delete(e),t&&i.focus())}function N(e,t=!1,o=!1){let r=y(e);for(;r;)h(r,t,o),r=y(e)}function T(e,t,o){let r=e.ownerDocument||e;if(e instanceof Document)return N(r,t,o);let i=null,l=!1;for(let u of p.get(r)||[])if(u===e)l=!0;else if(l){i=u;break}if(!l)return N(r,t,o);for(;i&&L(i)==="showing"&&p.get(r)?.size;)h(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(!y(o))return;let i=V(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&&T(i||o,!1,!0)}}var k=new WeakMap;function B(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 J=/(^|[^\\]):popover-open\b/g,q=` | ||
[popover] { | ||
@@ -57,3 +57,3 @@ position: fixed; | ||
} | ||
`,m=null;function x(e){if(m===null)try{m=new CSSStyleSheet,m.replaceSync(q)}catch{m=!1}if(m===!1){let t=document.createElement("style");t.textContent=q,e instanceof Document?e.head.append(t):e.append(t)}else e.adoptedStyleSheets=[...e.adoptedStyleSheets,m]}function K(){window.ToggleEvent=window.ToggleEvent||c;function e(n){return n?.includes(":popover-open")&&(n=n.replace(J,"$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(){S(this)}},hidePopover:{enumerable:!0,configurable:!0,value(){h(this,!0,!0)}},togglePopover:{enumerable:!0,configurable:!0,value(n){g.get(this)==="showing"&&n===void 0||n===!1?h(this,!0,!0):(n===void 0||n===!0)&&S(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 x(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&&x(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 a=v(this),E=this.getAttribute("popovertarget");return(a instanceof Document||a instanceof C)&&E&&a.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=>{if(!n.isTrusted)return;let s=n.composedPath()[0];if(!(s instanceof Element)||s?.shadowRoot)return;let a=v(s);if(!(a instanceof C||a instanceof Document))return;let E=s.closest("[popovertargetaction],[popovertarget]");if(E){O(E);return}},p=n=>{let s=n.key,a=n.target;a&&(s==="Escape"||s==="Esc")&&T(a.ownerDocument,!0,!0)};(n=>{n.addEventListener("click",l),n.addEventListener("keydown",p),n.addEventListener("pointerdown",D),n.addEventListener("pointerup",D)})(document),x(document)}j()||K();})(); | ||
`,m=null;function x(e){if(m===null)try{m=new CSSStyleSheet,m.replaceSync(q)}catch{m=!1}if(m===!1){let t=document.createElement("style");t.textContent=q,e instanceof Document?e.head.append(t):e.append(t)}else e.adoptedStyleSheets=[...e.adoptedStyleSheets,m]}function K(){window.ToggleEvent=window.ToggleEvent||c;function e(n){return n?.includes(":popover-open")&&(n=n.replace(J,"$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(){S(this)}},hidePopover:{enumerable:!0,configurable:!0,value(){h(this,!0,!0)}},togglePopover:{enumerable:!0,configurable:!0,value(n){g.get(this)==="showing"&&n===void 0||n===!1?h(this,!0,!0):(n===void 0||n===!0)&&S(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 x(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&&x(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 a=v(this),E=this.getAttribute("popovertarget");return(a instanceof Document||a instanceof C)&&E&&a.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=>{if(!n.isTrusted)return;let s=n.composedPath()[0];if(!(s instanceof Element)||s?.shadowRoot)return;let a=v(s);if(!(a instanceof C||a instanceof Document))return;let E=s.closest("[popovertargetaction],[popovertarget]");if(E){O(E);return}},u=n=>{let s=n.key,a=n.target;a&&(s==="Escape"||s==="Esc")&&T(a.ownerDocument,!0,!0)};(n=>{n.addEventListener("click",l),n.addEventListener("keydown",u),n.addEventListener("pointerdown",D),n.addEventListener("pointerup",D)})(document),x(document)}j()||K();})(); | ||
//# sourceMappingURL=popover.iife.min.js.map |
@@ -43,3 +43,3 @@ // src/events.ts | ||
const popover = element.popoverTargetElement; | ||
if (!popover) { | ||
if (!(popover instanceof HTMLElement)) { | ||
return; | ||
@@ -128,3 +128,3 @@ } | ||
const nodePopover = node.popoverTargetElement; | ||
if (nodePopover) | ||
if (nodePopover instanceof HTMLElement) | ||
return nodePopover; | ||
@@ -352,3 +352,3 @@ node = node.parentElement || getRootNode(node); | ||
const popover = el.popoverTargetElement; | ||
if (popover && popover.popover === "auto") { | ||
if (popover instanceof HTMLElement && popover.popover === "auto") { | ||
el.setAttribute("aria-expanded", String(force)); | ||
@@ -355,0 +355,0 @@ } else { |
@@ -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||"")}},I=new WeakMap;function P(e,t,o){I.set(e,setTimeout(()=>{I.has(e)&&e.dispatchEvent(new c("toggle",{cancelable:!1,oldState:t,newState:o}))},0))}var F=globalThis.ShadowRoot||function(){},z=globalThis.HTMLDialogElement||function(){},M=new WeakMap,u=new WeakMap,g=new WeakMap;function L(e){return g.get(e)||"hidden"}var b=new WeakMap;function O(e){let t=e.popoverTargetElement;if(!t)return;let o=L(t);e.popoverTargetAction==="show"&&o==="showing"||e.popoverTargetAction==="hide"&&o==="hidden"||(o==="showing"?h(t,!0,!0):d(t,!1)&&(b.set(t,e),S(t)))}function d(e,t){return!(e.popover!=="auto"&&e.popover!=="manual"||!e.isConnected||t&&L(e)!=="showing"||!t&&L(e)!=="hidden"||e instanceof z&&e.hasAttribute("open")||document.fullscreenElement===e)}function R(e){return e?Array.from(u.get(e.ownerDocument)||[]).indexOf(e)+1:0}function V(e){let t=W(e),o=U(e);return R(t)>R(o)?t:o}function y(e){let t=u.get(e);for(let o of t||[])if(!o.isConnected)t.delete(o);else return o;return null}function v(e){return typeof e.getRootNode=="function"?e.getRootNode():e.parentNode?v(e.parentNode):e}function W(e){for(;e;){if(e instanceof HTMLElement&&e.popover==="auto"&&g.get(e)==="showing")return e;if(e=e.parentElement||v(e),e instanceof F&&(e=e.host),e instanceof Document)return}}function U(e){for(;e;){let t=e.popoverTargetElement;if(t)return t;if(e=e.parentElement||v(e),e instanceof F&&(e=e.host),e instanceof Document)return}}function G(e){let t=new Map,o=0,r=e.ownerDocument;for(let p of u.get(r)||[])t.set(p,o),o+=1;t.set(e,o),o+=1;let i=null;function l(p){let w=W(p);if(w===null)return null;let n=t.get(w);(i===null||t.get(i)<n)&&(i=w)}return l(e?.parentElement),i}function Q(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 _(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 r=e.ownerDocument.createTreeWalker(t,NodeFilter.SHOW_ELEMENT),i=r.currentNode;for(;i;){if(Q(i))return i;i=r.nextNode()}}function $(e){_(e)?.focus()}var H=new WeakMap;function S(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(T(l,!1,!0),i!==e.getAttribute("popover")||!d(e,!1))return}y(t)||(o=!0),H.delete(e);let r=t.activeElement;e.classList.add(":popover-open"),g.set(e,"showing"),M.has(t)||M.set(t,new Set),M.get(t).add(e),$(e),e.popover==="auto"&&(u.has(t)||u.set(t,new Set),u.get(t).add(e),B(b.get(e),!0)),o&&r&&e.popover==="auto"&&H.set(e,r),P(e,"closed","open")}function h(e,t=!1,o=!1){if(!d(e,!0))return;let r=e.ownerDocument;if(e.popover==="auto"&&(T(e,t,o),!d(e,!0))||(B(b.get(e),!1),b.delete(e),o&&(e.dispatchEvent(new c("beforetoggle",{oldState:"open",newState:"closed"})),!d(e,!0))))return;M.get(r)?.delete(e),u.get(r)?.delete(e),e.classList.remove(":popover-open"),g.set(e,"hidden"),o&&P(e,"open","closed");let i=H.get(e);i&&(H.delete(e),t&&i.focus())}function N(e,t=!1,o=!1){let r=y(e);for(;r;)h(r,t,o),r=y(e)}function T(e,t,o){let r=e.ownerDocument||e;if(e instanceof Document)return N(r,t,o);let i=null,l=!1;for(let p of u.get(r)||[])if(p===e)l=!0;else if(l){i=p;break}if(!l)return N(r,t,o);for(;i&&L(i)==="showing"&&u.get(r)?.size;)h(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(!y(o))return;let i=V(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&&T(i||o,!1,!0)}}var k=new WeakMap;function B(e,t=!1){if(!e)return;k.has(e)||k.set(e,e.getAttribute("aria-expanded"));let o=e.popoverTargetElement;if(o&&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 J=/(^|[^\\]):popover-open\b/g,q=` | ||
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||"")}},I=new WeakMap;function P(e,t,o){I.set(e,setTimeout(()=>{I.has(e)&&e.dispatchEvent(new c("toggle",{cancelable:!1,oldState:t,newState:o}))},0))}var F=globalThis.ShadowRoot||function(){},z=globalThis.HTMLDialogElement||function(){},M=new WeakMap,p=new WeakMap,g=new WeakMap;function L(e){return g.get(e)||"hidden"}var b=new WeakMap;function O(e){let t=e.popoverTargetElement;if(!(t instanceof HTMLElement))return;let o=L(t);e.popoverTargetAction==="show"&&o==="showing"||e.popoverTargetAction==="hide"&&o==="hidden"||(o==="showing"?h(t,!0,!0):d(t,!1)&&(b.set(t,e),S(t)))}function d(e,t){return!(e.popover!=="auto"&&e.popover!=="manual"||!e.isConnected||t&&L(e)!=="showing"||!t&&L(e)!=="hidden"||e instanceof z&&e.hasAttribute("open")||document.fullscreenElement===e)}function R(e){return e?Array.from(p.get(e.ownerDocument)||[]).indexOf(e)+1:0}function V(e){let t=W(e),o=U(e);return R(t)>R(o)?t:o}function y(e){let t=p.get(e);for(let o of t||[])if(!o.isConnected)t.delete(o);else return o;return null}function v(e){return typeof e.getRootNode=="function"?e.getRootNode():e.parentNode?v(e.parentNode):e}function W(e){for(;e;){if(e instanceof HTMLElement&&e.popover==="auto"&&g.get(e)==="showing")return e;if(e=e.parentElement||v(e),e instanceof F&&(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||v(e),e instanceof F&&(e=e.host),e instanceof Document)return}}function G(e){let t=new Map,o=0,r=e.ownerDocument;for(let u of p.get(r)||[])t.set(u,o),o+=1;t.set(e,o),o+=1;let i=null;function l(u){let w=W(u);if(w===null)return null;let n=t.get(w);(i===null||t.get(i)<n)&&(i=w)}return l(e?.parentElement),i}function Q(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 _(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 r=e.ownerDocument.createTreeWalker(t,NodeFilter.SHOW_ELEMENT),i=r.currentNode;for(;i;){if(Q(i))return i;i=r.nextNode()}}function $(e){_(e)?.focus()}var H=new WeakMap;function S(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(T(l,!1,!0),i!==e.getAttribute("popover")||!d(e,!1))return}y(t)||(o=!0),H.delete(e);let r=t.activeElement;e.classList.add(":popover-open"),g.set(e,"showing"),M.has(t)||M.set(t,new Set),M.get(t).add(e),$(e),e.popover==="auto"&&(p.has(t)||p.set(t,new Set),p.get(t).add(e),B(b.get(e),!0)),o&&r&&e.popover==="auto"&&H.set(e,r),P(e,"closed","open")}function h(e,t=!1,o=!1){if(!d(e,!0))return;let r=e.ownerDocument;if(e.popover==="auto"&&(T(e,t,o),!d(e,!0))||(B(b.get(e),!1),b.delete(e),o&&(e.dispatchEvent(new c("beforetoggle",{oldState:"open",newState:"closed"})),!d(e,!0))))return;M.get(r)?.delete(e),p.get(r)?.delete(e),e.classList.remove(":popover-open"),g.set(e,"hidden"),o&&P(e,"open","closed");let i=H.get(e);i&&(H.delete(e),t&&i.focus())}function N(e,t=!1,o=!1){let r=y(e);for(;r;)h(r,t,o),r=y(e)}function T(e,t,o){let r=e.ownerDocument||e;if(e instanceof Document)return N(r,t,o);let i=null,l=!1;for(let u of p.get(r)||[])if(u===e)l=!0;else if(l){i=u;break}if(!l)return N(r,t,o);for(;i&&L(i)==="showing"&&p.get(r)?.size;)h(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(!y(o))return;let i=V(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&&T(i||o,!1,!0)}}var k=new WeakMap;function B(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 J=/(^|[^\\]):popover-open\b/g,q=` | ||
[popover] { | ||
@@ -57,3 +57,3 @@ position: fixed; | ||
} | ||
`,m=null;function x(e){if(m===null)try{m=new CSSStyleSheet,m.replaceSync(q)}catch{m=!1}if(m===!1){let t=document.createElement("style");t.textContent=q,e instanceof Document?e.head.append(t):e.append(t)}else e.adoptedStyleSheets=[...e.adoptedStyleSheets,m]}function K(){window.ToggleEvent=window.ToggleEvent||c;function e(n){return n?.includes(":popover-open")&&(n=n.replace(J,"$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(){S(this)}},hidePopover:{enumerable:!0,configurable:!0,value(){h(this,!0,!0)}},togglePopover:{enumerable:!0,configurable:!0,value(n){g.get(this)==="showing"&&n===void 0||n===!1?h(this,!0,!0):(n===void 0||n===!0)&&S(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 x(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&&x(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 a=v(this),E=this.getAttribute("popovertarget");return(a instanceof Document||a instanceof C)&&E&&a.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=>{if(!n.isTrusted)return;let s=n.composedPath()[0];if(!(s instanceof Element)||s?.shadowRoot)return;let a=v(s);if(!(a instanceof C||a instanceof Document))return;let E=s.closest("[popovertargetaction],[popovertarget]");if(E){O(E);return}},p=n=>{let s=n.key,a=n.target;a&&(s==="Escape"||s==="Esc")&&T(a.ownerDocument,!0,!0)};(n=>{n.addEventListener("click",l),n.addEventListener("keydown",p),n.addEventListener("pointerdown",D),n.addEventListener("pointerup",D)})(document),x(document)}j()||K(); | ||
`,m=null;function x(e){if(m===null)try{m=new CSSStyleSheet,m.replaceSync(q)}catch{m=!1}if(m===!1){let t=document.createElement("style");t.textContent=q,e instanceof Document?e.head.append(t):e.append(t)}else e.adoptedStyleSheets=[...e.adoptedStyleSheets,m]}function K(){window.ToggleEvent=window.ToggleEvent||c;function e(n){return n?.includes(":popover-open")&&(n=n.replace(J,"$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(){S(this)}},hidePopover:{enumerable:!0,configurable:!0,value(){h(this,!0,!0)}},togglePopover:{enumerable:!0,configurable:!0,value(n){g.get(this)==="showing"&&n===void 0||n===!1?h(this,!0,!0):(n===void 0||n===!0)&&S(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 x(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&&x(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 a=v(this),E=this.getAttribute("popovertarget");return(a instanceof Document||a instanceof C)&&E&&a.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=>{if(!n.isTrusted)return;let s=n.composedPath()[0];if(!(s instanceof Element)||s?.shadowRoot)return;let a=v(s);if(!(a instanceof C||a instanceof Document))return;let E=s.closest("[popovertargetaction],[popovertarget]");if(E){O(E);return}},u=n=>{let s=n.key,a=n.target;a&&(s==="Escape"||s==="Esc")&&T(a.ownerDocument,!0,!0)};(n=>{n.addEventListener("click",l),n.addEventListener("keydown",u),n.addEventListener("pointerdown",D),n.addEventListener("pointerup",D)})(document),x(document)}j()||K(); | ||
//# sourceMappingURL=popover.min.js.map |
{ | ||
"name": "@oddbird/popover-polyfill", | ||
"version": "0.3.1", | ||
"version": "0.3.2", | ||
"description": "Popover Attribute Polyfill", | ||
@@ -88,6 +88,6 @@ "license": "BSD-3-Clause", | ||
"@types/node": "*", | ||
"@typescript-eslint/eslint-plugin": "^6.9.0", | ||
"@typescript-eslint/parser": "^6.9.0", | ||
"@typescript-eslint/eslint-plugin": "^6.10.0", | ||
"@typescript-eslint/parser": "^6.10.0", | ||
"esbuild": "^0.19.5", | ||
"eslint": "^8.52.0", | ||
"eslint": "^8.53.0", | ||
"eslint-config-prettier": "^9.0.0", | ||
@@ -98,7 +98,7 @@ "eslint-import-resolver-typescript": "^3.6.1", | ||
"husky": "^8.0.3", | ||
"lint-staged": "^15.0.2", | ||
"lint-staged": "^15.1.0", | ||
"npm-run-all": "^4.1.5", | ||
"prettier": "^3.0.3", | ||
"prettier": "^3.1.0", | ||
"ts-node": "^10.9.1", | ||
"typescript": "5.1.6" | ||
"typescript": "^5.2.2" | ||
}, | ||
@@ -105,0 +105,0 @@ "lint-staged": { |
interface PopoverToggleTargetElementInvoker { | ||
popoverTargetElement: HTMLElement | null; | ||
popoverTargetAction: 'toggle' | 'show' | 'hide'; | ||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLButtonElement/popoverTargetAction) */ | ||
popoverTargetAction: string; | ||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLButtonElement/popoverTargetElement) */ | ||
popoverTargetElement: Element | null; | ||
} | ||
declare global { | ||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/ToggleEvent) */ | ||
interface ToggleEvent extends Event { | ||
oldState: string; | ||
newState: string; | ||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/ToggleEvent/newState) */ | ||
readonly newState: string; | ||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/ToggleEvent/oldState) */ | ||
readonly oldState: string; | ||
} | ||
interface HTMLElement { | ||
popover: 'auto' | 'manual' | null; | ||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLElement/popover) */ | ||
popover: string | null; | ||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLElement/hidePopover) */ | ||
hidePopover(): void; | ||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLElement/showPopover) */ | ||
showPopover(): void; | ||
hidePopover(): void; | ||
togglePopover(): void; | ||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLElement/togglePopover) */ | ||
togglePopover(force?: boolean): void; | ||
} | ||
/* eslint-disable @typescript-eslint/no-empty-interface */ | ||
@@ -21,2 +32,3 @@ interface HTMLButtonElement extends PopoverToggleTargetElementInvoker {} | ||
/* eslint-enable @typescript-eslint/no-empty-interface */ | ||
interface Window { | ||
@@ -23,0 +35,0 @@ ToggleEvent: ToggleEvent; |
import { apply, isSupported } from './popover.js'; | ||
interface PopoverToggleTargetElementInvoker { | ||
popoverTargetElement: HTMLElement | null; | ||
popoverTargetAction: 'toggle' | 'show' | 'hide'; | ||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLButtonElement/popoverTargetAction) */ | ||
popoverTargetAction: string; | ||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLButtonElement/popoverTargetElement) */ | ||
popoverTargetElement: Element | null; | ||
} | ||
declare global { | ||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/ToggleEvent) */ | ||
interface ToggleEvent extends Event { | ||
oldState: string; | ||
newState: string; | ||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/ToggleEvent/newState) */ | ||
readonly newState: string; | ||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/ToggleEvent/oldState) */ | ||
readonly oldState: string; | ||
} | ||
interface HTMLElement { | ||
popover: 'auto' | 'manual' | null; | ||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLElement/popover) */ | ||
popover: string | null; | ||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLElement/hidePopover) */ | ||
hidePopover(): void; | ||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLElement/showPopover) */ | ||
showPopover(): void; | ||
hidePopover(): void; | ||
togglePopover(): void; | ||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLElement/togglePopover) */ | ||
togglePopover(force?: boolean): void; | ||
} | ||
/* eslint-disable @typescript-eslint/no-empty-interface */ | ||
@@ -23,2 +34,3 @@ interface HTMLButtonElement extends PopoverToggleTargetElementInvoker {} | ||
/* eslint-enable @typescript-eslint/no-empty-interface */ | ||
interface Window { | ||
@@ -25,0 +37,0 @@ ToggleEvent: ToggleEvent; |
@@ -26,3 +26,3 @@ import { queuePopoverToggleEventTask, ToggleEvent } from './events.js'; | ||
const popover = element.popoverTargetElement; | ||
if (!popover) { | ||
if (!(popover instanceof HTMLElement)) { | ||
return; | ||
@@ -129,3 +129,3 @@ } | ||
const nodePopover = (node as HTMLButtonElement).popoverTargetElement; | ||
if (nodePopover) return nodePopover; | ||
if (nodePopover instanceof HTMLElement) return nodePopover; | ||
node = node.parentElement || getRootNode(node); | ||
@@ -415,3 +415,3 @@ if (node instanceof ShadowRoot) node = node.host; | ||
const popover = el.popoverTargetElement; | ||
if (popover && popover.popover === 'auto') { | ||
if (popover instanceof HTMLElement && popover.popover === 'auto') { | ||
el.setAttribute('aria-expanded', String(force)); | ||
@@ -418,0 +418,0 @@ } else { |
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
252259
2360