Merge the mutually recursive CSS scope helpers. [skip build]
This commit is contained in:
@@ -35,32 +35,7 @@ export function scopeRoomAppCss(css: string, scopeSelector: string): string {
|
|||||||
return `${scoped}{${body}}`;
|
return `${scoped}{${body}}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
const rewriteBlock = (block: string): string => {
|
function rewriteChunk(chunk: string): string {
|
||||||
const trimmed = block.trim();
|
|
||||||
if (!trimmed) return '';
|
|
||||||
|
|
||||||
if (trimmed.startsWith('@')) {
|
|
||||||
const open = trimmed.indexOf('{');
|
|
||||||
if (open === -1) return `${trimmed};`;
|
|
||||||
const header = trimmed.slice(0, open).trim();
|
|
||||||
const inner = trimmed.slice(open + 1);
|
|
||||||
// @keyframes / @font-face: keep as-is (namespaced risk is low for MVP)
|
|
||||||
if (/^@(keyframes|font-face)\b/i.test(header)) {
|
|
||||||
return `${header}{${inner}}`;
|
|
||||||
}
|
|
||||||
// @media / @supports: re-scope nested rules
|
|
||||||
const nested = rewriteCssChunk(inner);
|
|
||||||
return `${header}{${nested}}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
const open = trimmed.indexOf('{');
|
|
||||||
if (open === -1) return '';
|
|
||||||
const selectors = trimmed.slice(0, open);
|
|
||||||
const body = trimmed.slice(open + 1);
|
|
||||||
return scopeRule(selectors, body);
|
|
||||||
};
|
|
||||||
|
|
||||||
const rewriteCssChunk = (chunk: string): string => {
|
|
||||||
const parts: string[] = [];
|
const parts: string[] = [];
|
||||||
let depth = 0;
|
let depth = 0;
|
||||||
let start = 0;
|
let start = 0;
|
||||||
@@ -70,15 +45,32 @@ export function scopeRoomAppCss(css: string, scopeSelector: string): string {
|
|||||||
else if (ch === '}') {
|
else if (ch === '}') {
|
||||||
depth -= 1;
|
depth -= 1;
|
||||||
if (depth === 0) {
|
if (depth === 0) {
|
||||||
parts.push(rewriteBlock(chunk.slice(start, i)));
|
const block = chunk.slice(start, i).trim();
|
||||||
start = i + 1;
|
start = i + 1;
|
||||||
|
if (block) {
|
||||||
|
const open = block.indexOf('{');
|
||||||
|
if (open === -1) {
|
||||||
|
parts.push(`${block};`);
|
||||||
|
} else {
|
||||||
|
const header = block.slice(0, open).trim();
|
||||||
|
const inner = block.slice(open + 1);
|
||||||
|
if (!header.startsWith('@')) {
|
||||||
|
parts.push(scopeRule(header, inner));
|
||||||
|
} else if (/^@(keyframes|font-face)\b/i.test(header)) {
|
||||||
|
parts.push(`${header}{${inner}}`);
|
||||||
|
} else {
|
||||||
|
// @media / @supports: re-scope nested rules
|
||||||
|
parts.push(`${header}{${rewriteChunk(inner)}}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return parts.filter(Boolean).join('\n');
|
return parts.filter(Boolean).join('\n');
|
||||||
};
|
}
|
||||||
|
|
||||||
return rewriteCssChunk(sanitized);
|
return rewriteChunk(sanitized);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isAllowedRoomAppImageSrc(src: string): boolean {
|
export function isAllowedRoomAppImageSrc(src: string): boolean {
|
||||||
|
|||||||
Reference in New Issue
Block a user