@hh.ru/magritte-ui-button 6.0.23 → 7.0.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/Button.js CHANGED
@@ -1,19 +1,22 @@
1
1
  import './index.css';
2
2
  import { jsx, jsxs } from 'react/jsx-runtime';
3
- import React, { forwardRef } from 'react';
3
+ import React, { forwardRef, useRef } from 'react';
4
+ import { CSSTransition } from 'react-transition-group';
4
5
  import classnames from 'classnames';
5
6
  import { useDisabled } from '@hh.ru/magritte-common-use-disabled';
7
+ import { tokenSemanticAnimationTimeMDuration } from '@hh.ru/magritte-design-tokens/types';
6
8
  import { ComponentWithBadge } from '@hh.ru/magritte-ui-badge';
7
9
  import { useButton } from './aria.js';
8
10
  import { Loader } from '@hh.ru/magritte-ui-loader';
9
11
 
10
- var styles = {"button":"magritte-button___Pubhr_6-0-23","button_loading":"magritte-button_loading___tSd9G_6-0-23","buttonLoading":"magritte-button__loading___lYs93_6-0-23","button-view":"magritte-button-view___53Slm_6-0-23","buttonView":"magritte-button-view___53Slm_6-0-23","button__content":"magritte-button__content___BXYU0_6-0-23","buttonContent":"magritte-button__content___BXYU0_6-0-23","button_size-medium":"magritte-button_size-medium___WvUsb_6-0-23","buttonSizeMedium":"magritte-button_size-medium___WvUsb_6-0-23","button_size-large":"magritte-button_size-large___Gjw7e_6-0-23","buttonSizeLarge":"magritte-button_size-large___Gjw7e_6-0-23","button__label":"magritte-button__label___zplmt_6-0-23","buttonLabel":"magritte-button__label___zplmt_6-0-23","button__subcaption":"magritte-button__subcaption___SSASN_6-0-23","buttonSubcaption":"magritte-button_subcaption___0-hG0_6-0-23","button_size-small":"magritte-button_size-small___ZAmsS_6-0-23","buttonSizeSmall":"magritte-button_size-small___ZAmsS_6-0-23","button_stretched":"magritte-button_stretched___-aXS6_6-0-23","buttonStretched":"magritte-button_stretched___-aXS6_6-0-23","button-postfix":"magritte-button-postfix___0rpTU_6-0-23","buttonPostfix":"magritte-button-postfix___0rpTU_6-0-23","button__icon":"magritte-button__icon___912gw_6-0-23","buttonIcon":"magritte-button__icon___912gw_6-0-23","button_with-icon":"magritte-button_with-icon___znqnP_6-0-23","buttonWithIcon":"magritte-button_with-icon___znqnP_6-0-23","button_with-postfix":"magritte-button_with-postfix___iB7I6_6-0-23","buttonWithPostfix":"magritte-button_with-postfix___iB7I6_6-0-23","button_centred":"magritte-button_centred___7nw81_6-0-23","buttonCentred":"magritte-button_centred___7nw81_6-0-23","button_subcaption":"magritte-button_subcaption___0-hG0_6-0-23","button_textless":"magritte-button_textless___XBvNJ_6-0-23","buttonTextless":"magritte-button_textless___XBvNJ_6-0-23","button__loading":"magritte-button__loading___lYs93_6-0-23","button_style-neutral":"magritte-button_style-neutral___I5qS5_6-0-23","buttonStyleNeutral":"magritte-button_style-neutral___I5qS5_6-0-23","button_mode-primary":"magritte-button_mode-primary___wU8PN_6-0-23","buttonModePrimary":"magritte-button_mode-primary___wU8PN_6-0-23","button_mode-secondary":"magritte-button_mode-secondary___xYz4-_6-0-23","buttonModeSecondary":"magritte-button_mode-secondary___xYz4-_6-0-23","button_mode-tertiary":"magritte-button_mode-tertiary___ZMpad_6-0-23","buttonModeTertiary":"magritte-button_mode-tertiary___ZMpad_6-0-23","button_style-accent":"magritte-button_style-accent___TE21J_6-0-23","buttonStyleAccent":"magritte-button_style-accent___TE21J_6-0-23","button_style-positive":"magritte-button_style-positive___i-dJx_6-0-23","buttonStylePositive":"magritte-button_style-positive___i-dJx_6-0-23","button_style-negative":"magritte-button_style-negative___B2CVQ_6-0-23","buttonStyleNegative":"magritte-button_style-negative___B2CVQ_6-0-23","button_style-contrast":"magritte-button_style-contrast___mxXt-_6-0-23","buttonStyleContrast":"magritte-button_style-contrast___mxXt-_6-0-23","button_style-special":"magritte-button_style-special___qi7Yf_6-0-23","buttonStyleSpecial":"magritte-button_style-special___qi7Yf_6-0-23","button-postfix_size-large":"magritte-button-postfix_size-large___6fupR_6-0-23","buttonPostfixSizeLarge":"magritte-button-postfix_size-large___6fupR_6-0-23","button-postfix_size-medium":"magritte-button-postfix_size-medium___CKs6F_6-0-23","buttonPostfixSizeMedium":"magritte-button-postfix_size-medium___CKs6F_6-0-23","button-postfix_size-small":"magritte-button-postfix_size-small___p9vHk_6-0-23","buttonPostfixSizeSmall":"magritte-button-postfix_size-small___p9vHk_6-0-23"};
12
+ var styles = {"button":"magritte-button___Pubhr_7-0-0","button_loading":"magritte-button_loading___tSd9G_7-0-0","buttonLoading":"magritte-button__loading___lYs93_7-0-0","button-view":"magritte-button-view___53Slm_7-0-0","buttonView":"magritte-button-view___53Slm_7-0-0","button__content":"magritte-button__content___BXYU0_7-0-0","buttonContent":"magritte-button__content___BXYU0_7-0-0","button_size-medium":"magritte-button_size-medium___WvUsb_7-0-0","buttonSizeMedium":"magritte-button_size-medium___WvUsb_7-0-0","button_size-large":"magritte-button_size-large___Gjw7e_7-0-0","buttonSizeLarge":"magritte-button_size-large___Gjw7e_7-0-0","button__label":"magritte-button__label___zplmt_7-0-0","buttonLabel":"magritte-button__label___zplmt_7-0-0","button__subcaption":"magritte-button__subcaption___SSASN_7-0-0","buttonSubcaption":"magritte-button_subcaption___0-hG0_7-0-0","button_size-small":"magritte-button_size-small___ZAmsS_7-0-0","buttonSizeSmall":"magritte-button_size-small___ZAmsS_7-0-0","button_stretched":"magritte-button_stretched___-aXS6_7-0-0","buttonStretched":"magritte-button_stretched___-aXS6_7-0-0","button-postfix":"magritte-button-postfix___0rpTU_7-0-0","buttonPostfix":"magritte-button-postfix___0rpTU_7-0-0","button__icon":"magritte-button__icon___912gw_7-0-0","buttonIcon":"magritte-button__icon___912gw_7-0-0","button_with-icon":"magritte-button_with-icon___znqnP_7-0-0","buttonWithIcon":"magritte-button_with-icon___znqnP_7-0-0","button_with-postfix":"magritte-button_with-postfix___iB7I6_7-0-0","buttonWithPostfix":"magritte-button_with-postfix___iB7I6_7-0-0","button_centred":"magritte-button_centred___7nw81_7-0-0","buttonCentred":"magritte-button_centred___7nw81_7-0-0","button_subcaption":"magritte-button_subcaption___0-hG0_7-0-0","button_textless":"magritte-button_textless___XBvNJ_7-0-0","buttonTextless":"magritte-button_textless___XBvNJ_7-0-0","button__loading":"magritte-button__loading___lYs93_7-0-0","animation-timeout":"magritte-animation-timeout___IVFRG_7-0-0","animationTimeout":"magritte-animation-timeout___IVFRG_7-0-0","enter-animation":"magritte-enter-animation___tJoZW_7-0-0","enterAnimation":"magritte-enter-animation___tJoZW_7-0-0","enter-animation-active":"magritte-enter-animation-active___RRYSD_7-0-0","enterAnimationActive":"magritte-enter-animation-active___RRYSD_7-0-0","exit-animation":"magritte-exit-animation___BleRA_7-0-0","exitAnimation":"magritte-exit-animation___BleRA_7-0-0","exit-animation-active":"magritte-exit-animation-active___i0EAM_7-0-0","exitAnimationActive":"magritte-exit-animation-active___i0EAM_7-0-0","button_style-neutral":"magritte-button_style-neutral___I5qS5_7-0-0","buttonStyleNeutral":"magritte-button_style-neutral___I5qS5_7-0-0","button_mode-primary":"magritte-button_mode-primary___wU8PN_7-0-0","buttonModePrimary":"magritte-button_mode-primary___wU8PN_7-0-0","button_mode-secondary":"magritte-button_mode-secondary___xYz4-_7-0-0","buttonModeSecondary":"magritte-button_mode-secondary___xYz4-_7-0-0","on-surface":"magritte-on-surface___sOxCu_7-0-0","onSurface":"magritte-on-surface___sOxCu_7-0-0","button_mode-tertiary":"magritte-button_mode-tertiary___ZMpad_7-0-0","buttonModeTertiary":"magritte-button_mode-tertiary___ZMpad_7-0-0","button_style-accent":"magritte-button_style-accent___TE21J_7-0-0","buttonStyleAccent":"magritte-button_style-accent___TE21J_7-0-0","button_style-positive":"magritte-button_style-positive___i-dJx_7-0-0","buttonStylePositive":"magritte-button_style-positive___i-dJx_7-0-0","button_style-negative":"magritte-button_style-negative___B2CVQ_7-0-0","buttonStyleNegative":"magritte-button_style-negative___B2CVQ_7-0-0","button_style-constant":"magritte-button_style-constant___vP0wU_7-0-0","buttonStyleConstant":"magritte-button_style-constant___vP0wU_7-0-0","button_style-special":"magritte-button_style-special___qi7Yf_7-0-0","buttonStyleSpecial":"magritte-button_style-special___qi7Yf_7-0-0","button-postfix_size-large":"magritte-button-postfix_size-large___6fupR_7-0-0","buttonPostfixSizeLarge":"magritte-button-postfix_size-large___6fupR_7-0-0","button-postfix_size-medium":"magritte-button-postfix_size-medium___CKs6F_7-0-0","buttonPostfixSizeMedium":"magritte-button-postfix_size-medium___CKs6F_7-0-0","button-postfix_size-small":"magritte-button-postfix_size-small___p9vHk_7-0-0","buttonPostfixSizeSmall":"magritte-button-postfix_size-small___p9vHk_7-0-0"};
11
13
 
