@pushwoosh/websdk-common 6.30.1 → 6.32.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.
@@ -1,8 +1,9 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import { useState } from 'react';
3
3
  import { INBOX_KNOWN_LAYOUTS, INBOX_WIDGET_CSS } from './constants';
4
- import { formatInboxMessageTime, getInboxHeroUrl, getInboxIconInitial, getInboxMobileTexts, getInboxTextDirection, getInboxValidSlides, isInboxContentEmpty, resolveInboxLayout, resolveInboxWidgetAppearance } from './helpers';
4
+ import { formatInboxMessageTime, getInboxHeroUrl, getInboxIconInitial, getInboxMobileTexts, getInboxValidSlides, isInboxContentEmpty, resolveInboxLayout, resolveInboxWidgetAppearance } from './helpers';
5
5
  import { InboxWebCell, inboxWidgetPreviewFrame } from './InboxWidgetReader';
6
+ import { detectTextDirection } from '../shared/textDirection';
6
7
  const MAIN = '#4B5057';
7
8
  const LOCKED = '#767C82';
8
9
  const PHANTOM = '#9AA0A6';
@@ -613,7 +614,7 @@ export function InboxCellPreview(props) {
613
614
  const texts = getInboxMobileTexts(picked, layout);
614
615
  const useAppIcon = layout === 'classic' && !picked.iconUrl && !!appIconUrl;
615
616
  const Cell = platform === 'android' ? AndroidCell : IOSCell;
616
- const rtl = !isEmpty && getInboxTextDirection(texts.title, texts.body) === 'rtl';
617
+ const rtl = !isEmpty && detectTextDirection(texts.title, texts.body) === 'rtl';
617
618
  return _jsx("div", {
618
619
  dir: rtl ? 'rtl' : undefined,
619
620
  style: frame,
@@ -16,8 +16,6 @@ export declare function getInboxMobileTexts(content: InboxCellContent, layout: I
16
16
  title: string;
17
17
  body: string;
18
18
  };
19
- /** 'rtl' when most letters of the copy read right to left; markup and Liquid do not vote. */
20
- export declare function getInboxTextDirection(...texts: (string | undefined)[]): 'rtl' | 'ltr';
21
19
  /** The colored initial a classic cell shows when there is no icon. */
22
20
  export declare function getInboxIconInitial(content: InboxCellContent): string;
23
21
  /** Date label of a web widget message: relative within a day of `now`, then `D Mon YYYY, H:mm` in local time. */
package/inbox/helpers.js CHANGED
@@ -76,22 +76,6 @@ export function getInboxMobileTexts(content, layout) {
76
76
  body: content.body || ''
77
77
  };
78
78
  }
79
- const RTL_LETTER = /[\p{Script=Arabic}\p{Script=Hebrew}\p{Script=Syriac}\p{Script=Thaana}\p{Script=Nko}\p{Script=Samaritan}\p{Script=Mandaic}\p{Script=Adlam}\p{Script=Hanifi_Rohingya}\p{Script=Mende_Kikakui}\p{Script=Yezidi}]/u;
80
- const LETTER = /\p{L}/u;
81
- const NOT_COPY = /<[^>]*>|\{\{[\s\S]*?\}\}|\{%[\s\S]*?%\}/g;
82
- /** 'rtl' when most letters of the copy read right to left; markup and Liquid do not vote. */
83
- export function getInboxTextDirection(...texts) {
84
- let rtl = 0;
85
- let ltr = 0;
86
- for (const char of texts.join(' ').replace(NOT_COPY, '')) {
87
- if (RTL_LETTER.test(char)) {
88
- rtl += 1;
89
- } else if (LETTER.test(char)) {
90
- ltr += 1;
91
- }
92
- }
93
- return rtl > ltr ? 'rtl' : 'ltr';
94
- }
95
79
  /** The colored initial a classic cell shows when there is no icon. */
96
80
  export function getInboxIconInitial(content) {
97
81
  return (content.title || content.body || '?').trim().charAt(0).toUpperCase() || '?';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pushwoosh/websdk-common",
3
- "version": "6.30.1",
3
+ "version": "6.32.0",
4
4
  "description": "Code shared by the Pushwoosh WebSDK and the Control Panel, one entry point per module (web-popups: web popup model and renderer; subscription-widget: push subscription widget model and renderer; inbox: web inbox widget and inbox cell previews)",
5
5
  "main": "index.js",
6
6
  "module": "index.js",
@@ -34,10 +34,10 @@
34
34
  "@types/react-dom": "^19.3.0",
35
35
  "jsdom": "^30.1.3",
36
36
  "preact": "^10.29.8",
37
- "react": "^19.3.0",
38
- "react-dom": "^19.3.0",
37
+ "react": "19.3.0",
38
+ "react-dom": "19.3.0",
39
39
  "typescript": "^6.0.3",
40
- "vitest": "^4.1.12"
40
+ "vitest": "^5.1.1"
41
41
  },
42
42
  "peerDependencies": {
43
43
  "react": "^19.0.0"
@@ -0,0 +1,3 @@
1
+ export type TextDirection = 'ltr' | 'rtl';
2
+ /** 'rtl' when most letters of the copy read right to left; markup and Liquid do not vote. */
3
+ export declare function detectTextDirection(...texts: (string | undefined)[]): TextDirection;
@@ -0,0 +1,16 @@
1
+ const RTL_LETTER = /[\p{Script=Arabic}\p{Script=Hebrew}\p{Script=Syriac}\p{Script=Thaana}\p{Script=Nko}\p{Script=Samaritan}\p{Script=Mandaic}\p{Script=Adlam}\p{Script=Hanifi_Rohingya}\p{Script=Mende_Kikakui}\p{Script=Yezidi}]/u;
2
+ const LETTER = /\p{L}/u;
3
+ const NOT_COPY = /<[^>]*>|\{\{[\s\S]*?\}\}|\{%[\s\S]*?%\}/g;
4
+ /** 'rtl' when most letters of the copy read right to left; markup and Liquid do not vote. */
5
+ export function detectTextDirection(...texts) {
6
+ let rtl = 0;
7
+ let ltr = 0;
8
+ for (const char of texts.join(' ').replace(NOT_COPY, '')) {
9
+ if (RTL_LETTER.test(char)) {
10
+ rtl += 1;
11
+ } else if (LETTER.test(char)) {
12
+ ltr += 1;
13
+ }
14
+ }
15
+ return rtl > ltr ? 'rtl' : 'ltr';
16
+ }
@@ -1,15 +1,16 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
- import { useContext, useEffect, useState } from 'react';
2
+ import { useContext, useEffect, useMemo, useState } from 'react';
3
3
  import { useColorScheme } from './colorScheme';
4
4
  import { webPopupButtonPillStyle, webPopupFormInputStyle, webPopupRatingScores, webPopupTextColor, webPopupSlotGap, webPopupSlotRole, WEB_POPUP_BG_SECTION_FALLBACK, WEB_POPUP_BUTTON_SLOT_PADDING, WEB_POPUP_FONT_STACK, WEB_POPUP_EMAIL_PATTERN, WEB_POPUP_KEYFRAMES, WEB_POPUP_PAGE_TRANSITION_MS, WEB_POPUP_RETRY_ERROR, WEB_POPUP_TEXT_SLOT_PADDING, WEB_POPUP_TEXT_VARIANT_STYLES } from './constants';
5
5
  import { ConsentSlotView, EmailInputSlotView, SubmitSlotView, TagInputSlotView } from './form-slots';
6
6
  import { useWebPopupFormSession, WebPopupFormSessionContext } from './formSession';
7
7
  import { WEB_POPUP_GLYPH_PATHS, WEB_POPUP_THUMB_UP_PATH } from './glyphs';
8
- import { applyWebPopupSubscribeOutcome, placementMaxSize, resolveWebPopupPages, safeUrl, sanitizeWebPopupHtml, startPageOf, webPopupLinkTargetAttrs } from './helpers';
8
+ import { applyWebPopupSubscribeOutcome, placementMaxSize, resolveWebPopupPages, safeUrl, sanitizeWebPopupHtml, startPageOf, webPopupCssTextAlign, webPopupDirection, webPopupLinkTargetAttrs } from './helpers';
9
9
  import { webPopupBackgroundImageStyle, webPopupContainerStyle, webPopupScrimGradient } from './layout';
10
10
  import { resolveWebPopupBoxChrome, resolveWebPopupColors, webPopupColorAlpha, webPopupDarkEnabled, webPopupImageSrc } from './palette';
11
11
  import { ProductsSlotView, WebPopupProductsContext } from './productsSlot';
12
12
  import { WEB_POPUP_CLOSE_ATTRIBUTE } from './styles';
13
+ import { useWebPopupSubscribeSession, WebPopupSubscribeContext } from './subscribeSession';
13
14
  import { webPopupTimerLabels, webPopupTimerRemaining } from './timer';
14
15
  // Renders a popup from its model by interpreting each page's embedded layout
15
16
  // tree — the same node vocabulary the editor's canvas builds from: container
@@ -32,7 +33,7 @@ function TextSlotView({
32
33
  }) {
33
34
  const style = {
34
35
  ...WEB_POPUP_TEXT_VARIANT_STYLES[slot.variant],
35
- textAlign: slot.align ?? align
36
+ textAlign: webPopupCssTextAlign(slot.align ?? align)
36
37
  };
37
38
  const color = webPopupTextColor(slot.variant, colors, inverse);
38
39
  if (color) style.color = color;
@@ -55,6 +56,7 @@ function ButtonSlotView({
55
56
  onSubscribeClose
56
57
  }) {
57
58
  const form = useContext(WebPopupFormSessionContext);
59
+ const subscribe = useContext(WebPopupSubscribeContext);
58
60
  const [askPhase, setAskPhase] = useState('idle');
59
61
  const pill = webPopupButtonPillStyle(slot.variant, colors);
60
62
  const wrapper = {};
@@ -86,8 +88,8 @@ function ButtonSlotView({
86
88
  action
87
89
  } = slot;
88
90
  // 'asking' guards the double click (one prompt, one registerDevice);
89
- // 'denied' stays disabled because the browser grants no second prompt.
90
- const spent = askPhase !== 'idle';
91
+ // an answered ask stays disabled because the browser grants no second prompt.
92
+ const spent = askPhase !== 'idle' || subscribe.answered;
91
93
  const ask = () => {
92
94
  if (!onRequestSubscribe || spent) return;
93
95
  setAskPhase('asking');
@@ -96,11 +98,14 @@ function ButtonSlotView({
96
98
  setAskPhase('idle');
97
99
  return;
98
100
  }
99
- if (applyWebPopupSubscribeOutcome(action, result, logger)) {
101
+ subscribe.markAnswered();
102
+ const next = applyWebPopupSubscribeOutcome(action, result, logger);
103
+ if (next === 'close') {
100
104
  onSubscribeClose?.();
101
105
  return;
102
106
  }
103
- setAskPhase('denied');
107
+ setAskPhase(result);
108
+ if (next !== 'stay') onPageChange(next.page);
104
109
  }).catch(() => setAskPhase('idle'));
105
110
  };
106
111
  return _jsx("div", {
@@ -153,7 +158,7 @@ function SlotMessageView({
153
158
  style: {
154
159
  ...WEB_POPUP_TEXT_VARIANT_STYLES.body,
155
160
  padding: WEB_POPUP_TEXT_SLOT_PADDING,
156
- textAlign: align,
161
+ textAlign: webPopupCssTextAlign(align),
157
162
  ...(color ? {
158
163
  color
159
164
  } : {})
@@ -265,7 +270,7 @@ function FormSlotView({
265
270
  noValidate: true,
266
271
  style: {
267
272
  margin: 0,
268
- textAlign: 'left'
273
+ textAlign: 'start'
269
274
  },
270
275
  onSubmit: event => {
271
276
  event.preventDefault();
@@ -353,7 +358,7 @@ function FormSlotView({
353
358
  }), phase === 'error' && _jsx("div", {
354
359
  style: {
355
360
  ...errorStyle,
356
- textAlign: align
361
+ textAlign: webPopupCssTextAlign(align)
357
362
  },
358
363
  children: WEB_POPUP_RETRY_ERROR
359
364
  })]
@@ -441,7 +446,7 @@ function TimerSlotView({
441
446
  return _jsx("div", {
442
447
  style: {
443
448
  padding: WEB_POPUP_TEXT_SLOT_PADDING,
444
- textAlign: align
449
+ textAlign: webPopupCssTextAlign(align)
445
450
  },
446
451
  children: _jsx("div", {
447
452
  style: {
@@ -786,7 +791,7 @@ function GlyphSlotView({
786
791
  return _jsx("div", {
787
792
  style: {
788
793
  padding: WEB_POPUP_TEXT_SLOT_PADDING,
789
- textAlign: align,
794
+ textAlign: webPopupCssTextAlign(align),
790
795
  lineHeight: 0
791
796
  },
792
797
  children: _jsx("svg", {
@@ -1233,8 +1238,10 @@ export function WebPopupBox({
1233
1238
  logger
1234
1239
  }) {
1235
1240
  const formSession = useWebPopupFormSession(params, page.key, onPageChange, onSubmitFormValues);
1241
+ const subscribeSession = useWebPopupSubscribeSession();
1236
1242
  const colors = resolveWebPopupColors(params, colorScheme);
1237
1243
  const box = resolveWebPopupBoxChrome(params, colorScheme);
1244
+ const dir = useMemo(() => webPopupDirection(params), [params]);
1238
1245
  const style = {
1239
1246
  position: 'relative',
1240
1247
  boxSizing: 'border-box',
@@ -1267,30 +1274,34 @@ export function WebPopupBox({
1267
1274
  } : {})
1268
1275
  };
1269
1276
  return _jsx("div", {
1277
+ dir: dir,
1270
1278
  style: style,
1271
1279
  children: _jsx(WebPopupFormSessionContext.Provider, {
1272
1280
  value: formSession,
1273
1281
  children: _jsx(WebPopupProductsContext.Provider, {
1274
1282
  value: products,
1275
- children: _jsx("div", {
1276
- style: pageStyle,
1277
- children: _jsx(LayoutNodeView, {
1278
- node: page.layout,
1279
- page: page,
1280
- colors: colors,
1281
- mode: mode,
1282
- scheme: colors.scheme,
1283
- leaf: leafRenderers,
1284
- onRequestClose: onRequestClose,
1285
- onPageChange: onPageChange ?? (() => {}),
1286
- onSubmitForm: onSubmitForm,
1287
- onSubmitChoice: onSubmitChoice,
1288
- onSubmitRating: onSubmitRating,
1289
- onRequestSubscribe: onRequestSubscribe,
1290
- onSubscribeClose: onSubscribeClose,
1291
- logger: logger
1292
- })
1293
- }, page.key)
1283
+ children: _jsx(WebPopupSubscribeContext.Provider, {
1284
+ value: subscribeSession,
1285
+ children: _jsx("div", {
1286
+ style: pageStyle,
1287
+ children: _jsx(LayoutNodeView, {
1288
+ node: page.layout,
1289
+ page: page,
1290
+ colors: colors,
1291
+ mode: mode,
1292
+ scheme: colors.scheme,
1293
+ leaf: leafRenderers,
1294
+ onRequestClose: onRequestClose,
1295
+ onPageChange: onPageChange ?? (() => {}),
1296
+ onSubmitForm: onSubmitForm,
1297
+ onSubmitChoice: onSubmitChoice,
1298
+ onSubmitRating: onSubmitRating,
1299
+ onRequestSubscribe: onRequestSubscribe,
1300
+ onSubscribeClose: onSubscribeClose,
1301
+ logger: logger
1302
+ })
1303
+ }, page.key)
1304
+ })
1294
1305
  })
1295
1306
  })
1296
1307
  });
@@ -1307,7 +1318,7 @@ function CloseButton({
1307
1318
  style: {
1308
1319
  position: 'absolute',
1309
1320
  top: 10,
1310
- right: 10,
1321
+ insetInlineEnd: 10,
1311
1322
  width: 24,
1312
1323
  height: 24,
1313
1324
  padding: 0,
@@ -1396,6 +1407,7 @@ export function WebPopupReader({
1396
1407
  }));
1397
1408
  }, [params]);
1398
1409
  const scheme = useColorScheme(colorScheme, webPopupDarkEnabled(params));
1410
+ const dir = useMemo(() => webPopupDirection(params), [params]);
1399
1411
  const pages = resolveWebPopupPages(params);
1400
1412
  if (pages.length === 0) return null;
1401
1413
  const page = pages.find(p => p.key === pageKey) ?? startPageOf(params, pages);
@@ -1448,6 +1460,7 @@ export function WebPopupReader({
1448
1460
  },
1449
1461
  onClick: onRequestClose
1450
1462
  }), _jsxs("div", {
1463
+ dir: dir,
1451
1464
  style: fixedContainerStyle(params, page.width, page.height),
1452
1465
  children: [_jsx(WebPopupBox, {
1453
1466
  page: page,
@@ -1,6 +1,7 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useContext } from 'react';
3
3
  import { WebPopupFormSessionContext } from '../../formSession';
4
+ import { webPopupCssTextAlign } from '../../helpers';
4
5
  import { WEB_POPUP_SUBMIT_ATTRIBUTE } from '../../styles';
5
6
  import { errorStyle } from '../styles';
6
7
  import { pillStyle, slotStyle } from './styles';
@@ -24,7 +25,7 @@ export function SubmitSlotView({
24
25
  }), session.phase === 'error' && _jsx("div", {
25
26
  style: {
26
27
  ...errorStyle(colors),
27
- textAlign: align
28
+ textAlign: webPopupCssTextAlign(align)
28
29
  },
29
30
  children: slot.errorMessage
30
31
  })]
@@ -1,7 +1,7 @@
1
1
  import { webPopupTextColor, WEB_POPUP_TEXT_SLOT_PADDING, WEB_POPUP_TEXT_VARIANT_STYLES } from '../constants';
2
2
  export const fieldSlotStyle = {
3
3
  padding: WEB_POPUP_TEXT_SLOT_PADDING,
4
- textAlign: 'left'
4
+ textAlign: 'start'
5
5
  };
6
6
  export function captionStyle({
7
7
  inverse,
@@ -1,4 +1,4 @@
1
- import { type WebPopupButtonAction, type WebPopupColors, type WebPopupDark, type WebPopupJson, type WebPopupLogger, type WebPopupPageParams, type WebPopupParams, type WebPopupPlacement, type WebPopupProductsSlot, type WebPopupResolvedPage, type WebPopupValueParam } from './types';
1
+ import { type WebPopupButtonAction, type WebPopupColors, type WebPopupDark, type WebPopupDirection, type WebPopupJson, type WebPopupLogger, type WebPopupPageParams, type WebPopupParams, type WebPopupPlacement, type WebPopupProductsSlot, type WebPopupResolvedPage, type WebPopupSlot, type WebPopupTextAlign, type WebPopupValueParam } from './types';
2
2
  export declare function safeUrl(url: string | undefined): string | undefined;
3
3
  /**
4
4
  * The target/rel pair a popup link renders with: only an exact '_self' opts
@@ -10,13 +10,17 @@ export declare function webPopupLinkTargetAttrs(target: string | null | undefine
10
10
  target: '_blank' | '_self';
11
11
  rel?: 'noreferrer';
12
12
  };
13
+ /** What the content does after a subscribe answer: close, stay as it is, or turn to a page. */
14
+ export type WebPopupSubscribeNext = 'close' | 'stay' | {
15
+ page: string;
16
+ };
13
17
  /**
14
- * Carries out a subscribe button's setting for the visitor's answer; true = the content closes.
18
+ * Carries out a subscribe button's setting for the visitor's answer.
15
19
  * A new tab opens with noopener, so `window.open` returns null and a blocked tab goes unnoticed.
16
20
  */
17
21
  export declare function applyWebPopupSubscribeOutcome(action: Extract<WebPopupButtonAction, {
18
22
  type: 'subscribe';
19
- }>, result: 'granted' | 'denied', logger: WebPopupLogger | undefined): boolean;
23
+ }>, result: 'granted' | 'denied', logger: WebPopupLogger | undefined): WebPopupSubscribeNext;
20
24
  /**
21
25
  * Sanitize a text slot's html before it's injected into the page. The editor
22
26
  * only ever writes inline formatting, but the json travels through a public
@@ -87,6 +91,12 @@ export declare function resolveWebPopupPageSize(own: number | 'stretch' | null |
87
91
  * — the renderer never falls back itself.
88
92
  */
89
93
  export declare function resolveWebPopupPages(params: WebPopupParams): WebPopupResolvedPage[];
94
+ /** The popup's text direction: the authored `dir`, else what its copy reads as. */
95
+ export declare function webPopupDirection(params: WebPopupParams): WebPopupDirection;
96
+ /** The visitor-facing copy of a slot; placeholders, urls and tag names stay out of the direction vote. */
97
+ export declare function webPopupSlotCopy(slot: WebPopupSlot): string[];
98
+ /** CSS alignment of an authored one: 'left' is the editor's default, so it follows the direction. */
99
+ export declare function webPopupCssTextAlign(align: WebPopupTextAlign): 'start' | 'center' | 'right';
90
100
  /** The page shown first: startPage when it exists, else the first page. */
91
101
  export declare function startPageOf(params: WebPopupParams, pages: WebPopupResolvedPage[]): WebPopupResolvedPage;
92
102
  export declare function placementMaxSize(placement: WebPopupPlacement): string;
@@ -2,7 +2,8 @@ import { SAFE_URL_PROTOCOL, WEB_POPUP_CHOICE_DEFAULTS, WEB_POPUP_CONSENT_DEFAULT
2
2
  import { WEB_POPUP_GLYPH_NAMES, WEB_POPUP_GLYPH_SIZES } from './glyphs';
3
3
  import { normalizeWebPopupLayout, substituteWebPopupLayoutValues, WEB_POPUP_VALUE_KEY_PATTERN } from './layout';
4
4
  import { autoDarkWebPopupColors } from './palette';
5
- import { webPopupTimeZoneSupported, webPopupWallClockMs } from './timer';
5
+ import { webPopupTimerLabels, webPopupTimeZoneSupported, webPopupWallClockMs } from './timer';
6
+ import { detectTextDirection } from '../shared/textDirection';
6
7
  // Sanitize a user-entered button URL before it lands in an href: https/http/
7
8
  // mailto/tel and page-relative links only.
8
9
  export function safeUrl(url) {
@@ -27,15 +28,18 @@ export function webPopupLinkTargetAttrs(target) {
27
28
  };
28
29
  }
29
30
  /**
30
- * Carries out a subscribe button's setting for the visitor's answer; true = the content closes.
31
+ * Carries out a subscribe button's setting for the visitor's answer.
31
32
  * A new tab opens with noopener, so `window.open` returns null and a blocked tab goes unnoticed.
32
33
  */
33
34
  export function applyWebPopupSubscribeOutcome(action, result, logger) {
34
35
  const outcome = result === 'granted' ? action.onGranted : action.onDenied;
35
36
  if (outcome?.type === 'href') openWebPopupSubscribeLink(outcome, logger);
37
+ if (outcome?.type === 'page') return {
38
+ page: outcome.page
39
+ };
36
40
  // Granted always closes, as before the setting; denied closes only when set to.
37
- if (result === 'granted') return true;
38
- return outcome?.type === 'close';
41
+ if (result === 'granted' || outcome?.type === 'close') return 'close';
42
+ return 'stay';
39
43
  }
40
44
  function openWebPopupSubscribeLink(outcome, logger) {
41
45
  const href = typeof outcome.url === 'string' ? safeUrl(outcome.url) : undefined;
@@ -794,6 +798,45 @@ export function resolveWebPopupPages(params) {
794
798
  }
795
799
  return out;
796
800
  }
801
+ /** The popup's text direction: the authored `dir`, else what its copy reads as. */
802
+ export function webPopupDirection(params) {
803
+ if (params.dir === 'ltr' || params.dir === 'rtl') return params.dir;
804
+ const copy = resolveWebPopupPages(params).flatMap(page => page.contents.flatMap(zone => zone.slots.flatMap(webPopupSlotCopy)));
805
+ return detectTextDirection(...copy);
806
+ }
807
+ /** The visitor-facing copy of a slot; placeholders, urls and tag names stay out of the direction vote. */
808
+ export function webPopupSlotCopy(slot) {
809
+ switch (slot.type) {
810
+ case 'text':
811
+ return [slot.html];
812
+ case 'button':
813
+ return [slot.label];
814
+ case 'email-subscription-form':
815
+ return [...slot.fields.map(field => field.label), slot.submitLabel, slot.successMessage, slot.confirmEmailMessage, ...(slot.privacy ? [slot.privacy.checkboxLabel, slot.privacy.linkLabel] : [])];
816
+ case 'choice':
817
+ return [...slot.options.map(option => option.label), slot.submitLabel, slot.successMessage];
818
+ case 'rating':
819
+ return [slot.labels.low, slot.labels.high, slot.submitLabel, slot.successMessage];
820
+ case 'products':
821
+ return [slot.ctaText];
822
+ case 'email-input':
823
+ return [slot.label, slot.invalidMessage, slot.requiredMessage];
824
+ case 'tag-input':
825
+ return [slot.label, slot.requiredMessage];
826
+ case 'consent':
827
+ return [slot.checkboxLabel, slot.linkLabel, slot.requiredMessage];
828
+ case 'submit':
829
+ return [slot.label, slot.errorMessage];
830
+ case 'timer':
831
+ return slot.showLabels ? Object.values(webPopupTimerLabels(slot.language)) : [];
832
+ case 'glyph':
833
+ return [];
834
+ }
835
+ }
836
+ /** CSS alignment of an authored one: 'left' is the editor's default, so it follows the direction. */
837
+ export function webPopupCssTextAlign(align) {
838
+ return align === 'left' ? 'start' : align;
839
+ }
797
840
  /** The page shown first: startPage when it exists, else the first page. */
798
841
  export function startPageOf(params, pages) {
799
842
  return pages.find(p => p.key === params.startPage) ?? pages[0];
@@ -3,11 +3,11 @@ export { WebPopupInline } from './WebPopupInline';
3
3
  export { loadWebPopupProducts } from './productsSlot';
4
4
  export { WEB_POPUP_CLOSE_ATTRIBUTE, WEB_POPUP_SUBMIT_ATTRIBUTE } from './styles';
5
5
  export { WEB_POPUP_TEMPLATES, findWebPopupTemplate } from './templates';
6
- export { parseWebPopupJson, stringifyWebPopup, resolveWebPopupPages, resolveWebPopupPageSize, startPageOf, safeUrl, sanitizeWebPopupHtml, normalizeWebPopupColors, normalizeWebPopupValues, webPopupValuesMap, collectWebPopupFormCodes, collectWebPopupProductSlots, webPopupExpired, normalizeWebPopupDark, WEB_POPUP_MAX_SIZE_PX, isWebPopupCloseButton, webPopupPageWithoutCloseButtons, webPopupParamsWithoutCloseButtons, } from './helpers';
6
+ export { parseWebPopupJson, stringifyWebPopup, resolveWebPopupPages, resolveWebPopupPageSize, startPageOf, safeUrl, sanitizeWebPopupHtml, normalizeWebPopupColors, normalizeWebPopupValues, webPopupValuesMap, collectWebPopupFormCodes, collectWebPopupProductSlots, webPopupExpired, normalizeWebPopupDark, WEB_POPUP_MAX_SIZE_PX, isWebPopupCloseButton, webPopupPageWithoutCloseButtons, webPopupParamsWithoutCloseButtons, webPopupDirection, webPopupCssTextAlign, } from './helpers';
7
7
  export { webPopupHasForm } from './form';
8
8
  export { webPopupTimerLabels, webPopupTimerRemaining, webPopupTimeZoneSupported, webPopupWallClockMs, type WebPopupTimerLabels, } from './timer';
9
9
  export { normalizeWebPopupLayout, substituteWebPopupLayoutValues, WEB_POPUP_VALUE_KEY_PATTERN, webPopupBackgroundImageStyle, webPopupContainerStyle, webPopupCssLength, webPopupPaddingValue, webPopupTracksValue, } from './layout';
10
10
  export { WEB_POPUP_VERSION, WEB_POPUP_FONT_STACK, WEB_POPUP_TEXT_COLOR, WEB_POPUP_TEXT_SECONDARY_COLOR, WEB_POPUP_ACCENT_COLOR, WEB_POPUP_BACKGROUND_COLOR, WEB_POPUP_DEFAULT_COLORS, webPopupTextColor, WEB_POPUP_TEXT_VARIANT_STYLES, WEB_POPUP_BG_SECTION_FALLBACK, WEB_POPUP_TEXT_SLOT_PADDING, WEB_POPUP_BUTTON_SLOT_PADDING, webPopupSlotGap, webPopupSlotRole, type WebPopupSlotRole, WEB_POPUP_DEFAULT_WIDTH, WEB_POPUP_INLINE_IMAGE_MAX_HEIGHT, WEB_POPUP_LAYOUT_MAX_DEPTH, WEB_POPUP_LAYOUT_MAX_NODES, webPopupButtonPillStyle, webPopupFormInputStyle, WEB_POPUP_FORM_INPUT_BORDER, WEB_POPUP_FORM_ERROR_COLOR, WEB_POPUP_FORM_ERROR_COLOR_DARK, WEB_POPUP_ON_ACCENT_COLOR, WEB_POPUP_FORM_DEFAULTS, WEB_POPUP_PRODUCTS_DEFAULTS, WEB_POPUP_PRODUCTS_MAX_LIMIT, WEB_POPUP_PRODUCTS_CACHE_MS, WEB_POPUP_CHOICE_DEFAULTS, WEB_POPUP_MAX_CHOICE_OPTIONS, WEB_POPUP_RATING_DEFAULTS, WEB_POPUP_RETRY_ERROR, WEB_POPUP_EMAIL_INPUT_DEFAULTS, WEB_POPUP_TAG_INPUT_DEFAULTS, WEB_POPUP_CONSENT_DEFAULTS, WEB_POPUP_SUBMIT_DEFAULTS, webPopupRatingScores, } from './constants';
11
11
  export { resolveWebPopupBoxChrome, resolveWebPopupColors, autoDarkWebPopupColors, webPopupColorAlpha, webPopupDarkColors, webPopupDarkEnabled, webPopupEffectiveScheme, webPopupImageSrc, webPopupMixColor, webPopupShiftColor, } from './palette';
12
12
  export { WEB_POPUP_GLYPH_NAMES, WEB_POPUP_GLYPH_PATHS, WEB_POPUP_GLYPH_SIZES, WEB_POPUP_THUMB_UP_PATH, } from './glyphs';
13
- export { type WebPopupJson, type WebPopupKind, type WebPopupParams, type WebPopupColors, type WebPopupChrome, type WebPopupPageParams, type WebPopupResolvedPage, type WebPopupDark, type WebPopupResolvedColors, type WebPopupColorScheme, type WebPopupColorSchemePref, type WebPopupSlot, type WebPopupImage, type WebPopupVideo, type WebPopupPlacement, type WebPopupOverlay, type WebPopupAnimation, type WebPopupButtonAction, type WebPopupButtonVariant, type WebPopupTextVariant, type WebPopupTextAlign, type WebPopupVAnchor, type WebPopupHAnchor, type WebPopupReaderMode, type WebPopupReaderProps, type WebPopupLeafRenderers, type WebPopupBoxProps, type WebPopupInlineProps, type WebPopupLayoutNode, type WebPopupContainerNode, type WebPopupContentNode, type WebPopupImageNode, type WebPopupContainerType, type WebPopupContainerProps, type WebPopupContentZone, type WebPopupContentTone, type WebPopupCssLength, type WebPopupBoxSides, type WebPopupAlignItems, type WebPopupJustifyContent, type WebPopupValueParam, type WebPopupValueControl, type WebPopupLengthUnit, type WebPopupLengthRange, type WebPopupValueRef, type WebPopupTemplate, type WebPopupFormField, type WebPopupFormFieldKind, type WebPopupFormPrivacy, type WebPopupFormSubmitPayload, type WebPopupFormSubmitResult, type WebPopupFormSubmitHandler, type WebPopupEmailInputSlot, type WebPopupTagInputSlot, type WebPopupConsentSlot, type WebPopupSubmitSlot, type WebPopupFormValues, type WebPopupFormValuesSubmitResult, type WebPopupFormValuesSubmitHandler, type WebPopupTimerSlot, type WebPopupTimerExpireAction, type WebPopupTimerRemaining, type WebPopupChoiceSlot, type WebPopupChoiceOption, type WebPopupChoiceControl, type WebPopupChoiceSubmitPayload, type WebPopupChoiceSubmitHandler, type WebPopupRatingSlot, type WebPopupRatingScale, type WebPopupRatingSubmitMode, type WebPopupRatingSubmitPayload, type WebPopupRatingSubmitHandler, type WebPopupSubscribeResult, type WebPopupSubscribeOutcome, type WebPopupLogger, type WebPopupGlyphSlot, type WebPopupGlyphName, type WebPopupGlyphSize, type WebPopupProductsSlot, type WebPopupProductsStrategy, type WebPopupProductsLayout, type WebPopupProductsFields, type WebPopupProduct, type WebPopupProductsHost, type WebPopupSlotViewProps, } from './types';
13
+ export { type WebPopupJson, type WebPopupKind, type WebPopupParams, type WebPopupColors, type WebPopupChrome, type WebPopupPageParams, type WebPopupResolvedPage, type WebPopupDark, type WebPopupResolvedColors, type WebPopupColorScheme, type WebPopupColorSchemePref, type WebPopupSlot, type WebPopupImage, type WebPopupVideo, type WebPopupPlacement, type WebPopupOverlay, type WebPopupAnimation, type WebPopupButtonAction, type WebPopupButtonVariant, type WebPopupTextVariant, type WebPopupTextAlign, type WebPopupDirection, type WebPopupVAnchor, type WebPopupHAnchor, type WebPopupReaderMode, type WebPopupReaderProps, type WebPopupLeafRenderers, type WebPopupBoxProps, type WebPopupInlineProps, type WebPopupLayoutNode, type WebPopupContainerNode, type WebPopupContentNode, type WebPopupImageNode, type WebPopupContainerType, type WebPopupContainerProps, type WebPopupContentZone, type WebPopupContentTone, type WebPopupCssLength, type WebPopupBoxSides, type WebPopupAlignItems, type WebPopupJustifyContent, type WebPopupValueParam, type WebPopupValueControl, type WebPopupLengthUnit, type WebPopupLengthRange, type WebPopupValueRef, type WebPopupTemplate, type WebPopupFormField, type WebPopupFormFieldKind, type WebPopupFormPrivacy, type WebPopupFormSubmitPayload, type WebPopupFormSubmitResult, type WebPopupFormSubmitHandler, type WebPopupEmailInputSlot, type WebPopupTagInputSlot, type WebPopupConsentSlot, type WebPopupSubmitSlot, type WebPopupFormValues, type WebPopupFormValuesSubmitResult, type WebPopupFormValuesSubmitHandler, type WebPopupTimerSlot, type WebPopupTimerExpireAction, type WebPopupTimerRemaining, type WebPopupChoiceSlot, type WebPopupChoiceOption, type WebPopupChoiceControl, type WebPopupChoiceSubmitPayload, type WebPopupChoiceSubmitHandler, type WebPopupRatingSlot, type WebPopupRatingScale, type WebPopupRatingSubmitMode, type WebPopupRatingSubmitPayload, type WebPopupRatingSubmitHandler, type WebPopupSubscribeResult, type WebPopupSubscribeOutcome, type WebPopupLogger, type WebPopupGlyphSlot, type WebPopupGlyphName, type WebPopupGlyphSize, type WebPopupProductsSlot, type WebPopupProductsStrategy, type WebPopupProductsLayout, type WebPopupProductsFields, type WebPopupProduct, type WebPopupProductsHost, type WebPopupSlotViewProps, } from './types';
@@ -3,7 +3,7 @@ export { WebPopupInline } from './WebPopupInline';
3
3
  export { loadWebPopupProducts } from './productsSlot';
4
4
  export { WEB_POPUP_CLOSE_ATTRIBUTE, WEB_POPUP_SUBMIT_ATTRIBUTE } from './styles';
5
5
  export { WEB_POPUP_TEMPLATES, findWebPopupTemplate } from './templates';
6
- export { parseWebPopupJson, stringifyWebPopup, resolveWebPopupPages, resolveWebPopupPageSize, startPageOf, safeUrl, sanitizeWebPopupHtml, normalizeWebPopupColors, normalizeWebPopupValues, webPopupValuesMap, collectWebPopupFormCodes, collectWebPopupProductSlots, webPopupExpired, normalizeWebPopupDark, WEB_POPUP_MAX_SIZE_PX, isWebPopupCloseButton, webPopupPageWithoutCloseButtons, webPopupParamsWithoutCloseButtons } from './helpers';
6
+ export { parseWebPopupJson, stringifyWebPopup, resolveWebPopupPages, resolveWebPopupPageSize, startPageOf, safeUrl, sanitizeWebPopupHtml, normalizeWebPopupColors, normalizeWebPopupValues, webPopupValuesMap, collectWebPopupFormCodes, collectWebPopupProductSlots, webPopupExpired, normalizeWebPopupDark, WEB_POPUP_MAX_SIZE_PX, isWebPopupCloseButton, webPopupPageWithoutCloseButtons, webPopupParamsWithoutCloseButtons, webPopupDirection, webPopupCssTextAlign } from './helpers';
7
7
  export { webPopupHasForm } from './form';
8
8
  export { webPopupTimerLabels, webPopupTimerRemaining, webPopupTimeZoneSupported, webPopupWallClockMs } from './timer';
9
9
  export { normalizeWebPopupLayout, substituteWebPopupLayoutValues, WEB_POPUP_VALUE_KEY_PATTERN, webPopupBackgroundImageStyle, webPopupContainerStyle, webPopupCssLength, webPopupPaddingValue, webPopupTracksValue } from './layout';
@@ -0,0 +1,9 @@
1
+ /** Whether the visitor has answered a subscribe prompt in this box; it outlives page switches. */
2
+ export type WebPopupSubscribeSession = {
3
+ answered: boolean;
4
+ markAnswered: () => void;
5
+ };
6
+ /** What a subscribe button reads; a slot outside any WebPopupBox gets this inert session. */
7
+ export declare const WebPopupSubscribeContext: import("react").Context<WebPopupSubscribeSession>;
8
+ /** The subscribe session a WebPopupBox owns, so a button met again after a page turn stays spent. */
9
+ export declare function useWebPopupSubscribeSession(): WebPopupSubscribeSession;
@@ -0,0 +1,14 @@
1
+ import { createContext, useMemo, useState } from 'react';
2
+ /** What a subscribe button reads; a slot outside any WebPopupBox gets this inert session. */
3
+ export const WebPopupSubscribeContext = createContext({
4
+ answered: false,
5
+ markAnswered: () => {}
6
+ });
7
+ /** The subscribe session a WebPopupBox owns, so a button met again after a page turn stays spent. */
8
+ export function useWebPopupSubscribeSession() {
9
+ const [answered, setAnswered] = useState(false);
10
+ return useMemo(() => ({
11
+ answered,
12
+ markAnswered: () => setAnswered(true)
13
+ }), [answered]);
14
+ }
@@ -2,6 +2,7 @@ import type { ReactNode } from 'react';
2
2
  /** Text styles a slot can use ('icon' = emoji line, 'eyebrow' = small caps kicker). */
3
3
  export type WebPopupTextVariant = 'icon' | 'eyebrow' | 'h1' | 'h2' | 'h3' | 'body' | 'caption';
4
4
  export type WebPopupTextAlign = 'left' | 'center' | 'right';
5
+ export type WebPopupDirection = 'ltr' | 'rtl';
5
6
  export type WebPopupButtonVariant = 'primary' | 'secondary';
6
7
  /**
7
8
  * What a button does: open a URL, dismiss the popup, switch to another page
@@ -19,7 +20,8 @@ export type WebPopupButtonAction =
19
20
  type: 'page';
20
21
  page: string;
21
22
  }
22
- /** Ask for push permission; without `onGranted` / `onDenied` 'granted' closes and 'denied' disables the button. */
23
+ /** Ask for push permission; without `onGranted` / `onDenied` 'granted' closes and 'denied' disables the button,
24
+ * a `page` outcome turns to that page instead and keeps the content open. */
23
25
  | {
24
26
  type: 'subscribe';
25
27
  onGranted?: WebPopupSubscribeOutcome;
@@ -27,7 +29,7 @@ export type WebPopupButtonAction =
27
29
  };
28
30
  /** What the subscribe button does once the visitor answered. */
29
31
  export type WebPopupSubscribeOutcome = Extract<WebPopupButtonAction, {
30
- type: 'close' | 'href';
32
+ type: 'close' | 'href' | 'page';
31
33
  }>;
32
34
  /** What the host's subscribe handler settled on — the browser's permission after the ask. */
33
35
  export type WebPopupSubscribeResult = 'granted' | 'denied' | 'default';
@@ -573,6 +575,8 @@ export type WebPopupParams = WebPopupChrome & {
573
575
  pages: WebPopupPageParams[];
574
576
  /** Key of the page shown first; absent/unknown = the first page. */
575
577
  startPage?: string;
578
+ /** Text direction; absent = detected from the copy (mostly RTL letters = 'rtl'). */
579
+ dir?: WebPopupDirection;
576
580
  };
577
581
  export type WebPopupKind = {
578
582
  id: string;