@hortonstudio/main 1.2.2 → 1.2.4
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 +66 -9
- 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,56 @@ 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
|
|
158
|
+
if (!apiInstance || !apiInstance.process) {
|
159
|
+
console.error(`❌ API not initialized properly:`, apiInstance);
|
160
|
+
throw new Error(`${API_NAME} API not initialized`);
|
161
|
+
}
|
162
|
+
|
129
163
|
if (apiInstance.process.has(moduleName)) {
|
164
|
+
console.log(`⚠️ Module ${moduleName} already processing, returning existing promise`);
|
130
165
|
return apiInstance.modules[moduleName]?.loading;
|
131
166
|
}
|
132
167
|
|
168
|
+
console.log(`➕ Adding ${moduleName} to process set`);
|
133
169
|
apiInstance.process.add(moduleName);
|
134
170
|
|
135
171
|
const moduleObj = apiInstance.modules[moduleName] || {};
|
@@ -141,9 +177,14 @@ const loadHsModule = async (moduleName) => {
|
|
141
177
|
});
|
142
178
|
|
143
179
|
try {
|
180
|
+
console.log(`📦 Importing ${moduleName}...`);
|
144
181
|
const { init, version } = await loadModule(moduleName);
|
182
|
+
console.log(`✅ ${moduleName} imported, version: ${version}`);
|
183
|
+
|
184
|
+
console.log(`🔧 Initializing ${moduleName}...`);
|
145
185
|
const initResult = await init();
|
146
186
|
const { result, destroy } = initResult || {};
|
187
|
+
console.log(`✅ ${moduleName} initialized:`, result);
|
147
188
|
|
148
189
|
moduleObj.version = version;
|
149
190
|
|
@@ -165,6 +206,7 @@ const loadHsModule = async (moduleName) => {
|
|
165
206
|
return result;
|
166
207
|
|
167
208
|
} catch (error) {
|
209
|
+
console.error(`❌ Failed to load ${moduleName}:`, error);
|
168
210
|
moduleObj.reject?.(error);
|
169
211
|
apiInstance.process.delete(moduleName);
|
170
212
|
throw error;
|
@@ -172,16 +214,25 @@ const loadHsModule = async (moduleName) => {
|
|
172
214
|
};
|
173
215
|
|
174
216
|
const initializeAPI = () => {
|
217
|
+
console.log(`🚀 Initializing ${API_NAME} API...`);
|
218
|
+
|
175
219
|
// Handle early API calls (like Finsweet)
|
176
220
|
const existingAPI = window[API_NAME];
|
177
|
-
|
221
|
+
console.log(`🔍 Existing API:`, existingAPI);
|
222
|
+
|
223
|
+
if (existingAPI && !Array.isArray(existingAPI) && existingAPI.process) {
|
224
|
+
console.log(`⚡ API already initialized, processing...`);
|
178
225
|
processAPI();
|
179
226
|
return;
|
180
227
|
}
|
181
228
|
|
182
229
|
const existingRequests = Array.isArray(existingAPI) ? existingAPI : [];
|
230
|
+
console.log(`📝 Existing queued requests:`, existingRequests);
|
231
|
+
|
183
232
|
const scripts = [...document.querySelectorAll(`script[data-hs-main][src="${import.meta.url}"]`)];
|
184
233
|
const scriptTag = scripts[0] || document.querySelector('script[data-hs-main]');
|
234
|
+
console.log(`📄 Found ${scripts.length} script tags with exact src match`);
|
235
|
+
console.log(`🏷️ Using script tag:`, scriptTag);
|
185
236
|
|
186
237
|
// Handle rich text blocks
|
187
238
|
const richTextBlocks = document.querySelectorAll('.w-richtext');
|
@@ -291,7 +342,11 @@ const processAPI = () => {
|
|
291
342
|
|
292
343
|
// Always load auto-init modules
|
293
344
|
for (const moduleName of Object.keys(autoInitModules)) {
|
294
|
-
|
345
|
+
try {
|
346
|
+
loadHsModule(moduleName);
|
347
|
+
} catch (error) {
|
348
|
+
console.error(`❌ Failed to load auto-init module ${moduleName}:`, error);
|
349
|
+
}
|
295
350
|
}
|
296
351
|
|
297
352
|
// Hide .transition elements if transition module is not loaded
|
@@ -307,7 +362,9 @@ const processAPI = () => {
|
|
307
362
|
};
|
308
363
|
|
309
364
|
if (document.readyState === 'loading') {
|
365
|
+
console.log(`⏳ DOM still loading, waiting for DOMContentLoaded...`);
|
310
366
|
document.addEventListener('DOMContentLoaded', initializeAPI);
|
311
367
|
} else {
|
368
|
+
console.log(`✅ DOM ready, initializing immediately`);
|
312
369
|
initializeAPI();
|
313
370
|
}
|