@aceshooting/lyra-flags 1.3.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -12
- package/flags/generated.js +3 -2
- package/index.js +6 -5
- package/package.json +12 -4
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# @aceshooting/lyra-flags
|
|
2
2
|
|
|
3
3
|
Waving country/territory flag SVGs (249 codes) — the optional companion asset package for
|
|
4
|
-
`<
|
|
4
|
+
`<lr-flag>` in [`lyra-ui`](https://github.com/aceshooting/lyra-ui/tree/main/packages/lyra-ui).
|
|
5
5
|
|
|
6
6
|
## Install
|
|
7
7
|
|
|
@@ -10,11 +10,11 @@ pnpm add @aceshooting/lyra-flags
|
|
|
10
10
|
```
|
|
11
11
|
|
|
12
12
|
`lyra-ui` declares this as an **optional peer dependency** — installing `lyra-ui` alone never
|
|
13
|
-
pulls this package in. Add it explicitly if your app uses `<
|
|
13
|
+
pulls this package in. Add it explicitly if your app uses `<lr-flag>`.
|
|
14
14
|
|
|
15
15
|
## Usage
|
|
16
16
|
|
|
17
|
-
You normally never call this directly; `<
|
|
17
|
+
You normally never call this directly; `<lr-flag>` resolves it internally. Direct usage:
|
|
18
18
|
|
|
19
19
|
```js
|
|
20
20
|
import { flagUrl } from '@aceshooting/lyra-flags';
|
|
@@ -22,10 +22,12 @@ import { flagUrl } from '@aceshooting/lyra-flags';
|
|
|
22
22
|
await flagUrl('fr'); // -> resolved URL of flags/fr.svg
|
|
23
23
|
```
|
|
24
24
|
|
|
25
|
-
`flagUrl()`
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
`flagUrl()` selects one dynamically imported loader per flag, so a browser only fetches the
|
|
26
|
+
requested flag at runtime. Because the package exports a loader entry for every code, a production
|
|
27
|
+
bundler may still emit the complete reachable lazy-chunk graph even when the initial entry only
|
|
28
|
+
imports `flagUrl`; lazy network fetching and build-time pruning are separate concerns. Use a
|
|
29
|
+
literal `@aceshooting/lyra-flags/flags/<code>.svg` asset import, or copy only the required assets,
|
|
30
|
+
when the deployment artifact itself must contain a small allowlist.
|
|
29
31
|
|
|
30
32
|
For the opposite case — a consumer that genuinely wants every flag up front (e.g. a flag-picker
|
|
31
33
|
listing every country) — use `flagUrls()` instead:
|
|
@@ -42,12 +44,12 @@ A minority of flags (65 of 249) embed a detailed coat of arms, seal, or emblem i
|
|
|
42
44
|
artwork (e.g. `es`, `pt`, `sv`) — full illustrative vector detail that isn't visually
|
|
43
45
|
distinguishable at icon scale but costs real transfer bytes regardless (the worst case, `sv`, is
|
|
44
46
|
741 KB raw). Those 65 codes ship **three tiers**, each the best representation for a size band; pick
|
|
45
|
-
one with `flagUrl(code, { variant })` or `<
|
|
47
|
+
one with `flagUrl(code, { variant })` or `<lr-flag variant="...">`:
|
|
46
48
|
|
|
47
49
|
- **`compact`** — a tiny WebP raster (~1–3 KB) for icon-scale use (menu items, language selectors,
|
|
48
50
|
dense lists; ~12–28px), where the emblem is a sub-pixel smudge anyway. At that size a downscaled
|
|
49
51
|
raster is both crisper *and* far smaller than hundreds of sub-pixel vector paths.
|
|
50
|
-
- **`standard`** (the default — what `flagUrl(code)` / `<
|
|
52
|
+
- **`standard`** (the default — what `flagUrl(code)` / `<lr-flag country="...">` resolve to) — an
|
|
51
53
|
aggressively-but-losslessly SVGO-optimized vector for card/row sizes (~28–96px). Every flag is
|
|
52
54
|
under 80 KB, with no fidelity loss perceptible at that scale.
|
|
53
55
|
- **`detailed`** — the pristine, unmodified original vector, for rendering larger than icon scale
|
|
@@ -62,9 +64,9 @@ await flagUrl('es', { variant: 'compact' }); // -> WebP raster (~2 KB)
|
|
|
62
64
|
await flagUrl('es', { variant: 'detailed' }); // -> pristine original (~415 KB)
|
|
63
65
|
```
|
|
64
66
|
|
|
65
|
-
Every tier
|
|
66
|
-
|
|
67
|
-
|
|
67
|
+
Every tier has a separate loader per flag **and** per tier. At runtime a compact request fetches
|
|
68
|
+
only its compact asset; a bundler can nevertheless emit all statically reachable tier chunks. Use
|
|
69
|
+
literal subpath asset imports when the deployment artifact must be pruned to a small allowlist.
|
|
68
70
|
|
|
69
71
|
Maintainers, after adding/replacing source art: `pnpm run optimize` (re-derives the standard tier
|
|
70
72
|
from the pristine `flags/detailed/` originals) → `pnpm run build-compact` (renders the compact WebP
|
package/flags/generated.js
CHANGED
|
@@ -5,8 +5,9 @@
|
|
|
5
5
|
/**
|
|
6
6
|
* Lazy map of ISO 3166-1 alpha-2 (or territory) code -> flag SVG URL loader. Each entry is a
|
|
7
7
|
* `() => import('./loaders/xx.js')` with a literal (non-templated) specifier, so bundlers
|
|
8
|
-
* code-split every flag into its own
|
|
9
|
-
* specific loader is actually called.
|
|
8
|
+
* code-split every flag into its own lazy loader and never fetch a given flag until its
|
|
9
|
+
* specific loader is actually called. Bundlers may still emit the complete reachable lazy
|
|
10
|
+
* graph; this is what `flagUrl()` uses. See index.js — and
|
|
10
11
|
* critically, do NOT add an eager (`new URL()`-per-code) export to *this* file; see
|
|
11
12
|
* generate-index.mjs for why that defeats the whole point.
|
|
12
13
|
* @type {Record<string, () => Promise<string>>}
|
package/index.js
CHANGED
|
@@ -3,7 +3,9 @@ import { FLAG_LOADERS_DETAILED } from './flags/generated-detailed.js';
|
|
|
3
3
|
import { FLAG_LOADERS_COMPACT } from './flags/generated-compact.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* Resolves the URL of
|
|
6
|
+
* Resolves the URL of one flag SVG. The browser fetches only the requested flag at runtime; a
|
|
7
|
+
* bundler may still emit the complete reachable lazy-chunk graph because every supported code is
|
|
8
|
+
* represented by a literal loader import. See the package README for artifact-pruning options.
|
|
7
9
|
*
|
|
8
10
|
* Backing story: this used to be a synchronous lookup into `FLAG_URLS`, a single object literal
|
|
9
11
|
* with one `new URL('./xx.svg', import.meta.url)` per code, evaluated eagerly the moment the
|
|
@@ -25,9 +27,8 @@ import { FLAG_LOADERS_COMPACT } from './flags/generated-compact.js';
|
|
|
25
27
|
* `import`s the eager map, so loading it doesn't drag in `flags/eager.js` too. A dynamic
|
|
26
28
|
* `import()` of a literal specifier is exactly the pattern bundlers use to create a genuinely
|
|
27
29
|
* separate, lazily-fetched chunk per file — calling `flagUrl('fr')` only ever triggers a network
|
|
28
|
-
* fetch for `fr`'s chunk
|
|
29
|
-
*
|
|
30
|
-
* unfetched, never-imported build outputs). Every loader module (see `flags/loaders/*.js`) itself
|
|
30
|
+
* fetch for `fr`'s chunk; the other flags are not fetched until requested. Every loader module
|
|
31
|
+
* (see `flags/loaders/*.js`) itself
|
|
31
32
|
* uses `new URL(literal, import.meta.url)`, and every `import()` here uses a literal `.js`
|
|
32
33
|
* specifier — never a bundler-specific suffix like `?url` — so this still works completely
|
|
33
34
|
* unbundled (a plain browser `<script type="module">`, Node, `@web/test-runner`'s unbundled
|
|
@@ -46,7 +47,7 @@ import { FLAG_LOADERS_COMPACT } from './flags/generated-compact.js';
|
|
|
46
47
|
* @param {{ variant?: 'compact' | 'standard' | 'detailed' }} [options]
|
|
47
48
|
* @returns {Promise<string | undefined>} The flag's URL. For a `code` with no matching shipped
|
|
48
49
|
* flag, resolves `undefined` (same non-crashing "no image" outcome as the old code's
|
|
49
|
-
* now-404ing URL, for `<
|
|
50
|
+
* now-404ing URL, for `<lr-flag>`'s `<img src>` use).
|
|
50
51
|
*/
|
|
51
52
|
export function flagUrl(code, options) {
|
|
52
53
|
if (options?.variant === 'detailed' && FLAG_LOADERS_DETAILED[code]) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aceshooting/lyra-flags",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "Waving country/territory flag SVGs — optional companion asset package for <
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "Waving country/territory flag SVGs — optional companion asset package for <lr-flag> in lyra-ui.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"flag-icons",
|
|
7
|
+
"flags",
|
|
8
|
+
"country-flags",
|
|
9
|
+
"svg",
|
|
10
|
+
"i18n",
|
|
11
|
+
"web-components"
|
|
12
|
+
],
|
|
5
13
|
"license": "SEE LICENSE IN README.md",
|
|
6
14
|
"type": "module",
|
|
7
15
|
"author": {
|
|
@@ -13,7 +21,7 @@
|
|
|
13
21
|
"url": "git+https://github.com/aceshooting/lyra-ui.git",
|
|
14
22
|
"directory": "packages/lyra-flags"
|
|
15
23
|
},
|
|
16
|
-
"homepage": "https://
|
|
24
|
+
"homepage": "https://www.lyra-ui.com/",
|
|
17
25
|
"bugs": {
|
|
18
26
|
"url": "https://github.com/aceshooting/lyra-ui/issues"
|
|
19
27
|
},
|
|
@@ -42,7 +50,7 @@
|
|
|
42
50
|
"devDependencies": {
|
|
43
51
|
"@resvg/resvg-js": "^2.6.2",
|
|
44
52
|
"sharp": "^0.35.3",
|
|
45
|
-
"svgo": "^4.0.
|
|
53
|
+
"svgo": "^4.0.2"
|
|
46
54
|
},
|
|
47
55
|
"scripts": {
|
|
48
56
|
"generate": "node scripts/generate-index.mjs",
|