@spectrum-web-components/action-button 0.8.0 → 0.8.1

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.
Files changed (36) hide show
  1. package/package.json +6 -6
  2. package/sp-action-button.d.ts +6 -0
  3. package/sp-action-button.js +14 -0
  4. package/sp-action-button.js.map +1 -0
  5. package/src/ActionButton.d.ts +63 -0
  6. package/src/ActionButton.js +202 -0
  7. package/src/ActionButton.js.map +1 -0
  8. package/src/action-button.css.d.ts +2 -0
  9. package/src/action-button.css.js +691 -0
  10. package/src/action-button.css.js.map +1 -0
  11. package/src/index.d.ts +1 -0
  12. package/src/index.js +13 -0
  13. package/src/index.js.map +1 -0
  14. package/src/spectrum-action-button.css.d.ts +2 -0
  15. package/src/spectrum-action-button.css.js +655 -0
  16. package/src/spectrum-action-button.css.js.map +1 -0
  17. package/stories/action-button-black-quiet.stories.js +34 -0
  18. package/stories/action-button-black-quiet.stories.js.map +1 -0
  19. package/stories/action-button-black.stories.js +29 -0
  20. package/stories/action-button-black.stories.js.map +1 -0
  21. package/stories/action-button-emphasized-quiet.stories.js +32 -0
  22. package/stories/action-button-emphasized-quiet.stories.js.map +1 -0
  23. package/stories/action-button-emphasized.stories.js +27 -0
  24. package/stories/action-button-emphasized.stories.js.map +1 -0
  25. package/stories/action-button-quiet.stories.js +27 -0
  26. package/stories/action-button-quiet.stories.js.map +1 -0
  27. package/stories/action-button-standard.stories.js +22 -0
  28. package/stories/action-button-standard.stories.js.map +1 -0
  29. package/stories/action-button-white-quiet.stories.js +34 -0
  30. package/stories/action-button-white-quiet.stories.js.map +1 -0
  31. package/stories/action-button-white.stories.js +29 -0
  32. package/stories/action-button-white.stories.js.map +1 -0
  33. package/stories/action-button.stories.js +60 -0
  34. package/stories/action-button.stories.js.map +1 -0
  35. package/stories/index.js +71 -0
  36. package/stories/index.js.map +1 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spectrum-web-components/action-button",
3
- "version": "0.8.0",
3
+ "version": "0.8.1",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -44,10 +44,10 @@
44
44
  "lit-html"
45
45
  ],
46
46
  "dependencies": {
47
- "@spectrum-web-components/base": "^0.5.3",
48
- "@spectrum-web-components/button": "^0.17.0",
49
- "@spectrum-web-components/icon": "^0.11.4",
50
- "@spectrum-web-components/icons-ui": "^0.8.4",
47
+ "@spectrum-web-components/base": "^0.5.4",
48
+ "@spectrum-web-components/button": "^0.17.1",
49
+ "@spectrum-web-components/icon": "^0.11.5",
50
+ "@spectrum-web-components/icons-ui": "^0.8.5",
51
51
  "tslib": "^2.0.0"
52
52
  },
53
53
  "devDependencies": {
@@ -58,5 +58,5 @@
58
58
  "sideEffects": [
59
59
  "./sp-*.js"
60
60
  ],
61
- "gitHead": "57aba8030b6af96af4015a0aa830e342a17dc219"
61
+ "gitHead": "caf12727e7f91dcf961e1fadacc727eea9ece27b"
62
62
  }
