@hyperframes/parsers 0.9.56 → 0.9.59

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.
@@ -46,5 +46,11 @@ declare function findFfBinary(name: FfBinaryName, options?: FindFfBinaryOptions)
46
46
  declare function requireFfBinary(name: FfBinaryName): string;
47
47
  /** Test hook: drop cached system lookups so resolution can be re-exercised. */
48
48
  declare function clearFfBinaryLookupCache(): void;
49
+ /** What a render service lets a media input open: containers that name no other file. */
50
+ declare const SELF_CONTAINED_FORMATS = "mov,matroska,mxf,avi,mpeg,mpegts,mpegvideo,flv,asf,ogg,wav,mp3,aac,flac,aiff,gif,image2,png_pipe,jpeg_pipe,webp_pipe,bmp_pipe,tiff_pipe";
51
+ /** Tests feed a `-demuxers` listing so none spawns a binary; no argument forgets it. */
52
+ declare function _setDemuxerListingForTests(listing?: string): void;
53
+ /** Every demuxer `listingBinary` reports that opens nothing by itself and is not text art; one that cannot be asked gets the self-contained list, and is asked again. */
54
+ declare function mediaInputFormatArgs(listingBinary: string): string[];
49
55
 
50
- export { FFMPEG_PATH_ENV, FFPROBE_PATH_ENV, type FfBinaryName, type FindFfBinaryOptions, clearFfBinaryLookupCache, executableIn, findFfBinary, findTrustedExecutable, getSkippedX86Binary, isTrustedDirectory, isTrustedExecutablePath, isX86OnlyMachO, pathEntries, requireFfBinary, trustedPathDirs };
56
+ export { FFMPEG_PATH_ENV, FFPROBE_PATH_ENV, type FfBinaryName, type FindFfBinaryOptions, SELF_CONTAINED_FORMATS, _setDemuxerListingForTests, clearFfBinaryLookupCache, executableIn, findFfBinary, findTrustedExecutable, getSkippedX86Binary, isTrustedDirectory, isTrustedExecutablePath, isX86OnlyMachO, mediaInputFormatArgs, pathEntries, requireFfBinary, trustedPathDirs };
@@ -1,4 +1,5 @@
1
1
  // src/ffBinaries.ts
