( elements: Iterable<T>, compSrcPath: string, getAttr: (el: T, attr: string) => string | null | undefined, setAttr: (el: T, attr: string, value: string) => void, )
| 62 | * @param setAttr - Function to set an attribute on an element |
| 63 | */ |
| 64 | export function rewriteAssetPaths<T>( |
| 65 | elements: Iterable<T>, |
| 66 | compSrcPath: string, |
| 67 | getAttr: (el: T, attr: string) => string | null | undefined, |
| 68 | setAttr: (el: T, attr: string, value: string) => void, |
| 69 | ): void { |
| 70 | for (const el of elements) { |
| 71 | for (const attr of PATH_ATTRS) { |
| 72 | const val = (getAttr(el, attr) || "").trim(); |
| 73 | const rewritten = rewriteAssetPath(compSrcPath, val); |
| 74 | if (rewritten !== val) { |
| 75 | setAttr(el, attr, rewritten); |
| 76 | } |
| 77 | } |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Rewrite CSS url(...) references inside inline style attributes. |
no test coverage detected