@nukleus-sports/ui-patterns 0.1.2 → 0.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/dist/index.cjs CHANGED
@@ -3,6 +3,10 @@ var __defProp = Object.defineProperty;
3
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
6
10
  var __copyProps = (to, from, except, desc) => {
7
11
  if (from && typeof from === "object" || typeof from === "function") {
8
12
  for (let key of __getOwnPropNames(from))
@@ -15,5 +19,246 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
15
19
 
16
20
  // src/index.ts
17
21
  var src_exports = {};
22
+ __export(src_exports, {
23
+ ENTITY_AVATAR_SIZE_PX: () => ENTITY_AVATAR_SIZE_PX,
24
+ EntityAvatar: () => EntityAvatar
25
+ });
18
26
  module.exports = __toCommonJS(src_exports);
27
+
28
+ // src/entity-avatar.tsx
29
+ var import_ui_web = require("@nukleus-sports/ui-web");
30
+ var import_jsx_runtime = require("react/jsx-runtime");
31
+ var ENTITY_AVATAR_SIZE_PX = {
32
+ xs: 16,
33
+ sm: 24,
34
+ md: 32,
35
+ lg: 48,
36
+ xl: 64,
37
+ "2xl": 120
38
+ };
39
+ var sizeClasses = {
40
+ xs: "h-4 w-4",
41
+ sm: "h-6 w-6",
42
+ md: "h-8 w-8",
43
+ lg: "h-12 w-12",
44
+ xl: "h-16 w-16",
45
+ "2xl": "h-[120px] w-[120px]"
46
+ };
47
+ var initialSizeClasses = {
48
+ xs: "text-[8px]",
49
+ sm: "text-xs",
50
+ md: "text-sm",
51
+ lg: "text-base",
52
+ xl: "text-lg",
53
+ "2xl": "text-2xl"
54
+ };
55
+ var contactSizeClasses = {
56
+ xs: "h-4 w-4",
57
+ sm: "h-6 w-6",
58
+ md: "h-8 w-8",
59
+ lg: "h-12 w-12",
60
+ xl: "h-16 w-16",
61
+ "2xl": "h-[120px] w-[120px]"
62
+ };
63
+ var contactInitialSizeClasses = {
64
+ xs: "text-[8px]",
65
+ sm: "text-[10px]",
66
+ md: "text-sm",
67
+ lg: "text-base",
68
+ xl: "text-lg",
69
+ "2xl": "text-2xl"
70
+ };
71
+ function EntityAvatar({
72
+ entityType = "initials",
73
+ entityData,
74
+ firstName,
75
+ lastName,
76
+ name,
77
+ imageUrl,
78
+ resolveImageUrl,
79
+ size = "md",
80
+ className,
81
+ fallbackClassName,
82
+ showInitials = true,
83
+ cacheBreaker
84
+ }) {
85
+ const extractedFirstName = firstName || entityData?.first_name || "";
86
+ const extractedLastName = lastName || entityData?.last_name || "";
87
+ const extractedName = name || entityData?.name || "";
88
+ const isSquared = entityType === "team" || entityType === "company";
89
+ const usesContactSizes = entityType === "contact" || entityType === "company" || entityType === "initials";
90
+ const avatarSizeClasses = usesContactSizes ? contactSizeClasses : sizeClasses;
91
+ const initialsSizeClasses = usesContactSizes ? contactInitialSizeClasses : initialSizeClasses;
92
+ const defaultSize = usesContactSizes ? "sm" : "md";
93
+ const effectiveSize = size || defaultSize;
94
+ const getRawImageUrl = () => {
95
+ if (imageUrl) return imageUrl;
96
+ switch (entityType) {
97
+ case "player":
98
+ return entityData?.player_image_url ?? null;
99
+ case "coach":
100
+ return entityData?.coach_image_url ?? null;
101
+ case "team":
102
+ return entityData?.team_logo_url ?? null;
103
+ case "initials":
104
+ case "contact":
105
+ case "company":
106
+ return entityData?.avatar_url ?? null;
107
+ case "agency":
108
+ return entityData?.profile_image_url ?? null;
109
+ default:
110
+ return null;
111
+ }
112
+ };
113
+ const getImageUrl = () => {
114
+ const rawUrl = getRawImageUrl();
115
+ if (!rawUrl) return null;
116
+ if (resolveImageUrl) {
117
+ return resolveImageUrl(rawUrl, { entityType, size: effectiveSize, cacheBreaker });
118
+ }
119
+ if (rawUrl.startsWith("http") || rawUrl.startsWith("data:")) {
120
+ return rawUrl;
121
+ }
122
+ return null;
123
+ };
124
+ const getInitials = () => {
125
+ if (!showInitials) {
126
+ const defaults = {
127
+ player: "P",
128
+ coach: "C",
129
+ team: "T",
130
+ contact: "C",
131
+ company: "C",
132
+ agency: "",
133
+ initials: ""
134
+ };
135
+ return defaults[entityType];
136
+ }
137
+ switch (entityType) {
138
+ case "player":
139
+ case "coach":
140
+ case "agency": {
141
+ const first = extractedFirstName?.[0] || "";
142
+ const last = extractedLastName?.[0] || "";
143
+ const initials2 = (first + last).toUpperCase();
144
+ if (initials2) return initials2;
145
+ if (entityType === "player") return "P";
146
+ if (entityType === "coach") return "C";
147
+ return "?";
148
+ }
149
+ case "team": {
150
+ const teamName = entityData?.team || "";
151
+ const nickname = entityData?.nickname || "";
152
+ const displayName = nickname || teamName || "";
153
+ const words = displayName.trim().split(/\s+/);
154
+ if (words.length >= 2) {
155
+ return (words[0][0] + words[1][0]).toUpperCase();
156
+ } else if (words.length === 1 && words[0].length >= 2) {
157
+ return words[0].substring(0, 2).toUpperCase();
158
+ }
159
+ return "T";
160
+ }
161
+ case "initials": {
162
+ const displayName = extractedName.trim();
163
+ if (!displayName) return "?";
164
+ const nameParts = displayName.trim().split(/\s+/);
165
+ if (nameParts.length >= 2) {
166
+ return (nameParts[0][0] + nameParts[nameParts.length - 1][0]).toUpperCase();
167
+ }
168
+ return displayName.substring(0, 2).toUpperCase();
169
+ }
170
+ case "contact":
171
+ case "company": {
172
+ const displayName = extractedName;
173
+ if (!displayName) return "C";
174
+ const nameParts = displayName.trim().split(/\s+/);
175
+ if (nameParts.length >= 2) {
176
+ if (entityType === "company") {
177
+ return (nameParts[0][0] + nameParts[1][0]).toUpperCase();
178
+ } else {
179
+ return (nameParts[0][0] + nameParts[nameParts.length - 1][0]).toUpperCase();
180
+ }
181
+ }
182
+ return displayName.substring(0, 2).toUpperCase();
183
+ }
184
+ default:
185
+ return "?";
186
+ }
187
+ };
188
+ const getDefaultImageUrl = () => {
189
+ switch (entityType) {
190
+ case "player":
191
+ case "coach":
192
+ return "/images/headshot_default.png";
193
+ case "team":
194
+ return "/images/team_default.png";
195
+ case "contact":
196
+ return "/images/contact_default.png";
197
+ case "company":
198
+ return "/images/company_default.png";
199
+ case "agency":
200
+ return "/images/agency_default.png";
201
+ case "initials":
202
+ return "/images/headshot_default.png";
203
+ default:
204
+ return "/images/headshot_default.png";
205
+ }
206
+ };
207
+ const getAltText = () => {
208
+ switch (entityType) {
209
+ case "player":
210
+ return `${extractedFirstName} ${extractedLastName}`.trim() || "Player avatar";
211
+ case "coach":
212
+ return `${extractedFirstName} ${extractedLastName}`.trim() || "Coach avatar";
213
+ case "team":
214
+ return `${entityData?.team || entityData?.nickname || "Team"} logo`;
215
+ case "initials":
216
+ return `${extractedName}`.trim() || "User avatar";
217
+ case "contact":
218
+ return extractedName || "Profile Picture";
219
+ case "company":
220
+ return extractedName || "Company avatar";
221
+ case "agency":
222
+ return `${extractedFirstName} ${extractedLastName}`.trim() || "User avatar";
223
+ default:
224
+ return "Avatar";
225
+ }
226
+ };
227
+ const processedImageUrl = getImageUrl();
228
+ const defaultImageUrl = getDefaultImageUrl();
229
+ const initials = getInitials();
230
+ const altText = getAltText();
231
+ const hasValidImage = Boolean(
232
+ processedImageUrl && processedImageUrl !== "null" && processedImageUrl !== null && processedImageUrl.trim() !== ""
233
+ );
234
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_ui_web.Avatar, { className: (0, import_ui_web.cn)(avatarSizeClasses[effectiveSize], isSquared && "rounded-lg", className), children: [
235
+ hasValidImage && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ui_web.AvatarImage, { src: processedImageUrl, alt: altText }),
236
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
237
+ import_ui_web.AvatarFallback,
238
+ {
239
+ className: (0, import_ui_web.cn)(
240
+ initialsSizeClasses[effectiveSize],
241
+ isSquared && "rounded-lg bg-greys-grey-table-h",
242
+ fallbackClassName
243
+ ),
244
+ children: entityType === "contact" || entityType === "initials" ? initials : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
245
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
246
+ "img",
247
+ {
248
+ src: defaultImageUrl,
249
+ alt: altText,
250
+ className: "aspect-square h-full w-full object-cover"
251
+ }
252
+ ),
253
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "sr-only", children: initials })
254
+ ] })
255
+ }
256
+ )
257
+ ] });
258
+ }
259
+ // Annotate the CommonJS export names for ESM import in node:
260
+ 0 && (module.exports = {
261
+ ENTITY_AVATAR_SIZE_PX,
262
+ EntityAvatar
263
+ });
19
264
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export {};\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts","../src/entity-avatar.tsx"],"sourcesContent":["export {\n EntityAvatar,\n ENTITY_AVATAR_SIZE_PX,\n type EntityType,\n type EntityAvatarSize,\n type EntityAvatarProps,\n type EntityImageResolver,\n} from \"./entity-avatar\";\n","import { Avatar, AvatarFallback, AvatarImage, cn } from \"@nukleus-sports/ui-web\";\n\nexport type EntityType =\n \"player\" | \"coach\" | \"team\" | \"contact\" | \"company\" | \"agency\" | \"initials\";\n\n/** `2xl` (120px) added for `EntityBioCard`'s large profile avatar -- without\n * it, that card had no size step close to its actual rendered size and\n * fell back to `xl` (64px), which a real `resolveImageUrl` would've taken\n * literally and requested a thumbnail roughly half the size it's displayed\n * at. */\nexport type EntityAvatarSize = \"xs\" | \"sm\" | \"md\" | \"lg\" | \"xl\" | \"2xl\";\n\ninterface BaseEntityData {\n // Person fields (player, coach, agency user)\n first_name?: string | null;\n last_name?: string | null;\n player_image_url?: string | null;\n coach_image_url?: string | null;\n profile_image_url?: string | null;\n\n // Team fields\n team?: string | null;\n nickname?: string | null;\n team_logo_url?: string | null;\n\n // Contact/Company fields\n name?: string | null;\n avatar_url?: string | null;\n}\n\n/**\n * CSS pixel size of each avatar size step, mirroring `sizeClasses`/`contactSizeClasses` below.\n * Exported so a consuming app's `resolveImageUrl` adapter can request an appropriately\n * sized render (e.g. nukleus-clientapp's `sizedStorageImage(rawUrl, ENTITY_AVATAR_SIZE_PX[size], \"cover\")`)\n * without this package needing to know about that CDN's resize API.\n */\nexport const ENTITY_AVATAR_SIZE_PX: Record<EntityAvatarSize, number> = {\n xs: 16,\n sm: 24,\n md: 32,\n lg: 48,\n xl: 64,\n \"2xl\": 120,\n};\n\n/**\n * Turns a raw, possibly-relative stored image path into a renderable URL.\n *\n * Both source apps resolved this inline by calling Supabase-storage-specific helpers\n * (`getStoragePublicUrl`, `sizedStorageImage`, cache-busting query params) straight out of\n * `@/lib/image-utils`. This package has no legitimate reason to talk to Supabase or know\n * about a particular CDN's URL shape, so that resolution step is lifted out to this\n * injectable adapter instead of being baked into the shared component — the same\n * data-arrives-through-props principle this repo already applies to page-shells.\n *\n * Return `null` to fall back to initials/the default placeholder image.\n */\nexport type EntityImageResolver = (\n rawUrl: string,\n context: { entityType: EntityType; size: EntityAvatarSize; cacheBreaker?: string | number },\n) => string | null;\n\nexport interface EntityAvatarProps {\n /**\n * Drives image resolution and the placeholder shown when there's no image.\n * Defaults to \"initials\" — image when one is supplied, initials otherwise —\n * which is the behaviour every plain `name` + `imageUrl` call site expects.\n */\n entityType?: EntityType;\n entityData?: BaseEntityData | null;\n\n // Optional direct props (override entityData)\n firstName?: string | null;\n lastName?: string | null;\n name?: string | null;\n imageUrl?: string | null;\n\n /**\n * Resolves a raw stored image path/URL into something renderable. Omit it to only\n * render already-absolute URLs (`http(s)://...` or `data:...`) as-is — anything else\n * (a bare storage path) falls back to initials/the default placeholder, since this\n * package can't resolve it itself. See `EntityImageResolver` for why.\n */\n resolveImageUrl?: EntityImageResolver;\n\n // Styling\n size?: EntityAvatarSize;\n className?: string;\n fallbackClassName?: string;\n showInitials?: boolean;\n\n // Special props\n cacheBreaker?: string | number; // For agency user profile images\n}\n\nconst sizeClasses: Record<EntityAvatarSize, string> = {\n xs: \"h-4 w-4\",\n sm: \"h-6 w-6\",\n md: \"h-8 w-8\",\n lg: \"h-12 w-12\",\n xl: \"h-16 w-16\",\n \"2xl\": \"h-[120px] w-[120px]\",\n};\n\nconst initialSizeClasses: Record<EntityAvatarSize, string> = {\n xs: \"text-[8px]\",\n sm: \"text-xs\",\n md: \"text-sm\",\n lg: \"text-base\",\n xl: \"text-lg\",\n \"2xl\": \"text-2xl\",\n};\n\n// Special size classes for contacts/companies\nconst contactSizeClasses: Record<EntityAvatarSize, string> = {\n xs: \"h-4 w-4\",\n sm: \"h-6 w-6\",\n md: \"h-8 w-8\",\n lg: \"h-12 w-12\",\n xl: \"h-16 w-16\",\n \"2xl\": \"h-[120px] w-[120px]\",\n};\n\nconst contactInitialSizeClasses: Record<EntityAvatarSize, string> = {\n xs: \"text-[8px]\",\n sm: \"text-[10px]\",\n md: \"text-sm\",\n lg: \"text-base\",\n xl: \"text-lg\",\n \"2xl\": \"text-2xl\",\n};\n\nexport function EntityAvatar({\n entityType = \"initials\",\n entityData,\n firstName,\n lastName,\n name,\n imageUrl,\n resolveImageUrl,\n size = \"md\",\n className,\n fallbackClassName,\n showInitials = true,\n cacheBreaker,\n}: EntityAvatarProps) {\n // Extract data based on entity type\n const extractedFirstName = firstName || entityData?.first_name || \"\";\n const extractedLastName = lastName || entityData?.last_name || \"\";\n const extractedName = name || entityData?.name || \"\";\n\n // Determine if this entity should use rounded corners (team and company)\n const isSquared = entityType === \"team\" || entityType === \"company\";\n\n // Use contact-specific sizes for contact, company and initials\n const usesContactSizes =\n entityType === \"contact\" || entityType === \"company\" || entityType === \"initials\";\n const avatarSizeClasses = usesContactSizes ? contactSizeClasses : sizeClasses;\n const initialsSizeClasses = usesContactSizes ? contactInitialSizeClasses : initialSizeClasses;\n\n // Contact default size is \"sm\" instead of \"md\"\n const defaultSize = usesContactSizes ? \"sm\" : \"md\";\n const effectiveSize = size || defaultSize;\n\n // Resolve the raw stored path/URL based on entity type, before handing it to\n // `resolveImageUrl` (see `EntityImageResolver` for why resolution is injected).\n const getRawImageUrl = (): string | null => {\n if (imageUrl) return imageUrl;\n\n switch (entityType) {\n case \"player\":\n return entityData?.player_image_url ?? null;\n case \"coach\":\n return entityData?.coach_image_url ?? null;\n case \"team\":\n return entityData?.team_logo_url ?? null;\n case \"initials\":\n case \"contact\":\n case \"company\":\n return entityData?.avatar_url ?? null;\n case \"agency\":\n return entityData?.profile_image_url ?? null;\n default:\n return null;\n }\n };\n\n const getImageUrl = (): string | null => {\n const rawUrl = getRawImageUrl();\n if (!rawUrl) return null;\n\n if (resolveImageUrl) {\n return resolveImageUrl(rawUrl, { entityType, size: effectiveSize, cacheBreaker });\n }\n\n // No adapter supplied — only pass through URLs that are already renderable as-is.\n if (rawUrl.startsWith(\"http\") || rawUrl.startsWith(\"data:\")) {\n return rawUrl;\n }\n\n return null;\n };\n\n // Generate initials based on entity type\n const getInitials = (): string => {\n if (!showInitials) {\n // Return default initials for each type\n const defaults: Record<EntityType, string> = {\n player: \"P\",\n coach: \"C\",\n team: \"T\",\n contact: \"C\",\n company: \"C\",\n agency: \"\",\n initials: \"\",\n };\n return defaults[entityType];\n }\n\n switch (entityType) {\n case \"player\":\n case \"coach\":\n case \"agency\": {\n const first = extractedFirstName?.[0] || \"\";\n const last = extractedLastName?.[0] || \"\";\n const initials = (first + last).toUpperCase();\n\n if (initials) return initials;\n\n // Fallback defaults\n if (entityType === \"player\") return \"P\";\n if (entityType === \"coach\") return \"C\";\n return \"?\";\n }\n\n case \"team\": {\n const teamName = entityData?.team || \"\";\n const nickname = entityData?.nickname || \"\";\n const displayName = nickname || teamName || \"\";\n const words = displayName.trim().split(/\\s+/);\n\n if (words.length >= 2) {\n return (words[0][0] + words[1][0]).toUpperCase();\n } else if (words.length === 1 && words[0].length >= 2) {\n return words[0].substring(0, 2).toUpperCase();\n }\n\n return \"T\";\n }\n\n case \"initials\": {\n const displayName = extractedName.trim();\n if (!displayName) return \"?\";\n\n const nameParts = displayName.trim().split(/\\s+/);\n if (nameParts.length >= 2) {\n // For contact: first and last name initials\n return (nameParts[0][0] + nameParts[nameParts.length - 1][0]).toUpperCase();\n }\n return displayName.substring(0, 2).toUpperCase();\n }\n\n case \"contact\":\n case \"company\": {\n const displayName = extractedName;\n if (!displayName) return \"C\";\n\n const nameParts = displayName.trim().split(/\\s+/);\n if (nameParts.length >= 2) {\n // For company: first letter of first two words\n // For contact: first and last name initials\n if (entityType === \"company\") {\n return (nameParts[0][0] + nameParts[1][0]).toUpperCase();\n } else {\n return (nameParts[0][0] + nameParts[nameParts.length - 1][0]).toUpperCase();\n }\n }\n return displayName.substring(0, 2).toUpperCase();\n }\n\n default:\n return \"?\";\n }\n };\n\n // Get default image URL based on entity type\n const getDefaultImageUrl = (): string => {\n switch (entityType) {\n case \"player\":\n case \"coach\":\n return \"/images/headshot_default.png\";\n case \"team\":\n return \"/images/team_default.png\";\n case \"contact\":\n return \"/images/contact_default.png\";\n case \"company\":\n return \"/images/company_default.png\";\n case \"agency\":\n return \"/images/agency_default.png\";\n case \"initials\":\n return \"/images/headshot_default.png\";\n default:\n return \"/images/headshot_default.png\";\n }\n };\n\n const getAltText = (): string => {\n switch (entityType) {\n case \"player\":\n return `${extractedFirstName} ${extractedLastName}`.trim() || \"Player avatar\";\n case \"coach\":\n return `${extractedFirstName} ${extractedLastName}`.trim() || \"Coach avatar\";\n case \"team\":\n return `${entityData?.team || entityData?.nickname || \"Team\"} logo`;\n case \"initials\":\n return `${extractedName}`.trim() || \"User avatar\";\n case \"contact\":\n return extractedName || \"Profile Picture\";\n case \"company\":\n return extractedName || \"Company avatar\";\n case \"agency\":\n return `${extractedFirstName} ${extractedLastName}`.trim() || \"User avatar\";\n default:\n return \"Avatar\";\n }\n };\n\n const processedImageUrl = getImageUrl();\n const defaultImageUrl = getDefaultImageUrl();\n const initials = getInitials();\n const altText = getAltText();\n\n // Only render AvatarImage if we have a valid, non-empty URL\n // This prevents Radix from rendering an empty <img> tag which suppresses the fallback\n const hasValidImage = Boolean(\n processedImageUrl &&\n processedImageUrl !== \"null\" &&\n processedImageUrl !== null &&\n processedImageUrl.trim() !== \"\",\n );\n\n return (\n <Avatar className={cn(avatarSizeClasses[effectiveSize], isSquared && \"rounded-lg\", className)}>\n {hasValidImage && <AvatarImage src={processedImageUrl!} alt={altText} />}\n <AvatarFallback\n className={cn(\n initialsSizeClasses[effectiveSize],\n isSquared && \"rounded-lg bg-greys-grey-table-h\",\n fallbackClassName,\n )}\n >\n {entityType === \"contact\" || entityType === \"initials\" ? (\n initials\n ) : (\n <>\n <img\n src={defaultImageUrl}\n alt={altText}\n className=\"aspect-square h-full w-full object-cover\"\n />\n <span className=\"sr-only\">{initials}</span>\n </>\n )}\n </AvatarFallback>\n </Avatar>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,oBAAwD;AAuVhC;AAnTjB,IAAM,wBAA0D;AAAA,EACrE,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,OAAO;AACT;AAoDA,IAAM,cAAgD;AAAA,EACpD,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,OAAO;AACT;AAEA,IAAM,qBAAuD;AAAA,EAC3D,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,OAAO;AACT;AAGA,IAAM,qBAAuD;AAAA,EAC3D,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,OAAO;AAC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ACH,eAAO,GAAG,aAAa,GAAG,KAAK,KAAK;AAAA,MACtC,KAAK;AACH,eAAO,iBAAiB;AAAA,MAC1B,KAAK;AACH,eAAO,iBAAiB;AAAA,MAC1B,KAAK;AACH,eAAO,GAAG,kBAAkB,IAAI,iBAAiB,GAAG,KAAK,KAAK;AAAA,MAChE;AACE,eAAO;AAAA,IACX;AAAA,EACF;AAEA,QAAM,oBAAoB,YAAY;AACtC,QAAM,kBAAkB,mBAAmB;AAC3C,QAAM,WAAW,YAAY;AAC7B,QAAM,UAAU,WAAW;AAI3B,QAAM,gBAAgB;AAAA,IACpB,qBACA,sBAAsB,UACtB,sBAAsB,QACtB,kBAAkB,KAAK,MAAM;AAAA,EAC/B;AAEA,SACE,6CAAC,wBAAO,eAAW,kBAAG,kBAAkB,aAAa,GAAG,aAAa,cAAc,SAAS,GACzF;AAAA,qBAAiB,4CAAC,6BAAY,KAAK,mBAAoB,KAAK,SAAS;AAAA,IACtE;AAAA,MAAC;AAAA;AAAA,QACC,eAAW;AAAA,UACT,oBAAoB,aAAa;AAAA,UACjC,aAAa;AAAA,UACb;AAAA,QACF;AAAA,QAEC,yBAAe,aAAa,eAAe,aAC1C,WAEA,4EACE;AAAA;AAAA,YAAC;AAAA;AAAA,cACC,KAAK;AAAA,cACL,KAAK;AAAA,cACL,WAAU;AAAA;AAAA,UACZ;AAAA,UACA,4CAAC,UAAK,WAAU,WAAW,oBAAS;AAAA,WACtC;AAAA;AAAA,IAEJ;AAAA,KACF;AAEJ;","names":["initials"]}
package/dist/index.d.cts CHANGED
@@ -1,2 +1,73 @@
1
+ import * as react from 'react';
1
2
 
