miniray 0.1.2 → 0.1.3

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
@@ -82,6 +82,8 @@ interface MinifyOptions {
82
82
  treeShaking?: boolean; // Remove unused declarations (default: true)
83
83
  preserveUniformStructTypes?: boolean; // Keep struct types used in uniforms (default: false)
84
84
  keepNames?: string[]; // Names to preserve from renaming
85
+ sourceMap?: boolean; // Generate source map (default: false)
86
+ sourceMapSources?: boolean; // Include source in sourcesContent (default: false)
85
87
  }
86
88
 
87
89
  interface MinifyResult {
@@ -89,6 +91,7 @@ interface MinifyResult {
89
91
  errors: MinifyError[]; // Parse/minification errors
90
92
  originalSize: number; // Input size in bytes
91
93
  minifiedSize: number; // Output size in bytes
94
+ sourceMap?: string; // Source map JSON (if sourceMap: true)
92
95
  }
93
96
  ```
94
97
 
@@ -180,6 +183,85 @@ minify(source, {
180
183
  });
181
184
  ```
182
185
 
186
+ ### `sourceMap`
187
+
188
+ Generate a source map to debug minified shaders by mapping back to original source:
189
+
190
+ ```javascript
191
+ const result = minify(source, {
192
+ minifyIdentifiers: true,
193
+ sourceMap: true,
194
+ });
195
+
196
+ console.log(result.code);
197
+ // "const a=42;fn b()->i32{return a;}"
198
+
199
+ console.log(result.sourceMap);
200
+ // '{"version":3,"sources":[],"names":["longVariable","myFunction"],"mappings":"MAAAA,..."}'
201
+ ```
202
+
203
+ The source map follows the [Source Map v3 specification](https://sourcemaps.info/spec.html) and includes:
204
+ - `version`: Always 3
205
+ - `names`: Original names of renamed identifiers
206
+ - `mappings`: VLQ-encoded position mappings
207
+
208
+ ### `sourceMapSources`
209
+
210
+ Include the original source code in the source map's `sourcesContent` field for self-contained debugging:
211
+
212
+ ```javascript
213
+ const result = minify(source, {
214
+ sourceMap: true,
215
+ sourceMapSources: true, // Embed original source
216
+ });
217
+
218
+ const map = JSON.parse(result.sourceMap);
219
+ console.log(map.sourcesContent);
220
+ // ["const longVariable = 42;\nfn myFunction() -> i32 { return longVariable; }"]
221
+ ```
222
+
223
+ ### Source Map Example: Complete Workflow
224
+
225
+ ```javascript
226
+ import { initialize, minify } from 'miniray';
227
+
228
+ await initialize({ wasmURL: '/miniray.wasm' });
229
+
230
+ const source = `
231
+ const longVariableName = 42;
232
+
233
+ fn helperFunction(value: i32) -> i32 {
234
+ return value * 2;
235
+ }
236
+
237
+ @compute @workgroup_size(1)
238
+ fn main() {
239
+ let result = helperFunction(longVariableName);
240
+ }
241
+ `;
242
+
243
+ const result = minify(source, {
244
+ minifyWhitespace: true,
245
+ minifyIdentifiers: true,
246
+ sourceMap: true,
247
+ sourceMapSources: true,
248
+ });
249
+
250
+ console.log('Minified code:');
251
+ console.log(result.code);
252
+ // "const a=42;fn b(c:i32)->i32{return c*2;}@compute @workgroup_size(1) fn main(){let d=b(a);}"
253
+
254
+ console.log('\nSource map:');
255
+ const map = JSON.parse(result.sourceMap);
256
+ console.log('Names:', map.names);
257
+ // Names: ["longVariableName", "helperFunction", "value", "result"]
258
+
259
+ // To use the source map inline:
260
+ const codeWithSourceMap = result.code +
261
+ '\n//# sourceMappingURL=data:application/json;base64,' +
262
+ btoa(result.sourceMap);
263
+ ```
264
+
183
265
  ## Using with Bundlers
184
266
 
185
267
  ### Vite
package/miniray.wasm CHANGED
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "miniray",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "WGSL minifier for WebGPU shaders - WebAssembly build",
5
5
  "main": "lib/main.js",
6
6
  "module": "esm/browser.js",