@dloizides/ui-tour 1.2.1 → 1.2.2

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,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.2.2
4
+
5
+ - `toTourTheme` treats a theme as dark when its `mode` is `dark` or its background luminance is below 0.2 (design-tokens `toUiTheme` sets no `mode`), and the scrim dims with the darker of text and background. Fixes the light-grey dimmed page behind a tour in kefi dark.
6
+
3
7
  ## 1.2.1
4
8
 
5
9
  - `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).
@@ -108,12 +108,23 @@ function pickAccentText(shades, captionSurface, text, isDark, fallback) {
108
108
  var DARK_MODE = "dark";
109
109
  var TOUR_RADIUS = 12;
110
110
  var SCRIM_STRENGTH = "62%";
111
+ var DARK_BACKGROUND_LUMINANCE = 0.2;
112
+ function hasDarkBackground(background) {
113
+ const value = luminance(background);
114
+ return value !== void 0 && value < DARK_BACKGROUND_LUMINANCE;
115
+ }
116
+ function darkerOf(text, background, fallback) {
117
+ const textLuminance = luminance(text);
118
+ const backgroundLuminance = luminance(background);
119
+ if (textLuminance === void 0 || backgroundLuminance === void 0) return fallback;
120
+ return backgroundLuminance < textLuminance ? background : text;
121
+ }
111
122
  function toTourTheme(theme, dark) {
112
- const isDark = dark ?? theme.mode === DARK_MODE;
123
+ const isDark = dark ?? (theme.mode === DARK_MODE || hasDarkBackground(theme.colors.background));
113
124
  const { colors, palette } = theme;
114
125
  const lightAccent = palette.primary["700"] ?? palette.primary["600"] ?? palette.primary["500"] ?? colors.text;
115
126
  const accent = isDark ? palette.primary["300"] ?? colors.text : lightAccent;
116
- const shade = isDark ? colors.background : colors.text;
127
+ const shade = darkerOf(colors.text, colors.background, isDark ? colors.background : colors.text);
117
128
  const surface = colors.surfaceElevated ?? colors.surface;
118
129
  return {
119
130
  accent,
@@ -1 +1 @@
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,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,M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B,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,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","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"]}
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,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,OAAO,MAAA;AACT;AAGO,SAAS,aAAA,CAAc,OAAwB,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AAA,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';\nimport { luminance } from './contrast';\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%';\nconst DARK_BACKGROUND_LUMINANCE = 0.2;\n\nfunction hasDarkBackground(background: string): boolean {\n const value = luminance(background);\n return value !== undefined && value < DARK_BACKGROUND_LUMINANCE;\n}\n\nfunction darkerOf(text: string, background: string, fallback: string): string {\n const textLuminance = luminance(text);\n const backgroundLuminance = luminance(background);\n if (textLuminance === undefined || backgroundLuminance === undefined) return fallback;\n return backgroundLuminance < textLuminance ? background : text;\n}\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 || hasDarkBackground(theme.colors.background));\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 = darkerOf(colors.text, colors.background, 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"]}
@@ -106,12 +106,23 @@ function pickAccentText(shades, captionSurface, text, isDark, fallback) {
106
106
  var DARK_MODE = "dark";
107
107
  var TOUR_RADIUS = 12;
108
108
  var SCRIM_STRENGTH = "62%";
109
+ var DARK_BACKGROUND_LUMINANCE = 0.2;
110
+ function hasDarkBackground(background) {
111
+ const value = luminance(background);
112
+ return value !== void 0 && value < DARK_BACKGROUND_LUMINANCE;
113
+ }
114
+ function darkerOf(text, background, fallback) {
115
+ const textLuminance = luminance(text);
116
+ const backgroundLuminance = luminance(background);
117
+ if (textLuminance === void 0 || backgroundLuminance === void 0) return fallback;
118
+ return backgroundLuminance < textLuminance ? background : text;
119
+ }
109
120
  function toTourTheme(theme, dark) {
110
- const isDark = dark ?? theme.mode === DARK_MODE;
121
+ const isDark = dark ?? (theme.mode === DARK_MODE || hasDarkBackground(theme.colors.background));
111
122
  const { colors, palette } = theme;
112
123
  const lightAccent = palette.primary["700"] ?? palette.primary["600"] ?? palette.primary["500"] ?? colors.text;
113
124
  const accent = isDark ? palette.primary["300"] ?? colors.text : lightAccent;
114
- const shade = isDark ? colors.background : colors.text;
125
+ const shade = darkerOf(colors.text, colors.background, isDark ? colors.background : colors.text);
115
126
  const surface = colors.surfaceElevated ?? colors.surface;
116
127
  return {
117
128
  accent,
@@ -1 +1 @@
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,EAA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AU,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","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"]}
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":";;;;;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AM,WAAA,EAAa,KAAA,CAAM,WAAA,EAAa,OAAA,EAC/I,QAAA,EAAA;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","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';\nimport { luminance } from './contrast';\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%';\nconst DARK_BACKGROUND_LUMINANCE = 0.2;\n\nfunction hasDarkBackground(background: string): boolean {\n const value = luminance(background);\n return value !== undefined && value < DARK_BACKGROUND_LUMINANCE;\n}\n\nfunction darkerOf(text: string, background: string, fallback: string): string {\n const textLuminance = luminance(text);\n const backgroundLuminance = luminance(background);\n if (textLuminance === undefined || backgroundLuminance === undefined) return fallback;\n return backgroundLuminance < textLuminance ? background : text;\n}\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 || hasDarkBackground(theme.colors.background));\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 = darkerOf(colors.text, colors.background, 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dloizides/ui-tour",
3
- "version": "1.2.1",
3
+ "version": "1.2.2",
4
4
  "description": "In-app guided tours for React Native Web apps: Guide me, Show me and Auto modes with a themed ring, caption, cursor, tour picker and first-run offer. Write controls are never clicked. Web only; renders nothing on native.",
5
5
  "keywords": [
6
6
  "react",