wgsl-play 0.0.33 → 0.0.35

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/dist/WgslPlay.js CHANGED
@@ -151,9 +151,10 @@ var WgslPlay = class extends HTMLElement {
151
151
  }
152
152
  /** Set sources from a full project with weslSrc. */
153
153
  setProjectSources(weslSrc, rootModuleName) {
154
- const entries = Object.entries(weslSrc).map(([k, v]) => [toModulePath(k), v]);
155
- this._weslSrc = Object.fromEntries(entries);
156
- this._rootModuleName = rootModuleName ? toModulePath(rootModuleName) : "package::main";
154
+ const pkg = this._linkOptions.packageName || "package";
155
+ const root = rootModuleName ?? "main";
156
+ this._weslSrc = toModulePaths(weslSrc, pkg);
157
+ this._rootModuleName = fileToModulePath(root, pkg, false);
157
158
  this._fromFullProject = true;
158
159
  this.rebuildPipeline();
159
160
  }
@@ -285,13 +286,10 @@ var WgslPlay = class extends HTMLElement {
285
286
  const source = el.source ?? el.textContent ?? "";
286
287
  return { [this._rootModuleName]: source };
287
288
  };
288
- const conditions = el.conditions;
289
- const rootModuleName = el.rootModuleName;
290
- const libs = el.libs;
291
- const weslSrc = getSources();
292
- const entries = Object.entries(weslSrc).map(([k, v]) => [toModulePath(k), v]);
293
- this._weslSrc = Object.fromEntries(entries);
294
- this._rootModuleName = rootModuleName ? toModulePath(rootModuleName) : "package::main";
289
+ const { conditions, rootModuleName, libs } = el;
290
+ const root = rootModuleName ?? "main";
291
+ this._weslSrc = getSources();
292
+ this._rootModuleName = fileToModulePath(root, "package", false);
295
293
  if (conditions) this._linkOptions = {
296
294
  ...this._linkOptions,
297
295
  conditions
@@ -306,7 +304,8 @@ var WgslPlay = class extends HTMLElement {
306
304
  this.project = {
307
305
  weslSrc: detail?.sources ?? fallback,
308
306
  rootModuleName: detail?.rootModuleName,
309
- conditions: detail?.conditions
307
+ conditions: detail?.conditions,
308
+ libs: detail?.libs
310
309
  };
311
310
  };
312
311
  el.addEventListener("change", this._sourceListener);
@@ -444,9 +443,11 @@ function upgradeProperty(el, prop) {
444
443
  el[prop] = value;
445
444
  }
446
445
  }
