@zanichelli/zanichelli-it-frontend-kit 1.3.1 → 1.4.0-RC2

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 (124) hide show
  1. package/dist/types/components/menubar/menubar.d.ts +5 -0
  2. package/dist/types/components/menubar/mobile-menubar/mobile-menubar.d.ts +5 -0
  3. package/dist/types/components/menubar/search-form/search-form.d.ts +28 -5
  4. package/dist/types/components/menubar/search-form/suggestions.d.ts +11 -0
  5. package/dist/types/components.d.ts +60 -4
  6. package/dist/types/utils/subjects.api.d.ts +6 -0
  7. package/dist/types/utils/types.d.ts +7 -0
  8. package/dist/types/utils/utils.d.ts +8 -0
  9. package/dist/zanichelli-it-frontend-kit/index-DPw_TAEB.js +4170 -0
  10. package/dist/zanichelli-it-frontend-kit/index-DPw_TAEB.js.map +1 -0
  11. package/dist/zanichelli-it-frontend-kit/index.esm.js +10 -0
  12. package/dist/zanichelli-it-frontend-kit/index.esm.js.map +1 -1
  13. package/dist/zanichelli-it-frontend-kit/menu-BsP3cOc_.js +46 -0
  14. package/dist/zanichelli-it-frontend-kit/menu-BsP3cOc_.js.map +1 -0
  15. package/dist/zanichelli-it-frontend-kit/subjects.api-BRhngFD0.js +54 -0
  16. package/dist/zanichelli-it-frontend-kit/subjects.api-BRhngFD0.js.map +1 -0
  17. package/dist/zanichelli-it-frontend-kit/zanichelli-it-frontend-kit.css +993 -1
  18. package/dist/zanichelli-it-frontend-kit/zanichelli-it-frontend-kit.esm.js +49 -1
  19. package/dist/zanichelli-it-frontend-kit/zanichelli-it-frontend-kit.esm.js.map +1 -1
  20. package/dist/zanichelli-it-frontend-kit/zanit-back-to-top.entry.esm.js.map +1 -0
  21. package/dist/{components/zanit-back-to-top.js → zanichelli-it-frontend-kit/zanit-back-to-top.entry.js} +10 -34
  22. package/dist/zanichelli-it-frontend-kit/zanit-back-to-top.entry.js.map +1 -0
  23. package/dist/zanichelli-it-frontend-kit/zanit-menubar.entry.esm.js.map +1 -0
  24. package/dist/{components/zanit-menubar.js → zanichelli-it-frontend-kit/zanit-menubar.entry.js} +19 -58
  25. package/dist/zanichelli-it-frontend-kit/zanit-menubar.entry.js.map +1 -0
  26. package/dist/zanichelli-it-frontend-kit/zanit-mobile-menubar.entry.esm.js.map +1 -0
  27. package/dist/{components/p-BJzEFXY7.js → zanichelli-it-frontend-kit/zanit-mobile-menubar.entry.js} +18 -87
  28. package/dist/zanichelli-it-frontend-kit/zanit-mobile-menubar.entry.js.map +1 -0
  29. package/dist/zanichelli-it-frontend-kit/zanit-search-form.entry.esm.js.map +1 -0
  30. package/dist/zanichelli-it-frontend-kit/zanit-search-form.entry.js +307 -0
  31. package/dist/zanichelli-it-frontend-kit/zanit-search-form.entry.js.map +1 -0
  32. package/package.json +1 -1
  33. package/www/build/index-DPw_TAEB.js +4170 -0
  34. package/www/build/index-DPw_TAEB.js.map +1 -0
  35. package/www/build/index.esm.js +10 -0
  36. package/www/build/index.esm.js.map +1 -1
  37. package/www/build/menu-BsP3cOc_.js +46 -0
  38. package/www/build/menu-BsP3cOc_.js.map +1 -0
  39. package/www/build/subjects.api-BRhngFD0.js +54 -0
  40. package/www/build/subjects.api-BRhngFD0.js.map +1 -0
  41. package/www/build/zanichelli-it-frontend-kit.css +993 -1
  42. package/www/build/zanichelli-it-frontend-kit.esm.js +49 -1
  43. package/www/build/zanichelli-it-frontend-kit.esm.js.map +1 -1
  44. package/www/build/zanit-back-to-top.entry.esm.js.map +1 -0
  45. package/www/build/zanit-back-to-top.entry.js +64 -0
  46. package/www/build/zanit-back-to-top.entry.js.map +1 -0
  47. package/www/build/zanit-menubar.entry.esm.js.map +1 -0
  48. package/{dist/collection/components/menubar/menubar.js → www/build/zanit-menubar.entry.js} +31 -159
  49. package/www/build/zanit-menubar.entry.js.map +1 -0
  50. package/www/build/zanit-mobile-menubar.entry.esm.js.map +1 -0
  51. package/www/build/zanit-mobile-menubar.entry.js +171 -0
  52. package/www/build/zanit-mobile-menubar.entry.js.map +1 -0
  53. package/www/build/zanit-search-form.entry.esm.js.map +1 -0
  54. package/www/build/zanit-search-form.entry.js +307 -0
  55. package/www/build/zanit-search-form.entry.js.map +1 -0
  56. package/www/index.html +11 -2
  57. package/dist/cjs/index-BLzQAHAI.js +0 -1578
  58. package/dist/cjs/index-BLzQAHAI.js.map +0 -1
  59. package/dist/cjs/index.cjs.js +0 -5
  60. package/dist/cjs/index.cjs.js.map +0 -1
  61. package/dist/cjs/loader.cjs.js +0 -15
  62. package/dist/cjs/loader.cjs.js.map +0 -1
  63. package/dist/cjs/zanichelli-it-frontend-kit.cjs.js +0 -27
  64. package/dist/cjs/zanichelli-it-frontend-kit.cjs.js.map +0 -1
  65. package/dist/cjs/zanit-back-to-top.zanit-menubar.zanit-mobile-menubar.zanit-search-form.entry.cjs.js.map +0 -1
  66. package/dist/cjs/zanit-back-to-top_4.cjs.entry.js +0 -771
  67. package/dist/cjs/zanit-back-to-top_4.cjs.entry.js.map +0 -1
  68. package/dist/collection/collection-manifest.json +0 -15
  69. package/dist/collection/components/back-to-top/back-to-top.css +0 -16
  70. package/dist/collection/components/back-to-top/back-to-top.js +0 -130
  71. package/dist/collection/components/back-to-top/back-to-top.js.map +0 -1
  72. package/dist/collection/components/menubar/menu/menu.css +0 -95
  73. package/dist/collection/components/menubar/menu/menu.js +0 -38
  74. package/dist/collection/components/menubar/menu/menu.js.map +0 -1
  75. package/dist/collection/components/menubar/menubar.css +0 -168
  76. package/dist/collection/components/menubar/menubar.js.map +0 -1
  77. package/dist/collection/components/menubar/mobile-menubar/mobile-menubar.css +0 -121
  78. package/dist/collection/components/menubar/mobile-menubar/mobile-menubar.js +0 -291
  79. package/dist/collection/components/menubar/mobile-menubar/mobile-menubar.js.map +0 -1
  80. package/dist/collection/components/menubar/search-form/search-form.css +0 -155
  81. package/dist/collection/components/menubar/search-form/search-form.js +0 -176
  82. package/dist/collection/components/menubar/search-form/search-form.js.map +0 -1
  83. package/dist/collection/index.js +0 -11
  84. package/dist/collection/index.js.map +0 -1
  85. package/dist/collection/utils/index.js +0 -2
  86. package/dist/collection/utils/index.js.map +0 -1
  87. package/dist/collection/utils/utils.js +0 -17
  88. package/dist/collection/utils/utils.js.map +0 -1
  89. package/dist/components/index.js +0 -1335
  90. package/dist/components/index.js.map +0 -1
  91. package/dist/components/p-BJzEFXY7.js.map +0 -1
  92. package/dist/components/p-Cfa-BVne.js +0 -133
  93. package/dist/components/p-Cfa-BVne.js.map +0 -1
  94. package/dist/components/zanit-back-to-top.js.map +0 -1
  95. package/dist/components/zanit-menubar.js.map +0 -1
  96. package/dist/components/zanit-mobile-menubar.js +0 -9
  97. package/dist/components/zanit-mobile-menubar.js.map +0 -1
  98. package/dist/components/zanit-search-form.js +0 -9
  99. package/dist/components/zanit-search-form.js.map +0 -1
  100. package/dist/esm/index-DSdvvVFj.js +0 -1549
  101. package/dist/esm/index-DSdvvVFj.js.map +0 -1
  102. package/dist/esm/index.js +0 -4
  103. package/dist/esm/index.js.map +0 -1
  104. package/dist/esm/loader.js +0 -13
  105. package/dist/esm/loader.js.map +0 -1
  106. package/dist/esm/zanichelli-it-frontend-kit.js +0 -23
  107. package/dist/esm/zanichelli-it-frontend-kit.js.map +0 -1
  108. package/dist/esm/zanit-back-to-top.zanit-menubar.zanit-mobile-menubar.zanit-search-form.entry.js.map +0 -1
  109. package/dist/esm/zanit-back-to-top_4.entry.js +0 -766
  110. package/dist/esm/zanit-back-to-top_4.entry.js.map +0 -1
  111. package/dist/index.cjs.js +0 -1
  112. package/dist/index.js +0 -1
  113. package/dist/zanichelli-it-frontend-kit/p-DSdvvVFj.js +0 -3
  114. package/dist/zanichelli-it-frontend-kit/p-DSdvvVFj.js.map +0 -1
  115. package/dist/zanichelli-it-frontend-kit/p-fe01ee7e.entry.js +0 -2
  116. package/dist/zanichelli-it-frontend-kit/p-fe01ee7e.entry.js.map +0 -1
  117. package/dist/zanichelli-it-frontend-kit/zanit-back-to-top.zanit-menubar.zanit-mobile-menubar.zanit-search-form.entry.esm.js.map +0 -1
  118. package/www/build/p-43c395dc.css +0 -1
  119. package/www/build/p-DSdvvVFj.js +0 -3
  120. package/www/build/p-DSdvvVFj.js.map +0 -1
  121. package/www/build/p-b4df0dec.js +0 -2
  122. package/www/build/p-fe01ee7e.entry.js +0 -2
  123. package/www/build/p-fe01ee7e.entry.js.map +0 -1
  124. package/www/build/zanit-back-to-top.zanit-menubar.zanit-mobile-menubar.zanit-search-form.entry.esm.js.map +0 -1
