@swisspost/internet-header 1.12.0 → 1.12.1

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 (226) hide show
  1. package/dist/cjs/index.cjs.js +0 -36
  2. package/dist/cjs/index.cjs.js.map +1 -1
  3. package/dist/cjs/post-klp-login-widget.cjs.entry.js +56 -6
  4. package/dist/cjs/post-klp-login-widget.cjs.entry.js.map +1 -1
  5. package/dist/cjs/post-language-switch.cjs.entry.js +99 -8
  6. package/dist/cjs/post-language-switch.cjs.entry.js.map +1 -1
  7. package/dist/cjs/post-logo.cjs.entry.js +18 -4
  8. package/dist/cjs/post-logo.cjs.entry.js.map +1 -1
  9. package/dist/cjs/post-main-navigation.cjs.entry.js +233 -9
  10. package/dist/cjs/post-main-navigation.cjs.entry.js.map +1 -1
  11. package/dist/cjs/post-meta-navigation.cjs.entry.js +19 -4
  12. package/dist/cjs/post-meta-navigation.cjs.entry.js.map +1 -1
  13. package/dist/cjs/post-search.cjs.entry.js +590 -11
  14. package/dist/cjs/post-search.cjs.entry.js.map +1 -1
  15. package/dist/cjs/post-skiplinks.cjs.entry.js +45 -6
  16. package/dist/cjs/post-skiplinks.cjs.entry.js.map +1 -1
  17. package/dist/cjs/swisspost-internet-breadcrumbs.cjs.entry.js +3609 -11
  18. package/dist/cjs/swisspost-internet-breadcrumbs.cjs.entry.js.map +1 -1
  19. package/dist/cjs/swisspost-internet-footer.cjs.entry.js +154 -6
  20. package/dist/cjs/swisspost-internet-footer.cjs.entry.js.map +1 -1
  21. package/dist/cjs/swisspost-internet-header.cjs.entry.js +824 -10
  22. package/dist/cjs/swisspost-internet-header.cjs.entry.js.map +1 -1
  23. package/dist/collection/collection-manifest.json +4 -4
  24. package/dist/collection/index.js +1 -11
  25. package/dist/collection/index.js.map +1 -1
  26. package/dist/components/index.js +0 -10
  27. package/dist/components/index.js.map +1 -1
  28. package/dist/components/swisspost-internet-breadcrumbs.js +1 -1
  29. package/dist/components/swisspost-internet-footer.js +1 -1
  30. package/dist/components/swisspost-internet-header.js +10 -7
  31. package/dist/components/swisspost-internet-header.js.map +1 -1
  32. package/dist/docs.json +11 -11
  33. package/dist/esm/index.js +1 -21
  34. package/dist/esm/index.js.map +1 -1
  35. package/dist/esm/post-klp-login-widget.entry.js +59 -5
  36. package/dist/esm/post-klp-login-widget.entry.js.map +1 -1
  37. package/dist/esm/post-language-switch.entry.js +102 -7
  38. package/dist/esm/post-language-switch.entry.js.map +1 -1
  39. package/dist/esm/post-logo.entry.js +21 -3
  40. package/dist/esm/post-logo.entry.js.map +1 -1
  41. package/dist/esm/post-main-navigation.entry.js +236 -8
  42. package/dist/esm/post-main-navigation.entry.js.map +1 -1
  43. package/dist/esm/post-meta-navigation.entry.js +22 -3
  44. package/dist/esm/post-meta-navigation.entry.js.map +1 -1
  45. package/dist/esm/post-search.entry.js +593 -10
  46. package/dist/esm/post-search.entry.js.map +1 -1
  47. package/dist/esm/post-skiplinks.entry.js +48 -5
  48. package/dist/esm/post-skiplinks.entry.js.map +1 -1
  49. package/dist/esm/swisspost-internet-breadcrumbs.entry.js +3612 -10
  50. package/dist/esm/swisspost-internet-breadcrumbs.entry.js.map +1 -1
  51. package/dist/esm/swisspost-internet-footer.entry.js +157 -5
  52. package/dist/esm/swisspost-internet-footer.entry.js.map +1 -1
  53. package/dist/esm/swisspost-internet-header.entry.js +827 -9
  54. package/dist/esm/swisspost-internet-header.entry.js.map +1 -1
  55. package/dist/esm-es5/index.js +1 -1
  56. package/dist/esm-es5/post-klp-login-widget.entry.js +1 -1
  57. package/dist/esm-es5/post-klp-login-widget.entry.js.map +1 -1
  58. package/dist/esm-es5/post-language-switch.entry.js +1 -1
  59. package/dist/esm-es5/post-language-switch.entry.js.map +1 -1
  60. package/dist/esm-es5/post-logo.entry.js +1 -1
  61. package/dist/esm-es5/post-logo.entry.js.map +1 -1
  62. package/dist/esm-es5/post-main-navigation.entry.js +1 -1
  63. package/dist/esm-es5/post-main-navigation.entry.js.map +1 -1
  64. package/dist/esm-es5/post-meta-navigation.entry.js +1 -1
  65. package/dist/esm-es5/post-meta-navigation.entry.js.map +1 -1
  66. package/dist/esm-es5/post-search.entry.js +1 -1
  67. package/dist/esm-es5/post-search.entry.js.map +1 -1
  68. package/dist/esm-es5/post-skiplinks.entry.js +1 -1
  69. package/dist/esm-es5/post-skiplinks.entry.js.map +1 -1
  70. package/dist/esm-es5/swisspost-internet-breadcrumbs.entry.js +6 -1
  71. package/dist/esm-es5/swisspost-internet-breadcrumbs.entry.js.map +1 -1
  72. package/dist/esm-es5/swisspost-internet-footer.entry.js +1 -1
  73. package/dist/esm-es5/swisspost-internet-footer.entry.js.map +1 -1
  74. package/dist/esm-es5/swisspost-internet-header.entry.js +1 -1
  75. package/dist/esm-es5/swisspost-internet-header.entry.js.map +1 -1
  76. package/dist/swisspost-internet-header/index.esm.js +1 -1
  77. package/dist/swisspost-internet-header/{p-05eea2be.js → p-04b1cab7.entry.js} +2 -2
  78. package/dist/swisspost-internet-header/{p-c8d9cc8c.js → p-069dbe32.entry.js} +2 -2
  79. package/dist/swisspost-internet-header/{p-61528220.js → p-21d8e5bc.entry.js} +2 -2
  80. package/dist/swisspost-internet-header/{p-aab6679b.js → p-2e334cfc.entry.js} +2 -2
  81. package/dist/swisspost-internet-header/{p-c7945779.system.js → p-50da051d.system.entry.js} +2 -2
  82. package/dist/swisspost-internet-header/{p-c7945779.system.js.map → p-50da051d.system.entry.js.map} +1 -1
  83. package/dist/swisspost-internet-header/p-50ea2036.system.js +2 -0
  84. package/dist/swisspost-internet-header/p-5adcdd91.system.js +1 -1
  85. package/dist/swisspost-internet-header/{p-96618f42.system.js → p-5ec6e2de.system.entry.js} +2 -2
  86. package/dist/swisspost-internet-header/{p-96618f42.system.js.map → p-5ec6e2de.system.entry.js.map} +1 -1
  87. package/dist/swisspost-internet-header/{p-78e8a405.js → p-61074cb4.entry.js} +2 -2
  88. package/dist/swisspost-internet-header/{p-2fb1a3ce.system.js → p-62ae68ad.system.entry.js} +2 -2
  89. package/dist/swisspost-internet-header/{p-2fb1a3ce.system.js.map → p-62ae68ad.system.entry.js.map} +1 -1
  90. package/dist/swisspost-internet-header/{p-fc2417e7.system.js → p-64b3fabe.system.entry.js} +2 -2
  91. package/dist/swisspost-internet-header/{p-fc2417e7.system.js.map → p-64b3fabe.system.entry.js.map} +1 -1
  92. package/dist/swisspost-internet-header/p-65cd41a6.system.entry.js +2 -0
  93. package/dist/swisspost-internet-header/{p-771114f0.system.js.map → p-65cd41a6.system.entry.js.map} +1 -1
  94. package/dist/swisspost-internet-header/{p-f2f69ff4.system.js → p-6b18b251.system.entry.js} +2 -2
  95. package/dist/swisspost-internet-header/{p-f2f69ff4.system.js.map → p-6b18b251.system.entry.js.map} +1 -1
  96. package/dist/swisspost-internet-header/{p-e187ba33.js → p-76e3cd9c.entry.js} +2 -2
  97. package/dist/swisspost-internet-header/{p-ee5e0cc6.system.js → p-9acc06ba.system.entry.js} +2 -2
  98. package/dist/swisspost-internet-header/{p-ee5e0cc6.system.js.map → p-9acc06ba.system.entry.js.map} +1 -1
  99. package/dist/swisspost-internet-header/{p-7a94a2d7.system.js → p-9d827167.system.entry.js} +2 -2
  100. package/dist/swisspost-internet-header/{p-7a94a2d7.system.js.map → p-9d827167.system.entry.js.map} +1 -1
  101. package/dist/swisspost-internet-header/{p-56764f7d.system.js → p-a097e677.system.entry.js} +2 -2
  102. package/dist/swisspost-internet-header/{p-56764f7d.system.js.map → p-a097e677.system.entry.js.map} +1 -1
  103. package/dist/swisspost-internet-header/p-b3ad4f8a.entry.js +2 -0
  104. package/dist/swisspost-internet-header/{p-f5876cc8.js.map → p-b3ad4f8a.entry.js.map} +1 -1
  105. package/dist/swisspost-internet-header/{p-70df9137.js → p-b8368eca.entry.js} +2 -2
  106. package/dist/swisspost-internet-header/p-c201f1b3.system.entry.js +2 -0
  107. package/dist/swisspost-internet-header/{p-18e9ce89.system.js.map → p-c201f1b3.system.entry.js.map} +1 -1
  108. package/dist/swisspost-internet-header/{p-dee824b8.js → p-d2fd2ff6.entry.js} +2 -2
  109. package/dist/swisspost-internet-header/{p-0096509c.js → p-f5a1e4a6.entry.js} +2 -2
  110. package/dist/swisspost-internet-header/swisspost-internet-header.esm.js +1 -1
  111. package/dist/types/index.d.ts +0 -10
  112. package/package.json +8 -6
  113. package/dist/cjs/post-internet-breadcrumbs-09754c05.js +0 -3616
  114. package/dist/cjs/post-internet-breadcrumbs-09754c05.js.map +0 -1
  115. package/dist/cjs/post-internet-footer-b51276d8.js +0 -161
  116. package/dist/cjs/post-internet-footer-b51276d8.js.map +0 -1
  117. package/dist/cjs/post-internet-header-5962d752.js +0 -828
  118. package/dist/cjs/post-internet-header-5962d752.js.map +0 -1
  119. package/dist/cjs/post-klp-login-widget-d03de512.js +0 -63
  120. package/dist/cjs/post-klp-login-widget-d03de512.js.map +0 -1
  121. package/dist/cjs/post-language-switch-9cd31034.js +0 -106
  122. package/dist/cjs/post-language-switch-9cd31034.js.map +0 -1
  123. package/dist/cjs/post-logo-5867ad55.js +0 -25
  124. package/dist/cjs/post-logo-5867ad55.js.map +0 -1
  125. package/dist/cjs/post-main-navigation-ab81aac6.js +0 -240
  126. package/dist/cjs/post-main-navigation-ab81aac6.js.map +0 -1
  127. package/dist/cjs/post-meta-navigation-0b73779f.js +0 -26
  128. package/dist/cjs/post-meta-navigation-0b73779f.js.map +0 -1
  129. package/dist/cjs/post-search-2232c291.js +0 -597
  130. package/dist/cjs/post-search-2232c291.js.map +0 -1
  131. package/dist/cjs/post-skiplinks-3db1d214.js +0 -52
  132. package/dist/cjs/post-skiplinks-3db1d214.js.map +0 -1
  133. package/dist/esm/post-internet-breadcrumbs-474f625e.js +0 -3614
  134. package/dist/esm/post-internet-breadcrumbs-474f625e.js.map +0 -1
  135. package/dist/esm/post-internet-footer-273b0d8d.js +0 -159
  136. package/dist/esm/post-internet-footer-273b0d8d.js.map +0 -1
  137. package/dist/esm/post-internet-header-a825bfd6.js +0 -826
  138. package/dist/esm/post-internet-header-a825bfd6.js.map +0 -1
  139. package/dist/esm/post-klp-login-widget-b1306336.js +0 -61
  140. package/dist/esm/post-klp-login-widget-b1306336.js.map +0 -1
  141. package/dist/esm/post-language-switch-fd570b9d.js +0 -104
  142. package/dist/esm/post-language-switch-fd570b9d.js.map +0 -1
  143. package/dist/esm/post-logo-cde3c44d.js +0 -23
  144. package/dist/esm/post-logo-cde3c44d.js.map +0 -1
  145. package/dist/esm/post-main-navigation-12eaef9f.js +0 -238
  146. package/dist/esm/post-main-navigation-12eaef9f.js.map +0 -1
  147. package/dist/esm/post-meta-navigation-09e9bdc8.js +0 -24
  148. package/dist/esm/post-meta-navigation-09e9bdc8.js.map +0 -1
  149. package/dist/esm/post-search-5c3a10ac.js +0 -595
  150. package/dist/esm/post-search-5c3a10ac.js.map +0 -1
  151. package/dist/esm/post-skiplinks-b3c32a77.js +0 -50
  152. package/dist/esm/post-skiplinks-b3c32a77.js.map +0 -1
  153. package/dist/esm-es5/post-internet-breadcrumbs-474f625e.js +0 -7
  154. package/dist/esm-es5/post-internet-breadcrumbs-474f625e.js.map +0 -1
  155. package/dist/esm-es5/post-internet-footer-273b0d8d.js +0 -2
  156. package/dist/esm-es5/post-internet-footer-273b0d8d.js.map +0 -1
  157. package/dist/esm-es5/post-internet-header-a825bfd6.js +0 -2
  158. package/dist/esm-es5/post-internet-header-a825bfd6.js.map +0 -1
  159. package/dist/esm-es5/post-klp-login-widget-b1306336.js +0 -2
  160. package/dist/esm-es5/post-klp-login-widget-b1306336.js.map +0 -1
  161. package/dist/esm-es5/post-language-switch-fd570b9d.js +0 -2
  162. package/dist/esm-es5/post-language-switch-fd570b9d.js.map +0 -1
  163. package/dist/esm-es5/post-logo-cde3c44d.js +0 -2
  164. package/dist/esm-es5/post-logo-cde3c44d.js.map +0 -1
  165. package/dist/esm-es5/post-main-navigation-12eaef9f.js +0 -2
  166. package/dist/esm-es5/post-main-navigation-12eaef9f.js.map +0 -1
  167. package/dist/esm-es5/post-meta-navigation-09e9bdc8.js +0 -2
  168. package/dist/esm-es5/post-meta-navigation-09e9bdc8.js.map +0 -1
  169. package/dist/esm-es5/post-search-5c3a10ac.js +0 -2
  170. package/dist/esm-es5/post-search-5c3a10ac.js.map +0 -1
  171. package/dist/esm-es5/post-skiplinks-b3c32a77.js +0 -2
  172. package/dist/esm-es5/post-skiplinks-b3c32a77.js.map +0 -1
  173. package/dist/swisspost-internet-header/p-0d61ca4e.system.entry.js +0 -2
  174. package/dist/swisspost-internet-header/p-18e9ce89.system.js +0 -2
  175. package/dist/swisspost-internet-header/p-1a9fcba5.entry.js +0 -2
  176. package/dist/swisspost-internet-header/p-1a9fcba5.entry.js.map +0 -1
  177. package/dist/swisspost-internet-header/p-237a408c.entry.js +0 -2
  178. package/dist/swisspost-internet-header/p-237a408c.entry.js.map +0 -1
  179. package/dist/swisspost-internet-header/p-2eb179a7.entry.js +0 -2
  180. package/dist/swisspost-internet-header/p-2eb179a7.entry.js.map +0 -1
  181. package/dist/swisspost-internet-header/p-3672587a.entry.js +0 -2
  182. package/dist/swisspost-internet-header/p-3672587a.entry.js.map +0 -1
  183. package/dist/swisspost-internet-header/p-39785e3d.system.entry.js +0 -2
  184. package/dist/swisspost-internet-header/p-39785e3d.system.entry.js.map +0 -1
  185. package/dist/swisspost-internet-header/p-4248f499.system.entry.js +0 -2
  186. package/dist/swisspost-internet-header/p-4248f499.system.entry.js.map +0 -1
  187. package/dist/swisspost-internet-header/p-6145b5f1.system.js +0 -2
  188. package/dist/swisspost-internet-header/p-6145b5f1.system.js.map +0 -1
  189. package/dist/swisspost-internet-header/p-65ce36ba.entry.js +0 -2
  190. package/dist/swisspost-internet-header/p-65ce36ba.entry.js.map +0 -1
  191. package/dist/swisspost-internet-header/p-771114f0.system.js +0 -2
  192. package/dist/swisspost-internet-header/p-7e78b029.system.entry.js +0 -2
  193. package/dist/swisspost-internet-header/p-7e78b029.system.entry.js.map +0 -1
  194. package/dist/swisspost-internet-header/p-8ddbca59.system.entry.js +0 -2
  195. package/dist/swisspost-internet-header/p-8ddbca59.system.entry.js.map +0 -1
  196. package/dist/swisspost-internet-header/p-a0f5c014.system.entry.js +0 -2
  197. package/dist/swisspost-internet-header/p-a0f5c014.system.entry.js.map +0 -1
  198. package/dist/swisspost-internet-header/p-a290e3e2.system.entry.js +0 -2
  199. package/dist/swisspost-internet-header/p-a290e3e2.system.entry.js.map +0 -1
  200. package/dist/swisspost-internet-header/p-a58fc500.system.entry.js +0 -2
  201. package/dist/swisspost-internet-header/p-a58fc500.system.entry.js.map +0 -1
  202. package/dist/swisspost-internet-header/p-aeaa2c26.entry.js +0 -2
  203. package/dist/swisspost-internet-header/p-aeaa2c26.entry.js.map +0 -1
  204. package/dist/swisspost-internet-header/p-c4011fc6.system.entry.js +0 -2
  205. package/dist/swisspost-internet-header/p-c4011fc6.system.entry.js.map +0 -1
  206. package/dist/swisspost-internet-header/p-c99a43b0.entry.js +0 -2
  207. package/dist/swisspost-internet-header/p-c99a43b0.entry.js.map +0 -1
  208. package/dist/swisspost-internet-header/p-d9f67b45.entry.js +0 -2
  209. package/dist/swisspost-internet-header/p-d9f67b45.entry.js.map +0 -1
  210. package/dist/swisspost-internet-header/p-de27fab4.entry.js +0 -2
  211. package/dist/swisspost-internet-header/p-de27fab4.entry.js.map +0 -1
  212. package/dist/swisspost-internet-header/p-f25c234f.entry.js +0 -2
  213. package/dist/swisspost-internet-header/p-f25c234f.entry.js.map +0 -1
  214. package/dist/swisspost-internet-header/p-f5876cc8.js +0 -2
  215. package/dist/swisspost-internet-header/p-fef30370.system.entry.js +0 -2
  216. package/dist/swisspost-internet-header/p-fef30370.system.entry.js.map +0 -1
  217. /package/dist/swisspost-internet-header/{p-05eea2be.js.map → p-04b1cab7.entry.js.map} +0 -0
  218. /package/dist/swisspost-internet-header/{p-c8d9cc8c.js.map → p-069dbe32.entry.js.map} +0 -0
  219. /package/dist/swisspost-internet-header/{p-61528220.js.map → p-21d8e5bc.entry.js.map} +0 -0
  220. /package/dist/swisspost-internet-header/{p-aab6679b.js.map → p-2e334cfc.entry.js.map} +0 -0
  221. /package/dist/swisspost-internet-header/{p-0d61ca4e.system.entry.js.map → p-50ea2036.system.js.map} +0 -0
  222. /package/dist/swisspost-internet-header/{p-78e8a405.js.map → p-61074cb4.entry.js.map} +0 -0
  223. /package/dist/swisspost-internet-header/{p-e187ba33.js.map → p-76e3cd9c.entry.js.map} +0 -0
  224. /package/dist/swisspost-internet-header/{p-70df9137.js.map → p-b8368eca.entry.js.map} +0 -0
  225. /package/dist/swisspost-internet-header/{p-dee824b8.js.map → p-d2fd2ff6.entry.js.map} +0 -0
  226. /package/dist/swisspost-internet-header/{p-0096509c.js.map → p-f5a1e4a6.entry.js.map} +0 -0
