website-utilities 1.0.415 → 1.0.416

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +1 -1
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";if("undefined"!=typeof module&&null!==module&&"undefined"!==eval("typeof require")&&null!==eval("require")&&"main"in eval("require")&&"undefined"!==eval("typeof require.main")&&null!==eval("require.main")){var ORIGINAL_MAIN_MODULE=module;module!==eval("require.main")&&"paths"in module&&"paths"in eval("require.main")&&"undefined"!=typeof __dirname&&null!==__dirname&&(module.paths=eval("require.main.paths").concat(module.paths.filter((function(path){return eval("require.main.paths").includes(path)}))))}if(null==window)var window="undefined"==typeof global||null===global?{}:global;!function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e(require("@babel/runtime/helpers/applyDecoratedDescriptor"),require("@babel/runtime/helpers/initializerDefineProperty"),require("@babel/runtime/helpers/initializerWarningHelper"),require("clientnode"),require("clientnode/property-types"),require("web-component-wrapper/Web"),require("web-component-wrapper/decorator"));else if("function"==typeof define&&define.amd)define(["@babel/runtime/helpers/applyDecoratedDescriptor","@babel/runtime/helpers/initializerDefineProperty","@babel/runtime/helpers/initializerWarningHelper","clientnode","clientnode/property-types","web-component-wrapper/Web","web-component-wrapper/decorator"],e);else{var o="object"==typeof exports?e(require("@babel/runtime/helpers/applyDecoratedDescriptor"),require("@babel/runtime/helpers/initializerDefineProperty"),require("@babel/runtime/helpers/initializerWarningHelper"),require("clientnode"),require("clientnode/property-types"),require("web-component-wrapper/Web"),require("web-component-wrapper/decorator")):e(t["@babel/runtime/helpers/applyDecoratedDescriptor"],t["@babel/runtime/helpers/initializerDefineProperty"],t["@babel/runtime/helpers/initializerWarningHelper"],t.clientnode,t["clientnode/property-types"],t["web-component-wrapper/Web"],t["web-component-wrapper/decorator"]);for(var i in o)("object"==typeof exports?exports:t)[i]=o[i]}}(this,((t,e,o,i,n,r,s)=>(()=>{var a=[,,,t=>{t.exports=e},e=>{e.exports=t},t=>{t.exports=o},t=>{t.exports=i},t=>{t.exports=n},t=>{t.exports=s},t=>{t.exports=r}],l={};function c(t){var e=l[t];if(void 0!==e)return e.exports;var o=l[t]={exports:{}};return a[t](o,o.exports,c),o.exports}c.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return c.d(e,{a:e}),e},c.d=(t,e)=>{for(var o in e)c.o(e,o)&&!c.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:e[o]})},c.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),c.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var u={};return(()=>{c.r(u),c.d(u,{WebsiteUtilities:()=>M,api:()=>P,default:()=>z,log:()=>E});var t,e,o,i,n,r,s,a,l,p,d,h,m,w,f,v,g,b,y,N,S,T,_,L,D=c(3),C=c.n(D),k=c(4),A=c.n(k),x=(c(5),c(6)),O=c(7),q=c(8),I=c(9);const E=new x.Logger({name:"website-utilities"});let M=(t=(0,q.property)({type:O.object}),e=(0,q.property)({type:O.func}),o=(0,q.property)({type:O.func}),i=(0,q.property)({type:O.func}),n=(0,q.property)({type:O.func}),r=(0,q.property)({type:O.func}),s=(0,q.property)({type:O.func}),a=(0,q.property)({type:O.func}),l=(0,q.property)({type:O.func}),p=(0,q.property)({type:O.func}),d=(0,q.property)({type:O.func}),L=class t extends I.Web{constructor(){super(),this.self=t,C()(this,"options",m,this),C()(this,"onStartUpAnimationComplete",w,this),C()(this,"onSwitchSection",f,this),C()(this,"onViewportMovesAwayFromTop",v,this),C()(this,"onViewportMovesToTop",g,this),C()(this,"onSwitchToManualScrollingIndicator",b,this),C()(this,"onLoaded",y,this),C()(this,"onButtonClick",N,this),C()(this,"onSectionSwitch",S,this),C()(this,"onLinkClick",T,this),C()(this,"onTrack",_,this),this.currentSectionName="",this.startUpAnimationIsComplete=!1,this.continueAutoScrolling=!1,this.viewportIsOnTop=void 0,this.observerDeregisters=[],this.windowLoadingCoverDomNode=null,this.topDomNode=null,this.priorityNavigationDomNodes=null,this.routerOutletDomNode=null,this.sectionDomNodes={},this.scrollToTopButtonDomNodes=null,this.defineGetterAndSetterInterface()}async onUpdateAttribute(t,e){await super.onUpdateAttribute(t,e),"options"===t&&this._extendOptions()}async render(t="unknown",e=!0){if(await super.render(t,!1),0===Object.keys(this.options).length&&this._extendOptions(),this.disableScrolling(),!this.self.windowLoaded){const t=()=>{this.self.windowLoaded||(this.self.windowLoaded=!0,this._removeLoadingCover().then((()=>{this.enableScrolling(),this._performStartUpEffects().then((()=>{this.addMenuHighlighterViewTransition()})),this.onLoaded()})))};(0,x.onDocumentReady)((()=>{(0,x.timeout)(t,this.options.windowLoadedTimeoutAfterDocLoadedInMSec)})),x.globalContext.window&&this.addSecureEventListener(x.globalContext.window,"load",t)}await this.waitForNestedComponentRendering(),this.grabDomNodes(),this._bindScrollEvents(),this._bindClickTracking(),await this._initializeRouting(),this.initializePriorityNavigation(),await this.resolveRenderingPromiseIfSet(t,e)}disconnectedCallback(){super.disconnectedCallback();for(const t of this.observerDeregisters)t()}grabDomNodes(){var t,e,o;this.topDomNode=this.hostDomNode.querySelector(this.options.selectors.top),this.scrollToTopButtonDomNodes=this.hostDomNode.querySelectorAll(this.options.selectors.scrollToTopButtons),this.priorityNavigationDomNodes=this.hostDomNode.querySelectorAll(this.options.selectors.priorityNavigation),this.routerOutletDomNode=this.hostDomNode.querySelector(this.options.selectors.routerOutlet);for(const t of null!==(i=this.routerOutletDomNode?.children)&&void 0!==i?i:[]){var i;const e=t.getAttribute("data-website-utilities-section");""===e?this.sectionDomNodes.default=t:e&&this.options.sectionNames.managed.includes(e)&&(this.sectionDomNodes[e]=t)}this.windowLoadingCoverDomNode=null!==(t=null!==(e=null!==(o=this.hostDomNode.querySelector(this.options.selectors.windowLoadingCover))&&void 0!==o?o:this.hostDomNode.parentElement?.querySelector(this.options.selectors.windowLoadingCover))&&void 0!==e?e:x.globalContext.document?.body.querySelector(this.options.selectors.windowLoadingCover))&&void 0!==t?t:null}interruptableScrollToTop(){const t=window.pageYOffset,e=performance.now();this.continueAutoScrolling=!0;const o=i=>{if(!this.continueAutoScrolling)return;const n=i-e,r=Math.min(n/500,1),s=r*(2-r);window.scrollTo(0,t*(1-s)),r<1?requestAnimationFrame(o):this.continueAutoScrolling=!1};requestAnimationFrame(o)}scrollToTop(){x.globalContext.document&&window.scrollTo({top:0,behavior:"smooth"})}disableScrolling(){this.hostDomNode.parentElement&&(this.hostDomNode.parentElement.classList.add("wu-disable-scrolling"),this.addSecureEventListener(this.hostDomNode.parentElement,"touchmove",x.preventDefault))}enableScrolling(){this.hostDomNode.parentElement&&(this.hostDomNode.parentElement.classList.remove("wu-disable-scrolling"),this.hostDomNode.parentElement.classList.remove("touchmove"),this.hostDomNode.parentElement.removeEventListener("touchmove",x.preventDefault))}async track(t){if(x.globalContext.window?.location&&this.options.tracking){const e={context:`${x.globalContext.window.location.pathname}#`+this.currentSectionName,...t};("number"!=typeof e.value||isNaN(e.value))&&(e.value=1),E.debug('Run tracking code: "event" with arguments:'),E.debug(e);try{await this._onTrack(e)}catch(t){E.warn(`Problem in tracking "${(0,x.represent)(e)}":`,(0,x.represent)(t))}}}initializePriorityNavigation(){if(0===this.priorityNavigationDomNodes?.length)return;for(const t of this.priorityNavigationDomNodes||[])for(const e of t.querySelectorAll(`[href="#${this.currentSectionName}"]`))e.classList.add(this.options.selectors.activeNavigationItemClassName);const t=()=>{for(const t of this.priorityNavigationDomNodes||[]){const e=t.querySelectorAll("ul > li"),o=Array.from(e).filter((t=>!t.classList.contains(this.options.selectors.priorityNavigationOverflow.substring(1)))),i=t.querySelector("ul > li").offsetTop,n=[];let r=!0,s=0;for(const t of o){t.offsetTop!==i&&(n.push(t),r&&(n.push(o[s-1]),r=!1)),s+=1}if(n.length){const e=n.map((t=>t.cloneNode(!0)));for(const t of n)t.classList.add("wu-priority-navigation__list__item--hide");const o=t.querySelector(this.options.selectors.priorityNavigationOverflowList);if(o)for(const t of e)o.append(t);const i=t.querySelector(this.options.selectors.priorityNavigationOverflow);i&&i.classList.add("wu-priority-navigation__overflow--inline-block"),t.style.overflow="visible"}}};for(const t of this.hostDomNode.querySelectorAll(this.options.selectors.priorityNavigationOverflowTitle))this.addSecureEventListener(t,"click",(()=>{for(const t of this.hostDomNode.querySelectorAll(this.options.selectors.priorityNavigationOverflowList))t.classList.toggle("wu-priority-navigation__overflow__list--show")}));for(const e of this.priorityNavigationDomNodes||[]){const o=(0,x.trailingThrottle)((()=>{for(const t of e.querySelectorAll(this.options.selectors.priorityNavigationOverflowList))for(;t.firstChild;)t.removeChild(t.firstChild);for(const t of e.querySelectorAll(this.options.selectors.priorityNavigationOverflow))t.classList.remove("wu-priority-navigation__overflow--show-inline-block");for(const t of e.querySelectorAll("ul > li"))t.classList.contains(this.options.selectors.priorityNavigationOverflow.substring(1))||t.classList.remove("wu-priority-navigation__list__item--hide");t(),e.classList.remove("wu-priority-navigation--resizing")}),20),i=new ResizeObserver((()=>{e.classList.add("wu-priority-navigation--resizing"),o()}));this.observerDeregisters.push((()=>{i.unobserve(e)})),i.observe(e)}t()}addMenuHighlighterViewTransition(){if(!x.globalContext.document)return;const t=document.createElement("style");t.type="text/css";t.appendChild(x.globalContext.document.createTextNode("\n a.wu-priority-navigation__link--active::after {\n view-transition-name: wu-menu-highlight;\n }\n ")),x.globalContext.document.getElementsByTagName("head")[0].appendChild(t)}activateNavigationItemHighlighters(t){const e=this.options.selectors.activeNavigationItemClassName;for(const o of this.priorityNavigationDomNodes||[]){for(const t of o.querySelectorAll(`.${e}`))t.classList.remove(e);for(const i of o.querySelectorAll(`[href="#${t}"]`))i.classList.add(e)}}triggerNavigationItemHighlighterSwitching(t){x.globalContext.document?.startViewTransition?x.globalContext.document.startViewTransition((()=>{this.activateNavigationItemHighlighters(t)})):this.activateNavigationItemHighlighters(t)}async _onButtonClick(t){if(!1===await this.onButtonClick(t))return;const e=t.target,o=(0,x.getText)(e).join(" ");this._onTrack({event:"buttonClick",eventType:"click",label:o,reference:e.getAttribute("action")||e.getAttribute("target")||e.getAttribute("type")||o,subject:"button",value:parseInt(e.getAttribute("website-analytics-value")||"1"),userInteraction:!0})}async _onSectionSwitch(t,e,o){!1!==await this.onSectionSwitch(t,e,o)&&x.globalContext.window?.location&&await this._onTrack({event:"sectionSwitch",eventType:"sectionSwitch",label:t,reference:`${x.globalContext.window.location.pathname}#${t}`,subject:"url",userInteraction:!1})}async _onLinkClick(t){if(!1===await this.onLinkClick(t))return;const e=t.target,o=(0,x.getText)(e).join(" ");this._onTrack({event:"linkClick",eventType:"click",label:o,reference:e.getAttribute("href")||e.getAttribute("action")||e.getAttribute("target")||e.getAttribute("type")||o,subject:"link",value:parseInt(e.getAttribute("website-analytics-value")||"1"),userInteraction:!0})}async _onTrack(t){!1!==await this.onTrack(t)&&this.options.tracking&&x.globalContext.dataLayer?.push(t)}_onViewportMovesToTop(){this._finishScrollToTopButtonTransition();for(const e of null!==(t=this.scrollToTopButtonDomNodes)&&void 0!==t?t:[]){var t;const o=()=>{e.removeEventListener("transitionend",i),e.removeEventListener("transitioncancel",o)},i=()=>{this.viewportIsOnTop&&e.classList.add("wu-top-settled"),o()};e.addEventListener("transitionend",i,{once:!0}),e.addEventListener("transitioncancel",o,{once:!0}),e.classList.add("wu-scroll-up")}}async _onViewportMovesAwayFromTop(){this._finishScrollToTopButtonTransition("wu-top-settled"),await(0,x.timeout)(),this._finishScrollToTopButtonTransition();for(const e of null!==(t=this.scrollToTopButtonDomNodes)&&void 0!==t?t:[]){var t;e.classList.add("wu-scroll-down")}}async switchSection(t,e){if(x.globalContext.window&&"location"in x.globalContext.window&&(""===t||this.options.sectionNames.managed.includes(t)||this.options.sectionNames.unmanaged.includes(t))){var o,i;const n=Object.prototype.hasOwnProperty.call(this.sectionDomNodes,this.currentSectionName)?this.sectionDomNodes[this.currentSectionName]:null!==(o=this.sectionDomNodes.default)&&void 0!==o?o:null,r=Object.prototype.hasOwnProperty.call(this.sectionDomNodes,t)?this.sectionDomNodes[t]:null!==(i=this.sectionDomNodes.default)&&void 0!==i?i:null;await this.self.switchSectionLock.acquire(),this.triggerNavigationItemHighlighterSwitching(t),E.debug(`Run section switch from "${this.currentSectionName}" to`,`"${t}".`),this.currentSectionName===t?(n&&(n.classList.remove("wu-section-active"),n.classList.add("wu-section-inactive")),r&&(r.classList.remove("wu-section-inactive"),r.classList.add("wu-section-active"))):this.options.sectionNames.unmanaged.includes(t)&&this.options.sectionNames.unmanaged.includes(this.currentSectionName)||(this.interruptableScrollToTop(),n&&(await(0,x.fadeOut)(n),n.classList.remove("wu-section-active"),n.classList.add("wu-section-inactive")),r&&(r.classList.remove("wu-section-inactive"),r.classList.add("wu-section-active"),await(0,x.fadeIn)(r)));const s=this.currentSectionName;this.currentSectionName=t;try{await this._onSectionSwitch(this.currentSectionName,s,e)}catch(t){E.warn("Problem due to call section switch callback on section",`"${this.currentSectionName}": ${(0,x.represent)(t)}`)}await this.self.switchSectionLock.release()}}_extendOptions(){this.setPropertyValue("options",(0,x.extend)(!0,{},this.self._defaultOptions,this.options))}_initializeRouting(){""===this.currentSectionName&&(this.currentSectionName=this.options.sectionNames.default),this._bindNavigationEvents();const t=x.globalContext.location?.hash&&x.globalContext.location.hash.substring(1);t&&(this.options.sectionNames.managed.includes(t)||this.options.sectionNames.unmanaged.includes(t))&&(this.currentSectionName=t);for(const t of Object.values(this.sectionDomNodes))t.classList.add("wu-section-inactive");return this.switchSection(null!=t?t:this.currentSectionName)}_finishScrollToTopButtonTransition(t=["wu-scroll-down","wu-scroll-up"]){for(const o of null!==(e=this.scrollToTopButtonDomNodes)&&void 0!==e?e:[]){var e;o.classList.remove(...[].concat(t))}}_bindScrollEvents(){if(x.globalContext.document){for(const t of[x.globalContext.document.body,x.globalContext.document.querySelector("html"),x.globalContext.window])for(const e of this.options.knownScrollEventNames)t&&this.addSecureEventListener(t,e,(t=>{this.onSwitchToManualScrollingIndicator(t)&&(this.continueAutoScrolling=!1)}));if(x.globalContext.window&&this.addSecureEventListener(x.globalContext.window,"scroll",(t=>{x.globalContext.window?.scrollY?this.viewportIsOnTop&&(this.viewportIsOnTop=!1,this._onViewportMovesAwayFromTop().then(this.onViewportMovesAwayFromTop.bind(this,t))):this.viewportIsOnTop||(this.viewportIsOnTop=!0,this._onViewportMovesToTop(),this.onViewportMovesToTop(t))})),x.globalContext.window?.scrollY)this.viewportIsOnTop=!1,this._onViewportMovesAwayFromTop().then((()=>{this.onViewportMovesAwayFromTop()}));else{this.viewportIsOnTop=!0;for(const e of null!==(t=this.scrollToTopButtonDomNodes)&&void 0!==t?t:[]){var t;e.classList.add("wu-top-settled")}this._onViewportMovesToTop(),this.onViewportMovesToTop()}}}async _removeLoadingCover(){await(0,x.timeout)(this.options.additionalPageLoadingTimeInMilliseconds);for(const t of this.hostDomNode.querySelectorAll(`[class^="${this.options.selectors.startUpAnimationClassPrefix}"], [class*=" ${this.options.selectors.startUpAnimationClassPrefix}"]`))t.style.opacity="0";this.windowLoadingCoverDomNode&&await(0,x.fadeOut)(this.windowLoadingCoverDomNode)}async _performStartUpEffects(){const t=[];let e=1;for(;;){const o=this.hostDomNode.querySelectorAll("."+this.options.selectors.startUpAnimationClassPrefix+String(e));if(0===o.length){await Promise.all(t),this.startUpAnimationIsComplete=!0,this.onStartUpAnimationComplete();break}await(0,x.timeout)(this.options.startUpAnimationElementDelayInMilliseconds);for(const e of o)t.push((0,x.fadeIn)(e));e+=1}}_bindNavigationEvents(){x.globalContext.window&&this.addSecureEventListener(x.globalContext.window,"hashchange",(t=>{if(this.startUpAnimationIsComplete){const e=location.hash.substring(1);this.switchSection(e,t)}})),this._bindScrollToTopButton()}_bindScrollToTopButton(){for(const t of this.scrollToTopButtonDomNodes||[])this.addSecureEventListener(t,"click",(t=>{t.preventDefault(),this.interruptableScrollToTop()}))}_bindClickTracking(){if(this.options.tracking){for(const t of this.hostDomNode.querySelectorAll("a"))this.addSecureEventListener(t,"click",(t=>{this._onLinkClick(t)}));for(const t of this.hostDomNode.querySelectorAll("button"))this.addSecureEventListener(t,"click",(t=>{this._onButtonClick(t)}))}}},L._name="WebsiteUtilities",L._defaultOptions={additionalPageLoadingTimeInMilliseconds:0,startUpAnimationElementDelayInMilliseconds:100,windowLoadedTimeoutAfterDocLoadedInMSec:2e3,domain:"auto",knownScrollEventNames:["DOMMouseScroll","keyup","mousedown","mousewheel","scroll","touchmove","wheel"],sectionNames:{default:"",managed:["home"],unmanaged:[]},selectors:{windowLoadingCover:".wu-window-loading-cover",startUpAnimationClassPrefix:"wu-start-up-animation-number-",top:".wu-header",routerOutlet:".wu-router-outlet",scrollToTopButtons:".wu-scroll-to-top",activeNavigationItemClassName:"wu-priority-navigation__link--active",priorityNavigation:".wu-priority-navigation",priorityNavigationOverflow:".wu-priority-navigation__overflow",priorityNavigationOverflowTitle:".wu-priority-navigation__overflow__title",priorityNavigationOverflowList:".wu-priority-navigation__overflow__list"},tracking:!1},L.windowLoaded=!1,L.switchSectionLock=new x.Lock,h=L,m=A()(h.prototype,"options",[t],{configurable:!0,enumerable:!0,writable:!0,initializer:function(){return{}}}),w=A()(h.prototype,"onStartUpAnimationComplete",[e],{configurable:!0,enumerable:!0,writable:!0,initializer:function(){return x.NOOP}}),f=A()(h.prototype,"onSwitchSection",[o],{configurable:!0,enumerable:!0,writable:!0,initializer:function(){return x.NOOP}}),v=A()(h.prototype,"onViewportMovesAwayFromTop",[i],{configurable:!0,enumerable:!0,writable:!0,initializer:function(){return x.NOOP}}),g=A()(h.prototype,"onViewportMovesToTop",[n],{configurable:!0,enumerable:!0,writable:!0,initializer:function(){return x.NOOP}}),b=A()(h.prototype,"onSwitchToManualScrollingIndicator",[r],{configurable:!0,enumerable:!0,writable:!0,initializer:function(){return()=>!0}}),y=A()(h.prototype,"onLoaded",[s],{configurable:!0,enumerable:!0,writable:!0,initializer:function(){return x.NOOP}}),N=A()(h.prototype,"onButtonClick",[a],{configurable:!0,enumerable:!0,writable:!0,initializer:function(){return function(t){return Promise.resolve(void 0)}}}),S=A()(h.prototype,"onSectionSwitch",[l],{configurable:!0,enumerable:!0,writable:!0,initializer:function(){return function(t,e,o){return Promise.resolve(void 0)}}}),T=A()(h.prototype,"onLinkClick",[p],{configurable:!0,enumerable:!0,writable:!0,initializer:function(){return function(t){return Promise.resolve(void 0)}}}),_=A()(h.prototype,"onTrack",[d],{configurable:!0,enumerable:!0,writable:!0,initializer:function(){return function(t){return Promise.resolve(void 0)}}}),h);const P={component:M,register:(t=(0,x.camelCaseToDelimited)(M._name))=>{customElements.define(t,M)}},z=M;x.globalContext.AUTO_DEFINE_WEBSITE_UTILITIES&&P.register()})(),u})()));
1
+ "use strict";if("undefined"!=typeof module&&null!==module&&"undefined"!==eval("typeof require")&&null!==eval("require")&&"main"in eval("require")&&"undefined"!==eval("typeof require.main")&&null!==eval("require.main")){var ORIGINAL_MAIN_MODULE=module;module!==eval("require.main")&&"paths"in module&&"paths"in eval("require.main")&&"undefined"!=typeof __dirname&&null!==__dirname&&(module.paths=eval("require.main.paths").concat(module.paths.filter((function(path){return eval("require.main.paths").includes(path)}))))}if(null==window)var window="undefined"==typeof global||null===global?{}:global;!function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e(require("@babel/runtime/helpers/applyDecoratedDescriptor"),require("@babel/runtime/helpers/initializerDefineProperty"),require("@babel/runtime/helpers/initializerWarningHelper"),require("clientnode"),require("clientnode/property-types"),require("web-component-wrapper/Web"),require("web-component-wrapper/decorator"));else if("function"==typeof define&&define.amd)define(["@babel/runtime/helpers/applyDecoratedDescriptor","@babel/runtime/helpers/initializerDefineProperty","@babel/runtime/helpers/initializerWarningHelper","clientnode","clientnode/property-types","web-component-wrapper/Web","web-component-wrapper/decorator"],e);else{var o="object"==typeof exports?e(require("@babel/runtime/helpers/applyDecoratedDescriptor"),require("@babel/runtime/helpers/initializerDefineProperty"),require("@babel/runtime/helpers/initializerWarningHelper"),require("clientnode"),require("clientnode/property-types"),require("web-component-wrapper/Web"),require("web-component-wrapper/decorator")):e(t["@babel/runtime/helpers/applyDecoratedDescriptor"],t["@babel/runtime/helpers/initializerDefineProperty"],t["@babel/runtime/helpers/initializerWarningHelper"],t.clientnode,t["clientnode/property-types"],t["web-component-wrapper/Web"],t["web-component-wrapper/decorator"]);for(var i in o)("object"==typeof exports?exports:t)[i]=o[i]}}(this,((t,e,o,i,n,r,s)=>(()=>{var a=[,,,t=>{t.exports=e},e=>{e.exports=t},t=>{t.exports=o},t=>{t.exports=i},t=>{t.exports=n},t=>{t.exports=s},t=>{t.exports=r}],l={};function c(t){var e=l[t];if(void 0!==e)return e.exports;var o=l[t]={exports:{}};return a[t](o,o.exports,c),o.exports}c.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return c.d(e,{a:e}),e},c.d=(t,e)=>{for(var o in e)c.o(e,o)&&!c.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:e[o]})},c.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),c.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var u={};return(()=>{c.r(u),c.d(u,{WebsiteUtilities:()=>M,api:()=>P,default:()=>z,log:()=>E});var t,e,o,i,n,r,s,a,l,p,d,h,m,w,f,v,g,b,y,N,S,T,_,L,D=c(3),C=c.n(D),k=c(4),A=c.n(k),x=(c(5),c(6)),O=c(7),q=c(8),I=c(9);const E=new x.Logger({name:"website-utilities"});let M=(t=(0,q.property)({type:O.object}),e=(0,q.property)({type:O.func}),o=(0,q.property)({type:O.func}),i=(0,q.property)({type:O.func}),n=(0,q.property)({type:O.func}),r=(0,q.property)({type:O.func}),s=(0,q.property)({type:O.func}),a=(0,q.property)({type:O.func}),l=(0,q.property)({type:O.func}),p=(0,q.property)({type:O.func}),d=(0,q.property)({type:O.func}),L=class t extends I.Web{constructor(){super(),this.self=t,C()(this,"options",m,this),C()(this,"onStartUpAnimationComplete",w,this),C()(this,"onSwitchSection",f,this),C()(this,"onViewportMovesAwayFromTop",v,this),C()(this,"onViewportMovesToTop",g,this),C()(this,"onSwitchToManualScrollingIndicator",b,this),C()(this,"onLoaded",y,this),C()(this,"onButtonClick",N,this),C()(this,"onSectionSwitch",S,this),C()(this,"onLinkClick",T,this),C()(this,"onTrack",_,this),this.currentSectionName="",this.startUpAnimationIsComplete=!1,this.continueAutoScrolling=!1,this.viewportIsOnTop=void 0,this.observerDeregisters=[],this.windowLoadingCoverDomNode=null,this.topDomNode=null,this.priorityNavigationDomNodes=null,this.routerOutletDomNode=null,this.sectionDomNodes={},this.scrollToTopButtonDomNodes=null,this.defineGetterAndSetterInterface()}async onUpdateAttribute(t,e){await super.onUpdateAttribute(t,e),"options"===t&&this._extendOptions()}async render(t="unknown",e=!0){if(await super.render(t,!1),0===Object.keys(this.options).length&&this._extendOptions(),this.disableScrolling(),!this.self.windowLoaded){const t=()=>{this.self.windowLoaded||(this.self.windowLoaded=!0,this._removeLoadingCover().then((()=>{this.enableScrolling(),this._performStartUpEffects().then((()=>{this.addMenuHighlighterViewTransition()})),this.onLoaded()})))};(0,x.onDocumentReady)((()=>{(0,x.timeout)(t,this.options.windowLoadedTimeoutAfterDocLoadedInMSec)})),x.globalContext.window&&this.addSecureEventListener(x.globalContext.window,"load",t)}await this.waitForNestedComponentRendering(),this.grabDomNodes(),this._bindScrollEvents(),this._bindClickTracking(),await this._initializeRouting(),this.initializePriorityNavigation(),await this.resolveRenderingPromiseIfSet(t,e)}disconnectedCallback(){super.disconnectedCallback();for(const t of this.observerDeregisters)t()}grabDomNodes(){var t,e,o;this.topDomNode=this.hostDomNode.querySelector(this.options.selectors.top),this.scrollToTopButtonDomNodes=this.hostDomNode.querySelectorAll(this.options.selectors.scrollToTopButtons),this.priorityNavigationDomNodes=this.hostDomNode.querySelectorAll(this.options.selectors.priorityNavigation),this.routerOutletDomNode=this.hostDomNode.querySelector(this.options.selectors.routerOutlet);for(const t of null!==(i=this.routerOutletDomNode?.children)&&void 0!==i?i:[]){var i;const e=t.getAttribute("data-website-utilities-section");""===e?this.sectionDomNodes.default=t:e&&this.options.sectionNames.managed.includes(e)&&(this.sectionDomNodes[e]=t)}this.windowLoadingCoverDomNode=null!==(t=null!==(e=null!==(o=this.hostDomNode.querySelector(this.options.selectors.windowLoadingCover))&&void 0!==o?o:this.hostDomNode.parentElement?.querySelector(this.options.selectors.windowLoadingCover))&&void 0!==e?e:x.globalContext.document?.body.querySelector(this.options.selectors.windowLoadingCover))&&void 0!==t?t:null}interruptableScrollToTop(){const t=window.pageYOffset,e=performance.now();this.continueAutoScrolling=!0;const o=i=>{if(!this.continueAutoScrolling)return;const n=i-e,r=Math.min(n/500,1),s=r*(2-r);window.scrollTo(0,t*(1-s)),r<1?requestAnimationFrame(o):this.continueAutoScrolling=!1};requestAnimationFrame(o)}scrollToTop(){x.globalContext.document&&window.scrollTo({top:0,behavior:"smooth"})}disableScrolling(){this.hostDomNode.parentElement&&(this.hostDomNode.parentElement.classList.add("wu-disable-scrolling"),this.addSecureEventListener(this.hostDomNode.parentElement,"touchmove",x.preventDefault))}enableScrolling(){this.hostDomNode.parentElement&&(this.hostDomNode.parentElement.classList.remove("wu-disable-scrolling"),this.hostDomNode.parentElement.classList.remove("touchmove"),this.hostDomNode.parentElement.removeEventListener("touchmove",x.preventDefault))}async track(t){if(x.globalContext.window?.location&&this.options.tracking){const e={context:`${x.globalContext.window.location.pathname}#`+this.currentSectionName,...t};("number"!=typeof e.value||isNaN(e.value))&&(e.value=1),E.debug('Run tracking code: "event" with arguments:'),E.debug(e);try{await this._onTrack(e)}catch(t){E.warn(`Problem in tracking "${(0,x.represent)(e)}":`,(0,x.represent)(t))}}}initializePriorityNavigation(){if(0===this.priorityNavigationDomNodes?.length)return;for(const t of this.priorityNavigationDomNodes||[])for(const e of t.querySelectorAll(`[href="#${this.currentSectionName}"]`))e.classList.add(this.options.selectors.activeNavigationItemClassName);const t=()=>{for(const t of this.priorityNavigationDomNodes||[]){const e=t.querySelectorAll("ul > li"),o=Array.from(e).filter((t=>!t.classList.contains(this.options.selectors.priorityNavigationOverflow.substring(1)))),i=t.querySelector("ul > li").offsetTop,n=[];let r=!0,s=0;for(const t of o){t.offsetTop!==i&&(n.push(t),r&&(n.push(o[s-1]),r=!1)),s+=1}if(n.length){const e=n.map((t=>t.cloneNode(!0)));for(const t of n)t.classList.add("wu-priority-navigation__list__item--hide");const o=t.querySelector(this.options.selectors.priorityNavigationOverflowList);if(o)for(const t of e)o.append(t);const i=t.querySelector(this.options.selectors.priorityNavigationOverflow);i&&i.classList.add("wu-priority-navigation__overflow--inline-block"),t.style.overflow="visible"}}};for(const t of this.hostDomNode.querySelectorAll(this.options.selectors.priorityNavigationOverflowTitle))this.addSecureEventListener(t,"click",(()=>{for(const t of this.hostDomNode.querySelectorAll(this.options.selectors.priorityNavigationOverflowList))t.classList.toggle("wu-priority-navigation__overflow__list--show")}));for(const e of this.priorityNavigationDomNodes||[]){const o=(0,x.trailingThrottle)((()=>{for(const t of e.querySelectorAll(this.options.selectors.priorityNavigationOverflowList))for(;t.firstChild;)t.removeChild(t.firstChild);for(const t of e.querySelectorAll(this.options.selectors.priorityNavigationOverflow))t.classList.remove("wu-priority-navigation__overflow--show-inline-block");for(const t of e.querySelectorAll("ul > li"))t.classList.contains(this.options.selectors.priorityNavigationOverflow.substring(1))||t.classList.remove("wu-priority-navigation__list__item--hide");t(),e.classList.remove("wu-priority-navigation--resizing")}),20),i=new ResizeObserver((()=>{e.classList.add("wu-priority-navigation--resizing"),o()}));this.observerDeregisters.push((()=>{i.unobserve(e)})),i.observe(e)}t()}addMenuHighlighterViewTransition(){if(!x.globalContext.document)return;const t=document.createElement("style");t.type="text/css";t.appendChild(x.globalContext.document.createTextNode("\n a.wu-priority-navigation__link--active::after {\n view-transition-name: wu-menu-highlight;\n }\n ")),x.globalContext.document.getElementsByTagName("head")[0].appendChild(t)}activateNavigationItemHighlighters(t){const e=this.options.selectors.activeNavigationItemClassName;for(const o of this.priorityNavigationDomNodes||[]){for(const t of o.querySelectorAll(`.${e}`))t.classList.remove(e);for(const i of o.querySelectorAll(`[href="#${t}"]`))i.classList.add(e)}}triggerNavigationItemHighlighterSwitching(t){x.globalContext.document?.startViewTransition?x.globalContext.document.startViewTransition((()=>{this.activateNavigationItemHighlighters(t)})):this.activateNavigationItemHighlighters(t)}async _onButtonClick(t){if(!1===await this.onButtonClick(t))return;const e=t.target,o=(0,x.getText)(e).join(" ");this._onTrack({event:"buttonClick",eventType:"click",label:o,reference:e.getAttribute("action")||e.getAttribute("target")||e.getAttribute("type")||o,subject:"button",value:parseInt(e.getAttribute("website-analytics-value")||"1"),userInteraction:!0})}async _onSectionSwitch(t,e,o){!1!==await this.onSectionSwitch(t,e,o)&&x.globalContext.window?.location&&await this._onTrack({event:"sectionSwitch",eventType:"sectionSwitch",label:t,reference:`${x.globalContext.window.location.pathname}#${t}`,subject:"url",userInteraction:!1})}async _onLinkClick(t){if(!1===await this.onLinkClick(t))return;const e=t.target,o=(0,x.getText)(e).join(" ");this._onTrack({event:"linkClick",eventType:"click",label:o,reference:e.getAttribute("href")||e.getAttribute("action")||e.getAttribute("target")||e.getAttribute("type")||o,subject:"link",value:parseInt(e.getAttribute("website-analytics-value")||"1"),userInteraction:!0})}async _onTrack(t){!1!==await this.onTrack(t)&&this.options.tracking&&x.globalContext.dataLayer?.push(t)}_onViewportMovesToTop(){this._finishScrollToTopButtonTransition();for(const e of null!==(t=this.scrollToTopButtonDomNodes)&&void 0!==t?t:[]){var t;const o=()=>{e.removeEventListener("transitionend",i),e.removeEventListener("transitioncancel",o)},i=()=>{this.viewportIsOnTop&&e.classList.add("wu-top-settled"),o()};e.addEventListener("transitionend",i,{once:!0}),e.addEventListener("transitioncancel",o,{once:!0}),e.classList.add("wu-scroll-up")}}async _onViewportMovesAwayFromTop(){this._finishScrollToTopButtonTransition("wu-top-settled"),await(0,x.timeout)(),this._finishScrollToTopButtonTransition();for(const e of null!==(t=this.scrollToTopButtonDomNodes)&&void 0!==t?t:[]){var t;e.classList.add("wu-scroll-down")}}async switchSection(t,e){if(x.globalContext.window&&"location"in x.globalContext.window&&(""===t||this.options.sectionNames.managed.includes(t)||this.options.sectionNames.unmanaged.includes(t))){var o,i;const n=Object.prototype.hasOwnProperty.call(this.sectionDomNodes,this.currentSectionName)?this.sectionDomNodes[this.currentSectionName]:null!==(o=this.sectionDomNodes.default)&&void 0!==o?o:null,r=Object.prototype.hasOwnProperty.call(this.sectionDomNodes,t)?this.sectionDomNodes[t]:null!==(i=this.sectionDomNodes.default)&&void 0!==i?i:null;await this.self.switchSectionLock.acquire(),this.triggerNavigationItemHighlighterSwitching(t),E.debug(`Run section switch from "${this.currentSectionName}" to`,`"${t}".`),this.currentSectionName===t?(n&&(n.classList.remove("wu-section-active"),n.classList.add("wu-section-inactive")),r&&(r.classList.remove("wu-section-inactive"),r.classList.add("wu-section-active"))):this.options.sectionNames.unmanaged.includes(t)&&this.options.sectionNames.unmanaged.includes(this.currentSectionName)||(this.interruptableScrollToTop(),n&&(await(0,x.fadeOut)(n),n.classList.remove("wu-section-active"),n.classList.add("wu-section-inactive")),r&&(r.classList.remove("wu-section-inactive"),r.classList.add("wu-section-active"),await(0,x.fadeIn)(r)));const s=this.currentSectionName;this.currentSectionName=t;try{await this._onSectionSwitch(this.currentSectionName,s,e)}catch(t){E.warn("Problem due to call section switch callback on section",`"${this.currentSectionName}": ${(0,x.represent)(t)}`)}await this.self.switchSectionLock.release()}}_extendOptions(){this.setPropertyValue("options",(0,x.extend)(!0,{},this.self._defaultOptions,this.options))}_initializeRouting(){""===this.currentSectionName&&(this.currentSectionName=this.options.sectionNames.default),this._bindNavigationEvents();const t=x.globalContext.location?.hash&&x.globalContext.location.hash.substring(1);t&&(this.options.sectionNames.managed.includes(t)||this.options.sectionNames.unmanaged.includes(t))&&(this.currentSectionName=t);for(const t of Object.values(this.sectionDomNodes))t.classList.add("wu-section-inactive");return this.switchSection(t||this.currentSectionName)}_finishScrollToTopButtonTransition(t=["wu-scroll-down","wu-scroll-up"]){for(const o of null!==(e=this.scrollToTopButtonDomNodes)&&void 0!==e?e:[]){var e;o.classList.remove(...[].concat(t))}}_bindScrollEvents(){if(x.globalContext.document){for(const t of[x.globalContext.document.body,x.globalContext.document.querySelector("html"),x.globalContext.window])for(const e of this.options.knownScrollEventNames)t&&this.addSecureEventListener(t,e,(t=>{this.onSwitchToManualScrollingIndicator(t)&&(this.continueAutoScrolling=!1)}));if(x.globalContext.window&&this.addSecureEventListener(x.globalContext.window,"scroll",(t=>{x.globalContext.window?.scrollY?this.viewportIsOnTop&&(this.viewportIsOnTop=!1,this._onViewportMovesAwayFromTop().then(this.onViewportMovesAwayFromTop.bind(this,t))):this.viewportIsOnTop||(this.viewportIsOnTop=!0,this._onViewportMovesToTop(),this.onViewportMovesToTop(t))})),x.globalContext.window?.scrollY)this.viewportIsOnTop=!1,this._onViewportMovesAwayFromTop().then((()=>{this.onViewportMovesAwayFromTop()}));else{this.viewportIsOnTop=!0;for(const e of null!==(t=this.scrollToTopButtonDomNodes)&&void 0!==t?t:[]){var t;e.classList.add("wu-top-settled")}this._onViewportMovesToTop(),this.onViewportMovesToTop()}}}async _removeLoadingCover(){await(0,x.timeout)(this.options.additionalPageLoadingTimeInMilliseconds);for(const t of this.hostDomNode.querySelectorAll(`[class^="${this.options.selectors.startUpAnimationClassPrefix}"], [class*=" ${this.options.selectors.startUpAnimationClassPrefix}"]`))t.style.opacity="0";this.windowLoadingCoverDomNode&&await(0,x.fadeOut)(this.windowLoadingCoverDomNode)}async _performStartUpEffects(){const t=[];let e=1;for(;;){const o=this.hostDomNode.querySelectorAll("."+this.options.selectors.startUpAnimationClassPrefix+String(e));if(0===o.length){await Promise.all(t),this.startUpAnimationIsComplete=!0,this.onStartUpAnimationComplete();break}await(0,x.timeout)(this.options.startUpAnimationElementDelayInMilliseconds);for(const e of o)t.push((0,x.fadeIn)(e));e+=1}}_bindNavigationEvents(){x.globalContext.window&&this.addSecureEventListener(x.globalContext.window,"hashchange",(t=>{if(this.startUpAnimationIsComplete){const e=location.hash.substring(1);this.switchSection(e,t)}})),this._bindScrollToTopButton()}_bindScrollToTopButton(){for(const t of this.scrollToTopButtonDomNodes||[])this.addSecureEventListener(t,"click",(t=>{t.preventDefault(),this.interruptableScrollToTop()}))}_bindClickTracking(){if(this.options.tracking){for(const t of this.hostDomNode.querySelectorAll("a"))this.addSecureEventListener(t,"click",(t=>{this._onLinkClick(t)}));for(const t of this.hostDomNode.querySelectorAll("button"))this.addSecureEventListener(t,"click",(t=>{this._onButtonClick(t)}))}}},L._name="WebsiteUtilities",L._defaultOptions={additionalPageLoadingTimeInMilliseconds:0,startUpAnimationElementDelayInMilliseconds:100,windowLoadedTimeoutAfterDocLoadedInMSec:2e3,domain:"auto",knownScrollEventNames:["DOMMouseScroll","keyup","mousedown","mousewheel","scroll","touchmove","wheel"],sectionNames:{default:"",managed:["home"],unmanaged:[]},selectors:{windowLoadingCover:".wu-window-loading-cover",startUpAnimationClassPrefix:"wu-start-up-animation-number-",top:".wu-header",routerOutlet:".wu-router-outlet",scrollToTopButtons:".wu-scroll-to-top",activeNavigationItemClassName:"wu-priority-navigation__link--active",priorityNavigation:".wu-priority-navigation",priorityNavigationOverflow:".wu-priority-navigation__overflow",priorityNavigationOverflowTitle:".wu-priority-navigation__overflow__title",priorityNavigationOverflowList:".wu-priority-navigation__overflow__list"},tracking:!1},L.windowLoaded=!1,L.switchSectionLock=new x.Lock,h=L,m=A()(h.prototype,"options",[t],{configurable:!0,enumerable:!0,writable:!0,initializer:function(){return{}}}),w=A()(h.prototype,"onStartUpAnimationComplete",[e],{configurable:!0,enumerable:!0,writable:!0,initializer:function(){return x.NOOP}}),f=A()(h.prototype,"onSwitchSection",[o],{configurable:!0,enumerable:!0,writable:!0,initializer:function(){return x.NOOP}}),v=A()(h.prototype,"onViewportMovesAwayFromTop",[i],{configurable:!0,enumerable:!0,writable:!0,initializer:function(){return x.NOOP}}),g=A()(h.prototype,"onViewportMovesToTop",[n],{configurable:!0,enumerable:!0,writable:!0,initializer:function(){return x.NOOP}}),b=A()(h.prototype,"onSwitchToManualScrollingIndicator",[r],{configurable:!0,enumerable:!0,writable:!0,initializer:function(){return()=>!0}}),y=A()(h.prototype,"onLoaded",[s],{configurable:!0,enumerable:!0,writable:!0,initializer:function(){return x.NOOP}}),N=A()(h.prototype,"onButtonClick",[a],{configurable:!0,enumerable:!0,writable:!0,initializer:function(){return function(t){return Promise.resolve(void 0)}}}),S=A()(h.prototype,"onSectionSwitch",[l],{configurable:!0,enumerable:!0,writable:!0,initializer:function(){return function(t,e,o){return Promise.resolve(void 0)}}}),T=A()(h.prototype,"onLinkClick",[p],{configurable:!0,enumerable:!0,writable:!0,initializer:function(){return function(t){return Promise.resolve(void 0)}}}),_=A()(h.prototype,"onTrack",[d],{configurable:!0,enumerable:!0,writable:!0,initializer:function(){return function(t){return Promise.resolve(void 0)}}}),h);const P={component:M,register:(t=(0,x.camelCaseToDelimited)(M._name))=>{customElements.define(t,M)}},z=M;x.globalContext.AUTO_DEFINE_WEBSITE_UTILITIES&&P.register()})(),u})()));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "website-utilities",
3
- "version": "1.0.415",
3
+ "version": "1.0.416",
4
4
  "description": "extend your web app",
5
5
  "keywords": [
6
6
  "website",