@tamagui/avatar 2.7.7 → 3.0.0-beta.643.1

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.
@@ -1,3 +1,4 @@
1
+
1
2
  var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -5,40 +6,33 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
5
6
  var __getProtoOf = Object.getPrototypeOf;
6
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
8
  var __export = (target, all) => {
8
- for (var name in all) __defProp(target, name, {
9
- get: all[name],
10
- enumerable: true
11
- });
9
+ for (var name in all) __defProp(target, name, {
10
+ get: all[name],
11
+ enumerable: true
12
+ });
12
13
  };
13
14
  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, {
16
- get: () => from[key],
17
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
18
- });
19
- }
20
- return to;
15
+ if (from && typeof from === "object" || typeof from === "function") {
16
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
17
+ get: () => from[key],
18
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
19
+ });
20
+ }
21
+ return to;
21
22
  };
22
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
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
23
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
24
+ value: mod,
25
+ enumerable: true
30
26
  }) : target, mod));
31
- var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
32
- value: true
33
- }), mod);
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
34
28
  var Avatar_exports = {};
35
29
  __export(Avatar_exports, {
36
- Avatar: () => Avatar,
37
- AvatarFallback: () => AvatarFallback,
38
- AvatarFallbackFrame: () => AvatarFallbackFrame,
39
- AvatarFrame: () => AvatarFrame,
40
- AvatarImage: () => AvatarImage,
41
- createAvatarScope: () => createAvatarScope
30
+ Avatar: () => Avatar,
31
+ AvatarFallback: () => AvatarFallback,
32
+ AvatarFallbackFrame: () => AvatarFallbackFrame,
33
+ AvatarFrame: () => AvatarFrame,
34
+ AvatarImage: () => AvatarImage,
35
+ createAvatarScope: () => createAvatarScope
42
36
  });
43
37
  module.exports = __toCommonJS(Avatar_exports);
44
38
  var import_core = require("@tamagui/core");
@@ -53,108 +47,95 @@ const AVATAR_NAME = "Avatar";
53
47
  const [createAvatarContext, createAvatarScope] = (0, import_create_context.createContextScope)(AVATAR_NAME);
54
48
  const [AvatarProvider, useAvatarContext] = createAvatarContext(AVATAR_NAME);
55
49
  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 resolvedSrc = src || (source && typeof source === "object" && "uri" in source ? source.uri : source);
67
- React.useEffect(() => {
68
- if (!resolvedSrc) {
69
- setStatus("error");
70
- } else {
71
- setStatus("idle");
72
- }
73
- }, [resolvedSrc]);
74
- React.useEffect(() => {
75
- onLoadingStatusChange(status);
76
- context.onImageLoadingStatusChange(status);
77
- }, [status]);
78
- if (!resolvedSrc) {
79
- return null;
80
- }
81
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_stacks.YStack, {
82
- fullscreen: true,
83
- zIndex: 1,
84
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_image.Image, {
85
- position: "absolute",
86
- top: 0,
87
- left: 0,
88
- right: 0,
89
- bottom: 0,
90
- objectFit: "cover",
91
- width: "100%",
92
- height: "100%",
93
- ...imageProps,
94
- ref: forwardedRef,
95
- src: resolvedSrc,
96
- onError: () => {
97
- setStatus("error");
98
- },
99
- onLoad: () => {
100
- setStatus("loaded");
101
- }
102
- })
103
- });
50
+ const AvatarImage = (0, import_core.createRefComponent)((props, forwardedRef) => {
51
+ const { __scopeAvatar, src, source, onLoadingStatusChange = () => {}, ...imageProps } = props;
52
+ const context = useAvatarContext(IMAGE_NAME, __scopeAvatar);
53
+ const [status, setStatus] = React.useState("idle");
54
+ const resolvedSrc = src || (source && typeof source === "object" && "uri" in source ? source.uri : source);
55
+ React.useEffect(() => {
56
+ if (!resolvedSrc) {
57
+ setStatus("error");
58
+ } else {
59
+ setStatus("idle");
60
+ }
61
+ }, [resolvedSrc]);
62
+ React.useEffect(() => {
63
+ onLoadingStatusChange(status);
64
+ context.onImageLoadingStatusChange(status);
65
+ }, [status]);
66
+ if (!resolvedSrc) {
67
+ return null;
68
+ }
69
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stacks.YStack, {
70
+ position: "absolute",
71
+ inset: 0,
72
+ zIndex: 1,
73
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_image.Image, {
74
+ position: "absolute",
75
+ top: 0,
76
+ left: 0,
77
+ right: 0,
78
+ bottom: 0,
79
+ objectFit: "cover",
80
+ width: "100%",
81
+ height: "100%",
82
+ ...imageProps,
83
+ ref: forwardedRef,
84
+ src: resolvedSrc,
85
+ onError: () => {
86
+ setStatus("error");
87
+ },
88
+ onLoad: () => {
89
+ setStatus("loaded");
90
+ }
91
+ })
92
+ });
104
93
  });
