fn-ui-avatars 1.0.1 → 1.0.3
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/README.md +16 -1
- package/dist/index.cjs +2 -2
- package/dist/index.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -35,6 +35,20 @@ Add `data-name` to any `<img>` element and call `loadAvatars()` after the DOM is
|
|
|
35
35
|
</script>
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
+
### Via CDN (No bundler required)
|
|
39
|
+
|
|
40
|
+
If you are not using a build tool, you can import it directly from unpkg:
|
|
41
|
+
|
|
42
|
+
```html
|
|
43
|
+
<script type="module">
|
|
44
|
+
import { loadAvatars } from 'https://unpkg.com/fn-ui-avatars/dist/index.js';
|
|
45
|
+
|
|
46
|
+
document.addEventListener('DOMContentLoaded', () => {
|
|
47
|
+
loadAvatars();
|
|
48
|
+
});
|
|
49
|
+
</script>
|
|
50
|
+
```
|
|
51
|
+
|
|
38
52
|
### Generate a single URL
|
|
39
53
|
|
|
40
54
|
```js
|
|
@@ -83,7 +97,7 @@ Returns a UI-Avatars URL string for the given name.
|
|
|
83
97
|
| `fontSize` | `number` | `0.33` | Font size ratio (`0.1`–`1`). |
|
|
84
98
|
| `length` | `number` | `2` | Number of initials to display. |
|
|
85
99
|
| `rounded` | `boolean` | `true` | Circular avatar. |
|
|
86
|
-
| `color` | `string` | `'fff'` | Text color (hex without `#`). |
|
|
100
|
+
| `color` | `string` | `'fff'` | Text color (hex without `#`). Automatically outputs 'fff' or '000' for best contrast, unless overridden. |
|
|
87
101
|
| `format` | `string` | `'svg'` | Image format: `'svg'` or `'png'`. |
|
|
88
102
|
| `baseUrl` | `string` | `'https://eu.ui-avatars.com/api/'` | Custom API base URL. |
|
|
89
103
|
|
|
@@ -122,6 +136,7 @@ Each name is hashed with a simple djb2-style algorithm, and the resulting intege
|
|
|
122
136
|
|
|
123
137
|
- The same name **always** gets the same color.
|
|
124
138
|
- Different names get visually distinct colors.
|
|
139
|
+
- The text color automatically adapts to be legible on light or dark backgrounds.
|
|
125
140
|
- No configuration or storage required.
|
|
126
141
|
|
|
127
142
|
---
|
package/dist/index.cjs
CHANGED
|
@@ -33,7 +33,7 @@ var DEFAULT_OPTIONS = {
|
|
|
33
33
|
rounded: true,
|
|
34
34
|
color: "fff",
|
|
35
35
|
format: "svg",
|
|
36
|
-
baseUrl: "https://
|
|
36
|
+
baseUrl: "https://ui-avatars.com/api/"
|
|
37
37
|
};
|
|
38
38
|
function hashCode(str) {
|
|
39
39
|
let hash = 0;
|
|
@@ -73,7 +73,7 @@ function getAvatarUrl(name, options = {}) {
|
|
|
73
73
|
].join("&");
|
|
74
74
|
return `${opts.baseUrl}?${query}`;
|
|
75
75
|
}
|
|
76
|
-
function loadAvatars(selector = "img.fn-ui-
|
|
76
|
+
function loadAvatars(selector = "img.fn-ui-avatars", options = {}) {
|
|
77
77
|
if (typeof document === "undefined") {
|
|
78
78
|
throw new Error("fn-ui-avatars: loadAvatars() requires a browser environment.");
|
|
79
79
|
}
|
package/dist/index.js
CHANGED
|
@@ -6,7 +6,7 @@ var DEFAULT_OPTIONS = {
|
|
|
6
6
|
rounded: true,
|
|
7
7
|
color: "fff",
|
|
8
8
|
format: "svg",
|
|
9
|
-
baseUrl: "https://
|
|
9
|
+
baseUrl: "https://ui-avatars.com/api/"
|
|
10
10
|
};
|
|
11
11
|
function hashCode(str) {
|
|
12
12
|
let hash = 0;
|
|
@@ -46,7 +46,7 @@ function getAvatarUrl(name, options = {}) {
|
|
|
46
46
|
].join("&");
|
|
47
47
|
return `${opts.baseUrl}?${query}`;
|
|
48
48
|
}
|
|
49
|
-
function loadAvatars(selector = "img.fn-ui-
|
|
49
|
+
function loadAvatars(selector = "img.fn-ui-avatars", options = {}) {
|
|
50
50
|
if (typeof document === "undefined") {
|
|
51
51
|
throw new Error("fn-ui-avatars: loadAvatars() requires a browser environment.");
|
|
52
52
|
}
|