@@ -2,18 +2,832 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- const postInternetHeader = require('./post-internet-header-5962d752.js');
6
- require('./index-4bd0adf1.js');
7
- require('./index-3216e4c8.js');
8
- require('./language.service-dbe2a435.js');
9
- require('./store-77668e50.js');
10
- require('./utils-717975e0.js');
11
- require('./svg-sprite.component-4b5677ef.js');
12
- require('./svg-icon.component-5965f301.js');
13
- require('./if.component-2cd3c1ff.js');
5
+ const index$1 = require('./index-4bd0adf1.js');
6
+ const index = require('./index-3216e4c8.js');
7
+ const language_service = require('./language.service-dbe2a435.js');
8
+ const utils = require('./utils-717975e0.js');
9
+ const store = require('./store-77668e50.js');
10
+ const svgSprite_component = require('./svg-sprite.component-4b5677ef.js');
11
+ const svgIcon_component = require('./svg-icon.component-5965f301.js');
12
+ const if_component = require('./if.component-2cd3c1ff.js');
14
13
 
14
+ /**
15
+ * Activate the current route based on the config and the match mode
16
+ * @param config Main Navigation Config
17
+ * @param activeRouteProp Match mode
18
+ * @returns Modified Main Navigation Config
19
+ */
20
+ const markActiveRoute = (config, activeRouteProp) => {
21
+ // Don't highlight any route
22
+ if (activeRouteProp === false) {
23
+ return config;
24
+ }
25
+ // Set compare URL and check if activeRouteProp is valid
26
+ let compareUrl;
27
+ config = resetOverrideConfig(config);
28
+ if (activeRouteProp === 'auto' || activeRouteProp === 'exact') {
29
+ // Check if an active route is already configured, set override to that and return
30
+ if (hasActivePortalRoute(config)) {
31
+ return resetActiveStateToPortalConfig(config);
32
+ }
33
+ compareUrl = new URL(window.location.href);
34
+ }
35
+ else {
36
+ try {
37
+ compareUrl = new URL(activeRouteProp, document.location.origin);
38
+ }
39
+ catch (error) {
40
+ console.warn(`Active Route: ${activeRouteProp} is not a valid URL. Navigation highlighting has been disabled.`);
41
+ return config;
42
+ }
43
+ }
44
+ const scoreList = compileScoreList(config, compareUrl, activeRouteProp);
45
+ if (scoreList.length === 0) {
46
+ // No match found or already active links defined
47
+ return config;
48
+ }
49
+ const winnerPair = scoreList[0];
50
+ winnerPair.main.isActiveOverride = true;
51
+ if (winnerPair.sub)
52
+ winnerPair.sub.isActiveOverride = true;
53
+ return config;
54
+ };
55
+ /**
56
+ * Check if the portal config set any active route
57
+ * @param config Main navigation config
58
+ * @returns True if portal set any route as active
59
+ */
60
+ const hasActivePortalRoute = (config) => {
61
+ return config.filter(nav => nav.isActive).length > 0;
62
+ };
63
+ const resetActiveStateToPortalConfig = (config) => {
64
+ return config.map(nav => (Object.assign(Object.assign({}, nav), { isActiveOverride: nav.isActive, flyout: nav.flyout.map(flyout => (Object.assign(Object.assign({}, flyout), { linkList: flyout.linkList.map(link => (Object.assign(Object.assign({}, link), { isActiveOverride: link.isActive }))) }))) })));
65
+ };
66
+ const resetOverrideConfig = (config) => {
67
+ return config.map(nav => (Object.assign(Object.assign({}, nav), { isActiveOverride: false, flyout: nav.flyout.map(flyout => (Object.assign(Object.assign({}, flyout), { linkList: flyout.linkList.map(link => (Object.assign(Object.assign({}, link), { isActiveOverride: false }))) }))) })));
68
+ };
69
+ /**
70
+ * Compile a list of scores based on the map mode, sorted in descending order
71
+ * @param config Main Nav Config
72
+ * @param compareUrl Current Browser URL or a custom URL
73
+ * @param activeRouteProp Match mode
74
+ * @returns A list of scored URLs if any matched
75
+ */
76
+ const compileScoreList = (config, compareUrl, activeRouteProp) => {
77
+ // Flag to check if the Portal set any active links or if there are any exact matches
78
+ let hadAnyActiveLink = false;
79
+ const scoreList = [];
80
+ config
81
+ .filter(mainNav => !hadAnyActiveLink && mainNav)
82
+ .forEach(mainNav => {
83
+ try {
84
+ const score = compareRoutes(compareUrl, new URL(mainNav.url), activeRouteProp);
85
+ hadAnyActiveLink = updateScoreList(scoreList, score, { main: mainNav, score }, hadAnyActiveLink);
86
+ }
87
+ catch (_a) {
88
+ // Not a valid url, continue
89
+ }
90
+ // Loop through flyout links 2nd level
91
+ mainNav.flyout.forEach(flyout => {
92
+ var _a;
93
+ (_a = flyout.linkList) === null || _a === void 0 ? void 0 : _a.forEach(linklist => {
94
+ // Don't override if any link is already active
95
+ if (linklist.isActive && (activeRouteProp === 'auto' || activeRouteProp === 'exact')) {
96
+ hadAnyActiveLink = true;
97
+ return;
98
+ }
99
+ try {
100
+ const url = new URL(linklist.url);
101
+ const score = compareRoutes(compareUrl, url, activeRouteProp);
102
+ hadAnyActiveLink = updateScoreList(scoreList, score, { main: mainNav, sub: linklist, score }, hadAnyActiveLink);
103
+ }
104
+ catch (_a) {
105
+ // Not a valid URL, continue
106
+ }
107
+ });
108
+ });
109
+ });
110
+ return scoreList.sort((a, b) => b.score - a.score);
111
+ };
112
+ /**
113
+ * Update score list
114
+ */
115
+ function updateScoreList(scoreList, score, scoreListItem, hadAnyActiveLink) {
116
+ let hadActiveLink = hadAnyActiveLink;
117
+ if (score > 0) {
118
+ if (score === Infinity)
119
+ hadActiveLink = true;
120
+ // Push score
121
+ scoreList.push(scoreListItem);
122
+ }
123
+ return hadActiveLink;
124
+ }
125
+ /**
126
+ * Compare two URLs for similarity based on a match mode
127
+ * @param baseUrl Browser URL
128
+ * @param compareUrl Navigatgion URL
129
+ * @param matchMode exact or auto matching
130
+ * @returns Score
131
+ */
132
+ const compareRoutes = (baseUrl, compareUrl, matchMode) => {
133
+ // One url is not defined or they don't share the same orign
134
+ if (baseUrl === null || compareUrl === null || baseUrl.origin !== compareUrl.origin) {
135
+ return 0;
136
+ }
137
+ const baseUrlPath = baseUrl.pathname.toLocaleLowerCase();
138
+ const compareUrlPath = compareUrl.pathname.toLocaleLowerCase();
139
+ // Exact match, origin and pathname are the same
140
+ if (baseUrlPath === compareUrlPath) {
141
+ return Infinity;
142
+ }
143
+ // The basepath is longer than the comparison, a match is impossible
144
+ if (baseUrl.pathname.length < compareUrl.pathname.length) {
145
+ return 0;
146
+ }
147
+ if (matchMode === 'auto') {
148
+ const baseSegments = [
149
+ baseUrl.origin.toLocaleLowerCase(),
150
+ ...baseUrlPath.split('/').filter(x => x !== null && x !== ''),
151
+ ];
152
+ const compareSegments = [
153
+ compareUrl.origin.toLocaleLowerCase(),
154
+ ...compareUrlPath.split('/').filter(x => x !== null && x !== ''),
155
+ ];
156
+ const score = getSimilarityScore(baseSegments, compareSegments);
157
+ // If only some segments match, but not the whole smaller array, it's not a match
158
+ return Math.min(baseSegments.length, compareSegments.length) === score ? score : 0;
159
+ }
160
+ return 0;
161
+ };
162
+ /**
163
+ * Check how many items in an array match
164
+ * @param a Base array
165
+ * @param b Compare array
166
+ * @returns Score
167
+ */
168
+ const getSimilarityScore = (a, b) => {
169
+ if (a == null || b == null || a.length === 0 || b.length === 0) {
170
+ return 0;
171
+ }
172
+ let i = 0;
173
+ for (; i < Math.min(a.length, b.length); i++) {
174
+ if (a[i] !== b[i]) {
175
+ return 0;
176
+ }
177
+ }
178
+ return i;
179
+ };
15
180
 
