@coras-io/embed 0.11.0 → 0.13.0

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 (56) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/README.md +18 -8
  3. package/dist/components/attraction-card/base/attraction-card.mixin.js +17 -0
  4. package/dist/components/attraction-card/base/attraction-card.styles.js +10 -0
  5. package/dist/components/attraction-card/base/attraction-card.types.d.ts +2 -0
  6. package/dist/components/attraction-card/long/attraction-long-card.component.js +4 -2
  7. package/dist/components/attraction-card/short/attraction-short-card.component.d.ts +2 -0
  8. package/dist/components/attraction-card/short/attraction-short-card.component.js +16 -4
  9. package/dist/components/breadcrumbs/breadcrumb-item/breadcrumb-item.component.d.ts +5 -0
  10. package/dist/components/breadcrumbs/breadcrumb-item/breadcrumb-item.component.js +16 -3
  11. package/dist/components/breadcrumbs/breadcrumb-item/breadcrumb-item.styles.js +3 -1
  12. package/dist/components/button/button.component.d.ts +6 -0
  13. package/dist/components/button/button.component.js +31 -8
  14. package/dist/components/button/button.styles.js +8 -1
  15. package/dist/components/image/image.component.d.ts +12 -0
  16. package/dist/components/image/image.component.js +49 -6
  17. package/dist/components/text-section/text-section.component.js +1 -1
  18. package/dist/components/text-section/text-section.styles.js +1 -1
  19. package/dist/containers/footer/footer.component.d.ts +2 -0
  20. package/dist/containers/footer/footer.component.js +29 -22
  21. package/dist/containers/navbar/navbar.component.d.ts +3 -0
  22. package/dist/containers/navbar/navbar.component.js +33 -10
  23. package/dist/contexts/events.context.d.ts +8 -0
  24. package/dist/contexts/events.context.js +6 -0
  25. package/dist/core/images/srcset.d.ts +16 -0
  26. package/dist/core/images/srcset.js +21 -0
  27. package/dist/core/images/url.d.ts +1 -0
  28. package/dist/core/images/url.js +3 -1
  29. package/dist/core/utils/link-click.d.ts +8 -0
  30. package/dist/core/utils/link-click.js +20 -0
  31. package/dist/index.d.ts +1 -1
  32. package/dist/mixins/base.mixin.d.ts +3 -0
  33. package/dist/mixins/base.mixin.js +29 -1
  34. package/dist/sdk/mount.js +1 -0
  35. package/dist/sdk/types.d.ts +12 -0
  36. package/dist/sdk/url.d.ts +44 -2
  37. package/dist/sdk/url.js +54 -6
  38. package/dist/views/chrome-only-page/chrome-only-page.component.d.ts +2 -0
  39. package/dist/views/details-page/details-page.component.d.ts +4 -1
  40. package/dist/views/details-page/details-page.component.js +22 -41
  41. package/dist/views/details-page/partials/location-categories/location-categories.component.d.ts +2 -1
  42. package/dist/views/details-page/partials/location-categories/location-categories.component.js +18 -5
  43. package/dist/views/details-page/partials/location-highlights/location-highlights.component.d.ts +2 -1
  44. package/dist/views/details-page/partials/location-highlights/location-highlights.component.js +12 -5
  45. package/dist/views/help-page/help-page.component.d.ts +2 -0
  46. package/dist/views/landing-page/landing-page.component.d.ts +4 -1
  47. package/dist/views/landing-page/landing-page.component.js +21 -16
  48. package/dist/views/payment-page/partials/confirmation/confirmation.component.d.ts +2 -0
  49. package/dist/views/payment-page/partials/confirmation/confirmation.component.js +26 -6
  50. package/dist/views/payment-page/partials/confirmation/confirmation.styles.js +4 -0
  51. package/dist/views/payment-page/payment-page.component.d.ts +2 -0
  52. package/dist/views/search-page/search-page.component.d.ts +5 -2
  53. package/dist/views/search-page/search-page.component.js +41 -48
  54. package/dist/views/suggestion-widget/suggestion-widget.component.d.ts +6 -3
  55. package/dist/views/suggestion-widget/suggestion-widget.component.js +18 -8
  56. package/package.json +1 -1
@@ -5,19 +5,37 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
5
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6
6
  };
7
7
  import { LitElement, html } from "lit";
8
+ import { ifDefined } from "lit/directives/if-defined.js";
8
9
  import { localized, msg } from "@lit/localize";
9
10
  import { consume } from "@lit/context";
10
11
  import "../../components/footer-menu/footer-menu.js";
11
12
  import "../../components/footer-menu/footer-menu-item/footer-menu-item.js";
12
13
  import styles from "./footer.styles.js";
13
14
  import { ColorSchemeController } from "../../core/color-scheme.js";
