@cjlapao/ui-kit 0.2.35 → 0.2.36

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/dist/index.d.cts CHANGED
@@ -18,6 +18,8 @@ interface AiOrbAppearance {
18
18
  glow?: number;
19
19
  /** Ambient and audio-driven motion, from 0 to 1. */
20
20
  motionIntensity?: number;
21
+ /** Strength of automatic detail enhancement below 240 CSS pixels, from 0 to 1. */
22
+ definition?: number;
21
23
  }
22
24
  declare const AI_ORB_PRESETS: Record<AiOrbPreset, Required<AiOrbAppearance>>;
23
25
  declare const AI_ORB_QUALITY: {
package/dist/index.d.ts CHANGED
@@ -18,6 +18,8 @@ interface AiOrbAppearance {
18
18
  glow?: number;
19
19
  /** Ambient and audio-driven motion, from 0 to 1. */
20
20
  motionIntensity?: number;
21
+ /** Strength of automatic detail enhancement below 240 CSS pixels, from 0 to 1. */
22
+ definition?: number;
21
23
  }
22
24
  declare const AI_ORB_PRESETS: Record<AiOrbPreset, Required<AiOrbAppearance>>;
23
25
  declare const AI_ORB_QUALITY: {
package/dist/index.js CHANGED
@@ -7,9 +7,9 @@ import { memo, useEffect, useRef } from "react";
7
7
 
8
8
  // ../common/aiOrb/model.ts
9
9
  var AI_ORB_PRESETS = {
10
- solar: { coreColor: "#ffe9a8", accentColor: "#ff9b32", glowColor: "#ed5b16", glow: 0.7, motionIntensity: 0.75 },
11
- ion: { coreColor: "#e0fffa", accentColor: "#63e8dd", glowColor: "#158ca5", glow: 0.55, motionIntensity: 0.6 },
12
- ember: { coreColor: "#641b18", accentColor: "#ff7754", glowColor: "#ad2517", glow: 0.45, motionIntensity: 0.4 }
10
+ solar: { coreColor: "#ffe9a8", accentColor: "#ff9b32", glowColor: "#ed5b16", glow: 0.7, motionIntensity: 0.75, definition: 1 },
11
+ ion: { coreColor: "#e0fffa", accentColor: "#63e8dd", glowColor: "#158ca5", glow: 0.55, motionIntensity: 0.6, definition: 1 },
12
+ ember: { coreColor: "#641b18", accentColor: "#ff7754", glowColor: "#ad2517", glow: 0.45, motionIntensity: 0.4, definition: 1 }
13
13
  };
14
14
  var AI_ORB_QUALITY = {
15
15
  low: { fps: 24, dpr: 1, particles: 8, flares: 6, rings: 2 },
@@ -30,7 +30,8 @@ function resolveAppearance(preset, appearance) {
30
30
  accentColor: color2(appearance?.accentColor, base.accentColor),
31
31
  glowColor: color2(appearance?.glowColor, base.glowColor),
32
32
  glow: unit(appearance?.glow, base.glow),
33
- motionIntensity: unit(appearance?.motionIntensity, base.motionIntensity)
33
+ motionIntensity: unit(appearance?.motionIntensity, base.motionIntensity),
34
+ definition: unit(appearance?.definition, base.definition)
34
35
  };
35
36
  }
36
37
  function backingSize(cssSize, dpr, quality) {
@@ -48,6 +49,13 @@ function createOrbRenderer(canvas, options) {
48
49
  let listen = options.state === "listening" ? 1 : 0;
49
50
  let speak = options.state === "speaking" ? 1 : 0;
50
51
  let time = 0;
52
+ let cssSize = 240;
53
+ let compact2 = 0;
54
+ let pixel = 2;
55
+ const updateDefinition = () => {
56
+ compact2 = Math.max(0, Math.min(1, (240 - cssSize) / 176)) * colors3.definition;
57
+ pixel = 480 / cssSize;
58
+ };
51
59
  const core = document.createElement("canvas");
52
60
  const halo = document.createElement("canvas");
53
61
  core.width = core.height = 256;
@@ -86,9 +94,12 @@ function createOrbRenderer(canvas, options) {
86
94
  settings = next;
87
95
  colors3 = nextColors;
88
96
  budget = AI_ORB_QUALITY[next.quality];
97
+ updateDefinition();
89
98
  if (changed) textures();
90
99
  },
91
100
  resize(size, dpr) {
101
+ cssSize = Number.isFinite(size) && size > 0 ? size : 240;
102
+ updateDefinition();
92
103
  const pixels = backingSize(size, dpr, settings.quality);
93
104
  if (canvas.width !== pixels || canvas.height !== pixels) canvas.width = canvas.height = pixels;
94
105
  },
@@ -102,54 +113,57 @@ function createOrbRenderer(canvas, options) {
102
113
  const target = animated && settings.state !== "idle" ? audio?.sample() ?? 0 : 0;
103
114
  level += (target - level) * (animated ? Math.min(1, dt * 14) : 1);
104
115
  const energy = level * colors3.motionIntensity;
105
- const radius = 75 + Math.sin(time * 1.8) * 2 + energy * 12;
116
+ const radius = 75 + compact2 * 25 + Math.sin(time * 1.8) * (2 + compact2 * 3) + energy * (12 + compact2 * 10);
106
117
  ctx.setTransform(canvas.width / 480, 0, 0, canvas.height / 480, 0, 0);
107
118
  ctx.clearRect(0, 0, 480, 480);
108
- ctx.globalAlpha = colors3.glow * (0.65 + energy * 0.35);
119
+ ctx.globalAlpha = colors3.glow * (0.65 + energy * 0.35) * (1 - compact2 * 0.45);
109
120
  ctx.drawImage(halo, 0, 0);
110
121
  ctx.globalAlpha = 1;
111
122
  if (listen > 1e-3) {
112
- for (let ring = 0; ring < budget.rings; ring++) {
123
+ const rings = compact2 > 0.5 ? Math.min(2, budget.rings) : budget.rings;
124
+ for (let ring = 0; ring < rings; ring++) {
113
125
  ctx.beginPath();
114
126
  for (let i = 0; i <= 128; i++) {
115
127
  const angle = i / 128 * Math.PI * 2;
116
128
  const sample = animated ? audio?.waveform[i % 128] ?? 0 : 0;
117
- const wave = sample * Math.sin(angle / 2) * 40 * colors3.motionIntensity;
118
- const r = 112 + ring * 15 + wave + Math.sin(angle * 7 + time * 2 + ring) * 3 * colors3.motionIntensity;
129
+ const wave = sample * Math.sin(angle / 2) * (40 + compact2 * 28) * colors3.motionIntensity;
130
+ const r = 112 + compact2 * 25 + ring * (15 + compact2 * 8) + wave + Math.sin(angle * 7 + time * 2 + ring) * (3 + compact2 * 10) * colors3.motionIntensity;
119
131
  const x = 240 + Math.cos(angle) * r, y = 240 + Math.sin(angle) * r;
120
132
  if (i === 0) ctx.moveTo(x, y);
121
133
  else ctx.lineTo(x, y);
122
134
  }
123
135
  ctx.closePath();
124
136
  ctx.strokeStyle = colors3.accentColor;
125
- ctx.globalAlpha = listen * (0.65 - ring * 0.15);
126
- ctx.lineWidth = 1.4;
137
+ ctx.globalAlpha = listen * (0.65 + compact2 * 0.25 - ring * 0.15);
138
+ ctx.lineWidth = Math.max(1.4, pixel * compact2 * 1.25);
127
139
  ctx.stroke();
128
140
  }
129
141
  }
130
142
  if (speak > 1e-3) {
131
143
  ctx.strokeStyle = colors3.accentColor;
132
- for (let i = 0; i < budget.flares; i++) {
144
+ const flares = Math.max(6, Math.round(budget.flares * (1 - compact2 * 0.45)));
145
+ for (let i = 0; i < flares; i++) {
133
146
  const angle = seeds[i] + time * 0.07;
134
- const length = 10 + (Math.sin(time * 1.7 + seeds[i]) + 1) * 7 * colors3.motionIntensity + energy * 18;
147
+ const length = 10 + compact2 * 7 + (Math.sin(time * 1.7 + seeds[i]) + 1) * (7 + compact2 * 8) * colors3.motionIntensity + energy * 18;
135
148
  ctx.save();
136
149
  ctx.translate(240, 240);
137
150
  ctx.rotate(angle);
138
- ctx.globalAlpha = speak * (0.25 + colors3.glow * 0.4);
151
+ ctx.globalAlpha = speak * (0.25 + colors3.glow * 0.4 + compact2 * 0.3);
139
152
  ctx.beginPath();
140
- ctx.ellipse(radius + length * 0.45, 0, length, 4 + energy * 3, 0, 0, Math.PI * 2);
141
- ctx.lineWidth = 1.3;
153
+ ctx.ellipse(radius + length * 0.45, 0, length, 4 + compact2 * 5 + energy * 3, 0, 0, Math.PI * 2);
154
+ ctx.lineWidth = Math.max(1.3, pixel * compact2 * 1.15);
142
155
  ctx.stroke();
143
156
  ctx.restore();
144
157
  }
145
158
  ctx.fillStyle = colors3.coreColor;
146
- for (let i = 0; i < budget.particles; i++) {
159
+ const particles = Math.max(4, Math.round(budget.particles * (1 - compact2 * 0.5)));
160
+ for (let i = 0; i < particles; i++) {
147
161
  const phase = (time * 0.12 + i * 0.173) % 1;
148
162
  const angle = seeds[i] + time * 0.035;
149
163
  const r = radius + 22 + phase * 85;
150
- ctx.globalAlpha = speak * (1 - phase) * (0.3 + energy * 0.5);
164
+ ctx.globalAlpha = speak * (1 - phase) * (0.3 + energy * 0.5 + compact2 * 0.2);
151
165
  ctx.beginPath();
152
- ctx.arc(240 + Math.cos(angle) * r, 240 + Math.sin(angle) * r, 1 + i % 3 * 0.65, 0, Math.PI * 2);
166
+ ctx.arc(240 + Math.cos(angle) * r, 240 + Math.sin(angle) * r, Math.max(1 + i % 3 * 0.65, pixel * compact2 * (0.8 + i % 3 * 0.15)), 0, Math.PI * 2);
153
167
  ctx.fill();
154
168
  }
155
169
  }
@@ -160,11 +174,12 @@ function createOrbRenderer(canvas, options) {
160
174
  ctx.arc(240, 240, radius * 0.95, 0, Math.PI * 2);
161
175
  ctx.clip();
162
176
  ctx.strokeStyle = colors3.accentColor;
163
- for (let i = 0; i < 10; i++) {
164
- ctx.globalAlpha = 0.12 + speak * 0.07;
177
+ const surfaceLoops = compact2 > 0.5 ? 4 : 10;
178
+ for (let i = 0; i < surfaceLoops; i++) {
179
+ ctx.globalAlpha = 0.12 + speak * 0.07 + compact2 * 0.12;
165
180
  ctx.beginPath();
166
181
  ctx.ellipse(240 + Math.sin(seeds[i] + time * 0.16) * 54, 240 + Math.cos(seeds[i] * 2 + time * 0.1) * 54, 22 + i * 2, 8 + i % 4, seeds[i] + time * 0.1, 0, Math.PI * 2);
167
- ctx.lineWidth = 1;
182
+ ctx.lineWidth = Math.max(1, pixel * compact2 * 0.65);
168
183
  ctx.stroke();
169
184
  }
170
185
  ctx.restore();