@hyperframes/producer 0.9.82 → 0.9.83

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
  }
package/dist/index.js CHANGED
@@ -8417,6 +8417,96 @@ var THREE_D_CONTEXT_PATTERN = /transform-style\s*:\s*preserve-3d|backface-visibi
8417
8417
  function detectThreeDTransformUsage(html) {
8418
8418
  return THREE_D_CONTEXT_PATTERN.test(html);
8419
8419
  }
8420
+ var CSS_ESCAPE = /\\(?:[0-9a-fA-F]{1,6}[ \t\n\r\f]?|[^])?/y;
8421
+ function ancestorSelectorSteps(list) {
8422
+ const selectors = [];
8423
+ let steps = [];
8424
+ let combinators = [];
8425
+ let compound = "";
8426
+ let open2 = false;
8427
+ let combinator = null;
8428
+ const skipGroup = (at, close) => {
8429
+ let depth = 0;
8430
+ for (let i = at; i < list.length; i++) {
8431
+ const ch = list[i];
8432
+ if (ch === "\\") i++;
8433
+ else if (ch === '"' || ch === "'") {
8434
+ const end = list.indexOf(ch, i + 1);
8435
+ if (end < 0) return -1;
8436
+ i = end;
8437
+ } else if (ch === list[at]) depth++;
8438
+ else if (ch === close && --depth === 0) return i;
8439
+ }
8440
+ return -1;
8441
+ };
8442
+ const flush = () => {
8443
+ if (!open2) return;
8444
+ if ((combinator === "+" || combinator === "~") && steps.length > 0) {
8445
+ steps.pop();
8446
+ combinator = combinators.pop() ?? null;
8447
+ }
8448
+ steps.push({ compound: compound || "*", child: combinator === ">" });
8449
+ combinators.push(combinator);
8450
+ compound = "";
8451
+ open2 = false;
8452
+ combinator = null;
8453
+ };
8454
+ for (let i = 0; i <= list.length; i++) {
8455
+ const ch = list[i];
8456
+ if (ch === void 0 || ch === ",") {
8457
+ flush();
8458
+ if (steps.length) selectors.push(steps);
8459
+ steps = [];
8460
+ combinators = [];
8461
+ combinator = null;
8462
+ } else if (ch === "\\") {
8463
+ CSS_ESCAPE.lastIndex = i;
8464
+ const escape = CSS_ESCAPE.exec(list)[0];
8465
+ compound += escape;
8466
+ i += escape.length - 1;
8467
+ open2 = true;
8468
+ } else if (ch === "[") {
8469
+ const end = skipGroup(i, "]");
8470
+ if (end < 0) return null;
8471
+ compound += list.slice(i, end + 1);
8472
+ open2 = true;
8473
+ i = end;
8474
+ } else if (ch === ":") {
8475
+ while (/[:\w-]/.test(list[i + 1] ?? "")) i++;
8476
+ if (list[i + 1] === "(") i = skipGroup(i + 1, ")");
8477
+ if (i < 0) return null;
8478
+ open2 = true;
8479
+ } else if (/\s/.test(ch)) {
8480
+ flush();
8481
+ if (steps.length) combinator ??= " ";
8482
+ } else if (ch === ">" || ch === "+" || ch === "~") {
8483
+ flush();
8484
+ combinator = ch;
8485
+ } else if (ch === "(" || ch === ")" || ch === "]") {
8486
+ return null;
8487
+ } else {
8488
+ compound += ch;
8489
+ open2 = true;
8490
+ }
8491
+ }
8492
+ return selectors;
8493
+ }
8494
+ function matchesAnAncestor(steps, ancestors) {
8495
+ let reach = ancestors.map((el) => el.matches(steps[0].compound));
8496
+ for (const step of steps.slice(1)) {
8497
+ let above = false;
8498
+ const next = ancestors.map(() => false);
8499
+ for (let j = ancestors.length - 1; j >= 0; j--) {
8500
+ const placed = step.child ? reach[j + 1] === true : above;
8501
+ next[j] = placed && ancestors[j].matches(step.compound);
8502
+ above ||= reach[j];
8503
+ }
8504
+ reach = next;
8505
+ }
8506
+ return reach.includes(true);
8507
+ }
8508
+ var MAX_ROOT_ANCESTORS = 256;
8509
+ var MAX_ANCESTOR_SELECTOR_CHECKS = 1e5;
8420
8510
  function detectAncestorBackgroundImage(html) {
8421
8511
  const { document: document2 } = parseHTML5(html);
8422
8512
  const root = document2.querySelector("[data-composition-id]");
@@ -8426,6 +8516,8 @@ function detectAncestorBackgroundImage(html) {
8426
8516
  if (document2.documentElement && !ancestors.includes(document2.documentElement)) {
8427
8517
  ancestors.push(document2.documentElement);
8428
8518
  }
8519
+ if (ancestors.length > MAX_ROOT_ANCESTORS) return true;
8520
+ let selectorChecks = 0;
8429
8521
  for (const el of ancestors) {
8430
8522
  const style = el.getAttribute("style");
8431
8523
  if (style && hasBackgroundImageDeclaration(`{${style}}`)) return true;
@@ -8435,14 +8527,14 @@ function detectAncestorBackgroundImage(html) {
8435
8527
  for (const { parts: rule } of cssRuleMatches(css)) {
8436
8528
  const [, selectorList, declarations] = rule;
8437
8529
  if (!hasBackgroundImageDeclaration(`{${declarations}}`)) continue;
8438
- for (const selector of selectorList.split(",")) {
8439
- const sel = selector.trim();
8440
- if (!sel || sel.startsWith("@")) continue;
8441
- if (/^(?:html|:root)$/i.test(sel)) return true;
8530
+ if (selectorList.trim().startsWith("@")) continue;
8531
+ const selectors = ancestorSelectorSteps(selectorList);
8532
+ if (!selectors) return true;
8533
+ for (const steps of selectors) {
8534
+ selectorChecks += steps.length * ancestors.length;
8535
+ if (selectorChecks > MAX_ANCESTOR_SELECTOR_CHECKS) return true;
8442
8536
  try {
8443
- for (const matched of document2.querySelectorAll(sel)) {
8444
- if (ancestors.includes(matched)) return true;
8445
- }
8537
+ if (matchesAnAncestor(steps, ancestors)) return true;
8446
8538
  } catch {
8447
8539
  }
8448
8540
  }
@@ -8432,6 +8432,96 @@ var THREE_D_CONTEXT_PATTERN = /transform-style\s*:\s*preserve-3d|backface-visibi
8432
8432
  function detectThreeDTransformUsage(html) {
8433
8433
  return THREE_D_CONTEXT_PATTERN.test(html);
8434
8434
  }
8435
+ var CSS_ESCAPE = /\\(?:[0-9a-fA-F]{1,6}[ \t\n\r\f]?|[^])?/y;
8436
+ function ancestorSelectorSteps(list) {
8437
+ const selectors = [];
8438
+ let steps = [];
8439
+ let combinators = [];
8440
+ let compound = "";
8441
+ let open = false;
8442
+ let combinator = null;
8443
+ const skipGroup = (at, close) => {
8444
+ let depth = 0;
8445
+ for (let i = at; i < list.length; i++) {
8446
+ const ch = list[i];
8447
+ if (ch === "\\") i++;
8448
+ else if (ch === '"' || ch === "'") {
8449
+ const end = list.indexOf(ch, i + 1);
8450
+ if (end < 0) return -1;
8451
+ i = end;
8452
+ } else if (ch === list[at]) depth++;
8453
+ else if (ch === close && --depth === 0) return i;
8454
+ }
8455
+ return -1;
8456
+ };
8457
+ const flush = () => {
8458
+ if (!open) return;
8459
+ if ((combinator === "+" || combinator === "~") && steps.length > 0) {
8460
+ steps.pop();
8461
+ combinator = combinators.pop() ?? null;
8462
+ }
8463
+ steps.push({ compound: compound || "*", child: combinator === ">" });
8464
+ combinators.push(combinator);
8465
+ compound = "";
8466
+ open = false;
8467
+ combinator = null;
8468
+ };
8469
+ for (let i = 0; i <= list.length; i++) {
8470
+ const ch = list[i];
8471
+ if (ch === void 0 || ch === ",") {
8472
+ flush();
8473
+ if (steps.length) selectors.push(steps);
8474
+ steps = [];
8475
+ combinators = [];
8476
+ combinator = null;
8477
+ } else if (ch === "\\") {
8478
+ CSS_ESCAPE.lastIndex = i;
8479
+ const escape = CSS_ESCAPE.exec(list)[0];
8480
+ compound += escape;
8481
+ i += escape.length - 1;
8482
+ open = true;
8483
+ } else if (ch === "[") {
8484
+ const end = skipGroup(i, "]");
8485
+ if (end < 0) return null;
8486
+ compound += list.slice(i, end + 1);
8487
+ open = true;
8488
+ i = end;
8489
+ } else if (ch === ":") {
8490
+ while (/[:\w-]/.test(list[i + 1] ?? "")) i++;
8491
+ if (list[i + 1] === "(") i = skipGroup(i + 1, ")");
8492
+ if (i < 0) return null;
8493
+ open = true;
8494
+ } else if (/\s/.test(ch)) {
8495
+ flush();
8496
+ if (steps.length) combinator ??= " ";
8497
+ } else if (ch === ">" || ch === "+" || ch === "~") {
8498
+ flush();
8499
+ combinator = ch;
8500
+ } else if (ch === "(" || ch === ")" || ch === "]") {
8501
+ return null;
8502
+ } else {
8503
+ compound += ch;
8504
+ open = true;
8505
+ }
8506
+ }
8507
+ return selectors;
8508
+ }
8509
+ function matchesAnAncestor(steps, ancestors) {
8510
+ let reach = ancestors.map((el) => el.matches(steps[0].compound));
8511
+ for (const step of steps.slice(1)) {
8512
+ let above = false;
8513
+ const next = ancestors.map(() => false);
8514
+ for (let j = ancestors.length - 1; j >= 0; j--) {
8515
+ const placed = step.child ? reach[j + 1] === true : above;
8516
+ next[j] = placed && ancestors[j].matches(step.compound);
8517
+ above ||= reach[j];
8518
+ }
8519
+ reach = next;
8520
+ }
8521
+ return reach.includes(true);
8522
+ }
8523
+ var MAX_ROOT_ANCESTORS = 256;
8524
+ var MAX_ANCESTOR_SELECTOR_CHECKS = 1e5;
8435
8525
  function detectAncestorBackgroundImage(html) {
8436
8526
  const { document: document2 } = parseHTML5(html);
8437
8527
  const root = document2.querySelector("[data-composition-id]");
@@ -8441,6 +8531,8 @@ function detectAncestorBackgroundImage(html) {
8441
8531
  if (document2.documentElement && !ancestors.includes(document2.documentElement)) {
8442
8532
  ancestors.push(document2.documentElement);
8443
8533
  }
8534
+ if (ancestors.length > MAX_ROOT_ANCESTORS) return true;
8535
+ let selectorChecks = 0;
8444
8536
  for (const el of ancestors) {
8445
8537
  const style = el.getAttribute("style");
8446
8538
  if (style && hasBackgroundImageDeclaration(`{${style}}`)) return true;
@@ -8450,14 +8542,14 @@ function detectAncestorBackgroundImage(html) {
8450
8542
  for (const { parts: rule } of cssRuleMatches(css)) {
8451
8543
  const [, selectorList, declarations] = rule;
8452
8544
  if (!hasBackgroundImageDeclaration(`{${declarations}}`)) continue;
8453
- for (const selector of selectorList.split(",")) {
8454
- const sel = selector.trim();
8455
- if (!sel || sel.startsWith("@")) continue;
8456
- if (/^(?:html|:root)$/i.test(sel)) return true;
8545
+ if (selectorList.trim().startsWith("@")) continue;
8546
+ const selectors = ancestorSelectorSteps(selectorList);
8547
+ if (!selectors) return true;
8548
+ for (const steps of selectors) {
8549
+ selectorChecks += steps.length * ancestors.length;
8550
+ if (selectorChecks > MAX_ANCESTOR_SELECTOR_CHECKS) return true;
8457
8551
  try {
8458
- for (const matched of document2.querySelectorAll(sel)) {
8459
- if (ancestors.includes(matched)) return true;
8460
- }
8552
+ if (matchesAnAncestor(steps, ancestors)) return true;
8461
8553
  } catch {
8462
8554
  }
8463
8555
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperframes/producer",
3
- "version": "0.9.82",
3
+ "version": "0.9.83",
4
4
  "description": "HTML-to-video rendering engine using Chrome's BeginFrame API",
5
5
  "repository": {
6
6
  "type": "git",
@@ -35,11 +35,11 @@
35
35
  "postcss": "^8.4.0",
36
36
  "puppeteer": "~25.13.0",
37
37
  "puppeteer-core": "^25.13.0",
38
- "@hyperframes/engine": "0.9.82",
39
- "@hyperframes/lint": "0.9.82",
40
- "@hyperframes/core": "0.9.82",
41
- "@hyperframes/parsers": "0.9.82",
42
- "@hyperframes/studio-server": "0.9.82"
38
+ "@hyperframes/engine": "0.9.83",
39
+ "@hyperframes/lint": "0.9.83",
40
+ "@hyperframes/parsers": "0.9.83",
41
+ "@hyperframes/studio-server": "0.9.83",
42
+ "@hyperframes/core": "0.9.83"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@types/node": "^25.0.10",
@@ -48,7 +48,7 @@
48
48
  "tsx": "^4.21.0",
49
49
  "typescript": "^5.7.2",
50
50
  "vitest": "^4.1.12",
51
- "@hyperframes/aws-lambda": "0.9.82"
51
+ "@hyperframes/aws-lambda": "0.9.83"
52
52
  },
53
53
  "engines": {
54
54
  "node": ">=22"