@onekeyfe/react-native-native-overlay 6.7.0-alpha.475 → 6.8.0-11

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 (102) hide show
  1. package/README.md +119 -21
  2. package/android/src/main/java/com/onekey/nativeoverlay/NativeOverlayEntryRootView.kt +60 -0
  3. package/android/src/main/java/com/onekey/nativeoverlay/NativeOverlayHost.kt +37 -5
  4. package/android/src/main/java/com/onekey/nativeoverlay/NativeOverlayPackage.kt +1 -1
  5. package/android/src/main/java/com/onekey/nativeoverlay/NativeOverlayToastCardView.kt +869 -0
  6. package/android/src/main/java/com/onekey/nativeoverlay/NativeOverlayToastSpec.kt +327 -0
  7. package/android/src/main/java/com/onekey/nativeoverlay/NativeOverlayToasterView.kt +574 -0
  8. package/android/src/main/java/com/onekey/nativeoverlay/NativeOverlayToasterViewManager.kt +54 -0
  9. package/android/src/main/java/com/onekey/nativeoverlay/NativeOverlayView.kt +12 -0
  10. package/android/src/main/java/com/onekey/nativeoverlay/NativeOverlayViewManager.kt +8 -0
  11. package/android/src/test/java/com/onekey/nativeoverlay/NativeOverlayAccessibilityIsolationTest.kt +172 -0
  12. package/android/src/test/java/com/onekey/nativeoverlay/NativeOverlayMotionTest.kt +42 -0
  13. package/android/src/test/java/com/onekey/nativeoverlay/NativeOverlaySheetInsetTest.kt +78 -0
  14. package/docs/SPEC.md +324 -33
  15. package/ios/NativeOverlayContainerView.swift +6 -0
  16. package/ios/NativeOverlayToastCardView.swift +572 -0
  17. package/ios/NativeOverlayToastSpec.swift +356 -0
  18. package/ios/NativeOverlayToasterView.swift +519 -0
  19. package/ios/NativeOverlayWindowManager.swift +244 -7
  20. package/ios/RCTNativeOverlayToasterComponentView.h +11 -0
  21. package/ios/RCTNativeOverlayToasterComponentView.mm +85 -0
  22. package/lib/module/NativeOverlayNativeComponent.ts +13 -0
  23. package/lib/module/NativeOverlayToasterNativeComponent.ts +24 -0
  24. package/lib/module/OverlayView.js +7 -1
  25. package/lib/module/OverlayView.js.map +1 -1
  26. package/lib/module/animation/anchoredOrigin.js +26 -0
  27. package/lib/module/animation/anchoredOrigin.js.map +1 -0
  28. package/lib/module/animation/resolveAnimation.js +26 -4
  29. package/lib/module/animation/resolveAnimation.js.map +1 -1
  30. package/lib/module/index.js +3 -0
  31. package/lib/module/index.js.map +1 -1
  32. package/lib/module/toast/OverlayToastHost.js +42 -0
  33. package/lib/module/toast/OverlayToastHost.js.map +1 -0
  34. package/lib/module/toast/OverlayToastHost.web.js +32 -0
  35. package/lib/module/toast/OverlayToastHost.web.js.map +1 -0
  36. package/lib/module/toast/OverlayToastStore.js +217 -0
  37. package/lib/module/toast/OverlayToastStore.js.map +1 -0
  38. package/lib/module/toast/toastBridge.js +65 -0
  39. package/lib/module/toast/toastBridge.js.map +1 -0
  40. package/lib/module/toast/toastDomContent.web.js +298 -0
  41. package/lib/module/toast/toastDomContent.web.js.map +1 -0
  42. package/lib/module/toast/toastDomRenderer.web.js +695 -0
  43. package/lib/module/toast/toastDomRenderer.web.js.map +1 -0
  44. package/lib/module/toast/toastStyles.web.js +97 -0
  45. package/lib/module/toast/toastStyles.web.js.map +1 -0
  46. package/lib/module/toast/types.js +2 -0
  47. package/lib/module/toast/types.js.map +1 -0
  48. package/lib/module/web/animateTransition.js +38 -12
  49. package/lib/module/web/animateTransition.js.map +1 -1
  50. package/lib/module/web/overlayLayers.js +5 -0
  51. package/lib/module/web/overlayLayers.js.map +1 -1
  52. package/lib/typescript/src/NativeOverlayNativeComponent.d.ts +13 -0
  53. package/lib/typescript/src/NativeOverlayNativeComponent.d.ts.map +1 -1
  54. package/lib/typescript/src/NativeOverlayToasterNativeComponent.d.ts +19 -0
  55. package/lib/typescript/src/NativeOverlayToasterNativeComponent.d.ts.map +1 -0
  56. package/lib/typescript/src/OverlayView.d.ts.map +1 -1
  57. package/lib/typescript/src/animation/anchoredOrigin.d.ts +7 -0
  58. package/lib/typescript/src/animation/anchoredOrigin.d.ts.map +1 -0
  59. package/lib/typescript/src/animation/resolveAnimation.d.ts +9 -3
  60. package/lib/typescript/src/animation/resolveAnimation.d.ts.map +1 -1
  61. package/lib/typescript/src/animation/types.d.ts +5 -1
  62. package/lib/typescript/src/animation/types.d.ts.map +1 -1
  63. package/lib/typescript/src/index.d.ts +5 -0
  64. package/lib/typescript/src/index.d.ts.map +1 -1
  65. package/lib/typescript/src/toast/OverlayToastHost.d.ts +6 -0
  66. package/lib/typescript/src/toast/OverlayToastHost.d.ts.map +1 -0
  67. package/lib/typescript/src/toast/OverlayToastHost.web.d.ts +6 -0
  68. package/lib/typescript/src/toast/OverlayToastHost.web.d.ts.map +1 -0
  69. package/lib/typescript/src/toast/OverlayToastStore.d.ts +47 -0
  70. package/lib/typescript/src/toast/OverlayToastStore.d.ts.map +1 -0
  71. package/lib/typescript/src/toast/toastBridge.d.ts +11 -0
  72. package/lib/typescript/src/toast/toastBridge.d.ts.map +1 -0
  73. package/lib/typescript/src/toast/toastDomContent.web.d.ts +15 -0
  74. package/lib/typescript/src/toast/toastDomContent.web.d.ts.map +1 -0
  75. package/lib/typescript/src/toast/toastDomRenderer.web.d.ts +8 -0
  76. package/lib/typescript/src/toast/toastDomRenderer.web.d.ts.map +1 -0
  77. package/lib/typescript/src/toast/toastStyles.web.d.ts +2 -0
  78. package/lib/typescript/src/toast/toastStyles.web.d.ts.map +1 -0
  79. package/lib/typescript/src/toast/types.d.ts +240 -0
  80. package/lib/typescript/src/toast/types.d.ts.map +1 -0
  81. package/lib/typescript/src/web/animateTransition.d.ts +12 -0
  82. package/lib/typescript/src/web/animateTransition.d.ts.map +1 -1
  83. package/lib/typescript/src/web/overlayLayers.d.ts.map +1 -1
  84. package/package.json +3 -2
  85. package/react-native.config.js +1 -0
  86. package/src/NativeOverlayNativeComponent.ts +13 -0
  87. package/src/NativeOverlayToasterNativeComponent.ts +24 -0
  88. package/src/OverlayView.tsx +7 -0
  89. package/src/animation/anchoredOrigin.ts +35 -0
  90. package/src/animation/resolveAnimation.ts +28 -7
  91. package/src/animation/types.ts +5 -1
  92. package/src/index.ts +24 -0
  93. package/src/toast/OverlayToastHost.tsx +62 -0
  94. package/src/toast/OverlayToastHost.web.tsx +29 -0
  95. package/src/toast/OverlayToastStore.ts +254 -0
  96. package/src/toast/toastBridge.ts +62 -0
  97. package/src/toast/toastDomContent.web.ts +351 -0
  98. package/src/toast/toastDomRenderer.web.ts +856 -0
  99. package/src/toast/toastStyles.web.ts +97 -0
  100. package/src/toast/types.ts +251 -0
  101. package/src/web/animateTransition.ts +54 -14
  102. package/src/web/overlayLayers.ts +7 -0
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+
3
+ import { useCallback, useEffect, useMemo, useSyncExternalStore } from 'react';
4
+ import { StyleSheet } from 'react-native';
5
+ import NativeOverlayToaster from '../NativeOverlayToasterNativeComponent';
6
+ import { overlayToastStore } from "./OverlayToastStore.js";
7
+ import { serializeToastItems, toToastEvent } from "./toastBridge.js";
8
+ import { jsx as _jsx } from "react/jsx-runtime";
9
+ const styles = StyleSheet.create({
10
+ // The host only carries data to the platform; the cards are drawn in the
11
+ // native `toast` overlay level, not inside this view.
12
+ host: {
13
+ position: 'absolute',
14
+ width: 0,
15
+ height: 0
16
+ }
17
+ });
18
+
19
+ /**
20
+ * Hands the toast list to the platform renderer for as long as it is mounted.
21
+ * It draws nothing itself.
22
+ */
23
+ export function OverlayToastHost() {
24
+ const snapshot = useSyncExternalStore(overlayToastStore.subscribe, overlayToastStore.getSnapshot, overlayToastStore.getSnapshot);
25
+ useEffect(() => overlayToastStore.attachRenderer(), []);
26
+ const toasts = useMemo(() => serializeToastItems(snapshot.items), [snapshot.items]);
27
+ const config = useMemo(() => JSON.stringify(snapshot.config), [snapshot.config]);
28
+ const handleToastEvent = useCallback(event => {
29
+ const toastEvent = toToastEvent(event.nativeEvent);
30
+ if (toastEvent) {
31
+ overlayToastStore.handleEvent(toastEvent);
32
+ }
33
+ }, []);
34
+ return /*#__PURE__*/_jsx(NativeOverlayToaster, {
35
+ toasts: toasts,
36
+ config: config,
37
+ onToastEvent: handleToastEvent,
38
+ pointerEvents: "none",
39
+ style: styles.host
40
+ });
41
+ }
42
+ //# sourceMappingURL=OverlayToastHost.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["useCallback","useEffect","useMemo","useSyncExternalStore","StyleSheet","NativeOverlayToaster","overlayToastStore","serializeToastItems","toToastEvent","jsx","_jsx","styles","create","host","position","width","height","OverlayToastHost","snapshot","subscribe","getSnapshot","attachRenderer","toasts","items","config","JSON","stringify","handleToastEvent","event","toastEvent","nativeEvent","handleEvent","onToastEvent","pointerEvents","style"],"sourceRoot":"../../../src","sources":["toast/OverlayToastHost.tsx"],"mappings":";;AAAA,SAASA,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,oBAAoB,QAAQ,OAAO;AAE7E,SAASC,UAAU,QAAQ,cAAc;AAEzC,OAAOC,oBAAoB,MAAM,wCAAwC;AAEzE,SAASC,iBAAiB,QAAQ,wBAAqB;AACvD,SAASC,mBAAmB,EAAEC,YAAY,QAAQ,kBAAe;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAIlE,MAAMC,MAAM,GAAGP,UAAU,CAACQ,MAAM,CAAC;EAC/B;EACA;EACAC,IAAI,EAAE;IAAEC,QAAQ,EAAE,UAAU;IAAEC,KAAK,EAAE,CAAC;IAAEC,MAAM,EAAE;EAAE;AACpD,CAAC,CAAC;;AAEF;AACA;AACA;AACA;AACA,OAAO,SAASC,gBAAgBA,CAAA,EAAG;EACjC,MAAMC,QAAQ,GAAGf,oBAAoB,CACnCG,iBAAiB,CAACa,SAAS,EAC3Bb,iBAAiB,CAACc,WAAW,EAC7Bd,iBAAiB,CAACc,WACpB,CAAC;EACDnB,SAAS,CAAC,MAAMK,iBAAiB,CAACe,cAAc,CAAC,CAAC,EAAE,EAAE,CAAC;EACvD,MAAMC,MAAM,GAAGpB,OAAO,CACpB,MAAMK,mBAAmB,CAACW,QAAQ,CAACK,KAAK,CAAC,EACzC,CAACL,QAAQ,CAACK,KAAK,CACjB,CAAC;EACD,MAAMC,MAAM,GAAGtB,OAAO,CACpB,MAAMuB,IAAI,CAACC,SAAS,CAACR,QAAQ,CAACM,MAAM,CAAC,EACrC,CAACN,QAAQ,CAACM,MAAM,CAClB,CAAC;EACD,MAAMG,gBAAgB,GAAG3B,WAAW,CAEhC4B,KAKE,IACC;IACH,MAAMC,UAAU,GAAGrB,YAAY,CAACoB,KAAK,CAACE,WAAW,CAAC;IAClD,IAAID,UAAU,EAAE;MACdvB,iBAAiB,CAACyB,WAAW,CAACF,UAAU,CAAC;IAC3C;EACF,CAAC,EACD,EACF,CAAC;EACD,oBACEnB,IAAA,CAACL,oBAAoB;IACnBiB,MAAM,EAAEA,MAAO;IACfE,MAAM,EAAEA,MAAO;IACfQ,YAAY,EAAEL,gBAAiB;IAC/BM,aAAa,EAAC,MAAM;IACpBC,KAAK,EAAEvB,MAAM,CAACE;EAAK,CACpB,CAAC;AAEN","ignoreList":[]}
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+
3
+ import { useEffect } from 'react';
4
+ import { overlayToastStore } from "./OverlayToastStore.js";
5
+ import { createToastDomRenderer } from "./toastDomRenderer.web.js";
6
+
7
+ /**
8
+ * Attaches the DOM toast renderer for as long as it is mounted. It renders no
9
+ * React output: the renderer draws straight into the `toast` overlay layer.
10
+ */
11
+ export function OverlayToastHost() {
12
+ useEffect(() => {
13
+ const renderer = createToastDomRenderer(event => overlayToastStore.handleEvent(event));
14
+ const detach = overlayToastStore.attachRenderer();
15
+ const sync = () => {
16
+ const {
17
+ items,
18
+ config
19
+ } = overlayToastStore.getSnapshot();
20
+ renderer.sync(items, config);
21
+ };
22
+ sync();
23
+ const unsubscribe = overlayToastStore.subscribe(sync);
24
+ return () => {
25
+ unsubscribe();
26
+ renderer.destroy();
27
+ detach();
28
+ };
29
+ }, []);
30
+ return null;
31
+ }
32
+ //# sourceMappingURL=OverlayToastHost.web.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["useEffect","overlayToastStore","createToastDomRenderer","OverlayToastHost","renderer","event","handleEvent","detach","attachRenderer","sync","items","config","getSnapshot","unsubscribe","subscribe","destroy"],"sourceRoot":"../../../src","sources":["toast/OverlayToastHost.web.tsx"],"mappings":";;AAAA,SAASA,SAAS,QAAQ,OAAO;AAEjC,SAASC,iBAAiB,QAAQ,wBAAqB;AACvD,SAASC,sBAAsB,QAAQ,2BAAwB;;AAE/D;AACA;AACA;AACA;AACA,OAAO,SAASC,gBAAgBA,CAAA,EAAG;EACjCH,SAAS,CAAC,MAAM;IACd,MAAMI,QAAQ,GAAGF,sBAAsB,CAAEG,KAAK,IAC5CJ,iBAAiB,CAACK,WAAW,CAACD,KAAK,CACrC,CAAC;IACD,MAAME,MAAM,GAAGN,iBAAiB,CAACO,cAAc,CAAC,CAAC;IACjD,MAAMC,IAAI,GAAGA,CAAA,KAAM;MACjB,MAAM;QAAEC,KAAK;QAAEC;MAAO,CAAC,GAAGV,iBAAiB,CAACW,WAAW,CAAC,CAAC;MACzDR,QAAQ,CAACK,IAAI,CAACC,KAAK,EAAEC,MAAM,CAAC;IAC9B,CAAC;IACDF,IAAI,CAAC,CAAC;IACN,MAAMI,WAAW,GAAGZ,iBAAiB,CAACa,SAAS,CAACL,IAAI,CAAC;IACrD,OAAO,MAAM;MACXI,WAAW,CAAC,CAAC;MACbT,QAAQ,CAACW,OAAO,CAAC,CAAC;MAClBR,MAAM,CAAC,CAAC;IACV,CAAC;EACH,CAAC,EAAE,EAAE,CAAC;EACN,OAAO,IAAI;AACb","ignoreList":[]}
@@ -0,0 +1,217 @@
1
+ "use strict";
2
+
3
+ /** Toasts beyond this many are dropped oldest first. */
4
+ const TOAST_LIMIT = 20;
5
+
6
+ /**
7
+ * The single source of truth for message toasts. Callers push data in; a
8
+ * platform renderer (attached by `OverlayToastHost`) draws it and reports
9
+ * what happened to each card through `handleEvent`.
10
+ *
11
+ * A toast leaves the list only when its renderer reports `close`, so the exit
12
+ * animation always has a card to play on. With no renderer attached there is
13
+ * no animation to wait for and a dismissal removes the toast at once.
14
+ */
15
+ export class OverlayToastStore {
16
+ items = [];
17
+ config = {};
18
+ snapshot = {
19
+ items: [],
20
+ config: {}
21
+ };
22
+ handlers = new Map();
23
+ dismissReasons = new Map();
24
+ listeners = new Set();
25
+ renderers = 0;
26
+ nextId = 0;
27
+ nextGeneration = 0;
28
+ getSnapshot = () => this.snapshot;
29
+ subscribe = listener => {
30
+ this.listeners.add(listener);
31
+ return () => {
32
+ this.listeners.delete(listener);
33
+ };
34
+ };
35
+
36
+ /** A renderer is drawing the list; returns its detach function. */
37
+ attachRenderer() {
38
+ this.renderers += 1;
39
+ let attached = true;
40
+ return () => {
41
+ if (!attached) {
42
+ return;
43
+ }
44
+ attached = false;
45
+ this.renderers -= 1;
46
+ if (this.renderers === 0) {
47
+ // Nothing can report `close` any more: finish pending exits.
48
+ this.items.filter(item => !item.visible).forEach(item => this.remove(item.spec.id, this.dismissReasons.get(item.spec.id) ?? 'programmatic'));
49
+ }
50
+ };
51
+ }
52
+ createId() {
53
+ this.nextId += 1;
54
+ return `overlay-toast-${this.nextId}`;
55
+ }
56
+ show(spec, handlers = {}) {
57
+ const {
58
+ id
59
+ } = spec;
60
+ const generation = this.nextGeneration;
61
+ this.nextGeneration += 1;
62
+ const existing = this.items.find(item => item.spec.id === id);
63
+ this.handlers.set(id, handlers);
64
+ this.dismissReasons.delete(id);
65
+ if (existing) {
66
+ this.items = this.items.map(item => item === existing ? {
67
+ spec,
68
+ visible: true,
69
+ revision: item.revision + 1,
70
+ generation
71
+ } : item);
72
+ } else {
73
+ this.items = [{
74
+ spec,
75
+ visible: true,
76
+ revision: 0,
77
+ generation
78
+ }, ...this.items];
79
+ // Past the limit the oldest toasts leave without an animation, as the
80
+ // list they came from did.
81
+ this.items.slice(TOAST_LIMIT).forEach(item => {
82
+ this.handlers.delete(item.spec.id);
83
+ this.dismissReasons.delete(item.spec.id);
84
+ });
85
+ this.items = this.items.slice(0, TOAST_LIMIT);
86
+ }
87
+ this.emit();
88
+ return {
89
+ id,
90
+ dismiss: () => this.dismiss(id)
91
+ };
92
+ }
93
+
94
+ /**
95
+ * Redraws a toast that is on screen with a new spec (a theme or layout
96
+ * change) without restarting its lifetime. Unknown or leaving ids are
97
+ * ignored.
98
+ */
99
+ update(spec) {
100
+ const existing = this.items.find(item => item.spec.id === spec.id);
101
+ if (!existing || !existing.visible) {
102
+ return;
103
+ }
104
+ this.items = this.items.map(item => item === existing ? {
105
+ ...item,
106
+ spec,
107
+ revision: item.revision + 1
108
+ } : item);
109
+ this.emit();
110
+ }
111
+ dismiss(id) {
112
+ const item = this.items.find(entry => entry.spec.id === id);
113
+ if (!item || !item.visible) {
114
+ return;
115
+ }
116
+ this.items = this.items.map(entry => entry === item ? {
117
+ ...entry,
118
+ visible: false
119
+ } : entry);
120
+ this.dismissReasons.set(id, 'programmatic');
121
+ this.handlers.get(id)?.onDismiss?.('programmatic');
122
+ if (this.renderers === 0) {
123
+ this.remove(id, 'programmatic');
124
+ return;
125
+ }
126
+ this.emit();
127
+ }
128
+ dismissAll() {
129
+ this.items.map(item => item.spec.id).forEach(id => this.dismiss(id));
130
+ }
131
+ configure(config) {
132
+ const next = {
133
+ ...this.config,
134
+ ...config
135
+ };
136
+ const keys = Object.keys(next);
137
+ if (keys.every(key => next[key] === this.config[key])) {
138
+ return;
139
+ }
140
+ this.config = next;
141
+ this.emit();
142
+ }
143
+
144
+ /** Renderer → store. */
145
+ handleEvent(event) {
146
+ const item = this.items.find(entry => entry.spec.id === event.id);
147
+ if (!item || event.generation !== undefined && event.generation !== item.generation) {
148
+ return;
149
+ }
150
+ const handlers = this.handlers.get(event.id);
151
+ switch (event.type) {
152
+ case 'dismiss':
153
+ {
154
+ if (!item.visible) {
155
+ // A caller already dismissed it and was told so.
156
+ return;
157
+ }
158
+ this.items = this.items.map(entry => entry === item ? {
159
+ ...entry,
160
+ visible: false
161
+ } : entry);
162
+ this.dismissReasons.set(event.id, event.reason);
163
+ handlers?.onDismiss?.(event.reason);
164
+ this.emit();
165
+ return;
166
+ }
167
+ case 'close':
168
+ this.remove(event.id, event.reason, event.generation);
169
+ return;
170
+ case 'action':
171
+ if (!item.visible) {
172
+ return;
173
+ }
174
+ handlers?.onAction?.(event.actionId);
175
+ return;
176
+ case 'link':
177
+ if (!item.visible) {
178
+ return;
179
+ }
180
+ handlers?.onLink?.(event.link);
181
+ return;
182
+ case 'press':
183
+ if (!item.visible) {
184
+ return;
185
+ }
186
+ handlers?.onPress?.();
187
+ return;
188
+ default:
189
+ }
190
+ }
191
+ remove(id, reason, generation) {
192
+ const item = this.items.find(entry => entry.spec.id === id);
193
+ if (!item) {
194
+ return;
195
+ }
196
+ // A toast shown again under the same id while its predecessor was
197
+ // leaving stays: the renderer's `close` belongs to the old card.
198
+ if (item.visible || generation !== undefined && generation !== item.generation) {
199
+ return;
200
+ }
201
+ const handlers = this.handlers.get(id);
202
+ this.handlers.delete(id);
203
+ this.dismissReasons.delete(id);
204
+ this.items = this.items.filter(entry => entry !== item);
205
+ this.emit();
206
+ handlers?.onClose?.(reason);
207
+ }
208
+ emit() {
209
+ this.snapshot = {
210
+ items: this.items,
211
+ config: this.config
212
+ };
213
+ this.listeners.forEach(listener => listener());
214
+ }
215
+ }
216
+ export const overlayToastStore = new OverlayToastStore();
217
+ //# sourceMappingURL=OverlayToastStore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["TOAST_LIMIT","OverlayToastStore","items","config","snapshot","handlers","Map","dismissReasons","listeners","Set","renderers","nextId","nextGeneration","getSnapshot","subscribe","listener","add","delete","attachRenderer","attached","filter","item","visible","forEach","remove","spec","id","get","createId","show","generation","existing","find","set","map","revision","slice","emit","dismiss","update","entry","onDismiss","dismissAll","configure","next","keys","Object","every","key","handleEvent","event","undefined","type","reason","onAction","actionId","onLink","link","onPress","onClose","overlayToastStore"],"sourceRoot":"../../../src","sources":["toast/OverlayToastStore.ts"],"mappings":";;AAgBA;AACA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AMA,CACZE,EAAU,EACV2B,MAAkC,EAClCvB,UAAmB,EACb;IACN,MAAMT,IAAI,GAAG,IAAI,CAACnB,KAAK,CAAC8B,IAAI,CAAEQ,KAAK,IAAKA,KAAK,CAACf,IAAI,CAACC,EAAE,KAAKA,EAAE,CAAC;IAC7D,IAAI,CAACL,IAAI,EAAE;MACT;IACF;IACA;IACA;IACA,IACEA,IAAI,CAACC,OAAO,IACXQ,UAAU,KAAKqB,SAAS,IAAIrB,UAAU,KAAKT,IAAI,CAACS,UAAW,EAC5D;MACA;IACF;IACA,MAAMzB,QAAQ,GAAG,IAAI,CAACA,QAAQ,CAACsB,GAAG,CAACD,EAAE,CAAC;IACtC,IAAI,CAACrB,QAAQ,CAACY,MAAM,CAACS,EAAE,CAAC;IACxB,IAAI,CAACnB,cAAc,CAACU,MAAM,CAACS,EAAE,CAAC;IAC9B,IAAI,CAACxB,KAAK,GAAG,IAAI,CAACA,KAAK,CAACkB,MAAM,CAAEoB,KAAK,IAAKA,KAAK,KAAKnB,IAAI,CAAC;IACzD,IAAI,CAACgB,IAAI,CAAC,CAAC;IACXhC,QAAQ,EAAEsD,OAAO,GAAGN,MAAM,CAAC;EAC7B;EAEQhB,IAAIA,CAAA,EAAS;IACnB,IAAI,CAACjC,QAAQ,GAAG;MAAEF,KAAK,EAAE,IAAI,CAACA,KAAK;MAAEC,MAAM,EAAE,IAAI,CAACA;IAAO,CAAC;IAC1D,IAAI,CAACK,SAAS,CAACe,OAAO,CAAER,QAAQ,IAAKA,QAAQ,CAAC,CAAC,CAAC;EAClD;AACF;AAEA,OAAO,MAAM6C,iBAAiB,GAAG,IAAI3D,iBAAiB,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+
3
+ /** How a toast that never times out crosses the bridge: JSON has no Infinity. */
4
+ export const TOAST_DURATION_INFINITE = -1;
5
+ const DISMISS_REASONS = ['timeout', 'swipe', 'close', 'programmatic'];
6
+ export function serializeToastItems(items) {
7
+ return JSON.stringify(items.map(item => ({
8
+ ...item,
9
+ spec: {
10
+ ...item.spec,
11
+ duration: Number.isFinite(item.spec.duration) ? item.spec.duration : TOAST_DURATION_INFINITE
12
+ }
13
+ })));
14
+ }
15
+ function toDismissReason(value) {
16
+ return DISMISS_REASONS.find(reason => reason === value) ?? 'programmatic';
17
+ }
18
+ export function toToastEvent(native) {
19
+ const {
20
+ toastId: id,
21
+ generation,
22
+ type,
23
+ value
24
+ } = native;
25
+ const base = typeof generation === 'number' && Number.isFinite(generation) ? {
26
+ id,
27
+ generation
28
+ } : {
29
+ id
30
+ };
31
+ switch (type) {
32
+ case 'dismiss':
33
+ return {
34
+ ...base,
35
+ type,
36
+ reason: toDismissReason(value)
37
+ };
38
+ case 'close':
39
+ return {
40
+ ...base,
41
+ type,
42
+ reason: toDismissReason(value)
43
+ };
44
+ case 'action':
45
+ return {
46
+ ...base,
47
+ type,
48
+ actionId: value
49
+ };
50
+ case 'link':
51
+ return {
52
+ ...base,
53
+ type,
54
+ link: value
55
+ };
56
+ case 'press':
57
+ return {
58
+ ...base,
59
+ type
60
+ };
61
+ default:
62
+ return undefined;
63
+ }
64
+ }
65
+ //# sourceMappingURL=toastBridge.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["TOAST_DURATION_INFINITE","DISMISS_REASONS","serializeToastItems","items","JSON","stringify","map","item","spec","duration","Number","isFinite","toDismissReason","value","find","reason","toToastEvent","native","toastId","id","generation","type","base","actionId","link","undefined"],"sourceRoot":"../../../src","sources":["toast/toastBridge.ts"],"mappings":";;AAMA;AACA,OAAO,MAAMA,uBAAuB,GAAG,CAAC,CAAC;AAEzC,MAAMC,eAAsD,GAAG,CAC7D,SAAS,EACT,OAAO,EACP,OAAO,EACP,cAAc,CACf;AAED,OAAO,SAASC,mBAAmBA,CACjCC,KAAmC,EAC3B;EACR,OAAOC,IAAI,CAACC,SAAS,CACnBF,KAAK,CAACG,GAAG,CAAEC,IAAI,KAAM;IACnB,GAAGA,IAAI;IAC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3
+ /* cspell:ignore dasharray dashoffset */
4
+
5
+ const SVG_NS = 'http://www.w3.org/2000/svg';
6
+
7
+ // The card geometry of the layouts this replaces.
8
+ const MESSAGE_ICON_GAP = 8;
9
+ const MESSAGE_TEXT_GAP = 4;
10
+ const NOTIFICATION_GAP = 8;
11
+ const NOTIFICATION_TEXT_GAP = 2;
12
+ const ACTIONS_PADDING_TOP = 12;
13
+ const ACTIONS_PADDING_END = 2;
14
+ const ACTIONS_PADDING_BOTTOM = 2;
15
+ function element(tag, marker) {
16
+ const node = document.createElement(tag);
17
+ node.setAttribute(marker, '');
18
+ return node;
19
+ }
20
+ function createIcon(icon) {
21
+ if (icon.kind === 'image') {
22
+ const image = document.createElement('img');
23
+ image.setAttribute('data-okt-image', '');
24
+ image.src = icon.uri;
25
+ image.alt = '';
26
+ image.draggable = false;
27
+ image.width = icon.size;
28
+ image.height = icon.size;
29
+ image.style.width = `${icon.size}px`;
30
+ image.style.height = `${icon.size}px`;
31
+ if (icon.borderRadius) {
32
+ image.style.borderRadius = `${icon.borderRadius}px`;
33
+ }
34
+ return image;
35
+ }
36
+ const svg = document.createElementNS(SVG_NS, 'svg');
37
+ svg.setAttribute('width', String(icon.size));
38
+ svg.setAttribute('height', String(icon.size));
39
+ svg.setAttribute('aria-hidden', 'true');
40
+ svg.setAttribute('focusable', 'false');
41
+ svg.style.color = icon.color;
42
+ if (icon.kind === 'spinner') {
43
+ // The indeterminate ring of the activity indicator this replaces.
44
+ svg.setAttribute('data-okt-spinner', '');
45
+ svg.style.color = '';
46
+ svg.setAttribute('viewBox', '0 0 32 32');
47
+ const track = document.createElementNS(SVG_NS, 'circle');
48
+ const arc = document.createElementNS(SVG_NS, 'circle');
49
+ [track, arc].forEach(circle => {
50
+ circle.setAttribute('cx', '16');
51
+ circle.setAttribute('cy', '16');
52
+ circle.setAttribute('r', '14');
53
+ circle.setAttribute('fill', 'none');
54
+ circle.setAttribute('stroke-width', '4');
55
+ circle.style.stroke = icon.color;
56
+ });
57
+ track.style.opacity = '0.2';
58
+ arc.style.strokeDasharray = '80';
59
+ arc.style.strokeDashoffset = '60';
60
+ svg.append(track, arc);
61
+ return svg;
62
+ }
63
+ svg.setAttribute('data-okt-icon', '');
64
+ if (icon.href) {
65
+ const use = document.createElementNS(SVG_NS, 'use');
66
+ use.setAttribute('href', icon.href);
67
+ svg.append(use);
68
+ }
69
+ return svg;
70
+ }
71
+ function applyRunStyle(node, run) {
72
+ if (run.color) {
73
+ node.style.color = run.color;
74
+ }
75
+ if (run.fontWeight) {
76
+ node.style.fontWeight = run.fontWeight;
77
+ }
78
+ if (run.fontSize !== undefined) {
79
+ node.style.fontSize = `${run.fontSize}px`;
80
+ }
81
+ if (run.underline) {
82
+ node.style.textDecorationLine = 'underline';
83
+ }
84
+ }
85
+ function isPlainRun(run) {
86
+ return !run.color && !run.fontWeight && run.fontSize === undefined && !run.underline && run.link === undefined;
87
+ }
88
+ function createParagraph(text, runs, emit) {
89
+ const paragraph = element('span', 'data-okt-text');
90
+ paragraph.style.color = text.color;
91
+ paragraph.style.fontSize = `${text.fontSize}px`;
92
+ paragraph.style.lineHeight = `${text.lineHeight}px`;
93
+ paragraph.style.fontWeight = text.fontWeight;
94
+ if (text.fontFamily) {
95
+ paragraph.style.fontFamily = text.fontFamily;
96
+ }
97
+ if (text.letterSpacing !== undefined) {
98
+ paragraph.style.letterSpacing = `${text.letterSpacing}px`;
99
+ }
100
+ if (text.selectable) {
101
+ paragraph.setAttribute('data-okt-selectable', '');
102
+ }
103
+ if (text.tabularNumbers) {
104
+ paragraph.style.fontVariantNumeric = 'tabular-nums';
105
+ }
106
+ if (text.linkHoverColor) {
107
+ paragraph.style.setProperty('--okt-link-hover', text.linkHoverColor);
108
+ }
109
+ if (text.linkPressedColor) {
110
+ paragraph.style.setProperty('--okt-link-active', text.linkPressedColor);
111
+ }
112
+ if (text.numberOfLines) {
113
+ paragraph.setAttribute('data-okt-clamp', '');
114
+ paragraph.style.setProperty('-webkit-line-clamp', String(text.numberOfLines));
115
+ }
116
+ runs.forEach(run => {
117
+ if (isPlainRun(run)) {
118
+ paragraph.append(document.createTextNode(run.text));
119
+ return;
120
+ }
121
+ const span = element('span', 'data-okt-text');
122
+ span.textContent = run.text;
123
+ applyRunStyle(span, run);
124
+ const {
125
+ link
126
+ } = run;
127
+ if (link !== undefined) {
128
+ span.setAttribute('data-okt-link', '');
129
+ span.setAttribute('role', 'link');
130
+ span.tabIndex = 0;
131
+ const open = event => {
132
+ event.stopPropagation();
133
+ emit({
134
+ type: 'link',
135
+ link
136
+ });
137
+ };
138
+ span.addEventListener('click', open);
139
+ span.addEventListener('keydown', event => {
140
+ if (event.key === 'Enter') {
141
+ open(event);
142
+ }
143
+ });
144
+ }
145
+ paragraph.append(span);
146
+ });
147
+ return paragraph;
148
+ }
149
+ function createParagraphs(text, emit) {
150
+ const container = element('div', 'data-okt-paragraphs');
151
+ text.paragraphs.forEach(runs => container.append(createParagraph(text, runs, emit)));
152
+ return container;
153
+ }
154
+ function createAction(action, emit) {
155
+ const button = document.createElement('button');
156
+ button.type = 'button';
157
+ button.setAttribute('data-okt-action', '');
158
+ if (action.testID) {
159
+ button.setAttribute('data-testid', action.testID);
160
+ }
161
+ if (action.icon) {
162
+ const icon = createIcon(action.icon);
163
+ icon.style.marginRight = `${action.iconGap ?? 0}px`;
164
+ button.append(icon);
165
+ }
166
+ button.append(document.createTextNode(action.label));
167
+ button.disabled = !!action.disabled;
168
+ const {
169
+ style
170
+ } = button;
171
+ style.setProperty('--okt-action-bg', action.backgroundColor);
172
+ if (action.hoverBackgroundColor) {
173
+ style.setProperty('--okt-action-hover', action.hoverBackgroundColor);
174
+ }
175
+ if (action.pressedBackgroundColor) {
176
+ style.setProperty('--okt-action-active', action.pressedBackgroundColor);
177
+ }
178
+ if (action.focusRingColor) {
179
+ style.setProperty('--okt-action-ring', action.focusRingColor);
180
+ }
181
+ style.color = action.color;
182
+ style.fontSize = `${action.fontSize}px`;
183
+ style.lineHeight = `${action.lineHeight}px`;
184
+ style.fontWeight = action.fontWeight;
185
+ if (action.fontFamily) {
186
+ style.fontFamily = action.fontFamily;
187
+ }
188
+ style.padding = `${action.paddingVertical}px ${action.paddingHorizontal}px`;
189
+ style.borderRadius = `${action.borderRadius}px`;
190
+ style.borderWidth = `${action.borderWidth ?? 0}px`;
191
+ if (action.marginHorizontal || action.marginVertical) {
192
+ style.margin = `${action.marginVertical ?? 0}px ${action.marginHorizontal ?? 0}px`;
193
+ }
194
+ if (action.disabled && action.disabledOpacity !== undefined) {
195
+ style.opacity = String(action.disabledOpacity);
196
+ }
197
+ button.addEventListener('click', event => {
198
+ // A press on an action never reaches the row under it.
199
+ event.stopPropagation();
200
+ if (!action.disabled) {
201
+ emit({
202
+ type: 'action',
203
+ actionId: action.id
204
+ });
205
+ }
206
+ });
207
+ return button;
208
+ }
209
+ function createActions(actions, align, padding, emit) {
210
+ const row = element('div', 'data-okt-actions');
211
+ row.style.justifyContent = align === 'left' ? 'flex-start' : 'flex-end';
212
+ row.style.padding = padding;
213
+ actions.forEach(action => row.append(createAction(action, emit)));
214
+ return row;
215
+ }
216
+
217
+ /** Builds the body of one card. The caller owns the card element. */
218
+ export function buildToastContent(spec, emit) {
219
+ if (spec.layout === 'notification') {
220
+ const row = element('div', 'data-okt-row');
221
+ row.style.flex = '1 1 auto';
222
+ row.style.gap = `${NOTIFICATION_GAP}px`;
223
+ if (spec.pressable) {
224
+ row.setAttribute('data-okt-pressable', '');
225
+ row.setAttribute('role', 'button');
226
+ row.tabIndex = 0;
227
+ row.addEventListener('click', event => {
228
+ const target = event.target;
229
+ if (target?.closest?.('button, [data-okt-link]')) {
230
+ return;
231
+ }
232
+ emit({
233
+ type: 'press'
234
+ });
235
+ });
236
+ row.addEventListener('keydown', event => {
237
+ const target = event.target;
238
+ if (target && target !== row && target.closest?.('button, [data-okt-link]')) {
239
+ return;
240
+ }
241
+ if (event.key === 'Enter' || event.key === ' ') {
242
+ event.preventDefault();
243
+ emit({
244
+ type: 'press'
245
+ });
246
+ }
247
+ });
248
+ }
249
+ const badge = element('div', 'data-okt-badge');
250
+ badge.style.width = `${spec.badgeSize}px`;
251
+ badge.style.height = `${spec.badgeSize}px`;
252
+ badge.style.backgroundColor = spec.badgeColor;
253
+ badge.append(createIcon(spec.icon));
254
+ const column = element('div', 'data-okt-col');
255
+ column.style.gap = `${NOTIFICATION_TEXT_GAP}px`;
256
+ [spec.title, spec.message].forEach(text => {
257
+ if (text) {
258
+ text.paragraphs.forEach(runs => column.append(createParagraph(text, runs, emit)));
259
+ }
260
+ });
261
+ if (spec.actions?.length) {
262
+ column.append(createActions(spec.actions, spec.actionsAlign ?? 'right', `${ACTIONS_PADDING_TOP}px 0 0 0`, emit));
263
+ }
264
+ row.append(badge, column);
265
+ if (spec.image) {
266
+ row.append(createIcon({
267
+ kind: 'image',
268
+ uri: spec.image.uri,
269
+ size: spec.image.size,
270
+ borderRadius: spec.image.borderRadius
271
+ }));
272
+ }
273
+ return row;
274
+ }
275
+ const root = element('div', 'data-okt-root');
276
+ const row = element('div', 'data-okt-row');
277
+ if (spec.icon) {
278
+ row.style.gap = `${MESSAGE_ICON_GAP}px`;
279
+ const box = element('div', 'data-okt-icon-box');
280
+ box.append(createIcon(spec.icon));
281
+ row.append(box);
282
+ }
283
+ const column = element('div', 'data-okt-col');
284
+ column.style.gap = `${MESSAGE_TEXT_GAP}px`;
285
+ if (spec.title) {
286
+ column.append(createParagraphs(spec.title, emit));
287
+ }
288
+ if (spec.message) {
289
+ column.append(createParagraphs(spec.message, emit));
290
+ }
291
+ if (spec.actions?.length) {
292
+ column.append(createActions(spec.actions, spec.actionsAlign ?? 'right', `${ACTIONS_PADDING_TOP}px ${ACTIONS_PADDING_END}px ${ACTIONS_PADDING_BOTTOM}px 0`, emit));
293
+ }
294
+ row.append(column);
295
+ root.append(row);
296
+ return root;
297
+ }
298
+ //# sourceMappingURL=toastDomContent.web.js.map