Changing front

This commit is contained in:
2023-01-16 17:44:37 +01:00
parent 0b8a93b256
commit 4fe4be7730
48586 changed files with 4725790 additions and 17464 deletions

View File

@@ -0,0 +1,11 @@
'use strict';
const { Writable } = require('stream');
class DevNullStream extends Writable {
_write(chunk, encoding, cb) {
cb();
}
}
module.exports = DevNullStream;

166
front/app/node_modules/parse5-sax-parser/lib/index.js generated vendored Normal file
View File

@@ -0,0 +1,166 @@
'use strict';
const { Transform } = require('stream');
const Tokenizer = require('parse5/lib/tokenizer');
const LocationInfoTokenizerMixin = require('parse5/lib/extensions/location-info/tokenizer-mixin');
const Mixin = require('parse5/lib/utils/mixin');
const mergeOptions = require('parse5/lib/utils/merge-options');
const DevNullStream = require('./dev-null-stream');
const ParserFeedbackSimulator = require('./parser-feedback-simulator');
const DEFAULT_OPTIONS = {
sourceCodeLocationInfo: false
};
class SAXParser extends Transform {
constructor(options) {
super({ encoding: 'utf8', decodeStrings: false });
this.options = mergeOptions(DEFAULT_OPTIONS, options);
this.tokenizer = new Tokenizer(options);
this.locInfoMixin = null;
if (this.options.sourceCodeLocationInfo) {
this.locInfoMixin = Mixin.install(this.tokenizer, LocationInfoTokenizerMixin);
}
this.parserFeedbackSimulator = new ParserFeedbackSimulator(this.tokenizer);
this.pendingText = null;
this.lastChunkWritten = false;
this.stopped = false;
// NOTE: always pipe stream to the /dev/null stream to avoid
// `highWaterMark` hit even if we don't have consumers.
// (see: https://github.com/inikulin/parse5/issues/97#issuecomment-171940774)
this.pipe(new DevNullStream());
}
//TransformStream implementation
_transform(chunk, encoding, callback) {
if (typeof chunk !== 'string') {
throw new TypeError('Parser can work only with string streams.');
}
callback(null, this._transformChunk(chunk));
}
_final(callback) {
this.lastChunkWritten = true;
callback(null, this._transformChunk(''));
}
stop() {
this.stopped = true;
}
//Internals
_transformChunk(chunk) {
if (!this.stopped) {
this.tokenizer.write(chunk, this.lastChunkWritten);
this._runParsingLoop();
}
return chunk;
}
_runParsingLoop() {
let token = null;
do {
token = this.parserFeedbackSimulator.getNextToken();
if (token.type === Tokenizer.HIBERNATION_TOKEN) {
break;
}
if (
token.type === Tokenizer.CHARACTER_TOKEN ||
token.type === Tokenizer.WHITESPACE_CHARACTER_TOKEN ||
token.type === Tokenizer.NULL_CHARACTER_TOKEN
) {
if (this.pendingText === null) {
token.type = Tokenizer.CHARACTER_TOKEN;
this.pendingText = token;
} else {
this.pendingText.chars += token.chars;
if (this.options.sourceCodeLocationInfo) {
const { endLine, endCol, endOffset } = token.location;
Object.assign(this.pendingText.location, {
endLine,
endCol,
endOffset
});
}
}
} else {
this._emitPendingText();
this._handleToken(token);
}
} while (!this.stopped && token.type !== Tokenizer.EOF_TOKEN);
}
_handleToken(token) {
if (token.type === Tokenizer.EOF_TOKEN) {
return true;
}
const { eventName, reshapeToken } = TOKEN_EMISSION_HELPERS[token.type];
if (this.listenerCount(eventName) === 0) {
return false;
}
this._emitToken(eventName, reshapeToken(token));
return true;
}
_emitToken(eventName, token) {
this.emit(eventName, token);
}
_emitPendingText() {
if (this.pendingText !== null) {
this._handleToken(this.pendingText);
this.pendingText = null;
}
}
}
const TOKEN_EMISSION_HELPERS = {
[Tokenizer.START_TAG_TOKEN]: {
eventName: 'startTag',
reshapeToken: origToken => ({
tagName: origToken.tagName,
attrs: origToken.attrs,
selfClosing: origToken.selfClosing,
sourceCodeLocation: origToken.location
})
},
[Tokenizer.END_TAG_TOKEN]: {
eventName: 'endTag',
reshapeToken: origToken => ({ tagName: origToken.tagName, sourceCodeLocation: origToken.location })
},
[Tokenizer.COMMENT_TOKEN]: {
eventName: 'comment',
reshapeToken: origToken => ({ text: origToken.data, sourceCodeLocation: origToken.location })
},
[Tokenizer.DOCTYPE_TOKEN]: {
eventName: 'doctype',
reshapeToken: origToken => ({
name: origToken.name,
publicId: origToken.publicId,
systemId: origToken.systemId,
sourceCodeLocation: origToken.location
})
},
[Tokenizer.CHARACTER_TOKEN]: {
eventName: 'text',
reshapeToken: origToken => ({ text: origToken.chars, sourceCodeLocation: origToken.location })
}
};
module.exports = SAXParser;

