svelte-ag 1.1.8 → 1.1.10

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,7 +1,7 @@
1
1
  <script lang="ts">
2
2
  import { WebGlShader } from '../shader/index.js';
3
3
  import type { Vec2, Vec4 } from '../../utils/glsl.js';
4
- import fragment from './gradient.frag?raw';
4
+ // import fragment from './gradient.frag';
5
5
  import { cn } from '../../utils';
6
6
  import type { BitsPrimitiveDivAttributes } from 'bits-ui';
7
7
 
@@ -38,6 +38,51 @@
38
38
 
39
39
  return `radial-gradient(ellipse ${sizeX}% ${sizeY}% at ${posX}% ${posY}%, ${centerColorRgba}, ${edgeColorRgba})`;
40
40
  });
41
+
42
+ const fragment = `#version 300 es
43
+
44
+ precision highp float;
45
+
46
+ out vec4 fragColor;
47
+
48
+ uniform vec2 u_resolution;
49
+ uniform vec2 u_offset;
50
+
51
+ uniform vec2 u_centerPos;
52
+ uniform vec2 u_radius;
53
+ uniform float u_noise;
54
+ uniform vec4 u_centerColor;
55
+ uniform vec4 u_edgeColor;
56
+
57
+ // Pseudo-random number between 0 and 1 generator
58
+ float dither(vec2 pos) {
59
+ return fract(sin(dot(pos, vec2(12.9898, 78.233))) * 43758.5453);
60
+ }
61
+
62
+ void main() {
63
+ vec2 fragPos = gl_FragCoord.xy + u_offset;
64
+
65
+ vec2 centerPx = u_centerPos * u_resolution;
66
+ vec2 radiusPx = u_radius * u_resolution;
67
+
68
+ // Calculate distance from the center of the canvas
69
+ float d = distance(fragPos, u_resolution / 2.0);
70
+
71
+ // Calculate max distance from center to corner of the canvas
72
+ float maxDist = length(u_resolution / 2.0);
73
+ // float t = d / maxDist;
74
+
75
+ // compute “stretched” distance
76
+ vec2 diff = fragPos - centerPx;
77
+ vec2 norm = diff / radiusPx;
78
+ float t = length(norm);
79
+
80
+ // Dither strength (1/255 ~ 8-bit step size)
81
+ float noise = (dither(gl_FragCoord.xy) - 0.5) * (u_noise / 255.0);
82
+
83
+ fragColor = mix(u_centerColor, u_edgeColor, clamp(t + noise, 0.0, 1.0));
84
+ }
85
+ `;
41
86
  </script>
42
87
 
43
88
  <div class={cn('size-full', className)}>
@@ -1 +1 @@
1
- {"version":3,"file":"Gradient.svelte.d.ts","sourceRoot":"","sources":["../../../src/lib/components/gradient/Gradient.svelte.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAGjD,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,SAAS,CAAC;AAEzD,KAAK,gBAAgB,GAAI,0BAA0B,GAAG;IACnD,MAAM,EAAE,IAAI,CAAC;IACb,IAAI,EAAE,IAAI,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,IAAI,CAAC;IACjB,MAAM,CAAC,EAAE,IAAI,CAAC;CACf,CAAC;AAqDJ,QAAA,MAAM,QAAQ,sDAAwC,CAAC;AACvD,KAAK,QAAQ,GAAG,UAAU,CAAC,OAAO,QAAQ,CAAC,CAAC;AAC5C,eAAe,QAAQ,CAAC"}
1
+ {"version":3,"file":"Gradient.svelte.d.ts","sourceRoot":"","sources":["../../../src/lib/components/gradient/Gradient.svelte.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAGjD,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,SAAS,CAAC;AAEzD,KAAK,gBAAgB,GAAI,0BAA0B,GAAG;IACnD,MAAM,EAAE,IAAI,CAAC;IACb,IAAI,EAAE,IAAI,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,IAAI,CAAC;IACjB,MAAM,CAAC,EAAE,IAAI,CAAC;CACf,CAAC;AAkGJ,QAAA,MAAM,QAAQ,sDAAwC,CAAC;AACvD,KAAK,QAAQ,GAAG,UAAU,CAAC,OAAO,QAAQ,CAAC,CAAC;AAC5C,eAAe,QAAQ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte-ag",
3
- "version": "1.1.8",
3
+ "version": "1.1.10",
4
4
  "description": "Useful svelte components",
5
5
  "bugs": "https://github.com/ageorgeh/svelte-ag/issues",
6
6
  "repository": {
@@ -1,7 +1,7 @@
1
1
  <script lang="ts">
2
2
  import { WebGlShader } from '$components/shader/index.js';
3
3
  import type { Vec2, Vec4 } from '$utils/glsl.js';
4
- import fragment from './gradient.frag?raw';
4
+ // import fragment from './gradient.frag';
5
5
  import { cn } from '$utils';
6
6
  import type { BitsPrimitiveDivAttributes } from 'bits-ui';
7
7
 
@@ -38,6 +38,51 @@
38
38
 
39
39
  return `radial-gradient(ellipse ${sizeX}% ${sizeY}% at ${posX}% ${posY}%, ${centerColorRgba}, ${edgeColorRgba})`;
40
40
  });
41
+
42
+ const fragment = `#version 300 es
43
+
44
+ precision highp float;
45
+
46
+ out vec4 fragColor;
47
+
48
+ uniform vec2 u_resolution;
49
+ uniform vec2 u_offset;
50
+
51
+ uniform vec2 u_centerPos;
52
+ uniform vec2 u_radius;
53
+ uniform float u_noise;
54
+ uniform vec4 u_centerColor;
55
+ uniform vec4 u_edgeColor;
56
+
57
+ // Pseudo-random number between 0 and 1 generator
58
+ float dither(vec2 pos) {
59
+ return fract(sin(dot(pos, vec2(12.9898, 78.233))) * 43758.5453);
60
+ }
61
+
62
+ void main() {
63
+ vec2 fragPos = gl_FragCoord.xy + u_offset;
64
+
65
+ vec2 centerPx = u_centerPos * u_resolution;
66
+ vec2 radiusPx = u_radius * u_resolution;
67
+
68
+ // Calculate distance from the center of the canvas
69
+ float d = distance(fragPos, u_resolution / 2.0);
70
+
71
+ // Calculate max distance from center to corner of the canvas
72
+ float maxDist = length(u_resolution / 2.0);
73
+ // float t = d / maxDist;
74
+
75
+ // compute “stretched” distance
76
+ vec2 diff = fragPos - centerPx;
77
+ vec2 norm = diff / radiusPx;
78
+ float t = length(norm);
79
+
80
+ // Dither strength (1/255 ~ 8-bit step size)
81
+ float noise = (dither(gl_FragCoord.xy) - 0.5) * (u_noise / 255.0);
82
+
83
+ fragColor = mix(u_centerColor, u_edgeColor, clamp(t + noise, 0.0, 1.0));
84
+ }
85
+ `;
41
86
  </script>
42
87
 
43
88
  <div class={cn('size-full', className)}>