@okta/odyssey-react-mui 1.9.15 → 1.9.16
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/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,12 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [1.9.16](https://github.com/okta/odyssey/compare/v1.9.15...v1.9.16) (2024-01-08)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
- (odyssey-react-mui): move variable declaration below import ([#2082](https://github.com/okta/odyssey/issues/2082)) ([910e4fc](https://github.com/okta/odyssey/commit/910e4fc120371df48cfc5908f06e175c61cbcaba))
|
|
11
|
+
|
|
6
12
|
## [1.9.15](https://github.com/okta/odyssey/compare/v1.9.14...v1.9.15) (2024-01-08)
|
|
7
13
|
|
|
8
14
|
**Note:** Version bump only for package @okta/odyssey-react-mui
|
package/dist/labs/Switch.js
CHANGED
|
@@ -13,9 +13,6 @@ import _Switch from "@mui/material/Switch";
|
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
15
|
import { memo, useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
16
|
-
const {
|
|
17
|
-
CONTROLLED
|
|
18
|
-
} = ComponentControlledState;
|
|
19
16
|
import { useOdysseyDesignTokens } from "../OdysseyDesignTokensContext.js";
|
|
20
17
|
import { Box } from "../Box.js";
|
|
21
18
|
import { FieldHint } from "../FieldHint.js";
|
|
@@ -24,6 +21,9 @@ import { ComponentControlledState, getControlState } from "../inputUtils.js";
|
|
|
24
21
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
25
22
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
26
23
|
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
24
|
+
const {
|
|
25
|
+
CONTROLLED
|
|
26
|
+
} = ComponentControlledState;
|
|
27
27
|
const SwitchLabel = _ref => {
|
|
28
28
|
let {
|
|
29
29
|
checked,
|
package/dist/labs/Switch.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Switch.js","names":["memo","useCallback","useEffect","useMemo","useRef","useState","CONTROLLED","ComponentControlledState","useOdysseyDesignTokens","Box","FieldHint","useUniqueId","getControlState","jsx","_jsx","jsxs","_jsxs","Fragment","_Fragment","SwitchLabel","_ref","checked","hint","hintId","isFullWidth","label","odysseyDesignTokens","children","sx","display","alignItems","flexWrap","gap","Spacing1","margin","maxWidth","TypographyLineLengthMax","fontWeight","TypographyWeightBodyBold","padding","backgroundColor","PaletteSuccessLighter","HueNeutral100","borderRadius","BorderRadiusMain","color","PaletteSuccessText","HueNeutral700","fontSize","TypographyScale0","lineHeight","TypographyLineHeightOverline","transitionProperty","transitionDuration","TransitionDurationMain","id","text","Switch","_ref2","_id","isChecked","isDefaultChecked","isDisabled","name","_name","onChange","testId","value","controlledStateRef","controlledValue","uncontrolledValue","inputValues","current","defaultChecked","internalSwitchChecked","setInternalSwitchChecked","Boolean","undefined","labelElementId","handleOnChange","_","renderSwitchComponent","_Switch","disabled","disableRipple","inputProps","marginBlockEnd","Spacing2","_FormControlLabel","control","labelPlacement","justifyContent","Spacing4","width","MemoizedSwitch","displayName"],"sources":["../../src/labs/Switch.tsx"],"sourcesContent":["/*!\n * Copyright (c) 2022-present, Okta, Inc. and/or its affiliates. All rights reserved.\n * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the \"License.\")\n *\n * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n *\n * See the License for the specific language governing permissions and limitations under the License.\n */\n\nimport {\n memo,\n SyntheticEvent,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport {\n Switch as MuiSwitch,\n SwitchProps as MuiSwitchProps,\n FormControlLabel,\n} from \"@mui/material\";\n\nconst { CONTROLLED } = ComponentControlledState;\nimport { useOdysseyDesignTokens } from \"../OdysseyDesignTokensContext\";\nimport { Box } from \"../Box\";\nimport { FieldComponentProps } from \"../FieldComponentProps\";\nimport { FieldHint } from \"../FieldHint\";\nimport type { AllowedProps } from \"../AllowedProps\";\nimport { useUniqueId } from \"../useUniqueId\";\nimport { ComponentControlledState, getControlState } from \"../inputUtils\";\nimport { CheckedFieldProps } from \"../FormCheckedProps\";\n\ntype OnChangeCallbackArguments = {\n checked: boolean;\n value: string;\n};\n\nexport type SwitchProps = {\n /**\n * if `true`, the label and switch span entire containing element's width\n */\n isFullWidth?: boolean;\n /**\n * The label text for the Switch\n */\n label: string;\n /**\n * The change event handler for the Switch\n */\n onChange?: ({ checked, value }: OnChangeCallbackArguments) => void;\n /**\n * The value attribute of the Switch\n */\n value: string;\n} & Pick<\n FieldComponentProps,\n \"hint\" | \"id\" | \"isFullWidth\" | \"isDisabled\" | \"name\"\n> &\n CheckedFieldProps<MuiSwitchProps> &\n AllowedProps;\n\ntype SwitchLabelProps = {\n checked: boolean;\n hint: SwitchProps[\"hint\"];\n hintId?: string;\n isFullWidth: SwitchProps[\"isFullWidth\"];\n label: SwitchProps[\"label\"];\n};\n\nconst SwitchLabel = ({\n checked,\n hint,\n hintId,\n isFullWidth,\n label,\n}: SwitchLabelProps) => {\n const odysseyDesignTokens = useOdysseyDesignTokens();\n\n return (\n <>\n <Box\n sx={{\n display: \"flex\",\n alignItems: \"center\",\n flexWrap: \"wrap\",\n gap: odysseyDesignTokens.Spacing1,\n margin: 0,\n maxWidth: isFullWidth\n ? \"100%\"\n : odysseyDesignTokens.TypographyLineLengthMax,\n fontWeight: odysseyDesignTokens.TypographyWeightBodyBold,\n }}\n >\n {label}\n <Box\n sx={{\n padding: \"2px 4px\",\n backgroundColor: checked\n ? odysseyDesignTokens.PaletteSuccessLighter\n : odysseyDesignTokens.HueNeutral100,\n borderRadius: odysseyDesignTokens.BorderRadiusMain,\n color: checked\n ? odysseyDesignTokens.PaletteSuccessText\n : odysseyDesignTokens.HueNeutral700,\n fontWeight: odysseyDesignTokens.TypographyWeightBodyBold,\n fontSize: odysseyDesignTokens.TypographyScale0,\n lineHeight: odysseyDesignTokens.TypographyLineHeightOverline,\n transitionProperty: \"background-color, color\",\n transitionDuration: odysseyDesignTokens.TransitionDurationMain,\n }}\n >\n {checked ? \"Active\" : \"Inactive\"}\n </Box>\n </Box>\n {hint && <FieldHint id={hintId} text={hint} />}\n </>\n );\n};\n\nconst Switch = ({\n hint,\n id: _id,\n isChecked,\n isDefaultChecked,\n isDisabled,\n isFullWidth = false,\n label,\n name: _name,\n onChange,\n testId,\n value = \"Something\",\n}: SwitchProps) => {\n const odysseyDesignTokens = useOdysseyDesignTokens();\n const controlledStateRef = useRef(\n getControlState({\n controlledValue: isChecked,\n uncontrolledValue: isDefaultChecked,\n })\n );\n const inputValues = useMemo(() => {\n if (controlledStateRef.current === CONTROLLED) {\n return { checked: isChecked };\n }\n return { defaultChecked: isDefaultChecked };\n }, [isDefaultChecked, isChecked]);\n\n const [internalSwitchChecked, setInternalSwitchChecked] = useState(\n controlledStateRef.current === CONTROLLED\n ? Boolean(isChecked)\n : Boolean(isDefaultChecked)\n );\n\n useEffect(() => {\n if (controlledStateRef.current === CONTROLLED) {\n setInternalSwitchChecked(Boolean(isChecked));\n }\n }, [isChecked]);\n\n const id = useUniqueId(_id);\n\n const hintId = hint ? `${id}-hint` : undefined;\n const labelElementId = `${id}-label`;\n\n const handleOnChange = useCallback(\n (_: SyntheticEvent<Element, Event>, checked: boolean) => {\n setInternalSwitchChecked(checked);\n onChange?.({ checked, value });\n },\n [onChange, setInternalSwitchChecked, value]\n );\n\n const renderSwitchComponent = useMemo(\n () => (\n <MuiSwitch\n {...inputValues}\n disabled={isDisabled}\n disableRipple\n inputProps={{\n \"aria-checked\": internalSwitchChecked,\n \"aria-describedby\": hintId,\n \"aria-label\": label,\n \"aria-labelledby\": labelElementId,\n }}\n name={_name ?? id}\n onChange={handleOnChange}\n />\n ),\n [\n handleOnChange,\n hintId,\n inputValues,\n internalSwitchChecked,\n id,\n isDisabled,\n label,\n labelElementId,\n _name,\n ]\n );\n\n return (\n <Box\n sx={{\n marginBlockEnd: odysseyDesignTokens.Spacing2,\n }}\n >\n <FormControlLabel\n checked={internalSwitchChecked}\n control={renderSwitchComponent}\n data-se={testId}\n disabled={isDisabled}\n id={labelElementId}\n label={\n <SwitchLabel\n checked={internalSwitchChecked}\n hint={hint}\n hintId={hintId}\n isFullWidth={isFullWidth}\n label={label}\n />\n }\n labelPlacement=\"start\"\n sx={{\n justifyContent: \"space-between\",\n alignItems: \"flex-start\",\n gap: odysseyDesignTokens.Spacing4,\n width: \"100%\",\n maxWidth: isFullWidth\n ? \"100%\"\n : odysseyDesignTokens.TypographyLineLengthMax,\n }}\n value={value}\n />\n </Box>\n );\n};\n\nconst MemoizedSwitch = memo(Switch);\nMemoizedSwitch.displayName = \"Switch\";\n\nexport { MemoizedSwitch as Switch };\n"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SACEA,IAAI,EAEJC,WAAW,EACXC,SAAS,EACTC,OAAO,EACPC,MAAM,EACNC,QAAQ,QACH,OAAO;AAOd,MAAM;EAAEC;AAAW,CAAC,GAAGC,wBAAwB;AAAC,SACvCC,sBAAsB;AAAA,SACtBC,GAAG;AAAA,SAEHC,SAAS;AAAA,SAETC,WAAW;AAAA,SACXJ,wBAAwB,EAAEK,eAAe;AAAA,SAAAC,GAAA,IAAAC,IAAA;AAAA,SAAAC,IAAA,IAAAC,KAAA;AAAA,SAAAC,QAAA,IAAAC,SAAA;AAwClD,MAAMC,WAAW,GAAGC,IAAA,IAMI;EAAA,IANH;IACnBC,OAAO;IACPC,IAAI;IACJC,MAAM;IACNC,WAAW;IACXC;EACgB,CAAC,GAAAL,IAA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AEN,mBAAmB,CAACkE,QAAQ;QACjCC,KAAK,EAAE,MAAM;QACb1D,QAAQ,EAAEX,WAAW,GACjB,MAAM,GACNE,mBAAmB,CAACU;MAC1B,CAAE;MACF+B,KAAK,EAAEA;IAAM,CACd;EAAC,CACC,CAAC;AAEV,CAAC;AAED,MAAM2B,cAAc,GAAG9F,IAAI,CAACyD,MAAM,CAAC;AACnCqC,cAAc,CAACC,WAAW,GAAG,QAAQ;AAErC,SAASD,cAAc,IAAIrC,MAAM"}
|
|
1
|
+
{"version":3,"file":"Switch.js","names":["memo","useCallback","useEffect","useMemo","useRef","useState","useOdysseyDesignTokens","Box","FieldHint","useUniqueId","ComponentControlledState","getControlState","jsx","_jsx","jsxs","_jsxs","Fragment","_Fragment","CONTROLLED","SwitchLabel","_ref","checked","hint","hintId","isFullWidth","label","odysseyDesignTokens","children","sx","display","alignItems","flexWrap","gap","Spacing1","margin","maxWidth","TypographyLineLengthMax","fontWeight","TypographyWeightBodyBold","padding","backgroundColor","PaletteSuccessLighter","HueNeutral100","borderRadius","BorderRadiusMain","color","PaletteSuccessText","HueNeutral700","fontSize","TypographyScale0","lineHeight","TypographyLineHeightOverline","transitionProperty","transitionDuration","TransitionDurationMain","id","text","Switch","_ref2","_id","isChecked","isDefaultChecked","isDisabled","name","_name","onChange","testId","value","controlledStateRef","controlledValue","uncontrolledValue","inputValues","current","defaultChecked","internalSwitchChecked","setInternalSwitchChecked","Boolean","undefined","labelElementId","handleOnChange","_","renderSwitchComponent","_Switch","disabled","disableRipple","inputProps","marginBlockEnd","Spacing2","_FormControlLabel","control","labelPlacement","justifyContent","Spacing4","width","MemoizedSwitch","displayName"],"sources":["../../src/labs/Switch.tsx"],"sourcesContent":["/*!\n * Copyright (c) 2022-present, Okta, Inc. and/or its affiliates. All rights reserved.\n * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the \"License.\")\n *\n * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n *\n * See the License for the specific language governing permissions and limitations under the License.\n */\n\nimport {\n memo,\n SyntheticEvent,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport {\n Switch as MuiSwitch,\n SwitchProps as MuiSwitchProps,\n FormControlLabel,\n} from \"@mui/material\";\n\nimport { useOdysseyDesignTokens } from \"../OdysseyDesignTokensContext\";\nimport { Box } from \"../Box\";\nimport { FieldComponentProps } from \"../FieldComponentProps\";\nimport { FieldHint } from \"../FieldHint\";\nimport type { AllowedProps } from \"../AllowedProps\";\nimport { useUniqueId } from \"../useUniqueId\";\nimport { ComponentControlledState, getControlState } from \"../inputUtils\";\nimport { CheckedFieldProps } from \"../FormCheckedProps\";\n\nconst { CONTROLLED } = ComponentControlledState;\n\ntype OnChangeCallbackArguments = {\n checked: boolean;\n value: string;\n};\n\nexport type SwitchProps = {\n /**\n * if `true`, the label and switch span entire containing element's width\n */\n isFullWidth?: boolean;\n /**\n * The label text for the Switch\n */\n label: string;\n /**\n * The change event handler for the Switch\n */\n onChange?: ({ checked, value }: OnChangeCallbackArguments) => void;\n /**\n * The value attribute of the Switch\n */\n value: string;\n} & Pick<\n FieldComponentProps,\n \"hint\" | \"id\" | \"isFullWidth\" | \"isDisabled\" | \"name\"\n> &\n CheckedFieldProps<MuiSwitchProps> &\n AllowedProps;\n\ntype SwitchLabelProps = {\n checked: boolean;\n hint: SwitchProps[\"hint\"];\n hintId?: string;\n isFullWidth: SwitchProps[\"isFullWidth\"];\n label: SwitchProps[\"label\"];\n};\n\nconst SwitchLabel = ({\n checked,\n hint,\n hintId,\n isFullWidth,\n label,\n}: SwitchLabelProps) => {\n const odysseyDesignTokens = useOdysseyDesignTokens();\n\n return (\n <>\n <Box\n sx={{\n display: \"flex\",\n alignItems: \"center\",\n flexWrap: \"wrap\",\n gap: odysseyDesignTokens.Spacing1,\n margin: 0,\n maxWidth: isFullWidth\n ? \"100%\"\n : odysseyDesignTokens.TypographyLineLengthMax,\n fontWeight: odysseyDesignTokens.TypographyWeightBodyBold,\n }}\n >\n {label}\n <Box\n sx={{\n padding: \"2px 4px\",\n backgroundColor: checked\n ? odysseyDesignTokens.PaletteSuccessLighter\n : odysseyDesignTokens.HueNeutral100,\n borderRadius: odysseyDesignTokens.BorderRadiusMain,\n color: checked\n ? odysseyDesignTokens.PaletteSuccessText\n : odysseyDesignTokens.HueNeutral700,\n fontWeight: odysseyDesignTokens.TypographyWeightBodyBold,\n fontSize: odysseyDesignTokens.TypographyScale0,\n lineHeight: odysseyDesignTokens.TypographyLineHeightOverline,\n transitionProperty: \"background-color, color\",\n transitionDuration: odysseyDesignTokens.TransitionDurationMain,\n }}\n >\n {checked ? \"Active\" : \"Inactive\"}\n </Box>\n </Box>\n {hint && <FieldHint id={hintId} text={hint} />}\n </>\n );\n};\n\nconst Switch = ({\n hint,\n id: _id,\n isChecked,\n isDefaultChecked,\n isDisabled,\n isFullWidth = false,\n label,\n name: _name,\n onChange,\n testId,\n value = \"Something\",\n}: SwitchProps) => {\n const odysseyDesignTokens = useOdysseyDesignTokens();\n const controlledStateRef = useRef(\n getControlState({\n controlledValue: isChecked,\n uncontrolledValue: isDefaultChecked,\n })\n );\n const inputValues = useMemo(() => {\n if (controlledStateRef.current === CONTROLLED) {\n return { checked: isChecked };\n }\n return { defaultChecked: isDefaultChecked };\n }, [isDefaultChecked, isChecked]);\n\n const [internalSwitchChecked, setInternalSwitchChecked] = useState(\n controlledStateRef.current === CONTROLLED\n ? Boolean(isChecked)\n : Boolean(isDefaultChecked)\n );\n\n useEffect(() => {\n if (controlledStateRef.current === CONTROLLED) {\n setInternalSwitchChecked(Boolean(isChecked));\n }\n }, [isChecked]);\n\n const id = useUniqueId(_id);\n\n const hintId = hint ? `${id}-hint` : undefined;\n const labelElementId = `${id}-label`;\n\n const handleOnChange = useCallback(\n (_: SyntheticEvent<Element, Event>, checked: boolean) => {\n setInternalSwitchChecked(checked);\n onChange?.({ checked, value });\n },\n [onChange, setInternalSwitchChecked, value]\n );\n\n const renderSwitchComponent = useMemo(\n () => (\n <MuiSwitch\n {...inputValues}\n disabled={isDisabled}\n disableRipple\n inputProps={{\n \"aria-checked\": internalSwitchChecked,\n \"aria-describedby\": hintId,\n \"aria-label\": label,\n \"aria-labelledby\": labelElementId,\n }}\n name={_name ?? id}\n onChange={handleOnChange}\n />\n ),\n [\n handleOnChange,\n hintId,\n inputValues,\n internalSwitchChecked,\n id,\n isDisabled,\n label,\n labelElementId,\n _name,\n ]\n );\n\n return (\n <Box\n sx={{\n marginBlockEnd: odysseyDesignTokens.Spacing2,\n }}\n >\n <FormControlLabel\n checked={internalSwitchChecked}\n control={renderSwitchComponent}\n data-se={testId}\n disabled={isDisabled}\n id={labelElementId}\n label={\n <SwitchLabel\n checked={internalSwitchChecked}\n hint={hint}\n hintId={hintId}\n isFullWidth={isFullWidth}\n label={label}\n />\n }\n labelPlacement=\"start\"\n sx={{\n justifyContent: \"space-between\",\n alignItems: \"flex-start\",\n gap: odysseyDesignTokens.Spacing4,\n width: \"100%\",\n maxWidth: isFullWidth\n ? \"100%\"\n : odysseyDesignTokens.TypographyLineLengthMax,\n }}\n value={value}\n />\n </Box>\n );\n};\n\nconst MemoizedSwitch = memo(Switch);\nMemoizedSwitch.displayName = \"Switch\";\n\nexport { MemoizedSwitch as Switch };\n"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SACEA,IAAI,EAEJC,WAAW,EACXC,SAAS,EACTC,OAAO,EACPC,MAAM,EACNC,QAAQ,QACH,OAAO;AAAC,SAONC,sBAAsB;AAAA,SACtBC,GAAG;AAAA,SAEHC,SAAS;AAAA,SAETC,WAAW;AAAA,SACXC,wBAAwB,EAAEC,eAAe;AAAA,SAAAC,GAAA,IAAAC,IAAA;AAAA,SAAAC,IAAA,IAAAC,KAAA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AEA,IAAK;QACXC,MAAM,EAAEA,MAAO;QACfC,WAAW,EAAEA,WAAY;QACzBC,KAAK,EAAEA;MAAM,CACd,CACF;MACDiE,cAAc,EAAC,OAAO;MACtB9D,EAAE,EAAE;QACF+D,cAAc,EAAE,eAAe;QAC/B7D,UAAU,EAAE,YAAY;QACxBE,GAAG,EAAEN,mBAAmB,CAACkE,QAAQ;QACjCC,KAAK,EAAE,MAAM;QACb1D,QAAQ,EAAEX,WAAW,GACjB,MAAM,GACNE,mBAAmB,CAACU;MAC1B,CAAE;MACF+B,KAAK,EAAEA;IAAM,CACd;EAAC,CACC,CAAC;AAEV,CAAC;AAED,MAAM2B,cAAc,GAAG9F,IAAI,CAACyD,MAAM,CAAC;AACnCqC,cAAc,CAACC,WAAW,GAAG,QAAQ;AAErC,SAASD,cAAc,IAAIrC,MAAM"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Switch.d.ts","sourceRoot":"","sources":["../../../src/labs/Switch.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;;AAWH,OAAO,EAEL,WAAW,IAAI,cAAc,EAE9B,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"Switch.d.ts","sourceRoot":"","sources":["../../../src/labs/Switch.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;;AAWH,OAAO,EAEL,WAAW,IAAI,cAAc,EAE9B,MAAM,eAAe,CAAC;AAIvB,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAE7D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAGpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAIxD,KAAK,yBAAyB,GAAG;IAC/B,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB;;OAEG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,QAAQ,CAAC,EAAE,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,yBAAyB,KAAK,IAAI,CAAC;IACnE;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;CACf,GAAG,IAAI,CACN,mBAAmB,EACnB,MAAM,GAAG,IAAI,GAAG,aAAa,GAAG,YAAY,GAAG,MAAM,CACtD,GACC,iBAAiB,CAAC,cAAc,CAAC,GACjC,YAAY,CAAC;AAkLf,QAAA,MAAM,cAAc,8JA1GjB,WAAW,iBA0GqB,CAAC;AAGpC,OAAO,EAAE,cAAc,IAAI,MAAM,EAAE,CAAC"}
|