@thelacanians/vue-native-runtime 0.2.0 → 0.3.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/index.cjs CHANGED
@@ -160,7 +160,7 @@ function createCommentNode(_text) {
160
160
  }
161
161
 
162
162
  // src/bridge.ts
163
- var NativeBridgeImpl = class {
163
+ var _NativeBridgeImpl = class _NativeBridgeImpl {
164
164
  constructor() {
165
165
  /** Pending operations waiting to be flushed to native */
166
166
  this.pendingOps = [];
@@ -170,7 +170,8 @@ var NativeBridgeImpl = class {
170
170
  this.eventHandlers = /* @__PURE__ */ new Map();
171
171
  /** Pending async callbacks from native module invocations */
172
172
  this.pendingCallbacks = /* @__PURE__ */ new Map();
173
- /** Auto-incrementing callback ID for async native module calls */
173
+ /** Auto-incrementing callback ID for async native module calls.
174
+ * Wraps around at MAX_SAFE_CALLBACK_ID to prevent overflow. */
174
175
  this.nextCallbackId = 1;
175
176
  /** Global event listeners: eventName -> Set of callbacks */
176
177
  this.globalEventHandlers = /* @__PURE__ */ new Map();
@@ -202,10 +203,14 @@ var NativeBridgeImpl = class {
202
203
  const json = JSON.stringify(ops);
203
204
  const flushFn = globalThis.__VN_flushOperations;
204
205
  if (typeof flushFn === "function") {
205
- flushFn(json);
206
- } else if (__DEV__) {
206
+ try {
207
+ flushFn(json);
208
+ } catch (err) {
209
+ console.error("[VueNative] Error in __VN_flushOperations:", err);
210
+ }
211
+ } else {
207
212
  console.warn(
208
- "[VueNative] __VN_flushOperations is not registered. Make sure the Swift runtime has been initialized."
213
+ "[VueNative] __VN_flushOperations is not registered. Make sure the native runtime has been initialized."
209
214
  );
210
215
  }
211
216
  }
@@ -365,7 +370,12 @@ var NativeBridgeImpl = class {
365
370
  */
366
371
  invokeNativeModule(moduleName, methodName, args = [], timeoutMs = 3e4) {
367
372
  return new Promise((resolve, reject) => {
368
- const callbackId = this.nextCallbackId++;
373
+ const callbackId = this.nextCallbackId;
374
+ if (this.nextCallbackId >= _NativeBridgeImpl.MAX_CALLBACK_ID) {
375
+ this.nextCallbackId = 1;
376
+ } else {
377
+ this.nextCallbackId++;
378
+ }
369
379
  const timeoutId = setTimeout(() => {
370
380
  if (this.pendingCallbacks.has(callbackId)) {
371
381
  this.pendingCallbacks.delete(callbackId);
@@ -460,6 +470,9 @@ var NativeBridgeImpl = class {
460
470
  this.globalEventHandlers.clear();
461
471
  }
462
472
  };
473
+ /** Maximum callback ID before wraparound (safe for 32-bit signed int) */
474
+ _NativeBridgeImpl.MAX_CALLBACK_ID = 2147483647;
475
+ var NativeBridgeImpl = _NativeBridgeImpl;
463
476
  if (typeof globalThis.__DEV__ === "undefined") {
464
477
  ;
465
478
  globalThis.__DEV__ = true;
@@ -478,17 +491,21 @@ function toEventName(key) {
478
491
  return key.slice(2).toLowerCase();
479
492
  }
480
493
  function patchStyle(nodeId, prevStyle, nextStyle) {
481
- const prev = prevStyle || {};
482
- const next = nextStyle || {};
483
- for (const key in next) {
484
- if (next[key] !== prev[key]) {
485
- NativeBridge.updateStyle(nodeId, key, next[key]);
494
+ try {
495
+ const prev = prevStyle || {};
496
+ const next = nextStyle || {};
497
+ for (const key in next) {
498
+ if (next[key] !== prev[key]) {
499
+ NativeBridge.updateStyle(nodeId, key, next[key]);
500
+ }
486
501
  }
487
- }
488
- for (const key in prev) {
489
- if (!(key in next)) {
490
- NativeBridge.updateStyle(nodeId, key, null);
502
+ for (const key in prev) {
503
+ if (!(key in next)) {
504
+ NativeBridge.updateStyle(nodeId, key, null);
505
+ }
491
506
  }
507
+ } catch (err) {
508
+ console.error(`[VueNative] Error patching style on node ${nodeId}:`, err);
492
509
  }
493
510
  }
494
511
  var nodeOps = {
@@ -541,22 +558,26 @@ var nodeOps = {
541
558
  * - all else -> updateProp
542
559
  */
543
560
  patchProp(el, key, prevValue, nextValue) {
544
- if (key.startsWith("on") && key.length > 2 && key[2] === key[2].toUpperCase()) {
545
- const eventName = toEventName(key);
546
- if (prevValue) {
547
- NativeBridge.removeEventListener(el.id, eventName);
561
+ try {
562
+ if (key.startsWith("on") && key.length > 2 && key[2] === key[2].toUpperCase()) {
563
+ const eventName = toEventName(key);
564
+ if (prevValue) {
565
+ NativeBridge.removeEventListener(el.id, eventName);
566
+ }
567
+ if (nextValue) {
568
+ NativeBridge.addEventListener(el.id, eventName, nextValue);
569
+ }
570
+ return;
548
571
  }
549
- if (nextValue) {
550
- NativeBridge.addEventListener(el.id, eventName, nextValue);
572
+ if (key === "style") {
573
+ patchStyle(el.id, prevValue, nextValue);
574
+ return;
551
575
  }
552
- return;
553
- }
554
- if (key === "style") {
555
- patchStyle(el.id, prevValue, nextValue);
556
- return;
576
+ el.props[key] = nextValue;
577
+ NativeBridge.updateProp(el.id, key, nextValue);
578
+ } catch (err) {
579
+ console.error(`[VueNative] Error patching prop "${key}" on node ${el.id}:`, err);
557
580
  }
558
- el.props[key] = nextValue;
559
- NativeBridge.updateProp(el.id, key, nextValue);
560
581
  },
561
582
  /**
562
583
  * Insert a child node into a parent, optionally before an anchor node.
@@ -571,30 +592,34 @@ var nodeOps = {
571
592
  }
572
593
  }
573
594
  child.parent = parent;
574
- if (anchor) {
575
- const anchorIdx = parent.children.indexOf(anchor);
576
- if (anchorIdx !== -1) {
577
- parent.children.splice(anchorIdx, 0, child);
578
- } else {
579
- parent.children.push(child);
580
- }
581
- if (child.type !== "__COMMENT__") {
582
- if (anchor.type !== "__COMMENT__") {
583
- NativeBridge.insertBefore(parent.id, child.id, anchor.id);
595
+ try {
596
+ if (anchor) {
597
+ const anchorIdx = parent.children.indexOf(anchor);
598
+ if (anchorIdx !== -1) {
599
+ parent.children.splice(anchorIdx, 0, child);
584
600
  } else {
585
- const realAnchor = findNextNonComment(parent, anchor);
586
- if (realAnchor) {
587
- NativeBridge.insertBefore(parent.id, child.id, realAnchor.id);
601
+ parent.children.push(child);
602
+ }
603
+ if (child.type !== "__COMMENT__") {
604
+ if (anchor.type !== "__COMMENT__") {
605
+ NativeBridge.insertBefore(parent.id, child.id, anchor.id);
588
606
  } else {
589
- NativeBridge.appendChild(parent.id, child.id);
607
+ const realAnchor = findNextNonComment(parent, anchor);
608
+ if (realAnchor) {
609
+ NativeBridge.insertBefore(parent.id, child.id, realAnchor.id);
610
+ } else {
611
+ NativeBridge.appendChild(parent.id, child.id);
612
+ }
590
613
  }
591
614
  }
615
+ } else {
616
+ parent.children.push(child);
617
+ if (child.type !== "__COMMENT__") {
618
+ NativeBridge.appendChild(parent.id, child.id);
619
+ }
592
620
  }
593
- } else {
594
- parent.children.push(child);
595
- if (child.type !== "__COMMENT__") {
596
- NativeBridge.appendChild(parent.id, child.id);
597
- }
621
+ } catch (err) {
622
+ console.error(`[VueNative] Error inserting node ${child.id} into ${parent.id}:`, err);
598
623
  }
599
624
  },
600
625
  /**
@@ -608,8 +633,12 @@ var nodeOps = {
608
633
  parent.children.splice(idx, 1);
609
634
  }
610
635
  child.parent = null;
611
- if (child.type !== "__COMMENT__") {
612
- NativeBridge.removeChild(parent.id, child.id);
636
+ try {
637
+ if (child.type !== "__COMMENT__") {
638
+ NativeBridge.removeChild(parent.id, child.id);
639
+ }
640
+ } catch (err) {
641
+ console.error(`[VueNative] Error removing node ${child.id}:`, err);
613
642
  }
614
643
  }
615
644
  },
package/dist/index.d.cts CHANGED
@@ -3474,8 +3474,11 @@ declare class NativeBridgeImpl {
3474
3474
  private eventHandlers;
3475
3475
  /** Pending async callbacks from native module invocations */
3476
3476
  private pendingCallbacks;
3477
- /** Auto-incrementing callback ID for async native module calls */
3477
+ /** Auto-incrementing callback ID for async native module calls.
3478
+ * Wraps around at MAX_SAFE_CALLBACK_ID to prevent overflow. */
3478
3479
  private nextCallbackId;
3480
+ /** Maximum callback ID before wraparound (safe for 32-bit signed int) */
3481
+ private static readonly MAX_CALLBACK_ID;
3479
3482
  /** Global event listeners: eventName -> Set of callbacks */
3480
3483
  private globalEventHandlers;
3481
3484
  /**
package/dist/index.d.ts CHANGED
@@ -3474,8 +3474,11 @@ declare class NativeBridgeImpl {
3474
3474
  private eventHandlers;
3475
3475
  /** Pending async callbacks from native module invocations */
3476
3476
  private pendingCallbacks;
3477
- /** Auto-incrementing callback ID for async native module calls */
3477
+ /** Auto-incrementing callback ID for async native module calls.
3478
+ * Wraps around at MAX_SAFE_CALLBACK_ID to prevent overflow. */
3478
3479
  private nextCallbackId;
3480
+ /** Maximum callback ID before wraparound (safe for 32-bit signed int) */
3481
+ private static readonly MAX_CALLBACK_ID;
3479
3482
  /** Global event listeners: eventName -> Set of callbacks */
3480
3483
  private globalEventHandlers;
3481
3484
  /**
package/dist/index.js CHANGED
@@ -56,7 +56,7 @@ function createCommentNode(_text) {
56
56
  }
57
57
 
58
58
  // src/bridge.ts
59
- var NativeBridgeImpl = class {
59
+ var _NativeBridgeImpl = class _NativeBridgeImpl {
60
60
  constructor() {
61
61
  /** Pending operations waiting to be flushed to native */
62
62
  this.pendingOps = [];
@@ -66,7 +66,8 @@ var NativeBridgeImpl = class {
66
66
  this.eventHandlers = /* @__PURE__ */ new Map();
67
67
  /** Pending async callbacks from native module invocations */
68
68
  this.pendingCallbacks = /* @__PURE__ */ new Map();
69
- /** Auto-incrementing callback ID for async native module calls */
69
+ /** Auto-incrementing callback ID for async native module calls.
70
+ * Wraps around at MAX_SAFE_CALLBACK_ID to prevent overflow. */
70
71
  this.nextCallbackId = 1;
71
72
  /** Global event listeners: eventName -> Set of callbacks */
72
73
  this.globalEventHandlers = /* @__PURE__ */ new Map();
@@ -98,10 +99,14 @@ var NativeBridgeImpl = class {
98
99
  const json = JSON.stringify(ops);
99
100
  const flushFn = globalThis.__VN_flushOperations;
100
101
  if (typeof flushFn === "function") {
101
- flushFn(json);
102
- } else if (__DEV__) {
102
+ try {
103
+ flushFn(json);
104
+ } catch (err) {
105
+ console.error("[VueNative] Error in __VN_flushOperations:", err);
106
+ }
107
+ } else {
103
108
  console.warn(
104
- "[VueNative] __VN_flushOperations is not registered. Make sure the Swift runtime has been initialized."
109
+ "[VueNative] __VN_flushOperations is not registered. Make sure the native runtime has been initialized."
105
110
  );
106
111
  }
107
112
  }
@@ -261,7 +266,12 @@ var NativeBridgeImpl = class {
261
266
  */
262
267
  invokeNativeModule(moduleName, methodName, args = [], timeoutMs = 3e4) {
263
268
  return new Promise((resolve, reject) => {
264
- const callbackId = this.nextCallbackId++;
269
+ const callbackId = this.nextCallbackId;
270
+ if (this.nextCallbackId >= _NativeBridgeImpl.MAX_CALLBACK_ID) {
271
+ this.nextCallbackId = 1;
272
+ } else {
273
+ this.nextCallbackId++;
274
+ }
265
275
  const timeoutId = setTimeout(() => {
266
276
  if (this.pendingCallbacks.has(callbackId)) {
267
277
  this.pendingCallbacks.delete(callbackId);
@@ -356,6 +366,9 @@ var NativeBridgeImpl = class {
356
366
  this.globalEventHandlers.clear();
357
367
  }
358
368
  };
369
+ /** Maximum callback ID before wraparound (safe for 32-bit signed int) */
370
+ _NativeBridgeImpl.MAX_CALLBACK_ID = 2147483647;
371
+ var NativeBridgeImpl = _NativeBridgeImpl;
359
372
  if (typeof globalThis.__DEV__ === "undefined") {
360
373
  ;
361
374
  globalThis.__DEV__ = true;
@@ -374,17 +387,21 @@ function toEventName(key) {
374
387
  return key.slice(2).toLowerCase();
375
388
  }
376
389
  function patchStyle(nodeId, prevStyle, nextStyle) {
377
- const prev = prevStyle || {};
378
- const next = nextStyle || {};
379
- for (const key in next) {
380
- if (next[key] !== prev[key]) {
381
- NativeBridge.updateStyle(nodeId, key, next[key]);
390
+ try {
391
+ const prev = prevStyle || {};
392
+ const next = nextStyle || {};
393
+ for (const key in next) {
394
+ if (next[key] !== prev[key]) {
395
+ NativeBridge.updateStyle(nodeId, key, next[key]);
396
+ }
382
397
  }
383
- }
384
- for (const key in prev) {
385
- if (!(key in next)) {
386
- NativeBridge.updateStyle(nodeId, key, null);
398
+ for (const key in prev) {
399
+ if (!(key in next)) {
400
+ NativeBridge.updateStyle(nodeId, key, null);
401
+ }
387
402
  }
403
+ } catch (err) {
404
+ console.error(`[VueNative] Error patching style on node ${nodeId}:`, err);
388
405
  }
389
406
  }
390
407
  var nodeOps = {
@@ -437,22 +454,26 @@ var nodeOps = {
437
454
  * - all else -> updateProp
438
455
  */
439
456
  patchProp(el, key, prevValue, nextValue) {
440
- if (key.startsWith("on") && key.length > 2 && key[2] === key[2].toUpperCase()) {
441
- const eventName = toEventName(key);
442
- if (prevValue) {
443
- NativeBridge.removeEventListener(el.id, eventName);
457
+ try {
458
+ if (key.startsWith("on") && key.length > 2 && key[2] === key[2].toUpperCase()) {
459
+ const eventName = toEventName(key);
460
+ if (prevValue) {
461
+ NativeBridge.removeEventListener(el.id, eventName);
462
+ }
463
+ if (nextValue) {
464
+ NativeBridge.addEventListener(el.id, eventName, nextValue);
465
+ }
466
+ return;
444
467
  }
445
- if (nextValue) {
446
- NativeBridge.addEventListener(el.id, eventName, nextValue);
468
+ if (key === "style") {
469
+ patchStyle(el.id, prevValue, nextValue);
470
+ return;
447
471
  }
448
- return;
449
- }
450
- if (key === "style") {
451
- patchStyle(el.id, prevValue, nextValue);
452
- return;
472
+ el.props[key] = nextValue;
473
+ NativeBridge.updateProp(el.id, key, nextValue);
474
+ } catch (err) {
475
+ console.error(`[VueNative] Error patching prop "${key}" on node ${el.id}:`, err);
453
476
  }
454
- el.props[key] = nextValue;
455
- NativeBridge.updateProp(el.id, key, nextValue);
456
477
  },
457
478
  /**
458
479
  * Insert a child node into a parent, optionally before an anchor node.
@@ -467,30 +488,34 @@ var nodeOps = {
467
488
  }
468
489
  }
469
490
  child.parent = parent;
470
- if (anchor) {
471
- const anchorIdx = parent.children.indexOf(anchor);
472
- if (anchorIdx !== -1) {
473
- parent.children.splice(anchorIdx, 0, child);
474
- } else {
475
- parent.children.push(child);
476
- }
477
- if (child.type !== "__COMMENT__") {
478
- if (anchor.type !== "__COMMENT__") {
479
- NativeBridge.insertBefore(parent.id, child.id, anchor.id);
491
+ try {
492
+ if (anchor) {
493
+ const anchorIdx = parent.children.indexOf(anchor);
494
+ if (anchorIdx !== -1) {
495
+ parent.children.splice(anchorIdx, 0, child);
480
496
  } else {
481
- const realAnchor = findNextNonComment(parent, anchor);
482
- if (realAnchor) {
483
- NativeBridge.insertBefore(parent.id, child.id, realAnchor.id);
497
+ parent.children.push(child);
498
+ }
499
+ if (child.type !== "__COMMENT__") {
500
+ if (anchor.type !== "__COMMENT__") {
501
+ NativeBridge.insertBefore(parent.id, child.id, anchor.id);
484
502
  } else {
485
- NativeBridge.appendChild(parent.id, child.id);
503
+ const realAnchor = findNextNonComment(parent, anchor);
504
+ if (realAnchor) {
505
+ NativeBridge.insertBefore(parent.id, child.id, realAnchor.id);
506
+ } else {
507
+ NativeBridge.appendChild(parent.id, child.id);
508
+ }
486
509
  }
487
510
  }
511
+ } else {
512
+ parent.children.push(child);
513
+ if (child.type !== "__COMMENT__") {
514
+ NativeBridge.appendChild(parent.id, child.id);
515
+ }
488
516
  }
489
- } else {
490
- parent.children.push(child);
491
- if (child.type !== "__COMMENT__") {
492
- NativeBridge.appendChild(parent.id, child.id);
493
- }
517
+ } catch (err) {
518
+ console.error(`[VueNative] Error inserting node ${child.id} into ${parent.id}:`, err);
494
519
  }
495
520
  },
496
521
  /**
@@ -504,8 +529,12 @@ var nodeOps = {
504
529
  parent.children.splice(idx, 1);
505
530
  }
506
531
  child.parent = null;
507
- if (child.type !== "__COMMENT__") {
508
- NativeBridge.removeChild(parent.id, child.id);
532
+ try {
533
+ if (child.type !== "__COMMENT__") {
534
+ NativeBridge.removeChild(parent.id, child.id);
535
+ }
536
+ } catch (err) {
537
+ console.error(`[VueNative] Error removing node ${child.id}:`, err);
509
538
  }
510
539
  }
511
540
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thelacanians/vue-native-runtime",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Vue 3 custom renderer for native iOS and Android apps",
5
5
  "license": "MIT",
6
6
  "author": "Vue Native Contributors",