2
- export { }
3
+ type EntityType = "player" | "coach" | "team" | "contact" | "company" | "agency" | "initials";
4
+ /** `2xl` (120px) added for `EntityBioCard`'s large profile avatar -- without
5
+ * it, that card had no size step close to its actual rendered size and
6
+ * fell back to `xl` (64px), which a real `resolveImageUrl` would've taken
7
+ * literally and requested a thumbnail roughly half the size it's displayed
8
+ * at. */
9
+ type EntityAvatarSize = "xs" | "sm" | "md" | "lg" | "xl" | "2xl";
10
+ interface BaseEntityData {
11
+ first_name?: string | null;
12
+ last_name?: string | null;
13
+ player_image_url?: string | null;
14
+ coach_image_url?: string | null;
15
+ profile_image_url?: string | null;
16
+ team?: string | null;
17
+ nickname?: string | null;
18
+ team_logo_url?: string | null;
19
+ name?: string | null;
20
+ avatar_url?: string | null;
21
+ }
22
+ /**
23
+ * CSS pixel size of each avatar size step, mirroring `sizeClasses`/`contactSizeClasses` below.
24
+ * Exported so a consuming app's `resolveImageUrl` adapter can request an appropriately
25
+ * sized render (e.g. nukleus-clientapp's `sizedStorageImage(rawUrl, ENTITY_AVATAR_SIZE_PX[size], "cover")`)
26
+ * without this package needing to know about that CDN's resize API.
27
+ */
28
+ declare const ENTITY_AVATAR_SIZE_PX: Record<EntityAvatarSize, number>;
29
+ /**
30
+ * Turns a raw, possibly-relative stored image path into a renderable URL.
31
+ *
32
+ * Both source apps resolved this inline by calling Supabase-storage-specific helpers
33
+ * (`getStoragePublicUrl`, `sizedStorageImage`, cache-busting query params) straight out of
34
+ * `@/lib/image-utils`. This package has no legitimate reason to talk to Supabase or know
35
+ * about a particular CDN's URL shape, so that resolution step is lifted out to this
36
+ * injectable adapter instead of being baked into the shared component — the same
37
+ * data-arrives-through-props principle this repo already applies to page-shells.
38
+ *
39
+ * Return `null` to fall back to initials/the default placeholder image.
40
+ */
41
+ type EntityImageResolver = (rawUrl: string, context: {
42
+ entityType: EntityType;
43
+ size: EntityAvatarSize;
44
+ cacheBreaker?: string | number;
45
+ }) => string | null;
46
+ interface EntityAvatarProps {
47
+ /**
48
+ * Drives image resolution and the placeholder shown when there's no image.
49
+ * Defaults to "initials" — image when one is supplied, initials otherwise —
50
+ * which is the behaviour every plain `name` + `imageUrl` call site expects.
51
+ */
52
+ entityType?: EntityType;
53
+ entityData?: BaseEntityData | null;
54
+ firstName?: string | null;
55
+ lastName?: string | null;
56
+ name?: string | null;
57
+ imageUrl?: string | null;
58
+ /**
59
+ * Resolves a raw stored image path/URL into something renderable. Omit it to only
60
+ * render already-absolute URLs (`http(s)://...` or `data:...`) as-is — anything else
61
+ * (a bare storage path) falls back to initials/the default placeholder, since this
62
+ * package can't resolve it itself. See `EntityImageResolver` for why.
63
+ */
64
+ resolveImageUrl?: EntityImageResolver;
65
+ size?: EntityAvatarSize;
66
+ className?: string;
67
+ fallbackClassName?: string;
68
+ showInitials?: boolean;
69
+ cacheBreaker?: string | number;
70
+ }
71
+ declare function EntityAvatar({ entityType, entityData, firstName, lastName, name, imageUrl, resolveImageUrl, size, className, fallbackClassName, showInitials, cacheBreaker, }: EntityAvatarProps): react.JSX.Element;
72
+
73
+ export { ENTITY_AVATAR_SIZE_PX, EntityAvatar, type EntityAvatarProps, type EntityAvatarSize, type EntityImageResolver, type EntityType };
package/dist/index.d.ts CHANGED
@@ -1,2 +1,73 @@
1
+ import * as react from 'react';
1
2
 
