@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.
- package/dist/avl/index.cjs +318 -263
- package/dist/avl/index.js +319 -264
- package/dist/components/game/molecules/three/index.cjs +128 -17
- package/dist/components/game/molecules/three/index.js +128 -17
- package/dist/components/game/organisms/physics-sim/SimulationCanvas.d.ts +8 -2
- package/dist/components/game/templates/GameCanvas3DBattleTemplate.d.ts +8 -1
- package/dist/components/game/templates/GameCanvas3DCastleTemplate.d.ts +8 -1
- package/dist/components/game/templates/GameCanvas3DWorldMapTemplate.d.ts +8 -1
- package/dist/components/index.cjs +442 -264
- package/dist/components/index.js +443 -265
- package/dist/hooks/index.cjs +68 -0
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/index.js +68 -1
- package/dist/hooks/useRenderInterpolation.d.ts +33 -0
- package/dist/providers/index.cjs +318 -263
- package/dist/providers/index.js +319 -264
- package/dist/runtime/index.cjs +318 -263
- package/dist/runtime/index.js +319 -264
- package/package.json +1 -1
package/dist/hooks/index.cjs
CHANGED
|
@@ -2504,6 +2504,73 @@ function useDropZone({ accepts, onDrop, disabled = false }) {
|
|
|
2504
2504
|
);
|
|
2505
2505
|
return { dropProps, isOver };
|
|
2506
2506
|
}
|
|
2507
|
+
function useRenderInterpolation(options = {}) {
|
|
2508
|
+
const tickIntervalMs = options.tickIntervalMs ?? 1e3 / 30;
|
|
2509
|
+
const prevRef = react.useRef(null);
|
|
2510
|
+
const currRef = react.useRef(null);
|
|
2511
|
+
const rafRef = react.useRef(null);
|
|
2512
|
+
const onSnapshot = react.useCallback((entities2) => {
|
|
2513
|
+
prevRef.current = currRef.current;
|
|
2514
|
+
currRef.current = { entities: entities2, arrivedAt: performance.now() };
|
|
2515
|
+
}, []);
|
|
2516
|
+
const getInterpolated = react.useCallback((now) => {
|
|
2517
|
+
const out = /* @__PURE__ */ new Map();
|
|
2518
|
+
const curr = currRef.current;
|
|
2519
|
+
if (!curr) return out;
|
|
2520
|
+
const prev = prevRef.current;
|
|
2521
|
+
if (!prev) {
|
|
2522
|
+
for (const e of curr.entities) out.set(e.id, { x: e.x, y: e.y });
|
|
2523
|
+
return out;
|
|
2524
|
+
}
|
|
2525
|
+
const rawAlpha = (now - curr.arrivedAt) / tickIntervalMs;
|
|
2526
|
+
const alpha = rawAlpha < 0 ? 0 : rawAlpha > 1 ? 1 : rawAlpha;
|
|
2527
|
+
const prevMap = /* @__PURE__ */ new Map();
|
|
2528
|
+
for (const e of prev.entities) prevMap.set(e.id, e);
|
|
2529
|
+
for (const c of curr.entities) {
|
|
2530
|
+
const p = prevMap.get(c.id);
|
|
2531
|
+
if (!p) {
|
|
2532
|
+
out.set(c.id, { x: c.x, y: c.y });
|
|
2533
|
+
} else {
|
|
2534
|
+
out.set(c.id, {
|
|
2535
|
+
x: p.x + (c.x - p.x) * alpha,
|
|
2536
|
+
y: p.y + (c.y - p.y) * alpha
|
|
2537
|
+
});
|
|
2538
|
+
}
|
|
2539
|
+
}
|
|
2540
|
+
return out;
|
|
2541
|
+
}, [tickIntervalMs]);
|
|
2542
|
+
const startLoop = react.useCallback(
|
|
2543
|
+
(draw) => {
|
|
2544
|
+
let active = true;
|
|
2545
|
+
const loop = () => {
|
|
2546
|
+
if (!active) return;
|
|
2547
|
+
try {
|
|
2548
|
+
draw(getInterpolated(performance.now()));
|
|
2549
|
+
} catch {
|
|
2550
|
+
}
|
|
2551
|
+
rafRef.current = requestAnimationFrame(loop);
|
|
2552
|
+
};
|
|
2553
|
+
rafRef.current = requestAnimationFrame(loop);
|
|
2554
|
+
return () => {
|
|
2555
|
+
active = false;
|
|
2556
|
+
if (rafRef.current !== null) {
|
|
2557
|
+
cancelAnimationFrame(rafRef.current);
|
|
2558
|
+
rafRef.current = null;
|
|
2559
|
+
}
|
|
2560
|
+
};
|
|
2561
|
+
},
|
|
2562
|
+
[getInterpolated]
|
|
2563
|
+
);
|
|
2564
|
+
react.useEffect(() => {
|
|
2565
|
+
return () => {
|
|
2566
|
+
if (rafRef.current !== null) {
|
|
2567
|
+
cancelAnimationFrame(rafRef.current);
|
|
2568
|
+
rafRef.current = null;
|
|
2569
|
+
}
|
|
2570
|
+
};
|
|
2571
|
+
}, []);
|
|
2572
|
+
return { onSnapshot, getInterpolated, startLoop };
|
|
2573
|
+
}
|
|
2507
2574
|
var API_BASE = typeof process !== "undefined" && process.env?.VITE_API_URL ? process.env.VITE_API_URL : "http://localhost:3000";
|
|
2508
2575
|
function getUserId() {
|
|
2509
2576
|
return localStorage.getItem("userId") || "anonymous";
|
|
@@ -2626,6 +2693,7 @@ exports.usePlayer = usePlayer;
|
|
|
2626
2693
|
exports.usePreview = usePreview;
|
|
2627
2694
|
exports.usePullToRefresh = usePullToRefresh;
|
|
2628
2695
|
exports.useQuerySingleton = useQuerySingleton;
|
|
2696
|
+
exports.useRenderInterpolation = useRenderInterpolation;
|
|
2629
2697
|
exports.useSingletonEntity = useSingletonEntity;
|
|
2630
2698
|
exports.useSwipeGesture = useSwipeGesture;
|
|
2631
2699
|
exports.useTraitListens = useTraitListens;
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -26,4 +26,5 @@ export { usePullToRefresh, type PullToRefreshOptions, type PullToRefreshResult,
|
|
|
26
26
|
export { usePinchZoom, type PinchZoomOptions, type PinchZoomResult, } from './usePinchZoom';
|
|
27
27
|
export { useDraggable, ALMADAR_DND_MIME, type DraggablePayload, type UseDraggableOptions, type UseDraggableResult, } from './useDraggable';
|
|
28
28
|
export { useDropZone, type UseDropZoneOptions, type UseDropZoneResult, } from './useDropZone';
|
|
29
|
+
export { useRenderInterpolation, type Positioned, type RenderInterpolationOptions, type RenderInterpolationHandle, } from './useRenderInterpolation';
|
|
29
30
|
export { useGitHubStatus, useConnectGitHub, useDisconnectGitHub, useGitHubRepos, useGitHubRepo, useGitHubBranches, type GitHubStatus, type GitHubRepo, } from './useGitHub';
|
package/dist/hooks/index.js
CHANGED
|
@@ -2502,6 +2502,73 @@ function useDropZone({ accepts, onDrop, disabled = false }) {
|
|
|
2502
2502
|
);
|
|
2503
2503
|
return { dropProps, isOver };
|
|
2504
2504
|
}
|
|
2505
|
+
function useRenderInterpolation(options = {}) {
|
|
2506
|
+
const tickIntervalMs = options.tickIntervalMs ?? 1e3 / 30;
|
|
2507
|
+
const prevRef = useRef(null);
|
|
2508
|
+
const currRef = useRef(null);
|
|
2509
|
+
const rafRef = useRef(null);
|
|
2510
|
+
const onSnapshot = useCallback((entities2) => {
|
|
2511
|
+
prevRef.current = currRef.current;
|
|
2512
|
+
currRef.current = { entities: entities2, arrivedAt: performance.now() };
|
|
2513
|
+
}, []);
|
|
2514
|
+
const getInterpolated = useCallback((now) => {
|
|
2515
|
+
const out = /* @__PURE__ */ new Map();
|
|
2516
|
+
const curr = currRef.current;
|
|
2517
|
+
if (!curr) return out;
|
|
2518
|
+
const prev = prevRef.current;
|
|
2519
|
+
if (!prev) {
|
|
2520
|
+
for (const e of curr.entities) out.set(e.id, { x: e.x, y: e.y });
|
|
2521
|
+
return out;
|
|
2522
|
+
}
|
|
2523
|
+
const rawAlpha = (now - curr.arrivedAt) / tickIntervalMs;
|
|
2524
|
+
const alpha = rawAlpha < 0 ? 0 : rawAlpha > 1 ? 1 : rawAlpha;
|
|
2525
|
+
const prevMap = /* @__PURE__ */ new Map();
|
|
2526
|
+
for (const e of prev.entities) prevMap.set(e.id, e);
|
|
2527
|
+
for (const c of curr.entities) {
|
|
2528
|
+
const p = prevMap.get(c.id);
|
|
2529
|
+
if (!p) {
|
|
2530
|
+
out.set(c.id, { x: c.x, y: c.y });
|
|
2531
|
+
} else {
|
|
2532
|
+
out.set(c.id, {
|
|
2533
|
+
x: p.x + (c.x - p.x) * alpha,
|
|
2534
|
+
y: p.y + (c.y - p.y) * alpha
|
|
2535
|
+
});
|
|
2536
|
+
}
|
|
2537
|
+
}
|
|
2538
|
+
return out;
|
|
2539
|
+
}, [tickIntervalMs]);
|
|
2540
|
+
const startLoop = useCallback(
|
|
2541
|
+
(draw) => {
|
|
2542
|
+
let active = true;
|
|
2543
|
+
const loop = () => {
|
|
2544
|
+
if (!active) return;
|
|
2545
|
+
try {
|
|
2546
|
+
draw(getInterpolated(performance.now()));
|
|
2547
|
+
} catch {
|
|
2548
|
+
}
|
|
2549
|
+
rafRef.current = requestAnimationFrame(loop);
|
|
2550
|
+
};
|
|
2551
|
+
rafRef.current = requestAnimationFrame(loop);
|
|
2552
|
+
return () => {
|
|
2553
|
+
active = false;
|
|
2554
|
+
if (rafRef.current !== null) {
|
|
2555
|
+
cancelAnimationFrame(rafRef.current);
|
|
2556
|
+
rafRef.current = null;
|
|
2557
|
+
}
|
|
2558
|
+
};
|
|
2559
|
+
},
|
|
2560
|
+
[getInterpolated]
|
|
2561
|
+
);
|
|
2562
|
+
useEffect(() => {
|
|
2563
|
+
return () => {
|
|
2564
|
+
if (rafRef.current !== null) {
|
|
2565
|
+
cancelAnimationFrame(rafRef.current);
|
|
2566
|
+
rafRef.current = null;
|
|
2567
|
+
}
|
|
2568
|
+
};
|
|
2569
|
+
}, []);
|
|
2570
|
+
return { onSnapshot, getInterpolated, startLoop };
|
|
2571
|
+
}
|
|
2505
2572
|
var API_BASE = typeof process !== "undefined" && process.env?.VITE_API_URL ? process.env.VITE_API_URL : "http://localhost:3000";
|
|
2506
2573
|
function getUserId() {
|
|
2507
2574
|
return localStorage.getItem("userId") || "anonymous";
|
|
@@ -2578,4 +2645,4 @@ function useGitHubBranches(owner, repo, enabled = true) {
|
|
|
2578
2645
|
});
|
|
2579
2646
|
}
|
|
2580
2647
|
|
|
2581
|
-
export { ALMADAR_DND_MIME, DEFAULT_SLOTS, I18nProvider, clearEntities, createTranslate, getAllEntities, getByType, getEntity, getSingleton, parseQueryBinding, removeEntity, spawnEntity, updateEntity, updateSingleton, useAgentChat, useAuthContext, useCompile, useConnectGitHub, useDeepAgentGeneration, useDisconnectGitHub, useDragReorder, useDraggable, useDropZone, useEmitEvent, useEntities, useEntitiesByType, useEntity as useEntityById, useEventBus, useEventListener, useExtensions, useFileEditor, useFileSystem, useGitHubBranches, useGitHubRepo, useGitHubRepos, useGitHubStatus, useInfiniteScroll, useInput, useLongPress, useOrbitalHistory, usePhysics, usePinchZoom, usePlayer, usePreview, usePullToRefresh, useQuerySingleton, useSingletonEntity, useSwipeGesture, useTraitListens, useTranslate, useUIEvents, useUISlotManager, useValidation };
|
|
2648
|
+
export { ALMADAR_DND_MIME, DEFAULT_SLOTS, I18nProvider, clearEntities, createTranslate, getAllEntities, getByType, getEntity, getSingleton, parseQueryBinding, removeEntity, spawnEntity, updateEntity, updateSingleton, useAgentChat, useAuthContext, useCompile, useConnectGitHub, useDeepAgentGeneration, useDisconnectGitHub, useDragReorder, useDraggable, useDropZone, useEmitEvent, useEntities, useEntitiesByType, useEntity as useEntityById, useEventBus, useEventListener, useExtensions, useFileEditor, useFileSystem, useGitHubBranches, useGitHubRepo, useGitHubRepos, useGitHubStatus, useInfiniteScroll, useInput, useLongPress, useOrbitalHistory, usePhysics, usePinchZoom, usePlayer, usePreview, usePullToRefresh, useQuerySingleton, useRenderInterpolation, useSingletonEntity, useSwipeGesture, useTraitListens, useTranslate, useUIEvents, useUISlotManager, useValidation };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export interface Positioned {
|
|
2
|
+
id: string;
|
|
3
|
+
x: number;
|
|
4
|
+
y: number;
|
|
5
|
+
}
|
|
6
|
+
export interface RenderInterpolationOptions {
|
|
7
|
+
/** Expected tick interval in ms (default: 1000/30 ≈ 33.3ms) */
|
|
8
|
+
tickIntervalMs?: number;
|
|
9
|
+
}
|
|
10
|
+
export interface RenderInterpolationHandle<T extends Positioned> {
|
|
11
|
+
/** Call when a new authoritative snapshot arrives from the model */
|
|
12
|
+
onSnapshot: (entities: readonly T[]) => void;
|
|
13
|
+
/** Returns interpolated positions for the current rAF timestamp; falls back to authoritative values */
|
|
14
|
+
getInterpolated: (now: number) => Map<string, {
|
|
15
|
+
x: number;
|
|
16
|
+
y: number;
|
|
17
|
+
}>;
|
|
18
|
+
/** Start the rAF loop; call the supplied draw fn on every frame */
|
|
19
|
+
startLoop: (draw: (positions: Map<string, {
|
|
20
|
+
x: number;
|
|
21
|
+
y: number;
|
|
22
|
+
}>) => void) => () => void;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Fixed-timestep render interpolation between the last two authoritative model snapshots.
|
|
26
|
+
*
|
|
27
|
+
* Buffers two snapshots. On each rAF frame computes
|
|
28
|
+
* alpha = clamp((now - lastArrival) / tickIntervalMs, 0, 1)
|
|
29
|
+
* and lerps x/y between prev and curr, matched by entity id.
|
|
30
|
+
* New or removed entities fall back to their authoritative value directly.
|
|
31
|
+
* Never throws; never causes a React re-render per frame.
|
|
32
|
+
*/
|
|
33
|
+
export declare function useRenderInterpolation<T extends Positioned>(options?: RenderInterpolationOptions): RenderInterpolationHandle<T>;
|