@sveltia/ui 0.65.2 → 0.65.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.
@@ -7,7 +7,7 @@ export const SHIKI_VERSION: "4.4.3";
7
7
  /**
8
8
  * Version of this package, used to resolve the prebuilt Shiki engine chunk from a CDN.
9
9
  */
10
- export const UI_VERSION: "0.65.2";
10
+ export const UI_VERSION: "0.65.3";
11
11
  /**
12
12
  * Available syntax highlighting languages, sorted by display name.
13
13
  * @type {{ id: string, name: string, aliases?: string[] }[]}
@@ -10,7 +10,7 @@ export const SHIKI_VERSION = "4.4.3";
10
10
  /**
11
11
  * Version of this package, used to resolve the prebuilt Shiki engine chunk from a CDN.
12
12
  */
13
- export const UI_VERSION = "0.65.2";
13
+ export const UI_VERSION = "0.65.3";
14
14
 
15
15
  /**
16
16
  * Available syntax highlighting languages, sorted by display name.
@@ -766,22 +766,18 @@ export type TextEditorConfig = {
766
766
  */
767
767
  defaultLanguage?: string | undefined;
768
768
  };
769
- /**
770
- * Raw emoji data as published by `emojilib`, keyed by emoji character. Each value lists the
771
- * canonical name followed by any keywords.
772
- */
773
- export type EmojiData = Record<string, string[]>;
774
769
  export type EmojiEntry = {
775
770
  /**
776
771
  * Emoji character, e.g. `🎉`.
777
772
  */
778
773
  emoji: string;
779
774
  /**
780
- * Canonical name used as the shortcode, e.g. `party_popper`.
775
+ * Canonical shortcode, e.g. `tada`.
781
776
  */
782
777
  name: string;
783
778
  /**
784
- * Lower-cased alternative keywords, e.g. `party`, `tada`.
779
+ * Lower-cased alternative shortcodes and keywords, e.g. `party`,
780
+ * `popper`.
785
781
  */
786
782
  aliases: string[];
787
783
  };
package/dist/typedefs.js CHANGED
@@ -319,17 +319,12 @@
319
319
  * @property {string} [defaultLanguage] Default language for the code editor.
320
320
  */
321
321
 
322
- /**
323
- * Raw emoji data as published by `emojilib`, keyed by emoji character. Each value lists the
324
- * canonical name followed by any keywords.
325
- * @typedef {Record<string, string[]>} EmojiData
326
- */
327
-
328
322
  /**
329
323
  * @typedef {object} EmojiEntry
330
324
  * @property {string} emoji Emoji character, e.g. `🎉`.
331
- * @property {string} name Canonical name used as the shortcode, e.g. `party_popper`.
332
- * @property {string[]} aliases Lower-cased alternative keywords, e.g. `party`, `tada`.
325
+ * @property {string} name Canonical shortcode, e.g. `tada`.
326
+ * @property {string[]} aliases Lower-cased alternative shortcodes and keywords, e.g. `party`,
327
+ * `popper`.
333
328
  */
334
329
 
335
330
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltia/ui",
3
- "version": "0.65.2",
3
+ "version": "0.65.3",
4
4
  "description": "A collection of Svelte components and utilities for building user interfaces.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -48,7 +48,6 @@
48
48
  "@lexical/utils": "^0.49.0",
49
49
  "@sveltia/i18n": "^1.2.3",
50
50
  "@sveltia/utils": "^0.12.1",
51
- "emojilib": "^4.0.3",
52
51
  "lexical": "^0.49.0"
53
52
  },
