mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-18 16:08:56 +00:00
* feat(studio): load GSAP from the CLI's bundled copy by default Studio preview now loads the GSAP, CustomEase and MotionPathPlugin scripts it adds from files the CLI ships and serves same-origin at /api/vendor/npm, instead of jsDelivr. HYPERFRAMES_GSAP_BASE_URL still wins when set, and a composition on another GSAP version gets its plugin from jsDelivr. Renders now honor HYPERFRAMES_GSAP_BASE_URL when they replace a missing local GSAP script, and the setting accepts plain http only for loopback hosts. Closes #6205 Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * refactor(studio): keep comment share flat for the GSAP local root Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix(cli): find the installed gsap with node resolution when run from source The Windows CI lane installs with the hoisted linker, so gsap is not under packages/core/node_modules there. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix(producer): load a nested composition's missing GSAP from the mirror A sub-composition's missing local gsap/dist script was hoisted into the render unchanged, so HYPERFRAMES_GSAP_BASE_URL (and the jsDelivr fallback) only reached the entry document. Run the same rewrite on every sub-composition before it is compiled, resolving its path the way the inliner will hoist it. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
54 lines
2.3 KiB
TypeScript
54 lines
2.3 KiB
TypeScript
export const GSAP_CDN_VERSION = "3.15.0";
|
|
const GSAP_CDN_BASE_URL = "https://cdn.jsdelivr.net/npm";
|
|
export const GSAP_BASE_URL_META = "hyperframes-gsap-base-url";
|
|
|
|
function isLoopbackHost(hostname: string): boolean {
|
|
return hostname === "localhost" || hostname === "[::1]" || /^127\.\d+\.\d+\.\d+$/.test(hostname);
|
|
}
|
|
|
|
/** An npm-style mirror root; callers choose configuration without coupling this helper to a host. */
|
|
export function normalizeGsapBaseUrl(baseUrl?: string): string {
|
|
const value = baseUrl?.trim();
|
|
if (!value) return GSAP_CDN_BASE_URL;
|
|
if (!/^https?:\/\//i.test(value) || !URL.canParse(value) || /[?#]/.test(value)) {
|
|
throw new Error("GSAP base URL must be an absolute HTTP(S) URL without a query or fragment");
|
|
}
|
|
const url = new URL(value);
|
|
if (url.username || url.password) {
|
|
throw new Error("GSAP base URL must not contain credentials");
|
|
}
|
|
if (url.protocol === "http:" && !isLoopbackHost(url.hostname)) {
|
|
throw new Error("GSAP base URL must use HTTPS unless it points at this machine");
|
|
}
|
|
return url.href.replace(/\/+$/, "");
|
|
}
|
|
|
|
/** A same-origin path to the host's bundled GSAP, which holds only GSAP_CDN_VERSION. */
|
|
export function normalizeGsapLocalRoot(root: string): string {
|
|
const value = root.trim();
|
|
if (!/^\/(?![/\\])/.test(value) || /[?#\\]/.test(value)) {
|
|
throw new Error("GSAP local root must be a same-origin path such as /vendor/npm");
|
|
}
|
|
const origin = "http://local.invalid";
|
|
const url = new URL(value, origin);
|
|
const path = url.pathname.replace(/\/+$/, "");
|
|
if (url.origin !== origin || !path) {
|
|
throw new Error("GSAP local root must be a same-origin path such as /vendor/npm");
|
|
}
|
|
return path;
|
|
}
|
|
|
|
export function gsapCdnDist(gsapVersion?: string, baseUrl?: string): string {
|
|
const version = gsapVersion && /^\d+(\.\d+)*$/.test(gsapVersion) ? gsapVersion : GSAP_CDN_VERSION;
|
|
if (baseUrl?.trim().startsWith("/")) {
|
|
const root = normalizeGsapLocalRoot(baseUrl);
|
|
return `${version === GSAP_CDN_VERSION ? root : GSAP_CDN_BASE_URL}/gsap@${version}/dist/`;
|
|
}
|
|
return `${normalizeGsapBaseUrl(baseUrl)}/gsap@${version}/dist/`;
|
|
}
|
|
|
|
/** MotionPathPlugin at the composition's own gsap version; a skew registers with a GSAP warning. */
|
|
export function motionPathPluginUrl(gsapVersion?: string, baseUrl?: string): string {
|
|
return `${gsapCdnDist(gsapVersion, baseUrl)}MotionPathPlugin.min.js`;
|
|
}
|