@hyperframes/inspector 0.10.6 → 0.10.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/service.js
CHANGED
|
@@ -8672,12 +8672,12 @@ var require_esprima2 = __commonJS({
|
|
|
8672
8672
|
}
|
|
8673
8673
|
exports2.parseScript = parseScript;
|
|
8674
8674
|
function tokenize(code, options, delegate) {
|
|
8675
|
-
var
|
|
8675
|
+
var tokenizer2 = new tokenizer_1.Tokenizer(code, options);
|
|
8676
8676
|
var tokens2;
|
|
8677
8677
|
tokens2 = [];
|
|
8678
8678
|
try {
|
|
8679
8679
|
while (true) {
|
|
8680
|
-
var token =
|
|
8680
|
+
var token = tokenizer2.getNextToken();
|
|
8681
8681
|
if (!token) {
|
|
8682
8682
|
break;
|
|
8683
8683
|
}
|
|
@@ -8687,10 +8687,10 @@ var require_esprima2 = __commonJS({
|
|
|
8687
8687
|
tokens2.push(token);
|
|
8688
8688
|
}
|
|
8689
8689
|
} catch (e) {
|
|
8690
|
-
|
|
8690
|
+
tokenizer2.errorHandler.tolerate(e);
|
|
8691
8691
|
}
|
|
8692
|
-
if (
|
|
8693
|
-
tokens2.errors =
|
|
8692
|
+
if (tokenizer2.errorHandler.tolerant) {
|
|
8693
|
+
tokens2.errors = tokenizer2.errors();
|
|
8694
8694
|
}
|
|
8695
8695
|
return tokens2;
|
|
8696
8696
|
}
|
|
@@ -41901,8 +41901,111 @@ function getHyperframeRuntimeScript() {
|
|
|
41901
41901
|
// src/service.ts
|
|
41902
41902
|
import puppeteer from "puppeteer-core";
|
|
41903
41903
|
|
|
41904
|
-
// ../core/src/compiler/
|
|
41904
|
+
// ../core/src/compiler/stripJsComments.ts
|
|
41905
41905
|
import { createHash as createHash3 } from "node:crypto";
|
|
41906
|
+
import { tokenizer } from "acorn";
|
|
41907
|
+
var VLQ_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
41908
|
+
function encodeVlq(value) {
|
|
41909
|
+
let vlq = value < 0 ? -value << 1 | 1 : value << 1;
|
|
41910
|
+
let encoded = "";
|
|
41911
|
+
do {
|
|
41912
|
+
let digit = vlq & 31;
|
|
41913
|
+
vlq >>>= 5;
|
|
41914
|
+
if (vlq > 0) digit |= 32;
|
|
41915
|
+
encoded += VLQ_CHARS[digit];
|
|
41916
|
+
} while (vlq > 0);
|
|
41917
|
+
return encoded;
|
|
41918
|
+
}
|
|
41919
|
+
function buildIdentityTokenSourceMap(source, tokens2) {
|
|
41920
|
+
const lines = [];
|
|
41921
|
+
let prevOrigLine = 0;
|
|
41922
|
+
let prevOrigCol = 0;
|
|
41923
|
+
for (const { line, col } of tokens2) {
|
|
41924
|
+
const lineIndex = line - 1;
|
|
41925
|
+
while (lines.length <= lineIndex) lines.push([]);
|
|
41926
|
+
const row = lines[lineIndex];
|
|
41927
|
+
const prevGenCol = row.length === 0 ? 0 : prevOrigCol;
|
|
41928
|
+
row.push(
|
|
41929
|
+
encodeVlq(col - prevGenCol) + "A" + encodeVlq(lineIndex - prevOrigLine) + encodeVlq(col - prevOrigCol)
|
|
41930
|
+
);
|
|
41931
|
+
prevOrigLine = lineIndex;
|
|
41932
|
+
prevOrigCol = col;
|
|
41933
|
+
}
|
|
41934
|
+
return JSON.stringify({
|
|
41935
|
+
version: 3,
|
|
41936
|
+
sources: ["hf-authored-bundle.js"],
|
|
41937
|
+
sourcesContent: [source],
|
|
41938
|
+
mappings: lines.map((row) => row.join(",")).join(";"),
|
|
41939
|
+
names: []
|
|
41940
|
+
});
|
|
41941
|
+
}
|
|
41942
|
+
function replaceCommentSpansWithSpaces(source, comments) {
|
|
41943
|
+
if (comments.length === 0) return source.trimEnd();
|
|
41944
|
+
let out = "";
|
|
41945
|
+
let cursor = 0;
|
|
41946
|
+
for (const [start, end] of comments) {
|
|
41947
|
+
out += source.slice(cursor, start);
|
|
41948
|
+
out += source.slice(start, end).replace(/[^\r\n\u2028\u2029]/g, " ");
|
|
41949
|
+
cursor = end;
|
|
41950
|
+
}
|
|
41951
|
+
out += source.slice(cursor);
|
|
41952
|
+
return out.trimEnd();
|
|
41953
|
+
}
|
|
41954
|
+
var TOKENIZER_OPTIONS = {
|
|
41955
|
+
ecmaVersion: "latest",
|
|
41956
|
+
sourceType: "script",
|
|
41957
|
+
allowHashBang: true,
|
|
41958
|
+
allowReturnOutsideFunction: true,
|
|
41959
|
+
allowAwaitOutsideFunction: true,
|
|
41960
|
+
allowImportExportEverywhere: true
|
|
41961
|
+
};
|
|
41962
|
+
function endsWithLineComment(source) {
|
|
41963
|
+
if (!source) return false;
|
|
41964
|
+
let lastLineCommentEnd = -1;
|
|
41965
|
+
try {
|
|
41966
|
+
const stream = tokenizer(source, {
|
|
41967
|
+
...TOKENIZER_OPTIONS,
|
|
41968
|
+
onComment: (block, _text, _start, end) => {
|
|
41969
|
+
if (!block) lastLineCommentEnd = end;
|
|
41970
|
+
}
|
|
41971
|
+
});
|
|
41972
|
+
for (const _token of stream) {
|
|
41973
|
+
}
|
|
41974
|
+
return lastLineCommentEnd === source.length;
|
|
41975
|
+
} catch {
|
|
41976
|
+
return /\/\/[^\r\n\u2028\u2029]*$/.test(source);
|
|
41977
|
+
}
|
|
41978
|
+
}
|
|
41979
|
+
function stripJsCommentsInProcess(source, provenance) {
|
|
41980
|
+
if (!source) return source;
|
|
41981
|
+
const comments = [];
|
|
41982
|
+
const tokens2 = [];
|
|
41983
|
+
try {
|
|
41984
|
+
const stream = tokenizer(source, {
|
|
41985
|
+
...TOKENIZER_OPTIONS,
|
|
41986
|
+
locations: Boolean(provenance),
|
|
41987
|
+
onComment: (_block, _text, start, end) => {
|
|
41988
|
+
comments.push([start, end]);
|
|
41989
|
+
}
|
|
41990
|
+
});
|
|
41991
|
+
for (const token of stream) {
|
|
41992
|
+
if (provenance && token.loc) {
|
|
41993
|
+
tokens2.push({ line: token.loc.start.line, col: token.loc.start.column });
|
|
41994
|
+
}
|
|
41995
|
+
}
|
|
41996
|
+
} catch {
|
|
41997
|
+
return source;
|
|
41998
|
+
}
|
|
41999
|
+
const output = replaceCommentSpansWithSpaces(source, comments);
|
|
42000
|
+
if (provenance) {
|
|
42001
|
+
const sourceURL = `hf-inspect-${createHash3("sha256").update(source).digest("hex")}.js`;
|
|
42002
|
+
const sourceMap = buildIdentityTokenSourceMap(source, tokens2);
|
|
42003
|
+
provenance({ input: source, output, sourceMap, sourceURL });
|
|
42004
|
+
return `${output}
|
|
42005
|
+
//# sourceURL=${sourceURL}`;
|
|
42006
|
+
}
|
|
42007
|
+
return output;
|
|
42008
|
+
}
|
|
41906
42009
|
|
|
41907
42010
|
// ../core/src/compiler/compositionAssembly.ts
|
|
41908
42011
|
var COMPOSITION_ID_ATTR = "data-composition-id";
|
|
@@ -65493,7 +65596,7 @@ function pushRun(runs, scene, chunk) {
|
|
|
65493
65596
|
if (last && last.scene === scene) last.chunks.push(chunk);
|
|
65494
65597
|
else runs.push({ scene, chunks: [chunk] });
|
|
65495
65598
|
}
|
|
65496
|
-
|
|
65599
|
+
function coalesceHeadStylesAndBodyScripts(document2, provenance) {
|
|
65497
65600
|
const allHeadStyles = [...document2.querySelectorAll("head style")];
|
|
65498
65601
|
const isScenePart = (el) => el.hasAttribute(SCENE_PART_ATTR);
|
|
65499
65602
|
for (const run of allHeadStyles.length > 1 ? headStyleRuns(allHeadStyles, isScenePart) : []) {
|
|
@@ -65511,13 +65614,13 @@ async function coalesceHeadStylesAndBodyScripts(document2, provenance) {
|
|
|
65511
65614
|
const mergedJs = joinJsChunks(members.map((el) => el.textContent || ""));
|
|
65512
65615
|
if (mergedJs && !parsesAsScript(mergedJs)) {
|
|
65513
65616
|
for (const el of members)
|
|
65514
|
-
el.textContent =
|
|
65617
|
+
el.textContent = inlineScriptSource(el.textContent || "", provenance);
|
|
65515
65618
|
continue;
|
|
65516
65619
|
}
|
|
65517
65620
|
for (const el of members) el.remove();
|
|
65518
65621
|
if (!mergedJs) continue;
|
|
65519
65622
|
const inlineScript = document2.createElement("script");
|
|
65520
|
-
inlineScript.textContent =
|
|
65623
|
+
inlineScript.textContent = inlineScriptSource(mergedJs, provenance);
|
|
65521
65624
|
if (anchor) anchor.before(inlineScript);
|
|
65522
65625
|
else document2.body.appendChild(inlineScript);
|
|
65523
65626
|
}
|
|
@@ -65532,7 +65635,9 @@ function injectTextRenderingRule(document2) {
|
|
|
65532
65635
|
head.insertBefore(styleEl, head.firstChild);
|
|
65533
65636
|
}
|
|
65534
65637
|
function joinJsChunks(chunks) {
|
|
65535
|
-
return chunks.map((chunk) => chunk.trim()).filter((chunk) => chunk.length > 0).map(
|
|
65638
|
+
return chunks.map((chunk) => chunk.trim()).filter((chunk) => chunk.length > 0).map(
|
|
65639
|
+
(chunk) => chunk.endsWith(";") ? chunk : chunk + (endsWithLineComment(chunk) ? "\n;" : ";")
|
|
65640
|
+
).join("\n");
|
|
65536
65641
|
}
|
|
65537
65642
|
function parsesAsScript(source) {
|
|
65538
65643
|
try {
|
|
@@ -65542,29 +65647,8 @@ function parsesAsScript(source) {
|
|
|
65542
65647
|
return false;
|
|
65543
65648
|
}
|
|
65544
65649
|
}
|
|
65545
|
-
|
|
65546
|
-
|
|
65547
|
-
const { transform } = await import("esbuild");
|
|
65548
|
-
try {
|
|
65549
|
-
const result = await transform(source, {
|
|
65550
|
-
loader: "js",
|
|
65551
|
-
minify: false,
|
|
65552
|
-
legalComments: "none",
|
|
65553
|
-
...provenance ? { sourcemap: "external", sourcefile: "hf-authored-bundle.js" } : {}
|
|
65554
|
-
});
|
|
65555
|
-
if (provenance) {
|
|
65556
|
-
const sourceURL = `hf-inspect-${createHash3("sha256").update(source).digest("hex")}.js`;
|
|
65557
|
-
provenance({ input: source, output: result.code.trim(), sourceMap: result.map, sourceURL });
|
|
65558
|
-
return `${result.code.trim()}
|
|
65559
|
-
//# sourceURL=${sourceURL}`;
|
|
65560
|
-
}
|
|
65561
|
-
return result.code.trim();
|
|
65562
|
-
} catch {
|
|
65563
|
-
return source;
|
|
65564
|
-
}
|
|
65565
|
-
}
|
|
65566
|
-
async function inlineScriptSource(js, provenance) {
|
|
65567
|
-
return escapeInlineScriptSource(await stripJsCommentsParserSafe(js, provenance));
|
|
65650
|
+
function inlineScriptSource(js, provenance) {
|
|
65651
|
+
return escapeInlineScriptSource(stripJsCommentsInProcess(js, provenance));
|
|
65568
65652
|
}
|
|
65569
65653
|
function scriptTagsBySrc(doc) {
|
|
65570
65654
|
let index;
|
|
@@ -66057,7 +66141,7 @@ async function bundleProject(projectDir, options) {
|
|
|
66057
66141
|
for (const text of parsesAsScript(joined) ? [joined] : texts.filter(Boolean)) {
|
|
66058
66142
|
const script = document2.createElement("script");
|
|
66059
66143
|
if (scene) script.setAttribute(SCENE_PART_ATTR, scene);
|
|
66060
|
-
script.textContent = skipsRunMerge ?
|
|
66144
|
+
script.textContent = skipsRunMerge ? inlineScriptSource(text, options?.scriptProvenance) : text;
|
|
66061
66145
|
document2.body.appendChild(script);
|
|
66062
66146
|
}
|
|
66063
66147
|
}
|
|
@@ -66065,11 +66149,11 @@ async function bundleProject(projectDir, options) {
|
|
|
66065
66149
|
emitRootCompositionVariableStyles(document2, compVariablesByComp);
|
|
66066
66150
|
enforceCompositionPixelSizing(document2);
|
|
66067
66151
|
autoHealMissingCompositionIds(document2);
|
|
66068
|
-
|
|
66152
|
+
coalesceHeadStylesAndBodyScripts(document2, options?.scriptProvenance);
|
|
66069
66153
|
for (const el of document2.querySelectorAll(`script[${INLINED_FILE_ATTR}]`)) {
|
|
66070
66154
|
const js = el.textContent ?? "";
|
|
66071
66155
|
el.textContent = escapeInlineScriptSource(
|
|
66072
|
-
isJavaScriptType(el) ?
|
|
66156
|
+
isJavaScriptType(el) ? stripJsCommentsInProcess(js, options?.scriptProvenance) : js
|
|
66073
66157
|
);
|
|
66074
66158
|
}
|
|
66075
66159
|
deferScriptsUntilFonts(document2, (el) => el.hasAttribute(RUNTIME_BOOTSTRAP_ATTR));
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface StrippedScriptProvenance {
|
|
2
|
+
input: string;
|
|
3
|
+
output: string;
|
|
4
|
+
sourceMap: string;
|
|
5
|
+
sourceURL: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Whether `source` ends with an unterminated single-line comment (so appending `;`
|
|
9
|
+
* on the same line would be swallowed by the comment).
|
|
10
|
+
*/
|
|
11
|
+
export declare function endsWithLineComment(source: string): boolean;
|
|
12
|
+
export declare function stripJsCommentsInProcess(source: string, provenance?: (script: StrippedScriptProvenance) => void): string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hyperframes/inspector",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.7",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/heygen-com/hyperframes",
|
|
@@ -43,8 +43,8 @@
|
|
|
43
43
|
"htmlparser2": "^10.1.0",
|
|
44
44
|
"postcss": "^8.5.8",
|
|
45
45
|
"puppeteer-core": "^25.8.0",
|
|
46
|
-
"@hyperframes/parsers": "0.10.
|
|
47
|
-
"@hyperframes/core": "0.10.
|
|
46
|
+
"@hyperframes/parsers": "0.10.7",
|
|
47
|
+
"@hyperframes/core": "0.10.7"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@types/node": "^25.0.10",
|