@hyperframes/core 0.8.193 → 0.8.195

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/gsapCdn.d.ts CHANGED
@@ -1,3 +1,9 @@
1
- export declare function gsapCdnDist(gsapVersion?: string): string;
1
+ export declare const GSAP_CDN_VERSION = "3.15.0";
2
+ export declare const GSAP_BASE_URL_META = "hyperframes-gsap-base-url";
3
+ /** An npm-style mirror root; callers choose configuration without coupling this helper to a host. */
4
+ export declare function normalizeGsapBaseUrl(baseUrl?: string): string;
5
+ /** A same-origin path to the host's bundled GSAP, which holds only GSAP_CDN_VERSION. */
6
+ export declare function normalizeGsapLocalRoot(root: string): string;
7
+ export declare function gsapCdnDist(gsapVersion?: string, baseUrl?: string): string;
2
8
  /** MotionPathPlugin at the composition's own gsap version; a skew registers with a GSAP warning. */
3
- export declare function motionPathPluginUrl(gsapVersion?: string): string;
9
+ export declare function motionPathPluginUrl(gsapVersion?: string, baseUrl?: string): string;
package/dist/gsapCdn.js CHANGED
@@ -1,9 +1,49 @@
1
- const GSAP_CDN_VERSION = "3.15.0";
2
- export function gsapCdnDist(gsapVersion) {
1
+ export const GSAP_CDN_VERSION = "3.15.0";
2
+ const GSAP_CDN_BASE_URL = "https://cdn.jsdelivr.net/npm";
3
+ export const GSAP_BASE_URL_META = "hyperframes-gsap-base-url";
4
+ function isLoopbackHost(hostname) {
5
+ return hostname === "localhost" || hostname === "[::1]" || /^127\.\d+\.\d+\.\d+$/.test(hostname);
6
+ }
7
+ /** An npm-style mirror root; callers choose configuration without coupling this helper to a host. */
8
+ export function normalizeGsapBaseUrl(baseUrl) {
9
+ const value = baseUrl?.trim();
10
+ if (!value)
11
+ return GSAP_CDN_BASE_URL;
12
+ if (!/^https?:\/\//i.test(value) || !URL.canParse(value) || /[?#]/.test(value)) {
13
+ throw new Error("GSAP base URL must be an absolute HTTP(S) URL without a query or fragment");
14
+ }
15
+ const url = new URL(value);
16
+ if (url.username || url.password) {
17
+ throw new Error("GSAP base URL must not contain credentials");
18
+ }
19
+ if (url.protocol === "http:" && !isLoopbackHost(url.hostname)) {
20
+ throw new Error("GSAP base URL must use HTTPS unless it points at this machine");
21
+ }
22
+ return url.href.replace(/\/+$/, "");
23
+ }
24
+ /** A same-origin path to the host's bundled GSAP, which holds only GSAP_CDN_VERSION. */
25
+ export function normalizeGsapLocalRoot(root) {
26
+ const value = root.trim();
27
+ if (!/^\/(?![/\\])/.test(value) || /[?#\\]/.test(value)) {
28
+ throw new Error("GSAP local root must be a same-origin path such as /vendor/npm");
29
+ }
30
+ const origin = "http://local.invalid";
31
+ const url = new URL(value, origin);
32
+ const path = url.pathname.replace(/\/+$/, "");
33
+ if (url.origin !== origin || !path) {
34
+ throw new Error("GSAP local root must be a same-origin path such as /vendor/npm");
35
+ }
36
+ return path;
37
+ }
38
+ export function gsapCdnDist(gsapVersion, baseUrl) {
3
39
  const version = gsapVersion && /^\d+(\.\d+)*$/.test(gsapVersion) ? gsapVersion : GSAP_CDN_VERSION;
4
- return `https://cdn.jsdelivr.net/npm/gsap@${version}/dist/`;
40
+ if (baseUrl?.trim().startsWith("/")) {
41
+ const root = normalizeGsapLocalRoot(baseUrl);
42
+ return `${version === GSAP_CDN_VERSION ? root : GSAP_CDN_BASE_URL}/gsap@${version}/dist/`;
43
+ }
44
+ return `${normalizeGsapBaseUrl(baseUrl)}/gsap@${version}/dist/`;
5
45
  }
6
46
  /** MotionPathPlugin at the composition's own gsap version; a skew registers with a GSAP warning. */
7
- export function motionPathPluginUrl(gsapVersion) {
8
- return `${gsapCdnDist(gsapVersion)}MotionPathPlugin.min.js`;
47
+ export function motionPathPluginUrl(gsapVersion, baseUrl) {
48
+ return `${gsapCdnDist(gsapVersion, baseUrl)}MotionPathPlugin.min.js`;
9
49
  }