@almadar/ui 5.42.0 → 5.44.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.
@@ -6,7 +6,7 @@ import { twMerge } from 'tailwind-merge';
6
6
  import { EventBusContext, useTraitScope, TraitScopeProvider } from '@almadar/ui/providers';
7
7
  import { createLogger, isLogLevelEnabled } from '@almadar/logger';
8
8
  import * as LucideIcons2 from 'lucide-react';
9
- import { Loader2, X, List, Printer, ChevronRight, ChevronLeft, CheckCircle, XCircle, Wrench, RotateCcw, Send, Play, Terminal, Search, ChevronUp, ChevronDown, MoreHorizontal, Bug, Package, Calendar, Pencil, Eye, Image as Image$1, Upload, ZoomIn, ArrowRight, Pause, SkipForward, TrendingUp, TrendingDown, Minus, AlertCircle, Circle, Clock, CheckCircle2, Code, FileText, WrapText, Check, Copy, HelpCircle, Type, Heading1, Heading2, Heading3, ListOrdered, Quote, GitBranch, Plus, Trash, ArrowLeft, Menu as Menu$1, AlertTriangle, Trash2, Eraser, ZoomOut, Download, Lightbulb, PauseCircle, Link2, Tag, User, DollarSign, Zap, Sword, Move, Heart, Shield } from 'lucide-react';
9
+ import { Loader2, X, List, Printer, ChevronRight, ChevronLeft, CheckCircle, XCircle, Wrench, RotateCcw, Send, Play, Terminal, Search, ChevronUp, ChevronDown, MoreHorizontal, Bug, Package, Calendar, Pencil, Eye, Image as Image$1, Upload, ZoomIn, ArrowRight, TrendingUp, TrendingDown, Minus, AlertCircle, Circle, Clock, CheckCircle2, Pause, SkipForward, Code, FileText, WrapText, Check, Copy, HelpCircle, Type, Heading1, Heading2, Heading3, ListOrdered, Quote, GitBranch, Plus, Trash, ArrowLeft, Menu as Menu$1, AlertTriangle, Trash2, Eraser, ZoomOut, Download, Lightbulb, PauseCircle, Link2, Tag, User, DollarSign, Zap, Sword, Move, Heart, Shield } from 'lucide-react';
10
10
  import { useTranslate } from '@almadar/ui/hooks';
11
11
  export * from '@almadar/ui/hooks';
12
12
  import { evaluate, createMinimalContext } from '@almadar/evaluator';
@@ -28789,6 +28789,78 @@ var init_GameOverScreen = __esm({
28789
28789
  GameOverScreen.displayName = "GameOverScreen";
28790
28790
  }
28791
28791
  });
