@hyperframes/parsers 0.9.54 → 0.9.56

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,
@@ -2,8 +2,12 @@
2
2
  declare function isTrustedDirectory(dir: string): boolean;
3
3
  /** Whether `file` is an absolute path in a folder {@link isTrustedDirectory} accepts. */
4
4
  declare function isTrustedExecutablePath(file: string): boolean;
5
- /** The PATH folders a helper program may come from, in PATH order. */
6
- declare function trustedPathDirs(pathValue?: string): string[];
5
+ /** PATH entries as the program search reads them: Windows allows quotes, shells expand a leading `~`. */
6
+ declare function pathEntries(pathValue: string, platform?: NodeJS.Platform): string[];
7
+ /** The PATH folders a helper program may come from, in PATH order. Windows always keeps its system folders. */
8
+ declare function trustedPathDirs(pathValue?: string, platform?: NodeJS.Platform, env?: NodeJS.ProcessEnv): string[];
9
+ /** The program `name` in `dir`, trying the Windows program extensions there. */
10
+ declare function executableIn(dir: string, name: string): string | undefined;
7
11
  declare function findTrustedExecutable(name: string): string | undefined;
8
12
 
9
13
  /**
@@ -43,4 +47,4 @@ declare function requireFfBinary(name: FfBinaryName): string;
43
47
  /** Test hook: drop cached system lookups so resolution can be re-exercised. */
44
48
  declare function clearFfBinaryLookupCache(): void;
45
49
 
