@hyperframes/studio-server 0.8.134 → 0.8.136

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
@@ -3597,7 +3597,7 @@ function registerFileRoutes(api, adapter) {
3597
3597
  }
3598
3598
 
3599
3599
  // src/routes/preview.ts
3600
- import { parseHTML as parseHTML6 } from "linkedom";
3600
+ import { parseHTML as parseHTML7 } from "linkedom";
3601
3601
  import { createReadStream, existsSync as existsSync5, readFileSync as readFileSync6, statSync as statSync4 } from "fs";
3602
3602
  import { Readable } from "stream";
3603
3603
  import { join as join8, resolve as resolve4 } from "path";
@@ -3619,8 +3619,13 @@ import { ensureHfIds as ensureHfIds2 } from "@hyperframes/parsers/hf-ids";
3619
3619
  // src/helpers/previewReads.ts
3620
3620
  import { readlinkSync as readlinkSync2 } from "fs";
3621
3621
  import { dirname as dirname4, join as join7, parse, relative as relative3, resolve as resolve3 } from "path";
3622
+ import { parseHTML as parseHTML5 } from "linkedom";
3622
3623
  var ALWAYS_AFFECTS = ["hyperframes.json", ...STUDIO_SIGNATURE_MANIFEST_PATHS];
3624
+ var MAX_PREVIEW_PATH_LENGTH = 4096;
3625
+ var SHOW_ELEMENT = 1;
3623
3626
  var REFERENCE = /\b(?:src|href|poster|data-composition-src)\s*=\s*(?:"([^"\n]*)"|'([^'\n]*)')|url\(\s*(?:"([^"\n]*)"|'([^'\n]*)'|([^"'\s)]+))/gi;
3627
+ var REFERENCE_ATTRIBUTE = /\b(?:src|href|poster|data-composition-src)$/i;
3628
+ var isElement = (node) => node.nodeType === 1;
3624
3629
  var pathKey = process.platform === "darwin" || process.platform === "win32" ? (path) => resolve3(path).toLowerCase() : (path) => resolve3(path);
3625
3630
  var readsByProject = /* @__PURE__ */ new Map();
3626
3631
  var builtProjects = /* @__PURE__ */ new Set();
@@ -3645,6 +3650,7 @@ function linksOnTheWay(path) {
3645
3650
  continue;
3646
3651
  }
3647
3652
  const next = join7(at, part);
3653
+ if (next.length > MAX_PREVIEW_PATH_LENGTH) return passed;
3648
3654
  const target = hops < 40 ? readLink(next) : null;
