Fix code quality violations and exclude Manifest from checks

Document application modes (development/debug/production)
Add global file drop handler, order column normalization, SPA hash fix
Serve CDN assets via /_vendor/ URLs instead of merging into bundles
Add production minification with license preservation
Improve JSON formatting for debugging and production optimization
Add CDN asset caching with CSS URL inlining for production builds
Add three-mode system (development, debug, production)
Update Manifest CLAUDE.md to reflect helper class architecture
Refactor Manifest.php into helper classes for better organization
Pre-manifest-refactor checkpoint: Add app_mode documentation

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
root
2026-01-14 10:38:22 +00:00
parent bb9046af1b
commit d523f0f600
2355 changed files with 231384 additions and 32223 deletions

View File

@@ -1,37 +1,63 @@
'use strict';
import * as csso from 'csso';
import { detachNodeFromParent } from '../lib/xast.js';
import { hasScripts } from '../lib/svgo/tools.js';
/**
* @typedef {import('../lib/types').XastElement} XastElement
* @typedef Usage
* @property {boolean=} force
* @property {boolean=} ids
* @property {boolean=} classes
* @property {boolean=} tags
*
* @typedef MinifyStylesParams
* @property {boolean=} restructure Disable or enable a structure optimizations.
* @property {boolean=} forceMediaMerge
* Enables merging of `@media` rules with the same media query split by other
* rules. Unsafe in general, but should work fine in most cases. Use it on
* your own risk.
* @property {'exclamation' | 'first-exclamation' | boolean=} comments
* Specify what comments to leave:
* - `'exclamation'` or `true` — leave all exclamation comments
* - `'first-exclamation'` — remove every comment except first one
* - `false` — remove all comments
* @property {boolean | Usage=} usage Advanced optimizations.
*/
const csso = require('csso');
exports.type = 'visitor';
exports.name = 'minifyStyles';
exports.active = true;
exports.description =
'minifies styles and removes unused styles based on usage data';
export const name = 'minifyStyles';
export const description = 'minifies styles and removes unused styles';
/**
* Minifies styles (<style> element + style attribute) using CSSO
* Minifies styles (<style> element + style attribute) using CSSO.
*
* @author strarsis <strarsis@gmail.com>
*
* @type {import('../lib/types').Plugin<csso.MinifyOptions & Omit<csso.CompressOptions, 'usage'> & {
* usage?: boolean | {
* force?: boolean,
* ids?: boolean,
* classes?: boolean,
* tags?: boolean
* }
* }>}
* @type {import('../lib/types.js').Plugin<MinifyStylesParams>}
*/
exports.fn = (_root, { usage, ...params }) => {
export const fn = (_root, { usage, ...params }) => {
/** @type {Map<import('../lib/types.js').XastElement, import('../lib/types.js').XastParent>} */
const styleElements = new Map();
/** @type {import('../lib/types.js').XastElement[]} */
const elementsWithStyleAttributes = [];
/** @type {Set<string>} */
const tagsUsage = new Set();
/** @type {Set<string>} */
const idsUsage = new Set();
/** @type {Set<string>} */
const classesUsage = new Set();
let enableTagsUsage = true;
let enableIdsUsage = true;
let enableClassesUsage = true;
// force to use usage data even if it unsafe (document contains <script> or on* attributes)
/**
* Force to use usage data even if it unsafe. For example, the document
* contains scripts or in attributes.
*/
let forceUsageDeoptimized = false;
if (typeof usage === 'boolean') {
enableTagsUsage = usage;
enableIdsUsage = usage;
@@ -42,40 +68,17 @@ exports.fn = (_root, { usage, ...params }) => {
enableClassesUsage = usage.classes == null ? true : usage.classes;
forceUsageDeoptimized = usage.force == null ? false : usage.force;
}
/**
* @type {Array<XastElement>}
*/
const styleElements = [];
/**
* @type {Array<XastElement>}
*/
const elementsWithStyleAttributes = [];
let deoptimized = false;
/**
* @type {Set<string>}
*/
const tagsUsage = new Set();
/**
* @type {Set<string>}
*/
const idsUsage = new Set();
/**
* @type {Set<string>}
*/
const classesUsage = new Set();
return {
element: {
enter: (node) => {
// detect deoptimisations
if (node.name === 'script') {
enter: (node, parentNode) => {
// detect deoptimizations
if (hasScripts(node)) {
deoptimized = true;
}
for (const name of Object.keys(node.attributes)) {
if (name.startsWith('on')) {
deoptimized = true;
}
}
// collect tags, ids and classes usage
tagsUsage.add(node.name);
if (node.attributes.id != null) {
@@ -88,7 +91,7 @@ exports.fn = (_root, { usage, ...params }) => {
}
// collect style elements or elements with style attribute
if (node.name === 'style' && node.children.length !== 0) {
styleElements.push(node);
styleElements.set(node, parentNode);
} else if (node.attributes.style != null) {
elementsWithStyleAttributes.push(node);
}
@@ -97,40 +100,44 @@ exports.fn = (_root, { usage, ...params }) => {
root: {
exit: () => {
/**
* @type {csso.Usage}
*/
/** @type {csso.Usage} */
const cssoUsage = {};
if (deoptimized === false || forceUsageDeoptimized === true) {
if (enableTagsUsage && tagsUsage.size !== 0) {
if (!deoptimized || forceUsageDeoptimized) {
if (enableTagsUsage) {
cssoUsage.tags = Array.from(tagsUsage);
}
if (enableIdsUsage && idsUsage.size !== 0) {
if (enableIdsUsage) {
cssoUsage.ids = Array.from(idsUsage);
}
if (enableClassesUsage && classesUsage.size !== 0) {
if (enableClassesUsage) {
cssoUsage.classes = Array.from(classesUsage);
}
}
// minify style elements
for (const node of styleElements) {
for (const [styleNode, styleNodeParent] of styleElements.entries()) {
if (
node.children[0].type === 'text' ||
node.children[0].type === 'cdata'
styleNode.children[0].type === 'text' ||
styleNode.children[0].type === 'cdata'
) {
const cssText = node.children[0].value;
const cssText = styleNode.children[0].value;
const minified = csso.minify(cssText, {
...params,
usage: cssoUsage,
}).css;
if (minified.length === 0) {
detachNodeFromParent(styleNode, styleNodeParent);
continue;
}
// preserve cdata if necessary
// TODO split cdata -> text optimisation into separate plugin
// TODO split cdata -> text optimization into separate plugin
if (cssText.indexOf('>') >= 0 || cssText.indexOf('<') >= 0) {
node.children[0].type = 'cdata';
node.children[0].value = minified;
styleNode.children[0].type = 'cdata';
styleNode.children[0].value = minified;
} else {
node.children[0].type = 'text';
node.children[0].value = minified;
styleNode.children[0].type = 'text';
styleNode.children[0].value = minified;
}
}
}