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