@hyperframes/core 0.8.150 → 0.8.152
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/compiler/htmlBundler.d.ts +8 -0
- package/dist/compiler/htmlBundler.js +25 -10
- package/dist/compiler/index.d.ts +1 -1
- package/dist/generated/runtime-inline.js +1 -1
- package/dist/hyperframe.runtime.iife.js +54 -54
- package/dist/keyframeDefaults.d.ts +1 -0
- package/dist/keyframeDefaults.js +12 -0
- package/dist/runtime/startResolver.js +1 -1
- package/package.json +8 -4
|
@@ -7,7 +7,15 @@ export type BundledHostCompositionIdentity = {
|
|
|
7
7
|
export declare function assignBundledRuntimeCompositionIds(hosts: Element[], counts?: Map<string, number>): Map<Element, BundledHostCompositionIdentity>;
|
|
8
8
|
export declare function prepareFlattenedInnerRoot(innerRoot: Element): Element;
|
|
9
9
|
export declare function parsesAsScript(source: string): boolean;
|
|
10
|
+
export interface BundleScriptProvenance {
|
|
11
|
+
input: string;
|
|
12
|
+
output: string;
|
|
13
|
+
sourceMap: string;
|
|
14
|
+
sourceURL?: string;
|
|
15
|
+
}
|
|
10
16
|
export interface BundleOptions {
|
|
17
|
+
/** Optional source mapping for inspection; does not alter bundled HTML. */
|
|
18
|
+
scriptProvenance?: (script: BundleScriptProvenance) => void;
|
|
11
19
|
/** Project-relative HTML entry to bundle. Defaults to `index.html`. */
|
|
12
20
|
entryFile?: string;
|
|
13
21
|
stampHfIds?: boolean;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
1
2
|
import { compositionStyle, cssStyleMergeKey, deferScriptsUntilFonts, UNCONDITIONAL_CSS_KEY, headStyleRuns, INLINED_FILE_ATTR, inlineScriptRuns, styleElementsFor, } from "./scriptRuns.js";
|
|
2
3
|
import { executableScripts, isJavaScriptType, planCompositionAssembly, } from "./compositionAssembly.js";
|
|
3
4
|
import { SCENE_PART_ATTR } from "../sceneParts.js";
|
|
@@ -650,7 +651,7 @@ function pushRun(runs, scene, chunk) {
|
|
|
650
651
|
else
|
|
651
652
|
runs.push({ scene, chunks: [chunk] });
|
|
652
653
|
}
|
|
653
|
-
function coalesceHeadStylesAndBodyScripts(document) {
|
|
654
|
+
function coalesceHeadStylesAndBodyScripts(document, provenance) {
|
|
654
655
|
const allHeadStyles = [...document.querySelectorAll("head style")];
|
|
655
656
|
const isScenePart = (el) => el.hasAttribute(SCENE_PART_ATTR);
|
|
656
657
|
for (const run of allHeadStyles.length > 1 ? headStyleRuns(allHeadStyles, isScenePart) : []) {
|
|
@@ -668,7 +669,7 @@ function coalesceHeadStylesAndBodyScripts(document) {
|
|
|
668
669
|
const mergedJs = joinJsChunks(members.map((el) => el.textContent || ""));
|
|
669
670
|
if (mergedJs && !parsesAsScript(mergedJs)) {
|
|
670
671
|
for (const el of members)
|
|
671
|
-
el.textContent = inlineScriptSource(el.textContent || "");
|
|
672
|
+
el.textContent = inlineScriptSource(el.textContent || "", provenance);
|
|
672
673
|
continue;
|
|
673
674
|
}
|
|
674
675
|
for (const el of members)
|
|
@@ -676,7 +677,7 @@ function coalesceHeadStylesAndBodyScripts(document) {
|
|
|
676
677
|
if (!mergedJs)
|
|
677
678
|
continue;
|
|
678
679
|
const inlineScript = document.createElement("script");
|
|
679
|
-
inlineScript.textContent = inlineScriptSource(mergedJs);
|
|
680
|
+
inlineScript.textContent = inlineScriptSource(mergedJs, provenance);
|
|
680
681
|
if (anchor)
|
|
681
682
|
anchor.before(inlineScript);
|
|
682
683
|
else
|
|
@@ -739,19 +740,31 @@ export function parsesAsScript(source) {
|
|
|
739
740
|
return false;
|
|
740
741
|
}
|
|
741
742
|
}
|
|
742
|
-
function stripJsCommentsParserSafe(source) {
|
|
743
|
+
function stripJsCommentsParserSafe(source, provenance) {
|
|
743
744
|
if (!source)
|
|
744
745
|
return source;
|
|
745
746
|
try {
|
|
746
|
-
const result = transformSync(source, {
|
|
747
|
+
const result = transformSync(source, {
|
|
748
|
+
loader: "js",
|
|
749
|
+
minify: false,
|
|
750
|
+
legalComments: "none",
|
|
751
|
+
...(provenance
|
|
752
|
+
? { sourcemap: "external", sourcefile: "hf-authored-bundle.js" }
|
|
753
|
+
: {}),
|
|
754
|
+
});
|
|
755
|
+
if (provenance) {
|
|
756
|
+
const sourceURL = `hf-inspect-${createHash("sha256").update(source).digest("hex")}.js`;
|
|
757
|
+
provenance({ input: source, output: result.code.trim(), sourceMap: result.map, sourceURL });
|
|
758
|
+
return `${result.code.trim()}\n//# sourceURL=${sourceURL}`;
|
|
759
|
+
}
|
|
747
760
|
return result.code.trim();
|
|
748
761
|
}
|
|
749
762
|
catch {
|
|
750
763
|
return source;
|
|
751
764
|
}
|
|
752
765
|
}
|
|
753
|
-
function inlineScriptSource(js) {
|
|
754
|
-
return escapeInlineScriptSource(stripJsCommentsParserSafe(js));
|
|
766
|
+
function inlineScriptSource(js, provenance) {
|
|
767
|
+
return escapeInlineScriptSource(stripJsCommentsParserSafe(js, provenance));
|
|
755
768
|
}
|
|
756
769
|
function preserveLocalScriptIntegrity(doc, src, resolvePath) {
|
|
757
770
|
const path = resolvePath(src);
|
|
@@ -1117,7 +1130,9 @@ async function bundleProject(projectDir, options) {
|
|
|
1117
1130
|
const script = document.createElement("script");
|
|
1118
1131
|
if (scene)
|
|
1119
1132
|
script.setAttribute(SCENE_PART_ATTR, scene);
|
|
1120
|
-
script.textContent = skipsRunMerge
|
|
1133
|
+
script.textContent = skipsRunMerge
|
|
1134
|
+
? inlineScriptSource(text, options?.scriptProvenance)
|
|
1135
|
+
: text;
|
|
1121
1136
|
document.body.appendChild(script);
|
|
1122
1137
|
}
|
|
1123
1138
|
}
|
|
@@ -1125,10 +1140,10 @@ async function bundleProject(projectDir, options) {
|
|
|
1125
1140
|
emitRootCompositionVariableStyles(document, compVariablesByComp);
|
|
1126
1141
|
enforceCompositionPixelSizing(document);
|
|
1127
1142
|
autoHealMissingCompositionIds(document);
|
|
1128
|
-
coalesceHeadStylesAndBodyScripts(document);
|
|
1143
|
+
coalesceHeadStylesAndBodyScripts(document, options?.scriptProvenance);
|
|
1129
1144
|
for (const el of document.querySelectorAll(`script[${INLINED_FILE_ATTR}]`)) {
|
|
1130
1145
|
const js = el.textContent ?? "";
|
|
1131
|
-
el.textContent = escapeInlineScriptSource(isJavaScriptType(el) ? stripJsCommentsParserSafe(js) : js);
|
|
1146
|
+
el.textContent = escapeInlineScriptSource(isJavaScriptType(el) ? stripJsCommentsParserSafe(js, options?.scriptProvenance) : js);
|
|
1132
1147
|
}
|
|
1133
1148
|
deferScriptsUntilFonts(document, (el) => el.hasAttribute(RUNTIME_BOOTSTRAP_ATTR));
|
|
1134
1149
|
injectTextRenderingRule(document);
|
package/dist/compiler/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { resolveTimings, type WordTiming, type ElementAnchor, type AuthoredTiming, type ResolvedTiming, type ResolveTimingsInput, type ResolveTimingsResult, } from "./timingResolver";
|
|
2
2
|
export { compileTimingAttrs, injectDurations, extractResolvedMedia, clampDurations, shouldClampMediaDuration, shouldClampResolvedMediaDuration, type UnresolvedElement, type ResolvedDuration, type ResolvedMediaElement, type CompilationResult, } from "./timingCompiler";
|
|
3
3
|
export { compileHtml, type MediaDurationProber } from "./htmlCompiler";
|
|
4
|
-
export { assignBundledRuntimeCompositionIds, type BundledHostCompositionIdentity, bundleToSingleHtml, type BundleOptions, prepareFlattenedInnerRoot, FLATTENED_INNER_ROOT_STRIP_ATTRS, emitRootCompositionVariableStyles, parsesAsScript, } from "./htmlBundler";
|
|
4
|
+
export { assignBundledRuntimeCompositionIds, type BundledHostCompositionIdentity, bundleToSingleHtml, type BundleOptions, type BundleScriptProvenance, prepareFlattenedInnerRoot, FLATTENED_INNER_ROOT_STRIP_ATTRS, emitRootCompositionVariableStyles, parsesAsScript, } from "./htmlBundler";
|
|
5
5
|
export { readDeclaredDefaults, parseHostVariableValues } from "../runtime/getVariables";
|
|
6
6
|
export { extractCompiledHtmlParityContract, type CompiledHtmlParityContract, type HtmlParityComposition, type HtmlParityResource, type HtmlParityTimedElement, } from "./htmlParityContract";
|
|
7
7
|
export { RUNTIME_BOOTSTRAP_ATTR, injectScriptsAtHeadStart, injectTagsAtHeadStart, injectScriptsIntoHtml, insertBeforeCloseTag, insertRuntimeTag, isRuntimeFileUrl, parseHTMLContent, stripEmbeddedRuntimeScripts, } from "./htmlDocument";
|