@independo/capacitor-emoji-picker 1.3.7-dev.1 → 1.3.7-dev.3
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 +41 -12
- package/android/build.gradle +2 -0
- package/android/src/main/java/app/independo/capacitoremojipicker/EmojiPicker.java +13 -3
- package/dist/docs.json +1 -1
- package/dist/esm/definitions.d.ts +13 -13
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/platform/web/WebEmojiPickerPresenter.d.ts +4 -3
- package/dist/esm/platform/web/WebEmojiPickerPresenter.js +20 -30
- package/dist/esm/platform/web/WebEmojiPickerPresenter.js.map +1 -1
- package/dist/esm/platform/web/emoji-data-source.d.ts +18 -9
- package/dist/esm/platform/web/emoji-data-source.js +56 -17
- package/dist/esm/platform/web/emoji-data-source.js.map +1 -1
- package/dist/esm/platform/web/locales/en.d.ts +3 -3
- package/dist/esm/platform/web/locales/en.js +4 -5
- package/dist/esm/platform/web/locales/en.js.map +1 -1
- package/dist/esm/platform/web/locales/index.d.ts +5 -4
- package/dist/esm/platform/web/locales/index.js +5 -4
- package/dist/esm/platform/web/locales/index.js.map +1 -1
- package/dist/plugin.cjs.js +87 -53
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +87 -53
- package/dist/plugin.js.map +1 -1
- package/ios/Sources/EmojiPicker/Bridge/EmojiPicker.swift +1 -1
- package/ios/Sources/EmojiPicker/Core/EmojiPickerResult.swift +6 -0
- package/package.json +7 -2
package/README.md
CHANGED
|
@@ -151,9 +151,38 @@ platform including Android and iOS.
|
|
|
151
151
|
Native-presentation failures fall back to the web picker automatically. User cancellation (dismissing the picker
|
|
152
152
|
without selecting an emoji) always resolves with `{ emoji: null }` and never triggers a fallback.
|
|
153
153
|
|
|
154
|
-
The web picker
|
|
155
|
-
fetching it from `emoji-picker-element`'s default CDN)
|
|
156
|
-
|
|
154
|
+
The web picker hands its emoji dataset to `emoji-picker-element` as a `data:` URL (rather than
|
|
155
|
+
fetching it from `emoji-picker-element`'s default CDN), so the bundled and registered locales work offline.
|
|
156
|
+
Apps with a restrictive Content-Security-Policy should allow `data:` in `connect-src` (or `default-src`) for
|
|
157
|
+
this dataset to load. A `data:` URL rather than a `blob:` one because `emoji-picker-element` checks its cached
|
|
158
|
+
copy of the dataset with a `HEAD` request, which `blob:` URLs reject.
|
|
159
|
+
|
|
160
|
+
A CSP that allows `blob:` but not `data:` in `connect-src` still works: the plugin probes once per page load
|
|
161
|
+
whether the page may fetch a `data:` URL and falls back to a `blob:` URL if not. In that legacy mode the
|
|
162
|
+
`HEAD` request on a cached dataset fails, so a warm open (IndexedDB already populated) may log an unhandled
|
|
163
|
+
`TypeError: Failed to fetch` rejection, and the cached dataset is never refreshed. Allow `data:` to avoid it.
|
|
164
|
+
|
|
165
|
+
The probe is a `fetch('data:application/json,{}', { method: 'HEAD' })`. When the CSP blocks `data:`, the browser
|
|
166
|
+
fires a `securitypolicyviolation` event for it and, with `report-uri` or `report-to`, sends a CSP violation
|
|
167
|
+
report, on the first picker open of each page load. Catching the rejection does not suppress the report. Hosts
|
|
168
|
+
with CSP reporting should allow `data:` in `connect-src` (or `default-src`): that removes both the report and
|
|
169
|
+
the unhandled rejection. A `blob:`-only CSP keeps working but produces one violation report per page load.
|
|
170
|
+
|
|
171
|
+
On web, `emoji-picker-element` logs the warning `emoji-picker-element is more efficient if the dataSource
|
|
172
|
+
server exposes an ETag header.` (`console.warn`, about twice per open) because `data:` responses carry no
|
|
173
|
+
ETag. It is harmless; hosts that forward `console.warn` to telemetry can filter that exact message.
|
|
174
|
+
|
|
175
|
+
The web picker loads its code lazily. The first `present()` on web fetches these chunks: the web
|
|
176
|
+
implementation, `emoji-picker-element`, its `emoji-picker-element/database` module (only when `skinTone`
|
|
177
|
+
is set), the `en` dataset, and the loader of any other locale you registered. The first three were already
|
|
178
|
+
lazy; `en` is now one more chunk in the same set.
|
|
179
|
+
|
|
180
|
+
A web host that must open the picker offline for the first time has to precache these chunks (service worker)
|
|
181
|
+
or prefetch them. Without them, a failed load of `emoji-picker-element` or of the dataset makes `present()`
|
|
182
|
+
reject with `NOT_IMPLEMENTED`. A failed load of the web implementation chunk, or of the database module
|
|
183
|
+
when `skinTone` is set, rejects with the underlying import error instead. Common setups (Angular service
|
|
184
|
+
worker, Workbox, `vite-plugin-pwa`) already precache `*.js`. Native apps (Capacitor iOS and Android) serve
|
|
185
|
+
every chunk from the app bundle and are not affected.
|
|
157
186
|
|
|
158
187
|
Behavior that can't be reliably simulated in automated tests (especially the iOS system emoji keyboard) has a
|
|
159
188
|
manual QA checklist: see [`docs/MANUAL_QA.md`](./docs/MANUAL_QA.md).
|
|
@@ -226,15 +255,15 @@ Result of presenting the emoji picker.
|
|
|
226
255
|
|
|
227
256
|
Options for presenting the emoji picker.
|
|
228
257
|
|
|
229
|
-
| Prop | Type | Description
|
|
230
|
-
| -------------------------- | --------------------------------------------------------------------------------------- |
|
|
231
|
-
| **`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.
|
|
232
|
-
| **`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.
|
|
233
|
-
| **`backdrop`** | <code><a href="#emojipickerbackdropoptions">EmojiPickerBackdropOptions</a></code> | Configures the dimming/blur shown behind the picker.
|
|
234
|
-
| **`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.
|
|
235
|
-
| **`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).
|
|
236
|
-
| **`locale`** | <code><a href="#emojipickerlocale">EmojiPickerLocale</a></code> | BCP-47-ish locale code for the emoji dataset/UI strings (e.g. `'en'`, `'de'`, `'fr'`). Web only — ignored on iOS/Android, which follow the device locale automatically via the system emoji keyboard/`androidx.emoji2.emojipicker`. `'en'` is the only locale bundled and available offline by default; any other locale is fetched from a CDN at present-time unless registered ahead of time via `registerEmojiLocale`. Every locale `emoji-picker-element-data` ships is available as an
|
|
237
|
-
| **`skinTone`** | <code>0 \| 1 \| 2 \| 5 \| 4 \| 3</code> | Seeds the picker's starting skin tone (`0` = none/default, `1`-`5` = light through dark). Web only — iOS/Android use the OS's own last-selected skin tone. On web, the underlying picker persists the user's own choice after this via IndexedDB (keyed by `locale`), so this only affects the very first render for a given locale/origin.
|
|
258
|
+
| Prop | Type | Description | Default |
|
|
259
|
+
| -------------------------- | --------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- |
|
|
260
|
+
| **`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> |
|
|
261
|
+
| **`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. | |
|
|
262
|
+
| **`backdrop`** | <code><a href="#emojipickerbackdropoptions">EmojiPickerBackdropOptions</a></code> | Configures the dimming/blur shown behind the picker. | |
|
|
263
|
+
| **`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> |
|
|
264
|
+
| **`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> |
|
|
265
|
+
| **`locale`** | <code><a href="#emojipickerlocale">EmojiPickerLocale</a></code> | BCP-47-ish locale code for the emoji dataset/UI strings (e.g. `'en'`, `'de'`, `'fr'`). Web only — ignored on iOS/Android, which follow the device locale automatically via the system emoji keyboard/`androidx.emoji2.emojipicker`. `'en'` is the only locale bundled and available offline by default; any other locale is fetched from a CDN at present-time unless registered ahead of time via `registerEmojiLocale`. Every locale `emoji-picker-element-data` ships is available as an individual loader module (e.g. `en-gb`, `pt`, `zh-hant`, ...) under `@independo/capacitor-emoji-picker/dist/esm/platform/web/locales/` (for example `.../locales/pt`); its default export carries its own code as a typed `.locale` property. An app can register — and pass to this option — any of them offline without a CDN dependency by importing only the ones it needs: ```ts import { registerEmojiLocale } from '@independo/capacitor-emoji-picker'; import ptLocale from '@independo/capacitor-emoji-picker/dist/esm/platform/web/locales/pt'; registerEmojiLocale(ptLocale.locale, await ptLocale()); EmojiPicker.present({ locale: ptLocale.locale }); ``` Import the per-locale module, not the `.../locales` index: a bundler tree-shakes the unused loaders of the index from the module graph, but bundlers such as esbuild still write every locale's dataset file (~14 MB in total) into the build output. This is a deep import rather than a root-level export deliberately: the package root is also the standalone `dist/plugin.js` bundle's entry point, which inlines every dynamic import it can reach (there's no code-splitting in that single-file build). | <code>'en'</code> |
|
|
266
|
+
| **`skinTone`** | <code>0 \| 1 \| 2 \| 5 \| 4 \| 3</code> | Seeds the picker's starting skin tone (`0` = none/default, `1`-`5` = light through dark). Web only — iOS/Android use the OS's own last-selected skin tone. On web, the underlying picker persists the user's own choice after this via IndexedDB (keyed by `locale`), so this only affects the very first render for a given locale/origin. | <code>0</code> |
|
|
238
267
|
|
|
239
268
|
|
|
240
269
|
#### EmojiPickerCloseButtonOptions
|
package/android/build.gradle
CHANGED
|
@@ -79,6 +79,8 @@ dependencies {
|
|
|
79
79
|
// relying on it being pulled in transitively via material) for the same reason.
|
|
80
80
|
implementation "androidx.recyclerview:recyclerview:$androidxRecyclerViewVersion"
|
|
81
81
|
testImplementation "junit:junit:$junitVersion"
|
|
82
|
+
// Android unit tests only get a stubbed org.json; JSObject (a JSONObject) needs the real one.
|
|
83
|
+
testImplementation "org.json:json:20240303"
|
|
82
84
|
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
|
|
83
85
|
androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
|
|
84
86
|
}
|
|
@@ -20,6 +20,7 @@ import java.util.Arrays;
|
|
|
20
20
|
import java.util.HashSet;
|
|
21
21
|
import java.util.Set;
|
|
22
22
|
import java.util.regex.Pattern;
|
|
23
|
+
import org.json.JSONObject;
|
|
23
24
|
|
|
24
25
|
/** Capacitor bridge for the EmojiPicker plugin. */
|
|
25
26
|
@CapacitorPlugin(name = "EmojiPicker")
|
|
@@ -81,9 +82,7 @@ public class EmojiPicker extends Plugin {
|
|
|
81
82
|
new EmojiPickerCallback() {
|
|
82
83
|
@Override
|
|
83
84
|
public void onResult(EmojiPickerResult result) {
|
|
84
|
-
|
|
85
|
-
ret.put("emoji", result.getEmoji());
|
|
86
|
-
call.resolve(ret);
|
|
85
|
+
call.resolve(buildResultObject(result));
|
|
87
86
|
}
|
|
88
87
|
|
|
89
88
|
@Override
|
|
@@ -93,4 +92,15 @@ public class EmojiPicker extends Plugin {
|
|
|
93
92
|
}
|
|
94
93
|
);
|
|
95
94
|
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Builds the JS result. {@code JSObject} extends {@code JSONObject}, where {@code put(name, null)} removes the key,
|
|
98
|
+
* so a dismissal must be written as {@code JSONObject.NULL} for JS to receive {@code {emoji: null}}.
|
|
99
|
+
*/
|
|
100
|
+
static JSObject buildResultObject(EmojiPickerResult result) {
|
|
101
|
+
JSObject ret = new JSObject();
|
|
102
|
+
String emoji = result.getEmoji();
|
|
103
|
+
ret.put("emoji", emoji != null ? emoji : JSONObject.NULL);
|
|
104
|
+
return ret;
|
|
105
|
+
}
|
|
96
106
|
}
|
package/dist/docs.json
CHANGED
|
@@ -130,7 +130,7 @@
|
|
|
130
130
|
"name": "default"
|
|
131
131
|
}
|
|
132
132
|
],
|
|
133
|
-
"docs": "BCP-47-ish locale code for the emoji dataset/UI strings (e.g. `'en'`, `'de'`, `'fr'`).\n\nWeb only — ignored on iOS/Android, which follow the device locale automatically via the\nsystem emoji keyboard/`androidx.emoji2.emojipicker`. `'en'` is the only locale bundled and\navailable offline by default; any other locale is fetched from a CDN at present-time unless\nregistered ahead of time via `registerEmojiLocale`.\n\nEvery locale `emoji-picker-element-data` ships is available as an
|
|
133
|
+
"docs": "BCP-47-ish locale code for the emoji dataset/UI strings (e.g. `'en'`, `'de'`, `'fr'`).\n\nWeb only — ignored on iOS/Android, which follow the device locale automatically via the\nsystem emoji keyboard/`androidx.emoji2.emojipicker`. `'en'` is the only locale bundled and\navailable offline by default; any other locale is fetched from a CDN at present-time unless\nregistered ahead of time via `registerEmojiLocale`.\n\nEvery locale `emoji-picker-element-data` ships is available as an individual loader module\n(e.g. `en-gb`, `pt`, `zh-hant`, ...) under\n`@independo/capacitor-emoji-picker/dist/esm/platform/web/locales/` (for example\n`.../locales/pt`); its default export carries its own code as a typed `.locale`\nproperty. An app can register — and pass to this option — any of them offline without a CDN dependency by importing only the ones it needs:\n```ts\nimport { registerEmojiLocale } from '@independo/capacitor-emoji-picker';\nimport ptLocale from '@independo/capacitor-emoji-picker/dist/esm/platform/web/locales/pt';\nregisterEmojiLocale(ptLocale.locale, await ptLocale());\nEmojiPicker.present({ locale: ptLocale.locale });\n```\nImport the per-locale module, not the `.../locales` index: a bundler tree-shakes the unused\nloaders of the index from the module graph, but bundlers such as esbuild still write every\nlocale's dataset file (~14 MB in total) into the build output. This is a deep import rather\nthan a root-level export deliberately: the package root is also the standalone\n`dist/plugin.js` bundle's entry point, which inlines every dynamic import it can reach\n(there's no code-splitting in that single-file build).",
|
|
134
134
|
"complexTypes": [
|
|
135
135
|
"EmojiPickerLocale"
|
|
136
136
|
],
|
|
@@ -61,23 +61,23 @@ export interface EmojiPickerOptions {
|
|
|
61
61
|
* available offline by default; any other locale is fetched from a CDN at present-time unless
|
|
62
62
|
* registered ahead of time via `registerEmojiLocale`.
|
|
63
63
|
*
|
|
64
|
-
* Every locale `emoji-picker-element-data` ships is available as an
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
* offline without a CDN dependency by importing only the ones it needs:
|
|
64
|
+
* Every locale `emoji-picker-element-data` ships is available as an individual loader module
|
|
65
|
+
* (e.g. `en-gb`, `pt`, `zh-hant`, ...) under
|
|
66
|
+
* `@independo/capacitor-emoji-picker/dist/esm/platform/web/locales/` (for example
|
|
67
|
+
* `.../locales/pt`); its default export carries its own code as a typed `.locale`
|
|
68
|
+
* property. An app can register — and pass to this option — any of them offline without a CDN dependency by importing only the ones it needs:
|
|
69
69
|
* ```ts
|
|
70
|
-
* import { registerEmojiLocale } from 'capacitor-emoji-picker';
|
|
71
|
-
* import
|
|
70
|
+
* import { registerEmojiLocale } from '@independo/capacitor-emoji-picker';
|
|
71
|
+
* import ptLocale from '@independo/capacitor-emoji-picker/dist/esm/platform/web/locales/pt';
|
|
72
72
|
* registerEmojiLocale(ptLocale.locale, await ptLocale());
|
|
73
73
|
* EmojiPicker.present({ locale: ptLocale.locale });
|
|
74
74
|
* ```
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
75
|
+
* Import the per-locale module, not the `.../locales` index: a bundler tree-shakes the unused
|
|
76
|
+
* loaders of the index from the module graph, but bundlers such as esbuild still write every
|
|
77
|
+
* locale's dataset file (~14 MB in total) into the build output. This is a deep import rather
|
|
78
|
+
* than a root-level export deliberately: the package root is also the standalone
|
|
79
|
+
* `dist/plugin.js` bundle's entry point, which inlines every dynamic import it can reach
|
|
80
|
+
* (there's no code-splitting in that single-file build).
|
|
81
81
|
* @default 'en'
|
|
82
82
|
*/
|
|
83
83
|
locale?: EmojiPickerLocale;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["import type { EmojiPickerLocaleCode } from './core/emoji-locale';\n\n/**\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 * A locale code `emoji-picker-element-data` ships a dataset for, usable with\n * `EmojiPickerOptions.locale`/`registerEmojiLocale`. Widened to accept any other string too, so a\n * locale registered under a code outside this list still type-checks.\n */\n// `string & {}` is the standard trick for \"literal union with editor autocomplete, but any\n// string still type-checks\".\nexport type EmojiPickerLocale = EmojiPickerLocaleCode | (string & {});\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 * Configures the dimming/blur shown behind the picker.\n */\n backdrop?: EmojiPickerBackdropOptions;\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 * BCP-47-ish locale code for the emoji dataset/UI strings (e.g. `'en'`, `'de'`, `'fr'`).\n *\n * Web only — ignored on iOS/Android, which follow the device locale automatically via the\n * system emoji keyboard/`androidx.emoji2.emojipicker`. `'en'` is the only locale bundled and\n * available offline by default; any other locale is fetched from a CDN at present-time unless\n * registered ahead of time via `registerEmojiLocale`.\n *\n * Every locale `emoji-picker-element-data` ships is available as an
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["import type { EmojiPickerLocaleCode } from './core/emoji-locale';\n\n/**\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 * A locale code `emoji-picker-element-data` ships a dataset for, usable with\n * `EmojiPickerOptions.locale`/`registerEmojiLocale`. Widened to accept any other string too, so a\n * locale registered under a code outside this list still type-checks.\n */\n// `string & {}` is the standard trick for \"literal union with editor autocomplete, but any\n// string still type-checks\".\nexport type EmojiPickerLocale = EmojiPickerLocaleCode | (string & {});\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 * Configures the dimming/blur shown behind the picker.\n */\n backdrop?: EmojiPickerBackdropOptions;\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 * BCP-47-ish locale code for the emoji dataset/UI strings (e.g. `'en'`, `'de'`, `'fr'`).\n *\n * Web only — ignored on iOS/Android, which follow the device locale automatically via the\n * system emoji keyboard/`androidx.emoji2.emojipicker`. `'en'` is the only locale bundled and\n * available offline by default; any other locale is fetched from a CDN at present-time unless\n * registered ahead of time via `registerEmojiLocale`.\n *\n * Every locale `emoji-picker-element-data` ships is available as an individual loader module\n * (e.g. `en-gb`, `pt`, `zh-hant`, ...) under\n * `@independo/capacitor-emoji-picker/dist/esm/platform/web/locales/` (for example\n * `.../locales/pt`); its default export carries its own code as a typed `.locale`\n * property. An app can register — and pass to this option — any of them offline without a CDN dependency by importing only the ones it needs:\n * ```ts\n * import { registerEmojiLocale } from '@independo/capacitor-emoji-picker';\n * import ptLocale from '@independo/capacitor-emoji-picker/dist/esm/platform/web/locales/pt';\n * registerEmojiLocale(ptLocale.locale, await ptLocale());\n * EmojiPicker.present({ locale: ptLocale.locale });\n * ```\n * Import the per-locale module, not the `.../locales` index: a bundler tree-shakes the unused\n * loaders of the index from the module graph, but bundlers such as esbuild still write every\n * locale's dataset file (~14 MB in total) into the build output. This is a deep import rather\n * than a root-level export deliberately: the package root is also the standalone\n * `dist/plugin.js` bundle's entry point, which inlines every dynamic import it can reach\n * (there's no code-splitting in that single-file build).\n * @default 'en'\n */\n locale?: EmojiPickerLocale;\n /**\n * Seeds the picker's starting skin tone (`0` = none/default, `1`-`5` = light through dark).\n *\n * Web only — iOS/Android use the OS's own last-selected skin tone. On web, the underlying\n * picker persists the user's own choice after this via IndexedDB (keyed by `locale`), so this\n * only affects the very first render for a given locale/origin.\n * @default 0\n */\n skinTone?: 0 | 1 | 2 | 3 | 4 | 5;\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 * Configures the dimming/blur shown behind the picker.\n */\nexport interface EmojiPickerBackdropOptions {\n /**\n * CSS hex color for the backdrop; the alpha channel controls darkness (e.g. `'#000000cc'` is\n * 80% black, `'#00000000'` is no darkening). Supports `#RGB`, `#RRGGBB`, and `#RRGGBBAA`.\n * Falls back to the default on an invalid value.\n * @default '#00000066'\n */\n color?: string;\n /**\n * Backdrop blur radius in px, analogous to CSS `backdrop-filter: blur()`.\n *\n * Web applies this directly. iOS approximates it by mapping the value to the nearest system\n * blur material (there is no continuous-radius blur API). Android has no API to blur content\n * behind a dialog window, so this option is accepted but has no visual effect there.\n * @default 0\n */\n blur?: number;\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,4 +1,5 @@
|
|
|
1
1
|
import type { EmojiPickerOptions, EmojiPickerResult } from '../../definitions';
|
|
2
|
+
import type { EmojiDataSource } from './emoji-data-source';
|
|
2
3
|
/** Minimal shape of the `<emoji-picker>` custom element this presenter depends on. */
|
|
3
4
|
export interface EmojiPickerElement extends HTMLElement {
|
|
4
5
|
dataSource: string;
|
|
@@ -13,9 +14,9 @@ export interface WebEmojiPickerPresenterOptions {
|
|
|
13
14
|
/** Creates the picker element with its locale and data source. Overridable for testing. */
|
|
14
15
|
createPickerElement?: (props: EmojiPickerElementProps) => Promise<EmojiPickerElement>;
|
|
15
16
|
/** Seeds the locale's persisted preferred skin tone. Overridable for testing. */
|
|
16
|
-
seedSkinTone?: (locale: string, skinTone: number) => Promise<void>;
|
|
17
|
-
/** Resolves the `dataSource` URL for a locale. Overridable for testing. */
|
|
18
|
-
getDataSourceUrl?: (locale: string) => Promise<
|
|
17
|
+
seedSkinTone?: (locale: string, skinTone: number, dataSource: string) => Promise<void>;
|
|
18
|
+
/** Resolves the `dataSource` URL, and the locale it serves, for a requested locale. Overridable for testing. */
|
|
19
|
+
getDataSourceUrl?: (locale: string) => Promise<EmojiDataSource>;
|
|
19
20
|
}
|
|
20
21
|
/**
|
|
21
22
|
* Presents `emoji-picker-element` in a bottom-sheet `<dialog>` and resolves with the selected emoji.
|
|
@@ -20,21 +20,6 @@ async function defaultCreatePickerElement(props) {
|
|
|
20
20
|
picker.locale = props.locale;
|
|
21
21
|
return picker;
|
|
22
22
|
}
|
|
23
|
-
/**
|
|
24
|
-
* `emoji-picker-element`'s internal `Database` runs a background `fetch(dataSource, { method: 'HEAD' })`
|
|
25
|
-
* freshness check whenever it already has cached data for the locale (i.e. on the second+ open in a
|
|
26
|
-
* session). Non-`GET` requests to `blob:` URLs always throw `TypeError` per the Fetch spec, and this
|
|
27
|
-
* internal call isn't awaited, so it otherwise surfaces as a noisy but harmless `unhandledrejection`.
|
|
28
|
-
* This filters out only that specific rejection shape while a picker is open, letting everything else
|
|
29
|
-
* propagate normally to the host app.
|
|
30
|
-
*/
|
|
31
|
-
function isKnownBlobHeadCheckRejection(reason) {
|
|
32
|
-
var _a, _b;
|
|
33
|
-
if (!(reason instanceof TypeError) || !reason.message.includes('Failed to fetch')) {
|
|
34
|
-
return false;
|
|
35
|
-
}
|
|
36
|
-
return (_b = (_a = reason.stack) === null || _a === void 0 ? void 0 : _a.includes('getETag')) !== null && _b !== void 0 ? _b : false;
|
|
37
|
-
}
|
|
38
23
|
const SHEET_STYLE_ELEMENT_ID = 'emoji-picker-sheet-styles';
|
|
39
24
|
const ANIMATION_MS = 200;
|
|
40
25
|
/** Injects the bottom-sheet stylesheet into `document.head`, once per document. */
|
|
@@ -215,10 +200,13 @@ function createCloseButtonHeader(options) {
|
|
|
215
200
|
* Seeds `locale`'s persisted preferred skin tone via `emoji-picker-element`'s own `Database`, so
|
|
216
201
|
* `<emoji-picker>` picks it up as its default on render. A no-op for `skinTone === undefined`,
|
|
217
202
|
* so an already-made user choice (persisted in IndexedDB) is never overwritten.
|
|
203
|
+
*
|
|
204
|
+
* The `Database` gets the picker's own `dataSource`: left at its jsDelivr default, it would load
|
|
205
|
+
* an empty database from the CDN (failing offline) and check a cached one against the CDN.
|
|
218
206
|
*/
|
|
219
|
-
async function defaultSeedSkinTone(locale, skinTone) {
|
|
207
|
+
async function defaultSeedSkinTone(locale, skinTone, dataSource) {
|
|
220
208
|
const { default: Database } = await import('emoji-picker-element/database');
|
|
221
|
-
const db = new Database({ locale });
|
|
209
|
+
const db = new Database({ locale, dataSource });
|
|
222
210
|
await db.setPreferredSkinTone(skinTone);
|
|
223
211
|
}
|
|
224
212
|
/**
|
|
@@ -246,22 +234,31 @@ export class WebEmojiPickerPresenter {
|
|
|
246
234
|
// `prefers-color-scheme` tracking) so the picker and the sheet chrome around it always
|
|
247
235
|
// agree, fixing the mismatch from issue #19.
|
|
248
236
|
const resolvedTheme = resolveTheme(options.theme);
|
|
249
|
-
|
|
237
|
+
let locale = (_d = options.locale) !== null && _d !== void 0 ? _d : 'en';
|
|
238
|
+
let dataSource;
|
|
239
|
+
try {
|
|
240
|
+
// Resolved before the element exists, so it never starts with the default data source
|
|
241
|
+
// (see `defaultCreatePickerElement`). The resolver may have fallen back to another
|
|
242
|
+
// locale's data; the picker and the skin-tone seed must then use that locale too, or
|
|
243
|
+
// `emoji-picker-element` would file the fallback data under the requested locale's
|
|
244
|
+
// IndexedDB database and overwrite its cached copy.
|
|
245
|
+
({ locale, url: dataSource } = await this.getDataSourceUrl(locale));
|
|
246
|
+
}
|
|
247
|
+
catch (_f) {
|
|
248
|
+
throw new Error(ErrorCodes.NOT_IMPLEMENTED);
|
|
249
|
+
}
|
|
250
250
|
if (options.skinTone !== undefined) {
|
|
251
251
|
// Seeded before the element is created so its initial render already reflects it.
|
|
252
|
-
await this.seedSkinTone(locale, options.skinTone);
|
|
252
|
+
await this.seedSkinTone(locale, options.skinTone, dataSource);
|
|
253
253
|
}
|
|
254
254
|
let picker;
|
|
255
255
|
try {
|
|
256
|
-
// Resolved before the element exists, so it never starts with the default data source
|
|
257
|
-
// (see `defaultCreatePickerElement`).
|
|
258
|
-
const dataSource = await this.getDataSourceUrl(locale);
|
|
259
256
|
picker = await this.createPickerElement({ locale, dataSource });
|
|
260
257
|
picker.dataSource = dataSource;
|
|
261
258
|
picker.locale = locale;
|
|
262
259
|
picker.classList.add(resolvedTheme);
|
|
263
260
|
}
|
|
264
|
-
catch (
|
|
261
|
+
catch (_g) {
|
|
265
262
|
throw new Error(ErrorCodes.NOT_IMPLEMENTED);
|
|
266
263
|
}
|
|
267
264
|
ensureSheetStylesInjected();
|
|
@@ -292,14 +289,8 @@ export class WebEmojiPickerPresenter {
|
|
|
292
289
|
let pointerDownOnDialog = false;
|
|
293
290
|
const previouslyFocusedElement = document.activeElement;
|
|
294
291
|
const previousBodyOverflow = document.body.style.overflow;
|
|
295
|
-
const onUnhandledRejection = (event) => {
|
|
296
|
-
if (isKnownBlobHeadCheckRejection(event.reason)) {
|
|
297
|
-
event.preventDefault();
|
|
298
|
-
}
|
|
299
|
-
};
|
|
300
292
|
const finish = (result) => {
|
|
301
293
|
var _a;
|
|
302
|
-
window.removeEventListener('unhandledrejection', onUnhandledRejection);
|
|
303
294
|
document.body.style.overflow = previousBodyOverflow;
|
|
304
295
|
dialog.close();
|
|
305
296
|
dialog.remove();
|
|
@@ -371,7 +362,6 @@ export class WebEmojiPickerPresenter {
|
|
|
371
362
|
dialog.addEventListener('click', onDialogClick);
|
|
372
363
|
dialog.addEventListener('cancel', onCancel);
|
|
373
364
|
document.addEventListener('keydown', onKeyDown);
|
|
374
|
-
window.addEventListener('unhandledrejection', onUnhandledRejection);
|
|
375
365
|
closeButtonHeader === null || closeButtonHeader === void 0 ? void 0 : closeButtonHeader.button.addEventListener('click', onCloseButtonClick);
|
|
376
366
|
if (closeButtonHeader) {
|
|
377
367
|
dialog.appendChild(closeButtonHeader.header);
|
|
@@ -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;AAQpD,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAc5D;;;;;;;GAOG;AACH,KAAK,UAAU,0BAA0B,CAAC,KAA8B;IACpE,IAAI,CAAC;QACD,MAAM,MAAM,CAAC,sBAAsB,CAAC,CAAC;IACzC,CAAC;IAAC,WAAM,CAAC;QACL,MAAM,IAAI,KAAK,CAAC,UAAU,CAAC,eAAe,CAAC,CAAC;IAChD,CAAC;IACD,MAAM,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,cAAc,CAAkC,CAAC;IACvF,MAAM,CAAC,UAAU,GAAG,KAAK,CAAC,UAAU,CAAC;IACrC,MAAM,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;IAC7B,OAAO,MAAM,CAAC;AAClB,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,GA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,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 {\n EmojiPickerBackdropOptions,\n EmojiPickerCloseButtonOptions,\n EmojiPickerOptions,\n EmojiPickerResult,\n EmojiPickerTheme,\n} from '../../definitions';\nimport { getEmojiDataSourceUrl } 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 locale: string;\n}\n\n/** What the picker element is created with. */\nexport interface EmojiPickerElementProps {\n readonly locale: string;\n readonly dataSource: string;\n}\n\n/**\n * Registers `<emoji-picker>` (if needed) and creates the element with its locale and data source.\n *\n * The element's constructor queues the creation of its database in a microtask, with whatever\n * `locale` and `dataSource` are set by then - the jsDelivr default unless something else is.\n * Both are therefore set in the same synchronous step as `createElement`, before anything is\n * awaited, so that database is the only one and no request goes to the CDN.\n */\nasync function defaultCreatePickerElement(props: EmojiPickerElementProps): Promise<EmojiPickerElement> {\n try {\n await import('emoji-picker-element');\n } catch {\n throw new Error(ErrorCodes.NOT_IMPLEMENTED);\n }\n const picker = document.createElement('emoji-picker') as unknown as EmojiPickerElement;\n picker.dataSource = props.dataSource;\n picker.locale = props.locale;\n return picker;\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[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\nconst DEFAULT_BACKDROP_COLOR = '#00000066';\nconst HEX_COLOR_PATTERN = /^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/;\nlet backdropStyleCounter = 0;\n\n/** Validates a `#RGB`/`#RRGGBB`/`#RRGGBBAA` hex color, falling back to the default on any other input. */\nfunction resolveBackdropColor(color: string | undefined): string {\n if (color !== undefined && HEX_COLOR_PATTERN.test(color)) {\n return color;\n }\n return DEFAULT_BACKDROP_COLOR;\n}\n\n/** Injects a one-off `::backdrop` rule scoped to a unique class, since inline styles can't target it. */\nfunction injectBackdropStyle(options: EmojiPickerBackdropOptions): { className: string; remove: () => void } {\n const className = `emoji-picker-backdrop-${++backdropStyleCounter}`;\n const color = resolveBackdropColor(options.color);\n const blur = options.blur ?? 0;\n const style = document.createElement('style');\n // `backdrop-filter` is always set explicitly, never omitted: some browsers (e.g. Safari/WKWebView)\n // apply their own default blur to a <dialog>'s ::backdrop in their UA stylesheet, which would\n // otherwise leak through unopposed whenever the caller doesn't request blur.\n style.textContent = `\n dialog.${className}::backdrop {\n background: ${color};\n backdrop-filter: ${blur > 0 ? `blur(${blur}px)` : 'none'};\n }\n `;\n document.head.appendChild(style);\n return { className, remove: () => style.remove() };\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\n/**\n * Seeds `locale`'s persisted preferred skin tone via `emoji-picker-element`'s own `Database`, so\n * `<emoji-picker>` picks it up as its default on render. A no-op for `skinTone === undefined`,\n * so an already-made user choice (persisted in IndexedDB) is never overwritten.\n */\nasync function defaultSeedSkinTone(locale: string, skinTone: number): Promise<void> {\n const { default: Database } = await import('emoji-picker-element/database');\n const db = new Database({ locale });\n await db.setPreferredSkinTone(skinTone);\n}\n\nexport interface WebEmojiPickerPresenterOptions {\n /** Creates the picker element with its locale and data source. Overridable for testing. */\n createPickerElement?: (props: EmojiPickerElementProps) => Promise<EmojiPickerElement>;\n /** Seeds the locale's persisted preferred skin tone. Overridable for testing. */\n seedSkinTone?: (locale: string, skinTone: number) => Promise<void>;\n /** Resolves the `dataSource` URL for a locale. Overridable for testing. */\n getDataSourceUrl?: (locale: string) => Promise<string>;\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: (props: EmojiPickerElementProps) => Promise<EmojiPickerElement>;\n private readonly seedSkinTone: (locale: string, skinTone: number) => Promise<void>;\n private readonly getDataSourceUrl: (locale: string) => Promise<string>;\n\n public constructor(options: WebEmojiPickerPresenterOptions = {}) {\n this.createPickerElement = options.createPickerElement ?? defaultCreatePickerElement;\n this.seedSkinTone = options.seedSkinTone ?? defaultSeedSkinTone;\n this.getDataSourceUrl = options.getDataSourceUrl ?? getEmojiDataSourceUrl;\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 const locale = options.locale ?? 'en';\n\n if (options.skinTone !== undefined) {\n // Seeded before the element is created so its initial render already reflects it.\n await this.seedSkinTone(locale, options.skinTone);\n }\n\n let picker: EmojiPickerElement;\n try {\n // Resolved before the element exists, so it never starts with the default data source\n // (see `defaultCreatePickerElement`).\n const dataSource = await this.getDataSourceUrl(locale);\n picker = await this.createPickerElement({ locale, dataSource });\n picker.dataSource = dataSource;\n picker.locale = locale;\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 backdropStyle = injectBackdropStyle(options.backdrop ?? {});\n const dialog = document.createElement('dialog');\n dialog.className = `emoji-picker-sheet emoji-picker-sheet--${resolvedTheme} ${backdropStyle.className}`;\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 backdropStyle.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;AASpD,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAc5D;;;;;;;GAOG;AACH,KAAK,UAAU,0BAA0B,CAAC,KAA8B;IACpE,IAAI,CAAC;QACD,MAAM,MAAM,CAAC,sBAAsB,CAAC,CAAC;IACzC,CAAC;IAAC,WAAM,CAAC;QACL,MAAM,IAAI,KAAK,CAAC,UAAU,CAAC,eAAe,CAAC,CAAC;IAChD,CAAC;IACD,MAAM,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,cAAc,CAAkC,CAAC;IACvF,MAAM,CAAC,UAAU,GAAG,KAAK,CAAC,UAAU,CAAC;IACrC,MAAM,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;IAC7B,OAAO,MAAM,CAAC;AAClB,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,CAAC,OAAO,CAAC,CAAC;IAC9C,KAAK,CAAC,EAAE,GAAG,sBAAsB,CAAC;IAClC,KAAK,CAAC,WAAW,GAAG;;;;;;;;;;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AC;YAChD,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 {\n EmojiPickerBackdropOptions,\n EmojiPickerCloseButtonOptions,\n EmojiPickerOptions,\n EmojiPickerResult,\n EmojiPickerTheme,\n} from '../../definitions';\nimport type { EmojiDataSource } from './emoji-data-source';\nimport { getEmojiDataSourceUrl } 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 locale: string;\n}\n\n/** What the picker element is created with. */\nexport interface EmojiPickerElementProps {\n readonly locale: string;\n readonly dataSource: string;\n}\n\n/**\n * Registers `<emoji-picker>` (if needed) and creates the element with its locale and data source.\n *\n * The element's constructor queues the creation of its database in a microtask, with whatever\n * `locale` and `dataSource` are set by then - the jsDelivr default unless something else is.\n * Both are therefore set in the same synchronous step as `createElement`, before anything is\n * awaited, so that database is the only one and no request goes to the CDN.\n */\nasync function defaultCreatePickerElement(props: EmojiPickerElementProps): Promise<EmojiPickerElement> {\n try {\n await import('emoji-picker-element');\n } catch {\n throw new Error(ErrorCodes.NOT_IMPLEMENTED);\n }\n const picker = document.createElement('emoji-picker') as unknown as EmojiPickerElement;\n picker.dataSource = props.dataSource;\n picker.locale = props.locale;\n return picker;\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[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\nconst DEFAULT_BACKDROP_COLOR = '#00000066';\nconst HEX_COLOR_PATTERN = /^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/;\nlet backdropStyleCounter = 0;\n\n/** Validates a `#RGB`/`#RRGGBB`/`#RRGGBBAA` hex color, falling back to the default on any other input. */\nfunction resolveBackdropColor(color: string | undefined): string {\n if (color !== undefined && HEX_COLOR_PATTERN.test(color)) {\n return color;\n }\n return DEFAULT_BACKDROP_COLOR;\n}\n\n/** Injects a one-off `::backdrop` rule scoped to a unique class, since inline styles can't target it. */\nfunction injectBackdropStyle(options: EmojiPickerBackdropOptions): { className: string; remove: () => void } {\n const className = `emoji-picker-backdrop-${++backdropStyleCounter}`;\n const color = resolveBackdropColor(options.color);\n const blur = options.blur ?? 0;\n const style = document.createElement('style');\n // `backdrop-filter` is always set explicitly, never omitted: some browsers (e.g. Safari/WKWebView)\n // apply their own default blur to a <dialog>'s ::backdrop in their UA stylesheet, which would\n // otherwise leak through unopposed whenever the caller doesn't request blur.\n style.textContent = `\n dialog.${className}::backdrop {\n background: ${color};\n backdrop-filter: ${blur > 0 ? `blur(${blur}px)` : 'none'};\n }\n `;\n document.head.appendChild(style);\n return { className, remove: () => style.remove() };\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\n/**\n * Seeds `locale`'s persisted preferred skin tone via `emoji-picker-element`'s own `Database`, so\n * `<emoji-picker>` picks it up as its default on render. A no-op for `skinTone === undefined`,\n * so an already-made user choice (persisted in IndexedDB) is never overwritten.\n *\n * The `Database` gets the picker's own `dataSource`: left at its jsDelivr default, it would load\n * an empty database from the CDN (failing offline) and check a cached one against the CDN.\n */\nasync function defaultSeedSkinTone(locale: string, skinTone: number, dataSource: string): Promise<void> {\n const { default: Database } = await import('emoji-picker-element/database');\n const db = new Database({ locale, dataSource });\n await db.setPreferredSkinTone(skinTone);\n}\n\nexport interface WebEmojiPickerPresenterOptions {\n /** Creates the picker element with its locale and data source. Overridable for testing. */\n createPickerElement?: (props: EmojiPickerElementProps) => Promise<EmojiPickerElement>;\n /** Seeds the locale's persisted preferred skin tone. Overridable for testing. */\n seedSkinTone?: (locale: string, skinTone: number, dataSource: string) => Promise<void>;\n /** Resolves the `dataSource` URL, and the locale it serves, for a requested locale. Overridable for testing. */\n getDataSourceUrl?: (locale: string) => Promise<EmojiDataSource>;\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: (props: EmojiPickerElementProps) => Promise<EmojiPickerElement>;\n private readonly seedSkinTone: (locale: string, skinTone: number, dataSource: string) => Promise<void>;\n private readonly getDataSourceUrl: (locale: string) => Promise<EmojiDataSource>;\n\n public constructor(options: WebEmojiPickerPresenterOptions = {}) {\n this.createPickerElement = options.createPickerElement ?? defaultCreatePickerElement;\n this.seedSkinTone = options.seedSkinTone ?? defaultSeedSkinTone;\n this.getDataSourceUrl = options.getDataSourceUrl ?? getEmojiDataSourceUrl;\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 let locale = options.locale ?? 'en';\n\n let dataSource: string;\n try {\n // Resolved before the element exists, so it never starts with the default data source\n // (see `defaultCreatePickerElement`). The resolver may have fallen back to another\n // locale's data; the picker and the skin-tone seed must then use that locale too, or\n // `emoji-picker-element` would file the fallback data under the requested locale's\n // IndexedDB database and overwrite its cached copy.\n ({ locale, url: dataSource } = await this.getDataSourceUrl(locale));\n } catch {\n throw new Error(ErrorCodes.NOT_IMPLEMENTED);\n }\n\n if (options.skinTone !== undefined) {\n // Seeded before the element is created so its initial render already reflects it.\n await this.seedSkinTone(locale, options.skinTone, dataSource);\n }\n\n let picker: EmojiPickerElement;\n try {\n picker = await this.createPickerElement({ locale, dataSource });\n picker.dataSource = dataSource;\n picker.locale = locale;\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 backdropStyle = injectBackdropStyle(options.backdrop ?? {});\n const dialog = document.createElement('dialog');\n dialog.className = `emoji-picker-sheet emoji-picker-sheet--${resolvedTheme} ${backdropStyle.className}`;\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 finish = (result: EmojiPickerResult) => {\n document.body.style.overflow = previousBodyOverflow;\n dialog.close();\n dialog.remove();\n backdropStyle.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 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"]}
|
|
@@ -2,16 +2,25 @@
|
|
|
2
2
|
* Registers emoji data for a locale other than `'en'` (the only one bundled by default), so it's
|
|
3
3
|
* used instead of falling back to a CDN fetch.
|
|
4
4
|
*
|
|
5
|
-
* Pass a loader from
|
|
6
|
-
* `
|
|
7
|
-
* `
|
|
8
|
-
* decides what to import, which lets its own bundler include it statically or split it
|
|
9
|
-
* lazy chunk as it sees fit.
|
|
5
|
+
* Pass a loader from a per-locale entry, e.g.
|
|
6
|
+
* `import ptLocale from '@independo/capacitor-emoji-picker/dist/esm/platform/web/locales/pt'` and
|
|
7
|
+
* `registerEmojiLocale(ptLocale.locale, await ptLocale())`, or supply the dataset yourself. Either way, the
|
|
8
|
+
* host app decides what to import, which lets its own bundler include it statically or split it
|
|
9
|
+
* into a lazy chunk as it sees fit, and unused locales stay out of the build.
|
|
10
10
|
*/
|
|
11
11
|
export declare function registerEmojiLocale(locale: string, data: unknown): void;
|
|
12
|
+
/** A dataset URL together with the locale whose data it actually serves. */
|
|
13
|
+
export interface EmojiDataSource {
|
|
14
|
+
/** The locale the data belongs to: the requested one, or `'en'` after a fallback. */
|
|
15
|
+
locale: string;
|
|
16
|
+
url: string;
|
|
17
|
+
}
|
|
12
18
|
/**
|
|
13
|
-
* Returns a
|
|
14
|
-
* doesn't depend on a CDN at runtime for registered/bundled locales.
|
|
15
|
-
*
|
|
19
|
+
* Returns a URL serving the emoji dataset for `locale`, so the web picker
|
|
20
|
+
* doesn't depend on a CDN at runtime for registered/bundled locales. A `data:` URL when the page's
|
|
21
|
+
* CSP allows fetching one, else a `blob:` URL (see `canFetchDataUrls`). Falls back to `'en'` on any
|
|
22
|
+
* resolution failure (unknown locale with no network access, malformed code, etc); the result's
|
|
23
|
+
* `locale` is then `'en'`, so the caller never files English data under the requested locale's
|
|
24
|
+
* IndexedDB database.
|
|
16
25
|
*/
|
|
17
|
-
export declare function getEmojiDataSourceUrl(locale?: string): Promise<
|
|
26
|
+
export declare function getEmojiDataSourceUrl(locale?: string): Promise<EmojiDataSource>;
|