54
53
  "devDependencies": {
@@ -106,6 +105,7 @@
106
105
  "check:svelte": "svelte-kit sync && svelte-check --tsconfig ./jsconfig.json",
107
106
  "dev": "vite dev",
108
107
  "format": "prettier --write .",
108
+ "generate:emoji": "node scripts/generate-emoji-data.js",
109
109
  "generate:shiki": "node scripts/generate-shiki-metadata.js",
110
110
  "preview": "vite preview",
111
111
  "test": "vitest run",
@@ -1,3 +0,0 @@
1
- export function getCachedEmojiData(): Promise<EmojiData | undefined>;
2
- export function cacheEmojiData(data: EmojiData): Promise<void>;
3
- import type { EmojiData } from '../../typedefs';
@@ -1,96 +0,0 @@
1
- import { IndexedDB } from '@sveltia/utils/storage';
2
- import { EMOJILIB_VERSION } from './loader.js';
3
-
4
- /**
5
- * @import { EmojiData } from '../../typedefs';
6
- */
7
-
8
- /**
9
- * Client-side cache for the emoji data.
10
- *
11
- * The data is a few hundred kilobytes fetched from a CDN, and it never changes for a given version,
12
- * so it’s worth keeping locally rather than going back to the network on every page load. IndexedDB
13
- * is used rather than local storage because the payload is large enough to matter against the local
14
- * storage quota, and because writing it there would block the main thread.
15
- */
16
-
17
- const DATABASE_NAME = 'sveltia-ui';
18
- const STORE_NAME = 'emoji';
19
- /** Key of the sole entry, scoped to the version the data came from. */
20
- const KEY = `${EMOJILIB_VERSION}/data`;
21
- /** @type {IndexedDB | undefined | null} `null` once the store is known to be unusable. */
22
- let database;
23
- /** @type {Promise<void> | undefined} */
24
- let purgePromise;
25
-
26
- /**
27
- * Get the store, or `null` when IndexedDB is unavailable, as in a server-side render or with
28
- * storage blocked.
29
- * @returns {IndexedDB | null} Store.
30
- */
31
- const getDatabase = () => {
32
- if (database === undefined) {
33
- database = typeof indexedDB === 'undefined' ? null : new IndexedDB(DATABASE_NAME, STORE_NAME);
34
- }
35
-
36
- return database;
37
- };
38
-
39
- /**
40
- * Drop anything cached for a different version, once per session. A version bump changes the key,
41
- * so the old payload would otherwise linger forever.
42
- * @param {IndexedDB} db Store.
43
- * @returns {Promise<void>} Nothing.
44
- */
45
- const purgeStaleVersions = async (db) => {
46
- purgePromise ??= (async () => {
47
- const stale = (await db.keys()).filter((key) => key !== KEY);
48
-
49
- if (stale.length) {
50
- await db.deleteEntries(stale);
51
- }
52
- })();
53
-
54
- return purgePromise;
55
- };
56
-
57
- /**
58
- * Read the cached emoji data.
59
- * @returns {Promise<EmojiData | undefined>} Cached data, or `undefined` when not cached or
60
- * unreadable.
61
- */
62
- export const getCachedEmojiData = async () => {
63
- const db = getDatabase();
64
-
65
- if (!db) {
66
- return undefined;
67
- }
68
-
69
- try {
70
- await purgeStaleVersions(db);
71
-
72
- return await db.get(KEY);
73
- } catch {
74
- // A failed cache read just means fetching again
75
- return undefined;
76
- }
77
- };
78
-
79
- /**
80
- * Store the emoji data.
81
- * @param {EmojiData} data Emoji data.
82
- * @returns {Promise<void>} Nothing.
83
- */
84
- export const cacheEmojiData = async (data) => {
85
- const db = getDatabase();
86
-
87
- if (!db) {
88
- return;
89
- }
90
-
91
- try {
92
- await db.set(KEY, data);
93
- } catch {
94
- // Out of quota or storage blocked: not worth failing over, the data is already in hand
95
- }
96
- };
@@ -1,17 +0,0 @@
1
- /**
2
- * @import { EmojiData } from '../../typedefs';
3
- */
4
- /**
5
- * Version of `emojilib` the data is fetched from, which also scopes the cache so a bump invalidates
6
- * it.
7
- *
8
- * This is written out rather than read from `emojilib/package.json`, because this package ships
9
- * unbundled: a consumer’s test runner may well load these modules through Node, where a JSON import
10
- * needs an import attribute and exposes no named exports, and not every bundler understands the
11
- * attribute either. A test keeps this in step with the installed version.
12
- */
13
- export const EMOJILIB_VERSION: "4.0.3";
14
- export function getEmojiDataURL(): string;
15
- export function setEmojiDataLoader(newLoader: () => Promise<EmojiData>): void;
16
- export function getEmojiDataLoader(): () => Promise<EmojiData>;
17
- import type { EmojiData } from '../../typedefs';
@@ -1,78 +0,0 @@
1
- /**
2
- * @import { EmojiData } from '../../typedefs';
3
- */
4
-
5
- /**
6
- * Version of `emojilib` the data is fetched from, which also scopes the cache so a bump invalidates
7
- * it.
8
- *
9
- * This is written out rather than read from `emojilib/package.json`, because this package ships
10
- * unbundled: a consumer’s test runner may well load these modules through Node, where a JSON import
11
- * needs an import attribute and exposes no named exports, and not every bundler understands the
12
- * attribute either. A test keeps this in step with the installed version.
13
- */
14
- export const EMOJILIB_VERSION = '4.0.3';
15
-
16
- const CDN_BASE_URL = 'https://unpkg.com/emojilib';
17
- /**
18
- * How long to wait for the emoji data, in milliseconds. The suggestions are a convenience, so a
19
- * slow or unreachable CDN should never leave a request hanging around.
20
- */
21
- const FETCH_TIMEOUT = 5000;
22
-
23
- /**
24
- * Get the URL of the emoji data.
25
- *
26
- * The data is fetched rather than bundled because it’s a few hundred kilobytes that most sessions
27
- * never need, and a single-file bundle — our main consumer, Sveltia CMS — would otherwise inline it
28
- * wholesale. The URL is pinned to {@link EMOJILIB_VERSION}, so the data always matches the package
29
- * this was developed against.
30
- * @returns {string} URL.
31
- */
32
- export const getEmojiDataURL = () => `${CDN_BASE_URL}@${EMOJILIB_VERSION}/dist/emoji-en-US.json`;
33
-
34
- /**
35
- * Fetch the emoji data from the CDN.
36
- * @returns {Promise<EmojiData>} Emoji data, keyed by emoji character.
37
- * @throws {Error} When the request fails, times out or returns a non-OK response.
38
- */
39
- const loadEmojiData = async () => {
40
- const response = await fetch(getEmojiDataURL(), {
41
- signal: AbortSignal.timeout(FETCH_TIMEOUT),
42
- });
43
-
44
- if (!response.ok) {
45
- throw new Error(`Failed to load emoji data: ${response.status}`);
46
- }
47
-
48
- return response.json();
49
- };
50
-
51
- /**
52
- * Loader in effect.
53
- * @type {() => Promise<EmojiData>}
54
- */
55
- let loader = loadEmojiData;
56
-
57
- /**
58
- * Override how the emoji suggestions obtain their data.
59
- *
60
- * By default the data is fetched from a CDN and cached locally, which keeps it out of the
61
- * consumer’s bundle. Consumers who would rather bundle it, self-host it, or run without any
62
- * outbound requests at all can replace the loader.
63
- *
64
- * ```js
65
- * setEmojiDataLoader(async () => (await import('emojilib')).default);
66
- * ```
67
- * @param {() => Promise<EmojiData>} newLoader Loader returning the emoji data, keyed by emoji
68
- * character, with each value listing the name followed by any keywords.
69
- */
70
- export const setEmojiDataLoader = (newLoader) => {
71
- loader = newLoader;
72
- };
73
-
74
- /**
75
- * Get the loader currently in effect.
76
- * @returns {() => Promise<EmojiData>} Active loader.
77
- */
78
- export const getEmojiDataLoader = () => loader;