@naanlang/naan 1.4.1 → 1.4.2

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/LICENSE.md CHANGED
@@ -1,4 +1,4 @@
1
- **Naan for NPM** version **1.4.1+1** is released under the MIT License:
1
+ **NaaN for NPM** version **1.4.2+1** is released under the MIT License:
2
2
 
3
3
  Copyright (c) 2017-2024 Zulch Laboratories, Inc.
4
4
 
package/README.md CHANGED
@@ -1,14 +1,14 @@
1
- **Naan**™
1
+ **NaaN**™
2
2
  -----
3
3
 
4
- Naan is an async-first software platform for rapid development.
4
+ NaaN is an async-first software platform for rapid development.
5
5
 
6
6
  #### Release:
7
-      **Naan for NPM** version **1.4.1+1**
7
+      **NaaN for NPM** version **1.4.2+1**
8
8
       Copyright (c) 2017-2024 Zulch Laboratories, Inc.
9
9
 
10
10
  #### Features
11
- - **Naan** runs in NodeJS and web browsers using JavaScript
11
+ - **NaaN** runs in NodeJS and web browsers using JavaScript
12
12
  - Based on an asynchronous LISP-2 engine with persistent execution
13
13
  - The default **Lingo**™ surface language provides familiar Algol-style braces syntax
14
14
  - Fiber-based concurrent execution without async or await declarations
@@ -37,18 +37,18 @@ For use as a library in the current project:
37
37
 
38
38
  naan [options] [source file] [arguments]
39
39
 
40
- With no arguments Naan runs as an interactive REPL using the node.js terminal.
40
+ With no arguments NaaN runs as an interactive REPL using the node.js terminal.
41
41
  It can also evaluate an expression or execute a source file.
42
42
 
43
43
  ##### Command line usage
44
44
 
45
45
  -e <expression> evaluate an expression
46
46
  -i, --interactive use REPL with -e or [source file]
47
- --version print Naan version
48
- --buildno print Naan version with build number
47
+ --version print NaaN version
48
+ --buildno print NaaN version with build number
49
49
  -h, --help print usage information
50
50
 
51
- Naan prints the results of evaluating each expression with the REPL, but not
51
+ NaaN prints the results of evaluating each expression with the REPL, but not
52
52
  by default with an expression or source file. The interactive flag overrides
53
53
  this to print the result of each expression in all cases.
54
54
 
@@ -72,7 +72,7 @@ Fetch your public IP from a website (NodeJS version 18 or later):
72
72
 
73
73
  ##### Shell scripting
74
74
 
