@dloizides/ui-tour 1.0.2 → 1.1.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.1.0
4
+
5
+ - `@dloizides/ui-tour/expo`: `AppTours` (one-line setup: expo-router navigate, theme adapter `toTourTheme`, translated labels, Umami events, picker, first-run card) and `TourButton` ("Take a tour").
6
+ - `@dloizides/ui-tour/testing`: `expectValidTours` / `findTourProblems` (missing text keys, malformed targets, repeated ids, write-control clicks).
7
+ - `@dloizides/ui-tour/playwright`: `playAllToursInAuto` / `expectAllToursPlay`, failures reported as `tour <id> step <n>/<m>: <reason>`.
8
+ - Caption font falls back to `sans-serif` (`fontStack`); the caption carries `data-tour-id`, `data-tour-step`, `data-tour-steps`.
9
+ - `expo-router` and `@playwright/test` are optional peers; the core entry stays React DOM only.
10
+
3
11
  ## 1.0.2
4
12
 
5
13
  - A switch, checkbox or radio is a setting, so the write-control rule no longer refuses it: "Pay in a different currency" toggles, a "Pay" button is still never clicked.
package/README.md CHANGED
@@ -65,7 +65,7 @@ A step target is a testID string (`data-testid`) or `{ role, name, nth?, exact?,
65
65
 
66
66
  Every colour comes from the `theme` prop; map it from your design tokens or tenant theme:
67
67
 
68
- `accent`, `onAccent`, `surface`, `onSurface`, `muted`, `scrim`, `divider`, `radius`, `fontFamily`.
68
+ `accent`, `onAccent`, `surface`, `onSurface`, `muted`, `scrim`, `divider`, `radius`, `fontFamily`. The font always falls back to `sans-serif` (`fontStack`).
69
69
 
70
70
  ### Events
71
71
 
@@ -75,6 +75,72 @@ Every colour comes from the `theme` prop; map it from your design tokens or tena
75
75
 
76
76
  Steps with a `route` call your `navigate` (never a full page load). The tour state lives in `sessionStorage`, so a reload resumes the same step. A missing target is awaited for 8 s; an `optional` step is then skipped, a required one shows "This step isn't available here" with Skip and End.
77
77
 
78
+ ## Adopt tours in an Expo Router app (`@dloizides/ui-tour/expo`)
79
+
80
+ One provider line in the root layout. Router navigation, theme (light/dark), translated labels, Umami events, the picker, F2 and the first-run card come from the kit.
81
+
82
+ ```tsx
83
+ import { AppTours, TourButton } from '@dloizides/ui-tour/expo';
84
+ import { TOURS } from '../tours';
85
+
86
+ <AppTours tours={TOURS} translate={FM} theme={theme} user={user} vars={vars}>
87
+ <Stack />
88
+ </AppTours>;
89
+
90
+ <TourButton />
91
+ ```
92
+
93
+ | Prop | What it is |
94
+ |---|---|
95
+ | `tours` | Key-based tours: `title`, `category` and each step `text` are translation keys |
96
+ | `translate` | The app translate function (`FM`); a missing key keeps the English default |
97
+ | `theme` | The app theme (`colors`, `palette.primary`, `mode?`, `typography?`); `dark?` overrides the mode |
98
+ | `user`, `vars`, `allowWrites`, `onEvent` | As on `TourProvider`; events also go to Umami (`window.umami.track`, tour id and mode only) |
99
+ | `navigate` | Overrides `useRouter().push` |
100
+ | `labelPrefix` | Label keys root, default `tours.labels` (`tours.labels.next`, `tours.labels.takeTour`, ...) |
101
+
102
+ `TourButton` is the "Take a tour" button for the shell help slot (44 px hit box, `tours.labels.takeTour` / `takeTourHint`).
103
+
104
+ ### Add a tour in 3 steps
105
+
106
+ 1. Add the tour to `src/tours/`: an `id`, a `title` key, a `category` key and its steps.
107
+ 2. Add every text key to `src/localization/locales/en.json`.
108
+ 3. Run the jest check and the Auto E2E spec below.
109
+
110
+ ### Step fields
111
+
112
+ | Field | Meaning |
113
+ |---|---|
114
+ | `target` | A testID (`open-payees`) or `{ role, name, nth?, exact?, within? }` |
115
+ | `text` | Translation key of the caption text; `{name}` placeholders come from `vars` |
116
+ | `action` | `StepAction.Click`, `Type` (needs `value`) or `None` |
117
+ | `route?` | Navigates there first |
118
+ | `optional?` | Skipped when the target is absent |
119
+ | `wait?` | Extra wait in ms before the step |
120
+
121
+ ### Forbidden actions
122
+
123
+ A click step whose target name starts with Save, Submit, Approve, Reject, Delete, Reset, Pay or Send is never performed. A plain "Save" is allowed only with `allowSave: true` on the tour and `allowWrites` on the provider. Switches, checkboxes and radios are settings, not writes.
124
+
125
+ ### How to test
126
+
127
+ ```ts
128
+ import { expectValidTours } from '@dloizides/ui-tour/testing';
129
+ import en from '../localization/locales/en.json';
130
+
131
+ it('every tour is valid', () => expectValidTours(TOURS, en));
132
+ ```
133
+
134
+ It fails on a missing text key, a malformed target, a repeated id, a tour without steps or a click on a write control.
135
+
136
+ ```ts
137
+ import { expectAllToursPlay } from '@dloizides/ui-tour/playwright';
138
+
139
+ test('every tour plays to the end in Auto', async ({ page }) => expectAllToursPlay(page));
140
+ ```
141
+
142
+ It plays every tour in the picker in Auto and fails with `tour <id> step <n>/<m>: <reason>` (target missing, stuck, closed early, never started). The caption carries `data-tour-id`, `data-tour-step` and `data-tour-steps` for runners. `expo-router` and `@playwright/test` are optional peers.
143
+
78
144
  ## License
79
145
 
80
146
  MIT
@@ -0,0 +1,76 @@
1
+ import { ReactNode, ReactElement } from 'react';
2
+ import { TourLabels, Tour, TourTheme, TourUser, TourVars, TourEvent } from '@dloizides/ui-tour';
3
+
4
+ type Translate = (key: string) => string;
5
+ declare const DEFAULT_LABEL_PREFIX = "tours.labels";
6
+ declare const defaultAppTourLabels: {
7
+ takeTour: string;
8
+ takeTourHint: string;
9
+ };
10
+ type AppTourLabelKey = keyof typeof defaultAppTourLabels;
11
+ /** Translates `key`; a missing or empty translation returns `fallback`. */
12
+ declare function translateOr(translate: Translate, key: string, fallback: string): string;
13
+ /** Builds every tour label from `<prefix>.<labelName>` keys, keeping the English default for a missing key. */
14
+ declare function buildTourLabels(translate: Translate, prefix?: string): TourLabels;
15
+ /** Replaces each tour title, category and step text key with its translation. */
16
+ declare function localizeTours(tours: readonly Tour[], translate: Translate): Tour[];
17
+
18
+ interface AppThemeColors {
19
+ background: string;
20
+ surface: string;
21
+ surfaceElevated?: string;
22
+ text: string;
23
+ textSecondary: string;
24
+ border: string;
25
+ divider?: string;
26
+ }
27
+ interface AppThemeSource {
28
+ colors: AppThemeColors;
29
+ palette: {
30
+ primary: {
31
+ '300'?: string;
32
+ '500'?: string;
33
+ '600'?: string;
34
+ '700'?: string;
35
+ };
36
+ };
37
+ mode?: string;
38
+ typography?: {
39
+ fontFamily?: string;
40
+ };
41
+ }
42
+ /** Maps an app theme (theme-web `ResolvedTheme` or ui-feedback theme) onto the tour colour slots. */
43
+ declare function toTourTheme(theme: AppThemeSource, dark?: boolean): TourTheme;
44
+
45
+ interface AppToursProps {
46
+ tours: readonly Tour[];
47
+ translate: Translate;
48
+ theme: AppThemeSource;
49
+ dark?: boolean;
50
+ user?: TourUser | null;
51
+ vars?: TourVars;
52
+ navigate?: (route: string) => void;
53
+ labelPrefix?: string;
54
+ allowWrites?: boolean;
55
+ onEvent?: (event: TourEvent) => void;
56
+ children?: ReactNode;
57
+ }
58
+ /** One-line tour setup for an Expo Router app: router, theme, translated labels, Umami events, picker and first-run card. */
59
+ declare function AppTours(props: AppToursProps): ReactElement;
60
+
61
+ interface TourButtonProps {
62
+ testID?: string;
63
+ }
64
+ /** "Take a tour" button for the shell help slot; opens the tour picker (F2 does the same). */
65
+ declare function TourButton({ testID }: TourButtonProps): ReactElement;
66
+
67
+ interface AppToursValue {
68
+ label: (key: AppTourLabelKey) => string;
69
+ }
70
+ /** Returns the kit labels; must be called inside `AppTours`. */
71
+ declare function useAppTours(): AppToursValue;
72
+
73
+ /** Sends a tour event to Umami (when its script is loaded) with only the tour id and mode. */
74
+ declare function trackTourEvent(event: TourEvent): void;
75
+
76
+ export { type AppThemeColors, type AppThemeSource, type AppTourLabelKey, AppTours, type AppToursProps, type AppToursValue, DEFAULT_LABEL_PREFIX, TourButton, type TourButtonProps, type Translate, buildTourLabels, defaultAppTourLabels, localizeTours, toTourTheme, trackTourEvent, translateOr, useAppTours };
@@ -0,0 +1,76 @@
1
+ import { ReactNode, ReactElement } from 'react';
2
+ import { TourLabels, Tour, TourTheme, TourUser, TourVars, TourEvent } from '@dloizides/ui-tour';
3
+
4
+ type Translate = (key: string) => string;
5
+ declare const DEFAULT_LABEL_PREFIX = "tours.labels";
6
+ declare const defaultAppTourLabels: {
7
+ takeTour: string;
8
+ takeTourHint: string;
9
+ };
10
+ type AppTourLabelKey = keyof typeof defaultAppTourLabels;
11
+ /** Translates `key`; a missing or empty translation returns `fallback`. */
12
+ declare function translateOr(translate: Translate, key: string, fallback: string): string;
13
+ /** Builds every tour label from `<prefix>.<labelName>` keys, keeping the English default for a missing key. */
14
+ declare function buildTourLabels(translate: Translate, prefix?: string): TourLabels;
15
+ /** Replaces each tour title, category and step text key with its translation. */
16
+ declare function localizeTours(tours: readonly Tour[], translate: Translate): Tour[];
17
+
18
+ interface AppThemeColors {
19
+ background: string;
20
+ surface: string;
21
+ surfaceElevated?: string;
22
+ text: string;
23
+ textSecondary: string;
24
+ border: string;
25
+ divider?: string;
26
+ }
27
+ interface AppThemeSource {
28
+ colors: AppThemeColors;
29
+ palette: {
30
+ primary: {
31
+ '300'?: string;
32
+ '500'?: string;
33
+ '600'?: string;
34
+ '700'?: string;
35
+ };
36
+ };
37
+ mode?: string;
38
+ typography?: {
39
+ fontFamily?: string;
40
+ };
41
+ }
42
+ /** Maps an app theme (theme-web `ResolvedTheme` or ui-feedback theme) onto the tour colour slots. */
43
+ declare function toTourTheme(theme: AppThemeSource, dark?: boolean): TourTheme;
44
+
45
+ interface AppToursProps {
46
+ tours: readonly Tour[];
47
+ translate: Translate;
48
+ theme: AppThemeSource;
49
+ dark?: boolean;
50
+ user?: TourUser | null;
51
+ vars?: TourVars;
52
+ navigate?: (route: string) => void;
53
+ labelPrefix?: string;
54
+ allowWrites?: boolean;
55
+ onEvent?: (event: TourEvent) => void;
56
+ children?: ReactNode;
57
+ }
58
+ /** One-line tour setup for an Expo Router app: router, theme, translated labels, Umami events, picker and first-run card. */
59
+ declare function AppTours(props: AppToursProps): ReactElement;
60
+
61
+ interface TourButtonProps {
62
+ testID?: string;
63
+ }
64
+ /** "Take a tour" button for the shell help slot; opens the tour picker (F2 does the same). */
65
+ declare function TourButton({ testID }: TourButtonProps): ReactElement;
66
+
67
+ interface AppToursValue {
68
+ label: (key: AppTourLabelKey) => string;
69
+ }
70
+ /** Returns the kit labels; must be called inside `AppTours`. */
71
+ declare function useAppTours(): AppToursValue;
72
+
73
+ /** Sends a tour event to Umami (when its script is loaded) with only the tour id and mode. */
74
+ declare function trackTourEvent(event: TourEvent): void;
75
+
76
+ export { type AppThemeColors, type AppThemeSource, type AppTourLabelKey, AppTours, type AppToursProps, type AppToursValue, DEFAULT_LABEL_PREFIX, TourButton, type TourButtonProps, type Translate, buildTourLabels, defaultAppTourLabels, localizeTours, toTourTheme, trackTourEvent, translateOr, useAppTours };
@@ -0,0 +1,120 @@
1
+ 'use strict';
2
+
3
+ var react = require('react');
4
+ var expoRouter = require('expo-router');
5
+ var uiTour = require('@dloizides/ui-tour');
6
+ var jsxRuntime = require('react/jsx-runtime');
7
+ var reactNative = require('react-native');
8
+
9
+ // src/expo/AppTours.tsx
10
+ var AppToursContext = react.createContext(null);
11
+ function useAppTours() {
12
+ const value = react.useContext(AppToursContext);
13
+ if (value === null) throw new Error("useAppTours must be used inside AppTours");
14
+ return value;
15
+ }
16
+ var DEFAULT_LABEL_PREFIX = "tours.labels";
17
+ var defaultAppTourLabels = {
18
+ takeTour: "Take a tour",
19
+ takeTourHint: "Opens the list of guided tours"
20
+ };
21
+ function translateOr(translate, key, fallback) {
22
+ const value = translate(key);
23
+ return typeof value === "string" && value !== "" && value !== key ? value : fallback;
24
+ }
25
+ function buildTourLabels(translate, prefix = DEFAULT_LABEL_PREFIX) {
26
+ const names = Object.keys(uiTour.defaultTourLabels);
27
+ const labels = { ...uiTour.defaultTourLabels };
28
+ names.forEach((name) => {
29
+ labels[name] = translateOr(translate, `${prefix}.${name}`, uiTour.defaultTourLabels[name]);
30
+ });
31
+ return labels;
32
+ }
33
+ function localizeTours(tours, translate) {
34
+ const text = (key) => translateOr(translate, key, key);
35
+ return tours.map((tour) => ({
36
+ ...tour,
37
+ title: text(tour.title),
38
+ category: text(tour.category),
39
+ steps: tour.steps.map((step) => ({ ...step, text: text(step.text) }))
40
+ }));
41
+ }
42
+ var DARK_MODE = "dark";
43
+ var TOUR_RADIUS = 12;
44
+ var SCRIM_STRENGTH = "62%";
45
+ function toTourTheme(theme, dark) {
46
+ const isDark = dark ?? theme.mode === DARK_MODE;
47
+ const { colors, palette } = theme;
48
+ const lightAccent = palette.primary["700"] ?? palette.primary["600"] ?? palette.primary["500"] ?? colors.text;
49
+ const accent = isDark ? palette.primary["300"] ?? colors.text : lightAccent;
50
+ const shade = isDark ? colors.background : colors.text;
51
+ return {
52
+ accent,
53
+ onAccent: isDark ? colors.background : colors.surface,
54
+ surface: colors.surfaceElevated ?? colors.surface,
55
+ onSurface: colors.text,
56
+ muted: colors.textSecondary,
57
+ scrim: `color-mix(in srgb, ${shade} ${SCRIM_STRENGTH}, transparent)`,
58
+ divider: colors.divider ?? colors.border,
59
+ radius: TOUR_RADIUS,
60
+ fontFamily: uiTour.fontStack(theme.typography?.fontFamily)
61
+ };
62
+ }
63
+
64
+ // src/expo/trackTourEvent.ts
65
+ function trackTourEvent(event) {
66
+ if (typeof window === "undefined") return;
67
+ window.umami?.track(event.type, { tourId: event.tourId, mode: event.mode });
68
+ }
69
+ function AppTours(props) {
70
+ const router = expoRouter.useRouter();
71
+ const { translate, onEvent: extraEvent } = props;
72
+ const prefix = props.labelPrefix ?? DEFAULT_LABEL_PREFIX;
73
+ const navigate = props.navigate ?? router.push;
74
+ const tours = react.useMemo(() => localizeTours(props.tours, translate), [props.tours, translate]);
75
+ const labels = react.useMemo(() => buildTourLabels(translate, prefix), [translate, prefix]);
76
+ const theme = react.useMemo(() => toTourTheme(props.theme, props.dark), [props.theme, props.dark]);
77
+ const onEvent = react.useCallback((event) => {
78
+ trackTourEvent(event);
79
+ extraEvent?.(event);
80
+ }, [extraEvent]);
81
+ const appValue = react.useMemo(() => ({
82
+ label: (key) => translateOr(translate, `${prefix}.${key}`, defaultAppTourLabels[key])
83
+ }), [translate, prefix]);
84
+ return /* @__PURE__ */ jsxRuntime.jsx(AppToursContext.Provider, { value: appValue, children: /* @__PURE__ */ jsxRuntime.jsxs(uiTour.TourProvider, { tours, navigate, theme, labels, user: props.user, vars: props.vars, allowWrites: props.allowWrites, onEvent, children: [
85
+ props.children,
86
+ /* @__PURE__ */ jsxRuntime.jsx(uiTour.TourPicker, {}),
87
+ /* @__PURE__ */ jsxRuntime.jsx(uiTour.FirstRunOffer, {})
88
+ ] }) });
89
+ }
90
+ var MIN_HIT = 44;
91
+ var PADDING = 12;
92
+ function TourButton({ testID = "take-tour" }) {
93
+ const { openPicker, theme } = uiTour.useTour();
94
+ const { label } = useAppTours();
95
+ return /* @__PURE__ */ jsxRuntime.jsx(
96
+ reactNative.Pressable,
97
+ {
98
+ testID,
99
+ accessibilityRole: "button",
100
+ accessibilityLabel: label("takeTour"),
101
+ accessibilityHint: label("takeTourHint"),
102
+ onPress: openPicker,
103
+ style: { minHeight: MIN_HIT, minWidth: MIN_HIT, paddingHorizontal: PADDING, justifyContent: "center", borderWidth: 1, borderColor: theme.divider, borderRadius: theme.radius },
104
+ children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: { color: theme.onSurface, fontFamily: uiTour.fontStack(theme.fontFamily) }, children: label("takeTour") })
105
+ }
106
+ );
107
+ }
108
+
109
+ exports.AppTours = AppTours;
110
+ exports.DEFAULT_LABEL_PREFIX = DEFAULT_LABEL_PREFIX;
111
+ exports.TourButton = TourButton;
112
+ exports.buildTourLabels = buildTourLabels;
113
+ exports.defaultAppTourLabels = defaultAppTourLabels;
114
+ exports.localizeTours = localizeTours;
115
+ exports.toTourTheme = toTourTheme;
116
+ exports.trackTourEvent = trackTourEvent;
117
+ exports.translateOr = translateOr;
118
+ exports.useAppTours = useAppTours;
119
+ //# sourceMappingURL=index.js.map
120
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/expo/AppToursContext.ts","../../src/expo/labels.ts","../../src/expo/toTourTheme.ts","../../src/expo/trackTourEvent.ts","../../src/expo/AppTours.tsx","../../src/expo/TourButton.tsx"],"names":["createContext","useContext","defaultTourLabels","fontStack","useRouter","useMemo","useCallback","jsx","jsxs","TourProvider","TourPicker","FirstRunOffer","useTour","Pressable","Text"],"mappings":";;;;;;;;;AAOO,IAAM,eAAA,GAAkBA,oBAAoC,IAAI,CAAA;AAGhE,SAAS,WAAA,GAA6B;AAC3C,EAAA,MAAM,KAAA,GAAQC,iBAAW,eAAe,CAAA;AACxC,EAAA,IAAI,KAAA,KAAU,IAAA,EAAM,MAAM,IAAI,MAAM,0CAA0C,CAAA;AAC9E,EAAA,OAAO,KAAA;AACT;ACTO,IAAM,oBAAA,GAAuB;AAE7B,IAAM,oBAAA,GAAuB;AAAA,EAClC,QAAA,EAAU,aAAA;AAAA,EACV,YAAA,EAAc;AAChB;AAKO,SAAS,WAAA,CAAY,SAAA,EAAsB,GAAA,EAAa,QAAA,EAA0B;AACvF,EAAA,MAAM,KAAA,GAAQ,UAAU,GAAG,CAAA;AAC3B,EAAA,OAAO,OAAO,KAAA,KAAU,QAAA,IAAY,UAAU,EAAA,IAAM,KAAA,KAAU,MAAM,KAAA,GAAQ,QAAA;AAC9E;AAGO,SAAS,eAAA,CAAgB,SAAA,EAAsB,MAAA,GAAiB,oBAAA,EAAkC;AACvG,EAAA,MAAM,KAAA,GAAQ,MAAA,CAAO,IAAA,CAAKC,wBAAiB,CAAA;AAC3C,EAAA,MAAM,MAAA,GAAqB,EAAE,GAAGA,wBAAA,EAAkB;AAClD,EAAA,KAAA,CAAM,OAAA,CAAQ,CAAC,IAAA,KAAS;AACtB,IAAA,MAAA,CAAO,IAAI,CAAA,GAAI,WAAA,CAAY,SAAA,EAAW,CAAA,EAAG,MAAM,CAAA,CAAA,EAAI,IAAI,CAAA,CAAA,EAAIA,wBAAA,CAAkB,IAAI,CAAC,CAAA;AAAA,EACpF,CAAC,CAAA;AACD,EAAA,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Y,KAAA,EAAM,GAAIC,cAAA,EAAQ;AACtC,EAAA,MAAM,EAAE,KAAA,EAAM,GAAI,WAAA,EAAY;AAC9B,EAAA,uBACEL,cAAAA;AAAA,IAACM,qBAAA;AAAA,IAAA;AAAA,MACC,MAAA;AAAA,MACA,iBAAA,EAAkB,QAAA;AAAA,MAClB,kBAAA,EAAoB,MAAM,UAAU,CAAA;AAAA,MACpC,iBAAA,EAAmB,MAAM,cAAc,CAAA;AAAA,MACvC,OAAA,EAAS,UAAA;AAAA,MACT,OAAO,EAAE,SAAA,EAAW,OAAA,EAAS,QAAA,EAAU,SAAS,iBAAA,EAAmB,OAAA,EAAS,cAAA,EAAgB,QAAA,EAAU,aAAa,CAAA,EAAG,WAAA,EAAa,MAAM,OAAA,EAAS,YAAA,EAAc,MAAM,MAAA,EAAO;AAAA,MAE7K,0BAAAN,cAAAA,CAACO,gBAAA,EAAA,EAAK,KAAA,EAAO,EAAE,OAAO,KAAA,CAAM,SAAA,EAAW,UAAA,EAAYX,gBAAAA,CAAU,MAAM,UAAU,CAAA,EAAE,EAAI,QAAA,EAAA,KAAA,CAAM,UAAU,CAAA,EAAE;AAAA;AAAA,GACvG;AAEJ","file":"index.js","sourcesContent":["import { createContext, useContext } from 'react';\nimport type { AppTourLabelKey } from './labels';\n\nexport interface AppToursValue {\n label: (key: AppTourLabelKey) => string;\n}\n\nexport const AppToursContext = createContext<AppToursValue | null>(null);\n\n/** Returns the kit labels; must be called inside `AppTours`. */\nexport function useAppTours(): AppToursValue {\n const value = useContext(AppToursContext);\n if (value === null) throw new Error('useAppTours must be used inside AppTours');\n return value;\n}\n","import { defaultTourLabels } from '@dloizides/ui-tour';\nimport type { Tour, TourLabels } from '@dloizides/ui-tour';\n\nexport type Translate = (key: string) => string;\n\nexport const DEFAULT_LABEL_PREFIX = 'tours.labels';\n\nexport const defaultAppTourLabels = {\n takeTour: 'Take a tour',\n takeTourHint: 'Opens the list of guided tours',\n};\n\nexport type AppTourLabelKey = keyof typeof defaultAppTourLabels;\n\n/** Translates `key`; a missing or empty translation returns `fallback`. */\nexport function translateOr(translate: Translate, key: string, fallback: string): string {\n const value = translate(key);\n return typeof value === 'string' && value !== '' && value !== key ? value : fallback;\n}\n\n/** Builds every tour label from `<prefix>.<labelName>` keys, keeping the English default for a missing key. */\nexport function buildTourLabels(translate: Translate, prefix: string = DEFAULT_LABEL_PREFIX): TourLabels {\n const names = Object.keys(defaultTourLabels) as Array<keyof TourLabels>;\n const labels: TourLabels = { ...defaultTourLabels };\n names.forEach((name) => {\n labels[name] = translateOr(translate, `${prefix}.${name}`, defaultTourLabels[name]);\n });\n return labels;\n}\n\n/** Replaces each tour title, category and step text key with its translation. */\nexport function localizeTours(tours: readonly Tour[], translate: Translate): Tour[] {\n const text = (key: string): string => translateOr(translate, key, key);\n return tours.map((tour) => ({\n ...tour,\n title: text(tour.title),\n category: text(tour.category),\n steps: tour.steps.map((step) => ({ ...step, text: text(step.text) })),\n }));\n}\n","import { fontStack } from '@dloizides/ui-tour';\nimport type { TourTheme } from '@dloizides/ui-tour';\n\nexport interface AppThemeColors {\n background: string;\n surface: string;\n surfaceElevated?: string;\n text: string;\n textSecondary: string;\n border: string;\n divider?: string;\n}\n\nexport interface AppThemeSource {\n colors: AppThemeColors;\n palette: { primary: { '300'?: string; '500'?: string; '600'?: string; '700'?: string } };\n mode?: string;\n typography?: { fontFamily?: string };\n}\n\nconst DARK_MODE = 'dark';\nconst TOUR_RADIUS = 12;\nconst SCRIM_STRENGTH = '62%';\n\n/** Maps an app theme (theme-web `ResolvedTheme` or ui-feedback theme) onto the tour colour slots. */\nexport function toTourTheme(theme: AppThemeSource, dark?: boolean): TourTheme {\n const isDark = dark ?? theme.mode === DARK_MODE;\n const { colors, palette } = theme;\n const lightAccent = palette.primary['700'] ?? palette.primary['600'] ?? palette.primary['500'] ?? colors.text;\n const accent = isDark ? palette.primary['300'] ?? colors.text : lightAccent;\n const shade = isDark ? colors.background : colors.text;\n return {\n accent,\n onAccent: isDark ? colors.background : colors.surface,\n surface: colors.surfaceElevated ?? colors.surface,\n onSurface: colors.text,\n muted: colors.textSecondary,\n scrim: `color-mix(in srgb, ${shade} ${SCRIM_STRENGTH}, transparent)`,\n divider: colors.divider ?? colors.border,\n radius: TOUR_RADIUS,\n fontFamily: fontStack(theme.typography?.fontFamily),\n };\n}\n","import type { TourEvent } from '@dloizides/ui-tour';\n\ninterface UmamiWindow {\n umami?: { track: (name: string, data?: Record<string, string>) => void };\n}\n\n/** Sends a tour event to Umami (when its script is loaded) with only the tour id and mode. */\nexport function trackTourEvent(event: TourEvent): void {\n if (typeof window === 'undefined') return;\n (window as unknown as UmamiWindow).umami?.track(event.type, { tourId: event.tourId, mode: event.mode });\n}\n","import { useCallback, useMemo } from 'react';\nimport type { ReactElement, ReactNode } from 'react';\nimport { useRouter } from 'expo-router';\nimport { FirstRunOffer, TourPicker, TourProvider } from '@dloizides/ui-tour';\nimport type { Tour, TourEvent, TourUser, TourVars } from '@dloizides/ui-tour';\nimport { AppToursContext } from './AppToursContext';\nimport type { AppToursValue } from './AppToursContext';\nimport { buildTourLabels, DEFAULT_LABEL_PREFIX, defaultAppTourLabels, localizeTours, translateOr } from './labels';\nimport type { AppTourLabelKey, Translate } from './labels';\nimport { toTourTheme } from './toTourTheme';\nimport type { AppThemeSource } from './toTourTheme';\nimport { trackTourEvent } from './trackTourEvent';\n\nexport interface AppToursProps {\n tours: readonly Tour[];\n translate: Translate;\n theme: AppThemeSource;\n dark?: boolean;\n user?: TourUser | null;\n vars?: TourVars;\n navigate?: (route: string) => void;\n labelPrefix?: string;\n allowWrites?: boolean;\n onEvent?: (event: TourEvent) => void;\n children?: ReactNode;\n}\n\n/** One-line tour setup for an Expo Router app: router, theme, translated labels, Umami events, picker and first-run card. */\nexport function AppTours(props: AppToursProps): ReactElement {\n const router = useRouter();\n const { translate, onEvent: extraEvent } = props;\n const prefix = props.labelPrefix ?? DEFAULT_LABEL_PREFIX;\n const navigate = props.navigate ?? router.push;\n const tours = useMemo(() => localizeTours(props.tours, translate), [props.tours, translate]);\n const labels = useMemo(() => buildTourLabels(translate, prefix), [translate, prefix]);\n const theme = useMemo(() => toTourTheme(props.theme, props.dark), [props.theme, props.dark]);\n const onEvent = useCallback((event: TourEvent) => {\n trackTourEvent(event);\n extraEvent?.(event);\n }, [extraEvent]);\n const appValue = useMemo<AppToursValue>(() => ({\n label: (key: AppTourLabelKey) => translateOr(translate, `${prefix}.${key}`, defaultAppTourLabels[key]),\n }), [translate, prefix]);\n return (\n <AppToursContext.Provider value={appValue}>\n <TourProvider tours={tours} navigate={navigate} theme={theme} labels={labels} user={props.user} vars={props.vars} allowWrites={props.allowWrites} onEvent={onEvent}>\n {props.children}\n <TourPicker />\n <FirstRunOffer />\n </TourProvider>\n </AppToursContext.Provider>\n );\n}\n","import type { ReactElement } from 'react';\nimport { Pressable, Text } from 'react-native';\nimport { fontStack, useTour } from '@dloizides/ui-tour';\nimport { useAppTours } from './AppToursContext';\n\nexport interface TourButtonProps {\n testID?: string;\n}\n\nconst MIN_HIT = 44;\nconst PADDING = 12;\n\n/** \"Take a tour\" button for the shell help slot; opens the tour picker (F2 does the same). */\nexport function TourButton({ testID = 'take-tour' }: TourButtonProps): ReactElement {\n const { openPicker, theme } = useTour();\n const { label } = useAppTours();\n return (\n <Pressable\n testID={testID}\n accessibilityRole=\"button\"\n accessibilityLabel={label('takeTour')}\n accessibilityHint={label('takeTourHint')}\n onPress={openPicker}\n style={{ minHeight: MIN_HIT, minWidth: MIN_HIT, paddingHorizontal: PADDING, justifyContent: 'center', borderWidth: 1, borderColor: theme.divider, borderRadius: theme.radius }}\n >\n <Text style={{ color: theme.onSurface, fontFamily: fontStack(theme.fontFamily) }}>{label('takeTour')}</Text>\n </Pressable>\n );\n}\n"]}
@@ -0,0 +1,109 @@
1
+ import { createContext, useContext, useMemo, useCallback } from 'react';
2
+ import { useRouter } from 'expo-router';
3
+ import { defaultTourLabels, fontStack, TourProvider, TourPicker, FirstRunOffer, useTour } from '@dloizides/ui-tour';
4
+ import { jsx, jsxs } from 'react/jsx-runtime';
5
+ import { Pressable, Text } from 'react-native';
6
+
7
+ // src/expo/AppTours.tsx
8
+ var AppToursContext = createContext(null);
9
+ function useAppTours() {
10
+ const value = useContext(AppToursContext);
11
+ if (value === null) throw new Error("useAppTours must be used inside AppTours");
12
+ return value;
13
+ }
14
+ var DEFAULT_LABEL_PREFIX = "tours.labels";
15
+ var defaultAppTourLabels = {
16
+ takeTour: "Take a tour",
17
+ takeTourHint: "Opens the list of guided tours"
18
+ };
19
+ function translateOr(translate, key, fallback) {
20
+ const value = translate(key);
21
+ return typeof value === "string" && value !== "" && value !== key ? value : fallback;
22
+ }
23
+ function buildTourLabels(translate, prefix = DEFAULT_LABEL_PREFIX) {
24
+ const names = Object.keys(defaultTourLabels);
25
+ const labels = { ...defaultTourLabels };
26
+ names.forEach((name) => {
27
+ labels[name] = translateOr(translate, `${prefix}.${name}`, defaultTourLabels[name]);
28
+ });
29
+ return labels;
30
+ }
31
+ function localizeTours(tours, translate) {
32
+ const text = (key) => translateOr(translate, key, key);
33
+ return tours.map((tour) => ({
34
+ ...tour,
35
+ title: text(tour.title),
36
+ category: text(tour.category),
37
+ steps: tour.steps.map((step) => ({ ...step, text: text(step.text) }))
38
+ }));
39
+ }
40
+ var DARK_MODE = "dark";
41
+ var TOUR_RADIUS = 12;
42
+ var SCRIM_STRENGTH = "62%";
43
+ function toTourTheme(theme, dark) {
44
+ const isDark = dark ?? theme.mode === DARK_MODE;
45
+ const { colors, palette } = theme;
46
+ const lightAccent = palette.primary["700"] ?? palette.primary["600"] ?? palette.primary["500"] ?? colors.text;
47
+ const accent = isDark ? palette.primary["300"] ?? colors.text : lightAccent;
48
+ const shade = isDark ? colors.background : colors.text;
49
+ return {
50
+ accent,
51
+ onAccent: isDark ? colors.background : colors.surface,
52
+ surface: colors.surfaceElevated ?? colors.surface,
53
+ onSurface: colors.text,
54
+ muted: colors.textSecondary,
55
+ scrim: `color-mix(in srgb, ${shade} ${SCRIM_STRENGTH}, transparent)`,
56
+ divider: colors.divider ?? colors.border,
57
+ radius: TOUR_RADIUS,
58
+ fontFamily: fontStack(theme.typography?.fontFamily)
59
+ };
60
+ }
61
+
62
+ // src/expo/trackTourEvent.ts
63
+ function trackTourEvent(event) {
64
+ if (typeof window === "undefined") return;
65
+ window.umami?.track(event.type, { tourId: event.tourId, mode: event.mode });
66
+ }
67
+ function AppTours(props) {
68
+ const router = useRouter();
69
+ const { translate, onEvent: extraEvent } = props;
70
+ const prefix = props.labelPrefix ?? DEFAULT_LABEL_PREFIX;
71
+ const navigate = props.navigate ?? router.push;
72
+ const tours = useMemo(() => localizeTours(props.tours, translate), [props.tours, translate]);
73
+ const labels = useMemo(() => buildTourLabels(translate, prefix), [translate, prefix]);
74
+ const theme = useMemo(() => toTourTheme(props.theme, props.dark), [props.theme, props.dark]);
75
+ const onEvent = useCallback((event) => {
76
+ trackTourEvent(event);
77
+ extraEvent?.(event);
78
+ }, [extraEvent]);
79
+ const appValue = useMemo(() => ({
80
+ label: (key) => translateOr(translate, `${prefix}.${key}`, defaultAppTourLabels[key])
81
+ }), [translate, prefix]);
82
+ return /* @__PURE__ */ jsx(AppToursContext.Provider, { value: appValue, children: /* @__PURE__ */ jsxs(TourProvider, { tours, navigate, theme, labels, user: props.user, vars: props.vars, allowWrites: props.allowWrites, onEvent, children: [
83
+ props.children,
84
+ /* @__PURE__ */ jsx(TourPicker, {}),
85
+ /* @__PURE__ */ jsx(FirstRunOffer, {})
86
+ ] }) });
87
+ }
88
+ var MIN_HIT = 44;
89
+ var PADDING = 12;
90
+ function TourButton({ testID = "take-tour" }) {
91
+ const { openPicker, theme } = useTour();
92
+ const { label } = useAppTours();
93
+ return /* @__PURE__ */ jsx(
94
+ Pressable,
95
+ {
96
+ testID,
97
+ accessibilityRole: "button",
98
+ accessibilityLabel: label("takeTour"),
99
+ accessibilityHint: label("takeTourHint"),
100
+ onPress: openPicker,
101
+ style: { minHeight: MIN_HIT, minWidth: MIN_HIT, paddingHorizontal: PADDING, justifyContent: "center", borderWidth: 1, borderColor: theme.divider, borderRadius: theme.radius },
102
+ children: /* @__PURE__ */ jsx(Text, { style: { color: theme.onSurface, fontFamily: fontStack(theme.fontFamily) }, children: label("takeTour") })
103
+ }
104
+ );
105
+ }
106
+
107
+ export { AppTours, DEFAULT_LABEL_PREFIX, TourButton, buildTourLabels, defaultAppTourLabels, localizeTours, toTourTheme, trackTourEvent, translateOr, useAppTours };
108
+ //# sourceMappingURL=index.mjs.map
109
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/expo/AppToursContext.ts","../../src/expo/labels.ts","../../src/expo/toTourTheme.ts","../../src/expo/trackTourEvent.ts","../../src/expo/AppTours.tsx","../../src/expo/TourButton.tsx"],"names":["jsx","fontStack"],"mappings":";;;;;;;AAOO,IAAM,eAAA,GAAkB,cAAoC,IAAI,CAAA;AAGhE,SAAS,WAAA,GAA6B;AAC3C,EAAA,MAAM,KAAA,GAAQ,WAAW,eAAe,CAAA;AACxC,EAAA,IAAI,KAAA,KAAU,IAAA,EAAM,MAAM,IAAI,MAAM,0CAA0C,CAAA;AAC9E,EAAA,OAAO,KAAA;AACT;ACTO,IAAM,oBAAA,GAAuB;AAE7B,IAAM,oBAAA,GAAuB;AAAA,EAClC,QAAA,EAAU,aAAA;AAAA,EACV,YAAA,EAAc;AAChB;AAKO,SAAS,WAAA,CAAY,SAAA,EAAsB,GAAA,EAAa,QAAA,EAA0B;AACvF,EAAA,MAAM,KAAA,GAAQ,UAAU,GAAG,CAAA;AAC3B,EAAA,OAAO,OAAO,KAAA,KAAU,QAAA,IAAY,UAAU,EAAA,IAAM,KAAA,KAAU,MAAM,KAAA,GAAQ,QAAA;AAC9E;AAGO,SAAS,eAAA,CAAgB,SAAA,EAAsB,MAAA,GAAiB,oBAAA,EAAkC;AACvG,EAAA,MAAM,KAAA,GAAQ,MAAA,CAAO,IAAA,CAAK,iBAAiB,CA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A;AAAA,IAAA,KAAA,CAAM,QAAA;AAAA,wBACN,UAAA,EAAA,EAAW,CAAA;AAAA,wBACX,aAAA,EAAA,EAAc;AAAA,GAAA,EACjB,CAAA,EACF,CAAA;AAEJ;AC3CA,IAAM,OAAA,GAAU,EAAA;AAChB,IAAM,OAAA,GAAU,EAAA;AAGT,SAAS,UAAA,CAAW,EAAE,MAAA,GAAS,WAAA,EAAY,EAAkC;AAClF,EAAA,MAAM,EAAE,UAAA,EAAY,KAAA,EAAM,GAAI,OAAA,EAAQ;AACtC,EAAA,MAAM,EAAE,KAAA,EAAM,GAAI,WAAA,EAAY;AAC9B,EAAA,uBACEA,GAAAA;AAAA,IAAC,SAAA;AAAA,IAAA;AAAA,MACC,MAAA;AAAA,MACA,iBAAA,EAAkB,QAAA;AAAA,MAClB,kBAAA,EAAoB,MAAM,UAAU,CAAA;AAAA,MACpC,iBAAA,EAAmB,MAAM,cAAc,CAAA;AAAA,MACvC,OAAA,EAAS,UAAA;AAAA,MACT,OAAO,EAAE,SAAA,EAAW,OAAA,EAAS,QAAA,EAAU,SAAS,iBAAA,EAAmB,OAAA,EAAS,cAAA,EAAgB,QAAA,EAAU,aAAa,CAAA,EAAG,WAAA,EAAa,MAAM,OAAA,EAAS,YAAA,EAAc,MAAM,MAAA,EAAO;AAAA,MAE7K,0BAAAA,GAAAA,CAAC,IAAA,EAAA,EAAK,KAAA,EAAO,EAAE,OAAO,KAAA,CAAM,SAAA,EAAW,UAAA,EAAYC,SAAAA,CAAU,MAAM,UAAU,CAAA,EAAE,EAAI,QAAA,EAAA,KAAA,CAAM,UAAU,CAAA,EAAE;AAAA;AAAA,GACvG;AAEJ","file":"index.mjs","sourcesContent":["import { createContext, useContext } from 'react';\nimport type { AppTourLabelKey } from './labels';\n\nexport interface AppToursValue {\n label: (key: AppTourLabelKey) => string;\n}\n\nexport const AppToursContext = createContext<AppToursValue | null>(null);\n\n/** Returns the kit labels; must be called inside `AppTours`. */\nexport function useAppTours(): AppToursValue {\n const value = useContext(AppToursContext);\n if (value === null) throw new Error('useAppTours must be used inside AppTours');\n return value;\n}\n","import { defaultTourLabels } from '@dloizides/ui-tour';\nimport type { Tour, TourLabels } from '@dloizides/ui-tour';\n\nexport type Translate = (key: string) => string;\n\nexport const DEFAULT_LABEL_PREFIX = 'tours.labels';\n\nexport const defaultAppTourLabels = {\n takeTour: 'Take a tour',\n takeTourHint: 'Opens the list of guided tours',\n};\n\nexport type AppTourLabelKey = keyof typeof defaultAppTourLabels;\n\n/** Translates `key`; a missing or empty translation returns `fallback`. */\nexport function translateOr(translate: Translate, key: string, fallback: string): string {\n const value = translate(key);\n return typeof value === 'string' && value !== '' && value !== key ? value : fallback;\n}\n\n/** Builds every tour label from `<prefix>.<labelName>` keys, keeping the English default for a missing key. */\nexport function buildTourLabels(translate: Translate, prefix: string = DEFAULT_LABEL_PREFIX): TourLabels {\n const names = Object.keys(defaultTourLabels) as Array<keyof TourLabels>;\n const labels: TourLabels = { ...defaultTourLabels };\n names.forEach((name) => {\n labels[name] = translateOr(translate, `${prefix}.${name}`, defaultTourLabels[name]);\n });\n return labels;\n}\n\n/** Replaces each tour title, category and step text key with its translation. */\nexport function localizeTours(tours: readonly Tour[], translate: Translate): Tour[] {\n const text = (key: string): string => translateOr(translate, key, key);\n return tours.map((tour) => ({\n ...tour,\n title: text(tour.title),\n category: text(tour.category),\n steps: tour.steps.map((step) => ({ ...step, text: text(step.text) })),\n }));\n}\n","import { fontStack } from '@dloizides/ui-tour';\nimport type { TourTheme } from '@dloizides/ui-tour';\n\nexport interface AppThemeColors {\n background: string;\n surface: string;\n surfaceElevated?: string;\n text: string;\n textSecondary: string;\n border: string;\n divider?: string;\n}\n\nexport interface AppThemeSource {\n colors: AppThemeColors;\n palette: { primary: { '300'?: string; '500'?: string; '600'?: string; '700'?: string } };\n mode?: string;\n typography?: { fontFamily?: string };\n}\n\nconst DARK_MODE = 'dark';\nconst TOUR_RADIUS = 12;\nconst SCRIM_STRENGTH = '62%';\n\n/** Maps an app theme (theme-web `ResolvedTheme` or ui-feedback theme) onto the tour colour slots. */\nexport function toTourTheme(theme: AppThemeSource, dark?: boolean): TourTheme {\n const isDark = dark ?? theme.mode === DARK_MODE;\n const { colors, palette } = theme;\n const lightAccent = palette.primary['700'] ?? palette.primary['600'] ?? palette.primary['500'] ?? colors.text;\n const accent = isDark ? palette.primary['300'] ?? colors.text : lightAccent;\n const shade = isDark ? colors.background : colors.text;\n return {\n accent,\n onAccent: isDark ? colors.background : colors.surface,\n surface: colors.surfaceElevated ?? colors.surface,\n onSurface: colors.text,\n muted: colors.textSecondary,\n scrim: `color-mix(in srgb, ${shade} ${SCRIM_STRENGTH}, transparent)`,\n divider: colors.divider ?? colors.border,\n radius: TOUR_RADIUS,\n fontFamily: fontStack(theme.typography?.fontFamily),\n };\n}\n","import type { TourEvent } from '@dloizides/ui-tour';\n\ninterface UmamiWindow {\n umami?: { track: (name: string, data?: Record<string, string>) => void };\n}\n\n/** Sends a tour event to Umami (when its script is loaded) with only the tour id and mode. */\nexport function trackTourEvent(event: TourEvent): void {\n if (typeof window === 'undefined') return;\n (window as unknown as UmamiWindow).umami?.track(event.type, { tourId: event.tourId, mode: event.mode });\n}\n","import { useCallback, useMemo } from 'react';\nimport type { ReactElement, ReactNode } from 'react';\nimport { useRouter } from 'expo-router';\nimport { FirstRunOffer, TourPicker, TourProvider } from '@dloizides/ui-tour';\nimport type { Tour, TourEvent, TourUser, TourVars } from '@dloizides/ui-tour';\nimport { AppToursContext } from './AppToursContext';\nimport type { AppToursValue } from './AppToursContext';\nimport { buildTourLabels, DEFAULT_LABEL_PREFIX, defaultAppTourLabels, localizeTours, translateOr } from './labels';\nimport type { AppTourLabelKey, Translate } from './labels';\nimport { toTourTheme } from './toTourTheme';\nimport type { AppThemeSource } from './toTourTheme';\nimport { trackTourEvent } from './trackTourEvent';\n\nexport interface AppToursProps {\n tours: readonly Tour[];\n translate: Translate;\n theme: AppThemeSource;\n dark?: boolean;\n user?: TourUser | null;\n vars?: TourVars;\n navigate?: (route: string) => void;\n labelPrefix?: string;\n allowWrites?: boolean;\n onEvent?: (event: TourEvent) => void;\n children?: ReactNode;\n}\n\n/** One-line tour setup for an Expo Router app: router, theme, translated labels, Umami events, picker and first-run card. */\nexport function AppTours(props: AppToursProps): ReactElement {\n const router = useRouter();\n const { translate, onEvent: extraEvent } = props;\n const prefix = props.labelPrefix ?? DEFAULT_LABEL_PREFIX;\n const navigate = props.navigate ?? router.push;\n const tours = useMemo(() => localizeTours(props.tours, translate), [props.tours, translate]);\n const labels = useMemo(() => buildTourLabels(translate, prefix), [translate, prefix]);\n const theme = useMemo(() => toTourTheme(props.theme, props.dark), [props.theme, props.dark]);\n const onEvent = useCallback((event: TourEvent) => {\n trackTourEvent(event);\n extraEvent?.(event);\n }, [extraEvent]);\n const appValue = useMemo<AppToursValue>(() => ({\n label: (key: AppTourLabelKey) => translateOr(translate, `${prefix}.${key}`, defaultAppTourLabels[key]),\n }), [translate, prefix]);\n return (\n <AppToursContext.Provider value={appValue}>\n <TourProvider tours={tours} navigate={navigate} theme={theme} labels={labels} user={props.user} vars={props.vars} allowWrites={props.allowWrites} onEvent={onEvent}>\n {props.children}\n <TourPicker />\n <FirstRunOffer />\n </TourProvider>\n </AppToursContext.Provider>\n );\n}\n","import type { ReactElement } from 'react';\nimport { Pressable, Text } from 'react-native';\nimport { fontStack, useTour } from '@dloizides/ui-tour';\nimport { useAppTours } from './AppToursContext';\n\nexport interface TourButtonProps {\n testID?: string;\n}\n\nconst MIN_HIT = 44;\nconst PADDING = 12;\n\n/** \"Take a tour\" button for the shell help slot; opens the tour picker (F2 does the same). */\nexport function TourButton({ testID = 'take-tour' }: TourButtonProps): ReactElement {\n const { openPicker, theme } = useTour();\n const { label } = useAppTours();\n return (\n <Pressable\n testID={testID}\n accessibilityRole=\"button\"\n accessibilityLabel={label('takeTour')}\n accessibilityHint={label('takeTourHint')}\n onPress={openPicker}\n style={{ minHeight: MIN_HIT, minWidth: MIN_HIT, paddingHorizontal: PADDING, justifyContent: 'center', borderWidth: 1, borderColor: theme.divider, borderRadius: theme.radius }}\n >\n <Text style={{ color: theme.onSurface, fontFamily: fontStack(theme.fontFamily) }}>{label('takeTour')}</Text>\n </Pressable>\n );\n}\n"]}
package/dist/index.d.mts CHANGED
@@ -205,4 +205,7 @@ declare function isForbiddenClick(name: string, allowSave: boolean): boolean;
205
205
 
206
206
  declare const DEFAULT_TIMING: TourTiming;
207
207
 
208
- export { type ActiveTour, DEFAULT_TIMING, FirstRunOffer, type FirstRunOfferProps, type Point, type RoleTarget, StepAction, StepPhase, type StepTarget, type StepView, type TargetRect, TargetRole, type Tour, type TourContextValue, type TourEvent, TourEventType, type TourLabels, TourMode, TourPicker, TourProvider, type TourProviderProps, type TourStep, type TourTheme, type TourTiming, type TourUser, type TourValidation, type TourVars, defaultTourLabels, findTarget, formatLabel, isForbiddenClick, useTour, validateTours };
208
+ /** Font stack that always ends in a generic family, so a missing web font falls back to sans-serif. */
209
+ declare function fontStack(family: string | null | undefined): string;
210
+
211
+ export { type ActiveTour, DEFAULT_TIMING, FirstRunOffer, type FirstRunOfferProps, type Point, type RoleTarget, StepAction, StepPhase, type StepTarget, type StepView, type TargetRect, TargetRole, type Tour, type TourContextValue, type TourEvent, TourEventType, type TourLabels, TourMode, TourPicker, TourProvider, type TourProviderProps, type TourStep, type TourTheme, type TourTiming, type TourUser, type TourValidation, type TourVars, defaultTourLabels, findTarget, fontStack, formatLabel, isForbiddenClick, useTour, validateTours };
package/dist/index.d.ts CHANGED
@@ -205,4 +205,7 @@ declare function isForbiddenClick(name: string, allowSave: boolean): boolean;
205
205
 
206
206
  declare const DEFAULT_TIMING: TourTiming;
207
207
 
208
- export { type ActiveTour, DEFAULT_TIMING, FirstRunOffer, type FirstRunOfferProps, type Point, type RoleTarget, StepAction, StepPhase, type StepTarget, type StepView, type TargetRect, TargetRole, type Tour, type TourContextValue, type TourEvent, TourEventType, type TourLabels, TourMode, TourPicker, TourProvider, type TourProviderProps, type TourStep, type TourTheme, type TourTiming, type TourUser, type TourValidation, type TourVars, defaultTourLabels, findTarget, formatLabel, isForbiddenClick, useTour, validateTours };
208
+ /** Font stack that always ends in a generic family, so a missing web font falls back to sans-serif. */
209
+ declare function fontStack(family: string | null | undefined): string;
210
+
211
+ export { type ActiveTour, DEFAULT_TIMING, FirstRunOffer, type FirstRunOfferProps, type Point, type RoleTarget, StepAction, StepPhase, type StepTarget, type StepView, type TargetRect, TargetRole, type Tour, type TourContextValue, type TourEvent, TourEventType, type TourLabels, TourMode, TourPicker, TourProvider, type TourProviderProps, type TourStep, type TourTheme, type TourTiming, type TourUser, type TourValidation, type TourVars, defaultTourLabels, findTarget, fontStack, formatLabel, isForbiddenClick, useTour, validateTours };
package/dist/index.js CHANGED
@@ -587,6 +587,15 @@ function useTourEngine(options) {
587
587
  };
588
588
  }
589
589
 
590
+ // src/fontStack.ts
591
+ var GENERIC_TAIL = /(^|,)\s*(sans-serif|serif|monospace|cursive|fantasy)\s*$/i;
592
+ var FALLBACK = "sans-serif";
593
+ function fontStack(family) {
594
+ const clean = (family ?? "").trim();
595
+ if (clean === "") return FALLBACK;
596
+ return GENERIC_TAIL.test(clean) ? clean : `${clean}, ${FALLBACK}`;
597
+ }
598
+
590
599
  // src/components/styles.ts
591
600
  var EASE = "cubic-bezier(.4,0,.2,1)";
592
601
  function ringStyle(theme, rect) {
@@ -620,7 +629,7 @@ function captionStyle(theme, position) {
620
629
  border: `1px solid ${theme.accent}`,
621
630
  borderRadius: theme.radius,
622
631
  padding: "14px 16px",
623
- fontFamily: theme.fontFamily,
632
+ fontFamily: fontStack(theme.fontFamily),
624
633
  fontSize: 16,
625
634
  lineHeight: 1.4,
626
635
  overflowWrap: "anywhere",
@@ -645,7 +654,7 @@ function buttonStyle(theme, primary) {
645
654
  border: `1px solid ${theme.accent}`,
646
655
  background: primary ? theme.accent : "transparent",
647
656
  color: primary ? theme.onAccent : theme.onSurface,
648
- fontFamily: theme.fontFamily,
657
+ fontFamily: fontStack(theme.fontFamily),
649
658
  fontSize: 14,
650
659
  fontWeight: 600,
651
660
  cursor: "pointer"
@@ -741,7 +750,7 @@ function TourCaption() {
741
750
  if (active === null || current === null || step === void 0) return null;
742
751
  const missing = view.phase === "missing" /* Missing */;
743
752
  const note = noteFor(tour);
744
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { ref, role: "dialog", "aria-live": "polite", "aria-label": current.title, "data-testid": "tour-caption", style: captionStyle(theme, position), children: [
753
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { ref, role: "dialog", "aria-live": "polite", "aria-label": current.title, "data-testid": "tour-caption", "data-tour-id": current.id, "data-tour-step": stepIndex + 1, "data-tour-steps": current.steps.length, style: captionStyle(theme, position), children: [
745
754
  /* @__PURE__ */ jsxRuntime.jsx("div", { style: metaStyle(theme), children: formatLabel(labels.captionMeta, current.title, stepIndex + 1, current.steps.length, modeName(tour, active.mode)) }),
746
755
  /* @__PURE__ */ jsxRuntime.jsx("div", { "data-testid": "tour-text", children: substitute(step.text, tour.vars) }),
747
756
  note !== "" ? /* @__PURE__ */ jsxRuntime.jsx("div", { "data-testid": "tour-note", style: noteStyle(theme), children: note }) : null,
@@ -823,7 +832,7 @@ function panelStyle(theme) {
823
832
  boxSizing: "border-box",
824
833
  maxHeight: "90vh",
825
834
  overflow: "auto",
826
- fontFamily: theme.fontFamily,
835
+ fontFamily: fontStack(theme.fontFamily),
827
836
  fontSize: 15,
828
837
  lineHeight: 1.4
829
838
  };
@@ -846,7 +855,7 @@ function groupButtonStyle(theme) {
846
855
  marginTop: 8,
847
856
  padding: "12px 0",
848
857
  color: theme.accent,
849
- fontFamily: theme.fontFamily,
858
+ fontFamily: fontStack(theme.fontFamily),
850
859
  fontSize: 16,
851
860
  fontWeight: 700,
852
861
  cursor: "pointer"
@@ -868,7 +877,7 @@ function offerStyle(theme) {
868
877
  border: `1px solid ${theme.accent}`,
869
878
  borderRadius: theme.radius,
870
879
  padding: 16,
871
- fontFamily: theme.fontFamily,
880
+ fontFamily: fontStack(theme.fontFamily),
872
881
  fontSize: 15,
873
882
  lineHeight: 1.4
874
883
  };
@@ -1009,6 +1018,7 @@ exports.TourPicker = TourPicker;
1009
1018
  exports.TourProvider = TourProvider;
1010
1019
  exports.defaultTourLabels = defaultTourLabels;
1011
1020
  exports.findTarget = findTarget;
1021
+ exports.fontStack = fontStack;
1012
1022
  exports.formatLabel = formatLabel;
1013
1023
  exports.isForbiddenClick = isForbiddenClick;
1014
1024
  exports.useTour = useTour;