46
- export { FFMPEG_PATH_ENV, FFPROBE_PATH_ENV, type FfBinaryName, type FindFfBinaryOptions, clearFfBinaryLookupCache, findFfBinary, findTrustedExecutable, getSkippedX86Binary, isTrustedDirectory, isTrustedExecutablePath, isX86OnlyMachO, requireFfBinary, trustedPathDirs };
50
+ export { FFMPEG_PATH_ENV, FFPROBE_PATH_ENV, type FfBinaryName, type FindFfBinaryOptions, clearFfBinaryLookupCache, executableIn, findFfBinary, findTrustedExecutable, getSkippedX86Binary, isTrustedDirectory, isTrustedExecutablePath, isX86OnlyMachO, pathEntries, requireFfBinary, trustedPathDirs };
@@ -14,7 +14,17 @@ import { basename as basename2, dirname as dirname2, join as join2, resolve as r
14
14
  // src/trustedExecutable.ts
15
15
  import { accessSync, constants, existsSync, realpathSync, statSync } from "fs";
16
16
  import { homedir } from "os";
17
- import { basename, delimiter, dirname, isAbsolute, join, relative, resolve, sep } from "path";
17
+ import {
18
+ basename,
19
+ delimiter,
20
+ dirname,
21
+ isAbsolute,
22
+ join,
23
+ relative,
24
+ resolve,
25
+ sep,
26
+ win32
27
+ } from "path";
18
28
  function comparable(path) {
19
29
  const full = resolve(path);
20
30
  const missing = [];
@@ -67,13 +77,37 @@ function isTrustedExecutablePath(file) {
67
77
  return isAbsolute(file) && isTrustedDirectory(dirname(file));
68
78
  }
69
79
  function expandHome(dir) {
70
- if (process.platform === "win32" || !(dir === "~" || dir.startsWith("~/"))) return dir;
80
+ if (!(dir === "~" || dir.startsWith("~/"))) return dir;
71
81
  return join(homedir(), dir.slice(1));
72
82
  }
73
- function trustedPathDirs(pathValue = process.env.PATH ?? "") {
74
- const entries = pathValue.split(delimiter).map(expandHome);
83
+ function unquoted(dir) {
84
+ return dir.length > 1 && dir.startsWith('"') && dir.endsWith('"') ? dir.slice(1, -1) : dir;
85
+ }
86
+ function pathEntries(pathValue, platform = process.platform) {
87
+ if (platform === "win32") return pathValue.split(win32.delimiter).map(unquoted);
88
+ return pathValue.split(delimiter).map(expandHome);
89
+ }
90
+ function windowsFolderKey(dir) {
91
+ return dir.replaceAll("/", "\\").replace(/\\+$/, "").toLowerCase();
92
+ }
93
+ function windowsSystemFolders(env) {
94
+ const rootKey = Object.keys(env).find((key) => key.toUpperCase() === "SYSTEMROOT");
95
+ const root = rootKey && env[rootKey] || "C:\\Windows";
96
+ const system32 = win32.join(root, "System32");
97
+ return new Set(
98
+ [
99
+ root,
100
+ system32,
101
+ win32.join(system32, "Wbem"),
102
+ win32.join(system32, "WindowsPowerShell", "v1.0")
103
+ ].map(windowsFolderKey)
104
+ );
105
+ }
106
+ function trustedPathDirs(pathValue = process.env.PATH ?? "", platform = process.platform, env = process.env) {
107
+ const system = platform === "win32" ? windowsSystemFolders(env) : /* @__PURE__ */ new Set();
108
+ const entries = pathEntries(pathValue, platform);
75
109
  const trusted = trustRule();
76
- return [...new Set(entries.filter((dir) => trusted(dir)))];
110
+ return [...new Set(entries.filter((dir) => system.has(windowsFolderKey(dir)) || trusted(dir)))];
77
111
  }
78
112
  function windowsExtensions() {
79
113
  const listed = (process.env.PATHEXT ?? ".COM;.EXE;.BAT;.CMD").split(";").map((ext) => ext.trim().toLowerCase()).filter(Boolean);
@@ -88,13 +122,18 @@ function isExecutableFile(file) {
88
122
  return false;
89
123
  }
90
124
  }
91
- function findTrustedExecutable(name) {
125
+ function executableIn(dir, name) {
92
126
  const extensions = process.platform === "win32" ? windowsExtensions() : [""];
127
+ for (const ext of extensions) {
128
+ const candidate = join(dir, `${name}${ext}`);
129
+ if (isExecutableFile(candidate)) return candidate;
130
+ }
131
+ return void 0;
132
+ }
133
+ function findTrustedExecutable(name) {
93
134
  for (const dir of trustedPathDirs()) {
94
- for (const ext of extensions) {
95
- const candidate = join(dir, `${name}${ext}`);
96
- if (isExecutableFile(candidate)) return candidate;
97
- }
135
+ const found = executableIn(dir, name);
136
+ if (found) return found;
98
137
  }
99
138
  return void 0;
100
139
  }
@@ -240,12 +279,14 @@ export {
240
279
  FFMPEG_PATH_ENV,
241
280
  FFPROBE_PATH_ENV,
242
281
  clearFfBinaryLookupCache,
282
+ executableIn,
243
283
  findFfBinary,
244
284
  findTrustedExecutable,
245
285
  getSkippedX86Binary,
246
286
  isTrustedDirectory,
247
287
  isTrustedExecutablePath,
248
288
  isX86OnlyMachO,
289
+ pathEntries,
249
290
  requireFfBinary,
250
291
  trustedPathDirs
251
292
  };
@@ -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 };
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) => {
@@ -40,9 +41,11 @@ function contentKey(el) {
40
41
  }
41
42
  function mintHfId(el, assigned) {
42
43
  const key = contentKey(el);
43
- let id = toHfId(fnv1a(key));
44
- let dup = 0;
45
- while (assigned.has(id)) {
44
+ const twins = lastDup.get(assigned) ?? /* @__PURE__ */ new Map();
45
+ lastDup.set(assigned, twins);
46
+ 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)) {
46
49
  dup += 1;
47
50
  if (dup > 1e4) {
48
51
  id = `hf-${(fnv1a(key) >>> 0).toString(36)}-${dup}`;
@@ -50,6 +53,7 @@ function mintHfId(el, assigned) {
50
53
  }
51
54
  id = toHfId(fnv1a(`${key}#${dup}`));
52
55
  }
56
+ twins.set(key, dup);
53
57
  assigned.add(id);
54
58
  return id;
55
59
  }
@@ -236,21 +240,10 @@ function emptyHfIdValue(html, tag) {
236
240
  return tag.nameEnd + match.index + match[0].length - 1;
237
241
  }
238
242
  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);
243
+ return open.replace(/"[^"]*"?|'[^']*'?/g, (quoted) => {
244
+ const closed = quoted.length > 1 && quoted.endsWith(quoted.charAt(0));
245
+ return quoted.charAt(0) + " ".repeat(quoted.length - (closed ? 2 : 1)) + (closed ? quoted.charAt(0) : "");
246
+ });
254
247
  }
