@zanichelli/zanichelli-it-frontend-kit 1.4.1 → 1.4.2
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.
- package/dist/cjs/{index-BLzQAHAI.js → index-BKkNg6ed.js} +498 -358
- package/dist/cjs/index.cjs.js +0 -3
- package/dist/cjs/loader.cjs.js +2 -5
- package/dist/cjs/zanichelli-it-frontend-kit.cjs.js +3 -6
- package/dist/cjs/zanit-back-to-top_4.cjs.entry.js +75 -62
- package/dist/collection/collection-manifest.json +3 -2
- package/dist/collection/components/back-to-top/back-to-top.js +3 -4
- package/dist/collection/components/menubar/menu/menu.js +0 -1
- package/dist/collection/components/menubar/menubar.js +12 -11
- package/dist/collection/components/menubar/mobile-menubar/mobile-menubar.js +12 -13
- package/dist/collection/components/menubar/search-form/search-form.js +14 -12
- package/dist/collection/components/menubar/search-form/suggestions.js +0 -1
- package/dist/collection/index.js +0 -1
- package/dist/collection/utils/index.js +0 -1
- package/dist/collection/utils/subjects.api.js +0 -1
- package/dist/collection/utils/utils.js +0 -1
- package/dist/components/index.d.ts +2 -0
- package/dist/components/index.js +1 -1335
- package/dist/components/p-BMtMaJq9.js +1 -0
- package/dist/components/p-BXeRLfHX.js +1 -0
- package/dist/components/zanit-back-to-top.js +1 -88
- package/dist/components/zanit-menubar.js +1 -455
- package/dist/components/zanit-mobile-menubar.js +1 -9
- package/dist/components/zanit-search-form.js +1 -9
- package/dist/esm/{index-DSdvvVFj.js → index-CFgcJxsy.js} +498 -358
- package/dist/esm/index.js +0 -3
- package/dist/esm/loader.js +3 -6
- package/dist/esm/zanichelli-it-frontend-kit.js +4 -7
- package/dist/esm/zanit-back-to-top_4.entry.js +75 -62
- package/dist/types/components/back-to-top/back-to-top.d.ts +2 -1
- package/dist/types/components/menubar/menubar.d.ts +2 -1
- package/dist/types/components/menubar/mobile-menubar/mobile-menubar.d.ts +2 -1
- package/dist/types/components/menubar/search-form/search-form.d.ts +3 -2
- package/dist/types/components.d.ts +35 -8
- package/dist/types/stencil-public-runtime.d.ts +169 -11
- package/dist/zanichelli-it-frontend-kit/index.esm.js +0 -2
- package/dist/zanichelli-it-frontend-kit/p-93d8b277.entry.js +1 -0
- package/dist/zanichelli-it-frontend-kit/p-CFgcJxsy.js +2 -0
- package/dist/zanichelli-it-frontend-kit/zanichelli-it-frontend-kit.esm.js +1 -2
- package/package.json +17 -15
- package/www/build/index.esm.js +0 -2
- package/www/build/p-93d8b277.entry.js +1 -0
- package/www/build/p-CFgcJxsy.js +2 -0
- package/www/build/p-ec9829f4.js +1 -0
- package/www/build/zanichelli-it-frontend-kit.esm.js +1 -2
- package/www/index.html +2 -1
- package/dist/cjs/index-BLzQAHAI.js.map +0 -1
- package/dist/cjs/index.cjs.js.map +0 -1
- package/dist/cjs/loader.cjs.js.map +0 -1
- package/dist/cjs/zanichelli-it-frontend-kit.cjs.js.map +0 -1
- package/dist/cjs/zanit-back-to-top.zanit-menubar.zanit-mobile-menubar.zanit-search-form.entry.cjs.js.map +0 -1
- package/dist/cjs/zanit-back-to-top_4.cjs.entry.js.map +0 -1
- package/dist/collection/components/back-to-top/back-to-top.js.map +0 -1
- package/dist/collection/components/menubar/menu/menu.js.map +0 -1
- package/dist/collection/components/menubar/menubar.js.map +0 -1
- package/dist/collection/components/menubar/mobile-menubar/mobile-menubar.js.map +0 -1
- package/dist/collection/components/menubar/search-form/search-form.js.map +0 -1
- package/dist/collection/components/menubar/search-form/suggestions.js.map +0 -1
- package/dist/collection/index.js.map +0 -1
- package/dist/collection/utils/index.js.map +0 -1
- package/dist/collection/utils/subjects.api.js.map +0 -1
- package/dist/collection/utils/utils.js.map +0 -1
- package/dist/components/index.js.map +0 -1
- package/dist/components/p-BlgoYKK3.js +0 -246
- package/dist/components/p-BlgoYKK3.js.map +0 -1
- package/dist/components/p-DqMqkNnl.js +0 -386
- package/dist/components/p-DqMqkNnl.js.map +0 -1
- package/dist/components/zanit-back-to-top.js.map +0 -1
- package/dist/components/zanit-menubar.js.map +0 -1
- package/dist/components/zanit-mobile-menubar.js.map +0 -1
- package/dist/components/zanit-search-form.js.map +0 -1
- package/dist/esm/index-DSdvvVFj.js.map +0 -1
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/loader.js.map +0 -1
- package/dist/esm/zanichelli-it-frontend-kit.js.map +0 -1
- package/dist/esm/zanit-back-to-top.zanit-menubar.zanit-mobile-menubar.zanit-search-form.entry.js.map +0 -1
- package/dist/esm/zanit-back-to-top_4.entry.js.map +0 -1
- package/dist/zanichelli-it-frontend-kit/index.esm.js.map +0 -1
- package/dist/zanichelli-it-frontend-kit/loader.esm.js.map +0 -1
- package/dist/zanichelli-it-frontend-kit/p-62cc02c2.entry.js +0 -2
- package/dist/zanichelli-it-frontend-kit/p-62cc02c2.entry.js.map +0 -1
- package/dist/zanichelli-it-frontend-kit/p-DSdvvVFj.js +0 -3
- package/dist/zanichelli-it-frontend-kit/p-DSdvvVFj.js.map +0 -1
- package/dist/zanichelli-it-frontend-kit/zanichelli-it-frontend-kit.esm.js.map +0 -1
- package/dist/zanichelli-it-frontend-kit/zanit-back-to-top.zanit-menubar.zanit-mobile-menubar.zanit-search-form.entry.esm.js.map +0 -1
- package/www/build/index.esm.js.map +0 -1
- package/www/build/loader.esm.js.map +0 -1
- package/www/build/p-62cc02c2.entry.js +0 -2
- package/www/build/p-62cc02c2.entry.js.map +0 -1
- package/www/build/p-DSdvvVFj.js +0 -3
- package/www/build/p-DSdvvVFj.js.map +0 -1
- package/www/build/p-fe3aec03.js +0 -2
- package/www/build/zanichelli-it-frontend-kit.esm.js.map +0 -1
- package/www/build/zanit-back-to-top.zanit-menubar.zanit-mobile-menubar.zanit-search-form.entry.esm.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{h as e,t,p as i,H as n}from"./index.js";import{d as a,S as r,m as o,c as s}from"./p-BXeRLfHX.js";const m="default",l={id:m,label:m},d=({controlledBy:t,items:i,currentPath:n=[],onItemKeyDown:a})=>{if(!i?.length)return null;const r=(e=>e.reduce(((e,t)=>{const i=e.find((({group:e})=>e.id===(t.group?.id||l.id)));return i?i.items.push(t):e.push({group:t.group??l,items:[t]}),e}),[]).sort(((e,t)=>e.group.id===m?1:t.group.id===m?-1:0)))(i),o=e=>n.includes(t)&&n.includes(e.id);return e("div",{class:"menu-wrapper",role:"none"},e("div",{class:"menu","aria-labelledby":t??void 0,role:"menu"},r.map((({group:t,items:i})=>e("div",{class:{group:!0,highlight:i.some((e=>e.highlight))}},t.id!==m?e("div",{class:"group-name",id:t.id},t.label):r.length>1?e("div",{class:"group-name"}):null,e("ul",{class:"menu-list",role:"group","aria-labelledby":t.id!==m?t.id:void 0},i.map((t=>e("li",{role:"none"},t.href&&e("a",{class:{"menu-item":!0,active:o(t)},href:t.href,role:"menuitem",tabIndex:-1,"aria-current":o(t)?"page":"false",onKeyDown:e=>a(e),target:t.target},t.label))))))))))},h=i(class extends n{constructor(e){super(),!1!==e&&this.__registerHost(),this.__attachShadow()}get host(){return this}currentPath=[];items=[];searchQuery=void 0;loading=!1;searchEnv=r.PROD;searchArea;lastCurrent=void 0;parentItem=void 0;menuItems=void 0;menuType=void 0;open=!1;onItemsChange(){this.lastCurrent=this.currentPath?.length?this.currentPath[this.currentPath.length-1]:void 0,this.setupData(this.items)}setupData(e,t){if(void 0===this.lastCurrent)return this.parentItem=void 0,this.menuType="menubar",void(this.menuItems=e);for(const i of e){if(i.id===this.lastCurrent)return this.parentItem=t,this.menuType=i.menuItems?.length?"menu":"menubar",void(this.menuItems=i.menuItems||i.navbarItems);if(this.currentPath.length>1&&i.id===this.currentPath[this.currentPath.length-2]&&i.menuItems?.some((({id:e})=>e===this.lastCurrent)))return this.parentItem=i,this.menuType=i.menuItems?.length?"menu":"menubar",void(this.menuItems=i.menuItems||i.navbarItems);i.navbarItems?.length&&this.setupData(i.navbarItems,i)}}get menuItemsElement(){return Array.from(this.host.shadowRoot.querySelectorAll('[role="menuitem"]'))}initTabindex(){this.menuItemsElement.forEach(((e,t)=>e.setAttribute("tabindex",0===t?"0":"-1")))}toggleMenu(){this.open?this.open=!1:(this.open=!0,setTimeout((()=>{this.initTabindex(),this.menuItemsElement[0]?.focus({preventScroll:!0})}),200))}handleItemKeydown(e){switch(e.key){case"ArrowUp":{e.preventDefault(),e.stopPropagation();const t=this.menuItemsElement,i=t.indexOf(e.target);o(t[i],t[(i-1+t.length)%t.length]);break}case"ArrowDown":{e.preventDefault(),e.stopPropagation();const t=this.menuItemsElement,i=t.indexOf(e.target);o(t[i],t[(i+1)%t.length]);break}case"Home":e.preventDefault(),e.stopPropagation(),o(e.target,this.menuItemsElement[0]);break;case"End":e.preventDefault(),e.stopPropagation(),o(e.target,this.menuItemsElement.pop())}}connectedCallback(){this.lastCurrent=this.currentPath?.length?this.currentPath[this.currentPath.length-1]:void 0,this.setupData(this.items)}handleOutsideClick(e){s(this.host,e)||(this.open=!1)}handleKeydown(e){switch(e.key){case"Escape":this.open=!1;break;case"Tab":if(s(this.host,e))break;this.open=!1}}handleFocusout(e){s(this.host,e)||(this.open=!1)}render(){return e("nav",{key:"e3c4f8212d54b84206c2d40c9670263dd0f2460a","aria-label":"Zanichelli.it"},e("button",{key:"8f4600dbb2c530e5901127d556eee94dcd60947a",class:"burger-button",type:"button","aria-expanded":this.open?"true":"false","aria-controls":"mobile-menu","aria-label":this.open?"Chiudi menù":"Apri menù",onClick:()=>this.toggleMenu()},e("z-icon",{key:"aa3d06cca2f2c7e92cb4afb37a5085ea37ec8283",name:this.open?"multiply":"burger-menu",width:"1.5rem",height:"1.5rem"})),e("z-logo",{key:"af3724fc7f330c7b2f7d826bd0dd2edc2dbb5742",imageAlt:"Logo Zanichelli",link:"/",height:32,width:126}),e("zanit-search-form",{key:"cc3c8e2ece6ac0428864d8affcd567c9a1272824",searchQuery:this.searchQuery,onResetSearch:()=>this.searchQuery=void 0,searchArea:this.searchArea,searchEnv:this.searchEnv}),this.open&&e("ul",{key:"0c35b0f4869ae076a1c02f07f1b19e787f4c3780",class:"mobile-menu",role:"menubar"},!this.loading&&this.currentPath&&this.currentPath.length>0&&e("li",{key:"ff8e9d8871ebea21ba178d1ba9d295d26b018be2",role:"none"},e("a",{key:"4afb5ccda0e206f640f429ecfe7ac1e3491a475d",class:"parent",href:this.parentItem?.href??"/",id:this.parentItem?.id??void 0,role:"menuitem",tabIndex:-1,onKeyDown:e=>this.handleItemKeydown(e),target:this.parentItem?.target},e("z-icon",{key:"2db8da21ad88b937d591eac551a3599704e13147",name:"arrow-left",width:"0.5rem",height:"0.5rem"}),e("span",{key:"d285244285ccee5e76db049cb4fba1dd591d7ce1"},this.parentItem?.label||"Home"))),this.loading?e("div",{class:"items-container",role:"none"},[...new Array(4)].map((()=>e("li",{role:"none"},e("div",{class:"menubar-item",role:"none"},e("z-ghost-loading",null)))))):"menu"===this.menuType?e(d,{items:this.menuItems,controlledBy:this.parentItem?.id,currentPath:this.currentPath,onItemKeyDown:e=>this.handleItemKeydown(e)}):this.menuItems?.length>0&&e("div",{class:"items-container",role:"none"},this.menuItems.map((t=>e("li",{role:"none"},e("a",{class:{"menu-item":"menu"===this.menuType,"menubar-item":"menubar"===this.menuType},href:t.href,id:t.id,role:"menuitem","aria-current":this.lastCurrent===t.id?"page":"false",tabIndex:-1,onKeyDown:e=>this.handleItemKeydown(e),target:t.target},e("span",{"data-text":t.label},t.label))))))))}static get delegatesFocus(){return!0}static get watchers(){return{items:[{onItemsChange:0}],currentPath:[{onItemsChange:0}]}}static get style(){return":host{position:relative;z-index:2;display:block;width:100%;max-width:100%;height:3rem;background-color:#fff;color:var(--gray900);fill:var(--gray900);font-family:var(--font-family-sans)}:host,*,::before,::after{box-sizing:border-box}*:focus:focus-visible{box-shadow:var(--shadow-focus-primary);outline:none}ul{padding:0;margin:0;list-style:none}a{color:var(--gray900);cursor:pointer;text-decoration:none}button{all:unset;cursor:pointer}nav{display:flex;width:100%;align-items:center;padding-left:var(--grid-margin);gap:8px}nav::after{position:absolute;top:0;right:0;width:100%;height:100%;background:transparent;box-shadow:var(--shadow-1);content:'';pointer-events:none}z-logo{margin:8px 0}.mobile-menu{position:absolute;top:100%;left:0;display:flex;overflow:auto;width:100%;max-height:calc(100vh - 48px - var(--zanit-menubar-top-offset, 0px));flex-direction:column;padding:16px var(--grid-margin) 32px;background-color:#fff;box-shadow:var(--shadow-2);gap:8px}.mobile-menu li{width:100%}.mobile-menu .items-container{display:flex;min-height:256px;flex-direction:column;gap:8px}.mobile-menu .items-container z-ghost-loading{width:40%;height:1.2rem}.mobile-menu .items-container .menubar-item{display:block;width:100%;padding:8px 0;font-size:1rem;text-align:left}.mobile-menu .items-container li:not(:last-child) .menubar-item{border-bottom:1px solid #000}[role='menuitem'].parent{display:flex;width:fit-content;align-items:center;padding:0;border:none;font-size:0.875rem;gap:8px}zanit-search-form{margin-left:auto}.menu-wrapper{width:100%;background-color:#fff}.menu{position:relative;display:flex;width:100%;flex-direction:column;gap:32px 0}.menu .group{display:flex;flex-direction:column}.menu .group .group-name{border-bottom:1px solid currentcolor;margin-bottom:4px;color:var(--red500);font-size:0.875rem;font-weight:var(--font-md)}.menu .group .menu-list{display:flex;flex-direction:column;gap:8px}.menu .group .menu-list .menu-item{display:block;border-bottom:2px solid transparent;font-size:0.875rem;font-weight:var(--font-md)}.menu .menu-list .menu-item.active,.menu .menu-list .menu-item:hover{border-bottom-color:var(--red500)}.menu .group.highlight .menu-list .menu-item{font-size:1rem}@media (width >= 768px){.menu-wrapper{position:absolute;top:100%;left:0;display:flex;justify-content:center;box-shadow:var(--shadow-1)}.menu{display:grid;width:100%;max-width:var(--zanit-menubar-max-width, 1366px);padding:16px var(--grid-margin);gap:0 24px;grid-auto-columns:minmax(0, max-content);grid-auto-flow:column;grid-template-rows:minmax(0, max-content) max-content}.menu .group{display:grid;grid-row:1 / -1;grid-template-columns:1fr;grid-template-rows:subgrid}@supports not (grid-template-rows: subgrid){.menu .group{grid-template-rows:repeat(auto-fit, minmax(0, max-content))}}.menu .group .group-name{border:none;margin-bottom:16px}.menu .group .menu-list .menu-item{font-size:1rem}.menu .group.highlight .menu-list .menu-item{font-size:1.5rem}}"}},[529,"zanit-mobile-menubar",{currentPath:[16],items:[16],searchQuery:[1025,"search-query"],loading:[4],searchEnv:[1,"search-env"],searchArea:[1,"search-area"],lastCurrent:[32],parentItem:[32],menuItems:[32],menuType:[32],open:[32]},[[5,"click","handleOutsideClick"],[1,"keydown","handleKeydown"],[5,"focusin","handleFocusout"]],{items:[{onItemsChange:0}],currentPath:[{onItemsChange:0}]}]);function u(){"undefined"!=typeof customElements&&["zanit-mobile-menubar","zanit-search-form"].forEach((e=>{switch(e){case"zanit-mobile-menubar":customElements.get(t(e))||customElements.define(t(e),h);break;case"zanit-search-form":customElements.get(t(e))||a()}}))}u();export{d as M,h as Z,u as d}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{t as e,p as a,H as t,c as r,h as i,a as s}from"./index.js";const n=(e,a)=>a.composedPath().filter((e=>e!==document&&e!==window.window)).some((a=>e.contains(a))),o=(e,a)=>{e.tabIndex=-1,a.tabIndex=0,a.focus({preventScroll:!0})},h=e=>"ArrowDown"===e.key,c=e=>"Escape"===e.key;var d;!function(e){e.DEV="dev",e.TEST="test",e.PROD="prod"}(d||(d={}));const u={dev:"https://zanichelli-shop-dev.s3.eu-west-1.amazonaws.com",test:"https://zanichelli-shop-test.s3.eu-west-1.amazonaws.com",prod:"https://zanichelli-shop.s3.eu-west-1.amazonaws.com"};var l;!function(e){e.SCUOLA="Scuola",e["UNIVERSITÀ"]="Università",e.GIURIDICO="Giuridico",e.DIZIONARI="Dizionari",e.SAGGISTICA="Saggistica"}(l||(l={}));const b=Object.keys(l);const g=(e,a)=>({id:f(`word-${e}-${a}`),label:v(e,a),aria_label:y(e,a,!1),url:m({q:e,...a?{area:a}:{},user_query:e}),...w(e,e,a)}),p=(e,a,t)=>({id:f(`subj-${e}-${a}-${t}`),label:v(e,a),aria_label:y(e,a,!0),url:m({area:a,materia:t,user_query:e}),...w(e,void 0,a,t)}),f=e=>e.split("").map((e=>e.charCodeAt(0).toString(16))).join(""),m=e=>`/ricerca?${new URLSearchParams(e).toString()}`,w=(e,a,t,r)=>({user_query:e,...a?{query:a}:{},...t?{area:t}:{},...r?{subject:r}:{}}),v=(e,a)=>`<mark>${e}</mark> in <strong>${a?`${l[a]??a}`:"tutto il sito"}</strong>`,y=(e,a,t=!1)=>`Cerca la ${t?"materia":"parola"} ${e} ${a?`nel catalogo ${l[a]??a}`:"in tutto il sito"}`,S=e=>e.toLowerCase().replace(/\s+/g," "),x=e=>{const a=b.indexOf(e);return a>=0?a:100},z=a(class extends t{constructor(e){super(),!1!==e&&this.__registerHost(),this.__attachShadow(),this.search=r(this,"search"),this.resetSearch=r(this,"resetSearch")}formElement;subjectsByArea={};timer;get host(){return this}showSearchbar=!1;_searchQuery=void 0;suggestions=[];activeSuggestion="";showSuggestions=!1;searchQuery=void 0;searchEnv=d.PROD;searchArea;onSearchQueryChange(){this._searchQuery=this.searchQuery,this.searchQuery&&this.openSearchbar(),this.resetSuggestions()}onSearchAreaChange(){this.resetSuggestions()}onShowSearchbarChange(){this.showSearchbar||(this.showSuggestions=!1)}onShowSuggestionsChange(){this.activeSuggestion=""}search;resetSearch;async connectedCallback(){this.subjectsByArea=await async function(e){try{const a=await fetch(`${u[e]}/categories.json`);if(!a.ok)throw new Error(`HTTP ${a.status}`);return await a.json()}catch(e){return console.error("Error fetching subjects:",e),{}}}(this.searchEnv),this.showSearchbar=!!this.searchQuery,this._searchQuery=this.searchQuery}handleOutsideClick(e){this.showSearchbar&&this.host&&!n(this.host,e)&&(this.showSearchbar=!1)}handleEsc(e){c(e)&&(this.showSuggestions?this.showSuggestions=!1:this.showSearchbar=!1)}handleTab(e){(e=>"Tab"===e.key)(e)&&(this.showSuggestions=!1,n(this.host,e)||(this.showSearchbar=!1))}openSearchbar(){this.showSearchbar=!0,setTimeout((()=>{this.host.shadowRoot.querySelector("#searchbar-input").focus({preventScroll:!0})}),500)}resetSearchQuery(){this.searchQuery=void 0,this.resetSearch.emit()}resetSuggestions(){this.suggestions=[],this.showSuggestions=!1}handleInputChange(e){this._searchQuery=e.target.value,this._searchQuery||(this.searchQuery=void 0),this.updateSuggestions()}updateSuggestions(){clearTimeout(this.timer);const e=(this._searchQuery||"").trim();e.length<3?this.resetSuggestions():this.timer=setTimeout((()=>{this.resetSuggestions(),this.suggestions=function(e,a,t){const r=function(e,a){const t=S(e);return Object.entries(a).filter((([,e])=>e.some((e=>e.toLowerCase()===t)))).map((([e])=>e))}(e,a),i=r.length>0,s=i?e.toUpperCase():void 0,n=[];return t&&n.push(g(e,t)),n.push(g(e)),i&&(t?[...r.filter((e=>e===t)),...r.filter((e=>e!==t)).sort(((e,a)=>x(e)-x(a)))].forEach((a=>n.push(p(e,a,s)))):r.sort(((e,a)=>x(e)-x(a))).forEach((a=>n.push(p(e,a,s))))),n}(e,this.subjectsByArea,this.searchArea?.toUpperCase()),this.showSuggestions=!0}),300)}onSearchSubmit(e){if(e.preventDefault(),this._searchQuery){if(this.activeSuggestion){const e=this.suggestions.find((e=>e.id===this.activeSuggestion));if(e)return this.submitSuggestionSearch(e),void(this.showSuggestions=!1)}this.showSearchbar=!1,this.search.emit({query:this._searchQuery,area:this.searchArea}).defaultPrevented||this.formElement.submit()}}submitSuggestionSearch(e){this.search.emit({user_query:e.user_query,query:e.query,area:e.area,subject:e.subject}).defaultPrevented||(window.location.href=e.url)}handleSuggestionsNav(e){if(!h(e)&&!(e=>"ArrowUp"===e.key)(e))return;if(!this.suggestions.length)return;const a=this.suggestions.map((e=>e.id));if(!a.length)return;e.preventDefault(),e.stopPropagation(),this.showSuggestions||(this.showSuggestions=!0);let t=null;const r=a[0],i=a[a.length-1],s=a.indexOf(this.activeSuggestion);t=s<0?h(e)?r:i:h(e)?a[s+1]||i:a[s-1]||r,this.activeSuggestion=t}renderSuggestions(){const e=(e,a)=>i("span",{key:a,class:"suggestion-head","aria-hidden":"true"},e);return i("div",{class:{"suggestions-wrapper":!0,hidden:!this.showSuggestions||!this.suggestions.length},onPointerOver:e=>e.preventDefault()},i("div",{id:"search-suggestions",class:"suggestions",role:"listbox","aria-label":"Seleziona tra i suggerimenti"},this.suggestions.map(((a,t)=>{const r=[];return 0===t?r.push(e("Cerca la parola","word-head")):a.subject&&!this.suggestions[t-1].subject&&(r.push(i("z-divider",{"aria-hidden":"true"})),r.push(e("Cerca la materia","subj-head"))),r.push(i("span",{key:t,id:a.id,class:"suggestion",role:"option","aria-label":a.aria_label,"aria-selected":this.activeSuggestion===a.id?"true":void 0,onClick:()=>this.submitSuggestionSearch(a)},i("z-icon",{name:"left-magnifying-glass"}),i("span",{"aria-hidden":"true",innerHTML:a.label}))),r}))))}render(){return i(s,{key:"c87ecbcbff0205ddb35fb96bbfbcca6bb7ac8802"},i("form",{key:"77f2951f88ae0361897161688f3a9875d555b20c",class:{searchbar:!0,"searchbar-open":this.showSearchbar},ref:e=>this.formElement=e,role:"search","aria-label":"Cerca nel sito",method:"get",action:"/ricerca",onSubmit:e=>this.onSearchSubmit(e),onReset:()=>this.resetSearchQuery()},!!this.searchArea&&i("input",{key:"3cf0dceef1acc58c3c0e637f974db6c7587be081",type:"hidden",name:"area",value:this.searchArea}),i("div",{key:"d797f9832f29b723010ca486298f0c4a4aabe3ee",class:"input-wrapper",role:"none"},this.searchQuery&&i("button",{key:"2d5971957d84e83120fc96f49e359635e3792104",type:"reset","aria-label":"Svuota campo di ricerca",disabled:!this.showSearchbar,"aria-hidden":this.showSearchbar?void 0:"true",tabIndex:this.showSearchbar?0:-1},i("z-icon",{key:"7027abe8c6a2211433048041a4ef2a5e273ca226",name:"multiply-circled"})),i("input",{key:"2184d3fa615d94bf3615606a4624abdbb81cb2ae",id:"searchbar-input",name:"q",type:"search",disabled:!this.showSearchbar,placeholder:"Cerca per parola chiave o ISBN",value:this.searchQuery,required:!0,autocomplete:"off",role:"combobox","aria-autocomplete":"list","aria-expanded":this.showSuggestions?"true":"false","aria-controls":"search-suggestions","aria-activedescendant":this.activeSuggestion,"aria-label":"Cerca per parola chiave o ISBN","aria-hidden":this.showSearchbar?void 0:"true",tabIndex:this.showSearchbar?0:-1,onInput:e=>this.handleInputChange(e),onKeyDown:e=>{c(e)&&e.preventDefault(),this.handleSuggestionsNav(e)}})),i("button",{key:"06a7ad6e3e4c74f2dd3bd56fb6f2da006c8d59c0",class:"searchbar-button","aria-label":this.showSearchbar?"Esegui ricerca":"Apri il campo di ricerca","aria-controls":"searchbar-input",type:this.showSearchbar?"submit":"button",onClick:()=>this.openSearchbar()},this.showSearchbar?null:i("span",{class:"searchbar-button-label"},"Cerca"),i("z-icon",{key:"72e66f0280f0b835e760c1631076b71fa5dc03fa",name:"search"}))),this.renderSuggestions())}static get watchers(){return{searchQuery:[{onSearchQueryChange:0}],searchArea:[{onSearchAreaChange:0}],showSearchbar:[{onShowSearchbarChange:0}],showSuggestions:[{onShowSuggestionsChange:0}]}}static get style(){return":host,*,::before,::after{box-sizing:border-box}*:focus:focus-visible{box-shadow:var(--shadow-focus-primary);outline:none}button{all:unset;cursor:pointer}.searchbar{--searchbar-button-x-padding:14px;--searchbar-button-icon-width:1.75rem;--closed-searchbar-width:calc((var(--searchbar-button-x-padding) * 2) + var(--searchbar-button-icon-width) + 1px);position:absolute;z-index:5;top:0;right:0;display:flex;width:var(--closed-searchbar-width);height:3rem;justify-content:flex-end;transition:width 0.4s ease-in-out}.searchbar.searchbar-open{width:100%}.searchbar .input-wrapper{display:flex;overflow:hidden;width:100%;align-items:center;padding:8px;padding-left:var(--grid-margin);background-color:#fff;gap:8px;transition-duration:0.4s;transition-property:padding-right, padding-left, width;transition-timing-function:ease-in-out}.searchbar:not(.searchbar-open) .input-wrapper{overflow:hidden;width:0;padding:0}.searchbar button[type='reset']{--z-icon-width:1rem;--z-icon-height:1rem;display:flex;align-items:center;cursor:pointer}.searchbar input{z-index:1;width:100%;height:100%;padding:0;border:none;background-color:#fff;font-family:var(--font-family-sans);font-size:1rem}.searchbar.searchbar-open input:first-child{padding-left:4px;margin-left:-4px;}.searchbar input[type='search']::-webkit-search-cancel-button,.searchbar input[type='search']::-webkit-search-decoration{appearance:none}.searchbar input::placeholder{color:var(--gray500)}.searchbar .searchbar-button{display:flex;align-items:center;justify-content:center;padding:10px var(--searchbar-button-x-padding);border-left:1px solid #000;background:var(--zanit-accent-color);font-family:inherit;font-size:inherit;gap:64px;line-height:1}.searchbar .searchbar-button:focus-visible{z-index:1}.searchbar-button z-icon{--z-icon-width:var(--searchbar-button-icon-width);--z-icon-height:var(--searchbar-button-icon-width)}.suggestions-wrapper{position:absolute;z-index:4;top:3rem;left:50%;width:100vw;border-top:1px solid var(--gray200);margin-left:-50vw;background:#fff;box-shadow:var(--shadow-1)}.suggestions-wrapper.hidden{display:none}.suggestions{display:flex;width:100%;flex-direction:column;align-items:stretch;padding:var(--space-unit);margin:0 auto}.suggestion-head{padding:calc(var(--space-unit) * 0.75) var(--space-unit);color:var(--gray700);font-size:0.875rem;font-weight:var(--font-md);line-height:1.125rem}.suggestion{display:flex;padding:calc(var(--space-unit) * 0.75) var(--space-unit);color:var(--gray900);cursor:pointer;font-size:1rem;gap:var(--space-unit);line-height:1.5rem}.suggestion:hover,.suggestion[aria-selected='true']{background:var(--gray100)}.suggestion strong{font-weight:var(--font-bd)}.suggestion mark{background-color:var(--red50)}.suggestion z-icon{--z-icon-height:1.125rem;margin-top:0.125rem}.suggestions z-divider{margin:var(--space-unit) 0}@media (width < 1152px){.searchbar .searchbar-button>.searchbar-button-label{display:none}}@media (width >= 768px){.searchbar{--searchbar-button-x-padding:16px;--searchbar-button-icon-width:2rem}.searchbar .input-wrapper{gap:14px}.searchbar button[type='reset']{--z-icon-width:1.5rem;--z-icon-height:1.5rem}.searchbar input,.searchbar .searchbar-button{font-size:1.5rem}.searchbar .searchbar-button{padding:8px var(--searchbar-button-x-padding)}.suggestions{padding:var(--space-unit) calc(var(--space-unit) * 2)}}@media (width >= 1152px){.searchbar{--closed-searchbar-width:190px}}@media (width >= 1366px){.searchbar .searchbar-button{border-right:1px solid #000}.suggestions{max-width:1366px;padding:var(--space-unit) calc(var(--space-unit) * 3)}}"}},[513,"zanit-search-form",{searchQuery:[1025,"search-query"],searchEnv:[1,"search-env"],searchArea:[1,"search-area"],showSearchbar:[32],_searchQuery:[32],suggestions:[32],activeSuggestion:[32],showSuggestions:[32]},[[5,"mousedown","handleOutsideClick"],[1,"keydown","handleEsc"],[5,"keyup","handleTab"]],{searchQuery:[{onSearchQueryChange:0}],searchArea:[{onSearchAreaChange:0}],showSearchbar:[{onShowSearchbarChange:0}],showSuggestions:[{onShowSuggestionsChange:0}]}]);function k(){"undefined"!=typeof customElements&&["zanit-search-form"].forEach((a=>{"zanit-search-form"===a&&(customElements.get(e(a))||customElements.define(e(a),z))}))}k();export{d as S,z as Z,n as c,k as d,o as m}
|
|
@@ -1,88 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
const backToTopCss = ".sc-zanit-back-to-top-h{opacity:1;transition:all 0.2s linear;visibility:visible}.hidden.sc-zanit-back-to-top-h{opacity:0;visibility:hidden}.sc-zanit-back-to-top-h .z-fab.sc-zanit-back-to-top{--color-primary01:var(--gray950);outline:1px solid var(--color-white)}";
|
|
4
|
-
|
|
5
|
-
const ZanitBackTop = /*@__PURE__*/ proxyCustomElement(class ZanitBackTop extends H {
|
|
6
|
-
constructor() {
|
|
7
|
-
super();
|
|
8
|
-
this.__registerHost();
|
|
9
|
-
}
|
|
10
|
-
resizeObserver;
|
|
11
|
-
mutationObserver;
|
|
12
|
-
get host() { return this; }
|
|
13
|
-
/** Indicates whether the back-to-top button is visible and usable. */
|
|
14
|
-
showFab = false;
|
|
15
|
-
/** Indicates the current height of the page. */
|
|
16
|
-
currentPageHeight;
|
|
17
|
-
/** Indicates if the viewport is mobile. */
|
|
18
|
-
isMobile = false;
|
|
19
|
-
/** Min page height from which the back-to-top button must appear. */
|
|
20
|
-
pageMinHeight = 1600;
|
|
21
|
-
/** Min scroll height from which the back-to-top button must appear. */
|
|
22
|
-
scrollMinHeight = 800;
|
|
23
|
-
handleScroll() {
|
|
24
|
-
this.updateFabVisibility();
|
|
25
|
-
}
|
|
26
|
-
handleResize = () => {
|
|
27
|
-
const newHeight = document.body.scrollHeight;
|
|
28
|
-
if (newHeight !== this.currentPageHeight) {
|
|
29
|
-
this.currentPageHeight = newHeight;
|
|
30
|
-
this.updateFabVisibility();
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
connectedCallback() {
|
|
34
|
-
this.currentPageHeight = document.body.scrollHeight;
|
|
35
|
-
this.resizeObserver = new ResizeObserver(this.handleResize);
|
|
36
|
-
this.resizeObserver.observe(document.body);
|
|
37
|
-
this.mutationObserver = new MutationObserver(this.handleResize);
|
|
38
|
-
this.mutationObserver.observe(document.body, { childList: true, subtree: true });
|
|
39
|
-
this.updateFabVisibility();
|
|
40
|
-
const mobileMediaQuery = window.matchMedia('(width < 768px)');
|
|
41
|
-
this.isMobile = mobileMediaQuery.matches;
|
|
42
|
-
mobileMediaQuery.onchange = (mql) => {
|
|
43
|
-
this.isMobile = mql.matches;
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
disconnectedCallback() {
|
|
47
|
-
this.resizeObserver.disconnect();
|
|
48
|
-
this.mutationObserver.disconnect();
|
|
49
|
-
}
|
|
50
|
-
updateFabVisibility() {
|
|
51
|
-
this.showFab = this.currentPageHeight > this.pageMinHeight && window.scrollY > this.scrollMinHeight;
|
|
52
|
-
}
|
|
53
|
-
scroll() {
|
|
54
|
-
window.scrollTo({ top: 0, behavior: 'smooth' });
|
|
55
|
-
}
|
|
56
|
-
render() {
|
|
57
|
-
return (h(Host, { key: '3abd8ab70075d8042285d8ed6fab0729c4b5ec42', class: { hidden: !this.showFab }, "aria-hidden": this.showFab ? 'false' : 'true' }, h("button", { key: '11b149d5f1d75720d4bdd329e9897da782092ed1', class: { 'z-fab': true, 'z-fab-extended': !this.isMobile }, onClick: () => this.scroll() }, h("z-icon", { key: 'fbdff1419da6d20ab594ffd11c58d7bf25fb7aa6', name: "back-top" }), h("span", { key: '0292f761b5459c372f003ed514abbd3403570c75' }, "Torna su"))));
|
|
58
|
-
}
|
|
59
|
-
static get style() { return backToTopCss; }
|
|
60
|
-
}, [2, "zanit-back-to-top", {
|
|
61
|
-
"pageMinHeight": [2, "page-min-height"],
|
|
62
|
-
"scrollMinHeight": [2, "scroll-min-height"],
|
|
63
|
-
"showFab": [32],
|
|
64
|
-
"currentPageHeight": [32],
|
|
65
|
-
"isMobile": [32]
|
|
66
|
-
}, [[9, "scroll", "handleScroll"]]]);
|
|
67
|
-
function defineCustomElement$1() {
|
|
68
|
-
if (typeof customElements === "undefined") {
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
const components = ["zanit-back-to-top"];
|
|
72
|
-
components.forEach(tagName => { switch (tagName) {
|
|
73
|
-
case "zanit-back-to-top":
|
|
74
|
-
if (!customElements.get(tagName)) {
|
|
75
|
-
customElements.define(tagName, ZanitBackTop);
|
|
76
|
-
}
|
|
77
|
-
break;
|
|
78
|
-
} });
|
|
79
|
-
}
|
|
80
|
-
defineCustomElement$1();
|
|
81
|
-
|
|
82
|
-
const ZanitBackToTop = ZanitBackTop;
|
|
83
|
-
const defineCustomElement = defineCustomElement$1;
|
|
84
|
-
|
|
85
|
-
export { ZanitBackToTop, defineCustomElement };
|
|
86
|
-
//# sourceMappingURL=zanit-back-to-top.js.map
|
|
87
|
-
|
|
88
|
-
//# sourceMappingURL=zanit-back-to-top.js.map
|
|
1
|
+
import{t,p as e,H as i,h as s,a}from"./index.js";const o=e(class extends i{constructor(t){super(),!1!==t&&this.__registerHost()}resizeObserver;mutationObserver;get host(){return this}showFab=!1;currentPageHeight;isMobile=!1;pageMinHeight=1600;scrollMinHeight=800;handleScroll(){this.updateFabVisibility()}handleResize=()=>{const t=document.body.scrollHeight;t!==this.currentPageHeight&&(this.currentPageHeight=t,this.updateFabVisibility())};connectedCallback(){this.currentPageHeight=document.body.scrollHeight,this.resizeObserver=new ResizeObserver(this.handleResize),this.resizeObserver.observe(document.body),this.mutationObserver=new MutationObserver(this.handleResize),this.mutationObserver.observe(document.body,{childList:!0,subtree:!0}),this.updateFabVisibility();const t=window.matchMedia("(width < 768px)");this.isMobile=t.matches,t.onchange=t=>{this.isMobile=t.matches}}disconnectedCallback(){this.resizeObserver.disconnect(),this.mutationObserver.disconnect()}updateFabVisibility(){this.showFab=this.currentPageHeight>this.pageMinHeight&&window.scrollY>this.scrollMinHeight}scroll(){window.scrollTo({top:0,behavior:"smooth"})}render(){return s(a,{key:"8db557141277e71d6d2fdaad2e525df03fb78461",class:{hidden:!this.showFab},"aria-hidden":this.showFab?"false":"true"},s("button",{key:"e9a1cfcc75c39e6a5d657712306e331bbfabbcf9",class:{"z-fab":!0,"z-fab-extended":!this.isMobile},onClick:()=>this.scroll()},s("z-icon",{key:"c83accba15ee2efbbef5f17cdbb92c57f7aee0a0",name:"back-top"}),s("span",{key:"59167788a06ac2b45b4e91c944c0fefd1dc79780"},"Torna su")))}static get style(){return".sc-zanit-back-to-top-h{opacity:1;transition:all 0.2s linear;visibility:visible}.hidden.sc-zanit-back-to-top-h{opacity:0;visibility:hidden}.sc-zanit-back-to-top-h .z-fab.sc-zanit-back-to-top{--color-primary01:var(--gray950);outline:1px solid var(--color-white)}"}},[514,"zanit-back-to-top",{pageMinHeight:[2,"page-min-height"],scrollMinHeight:[2,"scroll-min-height"],showFab:[32],currentPageHeight:[32],isMobile:[32]},[[9,"scroll","handleScroll"]]]);function c(){"undefined"!=typeof customElements&&["zanit-back-to-top"].forEach((e=>{"zanit-back-to-top"===e&&(customElements.get(t(e))||customElements.define(t(e),o))}))}c();const n=o,h=c;export{n as ZanitBackToTop,h as defineCustomElement}
|
|
@@ -1,455 +1 @@
|
|
|
1
|
-
import { p as proxyCustomElement, H, h, F as Fragment } from './index.js';
|
|
2
|
-
import { d as defineCustomElement$2, S as SearchEnv, c as containsTarget, m as moveFocus } from './p-DqMqkNnl.js';
|
|
3
|
-
import { d as defineCustomElement$3, M as Menu } from './p-BlgoYKK3.js';
|
|
4
|
-
|
|
5
|
-
const menubarCss = ":host{position:relative;z-index:2;display:flex;width:100%;background-color:#fff;color:var(--gray900);font-family:var(--font-family-sans)}:host,*,::before,::after{box-sizing:border-box}*:focus:focus-visible{box-shadow:var(--shadow-focus-primary);outline:none}ul{padding:0;margin:0;list-style:none}a{color:var(--gray900);cursor:pointer;text-decoration:none}button{all:unset;cursor:pointer}:host nav{width:100%}.shadow-wrapper{position:relative;z-index:1;display:flex;width:100%}.shadow-wrapper::after{position:absolute;top:0;right:0;width:100%;height:100%;background:transparent;box-shadow:var(--shadow-1);content:'';pointer-events:none}.width-limiter{position:relative;display:flex;width:100%;max-width:var(--zanit-menubar-max-width, 1366px);margin:0 auto}.shadow-wrapper+.shadow-wrapper{z-index:0}.sub-menubar>ul{gap:28px}.width-limiter>ul,.sub-menubar>ul{position:relative;z-index:3;display:flex;width:100%;align-items:center;padding:0 var(--grid-margin);margin-right:auto;margin-left:auto;gap:20px}.shadow-wrapper>.width-limiter,.shadow-wrapper>ul{width:100%;max-width:var(--zanit-menubar-max-width, 1366px)}ul.menubar{height:3rem;padding-right:0}.menubar z-ghost-loading{display:block;width:120px;height:1.25rem}.menubar>li[role='separator']{width:1px;height:1.25rem;background-color:#000}.menubar-item{position:relative;display:flex;align-items:center;padding:14px 0;font-size:1rem;gap:8px;line-height:1.25rem}.menubar .menubar-item{text-transform:uppercase}.menubar-item [data-text]{display:flex;flex-direction:column}.menubar-item.active>[data-text],.menubar-item:hover>[data-text],.menubar-item:focus:focus-visible>[data-text]{font-weight:var(--font-bd)}.menubar-item>[data-text]::after{height:0;content:attr(data-text) / '';font-weight:var(--font-bd);letter-spacing:normal;pointer-events:none;user-select:none;visibility:hidden}.sub-menubar .menubar-item.active::after{position:absolute;z-index:-1;bottom:0;left:-4px;width:calc(100% + 8px);height:4px;background-color:var(--red500);content:''}zanit-search-form{margin-left:auto}";
|
|
6
|
-
|
|
7
|
-
const menuCss = ".menu-wrapper{width:100%;background-color:#fff}.menu{position:relative;display:flex;width:100%;flex-direction:column;gap:32px 0}.menu .group{display:flex;flex-direction:column}.menu .group .group-name{border-bottom:1px solid currentcolor;margin-bottom:4px;color:var(--red500);font-size:0.875rem;font-weight:var(--font-md)}.menu .group .menu-list{display:flex;flex-direction:column;gap:8px}.menu .group .menu-list .menu-item{display:block;border-bottom:2px solid transparent;font-size:0.875rem;font-weight:var(--font-md)}.menu .menu-list .menu-item.active,.menu .menu-list .menu-item:hover{border-bottom-color:var(--red500)}.menu .group.highlight .menu-list .menu-item{font-size:1rem}@media (width >= 768px){.menu-wrapper{position:absolute;top:100%;left:0;display:flex;justify-content:center;box-shadow:var(--shadow-1)}.menu{display:grid;width:100%;max-width:var(--zanit-menubar-max-width, 1366px);padding:16px var(--grid-margin);gap:0 24px;grid-auto-columns:minmax(0, max-content);grid-auto-flow:column;grid-template-rows:minmax(0, max-content) max-content}.menu .group{display:grid;grid-row:1 / -1;grid-template-columns:1fr;grid-template-rows:subgrid}@supports not (grid-template-rows: subgrid){.menu .group{grid-template-rows:repeat(auto-fit, minmax(0, max-content))}}.menu .group .group-name{border:none;margin-bottom:16px}.menu .group .menu-list .menu-item{font-size:1rem}.menu .group.highlight .menu-list .menu-item{font-size:1.5rem}}";
|
|
8
|
-
|
|
9
|
-
const ZanitMenubar$1 = /*@__PURE__*/ proxyCustomElement(class ZanitMenubar extends H {
|
|
10
|
-
constructor() {
|
|
11
|
-
super();
|
|
12
|
-
this.__registerHost();
|
|
13
|
-
this.__attachShadow();
|
|
14
|
-
}
|
|
15
|
-
get host() { return this; }
|
|
16
|
-
/** Menubar items extracted from `data`. */
|
|
17
|
-
items = [];
|
|
18
|
-
/** ID of the currently open menu. */
|
|
19
|
-
openMenu = undefined;
|
|
20
|
-
/** ID of the item to show the subitems navbar for. */
|
|
21
|
-
openNavbar = undefined;
|
|
22
|
-
/** IDs of the current prop */
|
|
23
|
-
currentPath = [];
|
|
24
|
-
isMobile = false;
|
|
25
|
-
loading = false;
|
|
26
|
-
/** The data to build the menu (as an array of `MenubarItem` or a JSON array) or the url to fetch to retrieve it. */
|
|
27
|
-
data;
|
|
28
|
-
/** Path of the current item. */
|
|
29
|
-
current = undefined;
|
|
30
|
-
/** Initial search query. */
|
|
31
|
-
searchQuery = undefined;
|
|
32
|
-
/** Environment for search suggestions */
|
|
33
|
-
searchEnv = SearchEnv.PROD;
|
|
34
|
-
/** Search area (e.g. "SCUOLA", "UNIVERSITÀ", "DIZIONARI"). */
|
|
35
|
-
searchArea;
|
|
36
|
-
timerId;
|
|
37
|
-
/** Setup the list of items. */
|
|
38
|
-
async parseData(data) {
|
|
39
|
-
if (!data) {
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
if (data instanceof URL) {
|
|
43
|
-
this.items = await this.fetchData(data);
|
|
44
|
-
}
|
|
45
|
-
else if (data instanceof Promise) {
|
|
46
|
-
this.loading = true;
|
|
47
|
-
this.items = await data;
|
|
48
|
-
this.loading = false;
|
|
49
|
-
}
|
|
50
|
-
else if (typeof data === 'string') {
|
|
51
|
-
try {
|
|
52
|
-
this.items = JSON.parse(data);
|
|
53
|
-
if (!Array.isArray(this.items) || !this.items?.every((item) => item)) {
|
|
54
|
-
throw new Error('Expected an array of MenubarItem objects.');
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
catch {
|
|
58
|
-
let url;
|
|
59
|
-
try {
|
|
60
|
-
url = new URL(data);
|
|
61
|
-
}
|
|
62
|
-
catch {
|
|
63
|
-
throw new Error('Invalid string provided for `data` property: not a valid url or JSON.');
|
|
64
|
-
}
|
|
65
|
-
this.items = await this.fetchData(url);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
else if (Array.isArray(data) && data.every((item) => item)) {
|
|
69
|
-
this.items = data;
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
throw new Error('Invalid `data` property value. Expected an url, a JSON or an array/promise of MenubarItem objects.');
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
onItemsChange() {
|
|
76
|
-
this.initTabindex();
|
|
77
|
-
}
|
|
78
|
-
onCurrentChange() {
|
|
79
|
-
this.currentPath = this.current?.split('/').filter(Boolean) || [];
|
|
80
|
-
}
|
|
81
|
-
async connectedCallback() {
|
|
82
|
-
const mobileMediaQuery = window.matchMedia('(width < 768px)');
|
|
83
|
-
this.isMobile = mobileMediaQuery.matches;
|
|
84
|
-
mobileMediaQuery.onchange = (mql) => {
|
|
85
|
-
this.isMobile = mql.matches;
|
|
86
|
-
this.initTabindex();
|
|
87
|
-
this.openMenu = undefined;
|
|
88
|
-
};
|
|
89
|
-
await this.parseData(this.data);
|
|
90
|
-
this.onCurrentChange();
|
|
91
|
-
this.initTabindex();
|
|
92
|
-
}
|
|
93
|
-
/** Close any open menu when clicking outside. */
|
|
94
|
-
handleOutsideClick(event) {
|
|
95
|
-
if (!this.openMenu || containsTarget(this.host, event)) {
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
this.openMenu = undefined;
|
|
99
|
-
}
|
|
100
|
-
/** Close any open menu when pressing Escape or Tab.
|
|
101
|
-
* Uses document-level listener to ensure Escape works from any focus location within the menu.
|
|
102
|
-
*/
|
|
103
|
-
handleKeydown(event) {
|
|
104
|
-
switch (event.key) {
|
|
105
|
-
case 'Escape': {
|
|
106
|
-
if (this.openMenu) {
|
|
107
|
-
event.preventDefault();
|
|
108
|
-
// Return focus to the menu trigger after closing
|
|
109
|
-
const menuTriggerId = this.openMenu;
|
|
110
|
-
this.openMenu = undefined;
|
|
111
|
-
// Use setTimeout(0) to defer focus until after Stencil's render cycle completes
|
|
112
|
-
setTimeout(() => {
|
|
113
|
-
const menuTrigger = this.host.shadowRoot.getElementById(menuTriggerId);
|
|
114
|
-
if (menuTrigger) {
|
|
115
|
-
menuTrigger.focus();
|
|
116
|
-
}
|
|
117
|
-
}, 0);
|
|
118
|
-
}
|
|
119
|
-
break;
|
|
120
|
-
}
|
|
121
|
-
case 'Tab':
|
|
122
|
-
this.openMenu = undefined;
|
|
123
|
-
break;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
handleMouseover() {
|
|
127
|
-
clearTimeout(this.timerId);
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Automatically close any open menu on mouseout after with a little delay.
|
|
131
|
-
* The delay is useful to avoid immediate closing when the pointer briefly leaves the component.
|
|
132
|
-
*/
|
|
133
|
-
handleMouseout(event) {
|
|
134
|
-
this.timerId = window.setTimeout(() => {
|
|
135
|
-
if (!this.openMenu || containsTarget(this.host, event)) {
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
this.openMenu = undefined;
|
|
139
|
-
}, 500);
|
|
140
|
-
}
|
|
141
|
-
/** Close the menu when it loses focus. */
|
|
142
|
-
handleFocusout(event) {
|
|
143
|
-
const relatedTarget = event.relatedTarget;
|
|
144
|
-
if (!this.openMenu || this.host.shadowRoot.querySelector('.menu')?.contains(relatedTarget)) {
|
|
145
|
-
return;
|
|
146
|
-
}
|
|
147
|
-
this.openMenu = undefined;
|
|
148
|
-
}
|
|
149
|
-
/** Fetch data from passed URL. */
|
|
150
|
-
async fetchData(url) {
|
|
151
|
-
try {
|
|
152
|
-
this.loading = true;
|
|
153
|
-
const data = await (await fetch(url)).json();
|
|
154
|
-
this.loading = false;
|
|
155
|
-
if (!Array.isArray(data) || !data.every((item) => item)) {
|
|
156
|
-
throw new Error('Invalid data structure. Expected an array of MenuItem objects.');
|
|
157
|
-
}
|
|
158
|
-
return data;
|
|
159
|
-
}
|
|
160
|
-
catch (error) {
|
|
161
|
-
this.loading = false;
|
|
162
|
-
console.error('Error fetching menubar data:', error);
|
|
163
|
-
throw new Error('Failed to fetch menubar data from the provided URL.', { cause: error });
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
/** Initialize tabindex on menuitems of menubars, setting -1 to all but the first one. */
|
|
167
|
-
initTabindex() {
|
|
168
|
-
setTimeout(() => {
|
|
169
|
-
this.host.shadowRoot.querySelectorAll('[role="menubar"]')?.forEach((menubar) => {
|
|
170
|
-
menubar
|
|
171
|
-
.querySelectorAll('[role="menuitem"]')
|
|
172
|
-
?.forEach((item, index) => item.setAttribute('tabindex', index === 0 ? '0' : '-1'));
|
|
173
|
-
});
|
|
174
|
-
}, 100);
|
|
175
|
-
}
|
|
176
|
-
/** Indicates whether the element has to be highlighted by checking whether it is set as current or one of its descendants is. */
|
|
177
|
-
isActive(item) {
|
|
178
|
-
if (this.currentPath.length === 0) {
|
|
179
|
-
return false;
|
|
180
|
-
}
|
|
181
|
-
if (this.currentPath.includes(item.id)) {
|
|
182
|
-
return true;
|
|
183
|
-
}
|
|
184
|
-
if (item.menuItems?.length) {
|
|
185
|
-
return item.menuItems.some((menuItem) => menuItem.id === this.current);
|
|
186
|
-
}
|
|
187
|
-
if (item.navbarItems?.length) {
|
|
188
|
-
const isActive = item.navbarItems.some((navbarItem) => this.isActive(navbarItem));
|
|
189
|
-
if (isActive) {
|
|
190
|
-
return true;
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
return false;
|
|
194
|
-
}
|
|
195
|
-
/** Opens the menu associated with the menubar `item`, if any. */
|
|
196
|
-
showMenu(item) {
|
|
197
|
-
this.openMenu = undefined; // close any open menu first
|
|
198
|
-
if (!item.menuItems?.length) {
|
|
199
|
-
return;
|
|
200
|
-
}
|
|
201
|
-
this.openMenu = item.id;
|
|
202
|
-
}
|
|
203
|
-
/** Get all elements with `menuitem` role inside parent's `menubar`. * */
|
|
204
|
-
getParentMenubarElements(itemEl) {
|
|
205
|
-
return Array.from(itemEl?.closest('[role="menubar"]')?.querySelectorAll(':scope > li a[role="menuitem"]') ?? []);
|
|
206
|
-
}
|
|
207
|
-
/** Move the focus to the previous menubar item, or the last one. Then open its menu if any other menu was open. */
|
|
208
|
-
focusPreviousItem(itemEl) {
|
|
209
|
-
this.openMenu = undefined; // close any open menu first
|
|
210
|
-
const menubarElements = this.getParentMenubarElements(itemEl);
|
|
211
|
-
const currentIndex = menubarElements.indexOf(itemEl);
|
|
212
|
-
const prevItem = menubarElements[(currentIndex - 1 + menubarElements.length) % menubarElements.length]; // get previous item or last one
|
|
213
|
-
moveFocus(itemEl, prevItem);
|
|
214
|
-
// open the item's menu if any other menu was open
|
|
215
|
-
if (prevItem.ariaHasPopup === 'true' && this.openMenu) {
|
|
216
|
-
this.openMenu = prevItem.id;
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
/** Move the focus to the next menubar item, or the first one. Then open its menu if any other menu was open. */
|
|
220
|
-
focusNextItem(itemEl) {
|
|
221
|
-
this.openMenu = undefined; // close any open menu first
|
|
222
|
-
const menubarElements = this.getParentMenubarElements(itemEl);
|
|
223
|
-
const currentIndex = menubarElements.indexOf(itemEl);
|
|
224
|
-
const nextItem = menubarElements[(currentIndex + 1) % menubarElements.length]; // get next item or first one
|
|
225
|
-
moveFocus(itemEl, nextItem);
|
|
226
|
-
// open the item's menu if any other menu was open
|
|
227
|
-
if (nextItem.ariaHasPopup === 'true' && this.openMenu) {
|
|
228
|
-
this.openMenu = nextItem.id;
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
/** Handles keyboard navigation on menubar items. */
|
|
232
|
-
handleItemKeydown(event, item) {
|
|
233
|
-
const target = event.target;
|
|
234
|
-
switch (event.key) {
|
|
235
|
-
case 'Home': {
|
|
236
|
-
event.preventDefault();
|
|
237
|
-
event.stopPropagation();
|
|
238
|
-
const firstItem = this.getParentMenubarElements(target)[0];
|
|
239
|
-
moveFocus(target, firstItem);
|
|
240
|
-
break;
|
|
241
|
-
}
|
|
242
|
-
case 'End': {
|
|
243
|
-
event.preventDefault();
|
|
244
|
-
event.stopPropagation();
|
|
245
|
-
const lastItem = this.getParentMenubarElements(target).pop();
|
|
246
|
-
moveFocus(target, lastItem);
|
|
247
|
-
break;
|
|
248
|
-
}
|
|
249
|
-
case 'ArrowUp': {
|
|
250
|
-
if (!item.menuItems?.length) {
|
|
251
|
-
break;
|
|
252
|
-
}
|
|
253
|
-
event.preventDefault();
|
|
254
|
-
event.stopPropagation();
|
|
255
|
-
this.openMenu = item.id;
|
|
256
|
-
// focus last item of the menu
|
|
257
|
-
setTimeout(() => {
|
|
258
|
-
const menuItems = Array.from(this.host.shadowRoot.querySelectorAll(`[aria-labelledby=${item.id}] [role="menuitem"]`));
|
|
259
|
-
moveFocus(target, menuItems[menuItems.length - 1]);
|
|
260
|
-
}, 100);
|
|
261
|
-
break;
|
|
262
|
-
}
|
|
263
|
-
case 'ArrowRight': {
|
|
264
|
-
event.preventDefault();
|
|
265
|
-
event.stopPropagation();
|
|
266
|
-
this.focusNextItem(target);
|
|
267
|
-
break;
|
|
268
|
-
}
|
|
269
|
-
case 'ArrowDown': {
|
|
270
|
-
if (!item.menuItems?.length) {
|
|
271
|
-
break;
|
|
272
|
-
}
|
|
273
|
-
this.openItemMenu(item);
|
|
274
|
-
break;
|
|
275
|
-
}
|
|
276
|
-
case 'ArrowLeft': {
|
|
277
|
-
event.preventDefault();
|
|
278
|
-
event.stopPropagation();
|
|
279
|
-
this.focusPreviousItem(target);
|
|
280
|
-
break;
|
|
281
|
-
}
|
|
282
|
-
case ' ': {
|
|
283
|
-
event.preventDefault();
|
|
284
|
-
event.stopPropagation();
|
|
285
|
-
if (this.openMenu === item.id) {
|
|
286
|
-
this.openMenu = undefined;
|
|
287
|
-
break;
|
|
288
|
-
}
|
|
289
|
-
else if (item.menuItems?.length) {
|
|
290
|
-
this.openItemMenu(item);
|
|
291
|
-
break;
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
/** Get the previous element with `role=group`. */
|
|
297
|
-
getPreviousGroup(groupContainer) {
|
|
298
|
-
const groups = Array.from(groupContainer?.closest('[role="menu"]')?.querySelectorAll('[role="group"]') ?? []);
|
|
299
|
-
const currentIndex = groups.indexOf(groupContainer);
|
|
300
|
-
return groups[currentIndex - 1];
|
|
301
|
-
}
|
|
302
|
-
/** Get the next element with `role=group`. */
|
|
303
|
-
getNextGroup(groupContainer) {
|
|
304
|
-
const groups = Array.from(groupContainer?.closest('[role="menu"]')?.querySelectorAll('[role="group"]') ?? []);
|
|
305
|
-
const currentIndex = groups.indexOf(groupContainer);
|
|
306
|
-
return groups[currentIndex + 1];
|
|
307
|
-
}
|
|
308
|
-
openItemMenu(item) {
|
|
309
|
-
this.openMenu = item.id;
|
|
310
|
-
setTimeout(() => {
|
|
311
|
-
// focus first item of the menu
|
|
312
|
-
const firstMenuItem = this.host.shadowRoot.querySelector(`[aria-labelledby=${item.id}] [role="menuitem"]`);
|
|
313
|
-
firstMenuItem.tabIndex = 0;
|
|
314
|
-
firstMenuItem.focus({ preventScroll: true });
|
|
315
|
-
}, 100);
|
|
316
|
-
}
|
|
317
|
-
/** Handles keyboard navigation events from `Menu` component. */
|
|
318
|
-
handleMenuKeydown(event) {
|
|
319
|
-
const itemElement = event.target;
|
|
320
|
-
const items = Array.from(itemElement.closest('[role="menu"]')?.querySelectorAll('[role="menuitem"]') ?? []);
|
|
321
|
-
const currentIndex = items.indexOf(itemElement);
|
|
322
|
-
switch (event.key) {
|
|
323
|
-
case 'ArrowUp': {
|
|
324
|
-
event.preventDefault();
|
|
325
|
-
event.stopPropagation();
|
|
326
|
-
const prevItem = items[currentIndex - 1] || items[items.length - 1];
|
|
327
|
-
moveFocus(itemElement, prevItem);
|
|
328
|
-
break;
|
|
329
|
-
}
|
|
330
|
-
// Move the focus to the first item of the next group if any, otherwise move it to the next menubar item
|
|
331
|
-
case 'ArrowRight': {
|
|
332
|
-
event.preventDefault();
|
|
333
|
-
event.stopPropagation();
|
|
334
|
-
const currentGroup = itemElement.closest('[role=group]');
|
|
335
|
-
const nextGroup = this.getNextGroup(currentGroup);
|
|
336
|
-
if (!nextGroup) {
|
|
337
|
-
itemElement.tabIndex = -1;
|
|
338
|
-
const menuTriggerId = itemElement.closest('[role="menu"][aria-labelledby]').getAttribute('aria-labelledby');
|
|
339
|
-
const focusedItem = this.host.shadowRoot.getElementById(menuTriggerId);
|
|
340
|
-
this.focusNextItem(focusedItem);
|
|
341
|
-
break;
|
|
342
|
-
}
|
|
343
|
-
const nextGroupItems = (nextGroup.querySelectorAll('[role="menuitem"]') ?? []);
|
|
344
|
-
moveFocus(itemElement, nextGroupItems[0]);
|
|
345
|
-
break;
|
|
346
|
-
}
|
|
347
|
-
case 'ArrowDown': {
|
|
348
|
-
event.preventDefault();
|
|
349
|
-
event.stopPropagation();
|
|
350
|
-
const nextItem = items[currentIndex + 1] || items[0];
|
|
351
|
-
moveFocus(itemElement, nextItem);
|
|
352
|
-
break;
|
|
353
|
-
}
|
|
354
|
-
// Move the focus to the first item of the previous group if any, otherwise move it to the previous menubar item
|
|
355
|
-
case 'ArrowLeft': {
|
|
356
|
-
event.preventDefault();
|
|
357
|
-
event.stopPropagation();
|
|
358
|
-
const currentGroup = itemElement.closest('[role=group]');
|
|
359
|
-
const prevGroup = this.getPreviousGroup(currentGroup);
|
|
360
|
-
if (!prevGroup) {
|
|
361
|
-
itemElement.tabIndex = -1;
|
|
362
|
-
const menuTriggerId = itemElement.closest('[role="menu"][aria-labelledby]').getAttribute('aria-labelledby');
|
|
363
|
-
const focusedItem = this.host.shadowRoot.getElementById(menuTriggerId);
|
|
364
|
-
this.focusPreviousItem(focusedItem);
|
|
365
|
-
break;
|
|
366
|
-
}
|
|
367
|
-
const prevGroupItems = (prevGroup.querySelectorAll('[role="menuitem"]') ?? []);
|
|
368
|
-
moveFocus(itemElement, prevGroupItems[0]);
|
|
369
|
-
break;
|
|
370
|
-
}
|
|
371
|
-
case 'Home':
|
|
372
|
-
// Move to the first menu item
|
|
373
|
-
event.preventDefault();
|
|
374
|
-
event.stopPropagation();
|
|
375
|
-
moveFocus(itemElement, items[0]);
|
|
376
|
-
break;
|
|
377
|
-
case 'End':
|
|
378
|
-
// Move to the last menu item
|
|
379
|
-
event.preventDefault();
|
|
380
|
-
event.stopPropagation();
|
|
381
|
-
moveFocus(itemElement, items[items.length - 1]);
|
|
382
|
-
break;
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
render() {
|
|
386
|
-
if (this.isMobile) {
|
|
387
|
-
return (h("zanit-mobile-menubar", { items: this.items, currentPath: this.currentPath, searchQuery: this.searchQuery, loading: this.loading, searchArea: this.searchArea, searchEnv: this.searchEnv }));
|
|
388
|
-
}
|
|
389
|
-
return (h("nav", { "aria-label": "Zanichelli.it" }, h("div", { class: "shadow-wrapper" }, h("div", { class: "width-limiter" }, h("ul", { class: "menubar", role: "menubar", "aria-label": "Zanichelli.it" }, this.loading &&
|
|
390
|
-
[...new Array(4)].map((_, index) => (h(Fragment, null, h("li", { role: "none" }, h("div", { class: "menubar-item" }, h("z-ghost-loading", null))), index < 3 && h("li", { role: "separator" })))), this.items?.map((item, index) => (h(Fragment, null, h("li", { role: "none" }, h("a", { class: {
|
|
391
|
-
'menubar-item': true,
|
|
392
|
-
'active': this.isActive(item),
|
|
393
|
-
}, href: item.href, id: item.id, role: "menuitem", tabIndex: -1, "aria-expanded": item.menuItems?.length ? (this.openMenu === item.id ? 'true' : 'false') : undefined, "aria-haspopup": item.menuItems?.length ? 'true' : 'false', "aria-current": this.current.includes(item.id) ? 'page' : 'false', onPointerOver: () => this.showMenu(item), onKeyDown: (event) => this.handleItemKeydown(event, item), target: item.target }, h("span", { "data-text": item.label }, item.label), item.menuItems?.length > 0 && (h("z-icon", { name: this.openMenu === item.id ? 'chevron-up' : 'chevron-down', width: "0.875rem", height: "0.875rem" })))), index < this.items?.length - 1 && h("li", { role: "separator" }))))), h("zanit-search-form", { searchQuery: this.searchQuery, searchArea: this.searchArea, searchEnv: this.searchEnv, onResetSearch: () => (this.searchQuery = undefined) })), this.items.map((item) => this.openMenu === item.id && (h(Menu, { controlledBy: item.id, items: item.menuItems, currentPath: this.currentPath, onItemKeyDown: (event) => this.handleMenuKeydown(event) })))), this.items
|
|
394
|
-
?.filter((item) => this.isActive(item))
|
|
395
|
-
.map((item) => item.navbarItems?.length && (h("nav", { class: { 'sub-menubar': true, 'shadow-wrapper': true }, "aria-label": `Sezioni: ${item.label}` }, h("ul", { role: "menubar" }, item.navbarItems.map((subitem) => (h(Fragment, null, h("li", { role: "none" }, h("a", { class: {
|
|
396
|
-
'menubar-item': true,
|
|
397
|
-
'active': this.isActive(subitem),
|
|
398
|
-
}, href: subitem.href, id: subitem.id, role: "menuitem", tabIndex: -1, "aria-haspopup": subitem.menuItems?.length ? 'true' : 'false', "aria-expanded": subitem.menuItems?.length ? (this.openMenu === subitem.id ? 'true' : 'false') : undefined, "aria-current": this.current.includes(subitem.id) ? 'page' : 'false', onPointerOver: () => this.showMenu(subitem), onKeyDown: (event) => this.handleItemKeydown(event, subitem), target: item.target }, h("span", null, subitem.label), subitem.menuItems?.length > 0 && (h("z-icon", { name: this.openMenu === subitem.id ? 'chevron-up' : 'chevron-down', width: "0.75rem", height: "0.75rem" })))))))), item.navbarItems.map((subitem) => this.openMenu === subitem.id && (h(Menu, { controlledBy: subitem.id, items: subitem.menuItems, currentPath: this.currentPath, onItemKeyDown: (event) => this.handleMenuKeydown(event) }))))))));
|
|
399
|
-
}
|
|
400
|
-
static get delegatesFocus() { return true; }
|
|
401
|
-
static get watchers() { return {
|
|
402
|
-
"data": ["parseData"],
|
|
403
|
-
"items": ["onItemsChange"],
|
|
404
|
-
"current": ["onCurrentChange"]
|
|
405
|
-
}; }
|
|
406
|
-
static get style() { return menubarCss + menuCss; }
|
|
407
|
-
}, [17, "zanit-menubar", {
|
|
408
|
-
"data": [1],
|
|
409
|
-
"current": [1],
|
|
410
|
-
"searchQuery": [1025, "search-query"],
|
|
411
|
-
"searchEnv": [1, "search-env"],
|
|
412
|
-
"searchArea": [1, "search-area"],
|
|
413
|
-
"items": [32],
|
|
414
|
-
"openMenu": [32],
|
|
415
|
-
"openNavbar": [32],
|
|
416
|
-
"currentPath": [32],
|
|
417
|
-
"isMobile": [32],
|
|
418
|
-
"loading": [32]
|
|
419
|
-
}, [[5, "click", "handleOutsideClick"], [5, "keydown", "handleKeydown"], [1, "mouseover", "handleMouseover"], [1, "mouseout", "handleMouseout"], [1, "focusout", "handleFocusout"]], {
|
|
420
|
-
"data": ["parseData"],
|
|
421
|
-
"items": ["onItemsChange"],
|
|
422
|
-
"current": ["onCurrentChange"]
|
|
423
|
-
}]);
|
|
424
|
-
function defineCustomElement$1() {
|
|
425
|
-
if (typeof customElements === "undefined") {
|
|
426
|
-
return;
|
|
427
|
-
}
|
|
428
|
-
const components = ["zanit-menubar", "zanit-mobile-menubar", "zanit-search-form"];
|
|
429
|
-
components.forEach(tagName => { switch (tagName) {
|
|
430
|
-
case "zanit-menubar":
|
|
431
|
-
if (!customElements.get(tagName)) {
|
|
432
|
-
customElements.define(tagName, ZanitMenubar$1);
|
|
433
|
-
}
|
|
434
|
-
break;
|
|
435
|
-
case "zanit-mobile-menubar":
|
|
436
|
-
if (!customElements.get(tagName)) {
|
|
437
|
-
defineCustomElement$3();
|
|
438
|
-
}
|
|
439
|
-
break;
|
|
440
|
-
case "zanit-search-form":
|
|
441
|
-
if (!customElements.get(tagName)) {
|
|
442
|
-
defineCustomElement$2();
|
|
443
|
-
}
|
|
444
|
-
break;
|
|
445
|
-
} });
|
|
446
|
-
}
|
|
447
|
-
defineCustomElement$1();
|
|
448
|
-
|
|
449
|
-
const ZanitMenubar = ZanitMenubar$1;
|
|
450
|
-
const defineCustomElement = defineCustomElement$1;
|
|
451
|
-
|
|
452
|
-
export { ZanitMenubar, defineCustomElement };
|
|
453
|
-
//# sourceMappingURL=zanit-menubar.js.map
|
|
454
|
-
|
|
455
|
-
//# sourceMappingURL=zanit-menubar.js.map
|
|
1
|
+
import{t as e,p as t,H as r,h as a,F as i}from"./index.js";import{d as o,S as n,c as s,m as h}from"./p-BXeRLfHX.js";import{d as l,M as u}from"./p-BMtMaJq9.js";const m=t(class extends r{constructor(e){super(),!1!==e&&this.__registerHost(),this.__attachShadow()}get host(){return this}items=[];openMenu=void 0;openNavbar=void 0;currentPath=[];isMobile=!1;loading=!1;data;current=void 0;searchQuery=void 0;searchEnv=n.PROD;searchArea;timerId;async parseData(e){if(e)if(e instanceof URL)this.items=await this.fetchData(e);else if(e instanceof Promise)this.loading=!0,this.items=await e,this.loading=!1;else if("string"==typeof e)try{if(this.items=JSON.parse(e),!Array.isArray(this.items)||!this.items?.every((e=>e)))throw Error("Expected an array of MenubarItem objects.")}catch{let t;try{t=new URL(e)}catch{throw Error("Invalid string provided for `data` property: not a valid url or JSON.")}this.items=await this.fetchData(t)}else{if(!Array.isArray(e)||!e.every((e=>e)))throw Error("Invalid `data` property value. Expected an url, a JSON or an array/promise of MenubarItem objects.");this.items=e}}onItemsChange(){this.initTabindex()}onCurrentChange(){this.currentPath=this.current?.split("/").filter(Boolean)||[]}async connectedCallback(){const e=window.matchMedia("(width < 768px)");this.isMobile=e.matches,e.onchange=e=>{this.isMobile=e.matches,this.initTabindex(),this.openMenu=void 0},await this.parseData(this.data),this.onCurrentChange(),this.initTabindex()}handleOutsideClick(e){this.openMenu&&!s(this.host,e)&&(this.openMenu=void 0)}handleKeydown(e){switch(e.key){case"Escape":if(this.openMenu){e.preventDefault();const t=this.openMenu;this.openMenu=void 0,setTimeout((()=>{const e=this.host.shadowRoot.getElementById(t);e&&e.focus()}),0)}break;case"Tab":this.openMenu=void 0}}handleMouseover(){clearTimeout(this.timerId)}handleMouseout(e){this.timerId=window.setTimeout((()=>{this.openMenu&&!s(this.host,e)&&(this.openMenu=void 0)}),500)}handleFocusout(e){const t=e.relatedTarget;this.openMenu&&!this.host.shadowRoot.querySelector(".menu")?.contains(t)&&(this.openMenu=void 0)}async fetchData(e){try{this.loading=!0;const t=await(await fetch(e)).json();if(this.loading=!1,!Array.isArray(t)||!t.every((e=>e)))throw Error("Invalid data structure. Expected an array of MenuItem objects.");return t}catch(e){throw this.loading=!1,console.error("Error fetching menubar data:",e),Error("Failed to fetch menubar data from the provided URL.",{cause:e})}}initTabindex(){setTimeout((()=>{this.host.shadowRoot.querySelectorAll('[role="menubar"]')?.forEach((e=>{e.querySelectorAll('[role="menuitem"]')?.forEach(((e,t)=>e.setAttribute("tabindex",0===t?"0":"-1")))}))}),100)}isActive(e){return 0!==this.currentPath.length&&(!!this.currentPath.includes(e.id)||(e.menuItems?.length?e.menuItems.some((e=>e.id===this.current)):!(!e.navbarItems?.length||!e.navbarItems.some((e=>this.isActive(e))))))}showMenu(e){this.openMenu=void 0,e.menuItems?.length&&(this.openMenu=e.id)}getParentMenubarElements(e){return Array.from(e?.closest('[role="menubar"]')?.querySelectorAll(':scope > li a[role="menuitem"]')??[])}focusPreviousItem(e){this.openMenu=void 0;const t=this.getParentMenubarElements(e),r=t.indexOf(e),a=t[(r-1+t.length)%t.length];h(e,a),"true"===a.ariaHasPopup&&this.openMenu&&(this.openMenu=a.id)}focusNextItem(e){this.openMenu=void 0;const t=this.getParentMenubarElements(e),r=t.indexOf(e),a=t[(r+1)%t.length];h(e,a),"true"===a.ariaHasPopup&&this.openMenu&&(this.openMenu=a.id)}handleItemKeydown(e,t){const r=e.target;switch(e.key){case"Home":{e.preventDefault(),e.stopPropagation();const t=this.getParentMenubarElements(r)[0];h(r,t);break}case"End":{e.preventDefault(),e.stopPropagation();const t=this.getParentMenubarElements(r).pop();h(r,t);break}case"ArrowUp":if(!t.menuItems?.length)break;e.preventDefault(),e.stopPropagation(),this.openMenu=t.id,setTimeout((()=>{const e=Array.from(this.host.shadowRoot.querySelectorAll(`[aria-labelledby=${t.id}] [role="menuitem"]`));h(r,e[e.length-1])}),100);break;case"ArrowRight":e.preventDefault(),e.stopPropagation(),this.focusNextItem(r);break;case"ArrowDown":if(!t.menuItems?.length)break;this.openItemMenu(t);break;case"ArrowLeft":e.preventDefault(),e.stopPropagation(),this.focusPreviousItem(r);break;case" ":if(e.preventDefault(),e.stopPropagation(),this.openMenu===t.id){this.openMenu=void 0;break}if(t.menuItems?.length){this.openItemMenu(t);break}}}getPreviousGroup(e){const t=Array.from(e?.closest('[role="menu"]')?.querySelectorAll('[role="group"]')??[]),r=t.indexOf(e);return t[r-1]}getNextGroup(e){const t=Array.from(e?.closest('[role="menu"]')?.querySelectorAll('[role="group"]')??[]),r=t.indexOf(e);return t[r+1]}openItemMenu(e){this.openMenu=e.id,setTimeout((()=>{const t=this.host.shadowRoot.querySelector(`[aria-labelledby=${e.id}] [role="menuitem"]`);t.tabIndex=0,t.focus({preventScroll:!0})}),100)}handleMenuKeydown(e){const t=e.target,r=Array.from(t.closest('[role="menu"]')?.querySelectorAll('[role="menuitem"]')??[]),a=r.indexOf(t);switch(e.key){case"ArrowUp":e.preventDefault(),e.stopPropagation(),h(t,r[a-1]||r[r.length-1]);break;case"ArrowRight":{e.preventDefault(),e.stopPropagation();const r=t.closest("[role=group]"),a=this.getNextGroup(r);if(!a){t.tabIndex=-1;const e=t.closest('[role="menu"][aria-labelledby]').getAttribute("aria-labelledby"),r=this.host.shadowRoot.getElementById(e);this.focusNextItem(r);break}const i=a.querySelectorAll('[role="menuitem"]')??[];h(t,i[0]);break}case"ArrowDown":e.preventDefault(),e.stopPropagation(),h(t,r[a+1]||r[0]);break;case"ArrowLeft":{e.preventDefault(),e.stopPropagation();const r=t.closest("[role=group]"),a=this.getPreviousGroup(r);if(!a){t.tabIndex=-1;const e=t.closest('[role="menu"][aria-labelledby]').getAttribute("aria-labelledby"),r=this.host.shadowRoot.getElementById(e);this.focusPreviousItem(r);break}const i=a.querySelectorAll('[role="menuitem"]')??[];h(t,i[0]);break}case"Home":e.preventDefault(),e.stopPropagation(),h(t,r[0]);break;case"End":e.preventDefault(),e.stopPropagation(),h(t,r[r.length-1])}}render(){return this.isMobile?a("zanit-mobile-menubar",{items:this.items,currentPath:this.currentPath,searchQuery:this.searchQuery,loading:this.loading,searchArea:this.searchArea,searchEnv:this.searchEnv}):a("nav",{"aria-label":"Zanichelli.it"},a("div",{class:"shadow-wrapper"},a("div",{class:"width-limiter"},a("ul",{class:"menubar",role:"menubar","aria-label":"Zanichelli.it"},this.loading&&[...[,,,,]].map(((e,t)=>a(i,null,a("li",{role:"none"},a("div",{class:"menubar-item"},a("z-ghost-loading",null))),t<3&&a("li",{role:"separator"})))),this.items?.map(((e,t)=>a(i,null,a("li",{role:"none"},a("a",{class:{"menubar-item":!0,active:this.isActive(e)},href:e.href,id:e.id,role:"menuitem",tabIndex:-1,"aria-expanded":e.menuItems?.length?this.openMenu===e.id?"true":"false":void 0,"aria-haspopup":e.menuItems?.length?"true":"false","aria-current":this.current.includes(e.id)?"page":"false",onPointerOver:()=>this.showMenu(e),onKeyDown:t=>this.handleItemKeydown(t,e),target:e.target},a("span",{"data-text":e.label},e.label),e.menuItems?.length>0&&a("z-icon",{name:this.openMenu===e.id?"chevron-up":"chevron-down",width:"0.875rem",height:"0.875rem"}))),t<this.items?.length-1&&a("li",{role:"separator"}))))),a("zanit-search-form",{searchQuery:this.searchQuery,searchArea:this.searchArea,searchEnv:this.searchEnv,onResetSearch:()=>this.searchQuery=void 0})),this.items.map((e=>this.openMenu===e.id&&a(u,{controlledBy:e.id,items:e.menuItems,currentPath:this.currentPath,onItemKeyDown:e=>this.handleMenuKeydown(e)})))),this.items?.filter((e=>this.isActive(e))).map((e=>e.navbarItems?.length&&a("nav",{class:{"sub-menubar":!0,"shadow-wrapper":!0},"aria-label":"Sezioni: "+e.label},a("ul",{role:"menubar"},e.navbarItems.map((t=>a(i,null,a("li",{role:"none"},a("a",{class:{"menubar-item":!0,active:this.isActive(t)},href:t.href,id:t.id,role:"menuitem",tabIndex:-1,"aria-haspopup":t.menuItems?.length?"true":"false","aria-expanded":t.menuItems?.length?this.openMenu===t.id?"true":"false":void 0,"aria-current":this.current.includes(t.id)?"page":"false",onPointerOver:()=>this.showMenu(t),onKeyDown:e=>this.handleItemKeydown(e,t),target:e.target},a("span",null,t.label),t.menuItems?.length>0&&a("z-icon",{name:this.openMenu===t.id?"chevron-up":"chevron-down",width:"0.75rem",height:"0.75rem"}))))))),e.navbarItems.map((e=>this.openMenu===e.id&&a(u,{controlledBy:e.id,items:e.menuItems,currentPath:this.currentPath,onItemKeyDown:e=>this.handleMenuKeydown(e)})))))))}static get delegatesFocus(){return!0}static get watchers(){return{data:[{parseData:0}],items:[{onItemsChange:0}],current:[{onCurrentChange:0}]}}static get style(){return":host{position:relative;z-index:2;display:flex;width:100%;background-color:#fff;color:var(--gray900);font-family:var(--font-family-sans)}:host,*,::before,::after{box-sizing:border-box}*:focus:focus-visible{box-shadow:var(--shadow-focus-primary);outline:none}ul{padding:0;margin:0;list-style:none}a{color:var(--gray900);cursor:pointer;text-decoration:none}button{all:unset;cursor:pointer}:host nav{width:100%}.shadow-wrapper{position:relative;z-index:1;display:flex;width:100%}.shadow-wrapper::after{position:absolute;top:0;right:0;width:100%;height:100%;background:transparent;box-shadow:var(--shadow-1);content:'';pointer-events:none}.width-limiter{position:relative;display:flex;width:100%;max-width:var(--zanit-menubar-max-width, 1366px);margin:0 auto}.shadow-wrapper+.shadow-wrapper{z-index:0}.sub-menubar>ul{gap:28px}.width-limiter>ul,.sub-menubar>ul{position:relative;z-index:3;display:flex;width:100%;align-items:center;padding:0 var(--grid-margin);margin-right:auto;margin-left:auto;gap:20px}.shadow-wrapper>.width-limiter,.shadow-wrapper>ul{width:100%;max-width:var(--zanit-menubar-max-width, 1366px)}ul.menubar{height:3rem;padding-right:0}.menubar z-ghost-loading{display:block;width:120px;height:1.25rem}.menubar>li[role='separator']{width:1px;height:1.25rem;background-color:#000}.menubar-item{position:relative;display:flex;align-items:center;padding:14px 0;font-size:1rem;gap:8px;line-height:1.25rem}.menubar .menubar-item{text-transform:uppercase}.menubar-item [data-text]{display:flex;flex-direction:column}.menubar-item.active>[data-text],.menubar-item:hover>[data-text],.menubar-item:focus:focus-visible>[data-text]{font-weight:var(--font-bd)}.menubar-item>[data-text]::after{height:0;content:attr(data-text) / '';font-weight:var(--font-bd);letter-spacing:normal;pointer-events:none;user-select:none;visibility:hidden}.sub-menubar .menubar-item.active::after{position:absolute;z-index:-1;bottom:0;left:-4px;width:calc(100% + 8px);height:4px;background-color:var(--red500);content:''}zanit-search-form{margin-left:auto}.menu-wrapper{width:100%;background-color:#fff}.menu{position:relative;display:flex;width:100%;flex-direction:column;gap:32px 0}.menu .group{display:flex;flex-direction:column}.menu .group .group-name{border-bottom:1px solid currentcolor;margin-bottom:4px;color:var(--red500);font-size:0.875rem;font-weight:var(--font-md)}.menu .group .menu-list{display:flex;flex-direction:column;gap:8px}.menu .group .menu-list .menu-item{display:block;border-bottom:2px solid transparent;font-size:0.875rem;font-weight:var(--font-md)}.menu .menu-list .menu-item.active,.menu .menu-list .menu-item:hover{border-bottom-color:var(--red500)}.menu .group.highlight .menu-list .menu-item{font-size:1rem}@media (width >= 768px){.menu-wrapper{position:absolute;top:100%;left:0;display:flex;justify-content:center;box-shadow:var(--shadow-1)}.menu{display:grid;width:100%;max-width:var(--zanit-menubar-max-width, 1366px);padding:16px var(--grid-margin);gap:0 24px;grid-auto-columns:minmax(0, max-content);grid-auto-flow:column;grid-template-rows:minmax(0, max-content) max-content}.menu .group{display:grid;grid-row:1 / -1;grid-template-columns:1fr;grid-template-rows:subgrid}@supports not (grid-template-rows: subgrid){.menu .group{grid-template-rows:repeat(auto-fit, minmax(0, max-content))}}.menu .group .group-name{border:none;margin-bottom:16px}.menu .group .menu-list .menu-item{font-size:1rem}.menu .group.highlight .menu-list .menu-item{font-size:1.5rem}}"}},[529,"zanit-menubar",{data:[1],current:[1],searchQuery:[1025,"search-query"],searchEnv:[1,"search-env"],searchArea:[1,"search-area"],items:[32],openMenu:[32],openNavbar:[32],currentPath:[32],isMobile:[32],loading:[32]},[[5,"click","handleOutsideClick"],[5,"keydown","handleKeydown"],[1,"mouseover","handleMouseover"],[1,"mouseout","handleMouseout"],[1,"focusout","handleFocusout"]],{data:[{parseData:0}],items:[{onItemsChange:0}],current:[{onCurrentChange:0}]}]);function d(){"undefined"!=typeof customElements&&["zanit-menubar","zanit-mobile-menubar","zanit-search-form"].forEach((t=>{switch(t){case"zanit-menubar":customElements.get(e(t))||customElements.define(e(t),m);break;case"zanit-mobile-menubar":customElements.get(e(t))||l();break;case"zanit-search-form":customElements.get(e(t))||o()}}))}d();const c=m,p=d;export{c as ZanitMenubar,p as defineCustomElement}
|