polished.cjs.js 123 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var _extends = require('@babel/runtime/helpers/extends');
  4. var _assertThisInitialized = require('@babel/runtime/helpers/assertThisInitialized');
  5. var _inheritsLoose = require('@babel/runtime/helpers/inheritsLoose');
  6. var _wrapNativeSuper = require('@babel/runtime/helpers/wrapNativeSuper');
  7. var _taggedTemplateLiteralLoose = require('@babel/runtime/helpers/taggedTemplateLiteralLoose');
  8. function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
  9. var _extends__default = /*#__PURE__*/_interopDefaultLegacy(_extends);
  10. var _assertThisInitialized__default = /*#__PURE__*/_interopDefaultLegacy(_assertThisInitialized);
  11. var _inheritsLoose__default = /*#__PURE__*/_interopDefaultLegacy(_inheritsLoose);
  12. var _wrapNativeSuper__default = /*#__PURE__*/_interopDefaultLegacy(_wrapNativeSuper);
  13. var _taggedTemplateLiteralLoose__default = /*#__PURE__*/_interopDefaultLegacy(_taggedTemplateLiteralLoose);
  14. function last() {
  15. var _ref;
  16. return _ref = arguments.length - 1, _ref < 0 || arguments.length <= _ref ? undefined : arguments[_ref];
  17. }
  18. function negation(a) {
  19. return -a;
  20. }
  21. function addition(a, b) {
  22. return a + b;
  23. }
  24. function subtraction(a, b) {
  25. return a - b;
  26. }
  27. function multiplication(a, b) {
  28. return a * b;
  29. }
  30. function division(a, b) {
  31. return a / b;
  32. }
  33. function max() {
  34. return Math.max.apply(Math, arguments);
  35. }
  36. function min() {
  37. return Math.min.apply(Math, arguments);
  38. }
  39. function comma() {
  40. return Array.of.apply(Array, arguments);
  41. }
  42. var defaultSymbols = {
  43. symbols: {
  44. '*': {
  45. infix: {
  46. symbol: '*',
  47. f: multiplication,
  48. notation: 'infix',
  49. precedence: 4,
  50. rightToLeft: 0,
  51. argCount: 2
  52. },
  53. symbol: '*',
  54. regSymbol: '\\*'
  55. },
  56. '/': {
  57. infix: {
  58. symbol: '/',
  59. f: division,
  60. notation: 'infix',
  61. precedence: 4,
  62. rightToLeft: 0,
  63. argCount: 2
  64. },
  65. symbol: '/',
  66. regSymbol: '/'
  67. },
  68. '+': {
  69. infix: {
  70. symbol: '+',
  71. f: addition,
  72. notation: 'infix',
  73. precedence: 2,
  74. rightToLeft: 0,
  75. argCount: 2
  76. },
  77. prefix: {
  78. symbol: '+',
  79. f: last,
  80. notation: 'prefix',
  81. precedence: 3,
  82. rightToLeft: 0,
  83. argCount: 1
  84. },
  85. symbol: '+',
  86. regSymbol: '\\+'
  87. },
  88. '-': {
  89. infix: {
  90. symbol: '-',
  91. f: subtraction,
  92. notation: 'infix',
  93. precedence: 2,
  94. rightToLeft: 0,
  95. argCount: 2
  96. },
  97. prefix: {
  98. symbol: '-',
  99. f: negation,
  100. notation: 'prefix',
  101. precedence: 3,
  102. rightToLeft: 0,
  103. argCount: 1
  104. },
  105. symbol: '-',
  106. regSymbol: '-'
  107. },
  108. ',': {
  109. infix: {
  110. symbol: ',',
  111. f: comma,
  112. notation: 'infix',
  113. precedence: 1,
  114. rightToLeft: 0,
  115. argCount: 2
  116. },
  117. symbol: ',',
  118. regSymbol: ','
  119. },
  120. '(': {
  121. prefix: {
  122. symbol: '(',
  123. f: last,
  124. notation: 'prefix',
  125. precedence: 0,
  126. rightToLeft: 0,
  127. argCount: 1
  128. },
  129. symbol: '(',
  130. regSymbol: '\\('
  131. },
  132. ')': {
  133. postfix: {
  134. symbol: ')',
  135. f: undefined,
  136. notation: 'postfix',
  137. precedence: 0,
  138. rightToLeft: 0,
  139. argCount: 1
  140. },
  141. symbol: ')',
  142. regSymbol: '\\)'
  143. },
  144. min: {
  145. func: {
  146. symbol: 'min',
  147. f: min,
  148. notation: 'func',
  149. precedence: 0,
  150. rightToLeft: 0,
  151. argCount: 1
  152. },
  153. symbol: 'min',
  154. regSymbol: 'min\\b'
  155. },
  156. max: {
  157. func: {
  158. symbol: 'max',
  159. f: max,
  160. notation: 'func',
  161. precedence: 0,
  162. rightToLeft: 0,
  163. argCount: 1
  164. },
  165. symbol: 'max',
  166. regSymbol: 'max\\b'
  167. }
  168. }
  169. };
  170. // based on https://github.com/styled-components/styled-components/blob/fcf6f3804c57a14dd7984dfab7bc06ee2edca044/src/utils/error.js
  171. /**
  172. * Parse errors.md and turn it into a simple hash of code: message
  173. * @private
  174. */
  175. var ERRORS = {
  176. "1": "Passed invalid arguments to hsl, please pass multiple numbers e.g. hsl(360, 0.75, 0.4) or an object e.g. rgb({ hue: 255, saturation: 0.4, lightness: 0.75 }).\n\n",
  177. "2": "Passed invalid arguments to hsla, please pass multiple numbers e.g. hsla(360, 0.75, 0.4, 0.7) or an object e.g. rgb({ hue: 255, saturation: 0.4, lightness: 0.75, alpha: 0.7 }).\n\n",
  178. "3": "Passed an incorrect argument to a color function, please pass a string representation of a color.\n\n",
  179. "4": "Couldn't generate valid rgb string from %s, it returned %s.\n\n",
  180. "5": "Couldn't parse the color string. Please provide the color as a string in hex, rgb, rgba, hsl or hsla notation.\n\n",
  181. "6": "Passed invalid arguments to rgb, please pass multiple numbers e.g. rgb(255, 205, 100) or an object e.g. rgb({ red: 255, green: 205, blue: 100 }).\n\n",
  182. "7": "Passed invalid arguments to rgba, please pass multiple numbers e.g. rgb(255, 205, 100, 0.75) or an object e.g. rgb({ red: 255, green: 205, blue: 100, alpha: 0.75 }).\n\n",
  183. "8": "Passed invalid argument to toColorString, please pass a RgbColor, RgbaColor, HslColor or HslaColor object.\n\n",
  184. "9": "Please provide a number of steps to the modularScale helper.\n\n",
  185. "10": "Please pass a number or one of the predefined scales to the modularScale helper as the ratio.\n\n",
  186. "11": "Invalid value passed as base to modularScale, expected number or em string but got \"%s\"\n\n",
  187. "12": "Expected a string ending in \"px\" or a number passed as the first argument to %s(), got \"%s\" instead.\n\n",
  188. "13": "Expected a string ending in \"px\" or a number passed as the second argument to %s(), got \"%s\" instead.\n\n",
  189. "14": "Passed invalid pixel value (\"%s\") to %s(), please pass a value like \"12px\" or 12.\n\n",
  190. "15": "Passed invalid base value (\"%s\") to %s(), please pass a value like \"12px\" or 12.\n\n",
  191. "16": "You must provide a template to this method.\n\n",
  192. "17": "You passed an unsupported selector state to this method.\n\n",
  193. "18": "minScreen and maxScreen must be provided as stringified numbers with the same units.\n\n",
  194. "19": "fromSize and toSize must be provided as stringified numbers with the same units.\n\n",
  195. "20": "expects either an array of objects or a single object with the properties prop, fromSize, and toSize.\n\n",
  196. "21": "expects the objects in the first argument array to have the properties `prop`, `fromSize`, and `toSize`.\n\n",
  197. "22": "expects the first argument object to have the properties `prop`, `fromSize`, and `toSize`.\n\n",
  198. "23": "fontFace expects a name of a font-family.\n\n",
  199. "24": "fontFace expects either the path to the font file(s) or a name of a local copy.\n\n",
  200. "25": "fontFace expects localFonts to be an array.\n\n",
  201. "26": "fontFace expects fileFormats to be an array.\n\n",
  202. "27": "radialGradient requries at least 2 color-stops to properly render.\n\n",
  203. "28": "Please supply a filename to retinaImage() as the first argument.\n\n",
  204. "29": "Passed invalid argument to triangle, please pass correct pointingDirection e.g. 'right'.\n\n",
  205. "30": "Passed an invalid value to `height` or `width`. Please provide a pixel based unit.\n\n",
  206. "31": "The animation shorthand only takes 8 arguments. See the specification for more information: http://mdn.io/animation\n\n",
  207. "32": "To pass multiple animations please supply them in arrays, e.g. animation(['rotate', '2s'], ['move', '1s'])\nTo pass a single animation please supply them in simple values, e.g. animation('rotate', '2s')\n\n",
  208. "33": "The animation shorthand arrays can only have 8 elements. See the specification for more information: http://mdn.io/animation\n\n",
  209. "34": "borderRadius expects a radius value as a string or number as the second argument.\n\n",
  210. "35": "borderRadius expects one of \"top\", \"bottom\", \"left\" or \"right\" as the first argument.\n\n",
  211. "36": "Property must be a string value.\n\n",
  212. "37": "Syntax Error at %s.\n\n",
  213. "38": "Formula contains a function that needs parentheses at %s.\n\n",
  214. "39": "Formula is missing closing parenthesis at %s.\n\n",
  215. "40": "Formula has too many closing parentheses at %s.\n\n",
  216. "41": "All values in a formula must have the same unit or be unitless.\n\n",
  217. "42": "Please provide a number of steps to the modularScale helper.\n\n",
  218. "43": "Please pass a number or one of the predefined scales to the modularScale helper as the ratio.\n\n",
  219. "44": "Invalid value passed as base to modularScale, expected number or em/rem string but got %s.\n\n",
  220. "45": "Passed invalid argument to hslToColorString, please pass a HslColor or HslaColor object.\n\n",
  221. "46": "Passed invalid argument to rgbToColorString, please pass a RgbColor or RgbaColor object.\n\n",
  222. "47": "minScreen and maxScreen must be provided as stringified numbers with the same units.\n\n",
  223. "48": "fromSize and toSize must be provided as stringified numbers with the same units.\n\n",
  224. "49": "Expects either an array of objects or a single object with the properties prop, fromSize, and toSize.\n\n",
  225. "50": "Expects the objects in the first argument array to have the properties prop, fromSize, and toSize.\n\n",
  226. "51": "Expects the first argument object to have the properties prop, fromSize, and toSize.\n\n",
  227. "52": "fontFace expects either the path to the font file(s) or a name of a local copy.\n\n",
  228. "53": "fontFace expects localFonts to be an array.\n\n",
  229. "54": "fontFace expects fileFormats to be an array.\n\n",
  230. "55": "fontFace expects a name of a font-family.\n\n",
  231. "56": "linearGradient requries at least 2 color-stops to properly render.\n\n",
  232. "57": "radialGradient requries at least 2 color-stops to properly render.\n\n",
  233. "58": "Please supply a filename to retinaImage() as the first argument.\n\n",
  234. "59": "Passed invalid argument to triangle, please pass correct pointingDirection e.g. 'right'.\n\n",
  235. "60": "Passed an invalid value to `height` or `width`. Please provide a pixel based unit.\n\n",
  236. "61": "Property must be a string value.\n\n",
  237. "62": "borderRadius expects a radius value as a string or number as the second argument.\n\n",
  238. "63": "borderRadius expects one of \"top\", \"bottom\", \"left\" or \"right\" as the first argument.\n\n",
  239. "64": "The animation shorthand only takes 8 arguments. See the specification for more information: http://mdn.io/animation.\n\n",
  240. "65": "To pass multiple animations please supply them in arrays, e.g. animation(['rotate', '2s'], ['move', '1s'])\\nTo pass a single animation please supply them in simple values, e.g. animation('rotate', '2s').\n\n",
  241. "66": "The animation shorthand arrays can only have 8 elements. See the specification for more information: http://mdn.io/animation.\n\n",
  242. "67": "You must provide a template to this method.\n\n",
  243. "68": "You passed an unsupported selector state to this method.\n\n",
  244. "69": "Expected a string ending in \"px\" or a number passed as the first argument to %s(), got %s instead.\n\n",
  245. "70": "Expected a string ending in \"px\" or a number passed as the second argument to %s(), got %s instead.\n\n",
  246. "71": "Passed invalid pixel value %s to %s(), please pass a value like \"12px\" or 12.\n\n",
  247. "72": "Passed invalid base value %s to %s(), please pass a value like \"12px\" or 12.\n\n",
  248. "73": "Please provide a valid CSS variable.\n\n",
  249. "74": "CSS variable not found and no default was provided.\n\n",
  250. "75": "important requires a valid style object, got a %s instead.\n\n",
  251. "76": "fromSize and toSize must be provided as stringified numbers with the same units as minScreen and maxScreen.\n\n",
  252. "77": "remToPx expects a value in \"rem\" but you provided it in \"%s\".\n\n",
  253. "78": "base must be set in \"px\" or \"%\" but you set it in \"%s\".\n"
  254. };
  255. /**
  256. * super basic version of sprintf
  257. * @private
  258. */
  259. function format() {
  260. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  261. args[_key] = arguments[_key];
  262. }
  263. var a = args[0];
  264. var b = [];
  265. var c;
  266. for (c = 1; c < args.length; c += 1) {
  267. b.push(args[c]);
  268. }
  269. b.forEach(function (d) {
  270. a = a.replace(/%[a-z]/, d);
  271. });
  272. return a;
  273. }
  274. /**
  275. * Create an error file out of errors.md for development and a simple web link to the full errors
  276. * in production mode.
  277. * @private
  278. */
  279. var PolishedError = /*#__PURE__*/function (_Error) {
  280. _inheritsLoose__default['default'](PolishedError, _Error);
  281. function PolishedError(code) {
  282. var _this;
  283. if (process.env.NODE_ENV === 'production') {
  284. _this = _Error.call(this, "An error occurred. See https://github.com/styled-components/polished/blob/main/src/internalHelpers/errors.md#" + code + " for more information.") || this;
  285. } else {
  286. for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
  287. args[_key2 - 1] = arguments[_key2];
  288. }
  289. _this = _Error.call(this, format.apply(void 0, [ERRORS[code]].concat(args))) || this;
  290. }
  291. return _assertThisInitialized__default['default'](_this);
  292. }
  293. return PolishedError;
  294. }( /*#__PURE__*/_wrapNativeSuper__default['default'](Error));
  295. var unitRegExp = /((?!\w)a|na|hc|mc|dg|me[r]?|xe|ni(?![a-zA-Z])|mm|cp|tp|xp|q(?!s)|hv|xamv|nimv|wv|sm|s(?!\D|$)|ged|darg?|nrut)/g; // Merges additional math functionality into the defaults.
  296. function mergeSymbolMaps(additionalSymbols) {
  297. var symbolMap = {};
  298. symbolMap.symbols = additionalSymbols ? _extends__default['default']({}, defaultSymbols.symbols, additionalSymbols.symbols) : _extends__default['default']({}, defaultSymbols.symbols);
  299. return symbolMap;
  300. }
  301. function exec(operators, values) {
  302. var _ref;
  303. var op = operators.pop();
  304. values.push(op.f.apply(op, (_ref = []).concat.apply(_ref, values.splice(-op.argCount))));
  305. return op.precedence;
  306. }
  307. function calculate(expression, additionalSymbols) {
  308. var symbolMap = mergeSymbolMaps(additionalSymbols);
  309. var match;
  310. var operators = [symbolMap.symbols['('].prefix];
  311. var values = [];
  312. var pattern = new RegExp( // Pattern for numbers
  313. "\\d+(?:\\.\\d+)?|" + // ...and patterns for individual operators/function names
  314. Object.keys(symbolMap.symbols).map(function (key) {
  315. return symbolMap.symbols[key];
  316. }) // longer symbols should be listed first
  317. // $FlowFixMe
  318. .sort(function (a, b) {
  319. return b.symbol.length - a.symbol.length;
  320. }) // $FlowFixMe
  321. .map(function (val) {
  322. return val.regSymbol;
  323. }).join('|') + "|(\\S)", 'g');
  324. pattern.lastIndex = 0; // Reset regular expression object
  325. var afterValue = false;
  326. do {
  327. match = pattern.exec(expression);
  328. var _ref2 = match || [')', undefined],
  329. token = _ref2[0],
  330. bad = _ref2[1];
  331. var notNumber = symbolMap.symbols[token];
  332. var notNewValue = notNumber && !notNumber.prefix && !notNumber.func;
  333. var notAfterValue = !notNumber || !notNumber.postfix && !notNumber.infix; // Check for syntax errors:
  334. if (bad || (afterValue ? notAfterValue : notNewValue)) {
  335. throw new PolishedError(37, match ? match.index : expression.length, expression);
  336. }
  337. if (afterValue) {
  338. // We either have an infix or postfix operator (they should be mutually exclusive)
  339. var curr = notNumber.postfix || notNumber.infix;
  340. do {
  341. var prev = operators[operators.length - 1];
  342. if ((curr.precedence - prev.precedence || prev.rightToLeft) > 0) break; // Apply previous operator, since it has precedence over current one
  343. } while (exec(operators, values)); // Exit loop after executing an opening parenthesis or function
  344. afterValue = curr.notation === 'postfix';
  345. if (curr.symbol !== ')') {
  346. operators.push(curr); // Postfix always has precedence over any operator that follows after it
  347. if (afterValue) exec(operators, values);
  348. }
  349. } else if (notNumber) {
  350. // prefix operator or function
  351. operators.push(notNumber.prefix || notNumber.func);
  352. if (notNumber.func) {
  353. // Require an opening parenthesis
  354. match = pattern.exec(expression);
  355. if (!match || match[0] !== '(') {
  356. throw new PolishedError(38, match ? match.index : expression.length, expression);
  357. }
  358. }
  359. } else {
  360. // number
  361. values.push(+token);
  362. afterValue = true;
  363. }
  364. } while (match && operators.length);
  365. if (operators.length) {
  366. throw new PolishedError(39, match ? match.index : expression.length, expression);
  367. } else if (match) {
  368. throw new PolishedError(40, match ? match.index : expression.length, expression);
  369. } else {
  370. return values.pop();
  371. }
  372. }
  373. function reverseString(str) {
  374. return str.split('').reverse().join('');
  375. }
  376. /**
  377. * Helper for doing math with CSS Units. Accepts a formula as a string. All values in the formula must have the same unit (or be unitless). Supports complex formulas utliziing addition, subtraction, multiplication, division, square root, powers, factorial, min, max, as well as parentheses for order of operation.
  378. *
  379. *In cases where you need to do calculations with mixed units where one unit is a [relative length unit](https://developer.mozilla.org/en-US/docs/Web/CSS/length#Relative_length_units), you will want to use [CSS Calc](https://developer.mozilla.org/en-US/docs/Web/CSS/calc).
  380. *
  381. * *warning* While we've done everything possible to ensure math safely evalutes formulas expressed as strings, you should always use extreme caution when passing `math` user provided values.
  382. * @example
  383. * // Styles as object usage
  384. * const styles = {
  385. * fontSize: math('12rem + 8rem'),
  386. * fontSize: math('(12px + 2px) * 3'),
  387. * fontSize: math('3px^2 + sqrt(4)'),
  388. * }
  389. *
  390. * // styled-components usage
  391. * const div = styled.div`
  392. * fontSize: ${math('12rem + 8rem')};
  393. * fontSize: ${math('(12px + 2px) * 3')};
  394. * fontSize: ${math('3px^2 + sqrt(4)')};
  395. * `
  396. *
  397. * // CSS as JS Output
  398. *
  399. * div: {
  400. * fontSize: '20rem',
  401. * fontSize: '42px',
  402. * fontSize: '11px',
  403. * }
  404. */
  405. function math(formula, additionalSymbols) {
  406. var reversedFormula = reverseString(formula);
  407. var formulaMatch = reversedFormula.match(unitRegExp); // Check that all units are the same
  408. if (formulaMatch && !formulaMatch.every(function (unit) {
  409. return unit === formulaMatch[0];
  410. })) {
  411. throw new PolishedError(41);
  412. }
  413. var cleanFormula = reverseString(reversedFormula.replace(unitRegExp, ''));
  414. return "" + calculate(cleanFormula, additionalSymbols) + (formulaMatch ? reverseString(formulaMatch[0]) : '');
  415. }
  416. var cssVariableRegex = /--[\S]*/g;
  417. /**
  418. * Fetches the value of a passed CSS Variable in the :root scope, or otherwise returns a defaultValue if provided.
  419. *
  420. * @example
  421. * // Styles as object usage
  422. * const styles = {
  423. * 'background': cssVar('--background-color'),
  424. * }
  425. *
  426. * // styled-components usage
  427. * const div = styled.div`
  428. * background: ${cssVar('--background-color')};
  429. * `
  430. *
  431. * // CSS in JS Output
  432. *
  433. * element {
  434. * 'background': 'red'
  435. * }
  436. */
  437. function cssVar(cssVariable, defaultValue) {
  438. if (!cssVariable || !cssVariable.match(cssVariableRegex)) {
  439. throw new PolishedError(73);
  440. }
  441. var variableValue;
  442. /* eslint-disable */
  443. /* istanbul ignore next */
  444. if (typeof document !== 'undefined' && document.documentElement !== null) {
  445. variableValue = getComputedStyle(document.documentElement).getPropertyValue(cssVariable);
  446. }
  447. /* eslint-enable */
  448. if (variableValue) {
  449. return variableValue.trim();
  450. } else if (defaultValue) {
  451. return defaultValue;
  452. }
  453. throw new PolishedError(74);
  454. }
  455. // @private
  456. function capitalizeString(string) {
  457. return string.charAt(0).toUpperCase() + string.slice(1);
  458. }
  459. var positionMap$1 = ['Top', 'Right', 'Bottom', 'Left'];
  460. function generateProperty(property, position) {
  461. if (!property) return position.toLowerCase();
  462. var splitProperty = property.split('-');
  463. if (splitProperty.length > 1) {
  464. splitProperty.splice(1, 0, position);
  465. return splitProperty.reduce(function (acc, val) {
  466. return "" + acc + capitalizeString(val);
  467. });
  468. }
  469. var joinedProperty = property.replace(/([a-z])([A-Z])/g, "$1" + position + "$2");
  470. return property === joinedProperty ? "" + property + position : joinedProperty;
  471. }
  472. function generateStyles(property, valuesWithDefaults) {
  473. var styles = {};
  474. for (var i = 0; i < valuesWithDefaults.length; i += 1) {
  475. if (valuesWithDefaults[i] || valuesWithDefaults[i] === 0) {
  476. styles[generateProperty(property, positionMap$1[i])] = valuesWithDefaults[i];
  477. }
  478. }
  479. return styles;
  480. }
  481. /**
  482. * Enables shorthand for direction-based properties. It accepts a property (hyphenated or camelCased) and up to four values that map to top, right, bottom, and left, respectively. You can optionally pass an empty string to get only the directional values as properties. You can also optionally pass a null argument for a directional value to ignore it.
  483. * @example
  484. * // Styles as object usage
  485. * const styles = {
  486. * ...directionalProperty('padding', '12px', '24px', '36px', '48px')
  487. * }
  488. *
  489. * // styled-components usage
  490. * const div = styled.div`
  491. * ${directionalProperty('padding', '12px', '24px', '36px', '48px')}
  492. * `
  493. *
  494. * // CSS as JS Output
  495. *
  496. * div {
  497. * 'paddingTop': '12px',
  498. * 'paddingRight': '24px',
  499. * 'paddingBottom': '36px',
  500. * 'paddingLeft': '48px'
  501. * }
  502. */
  503. function directionalProperty(property) {
  504. for (var _len = arguments.length, values = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  505. values[_key - 1] = arguments[_key];
  506. }
  507. // prettier-ignore
  508. var firstValue = values[0],
  509. _values$ = values[1],
  510. secondValue = _values$ === void 0 ? firstValue : _values$,
  511. _values$2 = values[2],
  512. thirdValue = _values$2 === void 0 ? firstValue : _values$2,
  513. _values$3 = values[3],
  514. fourthValue = _values$3 === void 0 ? secondValue : _values$3;
  515. var valuesWithDefaults = [firstValue, secondValue, thirdValue, fourthValue];
  516. return generateStyles(property, valuesWithDefaults);
  517. }
  518. /**
  519. * Check if a string ends with something
  520. * @private
  521. */
  522. function endsWith(string, suffix) {
  523. return string.substr(-suffix.length) === suffix;
  524. }
  525. var cssRegex$1 = /^([+-]?(?:\d+|\d*\.\d+))([a-z]*|%)$/;
  526. /**
  527. * Returns a given CSS value minus its unit of measure.
  528. *
  529. * @example
  530. * // Styles as object usage
  531. * const styles = {
  532. * '--dimension': stripUnit('100px')
  533. * }
  534. *
  535. * // styled-components usage
  536. * const div = styled.div`
  537. * --dimension: ${stripUnit('100px')};
  538. * `
  539. *
  540. * // CSS in JS Output
  541. *
  542. * element {
  543. * '--dimension': 100
  544. * }
  545. */
  546. function stripUnit(value) {
  547. if (typeof value !== 'string') return value;
  548. var matchedValue = value.match(cssRegex$1);
  549. return matchedValue ? parseFloat(value) : value;
  550. }
  551. /**
  552. * Factory function that creates pixel-to-x converters
  553. * @private
  554. */
  555. var pxtoFactory = function pxtoFactory(to) {
  556. return function (pxval, base) {
  557. if (base === void 0) {
  558. base = '16px';
  559. }
  560. var newPxval = pxval;
  561. var newBase = base;
  562. if (typeof pxval === 'string') {
  563. if (!endsWith(pxval, 'px')) {
  564. throw new PolishedError(69, to, pxval);
  565. }
  566. newPxval = stripUnit(pxval);
  567. }
  568. if (typeof base === 'string') {
  569. if (!endsWith(base, 'px')) {
  570. throw new PolishedError(70, to, base);
  571. }
  572. newBase = stripUnit(base);
  573. }
  574. if (typeof newPxval === 'string') {
  575. throw new PolishedError(71, pxval, to);
  576. }
  577. if (typeof newBase === 'string') {
  578. throw new PolishedError(72, base, to);
  579. }
  580. return "" + newPxval / newBase + to;
  581. };
  582. };
  583. /**
  584. * Convert pixel value to ems. The default base value is 16px, but can be changed by passing a
  585. * second argument to the function.
  586. * @function
  587. * @param {string|number} pxval
  588. * @param {string|number} [base='16px']
  589. * @example
  590. * // Styles as object usage
  591. * const styles = {
  592. * 'height': em('16px')
  593. * }
  594. *
  595. * // styled-components usage
  596. * const div = styled.div`
  597. * height: ${em('16px')}
  598. * `
  599. *
  600. * // CSS in JS Output
  601. *
  602. * element {
  603. * 'height': '1em'
  604. * }
  605. */
  606. var em = /*#__PURE__*/pxtoFactory('em');
  607. var cssRegex = /^([+-]?(?:\d+|\d*\.\d+))([a-z]*|%)$/;
  608. /**
  609. * Returns a given CSS value and its unit as elements of an array.
  610. *
  611. * @example
  612. * // Styles as object usage
  613. * const styles = {
  614. * '--dimension': getValueAndUnit('100px')[0],
  615. * '--unit': getValueAndUnit('100px')[1],
  616. * }
  617. *
  618. * // styled-components usage
  619. * const div = styled.div`
  620. * --dimension: ${getValueAndUnit('100px')[0]};
  621. * --unit: ${getValueAndUnit('100px')[1]};
  622. * `
  623. *
  624. * // CSS in JS Output
  625. *
  626. * element {
  627. * '--dimension': 100,
  628. * '--unit': 'px',
  629. * }
  630. */
  631. function getValueAndUnit(value) {
  632. if (typeof value !== 'string') return [value, ''];
  633. var matchedValue = value.match(cssRegex);
  634. if (matchedValue) return [parseFloat(value), matchedValue[2]];
  635. return [value, undefined];
  636. }
  637. /**
  638. * Helper for targeting rules in a style block generated by polished modules that need !important-level specificity. Can optionally specify a rule (or rules) to target specific rules.
  639. *
  640. * @example
  641. * // Styles as object usage
  642. * const styles = {
  643. * ...important(cover())
  644. * }
  645. *
  646. * // styled-components usage
  647. * const div = styled.div`
  648. * ${important(cover())}
  649. * `
  650. *
  651. * // CSS as JS Output
  652. *
  653. * div: {
  654. * 'position': 'absolute !important',
  655. * 'top': '0 !important',
  656. * 'right: '0 !important',
  657. * 'bottom': '0 !important',
  658. * 'left: '0 !important'
  659. * }
  660. */
  661. function important(styleBlock, rules) {
  662. if (typeof styleBlock !== 'object' || styleBlock === null) {
  663. throw new PolishedError(75, typeof styleBlock);
  664. }
  665. var newStyleBlock = {};
  666. Object.keys(styleBlock).forEach(function (key) {
  667. if (typeof styleBlock[key] === 'object' && styleBlock[key] !== null) {
  668. newStyleBlock[key] = important(styleBlock[key], rules);
  669. } else if (!rules || rules && (rules === key || rules.indexOf(key) >= 0)) {
  670. newStyleBlock[key] = styleBlock[key] + " !important";
  671. } else {
  672. newStyleBlock[key] = styleBlock[key];
  673. }
  674. });
  675. return newStyleBlock;
  676. }
  677. var ratioNames = {
  678. minorSecond: 1.067,
  679. majorSecond: 1.125,
  680. minorThird: 1.2,
  681. majorThird: 1.25,
  682. perfectFourth: 1.333,
  683. augFourth: 1.414,
  684. perfectFifth: 1.5,
  685. minorSixth: 1.6,
  686. goldenSection: 1.618,
  687. majorSixth: 1.667,
  688. minorSeventh: 1.778,
  689. majorSeventh: 1.875,
  690. octave: 2,
  691. majorTenth: 2.5,
  692. majorEleventh: 2.667,
  693. majorTwelfth: 3,
  694. doubleOctave: 4
  695. };
  696. function getRatio(ratioName) {
  697. return ratioNames[ratioName];
  698. }
  699. /**
  700. * Establish consistent measurements and spacial relationships throughout your projects by incrementing an em or rem value up or down a defined scale. We provide a list of commonly used scales as pre-defined variables.
  701. * @example
  702. * // Styles as object usage
  703. * const styles = {
  704. * // Increment two steps up the default scale
  705. * 'fontSize': modularScale(2)
  706. * }
  707. *
  708. * // styled-components usage
  709. * const div = styled.div`
  710. * // Increment two steps up the default scale
  711. * fontSize: ${modularScale(2)}
  712. * `
  713. *
  714. * // CSS in JS Output
  715. *
  716. * element {
  717. * 'fontSize': '1.77689em'
  718. * }
  719. */
  720. function modularScale(steps, base, ratio) {
  721. if (base === void 0) {
  722. base = '1em';
  723. }
  724. if (ratio === void 0) {
  725. ratio = 1.333;
  726. }
  727. if (typeof steps !== 'number') {
  728. throw new PolishedError(42);
  729. }
  730. if (typeof ratio === 'string' && !ratioNames[ratio]) {
  731. throw new PolishedError(43);
  732. }
  733. var _ref = typeof base === 'string' ? getValueAndUnit(base) : [base, ''],
  734. realBase = _ref[0],
  735. unit = _ref[1];
  736. var realRatio = typeof ratio === 'string' ? getRatio(ratio) : ratio;
  737. if (typeof realBase === 'string') {
  738. throw new PolishedError(44, base);
  739. }
  740. return "" + realBase * Math.pow(realRatio, steps) + (unit || '');
  741. }
  742. /**
  743. * Convert pixel value to rems. The default base value is 16px, but can be changed by passing a
  744. * second argument to the function.
  745. * @function
  746. * @param {string|number} pxval
  747. * @param {string|number} [base='16px']
  748. * @example
  749. * // Styles as object usage
  750. * const styles = {
  751. * 'height': rem('16px')
  752. * }
  753. *
  754. * // styled-components usage
  755. * const div = styled.div`
  756. * height: ${rem('16px')}
  757. * `
  758. *
  759. * // CSS in JS Output
  760. *
  761. * element {
  762. * 'height': '1rem'
  763. * }
  764. */
  765. var rem = /*#__PURE__*/pxtoFactory('rem');
  766. var defaultFontSize = 16;
  767. function convertBase(base) {
  768. var deconstructedValue = getValueAndUnit(base);
  769. if (deconstructedValue[1] === 'px') {
  770. return parseFloat(base);
  771. }
  772. if (deconstructedValue[1] === '%') {
  773. return parseFloat(base) / 100 * defaultFontSize;
  774. }
  775. throw new PolishedError(78, deconstructedValue[1]);
  776. }
  777. function getBaseFromDoc() {
  778. /* eslint-disable */
  779. /* istanbul ignore next */
  780. if (typeof document !== 'undefined' && document.documentElement !== null) {
  781. var rootFontSize = getComputedStyle(document.documentElement).fontSize;
  782. return rootFontSize ? convertBase(rootFontSize) : defaultFontSize;
  783. }
  784. /* eslint-enable */
  785. /* istanbul ignore next */
  786. return defaultFontSize;
  787. }
  788. /**
  789. * Convert rem values to px. By default, the base value is pulled from the font-size property on the root element (if it is set in % or px). It defaults to 16px if not found on the root. You can also override the base value by providing your own base in % or px.
  790. * @example
  791. * // Styles as object usage
  792. * const styles = {
  793. * 'height': remToPx('1.6rem')
  794. * 'height': remToPx('1.6rem', '10px')
  795. * }
  796. *
  797. * // styled-components usage
  798. * const div = styled.div`
  799. * height: ${remToPx('1.6rem')}
  800. * height: ${remToPx('1.6rem', '10px')}
  801. * `
  802. *
  803. * // CSS in JS Output
  804. *
  805. * element {
  806. * 'height': '25.6px',
  807. * 'height': '16px',
  808. * }
  809. */
  810. function remToPx(value, base) {
  811. var deconstructedValue = getValueAndUnit(value);
  812. if (deconstructedValue[1] !== 'rem' && deconstructedValue[1] !== '') {
  813. throw new PolishedError(77, deconstructedValue[1]);
  814. }
  815. var newBase = base ? convertBase(base) : getBaseFromDoc();
  816. return deconstructedValue[0] * newBase + "px";
  817. }
  818. var functionsMap$3 = {
  819. back: 'cubic-bezier(0.600, -0.280, 0.735, 0.045)',
  820. circ: 'cubic-bezier(0.600, 0.040, 0.980, 0.335)',
  821. cubic: 'cubic-bezier(0.550, 0.055, 0.675, 0.190)',
  822. expo: 'cubic-bezier(0.950, 0.050, 0.795, 0.035)',
  823. quad: 'cubic-bezier(0.550, 0.085, 0.680, 0.530)',
  824. quart: 'cubic-bezier(0.895, 0.030, 0.685, 0.220)',
  825. quint: 'cubic-bezier(0.755, 0.050, 0.855, 0.060)',
  826. sine: 'cubic-bezier(0.470, 0.000, 0.745, 0.715)'
  827. };
  828. /**
  829. * String to represent common easing functions as demonstrated here: (github.com/jaukia/easie).
  830. *
  831. * @example
  832. * // Styles as object usage
  833. * const styles = {
  834. * 'transitionTimingFunction': easeIn('quad')
  835. * }
  836. *
  837. * // styled-components usage
  838. * const div = styled.div`
  839. * transitionTimingFunction: ${easeIn('quad')};
  840. * `
  841. *
  842. * // CSS as JS Output
  843. *
  844. * 'div': {
  845. * 'transitionTimingFunction': 'cubic-bezier(0.550, 0.085, 0.680, 0.530)',
  846. * }
  847. */
  848. function easeIn(functionName) {
  849. return functionsMap$3[functionName.toLowerCase().trim()];
  850. }
  851. var functionsMap$2 = {
  852. back: 'cubic-bezier(0.680, -0.550, 0.265, 1.550)',
  853. circ: 'cubic-bezier(0.785, 0.135, 0.150, 0.860)',
  854. cubic: 'cubic-bezier(0.645, 0.045, 0.355, 1.000)',
  855. expo: 'cubic-bezier(1.000, 0.000, 0.000, 1.000)',
  856. quad: 'cubic-bezier(0.455, 0.030, 0.515, 0.955)',
  857. quart: 'cubic-bezier(0.770, 0.000, 0.175, 1.000)',
  858. quint: 'cubic-bezier(0.860, 0.000, 0.070, 1.000)',
  859. sine: 'cubic-bezier(0.445, 0.050, 0.550, 0.950)'
  860. };
  861. /**
  862. * String to represent common easing functions as demonstrated here: (github.com/jaukia/easie).
  863. *
  864. * @example
  865. * // Styles as object usage
  866. * const styles = {
  867. * 'transitionTimingFunction': easeInOut('quad')
  868. * }
  869. *
  870. * // styled-components usage
  871. * const div = styled.div`
  872. * transitionTimingFunction: ${easeInOut('quad')};
  873. * `
  874. *
  875. * // CSS as JS Output
  876. *
  877. * 'div': {
  878. * 'transitionTimingFunction': 'cubic-bezier(0.455, 0.030, 0.515, 0.955)',
  879. * }
  880. */
  881. function easeInOut(functionName) {
  882. return functionsMap$2[functionName.toLowerCase().trim()];
  883. }
  884. var functionsMap$1 = {
  885. back: 'cubic-bezier(0.175, 0.885, 0.320, 1.275)',
  886. cubic: 'cubic-bezier(0.215, 0.610, 0.355, 1.000)',
  887. circ: 'cubic-bezier(0.075, 0.820, 0.165, 1.000)',
  888. expo: 'cubic-bezier(0.190, 1.000, 0.220, 1.000)',
  889. quad: 'cubic-bezier(0.250, 0.460, 0.450, 0.940)',
  890. quart: 'cubic-bezier(0.165, 0.840, 0.440, 1.000)',
  891. quint: 'cubic-bezier(0.230, 1.000, 0.320, 1.000)',
  892. sine: 'cubic-bezier(0.390, 0.575, 0.565, 1.000)'
  893. };
  894. /**
  895. * String to represent common easing functions as demonstrated here: (github.com/jaukia/easie).
  896. *
  897. * @example
  898. * // Styles as object usage
  899. * const styles = {
  900. * 'transitionTimingFunction': easeOut('quad')
  901. * }
  902. *
  903. * // styled-components usage
  904. * const div = styled.div`
  905. * transitionTimingFunction: ${easeOut('quad')};
  906. * `
  907. *
  908. * // CSS as JS Output
  909. *
  910. * 'div': {
  911. * 'transitionTimingFunction': 'cubic-bezier(0.250, 0.460, 0.450, 0.940)',
  912. * }
  913. */
  914. function easeOut(functionName) {
  915. return functionsMap$1[functionName.toLowerCase().trim()];
  916. }
  917. /**
  918. * Returns a CSS calc formula for linear interpolation of a property between two values. Accepts optional minScreen (defaults to '320px') and maxScreen (defaults to '1200px').
  919. *
  920. * @example
  921. * // Styles as object usage
  922. * const styles = {
  923. * fontSize: between('20px', '100px', '400px', '1000px'),
  924. * fontSize: between('20px', '100px')
  925. * }
  926. *
  927. * // styled-components usage
  928. * const div = styled.div`
  929. * fontSize: ${between('20px', '100px', '400px', '1000px')};
  930. * fontSize: ${between('20px', '100px')}
  931. * `
  932. *
  933. * // CSS as JS Output
  934. *
  935. * h1: {
  936. * 'fontSize': 'calc(-33.33333333333334px + 13.333333333333334vw)',
  937. * 'fontSize': 'calc(-9.090909090909093px + 9.090909090909092vw)'
  938. * }
  939. */
  940. function between(fromSize, toSize, minScreen, maxScreen) {
  941. if (minScreen === void 0) {
  942. minScreen = '320px';
  943. }
  944. if (maxScreen === void 0) {
  945. maxScreen = '1200px';
  946. }
  947. var _getValueAndUnit = getValueAndUnit(fromSize),
  948. unitlessFromSize = _getValueAndUnit[0],
  949. fromSizeUnit = _getValueAndUnit[1];
  950. var _getValueAndUnit2 = getValueAndUnit(toSize),
  951. unitlessToSize = _getValueAndUnit2[0],
  952. toSizeUnit = _getValueAndUnit2[1];
  953. var _getValueAndUnit3 = getValueAndUnit(minScreen),
  954. unitlessMinScreen = _getValueAndUnit3[0],
  955. minScreenUnit = _getValueAndUnit3[1];
  956. var _getValueAndUnit4 = getValueAndUnit(maxScreen),
  957. unitlessMaxScreen = _getValueAndUnit4[0],
  958. maxScreenUnit = _getValueAndUnit4[1];
  959. if (typeof unitlessMinScreen !== 'number' || typeof unitlessMaxScreen !== 'number' || !minScreenUnit || !maxScreenUnit || minScreenUnit !== maxScreenUnit) {
  960. throw new PolishedError(47);
  961. }
  962. if (typeof unitlessFromSize !== 'number' || typeof unitlessToSize !== 'number' || fromSizeUnit !== toSizeUnit) {
  963. throw new PolishedError(48);
  964. }
  965. if (fromSizeUnit !== minScreenUnit || toSizeUnit !== maxScreenUnit) {
  966. throw new PolishedError(76);
  967. }
  968. var slope = (unitlessFromSize - unitlessToSize) / (unitlessMinScreen - unitlessMaxScreen);
  969. var base = unitlessToSize - slope * unitlessMaxScreen;
  970. return "calc(" + base.toFixed(2) + (fromSizeUnit || '') + " + " + (100 * slope).toFixed(2) + "vw)";
  971. }
  972. /**
  973. * CSS to contain a float (credit to CSSMojo).
  974. *
  975. * @example
  976. * // Styles as object usage
  977. * const styles = {
  978. * ...clearFix(),
  979. * }
  980. *
  981. * // styled-components usage
  982. * const div = styled.div`
  983. * ${clearFix()}
  984. * `
  985. *
  986. * // CSS as JS Output
  987. *
  988. * '&::after': {
  989. * 'clear': 'both',
  990. * 'content': '""',
  991. * 'display': 'table'
  992. * }
  993. */
  994. function clearFix(parent) {
  995. var _ref;
  996. if (parent === void 0) {
  997. parent = '&';
  998. }
  999. var pseudoSelector = parent + "::after";
  1000. return _ref = {}, _ref[pseudoSelector] = {
  1001. clear: 'both',
  1002. content: '""',
  1003. display: 'table'
  1004. }, _ref;
  1005. }
  1006. /**
  1007. * CSS to fully cover an area. Can optionally be passed an offset to act as a "padding".
  1008. *
  1009. * @example
  1010. * // Styles as object usage
  1011. * const styles = {
  1012. * ...cover()
  1013. * }
  1014. *
  1015. * // styled-components usage
  1016. * const div = styled.div`
  1017. * ${cover()}
  1018. * `
  1019. *
  1020. * // CSS as JS Output
  1021. *
  1022. * div: {
  1023. * 'position': 'absolute',
  1024. * 'top': '0',
  1025. * 'right: '0',
  1026. * 'bottom': '0',
  1027. * 'left: '0'
  1028. * }
  1029. */
  1030. function cover(offset) {
  1031. if (offset === void 0) {
  1032. offset = 0;
  1033. }
  1034. return {
  1035. position: 'absolute',
  1036. top: offset,
  1037. right: offset,
  1038. bottom: offset,
  1039. left: offset
  1040. };
  1041. }
  1042. /**
  1043. * CSS to represent truncated text with an ellipsis. You can optionally pass a max-width and number of lines before truncating.
  1044. *
  1045. * @example
  1046. * // Styles as object usage
  1047. * const styles = {
  1048. * ...ellipsis('250px')
  1049. * }
  1050. *
  1051. * // styled-components usage
  1052. * const div = styled.div`
  1053. * ${ellipsis('250px')}
  1054. * `
  1055. *
  1056. * // CSS as JS Output
  1057. *
  1058. * div: {
  1059. * 'display': 'inline-block',
  1060. * 'maxWidth': '250px',
  1061. * 'overflow': 'hidden',
  1062. * 'textOverflow': 'ellipsis',
  1063. * 'whiteSpace': 'nowrap',
  1064. * 'wordWrap': 'normal'
  1065. * }
  1066. */
  1067. function ellipsis(width, lines) {
  1068. if (lines === void 0) {
  1069. lines = 1;
  1070. }
  1071. var styles = {
  1072. display: 'inline-block',
  1073. maxWidth: width || '100%',
  1074. overflow: 'hidden',
  1075. textOverflow: 'ellipsis',
  1076. whiteSpace: 'nowrap',
  1077. wordWrap: 'normal'
  1078. };
  1079. return lines > 1 ? _extends__default['default']({}, styles, {
  1080. WebkitBoxOrient: 'vertical',
  1081. WebkitLineClamp: lines,
  1082. display: '-webkit-box',
  1083. whiteSpace: 'normal'
  1084. }) : styles;
  1085. }
  1086. function _createForOfIteratorHelperLoose(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (it) return (it = it.call(o)).next.bind(it); if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
  1087. function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
  1088. function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
  1089. /**
  1090. * Returns a set of media queries that resizes a property (or set of properties) between a provided fromSize and toSize. Accepts optional minScreen (defaults to '320px') and maxScreen (defaults to '1200px') to constrain the interpolation.
  1091. *
  1092. * @example
  1093. * // Styles as object usage
  1094. * const styles = {
  1095. * ...fluidRange(
  1096. * {
  1097. * prop: 'padding',
  1098. * fromSize: '20px',
  1099. * toSize: '100px',
  1100. * },
  1101. * '400px',
  1102. * '1000px',
  1103. * )
  1104. * }
  1105. *
  1106. * // styled-components usage
  1107. * const div = styled.div`
  1108. * ${fluidRange(
  1109. * {
  1110. * prop: 'padding',
  1111. * fromSize: '20px',
  1112. * toSize: '100px',
  1113. * },
  1114. * '400px',
  1115. * '1000px',
  1116. * )}
  1117. * `
  1118. *
  1119. * // CSS as JS Output
  1120. *
  1121. * div: {
  1122. * "@media (min-width: 1000px)": Object {
  1123. * "padding": "100px",
  1124. * },
  1125. * "@media (min-width: 400px)": Object {
  1126. * "padding": "calc(-33.33333333333334px + 13.333333333333334vw)",
  1127. * },
  1128. * "padding": "20px",
  1129. * }
  1130. */
  1131. function fluidRange(cssProp, minScreen, maxScreen) {
  1132. if (minScreen === void 0) {
  1133. minScreen = '320px';
  1134. }
  1135. if (maxScreen === void 0) {
  1136. maxScreen = '1200px';
  1137. }
  1138. if (!Array.isArray(cssProp) && typeof cssProp !== 'object' || cssProp === null) {
  1139. throw new PolishedError(49);
  1140. }
  1141. if (Array.isArray(cssProp)) {
  1142. var mediaQueries = {};
  1143. var fallbacks = {};
  1144. for (var _iterator = _createForOfIteratorHelperLoose(cssProp), _step; !(_step = _iterator()).done;) {
  1145. var _extends2, _extends3;
  1146. var obj = _step.value;
  1147. if (!obj.prop || !obj.fromSize || !obj.toSize) {
  1148. throw new PolishedError(50);
  1149. }
  1150. fallbacks[obj.prop] = obj.fromSize;
  1151. mediaQueries["@media (min-width: " + minScreen + ")"] = _extends__default['default']({}, mediaQueries["@media (min-width: " + minScreen + ")"], (_extends2 = {}, _extends2[obj.prop] = between(obj.fromSize, obj.toSize, minScreen, maxScreen), _extends2));
  1152. mediaQueries["@media (min-width: " + maxScreen + ")"] = _extends__default['default']({}, mediaQueries["@media (min-width: " + maxScreen + ")"], (_extends3 = {}, _extends3[obj.prop] = obj.toSize, _extends3));
  1153. }
  1154. return _extends__default['default']({}, fallbacks, mediaQueries);
  1155. } else {
  1156. var _ref, _ref2, _ref3;
  1157. if (!cssProp.prop || !cssProp.fromSize || !cssProp.toSize) {
  1158. throw new PolishedError(51);
  1159. }
  1160. return _ref3 = {}, _ref3[cssProp.prop] = cssProp.fromSize, _ref3["@media (min-width: " + minScreen + ")"] = (_ref = {}, _ref[cssProp.prop] = between(cssProp.fromSize, cssProp.toSize, minScreen, maxScreen), _ref), _ref3["@media (min-width: " + maxScreen + ")"] = (_ref2 = {}, _ref2[cssProp.prop] = cssProp.toSize, _ref2), _ref3;
  1161. }
  1162. }
  1163. var dataURIRegex = /^\s*data:([a-z]+\/[a-z-]+(;[a-z-]+=[a-z-]+)?)?(;charset=[a-z0-9-]+)?(;base64)?,[a-z0-9!$&',()*+,;=\-._~:@/?%\s]*\s*$/i;
  1164. var formatHintMap = {
  1165. woff: 'woff',
  1166. woff2: 'woff2',
  1167. ttf: 'truetype',
  1168. otf: 'opentype',
  1169. eot: 'embedded-opentype',
  1170. svg: 'svg',
  1171. svgz: 'svg'
  1172. };
  1173. function generateFormatHint(format, formatHint) {
  1174. if (!formatHint) return '';
  1175. return " format(\"" + formatHintMap[format] + "\")";
  1176. }
  1177. function isDataURI(fontFilePath) {
  1178. return !!fontFilePath.replace(/\s+/g, ' ').match(dataURIRegex);
  1179. }
  1180. function generateFileReferences(fontFilePath, fileFormats, formatHint) {
  1181. if (isDataURI(fontFilePath)) {
  1182. return "url(\"" + fontFilePath + "\")" + generateFormatHint(fileFormats[0], formatHint);
  1183. }
  1184. var fileFontReferences = fileFormats.map(function (format) {
  1185. return "url(\"" + fontFilePath + "." + format + "\")" + generateFormatHint(format, formatHint);
  1186. });
  1187. return fileFontReferences.join(', ');
  1188. }
  1189. function generateLocalReferences(localFonts) {
  1190. var localFontReferences = localFonts.map(function (font) {
  1191. return "local(\"" + font + "\")";
  1192. });
  1193. return localFontReferences.join(', ');
  1194. }
  1195. function generateSources(fontFilePath, localFonts, fileFormats, formatHint) {
  1196. var fontReferences = [];
  1197. if (localFonts) fontReferences.push(generateLocalReferences(localFonts));
  1198. if (fontFilePath) {
  1199. fontReferences.push(generateFileReferences(fontFilePath, fileFormats, formatHint));
  1200. }
  1201. return fontReferences.join(', ');
  1202. }
  1203. /**
  1204. * CSS for a @font-face declaration. Defaults to check for local copies of the font on the user's machine. You can disable this by passing `null` to localFonts.
  1205. *
  1206. * @example
  1207. * // Styles as object basic usage
  1208. * const styles = {
  1209. * ...fontFace({
  1210. * 'fontFamily': 'Sans-Pro',
  1211. * 'fontFilePath': 'path/to/file'
  1212. * })
  1213. * }
  1214. *
  1215. * // styled-components basic usage
  1216. * const GlobalStyle = createGlobalStyle`${
  1217. * fontFace({
  1218. * 'fontFamily': 'Sans-Pro',
  1219. * 'fontFilePath': 'path/to/file'
  1220. * }
  1221. * )}`
  1222. *
  1223. * // CSS as JS Output
  1224. *
  1225. * '@font-face': {
  1226. * 'fontFamily': 'Sans-Pro',
  1227. * 'src': 'url("path/to/file.eot"), url("path/to/file.woff2"), url("path/to/file.woff"), url("path/to/file.ttf"), url("path/to/file.svg")',
  1228. * }
  1229. */
  1230. function fontFace(_ref) {
  1231. var fontFamily = _ref.fontFamily,
  1232. fontFilePath = _ref.fontFilePath,
  1233. fontStretch = _ref.fontStretch,
  1234. fontStyle = _ref.fontStyle,
  1235. fontVariant = _ref.fontVariant,
  1236. fontWeight = _ref.fontWeight,
  1237. _ref$fileFormats = _ref.fileFormats,
  1238. fileFormats = _ref$fileFormats === void 0 ? ['eot', 'woff2', 'woff', 'ttf', 'svg'] : _ref$fileFormats,
  1239. _ref$formatHint = _ref.formatHint,
  1240. formatHint = _ref$formatHint === void 0 ? false : _ref$formatHint,
  1241. _ref$localFonts = _ref.localFonts,
  1242. localFonts = _ref$localFonts === void 0 ? [fontFamily] : _ref$localFonts,
  1243. unicodeRange = _ref.unicodeRange,
  1244. fontDisplay = _ref.fontDisplay,
  1245. fontVariationSettings = _ref.fontVariationSettings,
  1246. fontFeatureSettings = _ref.fontFeatureSettings;
  1247. // Error Handling
  1248. if (!fontFamily) throw new PolishedError(55);
  1249. if (!fontFilePath && !localFonts) {
  1250. throw new PolishedError(52);
  1251. }
  1252. if (localFonts && !Array.isArray(localFonts)) {
  1253. throw new PolishedError(53);
  1254. }
  1255. if (!Array.isArray(fileFormats)) {
  1256. throw new PolishedError(54);
  1257. }
  1258. var fontFaceDeclaration = {
  1259. '@font-face': {
  1260. fontFamily: fontFamily,
  1261. src: generateSources(fontFilePath, localFonts, fileFormats, formatHint),
  1262. unicodeRange: unicodeRange,
  1263. fontStretch: fontStretch,
  1264. fontStyle: fontStyle,
  1265. fontVariant: fontVariant,
  1266. fontWeight: fontWeight,
  1267. fontDisplay: fontDisplay,
  1268. fontVariationSettings: fontVariationSettings,
  1269. fontFeatureSettings: fontFeatureSettings
  1270. }
  1271. }; // Removes undefined fields for cleaner css object.
  1272. return JSON.parse(JSON.stringify(fontFaceDeclaration));
  1273. }
  1274. /**
  1275. * CSS to hide text to show a background image in a SEO-friendly way.
  1276. *
  1277. * @example
  1278. * // Styles as object usage
  1279. * const styles = {
  1280. * 'backgroundImage': 'url(logo.png)',
  1281. * ...hideText(),
  1282. * }
  1283. *
  1284. * // styled-components usage
  1285. * const div = styled.div`
  1286. * backgroundImage: url(logo.png);
  1287. * ${hideText()};
  1288. * `
  1289. *
  1290. * // CSS as JS Output
  1291. *
  1292. * 'div': {
  1293. * 'backgroundImage': 'url(logo.png)',
  1294. * 'textIndent': '101%',
  1295. * 'overflow': 'hidden',
  1296. * 'whiteSpace': 'nowrap',
  1297. * }
  1298. */
  1299. function hideText() {
  1300. return {
  1301. textIndent: '101%',
  1302. overflow: 'hidden',
  1303. whiteSpace: 'nowrap'
  1304. };
  1305. }
  1306. /**
  1307. * CSS to hide content visually but remain accessible to screen readers.
  1308. * from [HTML5 Boilerplate](https://github.com/h5bp/html5-boilerplate/blob/9a176f57af1cfe8ec70300da4621fb9b07e5fa31/src/css/main.css#L121)
  1309. *
  1310. * @example
  1311. * // Styles as object usage
  1312. * const styles = {
  1313. * ...hideVisually(),
  1314. * }
  1315. *
  1316. * // styled-components usage
  1317. * const div = styled.div`
  1318. * ${hideVisually()};
  1319. * `
  1320. *
  1321. * // CSS as JS Output
  1322. *
  1323. * 'div': {
  1324. * 'border': '0',
  1325. * 'clip': 'rect(0 0 0 0)',
  1326. * 'height': '1px',
  1327. * 'margin': '-1px',
  1328. * 'overflow': 'hidden',
  1329. * 'padding': '0',
  1330. * 'position': 'absolute',
  1331. * 'whiteSpace': 'nowrap',
  1332. * 'width': '1px',
  1333. * }
  1334. */
  1335. function hideVisually() {
  1336. return {
  1337. border: '0',
  1338. clip: 'rect(0 0 0 0)',
  1339. height: '1px',
  1340. margin: '-1px',
  1341. overflow: 'hidden',
  1342. padding: '0',
  1343. position: 'absolute',
  1344. whiteSpace: 'nowrap',
  1345. width: '1px'
  1346. };
  1347. }
  1348. /**
  1349. * Generates a media query to target HiDPI devices.
  1350. *
  1351. * @example
  1352. * // Styles as object usage
  1353. * const styles = {
  1354. * [hiDPI(1.5)]: {
  1355. * width: 200px;
  1356. * }
  1357. * }
  1358. *
  1359. * // styled-components usage
  1360. * const div = styled.div`
  1361. * ${hiDPI(1.5)} {
  1362. * width: 200px;
  1363. * }
  1364. * `
  1365. *
  1366. * // CSS as JS Output
  1367. *
  1368. * '@media only screen and (-webkit-min-device-pixel-ratio: 1.5),
  1369. * only screen and (min--moz-device-pixel-ratio: 1.5),
  1370. * only screen and (-o-min-device-pixel-ratio: 1.5/1),
  1371. * only screen and (min-resolution: 144dpi),
  1372. * only screen and (min-resolution: 1.5dppx)': {
  1373. * 'width': '200px',
  1374. * }
  1375. */
  1376. function hiDPI(ratio) {
  1377. if (ratio === void 0) {
  1378. ratio = 1.3;
  1379. }
  1380. return "\n @media only screen and (-webkit-min-device-pixel-ratio: " + ratio + "),\n only screen and (min--moz-device-pixel-ratio: " + ratio + "),\n only screen and (-o-min-device-pixel-ratio: " + ratio + "/1),\n only screen and (min-resolution: " + Math.round(ratio * 96) + "dpi),\n only screen and (min-resolution: " + ratio + "dppx)\n ";
  1381. }
  1382. function constructGradientValue(literals) {
  1383. var template = '';
  1384. for (var _len = arguments.length, substitutions = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  1385. substitutions[_key - 1] = arguments[_key];
  1386. }
  1387. for (var i = 0; i < literals.length; i += 1) {
  1388. template += literals[i];
  1389. if (i === substitutions.length - 1 && substitutions[i]) {
  1390. var definedValues = substitutions.filter(function (substitute) {
  1391. return !!substitute;
  1392. }); // Adds leading coma if properties preceed color-stops
  1393. if (definedValues.length > 1) {
  1394. template = template.slice(0, -1);
  1395. template += ", " + substitutions[i]; // No trailing space if color-stops is the only param provided
  1396. } else if (definedValues.length === 1) {
  1397. template += "" + substitutions[i];
  1398. }
  1399. } else if (substitutions[i]) {
  1400. template += substitutions[i] + " ";
  1401. }
  1402. }
  1403. return template.trim();
  1404. }
  1405. var _templateObject$1;
  1406. /**
  1407. * CSS for declaring a linear gradient, including a fallback background-color. The fallback is either the first color-stop or an explicitly passed fallback color.
  1408. *
  1409. * @example
  1410. * // Styles as object usage
  1411. * const styles = {
  1412. * ...linearGradient({
  1413. colorStops: ['#00FFFF 0%', 'rgba(0, 0, 255, 0) 50%', '#0000FF 95%'],
  1414. toDirection: 'to top right',
  1415. fallback: '#FFF',
  1416. })
  1417. * }
  1418. *
  1419. * // styled-components usage
  1420. * const div = styled.div`
  1421. * ${linearGradient({
  1422. colorStops: ['#00FFFF 0%', 'rgba(0, 0, 255, 0) 50%', '#0000FF 95%'],
  1423. toDirection: 'to top right',
  1424. fallback: '#FFF',
  1425. })}
  1426. *`
  1427. *
  1428. * // CSS as JS Output
  1429. *
  1430. * div: {
  1431. * 'backgroundColor': '#FFF',
  1432. * 'backgroundImage': 'linear-gradient(to top right, #00FFFF 0%, rgba(0, 0, 255, 0) 50%, #0000FF 95%)',
  1433. * }
  1434. */
  1435. function linearGradient(_ref) {
  1436. var colorStops = _ref.colorStops,
  1437. fallback = _ref.fallback,
  1438. _ref$toDirection = _ref.toDirection,
  1439. toDirection = _ref$toDirection === void 0 ? '' : _ref$toDirection;
  1440. if (!colorStops || colorStops.length < 2) {
  1441. throw new PolishedError(56);
  1442. }
  1443. return {
  1444. backgroundColor: fallback || colorStops[0].replace(/,\s+/g, ',').split(' ')[0].replace(/,(?=\S)/g, ', '),
  1445. backgroundImage: constructGradientValue(_templateObject$1 || (_templateObject$1 = _taggedTemplateLiteralLoose__default['default'](["linear-gradient(", "", ")"])), toDirection, colorStops.join(', ').replace(/,(?=\S)/g, ', '))
  1446. };
  1447. }
  1448. /**
  1449. * CSS to normalize abnormalities across browsers (normalize.css v8.0.1 | MIT License | github.com/necolas/normalize.css)
  1450. *
  1451. * @example
  1452. * // Styles as object usage
  1453. * const styles = {
  1454. * ...normalize(),
  1455. * }
  1456. *
  1457. * // styled-components usage
  1458. * const GlobalStyle = createGlobalStyle`${normalize()}`
  1459. *
  1460. * // CSS as JS Output
  1461. *
  1462. * html {
  1463. * lineHeight: 1.15,
  1464. * textSizeAdjust: 100%,
  1465. * } ...
  1466. */
  1467. function normalize() {
  1468. var _ref;
  1469. return [(_ref = {
  1470. html: {
  1471. lineHeight: '1.15',
  1472. textSizeAdjust: '100%'
  1473. },
  1474. body: {
  1475. margin: '0'
  1476. },
  1477. main: {
  1478. display: 'block'
  1479. },
  1480. h1: {
  1481. fontSize: '2em',
  1482. margin: '0.67em 0'
  1483. },
  1484. hr: {
  1485. boxSizing: 'content-box',
  1486. height: '0',
  1487. overflow: 'visible'
  1488. },
  1489. pre: {
  1490. fontFamily: 'monospace, monospace',
  1491. fontSize: '1em'
  1492. },
  1493. a: {
  1494. backgroundColor: 'transparent'
  1495. },
  1496. 'abbr[title]': {
  1497. borderBottom: 'none',
  1498. textDecoration: 'underline'
  1499. }
  1500. }, _ref["b,\n strong"] = {
  1501. fontWeight: 'bolder'
  1502. }, _ref["code,\n kbd,\n samp"] = {
  1503. fontFamily: 'monospace, monospace',
  1504. fontSize: '1em'
  1505. }, _ref.small = {
  1506. fontSize: '80%'
  1507. }, _ref["sub,\n sup"] = {
  1508. fontSize: '75%',
  1509. lineHeight: '0',
  1510. position: 'relative',
  1511. verticalAlign: 'baseline'
  1512. }, _ref.sub = {
  1513. bottom: '-0.25em'
  1514. }, _ref.sup = {
  1515. top: '-0.5em'
  1516. }, _ref.img = {
  1517. borderStyle: 'none'
  1518. }, _ref["button,\n input,\n optgroup,\n select,\n textarea"] = {
  1519. fontFamily: 'inherit',
  1520. fontSize: '100%',
  1521. lineHeight: '1.15',
  1522. margin: '0'
  1523. }, _ref["button,\n input"] = {
  1524. overflow: 'visible'
  1525. }, _ref["button,\n select"] = {
  1526. textTransform: 'none'
  1527. }, _ref["button,\n html [type=\"button\"],\n [type=\"reset\"],\n [type=\"submit\"]"] = {
  1528. WebkitAppearance: 'button'
  1529. }, _ref["button::-moz-focus-inner,\n [type=\"button\"]::-moz-focus-inner,\n [type=\"reset\"]::-moz-focus-inner,\n [type=\"submit\"]::-moz-focus-inner"] = {
  1530. borderStyle: 'none',
  1531. padding: '0'
  1532. }, _ref["button:-moz-focusring,\n [type=\"button\"]:-moz-focusring,\n [type=\"reset\"]:-moz-focusring,\n [type=\"submit\"]:-moz-focusring"] = {
  1533. outline: '1px dotted ButtonText'
  1534. }, _ref.fieldset = {
  1535. padding: '0.35em 0.625em 0.75em'
  1536. }, _ref.legend = {
  1537. boxSizing: 'border-box',
  1538. color: 'inherit',
  1539. display: 'table',
  1540. maxWidth: '100%',
  1541. padding: '0',
  1542. whiteSpace: 'normal'
  1543. }, _ref.progress = {
  1544. verticalAlign: 'baseline'
  1545. }, _ref.textarea = {
  1546. overflow: 'auto'
  1547. }, _ref["[type=\"checkbox\"],\n [type=\"radio\"]"] = {
  1548. boxSizing: 'border-box',
  1549. padding: '0'
  1550. }, _ref["[type=\"number\"]::-webkit-inner-spin-button,\n [type=\"number\"]::-webkit-outer-spin-button"] = {
  1551. height: 'auto'
  1552. }, _ref['[type="search"]'] = {
  1553. WebkitAppearance: 'textfield',
  1554. outlineOffset: '-2px'
  1555. }, _ref['[type="search"]::-webkit-search-decoration'] = {
  1556. WebkitAppearance: 'none'
  1557. }, _ref['::-webkit-file-upload-button'] = {
  1558. WebkitAppearance: 'button',
  1559. font: 'inherit'
  1560. }, _ref.details = {
  1561. display: 'block'
  1562. }, _ref.summary = {
  1563. display: 'list-item'
  1564. }, _ref.template = {
  1565. display: 'none'
  1566. }, _ref['[hidden]'] = {
  1567. display: 'none'
  1568. }, _ref), {
  1569. 'abbr[title]': {
  1570. textDecoration: 'underline dotted'
  1571. }
  1572. }];
  1573. }
  1574. var _templateObject;
  1575. /**
  1576. * CSS for declaring a radial gradient, including a fallback background-color. The fallback is either the first color-stop or an explicitly passed fallback color.
  1577. *
  1578. * @example
  1579. * // Styles as object usage
  1580. * const styles = {
  1581. * ...radialGradient({
  1582. * colorStops: ['#00FFFF 0%', 'rgba(0, 0, 255, 0) 50%', '#0000FF 95%'],
  1583. * extent: 'farthest-corner at 45px 45px',
  1584. * position: 'center',
  1585. * shape: 'ellipse',
  1586. * })
  1587. * }
  1588. *
  1589. * // styled-components usage
  1590. * const div = styled.div`
  1591. * ${radialGradient({
  1592. * colorStops: ['#00FFFF 0%', 'rgba(0, 0, 255, 0) 50%', '#0000FF 95%'],
  1593. * extent: 'farthest-corner at 45px 45px',
  1594. * position: 'center',
  1595. * shape: 'ellipse',
  1596. * })}
  1597. *`
  1598. *
  1599. * // CSS as JS Output
  1600. *
  1601. * div: {
  1602. * 'backgroundColor': '#00FFFF',
  1603. * 'backgroundImage': 'radial-gradient(center ellipse farthest-corner at 45px 45px, #00FFFF 0%, rgba(0, 0, 255, 0) 50%, #0000FF 95%)',
  1604. * }
  1605. */
  1606. function radialGradient(_ref) {
  1607. var colorStops = _ref.colorStops,
  1608. _ref$extent = _ref.extent,
  1609. extent = _ref$extent === void 0 ? '' : _ref$extent,
  1610. fallback = _ref.fallback,
  1611. _ref$position = _ref.position,
  1612. position = _ref$position === void 0 ? '' : _ref$position,
  1613. _ref$shape = _ref.shape,
  1614. shape = _ref$shape === void 0 ? '' : _ref$shape;
  1615. if (!colorStops || colorStops.length < 2) {
  1616. throw new PolishedError(57);
  1617. }
  1618. return {
  1619. backgroundColor: fallback || colorStops[0].split(' ')[0],
  1620. backgroundImage: constructGradientValue(_templateObject || (_templateObject = _taggedTemplateLiteralLoose__default['default'](["radial-gradient(", "", "", "", ")"])), position, shape, extent, colorStops.join(', '))
  1621. };
  1622. }
  1623. /**
  1624. * A helper to generate a retina background image and non-retina
  1625. * background image. The retina background image will output to a HiDPI media query. The mixin uses
  1626. * a _2x.png filename suffix by default.
  1627. *
  1628. * @example
  1629. * // Styles as object usage
  1630. * const styles = {
  1631. * ...retinaImage('my-img')
  1632. * }
  1633. *
  1634. * // styled-components usage
  1635. * const div = styled.div`
  1636. * ${retinaImage('my-img')}
  1637. * `
  1638. *
  1639. * // CSS as JS Output
  1640. * div {
  1641. * backgroundImage: 'url(my-img.png)',
  1642. * '@media only screen and (-webkit-min-device-pixel-ratio: 1.3),
  1643. * only screen and (min--moz-device-pixel-ratio: 1.3),
  1644. * only screen and (-o-min-device-pixel-ratio: 1.3/1),
  1645. * only screen and (min-resolution: 144dpi),
  1646. * only screen and (min-resolution: 1.5dppx)': {
  1647. * backgroundImage: 'url(my-img_2x.png)',
  1648. * }
  1649. * }
  1650. */
  1651. function retinaImage(filename, backgroundSize, extension, retinaFilename, retinaSuffix) {
  1652. var _ref;
  1653. if (extension === void 0) {
  1654. extension = 'png';
  1655. }
  1656. if (retinaSuffix === void 0) {
  1657. retinaSuffix = '_2x';
  1658. }
  1659. if (!filename) {
  1660. throw new PolishedError(58);
  1661. } // Replace the dot at the beginning of the passed extension if one exists
  1662. var ext = extension.replace(/^\./, '');
  1663. var rFilename = retinaFilename ? retinaFilename + "." + ext : "" + filename + retinaSuffix + "." + ext;
  1664. return _ref = {
  1665. backgroundImage: "url(" + filename + "." + ext + ")"
  1666. }, _ref[hiDPI()] = _extends__default['default']({
  1667. backgroundImage: "url(" + rFilename + ")"
  1668. }, backgroundSize ? {
  1669. backgroundSize: backgroundSize
  1670. } : {}), _ref;
  1671. }
  1672. /* eslint-disable key-spacing */
  1673. var functionsMap = {
  1674. easeInBack: 'cubic-bezier(0.600, -0.280, 0.735, 0.045)',
  1675. easeInCirc: 'cubic-bezier(0.600, 0.040, 0.980, 0.335)',
  1676. easeInCubic: 'cubic-bezier(0.550, 0.055, 0.675, 0.190)',
  1677. easeInExpo: 'cubic-bezier(0.950, 0.050, 0.795, 0.035)',
  1678. easeInQuad: 'cubic-bezier(0.550, 0.085, 0.680, 0.530)',
  1679. easeInQuart: 'cubic-bezier(0.895, 0.030, 0.685, 0.220)',
  1680. easeInQuint: 'cubic-bezier(0.755, 0.050, 0.855, 0.060)',
  1681. easeInSine: 'cubic-bezier(0.470, 0.000, 0.745, 0.715)',
  1682. easeOutBack: 'cubic-bezier(0.175, 0.885, 0.320, 1.275)',
  1683. easeOutCubic: 'cubic-bezier(0.215, 0.610, 0.355, 1.000)',
  1684. easeOutCirc: 'cubic-bezier(0.075, 0.820, 0.165, 1.000)',
  1685. easeOutExpo: 'cubic-bezier(0.190, 1.000, 0.220, 1.000)',
  1686. easeOutQuad: 'cubic-bezier(0.250, 0.460, 0.450, 0.940)',
  1687. easeOutQuart: 'cubic-bezier(0.165, 0.840, 0.440, 1.000)',
  1688. easeOutQuint: 'cubic-bezier(0.230, 1.000, 0.320, 1.000)',
  1689. easeOutSine: 'cubic-bezier(0.390, 0.575, 0.565, 1.000)',
  1690. easeInOutBack: 'cubic-bezier(0.680, -0.550, 0.265, 1.550)',
  1691. easeInOutCirc: 'cubic-bezier(0.785, 0.135, 0.150, 0.860)',
  1692. easeInOutCubic: 'cubic-bezier(0.645, 0.045, 0.355, 1.000)',
  1693. easeInOutExpo: 'cubic-bezier(1.000, 0.000, 0.000, 1.000)',
  1694. easeInOutQuad: 'cubic-bezier(0.455, 0.030, 0.515, 0.955)',
  1695. easeInOutQuart: 'cubic-bezier(0.770, 0.000, 0.175, 1.000)',
  1696. easeInOutQuint: 'cubic-bezier(0.860, 0.000, 0.070, 1.000)',
  1697. easeInOutSine: 'cubic-bezier(0.445, 0.050, 0.550, 0.950)'
  1698. };
  1699. /* eslint-enable key-spacing */
  1700. function getTimingFunction(functionName) {
  1701. return functionsMap[functionName];
  1702. }
  1703. /**
  1704. * String to represent common easing functions as demonstrated here: (github.com/jaukia/easie).
  1705. *
  1706. * @deprecated - This will be deprecated in v5 in favor of `easeIn`, `easeOut`, `easeInOut`.
  1707. *
  1708. * @example
  1709. * // Styles as object usage
  1710. * const styles = {
  1711. * 'transitionTimingFunction': timingFunctions('easeInQuad')
  1712. * }
  1713. *
  1714. * // styled-components usage
  1715. * const div = styled.div`
  1716. * transitionTimingFunction: ${timingFunctions('easeInQuad')};
  1717. * `
  1718. *
  1719. * // CSS as JS Output
  1720. *
  1721. * 'div': {
  1722. * 'transitionTimingFunction': 'cubic-bezier(0.550, 0.085, 0.680, 0.530)',
  1723. * }
  1724. */
  1725. function timingFunctions(timingFunction) {
  1726. return getTimingFunction(timingFunction);
  1727. }
  1728. var getBorderWidth = function getBorderWidth(pointingDirection, height, width) {
  1729. var fullWidth = "" + width[0] + (width[1] || '');
  1730. var halfWidth = "" + width[0] / 2 + (width[1] || '');
  1731. var fullHeight = "" + height[0] + (height[1] || '');
  1732. var halfHeight = "" + height[0] / 2 + (height[1] || '');
  1733. switch (pointingDirection) {
  1734. case 'top':
  1735. return "0 " + halfWidth + " " + fullHeight + " " + halfWidth;
  1736. case 'topLeft':
  1737. return fullWidth + " " + fullHeight + " 0 0";
  1738. case 'left':
  1739. return halfHeight + " " + fullWidth + " " + halfHeight + " 0";
  1740. case 'bottomLeft':
  1741. return fullWidth + " 0 0 " + fullHeight;
  1742. case 'bottom':
  1743. return fullHeight + " " + halfWidth + " 0 " + halfWidth;
  1744. case 'bottomRight':
  1745. return "0 0 " + fullWidth + " " + fullHeight;
  1746. case 'right':
  1747. return halfHeight + " 0 " + halfHeight + " " + fullWidth;
  1748. case 'topRight':
  1749. default:
  1750. return "0 " + fullWidth + " " + fullHeight + " 0";
  1751. }
  1752. };
  1753. var getBorderColor = function getBorderColor(pointingDirection, foregroundColor) {
  1754. switch (pointingDirection) {
  1755. case 'top':
  1756. case 'bottomRight':
  1757. return {
  1758. borderBottomColor: foregroundColor
  1759. };
  1760. case 'right':
  1761. case 'bottomLeft':
  1762. return {
  1763. borderLeftColor: foregroundColor
  1764. };
  1765. case 'bottom':
  1766. case 'topLeft':
  1767. return {
  1768. borderTopColor: foregroundColor
  1769. };
  1770. case 'left':
  1771. case 'topRight':
  1772. return {
  1773. borderRightColor: foregroundColor
  1774. };
  1775. default:
  1776. throw new PolishedError(59);
  1777. }
  1778. };
  1779. /**
  1780. * CSS to represent triangle with any pointing direction with an optional background color.
  1781. *
  1782. * @example
  1783. * // Styles as object usage
  1784. *
  1785. * const styles = {
  1786. * ...triangle({ pointingDirection: 'right', width: '100px', height: '100px', foregroundColor: 'red' })
  1787. * }
  1788. *
  1789. *
  1790. * // styled-components usage
  1791. * const div = styled.div`
  1792. * ${triangle({ pointingDirection: 'right', width: '100px', height: '100px', foregroundColor: 'red' })}
  1793. *
  1794. *
  1795. * // CSS as JS Output
  1796. *
  1797. * div: {
  1798. * 'borderColor': 'transparent transparent transparent red',
  1799. * 'borderStyle': 'solid',
  1800. * 'borderWidth': '50px 0 50px 100px',
  1801. * 'height': '0',
  1802. * 'width': '0',
  1803. * }
  1804. */
  1805. function triangle(_ref) {
  1806. var pointingDirection = _ref.pointingDirection,
  1807. height = _ref.height,
  1808. width = _ref.width,
  1809. foregroundColor = _ref.foregroundColor,
  1810. _ref$backgroundColor = _ref.backgroundColor,
  1811. backgroundColor = _ref$backgroundColor === void 0 ? 'transparent' : _ref$backgroundColor;
  1812. var widthAndUnit = getValueAndUnit(width);
  1813. var heightAndUnit = getValueAndUnit(height);
  1814. if (isNaN(heightAndUnit[0]) || isNaN(widthAndUnit[0])) {
  1815. throw new PolishedError(60);
  1816. }
  1817. return _extends__default['default']({
  1818. width: '0',
  1819. height: '0',
  1820. borderColor: backgroundColor
  1821. }, getBorderColor(pointingDirection, foregroundColor), {
  1822. borderStyle: 'solid',
  1823. borderWidth: getBorderWidth(pointingDirection, heightAndUnit, widthAndUnit)
  1824. });
  1825. }
  1826. /**
  1827. * Provides an easy way to change the `wordWrap` property.
  1828. *
  1829. * @example
  1830. * // Styles as object usage
  1831. * const styles = {
  1832. * ...wordWrap('break-word')
  1833. * }
  1834. *
  1835. * // styled-components usage
  1836. * const div = styled.div`
  1837. * ${wordWrap('break-word')}
  1838. * `
  1839. *
  1840. * // CSS as JS Output
  1841. *
  1842. * const styles = {
  1843. * overflowWrap: 'break-word',
  1844. * wordWrap: 'break-word',
  1845. * wordBreak: 'break-all',
  1846. * }
  1847. */
  1848. function wordWrap(wrap) {
  1849. if (wrap === void 0) {
  1850. wrap = 'break-word';
  1851. }
  1852. var wordBreak = wrap === 'break-word' ? 'break-all' : wrap;
  1853. return {
  1854. overflowWrap: wrap,
  1855. wordWrap: wrap,
  1856. wordBreak: wordBreak
  1857. };
  1858. }
  1859. function colorToInt(color) {
  1860. return Math.round(color * 255);
  1861. }
  1862. function convertToInt(red, green, blue) {
  1863. return colorToInt(red) + "," + colorToInt(green) + "," + colorToInt(blue);
  1864. }
  1865. function hslToRgb(hue, saturation, lightness, convert) {
  1866. if (convert === void 0) {
  1867. convert = convertToInt;
  1868. }
  1869. if (saturation === 0) {
  1870. // achromatic
  1871. return convert(lightness, lightness, lightness);
  1872. } // formulae from https://en.wikipedia.org/wiki/HSL_and_HSV
  1873. var huePrime = (hue % 360 + 360) % 360 / 60;
  1874. var chroma = (1 - Math.abs(2 * lightness - 1)) * saturation;
  1875. var secondComponent = chroma * (1 - Math.abs(huePrime % 2 - 1));
  1876. var red = 0;
  1877. var green = 0;
  1878. var blue = 0;
  1879. if (huePrime >= 0 && huePrime < 1) {
  1880. red = chroma;
  1881. green = secondComponent;
  1882. } else if (huePrime >= 1 && huePrime < 2) {
  1883. red = secondComponent;
  1884. green = chroma;
  1885. } else if (huePrime >= 2 && huePrime < 3) {
  1886. green = chroma;
  1887. blue = secondComponent;
  1888. } else if (huePrime >= 3 && huePrime < 4) {
  1889. green = secondComponent;
  1890. blue = chroma;
  1891. } else if (huePrime >= 4 && huePrime < 5) {
  1892. red = secondComponent;
  1893. blue = chroma;
  1894. } else if (huePrime >= 5 && huePrime < 6) {
  1895. red = chroma;
  1896. blue = secondComponent;
  1897. }
  1898. var lightnessModification = lightness - chroma / 2;
  1899. var finalRed = red + lightnessModification;
  1900. var finalGreen = green + lightnessModification;
  1901. var finalBlue = blue + lightnessModification;
  1902. return convert(finalRed, finalGreen, finalBlue);
  1903. }
  1904. var namedColorMap = {
  1905. aliceblue: 'f0f8ff',
  1906. antiquewhite: 'faebd7',
  1907. aqua: '00ffff',
  1908. aquamarine: '7fffd4',
  1909. azure: 'f0ffff',
  1910. beige: 'f5f5dc',
  1911. bisque: 'ffe4c4',
  1912. black: '000',
  1913. blanchedalmond: 'ffebcd',
  1914. blue: '0000ff',
  1915. blueviolet: '8a2be2',
  1916. brown: 'a52a2a',
  1917. burlywood: 'deb887',
  1918. cadetblue: '5f9ea0',
  1919. chartreuse: '7fff00',
  1920. chocolate: 'd2691e',
  1921. coral: 'ff7f50',
  1922. cornflowerblue: '6495ed',
  1923. cornsilk: 'fff8dc',
  1924. crimson: 'dc143c',
  1925. cyan: '00ffff',
  1926. darkblue: '00008b',
  1927. darkcyan: '008b8b',
  1928. darkgoldenrod: 'b8860b',
  1929. darkgray: 'a9a9a9',
  1930. darkgreen: '006400',
  1931. darkgrey: 'a9a9a9',
  1932. darkkhaki: 'bdb76b',
  1933. darkmagenta: '8b008b',
  1934. darkolivegreen: '556b2f',
  1935. darkorange: 'ff8c00',
  1936. darkorchid: '9932cc',
  1937. darkred: '8b0000',
  1938. darksalmon: 'e9967a',
  1939. darkseagreen: '8fbc8f',
  1940. darkslateblue: '483d8b',
  1941. darkslategray: '2f4f4f',
  1942. darkslategrey: '2f4f4f',
  1943. darkturquoise: '00ced1',
  1944. darkviolet: '9400d3',
  1945. deeppink: 'ff1493',
  1946. deepskyblue: '00bfff',
  1947. dimgray: '696969',
  1948. dimgrey: '696969',
  1949. dodgerblue: '1e90ff',
  1950. firebrick: 'b22222',
  1951. floralwhite: 'fffaf0',
  1952. forestgreen: '228b22',
  1953. fuchsia: 'ff00ff',
  1954. gainsboro: 'dcdcdc',
  1955. ghostwhite: 'f8f8ff',
  1956. gold: 'ffd700',
  1957. goldenrod: 'daa520',
  1958. gray: '808080',
  1959. green: '008000',
  1960. greenyellow: 'adff2f',
  1961. grey: '808080',
  1962. honeydew: 'f0fff0',
  1963. hotpink: 'ff69b4',
  1964. indianred: 'cd5c5c',
  1965. indigo: '4b0082',
  1966. ivory: 'fffff0',
  1967. khaki: 'f0e68c',
  1968. lavender: 'e6e6fa',
  1969. lavenderblush: 'fff0f5',
  1970. lawngreen: '7cfc00',
  1971. lemonchiffon: 'fffacd',
  1972. lightblue: 'add8e6',
  1973. lightcoral: 'f08080',
  1974. lightcyan: 'e0ffff',
  1975. lightgoldenrodyellow: 'fafad2',
  1976. lightgray: 'd3d3d3',
  1977. lightgreen: '90ee90',
  1978. lightgrey: 'd3d3d3',
  1979. lightpink: 'ffb6c1',
  1980. lightsalmon: 'ffa07a',
  1981. lightseagreen: '20b2aa',
  1982. lightskyblue: '87cefa',
  1983. lightslategray: '789',
  1984. lightslategrey: '789',
  1985. lightsteelblue: 'b0c4de',
  1986. lightyellow: 'ffffe0',
  1987. lime: '0f0',
  1988. limegreen: '32cd32',
  1989. linen: 'faf0e6',
  1990. magenta: 'f0f',
  1991. maroon: '800000',
  1992. mediumaquamarine: '66cdaa',
  1993. mediumblue: '0000cd',
  1994. mediumorchid: 'ba55d3',
  1995. mediumpurple: '9370db',
  1996. mediumseagreen: '3cb371',
  1997. mediumslateblue: '7b68ee',
  1998. mediumspringgreen: '00fa9a',
  1999. mediumturquoise: '48d1cc',
  2000. mediumvioletred: 'c71585',
  2001. midnightblue: '191970',
  2002. mintcream: 'f5fffa',
  2003. mistyrose: 'ffe4e1',
  2004. moccasin: 'ffe4b5',
  2005. navajowhite: 'ffdead',
  2006. navy: '000080',
  2007. oldlace: 'fdf5e6',
  2008. olive: '808000',
  2009. olivedrab: '6b8e23',
  2010. orange: 'ffa500',
  2011. orangered: 'ff4500',
  2012. orchid: 'da70d6',
  2013. palegoldenrod: 'eee8aa',
  2014. palegreen: '98fb98',
  2015. paleturquoise: 'afeeee',
  2016. palevioletred: 'db7093',
  2017. papayawhip: 'ffefd5',
  2018. peachpuff: 'ffdab9',
  2019. peru: 'cd853f',
  2020. pink: 'ffc0cb',
  2021. plum: 'dda0dd',
  2022. powderblue: 'b0e0e6',
  2023. purple: '800080',
  2024. rebeccapurple: '639',
  2025. red: 'f00',
  2026. rosybrown: 'bc8f8f',
  2027. royalblue: '4169e1',
  2028. saddlebrown: '8b4513',
  2029. salmon: 'fa8072',
  2030. sandybrown: 'f4a460',
  2031. seagreen: '2e8b57',
  2032. seashell: 'fff5ee',
  2033. sienna: 'a0522d',
  2034. silver: 'c0c0c0',
  2035. skyblue: '87ceeb',
  2036. slateblue: '6a5acd',
  2037. slategray: '708090',
  2038. slategrey: '708090',
  2039. snow: 'fffafa',
  2040. springgreen: '00ff7f',
  2041. steelblue: '4682b4',
  2042. tan: 'd2b48c',
  2043. teal: '008080',
  2044. thistle: 'd8bfd8',
  2045. tomato: 'ff6347',
  2046. turquoise: '40e0d0',
  2047. violet: 'ee82ee',
  2048. wheat: 'f5deb3',
  2049. white: 'fff',
  2050. whitesmoke: 'f5f5f5',
  2051. yellow: 'ff0',
  2052. yellowgreen: '9acd32'
  2053. };
  2054. /**
  2055. * Checks if a string is a CSS named color and returns its equivalent hex value, otherwise returns the original color.
  2056. * @private
  2057. */
  2058. function nameToHex(color) {
  2059. if (typeof color !== 'string') return color;
  2060. var normalizedColorName = color.toLowerCase();
  2061. return namedColorMap[normalizedColorName] ? "#" + namedColorMap[normalizedColorName] : color;
  2062. }
  2063. var hexRegex = /^#[a-fA-F0-9]{6}$/;
  2064. var hexRgbaRegex = /^#[a-fA-F0-9]{8}$/;
  2065. var reducedHexRegex = /^#[a-fA-F0-9]{3}$/;
  2066. var reducedRgbaHexRegex = /^#[a-fA-F0-9]{4}$/;
  2067. var rgbRegex = /^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$/i;
  2068. var rgbaRegex = /^rgba\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*([-+]?[0-9]*[.]?[0-9]+)\s*\)$/i;
  2069. var hslRegex = /^hsl\(\s*(\d{0,3}[.]?[0-9]+)\s*,\s*(\d{1,3}[.]?[0-9]?)%\s*,\s*(\d{1,3}[.]?[0-9]?)%\s*\)$/i;
  2070. var hslaRegex = /^hsla\(\s*(\d{0,3}[.]?[0-9]+)\s*,\s*(\d{1,3}[.]?[0-9]?)%\s*,\s*(\d{1,3}[.]?[0-9]?)%\s*,\s*([-+]?[0-9]*[.]?[0-9]+)\s*\)$/i;
  2071. /**
  2072. * Returns an RgbColor or RgbaColor object. This utility function is only useful
  2073. * if want to extract a color component. With the color util `toColorString` you
  2074. * can convert a RgbColor or RgbaColor object back to a string.
  2075. *
  2076. * @example
  2077. * // Assigns `{ red: 255, green: 0, blue: 0 }` to color1
  2078. * const color1 = parseToRgb('rgb(255, 0, 0)');
  2079. * // Assigns `{ red: 92, green: 102, blue: 112, alpha: 0.75 }` to color2
  2080. * const color2 = parseToRgb('hsla(210, 10%, 40%, 0.75)');
  2081. */
  2082. function parseToRgb(color) {
  2083. if (typeof color !== 'string') {
  2084. throw new PolishedError(3);
  2085. }
  2086. var normalizedColor = nameToHex(color);
  2087. if (normalizedColor.match(hexRegex)) {
  2088. return {
  2089. red: parseInt("" + normalizedColor[1] + normalizedColor[2], 16),
  2090. green: parseInt("" + normalizedColor[3] + normalizedColor[4], 16),
  2091. blue: parseInt("" + normalizedColor[5] + normalizedColor[6], 16)
  2092. };
  2093. }
  2094. if (normalizedColor.match(hexRgbaRegex)) {
  2095. var alpha = parseFloat((parseInt("" + normalizedColor[7] + normalizedColor[8], 16) / 255).toFixed(2));
  2096. return {
  2097. red: parseInt("" + normalizedColor[1] + normalizedColor[2], 16),
  2098. green: parseInt("" + normalizedColor[3] + normalizedColor[4], 16),
  2099. blue: parseInt("" + normalizedColor[5] + normalizedColor[6], 16),
  2100. alpha: alpha
  2101. };
  2102. }
  2103. if (normalizedColor.match(reducedHexRegex)) {
  2104. return {
  2105. red: parseInt("" + normalizedColor[1] + normalizedColor[1], 16),
  2106. green: parseInt("" + normalizedColor[2] + normalizedColor[2], 16),
  2107. blue: parseInt("" + normalizedColor[3] + normalizedColor[3], 16)
  2108. };
  2109. }
  2110. if (normalizedColor.match(reducedRgbaHexRegex)) {
  2111. var _alpha = parseFloat((parseInt("" + normalizedColor[4] + normalizedColor[4], 16) / 255).toFixed(2));
  2112. return {
  2113. red: parseInt("" + normalizedColor[1] + normalizedColor[1], 16),
  2114. green: parseInt("" + normalizedColor[2] + normalizedColor[2], 16),
  2115. blue: parseInt("" + normalizedColor[3] + normalizedColor[3], 16),
  2116. alpha: _alpha
  2117. };
  2118. }
  2119. var rgbMatched = rgbRegex.exec(normalizedColor);
  2120. if (rgbMatched) {
  2121. return {
  2122. red: parseInt("" + rgbMatched[1], 10),
  2123. green: parseInt("" + rgbMatched[2], 10),
  2124. blue: parseInt("" + rgbMatched[3], 10)
  2125. };
  2126. }
  2127. var rgbaMatched = rgbaRegex.exec(normalizedColor.substring(0, 50));
  2128. if (rgbaMatched) {
  2129. return {
  2130. red: parseInt("" + rgbaMatched[1], 10),
  2131. green: parseInt("" + rgbaMatched[2], 10),
  2132. blue: parseInt("" + rgbaMatched[3], 10),
  2133. alpha: parseFloat("" + rgbaMatched[4])
  2134. };
  2135. }
  2136. var hslMatched = hslRegex.exec(normalizedColor);
  2137. if (hslMatched) {
  2138. var hue = parseInt("" + hslMatched[1], 10);
  2139. var saturation = parseInt("" + hslMatched[2], 10) / 100;
  2140. var lightness = parseInt("" + hslMatched[3], 10) / 100;
  2141. var rgbColorString = "rgb(" + hslToRgb(hue, saturation, lightness) + ")";
  2142. var hslRgbMatched = rgbRegex.exec(rgbColorString);
  2143. if (!hslRgbMatched) {
  2144. throw new PolishedError(4, normalizedColor, rgbColorString);
  2145. }
  2146. return {
  2147. red: parseInt("" + hslRgbMatched[1], 10),
  2148. green: parseInt("" + hslRgbMatched[2], 10),
  2149. blue: parseInt("" + hslRgbMatched[3], 10)
  2150. };
  2151. }
  2152. var hslaMatched = hslaRegex.exec(normalizedColor.substring(0, 50));
  2153. if (hslaMatched) {
  2154. var _hue = parseInt("" + hslaMatched[1], 10);
  2155. var _saturation = parseInt("" + hslaMatched[2], 10) / 100;
  2156. var _lightness = parseInt("" + hslaMatched[3], 10) / 100;
  2157. var _rgbColorString = "rgb(" + hslToRgb(_hue, _saturation, _lightness) + ")";
  2158. var _hslRgbMatched = rgbRegex.exec(_rgbColorString);
  2159. if (!_hslRgbMatched) {
  2160. throw new PolishedError(4, normalizedColor, _rgbColorString);
  2161. }
  2162. return {
  2163. red: parseInt("" + _hslRgbMatched[1], 10),
  2164. green: parseInt("" + _hslRgbMatched[2], 10),
  2165. blue: parseInt("" + _hslRgbMatched[3], 10),
  2166. alpha: parseFloat("" + hslaMatched[4])
  2167. };
  2168. }
  2169. throw new PolishedError(5);
  2170. }
  2171. function rgbToHsl(color) {
  2172. // make sure rgb are contained in a set of [0, 255]
  2173. var red = color.red / 255;
  2174. var green = color.green / 255;
  2175. var blue = color.blue / 255;
  2176. var max = Math.max(red, green, blue);
  2177. var min = Math.min(red, green, blue);
  2178. var lightness = (max + min) / 2;
  2179. if (max === min) {
  2180. // achromatic
  2181. if (color.alpha !== undefined) {
  2182. return {
  2183. hue: 0,
  2184. saturation: 0,
  2185. lightness: lightness,
  2186. alpha: color.alpha
  2187. };
  2188. } else {
  2189. return {
  2190. hue: 0,
  2191. saturation: 0,
  2192. lightness: lightness
  2193. };
  2194. }
  2195. }
  2196. var hue;
  2197. var delta = max - min;
  2198. var saturation = lightness > 0.5 ? delta / (2 - max - min) : delta / (max + min);
  2199. switch (max) {
  2200. case red:
  2201. hue = (green - blue) / delta + (green < blue ? 6 : 0);
  2202. break;
  2203. case green:
  2204. hue = (blue - red) / delta + 2;
  2205. break;
  2206. default:
  2207. // blue case
  2208. hue = (red - green) / delta + 4;
  2209. break;
  2210. }
  2211. hue *= 60;
  2212. if (color.alpha !== undefined) {
  2213. return {
  2214. hue: hue,
  2215. saturation: saturation,
  2216. lightness: lightness,
  2217. alpha: color.alpha
  2218. };
  2219. }
  2220. return {
  2221. hue: hue,
  2222. saturation: saturation,
  2223. lightness: lightness
  2224. };
  2225. }
  2226. /**
  2227. * Returns an HslColor or HslaColor object. This utility function is only useful
  2228. * if want to extract a color component. With the color util `toColorString` you
  2229. * can convert a HslColor or HslaColor object back to a string.
  2230. *
  2231. * @example
  2232. * // Assigns `{ hue: 0, saturation: 1, lightness: 0.5 }` to color1
  2233. * const color1 = parseToHsl('rgb(255, 0, 0)');
  2234. * // Assigns `{ hue: 128, saturation: 1, lightness: 0.5, alpha: 0.75 }` to color2
  2235. * const color2 = parseToHsl('hsla(128, 100%, 50%, 0.75)');
  2236. */
  2237. function parseToHsl(color) {
  2238. // Note: At a later stage we can optimize this function as right now a hsl
  2239. // color would be parsed converted to rgb values and converted back to hsl.
  2240. return rgbToHsl(parseToRgb(color));
  2241. }
  2242. /**
  2243. * Reduces hex values if possible e.g. #ff8866 to #f86
  2244. * @private
  2245. */
  2246. var reduceHexValue = function reduceHexValue(value) {
  2247. if (value.length === 7 && value[1] === value[2] && value[3] === value[4] && value[5] === value[6]) {
  2248. return "#" + value[1] + value[3] + value[5];
  2249. }
  2250. return value;
  2251. };
  2252. function numberToHex(value) {
  2253. var hex = value.toString(16);
  2254. return hex.length === 1 ? "0" + hex : hex;
  2255. }
  2256. function colorToHex(color) {
  2257. return numberToHex(Math.round(color * 255));
  2258. }
  2259. function convertToHex(red, green, blue) {
  2260. return reduceHexValue("#" + colorToHex(red) + colorToHex(green) + colorToHex(blue));
  2261. }
  2262. function hslToHex(hue, saturation, lightness) {
  2263. return hslToRgb(hue, saturation, lightness, convertToHex);
  2264. }
  2265. /**
  2266. * Returns a string value for the color. The returned result is the smallest possible hex notation.
  2267. *
  2268. * @example
  2269. * // Styles as object usage
  2270. * const styles = {
  2271. * background: hsl(359, 0.75, 0.4),
  2272. * background: hsl({ hue: 360, saturation: 0.75, lightness: 0.4 }),
  2273. * }
  2274. *
  2275. * // styled-components usage
  2276. * const div = styled.div`
  2277. * background: ${hsl(359, 0.75, 0.4)};
  2278. * background: ${hsl({ hue: 360, saturation: 0.75, lightness: 0.4 })};
  2279. * `
  2280. *
  2281. * // CSS in JS Output
  2282. *
  2283. * element {
  2284. * background: "#b3191c";
  2285. * background: "#b3191c";
  2286. * }
  2287. */
  2288. function hsl(value, saturation, lightness) {
  2289. if (typeof value === 'number' && typeof saturation === 'number' && typeof lightness === 'number') {
  2290. return hslToHex(value, saturation, lightness);
  2291. } else if (typeof value === 'object' && saturation === undefined && lightness === undefined) {
  2292. return hslToHex(value.hue, value.saturation, value.lightness);
  2293. }
  2294. throw new PolishedError(1);
  2295. }
  2296. /**
  2297. * Returns a string value for the color. The returned result is the smallest possible rgba or hex notation.
  2298. *
  2299. * @example
  2300. * // Styles as object usage
  2301. * const styles = {
  2302. * background: hsla(359, 0.75, 0.4, 0.7),
  2303. * background: hsla({ hue: 360, saturation: 0.75, lightness: 0.4, alpha: 0,7 }),
  2304. * background: hsla(359, 0.75, 0.4, 1),
  2305. * }
  2306. *
  2307. * // styled-components usage
  2308. * const div = styled.div`
  2309. * background: ${hsla(359, 0.75, 0.4, 0.7)};
  2310. * background: ${hsla({ hue: 360, saturation: 0.75, lightness: 0.4, alpha: 0,7 })};
  2311. * background: ${hsla(359, 0.75, 0.4, 1)};
  2312. * `
  2313. *
  2314. * // CSS in JS Output
  2315. *
  2316. * element {
  2317. * background: "rgba(179,25,28,0.7)";
  2318. * background: "rgba(179,25,28,0.7)";
  2319. * background: "#b3191c";
  2320. * }
  2321. */
  2322. function hsla(value, saturation, lightness, alpha) {
  2323. if (typeof value === 'number' && typeof saturation === 'number' && typeof lightness === 'number' && typeof alpha === 'number') {
  2324. return alpha >= 1 ? hslToHex(value, saturation, lightness) : "rgba(" + hslToRgb(value, saturation, lightness) + "," + alpha + ")";
  2325. } else if (typeof value === 'object' && saturation === undefined && lightness === undefined && alpha === undefined) {
  2326. return value.alpha >= 1 ? hslToHex(value.hue, value.saturation, value.lightness) : "rgba(" + hslToRgb(value.hue, value.saturation, value.lightness) + "," + value.alpha + ")";
  2327. }
  2328. throw new PolishedError(2);
  2329. }
  2330. /**
  2331. * Returns a string value for the color. The returned result is the smallest possible hex notation.
  2332. *
  2333. * @example
  2334. * // Styles as object usage
  2335. * const styles = {
  2336. * background: rgb(255, 205, 100),
  2337. * background: rgb({ red: 255, green: 205, blue: 100 }),
  2338. * }
  2339. *
  2340. * // styled-components usage
  2341. * const div = styled.div`
  2342. * background: ${rgb(255, 205, 100)};
  2343. * background: ${rgb({ red: 255, green: 205, blue: 100 })};
  2344. * `
  2345. *
  2346. * // CSS in JS Output
  2347. *
  2348. * element {
  2349. * background: "#ffcd64";
  2350. * background: "#ffcd64";
  2351. * }
  2352. */
  2353. function rgb(value, green, blue) {
  2354. if (typeof value === 'number' && typeof green === 'number' && typeof blue === 'number') {
  2355. return reduceHexValue("#" + numberToHex(value) + numberToHex(green) + numberToHex(blue));
  2356. } else if (typeof value === 'object' && green === undefined && blue === undefined) {
  2357. return reduceHexValue("#" + numberToHex(value.red) + numberToHex(value.green) + numberToHex(value.blue));
  2358. }
  2359. throw new PolishedError(6);
  2360. }
  2361. /**
  2362. * Returns a string value for the color. The returned result is the smallest possible rgba or hex notation.
  2363. *
  2364. * Can also be used to fade a color by passing a hex value or named CSS color along with an alpha value.
  2365. *
  2366. * @example
  2367. * // Styles as object usage
  2368. * const styles = {
  2369. * background: rgba(255, 205, 100, 0.7),
  2370. * background: rgba({ red: 255, green: 205, blue: 100, alpha: 0.7 }),
  2371. * background: rgba(255, 205, 100, 1),
  2372. * background: rgba('#ffffff', 0.4),
  2373. * background: rgba('black', 0.7),
  2374. * }
  2375. *
  2376. * // styled-components usage
  2377. * const div = styled.div`
  2378. * background: ${rgba(255, 205, 100, 0.7)};
  2379. * background: ${rgba({ red: 255, green: 205, blue: 100, alpha: 0.7 })};
  2380. * background: ${rgba(255, 205, 100, 1)};
  2381. * background: ${rgba('#ffffff', 0.4)};
  2382. * background: ${rgba('black', 0.7)};
  2383. * `
  2384. *
  2385. * // CSS in JS Output
  2386. *
  2387. * element {
  2388. * background: "rgba(255,205,100,0.7)";
  2389. * background: "rgba(255,205,100,0.7)";
  2390. * background: "#ffcd64";
  2391. * background: "rgba(255,255,255,0.4)";
  2392. * background: "rgba(0,0,0,0.7)";
  2393. * }
  2394. */
  2395. function rgba(firstValue, secondValue, thirdValue, fourthValue) {
  2396. if (typeof firstValue === 'string' && typeof secondValue === 'number') {
  2397. var rgbValue = parseToRgb(firstValue);
  2398. return "rgba(" + rgbValue.red + "," + rgbValue.green + "," + rgbValue.blue + "," + secondValue + ")";
  2399. } else if (typeof firstValue === 'number' && typeof secondValue === 'number' && typeof thirdValue === 'number' && typeof fourthValue === 'number') {
  2400. return fourthValue >= 1 ? rgb(firstValue, secondValue, thirdValue) : "rgba(" + firstValue + "," + secondValue + "," + thirdValue + "," + fourthValue + ")";
  2401. } else if (typeof firstValue === 'object' && secondValue === undefined && thirdValue === undefined && fourthValue === undefined) {
  2402. return firstValue.alpha >= 1 ? rgb(firstValue.red, firstValue.green, firstValue.blue) : "rgba(" + firstValue.red + "," + firstValue.green + "," + firstValue.blue + "," + firstValue.alpha + ")";
  2403. }
  2404. throw new PolishedError(7);
  2405. }
  2406. var isRgb = function isRgb(color) {
  2407. return typeof color.red === 'number' && typeof color.green === 'number' && typeof color.blue === 'number' && (typeof color.alpha !== 'number' || typeof color.alpha === 'undefined');
  2408. };
  2409. var isRgba = function isRgba(color) {
  2410. return typeof color.red === 'number' && typeof color.green === 'number' && typeof color.blue === 'number' && typeof color.alpha === 'number';
  2411. };
  2412. var isHsl = function isHsl(color) {
  2413. return typeof color.hue === 'number' && typeof color.saturation === 'number' && typeof color.lightness === 'number' && (typeof color.alpha !== 'number' || typeof color.alpha === 'undefined');
  2414. };
  2415. var isHsla = function isHsla(color) {
  2416. return typeof color.hue === 'number' && typeof color.saturation === 'number' && typeof color.lightness === 'number' && typeof color.alpha === 'number';
  2417. };
  2418. /**
  2419. * Converts a RgbColor, RgbaColor, HslColor or HslaColor object to a color string.
  2420. * This util is useful in case you only know on runtime which color object is
  2421. * used. Otherwise we recommend to rely on `rgb`, `rgba`, `hsl` or `hsla`.
  2422. *
  2423. * @example
  2424. * // Styles as object usage
  2425. * const styles = {
  2426. * background: toColorString({ red: 255, green: 205, blue: 100 }),
  2427. * background: toColorString({ red: 255, green: 205, blue: 100, alpha: 0.72 }),
  2428. * background: toColorString({ hue: 240, saturation: 1, lightness: 0.5 }),
  2429. * background: toColorString({ hue: 360, saturation: 0.75, lightness: 0.4, alpha: 0.72 }),
  2430. * }
  2431. *
  2432. * // styled-components usage
  2433. * const div = styled.div`
  2434. * background: ${toColorString({ red: 255, green: 205, blue: 100 })};
  2435. * background: ${toColorString({ red: 255, green: 205, blue: 100, alpha: 0.72 })};
  2436. * background: ${toColorString({ hue: 240, saturation: 1, lightness: 0.5 })};
  2437. * background: ${toColorString({ hue: 360, saturation: 0.75, lightness: 0.4, alpha: 0.72 })};
  2438. * `
  2439. *
  2440. * // CSS in JS Output
  2441. * element {
  2442. * background: "#ffcd64";
  2443. * background: "rgba(255,205,100,0.72)";
  2444. * background: "#00f";
  2445. * background: "rgba(179,25,25,0.72)";
  2446. * }
  2447. */
  2448. function toColorString(color) {
  2449. if (typeof color !== 'object') throw new PolishedError(8);
  2450. if (isRgba(color)) return rgba(color);
  2451. if (isRgb(color)) return rgb(color);
  2452. if (isHsla(color)) return hsla(color);
  2453. if (isHsl(color)) return hsl(color);
  2454. throw new PolishedError(8);
  2455. }
  2456. // Type definitions taken from https://github.com/gcanti/flow-static-land/blob/master/src/Fun.js
  2457. // eslint-disable-next-line no-unused-vars
  2458. // eslint-disable-next-line no-unused-vars
  2459. // eslint-disable-next-line no-redeclare
  2460. function curried(f, length, acc) {
  2461. return function fn() {
  2462. // eslint-disable-next-line prefer-rest-params
  2463. var combined = acc.concat(Array.prototype.slice.call(arguments));
  2464. return combined.length >= length ? f.apply(this, combined) : curried(f, length, combined);
  2465. };
  2466. } // eslint-disable-next-line no-redeclare
  2467. function curry(f) {
  2468. // eslint-disable-line no-redeclare
  2469. return curried(f, f.length, []);
  2470. }
  2471. /**
  2472. * Changes the hue of the color. Hue is a number between 0 to 360. The first
  2473. * argument for adjustHue is the amount of degrees the color is rotated around
  2474. * the color wheel, always producing a positive hue value.
  2475. *
  2476. * @example
  2477. * // Styles as object usage
  2478. * const styles = {
  2479. * background: adjustHue(180, '#448'),
  2480. * background: adjustHue('180', 'rgba(101,100,205,0.7)'),
  2481. * }
  2482. *
  2483. * // styled-components usage
  2484. * const div = styled.div`
  2485. * background: ${adjustHue(180, '#448')};
  2486. * background: ${adjustHue('180', 'rgba(101,100,205,0.7)')};
  2487. * `
  2488. *
  2489. * // CSS in JS Output
  2490. * element {
  2491. * background: "#888844";
  2492. * background: "rgba(136,136,68,0.7)";
  2493. * }
  2494. */
  2495. function adjustHue(degree, color) {
  2496. if (color === 'transparent') return color;
  2497. var hslColor = parseToHsl(color);
  2498. return toColorString(_extends__default['default']({}, hslColor, {
  2499. hue: hslColor.hue + parseFloat(degree)
  2500. }));
  2501. } // prettier-ignore
  2502. var curriedAdjustHue = /*#__PURE__*/curry
  2503. /* ::<number | string, string, string> */
  2504. (adjustHue);
  2505. /**
  2506. * Returns the complement of the provided color. This is identical to adjustHue(180, <color>).
  2507. *
  2508. * @example
  2509. * // Styles as object usage
  2510. * const styles = {
  2511. * background: complement('#448'),
  2512. * background: complement('rgba(204,205,100,0.7)'),
  2513. * }
  2514. *
  2515. * // styled-components usage
  2516. * const div = styled.div`
  2517. * background: ${complement('#448')};
  2518. * background: ${complement('rgba(204,205,100,0.7)')};
  2519. * `
  2520. *
  2521. * // CSS in JS Output
  2522. * element {
  2523. * background: "#884";
  2524. * background: "rgba(153,153,153,0.7)";
  2525. * }
  2526. */
  2527. function complement(color) {
  2528. if (color === 'transparent') return color;
  2529. var hslColor = parseToHsl(color);
  2530. return toColorString(_extends__default['default']({}, hslColor, {
  2531. hue: (hslColor.hue + 180) % 360
  2532. }));
  2533. }
  2534. function guard(lowerBoundary, upperBoundary, value) {
  2535. return Math.max(lowerBoundary, Math.min(upperBoundary, value));
  2536. }
  2537. /**
  2538. * Returns a string value for the darkened color.
  2539. *
  2540. * @example
  2541. * // Styles as object usage
  2542. * const styles = {
  2543. * background: darken(0.2, '#FFCD64'),
  2544. * background: darken('0.2', 'rgba(255,205,100,0.7)'),
  2545. * }
  2546. *
  2547. * // styled-components usage
  2548. * const div = styled.div`
  2549. * background: ${darken(0.2, '#FFCD64')};
  2550. * background: ${darken('0.2', 'rgba(255,205,100,0.7)')};
  2551. * `
  2552. *
  2553. * // CSS in JS Output
  2554. *
  2555. * element {
  2556. * background: "#ffbd31";
  2557. * background: "rgba(255,189,49,0.7)";
  2558. * }
  2559. */
  2560. function darken(amount, color) {
  2561. if (color === 'transparent') return color;
  2562. var hslColor = parseToHsl(color);
  2563. return toColorString(_extends__default['default']({}, hslColor, {
  2564. lightness: guard(0, 1, hslColor.lightness - parseFloat(amount))
  2565. }));
  2566. } // prettier-ignore
  2567. var curriedDarken = /*#__PURE__*/curry
  2568. /* ::<number | string, string, string> */
  2569. (darken);
  2570. /**
  2571. * Decreases the intensity of a color. Its range is between 0 to 1. The first
  2572. * argument of the desaturate function is the amount by how much the color
  2573. * intensity should be decreased.
  2574. *
  2575. * @example
  2576. * // Styles as object usage
  2577. * const styles = {
  2578. * background: desaturate(0.2, '#CCCD64'),
  2579. * background: desaturate('0.2', 'rgba(204,205,100,0.7)'),
  2580. * }
  2581. *
  2582. * // styled-components usage
  2583. * const div = styled.div`
  2584. * background: ${desaturate(0.2, '#CCCD64')};
  2585. * background: ${desaturate('0.2', 'rgba(204,205,100,0.7)')};
  2586. * `
  2587. *
  2588. * // CSS in JS Output
  2589. * element {
  2590. * background: "#b8b979";
  2591. * background: "rgba(184,185,121,0.7)";
  2592. * }
  2593. */
  2594. function desaturate(amount, color) {
  2595. if (color === 'transparent') return color;
  2596. var hslColor = parseToHsl(color);
  2597. return toColorString(_extends__default['default']({}, hslColor, {
  2598. saturation: guard(0, 1, hslColor.saturation - parseFloat(amount))
  2599. }));
  2600. } // prettier-ignore
  2601. var curriedDesaturate = /*#__PURE__*/curry
  2602. /* ::<number | string, string, string> */
  2603. (desaturate);
  2604. /**
  2605. * Returns a number (float) representing the luminance of a color.
  2606. *
  2607. * @example
  2608. * // Styles as object usage
  2609. * const styles = {
  2610. * background: getLuminance('#CCCD64') >= getLuminance('#0000ff') ? '#CCCD64' : '#0000ff',
  2611. * background: getLuminance('rgba(58, 133, 255, 1)') >= getLuminance('rgba(255, 57, 149, 1)') ?
  2612. * 'rgba(58, 133, 255, 1)' :
  2613. * 'rgba(255, 57, 149, 1)',
  2614. * }
  2615. *
  2616. * // styled-components usage
  2617. * const div = styled.div`
  2618. * background: ${getLuminance('#CCCD64') >= getLuminance('#0000ff') ? '#CCCD64' : '#0000ff'};
  2619. * background: ${getLuminance('rgba(58, 133, 255, 1)') >= getLuminance('rgba(255, 57, 149, 1)') ?
  2620. * 'rgba(58, 133, 255, 1)' :
  2621. * 'rgba(255, 57, 149, 1)'};
  2622. *
  2623. * // CSS in JS Output
  2624. *
  2625. * div {
  2626. * background: "#CCCD64";
  2627. * background: "rgba(58, 133, 255, 1)";
  2628. * }
  2629. */
  2630. function getLuminance(color) {
  2631. if (color === 'transparent') return 0;
  2632. var rgbColor = parseToRgb(color);
  2633. var _Object$keys$map = Object.keys(rgbColor).map(function (key) {
  2634. var channel = rgbColor[key] / 255;
  2635. return channel <= 0.03928 ? channel / 12.92 : Math.pow((channel + 0.055) / 1.055, 2.4);
  2636. }),
  2637. r = _Object$keys$map[0],
  2638. g = _Object$keys$map[1],
  2639. b = _Object$keys$map[2];
  2640. return parseFloat((0.2126 * r + 0.7152 * g + 0.0722 * b).toFixed(3));
  2641. }
  2642. /**
  2643. * Returns the contrast ratio between two colors based on
  2644. * [W3's recommended equation for calculating contrast](http://www.w3.org/TR/WCAG20/#contrast-ratiodef).
  2645. *
  2646. * @example
  2647. * const contrastRatio = getContrast('#444', '#fff');
  2648. */
  2649. function getContrast(color1, color2) {
  2650. var luminance1 = getLuminance(color1);
  2651. var luminance2 = getLuminance(color2);
  2652. return parseFloat((luminance1 > luminance2 ? (luminance1 + 0.05) / (luminance2 + 0.05) : (luminance2 + 0.05) / (luminance1 + 0.05)).toFixed(2));
  2653. }
  2654. /**
  2655. * Converts the color to a grayscale, by reducing its saturation to 0.
  2656. *
  2657. * @example
  2658. * // Styles as object usage
  2659. * const styles = {
  2660. * background: grayscale('#CCCD64'),
  2661. * background: grayscale('rgba(204,205,100,0.7)'),
  2662. * }
  2663. *
  2664. * // styled-components usage
  2665. * const div = styled.div`
  2666. * background: ${grayscale('#CCCD64')};
  2667. * background: ${grayscale('rgba(204,205,100,0.7)')};
  2668. * `
  2669. *
  2670. * // CSS in JS Output
  2671. * element {
  2672. * background: "#999";
  2673. * background: "rgba(153,153,153,0.7)";
  2674. * }
  2675. */
  2676. function grayscale(color) {
  2677. if (color === 'transparent') return color;
  2678. return toColorString(_extends__default['default']({}, parseToHsl(color), {
  2679. saturation: 0
  2680. }));
  2681. }
  2682. /**
  2683. * Converts a HslColor or HslaColor object to a color string.
  2684. * This util is useful in case you only know on runtime which color object is
  2685. * used. Otherwise we recommend to rely on `hsl` or `hsla`.
  2686. *
  2687. * @example
  2688. * // Styles as object usage
  2689. * const styles = {
  2690. * background: hslToColorString({ hue: 240, saturation: 1, lightness: 0.5 }),
  2691. * background: hslToColorString({ hue: 360, saturation: 0.75, lightness: 0.4, alpha: 0.72 }),
  2692. * }
  2693. *
  2694. * // styled-components usage
  2695. * const div = styled.div`
  2696. * background: ${hslToColorString({ hue: 240, saturation: 1, lightness: 0.5 })};
  2697. * background: ${hslToColorString({ hue: 360, saturation: 0.75, lightness: 0.4, alpha: 0.72 })};
  2698. * `
  2699. *
  2700. * // CSS in JS Output
  2701. * element {
  2702. * background: "#00f";
  2703. * background: "rgba(179,25,25,0.72)";
  2704. * }
  2705. */
  2706. function hslToColorString(color) {
  2707. if (typeof color === 'object' && typeof color.hue === 'number' && typeof color.saturation === 'number' && typeof color.lightness === 'number') {
  2708. if (color.alpha && typeof color.alpha === 'number') {
  2709. return hsla({
  2710. hue: color.hue,
  2711. saturation: color.saturation,
  2712. lightness: color.lightness,
  2713. alpha: color.alpha
  2714. });
  2715. }
  2716. return hsl({
  2717. hue: color.hue,
  2718. saturation: color.saturation,
  2719. lightness: color.lightness
  2720. });
  2721. }
  2722. throw new PolishedError(45);
  2723. }
  2724. /**
  2725. * Inverts the red, green and blue values of a color.
  2726. *
  2727. * @example
  2728. * // Styles as object usage
  2729. * const styles = {
  2730. * background: invert('#CCCD64'),
  2731. * background: invert('rgba(101,100,205,0.7)'),
  2732. * }
  2733. *
  2734. * // styled-components usage
  2735. * const div = styled.div`
  2736. * background: ${invert('#CCCD64')};
  2737. * background: ${invert('rgba(101,100,205,0.7)')};
  2738. * `
  2739. *
  2740. * // CSS in JS Output
  2741. *
  2742. * element {
  2743. * background: "#33329b";
  2744. * background: "rgba(154,155,50,0.7)";
  2745. * }
  2746. */
  2747. function invert(color) {
  2748. if (color === 'transparent') return color; // parse color string to rgb
  2749. var value = parseToRgb(color);
  2750. return toColorString(_extends__default['default']({}, value, {
  2751. red: 255 - value.red,
  2752. green: 255 - value.green,
  2753. blue: 255 - value.blue
  2754. }));
  2755. }
  2756. /**
  2757. * Returns a string value for the lightened color.
  2758. *
  2759. * @example
  2760. * // Styles as object usage
  2761. * const styles = {
  2762. * background: lighten(0.2, '#CCCD64'),
  2763. * background: lighten('0.2', 'rgba(204,205,100,0.7)'),
  2764. * }
  2765. *
  2766. * // styled-components usage
  2767. * const div = styled.div`
  2768. * background: ${lighten(0.2, '#FFCD64')};
  2769. * background: ${lighten('0.2', 'rgba(204,205,100,0.7)')};
  2770. * `
  2771. *
  2772. * // CSS in JS Output
  2773. *
  2774. * element {
  2775. * background: "#e5e6b1";
  2776. * background: "rgba(229,230,177,0.7)";
  2777. * }
  2778. */
  2779. function lighten(amount, color) {
  2780. if (color === 'transparent') return color;
  2781. var hslColor = parseToHsl(color);
  2782. return toColorString(_extends__default['default']({}, hslColor, {
  2783. lightness: guard(0, 1, hslColor.lightness + parseFloat(amount))
  2784. }));
  2785. } // prettier-ignore
  2786. var curriedLighten = /*#__PURE__*/curry
  2787. /* ::<number | string, string, string> */
  2788. (lighten);
  2789. /**
  2790. * Determines which contrast guidelines have been met for two colors.
  2791. * Based on the [contrast calculations recommended by W3](https://www.w3.org/WAI/WCAG21/Understanding/contrast-enhanced.html).
  2792. *
  2793. * @example
  2794. * const scores = meetsContrastGuidelines('#444', '#fff');
  2795. */
  2796. function meetsContrastGuidelines(color1, color2) {
  2797. var contrastRatio = getContrast(color1, color2);
  2798. return {
  2799. AA: contrastRatio >= 4.5,
  2800. AALarge: contrastRatio >= 3,
  2801. AAA: contrastRatio >= 7,
  2802. AAALarge: contrastRatio >= 4.5
  2803. };
  2804. }
  2805. /**
  2806. * Mixes the two provided colors together by calculating the average of each of the RGB components weighted to the first color by the provided weight.
  2807. *
  2808. * @example
  2809. * // Styles as object usage
  2810. * const styles = {
  2811. * background: mix(0.5, '#f00', '#00f')
  2812. * background: mix(0.25, '#f00', '#00f')
  2813. * background: mix('0.5', 'rgba(255, 0, 0, 0.5)', '#00f')
  2814. * }
  2815. *
  2816. * // styled-components usage
  2817. * const div = styled.div`
  2818. * background: ${mix(0.5, '#f00', '#00f')};
  2819. * background: ${mix(0.25, '#f00', '#00f')};
  2820. * background: ${mix('0.5', 'rgba(255, 0, 0, 0.5)', '#00f')};
  2821. * `
  2822. *
  2823. * // CSS in JS Output
  2824. *
  2825. * element {
  2826. * background: "#7f007f";
  2827. * background: "#3f00bf";
  2828. * background: "rgba(63, 0, 191, 0.75)";
  2829. * }
  2830. */
  2831. function mix(weight, color, otherColor) {
  2832. if (color === 'transparent') return otherColor;
  2833. if (otherColor === 'transparent') return color;
  2834. if (weight === 0) return otherColor;
  2835. var parsedColor1 = parseToRgb(color);
  2836. var color1 = _extends__default['default']({}, parsedColor1, {
  2837. alpha: typeof parsedColor1.alpha === 'number' ? parsedColor1.alpha : 1
  2838. });
  2839. var parsedColor2 = parseToRgb(otherColor);
  2840. var color2 = _extends__default['default']({}, parsedColor2, {
  2841. alpha: typeof parsedColor2.alpha === 'number' ? parsedColor2.alpha : 1
  2842. }); // The formula is copied from the original Sass implementation:
  2843. // http://sass-lang.com/documentation/Sass/Script/Functions.html#mix-instance_method
  2844. var alphaDelta = color1.alpha - color2.alpha;
  2845. var x = parseFloat(weight) * 2 - 1;
  2846. var y = x * alphaDelta === -1 ? x : x + alphaDelta;
  2847. var z = 1 + x * alphaDelta;
  2848. var weight1 = (y / z + 1) / 2.0;
  2849. var weight2 = 1 - weight1;
  2850. var mixedColor = {
  2851. red: Math.floor(color1.red * weight1 + color2.red * weight2),
  2852. green: Math.floor(color1.green * weight1 + color2.green * weight2),
  2853. blue: Math.floor(color1.blue * weight1 + color2.blue * weight2),
  2854. alpha: color1.alpha * (parseFloat(weight) / 1.0) + color2.alpha * (1 - parseFloat(weight) / 1.0)
  2855. };
  2856. return rgba(mixedColor);
  2857. } // prettier-ignore
  2858. var curriedMix = /*#__PURE__*/curry
  2859. /* ::<number | string, string, string, string> */
  2860. (mix);
  2861. /**
  2862. * Increases the opacity of a color. Its range for the amount is between 0 to 1.
  2863. *
  2864. *
  2865. * @example
  2866. * // Styles as object usage
  2867. * const styles = {
  2868. * background: opacify(0.1, 'rgba(255, 255, 255, 0.9)');
  2869. * background: opacify(0.2, 'hsla(0, 0%, 100%, 0.5)'),
  2870. * background: opacify('0.5', 'rgba(255, 0, 0, 0.2)'),
  2871. * }
  2872. *
  2873. * // styled-components usage
  2874. * const div = styled.div`
  2875. * background: ${opacify(0.1, 'rgba(255, 255, 255, 0.9)')};
  2876. * background: ${opacify(0.2, 'hsla(0, 0%, 100%, 0.5)')},
  2877. * background: ${opacify('0.5', 'rgba(255, 0, 0, 0.2)')},
  2878. * `
  2879. *
  2880. * // CSS in JS Output
  2881. *
  2882. * element {
  2883. * background: "#fff";
  2884. * background: "rgba(255,255,255,0.7)";
  2885. * background: "rgba(255,0,0,0.7)";
  2886. * }
  2887. */
  2888. function opacify(amount, color) {
  2889. if (color === 'transparent') return color;
  2890. var parsedColor = parseToRgb(color);
  2891. var alpha = typeof parsedColor.alpha === 'number' ? parsedColor.alpha : 1;
  2892. var colorWithAlpha = _extends__default['default']({}, parsedColor, {
  2893. alpha: guard(0, 1, (alpha * 100 + parseFloat(amount) * 100) / 100)
  2894. });
  2895. return rgba(colorWithAlpha);
  2896. } // prettier-ignore
  2897. var curriedOpacify = /*#__PURE__*/curry
  2898. /* ::<number | string, string, string> */
  2899. (opacify);
  2900. var defaultReturnIfLightColor = '#000';
  2901. var defaultReturnIfDarkColor = '#fff';
  2902. /**
  2903. * Returns black or white (or optional passed colors) for best
  2904. * contrast depending on the luminosity of the given color.
  2905. * When passing custom return colors, strict mode ensures that the
  2906. * return color always meets or exceeds WCAG level AA or greater. If this test
  2907. * fails, the default return color (black or white) is returned in place of the
  2908. * custom return color. You can optionally turn off strict mode.
  2909. *
  2910. * Follows [W3C specs for readability](https://www.w3.org/TR/WCAG20-TECHS/G18.html).
  2911. *
  2912. * @example
  2913. * // Styles as object usage
  2914. * const styles = {
  2915. * color: readableColor('#000'),
  2916. * color: readableColor('black', '#001', '#ff8'),
  2917. * color: readableColor('white', '#001', '#ff8'),
  2918. * color: readableColor('red', '#333', '#ddd', true)
  2919. * }
  2920. *
  2921. * // styled-components usage
  2922. * const div = styled.div`
  2923. * color: ${readableColor('#000')};
  2924. * color: ${readableColor('black', '#001', '#ff8')};
  2925. * color: ${readableColor('white', '#001', '#ff8')};
  2926. * color: ${readableColor('red', '#333', '#ddd', true)};
  2927. * `
  2928. *
  2929. * // CSS in JS Output
  2930. * element {
  2931. * color: "#fff";
  2932. * color: "#ff8";
  2933. * color: "#001";
  2934. * color: "#000";
  2935. * }
  2936. */
  2937. function readableColor(color, returnIfLightColor, returnIfDarkColor, strict) {
  2938. if (returnIfLightColor === void 0) {
  2939. returnIfLightColor = defaultReturnIfLightColor;
  2940. }
  2941. if (returnIfDarkColor === void 0) {
  2942. returnIfDarkColor = defaultReturnIfDarkColor;
  2943. }
  2944. if (strict === void 0) {
  2945. strict = true;
  2946. }
  2947. var isColorLight = getLuminance(color) > 0.179;
  2948. var preferredReturnColor = isColorLight ? returnIfLightColor : returnIfDarkColor;
  2949. if (!strict || getContrast(color, preferredReturnColor) >= 4.5) {
  2950. return preferredReturnColor;
  2951. }
  2952. return isColorLight ? defaultReturnIfLightColor : defaultReturnIfDarkColor;
  2953. }
  2954. /**
  2955. * Converts a RgbColor or RgbaColor object to a color string.
  2956. * This util is useful in case you only know on runtime which color object is
  2957. * used. Otherwise we recommend to rely on `rgb` or `rgba`.
  2958. *
  2959. * @example
  2960. * // Styles as object usage
  2961. * const styles = {
  2962. * background: rgbToColorString({ red: 255, green: 205, blue: 100 }),
  2963. * background: rgbToColorString({ red: 255, green: 205, blue: 100, alpha: 0.72 }),
  2964. * }
  2965. *
  2966. * // styled-components usage
  2967. * const div = styled.div`
  2968. * background: ${rgbToColorString({ red: 255, green: 205, blue: 100 })};
  2969. * background: ${rgbToColorString({ red: 255, green: 205, blue: 100, alpha: 0.72 })};
  2970. * `
  2971. *
  2972. * // CSS in JS Output
  2973. * element {
  2974. * background: "#ffcd64";
  2975. * background: "rgba(255,205,100,0.72)";
  2976. * }
  2977. */
  2978. function rgbToColorString(color) {
  2979. if (typeof color === 'object' && typeof color.red === 'number' && typeof color.green === 'number' && typeof color.blue === 'number') {
  2980. if (typeof color.alpha === 'number') {
  2981. return rgba({
  2982. red: color.red,
  2983. green: color.green,
  2984. blue: color.blue,
  2985. alpha: color.alpha
  2986. });
  2987. }
  2988. return rgb({
  2989. red: color.red,
  2990. green: color.green,
  2991. blue: color.blue
  2992. });
  2993. }
  2994. throw new PolishedError(46);
  2995. }
  2996. /**
  2997. * Increases the intensity of a color. Its range is between 0 to 1. The first
  2998. * argument of the saturate function is the amount by how much the color
  2999. * intensity should be increased.
  3000. *
  3001. * @example
  3002. * // Styles as object usage
  3003. * const styles = {
  3004. * background: saturate(0.2, '#CCCD64'),
  3005. * background: saturate('0.2', 'rgba(204,205,100,0.7)'),
  3006. * }
  3007. *
  3008. * // styled-components usage
  3009. * const div = styled.div`
  3010. * background: ${saturate(0.2, '#FFCD64')};
  3011. * background: ${saturate('0.2', 'rgba(204,205,100,0.7)')};
  3012. * `
  3013. *
  3014. * // CSS in JS Output
  3015. *
  3016. * element {
  3017. * background: "#e0e250";
  3018. * background: "rgba(224,226,80,0.7)";
  3019. * }
  3020. */
  3021. function saturate(amount, color) {
  3022. if (color === 'transparent') return color;
  3023. var hslColor = parseToHsl(color);
  3024. return toColorString(_extends__default['default']({}, hslColor, {
  3025. saturation: guard(0, 1, hslColor.saturation + parseFloat(amount))
  3026. }));
  3027. } // prettier-ignore
  3028. var curriedSaturate = /*#__PURE__*/curry
  3029. /* ::<number | string, string, string> */
  3030. (saturate);
  3031. /**
  3032. * Sets the hue of a color to the provided value. The hue range can be
  3033. * from 0 and 359.
  3034. *
  3035. * @example
  3036. * // Styles as object usage
  3037. * const styles = {
  3038. * background: setHue(42, '#CCCD64'),
  3039. * background: setHue('244', 'rgba(204,205,100,0.7)'),
  3040. * }
  3041. *
  3042. * // styled-components usage
  3043. * const div = styled.div`
  3044. * background: ${setHue(42, '#CCCD64')};
  3045. * background: ${setHue('244', 'rgba(204,205,100,0.7)')};
  3046. * `
  3047. *
  3048. * // CSS in JS Output
  3049. * element {
  3050. * background: "#cdae64";
  3051. * background: "rgba(107,100,205,0.7)";
  3052. * }
  3053. */
  3054. function setHue(hue, color) {
  3055. if (color === 'transparent') return color;
  3056. return toColorString(_extends__default['default']({}, parseToHsl(color), {
  3057. hue: parseFloat(hue)
  3058. }));
  3059. } // prettier-ignore
  3060. var curriedSetHue = /*#__PURE__*/curry
  3061. /* ::<number | string, string, string> */
  3062. (setHue);
  3063. /**
  3064. * Sets the lightness of a color to the provided value. The lightness range can be
  3065. * from 0 and 1.
  3066. *
  3067. * @example
  3068. * // Styles as object usage
  3069. * const styles = {
  3070. * background: setLightness(0.2, '#CCCD64'),
  3071. * background: setLightness('0.75', 'rgba(204,205,100,0.7)'),
  3072. * }
  3073. *
  3074. * // styled-components usage
  3075. * const div = styled.div`
  3076. * background: ${setLightness(0.2, '#CCCD64')};
  3077. * background: ${setLightness('0.75', 'rgba(204,205,100,0.7)')};
  3078. * `
  3079. *
  3080. * // CSS in JS Output
  3081. * element {
  3082. * background: "#4d4d19";
  3083. * background: "rgba(223,224,159,0.7)";
  3084. * }
  3085. */
  3086. function setLightness(lightness, color) {
  3087. if (color === 'transparent') return color;
  3088. return toColorString(_extends__default['default']({}, parseToHsl(color), {
  3089. lightness: parseFloat(lightness)
  3090. }));
  3091. } // prettier-ignore
  3092. var curriedSetLightness = /*#__PURE__*/curry
  3093. /* ::<number | string, string, string> */
  3094. (setLightness);
  3095. /**
  3096. * Sets the saturation of a color to the provided value. The saturation range can be
  3097. * from 0 and 1.
  3098. *
  3099. * @example
  3100. * // Styles as object usage
  3101. * const styles = {
  3102. * background: setSaturation(0.2, '#CCCD64'),
  3103. * background: setSaturation('0.75', 'rgba(204,205,100,0.7)'),
  3104. * }
  3105. *
  3106. * // styled-components usage
  3107. * const div = styled.div`
  3108. * background: ${setSaturation(0.2, '#CCCD64')};
  3109. * background: ${setSaturation('0.75', 'rgba(204,205,100,0.7)')};
  3110. * `
  3111. *
  3112. * // CSS in JS Output
  3113. * element {
  3114. * background: "#adad84";
  3115. * background: "rgba(228,229,76,0.7)";
  3116. * }
  3117. */
  3118. function setSaturation(saturation, color) {
  3119. if (color === 'transparent') return color;
  3120. return toColorString(_extends__default['default']({}, parseToHsl(color), {
  3121. saturation: parseFloat(saturation)
  3122. }));
  3123. } // prettier-ignore
  3124. var curriedSetSaturation = /*#__PURE__*/curry
  3125. /* ::<number | string, string, string> */
  3126. (setSaturation);
  3127. /**
  3128. * Shades a color by mixing it with black. `shade` can produce
  3129. * hue shifts, where as `darken` manipulates the luminance channel and therefore
  3130. * doesn't produce hue shifts.
  3131. *
  3132. * @example
  3133. * // Styles as object usage
  3134. * const styles = {
  3135. * background: shade(0.25, '#00f')
  3136. * }
  3137. *
  3138. * // styled-components usage
  3139. * const div = styled.div`
  3140. * background: ${shade(0.25, '#00f')};
  3141. * `
  3142. *
  3143. * // CSS in JS Output
  3144. *
  3145. * element {
  3146. * background: "#00003f";
  3147. * }
  3148. */
  3149. function shade(percentage, color) {
  3150. if (color === 'transparent') return color;
  3151. return curriedMix(parseFloat(percentage), 'rgb(0, 0, 0)', color);
  3152. } // prettier-ignore
  3153. var curriedShade = /*#__PURE__*/curry
  3154. /* ::<number | string, string, string> */
  3155. (shade);
  3156. /**
  3157. * Tints a color by mixing it with white. `tint` can produce
  3158. * hue shifts, where as `lighten` manipulates the luminance channel and therefore
  3159. * doesn't produce hue shifts.
  3160. *
  3161. * @example
  3162. * // Styles as object usage
  3163. * const styles = {
  3164. * background: tint(0.25, '#00f')
  3165. * }
  3166. *
  3167. * // styled-components usage
  3168. * const div = styled.div`
  3169. * background: ${tint(0.25, '#00f')};
  3170. * `
  3171. *
  3172. * // CSS in JS Output
  3173. *
  3174. * element {
  3175. * background: "#bfbfff";
  3176. * }
  3177. */
  3178. function tint(percentage, color) {
  3179. if (color === 'transparent') return color;
  3180. return curriedMix(parseFloat(percentage), 'rgb(255, 255, 255)', color);
  3181. } // prettier-ignore
  3182. var curriedTint = /*#__PURE__*/curry
  3183. /* ::<number | string, string, string> */
  3184. (tint);
  3185. /**
  3186. * Decreases the opacity of a color. Its range for the amount is between 0 to 1.
  3187. *
  3188. *
  3189. * @example
  3190. * // Styles as object usage
  3191. * const styles = {
  3192. * background: transparentize(0.1, '#fff');
  3193. * background: transparentize(0.2, 'hsl(0, 0%, 100%)'),
  3194. * background: transparentize('0.5', 'rgba(255, 0, 0, 0.8)'),
  3195. * }
  3196. *
  3197. * // styled-components usage
  3198. * const div = styled.div`
  3199. * background: ${transparentize(0.1, '#fff')};
  3200. * background: ${transparentize(0.2, 'hsl(0, 0%, 100%)')},
  3201. * background: ${transparentize('0.5', 'rgba(255, 0, 0, 0.8)')},
  3202. * `
  3203. *
  3204. * // CSS in JS Output
  3205. *
  3206. * element {
  3207. * background: "rgba(255,255,255,0.9)";
  3208. * background: "rgba(255,255,255,0.8)";
  3209. * background: "rgba(255,0,0,0.3)";
  3210. * }
  3211. */
  3212. function transparentize(amount, color) {
  3213. if (color === 'transparent') return color;
  3214. var parsedColor = parseToRgb(color);
  3215. var alpha = typeof parsedColor.alpha === 'number' ? parsedColor.alpha : 1;
  3216. var colorWithAlpha = _extends__default['default']({}, parsedColor, {
  3217. alpha: guard(0, 1, +(alpha * 100 - parseFloat(amount) * 100).toFixed(2) / 100)
  3218. });
  3219. return rgba(colorWithAlpha);
  3220. } // prettier-ignore
  3221. var curriedTransparentize = /*#__PURE__*/curry
  3222. /* ::<number | string, string, string> */
  3223. (transparentize);
  3224. /**
  3225. * Shorthand for easily setting the animation property. Allows either multiple arrays with animations
  3226. * or a single animation spread over the arguments.
  3227. * @example
  3228. * // Styles as object usage
  3229. * const styles = {
  3230. * ...animation(['rotate', '1s', 'ease-in-out'], ['colorchange', '2s'])
  3231. * }
  3232. *
  3233. * // styled-components usage
  3234. * const div = styled.div`
  3235. * ${animation(['rotate', '1s', 'ease-in-out'], ['colorchange', '2s'])}
  3236. * `
  3237. *
  3238. * // CSS as JS Output
  3239. *
  3240. * div {
  3241. * 'animation': 'rotate 1s ease-in-out, colorchange 2s'
  3242. * }
  3243. * @example
  3244. * // Styles as object usage
  3245. * const styles = {
  3246. * ...animation('rotate', '1s', 'ease-in-out')
  3247. * }
  3248. *
  3249. * // styled-components usage
  3250. * const div = styled.div`
  3251. * ${animation('rotate', '1s', 'ease-in-out')}
  3252. * `
  3253. *
  3254. * // CSS as JS Output
  3255. *
  3256. * div {
  3257. * 'animation': 'rotate 1s ease-in-out'
  3258. * }
  3259. */
  3260. function animation() {
  3261. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  3262. args[_key] = arguments[_key];
  3263. }
  3264. // Allow single or multiple animations passed
  3265. var multiMode = Array.isArray(args[0]);
  3266. if (!multiMode && args.length > 8) {
  3267. throw new PolishedError(64);
  3268. }
  3269. var code = args.map(function (arg) {
  3270. if (multiMode && !Array.isArray(arg) || !multiMode && Array.isArray(arg)) {
  3271. throw new PolishedError(65);
  3272. }
  3273. if (Array.isArray(arg) && arg.length > 8) {
  3274. throw new PolishedError(66);
  3275. }
  3276. return Array.isArray(arg) ? arg.join(' ') : arg;
  3277. }).join(', ');
  3278. return {
  3279. animation: code
  3280. };
  3281. }
  3282. /**
  3283. * Shorthand that accepts any number of backgroundImage values as parameters for creating a single background statement.
  3284. * @example
  3285. * // Styles as object usage
  3286. * const styles = {
  3287. * ...backgroundImages('url("/image/background.jpg")', 'linear-gradient(red, green)')
  3288. * }
  3289. *
  3290. * // styled-components usage
  3291. * const div = styled.div`
  3292. * ${backgroundImages('url("/image/background.jpg")', 'linear-gradient(red, green)')}
  3293. * `
  3294. *
  3295. * // CSS as JS Output
  3296. *
  3297. * div {
  3298. * 'backgroundImage': 'url("/image/background.jpg"), linear-gradient(red, green)'
  3299. * }
  3300. */
  3301. function backgroundImages() {
  3302. for (var _len = arguments.length, properties = new Array(_len), _key = 0; _key < _len; _key++) {
  3303. properties[_key] = arguments[_key];
  3304. }
  3305. return {
  3306. backgroundImage: properties.join(', ')
  3307. };
  3308. }
  3309. /**
  3310. * Shorthand that accepts any number of background values as parameters for creating a single background statement.
  3311. * @example
  3312. * // Styles as object usage
  3313. * const styles = {
  3314. * ...backgrounds('url("/image/background.jpg")', 'linear-gradient(red, green)', 'center no-repeat')
  3315. * }
  3316. *
  3317. * // styled-components usage
  3318. * const div = styled.div`
  3319. * ${backgrounds('url("/image/background.jpg")', 'linear-gradient(red, green)', 'center no-repeat')}
  3320. * `
  3321. *
  3322. * // CSS as JS Output
  3323. *
  3324. * div {
  3325. * 'background': 'url("/image/background.jpg"), linear-gradient(red, green), center no-repeat'
  3326. * }
  3327. */
  3328. function backgrounds() {
  3329. for (var _len = arguments.length, properties = new Array(_len), _key = 0; _key < _len; _key++) {
  3330. properties[_key] = arguments[_key];
  3331. }
  3332. return {
  3333. background: properties.join(', ')
  3334. };
  3335. }
  3336. var sideMap = ['top', 'right', 'bottom', 'left'];
  3337. /**
  3338. * Shorthand for the border property that splits out individual properties for use with tools like Fela and Styletron. A side keyword can optionally be passed to target only one side's border properties.
  3339. *
  3340. * @example
  3341. * // Styles as object usage
  3342. * const styles = {
  3343. * ...border('1px', 'solid', 'red')
  3344. * }
  3345. *
  3346. * // styled-components usage
  3347. * const div = styled.div`
  3348. * ${border('1px', 'solid', 'red')}
  3349. * `
  3350. *
  3351. * // CSS as JS Output
  3352. *
  3353. * div {
  3354. * 'borderColor': 'red',
  3355. * 'borderStyle': 'solid',
  3356. * 'borderWidth': `1px`,
  3357. * }
  3358. *
  3359. * // Styles as object usage
  3360. * const styles = {
  3361. * ...border('top', '1px', 'solid', 'red')
  3362. * }
  3363. *
  3364. * // styled-components usage
  3365. * const div = styled.div`
  3366. * ${border('top', '1px', 'solid', 'red')}
  3367. * `
  3368. *
  3369. * // CSS as JS Output
  3370. *
  3371. * div {
  3372. * 'borderTopColor': 'red',
  3373. * 'borderTopStyle': 'solid',
  3374. * 'borderTopWidth': `1px`,
  3375. * }
  3376. */
  3377. function border(sideKeyword) {
  3378. for (var _len = arguments.length, values = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  3379. values[_key - 1] = arguments[_key];
  3380. }
  3381. if (typeof sideKeyword === 'string' && sideMap.indexOf(sideKeyword) >= 0) {
  3382. var _ref;
  3383. return _ref = {}, _ref["border" + capitalizeString(sideKeyword) + "Width"] = values[0], _ref["border" + capitalizeString(sideKeyword) + "Style"] = values[1], _ref["border" + capitalizeString(sideKeyword) + "Color"] = values[2], _ref;
  3384. } else {
  3385. values.unshift(sideKeyword);
  3386. return {
  3387. borderWidth: values[0],
  3388. borderStyle: values[1],
  3389. borderColor: values[2]
  3390. };
  3391. }
  3392. }
  3393. /**
  3394. * Shorthand that accepts up to four values, including null to skip a value, and maps them to their respective directions.
  3395. * @example
  3396. * // Styles as object usage
  3397. * const styles = {
  3398. * ...borderColor('red', 'green', 'blue', 'yellow')
  3399. * }
  3400. *
  3401. * // styled-components usage
  3402. * const div = styled.div`
  3403. * ${borderColor('red', 'green', 'blue', 'yellow')}
  3404. * `
  3405. *
  3406. * // CSS as JS Output
  3407. *
  3408. * div {
  3409. * 'borderTopColor': 'red',
  3410. * 'borderRightColor': 'green',
  3411. * 'borderBottomColor': 'blue',
  3412. * 'borderLeftColor': 'yellow'
  3413. * }
  3414. */
  3415. function borderColor() {
  3416. for (var _len = arguments.length, values = new Array(_len), _key = 0; _key < _len; _key++) {
  3417. values[_key] = arguments[_key];
  3418. }
  3419. return directionalProperty.apply(void 0, ['borderColor'].concat(values));
  3420. }
  3421. /**
  3422. * Shorthand that accepts a value for side and a value for radius and applies the radius value to both corners of the side.
  3423. * @example
  3424. * // Styles as object usage
  3425. * const styles = {
  3426. * ...borderRadius('top', '5px')
  3427. * }
  3428. *
  3429. * // styled-components usage
  3430. * const div = styled.div`
  3431. * ${borderRadius('top', '5px')}
  3432. * `
  3433. *
  3434. * // CSS as JS Output
  3435. *
  3436. * div {
  3437. * 'borderTopRightRadius': '5px',
  3438. * 'borderTopLeftRadius': '5px',
  3439. * }
  3440. */
  3441. function borderRadius(side, radius) {
  3442. var uppercaseSide = capitalizeString(side);
  3443. if (!radius && radius !== 0) {
  3444. throw new PolishedError(62);
  3445. }
  3446. if (uppercaseSide === 'Top' || uppercaseSide === 'Bottom') {
  3447. var _ref;
  3448. return _ref = {}, _ref["border" + uppercaseSide + "RightRadius"] = radius, _ref["border" + uppercaseSide + "LeftRadius"] = radius, _ref;
  3449. }
  3450. if (uppercaseSide === 'Left' || uppercaseSide === 'Right') {
  3451. var _ref2;
  3452. return _ref2 = {}, _ref2["borderTop" + uppercaseSide + "Radius"] = radius, _ref2["borderBottom" + uppercaseSide + "Radius"] = radius, _ref2;
  3453. }
  3454. throw new PolishedError(63);
  3455. }
  3456. /**
  3457. * Shorthand that accepts up to four values, including null to skip a value, and maps them to their respective directions.
  3458. * @example
  3459. * // Styles as object usage
  3460. * const styles = {
  3461. * ...borderStyle('solid', 'dashed', 'dotted', 'double')
  3462. * }
  3463. *
  3464. * // styled-components usage
  3465. * const div = styled.div`
  3466. * ${borderStyle('solid', 'dashed', 'dotted', 'double')}
  3467. * `
  3468. *
  3469. * // CSS as JS Output
  3470. *
  3471. * div {
  3472. * 'borderTopStyle': 'solid',
  3473. * 'borderRightStyle': 'dashed',
  3474. * 'borderBottomStyle': 'dotted',
  3475. * 'borderLeftStyle': 'double'
  3476. * }
  3477. */
  3478. function borderStyle() {
  3479. for (var _len = arguments.length, values = new Array(_len), _key = 0; _key < _len; _key++) {
  3480. values[_key] = arguments[_key];
  3481. }
  3482. return directionalProperty.apply(void 0, ['borderStyle'].concat(values));
  3483. }
  3484. /**
  3485. * Shorthand that accepts up to four values, including null to skip a value, and maps them to their respective directions.
  3486. * @example
  3487. * // Styles as object usage
  3488. * const styles = {
  3489. * ...borderWidth('12px', '24px', '36px', '48px')
  3490. * }
  3491. *
  3492. * // styled-components usage
  3493. * const div = styled.div`
  3494. * ${borderWidth('12px', '24px', '36px', '48px')}
  3495. * `
  3496. *
  3497. * // CSS as JS Output
  3498. *
  3499. * div {
  3500. * 'borderTopWidth': '12px',
  3501. * 'borderRightWidth': '24px',
  3502. * 'borderBottomWidth': '36px',
  3503. * 'borderLeftWidth': '48px'
  3504. * }
  3505. */
  3506. function borderWidth() {
  3507. for (var _len = arguments.length, values = new Array(_len), _key = 0; _key < _len; _key++) {
  3508. values[_key] = arguments[_key];
  3509. }
  3510. return directionalProperty.apply(void 0, ['borderWidth'].concat(values));
  3511. }
  3512. function generateSelectors(template, state) {
  3513. var stateSuffix = state ? ":" + state : '';
  3514. return template(stateSuffix);
  3515. }
  3516. /**
  3517. * Function helper that adds an array of states to a template of selectors. Used in textInputs and buttons.
  3518. * @private
  3519. */
  3520. function statefulSelectors(states, template, stateMap) {
  3521. if (!template) throw new PolishedError(67);
  3522. if (states.length === 0) return generateSelectors(template, null);
  3523. var selectors = [];
  3524. for (var i = 0; i < states.length; i += 1) {
  3525. if (stateMap && stateMap.indexOf(states[i]) < 0) {
  3526. throw new PolishedError(68);
  3527. }
  3528. selectors.push(generateSelectors(template, states[i]));
  3529. }
  3530. selectors = selectors.join(',');
  3531. return selectors;
  3532. }
  3533. var stateMap$1 = [undefined, null, 'active', 'focus', 'hover'];
  3534. function template$1(state) {
  3535. return "button" + state + ",\n input[type=\"button\"]" + state + ",\n input[type=\"reset\"]" + state + ",\n input[type=\"submit\"]" + state;
  3536. }
  3537. /**
  3538. * Populates selectors that target all buttons. You can pass optional states to append to the selectors.
  3539. * @example
  3540. * // Styles as object usage
  3541. * const styles = {
  3542. * [buttons('active')]: {
  3543. * 'border': 'none'
  3544. * }
  3545. * }
  3546. *
  3547. * // styled-components usage
  3548. * const div = styled.div`
  3549. * > ${buttons('active')} {
  3550. * border: none;
  3551. * }
  3552. * `
  3553. *
  3554. * // CSS in JS Output
  3555. *
  3556. * 'button:active,
  3557. * 'input[type="button"]:active,
  3558. * 'input[type=\"reset\"]:active,
  3559. * 'input[type=\"submit\"]:active: {
  3560. * 'border': 'none'
  3561. * }
  3562. */
  3563. function buttons() {
  3564. for (var _len = arguments.length, states = new Array(_len), _key = 0; _key < _len; _key++) {
  3565. states[_key] = arguments[_key];
  3566. }
  3567. return statefulSelectors(states, template$1, stateMap$1);
  3568. }
  3569. /**
  3570. * Shorthand that accepts up to four values, including null to skip a value, and maps them to their respective directions.
  3571. * @example
  3572. * // Styles as object usage
  3573. * const styles = {
  3574. * ...margin('12px', '24px', '36px', '48px')
  3575. * }
  3576. *
  3577. * // styled-components usage
  3578. * const div = styled.div`
  3579. * ${margin('12px', '24px', '36px', '48px')}
  3580. * `
  3581. *
  3582. * // CSS as JS Output
  3583. *
  3584. * div {
  3585. * 'marginTop': '12px',
  3586. * 'marginRight': '24px',
  3587. * 'marginBottom': '36px',
  3588. * 'marginLeft': '48px'
  3589. * }
  3590. */
  3591. function margin() {
  3592. for (var _len = arguments.length, values = new Array(_len), _key = 0; _key < _len; _key++) {
  3593. values[_key] = arguments[_key];
  3594. }
  3595. return directionalProperty.apply(void 0, ['margin'].concat(values));
  3596. }
  3597. /**
  3598. * Shorthand that accepts up to four values, including null to skip a value, and maps them to their respective directions.
  3599. * @example
  3600. * // Styles as object usage
  3601. * const styles = {
  3602. * ...padding('12px', '24px', '36px', '48px')
  3603. * }
  3604. *
  3605. * // styled-components usage
  3606. * const div = styled.div`
  3607. * ${padding('12px', '24px', '36px', '48px')}
  3608. * `
  3609. *
  3610. * // CSS as JS Output
  3611. *
  3612. * div {
  3613. * 'paddingTop': '12px',
  3614. * 'paddingRight': '24px',
  3615. * 'paddingBottom': '36px',
  3616. * 'paddingLeft': '48px'
  3617. * }
  3618. */
  3619. function padding() {
  3620. for (var _len = arguments.length, values = new Array(_len), _key = 0; _key < _len; _key++) {
  3621. values[_key] = arguments[_key];
  3622. }
  3623. return directionalProperty.apply(void 0, ['padding'].concat(values));
  3624. }
  3625. var positionMap = ['absolute', 'fixed', 'relative', 'static', 'sticky'];
  3626. /**
  3627. * Shorthand accepts up to five values, including null to skip a value, and maps them to their respective directions. The first value can optionally be a position keyword.
  3628. * @example
  3629. * // Styles as object usage
  3630. * const styles = {
  3631. * ...position('12px', '24px', '36px', '48px')
  3632. * }
  3633. *
  3634. * // styled-components usage
  3635. * const div = styled.div`
  3636. * ${position('12px', '24px', '36px', '48px')}
  3637. * `
  3638. *
  3639. * // CSS as JS Output
  3640. *
  3641. * div {
  3642. * 'top': '12px',
  3643. * 'right': '24px',
  3644. * 'bottom': '36px',
  3645. * 'left': '48px'
  3646. * }
  3647. *
  3648. * // Styles as object usage
  3649. * const styles = {
  3650. * ...position('absolute', '12px', '24px', '36px', '48px')
  3651. * }
  3652. *
  3653. * // styled-components usage
  3654. * const div = styled.div`
  3655. * ${position('absolute', '12px', '24px', '36px', '48px')}
  3656. * `
  3657. *
  3658. * // CSS as JS Output
  3659. *
  3660. * div {
  3661. * 'position': 'absolute',
  3662. * 'top': '12px',
  3663. * 'right': '24px',
  3664. * 'bottom': '36px',
  3665. * 'left': '48px'
  3666. * }
  3667. */
  3668. function position(firstValue) {
  3669. for (var _len = arguments.length, values = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  3670. values[_key - 1] = arguments[_key];
  3671. }
  3672. if (positionMap.indexOf(firstValue) >= 0 && firstValue) {
  3673. return _extends__default['default']({}, directionalProperty.apply(void 0, [''].concat(values)), {
  3674. position: firstValue
  3675. });
  3676. } else {
  3677. return directionalProperty.apply(void 0, ['', firstValue].concat(values));
  3678. }
  3679. }
  3680. /**
  3681. * Shorthand to set the height and width properties in a single statement.
  3682. * @example
  3683. * // Styles as object usage
  3684. * const styles = {
  3685. * ...size('300px', '250px')
  3686. * }
  3687. *
  3688. * // styled-components usage
  3689. * const div = styled.div`
  3690. * ${size('300px', '250px')}
  3691. * `
  3692. *
  3693. * // CSS as JS Output
  3694. *
  3695. * div {
  3696. * 'height': '300px',
  3697. * 'width': '250px',
  3698. * }
  3699. */
  3700. function size(height, width) {
  3701. if (width === void 0) {
  3702. width = height;
  3703. }
  3704. return {
  3705. height: height,
  3706. width: width
  3707. };
  3708. }
  3709. var stateMap = [undefined, null, 'active', 'focus', 'hover'];
  3710. function template(state) {
  3711. return "input[type=\"color\"]" + state + ",\n input[type=\"date\"]" + state + ",\n input[type=\"datetime\"]" + state + ",\n input[type=\"datetime-local\"]" + state + ",\n input[type=\"email\"]" + state + ",\n input[type=\"month\"]" + state + ",\n input[type=\"number\"]" + state + ",\n input[type=\"password\"]" + state + ",\n input[type=\"search\"]" + state + ",\n input[type=\"tel\"]" + state + ",\n input[type=\"text\"]" + state + ",\n input[type=\"time\"]" + state + ",\n input[type=\"url\"]" + state + ",\n input[type=\"week\"]" + state + ",\n input:not([type])" + state + ",\n textarea" + state;
  3712. }
  3713. /**
  3714. * Populates selectors that target all text inputs. You can pass optional states to append to the selectors.
  3715. * @example
  3716. * // Styles as object usage
  3717. * const styles = {
  3718. * [textInputs('active')]: {
  3719. * 'border': 'none'
  3720. * }
  3721. * }
  3722. *
  3723. * // styled-components usage
  3724. * const div = styled.div`
  3725. * > ${textInputs('active')} {
  3726. * border: none;
  3727. * }
  3728. * `
  3729. *
  3730. * // CSS in JS Output
  3731. *
  3732. * 'input[type="color"]:active,
  3733. * input[type="date"]:active,
  3734. * input[type="datetime"]:active,
  3735. * input[type="datetime-local"]:active,
  3736. * input[type="email"]:active,
  3737. * input[type="month"]:active,
  3738. * input[type="number"]:active,
  3739. * input[type="password"]:active,
  3740. * input[type="search"]:active,
  3741. * input[type="tel"]:active,
  3742. * input[type="text"]:active,
  3743. * input[type="time"]:active,
  3744. * input[type="url"]:active,
  3745. * input[type="week"]:active,
  3746. * input:not([type]):active,
  3747. * textarea:active': {
  3748. * 'border': 'none'
  3749. * }
  3750. */
  3751. function textInputs() {
  3752. for (var _len = arguments.length, states = new Array(_len), _key = 0; _key < _len; _key++) {
  3753. states[_key] = arguments[_key];
  3754. }
  3755. return statefulSelectors(states, template, stateMap);
  3756. }
  3757. /**
  3758. * Accepts any number of transition values as parameters for creating a single transition statement. You may also pass an array of properties as the first parameter that you would like to apply the same transition values to (second parameter).
  3759. * @example
  3760. * // Styles as object usage
  3761. * const styles = {
  3762. * ...transitions('opacity 1.0s ease-in 0s', 'width 2.0s ease-in 2s'),
  3763. * ...transitions(['color', 'background-color'], '2.0s ease-in 2s')
  3764. * }
  3765. *
  3766. * // styled-components usage
  3767. * const div = styled.div`
  3768. * ${transitions('opacity 1.0s ease-in 0s', 'width 2.0s ease-in 2s')};
  3769. * ${transitions(['color', 'background-color'], '2.0s ease-in 2s'),};
  3770. * `
  3771. *
  3772. * // CSS as JS Output
  3773. *
  3774. * div {
  3775. * 'transition': 'opacity 1.0s ease-in 0s, width 2.0s ease-in 2s'
  3776. * 'transition': 'color 2.0s ease-in 2s, background-color 2.0s ease-in 2s',
  3777. * }
  3778. */
  3779. function transitions() {
  3780. for (var _len = arguments.length, properties = new Array(_len), _key = 0; _key < _len; _key++) {
  3781. properties[_key] = arguments[_key];
  3782. }
  3783. if (Array.isArray(properties[0]) && properties.length === 2) {
  3784. var value = properties[1];
  3785. if (typeof value !== 'string') {
  3786. throw new PolishedError(61);
  3787. }
  3788. var transitionsString = properties[0].map(function (property) {
  3789. return property + " " + value;
  3790. }).join(', ');
  3791. return {
  3792. transition: transitionsString
  3793. };
  3794. } else {
  3795. return {
  3796. transition: properties.join(', ')
  3797. };
  3798. }
  3799. }
  3800. exports.adjustHue = curriedAdjustHue;
  3801. exports.animation = animation;
  3802. exports.backgroundImages = backgroundImages;
  3803. exports.backgrounds = backgrounds;
  3804. exports.between = between;
  3805. exports.border = border;
  3806. exports.borderColor = borderColor;
  3807. exports.borderRadius = borderRadius;
  3808. exports.borderStyle = borderStyle;
  3809. exports.borderWidth = borderWidth;
  3810. exports.buttons = buttons;
  3811. exports.clearFix = clearFix;
  3812. exports.complement = complement;
  3813. exports.cover = cover;
  3814. exports.cssVar = cssVar;
  3815. exports.darken = curriedDarken;
  3816. exports.desaturate = curriedDesaturate;
  3817. exports.directionalProperty = directionalProperty;
  3818. exports.easeIn = easeIn;
  3819. exports.easeInOut = easeInOut;
  3820. exports.easeOut = easeOut;
  3821. exports.ellipsis = ellipsis;
  3822. exports.em = em;
  3823. exports.fluidRange = fluidRange;
  3824. exports.fontFace = fontFace;
  3825. exports.getContrast = getContrast;
  3826. exports.getLuminance = getLuminance;
  3827. exports.getValueAndUnit = getValueAndUnit;
  3828. exports.grayscale = grayscale;
  3829. exports.hiDPI = hiDPI;
  3830. exports.hideText = hideText;
  3831. exports.hideVisually = hideVisually;
  3832. exports.hsl = hsl;
  3833. exports.hslToColorString = hslToColorString;
  3834. exports.hsla = hsla;
  3835. exports.important = important;
  3836. exports.invert = invert;
  3837. exports.lighten = curriedLighten;
  3838. exports.linearGradient = linearGradient;
  3839. exports.margin = margin;
  3840. exports.math = math;
  3841. exports.meetsContrastGuidelines = meetsContrastGuidelines;
  3842. exports.mix = curriedMix;
  3843. exports.modularScale = modularScale;
  3844. exports.normalize = normalize;
  3845. exports.opacify = curriedOpacify;
  3846. exports.padding = padding;
  3847. exports.parseToHsl = parseToHsl;
  3848. exports.parseToRgb = parseToRgb;
  3849. exports.position = position;
  3850. exports.radialGradient = radialGradient;
  3851. exports.readableColor = readableColor;
  3852. exports.rem = rem;
  3853. exports.remToPx = remToPx;
  3854. exports.retinaImage = retinaImage;
  3855. exports.rgb = rgb;
  3856. exports.rgbToColorString = rgbToColorString;
  3857. exports.rgba = rgba;
  3858. exports.saturate = curriedSaturate;
  3859. exports.setHue = curriedSetHue;
  3860. exports.setLightness = curriedSetLightness;
  3861. exports.setSaturation = curriedSetSaturation;
  3862. exports.shade = curriedShade;
  3863. exports.size = size;
  3864. exports.stripUnit = stripUnit;
  3865. exports.textInputs = textInputs;
  3866. exports.timingFunctions = timingFunctions;
  3867. exports.tint = curriedTint;
  3868. exports.toColorString = toColorString;
  3869. exports.transitions = transitions;
  3870. exports.transparentize = curriedTransparentize;
  3871. exports.triangle = triangle;
  3872. exports.wordWrap = wordWrap;