@hyperframes/parsers 0.9.65 → 0.9.66

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.
@@ -1,4 +1,4 @@
1
- import { A as AssetExists } from './rewriteSubCompPaths-DrZlWrIk.js';
1
+ import { A as AssetExists } from './rewriteSubCompPaths-Din3wu98.js';
2
2
 
3
3
  /** The subset of `node:path` that `isWithinProjectRoot` needs to run under
4
4
  * an injected platform (tests pass `path.win32` / `path.posix`). */
@@ -137,7 +137,7 @@ var isAbsoluteOrSpecial = isNonRelativeUrl;
137
137
  function needsRewrite(val) {
138
138
  return val.startsWith("../") || val === "..";
139
139
  }
140
- function rewriteAssetPath(compSrcPath, relativePath, assetExists) {
140
+ function rewriteAssetPath(compSrcPath, relativePath, assetExists, charge) {
141
141
  if (isAbsoluteOrSpecial(relativePath)) return relativePath;
142
142
  const compDir = dirname(compSrcPath);
143
143
  if (!compDir || compDir === ".") return relativePath;
@@ -147,7 +147,9 @@ function rewriteAssetPath(compSrcPath, relativePath, assetExists) {
147
147
  const filePath = decodeWellFormedEscapes(slashed);
148
148
  const sibling = resolve2("/", join(compDir, filePath)).slice(1);
149
149
  if (!needsRewrite(filePath) && (!assetExists || !assetExists(sibling))) return relativePath;
150
- return encodeUrlPath(sibling) + suffix;
150
+ const rebased = encodeUrlPath(sibling) + suffix;
151
+ charge?.(rebased.length - relativePath.length);
152
+ return rebased;
151
153
  }
152
154
 
153
155
  // src/assetResolution.ts
package/dist/assets.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { A as AssetExists, r as rewriteAssetPath, a as rewriteAssetPaths, b as rewriteCssAssetUrls, c as rewriteInlineStyleAssetUrls } from './rewriteSubCompPaths-DrZlWrIk.js';
1
+ export { A as AssetExists, C as ChargeRebase, r as rewriteAssetPath, a as rewriteAssetPaths, b as rewriteCssAssetUrls, c as rewriteInlineStyleAssetUrls } from './rewriteSubCompPaths-Din3wu98.js';
2
2
  export { a as decodeCssEscapes, b as decodeWellFormedEscapes, c as decodedUrlPath, e as encodeUrlPath, s as splitUrlSuffix } from './urlPath-CYK47t9W.js';
3
3
 
4
4
  /**
package/dist/assets.js CHANGED
@@ -170,7 +170,7 @@ var isAbsoluteOrSpecial = isNonRelativeUrl;
170
170
  function needsRewrite(val) {
171
171
  return val.startsWith("../") || val === "..";
172
172
  }
173
- function rewriteAssetPath(compSrcPath, relativePath, assetExists) {
173
+ function rewriteAssetPath(compSrcPath, relativePath, assetExists, charge) {
174
174
  if (isAbsoluteOrSpecial(relativePath)) return relativePath;
175
175
  const compDir = dirname(compSrcPath);
176
176
  if (!compDir || compDir === ".") return relativePath;
@@ -180,13 +180,15 @@ function rewriteAssetPath(compSrcPath, relativePath, assetExists) {
180
180
  const filePath = decodeWellFormedEscapes(slashed);
181
181
  const sibling = resolve2("/", join(compDir, filePath)).slice(1);
182
182
  if (!needsRewrite(filePath) && (!assetExists || !assetExists(sibling))) return relativePath;
183
- return encodeUrlPath(sibling) + suffix;
183
+ const rebased = encodeUrlPath(sibling) + suffix;
184
+ charge?.(rebased.length - relativePath.length);
185
+ return rebased;
184
186
  }
185
- function rewriteAssetPaths(elements, compSrcPath, getAttr, setAttr, assetExists) {
187
+ function rewriteAssetPaths(elements, compSrcPath, getAttr, setAttr, assetExists, charge) {
186
188
  for (const el of elements) {
187
189
  for (const attr of PATH_ATTRS) {
188
190
  const val = (getAttr(el, attr) || "").trim();
189
- const rewritten2 = rewriteAssetPath(compSrcPath, val, assetExists);
191
+ const rewritten2 = rewriteAssetPath(compSrcPath, val, assetExists, charge);
190
192
  if (rewritten2 !== val) {
191
193
  setAttr(el, attr, rewritten2);
192
194
  }
@@ -195,28 +197,28 @@ function rewriteAssetPaths(elements, compSrcPath, getAttr, setAttr, assetExists)
195
197
  if (!srcset) continue;
196
198
  const rewritten = rewriteSrcsetUrls(
197
199
  srcset,
198
- (url) => rewriteAssetPath(compSrcPath, url, assetExists)
200
+ (url) => rewriteAssetPath(compSrcPath, url, assetExists, charge)
199
201
  );
200
202
  if (rewritten !== srcset) setAttr(el, "srcset", rewritten);
201
203
  }
202
204
  }
203
- function rewriteInlineStyleAssetUrls(elements, compSrcPath, getStyle, setStyle, assetExists) {
205
+ function rewriteInlineStyleAssetUrls(elements, compSrcPath, getStyle, setStyle, assetExists, charge) {
204
206
  const compDir = dirname(compSrcPath);
205
207
  if (!compDir || compDir === ".") return;
206
208
  for (const el of elements) {
207
209
  const style = getStyle(el);
208
210
  if (!style) continue;
209
- const rewritten = rewriteCssAssetUrls(style, compSrcPath, assetExists);
211
+ const rewritten = rewriteCssAssetUrls(style, compSrcPath, assetExists, charge);
210
212
  if (rewritten !== style) {
211
213
  setStyle(el, rewritten);
212
214
  }
213
215
  }
214
216
  }
215
- function rewriteCssAssetUrls(cssText, compSrcPath, assetExists) {
217
+ function rewriteCssAssetUrls(cssText, compSrcPath, assetExists, charge) {
216
218
  if (!cssText) return cssText;
217
219
  return replaceMatches(cssText, cssUrlMatches(cssText), (full, quote, rawUrl) => {
218
220
  const urlValue = (rawUrl || "").trim();
219
- const rewritten = rewriteAssetPath(compSrcPath, urlValue, assetExists);
221
+ const rewritten = rewriteAssetPath(compSrcPath, urlValue, assetExists, charge);
220
222
  if (rewritten === urlValue) return full;
221
223
  return `url(${quote || ""}${rewritten}${quote || ""})`;
222
224
  });
@@ -11,6 +11,8 @@
11
11
  * Used by both the core bundler (preview) and the producer compiler (render)
12
12
  * to ensure consistent behavior.
13
13
  */
14
+ /** Gets the length a rebased path added over the authored one. */
15
+ type ChargeRebase = (addedBytes: number) => void;
14
16
  /**
15
17
  * Probe for "does this project-root-relative path exist?", supplied by callers
16
18
  * that can see the filesystem (the studio preview builder, the bundler, the
@@ -41,7 +43,7 @@ type AssetExists = (projectRelativePath: string) => boolean;
41
43
  * @returns The rewritten path relative to project root (e.g. "icon.svg"), or
42
44
  * the original path if no rewriting is needed.
43
45
  */
44
- declare function rewriteAssetPath(compSrcPath: string, relativePath: string, assetExists?: AssetExists): string;
46
+ declare function rewriteAssetPath(compSrcPath: string, relativePath: string, assetExists?: AssetExists, charge?: ChargeRebase): string;
45
47
  /**
46
48
  * Rewrite all relative `src` and `href` attributes on elements within a
47
49
  * DOM tree, adjusting paths from the sub-composition's directory context
@@ -52,15 +54,15 @@ declare function rewriteAssetPath(compSrcPath: string, relativePath: string, ass
52
54
  * @param getAttr - Function to read an attribute from an element
53
55
  * @param setAttr - Function to set an attribute on an element
54
56
  */
55
- declare function rewriteAssetPaths<T>(elements: Iterable<T>, compSrcPath: string, getAttr: (el: T, attr: string) => string | null | undefined, setAttr: (el: T, attr: string, value: string) => void, assetExists?: AssetExists): void;
57
+ declare function rewriteAssetPaths<T>(elements: Iterable<T>, compSrcPath: string, getAttr: (el: T, attr: string) => string | null | undefined, setAttr: (el: T, attr: string, value: string) => void, assetExists?: AssetExists, charge?: ChargeRebase): void;
56
58
  /**
57
59
  * Rewrite CSS url(...) references inside inline style attributes.
58
60
  */
59
- declare function rewriteInlineStyleAssetUrls<T>(elements: Iterable<T>, compSrcPath: string, getStyle: (el: T) => string | null | undefined, setStyle: (el: T, value: string) => void, assetExists?: AssetExists): void;
61
+ declare function rewriteInlineStyleAssetUrls<T>(elements: Iterable<T>, compSrcPath: string, getStyle: (el: T) => string | null | undefined, setStyle: (el: T, value: string) => void, assetExists?: AssetExists, charge?: ChargeRebase): void;
60
62
  /**
61
63
  * Rewrite CSS url(...) references in a sub-composition's inline styles so
62
64
  * ../foo.woff2 remains valid after the CSS is hoisted into the root document.
63
65
  */
64
- declare function rewriteCssAssetUrls(cssText: string, compSrcPath: string, assetExists?: AssetExists): string;
66
+ declare function rewriteCssAssetUrls(cssText: string, compSrcPath: string, assetExists?: AssetExists, charge?: ChargeRebase): string;
65
67
 
66
- export { type AssetExists as A, rewriteAssetPaths as a, rewriteCssAssetUrls as b, rewriteInlineStyleAssetUrls as c, rewriteAssetPath as r };
68
+ export { type AssetExists as A, type ChargeRebase as C, rewriteAssetPaths as a, rewriteCssAssetUrls as b, rewriteInlineStyleAssetUrls as c, rewriteAssetPath as r };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperframes/parsers",
3
- "version": "0.9.65",
3
+ "version": "0.9.66",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/heygen-com/hyperframes",
@@ -151,7 +151,7 @@
151
151
  "tsx": "^4.21.0",
152
152
  "typescript": "^5.0.0",
153
153
  "vitest": "^4.1.12",
154
- "@hyperframes/core": "0.9.65"
154
+ "@hyperframes/core": "0.9.66"
155
155
  },
156
156
  "scripts": {
157
157
  "build": "tsup",