glslh 1.1.1 → 1.1.2

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/CHANGELOG.md CHANGED
@@ -1,6 +1,12 @@
1
1
  ## 📋 `glslh` Changelog
2
2
 
3
- ### **v1.1.1** (Latest)
3
+ ### **v1.1.2** (Latest)
4
+
5
+ - **AI-Native Error Context Mapping**: Upgraded `translateShaderError` inside `parser.js` to automatically extract and embed surrounding 5-line code snippets (`--- Code Context ---`) directly alongside modular file and line indicators, allowing developers and AI assistants to diagnose and patch WebGL compilation errors instantly without manual file lookups.
6
+
7
+ ---
8
+
9
+ ### **v1.1.1**
4
10
 
5
11
  - **Documentation & README Refinement**: Updated documentation, architecture diagrams, and release logs to reflect complete structural guides for modular struct-based composition, CPU/GPU division of labor, and extension workflows.
6
12
 
package/README.md CHANGED
@@ -40,7 +40,7 @@
40
40
  - **Zero Runtime Performance Cost:** Because modular files are stitched and compiled once during initialization, your shaders execute at full native GPU speed with zero runtime overhead.
41
41
  - **C-Style `#include` Directives:** Split massive shaders into modular files with full circular dependency protection and strict extension validation.
42
42
  - **Duplicate Function Collision Detection:** Automatically scans included modules and warns you if multiple files define conflicting function signatures (`float hash()`) before WebGL compilation fails, while fully supporting valid GLSL function overloading.
43
- - **Error Line Mapping:** Instantly translates monolithic WebGL compilation error line numbers back to their exact source file and line number (`[shape_utils.glsl:14]`).
43
+ - **Error Context Mapping:** Automatically captures and embeds 5-line surrounding code context snippets alongside modular file and line numbers when WebGL compilation fails.
44
44
  - **Self-Contained Metadata Blocks:** Define uniform data types, default values, and derived per-frame formulas right at the top of your shader file (`@uniforms`).
45
45
  - **Direct JavaScript Math Injection:** Use native JS constants like `Math.PI` or `Math.TAU` directly in your GLSL code; the preprocessor evaluates them before GPU compilation.
46
46
  - **Framework Agnostic:** Seamlessly output standard Three.js `ShaderMaterial` objects ready for Vanilla JS, Three.js, or React Three Fiber.
@@ -93,7 +93,7 @@ package/
93
93
  ## 🚀 Installation & Quick Start
94
94
 
95
95
  ```bash
96
- npm install glslh@1.1.1
96
+ npm install glslh@1.1.2
97
97
  ```
98
98
 
99
99
  ### 1. Create a `.glslh` Shader File (`./shaders/header.glslh`)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "glslh",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "description": "A lightweight GLSL preprocessor and runtime bridge for modular shader development.",
5
5
  "type": "module",
6
6
  "main": "./src/dom-canvas.js",
package/src/parser.js CHANGED
@@ -103,7 +103,6 @@ export class GLSLHParser {
103
103
  new Set(),
104
104
  );
105
105
 
106
- // Run duplicate function collision check on the final flattened source
107
106
  detectFunctionCollisions(result.source);
108
107
 
109
108
  return result;
@@ -239,7 +238,6 @@ export class GLSLHParser {
239
238
  }
240
239
  }
241
240
 
242
- // 1. Extract #version if present so it always stays at the absolute top
243
241
  const versionMatch = processed.match(/^\s*#version[^\n]*\r?\n/);
244
242
  let versionHeader = "";
245
243
  if (versionMatch) {
@@ -247,7 +245,6 @@ export class GLSLHParser {
247
245
  processed = processed.slice(versionHeader.length);
248
246
  }
249
247
 
250
- // 2. Build auto-injected math constants defines
251
248
  let constantsBlock = "";
252
249
  if (usedConstants.size > 0) {
253
250
  constantsBlock = "// --- GLSLH Auto-injected Math Constants ---\n";
@@ -258,7 +255,6 @@ export class GLSLHParser {
258
255
  constantsBlock += "\n";
259
256
  }
260
257
 
261
- // 3. Build auto-injected uniform declarations
262
258
  let declBlock = "";
263
259
  const declLines = Object.entries(uniformsDefinition)
264
260
  .filter(
@@ -273,7 +269,6 @@ export class GLSLHParser {
273
269
  "\n\n";
274
270
  }
275
271
 
276
- // 4. Re-assemble with #version strictly at the top
277
272
  processed = versionHeader + constantsBlock + declBlock + processed;
278
273
 
279
274
  return {
@@ -362,7 +357,17 @@ export function translateShaderError(
362
357
  const mapped = lineMap.at(flatLine - 1);
363
358
 
364
359
  if (mapped && !mapped.isMarker) {
365
- return `[${mapped.file}:${mapped.line}]`;
360
+ const contextStart = Math.max(0, flatLine - 3);
361
+ const contextEnd = Math.min(lines.length - 1, flatLine + 1);
362
+ let snippet = "\n--- Code Context ---\n";
363
+
364
+ for (let i = contextStart; i <= contextEnd; i++) {
365
+ const prefix = i === flatLine - 1 ? " >> " : " ";
366
+ snippet += `${prefix}${i + 1}: ${lines[i]}\n`;
367
+ }
368
+ snippet += "--------------------";
369
+
370
+ return `[File: ${mapped.file} | Line: ${mapped.line}]${snippet}`;
366
371
  }
367
372
  return match;
368
373
  });