@hyperframes/core 0.10.7 → 0.10.8

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.
@@ -91,8 +91,8 @@ function scopeSelectorOnce(selector, scope, compositionId, authoredRootId, compo
91
91
  }
92
92
  return selectorWithoutRootTiming.replace(compositionIdPattern, () => scope);
93
93
  }
94
- const leading = selectorWithoutRootTiming.match(/^\s*/)?.[0] ?? "";
95
- const trailing = selectorWithoutRootTiming.match(/\s*$/)?.[0] ?? "";
94
+ const leading = selectorWithoutRootTiming.slice(0, selectorWithoutRootTiming.length - selectorWithoutRootTiming.trimStart().length);
95
+ const trailing = selectorWithoutRootTiming.slice(selectorWithoutRootTiming.trimEnd().length);
96
96
  if (compoundAuthoredRoot) {
97
97
  const authoredRootAttr = authoredRootId
98
98
  ? `[${AUTHORED_ROOT_ID_ATTR}="${escapeCssAttributeValue(authoredRootId)}"]`
@@ -107,10 +107,25 @@ function scopeSelectorOnce(selector, scope, compositionId, authoredRootId, compo
107
107
  function normalizeCompositionRootSelector(selector, scope, compositionId) {
108
108
  const quotedCompId = escapeRegExp(compositionId);
109
109
  const compAttr = String.raw `\[\s*data-composition-id\s*=\s*(?:"${quotedCompId}"|'${quotedCompId}')\s*\]`;
110
- const timingAttr = String.raw `\s*\[\s*data-(?:start|duration)\s*=\s*(?:"[^"]*"|'[^']*')\s*\]`;
111
- return selector
112
- .replace(new RegExp(`${compAttr}(?:${timingAttr})+`, "g"), () => scope)
113
- .replace(new RegExp(`(?:${timingAttr})+${compAttr}`, "g"), () => scope);
110
+ const firstTimingAttr = String.raw `\[\s*data-(?:start|duration)\s*=\s*(?:"[^"]*"|'[^']*')\s*\]`;
111
+ const timingAttr = String.raw `\s*${firstTimingAttr}`;
112
+ const rootThenTiming = selector.replace(new RegExp(`${compAttr}(?:${timingAttr})+`, "g"), () => scope);
113
+ // A pattern that needs the root at the end starts again at every attribute and space of a run with no root.
114
+ const timingRunThenMaybeRoot = new RegExp(`${firstTimingAttr}(?:${timingAttr})*(${compAttr})?`, "g");
115
+ let scoped = "";
116
+ let kept = 0;
117
+ for (const run of rootThenTiming.matchAll(timingRunThenMaybeRoot)) {
118
+ const rootFollows = run[1] !== undefined;
119
+ if (!rootFollows)
120
+ continue;
121
+ let replaceFrom = run.index;
122
+ while (replaceFrom > kept && rootThenTiming[replaceFrom - 1]?.trim() === "") {
123
+ replaceFrom -= 1;
124
+ }
125
+ scoped += rootThenTiming.slice(kept, replaceFrom) + scope;
126
+ kept = run.index + run[0].length;
127
+ }
128
+ return kept === 0 ? rootThenTiming : scoped + rootThenTiming.slice(kept);
114
129
  }
115
130
  const GLOBAL_AT_RULES = new Set(["keyframes", "-webkit-keyframes", "font-face"]);
116
131
  function isAtRuleNode(node) {