Changeset e29cc2e for trip-planner-front/node_modules/critters/src/index.js
- Timestamp:
- 11/25/21 22:08:24 (3 years ago)
- Branches:
- master
- Children:
- 8d391a1
- Parents:
- 59329aa
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trip-planner-front/node_modules/critters/src/index.js
r59329aa re29cc2e 30 30 /** 31 31 * The mechanism to use for lazy-loading stylesheets. 32 * 32 33 * Note: <kbd>JS</kbd> indicates a strategy requiring JavaScript (falls back to `<noscript>` unless disabled). 33 34 * … … 242 243 .replace(/^\//, ''); 243 244 } 245 246 // Ignore remote stylesheets 247 if (/^https:\/\//.test(normalizedPath) || href.startsWith('//')) { 248 return undefined; 249 } 250 244 251 const filename = path.resolve(outputPath, normalizedPath); 245 252 … … 484 491 } 485 492 }); 493 486 494 // If there are no matched selectors, remove the rule: 487 if ( rule.selectors.length === 0) {495 if (!rule.selector) { 488 496 return false; 489 497 } 490 498 491 if (rule. declarations) {492 for (let i = 0; i < rule. declarations.length; i++) {493 const decl = rule. declarations[i];499 if (rule.nodes) { 500 for (let i = 0; i < rule.nodes.length; i++) { 501 const decl = rule.nodes[i]; 494 502 495 503 // detect used fonts 496 if (decl.prop erty && decl.property.match(/\bfont(-family)?\b/i)) {504 if (decl.prop && decl.prop.match(/\bfont(-family)?\b/i)) { 497 505 criticalFonts += ' ' + decl.value; 498 506 } 499 507 500 508 // detect used keyframes 501 if ( 502 decl.property === 'animation' || 503 decl.property === 'animation-name' 504 ) { 509 if (decl.prop === 'animation' || decl.prop === 'animation-name') { 505 510 // @todo: parse animation declarations and extract only the name. for now we'll do a lazy match. 506 511 const names = decl.value.split(/\s+/); … … 515 520 516 521 // keep font rules, they're handled in the second pass: 517 if (rule.type === ' font-face') return;522 if (rule.type === 'atrule' && rule.name === 'font-face') return; 518 523 519 524 // If there are no remaining rules, remove the whole rule: 520 const rules = rule. rules && rule.rules.filter((rule) => !rule.$$remove);525 const rules = rule.nodes && rule.nodes.filter((rule) => !rule.$$remove); 521 526 return !rules || rules.length !== 0; 522 527 }) … … 547 552 548 553 // prune @keyframes rules 549 if (rule.type === ' keyframes') {554 if (rule.type === 'atrule' && rule.name === 'keyframes') { 550 555 if (keyframesMode === 'none') return false; 551 556 if (keyframesMode === 'all') return true; 552 return criticalKeyframeNames.indexOf(rule. name) !== -1;557 return criticalKeyframeNames.indexOf(rule.params) !== -1; 553 558 } 554 559 555 560 // prune @font-face rules 556 if (rule.type === ' font-face') {561 if (rule.type === 'atrule' && rule.name === 'font-face') { 557 562 let family, src; 558 for (let i = 0; i < rule. declarations.length; i++) {559 const decl = rule. declarations[i];560 if (decl.prop erty=== 'src') {563 for (let i = 0; i < rule.nodes.length; i++) { 564 const decl = rule.nodes[i]; 565 if (decl.prop === 'src') { 561 566 // @todo parse this properly and generate multiple preloads with type="font/woff2" etc 562 567 src = (decl.value.match(/url\s*\(\s*(['"]?)(.+?)\1\s*\)/) || [])[2]; 563 } else if (decl.prop erty=== 'font-family') {568 } else if (decl.prop === 'font-family') { 564 569 family = decl.value; 565 570 } … … 590 595 sheet = serializeStylesheet(ast, { 591 596 compress: this.options.compress !== false 592 }) .trim();597 }); 593 598 594 599 // If all rules were removed, get rid of the style element entirely
Note:
See TracChangeset
for help on using the changeset viewer.