open-avatar 0.1.0

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.
@@ -0,0 +1,9 @@
1
+ import { ImgHTMLAttributes } from 'react';
2
+ import { AvatarOptions } from '../core/types';
3
+
4
+ export interface AvatarProps extends AvatarOptions, Omit<ImgHTMLAttributes<HTMLImageElement>, "src" | "width" | "height"> {
5
+ hash: string;
6
+ size?: number;
7
+ }
8
+ export declare function Avatar({ hash, shape, size, title, alt, ...imageProps }: AvatarProps): import("react/jsx-runtime").JSX.Element;
9
+ //# sourceMappingURL=Avatar.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Avatar.d.ts","sourceRoot":"","sources":["../../src/react/Avatar.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAE/C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAanD,MAAM,WAAW,WACf,SAAQ,aAAa,EACnB,IAAI,CAAC,iBAAiB,CAAC,gBAAgB,CAAC,EAAE,KAAK,GAAG,OAAO,GAAG,QAAQ,CAAC;IACvE,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,wBAAgB,MAAM,CAAC,EACrB,IAAI,EACJ,KAAK,EACL,IAAI,EACJ,KAAK,EACL,GAAG,EACH,GAAG,UAAU,EACd,EAAE,WAAW,2CAcb"}
@@ -0,0 +1,11 @@
1
+ import { HTMLAttributes } from 'react';
2
+ import { AvatarOptions, AvatarResult } from '../core/types';
3
+
4
+ export interface AvatarGridProps extends Omit<HTMLAttributes<HTMLDivElement>, "children"> {
5
+ count?: number;
6
+ size?: number;
7
+ shape?: AvatarOptions["shape"];
8
+ onBatchChange?: (avatars: AvatarResult[]) => void;
9
+ }
10
+ export declare function AvatarGrid({ count, size, shape, className, onBatchChange, ...gridProps }: AvatarGridProps): import("react/jsx-runtime").JSX.Element;
11
+ //# sourceMappingURL=AvatarGrid.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AvatarGrid.d.ts","sourceRoot":"","sources":["../../src/react/AvatarGrid.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAE5C,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AA0BjE,MAAM,WAAW,eAAgB,SAAQ,IAAI,CAAC,cAAc,CAAC,cAAc,CAAC,EAAE,UAAU,CAAC;IACvF,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC;IAC/B,aAAa,CAAC,EAAE,CAAC,OAAO,EAAE,YAAY,EAAE,KAAK,IAAI,CAAC;CACnD;AAED,wBAAgB,UAAU,CAAC,EACzB,KAAU,EACV,IAAS,EACT,KAAK,EACL,SAAS,EACT,aAAa,EACb,GAAG,SAAS,EACb,EAAE,eAAe,2CAgEjB"}
@@ -0,0 +1,5 @@
1
+ export { Avatar } from './Avatar';
2
+ export type { AvatarProps } from './Avatar';
3
+ export { AvatarGrid } from './AvatarGrid';
4
+ export type { AvatarGridProps } from './AvatarGrid';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,YAAY,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,YAAY,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './react/index';
2
+ //# sourceMappingURL=react.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../src/react.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC"}
package/dist/react.js ADDED
@@ -0,0 +1,98 @@
1
+ import { jsx as f, jsxs as x } from "react/jsx-runtime";
2
+ import { generateAvatarUrl as I, generateRandomAvatars as T, MAX_RANDOM_AVATAR_BATCH as b } from "./index.js";
3
+ import { useRef as l, useState as E, useEffect as A, useCallback as R } from "react";
4
+ const D = 96, F = 1024;
5
+ function G(t) {
6
+ return t === void 0 || !Number.isFinite(t) || t <= 0 ? D : Math.min(Math.max(Math.floor(t), 1), F);
7
+ }
8
+ function y({
9
+ hash: t,
10
+ shape: u,
11
+ size: o,
12
+ title: s,
13
+ alt: e,
14
+ ...m
15
+ }) {
16
+ const r = G(o), c = s ?? (e || t), n = e ?? s ?? t;
17
+ return /* @__PURE__ */ f(
18
+ "img",
19
+ {
20
+ ...m,
21
+ src: I(t, { shape: u, size: r, title: c }),
22
+ width: r,
23
+ height: r,
24
+ alt: n
25
+ }
26
+ );
27
+ }
28
+ const N = 96, Z = 1024;
29
+ function d(t, u) {
30
+ return Array.from(T(t, u));
31
+ }
32
+ function U(t) {
33
+ return !Number.isFinite(t) || t <= 0 ? 0 : Math.min(Math.floor(t), b);
34
+ }
35
+ function V(t) {
36
+ return !Number.isFinite(t) || t <= 0 ? N : Math.min(Math.max(Math.floor(t), 1), Z);
37
+ }
38
+ function L({
39
+ count: t = 10,
40
+ size: u = 96,
41
+ shape: o,
42
+ className: s,
43
+ onBatchChange: e,
44
+ ...m
45
+ }) {
46
+ const r = U(t), c = V(u), n = l(e), [v, M] = E(
47
+ () => d(r, { shape: o })
48
+ ), S = l(v), _ = l({ count: r, shape: o });
49
+ A(() => {
50
+ n.current = e;
51
+ }, [e]);
52
+ const z = R(() => {
53
+ var a;
54
+ const i = d(r, { shape: o });
55
+ M(i), (a = n.current) == null || a.call(n, i);
56
+ }, [r, o]);
57
+ return A(() => {
58
+ var i;
59
+ (i = n.current) == null || i.call(n, S.current);
60
+ }, []), A(() => {
61
+ var p;
62
+ const i = _.current;
63
+ if (i.count === r && i.shape === o)
64
+ return;
65
+ _.current = { count: r, shape: o };
66
+ const a = d(r, { shape: o });
67
+ M(a), (p = n.current) == null || p.call(n, a);
68
+ }, [r, o]), /* @__PURE__ */ x("div", { ...m, className: s, children: [
69
+ /* @__PURE__ */ x("button", { type: "button", onClick: z, children: [
70
+ "Random ",
71
+ r
72
+ ] }),
73
+ /* @__PURE__ */ f(
74
+ "div",
75
+ {
76
+ style: {
77
+ display: "grid",
78
+ gap: 8,
79
+ gridTemplateColumns: `repeat(auto-fill, minmax(${c}px, 1fr))`
80
+ },
81
+ children: v.map((i) => /* @__PURE__ */ f(
82
+ y,
83
+ {
84
+ hash: i.hash,
85
+ shape: o ?? i.shape,
86
+ size: c,
87
+ alt: ""
88
+ },
89
+ i.hash
90
+ ))
91
+ }
92
+ )
93
+ ] });
94
+ }
95
+ export {
96
+ y as Avatar,
97
+ L as AvatarGrid
98
+ };
@@ -0,0 +1,58 @@
1
+ import { PropType } from 'vue';
2
+ import { AvatarOptions } from '../core/types';
3
+
4
+ export interface AvatarProps extends AvatarOptions {
5
+ hash: string;
6
+ alt?: string;
7
+ }
8
+ export declare const Avatar: import('vue').DefineComponent<import('vue').ExtractPropTypes<{
9
+ hash: {
10
+ type: StringConstructor;
11
+ required: true;
12
+ };
13
+ shape: {
14
+ type: PropType<AvatarOptions["shape"]>;
15
+ default: string;
16
+ };
17
+ size: {
18
+ type: NumberConstructor;
19
+ default: number;
20
+ };
21
+ title: {
22
+ type: StringConstructor;
23
+ default: undefined;
24
+ };
25
+ alt: {
26
+ type: StringConstructor;
27
+ default: undefined;
28
+ };
29
+ }>, () => import('vue').VNode<import('vue').RendererNode, import('vue').RendererElement, {
30
+ [key: string]: any;
31
+ }>, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<{
32
+ hash: {
33
+ type: StringConstructor;
34
+ required: true;
35
+ };
36
+ shape: {
37
+ type: PropType<AvatarOptions["shape"]>;
38
+ default: string;
39
+ };
40
+ size: {
41
+ type: NumberConstructor;
42
+ default: number;
43
+ };
44
+ title: {
45
+ type: StringConstructor;
46
+ default: undefined;
47
+ };
48
+ alt: {
49
+ type: StringConstructor;
50
+ default: undefined;
51
+ };
52
+ }>> & Readonly<{}>, {
53
+ size: number;
54
+ shape: import('..').AvatarShape | undefined;
55
+ alt: string;
56
+ title: string;
57
+ }, {}, {}, {}, string, import('vue').ComponentProvideOptions, true, {}, any>;
58
+ //# sourceMappingURL=Avatar.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Avatar.d.ts","sourceRoot":"","sources":["../../src/vue/Avatar.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,KAAK,CAAC;AAEpC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAanD,MAAM,WAAW,WAAY,SAAQ,aAAa;IAChD,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,eAAO,MAAM,MAAM;;;;;;cASG,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;;;;;;;;;;;;;;;;;;;;;;;cAAhC,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;;;;;;;;;;;;;;;;;;;;4EAmCpD,CAAC"}
@@ -0,0 +1,46 @@
1
+ import { PropType } from 'vue';
2
+ import { AvatarOptions, AvatarResult } from '../core/types';
3
+
4
+ export interface AvatarGridProps {
5
+ count?: number;
6
+ size?: number;
7
+ shape?: AvatarOptions["shape"];
8
+ }
9
+ export declare const AvatarGrid: import('vue').DefineComponent<import('vue').ExtractPropTypes<{
10
+ count: {
11
+ type: NumberConstructor;
12
+ default: number;
13
+ };
14
+ size: {
15
+ type: NumberConstructor;
16
+ default: number;
17
+ };
18
+ shape: {
19
+ type: PropType<AvatarOptions["shape"]>;
20
+ default: string;
21
+ };
22
+ }>, () => import('vue').VNode<import('vue').RendererNode, import('vue').RendererElement, {
23
+ [key: string]: any;
24
+ }>, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {
25
+ batchChange: (_avatars: AvatarResult[]) => true;
26
+ }, string, import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<{
27
+ count: {
28
+ type: NumberConstructor;
29
+ default: number;
30
+ };
31
+ size: {
32
+ type: NumberConstructor;
33
+ default: number;
34
+ };
35
+ shape: {
36
+ type: PropType<AvatarOptions["shape"]>;
37
+ default: string;
38
+ };
39
+ }>> & Readonly<{
40
+ onBatchChange?: ((_avatars: AvatarResult[]) => any) | undefined;
41
+ }>, {
42
+ size: number;
43
+ shape: import('..').AvatarShape | undefined;
44
+ count: number;
45
+ }, {}, {}, {}, string, import('vue').ComponentProvideOptions, true, {}, any>;
46
+ //# sourceMappingURL=AvatarGrid.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AvatarGrid.d.ts","sourceRoot":"","sources":["../../src/vue/AvatarGrid.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,KAAK,CAAC;AAEpC,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AA0BjE,MAAM,WAAW,eAAe;IAC9B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC;CAChC;AAED,eAAO,MAAM,UAAU;;;;;;;;;;cAYD,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;;;;;;4BAK1B,YAAY,EAAE;;;;;;;;;;;cALpB,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;;;;;;;;;4EAoDpD,CAAC"}
@@ -0,0 +1,5 @@
1
+ export { Avatar } from './Avatar';
2
+ export type { AvatarProps } from './Avatar';
3
+ export { AvatarGrid } from './AvatarGrid';
4
+ export type { AvatarGridProps } from './AvatarGrid';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/vue/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,YAAY,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,YAAY,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC"}
package/dist/vue.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './vue/index';
2
+ //# sourceMappingURL=vue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vue.d.ts","sourceRoot":"","sources":["../src/vue.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC"}
package/dist/vue.js ADDED
@@ -0,0 +1,116 @@
1
+ import { defineComponent as s, h as i, computed as o, ref as c, watch as A } from "vue";
2
+ import { generateAvatarUrl as f, MAX_RANDOM_AVATAR_BATCH as v, generateRandomAvatars as g } from "./index.js";
3
+ const m = 96, p = 1024;
4
+ function y(t) {
5
+ return t === void 0 || !Number.isFinite(t) || t <= 0 ? m : Math.min(Math.max(Math.floor(t), 1), p);
6
+ }
7
+ const S = s({
8
+ name: "OpenAvatar",
9
+ inheritAttrs: !1,
10
+ props: {
11
+ hash: {
12
+ type: String,
13
+ required: !0
14
+ },
15
+ shape: {
16
+ type: String,
17
+ default: "rounded-square"
18
+ },
19
+ size: {
20
+ type: Number,
21
+ default: m
22
+ },
23
+ title: {
24
+ type: String,
25
+ default: void 0
26
+ },
27
+ alt: {
28
+ type: String,
29
+ default: void 0
30
+ }
31
+ },
32
+ setup(t, { attrs: a }) {
33
+ return () => {
34
+ const r = y(t.size), n = t.title ?? t.alt ?? t.hash, u = t.alt ?? t.title ?? t.hash;
35
+ return i("img", {
36
+ ...a,
37
+ src: f(t.hash, {
38
+ shape: t.shape,
39
+ size: r,
40
+ title: n
41
+ }),
42
+ width: r,
43
+ height: r,
44
+ alt: u
45
+ });
46
+ };
47
+ }
48
+ }), d = 96, M = 1024;
49
+ function _(t, a) {
50
+ return Array.from(g(t, a));
51
+ }
52
+ function b(t) {
53
+ return !Number.isFinite(t) || t <= 0 ? 0 : Math.min(Math.floor(t), v);
54
+ }
55
+ function z(t) {
56
+ return !Number.isFinite(t) || t <= 0 ? d : Math.min(Math.max(Math.floor(t), 1), M);
57
+ }
58
+ const T = s({
59
+ name: "OpenAvatarGrid",
60
+ props: {
61
+ count: {
62
+ type: Number,
63
+ default: 10
64
+ },
65
+ size: {
66
+ type: Number,
67
+ default: d
68
+ },
69
+ shape: {
70
+ type: String,
71
+ default: "rounded-square"
72
+ }
73
+ },
74
+ emits: {
75
+ batchChange: (t) => !0
76
+ },
77
+ setup(t, { attrs: a, emit: r }) {
78
+ const n = o(() => b(t.count)), u = o(() => z(t.size)), h = c([]), l = () => {
79
+ const e = _(n.value, { shape: t.shape });
80
+ h.value = e, r("batchChange", e);
81
+ };
82
+ return A([n, () => t.shape], l, { immediate: !0 }), () => i("div", a, [
83
+ i(
84
+ "button",
85
+ {
86
+ type: "button",
87
+ onClick: l
88
+ },
89
+ `Random ${n.value}`
90
+ ),
91
+ i(
92
+ "div",
93
+ {
94
+ style: {
95
+ display: "grid",
96
+ gap: "8px",
97
+ gridTemplateColumns: `repeat(auto-fill, minmax(${u.value}px, 1fr))`
98
+ }
99
+ },
100
+ h.value.map(
101
+ (e) => i(S, {
102
+ key: e.hash,
103
+ hash: e.hash,
104
+ shape: t.shape ?? e.shape,
105
+ size: u.value,
106
+ alt: ""
107
+ })
108
+ )
109
+ )
110
+ ]);
111
+ }
112
+ });
113
+ export {
114
+ S as Avatar,
115
+ T as AvatarGrid
116
+ };
package/package.json ADDED
@@ -0,0 +1,88 @@
1
+ {
2
+ "name": "open-avatar",
3
+ "version": "0.1.0",
4
+ "description": "Deterministic SVG avatar generator with React and Vue components.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "author": "SMICES",
8
+ "homepage": "https://github.com/smices/open-avatar#readme",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/smices/open-avatar.git"
12
+ },
13
+ "bugs": {
14
+ "url": "https://github.com/smices/open-avatar/issues"
15
+ },
16
+ "keywords": [
17
+ "avatar",
18
+ "svg",
19
+ "generator",
20
+ "react",
21
+ "vue",
22
+ "dicebear",
23
+ "openavatar"
24
+ ],
25
+ "sideEffects": false,
26
+ "files": [
27
+ "dist",
28
+ "README.md",
29
+ "LICENSE",
30
+ "THIRD_PARTY_NOTICES.md"
31
+ ],
32
+ "main": "./dist/index.js",
33
+ "module": "./dist/index.js",
34
+ "types": "./dist/index.d.ts",
35
+ "scripts": {
36
+ "dev": "vite --host 0.0.0.0",
37
+ "test": "vitest run",
38
+ "test:watch": "vitest",
39
+ "build": "tsc -p tsconfig.json --noEmit && vite build",
40
+ "prepublishOnly": "npm test && npm run build",
41
+ "preview": "vite preview --host 0.0.0.0"
42
+ },
43
+ "exports": {
44
+ ".": {
45
+ "types": "./dist/index.d.ts",
46
+ "import": "./dist/index.js"
47
+ },
48
+ "./react": {
49
+ "types": "./dist/react.d.ts",
50
+ "import": "./dist/react.js"
51
+ },
52
+ "./vue": {
53
+ "types": "./dist/vue.d.ts",
54
+ "import": "./dist/vue.js"
55
+ }
56
+ },
57
+ "peerDependencies": {
58
+ "react": ">=18",
59
+ "vue": ">=3"
60
+ },
61
+ "peerDependenciesMeta": {
62
+ "react": {
63
+ "optional": true
64
+ },
65
+ "vue": {
66
+ "optional": true
67
+ }
68
+ },
69
+ "devDependencies": {
70
+ "@testing-library/react": "^15.0.0",
71
+ "@vitejs/plugin-react": "^4.0.0",
72
+ "@vitejs/plugin-vue": "^5.0.0",
73
+ "@vue/test-utils": "^2.4.0",
74
+ "jsdom": "^24.1.0",
75
+ "lucide-react": "^1.16.0",
76
+ "react": "^18.3.0",
77
+ "react-dom": "^18.3.0",
78
+ "typescript": "^5.5.0",
79
+ "vite": "^5.4.0",
80
+ "vite-plugin-dts": "^3.9.0",
81
+ "vitest": "^2.0.0",
82
+ "vue": "^3.4.0"
83
+ },
84
+ "dependencies": {
85
+ "@dicebear/avataaars": "^9.2.2",
86
+ "@dicebear/core": "^9.2.2"
87
+ }
88
+ }