{ | |
"version": 3, | |
"sources": ["unit.ts"], | |
"sourcesContent": ["/**\n * @license\n * Copyright 2021 The Go Authors. All rights reserved.\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file.\n */\n\nconst headerHeight = 3.5;\nconst breadcumbHeight = 2.5;\n\n/**\n * MainLayoutController calculates dynamic height values for header elements\n * to support variable size sticky positioned elements in the header so that\n * banners and breadcumbs may overflow to multiple lines.\n */\nexport class MainLayoutController {\n private headerObserver: IntersectionObserver;\n private navObserver: IntersectionObserver;\n private asideObserver: IntersectionObserver;\n\n constructor(\n private mainHeader?: Element | null,\n private mainNav?: Element | null,\n private mainAside?: Element | null\n ) {\n this.headerObserver = new IntersectionObserver(\n ([e]) => {\n if (e.intersectionRatio < 1) {\n for (const x of document.querySelectorAll('[class^=\"go-Main-header\"')) {\n x.setAttribute('data-fixed', 'true');\n }\n } else {\n for (const x of document.querySelectorAll('[class^=\"go-Main-header\"')) {\n x.removeAttribute('data-fixed');\n }\n this.handleResize();\n }\n },\n { threshold: 1, rootMargin: `${breadcumbHeight * 16}px` }\n );\n this.navObserver = new IntersectionObserver(\n ([e]) => {\n if (e.intersectionRatio < 1) {\n this.mainNav?.classList.add('go-Main-nav--fixed');\n this.mainNav?.setAttribute('data-fixed', 'true');\n } else {\n this.mainNav?.classList.remove('go-Main-nav--fixed');\n this.mainNav?.removeAttribute('data-fixed');\n }\n },\n { threshold: 1, rootMargin: `-${headerHeight * 16 + 10}px` }\n );\n this.asideObserver = new IntersectionObserver(\n ([e]) => {\n if (e.intersectionRatio < 1) {\n this.mainHeader?.setAttribute('data-raised', 'true');\n } else {\n this.mainHeader?.removeAttribute('data-raised');\n }\n },\n { threshold: 1, rootMargin: `-${headerHeight * 16 + 20}px 0px 0px 0px` }\n );\n this.init();\n }\n\n private init() {\n this.handleResize();\n window.addEventListener('resize', this.handleResize);\n this.mainHeader?.addEventListener('dblclick', this.handleDoubleClick);\n if (this.mainHeader?.hasChildNodes()) {\n const headerSentinel = document.createElement('div');\n this.mainHeader.prepend(headerSentinel);\n this.headerObserver.observe(headerSentinel);\n }\n if (this.mainNav?.hasChildNodes()) {\n const navSentinel = document.createElement('div');\n this.mainNav.prepend(navSentinel);\n this.navObserver.observe(navSentinel);\n }\n if (this.mainAside) {\n const asideSentinel = document.createElement('div');\n this.mainAside.prepend(asideSentinel);\n this.asideObserver.observe(asideSentinel);\n }\n }\n\n private handleDoubleClick: EventListener = e => {\n const target = e.target;\n if (target === this.mainHeader?.lastElementChild) {\n window.getSelection()?.removeAllRanges();\n window.scrollTo({ top: 0, behavior: 'smooth' });\n }\n };\n\n private handleResize = () => {\n const setProp = (name: string, value: string) =>\n document.documentElement.style.setProperty(name, value);\n setProp('--js-unit-header-height', '0');\n setTimeout(() => {\n const mainHeaderHeight = (this.mainHeader?.getBoundingClientRect().height ?? 0) / 16;\n setProp('--js-unit-header-height', `${mainHeaderHeight}rem`);\n setProp('--js-sticky-header-height', `${headerHeight}rem`);\n setProp('--js-unit-header-top', `${(mainHeaderHeight - headerHeight) * -1}rem`);\n });\n };\n}\n\nconst el = <T extends HTMLElement>(selector: string) => document.querySelector<T>(selector);\nnew MainLayoutController(el('.js-mainHeader'), el('.js-mainNav'), el('.js-mainAside'));\n"], | |
"mappings": "MAAA,AAOA,GAAM,GAAe,IACf,EAAkB,IAOjB,OAA2B,CAKhC,YACU,EACA,EACA,EACR,CAHQ,kBACA,eACA,iBA+DF,uBAAmC,GAAK,CAE9C,AAAI,AADW,EAAE,SACF,KAAK,YAAY,kBAC9B,QAAO,gBAAgB,kBACvB,OAAO,SAAS,CAAE,IAAK,EAAG,SAAU,aAIhC,kBAAe,IAAM,CAC3B,GAAM,GAAU,CAAC,EAAc,IAC7B,SAAS,gBAAgB,MAAM,YAAY,EAAM,GACnD,EAAQ,0BAA2B,KACnC,WAAW,IAAM,CACf,GAAM,GAAoB,MAAK,YAAY,wBAAwB,QAAU,GAAK,GAClF,EAAQ,0BAA2B,GAAG,QACtC,EAAQ,4BAA6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