@kerusiweb/angular 2.1.0 → 2.3.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
@@ -62,6 +62,9 @@ import { KerusiSeatmapComponent } from '@kerusiweb/angular';
62
62
  | --------------------------------- | --------------------- | ---------------- | ------------------------------------------------------------------------------------------------------------------------------- |
63
63
  | `colors` | `KerusiSeatmapColors` | theme defaults | Per-status fills, element tones, focus ring, backdrop. See [Theming](#theming) for the CSS custom properties. |
64
64
  | `typeColors` | `boolean` | `true` | Let an available seat take its `SeatType.color` (§4.7). |
65
+ | `seatTypeStyles` | `SeatTypeStyles` | — | Styles for every seat of a type, keyed by `SeatType.id`. Also shown in the legend. See [From code](#from-code). |
66
+ | `seatStyle` | `SeatStyleFn` | — | A style for one seat, over its type's. Never recolours a selected or blocked seat. See [From code](#from-code). |
67
+ | `<ng-template kerusiSeat>` | content child | — | Draws the inside of every seat yourself. See [Custom seat content](#custom-seat-content). |
65
68
  | `seatSize` | `number` | `28` | Grid cell edge, in viewBox units. |
66
69
  | `seatGap` | `number` | `6` | Gap between grid cells. |
67
70
  | `freeformBasis` | `number` | `1000` | Freeform viewBox width; height follows the aspect ratio. |
@@ -87,6 +90,16 @@ import { KerusiSeatmapComponent } from '@kerusiweb/angular';
87
90
  | `expireHolds` | `boolean` | `false` | Revert a lapsed `holdExpires` to available on a ticker. |
88
91
  | `expiryIntervalMs` | `number` | `1000` | |
89
92
 
93
+ **Zoom, pan and maximize** (both off by default; see [Zoom, pan and maximize](#zoom-pan-and-maximize))
94
+
95
+ | Input | Type | Default | |
96
+ | ------------------ | ------------------------------- | ------- | -------------------------------------------------------------------------------------- |
97
+ | `zoomable` | `boolean` | `false` | Pinch, Ctrl/Cmd + wheel and drag to zoom and pan; `+` `-` `0` keys; on-screen buttons. |
98
+ | `maxZoom` | `number` | `4` | The zoom ceiling, relative to fit. The floor is always fit. |
99
+ | `showZoomControls` | `boolean` | `true` | The built-in zoom buttons. Turn off to supply your own. |
100
+ | `maximizable` | `boolean` | `false` | A button that fills the screen with the map. |
101
+ | `controlStrings` | `Partial<KerusiControlStrings>` | English | The names of the zoom and maximize buttons, for translation. |
102
+
90
103
  ### Outputs
91
104
 
92
105
  | Output | Payload | |
@@ -96,6 +109,8 @@ import { KerusiSeatmapComponent } from '@kerusiweb/angular';
96
109
  | `seatDisallowed` | `SeatDisallowed` | `reason` is `booked`, `held`, `blocked`, `not-selectable`, `max-selection` or `companion-unavailable`. |
97
110
  | `seatFocus` | `RenderSeat` | |
98
111
  | `validationIssues` | `readonly KerusiViolation[]` | Emitted whenever the documents change. |
112
+ | `viewportChange` | `KerusiViewport` | `{ zoom, x, y }`, whenever the zoom or pan changes. Only with `zoomable`. |
113
+ | `maximizedChange` | `boolean` | When the map is maximized or restored. Only with `maximizable`. |
99
114
 
100
115
  ### The seat glyph
101
116
 
@@ -198,9 +213,11 @@ Every key of `KerusiSeatmapColors` has a property, kebab-cased:
198
213
  | `focusRing` | `--kerusi-focus-ring` |
199
214
  | `backdrop` | `--kerusi-backdrop` |
200
215
 
201
- A `SeatType.color` from the document is **not** themable, because it is
202
- the map's own value under §4.7. Turn it off wholesale with
203
- `[typeColors]="false"` if you want the theme to own every fill.
216
+ A `SeatType.color` from the document has **no theme token**, because it is
217
+ the map's own value under §4.7. It can be overridden only seat by seat (or type
218
+ by type) with `--kerusi-seat-fill`; see
219
+ [Styling individual seats](#styling-individual-seats). Turn it off wholesale
220
+ with `[typeColors]="false"` if you want the theme to own every fill.
204
221
 
205
222
  Overriding `selectedBg` does not cost you the selected cue: the core and the
206
223
  figure are shape, not color. Do set `selectedFg` alongside it, though. It is the
@@ -236,7 +253,295 @@ For anything the palette does not cover, each seat group carries class hooks:
236
253
  | `.kerusi-seat--companion` | Has companions (§4.6). |
237
254
 
238
255
  Inside a seat: `.kerusi-seat__box`, `__wash`, `__core`, `__occupant`
239
- (`__occupant--selected` / `--held` / `--booked`), `__label`, `__wheelchair`.
256
+ (`__occupant--selected` / `--held` / `--booked`), `__label`, `__wheelchair`, and,
257
+ only while a [seat template](#custom-seat-content) is in use, `__focus`.
258
+
259
+ ### Styling individual seats
260
+
261
+ The palette themes every seat of a status at once. To pick out _some_ seats (a
262
+ VIP block, every aisle seat, one row), select them in CSS and set the per-seat
263
+ tokens. Each seat's `<g>` carries what the document says about it:
264
+
265
+ | Attribute | Value | Example selector |
266
+ | ---------------------- | ------------------------------------------------------ | --------------------------------- |
267
+ | `data-seat-id` | `Seat.id` | `[data-seat-id="12A"]` |
268
+ | `data-seat-type` | `Seat.type` | `[data-seat-type="recliner"]` |
269
+ | `data-seat-row` | `Seat.row`, when the seat has one | `[data-seat-row="A"]` |
270
+ | `data-seat-status` | `available`, `held`, `booked` or `blocked` | `[data-seat-status="held"]` |
271
+ | `data-seat-attributes` | `Seat.attributes`, space-separated, when there are any | `[data-seat-attributes~="aisle"]` |
272
+ | `data-section-id` | The seat's section | `[data-section-id="balcony"]` |
273
+
274
+ Two tokens then recolour the seats a selector picks out:
275
+
276
+ | Token | Replaces |
277
+ | --------------------- | -------------------------------------------------------------- |
278
+ | `--kerusi-seat-fill` | The seat's own colour: its `SeatType.color`, or `availableBg`. |
279
+ | `--kerusi-seat-label` | The colour of the number drawn on it. |
280
+
281
+ ```css
282
+ kerusi-seatmap :is(.kerusi-seat, .kerusi-legend__item)[data-seat-type='vip'] {
283
+ --kerusi-seat-fill: #d4a017;
284
+ --kerusi-seat-label: #000000;
285
+ }
286
+
287
+ kerusi-seatmap .kerusi-seat[data-seat-attributes~='aisle'] {
288
+ --kerusi-seat-fill: #2f6b45;
289
+ --kerusi-seat-label: #ffffff;
290
+ }
291
+ ```
292
+
293
+ - **Per seat, not global.** The library never sets these tokens and gives them
294
+ no map-wide default. They are meant for a selector that picks seats out;
295
+ setting one on the map itself would repaint every seat and hide the
296
+ document's type colours, which is what `[typeColors]="false"` and `availableBg` are for.
297
+ - **Status still shows.** They replace only the seat's own colour. A held or
298
+ booked seat keeps it under its wash and occupant figure, while a selected seat
299
+ keeps its selected frame and core, and a blocked seat its grey, whatever the
300
+ tokens say. Status is never carried by colour alone.
301
+ - **Set the label with the fill.** The library cannot read a colour set in CSS,
302
+ so it cannot choose a readable number colour for it.
303
+ - **Keep the legend in step.** Each type in the legend carries the same
304
+ `data-seat-type`, and its swatch reads `--kerusi-seat-fill`. Include
305
+ `.kerusi-legend__item` in a type selector, as above, and the key matches the
306
+ map.
307
+ - **Where the rules go.** Put them in a global stylesheet. From a component's
308
+ own stylesheet, Angular's emulated encapsulation scopes them away from the
309
+ map's elements unless you prefix them with `::ng-deep`.
310
+
311
+ #### From code
312
+
313
+ When the choice lives in TypeScript (a recommendation, a search result, the
314
+ document's own `Seat.metadata`), use `seatTypeStyles` for whole types and
315
+ `seatStyle` for single seats. Both take a `KerusiSeatStyle`:
316
+
317
+ | Field | Type | |
318
+ | ------------ | ----------------------------- | ------------------------------------------------------------------------------------------------------------------ |
319
+ | `fill` | `string` | The seat's own colour, the same slot as `--kerusi-seat-fill`. Any CSS colour. |
320
+ | `labelColor` | `string` | The number's colour. Defaults to black or white for a hex `fill`; set it for any other kind of colour. |
321
+ | `className` | `string \| readonly string[]` | Extra classes on the seat's `<g>`, for CSS that needs more than colour. |
322
+ | `shape` | `KerusiSeatShape` | The seat's outline: `'seat'` (default), `'square'`, `'rounded'`, `'circle'`, or a function. See [Shapes](#shapes). |
323
+
324
+ ```ts
325
+ import { SeatStyleFn, SeatTypeStyles } from '@kerusiweb/core';
326
+
327
+ export class VenueComponent {
328
+ protected readonly typeStyles: SeatTypeStyles = {
329
+ vip: { fill: '#d4a017', labelColor: '#000000' },
330
+ };
331
+ protected readonly highlight: SeatStyleFn = (seat) =>
332
+ seat.source.metadata?.['bestView'] ? { fill: '#2f6b45', className: 'best-view' } : undefined;
333
+ }
334
+ ```
335
+
336
+ ```html
337
+ <kerusi-seatmap [map]="map" [seatTypeStyles]="typeStyles" [seatStyle]="highlight" />
338
+ ```
339
+
340
+ A seat's colour resolves in this order, first match wins:
341
+
342
+ | # | Source | |
343
+ | --- | ----------------------------------------- | -------------------------------------------------------- |
344
+ | 1 | Selected | `selectedBg` frame and `selectedFg` core, always. |
345
+ | 2 | Blocked | `blockedBg`, always. |
346
+ | 3 | `--kerusi-seat-fill` from your stylesheet | See above. |
347
+ | 4 | `seatStyle(seat)` | Its `fill`. |
348
+ | 5 | `seatTypeStyles[seat.type]` | Its `fill`. Applies whether or not `[typeColors]` is on. |
349
+ | 6 | `SeatType.color` | When `[typeColors]` is on. |
350
+ | 7 | `availableBg` | The theme. |
351
+
352
+ - **Status always reads.** Neither option can change a selected or blocked
353
+ seat's colour, and a held or booked seat keeps its wash and occupant figure
354
+ over whatever colour it has. A style that could recolour your own picks
355
+ would make them ambiguous. For anything beyond this, use a
356
+ [custom seat template](#custom-seat-content).
357
+ - **Per-seat over per-type, field by field.** A `seatStyle` result replaces only
358
+ the fields it sets, so a type's `fill` survives a per-seat `className`.
359
+ Classes from both are kept.
360
+ - **The legend shows `seatTypeStyles`**, because a type has one value to show.
361
+ A per-seat `seatStyle` has no single value a legend could draw.
362
+ - The function runs for every seat whenever the selection, the state or the
363
+ theme changes, so keep it cheap.
364
+
365
+ #### Shapes
366
+
367
+ A style's `shape` changes the seat's outline. It works in `seatTypeStyles` (a
368
+ sofa type drawn rounded, say) and in `seatStyle`; for every seat at once, use
369
+ `[seatStyle]="circle"` with `circle: SeatStyleFn = () => ({ shape: 'circle' })`.
370
+
371
+ | `shape` | |
372
+ | -------------------------- | --------------------------------------------------------------------------- |
373
+ | `'seat'` | The default: square-ish at the front, tapered at the back. |
374
+ | `'square'` | A square with the same slight corners as the seat's front. |
375
+ | `'rounded'` | A square with soft corners. |
376
+ | `'circle'` | A circle filling the seat's box. |
377
+ | `(box: SeatBox) => string` | Your own closed path `d`, drawn inside `box` (`x`, `y`, `width`, `height`). |
378
+
379
+ - **Status marks follow the shape.** The wash, the selected frame and core, and
380
+ a seat template's focus outline are all drawn in it, and the occupant figure
381
+ and wheelchair marker sit inside every preset.
382
+ - **Only `'seat'` shows which way a seat faces.** The other presets are
383
+ symmetric, so on rotated seats (a fanned theatre, a stadium bowl) that cue is
384
+ lost.
385
+ - **A function shape must draw relative to the box it is given.** It is called
386
+ once for the seat and again for the selected core's smaller box. Leave room
387
+ for the occupant figure (the middle 44% of the width, from 15% to 86% of the
388
+ height) and keep the top-right corner filled for the wheelchair marker.
389
+ - **The legend draws a shaped type in its shape.** Types without a `shape`, and
390
+ every status swatch, keep their usual swatches.
391
+
392
+ ### Custom seat content
393
+
394
+ When the palette and the class hooks are not enough (an icon, a badge, a price
395
+ tag, a different shape), draw the inside of each seat yourself. Put an
396
+ `<ng-template kerusiSeat>` inside the map:
397
+
398
+ ```ts
399
+ import { NgTemplateOutlet } from '@angular/common';
400
+ import { KerusiSeatmapComponent, KerusiSeatTemplateDirective } from '@kerusiweb/angular';
401
+
402
+ @Component({ imports: [KerusiSeatmapComponent, KerusiSeatTemplateDirective, NgTemplateOutlet] /* ... */ })
403
+ ```
404
+
405
+ ```html
406
+ <kerusi-seatmap [map]="map" [state]="state" [(selection)]="picked">
407
+ <ng-template kerusiSeat let-seat>
408
+ <!-- The stock seat, then a badge on top of it. -->
409
+ <ng-container *ngTemplateOutlet="seat.defaultContent; context: { $implicit: seat }" />
410
+ @if (seat.seat.source.metadata?.['bestView']) {
411
+ <svg:circle
412
+ [attr.cx]="seat.glyph.box.x + seat.glyph.box.width"
413
+ [attr.cy]="seat.glyph.box.y"
414
+ r="4"
415
+ fill="gold"
416
+ />
417
+ }
418
+ </ng-template>
419
+ </kerusi-seatmap>
420
+ ```
421
+
422
+ **Prefix every element with `svg:`.** The template is declared outside any
423
+ `<svg>`, so without the prefix Angular creates `<circle>` as an unknown HTML
424
+ element and nothing is drawn. Control flow and `<ng-container>` need no prefix.
425
+
426
+ `let-seat` is a `SeatTemplateContext`:
427
+
428
+ | Field | Type | |
429
+ | ---------------- | ---------------------------------------- | -------------------------------------------------------------------------------------------------- |
430
+ | `seat` | `RenderSeat` | Status, type, price, accessibility, and the document's own `source.metadata`. |
431
+ | `selected` | `boolean` | Whether the seat is in the current selection. |
432
+ | `placed` | `PlacedSeat` | The seat's box, centre, font size and rotation, in viewBox units. |
433
+ | `glyph` | `SeatGlyph` | The stock seat, resolved by `resolveSeatGlyph()` in core: every path, paint and position it draws. |
434
+ | `defaultContent` | `TemplateRef<SeatTemplateOutletContext>` | The stock drawing. Render it with `context: { $implicit: seat }` to keep or add to it. |
435
+
436
+ The template is stamped again whenever the selection, the state or the theme
437
+ changes, and it can sit inside an `@if` to switch it on and off at run time.
438
+
439
+ **What the library keeps.** Each seat's `<g>` stays the library's: its role,
440
+ `aria-label`, `aria-pressed`, `aria-disabled`, tab stop, `data-seat-id`, class
441
+ list, rotation and its click, focus and key handlers. Only what is drawn inside
442
+ it is yours. Keyboard navigation, selection, companions and announcements
443
+ therefore behave exactly as they do for the stock seat, and the accessible name
444
+ still comes from the library (and `ariaStrings`), whatever text you draw.
445
+
446
+ **Coordinates.** Draw in the section's viewBox units, using `glyph.box` (or
447
+ `placed`) for the seat's position and size. The `<g>` already carries the seat's
448
+ rotation, so draw it unrotated with the front at the top edge;
449
+ `glyph.label.transform` counter-rotates text so it stays upright.
450
+
451
+ **Status is yours to show.** A template replaces the stock marks, including the
452
+ occupant figure, the wash and the selected frame and core, which are what tell
453
+ held, booked and selected apart by shape rather than colour (WCAG 1.4.1). The
454
+ library's own styling options never alter those marks, so a template is the one
455
+ place that can, and it carries that responsibility. The simplest way to keep
456
+ them is to render `defaultContent` and add to it. Otherwise reuse `glyph.wash`,
457
+ `glyph.core` and `glyph.occupant`, and the `kerusi-seat__wash` and
458
+ `kerusi-seat__occupant--*` classes, which keep the stock opacity.
459
+
460
+ **Focus outline.** The stock focus ring strokes `.kerusi-seat__box`, which your
461
+ content may not have. So while a seat template is in use, the library draws one
462
+ more path in every seat, after your content: `.kerusi-seat__focus`, an outline
463
+ of the seat's body shown only on `:focus-visible`, so keyboard focus stays
464
+ visible whatever you draw (WCAG 2.4.7). It takes the same colour as the stock
465
+ ring (`--kerusi-focus-ring`, then `colors.focusRing`, then `currentColor`). It
466
+ follows the seat's outline (its [`shape`](#shapes), if a style gives one), not
467
+ your drawing; if you draw your own focus indicator, restyle or hide it with
468
+ `.kerusi-seat:focus-visible .kerusi-seat__focus`. Without a seat template it is
469
+ not rendered at all, and the markup is unchanged.
470
+
471
+ **Legend.** The legend keeps drawing the stock glyph. If your seats look very
472
+ different, turn it off and show your own key.
473
+
474
+ ### Zoom, pan and maximize
475
+
476
+ Two features, both **off by default**: with them off the markup and behaviour are
477
+ exactly what they were. They are independent; turn on either or both.
478
+
479
+ On a phone a map of several hundred seats is drawn at fit-to-width, so a seat is
480
+ too small to tap. `[zoomable]="true"` lets the reader zoom in and pan; `[maximizable]="true"` adds a button
481
+ that fills the screen.
482
+
483
+ **Zoom and pan.**
484
+
485
+ - **Pinch** with two fingers on a touch screen. **Ctrl/Cmd + wheel**, or a
486
+ trackpad pinch (Safari's included), on desktop. A plain wheel is left alone, so
487
+ the page still scrolls.
488
+ - **Drag** with one finger or the primary mouse button to pan.
489
+ - **A tap still selects**, at any zoom level. A touch or click that moves less
490
+ than 8 CSS pixels is a tap, and reaches the seat exactly as it does without
491
+ `zoomable`. Anything that moves further is a drag, and a drag never selects the
492
+ seat under it.
493
+ - **Limits.** The floor is fit-to-container, the ceiling is `maxZoom` (default
494
+ `4`), and panning stays inside the map. A map smaller than its container, which
495
+ happens when it is maximized on a large screen, is centred.
496
+ - **Gestures and the page.** `touch-action` is `pan-y` at fit, so a one-finger
497
+ vertical swipe still scrolls the page while a pinch is the map's; once zoomed in
498
+ or maximized it is `none`. With `zoomable` off, no `touch-action` is set.
499
+ - **Reduced motion.** The short transition on the zoom buttons, the keys and
500
+ reset is dropped under `prefers-reduced-motion: reduce`. A finger or wheel moves
501
+ the map directly and never eases.
502
+
503
+ | Key | |
504
+ | --------------- | ------------------------------------------------------------ |
505
+ | `+` / `=`, `-` | Zoom in / out, from anywhere inside the map |
506
+ | `0` | Reset to fit |
507
+ | `←` `→` `↑` `↓` | Pan, when the zoomable viewport itself has focus (Tab to it) |
508
+
509
+ On a seat, the arrow keys keep their usual job of moving seat focus, and a seat
510
+ that takes keyboard focus is scrolled into view. Ctrl, Cmd and Alt combinations
511
+ are left to the browser, and keys typed into a field you put inside the map are
512
+ ignored.
513
+
514
+ **Controls.** The zoom buttons (zoom in, zoom out, reset to fit) are real
515
+ `<button>`s with accessible names. At a limit they set `aria-disabled` rather than
516
+ `disabled`, so keyboard focus is not thrown away mid-press. Their names come from
517
+ `controlStrings`, for translation. They use the theme's existing tokens
518
+ (`--kerusi-element-bg`, `--kerusi-element-fg`, `--kerusi-element-muted-fg`,
519
+ `--kerusi-focus-ring`), so there is nothing new to theme.
520
+
521
+ To put the controls somewhere else, turn the built-in ones off
522
+ (`[showZoomControls]="false"`) and drive the map yourself:
523
+
524
+ ```ts
525
+ readonly map = viewChild.required(KerusiSeatmapComponent);
526
+ // this.map().zoomIn(); this.map().zoomOut(); this.map().resetZoom(); this.map().toggleMaximized();
527
+ // this.map().viewport() -> { zoom, x, y }
528
+ // this.map().maximized() -> boolean
529
+ ```
530
+
531
+ `viewportChange` reports `{ zoom, x, y }` whenever the view changes, for a host that wants
532
+ to display or persist it. (Restoring a saved view is not supported.)
533
+
534
+ **Maximize.** The button fills the screen with the map and its legend, freezes the
535
+ page behind it, and swaps to an "Exit full screen" button. The layout is a fixed
536
+ overlay, which is all iPhone Safari offers; where the browser has the Fullscreen
537
+ API it is requested on top, and leaving it with the browser's own Esc leaves the
538
+ map's maximized state too. `Escape` from the map also leaves, except that on a
539
+ seat with a non-empty selection the first `Escape` still clears the selection, as
540
+ it always has. The backdrop is `--kerusi-backdrop`, or the page's own canvas colour
541
+ while that is transparent; `--kerusi-maximized-z-index` (default `1000`) sets the
542
+ stacking. It is not a modal dialog: focus is not trapped, and an ancestor with a
543
+ `transform` or `filter` would anchor the fixed layout to itself instead of the
544
+ screen.
240
545
 
241
546
  ### Keyboard
242
547
 
@@ -258,6 +563,8 @@ Each seat is a `role="button"` announcing its position, type, price, status,
258
563
  every `Seat.accessibility` property and its attributes. A polite live region
259
564
  reports the running selection and any disallowed reason.
260
565
 
566
+ With `zoomable` on there are a few more keys: see [Zoom, pan and maximize](#zoom-pan-and-maximize).
567
+
261
568
  ---
262
569
 
263
570
  ## `<kerusi-legend>`