@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.cjs CHANGED
@@ -737,9 +737,9 @@ var import_react = require("react");
737
737
 
738
738
  // ../common/aiOrb/model.ts
739
739
  var AI_ORB_PRESETS = {
740
- solar: { coreColor: "#ffe9a8", accentColor: "#ff9b32", glowColor: "#ed5b16", glow: 0.7, motionIntensity: 0.75 },
741
- ion: { coreColor: "#e0fffa", accentColor: "#63e8dd", glowColor: "#158ca5", glow: 0.55, motionIntensity: 0.6 },
742
- ember: { coreColor: "#641b18", accentColor: "#ff7754", glowColor: "#ad2517", glow: 0.45, motionIntensity: 0.4 }
740
+ solar: { coreColor: "#ffe9a8", accentColor: "#ff9b32", glowColor: "#ed5b16", glow: 0.7, motionIntensity: 0.75, definition: 1 },
741
+ ion: { coreColor: "#e0fffa", accentColor: "#63e8dd", glowColor: "#158ca5", glow: 0.55, motionIntensity: 0.6, definition: 1 },
742
+ ember: { coreColor: "#641b18", accentColor: "#ff7754", glowColor: "#ad2517", glow: 0.45, motionIntensity: 0.4, definition: 1 }
743
743
  };
744
744
  var AI_ORB_QUALITY = {
745
745
  low: { fps: 24, dpr: 1, particles: 8, flares: 6, rings: 2 },
@@ -760,7 +760,8 @@ function resolveAppearance(preset, appearance) {
760
760
  accentColor: color2(appearance?.accentColor, base.accentColor),
761
761
  glowColor: color2(appearance?.glowColor, base.glowColor),
762
762
  glow: unit(appearance?.glow, base.glow),
763
- motionIntensity: unit(appearance?.motionIntensity, base.motionIntensity)
763
+ motionIntensity: unit(appearance?.motionIntensity, base.motionIntensity),
764
+ definition: unit(appearance?.definition, base.definition)
764
765
  };
765
766
  }
