@swisspost/internet-header 1.15.12 → 1.15.13

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 (25) hide show
  1. package/dist/cjs/index.cjs.js +1 -1
  2. package/dist/cjs/{post-internet-header-73538cc1.js → post-internet-header-a97a7cf2.js} +43 -38
  3. package/dist/cjs/swisspost-internet-header.cjs.entry.js +1 -1
  4. package/dist/collection/services/route.service.js +41 -36
  5. package/dist/components/swisspost-internet-header.js +43 -38
  6. package/dist/docs.json +1 -1
  7. package/dist/esm/index.js +1 -1
  8. package/dist/esm/{post-internet-header-96053f9b.js → post-internet-header-c7e6cae4.js} +43 -38
  9. package/dist/esm/swisspost-internet-header.entry.js +1 -1
  10. package/dist/esm-es5/index.js +1 -1
  11. package/dist/esm-es5/post-internet-header-c7e6cae4.js +1 -0
  12. package/dist/esm-es5/swisspost-internet-header.entry.js +1 -1
  13. package/dist/swisspost-internet-header/index.esm.js +1 -1
  14. package/dist/swisspost-internet-header/p-11de4a87.js +1 -0
  15. package/dist/swisspost-internet-header/p-297916c1.system.js +1 -0
  16. package/dist/swisspost-internet-header/p-695fe962.system.js +1 -1
  17. package/dist/swisspost-internet-header/{p-e5cbad90.system.js → p-876f9c55.system.js} +1 -1
  18. package/dist/swisspost-internet-header/{p-eb84e447.entry.js → p-b73ccb68.entry.js} +1 -1
  19. package/dist/swisspost-internet-header/{p-41799f6b.system.entry.js → p-e9f1c4ac.system.entry.js} +1 -1
  20. package/dist/swisspost-internet-header/swisspost-internet-header.esm.js +1 -1
  21. package/dist/types/services/route.service.d.ts +11 -11
  22. package/package.json +2 -2
  23. package/dist/esm-es5/post-internet-header-96053f9b.js +0 -1
  24. package/dist/swisspost-internet-header/p-2e092180.js +0 -1
  25. package/dist/swisspost-internet-header/p-c164ea99.system.js +0 -1
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- const postInternetHeader = require('./post-internet-header-73538cc1.js');
5
+ const postInternetHeader = require('./post-internet-header-a97a7cf2.js');
6
6
  const postInternetBreadcrumbs = require('./post-internet-breadcrumbs-ba6c9c31.js');
7
7
  const postInternetFooter = require('./post-internet-footer-69042a11.js');
8
8
  const postSkiplinks = require('./post-skiplinks-894eb1ca.js');
@@ -12,7 +12,7 @@ const if_component = require('./if.component-31542061.js');
12
12
  /**
13
13
  * Activate the current route based on the config and the match mode
14
14
  * @param config Main Navigation Config
15
- * @param activeRouteProp Match mode
15
+ * @param activeRouteProp Match mode or custom URL to compare against
16
16
  * @returns Modified Main Navigation Config
17
17
  */
