@actioneer/ads 0.3.1 → 0.5.0

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,203 +0,0 @@
1
- "use client";
2
- import { jsx as v } from "react/jsx-runtime";
3
- import * as g from "react";
4
- import { ReactShaderToy as y } from "./react-shader-toy.js";
5
- import { useAgentAudioVisualizerWave as w } from "../../hooks/agents-ui/use-agent-audio-visualizer-wave.js";
6
- import { cn as b } from "../../lib/cn.js";
7
- const p = [0.122, 0.835, 0.976], S = `
8
- const float TAU = 6.28318530718;
9
-
10
- // Noise for dithering
11
- vec2 randFibo(vec2 p) {
12
- p = fract(p * vec2(443.897, 441.423));
13
- p += dot(p, p.yx + 19.19);
14
- return fract((p.xx + p.yx) * p.xy);
15
- }
16
-
17
- // Luma for alpha
18
- float luma(vec3 color) {
19
- return dot(color, vec3(0.299, 0.587, 0.114));
20
- }
21
-
22
- // RGB to HSV
23
- vec3 rgb2hsv(vec3 c) {
24
- vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
25
- vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));
26
- vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));
27
- float d = q.x - min(q.w, q.y);
28
- float e = 1.0e-10;
29
- return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
30
- }
31
-
32
- // HSV to RGB
33
- vec3 hsv2rgb(vec3 c) {
34
- vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
35
- vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
36
- return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
37
- }
38
-
39
- // Bell curve function for attenuation from center with rounded top
40
- float bellCurve(float distanceFromCenter, float maxDistance) {
41
- float normalizedDistance = distanceFromCenter / maxDistance;
42
- // Use cosine with high power for smooth rounded top
43
- return pow(cos(normalizedDistance * (3.14159265359 / 4.0)), 16.0);
44
- }
45
-
46
- // Calculate the sine wave
47
- float oscilloscopeWave(float x, float centerX, float time) {
48
- float relativeX = x - centerX;
49
- float maxDistance = centerX;
50
- float distanceFromCenter = abs(relativeX);
51
-
52
- // Apply bell curve for amplitude attenuation
53
- float bell = bellCurve(distanceFromCenter, maxDistance);
54
-
55
- // Calculate wave with uniforms and bell curve attenuation
56
- float wave = sin(relativeX * uFrequency + time * uSpeed) * uAmplitude * bell;
57
-
58
- return wave;
59
- }
60
-
61
- void mainImage(out vec4 fragColor, in vec2 fragCoord) {
62
- vec2 uv = fragCoord / iResolution.xy;
63
- vec2 pos = uv - 0.5;
64
-
65
- // Calculate center and positions
66
- float centerX = 0.5;
67
- float centerY = 0.5;
68
- float x = uv.x;
69
- float y = uv.y;
70
-
71
- // Convert line width from pixels to UV space
72
- // Use the average of width and height to handle aspect ratio
73
- float pixelSize = 2.0 / (iResolution.x + iResolution.y);
74
- float lineWidthUV = uLineWidth * pixelSize;
75
- float smoothingUV = uSmoothing * pixelSize;
76
-
77
- // Find minimum distance to the wave by sampling nearby points
78
- // This gives us consistent line width without high-frequency artifacts
79
- const int NUM_SAMPLES = 50; // Must be const for GLSL loop
80
- float minDist = 1000.0;
81
- float sampleRange = 0.02; // Range to search for closest point
82
-
83
- for(int i = 0; i < NUM_SAMPLES; i++) {
84
- float offset = (float(i) / float(NUM_SAMPLES - 1) - 0.5) * sampleRange;
85
- float sampleX = x + offset;
86
- float waveY = centerY + oscilloscopeWave(sampleX, centerX, iTime);
87
-
88
- // Calculate distance from current pixel to this point on the wave
89
- vec2 wavePoint = vec2(sampleX, waveY);
90
- vec2 currentPoint = vec2(x, y);
91
- float dist = distance(currentPoint, wavePoint);
92
-
93
- minDist = min(minDist, dist);
94
- }
95
-
96
- // Solid line with smooth edges using minimum distance
97
- float line = smoothstep(lineWidthUV + smoothingUV, lineWidthUV - smoothingUV, minDist);
98
-
99
- vec3 color = uColor;
100
- if(abs(uColorShift) > 0.01) {
101
- // Keep the center 50% at base color, then ramp shift across outer 25% on each side.
102
- float centerBandHalfWidth = 0.2;
103
- float edgeBandWidth = 0.5;
104
- float distanceFromCenter = abs(x - centerX);
105
- float edgeFactor = clamp((distanceFromCenter - centerBandHalfWidth) / edgeBandWidth, 0.0, 1.0);
106
- vec3 hsv = rgb2hsv(color);
107
- // Hue shift is zero in the center band and strongest at far edges.
108
- hsv.x = fract(hsv.x + edgeFactor * uColorShift * 0.3);
109
- color = hsv2rgb(hsv);
110
- }
111
-
112
- // Apply line intensity
113
- color *= line;
114
-
115
- // Add dithering for smoother gradients
116
- // color += (randFibo(fragCoord).x - 0.5) / 255.0;
117
-
118
- // Calculate alpha based on line intensity
119
- float alpha = line * uMix;
120
-
121
- fragColor = vec4(color * uMix, alpha);
122
- }`;
123
- function m({
124
- speed: a = 10,
125
- color: t = p,
126
- colorShift: i = 0.05,
127
- mix: o = 1,
128
- amplitude: n = 0.02,
129
- frequency: r = 20,
130
- lineWidth: l = 2,
131
- blur: c = 0.5,
132
- reduced: s = !1,
133
- ref: f,
134
- className: u,
135
- ...d
136
- }) {
137
- return /* @__PURE__ */ v("div", { ref: f, className: u, ...d, children: /* @__PURE__ */ v(
138
- y,
139
- {
140
- fs: S,
141
- className: "size-full",
142
- devicePixelRatio: 1,
143
- paused: s || a === 0,
144
- uniforms: {
145
- uSpeed: { type: "1f", value: a },
146
- uAmplitude: { type: "1f", value: n },
147
- uFrequency: { type: "1f", value: r },
148
- uMix: { type: "1f", value: o },
149
- uLineWidth: { type: "1f", value: l },
150
- uSmoothing: { type: "1f", value: c },
151
- uColor: { type: "3fv", value: t },
152
- uColorShift: { type: "1f", value: i }
153
- },
154
- onError: (e) => {
155
- console.error("Shader error:", e);
156
- },
157
- onWarning: (e) => {
158
- console.warn("Shader warning:", e);
159
- }
160
- }
161
- ) });
162
- }
163
- m.displayName = "WaveShader";
164
- const C = g.forwardRef(function({
165
- state: t = "idle",
166
- volume: i = 0,
167
- reduced: o = !1,
168
- color: n = p,
169
- colorShift: r = 0.05,
170
- lineWidth: l = 1.5,
171
- blur: c = 0.5,
172
- className: s,
173
- ...f
174
- }, u) {
175
- const { speed: d, amplitude: e, frequency: h, opacity: x } = w({
176
- state: t,
177
- volume: i,
178
- reduced: o
179
- });
180
- return /* @__PURE__ */ v(
181
- m,
182
- {
183
- ref: u,
184
- "aria-hidden": !0,
185
- "data-state": t,
186
- speed: d,
187
- color: n,
188
- colorShift: r,
189
- mix: x,
190
- amplitude: e,
191
- frequency: h,
192
- lineWidth: l,
193
- blur: c,
194
- reduced: o,
195
- className: b("size-full", s),
196
- ...f
197
- }
198
- );
199
- });
200
- C.displayName = "AgentAudioVisualizerWave";
201
- export {
202
- C as AgentAudioVisualizerWave
203
- };
@@ -1,87 +0,0 @@
1
- import { default as React, ComponentPropsWithoutRef } from 'react';
2
- type Vector4<T = number> = [T, T, T, T];
3
- type Uniform = {
4
- type: string;
5
- value: number[] | number;
6
- };
7
- type Uniforms = Record<string, Uniform>;
8
- type TextureParams = {
9
- url: string;
10
- wrapS?: number;
11
- wrapT?: number;
12
- minFilter?: number;
13
- magFilter?: number;
14
- flipY?: number;
15
- };
16
- export interface ReactShaderToyProps {
17
- /** Fragment shader GLSL code. */
18
- fs: string;
19
- /** Vertex shader GLSL code. */
20
- vs?: string;
21
- /**
22
- * Textures to be passed to the shader. Textures need to be squared or will be
23
- * automatically resized.
24
- *
25
- * Options default to:
26
- *
27
- * ```js
28
- * {
29
- * minFilter: LinearMipMapLinearFilter,
30
- * magFilter: LinearFilter,
31
- * wrapS: RepeatWrapping,
32
- * wrapT: RepeatWrapping,
33
- * }
34
- * ```
35
- *
36
- * See [textures in the docs](https://rysana.com/docs/react-shaders#textures)
37
- * for details.
38
- */
39
- textures?: TextureParams[];
40
- /**
41
- * Custom uniforms to be passed to the shader.
42
- *
43
- * See [custom uniforms in the
44
- * docs](https://rysana.com/docs/react-shaders#custom-uniforms) for details.
45
- */
46
- uniforms?: Uniforms;
47
- /**
48
- * Color used when clearing the canvas.
49
- *
50
- * See [the WebGL
51
- * docs](https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/clearColor)
52
- * for details.
53
- */
54
- clearColor?: Vector4;
55
- /**
56
- * GLSL precision qualifier. Defaults to `'highp'`. Balance between
57
- * performance and quality.
58
- */
59
- precision?: 'highp' | 'lowp' | 'mediump';
60
- /** Custom inline style for canvas. */
61
- style?: React.CSSProperties;
62
- /** Customize WebGL context attributes. See [the WebGL docs](https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/getContextAttributes) for details. */
63
- contextAttributes?: Record<string, unknown>;
64
- /** Lerp value for `iMouse` built-in uniform. Must be between 0 and 1. */
65
- lerp?: number;
66
- /** Device pixel ratio. */
67
- devicePixelRatio?: number;
68
- /**
69
- * Callback for when the textures are done loading. Useful if you want to do
70
- * something like e.g. hide the canvas until textures are done loading.
71
- */
72
- onDoneLoadingTextures?: () => void;
73
- /** Custom callback to handle errors. Defaults to `console.error`. */
74
- onError?: (error: string) => void;
75
- /** Custom callback to handle warnings. Defaults to `console.warn`. */
76
- onWarning?: (warning: string) => void;
77
- /**
78
- * When true, the animation loop runs even when the canvas is not visible in the viewport.
79
- * When false (default), animation runs only while visible (uses Intersection Observer),
80
- * reducing CPU/GPU usage when the shader is off-screen.
81
- */
82
- animateWhenNotVisible?: boolean;
83
- /** Draw the current frame but freeze shader time until resumed. */
84
- paused?: boolean;
85
- }
86
- export declare function ReactShaderToy({ fs, vs, textures, uniforms: propUniforms, clearColor, precision, style, contextAttributes, lerp, devicePixelRatio, onDoneLoadingTextures, onError, onWarning, animateWhenNotVisible, paused, ...canvasProps }: ReactShaderToyProps & ComponentPropsWithoutRef<'canvas'>): React.JSX.Element;
87
- export {};