@papyrus-sdk/ui-react-native 0.1.2 → 0.1.3
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.js +31 -19
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +31 -19
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
- package/runtime/index.html +31 -19
- package/runtime/runtime.js +29 -11
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@papyrus-sdk/ui-react-native",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "dist/index.mjs",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -19,9 +19,9 @@
|
|
|
19
19
|
"access": "public"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@papyrus-sdk/core": "0.1.
|
|
23
|
-
"@papyrus-sdk/types": "0.1.
|
|
24
|
-
"@papyrus-sdk/engine-native": "0.1.
|
|
22
|
+
"@papyrus-sdk/core": "0.1.2",
|
|
23
|
+
"@papyrus-sdk/types": "0.1.2",
|
|
24
|
+
"@papyrus-sdk/engine-native": "0.1.2",
|
|
25
25
|
"react-native-svg": "^15.5.0"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
package/runtime/index.html
CHANGED
|
@@ -117,13 +117,21 @@ https://github.com/nodeca/pako/blob/main/LICENSE
|
|
|
117
117
|
}
|
|
118
118
|
};
|
|
119
119
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
120
|
+
const shouldIgnoreError = (error) => {
|
|
121
|
+
const message = error && error.message ? error.message : String(error || '');
|
|
122
|
+
return message.includes('ResizeObserver loop');
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
window.addEventListener('error', (event) => {
|
|
126
|
+
const error = event.error || event.message;
|
|
127
|
+
if (shouldIgnoreError(error)) return;
|
|
128
|
+
reportError(error, 'window.error');
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
window.addEventListener('unhandledrejection', (event) => {
|
|
132
|
+
if (shouldIgnoreError(event.reason)) return;
|
|
133
|
+
reportError(event.reason, 'unhandledrejection');
|
|
134
|
+
});
|
|
127
135
|
|
|
128
136
|
const clearViewer = () => {
|
|
129
137
|
while (viewer.firstChild) {
|
|
@@ -386,8 +394,12 @@ https://github.com/nodeca/pako/blob/main/LICENSE
|
|
|
386
394
|
});
|
|
387
395
|
|
|
388
396
|
const getPageIndex = (dest) => {
|
|
389
|
-
if (
|
|
397
|
+
if (!dest) return null;
|
|
390
398
|
if (typeof dest === 'string') return getSpineIndexByHref(dest);
|
|
399
|
+
if (typeof dest !== 'object') return null;
|
|
400
|
+
if (dest.kind === 'href') return getSpineIndexByHref(dest.value);
|
|
401
|
+
if (dest.kind === 'pageIndex') return dest.value;
|
|
402
|
+
if (dest.kind === 'pageNumber') return Math.max(0, dest.value - 1);
|
|
391
403
|
return null;
|
|
392
404
|
};
|
|
393
405
|
|
|
@@ -514,6 +526,9 @@ https://github.com/nodeca/pako/blob/main/LICENSE
|
|
|
514
526
|
if (raw && typeof raw === 'object' && raw.kind && raw.id) {
|
|
515
527
|
message = raw;
|
|
516
528
|
} else if (typeof raw === 'string') {
|
|
529
|
+
if (raw.startsWith('setImmediate$')) {
|
|
530
|
+
return;
|
|
531
|
+
}
|
|
517
532
|
const trimmed = raw.trim();
|
|
518
533
|
if (!trimmed || (!trimmed.startsWith('{') && !trimmed.startsWith('['))) {
|
|
519
534
|
return;
|
|
@@ -521,18 +536,15 @@ https://github.com/nodeca/pako/blob/main/LICENSE
|
|
|
521
536
|
try {
|
|
522
537
|
message = JSON.parse(trimmed);
|
|
523
538
|
} catch (err) {
|
|
524
|
-
sendEvent('RUNTIME_ERROR', {
|
|
525
|
-
message: 'Failed to parse message',
|
|
526
|
-
context: 'runtime.onMessage',
|
|
527
|
-
stack: err && err.stack ? err.stack : null,
|
|
528
|
-
preview: trimmed.slice(0, 200),
|
|
529
|
-
});
|
|
530
|
-
return;
|
|
531
|
-
}
|
|
539
|
+
sendEvent('RUNTIME_ERROR', {
|
|
540
|
+
message: 'Failed to parse message',
|
|
541
|
+
context: 'runtime.onMessage',
|
|
542
|
+
stack: err && err.stack ? err.stack : null,
|
|
543
|
+
preview: trimmed.slice(0, 200),
|
|
544
|
+
});
|
|
545
|
+
return;
|
|
546
|
+
}
|
|
532
547
|
} else {
|
|
533
|
-
sendEvent('RUNTIME_LOG', {
|
|
534
|
-
message: `Ignoring message of type ${typeof raw}`,
|
|
535
|
-
});
|
|
536
548
|
return;
|
|
537
549
|
}
|
|
538
550
|
|
package/runtime/runtime.js
CHANGED
|
@@ -293,8 +293,12 @@
|
|
|
293
293
|
});
|
|
294
294
|
|
|
295
295
|
const getPageIndex = (dest) => {
|
|
296
|
-
if (
|
|
296
|
+
if (!dest) return null;
|
|
297
297
|
if (typeof dest === 'string') return getSpineIndexByHref(dest);
|
|
298
|
+
if (typeof dest !== 'object') return null;
|
|
299
|
+
if (dest.kind === 'href') return getSpineIndexByHref(dest.value);
|
|
300
|
+
if (dest.kind === 'pageIndex') return dest.value;
|
|
301
|
+
if (dest.kind === 'pageNumber') return Math.max(0, dest.value - 1);
|
|
298
302
|
return null;
|
|
299
303
|
};
|
|
300
304
|
|
|
@@ -413,16 +417,30 @@
|
|
|
413
417
|
}
|
|
414
418
|
};
|
|
415
419
|
|
|
416
|
-
const onMessage = (event) => {
|
|
417
|
-
let message = null;
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
420
|
+
const onMessage = (event) => {
|
|
421
|
+
let message = null;
|
|
422
|
+
const raw = event && typeof event === 'object' ? event.data : null;
|
|
423
|
+
|
|
424
|
+
if (raw && typeof raw === 'object' && raw.kind && raw.id) {
|
|
425
|
+
message = raw;
|
|
426
|
+
} else if (typeof raw === 'string') {
|
|
427
|
+
if (raw.startsWith('setImmediate$')) return;
|
|
428
|
+
const trimmed = raw.trim();
|
|
429
|
+
if (!trimmed || (!trimmed.startsWith('{') && !trimmed.startsWith('['))) {
|
|
430
|
+
return;
|
|
431
|
+
}
|
|
432
|
+
try {
|
|
433
|
+
message = JSON.parse(trimmed);
|
|
434
|
+
} catch (err) {
|
|
435
|
+
return;
|
|
436
|
+
}
|
|
437
|
+
} else {
|
|
438
|
+
return;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
if (!message || !message.kind || message.id == null) return;
|
|
442
|
+
handleCommand(message);
|
|
443
|
+
};
|
|
426
444
|
|
|
427
445
|
window.addEventListener('message', onMessage);
|
|
428
446
|
document.addEventListener('message', onMessage);
|