@hagicode/hagilight-core 0.21.1-dev.212.1.g4291274 → 0.22.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.
- package/PromotoBanner.astro +8 -6
- package/README.md +3 -3
- package/dist/consent-open.d.ts +11 -0
- package/dist/consent-open.js +18 -0
- package/dist/consent-popup.js +5 -1
- package/dist/promoto-banner.d.ts +4 -4
- package/dist/promoto-banner.js +20 -16
- package/package.json +1 -1
package/PromotoBanner.astro
CHANGED
|
@@ -65,7 +65,9 @@ const { fallback, locale = Astro.currentLocale ?? 'en', siteId } = Astro.props;
|
|
|
65
65
|
* Layout model: the card is content on top, one action row on the bottom.
|
|
66
66
|
* The call to action sits bottom-left; pager and pause share that row at the
|
|
67
67
|
* bottom-right, so controls never take a column or a row of their own. Dismiss
|
|
68
|
-
* is a small corner mark.
|
|
68
|
+
* is a small corner mark. The card always sits on the bottom edge: it is never lifted
|
|
69
|
+
* above the consent panel, it steps aside while that panel is open (and for a domain's
|
|
70
|
+
* first visits it is not rendered at all). Wide: media beside the copy. Portrait phones: a small
|
|
69
71
|
* thumbnail beside the title only. Short landscape viewports: no thumbnail and a
|
|
70
72
|
* one-line description, so the card stays a thin strip.
|
|
71
73
|
*/
|
|
@@ -111,7 +113,7 @@ const { fallback, locale = Astro.currentLocale ?? 'en', siteId } = Astro.props;
|
|
|
111
113
|
/* Centered in the content area: a theme narrows it by setting these two insets on :root. */
|
|
112
114
|
inset-inline-start: var(--hagilight-promoto-inset-start, 0px);
|
|
113
115
|
inset-inline-end: var(--hagilight-promoto-inset-end, 0px);
|
|
114
|
-
bottom:
|
|
116
|
+
bottom: max(1rem, env(safe-area-inset-bottom));
|
|
115
117
|
width: min(42rem, calc(100% - var(--hagilight-promoto-inset-start, 0px) - var(--hagilight-promoto-inset-end, 0px) - 1rem - 2 * max(env(safe-area-inset-left, 0px), env(safe-area-inset-right, 0px))));
|
|
116
118
|
margin-inline: auto;
|
|
117
119
|
overflow: hidden;
|
|
@@ -126,7 +128,7 @@ const { fallback, locale = Astro.currentLocale ?? 'en', siteId } = Astro.props;
|
|
|
126
128
|
transition: opacity 0.24s ease, transform 0.62s var(--promoto-ease), visibility 0s linear;
|
|
127
129
|
}
|
|
128
130
|
|
|
129
|
-
/* Rises into place on first render and whenever it returns from the footer or the
|
|
131
|
+
/* Rises into place on first render and whenever it returns from the footer or the consent panel. */
|
|
130
132
|
.hagilight-promoto[data-state='ready'] .hagilight-promoto__shell {
|
|
131
133
|
animation: hagilight-promoto-rise 0.62s var(--promoto-ease) backwards;
|
|
132
134
|
}
|
|
@@ -137,7 +139,7 @@ const { fallback, locale = Astro.currentLocale ?? 'en', siteId } = Astro.props;
|
|
|
137
139
|
}
|
|
138
140
|
|
|
139
141
|
.hagilight-promoto[data-state='footer-hidden'] .hagilight-promoto__shell,
|
|
140
|
-
.hagilight-promoto[data-state='
|
|
142
|
+
.hagilight-promoto[data-state='consent-hidden'] .hagilight-promoto__shell {
|
|
141
143
|
opacity: 0;
|
|
142
144
|
visibility: hidden;
|
|
143
145
|
pointer-events: none;
|
|
@@ -468,7 +470,7 @@ const { fallback, locale = Astro.currentLocale ?? 'en', siteId } = Astro.props;
|
|
|
468
470
|
}
|
|
469
471
|
|
|
470
472
|
.hagilight-promoto__shell {
|
|
471
|
-
bottom: calc(env(safe-area-inset-bottom) + 0.5rem
|
|
473
|
+
bottom: calc(env(safe-area-inset-bottom) + 0.5rem);
|
|
472
474
|
width: min(calc(100vw - 1rem - 2 * max(env(safe-area-inset-left, 0px), env(safe-area-inset-right, 0px))), 28rem);
|
|
473
475
|
border-radius: 0.875rem;
|
|
474
476
|
}
|
|
@@ -537,7 +539,7 @@ const { fallback, locale = Astro.currentLocale ?? 'en', siteId } = Astro.props;
|
|
|
537
539
|
}
|
|
538
540
|
|
|
539
541
|
.hagilight-promoto__shell {
|
|
540
|
-
bottom:
|
|
542
|
+
bottom: max(0.5rem, env(safe-area-inset-bottom));
|
|
541
543
|
}
|
|
542
544
|
|
|
543
545
|
.hagilight-promoto__media {
|
package/README.md
CHANGED
|
@@ -474,9 +474,9 @@ Dismissal is stored in `localStorage` under `hagilight:promoto-banner:dismissed-
|
|
|
474
474
|
|
|
475
475
|
The shared banner (`PromotoBanner`, `loadActivePromotions`) displays only promotions whose `platforms` array in Index's `/promote.json` includes `web`, in addition to being enabled, inside their activation window, and matched with `/promote_content.json`. This follows the `platforms` flag documented in the Index README. An entry whose `platforms` is missing, empty, or not an array of strings is not displayed, other values such as `hagicode` are ignored, and matching is exact (`Web` does not match). When no promotion remains, the banner shows its site fallback or stays hidden, as before.
|
|
476
476
|
|
|
477
|
-
The card rises into place when it first appears and when it returns from the Footer or the
|
|
477
|
+
The card rises into place when it first appears and when it returns from the Footer or the consent popup, and sinks away when dismissed; browsers without `@starting-style` or `linear()` get the same movement with a plain ease-out or none, and `prefers-reduced-motion` turns all of it off along with automatic rotation. With more than one promotion, a thin line along the card's bottom edge fills over eight seconds and the next promotion arrives when it completes; hovering the card, tabbing into it, or pressing pause holds the line where it is. Slide content settles in the direction of travel (Previous reverses it). The call to action, muted copy and hover colors read Starlight tokens (`--sl-color-text-accent` on `--sl-color-black`, `--sl-color-gray-2`, `--sl-color-text-high`) and fall back to values derived from the card's own text color, so themes that map only part of the ramp stay legible on dark cards. Override `--promoto-cta-bg`, `--promoto-cta-fg`, `--promoto-muted`, `--promoto-strong` or `--promoto-rotation` on `.hagilight-promoto` to retune them.
|
|
478
478
|
|
|
479
|
-
The banner
|
|
479
|
+
The banner is not rendered at all during a domain's first 30 visits, wherever the page is scrolled. After that it yields while the cookie consent popup is open and while the Footer is in view. It always sits on the bottom edge and is never lifted above the popup; it fades in once the popup has left. Every page load, refresh, and page-to-page navigation counts as a visit; scrolling and hash changes do not. The per-domain counter is stored in the visitor's browser under `hagilight:promoto-banner:visit-count:<hostname>` and is never sent anywhere.
|
|
480
480
|
|
|
481
481
|
A promotion's `image` may also carry `sources`, the alternative image files that Index publishes in the order AVIF, WebP, then the original. The banner renders them as a `<picture>` in that order, with the original as its `<img>`, and skips any entry whose `type` is not an `image/*` media type or whose URL is unsafe. Each `src` is resolved against `https://index.hagicode.com` when the promotion documents load. If the browser fails to load a tier, the banner removes it and the next tier is used. A card without `sources` renders the plain `<img>` as before, and `sources` never affect the dismissal signature, so a dismissed banner stays dismissed when only its image chain changes.
|
|
482
482
|
|
|
@@ -640,7 +640,7 @@ Analytics is off until a visitor grants it. With consent on (the default wheneve
|
|
|
640
640
|
- `@hagicode/hagilight-core/consent` (browser-safe): `getConsent()` returns `{ necessary: 'granted', analytics: 'granted' | 'denied' | 'undecided' }`; `setConsent({ analytics })`; `onConsentChange(callback)` returns an unsubscribe function; `openConsentPreferences()` reopens the popup. None of them throw. `configureConsent({ regionHook })` takes an optional region check: returning `false` means consent is not required; any other result or a throw means it is. The hook may also answer `'required'`, `'notRequired'`, `'unknown'` or a promise of one of these. The regional options are described in [Regional analytics consent](#regional-analytics-consent).
|
|
641
641
|
- Events: `hagilight:consent-change` on `document`, with the new state as `detail`, after each effective change.
|
|
642
642
|
- Storage: cookie `hagicode_consent` (`Domain=.hagicode.com`, `Path=/`, `SameSite=Lax`, `Secure`, 180 days) on hagicode.com hosts only, and localStorage `hagicode:consent` everywhere. The record is `1|granted|<epoch seconds>|<policyVersion>`, expires after 180 days, and a changed policy version asks again. With storage blocked the choice holds for the page session only.
|
|
643
|
-
- `@hagicode/hagilight-core/CookieConsent` (Astro): renders the popup. Pass `providers` (the enabled analytics providers), and optionally `privacyUrl` (an absolute HTTP(S) URL or a `/` path; omitted means no privacy link) and `policyVersion` (1 to 32 letters, digits, dots, underscores or hyphens). Mount it only when a provider is enabled. The popup publishes `--hagilight-consent-clearance` so the
|
|
643
|
+
- `@hagicode/hagilight-core/CookieConsent` (Astro): renders the popup. Pass `providers` (the enabled analytics providers), and optionally `privacyUrl` (an absolute HTTP(S) URL or a `/` path; omitted means no privacy link) and `policyVersion` (1 to 32 letters, digits, dots, underscores or hyphens). Mount it only when a provider is enabled. The popup publishes `--hagilight-consent-clearance` so the footers stay clear of it, and sets `data-hagilight-consent-open` on the root (with a `hagilight:consent-open-change` event) so the promotion banner yields while it is shown.
|
|
644
644
|
- `@hagicode/hagilight-core/consent-markup` holds the shared markup, the config descriptor and the option validators; `@hagicode/hagilight-core/consent-copy` holds the localized copy for every `SITE_LOCALES` code.
|
|
645
645
|
|
|
646
646
|
51LA is loaded without screen recording or session replay: `LA.init` sets `autoTrack` and `hashMode` and never `screenRecord`. Session replay in this stack is PostHog's, controlled by the project's PostHog settings, and the popup discloses it only for PostHog.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether the consent panel is on screen. The popup sets `data-hagilight-consent-open` on the root while its panel is shown
|
|
3
|
+
* (including while it fades out) and dispatches `hagilight:consent-open-change` when that flips. The promotion banner reads
|
|
4
|
+
* this to yield: one floating card at a time, and the consent decision outranks a promotion. A tiny module of its own so
|
|
5
|
+
* the banner does not import the popup.
|
|
6
|
+
*/
|
|
7
|
+
export declare const CONSENT_OPEN_ATTRIBUTE = "data-hagilight-consent-open";
|
|
8
|
+
export declare const CONSENT_OPEN_EVENT = "hagilight:consent-open-change";
|
|
9
|
+
export declare function isConsentPanelOpen(): boolean;
|
|
10
|
+
/** Sets the root attribute and announces a change. Calling it again with the same value does nothing. */
|
|
11
|
+
export declare function setConsentPanelOpen(open: boolean): void;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether the consent panel is on screen. The popup sets `data-hagilight-consent-open` on the root while its panel is shown
|
|
3
|
+
* (including while it fades out) and dispatches `hagilight:consent-open-change` when that flips. The promotion banner reads
|
|
4
|
+
* this to yield: one floating card at a time, and the consent decision outranks a promotion. A tiny module of its own so
|
|
5
|
+
* the banner does not import the popup.
|
|
6
|
+
*/
|
|
7
|
+
export const CONSENT_OPEN_ATTRIBUTE = 'data-hagilight-consent-open';
|
|
8
|
+
export const CONSENT_OPEN_EVENT = 'hagilight:consent-open-change';
|
|
9
|
+
export function isConsentPanelOpen() {
|
|
10
|
+
return typeof document !== 'undefined' && document.documentElement.hasAttribute(CONSENT_OPEN_ATTRIBUTE);
|
|
11
|
+
}
|
|
12
|
+
/** Sets the root attribute and announces a change. Calling it again with the same value does nothing. */
|
|
13
|
+
export function setConsentPanelOpen(open) {
|
|
14
|
+
if (typeof document === 'undefined' || isConsentPanelOpen() === open)
|
|
15
|
+
return;
|
|
16
|
+
document.documentElement.toggleAttribute(CONSENT_OPEN_ATTRIBUTE, open);
|
|
17
|
+
document.dispatchEvent(new Event(CONSENT_OPEN_EVENT));
|
|
18
|
+
}
|
package/dist/consent-popup.js
CHANGED
|
@@ -2,11 +2,13 @@
|
|
|
2
2
|
* Browser wiring for the consent popup. `mountConsentPopup` reveals the markup from `consent-markup.ts` only for an
|
|
3
3
|
* undecided visitor whose region decision is `required` or `unknown`. It stays hidden while the decision is pending and
|
|
4
4
|
* for `notRequired`. It connects Accept and Reject to `setConsent`, toggles the details, reflects the current choice when
|
|
5
|
-
* `openConsentPreferences()` is called, and publishes the popup's height as `--hagilight-consent-clearance` on the root
|
|
5
|
+
* `openConsentPreferences()` is called, and publishes the popup's height as `--hagilight-consent-clearance` on the root
|
|
6
|
+
* (the footers pad by it) and its presence through `consent-open.ts` (the promotion banner yields while it is shown).
|
|
6
7
|
* A replay opt-in request (`openConsentPreferences('replay')`) shows the replay section instead. The details slide open
|
|
7
8
|
* and the panel fades out through the Web Animations API, and both snap under reduced motion. It never moves or traps focus.
|
|
8
9
|
*/
|
|
9
10
|
import { currentRegionConfig, CONSENT_PREFERENCES_EVENT, getConsent, onConsentChange, openConsentPreferences, regionalBehavior, setConsent, } from './consent.js';
|
|
11
|
+
import { setConsentPanelOpen } from './consent-open.js';
|
|
10
12
|
import { pageRegionSource, startRegionResolution } from './consent-region.js';
|
|
11
13
|
export const CONSENT_CLEARANCE_PROPERTY = '--hagilight-consent-clearance';
|
|
12
14
|
/** Space between the popup and the banner or footer it lifts. */
|
|
@@ -31,6 +33,8 @@ function canAnimate(element) {
|
|
|
31
33
|
}
|
|
32
34
|
function publishClearance(panel) {
|
|
33
35
|
try {
|
|
36
|
+
// The panel counts as open until its leave animation ends, so the promotion banner waits for it to be gone.
|
|
37
|
+
setConsentPanelOpen(!panel.hidden);
|
|
34
38
|
const root = document.documentElement;
|
|
35
39
|
// A panel that is leaving no longer holds space: the banner and footer settle back while it fades.
|
|
36
40
|
if (panel.hidden || panel.dataset.leaving === 'true') {
|
package/dist/promoto-banner.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { type PromotionCard, type PromotionImage, type PromotionImageSource } from './promotions.js';
|
|
2
|
-
export type PromotionVisibility = 'dismissed' | '
|
|
2
|
+
export type PromotionVisibility = 'consent-hidden' | 'dismissed' | 'early-visit' | 'footer-hidden' | 'hidden' | 'ready';
|
|
3
3
|
export declare function selectPromotionCards(remote: PromotionCard[], fallback?: PromotionCard | null): PromotionCard[];
|
|
4
4
|
export declare function getPromotionImageSources(image: PromotionImage | undefined): PromotionImageSource[];
|
|
5
5
|
export declare function getPromotionSetSignature(cards: PromotionCard[]): string | null;
|
|
6
|
-
|
|
7
|
-
export declare function
|
|
6
|
+
/** True while the visit being made is one of the domain's first, when the banner is not rendered. */
|
|
7
|
+
export declare function isEarlyVisit(visitCount: number): boolean;
|
|
8
8
|
export declare function getVisitCountKey(hostname: string): string;
|
|
9
9
|
export declare function parseVisitCount(raw: string | null): number;
|
|
10
|
-
export declare function getPromotionVisibility(cards: PromotionCard[], signature: string | null, dismissedSignature: string | null, footerVisible: boolean,
|
|
10
|
+
export declare function getPromotionVisibility(cards: PromotionCard[], signature: string | null, dismissedSignature: string | null, footerVisible: boolean, earlyVisit?: boolean, consentOpen?: boolean): PromotionVisibility;
|
|
11
11
|
export declare function getNextPromotionIndex(index: number, count: number, direction: -1 | 1): number;
|
|
12
12
|
export declare function shouldAutoRotate(count: number, paused: boolean, reducedMotion: boolean, documentVisible: boolean, visibility: PromotionVisibility): boolean;
|
|
13
13
|
export declare function recordSiteVisit(): number;
|
package/dist/promoto-banner.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { gaEventAttributes } from './analytics-events.js';
|
|
2
|
+
import { CONSENT_OPEN_EVENT, isConsentPanelOpen } from './consent-open.js';
|
|
2
3
|
import { classifyLink, getLinkRel, withCampaignUtm } from './link-policy.js';
|
|
3
4
|
import { capturePromoto, createPromotoAnalytics, } from './promoto-analytics.js';
|
|
4
5
|
import { loadActivePromotions, } from './promotions.js';
|
|
@@ -7,12 +8,14 @@ const ELEMENT_NAME = 'hagilight-promoto-banner';
|
|
|
7
8
|
* Dismissal is recorded once for the whole card set, not per promotion: `localStorage` holds the
|
|
8
9
|
* signature of every card (id, copy, link and image), with no expiry, scoped per origin. Changing any
|
|
9
10
|
* card shows the banner again. A failed write is not persisted, so the banner returns on the next load.
|
|
10
|
-
*
|
|
11
|
+
* Staying away during a domain's first visits, while the consent panel is open, and while the footer is in
|
|
12
|
+
* view are not dismissals.
|
|
11
13
|
*/
|
|
12
14
|
const DISMISSED_SIGNATURE_KEY = 'hagilight:promoto-banner:dismissed-signature';
|
|
13
15
|
const VISIT_COUNT_KEY_PREFIX = 'hagilight:promoto-banner:visit-count:';
|
|
14
16
|
const VISIT_EVENT = 'hagilight:promoto-visit';
|
|
15
|
-
|
|
17
|
+
/** Visits 1 to this number do not render the banner at all, wherever the page is scrolled. */
|
|
18
|
+
const EARLY_VISIT_LIMIT = 30;
|
|
16
19
|
const ROTATION_INTERVAL_MS = 8000;
|
|
17
20
|
const DISMISS_DURATION_MS = 220;
|
|
18
21
|
const REFRESH_INTERVAL_MS = 5 * 60 * 1000;
|
|
@@ -81,11 +84,9 @@ export function getPromotionSetSignature(cards) {
|
|
|
81
84
|
image?.variant ?? '', image?.width ?? 0, image?.height ?? 0,
|
|
82
85
|
]));
|
|
83
86
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
export function isPageTopRuleActive(visitCount) {
|
|
88
|
-
return visitCount <= PAGE_TOP_VISIT_LIMIT;
|
|
87
|
+
/** True while the visit being made is one of the domain's first, when the banner is not rendered. */
|
|
88
|
+
export function isEarlyVisit(visitCount) {
|
|
89
|
+
return visitCount <= EARLY_VISIT_LIMIT;
|
|
89
90
|
}
|
|
90
91
|
export function getVisitCountKey(hostname) {
|
|
91
92
|
return `${VISIT_COUNT_KEY_PREFIX}${hostname}`;
|
|
@@ -96,14 +97,16 @@ export function parseVisitCount(raw) {
|
|
|
96
97
|
const count = Number(raw);
|
|
97
98
|
return Number.isSafeInteger(count) ? count : 0;
|
|
98
99
|
}
|
|
99
|
-
export function getPromotionVisibility(cards, signature, dismissedSignature, footerVisible,
|
|
100
|
+
export function getPromotionVisibility(cards, signature, dismissedSignature, footerVisible, earlyVisit = false, consentOpen = false) {
|
|
100
101
|
if (!cards.length)
|
|
101
102
|
return 'hidden';
|
|
102
103
|
if (signature && signature === dismissedSignature)
|
|
103
104
|
return 'dismissed';
|
|
104
|
-
if (
|
|
105
|
-
return '
|
|
106
|
-
|
|
105
|
+
if (earlyVisit)
|
|
106
|
+
return 'early-visit';
|
|
107
|
+
if (consentOpen)
|
|
108
|
+
return 'consent-hidden';
|
|
109
|
+
return footerVisible ? 'footer-hidden' : 'ready';
|
|
107
110
|
}
|
|
108
111
|
export function getNextPromotionIndex(index, count, direction) {
|
|
109
112
|
return count > 0 ? (index + direction + count) % count : 0;
|
|
@@ -143,7 +146,7 @@ function countVisit(storage, key) {
|
|
|
143
146
|
catch {
|
|
144
147
|
return 0;
|
|
145
148
|
}
|
|
146
|
-
if (!
|
|
149
|
+
if (!isEarlyVisit(count))
|
|
147
150
|
return count;
|
|
148
151
|
try {
|
|
149
152
|
storage.setItem(key, String(count + 1));
|
|
@@ -283,6 +286,7 @@ export function definePromotoBannerElement() {
|
|
|
283
286
|
this.motionQuery?.addEventListener('change', this.onMotionChange);
|
|
284
287
|
document.addEventListener('astro:page-load', this.onPageLoad);
|
|
285
288
|
document.addEventListener(VISIT_EVENT, this.onLayoutChange);
|
|
289
|
+
document.addEventListener(CONSENT_OPEN_EVENT, this.onLayoutChange);
|
|
286
290
|
if (typeof ResizeObserver !== 'undefined') {
|
|
287
291
|
this.resizeObserver = new ResizeObserver(this.onLayoutChange);
|
|
288
292
|
if (this.footer)
|
|
@@ -306,6 +310,7 @@ export function definePromotoBannerElement() {
|
|
|
306
310
|
this.motionQuery?.removeEventListener('change', this.onMotionChange);
|
|
307
311
|
document.removeEventListener('astro:page-load', this.onPageLoad);
|
|
308
312
|
document.removeEventListener(VISIT_EVENT, this.onLayoutChange);
|
|
313
|
+
document.removeEventListener(CONSENT_OPEN_EVENT, this.onLayoutChange);
|
|
309
314
|
this.resizeObserver?.disconnect();
|
|
310
315
|
this.stopRotation();
|
|
311
316
|
this.stopRefresh();
|
|
@@ -505,10 +510,9 @@ export function definePromotoBannerElement() {
|
|
|
505
510
|
}
|
|
506
511
|
updateVisibility() {
|
|
507
512
|
const signature = getPromotionSetSignature(this.cards);
|
|
508
|
-
const
|
|
509
|
-
|
|
510
|
-
const
|
|
511
|
-
const hidden = state === 'hidden' || state === 'dismissed';
|
|
513
|
+
const state = getPromotionVisibility(this.cards, signature, this.dismissedSignature, this.isFooterVisible(), isEarlyVisit(siteVisitCount), isConsentPanelOpen());
|
|
514
|
+
// An early visit is not rendered at all; the other transient states fade out and back.
|
|
515
|
+
const hidden = state === 'hidden' || state === 'dismissed' || state === 'early-visit';
|
|
512
516
|
const shell = this.querySelector('[data-promoto-shell]');
|
|
513
517
|
this.hidden = hidden;
|
|
514
518
|
if (shell) {
|
package/package.json
CHANGED