@aperturesyndicate/synx-format 3.6.1 → 3.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,28 +1,28 @@
1
- var nt=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(n,s)=>(typeof require<"u"?require:n)[s]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});function X(t){if(t==="true")return!0;if(t==="false")return!1;if(t==="null")return null;let n=t.length;if(n===0)return t;let s=t.charCodeAt(0);if(s===40&&n>2){let o=t.indexOf(")");if(o>1){let l=t.substring(1,o),e=t.substring(o+1);switch(l){case"int":{let p=parseInt(e,10);return isNaN(p)?0:p}case"float":{let p=parseFloat(e);return isNaN(p)?0:p}case"bool":return e.trim()==="true";case"string":return e;case"random":return Math.floor(Math.random()*2147483647);case"random:int":return Math.floor(Math.random()*2147483647);case"random:float":return Math.random();case"random:bool":return Math.random()<.5}}}let r=0,a=s;if(a===45){if(n===1)return t;r=1,a=t.charCodeAt(1)}if(a>=48&&a<=57){let o=!0,l=-1;for(let e=r+1;e<n;e++){let p=t.charCodeAt(e);if(p===46){if(l!==-1){o=!1;break}l=e}else if(p<48||p>57){o=!1;break}}if(o){if(l===-1)return parseInt(t,10);if(l>r&&l<n-1)return parseFloat(t)}}return t}function U(t){if(t.indexOf(" ")===-1)return t;let n=t,s=n.indexOf(" //");s!==-1&&(n=n.substring(0,s));let r=n.indexOf(" #");return r!==-1&&(n=n.substring(0,r)),n.trimEnd()}function yt(t){let n={},s=0;for(;s<t.length;){let r=t.indexOf(",",s);r===-1&&(r=t.length);let a=t.substring(s,r).trim();if(s=r+1,!!a)if(a==="required")n.required=!0;else if(a==="readonly")n.readonly=!0;else{let o=a.indexOf(":");if(o!==-1){let l=a.substring(0,o).trim(),e=a.substring(o+1).trim();switch(l){case"min":n.min=Number(e);break;case"max":n.max=Number(e);break;case"type":n.type=e;break;case"pattern":n.pattern=e;break;case"enum":n.enum=e.split("|");break}}}}return n}function W(t,n,s,r,a,o,l){if(o!=="active"||s.length===0&&!a&&!l)return;let e;t.__synx?e=t.__synx:(e={},Object.defineProperty(t,"__synx",{value:e,enumerable:!1,writable:!0,configurable:!0}));let p={markers:s};r.length>0&&(p.args=r),a&&(p.constraints=a),l&&(p.typeHint=l),e[n]=p}var rt=/^([^\s\[:\-#/(][^\s\[:(]*)(?:\(([\w:]+)\))?(?:\[([^\]]*)\])?(?::([^\s]+))?\s*(.*)$/;function _(t){let n=t.split(`
2
- `),s={},r=[{indent:-1,obj:s}],a="static",o=!1,l=!1,e=[],p=null,i=null,A=!1;for(let c=0;c<n.length;c++){let u=n[c],d=u.length,f=0;for(;f<d;){let y=u.charCodeAt(f);if(y!==32&&y!==9&&y!==13)break;f++}if(f===d)continue;let g=u.charCodeAt(f);if(g===35&&u.substring(f).trimEnd()==="###"){A=!A;continue}if(A)continue;if(g===35){d-f>7&&u.charCodeAt(f+1)===33&&u.substring(f,f+7)==="#!mode:"&&(a=u.substring(f+7,d).trim()==="active"?"active":"static");continue}if(g===47&&f+1<d&&u.charCodeAt(f+1)===47)continue;let S=d;for(;S>f;){let y=u.charCodeAt(S-1);if(y!==32&&y!==9&&y!==13&&y!==10)break;S--}let h=u.substring(f,S),M=h.length;if(g===33){if(h==="!active"){a="active";continue}if(h==="!lock"){o=!0;continue}if(h==="!llm"){l=!0;continue}if(h.startsWith("!include ")){let y=h.substring(9).trim().split(/\s+/),m=y[0],x=y[1]||m.replace(/^.*[\/\\]/,"").replace(/\.synx$/i,"");e.push({path:m,alias:x});continue}}if(p&&f>p.indent){let y=h;p.obj[p.key]+=(p.obj[p.key]?`
3
- `:"")+y;continue}else p=null;if(g===45&&M>1&&h.charCodeAt(1)===32){if(i&&f>i.indent){let y=U(h.substring(2).trim()),m=c+1;for(;m<n.length;){let x=n[m],$=0;for(;$<x.length&&(x.charCodeAt($)===32||x.charCodeAt($)===9||x.charCodeAt($)===13);)$++;if($<x.length)break;m++}if(m<n.length){let x=n[m],$=0;for(;$<x.length&&(x.charCodeAt($)===32||x.charCodeAt($)===9||x.charCodeAt($)===13);)$++;let H=x.charCodeAt($);if($>f&&$<x.length&&H!==45&&H!==35&&!(H===47&&$+1<x.length&&x.charCodeAt($+1)===47)){let L={},tt=y.match(rt);if(tt){let[,dt,et,,,pt]=tt,F=pt||"";et&&(F=`(${et})${F}`),L[dt]=F?X(U(F)):{}}else L._value=X(y);i.arr.push(L),r.push({indent:f,obj:L});continue}}i.arr.push(X(y));continue}continue}if(i&&f<=i.indent&&(i=null),g===91||g===40||g===58||g===47)continue;let O,R,P,T,w,j=!1,D=-1;for(let y=0;y<M;y++){let m=h.charCodeAt(y);if(m===32||m===9){D=y;break}if(m===40||m===91||m===58){j=!0;break}}if(j){let y=h.match(rt);if(!y)continue;[,O,R,P,T,w]=y,w=w?U(w.trim()):""}else{if(D===-1)O=h,w="";else{O=h.substring(0,D);let y=D;for(;y<M&&(h.charCodeAt(y)===32||h.charCodeAt(y)===9);)y++;w=y<M?U(h.substring(y)):""}R=void 0,P=void 0,T=void 0}R&&(w=`(${R})${w}`);let N=[],v=[];if(T&&(N=T.split(":")),N.length>0&&N.includes("random")&&w){let y=w.split(/\s+/).filter(m=>/^\d+(\.\d+)?$/.test(m));y.length>0&&(v=y,w="")}let V=P?yt(P):void 0;for(;r.length>1&&r[r.length-1].indent>=f;)r.pop();let C=r[r.length-1].obj;if(!(O==="__proto__"||O==="constructor"||O==="prototype"))if(w==="|")C[O]="",p={indent:f,obj:C,key:O},W(C,O,N,v,V,a,R);else if(!w&&N.length>0&&(N.includes("random")||N.includes("unique")||N.includes("geo")||N.includes("join")))C[O]=[],i={indent:f,arr:C[O]},W(C,O,N,v,V,a,R);else if(w)C[O]=X(w),W(C,O,N,v,V,a,R);else{C[O]={},r.push({indent:f,obj:C[O]});let y=c+1;for(;y<n.length;){let m=n[y],x=0;for(;x<m.length&&(m.charCodeAt(x)===32||m.charCodeAt(x)===9||m.charCodeAt(x)===13);)x++;if(x<m.length)break;y++}if(y<n.length){let m=n[y],x=0;for(;x<m.length&&(m.charCodeAt(x)===32||m.charCodeAt(x)===9||m.charCodeAt(x)===13);)x++;x+1<m.length&&m.charCodeAt(x)===45&&m.charCodeAt(x+1)===32&&(C[O]=[],r[r.length-1]={indent:f,obj:C[O]},i={indent:f,arr:C[O]})}W(C,O,N,v,V,a,R)}}return{root:s,mode:a,locked:o,...l?{llm:!0}:{},includes:e.length>0?e:void 0}}function gt(t){let n=[],s=0;for(;s<t.length;){let r=t[s];if(r===" "||r===" "){s++;continue}if(r>="0"&&r<="9"||r==="."&&s+1<t.length&&t[s+1]>="0"&&t[s+1]<="9"||r==="-"&&(n.length===0||n[n.length-1].type==="op"||n[n.length-1].type==="paren"&&n[n.length-1].value==="(")){let a="";for(r==="-"&&(a+="-",s++);s<t.length&&(t[s]>="0"&&t[s]<="9"||t[s]===".");)a+=t[s],s++;n.push({type:"number",value:parseFloat(a)});continue}if("+-*/%".includes(r)){n.push({type:"op",value:r}),s++;continue}if(r==="("||r===")"){n.push({type:"paren",value:r}),s++;continue}throw new Error(`SYNX :calc \u2014 unexpected character: '${r}' in expression "${t}"`)}return n}var Y=class{constructor(n){this.tokens=n,this.pos=0}parse(){let n=this.expr();if(this.pos<this.tokens.length)throw new Error(`SYNX :calc \u2014 unexpected token at position ${this.pos}`);return n}expr(){let n=this.term();for(;this.pos<this.tokens.length&&this.tokens[this.pos].type==="op"&&(this.tokens[this.pos].value==="+"||this.tokens[this.pos].value==="-");){let s=this.tokens[this.pos].value;this.pos++;let r=this.term();n=s==="+"?n+r:n-r}return n}term(){let n=this.factor();for(;this.pos<this.tokens.length&&this.tokens[this.pos].type==="op"&&"*/%".includes(this.tokens[this.pos].value);){let s=this.tokens[this.pos].value;this.pos++;let r=this.factor();if(s==="*")n=n*r;else if(s==="/"){if(r===0)throw new Error("SYNX :calc \u2014 division by zero");n=n/r}else{if(r===0)throw new Error("SYNX :calc \u2014 division by zero");n=n%r}}return n}factor(){let n=this.tokens[this.pos];if(!n)throw new Error("SYNX :calc \u2014 unexpected end of expression");if(n.type==="number")return this.pos++,n.value;if(n.type==="paren"&&n.value==="("){this.pos++;let s=this.expr();if(!this.tokens[this.pos]||this.tokens[this.pos].type!=="paren"||this.tokens[this.pos].value!==")")throw new Error("SYNX :calc \u2014 missing closing parenthesis");return this.pos++,s}throw new Error(`SYNX :calc \u2014 unexpected token: ${JSON.stringify(n)}`)}};function K(t){let n=gt(t.trim());return n.length===0?0:new Y(n).parse()}var b,k;try{b=nt("fs"),k=nt("path")}catch{}var st=4096,it=10*1024*1024,B=16,ht=512;function z(t,n){if(!k)throw new Error("path module not available");if(k.isAbsolute(n))throw new Error(`absolute path not allowed: ${n}`);let s=k.resolve(t,n),r=k.resolve(t);if(!s.startsWith(r+k.sep)&&s!==r)throw new Error(`path escapes base directory: ${n}`);return s}function G(t){if(!b)return;let n=b.statSync(t);if(n.size>it)throw new Error(`file too large (${n.size} bytes, max ${it})`)}var J=class{constructor(n){this._value=n}toString(){return"[SECRET]"}toJSON(){return"[SECRET]"}reveal(){return this._value}[Symbol.toPrimitive](n){return n==="number"?NaN:"[SECRET]"}},q=new Map;function I(t,n={},s,r,a=0,o=""){if(!s){s=t,xt(t);for(let e of Object.keys(t))e.startsWith("_")&&delete t[e];!r&&n._includes&&(r=St(n._includes,n))}if(a>=ht){for(let e of Object.keys(t))e!=="__synx"&&(t[e]="NESTING_ERR: maximum object nesting depth exceeded");return t}let l=t.__synx;for(let e of Object.keys(t)){if(e==="__synx")continue;let p=t[e];if(p&&typeof p=="object"&&!Array.isArray(p)&&I(p,n,s,r,a+1,o?`${o}.${e}`:e),Array.isArray(p))for(let c of p)c&&typeof c=="object"&&!Array.isArray(c)&&I(c,n,s,r,a+1,o?`${o}.${e}`:e);if(!l||!l[e])continue;let{markers:i,args:A}=l[e];if(i.includes("spam")){let c=i.indexOf("spam"),u=parseInt(i[c+1]??"0",10),d=Math.max(1,parseInt(i[c+2]??"1",10)||1);if(!Number.isFinite(u)||u<=0){t[e]="SPAM_ERR: invalid limit, use :spam:MAX[:WINDOW_SEC]";continue}let f=String(t[e]??e),g=`${e}::${f}`;if(!Rt(g,u,d)){t[e]=`SPAM_ERR: '${f}' exceeded ${u} calls per ${d}s`;continue}let S=E(s,f)??E(t,f);S!==void 0&&(t[e]=S)}if(i.includes("include")&&typeof t[e]=="string"){if(!b||!k){t[e]="INCLUDE_ERR: :include is not supported in browser";continue}let c=n.maxIncludeDepth??B,u=n._includeDepth??0;if(u>=c){t[e]=`INCLUDE_ERR: max include depth (${c}) exceeded`;continue}let d=String(t[e]),f=n.basePath||(typeof process<"u"?process.cwd():".");try{let g=z(f,d);G(g);let S=b.readFileSync(g,"utf-8"),{root:h,mode:M}=_(S);M==="active"&&I(h,{...n,basePath:k.dirname(g),_includeDepth:u+1},s),t[e]=h}catch(g){t[e]=`INCLUDE_ERR: ${g.message}`}continue}if(i.includes("env")){let c=String(p),d=(n.env||(typeof process<"u"?process.env:{}))[c],f=i.indexOf("default"),g=l[e]?.typeHint==="string";if(d!==void 0&&d!=="")t[e]=g||isNaN(Number(d))?d:Number(d);else if(f!==-1&&i.length>f+1){let S=i.slice(f+1).join(":");t[e]=g||isNaN(Number(S))?S:Number(S)}else t[e]=null}if(i.includes("random")&&Array.isArray(t[e])){let c=t[e];if(c.length===0){t[e]=null;continue}if(A&&A.length>0){let u=A.map(Number);t[e]=Mt(c,u)}else t[e]=c[Math.floor(Math.random()*c.length)]}if(i.includes("ref")&&typeof t[e]=="string"){let c=t[e],u=E(s,c)??E(t,c);if(u!==void 0){if(t[e]=u,i.includes("calc")){let d=i.indexOf("calc"),f=i[d+1]??"";if(f&&typeof u=="number"){let g=f.charAt(0);if("+-*/%".includes(g)){let S=`${u} ${f}`;try{t[e]=K(S)}catch{t[e]=u}}}}}else t[e]=null}if(i.includes("i18n")&&t[e]&&typeof t[e]=="object"&&!Array.isArray(t[e])){let c=t[e],u=n.lang||"en",d=c[u]??c.en??Object.values(c)[0]??null;t[e]=d}if(i.includes("calc")&&typeof t[e]=="string"){let c=t[e];if(c.length>st){t[e]=`CALC_ERR: expression too long (${c.length} chars, max ${st})`;continue}let u=new Map;for(let d of Object.keys(s))typeof s[d]=="number"&&u.set(d,String(s[d]));for(let d of Object.keys(t))d!==e&&typeof t[d]=="number"&&u.set(d,String(t[d]));u.size>0&&(c=Nt(c,u));try{t[e]=K(c)}catch(d){t[e]=`CALC_ERR: ${d.message}`}}if(i.includes("alias")&&typeof t[e]=="string"){let c=t[e],u=o?`${o}.${e}`:e;if(c===e||c===u)t[e]=`ALIAS_ERR: self-referential alias: ${u} \u2192 ${c}`;else{let d=E(s,c),f=c.lastIndexOf("."),g=f>=0?c.slice(0,f):"",S=f>=0?c.slice(f+1):c,h=g?E(s,g):s;((h!=null&&typeof h=="object"?h.__synx:void 0)?.[S]?.markers?.includes("alias")??!1)&&typeof d=="string"&&d===e?t[e]=`ALIAS_ERR: circular alias detected: ${e} \u2192 ${c}`:t[e]=d??null}}if(i.includes("secret")&&(t[e]=new J(String(t[e]))),i.includes("unique")&&Array.isArray(t[e])){let c=new Set;t[e]=t[e].filter(u=>{let d=String(u);return c.has(d)?!1:(c.add(d),!0)})}if(i.includes("geo")&&Array.isArray(t[e])){let c=n.region||"US",u=t[e],d=u.find(f=>String(f).startsWith(c+" "));if(d)t[e]=d.substring(c.length+1).trim();else{let f=u[0];typeof f=="string"&&f.includes(" ")?t[e]=f.substring(f.indexOf(" ")+1).trim():t[e]=f??null}}if(i.includes("split")&&typeof t[e]=="string"){let c=i.indexOf("split"),u=c+1<i.length?i[c+1]:",",d=ot(u);t[e]=t[e].split(d).map(f=>f.trim()).filter(f=>f!=="").map(f=>ct(f))}if(i.includes("join")&&Array.isArray(t[e])){let c=i.indexOf("join"),u=c+1<i.length?i[c+1]:",",d=ot(u);t[e]=t[e].map(f=>String(f)).join(d)}if(i.includes("default")&&!i.includes("env")&&(t[e]===null||t[e]===void 0||t[e]==="")){let c=i.indexOf("default");if(c!==-1&&i.length>c+1){let u=i.slice(c+1).join(":"),d=l[e]?.typeHint==="string";t[e]=d||isNaN(Number(u))?u:Number(u)}}if(i.includes("clamp")){let c=i.indexOf("clamp"),u=parseFloat(i[c+1]??""),d=parseFloat(i[c+2]??"");!isNaN(u)&&!isNaN(d)&&(u>d?t[e]=`CONSTRAINT_ERR: clamp min (${u}) > max (${d})`:typeof t[e]=="number"&&(t[e]=Math.min(d,Math.max(u,t[e]))))}if(i.includes("round")){let c=i.indexOf("round"),u=parseInt(i[c+1]??"0",10)||0;if(typeof t[e]=="number"){let d=Math.pow(10,u);t[e]=Math.round(t[e]*d)/d}}if(i.includes("map")&&Array.isArray(t[e])){let c=i.indexOf("map"),u=i[c+1]??"",d=String(u?E(s,u)??E(t,u)??"":""),g=t[e].find(S=>{let h=String(S),M=h.indexOf(" ");return M!==-1&&h.substring(0,M).trim()===d});t[e]=g?ct(g.substring(g.indexOf(" ")+1).trim()):null}if(i.includes("format")){let c=i.indexOf("format"),u=i[c+1]??"%s";t[e]=At(u,t[e])}if(i.includes("fallback")){let c=i.indexOf("fallback"),u=i[c+1]??"",d=t[e],f=d==null||d==="";if(!f&&typeof d=="string"&&b&&k&&n.basePath)try{let g=z(n.basePath,d);f=!b.existsSync(g)}catch{f=!0}f&&u&&(t[e]=u)}if(i.includes("once")){let c=i.indexOf("once"),u=i[c+1]??"uuid",d=k&&n.basePath?k.resolve(n.basePath,".synx.lock"):".synx.lock",f=$t(d,e);if(f!==null)t[e]=f;else{let g;u==="uuid"?g=at():u==="timestamp"?g=String(Date.now()):u==="random"?g=String(Math.floor(Math.random()*2147483647)):g=at(),bt(d,e,g),t[e]=g}}if(i.includes("version")&&typeof t[e]=="string"){let c=i.indexOf("version"),u=i[c+1]??">=",d=i[c+2]??"0";t[e]=wt(t[e],u,d)}if(i.includes("watch")&&typeof t[e]=="string")if(!b||!k)t[e]="WATCH_ERR: not supported in browser";else{let c=n.maxIncludeDepth??B;if((n._includeDepth??0)>=c)t[e]=`WATCH_ERR: max include depth (${c}) exceeded`;else{let d=t[e],f=n.basePath||(typeof process<"u"?process.cwd():"."),g=i.indexOf("watch"),S=i[g+1];try{let h=z(f,d);G(h);let M=b.readFileSync(h,"utf-8"),O=k.extname(h).slice(1);S?t[e]=kt(M,S,O):t[e]=M.trim()}catch(h){t[e]=`WATCH_ERR: ${h.message}`}}}if(i.includes("prompt")){let c=i.indexOf("prompt"),u=i[c+1]??e,d=t[e],f=ut(d,0);t[e]=`${u} (SYNX):
1
+ var it=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(r,s)=>(typeof require<"u"?require:r)[s]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});function D(t){let r=t.length;if(r>=2){let u=t.charCodeAt(0),o=t.charCodeAt(r-1);if(u===34&&o===34||u===39&&o===39)return t.substring(1,r-1)}if(t==="true")return!0;if(t==="false")return!1;if(t==="null")return null;if(r===0)return t;let s=t.charCodeAt(0);if(s===40&&r>2){let u=t.indexOf(")");if(u>1){let o=t.substring(1,u);if(/^[A-Za-z_][A-Za-z0-9_:]*$/.test(o)){let n=t.substring(u+1);switch(o){case"int":{let p=parseInt(n,10);return isNaN(p)?0:p}case"float":{let p=parseFloat(n);return isNaN(p)?0:p}case"bool":return n.trim()==="true";case"string":return n;case"random":return Math.floor(Math.random()*2147483647);case"random:int":return Math.floor(Math.random()*2147483647);case"random:float":return Math.random();case"random:bool":return Math.random()<.5;default:return D(n)}}}}let e=0,c=s;if(c===45){if(r===1)return t;e=1,c=t.charCodeAt(1)}if(c>=48&&c<=57){let u=!0,o=-1;for(let n=e+1;n<r;n++){let p=t.charCodeAt(n);if(p===46){if(o!==-1){u=!1;break}o=n}else if(p<48||p>57){u=!1;break}}if(u){if(o===-1)return parseInt(t,10);if(o>e&&o<r-1)return parseFloat(t)}}return t}function W(t){if(t.indexOf(" ")===-1)return t;let r=t,s=r.indexOf(" //");s!==-1&&(r=r.substring(0,s));let e=r.indexOf(" #");return e!==-1&&(r=r.substring(0,e)),r.trimEnd()}function yt(t){let r={},s=0;for(;s<t.length;){let e=t.indexOf(",",s);e===-1&&(e=t.length);let c=t.substring(s,e).trim();if(s=e+1,!!c)if(c==="required")r.required=!0;else if(c==="readonly")r.readonly=!0;else{let u=c.indexOf(":");if(u!==-1){let o=c.substring(0,u).trim(),n=c.substring(u+1).trim();switch(o){case"min":r.min=Number(n);break;case"max":r.max=Number(n);break;case"type":r.type=n;break;case"pattern":r.pattern=n;break;case"enum":r.enum=n.split("|").slice(0,4096);break}}}}return r}function q(t,r,s,e,c,u,o){if(u!=="active"||s.length===0&&!c&&!o)return;let n;t.__synx?n=t.__synx:(n={},Object.defineProperty(t,"__synx",{value:n,enumerable:!1,writable:!0,configurable:!0}));let p={markers:s};e.length>0&&(p.args=e),c&&(p.constraints=c),o&&(p.typeHint=o),n[r]=p}function at(t){let r=t.length;if(r===0)return null;let s=t.charCodeAt(0);if(s===91||s===58||s===45||s===35||s===47||s===40)return null;let e=0;for(;e<r;){let i=t.charCodeAt(e);if(i===32||i===9||i===91||i===58||i===40)break;e++}if(e===0)return null;let c=t.substring(0,e),u,o,n;if(e<r&&t.charCodeAt(e)===40){let i=t.indexOf(")",e+1);i!==-1?(u=t.substring(e+1,i),e=i+1):e++}if(e<r&&t.charCodeAt(e)===91){e++;let i=e,x=1;for(;e<r&&x>0;){let a=t.charCodeAt(e);a===91?x++:a===93&&x--,x>0&&e++}if(x===0)o=t.substring(i,e),e++;else{let a=t.indexOf("]",i);a!==-1?(o=t.substring(i,a),e=a+1):(o=t.substring(i),e=r)}}if(e<r&&t.charCodeAt(e)===58){let i=e+1,x=i;for(;x<r;){let a=t.charCodeAt(x);if(a===32||a===9)break;x++}n=t.substring(i,x),e=x}for(;e<r;){let i=t.charCodeAt(e);if(i!==32&&i!==9)break;e++}let p=e<r?t.substring(e):"";return{key:c,typeHint:u,constraintStr:o,markerChain:n,rawValue:p}}function v(t){t.length>16777216&&(t=t.substring(0,16777216));let r=t.split(`
2
+ `);r.length>2e6&&(r=r.slice(0,2e6));let s={},e=[{indent:-1,obj:s}],c="static",u=!1,o=!1,n=!1,p=!1,i=[],x=null,a=null,f=!1;for(let l=0;l<r.length;l++){let d=r[l],h=d.length,g=0;for(;g<h;){let y=d.charCodeAt(g);if(y!==32&&y!==9&&y!==13)break;g++}if(g===h)continue;let m=d.charCodeAt(g);if(m===35&&d.substring(g).trimEnd()==="###"){f=!f;continue}if(f)continue;if(m===35){h-g>7&&d.charCodeAt(g+1)===33&&d.substring(g,g+7)==="#!mode:"&&(c=d.substring(g+7,h).trim()==="active"?"active":"static");continue}if(m===47&&g+1<h&&d.charCodeAt(g+1)===47)continue;let w=h;for(;w>g;){let y=d.charCodeAt(w-1);if(y!==32&&y!==9&&y!==13&&y!==10)break;w--}let O=d.substring(g,w),R=O.length;if(m===33){if(O==="!active"){c="active";continue}if(O==="!lock"){u=!0;continue}if(O==="!llm"){o=!0;continue}if(O==="!tool"){n=!0;continue}if(O==="!schema"){p=!0;continue}if(O.startsWith("!include ")){if(i.length<4096){let y=O.substring(9).trim().split(/\s+/),A=y[0],S=y[1]||A.replace(/^.*[\/\\]/,"").replace(/\.synx$/i,"");i.push({path:A,alias:S})}continue}}if(x&&g>x.indent){let y=x.obj[x.key];if(y.length<1048576){let A=O,S=1048576-y.length,V=(y?`
3
+ `:"")+A;x.obj[x.key]=y+V.substring(0,S)}continue}else x=null;if(m===45&&R>1&&O.charCodeAt(1)===32){if(a&&g>a.indent){if(a.arr.length>=1048576)continue;let y=W(O.substring(2).trim()),A=l+1;for(;A<r.length;){let S=r[A],b=0;for(;b<S.length&&(S.charCodeAt(b)===32||S.charCodeAt(b)===9||S.charCodeAt(b)===13);)b++;if(b<S.length)break;A++}if(A<r.length){let S=r[A],b=0;for(;b<S.length&&(S.charCodeAt(b)===32||S.charCodeAt(b)===9||S.charCodeAt(b)===13);)b++;let V=S.charCodeAt(b);if(b>g&&b<S.length&&V!==45&&V!==35&&!(V===47&&b+1<S.length&&S.charCodeAt(b+1)===47)){let z={},L=at(y);if(L){let B=L.rawValue;L.typeHint&&(B=`(${L.typeHint})${B}`),z[L.key]=B?D(W(B)):{}}else z._value=D(y);a.arr.push(z),e.push({indent:g,obj:z});continue}}a.arr.push(D(y));continue}continue}if(a&&g<=a.indent&&(a=null),m===91||m===40||m===58||m===47)continue;let _,k,U,F,$,st=!1,Y=-1;for(let y=0;y<R;y++){let A=O.charCodeAt(y);if(A===32||A===9){Y=y;break}if(A===40||A===91||A===58){st=!0;break}}if(st){let y=at(O);if(!y)continue;_=y.key,k=y.typeHint,U=y.constraintStr,F=y.markerChain,$=y.rawValue?W(y.rawValue):""}else{if(Y===-1)_=O,$="";else{_=O.substring(0,Y);let y=Y;for(;y<R&&(O.charCodeAt(y)===32||O.charCodeAt(y)===9);)y++;$=y<R?W(O.substring(y)):""}k=void 0,U=void 0,F=void 0}k&&($=`(${k})${$}`);let I=[],T=[];if(F&&(I=F.split(":").slice(0,512)),I.length>0&&I.includes("random")&&$){let y=$.split(/\s+/).filter(A=>/^\d+(\.\d+)?$/.test(A));y.length>0&&(T=y,$="")}I.length>0&&I.includes("inherit")&&$&&(T=[$.trim()],$="");let H=U?yt(U):void 0;for(;e.length>1&&e[e.length-1].indent>=g;)e.pop();let N=e[e.length-1].obj;if(!(_==="__proto__"||_==="constructor"||_==="prototype"))if($==="|")N[_]="",x={indent:g,obj:N,key:_},q(N,_,I,T,H,c,k);else if(!$&&I.length>0&&(I.includes("random")||I.includes("unique")||I.includes("geo")||I.includes("join")))N[_]=[],a={indent:g,arr:N[_]},q(N,_,I,T,H,c,k);else if($)N[_]=D($),q(N,_,I,T,H,c,k);else{N[_]={},e.length<128&&e.push({indent:g,obj:N[_]});let y=l+1;for(;y<r.length;){let A=r[y],S=0;for(;S<A.length&&(A.charCodeAt(S)===32||A.charCodeAt(S)===9||A.charCodeAt(S)===13);)S++;if(S<A.length)break;y++}if(y<r.length){let A=r[y],S=0;for(;S<A.length&&(A.charCodeAt(S)===32||A.charCodeAt(S)===9||A.charCodeAt(S)===13);)S++;S+1<A.length&&A.charCodeAt(S)===45&&A.charCodeAt(S+1)===32&&(N[_]=[],e[e.length-1]={indent:g,obj:N[_]},a={indent:g,arr:N[_]})}q(N,_,I,T,H,c,k)}}return{root:s,mode:c,locked:u,...o?{llm:!0}:{},...n?{tool:!0}:{},...p?{schema:!0}:{},includes:i.length>0?i:void 0}}function gt(t){let r=[],s=0;for(;s<t.length;){let e=t[s];if(e===" "||e===" "){s++;continue}if(e>="0"&&e<="9"||e==="."&&s+1<t.length&&t[s+1]>="0"&&t[s+1]<="9"||e==="-"&&(r.length===0||r[r.length-1].type==="op"||r[r.length-1].type==="paren"&&r[r.length-1].value==="(")){let c="";for(e==="-"&&(c+="-",s++);s<t.length&&(t[s]>="0"&&t[s]<="9"||t[s]===".");)c+=t[s],s++;r.push({type:"number",value:parseFloat(c)});continue}if("+-*/%".includes(e)){r.push({type:"op",value:e}),s++;continue}if(e==="("||e===")"){r.push({type:"paren",value:e}),s++;continue}throw new Error(`SYNX :calc \u2014 unexpected character: '${e}' in expression`)}return r}var Z=class{constructor(r){this.tokens=r,this.pos=0}parse(){let r=this.expr();if(this.pos<this.tokens.length)throw new Error(`SYNX :calc \u2014 unexpected token at position ${this.pos}`);return r}expr(){let r=this.term();for(;this.pos<this.tokens.length&&this.tokens[this.pos].type==="op"&&(this.tokens[this.pos].value==="+"||this.tokens[this.pos].value==="-");){let s=this.tokens[this.pos].value;this.pos++;let e=this.term();r=s==="+"?r+e:r-e}return r}term(){let r=this.factor();for(;this.pos<this.tokens.length&&this.tokens[this.pos].type==="op"&&"*/%".includes(this.tokens[this.pos].value);){let s=this.tokens[this.pos].value;this.pos++;let e=this.factor();if(s==="*")r=r*e;else if(s==="/"){if(e===0)throw new Error("SYNX :calc \u2014 division by zero");r=r/e}else{if(e===0)throw new Error("SYNX :calc \u2014 division by zero");r=r%e}}return r}factor(){let r=this.tokens[this.pos];if(!r)throw new Error("SYNX :calc \u2014 unexpected end of expression");if(r.type==="number")return this.pos++,r.value;if(r.type==="paren"&&r.value==="("){this.pos++;let s=this.expr();if(!this.tokens[this.pos]||this.tokens[this.pos].type!=="paren"||this.tokens[this.pos].value!==")")throw new Error("SYNX :calc \u2014 missing closing parenthesis");return this.pos++,s}throw new Error(`SYNX :calc \u2014 unexpected token: ${JSON.stringify(r)}`)}};function Q(t){let r=gt(t.trim());return r.length===0?0:new Z(r).parse()}var M,C;try{M=it("fs"),C=it("path")}catch{}var ct=4096,ot=10*1024*1024,j=16,ht=512;function G(t,r){if(!C)throw new Error("path module not available");let s=r.charCodeAt(0);if(s===47||s===92)throw new Error(`SECURITY: rooted paths are not allowed: '${r}'`);if(C.isAbsolute(r))throw new Error(`SECURITY: absolute paths are not allowed: '${r}'`);let e=C.resolve(t,r),c=C.resolve(t);if(r.includes("..")&&!e.startsWith(c+C.sep)&&e!==c)throw new Error(`SECURITY: path traversal detected: '${r}'`);if(!e.startsWith(c+C.sep)&&e!==c)throw new Error(`SECURITY: path escapes base directory: '${r}'`);return e}function tt(t){if(!M)return;let r=M.statSync(t);if(r.size>ot)throw new Error(`file too large (${r.size} bytes, max ${ot})`)}var et=class{constructor(r){this._value=r}toString(){return"[SECRET]"}toJSON(){return"[SECRET]"}reveal(){return this._value}[Symbol.toPrimitive](r){return r==="number"?NaN:"[SECRET]"}},K=new Map;function lt(t,r){let s=t&&t.code;return s==="ENOENT"?`file not found: ${r}`:s==="EACCES"||s==="EPERM"?`permission denied: ${r}`:t&&t.message?t.message:String(t)}function P(t,r={},s,e,c=0,u=""){if(!s){s=t,xt(t);for(let n of Object.keys(t))n.startsWith("_")&&delete t[n];if(!e){let n=r._includes;e=n?mt(n,r):new Map}}if(c>=ht){for(let n of Object.keys(t))n!=="__synx"&&(t[n]="NESTING_ERR: maximum object nesting depth exceeded");return t}let o=t.__synx;for(let n of Object.keys(t)){if(n==="__synx")continue;let p=t[n];if(p&&typeof p=="object"&&!Array.isArray(p)&&P(p,r,s,e,c+1,u?`${u}.${n}`:n),Array.isArray(p))for(let a of p)a&&typeof a=="object"&&!Array.isArray(a)&&P(a,r,s,e,c+1,u?`${u}.${n}`:n);if(!o||!o[n])continue;let{markers:i,args:x}=o[n];if(i.includes("spam")){let a=i.indexOf("spam"),f=parseInt(i[a+1]??"0",10),l=Math.max(1,parseInt(i[a+2]??"1",10)||1);if(!Number.isFinite(f)||f<=0){t[n]="SPAM_ERR: invalid limit, use :spam:MAX[:WINDOW_SEC]";continue}let d=String(t[n]??n),h=`${n}::${d}`;if(!Rt(h,f,l)){t[n]=`SPAM_ERR: '${d}' exceeded ${f} calls per ${l}s`;continue}let g=E(s,d)??E(t,d);g!==void 0&&(t[n]=g)}if((i.includes("include")||i.includes("import"))&&typeof t[n]=="string"){if(!M||!C){t[n]="INCLUDE_ERR: :include/:import is not supported in browser";continue}let a=r.maxIncludeDepth??j,f=r._includeDepth??0;if(f>=a){t[n]=`INCLUDE_ERR: max include depth (${a}) exceeded`;continue}let l=String(t[n]),d=r.basePath||(typeof process<"u"?process.cwd():".");try{let h=G(d,l);tt(h);let g=M.readFileSync(h,"utf-8"),{root:m,mode:w}=v(g);w==="active"&&P(m,{...r,basePath:C.dirname(h),_includeDepth:f+1},s),t[n]=m,e&&e.set(n,m)}catch(h){t[n]=`INCLUDE_ERR: ${lt(h,l)}`}continue}if(i.includes("env")&&typeof p=="string"){let a=p,l=(r.env||(typeof process<"u"?process.env:{}))[a],d=i.indexOf("default"),h=o[n]?.typeHint==="string";if(l!==void 0&&l!=="")t[n]=h?l:X(l);else if(d!==-1&&i.length>d+1){let g=i.slice(d+1).join(":");t[n]=h?g:X(g)}else t[n]=null}if(i.includes("random")&&Array.isArray(t[n])){let a=t[n];if(a.length===0){t[n]=null;continue}if(x&&x.length>0){let f=x.map(Number);t[n]=$t(a,f)}else t[n]=a[Math.floor(Math.random()*a.length)]}if(i.includes("ref")&&typeof t[n]=="string"){let a=t[n],f=E(s,a)??E(t,a);if(f!==void 0){if(t[n]=f,i.includes("calc")){let l=i.indexOf("calc"),d=i[l+1]??"";if(d&&typeof f=="number"){let h=d.charAt(0);if("+-*/%".includes(h)){let g=`${f} ${d}`;try{t[n]=Q(g)}catch{t[n]=f}}}}}else t[n]=null}if(i.includes("i18n")&&t[n]&&typeof t[n]=="object"&&!Array.isArray(t[n])){let a=t[n],f=r.lang||"en",l=a[f]??a.en??Object.values(a)[0]??null,d=i.indexOf("i18n"),h=i[d+1];if(h&&l&&typeof l=="object"&&!Array.isArray(l)){let g=l,m=E(s,h)??E(t,h),w=typeof m=="number"?m:typeof m=="string"&&!isNaN(Number(m))?Number(m):0,O=Ct(f,Math.trunc(w)),R=g[O]??g.other??Object.values(g)[0]??null;typeof R=="string"?t[n]=R.split("{count}").join(String(Math.trunc(w))):t[n]=R}else t[n]=l}if(i.includes("calc")&&typeof t[n]=="string"){let a=t[n];if(a.length>ct){t[n]=`CALC_ERR: expression too long (${a.length} chars, max ${ct})`;continue}let f=new Map;for(let l of Object.keys(s))typeof s[l]=="number"&&f.set(l,String(s[l]));for(let l of Object.keys(t))l!==n&&typeof t[l]=="number"&&f.set(l,String(t[l]));f.size>0&&(a=Nt(a,f)),a=kt(a,s);try{t[n]=Q(a)}catch(l){t[n]=`CALC_ERR: ${l.message}`}}if(i.includes("alias")&&typeof t[n]=="string"){let a=t[n],f=u?`${u}.${n}`:n;if(a===n||a===f)t[n]=`ALIAS_ERR: self-referential alias: ${f} \u2192 ${a}`;else{let l=E(s,a),d=a.lastIndexOf("."),h=d>=0?a.slice(0,d):"",g=d>=0?a.slice(d+1):a,m=h?E(s,h):s;if(((m!=null&&typeof m=="object"?m.__synx:void 0)?.[g]?.markers?.includes("alias")??!1)&&typeof l=="string"&&l===n){let _=f<=a?f:a,k=f<=a?a:f;t[n]=`ALIAS_ERR: circular alias detected: ${_} \u2192 ${k}`}else t[n]=l??null}}if(i.includes("secret")&&(t[n]=new et(String(t[n]))),i.includes("unique")&&Array.isArray(t[n])){let a=new Set;t[n]=t[n].filter(f=>{let l=String(f);return a.has(l)?!1:(a.add(l),!0)})}if(i.includes("geo")&&Array.isArray(t[n])){let a=r.region||"US",f=t[n],l=f.find(d=>String(d).startsWith(a+" "));if(l)t[n]=l.substring(a.length+1).trim();else{let d=f[0];typeof d=="string"&&d.includes(" ")?t[n]=d.substring(d.indexOf(" ")+1).trim():t[n]=d??null}}if(i.includes("split")&&typeof t[n]=="string"){let a=i.indexOf("split"),f=a+1<i.length?i[a+1]:",",l=ft(f);t[n]=t[n].split(l).map(d=>d.trim()).filter(d=>d!=="").map(d=>X(d))}if(i.includes("join")&&Array.isArray(t[n])){let a=i.indexOf("join"),f=a+1<i.length?i[a+1]:",",l=ft(f);t[n]=t[n].map(d=>String(d)).join(l)}if(i.includes("default")&&!i.includes("env")&&(t[n]===null||t[n]===void 0||t[n]==="")){let a=i.indexOf("default");if(a!==-1&&i.length>a+1){let f=i.slice(a+1).join(":"),l=o[n]?.typeHint==="string";t[n]=l?f:X(f)}}if(i.includes("clamp")){let a=i.indexOf("clamp"),f=parseFloat(i[a+1]??""),l=parseFloat(i[a+2]??"");!isNaN(f)&&!isNaN(l)&&(f>l?t[n]=`CONSTRAINT_ERR: clamp min (${f}) > max (${l})`:typeof t[n]=="number"&&(t[n]=Math.min(l,Math.max(f,t[n]))))}if(i.includes("round")){let a=i.indexOf("round"),f=parseInt(i[a+1]??"0",10)||0;if(typeof t[n]=="number"){let l=Math.pow(10,f);t[n]=Math.round(t[n]*l)/l}}if(i.includes("map")&&Array.isArray(t[n])){let a=i.indexOf("map"),f=i[a+1]??"",l=String(f?E(s,f)??E(t,f)??"":""),h=t[n].find(g=>{let m=String(g),w=m.indexOf(" ");return w!==-1&&m.substring(0,w).trim()===l});t[n]=h?X(h.substring(h.indexOf(" ")+1).trim()):null}if(i.includes("format")){let a=i.indexOf("format"),f=i[a+1]??"%s";t[n]=Ot(f,t[n])}if(i.includes("replace")&&typeof t[n]=="string"){let a=i.indexOf("replace"),f=i[a+1],l=i[a+2]??"";f!==void 0&&f!==""&&(t[n]=t[n].split(f).join(l))}if(i.includes("sort")&&Array.isArray(t[n])){let a=i.indexOf("sort"),f=i[a+1],l=t[n].slice().sort((d,h)=>typeof d=="number"&&typeof h=="number"?d-h:String(d).localeCompare(String(h)));f==="desc"&&l.reverse(),t[n]=l}if(i.includes("sum")&&Array.isArray(t[n])){let a=0,f=!0;for(let l of t[n])if(typeof l=="number")a+=l,Number.isInteger(l)||(f=!1);else if(typeof l=="string"&&l!==""&&!isNaN(Number(l))){let d=Number(l);a+=d,Number.isInteger(d)||(f=!1)}t[n]=f?Math.trunc(a):a}if(i.includes("fallback")){let a=i.indexOf("fallback"),f=i[a+1]??"",l=t[n],d=l==null||l==="";if(!d&&typeof l=="string"&&M&&C&&r.basePath)try{let h=G(r.basePath,l);d=!M.existsSync(h)}catch{d=!0}d&&f&&(t[n]=f)}if(i.includes("once")){let a=i.indexOf("once"),f=i[a+1]??"uuid",l=C&&r.basePath?C.resolve(r.basePath,".synx.lock"):".synx.lock",d=_t(l,n);if(d!==null)t[n]=d;else{let h;f==="uuid"?h=ut():f==="timestamp"?h=String(Date.now()):f==="random"?h=String(Math.floor(Math.random()*2147483647)):h=ut(),bt(l,n,h),t[n]=h}}if(i.includes("version")&&typeof t[n]=="string"){let a=i.indexOf("version"),f=i[a+1]??">=",l=i[a+2]??"0";t[n]=wt(t[n],f,l)}if(i.includes("watch")&&typeof t[n]=="string")if(!M||!C)t[n]="WATCH_ERR: not supported in browser";else{let a=r.maxIncludeDepth??j;if((r._includeDepth??0)>=a)t[n]=`WATCH_ERR: max include depth (${a}) exceeded`;else{let l=t[n],d=r.basePath||(typeof process<"u"?process.cwd():"."),h=i.indexOf("watch"),g=i[h+1];try{let m=G(d,l);tt(m);let w=M.readFileSync(m,"utf-8"),O=C.extname(m).slice(1);g?t[n]=Et(w,g,O):t[n]=w.trim()}catch(m){t[n]=`WATCH_ERR: ${lt(m,l)}`}}}if(i.includes("prompt")){let a=i.indexOf("prompt"),f=i[a+1]??n,l=t[n],d=dt(l,0);t[n]=`${f} (SYNX):
4
4
  \`\`\`synx
5
- ${f}\`\`\``}l&&l[e]?.constraints&&Ot(t,e,l[e].constraints)}for(let e of Object.keys(t))e!=="__synx"&&typeof t[e]=="string"&&t[e].includes("{")&&(t[e]=mt(t[e],s,t,r));return t}function xt(t){let n=t.__synx;if(n)for(let s of Object.keys(t)){if(s==="__synx")continue;let r=n[s];if(!r||!r.markers.includes("inherit"))continue;let a=r.markers.indexOf("inherit"),o=r.markers[a+1];if(!o)continue;let l=t[o];if(!l||typeof l!="object"||Array.isArray(l))continue;let e=t[s];if(!e||typeof e!="object"||Array.isArray(e))continue;let p={...l,...e},i=l.__synx,A=e.__synx;if(i||A){let c={...i||{},...A||{}};Object.defineProperty(p,"__synx",{value:c,enumerable:!1,writable:!0,configurable:!0})}t[s]=p}}function mt(t,n,s,r){return t.replace(/\{(\w+(?:\.\w+)*)(?::(\w+(?:[./\\][\w./\\]*)?))?\}/g,(a,o,l)=>{if(l){if(l==="include"){if(!r||r.size===0)return a;if(r.size>1)return"INCLUDE_ERR: multiple !include \u2014 specify alias";let p=r.values().next().value,i=E(p,o);return i!=null?String(i):a}if(r){let p=r.get(l);if(p){let i=E(p,o);return i!=null?String(i):a}}return a}let e=E(n,o)??E(s,o);return e!=null?String(e):a})}function St(t,n){let s=new Map;if(!b||!k)return s;let r=n.basePath||(typeof process<"u"?process.cwd():"."),a=n.maxIncludeDepth??B,o=n._includeDepth??0;if(o>=a)return s;for(let l of t)try{let e=z(r,l.path);G(e);let p=b.readFileSync(e,"utf-8"),{root:i,mode:A}=_(p);A==="active"&&I(i,{...n,basePath:k.dirname(e),_includeDepth:o+1},void 0,s),s.set(l.alias,i)}catch{}return s}function Ot(t,n,s){let r=t[n];if(s.required&&(r==null||r==="")){t[n]=`CONSTRAINT_ERR: '${n}' is required`;return}if(r==null)return;if(s.type&&!(()=>{switch(s.type){case"int":return typeof r=="number"&&Number.isInteger(r);case"float":return typeof r=="number";case"bool":return typeof r=="boolean";case"string":return typeof r=="string";default:return!0}})()){t[n]=`CONSTRAINT_ERR: '${n}' expected type '${s.type}'`;return}if(s.enum){let o=String(r);if(!s.enum.includes(o)){t[n]=`CONSTRAINT_ERR: '${n}' must be one of [${s.enum.join("|")}]`;return}}let a=typeof r=="number"?r:typeof r=="string"&&(s.min!==void 0||s.max!==void 0)?r.length:null;if(a!==null){if(s.min!==void 0&&a<s.min){t[n]=`CONSTRAINT_ERR: '${n}' value ${a} is below min ${s.min}`;return}if(s.max!==void 0&&a>s.max){t[n]=`CONSTRAINT_ERR: '${n}' value ${a} exceeds max ${s.max}`;return}}if(s.pattern&&typeof r=="string"){if(s.pattern.length>128)return;try{if(!new RegExp(s.pattern).test(r)){t[n]=`CONSTRAINT_ERR: '${n}' does not match pattern /${s.pattern}/`;return}}catch{}}}function At(t,n){let s=typeof n=="number"?n:parseFloat(String(n));if(isNaN(s))return String(n);let r=t.match(/^%\.(\d+)f$/);if(r)return s.toFixed(parseInt(r[1],10));let a=t.match(/^%0(\d+)d$/);if(a)return String(Math.round(s)).padStart(parseInt(a[1],10),"0");let o=t.match(/^%(\d+)d$/);return o?String(Math.round(s)).padStart(parseInt(o[1],10)):t==="%e"?s.toExponential():String(n)}function $t(t,n){if(!b)return null;try{let s=b.readFileSync(t,"utf-8");for(let r of s.split(/\r?\n/))if(r.startsWith(n+" "))return r.substring(n.length+1)}catch{}return null}function bt(t,n,s){if(!b)return;let r=[];try{r=b.readFileSync(t,"utf-8").split(/\r?\n/)}catch{}let a=`${n} ${s}`,o=r.findIndex(l=>l.startsWith(n+" "));o!==-1?r[o]=a:r.push(a);try{b.writeFileSync(t,r.filter(Boolean).join(`
5
+ ${d}\`\`\``}o&&o[n]?.constraints&&At(t,n,o[n].constraints)}for(let n of Object.keys(t))n!=="__synx"&&typeof t[n]=="string"&&t[n].includes("{")&&(t[n]=St(t[n],s,t,e));return t}function xt(t){let r=t.__synx;if(r)for(let s of Object.keys(t)){if(s==="__synx")continue;let e=r[s];if(!e||!e.markers.includes("inherit"))continue;let c=e.markers.indexOf("inherit"),u=e.markers[c+1]||e.args&&e.args[0];if(!u)continue;let o=t[u];if(!o||typeof o!="object"||Array.isArray(o))continue;let n=t[s];if(!n||typeof n!="object"||Array.isArray(n))continue;let p={...o,...n},i=o.__synx,x=n.__synx;if(i||x){let a={...i||{},...x||{}};Object.defineProperty(p,"__synx",{value:a,enumerable:!1,writable:!0,configurable:!0})}t[s]=p}}function St(t,r,s,e){return t.replace(/\{(\w+(?:\.\w+)*)(?::(\w+(?:[./\\][\w./\\]*)?))?\}/g,(c,u,o)=>{if(o){if(o==="include"){if(!e||e.size===0)return c;if(e.size>1)return"INCLUDE_ERR: multiple !include \u2014 specify alias";let p=e.values().next().value,i=E(p,u);return i!=null?String(i):c}if(e){let p=e.get(o);if(p){let i=E(p,u);return i!=null?String(i):c}}return c}let n=E(r,u)??E(s,u);return n!=null?String(n):c})}function mt(t,r){let s=new Map;if(!M||!C)return s;let e=r.basePath||(typeof process<"u"?process.cwd():"."),c=r.maxIncludeDepth??j,u=r._includeDepth??0;if(u>=c)return s;for(let o of t)try{let n=G(e,o.path);tt(n);let p=M.readFileSync(n,"utf-8"),{root:i,mode:x}=v(p);x==="active"&&P(i,{...r,basePath:C.dirname(n),_includeDepth:u+1},void 0,s),s.set(o.alias,i)}catch{}return s}function At(t,r,s){let e=t[r];if(s.required&&(e==null||e==="")){t[r]=`CONSTRAINT_ERR: '${r}' is required`;return}if(e==null)return;if(s.type&&!(()=>{switch(s.type){case"int":return typeof e=="number"&&Number.isInteger(e);case"float":return typeof e=="number";case"bool":return typeof e=="boolean";case"string":return typeof e=="string";default:return!0}})()){t[r]=`CONSTRAINT_ERR: '${r}' expected type '${s.type}'`;return}if(s.enum){let u=String(e);if(!s.enum.includes(u)){t[r]=`CONSTRAINT_ERR: '${r}' must be one of [${s.enum.join("|")}]`;return}}let c=typeof e=="number"?e:typeof e=="string"&&(s.min!==void 0||s.max!==void 0)?e.length:null;if(c!==null){if(s.min!==void 0&&c<s.min){t[r]=`CONSTRAINT_ERR: '${r}' value ${c} is below min ${s.min}`;return}if(s.max!==void 0&&c>s.max){t[r]=`CONSTRAINT_ERR: '${r}' value ${c} exceeds max ${s.max}`;return}}if(s.pattern&&typeof e=="string"){if(s.pattern.length>128)return;try{if(!new RegExp(s.pattern).test(e)){t[r]=`CONSTRAINT_ERR: '${r}' does not match pattern /${s.pattern}/`;return}}catch{}}}function Ot(t,r){let s=typeof r=="number"?r:parseFloat(String(r));if(isNaN(s))return String(r);let e=t.match(/^%\.(\d+)f$/);if(e)return s.toFixed(parseInt(e[1],10));let c=t.match(/^%0(\d+)d$/);if(c)return String(Math.round(s)).padStart(parseInt(c[1],10),"0");let u=t.match(/^%(\d+)d$/);return u?String(Math.round(s)).padStart(parseInt(u[1],10)):t==="%e"?s.toExponential():String(r)}function _t(t,r){if(!M)return null;try{let s=M.readFileSync(t,"utf-8");for(let e of s.split(/\r?\n/))if(e.startsWith(r+" "))return e.substring(r.length+1)}catch{}return null}function bt(t,r,s){if(!M)return;let e=[];try{e=M.readFileSync(t,"utf-8").split(/\r?\n/)}catch{}let c=`${r} ${s}`,u=e.findIndex(o=>o.startsWith(r+" "));u!==-1?e[u]=c:e.push(c);try{M.writeFileSync(t,e.filter(Boolean).join(`
6
6
  `)+`
7
- `,"utf-8")}catch{}}function at(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,t=>{let n=Math.random()*16|0;return(t==="x"?n:n&3|8).toString(16)})}function wt(t,n,s){let r=p=>p.split(".").map(i=>parseInt(i,10)||0),a=r(t),o=r(s),l=Math.max(a.length,o.length),e=0;for(let p=0;p<l;p++){let i=a[p]??0,A=o[p]??0;if(i!==A){e=i>A?1:-1;break}}switch(n){case">=":return e>=0;case"<=":return e<=0;case">":return e>0;case"<":return e<0;case"==":case"=":return e===0;case"!=":return e!==0;default:return!1}}function kt(t,n,s){if(s==="json")try{let r=JSON.parse(t);return n.split(".").reduce((a,o)=>a?.[o],r)??null}catch{return null}try{let{root:r}=_(t);return E(r,n)??null}catch{return null}}function ut(t,n){let s=" ".repeat(n);if(t==null)return`${s}null
7
+ `,"utf-8")}catch{}}function ut(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,t=>{let r=Math.random()*16|0;return(t==="x"?r:r&3|8).toString(16)})}function wt(t,r,s){let e=p=>p.split(".").map(i=>parseInt(i,10)||0),c=e(t),u=e(s),o=Math.max(c.length,u.length),n=0;for(let p=0;p<o;p++){let i=c[p]??0,x=u[p]??0;if(i!==x){n=i>x?1:-1;break}}switch(r){case">=":return n>=0;case"<=":return n<=0;case">":return n>0;case"<":return n<0;case"==":case"=":return n===0;case"!=":return n!==0;default:return!1}}function Et(t,r,s){if(s==="json")try{let e=JSON.parse(t);return r.split(".").reduce((c,u)=>c?.[u],e)??null}catch{return null}try{let{root:e}=v(t);return E(e,r)??null}catch{return null}}function dt(t,r){let s=" ".repeat(r);if(t==null)return`${s}null
8
8
  `;if(typeof t=="boolean"||typeof t=="number")return`${s}${t}
9
9
  `;if(typeof t=="string")return`${s}${t}
10
- `;if(Array.isArray(t)){let r="";for(let a of t)r+=`${s} - ${String(a)}
11
- `;return r}if(typeof t=="object"){let r="";for(let[a,o]of Object.entries(t))if(a!=="__synx")if(o&&typeof o=="object"&&!Array.isArray(o))r+=`${s}${a}
12
- `,r+=ut(o,n+2);else if(Array.isArray(o)){r+=`${s}${a}
13
- `;for(let l of o)r+=`${s} - ${String(l)}
14
- `}else r+=`${s}${a} ${o??"null"}
15
- `;return r}return`${s}${String(t)}
16
- `}function ct(t){return t==="true"?!0:t==="false"?!1:t==="null"?null:/^-?\d+$/.test(t)?parseInt(t,10):/^-?\d+\.\d+$/.test(t)?parseFloat(t):t}var Ct={space:" ",pipe:"|",dash:"-",dot:".",semi:";",tab:" ",slash:"/"};function ot(t){return Ct[t]||t}function Mt(t,n){let s=[...n];if(s.length<t.length){let l=s.reduce((p,i)=>p+i,0),e=l<100?(100-l)/(t.length-s.length):l/s.length;for(;s.length<t.length;)s.push(e)}let r=s.reduce((l,e)=>l+e,0);if(r<=0)return t[Math.floor(Math.random()*t.length)];let a=Math.random(),o=0;for(let l=0;l<t.length;l++)if(o+=s[l]/r,a<=o)return t[l];return t[t.length-1]}function lt(t){return t>=48&&t<=57||t>=65&&t<=90||t>=97&&t<=122||t===95}function Et(t,n,s){let r=n.length,a=t.length,o="",l=0;for(;l<=a-r;){if(t.slice(l,l+r)===n){let e=l===0||!lt(t.charCodeAt(l-1)),p=l+r>=a||!lt(t.charCodeAt(l+r));if(e&&p){o+=s,l+=r;continue}}o+=t[l++]}for(;l<a;)o+=t[l++];return o}function Nt(t,n){let s=[...n.entries()].sort((a,o)=>o[0].length-a[0].length),r=t;for(let[a,o]of s)r=Et(r,a,o);return r}function Rt(t,n,s){let r=Date.now(),a=s*1e3,o=q.get(t)??[],l=o.filter(e=>r-e<=a);return l.length>=n?(q.set(t,l),!1):(l.length===0&&o.length>0&&q.delete(t),l.push(r),q.set(t,l),!0)}function E(t,n){if(Object.prototype.hasOwnProperty.call(t,n))return t[n];let s=n.split("."),r=t;for(let a of s){if(r==null||typeof r!="object"||!Object.prototype.hasOwnProperty.call(r,a))return;r=r[a]}return r}var Z=class extends Error{constructor(n){super(n),this.name="SynxError";let s=n.indexOf(":");this.code=s!==-1?n.slice(0,s):"SYNX_ERR"}};var Q=class{static parse(n,s={}){let{root:r,mode:a}=_(n);return a==="active"&&I(r,s),r}static stringify(n,s=!1){let r="";return s&&(r+=`!active
17
- `),r+=ft(n,0),r}};function ft(t,n){let s="",r=" ".repeat(n);for(let[a,o]of Object.entries(t))if(Array.isArray(o)){s+=`${r}${a}
18
- `;for(let l of o)if(l&&typeof l=="object"&&!Array.isArray(l)){let e=Object.entries(l);if(e.length>0){let[p,i]=e[0];s+=`${r} - ${p} ${i}
19
- `;for(let A=1;A<e.length;A++)s+=`${r} ${e[A][0]} ${e[A][1]}
20
- `}}else s+=`${r} - ${l}
21
- `}else if(o&&typeof o=="object")s+=`${r}${a}
22
- `,s+=ft(o,n+2);else if(typeof o=="string"&&o.includes(`
23
- `)){s+=`${r}${a} |
24
- `;for(let l of o.split(`
25
- `))s+=`${r} ${l}
26
- `}else s+=`${r}${a} ${o}
27
- `;return s}var Xt=Q;export{Q as Synx,Z as SynxError,Xt as default};
10
+ `;if(Array.isArray(t)){let e="";for(let c of t)e+=`${s} - ${String(c)}
11
+ `;return e}if(typeof t=="object"){let e="",c=t,u=Object.keys(c).filter(o=>o!=="__synx").sort();for(let o of u){let n=c[o];if(n&&typeof n=="object"&&!Array.isArray(n))e+=`${s}${o}
12
+ `,e+=dt(n,r+2);else if(Array.isArray(n)){e+=`${s}${o}
13
+ `;for(let p of n)e+=`${s} - ${String(p)}
14
+ `}else e+=`${s}${o} ${n??"null"}
15
+ `}return e}return`${s}${String(t)}
16
+ `}function X(t){return t==="true"?!0:t==="false"?!1:t==="null"?null:/^-?\d+$/.test(t)?parseInt(t,10):/^-?\d+\.\d+$/.test(t)?parseFloat(t):t}function Ct(t,r){let s=Math.abs(r),e=s%10,c=s%100;switch(t){case"ru":case"uk":case"be":case"pl":return e===1&&c!==11?"one":e>=2&&e<=4&&!(c>=12&&c<=14)?"few":"many";case"cs":case"sk":return s===1?"one":s>=2&&s<=4?"few":"other";case"ar":return s===0?"zero":s===1?"one":s===2?"two":c>=3&&c<=10?"few":c>=11&&c<=99?"many":"other";case"fr":case"pt":return s<=1?"one":"other";case"ja":case"zh":case"ko":case"vi":case"th":return"other";default:return s===1?"one":"other"}}var Mt={space:" ",pipe:"|",dash:"-",dot:".",semi:";",tab:" ",slash:"/"};function ft(t){return Mt[t]||t}function $t(t,r){let s=[...r];if(s.length<t.length){let o=s.reduce((p,i)=>p+i,0),n=o<100?(100-o)/(t.length-s.length):o/s.length;for(;s.length<t.length;)s.push(n)}let e=s.reduce((o,n)=>o+n,0);if(e<=0)return t[Math.floor(Math.random()*t.length)];let c=Math.random(),u=0;for(let o=0;o<t.length;o++)if(u+=s[o]/e,c<=u)return t[o];return t[t.length-1]}function J(t){return t>=48&&t<=57||t>=65&&t<=90||t>=97&&t<=122||t===95}function It(t,r,s){let e=r.length,c=t.length,u="",o=0;for(;o<=c-e;){if(t.slice(o,o+e)===r){let n=o===0||!J(t.charCodeAt(o-1)),p=o+e>=c||!J(t.charCodeAt(o+e));if(n&&p){u+=s,o+=e;continue}}u+=t[o++]}for(;o<c;)u+=t[o++];return u}function Nt(t,r){let s=[...r.entries()].sort((c,u)=>u[0].length-c[0].length),e=t;for(let[c,u]of s)e=It(e,c,u);return e}function kt(t,r){let s="",e=0,c=t.length;for(;e<c;){let u=t.charCodeAt(e);if(J(u)){let o=e,n=!1;for(;e<c;){let i=t.charCodeAt(e);if(J(i))e++;else if(i===46)n=!0,e++;else break}let p=t.substring(o,e);if(n&&p.indexOf(".")!==-1){let i=E(r,p);if(typeof i=="number"){s+=String(i);continue}}s+=p}else s+=t[e],e++}return s}function Rt(t,r,s){let e=Date.now(),c=s*1e3,u=K.get(t)??[],o=u.filter(n=>e-n<=c);return o.length>=r?(K.set(t,o),!1):(o.length===0&&u.length>0&&K.delete(t),o.push(e),K.set(t,o),!0)}function E(t,r){if(Object.prototype.hasOwnProperty.call(t,r))return t[r];let s=r.split("."),e=t;for(let c of s){if(e==null||typeof e!="object"||!Object.prototype.hasOwnProperty.call(e,c))return;e=e[c]}return e}var nt=class extends Error{constructor(r){super(r),this.name="SynxError";let s=r.indexOf(":");this.code=s!==-1?r.slice(0,s):"SYNX_ERR"}};var rt=class{static parse(r,s={}){let{root:e,mode:c}=v(r);return c==="active"&&P(e,s),e}static stringify(r,s=!1){let e="";return s&&(e+=`!active
17
+ `),e+=pt(r,0),e}};function pt(t,r){let s="",e=" ".repeat(r);for(let[c,u]of Object.entries(t))if(Array.isArray(u)){s+=`${e}${c}
18
+ `;for(let o of u)if(o&&typeof o=="object"&&!Array.isArray(o)){let n=Object.entries(o);if(n.length>0){let[p,i]=n[0];s+=`${e} - ${p} ${i}
19
+ `;for(let x=1;x<n.length;x++)s+=`${e} ${n[x][0]} ${n[x][1]}
20
+ `}}else s+=`${e} - ${o}
21
+ `}else if(u&&typeof u=="object")s+=`${e}${c}
22
+ `,s+=pt(u,r+2);else if(typeof u=="string"&&u.includes(`
23
+ `)){s+=`${e}${c} |
24
+ `;for(let o of u.split(`
25
+ `))s+=`${e} ${o}
26
+ `}else s+=`${e}${c} ${u}
27
+ `;return s}var Yt=rt;export{rt as Synx,nt as SynxError,Yt as default};
28
28
  //# sourceMappingURL=synx.browser.mjs.map