@independo/capacitor-emoji-picker 1.3.7-dev.2 → 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.
@@ -3,25 +3,60 @@ const DEFAULT_LOCALE = 'en';
3
3
  const EMOJI_PICKER_ELEMENT_DATA_VERSION = '^1';
4
4
  /** Locales registered at runtime by the host app via `registerEmojiLocale`. */
5
5
  const registeredLocales = new Map();
6
- /** Object URLs already resolved for a given locale, so `present()` never re-fetches/re-blobs. */
7
- const cachedDataSourceUrls = new Map();
6
+ /** Dataset URLs already resolved for a given locale, so `present()` never re-fetches/re-encodes. */
7
+ const cachedDataSources = new Map();
8
8
  /**
9
9
  * Registers emoji data for a locale other than `'en'` (the only one bundled by default), so it's
10
10
  * used instead of falling back to a CDN fetch.
11
11
  *
12
- * Pass a loader from `capacitor-emoji-picker/dist/esm/platform/web/locales` (e.g.
13
- * `registerEmojiLocale(ptLocale.locale, await ptLocale())`) to pick from every locale
14
- * `emoji-picker-element-data` ships, or supply the dataset yourself. Either way, the host app
15
- * decides what to import, which lets its own bundler include it statically or split it into a
16
- * lazy chunk as it sees fit.
12
+ * Pass a loader from a per-locale entry, e.g.
13
+ * `import ptLocale from '@independo/capacitor-emoji-picker/dist/esm/platform/web/locales/pt'` and
14
+ * `registerEmojiLocale(ptLocale.locale, await ptLocale())`, or supply the dataset yourself. Either way, the
15
+ * host app decides what to import, which lets its own bundler include it statically or split it
16
+ * into a lazy chunk as it sees fit, and unused locales stay out of the build.
17
17
  */
18
18
  export function registerEmojiLocale(locale, data) {
19
19
  registeredLocales.set(locale, data);
20
- cachedDataSourceUrls.delete(locale);
20
+ cachedDataSources.delete(locale);
21
21
  }
