UNPKG

6.79 kBSource Map (JSON)View Raw
1{"version":3,"sources":["../src/getClassName.js"],"names":["DEFAULT_HANDLE_MISSING_STYLENAME_OPTION","isNamespacedStyleName","styleName","indexOf","getClassNameForNamespacedStyleName","styleModuleImportMap","handleMissingStyleNameOption","styleNameParts","split","importName","moduleName","handleMissingStyleName","Error","console","warn","styleNameValue","options","styleModuleImportMapKeys","Object","keys","filter","map","length","styleModuleMap","className","join"],"mappings":";;;;;;AAYA,MAAMA,uCAAuC,GAAG,OAAhD;;AAEA,MAAMC,qBAAqB,GAAIC,SAAD,IAAgC;AAC5D,SAAOA,SAAS,CAACC,OAAV,CAAkB,GAAlB,MAA2B,CAAC,CAAnC;AACD,CAFD;;AAIA,MAAMC,kCAAkC,GAAG,CACzCF,SADyC,EAEzCG,oBAFyC,EAGzCC,4BAHyC,KAI7B;AACZ;AACA;AACA;AACA,QAAMC,cAAc,GAAGL,SAAS,CAACM,KAAV,CAAgB,GAAhB,CAAvB;AACA,QAAMC,UAAU,GAAGF,cAAc,CAAC,CAAD,CAAjC;AACA,QAAMG,UAAU,GAAGH,cAAc,CAAC,CAAD,CAAjC;AACA,QAAMI,sBAAsB,GAAGL,4BAA4B,IACzDN,uCADF;;AAGA,MAAI,CAACU,UAAL,EAAiB;AACf,QAAIC,sBAAsB,KAAK,OAA/B,EAAwC;AACtC,YAAM,IAAIC,KAAJ,CAAU,yBAAyBV,SAAnC,CAAN;AACD,KAFD,MAEO,IAAIS,sBAAsB,KAAK,MAA/B,EAAuC;AAC5C;AACAE,MAAAA,OAAO,CAACC,IAAR,CAAa,yBAAyBZ,SAAtC;AACD,KAHM,MAGA;AACL,aAAO,IAAP;AACD;AACF;;AAED,MAAI,CAACG,oBAAoB,CAACI,UAAD,CAAzB,EAAuC;AACrC,QAAIE,sBAAsB,KAAK,OAA/B,EAAwC;AACtC,YAAM,IAAIC,KAAJ,CAAU,uCAAuCH,UAAjD,CAAN;AACD,KAFD,MAEO,IAAIE,sBAAsB,KAAK,M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I,CAAN;AAED;;AAED,UAAMqB,cAAkC,GAAGlB,oBAAoB,CAACY,wBAAwB,CAAC,CAAD,CAAzB,CAA/D;;AAEA,QAAI,CAACM,cAAc,CAACrB,SAAD,CAAnB,EAAgC;AAC9B,UAAIS,sBAAsB,KAAK,OAA/B,EAAwC;AACtC,cAAM,IAAIC,KAAJ,CAAU,uCAAuCV,SAAvC,GAAmD,KAA7D,CAAN;AACD;;AACD,UAAIS,sBAAsB,KAAK,MAA/B,EAAuC;AACrC;AACAE,QAAAA,OAAO,CAACC,IAAR,CAAa,uCAAuCZ,SAAvC,GAAmD,KAAhE;AACD;AACF;;AAED,WAAOqB,cAAc,CAACrB,SAAD,CAArB;AACD,GAjCI,EAkCJkB,MAlCI,CAkCII,SAAD,IAAe;AACrB;AACA,WAAOA,SAAP;AACD,GArCI,EAsCJC,IAtCI,CAsCC,GAtCD,CAAP;AAuCD,C","sourcesContent":["// @flow\n\nimport type {\n StyleModuleMapType,\n StyleModuleImportMapType,\n HandleMissingStyleNameOptionType\n} from './types';\n\ntype OptionsType = {|\n handleMissingStyleName: HandleMissingStyleNameOptionType\n|};\n\nconst DEFAULT_HANDLE_MISSING_STYLENAME_OPTION = 'throw';\n\nconst isNamespacedStyleName = (styleName: string): boolean => {\n return styleName.indexOf('.') !== -1;\n};\n\nconst getClassNameForNamespacedStyleName = (\n styleName: string,\n styleModuleImportMap: StyleModuleImportMapType,\n handleMissingStyleNameOption?: HandleMissingStyleNameOptionType\n): ?string => {\n // Note:\n // Do not use the desctructing syntax with Babel.\n // Desctructing adds _slicedToArray helper.\n const styleNameParts = styleName.split('.');\n const importName = styleNameParts[0];\n const moduleName = styleNameParts[1];\n const handleMissingStyleName = handleMissingStyleNameOption ||\n DEFAULT_HANDLE_MISSING_STYLENAME_OPTION;\n\n if (!moduleName) {\n if (handleMissingStyleName === 'throw') {\n throw new Error('Invalid style name: ' + styleName);\n } else if (handleMissingStyleName === 'warn') {\n // eslint-disable-next-line no-console\n console.warn('Invalid style name: ' + styleName);\n } else {\n return null;\n }\n }\n\n if (!styleModuleImportMap[importName]) {\n if (handleMissingStyleName === 'throw') {\n throw new Error('CSS module import does not exist: ' + importName);\n } else if (handleMissingStyleName === 'warn') {\n // eslint-disable-next-line no-console\n console.warn('CSS module import does not exist: ' + importName);\n } else {\n return null;\n }\n }\n\n if (!styleModuleImportMap[importName][moduleName]) {\n if (handleMissingStyleName === 'throw') {\n throw new Error('CSS module does not exist: ' + moduleName);\n } else if (handleMissingStyleName === 'warn') {\n // eslint-disable-next-line no-console\n console.warn('CSS module does not exist: ' + moduleName);\n } else {\n return null;\n }\n }\n\n return styleModuleImportMap[importName][moduleName];\n};\n\nexport default (styleNameValue: string, styleModuleImportMap: StyleModuleImportMapType, options?: OptionsType): string => {\n const styleModuleImportMapKeys = Object.keys(styleModuleImportMap);\n\n const handleMissingStyleName = options && options.handleMissingStyleName ||\n DEFAULT_HANDLE_MISSING_STYLENAME_OPTION;\n\n return styleNameValue\n .split(' ')\n .filter((styleName) => {\n return styleName;\n })\n .map((styleName) => {\n if (isNamespacedStyleName(styleName)) {\n return getClassNameForNamespacedStyleName(styleName, styleModuleImportMap, handleMissingStyleName);\n }\n\n if (styleModuleImportMapKeys.length === 0) {\n throw new Error('Cannot use styleName attribute for style name \\'' + styleName +\n '\\' without importing at least one stylesheet.');\n }\n\n if (styleModuleImportMapKeys.length > 1) {\n throw new Error('Cannot use anonymous style name \\'' + styleName +\n '\\' with more than one stylesheet import.');\n }\n\n const styleModuleMap: StyleModuleMapType = styleModuleImportMap[styleModuleImportMapKeys[0]];\n\n if (!styleModuleMap[styleName]) {\n if (handleMissingStyleName === 'throw') {\n throw new Error('Could not resolve the styleName \\'' + styleName + '\\'.');\n }\n if (handleMissingStyleName === 'warn') {\n // eslint-disable-next-line no-console\n console.warn('Could not resolve the styleName \\'' + styleName + '\\'.');\n }\n }\n\n return styleModuleMap[styleName];\n })\n .filter((className) => {\n // Remove any styles which could not be found (if handleMissingStyleName === 'ignore')\n return className;\n })\n .join(' ');\n};\n"],"file":"getClassName.js"}
\No newline at end of file