@hortonstudio/main 1.2.0 → 1.2.1
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/index.js +35 -26
- package/package.json +1 -1
package/index.js
CHANGED
@@ -1,48 +1,58 @@
|
|
1
|
-
// ver 1.1
|
1
|
+
// ver 1.2.1
|
2
2
|
|
3
3
|
const API_NAME = 'hsmain';
|
4
4
|
|
5
5
|
window[API_NAME] = window[API_NAME] || {};
|
6
6
|
window[API_NAME].loaded = false
|
7
7
|
|
8
|
+
// Dynamic module loader function (like Finsweet's approach)
|
9
|
+
const loadModule = async (moduleName) => {
|
10
|
+
const baseURL = new URL('./', import.meta.url).href;
|
11
|
+
|
12
|
+
switch (moduleName) {
|
13
|
+
case "data-hs-anim-text":
|
14
|
+
return import(new URL('./animations/text.js', import.meta.url).href);
|
15
|
+
case "data-hs-anim-hero":
|
16
|
+
return import(new URL('./animations/hero.js', import.meta.url).href);
|
17
|
+
case "data-hs-anim-transition":
|
18
|
+
return import(new URL('./animations/transition.js', import.meta.url).href);
|
19
|
+
case "data-hs-util-toc":
|
20
|
+
return import(new URL('./utils/toc.js', import.meta.url).href);
|
21
|
+
case "data-hs-util-progress":
|
22
|
+
return import(new URL('./utils/scroll-progress.js', import.meta.url).href);
|
23
|
+
case "data-hs-util-navbar":
|
24
|
+
return import(new URL('./utils/navbar.js', import.meta.url).href);
|
25
|
+
case "smooth-scroll":
|
26
|
+
return import(new URL('./autoInit/smooth-scroll.js', import.meta.url).href);
|
27
|
+
default:
|
28
|
+
throw new Error(`HortonStudio module "${moduleName}" is not supported.`);
|
29
|
+
}
|
30
|
+
};
|
31
|
+
|
8
32
|
const animationModules = {
|
9
|
-
"data-hs-anim-text":
|
10
|
-
"data-hs-anim-hero":
|
11
|
-
"data-hs-anim-transition":
|
33
|
+
"data-hs-anim-text": true,
|
34
|
+
"data-hs-anim-hero": true,
|
35
|
+
"data-hs-anim-transition": true
|
12
36
|
};
|
13
37
|
|
14
38
|
const utilityModules = {
|
15
|
-
"data-hs-util-toc":
|
16
|
-
"data-hs-util-progress":
|
17
|
-
"data-hs-util-navbar":
|
39
|
+
"data-hs-util-toc": true,
|
40
|
+
"data-hs-util-progress": true,
|
41
|
+
"data-hs-util-navbar": true
|
18
42
|
};
|
19
43
|
|
20
44
|
// Modules that auto-initialize
|
21
45
|
const autoInitModules = {
|
22
|
-
"smooth-scroll":
|
46
|
+
"smooth-scroll": true
|
23
47
|
};
|
24
48
|
|
25
49
|
// Store callbacks to run after Webflow.ready()
|
26
50
|
const postWebflowCallbacks = [];
|
27
51
|
|
28
|
-
const loadModule = (moduleName) => {
|
29
|
-
// Check manual modules first
|
30
|
-
let modulePath = animationModules[moduleName] || utilityModules[moduleName];
|
31
|
-
|
32
|
-
// Then check auto-init modules
|
33
|
-
if (!modulePath) {
|
34
|
-
modulePath = autoInitModules[moduleName];
|
35
|
-
}
|
36
|
-
|
37
|
-
if (!modulePath) {
|
38
|
-
throw new Error(`HortonStudio module "${moduleName}" is not supported.`);
|
39
|
-
}
|
40
|
-
return import(modulePath);
|
41
|
-
};
|
42
|
-
|
43
52
|
const findCurrentScriptTag = () => {
|
44
|
-
|
45
|
-
|
53
|
+
// Use import.meta.url like Finsweet does
|
54
|
+
const scripts = [...document.querySelectorAll(`script[data-hs-main][src="${import.meta.url}"]`)];
|
55
|
+
return scripts[0] || document.querySelector('script[data-hs-main]');
|
46
56
|
};
|
47
57
|
|
48
58
|
const processModules = async (scriptTag) => {
|
@@ -76,7 +86,6 @@ const processModules = async (scriptTag) => {
|
|
76
86
|
};
|
77
87
|
|
78
88
|
const refreshWebflow = () => {
|
79
|
-
|
80
89
|
setTimeout(() => {
|
81
90
|
if (window.Webflow && window.Webflow.ready) {
|
82
91
|
window.Webflow.ready();
|