wgsl-edit 0.0.12 → 0.0.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.
package/README.md CHANGED
@@ -90,6 +90,7 @@ editor.project = { // load a full project
90
90
 
91
91
  ### Methods
92
92
 
93
+ - `link(options?): Promise<string>` - Compile WESL sources into WGSL, returns the linked output
93
94
  - `addFile(name, content?)` - Add a new file
94
95
  - `removeFile(name)` - Remove a file
95
96
  - `renameFile(oldName, newName)` - Rename a file
@@ -1,7 +1,7 @@
1
1
  import { createWeslLinter, wesl } from "./Language.js";
2
2
  import { HighlightStyle, syntaxHighlighting } from "@codemirror/language";
3
3
  import { forceLinting } from "@codemirror/lint";
4
- import { fileToModulePath } from "wesl";
4
+ import { fileToModulePath, link } from "wesl";
5
5
  import { Compartment, EditorState, Text } from "@codemirror/state";
6
6
  import { tags } from "@lezer/highlight";
7
7
  import { EditorView, basicSetup } from "codemirror";
@@ -91,6 +91,10 @@ var WgslEdit = class extends HTMLElement {
91
91
  connectedCallback() {
92
92
  this.initEditor();
93
93
  this.loadInitialContent();
94
+ upgradeProperty(this, "conditions");
95
+ upgradeProperty(this, "source");
96
+ upgradeProperty(this, "sources");
97
+ upgradeProperty(this, "project");
94
98
  }
95
99
  disconnectedCallback() {
96
100
  this.connectLintSource(null);
@@ -168,6 +172,19 @@ var WgslEdit = class extends HTMLElement {
168
172
  }
169
173
  this.updateLint();
170
174
  }
175
+ /** Link/compile WESL sources into WGSL. Returns the compiled WGSL string. */
176
+ async link(options) {
177
+ const pkg = this._packageName ?? "package";
178
+ const rootModuleName = fileToModulePath(this._activeFile, pkg, false);
179
+ return (await link({
180
+ weslSrc: this.sources,
181
+ rootModuleName,
182
+ conditions: this._conditions,
183
+ libs: this._libs,
184
+ packageName: pkg,
185
+ ...options
186
+ })).dest;
187
+ }
171
188
  /** Currently active file name. */
172
189
  get activeFile() {
173
190
  return this._activeFile;
@@ -652,6 +669,14 @@ function getStyles() {
652
669
  }
653
670
  return cachedStyleSheet;
654
671
  }
672
+ /** Absorb instance properties set before custom element upgrade. */
673
+ function upgradeProperty(el, prop) {
674
+ if (Object.hasOwn(el, prop)) {
675
+ const value = el[prop];
676
+ delete el[prop];
677
+ el[prop] = value;
678
+ }
679
+ }
655
680
  /** Convert a module path or file path to a tab name: "package::main" -> "main", "main.wesl" -> "main.wesl" */
656
681
  function toTabName(key) {
657
682
  if (key.includes("::")) return key.replace(/^[^:]+::/, "").replaceAll("::", "/");
@@ -50,6 +50,8 @@ declare class WgslEdit extends HTMLElement {
50
50
  set sources(value: Record<string, string>);
51
51
  /** Load a full project config (sources, conditions, packageName, etc.). */
52
52
  set project(value: WeslProject);
53
+ /** Link/compile WESL sources into WGSL. Returns the compiled WGSL string. */
54
+ link(options?: Partial<LinkParams>): Promise<string>;
53
55
  /** Currently active file name. */
54
56
  get activeFile(): string;
55
57
  /** Switch to a file by name. */
package/dist/WgslEdit.js CHANGED
@@ -1,4 +1,4 @@
1
1
  import "./Language.js";
2
- import { t as WgslEdit } from "./WgslEdit-82bY_qxC.js";
2
+ import { t as WgslEdit } from "./WgslEdit-BSUXQfGS.js";
3
3
 
4
4
  export { WgslEdit };
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { wesl, weslLanguage } from "./Language.js";
2
- import { t as WgslEdit } from "./WgslEdit-82bY_qxC.js";
2
+ import { t as WgslEdit } from "./WgslEdit-BSUXQfGS.js";
3
3
 
4
4
  //#region src/index.ts
5
5
  if (!customElements.get("wgsl-edit")) customElements.define("wgsl-edit", WgslEdit);