447
- /** Convert file path to module path (e.g., "effects/main.wesl" -> "package::effects::main"). */
448
- function toModulePath(filePath) {
449
- return fileToModulePath(filePath, "package", false);
446
+ /** Normalize all keys in a weslSrc record to module paths. */
447
+ function toModulePaths(weslSrc, pkg) {
448
+ const result = {};
449
+ for (const [key, value] of Object.entries(weslSrc)) result[fileToModulePath(key, pkg, false)] = value;
450
+ return result;
450
451
  }
451
452
 
452
453
  //#endregion
package/dist/wgsl-play.js CHANGED
@@ -5836,9 +5836,10 @@ var WgslPlay = class extends HTMLElement {
5836
5836
  }
5837
5837
  /** Set sources from a full project with weslSrc. */
5838
5838
  setProjectSources(weslSrc, rootModuleName) {
5839
- const entries = Object.entries(weslSrc).map(([k, v]) => [toModulePath(k), v]);
5840
- this._weslSrc = Object.fromEntries(entries);
5841
- this._rootModuleName = rootModuleName ? toModulePath(rootModuleName) : "package::main";
5839
+ const pkg = this._linkOptions.packageName || "package";
5840
+ const root = rootModuleName ?? "main";
5841
+ this._weslSrc = toModulePaths(weslSrc, pkg);
5842
+ this._rootModuleName = fileToModulePath(root, pkg, false);
5842
5843
  this._fromFullProject = true;
5843
5844
  this.rebuildPipeline();
5844
5845
  }
@@ -5970,13 +5971,10 @@ var WgslPlay = class extends HTMLElement {
5970
5971
  const source = el.source ?? el.textContent ?? "";
5971
5972
  return { [this._rootModuleName]: source };
5972
5973
  };
5973
- const conditions = el.conditions;
5974
- const rootModuleName = el.rootModuleName;
5975
- const libs = el.libs;
5976
- const weslSrc = getSources();
5977
- const entries = Object.entries(weslSrc).map(([k, v]) => [toModulePath(k), v]);
5978
- this._weslSrc = Object.fromEntries(entries);
5979
- this._rootModuleName = rootModuleName ? toModulePath(rootModuleName) : "package::main";
5974
+ const { conditions, rootModuleName, libs } = el;
5975
+ const root = rootModuleName ?? "main";
5976
+ this._weslSrc = getSources();
5977
+ this._rootModuleName = fileToModulePath(root, "package", false);
5980
5978
  if (conditions) this._linkOptions = {
5981
5979
  ...this._linkOptions,
5982
5980
  conditions
@@ -5991,7 +5989,8 @@ var WgslPlay = class extends HTMLElement {
5991
5989
  this.project = {
5992
5990
  weslSrc: detail?.sources ?? fallback,
5993
5991
  rootModuleName: detail?.rootModuleName,
5994
- conditions: detail?.conditions
5992
+ conditions: detail?.conditions,
5993
+ libs: detail?.libs
5995
5994
  };
5996
5995
  };
5997
5996
  el.addEventListener("change", this._sourceListener);
@@ -6129,9 +6128,11 @@ function upgradeProperty(el, prop) {
6129
6128
  el[prop] = value;
6130
6129
  }
6131
6130
  }
6132
- /** Convert file path to module path (e.g., "effects/main.wesl" -> "package::effects::main"). */
6133
- function toModulePath(filePath) {
6134
- return fileToModulePath(filePath, "package", false);
6131
+ /** Normalize all keys in a weslSrc record to module paths. */
6132
+ function toModulePaths(weslSrc, pkg) {
6133
+ const result = {};
6134
+ for (const [key, value] of Object.entries(weslSrc)) result[fileToModulePath(key, pkg, false)] = value;
6135
+ return result;
6135
6136
  }
6136
6137
 
6137
6138
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wgsl-play",
3
- "version": "0.0.33",
3
+ "version": "0.0.35",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist",
package/src/WgslPlay.ts CHANGED
@@ -241,15 +241,10 @@ export class WgslPlay extends HTMLElement {
241
241
  weslSrc: Record<string, string>,
242
242
  rootModuleName?: string,
243
243
  ): void {
244
- // Convert file paths to module paths if needed (for ?link imports)
245
- const entries = Object.entries(weslSrc).map(([k, v]) => [
246
- toModulePath(k),
247
- v,
248
- ]);
249
- this._weslSrc = Object.fromEntries(entries);
250
- this._rootModuleName = rootModuleName
251
- ? toModulePath(rootModuleName)
252
- : "package::main";
244
+ const pkg = this._linkOptions.packageName || "package";
245
+ const root = rootModuleName ?? "main";
246
+ this._weslSrc = toModulePaths(weslSrc, pkg);
247
+ this._rootModuleName = fileToModulePath(root, pkg, false);
253
248
  this._fromFullProject = true;
254
249
  this.rebuildPipeline();
255
250
  }
@@ -427,25 +422,17 @@ export class WgslPlay extends HTMLElement {
427
422
 
428
423
  // Load initial sources, conditions, and libs from source element.
429
424
  // Use discoverAndRebuild (not project setter) so external deps are fetched.
430
- const conditions = (el as any).conditions;
431
- const rootModuleName = (el as any).rootModuleName;
432
- const libs = (el as any).libs;
433
- const weslSrc = getSources();
434
- const entries = Object.entries(weslSrc).map(([k, v]) => [
435
- toModulePath(k),
436
- v,
437
- ]);
438
- this._weslSrc = Object.fromEntries(entries);
439
- this._rootModuleName = rootModuleName
440
- ? toModulePath(rootModuleName)
441
- : "package::main";
425
+ const { conditions, rootModuleName, libs } = el as any;
426
+ const root = rootModuleName ?? "main";
427
+ this._weslSrc = getSources();
428
+ this._rootModuleName = fileToModulePath(root, "package", false);
442
429
  if (conditions) this._linkOptions = { ...this._linkOptions, conditions };
443
430
  if (libs) this._libs = libs;
444
431
  this._fromFullProject = false;
445
432
  await this.discoverAndRebuild();
446
433
  this._fromFullProject = true; // fast rebuilds on subsequent edits
447
434
 
448
- // Listen for changes - rebuild with cached libs
435
+ // Listen for changes - rebuild with libs from source element
449
436
  this._sourceListener = (e: Event) => {
450
437
  const detail = (e as CustomEvent).detail;
451
438
  const fallback = { [this._rootModuleName]: detail?.source ?? "" };
@@ -453,6 +440,7 @@ export class WgslPlay extends HTMLElement {
453
440
  weslSrc: detail?.sources ?? fallback,
454
441
  rootModuleName: detail?.rootModuleName,
455
442
  conditions: detail?.conditions,
443
+ libs: detail?.libs,
456
444
  };
457
445
  };
458
446
  el.addEventListener("change", this._sourceListener);
@@ -629,7 +617,13 @@ function upgradeProperty(el: HTMLElement, prop: string): void {
629
617
  }
630
618
  }
631
619
 
632
- /** Convert file path to module path (e.g., "effects/main.wesl" -> "package::effects::main"). */
633
- function toModulePath(filePath: string): string {
634
- return fileToModulePath(filePath, "package", false);
620
+ /** Normalize all keys in a weslSrc record to module paths. */
621
+ function toModulePaths(
622
+ weslSrc: Record<string, string>,
623
+ pkg: string,
624
+ ): Record<string, string> {
625
+ const result: Record<string, string> = {};
626
+ for (const [key, value] of Object.entries(weslSrc))
627
+ result[fileToModulePath(key, pkg, false)] = value;
628
+ return result;
635
629
  }
@@ -221,20 +221,36 @@ test("connectToSource - external deps are fetched", async ({ page }) => {
221
221
  await expectCanvasSnapshot(page, "#player11", "connect-source-external.png");
222
222
  });
223
223
 
224
+ test("connectToSource - dynamic npm package loading", async ({ page }) => {
225
+ await page.goto("/");
226
+ await waitForFrame(page, "#player12");
227
+
228
+ // Inject code referencing random_wgsl (not in initial content)
229
+ await page.click("#inject-npm12");
230
+ await page.waitForLoadState("networkidle");
231
+ await waitForFrame(page, "#player12");
232
+
233
+ const hasError = await page.evaluate(
234
+ () => (document.querySelector("#player12") as any)?.hasError ?? true,
235
+ );
236
+ expect(hasError).toBe(false);
237
+ await expectCanvasSnapshot(page, "#player12", "connect-dynamic-npm.png");
238
+ });
239
+
224
240
  test("editor.link() with virtualLibs resolves env:: module", async ({
225
241
  page,
226
242
  }) => {
227
243
  await page.goto("/");
228
244
  await waitForWgslPlay(page);
229
245
 
230
- await page.click("#link-btn12");
246
+ await page.click("#link-btn13");
231
247
  await page.waitForFunction(
232
248
  () =>
233
- document.querySelector("#link-output12")?.textContent !==
249
+ document.querySelector("#link-output13")?.textContent !==
234
250
  "Not linked yet",
235
251
  );
236
252
 
237
- const output = await page.textContent("#link-output12");
253
+ const output = await page.textContent("#link-output13");
238
254
  expect(output).toContain("var<uniform>");
239
255
  expect(output).toContain("fs_main");
240
256
  expect(output).not.toContain("Error");