2
- export { }
3
+ type EntityType = "player" | "coach" | "team" | "contact" | "company" | "agency" | "initials";
4
+ /** `2xl` (120px) added for `EntityBioCard`'s large profile avatar -- without
5
+ * it, that card had no size step close to its actual rendered size and
6
+ * fell back to `xl` (64px), which a real `resolveImageUrl` would've taken
7
+ * literally and requested a thumbnail roughly half the size it's displayed
8
+ * at. */
9
+ type EntityAvatarSize = "xs" | "sm" | "md" | "lg" | "xl" | "2xl";
10
+ interface BaseEntityData {
11
+ first_name?: string | null;
12
+ last_name?: string | null;
13
+ player_image_url?: string | null;
14
+ coach_image_url?: string | null;
15
+ profile_image_url?: string | null;
16
+ team?: string | null;
17
+ nickname?: string | null;
18
+ team_logo_url?: string | null;
19
+ name?: string | null;
20
+ avatar_url?: string | null;
21
+ }
22
+ /**
23
+ * CSS pixel size of each avatar size step, mirroring `sizeClasses`/`contactSizeClasses` below.
24
+ * Exported so a consuming app's `resolveImageUrl` adapter can request an appropriately
25
+ * sized render (e.g. nukleus-clientapp's `sizedStorageImage(rawUrl, ENTITY_AVATAR_SIZE_PX[size], "cover")`)
26
+ * without this package needing to know about that CDN's resize API.
27
+ */
28
+ declare const ENTITY_AVATAR_SIZE_PX: Record<EntityAvatarSize, number>;
29
+ /**
30
+ * Turns a raw, possibly-relative stored image path into a renderable URL.
31
+ *
32
+ * Both source apps resolved this inline by calling Supabase-storage-specific helpers
33
+ * (`getStoragePublicUrl`, `sizedStorageImage`, cache-busting query params) straight out of
34
+ * `@/lib/image-utils`. This package has no legitimate reason to talk to Supabase or know
35
+ * about a particular CDN's URL shape, so that resolution step is lifted out to this
36
+ * injectable adapter instead of being baked into the shared component — the same
37
+ * data-arrives-through-props principle this repo already applies to page-shells.
38
+ *
39
+ * Return `null` to fall back to initials/the default placeholder image.
40
+ */
41
+ type EntityImageResolver = (rawUrl: string, context: {
42
+ entityType: EntityType;
43
+ size: EntityAvatarSize;
44
+ cacheBreaker?: string | number;
45
+ }) => string | null;
46
+ interface EntityAvatarProps {
47
+ /**
48
+ * Drives image resolution and the placeholder shown when there's no image.
49
+ * Defaults to "initials" — image when one is supplied, initials otherwise —
50
+ * which is the behaviour every plain `name` + `imageUrl` call site expects.
51
+ */
52
+ entityType?: EntityType;
53
+ entityData?: BaseEntityData | null;
54
+ firstName?: string | null;
55
+ lastName?: string | null;
56
+ name?: string | null;
57
+ imageUrl?: string | null;
58
+ /**
59
+ * Resolves a raw stored image path/URL into something renderable. Omit it to only
60
+ * render already-absolute URLs (`http(s)://...` or `data:...`) as-is — anything else
61
+ * (a bare storage path) falls back to initials/the default placeholder, since this
62
+ * package can't resolve it itself. See `EntityImageResolver` for why.
63
+ */
64
+ resolveImageUrl?: EntityImageResolver;
65
+ size?: EntityAvatarSize;
66
+ className?: string;
67
+ fallbackClassName?: string;
68
+ showInitials?: boolean;
69
+ cacheBreaker?: string | number;
70
+ }
71
+ declare function EntityAvatar({ entityType, entityData, firstName, lastName, name, imageUrl, resolveImageUrl, size, className, fallbackClassName, showInitials, cacheBreaker, }: EntityAvatarProps): react.JSX.Element;
72
+
73
+ export { ENTITY_AVATAR_SIZE_PX, EntityAvatar, type EntityAvatarProps, type EntityAvatarSize, type EntityImageResolver, type EntityType };
package/dist/index.js CHANGED
@@ -1 +1,9 @@
1
+ import {
2
+ ENTITY_AVATAR_SIZE_PX,
3
+ EntityAvatar
4
+ } from "./chunk-WXPCAG5Z.js";
5
+ export {
6
+ ENTITY_AVATAR_SIZE_PX,
7
+ EntityAvatar
8
+ };
1
9
  //# sourceMappingURL=index.js.map