Skip to content

Commit

Permalink
chore(avatar): re-expose public typedef
Browse files Browse the repository at this point in the history
  • Loading branch information
vnphanquang committed Jul 9, 2024
1 parent 28126b5 commit a2f8449
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .changeset/twenty-coins-destroy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@svelte-put/avatar': patch
---

re-expose public typedef (following https://github.com/Rich-Harris/dts-buddy/pull/82)
3 changes: 2 additions & 1 deletion packages/avatar/src/Avatar.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script>
import { resolveAlt, resolveSize, resolveSrc, DEFINITIVE_FALLBACK } from './avatar.utils.js';
/** @type {import('./types').AvatarProps} */
/** @type {import('./types.public').AvatarProps} */
let { src, gravatar, uiAvatar, fallback, size, alt, class: cls = '', img, ...rest } = $props();
let rAlt = $derived(resolveAlt(alt, gravatar, uiAvatar, src));
Expand Down Expand Up @@ -59,3 +59,4 @@
aspect-ratio: 1 / 1;
}
</style>
3 changes: 2 additions & 1 deletion packages/avatar/src/Avatar.svelte.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Component } from 'svelte';

import { AvatarProps } from './types';
import { AvatarProps } from './types.public';

declare const Avatar: Component<AvatarProps>;
export default Avatar;

9 changes: 4 additions & 5 deletions packages/avatar/src/avatar.helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import md5 from 'md5';

/**
* Builds a {@link https://ui-avatars.com | UIAvatar } url
*
* @param {string | import('./types').UIAvatarOptions} input - name for UIAvatar or object of options
* @param {string | import('./types.public').UIAvatarOptions} input - name for UIAvatar or object of options
* @returns {string} the constructed UIAvatar URL
*/
export function uiAvatar(input) {
Expand All @@ -24,13 +23,12 @@ export function uiAvatar(input) {

/**
* Builds a {@link https://en.gravatar.com/site/implement/images | Gravatar } url
*
* @param {string | import('./types').GravatarOptions} input - email for Gravatar or object of options
* @param {string | import('./types.public').GravatarOptions} input - email for Gravatar or object of options
* @returns {string} the constructed Gravatar URL
*/
export function gravatar(input) {
let email = '';
/** @type {Omit<import('./types').GravatarOptions, 'email'>} */
/** @type {Omit<import('./types.public').GravatarOptions, 'email'>} */
let options = {};
if (typeof input === 'string') {
email = input;
Expand All @@ -46,3 +44,4 @@ export function gravatar(input) {

return output;
}

13 changes: 7 additions & 6 deletions packages/avatar/src/avatar.utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ function nonNullableFilter(value) {
/**
* @package
* @param {string | undefined} alt
* @param {import('./types').AvatarProps['gravatar'] | undefined} gravatar
* @param {import('./types').AvatarProps['uiAvatar'] | undefined} uiAvatar
* @param {import('./types.public').AvatarProps['gravatar'] | undefined} gravatar
* @param {import('./types.public').AvatarProps['uiAvatar'] | undefined} uiAvatar
* @param {string | undefined } src
* @returns {string}
*/
Expand All @@ -71,8 +71,8 @@ export function resolveAlt(
* @param {number} fallback
* @param {number | undefined} size
* @param {string | undefined} src
* @param {import('./types').AvatarProps['gravatar'] | undefined} gravatar
* @param {import('./types').AvatarProps['uiAvatar'] | undefined} uiAvatar
* @param {import('./types.public').AvatarProps['gravatar'] | undefined} gravatar
* @param {import('./types.public').AvatarProps['uiAvatar'] | undefined} uiAvatar
* @returns {number}
*/
export function resolveSize(
Expand All @@ -98,8 +98,8 @@ export const DEFINITIVE_FALLBACK = 'https://www.gravatar.com/avatar?d=mp';
/**
* @package
* @param {string | undefined} src
* @param {import('./types').AvatarProps['gravatar'] | undefined} gravatar
* @param {import('./types').AvatarProps['uiAvatar'] | undefined} uiAvatar
* @param {import('./types.public').AvatarProps['gravatar'] | undefined} gravatar
* @param {import('./types.public').AvatarProps['uiAvatar'] | undefined} uiAvatar
* @param {string | undefined} fallback
* @returns {string[]}
*/
Expand Down Expand Up @@ -128,3 +128,4 @@ export function resolveSrc(

return [src, rGravatar, rUIAvatar, fallback].filter(nonNullableFilter);
}

2 changes: 2 additions & 0 deletions packages/avatar/src/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export { default as Avatar } from './Avatar.svelte';
export { gravatar, uiAvatar } from './avatar.helpers.js';
export * from './types.public.js'

Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,4 @@ export interface AvatarProps extends HTMLImgAttributes {
alt?: string;
img?: Snippet<[{ src: string; size: number; alt: string; sources: string[] }]>;
}

3 changes: 3 additions & 0 deletions packages/avatar/src/types.public.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/** to provide typing only, see types.public.d.ts */
export {};

0 comments on commit a2f8449

Please sign in to comment.