@hyperframes/core 0.8.221 → 0.8.222

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.
@@ -444,8 +444,8 @@ export function inlineSubCompositions(document, hosts, options) {
444
444
  // Rewrite relative asset paths before inlining so ../foo.svg from
445
445
  // compositions/ resolves correctly when the content moves to root.
446
446
  const assetEls = innerRoot
447
- ? innerRoot.querySelectorAll("[src], [href]")
448
- : contentDoc.querySelectorAll("[src], [href]");
447
+ ? innerRoot.querySelectorAll("[src], [href], [srcset]")
448
+ : contentDoc.querySelectorAll("[src], [href], [srcset]");
449
449
  rewriteAssetPaths(assetEls, src, (el, attr) => el.getAttribute(attr), (el, attr, val) => {
450
450
  el.setAttribute(attr, val);
451
451
  }, assetExists);
@@ -1 +1 @@
1
- export declare function rewriteSrcsetUrls(srcset: string, rewriteUrl: (url: string) => string): string;
1
+ export { rewriteSrcsetUrls } from "@hyperframes/parsers/asset-paths";
@@ -1,46 +1 @@
1
- function skipSrcsetDescriptors(srcset, position) {
2
- let inParens = false;
3
- while (position < srcset.length) {
4
- const char = srcset.charAt(position++);
5
- if (char === "(")
6
- inParens = true;
7
- else if (char === ")")
8
- inParens = false;
9
- else if (char === "," && !inParens)
10
- break;
11
- }
12
- return position;
13
- }
14
- function readSrcsetUrl(srcset, position) {
15
- while (position < srcset.length && /[ \t\n\r\f,]/.test(srcset.charAt(position)))
16
- position++;
17
- const start = position;
18
- while (position < srcset.length && !/[ \t\n\r\f]/.test(srcset.charAt(position)))
19
- position++;
20
- let end = position;
21
- while (end > start && srcset.charAt(end - 1) === ",")
22
- end--;
23
- return { start, end, next: position };
24
- }
25
- export function rewriteSrcsetUrls(srcset, rewriteUrl) {
26
- const parts = [];
27
- let position = 0;
28
- let written = 0;
29
- // Preserve URL commas per https://html.spec.whatwg.org/multipage/images.html#parse-a-srcset-attribute
30
- while (position < srcset.length) {
31
- const { start, end, next } = readSrcsetUrl(srcset, position);
32
- position = next;
33
- if (end > start) {
34
- const url = srcset.slice(start, end);
35
- const rewritten = rewriteUrl(url);
36
- if (rewritten !== url) {
37
- parts.push(srcset.slice(written, start), rewritten);
38
- written = end;
39
- }
40
- }
41
- if (end < position)
42
- continue;
43
- position = skipSrcsetDescriptors(srcset, position);
44
- }
45
- return parts.length > 0 ? parts.join("") + srcset.slice(written) : srcset;
46
- }
1
+ export { rewriteSrcsetUrls } from "@hyperframes/parsers/asset-paths";
@@ -29,11 +29,13 @@ const PROPERTY_MAP = { rotate: "rotation" };
29
29
  function escapeRegExp(text) {
30
30
  return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
31
31
  }
32
+ function keyPattern(key, valuePattern) {
33
+ return new RegExp(`(?<![\\w$])${escapeRegExp(key)}\\s*:\\s*${valuePattern}`);
34
+ }
32
35
  /** Extract the balanced `{...}` body following `marker` in `src`. Brace
33
36
  * counting does not skip string literals — sound for motion.dev output
34
37
  * (numeric arrays + named eases, never arbitrary strings containing `}`). */
35
- function balancedBlock(src, marker) {
36
- const at = src.indexOf(marker);
38
+ function balancedBlock(src, marker, at = src.indexOf(marker)) {
37
39
  if (at === -1)
38
40
  return null;
39
41
  const start = src.indexOf("{", at + marker.length - 1);
@@ -51,9 +53,15 @@ function balancedBlock(src, marker) {
51
53
  }
52
54
  return null;
53
55
  }
56
+ function balancedBlockAfterKey(src, key) {
57
+ const match = keyPattern(key, "\\{").exec(src);
58
+ if (!match)
59
+ return null;
60
+ return balancedBlock(src, match[0], match.index);
61
+ }
54
62
  /** Extract a balanced `[...]` immediately after `key:` inside `src`. */
55
63
  function arrayAfterKey(src, key) {
56
- const re = new RegExp(`${escapeRegExp(key)}\\s*:\\s*\\[`);
64
+ const re = keyPattern(key, "\\[");
57
65
  const m = re.exec(src);
58
66
  if (!m)
59
67
  return null;
@@ -71,7 +79,7 @@ function arrayAfterKey(src, key) {
71
79
  return null;
72
80
  }
73
81
  function scalarAfterKey(src, key) {
74
- const m = new RegExp(`${escapeRegExp(key)}\\s*:\\s*("[^"]*"|[\\w.]+)`).exec(src);
82
+ const m = keyPattern(key, '("[^"]*"|[\\w.]+)').exec(src);
75
83
  return m?.[1] ?? null;
76
84
  }
77
85
  function parseEase(transitionBlock) {
@@ -110,7 +118,7 @@ function stripWrapTail(values, times, ease, duration) {
110
118
  /** Extract and validate one property's raw arrays from the snippet blocks. */
111
119
  function extractTrackData(animate, transition, prop) {
112
120
  const valuesSrc = arrayAfterKey(animate, prop);
113
- const propTransition = balancedBlock(transition, `${prop}: {`);
121
+ const propTransition = balancedBlockAfterKey(transition, prop);
114
122
  if (!valuesSrc || !propTransition)
115
123
  return null;
116
124
  const timesSrc = arrayAfterKey(propTransition, "times");