/** * The visitor context both halves of a page agree on. * * Live copy is cached per context, so the copy a server reads for a request * and the copy the browser's stream later replays or fills must be keyed by * the same values. This module is the one place those values are bucketed: * the browser provider and the server helper both call the functions below, * so a bucket boundary cannot drift between them. * * Everything here is safe in a browser bundle: no network, no secrets. */ import type { ContentSource } from "./wire.js"; /** The four time-of-day buckets the SDK sends. */ export type TimeOfDay = "night" | "morning" | "afternoon" | "evening"; /** The device buckets the SDK sends. */ export type DeviceType = "mobile" | "desktop"; /** * The viewport media query that makes a browser "mobile". Narrower than * 768 CSS pixels is mobile; everything else, tablets included, is desktop. */ export declare const MOBILE_VIEWPORT_QUERY = "(max-width: 767px)"; /** * Bucket an hour of the day (0–23, in the visitor's time zone): before 6 is * night, before 12 morning, before 18 afternoon, the rest evening. */ export declare function timeOfDayForHour(hour: number): TimeOfDay; /** The device bucket for a viewport that does or does not match `MOBILE_VIEWPORT_QUERY`. */ export declare function deviceTypeForViewport(matchesMobileQuery: boolean): DeviceType; /** True for an IANA time zone name this runtime knows, such as `Europe/Stockholm`. */ export declare function isValidTimeZone(timeZone: string): boolean; /** * The hour (0–23) of `date` in `timeZone`. Without a time zone, the * runtime's local hour (in a browser, the visitor's own). */ export declare function hourInTimeZone(date: Date, timeZone?: string): number; /** * The visitor context a server derived for one request, for the browser to * adopt for the same page view (`SparkletreeProvider`'s `serverContext`). * * The browser then sends exactly these values instead of reading its own, so * its streams and the copy they cache are keyed the way the server read * them. A value the server left out is left out by the browser too. */ export interface ServerContext { deviceType?: DeviceType; timeOfDay?: TimeOfDay; /** IANA time zone, e.g. `Europe/Stockholm`. */ timezone?: string; /** The visitor's preferred language tag, e.g. `sv-SE`. */ language?: string; /** * The variant the server read for, by pin key: the campaign id, or the * surface id for a surface-addressed island. Pinned for the page view * before any stream opens, so every island of that campaign or surface * tells the same story the server rendered. */ pins?: Record; /** * Identifies the page view the server rendered. The provider scopes * variant pins, slot memory and impressions to it, so a new server render * (a navigation, a refresh) is a new page view in the browser too, and its * pins are in place before any island's stream opens. */ viewId?: string; } /** The context keys a `ServerContext` decides for the page view. */ export declare const SERVER_CONTEXT_KEYS: readonly ["deviceType", "timeOfDay", "timezone", "language"]; /** * `context` with the server's decisions applied: each of * `SERVER_CONTEXT_KEYS` takes the server's value, or is removed when the * server had none. Without a `serverContext`, `context` is returned as is. */ export declare function applyServerContext(context: Record, serverContext: ServerContext | null | undefined): Record; /** * Copy already produced for this view, ready for the `initialCopy` option of * `useIsland`, `Hero` and `Cta`. It renders visibly from the first frame, * settled and final. */ export interface InitialCopy { copy: { greeting?: string; headline?: string; body?: string; cta?: string; }; /** Where the copy came from: `cached` for copy read from the live-copy cache. */ contentSource: ContentSource; /** The variant the copy belongs to. Pins the page's variant. */ variantId?: string; /** The campaign the copy belongs to. Impressions attribute to it. */ campaignId?: string; /** * For cached copy: `fresh`, or `stale` when it was past its freshness * window but still within its serving window. Reported with the * impression. */ freshness?: "fresh" | "stale"; } //# sourceMappingURL=visitorContext.d.ts.map