!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).littlefoot={})}(this,(function(t){"use strict";var e=function(){return e=Object.assign||function(t){for(var e,n=1,r=arguments.length;n=r||o>=i?["below",o-n-15]:["above",i-n-15]}(e,t),u=o[0],c=o[1];if(i!==u){r(t,"is-"+i),n(t,"is-"+u);var a=100*m(e)+"%",s="above"===u?"100%":"0";t.style.transformOrigin=a+" "+s}return[u,c]}var h="is-active",g="is-changing",y="is-scrollable",b=function(t){return document.body.contains(t)};function w(t){var e=t.id,o=t.button,u=t.content,c=t.host,a=t.popover,s=t.wrapper,f=0,w="above";return{id:e,activate:function(t){var e;o.setAttribute("aria-expanded","true"),n(o,g),n(o,h),o.insertAdjacentElement("afterend",a),a.style.maxWidth=document.body.clientWidth+"px",e=u,f=Math.round(d.pixels(l.getStyle(e,"maxHeight"),e)),null==t||t(a,o)},dismiss:function(t){o.setAttribute("aria-expanded","false"),n(o,g),r(o,h),r(a,h),null==t||t(a,o)},isActive:function(){return i(o,h)},isReady:function(){return!i(o,g)},ready:function(){n(a,h),r(o,g)},remove:function(){a.remove(),r(o,g)},reposition:function(){if(b(a)){var t=p(a,o,w),e=t[0],i=t[1];w=e,u.style.maxHeight=Math.min(f,i)+"px",a.offsetHeight0&&r(t,H),i&&o<=0&&o :not(."+M+")"),r=n.filter((function(t){return"HR"===t.tagName}));n.length===r.length&&(O.apply(void 0,r.concat(e)),j(e))}function R(t,e){var n=t.parentElement;t.remove(),n&&n!==e&&!n.innerHTML.replace(/(\[\]| |\s)/g,"")&&R(n,e)}function z(t,e){var n=t[0],r=t[1],i=t[2],o=C(i.outerHTML);W(o,'[href$="#'+n+'"]').forEach((function(t){return R(t,o)}));var u=o.innerHTML.trim();return[r,i,{id:String(e+1),number:e+1,reference:"lf-"+n,content:u.startsWith("<")?u:"

"+u+"

"}]}function k(t){return function(e){return t.replace(/<%=?\s*(\w+?)\s*%>/g,(function(t,n){var r;return String(null!==(r=e[n])&&void 0!==r?r:"")}))}}function I(t,e){var n=k(t),r=k(e);return function(t){var e=t[0],i=t[1],o=i.id,u=C(''+n(i)+""),c=u.firstElementChild;c.setAttribute("aria-expanded","false"),c.dataset.footnoteButton="",c.dataset.footnoteId=o;var a=C(r(i));a.dataset.footnotePopover="",a.dataset.footnoteId=o;var l=L(a,_),s=L(a,T);return function(t,e){t.addEventListener("wheel",D.throttle(A(e),16))}(s,a),e.insertAdjacentElement("beforebegin",u),{id:o,button:c,host:u,popover:a,content:s,wrapper:l}}}function q(t){var n,i,o,u=t.allowDuplicates,c=t.anchorParentSelector,a=t.anchorPattern,l=t.buttonTemplate,s=t.contentTemplate,f=t.footnoteSelector,d=t.numberResetSelector,v=t.scope,m=function(t,e,n){return W(t,n+' a[href*="#"]').filter((function(t){return(t.href+t.rel).match(e)}))}(document,a,v).map(function(t,e,n,r){var i=[];return function(o){var u=o.href.split("#")[1],c=u?W(t,"#"+window.CSS.escape(u)).find((function(t){return e||!i.includes(t)})):void 0,a=null==c?void 0:c.closest(r);if(a){i.push(a);var l=o.closest(n)||o;return[l.id||o.id,l,a]}}}(document,u,c,f)).filter(P).map(z).map(d?(n=d,i=0,o=null,function(t){var r=t[0],u=t[1],c=t[2],a=r.closest(n);return i=o===a?i+1:1,o=a,[r,u,e(e({},c),{number:i})]}):function(t){return t}).map((function(t){var e=t[0],n=t[1],r=t[2];return O(e,n),j(n),[e,r]})).map(I(l,s)).map(w);return{footnotes:m,unmount:function(){m.forEach((function(t){return t.destroy()})),W(document,"."+M).forEach((function(t){return r(t,M)}))}}}var F="[data-footnote-id]",N=function(t,e){return t.target.closest(e)},B=function(t){return null==t?void 0:t.dataset.footnoteId},V=function(t){return function(e){e.preventDefault();var n=N(e,F),r=B(n);r&&t(r)}},U=document.addEventListener,Y=window.addEventListener,$=function(t,e,n,r){return U(t,(function(t){var r=t.target;(null==r?void 0:r.closest(e))&&n.call(r,t)}),r)};var G={activateDelay:100,activateOnHover:!1,allowDuplicates:!0,allowMultiple:!1,anchorParentSelector:"sup",anchorPattern:/(fn|footnote|note)[:\-_\d]/gi,dismissDelay:100,dismissOnUnhover:!1,dismissOnDocumentTouch:!0,footnoteSelector:"li",hoverDelay:250,numberResetSelector:"",scope:"",contentTemplate:''),buttonTemplate:''};function J(t){void 0===t&&(t={});var n=e(e({},G),t),r=function(t,e){var n,r=t.footnotes,i=t.unmount,o=function(t){return function(n){n.isReady()&&(n.dismiss(e.dismissCallback),setTimeout(n.remove,t))}},u=function(t){return function(n){e.allowMultiple||r.filter((function(t){return t.id!==n.id})).forEach(o(e.dismissDelay)),n.isReady()&&(n.activate(e.activateCallback),n.reposition(),n.resize(),setTimeout(n.ready,t))}},c=function(t){return function(e){var n=r.find((function(t){return t.id===e}));n&&t(n)}},a=function(){return r.forEach(o(e.dismissDelay))};return{activate:function(t,e){return c(u(e))(t)},dismiss:function(t,e){return c(o(e))(t)},dismissAll:a,touchOutside:function(){e.dismissOnDocumentTouch&&a()},repositionAll:function(){return r.forEach((function(t){return t.reposition()}))},resizeAll:function(){return r.forEach((function(t){return t.resize()}))},toggle:c((function(t){return t.isActive()?o(e.dismissDelay)(t):u(e.activateDelay)(t)})),hover:c((function(t){n=t.id,e.activateOnHover&&!t.isActive()&&u(e.hoverDelay)(t)})),unhover:c((function(t){t.id===n&&(n=null),e.dismissOnUnhover&&setTimeout((function(){return r.filter((function(t){return t.id!==n})).forEach(o(e.dismissDelay))}),e.hoverDelay)})),unmount:i}}(q(n),n),i=function(t){var e=function(e){var n=N(e,"[data-footnote-button]"),r=B(n);r?(e.preventDefault(),t.toggle(r)):N(e,"[data-footnote-popover]")||t.touchOutside()},n=D.throttle(t.repositionAll,16),r=D.throttle(t.resizeAll,16),i=V(t.hover),o=V(t.unhover),u=new AbortController,c={signal:u.signal};return U("touchend",e,c),U("click",e,c),U("keyup",(function(e){27!==e.keyCode&&"Escape"!==e.key&&"Esc"!==e.key||t.dismissAll()}),c),U("gestureend",n,c),Y("scroll",n,c),Y("resize",r,c),$("mouseover",F,i,c),$("mouseout",F,o,c),function(){u.abort()}}(r);return{activate:function(t,e){void 0===e&&(e=n.activateDelay),r.activate(t,e)},dismiss:function(t,e){void 0===e&&(e=n.dismissDelay),void 0===t?r.dismissAll():r.dismiss(t,e)},unmount:function(){i(),r.unmount()},getSetting:function(t){return n[t]},updateSetting:function(t,e){n[t]=e}}}t.default=J,t.littlefoot=J,Object.defineProperty(t,"__esModule",{value:!0})}));