@@ -1,771 +0,0 @@
1
- 'use strict';
2
-
3
- var index = require('./index-BLzQAHAI.js');
4
-
5
- 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)}";
6
-
7
- const ZanitBackTop = class {
8
- constructor(hostRef) {
9
- index.registerInstance(this, hostRef);
10
- }
11
- resizeObserver;
12
- mutationObserver;
13
- get host() { return index.getElement(this); }
14
- /** Indicates whether the back-to-top button is visible and usable. */
15
- showFab = false;
16
- /** Indicates the current height of the page. */
17
- currentPageHeight;
18
- /** Indicates if the viewport is mobile. */
19
- isMobile = false;
20
- /** Min page height from which the back-to-top button must appear. */
21
- pageMinHeight = 1600;
22
- /** Min scroll height from which the back-to-top button must appear. */
23
- scrollMinHeight = 800;
24
- handleScroll() {
25
- this.updateFabVisibility();
26
- }
27
- handleResize = () => {
28
- const newHeight = document.body.scrollHeight;
29
- if (newHeight !== this.currentPageHeight) {
30
- this.currentPageHeight = newHeight;
31
- this.updateFabVisibility();
32
- }
33
- };
34
- connectedCallback() {
35
- this.currentPageHeight = document.body.scrollHeight;
36
- this.resizeObserver = new ResizeObserver(this.handleResize);
37
- this.resizeObserver.observe(document.body);
38
- this.mutationObserver = new MutationObserver(this.handleResize);
39
- this.mutationObserver.observe(document.body, { childList: true, subtree: true });
40
- this.updateFabVisibility();
41
- const mobileMediaQuery = window.matchMedia('(width < 768px)');
42
- this.isMobile = mobileMediaQuery.matches;
43
- mobileMediaQuery.onchange = (mql) => {
44
- this.isMobile = mql.matches;
45
- };
46
- }
47
- disconnectedCallback() {
48
- this.resizeObserver.disconnect();
49
- this.mutationObserver.disconnect();
50
- }
51
- updateFabVisibility() {
52
- this.showFab = this.currentPageHeight > this.pageMinHeight && window.scrollY > this.scrollMinHeight;
53
- }
54
- scroll() {
55
- window.scrollTo({ top: 0, behavior: 'smooth' });
56
- }
57
- render() {
58
- return (index.h(index.Host, { key: '3abd8ab70075d8042285d8ed6fab0729c4b5ec42', class: { hidden: !this.showFab }, "aria-hidden": this.showFab ? 'false' : 'true' }, index.h("button", { key: '11b149d5f1d75720d4bdd329e9897da782092ed1', class: { 'z-fab': true, 'z-fab-extended': !this.isMobile }, onClick: () => this.scroll() }, index.h("z-icon", { key: 'fbdff1419da6d20ab594ffd11c58d7bf25fb7aa6', name: "back-top" }), index.h("span", { key: '0292f761b5459c372f003ed514abbd3403570c75' }, "Torna su"))));
59
- }
60
- };
61
- ZanitBackTop.style = backToTopCss;
62
-
63
- /**
64
- * Check if an element contains an event target by checking its composedPath.
65
- * Useful when an event target may come from a component's shadow DOM.
66
- */
67
- const containsTarget = (ancestor, event) => {
68
- return event
69
- .composedPath()
70
- .filter((el) => el !== document && el !== window.window)
71
- .some((el) => ancestor.contains(el));
72
- };
73
- /** Move the focus to `next` element, set tabindex to 0 for `next` and -1 to `current`. */
74
- const moveFocus = (current, next) => {
75
- current.tabIndex = -1;
76
- next.tabIndex = 0;
77
- next.focus({ preventScroll: true });
78
- };
79
-
80
- const DEFAULT_GROUP_KEY = 'default';
81
- const DEFAULT_GROUP = {
82
- id: DEFAULT_GROUP_KEY,
83
- label: DEFAULT_GROUP_KEY,
84
- };
85
- /** Get the items grouped by their group. */
86
- const getGroupedItems = (items) => {
87
- const groups = items.reduce((grouped, item) => {
88
- const itemGroup = grouped.find(({ group }) => group.id === (item.group?.id || DEFAULT_GROUP.id));
89
- if (!itemGroup) {
90
- grouped.push({ group: item.group ?? DEFAULT_GROUP, items: [item] });
91
- }
92
- else {
93
- itemGroup.items.push(item);
94
- }
95
- return grouped;
96
- }, []);
97
- // Sort to keep default group at the end
98
- return groups.sort((a, b) => (a.group.id === DEFAULT_GROUP_KEY ? 1 : b.group.id === DEFAULT_GROUP_KEY ? -1 : 0));
99
- };
100
- /**
101
- * Floating menu component. It shows a list of items that can be grouped.
102
- */
103
- const Menu = ({ controlledBy, items, currentPath = [], onItemKeyDown }) => {
104
- if (!items?.length) {
105
- return null;
106
- }
107
- const groups = getGroupedItems(items);
108
- const isActive = (item) => currentPath.includes(controlledBy) && currentPath.includes(item.id);
109
- return (index.h("div", { class: "menu-wrapper", role: "none" },
110
- index.h("div", { class: "menu", "aria-labelledby": controlledBy ?? undefined, role: "menu" }, groups.map(({ group, items }) => (index.h("div", { class: { group: true, highlight: items.some((item) => item.highlight) } },
111
- group.id !== DEFAULT_GROUP_KEY ? (index.h("div", { class: "group-name", id: group.id }, group.label)) : groups.length > 1 ? (
112
- // empty div to keep the same height as the other groups
113
- index.h("div", { class: "group-name" })) : null,
114
- index.h("ul", { class: "menu-list", role: "group", "aria-labelledby": group.id !== DEFAULT_GROUP_KEY ? group.id : undefined }, items.map((item) => (index.h("li", { role: "none" }, item.href && (index.h("a", { class: {
115
- 'menu-item': true,
116
- 'active': isActive(item),
117
- }, href: item.href, role: "menuitem", tabIndex: -1, "aria-current": isActive(item) ? 'page' : 'false', onKeyDown: (event) => onItemKeyDown(event), target: item.target }, item.label))))))))))));
118
- };
119
-
120
- 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;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{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}";
121
-
122
- const menuCss$1 = ".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}}";
123
-
124
- const ZanitMenubar = class {
125
- constructor(hostRef) {
126
- index.registerInstance(this, hostRef);
127
- }
128
- get host() { return index.getElement(this); }
129
- /** Menubar items extracted from `data`. */
130
- items = [];
131
- /** ID of the currently open menu. */
132
- openMenu = undefined;
133
- /** ID of the item to show the subitems navbar for. */
134
- openNavbar = undefined;
135
- /** IDs of the current prop */
136
- currentPath = [];
137
- isMobile = false;
138
- loading = false;
139
- /** The data to build the menu (as an array of `MenubarItem` or a JSON array) or the url to fetch to retrieve it. */
140
- data;
141
- /** Path of the current item. */
142
- current = undefined;
143
- /** Initial search query. */
144
- searchQuery = undefined;
145
- timerId;
146
- /** Setup the list of items. */
147
- async parseData(data) {
148
- if (!data) {
149
- return;
150
- }
151
- if (data instanceof URL) {
152
- this.items = await this.fetchData(data);
153
- }
154
- else if (data instanceof Promise) {
155
- this.loading = true;
156
- this.items = await data;
157
- this.loading = false;
158
- }
159
- else if (typeof data === 'string') {
160
- try {
161
- this.items = JSON.parse(data);
162
- if (!Array.isArray(this.items) || !this.items?.every((item) => item)) {
163
- throw new Error('Expected an array of MenubarItem objects.');
164
- }
165
- }
166
- catch {
167
- let url;
168
- try {
169
- url = new URL(data);
170
- }
171
- catch {
172
- throw new Error('Invalid string provided for `data` property: not a valid url or JSON.');
173
- }
174
- this.items = await this.fetchData(url);
175
- }
176
- }
177
- else if (Array.isArray(data) && data.every((item) => item)) {
178
- this.items = data;
179
- }
180
- else {
181
- throw new Error('Invalid `data` property value. Expected an url, a JSON or an array/promise of MenubarItem objects.');
182
- }
183
- }
184
- onItemsChange() {
185
- this.initTabindex();
186
- }
187
- onCurrentChange() {
188
- this.currentPath = this.current?.split('/').filter(Boolean) || [];
189
- }
190
- async connectedCallback() {
191
- const mobileMediaQuery = window.matchMedia('(width < 768px)');
192
- this.isMobile = mobileMediaQuery.matches;
193
- mobileMediaQuery.onchange = (mql) => {
194
- this.isMobile = mql.matches;
195
- this.initTabindex();
196
- this.openMenu = undefined;
197
- };
198
- await this.parseData(this.data);
199
- this.onCurrentChange();
200
- this.initTabindex();
201
- }
202
- /** Close any open menu when clicking outside. */
203
- handleOutsideClick(event) {
204
- if (!this.openMenu || containsTarget(this.host, event)) {
205
- return;
206
- }
207
- this.openMenu = undefined;
208
- }
209
- /** Close any open menu when pressing Escape or Tab.
210
- * Uses document-level listener to ensure Escape works from any focus location within the menu.
211
- */
212
- handleKeydown(event) {
213
- switch (event.key) {
214
- case 'Escape': {
215
- if (this.openMenu) {
216
- event.preventDefault();
217
- // Return focus to the menu trigger after closing
218
- const menuTriggerId = this.openMenu;
219
- this.openMenu = undefined;
220
- // Use setTimeout(0) to defer focus until after Stencil's render cycle completes
221
- setTimeout(() => {
222
- const menuTrigger = this.host.shadowRoot.getElementById(menuTriggerId);
223
- if (menuTrigger) {
224
- menuTrigger.focus();
225
- }
226
- }, 0);
227
- }
228
- break;
229
- }
230
- case 'Tab':
231
- this.openMenu = undefined;
232
- break;
233
- }
234
- }
235
- handleMouseover() {
236
- clearTimeout(this.timerId);
237
- }
238
- /**
239
- * Automatically close any open menu on mouseout after with a little delay.
240
- * The delay is useful to avoid immediate closing when the pointer briefly leaves the component.
241
- */
242
- handleMouseout(event) {
243
- this.timerId = window.setTimeout(() => {
244
- if (!this.openMenu || containsTarget(this.host, event)) {
245
- return;
246
- }
247
- this.openMenu = undefined;
248
- }, 500);
249
- }
250
- /** Close the menu when it loses focus. */
251
- handleFocusout(event) {
252
- const relatedTarget = event.relatedTarget;
253
- if (!this.openMenu || this.host.shadowRoot.querySelector('.menu')?.contains(relatedTarget)) {
254
- return;
255
- }
256
- this.openMenu = undefined;
257
- }
258
- /** Fetch data from passed URL. */
259
- async fetchData(url) {
260
- try {
261
- this.loading = true;
262
- const data = await (await fetch(url)).json();
263
- this.loading = false;
264
- if (!Array.isArray(data) || !data.every((item) => item)) {
265
- throw new Error('Invalid data structure. Expected an array of MenuItem objects.');
266
- }
267
- return data;
268
- }
269
- catch (error) {
270
- this.loading = false;
271
- console.error('Error fetching menubar data:', error);
272
- throw new Error('Failed to fetch menubar data from the provided URL.', { cause: error });
273
- }
274
- }
275
- /** Initialize tabindex on menuitems of menubars, setting -1 to all but the first one. */
276
- initTabindex() {
277
- setTimeout(() => {
278
- this.host.shadowRoot.querySelectorAll('[role="menubar"]')?.forEach((menubar) => {
279
- menubar
280
- .querySelectorAll('[role="menuitem"]')
281
- ?.forEach((item, index) => item.setAttribute('tabindex', index === 0 ? '0' : '-1'));
282
- });
283
- }, 100);
284
- }
285
- /** Indicates whether the element has to be highlighted by checking whether it is set as current or one of its descendants is. */
286
- isActive(item) {
287
- if (this.currentPath.length === 0) {
288
- return false;
289
- }
290
- if (this.currentPath.includes(item.id)) {
291
- return true;
292
- }
293
- if (item.menuItems?.length) {
294
- return item.menuItems.some((menuItem) => menuItem.id === this.current);
295
- }
296
- if (item.navbarItems?.length) {
297
- const isActive = item.navbarItems.some((navbarItem) => this.isActive(navbarItem));
298
- if (isActive) {
299
- return true;
300
- }
301
- }
302
- return false;
303
- }
304
- /** Opens the menu associated with the menubar `item`, if any. */
305
- showMenu(item) {
306
- this.openMenu = undefined; // close any open menu first
307
- if (!item.menuItems?.length) {
308
- return;
309
- }
310
- this.openMenu = item.id;
311
- }
312
- /** Get all elements with `menuitem` role inside parent's `menubar`. * */
313
- getParentMenubarElements(itemEl) {
314
- return Array.from(itemEl?.closest('[role="menubar"]')?.querySelectorAll(':scope > li a[role="menuitem"]') ?? []);
315
- }
316
- /** Move the focus to the previous menubar item, or the last one. Then open its menu if any other menu was open. */
317
- focusPreviousItem(itemEl) {
318
- this.openMenu = undefined; // close any open menu first
319
- const menubarElements = this.getParentMenubarElements(itemEl);
320
- const currentIndex = menubarElements.indexOf(itemEl);
321
- const prevItem = menubarElements[(currentIndex - 1 + menubarElements.length) % menubarElements.length]; // get previous item or last one
322
- moveFocus(itemEl, prevItem);
323
- // open the item's menu if any other menu was open
324
- if (prevItem.ariaHasPopup === 'true' && this.openMenu) {
325
- this.openMenu = prevItem.id;
326
- }
327
- }
328
- /** Move the focus to the next menubar item, or the first one. Then open its menu if any other menu was open. */
329
- focusNextItem(itemEl) {
330
- this.openMenu = undefined; // close any open menu first
331
- const menubarElements = this.getParentMenubarElements(itemEl);
332
- const currentIndex = menubarElements.indexOf(itemEl);
333
- const nextItem = menubarElements[(currentIndex + 1) % menubarElements.length]; // get next item or first one
334
- moveFocus(itemEl, nextItem);
335
- // open the item's menu if any other menu was open
336
- if (nextItem.ariaHasPopup === 'true' && this.openMenu) {
337
- this.openMenu = nextItem.id;
338
- }
339
- }
340
- /** Handles keyboard navigation on menubar items. */
341
- handleItemKeydown(event, item) {
342
- const target = event.target;
343
- switch (event.key) {
344
- case 'Home': {
345
- event.preventDefault();
346
- event.stopPropagation();
347
- const firstItem = this.getParentMenubarElements(target)[0];
348
- moveFocus(target, firstItem);
349
- break;
350
- }
351
- case 'End': {
352
- event.preventDefault();
353
- event.stopPropagation();
354
- const lastItem = this.getParentMenubarElements(target).pop();
355
- moveFocus(target, lastItem);
356
- break;
357
- }
358
- case 'ArrowUp': {
359
- if (!item.menuItems?.length) {
360
- break;
361
- }
362
- event.preventDefault();
363
- event.stopPropagation();
364
- this.openMenu = item.id;
365
- // focus last item of the menu
366
- setTimeout(() => {
367
- const menuItems = Array.from(this.host.shadowRoot.querySelectorAll(`[aria-labelledby=${item.id}] [role="menuitem"]`));
368
- moveFocus(target, menuItems[menuItems.length - 1]);
369
- }, 100);
370
- break;
371
- }
372
- case 'ArrowRight': {
373
- event.preventDefault();
374
- event.stopPropagation();
375
- this.focusNextItem(target);
376
- break;
377
- }
378
- case 'ArrowDown': {
379
- if (!item.menuItems?.length) {
380
- break;
381
- }
382
- this.openItemMenu(item);
383
- break;
384
- }
385
- case 'ArrowLeft': {
386
- event.preventDefault();
387
- event.stopPropagation();
388
- this.focusPreviousItem(target);
389
- break;
390
- }
391
- case ' ': {
392
- event.preventDefault();
393
- event.stopPropagation();
394
- if (this.openMenu === item.id) {
395
- this.openMenu = undefined;
396
- break;
397
- }
398
- else if (item.menuItems?.length) {
399
- this.openItemMenu(item);
400
- break;
401
- }
402
- }
403
- }
404
- }
405
- /** Get the previous element with `role=group`. */
406
- getPreviousGroup(groupContainer) {
407
- const groups = Array.from(groupContainer?.closest('[role="menu"]')?.querySelectorAll('[role="group"]') ?? []);
408
- const currentIndex = groups.indexOf(groupContainer);
409
- return groups[currentIndex - 1];
410
- }
411
- /** Get the next element with `role=group`. */
412
- getNextGroup(groupContainer) {
413
- const groups = Array.from(groupContainer?.closest('[role="menu"]')?.querySelectorAll('[role="group"]') ?? []);
414
- const currentIndex = groups.indexOf(groupContainer);
415
- return groups[currentIndex + 1];
416
- }
417
- openItemMenu(item) {
418
- this.openMenu = item.id;
419
- setTimeout(() => {
420
- // focus first item of the menu
421
- const firstMenuItem = this.host.shadowRoot.querySelector(`[aria-labelledby=${item.id}] [role="menuitem"]`);
422
- firstMenuItem.tabIndex = 0;
423
- firstMenuItem.focus({ preventScroll: true });
424
- }, 100);
425
- }
426
- /** Handles keyboard navigation events from `Menu` component. */
427
- handleMenuKeydown(event) {
428
- const itemElement = event.target;
429
- const items = Array.from(itemElement.closest('[role="menu"]')?.querySelectorAll('[role="menuitem"]') ?? []);
430
- const currentIndex = items.indexOf(itemElement);
431
- switch (event.key) {
432
- case 'ArrowUp': {
433
- event.preventDefault();
434
- event.stopPropagation();
435
- const prevItem = items[currentIndex - 1] || items[items.length - 1];
436
- moveFocus(itemElement, prevItem);
437
- break;
438
- }
439
- // Move the focus to the first item of the next group if any, otherwise move it to the next menubar item
440
- case 'ArrowRight': {
441
- event.preventDefault();
442
- event.stopPropagation();
443
- const currentGroup = itemElement.closest('[role=group]');
444
- const nextGroup = this.getNextGroup(currentGroup);
445
- if (!nextGroup) {
446
- itemElement.tabIndex = -1;
447
- const menuTriggerId = itemElement.closest('[role="menu"][aria-labelledby]').getAttribute('aria-labelledby');
448
- const focusedItem = this.host.shadowRoot.getElementById(menuTriggerId);
449
- this.focusNextItem(focusedItem);
450
- break;
451
- }
452
- const nextGroupItems = (nextGroup.querySelectorAll('[role="menuitem"]') ?? []);
453
- moveFocus(itemElement, nextGroupItems[0]);
454
- break;
455
- }
456
- case 'ArrowDown': {
457
- event.preventDefault();
458
- event.stopPropagation();
459
- const nextItem = items[currentIndex + 1] || items[0];
460
- moveFocus(itemElement, nextItem);
461
- break;
462
- }
463
- // Move the focus to the first item of the previous group if any, otherwise move it to the previous menubar item
464
- case 'ArrowLeft': {
465
- event.preventDefault();
466
- event.stopPropagation();
467
- const currentGroup = itemElement.closest('[role=group]');
468
- const prevGroup = this.getPreviousGroup(currentGroup);
469
- if (!prevGroup) {
470
- itemElement.tabIndex = -1;
471
- const menuTriggerId = itemElement.closest('[role="menu"][aria-labelledby]').getAttribute('aria-labelledby');
472
- const focusedItem = this.host.shadowRoot.getElementById(menuTriggerId);
473
- this.focusPreviousItem(focusedItem);
474
- break;
475
- }
476
- const prevGroupItems = (prevGroup.querySelectorAll('[role="menuitem"]') ?? []);
477
- moveFocus(itemElement, prevGroupItems[0]);
478
- break;
479
- }
480
- case 'Home':
481
- // Move to the first menu item
482
- event.preventDefault();
483
- event.stopPropagation();
484
- moveFocus(itemElement, items[0]);
485
- break;
486
- case 'End':
487
- // Move to the last menu item
488
- event.preventDefault();
489
- event.stopPropagation();
490
- moveFocus(itemElement, items[items.length - 1]);
491
- break;
492
- }
493
- }
494
- render() {
495
- if (this.isMobile) {
496
- return (index.h("zanit-mobile-menubar", { items: this.items, currentPath: this.currentPath, searchQuery: this.searchQuery, loading: this.loading }));
497
- }
498
- return (index.h("nav", { "aria-label": "Zanichelli.it" }, index.h("div", { class: "shadow-wrapper" }, index.h("div", { class: "width-limiter" }, index.h("ul", { class: "menubar", role: "menubar", "aria-label": "Zanichelli.it" }, this.loading &&
499
- [...new Array(4)].map((_, index$1) => (index.h(index.Fragment, null, index.h("li", { role: "none" }, index.h("div", { class: "menubar-item" }, index.h("z-ghost-loading", null))), index$1 < 3 && index.h("li", { role: "separator" })))), this.items?.map((item, index$1) => (index.h(index.Fragment, null, index.h("li", { role: "none" }, index.h("a", { class: {
500
- 'menubar-item': true,
501
- 'active': this.isActive(item),
502
- }, 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 }, index.h("span", { "data-text": item.label }, item.label), item.menuItems?.length > 0 && (index.h("z-icon", { name: this.openMenu === item.id ? 'chevron-up' : 'chevron-down', width: "0.875rem", height: "0.875rem" })))), index$1 < this.items?.length - 1 && index.h("li", { role: "separator" }))))), index.h("zanit-search-form", { searchQuery: this.searchQuery, onResetSearch: () => (this.searchQuery = undefined) })), this.items.map((item) => this.openMenu === item.id && (index.h(Menu, { controlledBy: item.id, items: item.menuItems, currentPath: this.currentPath, onItemKeyDown: (event) => this.handleMenuKeydown(event) })))), this.items
503
- ?.filter((item) => this.isActive(item))
504
- .map((item) => item.navbarItems?.length && (index.h("nav", { class: { 'sub-menubar': true, 'shadow-wrapper': true }, "aria-label": `Sezioni: ${item.label}` }, index.h("ul", { role: "menubar" }, item.navbarItems.map((subitem) => (index.h(index.Fragment, null, index.h("li", { role: "none" }, index.h("a", { class: {
505
- 'menubar-item': true,
506
- 'active': this.isActive(subitem),
507
- }, 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 }, index.h("span", null, subitem.label), subitem.menuItems?.length > 0 && (index.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 && (index.h(Menu, { controlledBy: subitem.id, items: subitem.menuItems, currentPath: this.currentPath, onItemKeyDown: (event) => this.handleMenuKeydown(event) }))))))));
508
- }
509
- static get delegatesFocus() { return true; }
510
- static get watchers() { return {
511
- "data": ["parseData"],
512
- "items": ["onItemsChange"],
513
- "current": ["onCurrentChange"]
514
- }; }
515
- };
516
- ZanitMenubar.style = menubarCss + menuCss$1;
517
-
518
- const mobileMenubarCss = ":host{position:relative;z-index:2;display:block;width:100%;max-width:100%;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}";
519
-
520
- 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}}";
521
-
522
- const ZanitMobileMenubar = class {
523
- constructor(hostRef) {
524
- index.registerInstance(this, hostRef);
525
- }
526
- get host() { return index.getElement(this); }
527
- /** IDs path of the current item. */
528
- currentPath = [];
529
- /** Menubar items. */
530
- items = [];
531
- /** Initial search query. */
532
- searchQuery = undefined;
533
- /** Whether the menubar is loading the data. */
534
- loading = false;
535
- /** Last active item ID. */
536
- lastCurrent = undefined;
537
- parentItem = undefined;
538
- menuItems = undefined;
539
- /** Whether the items to render come from a menubar or a menu. */
540
- menuType = undefined;
541
- open;
542
- onItemsChange() {
543
- this.lastCurrent = this.currentPath?.length ? this.currentPath[this.currentPath.length - 1] : undefined;
544
- this.setupData(this.items);
545
- }
546
- /**
547
- * Find the current item and take its parent, `menuItems` or the `navbarItems`.
548
- */
549
- setupData(items, parent) {
550
- // If no current item is defined, we show all items
551
- if (this.lastCurrent === undefined) {
552
- this.parentItem = undefined;
553
- this.menuType = 'menubar';
554
- this.menuItems = items;
555
- return;
556
- }
557
- for (const item of items) {
558
- if (item.id === this.lastCurrent) {
559
- this.parentItem = parent;
560
- this.menuType = item.menuItems?.length ? 'menu' : 'menubar';
561
- this.menuItems = item.menuItems || item.navbarItems;
562
- return;
563
- }
564
- if (this.currentPath.length > 1 &&
565
- item.id === this.currentPath[this.currentPath.length - 2] &&
566
- item.menuItems?.some(({ id }) => id === this.lastCurrent)) {
567
- this.parentItem = item;
568
- this.menuType = item.menuItems?.length ? 'menu' : 'menubar';
569
- this.menuItems = item.menuItems || item.navbarItems;
570
- return;
571
- }
572
- if (item.navbarItems?.length) {
573
- this.setupData(item.navbarItems, item);
574
- }
575
- }
576
- }
577
- get menuItemsElement() {
578
- return Array.from(this.host.shadowRoot.querySelectorAll('[role="menuitem"]'));
579
- }
580
- /** Initialize tabindex on menuitems, setting -1 to all but the first one. */
581
- initTabindex() {
582
- this.menuItemsElement.forEach((item, index) => item.setAttribute('tabindex', index === 0 ? '0' : '-1'));
583
- }
584
- toggleMenu() {
585
- if (this.open) {
586
- this.open = false;
587
- }
588
- else {
589
- this.open = true;
590
- setTimeout(() => {
591
- this.initTabindex();
592
- this.menuItemsElement[0]?.focus({ preventScroll: true });
593
- }, 200);
594
- }
595
- }
596
- /** Handles keyboard navigation on mobile menu. */
597
- handleItemKeydown(event) {
598
- switch (event.key) {
599
- case 'ArrowUp': {
600
- event.preventDefault();
601
- event.stopPropagation();
602
- const items = this.menuItemsElement;
603
- const currentIndex = items.indexOf(event.target);
604
- const prevItem = items[(currentIndex - 1 + items.length) % items.length];
605
- moveFocus(items[currentIndex], prevItem);
606
- break;
607
- }
608
- case 'ArrowDown': {
609
- event.preventDefault();
610
- event.stopPropagation();
611
- const items = this.menuItemsElement;
612
- const currentIndex = items.indexOf(event.target);
613
- const nextItem = items[(currentIndex + 1) % items.length];
614
- moveFocus(items[currentIndex], nextItem);
615
- break;
616
- }
617
- case 'Home': {
618
- event.preventDefault();
619
- event.stopPropagation();
620
- moveFocus(event.target, this.menuItemsElement[0]);
621
- break;
622
- }
623
- case 'End': {
624
- event.preventDefault();
625
- event.stopPropagation();
626
- moveFocus(event.target, this.menuItemsElement.pop());
627
- break;
628
- }
629
- }
630
- }
631
- connectedCallback() {
632
- this.lastCurrent = this.currentPath?.length ? this.currentPath[this.currentPath.length - 1] : undefined;
633
- this.setupData(this.items);
634
- }
635
- /** Close the menu when clicking outside. */
636
- handleOutsideClick(event) {
637
- if (containsTarget(this.host, event)) {
638
- return;
639
- }
640
- this.open = false;
641
- }
642
- /** Close the menu when pressing Escape or Tab. */
643
- handleKeydown(event) {
644
- switch (event.key) {
645
- case 'Escape':
646
- this.open = false;
647
- break;
648
- case 'Tab':
649
- if (containsTarget(this.host, event)) {
650
- break;
651
- }
652
- this.open = false;
653
- break;
654
- }
655
- }
656
- /** Close the menu when the focus goes out. */
657
- handleFocusout(event) {
658
- if (containsTarget(this.host, event)) {
659
- return;
660
- }
661
- this.open = false;
662
- }
663
- render() {
664
- return (index.h("nav", { key: '3c60ac4ac98ee3defb91d07ed2b877031f0a35df', "aria-label": "Zanichelli.it" }, index.h("button", { key: 'bebe58a827addf39e62deb9c3ef44296f14da700', 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() }, index.h("z-icon", { key: '0b3e97a6bcb3f54c1b0669f9fe012ac3ff5b5632', name: this.open ? 'multiply' : 'burger-menu', width: "1.5rem", height: "1.5rem" })), index.h("z-logo", { key: 'a7216fc628ab13b243ace77a89d5dc16bde1f6da', imageAlt: "Logo Zanichelli", link: "/", height: 32, width: 126 }), index.h("zanit-search-form", { key: 'bdfd612ecc8cf6fb7d4d1941474a8b6cc0b8ff2d', searchQuery: this.searchQuery, onResetSearch: () => (this.searchQuery = undefined) }), this.open && (index.h("ul", { key: 'bf3f32326a98ff6a47a3734ac98f8afda74f0d12', class: "mobile-menu", role: "menubar" }, !this.loading && this.currentPath && this.currentPath.length > 0 && (index.h("li", { key: 'a157937b4358cba0a1bc990576051f4a703cedd4', role: "none" }, index.h("a", { key: '9f36e81c276da144abf96e9e1dd7cf2a84bdc4b7', class: "parent", href: this.parentItem?.href ?? '/', id: this.parentItem?.id ?? undefined, role: "menuitem", tabIndex: -1, onKeyDown: (event) => this.handleItemKeydown(event), target: this.parentItem?.target }, index.h("z-icon", { key: 'ba4c4e1c0b1132cbcd4be7a4088bf1fb6618f062', name: "arrow-left", width: "0.5rem", height: "0.5rem" }), index.h("span", { key: 'cc30b285857d7cb7908e35dadf424e0940342949' }, this.parentItem?.label || 'Home')))), this.loading ? (index.h("div", { class: "items-container", role: "none" }, [...new Array(4)].map(() => (index.h("li", { role: "none" }, index.h("div", { class: "menubar-item", role: "none" }, index.h("z-ghost-loading", null))))))) : this.menuType === 'menu' ? (index.h(Menu, { items: this.menuItems, controlledBy: this.parentItem?.id, currentPath: this.currentPath, onItemKeyDown: (event) => this.handleItemKeydown(event) })) : (this.menuItems?.length > 0 && (index.h("div", { class: "items-container", role: "none" }, this.menuItems.map((item) => (index.h("li", { role: "none" }, index.h("a", { class: {
665
- 'menu-item': this.menuType === 'menu',
666
- 'menubar-item': this.menuType === 'menubar',
667
- }, href: item.href, id: item.id, role: "menuitem", "aria-current": this.lastCurrent === item.id ? 'page' : 'false', tabIndex: -1, onKeyDown: (event) => this.handleItemKeydown(event), target: item.target }, index.h("span", { "data-text": item.label }, item.label))))))))))));
668
- }
669
- static get delegatesFocus() { return true; }
670
- static get watchers() { return {
671
- "items": ["onItemsChange"],
672
- "currentPath": ["onItemsChange"]
673
- }; }
674
- };
675
- ZanitMobileMenubar.style = mobileMenubarCss + menuCss;
676
-
677
- const searchFormCss = ":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;top:0;right:0;display:flex;width:var(--closed-searchbar-width);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)}@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)}}@media (width >= 1152px){.searchbar{--closed-searchbar-width:190px}}@media (width >= 1366px){.searchbar .searchbar-button{border-right:1px solid #000}}";
678
-
679
- const ZanitSearchForm = class {
680
- constructor(hostRef) {
681
- index.registerInstance(this, hostRef);
682
- this.search = index.createEvent(this, "search");
683
- this.resetSearch = index.createEvent(this, "resetSearch");
684
- }
685
- formElement;
686
- get host() { return index.getElement(this); }
687
- /** Indicates whether the searchbar is visible and usable. */
688
- showSearchbar = false;
689
- /** Search query to apply. */
690
- _searchQuery = undefined;
691
- /** Initial search query */
692
- searchQuery = undefined;
693
- onSearchQueryChange() {
694
- this._searchQuery = this.searchQuery;
695
- if (this.searchQuery) {
696
- this.openSearchbar();
697
- }
698
- }
699
- /** Emitted on search form submission. */
700
- search;
701
- resetSearch;
702
- async connectedCallback() {
703
- this.showSearchbar = !!this.searchQuery;
704
- this._searchQuery = this.searchQuery;
705
- }
706
- /** Close open searchbar when clicking outside. */
707
- handleOutsideClick(event) {
708
- if (this.showSearchbar && this.formElement && !containsTarget(this.formElement, event)) {
709
- this.showSearchbar = false;
710
- }
711
- }
712
- /** Close the menu when pressing Escape or Tab. */
713
- handleKeydown(event) {
714
- switch (event.key) {
715
- case 'Escape':
716
- this.showSearchbar = false;
717
- break;
718
- case 'Tab':
719
- if (containsTarget(this.host, event)) {
720
- break;
721
- }
722
- this.showSearchbar = false;
723
- break;
724
- }
725
- }
726
- openSearchbar() {
727
- this.showSearchbar = true;
728
- setTimeout(() => {
729
- const searchbarInput = this.host.shadowRoot.querySelector('#searchbar-input');
730
- searchbarInput.focus({ preventScroll: true });
731
- }, 500);
732
- }
733
- resetSearchQuery() {
734
- this.searchQuery = undefined;
735
- this.resetSearch.emit();
736
- }
737
- handleInputChange(event) {
738
- this._searchQuery = event.target.value;
739
- if (!this._searchQuery) {
740
- this.searchQuery = undefined;
741
- }
742
- }
743
- onSearchSubmit(event) {
744
- event.preventDefault();
745
- if (!this._searchQuery) {
746
- return;
747
- }
748
- this.showSearchbar = false;
749
- const searchEv = this.search.emit({ query: this._searchQuery });
750
- // do not submit the form if the event default behavior was prevented
751
- if (searchEv.defaultPrevented) {
752
- return;
753
- }
754
- this.formElement.submit();
755
- }
756
- render() {
757
- return (index.h("form", { key: 'e1d177efbec2aea39cd30cfc8f02fe4e9f5e82d9', class: { 'searchbar': true, 'searchbar-open': this.showSearchbar }, ref: (el) => (this.formElement = el), role: "search", "aria-label": "Cerca nel sito", method: "get", action: "/ricerca", onSubmit: (event) => this.onSearchSubmit(event), onReset: () => this.resetSearchQuery() }, index.h("div", { key: '49aeaa97516d5782e1fcf866a5526ff19f8b0c14', class: "input-wrapper", role: "none" }, this.searchQuery && (index.h("button", { key: '61ec6636b5efd875bcf879b28894ffd1cf8ac802', type: "reset", "aria-label": "Svuota campo di ricerca", disabled: !this.showSearchbar, "aria-hidden": !this.showSearchbar ? 'true' : undefined, tabIndex: !this.showSearchbar ? -1 : 0 }, index.h("z-icon", { key: 'a896ac0e6ae2762e9d5dbb0351634505b519a684', name: "multiply-circled" }))), index.h("input", { key: '3ab6655ef669a6c30b5bbe547884c680284d7f14', id: "searchbar-input", name: "q", type: "search", disabled: !this.showSearchbar, placeholder: "Cerca per parola chiave o ISBN", onInput: (event) => this.handleInputChange(event), value: this.searchQuery, required: true, "aria-label": "Cerca per parola chiave o ISBN", "aria-hidden": !this.showSearchbar ? 'true' : undefined, tabIndex: !this.showSearchbar ? -1 : 0 })), index.h("button", { key: '3df725da35664493fe70a15ea39184ab00b37e32', 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 : index.h("span", { class: "searchbar-button-label" }, "Cerca"), index.h("z-icon", { key: '8f6cfd25fbacbc04b7bc060470667eb9b2a45179', name: "search" }))));
758
- }
759
- static get watchers() { return {
760
- "searchQuery": ["onSearchQueryChange"]
761
- }; }
762
- };
763
- ZanitSearchForm.style = searchFormCss;
764
-
765
- exports.zanit_back_to_top = ZanitBackTop;
766
- exports.zanit_menubar = ZanitMenubar;
767
- exports.zanit_mobile_menubar = ZanitMobileMenubar;
768
- exports.zanit_search_form = ZanitSearchForm;
769
- //# sourceMappingURL=zanit-back-to-top.zanit-menubar.zanit-mobile-menubar.zanit-search-form.entry.cjs.js.map
770
-
771
- //# sourceMappingURL=zanit-back-to-top_4.cjs.entry.js.map