22
- function toObjectUrl(data) {
22
+ /**
23
+ * Encodes the dataset as a base64 `data:` URL.
24
+ *
25
+ * Not a `blob:` object URL: once a locale's data is cached in IndexedDB, `emoji-picker-element`
26
+ * checks it for freshness with a `fetch(dataSource, { method: 'HEAD' })` it never awaits, and the
27
+ * Fetch standard answers only `GET` for `blob:` URLs, so every such check rejected as an unhandled
28
+ * `TypeError` - and the cached copy was never replaced when the dataset changed. A `data:` URL
29
+ * answers `HEAD` too, and is the same on every page load for the same dataset, so the check keeps
30
+ * the cached copy until the dataset itself changes.
31
+ */
32
+ function toDataUrl(data) {
23
33
  const blob = new Blob([JSON.stringify(data)], { type: 'application/json' });
24
- return URL.createObjectURL(blob);
34
+ return new Promise((resolve, reject) => {
35
+ const reader = new FileReader();
36
+ reader.onload = () => resolve(reader.result);
37
+ reader.onerror = () => reject(reader.error);
38
+ reader.readAsDataURL(blob);
39
+ });
40
+ }
41
+ /**
42
+ * Whether the page may fetch `data:` URLs, i.e. whether its CSP `connect-src` (or `default-src`)
43
+ * allows `data:`. Probed once per session with the same `HEAD` request `emoji-picker-element`
44
+ * later makes against the dataset; Chromium and WebKit reject a `data:` fetch the policy blocks
45
+ * for `HEAD` and `GET` alike.
46
+ */
47
+ let dataUrlsFetchable;
48
+ function canFetchDataUrls() {
49
+ dataUrlsFetchable !== null && dataUrlsFetchable !== void 0 ? dataUrlsFetchable : (dataUrlsFetchable = fetch('data:application/json,{}', { method: 'HEAD' }).then(() => true, () => false));
50
+ return dataUrlsFetchable;
51
+ }
52
+ /**
53
+ * Serves the dataset as a `blob:` object URL: the legacy form, for pages whose CSP allows `blob:`
54
+ * but not `data:` in `connect-src`. Its random per-load URL means the dataset is re-stored in
55
+ * IndexedDB on every session, and the freshness check on a cached locale (a `HEAD`, which `blob:`
56
+ * URLs reject) raises an unhandled `TypeError` again; see `toDataUrl`.
57
+ */
58
+ function toBlobUrl(data) {
59
+ return URL.createObjectURL(new Blob([JSON.stringify(data)], { type: 'application/json' }));
25
60
  }
26
61
  /**
27
62
  * Fetches a locale's emoji dataset from jsDelivr, mirroring `emoji-picker-element`'s own default.
@@ -49,12 +84,15 @@ async function resolveLocaleData(locale) {
49
84
  return fetchLocaleFromCdn(locale);
50
85
  }
51
86
  /**
52
- * Returns a same-origin object URL serving the emoji dataset for `locale`, so the web picker
53
- * doesn't depend on a CDN at runtime for registered/bundled locales. Falls back to `'en'` on any
54
- * resolution failure (unknown locale with no network access, malformed code, etc).
87
+ * Returns a URL serving the emoji dataset for `locale`, so the web picker
88
+ * doesn't depend on a CDN at runtime for registered/bundled locales. A `data:` URL when the page's
89
+ * CSP allows fetching one, else a `blob:` URL (see `canFetchDataUrls`). Falls back to `'en'` on any
90
+ * resolution failure (unknown locale with no network access, malformed code, etc); the result's
91
+ * `locale` is then `'en'`, so the caller never files English data under the requested locale's
92
+ * IndexedDB database.
55
93
  */
56
94
  export async function getEmojiDataSourceUrl(locale = DEFAULT_LOCALE) {
57
- const cached = cachedDataSourceUrls.get(locale);
95
+ const cached = cachedDataSources.get(locale);
58
96
  if (cached) {
59
97
  return cached;
60
98
  }
@@ -68,8 +106,9 @@ export async function getEmojiDataSourceUrl(locale = DEFAULT_LOCALE) {
68
106
  }
69
107
  return getEmojiDataSourceUrl(DEFAULT_LOCALE);
70
108
  }
71
- const url = toObjectUrl(data);
72
- cachedDataSourceUrls.set(locale, url);
73
- return url;
109
+ const url = (await canFetchDataUrls()) ? await toDataUrl(data) : toBlobUrl(data);
110
+ const source = { locale, url };
111
+ cachedDataSources.set(locale, source);
112
+ return source;
74
113
  }
