@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 CHANGED
@@ -1,21 +1,42 @@
1
- MIT License
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
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
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.
@@ -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
- __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
7
  var __export = (target, all) => {
8
- for (var name in all) __defProp(target, name, {
9
- get: all[name],
10
- enumerable: !0
11
- });
12
- },
13
- __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
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
- return to;
19
- };
19
+ }
20
+ return to;
21
+ };
20
22
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
26
- value: mod,
27
- enumerable: !0
28
- }) : target, mod)),
29
- __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
30
- value: !0
31
- }), mod);
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 import_gui_core = require("@hanzogui/core"),
43
- import_gui_create_context = require("@hanzogui/create-context"),
44
- import_gui_helpers = require("@hanzogui/helpers"),
45
- import_gui_image = require("@hanzogui/image"),
46
- import_gui_shapes = require("@hanzogui/shapes"),
47
- import_gui_stacks = require("@hanzogui/stacks"),
48
- React = __toESM(require("react"), 1),
49
- import_jsx_runtime = require("react/jsx-runtime");
50
- const AVATAR_NAME = "Avatar",
51
- [createAvatarContext, createAvatarScope] = (0, import_gui_create_context.createContextScope)(AVATAR_NAME),
52
- [AvatarProvider, useAvatarContext] = createAvatarContext(AVATAR_NAME),
53
- IMAGE_NAME = "AvatarImage",
54
- AvatarImage = React.forwardRef((props, forwardedRef) => {
55
- const {
56
- __scopeAvatar,
57
- src,
58
- source,
59
- onLoadingStatusChange = () => {},
60
- ...imageProps
61
- } = props,
62
- context = useAvatarContext(IMAGE_NAME, __scopeAvatar),
63
- [status, setStatus] = React.useState("idle"),
64
- shapeSize = (0, import_gui_core.getVariableValue)((0, import_gui_shapes.getShapeSize)(context.size,
65
- // @ts-expect-error
66
- {
67
- tokens: (0, import_gui_core.getTokens)()
68
- })?.width),
69
- resolvedSrc = src || (source && typeof source == "object" && "uri" in source ? source.uri : source);
70
- return React.useEffect(() => {
71
- setStatus(resolvedSrc ? "idle" : "error");
72
- }, [resolvedSrc]), React.useEffect(() => {
73
- onLoadingStatusChange(status), context.onImageLoadingStatusChange(status);
74
- }, [status]), resolvedSrc ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_gui_stacks.YStack, {
75
- fullscreen: !0,
76
- zIndex: 1,
77
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_gui_image.Image, {
78
- position: "absolute",
79
- top: 0,
80
- left: 0,
81
- right: 0,
82
- bottom: 0,
83
- objectFit: "cover",
84
- ...(typeof shapeSize == "number" && !Number.isNaN(shapeSize) && {
85
- width: shapeSize,
86
- height: shapeSize
87
- }),
88
- ...imageProps,
89
- ref: forwardedRef,
90
- src: resolvedSrc,
91
- onError: () => {
92
- setStatus("error");
93
- },
94
- onLoad: () => {
95
- setStatus("loaded");
96
- }
97
- })
98
- }) : null;
99
- });
100
- AvatarImage.displayName = IMAGE_NAME;
101
- const FALLBACK_NAME = "AvatarFallback",
102
- AvatarFallbackFrame = (0, import_gui_core.styled)(import_gui_stacks.YStack, {
103
- name: FALLBACK_NAME,
104
- position: "absolute",
105
- fullscreen: !0,
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
- }, [delayMs]), canRender && context.imageLoadingStatus !== "loaded" ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(AvatarFallbackFrame, {
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, import_gui_core.styled)(import_gui_shapes.Square, {
128
- name: AVATAR_NAME,
129
- position: "relative",
130
- overflow: "hidden"
131
- }),
132
- Avatar = (0, import_gui_helpers.withStaticProperties)(React.forwardRef((props, forwardedRef) => {
133
- const {
134
- __scopeAvatar,
135
- size = "$true",
136
- ...avatarProps
137
- } = props,
138
- [imageLoadingStatus, setImageLoadingStatus] = React.useState("idle");
139
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(AvatarProvider, {
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
- scope: __scopeAvatar,
142
- imageLoadingStatus,
143
- onImageLoadingStatusChange: setImageLoadingStatus,
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;