@rtstic.dev/pulse 0.0.54 → 0.0.56

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.
@@ -1,4 +1,75 @@
1
- "use strict";(()=>{var g="https://cdn.prod.website-files.com/680cbbaefb50442c848aedf7/6926cf888059f91e69c286e7_IMG_0311.jpg",p="https://cdn.prod.website-files.com/680cbbaefb50442c848aedf7/6926cf7fd0f3c3f3276d1575_IMG_0310.png";var t={gl:null,program:null,mousePos:{x:0,y:0},targetPos:{x:0,y:0},textures:{color:null,depth:null},animationId:null,isLoaded:!1,imageAspect:1,canvasAspect:1,uvScale:{x:1,y:1},uvOffset:{x:0,y:0}},E=document.getElementById("viewer-wrapper"),i=document.getElementById("viewer-canvas"),d=document.getElementById("status");i.addEventListener("mousemove",e=>{let r=i.getBoundingClientRect(),n=((e.clientX-r.left)/r.width-.5)*2,o=-((e.clientY-r.top)/r.height-.5)*2;t.targetPos.x=n,t.targetPos.y=o});i.addEventListener("mouseleave",()=>{t.targetPos.x=0,t.targetPos.y=0});function v(){i.width=E.clientWidth,i.height=E.clientHeight,t.gl&&(t.gl.viewport(0,0,i.width,i.height),T())}function T(){t.canvasAspect=i.width/i.height;let e=t.imageAspect||1,r=t.canvasAspect||1,n=1,o=1,u=0,a=0;r>e?(n=r/e,u=(n-1)/2):(o=e/r,a=(o-1)/2),t.uvScale.x=n,t.uvScale.y=o,t.uvOffset.x=u,t.uvOffset.y=a}function L(){v();let e=i.getContext("webgl");if(!e){d.textContent="WebGL not supported in this browser.";return}t.gl=e;let r=`
1
+ "use strict";
2
+ (() => {
3
+ // src/home/depth.ts
4
+ var COLOR_URL = "https://cdn.prod.website-files.com/680cbbaefb50442c848aedf7/6926cf888059f91e69c286e7_IMG_0311.jpg";
5
+ var DEPTH_URL = "https://cdn.prod.website-files.com/680cbbaefb50442c848aedf7/6926cf7fd0f3c3f3276d1575_IMG_0310.png";
6
+ var DEPTH_SCALE = 0.01;
7
+ var MOUSE_SMOOTH = 0.9;
8
+ var IMAGE_SCALE = 0.9;
9
+ var state = {
10
+ gl: null,
11
+ program: null,
12
+ mousePos: { x: 0, y: 0 },
13
+ targetPos: { x: 0, y: 0 },
14
+ textures: { color: null, depth: null },
15
+ animationId: null,
16
+ isLoaded: false,
17
+ imageAspect: 1,
18
+ canvasAspect: 1,
19
+ uvScale: { x: 1, y: 1 },
20
+ uvOffset: { x: 0, y: 0 }
21
+ };
22
+ var wrapper = document.getElementById("viewer-wrapper");
23
+ var canvas = document.getElementById("viewer-canvas");
24
+ var statusEl = document.getElementById("status");
25
+ canvas.addEventListener("mousemove", (e) => {
26
+ const rect = canvas.getBoundingClientRect();
27
+ const x = ((e.clientX - rect.left) / rect.width - 0.5) * 2;
28
+ const y = -((e.clientY - rect.top) / rect.height - 0.5) * 2;
29
+ state.targetPos.x = x;
30
+ state.targetPos.y = y;
31
+ });
32
+ canvas.addEventListener("mouseleave", () => {
33
+ state.targetPos.x = 0;
34
+ state.targetPos.y = 0;
35
+ });
36
+ function updateCanvasSize() {
37
+ canvas.width = wrapper.clientWidth;
38
+ canvas.height = wrapper.clientHeight;
39
+ if (state.gl) {
40
+ state.gl.viewport(0, 0, canvas.width, canvas.height);
41
+ updateUvScale();
42
+ }
43
+ }
44
+ function updateUvScale() {
45
+ state.canvasAspect = canvas.width / canvas.height;
46
+ const ia = state.imageAspect || 1;
47
+ const ca = state.canvasAspect || 1;
48
+ let scaleX = 1;
49
+ let scaleY = 1;
50
+ let offsetX = 0;
51
+ let offsetY = 0;
52
+ if (ca > ia) {
53
+ scaleX = ca / ia;
54
+ offsetX = (scaleX - 1) / 2;
55
+ } else {
56
+ scaleY = ia / ca;
57
+ offsetY = (scaleY - 1) / 2;
58
+ }
59
+ state.uvScale.x = scaleX;
60
+ state.uvScale.y = scaleY;
61
+ state.uvOffset.x = offsetX;
62
+ state.uvOffset.y = offsetY;
63
+ }
64
+ function initWebGL() {
65
+ updateCanvasSize();
66
+ const gl = canvas.getContext("webgl");
67
+ if (!gl) {
68
+ statusEl.textContent = "WebGL not supported in this browser.";
69
+ return;
70
+ }
71
+ state.gl = gl;
72
+ const vertexShaderSource = `
2
73
  attribute vec2 a_position;
3
74
  attribute vec2 a_texCoord;
4
75
  varying vec2 v_texCoord;
@@ -6,7 +77,8 @@
6
77
  gl_Position = vec4(a_position, 0.0, 1.0);
7
78
  v_texCoord = a_texCoord;
8
79
  }
9
- `,n=`
80
+ `;
81
+ const fragmentShaderSource = `
10
82
  precision mediump float;
11
83
  uniform sampler2D u_colorTexture;
12
84
  uniform sampler2D u_depthTexture;
@@ -36,4 +108,172 @@
36
108
  gl_FragColor = texture2D(u_colorTexture, uv);
37
109
  }
38
110
  }
