@tamagui/select 1.0.1-beta.151 → 1.0.1-beta.154

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.
Files changed (48) hide show
  1. package/dist/cjs/BubbleSelect.js +24 -19
  2. package/dist/cjs/BubbleSelect.js.map +1 -1
  3. package/dist/cjs/Select.js +342 -301
  4. package/dist/cjs/Select.js.map +2 -2
  5. package/dist/cjs/SelectContent.js +18 -15
  6. package/dist/cjs/SelectContent.js.map +1 -1
  7. package/dist/cjs/SelectContent.native.js.map +1 -1
  8. package/dist/cjs/SelectImpl.js +9 -4
  9. package/dist/cjs/SelectImpl.js.map +2 -2
  10. package/dist/cjs/SelectScrollButton.js +109 -95
  11. package/dist/cjs/SelectScrollButton.js.map +2 -2
  12. package/dist/cjs/SelectViewport.js +49 -35
  13. package/dist/cjs/SelectViewport.js.map +2 -2
  14. package/dist/cjs/SelectViewport.native.js +5 -7
  15. package/dist/cjs/SelectViewport.native.js.map +1 -1
  16. package/dist/cjs/context.js.map +1 -1
  17. package/dist/esm/BubbleSelect.js +20 -18
  18. package/dist/esm/BubbleSelect.js.map +1 -1
  19. package/dist/esm/Select.js +338 -300
  20. package/dist/esm/Select.js.map +2 -2
  21. package/dist/esm/SelectContent.js +18 -12
  22. package/dist/esm/SelectContent.js.map +1 -1
  23. package/dist/esm/SelectContent.native.js.map +1 -1
  24. package/dist/esm/SelectImpl.js +5 -3
  25. package/dist/esm/SelectImpl.js.map +2 -2
  26. package/dist/esm/SelectScrollButton.js +105 -94
  27. package/dist/esm/SelectScrollButton.js.map +2 -2
  28. package/dist/esm/SelectViewport.js +45 -34
  29. package/dist/esm/SelectViewport.js.map +1 -1
  30. package/dist/esm/SelectViewport.native.js +5 -4
  31. package/dist/esm/SelectViewport.native.js.map +1 -1
  32. package/dist/esm/context.js.map +1 -1
  33. package/dist/esm/index.js.map +1 -1
  34. package/dist/jsx/BubbleSelect.js +20 -18
  35. package/dist/jsx/BubbleSelect.js.map +1 -1
  36. package/dist/jsx/Select.js +217 -196
  37. package/dist/jsx/Select.js.map +2 -2
  38. package/dist/jsx/SelectContent.js.map +1 -1
  39. package/dist/jsx/SelectContent.native.js.map +1 -1
  40. package/dist/jsx/SelectImpl.js.map +2 -2
  41. package/dist/jsx/SelectScrollButton.js +79 -69
  42. package/dist/jsx/SelectScrollButton.js.map +1 -1
  43. package/dist/jsx/SelectViewport.js +25 -23
  44. package/dist/jsx/SelectViewport.js.map +1 -1
  45. package/dist/jsx/SelectViewport.native.js.map +1 -1
  46. package/dist/jsx/context.js.map +1 -1
  47. package/dist/jsx/index.js.map +1 -1
  48. package/package.json +12 -12
@@ -17,7 +17,10 @@ var __copyProps = (to, from, except, desc) => {
17
17
  }
18
18
  return to;
19
19
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
+ mod
23
+ ));
21
24
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
22
25
  var SelectViewport_exports = {};
23
26
  __export(SelectViewport_exports, {
@@ -25,6 +28,7 @@ __export(SelectViewport_exports, {
25
28
  SelectViewportFrame: () => SelectViewportFrame
26
29
  });
27
30
  module.exports = __toCommonJS(SelectViewport_exports);
31
+ var import_jsx_runtime = require("react/jsx-runtime");
28
32
  var import_react_dom_interactions = require("@floating-ui/react-dom-interactions");
29
33
  var import_core = require("@tamagui/core");
30
34
  var import_core2 = require("@tamagui/core");
@@ -54,41 +58,51 @@ const SelectViewportFrame = (0, import_core2.styled)(import_stacks.ThemeableStac
54
58
  size: "$2"
55
59
  }
56
60
  });