14
- import { pageDispatchContext, } from "../../contexts/events.context.js";
15
+ import { pageDispatchContext, pageHrefContext, } from "../../contexts/events.context.js";
16
+ import { claimLinkClick } from "../../core/utils/link-click.js";
15
17
  let CorasFooter = class CorasFooter extends LitElement {
16
18
  constructor() {
17
19
  super(...arguments);
18
20
  this.colorScheme = new ColorSchemeController(this);
19
21
  }
20
22
  static { this.styles = styles; }
23
+ // A help link the host can route: a real link when the host builds URLs,
24
+ // and in-app navigation on a plain click either way.
25
+ renderHelpItem(label, target, slot) {
26
+ return html `
27
+ <coras-footer-menu-item
28
+ slot=${ifDefined(slot)}
29
+ href=${ifDefined(this._pageHref?.(target))}
30
+ @click=${(event) => {
31
+ if (claimLinkClick(event))
32
+ this._pageDispatch?.(target);
33
+ }}
34
+ >
35
+ ${label}
36
+ </coras-footer-menu-item>
37
+ `;
38
+ }
21
39
  willUpdate() {
22
40
  this.dataset.colorScheme = this.colorScheme.scheme;
23
41
  }
@@ -25,27 +43,18 @@ let CorasFooter = class CorasFooter extends LitElement {
25
43
  return html `
26
44
  <div class="container">
27
45
  <coras-footer-menu>
28
- <coras-footer-menu-item
29
- @click=${() => this._pageDispatch?.({
46
+ ${this.renderHelpItem(msg("Terms & Conditions"), {
30
47
  page: "help",
31
48
  content: "terms-and-conditions",
32
49
  })}
33
- >
34
- ${msg("Terms & Conditions")}
35
- </coras-footer-menu-item>
36
- <coras-footer-menu-item
37
- @click=${() => this._pageDispatch?.({
50
+ ${this.renderHelpItem(msg("Privacy"), {
38
51
  page: "help",
39
52
  content: "privacy-policy",
40
53
  })}
41
- >
42
- ${msg("Privacy")}
43
- </coras-footer-menu-item>
44
- <coras-footer-menu-item
45
- @click=${() => this._pageDispatch?.({ page: "help", content: "cookies" })}
46
- >
47
- ${msg("Cookies")}
48
- </coras-footer-menu-item>
54
+ ${this.renderHelpItem(msg("Cookies"), {
55
+ page: "help",
56
+ content: "cookies",
57
+ })}
49
58
  <coras-footer-menu-item
50
59
  href="https://coras.io/contact"
51
60
  target="_blank"
@@ -53,12 +62,7 @@ let CorasFooter = class CorasFooter extends LitElement {
53
62
  >
54
63
  ${msg("Partner with Coras")}
55
64
  </coras-footer-menu-item>
56
- <coras-footer-menu-item
57
- slot="right"
58
- @click=${() => this._pageDispatch?.({ page: "help" })}
59
- >
60
- ${msg("Help Centre")}
61
- </coras-footer-menu-item>
65
+ ${this.renderHelpItem(msg("Help Centre"), { page: "help" }, "right")}
62
66
  </coras-footer-menu>
63
67
  </div>
64
68
  `;
@@ -67,6 +71,9 @@ let CorasFooter = class CorasFooter extends LitElement {
67
71
  __decorate([
68
72
  consume({ context: pageDispatchContext })
69
73
  ], CorasFooter.prototype, "_pageDispatch", void 0);
74
+ __decorate([
75
+ consume({ context: pageHrefContext })
76
+ ], CorasFooter.prototype, "_pageHref", void 0);
70
77
  CorasFooter = __decorate([
71
78
  localized()
72
79
  ], CorasFooter);
@@ -51,6 +51,7 @@ export declare class CorasNavBar extends CorasNavBar_base implements SearchMixin
51
51
  private isBasketMobileOpen;
52
52
  currentPage: PageName;
53
53
  dispatchPageUpdate: (params: PageDispatchInput) => void;
54
+ private _pageHref?;
54
55
  private get shouldRenderMobileMenu();
55
56
  basket?: BasketContext;
56
57
  private isMobile;
@@ -103,7 +104,9 @@ export declare class CorasNavBar extends CorasNavBar_base implements SearchMixin
103
104
  private renderMobileMenuIcon;
104
105
  private renderReturnButton;
105
106
  private renderMobileMenuDrawer;
107
+ private get homeTarget();
106
108
  private handleLogoClick;
109
+ private handleHomeLinkClick;
107
110
  private renderBrand;
108
111
  private renderBrandHome;
109
112
  private renderSearchOnlyHeader;
@@ -32,7 +32,8 @@ import { renderSearchResultsOption } from "../../components/search-results-item/
32
32
  import { SearchMixin } from "../../mixins/search-mixin/search-mixin.js";
33
33
  import { addRecentlySelectedSearches, DrawerSubmenu, getLocaleLabel, getRecentlySelectedSearches, searchResultTypeToLocationPageMap, } from "./navbar.utils.js";
34
34
  import styles from "./navbar.styles.js";
35
- import { pageDispatchContext, } from "../../contexts/events.context.js";
35
+ import { pageDispatchContext, pageHrefContext, } from "../../contexts/events.context.js";
36
+ import { claimLinkClick } from "../../core/utils/link-click.js";
36
37
  import { assetsURLContext, currenciesContext, currencyContext, distributorIdContext, localeContext, localesContext, } from "../../contexts/properties.context.js";
37
38
  import { currentPageContext } from "../../contexts/current-page.context.js";
38
39
  import { clientContext } from "../../contexts/client.context.js";
@@ -96,11 +97,11 @@ let CorasNavBar = class CorasNavBar extends SearchMixin(LitElement) {
96
97
  // The logo is a home link. The embed owns no router, so it dispatches a
97
98
  // `landing` navigation the host applies (a no-op when already on landing).
98
99
  this.handleLogoClick = () => {
99
- this.dispatchPageUpdate({
100
- page: "landing",
101
- locale: this.locale,
102
- currency: this.currency,
103
- });
100
+ this.dispatchPageUpdate(this.homeTarget);
101
+ };
102
+ this.handleHomeLinkClick = (event) => {
103
+ if (claimLinkClick(event))
104
+ this.handleLogoClick();
104
105
  };
105
106
  }
106
107
  static { this.styles = styles; }
@@ -649,6 +650,13 @@ let CorasNavBar = class CorasNavBar extends SearchMixin(LitElement) {
649
650
  </coras-drawer>
650
651
  `;
651
652
  }
653
+ get homeTarget() {
654
+ return {
655
+ page: "landing",
656
+ locale: this.locale,
657
+ currency: this.currency,
658
+ };
659
+ }
652
660
  // The host's `brand` slot wins and keeps its own semantics: slotted content is
653
661
  // projected as-is, never wrapped, so a slotted link/button is not nested inside
654
662
  // our button (invalid interactive-in-interactive) and owns its own navigation.
@@ -666,8 +674,9 @@ let CorasNavBar = class CorasNavBar extends SearchMixin(LitElement) {
666
674
  }
667
675
  // A distributor with its own website links the logo straight there, the way its
668
676
  // main site does, and a real anchor keeps that a link (middle-click, new tab,
669
- // status bar). Without one there is no URL to link to, so the logo stays a
670
- // button dispatching the `landing` navigation for the host to route.
677
+ // status bar). Without one the logo links to the host's landing URL when the
678
+ // host gave the mount an `hrefFor`, routed in the app on a plain click, and
679
+ // otherwise stays a button dispatching the `landing` navigation.
671
680
  renderBrandHome(logo) {
672
681
  const image = html `<img
673
682
  class="brand-logo"
@@ -677,12 +686,23 @@ let CorasNavBar = class CorasNavBar extends SearchMixin(LitElement) {
677
686
  />`;
678
687
  // The URL comes from host config, so it is gated here rather than trusted.
679
688
  const href = safeUrl(this.logoHref);
680
- return href
689
+ if (href) {
690
+ return html `<a
691
+ class="brand-button"
692
+ part="brand-button"
693
+ href=${href}
694
+ aria-label=${msg("Go to the home page")}
695
+ >${image}</a
696
+ >`;
697
+ }
698
+ const homeHref = this._pageHref?.(this.homeTarget);
699
+ return homeHref
681
700
  ? html `<a
682
701
  class="brand-button"
683
702
  part="brand-button"
684
- href=${href}
703
+ href=${homeHref}
685
704
  aria-label=${msg("Go to the home page")}
705
+ @click=${this.handleHomeLinkClick}
686
706
  >${image}</a
687
707
  >`
688
708
  : html `<button
@@ -819,6 +839,9 @@ __decorate([
819
839
  __decorate([
820
840
  consume({ context: pageDispatchContext })
821
841
  ], CorasNavBar.prototype, "dispatchPageUpdate", void 0);
842
+ __decorate([
843
+ consume({ context: pageHrefContext })
844
+ ], CorasNavBar.prototype, "_pageHref", void 0);
822
845
  __decorate([
823
846
  consume({ context: basketContext, subscribe: true })
824
847
  ], CorasNavBar.prototype, "basket", void 0);
@@ -30,4 +30,12 @@ export type PageDispatchPayload = BasePageState & AllPageSpecificFields;
30
30
  export declare const pageDispatchContext: {
31
31
  __context__: (params: PageDispatchInput) => void;
32
32
  };
33
+ /**
34
+ * The host URL of the state a `dispatchPageUpdate` call would move to, for
35
+ * rendering that control as a link. `undefined` when the host gave the mount
36
+ * no `hrefFor`, so the control stays a button.
37
+ */
38
+ export declare const pageHrefContext: {
39
+ __context__: (params: PageDispatchInput) => string | undefined;
40
+ };
33
41
  export {};
@@ -1,2 +1,8 @@
1
1
  import { createContext } from "@lit/context";
2
2
  export const pageDispatchContext = createContext("coras-page-dispatch");
3
+ /**
4
+ * The host URL of the state a `dispatchPageUpdate` call would move to, for
5
+ * rendering that control as a link. `undefined` when the host gave the mount
6
+ * no `hrefFor`, so the control stays a button.
7
+ */
8
+ export const pageHrefContext = createContext("coras-page-href");
@@ -24,5 +24,21 @@ interface BuildSrcsetOptions extends Omit<ImgixOptions, "w" | "h" | "dpr"> {
24
24
  * straight to a `srcset` attribute without conditionals.
25
25
  */
26
26
  export declare function buildSrcset(src: string, widths?: readonly number[], options?: BuildSrcsetOptions): string;
27
+ export interface SourceSize {
28
+ width: number;
29
+ height: number;
30
+ }
31
+ /**
32
+ * The widest image imgix can cut from the source without enlarging it.
33
+ * `aspectRatio` is the ratio the image is cropped to: a crop narrower than
34
+ * the source runs out of height before it runs out of width.
35
+ */
36
+ export declare function maxWidthWithinSource(source: SourceSize, aspectRatio?: number): number;
37
+ /**
38
+ * Width candidates that never ask imgix to enlarge the source image. An
39
+ * enlarged image is a bigger download with no extra detail, so candidates
40
+ * wider than the source give way to one at the source's own size.
41
+ */
42
+ export declare function widthsWithinSource(widths: readonly number[], source: SourceSize, aspectRatio?: number): number[];
27
43
  export declare function buildSizes(preset: ImagePreset): string;
28
44
  export {};
@@ -29,6 +29,27 @@ export function buildSrcset(src, widths = RESPONSIVE_WIDTHS, options = {}) {
29
29
  })
30
30
  .join(", ");
31
31
  }
32
+ /**
33
+ * The widest image imgix can cut from the source without enlarging it.
34
+ * `aspectRatio` is the ratio the image is cropped to: a crop narrower than
35
+ * the source runs out of height before it runs out of width.
36
+ */
37
+ export function maxWidthWithinSource(source, aspectRatio) {
38
+ return Math.floor(aspectRatio
39
+ ? Math.min(source.width, source.height * aspectRatio)
40
+ : source.width);
41
+ }
42
+ /**
43
+ * Width candidates that never ask imgix to enlarge the source image. An
44
+ * enlarged image is a bigger download with no extra detail, so candidates
45
+ * wider than the source give way to one at the source's own size.
46
+ */
47
+ export function widthsWithinSource(widths, source, aspectRatio) {
48
+ const max = maxWidthWithinSource(source, aspectRatio);
49
+ if (widths.every((w) => w <= max))
50
+ return Array.from(widths);
51
+ return [...widths.filter((w) => w < max), max];
52
+ }
32
53
  /**
33
54
  * Slot presets for the `sizes` attribute. These describe the rendered size of
34
55
  * the image in the layout, NOT the viewport - which is exactly what `sizes`
@@ -20,4 +20,5 @@ export interface ImgixOptions {
20
20
  fpX?: number;
21
21
  fpY?: number;
22
22
  }
23
+ export declare const DEFAULT_QUALITY = 45;
23
24
  export declare function buildImgixUrl(src: string, opts?: ImgixOptions): string;
@@ -8,7 +8,9 @@
8
8
  * not call this helper.
9
9
  */
10
10
  const DEFAULT_AUTO = "compress,format";
11
- const DEFAULT_QUALITY = 85;
11
+ // The quality imgix itself uses for `auto=compress`. Photos at 85 were about
12
+ // a third larger with no visible gain at the sizes the SDK shows them.
13
+ export const DEFAULT_QUALITY = 45;
12
14
  export function buildImgixUrl(src, opts = {}) {
13
15
  if (!src)
14
16
  return "";
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Claims a click on a link the host routes. A plain left click is claimed: its
3
+ * default is prevented so the page does not load the href, and `true` tells the
4
+ * caller (or a listener up the tree) to emit the navigation intent instead. A
5
+ * modified click is left to the browser, which opens the href in a new tab or
6
+ * window, and is stopped from reaching the listeners that would also navigate.
7
+ */
8
+ export declare function claimLinkClick(event: MouseEvent): boolean;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Claims a click on a link the host routes. A plain left click is claimed: its
3
+ * default is prevented so the page does not load the href, and `true` tells the
4
+ * caller (or a listener up the tree) to emit the navigation intent instead. A
5
+ * modified click is left to the browser, which opens the href in a new tab or
6
+ * window, and is stopped from reaching the listeners that would also navigate.
7
+ */
8
+ export function claimLinkClick(event) {
9
+ const modified = event.button !== 0 ||
10
+ event.metaKey ||
11
+ event.ctrlKey ||
12
+ event.shiftKey ||
13
+ event.altKey;
14
+ if (modified) {
15
+ event.stopPropagation();
16
+ return false;
17
+ }
18
+ event.preventDefault();
19
+ return true;
20
+ }
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export { mount } from "./sdk/mount.js";
2
2
  export { CorasValidationError, type CorasValidationErrorCode, } from "./sdk/validation.js";
3
- export type { CorasApp, CorasConfig, CorasLoyaltyProgramme, CorasTheme, CorasColorScheme, CorasChrome, CorasChromeOptions, CorasNavbar, CorasFooter, CorasManagedNavbar, CorasManagedFooter, CorasNavbarSlotName, CorasNavbarProps, CorasMountOptions, CorasState, CorasUpdate, CorasConfigUpdate, CorasNavigateOptions, CorasCallbacks, CorasLogger, CorasObservabilityEvent, CorasPageName, CorasPageParams, CorasPageParamsByPage, CorasLandingPageParams, CorasSearchPageParams, CorasDetailsPageParams, CorasPaymentPageParams, CorasHelpPageParams, CorasSuggestionWidgetParams, CorasHostEventMap, CorasHostEventName, CorasReadyDetail, CorasNavigateDetail, CorasStateChangeDetail, CorasReservationCreatedDetail, CorasPaymentStatusDetail, CorasPaymentStatus, CorasErrorDetail, CorasNavigationSource, } from "./sdk/types.js";
3
+ export type { CorasApp, CorasConfig, CorasLoyaltyProgramme, CorasTheme, CorasColorScheme, CorasChrome, CorasChromeOptions, CorasNavbar, CorasFooter, CorasManagedNavbar, CorasManagedFooter, CorasNavbarSlotName, CorasNavbarProps, CorasMountOptions, CorasState, CorasUpdate, CorasConfigUpdate, CorasNavigateOptions, CorasCallbacks, CorasLogger, CorasHrefFor, CorasObservabilityEvent, CorasPageName, CorasPageParams, CorasPageParamsByPage, CorasLandingPageParams, CorasSearchPageParams, CorasDetailsPageParams, CorasPaymentPageParams, CorasHelpPageParams, CorasSuggestionWidgetParams, CorasHostEventMap, CorasHostEventName, CorasReadyDetail, CorasNavigateDetail, CorasStateChangeDetail, CorasReservationCreatedDetail, CorasPaymentStatusDetail, CorasPaymentStatus, CorasErrorDetail, CorasNavigationSource, } from "./sdk/types.js";
4
4
  export type { SupportedLocales } from "./core/types/core/locale.js";
5
5
  export type { SupportedCurrencies } from "./core/types/core/currency.js";
6
6
  export { allLocales } from "./core/i18n/locale-codes.js";
@@ -5,6 +5,7 @@ import type { Client } from "openapi-fetch";
5
5
  import type { LoyaltyProgramme } from "../core/utils/loyalty.js";
6
6
  import type { Constructor } from "../contexts/utils.js";
7
7
  import { type PageDispatchInput } from "../contexts/events.context.js";
8
+ import type { CorasHrefFor } from "../sdk/types.js";
8
9
  import { type Logger } from "../core/logger.js";
9
10
  import type { PageParamsEvent } from "../core/pages.js";
10
11
  type BaseMixinProperties<CustomPageContext extends PageParamsEvent> = {
@@ -18,9 +19,11 @@ type BaseMixinProperties<CustomPageContext extends PageParamsEvent> = {
18
19
  loyaltyPoints: boolean;
19
20
  loyaltyProgramme: LoyaltyProgramme | null;
20
21
  logger: Logger;
22
+ hrefFor: CorasHrefFor | null;
21
23
  client: Client<paths>;
22
24
  getPageProperties(): CustomPageContext;
23
25
  dispatchPageUpdate(params: PageDispatchInput): void;
26
+ pageUpdateHref(params: PageDispatchInput): string | undefined;
24
27
  };
25
28
  export declare const BaseMixin: <T extends Constructor<LitElement>, CustomPageContext extends PageParamsEvent>(superClass: T) => Constructor<BaseMixinProperties<CustomPageContext>> & T;
26
29
  export {};
@@ -13,7 +13,7 @@ import { allLocales } from "../core/i18n/locale-codes.js";
13
13
  import { getTextDirection } from "../core/utils/locale.js";
14
14
  import { ContextRoot, provide } from "@lit/context";
15
15
  import { clientContext } from "../contexts/client.context.js";
16
- import { pageDispatchContext, } from "../contexts/events.context.js";
16
+ import { pageDispatchContext, pageHrefContext, } from "../contexts/events.context.js";
17
17
  import { fireEvent } from "../core/events.js";
18
18
  import { classifyPageUpdate } from "../sdk/navigation-intent.js";
19
19
  import { apiHostContext, assetsURLContext, loyaltyPointsContext, loyaltyProgrammeContext, currenciesContext, currencyContext, distributorIdContext, localeContext, localesContext, } from "../contexts/properties.context.js";
@@ -38,7 +38,10 @@ export const BaseMixin = (superClass) => {
38
38
  // Set by the SDK mount, not an attribute: a host cannot pass a function
39
39
  // through markup, so the default stays silent until `mount` wires one.
40
40
  this.logger = NOOP_LOGGER;
41
+ // The host's `hrefFor` mount option, set by the SDK mount like the logger.
42
+ this.hrefFor = null;
41
43
  this._pageDispatch = this.dispatchPageUpdate.bind(this);
44
+ this._pageHref = this.pageUpdateHref.bind(this);
42
45
  // Replays context requests that arrive before their provider renders
43
46
  // inside this page's shadow DOM. See docs/ARCHITECTURE.md.
44
47
  new ContextRoot().attach(this);
@@ -46,6 +49,25 @@ export const BaseMixin = (superClass) => {
46
49
  getPageProperties() {
47
50
  return {};
48
51
  }
52
+ // The link for a control that would call `dispatchPageUpdate` with the same
53
+ // params. Unlike a same-page dispatch, which merges the current params in,
54
+ // the link names the target state alone: a crumb or the logo opened in a
55
+ // new tab lands on that page as a visitor would reach it, not with this
56
+ // page's filters carried over.
57
+ pageUpdateHref(params) {
58
+ if (!this.hrefFor)
59
+ return undefined;
60
+ const { page, currency, locale, href, text, ...pageSpecific } = params;
61
+ void text;
62
+ return this.hrefFor({
63
+ page: page ?? this.currentPage,
64
+ params: pageSpecific,
65
+ locale: locale ?? this.locale,
66
+ currency: currency ?? this.currency,
67
+ ...(href != null ? { href } : {}),
68
+ source: "embed",
69
+ });
70
+ }
49
71
  dispatchPageUpdate(params) {
50
72
  const { page, currency, locale, href, text, ...pageSpecific } = params;
51
73
  // External-link text is not part of the minimal public payload.
@@ -134,8 +156,14 @@ export const BaseMixin = (superClass) => {
134
156
  __decorate([
135
157
  provide({ context: loggerContext })
136
158
  ], BaseMixinElement.prototype, "logger", void 0);
159
+ __decorate([
160
+ property({ attribute: false })
161
+ ], BaseMixinElement.prototype, "hrefFor", void 0);
137
162
  __decorate([
138
163
  provide({ context: pageDispatchContext })
139
164
  ], BaseMixinElement.prototype, "_pageDispatch", void 0);
165
+ __decorate([
166
+ provide({ context: pageHrefContext })
167
+ ], BaseMixinElement.prototype, "_pageHref", void 0);
140
168
  return BaseMixinElement;
141
169
  };
package/dist/sdk/mount.js CHANGED
@@ -178,6 +178,7 @@ export function createMountWith(registry) {
178
178
  // set directly on the element; pages that honor it read their own property.
179
179
  element.preview = preview;
180
180
  element.logger = toLogger(options.logger);
181
+ element.hrefFor = options.hrefFor ?? null;
181
182
  const paramDefaults = captureParamDefaults(element, entry);
182
183
  applyParams(element, entry, currentParams, paramDefaults);
183
184
  // Chrome is rebuilt per page rather than moved: the navbar/footer consume
@@ -242,6 +242,7 @@ export type CorasCallbacks = {
242
242
  onError?: (detail: CorasErrorDetail) => void;
243
243
  onObservability?: (event: CorasObservabilityEvent) => void;
244
244
  };
245
+ export type CorasHrefFor = (intent: CorasNavigateDetail) => string | undefined;
245
246
  /**
246
247
  * `mount()` is generic over `P`, so a call passing a literal page gets its own
247
248
  * params checked against it. The alias is deliberately *not* distributed over
@@ -266,6 +267,17 @@ export type CorasMountOptions<P extends CorasPageName = CorasPageName> = {
266
267
  */
267
268
  content?: HTMLElement;
268
269
  logger?: CorasLogger;
270
+ /**
271
+ * The URL the host would route a navigation intent to. When set, pages render
272
+ * their internal navigation (attraction cards, breadcrumbs, the navbar logo,
273
+ * the footer's help links) as real `<a href>` links that crawlers follow,
274
+ * built the same way `onNavigate` routes them (usually with `buildCorasUrl`).
275
+ * A plain click on such a link still emits `onNavigate` and never loads the
276
+ * page; a modified or middle click opens the href the browser's way. Return
277
+ * `undefined` for an intent that has no link. Unset, those controls stay
278
+ * buttons.
279
+ */
280
+ hrefFor?: CorasHrefFor;
269
281
  /** Reject unknown config/param keys instead of ignoring them. */
270
282
  strict?: boolean;
271
283
  /**
package/dist/sdk/url.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { SupportedCurrencies } from "../core/types/core/currency.js";
2
2
  import type { SupportedLocales } from "../core/types/core/locale.js";
3
- import type { CorasPageName, CorasPageParams } from "./types.js";
3
+ import type { CorasHrefFor, CorasNavigateDetail, CorasPageName, CorasPageParams, CorasStateChangeDetail } from "./types.js";
4
4
  /**
5
5
  * Framework-neutral URL helpers for host-controlled routing. The host owns the
6
6
  * URL; these helpers translate between a Coras state and a canonical URL so each
@@ -47,8 +47,19 @@ export type CorasUrlStrategy = {
47
47
  * collide with real ids.
48
48
  */
49
49
  reservedSegments?: Partial<Record<CorasRoutablePage, string>>;
50
+ /**
51
+ * How a built URL writes the locale segment: the canonical `en-IE` by
52
+ * default, or `"lower"` for `en-ie`. Parsing accepts either case.
53
+ */
54
+ localeCase?: "canonical" | "lower";
55
+ /**
56
+ * A currency a built URL leaves out, as a code or as a function of the
57
+ * state's locale. A parsed URL without a currency has `currency: undefined`,
58
+ * so the host supplies the same default when it reads one.
59
+ */
60
+ defaultCurrency?: SupportedCurrencies | ((locale?: SupportedLocales) => SupportedCurrencies | undefined);
50
61
  };
51
- export declare const DEFAULT_URL_STRATEGY: Required<Omit<CorasUrlStrategy, "reservedSegments">> & {
62
+ export declare const DEFAULT_URL_STRATEGY: Required<Omit<CorasUrlStrategy, "reservedSegments" | "localeCase" | "defaultCurrency">> & {
52
63
  reservedSegments: Partial<Record<CorasRoutablePage, string>>;
53
64
  };
54
65
  /** Parse a (relative or absolute) URL into a Coras state. */
@@ -66,3 +77,34 @@ export declare function createCorasUrlState(strategy?: CorasUrlStrategy): {
66
77
  normalize: typeof normalizeCorasUrlState;
67
78
  isSame: typeof isSameCorasUrlState;
68
79
  };
80
+ /**
81
+ * What the routing glue needs from a URL helper: `createCorasUrlState()`
82
+ * itself, or a wrapper around its `build` for a host whose URL shape differs
83
+ * from the strategy (a lower-case locale segment, a currency left out).
84
+ */
85
+ export type CorasUrlBuilder = Pick<ReturnType<typeof createCorasUrlState>, "build">;
86
+ export type CorasRoutingOptions = {
87
+ /** The URL helper to build with, or the strategy to bind one to. */
88
+ url: CorasUrlBuilder | CorasUrlStrategy;
89
+ /** Shows `href` as a new history entry; `intent` is the detail it was built from. */
90
+ navigate: (href: string, intent: CorasNavigateDetail) => void;
91
+ /** Shows `href` in place of the current history entry. */
92
+ replace: (href: string, state: CorasStateChangeDetail) => void;
93
+ /** Opens an external link. By default a new tab that cannot reach the opener. */
94
+ external?: (href: string, intent: CorasNavigateDetail) => void;
95
+ };
96
+ export type CorasRouting = {
97
+ hrefFor: CorasHrefFor;
98
+ onNavigate: (intent: CorasNavigateDetail) => void;
99
+ onStateChange: (state: CorasStateChangeDetail) => void;
100
+ };
101
+ /**
102
+ * The three mount options that connect Coras to a host router, built from one
103
+ * URL helper so the link a control renders (`hrefFor`) and the route a click
104
+ * takes (`onNavigate`) are always the same URL. `onNavigate` pushes a history
105
+ * entry through `navigate`, `onStateChange` replaces the current one through
106
+ * `replace`, and an intent carrying `href` is an external link: it gets no
107
+ * `hrefFor` and is opened by `external` instead of routed. Spread the result
108
+ * into `mount()`.
109
+ */
110
+ export declare function createCorasRouting({ url: urlOrStrategy, navigate, replace, external, }: CorasRoutingOptions): CorasRouting;
package/dist/sdk/url.js CHANGED
@@ -141,6 +141,15 @@ export function parseCorasUrl(url, strategy = {}) {
141
141
  ...(currency ? { currency } : {}),
142
142
  };
143
143
  }
144
+ // The state's currency, unless the strategy leaves that one out as the default.
145
+ function currencyToWrite(state, defaultCurrency) {
146
+ if (!state.currency)
147
+ return undefined;
148
+ const omitted = typeof defaultCurrency === "function"
149
+ ? defaultCurrency(state.locale)
150
+ : defaultCurrency;
151
+ return state.currency === omitted ? undefined : state.currency;
152
+ }
144
153
  /** Build a canonical URL from a Coras state. */
145
154
  export function buildCorasUrl(state, strategy = {}) {
146
155
  const resolved = resolveStrategy(strategy);
@@ -156,10 +165,14 @@ export function buildCorasUrl(state, strategy = {}) {
156
165
  const base = trimSlashes(resolved.basePath);
157
166
  if (base)
158
167
  segments.push(base);
159
- if (resolved.localeInPath && state.locale)
160
- segments.push(state.locale);
161
- if (resolved.currencyInPath && state.currency)
162
- segments.push(state.currency);
168
+ if (resolved.localeInPath && state.locale) {
169
+ segments.push(resolved.localeCase === "lower"
170
+ ? state.locale.toLowerCase()
171
+ : state.locale);
172
+ }
173
+ const currency = currencyToWrite(state, resolved.defaultCurrency);
174
+ if (resolved.currencyInPath && currency)
175
+ segments.push(currency);
163
176
  const params = (state.params ?? {});
164
177
  if (state.page === "details") {
165
178
  const id = params.id;
@@ -195,8 +208,8 @@ export function buildCorasUrl(state, strategy = {}) {
195
208
  if (value != null && value !== "")
196
209
  query.set(key, String(value));
197
210
  }
198
- if (!resolved.currencyInPath && state.currency) {
199
- query.set(resolved.currencyParam, state.currency);
211
+ if (!resolved.currencyInPath && currency) {
212
+ query.set(resolved.currencyParam, currency);
200
213
  }
201
214
  const path = `/${segments.join("/")}`.replace(/\/+/g, "/");
202
215
  const queryString = query.toString();
@@ -243,3 +256,38 @@ export function createCorasUrlState(strategy = {}) {
243
256
  isSame: isSameCorasUrlState,
244
257
  };
245
258
  }
259
+ function urlStateOf(detail) {
260
+ return {
261
+ page: detail.page,
262
+ params: detail.params ?? {},
263
+ ...(detail.locale ? { locale: detail.locale } : {}),
264
+ ...(detail.currency ? { currency: detail.currency } : {}),
265
+ };
266
+ }
267
+ function openInNewTab(href) {
268
+ window.open(href, "_blank", "noopener,noreferrer");
269
+ }
270
+ /**
271
+ * The three mount options that connect Coras to a host router, built from one
272
+ * URL helper so the link a control renders (`hrefFor`) and the route a click
273
+ * takes (`onNavigate`) are always the same URL. `onNavigate` pushes a history
274
+ * entry through `navigate`, `onStateChange` replaces the current one through
275
+ * `replace`, and an intent carrying `href` is an external link: it gets no
276
+ * `hrefFor` and is opened by `external` instead of routed. Spread the result
277
+ * into `mount()`.
278
+ */
279
+ export function createCorasRouting({ url: urlOrStrategy, navigate, replace, external = openInNewTab, }) {
280
+ const url = "build" in urlOrStrategy && typeof urlOrStrategy.build === "function"
281
+ ? urlOrStrategy
282
+ : createCorasUrlState(urlOrStrategy);
283
+ return {
284
+ hrefFor: (intent) => intent.href ? undefined : url.build(urlStateOf(intent)),
285
+ onNavigate: (intent) => {
286
+ if (intent.href)
287
+ external(intent.href, intent);
288
+ else
289
+ navigate(url.build(urlStateOf(intent)), intent);
290
+ },
291
+ onStateChange: (state) => replace(url.build(urlStateOf(state)), state),
292
+ };
293
+ }
@@ -12,9 +12,11 @@ declare const CorasChromeOnlyPage_base: import("../../contexts/utils.js").Constr
12
12
  loyaltyPoints: boolean;
13
13
  loyaltyProgramme: import("../../index.js").CorasLoyaltyProgramme | null;
14
14
  logger: import("../../core/logger.js").Logger;
15
+ hrefFor: import("../../index.js").CorasHrefFor | null;
15
16
  client: import("openapi-fetch").Client<import("../../core/types/api-schema.js").paths>;
16
17
  getPageProperties(): PageParamsEvent;
17
18
  dispatchPageUpdate(params: import("../../contexts/events.context.js").PageDispatchInput): void;
19
+ pageUpdateHref(params: import("../../contexts/events.context.js").PageDispatchInput): string | undefined;
18
20
  }> & typeof LitElement;
19
21
  /**
20
22
  * The managed chrome around markup the host owns, with no Coras page inside it.
@@ -1,5 +1,6 @@
1
1
  import { type CSSResultGroup, LitElement, type PropertyValues } from "lit";
2
2
  import { Task } from "@lit/task";
3
+ import type { PageDispatchInput } from "../../contexts/events.context.js";
3
4
  import type { SupportedLocales, SupportedCurrencies } from "../../core/types/index.js";
4
5
  import "../../components/button/button.js";
5
6
  import "../../components/attraction-header/attraction-header.js";
@@ -48,9 +49,11 @@ declare const CorasDetailsPage_base: import("../../contexts/utils.js").Construct
48
49
  loyaltyPoints: boolean;
49
50
  loyaltyProgramme: import("../../core/utils/loyalty.js").LoyaltyProgramme | null;
50
51
  logger: import("../../core/logger.js").Logger;
52
+ hrefFor: import("../../index.js").CorasHrefFor | null;
51
53
  client: import("openapi-fetch").Client<import("../../core/types/api-schema.js").paths>;
52
54
  getPageProperties(): DetailsPageParamsEvent;
53
- dispatchPageUpdate(params: import("../../contexts/events.context.js").PageDispatchInput): void;
55
+ dispatchPageUpdate(params: PageDispatchInput): void;
56
+ pageUpdateHref(params: PageDispatchInput): string | undefined;
54
57
  }> & typeof LitElement;
55
58
  /**
56
59
  * @fires coras:navigate