@nysds/nys-unavbundle 1.21.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 ADDED
@@ -0,0 +1,141 @@
1
+ # @nysds/nys-unavbundle
2
+
3
+ The New York State universal navigation — `<nys-unavheader>` and `<nys-unavfooter>` —
4
+ as a single self-contained script.
5
+
6
+ Add one `<script>` and the two custom elements work. There is nothing else to
7
+ install, no stylesheet to link, and no icon directory to host.
8
+
9
+ ```html
10
+ <script src="https://unpkg.com/@nysds/nys-unavbundle"></script>
11
+
12
+ <nys-unavheader></nys-unavheader>
13
+ <!-- your page -->
14
+ <nys-unavfooter></nys-unavfooter>
15
+ ```
16
+
17
+ ## What's inside
18
+
19
+ Everything the two elements reach at runtime is compiled into the one file:
20
+
21
+ - Lit 3 and the shared `@nysds/internals` base classes
22
+ - `nys-button`, `nys-textinput`, `nys-alert`, `nys-icon`, `nys-label`,
23
+ `nys-errormessage`, `nys-tooltip` — the components the header composes
24
+ - DOMPurify, which `nys-icon` uses to sanitize SVG
25
+ - The `@nysds/tokens` CSS variables, injected on load (see below)
26
+ - 26 of the icon library's 82 icons — the set the nav can actually render
27
+
28
+ ## Installing
29
+
30
+ ### CDN
31
+
32
+ ```html
33
+ <script src="https://unpkg.com/@nysds/nys-unavbundle"></script>
34
+ ```
35
+
36
+ Pin a version for production:
37
+
38
+ ```html
39
+ <script src="https://unpkg.com/@nysds/nys-unavbundle@1.21.0/dist/nys-unavbundle.js"></script>
40
+ ```
41
+
42
+ Self-hosting works the same way — copy `dist/nys-unavbundle.js` and point a
43
+ `<script src>` at it.
44
+
45
+ ### npm
46
+
47
+ ```bash
48
+ npm install @nysds/nys-unavbundle
49
+ ```
50
+
51
+ ```js
52
+ import "@nysds/nys-unavbundle";
53
+ ```
54
+
55
+ The import is for its side effects: it registers both elements and injects the
56
+ tokens. There is no setup call to make.
57
+
58
+ ## Design tokens
59
+
60
+ The component styles read `--nys-*` custom properties, so the bundle injects the
61
+ NYSDS token stylesheet as the **first** `<style>` in `<head>` when it loads.
62
+ Being first is deliberate — a page that defines its own `--nys-*` values, or that
63
+ already loads `@nysds/styles`, wins on source order rather than fighting the
64
+ bundle for them.
65
+
66
+ To take over the timing, set a flag before the script runs and call the export
67
+ yourself:
68
+
69
+ ```html
70
+ <script>
71
+ window.NYS_UNAV_SKIP_TOKENS = true;
72
+ </script>
73
+ <script src="https://unpkg.com/@nysds/nys-unavbundle"></script>
74
+ <script>
75
+ NYSUnav.injectTokens();
76
+ </script>
77
+ ```
78
+
79
+ A page already loading `@nysds/styles` can set the flag and skip injection
80
+ entirely.
81
+
82
+ ## Using it alongside the full design system
83
+
84
+ Every element in the bundle registers itself behind a
85
+ `customElements.get()` check, so whichever script loads **first** wins. If your
86
+ page already loads the full NYSDS, load it before this bundle and its
87
+ definitions — including the complete icon library — stay in place.
88
+
89
+ Loading this bundle first on a page that also uses NYSDS components has one
90
+ consequence worth knowing: `nys-icon` will be the pruned build, so a
91
+ `<nys-button icon="download">` elsewhere on that page renders no icon. Either
92
+ load the full library first, or use `@nysds/components` rather than this bundle
93
+ on pages that need more than the nav.
94
+
95
+ ## Icon pruning
96
+
97
+ `nys-icon` ships 82 icons and lazy-loads them as one map. A drop-in script can't
98
+ lazy-load anything, so the map would land in the bundle whole — about 139 KB of
99
+ source for a nav that uses a couple of dozen icons.
100
+
101
+ At build time, `scripts/icon-allowlist.js` walks the sources that end up in the
102
+ bundle, collects every string literal that names a real icon, and keeps only
103
+ those. The scan is deliberately loose — it matches any quoted lowercase
104
+ identifier and intersects with the library's own keys — because over-matching
105
+ costs a few hundred bytes while under-matching renders a blank square.
106
+
107
+ Two sets of names can't be seen statically and are listed explicitly in
108
+ `RUNTIME_ICONS`:
109
+
110
+ - the values of `FEED_ICONS` in `nys-unavheader`, which the statewide alert feed
111
+ selects by name at runtime
112
+ - the per-type fallback icons `nys-alert` uses when the feed sends none
113
+
114
+ To see what the current scan keeps and drops:
115
+
116
+ ```bash
117
+ npm run icons -w @nysds/nys-unavbundle
118
+ ```
119
+
120
+ If you add an icon to the header or footer, the scan picks it up on the next
121
+ build. If you add one that is chosen at runtime, add it to `RUNTIME_ICONS`.
122
+
123
+ ## Building
124
+
125
+ ```bash
126
+ npm run build -w @nysds/nys-unavbundle
127
+ ```
128
+
129
+ Unlike the per-component packages, this one resolves `@nysds/*` to TypeScript
130
+ **source** rather than each package's `dist/`. That is what lets the icon map be
131
+ intercepted — by the time a package is built, the dynamic `import()` inside
132
+ `icon-library-registry` has already been resolved into a chunk. It also means
133
+ the package is transpiled by esbuild with no `tsc --emitDeclarationOnly` pass, so
134
+ `types/index.d.ts` is hand-maintained.
135
+
136
+ There is a demo page at `demo/index.html` that loads the built file and nothing
137
+ else — if the nav renders there, the bundle is genuinely self-contained.
138
+
139
+ ## License
140
+
141
+ MIT