@hyperframes/parsers 0.9.55 → 0.9.58

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.
@@ -1,5 +1,5 @@
1
1
  export { A as AddElementData, a as Asset, B as BooleanVariable, C as CANVAS_DIMENSIONS, b as COMPOSITION_VARIABLE_TYPES, c as CanvasResolution, d as ColorVariable, e as CompositionAPI, f as CompositionAsset, g as CompositionSpec, h as CompositionVariable, i as CompositionVariableBase, j as CompositionVariableType, D as DEFAULT_DURATIONS, E as ElementKeyframes, k as EnumVariable, F as FontValue, l as FontVariable, I as ImageValue, m as ImageVariable, K as Keyframe, n as KeyframeProperties, M as MediaElementType, o as MediaFile, N as NumberVariable, P as PlayerAPI, R as ResolvedResolutionFlag, S as StageZoom, p as StageZoomKeyframe, q as StringVariable, T as TIMELINE_COLORS, r as TimelineCompositionElement, s as TimelineElement, t as TimelineElementBase, u as TimelineElementType, v as TimelineMediaElement, w as TimelineTextElement, V as VALID_CANVAS_RESOLUTIONS, x as ValidationResult, W as WaveformData, y as getDefaultStageZoom, z as isAspectAgnosticResolutionAlias, G as isCompositionElement, H as isMediaElement, J as isTextElement, L as normalizeResolutionFlag, O as resolveResolutionFlagPair } from './types-C1bWHQbs.js';
2
- export { C as CANONICAL_FONT_DISPLAY_NAMES, F as FONT_ALIAS_KEYS, a as FONT_ALIAS_MAP, H as HTML_BODY_CSS_HEIGHT_FIRST_RE, b as HTML_BODY_CSS_WIDTH_FIRST_RE, M as MediaSrcMutation, R as ReadCompositionVariables, V as VIEWPORT_META_SIZE_RE, c as VariableUsageScan, e as extractMediaSrcMutations, i as isCompositionVariable, d as isFontValue, f as isImageValue, g as isSafeMediaUrl, h as isScalarVariableValue, p as parseCompositionVariables, r as readCompositionVariables, j as resolveAliasDisplayName, s as scanVariableUsage } from './fontAliases-o-I_DVRP.js';
2
+ export { C as CANONICAL_FONT_DISPLAY_NAMES, a as CanvasScaffoldMatch, F as FONT_ALIAS_KEYS, b as FONT_ALIAS_MAP, M as MediaSrcMutation, R as ReadCompositionVariables, V as VariableUsageScan, e as extractMediaSrcMutations, i as isCompositionVariable, c as isFontValue, d as isImageValue, f as isSafeMediaUrl, g as isScalarVariableValue, m as matchHtmlBodyCssHeightFirst, h as matchHtmlBodyCssWidthFirst, j as matchViewportMetaSize, p as parseCompositionVariables, r as readCompositionVariables, k as replaceCanvasScaffoldSize, l as resolveAliasDisplayName, s as scanVariableUsage } from './fontAliases-6Aft6tHT.js';
3
3
  export { d as decodeUrlPathVariants } from './urlPath-CYK47t9W.js';
4
4
  export { CANONICAL_AUTHORED_TIMING_ATTRIBUTES, COMPOSITION_ATTRIBUTES, COMPOSITION_CONTRACT_VERSION, ClipAttributeReader, ClipAttributeWriter, ClipTiming, ClipTimingDiagnostic, ClipTimingDiagnosticCode, ClipTimingUpdate, ClipTimingWriteError, DERIVED_TIMING_ATTRIBUTES, LEGACY_TIMING_ATTRIBUTES, ReadClipTimingOptions, ReferenceExpression, SPLIT_BOUNDARY_EPSILON_S, parseNumeric, parseStartExpression, readClipTiming, writeClipTiming } from './compositionContract.js';
5
5
 
@@ -751,9 +751,100 @@ function writeClipTiming(attributes, update) {
751
751
  }
752
752
 
753
753
  // src/canvasScaffoldPatterns.ts