57
- const SelectViewport = React.forwardRef((props, forwardedRef) => {
58
- const { __scopeSelect, children, ...viewportProps } = props;
59
- const context = (0, import_context.useSelectContext)(import_constants.VIEWPORT_NAME, __scopeSelect);
60
- const breakpointActive = (0, import_Select.useSelectBreakpointActive)(context.sheetBreakpoint);
61
- if (breakpointActive || !import_core.isWeb) {
62
- return /* @__PURE__ */ React.createElement(import_portal.PortalItem, {
63
- hostName: `${context.scopeKey}SheetContents`
64
- }, children);
65
- }
66
- if (!context.floatingContext) {
67
- return null;
68
- }
69
- if (!context.open) {
70
- return children;
71
- }
72
- const {
73
- style: { scrollbarWidth, listStyleType, ...restStyle },
74
- ...floatingProps
75
- } = context.interactions.getFloatingProps();
76
- return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("style", {
77
- dangerouslySetInnerHTML: {
78
- __html: selectViewportCSS
61
+ const SelectViewport = React.forwardRef(
62
+ (props, forwardedRef) => {
63
+ const { __scopeSelect, children, ...viewportProps } = props;
64
+ const context = (0, import_context.useSelectContext)(import_constants.VIEWPORT_NAME, __scopeSelect);
65
+ const breakpointActive = (0, import_Select.useSelectBreakpointActive)(context.sheetBreakpoint);
66
+ if (breakpointActive || !import_core.isWeb) {
67
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_portal.PortalItem, {
68
+ hostName: `${context.scopeKey}SheetContents`,
69
+ children
70
+ });
79
71
  }
80
- }), /* @__PURE__ */ React.createElement(import_react_dom_interactions.FloatingFocusManager, {
81
- context: context.floatingContext,
82
- preventTabbing: true
83
- }, /* @__PURE__ */ React.createElement(SelectViewportFrame, {
84
- size: context.size,
85
- role: "presentation",
86
- ...viewportProps,
87
- ref: forwardedRef,
88
- ...floatingProps,
89
- ...restStyle
90
- }, children)));
91
- });
72
+ if (!context.floatingContext) {
73
+ return null;
74
+ }
75
+ if (!context.open) {
76
+ return children;
77
+ }
78
+ const {
79
+ style: { scrollbarWidth, listStyleType, ...restStyle },
80
+ ...floatingProps
81
+ } = context.interactions.getFloatingProps();
82
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
83
+ children: [
84
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("style", {
85
+ dangerouslySetInnerHTML: {
86
+ __html: selectViewportCSS
87
+ }
88
+ }),
89
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_dom_interactions.FloatingFocusManager, {
90
+ context: context.floatingContext,
91
+ preventTabbing: true,
92
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectViewportFrame, {
93
+ size: context.size,
94
+ role: "presentation",
95
+ ...viewportProps,
96
+ ref: forwardedRef,
97
+ ...floatingProps,
98
+ ...restStyle,
99
+ children
100
+ })
101
+ })
102
+ ]
103
+ });
104
+ }
105
+ );
92
106
  SelectViewport.displayName = import_constants.VIEWPORT_NAME;