75
114
  //# sourceMappingURL=emoji-data-source.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"emoji-data-source.js","sourceRoot":"","sources":["../../../../src/platform/web/emoji-data-source.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,cAAc,CAAC;AAExC,MAAM,cAAc,GAAG,IAAI,CAAC;AAC5B,MAAM,iCAAiC,GAAG,IAAI,CAAC;AAE/C,+EAA+E;AAC/E,MAAM,iBAAiB,GAAG,IAAI,GAAG,EAAmB,CAAC;AAErD,iGAAiG;AACjG,MAAM,oBAAoB,GAAG,IAAI,GAAG,EAAkB,CAAC;AAEvD;;;;;;;;;GASG;AACH,MAAM,UAAU,mBAAmB,CAA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GAAG,oBAAoB,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAChD,IAAI,MAAM,EAAE,CAAC;QACT,OAAO,MAAM,CAAC;IAClB,CAAC;IAED,IAAI,IAAa,CAAC;IAClB,IAAI,CAAC;QACD,IAAI,GAAG,MAAM,iBAAiB,CAAC,MAAM,CAAC,CAAC;IAC3C,CAAC;IAAC,WAAM,CAAC;QACL,IAAI,MAAM,KAAK,cAAc,EAAE,CAAC;YAC5B,MAAM,IAAI,KAAK,CAAC,2CAA2C,cAAc,GAAG,CAAC,CAAC;QAClF,CAAC;QACD,OAAO,qBAAqB,CAAC,cAAc,CAAC,CAAC;IACjD,CAAC;IAED,MAAM,GAAG,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC;IAC9B,oBAAoB,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACtC,OAAO,GAAG,CAAC;AACf,CAAC","sourcesContent":["import loadEnLocale from './locales/en';\n\nconst DEFAULT_LOCALE = 'en';\nconst EMOJI_PICKER_ELEMENT_DATA_VERSION = '^1';\n\n/** Locales registered at runtime by the host app via `registerEmojiLocale`. */\nconst registeredLocales = new Map<string, unknown>();\n\n/** Object URLs already resolved for a given locale, so `present()` never re-fetches/re-blobs. */\nconst cachedDataSourceUrls = new Map<string, string>();\n\n/**\n * Registers emoji data for a locale other than `'en'` (the only one bundled by default), so it's\n * used instead of falling back to a CDN fetch.\n *\n * Pass a loader from `capacitor-emoji-picker/dist/esm/platform/web/locales` (e.g.\n * `registerEmojiLocale(ptLocale.locale, await ptLocale())`) to pick from every locale\n * `emoji-picker-element-data` ships, or supply the dataset yourself. Either way, the host app\n * decides what to import, which lets its own bundler include it statically or split it into a\n * lazy chunk as it sees fit.\n */\nexport function registerEmojiLocale(locale: string, data: unknown): void {\n registeredLocales.set(locale, data);\n cachedDataSourceUrls.delete(locale);\n}\n\nfunction toObjectUrl(data: unknown): string {\n const blob = new Blob([JSON.stringify(data)], { type: 'application/json' });\n return URL.createObjectURL(blob);\n}\n\n/**\n * Fetches a locale's emoji dataset from jsDelivr, mirroring `emoji-picker-element`'s own default.\n * Not every locale ships an `emojibase`-sourced dataset (only `en`, `en-gb`, `fr`, `ja`, `ru`,\n * `sv`, `zh` do); `cldr` produces the same normalized schema from a different annotation source,\n * so it's tried as a fallback before giving up.\n */\nasync function fetchLocaleFromCdn(locale: string): Promise<unknown> {\n for (const source of ['emojibase', 'cldr']) {\n const url = `https://cdn.jsdelivr.net/npm/emoji-picker-element-data@${EMOJI_PICKER_ELEMENT_DATA_VERSION}/${locale}/${source}/data.json`;\n const response = await fetch(url);\n if (response.ok) {\n return response.json();\n }\n }\n throw new Error(`Failed to fetch emoji data for locale '${locale}'`);\n}\n\nasync function resolveLocaleData(locale: string): Promise<unknown> {\n if (registeredLocales.has(locale)) {\n return registeredLocales.get(locale);\n }\n if (locale === DEFAULT_LOCALE) {\n return loadEnLocale();\n }\n return fetchLocaleFromCdn(locale);\n}\n\n/**\n * Returns a same-origin object URL serving the emoji dataset for `locale`, so the web picker\n * doesn't depend on a CDN at runtime for registered/bundled locales. Falls back to `'en'` on any\n * resolution failure (unknown locale with no network access, malformed code, etc).\n */\nexport async function getEmojiDataSourceUrl(locale: string = DEFAULT_LOCALE): Promise<string> {\n const cached = cachedDataSourceUrls.get(locale);\n if (cached) {\n return cached;\n }\n\n let data: unknown;\n try {\n data = await resolveLocaleData(locale);\n } catch {\n if (locale === DEFAULT_LOCALE) {\n throw new Error(`Failed to resolve default emoji locale '${DEFAULT_LOCALE}'`);\n }\n return getEmojiDataSourceUrl(DEFAULT_LOCALE);\n }\n\n const url = toObjectUrl(data);\n cachedDataSourceUrls.set(locale, url);\n return url;\n}\n"]}
