@fusion.dev/helix-headless 0.101.0 → 0.103.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.
@@ -85,6 +85,7 @@ registerElementEvents({
85
85
  'toggle',
86
86
  ],
87
87
  'helix-headless-listbox': ['change', 'helix-before-change', 'helix-filter', 'input'],
88
+ 'helix-headless-map': ['helix-map-pan', 'helix-map-zoom'],
88
89
  'helix-headless-megamenu': ['helix-before-close', 'helix-before-open', 'toggle'],
89
90
  'helix-headless-menu': ['helix-before-close', 'helix-before-open', 'helix-select', 'toggle'],
90
91
  'helix-headless-menu-item': ['helix-select'],
package/dist/index.d.ts CHANGED
@@ -58,6 +58,7 @@ export * from './line-chart/index.js';
58
58
  export * from './list/index.js';
59
59
  export * from './listbox/index.js';
60
60
  export * from './loader/index.js';
61
+ export * from './map/index.js';
61
62
  export * from './megamenu/index.js';
62
63
  export * from './menu/index.js';
63
64
  export * from './meter/index.js';
package/dist/index.js CHANGED
@@ -49,6 +49,7 @@ export * from './line-chart/index.js';
49
49
  export * from './list/index.js';
50
50
  export * from './listbox/index.js';
51
51
  export * from './loader/index.js';
52
+ export * from './map/index.js';
52
53
  export * from './megamenu/index.js';
53
54
  export * from './menu/index.js';
54
55
  export * from './meter/index.js';
@@ -0,0 +1 @@
1
+ export { HelixHeadlessMap } from './root/map-root.js';
@@ -0,0 +1 @@
1
+ export { HelixHeadlessMap } from './root/map-root.js';
@@ -0,0 +1,195 @@
1
+ import { HelixElement } from '@fusion.dev/helix-core';
2
+ import { type PropertyValues, type TemplateResult } from 'lit';
3
+ /** Which way a press or a key asked the map to go. */
4
+ type Way = 'up' | 'down' | 'start' | 'end';
5
+ /** Where the controls sit, in the corner words the rest of the library uses. */
6
+ export type MapControlsPlacement = 'top-start' | 'top-end' | 'bottom-start' | 'bottom-end';
7
+ /**
8
+ * @summary A frame around somebody else's map.
9
+ *
10
+ * @description
11
+ * **Helix draws no map.** There are no tiles here, no projection and no
12
+ * network, and there should not be: a tile renderer is a library, and what a
13
+ * design system can add to MapLibre or Leaflet is the frame. The consumer slots
14
+ * their map and this owns the box, the name, the controls and the way out,
15
+ * which is the shape `VideoPlaylist` uses for a player it never renders.
16
+ *
17
+ * **The accessibility argument is the reason this exists**, and it was measured
18
+ * rather than assumed: a map embedded the ordinary way is a canvas with no role
19
+ * and no name, and it has *no node at all* in the accessibility tree. A reader
20
+ * using a screen reader does not walk past it so much as never meet it. A named
21
+ * region with controls in it is the whole of the difference.
22
+ *
23
+ * **The controls are buttons, and that is a deliberate choice against arrow
24
+ * keys.** Arrows work here too, but what a screen reader does with them is not
25
+ * ours to decide: macOS passes them through, Windows readers hold them for
26
+ * their own reading mode unless a page takes `role="application"`, which costs
27
+ * the reader their normal way of reading everything else in the frame. A button
28
+ * is findable and operable in every screen reader on every platform without
29
+ * that bargain, so panning and zooming are buttons first and keys second.
30
+ *
31
+ * **Nothing here moves the map.** Both controls ask, through `helix-map-pan`
32
+ * and `helix-map-zoom`, and the consumer answers against whatever they slotted.
33
+ * A frame that moved the map would have to know whose map it was.
34
+ *
35
+ * @since 0.100.0
36
+ * @status stable
37
+ * @category media
38
+ * @aliases Map frame, Map container, Geo
39
+ * @documentation https://fusion.dev/helix/components/map
40
+ *
41
+ * @slot - The map, which is the consumer's own.
42
+ * @slot attribution - Whoever the tiles belong to, which most licenses require you to say.
43
+ * @slot footer - Chrome below the map, such as a legend or a scale.
44
+ * @slot header - Chrome above the map, such as a title or a search field.
45
+ *
46
+ * @event {HelixMapPanEvent} helix-map-pan - The reader asked the map to move. Answer it against your own map.
47
+ * @event {HelixMapZoomEvent} helix-map-zoom - The reader asked the map to zoom, by a direction rather than to a level.
48
+ *
49
+ * @csspart controls - The group the pan and zoom buttons sit in.
50
+ * @csspart fullscreen - The button that fills the screen.
51
+ * @csspart pan-down - The button that moves the map down.
52
+ * @csspart pan-end - The button that moves the map the way the text ends, which is right on an English page.
53
+ * @csspart pan-start - The button that moves the map the way the text starts, which is left on an English page.
54
+ * @csspart pan-up - The button that moves the map up.
55
+ * @csspart region - The named region the map is slotted into.
56
+ * @csspart viewport - The box the map is drawn in.
57
+ * @csspart zoom-in - The button that zooms in.
58
+ * @csspart zoom-out - The button that zooms out.
59
+ *
60
+ * @cssstate fullscreen - While the frame fills the screen.
61
+ * @cssstate idle - While the reader has been still long enough to hide the chrome.
62
+ */
63
+ export declare class HelixHeadlessMap extends HelixElement {
64
+ /**
65
+ * Which of the controls this frame draws, as a list of what to keep.
66
+ *
67
+ * **A list rather than a switch, because the overlap is not symmetric.**
68
+ * Every map library draws zoom controls and none of them draws pan buttons:
69
+ * MapLibre's navigation control is zoom and a compass, Leaflet's is zoom,
70
+ * Google's is zoom. So a consumer slotting one of those has our zoom twice
71
+ * over and our pan pad not at all, and a single switch would make them choose
72
+ * between a duplicate and nothing.
73
+ *
74
+ * `none` draws none of them, which is the right answer where the slotted map
75
+ * already has controls a reader can find: what this family argues for is that
76
+ * *a* findable control exists, never that it is ours. The methods stay public
77
+ * either way, so a consumer drawing their own chrome can still drive the
78
+ * frame.
79
+ *
80
+ * Absent is all three, which is this library's rule that a resting value is an
81
+ * attribute's absence, and it is what the stylesheet asks about: the layout
82
+ * rules are written against `[controls]:not([controls~="zoom"])` rather than
83
+ * the bare negation, or a frame that named no list at all would be laid out as
84
+ * though it had dropped everything.
85
+ */
86
+ controls?: string;
87
+ /**
88
+ * Which corner the controls sit in.
89
+ *
90
+ * **Configurable because there is no safe default**, and this is a collision
91
+ * rather than a taste: MapLibre puts its own controls at the top end, Leaflet
92
+ * and OpenLayers at the top start, Google's zoom at the bottom end. Whichever
93
+ * corner this took would land on somebody's, which is why every one of those
94
+ * libraries made it a setting too.
95
+ *
96
+ * Logical corners rather than left and right, so a right-to-left page moves
97
+ * them without a consumer writing a second rule.
98
+ *
99
+ * Absent is the top end, which is this library's rule that a resting value is
100
+ * an attribute's absence: a default that reflected would write an attribute
101
+ * onto every host that no server sent and nobody asked for.
102
+ */
103
+ controlsPlacement?: MapControlsPlacement;
104
+ /** What the control that fills the screen is called. */
105
+ fullscreenLabel: string;
106
+ /**
107
+ * How long the reader may be still before the chrome hides, in milliseconds.
108
+ *
109
+ * Zero keeps it up, which is the default: a map's controls are how a keyboard
110
+ * reader operates it, and chrome that hides itself by default would be this
111
+ * component undoing its own argument. Set it for a display map nobody drives.
112
+ */
113
+ idleDelay: number;
114
+ /**
115
+ * Accessible name for the map, which is the one thing a consumer must write.
116
+ *
117
+ * There is no sensible default. "Map" names the widget rather than the place,
118
+ * and a reader meeting three of them on a page learns nothing from hearing the
119
+ * same word three times.
120
+ */
121
+ label: string;
122
+ /**
123
+ * What the controls are called, for a page not in English.
124
+ */
125
+ panLabel: string;
126
+ /**
127
+ * How far one press moves the map, as a fraction of what is on screen.
128
+ *
129
+ * A fraction rather than a distance, because this frame does not know the
130
+ * scale of what is inside it: a quarter of the viewport is the same gesture at
131
+ * street level and at country level, and a consumer who wants metres can
132
+ * multiply by their own.
133
+ */
134
+ panStep: number;
135
+ /** What the zoom controls are called. */
136
+ zoomInLabel: string;
137
+ /** What the zoom control that goes the other way is called. */
138
+ zoomOutLabel: string;
139
+ /** Whether the reader has been still long enough to hide the chrome. */
140
+ private resting;
141
+ /** Whether the frame is filling the screen. */
142
+ private filled;
143
+ private readonly fullscreen;
144
+ private readonly idle;
145
+ /** Whether a named group of controls is one this frame draws. */
146
+ private draws;
147
+ /** Fills the screen with the frame, or comes back. */
148
+ toggleFullscreen(): void;
149
+ /** Asks for the map to move, which the consumer answers. */
150
+ pan(to: Way): void;
151
+ /** Asks for the map to zoom, `1` in and `-1` out. */
152
+ zoom(by: number): void;
153
+ /**
154
+ * The arrow keys, which are the second way rather than the only one.
155
+ *
156
+ * `inlineStep` rather than a test against `ArrowLeft`, so the reader on a
157
+ * right-to-left page gets `end` from the key that points the way their text
158
+ * runs, which is what the pan buttons say too.
159
+ */
160
+ private readonly handleKeydown;
161
+ /**
162
+ * Starts the wait, so a map nobody has touched counts as still.
163
+ *
164
+ * Without this the timer only ever starts on a pointer or a focus, and a frame
165
+ * rendered on a page the reader never reaches stays awake for as long as the
166
+ * page is open: the chrome a consumer asked to hide would hide only after
167
+ * being used once, which is the opposite of what an idle delay is for.
168
+ */
169
+ protected firstUpdated(changed: PropertyValues): void;
170
+ protected willUpdate(changed: PropertyValues): void;
171
+ /**
172
+ * What one pan button is called, with the way it goes filled in.
173
+ *
174
+ * Left and right rather than start and end, because the label is read aloud
175
+ * and a reader knows which way left is. The event keeps the reading-order
176
+ * name, which is the one a right-to-left page needs.
177
+ */
178
+ private named;
179
+ /**
180
+ * The controls, or nothing where a consumer kept none of them.
181
+ *
182
+ * **Written out rather than generated**, because a part name behind an
183
+ * interpolation is a part the manifest cannot see: it would publish `pan-`
184
+ * and a consumer's `::part(pan-up)` would match nothing. The same cost
185
+ * `drawIcon` names for `Trend`.
186
+ */
187
+ private renderControls;
188
+ protected render(): TemplateResult;
189
+ }
190
+ declare global {
191
+ interface HTMLElementTagNameMap {
192
+ 'helix-headless-map': HelixHeadlessMap;
193
+ }
194
+ }
195
+ export {};
@@ -0,0 +1,181 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { customElement, FullscreenController, HelixElement, HelixMapPanEvent, HelixMapZoomEvent, hostAria, IdleController, inlineStep, } from '@fusion.dev/helix-core';
8
+ import { html, nothing } from 'lit';
9
+ import { property, state } from 'lit/decorators.js';
10
+ let HelixHeadlessMap = class HelixHeadlessMap extends HelixElement {
11
+ constructor() {
12
+ super(...arguments);
13
+ this.fullscreenLabel = 'Fill the screen';
14
+ this.idleDelay = 0;
15
+ this.label = '';
16
+ this.panLabel = 'Pan {way}';
17
+ this.panStep = 0.25;
18
+ this.zoomInLabel = 'Zoom in';
19
+ this.zoomOutLabel = 'Zoom out';
20
+ this.resting = false;
21
+ this.filled = false;
22
+ this.fullscreen = new FullscreenController(this, (full) => {
23
+ this.filled = full;
24
+ });
25
+ this.idle = new IdleController(this, () => this.idleDelay, (resting) => {
26
+ this.resting = resting;
27
+ });
28
+ this.handleKeydown = (event) => {
29
+ const along = inlineStep(this, event.key);
30
+ if (along === 1) {
31
+ event.preventDefault();
32
+ this.pan('end');
33
+ }
34
+ else if (along === -1) {
35
+ event.preventDefault();
36
+ this.pan('start');
37
+ }
38
+ else if (event.key === 'ArrowUp') {
39
+ event.preventDefault();
40
+ this.pan('up');
41
+ }
42
+ else if (event.key === 'ArrowDown') {
43
+ event.preventDefault();
44
+ this.pan('down');
45
+ }
46
+ else if (event.key === '+' || event.key === '=') {
47
+ event.preventDefault();
48
+ this.zoom(1);
49
+ }
50
+ else if (event.key === '-' || event.key === '_') {
51
+ event.preventDefault();
52
+ this.zoom(-1);
53
+ }
54
+ };
55
+ }
56
+ draws(group) {
57
+ return this.controls === undefined ? true : this.controls.split(/\s+/).includes(group);
58
+ }
59
+ toggleFullscreen() {
60
+ void this.fullscreen.toggle();
61
+ }
62
+ pan(to) {
63
+ this.dispatchEvent(new HelixMapPanEvent({ by: this.panStep, to }));
64
+ }
65
+ zoom(by) {
66
+ this.dispatchEvent(new HelixMapZoomEvent({ by }));
67
+ }
68
+ firstUpdated(changed) {
69
+ super.firstUpdated(changed);
70
+ this.idle.stir();
71
+ }
72
+ willUpdate(changed) {
73
+ super.willUpdate(changed);
74
+ hostAria(this.internals, { label: this.label });
75
+ this.toggleState('fullscreen', this.filled);
76
+ this.toggleState('idle', this.resting);
77
+ }
78
+ named(way) {
79
+ const spoken = way === 'start' ? 'left' : way === 'end' ? 'right' : way;
80
+ return this.panLabel.replace('{way}', spoken);
81
+ }
82
+ renderControls() {
83
+ const pan = this.draws('pan');
84
+ const zoom = this.draws('zoom');
85
+ const fullscreen = this.draws('fullscreen');
86
+ if (!pan && !zoom && !fullscreen) {
87
+ return nothing;
88
+ }
89
+ return html `<div part="controls" role="group" aria-label="Map controls">
90
+ ${pan
91
+ ? html `<button part="pan-up" aria-label=${this.named('up')} type="button" @click=${() => this.pan('up')}>
92
+ ↑
93
+ </button>
94
+ <button part="pan-start" aria-label=${this.named('start')} type="button" @click=${() => this.pan('start')}>
95
+ ←
96
+ </button>
97
+ <button part="pan-end" aria-label=${this.named('end')} type="button" @click=${() => this.pan('end')}>
98
+ →
99
+ </button>
100
+ <button part="pan-down" aria-label=${this.named('down')} type="button" @click=${() => this.pan('down')}>
101
+ ↓
102
+ </button>`
103
+ : nothing}
104
+ ${zoom
105
+ ? html `<button part="zoom-in" aria-label=${this.zoomInLabel} type="button" @click=${() => this.zoom(1)}>
106
+ +
107
+ </button>
108
+ <button part="zoom-out" aria-label=${this.zoomOutLabel} type="button" @click=${() => this.zoom(-1)}>
109
+ −
110
+ </button>`
111
+ : nothing}
112
+ ${fullscreen
113
+ ? html `<button
114
+ part="fullscreen"
115
+ aria-label=${this.fullscreenLabel}
116
+ aria-pressed=${this.filled ? 'true' : 'false'}
117
+ type="button"
118
+ @click=${this.toggleFullscreen}
119
+ >
120
+ ⤢
121
+ </button>`
122
+ : nothing}
123
+ </div>`;
124
+ }
125
+ render() {
126
+ return html `<div
127
+ part="region"
128
+ role="group"
129
+ aria-label=${this.label || 'Map'}
130
+ @focusin=${this.idle.stir}
131
+ @keydown=${this.handleKeydown}
132
+ @pointerleave=${this.idle.leave}
133
+ @pointermove=${this.idle.stir}
134
+ >
135
+ <slot name="header"></slot>
136
+ <div part="viewport">
137
+ <slot></slot>
138
+ </div>
139
+ ${this.renderControls()}
140
+ <slot name="footer"></slot>
141
+ <slot name="attribution"></slot>
142
+ </div>`;
143
+ }
144
+ };
145
+ __decorate([
146
+ property({ reflect: true })
147
+ ], HelixHeadlessMap.prototype, "controls", void 0);
148
+ __decorate([
149
+ property({ attribute: 'controls-placement', reflect: true })
150
+ ], HelixHeadlessMap.prototype, "controlsPlacement", void 0);
151
+ __decorate([
152
+ property({ attribute: 'fullscreen-label' })
153
+ ], HelixHeadlessMap.prototype, "fullscreenLabel", void 0);
154
+ __decorate([
155
+ property({ attribute: 'idle-delay', type: Number })
156
+ ], HelixHeadlessMap.prototype, "idleDelay", void 0);
157
+ __decorate([
158
+ property()
159
+ ], HelixHeadlessMap.prototype, "label", void 0);
160
+ __decorate([
161
+ property({ attribute: 'pan-label' })
162
+ ], HelixHeadlessMap.prototype, "panLabel", void 0);
163
+ __decorate([
164
+ property({ attribute: 'pan-step', type: Number })
165
+ ], HelixHeadlessMap.prototype, "panStep", void 0);
166
+ __decorate([
167
+ property({ attribute: 'zoom-in-label' })
168
+ ], HelixHeadlessMap.prototype, "zoomInLabel", void 0);
169
+ __decorate([
170
+ property({ attribute: 'zoom-out-label' })
171
+ ], HelixHeadlessMap.prototype, "zoomOutLabel", void 0);
172
+ __decorate([
173
+ state()
174
+ ], HelixHeadlessMap.prototype, "resting", void 0);
175
+ __decorate([
176
+ state()
177
+ ], HelixHeadlessMap.prototype, "filled", void 0);
178
+ HelixHeadlessMap = __decorate([
179
+ customElement('helix-headless-map')
180
+ ], HelixHeadlessMap);
181
+ export { HelixHeadlessMap };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@fusion.dev/helix-headless",
3
3
  "description": "Headless component tier. Structure, accessibility, state, and form participation. No styling.",
4
- "version": "0.101.0",
4
+ "version": "0.103.0",
5
5
  "license": "MIT",
6
6
  "author": "Ross Sheppard <ross.sheppard@fusion.dev>",
7
7
  "repository": {
@@ -46,13 +46,13 @@
46
46
  },
47
47
  "bugs": "https://github.com/project-fusion/fusion/issues",
48
48
  "dependencies": {
49
- "@fusion.dev/helix-core": "0.101.0",
50
- "@fusion.dev/helix-icons": "0.101.0",
49
+ "@fusion.dev/helix-core": "0.103.0",
50
+ "@fusion.dev/helix-icons": "0.103.0",
51
51
  "uqr": "^0.1.3"
52
52
  },
53
53
  "devDependencies": {
54
- "@fusion.dev/helix-cem": "0.101.0",
55
- "@fusion.dev/helix-testing": "0.101.0",
54
+ "@fusion.dev/helix-cem": "0.103.0",
55
+ "@fusion.dev/helix-testing": "0.103.0",
56
56
  "@fusion.dev/scripts": "0.0.0-dev",
57
57
  "@happy-dom/global-registrator": "^20.0.0",
58
58
  "@lit-labs/ssr": "^4.1.0",