@pgy-eu/react-native-tour-guide 0.0.0-stage → 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (161) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +993 -2
  3. package/lib/commonjs/SpotlightOverlay.js +712 -0
  4. package/lib/commonjs/SpotlightOverlay.js.map +1 -0
  5. package/lib/commonjs/Tooltip.js +593 -0
  6. package/lib/commonjs/Tooltip.js.map +1 -0
  7. package/lib/commonjs/TourGuideContext.js +535 -0
  8. package/lib/commonjs/TourGuideContext.js.map +1 -0
  9. package/lib/commonjs/TourGuideOverlay.js +1173 -0
  10. package/lib/commonjs/TourGuideOverlay.js.map +1 -0
  11. package/lib/commonjs/TourTarget.js +80 -0
  12. package/lib/commonjs/TourTarget.js.map +1 -0
  13. package/lib/commonjs/accessibility.js +49 -0
  14. package/lib/commonjs/accessibility.js.map +1 -0
  15. package/lib/commonjs/dev.js +48 -0
  16. package/lib/commonjs/dev.js.map +1 -0
  17. package/lib/commonjs/events.js +56 -0
  18. package/lib/commonjs/events.js.map +1 -0
  19. package/lib/commonjs/index.js +169 -0
  20. package/lib/commonjs/index.js.map +1 -0
  21. package/lib/commonjs/package.json +1 -0
  22. package/lib/commonjs/shapes.js +158 -0
  23. package/lib/commonjs/shapes.js.map +1 -0
  24. package/lib/commonjs/storage.js +116 -0
  25. package/lib/commonjs/storage.js.map +1 -0
  26. package/lib/commonjs/themes.js +86 -0
  27. package/lib/commonjs/themes.js.map +1 -0
  28. package/lib/commonjs/types.js +6 -0
  29. package/lib/commonjs/types.js.map +1 -0
  30. package/lib/commonjs/useTourPersistence.js +135 -0
  31. package/lib/commonjs/useTourPersistence.js.map +1 -0
  32. package/lib/commonjs/useTourScroll.js +46 -0
  33. package/lib/commonjs/useTourScroll.js.map +1 -0
  34. package/lib/commonjs/utils.js +372 -0
  35. package/lib/commonjs/utils.js.map +1 -0
  36. package/lib/commonjs/validation.js +143 -0
  37. package/lib/commonjs/validation.js.map +1 -0
  38. package/lib/module/SpotlightOverlay.js +707 -0
  39. package/lib/module/SpotlightOverlay.js.map +1 -0
  40. package/lib/module/Tooltip.js +588 -0
  41. package/lib/module/Tooltip.js.map +1 -0
  42. package/lib/module/TourGuideContext.js +529 -0
  43. package/lib/module/TourGuideContext.js.map +1 -0
  44. package/lib/module/TourGuideOverlay.js +1167 -0
  45. package/lib/module/TourGuideOverlay.js.map +1 -0
  46. package/lib/module/TourTarget.js +74 -0
  47. package/lib/module/TourTarget.js.map +1 -0
  48. package/lib/module/accessibility.js +43 -0
  49. package/lib/module/accessibility.js.map +1 -0
  50. package/lib/module/dev.js +40 -0
  51. package/lib/module/dev.js.map +1 -0
  52. package/lib/module/events.js +51 -0
  53. package/lib/module/events.js.map +1 -0
  54. package/lib/module/index.js +25 -0
  55. package/lib/module/index.js.map +1 -0
  56. package/lib/module/package.json +1 -0
  57. package/lib/module/shapes.js +152 -0
  58. package/lib/module/shapes.js.map +1 -0
  59. package/lib/module/storage.js +111 -0
  60. package/lib/module/storage.js.map +1 -0
  61. package/lib/module/themes.js +81 -0
  62. package/lib/module/themes.js.map +1 -0
  63. package/lib/module/types.js +4 -0
  64. package/lib/module/types.js.map +1 -0
  65. package/lib/module/useTourPersistence.js +130 -0
  66. package/lib/module/useTourPersistence.js.map +1 -0
  67. package/lib/module/useTourScroll.js +41 -0
  68. package/lib/module/useTourScroll.js.map +1 -0
  69. package/lib/module/utils.js +361 -0
  70. package/lib/module/utils.js.map +1 -0
  71. package/lib/module/validation.js +138 -0
  72. package/lib/module/validation.js.map +1 -0
  73. package/lib/typescript/commonjs/package.json +1 -0
  74. package/lib/typescript/commonjs/src/SpotlightOverlay.d.ts +46 -0
  75. package/lib/typescript/commonjs/src/SpotlightOverlay.d.ts.map +1 -0
  76. package/lib/typescript/commonjs/src/Tooltip.d.ts +9 -0
  77. package/lib/typescript/commonjs/src/Tooltip.d.ts.map +1 -0
  78. package/lib/typescript/commonjs/src/TourGuideContext.d.ts +46 -0
  79. package/lib/typescript/commonjs/src/TourGuideContext.d.ts.map +1 -0
  80. package/lib/typescript/commonjs/src/TourGuideOverlay.d.ts +22 -0
  81. package/lib/typescript/commonjs/src/TourGuideOverlay.d.ts.map +1 -0
  82. package/lib/typescript/commonjs/src/TourTarget.d.ts +36 -0
  83. package/lib/typescript/commonjs/src/TourTarget.d.ts.map +1 -0
  84. package/lib/typescript/commonjs/src/accessibility.d.ts +22 -0
  85. package/lib/typescript/commonjs/src/accessibility.d.ts.map +1 -0
  86. package/lib/typescript/commonjs/src/dev.d.ts +22 -0
  87. package/lib/typescript/commonjs/src/dev.d.ts.map +1 -0
  88. package/lib/typescript/commonjs/src/events.d.ts +57 -0
  89. package/lib/typescript/commonjs/src/events.d.ts.map +1 -0
  90. package/lib/typescript/commonjs/src/index.d.ts +21 -0
  91. package/lib/typescript/commonjs/src/index.d.ts.map +1 -0
  92. package/lib/typescript/commonjs/src/shapes.d.ts +50 -0
  93. package/lib/typescript/commonjs/src/shapes.d.ts.map +1 -0
  94. package/lib/typescript/commonjs/src/storage.d.ts +15 -0
  95. package/lib/typescript/commonjs/src/storage.d.ts.map +1 -0
  96. package/lib/typescript/commonjs/src/themes.d.ts +10 -0
  97. package/lib/typescript/commonjs/src/themes.d.ts.map +1 -0
  98. package/lib/typescript/commonjs/src/types.d.ts +599 -0
  99. package/lib/typescript/commonjs/src/types.d.ts.map +1 -0
  100. package/lib/typescript/commonjs/src/useTourPersistence.d.ts +63 -0
  101. package/lib/typescript/commonjs/src/useTourPersistence.d.ts.map +1 -0
  102. package/lib/typescript/commonjs/src/useTourScroll.d.ts +36 -0
  103. package/lib/typescript/commonjs/src/useTourScroll.d.ts.map +1 -0
  104. package/lib/typescript/commonjs/src/utils.d.ts +97 -0
  105. package/lib/typescript/commonjs/src/utils.d.ts.map +1 -0
  106. package/lib/typescript/commonjs/src/validation.d.ts +11 -0
  107. package/lib/typescript/commonjs/src/validation.d.ts.map +1 -0
  108. package/lib/typescript/module/package.json +1 -0
  109. package/lib/typescript/module/src/SpotlightOverlay.d.ts +46 -0
  110. package/lib/typescript/module/src/SpotlightOverlay.d.ts.map +1 -0
  111. package/lib/typescript/module/src/Tooltip.d.ts +9 -0
  112. package/lib/typescript/module/src/Tooltip.d.ts.map +1 -0
  113. package/lib/typescript/module/src/TourGuideContext.d.ts +46 -0
  114. package/lib/typescript/module/src/TourGuideContext.d.ts.map +1 -0
  115. package/lib/typescript/module/src/TourGuideOverlay.d.ts +22 -0
  116. package/lib/typescript/module/src/TourGuideOverlay.d.ts.map +1 -0
  117. package/lib/typescript/module/src/TourTarget.d.ts +36 -0
  118. package/lib/typescript/module/src/TourTarget.d.ts.map +1 -0
  119. package/lib/typescript/module/src/accessibility.d.ts +22 -0
  120. package/lib/typescript/module/src/accessibility.d.ts.map +1 -0
  121. package/lib/typescript/module/src/dev.d.ts +22 -0
  122. package/lib/typescript/module/src/dev.d.ts.map +1 -0
  123. package/lib/typescript/module/src/events.d.ts +57 -0
  124. package/lib/typescript/module/src/events.d.ts.map +1 -0
  125. package/lib/typescript/module/src/index.d.ts +21 -0
  126. package/lib/typescript/module/src/index.d.ts.map +1 -0
  127. package/lib/typescript/module/src/shapes.d.ts +50 -0
  128. package/lib/typescript/module/src/shapes.d.ts.map +1 -0
  129. package/lib/typescript/module/src/storage.d.ts +15 -0
  130. package/lib/typescript/module/src/storage.d.ts.map +1 -0
  131. package/lib/typescript/module/src/themes.d.ts +10 -0
  132. package/lib/typescript/module/src/themes.d.ts.map +1 -0
  133. package/lib/typescript/module/src/types.d.ts +599 -0
  134. package/lib/typescript/module/src/types.d.ts.map +1 -0
  135. package/lib/typescript/module/src/useTourPersistence.d.ts +63 -0
  136. package/lib/typescript/module/src/useTourPersistence.d.ts.map +1 -0
  137. package/lib/typescript/module/src/useTourScroll.d.ts +36 -0
  138. package/lib/typescript/module/src/useTourScroll.d.ts.map +1 -0
  139. package/lib/typescript/module/src/utils.d.ts +97 -0
  140. package/lib/typescript/module/src/utils.d.ts.map +1 -0
  141. package/lib/typescript/module/src/validation.d.ts +11 -0
  142. package/lib/typescript/module/src/validation.d.ts.map +1 -0
  143. package/llms.txt +62 -0
  144. package/package.json +281 -4
  145. package/src/SpotlightOverlay.tsx +742 -0
  146. package/src/Tooltip.tsx +638 -0
  147. package/src/TourGuideContext.tsx +644 -0
  148. package/src/TourGuideOverlay.tsx +1382 -0
  149. package/src/TourTarget.tsx +74 -0
  150. package/src/accessibility.ts +60 -0
  151. package/src/dev.ts +39 -0
  152. package/src/events.ts +76 -0
  153. package/src/index.tsx +64 -0
  154. package/src/shapes.ts +184 -0
  155. package/src/storage.ts +114 -0
  156. package/src/themes.ts +83 -0
  157. package/src/types.ts +648 -0
  158. package/src/useTourPersistence.ts +147 -0
  159. package/src/useTourScroll.ts +60 -0
  160. package/src/utils.ts +401 -0
  161. package/src/validation.ts +248 -0
