@independo/capacitor-emoji-picker 1.0.2 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -5
- package/android/src/main/java/app/independo/capacitoremojipicker/EmojiPicker.java +3 -0
- package/android/src/main/java/app/independo/capacitoremojipicker/presenter/DefaultEmojiPickerDialogFactory.java +26 -6
- package/android/src/main/java/app/independo/capacitoremojipicker/presenter/DispatchingEmojiPickerPresenter.java +8 -2
- package/android/src/main/java/app/independo/capacitoremojipicker/presenter/EmojiPickerDialogFactory.java +1 -1
- package/android/src/main/java/app/independo/capacitoremojipicker/presenter/EmojiPickerPresenter.java +7 -1
- package/android/src/main/java/app/independo/capacitoremojipicker/presenter/NativeEmojiPickerPresenter.java +12 -5
- package/android/src/main/java/app/independo/capacitoremojipicker/presenter/WebFallbackEmojiPickerPresenter.java +20 -7
- package/android/src/main/java/app/independo/capacitoremojipicker/service/EmojiPickerService.java +8 -1
- package/dist/docs.json +33 -0
- package/dist/esm/definitions.d.ts +15 -0
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/platform/web/WebEmojiPickerPresenter.js +45 -7
- package/dist/esm/platform/web/WebEmojiPickerPresenter.js.map +1 -1
- package/dist/plugin.cjs.js +45 -7
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +45 -7
- package/dist/plugin.js.map +1 -1
- package/ios/Sources/EmojiPicker/Bridge/EmojiPicker.swift +4 -1
- package/ios/Sources/EmojiPicker/Presenter/DefaultEmojiKeyboardPresentationFactory.swift +42 -3
- package/ios/Sources/EmojiPicker/Presenter/EmojiKeyboardPresentationFactory.swift +1 -0
- package/ios/Sources/EmojiPicker/Presenter/EmojiPickerPresenter.swift +2 -0
- package/ios/Sources/EmojiPicker/Presenter/NativeEmojiPickerPresenter.swift +5 -1
- package/ios/Sources/EmojiPicker/Presenter/WebFallbackEmojiPickerPresenter.swift +10 -6
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -185,11 +185,12 @@ Result of presenting the emoji picker.
|
|
|
185
185
|
|
|
186
186
|
Options for presenting the emoji picker.
|
|
187
187
|
|
|
188
|
-
| Prop | Type | Description
|
|
189
|
-
| -------------------------- | --------------------------------------------------------------------------------------- |
|
|
190
|
-
| **`presentation`** | <code><a href="#emojipickerpresentation">EmojiPickerPresentation</a></code> | `auto`: prefer native/system UI and fall back to the web picker when native presentation is not available or fails. `web`: always use the web picker, including inside Capacitor native apps.
|
|
191
|
-
| **`closeButton`** | <code><a href="#emojipickerclosebuttonoptions">EmojiPickerCloseButtonOptions</a></code> | Configures the close button rendered above the iOS keyboard/the web picker sheet (iOS has no system-provided one). Ignored on Android.
|
|
192
|
-
| **`dismissOnBackdropTap`** | <code>boolean</code> | Dismiss the picker when the user taps the transparent area outside the keyboard/button (iOS) or the scrim outside the picker sheet (Android and web). On iOS and web, if `closeButton.hidden` is `true`, this is treated as `true` regardless of the value passed here, so the user always has a way to dismiss the picker.
|
|
188
|
+
| Prop | Type | Description | Default |
|
|
189
|
+
| -------------------------- | --------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- |
|
|
190
|
+
| **`presentation`** | <code><a href="#emojipickerpresentation">EmojiPickerPresentation</a></code> | `auto`: prefer native/system UI and fall back to the web picker when native presentation is not available or fails. `web`: always use the web picker, including inside Capacitor native apps. | <code>'auto'</code> |
|
|
191
|
+
| **`closeButton`** | <code><a href="#emojipickerclosebuttonoptions">EmojiPickerCloseButtonOptions</a></code> | Configures the close button rendered above the iOS keyboard/the web picker sheet (iOS has no system-provided one). Ignored on Android. | |
|
|
192
|
+
| **`dismissOnBackdropTap`** | <code>boolean</code> | Dismiss the picker when the user taps the transparent area outside the keyboard/button (iOS) or the scrim outside the picker sheet (Android and web). On iOS and web, if `closeButton.hidden` is `true`, this is treated as `true` regardless of the value passed here, so the user always has a way to dismiss the picker. | <code>true</code> |
|
|
193
|
+
| **`theme`** | <code><a href="#emojipickertheme">EmojiPickerTheme</a></code> | `system`: follows the OS/app appearance setting. `light` / `dark`: forces the picker's appearance regardless of the system setting. On iOS native presentation, this also sets `keyboardAppearance` on the underlying text input, which is the mechanism the system emoji keyboard itself honors (separate from the app's own `overrideUserInterfaceStyle`, which only themes the plugin's own overlay/close button). | <code>'system'</code> |
|
|
193
194
|
|
|
194
195
|
|
|
195
196
|
#### EmojiPickerCloseButtonOptions
|
|
@@ -212,6 +213,13 @@ How the picker should be presented.
|
|
|
212
213
|
|
|
213
214
|
<code>'auto' | 'web'</code>
|
|
214
215
|
|
|
216
|
+
|
|
217
|
+
#### EmojiPickerTheme
|
|
218
|
+
|
|
219
|
+
The picker's appearance.
|
|
220
|
+
|
|
221
|
+
<code>'system' | 'light' | 'dark'</code>
|
|
222
|
+
|
|
215
223
|
</docgen-api>
|
|
216
224
|
|
|
217
225
|
---
|
|
@@ -27,6 +27,7 @@ public class EmojiPicker extends Plugin {
|
|
|
27
27
|
new HashSet<>(Arrays.asList("xSmall", "small", "medium", "large"));
|
|
28
28
|
private static final Set<String> VALID_CLOSE_BUTTON_POSITIONS =
|
|
29
29
|
new HashSet<>(Arrays.asList("left", "center", "right"));
|
|
30
|
+
private static final Set<String> VALID_THEMES = new HashSet<>(Arrays.asList("system", "light", "dark"));
|
|
30
31
|
|
|
31
32
|
/** Service layer that owns presentation flow and concurrency guarding. */
|
|
32
33
|
private EmojiPickerService service;
|
|
@@ -60,10 +61,12 @@ public class EmojiPicker extends Plugin {
|
|
|
60
61
|
VALID_CLOSE_BUTTON_POSITIONS.contains(position) ? position : "right",
|
|
61
62
|
closeButtonObject != null && closeButtonObject.optBoolean("hidden", false)
|
|
62
63
|
);
|
|
64
|
+
String theme = call.getString("theme", "system");
|
|
63
65
|
service.present(
|
|
64
66
|
presentation,
|
|
65
67
|
dismissOnBackdropTap,
|
|
66
68
|
closeButton,
|
|
69
|
+
VALID_THEMES.contains(theme) ? theme : "system",
|
|
67
70
|
new EmojiPickerCallback() {
|
|
68
71
|
@Override
|
|
69
72
|
public void onResult(EmojiPickerResult result) {
|
|
@@ -9,13 +9,13 @@ import com.google.android.material.bottomsheet.BottomSheetDialog;
|
|
|
9
9
|
public class DefaultEmojiPickerDialogFactory implements EmojiPickerDialogFactory {
|
|
10
10
|
|
|
11
11
|
@Override
|
|
12
|
-
public EmojiPickerDialogHandle create(Activity activity, boolean dismissOnBackdropTap, Listener listener) {
|
|
13
|
-
BottomSheetDialog dialog = new BottomSheetDialog(
|
|
14
|
-
activity,
|
|
15
|
-
com.google.android.material.R.style.Theme_MaterialComponents_DayNight_BottomSheetDialog
|
|
16
|
-
);
|
|
12
|
+
public EmojiPickerDialogHandle create(Activity activity, boolean dismissOnBackdropTap, String theme, Listener listener) {
|
|
13
|
+
BottomSheetDialog dialog = new BottomSheetDialog(activity, resolveThemeResId(theme));
|
|
17
14
|
|
|
18
|
-
|
|
15
|
+
// Built from the dialog's own themed context (not `activity`) so it resolves colors
|
|
16
|
+
// against whichever theme variant `resolveThemeResId` picked, rather than the host app's
|
|
17
|
+
// own (potentially unrelated) theme.
|
|
18
|
+
EmojiPickerView pickerView = new EmojiPickerView(dialog.getContext());
|
|
19
19
|
pickerView.setLayoutParams(new ViewGroup.LayoutParams(
|
|
20
20
|
ViewGroup.LayoutParams.MATCH_PARENT,
|
|
21
21
|
ViewGroup.LayoutParams.MATCH_PARENT
|
|
@@ -32,4 +32,24 @@ public class DefaultEmojiPickerDialogFactory implements EmojiPickerDialogFactory
|
|
|
32
32
|
|
|
33
33
|
return dialog::dismiss;
|
|
34
34
|
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* `"light"`/`"dark"` pick Material's fixed (non-DayNight) theme variants directly, bypassing
|
|
38
|
+
* {@code Configuration.uiMode} entirely - an earlier attempt forced the night-mode bit via a
|
|
39
|
+
* wrapped/config-overridden {@code Context} instead, but that either broke the dialog's window
|
|
40
|
+
* token (when using {@code createConfigurationContext}, causing a `BadTokenException` on
|
|
41
|
+
* `show()`) or silently had no visible effect (when using a plain
|
|
42
|
+
* {@code ContextThemeWrapper#applyOverrideConfiguration}). Selecting the fixed theme resource
|
|
43
|
+
* directly has neither problem: `activity` is passed to `BottomSheetDialog` unmodified, and the
|
|
44
|
+
* chosen theme's colors don't depend on any night-qualifier resolution at all.
|
|
45
|
+
*/
|
|
46
|
+
private static int resolveThemeResId(String theme) {
|
|
47
|
+
if ("light".equals(theme)) {
|
|
48
|
+
return com.google.android.material.R.style.Theme_MaterialComponents_Light_BottomSheetDialog;
|
|
49
|
+
}
|
|
50
|
+
if ("dark".equals(theme)) {
|
|
51
|
+
return com.google.android.material.R.style.Theme_MaterialComponents_BottomSheetDialog;
|
|
52
|
+
}
|
|
53
|
+
return com.google.android.material.R.style.Theme_MaterialComponents_DayNight_BottomSheetDialog;
|
|
54
|
+
}
|
|
35
55
|
}
|
|
@@ -19,8 +19,14 @@ public class DispatchingEmojiPickerPresenter implements EmojiPickerPresenter {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
@Override
|
|
22
|
-
public void present(
|
|
22
|
+
public void present(
|
|
23
|
+
String presentation,
|
|
24
|
+
boolean dismissOnBackdropTap,
|
|
25
|
+
EmojiCloseButtonOptions closeButton,
|
|
26
|
+
String theme,
|
|
27
|
+
EmojiPickerCallback callback
|
|
28
|
+
) {
|
|
23
29
|
EmojiPickerPresenter target = "web".equals(presentation) ? webFallbackPresenter : nativePresenter;
|
|
24
|
-
target.present(presentation, dismissOnBackdropTap, closeButton, callback);
|
|
30
|
+
target.present(presentation, dismissOnBackdropTap, closeButton, theme, callback);
|
|
25
31
|
}
|
|
26
32
|
}
|
|
@@ -11,7 +11,7 @@ import android.app.Activity;
|
|
|
11
11
|
public interface EmojiPickerDialogFactory {
|
|
12
12
|
|
|
13
13
|
/** Creates and shows the dialog for the given activity, reporting outcomes via {@code listener}. */
|
|
14
|
-
EmojiPickerDialogHandle create(Activity activity, boolean dismissOnBackdropTap, Listener listener);
|
|
14
|
+
EmojiPickerDialogHandle create(Activity activity, boolean dismissOnBackdropTap, String theme, Listener listener);
|
|
15
15
|
|
|
16
16
|
/** Callback used by the factory's dialog implementation to report selection/dismissal. */
|
|
17
17
|
interface Listener {
|
package/android/src/main/java/app/independo/capacitoremojipicker/presenter/EmojiPickerPresenter.java
CHANGED
|
@@ -12,5 +12,11 @@ import app.independo.capacitoremojipicker.core.EmojiPickerCallback;
|
|
|
12
12
|
public interface EmojiPickerPresenter {
|
|
13
13
|
|
|
14
14
|
/** Presents the picker for the given presentation mode and reports the outcome. */
|
|
15
|
-
void present(
|
|
15
|
+
void present(
|
|
16
|
+
String presentation,
|
|
17
|
+
boolean dismissOnBackdropTap,
|
|
18
|
+
EmojiCloseButtonOptions closeButton,
|
|
19
|
+
String theme,
|
|
20
|
+
EmojiPickerCallback callback
|
|
21
|
+
);
|
|
16
22
|
}
|
|
@@ -59,7 +59,13 @@ public class NativeEmojiPickerPresenter implements EmojiPickerPresenter {
|
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
@Override
|
|
62
|
-
public void present(
|
|
62
|
+
public void present(
|
|
63
|
+
String presentation,
|
|
64
|
+
boolean dismissOnBackdropTap,
|
|
65
|
+
EmojiCloseButtonOptions closeButton,
|
|
66
|
+
String theme,
|
|
67
|
+
EmojiPickerCallback callback
|
|
68
|
+
) {
|
|
63
69
|
if (!"auto".equals(presentation)) {
|
|
64
70
|
// 'web' (and any future non-native presentation) isn't implemented on Android yet;
|
|
65
71
|
// honestly reject rather than silently showing the native picker instead.
|
|
@@ -68,7 +74,7 @@ public class NativeEmojiPickerPresenter implements EmojiPickerPresenter {
|
|
|
68
74
|
}
|
|
69
75
|
|
|
70
76
|
Activity activity = activityProvider.get();
|
|
71
|
-
Runnable work = () -> presentOnUiThread(activity, dismissOnBackdropTap, callback);
|
|
77
|
+
Runnable work = () -> presentOnUiThread(activity, dismissOnBackdropTap, theme, callback);
|
|
72
78
|
// Capacitor invokes @PluginMethod handlers on a background "CapacitorPlugins" thread, but
|
|
73
79
|
// BottomSheetDialog#show() and Lifecycle#addObserver() are UI-thread-only APIs. Hop onto the
|
|
74
80
|
// UI thread whenever we have a real Activity to hop through; a null Activity means there's no
|
|
@@ -80,7 +86,7 @@ public class NativeEmojiPickerPresenter implements EmojiPickerPresenter {
|
|
|
80
86
|
}
|
|
81
87
|
}
|
|
82
88
|
|
|
83
|
-
private void presentOnUiThread(Activity activity, boolean dismissOnBackdropTap, EmojiPickerCallback callback) {
|
|
89
|
+
private void presentOnUiThread(Activity activity, boolean dismissOnBackdropTap, String theme, EmojiPickerCallback callback) {
|
|
84
90
|
if (!availabilityChecker.isAvailable(activity)) {
|
|
85
91
|
callback.onError(ErrorCodes.NATIVE_UNAVAILABLE);
|
|
86
92
|
return;
|
|
@@ -98,7 +104,7 @@ public class NativeEmojiPickerPresenter implements EmojiPickerPresenter {
|
|
|
98
104
|
Presentation presentation = new Presentation(callback);
|
|
99
105
|
LifecycleOwner lifecycleOwner = (activity instanceof LifecycleOwner) ? (LifecycleOwner) activity : null;
|
|
100
106
|
current = presentation;
|
|
101
|
-
presentation.start(activity, dismissOnBackdropTap, lifecycleOwner);
|
|
107
|
+
presentation.start(activity, dismissOnBackdropTap, theme, lifecycleOwner);
|
|
102
108
|
}
|
|
103
109
|
|
|
104
110
|
/**
|
|
@@ -118,7 +124,7 @@ public class NativeEmojiPickerPresenter implements EmojiPickerPresenter {
|
|
|
118
124
|
this.callback = callback;
|
|
119
125
|
}
|
|
120
126
|
|
|
121
|
-
void start(Activity activity, boolean dismissOnBackdropTap, LifecycleOwner lifecycleOwner) {
|
|
127
|
+
void start(Activity activity, boolean dismissOnBackdropTap, String theme, LifecycleOwner lifecycleOwner) {
|
|
122
128
|
this.lifecycleOwner = lifecycleOwner;
|
|
123
129
|
|
|
124
130
|
EmojiPickerDialogFactory.EmojiPickerDialogHandle createdHandle;
|
|
@@ -126,6 +132,7 @@ public class NativeEmojiPickerPresenter implements EmojiPickerPresenter {
|
|
|
126
132
|
createdHandle = dialogFactory.create(
|
|
127
133
|
activity,
|
|
128
134
|
dismissOnBackdropTap,
|
|
135
|
+
theme,
|
|
129
136
|
new EmojiPickerDialogFactory.Listener() {
|
|
130
137
|
@Override
|
|
131
138
|
public void onEmojiSelected(String emoji) {
|
|
@@ -110,15 +110,25 @@ public class WebFallbackEmojiPickerPresenter implements EmojiPickerPresenter {
|
|
|
110
110
|
}
|
|
111
111
|
|
|
112
112
|
@Override
|
|
113
|
-
public void present(
|
|
113
|
+
public void present(
|
|
114
|
+
String presentation,
|
|
115
|
+
boolean dismissOnBackdropTap,
|
|
116
|
+
EmojiCloseButtonOptions closeButton,
|
|
117
|
+
String theme,
|
|
118
|
+
EmojiPickerCallback callback
|
|
119
|
+
) {
|
|
114
120
|
Activity activity = activityProvider.get();
|
|
115
|
-
uiThreadDispatcher.runOnUiThread(
|
|
121
|
+
uiThreadDispatcher.runOnUiThread(
|
|
122
|
+
activity,
|
|
123
|
+
() -> presentOnUiThread(activity, dismissOnBackdropTap, closeButton, theme, callback)
|
|
124
|
+
);
|
|
116
125
|
}
|
|
117
126
|
|
|
118
127
|
private void presentOnUiThread(
|
|
119
128
|
Activity activity,
|
|
120
129
|
boolean dismissOnBackdropTap,
|
|
121
130
|
EmojiCloseButtonOptions closeButton,
|
|
131
|
+
String theme,
|
|
122
132
|
EmojiPickerCallback callback
|
|
123
133
|
) {
|
|
124
134
|
String requestId = UUID.randomUUID().toString();
|
|
@@ -158,7 +168,8 @@ public class WebFallbackEmojiPickerPresenter implements EmojiPickerPresenter {
|
|
|
158
168
|
// bridge/webview is alive) - it cancels the timeout WITHOUT settling the request, which
|
|
159
169
|
// stays pending for the real result reported later via onWebResult.
|
|
160
170
|
jsEvaluator.eval(
|
|
161
|
-
"window.__CapacitorEmojiPickerPresentWeb('" + requestId + "', '"
|
|
171
|
+
"window.__CapacitorEmojiPickerPresentWeb('" + requestId + "', '"
|
|
172
|
+
+ encodeOptionsBase64Free(dismissOnBackdropTap, closeButton, theme) + "')",
|
|
162
173
|
() -> scheduler.cancel(timeoutRunnable)
|
|
163
174
|
);
|
|
164
175
|
}
|
|
@@ -191,20 +202,22 @@ public class WebFallbackEmojiPickerPresenter implements EmojiPickerPresenter {
|
|
|
191
202
|
}
|
|
192
203
|
|
|
193
204
|
/**
|
|
194
|
-
* Hand-rolled instead of a JSON library: `size`/`position` are always one of a small
|
|
195
|
-
* set of ASCII enum values validated/defaulted in {@code EmojiPicker#present}, never
|
|
205
|
+
* Hand-rolled instead of a JSON library: `size`/`position`/`theme` are always one of a small
|
|
206
|
+
* fixed set of ASCII enum values validated/defaulted in {@code EmojiPicker#present}, never
|
|
196
207
|
* arbitrary user text, so plain string interpolation is safe here. This also sidesteps
|
|
197
208
|
* `org.json`/`android.util.Base64` throwing under the mockable `android.jar` in plain JUnit
|
|
198
209
|
* unit tests (see the plan's Global Constraints).
|
|
199
210
|
*/
|
|
200
|
-
private static String encodeOptionsBase64Free(boolean dismissOnBackdropTap, EmojiCloseButtonOptions closeButton) {
|
|
211
|
+
private static String encodeOptionsBase64Free(boolean dismissOnBackdropTap, EmojiCloseButtonOptions closeButton, String theme) {
|
|
201
212
|
return "{"
|
|
202
213
|
+ "\"dismissOnBackdropTap\":" + dismissOnBackdropTap + ","
|
|
203
214
|
+ "\"closeButton\":{"
|
|
204
215
|
+ "\"size\":\"" + closeButton.size + "\","
|
|
205
216
|
+ "\"position\":\"" + closeButton.position + "\","
|
|
206
217
|
+ "\"hidden\":" + closeButton.hidden
|
|
207
|
-
+ "}
|
|
218
|
+
+ "},"
|
|
219
|
+
+ "\"theme\":\"" + theme + "\""
|
|
220
|
+
+ "}";
|
|
208
221
|
}
|
|
209
222
|
|
|
210
223
|
private static final class PendingRequest {
|
package/android/src/main/java/app/independo/capacitoremojipicker/service/EmojiPickerService.java
CHANGED
|
@@ -17,7 +17,13 @@ public class EmojiPickerService {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
/** Presents the picker, rejecting a second concurrent call instead of overlapping pickers. */
|
|
20
|
-
public void present(
|
|
20
|
+
public void present(
|
|
21
|
+
String presentation,
|
|
22
|
+
boolean dismissOnBackdropTap,
|
|
23
|
+
EmojiCloseButtonOptions closeButton,
|
|
24
|
+
String theme,
|
|
25
|
+
EmojiPickerCallback callback
|
|
26
|
+
) {
|
|
21
27
|
if (isPresenting) {
|
|
22
28
|
callback.onError(ErrorCodes.ALREADY_PRESENTING);
|
|
23
29
|
return;
|
|
@@ -28,6 +34,7 @@ public class EmojiPickerService {
|
|
|
28
34
|
presentation,
|
|
29
35
|
dismissOnBackdropTap,
|
|
30
36
|
closeButton,
|
|
37
|
+
theme,
|
|
31
38
|
new EmojiPickerCallback() {
|
|
32
39
|
@Override
|
|
33
40
|
public void onResult(EmojiPickerResult result) {
|
package/dist/docs.json
CHANGED
|
@@ -98,6 +98,20 @@
|
|
|
98
98
|
"docs": "Dismiss the picker when the user taps the transparent area outside the keyboard/button (iOS)\nor the scrim outside the picker sheet (Android and web).\n\nOn iOS and web, if `closeButton.hidden` is `true`, this is treated as `true` regardless of\nthe value passed here, so the user always has a way to dismiss the picker.",
|
|
99
99
|
"complexTypes": [],
|
|
100
100
|
"type": "boolean | undefined"
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
"name": "theme",
|
|
104
|
+
"tags": [
|
|
105
|
+
{
|
|
106
|
+
"text": "'system'",
|
|
107
|
+
"name": "default"
|
|
108
|
+
}
|
|
109
|
+
],
|
|
110
|
+
"docs": "`system`: follows the OS/app appearance setting.\n`light` / `dark`: forces the picker's appearance regardless of the system setting.\n\nOn iOS native presentation, this also sets `keyboardAppearance` on the underlying text\ninput, which is the mechanism the system emoji keyboard itself honors (separate from the\napp's own `overrideUserInterfaceStyle`, which only themes the plugin's own overlay/close\nbutton).",
|
|
111
|
+
"complexTypes": [
|
|
112
|
+
"EmojiPickerTheme"
|
|
113
|
+
],
|
|
114
|
+
"type": "EmojiPickerTheme"
|
|
101
115
|
}
|
|
102
116
|
]
|
|
103
117
|
},
|
|
@@ -163,6 +177,25 @@
|
|
|
163
177
|
"complexTypes": []
|
|
164
178
|
}
|
|
165
179
|
]
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
"name": "EmojiPickerTheme",
|
|
183
|
+
"slug": "emojipickertheme",
|
|
184
|
+
"docs": "The picker's appearance.",
|
|
185
|
+
"types": [
|
|
186
|
+
{
|
|
187
|
+
"text": "'system'",
|
|
188
|
+
"complexTypes": []
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
"text": "'light'",
|
|
192
|
+
"complexTypes": []
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
"text": "'dark'",
|
|
196
|
+
"complexTypes": []
|
|
197
|
+
}
|
|
198
|
+
]
|
|
166
199
|
}
|
|
167
200
|
],
|
|
168
201
|
"pluginConfigs": []
|
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
* How the picker should be presented.
|
|
3
3
|
*/
|
|
4
4
|
export type EmojiPickerPresentation = 'auto' | 'web';
|
|
5
|
+
/**
|
|
6
|
+
* The picker's appearance.
|
|
7
|
+
*/
|
|
8
|
+
export type EmojiPickerTheme = 'system' | 'light' | 'dark';
|
|
5
9
|
/**
|
|
6
10
|
* Options for presenting the emoji picker.
|
|
7
11
|
*/
|
|
@@ -27,6 +31,17 @@ export interface EmojiPickerOptions {
|
|
|
27
31
|
* @default true
|
|
28
32
|
*/
|
|
29
33
|
dismissOnBackdropTap?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* `system`: follows the OS/app appearance setting.
|
|
36
|
+
* `light` / `dark`: forces the picker's appearance regardless of the system setting.
|
|
37
|
+
*
|
|
38
|
+
* On iOS native presentation, this also sets `keyboardAppearance` on the underlying text
|
|
39
|
+
* input, which is the mechanism the system emoji keyboard itself honors (separate from the
|
|
40
|
+
* app's own `overrideUserInterfaceStyle`, which only themes the plugin's own overlay/close
|
|
41
|
+
* button).
|
|
42
|
+
* @default 'system'
|
|
43
|
+
*/
|
|
44
|
+
theme?: EmojiPickerTheme;
|
|
30
45
|
}
|
|
31
46
|
/**
|
|
32
47
|
* Configures the close button rendered above the iOS native emoji keyboard/the web picker sheet.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * How the picker should be presented.\n */\nexport type EmojiPickerPresentation = 'auto' | 'web';\n\n/**\n * Options for presenting the emoji picker.\n */\nexport interface EmojiPickerOptions {\n /**\n * `auto`: prefer native/system UI and fall back to the web picker when native presentation\n * is not available or fails.\n * `web`: always use the web picker, including inside Capacitor native apps.\n * @default 'auto'\n */\n presentation?: EmojiPickerPresentation;\n /**\n * Configures the close button rendered above the iOS keyboard/the web picker sheet (iOS has\n * no system-provided one). Ignored on Android.\n */\n closeButton?: EmojiPickerCloseButtonOptions;\n /**\n * Dismiss the picker when the user taps the transparent area outside the keyboard/button (iOS)\n * or the scrim outside the picker sheet (Android and web).\n *\n * On iOS and web, if `closeButton.hidden` is `true`, this is treated as `true` regardless of\n * the value passed here, so the user always has a way to dismiss the picker.\n * @default true\n */\n dismissOnBackdropTap?: boolean;\n}\n\n/**\n * Configures the close button rendered above the iOS native emoji keyboard/the web picker sheet.\n */\nexport interface EmojiPickerCloseButtonOptions {\n /**\n * `xSmall`: 24pt, `small`: 32pt, `medium`: 48pt, `large`: 64pt.\n * @default 'medium'\n */\n size?: 'xSmall' | 'small' | 'medium' | 'large';\n /**\n * Which side of the keyboard the button docks to.\n * @default 'right'\n */\n position?: 'left' | 'center' | 'right';\n /**\n * Hides the built-in close button. See `EmojiPickerOptions.dismissOnBackdropTap` for the\n * safety net this triggers.\n * @default false\n */\n hidden?: boolean;\n}\n\n/**\n * Result of presenting the emoji picker.\n */\nexport interface EmojiPickerResult {\n /**\n * The selected emoji as a complete Unicode string/grapheme (unchanged), or `null` when the\n * picker was dismissed without a selection.\n */\n emoji: string | null;\n}\n\n/**\n * Interface for the EmojiPicker plugin, which presents a native or web emoji picker and\n * resolves with the emoji the user selected.\n */\nexport interface EmojiPickerPlugin {\n /**\n * Presents the emoji picker.\n *\n * Resolves with `{ emoji: null }` rather than leaving the promise pending when the user\n * dismisses the picker without selecting an emoji.\n *\n * Calling this method again while a picker is already active rejects immediately with the\n * `ALREADY_PRESENTING` error code rather than presenting a second, overlapping picker.\n *\n * @param options The options for the presentation.\n * @returns A promise that resolves to an EmojiPickerResult.\n * @throws Error with code `ALREADY_PRESENTING` if a picker is already active.\n */\n present(options?: EmojiPickerOptions): Promise<EmojiPickerResult>;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * How the picker should be presented.\n */\nexport type EmojiPickerPresentation = 'auto' | 'web';\n\n/**\n * The picker's appearance.\n */\nexport type EmojiPickerTheme = 'system' | 'light' | 'dark';\n\n/**\n * Options for presenting the emoji picker.\n */\nexport interface EmojiPickerOptions {\n /**\n * `auto`: prefer native/system UI and fall back to the web picker when native presentation\n * is not available or fails.\n * `web`: always use the web picker, including inside Capacitor native apps.\n * @default 'auto'\n */\n presentation?: EmojiPickerPresentation;\n /**\n * Configures the close button rendered above the iOS keyboard/the web picker sheet (iOS has\n * no system-provided one). Ignored on Android.\n */\n closeButton?: EmojiPickerCloseButtonOptions;\n /**\n * Dismiss the picker when the user taps the transparent area outside the keyboard/button (iOS)\n * or the scrim outside the picker sheet (Android and web).\n *\n * On iOS and web, if `closeButton.hidden` is `true`, this is treated as `true` regardless of\n * the value passed here, so the user always has a way to dismiss the picker.\n * @default true\n */\n dismissOnBackdropTap?: boolean;\n /**\n * `system`: follows the OS/app appearance setting.\n * `light` / `dark`: forces the picker's appearance regardless of the system setting.\n *\n * On iOS native presentation, this also sets `keyboardAppearance` on the underlying text\n * input, which is the mechanism the system emoji keyboard itself honors (separate from the\n * app's own `overrideUserInterfaceStyle`, which only themes the plugin's own overlay/close\n * button).\n * @default 'system'\n */\n theme?: EmojiPickerTheme;\n}\n\n/**\n * Configures the close button rendered above the iOS native emoji keyboard/the web picker sheet.\n */\nexport interface EmojiPickerCloseButtonOptions {\n /**\n * `xSmall`: 24pt, `small`: 32pt, `medium`: 48pt, `large`: 64pt.\n * @default 'medium'\n */\n size?: 'xSmall' | 'small' | 'medium' | 'large';\n /**\n * Which side of the keyboard the button docks to.\n * @default 'right'\n */\n position?: 'left' | 'center' | 'right';\n /**\n * Hides the built-in close button. See `EmojiPickerOptions.dismissOnBackdropTap` for the\n * safety net this triggers.\n * @default false\n */\n hidden?: boolean;\n}\n\n/**\n * Result of presenting the emoji picker.\n */\nexport interface EmojiPickerResult {\n /**\n * The selected emoji as a complete Unicode string/grapheme (unchanged), or `null` when the\n * picker was dismissed without a selection.\n */\n emoji: string | null;\n}\n\n/**\n * Interface for the EmojiPicker plugin, which presents a native or web emoji picker and\n * resolves with the emoji the user selected.\n */\nexport interface EmojiPickerPlugin {\n /**\n * Presents the emoji picker.\n *\n * Resolves with `{ emoji: null }` rather than leaving the promise pending when the user\n * dismisses the picker without selecting an emoji.\n *\n * Calling this method again while a picker is already active rejects immediately with the\n * `ALREADY_PRESENTING` error code rather than presenting a second, overlapping picker.\n *\n * @param options The options for the presentation.\n * @returns A promise that resolves to an EmojiPickerResult.\n * @throws Error with code `ALREADY_PRESENTING` if a picker is already active.\n */\n present(options?: EmojiPickerOptions): Promise<EmojiPickerResult>;\n}\n"]}
|
|
@@ -50,14 +50,31 @@ function ensureSheetStylesInjected() {
|
|
|
50
50
|
max(0.5rem, env(safe-area-inset-left, 0px));
|
|
51
51
|
border: none;
|
|
52
52
|
border-radius: 1rem 1rem 0 0;
|
|
53
|
-
background-color: Canvas;
|
|
54
53
|
overflow: hidden;
|
|
55
54
|
transform: translateY(100%);
|
|
56
55
|
transition: transform ${ANIMATION_MS}ms ease-out;
|
|
57
56
|
}
|
|
57
|
+
/*
|
|
58
|
+
* Explicit colors rather than the \`Canvas\`/\`CanvasText\` system-color keywords: those rely
|
|
59
|
+
* on the UA knowing the page's color-scheme, which isn't reliably signaled inside a
|
|
60
|
+
* Capacitor WKWebView, so they were silently staying light-only regardless of the resolved
|
|
61
|
+
* theme. Values match emoji-picker-element's own light/dark defaults so the seam between
|
|
62
|
+
* the sheet chrome and the picker itself stays invisible.
|
|
63
|
+
*/
|
|
64
|
+
dialog.emoji-picker-sheet--light {
|
|
65
|
+
background-color: #fff;
|
|
66
|
+
color: #1f1f1f;
|
|
67
|
+
}
|
|
68
|
+
dialog.emoji-picker-sheet--dark {
|
|
69
|
+
background-color: #222;
|
|
70
|
+
color: #e8e8e8;
|
|
71
|
+
}
|
|
58
72
|
dialog.emoji-picker-sheet::backdrop {
|
|
59
73
|
background: rgba(0, 0, 0, 0.4);
|
|
60
74
|
}
|
|
75
|
+
dialog.emoji-picker-sheet--dark::backdrop {
|
|
76
|
+
background: rgba(0, 0, 0, 0.6);
|
|
77
|
+
}
|
|
61
78
|
dialog.emoji-picker-sheet[data-state='open'] {
|
|
62
79
|
transform: translateY(0);
|
|
63
80
|
}
|
|
@@ -77,6 +94,9 @@ function ensureSheetStylesInjected() {
|
|
|
77
94
|
padding: 0;
|
|
78
95
|
cursor: pointer;
|
|
79
96
|
}
|
|
97
|
+
dialog.emoji-picker-sheet--dark .emoji-picker-sheet__close {
|
|
98
|
+
background: rgba(255, 255, 255, 0.12);
|
|
99
|
+
}
|
|
80
100
|
@media (prefers-reduced-motion: reduce) {
|
|
81
101
|
dialog.emoji-picker-sheet {
|
|
82
102
|
transition: none;
|
|
@@ -88,6 +108,23 @@ function ensureSheetStylesInjected() {
|
|
|
88
108
|
function prefersReducedMotion() {
|
|
89
109
|
return typeof window.matchMedia === 'function' && window.matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
90
110
|
}
|
|
111
|
+
/** Resolves `system` to the OS's current light/dark preference; passes explicit themes through. */
|
|
112
|
+
function resolveTheme(theme) {
|
|
113
|
+
if (theme === 'light' || theme === 'dark') {
|
|
114
|
+
return theme;
|
|
115
|
+
}
|
|
116
|
+
const prefersDark = typeof window.matchMedia === 'function' && window.matchMedia('(prefers-color-scheme: dark)').matches;
|
|
117
|
+
return prefersDark ? 'dark' : 'light';
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Matches the sheet's own `--light`/`--dark` background colors (see `ensureSheetStylesInjected`).
|
|
121
|
+
* Set explicitly, rather than the `Canvas` system-color keyword, for the same WKWebView
|
|
122
|
+
* color-scheme-detection reason documented there.
|
|
123
|
+
*/
|
|
124
|
+
const SHEET_BACKGROUND_COLOR = {
|
|
125
|
+
light: '#fff',
|
|
126
|
+
dark: '#222',
|
|
127
|
+
};
|
|
91
128
|
const CLOSE_BUTTON_SIZE_PX = {
|
|
92
129
|
xSmall: 24,
|
|
93
130
|
small: 32,
|
|
@@ -160,14 +197,15 @@ export class WebEmojiPickerPresenter {
|
|
|
160
197
|
// so hiding it force-enables backdrop-tap-to-dismiss regardless of what was explicitly
|
|
161
198
|
// requested (mirrors the iOS presenter's `effectiveDismissOnBackdropTap`).
|
|
162
199
|
const dismissOnBackdropTap = ((_b = options.dismissOnBackdropTap) !== null && _b !== void 0 ? _b : true) || ((_c = closeButtonOptions.hidden) !== null && _c !== void 0 ? _c : false);
|
|
200
|
+
// Resolved once at open time (rather than left to each side's own live
|
|
201
|
+
// `prefers-color-scheme` tracking) so the picker and the sheet chrome around it always
|
|
202
|
+
// agree, fixing the mismatch from issue #19.
|
|
203
|
+
const resolvedTheme = resolveTheme(options.theme);
|
|
163
204
|
let picker;
|
|
164
205
|
try {
|
|
165
206
|
picker = await this.createPickerElement();
|
|
166
207
|
picker.dataSource = getBundledEmojiDataSourceUrl();
|
|
167
|
-
|
|
168
|
-
// force the picker to light mode too rather than let it auto-follow
|
|
169
|
-
// `prefers-color-scheme` on its own and visually mismatch the chrome.
|
|
170
|
-
picker.classList.add('light');
|
|
208
|
+
picker.classList.add(resolvedTheme);
|
|
171
209
|
}
|
|
172
210
|
catch (_d) {
|
|
173
211
|
throw new Error(ErrorCodes.NOT_IMPLEMENTED);
|
|
@@ -180,10 +218,10 @@ export class WebEmojiPickerPresenter {
|
|
|
180
218
|
// The picker's own card look (border + background) would otherwise float as a visibly
|
|
181
219
|
// smaller box inside the sheet; matching its background to the sheet's and dropping its
|
|
182
220
|
// border makes it read as full width, part of the sheet rather than nested inside it.
|
|
183
|
-
picker.style.setProperty('--background',
|
|
221
|
+
picker.style.setProperty('--background', SHEET_BACKGROUND_COLOR[resolvedTheme]);
|
|
184
222
|
picker.style.setProperty('--border-size', '0');
|
|
185
223
|
const dialog = document.createElement('dialog');
|
|
186
|
-
dialog.className =
|
|
224
|
+
dialog.className = `emoji-picker-sheet emoji-picker-sheet--${resolvedTheme}`;
|
|
187
225
|
dialog.setAttribute('role', 'dialog');
|
|
188
226
|
dialog.setAttribute('aria-modal', 'true');
|
|
189
227
|
dialog.setAttribute('aria-label', 'Emoji picker');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebEmojiPickerPresenter.js","sourceRoot":"","sources":["../../../../src/platform/web/WebEmojiPickerPresenter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEpD,OAAO,EAAE,4BAA4B,EAAE,MAAM,qBAAqB,CAAC;AAOnE,sEAAsE;AACtE,KAAK,UAAU,0BAA0B;IACrC,IAAI,CAAC;QACD,MAAM,MAAM,CAAC,sBAAsB,CAAC,CAAC;QACrC,OAAO,QAAQ,CAAC,aAAa,CAAC,cAAc,CAAkC,CAAC;IACnF,CAAC;IAAC,WAAM,CAAC;QACL,MAAM,IAAI,KAAK,CAAC,UAAU,CAAC,eAAe,CAAC,CAAC;IAChD,CAAC;AACL,CAAC;AAED;;;;;;;GAOG;AACH,SAAS,6BAA6B,CAAC,MAAe;;IAClD,IAAI,CAAC,CAAC,MAAM,YAAY,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC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C;YACD,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,gBAAgB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YAE3C,MAAM,CAAC,gBAAgB,CAAC,aAAa,EAAE,YAA6B,CAAC,CAAC;YACtE,MAAM,CAAC,gBAAgB,CAAC,aAAa,EAAE,mBAAmB,CAAC,CAAC;YAC5D,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC;YAChD,MAAM,CAAC,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;YAC5C,QAAQ,CAAC,gBAAgB,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;YAChD,MAAM,CAAC,gBAAgB,CAAC,oBAAoB,EAAE,oBAAoB,CAAC,CAAC;YACpE,iBAAiB,aAAjB,iBAAiB,uBAAjB,iBAAiB,CAAE,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,kBAAkB,CAAC,CAAC;YAExE,IAAI,iBAAiB,EAAE,CAAC;gBACpB,MAAM,CAAC,WAAW,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC;YACjD,CAAC;YACD,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;YAC3B,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;YAClC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG,QAAQ,CAAC;YACxC,MAAM,CAAC,SAAS,EAAE,CAAC;YAEnB,qBAAqB,CAAC,GAAG,EAAE;gBACvB,MAAM,CAAC,YAAY,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;YAC9C,CAAC,CAAC,CAAC;YAEH,MAAA,MAAM,CAAC,KAAK,sDAAI,CAAC;QACrB,CAAC,CAAC,CAAC;IACP,CAAC;CACJ","sourcesContent":["import { ErrorCodes } from '../../core/error-codes';\nimport type { EmojiPickerCloseButtonOptions, EmojiPickerOptions, EmojiPickerResult } from '../../definitions';\nimport { getBundledEmojiDataSourceUrl } from './emoji-data-source';\n\n/** Minimal shape of the `<emoji-picker>` custom element this presenter depends on. */\nexport interface EmojiPickerElement extends HTMLElement {\n dataSource: string;\n}\n\n/** Registers `<emoji-picker>` (if needed) and creates the element. */\nasync function defaultCreatePickerElement(): Promise<EmojiPickerElement> {\n try {\n await import('emoji-picker-element');\n return document.createElement('emoji-picker') as unknown as EmojiPickerElement;\n } catch {\n throw new Error(ErrorCodes.NOT_IMPLEMENTED);\n }\n}\n\n/**\n * `emoji-picker-element`'s internal `Database` runs a background `fetch(dataSource, { method: 'HEAD' })`\n * freshness check whenever it already has cached data for the locale (i.e. on the second+ open in a\n * session). Non-`GET` requests to `blob:` URLs always throw `TypeError` per the Fetch spec, and this\n * internal call isn't awaited, so it otherwise surfaces as a noisy but harmless `unhandledrejection`.\n * This filters out only that specific rejection shape while a picker is open, letting everything else\n * propagate normally to the host app.\n */\nfunction isKnownBlobHeadCheckRejection(reason: unknown): boolean {\n if (!(reason instanceof TypeError) || !reason.message.includes('Failed to fetch')) {\n return false;\n }\n return reason.stack?.includes('getETag') ?? false;\n}\n\nconst SHEET_STYLE_ELEMENT_ID = 'emoji-picker-sheet-styles';\nconst ANIMATION_MS = 200;\n\n/** Injects the bottom-sheet stylesheet into `document.head`, once per document. */\nfunction ensureSheetStylesInjected(): void {\n if (document.getElementById(SHEET_STYLE_ELEMENT_ID)) {\n return;\n }\n const style = document.createElement('style');\n style.id = SHEET_STYLE_ELEMENT_ID;\n style.textContent = `\n dialog.emoji-picker-sheet {\n position: fixed;\n inset: auto 0 0 0;\n margin: 0 auto;\n display: flex;\n flex-direction: column;\n box-sizing: border-box;\n width: 100%;\n max-width: 30rem;\n height: min(30rem, 80vh);\n max-height: 80vh;\n padding: 0 max(0.5rem, env(safe-area-inset-right, 0px)) max(0.5rem, env(safe-area-inset-bottom, 0px))\n max(0.5rem, env(safe-area-inset-left, 0px));\n border: none;\n border-radius: 1rem 1rem 0 0;\n background-color: Canvas;\n overflow: hidden;\n transform: translateY(100%);\n transition: transform ${ANIMATION_MS}ms ease-out;\n }\n dialog.emoji-picker-sheet::backdrop {\n background: rgba(0, 0, 0, 0.4);\n }\n dialog.emoji-picker-sheet[data-state='open'] {\n transform: translateY(0);\n }\n .emoji-picker-sheet__header {\n flex: 0 0 auto;\n display: flex;\n padding-block: 0.5rem;\n }\n .emoji-picker-sheet__close {\n border: none;\n border-radius: 50%;\n background: rgba(0, 0, 0, 0.06);\n color: inherit;\n display: flex;\n align-items: center;\n justify-content: center;\n padding: 0;\n cursor: pointer;\n }\n @media (prefers-reduced-motion: reduce) {\n dialog.emoji-picker-sheet {\n transition: none;\n }\n }\n `;\n document.head.appendChild(style);\n}\n\nfunction prefersReducedMotion(): boolean {\n return typeof window.matchMedia === 'function' && window.matchMedia('(prefers-reduced-motion: reduce)').matches;\n}\n\nconst CLOSE_BUTTON_SIZE_PX: Record<NonNullable<EmojiPickerCloseButtonOptions['size']>, number> = {\n xSmall: 24,\n small: 32,\n medium: 48,\n large: 64,\n};\n\n/** An \"x\" glyph sized proportionally to the button, matching the iOS button's icon/button ratio. */\nfunction createCloseIcon(buttonSizePx: number): SVGSVGElement {\n const svgNs = 'http://www.w3.org/2000/svg';\n const iconSizePx = Math.round(buttonSizePx * 0.375);\n const svg = document.createElementNS(svgNs, 'svg');\n svg.setAttribute('viewBox', '0 0 24 24');\n svg.setAttribute('width', String(iconSizePx));\n svg.setAttribute('height', String(iconSizePx));\n svg.setAttribute('fill', 'none');\n svg.setAttribute('stroke', 'currentColor');\n svg.setAttribute('stroke-width', '2.5');\n svg.setAttribute('stroke-linecap', 'round');\n svg.setAttribute('aria-hidden', 'true');\n\n const diagonal1 = document.createElementNS(svgNs, 'line');\n diagonal1.setAttribute('x1', '5');\n diagonal1.setAttribute('y1', '5');\n diagonal1.setAttribute('x2', '19');\n diagonal1.setAttribute('y2', '19');\n\n const diagonal2 = document.createElementNS(svgNs, 'line');\n diagonal2.setAttribute('x1', '19');\n diagonal2.setAttribute('y1', '5');\n diagonal2.setAttribute('x2', '5');\n diagonal2.setAttribute('y2', '19');\n\n svg.append(diagonal1, diagonal2);\n return svg;\n}\n\n/** Builds the header row hosting the close button, or `null` when the button is hidden. */\nfunction createCloseButtonHeader(options: EmojiPickerCloseButtonOptions): {\n header: HTMLDivElement;\n button: HTMLButtonElement;\n} | null {\n if (options.hidden) {\n return null;\n }\n const sizePx = CLOSE_BUTTON_SIZE_PX[options.size ?? 'medium'];\n const position = options.position ?? 'right';\n\n const header = document.createElement('div');\n header.className = 'emoji-picker-sheet__header';\n header.style.justifyContent = position === 'left' ? 'flex-start' : position === 'center' ? 'center' : 'flex-end';\n\n const button = document.createElement('button');\n button.type = 'button';\n button.className = 'emoji-picker-sheet__close';\n button.setAttribute('aria-label', 'Close');\n button.style.width = `${sizePx}px`;\n button.style.height = `${sizePx}px`;\n button.appendChild(createCloseIcon(sizePx));\n\n header.appendChild(button);\n return { header, button };\n}\n\nexport interface WebEmojiPickerPresenterOptions {\n /** Creates the picker element. Overridable for testing. */\n createPickerElement?: () => Promise<EmojiPickerElement>;\n}\n\n/**\n * Presents `emoji-picker-element` in a bottom-sheet `<dialog>` and resolves with the selected emoji.\n *\n * Kept independent of the Capacitor web plugin registration so native-platform fallback\n * orchestration (issue #6) can present the same web picker from inside a native WebView.\n */\nexport class WebEmojiPickerPresenter {\n private readonly createPickerElement: () => Promise<EmojiPickerElement>;\n\n public constructor(options: WebEmojiPickerPresenterOptions = {}) {\n this.createPickerElement = options.createPickerElement ?? defaultCreatePickerElement;\n }\n\n public async present(\n options: EmojiPickerOptions = {},\n presentOptions: { signal?: AbortSignal } = {}\n ): Promise<EmojiPickerResult> {\n const { signal } = presentOptions;\n const closeButtonOptions = options.closeButton ?? {};\n // A hidden close button must never leave the user with zero ways to dismiss the picker,\n // so hiding it force-enables backdrop-tap-to-dismiss regardless of what was explicitly\n // requested (mirrors the iOS presenter's `effectiveDismissOnBackdropTap`).\n const dismissOnBackdropTap = (options.dismissOnBackdropTap ?? true) || (closeButtonOptions.hidden ?? false);\n\n let picker: EmojiPickerElement;\n try {\n picker = await this.createPickerElement();\n picker.dataSource = getBundledEmojiDataSourceUrl();\n // The sheet chrome around the picker doesn't yet adapt to dark mode (issue #19), so\n // force the picker to light mode too rather than let it auto-follow\n // `prefers-color-scheme` on its own and visually mismatch the chrome.\n picker.classList.add('light');\n } catch {\n throw new Error(ErrorCodes.NOT_IMPLEMENTED);\n }\n\n ensureSheetStylesInjected();\n\n picker.style.display = 'block';\n picker.style.width = '100%';\n picker.style.flex = '1 1 auto';\n picker.style.minHeight = '0';\n // The picker's own card look (border + background) would otherwise float as a visibly\n // smaller box inside the sheet; matching its background to the sheet's and dropping its\n // border makes it read as full width, part of the sheet rather than nested inside it.\n picker.style.setProperty('--background', 'Canvas');\n picker.style.setProperty('--border-size', '0');\n\n const dialog = document.createElement('dialog');\n dialog.className = 'emoji-picker-sheet';\n dialog.setAttribute('role', 'dialog');\n dialog.setAttribute('aria-modal', 'true');\n dialog.setAttribute('aria-label', 'Emoji picker');\n\n const closeButtonHeader = createCloseButtonHeader(closeButtonOptions);\n if (closeButtonHeader) {\n // With the picker's own border removed above, this is the only visual separation\n // between the close button and the picker.\n picker.style.borderTop = '1px solid rgba(127, 127, 127, 0.3)';\n }\n\n return new Promise<EmojiPickerResult>((resolve) => {\n let settled = false;\n let pointerDownOnDialog = false;\n\n const previouslyFocusedElement = document.activeElement as HTMLElement | null;\n const previousBodyOverflow = document.body.style.overflow;\n\n const onUnhandledRejection = (event: PromiseRejectionEvent) => {\n if (isKnownBlobHeadCheckRejection(event.reason)) {\n event.preventDefault();\n }\n };\n\n const finish = (result: EmojiPickerResult) => {\n window.removeEventListener('unhandledrejection', onUnhandledRejection);\n document.body.style.overflow = previousBodyOverflow;\n dialog.close();\n dialog.remove();\n\n if (previouslyFocusedElement instanceof HTMLElement && document.contains(previouslyFocusedElement)) {\n previouslyFocusedElement.focus?.();\n }\n\n resolve(result);\n };\n\n const settle = (result: EmojiPickerResult) => {\n if (settled) {\n return;\n }\n settled = true;\n picker.removeEventListener('emoji-click', onEmojiClick as EventListener);\n dialog.removeEventListener('pointerdown', onDialogPointerDown);\n dialog.removeEventListener('click', onDialogClick);\n dialog.removeEventListener('cancel', onCancel);\n document.removeEventListener('keydown', onKeyDown);\n closeButtonHeader?.button.removeEventListener('click', onCloseButtonClick);\n signal?.removeEventListener('abort', onAbort);\n\n dialog.removeAttribute('data-state');\n\n if (prefersReducedMotion()) {\n finish(result);\n } else {\n setTimeout(() => finish(result), ANIMATION_MS);\n }\n };\n\n const onEmojiClick = (event: CustomEvent<{ unicode?: string }>) => {\n settle({ emoji: event.detail.unicode ?? null });\n };\n\n const onDialogPointerDown = (event: PointerEvent) => {\n pointerDownOnDialog = event.target === dialog;\n };\n\n const onDialogClick = (event: MouseEvent) => {\n if (dismissOnBackdropTap && event.target === dialog && pointerDownOnDialog) {\n settle({ emoji: null });\n }\n };\n\n // The dialog's native `cancel` event covers real browsers, where it fires\n // automatically on Escape and its default action would otherwise close the dialog\n // instantly, skipping the close animation. The `keydown` listener is a fallback for\n // environments (e.g. jsdom in tests) that don't implement dialog cancellation;\n // `settle` is idempotent, so both firing for the same keypress is harmless.\n const onCancel = (event: Event) => {\n event.preventDefault();\n settle({ emoji: null });\n };\n\n const onKeyDown = (event: KeyboardEvent) => {\n if (event.key === 'Escape') {\n settle({ emoji: null });\n }\n };\n\n const onCloseButtonClick = () => {\n settle({ emoji: null });\n };\n\n const onAbort = () => {\n settle({ emoji: null });\n };\n\n if (signal?.aborted) {\n resolve({ emoji: null });\n return;\n }\n signal?.addEventListener('abort', onAbort);\n\n picker.addEventListener('emoji-click', onEmojiClick as EventListener);\n dialog.addEventListener('pointerdown', onDialogPointerDown);\n dialog.addEventListener('click', onDialogClick);\n dialog.addEventListener('cancel', onCancel);\n document.addEventListener('keydown', onKeyDown);\n window.addEventListener('unhandledrejection', onUnhandledRejection);\n closeButtonHeader?.button.addEventListener('click', onCloseButtonClick);\n\n if (closeButtonHeader) {\n dialog.appendChild(closeButtonHeader.header);\n }\n dialog.appendChild(picker);\n document.body.appendChild(dialog);\n document.body.style.overflow = 'hidden';\n dialog.showModal();\n\n requestAnimationFrame(() => {\n dialog.setAttribute('data-state', 'open');\n });\n\n picker.focus?.();\n });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"WebEmojiPickerPresenter.js","sourceRoot":"","sources":["../../../../src/platform/web/WebEmojiPickerPresenter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAOpD,OAAO,EAAE,4BAA4B,EAAE,MAAM,qBAAqB,CAAC;AAOnE,sEAAsE;AACtE,KAAK,UAAU,0BAA0B;IACrC,IAAI,CAAC;QACD,MAAM,MAAM,CAAC,sBAAsB,CAAC,CAAC;QACrC,OAAO,QAAQ,CAAC,aAAa,CAAC,cAAc,CAAkC,CAAC;IACnF,CAAC;IAAC,WAAM,CAAC;QACL,MAAM,IAAI,KAAK,CAAC,UAAU,CAAC,eAAe,CAAC,CAAC;IAChD,CAAC;AACL,CAAC;AAED;;;;;;;GAOG;AACH,SAAS,6BAA6B,CAAC,MAAe;;IAClD,IAAI,CAAC,CAAC,MAAM,YAAY,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAC,EAAE,CAAC;QAChF,OAAO,KAAK,CAAC;IACjB,CAAC;IACD,OAAO,MAAA,MAAA,MAAM,CAAC,KAAK,0CAAE,QAAQ,CAAC,SAAS,CAAC,mCAAI,KAAK,CAAC;AACtD,CAAC;AAED,MAAM,sBAAsB,GAAG,2BAA2B,CAAC;AAC3D,MAAM,YAAY,GAAG,GAAG,CAAC;AAEzB,mFAAmF;AACnF,SAAS,yBAAyB;IAC9B,IAAI,QAAQ,CAAC,cAAc,CAAC,sBAAsB,CAAC,EAAE,CAAC;QAClD,OAAO;IACX,CAAC;IACD,MAAM,KAAK,GAAG,QAAQ,CAAC,aAAa,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,CAAC,CAAC;IACP,CAAC;CACJ","sourcesContent":["import { ErrorCodes } from '../../core/error-codes';\nimport type {\n EmojiPickerCloseButtonOptions,\n EmojiPickerOptions,\n EmojiPickerResult,\n EmojiPickerTheme,\n} from '../../definitions';\nimport { getBundledEmojiDataSourceUrl } from './emoji-data-source';\n\n/** Minimal shape of the `<emoji-picker>` custom element this presenter depends on. */\nexport interface EmojiPickerElement extends HTMLElement {\n dataSource: string;\n}\n\n/** Registers `<emoji-picker>` (if needed) and creates the element. */\nasync function defaultCreatePickerElement(): Promise<EmojiPickerElement> {\n try {\n await import('emoji-picker-element');\n return document.createElement('emoji-picker') as unknown as EmojiPickerElement;\n } catch {\n throw new Error(ErrorCodes.NOT_IMPLEMENTED);\n }\n}\n\n/**\n * `emoji-picker-element`'s internal `Database` runs a background `fetch(dataSource, { method: 'HEAD' })`\n * freshness check whenever it already has cached data for the locale (i.e. on the second+ open in a\n * session). Non-`GET` requests to `blob:` URLs always throw `TypeError` per the Fetch spec, and this\n * internal call isn't awaited, so it otherwise surfaces as a noisy but harmless `unhandledrejection`.\n * This filters out only that specific rejection shape while a picker is open, letting everything else\n * propagate normally to the host app.\n */\nfunction isKnownBlobHeadCheckRejection(reason: unknown): boolean {\n if (!(reason instanceof TypeError) || !reason.message.includes('Failed to fetch')) {\n return false;\n }\n return reason.stack?.includes('getETag') ?? false;\n}\n\nconst SHEET_STYLE_ELEMENT_ID = 'emoji-picker-sheet-styles';\nconst ANIMATION_MS = 200;\n\n/** Injects the bottom-sheet stylesheet into `document.head`, once per document. */\nfunction ensureSheetStylesInjected(): void {\n if (document.getElementById(SHEET_STYLE_ELEMENT_ID)) {\n return;\n }\n const style = document.createElement('style');\n style.id = SHEET_STYLE_ELEMENT_ID;\n style.textContent = `\n dialog.emoji-picker-sheet {\n position: fixed;\n inset: auto 0 0 0;\n margin: 0 auto;\n display: flex;\n flex-direction: column;\n box-sizing: border-box;\n width: 100%;\n max-width: 30rem;\n height: min(30rem, 80vh);\n max-height: 80vh;\n padding: 0 max(0.5rem, env(safe-area-inset-right, 0px)) max(0.5rem, env(safe-area-inset-bottom, 0px))\n max(0.5rem, env(safe-area-inset-left, 0px));\n border: none;\n border-radius: 1rem 1rem 0 0;\n overflow: hidden;\n transform: translateY(100%);\n transition: transform ${ANIMATION_MS}ms ease-out;\n }\n /*\n * Explicit colors rather than the \\`Canvas\\`/\\`CanvasText\\` system-color keywords: those rely\n * on the UA knowing the page's color-scheme, which isn't reliably signaled inside a\n * Capacitor WKWebView, so they were silently staying light-only regardless of the resolved\n * theme. Values match emoji-picker-element's own light/dark defaults so the seam between\n * the sheet chrome and the picker itself stays invisible.\n */\n dialog.emoji-picker-sheet--light {\n background-color: #fff;\n color: #1f1f1f;\n }\n dialog.emoji-picker-sheet--dark {\n background-color: #222;\n color: #e8e8e8;\n }\n dialog.emoji-picker-sheet::backdrop {\n background: rgba(0, 0, 0, 0.4);\n }\n dialog.emoji-picker-sheet--dark::backdrop {\n background: rgba(0, 0, 0, 0.6);\n }\n dialog.emoji-picker-sheet[data-state='open'] {\n transform: translateY(0);\n }\n .emoji-picker-sheet__header {\n flex: 0 0 auto;\n display: flex;\n padding-block: 0.5rem;\n }\n .emoji-picker-sheet__close {\n border: none;\n border-radius: 50%;\n background: rgba(0, 0, 0, 0.06);\n color: inherit;\n display: flex;\n align-items: center;\n justify-content: center;\n padding: 0;\n cursor: pointer;\n }\n dialog.emoji-picker-sheet--dark .emoji-picker-sheet__close {\n background: rgba(255, 255, 255, 0.12);\n }\n @media (prefers-reduced-motion: reduce) {\n dialog.emoji-picker-sheet {\n transition: none;\n }\n }\n `;\n document.head.appendChild(style);\n}\n\nfunction prefersReducedMotion(): boolean {\n return typeof window.matchMedia === 'function' && window.matchMedia('(prefers-reduced-motion: reduce)').matches;\n}\n\n/** Resolves `system` to the OS's current light/dark preference; passes explicit themes through. */\nfunction resolveTheme(theme: EmojiPickerTheme | undefined): 'light' | 'dark' {\n if (theme === 'light' || theme === 'dark') {\n return theme;\n }\n const prefersDark = typeof window.matchMedia === 'function' && window.matchMedia('(prefers-color-scheme: dark)').matches;\n return prefersDark ? 'dark' : 'light';\n}\n\n/**\n * Matches the sheet's own `--light`/`--dark` background colors (see `ensureSheetStylesInjected`).\n * Set explicitly, rather than the `Canvas` system-color keyword, for the same WKWebView\n * color-scheme-detection reason documented there.\n */\nconst SHEET_BACKGROUND_COLOR: Record<'light' | 'dark', string> = {\n light: '#fff',\n dark: '#222',\n};\n\nconst CLOSE_BUTTON_SIZE_PX: Record<NonNullable<EmojiPickerCloseButtonOptions['size']>, number> = {\n xSmall: 24,\n small: 32,\n medium: 48,\n large: 64,\n};\n\n/** An \"x\" glyph sized proportionally to the button, matching the iOS button's icon/button ratio. */\nfunction createCloseIcon(buttonSizePx: number): SVGSVGElement {\n const svgNs = 'http://www.w3.org/2000/svg';\n const iconSizePx = Math.round(buttonSizePx * 0.375);\n const svg = document.createElementNS(svgNs, 'svg');\n svg.setAttribute('viewBox', '0 0 24 24');\n svg.setAttribute('width', String(iconSizePx));\n svg.setAttribute('height', String(iconSizePx));\n svg.setAttribute('fill', 'none');\n svg.setAttribute('stroke', 'currentColor');\n svg.setAttribute('stroke-width', '2.5');\n svg.setAttribute('stroke-linecap', 'round');\n svg.setAttribute('aria-hidden', 'true');\n\n const diagonal1 = document.createElementNS(svgNs, 'line');\n diagonal1.setAttribute('x1', '5');\n diagonal1.setAttribute('y1', '5');\n diagonal1.setAttribute('x2', '19');\n diagonal1.setAttribute('y2', '19');\n\n const diagonal2 = document.createElementNS(svgNs, 'line');\n diagonal2.setAttribute('x1', '19');\n diagonal2.setAttribute('y1', '5');\n diagonal2.setAttribute('x2', '5');\n diagonal2.setAttribute('y2', '19');\n\n svg.append(diagonal1, diagonal2);\n return svg;\n}\n\n/** Builds the header row hosting the close button, or `null` when the button is hidden. */\nfunction createCloseButtonHeader(options: EmojiPickerCloseButtonOptions): {\n header: HTMLDivElement;\n button: HTMLButtonElement;\n} | null {\n if (options.hidden) {\n return null;\n }\n const sizePx = CLOSE_BUTTON_SIZE_PX[options.size ?? 'medium'];\n const position = options.position ?? 'right';\n\n const header = document.createElement('div');\n header.className = 'emoji-picker-sheet__header';\n header.style.justifyContent = position === 'left' ? 'flex-start' : position === 'center' ? 'center' : 'flex-end';\n\n const button = document.createElement('button');\n button.type = 'button';\n button.className = 'emoji-picker-sheet__close';\n button.setAttribute('aria-label', 'Close');\n button.style.width = `${sizePx}px`;\n button.style.height = `${sizePx}px`;\n button.appendChild(createCloseIcon(sizePx));\n\n header.appendChild(button);\n return { header, button };\n}\n\nexport interface WebEmojiPickerPresenterOptions {\n /** Creates the picker element. Overridable for testing. */\n createPickerElement?: () => Promise<EmojiPickerElement>;\n}\n\n/**\n * Presents `emoji-picker-element` in a bottom-sheet `<dialog>` and resolves with the selected emoji.\n *\n * Kept independent of the Capacitor web plugin registration so native-platform fallback\n * orchestration (issue #6) can present the same web picker from inside a native WebView.\n */\nexport class WebEmojiPickerPresenter {\n private readonly createPickerElement: () => Promise<EmojiPickerElement>;\n\n public constructor(options: WebEmojiPickerPresenterOptions = {}) {\n this.createPickerElement = options.createPickerElement ?? defaultCreatePickerElement;\n }\n\n public async present(\n options: EmojiPickerOptions = {},\n presentOptions: { signal?: AbortSignal } = {}\n ): Promise<EmojiPickerResult> {\n const { signal } = presentOptions;\n const closeButtonOptions = options.closeButton ?? {};\n // A hidden close button must never leave the user with zero ways to dismiss the picker,\n // so hiding it force-enables backdrop-tap-to-dismiss regardless of what was explicitly\n // requested (mirrors the iOS presenter's `effectiveDismissOnBackdropTap`).\n const dismissOnBackdropTap = (options.dismissOnBackdropTap ?? true) || (closeButtonOptions.hidden ?? false);\n\n // Resolved once at open time (rather than left to each side's own live\n // `prefers-color-scheme` tracking) so the picker and the sheet chrome around it always\n // agree, fixing the mismatch from issue #19.\n const resolvedTheme = resolveTheme(options.theme);\n\n let picker: EmojiPickerElement;\n try {\n picker = await this.createPickerElement();\n picker.dataSource = getBundledEmojiDataSourceUrl();\n picker.classList.add(resolvedTheme);\n } catch {\n throw new Error(ErrorCodes.NOT_IMPLEMENTED);\n }\n\n ensureSheetStylesInjected();\n\n picker.style.display = 'block';\n picker.style.width = '100%';\n picker.style.flex = '1 1 auto';\n picker.style.minHeight = '0';\n // The picker's own card look (border + background) would otherwise float as a visibly\n // smaller box inside the sheet; matching its background to the sheet's and dropping its\n // border makes it read as full width, part of the sheet rather than nested inside it.\n picker.style.setProperty('--background', SHEET_BACKGROUND_COLOR[resolvedTheme]);\n picker.style.setProperty('--border-size', '0');\n\n const dialog = document.createElement('dialog');\n dialog.className = `emoji-picker-sheet emoji-picker-sheet--${resolvedTheme}`;\n dialog.setAttribute('role', 'dialog');\n dialog.setAttribute('aria-modal', 'true');\n dialog.setAttribute('aria-label', 'Emoji picker');\n\n const closeButtonHeader = createCloseButtonHeader(closeButtonOptions);\n if (closeButtonHeader) {\n // With the picker's own border removed above, this is the only visual separation\n // between the close button and the picker.\n picker.style.borderTop = '1px solid rgba(127, 127, 127, 0.3)';\n }\n\n return new Promise<EmojiPickerResult>((resolve) => {\n let settled = false;\n let pointerDownOnDialog = false;\n\n const previouslyFocusedElement = document.activeElement as HTMLElement | null;\n const previousBodyOverflow = document.body.style.overflow;\n\n const onUnhandledRejection = (event: PromiseRejectionEvent) => {\n if (isKnownBlobHeadCheckRejection(event.reason)) {\n event.preventDefault();\n }\n };\n\n const finish = (result: EmojiPickerResult) => {\n window.removeEventListener('unhandledrejection', onUnhandledRejection);\n document.body.style.overflow = previousBodyOverflow;\n dialog.close();\n dialog.remove();\n\n if (previouslyFocusedElement instanceof HTMLElement && document.contains(previouslyFocusedElement)) {\n previouslyFocusedElement.focus?.();\n }\n\n resolve(result);\n };\n\n const settle = (result: EmojiPickerResult) => {\n if (settled) {\n return;\n }\n settled = true;\n picker.removeEventListener('emoji-click', onEmojiClick as EventListener);\n dialog.removeEventListener('pointerdown', onDialogPointerDown);\n dialog.removeEventListener('click', onDialogClick);\n dialog.removeEventListener('cancel', onCancel);\n document.removeEventListener('keydown', onKeyDown);\n closeButtonHeader?.button.removeEventListener('click', onCloseButtonClick);\n signal?.removeEventListener('abort', onAbort);\n\n dialog.removeAttribute('data-state');\n\n if (prefersReducedMotion()) {\n finish(result);\n } else {\n setTimeout(() => finish(result), ANIMATION_MS);\n }\n };\n\n const onEmojiClick = (event: CustomEvent<{ unicode?: string }>) => {\n settle({ emoji: event.detail.unicode ?? null });\n };\n\n const onDialogPointerDown = (event: PointerEvent) => {\n pointerDownOnDialog = event.target === dialog;\n };\n\n const onDialogClick = (event: MouseEvent) => {\n if (dismissOnBackdropTap && event.target === dialog && pointerDownOnDialog) {\n settle({ emoji: null });\n }\n };\n\n // The dialog's native `cancel` event covers real browsers, where it fires\n // automatically on Escape and its default action would otherwise close the dialog\n // instantly, skipping the close animation. The `keydown` listener is a fallback for\n // environments (e.g. jsdom in tests) that don't implement dialog cancellation;\n // `settle` is idempotent, so both firing for the same keypress is harmless.\n const onCancel = (event: Event) => {\n event.preventDefault();\n settle({ emoji: null });\n };\n\n const onKeyDown = (event: KeyboardEvent) => {\n if (event.key === 'Escape') {\n settle({ emoji: null });\n }\n };\n\n const onCloseButtonClick = () => {\n settle({ emoji: null });\n };\n\n const onAbort = () => {\n settle({ emoji: null });\n };\n\n if (signal?.aborted) {\n resolve({ emoji: null });\n return;\n }\n signal?.addEventListener('abort', onAbort);\n\n picker.addEventListener('emoji-click', onEmojiClick as EventListener);\n dialog.addEventListener('pointerdown', onDialogPointerDown);\n dialog.addEventListener('click', onDialogClick);\n dialog.addEventListener('cancel', onCancel);\n document.addEventListener('keydown', onKeyDown);\n window.addEventListener('unhandledrejection', onUnhandledRejection);\n closeButtonHeader?.button.addEventListener('click', onCloseButtonClick);\n\n if (closeButtonHeader) {\n dialog.appendChild(closeButtonHeader.header);\n }\n dialog.appendChild(picker);\n document.body.appendChild(dialog);\n document.body.style.overflow = 'hidden';\n dialog.showModal();\n\n requestAnimationFrame(() => {\n dialog.setAttribute('data-state', 'open');\n });\n\n picker.focus?.();\n });\n }\n}\n"]}
|