@hyperframes/core 0.8.204 → 0.8.206
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/compositionScoping.d.ts +2 -0
- package/dist/compiler/compositionScoping.js +4 -0
- package/dist/compiler/htmlBundler.js +4 -5
- package/dist/compiler/index.d.ts +2 -2
- package/dist/compiler/index.js +2 -2
- package/dist/compiler/inlineSubCompositions.js +2 -2
- package/dist/compiler/pngColourTags.d.ts +2 -0
- package/dist/compiler/pngColourTags.js +27 -0
- package/dist/compiler/scriptRuns.d.ts +1 -1
- package/dist/compiler/scriptRuns.js +4 -1
- package/dist/generated/runtime-inline.js +1 -1
- package/dist/generators/hyperframes.js +4 -1
- package/dist/hyperframe.runtime.iife.js +66 -64
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/runtime/media.js +4 -3
- package/dist/runtime/mediaClock.d.ts +2 -0
- package/dist/runtime/mediaClock.js +4 -0
- package/dist/runtime/preloadMedia.js +2 -1
- package/dist/runtime/startResolver.js +6 -8
- package/package.json +12 -4
|
@@ -13,6 +13,8 @@ export declare function hoistFontFaceRules(styleTexts: string[]): {
|
|
|
13
13
|
styles: string[];
|
|
14
14
|
faces: string[];
|
|
15
15
|
};
|
|
16
|
+
export declare const AUTHORED_SOURCE_BEGIN = "/*hf-authored-begin*/";
|
|
17
|
+
export declare const AUTHORED_SOURCE_END = "/*hf-authored-end*/";
|
|
16
18
|
export declare function scopedModulePrelude(timelineCompositionId: string, compositionSrc?: string | null): string;
|
|
17
19
|
export declare function wrapScopedCompositionScript(source: string, compositionId: string, errorLabel?: string, scopeSelectorOverride?: string, timelineCompositionId?: string, authoredRootId?: string | null, compositionSrc?: string | null): string;
|
|
18
20
|
export declare function wrapInlineScriptWithErrorBoundary(source: string, errorLabel: string): string;
|
|
@@ -295,6 +295,8 @@ const SCOPED_HYPERFRAMES_EXPRESSION = `!__hfBaseHyperframes
|
|
|
295
295
|
return scoped ? Object.assign({}, scoped) : {};
|
|
296
296
|
},
|
|
297
297
|
})`;
|
|
298
|
+
export const AUTHORED_SOURCE_BEGIN = "/*hf-authored-begin*/";
|
|
299
|
+
export const AUTHORED_SOURCE_END = "/*hf-authored-end*/";
|
|
298
300
|
export function scopedModulePrelude(timelineCompositionId, compositionSrc) {
|
|
299
301
|
return `const __hyperframes = (function(__hfBaseHyperframes, __hfTimelineCompId, __hfCompositionSrc) {
|
|
300
302
|
return ${SCOPED_HYPERFRAMES_EXPRESSION};
|
|
@@ -581,7 +583,9 @@ export function wrapScopedCompositionScript(source, compositionId, errorLabel =
|
|
|
581
583
|
if (typeof report === "function") report("start", __hfCompositionSrc || "index.html");
|
|
582
584
|
try {
|
|
583
585
|
(function(document, gsap, window, __hyperframes) {
|
|
586
|
+
${AUTHORED_SOURCE_BEGIN}
|
|
584
587
|
${source.replace(/<\/(script)/gi, "<\\/$1")}
|
|
588
|
+
${AUTHORED_SOURCE_END}
|
|
585
589
|
}).call(window, __hfScopedDocument, __hfScopedGsap, __hfScopedWindow, __hfScopedHyperframes);
|
|
586
590
|
} catch (_err) {
|
|
587
591
|
console.error(__hfErrorLabel, __hfCompId, _err);
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
|
-
import { compositionStyle, cssStyleMergeKey, deferScriptsUntilFonts,
|
|
2
|
+
import { compositionStyle, cssStyleMergeKey, deferScriptsUntilFonts, isAlwaysAppliedStyle, headStyleRuns, INLINED_FILE_ATTR, inlineScriptRuns, styleElementsFor, } from "./scriptRuns.js";
|
|
3
3
|
import { countPageRoot, executableScripts, isJavaScriptType, planCompositionAssembly, } from "./compositionAssembly.js";
|
|
4
4
|
import { SCENE_FONTS_ATTR, SCENE_PART_ATTR } from "../sceneParts.js";
|
|
5
|
+
import { stripSdrPngColourTags } from "./pngColourTags.js";
|
|
5
6
|
import { ensureExternalScriptTag, readExternalScriptAttributes, } from "./externalScripts.js";
|
|
6
7
|
import { emitMountedModuleScripts, parseImportMap } from "./importMaps.js";
|
|
7
8
|
import { markFlattenedInnerRoot } from "../runtime/flattenedRoot.js";
|
|
@@ -313,7 +314,8 @@ function createAssetInliner(resolveProjectPath, inlineAssets) {
|
|
|
313
314
|
const byteLength = safeStatSize(filePath);
|
|
314
315
|
if (byteLength !== null && byteLength > MAX_INLINE_ASSET_BYTES)
|
|
315
316
|
return { tooLarge: byteLength };
|
|
316
|
-
const
|
|
317
|
+
const read = safeReadFileBuffer(filePath);
|
|
318
|
+
const content = read && mimeType === "image/png" ? (stripSdrPngColourTags(read) ?? read) : read;
|
|
317
319
|
return {
|
|
318
320
|
dataUrl: content === null ? null : `data:${mimeType};base64,${content.toString("base64")}`,
|
|
319
321
|
};
|
|
@@ -640,9 +642,6 @@ function placeSceneStylesLikeRender(document) {
|
|
|
640
642
|
holder.textContent = hoisted;
|
|
641
643
|
first.before(holder);
|
|
642
644
|
}
|
|
643
|
-
function isAlwaysAppliedStyle(el) {
|
|
644
|
-
return cssStyleMergeKey(el) === UNCONDITIONAL_CSS_KEY && !el.closest("template, noscript, svg");
|
|
645
|
-
}
|
|
646
645
|
function pushRun(runs, scene, chunk) {
|
|
647
646
|
const last = runs.at(-1);
|
|
648
647
|
if (last && last.scene === scene)
|
package/dist/compiler/index.d.ts
CHANGED
|
@@ -6,10 +6,10 @@ export { readDeclaredDefaults, parseHostVariableValues } from "../runtime/getVar
|
|
|
6
6
|
export { extractCompiledHtmlParityContract, type CompiledHtmlParityContract, type HtmlParityComposition, type HtmlParityResource, type HtmlParityTimedElement, } from "./htmlParityContract.js";
|
|
7
7
|
export { RUNTIME_BOOTSTRAP_ATTR, injectScriptsAtHeadStart, injectTagsAtHeadStart, injectScriptsIntoHtml, insertBeforeCloseTag, insertRuntimeTag, isRuntimeFileUrl, parseHTMLContent, stripEmbeddedRuntimeScripts, } from "./htmlDocument.js";
|
|
8
8
|
export { addScenePartsManifest } from "./scenePartsManifest.js";
|
|
9
|
-
export { AFTER_FONTS_SCRIPT_TYPE, compositionStyle, cssStyleMergeKey, deferScriptsUntilFonts, headStyleRuns, inlineScriptRuns, styleElementsFor, type CompositionStyle, type InlineScriptRun, } from "./scriptRuns.js";
|
|
9
|
+
export { AFTER_FONTS_SCRIPT_TYPE, compositionStyle, cssStyleMergeKey, isAlwaysAppliedStyle, deferScriptsUntilFonts, headStyleRuns, inlineScriptRuns, styleElementsFor, type CompositionStyle, type InlineScriptRun, } from "./scriptRuns.js";
|
|
10
10
|
export { isJavaScriptType } from "./compositionAssembly.js";
|
|
11
11
|
export { validateHyperframeHtmlContract, type HyperframeStaticFailureReason, type HyperframeStaticGuardResult, } from "./staticGuard.js";
|
|
12
|
-
export { buildVariablesByCompScript, scopeCssToComposition, wrapScopedCompositionScript, } from "./compositionScoping.js";
|
|
12
|
+
export { buildVariablesByCompScript, dedupeFontFaceRules, scopeCssToComposition, wrapScopedCompositionScript, } from "./compositionScoping.js";
|
|
13
13
|
export { ensureExternalLinkTag, inlineSubCompositions, type InlineSubCompositionsOptions, type InlineSubCompositionsResult, } from "./inlineSubCompositions.js";
|
|
14
14
|
export { extractStandaloneEntryFromIndex, isTemplateEntry } from "./standaloneEntry.js";
|
|
15
15
|
export { checkSubCompositionUsability, type ParsableDocumentLike, type SubCompositionValidity, type SubCompositionValidityReason, } from "./subCompositionValidity.js";
|
package/dist/compiler/index.js
CHANGED
|
@@ -12,12 +12,12 @@ export { extractCompiledHtmlParityContract, } from "./htmlParityContract.js";
|
|
|
12
12
|
export { RUNTIME_BOOTSTRAP_ATTR, injectScriptsAtHeadStart, injectTagsAtHeadStart, injectScriptsIntoHtml, insertBeforeCloseTag, insertRuntimeTag, isRuntimeFileUrl, parseHTMLContent, stripEmbeddedRuntimeScripts, } from "./htmlDocument.js";
|
|
13
13
|
export { addScenePartsManifest } from "./scenePartsManifest.js";
|
|
14
14
|
// Script ordering shared by the bundler and the producer coalescers
|
|
15
|
-
export { AFTER_FONTS_SCRIPT_TYPE, compositionStyle, cssStyleMergeKey, deferScriptsUntilFonts, headStyleRuns, inlineScriptRuns, styleElementsFor, } from "./scriptRuns.js";
|
|
15
|
+
export { AFTER_FONTS_SCRIPT_TYPE, compositionStyle, cssStyleMergeKey, isAlwaysAppliedStyle, deferScriptsUntilFonts, headStyleRuns, inlineScriptRuns, styleElementsFor, } from "./scriptRuns.js";
|
|
16
16
|
export { isJavaScriptType } from "./compositionAssembly.js";
|
|
17
17
|
// Static guard
|
|
18
18
|
export { validateHyperframeHtmlContract, } from "./staticGuard.js";
|
|
19
19
|
// Composition isolation helpers
|
|
20
|
-
export { buildVariablesByCompScript, scopeCssToComposition, wrapScopedCompositionScript, } from "./compositionScoping.js";
|
|
20
|
+
export { buildVariablesByCompScript, dedupeFontFaceRules, scopeCssToComposition, wrapScopedCompositionScript, } from "./compositionScoping.js";
|
|
21
21
|
// Sub-composition inlining (shared between bundler and producer)
|
|
22
22
|
export { ensureExternalLinkTag, inlineSubCompositions, } from "./inlineSubCompositions.js";
|
|
23
23
|
export { extractStandaloneEntryFromIndex, isTemplateEntry } from "./standaloneEntry.js";
|
|
@@ -13,7 +13,7 @@ import { compositionStyle, cssStyleMergeKey, hasSameLink, } from "./scriptRuns.j
|
|
|
13
13
|
*/
|
|
14
14
|
import { rewriteAssetPath, rewriteAssetPaths, rewriteCssAssetUrls, rewriteInlineStyleAssetUrls, } from "./rewriteSubCompPaths.js";
|
|
15
15
|
import { warnUnknownEnumValues } from "../runtime/getVariables.js";
|
|
16
|
-
import { createCompositionCssScoper, wrapInlineScriptWithErrorBoundary, scopedModulePrelude, wrapScopedCompositionScript, } from "./compositionScoping.js";
|
|
16
|
+
import { createCompositionCssScoper, AUTHORED_SOURCE_BEGIN, AUTHORED_SOURCE_END, wrapInlineScriptWithErrorBoundary, scopedModulePrelude, wrapScopedCompositionScript, } from "./compositionScoping.js";
|
|
17
17
|
import { namespaceCollidingSvgIds, rewriteSvgIdReferencesInCss, } from "./svgIdNamespacing.js";
|
|
18
18
|
import { checkSubCompositionUsability, resolveSubCompositionContent, } from "@hyperframes/parsers/sub-composition-validity";
|
|
19
19
|
import { enumerateNestedCompositionHosts, planCompositionAssembly, extractedCompositionAssets, } from "./compositionAssembly.js";
|
|
@@ -419,7 +419,7 @@ export function inlineSubCompositions(document, hosts, options) {
|
|
|
419
419
|
const prelude = scriptCompositionId
|
|
420
420
|
? scopedModulePrelude(runtimeCompId || scopeCompId || scriptCompositionId, src)
|
|
421
421
|
: "";
|
|
422
|
-
moduleScripts.push(prelude
|
|
422
|
+
moduleScripts.push(`${prelude}${AUTHORED_SOURCE_BEGIN}\n${scriptEl.textContent || ""}\n${AUTHORED_SOURCE_END}`);
|
|
423
423
|
}
|
|
424
424
|
else if (externalSrc) {
|
|
425
425
|
if (!externalScriptSrcs.includes(externalSrc)) {
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const PNG_SIGNATURE = Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
|
|
2
|
+
const PNG_SIGNATURE_BYTES = PNG_SIGNATURE.length;
|
|
3
|
+
const CHUNK_OVERHEAD_BYTES = 12;
|
|
4
|
+
const REMOVED_CHUNKS = new Set(["cICP", "gAMA", "cHRM"]);
|
|
5
|
+
const HDR_CICP_TRANSFERS = new Set([16, 18]);
|
|
6
|
+
/** An SDR PNG's copy without the tags that make Chrome re-map its pixels; null if none apply or it is HDR. */
|
|
7
|
+
export function stripSdrPngColourTags(png) {
|
|
8
|
+
const bytes = Buffer.from(png.buffer, png.byteOffset, png.byteLength);
|
|
9
|
+
if (!bytes.subarray(0, PNG_SIGNATURE_BYTES).equals(PNG_SIGNATURE))
|
|
10
|
+
return null;
|
|
11
|
+
const kept = [bytes.subarray(0, PNG_SIGNATURE_BYTES)];
|
|
12
|
+
let removed = false;
|
|
13
|
+
for (let at = PNG_SIGNATURE_BYTES; at + CHUNK_OVERHEAD_BYTES <= bytes.length;) {
|
|
14
|
+
const end = at + CHUNK_OVERHEAD_BYTES + bytes.readUInt32BE(at);
|
|
15
|
+
if (end > bytes.length)
|
|
16
|
+
return null;
|
|
17
|
+
const type = bytes.toString("latin1", at + 4, at + 8);
|
|
18
|
+
if (type === "cICP" && HDR_CICP_TRANSFERS.has(bytes[at + 9] ?? 0))
|
|
19
|
+
return null;
|
|
20
|
+
if (REMOVED_CHUNKS.has(type))
|
|
21
|
+
removed = true;
|
|
22
|
+
else
|
|
23
|
+
kept.push(bytes.subarray(at, end));
|
|
24
|
+
at = end;
|
|
25
|
+
}
|
|
26
|
+
return removed ? Buffer.concat(kept) : null;
|
|
27
|
+
}
|
|
@@ -17,7 +17,7 @@ export declare function deferScriptsUntilFonts(document: Document, isFramework?:
|
|
|
17
17
|
export declare function typeAfterFonts(el: Element): string | null;
|
|
18
18
|
/** Undefined for a type the browser never applies as CSS; `media="all"` and an empty title count as none. */
|
|
19
19
|
export declare function cssStyleMergeKey(el: Element): string | undefined;
|
|
20
|
-
export declare
|
|
20
|
+
export declare function isAlwaysAppliedStyle(el: Element): boolean;
|
|
21
21
|
export declare function hasSameLink(scope: ParentNode, link: Element): boolean;
|
|
22
22
|
/** Groups head styles into runs of adjacent styles with one merge key, so merging a run never reorders rules. */
|
|
23
23
|
export declare function headStyleRuns(styles: readonly Element[], isPinned?: (el: Element) => boolean): Element[][];
|
|
@@ -102,7 +102,10 @@ export function cssStyleMergeKey(el) {
|
|
|
102
102
|
const media = (el.getAttribute("media") ?? "").trim().toLowerCase();
|
|
103
103
|
return JSON.stringify([media === "all" ? "" : media, el.getAttribute("title") ?? ""]);
|
|
104
104
|
}
|
|
105
|
-
|
|
105
|
+
const UNCONDITIONAL_CSS_KEY = JSON.stringify(["", ""]);
|
|
106
|
+
export function isAlwaysAppliedStyle(el) {
|
|
107
|
+
return cssStyleMergeKey(el) === UNCONDITIONAL_CSS_KEY && !el.closest("template, noscript, svg");
|
|
108
|
+
}
|
|
106
109
|
/** A link's identity and condition; fetch attributes (crossorigin, integrity, referrerpolicy) are not compared. */
|
|
107
110
|
function linkDedupeKey(el) {
|
|
108
111
|
return JSON.stringify([
|