1
+ {"version":3,"file":"emoji-data-source.js","sourceRoot":"","sources":["../../../../src/platform/web/emoji-data-source.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,cAAc,CAAC;AAExC,MAAM,cAAc,GAAG,IAAI,CAAC;AAC5B,MAAM,iCAA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;QACD,IAAI,GAAG,MAAM,iBAAiB,CAAC,MAAM,CAAC,CAAC;IAC3C,CAAC;IAAC,WAAM,CAAC;QACL,IAAI,MAAM,KAAK,cAAc,EAAE,CAAC;YAC5B,MAAM,IAAI,KAAK,CAAC,2CAA2C,cAAc,GAAG,CAAC,CAAC;QAClF,CAAC;QACD,OAAO,qBAAqB,CAAC,cAAc,CAAC,CAAC;IACjD,CAAC;IAED,MAAM,GAAG,GAAG,CAAC,MAAM,gBAAgB,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IACjF,MAAM,MAAM,GAAoB,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC;IAChD,iBAAiB,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACtC,OAAO,MAAM,CAAC;AAClB,CAAC","sourcesContent":["import loadEnLocale from './locales/en';\n\nconst DEFAULT_LOCALE = 'en';\nconst EMOJI_PICKER_ELEMENT_DATA_VERSION = '^1';\n\n/** Locales registered at runtime by the host app via `registerEmojiLocale`. */\nconst registeredLocales = new Map<string, unknown>();\n\n/** Dataset URLs already resolved for a given locale, so `present()` never re-fetches/re-encodes. */\nconst cachedDataSources = new Map<string, EmojiDataSource>();\n\n/**\n * Registers emoji data for a locale other than `'en'` (the only one bundled by default), so it's\n * used instead of falling back to a CDN fetch.\n *\n * Pass a loader from a per-locale entry, e.g.\n * `import ptLocale from '@independo/capacitor-emoji-picker/dist/esm/platform/web/locales/pt'` and\n * `registerEmojiLocale(ptLocale.locale, await ptLocale())`, or supply the dataset yourself. Either way, the\n * host app decides what to import, which lets its own bundler include it statically or split it\n * into a lazy chunk as it sees fit, and unused locales stay out of the build.\n */\nexport function registerEmojiLocale(locale: string, data: unknown): void {\n registeredLocales.set(locale, data);\n cachedDataSources.delete(locale);\n}\n\n/**\n * Encodes the dataset as a base64 `data:` URL.\n *\n * Not a `blob:` object URL: once a locale's data is cached in IndexedDB, `emoji-picker-element`\n * checks it for freshness with a `fetch(dataSource, { method: 'HEAD' })` it never awaits, and the\n * Fetch standard answers only `GET` for `blob:` URLs, so every such check rejected as an unhandled\n * `TypeError` - and the cached copy was never replaced when the dataset changed. A `data:` URL\n * answers `HEAD` too, and is the same on every page load for the same dataset, so the check keeps\n * the cached copy until the dataset itself changes.\n */\nfunction toDataUrl(data: unknown): Promise<string> {\n const blob = new Blob([JSON.stringify(data)], { type: 'application/json' });\n return new Promise((resolve, reject) => {\n const reader = new FileReader();\n reader.onload = () => resolve(reader.result as string);\n reader.onerror = () => reject(reader.error);\n reader.readAsDataURL(blob);\n });\n}\n\n/**\n * Whether the page may fetch `data:` URLs, i.e. whether its CSP `connect-src` (or `default-src`)\n * allows `data:`. Probed once per session with the same `HEAD` request `emoji-picker-element`\n * later makes against the dataset; Chromium and WebKit reject a `data:` fetch the policy blocks\n * for `HEAD` and `GET` alike.\n */\nlet dataUrlsFetchable: Promise<boolean> | undefined;\nfunction canFetchDataUrls(): Promise<boolean> {\n dataUrlsFetchable ??= fetch('data:application/json,{}', { method: 'HEAD' }).then(\n () => true,\n () => false\n );\n return dataUrlsFetchable;\n}\n\n/**\n * Serves the dataset as a `blob:` object URL: the legacy form, for pages whose CSP allows `blob:`\n * but not `data:` in `connect-src`. Its random per-load URL means the dataset is re-stored in\n * IndexedDB on every session, and the freshness check on a cached locale (a `HEAD`, which `blob:`\n * URLs reject) raises an unhandled `TypeError` again; see `toDataUrl`.\n */\nfunction toBlobUrl(data: unknown): string {\n return URL.createObjectURL(new Blob([JSON.stringify(data)], { type: 'application/json' }));\n}\n\n/**\n * Fetches a locale's emoji dataset from jsDelivr, mirroring `emoji-picker-element`'s own default.\n * Not every locale ships an `emojibase`-sourced dataset (only `en`, `en-gb`, `fr`, `ja`, `ru`,\n * `sv`, `zh` do); `cldr` produces the same normalized schema from a different annotation source,\n * so it's tried as a fallback before giving up.\n */\nasync function fetchLocaleFromCdn(locale: string): Promise<unknown> {\n for (const source of ['emojibase', 'cldr']) {\n const url = `https://cdn.jsdelivr.net/npm/emoji-picker-element-data@${EMOJI_PICKER_ELEMENT_DATA_VERSION}/${locale}/${source}/data.json`;\n const response = await fetch(url);\n if (response.ok) {\n return response.json();\n }\n }\n throw new Error(`Failed to fetch emoji data for locale '${locale}'`);\n}\n\nasync function resolveLocaleData(locale: string): Promise<unknown> {\n if (registeredLocales.has(locale)) {\n return registeredLocales.get(locale);\n }\n if (locale === DEFAULT_LOCALE) {\n return loadEnLocale();\n }\n return fetchLocaleFromCdn(locale);\n}\n\n/** A dataset URL together with the locale whose data it actually serves. */\nexport interface EmojiDataSource {\n /** The locale the data belongs to: the requested one, or `'en'` after a fallback. */\n locale: string;\n url: string;\n}\n\n/**\n * Returns a URL serving the emoji dataset for `locale`, so the web picker\n * doesn't depend on a CDN at runtime for registered/bundled locales. A `data:` URL when the page's\n * CSP allows fetching one, else a `blob:` URL (see `canFetchDataUrls`). Falls back to `'en'` on any\n * resolution failure (unknown locale with no network access, malformed code, etc); the result's\n * `locale` is then `'en'`, so the caller never files English data under the requested locale's\n * IndexedDB database.\n */\nexport async function getEmojiDataSourceUrl(locale: string = DEFAULT_LOCALE): Promise<EmojiDataSource> {\n const cached = cachedDataSources.get(locale);\n if (cached) {\n return cached;\n }\n\n let data: unknown;\n try {\n data = await resolveLocaleData(locale);\n } catch {\n if (locale === DEFAULT_LOCALE) {\n throw new Error(`Failed to resolve default emoji locale '${DEFAULT_LOCALE}'`);\n }\n return getEmojiDataSourceUrl(DEFAULT_LOCALE);\n }\n\n const url = (await canFetchDataUrls()) ? await toDataUrl(data) : toBlobUrl(data);\n const source: EmojiDataSource = { locale, url };\n cachedDataSources.set(locale, source);\n return source;\n}\n"]}
@@ -1,7 +1,7 @@
1
1
  /**
2
- * Lazily loads the English emoji dataset. Statically imported, unlike the other locales: `en`
3
- * is the default, used on every `present()` call that doesn't set `locale`, so lazy-loading
4
- * it would only add latency to the common case without any code-splitting upside.
2
+ * Lazily loads the English emoji dataset, so it code-splits into its own chunk. `en` is the
3
+ * default, but it is only needed once the picker is presented, so the package root must not
4
+ * carry its ~400 KB into an importer's initial chunk.
5
5
  */
6
6
  declare const _default: import("./create-locale-loader").EmojiLocaleLoader<"en">;
7
7
  export default _default;
@@ -1,9 +1,8 @@
1
1
  import { createLocaleLoader } from './create-locale-loader';
2
- import data from 'emoji-picker-element-data/en/emojibase/data.json';
3
2
  /**
4
- * Lazily loads the English emoji dataset. Statically imported, unlike the other locales: `en`
5
- * is the default, used on every `present()` call that doesn't set `locale`, so lazy-loading
6
- * it would only add latency to the common case without any code-splitting upside.
3
+ * Lazily loads the English emoji dataset, so it code-splits into its own chunk. `en` is the
4
+ * default, but it is only needed once the picker is presented, so the package root must not
5
+ * carry its ~400 KB into an importer's initial chunk.
7
6
  */
8
- export default createLocaleLoader('en', async () => data);
7
+ export default createLocaleLoader('en', async () => (await import('emoji-picker-element-data/en/emojibase/data.json')).default);
9
8
  //# sourceMappingURL=en.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"en.js","sourceRoot":"","sources":["../../../../../src/platform/web/locales/en.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,IAAI,MAAM,kDAAkD,CAAC;AAEpE;;;;GAIG;AACH,eAAe,kBAAkB,CAAC,IAAI,EAAE,KAAK,IAAI,EAAE,CAAC,IAAI,CAAC,CAAC","sourcesContent":["import { createLocaleLoader } from './create-locale-loader';\nimport data from 'emoji-picker-element-data/en/emojibase/data.json';\n\n/**\n * Lazily loads the English emoji dataset. Statically imported, unlike the other locales: `en`\n * is the default, used on every `present()` call that doesn't set `locale`, so lazy-loading\n * it would only add latency to the common case without any code-splitting upside.\n */\nexport default createLocaleLoader('en', async () => data);\n"]}
1
+ {"version":3,"file":"en.js","sourceRoot":"","sources":["../../../../../src/platform/web/locales/en.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAE5D;;;;GAIG;AACH,eAAe,kBAAkB,CAAC,IAAI,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC,MAAM,MAAM,CAAC,kDAAkD,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC","sourcesContent":["import { createLocaleLoader } from './create-locale-loader';\n\n/**\n * Lazily loads the English emoji dataset, so it code-splits into its own chunk. `en` is the\n * default, but it is only needed once the picker is presented, so the package root must not\n * carry its ~400 KB into an importer's initial chunk.\n */\nexport default createLocaleLoader('en', async () => (await import('emoji-picker-element-data/en/emojibase/data.json')).default);\n"]}
@@ -1,10 +1,11 @@
1
1
  /**
2
2
  * Every locale loader available for opt-in use with `registerEmojiLocale`, keyed by name.
3
3
  *
4
- * Only `en`/`de`/`es`/`fr`/`ja` are wired up as the default bundled set (see `emoji-data-source.ts`);
5
- * every other export here is inert until a caller imports it. Import only the loaders you need
6
- * (e.g. `import { ptLocale } from 'capacitor-emoji-picker'`) so your own bundler tree-shakes the
7
- * rest away instead of ever reaching them.
4
+ * Only `en` is wired up as the default bundled dataset (see `emoji-data-source.ts`, which loads it
5
+ * lazily); every other export here is inert until a caller imports it. Prefer importing the
6
+ * per-locale module directly (e.g. `import ptLocale from '.../dist/esm/platform/web/locales/pt'`):
7
+ * importing from this index is tree-shaken out of the bundle graph, but bundlers like esbuild still
8
+ * emit every locale's dataset file into the build output.
8
9
  */
9
10
  export { default as enLocale } from './en';
10
11
  export { default as bnLocale } from './bn';
@@ -1,10 +1,11 @@
1
1
  /**
2
2
  * Every locale loader available for opt-in use with `registerEmojiLocale`, keyed by name.
3
3
  *
4
- * Only `en`/`de`/`es`/`fr`/`ja` are wired up as the default bundled set (see `emoji-data-source.ts`);
5
- * every other export here is inert until a caller imports it. Import only the loaders you need
6
- * (e.g. `import { ptLocale } from 'capacitor-emoji-picker'`) so your own bundler tree-shakes the
7
- * rest away instead of ever reaching them.
4
+ * Only `en` is wired up as the default bundled dataset (see `emoji-data-source.ts`, which loads it
5
+ * lazily); every other export here is inert until a caller imports it. Prefer importing the
6
+ * per-locale module directly (e.g. `import ptLocale from '.../dist/esm/platform/web/locales/pt'`):
7
+ * importing from this index is tree-shaken out of the bundle graph, but bundlers like esbuild still
8
+ * emit every locale's dataset file into the build output.
8
9
  */
9
10
  export { default as enLocale } from './en';
10
11
  export { default as bnLocale } from './bn';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/platform/web/locales/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,SAAS,CAAC;AAChD,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,SAAS,CAAC;AAChD,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,WAAW,CAAC","sourcesContent":["/**\n * Every locale loader available for opt-in use with `registerEmojiLocale`, keyed by name.\n *\n * Only `en`/`de`/`es`/`fr`/`ja` are wired up as the default bundled set (see `emoji-data-source.ts`);\n * every other export here is inert until a caller imports it. Import only the loaders you need\n * (e.g. `import { ptLocale } from 'capacitor-emoji-picker'`) so your own bundler tree-shakes the\n * rest away instead of ever reaching them.\n */\nexport { default as enLocale } from './en';\nexport { default as bnLocale } from './bn';\nexport { default as daLocale } from './da';\nexport { default as deLocale } from './de';\nexport { default as enGbLocale } from './en-gb';\nexport { default as esMxLocale } from './es-mx';\nexport { default as esLocale } from './es';\nexport { default as etLocale } from './et';\nexport { default as fiLocale } from './fi';\nexport { default as frLocale } from './fr';\nexport { default as hiLocale } from './hi';\nexport { default as huLocale } from './hu';\nexport { default as itLocale } from './it';\nexport { default as jaLocale } from './ja';\nexport { default as koLocale } from './ko';\nexport { default as ltLocale } from './lt';\nexport { default as msLocale } from './ms';\nexport { default as nbLocale } from './nb';\nexport { default as nlLocale } from './nl';\nexport { default as plLocale } from './pl';\nexport { default as ptLocale } from './pt';\nexport { default as ruLocale } from './ru';\nexport { default as svLocale } from './sv';\nexport { default as thLocale } from './th';\nexport { default as ukLocale } from './uk';\nexport { default as viLocale } from './vi';\nexport { default as zhLocale } from './zh';\nexport { default as zhHantLocale } from './zh-hant';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/platform/web/locales/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,SAAS,CAAC;AAChD,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,SAAS,CAAC;AAChD,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,WAAW,CAAC","sourcesContent":["/**\n * Every locale loader available for opt-in use with `registerEmojiLocale`, keyed by name.\n *\n * Only `en` is wired up as the default bundled dataset (see `emoji-data-source.ts`, which loads it\n * lazily); every other export here is inert until a caller imports it. Prefer importing the\n * per-locale module directly (e.g. `import ptLocale from '.../dist/esm/platform/web/locales/pt'`):\n * importing from this index is tree-shaken out of the bundle graph, but bundlers like esbuild still\n * emit every locale's dataset file into the build output.\n */\nexport { default as enLocale } from './en';\nexport { default as bnLocale } from './bn';\nexport { default as daLocale } from './da';\nexport { default as deLocale } from './de';\nexport { default as enGbLocale } from './en-gb';\nexport { default as esMxLocale } from './es-mx';\nexport { default as esLocale } from './es';\nexport { default as etLocale } from './et';\nexport { default as fiLocale } from './fi';\nexport { default as frLocale } from './fr';\nexport { default as hiLocale } from './hi';\nexport { default as huLocale } from './hu';\nexport { default as itLocale } from './it';\nexport { default as jaLocale } from './ja';\nexport { default as koLocale } from './ko';\nexport { default as ltLocale } from './lt';\nexport { default as msLocale } from './ms';\nexport { default as nbLocale } from './nb';\nexport { default as nlLocale } from './nl';\nexport { default as plLocale } from './pl';\nexport { default as ptLocale } from './pt';\nexport { default as ruLocale } from './ru';\nexport { default as svLocale } from './sv';\nexport { default as thLocale } from './th';\nexport { default as ukLocale } from './uk';\nexport { default as viLocale } from './vi';\nexport { default as zhLocale } from './zh';\nexport { default as zhHantLocale } from './zh-hant';\n"]}