@srsergio/taptapp-ar 1.0.78 → 1.0.79

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.
@@ -5,26 +5,110 @@
5
5
  * que NO depende de TensorFlow, eliminando todos los problemas de
6
6
  * inicialización, bloqueos y compatibilidad.
7
7
  */
8
- import { WorkerPool } from "./utils/worker-pool.js";
9
8
  export declare class OfflineCompiler {
10
9
  data: any;
11
- workerPool: WorkerPool | null;
12
10
  constructor();
13
- _initNodeWorkers(): Promise<void>;
14
11
  compileImageTargets(images: any[], progressCallback: (p: number) => void): Promise<any>;
15
- _compileTarget(targetImages: any[], progressCallback: (p: number) => void): Promise<any[]>;
16
- _compileMatch(targetImages: any[], progressCallback: (p: number) => void): Promise<any[]>;
17
- _compileTrack(targetImages: any[], progressCallback: (p: number) => void): Promise<any[]>;
12
+ _compileTarget(targetImages: any[], progressCallback: (p: number) => void): Promise<{
13
+ matchingData: {
14
+ maximaPoints: any[];
15
+ minimaPoints: any[];
16
+ maximaPointsCluster: {
17
+ rootNode: {
18
+ leaf: boolean;
19
+ pointIndexes: never[];
20
+ centerPointIndex: null;
21
+ };
22
+ } | {
23
+ rootNode: {
24
+ centerPointIndex: any;
25
+ };
26
+ };
27
+ minimaPointsCluster: {
28
+ rootNode: {
29
+ leaf: boolean;
30
+ pointIndexes: never[];
31
+ centerPointIndex: null;
32
+ };
33
+ } | {
34
+ rootNode: {
35
+ centerPointIndex: any;
36
+ };
37
+ };
38
+ width: any;
39
+ height: any;
40
+ scale: any;
41
+ }[];
42
+ trackingData: Object[];
43
+ }[]>;
44
+ _compileMatch(targetImages: any[], progressCallback: (p: number) => void): Promise<{
45
+ maximaPoints: any[];
46
+ minimaPoints: any[];
47
+ maximaPointsCluster: {
48
+ rootNode: {
49
+ leaf: boolean;
50
+ pointIndexes: never[];
51
+ centerPointIndex: null;
52
+ };
53
+ } | {
54
+ rootNode: {
55
+ centerPointIndex: any;
56
+ };
57
+ };
58
+ minimaPointsCluster: {
59
+ rootNode: {
60
+ leaf: boolean;
61
+ pointIndexes: never[];
62
+ centerPointIndex: null;
63
+ };
64
+ } | {
65
+ rootNode: {
66
+ centerPointIndex: any;
67
+ };
68
+ };
69
+ width: any;
70
+ height: any;
71
+ scale: any;
72
+ }[][]>;
73
+ _compileTrack(targetImages: any[], progressCallback: (p: number) => void): Promise<Object[][]>;
18
74
  compileTrack({ progressCallback, targetImages, basePercent }: {
19
75
  progressCallback: (p: number) => void;
20
76
  targetImages: any[];
21
77
  basePercent?: number;
22
- }): Promise<any[]>;
78
+ }): Promise<Object[][]>;
23
79
  compileMatch({ progressCallback, targetImages, basePercent }: {
24
80
  progressCallback: (p: number) => void;
25
81
  targetImages: any[];
26
82
  basePercent?: number;
27
- }): Promise<any[]>;
83
+ }): Promise<{
84
+ maximaPoints: any[];
85
+ minimaPoints: any[];
86
+ maximaPointsCluster: {
87
+ rootNode: {
88
+ leaf: boolean;
89
+ pointIndexes: never[];
90
+ centerPointIndex: null;
91
+ };
92
+ } | {
93
+ rootNode: {
94
+ centerPointIndex: any;
95
+ };
96
+ };
97
+ minimaPointsCluster: {
98
+ rootNode: {
99
+ leaf: boolean;
100
+ pointIndexes: never[];
101
+ centerPointIndex: null;
102
+ };
103
+ } | {
104
+ rootNode: {
105
+ centerPointIndex: any;
106
+ };
107
+ };
108
+ width: any;
109
+ height: any;
110
+ scale: any;
111
+ }[][]>;
28
112
  exportData(): Uint8Array<ArrayBuffer>;
29
113
  _getMorton(x: number, y: number): number;
