@hortonstudio/main 1.2.3 → 1.2.5

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 +33 -6
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1,8 +1,8 @@
1
- // ver 1.2.3
1
+ // ver 1.2.4
2
2
 
3
3
  const API_NAME = 'hsmain';
4
4
 
5
- console.log(`🟢 ${API_NAME} v1.2.3 initializing...`);
5
+ console.log(`🟢 ${API_NAME} v1.2.4 initializing...`);
6
6
  console.log('🔍 DOM state:', document.readyState);
7
7
  console.log('🔍 Script URL:', import.meta.url);
8
8
 
@@ -155,6 +155,11 @@ const loadHsModule = async (moduleName) => {
155
155
  console.log(`🔄 loadHsModule called for: ${moduleName}`);
156
156
  const apiInstance = window[API_NAME];
157
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
+
158
163
  if (apiInstance.process.has(moduleName)) {
159
164
  console.log(`⚠️ Module ${moduleName} already processing, returning existing promise`);
160
165
  return apiInstance.modules[moduleName]?.loading;
@@ -215,7 +220,7 @@ const initializeAPI = () => {
215
220
  const existingAPI = window[API_NAME];
216
221
  console.log(`🔍 Existing API:`, existingAPI);
217
222
 
218
- if (existingAPI && !Array.isArray(existingAPI)) {
223
+ if (existingAPI && !Array.isArray(existingAPI) && existingAPI.process) {
219
224
  console.log(`⚡ API already initialized, processing...`);
220
225
  processAPI();
221
226
  return;
@@ -224,10 +229,28 @@ const initializeAPI = () => {
224
229
  const existingRequests = Array.isArray(existingAPI) ? existingAPI : [];
225
230
  console.log(`📝 Existing queued requests:`, existingRequests);
226
231
 
227
- const scripts = [...document.querySelectorAll(`script[data-hs-main][src="${import.meta.url}"]`)];
228
- const scriptTag = scripts[0] || document.querySelector('script[data-hs-main]');
232
+ // Try multiple approaches to find the script tag
233
+ let scripts = [...document.querySelectorAll(`script[data-hs-main][src="${import.meta.url}"]`)];
229
234
  console.log(`📄 Found ${scripts.length} script tags with exact src match`);
235
+
236
+ // Fallback: find any script with data-hs-main
237
+ if (scripts.length === 0) {
238
+ scripts = [...document.querySelectorAll('script[data-hs-main]')];
239
+ console.log(`📄 Fallback: Found ${scripts.length} script tags with data-hs-main`);
240
+ }
241
+
242
+ // Fallback: find script with similar src (same package name)
243
+ if (scripts.length === 0) {
244
+ scripts = [...document.querySelectorAll('script[src*="@hortonstudio/main"]')];
245
+ console.log(`📄 Fallback: Found ${scripts.length} script tags with @hortonstudio/main`);
246
+ }
247
+
248
+ const scriptTag = scripts[0];
230
249
  console.log(`🏷️ Using script tag:`, scriptTag);
250
+ if (scriptTag) {
251
+ console.log(`🏷️ Script src:`, scriptTag.src);
252
+ console.log(`🏷️ Script attributes:`, [...scriptTag.attributes].map(a => `${a.name}="${a.value}"`).join(' '));
253
+ }
231
254
 
232
255
  // Handle rich text blocks
233
256
  const richTextBlocks = document.querySelectorAll('.w-richtext');
@@ -337,7 +360,11 @@ const processAPI = () => {
337
360
 
338
361
  // Always load auto-init modules
339
362
  for (const moduleName of Object.keys(autoInitModules)) {
340
- loadHsModule(moduleName);
363
+ try {
364
+ loadHsModule(moduleName);
365
+ } catch (error) {
366
+ console.error(`❌ Failed to load auto-init module ${moduleName}:`, error);
367
+ }
341
368
  }
342
369
 
343
370
  // Hide .transition elements if transition module is not loaded
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hortonstudio/main",
3
- "version": "1.2.3",
3
+ "version": "1.2.5",
4
4
  "main": "index.js",
5
5
  "type": "module",
6
6
  "scripts": {