Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (isWhiteSpace(codePoint)) {
this.consumeWhiteSpace();
return WHITESPACE_TOKEN;
}
if (isDigit(codePoint)) {
this.reconsumeCodePoint(codePoint);
return this.consumeNumericToken();
}
if (isNameStartCodePoint(codePoint)) {
this.reconsumeCodePoint(codePoint);
return this.consumeIdentLikeToken();
}
return {type: TokenType.DELIM_TOKEN, value: fromCodePoint(codePoint)};
}
text.split(/\n/).forEach((line) => {
const breaker = LineBreaker(line, {lineBreak, wordBreak});
const words = [];
let bk = breaker.next();
while(!bk.done) {
words.push(bk.value.slice());
bk = breaker.next();
}
let l = '';
words.forEach((word) => {
if(!l) {
l = word;
} else {
const ll = `${l}${word}`;
const [w] = measureText(node, ll, font);
if(w > (lines.length === 0 ? textboxWidth - textIndent : textboxWidth)) {
lines.push(l);
l = word;
if (codePoint === LINE_FEED) {
this._value.splice(0, i);
return BAD_STRING_TOKEN;
}
if (codePoint === REVERSE_SOLIDUS) {
const next = this._value[i + 1];
if (next !== EOF && next !== undefined) {
if (next === LINE_FEED) {
value += this.consumeStringSlice(i);
i = -1;
this._value.shift();
} else if (isValidEscape(codePoint, next)) {
value += this.consumeStringSlice(i);
value += fromCodePoint(this.consumeEscapedCodePoint());
i = -1;
}
}
}
i++;
} while (true);
}
}
}
this.consumeBadUrlRemnants();
return BAD_URL_TOKEN;
}
while (true) {
const codePoint = this.consumeCodePoint();
if (codePoint === EOF || codePoint === RIGHT_PARENTHESIS) {
return {type: TokenType.URL_TOKEN, value: fromCodePoint(...value)};
} else if (isWhiteSpace(codePoint)) {
this.consumeWhiteSpace();
if (this.peekCodePoint(0) === EOF || this.peekCodePoint(0) === RIGHT_PARENTHESIS) {
this.consumeCodePoint();
return {type: TokenType.URL_TOKEN, value: fromCodePoint(...value)};
}
this.consumeBadUrlRemnants();
return BAD_URL_TOKEN;
} else if (
codePoint === QUOTATION_MARK ||
codePoint === APOSTROPHE ||
codePoint === LEFT_PARENTHESIS ||
isNonPrintableCodePoint(codePoint)
) {
this.consumeBadUrlRemnants();
return BAD_URL_TOKEN;
} else if (codePoint === REVERSE_SOLIDUS) {
if (isValidEscape(codePoint, this.peekCodePoint(0))) {
value.push(this.consumeEscapedCodePoint());
} else {
this.consumeBadUrlRemnants();
private consumeEscapedCodePoint(): number {
const codePoint = this.consumeCodePoint();
if (isHex(codePoint)) {
let hex = fromCodePoint(codePoint);
while (isHex(this.peekCodePoint(0)) && hex.length < 6) {
hex += fromCodePoint(this.consumeCodePoint());
}
if (isWhiteSpace(this.peekCodePoint(0))) {
this.consumeCodePoint();
}
const hexCodePoint = parseInt(hex, 16);
if (hexCodePoint === 0 || isSurrogateCodePoint(hexCodePoint) || hexCodePoint > 0x10ffff) {
return REPLACEMENT_CHARACTER;
}
return hexCodePoint;
}
if (codePoint === EOF) {
private consumeName(): string {
let result = '';
while (true) {
const codePoint = this.consumeCodePoint();
if (isNameCodePoint(codePoint)) {
result += fromCodePoint(codePoint);
} else if (isValidEscape(codePoint, this.peekCodePoint(0))) {
result += fromCodePoint(this.consumeEscapedCodePoint());
} else {
this.reconsumeCodePoint(codePoint);
return result;
}
}
}
}
private consumeName(): string {
let result = '';
while (true) {
const codePoint = this.consumeCodePoint();
if (isNameCodePoint(codePoint)) {
result += fromCodePoint(codePoint);
} else if (isValidEscape(codePoint, this.peekCodePoint(0))) {
result += fromCodePoint(this.consumeEscapedCodePoint());
} else {
this.reconsumeCodePoint(codePoint);
return result;
}
}
}
}
private consumeStringSlice(count: number): string {
const SLICE_STACK_SIZE = 60000;
let value = '';
while (count > 0) {
const amount = Math.min(SLICE_STACK_SIZE, count);
value += fromCodePoint(...this._value.splice(0, amount));
count -= amount;
}
this._value.shift();
return value;
}
renderTextWithLetterSpacing(text: TextBounds, letterSpacing: number) {
if (letterSpacing === 0) {
this.ctx.fillText(text.text, text.bounds.left, text.bounds.top + text.bounds.height);
} else {
const letters = toCodePoints(text.text).map(i => fromCodePoint(i));
letters.reduce((left, letter) => {
this.ctx.fillText(letter, left, text.bounds.top + text.bounds.height);
return left + this.ctx.measureText(letter).width;
}, text.bounds.left);
}
}
write(chunk: string) {
this._value = this._value.concat(toCodePoints(chunk));
}