766
767
  function backingSize(cssSize, dpr, quality) {
@@ -778,6 +779,13 @@ function createOrbRenderer(canvas, options) {
778
779
  let listen = options.state === "listening" ? 1 : 0;
779
780
  let speak = options.state === "speaking" ? 1 : 0;
780
781
  let time = 0;
782
+ let cssSize = 240;
783
+ let compact2 = 0;
784
+ let pixel = 2;
785
+ const updateDefinition = () => {
786
+ compact2 = Math.max(0, Math.min(1, (240 - cssSize) / 176)) * colors3.definition;
787
+ pixel = 480 / cssSize;
788
+ };
781
789
  const core = document.createElement("canvas");
782
790
  const halo = document.createElement("canvas");
783
791
  core.width = core.height = 256;
@@ -816,9 +824,12 @@ function createOrbRenderer(canvas, options) {
816
824
  settings = next;
817
825
  colors3 = nextColors;
818
826
  budget = AI_ORB_QUALITY[next.quality];
827
+ updateDefinition();
819
828
  if (changed) textures();
820
829
  },
821
830
  resize(size, dpr) {
831
+ cssSize = Number.isFinite(size) && size > 0 ? size : 240;
832
+ updateDefinition();
822
833
  const pixels = backingSize(size, dpr, settings.quality);
823
834
  if (canvas.width !== pixels || canvas.height !== pixels) canvas.width = canvas.height = pixels;
824
835
  },
@@ -832,54 +843,57 @@ function createOrbRenderer(canvas, options) {
832
843
  const target = animated && settings.state !== "idle" ? audio?.sample() ?? 0 : 0;
833
844
  level += (target - level) * (animated ? Math.min(1, dt * 14) : 1);
834
845
  const energy = level * colors3.motionIntensity;
835
- const radius = 75 + Math.sin(time * 1.8) * 2 + energy * 12;
846
+ const radius = 75 + compact2 * 25 + Math.sin(time * 1.8) * (2 + compact2 * 3) + energy * (12 + compact2 * 10);
836
847
  ctx.setTransform(canvas.width / 480, 0, 0, canvas.height / 480, 0, 0);
837
848
  ctx.clearRect(0, 0, 480, 480);
838
- ctx.globalAlpha = colors3.glow * (0.65 + energy * 0.35);
849
+ ctx.globalAlpha = colors3.glow * (0.65 + energy * 0.35) * (1 - compact2 * 0.45);
839
850
  ctx.drawImage(halo, 0, 0);
840
851
  ctx.globalAlpha = 1;
841
852
  if (listen > 1e-3) {
842
- for (let ring = 0; ring < budget.rings; ring++) {
853
+ const rings = compact2 > 0.5 ? Math.min(2, budget.rings) : budget.rings;
854
+ for (let ring = 0; ring < rings; ring++) {
843
855
  ctx.beginPath();
844
856
  for (let i = 0; i <= 128; i++) {
845
857
  const angle = i / 128 * Math.PI * 2;
846
858
  const sample = animated ? audio?.waveform[i % 128] ?? 0 : 0;
847
- const wave = sample * Math.sin(angle / 2) * 40 * colors3.motionIntensity;
848
- const r = 112 + ring * 15 + wave + Math.sin(angle * 7 + time * 2 + ring) * 3 * colors3.motionIntensity;
859
+ const wave = sample * Math.sin(angle / 2) * (40 + compact2 * 28) * colors3.motionIntensity;
860
+ const r = 112 + compact2 * 25 + ring * (15 + compact2 * 8) + wave + Math.sin(angle * 7 + time * 2 + ring) * (3 + compact2 * 10) * colors3.motionIntensity;
849
861
  const x = 240 + Math.cos(angle) * r, y = 240 + Math.sin(angle) * r;
850
862
  if (i === 0) ctx.moveTo(x, y);
851
863
  else ctx.lineTo(x, y);
852
864
  }
853
865
  ctx.closePath();
854
866
  ctx.strokeStyle = colors3.accentColor;
855
- ctx.globalAlpha = listen * (0.65 - ring * 0.15);
856
- ctx.lineWidth = 1.4;
867
+ ctx.globalAlpha = listen * (0.65 + compact2 * 0.25 - ring * 0.15);
868
+ ctx.lineWidth = Math.max(1.4, pixel * compact2 * 1.25);
857
869
  ctx.stroke();
858
870
  }
859
871
  }
860
872
  if (speak > 1e-3) {
861
873
  ctx.strokeStyle = colors3.accentColor;
862
- for (let i = 0; i < budget.flares; i++) {
874
+ const flares = Math.max(6, Math.round(budget.flares * (1 - compact2 * 0.45)));
875
+ for (let i = 0; i < flares; i++) {
863
876
  const angle = seeds[i] + time * 0.07;
864
- const length = 10 + (Math.sin(time * 1.7 + seeds[i]) + 1) * 7 * colors3.motionIntensity + energy * 18;
877
+ const length = 10 + compact2 * 7 + (Math.sin(time * 1.7 + seeds[i]) + 1) * (7 + compact2 * 8) * colors3.motionIntensity + energy * 18;
865
878
  ctx.save();
866
879
  ctx.translate(240, 240);
867
880
  ctx.rotate(angle);
868
- ctx.globalAlpha = speak * (0.25 + colors3.glow * 0.4);
881
+ ctx.globalAlpha = speak * (0.25 + colors3.glow * 0.4 + compact2 * 0.3);
869
882
  ctx.beginPath();
870
- ctx.ellipse(radius + length * 0.45, 0, length, 4 + energy * 3, 0, 0, Math.PI * 2);
871
- ctx.lineWidth = 1.3;
883
+ ctx.ellipse(radius + length * 0.45, 0, length, 4 + compact2 * 5 + energy * 3, 0, 0, Math.PI * 2);
884
+ ctx.lineWidth = Math.max(1.3, pixel * compact2 * 1.15);
872
885
  ctx.stroke();
873
886
  ctx.restore();
874
887
  }
875
888
  ctx.fillStyle = colors3.coreColor;
876
- for (let i = 0; i < budget.particles; i++) {
889
+ const particles = Math.max(4, Math.round(budget.particles * (1 - compact2 * 0.5)));
890
+ for (let i = 0; i < particles; i++) {
877
891
  const phase = (time * 0.12 + i * 0.173) % 1;
878
892
  const angle = seeds[i] + time * 0.035;
879
893
  const r = radius + 22 + phase * 85;
880
- ctx.globalAlpha = speak * (1 - phase) * (0.3 + energy * 0.5);
894
+ ctx.globalAlpha = speak * (1 - phase) * (0.3 + energy * 0.5 + compact2 * 0.2);
881
895
  ctx.beginPath();
882
- ctx.arc(240 + Math.cos(angle) * r, 240 + Math.sin(angle) * r, 1 + i % 3 * 0.65, 0, Math.PI * 2);
896
+ 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);
883
897
  ctx.fill();
884
898
  }
885
899
  }
@@ -890,11 +904,12 @@ function createOrbRenderer(canvas, options) {
890
904
  ctx.arc(240, 240, radius * 0.95, 0, Math.PI * 2);
891
905
  ctx.clip();
892
906
  ctx.strokeStyle = colors3.accentColor;
893
- for (let i = 0; i < 10; i++) {
894
- ctx.globalAlpha = 0.12 + speak * 0.07;
907
+ const surfaceLoops = compact2 > 0.5 ? 4 : 10;
908
+ for (let i = 0; i < surfaceLoops; i++) {
909
+ ctx.globalAlpha = 0.12 + speak * 0.07 + compact2 * 0.12;
895
910
  ctx.beginPath();
896
911
  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);
897
- ctx.lineWidth = 1;
912
+ ctx.lineWidth = Math.max(1, pixel * compact2 * 0.65);
898
913
  ctx.stroke();
899
914
  }
900
915
  ctx.restore();