754
- var HTML_BODY_CSS_WIDTH_FIRST_RE = /(html\s*,\s*body\s*\{[^}]*?width:\s*)(\d+)px([^}]*?height:\s*)(\d+)px/i;
755
- var HTML_BODY_CSS_HEIGHT_FIRST_RE = /(html\s*,\s*body\s*\{[^}]*?height:\s*)(\d+)px([^}]*?width:\s*)(\d+)px/i;
756
- var VIEWPORT_META_SIZE_RE = /(<meta[^>]*name=["']viewport["'][^>]*content=["']width=)(\d+)(,\s*height=)(\d+)/i;
754
+ function capture(source, start, firstStart, firstEnd, secondStart, secondEnd) {
755
+ const match = [
756
+ source.slice(start, secondEnd),
757
+ source.slice(start, firstStart),
758
+ source.slice(firstStart, firstEnd),
759
+ source.slice(firstEnd, secondStart),
760
+ source.slice(secondStart, secondEnd)
761
+ ];
762
+ return Object.assign(match, { index: start });
763
+ }
764
+ function findDimensionPair(source, first) {
765
+ const dimensions = /(width|height):\s*(\d+)px/gi;
766
+ let firstValue;
767
+ let token;
768
+ while (token = dimensions.exec(source)) {
769
+ if (!token[2]) continue;
770
+ const start = token.index + token[0].length - token[2].length - 2;
771
+ const end = start + token[2].length;
772
+ if (token[1]?.toLowerCase() === first) {
773
+ firstValue ??= { start, end };
774
+ } else if (firstValue) {
775
+ return [firstValue.start, firstValue.end, start, end];
776
+ }
777
+ }
778
+ return null;
779
+ }
780
+ function matchBody(source, first) {
781
+ let start = 0;
782
+ while (start < source.length) {
783
+ const close = source.indexOf("}", start);
784
+ const end = close < 0 ? source.length : close;
785
+ const region = source.slice(start, end);
786
+ const header = /html\s*,\s*body\s*\{/i.exec(region);
787
+ if (header) {
788
+ const contentStart = start + header.index + header[0].length;
789
+ const pair = findDimensionPair(source.slice(contentStart, end), first);
790
+ if (pair) {
791
+ return capture(
792
+ source,
793
+ start + header.index,
794
+ contentStart + pair[0],
795
+ contentStart + pair[1],
796
+ contentStart + pair[2],
797
+ contentStart + pair[3]
798
+ );
799
+ }
800
+ }
801
+ start = end + 1;
802
+ }
803
+ return null;
804
+ }
805
+ function matchHtmlBodyCssWidthFirst(source) {
806
+ return matchBody(source, "width");
807
+ }
808
+ function matchHtmlBodyCssHeightFirst(source) {
809
+ return matchBody(source, "height");
810
+ }
811
+ function matchViewportMetaSize(source) {
812
+ let start = 0;
813
+ while (start < source.length) {
814
+ const close = source.indexOf(">", start);
815
+ const end = close < 0 ? source.length : close;
816
+ const region = source.slice(start, end);
817
+ const meta = region.search(/<meta/i);
818
+ if (meta >= 0) {
819
+ const names = /name=["']viewport["']/gi;
820
+ names.lastIndex = meta + 5;
821
+ const name = names.exec(region);
822
+ if (name) {
823
+ const content = /content=["']width=(\d+)(,\s*height=)(\d+)/gi;
824
+ content.lastIndex = name.index + name[0].length;
825
+ const size = content.exec(region);
826
+ if (size && size[1] && size[2] && size[3]) {
827
+ const firstStart = start + size.index + 15;
828
+ const firstEnd = firstStart + size[1].length;
829
+ const secondStart = firstEnd + size[2].length;
830
+ return capture(
831
+ source,
832
+ start + meta,
833
+ firstStart,
834
+ firstEnd,
835
+ secondStart,
836
+ secondStart + size[3].length
837
+ );
838
+ }
839
+ }
840
+ }
841
+ start = end + 1;
842
+ }
843
+ return null;
844
+ }
845
+ function replaceCanvasScaffoldSize(source, match, first, second) {
846
+ return source.slice(0, match.index) + match[1] + first + match[3] + second + source.slice(match.index + match[0].length);
847
+ }
757
848
 
758
849
  // src/mediaSrcMutation.ts
759
850
  import * as acorn2 from "acorn";
@@ -950,13 +1041,10 @@ export {
950
1041
  DERIVED_TIMING_ATTRIBUTES,
951
1042
  FONT_ALIAS_KEYS,
952
1043
  FONT_ALIAS_MAP,
953
- HTML_BODY_CSS_HEIGHT_FIRST_RE,
954
- HTML_BODY_CSS_WIDTH_FIRST_RE,
955
1044
  LEGACY_TIMING_ATTRIBUTES,
956
1045
  SPLIT_BOUNDARY_EPSILON_S,
957
1046
  TIMELINE_COLORS,
958
1047
  VALID_CANVAS_RESOLUTIONS,
959
- VIEWPORT_META_SIZE_RE,
960
1048
  decodeUrlPathVariants,
961
1049
  extractMediaSrcMutations,
962
1050
  fontShorthandFamilies,
@@ -970,6 +1058,9 @@ export {
970
1058
  isSafeMediaUrl,
971
1059
  isScalarVariableValue,
972
1060
  isTextElement,
1061
+ matchHtmlBodyCssHeightFirst,
1062
+ matchHtmlBodyCssWidthFirst,
1063
+ matchViewportMetaSize,
973
1064
  normalizeResolutionFlag,
974
1065
  parseCompositionVariables,
975
1066
  parseFontShorthand,
@@ -977,6 +1068,7 @@ export {
977
1068
  parseStartExpression,
978
1069
  readClipTiming,
979
1070
  readCompositionVariables,
1071
+ replaceCanvasScaffoldSize,
980
1072
  resolveAliasDisplayName,
981
1073
  resolveResolutionFlagPair,
982
1074
  scanVariableUsage,
@@ -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; 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,64 @@ 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
+ function demuxersFromListing(listing) {
295
+ const row = /Is a device/.test(listing) ? /^ D[E ]([d ]) (\S+)/ : /^ D[E ]() (\S+)/;
296
+ const names = /* @__PURE__ */ new Set();
297
+ for (const line of listing.split("\n")) {
298
+ const match = row.exec(line);
299
+ if (!match || match[1] === "d") continue;
300
+ const aliases = match[2].split(",");
301
+ if (aliases.some((alias) => PATH_OPENING_DEMUXERS.has(alias))) continue;
302
+ for (const alias of aliases) names.add(alias);
303
+ }
304
+ return names.size > 0 ? [...names].join(",") : void 0;
305
+ }
306
+ var demuxerLists = /* @__PURE__ */ new Map();
307
+ var listingOverride;
308
+ function _setDemuxerListingForTests(listing) {
309
+ listingOverride = listing;
310
+ demuxerLists.clear();
311
+ }
312
+ function mediaInputFormatArgs(listingBinary) {
313
+ let formats = demuxerLists.get(listingBinary);
314
+ if (formats === void 0) {
315
+ try {
316
+ formats = demuxersFromListing(
317
+ listingOverride ?? execFileSync(listingBinary, ["-hide_banner", "-demuxers"], {
318
+ encoding: "utf8",
319
+ timeout: 1e4,
320
+ windowsHide: true,
321
+ stdio: ["ignore", "pipe", "ignore"]
322
+ })
323
+ );
324
+ } catch {
325
+ formats = void 0;
326
+ }
327
+ if (formats === void 0) return ["-format_whitelist", SELF_CONTAINED_FORMATS];
328
+ demuxerLists.set(listingBinary, formats);
329
+ }
330
+ return ["-format_whitelist", formats];
331
+ }
278
332
  export {
279
333
  FFMPEG_PATH_ENV,
280
334
  FFPROBE_PATH_ENV,
335
+ SELF_CONTAINED_FORMATS,
336
+ _setDemuxerListingForTests,
281
337
  clearFfBinaryLookupCache,
282
338
  executableIn,
283
339
  findFfBinary,
@@ -286,6 +342,7 @@ export {
286
342
  isTrustedDirectory,
287
343
  isTrustedExecutablePath,
288
344
  isX86OnlyMachO,
345
+ mediaInputFormatArgs,
289
346
  pathEntries,
290
347
  requireFfBinary,
291
348
  trustedPathDirs
@@ -51,16 +51,16 @@ declare function parseCompositionVariables(htmlEl: Element): CompositionVariable
51
51
  */
52
52
  declare function isSafeMediaUrl(url: string): boolean;
53
53
 
54
- /**
55
- * Where a scaffolded project's canvas resolution lives besides the root's own
56
- * data-width/data-height: the html/body CSS size and the meta viewport content.
57
- */
58
- /** html/body CSS, width first. Groups 1/3 are the surrounding text, 2/4 the digits. */
59
- declare const HTML_BODY_CSS_WIDTH_FIRST_RE: RegExp;
60
- /** Same block, height authored first. */
61
- declare const HTML_BODY_CSS_HEIGHT_FIRST_RE: RegExp;
62
- /** Viewport meta content. Shared by lint (reads groups 2/4) and cli (replaces via 1/3). */
63
- declare const VIEWPORT_META_SIZE_RE: RegExp;
54
+ /** Linear-time readers for the canvas dimensions in scaffold CSS and metadata. */
55
+ type CanvasScaffoldMatch = [string, string, string, string, string] & {
56
+ index: number;
57
+ };
58
+ declare function matchHtmlBodyCssWidthFirst(source: string): CanvasScaffoldMatch | null;
59
+ declare function matchHtmlBodyCssHeightFirst(source: string): CanvasScaffoldMatch | null;
60
+ /** Scan each tag-sized region once, including malformed unterminated tags. */
61
+ declare function matchViewportMetaSize(source: string): CanvasScaffoldMatch | null;
62
+ /** Replace only the captured digits; preserve whitespace, units and surrounding text. */
63
+ declare function replaceCanvasScaffoldSize(source: string, match: CanvasScaffoldMatch, first: number, second: number): string;
64
64
 
65
65
  /**
66
66
  * Browser-safe static scan for composition-variable reads in script text.
@@ -188,4 +188,4 @@ declare const CANONICAL_FONT_DISPLAY_NAMES: Readonly<Record<string, string>>;
188
188
  */
189
189
  declare function resolveAliasDisplayName(alias: string): string | undefined;
190
190
 
191
- export { CANONICAL_FONT_DISPLAY_NAMES as C, FONT_ALIAS_KEYS as F, HTML_BODY_CSS_HEIGHT_FIRST_RE as H, type MediaSrcMutation as M, type ReadCompositionVariables as R, VIEWPORT_META_SIZE_RE as V, FONT_ALIAS_MAP as a, HTML_BODY_CSS_WIDTH_FIRST_RE as b, type VariableUsageScan as c, isFontValue as d, extractMediaSrcMutations as e, isImageValue as f, isSafeMediaUrl as g, isScalarVariableValue as h, isCompositionVariable as i, resolveAliasDisplayName as j, parseCompositionVariables as p, readCompositionVariables as r, scanVariableUsage as s };
191
+ export { CANONICAL_FONT_DISPLAY_NAMES as C, FONT_ALIAS_KEYS as F, type MediaSrcMutation as M, type ReadCompositionVariables as R, type VariableUsageScan as V, type CanvasScaffoldMatch as a, FONT_ALIAS_MAP as b, isFontValue as c, isImageValue as d, extractMediaSrcMutations as e, isSafeMediaUrl as f, isScalarVariableValue as g, matchHtmlBodyCssWidthFirst as h, isCompositionVariable as i, matchViewportMetaSize as j, replaceCanvasScaffoldSize as k, resolveAliasDisplayName as l, matchHtmlBodyCssHeightFirst as m, parseCompositionVariables as p, readCompositionVariables as r, scanVariableUsage as s };
@@ -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
@@ -24,6 +24,7 @@ function toHfId(hash) {
24
24
  const four = s.length >= 4 ? s.slice(-4) : s.padStart(4, "0");
25
25
  return `hf-${four}`;
26
26
  }
27
+ var lastDup = /* @__PURE__ */ new WeakMap();
27
28
  function ownText(el) {
28
29
  let text = "";
29
30
  el.childNodes.forEach((n) => {
@@ -38,18 +39,18 @@ function contentKey(el) {
38
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("");
39
40
  return `${el.tagName.toLowerCase()}|${attrs}|${ownText(el)}`;
40
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
+ }
41
46
  function mintHfId(el, assigned) {
42
47
  const key = contentKey(el);
43
- let id = toHfId(fnv1a(key));
44
- let dup = 0;
45
- while (assigned.has(id)) {
46
- dup += 1;
47
- if (dup > 1e4) {
48
- id = `hf-${(fnv1a(key) >>> 0).toString(36)}-${dup}`;
49
- break;
50
- }
51
- id = toHfId(fnv1a(`${key}#${dup}`));
52
- }
48
+ const twins = lastDup.get(assigned) ?? /* @__PURE__ */ new Map();
49
+ lastDup.set(assigned, twins);
50
+ let dup = twins.get(key) ?? 0;
51
+ let id = dupId(key, dup);
52
+ while (assigned.has(id)) id = dupId(key, ++dup);
53
+ twins.set(key, dup);
53
54
  assigned.add(id);
54
55
  return id;
55
56
  }
@@ -236,21 +237,10 @@ function emptyHfIdValue(html, tag) {
236
237
  return tag.nameEnd + match.index + match[0].length - 1;
237
238
  }
238
239
  function outsideQuotes(open) {
239
- let quote = "";
240
- let out = "";
241
- for (const c of open) {
242
- out += quotedChar(quote, c);
243
- quote = quoteOf(quote, c);
244
- }
245
- return out;
246
- }
247
- function quoteOf(quote, c) {
248
- if (quote) return c === quote ? "" : quote;
249
- return c === '"' || c === "'" ? c : "";
250
- }
251
- function quotedChar(quote, c) {
252
- if (!quote || c === quote) return c;
253
- return " ".repeat(c.length);
240
+ return open.replace(/"[^"]*"?|'[^']*'?/g, (quoted) => {
241
+ const closed = quoted.length > 1 && quoted.endsWith(quoted.charAt(0));
242
+ return quoted.charAt(0) + " ".repeat(quoted.length - (closed ? 2 : 1)) + (closed ? quoted.charAt(0) : "");
243
+ });
254
244
  }
255
245
  function spliceIds(html, inserts) {
256
246
  let out = "";
package/dist/index.d.ts CHANGED
@@ -8,7 +8,7 @@ export { parseGsapScriptAcorn as parseGsapScript } from './gsapParserAcorn.js';
8
8
  export { EXCLUDED_TAGS, ensureHfIds, isCompositionTemplate, mintHfId, stampHfIdsInPlace, walkCompositionDescendants } from './hfIds.js';
9
9
  export { ParsableDocumentLike, SceneTemplateLike, SubCompositionValidity, SubCompositionValidityReason, checkSubCompositionUsability, findSceneTemplate, resolveSubCompositionContent } from './subCompositionValidity.js';
10
10
  export { CANONICAL_AUTHORED_TIMING_ATTRIBUTES, COMPOSITION_ATTRIBUTES, COMPOSITION_CONTRACT_VERSION, ClipAttributeReader, ClipAttributeWriter, ClipTiming, ClipTimingDiagnostic, ClipTimingDiagnosticCode, ClipTimingUpdate, ClipTimingWriteError, DERIVED_TIMING_ATTRIBUTES, LEGACY_TIMING_ATTRIBUTES, ReadClipTimingOptions, ReferenceExpression, SPLIT_BOUNDARY_EPSILON_S, parseNumeric, parseStartExpression, readClipTiming, writeClipTiming } from './compositionContract.js';
11
- export { C as CANONICAL_FONT_DISPLAY_NAMES, F as FONT_ALIAS_KEYS, a as FONT_ALIAS_MAP, H as HTML_BODY_CSS_HEIGHT_FIRST_RE, b as HTML_BODY_CSS_WIDTH_FIRST_RE, M as MediaSrcMutation, V as VIEWPORT_META_SIZE_RE, c as VariableUsageScan, e as extractMediaSrcMutations, p as parseCompositionVariables, j as resolveAliasDisplayName, s as scanVariableUsage } from './fontAliases-o-I_DVRP.js';
11
+ export { C as CANONICAL_FONT_DISPLAY_NAMES, a as CanvasScaffoldMatch, F as FONT_ALIAS_KEYS, b as FONT_ALIAS_MAP, M as MediaSrcMutation, V as VariableUsageScan, e as extractMediaSrcMutations, m as matchHtmlBodyCssHeightFirst, h as matchHtmlBodyCssWidthFirst, j as matchViewportMetaSize, p as parseCompositionVariables, k as replaceCanvasScaffoldSize, l as resolveAliasDisplayName, s as scanVariableUsage } from './fontAliases-6Aft6tHT.js';
12
12
  export { StructureNode, TrackKind, TrackKindSource, isSubCompositionHost, isTimedElement, topLevelElements, trackKindOf } from './topLevelElements.js';
13
13
  export { AttrReader, DEFAULT_IMAGE_TIMELINE_DURATION_SECONDS, MAX_PLAYBACK_RATE, MIN_PLAYBACK_RATE, MediaDurationResult, MediaDurationSource, MediaTag, PENDING_MEDIA_DURATION_READERS, ResolveMediaDurationInput, clampPlaybackRate, readAuthoredDurationSeconds, readDataDurationSeconds, readMediaOffsetSeconds, readPlaybackRate, resolveMediaDuration, resolveNaturalDurationSeconds } from './mediaDuration.js';
14
14
  export { CompositionDurationResult, CompositionDurationSource, ResolveCompositionDurationInput, TIMING_TOLERANCE_SECONDS, resolveCompositionDuration } from './compositionDuration.js';
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
@@ -2459,6 +2494,7 @@ function toHfId(hash) {
2459
2494
  const four = s.length >= 4 ? s.slice(-4) : s.padStart(4, "0");
2460
2495
  return `hf-${four}`;
2461
2496
  }
2497
+ var lastDup = /* @__PURE__ */ new WeakMap();
2462
2498
  function ownText(el) {
2463
2499
  let text = "";
2464
2500
  el.childNodes.forEach((n) => {
@@ -2473,18 +2509,18 @@ function contentKey(el) {
2473
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("");
2474
2510
  return `${el.tagName.toLowerCase()}|${attrs}|${ownText(el)}`;
2475
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
+ }
2476
2516
  function mintHfId(el, assigned) {
2477
2517
  const key = contentKey(el);
2478
- let id = toHfId(fnv1a(key));
2479
- let dup = 0;
2480
- while (assigned.has(id)) {
2481
- dup += 1;
2482
- if (dup > 1e4) {
2483
- id = `hf-${(fnv1a(key) >>> 0).toString(36)}-${dup}`;
2484
- break;
2485
- }
2486
- id = toHfId(fnv1a(`${key}#${dup}`));
2487
- }
2518
+ const twins = lastDup.get(assigned) ?? /* @__PURE__ */ new Map();
2519
+ lastDup.set(assigned, twins);
2520
+ let dup = twins.get(key) ?? 0;
2521
+ let id = dupId(key, dup);
2522
+ while (assigned.has(id)) id = dupId(key, ++dup);
2523
+ twins.set(key, dup);
2488
2524
  assigned.add(id);
2489
2525
  return id;
2490
2526
  }
@@ -2671,21 +2707,10 @@ function emptyHfIdValue(html, tag) {
2671
2707
  return tag.nameEnd + match.index + match[0].length - 1;
2672
2708
  }
2673
2709
  function outsideQuotes(open) {
2674
- let quote = "";
2675
- let out = "";
2676
- for (const c of open) {
2677
- out += quotedChar(quote, c);
2678
- quote = quoteOf(quote, c);
2679
- }
2680
- return out;
2681
- }
2682
- function quoteOf(quote, c) {
2683
- if (quote) return c === quote ? "" : quote;
2684
- return c === '"' || c === "'" ? c : "";
2685
- }
2686
- function quotedChar(quote, c) {
2687
- if (!quote || c === quote) return c;
2688
- return " ".repeat(c.length);
2710
+ return open.replace(/"[^"]*"?|'[^']*'?/g, (quoted) => {
2711
+ const closed = quoted.length > 1 && quoted.endsWith(quoted.charAt(0));
2712
+ return quoted.charAt(0) + " ".repeat(quoted.length - (closed ? 2 : 1)) + (closed ? quoted.charAt(0) : "");
2713
+ });
2689
2714
  }
2690
2715
  function spliceIds(html, inserts) {
2691
2716
  let out = "";
@@ -4065,9 +4090,100 @@ function unrollComputedTimeline(script) {
4065
4090
  }
4066
4091
 
4067
4092
  // src/canvasScaffoldPatterns.ts
4068
- var HTML_BODY_CSS_WIDTH_FIRST_RE = /(html\s*,\s*body\s*\{[^}]*?width:\s*)(\d+)px([^}]*?height:\s*)(\d+)px/i;
4069
- var HTML_BODY_CSS_HEIGHT_FIRST_RE = /(html\s*,\s*body\s*\{[^}]*?height:\s*)(\d+)px([^}]*?width:\s*)(\d+)px/i;
4070
- var VIEWPORT_META_SIZE_RE = /(<meta[^>]*name=["']viewport["'][^>]*content=["']width=)(\d+)(,\s*height=)(\d+)/i;
4093
+ function capture(source, start, firstStart, firstEnd, secondStart, secondEnd) {
4094
+ const match = [
4095
+ source.slice(start, secondEnd),
4096
+ source.slice(start, firstStart),
4097
+ source.slice(firstStart, firstEnd),
4098
+ source.slice(firstEnd, secondStart),
4099
+ source.slice(secondStart, secondEnd)
4100
+ ];
4101
+ return Object.assign(match, { index: start });
4102
+ }
4103
+ function findDimensionPair(source, first) {
4104
+ const dimensions = /(width|height):\s*(\d+)px/gi;
4105
+ let firstValue;
4106
+ let token;
4107
+ while (token = dimensions.exec(source)) {
4108
+ if (!token[2]) continue;
4109
+ const start = token.index + token[0].length - token[2].length - 2;
4110
+ const end = start + token[2].length;
4111
+ if (token[1]?.toLowerCase() === first) {
4112
+ firstValue ??= { start, end };
4113
+ } else if (firstValue) {
4114
+ return [firstValue.start, firstValue.end, start, end];
4115
+ }
4116
+ }
4117
+ return null;
4118
+ }
4119
+ function matchBody(source, first) {
4120
+ let start = 0;
4121
+ while (start < source.length) {
4122
+ const close = source.indexOf("}", start);
4123
+ const end = close < 0 ? source.length : close;
4124
+ const region = source.slice(start, end);
4125
+ const header = /html\s*,\s*body\s*\{/i.exec(region);
4126
+ if (header) {
4127
+ const contentStart = start + header.index + header[0].length;
4128
+ const pair = findDimensionPair(source.slice(contentStart, end), first);
4129
+ if (pair) {
4130
+ return capture(
4131
+ source,
4132
+ start + header.index,
4133
+ contentStart + pair[0],
4134
+ contentStart + pair[1],
4135
+ contentStart + pair[2],
4136
+ contentStart + pair[3]
4137
+ );
4138
+ }
4139
+ }
4140
+ start = end + 1;
4141
+ }
4142
+ return null;
4143
+ }
4144
+ function matchHtmlBodyCssWidthFirst(source) {
4145
+ return matchBody(source, "width");
4146
+ }
4147
+ function matchHtmlBodyCssHeightFirst(source) {
4148
+ return matchBody(source, "height");
4149
+ }
4150
+ function matchViewportMetaSize(source) {
4151
+ let start = 0;
4152
+ while (start < source.length) {
4153
+ const close = source.indexOf(">", start);
4154
+ const end = close < 0 ? source.length : close;
4155
+ const region = source.slice(start, end);
4156
+ const meta = region.search(/<meta/i);
4157
+ if (meta >= 0) {
4158
+ const names = /name=["']viewport["']/gi;
4159
+ names.lastIndex = meta + 5;
4160
+ const name = names.exec(region);
4161
+ if (name) {
4162
+ const content = /content=["']width=(\d+)(,\s*height=)(\d+)/gi;
4163
+ content.lastIndex = name.index + name[0].length;
4164
+ const size = content.exec(region);
4165
+ if (size && size[1] && size[2] && size[3]) {
4166
+ const firstStart = start + size.index + 15;
4167
+ const firstEnd = firstStart + size[1].length;
4168
+ const secondStart = firstEnd + size[2].length;
4169
+ return capture(
4170
+ source,
4171
+ start + meta,
4172
+ firstStart,
4173
+ firstEnd,
4174
+ secondStart,
4175
+ secondStart + size[3].length
4176
+ );
4177
+ }
4178
+ }
4179
+ }
4180
+ start = end + 1;
4181
+ }
4182
+ return null;
4183
+ }
4184
+ function replaceCanvasScaffoldSize(source, match, first, second) {
4185
+ return source.slice(0, match.index) + match[1] + first + match[3] + second + source.slice(match.index + match[0].length);
4186
+ }
4071
4187
 
4072
4188
  // src/topLevelElements.ts
4073
4189
  var NON_RENDERED_TAGS = /* @__PURE__ */ new Set(["script", "style", "template", "noscript", "link", "meta"]);
@@ -4835,8 +4951,6 @@ export {
4835
4951
  FONT_ALIAS_MAP,
4836
4952
  GSAP_DEFAULT_DURATION,
4837
4953
  HTML_ATTRIBUTE_ENTITIES,
4838
- HTML_BODY_CSS_HEIGHT_FIRST_RE,
4839
- HTML_BODY_CSS_WIDTH_FIRST_RE,
4840
4954
  LEGACY_TIMING_ATTRIBUTES,
4841
4955
  MAX_PLAYBACK_RATE,
4842
4956
  MIN_PLAYBACK_RATE,
@@ -4849,7 +4963,6 @@ export {
4849
4963
  TIMELINE_COLORS,
4850
4964
  TIMING_TOLERANCE_SECONDS,
4851
4965
  VALID_CANVAS_RESOLUTIONS,
4852
- VIEWPORT_META_SIZE_RE,
4853
4966
  addElementToHtml,
4854
4967
  checkOutputResolutionCompatibility,
4855
4968
  checkSubCompositionUsability,
@@ -4879,6 +4992,9 @@ export {
4879
4992
  isTextElement,
4880
4993
  isTimedElement,
4881
4994
  keyframesToGsapAnimations,
4995
+ matchHtmlBodyCssHeightFirst,
4996
+ matchHtmlBodyCssWidthFirst,
4997
+ matchViewportMetaSize,
4882
4998
  mintHfId,
4883
4999
  normalizeResolutionFlag,
4884
5000
  outputResolutionForSize,
@@ -4895,6 +5011,7 @@ export {
4895
5011
  readPlaybackRate,
4896
5012
  removeElementFromHtml,
4897
5013
  removeElementWithGsapCascade,
5014
+ replaceCanvasScaffoldSize,
4898
5015
  resolveAliasDisplayName,
4899
5016
  resolveCompositionDuration,
4900
5017
  resolveMediaDuration,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperframes/parsers",
3
- "version": "0.9.55",
3
+ "version": "0.9.58",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/heygen-com/hyperframes",
@@ -143,7 +143,7 @@
143
143
  "tsx": "^4.21.0",
144
144
  "typescript": "^5.0.0",
145
145
  "vitest": "^4.1.12",
146
- "@hyperframes/core": "0.9.55"
146
+ "@hyperframes/core": "0.9.58"
147
147
  },
148
148
  "scripts": {
149
149
  "build": "tsup",