@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.
package/dist/index.js CHANGED
@@ -2090,13 +2090,44 @@ import {
2090
2090
  rmSync as rmSync2,
2091
2091
  writeFileSync as writeFileSync2
2092
2092
  } from "node:fs";
2093
+ import { execFileSync } from "node:child_process";
2093
2094
  import { hostname, uptime } from "node:os";
2094
- import { basename as basename4, dirname as dirname3, join as join5 } from "node:path";
2095
+ import { basename as basename4, dirname as dirname3, join as join5, win32 } from "node:path";
2095
2096
  import { RENDER_TEMP_DIR } from "@hyperframes/core/project-folders";
2096
2097
  import { createStagingDir } from "@hyperframes/core/atomic-file";
2097
2098
  var OWNER_FILE = "owner.json";
2098
2099
  var TRANSACTION_BACKUP = "backup";
2099
2100
  var RENDER_JOB_DIR = /^[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}$/;
2101
+ var machineIdRead;
2102
+ function machineId() {
2103
+ const read2 = (file, args, pattern) => {
2104
+ try {
2105
+ const out = execFileSync(file, args, {
2106
+ encoding: "utf-8",
2107
+ timeout: 2e3,
2108
+ windowsHide: true
2109
+ });
2110
+ return pattern.exec(out)?.[1];
2111
+ } catch {
2112
+ return void 0;
2113
+ }
2114
+ };
2115
+ if (machineIdRead?.platform === process.platform) return machineIdRead.id;
2116
+ const systemRoot = process.env.SystemRoot;
2117
+ machineIdRead = {
2118
+ platform: process.platform,
2119
+ id: process.platform === "darwin" ? read2(
2120
+ "/usr/sbin/ioreg",
2121
+ ["-rd1", "-c", "IOPlatformExpertDevice"],
2122
+ /"IOPlatformUUID" = "([^"]+)"/
2123
+ ) : process.platform === "win32" && systemRoot && /^[A-Za-z]:\\/.test(systemRoot) ? read2(
2124
+ win32.join(systemRoot, "System32", "reg.exe"),
2125
+ ["query", "HKLM\\SOFTWARE\\Microsoft\\Cryptography", "/v", "MachineGuid"],
2126
+ /MachineGuid\s+REG_SZ\s+(\S+)/
2127
+ ) : void 0
2128
+ };
2129
+ return machineIdRead.id;
2130
+ }
2100
2131
  function pidScope() {
2101
2132
  const attempt = (read2) => {
2102
2133
  try {
@@ -2105,11 +2136,13 @@ function pidScope() {
2105
2136
  return void 0;
2106
2137
  }
2107
2138
  };
2139
+ const bootId = attempt(() => readFileSync2("/proc/sys/kernel/random/boot_id", "utf-8").trim());
2108
2140
  return {
2109
2141
  host: hostname(),
2110
- // Without /proc (macOS, Windows) the boot time, to the minute, stands in for the boot id.
2111
- boot: attempt(() => readFileSync2("/proc/sys/kernel/random/boot_id", "utf-8").trim()) ?? attempt(() => String(Math.round(Date.now() / 6e4 - uptime() / 60))),
2112
- pidns: attempt(() => readlinkSync2("/proc/self/ns/pid"))
2142
+ // Without /proc (macOS, Windows) the boot time in seconds stands in for the boot id, on this machine's own id.
2143
+ boot: bootId ?? attempt(() => `s:${Math.round(Date.now() / 1e3 - uptime())}`),
2144
+ pidns: attempt(() => readlinkSync2("/proc/self/ns/pid")),
2145
+ machine: bootId === void 0 ? machineId() : void 0
2113
2146
  };
2114
2147
  }
2115
2148
  function createOwnedRenderDir(prefix) {
@@ -2128,12 +2161,18 @@ function alive(pid) {
2128
2161
  }
2129
2162
  function knownPidScope() {
2130
2163
  const scope = pidScope();
2131
- const unknown = scope.boot === void 0 || process.platform === "linux" && scope.pidns === void 0;
2164
+ const unknown = scope.boot === void 0 || process.platform === "linux" && scope.pidns === void 0 || scope.boot.startsWith("s:") && scope.machine === void 0;
2132
2165
  return unknown ? void 0 : scope;
2133
2166
  }
2167
+ function sameBoot(stamped, current) {
2168
+ if (stamped === current) return true;
2169
+ const seconds = (boot) => typeof boot === "string" ? /^s:(\d+)$/.exec(boot)?.[1] : void 0;
2170
+ const [a, b] = [seconds(stamped), seconds(current)];
2171
+ return a !== void 0 && b !== void 0 && Math.abs(Number(a) - Number(b)) <= 2;
2172
+ }
2134
2173
  function inThisPidScope(owner) {
2135
2174
  const scope = knownPidScope();
2136
- return scope !== void 0 && owner.host === scope.host && owner.boot === scope.boot && owner.pidns === scope.pidns;
2175
+ return scope !== void 0 && owner.host === scope.host && sameBoot(owner.boot, scope.boot) && owner.pidns === scope.pidns && owner.machine === scope.machine;
2137
2176
  }
2138
2177
  function ownerState(dir) {
2139
2178
  let owner;
@@ -8417,6 +8456,96 @@ var THREE_D_CONTEXT_PATTERN = /transform-style\s*:\s*preserve-3d|backface-visibi
8417
8456
  function detectThreeDTransformUsage(html) {
8418
8457
  return THREE_D_CONTEXT_PATTERN.test(html);
8419
8458
  }
8459
+ var CSS_ESCAPE = /\\(?:[0-9a-fA-F]{1,6}[ \t\n\r\f]?|[^])?/y;
8460
+ function ancestorSelectorSteps(list) {
8461
+ const selectors = [];
8462
+ let steps = [];
8463
+ let combinators = [];
8464
+ let compound = "";
8465
+ let open2 = false;
8466
+ let combinator = null;
8467
+ const skipGroup = (at, close) => {
8468
+ let depth = 0;
8469
+ for (let i = at; i < list.length; i++) {
8470
+ const ch = list[i];
8471
+ if (ch === "\\") i++;
8472
+ else if (ch === '"' || ch === "'") {
8473
+ const end = list.indexOf(ch, i + 1);
8474
+ if (end < 0) return -1;
8475
+ i = end;
8476
+ } else if (ch === list[at]) depth++;
8477
+ else if (ch === close && --depth === 0) return i;
8478
+ }
8479
+ return -1;
8480
+ };
8481
+ const flush = () => {
8482
+ if (!open2) return;
8483
+ if ((combinator === "+" || combinator === "~") && steps.length > 0) {
8484
+ steps.pop();
8485
+ combinator = combinators.pop() ?? null;
8486
+ }
8487
+ steps.push({ compound: compound || "*", child: combinator === ">" });
8488
+ combinators.push(combinator);
8489
+ compound = "";
8490
+ open2 = false;
8491
+ combinator = null;
8492
+ };
8493
+ for (let i = 0; i <= list.length; i++) {
8494
+ const ch = list[i];
8495
+ if (ch === void 0 || ch === ",") {
8496
+ flush();
8497
+ if (steps.length) selectors.push(steps);
8498
+ steps = [];
8499
+ combinators = [];
8500
+ combinator = null;
8501
+ } else if (ch === "\\") {
8502
+ CSS_ESCAPE.lastIndex = i;
8503
+ const escape = CSS_ESCAPE.exec(list)[0];
8504
+ compound += escape;
8505
+ i += escape.length - 1;
8506
+ open2 = true;
8507
+ } else if (ch === "[") {
8508
+ const end = skipGroup(i, "]");
8509
+ if (end < 0) return null;
8510
+ compound += list.slice(i, end + 1);
8511
+ open2 = true;
8512
+ i = end;
8513
+ } else if (ch === ":") {
8514
+ while (/[:\w-]/.test(list[i + 1] ?? "")) i++;
8515
+ if (list[i + 1] === "(") i = skipGroup(i + 1, ")");
8516
+ if (i < 0) return null;
8517
+ open2 = true;
8518
+ } else if (/\s/.test(ch)) {
8519
+ flush();
8520
+ if (steps.length) combinator ??= " ";
8521
+ } else if (ch === ">" || ch === "+" || ch === "~") {
8522
+ flush();
8523
+ combinator = ch;
8524
+ } else if (ch === "(" || ch === ")" || ch === "]") {
8525
+ return null;
8526
+ } else {
8527
+ compound += ch;
8528
+ open2 = true;
8529
+ }
8530
+ }
8531
+ return selectors;
8532
+ }
8533
+ function matchesAnAncestor(steps, ancestors) {
8534
+ let reach = ancestors.map((el) => el.matches(steps[0].compound));
8535
+ for (const step of steps.slice(1)) {
8536
+ let above = false;
8537
+ const next = ancestors.map(() => false);
8538
+ for (let j = ancestors.length - 1; j >= 0; j--) {
8539
+ const placed = step.child ? reach[j + 1] === true : above;
8540
+ next[j] = placed && ancestors[j].matches(step.compound);
8541
+ above ||= reach[j];
8542
+ }
8543
+ reach = next;
8544
+ }
8545
+ return reach.includes(true);
8546
+ }
8547
+ var MAX_ROOT_ANCESTORS = 256;
8548
+ var MAX_ANCESTOR_SELECTOR_CHECKS = 1e5;
8420
8549
  function detectAncestorBackgroundImage(html) {
8421
8550
  const { document: document2 } = parseHTML5(html);
8422
8551
  const root = document2.querySelector("[data-composition-id]");
@@ -8426,6 +8555,8 @@ function detectAncestorBackgroundImage(html) {
8426
8555
  if (document2.documentElement && !ancestors.includes(document2.documentElement)) {
8427
8556
  ancestors.push(document2.documentElement);
8428
8557
  }
8558
+ if (ancestors.length > MAX_ROOT_ANCESTORS) return true;
8559
+ let selectorChecks = 0;
8429
8560
  for (const el of ancestors) {
8430
8561
  const style = el.getAttribute("style");
8431
8562
  if (style && hasBackgroundImageDeclaration(`{${style}}`)) return true;
@@ -8435,14 +8566,14 @@ function detectAncestorBackgroundImage(html) {
8435
8566
  for (const { parts: rule } of cssRuleMatches(css)) {
8436
8567
  const [, selectorList, declarations] = rule;
8437
8568
  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;
8569
+ if (selectorList.trim().startsWith("@")) continue;
8570
+ const selectors = ancestorSelectorSteps(selectorList);
8571
+ if (!selectors) return true;
8572
+ for (const steps of selectors) {
8573
+ selectorChecks += steps.length * ancestors.length;
8574
+ if (selectorChecks > MAX_ANCESTOR_SELECTOR_CHECKS) return true;
8442
8575
  try {
8443
- for (const matched of document2.querySelectorAll(sel)) {
8444
- if (ancestors.includes(matched)) return true;
8445
- }
8576
+ if (matchesAnAncestor(steps, ancestors)) return true;
8446
8577
  } catch {
8447
8578
  }
8448
8579
  }
@@ -2122,12 +2122,43 @@ import {
2122
2122
  rmSync as rmSync2,
2123
2123
  writeFileSync as writeFileSync2
2124
2124
  } from "node:fs";
2125
+ import { execFileSync } from "node:child_process";
2125
2126
  import { hostname, uptime } from "node:os";
2126
- import { basename as basename4, dirname as dirname3, join as join5 } from "node:path";
2127
+ import { basename as basename4, dirname as dirname3, join as join5, win32 } from "node:path";
2127
2128
  import { RENDER_TEMP_DIR } from "@hyperframes/core/project-folders";
2128
2129
  import { createStagingDir } from "@hyperframes/core/atomic-file";
2129
2130
  var OWNER_FILE = "owner.json";
2130
2131
  var TRANSACTION_BACKUP = "backup";
2132
+ var machineIdRead;
2133
+ function machineId() {
2134
+ const read2 = (file, args, pattern) => {
2135
+ try {
2136
+ const out = execFileSync(file, args, {
2137
+ encoding: "utf-8",
2138
+ timeout: 2e3,
2139
+ windowsHide: true
2140
+ });
2141
+ return pattern.exec(out)?.[1];
2142
+ } catch {
2143
+ return void 0;
2144
+ }
2145
+ };
2146
+ if (machineIdRead?.platform === process.platform) return machineIdRead.id;
2147
+ const systemRoot = process.env.SystemRoot;
2148
+ machineIdRead = {
2149
+ platform: process.platform,
2150
+ id: process.platform === "darwin" ? read2(
2151
+ "/usr/sbin/ioreg",
2152
+ ["-rd1", "-c", "IOPlatformExpertDevice"],
2153
+ /"IOPlatformUUID" = "([^"]+)"/
2154
+ ) : process.platform === "win32" && systemRoot && /^[A-Za-z]:\\/.test(systemRoot) ? read2(
2155
+ win32.join(systemRoot, "System32", "reg.exe"),
2156
+ ["query", "HKLM\\SOFTWARE\\Microsoft\\Cryptography", "/v", "MachineGuid"],
2157
+ /MachineGuid\s+REG_SZ\s+(\S+)/
2158
+ ) : void 0
2159
+ };
2160
+ return machineIdRead.id;
2161
+ }
2131
2162
  function pidScope() {
2132
2163
  const attempt = (read2) => {
2133
2164
  try {
@@ -2136,11 +2167,13 @@ function pidScope() {
2136
2167
  return void 0;
2137
2168
  }
2138
2169
  };
2170
+ const bootId = attempt(() => readFileSync2("/proc/sys/kernel/random/boot_id", "utf-8").trim());
2139
2171
  return {
2140
2172
  host: hostname(),
2141
- // Without /proc (macOS, Windows) the boot time, to the minute, stands in for the boot id.
2142
- boot: attempt(() => readFileSync2("/proc/sys/kernel/random/boot_id", "utf-8").trim()) ?? attempt(() => String(Math.round(Date.now() / 6e4 - uptime() / 60))),
2143
- pidns: attempt(() => readlinkSync2("/proc/self/ns/pid"))
2173
+ // Without /proc (macOS, Windows) the boot time in seconds stands in for the boot id, on this machine's own id.
2174
+ boot: bootId ?? attempt(() => `s:${Math.round(Date.now() / 1e3 - uptime())}`),
2175
+ pidns: attempt(() => readlinkSync2("/proc/self/ns/pid")),
2176
+ machine: bootId === void 0 ? machineId() : void 0
2144
2177
  };
2145
2178
  }
2146
2179
  function createOwnedRenderDir(prefix) {
@@ -2159,12 +2192,18 @@ function alive(pid) {
2159
2192
  }
2160
2193
  function knownPidScope() {
2161
2194
  const scope = pidScope();
2162
- const unknown = scope.boot === void 0 || process.platform === "linux" && scope.pidns === void 0;
2195
+ const unknown = scope.boot === void 0 || process.platform === "linux" && scope.pidns === void 0 || scope.boot.startsWith("s:") && scope.machine === void 0;
2163
2196
  return unknown ? void 0 : scope;
2164
2197
  }
2198
+ function sameBoot(stamped, current) {
2199
+ if (stamped === current) return true;
2200
+ const seconds = (boot) => typeof boot === "string" ? /^s:(\d+)$/.exec(boot)?.[1] : void 0;
2201
+ const [a, b] = [seconds(stamped), seconds(current)];
2202
+ return a !== void 0 && b !== void 0 && Math.abs(Number(a) - Number(b)) <= 2;
2203
+ }
2165
2204
  function inThisPidScope(owner) {
2166
2205
  const scope = knownPidScope();
2167
- return scope !== void 0 && owner.host === scope.host && owner.boot === scope.boot && owner.pidns === scope.pidns;
2206
+ return scope !== void 0 && owner.host === scope.host && sameBoot(owner.boot, scope.boot) && owner.pidns === scope.pidns && owner.machine === scope.machine;
2168
2207
  }
2169
2208
  function ownerState(dir) {
2170
2209
  let owner;
@@ -8432,6 +8471,96 @@ var THREE_D_CONTEXT_PATTERN = /transform-style\s*:\s*preserve-3d|backface-visibi
8432
8471
  function detectThreeDTransformUsage(html) {
8433
8472
  return THREE_D_CONTEXT_PATTERN.test(html);
8434
8473
  }
8474
+ var CSS_ESCAPE = /\\(?:[0-9a-fA-F]{1,6}[ \t\n\r\f]?|[^])?/y;
8475
+ function ancestorSelectorSteps(list) {
8476
+ const selectors = [];
8477
+ let steps = [];
8478
+ let combinators = [];
8479
+ let compound = "";
8480
+ let open = false;
8481
+ let combinator = null;
8482
+ const skipGroup = (at, close) => {
8483
+ let depth = 0;
8484
+ for (let i = at; i < list.length; i++) {
8485
+ const ch = list[i];
8486
+ if (ch === "\\") i++;
8487
+ else if (ch === '"' || ch === "'") {
8488
+ const end = list.indexOf(ch, i + 1);
8489
+ if (end < 0) return -1;
8490
+ i = end;
8491
+ } else if (ch === list[at]) depth++;
8492
+ else if (ch === close && --depth === 0) return i;
8493
+ }
8494
+ return -1;
8495
+ };
8496
+ const flush = () => {
8497
+ if (!open) return;
8498
+ if ((combinator === "+" || combinator === "~") && steps.length > 0) {
8499
+ steps.pop();
8500
+ combinator = combinators.pop() ?? null;
8501
+ }
8502
+ steps.push({ compound: compound || "*", child: combinator === ">" });
8503
+ combinators.push(combinator);
8504
+ compound = "";
8505
+ open = false;
8506
+ combinator = null;
8507
+ };
8508
+ for (let i = 0; i <= list.length; i++) {
8509
+ const ch = list[i];
8510
+ if (ch === void 0 || ch === ",") {
8511
+ flush();
8512
+ if (steps.length) selectors.push(steps);
8513
+ steps = [];
8514
+ combinators = [];
8515
+ combinator = null;
8516
+ } else if (ch === "\\") {
8517
+ CSS_ESCAPE.lastIndex = i;
8518
+ const escape = CSS_ESCAPE.exec(list)[0];
8519
+ compound += escape;
8520
+ i += escape.length - 1;
8521
+ open = true;
8522
+ } else if (ch === "[") {
8523
+ const end = skipGroup(i, "]");
8524
+ if (end < 0) return null;
8525
+ compound += list.slice(i, end + 1);
8526
+ open = true;
8527
+ i = end;
8528
+ } else if (ch === ":") {
8529
+ while (/[:\w-]/.test(list[i + 1] ?? "")) i++;
8530
+ if (list[i + 1] === "(") i = skipGroup(i + 1, ")");
8531
+ if (i < 0) return null;
8532
+ open = true;
8533
+ } else if (/\s/.test(ch)) {
8534
+ flush();
8535
+ if (steps.length) combinator ??= " ";
8536
+ } else if (ch === ">" || ch === "+" || ch === "~") {
8537
+ flush();
8538
+ combinator = ch;
8539
+ } else if (ch === "(" || ch === ")" || ch === "]") {
8540
+ return null;
8541
+ } else {
8542
+ compound += ch;
8543
+ open = true;
8544
+ }
8545
+ }
8546
+ return selectors;
8547
+ }
8548
+ function matchesAnAncestor(steps, ancestors) {
8549
+ let reach = ancestors.map((el) => el.matches(steps[0].compound));
8550
+ for (const step of steps.slice(1)) {
8551
+ let above = false;
8552
+ const next = ancestors.map(() => false);
8553
+ for (let j = ancestors.length - 1; j >= 0; j--) {
8554
+ const placed = step.child ? reach[j + 1] === true : above;
8555
+ next[j] = placed && ancestors[j].matches(step.compound);
8556
+ above ||= reach[j];
8557
+ }
8558
+ reach = next;
8559
+ }
8560
+ return reach.includes(true);
8561
+ }
8562
+ var MAX_ROOT_ANCESTORS = 256;
8563
+ var MAX_ANCESTOR_SELECTOR_CHECKS = 1e5;
8435
8564
  function detectAncestorBackgroundImage(html) {
8436
8565
  const { document: document2 } = parseHTML5(html);
8437
8566
  const root = document2.querySelector("[data-composition-id]");
@@ -8441,6 +8570,8 @@ function detectAncestorBackgroundImage(html) {
8441
8570
  if (document2.documentElement && !ancestors.includes(document2.documentElement)) {
8442
8571
  ancestors.push(document2.documentElement);
8443
8572
  }
8573
+ if (ancestors.length > MAX_ROOT_ANCESTORS) return true;
8574
+ let selectorChecks = 0;
8444
8575
  for (const el of ancestors) {
8445
8576
  const style = el.getAttribute("style");
8446
8577
  if (style && hasBackgroundImageDeclaration(`{${style}}`)) return true;
@@ -8450,14 +8581,14 @@ function detectAncestorBackgroundImage(html) {
8450
8581
  for (const { parts: rule } of cssRuleMatches(css)) {
8451
8582
  const [, selectorList, declarations] = rule;
8452
8583
  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;
8584
+ if (selectorList.trim().startsWith("@")) continue;
8585
+ const selectors = ancestorSelectorSteps(selectorList);
8586
+ if (!selectors) return true;
8587
+ for (const steps of selectors) {
8588
+ selectorChecks += steps.length * ancestors.length;
8589
+ if (selectorChecks > MAX_ANCESTOR_SELECTOR_CHECKS) return true;
8457
8590
  try {
8458
- for (const matched of document2.querySelectorAll(sel)) {
8459
- if (ancestors.includes(matched)) return true;
8460
- }
8591
+ if (matchesAnAncestor(steps, ancestors)) return true;
8461
8592
  } catch {
8462
8593
  }
8463
8594
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperframes/producer",
3
- "version": "0.9.82",
3
+ "version": "0.9.84",
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/core": "0.9.84",
39
+ "@hyperframes/engine": "0.9.84",
40
+ "@hyperframes/lint": "0.9.84",
41
+ "@hyperframes/studio-server": "0.9.84",
42
+ "@hyperframes/parsers": "0.9.84"
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.84"
52
52
  },
53
53
  "engines": {
54
54
  "node": ">=22"