View File

@@ -0,0 +1,159 @@
'use strict';
const Tokenizer = require('parse5/lib/tokenizer');
const foreignContent = require('parse5/lib/common/foreign-content');
const unicode = require('parse5/lib/common/unicode');
const HTML = require('parse5/lib/common/html');
//Aliases
const $ = HTML.TAG_NAMES;
const NS = HTML.NAMESPACES;
//ParserFeedbackSimulator
//Simulates adjustment of the Tokenizer which performed by standard parser during tree construction.
class ParserFeedbackSimulator {
constructor(tokenizer) {
this.tokenizer = tokenizer;
this.namespaceStack = [];
this.namespaceStackTop = -1;
this._enterNamespace(NS.HTML);
}
getNextToken() {
const token = this.tokenizer.getNextToken();
if (token.type === Tokenizer.START_TAG_TOKEN) {
this._handleStartTagToken(token);
} else if (token.type === Tokenizer.END_TAG_TOKEN) {
this._handleEndTagToken(token);
} else if (token.type === Tokenizer.NULL_CHARACTER_TOKEN && this.inForeignContent) {
token.type = Tokenizer.CHARACTER_TOKEN;
token.chars = unicode.REPLACEMENT_CHARACTER;
} else if (this.skipNextNewLine) {
if (token.type !== Tokenizer.HIBERNATION_TOKEN) {
this.skipNextNewLine = false;
}
if (token.type === Tokenizer.WHITESPACE_CHARACTER_TOKEN && token.chars[0] === '\n') {
if (token.chars.length === 1) {
return this.getNextToken();
}
token.chars = token.chars.substr(1);
}
}
return token;
}
//Namespace stack mutations
_enterNamespace(namespace) {
this.namespaceStackTop++;
this.namespaceStack.push(namespace);
this.inForeignContent = namespace !== NS.HTML;
this.currentNamespace = namespace;
this.tokenizer.allowCDATA = this.inForeignContent;
}
_leaveCurrentNamespace() {
this.namespaceStackTop--;
this.namespaceStack.pop();
this.currentNamespace = this.namespaceStack[this.namespaceStackTop];
this.inForeignContent = this.currentNamespace !== NS.HTML;
this.tokenizer.allowCDATA = this.inForeignContent;
}
//Token handlers
_ensureTokenizerMode(tn) {
if (tn === $.TEXTAREA || tn === $.TITLE) {
this.tokenizer.state = Tokenizer.MODE.RCDATA;
} else if (tn === $.PLAINTEXT) {
this.tokenizer.state = Tokenizer.MODE.PLAINTEXT;
} else if (tn === $.SCRIPT) {
this.tokenizer.state = Tokenizer.MODE.SCRIPT_DATA;
} else if (
tn === $.STYLE ||
tn === $.IFRAME ||
tn === $.XMP ||
tn === $.NOEMBED ||
tn === $.NOFRAMES ||
tn === $.NOSCRIPT
) {
this.tokenizer.state = Tokenizer.MODE.RAWTEXT;
}
}
_handleStartTagToken(token) {
let tn = token.tagName;
if (tn === $.SVG) {
this._enterNamespace(NS.SVG);
} else if (tn === $.MATH) {
this._enterNamespace(NS.MATHML);
}
if (this.inForeignContent) {
if (foreignContent.causesExit(token)) {
this._leaveCurrentNamespace();
return;
}
const currentNs = this.currentNamespace;
if (currentNs === NS.MATHML) {
foreignContent.adjustTokenMathMLAttrs(token);
} else if (currentNs === NS.SVG) {
foreignContent.adjustTokenSVGTagName(token);
foreignContent.adjustTokenSVGAttrs(token);
}
foreignContent.adjustTokenXMLAttrs(token);
tn = token.tagName;
if (!token.selfClosing && foreignContent.isIntegrationPoint(tn, currentNs, token.attrs)) {
this._enterNamespace(NS.HTML);
}
} else {
if (tn === $.PRE || tn === $.TEXTAREA || tn === $.LISTING) {
this.skipNextNewLine = true;
} else if (tn === $.IMAGE) {
token.tagName = $.IMG;
}
this._ensureTokenizerMode(tn);
}
}
_handleEndTagToken(token) {
let tn = token.tagName;
if (!this.inForeignContent) {
const previousNs = this.namespaceStack[this.namespaceStackTop - 1];
if (previousNs === NS.SVG && foreignContent.SVG_TAG_NAMES_ADJUSTMENT_MAP[tn]) {
tn = foreignContent.SVG_TAG_NAMES_ADJUSTMENT_MAP[tn];
}
//NOTE: check for exit from integration point
if (foreignContent.isIntegrationPoint(tn, previousNs, token.attrs)) {
this._leaveCurrentNamespace();
}
} else if (
(tn === $.SVG && this.currentNamespace === NS.SVG) ||
(tn === $.MATH && this.currentNamespace === NS.MATHML)
) {
this._leaveCurrentNamespace();
}
// NOTE: adjust end tag name as well for consistency
if (this.currentNamespace === NS.SVG) {
foreignContent.adjustTokenSVGTagName(token);
}
}
}
module.exports = ParserFeedbackSimulator;