39
- `;function o(c,A,R){let f=c.createShader(R);return f?(c.shaderSource(f,A),c.compileShader(f),c.getShaderParameter(f,c.COMPILE_STATUS)?f:(console.error(c.getShaderInfoLog(f)),c.deleteShader(f),null)):null}let u=o(e,r,e.VERTEX_SHADER),a=o(e,n,e.FRAGMENT_SHADER);if(!u||!a)return;let s=e.createProgram();if(!s)return;if(e.attachShader(s,u),e.attachShader(s,a),e.linkProgram(s),!e.getProgramParameter(s,e.LINK_STATUS)){console.error(e.getProgramInfoLog(s)),d.textContent="Error linking WebGL program.";return}t.program=s;let m=e.createBuffer();if(!m)return;e.bindBuffer(e.ARRAY_BUFFER,m),e.bufferData(e.ARRAY_BUFFER,new Float32Array([-1,-1,1,-1,-1,1,-1,1,1,-1,1,1]),e.STATIC_DRAW);let l=e.createBuffer();l&&(e.bindBuffer(e.ARRAY_BUFFER,l),e.bufferData(e.ARRAY_BUFFER,new Float32Array([0,1,1,1,0,0,0,0,1,1,1,0]),e.STATIC_DRAW),t.positionBuffer=m,t.texCoordBuffer=l,b())}function _(e,r,n,o){let u=e.createTexture();if(!u)return null;e.bindTexture(e.TEXTURE_2D,u),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,1,1,0,e.RGBA,e.UNSIGNED_BYTE,new Uint8Array([0,0,0,255]));let a=new Image;return a.crossOrigin="anonymous",a.onload=()=>{o&&o(a),e.bindTexture(e.TEXTURE_2D,u),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,a),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),n()},a.onerror=()=>{d.textContent="Error loading image: "+r},a.src=r,u}function b(){let e=t.gl;if(!e)return;let r=0;function n(){r+=1,r===2&&e&&(e.viewport(0,0,i.width,i.height),t.isLoaded=!0,d.textContent="Move your mouse over the image to see the 3D parallax effect.",x())}t.textures.color=_(e,g,n,o=>{t.imageAspect=o.width/o.height,T()}),t.textures.depth=_(e,p,n)}function x(){if(!t.isLoaded)return;let e=t.gl,r=t.program;if(!e||!r)return;t.mousePos.x+=(t.targetPos.x-t.mousePos.x)*.9,t.mousePos.y+=(t.targetPos.y-t.mousePos.y)*.9,e.clearColor(0,0,0,1),e.clear(e.COLOR_BUFFER_BIT),e.useProgram(r);let n=e.getAttribLocation(r,"a_position");e.bindBuffer(e.ARRAY_BUFFER,t.positionBuffer),e.enableVertexAttribArray(n),e.vertexAttribPointer(n,2,e.FLOAT,!1,0,0);let o=e.getAttribLocation(r,"a_texCoord");e.bindBuffer(e.ARRAY_BUFFER,t.texCoordBuffer),e.enableVertexAttribArray(o),e.vertexAttribPointer(o,2,e.FLOAT,!1,0,0),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,t.textures.color),e.uniform1i(e.getUniformLocation(r,"u_colorTexture"),0),e.activeTexture(e.TEXTURE1),e.bindTexture(e.TEXTURE_2D,t.textures.depth),e.uniform1i(e.getUniformLocation(r,"u_depthTexture"),1),e.uniform2f(e.getUniformLocation(r,"u_mouse"),t.mousePos.x,t.mousePos.y),e.uniform1f(e.getUniformLocation(r,"u_scale"),.01),e.uniform2f(e.getUniformLocation(r,"u_uvScale"),t.uvScale.x,t.uvScale.y),e.uniform2f(e.getUniformLocation(r,"u_uvOffset"),t.uvOffset.x,t.uvOffset.y),e.uniform1f(e.getUniformLocation(r,"u_imageScale"),.9),e.drawArrays(e.TRIANGLES,0,6),t.animationId=requestAnimationFrame(x)}window.addEventListener("load",L);window.addEventListener("resize",()=>{t.gl&&v()});})();
111
+ `;
112
+ function compileShader(glContext, source, type) {
113
+ const shader = glContext.createShader(type);
114
+ if (!shader) return null;
115
+ glContext.shaderSource(shader, source);
116
+ glContext.compileShader(shader);
117
+ if (!glContext.getShaderParameter(shader, glContext.COMPILE_STATUS)) {
118
+ console.error(glContext.getShaderInfoLog(shader));
119
+ glContext.deleteShader(shader);
120
+ return null;
121
+ }
122
+ return shader;
123
+ }
124
+ const vertexShader = compileShader(gl, vertexShaderSource, gl.VERTEX_SHADER);
125
+ const fragmentShader = compileShader(gl, fragmentShaderSource, gl.FRAGMENT_SHADER);
126
+ if (!vertexShader || !fragmentShader) return;
127
+ const program = gl.createProgram();
128
+ if (!program) return;
129
+ gl.attachShader(program, vertexShader);
130
+ gl.attachShader(program, fragmentShader);
131
+ gl.linkProgram(program);
132
+ if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
133
+ console.error(gl.getProgramInfoLog(program));
134
+ statusEl.textContent = "Error linking WebGL program.";
135
+ return;
136
+ }
137
+ state.program = program;
138
+ const positionBuffer = gl.createBuffer();
139
+ if (!positionBuffer) return;
140
+ gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);
141
+ gl.bufferData(
142
+ gl.ARRAY_BUFFER,
143
+ new Float32Array([
144
+ -1,
145
+ -1,
146
+ 1,
147
+ -1,
148
+ -1,
149
+ 1,
150
+ -1,
151
+ 1,
152
+ 1,
153
+ -1,
154
+ 1,
155
+ 1
156
+ ]),
157
+ gl.STATIC_DRAW
158
+ );
159
+ const texCoordBuffer = gl.createBuffer();
160
+ if (!texCoordBuffer) return;
161
+ gl.bindBuffer(gl.ARRAY_BUFFER, texCoordBuffer);
162
+ gl.bufferData(
163
+ gl.ARRAY_BUFFER,
164
+ new Float32Array([
165
+ 0,
166
+ 1,
167
+ 1,
168
+ 1,
169
+ 0,
170
+ 0,
171
+ 0,
172
+ 0,
173
+ 1,
174
+ 1,
175
+ 1,
176
+ 0
177
+ ]),
178
+ gl.STATIC_DRAW
179
+ );
180
+ state.positionBuffer = positionBuffer;
181
+ state.texCoordBuffer = texCoordBuffer;
182
+ loadTextures();
183
+ }
184
+ function loadTexture(gl, url, onLoaded, onImageLoaded) {
185
+ const texture = gl.createTexture();
186
+ if (!texture) return null;
187
+ gl.bindTexture(gl.TEXTURE_2D, texture);
188
+ gl.texImage2D(
189
+ gl.TEXTURE_2D,
190
+ 0,
191
+ gl.RGBA,
192
+ 1,
193
+ 1,
194
+ 0,
195
+ gl.RGBA,
196
+ gl.UNSIGNED_BYTE,
197
+ new Uint8Array([0, 0, 0, 255])
198
+ );
199
+ const image = new Image();
200
+ image.crossOrigin = "anonymous";
201
+ image.onload = () => {
202
+ if (onImageLoaded) onImageLoaded(image);
203
+ gl.bindTexture(gl.TEXTURE_2D, texture);
204
+ gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
205
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
206
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
207
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
208
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
209
+ onLoaded();
210
+ };
211
+ image.onerror = () => {
212
+ statusEl.textContent = "Error loading image: " + url;
213
+ };
214
+ image.src = url;
215
+ return texture;
216
+ }
217
+ function loadTextures() {
218
+ const gl = state.gl;
219
+ if (!gl) return;
220
+ let loadedCount = 0;
221
+ function onLoaded() {
222
+ loadedCount += 1;
223
+ if (loadedCount === 2 && gl) {
224
+ gl.viewport(0, 0, canvas.width, canvas.height);
225
+ state.isLoaded = true;
226
+ statusEl.textContent = "Move your mouse over the image to see the 3D parallax effect.";
227
+ render();
228
+ }
229
+ }
230
+ state.textures.color = loadTexture(
231
+ gl,
232
+ COLOR_URL,
233
+ onLoaded,
234
+ (image) => {
235
+ state.imageAspect = image.width / image.height;
236
+ updateUvScale();
237
+ }
238
+ );
239
+ state.textures.depth = loadTexture(gl, DEPTH_URL, onLoaded);
240
+ }
241
+ function render() {
242
+ if (!state.isLoaded) return;
243
+ const gl = state.gl;
244
+ const program = state.program;
245
+ if (!gl || !program) return;
246
+ state.mousePos.x += (state.targetPos.x - state.mousePos.x) * MOUSE_SMOOTH;
247
+ state.mousePos.y += (state.targetPos.y - state.mousePos.y) * MOUSE_SMOOTH;
248
+ gl.clearColor(0, 0, 0, 1);
249
+ gl.clear(gl.COLOR_BUFFER_BIT);
250
+ gl.useProgram(program);
251
+ const positionLocation = gl.getAttribLocation(program, "a_position");
252
+ gl.bindBuffer(gl.ARRAY_BUFFER, state.positionBuffer);
253
+ gl.enableVertexAttribArray(positionLocation);
254
+ gl.vertexAttribPointer(positionLocation, 2, gl.FLOAT, false, 0, 0);
255
+ const texCoordLocation = gl.getAttribLocation(program, "a_texCoord");
256
+ gl.bindBuffer(gl.ARRAY_BUFFER, state.texCoordBuffer);
257
+ gl.enableVertexAttribArray(texCoordLocation);
258
+ gl.vertexAttribPointer(texCoordLocation, 2, gl.FLOAT, false, 0, 0);
259
+ gl.activeTexture(gl.TEXTURE0);
260
+ gl.bindTexture(gl.TEXTURE_2D, state.textures.color);
261
+ gl.uniform1i(gl.getUniformLocation(program, "u_colorTexture"), 0);
262
+ gl.activeTexture(gl.TEXTURE1);
263
+ gl.bindTexture(gl.TEXTURE_2D, state.textures.depth);
264
+ gl.uniform1i(gl.getUniformLocation(program, "u_depthTexture"), 1);
265
+ gl.uniform2f(gl.getUniformLocation(program, "u_mouse"), state.mousePos.x, state.mousePos.y);
266
+ gl.uniform1f(gl.getUniformLocation(program, "u_scale"), DEPTH_SCALE);
267
+ gl.uniform2f(gl.getUniformLocation(program, "u_uvScale"), state.uvScale.x, state.uvScale.y);
268
+ gl.uniform2f(gl.getUniformLocation(program, "u_uvOffset"), state.uvOffset.x, state.uvOffset.y);
269
+ gl.uniform1f(gl.getUniformLocation(program, "u_imageScale"), IMAGE_SCALE);
270
+ gl.drawArrays(gl.TRIANGLES, 0, 6);
271
+ state.animationId = requestAnimationFrame(render);
272
+ }
273
+ window.addEventListener("load", initWebGL);
274
+ window.addEventListener("resize", () => {
275
+ if (!state.gl) return;
276
+ updateCanvasSize();
277
+ });
278
+ })();
279
+ //# sourceMappingURL=depth.js.map