181
+ // Prevent double requests
182
+ let request = null;
183
+ // Cache the original os flyout to use it for updates
184
+ let osFlyoutCache = null;
185
+ const getPPMConfig = () => {
186
+ const ppmConfigScript = document.querySelector('#PPM_HEADER_DATA');
187
+ if ((ppmConfigScript === null || ppmConfigScript === void 0 ? void 0 : ppmConfigScript.textContent) != null) {
188
+ return JSON.parse(ppmConfigScript.textContent);
189
+ }
190
+ return null;
191
+ };
192
+ /**
193
+ * Get a localized config object
194
+ *
195
+ * @param projectId String identifying the project
196
+ * @param language [optional] Preferred language
197
+ * @returns Localized config object
198
+ */
199
+ const getLocalizedConfig = async ({ projectId, environment, language, cookieKey, localStorageKey, activeRouteProp, localizedCustomConfig, osFlyoutOverrides, }) => {
200
+ var _a, _b;
201
+ const ppmConfig = getPPMConfig();
202
+ let localizedConfig;
203
+ let config = null;
204
+ let lang;
205
+ if (ppmConfig) {
206
+ localizedConfig = ppmConfig;
207
+ lang = document.documentElement.lang;
208
+ }
209
+ else {
210
+ if (request == null) {
211
+ request = fetchConfig(projectId, environment);
212
+ }
213
+ config = await request;
214
+ lang = language_service.getUserLang(Object.keys(config), language, localStorageKey, cookieKey);
215
+ if (lang === undefined) {
216
+ throw new Error('Internet Header: unable to determine current language');
217
+ }
218
+ // Clone config for more predictable state updates
219
+ localizedConfig = Object.assign({}, config[lang]);
220
+ }
221
+ // Merge custom config with portal config
222
+ if (localizedCustomConfig) {
223
+ const header = ((_a = localizedCustomConfig === null || localizedCustomConfig === void 0 ? void 0 : localizedCustomConfig.header) === null || _a === void 0 ? void 0 : _a.navMain)
224
+ ? Object.assign(Object.assign({}, localizedConfig.header), { navMain: [...localizedConfig.header.navMain, ...localizedCustomConfig.header.navMain] }) : localizedConfig.header;
225
+ localizedConfig = Object.assign(Object.assign({}, localizedConfig), { header });
226
+ }
227
+ // Add entries to flyout_os
228
+ if (osFlyoutOverrides)
229
+ localizedConfig.header.navMain = mergeOsFlyoutOverrides(localizedConfig, osFlyoutOverrides);
230
+ // Mark active route
231
+ if (activeRouteProp != null)
232
+ localizedConfig.header.navMain = markActiveRoute(localizedConfig.header.navMain, activeRouteProp);
233
+ setMainNavigationIds((_b = localizedConfig === null || localizedConfig === void 0 ? void 0 : localizedConfig.header) === null || _b === void 0 ? void 0 : _b.navMain);
234
+ // Set the new language choice
235
+ language_service.persistLanguageChoice(lang, cookieKey, localStorageKey);
236
+ return localizedConfig;
237
+ };
238
+ /**
239
+ * Merge portal config with custom os flyout overrides
240
+ * @param config Localized config
241
+ * @param osFlyoutOverrides Overrides for the flyout
242
+ * @returns Merged localized config
243
+ */
244
+ const mergeOsFlyoutOverrides = (config, osFlyoutOverrides) => {
245
+ if (osFlyoutOverrides == null)
246
+ return config.header.navMain;
247
+ return config.header.navMain.map(mainNav => {
248
+ var _a, _b;
249
+ if (mainNav.id !== 'flyout_os')
250
+ return mainNav;
251
+ if (osFlyoutCache === null) {
252
+ osFlyoutCache = JSON.parse(JSON.stringify(mainNav));
253
+ }
254
+ const mainNavText = (_a = osFlyoutOverrides.text) !== null && _a !== void 0 ? _a : osFlyoutCache.text;
255
+ const mainNavTitle = (_b = osFlyoutOverrides.title) !== null && _b !== void 0 ? _b : osFlyoutCache.title;
256
+ if (osFlyoutCache.flyout == null ||
257
+ osFlyoutCache.flyout.length === 0 ||
258
+ osFlyoutOverrides.flyout == null ||
259
+ osFlyoutOverrides.flyout.length === 0)
260
+ return Object.assign(Object.assign({}, mainNav), { title: mainNavTitle, text: mainNavText });
261
+ // Add entries for os flyout columns without overriding existing config
262
+ const mainNavFlyout = [
263
+ ...osFlyoutCache.flyout.map((col, index) => {
264
+ var _a;
265
+ const overrides = osFlyoutOverrides.flyout[index];
266
+ const title = (_a = overrides.title) !== null && _a !== void 0 ? _a : col.title;
267
+ const linkList = overrides.linkList != null ? osFlyoutOverrides.flyout[index].linkList : [];
268
+ return {
269
+ title,
270
+ linkList: [...col.linkList, ...linkList],
271
+ };
272
+ }),
273
+ ...osFlyoutOverrides.flyout.slice(osFlyoutCache.flyout.length),
274
+ ];
275
+ return Object.assign(Object.assign({}, mainNav), { text: mainNavText, title: mainNavTitle, flyout: mainNavFlyout });
276
+ });
277
+ };
278
+ /**
279
+ * Fetch the general config based on project id
280
+ *
281
+ * @returns Promise for Post Portal general config
282
+ */
283
+ const fetchConfig = async (projectId, environment) => {
284
+ // Check if project id is sanitized
285
+ if (!isValidProjectId(projectId)) {
286
+ throw new Error(`Internet Header: invalid project id "${projectId}"`);
287
+ }
288
+ if (projectId === 'test') {
289
+ environment = 'int01';
290
+ }
291
+ let url = generateConfigUrl(projectId, environment);
292
+ // Get the config if cache is invalid
293
+ try {
294
+ const res = await fetch(url);
295
+ return (await res.json());
296
+ }
297
+ catch (error) {
298
+ throw new Error(`Internet Header: fetching config failed. ${error.message}`);
299
+ }
300
+ };
301
+ /**
302
+ * Generate an URL with all necessary query params to get the configuration.
303
+ * Project id "test" will return a test configuration
304
+ * @param projectId string
305
+ * @param environment int01, int02 or prod
306
+ * @returns URL pointing to the project config
307
+ */
308
+ const generateConfigUrl = (projectId, environment) => {
309
+ if (projectId === 'test')
310
+ return 'assets/config/test-configuration.json';
311
+ const parsedEnvironment = environment.toLowerCase();
312
+ const isProd = parsedEnvironment === 'prod';
313
+ const host = `https://${isProd ? 'www' : 'int'}.post.ch`;
314
+ try {
315
+ // Use URL to validate the generated URL
316
+ return new URL(`${host}/api/headerjs/Json?serviceid=${encodeURIComponent(projectId)}${!isProd ? '&environment=' + parsedEnvironment : ''}`).toString();
317
+ }
318
+ catch (error) {
319
+ throw new Error(`Internet Header: Config URL is invalid.`);
320
+ }
321
+ };
322
+ /**
323
+ * Check if project id contains only URL safe characters
324
+ *
325
+ * @param projectId Project Id string
326
+ * @returns The valid project id
327
+ */
328
+ const isValidProjectId = (projectId) => {
329
+ return projectId !== '' && projectId.length > 0 && /^[a-zA-Z][\w-]*[a-zA-Z0-9]$/.test(projectId);
330
+ };
331
+ /**
332
+ * Get the localized config object from a custom config
333
+ *
334
+ * @param config String or json object of the custom config
335
+ * @param language Specific language
336
+ * @returns Localized custom config object
337
+ */
338
+ const getLocalizedCustomConfig = (config, language) => {
339
+ var _a;
340
+ let customConfig;
341
+ try {
342
+ customConfig = typeof config === 'string' ? JSON.parse(config) : config;
343
+ }
344
+ catch (error) {
345
+ throw new Error(`Internet Header: Custom config is invalid. Make sure your custom config contains valid JSON syntax and matches the definition. `);
346
+ }
347
+ let localizedCustomConfig = customConfig[language];
348
+ if ((_a = localizedCustomConfig === null || localizedCustomConfig === void 0 ? void 0 : localizedCustomConfig.header) === null || _a === void 0 ? void 0 : _a.navMain)
349
+ setMainNavigationIds(localizedCustomConfig.header.navMain);
350
+ return localizedCustomConfig;
351
+ };
352
+ /**
353
+ * Set unique ID's on main navigation entities but conserve flyout_os to be able to
354
+ * identify the online-service flyout, which can be configured by osFlyoutOverrides
355
+ */
356
+ const setMainNavigationIds = (navMainEntities) => {
357
+ navMainEntities.forEach(navMainEntity => {
358
+ navMainEntity.id = navMainEntity.id === 'flyout_os' ? navMainEntity.id : utils.uniqueId('main-nav-');
359
+ });
360
+ };
16
361
 
