@hanzogui/avatar 3.0.2 → 7.3.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.
- package/LICENSE +40 -19
- package/dist/cjs/Avatar.cjs +142 -129
- package/dist/cjs/Avatar.native.js +153 -140
- package/dist/cjs/Avatar.native.js.map +1 -1
- package/dist/cjs/index.cjs +7 -5
- package/dist/cjs/index.native.js +7 -5
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/esm/Avatar.mjs +109 -98
- package/dist/esm/Avatar.mjs.map +1 -1
- package/dist/esm/Avatar.native.js +120 -109
- package/dist/esm/Avatar.native.js.map +1 -1
- package/dist/jsx/Avatar.mjs +109 -98
- package/dist/jsx/Avatar.mjs.map +1 -1
- package/dist/jsx/Avatar.native.js +153 -140
- package/dist/jsx/Avatar.native.js.map +1 -1
- package/dist/jsx/index.native.js +7 -5
- package/package.json +16 -14
- package/types/Avatar.d.ts +27 -27
- package/types/Avatar.d.ts.map +1 -0
- package/types/index.d.ts.map +1 -0
package/LICENSE
CHANGED
|
@@ -1,21 +1,42 @@
|
|
|
1
|
-
|
|
1
|
+
BSD 3-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026-present, Hanzo AI, Inc.
|
|
4
|
+
|
|
5
|
+
Portions of this software are derived from upstream code originally licensed under
|
|
6
|
+
the MIT License, with the following copyright notices retained per its terms:
|
|
2
7
|
|
|
3
8
|
Copyright (c) 2020 Nate Wienert
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
9
|
+
Copyright (c) 2015-present, Nicolas Gallagher.
|
|
10
|
+
Copyright (c) 2015-present, Facebook, Inc.
|
|
11
|
+
Copyright (c) 2021 Radix
|
|
12
|
+
Copyright (c) 2017 Carmelo Pullara
|
|
13
|
+
Copyright (c) 2018 Framer B.V.
|
|
14
|
+
Copyright (c) 2022 WorkOS
|
|
15
|
+
|
|
16
|
+
All rights reserved.
|
|
17
|
+
|
|
18
|
+
Redistribution and use in source and binary forms, with or without
|
|
19
|
+
modification, are permitted provided that the following conditions are met:
|
|
20
|
+
|
|
21
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
22
|
+
list of conditions and the following disclaimer.
|
|
23
|
+
|
|
24
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
25
|
+
this list of conditions and the following disclaimer in the documentation
|
|
26
|
+
and/or other materials provided with the distribution.
|
|
27
|
+
|
|
28
|
+
3. Neither the name of the copyright holder nor the names of its contributors
|
|
29
|
+
may be used to endorse or promote products derived from this software
|
|
30
|
+
without specific prior written permission.
|
|
31
|
+
|
|
32
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
33
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
34
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
35
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
36
|
+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
37
|
+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
38
|
+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
39
|
+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
40
|
+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
41
|
+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
42
|
+
POSSIBILITY OF SUCH DAMAGE.
|
package/dist/cjs/Avatar.cjs
CHANGED
|
@@ -2,33 +2,35 @@ var __create = Object.create;
|
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf
|
|
6
|
-
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
7
|
var __export = (target, all) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: true
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
15
16
|
get: () => from[key],
|
|
16
17
|
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
18
|
});
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
20
22
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
23
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
24
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
25
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
26
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
27
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
28
|
+
value: mod,
|
|
29
|
+
enumerable: true
|
|
30
|
+
}) : target, mod));
|
|
31
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
32
|
+
value: true
|
|
33
|
+
}), mod);
|
|
32
34
|
var Avatar_exports = {};
|
|
33
35
|
__export(Avatar_exports, {
|
|
34
36
|
Avatar: () => Avatar,
|
|
@@ -39,116 +41,127 @@ __export(Avatar_exports, {
|
|
|
39
41
|
createAvatarScope: () => createAvatarScope
|
|
40
42
|
});
|
|
41
43
|
module.exports = __toCommonJS(Avatar_exports);
|
|
42
|
-
var
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const AVATAR_NAME = "Avatar"
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
})
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
zIndex: 0
|
|
107
|
-
}),
|
|
108
|
-
AvatarFallback = AvatarFallbackFrame.styleable((props, forwardedRef) => {
|
|
109
|
-
const {
|
|
110
|
-
__scopeAvatar,
|
|
111
|
-
delayMs,
|
|
112
|
-
...fallbackProps
|
|
113
|
-
} = props,
|
|
114
|
-
context = useAvatarContext(FALLBACK_NAME, __scopeAvatar),
|
|
115
|
-
[canRender, setCanRender] = React.useState(delayMs === void 0);
|
|
116
|
-
return React.useEffect(() => {
|
|
117
|
-
if (delayMs !== void 0) {
|
|
118
|
-
const timerId = setTimeout(() => setCanRender(!0), delayMs);
|
|
119
|
-
return () => clearTimeout(timerId);
|
|
44
|
+
var import_core = require("@hanzogui/core");
|
|
45
|
+
var import_create_context = require("@hanzogui/create-context");
|
|
46
|
+
var import_helpers = require("@hanzogui/helpers");
|
|
47
|
+
var import_image = require("@hanzogui/image");
|
|
48
|
+
var import_shapes = require("@hanzogui/shapes");
|
|
49
|
+
var import_stacks = require("@hanzogui/stacks");
|
|
50
|
+
var React = __toESM(require("react"), 1);
|
|
51
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
52
|
+
const AVATAR_NAME = "Avatar";
|
|
53
|
+
const [createAvatarContext, createAvatarScope] = (0, import_create_context.createContextScope)(AVATAR_NAME);
|
|
54
|
+
const [AvatarProvider, useAvatarContext] = createAvatarContext(AVATAR_NAME);
|
|
55
|
+
const IMAGE_NAME = "AvatarImage";
|
|
56
|
+
const AvatarImage = React.forwardRef((props, forwardedRef) => {
|
|
57
|
+
const {
|
|
58
|
+
__scopeAvatar,
|
|
59
|
+
src,
|
|
60
|
+
source,
|
|
61
|
+
onLoadingStatusChange = () => {},
|
|
62
|
+
...imageProps
|
|
63
|
+
} = props;
|
|
64
|
+
const context = useAvatarContext(IMAGE_NAME, __scopeAvatar);
|
|
65
|
+
const [status, setStatus] = React.useState("idle");
|
|
66
|
+
const shapeSize = (0, import_core.getVariableValue)((0, import_shapes.getShapeSize)(context.size,
|
|
67
|
+
// @ts-expect-error
|
|
68
|
+
{
|
|
69
|
+
tokens: (0, import_core.getTokens)()
|
|
70
|
+
})?.width);
|
|
71
|
+
const resolvedSrc = src || (source && typeof source === "object" && "uri" in source ? source.uri : source);
|
|
72
|
+
React.useEffect(() => {
|
|
73
|
+
if (!resolvedSrc) {
|
|
74
|
+
setStatus("error");
|
|
75
|
+
} else {
|
|
76
|
+
setStatus("idle");
|
|
77
|
+
}
|
|
78
|
+
}, [resolvedSrc]);
|
|
79
|
+
React.useEffect(() => {
|
|
80
|
+
onLoadingStatusChange(status);
|
|
81
|
+
context.onImageLoadingStatusChange(status);
|
|
82
|
+
}, [status]);
|
|
83
|
+
if (!resolvedSrc) {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_stacks.YStack, {
|
|
87
|
+
fullscreen: true,
|
|
88
|
+
zIndex: 1,
|
|
89
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_image.Image, {
|
|
90
|
+
position: "absolute",
|
|
91
|
+
top: 0,
|
|
92
|
+
left: 0,
|
|
93
|
+
right: 0,
|
|
94
|
+
bottom: 0,
|
|
95
|
+
objectFit: "cover",
|
|
96
|
+
...(typeof shapeSize === "number" && !Number.isNaN(shapeSize) && {
|
|
97
|
+
width: shapeSize,
|
|
98
|
+
height: shapeSize
|
|
99
|
+
}),
|
|
100
|
+
...imageProps,
|
|
101
|
+
ref: forwardedRef,
|
|
102
|
+
src: resolvedSrc,
|
|
103
|
+
onError: () => {
|
|
104
|
+
setStatus("error");
|
|
105
|
+
},
|
|
106
|
+
onLoad: () => {
|
|
107
|
+
setStatus("loaded");
|
|
120
108
|
}
|
|
121
|
-
}
|
|
122
|
-
...fallbackProps,
|
|
123
|
-
ref: forwardedRef
|
|
124
|
-
}) : null;
|
|
109
|
+
})
|
|
125
110
|
});
|
|
111
|
+
});
|
|
112
|
+
AvatarImage.displayName = IMAGE_NAME;
|
|
113
|
+
const FALLBACK_NAME = "AvatarFallback";
|
|
114
|
+
const AvatarFallbackFrame = (0, import_core.styled)(import_stacks.YStack, {
|
|
115
|
+
name: FALLBACK_NAME,
|
|
116
|
+
position: "absolute",
|
|
117
|
+
fullscreen: true,
|
|
118
|
+
zIndex: 0
|
|
119
|
+
});
|
|
120
|
+
const AvatarFallback = AvatarFallbackFrame.styleable((props, forwardedRef) => {
|
|
121
|
+
const {
|
|
122
|
+
__scopeAvatar,
|
|
123
|
+
delayMs,
|
|
124
|
+
...fallbackProps
|
|
125
|
+
} = props;
|
|
126
|
+
const context = useAvatarContext(FALLBACK_NAME, __scopeAvatar);
|
|
127
|
+
const [canRender, setCanRender] = React.useState(delayMs === void 0);
|
|
128
|
+
React.useEffect(() => {
|
|
129
|
+
if (delayMs !== void 0) {
|
|
130
|
+
const timerId = setTimeout(() => setCanRender(true), delayMs);
|
|
131
|
+
return () => clearTimeout(timerId);
|
|
132
|
+
}
|
|
133
|
+
}, [delayMs]);
|
|
134
|
+
return canRender && context.imageLoadingStatus !== "loaded" ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(AvatarFallbackFrame, {
|
|
135
|
+
...fallbackProps,
|
|
136
|
+
ref: forwardedRef
|
|
137
|
+
}) : null;
|
|
138
|
+
});
|
|
126
139
|
AvatarFallback.displayName = FALLBACK_NAME;
|
|
127
|
-
const AvatarFrame = (0,
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
+
const AvatarFrame = (0, import_core.styled)(import_shapes.Square, {
|
|
141
|
+
name: AVATAR_NAME,
|
|
142
|
+
position: "relative",
|
|
143
|
+
overflow: "hidden"
|
|
144
|
+
});
|
|
145
|
+
const Avatar = (0, import_helpers.withStaticProperties)(React.forwardRef((props, forwardedRef) => {
|
|
146
|
+
const {
|
|
147
|
+
__scopeAvatar,
|
|
148
|
+
size = "$true",
|
|
149
|
+
...avatarProps
|
|
150
|
+
} = props;
|
|
151
|
+
const [imageLoadingStatus, setImageLoadingStatus] = React.useState("idle");
|
|
152
|
+
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(AvatarProvider, {
|
|
153
|
+
size,
|
|
154
|
+
scope: __scopeAvatar,
|
|
155
|
+
imageLoadingStatus,
|
|
156
|
+
onImageLoadingStatusChange: setImageLoadingStatus,
|
|
157
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(AvatarFrame, {
|
|
140
158
|
size,
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(AvatarFrame, {
|
|
145
|
-
size,
|
|
146
|
-
...avatarProps,
|
|
147
|
-
ref: forwardedRef
|
|
148
|
-
})
|
|
149
|
-
});
|
|
150
|
-
}), {
|
|
151
|
-
Image: AvatarImage,
|
|
152
|
-
Fallback: AvatarFallback
|
|
159
|
+
...avatarProps,
|
|
160
|
+
ref: forwardedRef
|
|
161
|
+
})
|
|
153
162
|
});
|
|
163
|
+
}), {
|
|
164
|
+
Image: AvatarImage,
|
|
165
|
+
Fallback: AvatarFallback
|
|
166
|
+
});
|
|
154
167
|
Avatar.displayName = AVATAR_NAME;
|