index.cjs.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749
  1. 'use strict';
  2. function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
  3. var postcss = _interopDefault(require('postcss'));
  4. var cloneRule = ((decl, dir) => {
  5. const rule = Object(decl.parent).type === 'rule' ? decl.parent.clone({
  6. raws: {}
  7. }).removeAll() : postcss.rule({
  8. selector: '&'
  9. });
  10. rule.selectors = rule.selectors.map(selector => `${selector}:dir(${dir})`);
  11. return rule;
  12. });
  13. const matchLogical = /^\s*logical\s+/i;
  14. const matchLogicalBorder = /^border(-width|-style|-color)?$/i;
  15. const matchLogicalBorderSide = /^border-(block|block-start|block-end|inline|inline-start|inline-end|start|end)(-(width|style|color))?$/i;
  16. var transformBorder = {
  17. // border
  18. 'border': (decl, values, dir) => {
  19. const isLogical = matchLogical.test(values[0]);
  20. if (isLogical) {
  21. values[0] = values[0].replace(matchLogical, '');
  22. }
  23. const ltrDecls = [decl.clone({
  24. prop: `border-top${decl.prop.replace(matchLogicalBorder, '$1')}`,
  25. value: values[0]
  26. }), decl.clone({
  27. prop: `border-left${decl.prop.replace(matchLogicalBorder, '$1')}`,
  28. value: values[1] || values[0]
  29. }), decl.clone({
  30. prop: `border-bottom${decl.prop.replace(matchLogicalBorder, '$1')}`,
  31. value: values[2] || values[0]
  32. }), decl.clone({
  33. prop: `border-right${decl.prop.replace(matchLogicalBorder, '$1')}`,
  34. value: values[3] || values[1] || values[0]
  35. })];
  36. const rtlDecls = [decl.clone({
  37. prop: `border-top${decl.prop.replace(matchLogicalBorder, '$1')}`,
  38. value: values[0]
  39. }), decl.clone({
  40. prop: `border-right${decl.prop.replace(matchLogicalBorder, '$1')}`,
  41. value: values[1] || values[0]
  42. }), decl.clone({
  43. prop: `border-bottom${decl.prop.replace(matchLogicalBorder, '$1')}`,
  44. value: values[2] || values[0]
  45. }), decl.clone({
  46. prop: `border-left${decl.prop.replace(matchLogicalBorder, '$1')}`,
  47. value: values[3] || values[1] || values[0]
  48. })];
  49. return isLogical ? 1 === values.length ? decl.clone({
  50. value: decl.value.replace(matchLogical, '')
  51. }) : !values[3] || values[3] === values[1] ? [decl.clone({
  52. prop: `border-top${decl.prop.replace(matchLogicalBorder, '$1')}`,
  53. value: values[0]
  54. }), decl.clone({
  55. prop: `border-right${decl.prop.replace(matchLogicalBorder, '$1')}`,
  56. value: values[3] || values[1] || values[0]
  57. }), decl.clone({
  58. prop: `border-bottom${decl.prop.replace(matchLogicalBorder, '$1')}`,
  59. value: values[2] || values[0]
  60. }), decl.clone({
  61. prop: `border-left${decl.prop.replace(matchLogicalBorder, '$1')}`,
  62. value: values[1] || values[0]
  63. })] : 'ltr' === dir ? ltrDecls : 'rtl' === dir ? rtlDecls : [cloneRule(decl, 'ltr').append(ltrDecls), cloneRule(decl, 'rtl').append(rtlDecls)] : null;
  64. },
  65. // border-block
  66. 'border-block': (decl, values) => [decl.clone({
  67. prop: `border-top${decl.prop.replace(matchLogicalBorderSide, '$2')}`,
  68. value: values[0]
  69. }), decl.clone({
  70. prop: `border-bottom${decl.prop.replace(matchLogicalBorderSide, '$2')}`,
  71. value: values[0]
  72. })],
  73. // border-block-start
  74. 'border-block-start': decl => {
  75. decl.prop = 'border-top';
  76. },
  77. // border-block-end
  78. 'border-block-end': decl => {
  79. decl.prop = 'border-bottom';
  80. },
  81. // border-inline
  82. 'border-inline': (decl, values, dir) => {
  83. const ltrDecls = [decl.clone({
  84. prop: `border-left${decl.prop.replace(matchLogicalBorderSide, '$2')}`,
  85. value: values[0]
  86. }), decl.clone({
  87. prop: `border-right${decl.prop.replace(matchLogicalBorderSide, '$2')}`,
  88. value: values[1] || values[0]
  89. })];
  90. const rtlDecls = [decl.clone({
  91. prop: `border-right${decl.prop.replace(matchLogicalBorderSide, '$2')}`,
  92. value: values[0]
  93. }), decl.clone({
  94. prop: `border-left${decl.prop.replace(matchLogicalBorderSide, '$2')}`,
  95. value: values[1] || values[0]
  96. })];
  97. const isLTR = 1 === values.length || 2 === values.length && values[0] === values[1];
  98. return isLTR ? ltrDecls : 'ltr' === dir ? ltrDecls : 'rtl' === dir ? rtlDecls : [cloneRule(decl, 'ltr').append(ltrDecls), cloneRule(decl, 'rtl').append(rtlDecls)];
  99. },
  100. // border-inline-start
  101. 'border-inline-start': (decl, values, dir) => {
  102. const ltrDecl = decl.clone({
  103. prop: `border-left${decl.prop.replace(matchLogicalBorderSide, '$2')}`
  104. });
  105. const rtlDecl = decl.clone({
  106. prop: `border-right${decl.prop.replace(matchLogicalBorderSide, '$2')}`
  107. });
  108. return 'ltr' === dir ? ltrDecl : 'rtl' === dir ? rtlDecl : [cloneRule(decl, 'ltr').append(ltrDecl), cloneRule(decl, 'rtl').append(rtlDecl)];
  109. },
  110. // border-inline-end
  111. 'border-inline-end': (decl, values, dir) => {
  112. const ltrDecl = decl.clone({
  113. prop: `border-right${decl.prop.replace(matchLogicalBorderSide, '$2')}`
  114. });
  115. const rtlDecl = decl.clone({
  116. prop: `border-left${decl.prop.replace(matchLogicalBorderSide, '$2')}`
  117. });
  118. return 'ltr' === dir ? ltrDecl : 'rtl' === dir ? rtlDecl : [cloneRule(decl, 'ltr').append(ltrDecl), cloneRule(decl, 'rtl').append(rtlDecl)];
  119. },
  120. // border-start
  121. 'border-start': (decl, values, dir) => {
  122. const ltrDecls = [decl.clone({
  123. prop: `border-top${decl.prop.replace(matchLogicalBorderSide, '$2')}`,
  124. value: values[0]
  125. }), decl.clone({
  126. prop: `border-left${decl.prop.replace(matchLogicalBorderSide, '$2')}`,
  127. value: values[1] || values[0]
  128. })];
  129. const rtlDecls = [decl.clone({
  130. prop: `border-top${decl.prop.replace(matchLogicalBorderSide, '$2')}`,
  131. value: values[0]
  132. }), decl.clone({
  133. prop: `border-right${decl.prop.replace(matchLogicalBorderSide, '$2')}`,
  134. value: values[1] || values[0]
  135. })];
  136. return 'ltr' === dir ? ltrDecls : 'rtl' === dir ? rtlDecls : [cloneRule(decl, 'ltr').append(ltrDecls), cloneRule(decl, 'rtl').append(rtlDecls)];
  137. },
  138. // border-end
  139. 'border-end': (decl, values, dir) => {
  140. const ltrDecls = [decl.clone({
  141. prop: `border-bottom${decl.prop.replace(matchLogicalBorderSide, '$2')}`,
  142. value: values[0]
  143. }), decl.clone({
  144. prop: `border-right${decl.prop.replace(matchLogicalBorderSide, '$2')}`,
  145. value: values[1] || values[0]
  146. })];
  147. const rtlDecls = [decl.clone({
  148. prop: `border-bottom${decl.prop.replace(matchLogicalBorderSide, '$2')}`,
  149. value: values[0]
  150. }), decl.clone({
  151. prop: `border-left${decl.prop.replace(matchLogicalBorderSide, '$2')}`,
  152. value: values[1] || values[0]
  153. })];
  154. return 'ltr' === dir ? ltrDecls : 'rtl' === dir ? rtlDecls : [cloneRule(decl, 'ltr').append(ltrDecls), cloneRule(decl, 'rtl').append(rtlDecls)];
  155. }
  156. };
  157. var transformFloat = ((decl, values, dir) => {
  158. const lDecl = decl.clone({
  159. value: 'left'
  160. });
  161. const rDecl = decl.clone({
  162. value: 'right'
  163. });
  164. return /^inline-start$/i.test(decl.value) ? 'ltr' === dir ? lDecl : 'rtl' === dir ? rDecl : [cloneRule(decl, 'ltr').append(lDecl), cloneRule(decl, 'rtl').append(rDecl)] : /^inline-end$/i.test(decl.value) ? 'ltr' === dir ? rDecl : 'rtl' === dir ? lDecl : [cloneRule(decl, 'ltr').append(rDecl), cloneRule(decl, 'rtl').append(lDecl)] : null;
  165. });
  166. var transformInset = ((decl, values, dir) => {
  167. if ('logical' !== values[0]) {
  168. return [decl.clone({
  169. prop: 'top',
  170. value: values[0]
  171. }), decl.clone({
  172. prop: 'right',
  173. value: values[1] || values[0]
  174. }), decl.clone({
  175. prop: 'bottom',
  176. value: values[2] || values[0]
  177. }), decl.clone({
  178. prop: 'left',
  179. value: values[3] || values[1] || values[0]
  180. })];
  181. }
  182. const isLTR = !values[4] || values[4] === values[2];
  183. const ltrDecls = [decl.clone({
  184. prop: 'top',
  185. value: values[1]
  186. }), decl.clone({
  187. prop: 'left',
  188. value: values[2] || values[1]
  189. }), decl.clone({
  190. prop: 'bottom',
  191. value: values[3] || values[1]
  192. }), decl.clone({
  193. prop: 'right',
  194. value: values[4] || values[2] || values[1]
  195. })];
  196. const rtlDecls = [decl.clone({
  197. prop: 'top',
  198. value: values[1]
  199. }), decl.clone({
  200. prop: 'right',
  201. value: values[2] || values[1]
  202. }), decl.clone({
  203. prop: 'bottom',
  204. value: values[3] || values[1]
  205. }), decl.clone({
  206. prop: 'left',
  207. value: values[4] || values[2] || values[1]
  208. })];
  209. return isLTR || 'ltr' === dir ? ltrDecls : 'rtl' === dir ? rtlDecls : [cloneRule(decl, 'ltr').append(ltrDecls), cloneRule(decl, 'rtl').append(rtlDecls)];
  210. });
  211. var transformResize = (decl => /^block$/i.test(decl.value) ? decl.clone({
  212. value: 'vertical'
  213. }) : /^inline$/i.test(decl.value) ? decl.clone({
  214. value: 'horizontal'
  215. }) : null);
  216. var matchSide = /^(inset|margin|padding)(?:-(block|block-start|block-end|inline|inline-start|inline-end|start|end))$/i;
  217. var matchInsetPrefix = /^inset-/i;
  218. var cloneDecl = ((decl, suffix, value) => decl.clone({
  219. prop: `${decl.prop.replace(matchSide, '$1')}${suffix}`.replace(matchInsetPrefix, ''),
  220. value
  221. }));
  222. var transformSide = {
  223. // inset-block, margin-block, padding-block
  224. 'block': (decl, values) => [cloneDecl(decl, '-top', values[0]), cloneDecl(decl, '-bottom', values[1] || values[0])],
  225. // inset-block-start, margin-block-start, padding-block-start
  226. 'block-start': decl => {
  227. decl.prop = decl.prop.replace(matchSide, '$1-top').replace(matchInsetPrefix, '');
  228. },
  229. // inset-block-end, margin-block-end, padding-block-end
  230. 'block-end': decl => {
  231. decl.prop = decl.prop.replace(matchSide, '$1-bottom').replace(matchInsetPrefix, '');
  232. },
  233. // inset-inline, margin-inline, padding-inline
  234. 'inline': (decl, values, dir) => {
  235. const ltrDecls = [cloneDecl(decl, '-left', values[0]), cloneDecl(decl, '-right', values[1] || values[0])];
  236. const rtlDecls = [cloneDecl(decl, '-right', values[0]), cloneDecl(decl, '-left', values[1] || values[0])];
  237. const isLTR = 1 === values.length || 2 === values.length && values[0] === values[1];
  238. return isLTR ? ltrDecls : 'ltr' === dir ? ltrDecls : 'rtl' === dir ? rtlDecls : [cloneRule(decl, 'ltr').append(ltrDecls), cloneRule(decl, 'rtl').append(rtlDecls)];
  239. },
  240. // inset-inline-start, margin-inline-start, padding-inline-start
  241. 'inline-start': (decl, values, dir) => {
  242. const ltrDecl = cloneDecl(decl, '-left', decl.value);
  243. const rtlDecl = cloneDecl(decl, '-right', decl.value);
  244. return 'ltr' === dir ? ltrDecl : 'rtl' === dir ? rtlDecl : [cloneRule(decl, 'ltr').append(ltrDecl), cloneRule(decl, 'rtl').append(rtlDecl)];
  245. },
  246. // inset-inline-end, margin-inline-end, padding-inline-end
  247. 'inline-end': (decl, values, dir) => {
  248. const ltrDecl = cloneDecl(decl, '-right', decl.value);
  249. const rtlDecl = cloneDecl(decl, '-left', decl.value);
  250. return 'ltr' === dir ? ltrDecl : 'rtl' === dir ? rtlDecl : [cloneRule(decl, 'ltr').append(ltrDecl), cloneRule(decl, 'rtl').append(rtlDecl)];
  251. },
  252. // inset-start, margin-start, padding-start
  253. 'start': (decl, values, dir) => {
  254. const ltrDecls = [cloneDecl(decl, '-top', values[0]), cloneDecl(decl, '-left', values[1] || values[0])];
  255. const rtlDecls = [cloneDecl(decl, '-top', values[0]), cloneDecl(decl, '-right', values[1] || values[0])];
  256. return 'ltr' === dir ? ltrDecls : 'rtl' === dir ? rtlDecls : [cloneRule(decl, 'ltr').append(ltrDecls), cloneRule(decl, 'rtl').append(rtlDecls)];
  257. },
  258. // inset-end, margin-end, padding-end
  259. 'end': (decl, values, dir) => {
  260. const ltrDecls = [cloneDecl(decl, '-bottom', values[0]), cloneDecl(decl, '-right', values[1] || values[0])];
  261. const rtlDecls = [cloneDecl(decl, '-bottom', values[0]), cloneDecl(decl, '-left', values[1] || values[0])];
  262. return 'ltr' === dir ? ltrDecls : 'rtl' === dir ? rtlDecls : [cloneRule(decl, 'ltr').append(ltrDecls), cloneRule(decl, 'rtl').append(rtlDecls)];
  263. }
  264. };
  265. var matchSize = /^(min-|max-)?(block|inline)-(size)$/i;
  266. var transformSize = (decl => {
  267. decl.prop = decl.prop.replace(matchSize, ($0, minmax, flow) => `${minmax || ''}${'block' === flow ? 'height' : 'width'}`);
  268. });
  269. var transformSpacing = ((decl, values, dir) => {
  270. if ('logical' !== values[0]) {
  271. return null;
  272. }
  273. const isLTR = !values[4] || values[4] === values[2];
  274. const ltrDecl = decl.clone({
  275. value: [values[1], values[4] || values[2] || values[1], values[3] || values[1], values[2] || values[1]].join(' ')
  276. });
  277. const rtlDecl = decl.clone({
  278. value: [values[1], values[2] || values[1], values[3] || values[1], values[4] || values[2] || values[1]].join(' ')
  279. });
  280. return isLTR ? decl.clone({
  281. value: decl.value.replace(/^\s*logical\s+/i, '')
  282. }) : 'ltr' === dir ? ltrDecl : 'rtl' === dir ? rtlDecl : [cloneRule(decl, 'ltr').append(ltrDecl), cloneRule(decl, 'rtl').append(rtlDecl)];
  283. });
  284. var transformTextAlign = ((decl, values, dir) => {
  285. const lDecl = decl.clone({
  286. value: 'left'
  287. });
  288. const rDecl = decl.clone({
  289. value: 'right'
  290. });
  291. return /^start$/i.test(decl.value) ? 'ltr' === dir ? lDecl : 'rtl' === dir ? rDecl : [cloneRule(decl, 'ltr').append(lDecl), cloneRule(decl, 'rtl').append(rDecl)] : /^end$/i.test(decl.value) ? 'ltr' === dir ? rDecl : 'rtl' === dir ? lDecl : [cloneRule(decl, 'ltr').append(rDecl), cloneRule(decl, 'rtl').append(lDecl)] : null;
  292. });
  293. function splitByComma(string, isTrimmed) {
  294. return splitByRegExp(string, /^,$/, isTrimmed);
  295. }
  296. function splitBySpace(string, isTrimmed) {
  297. return splitByRegExp(string, /^\s$/, isTrimmed);
  298. }
  299. function splitBySlash(string, isTrimmed) {
  300. return splitByRegExp(string, /^\/$/, isTrimmed);
  301. }
  302. function splitByRegExp(string, re, isTrimmed) {
  303. const array = [];
  304. let buffer = '';
  305. let split = false;
  306. let func = 0;
  307. let i = -1;
  308. while (++i < string.length) {
  309. const char = string[i];
  310. if (char === '(') {
  311. func += 1;
  312. } else if (char === ')') {
  313. if (func > 0) {
  314. func -= 1;
  315. }
  316. } else if (func === 0) {
  317. if (re.test(char)) {
  318. split = true;
  319. }
  320. }
  321. if (split) {
  322. if (!isTrimmed || buffer.trim()) {
  323. array.push(isTrimmed ? buffer.trim() : buffer);
  324. }
  325. if (!isTrimmed) {
  326. array.push(char);
  327. }
  328. buffer = '';
  329. split = false;
  330. } else {
  331. buffer += char;
  332. }
  333. }
  334. if (buffer !== '') {
  335. array.push(isTrimmed ? buffer.trim() : buffer);
  336. }
  337. return array;
  338. }
  339. var transformTransition = ((decl, notValues, dir) => {
  340. const ltrValues = [];
  341. const rtlValues = [];
  342. splitByComma(decl.value).forEach(value => {
  343. let hasBeenSplit = false;
  344. splitBySpace(value).forEach((word, index, words) => {
  345. if (word in valueMap) {
  346. hasBeenSplit = true;
  347. valueMap[word].ltr.forEach(replacement => {
  348. const clone = words.slice();
  349. clone.splice(index, 1, replacement);
  350. if (ltrValues.length && !/^,$/.test(ltrValues[ltrValues.length - 1])) {
  351. ltrValues.push(',');
  352. }
  353. ltrValues.push(clone.join(''));
  354. });
  355. valueMap[word].rtl.forEach(replacement => {
  356. const clone = words.slice();
  357. clone.splice(index, 1, replacement);
  358. if (rtlValues.length && !/^,$/.test(rtlValues[rtlValues.length - 1])) {
  359. rtlValues.push(',');
  360. }
  361. rtlValues.push(clone.join(''));
  362. });
  363. }
  364. });
  365. if (!hasBeenSplit) {
  366. ltrValues.push(value);
  367. rtlValues.push(value);
  368. }
  369. });
  370. const ltrDecl = decl.clone({
  371. value: ltrValues.join('')
  372. });
  373. const rtlDecl = decl.clone({
  374. value: rtlValues.join('')
  375. });
  376. return ltrValues.length && 'ltr' === dir ? ltrDecl : rtlValues.length && 'rtl' === dir ? rtlDecl : ltrDecl.value !== rtlDecl.value ? [cloneRule(decl, 'ltr').append(ltrDecl), cloneRule(decl, 'rtl').append(rtlDecl)] : null;
  377. });
  378. const valueMap = {
  379. 'border-block': {
  380. ltr: ['border-top', 'border-bottom'],
  381. rtl: ['border-top', 'border-bottom']
  382. },
  383. 'border-block-color': {
  384. ltr: ['border-top-color', 'border-bottom-color'],
  385. rtl: ['border-top-color', 'border-bottom-color']
  386. },
  387. 'border-block-end': {
  388. ltr: ['border-bottom'],
  389. rtl: ['border-bottom']
  390. },
  391. 'border-block-end-color': {
  392. ltr: ['border-bottom-color'],
  393. rtl: ['border-bottom-color']
  394. },
  395. 'border-block-end-style': {
  396. ltr: ['border-bottom-style'],
  397. rtl: ['border-bottom-style']
  398. },
  399. 'border-block-end-width': {
  400. ltr: ['border-bottom-width'],
  401. rtl: ['border-bottom-width']
  402. },
  403. 'border-block-start': {
  404. ltr: ['border-top'],
  405. rtl: ['border-top']
  406. },
  407. 'border-block-start-color': {
  408. ltr: ['border-top-color'],
  409. rtl: ['border-top-color']
  410. },
  411. 'border-block-start-style': {
  412. ltr: ['border-top-style'],
  413. rtl: ['border-top-style']
  414. },
  415. 'border-block-start-width': {
  416. ltr: ['border-top-width'],
  417. rtl: ['border-top-width']
  418. },
  419. 'border-block-style': {
  420. ltr: ['border-top-style', 'border-bottom-style'],
  421. rtl: ['border-top-style', 'border-bottom-style']
  422. },
  423. 'border-block-width': {
  424. ltr: ['border-top-width', 'border-bottom-width'],
  425. rtl: ['border-top-width', 'border-bottom-width']
  426. },
  427. 'border-end': {
  428. ltr: ['border-bottom', 'border-right'],
  429. rtl: ['border-bottom', 'border-left']
  430. },
  431. 'border-end-color': {
  432. ltr: ['border-bottom-color', 'border-right-color'],
  433. rtl: ['border-bottom-color', 'border-left-color']
  434. },
  435. 'border-end-style': {
  436. ltr: ['border-bottom-style', 'border-right-style'],
  437. rtl: ['border-bottom-style', 'border-left-style']
  438. },
  439. 'border-end-width': {
  440. ltr: ['border-bottom-width', 'border-right-width'],
  441. rtl: ['border-bottom-width', 'border-left-width']
  442. },
  443. 'border-inline': {
  444. ltr: ['border-left', 'border-right'],
  445. rtl: ['border-left', 'border-right']
  446. },
  447. 'border-inline-color': {
  448. ltr: ['border-left-color', 'border-right-color'],
  449. rtl: ['border-left-color', 'border-right-color']
  450. },
  451. 'border-inline-end': {
  452. ltr: ['border-right'],
  453. rtl: ['border-left']
  454. },
  455. 'border-inline-end-color': {
  456. ltr: ['border-right-color'],
  457. rtl: ['border-left-color']
  458. },
  459. 'border-inline-end-style': {
  460. ltr: ['border-right-style'],
  461. rtl: ['border-left-style']
  462. },
  463. 'border-inline-end-width': {
  464. ltr: ['border-right-width'],
  465. rtl: ['border-left-width']
  466. },
  467. 'border-inline-start': {
  468. ltr: ['border-left'],
  469. rtl: ['border-right']
  470. },
  471. 'border-inline-start-color': {
  472. ltr: ['border-left-color'],
  473. rtl: ['border-right-color']
  474. },
  475. 'border-inline-start-style': {
  476. ltr: ['border-left-style'],
  477. rtl: ['border-right-style']
  478. },
  479. 'border-inline-start-width': {
  480. ltr: ['border-left-width'],
  481. rtl: ['border-right-width']
  482. },
  483. 'border-inline-style': {
  484. ltr: ['border-left-style', 'border-right-style'],
  485. rtl: ['border-left-style', 'border-right-style']
  486. },
  487. 'border-inline-width': {
  488. ltr: ['border-left-width', 'border-right-width'],
  489. rtl: ['border-left-width', 'border-right-width']
  490. },
  491. 'border-start': {
  492. ltr: ['border-top', 'border-left'],
  493. rtl: ['border-top', 'border-right']
  494. },
  495. 'border-start-color': {
  496. ltr: ['border-top-color', 'border-left-color'],
  497. rtl: ['border-top-color', 'border-right-color']
  498. },
  499. 'border-start-style': {
  500. ltr: ['border-top-style', 'border-left-style'],
  501. rtl: ['border-top-style', 'border-right-style']
  502. },
  503. 'border-start-width': {
  504. ltr: ['border-top-width', 'border-left-width'],
  505. rtl: ['border-top-width', 'border-right-width']
  506. },
  507. 'block-size': {
  508. ltr: ['height'],
  509. rtl: ['height']
  510. },
  511. 'inline-size': {
  512. ltr: ['width'],
  513. rtl: ['width']
  514. },
  515. 'inset': {
  516. ltr: ['top', 'right', 'bottom', 'left'],
  517. rtl: ['top', 'right', 'bottom', 'left']
  518. },
  519. 'inset-block': {
  520. ltr: ['top', 'bottom'],
  521. rtl: ['top', 'bottom']
  522. },
  523. 'inset-block-start': {
  524. ltr: ['top'],
  525. rtl: ['top']
  526. },
  527. 'inset-block-end': {
  528. ltr: ['bottom'],
  529. rtl: ['bottom']
  530. },
  531. 'inset-end': {
  532. ltr: ['bottom', 'right'],
  533. rtl: ['bottom', 'left']
  534. },
  535. 'inset-inline': {
  536. ltr: ['left', 'right'],
  537. rtl: ['left', 'right']
  538. },
  539. 'inset-inline-start': {
  540. ltr: ['left'],
  541. rtl: ['right']
  542. },
  543. 'inset-inline-end': {
  544. ltr: ['right'],
  545. rtl: ['left']
  546. },
  547. 'inset-start': {
  548. ltr: ['top', 'left'],
  549. rtl: ['top', 'right']
  550. },
  551. 'margin-block': {
  552. ltr: ['margin-top', 'margin-bottom'],
  553. rtl: ['margin-top', 'margin-bottom']
  554. },
  555. 'margin-block-start': {
  556. ltr: ['margin-top'],
  557. rtl: ['margin-top']
  558. },
  559. 'margin-block-end': {
  560. ltr: ['margin-bottom'],
  561. rtl: ['margin-bottom']
  562. },
  563. 'margin-end': {
  564. ltr: ['margin-bottom', 'margin-right'],
  565. rtl: ['margin-bottom', 'margin-left']
  566. },
  567. 'margin-inline': {
  568. ltr: ['margin-left', 'margin-right'],
  569. rtl: ['margin-left', 'margin-right']
  570. },
  571. 'margin-inline-start': {
  572. ltr: ['margin-left'],
  573. rtl: ['margin-right']
  574. },
  575. 'margin-inline-end': {
  576. ltr: ['margin-right'],
  577. rtl: ['margin-left']
  578. },
  579. 'margin-start': {
  580. ltr: ['margin-top', 'margin-left'],
  581. rtl: ['margin-top', 'margin-right']
  582. },
  583. 'padding-block': {
  584. ltr: ['padding-top', 'padding-bottom'],
  585. rtl: ['padding-top', 'padding-bottom']
  586. },
  587. 'padding-block-start': {
  588. ltr: ['padding-top'],
  589. rtl: ['padding-top']
  590. },
  591. 'padding-block-end': {
  592. ltr: ['padding-bottom'],
  593. rtl: ['padding-bottom']
  594. },
  595. 'padding-end': {
  596. ltr: ['padding-bottom', 'padding-right'],
  597. rtl: ['padding-bottom', 'padding-left']
  598. },
  599. 'padding-inline': {
  600. ltr: ['padding-left', 'padding-right'],
  601. rtl: ['padding-left', 'padding-right']
  602. },
  603. 'padding-inline-start': {
  604. ltr: ['padding-left'],
  605. rtl: ['padding-right']
  606. },
  607. 'padding-inline-end': {
  608. ltr: ['padding-right'],
  609. rtl: ['padding-left']
  610. },
  611. 'padding-start': {
  612. ltr: ['padding-top', 'padding-left'],
  613. rtl: ['padding-top', 'padding-right']
  614. }
  615. };
  616. var matchSupportedProperties = /^(?:(inset|margin|padding)(?:-(block|block-start|block-end|inline|inline-start|inline-end|start|end))|(min-|max-)?(block|inline)-(size))$/i;
  617. // tooling
  618. const transforms = {
  619. 'border': transformBorder['border'],
  620. 'border-width': transformBorder['border'],
  621. 'border-style': transformBorder['border'],
  622. 'border-color': transformBorder['border'],
  623. 'border-block': transformBorder['border-block'],
  624. 'border-block-width': transformBorder['border-block'],
  625. 'border-block-style': transformBorder['border-block'],
  626. 'border-block-color': transformBorder['border-block'],
  627. 'border-block-start': transformBorder['border-block-start'],
  628. 'border-block-start-width': transformBorder['border-block-start'],
  629. 'border-block-start-style': transformBorder['border-block-start'],
  630. 'border-block-start-color': transformBorder['border-block-start'],
  631. 'border-block-end': transformBorder['border-block-end'],
  632. 'border-block-end-width': transformBorder['border-block-end'],
  633. 'border-block-end-style': transformBorder['border-block-end'],
  634. 'border-block-end-color': transformBorder['border-block-end'],
  635. 'border-inline': transformBorder['border-inline'],
  636. 'border-inline-width': transformBorder['border-inline'],
  637. 'border-inline-style': transformBorder['border-inline'],
  638. 'border-inline-color': transformBorder['border-inline'],
  639. 'border-inline-start': transformBorder['border-inline-start'],
  640. 'border-inline-start-width': transformBorder['border-inline-start'],
  641. 'border-inline-start-style': transformBorder['border-inline-start'],
  642. 'border-inline-start-color': transformBorder['border-inline-start'],
  643. 'border-inline-end': transformBorder['border-inline-end'],
  644. 'border-inline-end-width': transformBorder['border-inline-end'],
  645. 'border-inline-end-style': transformBorder['border-inline-end'],
  646. 'border-inline-end-color': transformBorder['border-inline-end'],
  647. 'border-start': transformBorder['border-start'],
  648. 'border-start-width': transformBorder['border-start'],
  649. 'border-start-style': transformBorder['border-start'],
  650. 'border-start-color': transformBorder['border-start'],
  651. 'border-end': transformBorder['border-end'],
  652. 'border-end-width': transformBorder['border-end'],
  653. 'border-end-style': transformBorder['border-end'],
  654. 'border-end-color': transformBorder['border-end'],
  655. 'clear': transformFloat,
  656. 'inset': transformInset,
  657. 'margin': transformSpacing,
  658. 'padding': transformSpacing,
  659. 'block': transformSide['block'],
  660. 'block-start': transformSide['block-start'],
  661. 'block-end': transformSide['block-end'],
  662. 'inline': transformSide['inline'],
  663. 'inline-start': transformSide['inline-start'],
  664. 'inline-end': transformSide['inline-end'],
  665. 'start': transformSide['start'],
  666. 'end': transformSide['end'],
  667. 'float': transformFloat,
  668. 'resize': transformResize,
  669. 'size': transformSize,
  670. 'text-align': transformTextAlign,
  671. 'transition': transformTransition,
  672. 'transition-property': transformTransition
  673. }; // properties that will be split by slash
  674. const splitBySlashPropRegExp = /^border(-block|-inline|-start|-end)?(-width|-style|-color)?$/i; // plugin
  675. var index = postcss.plugin('postcss-logical-properties', opts => {
  676. const preserve = Boolean(Object(opts).preserve);
  677. const dir = !preserve && typeof Object(opts).dir === 'string' ? /^rtl$/i.test(opts.dir) ? 'rtl' : 'ltr' : false;
  678. return root => {
  679. root.walkDecls(decl => {
  680. const parent = decl.parent;
  681. const values = splitBySlashPropRegExp.test(decl.prop) ? splitBySlash(decl.value, true) : splitBySpace(decl.value, true);
  682. const prop = decl.prop.replace(matchSupportedProperties, '$2$5').toLowerCase();
  683. if (prop in transforms) {
  684. const replacer = transforms[prop](decl, values, dir);
  685. if (replacer) {
  686. [].concat(replacer).forEach(replacement => {
  687. if (replacement.type === 'rule') {
  688. parent.before(replacement);
  689. } else {
  690. decl.before(replacement);
  691. }
  692. });
  693. if (!preserve) {
  694. decl.remove();
  695. if (!parent.nodes.length) {
  696. parent.remove();
  697. }
  698. }
  699. }
  700. }
  701. });
  702. };
  703. });
  704. module.exports = index;
  705. //# sourceMappingURL=index.cjs.js.map