@ethicly/react-native 0.0.0-stage → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/CHANGELOG.md +133 -0
  2. package/LICENSE +21 -0
  3. package/README.md +428 -2
  4. package/core/package.json +6 -0
  5. package/interstitial/package.json +6 -0
  6. package/lib/commonjs/core/adapters.js +326 -0
  7. package/lib/commonjs/core/beacons.js +70 -0
  8. package/lib/commonjs/core/cache.js +261 -0
  9. package/lib/commonjs/core/click.js +29 -0
  10. package/lib/commonjs/core/client.js +585 -0
  11. package/lib/commonjs/core/config.js +128 -0
  12. package/lib/commonjs/core/http.js +115 -0
  13. package/lib/commonjs/core/index.js +21 -0
  14. package/lib/commonjs/core/outbox.js +192 -0
  15. package/lib/commonjs/core/tracker.js +379 -0
  16. package/lib/commonjs/core/types.js +4 -0
  17. package/lib/commonjs/index.js +22 -0
  18. package/lib/commonjs/interstitial.js +7 -0
  19. package/lib/commonjs/react/EthiclyInterstitial.js +319 -0
  20. package/lib/commonjs/react/useEthiclyInterstitial.js +54 -0
  21. package/lib/commonjs/version.js +5 -0
  22. package/lib/module/core/adapters.js +315 -0
  23. package/lib/module/core/beacons.js +64 -0
  24. package/lib/module/core/cache.js +257 -0
  25. package/lib/module/core/click.js +24 -0
  26. package/lib/module/core/client.js +581 -0
  27. package/lib/module/core/config.js +118 -0
  28. package/lib/module/core/http.js +105 -0
  29. package/lib/module/core/index.js +6 -0
  30. package/lib/module/core/outbox.js +186 -0
  31. package/lib/module/core/tracker.js +375 -0
  32. package/lib/module/core/types.js +3 -0
  33. package/lib/module/index.js +4 -0
  34. package/lib/module/interstitial.js +3 -0
  35. package/lib/module/react/EthiclyInterstitial.js +292 -0
  36. package/lib/module/react/useEthiclyInterstitial.js +51 -0
  37. package/lib/module/version.js +2 -0
  38. package/lib/typescript/core/adapters.d.ts +139 -0
  39. package/lib/typescript/core/beacons.d.ts +32 -0
  40. package/lib/typescript/core/cache.d.ts +71 -0
  41. package/lib/typescript/core/click.d.ts +13 -0
  42. package/lib/typescript/core/client.d.ts +78 -0
  43. package/lib/typescript/core/config.d.ts +33 -0
  44. package/lib/typescript/core/http.d.ts +34 -0
  45. package/lib/typescript/core/index.d.ts +8 -0
  46. package/lib/typescript/core/outbox.d.ts +56 -0
  47. package/lib/typescript/core/tracker.d.ts +95 -0
  48. package/lib/typescript/core/types.d.ts +175 -0
  49. package/lib/typescript/index.d.ts +3 -0
  50. package/lib/typescript/interstitial.d.ts +2 -0
  51. package/lib/typescript/react/EthiclyInterstitial.d.ts +51 -0
  52. package/lib/typescript/react/useEthiclyInterstitial.d.ts +20 -0
  53. package/lib/typescript/version.d.ts +2 -0
  54. package/package.json +101 -4
  55. package/src/core/adapters.ts +365 -0
  56. package/src/core/beacons.ts +81 -0
  57. package/src/core/cache.ts +261 -0
  58. package/src/core/click.ts +26 -0
  59. package/src/core/client.ts +665 -0
  60. package/src/core/config.ts +124 -0
  61. package/src/core/http.ts +115 -0
  62. package/src/core/index.ts +14 -0
  63. package/src/core/outbox.ts +193 -0
  64. package/src/core/tracker.ts +376 -0
  65. package/src/core/types.ts +185 -0
  66. package/src/index.ts +5 -0
  67. package/src/interstitial.ts +4 -0
  68. package/src/react/EthiclyInterstitial.tsx +432 -0
  69. package/src/react/useEthiclyInterstitial.ts +74 -0
  70. package/src/version.ts +2 -0
