@pindoba/core-avatar 0.0.0-alpha-20260426220647

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 ADDED
@@ -0,0 +1,12 @@
1
+ Copyright 2025 Eduardo Lopes
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
8
+ INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
9
+ PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
10
+ FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
11
+ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
12
+ DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,3 @@
1
+ import { _ as AvatarShape, a as AvatarBorder, b as ConnectAvatarOptions, c as AvatarFallbackProps, d as AvatarPadding, g as AvatarShadow, h as AvatarRootProps, i as AvatarBaseProps, l as AvatarFeedback, m as AvatarRadius, n as AvatarBackground, o as AvatarClasses, p as AvatarPassThrough, s as AvatarEmphasis, t as AvatarApi, u as AvatarImageProps, v as AvatarSize, x as ElementAttributes, y as AvatarSlotPassThrough } from "./types-CyUSJ_FB.js";
2
+ import { avatarDefaults, connectAvatar, getAvatarInitials } from "./src/connect-avatar.js";
3
+ export { type AvatarApi, type AvatarBackground, type AvatarBaseProps, type AvatarBorder, type AvatarClasses, type AvatarEmphasis, type AvatarFallbackProps, type AvatarFeedback, type AvatarImageProps, type AvatarPadding, type AvatarPassThrough, type AvatarRadius, type AvatarRootProps, type AvatarShadow, type AvatarShape, type AvatarSize, type AvatarSlotPassThrough, type ConnectAvatarOptions, type ElementAttributes, avatarDefaults, connectAvatar, getAvatarInitials };
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ import { avatarDefaults, connectAvatar, getAvatarInitials } from "./src/connect-avatar.js";
2
+ export { avatarDefaults, connectAvatar, getAvatarInitials };
@@ -0,0 +1,18 @@
1
+ import { b as ConnectAvatarOptions, t as AvatarApi } from "../types-CyUSJ_FB.js";
2
+
3
+ //#region src/connect-avatar.d.ts
4
+ declare const avatarDefaults: {
5
+ readonly emphasis: "secondary";
6
+ readonly size: "md";
7
+ readonly shape: "circle";
8
+ readonly feedback: "neutral";
9
+ };
10
+ /**
11
+ * Derive up to two uppercase initials from a name. Empty / undefined input
12
+ * returns an empty string so the consumer can render an icon fallback.
13
+ */
14
+ declare function getAvatarInitials(name?: string): string;
15
+ declare function connectAvatar(options: ConnectAvatarOptions): AvatarApi;
16
+ //#endregion
17
+ export { avatarDefaults, connectAvatar, getAvatarInitials };
18
+ //# sourceMappingURL=connect-avatar.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connect-avatar.d.ts","names":[],"sources":["../../src/connect-avatar.ts"],"mappings":";;;cAgBa,cAAA;EAAA;;;;;;;;;iBAsBG,iBAAA,CAAkB,IAAA;AAAA,iBAclB,aAAA,CAAc,OAAA,EAAS,oBAAA,GAAuB,SAAA"}
@@ -0,0 +1,103 @@
1
+ import { css } from "@pindoba/styled-system/css";
2
+ import { avatarStyles } from "@pindoba/styles-avatar";
3
+ import { connectPanel } from "@pindoba/core-panel";
4
+ //#region src/connect-avatar.ts
5
+ const avatarDefaults = {
6
+ emphasis: "secondary",
7
+ size: "md",
8
+ shape: "circle",
9
+ feedback: "neutral"
10
+ };
11
+ const sizeToRadius = {
12
+ xs: "xs",
13
+ sm: "xs",
14
+ md: "sm",
15
+ lg: "md"
16
+ };
17
+ /**
18
+ * Derive up to two uppercase initials from a name. Empty / undefined input
19
+ * returns an empty string so the consumer can render an icon fallback.
20
+ */
21
+ function getAvatarInitials(name) {
22
+ if (!name) return "";
23
+ const trimmed = name.trim();
24
+ if (/^\+\d+$/u.test(trimmed)) return trimmed.slice(0, 4);
25
+ const parts = trimmed.split(/\s+/u).filter(Boolean);
26
+ if (parts.length === 0) return "";
27
+ if (parts.length === 1) return parts[0].slice(0, 2).toUpperCase();
28
+ return (parts[0][0] + parts[parts.length - 1][0]).toUpperCase();
29
+ }
30
+ function connectAvatar(options) {
31
+ const { emphasis = avatarDefaults.emphasis, size = avatarDefaults.size, shape = avatarDefaults.shape, feedback: feedbackProp, src, alt, name, background: backgroundProp, border: borderProp, radius: radiusProp, padding: paddingProp, accent: accentProp, translucent, radiusTop, radiusBottom, radiusLeft, radiusRight, shadow, interactive, passThrough, class: className, ...restProps } = options;
32
+ const feedback = feedbackProp ?? (emphasis === "primary" ? "primary" : "neutral");
33
+ const resolvedAccent = accentProp ?? emphasis === "primary";
34
+ const background = backgroundProp ?? (emphasis === "ghost" ? "transparent" : "surface.soft");
35
+ const border = borderProp ?? (emphasis === "ghost" ? "none" : emphasis === "muted" ? "muted" : "accent");
36
+ const radius = radiusProp ?? (shape === "circle" ? "full" : sizeToRadius[size]);
37
+ const padding = paddingProp ?? "none";
38
+ const panelEmphasis = emphasis === "ghost" ? "secondary" : void 0;
39
+ const classes = avatarStyles.raw({
40
+ emphasis,
41
+ size,
42
+ shape,
43
+ feedback
44
+ });
45
+ const panelApi = connectPanel({
46
+ dataComponent: "avatar",
47
+ dataAttrs: {
48
+ shape,
49
+ emphasis,
50
+ size,
51
+ feedback
52
+ },
53
+ as: "span",
54
+ background,
55
+ accent: resolvedAccent,
56
+ emphasis: panelEmphasis,
57
+ feedback,
58
+ border,
59
+ translucent: translucent ?? false,
60
+ radius,
61
+ radiusTop,
62
+ radiusBottom,
63
+ radiusLeft,
64
+ radiusRight,
65
+ padding,
66
+ shadow,
67
+ interactive,
68
+ passThrough: { root: {
69
+ style: css.raw(classes.root, passThrough?.root?.style),
70
+ props: passThrough?.root?.props
71
+ } },
72
+ class: className,
73
+ ...restProps
74
+ });
75
+ const initials = getAvatarInitials(name);
76
+ const showImage = Boolean(src);
77
+ const imageProps = showImage ? {
78
+ class: css(classes.image, passThrough?.image?.style),
79
+ src,
80
+ alt: alt ?? name ?? "",
81
+ "data-slot": "image"
82
+ } : void 0;
83
+ const fallbackProps = {
84
+ class: css(classes.fallback, passThrough?.fallback?.style),
85
+ "aria-hidden": showImage ? "true" : void 0,
86
+ "data-slot": "fallback"
87
+ };
88
+ return {
89
+ rootProps: panelApi.rootProps,
90
+ classes: {
91
+ image: css(classes.image, passThrough?.image?.style),
92
+ fallback: css(classes.fallback, passThrough?.fallback?.style)
93
+ },
94
+ initials,
95
+ showImage,
96
+ imageProps,
97
+ fallbackProps
98
+ };
99
+ }
100
+ //#endregion
101
+ export { avatarDefaults, connectAvatar, getAvatarInitials };
102
+
103
+ //# sourceMappingURL=connect-avatar.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connect-avatar.js","names":[],"sources":["../../src/connect-avatar.ts"],"sourcesContent":["import { css } from \"@pindoba/styled-system/css\";\nimport { avatarStyles } from \"@pindoba/styles-avatar\";\nimport { connectPanel } from \"@pindoba/core-panel\";\nimport type {\n PanelBackground,\n PanelBorder,\n PanelStyleProps,\n} from \"@pindoba/core-panel\";\nimport type {\n AvatarApi,\n AvatarBaseProps,\n AvatarRadius,\n AvatarSize,\n ConnectAvatarOptions,\n} from \"./types.js\";\n\nexport const avatarDefaults = {\n emphasis: \"secondary\",\n size: \"md\",\n shape: \"circle\",\n feedback: \"neutral\",\n} as const satisfies Partial<AvatarBaseProps>;\n\ntype PanelEmphasis = NonNullable<PanelStyleProps[\"emphasis\"]>;\n\n// Avatar size → panel radius. Matches button's sizing.raw radii so square\n// avatars align with same-size buttons.\nconst sizeToRadius: Record<AvatarSize, AvatarRadius> = {\n xs: \"xs\",\n sm: \"xs\",\n md: \"sm\",\n lg: \"md\",\n};\n\n/**\n * Derive up to two uppercase initials from a name. Empty / undefined input\n * returns an empty string so the consumer can render an icon fallback.\n */\nexport function getAvatarInitials(name?: string): string {\n if (!name) return \"\";\n const trimmed = name.trim();\n // Pass overflow-chip strings (\"+3\", \"+12\", …) through verbatim so the\n // avatar renders the full count instead of truncating to initials.\n if (/^\\+\\d+$/u.test(trimmed)) return trimmed.slice(0, 4);\n const parts = trimmed.split(/\\s+/u).filter(Boolean);\n if (parts.length === 0) return \"\";\n if (parts.length === 1) {\n return parts[0].slice(0, 2).toUpperCase();\n }\n return (parts[0][0] + parts[parts.length - 1][0]).toUpperCase();\n}\n\nexport function connectAvatar(options: ConnectAvatarOptions): AvatarApi {\n const {\n emphasis = avatarDefaults.emphasis,\n size = avatarDefaults.size,\n shape = avatarDefaults.shape,\n feedback: feedbackProp,\n src,\n alt,\n name,\n background: backgroundProp,\n border: borderProp,\n radius: radiusProp,\n padding: paddingProp,\n accent: accentProp,\n translucent,\n radiusTop,\n radiusBottom,\n radiusLeft,\n radiusRight,\n shadow,\n interactive,\n passThrough,\n class: className,\n ...restProps\n } = options;\n\n // Resolve feedback based on emphasis when not explicitly set.\n const feedback =\n feedbackProp ?? (emphasis === \"primary\" ? \"primary\" : \"neutral\");\n\n // Emphasis-driven panel defaults (user props always win).\n const resolvedAccent = accentProp ?? emphasis === \"primary\";\n const defaultBackground: PanelBackground =\n emphasis === \"ghost\" ? \"transparent\" : \"surface.soft\";\n const background: PanelBackground = backgroundProp ?? defaultBackground;\n\n const defaultBorder: PanelBorder =\n emphasis === \"ghost\" ? \"none\" : emphasis === \"muted\" ? \"muted\" : \"accent\";\n const border: PanelBorder = borderProp ?? defaultBorder;\n\n // Shape drives radius fallback (circle → full, square → size-scaled to\n // match button radii) unless user overrides.\n const radius: AvatarRadius =\n radiusProp ?? (shape === \"circle\" ? \"full\" : sizeToRadius[size]);\n\n // Panel owns padding; avatar never pads at the root — inner slots own spacing.\n const padding = paddingProp ?? \"none\";\n\n // Avatar \"ghost\" emphasis has no panel analogue; map to secondary so panel\n // suppresses primary colouring and avatar's own rule (color:inherit) wins.\n const panelEmphasis: PanelEmphasis | undefined =\n emphasis === \"ghost\" ? \"secondary\" : undefined;\n\n const classes = avatarStyles.raw({ emphasis, size, shape, feedback });\n\n const panelApi = connectPanel({\n dataComponent: \"avatar\",\n dataAttrs: { shape, emphasis, size, feedback },\n as: \"span\",\n background,\n accent: resolvedAccent,\n emphasis: panelEmphasis,\n feedback,\n border,\n translucent: translucent ?? false,\n radius,\n radiusTop,\n radiusBottom,\n radiusLeft,\n radiusRight,\n padding,\n shadow,\n interactive,\n passThrough: {\n root: {\n style: css.raw(classes.root, passThrough?.root?.style),\n props: passThrough?.root?.props,\n },\n },\n class: className,\n ...restProps,\n });\n\n const initials = getAvatarInitials(name);\n const showImage = Boolean(src);\n\n const imageProps = showImage\n ? {\n class: css(classes.image, passThrough?.image?.style),\n src: src!,\n alt: alt ?? name ?? \"\",\n \"data-slot\": \"image\" as const,\n }\n : undefined;\n\n const fallbackProps = {\n class: css(classes.fallback, passThrough?.fallback?.style),\n \"aria-hidden\": showImage ? (\"true\" as const) : undefined,\n \"data-slot\": \"fallback\" as const,\n };\n\n return {\n rootProps: panelApi.rootProps as AvatarApi[\"rootProps\"],\n classes: {\n image: css(classes.image, passThrough?.image?.style),\n fallback: css(classes.fallback, passThrough?.fallback?.style),\n },\n initials,\n showImage,\n imageProps,\n fallbackProps,\n };\n}\n"],"mappings":";;;;AAgBA,MAAa,iBAAiB;CAC5B,UAAU;CACV,MAAM;CACN,OAAO;CACP,UAAU;CACX;AAMD,MAAM,eAAiD;CACrD,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACL;;;;;AAMD,SAAgB,kBAAkB,MAAuB;AACvD,KAAI,CAAC,KAAM,QAAO;CAClB,MAAM,UAAU,KAAK,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;GAC3B,EACF;EACD,OAAO;EACP,GAAG;EACJ,CAAC;CAEF,MAAM,WAAW,kBAAkB,KAAK;CACxC,MAAM,YAAY,QAAQ,IAAI;CAE9B,MAAM,aAAa,YACf;EACE,OAAO,IAAI,QAAQ,OAAO,aAAa,OAAO,MAAM;EAC/C;EACL,KAAK,OAAO,QAAQ;EACpB,aAAa;EACd,GACD,KAAA;CAEJ,MAAM,gBAAgB;EACpB,OAAO,IAAI,QAAQ,UAAU,aAAa,UAAU,MAAM;EAC1D,eAAe,YAAa,SAAmB,KAAA;EAC/C,aAAa;EACd;AAED,QAAO;EACL,WAAW,SAAS;EACpB,SAAS;GACP,OAAO,IAAI,QAAQ,OAAO,aAAa,OAAO,MAAM;GACpD,UAAU,IAAI,QAAQ,UAAU,aAAa,UAAU,MAAM;GAC9D;EACD;EACA;EACA;EACA;EACD"}
@@ -0,0 +1,2 @@
1
+ import { _ as AvatarShape, a as AvatarBorder, b as ConnectAvatarOptions, c as AvatarFallbackProps, d as AvatarPadding, f as AvatarPanelProps, g as AvatarShadow, h as AvatarRootProps, i as AvatarBaseProps, l as AvatarFeedback, m as AvatarRadius, n as AvatarBackground, o as AvatarClasses, p as AvatarPassThrough, r as AvatarBaseCommon, s as AvatarEmphasis, t as AvatarApi, u as AvatarImageProps, v as AvatarSize, x as ElementAttributes, y as AvatarSlotPassThrough } from "../types-CyUSJ_FB.js";
2
+ export { AvatarApi, AvatarBackground, AvatarBaseCommon, AvatarBaseProps, AvatarBorder, AvatarClasses, AvatarEmphasis, AvatarFallbackProps, AvatarFeedback, AvatarImageProps, AvatarPadding, AvatarPanelProps, AvatarPassThrough, AvatarRadius, AvatarRootProps, AvatarShadow, AvatarShape, AvatarSize, AvatarSlotPassThrough, ConnectAvatarOptions, ElementAttributes };
@@ -0,0 +1 @@
1
+ export {};