@r-universe/webr 2023.6.21 → 2023.9.18

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.
Files changed (135) hide show
  1. package/dist/R.bin.data +3934 -2174
  2. package/dist/R.bin.js +1 -6
  3. package/dist/R.bin.wasm +0 -0
  4. package/dist/repl/App.d.ts +15 -0
  5. package/dist/repl/components/Editor.d.ts +26 -0
  6. package/dist/repl/components/Files.d.ts +19 -0
  7. package/dist/repl/components/Plot.d.ts +7 -0
  8. package/dist/repl/components/Terminal.d.ts +9 -0
  9. package/dist/repl/components/utils.d.ts +11 -0
  10. package/dist/tests/webR/chan/channel-postmessage.test.d.ts +1 -0
  11. package/dist/tests/webR/error.test.d.ts +1 -0
  12. package/dist/vfs/usr/lib/R/library/grDevices/afm/ArialMT-Bold.afm.gz +0 -0
  13. package/dist/vfs/usr/lib/R/library/grDevices/afm/ArialMT-BoldItalic.afm.gz +0 -0
  14. package/dist/vfs/usr/lib/R/library/grDevices/afm/ArialMT-Italic.afm.gz +0 -0
  15. package/dist/vfs/usr/lib/R/library/grDevices/afm/ArialMT.afm.gz +0 -0
  16. package/dist/vfs/usr/lib/R/library/grDevices/afm/CM_boldx_10.afm.gz +0 -0
  17. package/dist/vfs/usr/lib/R/library/grDevices/afm/CM_boldx_italic_10.afm.gz +0 -0
  18. package/dist/vfs/usr/lib/R/library/grDevices/afm/CM_italic_10.afm.gz +0 -0
  19. package/dist/vfs/usr/lib/R/library/grDevices/afm/CM_regular_10.afm.gz +0 -0
  20. package/dist/vfs/usr/lib/R/library/grDevices/afm/CM_symbol_10.afm.gz +0 -0
  21. package/dist/vfs/usr/lib/R/library/grDevices/afm/Courier-Bold.afm.gz +0 -0
  22. package/dist/vfs/usr/lib/R/library/grDevices/afm/Courier-BoldOblique.afm.gz +0 -0
  23. package/dist/vfs/usr/lib/R/library/grDevices/afm/Courier-Oblique.afm.gz +0 -0
  24. package/dist/vfs/usr/lib/R/library/grDevices/afm/Courier.afm.gz +0 -0
  25. package/dist/vfs/usr/lib/R/library/grDevices/afm/Helvetica-Bold.afm.gz +0 -0
  26. package/dist/vfs/usr/lib/R/library/grDevices/afm/Helvetica-BoldOblique.afm.gz +0 -0
  27. package/dist/vfs/usr/lib/R/library/grDevices/afm/Helvetica-Oblique.afm.gz +0 -0
  28. package/dist/vfs/usr/lib/R/library/grDevices/afm/Helvetica.afm.gz +0 -0
  29. package/dist/vfs/usr/lib/R/library/grDevices/afm/Symbol.afm.gz +0 -0
  30. package/dist/vfs/usr/lib/R/library/grDevices/afm/Times-Bold.afm.gz +0 -0
  31. package/dist/vfs/usr/lib/R/library/grDevices/afm/Times-BoldItalic.afm.gz +0 -0
  32. package/dist/vfs/usr/lib/R/library/grDevices/afm/Times-Italic.afm.gz +0 -0
  33. package/dist/vfs/usr/lib/R/library/grDevices/afm/Times-Roman.afm.gz +0 -0
  34. package/dist/vfs/usr/lib/R/library/grDevices/afm/ZapfDingbats.afm.gz +0 -0
  35. package/dist/vfs/usr/lib/R/library/grDevices/afm/a010013l.afm.gz +0 -0
  36. package/dist/vfs/usr/lib/R/library/grDevices/afm/a010015l.afm.gz +0 -0
  37. package/dist/vfs/usr/lib/R/library/grDevices/afm/a010033l.afm.gz +0 -0
  38. package/dist/vfs/usr/lib/R/library/grDevices/afm/a010035l.afm.gz +0 -0
  39. package/dist/vfs/usr/lib/R/library/grDevices/afm/agd_____.afm.gz +0 -0
  40. package/dist/vfs/usr/lib/R/library/grDevices/afm/agdo____.afm.gz +0 -0
  41. package/dist/vfs/usr/lib/R/library/grDevices/afm/agw_____.afm.gz +0 -0
  42. package/dist/vfs/usr/lib/R/library/grDevices/afm/agwo____.afm.gz +0 -0
  43. package/dist/vfs/usr/lib/R/library/grDevices/afm/b018012l.afm.gz +0 -0
  44. package/dist/vfs/usr/lib/R/library/grDevices/afm/b018015l.afm.gz +0 -0
  45. package/dist/vfs/usr/lib/R/library/grDevices/afm/b018032l.afm.gz +0 -0
  46. package/dist/vfs/usr/lib/R/library/grDevices/afm/b018035l.afm.gz +0 -0
  47. package/dist/vfs/usr/lib/R/library/grDevices/afm/bkd_____.afm.gz +0 -0
  48. package/dist/vfs/usr/lib/R/library/grDevices/afm/bkdi____.afm.gz +0 -0
  49. package/dist/vfs/usr/lib/R/library/grDevices/afm/bkl_____.afm.gz +0 -0
  50. package/dist/vfs/usr/lib/R/library/grDevices/afm/bkli____.afm.gz +0 -0
  51. package/dist/vfs/usr/lib/R/library/grDevices/afm/c059013l.afm.gz +0 -0
  52. package/dist/vfs/usr/lib/R/library/grDevices/afm/c059016l.afm.gz +0 -0
  53. package/dist/vfs/usr/lib/R/library/grDevices/afm/c059033l.afm.gz +0 -0
  54. package/dist/vfs/usr/lib/R/library/grDevices/afm/c059036l.afm.gz +0 -0
  55. package/dist/vfs/usr/lib/R/library/grDevices/afm/cmbxti10.afm.gz +0 -0
  56. package/dist/vfs/usr/lib/R/library/grDevices/afm/cmti10.afm.gz +0 -0
  57. package/dist/vfs/usr/lib/R/library/grDevices/afm/cob_____.afm.gz +0 -0
  58. package/dist/vfs/usr/lib/R/library/grDevices/afm/cobo____.afm.gz +0 -0
  59. package/dist/vfs/usr/lib/R/library/grDevices/afm/com_____.afm.gz +0 -0
  60. package/dist/vfs/usr/lib/R/library/grDevices/afm/coo_____.afm.gz +0 -0
  61. package/dist/vfs/usr/lib/R/library/grDevices/afm/hv______.afm.gz +0 -0
  62. package/dist/vfs/usr/lib/R/library/grDevices/afm/hvb_____.afm.gz +0 -0
  63. package/dist/vfs/usr/lib/R/library/grDevices/afm/hvbo____.afm.gz +0 -0
  64. package/dist/vfs/usr/lib/R/library/grDevices/afm/hvn_____.afm.gz +0 -0
  65. package/dist/vfs/usr/lib/R/library/grDevices/afm/hvnb____.afm.gz +0 -0
  66. package/dist/vfs/usr/lib/R/library/grDevices/afm/hvnbo___.afm.gz +0 -0
  67. package/dist/vfs/usr/lib/R/library/grDevices/afm/hvno____.afm.gz +0 -0
  68. package/dist/vfs/usr/lib/R/library/grDevices/afm/hvo_____.afm.gz +0 -0
  69. package/dist/vfs/usr/lib/R/library/grDevices/afm/n019003l.afm.gz +0 -0
  70. package/dist/vfs/usr/lib/R/library/grDevices/afm/n019004l.afm.gz +0 -0
  71. package/dist/vfs/usr/lib/R/library/grDevices/afm/n019023l.afm.gz +0 -0
  72. package/dist/vfs/usr/lib/R/library/grDevices/afm/n019024l.afm.gz +0 -0
  73. package/dist/vfs/usr/lib/R/library/grDevices/afm/n019043l.afm.gz +0 -0
  74. package/dist/vfs/usr/lib/R/library/grDevices/afm/n019044l.afm.gz +0 -0
  75. package/dist/vfs/usr/lib/R/library/grDevices/afm/n019063l.afm.gz +0 -0
  76. package/dist/vfs/usr/lib/R/library/grDevices/afm/n019064l.afm.gz +0 -0
  77. package/dist/vfs/usr/lib/R/library/grDevices/afm/n021003l.afm.gz +0 -0
  78. package/dist/vfs/usr/lib/R/library/grDevices/afm/n021004l.afm.gz +0 -0
  79. package/dist/vfs/usr/lib/R/library/grDevices/afm/n021023l.afm.gz +0 -0
  80. package/dist/vfs/usr/lib/R/library/grDevices/afm/n021024l.afm.gz +0 -0
  81. package/dist/vfs/usr/lib/R/library/grDevices/afm/n022003l.afm.gz +0 -0
  82. package/dist/vfs/usr/lib/R/library/grDevices/afm/n022004l.afm.gz +0 -0
  83. package/dist/vfs/usr/lib/R/library/grDevices/afm/n022023l.afm.gz +0 -0
  84. package/dist/vfs/usr/lib/R/library/grDevices/afm/n022024l.afm.gz +0 -0
  85. package/dist/vfs/usr/lib/R/library/grDevices/afm/ncb_____.afm.gz +0 -0
  86. package/dist/vfs/usr/lib/R/library/grDevices/afm/ncbi____.afm.gz +0 -0
  87. package/dist/vfs/usr/lib/R/library/grDevices/afm/nci_____.afm.gz +0 -0
  88. package/dist/vfs/usr/lib/R/library/grDevices/afm/ncr_____.afm.gz +0 -0
  89. package/dist/vfs/usr/lib/R/library/grDevices/afm/p052003l.afm.gz +0 -0
  90. package/dist/vfs/usr/lib/R/library/grDevices/afm/p052004l.afm.gz +0 -0
  91. package/dist/vfs/usr/lib/R/library/grDevices/afm/p052023l.afm.gz +0 -0
  92. package/dist/vfs/usr/lib/R/library/grDevices/afm/p052024l.afm.gz +0 -0
  93. package/dist/vfs/usr/lib/R/library/grDevices/afm/pob_____.afm.gz +0 -0
  94. package/dist/vfs/usr/lib/R/library/grDevices/afm/pobi____.afm.gz +0 -0
  95. package/dist/vfs/usr/lib/R/library/grDevices/afm/poi_____.afm.gz +0 -0
  96. package/dist/vfs/usr/lib/R/library/grDevices/afm/por_____.afm.gz +0 -0
  97. package/dist/vfs/usr/lib/R/library/grDevices/afm/s050000l.afm.gz +0 -0
  98. package/dist/vfs/usr/lib/R/library/grDevices/afm/sy______.afm.gz +0 -0
  99. package/dist/vfs/usr/lib/R/library/grDevices/afm/tib_____.afm.gz +0 -0
  100. package/dist/vfs/usr/lib/R/library/grDevices/afm/tibi____.afm.gz +0 -0
  101. package/dist/vfs/usr/lib/R/library/grDevices/afm/tii_____.afm.gz +0 -0
  102. package/dist/vfs/usr/lib/R/library/grDevices/afm/tir_____.afm.gz +0 -0
  103. package/dist/vfs/usr/lib/R/library/parallel/DESCRIPTION +1 -1
  104. package/dist/vfs/usr/lib/R/library/parallel/Meta/package.rds +0 -0
  105. package/dist/vfs/usr/lib/R/library/tcltk/DESCRIPTION +1 -1
  106. package/dist/vfs/usr/lib/R/library/tcltk/Meta/package.rds +0 -0
  107. package/dist/vfs/usr/lib/R/library/tools/help/tools.rdb +0 -0
  108. package/dist/vfs/usr/lib/R/library/translations/Meta/package.rds +0 -0
  109. package/dist/webR/chan/channel-common.d.ts +4 -2
  110. package/dist/webR/chan/channel-postmessage.d.ts +26 -0
  111. package/dist/webR/chan/channel-shared.d.ts +1 -0
  112. package/dist/webR/chan/channel.d.ts +1 -0
  113. package/dist/webR/console.d.ts +6 -2
  114. package/dist/webR/emscripten.d.ts +7 -0
  115. package/dist/webR/error.d.ts +26 -0
  116. package/dist/webR/payload.d.ts +1 -1
  117. package/dist/webR/webr-chan.d.ts +18 -0
  118. package/dist/webR/webr-main.d.ts +7 -0
  119. package/dist/webr-serviceworker.js +14 -3
  120. package/dist/webr-serviceworker.js.map +3 -3
  121. package/dist/webr-serviceworker.mjs +14 -3
  122. package/dist/webr-serviceworker.mjs.map +3 -3
  123. package/dist/webr-worker.js +435 -175
  124. package/dist/webr-worker.js.map +4 -4
  125. package/dist/webr.cjs +3 -3
  126. package/dist/webr.cjs.map +4 -4
  127. package/dist/webr.mjs +3 -3
  128. package/dist/webr.mjs.map +4 -4
  129. package/package.json +20 -18
  130. package/dist/repl/fstree.d.ts +0 -57
  131. package/dist/repl/repl.d.ts +0 -1
  132. package/dist/vfs/usr/lib/R/library/grDevices/libs/grDevices.so +0 -0
  133. package/dist/vfs/usr/lib/R/modules/internet.so +0 -0
  134. package/dist/vfs/usr/lib/R/modules/lapack.so +0 -0
  135. package/templates/repl.html +0 -134