93
107
  const selectViewportCSS = `
94
108
  .is_SelectViewport {
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["../../src/SelectViewport.tsx"],
4
4
  "sourcesContent": ["import { FloatingFocusManager } from '@floating-ui/react-dom-interactions'\nimport { TamaguiElement, isWeb } from '@tamagui/core'\nimport { styled } from '@tamagui/core'\nimport { PortalItem } from '@tamagui/portal'\nimport { ThemeableStack } from '@tamagui/stacks'\nimport * as React from 'react'\n\nimport { VIEWPORT_NAME } from './constants'\nimport { useSelectContext } from './context'\nimport { useSelectBreakpointActive } from './Select'\nimport { ScopedProps, SelectViewportProps } from './types'\n\n/* -------------------------------------------------------------------------------------------------\n * SelectViewport\n * -----------------------------------------------------------------------------------------------*/\n\nexport const SelectViewportFrame = styled(ThemeableStack, {\n name: VIEWPORT_NAME,\n backgroundColor: '$background',\n elevate: true,\n bordered: true,\n overflow: 'scroll',\n userSelect: 'none',\n\n variants: {\n size: {\n '...size': (val, { tokens }) => {\n return {\n borderRadius: tokens.radius[val] ?? val,\n }\n },\n },\n },\n\n defaultVariants: {\n size: '$2',\n },\n})\n\nexport const SelectViewport = React.forwardRef<TamaguiElement, SelectViewportProps>(\n (props: ScopedProps<SelectViewportProps>, forwardedRef) => {\n const { __scopeSelect, children, ...viewportProps } = props\n const context = useSelectContext(VIEWPORT_NAME, __scopeSelect)\n const breakpointActive = useSelectBreakpointActive(context.sheetBreakpoint)\n\n if (breakpointActive || !isWeb) {\n return <PortalItem hostName={`${context.scopeKey}SheetContents`}>{children}</PortalItem>\n }\n\n if (!context.floatingContext) {\n return null\n }\n\n if (!context.open) {\n return children\n }\n\n const {\n style: { scrollbarWidth, listStyleType, ...restStyle },\n ...floatingProps\n } = context.interactions!.getFloatingProps()\n\n return (\n <>\n <style\n dangerouslySetInnerHTML={{\n __html: selectViewportCSS,\n }}\n />\n <FloatingFocusManager context={context.floatingContext} preventTabbing>\n <SelectViewportFrame\n size={context.size}\n // @ts-ignore\n role=\"presentation\"\n {...viewportProps}\n ref={forwardedRef}\n {...floatingProps}\n {...restStyle}\n >\n {children}\n </SelectViewportFrame>\n </FloatingFocusManager>\n </>\n )\n }\n)\n\nSelectViewport.displayName = VIEWPORT_NAME\n\nconst selectViewportCSS = `\n.is_SelectViewport {\n scrollbar-width: none;\n -webkit-overflow-scrolling: touch;\n overscroll-behavior: contain;\n}\n\n.is_SelectViewport::-webkit-scrollbar{\n display:none\n}\n`\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oCAAqC;AACrC,kBAAsC;AACtC,mBAAuB;AACvB,oBAA2B;AAC3B,oBAA+B;AAC/B,YAAuB;AAEvB,uBAA8B;AAC9B,qBAAiC;AACjC,oBAA0C;AAOnC,MAAM,sBAAsB,yBAAO,8BAAgB;AAAA,EACxD,MAAM;AAAA,EACN,iBAAiB;AAAA,EACjB,SAAS;AAAA,EACT,UAAU;AAAA,EACV,UAAU;AAAA,EACV,YAAY;AAAA,EAEZ,UAAU;AAAA,IACR,MAAM;AAAA,MACJ,WAAW,CAAC,KAAK,EAAE,aAAa;AAC9B,eAAO;AA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K;AAAA,YACJ,GAAG;AAAA,YACH,GAAG;AAAA,YAEH;AAAA,WACH;AAAA,SACF;AAAA;AAAA,KACF;AAAA,EAEJ;AACF;AAEA,eAAe,cAAc;AAE7B,MAAM,oBAAoB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;",
6
+ "names": ["import_core"]
7
7
  }
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name in all)
@@ -17,23 +15,23 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
21
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
22
19
  var SelectViewport_native_exports = {};
23
20
  __export(SelectViewport_native_exports, {
24
21
  SelectViewport: () => SelectViewport
25
22
  });
26
23
  module.exports = __toCommonJS(SelectViewport_native_exports);
24
+ var import_jsx_runtime = require("react/jsx-runtime");
27
25
  var import_portal = require("@tamagui/portal");
28
- var React = __toESM(require("react"));
29
26
  var import_constants = require("./constants");
30
27
  var import_context = require("./context");
31
28
  const SelectViewport = (props) => {
32
29
  const { __scopeSelect, children } = props;
33
30
  const context = (0, import_context.useSelectContext)(import_constants.VIEWPORT_NAME, __scopeSelect);
34
- return /* @__PURE__ */ React.createElement(import_portal.PortalItem, {
35
- hostName: `${context.scopeKey}SheetContents`
36
- }, children);
31
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_portal.PortalItem, {
32
+ hostName: `${context.scopeKey}SheetContents`,
33
+ children
34
+ });
37
35
  };
38
36
  SelectViewport.displayName = import_constants.VIEWPORT_NAME;
39
37
  // Annotate the CommonJS export names for ESM import in node:
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["../../src/SelectViewport.native.tsx"],
4
4
  "sourcesContent": ["import { PortalItem } from '@tamagui/portal'\nimport * as React from 'react'\n\nimport { VIEWPORT_NAME } from './constants'\nimport { useSelectContext } from './context'\nimport { ScopedProps, SelectViewportProps } from './types'\n\nexport const SelectViewport = (props: ScopedProps<SelectViewportProps>) => {\n const { __scopeSelect, children } = props\n const context = useSelectContext(VIEWPORT_NAME, __scopeSelect)\n return <PortalItem hostName={`${context.scopeKey}SheetContents`}>{children}</PortalItem>\n}\n\nSelectViewport.displayName = VIEWPORT_NAME\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA2B;AAC3B,YAAuB;AAEvB,uBAA8B;AAC9B,qBAAiC;AAG1B,MAAM,iBAAiB,CAAC,UAA4C;AACzE,QAAM,EAAE,eAAe,aAAa;AACpC,QAAM,UAAU,qCAAiB,gCAAe,aAAa;AAC7D,SAAO,oCAAC;AAAA,IAAW,UAAU,GAAG,QAAQ;AAAA,KAA0B,QAAS;AAC7E;AAEA,eAAe,cAAc;",
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAUS;AAVT,oBAA2B;AAG3B,uBAA8B;AAC9B,qBAAiC;AAG1B,MAAM,iBAAiB,CAAC,UAA4C;AACzE,QAAM,EAAE,eAAe,SAAS,IAAI;AACpC,QAAM,cAAU,iCAAiB,gCAAe,aAAa;AAC7D,SAAO,4CAAC;AAAA,IAAW,UAAU,GAAG,QAAQ;AAAA,IAA0B;AAAA,GAAS;AAC7E;AAEA,eAAe,cAAc;",
6
6
  "names": []
7
7
  }
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["../../src/context.tsx"],
4
4
  "sourcesContent": ["import { createContextScope } from '@tamagui/create-context'\n\nimport { SELECT_NAME } from './constants'\nimport { SelectContextValue } from './types'\n\nexport const [createSelectContext, createSelectScope] = createContextScope(SELECT_NAME)\n\nexport const [SelectProvider, useSelectContext] =\n createSelectContext<SelectContextValue>(SELECT_NAME)\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAAmC;AAEnC,uBAA4B;AAGrB,MAAM,CAAC,qBAAqB,qBAAqB,8CAAmB,4BAAW;AAE/E,MAAM,CAAC,gBAAgB,oBAC5B,oBAAwC,4BAAW;",
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAAmC;AAEnC,uBAA4B;AAGrB,MAAM,CAAC,qBAAqB,iBAAiB,QAAI,0CAAmB,4BAAW;AAE/E,MAAM,CAAC,gBAAgB,gBAAgB,IAC5C,oBAAwC,4BAAW;",
6
6
  "names": []
7
7
  }
@@ -1,22 +1,24 @@
1
1
  import { usePrevious } from "@radix-ui/react-use-previous";
2
2
  import { useComposedRefs } from "@tamagui/compose-refs";
3
3
  import * as React from "react";
4
- const BubbleSelect = React.forwardRef((props, forwardedRef) => {
5
- const { value, ...selectProps } = props;
6
- const ref = React.useRef(null);
7
- const composedRefs = useComposedRefs(forwardedRef, ref);
8
- const prevValue = usePrevious(value);
9
- React.useEffect(() => {
10
- const select = ref.current;
11
- const selectProto = window.HTMLSelectElement.prototype;
12
- const descriptor = Object.getOwnPropertyDescriptor(selectProto, "value");
13
- const setValue = descriptor.set;
14
- if (prevValue !== value && setValue) {
15
- const event = new Event("change", { bubbles: true });
16
- setValue.call(select, value);
17
- select.dispatchEvent(event);
18
- }
19
- }, [prevValue, value]);
20
- return null;
21
- });
4
+ const BubbleSelect = React.forwardRef(
5
+ (props, forwardedRef) => {
6
+ const { value, ...selectProps } = props;
7
+ const ref = React.useRef(null);
8
+ const composedRefs = useComposedRefs(forwardedRef, ref);
9
+ const prevValue = usePrevious(value);
10
+ React.useEffect(() => {
11
+ const select = ref.current;
12
+ const selectProto = window.HTMLSelectElement.prototype;
13
+ const descriptor = Object.getOwnPropertyDescriptor(selectProto, "value");
14
+ const setValue = descriptor.set;
15
+ if (prevValue !== value && setValue) {
16
+ const event = new Event("change", { bubbles: true });
17
+ setValue.call(select, value);
18
+ select.dispatchEvent(event);
19
+ }
20
+ }, [prevValue, value]);
21
+ return null;
22
+ }
23
+ );
22
24
  //# sourceMappingURL=BubbleSelect.js.map
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["../../src/BubbleSelect.tsx"],
4
4
  "sourcesContent": ["import { usePrevious } from '@radix-ui/react-use-previous'\nimport { useComposedRefs } from '@tamagui/compose-refs'\nimport * as React from 'react'\n\n/* -----------------------------------------------------------------------------------------------*/\nconst BubbleSelect = React.forwardRef<HTMLSelectElement, React.ComponentPropsWithoutRef<'select'>>(\n (props, forwardedRef) => {\n const { value, ...selectProps } = props\n const ref = React.useRef<HTMLSelectElement>(null)\n const composedRefs = useComposedRefs(forwardedRef, ref)\n const prevValue = usePrevious(value)\n\n // Bubble value change to parents (e.g form change event)\n React.useEffect(() => {\n const select = ref.current!\n const selectProto = window.HTMLSelectElement.prototype\n const descriptor = Object.getOwnPropertyDescriptor(selectProto, 'value') as PropertyDescriptor\n const setValue = descriptor.set\n if (prevValue !== value && setValue) {\n const event = new Event('change', { bubbles: true })\n setValue.call(select, value)\n select.dispatchEvent(event)\n }\n }, [prevValue, value])\n\n /**\n * We purposefully use a `select` here to support form autofill as much\n * as possible.\n *\n * We purposefully do not add the `value` attribute here to allow the value\n * to be set programatically and bubble to any parent form `onChange` event.\n * Adding the `value` will cause React to consider the programatic\n * dispatch a duplicate and it will get swallowed.\n *\n * We use `VisuallyHidden` rather than `display: \"none\"` because Safari autofill\n * won't work otherwise.\n */\n // TODO\n return null\n // return (\n // <VisuallyHidden asChild>\n // <select {...selectProps} ref={composedRefs} defaultValue={value} />\n // </VisuallyHidden>\n // )\n }\n)\n"],
