1- import type { SvelteComponent } from 'svelte' ;
1+ import type { Snippet , SvelteComponent } from 'svelte' ;
22import type { HTMLImgAttributes } from 'svelte/elements' ;
33
4- /**
5- * Slots of Avatar component
6- *
7- */
8- export interface AvatarSlots {
9- default : {
10- /** The resolved avatar url */
11- src : string ;
12- /** The resolved alt text, if any */
13- alt : string ;
14- /** The resolved size, if any */
15- size : number ;
16- /** All the images source from prop */
17- sources : string [ ] ;
18- } ;
19- }
20-
21- /**
22- * Props to Avatar component
23- *
24- */
25- export interface AvatarProps extends HTMLImgAttributes {
26- /**
27- * "src" attribute. This option is of highest priority
28- */
29- src ?: string ;
30- /**
31- * Either the email for {@link https://en.gravatar.com/site/implement/images | Gravatar }
32- * or {@link GravatarOptions } object. This option take second priority.
33- *
34- * By default, the Gravatar `default` query is set to 404, so that if gravatar is not valid,
35- * the next priority url will be used. Be careful when setting this `default` to other values,
36- * as gravatar will then always return a valid resource, hence stopping the resolution flow
37- * (i.e uiAvatar & fallback will never be used).
38- */
39- gravatar ?: GravatarOptions | string ;
40- /**
41- * Either the name for building initials with {@link https://ui-avatars.com | UIAvatar }
42- * or {@link UIAvatarOptions } object. This option take third priority.
43- */
44- uiAvatar ?: string | UIAvatarOptions ;
45- /**
46- * The fallback url string. This option takes lowest priority.
47- * It defaults to the internal fallback (https://www.gravatar.com/avatar?d=mp).
48- * If you provide a different url that is not a valid resource, the internal fallback
49- * will be used.
50- */
51- fallback ?: string ;
52- /**
53- * value for "width" & "height" attribute of <img>.
54- * Will have no effect if default slot is overridden
55- */
56- size ?: number ;
57- /**
58- * value for "alt" attribute of <img>.
59- * Default to uiAvatar.name or gravatar.email if any.
60- * Will have no effect if default slot is overridden
61- */
62- alt ?: string ;
63- class ?: string ;
64- }
65-
664/**
675 * URL or option to fallback when email hash returns no match from Gravatar.
686 * See {@link https://en.gravatar.com/site/implement/images | Gravatar } for
@@ -80,11 +18,6 @@ export type GravatarDefault =
8018 | 'blank'
8119 | `${'http' | 'https' } ://${string } .${'png' | 'jpg' | 'jpeg' | 'gif' } `;
8220
83- /**
84- * Options for building {@link https://en.gravatar.com/site/implement/images | Gravatar } url.
85- * Each option should map to a supported Gravatar query param
86- *
87- */
8821export interface GravatarOptions {
8922 /** email to md5-hash */
9023 email : string ;
@@ -126,5 +59,49 @@ export interface UIAvatarOptions {
12659 format ?: 'svg' | 'png' ;
12760}
12861
129- // eslint-disable-next-line @typescript-eslint/ban-types
130- export default class Avatar extends SvelteComponent < AvatarProps , { } , AvatarSlots > { }
62+ /**
63+ * Props to Avatar component
64+ */
65+ export interface AvatarProps extends HTMLImgAttributes {
66+ /**
67+ * "src" attribute. This option is of highest priority
68+ */
69+ src ?: string ;
70+ /**
71+ * Either the email for {@link https://en.gravatar.com/site/implement/images | Gravatar }
72+ * or {@link GravatarOptions } object. This option take second priority.
73+ *
74+ * By default, the Gravatar `default` query is set to 404, so that if gravatar is not valid,
75+ * the next priority url will be used. Be careful when setting this `default` to other values,
76+ * as gravatar will then always return a valid resource, hence stopping the resolution flow
77+ * (i.e uiAvatar & fallback will never be used).
78+ */
79+ gravatar ?: GravatarOptions | string ;
80+ /**
81+ * Either the name for building initials with {@link https://ui-avatars.com | UIAvatar }
82+ * or {@link UIAvatarOptions } object. This option take third priority.
83+ */
84+ uiAvatar ?: string | UIAvatarOptions ;
85+ /**
86+ * The fallback url string. This option takes lowest priority.
87+ * It defaults to the internal fallback (https://www.gravatar.com/avatar?d=mp).
88+ * If you provide a different url that is not a valid resource, the internal fallback
89+ * will be used.
90+ */
91+ fallback ?: string ;
92+ /**
93+ * value for "width" & "height" attribute of <img>.
94+ * Will have no effect if default slot is overridden
95+ */
96+ size ?: number ;
97+ /**
98+ * value for "alt" attribute of <img>.
99+ * Default to uiAvatar.name or gravatar.email if any.
100+ * Will have no effect if default slot is overridden
101+ */
102+ alt ?: string ;
103+ img ?: Snippet < [ { src : string ; size : number ; alt : string ; sources : string [ ] } ] > ;
104+ }
105+
106+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
107+ export default class Avatar extends SvelteComponent < AvatarProps , any , any > { }
0 commit comments