75
- When installed globally, Naan can be used for shell scripts with the [Shebang](https://en.wikipedia.org/wiki/Shebang_(Unix))
75
+ When installed globally, NaaN can be used for shell scripts with the [Shebang](https://en.wikipedia.org/wiki/Shebang_(Unix))
76
76
  mechanism. For example, copy the following text to a file named helloworld:
77
77
 
78
78
  #!/usr/bin/env naan
@@ -89,7 +89,7 @@ The [NaanIDE](https://www.npmjs.com/package/@naanlang/naanide) installation incl
89
89
  Please email [Richard Zulch](mailto:naanlang@zulchlabs.com) with questions and comments.
90
90
 
91
91
  #### Dependencies:
92
- We gratefully acknowledge these software packages used with Naan:
92
+ We gratefully acknowledge these software packages used with NaaN:
93
93
  - [jszip.js](http://stuartk.com/jszip) - read and write zip files
94
94
  - [NodeJS-path](https://nodejs.org/) - NodeJS path utilities
95
95
  - [PouchDB](https://pouchdb.com/) - synchronizing database
package/bin/index.js CHANGED
@@ -67,11 +67,11 @@ process.argv.every((val, index) => {
67
67
  return (true);
68
68
  }
69
69
  if (val == "--version") {
70
- console.log("1.4.1");
70
+ console.log("1.4.2");
71
71
  process.exit(0);
72
72
  }
73
73
  if (val == "--buildno") {
74
- console.log("1.4.1+1");
74
+ console.log("1.4.2+1");
75
75
  process.exit(0);
76
76
  }
77
77
  if (val.substring(0,1) == "-") {
package/dist/env_web.js CHANGED
@@ -34,7 +34,7 @@ exports.NaanControllerWeb = function() {
34
34
  "use strict";
35
35
  /*jshint -W024 */
36
36
  var undefined; // JavaScript should make this a keyword
37
-
37
+
38
38
  //
39
39
  // Persistent
40
40
  //
@@ -43,17 +43,11 @@ exports.NaanControllerWeb = function() {
43
43
  kStateFirstVersion = 200, // increment when losing backwards compatbility
44
44
  kStateCurrentVersion = 200; // increment when adding features
45
45
 
46
-
46
+
47
47
  //
48
48
  // Environment
49
49
  //
50
-
51
- var pageLoading = true; // assume we are loading the page
52
50
 
53
- window.addEventListener("load", function (e) {
54
- pageLoading = false;
55
- });
56
-
57
51
  var querystrings = (function(a) {
58
52
  if (a === "") return {};
59
53
  var b = {};
@@ -67,12 +61,12 @@ exports.NaanControllerWeb = function() {
67
61
  }
68
62
  return b;
69
63
  })(window.location.search.substr(1).split('&'));
70
-
71
-
64
+
65
+
72
66
  //
73
67
  // Initialization
74
68
  //
75
-
69
+
76
70
  var naanlib = new exports.Naanlib();
77
71
  var dontSaveUntilWorking; // true when state loaded, must be reset to save state again
78
72
  var contSelf = this; // this is us, for access within nested functions
@@ -129,7 +123,7 @@ exports.NaanControllerWeb = function() {
129
123
  //
130
124
  // Read any pending Naan output and send to terminal.
131
125
  //
132
-
126
+
133
127
  function takePending() {
134
128
  var outputq = replqueue;
135
129
  replqueue = false;
@@ -145,13 +139,13 @@ exports.NaanControllerWeb = function() {
145
139
  //==========================================================================
146
140
  // New Terminal Interface
147
141
  //--------------------------------------------------------------------------
148
-
142
+
149
143
  //
150
144
  // StateGet
151
145
  //
152
146
  // Report the saved state we are keeping for the terminal.
153
147
  //
154
-
148
+
155
149
  this.StateGet = function StateGet() {
156
150
  termlist.every(function(term) {
157
151
  var state;
@@ -170,20 +164,20 @@ exports.NaanControllerWeb = function() {
170
164
  //
171
165
  // Attach a terminal to our interpreter and immediately start sending it messages.
172
166
  //
173
-
167
+
174
168
  this.Attach = function Attach(terminal) {
175
169
  var repdex = termlist.indexOf(terminal);
176
170
  if (repdex < 0)
177
171
  termlist.push(terminal);
178
172
  takePending(); // output all pending terminal messages
179
173
  };
180
-
174
+
181
175
  //
182
176
  // Detach
183
177
  //
184
178
  // Detach the terminal from the interpreter.
185
179
  //
186
-
180
+
187
181
  this.Detach = function Detach(terminal) {
188
182
  var repdex = termlist.indexOf(terminal);
189
183
  if (repdex >= 0)
@@ -191,17 +185,17 @@ exports.NaanControllerWeb = function() {
191
185
  if (termlist.length === 0)
192
186
  replstate = terminal.StateSave(); // save ultimate repl state
193
187
  };
194
-
188
+
195
189
  //
196
190
  // Interrupt
197
191
  //
198
192
  // Interrupt the interpreter in response to a user request.
199
193
  //
200
-
194
+
201
195
  this.Interrupt = function Interrupt(terminal) {
202
- window.setTimeout(function () {
196
+ Promise.resolve().then(function () {
203
197
  naanlib.escape();
204
- }, 0);
198
+ });
205
199
  };
206
200
 
207
201
  //
@@ -209,7 +203,7 @@ exports.NaanControllerWeb = function() {
209
203
  //
210
204
  // Enter line of text to instance.
211
205
  //
212
-
206
+
213
207
  this.Return = function Return(text, terminal) {
214
208
  termlist.forEach(function(term) {
215
209
  if (term !== terminal)
@@ -240,13 +234,13 @@ exports.NaanControllerWeb = function() {
240
234
  });
241
235
  return (data);
242
236
  };
243
-
237
+
244
238
  var nideListener;
245
239
  this.OnMessage = function OnMessage(proc) {
246
240
  nideListener = proc;
247
241
  return (proc);
248
242
  };
249
-
243
+
250
244
  this.DispatchMessage = function DispatchMessage(data) { // "local" -> "remote"
251
245
  if (nideListener)
252
246
  setTimeout(function() {
@@ -267,7 +261,7 @@ exports.NaanControllerWeb = function() {
267
261
  debugListener = proc;
268
262
  return (proc);
269
263
  };
270
-
264
+
271
265
  this.DispatchDebugger = function DispatchDebugger(data) { // "local" -> "remote"
272
266
  if (debugListener)
273
267
  setTimeout(function() {
@@ -280,7 +274,7 @@ exports.NaanControllerWeb = function() {
280
274
  //
281
275
  // Report status to the terminal.
282
276
  //
283
-
277
+
284
278
  setInterval(function() {
285
279
  var samples = naanlib.status(1);
286
280
  if (samples.length > 0)
@@ -297,29 +291,30 @@ exports.NaanControllerWeb = function() {
297
291
  //
298
292
  // Enter keystroke to instance.
299
293
  //
300
-
294
+
301
295
  this.Keystroke = function Keystroke(text, keycode) {
302
296
  console.log("Naan keystroke mode not implemented");
303
297
  };
304
-
298
+
305
299
  //
306
300
  // Dimensions
307
301
  //
308
302
  // Report terminal dimensions to instance.
309
303
  //
310
-
304
+
311
305
  this.Dimensions = function Dimensions(rows, cols) {
312
306
  console.log("Naan terminal dimensions now (" + rows + ", " + cols + ")");
313
307
  };
314
-
308
+
315
309
  //
316
310
  // VsiteRefresh
317
311
  //
318
312
  // Check if our underlying data has changed, and reload if needed.
319
313
  //
320
-
314
+
321
315
  this.VsiteRefresh = function VsiteRefresh(url_origin) {
322
316
  if (vsiteName && window.location.href.startsWith(url_origin)) {
317
+ virtualClose();
323
318
  window.location.reload(); // we have changed underneath
324
319
  window.scroll(0,0); // Chrome 106 had flood pants 🤓
325
320
  return (true);
@@ -330,7 +325,7 @@ exports.NaanControllerWeb = function() {
330
325
  //==========================================================================
331
326
  // Browser Console Terminal
332
327
  //--------------------------------------------------------------------------
333
-
328
+
334
329
  // Commands:
335
330
  // Naanlang.debug(<text>) -- command line text entry
336
331
  // Naanlang.int() -- interrupt and enter debugger
@@ -373,7 +368,7 @@ exports.NaanControllerWeb = function() {
373
368
  return (false);
374
369
  };
375
370
  }
376
-
371
+
377
372
  //
378
373
  // debug
379
374
  //
@@ -429,7 +424,7 @@ exports.NaanControllerWeb = function() {
429
424
  debugListener(msg.data); // target received a message
430
425
  }
431
426
  });
432
-
427
+
433
428
  //
434
429
  // report messages back to opener
435
430
  //
@@ -437,7 +432,7 @@ exports.NaanControllerWeb = function() {
437
432
  window.opener.postMessage(msg, window.origin);
438
433
  return (msg);
439
434
  };
440
-
435
+
441
436
  //
442
437
  // report messages back to opener
443
438
  //
@@ -459,7 +454,7 @@ exports.NaanControllerWeb = function() {
459
454
  };
460
455
  return (termSelf.OnMessage(msg));
461
456
  };
462
-
457
+
463
458
  //
464
459
  // report status back to opener
465
460
  //
@@ -471,64 +466,47 @@ exports.NaanControllerWeb = function() {
471
466
  return (termSelf.OnMessage(msg));
472
467
  };
473
468
  }
474
-
469
+
475
470
  //==========================================================================
476
471
  // Host Environment
477
472
  //--------------------------------------------------------------------------
478
-
473
+
479
474
  //
480
475
  // SavePref
481
476
  //
482
477
  // Save a persistent preference object that can be retrieved in the future.
483
478
  //
484
-
479
+
485
480
  this.SavePref = function SavePref(key, value) {
486
481
  return (prefs[key] = value);
487
482
  };
488
-
483
+
489
484
  //
490
485
  // LoadPref
491
486
  //
492
487
  // Load a previously-saved preference object for future retrieval.
493
488
  //
494
-
489
+
495
490
  this.LoadPref = function LoadPref(key) {
496
491
  return (prefs[key]);
497
492
  };
498
-
493
+
499
494
  //
500
495
  // Working
501
496
  //
502
497
  // The application is working, so it is safe to save state.
503
498
  //
504
-
499
+
505
500
  this.Working = function Working() {
506
501
  dontSaveUntilWorking = false;
507
502
  };
508
-
509
- var saveEvent = new Event("NaanSave");
510
-
511
- window.document.addEventListener("visibilitychange", function (e) {
512
- if (window.document.visibilityState != "hidden")
513
- return;
514
- window.dispatchEvent(saveEvent);
515
- saveLocal();
516
- });
517
503
 
518
- window.addEventListener("pagehide", function (e) {
519
- window.dispatchEvent(saveEvent);
520
- saveLocal();
521
- });
522
-
523
- window.addEventListener("unload", function (e) {
524
- window.dispatchEvent(saveEvent);
525
- saveLocal();
526
- virtualClose();
527
- });
528
-
529
- window.addEventListener("beforeunload", function (e) {
530
- window.dispatchEvent(saveEvent);
531
- saveLocal();
504
+ window.document.addEventListener("visibilitychange", function (e) {
505
+ virtualVisibilityChange();
506
+ if (window.document.visibilityState == "hidden") {
507
+ window.dispatchEvent(new Event("NaanSave"));
508
+ saveLocal();
509
+ }
532
510
  });
533
511
 
534
512
  function makeState() {
@@ -548,24 +526,24 @@ exports.NaanControllerWeb = function() {
548
526
  statedoc.replstate = replstate;
549
527
  return (statedoc);
550
528
  }
551
-
529
+
552
530
  function loadState(statedoc) {
553
531
  if (statedoc===undefined || statedoc.naan === undefined
554
532
  || statedoc.firstver > kStateCurrentVersion
555
533
  || statedoc.curversion < kStateFirstVersion
556
534
  || statedoc.licensee != "$Licensee$"
557
- || statedoc.verstring != "$Version$")
535
+ || statedoc.verstring != "$Version$"
536
+ || !(naanstate = statedoc.naan))
558
537
  {
559
538
  localStorage.removeItem("NaanState_Hosted");
560
539
  return (false);
561
540
  }
562
- naanstate = statedoc.naan;
563
541
  replstate = statedoc.replstate; // get terminal state, if any
564
542
  if (typeof(statedoc.prefs) == "object")
565
543
  prefs = statedoc.prefs;
566
544
  return (true);
567
545
  }
568
-
546
+
569
547
  function saveLocal() {
570
548
  /*jshint sub:true */
571
549
  if (dontSaveUntilWorking) { // saved state is problematic
@@ -588,7 +566,7 @@ exports.NaanControllerWeb = function() {
588
566
  }
589
567
  return (false);
590
568
  }
591
-
569
+
592
570
  function loadLocal() {
593
571
  try {
594
572
  /*jshint sub:true */
@@ -604,7 +582,7 @@ exports.NaanControllerWeb = function() {
604
582
  }
605
583
  return (false);
606
584
  }
607
-
585
+
608
586
  function virtualOpen() {
609
587
  try {
610
588
  if (window.opener && window.opener.Naanlang) {
@@ -619,7 +597,7 @@ exports.NaanControllerWeb = function() {
619
597
  } catch (e) {
620
598
  }
621
599
  }
622
-
600
+
623
601
  function virtualClose() {
624
602
  try {
625
603
  if (window.opener && window.opener.Naanlang) {
@@ -636,6 +614,22 @@ exports.NaanControllerWeb = function() {
636
614
  vsiteName = false; // window is going away
637
615
  }
638
616
 
617
+ function virtualVisibilityChange() {
618
+ try {
619
+ if (window.opener && window.opener.Naanlang) {
620
+ window.opener.Naanlang.naancon.DispatchMessage({
621
+ op: "VsiteVisibilityChange",
622
+ name: vsiteName,
623
+ naancont: contSelf,
624
+ title: vsiteName + " $Version$",
625
+ hidden: window.document.visibilityState == "hidden",
626
+ window: window
627
+ });
628
+ }
629
+ } catch (e) {
630
+ }
631
+ }
632
+
639
633
  /*jshint sub:true */
640
634
  if (querystrings["restart"] || !loadLocal())
641
635
  { // don't load state or can't load state
@@ -656,6 +650,7 @@ exports.NaanControllerWeb = function() {
656
650
  localStorage.removeItem("NaanState_Hosted");
657
651
  window.location.reload();
658
652
  }
653
+ naanstate = false; // reclaim memory
659
654
  }
660
655
 
661
656
  if (window.opener) {