@hortonstudio/main 1.2.2 → 1.2.3
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 +55 -7
- package/package.json +1 -1
package/index.js
CHANGED
@@ -1,13 +1,19 @@
|
|
1
|
-
// ver 1.2.
|
1
|
+
// ver 1.2.3
|
2
2
|
|
3
3
|
const API_NAME = 'hsmain';
|
4
4
|
|
5
|
+
console.log(`🟢 ${API_NAME} v1.2.3 initializing...`);
|
6
|
+
console.log('🔍 DOM state:', document.readyState);
|
7
|
+
console.log('🔍 Script URL:', import.meta.url);
|
8
|
+
|
5
9
|
window[API_NAME] = window[API_NAME] || {};
|
6
10
|
window[API_NAME].loaded = false
|
7
11
|
|
8
12
|
// Dynamic module loader function (like Finsweet's approach)
|
9
13
|
const loadModule = async (moduleName) => {
|
14
|
+
console.log(`📦 Loading module: ${moduleName}`);
|
10
15
|
const baseURL = new URL('./', import.meta.url).href;
|
16
|
+
console.log(`📂 Base URL: ${baseURL}`);
|
11
17
|
|
12
18
|
switch (moduleName) {
|
13
19
|
case "data-hs-anim-text":
|
@@ -25,6 +31,7 @@ const loadModule = async (moduleName) => {
|
|
25
31
|
case "smooth-scroll":
|
26
32
|
return import(new URL('./autoInit/smooth-scroll.js', import.meta.url).href);
|
27
33
|
default:
|
34
|
+
console.error(`❌ Unsupported module: ${moduleName}`);
|
28
35
|
throw new Error(`HortonStudio module "${moduleName}" is not supported.`);
|
29
36
|
}
|
30
37
|
|
@@ -71,21 +78,32 @@ const postWebflowCallbacks = [];
|
|
71
78
|
const findCurrentScriptTag = () => {
|
72
79
|
// Use import.meta.url like Finsweet does
|
73
80
|
const scripts = [...document.querySelectorAll(`script[data-hs-main][src="${import.meta.url}"]`)];
|
74
|
-
|
81
|
+
const fallbackScript = document.querySelector('script[data-hs-main]');
|
82
|
+
const found = scripts[0] || fallbackScript;
|
83
|
+
console.log(`🏷️ Script tag found:`, found);
|
84
|
+
console.log(`🏷️ Script attributes:`, found ? [...found.attributes].map(a => `${a.name}="${a.value}"`).join(' ') : 'none');
|
85
|
+
return found;
|
75
86
|
};
|
76
87
|
|
77
88
|
const processModules = async (scriptTag) => {
|
89
|
+
console.log(`⚙️ Processing modules with script tag:`, scriptTag);
|
78
90
|
const modulePromises = [];
|
79
91
|
|
80
92
|
// Load manual modules based on attributes
|
81
|
-
|
93
|
+
const manualModules = Object.keys({ ...animationModules, ...utilityModules });
|
94
|
+
console.log(`🔍 Checking for manual modules:`, manualModules);
|
95
|
+
|
96
|
+
for (const moduleName of manualModules) {
|
82
97
|
if (scriptTag && scriptTag.hasAttribute(moduleName)) {
|
98
|
+
console.log(`✅ Found attribute for: ${moduleName}`);
|
83
99
|
modulePromises.push(loadHsModule(moduleName));
|
84
100
|
}
|
85
101
|
}
|
86
102
|
|
87
103
|
// Load auto-init modules
|
88
|
-
|
104
|
+
const autoModules = Object.keys(autoInitModules);
|
105
|
+
console.log(`🔄 Auto-loading modules:`, autoModules);
|
106
|
+
for (const moduleName of autoModules) {
|
89
107
|
modulePromises.push(loadHsModule(moduleName));
|
90
108
|
}
|
91
109
|
|
@@ -98,38 +116,51 @@ const processModules = async (scriptTag) => {
|
|
98
116
|
}
|
99
117
|
|
100
118
|
// Wait for ALL modules to finish loading
|
119
|
+
console.log(`⏳ Waiting for ${modulePromises.length} modules to load...`);
|
101
120
|
await Promise.all(modulePromises);
|
121
|
+
console.log(`✅ All modules loaded successfully`);
|
102
122
|
|
103
123
|
// Always refresh Webflow after all modules are loaded
|
104
124
|
refreshWebflow();
|
105
125
|
};
|
106
126
|
|
107
127
|
const refreshWebflow = () => {
|
128
|
+
console.log(`🔄 Refreshing Webflow...`);
|
108
129
|
setTimeout(() => {
|
109
130
|
if (window.Webflow && window.Webflow.ready) {
|
131
|
+
console.log(`🌐 Calling Webflow.ready()`);
|
110
132
|
window.Webflow.ready();
|
133
|
+
} else {
|
134
|
+
console.log(`⚠️ Webflow not detected`);
|
111
135
|
}
|
112
136
|
|
113
137
|
// Run all registered post-Webflow callbacks (even without Webflow)
|
114
138
|
setTimeout(() => {
|
115
|
-
|
139
|
+
console.log(`🔄 Running ${postWebflowCallbacks.length} post-Webflow callbacks`);
|
140
|
+
postWebflowCallbacks.forEach((callback, index) => {
|
116
141
|
try {
|
142
|
+
console.log(`📞 Executing callback ${index + 1}/${postWebflowCallbacks.length}`);
|
117
143
|
callback();
|
118
144
|
} catch (error) {
|
145
|
+
console.error(`❌ Callback ${index + 1} failed:`, error);
|
119
146
|
}
|
120
147
|
});
|
121
148
|
window[API_NAME].loaded = true;
|
122
|
-
|
123
|
-
|
149
|
+
console.log(`🎉 ${API_NAME} fully loaded and ready!`);
|
150
|
+
}, 100);
|
151
|
+
}, 100);
|
124
152
|
};
|
125
153
|
|
126
154
|
const loadHsModule = async (moduleName) => {
|
155
|
+
console.log(`🔄 loadHsModule called for: ${moduleName}`);
|
127
156
|
const apiInstance = window[API_NAME];
|
128
157
|
|
129
158
|
if (apiInstance.process.has(moduleName)) {
|
159
|
+
console.log(`⚠️ Module ${moduleName} already processing, returning existing promise`);
|
130
160
|
return apiInstance.modules[moduleName]?.loading;
|
131
161
|
}
|
132
162
|
|
163
|
+
console.log(`➕ Adding ${moduleName} to process set`);
|
133
164
|
apiInstance.process.add(moduleName);
|
134
165
|
|
135
166
|
const moduleObj = apiInstance.modules[moduleName] || {};
|
@@ -141,9 +172,14 @@ const loadHsModule = async (moduleName) => {
|
|
141
172
|
});
|
142
173
|
|
143
174
|
try {
|
175
|
+
console.log(`📦 Importing ${moduleName}...`);
|
144
176
|
const { init, version } = await loadModule(moduleName);
|
177
|
+
console.log(`✅ ${moduleName} imported, version: ${version}`);
|
178
|
+
|
179
|
+
console.log(`🔧 Initializing ${moduleName}...`);
|
145
180
|
const initResult = await init();
|
146
181
|
const { result, destroy } = initResult || {};
|
182
|
+
console.log(`✅ ${moduleName} initialized:`, result);
|
147
183
|
|
148
184
|
moduleObj.version = version;
|
149
185
|
|
@@ -165,6 +201,7 @@ const loadHsModule = async (moduleName) => {
|
|
165
201
|
return result;
|
166
202
|
|
167
203
|
} catch (error) {
|
204
|
+
console.error(`❌ Failed to load ${moduleName}:`, error);
|
168
205
|
moduleObj.reject?.(error);
|
169
206
|
apiInstance.process.delete(moduleName);
|
170
207
|
throw error;
|
@@ -172,16 +209,25 @@ const loadHsModule = async (moduleName) => {
|
|
172
209
|
};
|
173
210
|
|
174
211
|
const initializeAPI = () => {
|
212
|
+
console.log(`🚀 Initializing ${API_NAME} API...`);
|
213
|
+
|
175
214
|
// Handle early API calls (like Finsweet)
|
176
215
|
const existingAPI = window[API_NAME];
|
216
|
+
console.log(`🔍 Existing API:`, existingAPI);
|
217
|
+
|
177
218
|
if (existingAPI && !Array.isArray(existingAPI)) {
|
219
|
+
console.log(`⚡ API already initialized, processing...`);
|
178
220
|
processAPI();
|
179
221
|
return;
|
180
222
|
}
|
181
223
|
|
182
224
|
const existingRequests = Array.isArray(existingAPI) ? existingAPI : [];
|
225
|
+
console.log(`📝 Existing queued requests:`, existingRequests);
|
226
|
+
|
183
227
|
const scripts = [...document.querySelectorAll(`script[data-hs-main][src="${import.meta.url}"]`)];
|
184
228
|
const scriptTag = scripts[0] || document.querySelector('script[data-hs-main]');
|
229
|
+
console.log(`📄 Found ${scripts.length} script tags with exact src match`);
|
230
|
+
console.log(`🏷️ Using script tag:`, scriptTag);
|
185
231
|
|
186
232
|
// Handle rich text blocks
|
187
233
|
const richTextBlocks = document.querySelectorAll('.w-richtext');
|
@@ -307,7 +353,9 @@ const processAPI = () => {
|
|
307
353
|
};
|
308
354
|
|
309
355
|
if (document.readyState === 'loading') {
|
356
|
+
console.log(`⏳ DOM still loading, waiting for DOMContentLoaded...`);
|
310
357
|
document.addEventListener('DOMContentLoaded', initializeAPI);
|
311
358
|
} else {
|
359
|
+
console.log(`✅ DOM ready, initializing immediately`);
|
312
360
|
initializeAPI();
|
313
361
|
}
|