@dloizides/ui-tour 1.2.2 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/README.md +7 -3
- package/dist/expo/index.d.mts +2 -0
- package/dist/expo/index.d.ts +2 -0
- package/dist/expo/index.js +2 -1
- package/dist/expo/index.js.map +1 -1
- package/dist/expo/index.mjs +2 -1
- package/dist/expo/index.mjs.map +1 -1
- package/dist/index.d.mts +14 -1
- package/dist/index.d.ts +14 -1
- package/dist/index.js +83 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +81 -7
- package/dist/index.mjs.map +1 -1
- package/dist/testing/index.js +2 -1
- package/dist/testing/index.js.map +1 -1
- package/dist/testing/index.mjs +3 -2
- package/dist/testing/index.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.3.0
|
|
4
|
+
|
|
5
|
+
- `StepAction.Upload`: in Show and Auto modes the step fetches its `value` URL (`{var}` filled) and lands the file in the target's file input, then fires `input` and `change`. `validateTours` requires a URL value.
|
|
6
|
+
- Recipe tours: `recipe: true` with `allowWrites: true` may click a control named exactly Save, Save changes, Save draft, Submit, Send or Publish (when the provider passes `allowWrites`); a name holding delete, remove, reset, pay, approve, reject or refund is refused; Delete, Reset, Reject, Approve and Pay stay blocked. `allowWrites` without `recipe` is a `validateTours` / `expectValidTours` error.
|
|
7
|
+
- Publish is now a write control: no tour except a recipe tour clicks it.
|
|
8
|
+
- New exports: `WritePolicy`, `isForbiddenWrite`, `writePolicyOf`; `isForbiddenClick` keeps its signature.
|
|
9
|
+
|
|
10
|
+
## 1.2.3
|
|
11
|
+
|
|
12
|
+
- `toTourTheme` dark accent is the first of primary 300, 400, 500, base that exists, then the text colour. Fixes kefi dark (toUiTheme primary has only 100/500/700) showing a cream Next button and ring instead of coral.
|
|
13
|
+
|
|
3
14
|
## 1.2.2
|
|
4
15
|
|
|
5
16
|
- `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.
|
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@ In-app guided tours for React Native Web apps. Three modes:
|
|
|
6
6
|
- **Show me**: a themed cursor moves to the target and clicks or types by itself, then waits for Next.
|
|
7
7
|
- **Auto**: like Show me, and advances on its own every 2 s; Space pauses.
|
|
8
8
|
|
|
9
|
-
Write controls (Save, Submit, Approve, Reject, Delete, Reset, Pay, Send) are never clicked. Only a tour flagged `allowSave`, in an app that passes `allowWrites`, may press a plain "Save".
|
|
9
|
+
Write controls (Save, Submit, Approve, Reject, Delete, Reset, Pay, Send, Publish) are never clicked. Only a tour flagged `allowSave`, in an app that passes `allowWrites`, may press a plain "Save"; only a `recipe` tour with `allowWrites` may press Save, Submit, Send and Publish.
|
|
10
10
|
|
|
11
11
|
Web only. On native (`Platform.OS !== 'web'`) the provider renders its children and the tour API does nothing.
|
|
12
12
|
|
|
@@ -113,14 +113,18 @@ import { TOURS } from '../tours';
|
|
|
113
113
|
|---|---|
|
|
114
114
|
| `target` | A testID (`open-payees`) or `{ role, name, nth?, exact?, within? }` |
|
|
115
115
|
| `text` | Translation key of the caption text; `{name}` placeholders come from `vars` |
|
|
116
|
-
| `action` | `StepAction.Click`, `Type` (needs `value`) or `None` |
|
|
116
|
+
| `action` | `StepAction.Click`, `Type` (needs `value`), `Upload` (needs a URL `value`, `{var}` filled) or `None` |
|
|
117
117
|
| `route?` | Navigates there first; `{name}` placeholders come from `vars` (`/t/{tenantSlug}/register`) |
|
|
118
118
|
| `optional?` | Skipped when the target is absent |
|
|
119
119
|
| `wait?` | Extra wait in ms before the step |
|
|
120
120
|
|
|
121
121
|
### Forbidden actions
|
|
122
122
|
|
|
123
|
-
A click step whose target name starts with Save, Submit, Approve, Reject, Delete, Reset, Pay or
|
|
123
|
+
A click step whose target name starts with Save, Submit, Approve, Reject, Delete, Reset, Pay, Send or Publish is never performed. A plain "Save" is allowed only with `allowSave: true` on the tour and `allowWrites` on the provider. A tour with `recipe: true` and `allowWrites: true` (it builds data from scratch on a throwaway tenant) may also press a control named exactly Save, Save changes, Save draft, Submit, Send or Publish when the provider passes `allowWrites` (a name such as "Save and delete" is refused); Delete, Reset, Reject, Approve and Pay stay blocked. `allowWrites` on a tour without `recipe` is a validation error.
|
|
124
|
+
|
|
125
|
+
### Upload steps
|
|
126
|
+
|
|
127
|
+
In Show and Auto modes an `Upload` step fetches its `value` URL and puts the file in the target's file input (the target itself, one inside it, or one beside it), then fires `input` and `change` so the app's own upload flow runs. A failed fetch or no file input marks the step unavailable. In Guide mode the user picks the file and presses Next. Switches, checkboxes and radios are settings, not writes.
|
|
124
128
|
|
|
125
129
|
### How to test
|
|
126
130
|
|
package/dist/expo/index.d.mts
CHANGED
package/dist/expo/index.d.ts
CHANGED
package/dist/expo/index.js
CHANGED
|
@@ -123,7 +123,8 @@ function toTourTheme(theme, dark) {
|
|
|
123
123
|
const isDark = dark ?? (theme.mode === DARK_MODE || hasDarkBackground(theme.colors.background));
|
|
124
124
|
const { colors, palette } = theme;
|
|
125
125
|
const lightAccent = palette.primary["700"] ?? palette.primary["600"] ?? palette.primary["500"] ?? colors.text;
|
|
126
|
-
const
|
|
126
|
+
const darkAccent = palette.primary["300"] ?? palette.primary["400"] ?? palette.primary["500"] ?? palette.primary.base ?? colors.text;
|
|
127
|
+
const accent = isDark ? darkAccent : lightAccent;
|
|
127
128
|
const shade = darkerOf(colors.text, colors.background, isDark ? colors.background : colors.text);
|
|
128
129
|
const surface = colors.surfaceElevated ?? colors.surface;
|
|
129
130
|
return {
|
package/dist/expo/index.js.map
CHANGED
|
@@ -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,MAAA,CAAO,IAAI,CAAA,GAAI,WAAA,CAAY,SAAA,EAAW,CAAA,EAAG,MAAM,CAAA,CAAA,EAAI,IAAI,CAAA,CAAA,EAAIA,wBAAA,CAAkB,IAAI,CAAC,CAAA;AAAA,EACpF,CAAC,CAAA;AACD,EAAA,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AAU,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';\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"]}
|
|
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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A,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,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';\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; '400'?: string; '500'?: string; '600'?: string; '700'?: string; base?: 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 darkAccent = palette.primary['300'] ?? palette.primary['400'] ?? palette.primary['500'] ?? palette.primary.base ?? colors.text;\n const accent = isDark ? darkAccent : 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/dist/expo/index.mjs
CHANGED
|
@@ -121,7 +121,8 @@ function toTourTheme(theme, dark) {
|
|
|
121
121
|
const isDark = dark ?? (theme.mode === DARK_MODE || hasDarkBackground(theme.colors.background));
|
|
122
122
|
const { colors, palette } = theme;
|
|
123
123
|
const lightAccent = palette.primary["700"] ?? palette.primary["600"] ?? palette.primary["500"] ?? colors.text;
|
|
124
|
-
const
|
|
124
|
+
const darkAccent = palette.primary["300"] ?? palette.primary["400"] ?? palette.primary["500"] ?? palette.primary.base ?? colors.text;
|
|
125
|
+
const accent = isDark ? darkAccent : lightAccent;
|
|
125
126
|
const shade = darkerOf(colors.text, colors.background, isDark ? colors.background : colors.text);
|
|
126
127
|
const surface = colors.surfaceElevated ?? colors.surface;
|
|
127
128
|
return {
|
package/dist/expo/index.mjs.map
CHANGED
|
@@ -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,0CAA0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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"]}
|
|
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,CAA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AAO,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; '400'?: string; '500'?: string; '600'?: string; '700'?: string; base?: 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 darkAccent = palette.primary['300'] ?? palette.primary['400'] ?? palette.primary['500'] ?? palette.primary.base ?? colors.text;\n const accent = isDark ? darkAccent : 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/dist/index.d.mts
CHANGED
|
@@ -34,6 +34,7 @@ declare function formatLabel(template: string, ...params: Array<string | number>
|
|
|
34
34
|
declare enum StepAction {
|
|
35
35
|
Click = "click",
|
|
36
36
|
Type = "type",
|
|
37
|
+
Upload = "upload",
|
|
37
38
|
None = "none"
|
|
38
39
|
}
|
|
39
40
|
|
|
@@ -88,6 +89,8 @@ interface Tour {
|
|
|
88
89
|
category: string;
|
|
89
90
|
persona?: string;
|
|
90
91
|
allowSave?: boolean;
|
|
92
|
+
recipe?: boolean;
|
|
93
|
+
allowWrites?: boolean;
|
|
91
94
|
steps: TourStep[];
|
|
92
95
|
}
|
|
93
96
|
interface TourEvent {
|
|
@@ -204,12 +207,22 @@ declare function validateTours(tours: readonly Tour[]): TourValidation;
|
|
|
204
207
|
/** Finds the first visible element for a step target: a testID string or a role and accessible name. */
|
|
205
208
|
declare function findTarget(target: StepTarget, vars?: TourVars): Element | null;
|
|
206
209
|
|
|
210
|
+
declare enum WritePolicy {
|
|
211
|
+
None = "none",
|
|
212
|
+
PlainSave = "plainSave",
|
|
213
|
+
RecipeWrites = "recipeWrites"
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/** True when a control's accessible name marks it as a write action the tour may not click under `policy`. */
|
|
217
|
+
declare function isForbiddenWrite(name: string, policy: WritePolicy): boolean;
|
|
207
218
|
/** True when a control's accessible name marks it as a write action the tour must never click. */
|
|
208
219
|
declare function isForbiddenClick(name: string, allowSave: boolean): boolean;
|
|
220
|
+
/** The write policy of a tour; `appAllowsWrites` is the provider's `allowWrites`, without it nothing is written. */
|
|
221
|
+
declare function writePolicyOf(tour: Tour, appAllowsWrites: boolean): WritePolicy;
|
|
209
222
|
|
|
210
223
|
declare const DEFAULT_TIMING: TourTiming;
|
|
211
224
|
|
|
212
225
|
/** Font stack that always ends in a generic family, so a missing web font falls back to sans-serif. */
|
|
213
226
|
declare function fontStack(family: string | null | undefined): string;
|
|
214
227
|
|
|
215
|
-
export { type ActiveTour, DEFAULT_TIMING, FirstRunOffer, type FirstRunOfferProps, type Point, type RoleTarget, StepAction, StepPhase, type StepTarget, type StepView, type TargetRect, TargetRole, type Tour, type TourContextValue, type TourEvent, TourEventType, type TourLabels, TourMode, TourPicker, TourProvider, type TourProviderProps, type TourStep, type TourTheme, type TourTiming, type TourUser, type TourValidation, type TourVars, defaultTourLabels, findTarget, fontStack, formatLabel, isForbiddenClick, useTour, validateTours };
|
|
228
|
+
export { type ActiveTour, DEFAULT_TIMING, FirstRunOffer, type FirstRunOfferProps, type Point, type RoleTarget, StepAction, StepPhase, type StepTarget, type StepView, type TargetRect, TargetRole, type Tour, type TourContextValue, type TourEvent, TourEventType, type TourLabels, TourMode, TourPicker, TourProvider, type TourProviderProps, type TourStep, type TourTheme, type TourTiming, type TourUser, type TourValidation, type TourVars, WritePolicy, defaultTourLabels, findTarget, fontStack, formatLabel, isForbiddenClick, isForbiddenWrite, useTour, validateTours, writePolicyOf };
|
package/dist/index.d.ts
CHANGED
|
@@ -34,6 +34,7 @@ declare function formatLabel(template: string, ...params: Array<string | number>
|
|
|
34
34
|
declare enum StepAction {
|
|
35
35
|
Click = "click",
|
|
36
36
|
Type = "type",
|
|
37
|
+
Upload = "upload",
|
|
37
38
|
None = "none"
|
|
38
39
|
}
|
|
39
40
|
|
|
@@ -88,6 +89,8 @@ interface Tour {
|
|
|
88
89
|
category: string;
|
|
89
90
|
persona?: string;
|
|
90
91
|
allowSave?: boolean;
|
|
92
|
+
recipe?: boolean;
|
|
93
|
+
allowWrites?: boolean;
|
|
91
94
|
steps: TourStep[];
|
|
92
95
|
}
|
|
93
96
|
interface TourEvent {
|
|
@@ -204,12 +207,22 @@ declare function validateTours(tours: readonly Tour[]): TourValidation;
|
|
|
204
207
|
/** Finds the first visible element for a step target: a testID string or a role and accessible name. */
|
|
205
208
|
declare function findTarget(target: StepTarget, vars?: TourVars): Element | null;
|
|
206
209
|
|
|
210
|
+
declare enum WritePolicy {
|
|
211
|
+
None = "none",
|
|
212
|
+
PlainSave = "plainSave",
|
|
213
|
+
RecipeWrites = "recipeWrites"
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/** True when a control's accessible name marks it as a write action the tour may not click under `policy`. */
|
|
217
|
+
declare function isForbiddenWrite(name: string, policy: WritePolicy): boolean;
|
|
207
218
|
/** True when a control's accessible name marks it as a write action the tour must never click. */
|
|
208
219
|
declare function isForbiddenClick(name: string, allowSave: boolean): boolean;
|
|
220
|
+
/** The write policy of a tour; `appAllowsWrites` is the provider's `allowWrites`, without it nothing is written. */
|
|
221
|
+
declare function writePolicyOf(tour: Tour, appAllowsWrites: boolean): WritePolicy;
|
|
209
222
|
|
|
210
223
|
declare const DEFAULT_TIMING: TourTiming;
|
|
211
224
|
|
|
212
225
|
/** Font stack that always ends in a generic family, so a missing web font falls back to sans-serif. */
|
|
213
226
|
declare function fontStack(family: string | null | undefined): string;
|
|
214
227
|
|
|
215
|
-
export { type ActiveTour, DEFAULT_TIMING, FirstRunOffer, type FirstRunOfferProps, type Point, type RoleTarget, StepAction, StepPhase, type StepTarget, type StepView, type TargetRect, TargetRole, type Tour, type TourContextValue, type TourEvent, TourEventType, type TourLabels, TourMode, TourPicker, TourProvider, type TourProviderProps, type TourStep, type TourTheme, type TourTiming, type TourUser, type TourValidation, type TourVars, defaultTourLabels, findTarget, fontStack, formatLabel, isForbiddenClick, useTour, validateTours };
|
|
228
|
+
export { type ActiveTour, DEFAULT_TIMING, FirstRunOffer, type FirstRunOfferProps, type Point, type RoleTarget, StepAction, StepPhase, type StepTarget, type StepView, type TargetRect, TargetRole, type Tour, type TourContextValue, type TourEvent, TourEventType, type TourLabels, TourMode, TourPicker, TourProvider, type TourProviderProps, type TourStep, type TourTheme, type TourTiming, type TourUser, type TourValidation, type TourVars, WritePolicy, defaultTourLabels, findTarget, fontStack, formatLabel, isForbiddenClick, isForbiddenWrite, useTour, validateTours, writePolicyOf };
|
package/dist/index.js
CHANGED
|
@@ -308,6 +308,7 @@ function inertTour(tours, theme, labels) {
|
|
|
308
308
|
var StepAction = /* @__PURE__ */ ((StepAction2) => {
|
|
309
309
|
StepAction2["Click"] = "click";
|
|
310
310
|
StepAction2["Type"] = "type";
|
|
311
|
+
StepAction2["Upload"] = "upload";
|
|
311
312
|
StepAction2["None"] = "none";
|
|
312
313
|
return StepAction2;
|
|
313
314
|
})(StepAction || {});
|
|
@@ -380,23 +381,92 @@ function useRectTracking(phase, refreshRect) {
|
|
|
380
381
|
}, [phase, refreshRect]);
|
|
381
382
|
}
|
|
382
383
|
|
|
384
|
+
// src/enums/WritePolicy.ts
|
|
385
|
+
var WritePolicy = /* @__PURE__ */ ((WritePolicy2) => {
|
|
386
|
+
WritePolicy2["None"] = "none";
|
|
387
|
+
WritePolicy2["PlainSave"] = "plainSave";
|
|
388
|
+
WritePolicy2["RecipeWrites"] = "recipeWrites";
|
|
389
|
+
return WritePolicy2;
|
|
390
|
+
})(WritePolicy || {});
|
|
391
|
+
|
|
383
392
|
// src/dom/forbidden.ts
|
|
384
|
-
var WRITE_CONTROL = /^(save|submit|approve|reject|delete|reset|pay|send)\b/i;
|
|
393
|
+
var WRITE_CONTROL = /^(save|submit|approve|reject|delete|reset|pay|send|publish)\b/i;
|
|
385
394
|
var PLAIN_SAVE = /^save$/i;
|
|
386
|
-
|
|
395
|
+
var RECIPE_WRITE = /^(save|submit|send|publish)( changes| draft)?$/i;
|
|
396
|
+
var DENIED_VERB = /\b(delete|remove|reset|pay|approve|reject|refund)\b/i;
|
|
397
|
+
function isForbiddenWrite(name, policy) {
|
|
387
398
|
const clean = normalise(name);
|
|
388
399
|
if (!WRITE_CONTROL.test(clean)) return false;
|
|
389
|
-
return
|
|
400
|
+
if (policy === "recipeWrites" /* RecipeWrites */) return DENIED_VERB.test(clean) || !RECIPE_WRITE.test(clean);
|
|
401
|
+
return !(policy === "plainSave" /* PlainSave */ && PLAIN_SAVE.test(clean));
|
|
402
|
+
}
|
|
403
|
+
function isForbiddenClick(name, allowSave) {
|
|
404
|
+
return isForbiddenWrite(name, allowSave ? "plainSave" /* PlainSave */ : "none" /* None */);
|
|
405
|
+
}
|
|
406
|
+
function writePolicyOf(tour, appAllowsWrites) {
|
|
407
|
+
if (!appAllowsWrites) return "none" /* None */;
|
|
408
|
+
if (tour.recipe === true && tour.allowWrites === true) return "recipeWrites" /* RecipeWrites */;
|
|
409
|
+
return tour.allowSave === true ? "plainSave" /* PlainSave */ : "none" /* None */;
|
|
390
410
|
}
|
|
391
411
|
|
|
412
|
+
// src/dom/upload.ts
|
|
413
|
+
var FILE_INPUT = 'input[type="file"]';
|
|
414
|
+
var FALLBACK_NAME = "upload";
|
|
415
|
+
function fileInputOf(node) {
|
|
416
|
+
if (node.matches(FILE_INPUT)) return node;
|
|
417
|
+
return node.querySelector(FILE_INPUT) ?? node.parentElement?.querySelector(FILE_INPUT) ?? null;
|
|
418
|
+
}
|
|
419
|
+
function fileNameOf(url) {
|
|
420
|
+
const path = url.split(/[?#]/)[0] ?? "";
|
|
421
|
+
const last = path.split("/").pop() ?? "";
|
|
422
|
+
return last !== "" ? decodeURIComponent(last) : FALLBACK_NAME;
|
|
423
|
+
}
|
|
424
|
+
function fileListOf(file) {
|
|
425
|
+
if (typeof DataTransfer === "function") {
|
|
426
|
+
const transfer = new DataTransfer();
|
|
427
|
+
transfer.items.add(file);
|
|
428
|
+
return transfer.files;
|
|
429
|
+
}
|
|
430
|
+
const list = { 0: file, length: 1, item: (index) => index === 0 ? file : null };
|
|
431
|
+
return list;
|
|
432
|
+
}
|
|
433
|
+
async function fetchBlob(url, fetcher) {
|
|
434
|
+
try {
|
|
435
|
+
const response = await fetcher(url);
|
|
436
|
+
return response.ok ? await response.blob() : null;
|
|
437
|
+
} catch {
|
|
438
|
+
return null;
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
async function uploadFromUrl(input, url, fetcher) {
|
|
442
|
+
const blob = await fetchBlob(url, fetcher);
|
|
443
|
+
if (blob === null) return false;
|
|
444
|
+
const file = new File([blob], fileNameOf(url), { type: blob.type });
|
|
445
|
+
Object.defineProperty(input, "files", { value: fileListOf(file), configurable: true });
|
|
446
|
+
input.dispatchEvent(new Event("input", { bubbles: true }));
|
|
447
|
+
input.dispatchEvent(new Event("change", { bubbles: true }));
|
|
448
|
+
return true;
|
|
449
|
+
}
|
|
450
|
+
var browserFetch = (url) => fetch(url);
|
|
451
|
+
|
|
392
452
|
// src/engine/runStep.ts
|
|
393
453
|
var CANCELLED = { kind: "cancelled" /* Cancelled */ };
|
|
454
|
+
var MISSING = { kind: "missing" /* Missing */ };
|
|
394
455
|
function ready(node, clicked) {
|
|
395
456
|
return { kind: "ready" /* Ready */, node, clicked };
|
|
396
457
|
}
|
|
458
|
+
async function upload(context, node) {
|
|
459
|
+
const input = fileInputOf(node);
|
|
460
|
+
if (input === null) return MISSING;
|
|
461
|
+
await context.moveCursor(centreOf(node));
|
|
462
|
+
if (context.isCancelled()) return CANCELLED;
|
|
463
|
+
const done = await uploadFromUrl(input, substitute(context.step.value ?? "", context.vars), context.fetchFile);
|
|
464
|
+
return done ? ready(node, false) : MISSING;
|
|
465
|
+
}
|
|
397
466
|
async function perform(context, node) {
|
|
398
467
|
const { step, mode } = context;
|
|
399
468
|
const acts = mode !== "guide" /* Guide */;
|
|
469
|
+
if (step.action === "upload" /* Upload */) return acts ? upload(context, node) : ready(node, false);
|
|
400
470
|
if (step.action === "type" /* Type */) {
|
|
401
471
|
if (acts) await context.moveCursor(centreOf(node));
|
|
402
472
|
await typeValue(node, substitute(step.value ?? "", context.vars), context.timing.typeMs);
|
|
@@ -404,7 +474,7 @@ async function perform(context, node) {
|
|
|
404
474
|
}
|
|
405
475
|
if (step.action !== "click" /* Click */ || !acts) return ready(node, false);
|
|
406
476
|
const name = accessibleName(node);
|
|
407
|
-
if (!isToggleControl(node) &&
|
|
477
|
+
if (!isToggleControl(node) && isForbiddenWrite(name, context.writePolicy)) return { kind: "refused" /* Refused */, node, name };
|
|
408
478
|
const point = centreOf(node);
|
|
409
479
|
await context.moveCursor(point);
|
|
410
480
|
if (context.isCancelled()) return CANCELLED;
|
|
@@ -446,13 +516,15 @@ function useStepRunner(options) {
|
|
|
446
516
|
}
|
|
447
517
|
let cancelled = false;
|
|
448
518
|
setView(LOADING_VIEW);
|
|
449
|
-
const
|
|
519
|
+
const tour = tourOf(latest.tours, active);
|
|
520
|
+
const writePolicy = tour === null ? "none" /* None */ : writePolicyOf(tour, latest.allowWrites);
|
|
450
521
|
void runStep({
|
|
451
522
|
step,
|
|
452
523
|
mode: active.mode,
|
|
453
524
|
vars: latest.vars,
|
|
454
525
|
timing: latest.timing,
|
|
455
|
-
|
|
526
|
+
writePolicy,
|
|
527
|
+
fetchFile: browserFetch,
|
|
456
528
|
navigate: latest.navigate,
|
|
457
529
|
getPathname: latest.getPathname,
|
|
458
530
|
isCancelled: () => cancelled,
|
|
@@ -1006,6 +1078,7 @@ function stepErrors(tourId, index, step) {
|
|
|
1006
1078
|
if (!hasTarget(step.target)) errors.push(`${where}: missing target`);
|
|
1007
1079
|
if (typeof step.text !== "string" || step.text.trim() === "") errors.push(`${where}: missing text`);
|
|
1008
1080
|
if (step.action === "type" /* Type */ && (step.value ?? "") === "") errors.push(`${where}: type step needs a value`);
|
|
1081
|
+
if (step.action === "upload" /* Upload */ && (step.value ?? "").trim() === "") errors.push(`${where}: upload step needs a url value`);
|
|
1009
1082
|
return errors;
|
|
1010
1083
|
}
|
|
1011
1084
|
function validateTours(tours) {
|
|
@@ -1017,6 +1090,7 @@ function validateTours(tours) {
|
|
|
1017
1090
|
seen.add(id);
|
|
1018
1091
|
const steps = Array.isArray(tour.steps) ? tour.steps : [];
|
|
1019
1092
|
if (steps.length === 0) errors.push(`tour ${id}: has no steps`);
|
|
1093
|
+
if (tour.allowWrites === true && tour.recipe !== true) errors.push(`tour ${id}: allowWrites needs recipe: true`);
|
|
1020
1094
|
steps.forEach((step, stepIndex) => errors.push(...stepErrors(id, stepIndex, step)));
|
|
1021
1095
|
});
|
|
1022
1096
|
return { valid: errors.length === 0, errors };
|
|
@@ -1031,12 +1105,15 @@ exports.TourEventType = TourEventType;
|
|
|
1031
1105
|
exports.TourMode = TourMode;
|
|
1032
1106
|
exports.TourPicker = TourPicker;
|
|
1033
1107
|
exports.TourProvider = TourProvider;
|
|
1108
|
+
exports.WritePolicy = WritePolicy;
|
|
1034
1109
|
exports.defaultTourLabels = defaultTourLabels;
|
|
1035
1110
|
exports.findTarget = findTarget;
|
|
1036
1111
|
exports.fontStack = fontStack;
|
|
1037
1112
|
exports.formatLabel = formatLabel;
|
|
1038
1113
|
exports.isForbiddenClick = isForbiddenClick;
|
|
1114
|
+
exports.isForbiddenWrite = isForbiddenWrite;
|
|
1039
1115
|
exports.useTour = useTour;
|
|
1040
1116
|
exports.validateTours = validateTours;
|
|
1117
|
+
exports.writePolicyOf = writePolicyOf;
|
|
1041
1118
|
//# sourceMappingURL=index.js.map
|
|
1042
1119
|
//# sourceMappingURL=index.js.map
|