slicejs-web-framework 2.2.12 → 2.2.13

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.
@@ -249,9 +249,19 @@ export default class Controller {
249
249
  const processedDeps = new Set();
250
250
  for (const [componentName, componentData] of Object.entries(components)) {
251
251
  if (componentData.externalDependencies) {
252
- for (const [depName, depContent] of Object.entries(componentData.externalDependencies)) {
253
- if (!processedDeps.has(depName)) {
252
+ for (const [depName, depEntry] of Object.entries(componentData.externalDependencies)) {
253
+ const depKey = depName || '';
254
+ if (!processedDeps.has(depKey)) {
254
255
  try {
256
+ const depContent = typeof depEntry === 'string' ? depEntry : depEntry.content;
257
+ const bindings = typeof depEntry === 'string' ? [] : (depEntry.bindings || []);
258
+
259
+ const fileBaseName = depKey
260
+ ? depKey.split('/').pop().replace(/\.[^.]+$/, '')
261
+ : '';
262
+ const dataName = fileBaseName ? `${fileBaseName}Data` : '';
263
+ const exportPrefix = dataName ? `window.${dataName} = ` : '';
264
+
255
265
  // Process ES6 exports to make the code evaluable
256
266
  let processedContent = depContent
257
267
  // Convert named exports: export const varName = ... → window.varName = ...
@@ -259,6 +269,8 @@ export default class Controller {
259
269
  .replace(/export\s+let\s+(\w+)\s*=\s*/g, 'window.$1 = ')
260
270
  .replace(/export\s+function\s+(\w+)/g, 'window.$1 = function')
261
271
  .replace(/export\s+default\s+/g, 'window.defaultExport = ')
272
+ // Promote default export to <file>Data for data modules
273
+ .replace(/window\.defaultExport\s*=\s*/g, exportPrefix || 'window.defaultExport = ')
262
274
  // Handle export { var1, var2 } statements
263
275
  .replace(/export\s*{\s*([^}]+)\s*}/g, (match, exportsStr) => {
264
276
  const exports = exportsStr.split(',').map(exp => exp.trim().split(' as ')[0].trim());
@@ -271,11 +283,42 @@ export default class Controller {
271
283
  new Function('slice', 'customElements', 'window', 'document', processedContent)
272
284
  (window.slice, window.customElements, window, window.document);
273
285
 
274
- processedDeps.add(depName);
286
+ // Apply import bindings to map local identifiers to globals
287
+ for (const binding of bindings) {
288
+ if (!binding?.localName) continue;
289
+
290
+ if (binding.type === 'default') {
291
+ if (!window[binding.localName]) {
292
+ const fallbackValue = dataName && window[dataName] !== undefined
293
+ ? window[dataName]
294
+ : window.defaultExport;
295
+ if (fallbackValue !== undefined) {
296
+ window[binding.localName] = fallbackValue;
297
+ }
298
+ }
299
+ }
300
+
301
+ if (binding.type === 'named') {
302
+ if (!window[binding.localName] && window[binding.importedName] !== undefined) {
303
+ window[binding.localName] = window[binding.importedName];
304
+ }
305
+ }
306
+
307
+ if (binding.type === 'namespace' && !window[binding.localName]) {
308
+ const namespace = {};
309
+ Object.keys(window).forEach((key) => {
310
+ namespace[key] = window[key];
311
+ });
312
+ window[binding.localName] = namespace;
313
+ }
314
+ }
315
+
316
+ processedDeps.add(depKey);
275
317
  console.log(`📄 External dependency loaded: ${depName}`);
276
318
  } catch (depError) {
277
319
  console.warn(`⚠️ Failed to load external dependency ${depName}:`, depError);
278
- console.warn('Original content preview:', depContent.substring(0, 200));
320
+ const preview = typeof depEntry === 'string' ? depEntry : depEntry.content;
321
+ console.warn('Original content preview:', preview.substring(0, 200));
279
322
  }
280
323
  }
281
324
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "slicejs-web-framework",
3
- "version": "2.2.12",
3
+ "version": "2.2.13",
4
4
  "description": "",
5
5
  "engines": {
6
6
  "node": ">=20"