@dloizides/ui-tour 1.2.0 → 1.2.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 +4 -0
- package/README.md +1 -1
- package/dist/expo/index.js +70 -2
- package/dist/expo/index.js.map +1 -1
- package/dist/expo/index.mjs +70 -2
- package/dist/expo/index.mjs.map +1 -1
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.2.1
|
|
4
|
+
|
|
5
|
+
- `toTourTheme` no longer trusts tokens to be contrast-safe: `onAccent` is white or the background, whichever contrasts more with the accent fill; the new optional `accentText` slot (step label, note, picker item) is the first primary shade reaching 4.5:1 on the caption surface (lighter first in dark, darker first in light), else the text colour. Fixes kefi dark (Next 3.05:1, label 2.75:1).
|
|
6
|
+
|
|
3
7
|
## 1.2.0
|
|
4
8
|
|
|
5
9
|
- `vars` placeholders are filled in a step's `route` too (`/t/{tenantSlug}/register`). `expectValidTours(tours, translations, vars)` reports a route placeholder that `vars` does not fill.
|
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`. The font always falls back to `sans-serif` (`fontStack`).
|
|
68
|
+
`accent`, `onAccent`, `accentText` (optional; accent-coloured text on the caption, defaults to `accent`), `surface`, `onSurface`, `muted`, `scrim`, `divider`, `radius`, `fontFamily`. The font always falls back to `sans-serif` (`fontStack`). `toTourTheme` (`/expo`) measures contrast instead of trusting tokens: `onAccent` is white or the background, whichever contrasts more with the accent; `accentText` is the first primary shade reaching 4.5:1 on the caption (lighter first in dark), else the text colour.
|
|
69
69
|
|
|
70
70
|
### Events
|
|
71
71
|
|
package/dist/expo/index.js
CHANGED
|
@@ -39,6 +39,72 @@ function localizeTours(tours, translate) {
|
|
|
39
39
|
steps: tour.steps.map((step) => ({ ...step, text: text(step.text) }))
|
|
40
40
|
}));
|
|
41
41
|
}
|
|
42
|
+
|
|
43
|
+
// src/expo/contrast.ts
|
|
44
|
+
var CHANNEL_MAX = 255;
|
|
45
|
+
var HEX_SHORT = 3;
|
|
46
|
+
var HEX_RADIX = 16;
|
|
47
|
+
var LINEAR_KNEE = 0.03928;
|
|
48
|
+
var LINEAR_SLOPE = 12.92;
|
|
49
|
+
var GAMMA_OFFSET = 0.055;
|
|
50
|
+
var GAMMA_SCALE = 1.055;
|
|
51
|
+
var GAMMA = 2.4;
|
|
52
|
+
var RED_WEIGHT = 0.2126;
|
|
53
|
+
var GREEN_WEIGHT = 0.7152;
|
|
54
|
+
var BLUE_WEIGHT = 0.0722;
|
|
55
|
+
var FLARE = 0.05;
|
|
56
|
+
var WHITE_KEYWORD = "white";
|
|
57
|
+
var RGB_PATTERN = /^rgba?\(\s*(\d+(?:\.\d+)?)[\s,]+(\d+(?:\.\d+)?)[\s,]+(\d+(?:\.\d+)?)/i;
|
|
58
|
+
var HEX_PATTERN = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i;
|
|
59
|
+
var MIN_TEXT_CONTRAST = 4.5;
|
|
60
|
+
function hexChannels(hex) {
|
|
61
|
+
const digits = hex.length === HEX_SHORT ? hex.split("").map((digit) => digit + digit).join("") : hex;
|
|
62
|
+
const read = (start) => parseInt(digits.slice(start, start + 2), HEX_RADIX);
|
|
63
|
+
return [read(0), read(2), read(4)];
|
|
64
|
+
}
|
|
65
|
+
function channels(color) {
|
|
66
|
+
const value = color.trim();
|
|
67
|
+
if (value.toLowerCase() === WHITE_KEYWORD) return [CHANNEL_MAX, CHANNEL_MAX, CHANNEL_MAX];
|
|
68
|
+
const hex = HEX_PATTERN.exec(value)?.[1];
|
|
69
|
+
if (hex !== void 0) return hexChannels(hex);
|
|
70
|
+
const rgb = RGB_PATTERN.exec(value);
|
|
71
|
+
return rgb === null ? void 0 : [Number(rgb[1] ?? 0), Number(rgb[2] ?? 0), Number(rgb[3] ?? 0)];
|
|
72
|
+
}
|
|
73
|
+
function linear(channel) {
|
|
74
|
+
const unit = channel / CHANNEL_MAX;
|
|
75
|
+
return unit <= LINEAR_KNEE ? unit / LINEAR_SLOPE : ((unit + GAMMA_OFFSET) / GAMMA_SCALE) ** GAMMA;
|
|
76
|
+
}
|
|
77
|
+
function luminance(color) {
|
|
78
|
+
const rgb = channels(color);
|
|
79
|
+
if (rgb === void 0) return void 0;
|
|
80
|
+
const [red, green, blue] = rgb;
|
|
81
|
+
return RED_WEIGHT * linear(red) + GREEN_WEIGHT * linear(green) + BLUE_WEIGHT * linear(blue);
|
|
82
|
+
}
|
|
83
|
+
function contrastRatio(first, second) {
|
|
84
|
+
const a = luminance(first);
|
|
85
|
+
const b = luminance(second);
|
|
86
|
+
if (a === void 0 || b === void 0) return 0;
|
|
87
|
+
return (Math.max(a, b) + FLARE) / (Math.min(a, b) + FLARE);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// src/expo/accentInk.ts
|
|
91
|
+
var WHITE = "white";
|
|
92
|
+
var WHITE_LUMINANCE = 1;
|
|
93
|
+
var LIGHT_FIRST = ["300", "500", "600", "700"];
|
|
94
|
+
var DARK_FIRST = ["700", "600", "500", "300"];
|
|
95
|
+
function pickOnAccent(accent, background, surface, fallback) {
|
|
96
|
+
if (luminance(accent) === void 0) return fallback;
|
|
97
|
+
const white = luminance(surface) === WHITE_LUMINANCE ? surface : WHITE;
|
|
98
|
+
return contrastRatio(white, accent) >= contrastRatio(background, accent) ? white : background;
|
|
99
|
+
}
|
|
100
|
+
function pickAccentText(shades, captionSurface, text, isDark, fallback) {
|
|
101
|
+
if (luminance(captionSurface) === void 0) return fallback;
|
|
102
|
+
const order = isDark ? LIGHT_FIRST : DARK_FIRST;
|
|
103
|
+
const passing = order.map((key) => shades[key]).find((shade) => shade !== void 0 && contrastRatio(shade, captionSurface) >= MIN_TEXT_CONTRAST);
|
|
104
|
+
return passing ?? text;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// src/expo/toTourTheme.ts
|
|
42
108
|
var DARK_MODE = "dark";
|
|
43
109
|
var TOUR_RADIUS = 12;
|
|
44
110
|
var SCRIM_STRENGTH = "62%";
|
|
@@ -48,10 +114,12 @@ function toTourTheme(theme, dark) {
|
|
|
48
114
|
const lightAccent = palette.primary["700"] ?? palette.primary["600"] ?? palette.primary["500"] ?? colors.text;
|
|
49
115
|
const accent = isDark ? palette.primary["300"] ?? colors.text : lightAccent;
|
|
50
116
|
const shade = isDark ? colors.background : colors.text;
|
|
117
|
+
const surface = colors.surfaceElevated ?? colors.surface;
|
|
51
118
|
return {
|
|
52
119
|
accent,
|
|
53
|
-
onAccent: isDark ? colors.background : colors.surface,
|
|
54
|
-
|
|
120
|
+
onAccent: pickOnAccent(accent, colors.background, colors.surface, isDark ? colors.background : colors.surface),
|
|
121
|
+
accentText: pickAccentText(palette.primary, surface, colors.text, isDark, accent),
|
|
122
|
+
surface,
|
|
55
123
|
onSurface: colors.text,
|
|
56
124
|
muted: colors.textSecondary,
|
|
57
125
|
scrim: `color-mix(in srgb, ${shade} ${SCRIM_STRENGTH}, transparent)`,
|
package/dist/expo/index.js.map
CHANGED
|
@@ -1 +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","FirstRunO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,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"]}
|
|
1
|
+
{"version":3,"sources":["../../src/expo/AppToursContext.ts","../../src/expo/labels.ts","../../src/expo/contrast.ts","../../src/expo/accentInk.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,G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AAA;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","const CHANNEL_MAX = 255;\nconst HEX_SHORT = 3;\nconst HEX_RADIX = 16;\nconst LINEAR_KNEE = 0.03928;\nconst LINEAR_SLOPE = 12.92;\nconst GAMMA_OFFSET = 0.055;\nconst GAMMA_SCALE = 1.055;\nconst GAMMA = 2.4;\nconst RED_WEIGHT = 0.2126;\nconst GREEN_WEIGHT = 0.7152;\nconst BLUE_WEIGHT = 0.0722;\nconst FLARE = 0.05;\nconst WHITE_KEYWORD = 'white';\nconst RGB_PATTERN = /^rgba?\\(\\s*(\\d+(?:\\.\\d+)?)[\\s,]+(\\d+(?:\\.\\d+)?)[\\s,]+(\\d+(?:\\.\\d+)?)/i;\nconst HEX_PATTERN = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i;\n\n/** Minimum WCAG AA contrast for normal-size text. */\nexport const MIN_TEXT_CONTRAST = 4.5;\n\ntype Channels = [number, number, number];\n\nfunction hexChannels(hex: string): Channels {\n const digits = hex.length === HEX_SHORT ? hex.split('').map((digit) => digit + digit).join('') : hex;\n const read = (start: number): number => parseInt(digits.slice(start, start + 2), HEX_RADIX);\n return [read(0), read(2), read(4)];\n}\n\nfunction channels(color: string): Channels | undefined {\n const value = color.trim();\n if (value.toLowerCase() === WHITE_KEYWORD) return [CHANNEL_MAX, CHANNEL_MAX, CHANNEL_MAX];\n const hex = HEX_PATTERN.exec(value)?.[1];\n if (hex !== undefined) return hexChannels(hex);\n const rgb = RGB_PATTERN.exec(value);\n return rgb === null ? undefined : [Number(rgb[1] ?? 0), Number(rgb[2] ?? 0), Number(rgb[3] ?? 0)];\n}\n\nfunction linear(channel: number): number {\n const unit = channel / CHANNEL_MAX;\n return unit <= LINEAR_KNEE ? unit / LINEAR_SLOPE : ((unit + GAMMA_OFFSET) / GAMMA_SCALE) ** GAMMA;\n}\n\n/** WCAG relative luminance of a hex, rgb or white colour, or undefined when it cannot be parsed. */\nexport function luminance(color: string): number | undefined {\n const rgb = channels(color);\n if (rgb === undefined) return undefined;\n const [red, green, blue] = rgb;\n return RED_WEIGHT * linear(red) + GREEN_WEIGHT * linear(green) + BLUE_WEIGHT * linear(blue);\n}\n\n/** WCAG contrast ratio of two hex, rgb or white colours; 0 when either cannot be parsed. */\nexport function contrastRatio(first: string, second: string): number {\n const a = luminance(first);\n const b = luminance(second);\n if (a === undefined || b === undefined) return 0;\n return (Math.max(a, b) + FLARE) / (Math.min(a, b) + FLARE);\n}\n","import { contrastRatio, luminance, MIN_TEXT_CONTRAST } from './contrast';\n\nconst WHITE = 'white';\nconst WHITE_LUMINANCE = 1;\n\ntype Shades = Partial<Record<'300' | '500' | '600' | '700', string>>;\n\nconst LIGHT_FIRST = ['300', '500', '600', '700'] as const;\nconst DARK_FIRST = ['700', '600', '500', '300'] as const;\n\n/** Picks white or the background, whichever contrasts more with the accent fill; `fallback` when the accent cannot be measured. */\nexport function pickOnAccent(accent: string, background: string, surface: string, fallback: string): string {\n if (luminance(accent) === undefined) return fallback;\n const white = luminance(surface) === WHITE_LUMINANCE ? surface : WHITE;\n return contrastRatio(white, accent) >= contrastRatio(background, accent) ? white : background;\n}\n\n/** First primary shade reaching AA on the caption surface (lighter first in dark), else the text colour; `fallback` when the surface cannot be measured. */\nexport function pickAccentText(shades: Shades, captionSurface: string, text: string, isDark: boolean, fallback: string): string {\n if (luminance(captionSurface) === undefined) return fallback;\n const order = isDark ? LIGHT_FIRST : DARK_FIRST;\n const passing = order.map((key) => shades[key]).find((shade) => shade !== undefined && contrastRatio(shade, captionSurface) >= MIN_TEXT_CONTRAST);\n return passing ?? text;\n}\n","import { fontStack } from '@dloizides/ui-tour';\nimport type { TourTheme } from '@dloizides/ui-tour';\n\nimport { pickAccentText, pickOnAccent } from './accentInk';\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 const surface = colors.surfaceElevated ?? colors.surface;\n return {\n accent,\n onAccent: pickOnAccent(accent, colors.background, colors.surface, isDark ? colors.background : colors.surface),\n accentText: pickAccentText(palette.primary, surface, colors.text, isDark, accent),\n 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/expo/index.mjs
CHANGED
|
@@ -37,6 +37,72 @@ function localizeTours(tours, translate) {
|
|
|
37
37
|
steps: tour.steps.map((step) => ({ ...step, text: text(step.text) }))
|
|
38
38
|
}));
|
|
39
39
|
}
|
|
40
|
+
|
|
41
|
+
// src/expo/contrast.ts
|
|
42
|
+
var CHANNEL_MAX = 255;
|
|
43
|
+
var HEX_SHORT = 3;
|
|
44
|
+
var HEX_RADIX = 16;
|
|
45
|
+
var LINEAR_KNEE = 0.03928;
|
|
46
|
+
var LINEAR_SLOPE = 12.92;
|
|
47
|
+
var GAMMA_OFFSET = 0.055;
|
|
48
|
+
var GAMMA_SCALE = 1.055;
|
|
49
|
+
var GAMMA = 2.4;
|
|
50
|
+
var RED_WEIGHT = 0.2126;
|
|
51
|
+
var GREEN_WEIGHT = 0.7152;
|
|
52
|
+
var BLUE_WEIGHT = 0.0722;
|
|
53
|
+
var FLARE = 0.05;
|
|
54
|
+
var WHITE_KEYWORD = "white";
|
|
55
|
+
var RGB_PATTERN = /^rgba?\(\s*(\d+(?:\.\d+)?)[\s,]+(\d+(?:\.\d+)?)[\s,]+(\d+(?:\.\d+)?)/i;
|
|
56
|
+
var HEX_PATTERN = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i;
|
|
57
|
+
var MIN_TEXT_CONTRAST = 4.5;
|
|
58
|
+
function hexChannels(hex) {
|
|
59
|
+
const digits = hex.length === HEX_SHORT ? hex.split("").map((digit) => digit + digit).join("") : hex;
|
|
60
|
+
const read = (start) => parseInt(digits.slice(start, start + 2), HEX_RADIX);
|
|
61
|
+
return [read(0), read(2), read(4)];
|
|
62
|
+
}
|
|
63
|
+
function channels(color) {
|
|
64
|
+
const value = color.trim();
|
|
65
|
+
if (value.toLowerCase() === WHITE_KEYWORD) return [CHANNEL_MAX, CHANNEL_MAX, CHANNEL_MAX];
|
|
66
|
+
const hex = HEX_PATTERN.exec(value)?.[1];
|
|
67
|
+
if (hex !== void 0) return hexChannels(hex);
|
|
68
|
+
const rgb = RGB_PATTERN.exec(value);
|
|
69
|
+
return rgb === null ? void 0 : [Number(rgb[1] ?? 0), Number(rgb[2] ?? 0), Number(rgb[3] ?? 0)];
|
|
70
|
+
}
|
|
71
|
+
function linear(channel) {
|
|
72
|
+
const unit = channel / CHANNEL_MAX;
|
|
73
|
+
return unit <= LINEAR_KNEE ? unit / LINEAR_SLOPE : ((unit + GAMMA_OFFSET) / GAMMA_SCALE) ** GAMMA;
|
|
74
|
+
}
|
|
75
|
+
function luminance(color) {
|
|
76
|
+
const rgb = channels(color);
|
|
77
|
+
if (rgb === void 0) return void 0;
|
|
78
|
+
const [red, green, blue] = rgb;
|
|
79
|
+
return RED_WEIGHT * linear(red) + GREEN_WEIGHT * linear(green) + BLUE_WEIGHT * linear(blue);
|
|
80
|
+
}
|
|
81
|
+
function contrastRatio(first, second) {
|
|
82
|
+
const a = luminance(first);
|
|
83
|
+
const b = luminance(second);
|
|
84
|
+
if (a === void 0 || b === void 0) return 0;
|
|
85
|
+
return (Math.max(a, b) + FLARE) / (Math.min(a, b) + FLARE);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// src/expo/accentInk.ts
|
|
89
|
+
var WHITE = "white";
|
|
90
|
+
var WHITE_LUMINANCE = 1;
|
|
91
|
+
var LIGHT_FIRST = ["300", "500", "600", "700"];
|
|
92
|
+
var DARK_FIRST = ["700", "600", "500", "300"];
|
|
93
|
+
function pickOnAccent(accent, background, surface, fallback) {
|
|
94
|
+
if (luminance(accent) === void 0) return fallback;
|
|
95
|
+
const white = luminance(surface) === WHITE_LUMINANCE ? surface : WHITE;
|
|
96
|
+
return contrastRatio(white, accent) >= contrastRatio(background, accent) ? white : background;
|
|
97
|
+
}
|
|
98
|
+
function pickAccentText(shades, captionSurface, text, isDark, fallback) {
|
|
99
|
+
if (luminance(captionSurface) === void 0) return fallback;
|
|
100
|
+
const order = isDark ? LIGHT_FIRST : DARK_FIRST;
|
|
101
|
+
const passing = order.map((key) => shades[key]).find((shade) => shade !== void 0 && contrastRatio(shade, captionSurface) >= MIN_TEXT_CONTRAST);
|
|
102
|
+
return passing ?? text;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// src/expo/toTourTheme.ts
|
|
40
106
|
var DARK_MODE = "dark";
|
|
41
107
|
var TOUR_RADIUS = 12;
|
|
42
108
|
var SCRIM_STRENGTH = "62%";
|
|
@@ -46,10 +112,12 @@ function toTourTheme(theme, dark) {
|
|
|
46
112
|
const lightAccent = palette.primary["700"] ?? palette.primary["600"] ?? palette.primary["500"] ?? colors.text;
|
|
47
113
|
const accent = isDark ? palette.primary["300"] ?? colors.text : lightAccent;
|
|
48
114
|
const shade = isDark ? colors.background : colors.text;
|
|
115
|
+
const surface = colors.surfaceElevated ?? colors.surface;
|
|
49
116
|
return {
|
|
50
117
|
accent,
|
|
51
|
-
onAccent: isDark ? colors.background : colors.surface,
|
|
52
|
-
|
|
118
|
+
onAccent: pickOnAccent(accent, colors.background, colors.surface, isDark ? colors.background : colors.surface),
|
|
119
|
+
accentText: pickAccentText(palette.primary, surface, colors.text, isDark, accent),
|
|
120
|
+
surface,
|
|
53
121
|
onSurface: colors.text,
|
|
54
122
|
muted: colors.textSecondary,
|
|
55
123
|
scrim: `color-mix(in srgb, ${shade} ${SCRIM_STRENGTH}, transparent)`,
|
package/dist/expo/index.mjs.map
CHANGED
|
@@ -1 +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,CAAA;AAC3C,EAAA,MAAM,MAAA,GAAqB,EAAE,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N,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"]}
|
|
1
|
+
{"version":3,"sources":["../../src/expo/AppToursContext.ts","../../src/expo/labels.ts","../../src/expo/contrast.ts","../../src/expo/accentInk.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,CAAA;AAC3C,EAAA,MAAM,MAAA,GAAqB,EAAE,GAAG,iBAAA,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,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,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","const CHANNEL_MAX = 255;\nconst HEX_SHORT = 3;\nconst HEX_RADIX = 16;\nconst LINEAR_KNEE = 0.03928;\nconst LINEAR_SLOPE = 12.92;\nconst GAMMA_OFFSET = 0.055;\nconst GAMMA_SCALE = 1.055;\nconst GAMMA = 2.4;\nconst RED_WEIGHT = 0.2126;\nconst GREEN_WEIGHT = 0.7152;\nconst BLUE_WEIGHT = 0.0722;\nconst FLARE = 0.05;\nconst WHITE_KEYWORD = 'white';\nconst RGB_PATTERN = /^rgba?\\(\\s*(\\d+(?:\\.\\d+)?)[\\s,]+(\\d+(?:\\.\\d+)?)[\\s,]+(\\d+(?:\\.\\d+)?)/i;\nconst HEX_PATTERN = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i;\n\n/** Minimum WCAG AA contrast for normal-size text. */\nexport const MIN_TEXT_CONTRAST = 4.5;\n\ntype Channels = [number, number, number];\n\nfunction hexChannels(hex: string): Channels {\n const digits = hex.length === HEX_SHORT ? hex.split('').map((digit) => digit + digit).join('') : hex;\n const read = (start: number): number => parseInt(digits.slice(start, start + 2), HEX_RADIX);\n return [read(0), read(2), read(4)];\n}\n\nfunction channels(color: string): Channels | undefined {\n const value = color.trim();\n if (value.toLowerCase() === WHITE_KEYWORD) return [CHANNEL_MAX, CHANNEL_MAX, CHANNEL_MAX];\n const hex = HEX_PATTERN.exec(value)?.[1];\n if (hex !== undefined) return hexChannels(hex);\n const rgb = RGB_PATTERN.exec(value);\n return rgb === null ? undefined : [Number(rgb[1] ?? 0), Number(rgb[2] ?? 0), Number(rgb[3] ?? 0)];\n}\n\nfunction linear(channel: number): number {\n const unit = channel / CHANNEL_MAX;\n return unit <= LINEAR_KNEE ? unit / LINEAR_SLOPE : ((unit + GAMMA_OFFSET) / GAMMA_SCALE) ** GAMMA;\n}\n\n/** WCAG relative luminance of a hex, rgb or white colour, or undefined when it cannot be parsed. */\nexport function luminance(color: string): number | undefined {\n const rgb = channels(color);\n if (rgb === undefined) return undefined;\n const [red, green, blue] = rgb;\n return RED_WEIGHT * linear(red) + GREEN_WEIGHT * linear(green) + BLUE_WEIGHT * linear(blue);\n}\n\n/** WCAG contrast ratio of two hex, rgb or white colours; 0 when either cannot be parsed. */\nexport function contrastRatio(first: string, second: string): number {\n const a = luminance(first);\n const b = luminance(second);\n if (a === undefined || b === undefined) return 0;\n return (Math.max(a, b) + FLARE) / (Math.min(a, b) + FLARE);\n}\n","import { contrastRatio, luminance, MIN_TEXT_CONTRAST } from './contrast';\n\nconst WHITE = 'white';\nconst WHITE_LUMINANCE = 1;\n\ntype Shades = Partial<Record<'300' | '500' | '600' | '700', string>>;\n\nconst LIGHT_FIRST = ['300', '500', '600', '700'] as const;\nconst DARK_FIRST = ['700', '600', '500', '300'] as const;\n\n/** Picks white or the background, whichever contrasts more with the accent fill; `fallback` when the accent cannot be measured. */\nexport function pickOnAccent(accent: string, background: string, surface: string, fallback: string): string {\n if (luminance(accent) === undefined) return fallback;\n const white = luminance(surface) === WHITE_LUMINANCE ? surface : WHITE;\n return contrastRatio(white, accent) >= contrastRatio(background, accent) ? white : background;\n}\n\n/** First primary shade reaching AA on the caption surface (lighter first in dark), else the text colour; `fallback` when the surface cannot be measured. */\nexport function pickAccentText(shades: Shades, captionSurface: string, text: string, isDark: boolean, fallback: string): string {\n if (luminance(captionSurface) === undefined) return fallback;\n const order = isDark ? LIGHT_FIRST : DARK_FIRST;\n const passing = order.map((key) => shades[key]).find((shade) => shade !== undefined && contrastRatio(shade, captionSurface) >= MIN_TEXT_CONTRAST);\n return passing ?? text;\n}\n","import { fontStack } from '@dloizides/ui-tour';\nimport type { TourTheme } from '@dloizides/ui-tour';\n\nimport { pickAccentText, pickOnAccent } from './accentInk';\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 const surface = colors.surfaceElevated ?? colors.surface;\n return {\n accent,\n onAccent: pickOnAccent(accent, colors.background, colors.surface, isDark ? colors.background : colors.surface),\n accentText: pickAccentText(palette.primary, surface, colors.text, isDark, accent),\n 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
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -652,10 +652,10 @@ function captionStyle(theme, position) {
|
|
|
652
652
|
};
|
|
653
653
|
}
|
|
654
654
|
function metaStyle(theme) {
|
|
655
|
-
return { color: theme.accent, fontSize: 12, fontWeight: 600, letterSpacing: "0.04em", textTransform: "uppercase", marginBottom: 6 };
|
|
655
|
+
return { color: theme.accentText ?? theme.accent, fontSize: 12, fontWeight: 600, letterSpacing: "0.04em", textTransform: "uppercase", marginBottom: 6 };
|
|
656
656
|
}
|
|
657
657
|
function noteStyle(theme) {
|
|
658
|
-
return { color: theme.accent, fontSize: 14, marginTop: 6 };
|
|
658
|
+
return { color: theme.accentText ?? theme.accent, fontSize: 14, marginTop: 6 };
|
|
659
659
|
}
|
|
660
660
|
function rowStyle(theme) {
|
|
661
661
|
return { display: "flex", flexWrap: "wrap", alignItems: "center", gap: 8, marginTop: 10, color: theme.muted, fontSize: 13 };
|
|
@@ -869,7 +869,7 @@ function groupButtonStyle(theme) {
|
|
|
869
869
|
borderTop: `1px solid ${theme.divider}`,
|
|
870
870
|
marginTop: 8,
|
|
871
871
|
padding: "12px 0",
|
|
872
|
-
color: theme.accent,
|
|
872
|
+
color: theme.accentText ?? theme.accent,
|
|
873
873
|
fontFamily: fontStack(theme.fontFamily),
|
|
874
874
|
fontSize: 16,
|
|
875
875
|
fontWeight: 700,
|