Ignore:
Timestamp:
11/25/21 22:08:24 (3 years ago)
Author:
Ema <ema_spirova@…>
Branches:
master
Children:
8d391a1
Parents:
59329aa
Message:

primeNG components

Location:
trip-planner-front/node_modules/critters/src
Files:
5 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • trip-planner-front/node_modules/critters/src/css.js

    r59329aa re29cc2e  
    1515 */
    1616
    17 import css from 'css';
     17import { parse, stringify } from 'postcss';
    1818
    1919/**
    2020 * Parse a textual CSS Stylesheet into a Stylesheet instance.
    21  * Stylesheet is a mutable ReworkCSS AST with format similar to CSSOM.
    22  * @see https://github.com/reworkcss/css
     21 * Stylesheet is a mutable postcss AST with format similar to CSSOM.
     22 * @see https://github.com/postcss/postcss/
    2323 * @private
    2424 * @param {String} stylesheet
    2525 * @returns {css.Stylesheet} ast
    2626 */
    27 export function parseStylesheet (stylesheet) {
    28   return css.parse(stylesheet);
     27export function parseStylesheet(stylesheet) {
     28  return parse(stylesheet);
    2929}
    3030
    3131/**
    32  * Serialize a ReworkCSS Stylesheet to a String of CSS.
     32 * Serialize a postcss Stylesheet to a String of CSS.
    3333 * @private
    3434 * @param {css.Stylesheet} ast          A Stylesheet to serialize, such as one returned from `parseStylesheet()`
    35  * @param {Object} options              Options to pass to `css.stringify()`
     35 * @param {Object} options              Options used by the stringify logic
    3636 * @param {Boolean} [options.compress]  Compress CSS output (removes comments, whitespace, etc)
    3737 */
    38 export function serializeStylesheet (ast, options) {
    39   return css.stringify(ast, options);
     38export function serializeStylesheet(ast, options) {
     39  let cssStr = '';
     40
     41  stringify(ast, (result, node, type) => {
     42    if (!options.compress) {
     43      cssStr += result;
     44      return;
     45    }
     46
     47    // Simple minification logic
     48    if (node?.type === 'comment') return;
     49
     50    if (node?.type === 'decl') {
     51      const prefix = node.prop + node.raws.between;
     52
     53      cssStr += result.replace(prefix, prefix.trim());
     54      return;
     55    }
     56
     57    if (type === 'start') {
     58      if (node.type === 'rule' && node.selectors) {
     59        cssStr += node.selectors.join(',') + '{';
     60      } else {
     61        cssStr += result.replace(/\s\{$/, '{');
     62      }
     63      return;
     64    }
     65
     66    if (type === 'end' && result === '}' && node?.raws?.semicolon) {
     67      cssStr = cssStr.slice(0, -1);
     68    }
     69
     70    cssStr += result.trim();
     71  });
     72
     73  return cssStr;
    4074}
    4175
     
    4781 * @returns {(rule) => void} nonDestructiveIterator
    4882 */
    49 export function markOnly (predicate) {
    50   return rule => {
     83export function markOnly(predicate) {
     84  return (rule) => {
    5185    const sel = rule.selectors;
    5286    if (predicate(rule) === false) {
     
    6599 * @private
    66100 * @param {css.Rule} rule The Rule to apply marked selectors to (if they exist).
    67 */
    68 export function applyMarkedSelectors (rule) {
     101 */
     102export function applyMarkedSelectors(rule) {
    69103  if (rule.$$markedSelectors) {
    70104    rule.selectors = rule.$$markedSelectors;
     
    81115 * @param {Function} iterator   Invoked on each node in the tree. Return `false` to remove that node.
    82116 */
    83 export function walkStyleRules (node, iterator) {
    84   if (node.stylesheet) return walkStyleRules(node.stylesheet, iterator);
    85 
    86   node.rules = node.rules.filter(rule => {
    87     if (rule.rules) {
     117export function walkStyleRules(node, iterator) {
     118  node.nodes = node.nodes.filter((rule) => {
     119    if (hasNestedRules(rule)) {
    88120      walkStyleRules(rule, iterator);
    89121    }
     
    101133 * @param {Function} iterator   Invoked on each node in the tree. Return `false` to remove that node from the first tree, true to remove it from the second.
    102134 */
    103 export function walkStyleRulesWithReverseMirror (node, node2, iterator) {
     135export function walkStyleRulesWithReverseMirror(node, node2, iterator) {
    104136  if (node2 === null) return walkStyleRules(node, iterator);
    105137
    106   if (node.stylesheet) return walkStyleRulesWithReverseMirror(node.stylesheet, node2.stylesheet, iterator);
     138  [node.nodes, node2.nodes] = splitFilter(
     139    node.nodes,
     140    node2.nodes,
     141    (rule, index, rules, rules2) => {
     142      const rule2 = rules2[index];
     143      if (hasNestedRules(rule)) {
     144        walkStyleRulesWithReverseMirror(rule, rule2, iterator);
     145      }
     146      rule._other = rule2;
     147      rule.filterSelectors = filterSelectors;
     148      return iterator(rule) !== false;
     149    }
     150  );
     151}
    107152
    108   [node.rules, node2.rules] = splitFilter(node.rules, node2.rules, (rule, index, rules, rules2) => {
    109     const rule2 = rules2[index];
    110     if (rule.rules) {
    111       walkStyleRulesWithReverseMirror(rule, rule2, iterator);
    112     }
    113     rule._other = rule2;
    114     rule.filterSelectors = filterSelectors;
    115     return iterator(rule) !== false;
    116   });
     153// Checks if a node has nested rules, like @media
     154// @keyframes are an exception since they are evaluated as a whole
     155function hasNestedRules(rule) {
     156  return (
     157    rule.nodes &&
     158    rule.nodes.length &&
     159    rule.nodes.some((n) => n.type === 'rule' || n.type === 'atrule') &&
     160    rule.name !== 'keyframes'
     161  );
    117162}
    118163
    119164// Like [].filter(), but applies the opposite filtering result to a second copy of the Array without a second pass.
    120165// This is just a quicker version of generating the compliment of the set returned from a filter operation.
    121 function splitFilter (a, b, predicate) {
     166function splitFilter(a, b, predicate) {
    122167  const aOut = [];
    123168  const bOut = [];
     
    133178
    134179// can be invoked on a style rule to subset its selectors (with reverse mirroring)
    135 function filterSelectors (predicate) {
     180function filterSelectors(predicate) {
    136181  if (this._other) {
    137     const [a, b] = splitFilter(this.selectors, this._other.selectors, predicate);
     182    const [a, b] = splitFilter(
     183      this.selectors,
     184      this._other.selectors,
     185      predicate
     186    );
    138187    this.selectors = a;
    139188    this._other.selectors = b;
  • trip-planner-front/node_modules/critters/src/dom.js

    r59329aa re29cc2e  
    1616
    1717import parse5 from 'parse5';
    18 import select from 'css-select';
     18import { selectAll, selectOne } from 'css-select';
     19import treeAdapter from 'parse5-htmlparser2-tree-adapter';
    1920
    2021// htmlparser2 has a relatively DOM-like tree format, which we'll massage into a DOM elsewhere
    21 const treeAdapter = require('parse5-htmlparser2-tree-adapter');
    22 
    2322const PARSE5_OPTS = {
    2423  treeAdapter
     
    3130 */
    3231export function createDocument(html) {
    33   const document = parse5.parse(html, PARSE5_OPTS);
     32  const document = /** @type {HTMLDocument} */ (
     33    parse5.parse(html, PARSE5_OPTS)
     34  );
    3435
    3536  defineProperties(document, DocumentExtensions);
     
    4849/**
    4950 * Serialize a Document to an HTML String
    50  * @param {Document} document   A Document, such as one created via `createDocument()`
     51 * @param {HTMLDocument} document   A Document, such as one created via `createDocument()`
    5152 */
    5253export function serializeDocument(document) {
     
    5455}
    5556
     57/** @typedef {treeAdapter.Document & typeof ElementExtensions} HTMLDocument */
     58
    5659/**
    5760 * Methods and descriptors to mix into Element.prototype
     61 * @private
    5862 */
    5963const ElementExtensions = {
    60   /** @extends htmlparser2.Element.prototype */
     64  /** @extends treeAdapter.Element.prototype */
    6165
    6266  nodeName: {
     
    131135 */
    132136const DocumentExtensions = {
    133   /** @extends htmlparser2.Document.prototype */
     137  /** @extends treeAdapter.Document.prototype */
    134138
    135139  // document is just an Element in htmlparser2, giving it a nodeType of ELEMENT_NODE.
     
    196200
    197201  querySelector(sel) {
    198     return select.selectOne(sel, this.documentElement);
     202    return selectOne(sel, this.documentElement);
    199203  },
    200204
     
    203207      return this;
    204208    }
    205     return select(sel, this.documentElement);
     209    return selectAll(sel, this.documentElement);
    206210  }
    207211};
  • trip-planner-front/node_modules/critters/src/index.d.ts

    r59329aa re29cc2e  
    1515 */
    1616
    17 declare module 'critters' {
    18   export interface Options {
    19     path?: string;
    20     publicPath?: string;
    21     external?: boolean;
    22     inlineThreshold?: number;
    23     minimumExternalSize?: number;
    24     pruneSource?: boolean;
    25     mergeStylesheets?: boolean;
    26     additionalStylesheets?: string[];
    27     preload?: 'body' | 'media' | 'swap' | 'js' | 'js-lazy';
    28     noscriptFallback?: boolean;
    29     inlineFonts?: boolean;
    30     preloadFonts?: boolean;
    31     fonts?: boolean;
    32     keyframes?: string;
    33     compress?: boolean;
    34     logLevel?: 'info' | 'warn' | 'error' | 'trace' | 'debug' | 'silent';
    35     reduceInlineStyles?: boolean;
    36     logger?: Logger;
    37   }
     17export default class Critters {
     18  /**
     19   * Create an instance of Critters with custom options.
     20   * The `.process()` method can be called repeatedly to re-use this instance and its cache.
     21   */
     22  constructor(options: Options);
     23  /**
     24   * Process an HTML document to inline critical CSS from its stylesheets.
     25   * @param {string} html String containing a full HTML document to be parsed.
     26   * @returns {string} A modified copy of the provided HTML with critical CSS inlined.
     27   */
     28  process(html: string): Promise<string>;
     29  /**
     30   * Read the contents of a file from the specified filesystem or disk.
     31   * Override this method to customize how stylesheets are loaded.
     32   */
     33  readFile(filename: string): Promise<string> | string;
     34  /**
     35   * Given a stylesheet URL, returns the corresponding CSS asset.
     36   * Overriding this method requires doing your own URL normalization, so it's generally better to override `readFile()`.
     37   */
     38  getCssAsset(href: string): Promise<string | undefined> | string | undefined;
     39}
    3840
    39   export interface Logger {
    40     trace?: (message: string) => void;
    41     debug?: (message: string) => void;
    42     info?: (message: string) => void;
    43     warn?: (message: string) => void;
    44     error?: (message: string) => void;
    45   }
     41export interface Options {
     42  path?: string;
     43  publicPath?: string;
     44  external?: boolean;
     45  inlineThreshold?: number;
     46  minimumExternalSize?: number;
     47  pruneSource?: boolean;
     48  mergeStylesheets?: boolean;
     49  additionalStylesheets?: string[];
     50  preload?: 'body' | 'media' | 'swap' | 'js' | 'js-lazy';
     51  noscriptFallback?: boolean;
     52  inlineFonts?: boolean;
     53  preloadFonts?: boolean;
     54  fonts?: boolean;
     55  keyframes?: string;
     56  compress?: boolean;
     57  logLevel?: 'info' | 'warn' | 'error' | 'trace' | 'debug' | 'silent';
     58  reduceInlineStyles?: boolean;
     59  logger?: Logger;
     60}
    4661
    47   class Critters {
    48     constructor(options: Options);
    49     process(html: string): Promise<string>;
    50   }
    51 
    52   export default Critters;
     62export interface Logger {
     63  trace?: (message: string) => void;
     64  debug?: (message: string) => void;
     65  info?: (message: string) => void;
     66  warn?: (message: string) => void;
     67  error?: (message: string) => void;
    5368}
  • trip-planner-front/node_modules/critters/src/index.js

    r59329aa re29cc2e  
    3030/**
    3131 * The mechanism to use for lazy-loading stylesheets.
     32 *
    3233 * Note: <kbd>JS</kbd> indicates a strategy requiring JavaScript (falls back to `<noscript>` unless disabled).
    3334 *
     
    242243        .replace(/^\//, '');
    243244    }
     245
     246    // Ignore remote stylesheets
     247    if (/^https:\/\//.test(normalizedPath) || href.startsWith('//')) {
     248      return undefined;
     249    }
     250
    244251    const filename = path.resolve(outputPath, normalizedPath);
    245252
     
    484491            }
    485492          });
     493
    486494          // If there are no matched selectors, remove the rule:
    487           if (rule.selectors.length === 0) {
     495          if (!rule.selector) {
    488496            return false;
    489497          }
    490498
    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];
    494502
    495503              // detect used fonts
    496               if (decl.property && decl.property.match(/\bfont(-family)?\b/i)) {
     504              if (decl.prop && decl.prop.match(/\bfont(-family)?\b/i)) {
    497505                criticalFonts += ' ' + decl.value;
    498506              }
    499507
    500508              // detect used keyframes
    501               if (
    502                 decl.property === 'animation' ||
    503                 decl.property === 'animation-name'
    504               ) {
     509              if (decl.prop === 'animation' || decl.prop === 'animation-name') {
    505510                // @todo: parse animation declarations and extract only the name. for now we'll do a lazy match.
    506511                const names = decl.value.split(/\s+/);
     
    515520
    516521        // 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;
    518523
    519524        // 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);
    521526        return !rules || rules.length !== 0;
    522527      })
     
    547552
    548553      // prune @keyframes rules
    549       if (rule.type === 'keyframes') {
     554      if (rule.type === 'atrule' && rule.name === 'keyframes') {
    550555        if (keyframesMode === 'none') return false;
    551556        if (keyframesMode === 'all') return true;
    552         return criticalKeyframeNames.indexOf(rule.name) !== -1;
     557        return criticalKeyframeNames.indexOf(rule.params) !== -1;
    553558      }
    554559
    555560      // prune @font-face rules
    556       if (rule.type === 'font-face') {
     561      if (rule.type === 'atrule' && rule.name === 'font-face') {
    557562        let family, src;
    558         for (let i = 0; i < rule.declarations.length; i++) {
    559           const decl = rule.declarations[i];
    560           if (decl.property === 'src') {
     563        for (let i = 0; i < rule.nodes.length; i++) {
     564          const decl = rule.nodes[i];
     565          if (decl.prop === 'src') {
    561566            // @todo parse this properly and generate multiple preloads with type="font/woff2" etc
    562567            src = (decl.value.match(/url\s*\(\s*(['"]?)(.+?)\1\s*\)/) || [])[2];
    563           } else if (decl.property === 'font-family') {
     568          } else if (decl.prop === 'font-family') {
    564569            family = decl.value;
    565570          }
     
    590595    sheet = serializeStylesheet(ast, {
    591596      compress: this.options.compress !== false
    592     }).trim();
     597    });
    593598
    594599    // If all rules were removed, get rid of the style element entirely
Note: See TracChangeset for help on using the changeset viewer.