@hyperframes/lint 0.8.5 → 0.8.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser.js +0 -60
- package/dist/browser.js.map +1 -1
- package/dist/index.js +0 -60
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/browser.js
CHANGED
|
@@ -392,54 +392,8 @@ function describeStudioElement(tag) {
|
|
|
392
392
|
parts.push(">");
|
|
393
393
|
return parts.join("");
|
|
394
394
|
}
|
|
395
|
-
var HEAD_BLOCKS_TO_IGNORE_PATTERN = /<(?:style|script|template|title|noscript)\b[^>]*>[\s\S]*?<\/(?:style|script|template|title|noscript)(?:\s[^>]*)?>/gi;
|
|
396
|
-
var HTML_TAG_PATTERN = /<[^>]+>/g;
|
|
397
|
-
var HEAD_CONTENT_PATTERN = /<head\b[^>]*>([\s\S]*?)(?:<\/head>|<body\b|$)/gi;
|
|
398
|
-
var AFTER_HEAD_BEFORE_BODY_PATTERN = /<\/head(?:\s[^>]*)?>([\s\S]*?)(?=<body\b|$)/gi;
|
|
399
|
-
var STRAY_HEAD_CLOSE_PATTERN = /<\/(?:style|script)(?:\s[^>]*)?>/i;
|
|
400
|
-
var MARKDOWN_CODE_FENCE_PATTERN = /```[^\r\n`]*(?:\r?\n|$)[\s\S]*?```/i;
|
|
401
|
-
var ORPHAN_CSS_AT_RULE_PATTERN = /(?:^|\s)@(?:container|font-face|keyframes|layer|media|page|property|scope|supports)[^{<]*\{[\s\S]*?:[\s\S]*?\}/i;
|
|
402
|
-
var ORPHAN_CSS_RULE_PATTERN = /(?:^|\s)(?:\/\*[\s\S]*?\*\/\s*)?(?:@[a-z-]+[^{}<]*|[.#][\w-]+[^{}<]*|[a-z][\w-]*(?:\s+[.#:[\w-][^{}<]*)?)\s*\{[^{}]*:[^{}]*\}/i;
|
|
403
395
|
var VISIBLE_MARKUP_COMMENT_PATTERN = /\/\*[\s\S]*?\*\//g;
|
|
404
396
|
var VISIBLE_MARKUP_COMMENT_PROTECTED_BLOCK_PATTERN = /<(style|script|template|title|noscript|pre|code|textarea|text)\b[^>]*>[\s\S]*?<\/\1(?:\s[^>]*)?>/gi;
|
|
405
|
-
function findCodeFenceLeak(headWithoutValidBlocks) {
|
|
406
|
-
return MARKDOWN_CODE_FENCE_PATTERN.exec(headWithoutValidBlocks)?.[0] ?? null;
|
|
407
|
-
}
|
|
408
|
-
function findOrphanCssLeak(headContent) {
|
|
409
|
-
const residualText = headContent.replace(HEAD_BLOCKS_TO_IGNORE_PATTERN, " ").replace(HTML_TAG_PATTERN, " ");
|
|
410
|
-
return ORPHAN_CSS_AT_RULE_PATTERN.exec(residualText)?.[0] ?? ORPHAN_CSS_RULE_PATTERN.exec(residualText)?.[0] ?? null;
|
|
411
|
-
}
|
|
412
|
-
function findStrayCloseLeak(headWithoutValidBlocks) {
|
|
413
|
-
return STRAY_HEAD_CLOSE_PATTERN.exec(headWithoutValidBlocks)?.[0] ?? null;
|
|
414
|
-
}
|
|
415
|
-
function findLeakedTextInHeadContent(headContent) {
|
|
416
|
-
const withoutValidBlocks = headContent.replace(HEAD_BLOCKS_TO_IGNORE_PATTERN, " ");
|
|
417
|
-
return findCodeFenceLeak(withoutValidBlocks) ?? findOrphanCssLeak(headContent) ?? findStrayCloseLeak(withoutValidBlocks);
|
|
418
|
-
}
|
|
419
|
-
function findLeakedTextInHead(rawSource) {
|
|
420
|
-
const headMatches = [...rawSource.matchAll(HEAD_CONTENT_PATTERN)];
|
|
421
|
-
for (const match of headMatches) {
|
|
422
|
-
const leakedText = findLeakedTextInHeadContent(match[1] ?? "");
|
|
423
|
-
if (leakedText) return leakedText;
|
|
424
|
-
}
|
|
425
|
-
return null;
|
|
426
|
-
}
|
|
427
|
-
function findLeakedTextBetweenHeadAndBody(rawSource) {
|
|
428
|
-
const boundaryMatches = [...rawSource.matchAll(AFTER_HEAD_BEFORE_BODY_PATTERN)];
|
|
429
|
-
for (const match of boundaryMatches) {
|
|
430
|
-
const leakedText = findLeakedTextInHeadContent(match[1] ?? "");
|
|
431
|
-
if (leakedText) return leakedText;
|
|
432
|
-
}
|
|
433
|
-
return null;
|
|
434
|
-
}
|
|
435
|
-
function findLeakedTextBeforeCompositionRoot(source, rootTag) {
|
|
436
|
-
if (!rootTag || rootTag.name === "body") return null;
|
|
437
|
-
const bodyOpenMatch = /<body\b[^>]*>/i.exec(source);
|
|
438
|
-
const prefixStart = bodyOpenMatch ? bodyOpenMatch.index + bodyOpenMatch[0].length : 0;
|
|
439
|
-
const prefixEnd = rootTag.index;
|
|
440
|
-
if (prefixEnd <= prefixStart) return null;
|
|
441
|
-
return findLeakedTextInHeadContent(source.slice(prefixStart, prefixEnd));
|
|
442
|
-
}
|
|
443
397
|
function findProtectedVisibleMarkupRanges(source) {
|
|
444
398
|
const ranges = [];
|
|
445
399
|
for (const match of source.matchAll(VISIBLE_MARKUP_COMMENT_PROTECTED_BLOCK_PATTERN)) {
|
|
@@ -523,20 +477,6 @@ var coreRules = [
|
|
|
523
477
|
}
|
|
524
478
|
return findings;
|
|
525
479
|
},
|
|
526
|
-
// head_leaked_text
|
|
527
|
-
({ source, rootTag }) => {
|
|
528
|
-
const snippet = findLeakedTextInHead(source) ?? findLeakedTextBetweenHeadAndBody(source) ?? findLeakedTextBeforeCompositionRoot(source, rootTag);
|
|
529
|
-
if (!snippet) return [];
|
|
530
|
-
return [
|
|
531
|
-
{
|
|
532
|
-
code: "head_leaked_text",
|
|
533
|
-
severity: "error",
|
|
534
|
-
message: "Detected leaked code or CSS text around the document `<head>` or before the composition root. Browsers render this as visible text in the video.",
|
|
535
|
-
fixHint: "Move CSS into a single `<style>...</style>` block and remove stray close tags, markdown fences, or code text from `<head>`, the `</head>`/`<body>` boundary, or the pre-root body prefix.",
|
|
536
|
-
snippet: truncateSnippet(snippet)
|
|
537
|
-
}
|
|
538
|
-
];
|
|
539
|
-
},
|
|
540
480
|
// visible_markup_comment
|
|
541
481
|
({ source }) => {
|
|
542
482
|
const snippet = findVisibleMarkupCommentLeak(source);
|