12
14
  const ALLOWED_BADGE_SIZES = ['small', 'extra-small'];
13
15
  const ButtonForwardRefRenderFunc = (props, ref) => {
14
- const { 'aria-label': ariaLabel, children, postfix, Element = 'button', hideLabel = false, icon, loading, mode, size = 'medium', stretched, style = 'neutral', subcaption, type = 'button', disabled, badge, spaceBetween = true, ...buttonProps } = props;
16
+ const { 'aria-label': ariaLabel, children, postfix, Element = 'button', hideLabel = false, icon, loading, mode, size = 'medium', stretched, style = 'neutral', subcaption, type = 'button', disabled, badge, spaceBetween = true, onSurface, ...buttonProps } = props;
15
17
  const forceDisabled = useDisabled();
16
18
  const { ariaProps: additionalAttributes } = useButton({ disabled: !!disabled || forceDisabled, Element });
19
+ const loaderRef = useRef(null);
17
20
  if (Element === 'button') {
18
21
  additionalAttributes.type = type;
19
22
  }
@@ -30,6 +33,7 @@ const ButtonForwardRefRenderFunc = (props, ref) => {
30
33
  const button = (jsx(Element, { className: classnames(styles.button, {
31
34
  [styles[`button_mode-${mode}`]]: mode,
32
35
  [styles[`button_size-${size}`]]: size,
36
+ [styles.onSurface]: !!onSurface,
33
37
  [styles.button_stretched]: stretched,
34
38
  [styles.button_subcaption]: withSubcaption,
35
39
  [styles.button_textless]: !withSubcaption && (hideLabel || !children) && !postfix,
@@ -40,7 +44,12 @@ const ButtonForwardRefRenderFunc = (props, ref) => {
40
44
  [styles.buttonCentred]: !spaceBetween,
41
45
  }), disabled: forceDisabled || !!disabled, tabIndex: loading ? -1 : undefined, ...additionalAttributes, ...buttonProps, children: jsx("span", { className: styles.buttonView, children: jsxs("span", { className: styles.button__content, children: [postfix && (jsx("span", { className: classnames(styles.buttonPostfix, {
42
46
  [styles[`button-postfix_size-${size}`]]: size,
43
- }), children: postfix })), icon && (jsx("span", { className: styles.button__icon, children: React.cloneElement(icon, hideLabel ? { 'aria-label': ariaLabel } : { 'aria-hidden': true, focusable: false }) })), children && !hideLabel && jsx("span", { className: styles.button__label, children: children }), withSubcaption && jsx("span", { className: styles.button__subcaption, children: subcaption }), loading && (jsx("span", { className: styles.button__loading, children: jsx(Loader, {}) }))] }) }) }));
47
+ }), children: postfix })), icon && (jsx("span", { className: styles.button__icon, children: React.cloneElement(icon, hideLabel ? { 'aria-label': ariaLabel } : { 'aria-hidden': true, focusable: false }) })), children && !hideLabel && jsx("span", { className: styles.button__label, children: children }), withSubcaption && jsx("span", { className: styles.button__subcaption, children: subcaption }), jsx(CSSTransition, { in: loading, nodeRef: loaderRef, timeout: tokenSemanticAnimationTimeMDuration, classNames: {
48
+ enter: styles.enterAnimation,
49
+ enterActive: styles.enterAnimationActive,
50
+ exit: styles.exitAnimation,
51
+ exitActive: styles.exitAnimationActive,
52
+ }, unmountOnExit: true, children: jsx("span", { className: styles.button__loading, ref: loaderRef, children: jsx(Loader, {}) }) })] }) }) }));
44
53
  if (badge && !disabled && !forceDisabled) {
45
54
  return (jsx(ComponentWithBadge, { allowedSizes: ALLOWED_BADGE_SIZES, badge: badge, stretched: stretched, children: button }));
46
55
  }
