733c716ee6329436623e44f3570d95eb.json
9.23 KB
{"ast":null,"code":"var _interopRequireWildcard=require(\"@babel/runtime/helpers/interopRequireWildcard\");var _interopRequireDefault=require(\"@babel/runtime/helpers/interopRequireDefault\");Object.defineProperty(exports,\"__esModule\",{value:true});exports.default=exports.isEqualIcon=exports.isValidIcon=void 0;var _extends2=_interopRequireDefault(require(\"@babel/runtime/helpers/extends\"));var _objectWithoutProperties2=_interopRequireDefault(require(\"@babel/runtime/helpers/objectWithoutProperties\"));var React=_interopRequireWildcard(require(\"react\"));var _Image=_interopRequireDefault(require(\"react-native-web/dist/exports/Image\"));var _I18nManager=_interopRequireDefault(require(\"react-native-web/dist/exports/I18nManager\"));var _Platform=_interopRequireDefault(require(\"react-native-web/dist/exports/Platform\"));var _settings=require(\"../core/settings\");var _MaterialCommunityIcon=require(\"./MaterialCommunityIcon\");var _theming=require(\"../core/theming\");var _jsxFileName=\"/Users/satya/Workspace/Callstack/react-native-paper/src/components/Icon.tsx\";var isImageSource=function isImageSource(source){return typeof source==='object'&&source!==null&&Object.prototype.hasOwnProperty.call(source,'uri')&&typeof source.uri==='string'||typeof source==='number'||_Platform.default.OS==='web'&&typeof source==='string'&&(source.startsWith('data:image')||/\\.(bmp|jpg|jpeg|png|gif|svg)$/.test(source));};var getIconId=function getIconId(source){if(typeof source==='object'&&source!==null&&Object.prototype.hasOwnProperty.call(source,'uri')&&typeof source.uri==='string'){return source.uri;}return source;};var isValidIcon=function isValidIcon(source){return typeof source==='string'||isImageSource(source);};exports.isValidIcon=isValidIcon;var isEqualIcon=function isEqualIcon(a,b){return a===b||getIconId(a)===getIconId(b);};exports.isEqualIcon=isEqualIcon;var Icon=function Icon(_ref){var source=_ref.source,color=_ref.color,size=_ref.size,theme=_ref.theme,rest=(0,_objectWithoutProperties2.default)(_ref,[\"source\",\"color\",\"size\",\"theme\"]);var direction=typeof source==='object'&&source.direction&&source.source?source.direction==='auto'?_I18nManager.default.isRTL?'rtl':'ltr':source.direction:null;var s=typeof source==='object'&&source.direction&&source.source?source.source:source;var iconColor=color||theme.colors.text;if(isImageSource(s)){return React.createElement(_Image.default,(0,_extends2.default)({},rest,{source:s,style:[{transform:[{scaleX:direction==='rtl'?-1:1}]},{width:size,height:size,tintColor:color,resizeMode:'contain'}]},_MaterialCommunityIcon.accessibilityProps,{__source:{fileName:_jsxFileName,lineNumber:86}}));}else if(typeof s==='string'){return React.createElement(_settings.Consumer,{__source:{fileName:_jsxFileName,lineNumber:106}},function(_ref2){var icon=_ref2.icon;return icon({name:s,color:iconColor,size:size,direction:direction});});}else if(typeof s==='function'){return s({color:iconColor,size:size,direction:direction});}return null;};var _default=(0,_theming.withTheme)(Icon);exports.default=_default;","map":{"version":3,"sources":["Icon.tsx"],"names":["isImageSource","source","Object","Platform","getIconId","isValidIcon","isEqualIcon","a","Icon","color","size","theme","rest","direction","I18nManager","s","iconColor","transform","scaleX","width","height","tintColor","resizeMode","icon","name","withTheme"],"mappings":"geAAA,oD,wQAOA,0CACA,8DACA,wC,+FAwBA,GAAMA,CAAAA,aAAa,CAAbA,QAAAA,CAAAA,aAAAA,CAAgB,MAAhBA,CAAgB,CAAA,MAEnB,OAAA,CAAA,MAAA,GAAA,QAAA,EACCC,MAAM,GADP,IAAA,EAEEC,MAAM,CAANA,SAAAA,CAAAA,cAAAA,CAAAA,IAAAA,CAAAA,MAAAA,CAAAA,KAAAA,CAFF,EAGG,MAAOD,CAAAA,MAAM,CAAb,GAAA,GAHJ,QAAC,EAKD,MAAA,CAAA,MAAA,GALA,QAAC,EAOAE,kBAAAA,EAAAA,GAAAA,KAAAA,EACC,MAAA,CAAA,MAAA,GADDA,QAAAA,GAEEF,MAAM,CAANA,UAAAA,CAAAA,YAAAA,GACC,gCAAA,IAAA,CAZgB,MAYhB,CAHHE,CATmB,CAAtB,CAAA,CAcA,GAAMC,CAAAA,SAAS,CAATA,QAAAA,CAAAA,SAAAA,CAAY,MAAZA,CAA6B,CACjC,GACE,MAAA,CAAA,MAAA,GAAA,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,CAA6B,CAClC,MAAOE,CAAAA,CAAC,CAAC,CAAEN,KAAK,CAAP,SAAA,CAAoBC,IAAI,CAAxB,IAAA,CAA0BG,SAAS,CAA5C,SAAS,CAAD,CAAR,CAGF,OAAA,KAAA,CAtDF,CAAA,C,aAyDeY,uBAAf,IAAeA,C","sourcesContent":["import * as React from 'react';\nimport {\n Image,\n I18nManager,\n Platform,\n ImageSourcePropType,\n} from 'react-native';\nimport { Consumer as SettingsConsumer } from '../core/settings';\nimport { accessibilityProps } from './MaterialCommunityIcon';\nimport { withTheme } from '../core/theming';\nimport { Theme } from '../types';\n\ntype IconSourceBase = string | ImageSourcePropType;\n\nexport type IconSource =\n | IconSourceBase\n | Readonly<{ source: IconSourceBase; direction: 'rtl' | 'ltr' | 'auto' }>\n | ((props: IconProps & { color: string }) => React.ReactNode);\n\ntype IconProps = {\n size: number;\n allowFontScaling?: boolean;\n};\n\ntype Props = IconProps & {\n color?: string;\n source: any;\n /**\n * @optional\n */\n theme: Theme;\n};\n\nconst isImageSource = (source: any) =>\n // source is an object with uri\n (typeof source === 'object' &&\n source !== null &&\n (Object.prototype.hasOwnProperty.call(source, 'uri') &&\n typeof source.uri === 'string')) ||\n // source is a module, e.g. - require('image')\n typeof source === 'number' ||\n // image url on web\n (Platform.OS === 'web' &&\n typeof source === 'string' &&\n (source.startsWith('data:image') ||\n /\\.(bmp|jpg|jpeg|png|gif|svg)$/.test(source)));\n\nconst getIconId = (source: any) => {\n if (\n typeof source === 'object' &&\n source !== null &&\n (Object.prototype.hasOwnProperty.call(source, 'uri') &&\n typeof source.uri === 'string')\n ) {\n return source.uri;\n }\n\n return source;\n};\n\nexport const isValidIcon = (source: any) =>\n typeof source === 'string' || isImageSource(source);\n\nexport const isEqualIcon = (a: any, b: any) =>\n a === b || getIconId(a) === getIconId(b);\n\nconst Icon = ({ source, color, size, theme, ...rest }: Props) => {\n const direction =\n // @ts-ignore\n typeof source === 'object' && source.direction && source.source\n ? source.direction === 'auto'\n ? I18nManager.isRTL\n ? 'rtl'\n : 'ltr'\n : source.direction\n : null;\n const s =\n // @ts-ignore\n typeof source === 'object' && source.direction && source.source\n ? source.source\n : source;\n const iconColor = color || theme.colors.text;\n\n if (isImageSource(s)) {\n return (\n <Image\n {...rest}\n source={s}\n style={[\n {\n transform: [{ scaleX: direction === 'rtl' ? -1 : 1 }],\n },\n // eslint-disable-next-line react-native/no-inline-styles\n {\n width: size,\n height: size,\n tintColor: color,\n resizeMode: 'contain',\n },\n ]}\n {...accessibilityProps}\n />\n );\n } else if (typeof s === 'string') {\n return (\n <SettingsConsumer>\n {({ icon }) => {\n return icon({\n name: s,\n color: iconColor,\n size,\n direction,\n });\n }}\n </SettingsConsumer>\n );\n } else if (typeof s === 'function') {\n return s({ color: iconColor, size, direction });\n }\n\n return null;\n};\n\nexport default withTheme(Icon);\n"]},"metadata":{},"sourceType":"script"}