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>
56 lines
1.7 KiB
JavaScript
Executable File
56 lines
1.7 KiB
JavaScript
Executable File
export const name = 'removeUnusedNS';
|
|
export const description = 'removes unused namespaces declaration';
|
|
|
|
/**
|
|
* Remove unused namespaces declaration from svg element
|
|
* which are not used in elements or attributes
|
|
*
|
|
* @author Kir Belevich
|
|
*
|
|
* @type {import('../lib/types.js').Plugin}
|
|
*/
|
|
export const fn = () => {
|
|
/** @type {Set<string>} */
|
|
const unusedNamespaces = new Set();
|
|
return {
|
|
element: {
|
|
enter: (node, parentNode) => {
|
|
// collect all namespaces from svg element
|
|
// (such as xmlns:xlink="http://www.w3.org/1999/xlink")
|
|
if (node.name === 'svg' && parentNode.type === 'root') {
|
|
for (const name of Object.keys(node.attributes)) {
|
|
if (name.startsWith('xmlns:')) {
|
|
const local = name.slice('xmlns:'.length);
|
|
unusedNamespaces.add(local);
|
|
}
|
|
}
|
|
}
|
|
if (unusedNamespaces.size !== 0) {
|
|
// preserve namespace used in nested elements names
|
|
if (node.name.includes(':')) {
|
|
const [ns] = node.name.split(':');
|
|
if (unusedNamespaces.has(ns)) {
|
|
unusedNamespaces.delete(ns);
|
|
}
|
|
}
|
|
// preserve namespace used in nested elements attributes
|
|
for (const name of Object.keys(node.attributes)) {
|
|
if (name.includes(':')) {
|
|
const [ns] = name.split(':');
|
|
unusedNamespaces.delete(ns);
|
|
}
|
|
}
|
|
}
|
|
},
|
|
exit: (node, parentNode) => {
|
|
// remove unused namespace attributes from svg element
|
|
if (node.name === 'svg' && parentNode.type === 'root') {
|
|
for (const name of unusedNamespaces) {
|
|
delete node.attributes[`xmlns:${name}`];
|
|
}
|
|
}
|
|
},
|
|
},
|
|
};
|
|
};
|