@bigmistqke/view.gl 0.1.0 → 0.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.
Files changed (52) hide show
  1. package/.claude/settings.local.json +2 -1
  2. package/.github/ISSUE_TEMPLATE/bug-report.yml +31 -0
  3. package/.github/ISSUE_TEMPLATE/feature-request.yml +27 -0
  4. package/.github/workflows/codeql.yml +46 -0
  5. package/.github/workflows/deploy-page.yml +38 -0
  6. package/.github/workflows/format.yml +40 -0
  7. package/README.md +92 -35
  8. package/dev/404.html +19 -0
  9. package/dev/dist/404.html +19 -0
  10. package/dev/dist/assets/bezier-DuLTb2d1.js +294 -0
  11. package/dev/dist/assets/game_of_life-D7qHdFcv.js +202 -0
  12. package/dev/dist/assets/grid-Ie22U_9K.js +173 -0
  13. package/dev/dist/assets/index-0qrXMlfv.js +109 -0
  14. package/dev/dist/assets/index-C2N3u8wj.css +12 -0
  15. package/dev/dist/assets/main-BZ1N6pp6.js +32 -0
  16. package/dev/dist/assets/overview-DAxtMIw5.js +78 -0
  17. package/dev/dist/assets/pix_sim-DIhzM_vu.js +501 -0
  18. package/dev/dist/assets/symbol-BouRL-Ni.js +65 -0
  19. package/dev/dist/assets/tag-C_bg62fD.js +516 -0
  20. package/dev/dist/assets/tetris-IMnkSi9p.js +344 -0
  21. package/dev/dist/assets/utils-CvCgsM08.js +50 -0
  22. package/dev/dist/index.html +51 -0
  23. package/dev/index.html +39 -10
  24. package/dev/{bezier.ts → src/examples/bezier.ts} +1 -1
  25. package/dev/{grid.ts → src/examples/grid.ts} +1 -1
  26. package/dev/{pix_sim.ts → src/examples/pix_sim.ts} +112 -97
  27. package/dev/src/examples/symbol.ts +79 -0
  28. package/dev/{tetris.ts → src/examples/tetris.ts} +1 -0
  29. package/dev/src/index.css +12 -0
  30. package/dev/src/index.ts +69 -0
  31. package/dev/{utils.ts → src/utils.ts} +8 -2
  32. package/dev/vite.config.ts +9 -1
  33. package/dist/index.d.mts +18 -0
  34. package/dist/index.mjs +324 -0
  35. package/dist/index.mjs.map +1 -0
  36. package/dist/tag.d.mts +97 -0
  37. package/dist/tag.mjs +162 -0
  38. package/dist/tag.mjs.map +1 -0
  39. package/dist/types-DoFAJoh-.d.mts +266 -0
  40. package/package.json +24 -10
  41. package/src/index.ts +39 -17
  42. package/src/tag.ts +47 -39
  43. package/src/types.ts +24 -24
  44. package/src/{utils.ts → utils/index.ts} +39 -14
  45. package/src/utils/object.ts +27 -0
  46. package/test/index.test.ts +1017 -0
  47. package/test/mocks/webgl.ts +248 -0
  48. package/test/setup.ts +13 -0
  49. package/test/tag.test.ts +790 -0
  50. package/vitest.config.ts +15 -0
  51. /package/dev/{game_of_life.ts → src/examples/game_of_life.ts} +0 -0
  52. /package/dev/{index.ts → src/examples/overview.ts} +0 -0
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "permissions": {
3
3
  "allow": [
4
- "Bash(rg:*)"
4
+ "Bash(pnpm build:*)",
5
+ "Bash(grep:*)"
5
6
  ],
6
7
  "deny": []
7
8
  }
