@firstprateek/vastu 0.0.0-stage → 1.1.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/LICENSE +15 -0
- package/README.md +52 -2
- package/custom-elements.json +3737 -0
- package/dist/dev/all.d.ts +12 -0
- package/dist/dev/all.d.ts.map +1 -0
- package/dist/dev/all.js +13 -0
- package/dist/dev/all.js.map +1 -0
- package/dist/dev/bar-chart/bar-chart.d.ts +63 -0
- package/dist/dev/bar-chart/bar-chart.d.ts.map +1 -0
- package/dist/dev/bar-chart/bar-chart.js +316 -0
- package/dist/dev/bar-chart/bar-chart.js.map +1 -0
- package/dist/dev/bar-chart/index.d.ts +3 -0
- package/dist/dev/bar-chart/index.d.ts.map +1 -0
- package/dist/dev/bar-chart/index.js +5 -0
- package/dist/dev/bar-chart/index.js.map +1 -0
- package/dist/dev/button/button.d.ts +98 -0
- package/dist/dev/button/button.d.ts.map +1 -0
- package/dist/dev/button/button.js +292 -0
- package/dist/dev/button/button.js.map +1 -0
- package/dist/dev/button/index.d.ts +4 -0
- package/dist/dev/button/index.d.ts.map +1 -0
- package/dist/dev/button/index.js +5 -0
- package/dist/dev/button/index.js.map +1 -0
- package/dist/dev/checkbox/checkbox.d.ts +71 -0
- package/dist/dev/checkbox/checkbox.d.ts.map +1 -0
- package/dist/dev/checkbox/checkbox.js +232 -0
- package/dist/dev/checkbox/checkbox.js.map +1 -0
- package/dist/dev/checkbox/index.d.ts +3 -0
- package/dist/dev/checkbox/index.d.ts.map +1 -0
- package/dist/dev/checkbox/index.js +5 -0
- package/dist/dev/checkbox/index.js.map +1 -0
- package/dist/dev/core/cssom.d.ts +15 -0
- package/dist/dev/core/cssom.d.ts.map +1 -0
- package/dist/dev/core/cssom.js +30 -0
- package/dist/dev/core/cssom.js.map +1 -0
- package/dist/dev/core/define.d.ts +3 -0
- package/dist/dev/core/define.d.ts.map +1 -0
- package/dist/dev/core/define.js +6 -0
- package/dist/dev/core/define.js.map +1 -0
- package/dist/dev/core/dev-mode.d.ts +6 -0
- package/dist/dev/core/dev-mode.d.ts.map +1 -0
- package/dist/dev/core/dev-mode.js +6 -0
- package/dist/dev/core/dev-mode.js.map +1 -0
- package/dist/dev/core/focus-ring.d.ts +3 -0
- package/dist/dev/core/focus-ring.d.ts.map +1 -0
- package/dist/dev/core/focus-ring.js +14 -0
- package/dist/dev/core/focus-ring.js.map +1 -0
- package/dist/dev/core/form-control.d.ts +47 -0
- package/dist/dev/core/form-control.d.ts.map +1 -0
- package/dist/dev/core/form-control.js +75 -0
- package/dist/dev/core/form-control.js.map +1 -0
- package/dist/dev/core/warn.d.ts +12 -0
- package/dist/dev/core/warn.d.ts.map +1 -0
- package/dist/dev/core/warn.js +35 -0
- package/dist/dev/core/warn.js.map +1 -0
- package/dist/dev/dialog/dialog.d.ts +77 -0
- package/dist/dev/dialog/dialog.d.ts.map +1 -0
- package/dist/dev/dialog/dialog.js +253 -0
- package/dist/dev/dialog/dialog.js.map +1 -0
- package/dist/dev/dialog/index.d.ts +4 -0
- package/dist/dev/dialog/index.d.ts.map +1 -0
- package/dist/dev/dialog/index.js +5 -0
- package/dist/dev/dialog/index.js.map +1 -0
- package/dist/dev/menu/index.d.ts +3 -0
- package/dist/dev/menu/index.d.ts.map +1 -0
- package/dist/dev/menu/index.js +5 -0
- package/dist/dev/menu/index.js.map +1 -0
- package/dist/dev/menu/menu.d.ts +71 -0
- package/dist/dev/menu/menu.d.ts.map +1 -0
- package/dist/dev/menu/menu.js +330 -0
- package/dist/dev/menu/menu.js.map +1 -0
- package/dist/dev/navbar/index.d.ts +3 -0
- package/dist/dev/navbar/index.d.ts.map +1 -0
- package/dist/dev/navbar/index.js +5 -0
- package/dist/dev/navbar/index.js.map +1 -0
- package/dist/dev/navbar/navbar.d.ts +69 -0
- package/dist/dev/navbar/navbar.d.ts.map +1 -0
- package/dist/dev/navbar/navbar.js +353 -0
- package/dist/dev/navbar/navbar.js.map +1 -0
- package/dist/dev/poll/index.d.ts +3 -0
- package/dist/dev/poll/index.d.ts.map +1 -0
- package/dist/dev/poll/index.js +5 -0
- package/dist/dev/poll/index.js.map +1 -0
- package/dist/dev/poll/poll.d.ts +67 -0
- package/dist/dev/poll/poll.d.ts.map +1 -0
- package/dist/dev/poll/poll.js +301 -0
- package/dist/dev/poll/poll.js.map +1 -0
- package/dist/dev/switch/index.d.ts +3 -0
- package/dist/dev/switch/index.d.ts.map +1 -0
- package/dist/dev/switch/index.js +5 -0
- package/dist/dev/switch/index.js.map +1 -0
- package/dist/dev/switch/switch.d.ts +69 -0
- package/dist/dev/switch/switch.d.ts.map +1 -0
- package/dist/dev/switch/switch.js +213 -0
- package/dist/dev/switch/switch.js.map +1 -0
- package/dist/dev/tabs/index.d.ts +3 -0
- package/dist/dev/tabs/index.d.ts.map +1 -0
- package/dist/dev/tabs/index.js +5 -0
- package/dist/dev/tabs/index.js.map +1 -0
- package/dist/dev/tabs/tabs.d.ts +64 -0
- package/dist/dev/tabs/tabs.d.ts.map +1 -0
- package/dist/dev/tabs/tabs.js +212 -0
- package/dist/dev/tabs/tabs.js.map +1 -0
- package/dist/dev/text-field/index.d.ts +3 -0
- package/dist/dev/text-field/index.d.ts.map +1 -0
- package/dist/dev/text-field/index.js +5 -0
- package/dist/dev/text-field/index.js.map +1 -0
- package/dist/dev/text-field/text-field.d.ts +91 -0
- package/dist/dev/text-field/text-field.d.ts.map +1 -0
- package/dist/dev/text-field/text-field.js +267 -0
- package/dist/dev/text-field/text-field.js.map +1 -0
- package/dist/dev/toast/index.d.ts +4 -0
- package/dist/dev/toast/index.d.ts.map +1 -0
- package/dist/dev/toast/index.js +5 -0
- package/dist/dev/toast/index.js.map +1 -0
- package/dist/dev/toast/toast.d.ts +71 -0
- package/dist/dev/toast/toast.d.ts.map +1 -0
- package/dist/dev/toast/toast.js +258 -0
- package/dist/dev/toast/toast.js.map +1 -0
- package/dist/prod/all.js +13 -0
- package/dist/prod/bar-chart/bar-chart.js +316 -0
- package/dist/prod/bar-chart/index.js +5 -0
- package/dist/prod/button/button.js +292 -0
- package/dist/prod/button/index.js +5 -0
- package/dist/prod/checkbox/checkbox.js +232 -0
- package/dist/prod/checkbox/index.js +5 -0
- package/dist/prod/core/cssom.js +30 -0
- package/dist/prod/core/define.js +6 -0
- package/dist/prod/core/dev-mode.js +1 -0
- package/dist/prod/core/focus-ring.js +14 -0
- package/dist/prod/core/form-control.js +75 -0
- package/dist/prod/core/warn.js +2 -0
- package/dist/prod/dialog/dialog.js +253 -0
- package/dist/prod/dialog/index.js +5 -0
- package/dist/prod/menu/index.js +5 -0
- package/dist/prod/menu/menu.js +330 -0
- package/dist/prod/navbar/index.js +5 -0
- package/dist/prod/navbar/navbar.js +353 -0
- package/dist/prod/poll/index.js +5 -0
- package/dist/prod/poll/poll.js +301 -0
- package/dist/prod/switch/index.js +5 -0
- package/dist/prod/switch/switch.js +213 -0
- package/dist/prod/tabs/index.js +5 -0
- package/dist/prod/tabs/tabs.js +212 -0
- package/dist/prod/text-field/index.js +5 -0
- package/dist/prod/text-field/text-field.js +267 -0
- package/dist/prod/toast/index.js +5 -0
- package/dist/prod/toast/toast.js +258 -0
- package/package.json +110 -3
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
import { LitElement, css, html, nothing } from 'lit';
|
|
2
|
+
import { focusRing } from '../core/focus-ring.js';
|
|
3
|
+
import { checkTokensLoaded, devWarn } from '../core/warn.js';
|
|
4
|
+
/**
|
|
5
|
+
* A site's main navigation bar: a brand link and links to pages. On narrow screens the links fold
|
|
6
|
+
* behind a Menu button, following the WAI-ARIA disclosure navigation pattern.
|
|
7
|
+
*
|
|
8
|
+
* @tag va-navbar
|
|
9
|
+
* @summary Shows a site's brand and main links in a bar that folds behind a Menu button on narrow screens.
|
|
10
|
+
*
|
|
11
|
+
* @slot - The links, as `<a href="…">` elements. Mark the current page's link with `aria-current="page"`.
|
|
12
|
+
* @slot brand - The site's name or logo, as an `<a href="…">` to the home page.
|
|
13
|
+
*
|
|
14
|
+
* @cssstate collapsed - The links are folded behind the Menu button.
|
|
15
|
+
*
|
|
16
|
+
* @csspart bar - The bar, which is the `<nav>` element.
|
|
17
|
+
* @csspart toggle - The Menu button shown on narrow screens.
|
|
18
|
+
* @csspart links - The wrapper around the links. On narrow screens it is the panel that opens.
|
|
19
|
+
*
|
|
20
|
+
* @cssprop {<color>} --va-navbar-bg - Background colour of the bar and of the open panel.
|
|
21
|
+
* @cssprop {<color>} --va-navbar-border - Colour of the line under the bar.
|
|
22
|
+
* @cssprop {<length>} --va-navbar-size - Minimum height of the bar.
|
|
23
|
+
* @cssprop {<color>} --va-navbar-link-fg - Text colour of the links.
|
|
24
|
+
* @cssprop {<color>} --va-navbar-indicator-border - Colour of the line that marks the current page's link.
|
|
25
|
+
*
|
|
26
|
+
* @cssprop-applies --va-navbar-bg bar background-color
|
|
27
|
+
* @cssprop-applies --va-navbar-border bar border-bottom-color
|
|
28
|
+
* @cssprop-applies --va-navbar-size bar min-height
|
|
29
|
+
* @cssprop-applies --va-navbar-link-fg light(a:not([slot]):not([aria-current])) color
|
|
30
|
+
* @cssprop-applies --va-navbar-indicator-border light([aria-current="page"]) border-bottom-color
|
|
31
|
+
*
|
|
32
|
+
* @keyboard open: Escape | closes | Closes the open panel of links and returns focus to the Menu button.
|
|
33
|
+
*
|
|
34
|
+
* @a11y-role navigation
|
|
35
|
+
* @a11y-name-from accessible-label
|
|
36
|
+
* @a11y-name The `accessible-label` attribute, such as "Main" (not shown). Needed when a page has more than one navigation landmark.
|
|
37
|
+
* @a11y-note The bar is a `<nav>` landmark. The links keep their own names; mark the current page with `aria-current="page"`.
|
|
38
|
+
* @a11y-note Style the folded layout with `va-navbar:state(collapsed)`.
|
|
39
|
+
* @a11y-note On narrow screens the Menu button has a visible label, `aria-expanded` and `aria-controls`. Escape, a click outside or moving focus away closes the panel.
|
|
40
|
+
*
|
|
41
|
+
* @guidance-use For a site's or app's main navigation: a brand link and up to about seven links to pages.
|
|
42
|
+
* @guidance-avoid For actions that do something on the page, for switching views in one place, or for deep hierarchies of pages.
|
|
43
|
+
* @guidance-instead `va-menu` for actions; `va-tabs` for views in one place; nested lists in a sidebar for deep navigation.
|
|
44
|
+
*/
|
|
45
|
+
export class VaNavbar extends LitElement {
|
|
46
|
+
static { this.properties = {
|
|
47
|
+
open: { type: Boolean, reflect: true },
|
|
48
|
+
collapseBelow: { type: Number, attribute: 'collapse-below' },
|
|
49
|
+
toggleLabel: { attribute: 'toggle-label' },
|
|
50
|
+
accessibleLabel: { attribute: 'accessible-label' },
|
|
51
|
+
_collapsed: { state: true },
|
|
52
|
+
}; }
|
|
53
|
+
#internals;
|
|
54
|
+
#width = 0;
|
|
55
|
+
#resize = new ResizeObserver(([entry]) => {
|
|
56
|
+
this.#width = entry.contentRect.width;
|
|
57
|
+
this.#measure();
|
|
58
|
+
});
|
|
59
|
+
constructor() {
|
|
60
|
+
super();
|
|
61
|
+
this.open = false;
|
|
62
|
+
this.collapseBelow = 600;
|
|
63
|
+
this.toggleLabel = 'Menu';
|
|
64
|
+
this.accessibleLabel = '';
|
|
65
|
+
this._collapsed = false;
|
|
66
|
+
this.#internals = this.attachInternals();
|
|
67
|
+
}
|
|
68
|
+
connectedCallback() {
|
|
69
|
+
super.connectedCallback();
|
|
70
|
+
checkTokensLoaded(this);
|
|
71
|
+
this.#resize.observe(this);
|
|
72
|
+
// Moved while open: disconnectedCallback removed the document listeners, and open hasn't changed.
|
|
73
|
+
if (this.open)
|
|
74
|
+
this.#listen(true);
|
|
75
|
+
}
|
|
76
|
+
disconnectedCallback() {
|
|
77
|
+
super.disconnectedCallback();
|
|
78
|
+
this.#resize.disconnect();
|
|
79
|
+
this.#listen(false);
|
|
80
|
+
}
|
|
81
|
+
firstUpdated() {
|
|
82
|
+
// Measure before the first paint, so a phone never sees the wide layout flash.
|
|
83
|
+
this.#width = this.getBoundingClientRect().width;
|
|
84
|
+
this.#measure();
|
|
85
|
+
}
|
|
86
|
+
willUpdate(changed) {
|
|
87
|
+
if (changed.has('collapseBelow'))
|
|
88
|
+
this.#measure();
|
|
89
|
+
// Unfolding closes the panel, so it isn't open next time the navbar folds.
|
|
90
|
+
if (changed.has('_collapsed') && !this._collapsed && changed.get('_collapsed') === true)
|
|
91
|
+
this.open = false;
|
|
92
|
+
}
|
|
93
|
+
updated(changed) {
|
|
94
|
+
if (changed.has('open'))
|
|
95
|
+
this.#listen(this.open);
|
|
96
|
+
if (changed.has('_collapsed')) {
|
|
97
|
+
try {
|
|
98
|
+
if (this._collapsed)
|
|
99
|
+
this.#internals.states.add('collapsed');
|
|
100
|
+
else
|
|
101
|
+
this.#internals.states.delete('collapsed');
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
// Browsers without CustomStateSet: the state is only for authors' styling.
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
#measure() {
|
|
109
|
+
if (this.#width)
|
|
110
|
+
this._collapsed = this.#width < this.collapseBelow;
|
|
111
|
+
}
|
|
112
|
+
#listen(on) {
|
|
113
|
+
if (on) {
|
|
114
|
+
document.addEventListener('keydown', this.#onDocumentKeydown);
|
|
115
|
+
document.addEventListener('pointerdown', this.#onDocumentPointerdown);
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
document.removeEventListener('keydown', this.#onDocumentKeydown);
|
|
119
|
+
document.removeEventListener('pointerdown', this.#onDocumentPointerdown);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
get #toggle() {
|
|
123
|
+
return this.shadowRoot?.querySelector('[part="toggle"]') ?? null;
|
|
124
|
+
}
|
|
125
|
+
#onDocumentKeydown = (event) => {
|
|
126
|
+
if (event.key !== 'Escape' || !this.open)
|
|
127
|
+
return;
|
|
128
|
+
const hadFocus = this.matches(':focus-within');
|
|
129
|
+
this.open = false;
|
|
130
|
+
if (hadFocus && this._collapsed)
|
|
131
|
+
this.#toggle?.focus();
|
|
132
|
+
};
|
|
133
|
+
#onDocumentPointerdown = (event) => {
|
|
134
|
+
if (!event.composedPath().includes(this))
|
|
135
|
+
this.open = false;
|
|
136
|
+
};
|
|
137
|
+
#onFocusout(event) {
|
|
138
|
+
const next = event.relatedTarget;
|
|
139
|
+
if (this._collapsed && this.open && next && !this.contains(next) && !this.shadowRoot.contains(next))
|
|
140
|
+
this.open = false;
|
|
141
|
+
}
|
|
142
|
+
#onLinksClick(event) {
|
|
143
|
+
// Following a link closes the panel, so it isn't left open over the page that loads.
|
|
144
|
+
if (this._collapsed && event.composedPath().some((n) => n.localName === 'a'))
|
|
145
|
+
this.open = false;
|
|
146
|
+
}
|
|
147
|
+
#onSlotchange = () => {
|
|
148
|
+
for (const link of this.querySelectorAll(':scope > a:not([href])')) {
|
|
149
|
+
devWarn('va-navbar', `The link "${link.textContent?.trim()}" has no href, so it can't be reached with the keyboard.`, 'Give every link an href (e.g. <a href="/work">Work</a>).');
|
|
150
|
+
}
|
|
151
|
+
if ([...this.children].some((c) => !c.slot && c.localName !== 'a')) {
|
|
152
|
+
devWarn('va-navbar', 'Something other than a link is in the navbar.', 'Put only <a href="…"> elements in va-navbar; use va-menu or va-button for actions.');
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
render() {
|
|
156
|
+
const folded = this._collapsed;
|
|
157
|
+
return html `
|
|
158
|
+
<nav part="bar" class=${folded ? 'bar collapsed' : 'bar'} aria-label=${this.accessibleLabel || nothing} @focusout=${this.#onFocusout}>
|
|
159
|
+
<div class="brand"><slot name="brand"></slot></div>
|
|
160
|
+
<button
|
|
161
|
+
part="toggle"
|
|
162
|
+
class="toggle"
|
|
163
|
+
type="button"
|
|
164
|
+
?hidden=${!folded}
|
|
165
|
+
aria-expanded=${this.open ? 'true' : 'false'}
|
|
166
|
+
aria-controls="links"
|
|
167
|
+
@click=${() => (this.open = !this.open)}
|
|
168
|
+
>
|
|
169
|
+
<span class="icon" aria-hidden="true"><span></span><span></span><span></span></span>
|
|
170
|
+
${this.toggleLabel}
|
|
171
|
+
</button>
|
|
172
|
+
<div part="links" id="links" class=${this.open ? 'links open' : 'links'} @click=${this.#onLinksClick}>
|
|
173
|
+
<slot @slotchange=${this.#onSlotchange}></slot>
|
|
174
|
+
</div>
|
|
175
|
+
</nav>
|
|
176
|
+
`;
|
|
177
|
+
}
|
|
178
|
+
static { this.styles = [
|
|
179
|
+
focusRing,
|
|
180
|
+
css `
|
|
181
|
+
:host {
|
|
182
|
+
display: block;
|
|
183
|
+
box-sizing: border-box;
|
|
184
|
+
width: 100%;
|
|
185
|
+
position: relative;
|
|
186
|
+
z-index: 1;
|
|
187
|
+
font-family: var(--va-font-family-ui);
|
|
188
|
+
font-size: var(--va-font-size-md);
|
|
189
|
+
}
|
|
190
|
+
:host([hidden]) {
|
|
191
|
+
display: none;
|
|
192
|
+
}
|
|
193
|
+
.bar {
|
|
194
|
+
position: relative;
|
|
195
|
+
box-sizing: border-box;
|
|
196
|
+
display: flex;
|
|
197
|
+
align-items: center;
|
|
198
|
+
gap: var(--va-space-inline-lg);
|
|
199
|
+
min-height: var(--va-navbar-size, 3.5rem);
|
|
200
|
+
padding: 0 var(--va-space-inline-lg);
|
|
201
|
+
border-bottom: 1px solid var(--va-navbar-border, var(--va-color-border-subtle));
|
|
202
|
+
background-color: var(--va-navbar-bg, var(--va-color-surface-default));
|
|
203
|
+
color: var(--va-color-text-default);
|
|
204
|
+
}
|
|
205
|
+
.brand {
|
|
206
|
+
flex: none;
|
|
207
|
+
margin-inline-end: auto;
|
|
208
|
+
}
|
|
209
|
+
::slotted([slot='brand']) {
|
|
210
|
+
color: inherit;
|
|
211
|
+
font-size: var(--va-font-size-lg);
|
|
212
|
+
font-weight: var(--va-font-weight-bold);
|
|
213
|
+
text-decoration: none;
|
|
214
|
+
}
|
|
215
|
+
.links {
|
|
216
|
+
display: flex;
|
|
217
|
+
align-items: stretch;
|
|
218
|
+
align-self: stretch;
|
|
219
|
+
gap: var(--va-space-gap-sm);
|
|
220
|
+
}
|
|
221
|
+
slot:not([name])::slotted(a) {
|
|
222
|
+
display: flex;
|
|
223
|
+
align-items: center;
|
|
224
|
+
padding: 0 var(--va-space-inline-sm);
|
|
225
|
+
border-top: 2px solid transparent;
|
|
226
|
+
border-bottom: 2px solid transparent;
|
|
227
|
+
color: var(--va-navbar-link-fg, var(--va-color-text-muted));
|
|
228
|
+
font-weight: var(--va-font-weight-medium);
|
|
229
|
+
text-decoration: none;
|
|
230
|
+
}
|
|
231
|
+
slot:not([name])::slotted(a:hover) {
|
|
232
|
+
color: var(--va-color-text-default);
|
|
233
|
+
}
|
|
234
|
+
slot:not([name])::slotted([aria-current='page']) {
|
|
235
|
+
border-bottom-color: var(--va-navbar-indicator-border, var(--va-color-accent-default));
|
|
236
|
+
color: var(--va-color-text-default);
|
|
237
|
+
}
|
|
238
|
+
::slotted(a:focus-visible) {
|
|
239
|
+
outline: var(--va-size-focus-ring, 2px) solid var(--va-color-focus);
|
|
240
|
+
outline-offset: -2px;
|
|
241
|
+
border-radius: var(--va-radius-control);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/* Folded: brand and Menu button in the bar, the links in a panel under it. */
|
|
245
|
+
.toggle {
|
|
246
|
+
display: inline-flex;
|
|
247
|
+
align-items: center;
|
|
248
|
+
gap: var(--va-space-gap-md);
|
|
249
|
+
min-height: var(--va-size-control-md);
|
|
250
|
+
margin: 0 calc(-1 * var(--va-space-inline-sm));
|
|
251
|
+
padding: 0 var(--va-space-inline-sm);
|
|
252
|
+
border: none;
|
|
253
|
+
border-radius: var(--va-radius-control);
|
|
254
|
+
background: transparent;
|
|
255
|
+
color: inherit;
|
|
256
|
+
font: inherit;
|
|
257
|
+
font-weight: var(--va-font-weight-medium);
|
|
258
|
+
cursor: pointer;
|
|
259
|
+
}
|
|
260
|
+
.toggle[hidden] {
|
|
261
|
+
display: none;
|
|
262
|
+
}
|
|
263
|
+
.toggle:hover {
|
|
264
|
+
background: var(--va-color-surface-subtle);
|
|
265
|
+
}
|
|
266
|
+
.icon {
|
|
267
|
+
position: relative;
|
|
268
|
+
width: 1.125rem;
|
|
269
|
+
height: 0.875rem;
|
|
270
|
+
}
|
|
271
|
+
.icon span {
|
|
272
|
+
position: absolute;
|
|
273
|
+
left: 0;
|
|
274
|
+
width: 100%;
|
|
275
|
+
height: 2px;
|
|
276
|
+
border-radius: 1px;
|
|
277
|
+
background: currentColor;
|
|
278
|
+
transition:
|
|
279
|
+
transform var(--va-motion-duration-fast) ease-out,
|
|
280
|
+
opacity var(--va-motion-duration-fast) ease-out;
|
|
281
|
+
}
|
|
282
|
+
.icon span:nth-child(1) {
|
|
283
|
+
top: 0;
|
|
284
|
+
}
|
|
285
|
+
.icon span:nth-child(2) {
|
|
286
|
+
top: calc(50% - 1px);
|
|
287
|
+
}
|
|
288
|
+
.icon span:nth-child(3) {
|
|
289
|
+
bottom: 0;
|
|
290
|
+
}
|
|
291
|
+
[aria-expanded='true'] .icon span:nth-child(1) {
|
|
292
|
+
transform: translateY(0.375rem) rotate(45deg);
|
|
293
|
+
}
|
|
294
|
+
[aria-expanded='true'] .icon span:nth-child(2) {
|
|
295
|
+
opacity: 0;
|
|
296
|
+
}
|
|
297
|
+
[aria-expanded='true'] .icon span:nth-child(3) {
|
|
298
|
+
transform: translateY(-0.375rem) rotate(-45deg);
|
|
299
|
+
}
|
|
300
|
+
.collapsed .links {
|
|
301
|
+
position: absolute;
|
|
302
|
+
top: 100%;
|
|
303
|
+
left: 0;
|
|
304
|
+
right: 0;
|
|
305
|
+
display: none;
|
|
306
|
+
flex-direction: column;
|
|
307
|
+
gap: 0;
|
|
308
|
+
padding: var(--va-space-gap-sm) 0;
|
|
309
|
+
border-bottom: 1px solid var(--va-navbar-border, var(--va-color-border-subtle));
|
|
310
|
+
background-color: var(--va-navbar-bg, var(--va-color-surface-default));
|
|
311
|
+
box-shadow: 0 12px 24px rgb(0 0 0 / 0.12);
|
|
312
|
+
}
|
|
313
|
+
.collapsed .links.open {
|
|
314
|
+
display: flex;
|
|
315
|
+
animation: va-navbar-open var(--va-motion-duration-fast) ease-out;
|
|
316
|
+
}
|
|
317
|
+
.collapsed slot:not([name])::slotted(a) {
|
|
318
|
+
min-height: var(--va-size-control-lg);
|
|
319
|
+
padding: 0 var(--va-space-inline-lg);
|
|
320
|
+
border-top: none;
|
|
321
|
+
border-bottom: none;
|
|
322
|
+
border-inline-start: 3px solid transparent;
|
|
323
|
+
}
|
|
324
|
+
.collapsed slot:not([name])::slotted([aria-current='page']) {
|
|
325
|
+
border-inline-start-color: var(--va-navbar-indicator-border, var(--va-color-accent-default));
|
|
326
|
+
}
|
|
327
|
+
@keyframes va-navbar-open {
|
|
328
|
+
from {
|
|
329
|
+
opacity: 0;
|
|
330
|
+
transform: translateY(-4px);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
@media (prefers-reduced-motion: reduce) {
|
|
334
|
+
.icon span {
|
|
335
|
+
transition: none;
|
|
336
|
+
}
|
|
337
|
+
.collapsed .links.open {
|
|
338
|
+
animation: none;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
@media (forced-colors: active) {
|
|
342
|
+
.bar,
|
|
343
|
+
.collapsed .links {
|
|
344
|
+
border-bottom-color: CanvasText;
|
|
345
|
+
}
|
|
346
|
+
slot:not([name])::slotted([aria-current='page']) {
|
|
347
|
+
border-color: Highlight;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
`,
|
|
351
|
+
]; }
|
|
352
|
+
}
|
|
353
|
+
//# sourceMappingURL=navbar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"navbar.js","sourceRoot":"","sources":["../../../src/navbar/navbar.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,EAAkD,MAAM,KAAK,CAAC;AACrG,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE7D;;;;;;;;;;;;;;;;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,IAAI,CAAC,IAAI,CAAC;;;YAGrC,IAAI,CAAC,WAAW;;6CAEiB,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,OAAO,WAAW,IAAI,CAAC,aAAa;8BAC9E,IAAI,CAAC,aAAa;;;KAG3C,CAAC;IACJ,CAAC;aAEe,WAAM,GAAG;QACvB,SAAS;QACT,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KA0KF;KACF,CAAC","sourcesContent":["import { LitElement, css, html, nothing, type PropertyDeclarations, type PropertyValues } from 'lit';\nimport { focusRing } from '../core/focus-ring.js';\nimport { checkTokensLoaded, devWarn } from '../core/warn.js';\n\n/**\n * A site's main navigation bar: a brand link and links to pages. On narrow screens the links fold\n * behind a Menu button, following the WAI-ARIA disclosure navigation pattern.\n *\n * @tag va-navbar\n * @summary Shows a site's brand and main links in a bar that folds behind a Menu button on narrow screens.\n *\n * @slot - The links, as `<a href=\"…\">` elements. Mark the current page's link with `aria-current=\"page\"`.\n * @slot brand - The site's name or logo, as an `<a href=\"…\">` to the home page.\n *\n * @cssstate collapsed - The links are folded behind the Menu button.\n *\n * @csspart bar - The bar, which is the `<nav>` element.\n * @csspart toggle - The Menu button shown on narrow screens.\n * @csspart links - The wrapper around the links. On narrow screens it is the panel that opens.\n *\n * @cssprop {<color>} --va-navbar-bg - Background colour of the bar and of the open panel.\n * @cssprop {<color>} --va-navbar-border - Colour of the line under the bar.\n * @cssprop {<length>} --va-navbar-size - Minimum height of the bar.\n * @cssprop {<color>} --va-navbar-link-fg - Text colour of the links.\n * @cssprop {<color>} --va-navbar-indicator-border - Colour of the line that marks the current page's link.\n *\n * @cssprop-applies --va-navbar-bg bar background-color\n * @cssprop-applies --va-navbar-border bar border-bottom-color\n * @cssprop-applies --va-navbar-size bar min-height\n * @cssprop-applies --va-navbar-link-fg light(a:not([slot]):not([aria-current])) color\n * @cssprop-applies --va-navbar-indicator-border light([aria-current=\"page\"]) border-bottom-color\n *\n * @keyboard open: Escape | closes | Closes the open panel of links and returns focus to the Menu button.\n *\n * @a11y-role navigation\n * @a11y-name-from accessible-label\n * @a11y-name The `accessible-label` attribute, such as \"Main\" (not shown). Needed when a page has more than one navigation landmark.\n * @a11y-note The bar is a `<nav>` landmark. The links keep their own names; mark the current page with `aria-current=\"page\"`.\n * @a11y-note Style the folded layout with `va-navbar:state(collapsed)`.\n * @a11y-note On narrow screens the Menu button has a visible label, `aria-expanded` and `aria-controls`. Escape, a click outside or moving focus away closes the panel.\n *\n * @guidance-use For a site's or app's main navigation: a brand link and up to about seven links to pages.\n * @guidance-avoid For actions that do something on the page, for switching views in one place, or for deep hierarchies of pages.\n * @guidance-instead `va-menu` for actions; `va-tabs` for views in one place; nested lists in a sidebar for deep navigation.\n */\nexport class VaNavbar extends LitElement {\n static override properties: PropertyDeclarations = {\n open: { type: Boolean, reflect: true },\n collapseBelow: { type: Number, attribute: 'collapse-below' },\n toggleLabel: { attribute: 'toggle-label' },\n accessibleLabel: { attribute: 'accessible-label' },\n _collapsed: { state: true },\n };\n\n /** Whether the panel of links is open. It only shows while the navbar is folded. */\n declare open: boolean;\n /** Width in pixels below which the links fold behind the Menu button. It is the navbar's own width, not the window's. */\n declare collapseBelow: number;\n /** Visible text of the Menu button. */\n declare toggleLabel: string;\n /** Accessible name of the navigation landmark. */\n declare accessibleLabel: string;\n\n declare private _collapsed: boolean;\n\n #internals: ElementInternals;\n #width = 0;\n #resize = new ResizeObserver(([entry]) => {\n this.#width = entry.contentRect.width;\n this.#measure();\n });\n\n constructor() {\n super();\n this.open = false;\n this.collapseBelow = 600;\n this.toggleLabel = 'Menu';\n this.accessibleLabel = '';\n this._collapsed = false;\n this.#internals = this.attachInternals();\n }\n\n override connectedCallback(): void {\n super.connectedCallback();\n checkTokensLoaded(this);\n this.#resize.observe(this);\n // Moved while open: disconnectedCallback removed the document listeners, and open hasn't changed.\n if (this.open) this.#listen(true);\n }\n\n override disconnectedCallback(): void {\n super.disconnectedCallback();\n this.#resize.disconnect();\n this.#listen(false);\n }\n\n override firstUpdated(): void {\n // Measure before the first paint, so a phone never sees the wide layout flash.\n this.#width = this.getBoundingClientRect().width;\n this.#measure();\n }\n\n override willUpdate(changed: PropertyValues): void {\n if (changed.has('collapseBelow')) this.#measure();\n // Unfolding closes the panel, so it isn't open next time the navbar folds.\n if (changed.has('_collapsed') && !this._collapsed && changed.get('_collapsed') === true) this.open = false;\n }\n\n override updated(changed: PropertyValues): void {\n if (changed.has('open')) this.#listen(this.open);\n if (changed.has('_collapsed')) {\n try {\n if (this._collapsed) this.#internals.states.add('collapsed');\n else this.#internals.states.delete('collapsed');\n } catch {\n // Browsers without CustomStateSet: the state is only for authors' styling.\n }\n }\n }\n\n #measure(): void {\n if (this.#width) this._collapsed = this.#width < this.collapseBelow;\n }\n\n #listen(on: boolean): void {\n if (on) {\n document.addEventListener('keydown', this.#onDocumentKeydown);\n document.addEventListener('pointerdown', this.#onDocumentPointerdown);\n } else {\n document.removeEventListener('keydown', this.#onDocumentKeydown);\n document.removeEventListener('pointerdown', this.#onDocumentPointerdown);\n }\n }\n\n get #toggle(): HTMLButtonElement | null {\n return this.shadowRoot?.querySelector('[part=\"toggle\"]') ?? null;\n }\n\n #onDocumentKeydown = (event: KeyboardEvent): void => {\n if (event.key !== 'Escape' || !this.open) return;\n const hadFocus = this.matches(':focus-within');\n this.open = false;\n if (hadFocus && this._collapsed) this.#toggle?.focus();\n };\n\n #onDocumentPointerdown = (event: PointerEvent): void => {\n if (!event.composedPath().includes(this)) this.open = false;\n };\n\n #onFocusout(event: FocusEvent): void {\n const next = event.relatedTarget as Node | null;\n if (this._collapsed && this.open && next && !this.contains(next) && !this.shadowRoot!.contains(next)) this.open = false;\n }\n\n #onLinksClick(event: MouseEvent): void {\n // Following a link closes the panel, so it isn't left open over the page that loads.\n if (this._collapsed && event.composedPath().some((n) => (n as Element).localName === 'a')) this.open = false;\n }\n\n #onSlotchange = (): void => {\n for (const link of this.querySelectorAll(':scope > a:not([href])')) {\n devWarn('va-navbar', `The link \"${link.textContent?.trim()}\" has no href, so it can't be reached with the keyboard.`, 'Give every link an href (e.g. <a href=\"/work\">Work</a>).');\n }\n if ([...this.children].some((c) => !c.slot && c.localName !== 'a')) {\n devWarn('va-navbar', 'Something other than a link is in the navbar.', 'Put only <a href=\"…\"> elements in va-navbar; use va-menu or va-button for actions.');\n }\n };\n\n override render() {\n const folded = this._collapsed;\n return html`\n <nav part=\"bar\" class=${folded ? 'bar collapsed' : 'bar'} aria-label=${this.accessibleLabel || nothing} @focusout=${this.#onFocusout}>\n <div class=\"brand\"><slot name=\"brand\"></slot></div>\n <button\n part=\"toggle\"\n class=\"toggle\"\n type=\"button\"\n ?hidden=${!folded}\n aria-expanded=${this.open ? 'true' : 'false'}\n aria-controls=\"links\"\n @click=${() => (this.open = !this.open)}\n >\n <span class=\"icon\" aria-hidden=\"true\"><span></span><span></span><span></span></span>\n ${this.toggleLabel}\n </button>\n <div part=\"links\" id=\"links\" class=${this.open ? 'links open' : 'links'} @click=${this.#onLinksClick}>\n <slot @slotchange=${this.#onSlotchange}></slot>\n </div>\n </nav>\n `;\n }\n\n static override styles = [\n focusRing,\n css`\n :host {\n display: block;\n box-sizing: border-box;\n width: 100%;\n position: relative;\n z-index: 1;\n font-family: var(--va-font-family-ui);\n font-size: var(--va-font-size-md);\n }\n :host([hidden]) {\n display: none;\n }\n .bar {\n position: relative;\n box-sizing: border-box;\n display: flex;\n align-items: center;\n gap: var(--va-space-inline-lg);\n min-height: var(--va-navbar-size, 3.5rem);\n padding: 0 var(--va-space-inline-lg);\n border-bottom: 1px solid var(--va-navbar-border, var(--va-color-border-subtle));\n background-color: var(--va-navbar-bg, var(--va-color-surface-default));\n color: var(--va-color-text-default);\n }\n .brand {\n flex: none;\n margin-inline-end: auto;\n }\n ::slotted([slot='brand']) {\n color: inherit;\n font-size: var(--va-font-size-lg);\n font-weight: var(--va-font-weight-bold);\n text-decoration: none;\n }\n .links {\n display: flex;\n align-items: stretch;\n align-self: stretch;\n gap: var(--va-space-gap-sm);\n }\n slot:not([name])::slotted(a) {\n display: flex;\n align-items: center;\n padding: 0 var(--va-space-inline-sm);\n border-top: 2px solid transparent;\n border-bottom: 2px solid transparent;\n color: var(--va-navbar-link-fg, var(--va-color-text-muted));\n font-weight: var(--va-font-weight-medium);\n text-decoration: none;\n }\n slot:not([name])::slotted(a:hover) {\n color: var(--va-color-text-default);\n }\n slot:not([name])::slotted([aria-current='page']) {\n border-bottom-color: var(--va-navbar-indicator-border, var(--va-color-accent-default));\n color: var(--va-color-text-default);\n }\n ::slotted(a:focus-visible) {\n outline: var(--va-size-focus-ring, 2px) solid var(--va-color-focus);\n outline-offset: -2px;\n border-radius: var(--va-radius-control);\n }\n\n /* Folded: brand and Menu button in the bar, the links in a panel under it. */\n .toggle {\n display: inline-flex;\n align-items: center;\n gap: var(--va-space-gap-md);\n min-height: var(--va-size-control-md);\n margin: 0 calc(-1 * var(--va-space-inline-sm));\n padding: 0 var(--va-space-inline-sm);\n border: none;\n border-radius: var(--va-radius-control);\n background: transparent;\n color: inherit;\n font: inherit;\n font-weight: var(--va-font-weight-medium);\n cursor: pointer;\n }\n .toggle[hidden] {\n display: none;\n }\n .toggle:hover {\n background: var(--va-color-surface-subtle);\n }\n .icon {\n position: relative;\n width: 1.125rem;\n height: 0.875rem;\n }\n .icon span {\n position: absolute;\n left: 0;\n width: 100%;\n height: 2px;\n border-radius: 1px;\n background: currentColor;\n transition:\n transform var(--va-motion-duration-fast) ease-out,\n opacity var(--va-motion-duration-fast) ease-out;\n }\n .icon span:nth-child(1) {\n top: 0;\n }\n .icon span:nth-child(2) {\n top: calc(50% - 1px);\n }\n .icon span:nth-child(3) {\n bottom: 0;\n }\n [aria-expanded='true'] .icon span:nth-child(1) {\n transform: translateY(0.375rem) rotate(45deg);\n }\n [aria-expanded='true'] .icon span:nth-child(2) {\n opacity: 0;\n }\n [aria-expanded='true'] .icon span:nth-child(3) {\n transform: translateY(-0.375rem) rotate(-45deg);\n }\n .collapsed .links {\n position: absolute;\n top: 100%;\n left: 0;\n right: 0;\n display: none;\n flex-direction: column;\n gap: 0;\n padding: var(--va-space-gap-sm) 0;\n border-bottom: 1px solid var(--va-navbar-border, var(--va-color-border-subtle));\n background-color: var(--va-navbar-bg, var(--va-color-surface-default));\n box-shadow: 0 12px 24px rgb(0 0 0 / 0.12);\n }\n .collapsed .links.open {\n display: flex;\n animation: va-navbar-open var(--va-motion-duration-fast) ease-out;\n }\n .collapsed slot:not([name])::slotted(a) {\n min-height: var(--va-size-control-lg);\n padding: 0 var(--va-space-inline-lg);\n border-top: none;\n border-bottom: none;\n border-inline-start: 3px solid transparent;\n }\n .collapsed slot:not([name])::slotted([aria-current='page']) {\n border-inline-start-color: var(--va-navbar-indicator-border, var(--va-color-accent-default));\n }\n @keyframes va-navbar-open {\n from {\n opacity: 0;\n transform: translateY(-4px);\n }\n }\n @media (prefers-reduced-motion: reduce) {\n .icon span {\n transition: none;\n }\n .collapsed .links.open {\n animation: none;\n }\n }\n @media (forced-colors: active) {\n .bar,\n .collapsed .links {\n border-bottom-color: CanvasText;\n }\n slot:not([name])::slotted([aria-current='page']) {\n border-color: Highlight;\n }\n }\n `,\n ];\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'va-navbar': VaNavbar;\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/poll/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEnC,OAAO,EAAE,MAAM,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/poll/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEnC,OAAO,EAAE,MAAM,EAAE,CAAC;AAElB,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC","sourcesContent":["import { define } from '../core/define.js';\nimport { VaPoll } from './poll.js';\n\nexport { VaPoll };\n\ndefine('va-poll', VaPoll);\n"]}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { LitElement, type PropertyDeclarations, type PropertyValues } from 'lit';
|
|
2
|
+
/**
|
|
3
|
+
* A one-question poll. The user votes with one click, and the poll shows the results.
|
|
4
|
+
*
|
|
5
|
+
* @tag va-poll
|
|
6
|
+
* @summary A poll: asks one question with a few answers. Visitors vote with one click and see everyone's results.
|
|
7
|
+
*
|
|
8
|
+
* @slot - The answers, as `<button value="…" data-votes="N">` elements. `data-votes` is the number of votes so far.
|
|
9
|
+
* @slot help-text - Optional text under the poll, such as when it closes. Overrides the `help-text` attribute.
|
|
10
|
+
*
|
|
11
|
+
* @csspart label - The question.
|
|
12
|
+
* @csspart option - The row around each answer.
|
|
13
|
+
* @csspart bar - The bar behind each answer that shows its share of the votes.
|
|
14
|
+
* @csspart result - The share of the votes, shown after voting.
|
|
15
|
+
* @csspart help-text - The help text and the vote count.
|
|
16
|
+
*
|
|
17
|
+
* @cssprop {<color>} --va-poll-border - Border colour of each answer's row.
|
|
18
|
+
* @cssprop {<length>} --va-poll-radius - Corner radius of each answer's row.
|
|
19
|
+
* @cssprop {<color>} --va-poll-bar-bg - Colour of the result bars.
|
|
20
|
+
*
|
|
21
|
+
* @cssprop-applies --va-poll-border option border-top-color
|
|
22
|
+
* @cssprop-applies --va-poll-radius option border-top-left-radius
|
|
23
|
+
* @cssprop-applies --va-poll-bar-bg bar background-color
|
|
24
|
+
*
|
|
25
|
+
* @keyboard-items button
|
|
26
|
+
* @keyboard items: Enter | activates | Votes for the focused answer.
|
|
27
|
+
* @keyboard items: Space | activates | Votes for the focused answer.
|
|
28
|
+
*
|
|
29
|
+
* @a11y-role group
|
|
30
|
+
* @a11y-name-from label
|
|
31
|
+
* @a11y-name The `label`, which is the question shown above the answers.
|
|
32
|
+
* @a11y-note After a vote the answers stay focusable but get `aria-disabled="true"` and an `aria-description` with their share of the votes. A polite live region announces that the vote was counted.
|
|
33
|
+
*
|
|
34
|
+
* @guidance-use For a quick, one-click opinion poll on a page, with two to six answers.
|
|
35
|
+
* @guidance-avoid For choices that are submitted with a form, for surveys with several questions, or where users need to review their answer before sending it.
|
|
36
|
+
* @guidance-instead A radio group in a form, with a submit `va-button`.
|
|
37
|
+
*
|
|
38
|
+
* @fires {CustomEvent<{ value: string, item: HTMLElement }>} va-select - When the user votes. `event.detail.value` is the answer's `value`, or its text when it has none; `event.detail.item` is the answer. Send the vote to your server here.
|
|
39
|
+
* @event-trigger va-select | click-item 2
|
|
40
|
+
*/
|
|
41
|
+
export declare class VaPoll extends LitElement {
|
|
42
|
+
#private;
|
|
43
|
+
static shadowRootOptions: ShadowRootInit;
|
|
44
|
+
static properties: PropertyDeclarations;
|
|
45
|
+
/** The question, shown above the answers. */
|
|
46
|
+
label: string;
|
|
47
|
+
/** The value of the answer the user voted for, or an empty string before a vote. Setting it shows the results with that answer marked, for a user who has already voted. */
|
|
48
|
+
value: string;
|
|
49
|
+
/** Shows the results without a vote, such as for a closed poll. */
|
|
50
|
+
showResults: boolean;
|
|
51
|
+
/** Text under the poll, such as when it closes. */
|
|
52
|
+
helpText: string;
|
|
53
|
+
private _revision;
|
|
54
|
+
constructor();
|
|
55
|
+
connectedCallback(): void;
|
|
56
|
+
disconnectedCallback(): void;
|
|
57
|
+
firstUpdated(): void;
|
|
58
|
+
updated(changed: PropertyValues): void;
|
|
59
|
+
render(): import("lit").TemplateResult<1>;
|
|
60
|
+
static styles: import("lit").CSSResult[];
|
|
61
|
+
}
|
|
62
|
+
declare global {
|
|
63
|
+
interface HTMLElementTagNameMap {
|
|
64
|
+
'va-poll': VaPoll;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=poll.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"poll.d.ts","sourceRoot":"","sources":["../../../src/poll/poll.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAa,KAAK,oBAAoB,EAAE,KAAK,cAAc,EAAE,MAAM,KAAK,CAAC;AAK5F;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,qBAAa,MAAO,SAAQ,UAAU;;IACpC,OAAgB,iBAAiB,EAAE,cAAc,CAAiE;IAElH,OAAgB,UAAU,EAAE,oBAAoB,CAM9C;IAEF,6CAA6C;IACrC,KAAK,EAAE,MAAM,CAAC;IACtB,4KAA4K;IACpK,KAAK,EAAE,MAAM,CAAC;IACtB,mEAAmE;IAC3D,WAAW,EAAE,OAAO,CAAC;IAC7B,mDAAmD;IAC3C,QAAQ,EAAE,MAAM,CAAC;IAEzB,QAAgB,SAAS,CAAS;;IAczB,iBAAiB,IAAI,IAAI;IAQzB,oBAAoB,IAAI,IAAI;IAsB5B,YAAY,IAAI,IAAI;IAIpB,OAAO,CAAC,OAAO,EAAE,cAAc,GAAG,IAAI;IA0CtC,MAAM;IAiCf,OAAgB,MAAM,4BAoIpB;CACH;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,SAAS,EAAE,MAAM,CAAC;KACnB;CACF"}
|