@bigmistqke/view.gl 0.1.1 → 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.
- package/.claude/settings.local.json +9 -0
- package/.github/ISSUE_TEMPLATE/bug-report.yml +31 -0
- package/.github/ISSUE_TEMPLATE/feature-request.yml +27 -0
- package/.github/workflows/codeql.yml +46 -0
- package/.github/workflows/deploy-page.yml +38 -0
- package/.github/workflows/format.yml +40 -0
- package/README.md +92 -35
- package/dev/404.html +19 -0
- package/dev/dist/404.html +19 -0
- package/dev/dist/assets/bezier-DuLTb2d1.js +294 -0
- package/dev/dist/assets/game_of_life-D7qHdFcv.js +202 -0
- package/dev/dist/assets/grid-Ie22U_9K.js +173 -0
- package/dev/dist/assets/index-0qrXMlfv.js +109 -0
- package/dev/dist/assets/index-C2N3u8wj.css +12 -0
- package/dev/dist/assets/main-BZ1N6pp6.js +32 -0
- package/dev/dist/assets/overview-DAxtMIw5.js +78 -0
- package/dev/dist/assets/pix_sim-DIhzM_vu.js +501 -0
- package/dev/dist/assets/symbol-BouRL-Ni.js +65 -0
- package/dev/dist/assets/tag-C_bg62fD.js +516 -0
- package/dev/dist/assets/tetris-IMnkSi9p.js +344 -0
- package/dev/dist/assets/utils-CvCgsM08.js +50 -0
- package/dev/dist/index.html +51 -0
- package/dev/index.html +39 -10
- package/dev/{bezier.ts → src/examples/bezier.ts} +1 -1
- package/dev/{grid.ts → src/examples/grid.ts} +1 -1
- package/dev/{pix_sim.ts → src/examples/pix_sim.ts} +112 -97
- package/dev/src/examples/symbol.ts +79 -0
- package/dev/{tetris.ts → src/examples/tetris.ts} +1 -0
- package/dev/src/index.css +12 -0
- package/dev/src/index.ts +69 -0
- package/dev/{utils.ts → src/utils.ts} +8 -2
- package/dev/vite.config.ts +9 -1
- package/dist/index.d.mts +3 -2
- package/dist/index.mjs +81 -27
- package/dist/index.mjs.map +1 -1
- package/dist/tag.d.mts +9 -9
- package/dist/tag.mjs +46 -17
- package/dist/tag.mjs.map +1 -1
- package/dist/{types-DxpS9Bae.d.mts → types-DoFAJoh-.d.mts} +18 -18
- package/package.json +20 -7
- package/src/index.ts +39 -17
- package/src/tag.ts +47 -39
- package/src/types.ts +24 -24
- package/src/{utils.ts → utils/index.ts} +39 -14
- package/src/utils/object.ts +27 -0
- package/test/index.test.ts +1017 -0
- package/test/mocks/webgl.ts +248 -0
- package/test/setup.ts +13 -0
- package/test/tag.test.ts +790 -0
- package/vitest.config.ts +15 -0
- /package/dev/{game_of_life.ts → src/examples/game_of_life.ts} +0 -0
- /package/dev/{index.ts → src/examples/overview.ts} +0 -0
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
import { vi } from 'vitest'
|
|
2
|
+
|
|
3
|
+
interface MockWebGLBuffer extends WebGLBuffer {
|
|
4
|
+
id: number
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
interface MockWebGLProgram extends WebGLProgram {
|
|
8
|
+
id: number
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
interface MockWebGLShader extends WebGLShader {
|
|
12
|
+
id: number
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
interface MockWebGLTexture extends WebGLTexture {
|
|
16
|
+
id: number
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
interface MockWebGLFramebuffer extends WebGLFramebuffer {
|
|
20
|
+
id: number
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
interface MockWebGLVertexArrayObject extends WebGLVertexArrayObject {
|
|
24
|
+
id: number
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function createMockGL() {
|
|
28
|
+
const buffers = new Map<number, MockWebGLBuffer>()
|
|
29
|
+
const programs = new Map<number, MockWebGLProgram>()
|
|
30
|
+
const shaders = new Map<number, MockWebGLShader>()
|
|
31
|
+
const textures = new Map<number, MockWebGLTexture>()
|
|
32
|
+
const framebuffers = new Map<number, MockWebGLFramebuffer>()
|
|
33
|
+
const vertexArrays = new Map<number, MockWebGLVertexArrayObject>()
|
|
34
|
+
|
|
35
|
+
let nextId = 1
|
|
36
|
+
|
|
37
|
+
const mockGL = {
|
|
38
|
+
// Constants
|
|
39
|
+
ARRAY_BUFFER: 0x8892,
|
|
40
|
+
ELEMENT_ARRAY_BUFFER: 0x8893,
|
|
41
|
+
STATIC_DRAW: 0x88e4,
|
|
42
|
+
DYNAMIC_DRAW: 0x88e8,
|
|
43
|
+
FLOAT: 0x1406,
|
|
44
|
+
INT: 0x1404,
|
|
45
|
+
UNSIGNED_BYTE: 0x1401,
|
|
46
|
+
TRIANGLES: 0x0004,
|
|
47
|
+
LINES: 0x0001,
|
|
48
|
+
TRIANGLE_STRIP: 0x0005,
|
|
49
|
+
VERTEX_SHADER: 0x8b31,
|
|
50
|
+
FRAGMENT_SHADER: 0x8b30,
|
|
51
|
+
COMPILE_STATUS: 0x8b81,
|
|
52
|
+
LINK_STATUS: 0x8b82,
|
|
53
|
+
TEXTURE_2D: 0x0de1,
|
|
54
|
+
TEXTURE0: 0x84c0,
|
|
55
|
+
COLOR_ATTACHMENT0: 0x8ce0,
|
|
56
|
+
FRAMEBUFFER: 0x8d40,
|
|
57
|
+
NEAREST: 0x2600,
|
|
58
|
+
LINEAR: 0x2601,
|
|
59
|
+
TEXTURE_MAG_FILTER: 0x2800,
|
|
60
|
+
TEXTURE_MIN_FILTER: 0x2801,
|
|
61
|
+
|
|
62
|
+
// Buffer methods
|
|
63
|
+
createBuffer: vi.fn(() => {
|
|
64
|
+
const buffer = { id: nextId++ } as MockWebGLBuffer
|
|
65
|
+
buffers.set(buffer.id, buffer)
|
|
66
|
+
return buffer
|
|
67
|
+
}),
|
|
68
|
+
|
|
69
|
+
deleteBuffer: vi.fn((buffer: MockWebGLBuffer) => {
|
|
70
|
+
if (buffer) buffers.delete(buffer.id)
|
|
71
|
+
}),
|
|
72
|
+
|
|
73
|
+
bindBuffer: vi.fn((target: number, buffer: MockWebGLBuffer | null) => {
|
|
74
|
+
// Buffer binding logic would go here
|
|
75
|
+
}),
|
|
76
|
+
|
|
77
|
+
bufferData: vi.fn(),
|
|
78
|
+
|
|
79
|
+
// Program methods
|
|
80
|
+
createProgram: vi.fn(() => {
|
|
81
|
+
const program = { id: nextId++ } as MockWebGLProgram
|
|
82
|
+
programs.set(program.id, program)
|
|
83
|
+
return program
|
|
84
|
+
}),
|
|
85
|
+
|
|
86
|
+
deleteProgram: vi.fn((program: MockWebGLProgram) => {
|
|
87
|
+
if (program) programs.delete(program.id)
|
|
88
|
+
}),
|
|
89
|
+
|
|
90
|
+
useProgram: vi.fn((program: MockWebGLProgram | null) => {
|
|
91
|
+
// Program usage logic would go here
|
|
92
|
+
}),
|
|
93
|
+
|
|
94
|
+
linkProgram: vi.fn(),
|
|
95
|
+
attachShader: vi.fn(),
|
|
96
|
+
getProgramParameter: vi.fn(() => true),
|
|
97
|
+
getProgramInfoLog: vi.fn(() => ''),
|
|
98
|
+
|
|
99
|
+
// Shader methods
|
|
100
|
+
createShader: vi.fn((type: number) => {
|
|
101
|
+
const shader = { id: nextId++, type } as MockWebGLShader
|
|
102
|
+
shaders.set(shader.id, shader)
|
|
103
|
+
return shader
|
|
104
|
+
}),
|
|
105
|
+
|
|
106
|
+
deleteShader: vi.fn((shader: MockWebGLShader) => {
|
|
107
|
+
if (shader) shaders.delete(shader.id)
|
|
108
|
+
}),
|
|
109
|
+
|
|
110
|
+
shaderSource: vi.fn(),
|
|
111
|
+
compileShader: vi.fn(),
|
|
112
|
+
getShaderParameter: vi.fn(() => true),
|
|
113
|
+
getShaderInfoLog: vi.fn(() => ''),
|
|
114
|
+
|
|
115
|
+
// Attribute methods
|
|
116
|
+
getAttribLocation: vi.fn((program: MockWebGLProgram, name: string) => {
|
|
117
|
+
// Return incrementing location for each unique name
|
|
118
|
+
return name.charCodeAt(0) % 16
|
|
119
|
+
}),
|
|
120
|
+
|
|
121
|
+
enableVertexAttribArray: vi.fn(),
|
|
122
|
+
vertexAttribPointer: vi.fn(),
|
|
123
|
+
vertexAttribDivisor: vi.fn(),
|
|
124
|
+
|
|
125
|
+
// Uniform methods
|
|
126
|
+
getUniformLocation: vi.fn((program: MockWebGLProgram, name: string) => {
|
|
127
|
+
return { id: nextId++, name } as WebGLUniformLocation
|
|
128
|
+
}),
|
|
129
|
+
|
|
130
|
+
uniform1i: vi.fn(),
|
|
131
|
+
uniform1f: vi.fn(),
|
|
132
|
+
uniform2i: vi.fn(),
|
|
133
|
+
uniform2f: vi.fn(),
|
|
134
|
+
uniform3i: vi.fn(),
|
|
135
|
+
uniform3f: vi.fn(),
|
|
136
|
+
uniform4i: vi.fn(),
|
|
137
|
+
uniform4f: vi.fn(),
|
|
138
|
+
uniform1fv: vi.fn(),
|
|
139
|
+
uniform2fv: vi.fn(),
|
|
140
|
+
uniform3fv: vi.fn(),
|
|
141
|
+
uniform4fv: vi.fn(),
|
|
142
|
+
uniform1iv: vi.fn(),
|
|
143
|
+
uniform2iv: vi.fn(),
|
|
144
|
+
uniform3iv: vi.fn(),
|
|
145
|
+
uniform4iv: vi.fn(),
|
|
146
|
+
uniformMatrix2fv: vi.fn(),
|
|
147
|
+
uniformMatrix3fv: vi.fn(),
|
|
148
|
+
uniformMatrix4fv: vi.fn(),
|
|
149
|
+
|
|
150
|
+
// Drawing methods
|
|
151
|
+
drawArrays: vi.fn(),
|
|
152
|
+
drawArraysInstanced: vi.fn(),
|
|
153
|
+
drawElements: vi.fn(),
|
|
154
|
+
|
|
155
|
+
// Texture methods
|
|
156
|
+
createTexture: vi.fn(() => {
|
|
157
|
+
const texture = { id: nextId++ } as MockWebGLTexture
|
|
158
|
+
textures.set(texture.id, texture)
|
|
159
|
+
return texture
|
|
160
|
+
}),
|
|
161
|
+
|
|
162
|
+
deleteTexture: vi.fn((texture: MockWebGLTexture) => {
|
|
163
|
+
if (texture) textures.delete(texture.id)
|
|
164
|
+
}),
|
|
165
|
+
|
|
166
|
+
bindTexture: vi.fn(),
|
|
167
|
+
texImage2D: vi.fn(),
|
|
168
|
+
texParameteri: vi.fn(),
|
|
169
|
+
activeTexture: vi.fn(),
|
|
170
|
+
|
|
171
|
+
// Framebuffer methods
|
|
172
|
+
createFramebuffer: vi.fn(() => {
|
|
173
|
+
const framebuffer = { id: nextId++ } as MockWebGLFramebuffer
|
|
174
|
+
framebuffers.set(framebuffer.id, framebuffer)
|
|
175
|
+
return framebuffer
|
|
176
|
+
}),
|
|
177
|
+
|
|
178
|
+
deleteFramebuffer: vi.fn((framebuffer: MockWebGLFramebuffer) => {
|
|
179
|
+
if (framebuffer) framebuffers.delete(framebuffer.id)
|
|
180
|
+
}),
|
|
181
|
+
|
|
182
|
+
bindFramebuffer: vi.fn(),
|
|
183
|
+
framebufferTexture2D: vi.fn(),
|
|
184
|
+
|
|
185
|
+
// VAO methods (WebGL2)
|
|
186
|
+
createVertexArray: vi.fn(() => {
|
|
187
|
+
const vao = { id: nextId++ } as MockWebGLVertexArrayObject
|
|
188
|
+
vertexArrays.set(vao.id, vao)
|
|
189
|
+
return vao
|
|
190
|
+
}),
|
|
191
|
+
|
|
192
|
+
deleteVertexArray: vi.fn((vao: MockWebGLVertexArrayObject) => {
|
|
193
|
+
if (vao) vertexArrays.delete(vao.id)
|
|
194
|
+
}),
|
|
195
|
+
|
|
196
|
+
bindVertexArray: vi.fn(),
|
|
197
|
+
|
|
198
|
+
// Extensions
|
|
199
|
+
getExtension: vi.fn((name: string) => {
|
|
200
|
+
if (name === 'ANGLE_instanced_arrays') {
|
|
201
|
+
return {
|
|
202
|
+
vertexAttribDivisorANGLE: mockGL.vertexAttribDivisor.bind(mockGL),
|
|
203
|
+
drawArraysInstancedANGLE: mockGL.drawArraysInstanced.bind(mockGL),
|
|
204
|
+
drawElementsInstancedANGLE: mockGL.drawElements.bind(mockGL),
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
if (name === 'OES_vertex_array_object') {
|
|
208
|
+
return {
|
|
209
|
+
createVertexArrayOES: mockGL.createVertexArray.bind(mockGL),
|
|
210
|
+
deleteVertexArrayOES: mockGL.deleteVertexArray.bind(mockGL),
|
|
211
|
+
bindVertexArrayOES: mockGL.bindVertexArray.bind(mockGL),
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
return null
|
|
215
|
+
}),
|
|
216
|
+
|
|
217
|
+
// State
|
|
218
|
+
viewport: vi.fn(),
|
|
219
|
+
clear: vi.fn(),
|
|
220
|
+
clearColor: vi.fn(),
|
|
221
|
+
enable: vi.fn(),
|
|
222
|
+
disable: vi.fn(),
|
|
223
|
+
blendFunc: vi.fn(),
|
|
224
|
+
depthFunc: vi.fn(),
|
|
225
|
+
cullFace: vi.fn(),
|
|
226
|
+
|
|
227
|
+
// Error handling
|
|
228
|
+
getError: vi.fn(() => 0),
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
return mockGL as any
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
export function createMockCanvas() {
|
|
235
|
+
const canvas = document.createElement('canvas')
|
|
236
|
+
Object.defineProperty(canvas, 'width', { value: 800, writable: true })
|
|
237
|
+
Object.defineProperty(canvas, 'height', { value: 600, writable: true })
|
|
238
|
+
|
|
239
|
+
const gl = createMockGL()
|
|
240
|
+
canvas.getContext = vi.fn((contextType: string) => {
|
|
241
|
+
if (contextType === 'webgl' || contextType === 'webgl2') {
|
|
242
|
+
return gl as any
|
|
243
|
+
}
|
|
244
|
+
return null
|
|
245
|
+
})
|
|
246
|
+
|
|
247
|
+
return { canvas, gl }
|
|
248
|
+
}
|
package/test/setup.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { vi } from 'vitest'
|
|
2
|
+
import { createMockGL } from './mocks/webgl'
|
|
3
|
+
|
|
4
|
+
vi.stubGlobal('WebGLRenderingContext', createMockGL)
|
|
5
|
+
vi.stubGlobal('WebGL2RenderingContext', createMockGL)
|
|
6
|
+
|
|
7
|
+
// Mock canvas getContext to return our WebGL mock
|
|
8
|
+
HTMLCanvasElement.prototype.getContext = vi.fn(function (contextType: string) {
|
|
9
|
+
if (contextType === 'webgl' || contextType === 'webgl2') {
|
|
10
|
+
return createMockGL() as any
|
|
11
|
+
}
|
|
12
|
+
return null
|
|
13
|
+
})
|