Server IP : 108.163.255.210 / Your IP : 3.145.41.108 Web Server : Apache System : Linux blossom.urlnameserver.com 3.10.0-1160.80.1.el7.x86_64 #1 SMP Tue Nov 8 15:48:59 UTC 2022 x86_64 User : ( 1172) PHP Version : 7.2.34 Disable Function : eval,escapeshellarg,proc_close,proc_get_status,proc_nice,proc_open,symlink,system,pcntl_exec,getrusage,chown,chgp,closelog,openlog,syslog,define_syslog_variables,php_ini_loaded_file,getservbyname,getservbyport,posix_getgid,posix_getgrgid,proc_terminate,pfsockopen,apache_child_terminate,posix_mkfifo,posix_setpgid,posix_setuid,hypot,pg_host,pos,posix_access,posix_getcwd,posix_getservbyname,myshellexec,getpid,posix_getsid,posix_isatty,posix_kill,posix_mknod,posix_setgid,posix_setsid,posix_setuid,posix_times,posix_uname,ps_fill,posix_getpwuid,global,ini_restore,zip_open,zip_read,rar_open,bzopen,bzread,bzwrite,apache_get_modules,apache_get_version,phpversionphpinfo,php_ini_scanned_files,get_current_user,disk_total_space,diskfreespace,leak,imap_list,hypo,filedump,safe_mode,getmygid,apache_getenv,apache_setenv,bzread,bzwrite,bzopen,phpini,higlight_file,dos_conv,get_cwd,er_log,cmd,e_name,vdir,get_dir,only_read,ftok,ftpexec,posix_getpwnam,mysql_list_dbs,disk_free_space,session_save_path,confirm_phpdoc_compiled,zip_entry_rea,php_u,psockopen,crack_opendict,crack_getlastmessage,crack_closedict,crack_check,fpassthru,posix_get_last_error,posix_getlogin,posix_getgroups,posix_strerror,posix_getrlimit,posix_getpgrp,posix_getgrnam,pos,dl MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /home/unilinki/public_html/indijourneys.com/node_modules/svgo/plugins/ |
Upload File : |
'use strict'; exports.type = 'full'; exports.active = true; exports.description = 'minifies styles and removes unused styles based on usage data'; exports.params = { // ... CSSO options goes here // additional usage: { force: false, // force to use usage data even if it unsafe (document contains <script> or on* attributes) ids: true, classes: true, tags: true } }; var csso = require('csso'); /** * Minifies styles (<style> element + style attribute) using CSSO * * @author strarsis <strarsis@gmail.com> */ exports.fn = function(ast, options) { options = options || {}; var minifyOptionsForStylesheet = cloneObject(options); var minifyOptionsForAttribute = cloneObject(options); var elems = findStyleElems(ast); minifyOptionsForStylesheet.usage = collectUsageData(ast, options); minifyOptionsForAttribute.usage = null; elems.forEach(function(elem) { if (elem.isElem('style')) { // <style> element var styleCss = elem.content[0].text || elem.content[0].cdata || []; var DATA = styleCss.indexOf('>') >= 0 || styleCss.indexOf('<') >= 0 ? 'cdata' : 'text'; elem.content[0][DATA] = csso.minify(styleCss, minifyOptionsForStylesheet).css; } else { // style attribute var elemStyle = elem.attr('style').value; elem.attr('style').value = csso.minifyBlock(elemStyle, minifyOptionsForAttribute).css; } }); return ast; }; function cloneObject(obj) { var result = {}; for (var key in obj) { result[key] = obj[key]; } return result; } function findStyleElems(ast) { function walk(items, styles) { for (var i = 0; i < items.content.length; i++) { var item = items.content[i]; // go deeper if (item.content) { walk(item, styles); } if (item.isElem('style') && !item.isEmpty()) { styles.push(item); } else if (item.isElem() && item.hasAttr('style')) { styles.push(item); } } return styles; } return walk(ast, []); } function shouldFilter(options, name) { if ('usage' in options === false) { return true; } if (options.usage && name in options.usage === false) { return true; } return Boolean(options.usage && options.usage[name]); } function collectUsageData(ast, options) { function walk(items, usageData) { for (var i = 0; i < items.content.length; i++) { var item = items.content[i]; // go deeper if (item.content) { walk(item, usageData); } if (item.isElem('script')) { safe = false; } if (item.isElem()) { usageData.tags[item.elem] = true; if (item.hasAttr('id')) { usageData.ids[item.attr('id').value] = true; } if (item.hasAttr('class')) { item.attr('class').value.replace(/^\s+|\s+$/g, '').split(/\s+/).forEach(function(className) { usageData.classes[className] = true; }); } if (item.attrs && Object.keys(item.attrs).some(function(name) { return /^on/i.test(name); })) { safe = false; } } } return usageData; } var safe = true; var usageData = {}; var hasData = false; var rawData = walk(ast, { ids: Object.create(null), classes: Object.create(null), tags: Object.create(null) }); if (!safe && options.usage && options.usage.force) { safe = true; } for (var key in rawData) { if (shouldFilter(options, key)) { usageData[key] = Object.keys(rawData[key]); hasData = true; } } return safe && hasData ? usageData : null; }