@@ -0,0 +1,319 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.effectiveAudio = effectiveAudio;
27
+ exports.EthiclyInterstitial = EthiclyInterstitial;
28
+ const jsx_runtime_1 = require("react/jsx-runtime");
29
+ // Optional ready-made fullscreen screen. Needs expo-video (Expo SDK 52+).
30
+ // Layout follows a typical in-app video player: 9:16 video, a skip control that counts
31
+ // down then reads "Skip Ad", a white call-to-action button, an optional
32
+ // "Remove ads" slot and a small "Sponsored by Ethicly.ch" line under it.
33
+ // Video starts with sound unless the effective audio (the `audio` prop, else
34
+ // ad.audio: createEthicly's `audio` option, else /config) is 'none' or 'optional'.
35
+ // The controls keep clear of the notch, status bar and home indicator: see
36
+ // useSafeInsets below.
37
+ const react_1 = __importStar(require("react"));
38
+ const react_native_1 = require("react-native");
39
+ const expo_video_1 = require("expo-video");
40
+ /** The sound a screen plays with: the prop, else ad.audio, else 'on'. */
41
+ function effectiveAudio(prop, ad) {
42
+ for (const v of [prop, ad.audio])
43
+ if (v === 'on' || v === 'optional' || v === 'none')
44
+ return v;
45
+ return 'on';
46
+ }
47
+ const TICK_MS = 250;
48
+ /** Space between the safe area and the controls. */
49
+ const TOP_GAP = 12;
50
+ const BOTTOM_GAP = 10;
51
+ const SIDE_GAP_TOP = 16;
52
+ const SIDE_GAP_BOTTOM = 20;
53
+ /**
54
+ * The 0.1 layout (controls 56 from the top, 44 from the bottom) is a floor:
55
+ * insets only ever move the controls inward, so a phone without a notch or a
56
+ * tall status bar looks exactly as before.
57
+ */
58
+ const MIN_TOP = 56;
59
+ const MIN_BOTTOM = 44;
60
+ /**
61
+ * react-native-safe-area-context when the app has it, else null. Metro treats
62
+ * a require inside try/catch as an optional dependency (the React Native and
63
+ * Expo Metro configs set allowOptionalDependencies), so an app without the
64
+ * package still builds.
65
+ */
66
+ function loadSafeArea() {
67
+ try {
68
+ // @ts-ignore: the build compiles without Node's types, where require is undeclared.
69
+ return typeof require === 'function' ? require('react-native-safe-area-context') : null;
70
+ }
71
+ catch {
72
+ return null;
73
+ }
74
+ }
75
+ const safeArea = loadSafeArea();
76
+ const noInsets = react_1.default.createContext(null);
77
+ // Read with useContext, which returns null without a SafeAreaProvider instead
78
+ // of throwing like useSafeAreaInsets(). Fixed at load, so hook order never changes.
79
+ const InsetsContext = safeArea && safeArea.SafeAreaInsetsContext && typeof safeArea.SafeAreaInsetsContext === 'object'
80
+ ? safeArea.SafeAreaInsetsContext
81
+ : noInsets;
82
+ function validInsets(v) {
83
+ const i = v;
84
+ if (!i || typeof i !== 'object')
85
+ return null;
86
+ const n = (x) => (typeof x === 'number' && Number.isFinite(x) && x >= 0 ? x : 0);
87
+ if (typeof i.top !== 'number' && typeof i.bottom !== 'number')
88
+ return null;
89
+ return { top: n(i.top), bottom: n(i.bottom), left: n(i.left), right: n(i.right) };
90
+ }
91
+ /** The `insets` prop, else the provider's insets, else the window's first metrics, else the status bar. */
92
+ function useSafeInsets(prop) {
93
+ var _a, _b, _c, _d, _e;
94
+ const fromProvider = (0, react_1.useContext)(InsetsContext);
95
+ return (_d = (_b = (_a = validInsets(prop)) !== null && _a !== void 0 ? _a : validInsets(fromProvider)) !== null && _b !== void 0 ? _b : validInsets((_c = safeArea === null || safeArea === void 0 ? void 0 : safeArea.initialWindowMetrics) === null || _c === void 0 ? void 0 : _c.insets)) !== null && _d !== void 0 ? _d : { top: react_native_1.Platform.OS === 'android' ? (_e = react_native_1.StatusBar.currentHeight) !== null && _e !== void 0 ? _e : 0 : 0, bottom: 0, left: 0, right: 0 };
96
+ }
97
+ function EthiclyInterstitial(props) {
98
+ // Android back: a Modal receives it through onRequestClose, an inline screen
99
+ // through BackHandler. Either way it closes the ad only once Skip is allowed,
100
+ // and is swallowed before that.
101
+ const backRef = (0, react_1.useRef)(null);
102
+ const inline = props.modal === false;
103
+ (0, react_1.useEffect)(() => {
104
+ if (!inline)
105
+ return undefined;
106
+ const sub = react_native_1.BackHandler.addEventListener('hardwareBackPress', () => {
107
+ var _a;
108
+ (_a = backRef.current) === null || _a === void 0 ? void 0 : _a.call(backRef);
109
+ return true;
110
+ });
111
+ return () => sub.remove();
112
+ }, [inline]);
113
+ const body = (0, jsx_runtime_1.jsx)(InterstitialBody, { ...props, backRef: backRef });
114
+ if (inline)
115
+ return body;
116
+ return ((0, jsx_runtime_1.jsx)(react_native_1.Modal, { visible: true, animationType: "fade", presentationStyle: "fullScreen", statusBarTranslucent: true, onRequestClose: () => { var _a; return (_a = backRef.current) === null || _a === void 0 ? void 0 : _a.call(backRef); }, children: body }));
117
+ }
118
+ function useAppActive() {
119
+ const [active, setActive] = (0, react_1.useState)(react_native_1.AppState.currentState === 'active');
120
+ (0, react_1.useEffect)(() => {
121
+ const sub = react_native_1.AppState.addEventListener('change', (s) => setActive(s === 'active'));
122
+ return () => sub.remove();
123
+ }, []);
124
+ return active;
125
+ }
126
+ function InterstitialBody({ ad, tracker, onClose, onRemoveAds, removeAdsLabel, renderBelowButton, skipStyle, skipTextStyle, insets, backRef, audio: audioProp, }) {
127
+ const audio = effectiveAudio(audioProp, ad);
128
+ const safe = useSafeInsets(insets);
129
+ const isVideo = ad.media.kind === 'video' && !!ad.media.videoUri;
130
+ const appActive = useAppActive();
131
+ const activeRef = (0, react_1.useRef)(appActive);
132
+ activeRef.current = appActive;
133
+ const [positionMs, setPositionMs] = (0, react_1.useState)(0);
134
+ const [ended, setEnded] = (0, react_1.useState)(false);
135
+ const [failed, setFailed] = (0, react_1.useState)(false);
136
+ const [muted, setMuted] = (0, react_1.useState)(audio !== 'on');
137
+ /**
138
+ * A still image counts as visible only once it has loaded: an image that
139
+ * never arrives is never billed as viewable.
140
+ */
141
+ const imageLoadedRef = (0, react_1.useRef)(false);
142
+ /** Wall-clock time on screen with the app in the foreground. */
143
+ const [onScreenMs, setOnScreenMs] = (0, react_1.useState)(0);
144
+ const [clicked, setClicked] = (0, react_1.useState)(false);
145
+ const positionRef = (0, react_1.useRef)(0);
146
+ const closedRef = (0, react_1.useRef)(false);
147
+ const failedRef = (0, react_1.useRef)(false);
148
+ const player = (0, expo_video_1.useVideoPlayer)(isVideo ? ad.media.videoUri : null, (p) => {
149
+ p.loop = false;
150
+ p.muted = audio !== 'on';
151
+ p.timeUpdateEventInterval = TICK_MS / 1000;
152
+ p.play();
153
+ });
154
+ const onCloseRef = (0, react_1.useRef)(onClose);
155
+ onCloseRef.current = onClose;
156
+ // The impression goes out the moment the ad is on screen. shown() refuses an
157
+ // ad past its token lifetime (nothing is recorded), so the screen closes
158
+ // itself instead of playing an ad nobody is paid for.
159
+ (0, react_1.useEffect)(() => {
160
+ const expired = tracker.isExpired();
161
+ void tracker.shown();
162
+ if (expired && !closedRef.current) {
163
+ closedRef.current = true;
164
+ void tracker.closed();
165
+ onCloseRef.current();
166
+ }
167
+ }, [tracker]);
168
+ // Video: playback position drives viewability, quartiles and the skip countdown.
169
+ (0, react_1.useEffect)(() => {
170
+ if (!isVideo)
171
+ return undefined;
172
+ const subs = [
173
+ player.addListener('timeUpdate', ({ currentTime }) => {
174
+ const ms = Math.max(0, currentTime * 1000);
175
+ positionRef.current = ms;
176
+ setPositionMs(ms);
177
+ const durationMs = player.duration > 0 ? player.duration * 1000 : undefined;
178
+ tracker.progress(ms, { visible: activeRef.current && player.playing, durationMs });
179
+ }),
180
+ player.addListener('playToEnd', () => {
181
+ setEnded(true);
182
+ tracker.complete();
183
+ }),
184
+ player.addListener('statusChange', ({ status }) => {
185
+ if (status === 'error' && !failedRef.current) {
186
+ failedRef.current = true;
187
+ setFailed(true);
188
+ tracker.error();
189
+ }
190
+ }),
191
+ ];
192
+ return () => subs.forEach((s) => s.remove());
193
+ }, [isVideo, player, tracker]);
194
+ // Time on screen while the app is in the foreground: the skip countdown, so
195
+ // Skip appears after skipAfterMs even if the video stalls or the image never
196
+ // loads. For a still image, the time since it loaded is the playback position.
197
+ (0, react_1.useEffect)(() => {
198
+ let shownMs = 0;
199
+ let loadedMs = 0;
200
+ const id = setInterval(() => {
201
+ if (activeRef.current)
202
+ shownMs += TICK_MS;
203
+ setOnScreenMs(shownMs);
204
+ if (isVideo || !imageLoadedRef.current || failedRef.current)
205
+ return;
206
+ if (activeRef.current)
207
+ loadedMs += TICK_MS;
208
+ positionRef.current = loadedMs;
209
+ setPositionMs(loadedMs);
210
+ tracker.progress(loadedMs, { visible: activeRef.current });
211
+ }, TICK_MS);
212
+ return () => clearInterval(id);
213
+ }, [isVideo, tracker]);
214
+ const onImageLoad = (0, react_1.useCallback)(() => {
215
+ imageLoadedRef.current = true;
216
+ }, []);
217
+ const onImageError = (0, react_1.useCallback)(() => {
218
+ if (failedRef.current)
219
+ return;
220
+ failedRef.current = true;
221
+ setFailed(true);
222
+ tracker.error();
223
+ }, [tracker]);
224
+ (0, react_1.useEffect)(() => {
225
+ if (!isVideo)
226
+ return;
227
+ if (appActive && !ended)
228
+ player.play();
229
+ else
230
+ player.pause();
231
+ }, [appActive, ended, isVideo, player]);
232
+ // Leaving the foreground ends continuous visibility right away, without
233
+ // waiting for the next player tick (which may never come while paused).
234
+ (0, react_1.useEffect)(() => {
235
+ if (appActive)
236
+ return;
237
+ if (!isVideo && (!imageLoadedRef.current || failedRef.current))
238
+ return;
239
+ const durationMs = isVideo && player.duration > 0 ? player.duration * 1000 : undefined;
240
+ tracker.progress(positionRef.current, { visible: false, durationMs });
241
+ }, [appActive, isVideo, player, tracker]);
242
+ // The tracker is closed only from close() below (or by the hook's dismiss()),
243
+ // never from an effect cleanup: React StrictMode runs every cleanup once on
244
+ // mount, and a closed tracker drops /viewable and the video events.
245
+ const close = (0, react_1.useCallback)(() => {
246
+ if (closedRef.current)
247
+ return;
248
+ closedRef.current = true;
249
+ if (isVideo && !ended && !failed)
250
+ tracker.skipped(positionRef.current);
251
+ void tracker.closed();
252
+ onClose();
253
+ }, [ended, failed, isVideo, onClose, tracker]);
254
+ const onCta = (0, react_1.useCallback)(() => {
255
+ if (isVideo)
256
+ player.pause();
257
+ // Once the user has visited the advertiser, they can always close the ad
258
+ // when they come back.
259
+ setClicked(true);
260
+ void tracker.clicked();
261
+ }, [isVideo, player, tracker]);
262
+ const toggleSound = (0, react_1.useCallback)(() => {
263
+ setMuted((m) => {
264
+ player.muted = !m;
265
+ return !m;
266
+ });
267
+ }, [player]);
268
+ const remainingS = Math.ceil(Math.max(0, ad.skipAfterMs - Math.max(positionMs, onScreenMs)) / 1000);
269
+ const canSkip = remainingS === 0 || ended || failed || clicked;
270
+ backRef.current = canSkip ? close : null;
271
+ return ((0, jsx_runtime_1.jsxs)(react_native_1.View, { style: styles.root, children: [isVideo ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [ad.media.posterUri ? (0, jsx_runtime_1.jsx)(react_native_1.Image, { source: { uri: ad.media.posterUri }, style: react_native_1.StyleSheet.absoluteFill, resizeMode: "cover" }) : null, (0, jsx_runtime_1.jsx)(expo_video_1.VideoView, { player: player, style: react_native_1.StyleSheet.absoluteFill, contentFit: "cover", nativeControls: false, allowsPictureInPicture: false })] })) : ((0, jsx_runtime_1.jsx)(react_native_1.Image, { source: { uri: ad.media.uri }, style: react_native_1.StyleSheet.absoluteFill, resizeMode: "cover", onLoad: onImageLoad, onError: onImageError })), (0, jsx_runtime_1.jsxs)(react_native_1.View, { style: [styles.topRow, { top: Math.max(safe.top + TOP_GAP, MIN_TOP), left: safe.left + SIDE_GAP_TOP, right: safe.right + SIDE_GAP_TOP }], pointerEvents: "box-none", children: [(0, jsx_runtime_1.jsxs)(react_native_1.View, { style: styles.leftGroup, children: [(0, jsx_runtime_1.jsx)(react_native_1.Text, { style: styles.adLabel, accessibilityRole: "text", children: "Ad" }), ad.test ? (0, jsx_runtime_1.jsx)(react_native_1.Text, { style: [styles.adLabel, styles.testLabel], accessibilityRole: "text", children: "Test ad" }) : null, isVideo && audio !== 'none' ? ((0, jsx_runtime_1.jsx)(react_native_1.Pressable, { onPress: toggleSound, style: styles.soundButton, accessibilityRole: "button", accessibilityLabel: muted ? 'Turn sound on' : 'Mute', hitSlop: 8, children: (0, jsx_runtime_1.jsx)(react_native_1.Text, { style: styles.soundText, children: muted ? 'Sound off' : 'Sound on' }) })) : null] }), (0, jsx_runtime_1.jsx)(react_native_1.Pressable, { onPress: canSkip ? close : undefined, disabled: !canSkip, style: [styles.skip, skipStyle], accessibilityRole: "button", accessibilityLabel: canSkip ? 'Skip ad' : `Skip in ${remainingS} seconds`, hitSlop: 8, children: canSkip ? ((0, jsx_runtime_1.jsxs)(react_native_1.View, { style: styles.skipRow, children: [(0, jsx_runtime_1.jsx)(react_native_1.Text, { style: [styles.skipText, skipTextStyle], children: "Skip Ad" }), (0, jsx_runtime_1.jsx)(SkipIcon, {})] })) : ((0, jsx_runtime_1.jsx)(react_native_1.Text, { style: [styles.skipText, styles.skipTextWaiting, skipTextStyle], children: `Skip in ${remainingS}` })) })] }), (0, jsx_runtime_1.jsxs)(react_native_1.View, { style: [styles.bottom, {
272
+ bottom: Math.max(safe.bottom + BOTTOM_GAP, MIN_BOTTOM), left: safe.left + SIDE_GAP_BOTTOM, right: safe.right + SIDE_GAP_BOTTOM,
273
+ }], pointerEvents: "box-none", children: [(0, jsx_runtime_1.jsx)(react_native_1.Pressable, { onPress: onCta, style: ({ pressed }) => [styles.cta, pressed && styles.ctaPressed], accessibilityRole: "link", children: (0, jsx_runtime_1.jsx)(react_native_1.Text, { style: styles.ctaText, numberOfLines: 1, children: ad.ctaLabel || 'Learn more' }) }), renderBelowButton ? renderBelowButton() : onRemoveAds ? ((0, jsx_runtime_1.jsx)(react_native_1.Pressable, { onPress: onRemoveAds, accessibilityRole: "button", hitSlop: 8, children: (0, jsx_runtime_1.jsx)(react_native_1.Text, { style: styles.removeAds, children: removeAdsLabel || 'Remove ads' }) })) : null, (0, jsx_runtime_1.jsx)(react_native_1.Text, { style: styles.sponsor, children: "Sponsored by Ethicly.ch" })] })] }));
274
+ }
275
+ /** Skip-to-end mark (a play triangle against a bar), drawn so it never depends on a font glyph. */
276
+ function SkipIcon() {
277
+ return ((0, jsx_runtime_1.jsxs)(react_native_1.View, { style: styles.skipIcon, accessibilityElementsHidden: true, importantForAccessibility: "no-hide-descendants", children: [(0, jsx_runtime_1.jsx)(react_native_1.View, { style: styles.skipTriangle }), (0, jsx_runtime_1.jsx)(react_native_1.View, { style: styles.skipBar })] }));
278
+ }
279
+ const styles = react_native_1.StyleSheet.create({
280
+ root: { flex: 1, backgroundColor: '#000' },
281
+ topRow: {
282
+ position: 'absolute',
283
+ flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center',
284
+ },
285
+ leftGroup: { flexDirection: 'row', alignItems: 'center' },
286
+ adLabel: {
287
+ color: '#fff', fontSize: 11, fontWeight: '600', letterSpacing: 0.5,
288
+ backgroundColor: 'rgba(0,0,0,0.45)', paddingHorizontal: 6, paddingVertical: 2, borderRadius: 4, overflow: 'hidden',
289
+ },
290
+ testLabel: { marginLeft: 8, backgroundColor: 'rgba(196,120,0,0.85)' },
291
+ soundButton: { marginLeft: 8, backgroundColor: 'rgba(0,0,0,0.45)', paddingHorizontal: 8, paddingVertical: 4, borderRadius: 6 },
292
+ soundText: { color: '#fff', fontSize: 12, fontWeight: '500' },
293
+ // Solid black, no blur or translucency. The faint hairline keeps the edge
294
+ // visible over a dark frame.
295
+ skip: {
296
+ backgroundColor: '#000', paddingHorizontal: 18, height: 40, borderRadius: 20,
297
+ justifyContent: 'center', alignItems: 'center',
298
+ borderWidth: react_native_1.StyleSheet.hairlineWidth, borderColor: 'rgba(255,255,255,0.22)',
299
+ },
300
+ skipRow: { flexDirection: 'row', alignItems: 'center' },
301
+ skipText: { color: '#fff', fontSize: 15, fontWeight: '500', letterSpacing: 0.2 },
302
+ skipTextWaiting: { opacity: 0.75 },
303
+ skipIcon: { flexDirection: 'row', alignItems: 'center', marginLeft: 10 },
304
+ skipTriangle: {
305
+ width: 0, height: 0,
306
+ borderTopWidth: 6, borderBottomWidth: 6, borderLeftWidth: 10,
307
+ borderTopColor: 'transparent', borderBottomColor: 'transparent', borderLeftColor: '#fff',
308
+ },
309
+ skipBar: { width: 2, height: 12, backgroundColor: '#fff', marginLeft: 2, borderRadius: 1 },
310
+ bottom: { position: 'absolute', alignItems: 'center' },
311
+ cta: {
312
+ alignSelf: 'stretch', backgroundColor: '#fff', borderRadius: 12, paddingVertical: 15,
313
+ alignItems: 'center', justifyContent: 'center',
314
+ },
315
+ ctaPressed: { opacity: 0.85 },
316
+ ctaText: { color: '#000', fontSize: 17, fontWeight: '600' },
317
+ removeAds: { color: '#fff', fontSize: 14, marginTop: 14, textDecorationLine: 'underline', opacity: 0.9 },
318
+ sponsor: { color: '#fff', fontSize: 12, marginTop: 10, opacity: 0.6 },
319
+ });
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ // React hook over the headless core. No React Native or Expo imports, so it
3
+ // works with any player the host app already has.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.useEthiclyInterstitial = useEthiclyInterstitial;
6
+ const react_1 = require("react");
7
+ function useEthiclyInterstitial(ethicly, options = {}) {
8
+ var _a, _b;
9
+ const preload = options.preload !== false;
10
+ const [current, setCurrent] = (0, react_1.useState)(null);
11
+ const [reason, setReason] = (0, react_1.useState)(null);
12
+ const [loading, setLoading] = (0, react_1.useState)(false);
13
+ const mounted = (0, react_1.useRef)(true);
14
+ const currentRef = (0, react_1.useRef)(current);
15
+ currentRef.current = current;
16
+ (0, react_1.useEffect)(() => {
17
+ mounted.current = true;
18
+ if (preload)
19
+ void ethicly.preload();
20
+ return () => {
21
+ var _a;
22
+ mounted.current = false;
23
+ void ((_a = currentRef.current) === null || _a === void 0 ? void 0 : _a.tracker.closed());
24
+ };
25
+ }, [ethicly, preload]);
26
+ const show = (0, react_1.useCallback)(async () => {
27
+ setLoading(true);
28
+ try {
29
+ const r = await ethicly.loadInterstitial();
30
+ if (!mounted.current)
31
+ return false;
32
+ if (r.ad) {
33
+ setCurrent({ ad: r.ad, tracker: r.tracker });
34
+ setReason(null);
35
+ return true;
36
+ }
37
+ setReason(r.reason);
38
+ return false;
39
+ }
40
+ finally {
41
+ if (mounted.current)
42
+ setLoading(false);
43
+ }
44
+ }, [ethicly]);
45
+ const dismiss = (0, react_1.useCallback)(() => {
46
+ var _a;
47
+ void ((_a = currentRef.current) === null || _a === void 0 ? void 0 : _a.tracker.closed());
48
+ setCurrent(null);
49
+ if (preload)
50
+ void ethicly.preload();
51
+ }, [ethicly, preload]);
52
+ const canShow = (0, react_1.useCallback)(() => ethicly.canShow(), [ethicly]);
53
+ return { ad: (_a = current === null || current === void 0 ? void 0 : current.ad) !== null && _a !== void 0 ? _a : null, tracker: (_b = current === null || current === void 0 ? void 0 : current.tracker) !== null && _b !== void 0 ? _b : null, reason, loading, show, dismiss, canShow };
54
+ }
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SDK_VERSION = void 0;
4
+ /** SDK version, sent as sdk_version and in X-Ethicly-SDK. Keep in step with package.json. */
5
+ exports.SDK_VERSION = '0.2.1';