@@ -0,0 +1,707 @@
1
+ "use strict";
2
+
3
+ import React, { useRef, useEffect, useMemo, useState } from 'react';
4
+ import { StyleSheet, View, Animated, Pressable, Dimensions } from 'react-native';
5
+ import Svg, { Rect, Path, Defs, Mask } from 'react-native-svg';
6
+ import { computeShape, roundedRectPath } from "./shapes.js";
7
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
8
+ const AnimatedRect = Animated.createAnimatedComponent(Rect);
9
+ const DEFAULT_SPOTLIGHT_STYLES = {};
10
+
11
+ // Resolve optional dependencies once at module scope
12
+
13
+ let _resolvedBlur;
14
+ let _resolvedLinearGradient;
15
+ let _resolvedMaskedView;
16
+ const getBlurProvider = () => {
17
+ if (_resolvedBlur === undefined) {
18
+ _resolvedBlur = null;
19
+ try {
20
+ const community = require('@react-native-community/blur').BlurView;
21
+ if (community) _resolvedBlur = {
22
+ Component: community,
23
+ kind: 'community'
24
+ };
25
+ } catch {
26
+ // fall through to expo-blur
27
+ }
28
+ if (!_resolvedBlur) {
29
+ try {
30
+ // expo-blur ships inside Expo Go, so blur works there without a dev build.
31
+ const expo = require('expo-blur').BlurView;
32
+ if (expo) _resolvedBlur = {
33
+ Component: expo,
34
+ kind: 'expo'
35
+ };
36
+ } catch {
37
+ _resolvedBlur = null;
38
+ }
39
+ }
40
+ }
41
+ return _resolvedBlur;
42
+ };
43
+ const getLinearGradient = () => {
44
+ if (_resolvedLinearGradient === undefined) {
45
+ try {
46
+ _resolvedLinearGradient = require('react-native-linear-gradient').default;
47
+ } catch {
48
+ _resolvedLinearGradient = null;
49
+ }
50
+ }
51
+ return _resolvedLinearGradient;
52
+ };
53
+ const getMaskedView = () => {
54
+ if (_resolvedMaskedView === undefined) {
55
+ try {
56
+ _resolvedMaskedView = require('@react-native-masked-view/masked-view').default;
57
+ } catch {
58
+ _resolvedMaskedView = null;
59
+ }
60
+ }
61
+ return _resolvedMaskedView;
62
+ };
63
+ let maskIdCounter = 0;
64
+ /**
65
+ * Component that creates a spotlight effect with a dark overlay.
66
+ * Supports smooth animated transitions between targets.
67
+ * The spotlight automatically matches the target's shape via border radius.
68
+ * Optionally supports blur and gradient effects if dependencies are installed.
69
+ */
70
+ const SpotlightOverlay = ({
71
+ target,
72
+ padding = 0,
73
+ borderRadius: customBorderRadius,
74
+ styles = DEFAULT_SPOTLIGHT_STYLES,
75
+ screenWidth,
76
+ screenHeight,
77
+ animationDuration = 300,
78
+ onBackdropPress,
79
+ onSpotlightPress,
80
+ interactive = false,
81
+ motion = 'morph',
82
+ mountBlurLayer = false,
83
+ keptPaths
84
+ }) => {
85
+ const {
86
+ overlayOpacity = 0.6,
87
+ overlayColor = 'black',
88
+ blurAmount = 4,
89
+ enableBlur = false,
90
+ enableGradient = false,
91
+ gradientColors = ['rgba(217,217,217,0)', 'rgba(19,32,14,0.64)'],
92
+ enablePulse = false,
93
+ pulseColor = '#FFFFFF',
94
+ pulseWidth = 2,
95
+ pulseDuration = 1500,
96
+ pulseMinOpacity = 0.2,
97
+ pulseMaxOpacity = 0.8,
98
+ maskPath,
99
+ blurTarget
100
+ } = styles;
101
+
102
+ // Unique mask IDs per instance to avoid SVG conflicts
103
+ const maskIds = useRef({
104
+ inverse: `inverse-mask-${++maskIdCounter}`,
105
+ spotlight: `spotlight-mask-${maskIdCounter}`
106
+ }).current;
107
+
108
+ // Animated values for smooth spotlight transitions
109
+ const animX = useRef(new Animated.Value(0)).current;
110
+ const animY = useRef(new Animated.Value(0)).current;
111
+ const animWidth = useRef(new Animated.Value(0)).current;
112
+ const animHeight = useRef(new Animated.Value(0)).current;
113
+ const animRx = useRef(new Animated.Value(0)).current;
114
+ const animRy = useRef(new Animated.Value(0)).current;
115
+ const hasAnimated = useRef(false);
116
+ const pulseOpacity = useRef(new Animated.Value(0)).current;
117
+ // Whole-overlay opacity used by the 'fade' motion preset.
118
+ const overlayFade = useRef(new Animated.Value(1)).current;
119
+ // Blur layer cross-fade (used with mountBlurLayer): fading beats remounting.
120
+ const blurFade = useRef(new Animated.Value(enableBlur ? 1 : 0)).current;
121
+ useEffect(() => {
122
+ Animated.timing(blurFade, {
123
+ toValue: enableBlur ? 1 : 0,
124
+ duration: 220,
125
+ useNativeDriver: true
126
+ }).start();
127
+ }, [enableBlur, blurFade]);
128
+ // Pulse visibility combined with the fade, so the pulse ring dips with the
129
+ // backdrop instead of floating alone during a fade transition.
130
+ const pulseVisible = useRef(Animated.multiply(pulseOpacity, overlayFade)).current;
131
+ // Guards nested animation callbacks against applying a stale shape after a
132
+ // newer step's effect has already run.
133
+ const shapeEpoch = useRef(0);
134
+ // Direct handles to the two SVG paths so per-frame updates go through
135
+ // setNativeProps instead of setState — a React re-render per animation frame
136
+ // is invisible on a flagship and very visible on a low-end Android.
137
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
138
+ const overlayPathRef = useRef(null);
139
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
140
+ const pulsePathRef = useRef(null);
141
+
142
+ // Path data for per-corner border radius shapes
143
+ const [pathD, setPathD] = useState('');
144
+
145
+ // Compute shape result synchronously. A user-supplied maskPath overrides the
146
+ // automatic shape with an arbitrary SVG subpath (rendered as a static path;
147
+ // shape animation is skipped for custom paths).
148
+ const shapeResult = useMemo(() => {
149
+ if (!target) return null;
150
+ const auto = computeShape(target, padding, customBorderRadius);
151
+ if (maskPath) {
152
+ const autoBounds = auto.kind === 'rect' ? {
153
+ x: auto.x,
154
+ y: auto.y,
155
+ width: auto.width,
156
+ height: auto.height
157
+ } : auto.bounds;
158
+ try {
159
+ const d = maskPath({
160
+ target,
161
+ bounds: autoBounds,
162
+ screenWidth,
163
+ screenHeight
164
+ });
165
+ if (typeof d === 'string' && d.length > 0) {
166
+ return {
167
+ kind: 'path',
168
+ d,
169
+ bounds: autoBounds
170
+ };
171
+ }
172
+ } catch {
173
+ // A throwing maskPath falls back to the automatic shape.
174
+ }
175
+ }
176
+ return auto;
177
+ }, [target, padding, customBorderRadius, maskPath, screenWidth, screenHeight]);
178
+ const usePathRendering = shapeResult?.kind === 'path';
179
+
180
+ // Bounding box for press overlay positioning
181
+ const bounds = useMemo(() => {
182
+ if (!shapeResult) return null;
183
+ if (shapeResult.kind === 'rect') {
184
+ return {
185
+ x: shapeResult.x,
186
+ y: shapeResult.y,
187
+ width: shapeResult.width,
188
+ height: shapeResult.height
189
+ };
190
+ }
191
+ return shapeResult.bounds;
192
+ }, [shapeResult]);
193
+
194
+ // Interactive mode: four press bands around the hole catch backdrop touches
195
+ // while the hole itself stays open so taps reach the real element. The
196
+ // rounded corners leave sub-corner-radius slivers touch-transparent —
197
+ // visually part of the backdrop, acceptable.
198
+ const pressBands = useMemo(() => {
199
+ if (!interactive || !bounds) return null;
200
+ return [{
201
+ left: 0,
202
+ top: 0,
203
+ right: 0,
204
+ height: Math.max(0, bounds.y)
205
+ },
206
+ // above
207
+ {
208
+ left: 0,
209
+ top: bounds.y + bounds.height,
210
+ right: 0,
211
+ bottom: 0
212
+ },
213
+ // below
214
+ {
215
+ left: 0,
216
+ top: bounds.y,
217
+ width: Math.max(0, bounds.x),
218
+ height: bounds.height
219
+ },
220
+ // left
221
+ {
222
+ left: bounds.x + bounds.width,
223
+ top: bounds.y,
224
+ right: 0,
225
+ height: bounds.height
226
+ } // right
227
+ ];
228
+ }, [interactive, bounds]);
229
+
230
+ // The dark overlay is drawn as a single even-odd path: a full-screen rectangle
231
+ // with the spotlight punched out as a real hole. This replaces an SVG <Mask>,
232
+ // which on the new architecture (Fabric) leaves the cutout partially filled
233
+ // (a white film over the highlighted element) instead of fully transparent.
234
+ const [overlayPathD, setOverlayPathD] = useState('');
235
+ const animVals = useRef({
236
+ x: 0,
237
+ y: 0,
238
+ w: 0,
239
+ h: 0,
240
+ rx: 0
241
+ });
242
+
243
+ // The overlay Modal is statusBarTranslucent / edge-to-edge, so it spans the
244
+ // full PHYSICAL screen — but `screenWidth`/`screenHeight` come from
245
+ // Dimensions.get('window'), which on Android excludes the status/navigation
246
+ // bars. Sizing the dark backdrop to the window left an undimmed strip at the
247
+ // bottom (under the nav bar). Cover the full screen instead; over-drawing past
248
+ // the Modal bounds is harmless (clipped). iOS: window == screen, so no change.
249
+ const physicalScreen = Dimensions.get('screen');
250
+ const coverWidth = Math.max(screenWidth, physicalScreen.width);
251
+ const coverHeight = Math.max(screenHeight, physicalScreen.height);
252
+
253
+ // Kept spotlights from earlier steps are appended as extra holes — the
254
+ // evenodd fill rule punches every subpath out of the full-screen rect.
255
+ const keptSuffix = keptPaths && keptPaths.length > 0 ? ` ${keptPaths.join(' ')}` : '';
256
+ const buildOverlayPath = innerSubpath => `M0,0 H${coverWidth} V${coverHeight} H0 Z ${innerSubpath}${keptSuffix}`;
257
+
258
+ // Keep the overlay path in sync with the animated spotlight (rect shapes).
259
+ // Per-corner (path) shapes set the path directly in the animation effect.
260
+ useEffect(() => {
261
+ if (usePathRendering) return undefined;
262
+ // Five listeners (x/y/w/h/rx) fire once each per animation frame; building
263
+ // the path string five times per frame is wasted work. Coalesce to one
264
+ // update per frame via requestAnimationFrame; values are read at flush
265
+ // time, so the last-written values always win.
266
+ let frameScheduled = false;
267
+ const update = () => {
268
+ if (frameScheduled) return;
269
+ if (typeof requestAnimationFrame === 'function') {
270
+ frameScheduled = true;
271
+ requestAnimationFrame(() => {
272
+ frameScheduled = false;
273
+ flushUpdate();
274
+ });
275
+ } else {
276
+ flushUpdate();
277
+ }
278
+ };
279
+ const flushUpdate = () => {
280
+ const v = animVals.current;
281
+ const inner = roundedRectPath(v.x, v.y, v.w, v.h, v.rx);
282
+ // Fast path: write the path data straight to the native SVG nodes. Both
283
+ // the dark hole and the pulse ring are driven from the SAME string here,
284
+ // so they can never drift apart. Falls back to setState when
285
+ // setNativeProps is unavailable (tests, exotic hosts); the final frame is
286
+ // always committed to state when the animation ends.
287
+ const overlayNode = overlayPathRef.current;
288
+ if (overlayNode && typeof overlayNode.setNativeProps === 'function') {
289
+ overlayNode.setNativeProps({
290
+ d: buildOverlayPath(inner)
291
+ });
292
+ const pulseNode = pulsePathRef.current;
293
+ if (pulseNode && typeof pulseNode.setNativeProps === 'function') {
294
+ pulseNode.setNativeProps({
295
+ d: inner
296
+ });
297
+ }
298
+ } else {
299
+ setOverlayPathD(buildOverlayPath(inner));
300
+ setPathD(inner);
301
+ }
302
+ };
303
+ const ix = animX.addListener(({
304
+ value
305
+ }) => {
306
+ animVals.current.x = value;
307
+ update();
308
+ });
309
+ const iy = animY.addListener(({
310
+ value
311
+ }) => {
312
+ animVals.current.y = value;
313
+ update();
314
+ });
315
+ const iw = animWidth.addListener(({
316
+ value
317
+ }) => {
318
+ animVals.current.w = value;
319
+ update();
320
+ });
321
+ const ih = animHeight.addListener(({
322
+ value
323
+ }) => {
324
+ animVals.current.h = value;
325
+ update();
326
+ });
327
+ const ir = animRx.addListener(({
328
+ value
329
+ }) => {
330
+ animVals.current.rx = value;
331
+ update();
332
+ });
333
+ return () => {
334
+ animX.removeListener(ix);
335
+ animY.removeListener(iy);
336
+ animWidth.removeListener(iw);
337
+ animHeight.removeListener(ih);
338
+ animRx.removeListener(ir);
339
+ };
340
+ // eslint-disable-next-line react-hooks/exhaustive-deps
341
+ }, [usePathRendering, screenWidth, screenHeight, animX, animY, animWidth, animHeight, animRx, keptSuffix]);
342
+
343
+ // Animation effect
344
+ useEffect(() => {
345
+ if (!shapeResult) return;
346
+ const epoch = ++shapeEpoch.current;
347
+
348
+ // Snap every animated value + both state paths to a rect result at once.
349
+ const applyRectImmediate = r => {
350
+ animX.setValue(r.x);
351
+ animY.setValue(r.y);
352
+ animWidth.setValue(r.width);
353
+ animHeight.setValue(r.height);
354
+ animRx.setValue(r.rx);
355
+ animRy.setValue(r.ry);
356
+ animVals.current = {
357
+ x: r.x,
358
+ y: r.y,
359
+ w: r.width,
360
+ h: r.height,
361
+ rx: r.rx
362
+ };
363
+ const inner = roundedRectPath(r.x, r.y, r.width, r.height, r.rx);
364
+ setOverlayPathD(buildOverlayPath(inner));
365
+ // Same source as the dark hole — keeps the pulse border in lockstep.
366
+ setPathD(inner);
367
+ };
368
+ if (shapeResult.kind === 'path') {
369
+ // Path shapes (per-corner radius / custom maskPath): applied immediately —
370
+ // arbitrary paths can't be tweened reliably, so they jump. Restore the
371
+ // fade opacity in case an interrupted 'fade' left it near 0.
372
+ overlayFade.stopAnimation();
373
+ overlayFade.setValue(1);
374
+ const b = shapeResult.bounds;
375
+ animX.setValue(b.x);
376
+ animY.setValue(b.y);
377
+ animWidth.setValue(b.width);
378
+ animHeight.setValue(b.height);
379
+ setPathD(shapeResult.d);
380
+ setOverlayPathD(buildOverlayPath(shapeResult.d));
381
+ hasAnimated.current = true;
382
+ return;
383
+ }
384
+
385
+ // Rect shapes: first target always snaps into place (nothing to move from).
386
+ if (!hasAnimated.current || motion === 'none') {
387
+ overlayFade.stopAnimation();
388
+ overlayFade.setValue(1);
389
+ applyRectImmediate(shapeResult);
390
+ hasAnimated.current = true;
391
+ return;
392
+ }
393
+
394
+ // 'fade': dip the whole overlay out, jump the hole, fade back in.
395
+ // Halves scale with animationDuration (default 300ms ≈ the old 140/180).
396
+ if (motion === 'fade') {
397
+ Animated.timing(overlayFade, {
398
+ toValue: 0,
399
+ duration: Math.max(60, animationDuration * 0.45),
400
+ useNativeDriver: true
401
+ }).start(() => {
402
+ // A newer step took over mid-dip: it either runs its own fade from the
403
+ // current opacity, or its branch restores opacity itself — never leave
404
+ // the overlay stuck invisible.
405
+ if (epoch !== shapeEpoch.current) return;
406
+ applyRectImmediate(shapeResult);
407
+ Animated.timing(overlayFade, {
408
+ toValue: 1,
409
+ duration: Math.max(80, animationDuration * 0.55),
410
+ useNativeDriver: true
411
+ }).start();
412
+ });
413
+ return;
414
+ }
415
+
416
+ // 'morph' / 'bounce' below never touch overlayFade during the move, so make
417
+ // sure an interrupted fade can't leave the backdrop invisible.
418
+ overlayFade.stopAnimation();
419
+ overlayFade.setValue(1);
420
+
421
+ // 'morph' (timing) / 'bounce' (spring): animate position, size and radius.
422
+ const animate = motion === 'bounce' ? (value, toValue) => Animated.spring(value, {
423
+ toValue,
424
+ friction: 7,
425
+ tension: 90,
426
+ useNativeDriver: false
427
+ }) : (value, toValue) => Animated.timing(value, {
428
+ toValue,
429
+ duration: animationDuration,
430
+ useNativeDriver: false
431
+ });
432
+ Animated.parallel([animate(animX, shapeResult.x), animate(animY, shapeResult.y), animate(animWidth, shapeResult.width), animate(animHeight, shapeResult.height), animate(animRx, shapeResult.rx), animate(animRy, shapeResult.ry)]).start(({
433
+ finished
434
+ }) => {
435
+ // Commit the final frame to React state so a later unrelated re-render
436
+ // can't paint a stale path from before the setNativeProps fast path.
437
+ if (finished && epoch === shapeEpoch.current) {
438
+ applyRectImmediate(shapeResult);
439
+ }
440
+ });
441
+ // keptSuffix is intentionally NOT a dep: a kept-paths change must repaint
442
+ // the path (separate effect below), not replay the whole step transition —
443
+ // with 'fade' that replay double-blinked the backdrop on every
444
+ // keepSpotlight step change.
445
+ // eslint-disable-next-line react-hooks/exhaustive-deps
446
+ }, [shapeResult, motion, animX, animY, animWidth, animHeight, animRx, animRy, animationDuration, overlayFade]);
447
+
448
+ // Repaint-only path for kept-hole changes: rebuild the overlay path from the
449
+ // CURRENT inner subpath with the new kept suffix, without touching the
450
+ // animated values or the transition.
451
+ useEffect(() => {
452
+ if (pathD) setOverlayPathD(buildOverlayPath(pathD));
453
+ // buildOverlayPath closes over keptSuffix; pathD is the current inner.
454
+ // eslint-disable-next-line react-hooks/exhaustive-deps
455
+ }, [keptSuffix]);
456
+
457
+ // Pulse animation
458
+ useEffect(() => {
459
+ if (!enablePulse || !target) {
460
+ pulseOpacity.setValue(0);
461
+ return;
462
+ }
463
+ const halfDuration = pulseDuration / 2;
464
+ const loop = Animated.loop(Animated.sequence([Animated.timing(pulseOpacity, {
465
+ toValue: pulseMaxOpacity,
466
+ duration: halfDuration,
467
+ useNativeDriver: true
468
+ }), Animated.timing(pulseOpacity, {
469
+ toValue: pulseMinOpacity,
470
+ duration: halfDuration,
471
+ useNativeDriver: true
472
+ })]));
473
+ loop.start();
474
+ return () => loop.stop();
475
+ }, [enablePulse, target, pulseDuration, pulseMinOpacity, pulseMaxOpacity, pulseOpacity]);
476
+
477
+ // No target (centered / no-spotlight step, or the measurement gap between
478
+ // steps): the screen stays dimmed and the press handler available. Kept
479
+ // spotlights (keepSpotlight) must survive this branch too — a plain solid
480
+ // backdrop made accumulated holes vanish on centered steps and blink off
481
+ // between steps.
482
+ if (!target || !shapeResult || !bounds) {
483
+ if (keptPaths && keptPaths.length > 0) {
484
+ const w = Math.max(screenWidth, Dimensions.get('screen').width);
485
+ const h = Math.max(screenHeight, Dimensions.get('screen').height);
486
+ const d = `M0,0 H${w} V${h} H0 Z ${keptPaths.join(' ')}`;
487
+ return /*#__PURE__*/_jsx(View, {
488
+ style: StyleSheet.absoluteFill,
489
+ pointerEvents: "box-none",
490
+ children: /*#__PURE__*/_jsx(Pressable, {
491
+ style: StyleSheet.absoluteFill,
492
+ onPress: onBackdropPress,
493
+ children: /*#__PURE__*/_jsx(Svg, {
494
+ height: h,
495
+ width: w,
496
+ style: StyleSheet.absoluteFill,
497
+ children: /*#__PURE__*/_jsx(Path, {
498
+ d: d,
499
+ fill: overlayColor,
500
+ fillOpacity: overlayOpacity,
501
+ fillRule: "evenodd"
502
+ })
503
+ })
504
+ })
505
+ });
506
+ }
507
+ return /*#__PURE__*/_jsx(Pressable, {
508
+ style: [StyleSheet.absoluteFill, {
509
+ backgroundColor: overlayColor,
510
+ opacity: overlayOpacity
511
+ }],
512
+ onPress: onBackdropPress
513
+ });
514
+ }
515
+
516
+ // Resolve optional libraries (cached at module scope)
517
+ const wantsBlurLayer = enableBlur || mountBlurLayer;
518
+ const blurProvider = wantsBlurLayer ? getBlurProvider() : null;
519
+ const LinearGradient = enableGradient ? getLinearGradient() : null;
520
+ const MaskedView = wantsBlurLayer && blurProvider ? getMaskedView() : null;
521
+
522
+ // --- Cutout shape rendering helpers ---
523
+ const renderRectCutout = (fill, stroke, sw) => /*#__PURE__*/_jsx(AnimatedRect, {
524
+ x: animX,
525
+ y: animY,
526
+ width: animWidth,
527
+ height: animHeight,
528
+ rx: animRx,
529
+ ry: animRy,
530
+ fill: fill,
531
+ stroke: stroke,
532
+ strokeWidth: sw
533
+ });
534
+ const renderPathCutout = (fill, stroke, sw) => /*#__PURE__*/_jsx(Path, {
535
+ d: pathD,
536
+ fill: fill,
537
+ stroke: stroke,
538
+ strokeWidth: sw
539
+ });
540
+ const renderCutout = (fill, stroke, sw) => usePathRendering ? renderPathCutout(fill, stroke, sw) : renderRectCutout(fill, stroke, sw);
541
+
542
+ // Optional masked blur/gradient backdrop — shared by both render branches so
543
+ // interactive steps keep the same backdrop styling as everything else.
544
+ const renderBlurLayer = () => wantsBlurLayer && blurProvider && MaskedView ? /*#__PURE__*/_jsx(Animated.View, {
545
+ style: [StyleSheet.absoluteFill, {
546
+ opacity: blurFade
547
+ }],
548
+ pointerEvents: "none",
549
+ children: /*#__PURE__*/_jsxs(MaskedView, {
550
+ style: StyleSheet.absoluteFill,
551
+ maskElement: /*#__PURE__*/_jsxs(Svg, {
552
+ height: coverHeight,
553
+ width: coverWidth,
554
+ children: [/*#__PURE__*/_jsx(Defs, {
555
+ children: /*#__PURE__*/_jsxs(Mask, {
556
+ id: maskIds.inverse,
557
+ children: [/*#__PURE__*/_jsx(Rect, {
558
+ x: "0",
559
+ y: "0",
560
+ width: coverWidth,
561
+ height: coverHeight,
562
+ fill: "white"
563
+ }), renderCutout('black')]
564
+ })
565
+ }), /*#__PURE__*/_jsx(Rect, {
566
+ x: "0",
567
+ y: "0",
568
+ width: coverWidth,
569
+ height: coverHeight,
570
+ fill: "black",
571
+ mask: `url(#${maskIds.inverse})`
572
+ })]
573
+ }),
574
+ children: [blurProvider.kind === 'community' ? /*#__PURE__*/_jsx(blurProvider.Component, {
575
+ style: StyleSheet.absoluteFill,
576
+ blurType: "light",
577
+ blurAmount: blurAmount,
578
+ reducedTransparencyFallbackColor: "white"
579
+ }) :
580
+ /*#__PURE__*/
581
+ // expo-blur: real blur on iOS out of the box. On Android real blur
582
+ // additionally needs spotlightStyles.blurTarget (a ref to an
583
+ // expo-blur BlurTargetView wrapping the app content); without it,
584
+ // Android degrades to a soft tint.
585
+ _jsx(blurProvider.Component, {
586
+ style: StyleSheet.absoluteFill,
587
+ intensity: Math.min(100, blurAmount * 2),
588
+ tint: "light",
589
+ ...(blurTarget ? {
590
+ blurTarget,
591
+ blurMethod: 'dimezisBlurView'
592
+ } : {})
593
+ }), enableGradient && LinearGradient ? /*#__PURE__*/_jsx(LinearGradient, {
594
+ colors: gradientColors,
595
+ start: {
596
+ x: 0.5,
597
+ y: 0
598
+ },
599
+ end: {
600
+ x: 0.5,
601
+ y: 1
602
+ },
603
+ style: StyleSheet.absoluteFill
604
+ }) : null]
605
+ })
606
+ }) : null;
607
+ if (pressBands) {
608
+ return /*#__PURE__*/_jsxs(View, {
609
+ style: StyleSheet.absoluteFill,
610
+ pointerEvents: "box-none",
611
+ children: [/*#__PURE__*/_jsxs(Animated.View, {
612
+ style: [StyleSheet.absoluteFill, {
613
+ opacity: overlayFade
614
+ }],
615
+ pointerEvents: "none",
616
+ children: [renderBlurLayer(), /*#__PURE__*/_jsx(Svg, {
617
+ height: coverHeight,
618
+ width: coverWidth,
619
+ style: StyleSheet.absoluteFill,
620
+ children: /*#__PURE__*/_jsx(Path, {
621
+ ref: overlayPathRef,
622
+ d: motion === 'none' ? buildOverlayPath(shapeResult.kind === 'rect' ? roundedRectPath(shapeResult.x, shapeResult.y, shapeResult.width, shapeResult.height, shapeResult.rx) : shapeResult.d) : overlayPathD,
623
+ fill: overlayColor,
624
+ fillOpacity: overlayOpacity,
625
+ fillRule: "evenodd"
626
+ })
627
+ }), enablePulse ? /*#__PURE__*/_jsx(Animated.View, {
628
+ style: [StyleSheet.absoluteFill, {
629
+ opacity: pulseVisible
630
+ }],
631
+ pointerEvents: "none",
632
+ children: /*#__PURE__*/_jsx(Svg, {
633
+ height: coverHeight,
634
+ width: coverWidth,
635
+ children: /*#__PURE__*/_jsx(Path, {
636
+ ref: pulsePathRef,
637
+ d: pathD,
638
+ fill: "none",
639
+ stroke: pulseColor,
640
+ strokeWidth: pulseWidth
641
+ })
642
+ })
643
+ }) : null]
644
+ }), pressBands.map((band, i) => /*#__PURE__*/_jsx(Pressable, {
645
+ style: [{
646
+ position: 'absolute'
647
+ }, band],
648
+ onPress: onBackdropPress,
649
+ accessibilityElementsHidden: true,
650
+ importantForAccessibility: "no-hide-descendants"
651
+ }, `band-${i}`))]
652
+ });
653
+ }
654
+ return /*#__PURE__*/_jsxs(View, {
655
+ style: StyleSheet.absoluteFill,
656
+ pointerEvents: "box-none",
657
+ children: [/*#__PURE__*/_jsxs(Pressable, {
658
+ style: StyleSheet.absoluteFill,
659
+ onPress: onBackdropPress,
660
+ children: [renderBlurLayer(), /*#__PURE__*/_jsx(Animated.View, {
661
+ style: [StyleSheet.absoluteFill, {
662
+ opacity: overlayFade
663
+ }],
664
+ pointerEvents: "none",
665
+ children: /*#__PURE__*/_jsx(Svg, {
666
+ height: coverHeight,
667
+ width: coverWidth,
668
+ style: StyleSheet.absoluteFill,
669
+ children: /*#__PURE__*/_jsx(Path, {
670
+ ref: overlayPathRef,
671
+ d: motion === 'none' ? buildOverlayPath(shapeResult.kind === 'rect' ? roundedRectPath(shapeResult.x, shapeResult.y, shapeResult.width, shapeResult.height, shapeResult.rx) : shapeResult.d) : overlayPathD,
672
+ fill: overlayColor,
673
+ fillOpacity: overlayOpacity,
674
+ fillRule: "evenodd"
675
+ })
676
+ })
677
+ })]
678
+ }), enablePulse ? /*#__PURE__*/_jsx(Animated.View, {
679
+ style: [StyleSheet.absoluteFill, {
680
+ opacity: pulseVisible
681
+ }],
682
+ pointerEvents: "none",
683
+ children: /*#__PURE__*/_jsx(Svg, {
684
+ height: coverHeight,
685
+ width: coverWidth,
686
+ children: /*#__PURE__*/_jsx(Path, {
687
+ ref: pulsePathRef,
688
+ d: pathD,
689
+ fill: "none",
690
+ stroke: pulseColor,
691
+ strokeWidth: pulseWidth
692
+ })
693
+ })
694
+ }) : null, onSpotlightPress ? /*#__PURE__*/_jsx(Pressable, {
695
+ style: {
696
+ position: 'absolute',
697
+ left: bounds.x,
698
+ top: bounds.y,
699
+ width: bounds.width,
700
+ height: bounds.height
701
+ },
702
+ onPress: onSpotlightPress
703
+ }) : null]
704
+ });
705
+ };
706
+ export default SpotlightOverlay;
707
+ //# sourceMappingURL=SpotlightOverlay.js.map