How to use decl method in wpt

Best JavaScript code snippet using wpt

index.es.mjs

Source:index.es.mjs Github

copy

Full Screen

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

Full Screen

Full Screen

processor.js

Source:processor.js Github

copy

Full Screen

1"use strict";2function _createForOfIteratorHelperLoose(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { 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."); } it = o[Symbol.iterator](); return it.next.bind(it); }3function _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); }4function _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; }5var parser = require('postcss-value-parser');6var Value = require('./value');7var insertAreas = require('./hacks/grid-utils').insertAreas;8var OLD_LINEAR = /(^|[^-])linear-gradient\(\s*(top|left|right|bottom)/i;9var OLD_RADIAL = /(^|[^-])radial-gradient\(\s*\d+(\w*|%)\s+\d+(\w*|%)\s*,/i;10var IGNORE_NEXT = /(!\s*)?autoprefixer:\s*ignore\s+next/i;11var GRID_REGEX = /(!\s*)?autoprefixer\s*grid:\s*(on|off|(no-)?autoplace)/i;12var SIZES = ['width', 'height', 'min-width', 'max-width', 'min-height', 'max-height', 'inline-size', 'min-inline-size', 'max-inline-size', 'block-size', 'min-block-size', 'max-block-size'];13function hasGridTemplate(decl) {14 return decl.parent.some(function (i) {15 return i.prop === 'grid-template' || i.prop === 'grid-template-areas';16 });17}18function hasRowsAndColumns(decl) {19 var hasRows = decl.parent.some(function (i) {20 return i.prop === 'grid-template-rows';21 });22 var hasColumns = decl.parent.some(function (i) {23 return i.prop === 'grid-template-columns';24 });25 return hasRows && hasColumns;26}27var Processor = /*#__PURE__*/function () {28 function Processor(prefixes) {29 this.prefixes = prefixes;30 }31 /**32 * Add necessary prefixes33 */34 var _proto = Processor.prototype;35 _proto.add = function add(css, result) {36 var _this = this;37 // At-rules38 var resolution = this.prefixes.add['@resolution'];39 var keyframes = this.prefixes.add['@keyframes'];40 var viewport = this.prefixes.add['@viewport'];41 var supports = this.prefixes.add['@supports'];42 css.walkAtRules(function (rule) {43 if (rule.name === 'keyframes') {44 if (!_this.disabled(rule, result)) {45 return keyframes && keyframes.process(rule);46 }47 } else if (rule.name === 'viewport') {48 if (!_this.disabled(rule, result)) {49 return viewport && viewport.process(rule);50 }51 } else if (rule.name === 'supports') {52 if (_this.prefixes.options.supports !== false && !_this.disabled(rule, result)) {53 return supports.process(rule);54 }55 } else if (rule.name === 'media' && rule.params.includes('-resolution')) {56 if (!_this.disabled(rule, result)) {57 return resolution && resolution.process(rule);58 }59 }60 return undefined;61 }); // Selectors62 css.walkRules(function (rule) {63 if (_this.disabled(rule, result)) return undefined;64 return _this.prefixes.add.selectors.map(function (selector) {65 return selector.process(rule, result);66 });67 });68 function insideGrid(decl) {69 return decl.parent.nodes.some(function (node) {70 if (node.type !== 'decl') return false;71 var displayGrid = node.prop === 'display' && /(inline-)?grid/.test(node.value);72 var gridTemplate = node.prop.startsWith('grid-template');73 var gridGap = /^grid-([A-z]+-)?gap/.test(node.prop);74 return displayGrid || gridTemplate || gridGap;75 });76 }77 function insideFlex(decl) {78 return decl.parent.some(function (node) {79 return node.prop === 'display' && /(inline-)?flex/.test(node.value);80 });81 }82 var gridPrefixes = this.gridStatus(css, result) && this.prefixes.add['grid-area'] && this.prefixes.add['grid-area'].prefixes;83 css.walkDecls(function (decl) {84 if (_this.disabledDecl(decl, result)) return undefined;85 var parent = decl.parent;86 var prop = decl.prop;87 var value = decl.value;88 if (prop === 'grid-row-span') {89 result.warn('grid-row-span is not part of final Grid Layout. Use grid-row.', {90 node: decl91 });92 return undefined;93 } else if (prop === 'grid-column-span') {94 result.warn('grid-column-span is not part of final Grid Layout. Use grid-column.', {95 node: decl96 });97 return undefined;98 } else if (prop === 'display' && value === 'box') {99 result.warn('You should write display: flex by final spec ' + 'instead of display: box', {100 node: decl101 });102 return undefined;103 } else if (prop === 'text-emphasis-position') {104 if (value === 'under' || value === 'over') {105 result.warn('You should use 2 values for text-emphasis-position ' + 'For example, `under left` instead of just `under`.', {106 node: decl107 });108 }109 } else if (/^(align|justify|place)-(items|content)$/.test(prop) && insideFlex(decl)) {110 if (value === 'start' || value === 'end') {111 result.warn(value + " value has mixed support, consider using " + ("flex-" + value + " instead"), {112 node: decl113 });114 }115 } else if (prop === 'text-decoration-skip' && value === 'ink') {116 result.warn('Replace text-decoration-skip: ink to ' + 'text-decoration-skip-ink: auto, because spec had been changed', {117 node: decl118 });119 } else {120 if (gridPrefixes && _this.gridStatus(decl, result)) {121 if (decl.value === 'subgrid') {122 result.warn('IE does not support subgrid', {123 node: decl124 });125 }126 if (/^(align|justify|place)-items$/.test(prop) && insideGrid(decl)) {127 var fixed = prop.replace('-items', '-self');128 result.warn("IE does not support " + prop + " on grid containers. " + ("Try using " + fixed + " on child elements instead: ") + (decl.parent.selector + " > * { " + fixed + ": " + decl.value + " }"), {129 node: decl130 });131 } else if (/^(align|justify|place)-content$/.test(prop) && insideGrid(decl)) {132 result.warn("IE does not support " + decl.prop + " on grid containers", {133 node: decl134 });135 } else if (prop === 'display' && decl.value === 'contents') {136 result.warn('Please do not use display: contents; ' + 'if you have grid setting enabled', {137 node: decl138 });139 return undefined;140 } else if (decl.prop === 'grid-gap') {141 var status = _this.gridStatus(decl, result);142 if (status === 'autoplace' && !hasRowsAndColumns(decl) && !hasGridTemplate(decl)) {143 result.warn('grid-gap only works if grid-template(-areas) is being ' + 'used or both rows and columns have been declared ' + 'and cells have not been manually ' + 'placed inside the explicit grid', {144 node: decl145 });146 } else if ((status === true || status === 'no-autoplace') && !hasGridTemplate(decl)) {147 result.warn('grid-gap only works if grid-template(-areas) is being used', {148 node: decl149 });150 }151 } else if (prop === 'grid-auto-columns') {152 result.warn('grid-auto-columns is not supported by IE', {153 node: decl154 });155 return undefined;156 } else if (prop === 'grid-auto-rows') {157 result.warn('grid-auto-rows is not supported by IE', {158 node: decl159 });160 return undefined;161 } else if (prop === 'grid-auto-flow') {162 var hasRows = parent.some(function (i) {163 return i.prop === 'grid-template-rows';164 });165 var hasCols = parent.some(function (i) {166 return i.prop === 'grid-template-columns';167 });168 if (hasGridTemplate(decl)) {169 result.warn('grid-auto-flow is not supported by IE', {170 node: decl171 });172 } else if (value.includes('dense')) {173 result.warn('grid-auto-flow: dense is not supported by IE', {174 node: decl175 });176 } else if (!hasRows && !hasCols) {177 result.warn('grid-auto-flow works only if grid-template-rows and ' + 'grid-template-columns are present in the same rule', {178 node: decl179 });180 }181 return undefined;182 } else if (value.includes('auto-fit')) {183 result.warn('auto-fit value is not supported by IE', {184 node: decl,185 word: 'auto-fit'186 });187 return undefined;188 } else if (value.includes('auto-fill')) {189 result.warn('auto-fill value is not supported by IE', {190 node: decl,191 word: 'auto-fill'192 });193 return undefined;194 } else if (prop.startsWith('grid-template') && value.includes('[')) {195 result.warn('Autoprefixer currently does not support line names. ' + 'Try using grid-template-areas instead.', {196 node: decl,197 word: '['198 });199 }200 }201 if (value.includes('radial-gradient')) {202 if (OLD_RADIAL.test(decl.value)) {203 result.warn('Gradient has outdated direction syntax. ' + 'New syntax is like `closest-side at 0 0` ' + 'instead of `0 0, closest-side`.', {204 node: decl205 });206 } else {207 var ast = parser(value);208 for (var _iterator = _createForOfIteratorHelperLoose(ast.nodes), _step; !(_step = _iterator()).done;) {209 var i = _step.value;210 if (i.type === 'function' && i.value === 'radial-gradient') {211 for (var _iterator2 = _createForOfIteratorHelperLoose(i.nodes), _step2; !(_step2 = _iterator2()).done;) {212 var word = _step2.value;213 if (word.type === 'word') {214 if (word.value === 'cover') {215 result.warn('Gradient has outdated direction syntax. ' + 'Replace `cover` to `farthest-corner`.', {216 node: decl217 });218 } else if (word.value === 'contain') {219 result.warn('Gradient has outdated direction syntax. ' + 'Replace `contain` to `closest-side`.', {220 node: decl221 });222 }223 }224 }225 }226 }227 }228 }229 if (value.includes('linear-gradient')) {230 if (OLD_LINEAR.test(value)) {231 result.warn('Gradient has outdated direction syntax. ' + 'New syntax is like `to left` instead of `right`.', {232 node: decl233 });234 }235 }236 }237 if (SIZES.includes(decl.prop)) {238 if (!decl.value.includes('-fill-available')) {239 if (decl.value.includes('fill-available')) {240 result.warn('Replace fill-available to stretch, ' + 'because spec had been changed', {241 node: decl242 });243 } else if (decl.value.includes('fill')) {244 var _ast = parser(value);245 if (_ast.nodes.some(function (i) {246 return i.type === 'word' && i.value === 'fill';247 })) {248 result.warn('Replace fill to stretch, because spec had been changed', {249 node: decl250 });251 }252 }253 }254 }255 var prefixer;256 if (decl.prop === 'transition' || decl.prop === 'transition-property') {257 // Transition258 return _this.prefixes.transition.add(decl, result);259 } else if (decl.prop === 'align-self') {260 // align-self flexbox or grid261 var display = _this.displayType(decl);262 if (display !== 'grid' && _this.prefixes.options.flexbox !== false) {263 prefixer = _this.prefixes.add['align-self'];264 if (prefixer && prefixer.prefixes) {265 prefixer.process(decl);266 }267 }268 if (_this.gridStatus(decl, result) !== false) {269 prefixer = _this.prefixes.add['grid-row-align'];270 if (prefixer && prefixer.prefixes) {271 return prefixer.process(decl, result);272 }273 }274 } else if (decl.prop === 'justify-self') {275 // justify-self flexbox or grid276 if (_this.gridStatus(decl, result) !== false) {277 prefixer = _this.prefixes.add['grid-column-align'];278 if (prefixer && prefixer.prefixes) {279 return prefixer.process(decl, result);280 }281 }282 } else if (decl.prop === 'place-self') {283 prefixer = _this.prefixes.add['place-self'];284 if (prefixer && prefixer.prefixes && _this.gridStatus(decl, result) !== false) {285 return prefixer.process(decl, result);286 }287 } else {288 // Properties289 prefixer = _this.prefixes.add[decl.prop];290 if (prefixer && prefixer.prefixes) {291 return prefixer.process(decl, result);292 }293 }294 return undefined;295 }); // Insert grid-area prefixes. We need to be able to store the different296 // rules as a data and hack API is not enough for this297 if (this.gridStatus(css, result)) {298 insertAreas(css, this.disabled);299 } // Values300 return css.walkDecls(function (decl) {301 if (_this.disabledValue(decl, result)) return;302 var unprefixed = _this.prefixes.unprefixed(decl.prop);303 var list = _this.prefixes.values('add', unprefixed);304 if (Array.isArray(list)) {305 for (var _iterator3 = _createForOfIteratorHelperLoose(list), _step3; !(_step3 = _iterator3()).done;) {306 var value = _step3.value;307 if (value.process) value.process(decl, result);308 }309 }310 Value.save(_this.prefixes, decl);311 });312 }313 /**314 * Remove unnecessary pefixes315 */316 ;317 _proto.remove = function remove(css, result) {318 var _this2 = this;319 // At-rules320 var resolution = this.prefixes.remove['@resolution'];321 css.walkAtRules(function (rule, i) {322 if (_this2.prefixes.remove["@" + rule.name]) {323 if (!_this2.disabled(rule, result)) {324 rule.parent.removeChild(i);325 }326 } else if (rule.name === 'media' && rule.params.includes('-resolution') && resolution) {327 resolution.clean(rule);328 }329 }); // Selectors330 var _loop = function _loop() {331 var checker = _step4.value;332 css.walkRules(function (rule, i) {333 if (checker.check(rule)) {334 if (!_this2.disabled(rule, result)) {335 rule.parent.removeChild(i);336 }337 }338 });339 };340 for (var _iterator4 = _createForOfIteratorHelperLoose(this.prefixes.remove.selectors), _step4; !(_step4 = _iterator4()).done;) {341 _loop();342 }343 return css.walkDecls(function (decl, i) {344 if (_this2.disabled(decl, result)) return;345 var rule = decl.parent;346 var unprefixed = _this2.prefixes.unprefixed(decl.prop); // Transition347 if (decl.prop === 'transition' || decl.prop === 'transition-property') {348 _this2.prefixes.transition.remove(decl);349 } // Properties350 if (_this2.prefixes.remove[decl.prop] && _this2.prefixes.remove[decl.prop].remove) {351 var notHack = _this2.prefixes.group(decl).down(function (other) {352 return _this2.prefixes.normalize(other.prop) === unprefixed;353 });354 if (unprefixed === 'flex-flow') {355 notHack = true;356 }357 if (decl.prop === '-webkit-box-orient') {358 var hacks = {359 'flex-direction': true,360 'flex-flow': true361 };362 if (!decl.parent.some(function (j) {363 return hacks[j.prop];364 })) return;365 }366 if (notHack && !_this2.withHackValue(decl)) {367 if (decl.raw('before').includes('\n')) {368 _this2.reduceSpaces(decl);369 }370 rule.removeChild(i);371 return;372 }373 } // Values374 for (var _iterator5 = _createForOfIteratorHelperLoose(_this2.prefixes.values('remove', unprefixed)), _step5; !(_step5 = _iterator5()).done;) {375 var checker = _step5.value;376 if (!checker.check) continue;377 if (!checker.check(decl.value)) continue;378 unprefixed = checker.unprefixed;379 var _notHack = _this2.prefixes.group(decl).down(function (other) {380 return other.value.includes(unprefixed);381 });382 if (_notHack) {383 rule.removeChild(i);384 return;385 }386 }387 });388 }389 /**390 * Some rare old values, which is not in standard391 */392 ;393 _proto.withHackValue = function withHackValue(decl) {394 return decl.prop === '-webkit-background-clip' && decl.value === 'text';395 }396 /**397 * Check for grid/flexbox options.398 */399 ;400 _proto.disabledValue = function disabledValue(node, result) {401 if (this.gridStatus(node, result) === false && node.type === 'decl') {402 if (node.prop === 'display' && node.value.includes('grid')) {403 return true;404 }405 }406 if (this.prefixes.options.flexbox === false && node.type === 'decl') {407 if (node.prop === 'display' && node.value.includes('flex')) {408 return true;409 }410 }411 return this.disabled(node, result);412 }413 /**414 * Check for grid/flexbox options.415 */416 ;417 _proto.disabledDecl = function disabledDecl(node, result) {418 if (this.gridStatus(node, result) === false && node.type === 'decl') {419 if (node.prop.includes('grid') || node.prop === 'justify-items') {420 return true;421 }422 }423 if (this.prefixes.options.flexbox === false && node.type === 'decl') {424 var other = ['order', 'justify-content', 'align-items', 'align-content'];425 if (node.prop.includes('flex') || other.includes(node.prop)) {426 return true;427 }428 }429 return this.disabled(node, result);430 }431 /**432 * Check for control comment and global options433 */434 ;435 _proto.disabled = function disabled(node, result) {436 if (!node) return false;437 if (node._autoprefixerDisabled !== undefined) {438 return node._autoprefixerDisabled;439 }440 if (node.parent) {441 var p = node.prev();442 if (p && p.type === 'comment' && IGNORE_NEXT.test(p.text)) {443 node._autoprefixerDisabled = true;444 node._autoprefixerSelfDisabled = true;445 return true;446 }447 }448 var value = null;449 if (node.nodes) {450 var status;451 node.each(function (i) {452 if (i.type !== 'comment') return;453 if (/(!\s*)?autoprefixer:\s*(off|on)/i.test(i.text)) {454 if (typeof status !== 'undefined') {455 result.warn('Second Autoprefixer control comment ' + 'was ignored. Autoprefixer applies control ' + 'comment to whole block, not to next rules.', {456 node: i457 });458 } else {459 status = /on/i.test(i.text);460 }461 }462 });463 if (status !== undefined) {464 value = !status;465 }466 }467 if (!node.nodes || value === null) {468 if (node.parent) {469 var isParentDisabled = this.disabled(node.parent, result);470 if (node.parent._autoprefixerSelfDisabled === true) {471 value = false;472 } else {473 value = isParentDisabled;474 }475 } else {476 value = false;477 }478 }479 node._autoprefixerDisabled = value;480 return value;481 }482 /**483 * Normalize spaces in cascade declaration group484 */485 ;486 _proto.reduceSpaces = function reduceSpaces(decl) {487 var stop = false;488 this.prefixes.group(decl).up(function () {489 stop = true;490 return true;491 });492 if (stop) {493 return;494 }495 var parts = decl.raw('before').split('\n');496 var prevMin = parts[parts.length - 1].length;497 var diff = false;498 this.prefixes.group(decl).down(function (other) {499 parts = other.raw('before').split('\n');500 var last = parts.length - 1;501 if (parts[last].length > prevMin) {502 if (diff === false) {503 diff = parts[last].length - prevMin;504 }505 parts[last] = parts[last].slice(0, -diff);506 other.raws.before = parts.join('\n');507 }508 });509 }510 /**511 * Is it flebox or grid rule512 */513 ;514 _proto.displayType = function displayType(decl) {515 for (var _iterator6 = _createForOfIteratorHelperLoose(decl.parent.nodes), _step6; !(_step6 = _iterator6()).done;) {516 var i = _step6.value;517 if (i.prop !== 'display') {518 continue;519 }520 if (i.value.includes('flex')) {521 return 'flex';522 }523 if (i.value.includes('grid')) {524 return 'grid';525 }526 }527 return false;528 }529 /**530 * Set grid option via control comment531 */532 ;533 _proto.gridStatus = function gridStatus(node, result) {534 if (!node) return false;535 if (node._autoprefixerGridStatus !== undefined) {536 return node._autoprefixerGridStatus;537 }538 var value = null;539 if (node.nodes) {540 var status;541 node.each(function (i) {542 if (i.type !== 'comment') return;543 if (GRID_REGEX.test(i.text)) {544 var hasAutoplace = /:\s*autoplace/i.test(i.text);545 var noAutoplace = /no-autoplace/i.test(i.text);546 if (typeof status !== 'undefined') {547 result.warn('Second Autoprefixer grid control comment was ' + 'ignored. Autoprefixer applies control comments to the whole ' + 'block, not to the next rules.', {548 node: i549 });550 } else if (hasAutoplace) {551 status = 'autoplace';552 } else if (noAutoplace) {553 status = true;554 } else {555 status = /on/i.test(i.text);556 }557 }558 });559 if (status !== undefined) {560 value = status;561 }562 }563 if (node.type === 'atrule' && node.name === 'supports') {564 var params = node.params;565 if (params.includes('grid') && params.includes('auto')) {566 value = false;567 }568 }569 if (!node.nodes || value === null) {570 if (node.parent) {571 var isParentGrid = this.gridStatus(node.parent, result);572 if (node.parent._autoprefixerSelfDisabled === true) {573 value = false;574 } else {575 value = isParentGrid;576 }577 } else if (typeof this.prefixes.options.grid !== 'undefined') {578 value = this.prefixes.options.grid;579 } else if (typeof process.env.AUTOPREFIXER_GRID !== 'undefined') {580 if (process.env.AUTOPREFIXER_GRID === 'autoplace') {581 value = 'autoplace';582 } else {583 value = true;584 }585 } else {586 value = false;587 }588 }589 node._autoprefixerGridStatus = value;590 return value;591 };592 return Processor;593}();...

Full Screen

Full Screen

rules-fabric.js

Source:rules-fabric.js Github

copy

Full Screen

1var decls = require('./decls.json');2function template(string, data) {3 return string.replace(/\$\{([\w\-\.]*)\}/g, function (_str, key) {4 var v = data[key];5 return typeof v !== 'undefined' && v !== null ? v : '';6 });7}8/*9 Rules legend:10 - combined - if rule is combined it will be rendered with template11 - combined and basic rules are present in basic reset12 - combined, basic and inherited rules are present in full reset13*/14function _getRulesMap(inputDecls) {15 return inputDecls16 .filter(function (decl) {17 return !decl.combined;18 })19 .reduce(function (map, decl) {20 map[decl.prop.replace(/\-/g, '')] = decl.initial;21 return map;22 }, {});23}24function _compileDecls(inputDecls) {25 var templateVars = _getRulesMap(inputDecls);26 return inputDecls.map(function (decl) {27 if (decl.combined && decl.initial) {28 decl.initial = template(decl.initial.replace(/\-/g, ''), templateVars);29 }30 return decl;31 });32}33function _getRequirements(inputDecls) {34 return inputDecls.reduce(function (map, decl) {35 if (!decl.contains) return map;36 return decl.contains.reduce(function (mapInner, dependency) {37 mapInner[dependency] = decl;38 return mapInner;39 }, map);40 }, {});41}42function _expandContainments(inputDecls) {43 var requiredMap = _getRequirements(inputDecls);44 return inputDecls45 .filter(function (decl) {46 return !decl.contains;47 }).map(function (decl) {48 var dependency = requiredMap[decl.prop];49 if (dependency) {50 decl.requiredBy = dependency.prop;51 decl.basic = decl.basic || dependency.basic;52 decl.inherited = decl.inherited || dependency.inherited;53 }54 return decl;55 });56}57var compiledDecls = _expandContainments(_compileDecls(decls));58function _clearDecls(rules, value) {59 return rules.map(function (rule) {60 return {61 prop: rule.prop,62 value: value.replace(/\binitial\b/g, rule.initial)63 };64 });65}66function _allDecls(onlyInherited) {67 return compiledDecls.filter(function (decl) {68 var allowed = decl.combined || decl.basic;69 if (onlyInherited) return allowed && decl.inherited;70 return allowed;71 });72}73function _concreteDecl(declName) {74 return compiledDecls.filter(function (decl) {75 return declName === decl.prop || declName === decl.requiredBy;76 });77}78function makeFallbackFunction(onlyInherited) {79 return function (declName, declValue) {80 var result;81 if (declName === 'all') {82 result = _allDecls(onlyInherited);83 } else {84 result = _concreteDecl(declName);85 }86 return _clearDecls(result, declValue);87 };88}...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3var options = {4};5wpt.runTest(options, function(err, data) {6 if (err) return console.error(err);7 console.log('Test initiated for: ' + data.data.testUrl);8 console.log('Test ID: ' + data.data.id);9 console.log('View your test at: ' + data.data.userUrl);10 wpt.getTestStatus(data.data.testId, function(err, data) {11 if (err) return console.error(err);12 console.log('Test status: ' + data.statusCode);13 });14});15var wpt = require('webpagetest');16var wpt = new WebPageTest('www.webpagetest.org');17var options = {18};19wpt.runTest(options, function(err, data) {20 if (err) return console.error(err);21 console.log('Test initiated for: ' + data.data.testUrl);22 console.log('Test ID: ' + data.data.id);23 console.log('View your test at: ' + data.data.userUrl);24 wpt.getTestStatus(data.data.testId, function(err, data) {25 if (err) return console.error(err);26 console.log('Test status: ' + data.statusCode);27 });28});29var wpt = require('webpagetest');30var wpt = new WebPageTest('www.webpagetest.org');31var options = {32};33wpt.runTest(options, function(err, data) {34 if (err) return console.error(err);

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var options = {3};4wpt.decl(options, function(err, data) {5 if (err) {6 console.log(err);7 } else {8 console.log(data);9 }10});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3wpt.decl('test', {4}, function(err, data) {5 if (err) {6 console.log(err);7 } else {8 console.log(data);9 }10});11var wpt = require('webpagetest');12var wpt = require('webpagetest');13var wpt = new WebPageTest('www.webpagetest.org');14wpt.decl('test', {15}, function(err, data) {16 if (err) {17 console.log(err);18 } else {19 console.log(data);20 }21});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wtf_wikipedia = require('wtf_wikipedia');2var wiki = wtf_wikipedia.fetch('Albert Einstein');3var decl = wiki.decl();4console.log(decl);5var wikipedia = require('wikipedia');6var decl = wikipedia.decl('Albert Einstein');7console.log(decl);8var wikipedia = require('wikipedia-node');9var decl = wikipedia.decl('Albert Einstein');10console.log(decl);11var wiki = require('wikijs').default;12var decl = wiki.decl('Albert Einstein');13console.log(decl);14var wiki = require('wikijs').default;15var decl = wiki.decl('Albert Einstein');16console.log(decl);17var wiki = require('wikijs').default;18var decl = wiki.decl('Albert Einstein');19console.log(decl);20var wiki = require('wikijs').default;21var decl = wiki.decl('Albert Einstein');22console.log(decl);23var wiki = require('wikijs').default;24var decl = wiki.decl('Albert Einstein');25console.log(decl);26var wiki = require('wikijs').default;27var decl = wiki.decl('Albert Einstein');28console.log(decl);29var wiki = require('wikijs').default;30var decl = wiki.decl('Albert Einstein');31console.log(decl);32var wiki = require('wikijs').default;33var decl = wiki.decl('Albert Einstein');34console.log(decl);35var wiki = require('wikijs').default;36var decl = wiki.decl('Albert Einstein');37console.log(decl);38var wiki = require('wikijs').default;

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3var location = 'Dulles:Chrome';4var options = {5};6wpt.decl(url, options, function(err, data) {7 if (err) {8 console.log('Error: ' + err);9 } else {10 console.log(data);11 }12});13var wpt = require('webpagetest');14var wpt = new WebPageTest('www.webpagetest.org');15var location = 'Dulles:Chrome';16var options = {17};18wpt.runTest(url, options, function(err, data) {19 if (err) {20 console.log('Error: ' + err);21 } else {22 console.log(data);23 }24});25var wpt = require('webpagetest');26var wpt = new WebPageTest('www.webpagetest.org');27wpt.getLocations(function(err, data) {28 if (err) {29 console.log('Error: ' + err);30 } else {31 console.log(data);32 }33});34var wpt = require('webpagetest');35var wpt = new WebPageTest('www.webpagetest.org');36wpt.getBrowsers(function(err, data) {37 if (err) {38 console.log('Error: ' + err);39 } else {40 console.log(data);41 }42});43var wpt = require('webpagetest');

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2wpt.decl('test', {3 sayHi: function(){4 console.log("Hi!");5 }6});7wpt.decl('test', {8 sayBye: function(){9 console.log("Bye!");10 }11});12wpt('test').sayHi();13wpt('test').sayBye();14var wpt = require('wpt');15wpt.decl('test2', {16 sayHi: function(){17 console.log("Hi!");18 }19});20wpt.decl('test2', {21 sayBye: function(){22 console.log("Bye!");23 }24});25wpt('test2').sayHi();26wpt('test2').sayBye();27var wpt = require('wpt');28wpt.decl('test3', {29 sayHi: function(){30 console.log("Hi!");31 }32});33wpt.decl('test3', {34 sayBye: function(){35 console.log("Bye!");36 }37});38wpt('test3').sayHi();39wpt('test3').sayBye();40var wpt = require('wpt');41wpt.decl('test4', {42 sayHi: function(){43 console.log("Hi!");44 }45});46wpt.decl('test4', {47 sayBye: function(){48 console.log("Bye!");49 }50});51wpt('test4').sayHi();52wpt('test4').sayBye();53var wpt = require('wpt');54wpt.decl('test5', {55 sayHi: function(){56 console.log("Hi!");57 }58});59wpt.decl('test5', {60 sayBye: function(){61 console.log("Bye!");62 }63});64wpt('test5').sayHi();65wpt('test5').sayBye();

Full Screen

Using AI Code Generation

copy

Full Screen

1wpt.decl({name: 'test', method: function() {2 console.log('test');3}});4wpt.decl({name: 'test2', method: function() {5 console.log('test2');6}});7wpt.decl({name: 'test3', method: function() {8 console.log('test3');9}});10wpt.decl({name: 'test4', method: function() {11 console.log('test4');12}});13wpt.decl({name: 'test5', method: function() {14 console.log('test5');15}});16wpt.decl({name: 'test6', method: function() {17 console.log('test6');18}});19wpt.decl({name: 'test7', method: function() {20 console.log('test7');21}});22wpt.decl({name: 'test8', method: function() {23 console.log('test8');24}});25wpt.decl({name: 'test9', method: function() {26 console.log('test9');27}});28wpt.decl({name: 'test10', method: function() {29 console.log('test10');30}});31wpt.decl({name: 'test11', method: function() {32 console.log('test11');33}});34wpt.decl({name: 'test12', method: function() {35 console.log('test12');36}});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org', 'A.8d7e0cd2c2e1d1f0c8b1b4e0f4f4f4f4');3var options = {4};5var script = 'wpt.decl({navigateStart: 0, firstPaint: 5000, domContentLoaded: 10000, loadEventEnd: 15000});';6wpt.runTest(url, options, script, function(err, data) {7 if (err) {8 console.log(err);9 } else {10 console.log(data);11 }12});13var WebPageTest = require('webpagetest');14var util = require('util');15var WebPageTest = function(host, apiKey) {16 this.wpt = new WebPageTest(host, apiKey);17};18WebPageTest.prototype.runTest = function(url, options, script, cb) {19 this.wpt.runTest(url, options, script, function(err, data) {20 if (err) {21 cb(err);22 } else {23 cb(null, data);24 }25 });26};27module.exports = WebPageTest;28{29 "dependencies": {30 }31}32var WebPageTest = require('webpagetest');33var util = require('util');34var wpt = new WebPageTest('www.webpagetest.org', 'A.8d7e0cd2c2e1d1f0c8b1b4e0f4f4

Full Screen

Using AI Code Generation

copy

Full Screen

1I am not sure what you mean by "use decl method of wpt", but I think you want to use the wpt method (as in wpt.method() ) in your test code. If that's the case, you can use the wpt object as you would any other object in your test code. For example:2wpt.method();3If you want to use the wpt object in a different file, you can require() it in the file where you want to use it. For example:4var wpt = require('./wpt');5wpt.method();6If you want to use the wpt object in a different file, you can require() it in the file where you want to use it. For example:

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful