@uvalib/web-components 1.12.1 → 1.13.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/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # Changelog
2
2
 
3
+ ## v1.13.0 — 2026-12-02
4
+
5
+ ### Features
6
+
7
+ - <uvalib-qr>, a QR code styled for UVA Library
8
+
9
+ ### Fixes
10
+
11
+ - the visible address may wrap after each slash and dot
12
+
13
+ ### Other
14
+
15
+ - Merge branch 'feat/uvalib-qr': <uvalib-qr>, a QR code styled for UVA Library
16
+ - Event cards with a QR code example, as Scholars' Lab's event slides
17
+ - register uvalib-qr (vite, manifest, exports, index, size budgets, base.css pre-upgrade hold, catalogue tests)
18
+ - add lean-qr 2.7.4 for <uvalib-qr>
19
+
3
20
  ## v1.12.1 — 2026-11-30
4
21
 
5
22
  ### Features
package/README.md CHANGED
@@ -15,6 +15,7 @@ Reusable web components for UVA Library sites, built with Lit and TypeScript:
15
15
  - **Search:** `<uvalib-filter>`, `<uvalib-date-range>`, `<uvalib-date-histogram>`, `<uvalib-combobox>` (a text field that suggests values as you type), `<uvalib-list-filter>` (a field that filters a long list on the page as you type), `<uvalib-filter-drawer>` (the filters as a sidebar, or a modal panel on phones), `<uvalib-dialog>` (a modal dialog for search tips, Cite or a short form) and `<uvalib-pagefind-search>` (with `pagefind.css`, the library theme for Pagefind static-site search).
16
16
  - **Reading texts:** `edition.css` (reading styles for TEI texts converted to class-annotated HTML), and `edition-epub.css` / `edition-print.css` for the same texts as EPUB and PDF downloads.
17
17
  - **Audio:** `<uvalib-audio>` (a long recording played by chapter: an audiobook, an oral history).
18
+ - **QR codes:** `<uvalib-qr>` (a QR code in the library's colours, for an event's page on a slide or a poster).
18
19
  - **Library hours:** `<site-hours-section>`, `<library-weekly-hours>` and `<library-hours-setup>`.
19
20
  - **Library events:** `<events-section>`.
20
21
  - **Search results:** `<bento-box>` (library.virginia.edu/search), with its `<catalog-section>`, `<articles-section>`, `<libguides-section>` and `<website-section>`.
@@ -1338,6 +1339,34 @@ For the same text offered as an EPUB 3 file or a PDF printed from the same HTML,
1338
1339
  - **Analytics.** `['uvalib-audio', 'play', 'chapter <N>', N]` the first time each chapter plays in a page view (N is its place in the list, never the title or URL), `complete` when it plays to its end, `speed` once the visitor settles on one (name and value the speed), `resume` with the chapter, and `download` (`recording` or `chapter <N>`).
1339
1340
  - Shadow DOM by default; `no-shadow-dom` and `no-style` as for the other components; dark mode, forced colors and 320px reflow. Room for a cast or credits is the page's: a `.uvalib-table` after it.
1340
1341
 
