@hyperframes/producer 0.9.82 → 0.9.84

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.
@@ -3777,6 +3777,96 @@ var THREE_D_CONTEXT_PATTERN = /transform-style\s*:\s*preserve-3d|backface-visibi
3777
3777
  function detectThreeDTransformUsage(html) {
3778
3778
  return THREE_D_CONTEXT_PATTERN.test(html);
3779
3779
  }
3780
+ var CSS_ESCAPE = /\\(?:[0-9a-fA-F]{1,6}[ \t\n\r\f]?|[^])?/y;
3781
+ function ancestorSelectorSteps(list) {
3782
+ const selectors = [];
3783
+ let steps = [];
3784
+ let combinators = [];
3785
+ let compound = "";
3786
+ let open2 = false;
3787
+ let combinator = null;
3788
+ const skipGroup = (at, close) => {
3789
+ let depth = 0;
3790
+ for (let i = at; i < list.length; i++) {
3791
+ const ch = list[i];
3792
+ if (ch === "\\") i++;
3793
+ else if (ch === '"' || ch === "'") {
3794
+ const end = list.indexOf(ch, i + 1);
3795
+ if (end < 0) return -1;
3796
+ i = end;
3797
+ } else if (ch === list[at]) depth++;
3798
+ else if (ch === close && --depth === 0) return i;
3799
+ }
3800
+ return -1;
3801
+ };
3802
+ const flush = () => {
3803
+ if (!open2) return;
3804
+ if ((combinator === "+" || combinator === "~") && steps.length > 0) {
3805
+ steps.pop();
3806
+ combinator = combinators.pop() ?? null;
3807
+ }
3808
+ steps.push({ compound: compound || "*", child: combinator === ">" });
3809
+ combinators.push(combinator);
3810
+ compound = "";
3811
+ open2 = false;
3812
+ combinator = null;
3813
+ };
3814
+ for (let i = 0; i <= list.length; i++) {
3815
+ const ch = list[i];
3816
+ if (ch === void 0 || ch === ",") {
3817
+ flush();
3818
+ if (steps.length) selectors.push(steps);
3819
+ steps = [];
3820
+ combinators = [];
3821
+ combinator = null;
3822
+ } else if (ch === "\\") {
3823
+ CSS_ESCAPE.lastIndex = i;
3824
+ const escape = CSS_ESCAPE.exec(list)[0];
3825
+ compound += escape;
3826
+ i += escape.length - 1;
3827
+ open2 = true;
3828
+ } else if (ch === "[") {
3829
+ const end = skipGroup(i, "]");
3830
+ if (end < 0) return null;
3831
+ compound += list.slice(i, end + 1);
3832
+ open2 = true;
3833
+ i = end;
3834
+ } else if (ch === ":") {
3835
+ while (/[:\w-]/.test(list[i + 1] ?? "")) i++;
3836
+ if (list[i + 1] === "(") i = skipGroup(i + 1, ")");
3837
+ if (i < 0) return null;
3838
+ open2 = true;
3839
+ } else if (/\s/.test(ch)) {
3840
+ flush();
3841
+ if (steps.length) combinator ??= " ";
3842
+ } else if (ch === ">" || ch === "+" || ch === "~") {
3843
+ flush();
3844
+ combinator = ch;
3845
+ } else if (ch === "(" || ch === ")" || ch === "]") {
3846
+ return null;
3847
+ } else {
3848
+ compound += ch;
3849
+ open2 = true;
3850
+ }
3851
+ }
3852
+ return selectors;
3853
+ }
3854
+ function matchesAnAncestor(steps, ancestors) {
3855
+ let reach = ancestors.map((el) => el.matches(steps[0].compound));
3856
+ for (const step of steps.slice(1)) {
3857
+ let above = false;
3858
+ const next = ancestors.map(() => false);
3859
+ for (let j = ancestors.length - 1; j >= 0; j--) {
3860
+ const placed = step.child ? reach[j + 1] === true : above;
3861
+ next[j] = placed && ancestors[j].matches(step.compound);
3862
+ above ||= reach[j];
3863
+ }
3864
+ reach = next;
3865
+ }
3866
+ return reach.includes(true);
3867
+ }
3868
+ var MAX_ROOT_ANCESTORS = 256;
3869
+ var MAX_ANCESTOR_SELECTOR_CHECKS = 1e5;
3780
3870
  function detectAncestorBackgroundImage(html) {
3781
3871
  const { document: document2 } = parseHTML5(html);
3782
3872
  const root = document2.querySelector("[data-composition-id]");
@@ -3786,6 +3876,8 @@ function detectAncestorBackgroundImage(html) {
3786
3876
  if (document2.documentElement && !ancestors.includes(document2.documentElement)) {
3787
3877
  ancestors.push(document2.documentElement);
3788
3878
  }
3879
+ if (ancestors.length > MAX_ROOT_ANCESTORS) return true;
3880
+ let selectorChecks = 0;
3789
3881
  for (const el of ancestors) {
3790
3882
  const style = el.getAttribute("style");
3791
3883
  if (style && hasBackgroundImageDeclaration(`{${style}}`)) return true;
@@ -3795,14 +3887,14 @@ function detectAncestorBackgroundImage(html) {
3795
3887
  for (const { parts: rule } of cssRuleMatches(css)) {
3796
3888
  const [, selectorList, declarations] = rule;
3797
3889
  if (!hasBackgroundImageDeclaration(`{${declarations}}`)) continue;
3798
- for (const selector of selectorList.split(",")) {
3799
- const sel = selector.trim();
3800
- if (!sel || sel.startsWith("@")) continue;
3801
- if (/^(?:html|:root)$/i.test(sel)) return true;
3890
+ if (selectorList.trim().startsWith("@")) continue;
3891
+ const selectors = ancestorSelectorSteps(selectorList);
3892
+ if (!selectors) return true;
3893
+ for (const steps of selectors) {
3894
+ selectorChecks += steps.length * ancestors.length;
3895
+ if (selectorChecks > MAX_ANCESTOR_SELECTOR_CHECKS) return true;
3802
3896
  try {
3803
- for (const matched of document2.querySelectorAll(sel)) {
3804
- if (ancestors.includes(matched)) return true;
3805
- }
3897
+ if (matchesAnAncestor(steps, ancestors)) return true;
3806
3898
  } catch {
3807
3899
  }
3808
3900
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": "0.1.0",
3
3
  "buildId": "dev",
4
- "sha256": "d56d279eab6240b740f1086bddc68b57ad9bfc1c4db4a35329612330e3830ae6",
4
+ "sha256": "588ac12bca4d71abf797ca1effa6d51c804533f4fc90139ab0fad9b8736dab22",
5
5
  "artifacts": {
6
6
  "iife": "hyperframe.runtime.iife.js",
7
7
  "esm": "hyperframe.runtime.mjs"