@@ -42,6 +42,14 @@ var __privateSet = (obj, member, value, setter) => {
42
42
  setter ? setter.call(obj, value) : member.set(obj, value);
43
43
  return value;
44
44
  };
45
+ var __privateWrapper = (obj, member, setter, getter) => ({
46
+ set _(value) {
47
+ __privateSet(obj, member, value, setter);
48
+ },
49
+ get _() {
50
+ return __privateGet(obj, member, getter);
51
+ }
52
+ });
45
53
  var __privateMethod = (obj, member, method) => {
46
54
  __accessCheck(obj, member, "access private method");
47
55
  return method;
@@ -1936,6 +1944,19 @@ var require_XMLHttpRequest = __commonJS({
1936
1944
  }
1937
1945
  });
1938
1946
 
1947
+ // webR/error.ts
1948
+ var WebRError = class extends Error {
1949
+ constructor(msg) {
1950
+ super(msg);
1951
+ this.name = this.constructor.name;
1952
+ Object.setPrototypeOf(this, new.target.prototype);
1953
+ }
1954
+ };
1955
+ var WebRWorkerError = class extends WebRError {
1956
+ };
1957
+ var WebRChannelError = class extends WebRError {
1958
+ };
1959
+
1939
1960
  // webR/compat.ts
1940
1961
  var IN_NODE = typeof process !== "undefined" && process.release && process.release.name === "node";
1941
1962
  var loadScript;
@@ -1965,7 +1986,7 @@ if (globalThis.document) {
1965
1986
  await Promise.resolve().then(() => __toESM(require(nodePathMod.resolve(url))));
1966
1987
  };
1967
1988
  } else {
1968
- throw new Error("Cannot determine runtime environment");
1989
+ throw new WebRError("Cannot determine runtime environment");
1969
1990
  }
1970
1991
 
1971
1992
  // webR/utils.ts