@@ -0,0 +1,31 @@
1
+ name: "🐛 Bug report"
2
+ description: Create a report to help us improve
3
+ body:
4
+ - type: markdown
5
+ attributes:
6
+ value: |
7
+ Thank you for reporting an issue :pray:.
8
+
9
+ The more information you fill in, the better the community can help you.
10
+ - type: textarea
11
+ id: description
12
+ attributes:
13
+ label: Describe the bug
14
+ description: Provide a clear and concise description of the challenge you are running into.
15
+ validations:
16
+ required: true
17
+ - type: input
18
+ id: link
19
+ attributes:
20
+ label: Minimal Reproduction Link
21
+ description: |
22
+ Please provide a link to a minimal reproduction of the bug you are running into.
23
+ It makes the process of verifying and fixing the bug much easier.
24
+ Note:
25
+ - Your bug will may get fixed much faster if we can run your code and it doesn't have dependencies other than the solid-js and solid-primitives.
26
+ - To create a shareable code example you can use [Stackblitz](https://stackblitz.com/) (https://solid.new). Please no localhost URLs.
27
+ - Please read these tips for providing a minimal example: https://stackoverflow.com/help/mcve.
28
+ placeholder: |
29
+ e.g. https://stackblitz.com/edit/...... OR Github Repo
30
+ validations:
31
+ required: true
@@ -0,0 +1,27 @@
1
+ name: "Feature Request"
2
+ description: For feature/enhancement requests. Please search for existing issues first.
3
+ body:
4
+ - type: markdown
5
+ attributes:
6
+ value: |
7
+ Thank you for bringing your ideas here :pray:.
8
+
9
+ The more information you fill in, the better the community can understand your idea.
10
+ - type: textarea
11
+ id: problem
12
+ attributes:
13
+ label: Describe The Problem To Be Solved
14
+ description: Provide a clear and concise description of the challenge you are running into.
15
+ validations:
16
+ required: true
17
+ - type: textarea
18
+ id: solution
19
+ attributes:
20
+ label: Suggest A Solution
21
+ description: |
22
+ A concise description of your preferred solution. Things to address include:
23
+ - Details of the technical implementation
24
+ - Tradeoffs made in design decisions
25
+ - Caveats and considerations for the future
26
+ validations:
27
+ required: true
@@ -0,0 +1,46 @@
1
+ name: 'CodeQL'
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ branches: [main]
8
+ schedule:
9
+ - cron: '30 1 * * 0'
10
+
11
+ jobs:
12
+ analyze:
13
+ name: Analyze
14
+ runs-on: ubuntu-latest
15
+ permissions:
16
+ security-events: write
17
+
18
+ steps:
19
+ - name: Checkout repository
20
+ uses: actions/checkout@v4
21
+
22
+ - name: Initialize CodeQL
23
+ uses: github/codeql-action/init@v1
24
+ with:
25
+ languages: javascript
26
+
27
+ - name: Perform CodeQL Analysis
28
+ uses: github/codeql-action/analyze@v1
29
+ with:
30
+ upload: false
31
+ output: sarif-results
32
+
33
+ # Only include files that are public
34
+ - name: filter-sarif
35
+ uses: advanced-security/filter-sarif@main
36
+ with:
37
+ patterns: |
38
+ /src/**/*.*
39
+ -**/*.test.*
40
+ input: sarif-results/javascript.sarif
41
+ output: sarif-results/javascript.sarif
42
+
43
+ - name: Upload SARIF
44
+ uses: github/codeql-action/upload-sarif@v1
45
+ with:
46
+ sarif_file: sarif-results/javascript.sarif
@@ -0,0 +1,38 @@
1
+ name: Deploy to GitHub Pages
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main # or the branch you want to trigger the deployment from
7
+
8
+ jobs:
9
+ build-and-deploy:
10
+ runs-on: ubuntu-latest
11
+ permissions:
12
+ contents: write
13
+
14
+ steps:
15
+ - name: Checkout repository
16
+ uses: actions/checkout@v2
17
+
18
+ - name: install latest corepack
19
+ run: npm install corepack@latest -g
20
+
21
+ - run: corepack enable
22
+ - uses: actions/setup-node@v4
23
+ with:
24
+ node-version: 20
25
+ cache: 'pnpm'
26
+
27
+ - name: Install dependencies
28
+ run: pnpm install
29
+
30
+ - name: Build dev
31
+ run: pnpm dev:build
32
+
33
+ - name: Deploy to GitHub Pages
34
+ uses: peaceiris/actions-gh-pages@v3
35
+ with:
36
+ github_token: ${{ secrets.GITHUB_TOKEN }}
37
+ publish_dir: ./dev/dist # Adjust if your build output directory is different
38
+ publish_branch: gh-pages # Specify the branch to deploy to
@@ -0,0 +1,40 @@
1
+ name: Format
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+
7
+ jobs:
8
+ format:
9
+ runs-on: ubuntu-latest
10
+
11
+ permissions:
12
+ # Give the default GITHUB_TOKEN write permission to commit and push the
13
+ # added or changed files to the repository.
14
+ contents: write
15
+
16
+ steps:
17
+ - uses: actions/checkout@v4
18
+
19
+ - name: install latest corepack
20
+ run: npm install corepack@latest -g
21
+
22
+ - run: corepack enable
23
+ - uses: actions/setup-node@v4
24
+ with:
25
+ node-version: 20
26
+ cache: 'pnpm'
27
+
28
+ # "git restore ." discards changes to package-lock.json
29
+ - name: Install dependencies
30
+ run: |
31
+ pnpm install --no-frozen-lockfile --ignore-scripts
32
+ git restore .
33
+
34
+ - name: Format
35
+ run: pnpm run format
36
+
37
+ - name: Add, Commit and Push
38
+ uses: stefanzweifel/git-auto-commit-action@v4
39
+ with:
40
+ commit_message: 'Format'
package/README.md CHANGED
@@ -14,17 +14,15 @@ Minimal library for WebGL shader resource management with type-safe GLSL templat
14
14
  - [Drawing Examples](#drawing-examples)
15
15
  - [Regular Drawing](#regular-drawing)
16
16
  - [Instanced Drawing](#instanced-drawing)
17
- - [Features](#features)
18
17
  - [Tag](#tag)
19
18
  - [Basic Usage](#basic-usage-1)
20
19
  - [Template Features](#template-features)
21
20
  - [Tag Functions](#tag-functions)
22
- - [Supported Types](#supported-types)
21
+ - [Symbol Support in Templates](#symbol-support)
23
22
  - [Utils](#utils)
24
- - [WebGL Utilities](#webgl-utilities)
25
- - [Type Utilities](#type-utilities)
26
- - [Type Guards](#type-guards)
27
- - [Resource Creation](#resource-creation)
23
+ - [Create Program](#createprogram)
24
+ - [Create Texture](#createtexture)
25
+ - [Create Frame Buffer](#createframebuffer)
28
26
 
29
27
  ## View
30
28
 
@@ -33,9 +31,9 @@ The view system provides type-safe WebGL resource management for uniforms, attri
33
31
  ### Basic Usage
34
32
 
35
33
  ```typescript
36
- import { view } from 'view.gl'
34
+ import { view } from '@bigmistqke/view.gl'
37
35
 
38
- const resources = view(gl, program, {
36
+ const { uniforms, attributes } = view(gl, program, {
39
37
  uniforms: {
40
38
  time: { kind: 'float' },
41
39
  resolution: { kind: 'vec2' },
@@ -50,12 +48,12 @@ const resources = view(gl, program, {
50
48
  })
51
49
 
52
50
  // Type-safe uniform setting
53
- resources.uniforms.time.set(performance.now())
54
- resources.uniforms.resolution.set(canvas.width, canvas.height)
51
+ uniforms.time.set(performance.now())
52
+ uniforms.resolution.set(canvas.width, canvas.height)
55
53
 
56
54
  // Attribute management
57
- resources.attributes.position.set(positionData)
58
- resources.attributes.position.bind()
55
+ attributes.position.set(positionData)
56
+ attributes.position.bind()
59
57
  ```
60
58
 
61
59
  ### View Types
@@ -63,7 +61,12 @@ resources.attributes.position.bind()
63
61
  Each view type can be imported individually too.
64
62
 
65
63
  ```typescript
66
- import { uniformView, attributeView, interleavedAttributeView, bufferView } from 'view.gl'
64
+ import {
65
+ uniformView,
66
+ attributeView,
67
+ interleavedAttributeView,
68
+ bufferView,
69
+ } from '@bigmistqke/view.gl'
67
70
  ```
68
71
 
69
72
  #### uniformView
@@ -71,7 +74,7 @@ import { uniformView, attributeView, interleavedAttributeView, bufferView } from
71
74
  Manages shader uniform variables.
72
75
 
73
76
  ```typescript
74
- import { uniformView } from 'view.gl'
77
+ import { uniformView } from '@bigmistqke/view.gl'
75
78
 
76
79
  const uniforms = uniformView(gl, program, {
77
80
  time: { kind: 'float' },
@@ -94,7 +97,7 @@ uniforms.transform.set(transformMatrix)
94
97
  Manages vertex attributes with buffer creation, binding, and data management.
95
98
 
96
99
  ```typescript
97
- import { attributeView } from 'view.gl'
100
+ import { attributeView } from '@bigmistqke/view.gl'
98
101
 
99
102
  const attributes = attributeView(gl, program, {
100
103
  position: { kind: 'vec3' },
@@ -125,20 +128,20 @@ gl.drawArraysInstanced(gl.TRIANGLES, 0, 3, 100)
125
128
  Manages interleaved vertex data with automatic stride/offset calculation and VAO optimization.
126
129
 
127
130
  ```typescript
128
- import { interleavedAttributeView } from 'view.gl'
131
+ import { interleavedAttributeView } from '@bigmistqke/view.gl'
129
132
 
130
133
  const interleavedAttributes = interleavedAttributeView(gl, program, {
131
134
  vertexData: {
132
135
  layout: [
133
- { name: 'position', kind: 'vec3' },
134
- { name: 'normal', kind: 'vec3' },
135
- { name: 'uv', kind: 'vec2' },
136
+ { key: 'position', kind: 'vec3' },
137
+ { key: 'normal', kind: 'vec3' },
138
+ { key: 'uv', kind: 'vec2' },
136
139
  ],
137
140
  },
138
141
  instanceData: {
139
142
  layout: [
140
- { name: 'instancePos', kind: 'vec2' },
141
- { name: 'instanceColor', kind: 'vec3' },
143
+ { key: 'instancePos', kind: 'vec2' },
144
+ { key: 'instanceColor', kind: 'vec3' },
142
145
  ],
143
146
  instanced: true,
144
147
  },
@@ -163,7 +166,7 @@ interleavedAttributes.instanceData.bind()
163
166
  Manages generic WebGL buffers for various uses.
164
167
 
165
168
  ```typescript
166
- import { bufferView } from 'view.gl'
169
+ import { bufferView } from '@bigmistqke/view.gl'
167
170
 
168
171
  const buffers = bufferView(gl, {
169
172
  indices: { target: 'ELEMENT_ARRAY_BUFFER' },
@@ -221,13 +224,13 @@ gl.drawArraysInstanced(gl.TRIANGLES, 0, 3, instanceCount)
221
224
  ### Features
222
225
 
223
226
  - **Automatic Resource Management**: Buffer creation, disposal, and cleanup
224
- - **Type Safety**: Compile-time type checking for uniform and attribute operations
227
+ - **Type Safety**: type checking for uniform and attribute operations
225
228
  - **WebGL Extensions**: Automatic fallback for instanced arrays and vertex array objects
226
- - **Memory Management**: AbortSignal support for resource cleanup
229
+ - **Memory Management**: AbortSignal support for scheduling cleanup of resources
227
230
 
228
231
  ## Tag
229
232
 
230
- The tag system provides GLSL template literal support with embedded resource definitions.
233
+ The tag system provides GLSL template literal support with embedded schema definitions.
231
234
 
232
235
  ### Template Features
233
236
 
@@ -235,6 +238,7 @@ The tag system provides GLSL template literal support with embedded resource def
235
238
  - **Type Safety**: Automatic schema generation from template literals
236
239
  - **WebGL Version Support**: Automatic syntax conversion for WebGL1/2
237
240
  - **Interleaved Attributes**: Multi-attribute layout support
241
+ - **Symbol Support**: Use JavaScript symbols as keys (see [View Features](#symbol-support))
238
242
 
239
243
  ### Tag Functions
240
244
 
@@ -247,7 +251,7 @@ The tag system provides GLSL template literal support with embedded resource def
247
251
  ### Basic Usage
248
252
 
249
253
  ```typescript
250
- import { glsl, uniform, attribute, compile } from 'view.gl/tag'
254
+ import { glsl, uniform, attribute, compile } from '@bigmistqke/view.gl/tag'
251
255
 
252
256
  const vertexShader = glsl`
253
257
  ${attribute.vec3('position')}
@@ -276,28 +280,81 @@ const fragmentShader = glsl`
276
280
  const { program, schema } = compile(gl, vertexShader, fragmentShader)
277
281
  ```
278
282
 
279
- ## Utils
283
+ ### Symbol Support
284
+
285
+ Symbols are supported as keys for uniforms, attributes, and buffers. When interpolated in glsl templates, they're automatically converted to valid GLSL identifiers. This prevents naming collisions between different shader modules and enables private scoping of shader variables.
286
+
287
+ ```typescript
288
+ const u_time = Symbol('time')
289
+ const a_position = Symbol('position')
290
+
291
+ const shader = glsl`
292
+ ${attribute.vec3(a_position)}
293
+ ${uniform.float(u_time)}
294
+
295
+ void main() {
296
+ gl_Position = vec4(${a_position}, ${u_time});
297
+ }
298
+ `
299
+ ```
300
+
301
+ When manually constructing GLSL strings, use `toID()` to convert symbols to valid identifiers:
302
+
303
+ ```typescript
304
+ import { createProgram, view, toID } from 'view.gl'
305
+
306
+ const u_time = Symbol('time')
307
+ const a_position = Symbol('position')
308
+
309
+ const vertex = `
310
+ attribute vec3 ${toID(a_position)};
311
+ uniform float ${toID(u_time)};
280
312
 
281
- WebGL utilities and helper functions.
313
+ void main() {
314
+ gl_Position = vec4(${toID(a_position)}, ${toID(u_time)});
315
+ }
316
+ `
317
+
318
+ const fragment = `
319
+ precision mediump float;
320
+ uniform float ${toID(u_time)};
321
+
322
+ void main() {
323
+ gl_FragColor = vec4(1.0, 1.0, 1.0, sin(${toID(u_time)}));
324
+ }
325
+ `
326
+
327
+ const program = createProgram(gl, vertex, fragment)
328
+
329
+ const { attributes, uniforms } = view(gl, program, {
330
+ uniforms: { [u_time]: { kind: 'float' } },
331
+ attributes: { [a_position]: { kind: 'vec3' } },
332
+ })
333
+
334
+ attributes[a_position].set(vertexData)
335
+ uniforms[u_time].set(performance.now())
336
+ ```
337
+
338
+ ## Utils
282
339
 
283
- ### WebGL Utilities
340
+ WebGL utilities.
284
341
 
285
- #### createProgram
342
+ ### createProgram
286
343
 
287
344
  Creates and links a WebGL program from vertex and fragment shader sources.
288
345
 
289
346
  ```typescript
290
- import { createProgram } from 'view.gl/utils'
347
+ import { createProgram } from '@bigmistqke/view.gl/utils'
291
348
 
292
349
  const program = createProgram(gl, vertexShaderSource, fragmentShaderSource)
293
350
  ```
294
351
 
295
- #### createTexture
352
+ ### createTexture
296
353
 
297
354
  Creates a WebGL texture with specified parameters.
298
355
 
299
356
  ```typescript
300
- import { createTexture } from 'view.gl/utils'
357
+ import { createTexture } from '@bigmistqke/view.gl/utils'
301
358
 
302
359
  const texture = createTexture(
303
360
  gl,
@@ -318,12 +375,12 @@ const texture = createTexture(
318
375
 
319
376
  Automatically validates WebGL2-only formats and provides fallbacks for WebGL1.
320
377
 
321
- #### createFramebuffer
378
+ ### createFramebuffer
322
379
 
323
380
  Creates a framebuffer with attached texture for render-to-texture operations.
324
381
 
325
382
  ```typescript
326
- import { createFramebuffer } from 'view.gl/utils'
383
+ import { createFramebuffer } from '@bigmistqke/view.gl/utils'
327
384
 
328
385
  const { framebuffer, texture } = createFramebuffer(gl, {
329
386
  width: 512,
package/dev/404.html ADDED
@@ -0,0 +1,19 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <title>view.gl</title>
6
+ <script>
7
+ // Redirect to index.html with the current path as a query parameter
8
+ const path = window.location.pathname.slice(1); // Remove leading slash
9
+ if (path) {
10
+ window.location.replace(window.location.origin + '/?redirect=' + path);
11
+ } else {
12
+ window.location.replace(window.location.origin);
13
+ }
14
+ </script>
15
+ </head>
16
+ <body>
17
+ Redirecting...
18
+ </body>
19
+ </html>
@@ -0,0 +1,19 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <title>view.gl</title>
6
+ <script>
7
+ // Redirect to index.html with the current path as a query parameter
8
+ const path = window.location.pathname.slice(1); // Remove leading slash
9
+ if (path) {
10
+ window.location.replace(window.location.origin + '/?redirect=' + path);
11
+ } else {
12
+ window.location.replace(window.location.origin);
13
+ }
14
+ </script>
15
+ </head>
16
+ <body>
17
+ Redirecting...
18
+ </body>
19
+ </html>