30
114
  _columnarize(points: any[], tree: any, width: number, height: number): {
@@ -10,7 +10,6 @@ import { extractTrackingFeatures } from "./tracker/extract-utils.js";
10
10
  import { DetectorLite } from "./detector/detector-lite.js";
11
11
  import { build as hierarchicalClusteringBuild } from "./matching/hierarchical-clustering.js";
12
12
  import * as msgpack from "@msgpack/msgpack";
13
- import { WorkerPool } from "./utils/worker-pool.js";
14
13
  // Detect environment
15
14
  const isNode = typeof process !== "undefined" &&
16
15
  process.versions != null &&
@@ -18,35 +17,8 @@ const isNode = typeof process !== "undefined" &&
18
17
  const CURRENT_VERSION = 7; // Protocol v7: Moonshot - 4-bit Packed Tracking Data
19
18
  export class OfflineCompiler {
20
19
  data = null;
21
- workerPool = null;
22
20
  constructor() {
23
- // Workers only in Node.js
24
- if (!isNode) {
25
- console.log("🌐 OfflineCompiler: Browser mode (no workers)");
26
- }
27
- }
28
- async _initNodeWorkers() {
29
- try {
30
- const pathModule = "path";
31
- const urlModule = "url";
32
- const osModule = "os";
33
- const workerThreadsModule = "node:worker_threads";
34
- const [path, url, os, { Worker }] = await Promise.all([
35
- import(/* @vite-ignore */ pathModule),
36
- import(/* @vite-ignore */ urlModule),
37
- import(/* @vite-ignore */ osModule),
38
- import(/* @vite-ignore */ workerThreadsModule)
39
- ]);
40
- const __filename = url.fileURLToPath(import.meta.url);
41
- const __dirname = path.dirname(__filename);
42
- const workerPath = path.join(__dirname, "node-worker.js");
43
- // Limit workers to avoid freezing system
44
- const numWorkers = Math.min(os.cpus().length, 4);
45
- this.workerPool = new WorkerPool(workerPath, numWorkers, Worker);
46
- }
47
- catch (e) {
48
- console.log("⚡ OfflineCompiler: Running without workers (initialization failed)", e);
49
- }
21
+ console.log("⚡ OfflineCompiler: Main thread mode (no workers)");
50
22
  }
51
23
  async compileImageTargets(images, progressCallback) {
52
24
  console.time("⏱️ Compilación total");
@@ -86,24 +58,7 @@ export class OfflineCompiler {
86
58
  return this.data;
87
59
  }
88
60
  async _compileTarget(targetImages, progressCallback) {
89
- if (isNode)
90
- await this._initNodeWorkers();
91
- if (this.workerPool) {
92
- const progressMap = new Float32Array(targetImages.length);
93
- const wrappedPromises = targetImages.map((targetImage, index) => {
94
- return this.workerPool.runTask({
95
- type: 'compile-all', // 🚀 MOONSHOT: Combined task
96
- targetImage,
97
- onProgress: (p) => {
98
- progressMap[index] = p;
99
- const sum = progressMap.reduce((a, b) => a + b, 0);
100
- progressCallback(sum / targetImages.length);
101
- }
102
- });
103
- });
104
- return Promise.all(wrappedPromises);
105
- }
106
- // Fallback or non-worker implementation: run match and track sequentially
61
+ // Run match and track sequentially to match browser behavior exactly
107
62
  const matchingResults = await this._compileMatch(targetImages, (p) => progressCallback(p * 0.5));
108
63
  const trackingResults = await this._compileTrack(targetImages, (p) => progressCallback(50 + p * 0.5));
109
64
  return targetImages.map((_, i) => ({
@@ -114,25 +69,6 @@ export class OfflineCompiler {
114
69
  async _compileMatch(targetImages, progressCallback) {
115
70
  const percentPerImage = 100 / targetImages.length;
116
71
  let currentPercent = 0;
117
- if (isNode)
118
- await this._initNodeWorkers();
119
- if (this.workerPool) {
120
- const progressMap = new Float32Array(targetImages.length);
121
- const wrappedPromises = targetImages.map((targetImage, index) => {
122
- return this.workerPool.runTask({
123
- type: 'match',
124
- targetImage,
125
- percentPerImage,
126
- basePercent: 0,
127
- onProgress: (p) => {
128
- progressMap[index] = p;
129
- const sum = progressMap.reduce((a, b) => a + b, 0);
130
- progressCallback(sum);
131
- }
132
- });
133
- });
134
- return Promise.all(wrappedPromises);
135
- }
136
72
  const results = [];
137
73
  for (let i = 0; i < targetImages.length; i++) {
138
74
  const targetImage = targetImages[i];
@@ -165,23 +101,6 @@ export class OfflineCompiler {
165
101
  async _compileTrack(targetImages, progressCallback) {
166
102
  const percentPerImage = 100 / targetImages.length;
167
103
  let currentPercent = 0;
168
- if (this.workerPool) {
169
- const progressMap = new Float32Array(targetImages.length);
170
- const wrappedPromises = targetImages.map((targetImage, index) => {
171
- return this.workerPool.runTask({
172
- type: 'compile',
173
- targetImage,
174
- percentPerImage,
175
- basePercent: 0,
176
- onProgress: (p) => {
177
- progressMap[index] = p;
178
- const sum = progressMap.reduce((a, b) => a + b, 0);
179
- progressCallback(sum);
180
- }
181
- });
182
- });
183
- return Promise.all(wrappedPromises);
184
- }
185
104
  const results = [];
186
105
  for (let i = 0; i < targetImages.length; i++) {
187
106
  const targetImage = targetImages[i];
@@ -407,9 +326,7 @@ export class OfflineCompiler {
407
326
  };
408
327
  }
409
328
  async destroy() {
410
- if (this.workerPool) {
411
- await this.workerPool.destroy();
412
- }
329
+ // No workers to destroy
413
330
  }
414
331
  _pack4Bit(data) {
415
332
  const length = data.length;
@@ -92,6 +92,9 @@ export const TaptappAR = ({ config, className = "", showScanningOverlay = true,
92
92
  display: block;
93
93
  width: 100%;
94
94
  height: auto;
95
+ opacity: 0;
96
+ pointer-events: none;
97
+ transition: opacity 0.3s ease;
95
98
  }
96
99
  ` })] }));
97
100
  };
@@ -38,6 +38,7 @@ export const useAR = (config) => {
38
38
  targetSrc: config.targetTaarSrc,
39
39
  overlay: overlayRef.current,
40
40
  scale: config.scale,
41
+ debug: false,
41
42
  onFound: async ({ targetIndex }) => {
42
43
  console.log(`🎯 Target ${targetIndex} detected!`);
43
44
  if (!isMounted)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@srsergio/taptapp-ar",
3
- "version": "1.0.78",
3
+ "version": "1.0.79",
4
4
  "description": "AR Compiler for Node.js and Browser",
5
5
  "repository": {
6
6
  "type": "git",
@@ -11,7 +11,6 @@ import { extractTrackingFeatures } from "./tracker/extract-utils.js";
11
11
  import { DetectorLite } from "./detector/detector-lite.js";
12
12
  import { build as hierarchicalClusteringBuild } from "./matching/hierarchical-clustering.js";
13
13
  import * as msgpack from "@msgpack/msgpack";
14
- import { WorkerPool } from "./utils/worker-pool.js";
15
14
 
16
15
  // Detect environment
17
16
  const isNode = typeof process !== "undefined" &&
@@ -22,40 +21,9 @@ const CURRENT_VERSION = 7; // Protocol v7: Moonshot - 4-bit Packed Tracking Data
22
21
 
23
22
  export class OfflineCompiler {
24
23
  data: any = null;
25
- workerPool: WorkerPool | null = null;
26
24
 
27
25
  constructor() {
28
- // Workers only in Node.js
29
- if (!isNode) {
30
- console.log("🌐 OfflineCompiler: Browser mode (no workers)");
31
- }
32
- }
33
-
34
- async _initNodeWorkers() {
35
- try {
36
- const pathModule = "path";
37
- const urlModule = "url";
38
- const osModule = "os";
39
- const workerThreadsModule = "node:worker_threads";
40
-
41
- const [path, url, os, { Worker }] = await Promise.all([
42
- import(/* @vite-ignore */ pathModule),
43
- import(/* @vite-ignore */ urlModule),
44
- import(/* @vite-ignore */ osModule),
45
- import(/* @vite-ignore */ workerThreadsModule)
46
- ]);
47
-
48
- const __filename = url.fileURLToPath(import.meta.url);
49
- const __dirname = path.dirname(__filename);
50
- const workerPath = path.join(__dirname, "node-worker.js");
51
-
52
- // Limit workers to avoid freezing system
53
- const numWorkers = Math.min(os.cpus().length, 4);
54
-
55
- this.workerPool = new WorkerPool(workerPath, numWorkers, Worker);
56
- } catch (e) {
57
- console.log("⚡ OfflineCompiler: Running without workers (initialization failed)", e);
58
- }
26
+ console.log("⚡ OfflineCompiler: Main thread mode (no workers)");
59
27
  }
60
28
 
61
29
  async compileImageTargets(images: any[], progressCallback: (p: number) => void) {
@@ -108,25 +76,7 @@ export class OfflineCompiler {
108
76
  }
109
77
 
110
78
  async _compileTarget(targetImages: any[], progressCallback: (p: number) => void) {
111
- if (isNode) await this._initNodeWorkers();
112
-
113
- if (this.workerPool) {
114
- const progressMap = new Float32Array(targetImages.length);
115
- const wrappedPromises = targetImages.map((targetImage: any, index: number) => {
116
- return this.workerPool!.runTask({
117
- type: 'compile-all', // 🚀 MOONSHOT: Combined task
118
- targetImage,
119
- onProgress: (p: number) => {
120
- progressMap[index] = p;
121
- const sum = progressMap.reduce((a, b) => a + b, 0);
122
- progressCallback(sum / targetImages.length);
123
- }
124
- });
125
- });
126
- return Promise.all(wrappedPromises);
127
- }
128
-
129
- // Fallback or non-worker implementation: run match and track sequentially
79
+ // Run match and track sequentially to match browser behavior exactly
130
80
  const matchingResults = await this._compileMatch(targetImages, (p) => progressCallback(p * 0.5));
131
81
  const trackingResults = await this._compileTrack(targetImages, (p) => progressCallback(50 + p * 0.5));
132
82
 
@@ -140,27 +90,6 @@ export class OfflineCompiler {
140
90
  const percentPerImage = 100 / targetImages.length;
141
91
  let currentPercent = 0;
142
92
 
143
- if (isNode) await this._initNodeWorkers();
144
- if (this.workerPool) {
145
- const progressMap = new Float32Array(targetImages.length);
146
-
147
- const wrappedPromises = targetImages.map((targetImage: any, index: number) => {
148
- return this.workerPool!.runTask({
149
- type: 'match',
150
- targetImage,
151
- percentPerImage,
152
- basePercent: 0,
153
- onProgress: (p: number) => {
154
- progressMap[index] = p;
155
- const sum = progressMap.reduce((a, b) => a + b, 0);
156
- progressCallback(sum);
157
- }
158
- });
159
- });
160
-
161
- return Promise.all(wrappedPromises);
162
- }
163
-
164
93
  const results = [];
165
94
  for (let i = 0; i < targetImages.length; i++) {
166
95
  const targetImage = targetImages[i];
@@ -201,24 +130,6 @@ export class OfflineCompiler {
201
130
  const percentPerImage = 100 / targetImages.length;
202
131
  let currentPercent = 0;
203
132
 
204
- if (this.workerPool) {
205
- const progressMap = new Float32Array(targetImages.length);
206
- const wrappedPromises = targetImages.map((targetImage: any, index: number) => {
207
- return this.workerPool!.runTask({
208
- type: 'compile',
209
- targetImage,
210
- percentPerImage,
211
- basePercent: 0,
212
- onProgress: (p: number) => {
213
- progressMap[index] = p;
214
- const sum = progressMap.reduce((a, b) => a + b, 0);
215
- progressCallback(sum);
216
- }
217
- });
218
- });
219
- return Promise.all(wrappedPromises);
220
- }
221
-
222
133
  const results = [];
223
134
  for (let i = 0; i < targetImages.length; i++) {
224
135
  const targetImage = targetImages[i];
@@ -480,9 +391,7 @@ export class OfflineCompiler {
480
391
  }
481
392
 
482
393
  async destroy() {
483
- if (this.workerPool) {
484
- await this.workerPool.destroy();
485
- }
394
+ // No workers to destroy
486
395
  }
487
396
 
488
397
 
@@ -169,6 +169,9 @@ export const TaptappAR: React.FC<TaptappARProps> = ({
169
169
  display: block;
170
170
  width: 100%;
171
171
  height: auto;
172
+ opacity: 0;
173
+ pointer-events: none;
174
+ transition: opacity 0.3s ease;
172
175
  }
173
176
  `}</style>
174
177
  </div>
@@ -52,6 +52,7 @@ export const useAR = (config: ARConfig): UseARReturn => {
52
52
  targetSrc: config.targetTaarSrc,
53
53
  overlay: overlayRef.current!,
54
54
  scale: config.scale,
55
+ debug: false,
55
56
  onFound: async ({ targetIndex }) => {
56
57
  console.log(`🎯 Target ${targetIndex} detected!`);
57
58
  if (!isMounted) return;