@@ -2025,7 +2046,7 @@ function isCrossOrigin(urlString) {
2025
2046
  function throwUnreachable(context) {
2026
2047
  let msg = "Reached the unreachable";
2027
2048
  msg = msg + (context ? ": " + context : ".");
2028
- throw new Error(msg);
2049
+ throw new WebRError(msg);
2029
2050
  }
2030
2051
 
2031
2052
  // webR/chan/task-common.ts
@@ -2208,9 +2229,11 @@ function newSyncRequest(msg, data) {
2208
2229
  }
2209
2230
 
2210
2231
  // webR/payload.ts
2211
- function webRPayloadError(payload) {
2212
- const e = new Error(payload.obj.message);
2213
- e.name = payload.obj.name;
2232
+ function webRPayloadAsError(payload) {
2233
+ const e = new WebRWorkerError(payload.obj.message);
2234
+ if (payload.obj.name !== "Error") {
2235
+ e.name = payload.obj.name;
2236
+ }
2214
2237
  e.stack = payload.obj.stack;
2215
2238
  return e;
2216
2239
  }
@@ -2263,7 +2286,7 @@ var ChannelMain = class {
2263
2286
  const payload = msg.data.resp;
2264
2287
  __privateGet(this, _parked).delete(uuid);
2265
2288
  if (payload.payloadType === "err") {
2266
- handles.reject(webRPayloadError(payload));
2289
+ handles.reject(webRPayloadAsError(payload));
2267
2290
  } else {
2268
2291
  handles.resolve(payload);
2269
2292
  }
@@ -2454,9 +2477,9 @@ function setInterruptBuffer(buffer) {
2454
2477
  }
2455
2478
 
2456
2479
  // webR/emscripten.ts
2457
- var Module = {};
2480
+ var Module2 = {};
2458
2481
  function dictEmFree(dict) {
2459
- Object.keys(dict).forEach((key) => Module._free(dict[key]));
2482
+ Object.keys(dict).forEach((key) => Module2._free(dict[key]));
2460
2483
  }
2461
2484
 
2462
2485
  // webR/chan/channel-shared.ts
@@ -2500,12 +2523,12 @@ var SharedBufferChannelMain = class extends ChannelMain {
2500
2523
  break;
2501
2524
  }
2502
2525
  default:
2503
- throw new TypeError(`Unsupported request type '${payload.type}'.`);
2526
+ throw new WebRChannelError(`Unsupported request type '${payload.type}'.`);
2504
2527
  }
2505
2528
  return;
2506
2529
  }
2507
2530
  case "request":
2508
- throw new TypeError(
2531
+ throw new WebRChannelError(
2509
2532
  "Can't send messages of type 'request' from a worker. Please Use 'sync-request' instead."
2510
2533
  );
2511
2534
  }
@@ -2535,7 +2558,7 @@ var SharedBufferChannelMain = class extends ChannelMain {
2535
2558
  }
2536
2559
  interrupt() {
2537
2560
  if (!__privateGet(this, _interruptBuffer)) {
2538
- throw new Error("Failed attempt to interrupt before initialising interruptBuffer");
2561
+ throw new WebRChannelError("Failed attempt to interrupt before initialising interruptBuffer");
2539
2562
  }
2540
2563
  this.inputQueue.reset();
2541
2564
  __privateGet(this, _interruptBuffer)[0] = 1;
@@ -2561,6 +2584,8 @@ var SharedBufferChannelWorker = class {
2561
2584
  __privateAdd(this, _interruptBuffer2, new Int32Array(new SharedArrayBuffer(4)));
2562
2585
  __privateAdd(this, _interrupt, () => {
2563
2586
  });
2587
+ this.onMessageFromMainThread = () => {
2588
+ };
2564
2589
  __privateSet(this, _ep, IN_NODE ? require("worker_threads").parentPort : globalThis);
2565
2590
  setInterruptBuffer(__privateGet(this, _interruptBuffer2).buffer);
2566
2591
  setInterruptHandler(() => this.handleInterrupt());
@@ -2583,13 +2608,13 @@ var SharedBufferChannelWorker = class {
2583
2608
  for (; ; ) {
2584
2609
  const msg = this.read();
2585
2610
  if (msg.type === "stdin") {
2586
- return Module.allocateUTF8(msg.data);
2611
+ return Module2.allocateUTF8(msg.data);
2587
2612
  }
2588
2613
  __privateGet(this, _dispatch).call(this, msg);
2589
2614
  }
2590
2615
  }
2591
2616
  run(args) {
2592
- Module.callMain(args);
2617
+ Module2.callMain(args);
2593
2618
  }
2594
2619
  setInterrupt(interrupt) {
2595
2620
  __privateSet(this, _interrupt, interrupt);
@@ -2649,7 +2674,7 @@ var ServiceWorkerChannelMain = class extends ChannelMain {
2649
2674
  return;
2650
2675
  }
2651
2676
  case "request":
2652
- throw new TypeError(
2677
+ throw new WebRChannelError(
2653
2678
  "Can't send messages of type 'request' from a worker.Use service worker fetch request instead."
2654
2679
  );
2655
2680
  }
@@ -2689,7 +2714,7 @@ var ServiceWorkerChannelMain = class extends ChannelMain {
2689
2714
  activeRegistration() {
2690
2715
  var _a;
2691
2716
  if (!((_a = __privateGet(this, _registration)) == null ? void 0 : _a.active)) {
2692
- throw new Error("Attempted to obtain a non-existent active registration.");
2717
+ throw new WebRChannelError("Attempted to obtain a non-existent active registration.");
2693
2718
  }
2694
2719
  return __privateGet(this, _registration).active;
2695
2720
  }
@@ -2731,7 +2756,7 @@ onMessageFromServiceWorker_fn = async function(event) {
2731
2756
  const uuid = event.data.data;
2732
2757
  const message = __privateGet(this, _syncMessageCache).get(uuid);
2733
2758
  if (!message) {
2734
- throw new Error("Request not found during service worker XHR request");
2759
+ throw new WebRChannelError("Request not found during service worker XHR request");
2735
2760
  }
2736
2761
  __privateGet(this, _syncMessageCache).delete(uuid);
2737
2762
  switch (message.type) {
@@ -2756,7 +2781,7 @@ onMessageFromServiceWorker_fn = async function(event) {
2756
2781
  break;
2757
2782
  }
2758
2783
  default:
2759
- throw new TypeError(`Unsupported request type '${message.type}'.`);
2784
+ throw new WebRChannelError(`Unsupported request type '${message.type}'.`);
2760
2785
  }
2761
2786
  return;
2762
2787
  }
@@ -2772,19 +2797,20 @@ handleEventsFromWorker_fn2 = function(worker) {
2772
2797
  }
2773
2798
  };
2774
2799
  _onMessageFromWorker2 = new WeakMap();
2775
- var _ep2, _mainThreadId, _location, _dispatch2, _interrupt2;
2800
+ var _ep2, _mainThreadId, _location, _lastInterruptReq, _dispatch2, _interrupt2;
2776
2801
  var ServiceWorkerChannelWorker = class {
2777
2802
  constructor(data) {
2778
2803
  __privateAdd(this, _ep2, void 0);
2779
2804
  __privateAdd(this, _mainThreadId, void 0);
2780
2805
  __privateAdd(this, _location, void 0);
2806
+ __privateAdd(this, _lastInterruptReq, Date.now());
2781
2807
  __privateAdd(this, _dispatch2, () => 0);
2782
2808
  __privateAdd(this, _interrupt2, () => {
2783
2809
  });
2784
2810
  this.onMessageFromMainThread = () => {
2785
2811
  };
2786
2812
  if (!data.clientId || !data.location) {
2787
- throw Error("Can't start service worker channel");
2813
+ throw new WebRChannelError("Can't start service worker channel");
2788
2814
  }
2789
2815
  __privateSet(this, _mainThreadId, data.clientId);
2790
2816
  __privateSet(this, _location, data.location);
@@ -2833,22 +2859,25 @@ var ServiceWorkerChannelWorker = class {
2833
2859
  for (; ; ) {
2834
2860
  const msg = this.read();
2835
2861
  if (msg.type === "stdin") {
2836
- return Module.allocateUTF8(msg.data);
2862
+ return Module2.allocateUTF8(msg.data);
2837
2863
  }
2838
2864
  __privateGet(this, _dispatch2).call(this, msg);
2839
2865
  }
2840
2866
  }
2841
2867
  run(args) {
2842
- Module.callMain(args);
2868
+ Module2.callMain(args);
2843
2869
  }
2844
2870
  setInterrupt(interrupt) {
2845
2871
  __privateSet(this, _interrupt2, interrupt);
2846
2872
  }
2847
2873
  handleInterrupt() {
2848
- const response = this.syncRequest({ type: "interrupt" });
2849
- const interrupted = response.data.resp;
2850
- if (interrupted) {
2851
- __privateGet(this, _interrupt2).call(this);
2874
+ if (Date.now() > __privateGet(this, _lastInterruptReq) + 1e3) {
2875
+ __privateSet(this, _lastInterruptReq, Date.now());
2876
+ const response = this.syncRequest({ type: "interrupt" });
2877
+ const interrupted = response.data.resp;
2878
+ if (interrupted) {
2879
+ __privateGet(this, _interrupt2).call(this);
2880
+ }
2852
2881
  }
2853
2882
  }
2854
2883
  setDispatchHandler(dispatch2) {
@@ -2858,14 +2887,239 @@ var ServiceWorkerChannelWorker = class {
2858
2887
  _ep2 = new WeakMap();
2859
2888
  _mainThreadId = new WeakMap();
2860
2889
  _location = new WeakMap();
2890
+ _lastInterruptReq = new WeakMap();
2861
2891
  _dispatch2 = new WeakMap();
2862
2892
  _interrupt2 = new WeakMap();
2863
2893
 
2894
+ // webR/chan/channel-postmessage.ts
2895
+ if (IN_NODE) {
2896
+ globalThis.Worker = require("worker_threads").Worker;
2897
+ }
2898
+ var _worker, _handleEventsFromWorker3, handleEventsFromWorker_fn3, _onMessageFromWorker3;
2899
+ var PostMessageChannelMain = class extends ChannelMain {
2900
+ constructor(config) {
2901
+ super();
2902
+ __privateAdd(this, _handleEventsFromWorker3);
2903
+ this.close = () => {
2904
+ };
2905
+ __privateAdd(this, _worker, void 0);
2906
+ __privateAdd(this, _onMessageFromWorker3, async (worker, message) => {
2907
+ if (!message || !message.type) {
2908
+ return;
2909
+ }
2910
+ switch (message.type) {
2911
+ case "resolve":
2912
+ this.resolve();
2913
+ return;
2914
+ case "response":
2915
+ this.resolveResponse(message);
2916
+ return;
2917
+ case "system":
2918
+ this.systemQueue.put(message.data);
2919
+ return;
2920
+ default:
2921
+ this.outputQueue.put(message);
2922
+ return;
2923
+ case "request": {
2924
+ const msg = message;
2925
+ const payload = msg.data.msg;
2926
+ switch (payload.type) {
2927
+ case "read": {
2928
+ const input = await this.inputQueue.get();
2929
+ if (__privateGet(this, _worker)) {
2930
+ const response = newResponse(msg.data.uuid, input);
2931
+ __privateGet(this, _worker).postMessage(response);
2932
+ }
2933
+ break;
2934
+ }
2935
+ default:
2936
+ throw new WebRChannelError(`Unsupported request type '${payload.type}'.`);
2937
+ }
2938
+ return;
2939
+ }
2940
+ case "sync-request":
2941
+ throw new WebRChannelError(
2942
+ "Can't send messages of type 'sync-request' in PostMessage mode. Use 'request' instead."
2943
+ );
2944
+ }
2945
+ });
2946
+ const initWorker = (worker) => {
2947
+ __privateSet(this, _worker, worker);
2948
+ __privateMethod(this, _handleEventsFromWorker3, handleEventsFromWorker_fn3).call(this, worker);
2949
+ this.close = () => worker.terminate();
2950
+ const msg = {
2951
+ type: "init",
2952
+ data: { config, channelType: ChannelType.PostMessage }
2953
+ };
2954
+ worker.postMessage(msg);
2955
+ };
2956
+ if (isCrossOrigin(config.baseUrl)) {
2957
+ newCrossOriginWorker(
2958
+ `${config.baseUrl}webr-worker.js`,
2959
+ (worker) => initWorker(worker)
2960
+ );
2961
+ } else {
2962
+ const worker = new Worker(`${config.baseUrl}webr-worker.js`);
2963
+ initWorker(worker);
2964
+ }
2965
+ ({ resolve: this.resolve, promise: this.initialised } = promiseHandles());
2966
+ }
2967
+ interrupt() {
2968
+ console.error("Interrupting R execution is not available when using the PostMessage channel");
2969
+ }
2970
+ };
2971
+ _worker = new WeakMap();
2972
+ _handleEventsFromWorker3 = new WeakSet();
2973
+ handleEventsFromWorker_fn3 = function(worker) {
2974
+ if (IN_NODE) {
2975
+ worker.on("message", (message) => {
2976
+ __privateGet(this, _onMessageFromWorker3).call(this, worker, message);
2977
+ });
2978
+ } else {
2979
+ worker.onmessage = (ev) => __privateGet(this, _onMessageFromWorker3).call(this, worker, ev.data);
2980
+ }
2981
+ };
2982
+ _onMessageFromWorker3 = new WeakMap();
2983
+ var _ep3, _parked2, _dispatch3, _promptDepth, _interrupt3, _asyncREPL;
2984
+ var PostMessageChannelWorker = class {
2985
+ constructor() {
2986
+ __privateAdd(this, _ep3, void 0);
2987
+ __privateAdd(this, _parked2, /* @__PURE__ */ new Map());
2988
+ __privateAdd(this, _dispatch3, () => 0);
2989
+ __privateAdd(this, _promptDepth, 0);
2990
+ __privateAdd(this, _interrupt3, () => {
2991
+ });
2992
+ /*
2993
+ * This is a fallback REPL for webR running in PostMessage mode. The prompt
2994
+ * section of R's R_ReplDLLdo1 returns empty with -1, which allows this
2995
+ * fallback REPL to yield to the event loop with await.
2996
+ *
2997
+ * The drawback of this approach is that nested REPLs do not work, such as
2998
+ * realine, browser or menu. Attempting to use a nested REPL prints an error
2999
+ * to the JS console.
3000
+ *
3001
+ * R/Wasm errors during execution are caught and the REPL is restarted at the
3002
+ * top level. Any other JS errors are re-thrown.
3003
+ */
3004
+ __privateAdd(this, _asyncREPL, async () => {
3005
+ for (; ; ) {
3006
+ try {
3007
+ __privateSet(this, _promptDepth, 0);
3008
+ const msg = await this.request({ type: "read" });
3009
+ if (msg.type === "stdin") {
3010
+ const str = Module.allocateUTF8(msg.data);
3011
+ Module._strcpy(Module._DLLbuf, str);
3012
+ Module.setValue(Module._DLLbufp, Module._DLLbuf, "*");
3013
+ Module._free(str);
3014
+ try {
3015
+ while (Module._R_ReplDLLdo1() > 0)
3016
+ ;
3017
+ } catch (e) {
3018
+ if (e instanceof WebAssembly.Exception) {
3019
+ Module._R_ReplDLLinit();
3020
+ Module._R_ReplDLLdo1();
3021
+ } else {
3022
+ throw e;
3023
+ }
3024
+ }
3025
+ } else {
3026
+ __privateGet(this, _dispatch3).call(this, msg);
3027
+ }
3028
+ } catch (e) {
3029
+ if (!(e instanceof WebAssembly.Exception)) {
3030
+ throw e;
3031
+ }
3032
+ }
3033
+ }
3034
+ });
3035
+ __privateSet(this, _ep3, IN_NODE ? require("worker_threads").parentPort : globalThis);
3036
+ }
3037
+ resolve() {
3038
+ this.write({ type: "resolve" });
3039
+ }
3040
+ write(msg, transfer2) {
3041
+ __privateGet(this, _ep3).postMessage(msg, transfer2);
3042
+ }
3043
+ writeSystem(msg, transfer2) {
3044
+ __privateGet(this, _ep3).postMessage({ type: "system", data: msg }, transfer2);
3045
+ }
3046
+ read() {
3047
+ throw new WebRChannelError(
3048
+ "Unable to synchronously read when using the `PostMessage` channel."
3049
+ );
3050
+ }
3051
+ inputOrDispatch() {
3052
+ if (__privateGet(this, _promptDepth) > 10) {
3053
+ __privateGet(this, _interrupt3).call(this);
3054
+ } else if (__privateGet(this, _promptDepth) > 0) {
3055
+ this.writeSystem({
3056
+ type: "console.error",
3057
+ data: "Nested REPL prompts are not available when using the `PostMessage` channel."
3058
+ });
3059
+ }
3060
+ __privateWrapper(this, _promptDepth)._++;
3061
+ return 0;
3062
+ }
3063
+ run(_args) {
3064
+ const args = _args || [];
3065
+ args.unshift("R");
3066
+ const argc = args.length;
3067
+ const argv = Module._malloc(4 * (argc + 1));
3068
+ args.forEach((arg, idx) => {
3069
+ const argvPtr = argv + 4 * idx;
3070
+ const argPtr = Module.allocateUTF8(arg);
3071
+ Module.setValue(argvPtr, argPtr, "*");
3072
+ });
3073
+ this.writeSystem({
3074
+ type: "console.warn",
3075
+ data: "WebR is using `PostMessage` communication channel, nested R REPLs are not available."
3076
+ });
3077
+ Module._Rf_initialize_R(argc, argv);
3078
+ Module._setup_Rmainloop();
3079
+ Module._R_ReplDLLinit();
3080
+ Module._R_ReplDLLdo1();
3081
+ __privateGet(this, _asyncREPL).call(this);
3082
+ }
3083
+ setDispatchHandler(dispatch2) {
3084
+ __privateSet(this, _dispatch3, dispatch2);
3085
+ }
3086
+ async request(msg, transferables) {
3087
+ const req = newRequest(msg, transferables);
3088
+ const { resolve, promise: prom } = promiseHandles();
3089
+ __privateGet(this, _parked2).set(req.data.uuid, resolve);
3090
+ this.write(req);
3091
+ return prom;
3092
+ }
3093
+ setInterrupt(interrupt) {
3094
+ __privateSet(this, _interrupt3, interrupt);
3095
+ }
3096
+ handleInterrupt() {
3097
+ }
3098
+ onMessageFromMainThread(message) {
3099
+ const msg = message;
3100
+ const uuid = msg.data.uuid;
3101
+ const resolve = __privateGet(this, _parked2).get(uuid);
3102
+ if (resolve) {
3103
+ __privateGet(this, _parked2).delete(uuid);
3104
+ resolve(msg.data.resp);
3105
+ } else {
3106
+ console.warn("Can't find request.");
3107
+ }
3108
+ }
3109
+ };
3110
+ _ep3 = new WeakMap();
3111
+ _parked2 = new WeakMap();
3112
+ _dispatch3 = new WeakMap();
3113
+ _promptDepth = new WeakMap();
3114
+ _interrupt3 = new WeakMap();
3115
+ _asyncREPL = new WeakMap();
3116
+
2864
3117
  // webR/chan/channel-common.ts
2865
3118
  var ChannelType = {
2866
3119
  Automatic: 0,
2867
3120
  SharedArrayBuffer: 1,
2868
- ServiceWorker: 2
3121
+ ServiceWorker: 2,
3122
+ PostMessage: 3
2869
3123
  };
2870
3124
  function newChannelWorker(msg) {
2871
3125
  switch (msg.data.channelType) {
@@ -2873,8 +3127,10 @@ function newChannelWorker(msg) {
2873
3127
  return new SharedBufferChannelWorker();
2874
3128
  case ChannelType.ServiceWorker:
2875
3129
  return new ServiceWorkerChannelWorker(msg.data);
3130
+ case ChannelType.PostMessage:
3131
+ return new PostMessageChannelWorker();
2876
3132
  default:
2877
- throw new Error("Unknown worker channel type recieved");
3133
+ throw new WebRChannelError("Unknown worker channel type recieved");
2878
3134
  }
2879
3135
  }
2880
3136
 
@@ -2917,33 +3173,33 @@ function isComplex(value) {
2917
3173
 
2918
3174
  // webR/utils-r.ts
2919
3175
  function protect(x) {
2920
- Module._Rf_protect(handlePtr(x));
3176
+ Module2._Rf_protect(handlePtr(x));
2921
3177
  return x;
2922
3178
  }
2923
3179
  function protectInc(x, prot) {
2924
- Module._Rf_protect(handlePtr(x));
3180
+ Module2._Rf_protect(handlePtr(x));
2925
3181
  ++prot.n;
2926
3182
  return x;
2927
3183
  }
2928
3184
  function protectWithIndex(x) {
2929
- const pLoc = Module._malloc(4);
2930
- Module._R_ProtectWithIndex(handlePtr(x), pLoc);
2931
- const loc = Module.getValue(pLoc, "i32");
3185
+ const pLoc = Module2._malloc(4);
3186
+ Module2._R_ProtectWithIndex(handlePtr(x), pLoc);
3187
+ const loc = Module2.getValue(pLoc, "i32");
2932
3188
  return { loc, ptr: pLoc };
2933
3189
  }
2934
3190
  function unprotectIndex(index) {
2935
- Module._Rf_unprotect(1);
2936
- Module._free(index.ptr);
3191
+ Module2._Rf_unprotect(1);
3192
+ Module2._free(index.ptr);
2937
3193
  }
2938
3194
  function reprotect(x, index) {
2939
- Module._R_Reprotect(handlePtr(x), index.loc);
3195
+ Module2._R_Reprotect(handlePtr(x), index.loc);
2940
3196
  return x;
2941
3197
  }
2942
3198
  function unprotect(n) {
2943
- Module._Rf_unprotect(n);
3199
+ Module2._Rf_unprotect(n);
2944
3200
  }
2945
3201
  function envPoke(env, sym, value) {
2946
- Module._Rf_defineVar(handlePtr(sym), handlePtr(value), handlePtr(env));
3202
+ Module2._Rf_defineVar(handlePtr(sym), handlePtr(value), handlePtr(env));
2947
3203
  }
2948
3204
  function parseEvalBare(code, env) {
2949
3205
  const strings = {};
@@ -2951,8 +3207,8 @@ function parseEvalBare(code, env) {
2951
3207
  try {
2952
3208
  const envObj = new REnvironment(env);
2953
3209
  protectInc(envObj, prot);
2954
- strings.code = Module.allocateUTF8(code);
2955
- const out = Module._R_ParseEvalString(strings.code, envObj.ptr);
3210
+ strings.code = Module2.allocateUTF8(code);
3211
+ const out = Module2._R_ParseEvalString(strings.code, envObj.ptr);
2956
3212
  return RObject.wrap(out);
2957
3213
  } finally {
2958
3214
  dictEmFree(strings);
@@ -2967,7 +3223,7 @@ var UnwindProtectException = class extends Error {
2967
3223
  }
2968
3224
  };
2969
3225
  function safeEval(call, env) {
2970
- return Module.getWasmTableEntry(Module.GOT.ffi_safe_eval.value)(
3226
+ return Module2.getWasmTableEntry(Module2.GOT.ffi_safe_eval.value)(
2971
3227
  handlePtr(call),
2972
3228
  handlePtr(env)
2973
3229
  );
@@ -2982,14 +3238,14 @@ function handlePtr(x) {
2982
3238
  }
2983
3239
  }
2984
3240
  function assertRType(obj, type) {
2985
- if (Module._TYPEOF(obj.ptr) !== RTypeMap[type]) {
3241
+ if (Module2._TYPEOF(obj.ptr) !== RTypeMap[type]) {
2986
3242
  throw new Error(`Unexpected object type "${obj.type()}" when expecting type "${type}"`);
2987
3243
  }
2988
3244
  }
2989
3245
  var shelters = /* @__PURE__ */ new Map();
2990
3246
  function keep(shelter, x) {
2991
3247
  const ptr = handlePtr(x);
2992
- Module._R_PreserveObject(ptr);
3248
+ Module2._R_PreserveObject(ptr);
2993
3249
  if (shelter === void 0) {
2994
3250
  return;
2995
3251
  }
@@ -3001,7 +3257,7 @@ function keep(shelter, x) {
3001
3257
  }
3002
3258
  function destroy(shelter, x) {
3003
3259
  const ptr = handlePtr(x);
3004
- Module._R_ReleaseObject(ptr);
3260
+ Module2._R_ReleaseObject(ptr);
3005
3261
  const objs2 = shelters.get(shelter);
3006
3262
  const loc = objs2.indexOf(ptr);
3007
3263
  if (loc < 0) {
@@ -3013,7 +3269,7 @@ function purge(shelter) {
3013
3269
  const ptrs = shelters.get(shelter);
3014
3270
  for (const ptr of ptrs) {
3015
3271
  try {
3016
- Module._R_ReleaseObject(ptr);
3272
+ Module2._R_ReleaseObject(ptr);
3017
3273
  } catch (e) {
3018
3274
  console.error(e);
3019
3275
  }
@@ -3062,7 +3318,7 @@ var RObjectBase = class {
3062
3318
  this.ptr = ptr;
3063
3319
  }
3064
3320
  type() {
3065
- const typeNumber = Module._TYPEOF(this.ptr);
3321
+ const typeNumber = Module2._TYPEOF(this.ptr);
3066
3322
  const type = Object.keys(RTypeMap).find(
3067
3323
  (typeName) => RTypeMap[typeName] === typeNumber
3068
3324
  );
@@ -3079,7 +3335,7 @@ var _RObject = class extends RObjectBase {
3079
3335
  __privateAdd(this, _slice);
3080
3336
  }
3081
3337
  static wrap(ptr) {
3082
- const type = Module._TYPEOF(ptr);
3338
+ const type = Module2._TYPEOF(ptr);
3083
3339
  return new (getRWorkerClass(type))(new RObjectBase(ptr));
3084
3340
  }
3085
3341
  get [Symbol.toStringTag]() {
@@ -3097,13 +3353,13 @@ var _RObject = class extends RObjectBase {
3097
3353
  parseEvalBare(".Internal(inspect(x))", { x: this });
3098
3354
  }
3099
3355
  isNull() {
3100
- return Module._TYPEOF(this.ptr) === RTypeMap.null;
3356
+ return Module2._TYPEOF(this.ptr) === RTypeMap.null;
3101
3357
  }
3102
3358
  isUnbound() {
3103
3359
  return this.ptr === objs.unboundValue.ptr;
3104
3360
  }
3105
3361
  attrs() {
3106
- return RPairlist.wrap(Module._ATTRIB(this.ptr));
3362
+ return RPairlist.wrap(Module2._ATTRIB(this.ptr));
3107
3363
  }
3108
3364
  setNames(values) {
3109
3365
  let namesObj;
@@ -3114,11 +3370,11 @@ var _RObject = class extends RObjectBase {
3114
3370
  } else {
3115
3371
  throw new Error("Argument to setNames must be null or an Array of strings or null");
3116
3372
  }
3117
- Module._Rf_setAttrib(this.ptr, objs.namesSymbol.ptr, namesObj.ptr);
3373
+ Module2._Rf_setAttrib(this.ptr, objs.namesSymbol.ptr, namesObj.ptr);
3118
3374
  return this;
3119
3375
  }
3120
3376
  names() {
3121
- const names = RCharacter.wrap(Module._Rf_getAttrib(this.ptr, objs.namesSymbol.ptr));
3377
+ const names = RCharacter.wrap(Module2._Rf_getAttrib(this.ptr, objs.namesSymbol.ptr));
3122
3378
  if (names.isNull()) {
3123
3379
  return null;
3124
3380
  } else {
@@ -3162,7 +3418,7 @@ var _RObject = class extends RObjectBase {
3162
3418
  const valueObj = new _RObject(value);
3163
3419
  protectInc(valueObj, prot);
3164
3420
  const assign = new RSymbol("[[<-");
3165
- const call = Module._Rf_lang4(assign.ptr, this.ptr, idx.ptr, valueObj.ptr);
3421
+ const call = Module2._Rf_lang4(assign.ptr, this.ptr, idx.ptr, valueObj.ptr);
3166
3422
  protectInc(call, prot);
3167
3423
  return _RObject.wrap(safeEval(call, objs.baseEnv));
3168
3424
  } finally {
@@ -3186,7 +3442,7 @@ slice_fn = function(prop, op) {
3186
3442
  try {
3187
3443
  const idx = new _RObject(prop);
3188
3444
  protectInc(idx, prot);
3189
- const call = Module._Rf_lang3(op, this.ptr, idx.ptr);
3445
+ const call = Module2._Rf_lang3(op, this.ptr, idx.ptr);
3190
3446
  protectInc(call, prot);
3191
3447
  return _RObject.wrap(safeEval(call, objs.baseEnv));
3192
3448
  } finally {
@@ -3195,7 +3451,7 @@ slice_fn = function(prop, op) {
3195
3451
  };
3196
3452
  var RNull = class extends RObject {
3197
3453
  constructor() {
3198
- super(new RObjectBase(Module.getValue(Module._R_NilValue, "*")));
3454
+ super(new RObjectBase(Module2.getValue(Module2._R_NilValue, "*")));
3199
3455
  return this;
3200
3456
  }
3201
3457
  toJs() {
@@ -3212,11 +3468,11 @@ var RSymbol = class extends RObject {
3212
3468
  super(x);
3213
3469
  return;
3214
3470
  }
3215
- const name = Module.allocateUTF8(x);
3471
+ const name = Module2.allocateUTF8(x);
3216
3472
  try {
3217
- super(new RObjectBase(Module._Rf_install(name)));
3473
+ super(new RObjectBase(Module2._Rf_install(name)));
3218
3474
  } finally {
3219
- Module._free(name);
3475
+ Module2._free(name);
3220
3476
  }
3221
3477
  }
3222
3478
  toJs() {
@@ -3239,13 +3495,13 @@ var RSymbol = class extends RObject {
3239
3495
  return this.printname().toString();
3240
3496
  }
3241
3497
  printname() {
3242
- return RString.wrap(Module._PRINTNAME(this.ptr));
3498
+ return RString.wrap(Module2._PRINTNAME(this.ptr));
3243
3499
  }
3244
3500
  symvalue() {
3245
- return RObject.wrap(Module._SYMVALUE(this.ptr));
3501
+ return RObject.wrap(Module2._SYMVALUE(this.ptr));
3246
3502
  }
3247
3503
  internal() {
3248
- return RObject.wrap(Module._INTERNAL(this.ptr));
3504
+ return RObject.wrap(Module2._INTERNAL(this.ptr));
3249
3505
  }
3250
3506
  };
3251
3507
  var RPairlist = class extends RObject {
@@ -3258,7 +3514,7 @@ var RPairlist = class extends RObject {
3258
3514
  const prot = { n: 0 };
3259
3515
  try {
3260
3516
  const { names, values } = toWebRData(val);
3261
- const list = RPairlist.wrap(Module._Rf_allocList(values.length));
3517
+ const list = RPairlist.wrap(Module2._Rf_allocList(values.length));
3262
3518
  protectInc(list, prot);
3263
3519
  for (let [i, next] = [0, list]; !next.isNull(); [i, next] = [i + 1, next.cdr()]) {
3264
3520
  next.setcar(new RObject(values[i]));
@@ -3321,16 +3577,16 @@ var RPairlist = class extends RObject {
3321
3577
  return name in this.toObject();
3322
3578
  }
3323
3579
  setcar(obj) {
3324
- Module._SETCAR(this.ptr, obj.ptr);
3580
+ Module2._SETCAR(this.ptr, obj.ptr);
3325
3581
  }
3326
3582
  car() {
3327
- return RObject.wrap(Module._CAR(this.ptr));
3583
+ return RObject.wrap(Module2._CAR(this.ptr));
3328
3584
  }
3329
3585
  cdr() {
3330
- return RObject.wrap(Module._CDR(this.ptr));
3586
+ return RObject.wrap(Module2._CDR(this.ptr));
3331
3587
  }
3332
3588
  tag() {
3333
- return RObject.wrap(Module._TAG(this.ptr));
3589
+ return RObject.wrap(Module2._TAG(this.ptr));
3334
3590
  }
3335
3591
  };
3336
3592
  var RCall = class extends RObject {
@@ -3344,7 +3600,7 @@ var RCall = class extends RObject {
3344
3600
  try {
3345
3601
  const { values } = toWebRData(val);
3346
3602
  const objs2 = values.map((value) => protectInc(new RObject(value), prot));
3347
- const call = RCall.wrap(Module._Rf_allocVector(RTypeMap.call, values.length));
3603
+ const call = RCall.wrap(Module2._Rf_allocVector(RTypeMap.call, values.length));
3348
3604
  protectInc(call, prot);
3349
3605
  for (let [i, next] = [0, call]; !next.isNull(); [i, next] = [i + 1, next.cdr()]) {
3350
3606
  next.setcar(objs2[i]);
@@ -3355,13 +3611,13 @@ var RCall = class extends RObject {
3355
3611
  }
3356
3612
  }
3357
3613
  setcar(obj) {
3358
- Module._SETCAR(this.ptr, obj.ptr);
3614
+ Module2._SETCAR(this.ptr, obj.ptr);
3359
3615
  }
3360
3616
  car() {
3361
- return RObject.wrap(Module._CAR(this.ptr));
3617
+ return RObject.wrap(Module2._CAR(this.ptr));
3362
3618
  }
3363
3619
  cdr() {
3364
- return RObject.wrap(Module._CDR(this.ptr));
3620
+ return RObject.wrap(Module2._CDR(this.ptr));
3365
3621
  }
3366
3622
  eval() {
3367
3623
  return RObject.wrap(safeEval(this.ptr, objs.baseEnv));
@@ -3377,10 +3633,10 @@ var RList = class extends RObject {
3377
3633
  const prot = { n: 0 };
3378
3634
  try {
3379
3635
  const { names, values } = toWebRData(val);
3380
- const ptr = Module._Rf_allocVector(RTypeMap.list, values.length);
3636
+ const ptr = Module2._Rf_allocVector(RTypeMap.list, values.length);
3381
3637
  protectInc(ptr, prot);
3382
3638
  values.forEach((v, i) => {
3383
- Module._SET_VECTOR_ELT(ptr, i, new RObject(v).ptr);
3639
+ Module2._SET_VECTOR_ELT(ptr, i, new RObject(v).ptr);
3384
3640
  });
3385
3641
  RObject.wrap(ptr).setNames(names);
3386
3642
  super(new RObjectBase(ptr));
@@ -3389,7 +3645,7 @@ var RList = class extends RObject {
3389
3645
  }
3390
3646
  }
3391
3647
  get length() {
3392
- return Module._LENGTH(this.ptr);
3648
+ return Module2._LENGTH(this.ptr);
3393
3649
  }
3394
3650
  toArray(options = { depth: 1 }) {
3395
3651
  return this.toJs(options).values;
@@ -3449,15 +3705,15 @@ var RString = class extends RObject {
3449
3705
  super(x);
3450
3706
  return;
3451
3707
  }
3452
- const name = Module.allocateUTF8(x);
3708
+ const name = Module2.allocateUTF8(x);
3453
3709
  try {
3454
- super(new RObjectBase(Module._Rf_mkChar(name)));
3710
+ super(new RObjectBase(Module2._Rf_mkChar(name)));
3455
3711
  } finally {
3456
- Module._free(name);
3712
+ Module2._free(name);
3457
3713
  }
3458
3714
  }
3459
3715
  toString() {
3460
- return Module.UTF8ToString(Module._R_CHAR(this.ptr));
3716
+ return Module2.UTF8ToString(Module2._R_CHAR(this.ptr));
3461
3717
  }
3462
3718
  toJs() {
3463
3719
  return {
@@ -3476,7 +3732,7 @@ var REnvironment = class extends RObject {
3476
3732
  let nProt = 0;
3477
3733
  try {
3478
3734
  const { names, values } = toWebRData(val);
3479
- const ptr = protect(Module._R_NewEnv(objs.globalEnv.ptr, 0, 0));
3735
+ const ptr = protect(Module2._R_NewEnv(objs.globalEnv.ptr, 0, 0));
3480
3736
  ++nProt;
3481
3737
  values.forEach((v, i) => {
3482
3738
  const name = names ? names[i] : null;
@@ -3497,7 +3753,7 @@ var REnvironment = class extends RObject {
3497
3753
  }
3498
3754
  }
3499
3755
  ls(all = false, sorted = true) {
3500
- const ls = RCharacter.wrap(Module._R_lsInternal3(this.ptr, Number(all), Number(sorted)));
3756
+ const ls = RCharacter.wrap(Module2._R_lsInternal3(this.ptr, Number(all), Number(sorted)));
3501
3757
  return ls.toArray();
3502
3758
  }
3503
3759
  bind(name, value) {
@@ -3513,7 +3769,7 @@ var REnvironment = class extends RObject {
3513
3769
  return this.ls(true, true);
3514
3770
  }
3515
3771
  frame() {
3516
- return RObject.wrap(Module._FRAME(this.ptr));
3772
+ return RObject.wrap(Module2._FRAME(this.ptr));
3517
3773
  }
3518
3774
  subset(prop) {
3519
3775
  if (typeof prop === "number") {
@@ -3555,7 +3811,7 @@ var RVectorAtomic = class extends RObject {
3555
3811
  const prot = { n: 0 };
3556
3812
  try {
3557
3813
  const { names, values } = toWebRData(val);
3558
- const ptr = Module._Rf_allocVector(RTypeMap[kind], values.length);
3814
+ const ptr = Module2._Rf_allocVector(RTypeMap[kind], values.length);
3559
3815
  protectInc(ptr, prot);
3560
3816
  values.forEach(newSetter(ptr));
3561
3817
  RObject.wrap(ptr).setNames(names);
@@ -3565,7 +3821,7 @@ var RVectorAtomic = class extends RObject {
3565
3821
  }
3566
3822
  }
3567
3823
  get length() {
3568
- return Module._LENGTH(this.ptr);
3824
+ return Module2._LENGTH(this.ptr);
3569
3825
  }
3570
3826
  get(prop) {
3571
3827
  return super.get(prop);
@@ -3579,7 +3835,7 @@ var RVectorAtomic = class extends RObject {
3579
3835
  detectMissing() {
3580
3836
  const prot = { n: 0 };
3581
3837
  try {
3582
- const call = Module._Rf_lang2(new RSymbol("is.na").ptr, this.ptr);
3838
+ const call = Module2._Rf_lang2(new RSymbol("is.na").ptr, this.ptr);
3583
3839
  protectInc(call, prot);
3584
3840
  const val = RLogical.wrap(safeEval(call, objs.baseEnv));
3585
3841
  protectInc(val, prot);
@@ -3643,9 +3899,9 @@ var _RLogical = class extends RVectorAtomic {
3643
3899
  }
3644
3900
  toTypedArray() {
3645
3901
  return new Int32Array(
3646
- Module.HEAP32.subarray(
3647
- Module._LOGICAL(this.ptr) / 4,
3648
- Module._LOGICAL(this.ptr) / 4 + this.length
3902
+ Module2.HEAP32.subarray(
3903
+ Module2._LOGICAL(this.ptr) / 4,
3904
+ Module2._LOGICAL(this.ptr) / 4 + this.length
3649
3905
  )
3650
3906
  );
3651
3907
  }
@@ -3657,10 +3913,10 @@ var _RLogical = class extends RVectorAtomic {
3657
3913
  var RLogical = _RLogical;
3658
3914
  _newSetter = new WeakMap();
3659
3915
  __privateAdd(RLogical, _newSetter, (ptr) => {
3660
- const data = Module._LOGICAL(ptr);
3661
- const naLogical = Module.getValue(Module._R_NaInt, "i32");
3916
+ const data = Module2._LOGICAL(ptr);
3917
+ const naLogical = Module2.getValue(Module2._R_NaInt, "i32");
3662
3918
  return (v, i) => {
3663
- Module.setValue(data + 4 * i, v === null ? naLogical : Boolean(v), "i32");
3919
+ Module2.setValue(data + 4 * i, v === null ? naLogical : Boolean(v), "i32");
3664
3920
  };
3665
3921
  });
3666
3922
  var _newSetter2;
@@ -3683,9 +3939,9 @@ var _RInteger = class extends RVectorAtomic {
3683
3939
  }
3684
3940
  toTypedArray() {
3685
3941
  return new Int32Array(
3686
- Module.HEAP32.subarray(
3687
- Module._INTEGER(this.ptr) / 4,
3688
- Module._INTEGER(this.ptr) / 4 + this.length
3942
+ Module2.HEAP32.subarray(
3943
+ Module2._INTEGER(this.ptr) / 4,
3944
+ Module2._INTEGER(this.ptr) / 4 + this.length
3689
3945
  )
3690
3946
  );
3691
3947
  }
@@ -3693,10 +3949,10 @@ var _RInteger = class extends RVectorAtomic {
3693
3949
  var RInteger = _RInteger;
3694
3950
  _newSetter2 = new WeakMap();
3695
3951
  __privateAdd(RInteger, _newSetter2, (ptr) => {
3696
- const data = Module._INTEGER(ptr);
3697
- const naInteger = Module.getValue(Module._R_NaInt, "i32");
3952
+ const data = Module2._INTEGER(ptr);
3953
+ const naInteger = Module2.getValue(Module2._R_NaInt, "i32");
3698
3954
  return (v, i) => {
3699
- Module.setValue(data + 4 * i, v === null ? naInteger : Math.round(Number(v)), "i32");
3955
+ Module2.setValue(data + 4 * i, v === null ? naInteger : Math.round(Number(v)), "i32");
3700
3956
  };
3701
3957
  });
3702
3958
  var _newSetter3;
@@ -3719,17 +3975,17 @@ var _RDouble = class extends RVectorAtomic {
3719
3975
  }
3720
3976
  toTypedArray() {
3721
3977
  return new Float64Array(
3722
- Module.HEAPF64.subarray(Module._REAL(this.ptr) / 8, Module._REAL(this.ptr) / 8 + this.length)
3978
+ Module2.HEAPF64.subarray(Module2._REAL(this.ptr) / 8, Module2._REAL(this.ptr) / 8 + this.length)
3723
3979
  );
3724
3980
  }
3725
3981
  };
3726
3982
  var RDouble = _RDouble;
3727
3983
  _newSetter3 = new WeakMap();
3728
3984
  __privateAdd(RDouble, _newSetter3, (ptr) => {
3729
- const data = Module._REAL(ptr);
3730
- const naDouble = Module.getValue(Module._R_NaReal, "double");
3985
+ const data = Module2._REAL(ptr);
3986
+ const naDouble = Module2.getValue(Module2._R_NaReal, "double");
3731
3987
  return (v, i) => {
3732
- Module.setValue(data + 8 * i, v === null ? naDouble : v, "double");
3988
+ Module2.setValue(data + 8 * i, v === null ? naDouble : v, "double");
3733
3989
  };
3734
3990
  });
3735
3991
  var _newSetter4;
@@ -3752,9 +4008,9 @@ var _RComplex = class extends RVectorAtomic {
3752
4008
  }
3753
4009
  toTypedArray() {
3754
4010
  return new Float64Array(
3755
- Module.HEAPF64.subarray(
3756
- Module._COMPLEX(this.ptr) / 8,
3757
- Module._COMPLEX(this.ptr) / 8 + 2 * this.length
4011
+ Module2.HEAPF64.subarray(
4012
+ Module2._COMPLEX(this.ptr) / 8,
4013
+ Module2._COMPLEX(this.ptr) / 8 + 2 * this.length
3758
4014
  )
3759
4015
  );
3760
4016
  }
@@ -3768,11 +4024,11 @@ var _RComplex = class extends RVectorAtomic {
3768
4024
  var RComplex = _RComplex;
3769
4025
  _newSetter4 = new WeakMap();
3770
4026
  __privateAdd(RComplex, _newSetter4, (ptr) => {
3771
- const data = Module._COMPLEX(ptr);
3772
- const naDouble = Module.getValue(Module._R_NaReal, "double");
4027
+ const data = Module2._COMPLEX(ptr);
4028
+ const naDouble = Module2.getValue(Module2._R_NaReal, "double");
3773
4029
  return (v, i) => {
3774
- Module.setValue(data + 8 * (2 * i), v === null ? naDouble : v.re, "double");
3775
- Module.setValue(data + 8 * (2 * i + 1), v === null ? naDouble : v.im, "double");
4030
+ Module2.setValue(data + 8 * (2 * i), v === null ? naDouble : v.re, "double");
4031
+ Module2.setValue(data + 8 * (2 * i + 1), v === null ? naDouble : v.im, "double");
3776
4032
  };
3777
4033
  });
3778
4034
  var _newSetter5;
@@ -3795,15 +4051,15 @@ var _RCharacter = class extends RVectorAtomic {
3795
4051
  }
3796
4052
  toTypedArray() {
3797
4053
  return new Uint32Array(
3798
- Module.HEAPU32.subarray(
3799
- Module._STRING_PTR(this.ptr) / 4,
3800
- Module._STRING_PTR(this.ptr) / 4 + this.length
4054
+ Module2.HEAPU32.subarray(
4055
+ Module2._STRING_PTR(this.ptr) / 4,
4056
+ Module2._STRING_PTR(this.ptr) / 4 + this.length
3801
4057
  )
3802
4058
  );
3803
4059
  }
3804
4060
  toArray() {
3805
4061
  return this.detectMissing().map(
3806
- (m, idx) => m ? null : Module.UTF8ToString(Module._R_CHAR(Module._STRING_ELT(this.ptr, idx)))
4062
+ (m, idx) => m ? null : Module2.UTF8ToString(Module2._R_CHAR(Module2._STRING_ELT(this.ptr, idx)))
3807
4063
  );
3808
4064
  }
3809
4065
  };
@@ -3812,9 +4068,9 @@ _newSetter5 = new WeakMap();
3812
4068
  __privateAdd(RCharacter, _newSetter5, (ptr) => {
3813
4069
  return (v, i) => {
3814
4070
  if (v === null) {
3815
- Module._SET_STRING_ELT(ptr, i, objs.naString.ptr);
4071
+ Module2._SET_STRING_ELT(ptr, i, objs.naString.ptr);
3816
4072
  } else {
3817
- Module._SET_STRING_ELT(ptr, i, new RString(v).ptr);
4073
+ Module2._SET_STRING_ELT(ptr, i, new RString(v).ptr);
3818
4074
  }
3819
4075
  };
3820
4076
  });
@@ -3838,16 +4094,16 @@ var _RRaw = class extends RVectorAtomic {
3838
4094
  }
3839
4095
  toTypedArray() {
3840
4096
  return new Uint8Array(
3841
- Module.HEAPU8.subarray(Module._RAW(this.ptr), Module._RAW(this.ptr) + this.length)
4097
+ Module2.HEAPU8.subarray(Module2._RAW(this.ptr), Module2._RAW(this.ptr) + this.length)
3842
4098
  );
3843
4099
  }
3844
4100
  };
3845
4101
  var RRaw = _RRaw;
3846
4102
  _newSetter6 = new WeakMap();
3847
4103
  __privateAdd(RRaw, _newSetter6, (ptr) => {
3848
- const data = Module._RAW(ptr);
4104
+ const data = Module2._RAW(ptr);
3849
4105
  return (v, i) => {
3850
- Module.setValue(data + i, Number(v), "i8");
4106
+ Module2.setValue(data + i, Number(v), "i8");
3851
4107
  };
3852
4108
  });
3853
4109
  function toWebRData(jsObj) {
@@ -3894,19 +4150,19 @@ function isRObject(value) {
3894
4150
  var objs;
3895
4151
  function initPersistentObjects() {
3896
4152
  objs = {
3897
- baseEnv: REnvironment.wrap(Module.getValue(Module._R_BaseEnv, "*")),
3898
- bracket2Symbol: RSymbol.wrap(Module.getValue(Module._R_Bracket2Symbol, "*")),
3899
- bracketSymbol: RSymbol.wrap(Module.getValue(Module._R_BracketSymbol, "*")),
3900
- dollarSymbol: RSymbol.wrap(Module.getValue(Module._R_DollarSymbol, "*")),
3901
- emptyEnv: REnvironment.wrap(Module.getValue(Module._R_EmptyEnv, "*")),
3902
- false: RLogical.wrap(Module.getValue(Module._R_FalseValue, "*")),
3903
- globalEnv: REnvironment.wrap(Module.getValue(Module._R_GlobalEnv, "*")),
3904
- na: RLogical.wrap(Module.getValue(Module._R_LogicalNAValue, "*")),
3905
- namesSymbol: RSymbol.wrap(Module.getValue(Module._R_NamesSymbol, "*")),
3906
- naString: RObject.wrap(Module.getValue(Module._R_NaString, "*")),
3907
- null: RNull.wrap(Module.getValue(Module._R_NilValue, "*")),
3908
- true: RLogical.wrap(Module.getValue(Module._R_TrueValue, "*")),
3909
- unboundValue: RObject.wrap(Module.getValue(Module._R_UnboundValue, "*"))
4153
+ baseEnv: REnvironment.wrap(Module2.getValue(Module2._R_BaseEnv, "*")),
4154
+ bracket2Symbol: RSymbol.wrap(Module2.getValue(Module2._R_Bracket2Symbol, "*")),
4155
+ bracketSymbol: RSymbol.wrap(Module2.getValue(Module2._R_BracketSymbol, "*")),
4156
+ dollarSymbol: RSymbol.wrap(Module2.getValue(Module2._R_DollarSymbol, "*")),
4157
+ emptyEnv: REnvironment.wrap(Module2.getValue(Module2._R_EmptyEnv, "*")),
4158
+ false: RLogical.wrap(Module2.getValue(Module2._R_FalseValue, "*")),
4159
+ globalEnv: REnvironment.wrap(Module2.getValue(Module2._R_GlobalEnv, "*")),
4160
+ na: RLogical.wrap(Module2.getValue(Module2._R_LogicalNAValue, "*")),
4161
+ namesSymbol: RSymbol.wrap(Module2.getValue(Module2._R_NamesSymbol, "*")),
4162
+ naString: RObject.wrap(Module2.getValue(Module2._R_NaString, "*")),
4163
+ null: RNull.wrap(Module2.getValue(Module2._R_NilValue, "*")),
4164
+ true: RLogical.wrap(Module2.getValue(Module2._R_TrueValue, "*")),
4165
+ unboundValue: RObject.wrap(Module2.getValue(Module2._R_UnboundValue, "*"))
3910
4166
  };
3911
4167
  }
3912
4168
 
@@ -3914,16 +4170,20 @@ function initPersistentObjects() {
3914
4170
  var initialised = false;
3915
4171
  var chan;
3916
4172
  var onWorkerMessage = function(msg) {
3917
- if (!msg || !msg.type || msg.type !== "init") {
4173
+ if (!msg || !msg.type) {
3918
4174
  return;
3919
4175
  }
3920
- if (initialised) {
3921
- throw new Error("Can't initialise worker multiple times.");
4176
+ if (msg.type === "init") {
4177
+ if (initialised) {
4178
+ throw new Error("Can't initialise worker multiple times.");
4179
+ }
4180
+ const messageInit = msg;
4181
+ chan = newChannelWorker(messageInit);
4182
+ init(messageInit.data.config);
4183
+ initialised = true;
4184
+ return;
3922
4185
  }
3923
- const messageInit = msg;
3924
- chan = newChannelWorker(messageInit);
3925
- init(messageInit.data.config);
3926
- initialised = true;
4186
+ chan == null ? void 0 : chan.onMessageFromMainThread(msg);
3927
4187
  };
3928
4188
  if (IN_NODE) {
3929
4189
  require("worker_threads").parentPort.on("message", onWorkerMessage);
@@ -3942,7 +4202,7 @@ function dispatch(msg) {
3942
4202
  switch (reqMsg.type) {
3943
4203
  case "lookupPath": {
3944
4204
  const msg2 = reqMsg;
3945
- const node = Module.FS.lookupPath(msg2.data.path, {}).node;
4205
+ const node = Module2.FS.lookupPath(msg2.data.path, {}).node;
3946
4206
  write({
3947
4207
  obj: copyFSNode(node),
3948
4208
  payloadType: "raw"
@@ -3952,7 +4212,7 @@ function dispatch(msg) {
3952
4212
  case "mkdir": {
3953
4213
  const msg2 = reqMsg;
3954
4214
  write({
3955
- obj: copyFSNode(Module.FS.mkdir(msg2.data.path)),
4215
+ obj: copyFSNode(Module2.FS.mkdir(msg2.data.path)),
3956
4216
  payloadType: "raw"
3957
4217
  });
3958
4218
  break;
@@ -3961,7 +4221,7 @@ function dispatch(msg) {
3961
4221
  const msg2 = reqMsg;
3962
4222
  const reqData = msg2.data;
3963
4223
  const out = {
3964
- obj: Module.FS.readFile(reqData.path, {
4224
+ obj: Module2.FS.readFile(reqData.path, {
3965
4225
  encoding: "binary",
3966
4226
  flags: reqData.flags
3967
4227
  }),
@@ -3973,7 +4233,7 @@ function dispatch(msg) {
3973
4233
  case "rmdir": {
3974
4234
  const msg2 = reqMsg;
3975
4235
  write({
3976
- obj: Module.FS.rmdir(msg2.data.path),
4236
+ obj: Module2.FS.rmdir(msg2.data.path),
3977
4237
  payloadType: "raw"
3978
4238
  });
3979
4239
  break;
@@ -3983,7 +4243,7 @@ function dispatch(msg) {
3983
4243
  const reqData = msg2.data;
3984
4244
  const data = Uint8Array.from(Object.values(reqData.data));
3985
4245
  write({
3986
- obj: Module.FS.writeFile(reqData.path, data, { flags: reqData.flags }),
4246
+ obj: Module2.FS.writeFile(reqData.path, data, { flags: reqData.flags }),
3987
4247
  payloadType: "raw"
3988
4248
  });
3989
4249
  break;
@@ -3991,7 +4251,7 @@ function dispatch(msg) {
3991
4251
  case "unlink": {
3992
4252
  const msg2 = reqMsg;
3993
4253
  write({
3994
- obj: Module.FS.unlink(msg2.data.path),
4254
+ obj: Module2.FS.unlink(msg2.data.path),
3995
4255
  payloadType: "raw"
3996
4256
  });
3997
4257
  break;
@@ -4214,7 +4474,7 @@ function dispatch(msg) {
4214
4474
  }
4215
4475
  case "invokeWasmFunction": {
4216
4476
  const msg2 = reqMsg;
4217
- const res = Module.getWasmTableEntry(msg2.data.ptr)(...msg2.data.args);
4477
+ const res = Module2.getWasmTableEntry(msg2.data.ptr)(...msg2.data.args);
4218
4478
  write({
4219
4479
  payloadType: "raw",
4220
4480
  obj: res
@@ -4243,7 +4503,7 @@ function dispatch(msg) {
4243
4503
  obj: { name: e.name, message: e.message, stack: e.stack }
4244
4504
  });
4245
4505
  if (e instanceof UnwindProtectException) {
4246
- Module._R_ContinueUnwind(e.cont);
4506
+ Module2._R_ContinueUnwind(e.cont);
4247
4507
  throwUnreachable();
4248
4508
  }
4249
4509
  }
@@ -4371,7 +4631,7 @@ function captureR(code, options = {}) {
4371
4631
  protectInc(fn, prot);
4372
4632
  const codeObj = new RCharacter(code);
4373
4633
  protectInc(codeObj, prot);
4374
- const call = Module._Rf_lang6(
4634
+ const call = Module2._Rf_lang6(
4375
4635
  fn.ptr,
4376
4636
  codeObj.ptr,
4377
4637
  _options.captureConditions ? tPtr : fPtr,
@@ -4401,7 +4661,7 @@ function captureR(code, options = {}) {
4401
4661
  function evalR(code, options = {}) {
4402
4662
  var _a, _b;
4403
4663
  const capture = captureR(code, options);
4404
- Module._Rf_protect(capture.ptr);
4664
+ Module2._Rf_protect(capture.ptr);
4405
4665
  try {
4406
4666
  const output = capture.get("output");
4407
4667
  for (let i = 1; i <= output.length; i++) {
@@ -4435,7 +4695,7 @@ ${((_b = out.pluck("data", "message")) == null ? void 0 : _b.toString()) || ""}`
4435
4695
  }
4436
4696
  return capture.get("result");
4437
4697
  } finally {
4438
- Module._Rf_unprotect(1);
4698
+ Module2._Rf_unprotect(1);
4439
4699
  }
4440
4700
  }
4441
4701
  function init(config) {
@@ -4445,33 +4705,36 @@ function init(config) {
4445
4705
  const fmt = new Intl.DateTimeFormat();
4446
4706
  env.TZ = fmt.resolvedOptions().timeZone;
4447
4707
  }
4448
- Module.preRun = [];
4449
- Module.arguments = _config.RArgs;
4450
- Module.noExitRuntime = true;
4451
- Module.noImageDecoding = true;
4452
- Module.noAudioDecoding = true;
4453
- Module.noInitialRun = true;
4454
- Module.noWasmDecoding = true;
4455
- Module.preRun.push(() => {
4708
+ Module2.preRun = [];
4709
+ Module2.arguments = _config.RArgs;
4710
+ Module2.noExitRuntime = true;
4711
+ Module2.noImageDecoding = true;
4712
+ Module2.noAudioDecoding = true;
4713
+ Module2.noInitialRun = true;
4714
+ Module2.noWasmDecoding = true;
4715
+ Module2.preRun.push(() => {
4456
4716
  if (IN_NODE) {
4457
- globalThis.FS = Module.FS;
4717
+ globalThis.FS = Module2.FS;
4718
+ globalThis.chan = chan;
4719
+ }
4720
+ if (_config.createLazyFilesystem) {
4721
+ Module2.createLazyFilesystem();
4458
4722
  }
4459
- Module.createLazyFilesystem();
4460
- Module.FS.mkdirTree(_config.homedir);
4461
- Module.ENV.HOME = _config.homedir;
4462
- Module.FS.chdir(_config.homedir);
4463
- Module.ENV = Object.assign(Module.ENV, env);
4723
+ Module2.FS.mkdirTree(_config.homedir);
4724
+ Module2.ENV.HOME = _config.homedir;
4725
+ Module2.FS.chdir(_config.homedir);
4726
+ Module2.ENV = Object.assign(Module2.ENV, env);
4464
4727
  });
4465
4728
  chan == null ? void 0 : chan.setDispatchHandler(dispatch);
4466
- Module.onRuntimeInitialized = () => {
4729
+ Module2.onRuntimeInitialized = () => {
4467
4730
  chan == null ? void 0 : chan.run(_config.RArgs);
4468
4731
  };
4469
- Module.webr = {
4732
+ Module2.webr = {
4470
4733
  UnwindProtectException,
4471
4734
  resolveInit: () => {
4472
4735
  initPersistentObjects();
4473
- chan == null ? void 0 : chan.setInterrupt(Module._Rf_onintr);
4474
- Module.setValue(Module._R_Interactive, _config.interactive, "*");
4736
+ chan == null ? void 0 : chan.setInterrupt(Module2._Rf_onintr);
4737
+ Module2.setValue(Module2._R_Interactive, _config.interactive, "*");
4475
4738
  evalR(`options(webr_pkg_repos="${_config.repoUrl}")`);
4476
4739
  chan == null ? void 0 : chan.resolve();
4477
4740
  },
@@ -4486,19 +4749,19 @@ function init(config) {
4486
4749
  },
4487
4750
  evalJs: (code) => {
4488
4751
  try {
4489
- return (0, eval)(Module.UTF8ToString(code));
4752
+ return (0, eval)(Module2.UTF8ToString(code));
4490
4753
  } catch (e) {
4491
4754
  if (e instanceof UnwindProtectException) {
4492
- Module._R_ContinueUnwind(e.cont);
4755
+ Module2._R_ContinueUnwind(e.cont);
4493
4756
  throwUnreachable();
4494
4757
  } else if (e === Infinity) {
4495
4758
  throw e;
4496
4759
  }
4497
- const msg = Module.allocateUTF8OnStack(
4760
+ const msg = Module2.allocateUTF8OnStack(
4498
4761
  `An error occured during JavaScript evaluation:
4499
4762
  ${e.message}`
4500
4763
  );
4501
- Module._Rf_error(msg);
4764
+ Module2._Rf_error(msg);
4502
4765
  }
4503
4766
  throwUnreachable();
4504
4767
  return 0;
@@ -4507,21 +4770,18 @@ function init(config) {
4507
4770
  chan == null ? void 0 : chan.writeSystem({ type: "setTimeoutWasm", data: { ptr, delay, args } });
4508
4771
  }
4509
4772
  };
4510
- Module.locateFile = (path) => _config.baseUrl + path;
4511
- Module.downloadFileContent = downloadFileContent;
4512
- Module.print = (text) => {
4773
+ Module2.locateFile = (path) => _config.baseUrl + path;
4774
+ Module2.downloadFileContent = downloadFileContent;
4775
+ Module2.print = (text) => {
4513
4776
  chan == null ? void 0 : chan.write({ type: "stdout", data: text });
4514
4777
  };
4515
- Module.printErr = (text) => {
4778
+ Module2.printErr = (text) => {
4516
4779
  chan == null ? void 0 : chan.write({ type: "stderr", data: text });
4517
4780
  };
4518
- Module.setPrompt = (prompt) => {
4781
+ Module2.setPrompt = (prompt) => {
4519
4782
  chan == null ? void 0 : chan.write({ type: "prompt", data: prompt });
4520
4783
  };
4521
- Module.canvasExec = (op) => {
4522
- chan == null ? void 0 : chan.write({ type: "canvasExec", data: op });
4523
- };
4524
- globalThis.Module = Module;
4784
+ globalThis.Module = Module2;
4525
4785
  setTimeout(() => {
4526
4786
  const scriptSrc = `${_config.baseUrl}R.bin.js`;
4527
4787
  loadScript(scriptSrc);