18
18
  const markActiveRoute = (config, activeRouteProp) => {
@@ -20,26 +20,28 @@ const markActiveRoute = (config, activeRouteProp) => {
20
20
  if (activeRouteProp === false) {
21
21
  return config;
22
22
  }
23
- // Set compare URL and check if activeRouteProp is valid
24
- let compareUrl;
23
+ // Set reference URL to compare nav items against
24
+ let referenceUrl;
25
+ let isRelativeReference = false;
25
26
  config = resetOverrideConfig(config);
26
27
  if (activeRouteProp === 'auto' || activeRouteProp === 'exact') {
27
28
  // Check if an active route is already configured, set override to that and return
28
29
  if (hasActivePortalRoute(config)) {
29
30
  return resetActiveStateToPortalConfig(config);
30
31
  }
31
- compareUrl = new URL(window.location.href);
32
+ referenceUrl = new URL(window.location.href);
32
33
  }
33
34
  else {
34
35
  try {
35
- compareUrl = new URL(activeRouteProp, document.location.origin);
36
+ isRelativeReference = activeRouteProp.startsWith('/') || activeRouteProp.startsWith('./');
37
+ referenceUrl = new URL(activeRouteProp, window.location.href);
36
38
  }
37
39
  catch (error) {
38
40
  console.warn(`Active Route: ${activeRouteProp} is not a valid URL. Navigation highlighting has been disabled.`);
39
41
  return config;
40
42
  }
41
43
  }
42
- const scoreList = compileScoreList(config, compareUrl, activeRouteProp);
44
+ const scoreList = compileScoreList(config, referenceUrl, activeRouteProp, isRelativeReference);
43
45
  if (scoreList.length === 0) {
44
46
  // No match found or already active links defined
45
47
  return config;
@@ -73,13 +75,13 @@ const resetOverrideConfig = (config) => {
73
75
  });
74
76
  };
75
77
  /**
76
- * Compile a list of scores based on the map mode, sorted in descending order
78
+ * Compile a list of scores based on how well nav items match the reference URL
77
79
  * @param config Main Nav Config
78
- * @param compareUrl Current Browser URL or a custom URL
80
+ * @param referenceUrl URL to compare nav items against (window.location or custom)
79
81
  * @param activeRouteProp Match mode
80
82
  * @returns A list of scored URLs if any matched
81
83
  */
82
- const compileScoreList = (config, compareUrl, activeRouteProp) => {
84
+ const compileScoreList = (config, referenceUrl, activeRouteProp, isRelativeReference) => {
83
85
  // Flag to check if the Portal set any active links or if there are any exact matches
84
86
  let hadAnyActiveLink = false;
85
87
  const scoreList = [];
@@ -88,7 +90,8 @@ const compileScoreList = (config, compareUrl, activeRouteProp) => {
88
90
  .forEach(mainNav => {
89
91
  var _a;
90
92
  try {
91
- const score = compareRoutes(compareUrl, new URL(mainNav.url), activeRouteProp);
93
+ const navItemUrl = new URL(mainNav.url);
94
+ const score = compareRoutes(referenceUrl, navItemUrl, isRelativeReference, activeRouteProp);
92
95
  hadAnyActiveLink = updateScoreList(scoreList, score, { main: mainNav, score }, hadAnyActiveLink);
93
96
  }
94
97
  catch (_b) {
@@ -104,8 +107,8 @@ const compileScoreList = (config, compareUrl, activeRouteProp) => {
104
107
  return;
105
108
  }
106
109
  try {
107
- const url = new URL(linklist.url);
108
- const score = compareRoutes(compareUrl, url, activeRouteProp);
110
+ const flyoutNavUrl = new URL(linklist.url);
111
+ const score = compareRoutes(referenceUrl, flyoutNavUrl, isRelativeReference, activeRouteProp);
109
112
  hadAnyActiveLink = updateScoreList(scoreList, score, { main: mainNav, sub: linklist, score }, hadAnyActiveLink);
110
113
  }
111
114
  catch (_a) {
@@ -130,46 +133,48 @@ function updateScoreList(scoreList, score, scoreListItem, hadAnyActiveLink) {
130
133
  return hadActiveLink;
131
134
  }
132
135
  /**
133
- * Compare two URLs for similarity based on a match mode
134
- * @param baseUrl Browser URL
135
- * @param compareUrl Navigatgion URL
136
+ * Compare a nav item URL against the reference URL for similarity
137
+ * @param referenceUrl URL we're comparing against (from window.location or custom)
138
+ * @param navItemUrl URL from the navigation item
136
139
  * @param matchMode exact or auto matching
137
- * @returns Score
140
+ * @returns Score indicating how well the URLs match
138
141
  */
139
- const compareRoutes = (baseUrl, compareUrl, matchMode) => {
140
- // One url is not defined or they don't share the same orign
141
- if (baseUrl === null || compareUrl === null || baseUrl.origin !== compareUrl.origin) {
142
+ const compareRoutes = (referenceUrl, navItemUrl, isRelativeReference, matchMode) => {
143
+ if (referenceUrl === null || navItemUrl === null) {
144
+ return 0;
145
+ }
146
+ // Only compare origins if reference URL is not relative
147
+ if (!isRelativeReference && referenceUrl.origin !== navItemUrl.origin) {
142
148
  return 0;
143
149
  }
144
- const baseUrlPath = baseUrl.pathname.toLocaleLowerCase();
145
- const compareUrlPath = compareUrl.pathname.toLocaleLowerCase();
146
- // Exact match, origin and pathname are the same
147
- if (baseUrlPath === compareUrlPath) {
150
+ const referenceUrlPath = referenceUrl.pathname.toLocaleLowerCase();
151
+ const navItemUrlPath = navItemUrl.pathname.toLocaleLowerCase();
152
+ // Exact match, pathname is the same
153
+ if (referenceUrlPath === navItemUrlPath) {
148
154
  return Infinity;
149
155
  }
150
- // The basepath is longer than the comparison, a match is impossible
151
- if (baseUrl.pathname.length < compareUrl.pathname.length) {
156
+ // The reference path is shorter than nav item path, a match is impossible
157
+ if (referenceUrl.pathname.length < navItemUrl.pathname.length) {
152
158
  return 0;
153
159
  }
154
160
  if (matchMode === 'auto') {
155
- const baseSegments = [
156
- baseUrl.origin.toLocaleLowerCase(),
157
- ...baseUrlPath.split('/').filter(x => x !== null && x !== ''),
161
+ const referenceSegments = [
162
+ referenceUrl.origin.toLocaleLowerCase(),
163
+ ...referenceUrlPath.split('/').filter(x => x !== null && x !== ''),
158
164
  ];
159
- const compareSegments = [
160
- compareUrl.origin.toLocaleLowerCase(),
161
- ...compareUrlPath.split('/').filter(x => x !== null && x !== ''),
165
+ const navItemSegments = [
166
+ navItemUrl.origin.toLocaleLowerCase(),
167
+ ...navItemUrlPath.split('/').filter(x => x !== null && x !== ''),
162
168
  ];
163
- const score = getSimilarityScore(baseSegments, compareSegments);
164
- // If only some segments match, but not the whole smaller array, it's not a match
165
- return Math.min(baseSegments.length, compareSegments.length) === score ? score : 0;
169
+ const score = getSimilarityScore(referenceSegments, navItemSegments);
170
+ return Math.min(referenceSegments.length, navItemSegments.length) === score ? score : 0;
166
171
  }
167
172
  return 0;
168
173
  };
169
174
  /**
170
175
  * Check how many items in an array match
171
- * @param a Base array
172
- * @param b Compare array
176
+ * @param a Reference array
177
+ * @param b Nav item array to compare
173
178
  * @returns Score
174
179
  */
175
180
  const getSimilarityScore = (a, b) => {
@@ -368,7 +373,7 @@ const setMainNavigationIds = (navMainEntities) => {
368
373
  };
369
374
 
370
375
  const name = "@swisspost/internet-header";
371
- const version = "1.15.12";
376
+ const version = "1.15.13";
372
377
  const description = "The header for client facing applications.";
373
378
  const author = "Swiss Post <design-system@post.ch>";
374
379
  const license = "Apache-2.0";
@@ -409,7 +414,7 @@ const scripts = {
409
414
  generate: "stencil generate"
410
415
  };
411
416
  const dependencies = {
412
- "@swisspost/design-system-styles": "workspace:8.9.4",
417
+ "@swisspost/design-system-styles": "workspace:8.10.0",
413
418
  "body-scroll-lock": "4.0.0-beta.0",
414
419
  "iframe-resizer": "4.4.5",
415
420
  jquery: "3.7.1",
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- const postInternetHeader = require('./post-internet-header-73538cc1.js');
5
+ const postInternetHeader = require('./post-internet-header-a97a7cf2.js');
6
6
  require('./index-ecd8c9bb.js');
7
7
  require('./index-fbcc9ff3.js');
8
8
  require('./language.service-2a3c77d1.js');
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Activate the current route based on the config and the match mode
3
3
  * @param config Main Navigation Config
4
- * @param activeRouteProp Match mode
4
+ * @param activeRouteProp Match mode or custom URL to compare against
5
5
  * @returns Modified Main Navigation Config
6
6
  */
7
7
  export const markActiveRoute = (config, activeRouteProp) => {
@@ -9,26 +9,28 @@ export const markActiveRoute = (config, activeRouteProp) => {
9
9
  if (activeRouteProp === false) {
10
10
  return config;
11
11
  }
12
- // Set compare URL and check if activeRouteProp is valid
13
- let compareUrl;
12
+ // Set reference URL to compare nav items against
13
+ let referenceUrl;
14
+ let isRelativeReference = false;
14
15
  config = resetOverrideConfig(config);
15
16
  if (activeRouteProp === 'auto' || activeRouteProp === 'exact') {
16
17
  // Check if an active route is already configured, set override to that and return
17
18
  if (hasActivePortalRoute(config)) {
18
19
  return resetActiveStateToPortalConfig(config);
19
20
  }
20
- compareUrl = new URL(window.location.href);
21
+ referenceUrl = new URL(window.location.href);
21
22
  }
22
23
  else {
23
24
  try {
24
- compareUrl = new URL(activeRouteProp, document.location.origin);
25
+ isRelativeReference = activeRouteProp.startsWith('/') || activeRouteProp.startsWith('./');
26
+ referenceUrl = new URL(activeRouteProp, window.location.href);
25
27
  }
26
28
  catch (error) {
27
29
  console.warn(`Active Route: ${activeRouteProp} is not a valid URL. Navigation highlighting has been disabled.`);
28
30
  return config;
29
31
  }
30
32
  }
31
- const scoreList = compileScoreList(config, compareUrl, activeRouteProp);
33
+ const scoreList = compileScoreList(config, referenceUrl, activeRouteProp, isRelativeReference);
32
34
  if (scoreList.length === 0) {
33
35
  // No match found or already active links defined
34
36
  return config;
@@ -62,13 +64,13 @@ const resetOverrideConfig = (config) => {
62
64
  });
63
65
  };
64
66
  /**
65
- * Compile a list of scores based on the map mode, sorted in descending order
67
+ * Compile a list of scores based on how well nav items match the reference URL
66
68
  * @param config Main Nav Config
67
- * @param compareUrl Current Browser URL or a custom URL
69
+ * @param referenceUrl URL to compare nav items against (window.location or custom)
68
70
  * @param activeRouteProp Match mode
69
71
  * @returns A list of scored URLs if any matched
70
72
  */
71
- export const compileScoreList = (config, compareUrl, activeRouteProp) => {
73
+ export const compileScoreList = (config, referenceUrl, activeRouteProp, isRelativeReference) => {
72
74
  // Flag to check if the Portal set any active links or if there are any exact matches
73
75
  let hadAnyActiveLink = false;
74
76
  const scoreList = [];
@@ -77,7 +79,8 @@ export const compileScoreList = (config, compareUrl, activeRouteProp) => {
77
79
  .forEach(mainNav => {
78
80
  var _a;
79
81
  try {
80
- const score = compareRoutes(compareUrl, new URL(mainNav.url), activeRouteProp);
82
+ const navItemUrl = new URL(mainNav.url);
83
+ const score = compareRoutes(referenceUrl, navItemUrl, isRelativeReference, activeRouteProp);
81
84
  hadAnyActiveLink = updateScoreList(scoreList, score, { main: mainNav, score }, hadAnyActiveLink);
82
85
  }
83
86
  catch (_b) {
@@ -93,8 +96,8 @@ export const compileScoreList = (config, compareUrl, activeRouteProp) => {
93
96
  return;
94
97
  }
95
98
  try {
96
- const url = new URL(linklist.url);
97
- const score = compareRoutes(compareUrl, url, activeRouteProp);
99
+ const flyoutNavUrl = new URL(linklist.url);
100
+ const score = compareRoutes(referenceUrl, flyoutNavUrl, isRelativeReference, activeRouteProp);
98
101
  hadAnyActiveLink = updateScoreList(scoreList, score, { main: mainNav, sub: linklist, score }, hadAnyActiveLink);
99
102
  }
100
103
  catch (_a) {
@@ -119,46 +122,48 @@ function updateScoreList(scoreList, score, scoreListItem, hadAnyActiveLink) {
119
122
  return hadActiveLink;
120
123
  }
121
124
  /**
122
- * Compare two URLs for similarity based on a match mode
123
- * @param baseUrl Browser URL
124
- * @param compareUrl Navigatgion URL
125
+ * Compare a nav item URL against the reference URL for similarity
126
+ * @param referenceUrl URL we're comparing against (from window.location or custom)
127
+ * @param navItemUrl URL from the navigation item
125
128
  * @param matchMode exact or auto matching
126
- * @returns Score
129
+ * @returns Score indicating how well the URLs match
127
130
  */
128
- export const compareRoutes = (baseUrl, compareUrl, matchMode) => {
129
- // One url is not defined or they don't share the same orign
130
- if (baseUrl === null || compareUrl === null || baseUrl.origin !== compareUrl.origin) {
131
+ export const compareRoutes = (referenceUrl, navItemUrl, isRelativeReference, matchMode) => {
132
+ if (referenceUrl === null || navItemUrl === null) {
133
+ return 0;
134
+ }
135
+ // Only compare origins if reference URL is not relative
136
+ if (!isRelativeReference && referenceUrl.origin !== navItemUrl.origin) {
131
137
  return 0;
132
138
  }
133
- const baseUrlPath = baseUrl.pathname.toLocaleLowerCase();
134
- const compareUrlPath = compareUrl.pathname.toLocaleLowerCase();
135
- // Exact match, origin and pathname are the same
136
- if (baseUrlPath === compareUrlPath) {
139
+ const referenceUrlPath = referenceUrl.pathname.toLocaleLowerCase();
140
+ const navItemUrlPath = navItemUrl.pathname.toLocaleLowerCase();
141
+ // Exact match, pathname is the same
142
+ if (referenceUrlPath === navItemUrlPath) {
137
143
  return Infinity;
138
144
  }
139
- // The basepath is longer than the comparison, a match is impossible
140
- if (baseUrl.pathname.length < compareUrl.pathname.length) {
145
+ // The reference path is shorter than nav item path, a match is impossible
146
+ if (referenceUrl.pathname.length < navItemUrl.pathname.length) {
141
147
  return 0;
142
148
  }
143
149
  if (matchMode === 'auto') {
144
- const baseSegments = [
145
- baseUrl.origin.toLocaleLowerCase(),
146
- ...baseUrlPath.split('/').filter(x => x !== null && x !== ''),
150
+ const referenceSegments = [
151
+ referenceUrl.origin.toLocaleLowerCase(),
152
+ ...referenceUrlPath.split('/').filter(x => x !== null && x !== ''),
147
153
  ];
148
- const compareSegments = [
149
- compareUrl.origin.toLocaleLowerCase(),
150
- ...compareUrlPath.split('/').filter(x => x !== null && x !== ''),
154
+ const navItemSegments = [
155
+ navItemUrl.origin.toLocaleLowerCase(),
156
+ ...navItemUrlPath.split('/').filter(x => x !== null && x !== ''),
151
157
  ];
152
- const score = getSimilarityScore(baseSegments, compareSegments);
153
- // If only some segments match, but not the whole smaller array, it's not a match
154
- return Math.min(baseSegments.length, compareSegments.length) === score ? score : 0;
158
+ const score = getSimilarityScore(referenceSegments, navItemSegments);
159
+ return Math.min(referenceSegments.length, navItemSegments.length) === score ? score : 0;
155
160
  }
156
161
  return 0;
157
162
  };
158
163
  /**
159
164
  * Check how many items in an array match
160
- * @param a Base array
161
- * @param b Compare array
165
+ * @param a Reference array
166
+ * @param b Nav item array to compare
162
167
  * @returns Score
163
168
  */
164
169
  export const getSimilarityScore = (a, b) => {
@@ -17,7 +17,7 @@ import { d as defineCustomElement$2 } from './post-skiplinks2.js';
17
17
  /**
18
18
  * Activate the current route based on the config and the match mode
19
19
  * @param config Main Navigation Config
20
- * @param activeRouteProp Match mode
20
+ * @param activeRouteProp Match mode or custom URL to compare against
21
21
  * @returns Modified Main Navigation Config
22
22
  */
23
23
  const markActiveRoute = (config, activeRouteProp) => {
@@ -25,26 +25,28 @@ const markActiveRoute = (config, activeRouteProp) => {
25
25
  if (activeRouteProp === false) {
26
26
  return config;
27
27
  }
28
- // Set compare URL and check if activeRouteProp is valid
29
- let compareUrl;
28
+ // Set reference URL to compare nav items against
29
+ let referenceUrl;
30
+ let isRelativeReference = false;
30
31
  config = resetOverrideConfig(config);
31
32
  if (activeRouteProp === 'auto' || activeRouteProp === 'exact') {
32
33
  // Check if an active route is already configured, set override to that and return
33
34
  if (hasActivePortalRoute(config)) {
34
35
  return resetActiveStateToPortalConfig(config);
35
36
  }
36
- compareUrl = new URL(window.location.href);
37
+ referenceUrl = new URL(window.location.href);
37
38
  }
38
39
  else {
39
40
  try {
40
- compareUrl = new URL(activeRouteProp, document.location.origin);
41
+ isRelativeReference = activeRouteProp.startsWith('/') || activeRouteProp.startsWith('./');
42
+ referenceUrl = new URL(activeRouteProp, window.location.href);
41
43
  }
42
44
  catch (error) {
43
45
  console.warn(`Active Route: ${activeRouteProp} is not a valid URL. Navigation highlighting has been disabled.`);
44
46
  return config;
45
47
  }
46
48
  }
47
- const scoreList = compileScoreList(config, compareUrl, activeRouteProp);
49
+ const scoreList = compileScoreList(config, referenceUrl, activeRouteProp, isRelativeReference);
48
50
  if (scoreList.length === 0) {
49
51
  // No match found or already active links defined
50
52
  return config;
@@ -78,13 +80,13 @@ const resetOverrideConfig = (config) => {
78
80
  });
79
81
  };
80
82
  /**
81
- * Compile a list of scores based on the map mode, sorted in descending order
83
+ * Compile a list of scores based on how well nav items match the reference URL
82
84
  * @param config Main Nav Config
83
- * @param compareUrl Current Browser URL or a custom URL
85
+ * @param referenceUrl URL to compare nav items against (window.location or custom)
84
86
  * @param activeRouteProp Match mode
85
87
  * @returns A list of scored URLs if any matched
86
88
  */
87
- const compileScoreList = (config, compareUrl, activeRouteProp) => {
89
+ const compileScoreList = (config, referenceUrl, activeRouteProp, isRelativeReference) => {
88
90
  // Flag to check if the Portal set any active links or if there are any exact matches
89
91
  let hadAnyActiveLink = false;
90
92
  const scoreList = [];
@@ -93,7 +95,8 @@ const compileScoreList = (config, compareUrl, activeRouteProp) => {
93
95
  .forEach(mainNav => {
94
96
  var _a;
95
97
  try {
96
- const score = compareRoutes(compareUrl, new URL(mainNav.url), activeRouteProp);
98
+ const navItemUrl = new URL(mainNav.url);
99
+ const score = compareRoutes(referenceUrl, navItemUrl, isRelativeReference, activeRouteProp);
97
100
  hadAnyActiveLink = updateScoreList(scoreList, score, { main: mainNav, score }, hadAnyActiveLink);
98
101
  }
99
102
  catch (_b) {
@@ -109,8 +112,8 @@ const compileScoreList = (config, compareUrl, activeRouteProp) => {
109
112
  return;
110
113
  }
111
114
  try {
112
- const url = new URL(linklist.url);
113
- const score = compareRoutes(compareUrl, url, activeRouteProp);
115
+ const flyoutNavUrl = new URL(linklist.url);
116
+ const score = compareRoutes(referenceUrl, flyoutNavUrl, isRelativeReference, activeRouteProp);
114
117
  hadAnyActiveLink = updateScoreList(scoreList, score, { main: mainNav, sub: linklist, score }, hadAnyActiveLink);
115
118
  }
116
119
  catch (_a) {
@@ -135,46 +138,48 @@ function updateScoreList(scoreList, score, scoreListItem, hadAnyActiveLink) {
135
138
  return hadActiveLink;
136
139
  }
137
140
  /**
138
- * Compare two URLs for similarity based on a match mode
139
- * @param baseUrl Browser URL
140
- * @param compareUrl Navigatgion URL
141
+ * Compare a nav item URL against the reference URL for similarity
142
+ * @param referenceUrl URL we're comparing against (from window.location or custom)
143
+ * @param navItemUrl URL from the navigation item
141
144
  * @param matchMode exact or auto matching
142
- * @returns Score
145
+ * @returns Score indicating how well the URLs match
143
146
  */
144
- const compareRoutes = (baseUrl, compareUrl, matchMode) => {
145
- // One url is not defined or they don't share the same orign
146
- if (baseUrl === null || compareUrl === null || baseUrl.origin !== compareUrl.origin) {
147
+ const compareRoutes = (referenceUrl, navItemUrl, isRelativeReference, matchMode) => {
148
+ if (referenceUrl === null || navItemUrl === null) {
149
+ return 0;
150
+ }
151
+ // Only compare origins if reference URL is not relative
152
+ if (!isRelativeReference && referenceUrl.origin !== navItemUrl.origin) {
147
153
  return 0;
148
154
  }
149
- const baseUrlPath = baseUrl.pathname.toLocaleLowerCase();
150
- const compareUrlPath = compareUrl.pathname.toLocaleLowerCase();
151
- // Exact match, origin and pathname are the same
152
- if (baseUrlPath === compareUrlPath) {
155
+ const referenceUrlPath = referenceUrl.pathname.toLocaleLowerCase();
156
+ const navItemUrlPath = navItemUrl.pathname.toLocaleLowerCase();
157
+ // Exact match, pathname is the same
158
+ if (referenceUrlPath === navItemUrlPath) {
153
159
  return Infinity;
154
160
  }
155
- // The basepath is longer than the comparison, a match is impossible
156
- if (baseUrl.pathname.length < compareUrl.pathname.length) {
161
+ // The reference path is shorter than nav item path, a match is impossible
162
+ if (referenceUrl.pathname.length < navItemUrl.pathname.length) {
157
163
  return 0;
158
164
  }
159
165
  if (matchMode === 'auto') {
160
- const baseSegments = [
161
- baseUrl.origin.toLocaleLowerCase(),
162
- ...baseUrlPath.split('/').filter(x => x !== null && x !== ''),
166
+ const referenceSegments = [
167
+ referenceUrl.origin.toLocaleLowerCase(),
168
+ ...referenceUrlPath.split('/').filter(x => x !== null && x !== ''),
163
169
  ];
164
- const compareSegments = [
165
- compareUrl.origin.toLocaleLowerCase(),
166
- ...compareUrlPath.split('/').filter(x => x !== null && x !== ''),
170
+ const navItemSegments = [
171
+ navItemUrl.origin.toLocaleLowerCase(),
172
+ ...navItemUrlPath.split('/').filter(x => x !== null && x !== ''),
167
173
  ];
168
- const score = getSimilarityScore(baseSegments, compareSegments);
169
- // If only some segments match, but not the whole smaller array, it's not a match
170
- return Math.min(baseSegments.length, compareSegments.length) === score ? score : 0;
174
+ const score = getSimilarityScore(referenceSegments, navItemSegments);
175
+ return Math.min(referenceSegments.length, navItemSegments.length) === score ? score : 0;
171
176
  }
172
177
  return 0;
173
178
  };
174
179
  /**
175
180
  * Check how many items in an array match
176
- * @param a Base array
177
- * @param b Compare array
181
+ * @param a Reference array
182
+ * @param b Nav item array to compare
178
183
  * @returns Score
179
184
  */
180
185
  const getSimilarityScore = (a, b) => {
@@ -373,7 +378,7 @@ const setMainNavigationIds = (navMainEntities) => {
373
378
  };
374
379
 
375
380
  const name = "@swisspost/internet-header";
376
- const version = "1.15.12";
381
+ const version = "1.15.13";
377
382
  const description = "The header for client facing applications.";
378
383
  const author = "Swiss Post <design-system@post.ch>";
379
384
  const license = "Apache-2.0";
@@ -414,7 +419,7 @@ const scripts = {
414
419
  generate: "stencil generate"
415
420
  };
416
421
  const dependencies = {
417
- "@swisspost/design-system-styles": "workspace:8.9.4",
422
+ "@swisspost/design-system-styles": "workspace:8.10.0",
418
423
  "body-scroll-lock": "4.0.0-beta.0",
419
424
  "iframe-resizer": "4.4.5",
420
425
  jquery: "3.7.1",
package/dist/docs.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "timestamp": "2025-04-28T10:55:50",
2
+ "timestamp": "2025-05-05T12:45:06",
3
3
  "compiler": {
4
4
  "name": "@stencil/core",
5
5
  "version": "4.19.2",
package/dist/esm/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export { P as PostInternetHeader } from './post-internet-header-96053f9b.js';
1
+ export { P as PostInternetHeader } from './post-internet-header-c7e6cae4.js';
2
2
  export { P as PostInternetBreadcrumbs } from './post-internet-breadcrumbs-853096c4.js';
3
3
  export { P as PostInternetFooter } from './post-internet-footer-3a7024bf.js';
4
4
  export { P as PostSkiplinks } from './post-skiplinks-8c64cda3.js';