3649
3655
  if (target === null) {
3650
3656
  at = next;
@@ -3660,26 +3666,51 @@ function linksOnTheWay(path) {
3660
3666
  return passed;
3661
3667
  }
3662
3668
  function recordPreviewRead(projectDir, filePath) {
3669
+ if (filePath.length > MAX_PREVIEW_PATH_LENGTH) return;
3663
3670
  const key = projectKey(projectDir);
3664
3671
  let reads = readsByProject.get(key);
3665
3672
  if (!reads) readsByProject.set(key, reads = /* @__PURE__ */ new Set());
3666
3673
  const read = inRealProject(projectDir, filePath);
3674
+ if (read.length > MAX_PREVIEW_PATH_LENGTH) return;
3667
3675
  for (const found of [read, ...linksOnTheWay(read)]) {
3668
3676
  for (let path = pathKey(found); !reads.has(path); path = dirname4(path)) reads.add(path);
3669
3677
  }
3670
3678
  }
3671
3679
  function recordPreviewReferences(projectDir, html) {
3672
3680
  const named = /* @__PURE__ */ new Set();
3673
- for (const match of html.matchAll(REFERENCE)) {
3674
- const url = (match[1] ?? match[2] ?? match[3] ?? match[4] ?? match[5] ?? "").trim();
3675
- if (!url || /^(?:[a-z][a-z0-9+.-]*:|[/#])/i.test(url)) continue;
3681
+ const add = (reference) => {
3682
+ const url = reference.trim();
3683
+ if (!url || /^(?:[a-z][a-z0-9+.-]*:|[/#])/i.test(url)) return;
3676
3684
  const path = url.split(/[?#]/)[0] ?? "";
3677
3685
  let decoded = path;
3678
3686
  try {
3679
3687
  decoded = decodeURIComponent(path);
3680
3688
  } catch {
3681
3689
  }
3682
- if (decoded) named.add(decoded);
3690
+ if (decoded && decoded.length <= MAX_PREVIEW_PATH_LENGTH) named.add(decoded);
3691
+ };
3692
+ const scan = (text2) => {
3693
+ for (const match of text2.matchAll(REFERENCE)) {
3694
+ add(match[1] ?? match[2] ?? match[3] ?? match[4] ?? match[5] ?? "");
3695
+ }
3696
+ };
3697
+ const scanElement = (element) => {
3698
+ for (const attribute of element.attributes) {
3699
+ if (REFERENCE_ATTRIBUTE.test(attribute.name)) add(attribute.value);
3700
+ }
3701
+ const style = element.getAttribute("style");
3702
+ if (style) scan(style);
3703
+ if (element.localName === "style" || element.localName === "script") {
3704
+ scan(element.textContent ?? "");
3705
+ }
3706
+ };
3707
+ const { document } = parseHTML5(html);
3708
+ for (const root of document.children) {
3709
+ scanElement(root);
3710
+ const elements = document.createTreeWalker(root, SHOW_ELEMENT);
3711
+ for (let node = elements.nextNode(); node; node = elements.nextNode()) {
3712
+ if (isElement(node)) scanElement(node);
3713
+ }
3683
3714
  }
3684
3715
  for (const path of named) recordPreviewRead(projectDir, path);
3685
3716
  }
@@ -3717,7 +3748,7 @@ function injectPreviewVariables(html, values) {
3717
3748
 
3718
3749
  // src/helpers/lazyPreviewImages.ts
3719
3750
  import { findStartTags } from "@hyperframes/core/compiler/html-document";
3720
- import { parseHTML as parseHTML5 } from "linkedom";
3751
+ import { parseHTML as parseHTML6 } from "linkedom";
3721
3752
  import { STUDIO_PREVIEW_LAZY_ATTR } from "@hyperframes/core/studio-preview-mark";
3722
3753
  function startsAfterZero(el) {
3723
3754
  for (let node = el; node; node = node.parentElement) {
@@ -3728,7 +3759,7 @@ function startsAfterZero(el) {
3728
3759
  var hasLoading = (img) => Array.from(img.attributes).some((attr) => attr.name.toLowerCase() === "loading");
3729
3760
  function lazyPreviewImages(html) {
3730
3761
  if (!/<!doctype|<html[\s>]/i.test(html)) return html;
3731
- const images = [...parseHTML5(html).document.querySelectorAll("img")];
3762
+ const images = [...parseHTML6(html).document.querySelectorAll("img")];
3732
3763
  const tags = findStartTags(html, "img");
3733
3764
  if (tags.length !== images.length) return html;
3734
3765
  const parts = [];
@@ -3819,7 +3850,7 @@ function isGsapCoreUrl(src) {
3819
3850
  return URL.canParse(src, base) && /\/gsap(\.min)?\.js$/i.test(new URL(src, base).pathname);
3820
3851
  }
3821
3852
  function findGsapCoreScript(html) {
3822
- const scripts = [...parseHTML6(html).document.querySelectorAll("script")];
3853
+ const scripts = [...parseHTML7(html).document.querySelectorAll("script")];
3823
3854
  const starts = findStartTags2(html, "script");
3824
3855
  if (starts.length !== scripts.length) return null;
3825
3856
  const at = scripts.findIndex(