255
248
  function spliceIds(html, inserts) {
256
249
  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
@@ -2459,6 +2459,7 @@ function toHfId(hash) {
2459
2459
  const four = s.length >= 4 ? s.slice(-4) : s.padStart(4, "0");
2460
2460
  return `hf-${four}`;
2461
2461
  }
2462
+ var lastDup = /* @__PURE__ */ new WeakMap();
2462
2463
  function ownText(el) {
2463
2464
  let text = "";
2464
2465
  el.childNodes.forEach((n) => {
@@ -2475,9 +2476,11 @@ function contentKey(el) {
2475
2476
  }
2476
2477
  function mintHfId(el, assigned) {
2477
2478
  const key = contentKey(el);
2478
- let id = toHfId(fnv1a(key));
2479
- let dup = 0;
2480
- while (assigned.has(id)) {
2479
+ const twins = lastDup.get(assigned) ?? /* @__PURE__ */ new Map();
2480
+ lastDup.set(assigned, twins);
2481
+ 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)) {
2481
2484
  dup += 1;
2482
2485
  if (dup > 1e4) {
2483
2486
  id = `hf-${(fnv1a(key) >>> 0).toString(36)}-${dup}`;
@@ -2485,6 +2488,7 @@ function mintHfId(el, assigned) {
2485
2488
  }
2486
2489
  id = toHfId(fnv1a(`${key}#${dup}`));
2487
2490
  }
2491
+ twins.set(key, dup);
2488
2492
  assigned.add(id);
2489
2493
  return id;
2490
2494
  }
@@ -2671,21 +2675,10 @@ function emptyHfIdValue(html, tag) {
2671
2675
  return tag.nameEnd + match.index + match[0].length - 1;
2672
2676
  }
2673
2677
  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);
2678
+ return open.replace(/"[^"]*"?|'[^']*'?/g, (quoted) => {
2679
+ const closed = quoted.length > 1 && quoted.endsWith(quoted.charAt(0));
2680
+ return quoted.charAt(0) + " ".repeat(quoted.length - (closed ? 2 : 1)) + (closed ? quoted.charAt(0) : "");
2681
+ });
2689
2682
  }
