@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 +78 -49
- package/dist/index.d.cts +4 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +78 -49
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -160,7 +160,7 @@ function createCommentNode(_text) {
|
|
|
160
160
|
}
|
|
161
161
|
|
|
162
162
|
// src/bridge.ts
|
|
163
|
-
var
|
|
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
|
-
|
|
206
|
-
|
|
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
|
|
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
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
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
|
-
|
|
489
|
-
|
|
490
|
-
|
|
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
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
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 (
|
|
550
|
-
|
|
572
|
+
if (key === "style") {
|
|
573
|
+
patchStyle(el.id, prevValue, nextValue);
|
|
574
|
+
return;
|
|
551
575
|
}
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
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
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
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
|
-
|
|
586
|
-
|
|
587
|
-
|
|
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
|
-
|
|
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
|
-
}
|
|
594
|
-
|
|
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
|
-
|
|
612
|
-
|
|
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
|
|
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
|
-
|
|
102
|
-
|
|
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
|
|
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
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
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
|
-
|
|
385
|
-
|
|
386
|
-
|
|
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
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
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 (
|
|
446
|
-
|
|
468
|
+
if (key === "style") {
|
|
469
|
+
patchStyle(el.id, prevValue, nextValue);
|
|
470
|
+
return;
|
|
447
471
|
}
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
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
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
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
|
-
|
|
482
|
-
|
|
483
|
-
|
|
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
|
-
|
|
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
|
-
}
|
|
490
|
-
|
|
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
|
-
|
|
508
|
-
|
|
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
|
},
|