2
+ import { execFileSync } from "child_process";
2
3
  import {
3
4
  accessSync as accessSync2,
4
5
  closeSync,
@@ -275,9 +276,66 @@ function clearFfBinaryLookupCache() {
275
276
  lastMissAt.clear();
276
277
  skippedX86Binaries.clear();
277
278
  }
279
+ var SELF_CONTAINED_FORMATS = "mov,matroska,mxf,avi,mpeg,mpegts,mpegvideo,flv,asf,ogg,wav,mp3,aac,flac,aiff,gif,image2,png_pipe,jpeg_pipe,webp_pipe,bmp_pipe,tiff_pipe";
280
+ var PATH_OPENING_DEMUXERS = /* @__PURE__ */ new Set([
281
+ "dash",
282
+ "imf",
283
+ "mlv",
284
+ "vobsub",
285
+ "dvdvideo",
286
+ "sdp",
287
+ "rtsp",
288
+ "rtp",
289
+ "sap",
290
+ "avisynth",
291
+ "vapoursynth",
292
+ "lavfi"
293
+ ]);
294
+ var TEXT_ART_DEMUXERS = /* @__PURE__ */ new Set(["tty", "bin", "xbin", "idf", "adf"]);
295
+ function demuxersFromListing(listing) {
296
+ const row = /Is a device/.test(listing) ? /^ D[E ]([d ]) (\S+)/ : /^ D[E ]() (\S+)/;
297
+ const names = /* @__PURE__ */ new Set();
298
+ for (const line of listing.split("\n")) {
299
+ const match = row.exec(line);
300
+ if (!match || match[1] === "d") continue;
301
+ const aliases = match[2].split(",");
302
+ if (aliases.some((alias) => PATH_OPENING_DEMUXERS.has(alias) || TEXT_ART_DEMUXERS.has(alias)))
303
+ continue;
304
+ for (const alias of aliases) names.add(alias);
305
+ }
306
+ return names.size > 0 ? [...names].join(",") : void 0;
307
+ }
308
+ var demuxerLists = /* @__PURE__ */ new Map();
309
+ var listingOverride;
310
+ function _setDemuxerListingForTests(listing) {
311
+ listingOverride = listing;
312
+ demuxerLists.clear();
313
+ }
314
+ function mediaInputFormatArgs(listingBinary) {
315
+ let formats = demuxerLists.get(listingBinary);
316
+ if (formats === void 0) {
317
+ try {
318
+ formats = demuxersFromListing(
319
+ listingOverride ?? execFileSync(listingBinary, ["-hide_banner", "-demuxers"], {
320
+ encoding: "utf8",
321
+ timeout: 1e4,
322
+ windowsHide: true,
323
+ stdio: ["ignore", "pipe", "ignore"]
324
+ })
325
+ );
326
+ } catch {
327
+ formats = void 0;
328
+ }
329
+ if (formats === void 0) return ["-format_whitelist", SELF_CONTAINED_FORMATS];
330
+ demuxerLists.set(listingBinary, formats);
331
+ }
332
+ return ["-format_whitelist", formats];
333
+ }
278
334
  export {
279
335
  FFMPEG_PATH_ENV,
280
336
  FFPROBE_PATH_ENV,
337
+ SELF_CONTAINED_FORMATS,
338
+ _setDemuxerListingForTests,
281
339
  clearFfBinaryLookupCache,
282
340
  executableIn,
283
341
  findFfBinary,
@@ -286,6 +344,7 @@ export {
286
344
  isTrustedDirectory,
287
345
  isTrustedExecutablePath,
288
346
  isX86OnlyMachO,
347
+ mediaInputFormatArgs,
289
348
  pathEntries,
290
349
  requireFfBinary,
291
350
  trustedPathDirs
@@ -120,6 +120,9 @@ var FUNCTION_TYPES = /* @__PURE__ */ new Set([
120
120
  var GSAP_METHODS = /* @__PURE__ */ new Set(["set", "to", "from", "fromTo"]);
121
121
  var MAX_DEPTH = 8;
122
122
  var MAX_ITERS = 512;
123
+ var MAX_EXPANDED_NODES = 25e4;
124
+ var ExpansionBudgetExceeded = class extends Error {
125
+ };
123
126
  function isFunctionNode(node) {
124
127
  return !!node && FUNCTION_TYPES.has(node.type);
125
128
  }
@@ -355,8 +358,11 @@ function undefinedIdentifier() {
355
358
  function isExplicitUndefined(node) {
356
359
  return node?.type === "Identifier" && node.name === "undefined" || node?.type === "UnaryExpression" && node.operator === "void" && node.argument?.type === "Literal" && node.argument.value === 0;
357
360
  }
358
- function resolveHelperBindings(call, params) {
359
- if (call.arguments?.some((arg) => arg?.type === "SpreadElement")) return null;
361
+ function hasSpreadArgument(call) {
362
+ return !!call.arguments?.some((arg) => arg?.type === "SpreadElement");
363
+ }
364
+ function resolveHelperBindings(call, params, ctx) {
365
+ if (hasSpreadArgument(call)) return null;
360
366
  const bindings = /* @__PURE__ */ new Map();
361
367
  for (let i = 0; i < params.length; i++) {
362
368
  const param = params[i];
@@ -364,6 +370,7 @@ function resolveHelperBindings(call, params) {
364
370
  if (arg && !isExplicitUndefined(arg)) {
365
371
  bindings.set(param.name, arg);
366
372
  } else if (param.defaultExpression) {
373
+ chargeBudget([param.defaultExpression], bindings, ctx);
367
374
  bindings.set(param.name, substituteParams(cloneNode(param.defaultExpression), bindings));
368
375
  } else {
369
376
  bindings.set(param.name, undefinedIdentifier());
@@ -391,7 +398,7 @@ function safelyDroppable(program, candidates) {
391
398
  bump(stmtCalls, call.callee.name);
392
399
  const fn = candidates.get(call.callee.name);
393
400
  const params = fn && supportedParams(fn);
394
- if (!params || !resolveHelperBindings(call, params)) unbindable.add(call.callee.name);
401
+ if (!params || hasSpreadArgument(call)) unbindable.add(call.callee.name);
395
402
  });
396
403
  const safe = /* @__PURE__ */ new Map();
397
404
  for (const [name, fn] of candidates) {
@@ -436,7 +443,26 @@ function tagTimelineCalls(stmts, prov, ctx) {
436
443
  }
437
444
  }
438
445
  }
446
+ function nodeCount(root) {
447
+ let n = 0;
448
+ walkNodes(root, () => n++);
449
+ return n;
450
+ }
451
+ function chargeBudget(stmts, bindings, ctx, fixedCost = 0) {
452
+ const bindingSize = /* @__PURE__ */ new Map();
453
+ ctx.budget.left -= fixedCost;
454
+ for (const stmt of stmts) {
455
+ walkNodes(stmt, (n) => {
456
+ ctx.budget.left--;
457
+ if (n.type !== "Identifier" || !bindings.has(n.name)) return;
458
+ if (!bindingSize.has(n.name)) bindingSize.set(n.name, nodeCount(bindings.get(n.name)));
459
+ ctx.budget.left -= bindingSize.get(n.name);
460
+ });
461
+ }
462
+ if (ctx.budget.left < 0) throw new ExpansionBudgetExceeded();
463
+ }
439
464
  function expandBody(bodyStmts, bindings, prov, ctx) {
465
+ chargeBudget(bodyStmts, bindings, ctx, 1 + bindings.size);
440
466
  const block = substituteParams(cloneNode({ type: "BlockStatement", body: bodyStmts }), bindings);
441
467
  tagProvenance(block, prov);
442
468
  tagTimelineCalls(block.body, prov, ctx);
@@ -448,7 +474,7 @@ function inlineHelper(call, ctx) {
448
474
  if (!fn) return null;
449
475
  const params = supportedParams(fn);
450
476
  if (!params) return null;
451
- const bindings = resolveHelperBindings(call, params);
477
+ const bindings = resolveHelperBindings(call, params, ctx);
452
478
  if (!bindings) return null;
453
479
  const prov = {
454
480
  kind: "helper",
@@ -509,10 +535,13 @@ function unrollFor(stmt, ctx) {
509
535
  if (!h) return null;
510
536
  const body = bodyStatements(stmt.body);
511
537
  const out = [];
538
+ let count = 0;
539
+ for (let x = h.start; loopSatisfied(h.op, x, h.end); x += h.step) {
540
+ if (++count > MAX_ITERS) return null;
541
+ }
512
542
  const site = ++ctx.site.n;
513
543
  let iteration = 0;
514
544
  for (let x = h.start; loopSatisfied(h.op, x, h.end); x += h.step) {
515
- if (iteration >= MAX_ITERS) return null;
516
545
  const prov = {
517
546
  kind: "loop",
518
547
  callSite: site,
@@ -532,6 +561,7 @@ function forOfVarName(left) {
532
561
  return left?.type === "Identifier" ? left.name : null;
533
562
  }
534
563
  function unrollOverArray(elements, body, elName, idxName, range, ctx) {
564
+ if (elements.length > MAX_ITERS) return null;
535
565
  const out = [];
536
566
  const site = ++ctx.site.n;
537
567
  elements.forEach((el, i) => {
@@ -621,13 +651,18 @@ function inlineComputedTimelines(ast, timelineVar, resolve) {
621
651
  depth: 0,
622
652
  site: { n: 0 },
623
653
  order: { n: 0 },
624
- rootStart: 0
654
+ rootStart: 0,
655
+ budget: { left: MAX_EXPANDED_NODES }
625
656
  };
626
657
  const body = (ast.body ?? []).filter((stmt) => !isHelperDecl(stmt, helpers));
627
- ast.body = body.flatMap((stmt) => {
628
- ctx.rootStart = stmt.start;
629
- return expandStatements([stmt], ctx);
630
- });
658
+ try {
659
+ ast.body = body.flatMap((stmt) => {
660
+ ctx.rootStart = stmt.start;
661
+ return expandStatements([stmt], ctx);
662
+ });
663
+ } catch (error) {
664
+ if (!(error instanceof ExpansionBudgetExceeded)) throw error;
665
+ }
631
666
  }
632
667
 
633
668
  // src/gsapObjectArrayTiming.ts
@@ -462,6 +462,9 @@ var FUNCTION_TYPES = /* @__PURE__ */ new Set([
462
462
  var GSAP_METHODS = /* @__PURE__ */ new Set(["set", "to", "from", "fromTo"]);
463
463
  var MAX_DEPTH = 8;
464
464
  var MAX_ITERS = 512;
465
+ var MAX_EXPANDED_NODES = 25e4;
466
+ var ExpansionBudgetExceeded = class extends Error {
467
+ };
465
468
  function isFunctionNode(node) {
466
469
  return !!node && FUNCTION_TYPES.has(node.type);
467
470
  }
@@ -697,8 +700,11 @@ function undefinedIdentifier() {
697
700
  function isExplicitUndefined(node) {
698
701
  return node?.type === "Identifier" && node.name === "undefined" || node?.type === "UnaryExpression" && node.operator === "void" && node.argument?.type === "Literal" && node.argument.value === 0;
699
702
  }
700
- function resolveHelperBindings(call, params) {
701
- if (call.arguments?.some((arg) => arg?.type === "SpreadElement")) return null;
703
+ function hasSpreadArgument(call) {
704
+ return !!call.arguments?.some((arg) => arg?.type === "SpreadElement");
705
+ }
706
+ function resolveHelperBindings(call, params, ctx) {
707
+ if (hasSpreadArgument(call)) return null;
702
708
  const bindings = /* @__PURE__ */ new Map();
703
709
  for (let i = 0; i < params.length; i++) {
704
710
  const param = params[i];
@@ -706,6 +712,7 @@ function resolveHelperBindings(call, params) {
706
712
  if (arg && !isExplicitUndefined(arg)) {
707
713
  bindings.set(param.name, arg);
708
714
  } else if (param.defaultExpression) {
715
+ chargeBudget([param.defaultExpression], bindings, ctx);
709
716
  bindings.set(param.name, substituteParams(cloneNode(param.defaultExpression), bindings));
710
717
  } else {
711
718
  bindings.set(param.name, undefinedIdentifier());
@@ -733,7 +740,7 @@ function safelyDroppable(program, candidates) {
733
740
  bump(stmtCalls, call.callee.name);
734
741
  const fn = candidates.get(call.callee.name);
735
742
  const params = fn && supportedParams(fn);
736
- if (!params || !resolveHelperBindings(call, params)) unbindable.add(call.callee.name);
743
+ if (!params || hasSpreadArgument(call)) unbindable.add(call.callee.name);
737
744
  });
738
745
  const safe = /* @__PURE__ */ new Map();
739
746
  for (const [name, fn] of candidates) {
@@ -778,7 +785,26 @@ function tagTimelineCalls(stmts, prov, ctx) {
778
785
  }
779
786
  }
780
787
  }
788
+ function nodeCount(root) {
789
+ let n = 0;
790
+ walkNodes(root, () => n++);
791
+ return n;
792
+ }
793
+ function chargeBudget(stmts, bindings, ctx, fixedCost = 0) {
794
+ const bindingSize = /* @__PURE__ */ new Map();
795
+ ctx.budget.left -= fixedCost;
796
+ for (const stmt of stmts) {
797
+ walkNodes(stmt, (n) => {
798
+ ctx.budget.left--;
799
+ if (n.type !== "Identifier" || !bindings.has(n.name)) return;
800
+ if (!bindingSize.has(n.name)) bindingSize.set(n.name, nodeCount(bindings.get(n.name)));
801
+ ctx.budget.left -= bindingSize.get(n.name);
802
+ });
803
+ }
804
+ if (ctx.budget.left < 0) throw new ExpansionBudgetExceeded();
805
+ }
781
806
  function expandBody(bodyStmts, bindings, prov, ctx) {
807
+ chargeBudget(bodyStmts, bindings, ctx, 1 + bindings.size);
782
808
  const block = substituteParams(cloneNode({ type: "BlockStatement", body: bodyStmts }), bindings);
783
809
  tagProvenance(block, prov);
784
810
  tagTimelineCalls(block.body, prov, ctx);
@@ -790,7 +816,7 @@ function inlineHelper(call, ctx) {
790
816
  if (!fn) return null;
791
817
  const params = supportedParams(fn);
792
818
  if (!params) return null;
793
- const bindings = resolveHelperBindings(call, params);
819
+ const bindings = resolveHelperBindings(call, params, ctx);
794
820
  if (!bindings) return null;
795
821
  const prov = {
796
822
  kind: "helper",
@@ -851,10 +877,13 @@ function unrollFor(stmt, ctx) {
851
877
  if (!h) return null;
852
878
  const body = bodyStatements(stmt.body);
853
879
  const out = [];
880
+ let count = 0;
881
+ for (let x = h.start; loopSatisfied(h.op, x, h.end); x += h.step) {
882
+ if (++count > MAX_ITERS) return null;
883
+ }
854
884
  const site = ++ctx.site.n;
855
885
  let iteration = 0;
856
886
  for (let x = h.start; loopSatisfied(h.op, x, h.end); x += h.step) {
857
- if (iteration >= MAX_ITERS) return null;
858
887
  const prov = {
859
888
  kind: "loop",
860
889
  callSite: site,
@@ -874,6 +903,7 @@ function forOfVarName(left) {
874
903
  return left?.type === "Identifier" ? left.name : null;
875
904
  }
876
905
  function unrollOverArray(elements, body, elName, idxName, range, ctx) {
906
+ if (elements.length > MAX_ITERS) return null;
877
907
  const out = [];
878
908
  const site = ++ctx.site.n;
879
909
  elements.forEach((el, i) => {
@@ -963,13 +993,18 @@ function inlineComputedTimelines(ast, timelineVar, resolve) {
963
993
  depth: 0,
964
994
  site: { n: 0 },
965
995
  order: { n: 0 },
966
- rootStart: 0
996
+ rootStart: 0,
997
+ budget: { left: MAX_EXPANDED_NODES }
967
998
  };
968
999
  const body = (ast.body ?? []).filter((stmt) => !isHelperDecl(stmt, helpers));
969
- ast.body = body.flatMap((stmt) => {
970
- ctx.rootStart = stmt.start;
971
- return expandStatements([stmt], ctx);
972
- });
1000
+ try {
1001
+ ast.body = body.flatMap((stmt) => {
1002
+ ctx.rootStart = stmt.start;
1003
+ return expandStatements([stmt], ctx);
1004
+ });
1005
+ } catch (error) {
1006
+ if (!(error instanceof ExpansionBudgetExceeded)) throw error;
1007
+ }
973
1008
  }
974
1009
 
975
1010
  // src/gsapParserAcorn.ts
package/dist/hfIds.d.ts CHANGED
@@ -1,17 +1,4 @@
1
1
  declare const EXCLUDED_TAGS: Set<string>;
2
- /**
3
- * Collision tiebreak for byte-identical siblings: document-order dup counter
4
- * (`hash(key#N)`). This IS order-dependent — two identical `<span></span>`
5
- * get different ids based on which comes first in the DOM. This is unavoidable:
6
- * unique ids for byte-identical elements require a positional signal.
7
- *
8
- * Why this is safe in practice: once `data-hf-id` is on disk (stamped at project open, or by the
9
- * first save) it is bound to its element, so reordering identical siblings carries it along, and
10
- * `ensureHfIds` skips pinned elements (`if (getContractAttribute(el, "data-hf-id")) continue`).
11
- * Before that, an outside edit changes what is minted (an element's attributes or own text, or a
12
- * twin added or removed), so a save carrying an id served before the edit misses or hits the other
13
- * twin until the watcher reloads the preview.
14
- */
15
2
  declare function mintHfId(el: Element, assigned: Set<string>): string;
16
3
  declare function isCompositionTemplate(el: Element): boolean;
17
4
  /**
package/dist/hfIds.js CHANGED
@@ -39,20 +39,17 @@ function contentKey(el) {
39
39
  const attrs = Array.from(el.attributes).filter((a) => !a.name.toLowerCase().startsWith("data-hf-")).map((a) => `${a.name.toLowerCase()}\0${a.value}`).sort().join("");
40
40
  return `${el.tagName.toLowerCase()}|${attrs}|${ownText(el)}`;
41
41
  }
42
+ function dupId(key, dup) {
43
+ if (dup > 1e4) return `hf-${(fnv1a(key) >>> 0).toString(36)}-${dup}`;
44
+ return toHfId(fnv1a(dup ? `${key}#${dup}` : key));
45
+ }
42
46
  function mintHfId(el, assigned) {
43
47
  const key = contentKey(el);
44
48
  const twins = lastDup.get(assigned) ?? /* @__PURE__ */ new Map();
45
49
  lastDup.set(assigned, twins);
46
50
  let dup = twins.get(key) ?? 0;
47
- let id = dup > 1e4 ? `hf-${(fnv1a(key) >>> 0).toString(36)}-${dup}` : toHfId(fnv1a(dup ? `${key}#${dup}` : key));
48
- while (dup <= 1e4 && assigned.has(id)) {
49
- dup += 1;
50
- if (dup > 1e4) {
51
- id = `hf-${(fnv1a(key) >>> 0).toString(36)}-${dup}`;
52
- break;
53
- }
54
- id = toHfId(fnv1a(`${key}#${dup}`));
55
- }
51
+ let id = dupId(key, dup);
52
+ while (assigned.has(id)) id = dupId(key, ++dup);
56
53
  twins.set(key, dup);
57
54
  assigned.add(id);
58
55
  return id;
package/dist/index.js CHANGED
@@ -579,6 +579,9 @@ var FUNCTION_TYPES = /* @__PURE__ */ new Set([
579
579
  var GSAP_METHODS = /* @__PURE__ */ new Set(["set", "to", "from", "fromTo"]);
580
580
  var MAX_DEPTH = 8;
581
581
  var MAX_ITERS = 512;
582
+ var MAX_EXPANDED_NODES = 25e4;
583
+ var ExpansionBudgetExceeded = class extends Error {
584
+ };
582
585
  function isFunctionNode(node) {
583
586
  return !!node && FUNCTION_TYPES.has(node.type);
584
587
  }
@@ -814,8 +817,11 @@ function undefinedIdentifier() {
814
817
  function isExplicitUndefined(node) {
815
818
  return node?.type === "Identifier" && node.name === "undefined" || node?.type === "UnaryExpression" && node.operator === "void" && node.argument?.type === "Literal" && node.argument.value === 0;
816
819
  }
817
- function resolveHelperBindings(call, params) {
818
- if (call.arguments?.some((arg) => arg?.type === "SpreadElement")) return null;
820
+ function hasSpreadArgument(call) {
821
+ return !!call.arguments?.some((arg) => arg?.type === "SpreadElement");
822
+ }
823
+ function resolveHelperBindings(call, params, ctx) {
824
+ if (hasSpreadArgument(call)) return null;
819
825
  const bindings = /* @__PURE__ */ new Map();
820
826
  for (let i = 0; i < params.length; i++) {
821
827
  const param = params[i];
@@ -823,6 +829,7 @@ function resolveHelperBindings(call, params) {
823
829
  if (arg && !isExplicitUndefined(arg)) {
824
830
  bindings.set(param.name, arg);
825
831
  } else if (param.defaultExpression) {
832
+ chargeBudget([param.defaultExpression], bindings, ctx);
826
833
  bindings.set(param.name, substituteParams(cloneNode(param.defaultExpression), bindings));
827
834
  } else {
828
835
  bindings.set(param.name, undefinedIdentifier());
@@ -850,7 +857,7 @@ function safelyDroppable(program, candidates) {
850
857
  bump(stmtCalls, call.callee.name);
851
858
  const fn = candidates.get(call.callee.name);
852
859
  const params = fn && supportedParams(fn);
853
- if (!params || !resolveHelperBindings(call, params)) unbindable.add(call.callee.name);
860
+ if (!params || hasSpreadArgument(call)) unbindable.add(call.callee.name);
854
861
  });
855
862
  const safe = /* @__PURE__ */ new Map();
856
863
  for (const [name, fn] of candidates) {
@@ -895,7 +902,26 @@ function tagTimelineCalls(stmts, prov, ctx) {
895
902
  }
896
903
  }
897
904
  }
905
+ function nodeCount(root) {
906
+ let n = 0;
907
+ walkNodes(root, () => n++);
908
+ return n;
909
+ }
910
+ function chargeBudget(stmts, bindings, ctx, fixedCost = 0) {
911
+ const bindingSize = /* @__PURE__ */ new Map();
912
+ ctx.budget.left -= fixedCost;
913
+ for (const stmt of stmts) {
914
+ walkNodes(stmt, (n) => {
915
+ ctx.budget.left--;
916
+ if (n.type !== "Identifier" || !bindings.has(n.name)) return;
917
+ if (!bindingSize.has(n.name)) bindingSize.set(n.name, nodeCount(bindings.get(n.name)));
918
+ ctx.budget.left -= bindingSize.get(n.name);
919
+ });
920
+ }
921
+ if (ctx.budget.left < 0) throw new ExpansionBudgetExceeded();
922
+ }
898
923
  function expandBody(bodyStmts, bindings, prov, ctx) {
924
+ chargeBudget(bodyStmts, bindings, ctx, 1 + bindings.size);
899
925
  const block = substituteParams(cloneNode({ type: "BlockStatement", body: bodyStmts }), bindings);
900
926
  tagProvenance(block, prov);
901
927
  tagTimelineCalls(block.body, prov, ctx);
@@ -907,7 +933,7 @@ function inlineHelper(call, ctx) {
907
933
  if (!fn) return null;
908
934
  const params = supportedParams(fn);
909
935
  if (!params) return null;
910
- const bindings = resolveHelperBindings(call, params);
936
+ const bindings = resolveHelperBindings(call, params, ctx);
911
937
  if (!bindings) return null;
912
938
  const prov = {
913
939
  kind: "helper",
@@ -968,10 +994,13 @@ function unrollFor(stmt, ctx) {
968
994
  if (!h) return null;
969
995
  const body = bodyStatements(stmt.body);
970
996
  const out = [];
997
+ let count = 0;
998
+ for (let x = h.start; loopSatisfied(h.op, x, h.end); x += h.step) {
999
+ if (++count > MAX_ITERS) return null;
1000
+ }
971
1001
  const site = ++ctx.site.n;
972
1002
  let iteration = 0;
973
1003
  for (let x = h.start; loopSatisfied(h.op, x, h.end); x += h.step) {
974
- if (iteration >= MAX_ITERS) return null;
975
1004
  const prov = {
976
1005
  kind: "loop",
977
1006
  callSite: site,
@@ -991,6 +1020,7 @@ function forOfVarName(left) {
991
1020
  return left?.type === "Identifier" ? left.name : null;
992
1021
  }
993
1022
  function unrollOverArray(elements, body, elName, idxName, range, ctx) {
1023
+ if (elements.length > MAX_ITERS) return null;
994
1024
  const out = [];
995
1025
  const site = ++ctx.site.n;
996
1026
  elements.forEach((el, i) => {
@@ -1080,13 +1110,18 @@ function inlineComputedTimelines(ast, timelineVar, resolve) {
1080
1110
  depth: 0,
1081
1111
  site: { n: 0 },
1082
1112
  order: { n: 0 },
1083
- rootStart: 0
1113
+ rootStart: 0,
1114
+ budget: { left: MAX_EXPANDED_NODES }
1084
1115
  };
1085
1116
  const body = (ast.body ?? []).filter((stmt) => !isHelperDecl(stmt, helpers));
1086
- ast.body = body.flatMap((stmt) => {
1087
- ctx.rootStart = stmt.start;
1088
- return expandStatements([stmt], ctx);
1089
- });
1117
+ try {
1118
+ ast.body = body.flatMap((stmt) => {
1119
+ ctx.rootStart = stmt.start;
1120
+ return expandStatements([stmt], ctx);
1121
+ });
1122
+ } catch (error) {
1123
+ if (!(error instanceof ExpansionBudgetExceeded)) throw error;
1124
+ }
1090
1125
  }
1091
1126
 
1092
1127
  // src/gsapParserAcorn.ts
@@ -2474,20 +2509,17 @@ function contentKey(el) {
2474
2509
  const attrs = Array.from(el.attributes).filter((a) => !a.name.toLowerCase().startsWith("data-hf-")).map((a) => `${a.name.toLowerCase()}\0${a.value}`).sort().join("");
2475
2510
  return `${el.tagName.toLowerCase()}|${attrs}|${ownText(el)}`;
2476
2511
  }
2512
+ function dupId(key, dup) {
2513
+ if (dup > 1e4) return `hf-${(fnv1a(key) >>> 0).toString(36)}-${dup}`;
2514
+ return toHfId(fnv1a(dup ? `${key}#${dup}` : key));
2515
+ }
2477
2516
  function mintHfId(el, assigned) {
2478
2517
  const key = contentKey(el);
2479
2518
  const twins = lastDup.get(assigned) ?? /* @__PURE__ */ new Map();
2480
2519
  lastDup.set(assigned, twins);
2481
2520
  let dup = twins.get(key) ?? 0;
2482
- let id = dup > 1e4 ? `hf-${(fnv1a(key) >>> 0).toString(36)}-${dup}` : toHfId(fnv1a(dup ? `${key}#${dup}` : key));
2483
- while (dup <= 1e4 && assigned.has(id)) {
2484
- dup += 1;
2485
- if (dup > 1e4) {
2486
- id = `hf-${(fnv1a(key) >>> 0).toString(36)}-${dup}`;
2487
- break;
2488
- }
2489
- id = toHfId(fnv1a(`${key}#${dup}`));
2490
- }
2521
+ let id = dupId(key, dup);
2522
+ while (assigned.has(id)) id = dupId(key, ++dup);
2491
2523
  twins.set(key, dup);
2492
2524
  assigned.add(id);
2493
2525
  return id;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Segments as a case-insensitive file system or Windows opens them: any case or Unicode form (a long s, a ligature or a
3
+ * full-width letter reads as its plain letters, an invisible character is dropped), no trailing dots or spaces, no
4
+ * `:stream` suffix.
5
+ */
6
+ declare function projectPathSegments(relPath: string): string[];
7
+ declare function isVcsOrSecretPath(relPath: string): boolean;
8
+ /** Credential files and tool or agent state, for a project-relative path in any spelling Windows opens. */
9
+ declare function isCredentialOrToolStatePath(relPath: string): boolean;
10
+ /** Files no composition loads, in any spelling Windows opens: git, env, credentials, tool state, app records. */
11
+ declare function isStudioPrivatePath(relPath: string): boolean;
12
+ /** Whether `isPrivate` holds for a file under `projectDir`, spelled as given or with its links resolved. */
13
+ declare function isPrivateFileUnder(projectDir: string, filePath: string, isPrivate: (relPath: string) => boolean): boolean;
14
+
15
+ export { isCredentialOrToolStatePath, isPrivateFileUnder, isStudioPrivatePath, isVcsOrSecretPath, projectPathSegments };
@@ -0,0 +1,101 @@
1
+ // src/privatePath.ts
2
+ import { realpathSync } from "fs";
3
+ import { isAbsolute, relative, resolve, sep } from "path";
4
+ function realpath(path) {
5
+ try {
6
+ return realpathSync.native(path);
7
+ } catch (error) {
8
+ if (error.code === "EISDIR") return realpathSync(path);
9
+ throw error;
10
+ }
11
+ }
12
+ function projectPathSegments(relPath) {
13
+ return relPath.normalize("NFKC").toUpperCase().toLowerCase().replace(new RegExp("\\p{Default_Ignorable_Code_Point}", "gu"), "").split(/[\\/]/).map((segment) => withoutTrailingDotsOrSpaces(segment.split(":", 1)[0] ?? ""));
14
+ }
15
+ function withoutTrailingDotsOrSpaces(segment) {
16
+ let end = segment.length;
17
+ while (end > 0 && (segment[end - 1] === "." || segment[end - 1] === " ")) end--;
18
+ return segment.slice(0, end);
19
+ }
20
+ function isVcsOrSecretPath(relPath) {
21
+ return projectPathSegments(relPath).some(
22
+ (segment) => segment === ".git" || segment.startsWith(".env")
23
+ );
24
+ }
25
+ var STUDIO_FILES = /* @__PURE__ */ new Set([
26
+ ".hyperframes/studio-motion.json",
27
+ ".hyperframes/studio-manual-edits.json"
28
+ ]);
29
+ var STUDIO_FOLDERS = [".hyperframes/prepared-assets", ".hyperframes/requests"];
30
+ var CREDENTIAL_FILES = /* @__PURE__ */ new Set([
31
+ ".npmrc",
32
+ ".yarnrc",
33
+ ".yarnrc.yml",
34
+ ".pypirc",
35
+ "pip.conf",
36
+ "pip.ini",
37
+ ".netrc",
38
+ "_netrc",
39
+ ".git-credentials",
40
+ ".gitconfig",
41
+ ".mcp.json"
42
+ ]);
43
+ var CREDENTIAL_FOLDERS = /* @__PURE__ */ new Set([
44
+ ".ssh",
45
+ ".aws",
46
+ ".gnupg",
47
+ ".docker",
48
+ ".kube",
49
+ ".azure",
50
+ ".claude",
51
+ ".codex",
52
+ ".cursor",
53
+ ".agents",
54
+ ".gemini",
55
+ ".vscode",
56
+ ".idea"
57
+ ]);
58
+ var CREDENTIAL_CONFIG_FOLDERS = /* @__PURE__ */ new Set(["gcloud", "gh"]);
59
+ var KEY_FILE = /^(?:id_(?:rsa|dsa|ecdsa|ed25519).*|.*\.(?:pem|key|p12|pfx|p8|ppk|jks|keystore|kdbx))$/;
60
+ var SECRET_STORE_FILE = /\.(?:tfstate(?:\.backup)?|tfvars(?:\.json)?)$/;
61
+ function isCredentialOrToolStatePath(relPath) {
62
+ const segments = projectPathSegments(relPath);
63
+ const name = segments.at(-1) ?? "";
64
+ return CREDENTIAL_FILES.has(name) || KEY_FILE.test(name) || SECRET_STORE_FILE.test(name) || segments.some(
65
+ (segment, at) => CREDENTIAL_FOLDERS.has(segment) || segment === ".config" && CREDENTIAL_CONFIG_FOLDERS.has(segments[at + 1] ?? "")
66
+ );
67
+ }
68
+ function isStudioPrivatePath(relPath) {
69
+ if (isVcsOrSecretPath(relPath) || isCredentialOrToolStatePath(relPath)) return true;
70
+ const segments = projectPathSegments(relPath);
71
+ const inside = !isAbsolute(relPath) && !/^\.\.[. ]*$/.test(relPath.split(/[\\/]/, 1)[0] ?? "");
72
+ const loadedType = LOADED_ASSET_TYPE.test(segments.at(-1) ?? "");
73
+ return segments.some((segment, at) => {
74
+ const atRoot = segments.slice(0, at).every((before) => before === "");
75
+ if (segment === ".hyperframes")
76
+ return !atRoot || !isStudioOwnFile(segments.slice(at).join("/"));
77
+ const mediaFolder = atRoot && segment === MEDIA_FOLDER;
78
+ return inside && segment.startsWith(".") && !mediaFolder && !loadedType;
79
+ });
80
+ }
81
+ var MEDIA_FOLDER = ".media";
82
+ var LOADED_ASSET_TYPE = /.\.(?:png|jpe?g|gif|webp|avif|svg|ico|bmp|tiff?|heic|heif|mp4|m4v|mov|webm|mkv|mxf|avi|mp3|wav|m4a|aac|ogg|oga|opus|flac|woff2?|ttf|otf|css|m?js|cjs)$/;
83
+ function isStudioOwnFile(path) {
84
+ return STUDIO_FILES.has(path) || STUDIO_FOLDERS.some((folder) => path === folder || path.startsWith(`${folder}/`));
85
+ }
86
+ function isPrivateFileUnder(projectDir, filePath, isPrivate) {
87
+ const rel = (from, to) => relative(from, to).split(sep).join("/");
88
+ if (isPrivate(rel(resolve(projectDir), resolve(filePath)))) return true;
89
+ try {
90
+ return isPrivate(rel(realpath(resolve(projectDir)), realpath(filePath)));
91
+ } catch {
92
+ return false;
93
+ }
94
+ }
95
+ export {
96
+ isCredentialOrToolStatePath,
97
+ isPrivateFileUnder,
98
+ isStudioPrivatePath,
99
+ isVcsOrSecretPath,
100
+ projectPathSegments
101
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperframes/parsers",
3
- "version": "0.9.56",
3
+ "version": "0.9.59",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/heygen-com/hyperframes",
@@ -104,6 +104,10 @@
104
104
  "import": "./dist/assetResolution.js",
105
105
  "types": "./dist/assetResolution.d.ts"
106
106
  },
107
+ "./private-path": {
108
+ "import": "./dist/privatePath.js",
109
+ "types": "./dist/privatePath.d.ts"
110
+ },
107
111
  "./html-attribute-spans": {
108
112
  "import": "./dist/htmlAttributeSpans.js",
109
113
  "types": "./dist/htmlAttributeSpans.d.ts"
@@ -143,7 +147,7 @@
143
147
  "tsx": "^4.21.0",
144
148
  "typescript": "^5.0.0",
145
149
  "vitest": "^4.1.12",
146
- "@hyperframes/core": "0.9.56"
150
+ "@hyperframes/core": "0.9.59"
147
151
  },
148
152
  "scripts": {
149
153
  "build": "tsup",