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:
141
node_modules/svgo/lib/parser.js
generated
vendored
141
node_modules/svgo/lib/parser.js
generated
vendored
@@ -1,29 +1,13 @@
|
||||
'use strict';
|
||||
import SAX from 'sax';
|
||||
import { textElems } from '../plugins/_collections.js';
|
||||
|
||||
/**
|
||||
* @typedef {import('./types').XastNode} XastNode
|
||||
* @typedef {import('./types').XastInstruction} XastInstruction
|
||||
* @typedef {import('./types').XastDoctype} XastDoctype
|
||||
* @typedef {import('./types').XastComment} XastComment
|
||||
* @typedef {import('./types').XastRoot} XastRoot
|
||||
* @typedef {import('./types').XastElement} XastElement
|
||||
* @typedef {import('./types').XastCdata} XastCdata
|
||||
* @typedef {import('./types').XastText} XastText
|
||||
* @typedef {import('./types').XastParent} XastParent
|
||||
*/
|
||||
|
||||
// @ts-ignore sax will be replaced with something else later
|
||||
const SAX = require('@trysound/sax');
|
||||
const JSAPI = require('./svgo/jsAPI.js');
|
||||
const { textElems } = require('../plugins/_collections.js');
|
||||
|
||||
class SvgoParserError extends Error {
|
||||
export class SvgoParserError extends Error {
|
||||
/**
|
||||
* @param message {string}
|
||||
* @param line {number}
|
||||
* @param column {number}
|
||||
* @param source {string}
|
||||
* @param file {void | string}
|
||||
* @param {string} message
|
||||
* @param {number} line
|
||||
* @param {number} column
|
||||
* @param {string} source
|
||||
* @param {string=} file
|
||||
*/
|
||||
constructor(message, line, column, source, file) {
|
||||
super(message);
|
||||
@@ -37,6 +21,7 @@ class SvgoParserError extends Error {
|
||||
Error.captureStackTrace(this, SvgoParserError);
|
||||
}
|
||||
}
|
||||
|
||||
toString() {
|
||||
const lines = this.source.split(/\r?\n/);
|
||||
const startLine = Math.max(this.line - 3, 0);
|
||||
@@ -82,44 +67,34 @@ const config = {
|
||||
lowercase: true,
|
||||
xmlns: true,
|
||||
position: true,
|
||||
unparsedEntities: true,
|
||||
};
|
||||
|
||||
/**
|
||||
* Convert SVG (XML) string to SVG-as-JS object.
|
||||
*
|
||||
* @type {(data: string, from?: string) => XastRoot}
|
||||
* @param {string} data
|
||||
* @param {string=} from
|
||||
* @returns {import('./types.js').XastRoot}
|
||||
*/
|
||||
const parseSvg = (data, from) => {
|
||||
export const parseSvg = (data, from) => {
|
||||
const sax = SAX.parser(config.strict, config);
|
||||
/**
|
||||
* @type {XastRoot}
|
||||
*/
|
||||
const root = new JSAPI({ type: 'root', children: [] });
|
||||
/**
|
||||
* @type {XastParent}
|
||||
*/
|
||||
/** @type {import('./types.js').XastRoot} */
|
||||
const root = { type: 'root', children: [] };
|
||||
/** @type {import('./types.js').XastParent} */
|
||||
let current = root;
|
||||
/**
|
||||
* @type {Array<XastParent>}
|
||||
*/
|
||||
/** @type {import('./types.js').XastParent[]} */
|
||||
const stack = [root];
|
||||
|
||||
/**
|
||||
* @type {<T extends XastNode>(node: T) => T}
|
||||
* @param {import('./types.js').XastChild} node
|
||||
*/
|
||||
const pushToContent = (node) => {
|
||||
const wrapped = new JSAPI(node, current);
|
||||
current.children.push(wrapped);
|
||||
return wrapped;
|
||||
current.children.push(node);
|
||||
};
|
||||
|
||||
/**
|
||||
* @type {(doctype: string) => void}
|
||||
*/
|
||||
sax.ondoctype = (doctype) => {
|
||||
/**
|
||||
* @type {XastDoctype}
|
||||
*/
|
||||
/** @type {import('./types.js').XastDoctype} */
|
||||
const node = {
|
||||
type: 'doctype',
|
||||
// TODO parse doctype for name, public and system to match xast
|
||||
@@ -140,13 +115,8 @@ const parseSvg = (data, from) => {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @type {(data: { name: string, body: string }) => void}
|
||||
*/
|
||||
sax.onprocessinginstruction = (data) => {
|
||||
/**
|
||||
* @type {XastInstruction}
|
||||
*/
|
||||
/** @type {import('./types.js').XastInstruction} */
|
||||
const node = {
|
||||
type: 'instruction',
|
||||
name: data.name,
|
||||
@@ -155,13 +125,8 @@ const parseSvg = (data, from) => {
|
||||
pushToContent(node);
|
||||
};
|
||||
|
||||
/**
|
||||
* @type {(comment: string) => void}
|
||||
*/
|
||||
sax.oncomment = (comment) => {
|
||||
/**
|
||||
* @type {XastComment}
|
||||
*/
|
||||
/** @type {import('./types.js').XastComment} */
|
||||
const node = {
|
||||
type: 'comment',
|
||||
value: comment.trim(),
|
||||
@@ -169,13 +134,8 @@ const parseSvg = (data, from) => {
|
||||
pushToContent(node);
|
||||
};
|
||||
|
||||
/**
|
||||
* @type {(cdata: string) => void}
|
||||
*/
|
||||
sax.oncdata = (cdata) => {
|
||||
/**
|
||||
* @type {XastCdata}
|
||||
*/
|
||||
/** @type {import('./types.js').XastCdata} */
|
||||
const node = {
|
||||
type: 'cdata',
|
||||
value: cdata,
|
||||
@@ -183,14 +143,9 @@ const parseSvg = (data, from) => {
|
||||
pushToContent(node);
|
||||
};
|
||||
|
||||
/**
|
||||
* @type {(data: { name: string, attributes: Record<string, { value: string }>}) => void}
|
||||
*/
|
||||
sax.onopentag = (data) => {
|
||||
/**
|
||||
* @type {XastElement}
|
||||
*/
|
||||
let element = {
|
||||
/** @type {import('./types.js').XastElement} */
|
||||
const element = {
|
||||
type: 'element',
|
||||
name: data.name,
|
||||
attributes: {},
|
||||
@@ -199,35 +154,32 @@ const parseSvg = (data, from) => {
|
||||
for (const [name, attr] of Object.entries(data.attributes)) {
|
||||
element.attributes[name] = attr.value;
|
||||
}
|
||||
element = pushToContent(element);
|
||||
pushToContent(element);
|
||||
current = element;
|
||||
stack.push(element);
|
||||
};
|
||||
|
||||
/**
|
||||
* @type {(text: string) => void}
|
||||
*/
|
||||
sax.ontext = (text) => {
|
||||
if (current.type === 'element') {
|
||||
// prevent trimming of meaningful whitespace inside textual tags
|
||||
if (textElems.includes(current.name)) {
|
||||
/**
|
||||
* @type {XastText}
|
||||
*/
|
||||
if (textElems.has(current.name)) {
|
||||
/** @type {import('./types.js').XastText} */
|
||||
const node = {
|
||||
type: 'text',
|
||||
value: text,
|
||||
};
|
||||
pushToContent(node);
|
||||
} else if (/\S/.test(text)) {
|
||||
/**
|
||||
* @type {XastText}
|
||||
*/
|
||||
const node = {
|
||||
type: 'text',
|
||||
value: text.trim(),
|
||||
};
|
||||
pushToContent(node);
|
||||
} else {
|
||||
const value = text.trim();
|
||||
|
||||
if (value !== '') {
|
||||
/** @type {import('./types.js').XastText} */
|
||||
const node = {
|
||||
type: 'text',
|
||||
value,
|
||||
};
|
||||
pushToContent(node);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -237,16 +189,14 @@ const parseSvg = (data, from) => {
|
||||
current = stack[stack.length - 1];
|
||||
};
|
||||
|
||||
/**
|
||||
* @type {(e: any) => void}
|
||||
*/
|
||||
sax.onerror = (e) => {
|
||||
const reason = e.message.split('\n')[0];
|
||||
const error = new SvgoParserError(
|
||||
e.reason,
|
||||
e.line + 1,
|
||||
e.column,
|
||||
reason,
|
||||
sax.line + 1,
|
||||
sax.column,
|
||||
data,
|
||||
from
|
||||
from,
|
||||
);
|
||||
if (e.message.indexOf('Unexpected end') === -1) {
|
||||
throw error;
|
||||
@@ -256,4 +206,3 @@ const parseSvg = (data, from) => {
|
||||
sax.write(data).close();
|
||||
return root;
|
||||
};
|
||||
exports.parseSvg = parseSvg;
|
||||
|
||||
Reference in New Issue
Block a user