105
94
  AvatarImage.displayName = IMAGE_NAME;
106
95
  const FALLBACK_NAME = "AvatarFallback";
107
96
  const AvatarFallbackFrame = (0, import_core.styled)(import_stacks.YStack, {
108
- name: FALLBACK_NAME,
109
- position: "absolute",
110
- fullscreen: true,
111
- zIndex: 0
97
+ displayName: FALLBACK_NAME,
98
+ position: "absolute",
99
+ inset: 0,
100
+ zIndex: 0
112
101
  });
113
- const AvatarFallback = AvatarFallbackFrame.styleable((props, forwardedRef) => {
114
- const {
115
- __scopeAvatar,
116
- delayMs,
117
- ...fallbackProps
118
- } = props;
119
- const context = useAvatarContext(FALLBACK_NAME, __scopeAvatar);
120
- const [canRender, setCanRender] = React.useState(delayMs === void 0);
121
- React.useEffect(() => {
122
- if (delayMs !== void 0) {
123
- const timerId = setTimeout(() => setCanRender(true), delayMs);
124
- return () => clearTimeout(timerId);
125
- }
126
- }, [delayMs]);
127
- return canRender && context.imageLoadingStatus !== "loaded" ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(AvatarFallbackFrame, {
128
- ...fallbackProps,
129
- ref: forwardedRef
130
- }) : null;
102
+ const AvatarFallback = (0, import_core.createStyledHOC)(AvatarFallbackFrame, (props, forwardedRef) => {
103
+ const { __scopeAvatar, delay, ...fallbackProps } = props;
104
+ const context = useAvatarContext(FALLBACK_NAME, __scopeAvatar);
105
+ const [canRender, setCanRender] = React.useState(delay === void 0);
106
+ React.useEffect(() => {
107
+ if (delay !== void 0) {
108
+ const timerId = setTimeout(() => setCanRender(true), delay);
109
+ return () => clearTimeout(timerId);
110
+ }
111
+ }, [delay]);
112
+ return canRender && context.imageLoadingStatus !== "loaded" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AvatarFallbackFrame, {
113
+ ...fallbackProps,
114
+ ref: forwardedRef
115
+ }) : null;
131
116
  });
132
117
  AvatarFallback.displayName = FALLBACK_NAME;
133
118
  const AvatarFrame = (0, import_core.styled)(import_shapes.Square, {
134
- name: AVATAR_NAME,
135
- position: "relative",
136
- overflow: "hidden"
119
+ displayName: AVATAR_NAME,
120
+ position: "relative",
121
+ overflow: "hidden"
137
122
  });
138
- const Avatar = (0, import_helpers.withStaticProperties)(React.forwardRef((props, forwardedRef) => {
139
- const {
140
- __scopeAvatar,
141
- size = "$true",
142
- ...avatarProps
143
- } = props;
144
- const [imageLoadingStatus, setImageLoadingStatus] = React.useState("idle");
145
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(AvatarProvider, {
146
- size,
147
- scope: __scopeAvatar,
148
- imageLoadingStatus,
149
- onImageLoadingStatusChange: setImageLoadingStatus,
150
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(AvatarFrame, {
151
- size,
152
- ...avatarProps,
153
- ref: forwardedRef
154
- })
155
- });
123
+ const Avatar = (0, import_helpers.withStaticProperties)((0, import_core.createRefComponent)((props, forwardedRef) => {
124
+ const { __scopeAvatar, size = true, ...avatarProps } = props;
125
+ const [imageLoadingStatus, setImageLoadingStatus] = React.useState("idle");
126
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AvatarProvider, {
127
+ size,
128
+ scope: __scopeAvatar,
129
+ imageLoadingStatus,
130
+ onImageLoadingStatusChange: setImageLoadingStatus,
131
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AvatarFrame, {
132
+ size,
133
+ ...avatarProps,
134
+ ref: forwardedRef
135
+ })
136
+ });
156
137
  }), {
157
- Image: AvatarImage,
158
- Fallback: AvatarFallback
138
+ Image: AvatarImage,
139
+ Fallback: AvatarFallback
159
140
  });
160
- Avatar.displayName = AVATAR_NAME;
141
+ Avatar.displayName = AVATAR_NAME;
@@ -0,0 +1,151 @@
1
+ "use strict";
2
+
3
+
4
+ var __create = Object.create;
5
+ var __defProp = Object.defineProperty;
6
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
+ var __getOwnPropNames = Object.getOwnPropertyNames;
8
+ var __getProtoOf = Object.getPrototypeOf;
9
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
10
+ var __export = (target, all) => {
11
+ for (var name in all) __defProp(target, name, {
12
+ get: all[name],
13
+ enumerable: true
14
+ });
15
+ };
16
+ var __copyProps = (to, from, except, desc) => {
17
+ if (from && typeof from === "object" || typeof from === "function") {
18
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
19
+ get: () => from[key],
20
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
21
+ });
22
+ }
23
+ return to;
24
+ };
25
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
26
+ value: mod,
27
+ enumerable: true
28
+ }) : target, mod));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+ var Avatar_exports = {};
31
+ __export(Avatar_exports, {
32
+ Avatar: () => Avatar,
33
+ AvatarFallback: () => AvatarFallback,
34
+ AvatarFallbackFrame: () => AvatarFallbackFrame,
35
+ AvatarFrame: () => AvatarFrame,
36
+ AvatarImage: () => AvatarImage,
37
+ createAvatarScope: () => createAvatarScope
38
+ });
39
+ module.exports = __toCommonJS(Avatar_exports);
40
+ var import_jsx_runtime = require("react/jsx-runtime");
41
+ var import_core = require("@tamagui/core");
42
+ var import_create_context = require("@tamagui/create-context");
43
+ var import_helpers = require("@tamagui/helpers");
44
+ var import_image = require("@tamagui/image");
45
+ var import_shapes = require("@tamagui/shapes");
46
+ var import_stacks = require("@tamagui/stacks");
47
+ var React = __toESM(require("react"), 1);
48
+ function _type_of(obj) {
49
+ "@swc/helpers - typeof";
50
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
51
+ }
52
+ var AVATAR_NAME = "Avatar";
53
+ var [createAvatarContext, createAvatarScope] = (0, import_create_context.createContextScope)(AVATAR_NAME);
54
+ var [AvatarProvider, useAvatarContext] = createAvatarContext(AVATAR_NAME);
55
+ var IMAGE_NAME = "AvatarImage";
56
+ var AvatarImage = (0, import_core.createRefComponent)(function(props, forwardedRef) {
57
+ var { __scopeAvatar, src, source, onLoadingStatusChange = function() {}, ...imageProps } = props;
58
+ var context = useAvatarContext(IMAGE_NAME, __scopeAvatar);
59
+ var [status, setStatus] = React.useState("idle");
60
+ var resolvedSrc = src || (source && (typeof source === "undefined" ? "undefined" : _type_of(source)) === "object" && "uri" in source ? source.uri : source);
61
+ React.useEffect(function() {
62
+ if (!resolvedSrc) {
63
+ setStatus("error");
64
+ } else {
65
+ setStatus("idle");
66
+ }
67
+ }, [resolvedSrc]);
68
+ React.useEffect(function() {
69
+ onLoadingStatusChange(status);
70
+ context.onImageLoadingStatusChange(status);
71
+ }, [status]);
72
+ if (!resolvedSrc) {
73
+ return null;
74
+ }
75
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stacks.YStack, {
76
+ position: "absolute",
77
+ inset: 0,
78
+ zIndex: 1,
79
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_image.Image, {
80
+ position: "absolute",
81
+ top: 0,
82
+ left: 0,
83
+ right: 0,
84
+ bottom: 0,
85
+ objectFit: "cover",
86
+ width: "100%",
87
+ height: "100%",
88
+ ...imageProps,
89
+ ref: forwardedRef,
90
+ src: resolvedSrc,
91
+ onError: function() {
92
+ setStatus("error");
93
+ },
94
+ onLoad: function() {
95
+ setStatus("loaded");
96
+ }
97
+ })
98
+ });
99
+ });
100
+ AvatarImage.displayName = IMAGE_NAME;
101
+ var FALLBACK_NAME = "AvatarFallback";
102
+ var AvatarFallbackFrame = (0, import_core.styled)(import_stacks.YStack, {
103
+ displayName: FALLBACK_NAME,
104
+ position: "absolute",
105
+ inset: 0,
106
+ zIndex: 0
107
+ });
108
+ var AvatarFallback = (0, import_core.createStyledHOC)(AvatarFallbackFrame, function(props, forwardedRef) {
109
+ var { __scopeAvatar, delay, ...fallbackProps } = props;
110
+ var context = useAvatarContext(FALLBACK_NAME, __scopeAvatar);
111
+ var [canRender, setCanRender] = React.useState(delay === void 0);
112
+ React.useEffect(function() {
113
+ if (delay !== void 0) {
114
+ var timerId = setTimeout(function() {
115
+ return setCanRender(true);
116
+ }, delay);
117
+ return function() {
118
+ return clearTimeout(timerId);
119
+ };
120
+ }
121
+ }, [delay]);
122
+ return canRender && context.imageLoadingStatus !== "loaded" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AvatarFallbackFrame, {
123
+ ...fallbackProps,
124
+ ref: forwardedRef
125
+ }) : null;
126
+ });
127
+ AvatarFallback.displayName = FALLBACK_NAME;
128
+ var AvatarFrame = (0, import_core.styled)(import_shapes.Square, {
129
+ displayName: AVATAR_NAME,
130
+ position: "relative",
131
+ overflow: "hidden"
132
+ });
133
+ var Avatar = (0, import_helpers.withStaticProperties)((0, import_core.createRefComponent)(function(props, forwardedRef) {
134
+ var { __scopeAvatar, size = true, ...avatarProps } = props;
135
+ var [imageLoadingStatus, setImageLoadingStatus] = React.useState("idle");
136
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AvatarProvider, {
137
+ size,
138
+ scope: __scopeAvatar,
139
+ imageLoadingStatus,
140
+ onImageLoadingStatusChange: setImageLoadingStatus,
141
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AvatarFrame, {
142
+ size,
143
+ ...avatarProps,
144
+ ref: forwardedRef
145
+ })
146
+ });
147
+ }), {
148
+ Image: AvatarImage,
149
+ Fallback: AvatarFallback
150
+ });
151
+ Avatar.displayName = AVATAR_NAME;