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/penthouse/lib/postformatting/ |
Upload File : |
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = unusedFontfaceRemover; var _cssTree = require('css-tree'); var _cssTree2 = _interopRequireDefault(_cssTree); var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } const debuglog = (0, _debug2.default)('penthouse:css-cleanup:unused-font-face-remover'); function decodeFontName(node) { let name = _cssTree2.default.generate(node); // TODO: use string decode if (name[0] === '"' || name[0] === "'") { name = name.substr(1, name.length - 2); } return name; } function getAllFontNameValues(ast) { const fontNameValues = new Set(); debuglog('getAllFontNameValues'); _cssTree2.default.walk(ast, { visit: 'Declaration', enter: function (node) { // walker pass through `font-family` declarations inside @font-face too // this condition filters them, to walk through declarations inside a rules only if (this.rule) { _cssTree2.default.lexer.findDeclarationValueFragments(node, 'Type', 'family-name').forEach(entry => { const familyName = decodeFontName({ type: 'Value', children: entry.nodes }); if (!fontNameValues.has(familyName)) { debuglog('found used font-family: ' + familyName); fontNameValues.add(familyName); } }); } } }); debuglog('getAllFontNameValues AFTER'); return fontNameValues; } function unusedFontfaceRemover(ast) { const fontNameValues = getAllFontNameValues(ast); // remove @font-face at-rule when: // - it's never unused // - has no a `src` descriptor _cssTree2.default.walk(ast, { visit: 'Atrule', enter: (atrule, atruleItem, atruleList) => { if (_cssTree2.default.keyword(atrule.name).basename !== 'font-face') { return; } let hasSrc = false; let used = true; _cssTree2.default.walk(atrule, { visit: 'Declaration', enter: declaration => { const name = _cssTree2.default.property(declaration.property).name; if (name === 'font-family') { const familyName = decodeFontName(declaration.value); // was this @font-face used? if (!fontNameValues.has(familyName)) { debuglog('drop unused @font-face: ' + familyName); used = false; } } else if (name === 'src') { hasSrc = true; } } }); if (!used || !hasSrc) { if (used && !hasSrc) { debuglog('drop @font-face with no src descriptor'); } atruleList.remove(atruleItem); } } }); }