@srsergio/taptapp-ar 1.0.95 → 1.0.97

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,8 +1,8 @@
1
1
  import { useEffect, useRef, useState, useCallback } from "react";
2
2
  import type { ARConfig } from "./types.js";
3
- import type { SimpleAR as SimpleARType } from "../runtime/simple-ar.js";
3
+ import type { Tracker } from "../runtime/track.js";
4
4
 
5
- export type ARStatus = "scanning" | "tracking" | "error";
5
+ export type ARStatus = "compiling" | "scanning" | "tracking" | "error";
6
6
 
7
7
  export interface TrackedPoint {
8
8
  x: number;
@@ -18,6 +18,7 @@ export interface UseARReturn {
18
18
  isPlaying: boolean;
19
19
  toggleVideo: () => Promise<void>;
20
20
  trackedPoints: TrackedPoint[];
21
+ error: string | null;
21
22
  }
22
23
 
23
24
  export const useAR = (config: ARConfig): UseARReturn => {
@@ -26,7 +27,8 @@ export const useAR = (config: ARConfig): UseARReturn => {
26
27
  const [status, setStatus] = useState<ARStatus>("scanning");
27
28
  const [isPlaying, setIsPlaying] = useState(false);
28
29
  const [trackedPoints, setTrackedPoints] = useState<TrackedPoint[]>([]);
29
- const arInstanceRef = useRef<SimpleARType | null>(null);
30
+ const [error, setError] = useState<string | null>(null);
31
+ const arInstanceRef = useRef<Tracker | null>(null);
30
32
 
31
33
  const toggleVideo = useCallback(async () => {
32
34
  const overlay = overlayRef.current;
@@ -53,63 +55,70 @@ export const useAR = (config: ARConfig): UseARReturn => {
53
55
  const initAR = async () => {
54
56
  try {
55
57
  // Safe hybrid import for SSR + Speed
56
- const { SimpleAR } = await import("../runtime/simple-ar.js");
58
+ const { createTracker } = await import("../runtime/track.js");
57
59
  if (!isMounted) return;
58
60
 
59
- const instance = new SimpleAR({
61
+ setStatus("compiling");
62
+
63
+ const instance = await createTracker({
60
64
  container: containerRef.current!,
61
- targetSrc: config.targetTaarSrc,
65
+ targetSrc: config.targetTaarSrc || config.targetImageSrc,
62
66
  overlay: overlayRef.current!,
63
67
  scale: config.scale,
64
- debug: false,
65
- onUpdate: (data: any) => {
66
- const { screenCoords, reliabilities, stabilities } = data;
67
- if (screenCoords && reliabilities && stabilities) {
68
- const points = screenCoords.map((p: any, i: number) => ({
69
- x: p.x,
70
- y: p.y,
71
- reliability: reliabilities[i],
72
- stability: stabilities[i]
73
- }));
74
- setTrackedPoints(points);
75
- }
76
- },
77
- onFound: async ({ targetIndex }) => {
78
- console.log(`🎯 Target ${targetIndex} detected!`);
79
- if (!isMounted) return;
80
- setStatus("tracking");
81
-
82
- const overlay = overlayRef.current;
83
- if (overlay instanceof HTMLVideoElement) {
84
- try {
85
- await overlay.play();
86
- setIsPlaying(true);
87
- } catch (err) {
88
- console.warn("Auto-play blocked:", err);
68
+ debugMode: false,
69
+ callbacks: {
70
+ onUpdate: (data) => {
71
+ const { screenCoords, reliabilities, stabilities } = data;
72
+ if (screenCoords && reliabilities && stabilities) {
73
+ const points = screenCoords.map((p, i) => ({
74
+ x: p.x,
75
+ y: p.y,
76
+ reliability: reliabilities[i],
77
+ stability: stabilities[i]
78
+ }));
79
+ setTrackedPoints(points);
80
+ }
81
+ },
82
+ onFound: async ({ targetIndex }) => {
83
+ console.log(`🎯 Target ${targetIndex} detected!`);
84
+ if (!isMounted) return;
85
+ setStatus("tracking");
86
+
87
+ const overlay = overlayRef.current;
88
+ if (overlay instanceof HTMLVideoElement) {
89
+ try {
90
+ await overlay.play();
91
+ setIsPlaying(true);
92
+ } catch (err) {
93
+ console.warn("Auto-play blocked:", err);
94
+ }
95
+ }
96
+ },
97
+ onLost: ({ targetIndex }) => {
98
+ console.log(`👋 Target ${targetIndex} lost`);
99
+ if (!isMounted) return;
100
+ setStatus("scanning");
101
+ setTrackedPoints([]);
102
+
103
+ const overlay = overlayRef.current;
104
+ if (overlay instanceof HTMLVideoElement) {
105
+ overlay.pause();
106
+ setIsPlaying(false);
89
107
  }
90
- }
91
- },
92
- onLost: ({ targetIndex }) => {
93
- console.log(`👋 Target ${targetIndex} lost`);
94
- if (!isMounted) return;
95
- setStatus("scanning");
96
- setTrackedPoints([]);
97
-
98
- const overlay = overlayRef.current;
99
- if (overlay instanceof HTMLVideoElement) {
100
- overlay.pause();
101
- setIsPlaying(false);
102
108
  }
103
109
  }
104
110
  });
105
111
 
106
112
  arInstanceRef.current = instance;
107
- await instance.start();
113
+ await instance.startCamera();
108
114
 
109
115
  if (isMounted) setStatus("scanning");
110
- } catch (err) {
111
- console.error("Failed to initialize AR:", err);
112
- if (isMounted) setStatus("error");
116
+ } catch (err: any) {
117
+ console.error(" [TapTapp AR] Error durante la inicialización:", err);
118
+ if (isMounted) {
119
+ setError(err.message || String(err));
120
+ setStatus("error");
121
+ }
113
122
  }
114
123
  };
115
124
 
@@ -120,7 +129,7 @@ export const useAR = (config: ARConfig): UseARReturn => {
120
129
  arInstanceRef.current?.stop();
121
130
  arInstanceRef.current = null;
122
131
  };
123
- }, [config.targetTaarSrc, config.scale]);
132
+ }, [config.targetTaarSrc, config.targetImageSrc, config.scale]);
124
133
 
125
134
  return {
126
135
  containerRef,
@@ -128,6 +137,7 @@ export const useAR = (config: ARConfig): UseARReturn => {
128
137
  status,
129
138
  isPlaying,
130
139
  toggleVideo,
131
- trackedPoints
140
+ trackedPoints,
141
+ error
132
142
  };
133
143
  };
@@ -1,4 +1,5 @@
1
1
  export * from "./controller.js";
2
- export * from "./simple-ar.js";
2
+ export * from "./bio-inspired-controller.js";
3
+ export * from "./track.js";
3
4
  export * from "./three.js";
4
5
  export * from "./aframe.js";