atharv-mandlavdiya 1.0.2 → 1.0.4

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.
@@ -9,3 +9,340 @@ const atharv_mandlavdiya = `
9
9
  export function atharvm() {
10
10
  console.log(atharv_mandlavdiya);
11
11
  }
12
+
13
+ const _svg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 650 200" width="650" height="200">
14
+ <defs>
15
+ <linearGradient id="pathGradient" x1="0%" y1="0%" x2="100%" y2="0%">
16
+ <stop offset="0%" stop-color="#404040" stop-opacity="1" />
17
+ <stop offset="100%" stop-color="#4ecdc4" stop-opacity="1" />
18
+ </linearGradient>
19
+ <filter id="noise" x="0" y="0" width="100%" height="100%">
20
+ <feTurbulence type="fractalNoise" baseFrequency="0.9" numOctaves="2" stitchTiles="stitch" result="n" />
21
+ <feColorMatrix in="n" type="saturate" values="0" />
22
+ </filter>
23
+ </defs>
24
+ <rect width="650" height="200" fill="#000" />
25
+ <rect width="650" height="200" filter="url(#noise)" opacity="0.15" style="mix-blend-mode:overlay" />
26
+ <path
27
+ d="M 73 100 C 140.5 62, 230.5 78, 298 40 C 320.5 38, 350.5 102, 373 100 C 283 80, 163 120, 73 100 C 122.5 62, 188.5 78, 238 40 C 251.5 56, 269.5 144, 283 160 C 337 140, 409 180, 463 160 C 346 122, 190 138, 73 100 C 172 98, 304 162, 403 160 C 340 122, 256 138, 193 100 C 301 80, 445 120, 553 100 C 409 80, 217 120, 73 100 C 136 98, 220 162, 283 160 C 256 122, 220 138, 193 100 C 278.5 62, 392.5 78, 478 40 C 442 20, 394 60, 358 40 C 272.5 38, 158.5 102, 73 100"
28
+ fill="none"
29
+ stroke="url(#pathGradient)"
30
+ stroke-width="3"
31
+ stroke-linecap="round"
32
+ stroke-linejoin="round"
33
+ pathLength="1000"
34
+ stroke-dasharray="1000"
35
+ >
36
+ <animate
37
+ attributeName="stroke-dashoffset"
38
+ values="1000;0;0;-1000"
39
+ keyTimes="0;0.6;0.85;1"
40
+ dur="6s"
41
+ repeatCount="indefinite"
42
+ />
43
+ </path>
44
+ </svg>`;
45
+
46
+ export function signature() {
47
+ return _svg;
48
+ }
49
+
50
+ export function sign() {
51
+ const PATH_D = "M 73 100 C 140.5 62, 230.5 78, 298 40 C 320.5 38, 350.5 102, 373 100 C 283 80, 163 120, 73 100 C 122.5 62, 188.5 78, 238 40 C 251.5 56, 269.5 144, 283 160 C 337 140, 409 180, 463 160 C 346 122, 190 138, 73 100 C 172 98, 304 162, 403 160 C 340 122, 256 138, 193 100 C 301 80, 445 120, 553 100 C 409 80, 217 120, 73 100 C 136 98, 220 162, 283 160 C 256 122, 220 138, 193 100 C 278.5 62, 392.5 78, 478 40 C 442 20, 394 60, 358 40 C 272.5 38, 158.5 102, 73 100";
52
+ const SVG_W = 650;
53
+ const SVG_H = 200;
54
+
55
+ return `<canvas id="am-sig-canvas" style="display:block;touch-action:pan-y;" width="1300" height="400"></canvas>
56
+ <script>
57
+ (function() {
58
+ var VERTEX_SHADER = \`
59
+ attribute vec2 aPosition;
60
+ attribute float aSize;
61
+ attribute float aAlpha;
62
+ uniform vec2 uResolution;
63
+ varying float vAlpha;
64
+ void main() {
65
+ vec2 clip = (aPosition / uResolution) * 2.0 - 1.0;
66
+ clip.y *= -1.0;
67
+ gl_Position = vec4(clip, 0.0, 1.0);
68
+ gl_PointSize = aSize;
69
+ vAlpha = aAlpha;
70
+ }
71
+ \`;
72
+
73
+ var FRAGMENT_SHADER = \`
74
+ precision mediump float;
75
+ varying float vAlpha;
76
+ void main() {
77
+ vec2 d = gl_PointCoord - 0.5;
78
+ float r = length(d) * 2.0;
79
+ if (r > 1.0) discard;
80
+ float a = (1.0 - smoothstep(0.55, 0.95, r)) * vAlpha;
81
+ gl_FragColor = vec4(1.0, 1.0, 1.0, a);
82
+ }
83
+ \`;
84
+
85
+ var canvas = document.getElementById('am-sig-canvas');
86
+ if (!canvas) return;
87
+
88
+ var gl = canvas.getContext('webgl', { premultipliedAlpha: false, alpha: true, antialias: true });
89
+ if (!gl) return;
90
+
91
+ var reduced = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
92
+
93
+ function compile(type, source) {
94
+ var s = gl.createShader(type);
95
+ gl.shaderSource(s, source);
96
+ gl.compileShader(s);
97
+ return s;
98
+ }
99
+
100
+ var program = gl.createProgram();
101
+ gl.attachShader(program, compile(gl.VERTEX_SHADER, VERTEX_SHADER));
102
+ gl.attachShader(program, compile(gl.FRAGMENT_SHADER, FRAGMENT_SHADER));
103
+ gl.linkProgram(program);
104
+ gl.useProgram(program);
105
+
106
+ var aPos = gl.getAttribLocation(program, 'aPosition');
107
+ var aSize = gl.getAttribLocation(program, 'aSize');
108
+ var aAlpha = gl.getAttribLocation(program, 'aAlpha');
109
+ var uRes = gl.getUniformLocation(program, 'uResolution');
110
+
111
+ var posBuf = gl.createBuffer();
112
+ var sizeBuf = gl.createBuffer();
113
+ var alphaBuf = gl.createBuffer();
114
+
115
+ gl.enable(gl.BLEND);
116
+ gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
117
+
118
+ var sampleScale = 2;
119
+ var svgW = ${SVG_W};
120
+ var svgH = ${SVG_H};
121
+ var rW = svgW * sampleScale;
122
+ var rH = svgH * sampleScale;
123
+
124
+ var svgBlob = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ' + svgW + ' ' + svgH + '" width="' + rW + '" height="' + rH + '">'
125
+ + '<path d="${PATH_D}" fill="none" stroke="white" stroke-width="6" stroke-linecap="round" stroke-linejoin="round"/>'
126
+ + '</svg>';
127
+
128
+ var svgUrl = 'data:image/svg+xml;charset=utf-8,' + encodeURIComponent(svgBlob);
129
+
130
+ var img = new Image();
131
+ img.onload = function() {
132
+ var PAD = 60;
133
+ var canvasW = rW + 2 * PAD;
134
+ var canvasH = rH + 2 * PAD;
135
+
136
+ var off = document.createElement('canvas');
137
+ off.width = rW;
138
+ off.height = rH;
139
+ var ctx = off.getContext('2d', { willReadFrequently: true });
140
+ ctx.drawImage(img, 0, 0, rW, rH);
141
+ var data = ctx.getImageData(0, 0, rW, rH).data;
142
+
143
+ var targets = [];
144
+ for (var y = 0; y < rH; y++) {
145
+ for (var x = 0; x < rW; x++) {
146
+ var a = data[(y * rW + x) * 4 + 3] || 0;
147
+ if (a > 64) targets.push({ x: x + 0.5, y: y + 0.5, a: a / 255 });
148
+ }
149
+ }
150
+
151
+ canvas.width = canvasW;
152
+ canvas.height = canvasH;
153
+ gl.viewport(0, 0, canvasW, canvasH);
154
+ gl.uniform2f(uRes, canvasW, canvasH);
155
+
156
+ var cx = canvasW / 2;
157
+ var cy = canvasH / 2;
158
+
159
+ var particles = targets.map(function(t) {
160
+ var tx = t.x + PAD;
161
+ var ty = t.y + PAD;
162
+ var angle = Math.random() * Math.PI * 2;
163
+ var dist = Math.max(canvasW, canvasH) * (0.55 + Math.random() * 0.6);
164
+ var delay = reduced ? 0 : (t.x / rW) * 0.48 + Math.random() * 0.24;
165
+ return {
166
+ tx: tx, ty: ty,
167
+ x: reduced ? tx : cx + Math.cos(angle) * dist,
168
+ y: reduced ? ty : cy + Math.sin(angle) * dist,
169
+ vx: 0, vy: 0,
170
+ delay: delay,
171
+ arrived: reduced,
172
+ size: 3.0 + Math.random() * 0.6,
173
+ baseAlpha: t.a,
174
+ phaseX: Math.random() * Math.PI * 2,
175
+ phaseY: Math.random() * Math.PI * 2
176
+ };
177
+ });
178
+
179
+ var N = particles.length;
180
+ var positions = new Float32Array(N * 2);
181
+ var alphas = new Float32Array(N);
182
+ var sizesArr = new Float32Array(N);
183
+ for (var i = 0; i < N; i++) sizesArr[i] = particles[i].size;
184
+
185
+ gl.bindBuffer(gl.ARRAY_BUFFER, sizeBuf);
186
+ gl.bufferData(gl.ARRAY_BUFFER, sizesArr, gl.STATIC_DRAW);
187
+ gl.enableVertexAttribArray(aSize);
188
+ gl.vertexAttribPointer(aSize, 1, gl.FLOAT, false, 0, 0);
189
+
190
+ gl.bindBuffer(gl.ARRAY_BUFFER, posBuf);
191
+ gl.bufferData(gl.ARRAY_BUFFER, positions, gl.DYNAMIC_DRAW);
192
+ gl.enableVertexAttribArray(aPos);
193
+ gl.vertexAttribPointer(aPos, 2, gl.FLOAT, false, 0, 0);
194
+
195
+ gl.bindBuffer(gl.ARRAY_BUFFER, alphaBuf);
196
+ gl.bufferData(gl.ARRAY_BUFFER, alphas, gl.DYNAMIC_DRAW);
197
+ gl.enableVertexAttribArray(aAlpha);
198
+ gl.vertexAttribPointer(aAlpha, 1, gl.FLOAT, false, 0, 0);
199
+
200
+ var k = 0.014;
201
+ var damp = 0.8;
202
+ var mr = 130;
203
+ var mForce = 5.5;
204
+ var driftAmp = 0.12;
205
+ var fadeDur = 0.48;
206
+ var revealBand = 140;
207
+ var arriveDist = 6;
208
+
209
+ function smoothstep(e0, e1, x) {
210
+ var t = Math.min(1, Math.max(0, (x - e0) / (e1 - e0)));
211
+ return t * t * (3 - 2 * t);
212
+ }
213
+
214
+ var mouse = { x: -1e6, y: -1e6, has: false };
215
+ var startTime = 0;
216
+ var rafId = null;
217
+ var rafScheduled = false;
218
+ var isVisible = true;
219
+
220
+ function step(elapsed) {
221
+ for (var i = 0; i < particles.length; i++) {
222
+ var p = particles[i];
223
+ var t = elapsed - p.delay;
224
+ if (t < 0) {
225
+ positions[i * 2] = -1e6;
226
+ positions[i * 2 + 1] = -1e6;
227
+ alphas[i] = 0;
228
+ continue;
229
+ }
230
+
231
+ var driftX = Math.sin(elapsed * 0.5 + p.tx * 0.006 + p.phaseX * 0.15) * driftAmp;
232
+ var driftY = Math.cos(elapsed * 0.42 + p.ty * 0.01 + p.phaseY * 0.15) * driftAmp;
233
+ var tgtX = p.tx + driftX;
234
+ var tgtY = p.ty + driftY;
235
+
236
+ var ax = (tgtX - p.x) * k;
237
+ var ay = (tgtY - p.y) * k;
238
+
239
+ if (!reduced && mouse.has) {
240
+ var dx = p.x - mouse.x;
241
+ var dy = p.y - mouse.y;
242
+ var d2 = dx * dx + dy * dy;
243
+ if (d2 < mr * mr && d2 > 0.5) {
244
+ var d = Math.sqrt(d2);
245
+ var falloff = 1 - d / mr;
246
+ var force = falloff * falloff * mForce;
247
+ ax += (dx / d) * force;
248
+ ay += (dy / d) * force;
249
+ }
250
+ }
251
+
252
+ p.vx = (p.vx + ax) * damp;
253
+ p.vy = (p.vy + ay) * damp;
254
+ p.x += p.vx;
255
+ p.y += p.vy;
256
+
257
+ positions[i * 2] = p.x;
258
+ positions[i * 2 + 1] = p.y;
259
+
260
+ var alpha = Math.min(1, t / fadeDur) * p.baseAlpha;
261
+ if (!p.arrived) {
262
+ var dxr = p.tx - p.x;
263
+ var dyr = p.ty - p.y;
264
+ var dist2 = dxr * dxr + dyr * dyr;
265
+ if (dist2 < arriveDist * arriveDist) {
266
+ p.arrived = true;
267
+ } else {
268
+ alpha *= 1 - smoothstep(arriveDist, revealBand, Math.sqrt(dist2));
269
+ }
270
+ }
271
+ alphas[i] = alpha;
272
+ }
273
+ }
274
+
275
+ var STEP_MS = 1000 / 60;
276
+ var lastNow = 0;
277
+ var accMs = 0;
278
+ var simMs = 0;
279
+
280
+ function render() {
281
+ rafScheduled = false;
282
+ if (!isVisible) return;
283
+
284
+ var now = performance.now();
285
+ if (startTime === 0) {
286
+ startTime = now;
287
+ lastNow = now - STEP_MS;
288
+ }
289
+
290
+ var frameDt = now - lastNow;
291
+ lastNow = now;
292
+ if (frameDt > 250) frameDt = STEP_MS;
293
+
294
+ accMs += frameDt;
295
+ if (accMs > STEP_MS * 5) accMs = STEP_MS * 5;
296
+
297
+ while (accMs >= STEP_MS) {
298
+ step(simMs / 1000);
299
+ simMs += STEP_MS;
300
+ accMs -= STEP_MS;
301
+ }
302
+
303
+ gl.clearColor(0, 0, 0, 0);
304
+ gl.clear(gl.COLOR_BUFFER_BIT);
305
+
306
+ gl.bindBuffer(gl.ARRAY_BUFFER, posBuf);
307
+ gl.bufferSubData(gl.ARRAY_BUFFER, 0, positions);
308
+
309
+ gl.bindBuffer(gl.ARRAY_BUFFER, alphaBuf);
310
+ gl.bufferSubData(gl.ARRAY_BUFFER, 0, alphas);
311
+
312
+ gl.drawArrays(gl.POINTS, 0, particles.length);
313
+
314
+ rafScheduled = true;
315
+ rafId = requestAnimationFrame(render);
316
+ }
317
+
318
+ var io = new IntersectionObserver(function(entries) {
319
+ entries.forEach(function(e) { isVisible = e.isIntersecting; });
320
+ if (isVisible && !rafScheduled) {
321
+ rafScheduled = true;
322
+ rafId = requestAnimationFrame(render);
323
+ }
324
+ }, { threshold: 0 });
325
+ io.observe(canvas);
326
+
327
+ rafScheduled = true;
328
+ rafId = requestAnimationFrame(render);
329
+
330
+ function setMouse(cx, cy) {
331
+ var rect = canvas.getBoundingClientRect();
332
+ if (!rect.width || !rect.height) return;
333
+ mouse.x = (cx - rect.left) * (canvas.width / rect.width);
334
+ mouse.y = (cy - rect.top) * (canvas.height / rect.height);
335
+ mouse.has = true;
336
+ }
337
+
338
+ window.addEventListener('mousemove', function(e) { setMouse(e.clientX, e.clientY); }, { passive: true });
339
+ canvas.addEventListener('touchmove', function(e) { var t = e.touches[0]; if (t) setMouse(t.clientX, t.clientY); }, { passive: true });
340
+ canvas.addEventListener('touchend', function() { mouse.has = false; }, { passive: true });
341
+ canvas.addEventListener('touchcancel', function() { mouse.has = false; }, { passive: true });
342
+ document.addEventListener('mouseleave', function() { mouse.has = false; });
343
+ };
344
+
345
+ img.src = svgUrl;
346
+ })();
347
+ </script>`;
348
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "atharv-mandlavdiya",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "Made With Love By Atharv Mandlavdiya",
5
5
  "type": "module",
6
6
  "main": "atharvmandlavdiya.js",