5
- "mappings": "AAAA;AACA;AACA;AAGA,MAAM,eAAe,MAAM,WACzB,CAAC,OAAO,iBAAiB;AACvB,QAAM,EAAE,UAAU,gBAAgB;AAClC,QAAM,MAAM,MAAM,OAA0B,IAAI;AAChD,QAAM,eAAe,gBAAgB,cAAc,GAAG;AACtD,QAAM,YAAY,YAAY,KAAK;AAGnC,QAAM,UAAU,MAAM;AACpB,UAAM,SAAS,IAAI;AACnB,UAAM,cAAc,OAAO,kBAAkB;AAC7C,UAAM,aAAa,OAAO,yBAAyB,aAAa,OAAO;AACvE,UAAM,WAAW,WAAW;AAC5B,QAAI,cAAc,SAAS,UAAU;AACnC,YAAM,QAAQ,IAAI,MAAM,UAAU,EAAE,SAAS,KAAK,CAAC;AACnD,eAAS,KAAK,QAAQ,KAAK;AAC3B,aAAO,cAAc,KAAK;AAAA,IAC5B;AAAA,EACF,GAAG,CAAC,WAAW,KAAK,CAAC;AAerB,SAAO;AAMT,CACF;",
5
+ "mappings": "AAAA,SAAS,mBAAmB;AAC5B,SAAS,uBAAuB;AAChC,YAAY,WAAW;AAGvB,MAAM,eAAe,MAAM;AAAA,EACzB,CAAC,OAAO,iBAAiB;AACvB,UAAM,EAAE,UAAU,YAAY,IAAI;AAClC,UAAM,MAAM,MAAM,OAA0B,IAAI;AAChD,UAAM,eAAe,gBAAgB,cAAc,GAAG;AACtD,UAAM,YAAY,YAAY,KAAK;AAGnC,UAAM,UAAU,MAAM;AACpB,YAAM,SAAS,IAAI;AACnB,YAAM,cAAc,OAAO,kBAAkB;AAC7C,YAAM,aAAa,OAAO,yBAAyB,aAAa,OAAO;AACvE,YAAM,WAAW,WAAW;AAC5B,UAAI,cAAc,SAAS,UAAU;AACnC,cAAM,QAAQ,IAAI,MAAM,UAAU,EAAE,SAAS,KAAK,C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