17
- exports.swisspost_internet_header = postInternetHeader.PostInternetHeader;
362
+ const name = "@swisspost/internet-header";
363
+ const version = "1.12.1";
364
+ const description = "The header for client facing applications.";
365
+ const author = "Swiss Post <oss@post.ch>";
366
+ const license = "Apache-2.0";
367
+ const repository = {
368
+ type: "git",
369
+ url: "https://github.com/swisspost/design-system.git"
370
+ };
371
+ const homepage = "https://next.design-system.post.ch";
372
+ const bugs = {
373
+ url: "https://github.com/swisspost/design-system/issues"
374
+ };
375
+ const main = "loader/index.cjs.js";
376
+ const module$1 = "loader/index.js";
377
+ const es2015 = "loader/index.es2017.js";
378
+ const es2017 = "loader/index.es2017.js";
379
+ const types = "loader/index.d.ts";
380
+ const collection = "dist/collection/collection-manifest.json";
381
+ const unpkg = "loader/cdn.js";
382
+ const publishConfig = {
383
+ access: "public"
384
+ };
385
+ const files = [
386
+ "dist/",
387
+ "loader/"
388
+ ];
389
+ const scripts = {
390
+ dev: "stencil build --serve --port 9310 --watch --docs-readme",
391
+ start: "stencil build --watch --docs-readme",
392
+ build: "stencil build --docs-readme",
393
+ clean: "rimraf www dist loader",
394
+ test: "npm run unit",
395
+ unit: "jest",
396
+ "unit:watch": "jest --watch",
397
+ e2e: "cypress run",
398
+ "e2e:watch": "cypress open",
399
+ lint: "eslint src/**/*{.ts,.tsx}",
400
+ "lint:fix": "eslint src/**/*{.ts,.tsx} --fix",
401
+ generate: "stencil generate"
402
+ };
403
+ const dependencies = {
404
+ "@stencil/core": "4.6.0",
405
+ "@stencil/store": "2.0.11",
406
+ "@swisspost/design-system-styles": "workspace:6.4.3",
407
+ "body-scroll-lock": "4.0.0-beta.0",
408
+ "iframe-resizer": "4.3.7",
409
+ jquery: "3.7.1",
410
+ tabbable: "6.2.0",
411
+ "throttle-debounce": "5.0.0",
412
+ "url-polyfill": "1.1.12"
413
+ };
414
+ const devDependencies = {
415
+ "@babel/core": "7.22.20",
416
+ "@percy/cli": "1.27.2",
417
+ "@percy/cypress": "3.1.2",
418
+ "@stencil-community/eslint-plugin": "0.5.0",
419
+ "@stencil/sass": "3.0.7",
420
+ "@types/body-scroll-lock": "3.1.0",
421
+ "@types/iframe-resizer": "3.5.9",
422
+ "@types/jest": "27.5.2",
423
+ "@types/jquery": "3.5.19",
424
+ "@types/node": "18.17.19",
425
+ "@types/throttle-debounce": "5.0.0",
426
+ "babel-loader": "9.1.3",
427
+ bootstrap: "5.3.2",
428
+ cypress: "13.2.0",
429
+ "cypress-each": "1.13.3",
430
+ "cypress-storybook": "0.5.1",
431
+ "eslint-plugin-react": "7.33.2",
432
+ globby: "13.2.2",
433
+ jest: "27.5.1",
434
+ rimraf: "5.0.1",
435
+ "rollup-plugin-node-polyfills": "0.2.1",
436
+ "rollup-plugin-scss": "4.0.0",
437
+ "rollup-plugin-visualizer": "5.9.2",
438
+ sass: "1.68.0",
439
+ "start-server-and-test": "2.0.1",
440
+ "ts-jest": "27.1.5",
441
+ typescript: "4.9.5"
442
+ };
443
+ const packageJson = {
444
+ name: name,
445
+ version: version,
446
+ description: description,
447
+ author: author,
448
+ license: license,
449
+ repository: repository,
450
+ homepage: homepage,
451
+ bugs: bugs,
452
+ main: main,
453
+ module: module$1,
454
+ es2015: es2015,
455
+ es2017: es2017,
456
+ "jsnext:main": "loader/index.es2017.js",
457
+ types: types,
458
+ collection: collection,
459
+ "collection:main": "dist/collection/index.js",
460
+ unpkg: unpkg,
461
+ publishConfig: publishConfig,
462
+ files: files,
463
+ scripts: scripts,
464
+ dependencies: dependencies,
465
+ devDependencies: devDependencies
466
+ };
467
+
468
+ const isScrollable = (node) => {
469
+ if (!(node instanceof HTMLElement || node instanceof SVGElement)) {
470
+ return false;
471
+ }
472
+ const style = getComputedStyle(node);
473
+ return ['overflow', 'overflow-x', 'overflow-y'].some(propertyName => {
474
+ const value = style.getPropertyValue(propertyName);
475
+ return value === 'auto' || value === 'scroll';
476
+ });
477
+ };
478
+ const getScrollParent = (node) => {
479
+ let currentParent = node.parentElement;
480
+ while (currentParent) {
481
+ if (isScrollable(currentParent)) {
482
+ return currentParent;
483
+ }
484
+ currentParent = currentParent.parentElement;
485
+ }
486
+ return document;
487
+ };
488
+
489
+ const registerLogoAnimationObserver = (target, headerRef) => {
490
+ const scrollParent = getScrollParent(headerRef);
491
+ /**
492
+ * Set intersection ratio as CSS custom property
493
+ */
494
+ const handleScroll = () => {
495
+ const fullStickyness = store.state.stickyness === 'full';
496
+ let scale = 1;
497
+ // Minus 1px border at the bottom that the logo is not covering
498
+ const adjustedHeaderHeight = headerRef.clientHeight - 1;
499
+ const scrollDistance = scrollParent instanceof Element ? scrollParent.scrollTop : scrollParent.documentElement.scrollTop;
500
+ const scrollY = fullStickyness ? 0 : scrollDistance;
501
+ // If meta navigation is not visible (mobile, not configured), scale should just be 1
502
+ if (target.clientHeight > 0) {
503
+ scale = Math.max((adjustedHeaderHeight - Math.max(scrollY, 0)) /
504
+ (adjustedHeaderHeight - target.clientHeight), 1);
505
+ }
506
+ headerRef.style.setProperty('--logo-scale', scale.toString());
507
+ };
508
+ const debounced = index.debounce(150, handleScroll);
509
+ /**
510
+ * Observe the meta navigation in order to not track scroll events throughout the whole page.
511
+ * This ensures that the scroll listener is only active while the meta navigation is visible.
512
+ */
513
+ const observer = new IntersectionObserver(entries => {
514
+ entries.forEach(entry => {
515
+ if (entry.isIntersecting && entry.intersectionRatio > 0) {
516
+ scrollParent.addEventListener('scroll', handleScroll, { passive: true });
517
+ window.addEventListener('resize', debounced);
518
+ // Ensure callback is called at least once in case main thread is too busy while scrolling up
519
+ window.requestAnimationFrame(handleScroll);
520
+ }
521
+ else {
522
+ scrollParent.removeEventListener('scroll', handleScroll);
523
+ window.removeEventListener('resize', debounced);
524
+ window.requestAnimationFrame(handleScroll);
525
+ }
526
+ });
527
+ }, {
528
+ // Fires when element leaves viewport (0) and when it just about enters it (0.001)
529
+ threshold: [0, 0.001],
530
+ });
531
+ observer.observe(target);
532
+ return handleScroll;
533
+ };
534
+
535
+ const postInternetHeaderCss = "@font-face{font-display:swap;font-family:\"Frutiger Neue For Post\";font-weight:700;src:url(\"https://fonts.post.ch/frutigerneueforpost/v2/FrutigerNeueforPostW05-Bold.woff2\") format(\"woff2\"),url(\"https://fonts.post.ch/frutigerneueforpost/v2/FrutigerNeueforPostW05-Bold.woff\") format(\"woff\")}@font-face{font-display:swap;font-family:\"Frutiger Neue For Post\";font-weight:700;font-style:italic;src:url(\"https://fonts.post.ch/frutigerneueforpost/v2/FrutigerNeueforPostW05-BdIt.woff2\") format(\"woff2\"),url(\"https://fonts.post.ch/frutigerneueforpost/v2/FrutigerNeueforPostW05-BdIt.woff\") format(\"woff\")}@font-face{font-display:swap;font-family:\"Frutiger Neue For Post\";font-weight:400;src:url(\"https://fonts.post.ch/frutigerneueforpost/v2/FrutigerNeueforPostW05-Rg.woff2\") format(\"woff2\"),url(\"https://fonts.post.ch/frutigerneueforpost/v2/FrutigerNeueforPostW05-Rg.woff\") format(\"woff\")}@font-face{font-display:swap;font-family:\"Frutiger Neue For Post\";font-weight:400;font-style:italic;src:url(\"https://fonts.post.ch/frutigerneueforpost/v2/FrutigerNeueforPostW05-It.woff2\") format(\"woff2\"),url(\"https://fonts.post.ch/frutigerneueforpost/v2/FrutigerNeueforPostW05-It.woff\") format(\"woff\")}@font-face{font-display:swap;font-family:\"Frutiger Neue For Post\";font-weight:300;src:url(\"https://fonts.post.ch/frutigerneueforpost/v2/FrutigerNeueforPostW05-Lt.woff2\") format(\"woff2\"),url(\"https://fonts.post.ch/frutigerneueforpost/v2/FrutigerNeueforPostW05-Lt.woff\") format(\"woff\")}@font-face{font-display:swap;font-family:\"Frutiger Neue For Post\";font-weight:300;font-style:italic;src:url(\"https://fonts.post.ch/frutigerneueforpost/v2/FrutigerNeueforPostW05-LtIt.woff2\") format(\"woff2\"),url(\"https://fonts.post.ch/frutigerneueforpost/v2/FrutigerNeueforPostW05-LtIt.woff\") format(\"woff\")}.visually-hidden{position:absolute;width:1px;height:1px;border:0;padding:0;margin:-1px;overflow:hidden;clip:rect(0 0 0 0)}.btn-blank{background-color:rgba(0,0,0,0);border:none;border-radius:0;padding:0}.nav-link{outline:none;outline-offset:2px;text-decoration:none;color:rgba(0,0,0,.8);-webkit-transition:color 200ms;transition:color 200ms;background-color:rgba(0,0,0,0);-webkit-box-shadow:none;box-shadow:none;border:0;margin:0;cursor:pointer;display:-ms-flexbox;display:flex;-ms-flex-align:center;align-items:center;gap:.5rem}.nav-link:is(:focus-visible,:focus-within,.pretend-focus){outline:2px solid var(--post-contrast-color)}.nav-link:hover,.nav-link:focus{color:#000}.nav-link:is(:focus-visible,:focus-within,.pretend-focus){z-index:1;position:relative}.nav-link>svg{width:1.4em;height:1.4em;-ms-flex-negative:0;flex-shrink:0}.nav-link>span{-ms-flex-negative:1;flex-shrink:1}.no-list{list-style:none;padding-left:0;margin-top:0;margin-bottom:0}*,:host,*::before,*::after{-webkit-box-sizing:border-box;box-sizing:border-box}:host{font-family:\"Frutiger Neue For Post\",system-ui,sans-serif}button{font:inherit;padding:0}a,button{border-radius:4px;outline:none;outline-offset:2px}a:is(:focus-visible,:focus-within,.pretend-focus),button:is(:focus-visible,:focus-within,.pretend-focus){outline:2px solid var(--post-contrast-color);border-radius:4px}img,svg{max-width:100%;max-height:100%}@media (forced-colors: active){svg{color:#fff}}.box>*:first-child{margin-top:0}.box>*:last-child{margin-bottom:0}.mirrored{-webkit-transform:scaleX(-1);transform:scaleX(-1)}.rotate-270{-webkit-transform:rotate(270deg);transform:rotate(270deg)}.bold{font-weight:700}.light{font-weight:300}.d-flex{display:-ms-flexbox;display:flex}.d-inline-flex{display:-ms-inline-flexbox;display:inline-flex}.align-items-center{-ms-flex-align:center;align-items:center}@media (min-width: 1441px){.wide-container{margin:0 auto;max-width:1440px}}@media (max-width: 599.98px){.container{padding-right:16px;padding-left:16px}}@media (min-width: 600px)and (max-width: 1023.98px){.container{padding-right:32px;padding-left:32px}}@media (min-width: 1024px){.container{padding-right:40px;padding-left:40px}}@media (max-width: -0.02px){.hidden-xs{display:none}}@media (max-width: 399.98px){.hidden-sm{display:none}}@media (max-width: 599.98px){.hidden-rg{display:none}}@media (max-width: 779.98px){.hidden-md{display:none}}@media (max-width: 1023.98px){.hidden-lg{display:none}}@media (max-width: 1279.98px){.hidden-xl{display:none}}@media (max-width: 1440.98px){.hidden-xxl{display:none}}:host{--logo-scale:1}@media (max-width: 1023.98px){:host{--logo-scale:1 !important}}post-logo{height:var(--header-height);-webkit-transform-origin:bottom left;transform-origin:bottom left;-webkit-transform:scale(var(--logo-scale));transform:scale(var(--logo-scale))}post-main-navigation{margin-left:calc(var(--header-height)*var(--logo-scale) - var(--header-height))}:host{display:block;position:relative;font-size:1rem;font-weight:300;z-index:var(--header-z-index, 10);--header-height:3.5rem;--meta-header-height:0px;--language-dropdown-margin-top:0px}@media (min-width: 1024px){:host{--meta-header-height:3rem;--header-height:4rem}}@media (min-width: 1280px){:host{--header-height:4.5rem}}:host([meta=false]){--meta-header-height:0px;--language-dropdown-margin-top:1px}@supports ((position: -webkit-sticky) or (position: sticky)){:host(:not(.stickyness-none)){position:-webkit-sticky;position:sticky}:host(.stickyness-full){top:0}:host(.stickyness-main){top:calc(var(--meta-header-height, 0px)*-1)}:host(.stickyness-minimal){top:calc((var(--header-height, 0px) + var(--meta-header-height, 0px) + 1px)*-1);-webkit-transition:top 200ms ease-in;transition:top 200ms ease-in}:host(.stickyness-minimal.scrolling-up),:host(.stickyness-minimal.dropdown-open){top:calc(var(--meta-header-height, 0px)*-1);-webkit-transition:top 200ms ease-out;transition:top 200ms ease-out}}.post-internet-header{border-bottom:1px solid #e6e6e6;background-color:#fff}.main-navigation-container{display:-ms-flexbox;display:flex}.main-navigation-container>.main-navigation-controls{-ms-flex:0 0 auto;flex:0 0 auto}.main-navigation{display:-ms-flexbox;display:flex}.sub-navigation-container{position:absolute;top:100%;left:0;width:100%;display:-ms-flexbox;display:flex;background:#fff;visibility:hidden}.main-navigation-item:hover .sub-navigation-container{visibility:visible}.main-navigation-controls{display:-ms-flexbox;display:flex;margin-left:auto}@media (max-width: 1023.98px){.main-navigation-controls{font-weight:400}}@media (min-width: 1024px){.main-navigation-controls{font-size:1.0625rem}}.main-navigation-controls>*{border-left:1px solid #e6e6e6}.menu-button{display:-ms-flexbox;display:flex;-ms-flex-align:center;align-items:center;padding:0 calc(1rem - 1px);font-weight:300;cursor:pointer;border-left:1px solid #e6e6e6;-ms-flex-order:1;order:1}@media (min-width: 1024px){.menu-button{display:none}}@media (min-width: 600px)and (max-width: 1023.98px){.menu-button .visually-hidden{position:static;width:auto;height:auto;margin:auto;overflow:visible;clip:auto;visibility:visible;margin-right:.5rem}}.menu-button svg{width:1.5rem;height:1.5rem}.full-width .wide-container{max-width:none}";
536
+
537
+ const PostInternetHeader = class {
538
+ /**
539
+ * Get the currently set language as a two letter string ("de", "fr" "it" or "en")
540
+ * @returns string
541
+ */
542
+ async getCurrentLanguage() {
543
+ var _a;
544
+ return (_a = store.state.currentLanguage) !== null && _a !== void 0 ? _a : 'de';
545
+ }
546
+ constructor(hostRef) {
547
+ index$1.registerInstance(this, hostRef);
548
+ this.headerLoaded = index$1.createEvent(this, "headerLoaded", 7);
549
+ this.lastScrollTop = window.scrollY || document.documentElement.scrollTop;
550
+ this.lastWindowWidth = window.innerWidth;
551
+ this.handleClickOutsideBound = this.handleClickOutside.bind(this);
552
+ this.project = undefined;
553
+ this.stickyness = 'minimal';
554
+ this.language = undefined;
555
+ this.meta = true;
556
+ this.login = true;
557
+ this.search = true;
558
+ this.skiplinks = true;
559
+ this.configProxy = undefined;
560
+ this.environment = 'prod';
561
+ this.languageSwitchOverrides = undefined;
562
+ this.customConfig = undefined;
563
+ this.languageCookieKey = undefined;
564
+ this.languageLocalStorageKey = 'swisspost-internet-header-language';
565
+ this.logoutUrl = undefined;
566
+ this.activeRoute = 'auto';
567
+ this.osFlyoutOverrides = undefined;
568
+ this.fullWidth = false;
569
+ this.activeFlyout = null;
570
+ this.activeDropdownElement = null;
571
+ if (this.project === undefined || this.project === '' || !isValidProjectId(this.project)) {
572
+ throw new Error(`Internet Header project key is "${this.project}". Please provide a valid project key.`);
573
+ }
574
+ }
575
+ connectedCallback() {
576
+ this.throttledScroll = index.throttle(300, () => this.handleScrollEvent());
577
+ this.debouncedResize = index.debounce(200, () => this.handleResize());
578
+ }
579
+ disconnectedCallback() {
580
+ this.scrollParent.removeEventListener('scroll', this.throttledScroll);
581
+ this.scrollParent.removeEventListener('resize', this.debouncedResize);
582
+ // Reset the store to its original state
583
+ store.dispose();
584
+ }
585
+ async componentWillLoad() {
586
+ this.scrollParent = getScrollParent(this.host);
587
+ this.scrollParent.addEventListener('scroll', this.throttledScroll, { passive: true });
588
+ this.scrollParent.addEventListener('resize', this.debouncedResize, { passive: true });
589
+ // Wait for the config to arrive, then render the header
590
+ try {
591
+ store.state.projectId = this.project;
592
+ store.state.stickyness = this.stickyness;
593
+ store.state.environment = this.environment.toLocaleLowerCase();
594
+ if (this.language !== undefined)
595
+ store.state.currentLanguage = this.language;
596
+ store.state.languageSwitchOverrides =
597
+ typeof this.languageSwitchOverrides === 'string'
598
+ ? JSON.parse(this.languageSwitchOverrides)
599
+ : this.languageSwitchOverrides;
600
+ store.state.osFlyoutOverrides =
601
+ typeof this.osFlyoutOverrides === 'string'
602
+ ? JSON.parse(this.osFlyoutOverrides)
603
+ : this.osFlyoutOverrides;
604
+ if (this.customConfig !== undefined) {
605
+ const langs = Object.keys(typeof this.customConfig === 'string' ? JSON.parse(this.customConfig) : this.customConfig);
606
+ const lang = store.state.currentLanguage || language_service.getUserLang(langs, this.language);
607
+ store.state.localizedCustomConfig = getLocalizedCustomConfig(this.customConfig, lang);
608
+ }
609
+ store.state.localizedConfig = await getLocalizedConfig({
610
+ projectId: this.project,
611
+ environment: store.state.environment,
612
+ language: this.language,
613
+ cookieKey: this.languageCookieKey,
614
+ localStorageKey: this.languageLocalStorageKey,
615
+ activeRouteProp: this.activeRoute,
616
+ localizedCustomConfig: store.state.localizedCustomConfig,
617
+ osFlyoutOverrides: store.state.osFlyoutOverrides,
618
+ });
619
+ }
620
+ catch (error) {
621
+ console.error(error);
622
+ }
623
+ }
624
+ componentDidLoad() {
625
+ window.requestAnimationFrame(() => {
626
+ this.handleResize();
627
+ this.headerLoaded.emit();
628
+ this.host.classList.add('header-loaded');
629
+ if (this.meta && this.metaNav) {
630
+ this.updateLogoAnimation = registerLogoAnimationObserver(this.metaNav, this.host);
631
+ }
632
+ });
633
+ if (this.stickyness === 'full')
634
+ console.warn('Internet Header: The stickyness="full" option is deprecated.');
635
+ }
636
+ async handleLanguageChange(newValue) {
637
+ store.state.currentLanguage = newValue;
638
+ store.state.localizedConfig = await getLocalizedConfig({
639
+ projectId: this.project,
640
+ environment: this.environment,
641
+ language: newValue,
642
+ cookieKey: this.languageCookieKey,
643
+ localStorageKey: this.languageLocalStorageKey,
644
+ activeRouteProp: this.activeRoute,
645
+ localizedCustomConfig: store.state.localizedCustomConfig,
646
+ osFlyoutOverrides: store.state.osFlyoutOverrides,
647
+ });
648
+ if (this.customConfig)
649
+ store.state.localizedCustomConfig = getLocalizedCustomConfig(this.customConfig, newValue);
650
+ }
651
+ handleAvailableLanguagesChange(newValue) {
652
+ store.state.languageSwitchOverrides = typeof newValue === 'string' ? JSON.parse(newValue) : newValue;
653
+ }
654
+ async handleOsFlyoutOverrides(newValue) {
655
+ store.state.osFlyoutOverrides = typeof newValue === 'string' ? JSON.parse(newValue) : newValue;
656
+ store.state.localizedConfig = await getLocalizedConfig({
657
+ projectId: this.project,
658
+ environment: this.environment,
659
+ language: this.language,
660
+ cookieKey: this.languageCookieKey,
661
+ localStorageKey: this.languageLocalStorageKey,
662
+ activeRouteProp: this.activeRoute,
663
+ localizedCustomConfig: store.state.localizedCustomConfig,
664
+ osFlyoutOverrides: store.state.osFlyoutOverrides,
665
+ });
666
+ }
667
+ async handleActiveRouteChange(newValue) {
668
+ store.state.localizedConfig = await getLocalizedConfig({
669
+ projectId: this.project,
670
+ environment: this.environment,
671
+ language: this.language,
672
+ cookieKey: this.languageCookieKey,
673
+ localStorageKey: this.languageLocalStorageKey,
674
+ activeRouteProp: newValue,
675
+ localizedCustomConfig: store.state.localizedCustomConfig,
676
+ osFlyoutOverrides: store.state.osFlyoutOverrides,
677
+ });
678
+ }
679
+ async handleCustomConfigChange(newValue) {
680
+ if (this.language === undefined)
681
+ return;
682
+ const localizedCustomConfig = getLocalizedCustomConfig(newValue, this.language);
683
+ store.state.localizedCustomConfig = localizedCustomConfig;
684
+ store.state.localizedConfig = await getLocalizedConfig({
685
+ projectId: this.project,
686
+ environment: this.environment,
687
+ language: this.language,
688
+ cookieKey: this.languageCookieKey,
689
+ localStorageKey: this.languageLocalStorageKey,
690
+ activeRouteProp: this.activeRoute,
691
+ localizedCustomConfig: localizedCustomConfig,
692
+ osFlyoutOverrides: store.state.osFlyoutOverrides,
693
+ });
694
+ }
695
+ handleSearchChange(newValue) {
696
+ store.state.search = newValue;
697
+ }
698
+ handleLoginChange(newValue) {
699
+ store.state.login = newValue;
700
+ }
701
+ handleMetaChange(newValue) {
702
+ store.state.meta = newValue;
703
+ }
704
+ handleLanguageChangeEvent(event) {
705
+ void this.handleLanguageChange(event.detail);
706
+ }
707
+ handleStickynessChange(newValue) {
708
+ store.state.stickyness = newValue;
709
+ if (typeof this.updateLogoAnimation === 'function')
710
+ this.updateLogoAnimation();
711
+ }
712
+ handleClickOutside(event) {
713
+ // Close active dropdown element on click outside of it
714
+ if (this.activeDropdownElement && !event.composedPath().includes(this.activeDropdownElement)) {
715
+ void this.activeDropdownElement.toggleDropdown(false);
716
+ }
717
+ }
718
+ handleKeyUp(event) {
719
+ if (event.key === 'Escape') {
720
+ if (this.activeDropdownElement) {
721
+ void this.activeDropdownElement.toggleDropdown(false);
722
+ }
723
+ if (this.activeFlyout !== null && this.mainNav) {
724
+ void this.mainNav.toggleDropdown(false);
725
+ }
726
+ }
727
+ }
728
+ handleScrollEvent() {
729
+ // Credits: "https://github.com/qeremy/so/blob/master/so.dom.js#L426"
730
+ const st = this.scrollParent instanceof Document
731
+ ? this.scrollParent.documentElement.scrollTop
732
+ : this.scrollParent.scrollTop;
733
+ // Toggle class without re-rendering the component if stickyness is minimal
734
+ // the other stickyness modes do not need the class
735
+ if (this.stickyness === 'minimal') {
736
+ this.host.classList.toggle('scrolling-up', st <= this.lastScrollTop);
737
+ }
738
+ // For Mobile or negative scrolling
739
+ this.lastScrollTop = st <= 0 ? 0 : st;
740
+ }
741
+ handleResize() {
742
+ var _a;
743
+ // Close main navigation dropdown if size changed to bigger than 1024px (search dropdown will be kept open)
744
+ if (this.isMainNavOpen() && this.lastWindowWidth < 1024 && window.innerWidth >= 1024) {
745
+ (_a = this.activeDropdownElement) === null || _a === void 0 ? void 0 : _a.toggleDropdown(false);
746
+ }
747
+ this.lastWindowWidth = window.innerWidth;
748
+ }
749
+ /**
750
+ * Close open dropdown menus if another is being opened
751
+ *
752
+ * @param event Dropdown toggled event
753
+ * @returns void
754
+ */
755
+ handleDropdownToggled(event) {
756
+ if (!event.detail.open && this.activeDropdownElement !== event.detail.element) {
757
+ // Some dropdown got closed programmatically (possibly by this function). To prevent
758
+ // a circle or an outdated state, we'll not handle this event
759
+ return;
760
+ }
761
+ if (event.detail.open) {
762
+ if (this.activeDropdownElement) {
763
+ void this.activeDropdownElement.toggleDropdown(false);
764
+ }
765
+ this.activeDropdownElement = event.detail.element;
766
+ if (window.innerWidth >= 1024) {
767
+ // Add event listener to close active dropdown element on click outside of it
768
+ // Also adds 10ms delay in case of an external interaction:
769
+ // Some button on the page calls toggleDropdown() -> dropdown opens
770
+ // Click event bubbles to the window, this.handleClickOutsideBound closes dropdown again
771
+ window.setTimeout(() => {
772
+ window.addEventListener('click', this.handleClickOutsideBound);
773
+ }, 10);
774
+ }
775
+ if (this.activeFlyout !== null && this.mainNav) {
776
+ void this.mainNav.setActiveFlyout(null);
777
+ }
778
+ }
779
+ else {
780
+ this.activeDropdownElement = null;
781
+ // Remove event listener as it is not needed if no dropdown element is active
782
+ window.removeEventListener('click', this.handleClickOutsideBound);
783
+ }
784
+ }
785
+ /**
786
+ * Close open dropdowns if the flyout is being opened
787
+ * @param event Flyout toggle event
788
+ */
789
+ handleFlyoutToggled(event) {
790
+ this.activeFlyout = event.detail;
791
+ if (this.activeDropdownElement && event.detail && !this.isMainNavOpen()) {
792
+ void this.activeDropdownElement.toggleDropdown(false);
793
+ }
794
+ }
795
+ toggleMobileDropdown() {
796
+ var _a;
797
+ (_a = this.mainNav) === null || _a === void 0 ? void 0 : _a.toggleDropdown();
798
+ }
799
+ isMainNavOpen() {
800
+ return (this.activeDropdownElement && this.activeDropdownElement.tagName === 'POST-MAIN-NAVIGATION');
801
+ }
802
+ render() {
803
+ var _a, _b, _c;
804
+ if (!((_a = store.state.localizedConfig) === null || _a === void 0 ? void 0 : _a.header)) {
805
+ console.error(new Error('Internet Header: Config cannot be loaded'));
806
+ return;
807
+ }
808
+ const config = store.state.localizedConfig;
809
+ const renderMetaNavigation = this.meta &&
810
+ config.header.navMeta !== undefined &&
811
+ ((_b = config.header.navMeta) === null || _b === void 0 ? void 0 : _b.filter(meta => !meta.isHomeLink).length) > 0;
812
+ const renderLogin = ((_c = this.login) !== null && _c !== void 0 ? _c : !config.header.isLoginWidgetHidden) && config.header.loginWidgetOptions;
813
+ const renderLanguageSwitch = config.header.navLang.length > 1;
814
+ return (index$1.h(index$1.Host, { class: `stickyness-${this.stickyness} ${Boolean(this.activeDropdownElement) || Boolean(this.activeFlyout) ? 'dropdown-open' : ''}`, "data-version": packageJson.version, onKeyup: (e) => this.handleKeyUp(e) }, index$1.h("header", { class: `post-internet-header${this.fullWidth ? ' full-width' : ''}` }, index$1.h(svgSprite_component.SvgSprite, null), index$1.h("h1", { class: "visually-hidden" }, language_service.translate('Navigate on post.ch')), index$1.h(if_component.If, { condition: this.skiplinks }, index$1.h("post-skiplinks", null)), index$1.h(if_component.If, { condition: renderMetaNavigation }, index$1.h("post-meta-navigation", { orientation: "horizontal", class: "hidden-lg", "full-width": this.fullWidth, ref: el => (this.metaNav = el) }, index$1.h(if_component.If, { condition: renderLanguageSwitch }, index$1.h("post-language-switch", { id: "post-language-switch-desktop", mode: "dropdown", onDropdownToggled: e => this.handleDropdownToggled(e) })))), index$1.h("div", { class: "main-navigation-container wide-container" }, index$1.h("post-logo", null), index$1.h("button", { class: "menu-button nav-link", onClick: () => this.toggleMobileDropdown(), "aria-haspopup": "menu", "aria-controls": "post-internet-header-main-navigation", "aria-expanded": this.activeDropdownElement ? 'true' : 'false' }, index$1.h("span", { class: "menu-button-text visually-hidden" }, config.header.mobileMenu.text), index$1.h(svgIcon_component.SvgIcon, { name: this.isMainNavOpen() ? 'pi-close' : 'pi-menu' })), index$1.h("post-main-navigation", { onDropdownToggled: e => this.handleDropdownToggled(e), onFlyoutToggled: e => this.handleFlyoutToggled(e), ref: el => (this.mainNav = el) }, index$1.h(if_component.If, { condition: renderMetaNavigation }, index$1.h("post-meta-navigation", { orientation: "vertical" }, index$1.h(if_component.If, { condition: renderLanguageSwitch }, index$1.h("post-language-switch", { id: "post-language-switch-mobile", mode: "list" }))))), index$1.h("div", { class: "main-navigation-controls" }, index$1.h(if_component.If, { condition: this.search }, index$1.h("post-search", { onDropdownToggled: e => this.handleDropdownToggled(e) })), index$1.h(if_component.If, { condition: !!renderLogin }, index$1.h("post-klp-login-widget", { "logout-url": this.logoutUrl }, index$1.h("slot", { name: "login-widget" }))), index$1.h(if_component.If, { condition: !renderMetaNavigation && renderLanguageSwitch }, index$1.h("post-language-switch", { id: "post-language-switch-no-meta", onDropdownToggled: e => this.handleDropdownToggled(e), mode: "dropdown" })), index$1.h("slot", { name: "main" }))))));
815
+ }
816
+ get host() { return index$1.getElement(this); }
817
+ static get watchers() { return {
818
+ "language": ["handleLanguageChange"],
819
+ "languageSwitchOverrides": ["handleAvailableLanguagesChange"],
820
+ "osFlyoutOverrides": ["handleOsFlyoutOverrides"],
821
+ "activeRoute": ["handleActiveRouteChange"],
822
+ "customConfig": ["handleCustomConfigChange"],
823
+ "search": ["handleSearchChange"],
824
+ "login": ["handleLoginChange"],
825
+ "meta": ["handleMetaChange"],
826
+ "stickyness": ["handleStickynessChange"]
827
+ }; }
828
+ };
829
+ PostInternetHeader.style = postInternetHeaderCss;
830
+
831
+ exports.swisspost_internet_header = PostInternetHeader;
18
832
 
19
833
  //# sourceMappingURL=swisspost-internet-header.cjs.entry.js.map