MCPcopy Create free account
hub / github.com/heygen-com/hyperframes / rewriteAssetPaths

Function rewriteAssetPaths

packages/parsers/src/rewriteSubCompPaths.ts:64–79  ·  view source on GitHub ↗
(
  elements: Iterable<T>,
  compSrcPath: string,
  getAttr: (el: T, attr: string) => string | null | undefined,
  setAttr: (el: T, attr: string, value: string) => void,
)

Source from the content-addressed store, hash-verified

62 * @param setAttr - Function to set an attribute on an element
63 */
64export 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.

Callers 2

inlineSubCompositionsFunction · 0.90
rewriteRelativePathsFunction · 0.85

Calls 2

getAttrFunction · 0.85
rewriteAssetPathFunction · 0.85

Tested by

no test coverage detected