titanfiber 1.0.23 → 1.0.25
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/package.json +1 -1
- package/titanfiber.js +120 -1
- package/titanfiber.pkg.js +1 -0
package/package.json
CHANGED
package/titanfiber.js
CHANGED
|
@@ -1 +1,120 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
//Load a static Titan package and integrate it with the current t tree.
|
|
11
|
+
function load(packagePath, options) {
|
|
12
|
+
//used directly and by t.titan.loadJSONPackage
|
|
13
|
+
if(!packagePath) {
|
|
14
|
+
//shane - add package.json loading to detect file name,
|
|
15
|
+
// or default to <scriptName>.pkg.json.
|
|
16
|
+
const path = require("node:path");
|
|
17
|
+
var scriptPath = process.mainModule?.filename;
|
|
18
|
+
if(!scriptPath) { throw new Error("Cannot find package name because scriptPath does not exist."); }
|
|
19
|
+
var dir = path.dirname(scriptPath);
|
|
20
|
+
var baseName = path.basename(scriptPath).split(".")[0];
|
|
21
|
+
baseName = baseName[0].toLowerCase()+baseName.slice(1);
|
|
22
|
+
//Uses absolute path to help loading work from non-standard CWDs.
|
|
23
|
+
//Currently only supports static package,
|
|
24
|
+
// dynamic packages are loaded and updated through .auto().
|
|
25
|
+
packagePath = path.join(dir, baseName+".pkg.json");
|
|
26
|
+
}
|
|
27
|
+
//console.log("PACKAGEPATH", packagePath);
|
|
28
|
+
|
|
29
|
+
const fs = require("node:fs");
|
|
30
|
+
var packageText = fs.readFileSync(packagePath, "utf8");
|
|
31
|
+
var packageObj = JSON.parse(packageText);
|
|
32
|
+
//console.log("PACKAGEOBJ", packageObj);
|
|
33
|
+
|
|
34
|
+
var t = globalThis.t;
|
|
35
|
+
if(!t) { t = globalThis.t = {}; }
|
|
36
|
+
|
|
37
|
+
var items = packageObj.itemsInOrder;
|
|
38
|
+
var numItems = items.length;
|
|
39
|
+
for(var i=0; i<numItems; i++) {
|
|
40
|
+
var item = items[i];
|
|
41
|
+
var [shortName, itemName, evalText] = item;
|
|
42
|
+
var tModObj = t[shortName];
|
|
43
|
+
if(!tModObj) { tModObj = t[shortName] = {}; }
|
|
44
|
+
var itemVal = eval("("+evalText+")");
|
|
45
|
+
tModObj[itemName] = itemVal;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if(packageObj.globals) {
|
|
49
|
+
addGlobals(packageObj);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return t;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
//Auto-pack the current file if needed, and load the new items.
|
|
57
|
+
function auto(options) {
|
|
58
|
+
//used directly
|
|
59
|
+
require("./titanfiber.pkg.js");
|
|
60
|
+
if(!options) { options = {}; }
|
|
61
|
+
//Can disable dynamic to use static package,
|
|
62
|
+
// if growth over time is not desired.
|
|
63
|
+
if(options.dynamic == null) { options.dynamic = true; }
|
|
64
|
+
options.loadFn = load;
|
|
65
|
+
return t.titan.autoPackAndLoadJSON(t.node.getScriptPath(), null, options);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
function addGlobals(packageObj) {
|
|
70
|
+
//shane1
|
|
71
|
+
//used by load
|
|
72
|
+
//require("./titanfiber.pkg.js");
|
|
73
|
+
var globals = packageObj.globals;
|
|
74
|
+
var shortNamesToGlobals = packageObj.shortNamesToGlobals;
|
|
75
|
+
//for each shortName in shortNamesToGlobals,
|
|
76
|
+
Object.keys(shortNamesToGlobals).forEach(shortName => {
|
|
77
|
+
//for each globalName mapped to that shortName,
|
|
78
|
+
var globalNames = shortNamesToGlobals[shortName];
|
|
79
|
+
var len = globalNames.length;
|
|
80
|
+
for(var i=0; i<len; i++) {
|
|
81
|
+
var globalName = globalNames[i];
|
|
82
|
+
var globalObj = globalThis[globalName];
|
|
83
|
+
//ensure the global exists,
|
|
84
|
+
if(!globalObj) { globalObj = globalThis[globalName] = {}; }
|
|
85
|
+
|
|
86
|
+
//then create bindings between each global item and the t tree item.
|
|
87
|
+
var globalUsesObj = globals[globalName];
|
|
88
|
+
Object.keys(globalUsesObj).forEach(itemName => {
|
|
89
|
+
var tItem = t[shortName][itemName];
|
|
90
|
+
globalObj[itemName] = tItem;
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
//Track globals in memory, not just in the package.
|
|
95
|
+
// Used by REPL to to eliminate unnecessary disk reads.
|
|
96
|
+
console.log("TRACKING GLBOALS", packageObj.globals);
|
|
97
|
+
var _t = t; //avoid pattern.
|
|
98
|
+
if(!_t._meta) { _t._meta = {}; }
|
|
99
|
+
//This is fine for now, but will need to be updated to deep merge
|
|
100
|
+
// if I add partial packages.
|
|
101
|
+
_t._meta.globals = packageObj.globals;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
exports.load = load;
|
|
106
|
+
exports.auto = auto;
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e=function(e){return require(e)},n=function(n){return!!n.startsWith("node:")||e("node:module").isBuiltin(n)},r=function(e){return e.startsWith(".")},i=function(e){return Nr("readline-sync").keyInYNStrict(e)},u=function(e,n){if("readline-sync"===e)throw new Error('Npm package "readline-sync" is required to prompt for package installation.');return n||(n='Npm package "'+e+'" is required. Install now?'),i(n)},o=function(e){return"string"==typeof e},a=function(e){return Array.isArray(e)},s=function(e){return a(e)?e:[e]},c=function(e){return e instanceof Promise},l=function(e,n){var r=e;return c(r)?r.then(n):n(r)},f=function(e,n){return null!=e&&e.constructor===n},p=function(e){return f(e,Function)},h=async function(){}.constructor,d=function(e){return f(e,h)},v=function(e){return p(e)||d(e)},m=function(e){return v(e)&&null==e.prototype},g=m,y=function(e){return function(){return e.apply(this,arguments)}},b=function(e,n){var r;return r=n?function(){return this.super=n,l(e.apply(this,arguments),(()=>(delete this.super,this)))}:g(e)?y(e):e,r._isConstructor=!0,r},w=function(e,n){return e._isConstructor?e:b(e,n)},x=function(){return this},O=function(e,n,r){Object.defineProperty(e,n,{value:r,writable:!0,enumerable:!1,configurable:!0})},T=O,E=function(e,n){Object.defineProperty(e,"name",{value:n,configurable:!0}),T(e,"displayName",n)},S=function(e,n){return e&&E(n,e),n},N=S,j=function(e){return N(e.name,class extends e{constructor(e,n){super(e,n);var r=this.constructor.name;r&&(this.name=r)}})},k=j(globalThis.Error),F=function(e,n,r){var t=new k(e,r);return n&&Object.assign(t,n),t},A=class extends k{constructor(e,n){super(e??"Not yet implemented",n)}},C=function(e,n,r,t){var i=e[n];if(void 0===i){var u=r;!1!==t&&v(u)&&(u=u(e,n)),e[n]=i=u}return i},P=function(e,n,r,t){return e||(e={}),C(e,n,r,t),e},D=function(e,n){return P(e,"fromFn",n,!1)},_=function(e,n){return new A(e,D(n,_))},I=function(e){return e instanceof Object&&null!==e},L=E,q=function(e,n){return Object.assign(e,n)},M=function(e){var n,r=!1;return function(){return r||(r=!0,n=e.apply(this,arguments)),n}},R=M((function(){return"undefined"==typeof window})),B=R()?require("util").inspect.custom:Symbol("Display"),G=function(e,n){e.prototype[B]=n},J=function(e,n,r,t,i,u){u||(u={}),o(n)&&(n=null);var c,f,p,h=r;if(h)if(a(h)){if([f,p]=h,f)if(a(f)){if(!n)throw F("Bare args array for instanceFn is only valid when extending a class.");var d=f;f=null,c=b((function(){this.super.apply(this,d)}),n)}else f=w(f)}else c=w(h,n);var v=u.bareFn;u.singleton&&(v=function(){return null==y.default&&(y.default=new y(...arguments)),y.default});var m,g=f||c||n||x;function y(){if(!new.target&&v&&!(this instanceof y))return v.apply(this,arguments);var e=this;return l(g.apply(e,arguments),(r=>{if(r&&I(r)&&(e=r,f)){if(!new.target)throw _('Prototype repair is NYI for class instantiation without "new".');if(!n)throw _("instanceFn is not yet supported when extendsClass is null.");var t=Object.getPrototypeOf(this);Object.getPrototypeOf(e)!==t&&Object.setPrototypeOf(e,t)}return p?l(p.apply(e,arguments),(()=>e)):e}))}return e&&L(y,e),t?(m=t,n&&Object.setPrototypeOf(t,n.prototype)):m=n?Object.create(n.prototype):{},T(m,"constructor",y),y.prototype=m,i&&q(y,i),u.display&&G(y,u.display),u.implements&&s(u.implements).forEach((e=>e(y))),y},K=function(e,n){Object.defineProperty(e,n,{enumerable:!1})},W=K,U=function(e,n,r,t,i){var u=Symbol();return J(e,Function,[function(){var e=function(){return e[u].apply(this,arguments)};return e},function(){var e=n.apply(this,arguments);if(!e)throw new Error("Constructor must return a function.");this[u]=e,W(this,u)}],r,t,i)},z=function(e,n){return n<0?e.length+n:n},Y=function(e,n,r,t){return n=null==n?0:z(e,n),r=null==r?e.length:z(e,r),t&&(0==t.inclusiveStart&&n++,t.inclusiveEnd&&r++),[n,r]},H=function(e,n,r,t){var i=n;if([r,t]=Y(e,r,t),v(i))for(var u=r;u<t;u++)e[u]=i(u,e);else e.fill(i,r,t);return e},Q=function(e,n){var r=new Array(e||0);return arguments.length>1&&H(r,n),r},V=function(e,n){return Q(n.length,(r=>e[n[r]]))},$=function(e,n){return e[n]},Z=function(e,n,r){return e[n]=r},X=function(e,n,r){var t=e;return v(t)?t.apply(r,n):t},ee=function(e,n,r,t,i){t||(t=$);var u=t(e,n);return void 0===u&&(u=X(r,[e,n]),i||(i=Z),i(e,n,u)),u},ne=function(e,n){return e.get(n)},re=function(e,n,r){return e.set(n,r)},te=function(e,n,r){return ee(e,n,r,ne,re)},ie=class{constructor(){this.store=new Map}get(e,n){return te(this.store,e,n)}remove(e){return this.store.delete(e)}delete(e){return this.remove(e)}},ue=function(e,n){return e.push(n),e},oe=function(e){var n=e;return Array.isArray(n)?n:Array.from(n)},ae=Symbol("Value"),se=function(){return{}},ce=function(e){return[e.slice(0,-1),e[e.length-1]]},le=function(e,n,r,t,i,u){r||(r=$),null==t&&(t=se),null==i&&(i=Z),null==u&&(u=r);for(var[o,a]=ce(n),s=e,c=o.length,l=0;l<c;l++){var f=o[l],p=r(s,f);if(void 0===p){if(!t)return;p=ee(s,f,t,r,i)}s=p}if(u)return u(s,a,i)},fe=function(e,n,r,t,i,u){return le(e,n,t,i,u,((e,n)=>ee(e,n,r,t,u)))},pe=function(){return new Map},he=function(e,n,r){return fe(e,n,r,ne,pe,re)},de=function(e,n){return delete e[n],e},ve=function(e,n,r,t){return le(e,n,r,!1,!1,t||de)},me=function(e,n){return e.delete(n)},ge=function(e,n){return ve(e,n,ne,me)},ye=class{constructor(){this.store=new Map}get(e,n){return e=ue(oe(e),ae),he(this.store,e,n)}remove(e){return e=ue(oe(e),ae),ge(this.store,e)}delete(e){return this.remove(e)}},be=U("MemoizedFunction",(function(e,n){if(this.base=e,null!=n)if(1===(n=s(n)).length){this.cache=new ie;var r=n[0];this._cacheKeyFormatter=e=>e[r]}else this.cache=new ye,this._cacheKeyFormatter=e=>V(e,n);else this.cache=new ye,this._cacheKeyFormatter=e=>e;var t=this;return function(){var n=t._cacheKeyFormatter(arguments);return t.cache.get(n,(()=>e.apply(this,arguments)))}}),{remove(e){return this.cache.remove(this._cacheKeyFormatter(e))}}),we=function(e,n){return new be(e,n)},xe=/\r?\n/,Oe=function(e,n){var r=n.length;e.length=r;for(var t=0;t<r;t++)e[t]=n[t];return e},Te=function(e){return function(){return!e.apply(this,arguments)}},Ee=function(e,n){return Oe(e,e.filter(Te(n)))},Se=function(e){return null==e||void 0!==e.length&&0===e.length},Ne=function(e,n){return Ee(e,Se)},je=function(e,n){return e.splice(n,1),e},ke=function(e,n,r,t){[r,t]=Y(e,r,t);for(var i=r;i<t;i++){var u=n(e[i],i,e);void 0!==u&&(e[i]=u)}return e},Fe=function(e,n,r){for(var t={},i=e.length,u=0;u<i;u++){var o=n(e[u],u,e);if(o){var[a,s]=o;r?(t[a]||(t[a]=[]),t[a].push(s)):t[a]=s}}return t},Ae=function(e,n,r,t){return[n,r]=Y(e,n,r,t),e.slice(n,r)},Ce=function(e){return e[e.length-1]},Pe=function(e,n){return Q(n,e).join("")},De=function(e,n){return e.endsWith(n)?e.substring(0,e.length-n.length):e},_e=function(e){return f(e,Object)},Ie=function(e){return new Set(e)},Le=function(e){var n={};if(e){var r=Ie(e);r.has("g")&&(n.global=!0),r.has("i")&&(n.caseInsensitive=!0),r.has("y")&&(n.sticky=!0)}return n},qe=function(e){var n="";return e.global&&(n+="g"),(e.caseInsensitive||0==e.caseSensitive)&&(n+="i"),e.sticky&&(n+="y"),n},Me=function(e,n){var r=Le(e);return qe(Object.assign(r,n))},Re=function(e,n){var r=n,t=void 0;return o(r)?t=r:_e(r)&&(t=Me(e.flags,r)),new RegExp(e,t)},Be=z,Ge=function(e,n,r){return e=Re(e,{global:!0}),null!=r&&(n=Be(r,n)),e.lastIndex=n,e},Je=function(e,n){return Re(e,e.flags+n)},Ke=function(e){return Je(e,"g")},We=function(e){return e.global?e:Ke(e)},Ue=function(e,n,r){return e=null!=r?Ge(e,r,n):We(e),Array.from(n.matchAll(e))},ze=function(e,n,r){return null!=r&&(n=n.slice(0,r)),Ce(Ue(e,n))||null},Ye=function(e,n){var r=ze(e,n);return r&&n.length===r.index+r[0].length?r:null},He=function(e,n){var r=Ye(n,e);return r?e.slice(0,r.index):e},Qe=f,Ve=function(e){return Qe(e,RegExp)},$e=j(globalThis.TypeError),Ze=function(e){return null==e?e:e.constructor},Xe=function(e,n){return n||(n={}),null==n.colors&&(n.colors=!0),Nr("node:util").inspect(e,n)},en=function(e){var n=e;return null==n?void 0:o(n)?n:qe(n)},nn=function(e,n){return new RegExp(e,en(n))},rn=function(e){return e.replace(/[-[\]{}()*+!<=:?.\/\\^$|#\s,]/g,"\\$&")},tn=function(e,n){return nn(rn(e),n)},un=function(e,n,r){return e.replaceAll?(Ve(n)&&(n=We(n)),e.replaceAll(n,r)):(n=o(n)?tn(n,"g"):We(n),this.replace(n,r))},on=function(e,n,r){return un(e,n,(r??"\\")+n)},an=function(e,n,r){return null==n&&(n='"'),!1!==r&&(e=on(e,n,r)),n+e+n},sn=function(e){return an(e,'"')},cn=_e,ln=function(e){return cn(e)?mn(e):String(e)},fn=function(e,n){return n||(n=pn),"["+e.reduce((function(e,r){return e+n(r)+", "}),"").slice(0,-2)+"]"},pn=function(e){return o(e)?sn(e):a(e)?fn(e):ln(e)},hn=function(e,n){return(n?Object.getOwnPropertyNames:Object.keys)(e)},dn=function(e,n,r){hn(e,r).forEach(((r,t,i)=>n(r,e[r],t,i)))},vn=function(e,n,r,t){var i=null!=r?r:"";return dn(e,(function(){i=n.call(this,i,...arguments)}),t),i},mn=function(e,n){return n||(n=pn),"{"+vn(e,(function(e,r,t){return e+r+":"+n(t)+", "}),"",!0).slice(0,-2)+"}"},gn=function(e,n){return null==n&&(n=1),n<=0?"[object Object]":mn(e,(e=>bn(e,n-1)))},yn=function(e,n){return null==n&&(n=1),n<=0?"[object Array]":fn(e,(e=>bn(e,n-1)))},bn=function(e,n){return void 0===e?"undefined":null===e?"null":R()?Xe(e,n):_e(e)?gn(e,maxNumLevels):a(e)?yn(e,maxNumLevels):ln(e)},wn=function(e,n,r,t){if(0===arguments.length)return new $e("Unexpected type received");t||(t={});var i,{type:u,expected:o}=t;return null==u&&(u=Ze(e)),u&&u.name&&(u=u.name),o?(o.name&&(o=o.name),i="Expected "+o+", received "):i="Unexpected type received (",i+=u,null!=e&&(i+=" ("+bn(e)+")"),o||(i+=")"),r&&(i+=' for "'+r+'"'),null!=n&&(i+=" (index "+n+")"),t.fromFn||(t.fromFn=wn),new $e(i,t)},xn=function(e,n){if(o(n))return De(e,n);if(Ve(n))return He(e,n);throw wn(n,1)},On=xn,Tn=function(e){return e?e[0]:null},En=function(e,n){return un(e,n,"")},Sn=En,Nn=function(e,n){return Re(e,Sn(e.flags,n))},jn=function(e){return Nn(e,"g")},kn=function(e){return e.global?jn(e):e},Fn=function(e,n,r){return(e=null!=r?Ge(e,r,n):kn(e)).exec(n)},An=function(e,n){return[e.slice(0,n),e.slice(n)]},Cn=function(e,n){var r=null==n?-1:n.index;if(-1===r)return[e];var t=An(e,r);return t[1]=t[1].slice(n[0].length),t},Pn=class extends Array{constructor(e,n){super(),this[0]=-1===n?null:e,this.index=n}},Dn=function(e,n,r){if(o(n)){var t=e.indexOf(n,r);return new Pn(n,t)}return Fn(n,e,r)},_n=function(e,n){return Cn(e,Dn(e,n))},In=function(e){return isNaN(e)?null:e},Ln=function(e){return null==e?null:In(Number(e))},qn=Ln,Mn=function(e){return qn(e)??e},Rn=function(e,n){null==n&&(n="=");var r={};return e.forEach((function(e){var[t,i]=_n(e,n);null!=i&&(i=Mn(i.trim())),r[t.trim()]=i})),r},Bn=P,Gn=class extends Array{constructor(e){var n,r=e;null!=r&&(a(r)?n=r:o(r)&&(n=r.split(xe))),n?(super(n.length),Object.assign(this,n)):super(...arguments)}condense(e){return this.trim().removeEmpty(),e&&this.removeComments(e),this}trim(){return this.apply((e=>e.trim()))}removeEmpty(){return Ne(this)}removeComments(e){for(var n=0;n<this.length;n++){var r=this[n],t=r.indexOf(e);-1!==t&&(""===(r=r.slice(0,t)).trim()?(je(this,n),n--):this[n]=r)}return this}removeFirst(){return this.shift(),this}removeLast(){return this.pop(),this}apply(e){return ke(this,e)}join(){return super.join("\n")}toObj(e){return Rn(this,e)}mapToObj(e,n){return Fe(this,e,n)}between(e,n,r){return r=Bn(r,"inclusiveEnd",!0),Ae(this,e,n,r)}normalize(){if(this.length>0&&(""===this[0].trim()&&this.shift(),this.length>0&&(""===Ce(this).trim()&&this.pop(),this.length>0))){var e=this.find((e=>""!==e.trim())),n=Tn(Fn(/^\s*/,e));if(n){var r=n.length;this.apply((e=>{if(e.startsWith(n))return e.slice(r)}))}}return this}deindent(e,n,r){throw _()}indent(e,n){var r=Pe(n??"\t",e??1);return this.apply((e=>r+e))}static is(e){return f(e,this)}static fromChunks(e){return e.map((e=>On(e,xe))).flatMap((e=>Kn(e,!1)))}},Jn=function(e,n){var r=new Gn(e);return n&&r.condense(),r},Kn=function(e,n,r){var t=e.split(xe);return n?Jn(t,r):t},Wn=function(e){try{var n=rr("where",[e]);return Kn(n,!1)}catch(e){return null}},Un=M((function(){return"win32"===process.platform})),zn=function(e){return function(){return!!e.apply(this,arguments)}},Yn=function(e){return n=>n===e},Hn=function(e){return e instanceof Set},Qn=function(e){if(v(e))return zn(e);if(o(e))return n=>o(n)&&n.includes(e);if(Ve(e))return n=>o(n)&&e.test(n);if(Hn(e))return n=>e.has(n);if(a(e)){var n=e.map(Qn);return function(){return n.some((e=>e.apply(null,arguments)))}}return Yn(e)},Vn=function(e,n){return e.find(Qn(n))},$n=M((function(){return"linux"===process.platform})),Zn=/\.?[a-zA-Z0-9]+$/,Xn=function(e){return Zn.test(e)},er=we((function(e){var n=Wn(e);if(n){if(Un())return Vn(n,(function(e){return(e=e.toLowerCase()).endsWith(".exe")||e.endsWith(".cmd")}));if($n())return Vn(n,(e=>!Xn(e)))}return null})),nr=function(e){return Ee(e,(e=>null==e))},rr=function(e,n,r){if(r||(r={}),r.dir&&(r.cwd=r.dir),r.filterExtensions){var t=er(e);if(!t)throw F("Could not resolve command: "+e);e=t}r.encoding||(r.encoding="utf8"),n&&nr(n);var i=Nr("node:child_process").execFileSync(e,n,r);return null!=i?i.trim():i},tr=function(e,n){return n||(n={}),n.shell=!0,n.filterExtensions=!1,rr("npm",e,n)},ir=function(e,n,r){return tr(["install",e,n?"-g":null],r)},ur=function(e){return require(jr(e))},or=class{constructor(){this.store={}}get(e,n){return C(this.store,e,n)}remove(e){return delete this.store[e]}delete(e){return this.remove(e)}},ar=new or,sr=function(e){return e.endsWith("\\node_modules")||(e+="\\node_modules"),require("node:module").createRequire(e)},cr=function(e,n){return ar.get(e,(()=>sr(e)))(n)},lr=function(e){return a(e)?e:o(e)?e.split("."):[e]},fr=function(e,n,r,t,i,u){var o=r;return le(e,n,t,i,u,((e,n,r)=>r(e,n,X(o))))},pr=function(e,n){var r=n,t=globalThis.config;t||(t=globalThis.config={});var i,u=lr(e);return u.length>1?i=fr(t,u,r):(i=X(r),t[u[0]]=i),i},hr=function(e,n){return pr("node.require.customDirs",(r=>(r||(r=[]),!1!==n&&(e.endsWith("node_modules")||(e+="\\node_modules")),r.includes(e)||r.push(e),r))),e},dr=hr,vr=le,mr=function(e){var n=globalThis.config;if(n){var r=lr(e);return r.length>1?vr(n,r):n[r[0]]}},gr=function(e,n,r){if(null!=e)return e;var t=mr(n);return null!=t?t:r},yr=function(e){return Nr("node:fs").existsSync(e)},br=function(e,n){if(o(n))return e.endsWith(e);if(Ve(n))return!!Ye(n,e);throw wn(n,1,"matchThis")},wr=/\/|\\/,xr=function(e){return br(e,wr)?e:e+"/"},Or=function(e,n){return e=Nr("node:path").dirname(e),!1===n?e:xr(e)},Tr=function(e){var n=Or(e,!1);return yr(n)||(n!==e&&Tr(n),Nr("node:fs").mkdirSync(n)),e},Er=function(e){return Tr(e),Nr("node:fs").mkdirSync(e),e},Sr=function(e){return yr(e)?e:Er(e)},Nr=function(e,t){if(n(e))return require(e);if(r(e))return ur(e);try{return require(e)}catch(e){}var i=__dirname,o=process.mainModule?.path;if(o!==i)try{return cr(o,e)}catch(e){}var a=process.cwd();if(a!==o&&a!==i)try{return cr(a,e)}catch(e){}var s=mr("node.require.customDirs");if(s)for(var c of s)try{return cr(c,e)}catch(e){}var l=gr(t?.autoInstall,"node.require.autoInstall"),f=gr(t?.promptInstall,"node.require.promptInstall",!0);if(l||f){var p=l||f;!0===p&&(p="./node_modules"),p=jr(p);var h=!1;if(l?(h=!0,console.log('Auto-installing "'+e+'" from npm to "'+p+'"...')):u(e)&&(h=!0,console.log('Installing "'+e+'" from npm to "'+p+'"...')),h){p=Sr(p),ir(e,!1,{cwd:p});try{return dr(p),cr(p,e)}catch(e){console.error("Failed to load from auto-install dir: ",p)}}}throw F('Module not found: "'+e+'"',{checked:{moduleDir:i,scriptDir:o,cwd:a}})},jr=function(e,n){var r=Nr("node:path").resolve;return n?r(n,e):r(e)},kr=function(){return process.mainModule?.filename??null},Fr=function(e){return e.charAt(0).toLowerCase()+e.slice(1)},Ar=function(e,n,r){if(Ve(n))return ze(n,e,r);if(o(n)){var t=e.lastIndexOf(n,r);return-1!==t?new Pn(n,t):null}throw wn(n,1)},Cr=function(e,n){return Cn(e,Ar(e,n))},Pr=function(e){return Cr(e,".")},Dr=function(e){return Pr(e)[0]},_r=function(e){return Nr("node:path").basename(e)},Ir=function(e){return Dr(_r(e))},Lr=function(e,n,r,t){e||(e=kr()??"_console.js");var i=Fr(Ir(e));n&&(i+="_repl"),i+=r?t?.dynamic?".dypkg.json":".pkg.json":".pkg.js";var u=Or(e)+i;return jr(u)},qr=M((function(){var e=process.env.TITAN_PATH;if(!e)throw F("Environment variable TITAN_PATH is not set.");return xr(e)})),Mr=M((function(){return qr()+"Compiled/"})),Rr=function(e){return Nr("node:fs").readFileSync(e,"utf8")},Br=function(){return new Date},Gr=function(e,n,r,t){var i="Required argument";return r&&(i+=' "'+r+'"'),null!=n&&(i+=" (index "+n+")"),i+=" missing",arguments.length>0&&(i+=" (received "+bn(e)+")"),F(i,null,D(t,Gr))},Jr=function(e){return new Date(e.getTime())},Kr=function(e){return new Date(e,null)},Wr=function(e){var n=new Date(e);return isNaN(n.getTime())?null:n},Ur=Ln,zr=function(e){return"number"==typeof e},Yr=function(e,n){if(null==e)throw Gr(e,0);if(e.constructor===Date)return n?Jr(e):e;if(o(e)){var r=Ur(e);return null!=r?Kr(r):Wr(e)||null}return zr(e)?Kr(e):void 0},Hr=function(e,n){return null==e?Br():Yr(e,n)},Qr=function(e){return Hr(e,!0)},Vr=Qr,$r=function(){var e=Mr()+"LastCompileTime.txt";return yr(e)?Vr(Rr(e)):null},Zr=function(e){return Nr("node:fs").statSync(e).mtime},Xr=function(e,n,r){return e=Yr(e),n=Yr(n),!1===r?e<n:e<=n},et=function(e){var n=$r();if(n){var r=Zr(e);if(Xr(r,n))return!0}return!1},nt=function(e,n){return Nr("astring").generate(e,n)},rt=function(e,n){return e.stack=n+"\n"+e.stack,e},tt=function(e,n,r){r||(r={}),!1!==n&&(r.sourceType="module"),null==r.allowAwaitOutsideFunction&&(r.allowAwaitOutsideFunction=!0);var t=Nr("acorn-node");try{return t.parse(e,r)}catch(n){throw rt(n,"Acorn parsing error: "+e)}},it=function(e,n,r){return nt(tt(e,n,r))},ut=/(['"])(.*?)\1/,ot=Ke(ut),at=function(e){return e.replace(ot,"")},st=at,ct=we,lt=Rr,ft=function(e,n){return Kn(lt(e),!0,n)},pt=function(e,n){return kn(e).test(n)},ht=function(e,n){return Ve(n)?pt(n,e):e.includes(n)},dt=function(e,n,r,t){null==e&&(e=""),null==n&&(n="");var i={},u=(r,t)=>i[e+r+n]=t;return t&&dn(t,u),r&&dn(r,u),i},vt=function(e,n){return dn(n,((n,r)=>e=un(e,n,r))),e},mt=function(e,n,r,t){var i,u;if(n)if(o(n)){if(!ht(e,n))return e;i=n}else{if(!a(n))throw wn(n,1,"paramIdentifier");if([i,u]=n,!ht(e,i)&&!ht(e,u))return e}var s=dt(i,u,r,t);return vt(e,s)},gt=function(e){return String(e)},yt=globalThis.process?.env.windir,bt=function(){return process.env.TEMP+"\\"},wt=function(e){return e?"C:/Users/"+e+"/":process.env.USERPROFILE+"\\"},xt=function(e){return wt(e)+"Desktop/"},Ot={PROGRAMFILES:globalThis.process?.env.ProgramFiles,WINDIR:yt,SYSTEM32:yt&&yt+"System32",TEMP:bt(),DESKTOP:xt()},Tt=function(e,n){return mt(gt(e),"$",n,Ot)},Et=function(){return qr()+"Source/SourceMap.txt"},St=function(e){return e?Tt(e,{TITAN:qr()}):Et()},Nt=function(e,n){throw _()},jt=function(e,n,r){if(o(n))return e.indexOf(n,r);null==r?r=0:e=e.slice(r);var t=Ve(n)?e.search(n):Nt();return-1===t?t:r+t},kt=function(e,n,r){null==r&&(r=0);var t=jt(e,n,r);return-1===t?null:e.slice(r,t)},Ft=function(e){var n=e[0];return n===n.toUpperCase()},At=function(e,n){var r=[],t=[];return e.forEach(((i,u)=>(n(i,u,e)?r:t).push(i))),[r,t]},Ct=ct((function(e){var n=ft(St(e),!0),r={};return n.forEach((e=>{var n=kt(e,"=").split(",").map((e=>e.trim())),[t,i]=At(n,(e=>!Ft(e))),u=t[0];if(!u)throw F('No shortName in SourceMap line: "'+e+'"');i.forEach((e=>{r[e]=u}))})),r}),0),Pt=M((function(e){var n=Object.keys(e);return nn("\\b("+n.join("|")+")\\.(\\w+)","g")})),Dt=/\bt\.(\w+)\.(\w+)/g,_t=function(e,n){var r={},i=r.t={};if(n?.enableGlobals){var u=r.globals={},o=Ct(),a=Pt(o),s=Ue(a,e).filter((n=>{var r=n[1],i=n[2],u=e[n.index-1];if("."===u||"_"===u)return!1;var o=globalThis[r];if(!o)return!0;if(void 0===o[i])return!0;var a=t._globals;return!!(a&&a[r]&&a[r][i])}));for(var[c,l,f]of s)u[l]||(u[l]={}),u[l][f]=!0;var p=s.map((([e,n,r])=>{var t=o[n];if(!t)throw F("No short name found for global: "+n);return"t."+t+"."+r+";"})).join(" ");e+="\n"+p}for(var[c,h,f]of s=e.matchAll(Dt))i[h]||(i[h]={}),i[h][f]=!0;return r},It=function(e,n){return e=it(e),e=st(e),_t(e,n)},Lt=function(e,n){return _t(e,n)},qt=function(e,n,r){if(n){if("js"===(n=n.toLowerCase()))return It(e,r);if("html"===n)return Lt(e,r)}return _t(e,r)},Mt=function(e,n,r){if(null==e)throw Gr(e,n,r,{fromFn:Mt});return e},Rt=function(e,n){return void 0!==e[n]},Bt=Rt,Gt=function(e,n){for(var r of(Mt(n,1),Object.keys(e))){if(!Bt(n,r))return!1;var t=e[r];if(t&&t.constructor===Object&&!Gt(t,n[r]))return!1}return!0},Jt=function(e,n){if(!Gt(n.t,e.t))return!0;if(n.globals){if(!e.globals)return!0;if(!Gt(n.globals,e.globals))return!0}return!1},Kt=function(e){return JSON.parse(lt(e))},Wt=function(e,n,r){var t,i,u;if(r||(r={}),e&&(e=jr(e)),r.packagePath)t=jr(r.packagePath);else{if(!e)throw F("Could not determine packagePath because no scriptPath was given.");t=Lr(e,!1,!0,r)}var o=yr(t);if(o)if(i=et(t))u="New compile";else{null==n&&(n=lt(e));var a,s=qt(n,"js",r),c=Kt(t);(a=Jt(c,s))&&(u="New deps")}else u="No package";var l={needsPack:!!u,scriptPath:e,packagePath:t};return u&&(l.reasonText=u),null!=o&&(l.exists=o),null!=i&&(l.newCompile=i),null!=a&&(l.newDeps=a),n&&(l.sourceText=n),l},Ut=function(e,n){var r=Pr(e)[1];return r?!1!==n?r.toLowerCase():r:null},zt=function(e,n){var r=n?.fileType;if(r){if("js"===(r=r.toLowerCase()))return It(e,n);if("html"===r)return Lt(e,n)}return _t(e,n)},Yt={},Ht=function(e,n,r){if(R()){var t=Nr("node:path").join(e,n);return r?xr(t):t}throw _()},Qt=ct((function(e){e=St(e);var n=Or(e)+"../Compiled/",r=ft(e,"//"),t=Yt;for(var i of r){var u=i.indexOf("="),o=i.slice(0,u).trim();o=o.split(",").map((e=>e.trim())).filter((e=>!Ft(e)));var a=i.slice(u+1).trim(),s=Ht(n,a).replaceAll("\\","/");for(var c of o)t[c]=s}return t}),0),Vt=function*(e,n){var r=0;for(var t of e)n(t,r++,e)&&(yield t)},$t=function(e){return e.slice()},Zt=function(e,n,r){for(var t=e.length-1;t>=n;t--)e[t+1]=e[t];return e[n]=r,e.length++,e},Xt=function(e,n){return Zt(e,e.length,n)},ei=Xt,ni=function(e,n){return e.call(this,...n,(function n(){return Ce(arguments)!==n&&ei(arguments,n),e.apply(this,arguments)}))},ri=function(e){e||(e={});var n=e.getKeys;n||(n=function(e){return Object.keys(e)});var r=e.recurseIf;if(!r){var t=this.constructor;r=e=>f(e,t)||cn(e)||a(e)}var i=e.leavesOnly??e.leafsOnly??!1,u=this;return ni((function*(e,t,o,a){var s=n(e,t,o);if(s)for(var c=s.length,l=0;l<c;l++){var f=s[l],p=e[f],h=$t(t);h.push(f);var d=null,v={value:p,key:f,object:e,path:h,level:o,isLeaf:d,root:u},m=r(p,v);v.isLeaf=d=!m,i&&!d||(yield v),m&&(yield*a(p,h,o+1,a))}}),[this,[],0])},ti=function(e,n){return ri.call(e,n)},ii=un,ui=function(e,n){return""===e?e:(null==n&&(n=!0),e=ii(e,"\\","/"),n?xr(e):e)},oi=function(e,n){1===arguments.length&&(n=!0);var r={};for(var t of e)r[t]=n;return r},ai=function(e,n,r,t){var i=tt(e,n,t);Nr("acorn-walk").full(i,r)},si=function(e,n,r,t){var i;if(o(r))i=e=>e.type===r;else if(a(r)){var u=oi(r);i=e=>u[e.type]}else i=r;var s=[];return ai(e,n,(function(e){i.apply(this,arguments)&&s.push(e)}),t),s},ci=nt,li=function(e){var n,r,t,i=e,u=o(i)?tt(i).body[0]:i,a=u.type;if("VariableDeclaration"===a){n="variable";var s=u.declarations[0];r=s.id.name,t=s.init?s.init.raw??nt(s.init):"undefined"}else"FunctionDeclaration"===a?n="function":"ClassDeclaration"===a&&(n="class"),r=u.id.name;var c={type:n,name:r};return t&&(c.value=t),c.text=ci(u),c.node=u,c},fi=function(e){return si(e,!0,["ExportNamedDeclaration","ExportDefaultDeclaration"]).map((function(e){var n=e.declaration;if(n){var r=li(n);return r.node=e,r}return{node:e}}))},pi=function(e,n){n||(n={});var r=n.enableGlobals,t=Qt(n.sourceMap),i={},u=[];return function e(n,o,a){var s=Vt(ti(n),(e=>e.isLeaf));for(var c of s){var[l,f]=c.path,p=i[l];if(p||(p=i[l]={}),null==p[f]){var h=t[l];if(h){var d=ui(h)+f+".js";if(!yr(d)){var v='Titan compiled value "t.'+l+"."+f+'" does not exist';throw a&&(v+=' (called by "t.'+o+"."+a+'")'),F(v+=".")}var m=Rr(d),g=fi(m)[0];p[f]=g,e(zt(m,{fileType:"js",enableGlobals:r}).t,l,f),u.push([l,f])}else console.log('Skipping unmapped module "'+l+'"'),p[f]=!1}}}(e.t),{t:i,globals:e.globals,order:u}},hi=function(e,n){n||(n={});var r=n.deps??zt(e,n),{t:t,globals:i,order:u}=pi(r,n),o={};if(o.t=r.t,i&&n.enableGlobals){o.globals=i;var a=Ct(),s=Object.keys(i),c=Fe(s,(e=>[a[e],e]),!0);o.shortNamesToGlobals=c}return o.itemsInOrder=u.map((([e,n])=>{var r=t[e][n];return[e,n,"variable"===r.type?r.value:"("+r.text+")"]})),o},di=function(e,n,r){return null==r&&(r=!0),ni((function(e,n,t){dn(e,(function(e,i){if(Bt(n,e)){var u=n[e];r?_e(u)&&_e(i)?t(i,u):n[e]=i:_e(u)&&t(i,u)}else n[e]=i}))}),[e,n]),n},vi=di,mi=function(e){return Object.assign({},e)},gi=function(e,n){if(n){var r={};return e.forEach(((e,t,i)=>r[n(e,t,i)]=!0)),r}return mi(e)},yi=function(e,n){vi(n.t,e.t,!1);var r=n.globals;if(r){var t=e.globals;t?vi(r,t,!1):e.globals=r,e.shortNamesToGlobals=n.shortNamesToGlobals}var i=gi(e.itemsInOrder,(e=>e[0]+"."+e[1]));return n.itemsInOrder.forEach((n=>{i[n[0]+"."+n[1]]||e.itemsInOrder.push(n)})),e},bi=function(e){return e instanceof Buffer},wi=function(e){return ArrayBuffer.isView(e)},xi=wi,Oi=function(e){return bi(e)||xi(e)||o(e)},Ti=function(e){return e.constructor===ArrayBuffer},Ei=function(e){return Oi(e)?e:Ti(e)?Buffer.from(e):ln(e)},Si=function(e){return zr(e)?String(e):Ei(e)},Ni=function(e,n){return Tr(e),Nr("node:fs").writeFileSync(e,Si(n)),e},ji=function(e,n){var r;return n||(n={}),r=n.condensed?0:null!=n.whitespace?n.whitespace:"\t",JSON.stringify(e,n.replacer,r)},ki=function(e,n,r){return Ni(e,ji(n,r))},Fi=function(e,n,r){r||(r={}),r.deps||r.fileType||!n||(r.fileType=Ut(n));var t=hi(e,r),i=r.packagePath||Lr(n,r.repl,!0,r);if(r.dynamic&&(r.packageExists??yr(i))&&!(r.newCompile??et(i))){var u=Kt(i);t=yi(u,t)}return ki(i,t),i},Ai=function(e,n){console.log("SUBREQUIRE");var r=require("titanfiber").load(e,n);return console.log("AFTER SUBREQUIRE"),r},Ci={titan:{autoPackAndLoadJSON:function(e,n,r){var t=Wt(e,n,r);return t.needsPack&&(r.onPack&&r.onPack(t.reasonText),n=t.sourceText??lt(e),r.packagePath=t.packagePath,r.packageExists=t.exists,r.newCompile=t.newCompile,Fi(n,e,r)),(r.loadFn??Ai)(t.packagePath,r)},needsToPack:Wt,getPackagePath:Lr,hasNewCompile:et,getLastCompileTime:$r,getCompiledDir:Mr,locate:qr,getShallowDeps:qt,getDepsFromJS:It,_getDepsBasic:_t,loadGlobalsMap:Ct,_resolveSourceMapPath:St,locateSourceMap:Et,_getGlobalsRegex:Pt,depsRegex:Dt,getDepsFromHTML:Lt,jsonHasNewDeps:Jt,packTextToJSONFile:Fi,packTextToJSON:hi,getDeps:zt,_getAllDeps:pi,loadSourceMap:Qt,sourceMap:Yt,addNewItemsToJSON:yi,loadJSONPackage:Ai},path:{abs:jr,hasExt:Xn,extRegex:Zn,dir:Or,ensureTrailingSlash:xr,baseName:Ir,removeExt:Dr,splitExt:Pr,file:_r,resolveVars:Tt,string:gt,_defaultParams:Ot,windir:yt,_getDefaultTempDir:bt,getDesktop:xt,getUserDir:wt,ext:Ut,join:Ht,fws:ui},node:{require:Nr,_basicRequire:e,promptYNSync:i,is:R,display:Xe,requireLocal:ur,_requireFromDir:cr,_requireDirCache:ar,_createRequire:sr,ensureRequireDir:dr,addRequireDir:hr,getScriptPath:kr},npm:{isBuiltIn:n,isFile:r,_promptForInstall:u,install:ir,_runCommand:tr},os:{run:rr,findCommand:er},f:{memoize:we,MemoizedFunction:be,createClass:U,createConstructor:b,isArrowFn:g,isArrow:m,is:v,isSync:p,isAsync:d,AsyncFunction:h,wrap:y,ensureConstructor:w,retThis:x,withName:S,setName:E,one:M,not:Te,match:Qn,bool:zn,eq:Yn,cache:ct,recurse:ni},class:{create:J,withName:N,setName:L,addStatics:q,setDisplay:G},s:{is:o,splitLines:Kn,lines:Jn,LinesArray:Gn,repeat:Pe,removeTrailing:On,removeFromEnd:xn,_removeStringFromEnd:De,_removeRegexFromEnd:He,chars:Ie,resolveIndex:Be,toLiteral:sn,quote:an,escape:on,replaceAll:un,from:ln,remove:Sn,removeAll:En,splitFirst:_n,_splitByMatch:Cn,splitAtIndex:An,match:Dn,endsWith:br,decapitalize:Fr,splitLast:Cr,matchLast:Ar,removeQuotes:at,replaceParams:mt,contains:ht,_createParamsObj:dt,_replaceByObj:vt,before:kt,index:jt,_findFn:Nt,isCapitalized:Ft,replace:ii},a:{is:a,ensure:s,pick:V,create:Q,fill:H,resolveIndices:Y,resolveIndex:z,push:ue,splitLast:ce,removeEmpty:Ne,removeByFilter:Ee,replaceContents:Oe,removeIndex:je,apply:ke,mapToObj:Fe,slice:Ae,last:Ce,toLiteral:fn,display:yn,find:Vn,removeNullish:nr,filterSplit:At,copy:$t,toObj:gi},p:{asyncJoint:l,is:c},v:{constructorMatches:f,resolve:X,isEmpty:Se,type:Ze,display:bn,toLiteral:pn,nullIfNaN:In,req:Mt},err:{create:F,Error:k,Enhanced:j,nyi:_,NYIError:A,defaultFromFn:D,type:wn,TypeError:$e,req:Gr,prepend:rt},o:{setHidden:T,addNonEnumerable:O,safeEnsure:P,ensure:C,isAny:I,hideKey:W,makeNonEnumerable:K,ensureCustom:ee,get:$,set:Z,createEmpty:se,remove:de,is:_e,constructorMatches:Qe,display:gn,toLiteral:mn,isPure:cn,reduce:vn,each:dn,keys:hn,fromLines:Rn,safeDefault:Bn,Cache:or,resolveKeys:lr,diveGet:vr,hasKey:Bt,has:Rt,fromKeys:oi,fromArray:mi},sym:{display:B,value:ae},js:{optMacro:function(e){},removeComments:it,fromAST:nt,parse:tt,removeQuotes:st,getExports:fi,getNodes:si,eachNode:ai,parseDeclaration:li,fromASTNode:ci},map:{Cache:ie,ensure:te,get:ne,set:re,MultiCache:ye,diveEnsure:he,createEmpty:pe,diveDelete:ge,remove:me},args:{ensureArray:oe,push:ei,append:Xt,insert:Zt},tree:{ensure:fe,dive:le,remove:ve,setCustom:fr,isSubsetOf:Gt,iterate:ti,iterator:ri,merge:vi,join:di},cmd:{where:Wn},re:{newline:xe,matchEnd:Ye,matchLast:ze,matchAll:Ue,setStartIndex:Ge,copy:Re,updateFlagString:Me,parseFlagString:Le,createFlagString:qe,ensureGlobal:We,global:Ke,addFlag:Je,is:Ve,createEscaped:tn,create:nn,resolveFlags:en,escape:rn,text:Tn,match:Fn,ensureLocal:kn,local:jn,removeFlag:Nn,RegexResult:Pn,slash:wr,quotes:ot,quote:ut,test:pt},n:{tryCoerce:Mn,tryParse:qn,ensure:Ln,fromString:Ur,is:zr},win:{is:Un},set:{is:Hn},linux:{is:$n},env:{setConfig:pr,getConfig:mr,resolveConfig:gr},fs:{ensureDir:Sr,exists:yr,mkdir:Er,ensureParent:Tr,load:Rr,getModifiedDate:Zr,loadLines:ft,loadText:lt,loadJSON:Kt,writeJSON:ki,write:Ni,formatRaw:Si},d:{from:Vr,create:Qr,resolve:Hr,now:Br,ensure:Yr,copy:Jr,fromYear:Kr,_resolveNative:Wr,isBefore:Xr},gen:{filter:Vt},bin:{ensureByteSafe:Ei,isByteSafe:Oi,isNodeBuffer:bi,isTA:xi},ab:{isTA:wi,is:Ti},json:{stringify:ji}};globalThis.t?Object.keys(Ci).forEach((function(e){if(t[e]){var n=Ci[e];Object.keys(n).forEach((function(r){t[e][r]=n[r]}))}else t[e]=Ci[e]})):globalThis.t=Object.assign({},Ci),globalThis.exports&&(exports.default=globalThis.t);
|