@hortonstudio/main 1.2.7 → 1.2.9
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 +37 -37
- package/package.json +1 -1
package/index.js
CHANGED
@@ -1,16 +1,11 @@
|
|
1
|
-
// ver 1.2.
|
1
|
+
// ver 1.2.9
|
2
2
|
|
3
3
|
const API_NAME = 'hsmain';
|
4
4
|
|
5
|
-
console.log(`🟢 ${API_NAME} v1.2.6 initializing...`);
|
6
|
-
console.log('🔍 DOM state:', document.readyState);
|
7
|
-
console.log('🔍 Script URL:', import.meta.url);
|
8
|
-
|
9
5
|
// Main initialization function
|
10
6
|
const initializeHsMain = () => {
|
11
7
|
// Handle existing API
|
12
8
|
if (window[API_NAME] && !Array.isArray(window[API_NAME]) && window[API_NAME].loaded) {
|
13
|
-
console.log('⚠️ API already loaded, skipping initialization');
|
14
9
|
return;
|
15
10
|
}
|
16
11
|
|
@@ -39,8 +34,6 @@ const initializeHsMain = () => {
|
|
39
34
|
|
40
35
|
// Dynamic module loader (like Finsweet)
|
41
36
|
const loadModule = async (moduleName) => {
|
42
|
-
console.log(`📦 Loading module: ${moduleName}`);
|
43
|
-
|
44
37
|
switch (moduleName) {
|
45
38
|
case "data-hs-anim-text":
|
46
39
|
return import(new URL('./animations/text.js', import.meta.url).href);
|
@@ -57,7 +50,6 @@ const initializeHsMain = () => {
|
|
57
50
|
case "smooth-scroll":
|
58
51
|
return import(new URL('./autoInit/smooth-scroll.js', import.meta.url).href);
|
59
52
|
default:
|
60
|
-
console.error(`❌ Unsupported module: ${moduleName}`);
|
61
53
|
throw new Error(`${API_NAME} module "${moduleName}" is not supported.`);
|
62
54
|
}
|
63
55
|
};
|
@@ -83,22 +75,17 @@ const initializeHsMain = () => {
|
|
83
75
|
|
84
76
|
// Find script tags (Finsweet approach)
|
85
77
|
const scripts = [...document.querySelectorAll(`script[type="module"][src="${import.meta.url}"]`)];
|
86
|
-
console.log(`📄 Found ${scripts.length} matching script tags`);
|
87
78
|
|
88
79
|
// Module loading function
|
89
80
|
const loadHsModule = async (moduleName) => {
|
90
|
-
console.log(`🔄 loadHsModule called for: ${moduleName}`);
|
91
|
-
|
92
81
|
const apiInstance = window[API_NAME];
|
93
82
|
|
94
83
|
// Check if already processing
|
95
84
|
if (apiInstance.process.has(moduleName)) {
|
96
|
-
console.log(`⚠️ Module ${moduleName} already processing`);
|
97
85
|
return apiInstance.modules[moduleName]?.loading;
|
98
86
|
}
|
99
87
|
|
100
88
|
// Add to processing set
|
101
|
-
console.log(`➕ Adding ${moduleName} to process set`);
|
102
89
|
apiInstance.process.add(moduleName);
|
103
90
|
|
104
91
|
// Create module object
|
@@ -112,14 +99,9 @@ const initializeHsMain = () => {
|
|
112
99
|
});
|
113
100
|
|
114
101
|
try {
|
115
|
-
console.log(`📦 Importing ${moduleName}...`);
|
116
102
|
const { init, version } = await loadModule(moduleName);
|
117
|
-
console.log(`✅ ${moduleName} imported, version: ${version}`);
|
118
|
-
|
119
|
-
console.log(`🔧 Initializing ${moduleName}...`);
|
120
103
|
const initResult = await init();
|
121
104
|
const { result, destroy } = initResult || {};
|
122
|
-
console.log(`✅ ${moduleName} initialized:`, result);
|
123
105
|
|
124
106
|
moduleObj.version = version;
|
125
107
|
|
@@ -141,13 +123,15 @@ const initializeHsMain = () => {
|
|
141
123
|
return result;
|
142
124
|
|
143
125
|
} catch (error) {
|
144
|
-
console.error(`❌ Failed to load ${moduleName}:`, error);
|
145
126
|
moduleObj.reject?.(error);
|
146
127
|
apiInstance.process.delete(moduleName);
|
147
128
|
throw error;
|
148
129
|
}
|
149
130
|
};
|
150
131
|
|
132
|
+
// Store callbacks to run after initialization
|
133
|
+
const postWebflowCallbacks = [];
|
134
|
+
|
151
135
|
// Initialize API
|
152
136
|
window[API_NAME] = {
|
153
137
|
scripts,
|
@@ -173,6 +157,28 @@ const initializeHsMain = () => {
|
|
173
157
|
this.modules[moduleName]?.destroy?.();
|
174
158
|
}
|
175
159
|
},
|
160
|
+
|
161
|
+
// API function for scripts to register post-initialization callbacks
|
162
|
+
afterReady(callback) {
|
163
|
+
if (typeof callback === 'function') {
|
164
|
+
if (this.loaded) {
|
165
|
+
callback();
|
166
|
+
} else {
|
167
|
+
postWebflowCallbacks.push(callback);
|
168
|
+
}
|
169
|
+
}
|
170
|
+
},
|
171
|
+
|
172
|
+
// Legacy alias for Webflow compatibility
|
173
|
+
afterWebflowReady(callback) {
|
174
|
+
if (typeof callback === 'function') {
|
175
|
+
if (this.loaded) {
|
176
|
+
callback();
|
177
|
+
} else {
|
178
|
+
postWebflowCallbacks.push(callback);
|
179
|
+
}
|
180
|
+
}
|
181
|
+
},
|
176
182
|
|
177
183
|
// Status method
|
178
184
|
status(moduleName) {
|
@@ -194,19 +200,13 @@ const initializeHsMain = () => {
|
|
194
200
|
|
195
201
|
// Process modules from script tags
|
196
202
|
const processScriptModules = () => {
|
197
|
-
console.log(`⚙️ Processing ${scripts.length} script tags`);
|
198
|
-
|
199
203
|
for (const script of scripts) {
|
200
|
-
console.log(`🏷️ Processing script:`, script.src);
|
201
|
-
|
202
204
|
// Check for auto mode
|
203
205
|
const autoMode = script.getAttribute('data-hs-auto') === 'true';
|
204
|
-
console.log(`🔍 Auto mode: ${autoMode}`);
|
205
206
|
|
206
207
|
// Load modules based on script attributes
|
207
208
|
for (const moduleName of Object.keys(allModules)) {
|
208
209
|
if (script.hasAttribute(moduleName)) {
|
209
|
-
console.log(`✅ Found attribute for: ${moduleName}`);
|
210
210
|
loadHsModule(moduleName);
|
211
211
|
}
|
212
212
|
}
|
@@ -214,7 +214,6 @@ const initializeHsMain = () => {
|
|
214
214
|
// Auto-discovery mode
|
215
215
|
if (autoMode) {
|
216
216
|
waitDOMReady().then(() => {
|
217
|
-
console.log(`🔍 Starting auto-discovery...`);
|
218
217
|
const foundModules = new Set();
|
219
218
|
const allElements = document.querySelectorAll('*');
|
220
219
|
|
@@ -228,7 +227,6 @@ const initializeHsMain = () => {
|
|
228
227
|
}
|
229
228
|
}
|
230
229
|
|
231
|
-
console.log(`🔍 Auto-discovered modules:`, [...foundModules]);
|
232
230
|
for (const moduleName of foundModules) {
|
233
231
|
loadHsModule(moduleName);
|
234
232
|
}
|
@@ -237,7 +235,6 @@ const initializeHsMain = () => {
|
|
237
235
|
}
|
238
236
|
|
239
237
|
// Always load auto-init modules
|
240
|
-
console.log(`🔄 Loading auto-init modules:`, Object.keys(autoInitModules));
|
241
238
|
for (const moduleName of Object.keys(autoInitModules)) {
|
242
239
|
loadHsModule(moduleName);
|
243
240
|
}
|
@@ -263,28 +260,31 @@ const initializeHsMain = () => {
|
|
263
260
|
|
264
261
|
// Main initialization
|
265
262
|
const initializeMain = async () => {
|
266
|
-
console.log(`🚀 Starting main initialization...`);
|
267
|
-
|
268
263
|
// Process script modules
|
269
264
|
processScriptModules();
|
270
265
|
|
271
266
|
// Wait for Webflow
|
272
|
-
console.log(`⏳ Waiting for Webflow...`);
|
273
267
|
await waitWebflowReady();
|
274
|
-
console.log(`✅ Webflow ready`);
|
275
268
|
|
276
269
|
// Mark as loaded
|
277
270
|
window[API_NAME].loaded = true;
|
278
|
-
|
271
|
+
|
272
|
+
// Run all registered post-Webflow callbacks
|
273
|
+
postWebflowCallbacks.forEach((callback) => {
|
274
|
+
try {
|
275
|
+
callback();
|
276
|
+
} catch (error) {
|
277
|
+
// Silent fail for callbacks
|
278
|
+
}
|
279
|
+
});
|
279
280
|
};
|
280
281
|
|
281
282
|
// Process any early requests
|
282
|
-
console.log(`📝 Processing ${existingRequests.length} early requests`);
|
283
283
|
window[API_NAME].push(...existingRequests);
|
284
284
|
|
285
285
|
// Start initialization
|
286
|
-
initializeMain().catch(
|
287
|
-
|
286
|
+
initializeMain().catch(() => {
|
287
|
+
// Silent fail for initialization
|
288
288
|
});
|
289
289
|
};
|
290
290
|
|