@@ -0,0 +1,6 @@
1
+ import { ActionButton } from './src/ActionButton.js';
2
+ declare global {
3
+ interface HTMLElementTagNameMap {
4
+ 'sp-action-button': ActionButton;
5
+ }
6
+ }
@@ -0,0 +1,14 @@
1
+ /*
2
+ Copyright 2020 Adobe. All rights reserved.
3
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License. You may obtain a copy
5
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ Unless required by applicable law or agreed to in writing, software distributed under
8
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ OF ANY KIND, either express or implied. See the License for the specific language
10
+ governing permissions and limitations under the License.
11
+ */
12
+ import { ActionButton } from './src/ActionButton.js';
13
+ customElements.define('sp-action-button', ActionButton);
14
+ //# sourceMappingURL=sp-action-button.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sp-action-button.js","sourceRoot":"","sources":["sp-action-button.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AAEF,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAErD,cAAc,CAAC,MAAM,CAAC,kBAAkB,EAAE,YAAY,CAAC,CAAC","sourcesContent":["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport { ActionButton } from './src/ActionButton.js';\n\ncustomElements.define('sp-action-button', ActionButton);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'sp-action-button': ActionButton;\n }\n}\n"]}
@@ -0,0 +1,63 @@
1
+ import { CSSResultArray, PropertyValues, TemplateResult } from '@spectrum-web-components/base';
2
+ import { ButtonBase } from '@spectrum-web-components/button';
3
+ import '@spectrum-web-components/icons-ui/icons/sp-icon-corner-triangle300.js';
4
+ export declare type LongpressEvent = {
5
+ source: 'pointer' | 'keyboard';
6
+ };
7
+ declare const ActionButton_base: typeof ButtonBase & {
8
+ new (...args: any[]): import("@spectrum-web-components/base").SizedElementInterface;
9
+ prototype: import("@spectrum-web-components/base").SizedElementInterface;
10
+ };
11
+ /**
12
+ * @element sp-action-button
13
+ *
14
+ * @slot - text label of the Action Button
15
+ * @slot icon - The icon to use for Action Button
16
+ * @fires change - Announces a change in the `selected` property of an action button
17
+ * @fires longpress - Synthesizes a "longpress" interaction that signifies a
18
+ * `pointerdown` event that is >=300ms or a keyboard event wher code is `Space` or code is `ArrowDown`
19
+ * while `altKey===true`.
20
+ */
21
+ export declare class ActionButton extends ActionButton_base {
22
+ static get styles(): CSSResultArray;
23
+ emphasized: boolean;
24
+ holdAffordance: boolean;
25
+ quiet: boolean;
26
+ role: string;
27
+ /**
28
+ * Whether an Action Button with `role='button'`
29
+ * should also be `aria-pressed='true'`
30
+ */
31
+ selected: boolean;
32
+ /**
33
+ * Whether to automatically manage the `selected`
34
+ * attribute on interaction and whether `aria-pressed="false"`
35
+ * should be used when `selected === false`
36
+ */
37
+ toggles: boolean;
38
+ variant?: 'white' | 'black';
39
+ get value(): string;
40
+ set value(value: string);
41
+ private _value;
42
+ /**
43
+ * @private
44
+ */
45
+ get itemText(): string;
46
+ constructor();
47
+ private onClick;
48
+ private onPointerdown;
49
+ private onPointerup;
50
+ /**
51
+ * @private
52
+ */
53
+ protected handleKeydown(event: KeyboardEvent): void;
54
+ protected handleKeyup(event: KeyboardEvent): void;
55
+ protected get buttonContent(): TemplateResult[];
56
+ protected updated(changes: PropertyValues): void;
57
+ }
58
+ declare global {
59
+ interface GlobalEventHandlersEventMap {
60
+ longpress: CustomEvent<LongpressEvent>;
61
+ }
62
+ }
63
+ export {};
@@ -0,0 +1,202 @@
1
+ /*
2
+ Copyright 2020 Adobe. All rights reserved.
3
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License. You may obtain a copy
5
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ Unless required by applicable law or agreed to in writing, software distributed under
8
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ OF ANY KIND, either express or implied. See the License for the specific language
10
+ governing permissions and limitations under the License.
11
+ */
12
+ import { __decorate } from "tslib";
13
+ import { html, SizedMixin, } from '@spectrum-web-components/base';
14
+ import { property } from '@spectrum-web-components/base/src/decorators.js';
15
+ import { ButtonBase } from '@spectrum-web-components/button';
16
+ import buttonStyles from './action-button.css.js';
17
+ import cornerTriangleStyles from '@spectrum-web-components/icon/src/spectrum-icon-corner-triangle.css.js';
18
+ import '@spectrum-web-components/icons-ui/icons/sp-icon-corner-triangle300.js';
19
+ const holdAffordanceClass = {
20
+ s: 'spectrum-UIIcon-CornerTriangle75',
21
+ m: 'spectrum-UIIcon-CornerTriangle100',
22
+ l: 'spectrum-UIIcon-CornerTriangle200',
23
+ xl: 'spectrum-UIIcon-CornerTriangle300',
24
+ };
25
+ const LONGPRESS_DURATION = 300;
26
+ let LONGPRESS_TIMEOUT;
27
+ /**
28
+ * @element sp-action-button
29
+ *
30
+ * @slot - text label of the Action Button
31
+ * @slot icon - The icon to use for Action Button
32
+ * @fires change - Announces a change in the `selected` property of an action button
33
+ * @fires longpress - Synthesizes a "longpress" interaction that signifies a
34
+ * `pointerdown` event that is >=300ms or a keyboard event wher code is `Space` or code is `ArrowDown`
35
+ * while `altKey===true`.
36
+ */
37
+ export class ActionButton extends SizedMixin(ButtonBase) {
38
+ constructor() {
39
+ super();
40
+ this.emphasized = false;
41
+ this.holdAffordance = false;
42
+ this.quiet = false;
43
+ this.role = 'button';
44
+ /**
45
+ * Whether an Action Button with `role='button'`
46
+ * should also be `aria-pressed='true'`
47
+ */
48
+ this.selected = false;
49
+ /**
50
+ * Whether to automatically manage the `selected`
51
+ * attribute on interaction and whether `aria-pressed="false"`
52
+ * should be used when `selected === false`
53
+ */
54
+ this.toggles = false;
55
+ this._value = '';
56
+ this.onClick = () => {
57
+ if (!this.toggles) {
58
+ return;
59
+ }
60
+ this.selected = !this.selected;
61
+ const applyDefault = this.dispatchEvent(new Event('change', {
62
+ cancelable: true,
63
+ }));
64
+ if (!applyDefault) {
65
+ this.selected = !this.selected;
66
+ }
67
+ };
68
+ this.addEventListener('click', this.onClick);
69
+ this.addEventListener('pointerdown', this.onPointerdown);
70
+ }
71
+ static get styles() {
72
+ return [buttonStyles, cornerTriangleStyles];
73
+ }
74
+ get value() {
75
+ return this._value || this.itemText;
76
+ }
77
+ set value(value) {
78
+ if (value === this._value) {
79
+ return;
80
+ }
81
+ this._value = value || '';
82
+ if (this._value) {
83
+ this.setAttribute('value', this._value);
84
+ }
85
+ else {
86
+ this.removeAttribute('value');
87
+ }
88
+ }
89
+ /**
90
+ * @private
91
+ */
92
+ get itemText() {
93
+ return (this.textContent || /* c8 ignore next */ '').trim();
94
+ }
95
+ onPointerdown() {
96
+ this.addEventListener('pointerup', this.onPointerup);
97
+ this.addEventListener('pointercancel', this.onPointerup);
98
+ LONGPRESS_TIMEOUT = setTimeout(() => {
99
+ this.dispatchEvent(new CustomEvent('longpress', {
100
+ bubbles: true,
101
+ composed: true,
102
+ detail: {
103
+ source: 'pointer',
104
+ },
105
+ }));
106
+ }, LONGPRESS_DURATION);
107
+ }
108
+ onPointerup() {
109
+ clearTimeout(LONGPRESS_TIMEOUT);
110
+ this.removeEventListener('pointerup', this.onPointerup);
111
+ this.removeEventListener('pointercancel', this.onPointerup);
112
+ }
113
+ /**
114
+ * @private
115
+ */
116
+ handleKeydown(event) {
117
+ if (!this.holdAffordance) {
118
+ return super.handleKeydown(event);
119
+ }
120
+ const { code, altKey } = event;
121
+ if (code === 'Space' || (altKey && code === 'ArrowDown')) {
122
+ event.preventDefault();
123
+ if (code === 'ArrowDown') {
124
+ event.stopPropagation();
125
+ event.stopImmediatePropagation();
126
+ }
127
+ this.addEventListener('keyup', this.handleKeyup);
128
+ this.active = true;
129
+ }
130
+ }
131
+ handleKeyup(event) {
132
+ if (!this.holdAffordance) {
133
+ return super.handleKeyup(event);
134
+ }
135
+ const { code, altKey } = event;
136
+ if (code === 'Space' || (altKey && code === 'ArrowDown')) {
137
+ event.stopPropagation();
138
+ this.dispatchEvent(new CustomEvent('longpress', {
139
+ bubbles: true,
140
+ composed: true,
141
+ detail: {
142
+ source: 'keyboard',
143
+ },
144
+ }));
145
+ this.active = false;
146
+ }
147
+ }
148
+ get buttonContent() {
149
+ const buttonContent = super.buttonContent;
150
+ if (this.holdAffordance) {
151
+ buttonContent.unshift(html `
152
+ <sp-icon-corner-triangle300
153
+ class="hold-affordance ${holdAffordanceClass[this.size]}"
154
+ ></sp-icon-corner-triangle300>
155
+ `);
156
+ }
157
+ return buttonContent;
158
+ }
159
+ updated(changes) {
160
+ super.updated(changes);
161
+ const isButton = this.role === 'button';
162
+ const canBePressed = isButton && (this.selected || this.toggles);
163
+ if (changes.has('selected') || changes.has('role')) {
164
+ // When role !== 'button' then the Action Button is within
165
+ // an Action Group that manages selects which means the
166
+ // Action Button is a "checkbox" or "radio" and cannot
167
+ // accept the `aria-pressed` attribute.
168
+ if (canBePressed) {
169
+ this.setAttribute('aria-pressed', this.selected ? 'true' : 'false');
170
+ }
171
+ else {
172
+ // When !this.toggles the lack of "aria-pressed" is inconsequential.
173
+ this.removeAttribute('aria-pressed');
174
+ }
175
+ }
176
+ }
177
+ }
178
+ __decorate([
179
+ property({ type: Boolean, reflect: true })
180
+ ], ActionButton.prototype, "emphasized", void 0);
181
+ __decorate([
182
+ property({ type: Boolean, reflect: true, attribute: 'hold-affordance' })
183
+ ], ActionButton.prototype, "holdAffordance", void 0);
184
+ __decorate([
185
+ property({ type: Boolean, reflect: true })
186
+ ], ActionButton.prototype, "quiet", void 0);
187
+ __decorate([
188
+ property({ reflect: true })
189
+ ], ActionButton.prototype, "role", void 0);
190
+ __decorate([
191
+ property({ type: Boolean, reflect: true })
192
+ ], ActionButton.prototype, "selected", void 0);
193
+ __decorate([
194
+ property({ type: Boolean, reflect: true })
195
+ ], ActionButton.prototype, "toggles", void 0);
196
+ __decorate([
197
+ property({ reflect: true })
198
+ ], ActionButton.prototype, "variant", void 0);
199
+ __decorate([
200
+ property({ type: String })
201
+ ], ActionButton.prototype, "value", null);
202
+ //# sourceMappingURL=ActionButton.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ActionButton.js","sourceRoot":"","sources":["ActionButton.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;;AAEF,OAAO,EAGH,IAAI,EAEJ,UAAU,GAEb,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,iDAAiD,CAAC;AAC3E,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC7D,OAAO,YAAY,MAAM,wBAAwB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OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;8CACnB;AAQxB;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;6CACpB;AAGvB;IADC,QAAQ,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;6CACO;AAGnC;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;yCAG1B","sourcesContent":["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport {\n CSSResultArray,\n DefaultElementSize,\n html,\n PropertyValues,\n SizedMixin,\n TemplateResult,\n} from '@spectrum-web-components/base';\nimport { property } from '@spectrum-web-components/base/src/decorators.js';\nimport { ButtonBase } from '@spectrum-web-components/button';\nimport buttonStyles from './action-button.css.js';\nimport cornerTriangleStyles from '@spectrum-web-components/icon/src/spectrum-icon-corner-triangle.css.js';\nimport '@spectrum-web-components/icons-ui/icons/sp-icon-corner-triangle300.js';\n\nconst holdAffordanceClass = {\n s: 'spectrum-UIIcon-CornerTriangle75',\n m: 'spectrum-UIIcon-CornerTriangle100',\n l: 'spectrum-UIIcon-CornerTriangle200',\n xl: 'spectrum-UIIcon-CornerTriangle300',\n};\n\nconst LONGPRESS_DURATION = 300;\nlet LONGPRESS_TIMEOUT: ReturnType<typeof setTimeout>;\n\nexport type LongpressEvent = {\n source: 'pointer' | 'keyboard';\n};\n\n/**\n * @element sp-action-button\n *\n * @slot - text label of the Action Button\n * @slot icon - The icon to use for Action Button\n * @fires change - Announces a change in the `selected` property of an action button\n * @fires longpress - Synthesizes a \"longpress\" interaction that signifies a\n * `pointerdown` event that is >=300ms or a keyboard event wher code is `Space` or code is `ArrowDown`\n * while `altKey===true`.\n */\nexport class ActionButton extends SizedMixin(ButtonBase) {\n public static get styles(): CSSResultArray {\n return [buttonStyles, cornerTriangleStyles];\n }\n\n @property({ type: Boolean, reflect: true })\n public emphasized = false;\n\n @property({ type: Boolean, reflect: true, attribute: 'hold-affordance' })\n public holdAffordance = false;\n\n @property({ type: Boolean, reflect: true })\n public quiet = false;\n\n @property({ reflect: true })\n public role = 'button';\n\n /**\n * Whether an Action Button with `role='button'`\n * should also be `aria-pressed='true'`\n */\n @property({ type: Boolean, reflect: true })\n public selected = false;\n\n /**\n * Whether to automatically manage the `selected`\n * attribute on interaction and whether `aria-pressed=\"false\"`\n * should be used when `selected === false`\n */\n @property({ type: Boolean, reflect: true })\n public toggles = false;\n\n @property({ reflect: true })\n public variant?: 'white' | 'black';\n\n @property({ type: String })\n public get value(): string {\n return this._value || this.itemText;\n }\n public set value(value: string) {\n if (value === this._value) {\n return;\n }\n this._value = value || '';\n if (this._value) {\n this.setAttribute('value', this._value);\n } else {\n this.removeAttribute('value');\n }\n }\n private _value = '';\n\n /**\n * @private\n */\n public get itemText(): string {\n return (this.textContent || /* c8 ignore next */ '').trim();\n }\n\n constructor() {\n super();\n this.addEventListener('click', this.onClick);\n this.addEventListener('pointerdown', this.onPointerdown);\n }\n\n private onClick = (): void => {\n if (!this.toggles) {\n return;\n }\n this.selected = !this.selected;\n const applyDefault = this.dispatchEvent(\n new Event('change', {\n cancelable: true,\n })\n );\n if (!applyDefault) {\n this.selected = !this.selected;\n }\n };\n\n private onPointerdown(): void {\n this.addEventListener('pointerup', this.onPointerup);\n this.addEventListener('pointercancel', this.onPointerup);\n LONGPRESS_TIMEOUT = setTimeout(() => {\n this.dispatchEvent(\n new CustomEvent<LongpressEvent>('longpress', {\n bubbles: true,\n composed: true,\n detail: {\n source: 'pointer',\n },\n })\n );\n }, LONGPRESS_DURATION);\n }\n\n private onPointerup(): void {\n clearTimeout(LONGPRESS_TIMEOUT);\n this.removeEventListener('pointerup', this.onPointerup);\n this.removeEventListener('pointercancel', this.onPointerup);\n }\n\n /**\n * @private\n */\n protected handleKeydown(event: KeyboardEvent): void {\n if (!this.holdAffordance) {\n return super.handleKeydown(event);\n }\n const { code, altKey } = event;\n if (code === 'Space' || (altKey && code === 'ArrowDown')) {\n event.preventDefault();\n if (code === 'ArrowDown') {\n event.stopPropagation();\n event.stopImmediatePropagation();\n }\n this.addEventListener('keyup', this.handleKeyup);\n this.active = true;\n }\n }\n\n protected handleKeyup(event: KeyboardEvent): void {\n if (!this.holdAffordance) {\n return super.handleKeyup(event);\n }\n const { code, altKey } = event;\n if (code === 'Space' || (altKey && code === 'ArrowDown')) {\n event.stopPropagation();\n this.dispatchEvent(\n new CustomEvent<LongpressEvent>('longpress', {\n bubbles: true,\n composed: true,\n detail: {\n source: 'keyboard',\n },\n })\n );\n this.active = false;\n }\n }\n\n protected get buttonContent(): TemplateResult[] {\n const buttonContent = super.buttonContent;\n if (this.holdAffordance) {\n buttonContent.unshift(html`\n <sp-icon-corner-triangle300\n class=\"hold-affordance ${holdAffordanceClass[\n this.size as DefaultElementSize\n ]}\"\n ></sp-icon-corner-triangle300>\n `);\n }\n return buttonContent;\n }\n\n protected updated(changes: PropertyValues): void {\n super.updated(changes);\n const isButton = this.role === 'button';\n const canBePressed = isButton && (this.selected || this.toggles);\n if (changes.has('selected') || changes.has('role')) {\n // When role !== 'button' then the Action Button is within\n // an Action Group that manages selects which means the\n // Action Button is a \"checkbox\" or \"radio\" and cannot\n // accept the `aria-pressed` attribute.\n if (canBePressed) {\n this.setAttribute(\n 'aria-pressed',\n this.selected ? 'true' : 'false'\n );\n } else {\n // When !this.toggles the lack of \"aria-pressed\" is inconsequential.\n this.removeAttribute('aria-pressed');\n }\n }\n }\n}\n\ndeclare global {\n interface GlobalEventHandlersEventMap {\n longpress: CustomEvent<LongpressEvent>;\n }\n}\n"]}
@@ -0,0 +1,2 @@
1
+ declare const styles: import("@spectrum-web-components/base").CSSResult;
2
+ export default styles;