{ | |
"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 const siteHeader = document.querySelector('.js-siteHeader');\n if (this.mainHeader?.hasChildNodes() && siteHeader) {\n const headerSentinel = document.createElement('div');\n siteHeader.append(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": "AAAA,AAOA,GAAM,GAAe,IACf,EAAkB,IAOjB,OAA2B,CAKhC,YACU,EACA,EACA,EACR,CAHQ,kBACA,eACA,iBAgEF,uBAAmC,GAAK,CAvFlD,QAyFI,AAAI,AADW,EAAE,SACF,SAAK,aAAL,cAAiB,mBAC9B,WAAO,iBAAP,QAAuB,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,CAnGrB,QAoGM,GAAM,GAAoB,YAAK,aAAL,cA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