2690
2683
  function spliceIds(html, inserts) {
2691
2684
  let out = "";
@@ -4065,9 +4058,100 @@ function unrollComputedTimeline(script) {
4065
4058
  }
4066
4059
 
4067
4060
  // 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;
4061
+ function capture(source, start, firstStart, firstEnd, secondStart, secondEnd) {
4062
+ const match = [
4063
+ source.slice(start, secondEnd),
4064
+ source.slice(start, firstStart),
4065
+ source.slice(firstStart, firstEnd),
4066
+ source.slice(firstEnd, secondStart),
4067
+ source.slice(secondStart, secondEnd)
4068
+ ];
4069
+ return Object.assign(match, { index: start });
4070
+ }
4071
+ function findDimensionPair(source, first) {
4072
+ const dimensions = /(width|height):\s*(\d+)px/gi;
4073
+ let firstValue;
4074
+ let token;
4075
+ while (token = dimensions.exec(source)) {
4076
+ if (!token[2]) continue;
4077
+ const start = token.index + token[0].length - token[2].length - 2;
4078
+ const end = start + token[2].length;
4079
+ if (token[1]?.toLowerCase() === first) {
4080
+ firstValue ??= { start, end };
4081
+ } else if (firstValue) {
4082
+ return [firstValue.start, firstValue.end, start, end];
4083
+ }
4084
+ }
4085
+ return null;
4086
+ }
4087
+ function matchBody(source, first) {
4088
+ let start = 0;
4089
+ while (start < source.length) {
4090
+ const close = source.indexOf("}", start);
4091
+ const end = close < 0 ? source.length : close;
4092
+ const region = source.slice(start, end);
4093
+ const header = /html\s*,\s*body\s*\{/i.exec(region);
4094
+ if (header) {
4095
+ const contentStart = start + header.index + header[0].length;
4096
+ const pair = findDimensionPair(source.slice(contentStart, end), first);
4097
+ if (pair) {
4098
+ return capture(
4099
+ source,
4100
+ start + header.index,
4101
+ contentStart + pair[0],
4102
+ contentStart + pair[1],
4103
+ contentStart + pair[2],
4104
+ contentStart + pair[3]
4105
+ );
4106
+ }
4107
+ }
4108
+ start = end + 1;
4109
+ }
4110
+ return null;
4111
+ }
4112
+ function matchHtmlBodyCssWidthFirst(source) {
4113
+ return matchBody(source, "width");
4114
+ }
4115
+ function matchHtmlBodyCssHeightFirst(source) {
4116
+ return matchBody(source, "height");
4117
+ }
4118
+ function matchViewportMetaSize(source) {
4119
+ let start = 0;
4120
+ while (start < source.length) {
4121
+ const close = source.indexOf(">", start);
4122
+ const end = close < 0 ? source.length : close;
4123
+ const region = source.slice(start, end);
4124
+ const meta = region.search(/<meta/i);
4125
+ if (meta >= 0) {
4126
+ const names = /name=["']viewport["']/gi;
4127
+ names.lastIndex = meta + 5;
4128
+ const name = names.exec(region);
4129
+ if (name) {
4130
+ const content = /content=["']width=(\d+)(,\s*height=)(\d+)/gi;
4131
+ content.lastIndex = name.index + name[0].length;
4132
+ const size = content.exec(region);
4133
+ if (size && size[1] && size[2] && size[3]) {
4134
+ const firstStart = start + size.index + 15;
4135
+ const firstEnd = firstStart + size[1].length;
4136
+ const secondStart = firstEnd + size[2].length;
4137
+ return capture(
4138
+ source,
4139
+ start + meta,
4140
+ firstStart,
4141
+ firstEnd,
4142
+ secondStart,
4143
+ secondStart + size[3].length
4144
+ );
4145
+ }
4146
+ }
4147
+ }
4148
+ start = end + 1;
4149
+ }
4150
+ return null;
4151
+ }
4152
+ function replaceCanvasScaffoldSize(source, match, first, second) {
4153
+ return source.slice(0, match.index) + match[1] + first + match[3] + second + source.slice(match.index + match[0].length);
4154
+ }
4071
4155
 
4072
4156
  // src/topLevelElements.ts
4073
4157
  var NON_RENDERED_TAGS = /* @__PURE__ */ new Set(["script", "style", "template", "noscript", "link", "meta"]);
@@ -4835,8 +4919,6 @@ export {
4835
4919
  FONT_ALIAS_MAP,
4836
4920
  GSAP_DEFAULT_DURATION,
4837
4921
  HTML_ATTRIBUTE_ENTITIES,
4838
- HTML_BODY_CSS_HEIGHT_FIRST_RE,
4839
- HTML_BODY_CSS_WIDTH_FIRST_RE,
4840
4922
  LEGACY_TIMING_ATTRIBUTES,
4841
4923
  MAX_PLAYBACK_RATE,
4842
4924
  MIN_PLAYBACK_RATE,
@@ -4849,7 +4931,6 @@ export {
4849
4931
  TIMELINE_COLORS,
4850
4932
  TIMING_TOLERANCE_SECONDS,
4851
4933
  VALID_CANVAS_RESOLUTIONS,
4852
- VIEWPORT_META_SIZE_RE,
4853
4934
  addElementToHtml,
4854
4935
  checkOutputResolutionCompatibility,
4855
4936
  checkSubCompositionUsability,
@@ -4879,6 +4960,9 @@ export {
4879
4960
  isTextElement,
4880
4961
  isTimedElement,
4881
4962
  keyframesToGsapAnimations,
4963
+ matchHtmlBodyCssHeightFirst,
4964
+ matchHtmlBodyCssWidthFirst,
4965
+ matchViewportMetaSize,
4882
4966
  mintHfId,
4883
4967
  normalizeResolutionFlag,
4884
4968
  outputResolutionForSize,
@@ -4895,6 +4979,7 @@ export {
4895
4979
  readPlaybackRate,
4896
4980
  removeElementFromHtml,
4897
4981
  removeElementWithGsapCascade,
4982
+ replaceCanvasScaffoldSize,
4898
4983
  resolveAliasDisplayName,
4899
4984
  resolveCompositionDuration,
4900
4985
  resolveMediaDuration,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperframes/parsers",
3
- "version": "0.9.54",
3
+ "version": "0.9.56",
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.54"
146
+ "@hyperframes/core": "0.9.56"
147
147
  },
148
148
  "scripts": {
149
149
  "build": "tsup",