28792
+ function useRenderInterpolation(options = {}) {
28793
+ const tickIntervalMs = options.tickIntervalMs ?? 1e3 / 30;
28794
+ const prevRef = useRef(null);
28795
+ const currRef = useRef(null);
28796
+ const rafRef = useRef(null);
28797
+ const onSnapshot = useCallback((entities) => {
28798
+ prevRef.current = currRef.current;
28799
+ currRef.current = { entities, arrivedAt: performance.now() };
28800
+ }, []);
28801
+ const getInterpolated = useCallback((now) => {
28802
+ const out = /* @__PURE__ */ new Map();
28803
+ const curr = currRef.current;
28804
+ if (!curr) return out;
28805
+ const prev = prevRef.current;
28806
+ if (!prev) {
28807
+ for (const e of curr.entities) out.set(e.id, { x: e.x, y: e.y });
28808
+ return out;
28809
+ }
28810
+ const rawAlpha = (now - curr.arrivedAt) / tickIntervalMs;
28811
+ const alpha = rawAlpha < 0 ? 0 : rawAlpha > 1 ? 1 : rawAlpha;
28812
+ const prevMap = /* @__PURE__ */ new Map();
28813
+ for (const e of prev.entities) prevMap.set(e.id, e);
28814
+ for (const c of curr.entities) {
28815
+ const p2 = prevMap.get(c.id);
28816
+ if (!p2) {
28817
+ out.set(c.id, { x: c.x, y: c.y });
28818
+ } else {
28819
+ out.set(c.id, {
28820
+ x: p2.x + (c.x - p2.x) * alpha,
28821
+ y: p2.y + (c.y - p2.y) * alpha
28822
+ });
28823
+ }
28824
+ }
28825
+ return out;
28826
+ }, [tickIntervalMs]);
28827
+ const startLoop = useCallback(
28828
+ (draw) => {
28829
+ let active = true;
28830
+ const loop = () => {
28831
+ if (!active) return;
28832
+ try {
28833
+ draw(getInterpolated(performance.now()));
28834
+ } catch {
28835
+ }
28836
+ rafRef.current = requestAnimationFrame(loop);
28837
+ };
28838
+ rafRef.current = requestAnimationFrame(loop);
28839
+ return () => {
28840
+ active = false;
28841
+ if (rafRef.current !== null) {
28842
+ cancelAnimationFrame(rafRef.current);
28843
+ rafRef.current = null;
28844
+ }
28845
+ };
28846
+ },
28847
+ [getInterpolated]
28848
+ );
28849
+ useEffect(() => {
28850
+ return () => {
28851
+ if (rafRef.current !== null) {
28852
+ cancelAnimationFrame(rafRef.current);
28853
+ rafRef.current = null;
28854
+ }
28855
+ };
28856
+ }, []);
28857
+ return { onSnapshot, getInterpolated, startLoop };
28858
+ }
28859
+ var init_useRenderInterpolation = __esm({
28860
+ "hooks/useRenderInterpolation.ts"() {
28861
+ "use client";
28862
+ }
28863
+ });
28792
28864
  function PlatformerCanvas({
28793
28865
  player,
28794
28866
  platforms = [
@@ -28857,8 +28929,43 @@ function PlatformerCanvas({
28857
28929
  y: 336,
28858
28930
  width: 32,
28859
28931
  height: 48,
28932
+ vx: 0,
28933
+ vy: 0,
28934
+ grounded: true,
28860
28935
  facingRight: true
28861
28936
  };
28937
+ const playerRef = useRef(resolvedPlayer);
28938
+ playerRef.current = resolvedPlayer;
28939
+ const interp = useRenderInterpolation();
28940
+ useEffect(() => {
28941
+ interp.onSnapshot([{ id: "player", x: resolvedPlayer.x, y: resolvedPlayer.y }]);
28942
+ }, [resolvedPlayer.x, resolvedPlayer.y]);
28943
+ const propsRef = useRef({
28944
+ platforms,
28945
+ worldWidth,
28946
+ worldHeight,
28947
+ canvasWidth,
28948
+ canvasHeight,
28949
+ followCamera,
28950
+ bgColor,
28951
+ playerSprite,
28952
+ tileSprites,
28953
+ backgroundImage,
28954
+ assetBaseUrl
28955
+ });
28956
+ propsRef.current = {
28957
+ platforms,
28958
+ worldWidth,
28959
+ worldHeight,
28960
+ canvasWidth,
28961
+ canvasHeight,
28962
+ followCamera,
28963
+ bgColor,
28964
+ playerSprite,
28965
+ tileSprites,
28966
+ backgroundImage,
28967
+ assetBaseUrl
28968
+ };
28862
28969
  const handleKeyDown = useCallback((e) => {
28863
28970
  if (keysRef.current.has(e.code)) return;
28864
28971
  keysRef.current.add(e.code);
@@ -28907,124 +29014,149 @@ function PlatformerCanvas({
28907
29014
  canvas.width = canvasWidth * dpr;
28908
29015
  canvas.height = canvasHeight * dpr;
28909
29016
  ctx.scale(dpr, dpr);
28910
- let camX = 0;
28911
- let camY = 0;
28912
- if (followCamera) {
28913
- camX = Math.max(0, Math.min(resolvedPlayer.x - canvasWidth / 2, worldWidth - canvasWidth));
28914
- camY = Math.max(0, Math.min(resolvedPlayer.y - canvasHeight / 2 - 50, worldHeight - canvasHeight));
28915
- }
28916
- const bgImg = backgroundImage ? loadImage(backgroundImage) : null;
28917
- if (bgImg) {
28918
- ctx.drawImage(bgImg, 0, 0, canvasWidth, canvasHeight);
28919
- } else if (bgColor) {
28920
- ctx.fillStyle = bgColor;
28921
- ctx.fillRect(0, 0, canvasWidth, canvasHeight);
28922
- } else {
28923
- const grad = ctx.createLinearGradient(0, 0, 0, canvasHeight);
28924
- grad.addColorStop(0, SKY_GRADIENT_TOP);
28925
- grad.addColorStop(1, SKY_GRADIENT_BOTTOM);
28926
- ctx.fillStyle = grad;
28927
- ctx.fillRect(0, 0, canvasWidth, canvasHeight);
28928
- }
28929
- ctx.strokeStyle = GRID_COLOR;
28930
- ctx.lineWidth = 1;
28931
- const gridSize = 32;
28932
- for (let gx = -camX % gridSize; gx < canvasWidth; gx += gridSize) {
28933
- ctx.beginPath();
28934
- ctx.moveTo(gx, 0);
28935
- ctx.lineTo(gx, canvasHeight);
28936
- ctx.stroke();
28937
- }
28938
- for (let gy = -camY % gridSize; gy < canvasHeight; gy += gridSize) {
28939
- ctx.beginPath();
28940
- ctx.moveTo(0, gy);
28941
- ctx.lineTo(canvasWidth, gy);
28942
- ctx.stroke();
28943
- }
28944
- for (const plat of platforms) {
28945
- const px = plat.x - camX;
28946
- const py = plat.y - camY;
28947
- const platType = plat.type ?? "ground";
28948
- const spriteUrl = tileSprites?.[platType];
28949
- const tileImg = spriteUrl ? loadImage(spriteUrl) : null;
28950
- if (tileImg) {
28951
- const tileW = tileImg.naturalWidth;
28952
- const tileH = tileImg.naturalHeight;
28953
- const scaleH = plat.height / tileH;
28954
- const scaledW = tileW * scaleH;
28955
- for (let tx = 0; tx < plat.width; tx += scaledW) {
28956
- const drawW = Math.min(scaledW, plat.width - tx);
28957
- const srcW = drawW / scaleH;
28958
- ctx.drawImage(tileImg, 0, 0, srcW, tileH, px + tx, py, drawW, plat.height);
28959
- }
29017
+ }, [canvasWidth, canvasHeight]);
29018
+ useEffect(() => {
29019
+ const drawFrame = (positions) => {
29020
+ const canvas = canvasRef.current;
29021
+ if (!canvas) return;
29022
+ const ctx = canvas.getContext("2d");
29023
+ if (!ctx) return;
29024
+ const {
29025
+ platforms: plats,
29026
+ worldWidth: ww,
29027
+ worldHeight: wh,
29028
+ canvasWidth: cw,
29029
+ canvasHeight: ch,
29030
+ followCamera: fc,
29031
+ bgColor: bg,
29032
+ playerSprite: pSprite,
29033
+ tileSprites: tSprites,
29034
+ backgroundImage: bgImg
29035
+ } = propsRef.current;
29036
+ const auth = playerRef.current;
29037
+ const interped = positions.get("player");
29038
+ const px = interped?.x ?? auth.x;
29039
+ const py = interped?.y ?? auth.y;
29040
+ let camX = 0;
29041
+ let camY = 0;
29042
+ if (fc) {
29043
+ camX = Math.max(0, Math.min(px - cw / 2, ww - cw));
29044
+ camY = Math.max(0, Math.min(py - ch / 2 - 50, wh - ch));
29045
+ }
29046
+ const bgImage = bgImg ? loadImage(bgImg) : null;
29047
+ if (bgImage) {
29048
+ ctx.drawImage(bgImage, 0, 0, cw, ch);
29049
+ } else if (bg) {
29050
+ ctx.fillStyle = bg;
29051
+ ctx.fillRect(0, 0, cw, ch);
28960
29052
  } else {
28961
- const color = PLATFORM_COLORS[platType] ?? PLATFORM_COLORS.ground;
28962
- ctx.fillStyle = color;
28963
- ctx.fillRect(px, py, plat.width, plat.height);
28964
- ctx.fillStyle = "rgba(255, 255, 255, 0.15)";
28965
- ctx.fillRect(px, py, plat.width, 3);
28966
- ctx.fillStyle = "rgba(0, 0, 0, 0.3)";
28967
- ctx.fillRect(px, py + plat.height - 2, plat.width, 2);
28968
- if (platType === "hazard") {
28969
- ctx.strokeStyle = "#e74c3c";
28970
- ctx.lineWidth = 2;
28971
- for (let sx = px; sx < px + plat.width; sx += 12) {
29053
+ const grad = ctx.createLinearGradient(0, 0, 0, ch);
29054
+ grad.addColorStop(0, SKY_GRADIENT_TOP);
29055
+ grad.addColorStop(1, SKY_GRADIENT_BOTTOM);
29056
+ ctx.fillStyle = grad;
29057
+ ctx.fillRect(0, 0, cw, ch);
29058
+ }
29059
+ ctx.strokeStyle = GRID_COLOR;
29060
+ ctx.lineWidth = 1;
29061
+ const gridSize = 32;
29062
+ for (let gx = -camX % gridSize; gx < cw; gx += gridSize) {
29063
+ ctx.beginPath();
29064
+ ctx.moveTo(gx, 0);
29065
+ ctx.lineTo(gx, ch);
29066
+ ctx.stroke();
29067
+ }
29068
+ for (let gy = -camY % gridSize; gy < ch; gy += gridSize) {
29069
+ ctx.beginPath();
29070
+ ctx.moveTo(0, gy);
29071
+ ctx.lineTo(cw, gy);
29072
+ ctx.stroke();
29073
+ }
29074
+ for (const plat of plats) {
29075
+ const platX = plat.x - camX;
29076
+ const platY = plat.y - camY;
29077
+ const platType = plat.type ?? "ground";
29078
+ const spriteUrl = tSprites?.[platType];
29079
+ const tileImg = spriteUrl ? loadImage(spriteUrl) : null;
29080
+ if (tileImg) {
29081
+ const tileW = tileImg.naturalWidth;
29082
+ const tileH = tileImg.naturalHeight;
29083
+ const scaleH = plat.height / tileH;
29084
+ const scaledW = tileW * scaleH;
29085
+ for (let tx = 0; tx < plat.width; tx += scaledW) {
29086
+ const drawW = Math.min(scaledW, plat.width - tx);
29087
+ const srcW = drawW / scaleH;
29088
+ ctx.drawImage(tileImg, 0, 0, srcW, tileH, platX + tx, platY, drawW, plat.height);
29089
+ }
29090
+ } else {
29091
+ const color = PLATFORM_COLORS[platType] ?? PLATFORM_COLORS.ground;
29092
+ ctx.fillStyle = color;
29093
+ ctx.fillRect(platX, platY, plat.width, plat.height);
29094
+ ctx.fillStyle = "rgba(255, 255, 255, 0.15)";
29095
+ ctx.fillRect(platX, platY, plat.width, 3);
29096
+ ctx.fillStyle = "rgba(0, 0, 0, 0.3)";
29097
+ ctx.fillRect(platX, platY + plat.height - 2, plat.width, 2);
29098
+ if (platType === "hazard") {
29099
+ ctx.strokeStyle = "#e74c3c";
29100
+ ctx.lineWidth = 2;
29101
+ for (let sx = platX; sx < platX + plat.width; sx += 12) {
29102
+ ctx.beginPath();
29103
+ ctx.moveTo(sx, platY);
29104
+ ctx.lineTo(sx + 6, platY + plat.height);
29105
+ ctx.stroke();
29106
+ }
29107
+ }
29108
+ if (platType === "goal") {
29109
+ ctx.fillStyle = "rgba(241, 196, 15, 0.5)";
28972
29110
  ctx.beginPath();
28973
- ctx.moveTo(sx, py);
28974
- ctx.lineTo(sx + 6, py + plat.height);
28975
- ctx.stroke();
29111
+ ctx.arc(platX + plat.width / 2, platY - 10, 8, 0, Math.PI * 2);
29112
+ ctx.fill();
28976
29113
  }
28977
29114
  }
28978
- if (platType === "goal") {
28979
- ctx.fillStyle = "rgba(241, 196, 15, 0.5)";
28980
- ctx.beginPath();
28981
- ctx.arc(px + plat.width / 2, py - 10, 8, 0, Math.PI * 2);
28982
- ctx.fill();
28983
- }
28984
29115
  }
28985
- }
28986
- const pw = resolvedPlayer.width ?? 24;
28987
- const ph = resolvedPlayer.height ?? 32;
28988
- const ppx = resolvedPlayer.x - camX;
28989
- const ppy = resolvedPlayer.y - camY;
28990
- const facingRight = resolvedPlayer.facingRight ?? true;
28991
- const playerImg = playerSprite ? loadImage(playerSprite) : null;
28992
- if (playerImg) {
28993
- ctx.save();
28994
- if (!facingRight) {
28995
- ctx.translate(ppx + pw, ppy);
28996
- ctx.scale(-1, 1);
28997
- ctx.drawImage(playerImg, 0, 0, pw, ph);
29116
+ const pw = auth.width ?? 24;
29117
+ const ph = auth.height ?? 32;
29118
+ const ppx = px - camX;
29119
+ const ppy = py - camY;
29120
+ const facingRight = auth.facingRight ?? true;
29121
+ const playerImg = pSprite ? loadImage(pSprite) : null;
29122
+ if (playerImg) {
29123
+ ctx.save();
29124
+ if (!facingRight) {
29125
+ ctx.translate(ppx + pw, ppy);
29126
+ ctx.scale(-1, 1);
29127
+ ctx.drawImage(playerImg, 0, 0, pw, ph);
29128
+ } else {
29129
+ ctx.drawImage(playerImg, ppx, ppy, pw, ph);
29130
+ }
29131
+ ctx.restore();
28998
29132
  } else {
28999
- ctx.drawImage(playerImg, ppx, ppy, pw, ph);
29133
+ ctx.fillStyle = PLAYER_COLOR;
29134
+ const radius = Math.min(pw, ph) * 0.25;
29135
+ ctx.beginPath();
29136
+ ctx.moveTo(ppx + radius, ppy);
29137
+ ctx.lineTo(ppx + pw - radius, ppy);
29138
+ ctx.quadraticCurveTo(ppx + pw, ppy, ppx + pw, ppy + radius);
29139
+ ctx.lineTo(ppx + pw, ppy + ph - radius);
29140
+ ctx.quadraticCurveTo(ppx + pw, ppy + ph, ppx + pw - radius, ppy + ph);
29141
+ ctx.lineTo(ppx + radius, ppy + ph);
29142
+ ctx.quadraticCurveTo(ppx, ppy + ph, ppx, ppy + ph - radius);
29143
+ ctx.lineTo(ppx, ppy + radius);
29144
+ ctx.quadraticCurveTo(ppx, ppy, ppx + radius, ppy);
29145
+ ctx.fill();
29146
+ const eyeY = ppy + ph * 0.3;
29147
+ const eyeSize = 3;
29148
+ const eyeOffsetX = facingRight ? pw * 0.55 : pw * 0.2;
29149
+ ctx.fillStyle = PLAYER_EYE_COLOR;
29150
+ ctx.beginPath();
29151
+ ctx.arc(ppx + eyeOffsetX, eyeY, eyeSize, 0, Math.PI * 2);
29152
+ ctx.fill();
29153
+ ctx.beginPath();
29154
+ ctx.arc(ppx + eyeOffsetX + 7, eyeY, eyeSize, 0, Math.PI * 2);
29155
+ ctx.fill();
29000
29156
  }
29001
- ctx.restore();
29002
- } else {
29003
- ctx.fillStyle = PLAYER_COLOR;
29004
- const radius = Math.min(pw, ph) * 0.25;
29005
- ctx.beginPath();
29006
- ctx.moveTo(ppx + radius, ppy);
29007
- ctx.lineTo(ppx + pw - radius, ppy);
29008
- ctx.quadraticCurveTo(ppx + pw, ppy, ppx + pw, ppy + radius);
29009
- ctx.lineTo(ppx + pw, ppy + ph - radius);
29010
- ctx.quadraticCurveTo(ppx + pw, ppy + ph, ppx + pw - radius, ppy + ph);
29011
- ctx.lineTo(ppx + radius, ppy + ph);
29012
- ctx.quadraticCurveTo(ppx, ppy + ph, ppx, ppy + ph - radius);
29013
- ctx.lineTo(ppx, ppy + radius);
29014
- ctx.quadraticCurveTo(ppx, ppy, ppx + radius, ppy);
29015
- ctx.fill();
29016
- const eyeY = ppy + ph * 0.3;
29017
- const eyeSize = 3;
29018
- const eyeOffsetX = facingRight ? pw * 0.55 : pw * 0.2;
29019
- ctx.fillStyle = PLAYER_EYE_COLOR;
29020
- ctx.beginPath();
29021
- ctx.arc(ppx + eyeOffsetX, eyeY, eyeSize, 0, Math.PI * 2);
29022
- ctx.fill();
29023
- ctx.beginPath();
29024
- ctx.arc(ppx + eyeOffsetX + 7, eyeY, eyeSize, 0, Math.PI * 2);
29025
- ctx.fill();
29026
- }
29027
- }, [player, platforms, worldWidth, worldHeight, canvasWidth, canvasHeight, followCamera, bgColor, playerSprite, tileSprites, backgroundImage, assetBaseUrl, loadedImages]);
29157
+ };
29158
+ return interp.startLoop(drawFrame);
29159
+ }, [interp.startLoop, loadImage]);
29028
29160
  return /* @__PURE__ */ jsx(
29029
29161
  "canvas",
29030
29162
  {
@@ -29042,6 +29174,7 @@ var init_PlatformerCanvas = __esm({
29042
29174
  init_cn();
29043
29175
  init_useEventBus();
29044
29176
  init_verificationRegistry();
29177
+ init_useRenderInterpolation();
29045
29178
  PLATFORM_COLORS = {
29046
29179
  ground: "#4a7c59",
29047
29180
  platform: "#7c6b4a",
@@ -29446,13 +29579,13 @@ var init_MapView = __esm({
29446
29579
  shadowSize: [41, 41]
29447
29580
  });
29448
29581
  L.Marker.prototype.options.icon = defaultIcon;
29449
- const { useEffect: useEffect73, useRef: useRef70, useCallback: useCallback113, useState: useState105 } = React77__default;
29582
+ const { useEffect: useEffect74, useRef: useRef71, useCallback: useCallback114, useState: useState105 } = React77__default;
29450
29583
  const { Typography: Typography2 } = await Promise.resolve().then(() => (init_Typography(), Typography_exports));
29451
29584
  const { useEventBus: useEventBus2 } = await Promise.resolve().then(() => (init_useEventBus(), useEventBus_exports));
29452
29585
  function MapUpdater({ centerLat, centerLng, zoom }) {
29453
29586
  const map = useMap();
29454
- const prevRef = useRef70({ centerLat, centerLng, zoom });
29455
- useEffect73(() => {
29587
+ const prevRef = useRef71({ centerLat, centerLng, zoom });
29588
+ useEffect74(() => {
29456
29589
  const prev = prevRef.current;
29457
29590
  if (prev.centerLat !== centerLat || prev.centerLng !== centerLng || prev.zoom !== zoom) {
29458
29591
  map.setView([centerLat, centerLng], zoom);
@@ -29463,7 +29596,7 @@ var init_MapView = __esm({
29463
29596
  }
29464
29597
  function MapClickHandler({ onMapClick }) {
29465
29598
  const map = useMap();
29466
- useEffect73(() => {
29599
+ useEffect74(() => {
29467
29600
  if (!onMapClick) return;
29468
29601
  const handler = (e) => {
29469
29602
  onMapClick(e.latlng.lat, e.latlng.lng);
@@ -29492,7 +29625,7 @@ var init_MapView = __esm({
29492
29625
  }) {
29493
29626
  const eventBus = useEventBus2();
29494
29627
  const [clickedPosition, setClickedPosition] = useState105(null);
29495
- const handleMapClick = useCallback113((lat, lng) => {
29628
+ const handleMapClick = useCallback114((lat, lng) => {
29496
29629
  if (showClickedPin) {
29497
29630
  setClickedPosition({ lat, lng });
29498
29631
  }
@@ -29501,7 +29634,7 @@ var init_MapView = __esm({
29501
29634
  eventBus.emit(`UI:${mapClickEvent}`, { latitude: lat, longitude: lng });
29502
29635
  }
29503
29636
  }, [onMapClick, mapClickEvent, eventBus, showClickedPin]);
29504
- const handleMarkerClick = useCallback113((marker) => {
29637
+ const handleMarkerClick = useCallback114((marker) => {
29505
29638
  onMarkerClick?.(marker);
29506
29639
  if (markerClickEvent) {
29507
29640
  eventBus.emit(`UI:${markerClickEvent}`, { ...marker });
@@ -45831,11 +45964,13 @@ function SimulationCanvas({
45831
45964
  height = 400,
45832
45965
  running,
45833
45966
  speed = 1,
45967
+ bodies: externalBodies,
45834
45968
  className
45835
45969
  }) {
45836
45970
  const preset = useMemo(() => resolvePreset(presetProp), [presetProp]);
45837
45971
  const canvasRef = useRef(null);
45838
45972
  const bodiesRef = useRef(structuredClone(preset.bodies));
45973
+ const interp = useRenderInterpolation();
45839
45974
  useEffect(() => {
45840
45975
  bodiesRef.current = structuredClone(preset.bodies);
45841
45976
  }, [preset]);
@@ -45933,6 +46068,67 @@ function SimulationCanvas({
45933
46068
  }
45934
46069
  }, [width, height, preset]);
45935
46070
  useEffect(() => {
46071
+ if (!externalBodies) return;
46072
+ interp.onSnapshot(externalBodies.map((b) => ({ id: b.id, x: b.x, y: b.y })));
46073
+ }, [externalBodies]);
46074
+ const presetRef = useRef(preset);
46075
+ presetRef.current = preset;
46076
+ const widthRef = useRef(width);
46077
+ widthRef.current = width;
46078
+ const heightRef = useRef(height);
46079
+ heightRef.current = height;
46080
+ useEffect(() => {
46081
+ if (!externalBodies) return;
46082
+ const drawInterpolated = (positions) => {
46083
+ const canvas = canvasRef.current;
46084
+ if (!canvas) return;
46085
+ const ctx = canvas.getContext("2d");
46086
+ if (!ctx) return;
46087
+ const bodies = bodiesRef.current;
46088
+ const p2 = presetRef.current;
46089
+ const w = widthRef.current;
46090
+ const h = heightRef.current;
46091
+ ctx.clearRect(0, 0, w, h);
46092
+ ctx.fillStyle = p2.backgroundColor ?? "#1a1a2e";
46093
+ ctx.fillRect(0, 0, w, h);
46094
+ if (p2.constraints) {
46095
+ for (const c of p2.constraints) {
46096
+ const a = bodies[c.bodyA];
46097
+ const b = bodies[c.bodyB];
46098
+ if (a && b) {
46099
+ const aPos = positions.get(a.id) ?? a;
46100
+ const bPos = positions.get(b.id) ?? b;
46101
+ ctx.beginPath();
46102
+ ctx.moveTo(aPos.x, aPos.y);
46103
+ ctx.lineTo(bPos.x, bPos.y);
46104
+ ctx.strokeStyle = "#533483";
46105
+ ctx.lineWidth = 1;
46106
+ ctx.setLineDash([4, 4]);
46107
+ ctx.stroke();
46108
+ ctx.setLineDash([]);
46109
+ }
46110
+ }
46111
+ }
46112
+ for (const body of bodies) {
46113
+ const pos = positions.get(body.id) ?? body;
46114
+ ctx.beginPath();
46115
+ ctx.arc(pos.x, pos.y, body.radius, 0, Math.PI * 2);
46116
+ ctx.fillStyle = body.color ?? "#e94560";
46117
+ ctx.fill();
46118
+ if (p2.showVelocity) {
46119
+ ctx.beginPath();
46120
+ ctx.moveTo(pos.x, pos.y);
46121
+ ctx.lineTo(pos.x + body.vx * 0.1, pos.y + body.vy * 0.1);
46122
+ ctx.strokeStyle = "#16213e";
46123
+ ctx.lineWidth = 2;
46124
+ ctx.stroke();
46125
+ }
46126
+ }
46127
+ };
46128
+ return interp.startLoop(drawInterpolated);
46129
+ }, [externalBodies !== void 0, interp.startLoop]);
46130
+ useEffect(() => {
46131
+ if (externalBodies !== void 0) return;
45936
46132
  if (!running) return;
45937
46133
  let raf;
45938
46134
  const loop = () => {
@@ -45942,10 +46138,11 @@ function SimulationCanvas({
45942
46138
  };
45943
46139
  raf = requestAnimationFrame(loop);
45944
46140
  return () => cancelAnimationFrame(raf);
45945
- }, [running, step, draw]);
46141
+ }, [running, step, draw, externalBodies]);
45946
46142
  useEffect(() => {
46143
+ if (externalBodies !== void 0) return;
45947
46144
  draw();
45948
- }, [draw]);
46145
+ }, [draw, externalBodies]);
45949
46146
  useEffect(() => {
45950
46147
  if (typeof window === "undefined") return;
45951
46148
  const canvas = canvasRef.current;
@@ -45971,136 +46168,10 @@ var init_SimulationCanvas = __esm({
45971
46168
  init_atoms2();
45972
46169
  init_verificationRegistry();
45973
46170
  init_presets();
46171
+ init_useRenderInterpolation();
45974
46172
  SimulationCanvas.displayName = "SimulationCanvas";
45975
46173
  }
45976
46174
  });
45977
- function SimulationControls({
45978
- running,
45979
- speed,
45980
- parameters,
45981
- onPlay,
45982
- onPause,
45983
- onStep,
45984
- onReset,
45985
- onSpeedChange,
45986
- onParameterChange,
45987
- className
45988
- }) {
45989
- return /* @__PURE__ */ jsxs(VStack, { gap: "md", className, children: [
45990
- /* @__PURE__ */ jsxs(HStack, { gap: "sm", align: "center", children: [
45991
- running ? /* @__PURE__ */ jsx(Button, { size: "sm", variant: "secondary", onClick: onPause, icon: Pause, children: "Pause" }) : /* @__PURE__ */ jsx(Button, { size: "sm", variant: "primary", onClick: onPlay, icon: Play, children: "Play" }),
45992
- /* @__PURE__ */ jsx(Button, { size: "sm", variant: "ghost", onClick: onStep, icon: SkipForward, disabled: running, children: "Step" }),
45993
- /* @__PURE__ */ jsx(Button, { size: "sm", variant: "ghost", onClick: onReset, icon: RotateCcw, children: "Reset" })
45994
- ] }),
45995
- /* @__PURE__ */ jsxs(VStack, { gap: "xs", children: [
45996
- /* @__PURE__ */ jsxs(Typography, { variant: "caption", color: "muted", children: [
45997
- "Speed: ",
45998
- speed.toFixed(1),
45999
- "x"
46000
- ] }),
46001
- /* @__PURE__ */ jsx(
46002
- "input",
46003
- {
46004
- type: "range",
46005
- min: 0.1,
46006
- max: 5,
46007
- step: 0.1,
46008
- value: speed,
46009
- onChange: (e) => onSpeedChange(parseFloat(e.target.value)),
46010
- className: "w-full"
46011
- }
46012
- )
46013
- ] }),
46014
- Object.entries(parameters).map(([name, param]) => /* @__PURE__ */ jsxs(VStack, { gap: "xs", children: [
46015
- /* @__PURE__ */ jsxs(Typography, { variant: "caption", color: "muted", children: [
46016
- param.label,
46017
- ": ",
46018
- param.value.toFixed(2)
46019
- ] }),
46020
- /* @__PURE__ */ jsx(
46021
- "input",
46022
- {
46023
- type: "range",
46024
- min: param.min,
46025
- max: param.max,
46026
- step: param.step,
46027
- value: param.value,
46028
- onChange: (e) => onParameterChange(name, parseFloat(e.target.value)),
46029
- className: "w-full"
46030
- }
46031
- )
46032
- ] }, name))
46033
- ] });
46034
- }
46035
- var init_SimulationControls = __esm({
46036
- "components/game/organisms/physics-sim/SimulationControls.tsx"() {
46037
- init_atoms2();
46038
- SimulationControls.displayName = "SimulationControls";
46039
- }
46040
- });
46041
- function SimulationGraph({
46042
- label,
46043
- unit,
46044
- data,
46045
- maxPoints = 200,
46046
- width = 300,
46047
- height = 120,
46048
- color = "#e94560",
46049
- className
46050
- }) {
46051
- const canvasRef = useRef(null);
46052
- const visibleData = data.slice(-maxPoints);
46053
- useEffect(() => {
46054
- const canvas = canvasRef.current;
46055
- if (!canvas || visibleData.length < 2) return;
46056
- const ctx = canvas.getContext("2d");
46057
- if (!ctx) return;
46058
- ctx.clearRect(0, 0, width, height);
46059
- ctx.fillStyle = "#0f0f23";
46060
- ctx.fillRect(0, 0, width, height);
46061
- ctx.strokeStyle = "#1a1a3e";
46062
- ctx.lineWidth = 0.5;
46063
- for (let i = 0; i < 5; i++) {
46064
- const y = height / 5 * i;
46065
- ctx.beginPath();
46066
- ctx.moveTo(0, y);
46067
- ctx.lineTo(width, y);
46068
- ctx.stroke();
46069
- }
46070
- let minVal = Infinity;
46071
- let maxVal = -Infinity;
46072
- for (const pt of visibleData) {
46073
- if (pt.value < minVal) minVal = pt.value;
46074
- if (pt.value > maxVal) maxVal = pt.value;
46075
- }
46076
- const range = maxVal - minVal || 1;
46077
- const pad = height * 0.1;
46078
- ctx.beginPath();
46079
- ctx.strokeStyle = color;
46080
- ctx.lineWidth = 2;
46081
- for (let i = 0; i < visibleData.length; i++) {
46082
- const x = i / (maxPoints - 1) * width;
46083
- const y = pad + (maxVal - visibleData[i].value) / range * (height - 2 * pad);
46084
- if (i === 0) ctx.moveTo(x, y);
46085
- else ctx.lineTo(x, y);
46086
- }
46087
- ctx.stroke();
46088
- const last = visibleData[visibleData.length - 1];
46089
- ctx.fillStyle = color;
46090
- ctx.font = "12px monospace";
46091
- ctx.fillText(`${last.value.toFixed(2)} ${unit}`, width - 80, 16);
46092
- }, [visibleData, width, height, color, unit, maxPoints]);
46093
- return /* @__PURE__ */ jsx(Card, { padding: "sm", className, children: /* @__PURE__ */ jsxs(VStack, { gap: "xs", children: [
46094
- /* @__PURE__ */ jsx(Typography, { variant: "caption", weight: "bold", children: label }),
46095
- /* @__PURE__ */ jsx("canvas", { ref: canvasRef, width, height, className: "rounded" })
46096
- ] }) });
46097
- }
46098
- var init_SimulationGraph = __esm({
46099
- "components/game/organisms/physics-sim/SimulationGraph.tsx"() {
46100
- init_atoms2();
46101
- SimulationGraph.displayName = "SimulationGraph";
46102
- }
46103
- });
46104
46175
  function SimulatorBoard({
46105
46176
  entity,
46106
46177
  completeEvent = "PUZZLE_COMPLETE",
@@ -48634,7 +48705,6 @@ var init_component_registry_generated = __esm({
48634
48705
  init_Navigation();
48635
48706
  init_NegotiatorBoard();
48636
48707
  init_NumberStepper();
48637
- init_ObjectRulePanel();
48638
48708
  init_OptionConstraintGroup();
48639
48709
  init_OrbitalVisualization();
48640
48710
  init_Overlay();
@@ -48665,7 +48735,6 @@ var init_component_registry_generated = __esm({
48665
48735
  init_ResourceBar();
48666
48736
  init_ResourceCounter();
48667
48737
  init_RichBlockEditor();
48668
- init_RuleEditor();
48669
48738
  init_RuntimeDebugger2();
48670
48739
  init_ScaledDiagram();
48671
48740
  init_ScoreBoard();
@@ -48685,8 +48754,6 @@ var init_component_registry_generated = __esm({
48685
48754
  init_SignaturePad();
48686
48755
  init_SimpleGrid();
48687
48756
  init_SimulationCanvas();
48688
- init_SimulationControls();
48689
- init_SimulationGraph();
48690
48757
  init_SimulatorBoard();
48691
48758
  init_Skeleton();
48692
48759
  init_SocialProof();
@@ -48704,7 +48771,6 @@ var init_component_registry_generated = __esm({
48704
48771
  init_StateArchitectBoard();
48705
48772
  init_StateIndicator();
48706
48773
  init_StateMachineView();
48707
- init_StateNode();
48708
48774
  init_StatsGrid();
48709
48775
  init_StatsOrganism();
48710
48776
  init_StatusDot();
@@ -48743,8 +48809,6 @@ var init_component_registry_generated = __esm({
48743
48809
  init_Tooltip();
48744
48810
  init_TraitFrame();
48745
48811
  init_TraitSlot();
48746
- init_TraitStateViewer();
48747
- init_TransitionArrow();
48748
48812
  init_TrendIndicator();
48749
48813
  init_TurnIndicator();
48750
48814
  init_TurnPanel();
@@ -48754,7 +48818,6 @@ var init_component_registry_generated = __esm({
48754
48818
  init_UncontrolledBattleBoard();
48755
48819
  init_UnitCommandBar();
48756
48820
  init_UploadDropZone();
48757
- init_VariablePanel();
48758
48821
  init_VersionDiff();
48759
48822
  init_ViolationAlert();
48760
48823
  init_VoteStack();
@@ -48964,7 +49027,6 @@ var init_component_registry_generated = __esm({
48964
49027
  "Navigation": Navigation,
48965
49028
  "NegotiatorBoard": NegotiatorBoard,
48966
49029
  "NumberStepper": NumberStepper,
48967
- "ObjectRulePanel": ObjectRulePanel,
48968
49030
  "OptionConstraintGroup": OptionConstraintGroup,
48969
49031
  "OrbitalVisualization": OrbitalVisualization,
48970
49032
  "Overlay": Overlay,
@@ -48995,7 +49057,6 @@ var init_component_registry_generated = __esm({
48995
49057
  "ResourceBar": ResourceBar,
48996
49058
  "ResourceCounter": ResourceCounter,
48997
49059
  "RichBlockEditor": RichBlockEditor,
48998
- "RuleEditor": RuleEditor,
48999
49060
  "RuntimeDebugger": RuntimeDebugger,
49000
49061
  "ScaledDiagram": ScaledDiagram,
49001
49062
  "ScoreBoard": ScoreBoard,
@@ -49015,8 +49076,6 @@ var init_component_registry_generated = __esm({
49015
49076
  "SignaturePad": SignaturePad,
49016
49077
  "SimpleGrid": SimpleGrid,
49017
49078
  "SimulationCanvas": SimulationCanvas,
49018
- "SimulationControls": SimulationControls,
49019
- "SimulationGraph": SimulationGraph,
49020
49079
  "SimulatorBoard": SimulatorBoard,
49021
49080
  "Skeleton": Skeleton,
49022
49081
  "SocialProof": SocialProof,
@@ -49037,7 +49096,6 @@ var init_component_registry_generated = __esm({
49037
49096
  "StateArchitectBoard": StateArchitectBoard,
49038
49097
  "StateIndicator": StateIndicator,
49039
49098
  "StateMachineView": StateMachineView,
49040
- "StateNode": StateNode2,
49041
49099
  "StatsGrid": StatsGrid,
49042
49100
  "StatsOrganism": StatsOrganism,
49043
49101
  "StatusDot": StatusDot,
@@ -49076,8 +49134,6 @@ var init_component_registry_generated = __esm({
49076
49134
  "Tooltip": Tooltip,
49077
49135
  "TraitFrame": TraitFrame,
49078
49136
  "TraitSlot": TraitSlot,
49079
- "TraitStateViewer": TraitStateViewer,
49080
- "TransitionArrow": TransitionArrow,
49081
49137
  "TrendIndicator": TrendIndicator,
49082
49138
  "TurnIndicator": TurnIndicator,
49083
49139
  "TurnPanel": TurnPanel,
@@ -49088,7 +49144,6 @@ var init_component_registry_generated = __esm({
49088
49144
  "UnitCommandBar": UnitCommandBar,
49089
49145
  "UploadDropZone": UploadDropZone,
49090
49146
  "VStack": VStack,
49091
- "VariablePanel": VariablePanel,
49092
49147
  "VersionDiff": VersionDiff,
49093
49148
  "ViolationAlert": ViolationAlert,
49094
49149
  "VoteStack": VoteStack,
@@ -50852,8 +50907,131 @@ init_NegotiatorBoard();
50852
50907
 
50853
50908
  // components/game/organisms/physics-sim/index.ts
50854
50909
  init_SimulationCanvas();
50855
- init_SimulationControls();
50856
- init_SimulationGraph();
50910
+
50911
+ // components/game/organisms/physics-sim/SimulationControls.tsx
50912
+ init_atoms2();
50913
+ function SimulationControls({
50914
+ running,
50915
+ speed,
50916
+ parameters,
50917
+ onPlay,
50918
+ onPause,
50919
+ onStep,
50920
+ onReset,
50921
+ onSpeedChange,
50922
+ onParameterChange,
50923
+ className
50924
+ }) {
50925
+ return /* @__PURE__ */ jsxs(VStack, { gap: "md", className, children: [
50926
+ /* @__PURE__ */ jsxs(HStack, { gap: "sm", align: "center", children: [
50927
+ running ? /* @__PURE__ */ jsx(Button, { size: "sm", variant: "secondary", onClick: onPause, icon: Pause, children: "Pause" }) : /* @__PURE__ */ jsx(Button, { size: "sm", variant: "primary", onClick: onPlay, icon: Play, children: "Play" }),
50928
+ /* @__PURE__ */ jsx(Button, { size: "sm", variant: "ghost", onClick: onStep, icon: SkipForward, disabled: running, children: "Step" }),
50929
+ /* @__PURE__ */ jsx(Button, { size: "sm", variant: "ghost", onClick: onReset, icon: RotateCcw, children: "Reset" })
50930
+ ] }),
50931
+ /* @__PURE__ */ jsxs(VStack, { gap: "xs", children: [
50932
+ /* @__PURE__ */ jsxs(Typography, { variant: "caption", color: "muted", children: [
50933
+ "Speed: ",
50934
+ speed.toFixed(1),
50935
+ "x"
50936
+ ] }),
50937
+ /* @__PURE__ */ jsx(
50938
+ "input",
50939
+ {
50940
+ type: "range",
50941
+ min: 0.1,
50942
+ max: 5,
50943
+ step: 0.1,
50944
+ value: speed,
50945
+ onChange: (e) => onSpeedChange(parseFloat(e.target.value)),
50946
+ className: "w-full"
50947
+ }
50948
+ )
50949
+ ] }),
50950
+ Object.entries(parameters).map(([name, param]) => /* @__PURE__ */ jsxs(VStack, { gap: "xs", children: [
50951
+ /* @__PURE__ */ jsxs(Typography, { variant: "caption", color: "muted", children: [
50952
+ param.label,
50953
+ ": ",
50954
+ param.value.toFixed(2)
50955
+ ] }),
50956
+ /* @__PURE__ */ jsx(
50957
+ "input",
50958
+ {
50959
+ type: "range",
50960
+ min: param.min,
50961
+ max: param.max,
50962
+ step: param.step,
50963
+ value: param.value,
50964
+ onChange: (e) => onParameterChange(name, parseFloat(e.target.value)),
50965
+ className: "w-full"
50966
+ }
50967
+ )
50968
+ ] }, name))
50969
+ ] });
50970
+ }
50971
+ SimulationControls.displayName = "SimulationControls";
50972
+
50973
+ // components/game/organisms/physics-sim/SimulationGraph.tsx
50974
+ init_atoms2();
50975
+ function SimulationGraph({
50976
+ label,
50977
+ unit,
50978
+ data,
50979
+ maxPoints = 200,
50980
+ width = 300,
50981
+ height = 120,
50982
+ color = "#e94560",
50983
+ className
50984
+ }) {
50985
+ const canvasRef = useRef(null);
50986
+ const visibleData = data.slice(-maxPoints);
50987
+ useEffect(() => {
50988
+ const canvas = canvasRef.current;
50989
+ if (!canvas || visibleData.length < 2) return;
50990
+ const ctx = canvas.getContext("2d");
50991
+ if (!ctx) return;
50992
+ ctx.clearRect(0, 0, width, height);
50993
+ ctx.fillStyle = "#0f0f23";
50994
+ ctx.fillRect(0, 0, width, height);
50995
+ ctx.strokeStyle = "#1a1a3e";
50996
+ ctx.lineWidth = 0.5;
50997
+ for (let i = 0; i < 5; i++) {
50998
+ const y = height / 5 * i;
50999
+ ctx.beginPath();
51000
+ ctx.moveTo(0, y);
51001
+ ctx.lineTo(width, y);
51002
+ ctx.stroke();
51003
+ }
51004
+ let minVal = Infinity;
51005
+ let maxVal = -Infinity;
51006
+ for (const pt of visibleData) {
51007
+ if (pt.value < minVal) minVal = pt.value;
51008
+ if (pt.value > maxVal) maxVal = pt.value;
51009
+ }
51010
+ const range = maxVal - minVal || 1;
51011
+ const pad = height * 0.1;
51012
+ ctx.beginPath();
51013
+ ctx.strokeStyle = color;
51014
+ ctx.lineWidth = 2;
51015
+ for (let i = 0; i < visibleData.length; i++) {
51016
+ const x = i / (maxPoints - 1) * width;
51017
+ const y = pad + (maxVal - visibleData[i].value) / range * (height - 2 * pad);
51018
+ if (i === 0) ctx.moveTo(x, y);
51019
+ else ctx.lineTo(x, y);
51020
+ }
51021
+ ctx.stroke();
51022
+ const last = visibleData[visibleData.length - 1];
51023
+ ctx.fillStyle = color;
51024
+ ctx.font = "12px monospace";
51025
+ ctx.fillText(`${last.value.toFixed(2)} ${unit}`, width - 80, 16);
51026
+ }, [visibleData, width, height, color, unit, maxPoints]);
51027
+ return /* @__PURE__ */ jsx(Card, { padding: "sm", className, children: /* @__PURE__ */ jsxs(VStack, { gap: "xs", children: [
51028
+ /* @__PURE__ */ jsx(Typography, { variant: "caption", weight: "bold", children: label }),
51029
+ /* @__PURE__ */ jsx("canvas", { ref: canvasRef, width, height, className: "rounded" })
51030
+ ] }) });
51031
+ }
51032
+ SimulationGraph.displayName = "SimulationGraph";
51033
+
51034
+ // components/game/organisms/physics-sim/index.ts
50857
51035
  init_presets();
50858
51036
 
50859
51037
  // components/game/organisms/types/game.ts