1342
+ ## QR codes
1343
+
1344
+ `<uvalib-qr>` draws a QR code for a link, styled for UVA Library: an event's page on a slide (as Scholars' Lab's event slides show them), a poster or a room sign. Entry: `uvalib-qr.js` on the CDN, `@uvalib/web-components/uvalib-qr.js` on npm. See the [Event cards with a QR code](https://uvalib.github.io/reusable-web-library/#event-qr) example.
1345
+
1346
+ ```html
1347
+ <script
1348
+ type="module"
1349
+ src="https://unpkg.internal.lib.virginia.edu/web-components/v1/uvalib-qr.js"
1350
+ ></script>
1351
+
1352
+ <uvalib-qr
1353
+ value="https://scholarslab.lib.virginia.edu/events/mapping-the-book-trade/"
1354
+ show-link
1355
+ ></uvalib-qr>
1356
+ ```
1357
+
1358
+ - **The look.** UVA navy modules (`--uva-brand-blue`, 13:1 on white) on a white tile, the three eyes with rounded corners, and a thin orange frame around the tile. The orange is decoration and carries no part of the code (orange on white is about 2.9:1, too low to scan). `variant="plain"` is square black modules with no frame, for the oldest scanners. `--uvalib-qr-color` changes the modules (keep it dark, at least 7:1 on white) and `--uvalib-qr-frame` the frame.
1359
+ - **No logo by default.** The University's marks may not be cut apart, boxed or used alone (the Rotunda is a limited-use mark), so the component ships no logo. A site with artwork it is cleared to use gives `logo-src` (and `logo-alt`, added to the code's name; without it the logo is decorative): the modules under the centre are cleared (`logo-size`, the cleared square's side as a percentage of the code's, default 20) and error correction is level H whatever `error-correction` says. The cleared area is at most 10% of the code (`logo-size` up to about 31; more is cut to that, with a console warning): in testing, 20% failed to read on some sizes of code.
1360
+ - **Accessible name.** An inline `<svg role="img">` named by its `<title>`: `label`, else "QR code for scholarslab.lib.virginia.edu/events/mapping-the-book-trade" (the address without its scheme, `www.`, query or fragment), or for text that is not a URL, "QR code for" and the text in quotation marks (cut at 60 characters).
1361
+ - **A link for people who cannot scan.** The image is never a link (images as links are discouraged). `show-link` adds the address under it as a real `<a>` (its visible text is its name; it may wrap after a slash or dot), and `link-label` gives it other text (and implies `show-link`). Only `http`, `https`, `mailto` and `tel` addresses become links. With several codes on a page, keep each link's text different.
1362
+ - **Size.** `size` is the tile's width and height, a number of pixels or a CSS length (default 10rem), and sets `--uvalib-qr-size` on the element; it is never wider than its container. `quiet-zone` is the white margin in modules (default 4, the standard minimum; 0 to 16). `error-correction` is `L`, `M` (default), `Q` or `H`.
1363
+ - **Dark mode, forced colors and print.** The code stays dark on its white tile in dark mode (scanners need dark on light; it is never inverted). In forced colors it keeps its colours as an image, outlined in the system text colour. In print the frame is dropped and the quiet zone kept.
1364
+ - **Export.** `toSvgString({ scale })` is a standalone SVG of the code (the modules in their drawn colour on white, with the quiet zone and the logo by its URL, `scale` pixels per module, default 10; no frame), `toDataURL()` the same as a `data:` URL, and `download('name.svg')` saves it (call it from a button press). `code` is the encoded symbol (`size`, `level`, `get(x, y)`, `clear`).
1365
+ - **Errors.** An empty value, or one too long for a QR code, shows "QR code unavailable" in the tile, with a console warning; the visible link still shows when the value is a URL.
1366
+ - **Before it upgrades**, `base.css` holds its square (`--uvalib-qr-size`, or the `size` attribute where the browser reads `attr()` lengths) and one line for the link, so nothing moves. A link that wraps to more lines moves what follows by those lines.
1367
+ - **Analytics.** `['uvalib-qr', 'link-click']` when the visible link is followed, never the URL. Showing the code is not an interaction and reports nothing.
1368
+ - Shadow DOM by default; `no-shadow-dom` and `no-style` (the code keeps its colours and its square) as for the other components; 320px reflow. It is encoded with [lean-qr](https://github.com/davidje13/lean-qr) (MIT), bundled.
1369
+
1341
1370
  ## Back to top
1342
1371
 
1343
1372
  `<uvalib-back-to-top>` is a “Back to top” button for long pages: minutes, finding aids, transcriptions, long result lists. Entry: `uvalib-back-to-top.js` on the CDN, `@uvalib/web-components/uvalib-back-to-top.js` on npm. See the [Back to top](https://uvalib.github.io/reusable-web-library/#back-to-top) example.
@@ -2258,6 +2287,7 @@ Static sites that search with [Pagefind](https://pagefind.app) (such as Electron
2258
2287
  | `uvalib-audio` | `speed` (1 s after the last change, if it differs) | the speed, such as `1.5` | the speed |
2259
2288
  | `uvalib-audio` | `resume` (the Resume button) | `chapter <N>` | N |
2260
2289
  | `uvalib-audio` | `download` | `recording`, or `chapter <N>` | |
2290
+ | `uvalib-qr` | `link-click` (the visible link under the code; the code itself reports nothing) | | |
2261
2291
  | `uvalib-filter-drawer` | `open`, `close` (by the visitor: the button, Close, Escape or the backdrop; not a resize or a script) | the drawer's `label` | |
2262
2292
  | `uvalib-back-to-top` | `click` | | |
2263
2293
  | `uvalib-dialog` | `open` (a visitor's button), `close` (by the visitor: Close, a close button, Escape, the backdrop or a dialog form; not a script) | the dialog's `label` (never its content) |
@@ -3952,6 +3982,53 @@ Justified rows of thumbnails. Each direct child that is a link or a button is on
3952
3982
  | `--uva-grey-darkest` | `#2b2b2b` | Caption colour when `--uva-color-text` is unset. |
3953
3983
  | `--uva-brand-orange` | `#e57200` | Focus ring when `--uva-color-focus` is unset. |
3954
3984
 
3985
+ ### `<uvalib-qr>`
3986
+
3987
+ A QR code for a link (an event's page on a slide or a poster), styled for UVA Library: modules in UVA navy on a white tile, the three "eyes" with rounded corners, and a thin orange frame around the tile that carries no part of the code. `variant="plain"` is a square black code with no frame, for the oldest scanners. It is an inline `<svg role="img">` whose `<title>` names it (`label`, else "QR code for example.org/path"), crisp at any size and in print. The code stays dark on its white tile in dark mode and in forced colors (scanners need that), and the quiet zone (`quiet-zone`, 4 modules) is part of the tile. The image is not a link; `show-link` (or `link-label`) adds the address as a real link under it, for people who cannot scan. No logo is drawn by default (the University's marks may not be cut apart or boxed). A site with approved artwork gives `logo-src` (and `logo-alt`): the modules under the centre are cleared (`logo-size`, 20% of the side; at most 10% of the area), and level H is used. A value that cannot be encoded (empty, or too long) shows "QR code unavailable" in the tile, with a console warning.
3988
+
3989
+ #### Attributes
3990
+
3991
+ | Attribute | Type | Default | Description |
3992
+ |---|---|---|---|
3993
+ | `value` | `string` | `''` | The text encoded: usually a URL (required). |
3994
+ | `label` | `string` | `''` | The code's accessible name (default "QR code for example.org/path"). |
3995
+ | `size` | `string` | `''` | The tile's width and height: a number of pixels, or a CSS length (default 10rem). |
3996
+ | `error-correction` | `string` | `''` | `L`, `M`, `Q` or `H` (default `M`; always `H` with a logo). |
3997
+ | `quiet-zone` | `number` | `4` | White modules around the code: 4 is the standard minimum (0 to 16). |
3998
+ | `variant` | `string` | `''` | `plain`: square black modules, no frame, for maximum compatibility. Default: branded. |
3999
+ | `show-link` | `boolean` | `false` | Show the address as a link under the code (http, https, mailto and tel only). |
4000
+ | `link-label` | `string` | `''` | The visible link's text (default the address without its scheme); implies `show-link`. |
4001
+ | `logo-src` | `string` | `''` | Approved logo artwork for the centre (an image URL). Off by default. |
4002
+ | `logo-alt` | `string` | `''` | The logo's text alternative, added to the code's name; empty means decorative. |
4003
+ | `logo-size` | | `QR_LOGO_SIZE` | The cleared centre's side, in % of the symbol's side (default 20; at most about 31). |
4004
+ | `no-shadow-dom` | `boolean` | `false` | |
4005
+ | `no-style` | `boolean` | `false` | |
4006
+
4007
+ #### CSS parts
4008
+
4009
+ | Part | Description |
4010
+ |---|---|
4011
+ | `tile` | The white tile (the code and its quiet zone), with the frame. |
4012
+ | `svg` | The code's `<svg>`. |
4013
+ | `link` | The visible link under the code (`show-link`). |
4014
+ | `fallback` | The "QR code unavailable" text. |
4015
+
4016
+ #### Events
4017
+
4018
+ | Event | Description |
4019
+ |---|---|
4020
+ | `uvalib-analytics-event` | For `<site-analytics>`: `['uvalib-qr', 'link-click']` when the visible link is followed (never the URL). Bubbles and is composed. |
4021
+
4022
+ #### CSS custom properties
4023
+
4024
+ | Property | Default | Description |
4025
+ |---|---|---|
4026
+ | `--uvalib-qr-size` | `10rem` | The tile's width and height (the `size` attribute sets it). At most the container's width. |
4027
+ | `--uvalib-qr-color` | `#232d4b` | The modules (else `--uva-brand-blue`). Keep it dark: at least 7:1 on white. |
4028
+ | `--uvalib-qr-frame` | `#e57200` | The frame (else `--uva-brand-orange`). It is decoration: never needed to scan. |
4029
+ | `--uva-color-link` | | Dark-mode role token: the visible link (else `--uva-brand-blue`). |
4030
+ | `--uva-color-focus` | | Dark-mode role token: focus ring (else `--uva-brand-orange`). |
4031
+
3955
4032
  ### `<uvalib-results-count>`
3956
4033
 
3957
4034
  The results summary of a search or listing page, such as “Showing 48 of 3,694 shoots”, and a polite live region that tells screen reader users when it changes. Set `total` (how many match), `shown` (how many are on the page) and `noun` (plural, default “results”; `singular` for a total of one). The visible text follows at once: “Showing 48 of 3,694 shoots”, “Showing all 12 shoots” (shown is the total, or unset), “Showing 1 shoot” or “No shoots” (a total of 0, or 0 shown); with only `shown`, “Showing 48 shoots”. Numbers use thousands separators. A missing or blank `shown` or `total` is unset, not 0. The announcement waits until the text has not changed for `announce-delay` milliseconds (default 1000, as `<bento-box>` and `<uvalib-pagefind-search>` settle), so typing in a filter box is announced once. The first render is never announced; when it has no count yet (the data still loading), the first count that arrives is. A count is announced again when it comes back after a different one (a new search with the same number of results), but not when nothing was shown in between. The announcement is cleared from the hidden region five seconds later, so reading the page finds the count once. `<bento-box>` and `<uvalib-pagefind-search>` announce their own counts: use this element for your own listings, not beside them.
package/dist/base.css CHANGED
@@ -212,7 +212,8 @@
212
212
  uvalib-filter-drawer,
213
213
  uvalib-filter,
214
214
  uvalib-list-filter,
215
- uvalib-audio
215
+ uvalib-audio,
216
+ uvalib-qr
216
217
  ):not(:defined)[hidden],
217
218
  :where(uvalib-combobox, uvalib-image-regions):not(:defined) > [hidden] {
218
219
  display: none;
@@ -430,6 +431,31 @@ uvalib-metadata:not(:defined) > dl > dd[data-limit="12"] > :is(ul, ol):has(> li:
430
431
  uvalib-audio:not(:defined) > :is(ol, ul) > li > a:first-child {
431
432
  margin-inline-start: calc(0.5rem + 5rem + 0.75rem);
432
433
  }
434
+ /* A QR code (<uvalib-qr>): the square tile, as wide as --uvalib-qr-size (or the size
435
+ attribute, where the browser reads attr() as a length) and at most its container, and
436
+ one line for the visible link (show-link or link-label), so nothing moves when it is
437
+ drawn. A link that wraps to more lines still moves what follows by those lines. Keep in
438
+ step with UvalibQr's rules. */
439
+ uvalib-qr:not(:defined) {
440
+ display: block;
441
+ inline-size: var(--uvalib-qr-size, 10rem);
442
+ max-inline-size: 100%;
443
+ }
444
+ /* A number is pixels, else a length: one of the two terms is 0. A browser without attr()
445
+ lengths drops this and holds --uvalib-qr-size. */
446
+ uvalib-qr[size]:not(:defined) {
447
+ inline-size: calc(attr(size px, 0px) + attr(size type(<length-percentage>), 0px));
448
+ }
449
+ uvalib-qr:not(:defined)::before {
450
+ content: '';
451
+ display: block;
452
+ aspect-ratio: 1;
453
+ }
454
+ uvalib-qr:is([show-link], [link-label]):not(:defined)::after {
455
+ content: '';
456
+ display: block;
457
+ block-size: calc(0.5rem + 0.875rem * 1.7);
458
+ }
433
459
  /* Image regions: the image at its own width and the list beside it (or under it), the
434
460
  layout the element keeps once it upgrades, so the image does not move. */
435
461
  uvalib-image-regions:not(:defined) {
@@ -0,0 +1,139 @@
1
+ import { type PropertyValues } from 'lit';
2
+ import { UvalibElement } from '../../base/UvalibElement.js';
3
+ /** Error-correction levels: the share of the symbol that can be lost and still read. */
4
+ export type QrErrorCorrection = 'L' | 'M' | 'Q' | 'H';
5
+ /** Default `logo-size`: the cleared centre's side, in % of the symbol's side. */
6
+ export declare const QR_LOGO_SIZE = 20;
7
+ /**
8
+ * The cleared centre may cover at most this share of the symbol's area (with level H): 10%, about
9
+ * 31% of the side. 20% did not decode at every size in testing (version 13 failed from 11%).
10
+ */
11
+ export declare const QR_LOGO_MAX_AREA = 0.1;
12
+ /** The encoded symbol: its module grid (without the quiet zone) and how it was made. */
13
+ export interface QrCode {
14
+ /** Modules per side (21 for version 1, up to 177). */
15
+ readonly size: number;
16
+ /** The error-correction level used (H whenever there is a logo). */
17
+ readonly level: QrErrorCorrection;
18
+ /** Whether the module at column `x`, row `y` is dark, as encoded (before any logo). */
19
+ get(x: number, y: number): boolean;
20
+ /** The square of modules cleared for the logo, in module units, if there is one. */
21
+ readonly clear: {
22
+ readonly x: number;
23
+ readonly y: number;
24
+ readonly size: number;
25
+ } | null;
26
+ }
27
+ /** `https://www.example.org/a/b/?q#h` → `example.org/a/b`; null when `value` is not such a URL. */
28
+ export declare function shortUrl(value: string): string | null;
29
+ /** The modules as one path (even-odd fill), with rounded eyes unless `plain`. */
30
+ export declare function qrPath(code: QrCode, plain: boolean): string;
31
+ /**
32
+ * The side of the cleared centre, in modules: odd (so it is centred), about `percent` of the
33
+ * side, and never more than `QR_LOGO_MAX_AREA` of the symbol's area.
34
+ */
35
+ export declare function clearSide(n: number, percent: number): {
36
+ side: number;
37
+ limited: boolean;
38
+ };
39
+ /**
40
+ * A QR code for a link (an event's page on a slide or a poster), styled for UVA Library:
41
+ * modules in UVA navy on a white tile, the three "eyes" with rounded corners, and a thin orange
42
+ * frame around the tile that carries no part of the code. `variant="plain"` is a square black
43
+ * code with no frame, for the oldest scanners.
44
+ *
45
+ * It is an inline `<svg role="img">` whose `<title>` names it (`label`, else "QR code for
46
+ * example.org/path"), crisp at any size and in print. The code stays dark on its white tile in
47
+ * dark mode and in forced colors (scanners need that), and the quiet zone (`quiet-zone`, 4
48
+ * modules) is part of the tile. The image is not a link; `show-link` (or `link-label`) adds the
49
+ * address as a real link under it, for people who cannot scan.
50
+ *
51
+ * No logo is drawn by default (the University's marks may not be cut apart or boxed). A site
52
+ * with approved artwork gives `logo-src` (and `logo-alt`): the modules under the centre are
53
+ * cleared (`logo-size`, 20% of the side; at most 10% of the area), and level H is used.
54
+ *
55
+ * A value that cannot be encoded (empty, or too long) shows "QR code unavailable" in the tile,
56
+ * with a console warning.
57
+ *
58
+ * @tagname uvalib-qr
59
+ * @fires uvalib-analytics-event - For `<site-analytics>`: `['uvalib-qr', 'link-click']` when the visible link is followed (never the URL). Bubbles and is composed.
60
+ * @csspart tile - The white tile (the code and its quiet zone), with the frame.
61
+ * @csspart svg - The code's `<svg>`.
62
+ * @csspart link - The visible link under the code (`show-link`).
63
+ * @csspart fallback - The "QR code unavailable" text.
64
+ * @cssprop [--uvalib-qr-size=10rem] - The tile's width and height (the `size` attribute sets it). At most the container's width.
65
+ * @cssprop [--uvalib-qr-color=#232d4b] - The modules (else `--uva-brand-blue`). Keep it dark: at least 7:1 on white.
66
+ * @cssprop [--uvalib-qr-frame=#e57200] - The frame (else `--uva-brand-orange`). It is decoration: never needed to scan.
67
+ * @cssprop --uva-color-link - Dark-mode role token: the visible link (else `--uva-brand-blue`).
68
+ * @cssprop --uva-color-focus - Dark-mode role token: focus ring (else `--uva-brand-orange`).
69
+ */
70
+ export declare class UvalibQr extends UvalibElement {
71
+ static styles: import("lit").CSSResult[];
72
+ /** The text encoded: usually a URL (required). */
73
+ value: string;
74
+ /** The code's accessible name (default "QR code for example.org/path"). */
75
+ label: string;
76
+ /** The tile's width and height: a number of pixels, or a CSS length (default 10rem). */
77
+ size: string;
78
+ /** `L`, `M`, `Q` or `H` (default `M`; always `H` with a logo). */
79
+ errorCorrection: string;
80
+ /** White modules around the code: 4 is the standard minimum (0 to 16). */
81
+ quietZone: number;
82
+ /** `plain`: square black modules, no frame, for maximum compatibility. Default: branded. */
83
+ variant: string;
84
+ /** Show the address as a link under the code (http, https, mailto and tel only). */
85
+ showLink: boolean;
86
+ /** The visible link's text (default the address without its scheme); implies `show-link`. */
87
+ linkLabel: string;
88
+ /** Approved logo artwork for the centre (an image URL). Off by default. */
89
+ logoSrc: string;
90
+ /** The logo's text alternative, added to the code's name; empty means decorative. */
91
+ logoAlt: string;
92
+ /** The cleared centre's side, in % of the symbol's side (default 20; at most about 31). */
93
+ logoSize: number;
94
+ private _code;
95
+ private _path;
96
+ private warned;
97
+ /** The encoded symbol, or null when the value could not be encoded. */
98
+ get code(): QrCode | null;
99
+ private warn;
100
+ private get hasLogo();
101
+ private get quiet();
102
+ private get plain();
103
+ private level;
104
+ private encode;
105
+ protected willUpdate(changed: PropertyValues<this>): void;
106
+ /** `size` sets `--uvalib-qr-size` on the element (a number is pixels). */
107
+ private applySize;
108
+ /** The page's inline `--uvalib-qr-size` from before `size` set it ('' for none). */
109
+ private ownSize?;
110
+ createRenderRoot(): HTMLElement | DocumentFragment;
111
+ connectedCallback(): void;
112
+ /** The visible address, or null when `value` is not a URL. */
113
+ private get short();
114
+ /** The code's accessible name, as the `<title>` gives it. */
115
+ get accessibleName(): string;
116
+ /** The href of the visible link, if the value is a URL with a safe scheme. */
117
+ private get href();
118
+ private readonly onLinkClick;
119
+ /** The colours the code is drawn in now (resolved from the page's styles). */
120
+ private colors;
121
+ /**
122
+ * The code as a standalone SVG document (for a poster or a print shop): the modules in the
123
+ * colour they are drawn in, on white, with the quiet zone and the logo (by its URL), at
124
+ * `scale` pixels per module (default 10). The frame is the page's and is not included.
125
+ * Empty when the value could not be encoded.
126
+ */
127
+ toSvgString({ scale }?: {
128
+ scale?: number;
129
+ }): string;
130
+ /** `toSvgString()` as a `data:image/svg+xml` URL. Empty when the value could not be encoded. */
131
+ toDataURL(options?: {
132
+ scale?: number;
133
+ }): string;
134
+ /** Save `toSvgString()` as a file (default `qr-code.svg`). Call it from a visitor's click. */
135
+ download(filename?: string): void;
136
+ private logoBox;
137
+ private logoMarkup;
138
+ protected render(): import("lit").TemplateResult<1>;
139
+ }