@vaadin/icon 24.4.0-dev.4b20a0c55.3 → 24.4.0-rc1
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 +190 -0
- package/package.json +7 -5
- package/src/vaadin-icon-mixin.d.ts +88 -0
- package/src/vaadin-icon-mixin.js +364 -0
- package/src/vaadin-icon-styles.js +49 -0
- package/src/vaadin-icon.d.ts +2 -74
- package/src/vaadin-icon.js +7 -396
- package/src/vaadin-iconset-mixin.d.ts +29 -0
- package/src/vaadin-iconset-mixin.js +169 -0
- package/src/vaadin-iconset.d.ts +2 -17
- package/src/vaadin-iconset.js +3 -163
- package/theme/lumo/vaadin-icon-styles.d.ts +1 -0
- package/theme/lumo/vaadin-icon.d.ts +2 -0
- package/theme/material/vaadin-icon-styles.d.ts +1 -0
- package/theme/material/vaadin-icon.d.ts +2 -0
- package/web-types.json +259 -0
- package/web-types.lit.json +111 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2017 - 2024 Vaadin Ltd.
|
|
4
|
+
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
|
+
*/
|
|
6
|
+
import { css } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
|
|
7
|
+
|
|
8
|
+
export const iconStyles = css`
|
|
9
|
+
:host {
|
|
10
|
+
display: inline-flex;
|
|
11
|
+
justify-content: center;
|
|
12
|
+
align-items: center;
|
|
13
|
+
box-sizing: border-box;
|
|
14
|
+
vertical-align: middle;
|
|
15
|
+
width: 24px;
|
|
16
|
+
height: 24px;
|
|
17
|
+
fill: currentColor;
|
|
18
|
+
container-type: size;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
:host::after,
|
|
22
|
+
:host::before {
|
|
23
|
+
line-height: 1;
|
|
24
|
+
font-size: 100cqh;
|
|
25
|
+
-webkit-font-smoothing: antialiased;
|
|
26
|
+
text-rendering: optimizeLegibility;
|
|
27
|
+
-moz-osx-font-smoothing: grayscale;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
:host([hidden]) {
|
|
31
|
+
display: none !important;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
svg {
|
|
35
|
+
display: block;
|
|
36
|
+
width: 100%;
|
|
37
|
+
height: 100%;
|
|
38
|
+
/* prevent overflowing icon from clipping, see https://github.com/vaadin/flow-components/issues/5872 */
|
|
39
|
+
overflow: visible;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
:host(:is([icon-class], [font-icon-content])) svg {
|
|
43
|
+
display: none;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
:host([font-icon-content])::before {
|
|
47
|
+
content: attr(font-icon-content);
|
|
48
|
+
}
|
|
49
|
+
`;
|
package/src/vaadin-icon.d.ts
CHANGED
|
@@ -5,10 +5,8 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { ControllerMixin } from '@vaadin/component-base/src/controller-mixin.js';
|
|
7
7
|
import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
|
|
8
|
-
import { SlotStylesMixin } from '@vaadin/component-base/src/slot-styles-mixin.js';
|
|
9
8
|
import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
|
|
10
|
-
import {
|
|
11
|
-
import type { IconSvgLiteral } from './vaadin-icon-svg.js';
|
|
9
|
+
import { IconMixin } from './vaadin-icon-mixin.js';
|
|
12
10
|
|
|
13
11
|
/**
|
|
14
12
|
* `<vaadin-icon>` is a Web Component for displaying SVG icons.
|
|
@@ -49,77 +47,7 @@ import type { IconSvgLiteral } from './vaadin-icon-svg.js';
|
|
|
49
47
|
* }
|
|
50
48
|
* ```
|
|
51
49
|
*/
|
|
52
|
-
declare class Icon extends ThemableMixin(
|
|
53
|
-
ElementMixin(ControllerMixin(SlotStylesMixin(IconFontSizeMixin(HTMLElement)))),
|
|
54
|
-
) {
|
|
55
|
-
/**
|
|
56
|
-
* The name of the icon to use. The name should be of the form:
|
|
57
|
-
* `iconset_name:icon_name`. When using `vaadin-icons` it is possible
|
|
58
|
-
* to omit the first part and only use `icon_name` as a value.
|
|
59
|
-
*
|
|
60
|
-
* Setting the `icon` property updates the `svg` and `size` based on the
|
|
61
|
-
* values provided by the corresponding `vaadin-iconset` element.
|
|
62
|
-
*
|
|
63
|
-
* See also [`name`](#/elements/vaadin-iconset#property-name) property of `vaadin-iconset`.
|
|
64
|
-
*
|
|
65
|
-
* @attr {string} icon
|
|
66
|
-
*/
|
|
67
|
-
icon: string | null;
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* The SVG icon wrapped in a Lit template literal.
|
|
71
|
-
*/
|
|
72
|
-
svg: IconSvgLiteral | null;
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* The SVG source to be loaded as the icon. It can be:
|
|
76
|
-
* - an URL to a file containing the icon
|
|
77
|
-
* - an URL in the format "/path/to/file.svg#objectID", where the "objectID" refers to an ID attribute contained
|
|
78
|
-
* inside the SVG referenced by the path. Note that the file needs to follow the same-origin policy.
|
|
79
|
-
* - a string in the format "data:image/svg+xml,<svg>...</svg>". You may need to use the "encodeURIComponent"
|
|
80
|
-
* function for the SVG content passed
|
|
81
|
-
*/
|
|
82
|
-
src: string | null;
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* The symbol identifier that references an ID of an element contained in the SVG element assigned to the
|
|
86
|
-
* `src` property
|
|
87
|
-
*/
|
|
88
|
-
symbol: string | null;
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Class names defining an icon font and/or a specific glyph inside an icon font.
|
|
92
|
-
*
|
|
93
|
-
* Example: "fa-solid fa-user"
|
|
94
|
-
*
|
|
95
|
-
* @attr {string} icon-class
|
|
96
|
-
*/
|
|
97
|
-
iconClass: string | null;
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* A hexadecimal code point that specifies a glyph from an icon font.
|
|
101
|
-
*
|
|
102
|
-
* Example: "e001"
|
|
103
|
-
*/
|
|
104
|
-
char: string | null;
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* A ligature name that specifies an icon from an icon font with support for ligatures.
|
|
108
|
-
*
|
|
109
|
-
* Example: "home".
|
|
110
|
-
*/
|
|
111
|
-
ligature: string | null;
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* The font family to use for the font icon.
|
|
115
|
-
*/
|
|
116
|
-
fontFamily: string | null;
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* The size of an icon, used to set the `viewBox` attribute.
|
|
120
|
-
*/
|
|
121
|
-
size: number;
|
|
122
|
-
}
|
|
50
|
+
declare class Icon extends ThemableMixin(ElementMixin(ControllerMixin(IconMixin(HTMLElement)))) {}
|
|
123
51
|
|
|
124
52
|
declare global {
|
|
125
53
|
interface HTMLElementTagNameMap {
|
package/src/vaadin-icon.js
CHANGED
|
@@ -3,18 +3,16 @@
|
|
|
3
3
|
* Copyright (c) 2021 - 2024 Vaadin Ltd.
|
|
4
4
|
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
5
|
*/
|
|
6
|
+
import './vaadin-iconset.js';
|
|
6
7
|
import { html, PolymerElement } from '@polymer/polymer/polymer-element.js';
|
|
7
8
|
import { ControllerMixin } from '@vaadin/component-base/src/controller-mixin.js';
|
|
8
9
|
import { defineCustomElement } from '@vaadin/component-base/src/define.js';
|
|
9
10
|
import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import { IconFontSizeMixin } from './vaadin-icon-font-size-mixin.js';
|
|
14
|
-
import { ensureSvgLiteral, renderSvg, unsafeSvgLiteral } from './vaadin-icon-svg.js';
|
|
15
|
-
import { Iconset } from './vaadin-iconset.js';
|
|
11
|
+
import { registerStyles, ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
|
|
12
|
+
import { IconMixin } from './vaadin-icon-mixin.js';
|
|
13
|
+
import { iconStyles } from './vaadin-icon-styles.js';
|
|
16
14
|
|
|
17
|
-
|
|
15
|
+
registerStyles('vaadin-icon', iconStyles, { moduleId: 'vaadin-icon-styles' });
|
|
18
16
|
|
|
19
17
|
/**
|
|
20
18
|
* `<vaadin-icon>` is a Web Component for displaying SVG icons.
|
|
@@ -57,57 +55,14 @@ const srcCache = new Map();
|
|
|
57
55
|
*
|
|
58
56
|
* @customElement
|
|
59
57
|
* @extends HTMLElement
|
|
58
|
+
* @mixes IconMixin
|
|
60
59
|
* @mixes ControllerMixin
|
|
61
60
|
* @mixes ThemableMixin
|
|
62
61
|
* @mixes ElementMixin
|
|
63
|
-
* @mixes SlotStylesMixin
|
|
64
|
-
* @mixes IconFontSizeMixin
|
|
65
62
|
*/
|
|
66
|
-
class Icon extends
|
|
63
|
+
class Icon extends IconMixin(ControllerMixin(ElementMixin(ThemableMixin(PolymerElement)))) {
|
|
67
64
|
static get template() {
|
|
68
65
|
return html`
|
|
69
|
-
<style>
|
|
70
|
-
:host {
|
|
71
|
-
display: inline-flex;
|
|
72
|
-
justify-content: center;
|
|
73
|
-
align-items: center;
|
|
74
|
-
box-sizing: border-box;
|
|
75
|
-
vertical-align: middle;
|
|
76
|
-
width: 24px;
|
|
77
|
-
height: 24px;
|
|
78
|
-
fill: currentColor;
|
|
79
|
-
container-type: size;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
:host::after,
|
|
83
|
-
:host::before {
|
|
84
|
-
line-height: 1;
|
|
85
|
-
font-size: 100cqh;
|
|
86
|
-
-webkit-font-smoothing: antialiased;
|
|
87
|
-
text-rendering: optimizeLegibility;
|
|
88
|
-
-moz-osx-font-smoothing: grayscale;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
:host([hidden]) {
|
|
92
|
-
display: none !important;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
svg {
|
|
96
|
-
display: block;
|
|
97
|
-
width: 100%;
|
|
98
|
-
height: 100%;
|
|
99
|
-
/* prevent overflowing icon from clipping, see https://github.com/vaadin/flow-components/issues/5872 */
|
|
100
|
-
overflow: visible;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
:host(:is([icon-class], [font-icon-content])) svg {
|
|
104
|
-
display: none;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
:host([font-icon-content])::before {
|
|
108
|
-
content: attr(font-icon-content);
|
|
109
|
-
}
|
|
110
|
-
</style>
|
|
111
66
|
<svg
|
|
112
67
|
version="1.1"
|
|
113
68
|
xmlns="http://www.w3.org/2000/svg"
|
|
@@ -134,350 +89,6 @@ class Icon extends ThemableMixin(ElementMixin(ControllerMixin(SlotStylesMixin(Ic
|
|
|
134
89
|
static get is() {
|
|
135
90
|
return 'vaadin-icon';
|
|
136
91
|
}
|
|
137
|
-
|
|
138
|
-
static get properties() {
|
|
139
|
-
return {
|
|
140
|
-
/**
|
|
141
|
-
* The name of the icon to use. The name should be of the form:
|
|
142
|
-
* `iconset_name:icon_name`. When using `vaadin-icons` it is possible
|
|
143
|
-
* to omit the first part and only use `icon_name` as a value.
|
|
144
|
-
*
|
|
145
|
-
* Setting the `icon` property updates the `svg` and `size` based on the
|
|
146
|
-
* values provided by the corresponding `vaadin-iconset` element.
|
|
147
|
-
*
|
|
148
|
-
* See also [`name`](#/elements/vaadin-iconset#property-name) property of `vaadin-iconset`.
|
|
149
|
-
*
|
|
150
|
-
* @attr {string} icon
|
|
151
|
-
* @type {string}
|
|
152
|
-
*/
|
|
153
|
-
icon: {
|
|
154
|
-
type: String,
|
|
155
|
-
reflectToAttribute: true,
|
|
156
|
-
observer: '__iconChanged',
|
|
157
|
-
},
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* The SVG icon wrapped in a Lit template literal.
|
|
161
|
-
*/
|
|
162
|
-
svg: {
|
|
163
|
-
type: Object,
|
|
164
|
-
},
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* The SVG source to be loaded as the icon. It can be:
|
|
168
|
-
* - an URL to a file containing the icon
|
|
169
|
-
* - an URL in the format "/path/to/file.svg#objectID", where the "objectID" refers to an ID attribute contained
|
|
170
|
-
* inside the SVG referenced by the path. Note that the file needs to follow the same-origin policy.
|
|
171
|
-
* - a string in the format "data:image/svg+xml,<svg>...</svg>". You may need to use the "encodeURIComponent"
|
|
172
|
-
* function for the SVG content passed
|
|
173
|
-
*
|
|
174
|
-
* @type {string}
|
|
175
|
-
*/
|
|
176
|
-
src: {
|
|
177
|
-
type: String,
|
|
178
|
-
},
|
|
179
|
-
|
|
180
|
-
/**
|
|
181
|
-
* The symbol identifier that references an ID of an element contained in the SVG element assigned to the
|
|
182
|
-
* `src` property
|
|
183
|
-
*
|
|
184
|
-
* @type {string}
|
|
185
|
-
*/
|
|
186
|
-
symbol: {
|
|
187
|
-
type: String,
|
|
188
|
-
},
|
|
189
|
-
|
|
190
|
-
/**
|
|
191
|
-
* Class names defining an icon font and/or a specific glyph inside an icon font.
|
|
192
|
-
*
|
|
193
|
-
* Example: "fa-solid fa-user"
|
|
194
|
-
*
|
|
195
|
-
* @attr {string} icon-class
|
|
196
|
-
* @type {string}
|
|
197
|
-
*/
|
|
198
|
-
iconClass: {
|
|
199
|
-
type: String,
|
|
200
|
-
reflectToAttribute: true,
|
|
201
|
-
},
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
* A hexadecimal code point that specifies a glyph from an icon font.
|
|
205
|
-
*
|
|
206
|
-
* Example: "e001"
|
|
207
|
-
*
|
|
208
|
-
* @type {string}
|
|
209
|
-
*/
|
|
210
|
-
char: {
|
|
211
|
-
type: String,
|
|
212
|
-
},
|
|
213
|
-
|
|
214
|
-
/**
|
|
215
|
-
* A ligature name that specifies an icon from an icon font with support for ligatures.
|
|
216
|
-
*
|
|
217
|
-
* Example: "home".
|
|
218
|
-
*
|
|
219
|
-
* @type {string}
|
|
220
|
-
*/
|
|
221
|
-
ligature: {
|
|
222
|
-
type: String,
|
|
223
|
-
},
|
|
224
|
-
|
|
225
|
-
/**
|
|
226
|
-
* The font family to use for the font icon.
|
|
227
|
-
*
|
|
228
|
-
* @type {string}
|
|
229
|
-
*/
|
|
230
|
-
fontFamily: {
|
|
231
|
-
type: String,
|
|
232
|
-
observer: '__fontFamilyChanged',
|
|
233
|
-
},
|
|
234
|
-
|
|
235
|
-
/**
|
|
236
|
-
* The size of an icon, used to set the `viewBox` attribute.
|
|
237
|
-
*/
|
|
238
|
-
size: {
|
|
239
|
-
type: Number,
|
|
240
|
-
value: 24,
|
|
241
|
-
},
|
|
242
|
-
|
|
243
|
-
/** @private */
|
|
244
|
-
__defaultPAR: {
|
|
245
|
-
type: String,
|
|
246
|
-
value: 'xMidYMid meet',
|
|
247
|
-
},
|
|
248
|
-
|
|
249
|
-
/** @private */
|
|
250
|
-
__preserveAspectRatio: String,
|
|
251
|
-
|
|
252
|
-
/** @private */
|
|
253
|
-
__useRef: Object,
|
|
254
|
-
|
|
255
|
-
/** @private */
|
|
256
|
-
__svgElement: String,
|
|
257
|
-
|
|
258
|
-
/** @private */
|
|
259
|
-
__viewBox: String,
|
|
260
|
-
|
|
261
|
-
/** @private */
|
|
262
|
-
__fill: String,
|
|
263
|
-
|
|
264
|
-
/** @private */
|
|
265
|
-
__stroke: String,
|
|
266
|
-
|
|
267
|
-
/** @private */
|
|
268
|
-
__strokeWidth: String,
|
|
269
|
-
|
|
270
|
-
/** @private */
|
|
271
|
-
__strokeLinecap: String,
|
|
272
|
-
|
|
273
|
-
/** @private */
|
|
274
|
-
__strokeLinejoin: String,
|
|
275
|
-
};
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
static get observers() {
|
|
279
|
-
return ['__svgChanged(svg, __svgElement)', '__fontChanged(iconClass, char, ligature)', '__srcChanged(src, symbol)'];
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
static get observedAttributes() {
|
|
283
|
-
return [...super.observedAttributes, 'class'];
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
constructor() {
|
|
287
|
-
super();
|
|
288
|
-
|
|
289
|
-
this.__fetch = fetch.bind(window);
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
/** @protected */
|
|
293
|
-
get slotStyles() {
|
|
294
|
-
const tag = this.localName;
|
|
295
|
-
return [
|
|
296
|
-
`
|
|
297
|
-
${tag}[icon-class] {
|
|
298
|
-
display: inline-flex;
|
|
299
|
-
vertical-align: middle;
|
|
300
|
-
font-size: inherit;
|
|
301
|
-
}
|
|
302
|
-
`,
|
|
303
|
-
];
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
/** @private */
|
|
307
|
-
get __iconClasses() {
|
|
308
|
-
return this.iconClass ? this.iconClass.split(' ') : [];
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
/** @protected */
|
|
312
|
-
ready() {
|
|
313
|
-
super.ready();
|
|
314
|
-
this.__svgElement = this.shadowRoot.querySelector('#svg-group');
|
|
315
|
-
|
|
316
|
-
this._tooltipController = new TooltipController(this);
|
|
317
|
-
this.addController(this._tooltipController);
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
/** @protected */
|
|
321
|
-
connectedCallback() {
|
|
322
|
-
super.connectedCallback();
|
|
323
|
-
|
|
324
|
-
Iconset.attachedIcons.add(this);
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
/** @protected */
|
|
328
|
-
disconnectedCallback() {
|
|
329
|
-
super.disconnectedCallback();
|
|
330
|
-
|
|
331
|
-
Iconset.attachedIcons.delete(this);
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
/** @protected */
|
|
335
|
-
_applyIcon() {
|
|
336
|
-
const { preserveAspectRatio, svg, size, viewBox } = Iconset.getIconSvg(this.icon);
|
|
337
|
-
|
|
338
|
-
if (viewBox) {
|
|
339
|
-
this.__viewBox = viewBox;
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
if (preserveAspectRatio) {
|
|
343
|
-
this.__preserveAspectRatio = preserveAspectRatio;
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
if (size && size !== this.size) {
|
|
347
|
-
this.size = size;
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
this.svg = svg;
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
/** @private */
|
|
354
|
-
__iconChanged(icon) {
|
|
355
|
-
if (icon) {
|
|
356
|
-
this._applyIcon();
|
|
357
|
-
} else {
|
|
358
|
-
this.svg = ensureSvgLiteral(null);
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
/** @private */
|
|
363
|
-
async __srcChanged(src, symbol) {
|
|
364
|
-
if (!src) {
|
|
365
|
-
this.svg = null;
|
|
366
|
-
return;
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
// Need to add the "icon" attribute to avoid issues as described in
|
|
370
|
-
// https://github.com/vaadin/web-components/issues/6301
|
|
371
|
-
this.icon = '';
|
|
372
|
-
|
|
373
|
-
if (!src.startsWith('data:') && (symbol || src.includes('#'))) {
|
|
374
|
-
const [path, iconId] = src.split('#');
|
|
375
|
-
this.__useRef = `${path}#${symbol || iconId}`;
|
|
376
|
-
} else {
|
|
377
|
-
try {
|
|
378
|
-
if (!srcCache.has(src)) {
|
|
379
|
-
srcCache.set(
|
|
380
|
-
src,
|
|
381
|
-
this.__fetch(src, { mode: 'cors' }).then((data) => {
|
|
382
|
-
if (!data.ok) {
|
|
383
|
-
throw new Error('Error loading icon');
|
|
384
|
-
}
|
|
385
|
-
return data.text();
|
|
386
|
-
}),
|
|
387
|
-
);
|
|
388
|
-
}
|
|
389
|
-
const svgData = await srcCache.get(src);
|
|
390
|
-
|
|
391
|
-
if (!Icon.__domParser) {
|
|
392
|
-
Icon.__domParser = new DOMParser();
|
|
393
|
-
}
|
|
394
|
-
const parsedResponse = Icon.__domParser.parseFromString(svgData, 'text/html');
|
|
395
|
-
|
|
396
|
-
const svgElement = parsedResponse.querySelector('svg');
|
|
397
|
-
if (!svgElement) {
|
|
398
|
-
throw new Error(`SVG element not found on path: ${src}`);
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
this.svg = unsafeSvgLiteral(svgElement.innerHTML);
|
|
402
|
-
|
|
403
|
-
if (symbol) {
|
|
404
|
-
this.__useRef = `#${symbol}`;
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
this.__viewBox = svgElement.getAttribute('viewBox');
|
|
408
|
-
this.__fill = svgElement.getAttribute('fill');
|
|
409
|
-
this.__stroke = svgElement.getAttribute('stroke');
|
|
410
|
-
this.__strokeWidth = svgElement.getAttribute('stroke-width');
|
|
411
|
-
this.__strokeLinecap = svgElement.getAttribute('stroke-linecap');
|
|
412
|
-
this.__strokeLinejoin = svgElement.getAttribute('stroke-linejoin');
|
|
413
|
-
} catch (e) {
|
|
414
|
-
console.error(e);
|
|
415
|
-
this.svg = null;
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
/** @private */
|
|
421
|
-
__svgChanged(svg, svgElement) {
|
|
422
|
-
if (!svgElement) {
|
|
423
|
-
return;
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
renderSvg(svg, svgElement);
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
/** @private */
|
|
430
|
-
__computePAR(defaultPAR, preserveAspectRatio) {
|
|
431
|
-
return preserveAspectRatio || defaultPAR;
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
/** @private */
|
|
435
|
-
__computeVisibility(__useRef) {
|
|
436
|
-
return __useRef ? 'visible' : 'hidden';
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
/** @private */
|
|
440
|
-
__computeViewBox(size, viewBox) {
|
|
441
|
-
return viewBox || `0 0 ${size} ${size}`;
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
/** @private */
|
|
445
|
-
__fontChanged(iconClass, char, ligature) {
|
|
446
|
-
this.classList.remove(...(this.__addedIconClasses || []));
|
|
447
|
-
if (iconClass) {
|
|
448
|
-
this.__addedIconClasses = [...this.__iconClasses];
|
|
449
|
-
this.classList.add(...this.__addedIconClasses);
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
if (char) {
|
|
453
|
-
this.setAttribute('font-icon-content', char.length > 1 ? String.fromCodePoint(parseInt(char, 16)) : char);
|
|
454
|
-
} else if (ligature) {
|
|
455
|
-
this.setAttribute('font-icon-content', ligature);
|
|
456
|
-
} else {
|
|
457
|
-
this.removeAttribute('font-icon-content');
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
if ((iconClass || char || ligature) && !this.icon) {
|
|
461
|
-
// The "icon" attribute needs to be set on the host also when using font icons
|
|
462
|
-
// to avoid issues such as https://github.com/vaadin/web-components/issues/6301
|
|
463
|
-
this.icon = '';
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
/** @protected */
|
|
468
|
-
attributeChangedCallback(name, oldValue, newValue) {
|
|
469
|
-
super.attributeChangedCallback(name, oldValue, newValue);
|
|
470
|
-
|
|
471
|
-
// Make sure class list always contains all the font class names
|
|
472
|
-
if (name === 'class' && this.__iconClasses.some((className) => !this.classList.contains(className))) {
|
|
473
|
-
this.classList.add(...this.__iconClasses);
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
/** @private */
|
|
478
|
-
__fontFamilyChanged(fontFamily) {
|
|
479
|
-
this.style.fontFamily = `'${fontFamily}'`;
|
|
480
|
-
}
|
|
481
92
|
}
|
|
482
93
|
|
|
483
94
|
defineCustomElement(Icon);
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2017 - 2024 Vaadin Ltd.
|
|
4
|
+
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
|
+
*/
|
|
6
|
+
import type { Constructor } from '@open-wc/dedupe-mixin';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A mixin providing common iconset functionality.
|
|
10
|
+
*/
|
|
11
|
+
export declare function IconsetMixin<T extends Constructor<HTMLElement>>(base: T): Constructor<IconsetMixinClass> & T;
|
|
12
|
+
|
|
13
|
+
export declare class IconsetMixinClass {
|
|
14
|
+
/**
|
|
15
|
+
* The name of the iconset. Every iconset is required to have its own unique name.
|
|
16
|
+
* All the SVG icons in the iconset must have IDs conforming to its name.
|
|
17
|
+
*
|
|
18
|
+
* See also [`name`](#/elements/vaadin-icon#property-name) property of `vaadin-icon`.
|
|
19
|
+
*/
|
|
20
|
+
name: string;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The size of an individual icon. Note that icons must be square.
|
|
24
|
+
*
|
|
25
|
+
* When using `vaadin-icon`, the size of the iconset will take precedence
|
|
26
|
+
* over the size defined by the user to ensure correct appearance.
|
|
27
|
+
*/
|
|
28
|
+
size: number;
|
|
29
|
+
}
|