@hortonstudio/main 1.2.7 → 1.2.8

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.
Files changed (2) hide show
  1. package/index.js +37 -0
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -148,6 +148,9 @@ const initializeHsMain = () => {
148
148
  }
149
149
  };
150
150
 
151
+ // Store callbacks to run after initialization
152
+ const postWebflowCallbacks = [];
153
+
151
154
  // Initialize API
152
155
  window[API_NAME] = {
153
156
  scripts,
@@ -173,6 +176,28 @@ const initializeHsMain = () => {
173
176
  this.modules[moduleName]?.destroy?.();
174
177
  }
175
178
  },
179
+
180
+ // API function for scripts to register post-initialization callbacks
181
+ afterReady(callback) {
182
+ if (typeof callback === 'function') {
183
+ if (this.loaded) {
184
+ callback();
185
+ } else {
186
+ postWebflowCallbacks.push(callback);
187
+ }
188
+ }
189
+ },
190
+
191
+ // Legacy alias for Webflow compatibility
192
+ afterWebflowReady(callback) {
193
+ if (typeof callback === 'function') {
194
+ if (this.loaded) {
195
+ callback();
196
+ } else {
197
+ postWebflowCallbacks.push(callback);
198
+ }
199
+ }
200
+ },
176
201
 
177
202
  // Status method
178
203
  status(moduleName) {
@@ -275,6 +300,18 @@ const initializeHsMain = () => {
275
300
 
276
301
  // Mark as loaded
277
302
  window[API_NAME].loaded = true;
303
+
304
+ // Run all registered post-Webflow callbacks
305
+ console.log(`🔄 Running ${postWebflowCallbacks.length} post-Webflow callbacks`);
306
+ postWebflowCallbacks.forEach((callback, index) => {
307
+ try {
308
+ console.log(`📞 Executing callback ${index + 1}/${postWebflowCallbacks.length}`);
309
+ callback();
310
+ } catch (error) {
311
+ console.error(`❌ Callback ${index + 1} failed:`, error);
312
+ }
313
+ });
314
+
278
315
  console.log(`🎉 ${API_NAME} fully loaded and ready!`);
279
316
  };
280
317
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hortonstudio/main",
3
- "version": "1.2.7",
3
+ "version": "1.2.8",
4
4
  "main": "index.js",
5
5
  "type": "module",
6
6
  "scripts": {