@lobehub/ui 2.8.0 → 2.8.2

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,7 +1,7 @@
1
1
  'use client';
2
2
 
3
3
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
4
- var _excluded = ["className", "style", "avatars", "size", "smoothCornerType"];
4
+ var _excluded = ["className", "style", "avatars", "size", "cornerShape", "avatarShape"];
5
5
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
6
6
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
7
7
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
@@ -9,11 +9,11 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
9
9
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
10
10
  function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
11
11
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
12
+ import { cva } from 'class-variance-authority';
12
13
  import { memo, useMemo } from 'react';
13
14
  import Avatar from "../Avatar";
14
15
  import Block from "../Block";
15
16
  import Grid from "../Grid";
16
- import { getSmoothCornersMaskStyle } from "../utils/smoothCorners";
17
17
  import { useStyles } from "./style";
18
18
  import { jsx as _jsx } from "react/jsx-runtime";
19
19
  var GroupAvatar = /*#__PURE__*/memo(function (_ref) {
@@ -23,31 +23,51 @@ var GroupAvatar = /*#__PURE__*/memo(function (_ref) {
23
23
  avatars = _ref$avatars === void 0 ? [] : _ref$avatars,
24
24
  _ref$size = _ref.size,
25
25
  size = _ref$size === void 0 ? 32 : _ref$size,
26
- _ref$smoothCornerType = _ref.smoothCornerType,
27
- smoothCornerType = _ref$smoothCornerType === void 0 ? 'squircle' : _ref$smoothCornerType,
26
+ _ref$cornerShape = _ref.cornerShape,
27
+ cornerShape = _ref$cornerShape === void 0 ? 'squircle' : _ref$cornerShape,
28
+ _ref$avatarShape = _ref.avatarShape,
29
+ avatarShape = _ref$avatarShape === void 0 ? 'circle' : _ref$avatarShape,
28
30
  rest = _objectWithoutProperties(_ref, _excluded);
29
31
  var _useStyles = useStyles(),
30
32
  cx = _useStyles.cx,
31
33
  styles = _useStyles.styles;
32
- var smoothCornersMask = useMemo(function () {
33
- return getSmoothCornersMaskStyle(smoothCornerType);
34
- }, [smoothCornerType]);
35
34
  var calcSize = useMemo(function () {
36
- var avatarSize = Math.floor(size / 2 * 0.75);
37
- var gapSize = Math.floor((size - avatarSize * 2) / 4);
35
+ var isCircle = cornerShape === 'circle';
36
+ var avatarSize = Math.floor(size / 2 * (isCircle ? 0.65 : 0.75));
37
+ var gapSize = Math.floor((size - avatarSize * 2) / (isCircle ? 6 : 4));
38
38
  return {
39
39
  avatarSize: avatarSize,
40
40
  gapSize: gapSize,
41
41
  gridWidth: avatarSize * 2 + gapSize,
42
42
  maxItemWidth: avatarSize - 1
43
43
  };
44
- }, [size]);
44
+ }, [size, cornerShape]);
45
+ var variants = useMemo(function () {
46
+ return cva(styles.root, {
47
+ defaultVariants: {
48
+ cornerShape: 'squircle'
49
+ },
50
+ variants: {
51
+ cornerShape: {
52
+ circle: styles.circle,
53
+ ios: styles.ios,
54
+ sharp: styles.sharp,
55
+ smooth: styles.smooth,
56
+ square: styles.square,
57
+ squircle: styles.squircle
58
+ }
59
+ }
60
+ /* eslint-enable sort-keys-fix/sort-keys-fix */
61
+ });
62
+ }, [styles]);
45
63
  return /*#__PURE__*/_jsx(Block, _objectSpread(_objectSpread({
46
64
  align: 'center',
47
- className: cx(styles.root, className),
65
+ className: cx(variants({
66
+ cornerShape: cornerShape
67
+ }), className),
48
68
  height: size,
49
69
  justify: 'center',
50
- style: _objectSpread(_objectSpread({}, smoothCornersMask), style),
70
+ style: style,
51
71
  width: size
52
72
  }, rest), {}, {
53
73
  children: /*#__PURE__*/_jsx(Grid, {
@@ -59,10 +79,12 @@ var GroupAvatar = /*#__PURE__*/memo(function (_ref) {
59
79
  if (typeof item === 'string') {
60
80
  return /*#__PURE__*/_jsx(Avatar, {
61
81
  avatar: item,
82
+ shape: avatarShape,
62
83
  size: calcSize.avatarSize
63
84
  }, index);
64
85
  }
65
86
  return /*#__PURE__*/_jsx(Avatar, _objectSpread(_objectSpread({}, item), {}, {
87
+ shape: avatarShape,
66
88
  size: calcSize.avatarSize
67
89
  }), index);
68
90
  })
@@ -1,3 +1,9 @@
1
1
  export declare const useStyles: (props?: unknown) => import("antd-style").ReturnStyles<{
2
+ circle: import("antd-style").SerializedStyles;
3
+ ios: import("antd-style").SerializedStyles;
2
4
  root: import("antd-style").SerializedStyles;
5
+ sharp: import("antd-style").SerializedStyles;
6
+ smooth: import("antd-style").SerializedStyles;
7
+ square: import("antd-style").SerializedStyles;
8
+ squircle: import("antd-style").SerializedStyles;
3
9
  }>;
@@ -1,9 +1,20 @@
1
- var _templateObject;
1
+ var _templateObject, _templateObject2;
2
2
  function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
3
3
  import { createStyles } from 'antd-style';
4
+ import { SMOOTH_CORNER_MASKS } from "../utils/smoothCorners";
4
5
  export var useStyles = createStyles(function (_ref) {
5
6
  var css = _ref.css;
7
+ var baseRoot = css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n overflow: hidden;\n flex: none;\n\n /* Fallback for browsers without mask support */\n border-radius: 15%;\n\n /* Apply smooth corners mask with fallback */\n @supports (mask-image: url('data:image/svg+xml;base64,')) {\n border-radius: 0;\n }\n "])));
8
+ var createCornerVariant = function createCornerVariant(cornerType) {
9
+ return css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n /* WebKit prefix for better browser support */\n mask-image: url('", "');\n\n mask-image: url('", "');\n mask-position: center;\n mask-position: center;\n mask-repeat: no-repeat;\n mask-repeat: no-repeat;\n mask-size: 100% 100%;\n mask-size: 100% 100%;\n "])), SMOOTH_CORNER_MASKS[cornerType], SMOOTH_CORNER_MASKS[cornerType]);
10
+ };
6
11
  return {
7
- root: css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n overflow: hidden;\n flex: none;\n\n /* Fallback for browsers without mask support */\n border-radius: 15%;\n\n /* Apply smooth corners mask with fallback */\n @supports (mask-image: url('data:image/svg+xml;base64,')) {\n border-radius: 0;\n\n /* The mask will be applied via inline style */\n }\n "])))
12
+ circle: createCornerVariant('circle'),
13
+ ios: createCornerVariant('ios'),
14
+ root: baseRoot,
15
+ sharp: createCornerVariant('sharp'),
16
+ smooth: createCornerVariant('smooth'),
17
+ square: createCornerVariant('square'),
18
+ squircle: createCornerVariant('squircle')
8
19
  };
9
20
  });
@@ -4,9 +4,10 @@ import type { BlockProps } from "../Block/type";
4
4
  import type { SMOOTH_CORNER_MASKS } from "../utils/smoothCorners";
5
5
  type AvatarItem = string | Omit<AvatarProps, 'size'>;
6
6
  export interface GroupAvatarProps extends Omit<BlockProps, 'width' | 'height' | 'variant'> {
7
+ avatarShape?: AvatarProps['shape'];
7
8
  avatars?: AvatarItem[];
9
+ cornerShape?: keyof typeof SMOOTH_CORNER_MASKS;
8
10
  ref?: Ref<HTMLDivElement>;
9
11
  size?: number;
10
- smoothCornerType?: keyof typeof SMOOTH_CORNER_MASKS;
11
12
  }
12
13
  export {};
package/es/Text/Text.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use client';
2
2
 
3
- var _excluded = ["as", "className", "children", "style", "type", "disabled", "strong", "italic", "underline", "delete", "fontSize", "mark", "code", "color", "weight", "ellipsis"];
3
+ var _excluded = ["as", "align", "className", "children", "style", "type", "disabled", "strong", "italic", "underline", "delete", "fontSize", "mark", "code", "color", "weight", "ellipsis"];
4
4
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
5
5
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
6
6
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
@@ -17,6 +17,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
17
17
  var Text = /*#__PURE__*/memo(function (_ref) {
18
18
  var _ref$as = _ref.as,
19
19
  Container = _ref$as === void 0 ? 'div' : _ref$as,
20
+ align = _ref.align,
20
21
  className = _ref.className,
21
22
  children = _ref.children,
22
23
  style = _ref.style,
@@ -83,7 +84,7 @@ var Text = /*#__PURE__*/memo(function (_ref) {
83
84
  }
84
85
  });
85
86
  }, [styles]);
86
- var textStyle = _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({}, color && {
87
+ var textStyle = _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({}, color && {
87
88
  color: color
88
89
  }), weight && {
89
90
  fontWeight: weight
@@ -91,6 +92,8 @@ var Text = /*#__PURE__*/memo(function (_ref) {
91
92
  WebkitLineClamp: ellipsis.rows
92
93
  }), fontSize && {
93
94
  fontSize: fontSize
95
+ }), align && {
96
+ textAlign: align
94
97
  }), style);
95
98
  var content = /*#__PURE__*/_jsx(Container, _objectSpread(_objectSpread({
96
99
  className: cx(variants({
package/es/Text/type.d.ts CHANGED
@@ -2,6 +2,7 @@ import type { ElementType, Ref } from 'react';
2
2
  import type { TooltipProps } from "../Tooltip";
3
3
  import { DivProps } from "../types";
4
4
  export interface TextProps extends DivProps {
5
+ align?: 'left' | 'center' | 'right';
5
6
  as?: ElementType;
6
7
  code?: boolean;
7
8
  color?: string;
@@ -7,13 +7,30 @@ export declare const createSmoothCornersMask: (options?: {
7
7
  cornerValue?: number;
8
8
  size?: number;
9
9
  }) => string;
10
+ /**
11
+ * Create a Base64 encoded SVG mask for circle shape
12
+ * @param options - Configuration options
13
+ */
14
+ export declare const createCircleMask: (options?: {
15
+ size?: number;
16
+ }) => string;
17
+ /**
18
+ * Create a Base64 encoded SVG mask for rounded rectangle
19
+ * @param options - Configuration options
20
+ */
21
+ export declare const createRoundedRectMask: (options?: {
22
+ borderRadius?: number;
23
+ size?: number;
24
+ }) => string;
10
25
  /**
11
26
  * Predefined smooth corners masks for common corner values
12
27
  */
13
28
  export declare const SMOOTH_CORNER_MASKS: {
29
+ readonly circle: string;
14
30
  readonly ios: string;
15
31
  readonly sharp: string;
16
32
  readonly smooth: string;
33
+ readonly square: string;
17
34
  readonly squircle: string;
18
35
  };
19
36
  /**
@@ -42,25 +42,55 @@ export var createSmoothCornersMask = function createSmoothCornersMask() {
42
42
  return "data:image/svg+xml;base64,".concat(btoa(svg));
43
43
  };
44
44
 
45
+ /**
46
+ * Create a Base64 encoded SVG mask for circle shape
47
+ * @param options - Configuration options
48
+ */
49
+ export var createCircleMask = function createCircleMask() {
50
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
51
+ var _options$size2 = options.size,
52
+ size = _options$size2 === void 0 ? 100 : _options$size2;
53
+ var r = size / 2;
54
+ var svg = "\n <svg width=\"".concat(size, "\" height=\"").concat(size, "\" viewBox=\"0 0 ").concat(size, " ").concat(size, "\" xmlns=\"http://www.w3.org/2000/svg\">\n <circle cx=\"").concat(r, "\" cy=\"").concat(r, "\" r=\"").concat(r, "\" fill=\"white\"/>\n </svg>\n ").trim().replaceAll(/\s+/g, ' ');
55
+ return "data:image/svg+xml;base64,".concat(btoa(svg));
56
+ };
57
+
58
+ /**
59
+ * Create a Base64 encoded SVG mask for rounded rectangle
60
+ * @param options - Configuration options
61
+ */
62
+ export var createRoundedRectMask = function createRoundedRectMask() {
63
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
64
+ var _options$size3 = options.size,
65
+ size = _options$size3 === void 0 ? 100 : _options$size3,
66
+ _options$borderRadius = options.borderRadius,
67
+ borderRadius = _options$borderRadius === void 0 ? 15 : _options$borderRadius;
68
+ var svg = "\n <svg width=\"".concat(size, "\" height=\"").concat(size, "\" viewBox=\"0 0 ").concat(size, " ").concat(size, "\" xmlns=\"http://www.w3.org/2000/svg\">\n <rect x=\"0\" y=\"0\" width=\"").concat(size, "\" height=\"").concat(size, "\" rx=\"").concat(borderRadius, "\" ry=\"").concat(borderRadius, "\" fill=\"white\"/>\n </svg>\n ").trim().replaceAll(/\s+/g, ' ');
69
+ return "data:image/svg+xml;base64,".concat(btoa(svg));
70
+ };
71
+
45
72
  /**
46
73
  * Predefined smooth corners masks for common corner values
47
74
  */
48
75
  export var SMOOTH_CORNER_MASKS = {
49
- // n=4, classic squircle
76
+ // Basic shapes
77
+ circle: createCircleMask(),
78
+ // Superellipse shapes
50
79
  ios: createSmoothCornersMask({
51
80
  cornerValue: 5
52
81
  }),
53
- // n=3, more rounded
54
82
  sharp: createSmoothCornersMask({
55
83
  cornerValue: 6
56
84
  }),
57
- // n=5, iOS style
58
85
  smooth: createSmoothCornersMask({
59
86
  cornerValue: 3
60
87
  }),
88
+ square: createRoundedRectMask({
89
+ borderRadius: 15
90
+ }),
61
91
  squircle: createSmoothCornersMask({
62
92
  cornerValue: 4
63
- }) // n=6, less rounded
93
+ })
64
94
  };
65
95
 
66
96
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/ui",
3
- "version": "2.8.0",
3
+ "version": "2.8.2",
4
4
  "description": "Lobe UI is an open-source UI component library for building AIGC web apps",
5
5
  "keywords": [
6
6
  "lobehub",