@aceshooting/lyra-flags 1.3.0 → 1.4.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 CHANGED
@@ -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()` is genuinely code-split per flag each code is its own dynamically-`import()`ed
26
- chunk, so calling `flagUrl('fr')` only ever fetches `fr`'s asset, never the other 248. That's why
27
- it's `async`: this is a real, separate lazy-load per code, not a lookup into one eagerly-bundled
28
- map (verified with a real Vite build: referencing 2 codes shipped ~28 KB total, not all 249).
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:
@@ -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 is code-split per flag **and** per tier: a bundled app that only ever requests
66
- `variant: 'compact'` for a handful of codes ships only those few compact WebPs — never their
67
- standard or detailed variants, and never the other flags.
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
@@ -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 chunk and never fetch/inline a given flag until its
9
- * specific loader is actually called. This is what `flagUrl()` uses. See index.js — and
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 a flag SVG shipped in this package, fetching only that one flag.
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, never the other 248 (confirmed with a real Vite build: referencing 2
29
- * codes produced 2 non-trivial chunks and shipped only those 2 flag assets; the rest were
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
package/package.json CHANGED
@@ -1,7 +1,15 @@
1
1
  {
2
2
  "name": "@aceshooting/lyra-flags",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
4
4
  "description": "Waving country/territory flag SVGs — optional companion asset package for <lyra-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://github.com/aceshooting/lyra-ui#readme",
24
+ "homepage": "https://www.lyra-ui.com/",
17
25
  "bugs": {
18
26
  "url": "https://github.com/aceshooting/lyra-ui/issues"
19
27
  },
@@ -24,6 +32,13 @@
24
32
  "node": ">=20"
25
33
  },
26
34
  "sideEffects": false,
35
+ "scripts": {
36
+ "generate": "node scripts/generate-index.mjs",
37
+ "optimize": "node scripts/optimize-flags.mjs",
38
+ "build-compact": "node scripts/build-compact.mjs",
39
+ "test": "node scripts/test.mjs",
40
+ "prepack": "pnpm run generate"
41
+ },
27
42
  "files": [
28
43
  "flags",
29
44
  "index.js",
@@ -39,15 +54,10 @@
39
54
  },
40
55
  "./flags/*": "./flags/*"
41
56
  },
57
+ "packageManager": "pnpm@11.13.0",
42
58
  "devDependencies": {
43
59
  "@resvg/resvg-js": "^2.6.2",
44
60
  "sharp": "^0.35.3",
45
- "svgo": "^4.0.1"
46
- },
47
- "scripts": {
48
- "generate": "node scripts/generate-index.mjs",
49
- "optimize": "node scripts/optimize-flags.mjs",
50
- "build-compact": "node scripts/build-compact.mjs",
51
- "test": "node scripts/test.mjs"
61
+ "svgo": "^4.0.2"
52
62
  }
53
- }
63
+ }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 Aceshooting
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.