package/Button.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"Button.js","sources":["../src/Button.tsx"],"sourcesContent":["import React, { forwardRef } from 'react';\nimport classnames from 'classnames';\n\nimport { useDisabled } from '@hh.ru/magritte-common-use-disabled';\nimport type { PolymorphicForwardRefRenderFunc, PolymorphicComponentWithRef } from '@hh.ru/magritte-types';\nimport { BadgeSize, ComponentWithBadge } from '@hh.ru/magritte-ui-badge';\nimport { useButton } from '@hh.ru/magritte-ui-button/aria';\nimport type { ButtonProps } from '@hh.ru/magritte-ui-button/types';\nimport { Loader } from '@hh.ru/magritte-ui-loader';\n\nimport styles from './button.less';\n\nconst ALLOWED_BADGE_SIZES: BadgeSize[] = ['small', 'extra-small'];\n\nconst ButtonForwardRefRenderFunc: PolymorphicForwardRefRenderFunc<ButtonProps, 'button'> = (props, ref) => {\n const {\n 'aria-label': ariaLabel,\n children,\n postfix,\n Element = 'button',\n hideLabel = false,\n icon,\n loading,\n mode,\n size = 'medium',\n stretched,\n style = 'neutral',\n subcaption,\n type = 'button',\n disabled,\n badge,\n spaceBetween = true,\n ...buttonProps\n } = props;\n\n const forceDisabled = useDisabled();\n const { ariaProps: additionalAttributes } = useButton({ disabled: !!disabled || forceDisabled, Element });\n\n if (Element === 'button') {\n additionalAttributes.type = type;\n }\n\n if (ref) {\n /**\n * Element может быть простой функцией поэтому напрямую\n * нельзя назначать ref\n * А может быть forwardRef, ClassComponent и простой тег,\n * поэтому в обход типизации назначаем ref как unknown\n */\n additionalAttributes.ref = ref;\n }\n\n const withSubcaption = size !== 'small' && subcaption;\n\n const button = (\n <Element\n className={classnames(styles.button, {\n [styles[`button_mode-${mode}`]]: mode,\n [styles[`button_size-${size}`]]: size,\n [styles.button_stretched]: stretched,\n [styles.button_subcaption]: withSubcaption,\n [styles.button_textless]: !withSubcaption && (hideLabel || !children) && !postfix,\n [styles.button_loading]: loading,\n [styles[`button_style-${style}`]]: style,\n [styles.buttonWithIcon]: !!icon,\n [styles.buttonWithPostfix]: !!postfix,\n [styles.buttonCentred]: !spaceBetween,\n })}\n disabled={forceDisabled || !!disabled}\n tabIndex={loading ? -1 : undefined}\n {...additionalAttributes}\n {...buttonProps}\n >\n <span className={styles.buttonView}>\n <span className={styles.button__content}>\n {postfix && (\n <span\n className={classnames(styles.buttonPostfix, {\n [styles[`button-postfix_size-${size}`]]: size,\n })}\n >\n {postfix}\n </span>\n )}\n {icon && (\n <span className={styles.button__icon}>\n {React.cloneElement(\n icon,\n hideLabel ? { 'aria-label': ariaLabel } : { 'aria-hidden': true, focusable: false }\n )}\n </span>\n )}\n {children && !hideLabel && <span className={styles.button__label}>{children}</span>}\n {withSubcaption && <span className={styles.button__subcaption}>{subcaption}</span>}\n {loading && (\n <span className={styles.button__loading}>\n <Loader />\n </span>\n )}\n </span>\n </span>\n </Element>\n );\n\n if (badge && !disabled && !forceDisabled) {\n return (\n <ComponentWithBadge allowedSizes={ALLOWED_BADGE_SIZES} badge={badge} stretched={stretched}>\n {button}\n </ComponentWithBadge>\n );\n }\n\n return button;\n};\n\nexport const Button = forwardRef(ButtonForwardRefRenderFunc) as PolymorphicComponentWithRef<ButtonProps, 'button'>;\n\nexport const STRETCHED_WRAPPER_CLASS = 'magritte-button-stretched-wrapper';\n"],"names":["_jsx","_jsxs"],"mappings":";;;;;;;;;;AAYA,MAAM,mBAAmB,GAAgB,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC;AAElE,MAAM,0BAA0B,GAA2D,CAAC,KAAK,EAAE,GAAG,KAAI;IACtG,MAAM,EACF,YAAY,EAAE,SAAS,EACvB,QAAQ,EACR,OAAO,EACP,OAAO,GAAG,QAAQ,EAClB,SAAS,GAAG,KAAK,EACjB,IAAI,EACJ,OAAO,EACP,IAAI,EACJ,IAAI,GAAG,QAAQ,EACf,SAAS,EACT,KAAK,GAAG,SAAS,EACjB,UAAU,EACV,IAAI,GAAG,QAAQ,EACf,QAAQ,EACR,KAAK,EACL,YAAY,GAAG,IAAI,EACnB,GAAG,WAAW,EACjB,GAAG,KAAK,CAAC;AAEV,IAAA,MAAM,aAAa,GAAG,WAAW,EAAE,CAAC;IACpC,MAAM,EAAE,SAAS,EAAE,oBAAoB,EAAE,GAAG,SAAS,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,QAAQ,IAAI,aAAa,EAAE,OAAO,EAAE,CAAC,CAAC;AAE1G,IAAA,IAAI,OAA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E5G,MAAM,uBAAuB,GAAG;;;;"}
1
+ {"version":3,"file":"Button.js","sources":["../src/Button.tsx"],"sourcesContent":["import React, { forwardRef, useRef } from 'react';\nimport { CSSTransition } from 'react-transition-group';\nimport classnames from 'classnames';\n\nimport { useDisabled } from '@hh.ru/magritte-common-use-disabled';\nimport { tokenSemanticAnimationTimeMDuration } from '@hh.ru/magritte-design-tokens/types';\nimport type { PolymorphicForwardRefRenderFunc, PolymorphicComponentWithRef } from '@hh.ru/magritte-types';\nimport { BadgeSize, ComponentWithBadge } from '@hh.ru/magritte-ui-badge';\nimport { useButton } from '@hh.ru/magritte-ui-button/aria';\nimport type { ButtonProps } from '@hh.ru/magritte-ui-button/types';\nimport { Loader } from '@hh.ru/magritte-ui-loader';\n\nimport styles from './button.less';\n\nconst ALLOWED_BADGE_SIZES: BadgeSize[] = ['small', 'extra-small'];\n\nconst ButtonForwardRefRenderFunc: PolymorphicForwardRefRenderFunc<ButtonProps, 'button'> = (props, ref) => {\n const {\n 'aria-label': ariaLabel,\n children,\n postfix,\n Element = 'button',\n hideLabel = false,\n icon,\n loading,\n mode,\n size = 'medium',\n stretched,\n style = 'neutral',\n subcaption,\n type = 'button',\n disabled,\n badge,\n spaceBetween = true,\n onSurface,\n ...buttonProps\n } = props;\n\n const forceDisabled = useDisabled();\n const { ariaProps: additionalAttributes } = useButton({ disabled: !!disabled || forceDisabled, Element });\n const loaderRef = useRef<HTMLSpanElement>(null);\n\n if (Element === 'button') {\n additionalAttributes.type = type;\n }\n\n if (ref) {\n /**\n * Element может быть простой функцией поэтому напрямую\n * нельзя назначать ref\n * А может быть forwardRef, ClassComponent и простой тег,\n * поэтому в обход типизации назначаем ref как unknown\n */\n additionalAttributes.ref = ref;\n }\n\n const withSubcaption = size !== 'small' && subcaption;\n\n const button = (\n <Element\n className={classnames(styles.button, {\n [styles[`button_mode-${mode}`]]: mode,\n [styles[`button_size-${size}`]]: size,\n [styles.onSurface]: !!onSurface,\n [styles.button_stretched]: stretched,\n [styles.button_subcaption]: withSubcaption,\n [styles.button_textless]: !withSubcaption && (hideLabel || !children) && !postfix,\n [styles.button_loading]: loading,\n [styles[`button_style-${style}`]]: style,\n [styles.buttonWithIcon]: !!icon,\n [styles.buttonWithPostfix]: !!postfix,\n [styles.buttonCentred]: !spaceBetween,\n })}\n disabled={forceDisabled || !!disabled}\n tabIndex={loading ? -1 : undefined}\n {...additionalAttributes}\n {...buttonProps}\n >\n <span className={styles.buttonView}>\n <span className={styles.button__content}>\n {postfix && (\n <span\n className={classnames(styles.buttonPostfix, {\n [styles[`button-postfix_size-${size}`]]: size,\n })}\n >\n {postfix}\n </span>\n )}\n {icon && (\n <span className={styles.button__icon}>\n {React.cloneElement(\n icon,\n hideLabel ? { 'aria-label': ariaLabel } : { 'aria-hidden': true, focusable: false }\n )}\n </span>\n )}\n {children && !hideLabel && <span className={styles.button__label}>{children}</span>}\n {withSubcaption && <span className={styles.button__subcaption}>{subcaption}</span>}\n <CSSTransition\n in={loading}\n nodeRef={loaderRef}\n timeout={tokenSemanticAnimationTimeMDuration}\n classNames={{\n enter: styles.enterAnimation,\n enterActive: styles.enterAnimationActive,\n exit: styles.exitAnimation,\n exitActive: styles.exitAnimationActive,\n }}\n unmountOnExit\n >\n <span className={styles.button__loading} ref={loaderRef}>\n <Loader />\n </span>\n </CSSTransition>\n </span>\n </span>\n </Element>\n );\n\n if (badge && !disabled && !forceDisabled) {\n return (\n <ComponentWithBadge allowedSizes={ALLOWED_BADGE_SIZES} badge={badge} stretched={stretched}>\n {button}\n </ComponentWithBadge>\n );\n }\n\n return button;\n};\n\nexport const Button = forwardRef(ButtonForwardRefRenderFunc) as PolymorphicComponentWithRef<ButtonProps, 'button'>;\n\nexport const STRETCHED_WRAPPER_CLASS = 'magritte-button-stretched-wrapper';\n"],"names":["_jsx","_jsxs"],"mappings":";;;;;;;;;;;;AAcA,MAAM,mBAAmB,GAAgB,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC;AAElE,MAAM,0BAA0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